"use strict";var p=Object.create;var m=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var P=(i,r)=>{for(var t in r)m(i,t,{get:r[t],enumerable:!0})},h=(i,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of g(r))!d.call(i,a)&&a!==t&&m(i,a,{get:()=>r[a],enumerable:!(s=w(r,a))||s.enumerable});return i};var y=(i,r,t)=>(t=i!=null?p(u(i)):{},h(r||!i||!i.__esModule?m(t,"default",{value:i,enumerable:!0}):t,i)),$=i=>h(m({},"__esModule",{value:!0}),i);var x={};P(x,{hashUrl:()=>c,resolveImageUrl:()=>D});module.exports=$(x);var f=require("react-native"),n=y(require("react-native-fs")),e=require("./pngImage");function c(i){let r=0;for(let t=0;t<i.length;t++)r=r*31+i.charCodeAt(t)|0;return Math.abs(r).toString(36)}async function D(i,r){const t=i.trim();if(!t)throw new Error("Image URL is empty");const s=(0,e.toPngFileName)(r??`img_${c(t)}.png`);if(t.startsWith("http://")||t.startsWith("https://")){const o=`${n.default.CachesDirectoryPath}/tmp_${Date.now()}_${s}`,{statusCode:l}=await n.default.downloadFile({fromUrl:t,toFile:o}).promise;if(l!==200)throw new Error(`Download image failed: ${t}`);try{return await(0,e.ensurePngFile)(o,s)}finally{await n.default.exists(o)&&await n.default.unlink(o)}}const a=(0,e.normalizePath)(t);if(await n.default.exists(a)&&(0,e.isPngPath)(a))return a;if(a.startsWith("file://"))return(0,e.ensurePngFile)(a,s);if(f.Platform.OS==="ios"&&a.startsWith("/"))return(0,e.ensurePngFile)(a,s);if(await n.default.exists(a))return(0,e.ensurePngFile)(a,s);if(f.Platform.OS==="android"){const o=t.replace(/^asset:\/?\/?/,"").replace(/^file:\/\/\/android_asset\//,"");if(o!==t){const l=`${n.default.CachesDirectoryPath}/tmp_${Date.now()}_${s}`;await n.default.copyFileAssets(o,l);try{return await(0,e.ensurePngFile)(l,s)}finally{await n.default.exists(l)&&await n.default.unlink(l)}}}return(0,e.ensurePngFile)(t,s)}
