@keeratita/heic-converter 0.6.2-prerelease → 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.
- package/dist/chunk-6XIPSRPS.js +1 -0
- package/dist/chunk-N2LCVW2Q.js +1 -1
- package/dist/exif-H2Q7BO7Y.js +1 -1
- package/dist/heic-decoder-LWGIYGE3.js +1 -0
- package/dist/heic-decoder-ZFSRP4EX.mjs +1 -0
- package/dist/heic-decoder.wasm +0 -0
- package/dist/heic-decoder.wasm.br +0 -0
- package/dist/heic-decoder.wasm.gz +0 -0
- package/dist/index.d.mts +566 -0
- package/dist/index.d.ts +412 -30
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/native-JFFONPCS.js +1 -1
- package/dist/worker-4HVYKWRG.js +1 -0
- package/dist/{worker-VA6WQF25.mjs → worker-N6W3ASWN.mjs} +1 -1
- package/package.json +5 -5
- package/dist/batch.d.ts +0 -27
- package/dist/chunk-TND3VERK.js +0 -1
- package/dist/errors.d.ts +0 -28
- package/dist/heic-decoder-2EERQO7N.js +0 -1
- package/dist/heic-decoder-IZMSMJZ7.mjs +0 -1
- package/dist/messages/core.d.ts +0 -60
- package/dist/messages/worker.d.ts +0 -33
- package/dist/progress.d.ts +0 -39
- package/dist/render/canvas.d.ts +0 -71
- package/dist/render/exif.d.ts +0 -37
- package/dist/types.d.ts +0 -257
- package/dist/validate.d.ts +0 -59
- package/dist/wasm/fault.d.ts +0 -3
- package/dist/wasm/index.d.ts +0 -1
- package/dist/wasm/native.d.ts +0 -46
- package/dist/wasm/wrapper.d.ts +0 -61
- package/dist/worker-DISSAV3W.js +0 -1
- package/dist/worker.d.ts +0 -128
- /package/dist/{chunk-BTAX2PFV.mjs → chunk-GR5XSYDQ.mjs} +0 -0
|
@@ -0,0 +1 @@
|
|
|
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;
|
package/dist/chunk-N2LCVW2Q.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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;
|
package/dist/exif-H2Q7BO7Y.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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};
|
package/dist/heic-decoder.wasm
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
interface DecodedImage {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
/**
|
|
5
|
+
* RGBA pixel data, interleaved, row-major, 4 bytes per pixel. Always a
|
|
6
|
+
* plain `ArrayBuffer` owned by the returned array — never a WASM-heap
|
|
7
|
+
* view — so it stays valid after `LibheifDecoder.free()` and passes
|
|
8
|
+
* directly to `new ImageData(...)` / `putImageData`, including the
|
|
9
|
+
* `ImageData` overload that requires `Uint8ClampedArray<ArrayBuffer>`
|
|
10
|
+
* under TS >= 5.7.
|
|
11
|
+
*/
|
|
12
|
+
data: Uint8ClampedArray;
|
|
13
|
+
/**
|
|
14
|
+
* Raw EXIF block copied from the source file, normalized to the JPEG APP1
|
|
15
|
+
* payload form: `"Exif\0\0"` followed by the TIFF structure. Present
|
|
16
|
+
* whenever the file carries an Exif item — including files where libheif
|
|
17
|
+
* already applied `irot`/`imir` (reported independently of
|
|
18
|
+
* {@link DecodedImage.orientation}). `convertHeic` re-injects it into
|
|
19
|
+
* JPEG (APP1) and PNG (`eXIf`) output when `preserveExif: true`;
|
|
20
|
+
* raw-decode consumers can attach it to their own encoder output (e.g.
|
|
21
|
+
* `sharp`'s `.withMetadata({ exif })`). Owned by the returned object,
|
|
22
|
+
* never a WASM-heap view.
|
|
23
|
+
*/
|
|
24
|
+
exif?: Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* EXIF orientation of the **stored** pixels (1–8, EXIF tag 274 semantics;
|
|
27
|
+
* 1 = upright). Absent or 1 means no rotation is pending. libheif applies
|
|
28
|
+
* `irot`/`imir` container transforms at decode — for those files this is
|
|
29
|
+
* 1 and the pixels are upright. A value > 1 means the orientation comes
|
|
30
|
+
* only from the Exif item: `convertHeic` applies it automatically unless
|
|
31
|
+
* `applyOrientation: false`; raw `decode()` consumers get stored pixels
|
|
32
|
+
* and must apply it themselves. Decoders that do not report orientation
|
|
33
|
+
* may omit this field.
|
|
34
|
+
*/
|
|
35
|
+
orientation?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Decoder contract used by {@link ConvertOptions.decoder} /
|
|
39
|
+
* {@link ConvertManyOptions.decoder} and implemented by `LibheifDecoder`.
|
|
40
|
+
*
|
|
41
|
+
* Lifecycle rules followed by the library (implementations may rely on them):
|
|
42
|
+
* - `initialize()` is called before every `decode()`; repeated/concurrent
|
|
43
|
+
* calls must be cheap (e.g. memoize the load promise).
|
|
44
|
+
* - `decode()` is awaited before the library calls `free()`; the returned
|
|
45
|
+
* `DecodedImage` must therefore not reference decoder-owned memory that
|
|
46
|
+
* `free()` releases (copy pixels out, as `LibheifDecoder` does).
|
|
47
|
+
* - `free()` is called at most once per conversion. Decoders **injected**
|
|
48
|
+
* via options are never freed by the library — the caller owns their
|
|
49
|
+
* lifetime.
|
|
50
|
+
*
|
|
51
|
+
* Concurrency: with `convertMany`, a single injected decoder is shared by
|
|
52
|
+
* all concurrent conversions, so `decode()` must be safe to call concurrently
|
|
53
|
+
* on one instance (no shared mutable state across in-flight decodes).
|
|
54
|
+
*/
|
|
55
|
+
interface IHeicDecoder {
|
|
56
|
+
/** Initializes the decoder (e.g. loading the WebAssembly module). */
|
|
57
|
+
initialize(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Decodes HEIC binary data into raw RGBA pixel data; `onProgress`
|
|
60
|
+
* receives the progress percentage.
|
|
61
|
+
*/
|
|
62
|
+
decode(data: Uint8Array, onProgress?: (percent: number) => void): Promise<DecodedImage>;
|
|
63
|
+
/** Cleans up allocated resources. Idempotent: safe to call multiple times. */
|
|
64
|
+
free(): void;
|
|
65
|
+
}
|
|
66
|
+
type ImageFormat = 'jpeg' | 'jpg' | 'png' | 'svg' | 'webp' | 'avif';
|
|
67
|
+
/**
|
|
68
|
+
* Formats accepted by {@link ConvertOptions.to} (case-insensitive).
|
|
69
|
+
* `'jpg'` is an alias of `'jpeg'`. `'avif'` requires an environment whose
|
|
70
|
+
* canvas can encode AVIF (Chromium/Firefox today); elsewhere it rejects with
|
|
71
|
+
* `format_unsupported`.
|
|
72
|
+
*/
|
|
73
|
+
declare const SUPPORTED_FORMATS: readonly ImageFormat[];
|
|
74
|
+
/** Default encoding quality used when `quality` is not provided. */
|
|
75
|
+
declare const DEFAULT_QUALITY = 0.92;
|
|
76
|
+
/**
|
|
77
|
+
* Accepted input for every convert entry point. `ArrayBufferView` is a
|
|
78
|
+
* declared (tested) surface: `DataView` and non-Uint8 typed arrays are read
|
|
79
|
+
* as raw bytes via byteOffset/byteLength, SharedArrayBuffer-backed views
|
|
80
|
+
* included. Cross-realm Blob-likes (anything exposing `arrayBuffer()`, e.g.
|
|
81
|
+
* a Blob from another frame) are accepted at runtime even though
|
|
82
|
+
* `instanceof Blob` cannot see them.
|
|
83
|
+
*/
|
|
84
|
+
type HeicInput = Blob | ArrayBuffer | ArrayBufferView;
|
|
85
|
+
/**
|
|
86
|
+
* How {@link convertHeic} returns the converted image.
|
|
87
|
+
* - `'blob'` — a `Blob` (the default; browser-native, works everywhere)
|
|
88
|
+
* - `'dataUrl'` — a `data:image/...;base64,…` string (previews, `<img src>`)
|
|
89
|
+
* - `'arrayBuffer'` — raw bytes (uploads, WebCodecs, Node-friendly transfer)
|
|
90
|
+
*/
|
|
91
|
+
type OutputShape = 'blob' | 'dataUrl' | 'arrayBuffer';
|
|
92
|
+
/** Resolved return type of `convertHeic`/`convertMany` for an output shape. */
|
|
93
|
+
type ConvertResult<S extends OutputShape> = S extends 'dataUrl' ? string : S extends 'arrayBuffer' ? ArrayBuffer : Blob;
|
|
94
|
+
/** Crop rectangle in **post-orientation display pixels** (top-left origin). */
|
|
95
|
+
interface CropOptions {
|
|
96
|
+
/** Left edge of the crop box. @default 0 */
|
|
97
|
+
x?: number;
|
|
98
|
+
/** Top edge of the crop box. @default 0 */
|
|
99
|
+
y?: number;
|
|
100
|
+
/** Crop width in pixels. Must be a positive integer and fit inside the image. */
|
|
101
|
+
width: number;
|
|
102
|
+
/** Crop height in pixels. Must be a positive integer and fit inside the image. */
|
|
103
|
+
height: number;
|
|
104
|
+
}
|
|
105
|
+
/** Per-item outcome when `continueOnError: true`. */
|
|
106
|
+
type ConvertItemResult<T = Blob> = {
|
|
107
|
+
index: number;
|
|
108
|
+
ok: true;
|
|
109
|
+
result: T;
|
|
110
|
+
} | {
|
|
111
|
+
index: number;
|
|
112
|
+
ok: false;
|
|
113
|
+
error: Error;
|
|
114
|
+
};
|
|
115
|
+
interface ResizeOptions {
|
|
116
|
+
/**
|
|
117
|
+
* Maximum width in pixels; downscaled to fit while preserving the aspect
|
|
118
|
+
* ratio. Images smaller than the bound are never upscaled.
|
|
119
|
+
*/
|
|
120
|
+
maxWidth?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Maximum height in pixels; downscaled to fit while preserving the aspect
|
|
123
|
+
* ratio. Images smaller than the bound are never upscaled.
|
|
124
|
+
*/
|
|
125
|
+
maxHeight?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Uniform scale factor for both dimensions (e.g. 0.5 halves the image).
|
|
128
|
+
* Takes precedence over `maxWidth`/`maxHeight` when set.
|
|
129
|
+
*/
|
|
130
|
+
scale?: number;
|
|
131
|
+
}
|
|
132
|
+
interface ConvertOptions extends ResizeOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Target format; must be one of {@link SUPPORTED_FORMATS}. An unknown
|
|
135
|
+
* value is rejected up front, before the input is decoded.
|
|
136
|
+
* @default 'jpeg'
|
|
137
|
+
*/
|
|
138
|
+
to?: ImageFormat;
|
|
139
|
+
/**
|
|
140
|
+
* Quality between 0.0 and 1.0 (inclusive). Applies to `'jpeg'`, `'jpg'`,
|
|
141
|
+
* `'webp'` and `'avif'` but is validated for every format: an out-of-range
|
|
142
|
+
* value (e.g. `90` from a 0-100 scale) throws regardless of `to`.
|
|
143
|
+
* @default 0.92
|
|
144
|
+
*/
|
|
145
|
+
quality?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Custom decoder to inject; a default `LibheifDecoder` is used otherwise.
|
|
148
|
+
* The library never calls `free()` on an injected decoder.
|
|
149
|
+
*/
|
|
150
|
+
decoder?: IHeicDecoder;
|
|
151
|
+
/**
|
|
152
|
+
* Progress callback receiving percentages normalized and clamped to
|
|
153
|
+
* 0–100; the final 100% is emitted only when the conversion succeeds. A
|
|
154
|
+
* callback that throws rejects the conversion with
|
|
155
|
+
* `progress_callback_failed`.
|
|
156
|
+
*/
|
|
157
|
+
onProgress?: (percent: number) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Rotate/flip the output to match the source's EXIF orientation, applied
|
|
160
|
+
* as a canvas transform during rendering; `irot`/`imir` container
|
|
161
|
+
* transforms are already applied by the decoder and never stacked on top.
|
|
162
|
+
* `false` keeps the exact stored-pixel geometry. A non-boolean value is
|
|
163
|
+
* rejected up front with `invalid_input`.
|
|
164
|
+
* @default true
|
|
165
|
+
*/
|
|
166
|
+
applyOrientation?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Representation of the converted image. See {@link OutputShape}.
|
|
169
|
+
* @default 'blob'
|
|
170
|
+
*/
|
|
171
|
+
output?: OutputShape;
|
|
172
|
+
/**
|
|
173
|
+
* Cancels the conversion at stage boundaries (input read, decoder init,
|
|
174
|
+
* before/after decode, before encode). `convertHeicInWorker` aborts
|
|
175
|
+
* immediately by terminating the worker; the synchronous WASM decode
|
|
176
|
+
* itself cannot be preempted mid-call. An aborted signal rejects with
|
|
177
|
+
* code `aborted`.
|
|
178
|
+
*/
|
|
179
|
+
signal?: AbortSignal;
|
|
180
|
+
/**
|
|
181
|
+
* Crop rectangle in post-orientation display pixels (the geometry the
|
|
182
|
+
* image will be displayed in). Applied before resize: `scale`/`maxWidth`/
|
|
183
|
+
* `maxHeight` then downscale the cropped region. Out-of-bounds crops
|
|
184
|
+
* reject with `invalid_crop`.
|
|
185
|
+
*/
|
|
186
|
+
crop?: CropOptions;
|
|
187
|
+
/**
|
|
188
|
+
* Copy the source HEIC's EXIF block into JPEG (APP1) and PNG (`eXIf`
|
|
189
|
+
* chunk) output so converted files keep camera metadata (orientation, GPS,
|
|
190
|
+
* timestamps). This **preserves private data** like GPS — set
|
|
191
|
+
* deliberately. Ignored for `webp`/`svg` output.
|
|
192
|
+
* @default false
|
|
193
|
+
*/
|
|
194
|
+
preserveExif?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Decode with the platform's native HEIC stack (`createImageBitmap` on
|
|
197
|
+
* Safari/iOS, Edge, Windows) instead of the bundled libheif WASM decoder,
|
|
198
|
+
* skipping its ~300 KB payload. Hosts without native HEIC support fall
|
|
199
|
+
* back to libheif on the same conversion; the refusal is cached per realm.
|
|
200
|
+
* Ignored (libheif used) with an injected `decoder`, `preserveExif: true`
|
|
201
|
+
* or `applyOrientation: false`. Native output is upright and progress
|
|
202
|
+
* fires only at completion (tile progress is a libheif feature).
|
|
203
|
+
* @default false
|
|
204
|
+
*/
|
|
205
|
+
nativeDecode?: boolean;
|
|
206
|
+
}
|
|
207
|
+
interface ConvertManyOptions extends Omit<ConvertOptions, 'onProgress'> {
|
|
208
|
+
/**
|
|
209
|
+
* Maximum number of conversions running concurrently.
|
|
210
|
+
* @default 4
|
|
211
|
+
*/
|
|
212
|
+
concurrency?: number;
|
|
213
|
+
/**
|
|
214
|
+
* Progress callback receiving the 0-based item index and its percentage
|
|
215
|
+
* (normalized to 0–100) during decoding.
|
|
216
|
+
*/
|
|
217
|
+
onProgress?: (index: number, percent: number) => void;
|
|
218
|
+
/**
|
|
219
|
+
* Custom decoder to inject; the same instance is shared by all concurrent
|
|
220
|
+
* conversions, so it must be safe for concurrent `decode()` calls (see
|
|
221
|
+
* {@link IHeicDecoder}). A fresh default `LibheifDecoder` is created per
|
|
222
|
+
* item otherwise.
|
|
223
|
+
*/
|
|
224
|
+
decoder?: IHeicDecoder;
|
|
225
|
+
/**
|
|
226
|
+
* Resolve with `ConvertItemResult[]` in input order instead of rejecting
|
|
227
|
+
* the whole batch on the first failure; all items run to completion.
|
|
228
|
+
* Up-front option validation failures still reject normally (a typo is a
|
|
229
|
+
* caller bug, not an item failure).
|
|
230
|
+
* @default false
|
|
231
|
+
*/
|
|
232
|
+
continueOnError?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Reuse one library-owned `LibheifDecoder` per concurrent runner across
|
|
235
|
+
* items instead of creating (and WASM-initializing) a fresh instance per
|
|
236
|
+
* item — amortizes the module load in large batches while preserving the
|
|
237
|
+
* exclusive-use invariant (an instance is only ever held by one runner,
|
|
238
|
+
* never decodes concurrently). Ignored when `decoder` is injected.
|
|
239
|
+
* @default false
|
|
240
|
+
*/
|
|
241
|
+
reuseDecoders?: boolean;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface LibheifDecoderOptions {
|
|
245
|
+
/**
|
|
246
|
+
* Custom WASM file locator, for serving the binary from a custom route or CDN.
|
|
247
|
+
*/
|
|
248
|
+
locateFile?: (path: string, prefix: string) => string;
|
|
249
|
+
/**
|
|
250
|
+
* Raw WASM binary, used instead of fetching the file. Accepts an
|
|
251
|
+
* `ArrayBuffer` or any `ArrayBufferView` (e.g. a Node.js `Buffer` from
|
|
252
|
+
* `fs.readFileSync`).
|
|
253
|
+
*/
|
|
254
|
+
wasmBinary?: ArrayBuffer | ArrayBufferView;
|
|
255
|
+
/**
|
|
256
|
+
* Advanced: extra properties merged into the Emscripten module argument
|
|
257
|
+
* object (e.g. `instantiateWasm` for streaming compilation). Prefer
|
|
258
|
+
* `locateFile`/`wasmBinary` for the common cases; keys must not collide
|
|
259
|
+
* with them.
|
|
260
|
+
*/
|
|
261
|
+
moduleOverrides?: Record<string, unknown>;
|
|
262
|
+
}
|
|
263
|
+
declare class LibheifDecoder implements IHeicDecoder {
|
|
264
|
+
private options?;
|
|
265
|
+
private module;
|
|
266
|
+
private initPromise;
|
|
267
|
+
private initGeneration;
|
|
268
|
+
constructor(options?: LibheifDecoderOptions);
|
|
269
|
+
/**
|
|
270
|
+
* Initializes the WebAssembly module (the raw C-ABI decoder surface).
|
|
271
|
+
* Safe to call concurrently: the module is loaded at most once per instance.
|
|
272
|
+
*/
|
|
273
|
+
initialize(): Promise<void>;
|
|
274
|
+
/**
|
|
275
|
+
* Decodes HEIC binary data into raw RGBA pixel data.
|
|
276
|
+
* @param onProgress Optional progress callback; receives percentages
|
|
277
|
+
* normalized and clamped to 0-100.
|
|
278
|
+
*/
|
|
279
|
+
decode(data: Uint8Array, onProgress?: (percent: number) => void): Promise<DecodedImage>;
|
|
280
|
+
/**
|
|
281
|
+
* Cleans up the WebAssembly decoder resources. Idempotent. After `free()`,
|
|
282
|
+
* the next `initialize()` — or `decode()` directly, which re-initializes
|
|
283
|
+
* transparently — loads a fresh module. Safe during an in-flight
|
|
284
|
+
* `initialize()`: a load completing after `free()` discards itself instead
|
|
285
|
+
* of resurrecting state.
|
|
286
|
+
*/
|
|
287
|
+
free(): void;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
interface WorkerConvertOptions extends Omit<ConvertOptions, 'decoder'> {
|
|
291
|
+
/**
|
|
292
|
+
* URL of the worker script. Should be a compile-time constant (e.g.
|
|
293
|
+
* `new URL('./worker.js', import.meta.url)` under a bundler); the script
|
|
294
|
+
* runs with the page's privileges.
|
|
295
|
+
*/
|
|
296
|
+
workerUrl: string | URL;
|
|
297
|
+
/**
|
|
298
|
+
* Milliseconds to wait for the worker result before rejecting with a
|
|
299
|
+
* timeout. Queueing for a free worker slot counts toward this. Defaults to
|
|
300
|
+
* 60000; 0 disables the timeout.
|
|
301
|
+
*/
|
|
302
|
+
timeoutMs?: number;
|
|
303
|
+
/**
|
|
304
|
+
* Worker script type. Use `'module'` when the script uses ES module
|
|
305
|
+
* imports (e.g. `import { convertHeic } from ...`); `'classic'`
|
|
306
|
+
* scripts must be pre-bundled.
|
|
307
|
+
* @default 'classic'
|
|
308
|
+
*/
|
|
309
|
+
workerType?: 'classic' | 'module';
|
|
310
|
+
/**
|
|
311
|
+
* Upper bound on simultaneously live workers for this worker script; calls
|
|
312
|
+
* beyond the bound queue until a slot frees, keeping bulk conversions from
|
|
313
|
+
* exhausting memory or the browser's worker limit. Must be an integer from
|
|
314
|
+
* 1 to 64 — each worker is a full WASM boot with its own heap, so an
|
|
315
|
+
* unbounded value is a page-taking-down footgun, not capacity. Defaults to
|
|
316
|
+
* `navigator.hardwareConcurrency` clamped to 1–8.
|
|
317
|
+
*/
|
|
318
|
+
maxConcurrentWorkers?: number;
|
|
319
|
+
}
|
|
320
|
+
interface CorrelatedMessage {
|
|
321
|
+
id: number;
|
|
322
|
+
}
|
|
323
|
+
/** Progress message a worker script posts to report decode progress. */
|
|
324
|
+
interface WorkerProgressMessage extends CorrelatedMessage {
|
|
325
|
+
type: 'progress';
|
|
326
|
+
percent: number;
|
|
327
|
+
}
|
|
328
|
+
/** Result message a worker script posts to settle a conversion. */
|
|
329
|
+
interface WorkerResultMessage extends CorrelatedMessage {
|
|
330
|
+
type: 'result';
|
|
331
|
+
ok: boolean;
|
|
332
|
+
/**
|
|
333
|
+
* The converted image as `convertHeic` returned it inside the worker:
|
|
334
|
+
* `Blob`, data-URL string, or `ArrayBuffer`. The field name `blob` is kept
|
|
335
|
+
* for protocol compatibility.
|
|
336
|
+
*/
|
|
337
|
+
blob?: Blob | string | ArrayBuffer;
|
|
338
|
+
error?: string;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Options for {@link convertManyInWorker}: the {@link convertHeicInWorker}
|
|
342
|
+
* worker options plus the batch semantics of `convertMany`.
|
|
343
|
+
*/
|
|
344
|
+
interface WorkerBatchOptions extends Omit<WorkerConvertOptions, 'onProgress'> {
|
|
345
|
+
/**
|
|
346
|
+
* Per-item progress callback: receives the 0-based item index and its
|
|
347
|
+
* progress percentage (normalized 0–100). Values below 100 may also be
|
|
348
|
+
* reported for items that ultimately fail; the 100% event fires only for
|
|
349
|
+
* items that succeed.
|
|
350
|
+
*/
|
|
351
|
+
onProgress?: (index: number, percent: number) => void;
|
|
352
|
+
/**
|
|
353
|
+
* Resolve with per-item results instead of rejecting the batch on the
|
|
354
|
+
* first failure; all items run to completion (see
|
|
355
|
+
* `ConvertManyOptions.continueOnError`).
|
|
356
|
+
* @default false
|
|
357
|
+
*/
|
|
358
|
+
continueOnError?: boolean;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Stable, machine-readable error codes attached to every error the library
|
|
363
|
+
* throws (as `HeicConverterError.code`). Codes are part of the public API:
|
|
364
|
+
* they are additive-only and never repurposed, so callers can branch on
|
|
365
|
+
* `error.code` instead of matching on message strings.
|
|
366
|
+
*/
|
|
367
|
+
type HeicConverterErrorCode = 'invalid_input' | 'invalid_quality' | 'invalid_resize' | 'invalid_format' | 'invalid_crop' | 'invalid_concurrency' | 'decoder_init_failed' | 'decode_failed' | 'progress_callback_failed' | 'render_encode_failed' | 'unsupported_environment' | 'format_unsupported' | 'aborted' | 'worker_unsupported' | 'worker_load_failed' | 'worker_create_failed' | 'worker_post_failed' | 'worker_failed' | 'worker_timeout' | 'batch_item_failed';
|
|
368
|
+
/**
|
|
369
|
+
* Error thrown by all first-party code paths. Extends `Error` so existing
|
|
370
|
+
* `instanceof Error` / message-based handling keeps working; the `code`
|
|
371
|
+
* (and, for batch failures, `itemIndex`/`itemTotal`/`failedCount`) fields
|
|
372
|
+
* add a structured discriminator without changing message text.
|
|
373
|
+
*/
|
|
374
|
+
declare class HeicConverterError extends Error {
|
|
375
|
+
readonly code: HeicConverterErrorCode;
|
|
376
|
+
/** 0-based index of the failing input. Only set on `batch_item_failed` errors. */
|
|
377
|
+
readonly itemIndex?: number;
|
|
378
|
+
/** Total number of inputs in the batch. Only set on `batch_item_failed` errors. */
|
|
379
|
+
readonly itemTotal?: number;
|
|
380
|
+
/** How many items failed overall. Only set on `batch_item_failed` errors. */
|
|
381
|
+
readonly failedCount?: number;
|
|
382
|
+
constructor(code: HeicConverterErrorCode, message: string, options?: {
|
|
383
|
+
cause?: unknown;
|
|
384
|
+
itemIndex?: number;
|
|
385
|
+
itemTotal?: number;
|
|
386
|
+
failedCount?: number;
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Converts a HEIC image inside a Web Worker so the main thread stays responsive
|
|
392
|
+
* during the (potentially slow) WASM decode. The implementation lives in
|
|
393
|
+
* `src/worker.ts`, fetched as a lazy chunk on the first call — a deployment
|
|
394
|
+
* missing that chunk rejects with `worker_load_failed` (original failure on
|
|
395
|
+
* `cause`) rather than a raw module-load error.
|
|
396
|
+
*
|
|
397
|
+
* The worker script is user-provided and must handle the following message
|
|
398
|
+
* protocol (types are exported as {@link WorkerProgressMessage} and
|
|
399
|
+
* {@link WorkerResultMessage}); the canonical reference implementation is
|
|
400
|
+
* `docs/worker.js`, and this example is kept byte-equal to it (modulo the
|
|
401
|
+
* import specifier) by `test/unit/docs-sync.test.ts`:
|
|
402
|
+
*
|
|
403
|
+
* ```js
|
|
404
|
+
* // converter.worker.js
|
|
405
|
+
* import { convertHeic } from '@keeratita/heic-converter';
|
|
406
|
+
*
|
|
407
|
+
* self.onmessage = async (event) => {
|
|
408
|
+
* const { id, input, options } = event.data;
|
|
409
|
+
* try {
|
|
410
|
+
* const blob = await convertHeic(input, {
|
|
411
|
+
* ...options,
|
|
412
|
+
* onProgress: (percent) => self.postMessage({ id, type: 'progress', percent }),
|
|
413
|
+
* });
|
|
414
|
+
* // With output: 'arrayBuffer' the payload is zero-copy via a transfer list.
|
|
415
|
+
* self.postMessage(
|
|
416
|
+
* { id, type: 'result', ok: true, blob },
|
|
417
|
+
* blob instanceof ArrayBuffer ? [blob] : []
|
|
418
|
+
* );
|
|
419
|
+
* } catch (error) {
|
|
420
|
+
* self.postMessage({ id, type: 'result', ok: false, error: error?.stack ?? error?.message ?? String(error) });
|
|
421
|
+
* }
|
|
422
|
+
* };
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* ```ts
|
|
426
|
+
* const jpegBlob = await convertHeicInWorker(heicBlob, {
|
|
427
|
+
* workerUrl: new URL('./converter.worker.js', import.meta.url),
|
|
428
|
+
* workerType: 'module',
|
|
429
|
+
* to: 'jpeg',
|
|
430
|
+
* });
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* Only `progress` and `result` messages are understood; any other message type
|
|
434
|
+
* is ignored (the first unknown type is reported in the timeout diagnostic).
|
|
435
|
+
* Use `workerType: 'module'` when the script uses ES module imports (as above);
|
|
436
|
+
* `'classic'` scripts must be pre-bundled, since static ES imports are not
|
|
437
|
+
* supported there.
|
|
438
|
+
*
|
|
439
|
+
* Notes that are easy to trip over:
|
|
440
|
+
* - `decoder` is rejected — class instances cannot cross the worker boundary,
|
|
441
|
+
* so the worker creates its own.
|
|
442
|
+
* - `timeoutMs` is a per-call deadline that **includes queueing** for a free
|
|
443
|
+
* worker slot, not just the conversion itself.
|
|
444
|
+
* - An error raised *inside* the worker comes back stringified under
|
|
445
|
+
* `worker_failed`: the numeric `code` does not survive the boundary, so match
|
|
446
|
+
* on the message. Option validation happens here instead, so an invalid
|
|
447
|
+
* option keeps its own code.
|
|
448
|
+
* - Workers are pooled per `workerUrl`, so concurrent callers to the same URL
|
|
449
|
+
* share one bounded set rather than spawning unbounded workers.
|
|
450
|
+
*
|
|
451
|
+
* @param input HEIC image as a Blob (incl. File), ArrayBuffer, or ArrayBufferView
|
|
452
|
+
* (typed array or DataView).
|
|
453
|
+
* @param options Conversion options plus the worker script URL.
|
|
454
|
+
* @returns The converted image as a Blob, data URL string, or ArrayBuffer
|
|
455
|
+
* depending on `options.output` (default Blob).
|
|
456
|
+
*/
|
|
457
|
+
declare function convertHeicInWorker<S extends OutputShape = 'blob'>(input: HeicInput, options: WorkerConvertOptions & {
|
|
458
|
+
output?: S;
|
|
459
|
+
}): Promise<ConvertResult<S>>;
|
|
460
|
+
/**
|
|
461
|
+
* Converts multiple HEIC images inside Web Workers, mirroring {@link convertMany}
|
|
462
|
+
* semantics (input order, bounded concurrency, `batch_item_failed` aggregation
|
|
463
|
+
* or `continueOnError` per-item results). Concurrency is bounded by
|
|
464
|
+
* `maxConcurrentWorkers` (default `navigator.hardwareConcurrency` clamped to
|
|
465
|
+
* 1–8), so a large batch never exhausts memory or the browser's worker limit;
|
|
466
|
+
* workers are pooled per `workerUrl`, so items reuse live instances instead
|
|
467
|
+
* of paying boot per item (the script must stay alive across requests — see
|
|
468
|
+
* the protocol above). Runs via {@link convertHeicInWorker}: `decoder` cannot
|
|
469
|
+
* be injected and `workerUrl` is required — see it for the protocol and the
|
|
470
|
+
* `timeoutMs`, worker-boundary, and `worker_load_failed` caveats.
|
|
471
|
+
*
|
|
472
|
+
* ```ts
|
|
473
|
+
* const blobs = await convertManyInWorker(heicFiles, {
|
|
474
|
+
* workerUrl: new URL('./converter.worker.js', import.meta.url),
|
|
475
|
+
* workerType: 'module',
|
|
476
|
+
* to: 'webp',
|
|
477
|
+
* continueOnError: true, // get per-item results instead of batch rejection
|
|
478
|
+
* });
|
|
479
|
+
* ```
|
|
480
|
+
*
|
|
481
|
+
* Overloads must mirror `convertManyInWorker` in `src/worker.ts`: the deferred
|
|
482
|
+
* call below erases the union, so drift here is a public typing bug that `tsc`,
|
|
483
|
+
* the unit tests and the bundle guard all fail to catch.
|
|
484
|
+
*
|
|
485
|
+
* @param inputs HEIC images as Blobs (incl. Files), ArrayBuffers, or ArrayBufferViews.
|
|
486
|
+
* @param options Batch + worker conversion options (see {@link WorkerBatchOptions}).
|
|
487
|
+
* @returns The converted images in input order, or per-item result entries
|
|
488
|
+
* when `continueOnError: true`.
|
|
489
|
+
*/
|
|
490
|
+
declare function convertManyInWorker<S extends OutputShape = 'blob'>(inputs: HeicInput[], options: WorkerBatchOptions & {
|
|
491
|
+
output?: S;
|
|
492
|
+
continueOnError: true;
|
|
493
|
+
}): Promise<ConvertItemResult<ConvertResult<S>>[]>;
|
|
494
|
+
declare function convertManyInWorker<S extends OutputShape = 'blob'>(inputs: HeicInput[], options: WorkerBatchOptions & {
|
|
495
|
+
output?: S;
|
|
496
|
+
continueOnError?: false;
|
|
497
|
+
}): Promise<ConvertResult<S>[]>;
|
|
498
|
+
declare function convertManyInWorker<S extends OutputShape = 'blob'>(inputs: HeicInput[], options: WorkerBatchOptions & {
|
|
499
|
+
output?: S;
|
|
500
|
+
continueOnError: boolean;
|
|
501
|
+
}): Promise<Array<ConvertResult<S> | ConvertItemResult<ConvertResult<S>>>>;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Releases any cached decoder resources.
|
|
505
|
+
*
|
|
506
|
+
* Decoders are now created and released per conversion, so there is no shared
|
|
507
|
+
* instance to free. This function is kept for API compatibility.
|
|
508
|
+
*/
|
|
509
|
+
declare function freeSharedDecoder(): void;
|
|
510
|
+
/**
|
|
511
|
+
* Converts HEIC image data to a standard web format (JPEG, PNG, WebP, AVIF,
|
|
512
|
+
* or SVG).
|
|
513
|
+
*
|
|
514
|
+
* @param input HEIC image as a Blob (incl. File), ArrayBuffer, or ArrayBufferView
|
|
515
|
+
* (typed array or DataView).
|
|
516
|
+
* @param options Conversion configuration options (see {@link ConvertOptions}).
|
|
517
|
+
* @returns The converted image as a Blob, data URL string, or ArrayBuffer
|
|
518
|
+
* depending on `options.output` (default Blob).
|
|
519
|
+
* @throws HeicConverterError with a machine-readable `code`:
|
|
520
|
+
* `invalid_input` (unsupported input type or option value),
|
|
521
|
+
* `invalid_quality`, `invalid_resize`, `invalid_crop`,
|
|
522
|
+
* `invalid_format` (unknown `to` value), `decoder_init_failed` (WASM
|
|
523
|
+
* module could not load), `decode_failed` (invalid/corrupt HEIC),
|
|
524
|
+
* `unsupported_environment` (no canvas APIs — e.g. Node.js, where raw RGBA
|
|
525
|
+
* decoding via `LibheifDecoder` is the supported path),
|
|
526
|
+
* `format_unsupported` (environment cannot encode the format, e.g. AVIF
|
|
527
|
+
* in Safari), `aborted` (`options.signal` aborted), or
|
|
528
|
+
* `render_encode_failed`.
|
|
529
|
+
*/
|
|
530
|
+
declare function convertHeic<S extends OutputShape = 'blob'>(input: HeicInput, options?: ConvertOptions & {
|
|
531
|
+
output?: S;
|
|
532
|
+
}): Promise<ConvertResult<S>>;
|
|
533
|
+
/**
|
|
534
|
+
* Converts multiple HEIC images to a standard web format.
|
|
535
|
+
*
|
|
536
|
+
* Conversions run with a bounded concurrency (default 4) and results are
|
|
537
|
+
* returned in the same order as the inputs. By default, if any conversion
|
|
538
|
+
* fails, the returned promise rejects as soon as the failure is known
|
|
539
|
+
* (in-flight conversions are allowed to finish in the background) with a
|
|
540
|
+
* `batch_item_failed` HeicConverterError carrying `itemIndex`, `itemTotal`,
|
|
541
|
+
* and `failedCount` — a batch is all-or-nothing. With
|
|
542
|
+
* `options.continueOnError: true` the promise instead fulfills with
|
|
543
|
+
* per-item `ConvertItemResult` entries and all items run to completion
|
|
544
|
+
* (a mid-batch abort completes not-yet-started items with `aborted`
|
|
545
|
+
* entries instead of launching them).
|
|
546
|
+
*
|
|
547
|
+
* @param inputs HEIC images as Blobs (incl. Files), ArrayBuffers, or ArrayBufferViews.
|
|
548
|
+
* @param options Batch conversion options (see {@link ConvertManyOptions}).
|
|
549
|
+
* @returns The converted images in input order: results array by default,
|
|
550
|
+
* or per-item result entries when `continueOnError: true`.
|
|
551
|
+
*/
|
|
552
|
+
declare function convertMany<S extends OutputShape = 'blob'>(inputs: HeicInput[], options: ConvertManyOptions & {
|
|
553
|
+
output?: S;
|
|
554
|
+
continueOnError: true;
|
|
555
|
+
}): Promise<ConvertItemResult<ConvertResult<S>>[]>;
|
|
556
|
+
declare function convertMany<S extends OutputShape = 'blob'>(inputs: HeicInput[], options?: ConvertManyOptions & {
|
|
557
|
+
output?: S;
|
|
558
|
+
continueOnError?: false;
|
|
559
|
+
}): Promise<ConvertResult<S>[]>;
|
|
560
|
+
declare function convertMany<S extends OutputShape = 'blob'>(inputs: HeicInput[], options: ConvertManyOptions & {
|
|
561
|
+
output?: S;
|
|
562
|
+
continueOnError: boolean;
|
|
563
|
+
}): Promise<Array<ConvertResult<S> | ConvertItemResult<ConvertResult<S>>>>;
|
|
564
|
+
|
|
565
|
+
export { DEFAULT_QUALITY, HeicConverterError, LibheifDecoder, SUPPORTED_FORMATS, convertHeic, convertHeicInWorker, convertMany, convertManyInWorker, freeSharedDecoder };
|
|
566
|
+
export type { ConvertItemResult, ConvertManyOptions, ConvertOptions, ConvertResult, CropOptions, DecodedImage, HeicConverterErrorCode, HeicInput, IHeicDecoder, ImageFormat, LibheifDecoderOptions, OutputShape, ResizeOptions, WorkerBatchOptions, WorkerConvertOptions, WorkerProgressMessage, WorkerResultMessage };
|