@keeratita/heic-converter 0.6.2-prerelease.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var e=require("./chunk-N2LCVW2Q.js"),r={QualityInvalid:e=>`Quality must be a number between 0.0 and 1.0, got: ${e}`,BooleanOptionInvalid:(e,r)=>`${e} must be a boolean, got: ${r}`,UnsupportedInputType:e=>`Unsupported input type. Expected Blob (incl. File), ArrayBuffer, or ArrayBufferView. Got: ${e}`,DecoderInitFailed:e=>`Failed to initialize HEIC decoder: ${e} — verify heic-decoder.wasm is served (dist/heic-decoder.wasm; see the README "Serving and Locating WASM" section / locateFile option) and that your CSP allows 'wasm-unsafe-eval'`,WorkerChunkLoadFailed:e=>`Failed to load the Web Worker implementation chunk (dist/worker-*.mjs): ${e} — deploy every file in dist/ together, or use convertHeic to convert in the current thread`,NativeChunkLoadWarning:e=>`@keeratita/heic-converter: the native-decode chunk could not be loaded (${e}) — converting with the bundled decoder; serve every file in dist/ together, with dist/native-*.mjs as JavaScript`,RenderEncodeFailed:(e,r)=>`Failed to render and encode image as ${e}: ${r}`,ConcurrencyInvalid:(e,r)=>`Concurrency must be an integer between 1 and ${r}, got: ${e}`,InputsMustBeArray:"Inputs must be an array of HEIC images",OutputShapeInvalid:e=>`output must be one of 'blob', 'dataUrl', 'arrayBuffer', got: ${e}`,SignalInvalid:e=>`signal must be an AbortSignal, got: ${e}`,Aborted:"Conversion aborted (AbortSignal was aborted)",ConvertManyItemFailed:(e,r,t)=>`Conversion of item ${e} of ${r} failed: ${t}`,BatchItemProducedNoResult:(e,r)=>`Conversion of item ${e} of ${r} failed: item produced no result`,BatchEndedWithoutSettling:e=>`Batch ended without settling any of its ${e} items`,ConvertManyExtraFailures:(e,r)=>` (${e} of ${r} items failed in total)`,ConvertManyOtherErrors:e=>`; other errors: ${e.join(" | ")}`,ExifChunkLoadWarning:"@keeratita/heic-converter: the EXIF injector chunk could not be loaded — converted without metadata; serve every file in dist/ together, with dist/exif-*.mjs as JavaScript.",ScaleInvalid:e=>`Scale must be a positive finite number, got: ${e}`,MaxWidthInvalid:e=>`maxWidth must be a positive finite number, got: ${e}`,MaxHeightInvalid:e=>`maxHeight must be a positive finite number, got: ${e}`,TargetSizeTooLarge:(e,r,t)=>`Target image size ${e}x${r} exceeds the maximum supported dimension of ${t}px`,BlobToBase64FailedWithCause:e=>`Failed to convert Blob to base64 string: ${e}`,CanvasToBlobFailed:e=>`Failed to convert canvas to blob (type: ${e})`,CanvasUnsupported:"Canvas is not supported in the current environment. In a browser this requires OffscreenCanvas or HTMLCanvasElement. In Node.js there is no canvas: decode raw RGBA with LibheifDecoder and encode externally (see the Node.js section of the README).",InvalidDimensions:(e,r)=>`Invalid image dimensions: ${e}x${r}. Width and height must be positive integers.`,DataLengthMismatch:(e,r,t,n)=>`Image data length mismatch. Expected ${e} bytes for ${r}x${t}, got ${n}`,ContextUnavailable:"Failed to acquire 2D rendering context from canvas",UnsupportedFormat:e=>`Unsupported output format: ${e}`,FormatUnsupported:e=>`The current environment cannot encode '${e}' — canvas encoding produced no '${e}' image (e.g. AVIF encoding is not supported in this browser). Try 'jpeg', 'png', or 'webp' instead.`,CropInvalid:(e,r)=>`crop.${e} must be ${"width"===e||"height"===e?"a positive integer":"a non-negative integer"}, got: ${r}`,CropOutOfBounds:(e,r,t,n,o,i)=>`crop ${t}x${n} at (${e}, ${r}) exceeds the ${o}x${i} image (crop coordinates are in post-orientation display pixels)`,GlueApiMissing:e=>`The bundled decoder glue is missing required APIs (${e}) — deploy every file in dist/ from the same release; heic-decoder.wasm and its glue chunk must come from one build.`,DecoderFreedDuringDecode:"Decoder was freed before decoding completed; call initialize() again.",DecodeInputAllocFailed:e=>`Failed to allocate ${e} bytes in the WASM heap for decode input`,DecodeFailed:e=>`HEIC decoding failed (no result returned; input: ${e} bytes — is the file truncated or empty?)`,DecodeFailedWithDetail:(e,r)=>`HEIC decoding failed: ${e} (input: ${r} bytes)`,DecodeFaulted:e=>`Decoder faulted on a ${e}-byte image (out of memory, or a corrupted WebAssembly instance); retry — a faulted pooled decoder is discarded, not reused`,ProgressCallbackThrew:e=>`onProgress callback threw during decode: ${e}`};function t(e){const r=Number(e);return Number.isFinite(r)?Math.min(100,Math.max(0,r)):0}function n(t){return new e.HeicConverterError("progress_callback_failed",r.ProgressCallbackThrew(t instanceof Error?t.message:String(t)),{cause:t})}function o(e){return"function"==typeof e?e:void 0}var i=["jpeg","jpg","png","svg","webp","avif"];function a(t,n){if(void 0!==n&&"boolean"!=typeof n)throw new e.HeicConverterError("invalid_input",r.BooleanOptionInvalid(t,n))}function d(t){const n=String(t).toLowerCase();if(!i.includes(n))throw new e.HeicConverterError("invalid_format",r.UnsupportedFormat(String(t)))}function s(t){if(!t)return;const{maxWidth:n,maxHeight:o,scale:i}=t;if(void 0!==i&&("number"!=typeof i||!Number.isFinite(i)||i<=0))throw new e.HeicConverterError("invalid_resize",r.ScaleInvalid(i));if(void 0!==n&&("number"!=typeof n||!Number.isFinite(n)||n<=0))throw new e.HeicConverterError("invalid_resize",r.MaxWidthInvalid(n));if(void 0!==o&&("number"!=typeof o||!Number.isFinite(o)||o<=0))throw new e.HeicConverterError("invalid_resize",r.MaxHeightInvalid(o))}function c(t){if(!t)return;const{x:n=0,y:o=0,width:i,height:a}=t;if(!Number.isInteger(i)||i<=0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("width",i));if(!Number.isInteger(a)||a<=0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("height",a));if(!Number.isInteger(n)||n<0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("x",n));if(!Number.isInteger(o)||o<0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("y",o))}exports.DEFAULT_QUALITY=.92,exports.MAX_BATCH_CONCURRENCY=64,exports.Messages=r,exports.SUPPORTED_FORMATS=i,exports.clampPercent=t,exports.progressCallbackError=n,exports.progressCallbackFor=o,exports.progressGateFor=function(e){const r=o(e);return r?function(e){let r,o=!1;return{report:n=>{if(o)return;const i=t(n);if(!(i>=100))try{e(i)}catch(e){r=r??e}},complete:()=>{if(!o){if(o=!0,void 0!==r)throw n(r);try{e(100)}catch(e){throw n(e)}}},pendingError:()=>void 0===r?void 0:n(r)}}(r):void 0},exports.runBoundedBatch=async function(t,n,o,i){const a=!0===i?.continueOnError,d=i?.signal,s=new Array(t.length);let c=0,l=!1,u=0,v=null,h=-1,p=0;const f=[];let g;const m=new Promise(e=>{g=e}),b=()=>g?.();d&&!a&&d.addEventListener("abort",b,{once:!0});const w=function(e,r){return Math.min(e,r)}(n,t.length),y=Array.from({length:w},()=>(async()=>{for(;!l&&!d?.aborted||a;){const n=c;if(c+=1,n>=t.length)return;if(a&&d?.aborted){const o=new e.HeicConverterError("aborted",r.Aborted);for(let e=n;e<t.length;e++)s[e]={index:e,ok:!1,error:o};return void(c=t.length)}try{const e=await o(t[n],n);s[n]={index:n,ok:!0,result:e},u+=1}catch(e){if(p+=1,a){s[n]={index:n,ok:!1,error:e instanceof Error?e:new Error(String(e))};continue}l?f.length<2&&f.push(e instanceof Error?e.message:String(e)):(l=!0,v=e,h=n,g?.())}}})());try{if(a)return await Promise.all(y),s;if(await Promise.race([Promise.all(y),m]),u===t.length)return s.map(n=>{if(!n||!n.ok)throw new e.HeicConverterError("batch_item_failed",r.BatchItemProducedNoResult((n?.index??0)+1,t.length));return n.result});if(d?.aborted)throw new e.HeicConverterError("aborted",r.Aborted);if(l){const n=v instanceof Error?v.message:String(v);let o=r.ConvertManyItemFailed(h+1,t.length,n);throw p>1&&(o+=r.ConvertManyExtraFailures(p,t.length),f.length>0&&(o+=r.ConvertManyOtherErrors(f))),new e.HeicConverterError("batch_item_failed",o,{cause:v,itemIndex:h,itemTotal:t.length,failedCount:p})}throw new e.HeicConverterError("batch_item_failed",r.BatchEndedWithoutSettling(t.length))}finally{d?.removeEventListener("abort",b)}},exports.throwIfAborted=function(t){if(t?.aborted)throw new e.HeicConverterError("aborted",r.Aborted)},exports.validateBatchOptions=function(e){a("continueOnError",e?.continueOnError),a("reuseDecoders",e?.reuseDecoders)},exports.validateConcurrency=function(t){if(!Number.isInteger(t)||t<1||t>64)throw new e.HeicConverterError("invalid_concurrency",r.ConcurrencyInvalid(t,64))},exports.validateConvertOptions=function(t){d(t?.to??"jpeg"),void 0!==t?.quality&&function(t){if("number"!=typeof t||!Number.isFinite(t)||t<0||t>1)throw new e.HeicConverterError("invalid_quality",r.QualityInvalid(t))}(t.quality),a("applyOrientation",t?.applyOrientation),function(t){if(void 0!==t&&"blob"!==t&&"dataUrl"!==t&&"arrayBuffer"!==t)throw new e.HeicConverterError("invalid_input",r.OutputShapeInvalid(t))}(t?.output),function(t){if(void 0!==t&&("object"!=typeof t||null===t||"function"!=typeof t.addEventListener))throw new e.HeicConverterError("invalid_input",r.SignalInvalid(t))}(t?.signal),c(t?.crop),a("preserveExif",t?.preserveExif),a("nativeDecode",t?.nativeDecode),s(t)},exports.validateCrop=c,exports.validateFormat=d,exports.validateResize=s;
1
+ var e=require("./chunk-N2LCVW2Q.js"),r={QualityInvalid:e=>`Quality must be a number between 0.0 and 1.0, got: ${e}`,BooleanOptionInvalid:(e,r)=>`${e} must be a boolean, got: ${r}`,UnsupportedInputType:e=>`Unsupported input type. Expected Blob (incl. File), ArrayBuffer, or ArrayBufferView. Got: ${e}`,DecoderInitFailed:e=>`Failed to initialize HEIC decoder: ${e} — verify heic-decoder.wasm is served (dist/heic-decoder.wasm; see the README "Serving and Locating WASM" section / locateFile option) and that your CSP allows 'wasm-unsafe-eval'`,WorkerChunkLoadFailed:e=>`Failed to load the Web Worker implementation chunk (dist/worker-*.mjs): ${e} — deploy every file in dist/ together, or use convertHeic to convert in the current thread`,NativeChunkLoadWarning:e=>`@keeratita/heic-converter: the native-decode chunk could not be loaded (${e}) — converting with the bundled decoder; serve every file in dist/ together, with dist/native-*.mjs as JavaScript`,RenderEncodeFailed:(e,r)=>`Failed to render and encode image as ${e}: ${r}`,ConcurrencyInvalid:(e,r)=>`Concurrency must be an integer between 1 and ${r}, got: ${e}`,InputsMustBeArray:"Inputs must be an array of HEIC images",OutputShapeInvalid:e=>`output must be one of 'blob', 'dataUrl', 'arrayBuffer', got: ${e}`,SignalInvalid:e=>`signal must be an AbortSignal, got: ${e}`,Aborted:"Conversion aborted (AbortSignal was aborted)",ConvertManyItemFailed:(e,r,t)=>`Conversion of item ${e} of ${r} failed: ${t}`,BatchItemProducedNoResult:(e,r)=>`Conversion of item ${e} of ${r} failed: item produced no result`,BatchEndedWithoutSettling:e=>`Batch ended without settling any of its ${e} items`,ConvertManyExtraFailures:(e,r)=>` (${e} of ${r} items failed in total)`,ConvertManyOtherErrors:e=>`; other errors: ${e.join(" | ")}`,ExifChunkLoadWarning:"@keeratita/heic-converter: the EXIF injector chunk could not be loaded — converted without metadata; serve every file in dist/ together, with dist/exif-*.mjs as JavaScript.",ScaleInvalid:e=>`Scale must be a positive finite number, got: ${e}`,MaxWidthInvalid:e=>`maxWidth must be a positive finite number, got: ${e}`,MaxHeightInvalid:e=>`maxHeight must be a positive finite number, got: ${e}`,TargetSizeTooLarge:(e,r,t)=>`Target image size ${e}x${r} exceeds the maximum supported dimension of ${t}px`,BlobToBase64FailedWithCause:e=>`Failed to convert Blob to base64 string: ${e}`,CanvasToBlobFailed:e=>`Failed to convert canvas to blob (type: ${e})`,CanvasUnsupported:"Canvas is not supported in the current environment. In a browser this requires OffscreenCanvas or HTMLCanvasElement. In Node.js there is no canvas: decode raw RGBA with LibheifDecoder and encode externally (see the Node.js section of the README).",InvalidDimensions:(e,r)=>`Invalid image dimensions: ${e}x${r}. Width and height must be positive integers.`,DataLengthMismatch:(e,r,t,n)=>`Image data length mismatch. Expected ${e} bytes for ${r}x${t}, got ${n}`,ContextUnavailable:"Failed to acquire 2D rendering context from canvas",UnsupportedFormat:e=>`Unsupported output format: ${e}`,FormatUnsupported:e=>`The current environment cannot encode '${e}' — canvas encoding produced no '${e}' image (e.g. AVIF encoding is not supported in this browser). Try 'jpeg', 'png', or 'webp' instead.`,CropInvalid:(e,r)=>`crop.${e} must be ${"width"===e||"height"===e?"a positive integer":"a non-negative integer"}, got: ${r}`,CropOutOfBounds:(e,r,t,n,o,i)=>`crop ${t}x${n} at (${e}, ${r}) exceeds the ${o}x${i} image (crop coordinates are in post-orientation display pixels)`,GlueApiMissing:e=>`The bundled decoder glue is missing required APIs (${e}) — deploy every file in dist/ from the same release; heic-decoder.wasm and its glue chunk must come from one build.`,DecoderFreedDuringDecode:"Decoder was freed before decoding completed; call initialize() again.",DecodeInputAllocFailed:e=>`Failed to allocate ${e} bytes in the WASM heap for decode input`,DecodeFailed:e=>`HEIC decoding failed (no result returned; input: ${e} bytes — is the file truncated or empty?)`,DecodeFailedWithDetail:(e,r)=>`HEIC decoding failed: ${e} (input: ${r} bytes)`,DecodeFaulted:e=>`Decoder faulted on a ${e}-byte image (out of memory, or a corrupted WebAssembly instance); retry — a faulted pooled decoder is discarded, not reused`,ProgressCallbackThrew:e=>`onProgress callback threw during decode: ${e}`};function t(e){const r=Number(e);return Number.isFinite(r)?Math.min(100,Math.max(0,r)):0}function n(t){return new e.HeicConverterError("progress_callback_failed",r.ProgressCallbackThrew(t instanceof Error?t.message:String(t)),{cause:t})}function o(e){return"function"==typeof e?e:void 0}var i=["jpeg","jpg","png","svg","webp","avif"];function a(t,n){if(void 0!==n&&"boolean"!=typeof n)throw new e.HeicConverterError("invalid_input",r.BooleanOptionInvalid(t,n))}function d(t){const n=String(t).toLowerCase();if(!i.includes(n))throw new e.HeicConverterError("invalid_format",r.UnsupportedFormat(String(t)))}function s(t){if(!t)return;const{maxWidth:n,maxHeight:o,scale:i}=t;if(void 0!==i&&("number"!=typeof i||!Number.isFinite(i)||i<=0))throw new e.HeicConverterError("invalid_resize",r.ScaleInvalid(i));if(void 0!==n&&("number"!=typeof n||!Number.isFinite(n)||n<=0))throw new e.HeicConverterError("invalid_resize",r.MaxWidthInvalid(n));if(void 0!==o&&("number"!=typeof o||!Number.isFinite(o)||o<=0))throw new e.HeicConverterError("invalid_resize",r.MaxHeightInvalid(o))}function c(t){if(!t)return;const{x:n=0,y:o=0,width:i,height:a}=t;if(!Number.isInteger(i)||i<=0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("width",i));if(!Number.isInteger(a)||a<=0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("height",a));if(!Number.isInteger(n)||n<0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("x",n));if(!Number.isInteger(o)||o<0)throw new e.HeicConverterError("invalid_crop",r.CropInvalid("y",o))}exports.DEFAULT_QUALITY=.92,exports.MAX_BATCH_CONCURRENCY=64,exports.Messages=r,exports.SUPPORTED_FORMATS=i,exports.clampPercent=t,exports.progressCallbackError=n,exports.progressCallbackFor=o,exports.progressGateFor=function(e){const r=o(e);return r?function(e){let r,o=!1;return{report:n=>{if(o)return;const i=t(n);if(!(i>=100))try{e(i)}catch(e){r=r??e}},complete:()=>{if(!o){if(o=!0,void 0!==r)throw n(r);try{e(100)}catch(e){throw n(e)}}},pendingError:()=>void 0===r?void 0:n(r)}}(r):void 0},exports.runBoundedBatch=async function(t,n,o,i){const a=!0===i?.continueOnError,d=i?.signal,s=new Array(t.length);let c=0,l=!1,u=0,v=null,h=-1,p=0;const f=[];let g;const m=new Promise(e=>{g=e}),b=()=>g?.();d&&!a&&d.addEventListener("abort",b,{once:!0});const w=function(e,r){return Math.min(e,r)}(n,t.length),y=Array.from({length:w},()=>(async()=>{for(;!l&&!d?.aborted||a;){const n=c;if(c+=1,n>=t.length)return;if(a&&d?.aborted){const o=new e.HeicConverterError("aborted",r.Aborted);for(let e=n;e<t.length;e++)s[e]={index:e,ok:!1,error:o};return void(c=t.length)}try{const e=await o(t[n],n);s[n]={index:n,ok:!0,result:e},u+=1}catch(e){if(p+=1,a){s[n]={index:n,ok:!1,error:e instanceof Error?e:new Error(String(e))};continue}l?f.length<2&&f.push(e instanceof Error?e.message:String(e)):(l=!0,v=e,h=n,g?.())}}})());try{if(a)return await Promise.all(y),s;if(await Promise.race([Promise.all(y),m]),u===t.length)return s.map(n=>{if(!n||!n.ok)throw new e.HeicConverterError("batch_item_failed",r.BatchItemProducedNoResult((n?.index??0)+1,t.length));return n.result});if(d?.aborted)throw new e.HeicConverterError("aborted",r.Aborted);if(l){const n=v instanceof Error?v.message:String(v);let o=r.ConvertManyItemFailed(h+1,t.length,n);throw p>1&&(o+=r.ConvertManyExtraFailures(p,t.length),f.length>0&&(o+=r.ConvertManyOtherErrors(f))),new e.HeicConverterError("batch_item_failed",o,{cause:v,itemIndex:h,itemTotal:t.length,failedCount:p})}throw new e.HeicConverterError("batch_item_failed",r.BatchEndedWithoutSettling(t.length))}finally{d?.removeEventListener("abort",b)}},exports.throwIfAborted=function(t){if(t?.aborted)throw new e.HeicConverterError("aborted",r.Aborted)},exports.validateBatchOptions=function(e){a("continueOnError",e?.continueOnError),a("reuseDecoders",e?.reuseDecoders)},exports.validateConcurrency=function(t){if(!Number.isInteger(t)||t<1||t>64)throw new e.HeicConverterError("invalid_concurrency",r.ConcurrencyInvalid(t,64))},exports.validateConvertOptions=function(t){d(t?.to??"jpeg"),void 0!==t?.quality&&function(t){if("number"!=typeof t||!Number.isFinite(t)||t<0||t>1)throw new e.HeicConverterError("invalid_quality",r.QualityInvalid(t))}(t.quality),a("applyOrientation",t?.applyOrientation),function(t){if(void 0!==t&&"blob"!==t&&"dataUrl"!==t&&"arrayBuffer"!==t)throw new e.HeicConverterError("invalid_input",r.OutputShapeInvalid(t))}(t?.output),function(t){if(void 0!==t&&("object"!=typeof t||null===t||"function"!=typeof t.addEventListener))throw new e.HeicConverterError("invalid_input",r.SignalInvalid(t))}(t?.signal),c(t?.crop),a("preserveExif",t?.preserveExif),a("nativeDecode",t?.nativeDecode),s(t)},exports.validateCrop=c,exports.validateFormat=d,exports.validateResize=s;
@@ -1 +1 @@
1
- "use strict";var e=class extends Error{code;itemIndex;itemTotal;failedCount;constructor(e,t,i){super(t,{cause:i?.cause}),this.name="HeicConverterError",this.code=e,void 0!==i?.itemIndex&&(this.itemIndex=i.itemIndex),void 0!==i?.itemTotal&&(this.itemTotal=i.itemTotal),void 0!==i?.failedCount&&(this.failedCount=i.failedCount)}};exports.HeicConverterError=e;
1
+ var e=class extends Error{code;itemIndex;itemTotal;failedCount;constructor(e,t,i){super(t,{cause:i?.cause}),this.name="HeicConverterError",this.code=e,void 0!==i?.itemIndex&&(this.itemIndex=i.itemIndex),void 0!==i?.itemTotal&&(this.itemTotal=i.itemTotal),void 0!==i?.failedCount&&(this.failedCount=i.failedCount)}};exports.HeicConverterError=e;
@@ -1 +1 @@
1
- "use strict";var t,n=new Uint8Array([69,120,105,102,0,0]),r=new Uint8Array([137,80,78,71,13,10,26,10]);function e(t){if(t.length<n.length+8)return!1;for(let r=0;r<n.length;r++)if(t[r]!==n[r])return!1;return function(t,n){if(n+8>t.length)return!1;const r=73===t[n]&&73===t[n+1],e=77===t[n]&&77===t[n+1];return!(!r&&!e)&&42==(r?t[n+2]|t[n+3]<<8:t[n+2]<<8|t[n+3])}(t,n.length)}function u(t,n){return t[n]<<8|t[n+1]}function i(t,n){return(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0}function l(t,n,r){return t[n]===r.charCodeAt(0)&&t[n+1]===r.charCodeAt(1)&&t[n+2]===r.charCodeAt(2)&&t[n+3]===r.charCodeAt(3)}exports.injectExifIntoJpeg=function(t,n){try{if(t.length<4||255!==t[0]||216!==t[1])return t;if(!e(n))return t;const r=n.length+2;if(r>65535)return t;let i=2;for(;i<t.length;){if(i+4>t.length)return t;if(255!==t[i])return t;const n=t[i+1];if(255===n){i+=1;continue}if(!(n>=224&&n<=239||254===n))break;const r=u(t,i+2);if(r<2||i+2+r>t.length)return t;i+=2+r}const l=new Uint8Array(t.length+4+n.length);return l.set(t.subarray(0,i),0),l[i]=255,l[i+1]=225,l[i+2]=r>>8&255,l[i+3]=255&r,l.set(n,i+4),l.set(t.subarray(i),i+4+n.length),l}catch{return t}},exports.injectExifIntoPng=function(u,o){try{if(u.length<33)return u;for(let t=0;t<r.length;t++)if(u[t]!==r[t])return u;if(13!==i(u,8)||!l(u,12,"IHDR"))return u;if(!e(o))return u;const f=o.subarray(n.length);let h=33;for(;h+8<=u.length;){const t=i(u,h);if(t>u.length||h+12+t>u.length)return u;if(l(u,h+4,"IDAT")||l(u,h+4,"IEND"))break;if(l(u,h+4,"eXIf"))return u;h+=12+t}const c=new Uint8Array(12+f.length);c[0]=f.length>>>24&255,c[1]=f.length>>>16&255,c[2]=f.length>>>8&255,c[3]=255&f.length,c.set([101,88,73,102],4),c.set(f,8);const g=function(n){const r=function(){if(!t){t=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let t=0;t<8;t++)r=1&r?3988292384^r>>>1:r>>>1;t[n]=r>>>0}}return t}();let e=4294967295;for(let t=0;t<n.length;t++)e=r[255&(e^n[t])]^e>>>8;return(4294967295^e)>>>0}(c.subarray(4,8+f.length));c[8+f.length]=g>>>24&255,c[9+f.length]=g>>>16&255,c[10+f.length]=g>>>8&255,c[11+f.length]=255&g;const s=new Uint8Array(u.length+c.length);return s.set(u.subarray(0,h),0),s.set(c,h),s.set(u.subarray(h),h+c.length),s}catch{return u}},exports.normalizeOrientationTag=function(t){try{if(!e(t))return t;const r=n.length,u=73===t[r],i=n=>u?t[n]|t[n+1]<<8:t[n]<<8|t[n+1],l=n=>u?(t[n+3]<<24|t[n+2]<<16|t[n+1]<<8|t[n])>>>0:(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0,o=l(r+4);if(o<8||r+o+2>t.length)return t;const f=r+o,h=i(f);for(let n=0;n<h;n++){const r=f+2+12*n;if(r+12>t.length)return t;if(274!==i(r))continue;const e=i(r+2),o=l(r+4);if(3!==e||1!==o)return t;if(1==(u?t[r+8]|t[r+9]<<8:t[r+8]<<8|t[r+9]))return t;const h=t.slice();return h[r+8]=u?1:0,h[r+9]=u?0:1,h[r+10]=0,h[r+11]=0,h}return t}catch{return t}};
1
+ var t,n=new Uint8Array([69,120,105,102,0,0]),r=new Uint8Array([137,80,78,71,13,10,26,10]);function e(t){if(t.length<n.length+8)return!1;for(let r=0;r<n.length;r++)if(t[r]!==n[r])return!1;return function(t,n){if(n+8>t.length)return!1;const r=73===t[n]&&73===t[n+1],e=77===t[n]&&77===t[n+1];return!(!r&&!e)&&42==(r?t[n+2]|t[n+3]<<8:t[n+2]<<8|t[n+3])}(t,n.length)}function u(t,n){return t[n]<<8|t[n+1]}function i(t,n){return(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0}function l(t,n,r){return t[n]===r.charCodeAt(0)&&t[n+1]===r.charCodeAt(1)&&t[n+2]===r.charCodeAt(2)&&t[n+3]===r.charCodeAt(3)}exports.injectExifIntoJpeg=function(t,n){try{if(t.length<4||255!==t[0]||216!==t[1])return t;if(!e(n))return t;const r=n.length+2;if(r>65535)return t;let i=2;for(;i<t.length;){if(i+4>t.length)return t;if(255!==t[i])return t;const n=t[i+1];if(255===n){i+=1;continue}if(!(n>=224&&n<=239||254===n))break;const r=u(t,i+2);if(r<2||i+2+r>t.length)return t;i+=2+r}const l=new Uint8Array(t.length+4+n.length);return l.set(t.subarray(0,i),0),l[i]=255,l[i+1]=225,l[i+2]=r>>8&255,l[i+3]=255&r,l.set(n,i+4),l.set(t.subarray(i),i+4+n.length),l}catch{return t}},exports.injectExifIntoPng=function(u,o){try{if(u.length<33)return u;for(let t=0;t<r.length;t++)if(u[t]!==r[t])return u;if(13!==i(u,8)||!l(u,12,"IHDR"))return u;if(!e(o))return u;const f=o.subarray(n.length);let h=33;for(;h+8<=u.length;){const t=i(u,h);if(t>u.length||h+12+t>u.length)return u;if(l(u,h+4,"IDAT")||l(u,h+4,"IEND"))break;if(l(u,h+4,"eXIf"))return u;h+=12+t}const c=new Uint8Array(12+f.length);c[0]=f.length>>>24&255,c[1]=f.length>>>16&255,c[2]=f.length>>>8&255,c[3]=255&f.length,c.set([101,88,73,102],4),c.set(f,8);const g=function(n){const r=function(){if(!t){t=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let t=0;t<8;t++)r=1&r?3988292384^r>>>1:r>>>1;t[n]=r>>>0}}return t}();let e=4294967295;for(let t=0;t<n.length;t++)e=r[255&(e^n[t])]^e>>>8;return(4294967295^e)>>>0}(c.subarray(4,8+f.length));c[8+f.length]=g>>>24&255,c[9+f.length]=g>>>16&255,c[10+f.length]=g>>>8&255,c[11+f.length]=255&g;const s=new Uint8Array(u.length+c.length);return s.set(u.subarray(0,h),0),s.set(c,h),s.set(u.subarray(h),h+c.length),s}catch{return u}},exports.normalizeOrientationTag=function(t){try{if(!e(t))return t;const r=n.length,u=73===t[r],i=n=>u?t[n]|t[n+1]<<8:t[n]<<8|t[n+1],l=n=>u?(t[n+3]<<24|t[n+2]<<16|t[n+1]<<8|t[n])>>>0:(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0,o=l(r+4);if(o<8||r+o+2>t.length)return t;const f=r+o,h=i(f);for(let n=0;n<h;n++){const r=f+2+12*n;if(r+12>t.length)return t;if(274!==i(r))continue;const e=i(r+2),o=l(r+4);if(3!==e||1!==o)return t;if(1==(u?t[r+8]|t[r+9]<<8:t[r+8]<<8|t[r+9]))return t;const h=t.slice();return h[r+8]=u?1:0,h[r+9]=u?0:1,h[r+10]=0,h[r+11]=0,h}return t}catch{return t}};
@@ -0,0 +1 @@
1
+ var r="undefined"!=typeof document?document.currentScript:null;module.exports=async function(t={}){var e=t,n=!!globalThis.window,a=!!globalThis.WorkerGlobalScope,i=globalThis.process?.versions?.node&&"renderer"!=globalThis.process?.type;if(i){const{createRequire:t}=await(import("module"));var o=t("undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("heic-decoder-LWGIYGE3.js",document.baseURI).href)}var s,c,f="./this.program",u="undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("heic-decoder-LWGIYGE3.js",document.baseURI).href,h="";if(i){var l=o("node:fs");u.startsWith("file:")&&(h=o("node:path").dirname(o("node:url").fileURLToPath(u))+"/"),c=r=>(r=y(r)?new URL(r):r,l.readFileSync(r)),s=async(r,t=!0)=>(r=y(r)?new URL(r):r,l.readFileSync(r,t?void 0:"utf8")),process.argv.length>1&&(f=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2)}else if(n||a){try{h=new URL(".",u).href}catch{}a&&(c=r=>{var t=new XMLHttpRequest;return t.open("GET",r,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),s=async r=>{var t=await fetch(r,{credentials:"same-origin"});if(t.ok)return t.arrayBuffer();throw new Error(t.status+" : "+t.url)}}var v,p,d=console.log.bind(console),w=console.error.bind(console),g=!1,y=r=>r.startsWith("file://");class m{}class _ extends m{constructor(r){super(),this.excPtr=r}}function b(){if(!p?.buffer?.resizable){var r=er.buffer;p=new Int8Array(r),e.HEAPU8=E=new Uint8Array(r),U=new Uint32Array(r)}}function R(r){throw e.onAbort?.(r),w(r=`Aborted(${r})`),g=!0,r+=". Build with -sASSERTIONS for more info.",new WebAssembly.RuntimeError(r)}var U,T=r=>{for(;r.length>0;)r.shift()(e)},L=[],P=[],A=r=>Q(r),C=()=>X();class S{constructor(r){this.excPtr=r,this.ptr=r-24}set_type(r){U[this.ptr+4>>2]=r}get_type(){return U[this.ptr+4>>2]}set_destructor(r){U[this.ptr+8>>2]=r}get_destructor(){return U[this.ptr+8>>2]}set_caught(r){r=r?1:0,p[this.ptr+12]=r}get_caught(){return 0!=p[this.ptr+12]}set_rethrown(r){r=r?1:0,p[this.ptr+13]=r}get_rethrown(){return 0!=p[this.ptr+13]}init(r,t){this.set_adjusted_ptr(0),this.set_type(r),this.set_destructor(t)}set_adjusted_ptr(r){U[this.ptr+16>>2]=r}get_adjusted_ptr(){return U[this.ptr+16>>2]}}var E,x=[],I=0,G=null,W=r=>K(r),F=r=>{var t=G?.excPtr;if(!t)return W(0),0;var e=new S(t);e.set_adjusted_ptr(t);var n=e.get_type();if(!n)return W(0),t;for(var a of r){if(!a||a===n)break;var i=e.ptr+16;if(rr(a,n,i))return W(a),t}return W(n),t},k=r=>{throw r},j=(r,t)=>Math.ceil(r/t)*t,M=r=>{var t=(r-er.buffer.byteLength+65535)/65536|0;try{return er.grow(t),b(),1}catch(r){}},N={},q=()=>{if(!q.strings){var r={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:f};for(var t in N)void 0===N[t]?delete r[t]:r[t]=N[t];var e=[];for(var t in r)e.push(`${t}=${r[t]}`);q.strings=e}return q.strings},H=(r,t,e)=>((r,t,e,n)=>{for(var a=e,i=e+n-1,o=0;o<r.length;++o){var s=r.codePointAt(o);if(s<=127){if(e>=i)break;t[e++]=s}else if(s<=2047){if(e+1>=i)break;t[e++]=192|s>>6,t[e++]=128|63&s}else if(s<=65535){if(e+2>=i)break;t[e++]=224|s>>12,t[e++]=128|s>>6&63,t[e++]=128|63&s}else{if(e+3>=i)break;t[e++]=240|s>>18,t[e++]=128|s>>12&63,t[e++]=128|s>>6&63,t[e++]=128|63&s,o++}}return t[e]=0,e-a})(r,E,t,e),$=r=>{for(var t=0,e=0;e<r.length;++e){var n=r.codePointAt(e);n<=127?t++:n<=2047?t+=2:n<=65535?t+=3:(t+=4,e++)}return t},B=globalThis.TextDecoder&&new TextDecoder,D=[null,[],[]],O=(r,t)=>{var e=D[r];t&&10!==t?e.push(t):((1===r?d:w)(((r,t=0)=>{var e=((r,t)=>{for(var e=t+void 0;r[t]&&!(t>=e);)++t;return t})(r,t);if(e-t>16&&r.buffer&&B)return B.decode(r.subarray(t,e));for(var n="";t<e;){var a=r[t++];if(128&a){var i=63&r[t++];if(192!=(224&a)){var o=63&r[t++];if((a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&r[t++])<65536)n+=String.fromCharCode(a);else{var s=a-65536;n+=String.fromCharCode(55296|s>>10,56320|1023&s)}}else n+=String.fromCharCode((31&a)<<6|i)}else n+=String.fromCharCode(a)}return n})(e)),e.length=0)},z=[],Y=r=>{var t=z[r];return t||(z[r]=t=nr.get(r)),t};e.noExitRuntime&&e.noExitRuntime,e.print&&(d=e.print),e.printErr&&(w=e.printErr),e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram);var J,K,Q,X,V,Z,rr,tr,er,nr,ar=e.preInit;if(ar)for("function"==typeof ar&&(e.preInit=ar=[ar]);ar.length>0;)ar.shift()();var ir,or={j:r=>{var t=new S(r);return t.get_caught()||(t.set_caught(!0),I--),t.set_rethrown(!1),x.push(t),tr(r)},l:()=>{J(0,0);var r=x.pop();V(r.excPtr),G=null},a:()=>F([]),b:r=>F([r]),u:()=>{x.length||R("no exception to throw");var r=x.at(-1),t=r.excPtr;r.set_rethrown(!0),r.set_caught(!1),I++,Z(t),t=G=new _(t),k(t)},h:(r,t,e)=>{new S(r).init(t,e),Z(r),r=G=new _(r),I++,k(r)},t:()=>I,e:r=>{(r=>{throw r})(r=G??=new _(r))},w:()=>{},y:()=>R(""),n:function(r){try{e.__progressCb&&e.__progressCb(r)}catch(r){}},v:r=>{var t=E.length,e=2147483648;if((r>>>=0)>e)return!1;for(var n=1;n<=4;n*=2){var a=t*(1+.2/n);a=Math.min(a,r+100663296);var i=Math.min(e,j(Math.max(r,a),65536));if(M(i))return!0}return!1},A:(r,t)=>{var e=0,n=0;for(var a of q()){var i=t+e;U[r+n>>2]=i,e+=H(a,i,1/0)+1,n+=4}return 0},B:(r,t)=>{var e=q();U[r>>2]=e.length;var n=0;for(var a of e)n+=$(a)+1;return U[t>>2]=n,0},x:()=>52,z:function(r,t){return 70},o:(r,t,e,n)=>{for(var a=0,i=0;i<e;i++){var o=U[t>>2],s=U[t+4>>2];t+=8;for(var c=0;c<s;c++)O(r,E[o+c]);a+=s}return U[n>>2]=a,0},c:function(r,t){var e=C();try{return Y(r)(t)}catch(r){if(A(e),!(r instanceof m))throw r;J(1,0)}},d:function(r,t,e){var n=C();try{return Y(r)(t,e)}catch(r){if(A(n),!(r instanceof m))throw r;J(1,0)}},i:function(r,t,e,n){var a=C();try{return Y(r)(t,e,n)}catch(r){if(A(a),!(r instanceof m))throw r;J(1,0)}},q:function(r,t,e,n,a){var i=C();try{return Y(r)(t,e,n,a)}catch(r){if(A(i),!(r instanceof m))throw r;J(1,0)}},m:function(r,t,e,n,a,i){var o=C();try{return Y(r)(t,e,n,a,i)}catch(r){if(A(o),!(r instanceof m))throw r;J(1,0)}},s:function(r,t,e,n,a,i){var o=C();try{return Y(r)(t,e,n,a,i)}catch(r){if(A(o),!(r instanceof m))throw r;J(1,0)}},k:function(r){var t=C();try{Y(r)()}catch(r){if(A(t),!(r instanceof m))throw r;J(1,0)}},C:function(r,t){var e=C();try{Y(r)(t)}catch(r){if(A(e),!(r instanceof m))throw r;J(1,0)}},g:function(r,t){var e=C();try{Y(r)(t)}catch(r){if(A(e),!(r instanceof m))throw r;J(1,0)}},f:function(r,t,e){var n=C();try{Y(r)(t,e)}catch(r){if(A(n),!(r instanceof m))throw r;J(1,0)}},r:function(r,t,e,n){var a=C();try{Y(r)(t,e,n)}catch(r){if(A(a),!(r instanceof m))throw r;J(1,0)}},p:function(r,t,e,n,a){var i=C();try{Y(r)(t,e,n,a)}catch(r){if(A(i),!(r instanceof m))throw r;J(1,0)}},D:function(r,t,e){var n=C();try{Y(r)(t,e)}catch(r){if(A(n),!(r instanceof m))throw r;J(1,0)}}};return ir=await async function(){function t(r){var t;return t=ir=r.exports,e._heic_decode=t.G,e._heic_result_free=t.H,e._free=t.J,e._malloc=t.K,J=t.L,K=t.M,Q=t.N,X=t.O,V=t.P,Z=t.Q,rr=t.R,tr=t.S,er=t.E,nr=t.I,b(),ir}var n,a={a:or},o=e.instantiateWasm;return o?new Promise(r=>{o(a,e=>r(t(e)))}):(v??=e.locateFile?(n="heic-decoder.wasm",e.locateFile?e.locateFile(n,h):h+n):new URL("heic-decoder.wasm","undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("heic-decoder-LWGIYGE3.js",document.baseURI).href).href,t((await async function(r,t,e){if(!i)try{var n=fetch(t,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(n,e)}catch(r){w(`wasm streaming compile failed: ${r}`),w("falling back to ArrayBuffer instantiation")}return async function(r,t){try{var e=await async function(r){try{return await s(r)}catch{}return function(r){if(c)return c(r);throw"both async and sync fetching of the wasm failed"}(r)}(r);return await WebAssembly.instantiate(e,t)}catch(r){w(`failed to asynchronously prepare wasm: ${r}`),R(r)}}(t,e)}(0,v,a)).instance))}(),await async function(){var r;(r=e.preRun)&&("function"==typeof r&&(r=[r]),P.push(...r)),T(P);var t,n=e.setStatus;n&&(n("Running..."),await new Promise(r=>setTimeout(r,1)),setTimeout(n,1,"")),g||(ir.F(),e.onRuntimeInitialized?.(),(t=e.postRun)&&("function"==typeof t&&(t=[t]),L.push(...t)),T(L))}(),e};
@@ -0,0 +1 @@
1
+ var r=async function(r={}){var t=r,e=!!globalThis.window,n=!!globalThis.WorkerGlobalScope,a=globalThis.process?.versions?.node&&"renderer"!=globalThis.process?.type;if(a){const{createRequire:r}=await(import("module"));var i=r(import.meta.url)}var o,s,c="./this.program",f=import.meta.url,u="";if(a){var h=i("node:fs");f.startsWith("file:")&&(u=i("node:path").dirname(i("node:url").fileURLToPath(f))+"/"),s=r=>(r=d(r)?new URL(r):r,h.readFileSync(r)),o=async(r,t=!0)=>(r=d(r)?new URL(r):r,h.readFileSync(r,t?void 0:"utf8")),process.argv.length>1&&(c=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2)}else if(e||n){try{u=new URL(".",f).href}catch{}n&&(s=r=>{var t=new XMLHttpRequest;return t.open("GET",r,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),o=async r=>{var t=await fetch(r,{credentials:"same-origin"});if(t.ok)return t.arrayBuffer();throw new Error(t.status+" : "+t.url)}}var l,v,p=console.log.bind(console),w=console.error.bind(console),g=!1,d=r=>r.startsWith("file://");class y{}class m extends y{constructor(r){super(),this.excPtr=r}}function _(){if(!v?.buffer?.resizable){var r=tr.buffer;v=new Int8Array(r),t.HEAPU8=C=new Uint8Array(r),A=new Uint32Array(r)}}function b(r){throw t.onAbort?.(r),w(r=`Aborted(${r})`),g=!0,r+=". Build with -sASSERTIONS for more info.",new WebAssembly.RuntimeError(r)}var A,R=r=>{for(;r.length>0;)r.shift()(t)},P=[],T=[],x=r=>Q(r),S=()=>X();class E{constructor(r){this.excPtr=r,this.ptr=r-24}set_type(r){A[this.ptr+4>>2]=r}get_type(){return A[this.ptr+4>>2]}set_destructor(r){A[this.ptr+8>>2]=r}get_destructor(){return A[this.ptr+8>>2]}set_caught(r){r=r?1:0,v[this.ptr+12]=r}get_caught(){return 0!=v[this.ptr+12]}set_rethrown(r){r=r?1:0,v[this.ptr+13]=r}get_rethrown(){return 0!=v[this.ptr+13]}init(r,t){this.set_adjusted_ptr(0),this.set_type(r),this.set_destructor(t)}set_adjusted_ptr(r){A[this.ptr+16>>2]=r}get_adjusted_ptr(){return A[this.ptr+16>>2]}}var C,U=[],L=0,k=null,M=r=>K(r),W=r=>{var t=k?.excPtr;if(!t)return M(0),0;var e=new E(t);e.set_adjusted_ptr(t);var n=e.get_type();if(!n)return M(0),t;for(var a of r){if(!a||a===n)break;var i=e.ptr+16;if(Z(a,n,i))return M(a),t}return M(n),t},F=r=>{throw r},I=(r,t)=>Math.ceil(r/t)*t,j=r=>{var t=(r-tr.buffer.byteLength+65535)/65536|0;try{return tr.grow(t),_(),1}catch(r){}},G={},H=()=>{if(!H.strings){var r={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:c};for(var t in G)void 0===G[t]?delete r[t]:r[t]=G[t];var e=[];for(var t in r)e.push(`${t}=${r[t]}`);H.strings=e}return H.strings},$=(r,t,e)=>((r,t,e,n)=>{for(var a=e,i=e+n-1,o=0;o<r.length;++o){var s=r.codePointAt(o);if(s<=127){if(e>=i)break;t[e++]=s}else if(s<=2047){if(e+1>=i)break;t[e++]=192|s>>6,t[e++]=128|63&s}else if(s<=65535){if(e+2>=i)break;t[e++]=224|s>>12,t[e++]=128|s>>6&63,t[e++]=128|63&s}else{if(e+3>=i)break;t[e++]=240|s>>18,t[e++]=128|s>>12&63,t[e++]=128|s>>6&63,t[e++]=128|63&s,o++}}return t[e]=0,e-a})(r,C,t,e),B=r=>{for(var t=0,e=0;e<r.length;++e){var n=r.codePointAt(e);n<=127?t++:n<=2047?t+=2:n<=65535?t+=3:(t+=4,e++)}return t},D=globalThis.TextDecoder&&new TextDecoder,N=[null,[],[]],O=(r,t)=>{var e=N[r];t&&10!==t?e.push(t):((1===r?p:w)(((r,t=0)=>{var e=((r,t)=>{for(var e=t+void 0;r[t]&&!(t>=e);)++t;return t})(r,t);if(e-t>16&&r.buffer&&D)return D.decode(r.subarray(t,e));for(var n="";t<e;){var a=r[t++];if(128&a){var i=63&r[t++];if(192!=(224&a)){var o=63&r[t++];if((a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&r[t++])<65536)n+=String.fromCharCode(a);else{var s=a-65536;n+=String.fromCharCode(55296|s>>10,56320|1023&s)}}else n+=String.fromCharCode((31&a)<<6|i)}else n+=String.fromCharCode(a)}return n})(e)),e.length=0)},q=[],z=r=>{var t=q[r];return t||(q[r]=t=er.get(r)),t};t.noExitRuntime&&t.noExitRuntime,t.print&&(p=t.print),t.printErr&&(w=t.printErr),t.arguments&&t.arguments,t.thisProgram&&(c=t.thisProgram);var J,K,Q,X,V,Y,Z,rr,tr,er,nr=t.preInit;if(nr)for("function"==typeof nr&&(t.preInit=nr=[nr]);nr.length>0;)nr.shift()();var ar,ir={j:r=>{var t=new E(r);return t.get_caught()||(t.set_caught(!0),L--),t.set_rethrown(!1),U.push(t),rr(r)},l:()=>{J(0,0);var r=U.pop();V(r.excPtr),k=null},a:()=>W([]),b:r=>W([r]),u:()=>{U.length||b("no exception to throw");var r=U.at(-1),t=r.excPtr;r.set_rethrown(!0),r.set_caught(!1),L++,Y(t),t=k=new m(t),F(t)},h:(r,t,e)=>{new E(r).init(t,e),Y(r),r=k=new m(r),L++,F(r)},t:()=>L,e:r=>{(r=>{throw r})(r=k??=new m(r))},w:()=>{},y:()=>b(""),n:function(r){try{t.__progressCb&&t.__progressCb(r)}catch(r){}},v:r=>{var t=C.length,e=2147483648;if((r>>>=0)>e)return!1;for(var n=1;n<=4;n*=2){var a=t*(1+.2/n);a=Math.min(a,r+100663296);var i=Math.min(e,I(Math.max(r,a),65536));if(j(i))return!0}return!1},A:(r,t)=>{var e=0,n=0;for(var a of H()){var i=t+e;A[r+n>>2]=i,e+=$(a,i,1/0)+1,n+=4}return 0},B:(r,t)=>{var e=H();A[r>>2]=e.length;var n=0;for(var a of e)n+=B(a)+1;return A[t>>2]=n,0},x:()=>52,z:function(r,t){return 70},o:(r,t,e,n)=>{for(var a=0,i=0;i<e;i++){var o=A[t>>2],s=A[t+4>>2];t+=8;for(var c=0;c<s;c++)O(r,C[o+c]);a+=s}return A[n>>2]=a,0},c:function(r,t){var e=S();try{return z(r)(t)}catch(r){if(x(e),!(r instanceof y))throw r;J(1,0)}},d:function(r,t,e){var n=S();try{return z(r)(t,e)}catch(r){if(x(n),!(r instanceof y))throw r;J(1,0)}},i:function(r,t,e,n){var a=S();try{return z(r)(t,e,n)}catch(r){if(x(a),!(r instanceof y))throw r;J(1,0)}},q:function(r,t,e,n,a){var i=S();try{return z(r)(t,e,n,a)}catch(r){if(x(i),!(r instanceof y))throw r;J(1,0)}},m:function(r,t,e,n,a,i){var o=S();try{return z(r)(t,e,n,a,i)}catch(r){if(x(o),!(r instanceof y))throw r;J(1,0)}},s:function(r,t,e,n,a,i){var o=S();try{return z(r)(t,e,n,a,i)}catch(r){if(x(o),!(r instanceof y))throw r;J(1,0)}},k:function(r){var t=S();try{z(r)()}catch(r){if(x(t),!(r instanceof y))throw r;J(1,0)}},C:function(r,t){var e=S();try{z(r)(t)}catch(r){if(x(e),!(r instanceof y))throw r;J(1,0)}},g:function(r,t){var e=S();try{z(r)(t)}catch(r){if(x(e),!(r instanceof y))throw r;J(1,0)}},f:function(r,t,e){var n=S();try{z(r)(t,e)}catch(r){if(x(n),!(r instanceof y))throw r;J(1,0)}},r:function(r,t,e,n){var a=S();try{z(r)(t,e,n)}catch(r){if(x(a),!(r instanceof y))throw r;J(1,0)}},p:function(r,t,e,n,a){var i=S();try{z(r)(t,e,n,a)}catch(r){if(x(i),!(r instanceof y))throw r;J(1,0)}},D:function(r,t,e){var n=S();try{z(r)(t,e)}catch(r){if(x(n),!(r instanceof y))throw r;J(1,0)}}};return ar=await async function(){function r(r){var e;return e=ar=r.exports,t._heic_decode=e.G,t._heic_result_free=e.H,t._free=e.J,t._malloc=e.K,J=e.L,K=e.M,Q=e.N,X=e.O,V=e.P,Y=e.Q,Z=e.R,rr=e.S,tr=e.E,er=e.I,_(),ar}var e,n={a:ir},i=t.instantiateWasm;return i?new Promise(t=>{i(n,e=>t(r(e)))}):(l??=t.locateFile?(e="heic-decoder.wasm",t.locateFile?t.locateFile(e,u):u+e):new URL("heic-decoder.wasm",import.meta.url).href,r((await async function(r,t,e){if(!a)try{var n=fetch(t,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(n,e)}catch(r){w(`wasm streaming compile failed: ${r}`),w("falling back to ArrayBuffer instantiation")}return async function(r,t){try{var e=await async function(r){try{return await o(r)}catch{}return function(r){if(s)return s(r);throw"both async and sync fetching of the wasm failed"}(r)}(r);return await WebAssembly.instantiate(e,t)}catch(r){w(`failed to asynchronously prepare wasm: ${r}`),b(r)}}(t,e)}(0,l,n)).instance))}(),await async function(){var r;(r=t.preRun)&&("function"==typeof r&&(r=[r]),T.push(...r)),R(T);var e,n=t.setStatus;n&&(n("Running..."),await new Promise(r=>setTimeout(r,1)),setTimeout(n,1,"")),g||(ar.F(),t.onRuntimeInitialized?.(),(e=t.postRun)&&("function"==typeof e&&(e=[e]),P.push(...e)),R(P))}(),t};export{r as default};
Binary file
Binary file
Binary file
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("./chunk-6XIPSRPS.js"),t=require("./chunk-N2LCVW2Q.js"),r=new WeakSet,n=/[\u0000-\u001f\u007f-\u009f]+/g,i=class{options;module=null;initPromise=null;initGeneration=0;constructor(e){this.options=e}async initialize(){if(!this.initPromise){const r=++this.initGeneration,n={};this.options?.moduleOverrides&&Object.assign(n,this.options.moduleOverrides),this.options?.locateFile&&(n.locateFile=this.options.locateFile);const i=import("./heic-decoder-DRALRKX4.js").then(async({default:e})=>{if(this.options?.wasmBinary){const e=await WebAssembly.compile(this.options.wasmBinary);n.instantiateWasm=(t,r)=>r(new WebAssembly.Instance(e,t))}return e(n)}).then(n=>{if(r!==this.initGeneration)return null;const i=["function"==typeof n._heic_decode?null:"_heic_decode","function"==typeof n._heic_result_free?null:"_heic_result_free","function"==typeof n._malloc?null:"_malloc","function"==typeof n._free?null:"_free",n.HEAPU8 instanceof Uint8Array?null:"HEAPU8"].filter(e=>null!==e);if(i.length>0)throw new t.HeicConverterError("decoder_init_failed",e.Messages.GlueApiMissing(i.join(", ")));return this.module=n,n}).catch(e=>{throw this.initPromise===i&&(this.initPromise=null),e});this.initPromise=i}await this.initPromise}async decode(i,o){this.module||await this.initialize();const a=this.module;if(!a)throw new t.HeicConverterError("decode_failed",e.Messages.DecoderFreedDuringDecode);let s;const c=o?t=>{try{o(e.clampPercent(t))}catch(e){s=s??e,a.__progressCb=null}}:null,u=i.buffer===a.HEAPU8.buffer?new Uint8Array(i):i;let f,d=0,l=0;try{if(d=a._malloc(u.byteLength),0===d)throw new t.HeicConverterError("decode_failed",e.Messages.DecodeInputAllocFailed(u.byteLength));a.HEAPU8.set(u,d);const r=a.__progressCb??null;a.__progressCb=c;try{l=a._heic_decode(d,u.byteLength)}finally{a.__progressCb=r}const o=a.HEAPU8;if(0===l)throw new TypeError("heic_decode returned a null result");const s=new DataView(o.buffer,l,36),h=s.getInt32(0,!0);if(0===h){const r=s.getUint32(28,!0),a=s.getUint32(32,!0),c=0!==r?(new TextDecoder).decode(o.subarray(r,r+a)):"";throw new t.HeicConverterError("decode_failed",c?e.Messages.DecodeFailedWithDetail(function(e){const t=e.replace(n," ").trim();return t.length>200?`${t.slice(0,197)}...`:t}(c),i.byteLength):e.Messages.DecodeFailed(i.byteLength))}const w=s.getInt32(4,!0),g=s.getInt32(8,!0),p=g>=1&&g<=8?g:1,v=s.getUint32(12,!0),y=s.getUint32(16,!0),m=4*h,_=new Uint8ClampedArray(m*w);if(y===m)_.set(o.subarray(v,v+m*w));else for(let e=0;e<w;e++)_.set(o.subarray(v+e*y,v+e*y+m),e*m);f={width:h,height:w,data:_},p>1&&(f.orientation=p);const b=s.getUint32(20,!0),C=s.getUint32(24,!0);0!==b&&C>=14&&(f.exif=o.slice(b,b+C))}catch(n){if(n instanceof t.HeicConverterError)throw n;throw r.add(this),new t.HeicConverterError("decode_failed",e.Messages.DecodeFaulted(i.byteLength),{cause:n})}finally{a.__progressCb=null;try{0!==l&&a._heic_result_free(l),0!==d&&a._free(d)}catch{}}if(void 0!==s)throw e.progressCallbackError(s);return f}free(){this.initGeneration+=1,this.module=null,r.delete(this),this.initPromise=null}},o=16384;function a(){if("undefined"==typeof OffscreenCanvas&&"undefined"==typeof document)throw new t.HeicConverterError("unsupported_environment",e.Messages.CanvasUnsupported)}var s=null,c=0;function u(){if(null===s){if(Date.now()<c)return Promise.resolve(void 0);const e=async function(){let e;try{e=w(1,1)}catch{return}const t=h(e,"image/avif");let r;const n=new Promise(e=>{r=setTimeout(()=>e("timeout"),5e3)});try{const e=await Promise.race([t,n]);return"timeout"===e?void 0:"image/avif"===e.type&&e.size>0}finally{void 0!==r&&clearTimeout(r),g(e)}}().catch(()=>{});s=e,e.then(t=>{void 0===t&&s===e&&(s=null,c=Date.now()+1e4)})}return s}async function f(r){if(e.validateFormat(r),"avif"===String(r).toLowerCase()&&!1===await u())throw new t.HeicConverterError("format_unsupported",e.Messages.FormatUnsupported("avif"))}function d(r,n){if(!Number.isFinite(r)||!Number.isFinite(n)||r>o||n>o)throw new t.HeicConverterError("invalid_resize",e.Messages.TargetSizeTooLarge(r,n,o))}async function l(r){try{const e=await r.arrayBuffer(),t=new Uint8Array(e);let n="";const i=32768;for(let e=0;e<t.length;e+=i)n+=String.fromCharCode(...t.subarray(e,e+i));const o=btoa(n);return`data:${r.type};base64,${o}`}catch(r){throw new t.HeicConverterError("render_encode_failed",e.Messages.BlobToBase64FailedWithCause(r instanceof Error?r.message:String(r)),{cause:r})}}function h(r,n,i){return"convertToBlob"in r?r.convertToBlob({type:n,quality:i}):new Promise((o,a)=>{r.toBlob(r=>{r?o(r):a(new t.HeicConverterError("render_encode_failed",e.Messages.CanvasToBlobFailed(n)))},n,i)})}function w(r,n){if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(r,n);if("undefined"!=typeof document){const e=document.createElement("canvas");return e.width=r,e.height=n,e}throw new t.HeicConverterError("unsupported_environment",e.Messages.CanvasUnsupported)}function g(e){const t=e;"function"==typeof t.close?t.close():e.width=0}function p(e,t,r,n){if("undefined"!=typeof ImageData)e.putImageData(new ImageData(t,r,n),0,0);else{const i=e.createImageData(r,n);i.data.set(t),e.putImageData(i,0,0)}}var v=!1;async function y(t,r,n,i,o){const a=r.exif;if(!n||!a||0===a.length)return t;const s=await import("./exif-H2Q7BO7Y.js").catch(()=>null);if(!s)return v||(v=!0,console.warn(e.Messages.ExifChunkLoadWarning)),t;const{injectExifIntoJpeg:c,injectExifIntoPng:u,normalizeOrientationTag:f}=s,d=o?f(a):a,l=new Uint8Array(await t.arrayBuffer()),h="jpeg"===i?c(l,d):u(l,d);return h===l?t:new Blob([h.buffer],{type:t.type})}function m(){return import("./worker-4HVYKWRG.js").catch(r=>{const n=r instanceof Error?r.message:String(r);throw new t.HeicConverterError("worker_load_failed",e.Messages.WorkerChunkLoadFailed(n),{cause:r})})}function _(e){return!0===e?.nativeDecode&&!0!==e?.preserveExif&&!1!==e?.applyOrientation}var b=!1;async function C(r,n){const o=n?.to??"jpeg";e.validateConvertOptions(n),a(),await f(o);const s=n?.signal;e.throwIfAborted(s);const c=n,v=await async function(r){if(r instanceof Uint8Array)return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if("undefined"!=typeof Blob&&r instanceof Blob)return new Uint8Array(await r.arrayBuffer());if(null!==r&&"object"==typeof r&&"function"==typeof r.arrayBuffer){const e=await r.arrayBuffer();if(e instanceof ArrayBuffer)return new Uint8Array(e)}if(ArrayBuffer.isView(r)){const e=r;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}throw new t.HeicConverterError("invalid_input",e.Messages.UnsupportedInputType(Object.prototype.toString.call(r)))}(r);let m,C;e.throwIfAborted(s);let E,I=!1;if(n?.decoder)m=n.decoder,C=!1;else if(_(n)){try{E=await(import("./native-JFFONPCS.js"))}catch(t){M=t instanceof Error?t.message:String(t),b||(b=!0,console.warn(e.Messages.NativeChunkLoadWarning(M)))}void 0===E||E.isNativeHeicRefused()?m=new i:(m=new E.NativeHeicDecoder,I=!0),C=!0}else m=new i,C=!0;var M;let H=!1;const A=()=>{if(C&&!H){H=!0;try{m.free()}catch{}}};try{const r=e.progressGateFor(n?.onProgress),a=async n=>{try{await n.initialize()}catch(r){throw new t.HeicConverterError("decoder_init_failed",e.Messages.DecoderInitFailed(r instanceof Error?r.message:String(r)),{cause:r})}return e.throwIfAborted(s),n.decode(v,r?r.report:void 0)};let f;try{f=await a(m)}catch(r){if(!I)throw r;if(r instanceof t.HeicConverterError&&"aborted"===r.code)throw r;r instanceof t.HeicConverterError&&"decoder_init_failed"===r.code&&E.markNativeHeicRefused(),e.throwIfAborted(s),A(),m=new i,H=!1,I=!1,f=await a(m)}A(),e.throwIfAborted(s);const _=void 0!==n?.quality?n.quality:e.DEFAULT_QUALITY;let b;try{b=await async function(r,n,i,o,a=!0,s,c=!1){e.validateFormat(n),e.validateCrop(s);const f=n.toLowerCase();if("avif"===f&&!1===await u())throw new t.HeicConverterError("format_unsupported",e.Messages.FormatUnsupported("avif"));const{width:v,height:m,data:_}=r;if(!Number.isInteger(v)||v<=0||!Number.isInteger(m)||m<=0)throw new t.HeicConverterError("render_encode_failed",e.Messages.InvalidDimensions(v,m));const b=v*m*4;if(_.length!==b)throw new t.HeicConverterError("render_encode_failed",e.Messages.DataLengthMismatch(b,v,m,_.length));const C=function(e,t){return t&&"number"==typeof e&&Number.isInteger(e)&&e>=1&&e<=8?e:1}(r.orientation,a),E=!(void 0!==r.orientation&&r.orientation>=2&&r.orientation<=8)||a,I=function(e,t,r){switch(e){case 2:return[-1,0,0,1,t,0];case 3:return[-1,0,0,-1,t,r];case 4:return[1,0,0,-1,0,r];case 5:return[0,1,1,0,0,0];case 6:return[0,1,-1,0,r,0];case 7:return[0,-1,-1,0,r,t];case 8:return[0,-1,1,0,0,t];default:return null}}(C,v,m),M=C>=5,H=M?m:v,A=M?v:m,U=s?.x??0,P=s?.y??0,F=s?s.width:H,x=s?s.height:A;if(s&&(U+F>H||P+x>A))throw new t.HeicConverterError("invalid_crop",e.Messages.CropOutOfBounds(U,P,F,x,H,A));const O=function(t,r,n){if(e.validateResize(n),!n)return{width:t,height:r};const{maxWidth:i,maxHeight:o,scale:a}=n;if(void 0!==a){const e=Math.max(1,Math.round(t*a)),n=Math.max(1,Math.round(r*a));return d(e,n),{width:e,height:n}}if(void 0===i&&void 0===o)return{width:t,height:r};const s=Math.min(void 0!==i?i/t:Number.POSITIVE_INFINITY,void 0!==o?o/r:Number.POSITIVE_INFINITY);if(s>=1)return{width:t,height:r};const c=Math.min(Math.max(1,Math.round(t*s)),void 0!==i?Math.floor(i):Number.POSITIVE_INFINITY),u=Math.min(Math.max(1,Math.round(r*s)),void 0!==o?Math.floor(o):Number.POSITIVE_INFINITY);return d(c,u),{width:c,height:u}}(F,x,o),D=O.width!==F||O.height!==x,T=null!==I||void 0!==s,B=w(O.width,O.height),L=B.getContext("2d");if(!L)throw new t.HeicConverterError("render_encode_failed",e.Messages.ContextUnavailable);if(T||D){const r=w(v,m),n=r.getContext("2d");if(!n)throw new t.HeicConverterError("render_encode_failed",e.Messages.ContextUnavailable);if(p(n,_,v,m),T){const e=O.width/F,t=O.height/x,n=I?I[0]:1,i=I?I[1]:0,o=I?I[2]:0,a=I?I[3]:1,s=I?I[4]:0,c=I?I[5]:0;L.setTransform(n*e,i*t,o*e,a*t,e*(s-U),t*(c-P)),L.drawImage(r,0,0)}else L.drawImage(r,0,0,O.width,O.height);g(r)}else p(L,_,v,m);if("png"===f){const e=await h(B,"image/png");return g(B),y(e,r,c,"png",E)}if("jpeg"===f||"jpg"===f){const e=await h(B,"image/jpeg",i);return g(B),y(e,r,c,"jpeg",E)}if("webp"===f){const e=await h(B,"image/webp",i);return g(B),e}if("avif"===f){const r=await h(B,"image/avif",i);if(g(B),"image/avif"!==r.type)throw new t.HeicConverterError("format_unsupported",e.Messages.FormatUnsupported("avif"));return r}if("svg"===f){const e=await h(B,"image/png");g(B);const t=await l(e),r=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${O.width} ${O.height}" width="${O.width}" height="${O.height}">\n <image width="${O.width}" height="${O.height}" href="`;return new Blob([r,t,'" />\n</svg>'],{type:"image/svg+xml"})}throw new t.HeicConverterError("invalid_format",e.Messages.UnsupportedFormat(String(n)))}(f,o,_,c,n?.applyOrientation??!0,n?.crop,n?.preserveExif??!1)}catch(r){if(r instanceof t.HeicConverterError)throw r;throw new t.HeicConverterError("render_encode_failed",e.Messages.RenderEncodeFailed(o,r instanceof Error?r.message:String(r)),{cause:r})}return e.throwIfAborted(s),r?.complete(),async function(e,t){return"dataUrl"===t?await l(e):"arrayBuffer"===t?await e.arrayBuffer():e}(b,n?.output??"blob")}finally{A()}}var E=class{idle=[];disposed=!1;acquire(){return this.idle.pop()??new i}release(e){if(this.disposed||function(e){return r.has(e)}(e))try{e.free()}catch{}else this.idle.push(e)}dispose(){this.disposed=!0;for(const e of this.idle)try{e.free()}catch{}this.idle.length=0}};Object.defineProperty(exports,"DEFAULT_QUALITY",{enumerable:!0,get:function(){return e.DEFAULT_QUALITY}}),Object.defineProperty(exports,"SUPPORTED_FORMATS",{enumerable:!0,get:function(){return e.SUPPORTED_FORMATS}}),Object.defineProperty(exports,"HeicConverterError",{enumerable:!0,get:function(){return t.HeicConverterError}}),exports.LibheifDecoder=i,exports.convertHeic=C,exports.convertHeicInWorker=function(e,t){return m().then(r=>r.convertHeicInWorker(e,t))},exports.convertMany=async function(r,n){if(!Array.isArray(r))throw new t.HeicConverterError("invalid_input",e.Messages.InputsMustBeArray);const i=n?.concurrency??4;e.validateConcurrency(i),e.validateConvertOptions(n),e.validateBatchOptions(n),a(),await f(n?.to??"jpeg");const{concurrency:o,onProgress:s,continueOnError:c,reuseDecoders:u,...d}=n??{},l=e.progressCallbackFor(s),h=!0!==u||void 0!==n?.decoder||_(n)?null:new E;try{return await e.runBoundedBatch(r,i,async(e,t)=>{const r=h?h.acquire():null;try{return await C(e,{...d,...r?{decoder:r}:{},onProgress:l?e=>l(t,e):void 0})}finally{r&&h.release(r)}},{continueOnError:!0===n?.continueOnError,signal:n?.signal})}finally{h?.dispose()}},exports.convertManyInWorker=function(e,t){return m().then(r=>r.convertManyInWorker(e,t))},exports.freeSharedDecoder=function(){};
1
+ var e=require("./chunk-6XIPSRPS.js"),t=require("./chunk-N2LCVW2Q.js"),r=new WeakSet,n=/[\u0000-\u001f\u007f-\u009f]+/g,i=class{options;module=null;initPromise=null;initGeneration=0;constructor(e){this.options=e}async initialize(){if(!this.initPromise){const r=++this.initGeneration,n={};this.options?.moduleOverrides&&Object.assign(n,this.options.moduleOverrides),this.options?.locateFile&&(n.locateFile=this.options.locateFile);const i=import("./heic-decoder-LWGIYGE3.js").then(async({default:e})=>{if(this.options?.wasmBinary){const e=await WebAssembly.compile(this.options.wasmBinary);n.instantiateWasm=(t,r)=>r(new WebAssembly.Instance(e,t))}return e(n)}).then(n=>{if(r!==this.initGeneration)return null;const i=["function"==typeof n._heic_decode?null:"_heic_decode","function"==typeof n._heic_result_free?null:"_heic_result_free","function"==typeof n._malloc?null:"_malloc","function"==typeof n._free?null:"_free",n.HEAPU8 instanceof Uint8Array?null:"HEAPU8"].filter(e=>null!==e);if(i.length>0)throw new t.HeicConverterError("decoder_init_failed",e.Messages.GlueApiMissing(i.join(", ")));return this.module=n,n}).catch(e=>{throw this.initPromise===i&&(this.initPromise=null),e});this.initPromise=i}await this.initPromise}async decode(i,o){this.module||await this.initialize();const a=this.module;if(!a)throw new t.HeicConverterError("decode_failed",e.Messages.DecoderFreedDuringDecode);let s;const c=o?t=>{try{o(e.clampPercent(t))}catch(e){s=s??e,a.__progressCb=null}}:null,u=i.buffer===a.HEAPU8.buffer?new Uint8Array(i):i;let f,d=0,l=0;try{if(d=a._malloc(u.byteLength),0===d)throw new t.HeicConverterError("decode_failed",e.Messages.DecodeInputAllocFailed(u.byteLength));a.HEAPU8.set(u,d);const r=a.__progressCb??null;a.__progressCb=c;try{l=a._heic_decode(d,u.byteLength)}finally{a.__progressCb=r}const o=a.HEAPU8;if(0===l)throw new TypeError("heic_decode returned a null result");const s=new DataView(o.buffer,l,36),h=s.getInt32(0,!0);if(0===h){const r=s.getUint32(28,!0),a=s.getUint32(32,!0),c=0!==r?(new TextDecoder).decode(o.subarray(r,r+a)):"";throw new t.HeicConverterError("decode_failed",c?e.Messages.DecodeFailedWithDetail(function(e){const t=e.replace(n," ").trim();return t.length>200?`${t.slice(0,197)}...`:t}(c),i.byteLength):e.Messages.DecodeFailed(i.byteLength))}const w=s.getInt32(4,!0),g=s.getInt32(8,!0),p=g>=1&&g<=8?g:1,v=s.getUint32(12,!0),y=s.getUint32(16,!0),m=4*h,_=new Uint8ClampedArray(m*w);if(y===m)_.set(o.subarray(v,v+m*w));else for(let e=0;e<w;e++)_.set(o.subarray(v+e*y,v+e*y+m),e*m);f={width:h,height:w,data:_},p>1&&(f.orientation=p);const b=s.getUint32(20,!0),C=s.getUint32(24,!0);0!==b&&C>=14&&(f.exif=o.slice(b,b+C))}catch(n){if(n instanceof t.HeicConverterError)throw n;throw r.add(this),new t.HeicConverterError("decode_failed",e.Messages.DecodeFaulted(i.byteLength),{cause:n})}finally{a.__progressCb=null;try{0!==l&&a._heic_result_free(l),0!==d&&a._free(d)}catch{}}if(void 0!==s)throw e.progressCallbackError(s);return f}free(){this.initGeneration+=1,this.module=null,r.delete(this),this.initPromise=null}},o=16384;function a(){if("undefined"==typeof OffscreenCanvas&&"undefined"==typeof document)throw new t.HeicConverterError("unsupported_environment",e.Messages.CanvasUnsupported)}var s=null,c=0;function u(){if(null===s){if(Date.now()<c)return Promise.resolve(void 0);const e=async function(){let e;try{e=w(1,1)}catch{return}const t=h(e,"image/avif");let r;const n=new Promise(e=>{r=setTimeout(()=>e("timeout"),5e3)});try{const e=await Promise.race([t,n]);return"timeout"===e?void 0:"image/avif"===e.type&&e.size>0}finally{void 0!==r&&clearTimeout(r),g(e)}}().catch(()=>{});s=e,e.then(t=>{void 0===t&&s===e&&(s=null,c=Date.now()+1e4)})}return s}async function f(r){if(e.validateFormat(r),"avif"===String(r).toLowerCase()&&!1===await u())throw new t.HeicConverterError("format_unsupported",e.Messages.FormatUnsupported("avif"))}function d(r,n){if(!Number.isFinite(r)||!Number.isFinite(n)||r>o||n>o)throw new t.HeicConverterError("invalid_resize",e.Messages.TargetSizeTooLarge(r,n,o))}async function l(r){try{const e=await r.arrayBuffer(),t=new Uint8Array(e);let n="";const i=32768;for(let e=0;e<t.length;e+=i)n+=String.fromCharCode(...t.subarray(e,e+i));const o=btoa(n);return`data:${r.type};base64,${o}`}catch(r){throw new t.HeicConverterError("render_encode_failed",e.Messages.BlobToBase64FailedWithCause(r instanceof Error?r.message:String(r)),{cause:r})}}function h(r,n,i){return"convertToBlob"in r?r.convertToBlob({type:n,quality:i}):new Promise((o,a)=>{r.toBlob(r=>{r?o(r):a(new t.HeicConverterError("render_encode_failed",e.Messages.CanvasToBlobFailed(n)))},n,i)})}function w(r,n){if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(r,n);if("undefined"!=typeof document){const e=document.createElement("canvas");return e.width=r,e.height=n,e}throw new t.HeicConverterError("unsupported_environment",e.Messages.CanvasUnsupported)}function g(e){const t=e;"function"==typeof t.close?t.close():e.width=0}function p(e,t,r,n){if("undefined"!=typeof ImageData)e.putImageData(new ImageData(t,r,n),0,0);else{const i=e.createImageData(r,n);i.data.set(t),e.putImageData(i,0,0)}}var v=!1;async function y(t,r,n,i,o){const a=r.exif;if(!n||!a||0===a.length)return t;const s=await import("./exif-H2Q7BO7Y.js").catch(()=>null);if(!s)return v||(v=!0,console.warn(e.Messages.ExifChunkLoadWarning)),t;const{injectExifIntoJpeg:c,injectExifIntoPng:u,normalizeOrientationTag:f}=s,d=o?f(a):a,l=new Uint8Array(await t.arrayBuffer()),h="jpeg"===i?c(l,d):u(l,d);return h===l?t:new Blob([h.buffer],{type:t.type})}function m(){return import("./worker-4HVYKWRG.js").catch(r=>{const n=r instanceof Error?r.message:String(r);throw new t.HeicConverterError("worker_load_failed",e.Messages.WorkerChunkLoadFailed(n),{cause:r})})}function _(e){return!0===e?.nativeDecode&&!0!==e?.preserveExif&&!1!==e?.applyOrientation}var b=!1;async function C(r,n){const o=n?.to??"jpeg";e.validateConvertOptions(n),a(),await f(o);const s=n?.signal;e.throwIfAborted(s);const c=n,v=await async function(r){if(r instanceof Uint8Array)return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if("undefined"!=typeof Blob&&r instanceof Blob)return new Uint8Array(await r.arrayBuffer());if(null!==r&&"object"==typeof r&&"function"==typeof r.arrayBuffer){const e=await r.arrayBuffer();if(e instanceof ArrayBuffer)return new Uint8Array(e)}if(ArrayBuffer.isView(r)){const e=r;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}throw new t.HeicConverterError("invalid_input",e.Messages.UnsupportedInputType(Object.prototype.toString.call(r)))}(r);let m,C;e.throwIfAborted(s);let E,I=!1;if(n?.decoder)m=n.decoder,C=!1;else if(_(n)){try{E=await(import("./native-JFFONPCS.js"))}catch(t){M=t instanceof Error?t.message:String(t),b||(b=!0,console.warn(e.Messages.NativeChunkLoadWarning(M)))}void 0===E||E.isNativeHeicRefused()?m=new i:(m=new E.NativeHeicDecoder,I=!0),C=!0}else m=new i,C=!0;var M;let H=!1;const A=()=>{if(C&&!H){H=!0;try{m.free()}catch{}}};try{const r=e.progressGateFor(n?.onProgress),a=async n=>{try{await n.initialize()}catch(r){throw new t.HeicConverterError("decoder_init_failed",e.Messages.DecoderInitFailed(r instanceof Error?r.message:String(r)),{cause:r})}return e.throwIfAborted(s),n.decode(v,r?r.report:void 0)};let f;try{f=await a(m)}catch(r){if(!I)throw r;if(r instanceof t.HeicConverterError&&"aborted"===r.code)throw r;r instanceof t.HeicConverterError&&"decoder_init_failed"===r.code&&E.markNativeHeicRefused(),e.throwIfAborted(s),A(),m=new i,H=!1,I=!1,f=await a(m)}A(),e.throwIfAborted(s);const _=void 0!==n?.quality?n.quality:e.DEFAULT_QUALITY;let b;try{b=await async function(r,n,i,o,a=!0,s,c=!1){e.validateFormat(n),e.validateCrop(s);const f=n.toLowerCase();if("avif"===f&&!1===await u())throw new t.HeicConverterError("format_unsupported",e.Messages.FormatUnsupported("avif"));const{width:v,height:m,data:_}=r;if(!Number.isInteger(v)||v<=0||!Number.isInteger(m)||m<=0)throw new t.HeicConverterError("render_encode_failed",e.Messages.InvalidDimensions(v,m));const b=v*m*4;if(_.length!==b)throw new t.HeicConverterError("render_encode_failed",e.Messages.DataLengthMismatch(b,v,m,_.length));const C=function(e,t){return t&&"number"==typeof e&&Number.isInteger(e)&&e>=1&&e<=8?e:1}(r.orientation,a),E=!(void 0!==r.orientation&&r.orientation>=2&&r.orientation<=8)||a,I=function(e,t,r){switch(e){case 2:return[-1,0,0,1,t,0];case 3:return[-1,0,0,-1,t,r];case 4:return[1,0,0,-1,0,r];case 5:return[0,1,1,0,0,0];case 6:return[0,1,-1,0,r,0];case 7:return[0,-1,-1,0,r,t];case 8:return[0,-1,1,0,0,t];default:return null}}(C,v,m),M=C>=5,H=M?m:v,A=M?v:m,U=s?.x??0,P=s?.y??0,F=s?s.width:H,x=s?s.height:A;if(s&&(U+F>H||P+x>A))throw new t.HeicConverterError("invalid_crop",e.Messages.CropOutOfBounds(U,P,F,x,H,A));const O=function(t,r,n){if(e.validateResize(n),!n)return{width:t,height:r};const{maxWidth:i,maxHeight:o,scale:a}=n;if(void 0!==a){const e=Math.max(1,Math.round(t*a)),n=Math.max(1,Math.round(r*a));return d(e,n),{width:e,height:n}}if(void 0===i&&void 0===o)return{width:t,height:r};const s=Math.min(void 0!==i?i/t:Number.POSITIVE_INFINITY,void 0!==o?o/r:Number.POSITIVE_INFINITY);if(s>=1)return{width:t,height:r};const c=Math.min(Math.max(1,Math.round(t*s)),void 0!==i?Math.floor(i):Number.POSITIVE_INFINITY),u=Math.min(Math.max(1,Math.round(r*s)),void 0!==o?Math.floor(o):Number.POSITIVE_INFINITY);return d(c,u),{width:c,height:u}}(F,x,o),T=O.width!==F||O.height!==x,D=null!==I||void 0!==s,B=w(O.width,O.height),L=B.getContext("2d");if(!L)throw new t.HeicConverterError("render_encode_failed",e.Messages.ContextUnavailable);if(D||T){const r=w(v,m),n=r.getContext("2d");if(!n)throw new t.HeicConverterError("render_encode_failed",e.Messages.ContextUnavailable);if(p(n,_,v,m),D){const e=O.width/F,t=O.height/x,n=I?I[0]:1,i=I?I[1]:0,o=I?I[2]:0,a=I?I[3]:1,s=I?I[4]:0,c=I?I[5]:0;L.setTransform(n*e,i*t,o*e,a*t,e*(s-U),t*(c-P)),L.drawImage(r,0,0)}else L.drawImage(r,0,0,O.width,O.height);g(r)}else p(L,_,v,m);if("png"===f){const e=await h(B,"image/png");return g(B),y(e,r,c,"png",E)}if("jpeg"===f||"jpg"===f){const e=await h(B,"image/jpeg",i);return g(B),y(e,r,c,"jpeg",E)}if("webp"===f){const e=await h(B,"image/webp",i);return g(B),e}if("avif"===f){const r=await h(B,"image/avif",i);if(g(B),"image/avif"!==r.type)throw new t.HeicConverterError("format_unsupported",e.Messages.FormatUnsupported("avif"));return r}if("svg"===f){const e=await h(B,"image/png");g(B);const t=await l(e),r=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${O.width} ${O.height}" width="${O.width}" height="${O.height}">\n <image width="${O.width}" height="${O.height}" href="`;return new Blob([r,t,'" />\n</svg>'],{type:"image/svg+xml"})}throw new t.HeicConverterError("invalid_format",e.Messages.UnsupportedFormat(String(n)))}(f,o,_,c,n?.applyOrientation??!0,n?.crop,n?.preserveExif??!1)}catch(r){if(r instanceof t.HeicConverterError)throw r;throw new t.HeicConverterError("render_encode_failed",e.Messages.RenderEncodeFailed(o,r instanceof Error?r.message:String(r)),{cause:r})}return e.throwIfAborted(s),r?.complete(),async function(e,t){return"dataUrl"===t?await l(e):"arrayBuffer"===t?await e.arrayBuffer():e}(b,n?.output??"blob")}finally{A()}}var E=class{idle=[];disposed=!1;acquire(){return this.idle.pop()??new i}release(e){if(this.disposed||function(e){return r.has(e)}(e))try{e.free()}catch{}else this.idle.push(e)}dispose(){this.disposed=!0;for(const e of this.idle)try{e.free()}catch{}this.idle.length=0}};Object.defineProperty(exports,"DEFAULT_QUALITY",{enumerable:!0,get:function(){return e.DEFAULT_QUALITY}}),Object.defineProperty(exports,"SUPPORTED_FORMATS",{enumerable:!0,get:function(){return e.SUPPORTED_FORMATS}}),Object.defineProperty(exports,"HeicConverterError",{enumerable:!0,get:function(){return t.HeicConverterError}}),exports.LibheifDecoder=i,exports.convertHeic=C,exports.convertHeicInWorker=function(e,t){return m().then(r=>r.convertHeicInWorker(e,t))},exports.convertMany=async function(r,n){if(!Array.isArray(r))throw new t.HeicConverterError("invalid_input",e.Messages.InputsMustBeArray);const i=n?.concurrency??4;e.validateConcurrency(i),e.validateConvertOptions(n),e.validateBatchOptions(n),a(),await f(n?.to??"jpeg");const{concurrency:o,onProgress:s,continueOnError:c,reuseDecoders:u,...d}=n??{},l=e.progressCallbackFor(s),h=!0!==u||void 0!==n?.decoder||_(n)?null:new E;try{return await e.runBoundedBatch(r,i,async(e,t)=>{const r=h?h.acquire():null;try{return await C(e,{...d,...r?{decoder:r}:{},onProgress:l?e=>l(t,e):void 0})}finally{r&&h.release(r)}},{continueOnError:!0===n?.continueOnError,signal:n?.signal})}finally{h?.dispose()}},exports.convertManyInWorker=function(e,t){return m().then(r=>r.convertManyInWorker(e,t))},exports.freeSharedDecoder=function(){};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{Messages as e,validateConvertOptions as t,throwIfAborted as n,progressGateFor as i,DEFAULT_QUALITY as r,validateConcurrency as o,validateBatchOptions as a,progressCallbackFor as s,runBoundedBatch as c,clampPercent as u,progressCallbackError as f,validateFormat as d,validateCrop as l,validateResize as h}from"./chunk-GR5XSYDQ.mjs";export{DEFAULT_QUALITY,SUPPORTED_FORMATS}from"./chunk-GR5XSYDQ.mjs";import{HeicConverterError as w}from"./chunk-AROQBV5T.mjs";export{HeicConverterError}from"./chunk-AROQBV5T.mjs";var g=new WeakSet,p=/[\u0000-\u001f\u007f-\u009f]+/g,m=class{options;module=null;initPromise=null;initGeneration=0;constructor(e){this.options=e}async initialize(){if(!this.initPromise){const t=++this.initGeneration,n={};this.options?.moduleOverrides&&Object.assign(n,this.options.moduleOverrides),this.options?.locateFile&&(n.locateFile=this.options.locateFile);const i=import("./heic-decoder-Y2OU4CGB.mjs").then(async({default:e})=>{if(this.options?.wasmBinary){const e=await WebAssembly.compile(this.options.wasmBinary);n.instantiateWasm=(t,n)=>n(new WebAssembly.Instance(e,t))}return e(n)}).then(n=>{if(t!==this.initGeneration)return null;const i=["function"==typeof n._heic_decode?null:"_heic_decode","function"==typeof n._heic_result_free?null:"_heic_result_free","function"==typeof n._malloc?null:"_malloc","function"==typeof n._free?null:"_free",n.HEAPU8 instanceof Uint8Array?null:"HEAPU8"].filter(e=>null!==e);if(i.length>0)throw new w("decoder_init_failed",e.GlueApiMissing(i.join(", ")));return this.module=n,n}).catch(e=>{throw this.initPromise===i&&(this.initPromise=null),e});this.initPromise=i}await this.initPromise}async decode(t,n){this.module||await this.initialize();const i=this.module;if(!i)throw new w("decode_failed",e.DecoderFreedDuringDecode);let r;const o=n?e=>{try{n(u(e))}catch(e){r=r??e,i.__progressCb=null}}:null,a=t.buffer===i.HEAPU8.buffer?new Uint8Array(t):t;let s,c=0,d=0;try{if(c=i._malloc(a.byteLength),0===c)throw new w("decode_failed",e.DecodeInputAllocFailed(a.byteLength));i.HEAPU8.set(a,c);const n=i.__progressCb??null;i.__progressCb=o;try{d=i._heic_decode(c,a.byteLength)}finally{i.__progressCb=n}const r=i.HEAPU8;if(0===d)throw new TypeError("heic_decode returned a null result");const u=new DataView(r.buffer,d,36),f=u.getInt32(0,!0);if(0===f){const n=u.getUint32(28,!0),i=u.getUint32(32,!0),o=0!==n?(new TextDecoder).decode(r.subarray(n,n+i)):"";throw new w("decode_failed",o?e.DecodeFailedWithDetail(function(e){const t=e.replace(p," ").trim();return t.length>200?`${t.slice(0,197)}...`:t}(o),t.byteLength):e.DecodeFailed(t.byteLength))}const l=u.getInt32(4,!0),h=u.getInt32(8,!0),g=h>=1&&h<=8?h:1,m=u.getUint32(12,!0),y=u.getUint32(16,!0),v=4*f,_=new Uint8ClampedArray(v*l);if(y===v)_.set(r.subarray(m,m+v*l));else for(let e=0;e<l;e++)_.set(r.subarray(m+e*y,m+e*y+v),e*v);s={width:f,height:l,data:_},g>1&&(s.orientation=g);const b=u.getUint32(20,!0),I=u.getUint32(24,!0);0!==b&&I>=14&&(s.exif=r.slice(b,b+I))}catch(n){if(n instanceof w)throw n;throw g.add(this),new w("decode_failed",e.DecodeFaulted(t.byteLength),{cause:n})}finally{i.__progressCb=null;try{0!==d&&i._heic_result_free(d),0!==c&&i._free(c)}catch{}}if(void 0!==r)throw f(r);return s}free(){this.initGeneration+=1,this.module=null,g.delete(this),this.initPromise=null}},y=16384;function v(){if("undefined"==typeof OffscreenCanvas&&"undefined"==typeof document)throw new w("unsupported_environment",e.CanvasUnsupported)}var _=null,b=0;function I(){if(null===_){if(Date.now()<b)return Promise.resolve(void 0);const e=async function(){let e;try{e=C(1,1)}catch{return}const t=E(e,"image/avif");let n;const i=new Promise(e=>{n=setTimeout(()=>e("timeout"),5e3)});try{const e=await Promise.race([t,i]);return"timeout"===e?void 0:"image/avif"===e.type&&e.size>0}finally{void 0!==n&&clearTimeout(n),D(e)}}().catch(()=>{});_=e,e.then(t=>{void 0===t&&_===e&&(_=null,b=Date.now()+1e4)})}return _}async function U(t){if(d(t),"avif"===String(t).toLowerCase()&&!1===await I())throw new w("format_unsupported",e.FormatUnsupported("avif"))}function A(t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t>y||n>y)throw new w("invalid_resize",e.TargetSizeTooLarge(t,n,y))}async function B(t){try{const e=await t.arrayBuffer(),n=new Uint8Array(e);let i="";const r=32768;for(let e=0;e<n.length;e+=r)i+=String.fromCharCode(...n.subarray(e,e+r));const o=btoa(i);return`data:${t.type};base64,${o}`}catch(t){throw new w("render_encode_failed",e.BlobToBase64FailedWithCause(t instanceof Error?t.message:String(t)),{cause:t})}}function E(t,n,i){return"convertToBlob"in t?t.convertToBlob({type:n,quality:i}):new Promise((r,o)=>{t.toBlob(t=>{t?r(t):o(new w("render_encode_failed",e.CanvasToBlobFailed(n)))},n,i)})}function C(t,n){if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(t,n);if("undefined"!=typeof document){const e=document.createElement("canvas");return e.width=t,e.height=n,e}throw new w("unsupported_environment",e.CanvasUnsupported)}function D(e){const t=e;"function"==typeof t.close?t.close():e.width=0}function T(e,t,n,i){if("undefined"!=typeof ImageData)e.putImageData(new ImageData(t,n,i),0,0);else{const r=e.createImageData(n,i);r.data.set(t),e.putImageData(r,0,0)}}var x=!1;async function P(t,n,i,r,o){const a=n.exif;if(!i||!a||0===a.length)return t;const s=await import("./exif-MBEKII5G.mjs").catch(()=>null);if(!s)return x||(x=!0,console.warn(e.ExifChunkLoadWarning)),t;const{injectExifIntoJpeg:c,injectExifIntoPng:u,normalizeOrientationTag:f}=s,d=o?f(a):a,l=new Uint8Array(await t.arrayBuffer()),h="jpeg"===r?c(l,d):u(l,d);return h===l?t:new Blob([h.buffer],{type:t.type})}function F(){return import("./worker-N6W3ASWN.mjs").catch(t=>{const n=t instanceof Error?t.message:String(t);throw new w("worker_load_failed",e.WorkerChunkLoadFailed(n),{cause:t})})}function O(e,t){return F().then(n=>n.convertHeicInWorker(e,t))}function N(e,t){return F().then(n=>n.convertManyInWorker(e,t))}function j(){}function S(e){return!0===e?.nativeDecode&&!0!==e?.preserveExif&&!1!==e?.applyOrientation}var M=!1;async function L(o,a){const s=a?.to??"jpeg";t(a),v(),await U(s);const c=a?.signal;n(c);const u=a,f=await async function(t){if(t instanceof Uint8Array)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if("undefined"!=typeof Blob&&t instanceof Blob)return new Uint8Array(await t.arrayBuffer());if(null!==t&&"object"==typeof t&&"function"==typeof t.arrayBuffer){const e=await t.arrayBuffer();if(e instanceof ArrayBuffer)return new Uint8Array(e)}if(ArrayBuffer.isView(t)){const e=t;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}throw new w("invalid_input",e.UnsupportedInputType(Object.prototype.toString.call(t)))}(o);let g,p;n(c);let y,_=!1;if(a?.decoder)g=a.decoder,p=!1;else if(S(a)){try{y=await(import("./native-IGARV2W7.mjs"))}catch(t){b=t instanceof Error?t.message:String(t),M||(M=!0,console.warn(e.NativeChunkLoadWarning(b)))}void 0===y||y.isNativeHeicRefused()?g=new m:(g=new y.NativeHeicDecoder,_=!0),p=!0}else g=new m,p=!0;var b;let x=!1;const F=()=>{if(p&&!x){x=!0;try{g.free()}catch{}}};try{const t=i(a?.onProgress),o=async i=>{try{await i.initialize()}catch(t){throw new w("decoder_init_failed",e.DecoderInitFailed(t instanceof Error?t.message:String(t)),{cause:t})}return n(c),i.decode(f,t?t.report:void 0)};let p;try{p=await o(g)}catch(e){if(!_)throw e;if(e instanceof w&&"aborted"===e.code)throw e;e instanceof w&&"decoder_init_failed"===e.code&&y.markNativeHeicRefused(),n(c),F(),g=new m,x=!1,_=!1,p=await o(g)}F(),n(c);const v=void 0!==a?.quality?a.quality:r;let b;try{b=await async function(t,n,i,r,o=!0,a,s=!1){d(n),l(a);const c=n.toLowerCase();if("avif"===c&&!1===await I())throw new w("format_unsupported",e.FormatUnsupported("avif"));const{width:u,height:f,data:g}=t;if(!Number.isInteger(u)||u<=0||!Number.isInteger(f)||f<=0)throw new w("render_encode_failed",e.InvalidDimensions(u,f));const p=u*f*4;if(g.length!==p)throw new w("render_encode_failed",e.DataLengthMismatch(p,u,f,g.length));const m=function(e,t){return t&&"number"==typeof e&&Number.isInteger(e)&&e>=1&&e<=8?e:1}(t.orientation,o),y=!(void 0!==t.orientation&&t.orientation>=2&&t.orientation<=8)||o,v=function(e,t,n){switch(e){case 2:return[-1,0,0,1,t,0];case 3:return[-1,0,0,-1,t,n];case 4:return[1,0,0,-1,0,n];case 5:return[0,1,1,0,0,0];case 6:return[0,1,-1,0,n,0];case 7:return[0,-1,-1,0,n,t];case 8:return[0,-1,1,0,0,t];default:return null}}(m,u,f),_=m>=5,b=_?f:u,U=_?u:f,x=a?.x??0,F=a?.y??0,O=a?a.width:b,N=a?a.height:U;if(a&&(x+O>b||F+N>U))throw new w("invalid_crop",e.CropOutOfBounds(x,F,O,N,b,U));const j=function(e,t,n){if(h(n),!n)return{width:e,height:t};const{maxWidth:i,maxHeight:r,scale:o}=n;if(void 0!==o){const n=Math.max(1,Math.round(e*o)),i=Math.max(1,Math.round(t*o));return A(n,i),{width:n,height:i}}if(void 0===i&&void 0===r)return{width:e,height:t};const a=Math.min(void 0!==i?i/e:Number.POSITIVE_INFINITY,void 0!==r?r/t:Number.POSITIVE_INFINITY);if(a>=1)return{width:e,height:t};const s=Math.min(Math.max(1,Math.round(e*a)),void 0!==i?Math.floor(i):Number.POSITIVE_INFINITY),c=Math.min(Math.max(1,Math.round(t*a)),void 0!==r?Math.floor(r):Number.POSITIVE_INFINITY);return A(s,c),{width:s,height:c}}(O,N,r),S=j.width!==O||j.height!==N,M=null!==v||void 0!==a,L=C(j.width,j.height),W=L.getContext("2d");if(!W)throw new w("render_encode_failed",e.ContextUnavailable);if(M||S){const t=C(u,f),n=t.getContext("2d");if(!n)throw new w("render_encode_failed",e.ContextUnavailable);if(T(n,g,u,f),M){const e=j.width/O,n=j.height/N,i=v?v[0]:1,r=v?v[1]:0,o=v?v[2]:0,a=v?v[3]:1,s=v?v[4]:0,c=v?v[5]:0;W.setTransform(i*e,r*n,o*e,a*n,e*(s-x),n*(c-F)),W.drawImage(t,0,0)}else W.drawImage(t,0,0,j.width,j.height);D(t)}else T(W,g,u,f);if("png"===c){const e=await E(L,"image/png");return D(L),P(e,t,s,"png",y)}if("jpeg"===c||"jpg"===c){const e=await E(L,"image/jpeg",i);return D(L),P(e,t,s,"jpeg",y)}if("webp"===c){const e=await E(L,"image/webp",i);return D(L),e}if("avif"===c){const t=await E(L,"image/avif",i);if(D(L),"image/avif"!==t.type)throw new w("format_unsupported",e.FormatUnsupported("avif"));return t}if("svg"===c){const e=await E(L,"image/png");D(L);const t=await B(e),n=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${j.width} ${j.height}" width="${j.width}" height="${j.height}">\n <image width="${j.width}" height="${j.height}" href="`;return new Blob([n,t,'" />\n</svg>'],{type:"image/svg+xml"})}throw new w("invalid_format",e.UnsupportedFormat(String(n)))}(p,s,v,u,a?.applyOrientation??!0,a?.crop,a?.preserveExif??!1)}catch(t){if(t instanceof w)throw t;throw new w("render_encode_failed",e.RenderEncodeFailed(s,t instanceof Error?t.message:String(t)),{cause:t})}return n(c),t?.complete(),async function(e,t){return"dataUrl"===t?await B(e):"arrayBuffer"===t?await e.arrayBuffer():e}(b,a?.output??"blob")}finally{F()}}var W=class{idle=[];disposed=!1;acquire(){return this.idle.pop()??new m}release(e){if(this.disposed||function(e){return g.has(e)}(e))try{e.free()}catch{}else this.idle.push(e)}dispose(){this.disposed=!0;for(const e of this.idle)try{e.free()}catch{}this.idle.length=0}};async function k(n,i){if(!Array.isArray(n))throw new w("invalid_input",e.InputsMustBeArray);const r=i?.concurrency??4;o(r),t(i),a(i),v(),await U(i?.to??"jpeg");const{concurrency:u,onProgress:f,continueOnError:d,reuseDecoders:l,...h}=i??{},g=s(f),p=!0!==l||void 0!==i?.decoder||S(i)?null:new W;try{return await c(n,r,async(e,t)=>{const n=p?p.acquire():null;try{return await L(e,{...h,...n?{decoder:n}:{},onProgress:g?e=>g(t,e):void 0})}finally{n&&p.release(n)}},{continueOnError:!0===i?.continueOnError,signal:i?.signal})}finally{p?.dispose()}}export{m as LibheifDecoder,L as convertHeic,O as convertHeicInWorker,k as convertMany,N as convertManyInWorker,j as freeSharedDecoder};
1
+ import{Messages as e,validateConvertOptions as t,throwIfAborted as n,progressGateFor as i,DEFAULT_QUALITY as r,validateConcurrency as o,validateBatchOptions as a,progressCallbackFor as s,runBoundedBatch as c,clampPercent as u,progressCallbackError as f,validateFormat as d,validateCrop as l,validateResize as h}from"./chunk-GR5XSYDQ.mjs";export{DEFAULT_QUALITY,SUPPORTED_FORMATS}from"./chunk-GR5XSYDQ.mjs";import{HeicConverterError as w}from"./chunk-AROQBV5T.mjs";export{HeicConverterError}from"./chunk-AROQBV5T.mjs";var g=new WeakSet,p=/[\u0000-\u001f\u007f-\u009f]+/g,m=class{options;module=null;initPromise=null;initGeneration=0;constructor(e){this.options=e}async initialize(){if(!this.initPromise){const t=++this.initGeneration,n={};this.options?.moduleOverrides&&Object.assign(n,this.options.moduleOverrides),this.options?.locateFile&&(n.locateFile=this.options.locateFile);const i=import("./heic-decoder-ZFSRP4EX.mjs").then(async({default:e})=>{if(this.options?.wasmBinary){const e=await WebAssembly.compile(this.options.wasmBinary);n.instantiateWasm=(t,n)=>n(new WebAssembly.Instance(e,t))}return e(n)}).then(n=>{if(t!==this.initGeneration)return null;const i=["function"==typeof n._heic_decode?null:"_heic_decode","function"==typeof n._heic_result_free?null:"_heic_result_free","function"==typeof n._malloc?null:"_malloc","function"==typeof n._free?null:"_free",n.HEAPU8 instanceof Uint8Array?null:"HEAPU8"].filter(e=>null!==e);if(i.length>0)throw new w("decoder_init_failed",e.GlueApiMissing(i.join(", ")));return this.module=n,n}).catch(e=>{throw this.initPromise===i&&(this.initPromise=null),e});this.initPromise=i}await this.initPromise}async decode(t,n){this.module||await this.initialize();const i=this.module;if(!i)throw new w("decode_failed",e.DecoderFreedDuringDecode);let r;const o=n?e=>{try{n(u(e))}catch(e){r=r??e,i.__progressCb=null}}:null,a=t.buffer===i.HEAPU8.buffer?new Uint8Array(t):t;let s,c=0,d=0;try{if(c=i._malloc(a.byteLength),0===c)throw new w("decode_failed",e.DecodeInputAllocFailed(a.byteLength));i.HEAPU8.set(a,c);const n=i.__progressCb??null;i.__progressCb=o;try{d=i._heic_decode(c,a.byteLength)}finally{i.__progressCb=n}const r=i.HEAPU8;if(0===d)throw new TypeError("heic_decode returned a null result");const u=new DataView(r.buffer,d,36),f=u.getInt32(0,!0);if(0===f){const n=u.getUint32(28,!0),i=u.getUint32(32,!0),o=0!==n?(new TextDecoder).decode(r.subarray(n,n+i)):"";throw new w("decode_failed",o?e.DecodeFailedWithDetail(function(e){const t=e.replace(p," ").trim();return t.length>200?`${t.slice(0,197)}...`:t}(o),t.byteLength):e.DecodeFailed(t.byteLength))}const l=u.getInt32(4,!0),h=u.getInt32(8,!0),g=h>=1&&h<=8?h:1,m=u.getUint32(12,!0),y=u.getUint32(16,!0),v=4*f,_=new Uint8ClampedArray(v*l);if(y===v)_.set(r.subarray(m,m+v*l));else for(let e=0;e<l;e++)_.set(r.subarray(m+e*y,m+e*y+v),e*v);s={width:f,height:l,data:_},g>1&&(s.orientation=g);const b=u.getUint32(20,!0),I=u.getUint32(24,!0);0!==b&&I>=14&&(s.exif=r.slice(b,b+I))}catch(n){if(n instanceof w)throw n;throw g.add(this),new w("decode_failed",e.DecodeFaulted(t.byteLength),{cause:n})}finally{i.__progressCb=null;try{0!==d&&i._heic_result_free(d),0!==c&&i._free(c)}catch{}}if(void 0!==r)throw f(r);return s}free(){this.initGeneration+=1,this.module=null,g.delete(this),this.initPromise=null}},y=16384;function v(){if("undefined"==typeof OffscreenCanvas&&"undefined"==typeof document)throw new w("unsupported_environment",e.CanvasUnsupported)}var _=null,b=0;function I(){if(null===_){if(Date.now()<b)return Promise.resolve(void 0);const e=async function(){let e;try{e=D(1,1)}catch{return}const t=B(e,"image/avif");let n;const i=new Promise(e=>{n=setTimeout(()=>e("timeout"),5e3)});try{const e=await Promise.race([t,i]);return"timeout"===e?void 0:"image/avif"===e.type&&e.size>0}finally{void 0!==n&&clearTimeout(n),P(e)}}().catch(()=>{});_=e,e.then(t=>{void 0===t&&_===e&&(_=null,b=Date.now()+1e4)})}return _}async function U(t){if(d(t),"avif"===String(t).toLowerCase()&&!1===await I())throw new w("format_unsupported",e.FormatUnsupported("avif"))}function A(t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t>y||n>y)throw new w("invalid_resize",e.TargetSizeTooLarge(t,n,y))}async function E(t){try{const e=await t.arrayBuffer(),n=new Uint8Array(e);let i="";const r=32768;for(let e=0;e<n.length;e+=r)i+=String.fromCharCode(...n.subarray(e,e+r));const o=btoa(i);return`data:${t.type};base64,${o}`}catch(t){throw new w("render_encode_failed",e.BlobToBase64FailedWithCause(t instanceof Error?t.message:String(t)),{cause:t})}}function B(t,n,i){return"convertToBlob"in t?t.convertToBlob({type:n,quality:i}):new Promise((r,o)=>{t.toBlob(t=>{t?r(t):o(new w("render_encode_failed",e.CanvasToBlobFailed(n)))},n,i)})}function D(t,n){if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(t,n);if("undefined"!=typeof document){const e=document.createElement("canvas");return e.width=t,e.height=n,e}throw new w("unsupported_environment",e.CanvasUnsupported)}function P(e){const t=e;"function"==typeof t.close?t.close():e.width=0}function T(e,t,n,i){if("undefined"!=typeof ImageData)e.putImageData(new ImageData(t,n,i),0,0);else{const r=e.createImageData(n,i);r.data.set(t),e.putImageData(r,0,0)}}var x=!1;async function C(t,n,i,r,o){const a=n.exif;if(!i||!a||0===a.length)return t;const s=await import("./exif-MBEKII5G.mjs").catch(()=>null);if(!s)return x||(x=!0,console.warn(e.ExifChunkLoadWarning)),t;const{injectExifIntoJpeg:c,injectExifIntoPng:u,normalizeOrientationTag:f}=s,d=o?f(a):a,l=new Uint8Array(await t.arrayBuffer()),h="jpeg"===r?c(l,d):u(l,d);return h===l?t:new Blob([h.buffer],{type:t.type})}function F(){return import("./worker-N6W3ASWN.mjs").catch(t=>{const n=t instanceof Error?t.message:String(t);throw new w("worker_load_failed",e.WorkerChunkLoadFailed(n),{cause:t})})}function O(e,t){return F().then(n=>n.convertHeicInWorker(e,t))}function N(e,t){return F().then(n=>n.convertManyInWorker(e,t))}function j(){}function S(e){return!0===e?.nativeDecode&&!0!==e?.preserveExif&&!1!==e?.applyOrientation}var M=!1;async function L(o,a){const s=a?.to??"jpeg";t(a),v(),await U(s);const c=a?.signal;n(c);const u=a,f=await async function(t){if(t instanceof Uint8Array)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if("undefined"!=typeof Blob&&t instanceof Blob)return new Uint8Array(await t.arrayBuffer());if(null!==t&&"object"==typeof t&&"function"==typeof t.arrayBuffer){const e=await t.arrayBuffer();if(e instanceof ArrayBuffer)return new Uint8Array(e)}if(ArrayBuffer.isView(t)){const e=t;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}throw new w("invalid_input",e.UnsupportedInputType(Object.prototype.toString.call(t)))}(o);let g,p;n(c);let y,_=!1;if(a?.decoder)g=a.decoder,p=!1;else if(S(a)){try{y=await(import("./native-IGARV2W7.mjs"))}catch(t){b=t instanceof Error?t.message:String(t),M||(M=!0,console.warn(e.NativeChunkLoadWarning(b)))}void 0===y||y.isNativeHeicRefused()?g=new m:(g=new y.NativeHeicDecoder,_=!0),p=!0}else g=new m,p=!0;var b;let x=!1;const F=()=>{if(p&&!x){x=!0;try{g.free()}catch{}}};try{const t=i(a?.onProgress),o=async i=>{try{await i.initialize()}catch(t){throw new w("decoder_init_failed",e.DecoderInitFailed(t instanceof Error?t.message:String(t)),{cause:t})}return n(c),i.decode(f,t?t.report:void 0)};let p;try{p=await o(g)}catch(e){if(!_)throw e;if(e instanceof w&&"aborted"===e.code)throw e;e instanceof w&&"decoder_init_failed"===e.code&&y.markNativeHeicRefused(),n(c),F(),g=new m,x=!1,_=!1,p=await o(g)}F(),n(c);const v=void 0!==a?.quality?a.quality:r;let b;try{b=await async function(t,n,i,r,o=!0,a,s=!1){d(n),l(a);const c=n.toLowerCase();if("avif"===c&&!1===await I())throw new w("format_unsupported",e.FormatUnsupported("avif"));const{width:u,height:f,data:g}=t;if(!Number.isInteger(u)||u<=0||!Number.isInteger(f)||f<=0)throw new w("render_encode_failed",e.InvalidDimensions(u,f));const p=u*f*4;if(g.length!==p)throw new w("render_encode_failed",e.DataLengthMismatch(p,u,f,g.length));const m=function(e,t){return t&&"number"==typeof e&&Number.isInteger(e)&&e>=1&&e<=8?e:1}(t.orientation,o),y=!(void 0!==t.orientation&&t.orientation>=2&&t.orientation<=8)||o,v=function(e,t,n){switch(e){case 2:return[-1,0,0,1,t,0];case 3:return[-1,0,0,-1,t,n];case 4:return[1,0,0,-1,0,n];case 5:return[0,1,1,0,0,0];case 6:return[0,1,-1,0,n,0];case 7:return[0,-1,-1,0,n,t];case 8:return[0,-1,1,0,0,t];default:return null}}(m,u,f),_=m>=5,b=_?f:u,U=_?u:f,x=a?.x??0,F=a?.y??0,O=a?a.width:b,N=a?a.height:U;if(a&&(x+O>b||F+N>U))throw new w("invalid_crop",e.CropOutOfBounds(x,F,O,N,b,U));const j=function(e,t,n){if(h(n),!n)return{width:e,height:t};const{maxWidth:i,maxHeight:r,scale:o}=n;if(void 0!==o){const n=Math.max(1,Math.round(e*o)),i=Math.max(1,Math.round(t*o));return A(n,i),{width:n,height:i}}if(void 0===i&&void 0===r)return{width:e,height:t};const a=Math.min(void 0!==i?i/e:Number.POSITIVE_INFINITY,void 0!==r?r/t:Number.POSITIVE_INFINITY);if(a>=1)return{width:e,height:t};const s=Math.min(Math.max(1,Math.round(e*a)),void 0!==i?Math.floor(i):Number.POSITIVE_INFINITY),c=Math.min(Math.max(1,Math.round(t*a)),void 0!==r?Math.floor(r):Number.POSITIVE_INFINITY);return A(s,c),{width:s,height:c}}(O,N,r),S=j.width!==O||j.height!==N,M=null!==v||void 0!==a,L=D(j.width,j.height),W=L.getContext("2d");if(!W)throw new w("render_encode_failed",e.ContextUnavailable);if(M||S){const t=D(u,f),n=t.getContext("2d");if(!n)throw new w("render_encode_failed",e.ContextUnavailable);if(T(n,g,u,f),M){const e=j.width/O,n=j.height/N,i=v?v[0]:1,r=v?v[1]:0,o=v?v[2]:0,a=v?v[3]:1,s=v?v[4]:0,c=v?v[5]:0;W.setTransform(i*e,r*n,o*e,a*n,e*(s-x),n*(c-F)),W.drawImage(t,0,0)}else W.drawImage(t,0,0,j.width,j.height);P(t)}else T(W,g,u,f);if("png"===c){const e=await B(L,"image/png");return P(L),C(e,t,s,"png",y)}if("jpeg"===c||"jpg"===c){const e=await B(L,"image/jpeg",i);return P(L),C(e,t,s,"jpeg",y)}if("webp"===c){const e=await B(L,"image/webp",i);return P(L),e}if("avif"===c){const t=await B(L,"image/avif",i);if(P(L),"image/avif"!==t.type)throw new w("format_unsupported",e.FormatUnsupported("avif"));return t}if("svg"===c){const e=await B(L,"image/png");P(L);const t=await E(e),n=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${j.width} ${j.height}" width="${j.width}" height="${j.height}">\n <image width="${j.width}" height="${j.height}" href="`;return new Blob([n,t,'" />\n</svg>'],{type:"image/svg+xml"})}throw new w("invalid_format",e.UnsupportedFormat(String(n)))}(p,s,v,u,a?.applyOrientation??!0,a?.crop,a?.preserveExif??!1)}catch(t){if(t instanceof w)throw t;throw new w("render_encode_failed",e.RenderEncodeFailed(s,t instanceof Error?t.message:String(t)),{cause:t})}return n(c),t?.complete(),async function(e,t){return"dataUrl"===t?await E(e):"arrayBuffer"===t?await e.arrayBuffer():e}(b,a?.output??"blob")}finally{F()}}var W=class{idle=[];disposed=!1;acquire(){return this.idle.pop()??new m}release(e){if(this.disposed||function(e){return g.has(e)}(e))try{e.free()}catch{}else this.idle.push(e)}dispose(){this.disposed=!0;for(const e of this.idle)try{e.free()}catch{}this.idle.length=0}};async function k(n,i){if(!Array.isArray(n))throw new w("invalid_input",e.InputsMustBeArray);const r=i?.concurrency??4;o(r),t(i),a(i),v(),await U(i?.to??"jpeg");const{concurrency:u,onProgress:f,continueOnError:d,reuseDecoders:l,...h}=i??{},g=s(f),p=!0!==l||void 0!==i?.decoder||S(i)?null:new W;try{return await c(n,r,async(e,t)=>{const n=p?p.acquire():null;try{return await L(e,{...h,...n?{decoder:n}:{},onProgress:g?e=>g(t,e):void 0})}finally{n&&p.release(n)}},{continueOnError:!0===i?.continueOnError,signal:i?.signal})}finally{p?.dispose()}}export{m as LibheifDecoder,L as convertHeic,O as convertHeicInWorker,k as convertMany,N as convertManyInWorker,j as freeSharedDecoder};
@@ -1 +1 @@
1
- "use strict";var e=require("./chunk-N2LCVW2Q.js"),i=16384,t=67108864,r=!1,n=!1;exports.MAX_NATIVE_DECODE_DIMENSION=i,exports.MAX_NATIVE_DECODE_PIXELS=t,exports.NativeHeicDecoder=class{async initialize(){if("function"!=typeof createImageBitmap||"undefined"==typeof OffscreenCanvas)throw new e.HeicConverterError("decoder_init_failed","Native HEIC decoding is unavailable in this environment.")}async decode(r){const n="undefined"!=typeof SharedArrayBuffer&&r.buffer instanceof SharedArrayBuffer?new Uint8Array(r):r,a=await createImageBitmap(new Blob([n],{type:"image/heic"}),{imageOrientation:"from-image"});try{if(a.width>i||a.height>i)throw new e.HeicConverterError("decode_failed",`Native HEIC decoding is limited to 16384px per side, got ${a.width}x${a.height}.`);if(a.width*a.height>t)throw new e.HeicConverterError("decode_failed",`Native HEIC decoding is limited to 64MP total, got ${a.width}x${a.height} (${a.width*a.height} pixels).`);const r=new OffscreenCanvas(a.width,a.height).getContext("2d",{willReadFrequently:!0});if(!r)throw new e.HeicConverterError("decode_failed","Could not acquire a 2D context for native HEIC pixel readback.");r.drawImage(a,0,0);const n=r.getImageData(0,0,a.width,a.height);return{width:n.width,height:n.height,data:n.data}}finally{a.close?.()}}free(){}},exports.__resetNativeHeicProbe=function(){r=!1,n=!1},exports.isNativeHeicRefused=function(){return r},exports.markNativeHeicRefused=function(){r=!0,n||(n=!0,console.warn("@keeratita/heic-converter: native HEIC decoding is unavailable in this environment — nativeDecode conversions will use the bundled decoder on this page."))};
1
+ var e=require("./chunk-N2LCVW2Q.js"),i=16384,t=67108864,r=!1,n=!1;exports.MAX_NATIVE_DECODE_DIMENSION=i,exports.MAX_NATIVE_DECODE_PIXELS=t,exports.NativeHeicDecoder=class{async initialize(){if("function"!=typeof createImageBitmap||"undefined"==typeof OffscreenCanvas)throw new e.HeicConverterError("decoder_init_failed","Native HEIC decoding is unavailable in this environment.")}async decode(r){const n="undefined"!=typeof SharedArrayBuffer&&r.buffer instanceof SharedArrayBuffer?new Uint8Array(r):r,a=await createImageBitmap(new Blob([n],{type:"image/heic"}),{imageOrientation:"from-image"});try{if(a.width>i||a.height>i)throw new e.HeicConverterError("decode_failed",`Native HEIC decoding is limited to 16384px per side, got ${a.width}x${a.height}.`);if(a.width*a.height>t)throw new e.HeicConverterError("decode_failed",`Native HEIC decoding is limited to 64MP total, got ${a.width}x${a.height} (${a.width*a.height} pixels).`);const r=new OffscreenCanvas(a.width,a.height).getContext("2d",{willReadFrequently:!0});if(!r)throw new e.HeicConverterError("decode_failed","Could not acquire a 2D context for native HEIC pixel readback.");r.drawImage(a,0,0);const n=r.getImageData(0,0,a.width,a.height);return{width:n.width,height:n.height,data:n.data}}finally{a.close?.()}}free(){}},exports.__resetNativeHeicProbe=function(){r=!1,n=!1},exports.isNativeHeicRefused=function(){return r},exports.markNativeHeicRefused=function(){r=!0,n||(n=!0,console.warn("@keeratita/heic-converter: native HEIC decoding is unavailable in this environment — nativeDecode conversions will use the bundled decoder on this page."))};
@@ -1 +1 @@
1
- "use strict";var e=require("./chunk-6XIPSRPS.js"),r=require("./chunk-N2LCVW2Q.js"),t="Web Worker is not supported in the current environment",o="The decoder option is not supported by convertHeicInWorker: the worker creates its own decoder (functions and class instances cannot cross the worker boundary). Use convertHeic with an injected decoder instead.",s=e=>"Worker failed"+(void 0!==e?` (could not load worker script at ${String(e)}; check the path resolves and the script is served as JavaScript, e.g. Content-Type: text/javascript)`:"");function n(t){if(void 0!==t&&(!Number.isInteger(t)||t<1||t>e.MAX_BATCH_CONCURRENCY))throw new r.HeicConverterError("invalid_concurrency",(o=t,`maxConcurrentWorkers must be an integer between 1 and ${e.MAX_BATCH_CONCURRENCY}, got: ${o}`));var o}function i(e){if(void 0!==e&&("number"!=typeof e||!Number.isFinite(e)||e<0))throw new r.HeicConverterError("invalid_input",`timeoutMs must be a finite number >= 0 (0 disables the timeout), got: ${e}`)}function a(){const e="undefined"!=typeof navigator&&"number"==typeof navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;return Math.max(1,Math.min(e,8))}var d=new Map,c=1;function u(e,r,t){let o=d.get(e);o||(o={active:0,waiters:[],parked:[]},d.set(e,o));const s={granted:!1,released:!1},n=()=>{0===o.active&&0===o.waiters.length&&(0!==o.parked.length?o.idleTimer=setTimeout(()=>{o.idleTimer=void 0;for(const e of o.parked.splice(0))e.terminate();d.delete(e)},5e3):d.delete(e))},i=e=>{if(!s.released)if(s.released=!0,e&&(o.parked.length>=2&&o.parked.shift().terminate(),o.parked.push(e)),s.granted){s.granted=!1,o.active-=1;const e=o.waiters.shift();e?e():n()}else{const e=o.waiters.indexOf(a);-1!==e&&o.waiters.splice(e,1),n()}},a=()=>{s.released||(void 0!==o.idleTimer&&(clearTimeout(o.idleTimer),o.idleTimer=void 0),s.granted=!0,o.active+=1,t(i,o.parked.pop()))};return o.active<r?a():o.waiters.push(a),i}var l={reserveWorkerSlot:u,workerSlots:d,defaultMaxWorkers:a,WORKER_POOL_IDLE_MS:5e3,MAX_PARKED_WORKERS:2};function p(a,d){return new Promise((l,p)=>{if("undefined"==typeof Worker)return void p(new r.HeicConverterError("worker_unsupported",t));if(void 0!==d.decoder)return void p(new r.HeicConverterError("invalid_input",o));try{e.validateConvertOptions(d),n(d?.maxConcurrentWorkers),i(d?.timeoutMs)}catch(e){return void p(e)}if(d.signal?.aborted)return void p(new r.HeicConverterError("aborted",e.Messages.Aborted));const m={progressMessages:0},g=c++,f=e.progressGateFor(d.onProgress);let w,k,h,y=!1,C=!1;const E=(e=!1)=>{y||(y=!0,void 0!==k&&clearTimeout(k),d.signal?.removeEventListener("abort",b),w&&(w.removeEventListener("message",T),w.removeEventListener("messageerror",$),w.removeEventListener("error",P)),e&&w?h?.(w):(w?.terminate(),h?.()))},b=()=>{E(),p(new r.HeicConverterError("aborted",e.Messages.Aborted))};d.signal?.addEventListener("abort",b,{once:!0});const W=d.timeoutMs??6e4,M=Date.now();let _;W>0&&(k=setTimeout(()=>{E(),p(new r.HeicConverterError("worker_timeout",((e,r)=>{if(void 0===r.startedAt)return`Web Worker conversion timed out after ${e}ms before a worker slot was granted — the deadline was spent waiting behind other conversions (timeoutMs includes queue wait). Raise maxConcurrentWorkers or timeoutMs, or set timeoutMs to 0 to disable the timeout.`;const t=[`${r.progressMessages} progress message(s) received`];return void 0!==r.queueWaitMs&&r.queueWaitMs>0&&t.unshift(`started after ${r.queueWaitMs}ms queued`),void 0!==r.lastPercent&&t.push(`last percent ${r.lastPercent}`),void 0!==r.unknownType&&t.push(`last unknown message type '${r.unknownType}' (worker may not implement the progress/result protocol)`),void 0!==r.staleResults&&t.push(`${r.staleResults} result(s) ignored for not echoing the request id (duplicate or stale replies must not be posted)`),void 0!==r.staleProgress&&t.push(`${r.staleProgress} progress message(s) ignored for not echoing the request id`),r.adopted&&t.push("lease adopted from the pool — a script that calls self.close() after replying stalls adopted leases"),void 0!==r.workerUrl&&t.push(`worker ${String(r.workerUrl)}`),`Web Worker conversion timed out after ${e}ms (${t.join("; ")}). Increase timeoutMs for large images, set timeoutMs to 0 to disable the timeout, and verify the worker script implements the { id, type: "progress" | "result" } protocol.`})(W,{progressMessages:m.progressMessages,lastPercent:m.lastPercent,unknownType:m.unknownType,staleResults:m.staleResults,staleProgress:m.staleProgress,adopted:C,workerUrl:d.workerUrl,startedAt:_,queueWaitMs:void 0===_?void 0:_-M})))},W));const T=t=>{const o=t.data;if("progress"===o?.type){if(o.id!==g)return void(m.staleProgress=(m.staleProgress??0)+1);m.progressMessages+=1;const r=e.clampPercent(o.percent);if(m.lastPercent=r,r>=100)return;f?.report(r);const t=f?.pendingError();return void(t&&(E(),p(t)))}if("result"!==o?.type)return void("string"==typeof o?.type&&(m.unknownType=o.type));if(o.id!==g)return void(m.staleResults=(m.staleResults??0)+1);const s=!0===o.ok&&void 0!==o.blob;if(E(s),s){try{f?.complete()}catch(e){return void p(e)}l(o.blob)}else p(new r.HeicConverterError("worker_failed",o.error??"Worker conversion failed"))},P=e=>{E();const t=e.filename?` (${e.filename}:${e.lineno})`:"";p(new r.HeicConverterError("worker_failed",`${e.message||s(d.workerUrl)}${t}`))},$=e=>{E();const t=e.data;p(new r.HeicConverterError("worker_failed",t instanceof Error?t.message:void 0!==t?String(t):s(d.workerUrl),{cause:t}))},{workerUrl:H,onProgress:R,timeoutMs:x,workerType:A,maxConcurrentWorkers:O,signal:S,...L}=d,q=`${String(H)}|${d.workerType??"classic"}`,U=v(d.maxConcurrentWorkers);h=u(q,U,(e,t)=>{if(h=e,y)t?.terminate();else{_=Date.now(),C=void 0!==t;try{w=t??new Worker(H,"module"===d.workerType?{type:"module"}:void 0)}catch(e){return E(),void p(new r.HeicConverterError("worker_create_failed",(o=e instanceof Error?e.message:String(e),`Failed to create Web Worker: ${o}`),{cause:e}))}w.addEventListener("message",T),w.addEventListener("messageerror",$),w.addEventListener("error",P);try{w.postMessage({id:g,input:a,options:L})}catch(e){E(),p(new r.HeicConverterError("worker_post_failed",(e=>`Failed to post message to Web Worker: ${e}`)(e instanceof Error?e.message:String(e)),{cause:e}))}}var o})})}function v(e){return"number"==typeof e&&Number.isInteger(e)?Math.max(1,e):a()}exports.__resetWorkerPool=function(){for(const e of d.values()){void 0!==e.idleTimer&&(clearTimeout(e.idleTimer),e.idleTimer=void 0);for(const r of e.parked.splice(0))r.terminate()}d.clear()},exports.__semaphoreTestHooks=l,exports.convertHeicInWorker=p,exports.convertManyInWorker=async function(s,a){if(!Array.isArray(s))throw new r.HeicConverterError("invalid_input",e.Messages.InputsMustBeArray);if("undefined"==typeof Worker)throw new r.HeicConverterError("worker_unsupported",t);if(void 0!==a.decoder)throw new r.HeicConverterError("invalid_input",o);e.validateConvertOptions(a),e.validateBatchOptions(a),n(a.maxConcurrentWorkers),i(a.timeoutMs);const{onProgress:d,continueOnError:c,...u}=a,l=e.progressCallbackFor(d);return e.runBoundedBatch(s,v(a.maxConcurrentWorkers),(e,r)=>p(e,{...u,...l?{onProgress:e=>l(r,e)}:{}}),{continueOnError:!0===a.continueOnError,signal:a.signal})};
1
+ var e=require("./chunk-6XIPSRPS.js"),r=require("./chunk-N2LCVW2Q.js"),t="Web Worker is not supported in the current environment",o="The decoder option is not supported by convertHeicInWorker: the worker creates its own decoder (functions and class instances cannot cross the worker boundary). Use convertHeic with an injected decoder instead.",s=e=>"Worker failed"+(void 0!==e?` (could not load worker script at ${String(e)}; check the path resolves and the script is served as JavaScript, e.g. Content-Type: text/javascript)`:"");function n(t){if(void 0!==t&&(!Number.isInteger(t)||t<1||t>e.MAX_BATCH_CONCURRENCY))throw new r.HeicConverterError("invalid_concurrency",(o=t,`maxConcurrentWorkers must be an integer between 1 and ${e.MAX_BATCH_CONCURRENCY}, got: ${o}`));var o}function i(e){if(void 0!==e&&("number"!=typeof e||!Number.isFinite(e)||e<0))throw new r.HeicConverterError("invalid_input",`timeoutMs must be a finite number >= 0 (0 disables the timeout), got: ${e}`)}function a(){const e="undefined"!=typeof navigator&&"number"==typeof navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;return Math.max(1,Math.min(e,8))}var d=new Map,c=1;function u(e,r,t){let o=d.get(e);o||(o={active:0,waiters:[],parked:[]},d.set(e,o));const s={granted:!1,released:!1},n=()=>{0===o.active&&0===o.waiters.length&&(0!==o.parked.length?o.idleTimer=setTimeout(()=>{o.idleTimer=void 0;for(const e of o.parked.splice(0))e.terminate();d.delete(e)},5e3):d.delete(e))},i=e=>{if(!s.released)if(s.released=!0,e&&(o.parked.length>=2&&o.parked.shift().terminate(),o.parked.push(e)),s.granted){s.granted=!1,o.active-=1;const e=o.waiters.shift();e?e():n()}else{const e=o.waiters.indexOf(a);-1!==e&&o.waiters.splice(e,1),n()}},a=()=>{s.released||(void 0!==o.idleTimer&&(clearTimeout(o.idleTimer),o.idleTimer=void 0),s.granted=!0,o.active+=1,t(i,o.parked.pop()))};return o.active<r?a():o.waiters.push(a),i}var l={reserveWorkerSlot:u,workerSlots:d,defaultMaxWorkers:a,WORKER_POOL_IDLE_MS:5e3,MAX_PARKED_WORKERS:2};function p(a,d){return new Promise((l,p)=>{if("undefined"==typeof Worker)return void p(new r.HeicConverterError("worker_unsupported",t));if(void 0!==d.decoder)return void p(new r.HeicConverterError("invalid_input",o));try{e.validateConvertOptions(d),n(d?.maxConcurrentWorkers),i(d?.timeoutMs)}catch(e){return void p(e)}if(d.signal?.aborted)return void p(new r.HeicConverterError("aborted",e.Messages.Aborted));const m={progressMessages:0},g=c++,f=e.progressGateFor(d.onProgress);let w,k,h,y=!1,C=!1;const E=(e=!1)=>{y||(y=!0,void 0!==k&&clearTimeout(k),d.signal?.removeEventListener("abort",b),w&&(w.removeEventListener("message",T),w.removeEventListener("messageerror",$),w.removeEventListener("error",P)),e&&w?h?.(w):(w?.terminate(),h?.()))},b=()=>{E(),p(new r.HeicConverterError("aborted",e.Messages.Aborted))};d.signal?.addEventListener("abort",b,{once:!0});const W=d.timeoutMs??6e4,M=Date.now();let _;W>0&&(k=setTimeout(()=>{E(),p(new r.HeicConverterError("worker_timeout",((e,r)=>{if(void 0===r.startedAt)return`Web Worker conversion timed out after ${e}ms before a worker slot was granted — the deadline was spent waiting behind other conversions (timeoutMs includes queue wait). Raise maxConcurrentWorkers or timeoutMs, or set timeoutMs to 0 to disable the timeout.`;const t=[`${r.progressMessages} progress message(s) received`];return void 0!==r.queueWaitMs&&r.queueWaitMs>0&&t.unshift(`started after ${r.queueWaitMs}ms queued`),void 0!==r.lastPercent&&t.push(`last percent ${r.lastPercent}`),void 0!==r.unknownType&&t.push(`last unknown message type '${r.unknownType}' (worker may not implement the progress/result protocol)`),void 0!==r.staleResults&&t.push(`${r.staleResults} result(s) ignored for not echoing the request id (duplicate or stale replies must not be posted)`),void 0!==r.staleProgress&&t.push(`${r.staleProgress} progress message(s) ignored for not echoing the request id`),r.adopted&&t.push("lease adopted from the pool — a script that calls self.close() after replying stalls adopted leases"),void 0!==r.workerUrl&&t.push(`worker ${String(r.workerUrl)}`),`Web Worker conversion timed out after ${e}ms (${t.join("; ")}). Increase timeoutMs for large images, set timeoutMs to 0 to disable the timeout, and verify the worker script implements the { id, type: "progress" | "result" } protocol.`})(W,{progressMessages:m.progressMessages,lastPercent:m.lastPercent,unknownType:m.unknownType,staleResults:m.staleResults,staleProgress:m.staleProgress,adopted:C,workerUrl:d.workerUrl,startedAt:_,queueWaitMs:void 0===_?void 0:_-M})))},W));const T=t=>{const o=t.data;if("progress"===o?.type){if(o.id!==g)return void(m.staleProgress=(m.staleProgress??0)+1);m.progressMessages+=1;const r=e.clampPercent(o.percent);if(m.lastPercent=r,r>=100)return;f?.report(r);const t=f?.pendingError();return void(t&&(E(),p(t)))}if("result"!==o?.type)return void("string"==typeof o?.type&&(m.unknownType=o.type));if(o.id!==g)return void(m.staleResults=(m.staleResults??0)+1);const s=!0===o.ok&&void 0!==o.blob;if(E(s),s){try{f?.complete()}catch(e){return void p(e)}l(o.blob)}else p(new r.HeicConverterError("worker_failed",o.error??"Worker conversion failed"))},P=e=>{E();const t=e.filename?` (${e.filename}:${e.lineno})`:"";p(new r.HeicConverterError("worker_failed",`${e.message||s(d.workerUrl)}${t}`))},$=e=>{E();const t=e.data;p(new r.HeicConverterError("worker_failed",t instanceof Error?t.message:void 0!==t?String(t):s(d.workerUrl),{cause:t}))},{workerUrl:H,onProgress:R,timeoutMs:x,workerType:A,maxConcurrentWorkers:O,signal:S,...L}=d,q=`${String(H)}|${d.workerType??"classic"}`,U=v(d.maxConcurrentWorkers);h=u(q,U,(e,t)=>{if(h=e,y)t?.terminate();else{_=Date.now(),C=void 0!==t;try{w=t??new Worker(H,"module"===d.workerType?{type:"module"}:void 0)}catch(e){return E(),void p(new r.HeicConverterError("worker_create_failed",(o=e instanceof Error?e.message:String(e),`Failed to create Web Worker: ${o}`),{cause:e}))}w.addEventListener("message",T),w.addEventListener("messageerror",$),w.addEventListener("error",P);try{w.postMessage({id:g,input:a,options:L})}catch(e){E(),p(new r.HeicConverterError("worker_post_failed",(e=>`Failed to post message to Web Worker: ${e}`)(e instanceof Error?e.message:String(e)),{cause:e}))}}var o})})}function v(e){return"number"==typeof e&&Number.isInteger(e)?Math.max(1,e):a()}exports.__resetWorkerPool=function(){for(const e of d.values()){void 0!==e.idleTimer&&(clearTimeout(e.idleTimer),e.idleTimer=void 0);for(const r of e.parked.splice(0))r.terminate()}d.clear()},exports.__semaphoreTestHooks=l,exports.convertHeicInWorker=p,exports.convertManyInWorker=async function(s,a){if(!Array.isArray(s))throw new r.HeicConverterError("invalid_input",e.Messages.InputsMustBeArray);if("undefined"==typeof Worker)throw new r.HeicConverterError("worker_unsupported",t);if(void 0!==a.decoder)throw new r.HeicConverterError("invalid_input",o);e.validateConvertOptions(a),e.validateBatchOptions(a),n(a.maxConcurrentWorkers),i(a.timeoutMs);const{onProgress:d,continueOnError:c,...u}=a,l=e.progressCallbackFor(d);return e.runBoundedBatch(s,v(a.maxConcurrentWorkers),(e,r)=>p(e,{...u,...l?{onProgress:e=>l(r,e)}:{}}),{continueOnError:!0===a.continueOnError,signal:a.signal})};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keeratita/heic-converter",
3
- "version": "0.6.2-prerelease.1",
3
+ "version": "0.6.2",
4
4
  "description": "Convert HEIC images to standard web formats (JPEG, PNG, WebP, AVIF, SVG) without breaking CSP",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1 +0,0 @@
1
- "use strict";var r="undefined"!=typeof document?document.currentScript:null;module.exports=async function(t={}){var e=t,n=!!globalThis.window,a=!!globalThis.WorkerGlobalScope,i=globalThis.process?.versions?.node&&"renderer"!=globalThis.process?.type;if(i){const{createRequire:t}=await(import("module"));var o=t("undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("heic-decoder-DRALRKX4.js",document.baseURI).href)}var s,c,f="./this.program",u="undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("heic-decoder-DRALRKX4.js",document.baseURI).href,h="";if(i){var l=o("node:fs");u.startsWith("file:")&&(h=o("node:path").dirname(o("node:url").fileURLToPath(u))+"/"),c=r=>(r=y(r)?new URL(r):r,l.readFileSync(r)),s=async(r,t=!0)=>(r=y(r)?new URL(r):r,l.readFileSync(r,t?void 0:"utf8")),process.argv.length>1&&(f=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2)}else if(n||a){try{h=new URL(".",u).href}catch{}a&&(c=r=>{var t=new XMLHttpRequest;return t.open("GET",r,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),s=async r=>{var t=await fetch(r,{credentials:"same-origin"});if(t.ok)return t.arrayBuffer();throw new Error(t.status+" : "+t.url)}}var v,p,d=console.log.bind(console),w=console.error.bind(console),g=!1,y=r=>r.startsWith("file://");class m{}class _ extends m{constructor(r){super(),this.excPtr=r}}function b(){if(!p?.buffer?.resizable){var r=er.buffer;p=new Int8Array(r),e.HEAPU8=I=new Uint8Array(r),U=new Uint32Array(r)}}function R(r){throw e.onAbort?.(r),w(r=`Aborted(${r})`),g=!0,r+=". Build with -sASSERTIONS for more info.",new WebAssembly.RuntimeError(r)}var U,A=r=>{for(;r.length>0;)r.shift()(e)},T=[],C=[],L=r=>Q(r),P=()=>V(),S=[],x=0;class E{constructor(r){this.excPtr=r,this.ptr=r-24}set_type(r){U[this.ptr+4>>2]=r}get_type(){return U[this.ptr+4>>2]}set_destructor(r){U[this.ptr+8>>2]=r}get_destructor(){return U[this.ptr+8>>2]}set_caught(r){r=r?1:0,p[this.ptr+12]=r}get_caught(){return 0!=p[this.ptr+12]}set_rethrown(r){r=r?1:0,p[this.ptr+13]=r}get_rethrown(){return 0!=p[this.ptr+13]}init(r,t){this.set_adjusted_ptr(0),this.set_type(r),this.set_destructor(t)}set_adjusted_ptr(r){U[this.ptr+16>>2]=r}get_adjusted_ptr(){return U[this.ptr+16>>2]}}var I,F=null,k=r=>J(r),j=r=>{var t=F?.excPtr;if(!t)return k(0),0;var e=new E(t);e.set_adjusted_ptr(t);var n=e.get_type();if(!n)return k(0),t;for(var a of r){if(!a||a===n)break;var i=e.ptr+16;if(rr(a,n,i))return k(a),t}return k(n),t},M=r=>{throw r},W=(r,t)=>Math.ceil(r/t)*t,D=r=>{var t=(r-er.buffer.byteLength+65535)/65536|0;try{return er.grow(t),b(),1}catch(r){}},N={},q=()=>{if(!q.strings){var r={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:f};for(var t in N)void 0===N[t]?delete r[t]:r[t]=N[t];var e=[];for(var t in r)e.push(`${t}=${r[t]}`);q.strings=e}return q.strings},G=(r,t,e)=>((r,t,e,n)=>{for(var a=e,i=e+n-1,o=0;o<r.length;++o){var s=r.codePointAt(o);if(s<=127){if(e>=i)break;t[e++]=s}else if(s<=2047){if(e+1>=i)break;t[e++]=192|s>>6,t[e++]=128|63&s}else if(s<=65535){if(e+2>=i)break;t[e++]=224|s>>12,t[e++]=128|s>>6&63,t[e++]=128|63&s}else{if(e+3>=i)break;t[e++]=240|s>>18,t[e++]=128|s>>12&63,t[e++]=128|s>>6&63,t[e++]=128|63&s,o++}}return t[e]=0,e-a})(r,I,t,e),H=r=>{for(var t=0,e=0;e<r.length;++e){var n=r.charCodeAt(e);n<=127?t++:n<=2047?t+=2:n>=55296&&n<=57343?(t+=4,++e):t+=3}return t},$=[null,[],[]],B=globalThis.TextDecoder&&new TextDecoder,K=(r,t)=>{var e=$[r];t&&10!==t?e.push(t):((1===r?d:w)(((r,t=0)=>{var e=((r,t)=>{for(var e=t+void 0;r[t]&&!(t>=e);)++t;return t})(r,t);if(e-t>16&&r.buffer&&B)return B.decode(r.subarray(t,e));for(var n="";t<e;){var a=r[t++];if(128&a){var i=63&r[t++];if(192!=(224&a)){var o=63&r[t++];if((a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&r[t++])<65536)n+=String.fromCharCode(a);else{var s=a-65536;n+=String.fromCharCode(55296|s>>10,56320|1023&s)}}else n+=String.fromCharCode((31&a)<<6|i)}else n+=String.fromCharCode(a)}return n})(e)),e.length=0)},O=[],X=r=>{var t=O[r];return t||(O[r]=t=nr.get(r)),t};e.noExitRuntime&&e.noExitRuntime,e.print&&(d=e.print),e.printErr&&(w=e.printErr),e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram);var z,J,Q,V,Y,Z,rr,tr,er,nr,ar=e.preInit;if(ar)for("function"==typeof ar&&(e.preInit=ar=[ar]);ar.length>0;)ar.shift()();var ir,or={j:r=>{var t=new E(r);return t.get_caught()||(t.set_caught(!0),x--),t.set_rethrown(!1),S.push(t),tr(r)},l:()=>{z(0,0);var r=S.pop();Y(r.excPtr),F=null},a:()=>j([]),b:r=>j([r]),u:()=>{S.length||R("no exception to throw");var r=S.at(-1),t=r.excPtr;r.set_rethrown(!0),r.set_caught(!1),x++,Z(t),t=F=new _(t),M(t)},h:(r,t,e)=>{new E(r).init(t,e),Z(r),r=F=new _(r),x++,M(r)},t:()=>x,e:r=>{(r=>{throw r})(r=F??=new _(r))},w:()=>{},y:()=>R(""),n:function(r){try{e.__progressCb&&e.__progressCb(r)}catch(r){}},v:r=>{var t=I.length,e=2147483648;if((r>>>=0)>e)return!1;for(var n=1;n<=4;n*=2){var a=t*(1+.2/n);a=Math.min(a,r+100663296);var i=Math.min(e,W(Math.max(r,a),65536));if(D(i))return!0}return!1},A:(r,t)=>{var e=0,n=0;for(var a of q()){var i=t+e;U[r+n>>2]=i,e+=G(a,i,1/0)+1,n+=4}return 0},B:(r,t)=>{var e=q();U[r>>2]=e.length;var n=0;for(var a of e)n+=H(a)+1;return U[t>>2]=n,0},x:()=>52,z:function(r,t){return 70},o:(r,t,e,n)=>{for(var a=0,i=0;i<e;i++){var o=U[t>>2],s=U[t+4>>2];t+=8;for(var c=0;c<s;c++)K(r,I[o+c]);a+=s}return U[n>>2]=a,0},d:function(r,t){var e=P();try{return X(r)(t)}catch(r){if(L(e),!(r instanceof m))throw r;z(1,0)}},c:function(r,t,e){var n=P();try{return X(r)(t,e)}catch(r){if(L(n),!(r instanceof m))throw r;z(1,0)}},i:function(r,t,e,n){var a=P();try{return X(r)(t,e,n)}catch(r){if(L(a),!(r instanceof m))throw r;z(1,0)}},q:function(r,t,e,n,a){var i=P();try{return X(r)(t,e,n,a)}catch(r){if(L(i),!(r instanceof m))throw r;z(1,0)}},m:function(r,t,e,n,a,i){var o=P();try{return X(r)(t,e,n,a,i)}catch(r){if(L(o),!(r instanceof m))throw r;z(1,0)}},s:function(r,t,e,n,a,i){var o=P();try{return X(r)(t,e,n,a,i)}catch(r){if(L(o),!(r instanceof m))throw r;z(1,0)}},k:function(r){var t=P();try{X(r)()}catch(r){if(L(t),!(r instanceof m))throw r;z(1,0)}},C:function(r,t){var e=P();try{X(r)(t)}catch(r){if(L(e),!(r instanceof m))throw r;z(1,0)}},g:function(r,t){var e=P();try{X(r)(t)}catch(r){if(L(e),!(r instanceof m))throw r;z(1,0)}},f:function(r,t,e){var n=P();try{X(r)(t,e)}catch(r){if(L(n),!(r instanceof m))throw r;z(1,0)}},r:function(r,t,e,n){var a=P();try{X(r)(t,e,n)}catch(r){if(L(a),!(r instanceof m))throw r;z(1,0)}},p:function(r,t,e,n,a){var i=P();try{X(r)(t,e,n,a)}catch(r){if(L(i),!(r instanceof m))throw r;z(1,0)}},D:function(r,t,e){var n=P();try{X(r)(t,e)}catch(r){if(L(n),!(r instanceof m))throw r;z(1,0)}}};return ir=await async function(){function t(r){var t;return t=ir=r.exports,e._heic_decode=t.G,e._heic_result_free=t.H,e._free=t.J,e._malloc=t.K,z=t.L,J=t.M,Q=t.N,V=t.O,Y=t.P,Z=t.Q,rr=t.R,tr=t.S,er=t.E,nr=t.I,b(),ir}var n,a={a:or},o=e.instantiateWasm;return o?new Promise(r=>{o(a,e=>r(t(e)))}):(v??=e.locateFile?(n="heic-decoder.wasm",e.locateFile?e.locateFile(n,h):h+n):new URL("heic-decoder.wasm","undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("heic-decoder-DRALRKX4.js",document.baseURI).href).href,t((await async function(r,t,e){if(!i)try{var n=fetch(t,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(n,e)}catch(r){w(`wasm streaming compile failed: ${r}`),w("falling back to ArrayBuffer instantiation")}return async function(r,t){try{var e=await async function(r){try{var t=await s(r);return new Uint8Array(t)}catch{}return function(r){if(c)return c(r);throw"both async and sync fetching of the wasm failed"}(r)}(r);return await WebAssembly.instantiate(e,t)}catch(r){w(`failed to asynchronously prepare wasm: ${r}`),R(r)}}(t,e)}(0,v,a)).instance))}(),await async function(){var r;(r=e.preRun)&&("function"==typeof r&&(r=[r]),C.push(...r)),A(C);var t,n=e.setStatus;n&&(n("Running..."),await new Promise(r=>setTimeout(r,1)),setTimeout(n,1,"")),g||(ir.F(),e.onRuntimeInitialized?.(),(t=e.postRun)&&("function"==typeof t&&(t=[t]),T.push(...t)),A(T))}(),e};
@@ -1 +0,0 @@
1
- var r=async function(r={}){var t=r,e=!!globalThis.window,n=!!globalThis.WorkerGlobalScope,a=globalThis.process?.versions?.node&&"renderer"!=globalThis.process?.type;if(a){const{createRequire:r}=await(import("module"));var i=r(import.meta.url)}var o,s,c="./this.program",f=import.meta.url,u="";if(a){var h=i("node:fs");f.startsWith("file:")&&(u=i("node:path").dirname(i("node:url").fileURLToPath(f))+"/"),s=r=>(r=d(r)?new URL(r):r,h.readFileSync(r)),o=async(r,t=!0)=>(r=d(r)?new URL(r):r,h.readFileSync(r,t?void 0:"utf8")),process.argv.length>1&&(c=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2)}else if(e||n){try{u=new URL(".",f).href}catch{}n&&(s=r=>{var t=new XMLHttpRequest;return t.open("GET",r,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),o=async r=>{var t=await fetch(r,{credentials:"same-origin"});if(t.ok)return t.arrayBuffer();throw new Error(t.status+" : "+t.url)}}var l,v,p=console.log.bind(console),w=console.error.bind(console),g=!1,d=r=>r.startsWith("file://");class y{}class m extends y{constructor(r){super(),this.excPtr=r}}function _(){if(!v?.buffer?.resizable){var r=tr.buffer;v=new Int8Array(r),t.HEAPU8=L=new Uint8Array(r),A=new Uint32Array(r)}}function b(r){throw t.onAbort?.(r),w(r=`Aborted(${r})`),g=!0,r+=". Build with -sASSERTIONS for more info.",new WebAssembly.RuntimeError(r)}var A,R=r=>{for(;r.length>0;)r.shift()(t)},T=[],x=[],P=r=>Q(r),S=()=>X(),C=[],E=0;class U{constructor(r){this.excPtr=r,this.ptr=r-24}set_type(r){A[this.ptr+4>>2]=r}get_type(){return A[this.ptr+4>>2]}set_destructor(r){A[this.ptr+8>>2]=r}get_destructor(){return A[this.ptr+8>>2]}set_caught(r){r=r?1:0,v[this.ptr+12]=r}get_caught(){return 0!=v[this.ptr+12]}set_rethrown(r){r=r?1:0,v[this.ptr+13]=r}get_rethrown(){return 0!=v[this.ptr+13]}init(r,t){this.set_adjusted_ptr(0),this.set_type(r),this.set_destructor(t)}set_adjusted_ptr(r){A[this.ptr+16>>2]=r}get_adjusted_ptr(){return A[this.ptr+16>>2]}}var L,k=null,M=r=>K(r),W=r=>{var t=k?.excPtr;if(!t)return M(0),0;var e=new U(t);e.set_adjusted_ptr(t);var n=e.get_type();if(!n)return M(0),t;for(var a of r){if(!a||a===n)break;var i=e.ptr+16;if(Z(a,n,i))return M(a),t}return M(n),t},F=r=>{throw r},I=(r,t)=>Math.ceil(r/t)*t,j=r=>{var t=(r-tr.buffer.byteLength+65535)/65536|0;try{return tr.grow(t),_(),1}catch(r){}},G={},H=()=>{if(!H.strings){var r={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:c};for(var t in G)void 0===G[t]?delete r[t]:r[t]=G[t];var e=[];for(var t in r)e.push(`${t}=${r[t]}`);H.strings=e}return H.strings},$=(r,t,e)=>((r,t,e,n)=>{for(var a=e,i=e+n-1,o=0;o<r.length;++o){var s=r.codePointAt(o);if(s<=127){if(e>=i)break;t[e++]=s}else if(s<=2047){if(e+1>=i)break;t[e++]=192|s>>6,t[e++]=128|63&s}else if(s<=65535){if(e+2>=i)break;t[e++]=224|s>>12,t[e++]=128|s>>6&63,t[e++]=128|63&s}else{if(e+3>=i)break;t[e++]=240|s>>18,t[e++]=128|s>>12&63,t[e++]=128|s>>6&63,t[e++]=128|63&s,o++}}return t[e]=0,e-a})(r,L,t,e),B=r=>{for(var t=0,e=0;e<r.length;++e){var n=r.charCodeAt(e);n<=127?t++:n<=2047?t+=2:n>=55296&&n<=57343?(t+=4,++e):t+=3}return t},D=[null,[],[]],N=globalThis.TextDecoder&&new TextDecoder,O=(r,t)=>{var e=D[r];t&&10!==t?e.push(t):((1===r?p:w)(((r,t=0)=>{var e=((r,t)=>{for(var e=t+void 0;r[t]&&!(t>=e);)++t;return t})(r,t);if(e-t>16&&r.buffer&&N)return N.decode(r.subarray(t,e));for(var n="";t<e;){var a=r[t++];if(128&a){var i=63&r[t++];if(192!=(224&a)){var o=63&r[t++];if((a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&r[t++])<65536)n+=String.fromCharCode(a);else{var s=a-65536;n+=String.fromCharCode(55296|s>>10,56320|1023&s)}}else n+=String.fromCharCode((31&a)<<6|i)}else n+=String.fromCharCode(a)}return n})(e)),e.length=0)},q=[],z=r=>{var t=q[r];return t||(q[r]=t=er.get(r)),t};t.noExitRuntime&&t.noExitRuntime,t.print&&(p=t.print),t.printErr&&(w=t.printErr),t.arguments&&t.arguments,t.thisProgram&&(c=t.thisProgram);var J,K,Q,X,V,Y,Z,rr,tr,er,nr=t.preInit;if(nr)for("function"==typeof nr&&(t.preInit=nr=[nr]);nr.length>0;)nr.shift()();var ar,ir={j:r=>{var t=new U(r);return t.get_caught()||(t.set_caught(!0),E--),t.set_rethrown(!1),C.push(t),rr(r)},l:()=>{J(0,0);var r=C.pop();V(r.excPtr),k=null},a:()=>W([]),b:r=>W([r]),u:()=>{C.length||b("no exception to throw");var r=C.at(-1),t=r.excPtr;r.set_rethrown(!0),r.set_caught(!1),E++,Y(t),t=k=new m(t),F(t)},h:(r,t,e)=>{new U(r).init(t,e),Y(r),r=k=new m(r),E++,F(r)},t:()=>E,e:r=>{(r=>{throw r})(r=k??=new m(r))},w:()=>{},y:()=>b(""),n:function(r){try{t.__progressCb&&t.__progressCb(r)}catch(r){}},v:r=>{var t=L.length,e=2147483648;if((r>>>=0)>e)return!1;for(var n=1;n<=4;n*=2){var a=t*(1+.2/n);a=Math.min(a,r+100663296);var i=Math.min(e,I(Math.max(r,a),65536));if(j(i))return!0}return!1},A:(r,t)=>{var e=0,n=0;for(var a of H()){var i=t+e;A[r+n>>2]=i,e+=$(a,i,1/0)+1,n+=4}return 0},B:(r,t)=>{var e=H();A[r>>2]=e.length;var n=0;for(var a of e)n+=B(a)+1;return A[t>>2]=n,0},x:()=>52,z:function(r,t){return 70},o:(r,t,e,n)=>{for(var a=0,i=0;i<e;i++){var o=A[t>>2],s=A[t+4>>2];t+=8;for(var c=0;c<s;c++)O(r,L[o+c]);a+=s}return A[n>>2]=a,0},d:function(r,t){var e=S();try{return z(r)(t)}catch(r){if(P(e),!(r instanceof y))throw r;J(1,0)}},c:function(r,t,e){var n=S();try{return z(r)(t,e)}catch(r){if(P(n),!(r instanceof y))throw r;J(1,0)}},i:function(r,t,e,n){var a=S();try{return z(r)(t,e,n)}catch(r){if(P(a),!(r instanceof y))throw r;J(1,0)}},q:function(r,t,e,n,a){var i=S();try{return z(r)(t,e,n,a)}catch(r){if(P(i),!(r instanceof y))throw r;J(1,0)}},m:function(r,t,e,n,a,i){var o=S();try{return z(r)(t,e,n,a,i)}catch(r){if(P(o),!(r instanceof y))throw r;J(1,0)}},s:function(r,t,e,n,a,i){var o=S();try{return z(r)(t,e,n,a,i)}catch(r){if(P(o),!(r instanceof y))throw r;J(1,0)}},k:function(r){var t=S();try{z(r)()}catch(r){if(P(t),!(r instanceof y))throw r;J(1,0)}},C:function(r,t){var e=S();try{z(r)(t)}catch(r){if(P(e),!(r instanceof y))throw r;J(1,0)}},g:function(r,t){var e=S();try{z(r)(t)}catch(r){if(P(e),!(r instanceof y))throw r;J(1,0)}},f:function(r,t,e){var n=S();try{z(r)(t,e)}catch(r){if(P(n),!(r instanceof y))throw r;J(1,0)}},r:function(r,t,e,n){var a=S();try{z(r)(t,e,n)}catch(r){if(P(a),!(r instanceof y))throw r;J(1,0)}},p:function(r,t,e,n,a){var i=S();try{z(r)(t,e,n,a)}catch(r){if(P(i),!(r instanceof y))throw r;J(1,0)}},D:function(r,t,e){var n=S();try{z(r)(t,e)}catch(r){if(P(n),!(r instanceof y))throw r;J(1,0)}}};return ar=await async function(){function r(r){var e;return e=ar=r.exports,t._heic_decode=e.G,t._heic_result_free=e.H,t._free=e.J,t._malloc=e.K,J=e.L,K=e.M,Q=e.N,X=e.O,V=e.P,Y=e.Q,Z=e.R,rr=e.S,tr=e.E,er=e.I,_(),ar}var e,n={a:ir},i=t.instantiateWasm;return i?new Promise(t=>{i(n,e=>t(r(e)))}):(l??=t.locateFile?(e="heic-decoder.wasm",t.locateFile?t.locateFile(e,u):u+e):new URL("heic-decoder.wasm",import.meta.url).href,r((await async function(r,t,e){if(!a)try{var n=fetch(t,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(n,e)}catch(r){w(`wasm streaming compile failed: ${r}`),w("falling back to ArrayBuffer instantiation")}return async function(r,t){try{var e=await async function(r){try{var t=await o(r);return new Uint8Array(t)}catch{}return function(r){if(s)return s(r);throw"both async and sync fetching of the wasm failed"}(r)}(r);return await WebAssembly.instantiate(e,t)}catch(r){w(`failed to asynchronously prepare wasm: ${r}`),b(r)}}(t,e)}(0,l,n)).instance))}(),await async function(){var r;(r=t.preRun)&&("function"==typeof r&&(r=[r]),x.push(...r)),R(x);var e,n=t.setStatus;n&&(n("Running..."),await new Promise(r=>setTimeout(r,1)),setTimeout(n,1,"")),g||(ar.F(),t.onRuntimeInitialized?.(),(e=t.postRun)&&("function"==typeof e&&(e=[e]),T.push(...e)),R(T))}(),t};export{r as default};