@hussmartinez/image-sdk 0.7.1 → 0.7.3
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/assets/image/job.worker.js +1 -1
- package/dist/assets/image/render.worker.js +1 -1
- package/dist/element.js +2 -2
- package/dist/index.js +1 -1
- package/dist/lazy/{inline-job-worker-evNz8nkZ.js → inline-job-worker-B-NXVhUL.js} +2 -2
- package/dist/lazy/{inline-job-worker-evNz8nkZ.js.map → inline-job-worker-B-NXVhUL.js.map} +1 -1
- package/dist/lazy/{inline-worker-Peuoqhhv.js → inline-worker-DXE7yL4C.js} +2 -2
- package/dist/lazy/{inline-worker-Peuoqhhv.js.map → inline-worker-DXE7yL4C.js.map} +1 -1
- package/dist/react.js +1 -1
- package/dist/shared/{core-BPCYhBPk.js → core-BiKXMhuI.js} +42 -13
- package/dist/shared/core-BiKXMhuI.js.map +1 -0
- package/dist/shared/{editor-MivFzZ2M.js → editor-BLQCHS3B.js} +2 -2
- package/dist/shared/{editor-MivFzZ2M.js.map → editor-BLQCHS3B.js.map} +1 -1
- package/package.json +2 -2
- package/dist/shared/core-BPCYhBPk.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),t=!1;function n(){t||=!0}var r=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),i=class extends Error{name=`SdkError`;code;constructor(e,t,i={}){super(t,`cause`in i?{cause:i.cause}:void 0),n(),this.code=e,Object.defineProperty(this,r,{value:!0}),i.details!==void 0&&(this.details=i.details)}};function a(e,t){if(typeof e!=`object`||!e)return!1;let n=e;return(e instanceof i||n[r]===!0)&&typeof n.code==`string`&&typeof n.message==`string`&&(t===void 0||n.code===t)}var o=8,s=16,c=`UNKNOWN`;function l(e,t={}){let n=t.includeStack??!1,r=h(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=u(e),s=n&&p(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),p(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function u(e){if(a(e)){let t={name:e.name,code:e.code,message:e.message},n=d(e.details);return n!==void 0&&(t.details=n),t}if(p(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:c,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:c,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:c,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function d(e){if(!m(e))return;let t=f(e,0);return m(t)?t:void 0}function f(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=s)){if(Array.isArray(e))return e.flatMap(e=>{let n=f(e,t+1);return n===void 0?[]:[n]});if(m(e)){let n={};for(let[r,i]of Object.entries(e)){let e=f(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function p(e){return typeof e==`object`&&!!e}function m(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function h(e){if(e===void 0)return o;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var g=`hm-rpc`;function _(e){return{protocol:g,version:1,...e}}function v(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function y(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=x(e)?e:S(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return w(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):T(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),E(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function b(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function x(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function S(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var C=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function w(e){let t=globalThis;return C.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function T(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function E(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function D(e,t={}){let n=t.scope??globalThis,r=t.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{n.postMessage(e,t)},s=(e,t)=>{o(_({type:`error`,id:e,error:l(t,{includeStack:r})}))},c=(e,t,r)=>{let a=y(r,!0);try{b((e,t)=>n.postMessage(e,t),_({type:`result`,id:e,output:a.value}),a.transferables)}catch(n){s(e,new i(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${t}" can't be sent to the page.`,{cause:n,details:{method:t}}))}},u=t=>{let{id:n,method:r}=t,l=Object.hasOwn(e,r)?e[r]:void 0;if(typeof l!=`function`){s(n,new i(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${r}".`,{details:{method:r}}));return}let u=new AbortController;a.set(n,u);let d={signal:u.signal,progress:e=>{a.get(n)===u&&o(_({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{a.delete(n),c(n,r,e)},e=>{a.delete(n),s(n,e)})},d=e=>{o(_({type:`crash`,error:l(e,{includeStack:r})}))};n.addEventListener(`message`,e=>{let t=v(e.data);t!==void 0&&t.version===1&&(t.type===`call`?u(t):t.type===`cancel`&&a.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;d(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{d(e.reason)}),o(_({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var O=(/* @__PURE__ */ e((e=>{var t=Object.defineProperty;(e=>t(e,`__esModule`,{value:!0}))(e),((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(e,{GIFEncoder:()=>A,applyPalette:()=>S,default:()=>B,nearestColor:()=>k,nearestColorIndex:()=>D,nearestColorIndexWithDistance:()=>O,prequantize:()=>x,quantize:()=>_,snapColorsToPalette:()=>T});var n={signature:`GIF`,version:`89a`,trailer:59,extensionIntroducer:33,applicationExtensionLabel:255,graphicControlExtensionLabel:249,imageSeparator:44,signatureSize:3,versionSize:3,globalColorTableFlagMask:128,colorResolutionMask:112,sortFlagMask:8,globalColorTableSizeMask:7,applicationIdentifierSize:8,applicationAuthCodeSize:3,disposalMethodMask:28,userInputFlagMask:2,transparentColorFlagMask:1,localColorTableFlagMask:128,interlaceFlagMask:64,idSortFlagMask:32,localColorTableSizeMask:7};function r(e=256){let t=0,n=new Uint8Array(e);return{get buffer(){return n.buffer},reset(){t=0},bytesView(){return n.subarray(0,t)},bytes(){return n.slice(0,t)},writeByte(e){r(t+1),n[t]=e,t++},writeBytes(e,i=0,a=e.length){r(t+a);for(let r=0;r<a;r++)n[t++]=e[r+i]},writeBytesView(e,i=0,a=e.byteLength){r(t+a),n.set(e.subarray(i,i+a),t),t+=a}};function r(e){var r=n.length;if(r>=e)return;e=Math.max(e,r*(r<1048576?2:1.125)>>>0),r!=0&&(e=Math.max(e,256));let i=n;n=new Uint8Array(e),t>0&&n.set(i.subarray(0,t),0)}}var i=12,a=5003,o=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function s(e,t,n,s,c=r(512),l=/* @__PURE__ */ new Uint8Array(256),u=new Int32Array(a),d=new Int32Array(a)){let f=u.length,p=Math.max(2,s);l.fill(0),d.fill(0),u.fill(-1);let m=0,h=0,g=p+1,_=g,v=!1,y=_,b=(1<<y)-1,x=1<<g-1,S=x+1,C=x+2,w=0,T=n[0],E=0;for(let e=f;e<65536;e*=2)++E;E=8-E,c.writeByte(p),O(x);let D=n.length;for(let e=1;e<D;e++)next_block:{let t=n[e],r=(t<<i)+T,a=t<<E^T;if(u[a]===r){T=d[a];break next_block}let o=a===0?1:f-a;for(;u[a]>=0;)if(a-=o,a<0&&(a+=f),u[a]===r){T=d[a];break next_block}O(T),T=t,C<1<<i?(d[a]=C++,u[a]=r):(u.fill(-1),C=x+2,v=!0,O(x))}return O(T),O(S),c.writeByte(0),c.bytesView();function O(e){for(m&=o[h],h>0?m|=e<<h:m=e,h+=y;h>=8;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;if((C>b||v)&&(v?(y=_,b=(1<<y)-1,v=!1):(++y,b=y===i?1<<y:(1<<y)-1)),e==S){for(;h>0;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;w>0&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0)}}}var c=s;function l(e,t,n){return e<<8&63488|t<<2&992|n>>3}function u(e,t,n,r){return e>>4|t&240|(n&240)<<4|(r&240)<<8}function d(e,t,n){return e>>4<<8|t&240|n>>4}function f(e,t,n){return e<t?t:e>n?n:e}function p(e){return e*e}function m(e,t,n){var r=0,i=1e100;let a=e[t],o=a.cnt,s=a.ac,c=a.rc,l=a.gc,u=a.bc;for(var d=a.fw;d!=0;d=e[d].fw){let t=e[d],a=t.cnt,m=o*a/(o+a);if(!(m>=i)){var f=0;n&&(f+=m*p(t.ac-s),f>=i)||(f+=m*p(t.rc-c),f>=i||(f+=m*p(t.gc-l),f>=i||(f+=m*p(t.bc-u),f>=i||(i=f,r=d))))}}a.err=i,a.nn=r}function h(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function g(e,t){let n=Array(t===`rgb444`?4096:65536),r=e.length;if(t===`rgba4444`)for(let t=0;t<r;++t){let r=e[t],i=r>>24&255,a=r>>16&255,o=r>>8&255,s=r&255,c=u(s,o,a,i),l=c in n?n[c]:n[c]=h();l.rc+=s,l.gc+=o,l.bc+=a,l.ac+=i,l.cnt++}else if(t===`rgb444`)for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=d(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}else for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=l(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}return n}function _(e,t,n={}){let{format:r=`rgb565`,clearAlpha:i=!0,clearAlphaColor:a=0,clearAlphaThreshold:o=0,oneBitAlpha:s=!1}=n;if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);let c=new Uint32Array(e.buffer),l=n.useSqrt!==!1,u=r===`rgba4444`,d=g(c,r),h=d.length,_=h-1,y=new Uint32Array(h+1);for(var b=0,x=0;x<h;++x){let e=d[x];if(e!=null){var S=1/e.cnt;u&&(e.ac*=S),e.rc*=S,e.gc*=S,e.bc*=S,d[b++]=e}}p(t)/b<.022&&(l=!1);for(var x=0;x<b-1;++x)d[x].fw=x+1,d[x+1].bk=x,l&&(d[x].cnt=Math.sqrt(d[x].cnt));l&&(d[x].cnt=Math.sqrt(d[x].cnt));var C,w,T;for(x=0;x<b;++x){m(d,x,!1);var E=d[x].err;for(w=++y[0];w>1&&(T=w>>1,!(d[C=y[T]].err<=E));w=T)y[w]=C;y[w]=x}var D=b-t;for(x=0;x<D;){for(var O;;){var k=y[1];if(O=d[k],O.tm>=O.mtm&&d[O.nn].mtm<=O.tm)break;O.mtm==_?k=y[1]=y[y[0]--]:(m(d,k,!1),O.tm=x);var E=d[k].err;for(w=1;(T=w+w)<=y[0]&&(T<y[0]&&d[y[T]].err>d[y[T+1]].err&&T++,!(E<=d[C=y[T]].err));w=T)y[w]=C;y[w]=k}var A=d[O.nn],j=O.cnt,M=A.cnt,S=1/(j+M);u&&(O.ac=S*(j*O.ac+M*A.ac)),O.rc=S*(j*O.rc+M*A.rc),O.gc=S*(j*O.gc+M*A.gc),O.bc=S*(j*O.bc+M*A.bc),O.cnt+=A.cnt,O.mtm=++x,d[A.bk].fw=A.fw,d[A.fw].bk=A.bk,A.mtm=_}let N=[];var P=0;for(x=0;;++P){let e=f(Math.round(d[x].rc),0,255),t=f(Math.round(d[x].gc),0,255),n=f(Math.round(d[x].bc),0,255),r=255;u&&(r=f(Math.round(d[x].ac),0,255),s&&(r=r<=(typeof s==`number`?s:127)?0:255),i&&r<=o&&(e=t=n=a,r=0));let c=u?[e,t,n,r]:[e,t,n];if(v(N,c)||N.push(c),(x=d[x].fw)==0)break}return N}function v(e,t){for(let n=0;n<e.length;n++){let r=e[n],i=r[0]===t[0]&&r[1]===t[1]&&r[2]===t[2],a=r.length>=4&&t.length>=4?r[3]===t[3]:!0;if(i&&a)return!0}return!1}function y(e,t){for(var n=0,r=0;r<e.length;r++){let i=e[r]-t[r];n+=i*i}return n}function b(e,t){return t>1?Math.round(e/t)*t:e}function x(e,{roundRGB:t=5,roundAlpha:n=10,oneBitAlpha:r=null}={}){let i=new Uint32Array(e.buffer);for(let e=0;e<i.length;e++){let a=i[e],o=a>>24&255,s=a>>16&255,c=a>>8&255,l=a&255;o=b(o,n),r&&(o=o<=(typeof r==`number`?r:127)?0:255),l=b(l,t),c=b(c,t),s=b(s,t),i[e]=o<<24|s<<16|c<<8|l}}function S(e,t,n=`rgb565`){if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);if(t.length>256)throw Error(`applyPalette() only works with 256 colors or less`);let r=new Uint32Array(e.buffer),i=r.length,a=n===`rgb444`?4096:65536,o=new Uint8Array(i),s=Array(a);if(n===`rgba4444`)for(let e=0;e<i;e++){let n=r[e],i=n>>24&255,a=n>>16&255,c=n>>8&255,l=n&255,d=u(l,c,a,i),f=d in s?s[d]:s[d]=C(l,c,a,i,t);o[e]=f}else{let e=n===`rgb444`?d:l;for(let n=0;n<i;n++){let i=r[n],a=i>>16&255,c=i>>8&255,l=i&255,u=e(l,c,a),d=u in s?s[u]:s[u]=w(l,c,a,t);o[n]=d}}return o}function C(e,t,n,r,i){let a=0,o=1e100;for(let s=0;s<i.length;s++){let c=i[s],l=c[3],u=E(l-r);if(u>o)continue;let d=c[0];if(u+=E(d-e),u>o)continue;let f=c[1];if(u+=E(f-t),u>o)continue;let p=c[2];u+=E(p-n),u>o||(o=u,a=s)}return a}function w(e,t,n,r){let i=0,a=1e100;for(let o=0;o<r.length;o++){let s=r[o],c=s[0],l=E(c-e);if(l>a)continue;let u=s[1];if(l+=E(u-t),l>a)continue;let d=s[2];l+=E(d-n),l>a||(a=l,i=o)}return i}function T(e,t,n=5){if(!e.length||!t.length)return;let r=e.map(e=>e.slice(0,3)),i=n*n,a=e[0].length;for(let n=0;n<t.length;n++){let o=t[n];o=o.length<a?[o[0],o[1],o[2],255]:o.length>a?o.slice(0,3):o.slice();let s=O(r,o.slice(0,3),y),c=s[0],l=s[1];l>0&&l<=i&&(e[c]=o)}}function E(e){return e*e}function D(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return i}function O(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return[i,r]}function k(e,t,n=y){return e[D(e,t,n)]}function A(e={}){let{initialCapacity:t=4096,auto:i=!0}=e,a=r(t),o=5003,s=/* @__PURE__ */ new Uint8Array(256),c=new Int32Array(o),l=new Int32Array(o),u=!1;return{reset(){a.reset(),u=!1},finish(){a.writeByte(n.trailer)},bytes(){return a.bytes()},bytesView(){return a.bytesView()},get buffer(){return a.buffer},get stream(){return a},writeHeader:d,writeFrame(e,t,n,r={}){let{transparent:o=!1,transparentIndex:f=0,delay:p=0,palette:m=null,repeat:h=0,colorDepth:g=8,dispose:_=-1}=r,v=!1;if(i?u||=(v=!0,d(),!0):v=!!r.first,t=Math.max(0,Math.floor(t)),n=Math.max(0,Math.floor(n)),v){if(!m)throw Error(`First frame must include a { palette } option`);M(a,t,n,m,g),P(a,m),h>=0&&N(a,h)}let y=Math.round(p/10);j(a,_,y,o,f);let b=!!m&&!v;F(a,t,n,b?m:null),b&&P(a,m),I(a,e,t,n,g,s,c,l)}};function d(){R(a,`GIF89a`)}}function j(e,t,n,r,i){e.writeByte(33),e.writeByte(249),e.writeByte(4),i<0&&(i=0,r=!1);var a,o;r?(a=1,o=2):(a=0,o=0),t>=0&&(o=t&7),o<<=2,e.writeByte(o|0|a),L(e,n),e.writeByte(i||0),e.writeByte(0)}function M(e,t,n,r,i=8){let a=z(r.length)-1,o=i-1<<4|128|a;L(e,t),L(e,n),e.writeBytes([o,0,0])}function N(e,t){e.writeByte(33),e.writeByte(255),e.writeByte(11),R(e,`NETSCAPE2.0`),e.writeByte(3),e.writeByte(1),L(e,t),e.writeByte(0)}function P(e,t){let n=1<<z(t.length);for(let r=0;r<n;r++){let n=[0,0,0];r<t.length&&(n=t[r]),e.writeByte(n[0]),e.writeByte(n[1]),e.writeByte(n[2])}}function F(e,t,n,r){if(e.writeByte(44),L(e,0),L(e,0),L(e,t),L(e,n),r){let t=z(r.length)-1;e.writeByte(128|t)}else e.writeByte(0)}function I(e,t,n,r,i=8,a,o,s){c(n,r,t,i,e,a,o,s)}function L(e,t){e.writeByte(t&255),e.writeByte(t>>8&255)}function R(e,t){for(var n=0;n<t.length;n++)e.writeByte(t.charCodeAt(n))}function z(e){return Math.max(Math.ceil(Math.log2(e)),1)}var B=A})))(),k=128;function A(e){let{width:t,height:n,loop:r}=e;if(!Number.isInteger(t)||!Number.isInteger(n)||t<1||n<1||t>65535||n>65535)throw RangeError(`A GIF is from 1 × 1 to 65,535 × 65,535 pixels.`);if(r!==null&&(!Number.isInteger(r)||r<0||r>65535))throw RangeError(`A loop count is null, or a whole number from 0 to 65,535.`);let i=(0,O.GIFEncoder)(),a=t*n,o=0,s=!1;return{get frames(){return o},frame(e,c){if(s)throw Error(`The GIF is finished.`);if(e.length!==a*4)throw RangeError(`A frame is ${t} × ${n} RGBA pixels.`);if(!Number.isInteger(c)||c<0||c>65535)throw RangeError(`A delay is a whole number of hundredths of a second, from 0 to 65,535.`);let l=0;for(let t=3;t<e.length;t+=4)e[t]>=k&&(l+=1);let u=new Uint8Array(l*4),d=0;for(let t=0;t<e.length;t+=4)e[t+3]<k||(u[d]=e[t],u[d+1]=e[t+1],u[d+2]=e[t+2],u[d+3]=255,d+=4);let f=l>0?(0,O.quantize)(u,255):[],p=l>0?(0,O.applyPalette)(u,f):/* @__PURE__ */ new Uint8Array,m=new Uint8Array(a),h=0;for(let t=0;t<a;t+=1)e[t*4+3]<k||(m[t]=p[h]+1,h+=1);i.writeFrame(m,t,n,{palette:[[0,0,0],...f],delay:c*10,transparent:l<a,transparentIndex:0,dispose:2,repeat:r===null?-1:r}),o+=1},finish(){if(s)throw Error(`The GIF is finished.`);if(o===0)throw RangeError(`A GIF has at least one frame.`);return s=!0,i.finish(),i.bytes()}}}function j(e){let t=/* @__PURE__ */ new Map,n=e=>{let n=t.get(e);if(!n)throw TypeError(`There's no job with the id "${e}".`);return n};D({gifStart({id:e,width:n,height:r,loop:i}){if(t.has(e))throw TypeError(`The job id "${e}" is already in use.`);t.set(e,A({width:n,height:r,loop:i}))},gifFrame({id:e,pixels:t,delay:r},{signal:i}){if(i.aborted)throw i.reason;n(e).frame(new Uint8ClampedArray(t),r)},gifFinish({id:e}){let r=n(e).finish();return t.delete(e),new Blob([r],{type:`image/gif`})},gifAbandon({id:e}){t.delete(e)}},{...e,packageVersion:`0.7.1`})}j();
|
|
1
|
+
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),t=!1;function n(){t||=!0}var r=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),i=class extends Error{name=`SdkError`;code;constructor(e,t,i={}){super(t,`cause`in i?{cause:i.cause}:void 0),n(),this.code=e,Object.defineProperty(this,r,{value:!0}),i.details!==void 0&&(this.details=i.details)}};function a(e,t){if(typeof e!=`object`||!e)return!1;let n=e;return(e instanceof i||n[r]===!0)&&typeof n.code==`string`&&typeof n.message==`string`&&(t===void 0||n.code===t)}var o=8,s=16,c=`UNKNOWN`;function l(e,t={}){let n=t.includeStack??!1,r=h(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=u(e),s=n&&p(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),p(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function u(e){if(a(e)){let t={name:e.name,code:e.code,message:e.message},n=d(e.details);return n!==void 0&&(t.details=n),t}if(p(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:c,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:c,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:c,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function d(e){if(!m(e))return;let t=f(e,0);return m(t)?t:void 0}function f(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=s)){if(Array.isArray(e))return e.flatMap(e=>{let n=f(e,t+1);return n===void 0?[]:[n]});if(m(e)){let n={};for(let[r,i]of Object.entries(e)){let e=f(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function p(e){return typeof e==`object`&&!!e}function m(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function h(e){if(e===void 0)return o;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var g=`hm-rpc`;function _(e){return{protocol:g,version:1,...e}}function v(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function y(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=x(e)?e:S(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return w(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):T(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),E(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function b(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function x(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function S(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var C=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function w(e){let t=globalThis;return C.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function T(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function E(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function D(e,t={}){let n=t.scope??globalThis,r=t.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{n.postMessage(e,t)},s=(e,t)=>{o(_({type:`error`,id:e,error:l(t,{includeStack:r})}))},c=(e,t,r)=>{let a=y(r,!0);try{b((e,t)=>n.postMessage(e,t),_({type:`result`,id:e,output:a.value}),a.transferables)}catch(n){s(e,new i(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${t}" can't be sent to the page.`,{cause:n,details:{method:t}}))}},u=t=>{let{id:n,method:r}=t,l=Object.hasOwn(e,r)?e[r]:void 0;if(typeof l!=`function`){s(n,new i(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${r}".`,{details:{method:r}}));return}let u=new AbortController;a.set(n,u);let d={signal:u.signal,progress:e=>{a.get(n)===u&&o(_({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{a.delete(n),c(n,r,e)},e=>{a.delete(n),s(n,e)})},d=e=>{o(_({type:`crash`,error:l(e,{includeStack:r})}))};n.addEventListener(`message`,e=>{let t=v(e.data);t!==void 0&&t.version===1&&(t.type===`call`?u(t):t.type===`cancel`&&a.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;d(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{d(e.reason)}),o(_({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var O=(/* @__PURE__ */ e((e=>{var t=Object.defineProperty;(e=>t(e,`__esModule`,{value:!0}))(e),((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(e,{GIFEncoder:()=>A,applyPalette:()=>S,default:()=>B,nearestColor:()=>k,nearestColorIndex:()=>D,nearestColorIndexWithDistance:()=>O,prequantize:()=>x,quantize:()=>_,snapColorsToPalette:()=>T});var n={signature:`GIF`,version:`89a`,trailer:59,extensionIntroducer:33,applicationExtensionLabel:255,graphicControlExtensionLabel:249,imageSeparator:44,signatureSize:3,versionSize:3,globalColorTableFlagMask:128,colorResolutionMask:112,sortFlagMask:8,globalColorTableSizeMask:7,applicationIdentifierSize:8,applicationAuthCodeSize:3,disposalMethodMask:28,userInputFlagMask:2,transparentColorFlagMask:1,localColorTableFlagMask:128,interlaceFlagMask:64,idSortFlagMask:32,localColorTableSizeMask:7};function r(e=256){let t=0,n=new Uint8Array(e);return{get buffer(){return n.buffer},reset(){t=0},bytesView(){return n.subarray(0,t)},bytes(){return n.slice(0,t)},writeByte(e){r(t+1),n[t]=e,t++},writeBytes(e,i=0,a=e.length){r(t+a);for(let r=0;r<a;r++)n[t++]=e[r+i]},writeBytesView(e,i=0,a=e.byteLength){r(t+a),n.set(e.subarray(i,i+a),t),t+=a}};function r(e){var r=n.length;if(r>=e)return;e=Math.max(e,r*(r<1048576?2:1.125)>>>0),r!=0&&(e=Math.max(e,256));let i=n;n=new Uint8Array(e),t>0&&n.set(i.subarray(0,t),0)}}var i=12,a=5003,o=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function s(e,t,n,s,c=r(512),l=/* @__PURE__ */ new Uint8Array(256),u=new Int32Array(a),d=new Int32Array(a)){let f=u.length,p=Math.max(2,s);l.fill(0),d.fill(0),u.fill(-1);let m=0,h=0,g=p+1,_=g,v=!1,y=_,b=(1<<y)-1,x=1<<g-1,S=x+1,C=x+2,w=0,T=n[0],E=0;for(let e=f;e<65536;e*=2)++E;E=8-E,c.writeByte(p),O(x);let D=n.length;for(let e=1;e<D;e++)next_block:{let t=n[e],r=(t<<i)+T,a=t<<E^T;if(u[a]===r){T=d[a];break next_block}let o=a===0?1:f-a;for(;u[a]>=0;)if(a-=o,a<0&&(a+=f),u[a]===r){T=d[a];break next_block}O(T),T=t,C<1<<i?(d[a]=C++,u[a]=r):(u.fill(-1),C=x+2,v=!0,O(x))}return O(T),O(S),c.writeByte(0),c.bytesView();function O(e){for(m&=o[h],h>0?m|=e<<h:m=e,h+=y;h>=8;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;if((C>b||v)&&(v?(y=_,b=(1<<y)-1,v=!1):(++y,b=y===i?1<<y:(1<<y)-1)),e==S){for(;h>0;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;w>0&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0)}}}var c=s;function l(e,t,n){return e<<8&63488|t<<2&992|n>>3}function u(e,t,n,r){return e>>4|t&240|(n&240)<<4|(r&240)<<8}function d(e,t,n){return e>>4<<8|t&240|n>>4}function f(e,t,n){return e<t?t:e>n?n:e}function p(e){return e*e}function m(e,t,n){var r=0,i=1e100;let a=e[t],o=a.cnt,s=a.ac,c=a.rc,l=a.gc,u=a.bc;for(var d=a.fw;d!=0;d=e[d].fw){let t=e[d],a=t.cnt,m=o*a/(o+a);if(!(m>=i)){var f=0;n&&(f+=m*p(t.ac-s),f>=i)||(f+=m*p(t.rc-c),f>=i||(f+=m*p(t.gc-l),f>=i||(f+=m*p(t.bc-u),f>=i||(i=f,r=d))))}}a.err=i,a.nn=r}function h(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function g(e,t){let n=Array(t===`rgb444`?4096:65536),r=e.length;if(t===`rgba4444`)for(let t=0;t<r;++t){let r=e[t],i=r>>24&255,a=r>>16&255,o=r>>8&255,s=r&255,c=u(s,o,a,i),l=c in n?n[c]:n[c]=h();l.rc+=s,l.gc+=o,l.bc+=a,l.ac+=i,l.cnt++}else if(t===`rgb444`)for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=d(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}else for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=l(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}return n}function _(e,t,n={}){let{format:r=`rgb565`,clearAlpha:i=!0,clearAlphaColor:a=0,clearAlphaThreshold:o=0,oneBitAlpha:s=!1}=n;if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);let c=new Uint32Array(e.buffer),l=n.useSqrt!==!1,u=r===`rgba4444`,d=g(c,r),h=d.length,_=h-1,y=new Uint32Array(h+1);for(var b=0,x=0;x<h;++x){let e=d[x];if(e!=null){var S=1/e.cnt;u&&(e.ac*=S),e.rc*=S,e.gc*=S,e.bc*=S,d[b++]=e}}p(t)/b<.022&&(l=!1);for(var x=0;x<b-1;++x)d[x].fw=x+1,d[x+1].bk=x,l&&(d[x].cnt=Math.sqrt(d[x].cnt));l&&(d[x].cnt=Math.sqrt(d[x].cnt));var C,w,T;for(x=0;x<b;++x){m(d,x,!1);var E=d[x].err;for(w=++y[0];w>1&&(T=w>>1,!(d[C=y[T]].err<=E));w=T)y[w]=C;y[w]=x}var D=b-t;for(x=0;x<D;){for(var O;;){var k=y[1];if(O=d[k],O.tm>=O.mtm&&d[O.nn].mtm<=O.tm)break;O.mtm==_?k=y[1]=y[y[0]--]:(m(d,k,!1),O.tm=x);var E=d[k].err;for(w=1;(T=w+w)<=y[0]&&(T<y[0]&&d[y[T]].err>d[y[T+1]].err&&T++,!(E<=d[C=y[T]].err));w=T)y[w]=C;y[w]=k}var A=d[O.nn],j=O.cnt,M=A.cnt,S=1/(j+M);u&&(O.ac=S*(j*O.ac+M*A.ac)),O.rc=S*(j*O.rc+M*A.rc),O.gc=S*(j*O.gc+M*A.gc),O.bc=S*(j*O.bc+M*A.bc),O.cnt+=A.cnt,O.mtm=++x,d[A.bk].fw=A.fw,d[A.fw].bk=A.bk,A.mtm=_}let N=[];var P=0;for(x=0;;++P){let e=f(Math.round(d[x].rc),0,255),t=f(Math.round(d[x].gc),0,255),n=f(Math.round(d[x].bc),0,255),r=255;u&&(r=f(Math.round(d[x].ac),0,255),s&&(r=r<=(typeof s==`number`?s:127)?0:255),i&&r<=o&&(e=t=n=a,r=0));let c=u?[e,t,n,r]:[e,t,n];if(v(N,c)||N.push(c),(x=d[x].fw)==0)break}return N}function v(e,t){for(let n=0;n<e.length;n++){let r=e[n],i=r[0]===t[0]&&r[1]===t[1]&&r[2]===t[2],a=r.length>=4&&t.length>=4?r[3]===t[3]:!0;if(i&&a)return!0}return!1}function y(e,t){for(var n=0,r=0;r<e.length;r++){let i=e[r]-t[r];n+=i*i}return n}function b(e,t){return t>1?Math.round(e/t)*t:e}function x(e,{roundRGB:t=5,roundAlpha:n=10,oneBitAlpha:r=null}={}){let i=new Uint32Array(e.buffer);for(let e=0;e<i.length;e++){let a=i[e],o=a>>24&255,s=a>>16&255,c=a>>8&255,l=a&255;o=b(o,n),r&&(o=o<=(typeof r==`number`?r:127)?0:255),l=b(l,t),c=b(c,t),s=b(s,t),i[e]=o<<24|s<<16|c<<8|l}}function S(e,t,n=`rgb565`){if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);if(t.length>256)throw Error(`applyPalette() only works with 256 colors or less`);let r=new Uint32Array(e.buffer),i=r.length,a=n===`rgb444`?4096:65536,o=new Uint8Array(i),s=Array(a);if(n===`rgba4444`)for(let e=0;e<i;e++){let n=r[e],i=n>>24&255,a=n>>16&255,c=n>>8&255,l=n&255,d=u(l,c,a,i),f=d in s?s[d]:s[d]=C(l,c,a,i,t);o[e]=f}else{let e=n===`rgb444`?d:l;for(let n=0;n<i;n++){let i=r[n],a=i>>16&255,c=i>>8&255,l=i&255,u=e(l,c,a),d=u in s?s[u]:s[u]=w(l,c,a,t);o[n]=d}}return o}function C(e,t,n,r,i){let a=0,o=1e100;for(let s=0;s<i.length;s++){let c=i[s],l=c[3],u=E(l-r);if(u>o)continue;let d=c[0];if(u+=E(d-e),u>o)continue;let f=c[1];if(u+=E(f-t),u>o)continue;let p=c[2];u+=E(p-n),u>o||(o=u,a=s)}return a}function w(e,t,n,r){let i=0,a=1e100;for(let o=0;o<r.length;o++){let s=r[o],c=s[0],l=E(c-e);if(l>a)continue;let u=s[1];if(l+=E(u-t),l>a)continue;let d=s[2];l+=E(d-n),l>a||(a=l,i=o)}return i}function T(e,t,n=5){if(!e.length||!t.length)return;let r=e.map(e=>e.slice(0,3)),i=n*n,a=e[0].length;for(let n=0;n<t.length;n++){let o=t[n];o=o.length<a?[o[0],o[1],o[2],255]:o.length>a?o.slice(0,3):o.slice();let s=O(r,o.slice(0,3),y),c=s[0],l=s[1];l>0&&l<=i&&(e[c]=o)}}function E(e){return e*e}function D(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return i}function O(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return[i,r]}function k(e,t,n=y){return e[D(e,t,n)]}function A(e={}){let{initialCapacity:t=4096,auto:i=!0}=e,a=r(t),o=5003,s=/* @__PURE__ */ new Uint8Array(256),c=new Int32Array(o),l=new Int32Array(o),u=!1;return{reset(){a.reset(),u=!1},finish(){a.writeByte(n.trailer)},bytes(){return a.bytes()},bytesView(){return a.bytesView()},get buffer(){return a.buffer},get stream(){return a},writeHeader:d,writeFrame(e,t,n,r={}){let{transparent:o=!1,transparentIndex:f=0,delay:p=0,palette:m=null,repeat:h=0,colorDepth:g=8,dispose:_=-1}=r,v=!1;if(i?u||=(v=!0,d(),!0):v=!!r.first,t=Math.max(0,Math.floor(t)),n=Math.max(0,Math.floor(n)),v){if(!m)throw Error(`First frame must include a { palette } option`);M(a,t,n,m,g),P(a,m),h>=0&&N(a,h)}let y=Math.round(p/10);j(a,_,y,o,f);let b=!!m&&!v;F(a,t,n,b?m:null),b&&P(a,m),I(a,e,t,n,g,s,c,l)}};function d(){R(a,`GIF89a`)}}function j(e,t,n,r,i){e.writeByte(33),e.writeByte(249),e.writeByte(4),i<0&&(i=0,r=!1);var a,o;r?(a=1,o=2):(a=0,o=0),t>=0&&(o=t&7),o<<=2,e.writeByte(o|0|a),L(e,n),e.writeByte(i||0),e.writeByte(0)}function M(e,t,n,r,i=8){let a=z(r.length)-1,o=i-1<<4|128|a;L(e,t),L(e,n),e.writeBytes([o,0,0])}function N(e,t){e.writeByte(33),e.writeByte(255),e.writeByte(11),R(e,`NETSCAPE2.0`),e.writeByte(3),e.writeByte(1),L(e,t),e.writeByte(0)}function P(e,t){let n=1<<z(t.length);for(let r=0;r<n;r++){let n=[0,0,0];r<t.length&&(n=t[r]),e.writeByte(n[0]),e.writeByte(n[1]),e.writeByte(n[2])}}function F(e,t,n,r){if(e.writeByte(44),L(e,0),L(e,0),L(e,t),L(e,n),r){let t=z(r.length)-1;e.writeByte(128|t)}else e.writeByte(0)}function I(e,t,n,r,i=8,a,o,s){c(n,r,t,i,e,a,o,s)}function L(e,t){e.writeByte(t&255),e.writeByte(t>>8&255)}function R(e,t){for(var n=0;n<t.length;n++)e.writeByte(t.charCodeAt(n))}function z(e){return Math.max(Math.ceil(Math.log2(e)),1)}var B=A})))(),k=128;function A(e){let{width:t,height:n,loop:r}=e;if(!Number.isInteger(t)||!Number.isInteger(n)||t<1||n<1||t>65535||n>65535)throw RangeError(`A GIF is from 1 × 1 to 65,535 × 65,535 pixels.`);if(r!==null&&(!Number.isInteger(r)||r<0||r>65535))throw RangeError(`A loop count is null, or a whole number from 0 to 65,535.`);let i=(0,O.GIFEncoder)(),a=t*n,o=0,s=!1;return{get frames(){return o},frame(e,c){if(s)throw Error(`The GIF is finished.`);if(e.length!==a*4)throw RangeError(`A frame is ${t} × ${n} RGBA pixels.`);if(!Number.isInteger(c)||c<0||c>65535)throw RangeError(`A delay is a whole number of hundredths of a second, from 0 to 65,535.`);let l=0;for(let t=3;t<e.length;t+=4)e[t]>=k&&(l+=1);let u=new Uint8Array(l*4),d=0;for(let t=0;t<e.length;t+=4)e[t+3]<k||(u[d]=e[t],u[d+1]=e[t+1],u[d+2]=e[t+2],u[d+3]=255,d+=4);let f=l>0?(0,O.quantize)(u,255):[],p=l>0?(0,O.applyPalette)(u,f):/* @__PURE__ */ new Uint8Array,m=new Uint8Array(a),h=0;for(let t=0;t<a;t+=1)e[t*4+3]<k||(m[t]=p[h]+1,h+=1);i.writeFrame(m,t,n,{palette:[[0,0,0],...f],delay:c*10,transparent:l<a,transparentIndex:0,dispose:2,repeat:r===null?-1:r}),o+=1},finish(){if(s)throw Error(`The GIF is finished.`);if(o===0)throw RangeError(`A GIF has at least one frame.`);return s=!0,i.finish(),i.bytes()}}}function j(e){let t=/* @__PURE__ */ new Map,n=e=>{let n=t.get(e);if(!n)throw TypeError(`There's no job with the id "${e}".`);return n};D({gifStart({id:e,width:n,height:r,loop:i}){if(t.has(e))throw TypeError(`The job id "${e}" is already in use.`);t.set(e,A({width:n,height:r,loop:i}))},gifFrame({id:e,pixels:t,delay:r},{signal:i}){if(i.aborted)throw i.reason;n(e).frame(new Uint8ClampedArray(t),r)},gifFinish({id:e}){let r=n(e).finish();return t.delete(e),new Blob([r],{type:`image/gif`})},gifAbandon({id:e}){t.delete(e)}},{...e,packageVersion:`0.7.3`})}j();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var e=!1;function t(){e||=!0}var n=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),r=class extends Error{name=`SdkError`;code;constructor(e,r,i={}){super(r,`cause`in i?{cause:i.cause}:void 0),t(),this.code=e,Object.defineProperty(this,n,{value:!0}),i.details!==void 0&&(this.details=i.details)}};function i(e,t){if(typeof e!=`object`||!e)return!1;let i=e;return(e instanceof r||i[n]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(t===void 0||i.code===t)}var a=1<<20;function o(e,t,n){if(!Number.isSafeInteger(t)||t<n)throw RangeError(`The ${e} must be an integer of at least ${n}, not ${String(t)}.`)}function s(e,t={}){let n=t.windowSize??a;o(`window size`,n,1);let r=e.size,i=0,s=/* @__PURE__ */ new Uint8Array;return{size:r,async bytes(t,a){o(`offset`,t,0),o(`length`,a,0);let c=Math.min(t,r),l=Math.min(r,c+a);if(c<i||l>i+s.length){let t=Math.min(r,c+Math.max(a,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),i=c}return s.subarray(c-i,l-i)}}}var c=8,l=16,u=`UNKNOWN`;function d(e,t={}){let n=t.includeStack??!1,r=_(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=f(e),s=n&&h(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),h(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function f(e){if(i(e)){let t={name:e.name,code:e.code,message:e.message},n=p(e.details);return n!==void 0&&(t.details=n),t}if(h(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:u,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:u,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:u,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function p(e){if(!g(e))return;let t=m(e,0);return g(t)?t:void 0}function m(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=l)){if(Array.isArray(e))return e.flatMap(e=>{let n=m(e,t+1);return n===void 0?[]:[n]});if(g(e)){let n={};for(let[r,i]of Object.entries(e)){let e=m(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function h(e){return typeof e==`object`&&!!e}function g(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function _(e){if(e===void 0)return c;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}var v={maxFileSize:{code:`FILE_TOO_LARGE`,unit:`bytes`,default:1e8,warning:5e7},maxFiles:{code:`TOO_MANY_FILES`,unit:`count`,default:20},maxDecodedSize:{code:`DECODED_SIZE_TOO_LARGE`,unit:`bytes`,default:5e8},maxProcessingTime:{code:`PROCESSING_TIME_EXCEEDED`,unit:`milliseconds`,default:12e4}};function y(e,t={}){let n=t.errorClass??r;for(let[t,n]of Object.entries(e))x(`${t}.default`,n.default),n.warning!==void 0&&x(`${t}.warning`,n.warning);return{definitions:e,resolve(t={}){let r={};for(let[t,n]of Object.entries(e))r[t]={maximum:n.default,warning:n.warning??1/0};for(let[e,n]of Object.entries(t)){let t=Object.hasOwn(r,e)?r[e]:void 0;if(t===void 0)throw TypeError(`"${e}" isn't a file policy limit. Known limits: ${Object.keys(r).join(`, `)}.`);r[e]=b(e,t,n)}let i=(t,n)=>{let i=Object.hasOwn(r,t)?r[t]:void 0,a=Object.hasOwn(e,t)?e[t]:void 0;if(i===void 0||a===void 0)throw TypeError(`"${t}" isn't a file policy limit.`);if(typeof n!=`number`||Number.isNaN(n)||n<0)throw RangeError(`The value checked against ${t} must be a non-negative number, received ${String(n)}.`);return{resolved:i,definition:a,actual:n}},a=(e,t)=>{let r=i(e,t),{maximum:a}=r.resolved,{code:o,unit:s}=r.definition;return new n(o,`${e} is ${a} ${s}, but the value is ${r.actual}.`,{details:{limit:e,maximum:a,actual:r.actual,unit:s}})};return{limits:r,check(e,t){let{resolved:n}=i(e,t);if(t>n.maximum)throw a(e,t);return t>=n.warning?`warning`:void 0},error:(e,t)=>a(e,t)}}}}function b(e,t,n){if(typeof n==`number`)return x(e,n),{...t,maximum:n};if(typeof n!=`object`||!n)throw TypeError(`The setting for ${e} must be a number or { maximum, warning }.`);let{maximum:r=t.maximum,warning:i=t.warning,...a}=n,o=Object.keys(a);if(o.length>0)throw TypeError(`The setting for ${e} has unknown keys: ${o.join(`, `)}.`);return x(`${e}.maximum`,r),x(`${e}.warning`,i),{maximum:r,warning:i}}function x(e,t){if(typeof t!=`number`||Number.isNaN(t)||t<=0)throw RangeError(`${e} must be a positive number or Infinity, received ${String(t)}.`)}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var S=`hm-rpc`;function C(e){return{protocol:S,version:1,...e}}function ee(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function te(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=re(e)?e:ie(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return oe(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):se(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),ce(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function ne(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function re(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function ie(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var ae=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function oe(e){let t=globalThis;return ae.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function se(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ce(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function le(e,t={}){let n=t.scope??globalThis,i=t.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{n.postMessage(e,t)},s=(e,t)=>{o(C({type:`error`,id:e,error:d(t,{includeStack:i})}))},c=(e,t,i)=>{let a=te(i,!0);try{ne((e,t)=>n.postMessage(e,t),C({type:`result`,id:e,output:a.value}),a.transferables)}catch(n){s(e,new r(`WORKER_DATA_NOT_CLONEABLE`,`The result of "${t}" can't be sent to the page.`,{cause:n,details:{method:t}}))}},l=t=>{let{id:n,method:i}=t,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(n,new r(`WORKER_METHOD_NOT_FOUND`,`The worker has no method "${i}".`,{details:{method:i}}));return}let u=new AbortController;a.set(n,u);let d={signal:u.signal,progress:e=>{a.get(n)===u&&o(C({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{a.delete(n),c(n,i,e)},e=>{a.delete(n),s(n,e)})},u=e=>{o(C({type:`crash`,error:d(e,{includeStack:i})}))};n.addEventListener(`message`,e=>{let t=ee(e.data);t!==void 0&&t.version===1&&(t.type===`call`?l(t):t.type===`cancel`&&a.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;u(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{u(e.reason)}),o(C({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var w=class extends r{name=`ImageError`};function T(e,t){return i(e,t)&&e.name===`ImageError`}var E=/* @__PURE__ */ y({...v,maxDecodedSize:{...v.maxDecodedSize,default:1e9,warning:4e8},maxImagePixels:{code:`IMAGE_TOO_LARGE`,unit:`pixels`,default:5e7,warning:24e6},maxImageDimension:{code:`IMAGE_DIMENSION_TOO_LARGE`,unit:`pixels`,default:16384},maxFrames:{code:`TOO_MANY_FRAMES`,unit:`count`,default:300,warning:100},maxAnimationPixels:{code:`ANIMATION_TOO_LARGE`,unit:`pixels`,default:8e6,warning:2e6},maxSessionSize:{code:`SESSION_TOO_LARGE`,unit:`bytes`,default:1e9,warning:5e8},maxLayers:{code:`TOO_MANY_LAYERS`,unit:`count`,default:256},maxDrawingPoints:{code:`TOO_MANY_POINTS`,unit:`count`,default:2e5,warning:1e5}},{errorClass:w}),D=[`maxFileSize`,`maxImageDimension`,`maxImagePixels`,`maxFrames`,`maxDecodedSize`];function O(e,t,n,r=`all`){let{width:i,height:a}=n.oriented,o={maxFileSize:t,maxImageDimension:Math.max(i,a),maxImagePixels:i*a,maxFrames:r===`all`?n.frames:1,maxDecodedSize:(r===`all`?n.decodedPixelBound:i*a)*4};return D.filter(t=>e.check(t,o[t])===`warning`)}function k(e,t){e.check(`maxImageDimension`,Math.max(t.width,t.height)),e.check(`maxImagePixels`,t.width*t.height)}function ue(e){let t=Math.min(e.pixelRatio,4);return{width:Math.max(1,Math.round(e.width*t)),height:Math.max(1,Math.round(e.height*t))}}function de(e,t){let n=t.inset??0,r=Math.min((t.width-2*n)/e.width,(t.height-2*n)/e.height),i=Math.max(0,r)*t.zoom,a=e.width*i,o=e.height*i;return{x:(t.width-a)/2+t.pan.x,y:(t.height-o)/2+t.pan.y,width:a,height:o,scale:i}}function fe(e,t){let n={layers:!(Array.isArray(e.layers)&&e.layers.length===0),drawings:Array.isArray(e.layers)&&e.layers.some(e=>e?.kind===`drawing`||e?.kind===`arrow`),redactions:!(Array.isArray(e.redactions)&&e.redactions.length===0),animation:e.animation!==null};for(let e of[`layers`,`drawings`,`redactions`,`animation`])if(n[e]&&!t.includes(e))throw new w(`UNSUPPORTED_PLAN`,`This renderer can't draw the plan's ${e}.`,{details:{reason:e}})}function A(e,t){return new w(`INVALID_IMAGE`,`Invalid ${e}: ${t}.`,{details:{format:e,problem:t}})}async function j(e,t,n,r,i){if(n+r>e.size)throw A(t,`${i} ends past the end of the file`);return e.bytes(n,r)}function pe(e,t){return(e[t]??0)<<8|(e[t+1]??0)}function M(e,t){return((e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0}function N(e,t,n){let r=``;for(let i=t;i<t+n&&i<e.length;i+=1)r+=String.fromCharCode(e[i]??0);return r}function me(e,t){return t.every((t,n)=>e[n]===t)}function P(e,t){return(e[t]??0)|(e[t+1]??0)<<8}function F(e,t){return(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16}function I(e,t){return((e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24)>>>0}function he(e,t){return I(e,t)|0}var L=4096;function ge(e,t,n,r){let i=1<<n,a=i+1,o=new Uint16Array(L),s=new Uint8Array(L),c=new Uint8Array(L);for(let e=0;e<i;e+=1)s[e]=e,c[e]=e;let l=new Uint8Array(L),u=n+1,d=a+1,f=-1,p=0,m=0,h=0,g=t,_=0,v=!1;for(;;){for(;h<u;){if(_===0){if(g>=e.length)throw A(`gif`,`a frame's data ends past the end of the file`);if(_=e[g],g+=1,_===0){v=!0;break}if(g+_>e.length)throw A(`gif`,`a frame's data ends past the end of the file`)}m|=e[g]<<h,h+=8,g+=1,--_}if(v)break;let t=m&(1<<u)-1;if(m>>>=u,h-=u,t===i){u=n+1,d=a+1,f=-1;continue}if(t===a)break;let y=0,b=t;if(f===-1){if(t>=i)throw A(`gif`,`a frame's data starts with a code that isn't a colour`)}else if(t>d)throw A(`gif`,`a frame's data uses a code that isn't defined yet`);else t===d&&(l[y]=c[f],y+=1,b=f);for(;b>=i;){if(y>=4095)throw A(`gif`,`a frame's data has a code with no end`);l[y]=s[b],y+=1,b=o[b]}l[y]=b,y+=1;for(let e=y-1;e>=0&&p<r.length;--e)r[p]=l[e],p+=1;if(p===r.length)return;f!==-1&&d<L&&(o[d]=f,s[d]=b,c[d]=c[f],d+=1),d>=1<<u&&u<12&&(u+=1),f=t}throw A(`gif`,`a frame's data holds fewer pixels than the frame`)}var R={offset:0,size:0},_e=[[0,8],[4,8],[2,4],[1,2]];function ve(e,t){let{width:n,height:r}=t,i=new Uint8Array(n*r);if(ge(e,t.data,t.codeSize,i),!t.interlaced)return i;let a=new Uint8Array(n*r),o=0;for(let[e,t]of _e)for(let s=e;s<r;s+=t)a.set(i.subarray(o,o+n),s*n),o+=n;return a}function ye(e,t){let n=new Uint8ClampedArray(t.width*t.height*4),r=-1,i,a=e=>{if(e.disposal===2)for(let r=0;r<e.height;r+=1){let i=((e.y+r)*t.width+e.x)*4;n.fill(0,i,i+e.width*4)}else if(e.disposal===3&&i)for(let r=0;r<e.height;r+=1)n.set(i.subarray(r*e.width*4,(r+1)*e.width*4),((e.y+r)*t.width+e.x)*4);i=void 0};return{get shown(){return r},get screen(){return n},reset(){n.fill(0),r=-1,i=void 0},snapshot(){return{shown:r,screen:n.slice(),saved:i?.slice()}},restore(e){n.set(e.screen),r=e.shown,i=e.saved?.slice()},next(){let o=t.frames[r+1];if(!o)throw RangeError(`The GIF has no more frames.`);let s=ve(e,o),c=o.table??t.table??R,l=t.frames[r];if(l&&a(l),o.disposal===3){i=new Uint8ClampedArray(o.width*o.height*4);for(let e=0;e<o.height;e+=1){let r=((o.y+e)*t.width+o.x)*4;i.set(n.subarray(r,r+o.width*4),e*o.width*4)}}for(let r=0;r<o.height;r+=1){let i=((o.y+r)*t.width+o.x)*4;for(let t=0;t<o.width;t+=1,i+=4){let a=s[r*o.width+t];if(a===o.transparent||a>=c.size)continue;let l=c.offset+a*3;n[i]=e[l],n[i+1]=e[l+1],n[i+2]=e[l+2],n[i+3]=255}}return r+=1,n}}}var be=4096,xe=17408;function Se(e,t){let n=t;for(;;){if(n>=e.length)throw A(`gif`,`a data sub-block ends past the end of the file`);let t=e[n];if(n+=1,t===0)return n;if(n+t>e.length)throw A(`gif`,`a data sub-block ends past the end of the file`);n+=t}}function z(e,t,n,r){if(t+n>e.length)throw A(`gif`,`${r} ends past the end of the file`)}function Ce(e,t,n){let r=2**(n+1);return z(e,t,3*r,`a colour table`),{offset:t,size:r}}function we(e,t=`all`){z(e,0,13,`the logical screen descriptor`);let n=N(e,0,6);if(n!==`GIF87a`&&n!==`GIF89a`)throw A(`gif`,`not a GIF`);let r=P(e,6),i=P(e,8);if(r<1||i<1)throw A(`gif`,`the logical screen has no pixels`);let a=e[10],o=13,s=null;a&128&&(s=Ce(e,o,a&7),o+=3*s.size);let c=[],l=!1,u=null,d=0,f=0,p=null;for(let n=0;;n+=1){if(n>=xe)throw A(`gif`,`the file has too many blocks`);try{z(e,o,1,`a block`);let n=e[o];if(n===59){l=!0;break}if(n===33){z(e,o,2,`an extension label`);let t=e[o+1];if(t===249){if(z(e,o+2,6,`a graphic control extension`),e[o+2]!==4)throw A(`gif`,`a graphic control extension is the wrong size`);let t=e[o+3],n=t>>>2&7;f=n===4?3:n>4?0:n,d=P(e,o+4),p=t&1?e[o+6]:null}else if(t===255){z(e,o+2,12,`an application extension`);let t=N(e,o+3,11);e[o+2]===11&&(t===`NETSCAPE2.0`||t===`ANIMEXTS1.0`)&&o+18<=e.length&&e[o+14]===3&&e[o+15]===1&&(u=P(e,o+16))}o=Se(e,o+2);continue}if(n!==44)throw A(`gif`,`an unknown block`);z(e,o,10,`an image descriptor`);let a=P(e,o+1),s=P(e,o+3),m=P(e,o+5),h=P(e,o+7);if(c.length===0&&a===0&&s===0&&m>=r&&h>=i&&(r=m,i=h),m<1||h<1||a+m>r||s+h>i)throw A(`gif`,`a frame doesn't fit inside the logical screen`);let g=e[o+9];o+=10;let _=null;g&128&&(_=Ce(e,o,g&7),o+=3*_.size),z(e,o,1,`an LZW minimum code size`);let v=e[o];if(v<1||v>8)throw A(`gif`,`a frame's LZW minimum code size is out of range`);let y=o+1;if(o=Se(e,y),c.length>=4096)throw new w(`TOO_MANY_FRAMES`,`A GIF holds at most ${be} frames.`,{details:{limit:`maxFrames`,maximum:be,actual:c.length+1,unit:`count`}});if(c.push({x:a,y:s,width:m,height:h,delay:d,disposal:f,transparent:p,interlaced:!!(g&64),table:_,codeSize:v,data:y}),d=0,f=0,p=null,t===`first`)break}catch(e){if(c.length>0&&T(e)&&e.code===`INVALID_IMAGE`)break;throw e}}if(c.length===0)throw A(`gif`,`there are no frames`);return{width:r,height:i,loop:u,table:s,frames:c,complete:l}}var Te=Object.freeze({location:!1,camera:!1,timestamps:!1,thumbnail:!1,colourProfile:!1,other:!1}),Ee=Object.freeze({title:``,description:``,artist:``,copyright:``}),De=2e3;function Oe(e,t){if(e.length<=t)return!1;let n=0;for(let r of e)if(n+=1,n>t)return!0;return!1}var ke=/* @__PURE__ */ new Set([12,40,52,56,108,124]);function Ae(e){return N(e,0,2)===`BM`}async function je(e){let t=await j(e,`bmp`,0,18,`the file header`),n=I(t,10),r=I(t,14);if(!ke.has(r))throw A(`bmp`,`the DIB header size is unknown`);let i=await j(e,`bmp`,14,r,`the DIB header`),a,o,s;if(r===12?(a=P(i,4),o=P(i,6),s=P(i,10)):(a=he(i,4),o=Math.abs(he(i,8)),s=P(i,14)),P(i,r===12?8:12)!==1)throw A(`bmp`,`the plane count isn't 1`);if(a<1||o<1||a>2147483647||o>2147483647)throw A(`bmp`,`the dimensions are out of range`);if(![1,4,8,16,24,32].includes(s))throw A(`bmp`,`the bit depth is unsupported`);if(n<14+r||n>=e.size)throw A(`bmp`,`the pixel data starts outside the file`);let c=r===124&&[1279872587,1296188740].includes(I(i,56)),l={width:a,height:o};return{format:`bmp`,stored:l,oriented:l,orientation:1,frames:1,hasAlpha:s===32,decodedPixelBound:a*o,metadata:{...Te,colourProfile:c},keepable:Ee}}var Me=1e6;function Ne(e){let t=N(e,0,6);return t===`GIF87a`||t===`GIF89a`}var Pe=65536;async function Fe(e,t){let n=t;for(;;){if(n+1>e.size)throw A(`gif`,`a data sub-block ends past the end of the file`);let t=await e.bytes(n,Pe),r=0;for(;r<t.length;){let i=t[r]??0;if(n+=1,i===0)return n;if(n+i>e.size)throw A(`gif`,`a data sub-block ends past the end of the file`);n+=i,r+=1+i}}}async function Ie(e){let t=await j(e,`gif`,0,13,`the logical screen descriptor`),n=P(t,6),r=P(t,8);if(n<1||r<1)throw A(`gif`,`the logical screen has no pixels`);let i=t[10]??0,a=13+(i&128?3*2**((i&7)+1):0),o=0,s=!1,c=!1;for(let t=0;;t+=1){if(t>=Me)throw A(`gif`,`the file has too many blocks`);try{let t=(await j(e,`gif`,a,1,`a block`))[0];if(t===59)break;if(t===33){let t=(await j(e,`gif`,a+1,1,`an extension label`))[0];if(t===249){let t=await j(e,`gif`,a+2,6,`a graphic control extension`);if(t[0]!==4)throw A(`gif`,`a graphic control extension is the wrong size`);(t[1]??0)&1&&(s=!0)}else if(t===255){let t=N(await j(e,`gif`,a+2,12,`an application extension`),1,11);t!==`NETSCAPE2.0`&&t!==`ANIMEXTS1.0`&&(c=!0)}else t===254&&(c=!0);a=await Fe(e,a+2);continue}if(t===44){let t=await j(e,`gif`,a,10,`an image descriptor`),i=P(t,1),s=P(t,3),c=P(t,5),l=P(t,7);if(o===0&&i===0&&s===0&&c>=n&&l>=r&&(n=c,r=l),c<1||l<1||i+c>n||s+l>r)throw A(`gif`,`a frame doesn't fit inside the logical screen`);let u=t[9]??0;a+=10+(u&128?3*2**((u&7)+1):0);let d=(await j(e,`gif`,a,1,`an LZW minimum code size`))[0]??0;if(d<1||d>8)throw A(`gif`,`a frame's LZW minimum code size is out of range`);a=await Fe(e,a+1),o+=1;continue}throw A(`gif`,`an unknown block`)}catch(e){if(o>0&&T(e)&&e.code===`INVALID_IMAGE`)break;throw e}}if(o===0)throw A(`gif`,`there are no frames`);let l={width:n,height:r};return{format:`gif`,stored:l,oriented:l,orientation:1,frames:o,hasAlpha:s,decodedPixelBound:o*n*r,metadata:{...Te,other:c},keepable:Ee}}function Le(e,t){return t>=5?{width:e.height,height:e.width}:e}function B(e,t){return e??{x:0,y:0,width:t.width,height:t.height}}function Re(e,t){let{width:n,height:r}=B(e.base.crop,t);return e.base.orientation.rotate%180==0?{width:n,height:r}:{width:r,height:n}}function ze(e,t){let n=e.kind===`scale`?e.scale:Math.min(1,e.width/t.width,e.height/t.height);return{width:Math.max(1,Math.round(t.width*n)),height:Math.max(1,Math.round(t.height*n))}}function Be(e,t,n){let r=e.x-t.x,i=e.y-t.y,{width:a,height:o}=t,s;switch(n.rotate){case 90:s={x:o-i,y:r};break;case 180:s={x:a-r,y:o-i};break;case 270:s={x:i,y:a-r};break;default:s={x:r,y:i}}let c=n.rotate%180==0?{width:a,height:o}:{width:o,height:a};return{x:n.flipX?c.width-s.x:s.x,y:n.flipY?c.height-s.y:s.y}}function Ve(){return{orientation:1,location:!1,camera:!1,timestamps:!1,thumbnail:!1,other:!1,title:``,description:``,artist:``,copyright:``}}function He(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}var Ue=8,We=1e3,Ge=/* @__PURE__ */ new Set([271,272,42033,42035,42036,42037,37500]),Ke=/* @__PURE__ */ new Set([306,36867,36868,36880,36881,36882]),qe=/* @__PURE__ */ new Set([34665,34853,40965,513,514]),Je={1:1,2:1,3:2,4:4,5:8,6:1,7:1,8:2,9:4,10:8,11:4,12:8};function Ye(e,t){let n=Ve();if(e.length<8)throw A(t,`the EXIF block is too short`);let r=e[0]===73&&e[1]===73;if(!r&&(e[0]!==77||e[1]!==77))throw A(t,`the EXIF byte order is unknown`);let i=t=>r?(e[t]??0)|(e[t+1]??0)<<8:(e[t]??0)<<8|(e[t+1]??0),a=t=>(r?(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24:(e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0;if(i(2)!==42)throw A(t,`the EXIF block isn't TIFF`);let o=(n,r,i,o)=>{let s=r*(Je[n]??1),c=s<=4?i:a(i);if(c+s>e.length)throw A(t,`an EXIF value ends past the block`);let l=e.subarray(c,c+s),u=(o?new TextDecoder(`utf-16le`).decode(l):He(l)).replace(/\0+$/,``);return Oe(u,2e3)?[...u].slice(0,De).join(``):u},s=/* @__PURE__ */ new Set,c=[{offset:a(4),kind:`main`}];for(;c.length>0;){let{offset:r,kind:l}=c.shift();if(r===0)continue;if(s.has(r))throw A(t,`EXIF directories loop`);if(s.size>=Ue)throw A(t,`the EXIF block has too many directories`);if(s.add(r),r+2>e.length)throw A(t,`an EXIF directory starts past the block`);let u=i(r);if(u>We||r+2+u*12+4>e.length)throw A(t,`an EXIF directory ends past the block`);l===`gps`&&u>0&&(n.location=!0);for(let e=0;e<u;e+=1){let t=r+2+e*12,s=i(t),u=i(t+2),d=a(t+4),f=t+8;if(l!==`gps`){if(s===274&&l===`main`){let e=i(f);n.orientation=e>=1&&e<=8?e:1}else s===34665?c.push({offset:a(f),kind:`exif`}):s===34853?(n.location=!0,c.push({offset:a(f),kind:`gps`})):l===`next`?n.thumbnail=!0:s===270&&u===2?n.description=o(u,d,f,!1):s===315&&u===2?n.artist=o(u,d,f,!1):s===33432&&u===2?n.copyright=o(u,d,f,!1):s===40091&&(u===1||u===7)?n.title=o(1,d,f,!0):Ge.has(s)?n.camera=!0:Ke.has(s)?n.timestamps=!0:qe.has(s)||(n.other=!0)}}l===`main`?c.push({offset:a(r+2+u*12),kind:`next`}):l===`next`&&(n.thumbnail=!0)}return n}var Xe=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`,`heic`,`heix`,`heim`,`heis`,`hevc`,`hevx`,`mif1`,`mif2`,`msf1`]),Ze=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`]),Qe=/* @__PURE__ */ new Set([`av01`,`hvc1`]),$e=/* @__PURE__ */ new Set([`urn:mpeg:mpegB:cicp:systems:auxiliary:alpha`,`urn:mpeg:hevc:2015:auxid:1`]),et=/* @__PURE__ */ new Set([`dimg`,`auxl`,`thmb`]),tt=1024,nt=4<<20,rt=4096,it=1024,at=1<<20;function ot(e){return N(e,4,4)===`ftyp`&&Xe.has(N(e,8,4))}function st(e,t){return M(e,t)*2**32+M(e,t+4)}function V(e,t,n,r){let i=(t,n)=>{if(t.at+n>r)throw A(e,`a box is shorter than its fields`)},a={at:n,end:r,u8(){return i(a,1),a.at+=1,t[a.at-1]??0},u16(){return i(a,2),a.at+=2,pe(t,a.at-2)},u32(){return i(a,4),a.at+=4,M(t,a.at-4)},uint(n){if(n===0)return 0;if(n===4)return a.u32();if(n===8)return i(a,8),a.at+=8,st(t,a.at-8);throw A(e,`a field has an unsupported size`)},fourcc(){return i(a,4),a.at+=4,N(t,a.at-4,4)},string(){let n=t.subarray(a.at,r).indexOf(0);if(n<0)throw A(e,`a string isn't terminated inside its box`);let i=N(t,a.at,n);return a.at+=n+1,i}};return a}function H(e,t,n,r){let i=[],a=n;for(;a<r;){if(i.length>=rt)throw A(e,`a box holds too many boxes`);if(a+8>r)throw A(e,`a box header ends past its parent`);let n=M(t,a),o=8;if(n===1){if(a+16>r)throw A(e,`a box header ends past its parent`);n=st(t,a+8),o=16}else n===0&&(n=r-a);if(n<o||a+n>r)throw A(e,`a box ends past its parent`);i.push({type:N(t,a+4,4),start:a+o,end:a+n}),a+=n}return i}function U(e,t,n){let r=t.filter(e=>e.type===n);if(r.length>1)throw A(e,`a box that may appear once appears twice`);return r[0]}var ct=[[1,[1,0,0,1]],[2,[-1,0,0,1]],[3,[-1,0,0,-1]],[4,[1,0,0,-1]],[5,[0,1,1,0]],[6,[0,-1,1,0]],[7,[0,-1,-1,0]],[8,[0,1,-1,0]]];function lt(e){return ct.find(([t])=>t===e)?.[1]??[1,0,0,1]}function ut(e,t){let[n=0,r=0,i=0,a=0]=lt(t),[o=0,s=0,c=0,l=0]=lt(e),u=[n*o+r*c,n*s+r*l,i*o+a*c,i*s+a*l];return ct.find(([,e])=>e.every((e,t)=>e===u[t]))?.[0]??1}function dt(e,t,n){let r=n=>{let r=t.u32(),i=t.u32();if(i===0)throw A(e,`a clean aperture divides by zero`);return(n?r|0:r)/i},i=r(!1),a=r(!1),o=r(!0),s=r(!0);if(!Number.isInteger(i)||!Number.isInteger(a)||i<1||a<1)throw A(e,`a clean aperture isn't a whole number of pixels`);let c=(n.width-i)/2+o,l=(n.height-a)/2+s;if(c<0||l<0||c+i>n.width||l+a>n.height)throw A(e,`a clean aperture lies outside the image`);return{width:i,height:a}}var ft=[1,8,3,6];async function pt(e){let t=M(await j(e,`heif`,0,8,`the ftyp box`),0);if(t<16||t>4096)throw A(`heif`,`the ftyp box has an invalid size`);let n=await j(e,`heif`,8,t-8,`the ftyp box`),r=[N(n,0,4)];for(let e=8;e+4<=n.length;e+=4)r.push(N(n,e,4));let i=r.some(e=>Ze.has(e))?`avif`:`heif`,a,o=t;for(let t=0;o<e.size;t+=1){if(t>=tt)throw A(i,`the file has too many boxes`);let n=await j(e,i,o,8,`a box header`),r=M(n,0),s=8;if(r===1?(r=st(await j(e,i,o+8,8,`a box header`),0),s=16):r===0&&(r=e.size-o),r<s||o+r>e.size)throw A(i,`a box ends past the end of the file`);let c=N(n,4,4);if(c===`moov`)throw new w(`UNSUPPORTED_FORMAT`,`Image sequences in ${i} aren't supported.`,{details:{format:i}});if(c===`meta`){if(a!==void 0)throw A(i,`there are two meta boxes`);a={start:o+s,end:o+r}}o+=r}if(a===void 0)throw A(i,`there's no meta box`);if(a.end-a.start>nt)throw A(i,`the meta box is too large`);let s=await j(e,i,a.start,a.end-a.start,`the meta box`),c=H(i,s,4,s.length),l=U(i,c,`hdlr`),u=l&&V(i,s,l.start+8,l.end);if(u===void 0||u.fourcc()!==`pict`)throw A(i,`the meta box isn't for a picture`);let d=U(i,c,`pitm`);if(d===void 0)throw A(i,`there's no primary item`);let f=V(i,s,d.start,d.end),p=f.u8();f.at+=3;let m=p===0?f.u16():f.u32(),h=/* @__PURE__ */ new Map,g=U(i,c,`iinf`);if(g===void 0)throw A(i,`there's no item information`);let _=V(i,s,g.start,g.end),v=_.u8();_.at+=3;let y=v===0?_.u16():_.u32(),b=H(i,s,_.at,g.end).filter(e=>e.type===`infe`);if(b.length!==y)throw A(i,`the item count doesn't match the item entries`);for(let e of b){let t=V(i,s,e.start,e.end),n=t.u8();t.at+=3;let r;if(n<2)r={id:t.u16(),type:``};else{let e=n===2?t.u16():t.u32();t.u16(),r={id:e,type:t.fourcc()}}if(h.has(r.id))throw A(i,`two items share an ID`);h.set(r.id,r)}let x=h.get(m);if(x===void 0)throw A(i,`the primary item isn't declared`);if(x.type!==`grid`&&!Qe.has(x.type))throw new w(`UNSUPPORTED_FORMAT`,`The ${i} file's primary image type isn't supported.`,{details:{format:i}});let S=[],C=U(i,c,`iref`);if(C!==void 0){let e=s[C.start]??0;for(let t of H(i,s,C.start+4,C.end)){let n=V(i,s,t.start,t.end),r=e===0?n.u16():n.u32(),a=n.u16(),o=[];for(let t=0;t<a;t+=1)o.push(e===0?n.u16():n.u32());S.push({type:t.type,from:r,to:o})}}let ee=U(i,c,`iprp`);if(ee===void 0)throw A(i,`there are no item properties`);let te=H(i,s,ee.start,ee.end),ne=U(i,te,`ipco`);if(ne===void 0)throw A(i,`there's no property container`);let re=H(i,s,ne.start,ne.end),ie=/* @__PURE__ */ new Map;for(let e of te.filter(e=>e.type===`ipma`)){let t=V(i,s,e.start,e.end),n=t.u8();t.u16();let r=(t.u8()&1)==1,a=t.u32();if(a>rt)throw A(i,`too many property associations`);for(let e=0;e<a;e+=1){let e=n<1?t.u16():t.u32();if(ie.has(e))throw A(i,`an item's properties are associated twice`);let a=[],o=t.u8();for(let e=0;e<o;e+=1){let e=r?t.u16()&32767:t.u8()&127;if(e===0)continue;let n=re[e-1];if(n===void 0)throw A(i,`an item refers to a property that doesn't exist`);a.push(n)}ie.set(e,a)}}let ae=(e,t)=>(ie.get(e)??[]).filter(e=>e.type===t),oe=e=>{let t=ae(e,`ispe`),n=t[0];if(n===void 0||t.length>1)throw A(i,`an image item has no single ispe`);let r=V(i,s,n.start+4,n.end),a={width:r.u32(),height:r.u32()};if(a.width<1||a.height<1)throw A(i,`an image item has no pixels`);return a},se=U(i,c,`idat`),ce=/* @__PURE__ */ new Map,le=U(i,c,`iloc`);if(le!==void 0){let t=V(i,s,le.start,le.end),n=t.u8();if(t.at+=3,n>2)throw A(i,`the item location version is unknown`);let r=t.u8(),a=t.u8(),o=r>>>4,c=r&15,l=a>>>4,u=n===0?0:a&15,d=n<2?t.u16():t.u32();if(d>rt)throw A(i,`too many item locations`);for(let r=0;r<d;r+=1){let r=n<2?t.u16():t.u32(),a=n===0?0:t.u16()&15;t.u16();let s=t.uint(l),d=t.u16(),f=[];for(let n=0;n<d;n+=1){t.uint(u);let n=s+t.uint(o),r=t.uint(c),l=a===0?e.size:a===1?(se?.end??0)-(se?.start??0):1/0,d=r===0?l-n:r;if(n+d>l||d<0)throw A(i,`an item's data lies outside the file`);f.push({offset:n,length:d})}if(ce.has(r))throw A(i,`an item is located twice`);ce.set(r,{method:a,extents:f})}}let T=async(t,n)=>{let r=ce.get(t);if(r===void 0)throw A(i,`an item's data has no location`);let a=r.extents.reduce((e,t)=>e+t.length,0);if(a>n)throw A(i,`an item's data is too large`);let o=[];for(let t of r.extents)if(r.method===0)o.push(await e.bytes(t.offset,t.length));else if(r.method===1&&se!==void 0){let e=se.start+t.offset;o.push(s.subarray(e,e+t.length))}else throw A(i,`an item's data is stored in a way the probe doesn't read`);let c=new Uint8Array(a),l=0;for(let e of o)c.set(e,l),l+=e.length;return c},E=S.filter(e=>et.has(e.type)),D=/* @__PURE__ */ new Set([m]);for(let e=[m];e.length>0;){let t=e.pop()??m;for(let n of E){let r=n.from===t?n.to:n.to.includes(t)?[n.from]:[];for(let t of r){if(!h.has(t))throw A(i,`a reference names an item that isn't declared`);D.has(t)||(D.add(t),e.push(t))}}}let O=new Map([...D].map(e=>[e,0])),k=E.filter(e=>D.has(e.from));for(let e of k)for(let t of e.to)O.set(t,(O.get(t)??0)+1);let ue=[...O].filter(([,e])=>e===0).map(([e])=>e),de=0;for(;ue.length>0;){let e=ue.pop()??0;de+=1;for(let t of k)if(t.from===e)for(let e of t.to){let t=(O.get(e)??0)-1;O.set(e,t),t===0&&ue.push(e)}}if(de!==D.size)throw A(i,`item references form a cycle`);let fe=0;for(let e of D){let t=oe(e);fe+=t.width*t.height,h.get(e)?.type===`grid`&&await pe(e,t)}async function pe(e,t){let n=S.filter(t=>t.type===`dimg`&&t.from===e),r=n[0]?.to??[];if(n.length!==1||r.length===0)throw A(i,`a grid doesn't name its tiles once`);if(r.length>it)throw A(i,`a grid has too many tiles`);let a=await T(e,64),o=V(i,a,0,a.length);if(o.u8()!==0)throw A(i,`the grid version is unknown`);let s=(o.u8()&1)==1,c=o.u8()+1,l=o.u8()+1,u=s?{width:o.u32(),height:o.u32()}:{width:o.u16(),height:o.u16()};if(c*l!==r.length)throw A(i,`a grid's tile count doesn't match its rows and columns`);if(u.width!==t.width||u.height!==t.height)throw A(i,`a grid's output differs from its ispe`);let d;for(let e of r){if(!Qe.has(h.get(e)?.type??``))throw A(i,`a grid tile isn't a coded image`);let t=oe(e);if(d!==void 0&&(t.width!==d.width||t.height!==d.height))throw A(i,`a grid's tiles differ in size`);d=t}if(d===void 0||t.width>l*d.width||t.height>c*d.height)throw A(i,`a grid's output doesn't fit its tiles`)}let me=oe(m),P=me,F=1,I=!1;for(let e of ie.get(m)??[])if(e.type===`clap`){if(I||P!==me)throw A(i,`a clean aperture follows a transformation`);P=dt(i,V(i,s,e.start,e.end),me)}else if(e.type===`irot`){I=!0;let t=V(i,s,e.start,e.end);F=ut(F,ft[t.u8()&3]??1)}else if(e.type===`imir`){I=!0;let t=V(i,s,e.start,e.end);F=ut(F,t.u8()&1?2:4)}let he=e=>S.filter(t=>t.type===e&&t.to.includes(m)),L=he(`auxl`).some(e=>ae(e.from,`auxC`).some(e=>{let t=V(i,s,e.start+4,e.end);return $e.has(t.string())})),ge=ae(m,`colr`).some(e=>{let t=V(i,s,e.start,e.end).fourcc();return t===`prof`||t===`rICC`}),R=Ve(),_e=[...h.values()].find(e=>e.type===`Exif`);if(_e!==void 0){let e=await T(_e.id,at);if(e.length<4||4+M(e,0)>e.length)throw A(i,`the EXIF item's header offset is out of range`);Object.assign(R,Ye(e.subarray(4+M(e,0)),i))}let ve=R.other||[...h.values()].some(e=>e.type===`mime`||e.type===`uri `);return{format:i,stored:P,oriented:Le(P,F),orientation:F,frames:1,hasAlpha:L,decodedPixelBound:fe,metadata:{location:R.location,camera:R.camera,timestamps:R.timestamps,thumbnail:R.thumbnail||he(`thmb`).length>0,colourProfile:ge,other:ve},keepable:{title:R.title,description:R.description,artist:R.artist,copyright:R.copyright}}}var mt=[255,216,255],ht=1e4;function gt(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}async function _t(e){let t=2,n,r=!1,i=Ve(),a=!1,o=!1;for(let s=0;!r;s+=1){if(s>=ht)throw A(`jpeg`,`the file has too many segments`);let c=await j(e,`jpeg`,t,2,`a marker`);if(c[0]!==255)throw A(`jpeg`,`a marker is missing`);let l=c[1]??0;if(l===255){t+=1;continue}if(l===216||l===217||l>=208&&l<=215||l===1){if(l===217)throw A(`jpeg`,`the image ends before its first scan`);t+=2;continue}let u=pe(await j(e,`jpeg`,t+2,2,`a segment length`),0);if(u<2)throw A(`jpeg`,`a segment length is out of range`);let d=t+4,f=u-2;if(d+f>e.size)throw A(`jpeg`,`a segment ends past the end of the file`);if(gt(l)){if(n!==void 0)throw A(`jpeg`,`there's more than one frame header before the scan`);if(f<6)throw A(`jpeg`,`the frame header is too short`);let t=await e.bytes(d,f),r=pe(t,1),i=pe(t,3),a=t[5]??0;if(r===0)throw A(`jpeg`,`the height is only defined after the scan`);if(i===0||a<1||a>4||f<6+a*3)throw A(`jpeg`,`the frame header is invalid`);n={width:i,height:r,components:a}}else if(l===218){if(n===void 0)throw A(`jpeg`,`the scan comes before a frame header`);r=!0}else if(l===225&&f>=6){if(N(await e.bytes(d,Math.min(f,64)),0,6)===`Exif\0\0`){if(a)i.other=!0;else{a=!0;let t=Ye((await e.bytes(d,f)).subarray(6),`jpeg`);Object.assign(i,t)}}else i.other=!0}else l===226&&f>=12?N(await e.bytes(d,12),0,12)===`ICC_PROFILE\0`?o=!0:i.other=!0:(l>=227&&l<=239||l===254)&&(i.other=!0);t=d+f}let s={width:n?.width??0,height:n?.height??0};return{format:`jpeg`,stored:s,oriented:Le(s,i.orientation),orientation:i.orientation,frames:1,hasAlpha:!1,decodedPixelBound:s.width*s.height,metadata:{location:i.location,camera:i.camera,timestamps:i.timestamps,thumbnail:i.thumbnail,colourProfile:o,other:i.other},keepable:{title:i.title,description:i.description,artist:i.artist,copyright:i.copyright}}}var vt=[137,80,78,71,13,10,26,10],yt=2**31-1,bt=1e5,xt=1<<20,St={Title:`title`,Description:`description`,Author:`artist`,Copyright:`copyright`};async function Ct(e){let t=8,n=0,r=0,i=!1,a,o=0,s=!1,c=!1,l=Ve(),u=!1;for(let d=0;!c;d+=1){if(d>=bt)throw A(`png`,`the file has too many chunks`);let f=await j(e,`png`,t,8,`a chunk header`),p=M(f,0),m=N(f,4,4);if(p>2147483647)throw A(`png`,`a chunk length is out of range`);let h=t+8;if(h+p+4>e.size)throw A(`png`,`a chunk ends past the end of the file`);if(d===0&&m!==`IHDR`)throw A(`png`,`IHDR isn't the first chunk`);let g=async()=>{if(p>xt)throw A(`png`,`the ${m} chunk is too large`);return e.bytes(h,p)};switch(m){case`IHDR`:{if(d!==0||p!==13)throw A(`png`,`IHDR is repeated or the wrong size`);let e=await g();if(n=M(e,0),r=M(e,4),n<1||r<1||n>yt||r>yt)throw A(`png`,`the dimensions are out of range`);let t=e[9];i=t===4||t===6;break}case`acTL`:if(s||a!==void 0||p!==8)throw A(`png`,`acTL is misplaced, repeated or the wrong size`);if(a=M(await g(),0),a<1)throw A(`png`,`acTL declares no frames`);break;case`fcTL`:{if(p!==26)throw A(`png`,`an fcTL is the wrong size`);let e=await g(),t=M(e,4),i=M(e,8),a=M(e,12),s=M(e,16);if(t<1||i<1||a+t>n||s+i>r)throw A(`png`,`a frame doesn't fit inside the image`);o+=1;break}case`IDAT`:s=!0;break;case`tRNS`:i=!0;break;case`iCCP`:case`sRGB`:case`cICP`:u||=m!==`sRGB`;break;case`tIME`:l.timestamps=!0;break;case`eXIf`:{let e=Ye(await g(),`png`);Object.assign(l,{...e,orientation:s?l.orientation:e.orientation,title:l.title||e.title,description:l.description||e.description,artist:l.artist||e.artist,copyright:l.copyright||e.copyright});break}case`tEXt`:case`iTXt`:case`zTXt`:{let e=await g(),t=e.indexOf(0),n=St[N(e,0,t<0?Math.min(e.length,79):t)];if(n===void 0)l.other=!0;else if(m===`tEXt`&&t>=0)l[n]=new TextDecoder(`latin1`).decode(e.subarray(t+1)).slice(0,De);else if(m===`iTXt`&&t>=0&&e[t+1]===0){let r=t+3;for(let t=0;t<2&&r<e.length;r+=1)e[r]===0&&(t+=1);l[n]=new TextDecoder().decode(e.subarray(r)).slice(0,De)}else l.other=!0;break}case`IEND`:c=!0}t=h+p+4}if(!s)throw A(`png`,`there's no image data`);if(a!==void 0&&o!==a)throw A(`png`,`acTL's frame count doesn't match the frames`);let d=a??1,f={width:n,height:r};return{format:`png`,stored:f,oriented:Le(f,l.orientation),orientation:l.orientation,frames:d,hasAlpha:i,decodedPixelBound:d*n*r,metadata:{location:l.location,camera:l.camera,timestamps:l.timestamps,thumbnail:l.thumbnail,colourProfile:u,other:l.other},keepable:{title:l.title,description:l.description,artist:l.artist,copyright:l.copyright}}}var wt=1e5,Tt=1<<20;function Et(e){return N(e,0,4)===`RIFF`&&N(e,8,4)===`WEBP`}async function Dt(e){let t=8+I(await j(e,`webp`,0,12,`the RIFF header`),4);if(t>e.size||t<20)throw A(`webp`,`the RIFF size doesn't match the file`);let n=0,r=0,i=!1,a,o=!1,s=0,c=Ve(),l=!1,u=12;for(let d=0;u<t;d+=1){if(d>=wt)throw A(`webp`,`the file has too many chunks`);let f=await j(e,`webp`,u,8,`a chunk header`),p=N(f,0,4),m=I(f,4),h=u+8;if(h+m>t)throw A(`webp`,`a chunk ends past the RIFF data`);if(d===0&&p!==`VP8 `&&p!==`VP8L`&&p!==`VP8X`)throw A(`webp`,`the first chunk isn't an image header`);switch(p){case`VP8X`:{if(d!==0||m<10)throw A(`webp`,`VP8X is misplaced or too short`);let t=await e.bytes(h,10),o=t[0]??0;i=!!(o&16),a={animated:!!(o&2)},n=F(t,4)+1,r=F(t,7)+1;break}case`VP8 `:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<10)throw A(`webp`,`the VP8 frame header is too short`);let t=await e.bytes(h,10);if(t[3]!==157||t[4]!==1||t[5]!==42)throw A(`webp`,`the VP8 start code is missing`);let i=((t[6]??0)|(t[7]??0)<<8)&16383,a=((t[8]??0)|(t[9]??0)<<8)&16383;if(o)n=i,r=a;else if(i!==n||a!==r)throw A(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`VP8L`:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<5)throw A(`webp`,`the VP8L header is too short`);let t=await e.bytes(h,5);if(t[0]!==47)throw A(`webp`,`the VP8L signature is missing`);let a=I(t,1),c=(a&16383)+1,l=(a>>>14&16383)+1;if(o)n=c,r=l,i=(a>>>28&1)==1;else if(c!==n||l!==r)throw A(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`ANMF`:{if(a?.animated!==!0)throw A(`webp`,`an animation frame without the animation flag`);if(m<16)throw A(`webp`,`an ANMF header is too short`);let t=await e.bytes(h,16),i=F(t,0)*2,o=F(t,3)*2,c=F(t,6)+1,l=F(t,9)+1;if(i+c>n||o+l>r)throw A(`webp`,`a frame doesn't fit inside the canvas`);s+=1;break}case`EXIF`:{if(m>Tt)throw A(`webp`,`the EXIF chunk is too large`);let t=await e.bytes(h,m),n=N(t,0,6)===`Exif\0\0`?t.subarray(6):t;Object.assign(c,Ye(n,`webp`));break}case`ICCP`:l=!0;break;case`XMP `:c.other=!0}u=h+m+m%2}if(a?.animated===!0&&s===0)throw A(`webp`,`an animation without frames`);if(s===0||n<1||r<1)throw A(`webp`,`there's no image data`);let d={width:n,height:r};return{format:`webp`,stored:d,oriented:d,orientation:1,frames:s,hasAlpha:i,decodedPixelBound:s*n*r,metadata:{location:c.location,camera:c.camera,timestamps:c.timestamps,thumbnail:c.thumbnail,colourProfile:l,other:c.other},keepable:{title:c.title,description:c.description,artist:c.artist,copyright:c.copyright}}}async function Ot(e){let t=await kt(e);return t.orientation===1?t:{...t,decodedPixelBound:t.decodedPixelBound+t.oriented.width*t.oriented.height}}async function kt(e){let t=await e.bytes(0,16);if(me(t,vt))return Ct(e);if(me(t,mt))return _t(e);if(Et(t))return Dt(e);if(Ne(t))return Ie(e);if(ot(t))return pt(e);if(Ae(t))return je(e);throw new w(`UNSUPPORTED_FORMAT`,`The file isn't an image format the SDK reads.`,{details:{format:`unknown`}})}var At=`AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUEAAAD/bWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAAAAAAAOcGl0bQAAAAAAAQAAAB5pbG9jAAAAAEQAAAEAAQAAAAEAAAEnAAAAcgAAAChpaW5mAAAAAAABAAAAGmluZmUCAAAAAAEAAGF2MDFDb2xvcgAAAAB+aXBycAAAAF1pcGNvAAAAFGlzcGUAAAAAAAAAMAAAACAAAAAQcGl4aQAAAAADCAgIAAAADGF2MUOBIAAAAAAAE2NvbHJuY2x4AAEADQAAgAAAAAlpcm90AQAAAAlpbWlyAAAAABlpcG1hAAAAAAAAAAEAAQYBAoMEhYYAAAB6bWRhdBIACgg4FS/7CAhoATJkRAAA66GyTOByOdAYkRkr4m7XruCgkx+mYn1Qgy/LhM4TZqjxnONsI9XbAWAHGMpcPWGmUkXOiY7S7v9FNX7P7LNof17If68icGW/sP+HwSL0D+g3eqOYaSrFfjiDyX15CtJnQA==`,jt=`AAAAHGZ0eXBoZWljAAAAAG1pZjFoZWljbWlhZgAAAYdtZXRhAAAAAAAAACFoZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAAACJpbG9jAAAAAERAAAEAAQAAAAABqwABAAAAAAAAAWgAAAAjaWluZgAAAAAAAQAAABVpbmZlAgAAAAABAABodmMxAAAAAA5waXRtAAAAAAABAAABB2lwcnAAAADmaXBjbwAAAHZodmNDAQNwAAAAkAAAAAAAHvAA/P34+AAADwNgAAEAGEABDAH//wNwAAADAJAAAAMAAAMAHroCQGEAAQAqQgEBA3AAAAMAkAAAAwAAAwAeoCCBBZbq5Ka5uAhoMCAAAAMDIAAAAwAhYgABAAZEAcFzwIkAAAATY29scm5jbHgAAQANAAaAAAAAFGlzcGUAAAAAAAAAQAAAAEAAAAAoY2xhcAAAADAAAAABAAAAIAAAAAH////wAAAAAv///+AAAAACAAAAEHBpeGkAAAAAAwgICAAAAAlpcm90AwAAABlpcG1hAAAAAAAAAAEAAQaBAgMFhIYAAAFwbWRhdAAAAWQoAa8GOFr3tt/M4H//+Vpvof3rcAh8Eib+lqP/9+gf/+RCoo6DBnp3DS7HVjpEKagkLLToAgLPf0gsRJBgcTX4smMnA56A3yusdiX58OB/cyikP5RcP/+9DOaSLzxpbfDIZx/2MvdnwDvv9lSv0freK1OdDW2Ic4mjihv4Uz//vczuufFs///BqPj3RM/C9DmybAdK2pHa/WML+n/ofh5OM4ta2QwoyoH3+alRlUJmOn32ErQy0y2l9of783mHK5kj3qBIVLt5C1BsgYvxBJJJhajHb4IsPzEa+wCUZ5YPLfyZ/uW52rOVP02LJknTKZhyZSGGlQM61gCojEG7/8aeNtxBJSuYa9zi2C0FUTZ4EDzXcIldzBDOZRRifvUNh8tXulTFvZTGIysgw+2l3qZ2NW5kvuf+S5yWynAG/xw+MPF+8sAgASh/Fw7rEV3MEM5lFGJ+9Q2Hy1eE3LPWi21NT3jguA==`;function Mt(e,{width:t,height: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[1,0,0,1,0,0]}}function Nt(e,t){let n={width:e.width,height:e.height},r=Le(n,t),i=new OffscreenCanvas(r.width,r.height),a=i.getContext(`2d`);if(!a)throw e.close(),Error(`The worker has no 2D canvas.`);return a.setTransform(...Mt(t,n)),a.drawImage(e,0,0),e.close(),i.transferToImageBitmap()}var Pt=[[255,0,0],[0,255,0],[0,0,255],[255,255,0]];function Ft(e){let[t,n,r,i]=Mt(e,{width:0,height:0}),a=[[-1,-1],[1,-1],[-1,1],[1,1]],o=[];return a.forEach(([e,s],c)=>{let l=a.findIndex(([a,o])=>a===t*e+r*s&&o===n*e+i*s);o[l]=c}),o}var It=(e,t)=>t.every((t,n)=>Math.abs((e[n]??NaN)-t)<=64);function Lt(e,t,n){for(let r of[1,2,3,4,5,6,7,8]){let i=Le(n,r);if(i.width===e.width&&i.height===e.height&&Ft(r).every((e,n)=>It(t[n]??[],Pt[e]??[])))return r}}function Rt(e){let{width:t,height:n}=e,r=new OffscreenCanvas(t,n).getContext(`2d`,{willReadFrequently:!0});if(!r)throw Error(`The worker has no 2D canvas.`);return r.drawImage(e,0,0),[[t/4,n/4],[3*t/4,n/4],[t/4,3*n/4],[3*t/4,3*n/4]].map(([e=0,t=0])=>Array.from(r.getImageData(Math.floor(e),Math.floor(t),1,1).data))}var zt={width:48,height:32};function Bt(){let e=new OffscreenCanvas(zt.width,zt.height),t=e.getContext(`2d`);if(!t)throw Error(`The worker has no 2D canvas.`);return Pt.forEach(([e,n,r],i)=>{t.fillStyle=`rgb(${e} ${n} ${r})`,t.fillRect(i%2*24,Math.floor(i/2)*16,24,16)}),e}function Vt(e){return Uint8Array.of(77,77,0,42,0,0,0,8,0,1,1,18,0,3,0,0,0,1,0,e,0,0,0,0,0,0)}var Ht=Array.from({length:256},(e,t)=>{let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function Ut(e){let t=4294967295;for(let n of e)t=(Ht[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}var Wt=(e,t)=>Array.from({length:t},(n,r)=>e>>>8*(t-1-r)&255);async function Gt(){let e=new Uint8Array(await(await Bt().convertToBlob()).arrayBuffer()),t=Uint8Array.of(101,88,73,102,...Vt(7)),n=Uint8Array.of(...Wt(t.length-4,4),...t,...Wt(Ut(t),4));return new Blob([e.slice(0,33),n,e.slice(33)],{type:`image/png`})}function Kt(e){return e[2]===255&&e[3]===224?4+((e[4]??0)<<8|(e[5]??0)):2}async function qt(){let e=new Uint8Array(await(await Bt().convertToBlob({type:`image/jpeg`,quality:1})).arrayBuffer()),t=Uint8Array.of(69,120,105,102,0,0,...Vt(7)),n=Uint8Array.of(255,225,...Wt(t.length+2,2),...t),r=Kt(e);return new Blob([e.slice(0,r),n,e.slice(r)],{type:`image/jpeg`})}var Jt=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function Yt(e){switch(e){case`jpeg`:return qt();case`png`:return Gt();case`avif`:return new Blob([Jt(At)]);case`heif`:return new Blob([Jt(jt)]);default:return}}async function Xt(e){let t=await Yt(e);if(!t)return`unknown`;let n=await Ot(s(t)),r=await createImageBitmap(t,{imageOrientation:`from-image`});try{let e=Lt(r,Rt(r),n.stored);return n.orientation!==1&&e===n.orientation?`applied`:e===1?`not applied`:`unknown`}finally{r.close()}}var Zt=/* @__PURE__ */ new Map;function Qt(e,t=Xt){let n=Zt.get(e);return n||(n=t(e).catch(()=>(Zt.delete(e),`unknown`)),Zt.set(e,n)),n}var $t={decode:e=>createImageBitmap(e,{imageOrientation:`from-image`,premultiplyAlpha:`none`,colorSpaceConversion:`default`}),calibrate:Qt},en=(e,t,n)=>createImageBitmap(new ImageData(e,t,n),{premultiplyAlpha:`none`});async function tn(e,t){let n=new Uint8Array(await e.arrayBuffer()),r=we(n);if(r.frames.length!==t.frames||r.width!==t.stored.width||r.height!==t.stored.height)throw new w(`INVALID_IMAGE`,`The GIF's frames differ from what its probe read.`,{details:{format:`gif`,problem:`the frame table differs from the probe`}});return{bytes:n,gif:r}}async function nn(e,t,n){let r=new Uint8Array(await e.arrayBuffer()),i=we(r,`first`);if(i.width!==t.stored.width||i.height!==t.stored.height)throw new w(`INVALID_IMAGE`,`The GIF's frames differ from what its probe read.`,{details:{format:`gif`,problem:`the frame table differs from the probe`}});let a=ye(r,i).next();return(n.fromPixels??en)(a,i.width,i.height)}var rn=(e,t)=>new w(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:e.format,problem:t}});async function an(e,t,n=$t){let r;try{r=t.format===`gif`?await nn(e,t,n):await n.decode(e)}catch(e){throw T(e)?e:new w(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:t.format},cause:e})}if(t.orientation!==1){let e=await n.calibrate(t.format);if(e===`unknown`)throw r.close(),rn(t,`this browser's orientation handling is unknown`);if(e===`not applied`)try{r=Nt(r,t.orientation)}catch(e){throw new w(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:t.format,problem:`the worker couldn't orient it`},cause:e})}}if(r.width!==t.oriented.width||r.height!==t.oriented.height)throw r.close(),new w(`INVALID_IMAGE`,`The image decoded to another size than its header declares.`,{details:{format:t.format,problem:`the decoded size differs from the probe`}});return r}var on=e=>new TextEncoder().encode(e),W=e=>Uint8Array.from(e,e=>e.charCodeAt(0)&255),G=e=>[e>>>8&255,e&255],K=e=>[...G(e>>>16),...G(e&65535)];function q(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}var sn=e=>Object.values(e).some(e=>e!==``);function cn(e){let t=[];if(e.description&&t.push({tag:270,type:2,value:q([on(e.description),[0]])}),e.artist&&t.push({tag:315,type:2,value:q([on(e.artist),[0]])}),e.copyright&&t.push({tag:33432,type:2,value:q([on(e.copyright),[0]])}),e.title){let n=[];for(let t=0;t<e.title.length;t+=1){let r=e.title.charCodeAt(t);n.push(r&255,r>>>8)}n.push(0,0),t.push({tag:40091,type:1,value:Uint8Array.from(n)})}let n=8+(2+t.length*12+4),r=[...G(t.length)],i=[];for(let{tag:e,type:a,value:o}of t)r.push(...G(e),...G(a),...K(o.length)),o.length<=4?r.push(...o,...Array(4-o.length).fill(0)):(r.push(...K(n)),i.push(o),n+=o.length+o.length%2,o.length%2&&i.push(Uint8Array.of(0)));return r.push(...K(0)),q([W(`MM`),G(42),K(8),r,...i])}function ln(e,t){let n=[e.subarray(0,2)],r=2,i=!1,a=()=>{if(i||!sn(t))return;i=!0;let e=q([W(`Exif\0\0`),cn(t)]);n.push(q([[255,225,...G(e.length+2)],e]))};for(;r+4<=e.length&&e[r]===255;){let t=e[r+1]??0;if(!(t>=224&&t<=239)&&t!==254)break;let i=(e[r+2]??0)<<8|(e[r+3]??0),a=e.subarray(r,r+2+i);t===224&&String.fromCharCode(...a.subarray(4,9))===`JFIF\0`&&n.push(a),r+=2+i}return a(),n.push(e.subarray(r)),q(n)}var un=Array.from({length:256},(e,t)=>{let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;return n>>>0});function dn(e,t){let n=q([W(e),t]),r=4294967295;for(let e of n)r=(un[(r^e)&255]??0)^r>>>8;return q([K(t.length),n,K((r^4294967295)>>>0)])}var fn=/* @__PURE__ */ new Set([`IHDR`,`PLTE`,`tRNS`,`IDAT`,`IEND`]),pn={title:`Title`,description:`Description`,artist:`Author`,copyright:`Copyright`};function mn(e,t){let n=[e.subarray(0,8)],r=8;for(;r+12<=e.length;){let i=((e[r]??0)<<24|(e[r+1]??0)<<16|(e[r+2]??0)<<8|(e[r+3]??0))>>>0,a=String.fromCharCode(...e.subarray(r+4,r+8)),o=r+12+i;if(fn.has(a)&&n.push(e.subarray(r,o)),a===`IHDR`)for(let[e,r]of Object.entries(pn)){let i=t[e];i&&n.push(dn(`iTXt`,q([W(r),[0,0,0,0,0],on(i)])))}r=o}return q(n)}function hn(e){let t=[],n=12;for(;n+8<=e.length;){let r=String.fromCharCode(...e.subarray(n,n+4)),i=((e[n+4]??0)|(e[n+5]??0)<<8|(e[n+6]??0)<<16|(e[n+7]??0)<<24)>>>0,a=n+8+i+i%2,o=e.slice(n,a);r===`VP8X`?(o[8]=(o[8]??0)&-45,t.push(o)):(r===`VP8 `||r===`VP8L`||r===`ALPH`||r===`ANIM`||r===`ANMF`)&&t.push(o),n=a}let r=q([W(`WEBP`),...t]),i=r.length;return q([W(`RIFF`),[i&255,i>>>8&255,i>>>16&255,i>>>24],r])}var gn=Object.freeze({temperature:0,tint:0,exposure:0,highlights:0,shadows:0,contrast:0,saturation:0,vibrance:0});Object.freeze({rotate:0,flipX:!1,flipY:!1}),Object.freeze({kind:`scale`,scale:1});var _n=.2126,vn=.7152,yn=.0722,bn=[_n,vn,yn],J=(e,t)=>[[0,e],[255,t]],xn={vivid:{develop:{contrast:20,saturation:35,vibrance:25}},warm:{develop:{temperature:35,tint:5,vibrance:10}},cool:{develop:{temperature:-35,tint:-5}},fade:{develop:{contrast:-30,shadows:25},curves:[J(30,240),J(30,240),J(30,240)]},mono:{mono:bn},noir:{develop:{contrast:50,shadows:-20},mono:bn},sepia:{mono:bn,curves:[J(40,255),J(20,235),J(0,190)]}},Sn=2**20,Cn=e=>Math.round(e*Sn)/Sn,wn=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Tn=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,Y=4095,En=Float32Array.from({length:256},(e,t)=>Cn(wn(t/255))),X=Float32Array.from({length:4096},(e,t)=>Cn(wn(t/Y))),Z=Float32Array.from({length:4096},(e,t)=>Cn(Tn(t/Y))),Dn=Float64Array.from(X,e=>e>0?1/e:0),On=e=>Math.min(1,Math.max(0,e)),kn=e=>Math.round(On(e)*Y),An=e=>Math.round(On(e)*255),jn=(e,t)=>t===0?e:On(e+t*(e*e*(3-2*e)-e)),Q=e=>[e(0),e(1),e(2)];function Mn(e){let t=Cn(2**(e.exposure/50)),n=e.temperature/100,r=e.tint/100,i=[(1+.2*n)*t,(1-.2*r)*t,(1-.2*n)*t],[a,o,s]=Q(e=>Float32Array.from(En,t=>Z[kn(t*i[e])])),c=e.contrast/100,l=e.highlights/100*.25,u=e.shadows/100*.25,d=e.saturation/100,f=e.vibrance/100,p=l!==0||u!==0,m=d!==0||f!==0,h=(e,t,n,r)=>{let i=a[e],h=o[t],g=s[n];if(p){let e=_n*i+vn*h+yn*g,t=(e-.5)*2;t=Math.min(1,Math.max(0,t));let n=e*2;n=Math.min(1,Math.max(0,n));let r=l*t*t*(3-2*t)+u*(1-n*n*(3-2*n));i+=r,h+=r,g+=r,i=Math.min(1,Math.max(0,i)),h=Math.min(1,Math.max(0,h)),g=Math.min(1,Math.max(0,g))}if(c!==0&&(i+=c*(i*i*(3-2*i)-i),h+=c*(h*h*(3-2*h)-h),g+=c*(g*g*(3-2*g)-g),i=Math.min(1,Math.max(0,i)),h=Math.min(1,Math.max(0,h)),g=Math.min(1,Math.max(0,g))),m){let e=i*Y+.5|0,t=h*Y+.5|0,n=g*Y+.5|0,r=X[e],a=X[t],o=X[n],s=_n*r+vn*a+yn*o,c=1+d;if(f!==0){let r=Math.max(e,Math.max(t,n)),i=r>0?(X[r]-X[Math.min(e,Math.min(t,n))])*Dn[r]:0;c+=f*(1-i)}i=s+(r-s)*c,h=s+(a-s)*c,g=s+(o-s)*c,i=Z[Math.min(1,Math.max(0,i))*Y+.5|0],h=Z[Math.min(1,Math.max(0,h))*Y+.5|0],g=Z[Math.min(1,Math.max(0,g))*Y+.5|0]}r[0]=i,r[1]=h,r[2]=g},[g,_,v]=Q(e=>Uint16Array.from([a,o,s][e],e=>kn(jn(e,c))));return{perChannel:p||m?void 0:Q(e=>Uint8Array.from([a,o,s][e],e=>An(jn(e,c)))),run:p?h:(e,t,n,r)=>{let i=g[e],a=_[t],o=v[n],s=X[i],c=X[a],l=X[o],u=_n*s+vn*c+yn*l,p=1+d;if(f!==0){let e=Math.max(i,Math.max(a,o)),t=e>0?(X[e]-X[Math.min(i,Math.min(a,o))])*Dn[e]:0;p+=f*(1-t)}let m=u+(s-u)*p,h=u+(c-u)*p,y=u+(l-u)*p;m=Z[Math.min(1,Math.max(0,m))*Y+.5|0],h=Z[Math.min(1,Math.max(0,h))*Y+.5|0],y=Z[Math.min(1,Math.max(0,y))*Y+.5|0],r[0]=m,r[1]=h,r[2]=y}}}function Nn(e){return Uint8Array.from({length:256},(t,n)=>{for(let t=1;t<e.length;t+=1){let[r,i]=e[t-1]??[0,0],[a,o]=e[t]??[255,255];if(n<=a)return Math.round(i+(o-i)*(n-r)/(a-r||1))}return e.at(-1)?.[1]??n})}var Pn=e=>Object.values(e).every(e=>e===0);function Fn(e,t){return!Pn(e)||t!==null&&t.strength>0}var In=e=>new Uint8Array(e.buffer,e.byteOffset,e.length),$=Uint8Array.from({length:256},(e,t)=>t);function Ln(e,t){let n=Pn(e)?void 0:Mn(e),r=t===null||t.strength===0?void 0:xn[t.preset],i=(t?.strength??0)/100,a=r?.develop?Mn({...gn,...r.develop}):void 0,o=r?.curves?Q(e=>Nn(r.curves?.[e]??[])):[$,$,$],s=r?.mono,c=r?.curves!==void 0,l=/* @__PURE__ */ new Float64Array(3),u=r!==void 0&&s===void 0&&(!a||a.perChannel)?Q(e=>Uint8Array.from($,t=>{let n=a?.perChannel?.[e][t]??t,r=o[e][n]??n;return Math.round(t+(r-t)*i)})):void 0,d=n?n.perChannel:[$,$,$];if(d&&(!r||u)){let[e,t,n]=Q(e=>Uint8Array.from(d[e],t=>u?u[e][t]??t:t));return r=>{let i=In(r);for(let r=0;r<i.length;r+=4)i[r]=e[i[r]??0]??0,i[r+1]=t[i[r+1]??0]??0,i[r+2]=n[i[r+2]??0]??0}}return e=>{let t=In(e);for(let e=0;e<t.length;e+=4){let f=t[e]??0,p=t[e+1]??0,m=t[e+2]??0;if(d?(f=d[0][f]??0,p=d[1][p]??0,m=d[2][m]??0):n&&(n.run(f,p,m,l),f=l[0]*255+.5|0,p=l[1]*255+.5|0,m=l[2]*255+.5|0),u)f=u[0][f]??f,p=u[1][p]??p,m=u[2][m]??m;else if(r){let e,t,n;if(a?.perChannel?(e=(a.perChannel[0][f]??0)/255,t=(a.perChannel[1][p]??0)/255,n=(a.perChannel[2][m]??0)/255):a?(a.run(f,p,m,l),e=l[0]??0,t=l[1]??0,n=l[2]??0):(e=f/255,t=p/255,n=m/255),s){let r=s[0]*e+s[1]*t+s[2]*n;e=r,t=r,n=r}let r=e*255+.5|0,u=t*255+.5|0,d=n*255+.5|0;c&&(r=o[0][r],u=o[1][u],d=o[2][d]),f=f+(r-f)*i+.5|0,p=p+(u-p)*i+.5|0,m=m+(d-m)*i+.5|0}t[e]=f,t[e+1]=p,t[e+2]=m}}}function Rn(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.hypot(r,i);if(!(a>0))throw RangeError(`An arrow's ends differ.`);let o=r/a,s=i/a,c=s,l=-o,u=Math.min(4*n,a),d=u/2,f=Math.min(n/2,d),p={x:t.x-o*u,y:t.y-s*u},m=(e,t)=>({x:e.x+c*t||0,y:e.y+l*t||0});return[m(e,f),m(e,-f),m(p,-f),m(p,-d),{x:t.x,y:t.y},m(p,d),m(p,f)]}function zn(e,t){let[n,r,i,a,o,s]=e,[c,l,u,d,f,p]=t;return[c*n+u*r,l*n+d*r,c*i+u*a,l*i+d*a,c*o+u*s+f,l*o+d*s+p]}function Bn(e,t,n){let r=t.rotate%180==0?{width:e.width,height:e.height}:{width:e.height,height:e.width},i=n.width/r.width,a=n.height/r.height,o=(n,r)=>{let o=Be({x:n,y:r},e,t);return{x:o.x*i,y:o.y*a}},s=o(0,0),c=o(1,0),l=o(0,1);return[c.x-s.x,c.y-s.y,l.x-s.x,l.y-s.y,s.x,s.y]}function Vn(e){let t=e.rotation*Math.PI/1800,n=e.rotation%900==0?e.rotation/900%4:-1,r=n>=0?[1,0,-1,0][n]:Math.cos(t),i=n>=0?[0,1,0,-1][n]:Math.sin(t),a=e=>e===0?0:-e,o=e.flipX?a(r):r,s=e.flipX?a(i):i,c=a(i),l=r;return[o,s,c,l,e.x+e.width/2-(o*e.width+c*e.height)/2,e.y+e.height/2-(s*e.width+l*e.height)/2]}function Hn(e,t,n,r){return zn(Vn(e),Bn(t,n,r))}function Un(e){let[t,n,r,i,a,o]=e,s=t*i-n*r;return[i/s,-n/s,-r/s,t/s,(r*o-i*a)/s,(n*a-t*o)/s]}function Wn(e,t){let n=[t.width/e.width,0,0,t.height/e.height,t.x,t.y];return zn(Un(Vn(e)),n)}function Gn(e,t){let[n,r,i,a,o,s]=e;return{x:n*t.x+i*t.y+o,y:r*t.x+a*t.y+s}}function Kn(e,t,n,r,i,a){let o=Math.max(0,...e.map(e=>e.width));if(!(o>0)||!(t>0))return null;let s=Math.min(r.width/o,r.height/(t*e.length)),c=(r.height-t*e.length*s)/2,l=i===`center`?.5:+(i===`start`===a);return{scale:s,lines:e.map((e,i)=>({x:(r.width-e.width*s)*l,baseline:c+(i*t+n)*s}))}}function qn(e){for(let t of e){if(Jn.test(t))return!0;if(Yn.test(t))return!1}return!1}var Jn=/[-ࣿיִ-﷿ﹰ-\u{10800}-\u{10FFF}\u{1E800}-\u{1EFFF}]/u,Yn=/\p{L}/u,Xn=8,Zn=12;function Qn(e){return Math.max(Xn,Math.ceil(Math.max(e.width,e.height)/Zn))}function $n(e,t,n){let r=[e];for(let i=e+n;i<e+t;i+=n)r.push(i);return r.push(e+t),r}function er(e,t){let n=[];for(let r=0;r+1<t.length;r+=1){let i=t[r],a=t[r+1]-i;if(!(a<=0))for(let t=0;t+1<e.length;t+=1){let r=e[t],o=e[t+1]-r;o>0&&n.push({x:r,y:i,width:o,height:a})}}return n}var tr=(e,t,n)=>Math.min(n,Math.max(t,e));function nr(e,t){let n=Qn(e),r=(e,t,n)=>e.map(e=>tr(e,t,n));return er(r($n(e.x,e.width,n),t.x,t.x+t.width),r($n(e.y,e.height,n),t.y,t.y+t.height))}function rr(e,t,n){let r=t.rotate%180!=0,i=r?{width:e.height,height:e.width}:{width:e.width,height:e.height},a=n.width/i.width,o=n.height/i.height,s=(n,r)=>{let i=Be({x:n,y:r},e,t);return{x:i.x*a,y:i.y*o}};return{turned:r,fromX:t=>r?s(t,e.y).y:s(t,e.y).x,fromY:t=>r?s(e.x,t).x:s(e.x,t).y}}function ir(e,t){let n=[...e].sort((e,t)=>e-t),r=n.length-1,i=0;return n.map((e,n)=>(i=Math.max(i,tr(n===0?Math.floor(e):n===r?Math.ceil(e):Math.round(e),0,t)),i))}function ar(e,t,n,r){let{turned:i,fromX:a,fromY:o}=rr(t,n,r),s=[a(e.x),a(e.x+e.width)],c=[o(e.y),o(e.y+e.height)],[l,u]=ir(i?c:s,r.width),[d,f]=ir(i?s:c,r.height);return u<=l||f<=d?null:{x:l,y:d,width:u-l,height:f-d}}function or(e,t,n,r){let i=Qn(e),{turned:a,fromX:o,fromY:s}=rr(t,n,r),c=$n(e.x,e.width,i).map(o),l=$n(e.y,e.height,i).map(s);return er(ir(a?l:c,r.width),ir(a?c:l,r.height))}function sr(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(void 0)})}async function cr(e){if(e&&(await sr(),e.aborted))throw e.reason}var lr=4e6;function ur(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return i>n&&a>r?{x:n,y:r,width:i-n,height:a-r}:null}function dr(e,t,n){e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=1,e.globalCompositeOperation=`source-over`,e.fillStyle=n,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}var fr=/* @__PURE__ */ new WeakMap,pr=/* @__PURE__ */ new WeakMap;function mr(e){let t=fr.get(e);t&&(t.canvas.width=0),fr.delete(e);for(let t of pr.get(e)?.values()??[])t.canvas.width=0;pr.delete(e)}var hr={x:-1e9,y:-1e9,width:2e9,height:2e9};function gr(e,t){return[[t.x,t.y],[t.x+t.width,t.y],[t.x+t.width,t.y+t.height],[t.x,t.y+t.height]].map(([t,n])=>Gn(e,{x:t,y:n}))}function _r(e,t){let n=e.map(e=>e.x),r=e.map(e=>e.y),i=Math.floor(Math.min(...n)),a=Math.floor(Math.min(...r));return ur({x:i,y:a,width:Math.ceil(Math.max(...n))-i,height:Math.ceil(Math.max(...r))-a},t)}async function vr(e,t,n,r,i){let a=_r(gr(t,n),r);if(!a)return[0,0,0,0];let o=Un(t),s=Math.max(1,Math.floor(lr/(a.width*4))),c=[0,0,0,0],l=0;for(let t=0;t<a.height;t+=s){await cr(i);let r=Math.min(s,a.height-t),{data:u}=e.getImageData(a.x,a.y+t,a.width,r,{colorSpace:`srgb`});for(let e=0;e<r;e+=1)for(let r=0;r<a.width;r+=1){let i=Gn(o,{x:a.x+r+.5,y:a.y+t+e+.5});if(i.x<n.x||i.x>=n.x+n.width||i.y<n.y||i.y>=n.y+n.height)continue;let s=(e*a.width+r)*4,d=u[s+3];c[0]+=u[s]*d,c[1]+=u[s+1]*d,c[2]+=u[s+2]*d,c[3]+=d,l+=1}}let[u=0,d=0,f=0,p=0]=c;return p>0&&l>0?[Math.round(u/p),Math.round(d/p),Math.round(f/p),Math.round(p/l)]:[0,0,0,0]}async function yr(e,t,n,r){let i={x:0,y:0,width:e.width,height:e.height},a=B(t.crop,e),o=Wn(t,a),s=_r(gr(Vn(t),{x:0,y:0,width:t.width,height:t.height}),hr),c=n.redactions.filter(e=>s!==null&&ur(e,s)!==null),l=pr.get(e);if(c.length===0)return l?.delete(t.key),e;let{x:u,y:d,width:f,height:p,rotation:m,flipX:h}=t,g=JSON.stringify([c,u,d,f,p,m,h,a]),_=l?.get(t.key);if(_?.key===g)return _.canvas;let v=new OffscreenCanvas(e.width,e.height),y=v.getContext(`2d`,{colorSpace:`srgb`,willReadFrequently:Tr(c)});if(!y)throw Error(`The worker has no 2D canvas.`);y.imageSmoothingEnabled=!1,y.drawImage(e,0,0);for(let e of c){let t=e.mode===`solid`?e.colour:await vr(y,o,e,i,r).then(([e,t,n])=>`rgb(${e} ${t} ${n})`);y.save(),y.setTransform(...o),y.fillStyle=t,y.fillRect(e.x,e.y,e.width,e.height),y.restore()}if(r?.aborted)throw v.width=0,r.reason;let b=l??/* @__PURE__ */ new Map;return b.set(t.key,{key:g,canvas:v}),pr.set(e,b),v}function br(e,t){let n=pr.get(e);if(n)for(let e of[...n.keys()])t.has(e)||n.delete(e)}async function xr(e,t,n){let r={x:0,y:0,width:e.width,height:e.height},i=B(t.base.crop,e),a=t.redactions.filter(e=>ur(e,r)!==null);if(a.length===0)return e;let o=JSON.stringify([a,i]),s=fr.get(e);if(s?.key===o)return s.canvas;let c=new OffscreenCanvas(e.width,e.height),l=c.getContext(`2d`,{colorSpace:`srgb`,willReadFrequently:a.some(e=>e.mode===`pixelate`)});if(!l)throw Error(`The worker has no 2D canvas.`);l.imageSmoothingEnabled=!1,l.drawImage(e,0,0);for(let e of a){let t=ur(e,r);if(e.mode===`solid`)dr(l,t,e.colour);else{let r=nr(e,i),a=await Sr(l,r,n);dr(l,t,`#000000`),a.forEach((e,t)=>{Cr(l,r[t],e)})}}if(n?.aborted)throw c.width=0,n.reason;return fr.set(e,{key:o,canvas:c}),c}async function Sr(e,t,n){let r=[];for(let{x:i,y:a,width:o,height:s}of t){await cr(n);let t=Math.max(1,Math.floor(lr/(o*4))),c=[0,0,0,0];for(let n=0;n<s;n+=t){let{data:r}=e.getImageData(i,a+n,o,Math.min(t,s-n),{colorSpace:`srgb`});for(let e=0;e<r.length;e+=4){let t=r[e+3];c[0]+=r[e]*t,c[1]+=r[e+1]*t,c[2]+=r[e+2]*t,c[3]+=t}}let[l=0,u=0,d=0,f=0]=c;r.push(f>0?[Math.round(l/f),Math.round(u/f),Math.round(d/f),Math.round(f/(o*s))]:[0,0,0,0])}return r}function Cr(e,{x:t,y:n,width:r,height:i},a){let o=Math.max(1,Math.floor(lr/(r*4))),s=e.createImageData(r,Math.min(o,i));for(let e=0;e<s.data.length;e+=4)s.data.set(a,e);for(let a=0;a<i;a+=o)e.putImageData(s,t,n+a,0,0,r,Math.min(o,i-a))}async function wr(e,t,n,r,i){let a=B(t.base.crop,n),{orientation:o}=t.base;for(let n of t.redactions)if(n.mode===`solid`){let t=ar(n,a,o,r);t&&dr(e,t,n.colour)}else{let t=or(n,a,o,r);(await Sr(e,t,i)).forEach((n,r)=>{Cr(e,t[r],n)})}}function Tr(e){return e.some(e=>e.mode===`pixelate`)}var Er=100;function Dr(e,t){let{width:n,height:r,shape:i,fill:a,stroke:o}=t,s=o?Math.min(o.width,n/2,r/2):0;a!==null&&(e.fillStyle=a,i===`rectangle`?e.fillRect(0,0,n,r):(e.beginPath(),e.ellipse(n/2,r/2,n/2,r/2,0,0,Math.PI*2),e.fill())),o!==null&&(e.strokeStyle=o.colour,e.lineWidth=s,e.lineJoin=`miter`,i===`rectangle`?e.strokeRect(s/2,s/2,n-s,r-s):(e.beginPath(),e.ellipse(n/2,r/2,(n-s)/2,(r-s)/2,0,0,Math.PI*2),e.stroke()))}function Or(e,t){if(t.text===``)return;let n=t.text.split(`
|
|
2
|
-
`);e.font=`${t.bold?`bold `:``}${Er}px ${t.font}`;let r=qn(t.text);e.direction=r?`rtl`:`ltr`,e.textAlign=`left`,e.textBaseline=`alphabetic`;let i=e.measureText(`Mg`),a=i.fontBoundingBoxAscent??i.actualBoundingBoxAscent,o=i.fontBoundingBoxDescent??i.actualBoundingBoxDescent,s=Kn(n.map(t=>({width:e.measureText(t).width})),a+o,a,t,t.align,r);s&&(e.fillStyle=t.colour,n.forEach((t,n)=>{let r=s.lines[n];r&&t!==``&&(e.save(),e.translate(r.x,r.baseline),e.scale(s.scale,s.scale),e.fillText(t,0,0),e.restore())}))}async function kr(e,t,n,r,i){let a=r(t.source);if(!a)throw TypeError(`There's no source with the id "${t.source}".`);let o=await yr(a,t,n,i),s=B(t.crop,a);e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(o,s.x,s.y,s.width,s.height,0,0,t.width,t.height)}function Ar(e,t){e.translate(t.x,t.y),e.lineJoin=`round`,e.lineCap=`round`;for(let n of t.strokes){e.strokeStyle=n.colour,e.fillStyle=n.colour,e.lineWidth=n.width,e.beginPath();let t=[],r=NaN,i=NaN;for(let a of n.runs){let n=a[0],o=a[1],s=n===r&&o===i;if(a.length===2)s||t.push(n,o),r=NaN;else{s||e.moveTo(n,o);for(let t=2;t+1<a.length;t+=2)e.lineTo(a[t],a[t+1]);r=a[a.length-2],i=a[a.length-1]}}if(e.stroke(),t.length>0){e.beginPath();for(let r=0;r<t.length;r+=2){let i=t[r],a=t[r+1];e.moveTo(i+n.width/2,a),e.arc(i,a,n.width/2,0,Math.PI*2)}e.fill()}}}function jr(e,t){let n=Rn(t.from,t.to,t.width);e.fillStyle=t.colour,e.beginPath(),n.forEach((t,n)=>{n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)}),e.closePath(),e.fill()}async function Mr(e,t,n,r,i,a){let o=B(t.base.crop,n),s;for(let n of t.layers){if(!n.visible||n.opacity===0)continue;await cr(a);let c=e;if(n.opacity<100){if(!s){let e=new OffscreenCanvas(r.width,r.height).getContext(`2d`,{colorSpace:`srgb`});if(!e)throw Error(`The worker has no 2D canvas.`);s=e}s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,r.width,r.height),c=s}c.save(),n.kind===`drawing`||n.kind===`arrow`?(c.setTransform(...Bn(o,t.base.orientation,r)),n.kind===`drawing`?Ar(c,n):jr(c,n)):(c.setTransform(...Hn(n,o,t.base.orientation,r)),n.kind===`shape`?Dr(c,n):n.kind===`text`?Or(c,n):await kr(c,n,t,i,a)),c.restore(),c!==e&&(e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=n.opacity/100,e.drawImage(c.canvas,0,0),e.restore())}s&&(s.canvas.width=0);let c=new Set(t.layers.map(e=>e.key));for(let e of new Set(t.layers.flatMap(e=>e.kind===`image`?[e.source]:[]))){let t=i(e);t&&br(t,c)}}var Nr=4e6;function Pr(e,t){return ze(e.output,Re(e,t))}async function Fr(e,t,n,r,i=()=>void 0){let{develop:a,filter:o}=t.base,s=Fn(a,o),c=B(t.base.crop,e),l=Re(t,e),u=ze(t.output,l),d=new OffscreenCanvas(u.width,u.height),f=d.getContext(`2d`,{colorSpace:`srgb`,alpha:!n,willReadFrequently:s||Tr(t.redactions)});if(!f)throw Error(`The worker has no 2D canvas.`);n&&(f.fillStyle=`#ffffff`,f.fillRect(0,0,u.width,u.height));let p=u.width/l.width,m=u.height/l.height;f.imageSmoothingEnabled=p!==1||m!==1,f.imageSmoothingQuality=`high`,f.scale(p,m);let{rotate:h,flipX:g,flipY:_}=t.base.orientation;g&&f.transform(-1,0,0,1,l.width,0),_&&f.transform(1,0,0,-1,0,l.height),h===90&&f.transform(0,1,-1,0,l.width,0),h===180&&f.transform(-1,0,0,-1,l.width,l.height),h===270&&f.transform(0,-1,1,0,0,l.height);let v=await xr(e,t,r);if(f.drawImage(v,c.x,c.y,c.width,c.height,0,0,c.width,c.height),f.setTransform(1,0,0,1,0,0),s){let e=Ln(a,o),t=Math.max(1,Math.floor(Nr/(u.width*4)));for(let n=0;n<u.height;n+=t){if(r&&(await sr(),r.aborted))throw r.reason;let i=f.getImageData(0,n,u.width,Math.min(t,u.height-n),{colorSpace:`srgb`});e(i.data),f.putImageData(i,0,n)}}return await Mr(f,t,e,u,i,r),await wr(f,t,e,u,r),d}var Ir={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`};async function Lr(e,t,n,r,i){let a=Ir[n.type],o=await Fr(e,t,n.type===`jpeg`,r,i),s=await o.convertToBlob({type:a,...n.type===`png`?{}:{quality:n.quality??.92}});if(o.width=0,o.height=0,r?.aborted)throw r.reason;if(s.type!==a)throw new w(`UNSUPPORTED_FORMAT`,`This browser can't encode the requested format.`,{details:{format:n.type}});let c=new Uint8Array(await s.arrayBuffer()),l=n.type===`jpeg`?ln(c,t.metadata):n.type===`png`?mn(c,t.metadata):hn(c);return new Blob([l.slice()],{type:a})}async function Rr(e,t,n,r,i,a){let o=Re(n,t),{width:s,height:c}=ue(r),l=Math.min(r.pixelRatio,4),u=de(o,r),d=u.scale*l,f=Math.min(1,d),p=await Fr(t,{...n,output:{kind:`scale`,scale:f}},!1,i,a);if(i?.aborted)throw p.width=0,i.reason;let{canvas:m}=e;(m.width!==s||m.height!==c)&&(m.width=s,m.height=c),e.clearRect(0,0,s,c),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(p,u.x*l,u.y*l,u.width*l,u.height*l),p.width=0}function zr(e,t,n={}){let r=ye(e,t),i=t.frames.length,a=t.width*t.height*4,o=t.frames.some(e=>e.disposal===3),s=Math.floor((n.cacheBytes??67108864)/(a*(o?2:1))),c=s<=0?0:Math.ceil(i/s),l=/* @__PURE__ */ new Map,u=0,d=0,f=e=>{if(c===0||e%c!==0||l.has(e))return;let t=r.snapshot();l.set(e,t),u+=t.screen.byteLength+(t.saved?.byteLength??0)};return{frames:i,spacing:c,ceiling:c===0?0:Math.ceil(i/c)*a*(o?2:1),get cached(){return u},get decoded(){return d},frame(e){if(!Number.isInteger(e)||e<0||e>=i)throw RangeError(`The GIF has no frame ${e}.`);if(r.shown!==e){let t=r.shown<=e?r.shown:-1,n=c===0?-1:e-e%c,i=n>t?l.get(n):void 0;for(i?r.restore(i):r.shown>e&&r.reset();r.shown<e;)r.next(),d+=1,f(r.shown)}return r.screen}}}var Br=12;function Vr(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(0)})}async function Hr(e,t,n){let{signal:r,progress:i,pause:a=Vr,now:o=()=>performance.now()}=n,s=zr(e,t),c=t.frames.length,l=0,u=o();for(;l<c;){if(r.aborted)throw r.reason;try{s.frame(l)}catch(e){if(l===0||!T(e,`INVALID_IMAGE`))throw e;break}l+=1,i?.(l,c,s.frame(l-1)),l<c&&o()-u>=Br&&(await a(),u=o())}if(r.aborted)throw r.reason;let d=t.width*t.height*4;return{store:s,width:t.width,height:t.height,frames:l,incomplete:!t.complete||l<c,loop:t.loop,delays:t.frames.slice(0,l).map(e=>e.delay),bytes:e.byteLength+d+s.ceiling}}function Ur(e,t){return e.format===t.format&&e.orientation===t.orientation&&e.frames===t.frames&&e.decodedPixelBound===t.decodedPixelBound&&e.stored.width===t.stored.width&&e.stored.height===t.stored.height&&e.oriented.width===t.oriented.width&&e.oriented.height===t.oriented.height}var Wr=[`layers`,`drawings`,`redactions`],Gr=[...Wr,`animation`];function Kr(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=async(e,r)=>{let i=n.get(e.base.source);fe(e,i?Gr:Wr);let a=t.get(e.base.source);if(!a)throw TypeError(`There's no source with the id "${e.base.source}".`);let o=e.animation?.frames[r];if(!i||e.animation===null)return{bitmap:a,own:!1};if(!o||!Number.isInteger(o.frame)||o.frame<0||o.frame>=i.frames)throw new w(`UNSUPPORTED_PLAN`,`The plan shows a frame its source doesn't hold.`,{details:{reason:`animation`}});if(o.frame===0)return{bitmap:a,own:!1};let{width:s,height:c}=i;return{bitmap:await en(new Uint8ClampedArray(i.store.frame(o.frame)),s,c),own:!0}},i=e=>{e.own&&(mr(e.bitmap),e.bitmap.close())},a=/* @__PURE__ */ new Map,o=(e,n,r)=>{k(e,r);for(let r of n.layers){let n=r.kind===`image`?t.get(r.source):void 0;n&&k(e,n)}};le({probe:({file:e})=>Ot(s(e)),async register({id:e,file:r,probe:i,limits:a,frames:o,animationPixels:c},{signal:l,progress:u}){if(t.has(e))throw TypeError(`The source id "${e}" is already in use.`);let d=await Ot(s(r));if(!Ur(d,i))throw new w(`INVALID_IMAGE`,`The probe doesn't describe this file.`,{details:{format:d.format,problem:`the probe describes another file`}});let f=o===`all`&&d.format===`gif`&&d.frames>1;if(O(E.resolve(a),r.size,d,f?`all`:`first`),f){E.resolve({maxAnimationPixels:c}).check(`maxAnimationPixels`,d.oriented.width*d.oriented.height);let{bytes:i,gif:a}=await tn(r,d),o,s=()=>{o?.then(n=>{t.get(e)===n&&t.delete(e),n.close()})},f;try{f=await Hr(i,a,{signal:l,progress:(n,r,i)=>{u({done:n,total:r}),n===1&&(o=en(new Uint8ClampedArray(i),a.width,a.height).then(i=>(l.aborted||(t.set(e,i),u({done:n,total:r,firstFrame:!0})),i)))}})}catch(e){throw s(),e}let p=await(o??en(new Uint8ClampedArray(f.store.frame(0)),a.width,a.height));if(l.aborted)throw t.get(e)===p&&t.delete(e),p.close(),l.reason;return t.set(e,p),n.set(e,f),{width:p.width,height:p.height,frames:f.frames,timing:{loop:f.loop,delays:f.delays},incomplete:f.incomplete,bytes:p.width*p.height*4+f.bytes}}let p=await an(r,d);if(l.aborted)throw p.close(),l.reason;return t.set(e,p),{width:p.width,height:p.height,frames:1,timing:null,incomplete:!1,bytes:p.width*p.height*4}},thumbnail({id:e,maxSize:n}){let r=t.get(e);if(!r)throw TypeError(`There's no source with the id "${e}".`);let i=Math.min(1,n/r.width,n/r.height);return createImageBitmap(r,{resizeWidth:Math.max(1,Math.round(r.width*i)),resizeHeight:Math.max(1,Math.round(r.height*i)),resizeQuality:`high`})},async export({plan:e,format:n,frame:a,limits:s},{signal:c}){if(n.type===`gif`)throw TypeError(`A GIF is exported frame by frame.`);let l=await r(e,a);try{let r=l.bitmap,i=E.resolve(s);return k(i,Pr(e,r)),e.redactions.length>0&&o(i,e,r),await Lr(r,e,n,c,e=>t.get(e))}finally{i(l)}},async frame({plan:e,frame:n,count:a,limits:s},{signal:c}){let l=await r(e,n);try{let n=l.bitmap,r=E.resolve(s),i=Pr(e,n);k(r,i),r.check(`maxDecodedSize`,a*i.width*i.height*4),e.redactions.length>0&&o(r,e,n);let u=await Fr(n,e,!1,c,e=>t.get(e)),d=u.getContext(`2d`,{colorSpace:`srgb`});if(!d)throw Error(`The worker has no 2D canvas.`);let{data:f}=d.getImageData(0,0,u.width,u.height,{colorSpace:`srgb`});if(u.width=0,u.height=0,c.aborted)throw c.reason;return{width:i.width,height:i.height,pixels:f.buffer}}finally{i(l)}},attachCanvas({id:e,canvas:t}){let n=t.getContext(`2d`,{colorSpace:`srgb`});if(!n)throw Error(`The worker has no 2D canvas.`);a.set(e,n)},async render({id:e,plan:s,view:c,frame:l,limits:u},{signal:d}){fe(s,n.has(s.base.source)?Gr:Wr),k(E.resolve(u),ue(c));let f=a.get(e);if(!f)throw TypeError(`There's no canvas with the id "${e}".`);let p=await r(s,l);try{let e=p.bitmap;s.redactions.length>0&&o(E.resolve(u),s,e),await Rr(f,e,s,c,d,e=>t.get(e))}finally{i(p)}},detachCanvas({id:e}){let t=a.get(e);t&&(t.canvas.width=0,t.canvas.height=0),a.delete(e)},snapshot({id:e}){let t=a.get(e);if(!t)throw TypeError(`There's no canvas with the id "${e}".`);return createImageBitmap(t.canvas)},release({id:e}){let r=t.get(e);r&&mr(r),r?.close(),t.delete(e),n.delete(e)}},{...e,packageVersion:`0.7.1`})}Kr();
|
|
2
|
+
`);e.font=`${t.bold?`bold `:``}${Er}px ${t.font}`;let r=qn(t.text);e.direction=r?`rtl`:`ltr`,e.textAlign=`left`,e.textBaseline=`alphabetic`;let i=e.measureText(`Mg`),a=i.fontBoundingBoxAscent??i.actualBoundingBoxAscent,o=i.fontBoundingBoxDescent??i.actualBoundingBoxDescent,s=Kn(n.map(t=>({width:e.measureText(t).width})),a+o,a,t,t.align,r);s&&(e.fillStyle=t.colour,n.forEach((t,n)=>{let r=s.lines[n];r&&t!==``&&(e.save(),e.translate(r.x,r.baseline),e.scale(s.scale,s.scale),e.fillText(t,0,0),e.restore())}))}async function kr(e,t,n,r,i){let a=r(t.source);if(!a)throw TypeError(`There's no source with the id "${t.source}".`);let o=await yr(a,t,n,i),s=B(t.crop,a);e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(o,s.x,s.y,s.width,s.height,0,0,t.width,t.height)}function Ar(e,t){e.translate(t.x,t.y),e.lineJoin=`round`,e.lineCap=`round`;for(let n of t.strokes){e.strokeStyle=n.colour,e.fillStyle=n.colour,e.lineWidth=n.width,e.beginPath();let t=[],r=NaN,i=NaN;for(let a of n.runs){let n=a[0],o=a[1],s=n===r&&o===i;if(a.length===2)s||t.push(n,o),r=NaN;else{s||e.moveTo(n,o);for(let t=2;t+1<a.length;t+=2)e.lineTo(a[t],a[t+1]);r=a[a.length-2],i=a[a.length-1]}}if(e.stroke(),t.length>0){e.beginPath();for(let r=0;r<t.length;r+=2){let i=t[r],a=t[r+1];e.moveTo(i+n.width/2,a),e.arc(i,a,n.width/2,0,Math.PI*2)}e.fill()}}}function jr(e,t){let n=Rn(t.from,t.to,t.width);e.fillStyle=t.colour,e.beginPath(),n.forEach((t,n)=>{n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)}),e.closePath(),e.fill()}async function Mr(e,t,n,r,i,a){let o=B(t.base.crop,n),s;for(let n of t.layers){if(!n.visible||n.opacity===0)continue;await cr(a);let c=e;if(n.opacity<100){if(!s){let e=new OffscreenCanvas(r.width,r.height).getContext(`2d`,{colorSpace:`srgb`});if(!e)throw Error(`The worker has no 2D canvas.`);s=e}s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,r.width,r.height),c=s}c.save(),n.kind===`drawing`||n.kind===`arrow`?(c.setTransform(...Bn(o,t.base.orientation,r)),n.kind===`drawing`?Ar(c,n):jr(c,n)):(c.setTransform(...Hn(n,o,t.base.orientation,r)),n.kind===`shape`?Dr(c,n):n.kind===`text`?Or(c,n):await kr(c,n,t,i,a)),c.restore(),c!==e&&(e.save(),e.setTransform(1,0,0,1,0,0),e.globalAlpha=n.opacity/100,e.drawImage(c.canvas,0,0),e.restore())}s&&(s.canvas.width=0);let c=new Set(t.layers.map(e=>e.key));for(let e of new Set(t.layers.flatMap(e=>e.kind===`image`?[e.source]:[]))){let t=i(e);t&&br(t,c)}}var Nr=4e6;function Pr(e,t){return ze(e.output,Re(e,t))}async function Fr(e,t,n,r,i=()=>void 0){let{develop:a,filter:o}=t.base,s=Fn(a,o),c=B(t.base.crop,e),l=Re(t,e),u=ze(t.output,l),d=new OffscreenCanvas(u.width,u.height),f=d.getContext(`2d`,{colorSpace:`srgb`,alpha:!n,willReadFrequently:s||Tr(t.redactions)});if(!f)throw Error(`The worker has no 2D canvas.`);n&&(f.fillStyle=`#ffffff`,f.fillRect(0,0,u.width,u.height));let p=u.width/l.width,m=u.height/l.height;f.imageSmoothingEnabled=p!==1||m!==1,f.imageSmoothingQuality=`high`,f.scale(p,m);let{rotate:h,flipX:g,flipY:_}=t.base.orientation;g&&f.transform(-1,0,0,1,l.width,0),_&&f.transform(1,0,0,-1,0,l.height),h===90&&f.transform(0,1,-1,0,l.width,0),h===180&&f.transform(-1,0,0,-1,l.width,l.height),h===270&&f.transform(0,-1,1,0,0,l.height);let v=await xr(e,t,r);if(f.drawImage(v,c.x,c.y,c.width,c.height,0,0,c.width,c.height),f.setTransform(1,0,0,1,0,0),s){let e=Ln(a,o),t=Math.max(1,Math.floor(Nr/(u.width*4)));for(let n=0;n<u.height;n+=t){if(r&&(await sr(),r.aborted))throw r.reason;let i=f.getImageData(0,n,u.width,Math.min(t,u.height-n),{colorSpace:`srgb`});e(i.data),f.putImageData(i,0,n)}}return await Mr(f,t,e,u,i,r),await wr(f,t,e,u,r),d}var Ir={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`};async function Lr(e,t,n,r,i){let a=Ir[n.type],o=await Fr(e,t,n.type===`jpeg`,r,i),s=await o.convertToBlob({type:a,...n.type===`png`?{}:{quality:n.quality??.92}});if(o.width=0,o.height=0,r?.aborted)throw r.reason;if(s.type!==a)throw new w(`UNSUPPORTED_FORMAT`,`This browser can't encode the requested format.`,{details:{format:n.type}});let c=new Uint8Array(await s.arrayBuffer()),l=n.type===`jpeg`?ln(c,t.metadata):n.type===`png`?mn(c,t.metadata):hn(c);return new Blob([l.slice()],{type:a})}async function Rr(e,t,n,r,i,a){let o=Re(n,t),{width:s,height:c}=ue(r),l=Math.min(r.pixelRatio,4),u=de(o,r),d=u.scale*l,f=Math.min(1,d),p=await Fr(t,{...n,output:{kind:`scale`,scale:f}},!1,i,a);if(i?.aborted)throw p.width=0,i.reason;let{canvas:m}=e;(m.width!==s||m.height!==c)&&(m.width=s,m.height=c),e.clearRect(0,0,s,c),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.drawImage(p,u.x*l,u.y*l,u.width*l,u.height*l),p.width=0}function zr(e,t,n={}){let r=ye(e,t),i=t.frames.length,a=t.width*t.height*4,o=t.frames.some(e=>e.disposal===3),s=Math.floor((n.cacheBytes??67108864)/(a*(o?2:1))),c=s<=0?0:Math.ceil(i/s),l=/* @__PURE__ */ new Map,u=0,d=0,f=e=>{if(c===0||e%c!==0||l.has(e))return;let t=r.snapshot();l.set(e,t),u+=t.screen.byteLength+(t.saved?.byteLength??0)};return{frames:i,spacing:c,ceiling:c===0?0:Math.ceil(i/c)*a*(o?2:1),get cached(){return u},get decoded(){return d},frame(e){if(!Number.isInteger(e)||e<0||e>=i)throw RangeError(`The GIF has no frame ${e}.`);if(r.shown!==e){let t=r.shown<=e?r.shown:-1,n=c===0?-1:e-e%c,i=n>t?l.get(n):void 0;for(i?r.restore(i):r.shown>e&&r.reset();r.shown<e;)r.next(),d+=1,f(r.shown)}return r.screen}}}var Br=12;function Vr(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(0)})}async function Hr(e,t,n){let{signal:r,progress:i,pause:a=Vr,now:o=()=>performance.now()}=n,s=zr(e,t),c=t.frames.length,l=0,u=o();for(;l<c;){if(r.aborted)throw r.reason;try{s.frame(l)}catch(e){if(l===0||!T(e,`INVALID_IMAGE`))throw e;break}l+=1,i?.(l,c,s.frame(l-1)),l<c&&o()-u>=Br&&(await a(),u=o())}if(r.aborted)throw r.reason;let d=t.width*t.height*4;return{store:s,width:t.width,height:t.height,frames:l,incomplete:!t.complete||l<c,loop:t.loop,delays:t.frames.slice(0,l).map(e=>e.delay),bytes:e.byteLength+d+s.ceiling}}function Ur(e,t){return e.format===t.format&&e.orientation===t.orientation&&e.frames===t.frames&&e.decodedPixelBound===t.decodedPixelBound&&e.stored.width===t.stored.width&&e.stored.height===t.stored.height&&e.oriented.width===t.oriented.width&&e.oriented.height===t.oriented.height}var Wr=[`layers`,`drawings`,`redactions`],Gr=[...Wr,`animation`];function Kr(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=async(e,r)=>{let i=n.get(e.base.source);fe(e,i?Gr:Wr);let a=t.get(e.base.source);if(!a)throw TypeError(`There's no source with the id "${e.base.source}".`);let o=e.animation?.frames[r];if(!i||e.animation===null)return{bitmap:a,own:!1};if(!o||!Number.isInteger(o.frame)||o.frame<0||o.frame>=i.frames)throw new w(`UNSUPPORTED_PLAN`,`The plan shows a frame its source doesn't hold.`,{details:{reason:`animation`}});if(o.frame===0)return{bitmap:a,own:!1};let{width:s,height:c}=i;return{bitmap:await en(new Uint8ClampedArray(i.store.frame(o.frame)),s,c),own:!0}},i=e=>{e.own&&(mr(e.bitmap),e.bitmap.close())},a=/* @__PURE__ */ new Map,o=(e,n,r)=>{k(e,r);for(let r of n.layers){let n=r.kind===`image`?t.get(r.source):void 0;n&&k(e,n)}};le({probe:({file:e})=>Ot(s(e)),async register({id:e,file:r,probe:i,limits:a,frames:o,animationPixels:c},{signal:l,progress:u}){if(t.has(e))throw TypeError(`The source id "${e}" is already in use.`);let d=await Ot(s(r));if(!Ur(d,i))throw new w(`INVALID_IMAGE`,`The probe doesn't describe this file.`,{details:{format:d.format,problem:`the probe describes another file`}});let f=o===`all`&&d.format===`gif`&&d.frames>1;if(O(E.resolve(a),r.size,d,f?`all`:`first`),f){E.resolve({maxAnimationPixels:c}).check(`maxAnimationPixels`,d.oriented.width*d.oriented.height);let{bytes:i,gif:a}=await tn(r,d),o,s=()=>{o?.then(n=>{t.get(e)===n&&t.delete(e),n.close()})},f;try{f=await Hr(i,a,{signal:l,progress:(n,r,i)=>{u({done:n,total:r}),n===1&&(o=en(new Uint8ClampedArray(i),a.width,a.height).then(i=>(l.aborted||(t.set(e,i),u({done:n,total:r,firstFrame:!0})),i)))}})}catch(e){throw s(),e}let p=await(o??en(new Uint8ClampedArray(f.store.frame(0)),a.width,a.height));if(l.aborted)throw t.get(e)===p&&t.delete(e),p.close(),l.reason;return t.set(e,p),n.set(e,f),{width:p.width,height:p.height,frames:f.frames,timing:{loop:f.loop,delays:f.delays},incomplete:f.incomplete,bytes:p.width*p.height*4+f.bytes}}let p=await an(r,d);if(l.aborted)throw p.close(),l.reason;return t.set(e,p),{width:p.width,height:p.height,frames:1,timing:null,incomplete:!1,bytes:p.width*p.height*4}},thumbnail({id:e,maxSize:n}){let r=t.get(e);if(!r)throw TypeError(`There's no source with the id "${e}".`);let i=Math.min(1,n/r.width,n/r.height);return createImageBitmap(r,{resizeWidth:Math.max(1,Math.round(r.width*i)),resizeHeight:Math.max(1,Math.round(r.height*i)),resizeQuality:`high`})},async export({plan:e,format:n,frame:a,limits:s},{signal:c}){if(n.type===`gif`)throw TypeError(`A GIF is exported frame by frame.`);let l=await r(e,a);try{let r=l.bitmap,i=E.resolve(s);return k(i,Pr(e,r)),e.redactions.length>0&&o(i,e,r),await Lr(r,e,n,c,e=>t.get(e))}finally{i(l)}},async frame({plan:e,frame:n,count:a,limits:s},{signal:c}){let l=await r(e,n);try{let n=l.bitmap,r=E.resolve(s),i=Pr(e,n);k(r,i),r.check(`maxDecodedSize`,a*i.width*i.height*4),e.redactions.length>0&&o(r,e,n);let u=await Fr(n,e,!1,c,e=>t.get(e)),d=u.getContext(`2d`,{colorSpace:`srgb`});if(!d)throw Error(`The worker has no 2D canvas.`);let{data:f}=d.getImageData(0,0,u.width,u.height,{colorSpace:`srgb`});if(u.width=0,u.height=0,c.aborted)throw c.reason;return{width:i.width,height:i.height,pixels:f.buffer}}finally{i(l)}},attachCanvas({id:e,canvas:t}){let n=t.getContext(`2d`,{colorSpace:`srgb`});if(!n)throw Error(`The worker has no 2D canvas.`);a.set(e,n)},async render({id:e,plan:s,view:c,frame:l,limits:u},{signal:d}){fe(s,n.has(s.base.source)?Gr:Wr),k(E.resolve(u),ue(c));let f=a.get(e);if(!f)throw TypeError(`There's no canvas with the id "${e}".`);let p=await r(s,l);try{let e=p.bitmap;s.redactions.length>0&&o(E.resolve(u),s,e),await Rr(f,e,s,c,d,e=>t.get(e))}finally{i(p)}},detachCanvas({id:e}){let t=a.get(e);t&&(t.canvas.width=0,t.canvas.height=0),a.delete(e)},snapshot({id:e}){let t=a.get(e);if(!t)throw TypeError(`There's no canvas with the id "${e}".`);return createImageBitmap(t.canvas)},release({id:e}){let r=t.get(e);r&&mr(r),r?.close(),t.delete(e),n.delete(e)}},{...e,packageVersion:`0.7.3`})}Kr();
|
package/dist/element.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { qt as ImageError } from "./shared/core-
|
|
2
|
-
import { d as imageEditorMessages, p as ExportListenerContext, t as ImageEditor } from "./shared/editor-
|
|
1
|
+
import { qt as ImageError } from "./shared/core-BiKXMhuI.js";
|
|
2
|
+
import { d as imageEditorMessages, p as ExportListenerContext, t as ImageEditor } from "./shared/editor-BLQCHS3B.js";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { createEditorElement } from "@hussmartinez/sdk-core/element";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as checkCrop, A as dragHandle, At as createImageRenderer, B as outputSize, Bt as PER_FILE_LIMITS, C as drawingBounds, Ct as MAX_SCENE_COORDINATE, D as aspectRatio, Dt as REDACTION_MODES, E as ASPECT_PRESETS, Et as NEUTRAL_DEVELOP, Ft as createImageProcessor, G as checkOrientation, Gt as imageLimits, H as checkDevelop, Ht as checkFileLimits, I as compositionSize, It as createImageEngine, Jt as isImageError, K as checkOutput, L as compositionToSource, M as handleInSource, Mt as backingSize, N as moveCrop, Nt as fittedView, O as compositionDeltaToSource, Ot as UPRIGHT, P as nudgeCropOnScreen, Pt as placement, Q as Invalid, R as cropRect, Rt as ANIMATION_LIMITS, S as arrowOutline, St as MAX_RUN_POINTS, T as simplifyStroke, Tt as MAX_STROKE_WIDTH, U as checkFilter, Ut as checkOutputLimits, V as sourceToComposition, Vt as animationLimits, W as checkMetadata, Wt as imageLimitDefinitions, X as checkRedaction, Y as checkLayer, Z as checkAnimation, _ as layerToScene, _t as MAX_FRAME_DELAY, a as compositionRectToScene, at as MAX_METADATA_LENGTH, b as createImageKey, bt as MAX_LAYER_TEXT_LENGTH, c as redactionBlocksInOutput, ct as DEVELOP_ADJUSTMENTS, d as sceneRectToComposition, dt as LAYER_ALIGNMENTS, et as checkCropInSource, f as applyMatrix, ft as LAYER_FONTS, g as layerToOutput, gt as MAX_DRAWING_STROKES, h as isRightToLeft, ht as MAX_ANIMATION_FRAMES, it as EMPTY_KEEPABLE_METADATA, j as fitAspect, jt as MAX_PIXEL_RATIO, k as cropInComposition, kt as createPlan, l as redactionBlocksInScene, lt as FILTER_PRESETS, m as invertMatrix, mt as LAYER_SHAPES, n as createImageSession, nt as isRecord, o as fitRedactionRegion, ot as NO_METADATA, p as fitTextLines, pt as LAYER_KINDS, q as createImageReducer, qt as ImageError, rt as onlyFields, s as redactionBlockSize, t as imageMessages, tt as invalid, u as redactionRectInOutput, ut as FULL_SIZE, v as sceneToLayerSource, vt as MAX_KEY_LENGTH, w as drawingPoints, wt as MAX_STROKE_RUNS, x as arrowBounds, xt as MAX_PLAN_ITEMS, y as sceneToOutput, yt as MAX_LAYER_NAME_LENGTH, z as orientedSize, zt as OUTPUT_LIMITS } from "./shared/core-
|
|
1
|
+
import { $ as checkCrop, A as dragHandle, At as createImageRenderer, B as outputSize, Bt as PER_FILE_LIMITS, C as drawingBounds, Ct as MAX_SCENE_COORDINATE, D as aspectRatio, Dt as REDACTION_MODES, E as ASPECT_PRESETS, Et as NEUTRAL_DEVELOP, Ft as createImageProcessor, G as checkOrientation, Gt as imageLimits, H as checkDevelop, Ht as checkFileLimits, I as compositionSize, It as createImageEngine, Jt as isImageError, K as checkOutput, L as compositionToSource, M as handleInSource, Mt as backingSize, N as moveCrop, Nt as fittedView, O as compositionDeltaToSource, Ot as UPRIGHT, P as nudgeCropOnScreen, Pt as placement, Q as Invalid, R as cropRect, Rt as ANIMATION_LIMITS, S as arrowOutline, St as MAX_RUN_POINTS, T as simplifyStroke, Tt as MAX_STROKE_WIDTH, U as checkFilter, Ut as checkOutputLimits, V as sourceToComposition, Vt as animationLimits, W as checkMetadata, Wt as imageLimitDefinitions, X as checkRedaction, Y as checkLayer, Z as checkAnimation, _ as layerToScene, _t as MAX_FRAME_DELAY, a as compositionRectToScene, at as MAX_METADATA_LENGTH, b as createImageKey, bt as MAX_LAYER_TEXT_LENGTH, c as redactionBlocksInOutput, ct as DEVELOP_ADJUSTMENTS, d as sceneRectToComposition, dt as LAYER_ALIGNMENTS, et as checkCropInSource, f as applyMatrix, ft as LAYER_FONTS, g as layerToOutput, gt as MAX_DRAWING_STROKES, h as isRightToLeft, ht as MAX_ANIMATION_FRAMES, it as EMPTY_KEEPABLE_METADATA, j as fitAspect, jt as MAX_PIXEL_RATIO, k as cropInComposition, kt as createPlan, l as redactionBlocksInScene, lt as FILTER_PRESETS, m as invertMatrix, mt as LAYER_SHAPES, n as createImageSession, nt as isRecord, o as fitRedactionRegion, ot as NO_METADATA, p as fitTextLines, pt as LAYER_KINDS, q as createImageReducer, qt as ImageError, rt as onlyFields, s as redactionBlockSize, t as imageMessages, tt as invalid, u as redactionRectInOutput, ut as FULL_SIZE, v as sceneToLayerSource, vt as MAX_KEY_LENGTH, w as drawingPoints, wt as MAX_STROKE_RUNS, x as arrowBounds, xt as MAX_PLAN_ITEMS, y as sceneToOutput, yt as MAX_LAYER_NAME_LENGTH, z as orientedSize, zt as OUTPUT_LIMITS } from "./shared/core-BiKXMhuI.js";
|
|
2
2
|
// src/core/format/plan-document.ts
|
|
3
3
|
var IMAGE_PLAN_FORMAT = "hm-image-plan";
|
|
4
4
|
var IMAGE_PLAN_VERSION = 4;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/workers/job.worker.ts?worker&inline
|
|
2
|
-
var jsContent = "var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);function t(){try{return process.env.NODE_ENV!==`production`}catch{return!1}}function n(e){t()&&console.warn(`[@hussmartinez/sdk-core] ${e}`)}var r=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core`),i={},a=!1;function o(){return`0.4.4`}function s(){if(!a&&(a=!0,typeof process<`u`&&process.env.NODE_ENV!==`production`)){let e=globalThis,t=e[r]??/* @__PURE__ */ new Map;e[r]=t,t.set(i,o()),t.size>1&&n(`${t.size} copies of @hussmartinez/sdk-core are in use (${[...t.values()].join(`, `)}). \\`instanceof SdkError\\` fails for errors from another copy, so use \\`isSdkError\\`, and each copy keeps its own caches. Install a single version: \\`npm ls @hussmartinez/sdk-core\\` shows where each comes from, and every SDK, \\`@hussmartinez/ui\\` and your application should use the same minor version.`)}}var c=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),l=class extends Error{name=`SdkError`;code;constructor(e,t,n={}){super(t,`cause`in n?{cause:n.cause}:void 0),s(),this.code=e,Object.defineProperty(this,c,{value:!0}),n.details!==void 0&&(this.details=n.details)}};function u(e,t){if(typeof e!=`object`||!e)return!1;let n=e;return(e instanceof l||n[c]===!0)&&typeof n.code==`string`&&typeof n.message==`string`&&(t===void 0||n.code===t)}var d=8,f=16,p=`UNKNOWN`;function m(e,t={}){let n=t.includeStack??!1,r=b(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=h(e),s=n&&v(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),v(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function h(e){if(u(e)){let t={name:e.name,code:e.code,message:e.message},n=g(e.details);return n!==void 0&&(t.details=n),t}if(v(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:p,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:p,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:p,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function g(e){if(!y(e))return;let t=_(e,0);return y(t)?t:void 0}function _(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=f)){if(Array.isArray(e))return e.flatMap(e=>{let n=_(e,t+1);return n===void 0?[]:[n]});if(y(e)){let n={};for(let[r,i]of Object.entries(e)){let e=_(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function v(e){return typeof e==`object`&&!!e}function y(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function b(e){if(e===void 0)return d;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var x=`hm-rpc`;function S(e){return{protocol:x,version:1,...e}}function C(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function w(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=E(e)?e:D(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return k(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):A(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),j(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function T(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function E(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function D(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var O=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function k(e){let t=globalThis;return O.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function A(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function j(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function M(e,t={}){let n=t.scope??globalThis,r=t.includeStack??!1,i=/* @__PURE__ */ new Map,a=(e,t=[])=>{n.postMessage(e,t)},o=(e,t)=>{a(S({type:`error`,id:e,error:m(t,{includeStack:r})}))},s=(e,t,r)=>{let i=w(r,!0);try{T((e,t)=>n.postMessage(e,t),S({type:`result`,id:e,output:i.value}),i.transferables)}catch(n){o(e,new l(`WORKER_DATA_NOT_CLONEABLE`,`The result of \"${t}\" can't be sent to the page.`,{cause:n,details:{method:t}}))}},c=t=>{let{id:n,method:r}=t,c=Object.hasOwn(e,r)?e[r]:void 0;if(typeof c!=`function`){o(n,new l(`WORKER_METHOD_NOT_FOUND`,`The worker has no method \"${r}\".`,{details:{method:r}}));return}let u=new AbortController;i.set(n,u);let d={signal:u.signal,progress:e=>{i.get(n)===u&&a(S({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>c.call(e,t.input,d)).then(e=>{i.delete(n),s(n,r,e)},e=>{i.delete(n),o(n,e)})},u=e=>{a(S({type:`crash`,error:m(e,{includeStack:r})}))};n.addEventListener(`message`,e=>{let t=C(e.data);t!==void 0&&t.version===1&&(t.type===`call`?c(t):t.type===`cancel`&&i.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;u(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{u(e.reason)}),a(S({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var N=(/* @__PURE__ */ e((e=>{var t=Object.defineProperty;(e=>t(e,`__esModule`,{value:!0}))(e),((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(e,{GIFEncoder:()=>A,applyPalette:()=>S,default:()=>B,nearestColor:()=>k,nearestColorIndex:()=>D,nearestColorIndexWithDistance:()=>O,prequantize:()=>x,quantize:()=>_,snapColorsToPalette:()=>T});var n={signature:`GIF`,version:`89a`,trailer:59,extensionIntroducer:33,applicationExtensionLabel:255,graphicControlExtensionLabel:249,imageSeparator:44,signatureSize:3,versionSize:3,globalColorTableFlagMask:128,colorResolutionMask:112,sortFlagMask:8,globalColorTableSizeMask:7,applicationIdentifierSize:8,applicationAuthCodeSize:3,disposalMethodMask:28,userInputFlagMask:2,transparentColorFlagMask:1,localColorTableFlagMask:128,interlaceFlagMask:64,idSortFlagMask:32,localColorTableSizeMask:7};function r(e=256){let t=0,n=new Uint8Array(e);return{get buffer(){return n.buffer},reset(){t=0},bytesView(){return n.subarray(0,t)},bytes(){return n.slice(0,t)},writeByte(e){r(t+1),n[t]=e,t++},writeBytes(e,i=0,a=e.length){r(t+a);for(let r=0;r<a;r++)n[t++]=e[r+i]},writeBytesView(e,i=0,a=e.byteLength){r(t+a),n.set(e.subarray(i,i+a),t),t+=a}};function r(e){var r=n.length;if(r>=e)return;e=Math.max(e,r*(r<1048576?2:1.125)>>>0),r!=0&&(e=Math.max(e,256));let i=n;n=new Uint8Array(e),t>0&&n.set(i.subarray(0,t),0)}}var i=12,a=5003,o=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function s(e,t,n,s,c=r(512),l=/* @__PURE__ */ new Uint8Array(256),u=new Int32Array(a),d=new Int32Array(a)){let f=u.length,p=Math.max(2,s);l.fill(0),d.fill(0),u.fill(-1);let m=0,h=0,g=p+1,_=g,v=!1,y=_,b=(1<<y)-1,x=1<<g-1,S=x+1,C=x+2,w=0,T=n[0],E=0;for(let e=f;e<65536;e*=2)++E;E=8-E,c.writeByte(p),O(x);let D=n.length;for(let e=1;e<D;e++)next_block:{let t=n[e],r=(t<<i)+T,a=t<<E^T;if(u[a]===r){T=d[a];break next_block}let o=a===0?1:f-a;for(;u[a]>=0;)if(a-=o,a<0&&(a+=f),u[a]===r){T=d[a];break next_block}O(T),T=t,C<1<<i?(d[a]=C++,u[a]=r):(u.fill(-1),C=x+2,v=!0,O(x))}return O(T),O(S),c.writeByte(0),c.bytesView();function O(e){for(m&=o[h],h>0?m|=e<<h:m=e,h+=y;h>=8;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;if((C>b||v)&&(v?(y=_,b=(1<<y)-1,v=!1):(++y,b=y===i?1<<y:(1<<y)-1)),e==S){for(;h>0;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;w>0&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0)}}}var c=s;function l(e,t,n){return e<<8&63488|t<<2&992|n>>3}function u(e,t,n,r){return e>>4|t&240|(n&240)<<4|(r&240)<<8}function d(e,t,n){return e>>4<<8|t&240|n>>4}function f(e,t,n){return e<t?t:e>n?n:e}function p(e){return e*e}function m(e,t,n){var r=0,i=1e100;let a=e[t],o=a.cnt,s=a.ac,c=a.rc,l=a.gc,u=a.bc;for(var d=a.fw;d!=0;d=e[d].fw){let t=e[d],a=t.cnt,m=o*a/(o+a);if(!(m>=i)){var f=0;n&&(f+=m*p(t.ac-s),f>=i)||(f+=m*p(t.rc-c),f>=i||(f+=m*p(t.gc-l),f>=i||(f+=m*p(t.bc-u),f>=i||(i=f,r=d))))}}a.err=i,a.nn=r}function h(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function g(e,t){let n=Array(t===`rgb444`?4096:65536),r=e.length;if(t===`rgba4444`)for(let t=0;t<r;++t){let r=e[t],i=r>>24&255,a=r>>16&255,o=r>>8&255,s=r&255,c=u(s,o,a,i),l=c in n?n[c]:n[c]=h();l.rc+=s,l.gc+=o,l.bc+=a,l.ac+=i,l.cnt++}else if(t===`rgb444`)for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=d(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}else for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=l(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}return n}function _(e,t,n={}){let{format:r=`rgb565`,clearAlpha:i=!0,clearAlphaColor:a=0,clearAlphaThreshold:o=0,oneBitAlpha:s=!1}=n;if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);let c=new Uint32Array(e.buffer),l=n.useSqrt!==!1,u=r===`rgba4444`,d=g(c,r),h=d.length,_=h-1,y=new Uint32Array(h+1);for(var b=0,x=0;x<h;++x){let e=d[x];if(e!=null){var S=1/e.cnt;u&&(e.ac*=S),e.rc*=S,e.gc*=S,e.bc*=S,d[b++]=e}}p(t)/b<.022&&(l=!1);for(var x=0;x<b-1;++x)d[x].fw=x+1,d[x+1].bk=x,l&&(d[x].cnt=Math.sqrt(d[x].cnt));l&&(d[x].cnt=Math.sqrt(d[x].cnt));var C,w,T;for(x=0;x<b;++x){m(d,x,!1);var E=d[x].err;for(w=++y[0];w>1&&(T=w>>1,!(d[C=y[T]].err<=E));w=T)y[w]=C;y[w]=x}var D=b-t;for(x=0;x<D;){for(var O;;){var k=y[1];if(O=d[k],O.tm>=O.mtm&&d[O.nn].mtm<=O.tm)break;O.mtm==_?k=y[1]=y[y[0]--]:(m(d,k,!1),O.tm=x);var E=d[k].err;for(w=1;(T=w+w)<=y[0]&&(T<y[0]&&d[y[T]].err>d[y[T+1]].err&&T++,!(E<=d[C=y[T]].err));w=T)y[w]=C;y[w]=k}var A=d[O.nn],j=O.cnt,M=A.cnt,S=1/(j+M);u&&(O.ac=S*(j*O.ac+M*A.ac)),O.rc=S*(j*O.rc+M*A.rc),O.gc=S*(j*O.gc+M*A.gc),O.bc=S*(j*O.bc+M*A.bc),O.cnt+=A.cnt,O.mtm=++x,d[A.bk].fw=A.fw,d[A.fw].bk=A.bk,A.mtm=_}let N=[];var P=0;for(x=0;;++P){let e=f(Math.round(d[x].rc),0,255),t=f(Math.round(d[x].gc),0,255),n=f(Math.round(d[x].bc),0,255),r=255;u&&(r=f(Math.round(d[x].ac),0,255),s&&(r=r<=(typeof s==`number`?s:127)?0:255),i&&r<=o&&(e=t=n=a,r=0));let c=u?[e,t,n,r]:[e,t,n];if(v(N,c)||N.push(c),(x=d[x].fw)==0)break}return N}function v(e,t){for(let n=0;n<e.length;n++){let r=e[n],i=r[0]===t[0]&&r[1]===t[1]&&r[2]===t[2],a=r.length>=4&&t.length>=4?r[3]===t[3]:!0;if(i&&a)return!0}return!1}function y(e,t){for(var n=0,r=0;r<e.length;r++){let i=e[r]-t[r];n+=i*i}return n}function b(e,t){return t>1?Math.round(e/t)*t:e}function x(e,{roundRGB:t=5,roundAlpha:n=10,oneBitAlpha:r=null}={}){let i=new Uint32Array(e.buffer);for(let e=0;e<i.length;e++){let a=i[e],o=a>>24&255,s=a>>16&255,c=a>>8&255,l=a&255;o=b(o,n),r&&(o=o<=(typeof r==`number`?r:127)?0:255),l=b(l,t),c=b(c,t),s=b(s,t),i[e]=o<<24|s<<16|c<<8|l}}function S(e,t,n=`rgb565`){if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);if(t.length>256)throw Error(`applyPalette() only works with 256 colors or less`);let r=new Uint32Array(e.buffer),i=r.length,a=n===`rgb444`?4096:65536,o=new Uint8Array(i),s=Array(a);if(n===`rgba4444`)for(let e=0;e<i;e++){let n=r[e],i=n>>24&255,a=n>>16&255,c=n>>8&255,l=n&255,d=u(l,c,a,i),f=d in s?s[d]:s[d]=C(l,c,a,i,t);o[e]=f}else{let e=n===`rgb444`?d:l;for(let n=0;n<i;n++){let i=r[n],a=i>>16&255,c=i>>8&255,l=i&255,u=e(l,c,a),d=u in s?s[u]:s[u]=w(l,c,a,t);o[n]=d}}return o}function C(e,t,n,r,i){let a=0,o=1e100;for(let s=0;s<i.length;s++){let c=i[s],l=c[3],u=E(l-r);if(u>o)continue;let d=c[0];if(u+=E(d-e),u>o)continue;let f=c[1];if(u+=E(f-t),u>o)continue;let p=c[2];u+=E(p-n),u>o||(o=u,a=s)}return a}function w(e,t,n,r){let i=0,a=1e100;for(let o=0;o<r.length;o++){let s=r[o],c=s[0],l=E(c-e);if(l>a)continue;let u=s[1];if(l+=E(u-t),l>a)continue;let d=s[2];l+=E(d-n),l>a||(a=l,i=o)}return i}function T(e,t,n=5){if(!e.length||!t.length)return;let r=e.map(e=>e.slice(0,3)),i=n*n,a=e[0].length;for(let n=0;n<t.length;n++){let o=t[n];o=o.length<a?[o[0],o[1],o[2],255]:o.length>a?o.slice(0,3):o.slice();let s=O(r,o.slice(0,3),y),c=s[0],l=s[1];l>0&&l<=i&&(e[c]=o)}}function E(e){return e*e}function D(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return i}function O(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return[i,r]}function k(e,t,n=y){return e[D(e,t,n)]}function A(e={}){let{initialCapacity:t=4096,auto:i=!0}=e,a=r(t),o=5003,s=/* @__PURE__ */ new Uint8Array(256),c=new Int32Array(o),l=new Int32Array(o),u=!1;return{reset(){a.reset(),u=!1},finish(){a.writeByte(n.trailer)},bytes(){return a.bytes()},bytesView(){return a.bytesView()},get buffer(){return a.buffer},get stream(){return a},writeHeader:d,writeFrame(e,t,n,r={}){let{transparent:o=!1,transparentIndex:f=0,delay:p=0,palette:m=null,repeat:h=0,colorDepth:g=8,dispose:_=-1}=r,v=!1;if(i?u||=(v=!0,d(),!0):v=!!r.first,t=Math.max(0,Math.floor(t)),n=Math.max(0,Math.floor(n)),v){if(!m)throw Error(`First frame must include a { palette } option`);M(a,t,n,m,g),P(a,m),h>=0&&N(a,h)}let y=Math.round(p/10);j(a,_,y,o,f);let b=!!m&&!v;F(a,t,n,b?m:null),b&&P(a,m),I(a,e,t,n,g,s,c,l)}};function d(){R(a,`GIF89a`)}}function j(e,t,n,r,i){e.writeByte(33),e.writeByte(249),e.writeByte(4),i<0&&(i=0,r=!1);var a,o;r?(a=1,o=2):(a=0,o=0),t>=0&&(o=t&7),o<<=2,e.writeByte(o|0|a),L(e,n),e.writeByte(i||0),e.writeByte(0)}function M(e,t,n,r,i=8){let a=z(r.length)-1,o=i-1<<4|128|a;L(e,t),L(e,n),e.writeBytes([o,0,0])}function N(e,t){e.writeByte(33),e.writeByte(255),e.writeByte(11),R(e,`NETSCAPE2.0`),e.writeByte(3),e.writeByte(1),L(e,t),e.writeByte(0)}function P(e,t){let n=1<<z(t.length);for(let r=0;r<n;r++){let n=[0,0,0];r<t.length&&(n=t[r]),e.writeByte(n[0]),e.writeByte(n[1]),e.writeByte(n[2])}}function F(e,t,n,r){if(e.writeByte(44),L(e,0),L(e,0),L(e,t),L(e,n),r){let t=z(r.length)-1;e.writeByte(128|t)}else e.writeByte(0)}function I(e,t,n,r,i=8,a,o,s){c(n,r,t,i,e,a,o,s)}function L(e,t){e.writeByte(t&255),e.writeByte(t>>8&255)}function R(e,t){for(var n=0;n<t.length;n++)e.writeByte(t.charCodeAt(n))}function z(e){return Math.max(Math.ceil(Math.log2(e)),1)}var B=A})))();function P(e){let{width:t,height:n,loop:r}=e;if(!Number.isInteger(t)||!Number.isInteger(n)||t<1||n<1||t>65535||n>65535)throw RangeError(`A GIF is from 1 × 1 to 65,535 × 65,535 pixels.`);if(r!==null&&(!Number.isInteger(r)||r<0||r>65535))throw RangeError(`A loop count is null, or a whole number from 0 to 65,535.`);let i=(0,N.GIFEncoder)(),a=t*n,o=0,s=!1;return{get frames(){return o},frame(e,c){if(s)throw Error(`The GIF is finished.`);if(e.length!==a*4)throw RangeError(`A frame is ${t} × ${n} RGBA pixels.`);if(!Number.isInteger(c)||c<0||c>65535)throw RangeError(`A delay is a whole number of hundredths of a second, from 0 to 65,535.`);let l=0;for(let t=3;t<e.length;t+=4)e[t]>=128&&(l+=1);let u=new Uint8Array(l*4),d=0;for(let t=0;t<e.length;t+=4)e[t+3]<128||(u[d]=e[t],u[d+1]=e[t+1],u[d+2]=e[t+2],u[d+3]=255,d+=4);let f=l>0?(0,N.quantize)(u,255):[],p=l>0?(0,N.applyPalette)(u,f):/* @__PURE__ */ new Uint8Array,m=new Uint8Array(a),h=0;for(let t=0;t<a;t+=1)e[t*4+3]<128||(m[t]=p[h]+1,h+=1);i.writeFrame(m,t,n,{palette:[[0,0,0],...f],delay:c*10,transparent:l<a,transparentIndex:0,dispose:2,repeat:r===null?-1:r}),o+=1},finish(){if(s)throw Error(`The GIF is finished.`);if(o===0)throw RangeError(`A GIF has at least one frame.`);return s=!0,i.finish(),i.bytes()}}}function F(e){let t=/* @__PURE__ */ new Map,n=e=>{let n=t.get(e);if(!n)throw TypeError(`There's no job with the id \"${e}\".`);return n};M({gifStart({id:e,width:n,height:r,loop:i}){if(t.has(e))throw TypeError(`The job id \"${e}\" is already in use.`);t.set(e,P({width:n,height:r,loop:i}))},gifFrame({id:e,pixels:t,delay:r},{signal:i}){if(i.aborted)throw i.reason;n(e).frame(new Uint8ClampedArray(t),r)},gifFinish({id:e}){let r=n(e).finish();return t.delete(e),new Blob([r],{type:`image/gif`})},gifAbandon({id:e}){t.delete(e)}},{...e,packageVersion:`0.7.1`})}F();\n";
|
|
2
|
+
var jsContent = "var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);function t(){try{return process.env.NODE_ENV!==`production`}catch{return!1}}function n(e){t()&&console.warn(`[@hussmartinez/sdk-core] ${e}`)}var r=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core`),i={},a=!1;function o(){return`0.4.4`}function s(){if(!a&&(a=!0,typeof process<`u`&&process.env.NODE_ENV!==`production`)){let e=globalThis,t=e[r]??/* @__PURE__ */ new Map;e[r]=t,t.set(i,o()),t.size>1&&n(`${t.size} copies of @hussmartinez/sdk-core are in use (${[...t.values()].join(`, `)}). \\`instanceof SdkError\\` fails for errors from another copy, so use \\`isSdkError\\`, and each copy keeps its own caches. Install a single version: \\`npm ls @hussmartinez/sdk-core\\` shows where each comes from, and every SDK, \\`@hussmartinez/ui\\` and your application should use the same minor version.`)}}var c=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),l=class extends Error{name=`SdkError`;code;constructor(e,t,n={}){super(t,`cause`in n?{cause:n.cause}:void 0),s(),this.code=e,Object.defineProperty(this,c,{value:!0}),n.details!==void 0&&(this.details=n.details)}};function u(e,t){if(typeof e!=`object`||!e)return!1;let n=e;return(e instanceof l||n[c]===!0)&&typeof n.code==`string`&&typeof n.message==`string`&&(t===void 0||n.code===t)}var d=8,f=16,p=`UNKNOWN`;function m(e,t={}){let n=t.includeStack??!1,r=b(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=h(e),s=n&&v(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),v(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function h(e){if(u(e)){let t={name:e.name,code:e.code,message:e.message},n=g(e.details);return n!==void 0&&(t.details=n),t}if(v(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:p,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:p,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:p,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function g(e){if(!y(e))return;let t=_(e,0);return y(t)?t:void 0}function _(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=f)){if(Array.isArray(e))return e.flatMap(e=>{let n=_(e,t+1);return n===void 0?[]:[n]});if(y(e)){let n={};for(let[r,i]of Object.entries(e)){let e=_(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function v(e){return typeof e==`object`&&!!e}function y(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function b(e){if(e===void 0)return d;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var x=`hm-rpc`;function S(e){return{protocol:x,version:1,...e}}function C(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function w(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=E(e)?e:D(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return k(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):A(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),j(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function T(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function E(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function D(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var O=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function k(e){let t=globalThis;return O.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function A(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function j(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function M(e,t={}){let n=t.scope??globalThis,r=t.includeStack??!1,i=/* @__PURE__ */ new Map,a=(e,t=[])=>{n.postMessage(e,t)},o=(e,t)=>{a(S({type:`error`,id:e,error:m(t,{includeStack:r})}))},s=(e,t,r)=>{let i=w(r,!0);try{T((e,t)=>n.postMessage(e,t),S({type:`result`,id:e,output:i.value}),i.transferables)}catch(n){o(e,new l(`WORKER_DATA_NOT_CLONEABLE`,`The result of \"${t}\" can't be sent to the page.`,{cause:n,details:{method:t}}))}},c=t=>{let{id:n,method:r}=t,c=Object.hasOwn(e,r)?e[r]:void 0;if(typeof c!=`function`){o(n,new l(`WORKER_METHOD_NOT_FOUND`,`The worker has no method \"${r}\".`,{details:{method:r}}));return}let u=new AbortController;i.set(n,u);let d={signal:u.signal,progress:e=>{i.get(n)===u&&a(S({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>c.call(e,t.input,d)).then(e=>{i.delete(n),s(n,r,e)},e=>{i.delete(n),o(n,e)})},u=e=>{a(S({type:`crash`,error:m(e,{includeStack:r})}))};n.addEventListener(`message`,e=>{let t=C(e.data);t!==void 0&&t.version===1&&(t.type===`call`?c(t):t.type===`cancel`&&i.get(t.id)?.abort())}),n.addEventListener(`error`,e=>{let t=e;u(t.error??Error(t.message))}),n.addEventListener(`unhandledrejection`,e=>{u(e.reason)}),a(S({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var N=(/* @__PURE__ */ e((e=>{var t=Object.defineProperty;(e=>t(e,`__esModule`,{value:!0}))(e),((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(e,{GIFEncoder:()=>A,applyPalette:()=>S,default:()=>B,nearestColor:()=>k,nearestColorIndex:()=>D,nearestColorIndexWithDistance:()=>O,prequantize:()=>x,quantize:()=>_,snapColorsToPalette:()=>T});var n={signature:`GIF`,version:`89a`,trailer:59,extensionIntroducer:33,applicationExtensionLabel:255,graphicControlExtensionLabel:249,imageSeparator:44,signatureSize:3,versionSize:3,globalColorTableFlagMask:128,colorResolutionMask:112,sortFlagMask:8,globalColorTableSizeMask:7,applicationIdentifierSize:8,applicationAuthCodeSize:3,disposalMethodMask:28,userInputFlagMask:2,transparentColorFlagMask:1,localColorTableFlagMask:128,interlaceFlagMask:64,idSortFlagMask:32,localColorTableSizeMask:7};function r(e=256){let t=0,n=new Uint8Array(e);return{get buffer(){return n.buffer},reset(){t=0},bytesView(){return n.subarray(0,t)},bytes(){return n.slice(0,t)},writeByte(e){r(t+1),n[t]=e,t++},writeBytes(e,i=0,a=e.length){r(t+a);for(let r=0;r<a;r++)n[t++]=e[r+i]},writeBytesView(e,i=0,a=e.byteLength){r(t+a),n.set(e.subarray(i,i+a),t),t+=a}};function r(e){var r=n.length;if(r>=e)return;e=Math.max(e,r*(r<1048576?2:1.125)>>>0),r!=0&&(e=Math.max(e,256));let i=n;n=new Uint8Array(e),t>0&&n.set(i.subarray(0,t),0)}}var i=12,a=5003,o=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function s(e,t,n,s,c=r(512),l=/* @__PURE__ */ new Uint8Array(256),u=new Int32Array(a),d=new Int32Array(a)){let f=u.length,p=Math.max(2,s);l.fill(0),d.fill(0),u.fill(-1);let m=0,h=0,g=p+1,_=g,v=!1,y=_,b=(1<<y)-1,x=1<<g-1,S=x+1,C=x+2,w=0,T=n[0],E=0;for(let e=f;e<65536;e*=2)++E;E=8-E,c.writeByte(p),O(x);let D=n.length;for(let e=1;e<D;e++)next_block:{let t=n[e],r=(t<<i)+T,a=t<<E^T;if(u[a]===r){T=d[a];break next_block}let o=a===0?1:f-a;for(;u[a]>=0;)if(a-=o,a<0&&(a+=f),u[a]===r){T=d[a];break next_block}O(T),T=t,C<1<<i?(d[a]=C++,u[a]=r):(u.fill(-1),C=x+2,v=!0,O(x))}return O(T),O(S),c.writeByte(0),c.bytesView();function O(e){for(m&=o[h],h>0?m|=e<<h:m=e,h+=y;h>=8;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;if((C>b||v)&&(v?(y=_,b=(1<<y)-1,v=!1):(++y,b=y===i?1<<y:(1<<y)-1)),e==S){for(;h>0;)l[w++]=m&255,w>=254&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0),m>>=8,h-=8;w>0&&(c.writeByte(w),c.writeBytesView(l,0,w),w=0)}}}var c=s;function l(e,t,n){return e<<8&63488|t<<2&992|n>>3}function u(e,t,n,r){return e>>4|t&240|(n&240)<<4|(r&240)<<8}function d(e,t,n){return e>>4<<8|t&240|n>>4}function f(e,t,n){return e<t?t:e>n?n:e}function p(e){return e*e}function m(e,t,n){var r=0,i=1e100;let a=e[t],o=a.cnt,s=a.ac,c=a.rc,l=a.gc,u=a.bc;for(var d=a.fw;d!=0;d=e[d].fw){let t=e[d],a=t.cnt,m=o*a/(o+a);if(!(m>=i)){var f=0;n&&(f+=m*p(t.ac-s),f>=i)||(f+=m*p(t.rc-c),f>=i||(f+=m*p(t.gc-l),f>=i||(f+=m*p(t.bc-u),f>=i||(i=f,r=d))))}}a.err=i,a.nn=r}function h(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function g(e,t){let n=Array(t===`rgb444`?4096:65536),r=e.length;if(t===`rgba4444`)for(let t=0;t<r;++t){let r=e[t],i=r>>24&255,a=r>>16&255,o=r>>8&255,s=r&255,c=u(s,o,a,i),l=c in n?n[c]:n[c]=h();l.rc+=s,l.gc+=o,l.bc+=a,l.ac+=i,l.cnt++}else if(t===`rgb444`)for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=d(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}else for(let t=0;t<r;++t){let r=e[t],i=r>>16&255,a=r>>8&255,o=r&255,s=l(o,a,i),c=s in n?n[s]:n[s]=h();c.rc+=o,c.gc+=a,c.bc+=i,c.cnt++}return n}function _(e,t,n={}){let{format:r=`rgb565`,clearAlpha:i=!0,clearAlphaColor:a=0,clearAlphaThreshold:o=0,oneBitAlpha:s=!1}=n;if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);let c=new Uint32Array(e.buffer),l=n.useSqrt!==!1,u=r===`rgba4444`,d=g(c,r),h=d.length,_=h-1,y=new Uint32Array(h+1);for(var b=0,x=0;x<h;++x){let e=d[x];if(e!=null){var S=1/e.cnt;u&&(e.ac*=S),e.rc*=S,e.gc*=S,e.bc*=S,d[b++]=e}}p(t)/b<.022&&(l=!1);for(var x=0;x<b-1;++x)d[x].fw=x+1,d[x+1].bk=x,l&&(d[x].cnt=Math.sqrt(d[x].cnt));l&&(d[x].cnt=Math.sqrt(d[x].cnt));var C,w,T;for(x=0;x<b;++x){m(d,x,!1);var E=d[x].err;for(w=++y[0];w>1&&(T=w>>1,!(d[C=y[T]].err<=E));w=T)y[w]=C;y[w]=x}var D=b-t;for(x=0;x<D;){for(var O;;){var k=y[1];if(O=d[k],O.tm>=O.mtm&&d[O.nn].mtm<=O.tm)break;O.mtm==_?k=y[1]=y[y[0]--]:(m(d,k,!1),O.tm=x);var E=d[k].err;for(w=1;(T=w+w)<=y[0]&&(T<y[0]&&d[y[T]].err>d[y[T+1]].err&&T++,!(E<=d[C=y[T]].err));w=T)y[w]=C;y[w]=k}var A=d[O.nn],j=O.cnt,M=A.cnt,S=1/(j+M);u&&(O.ac=S*(j*O.ac+M*A.ac)),O.rc=S*(j*O.rc+M*A.rc),O.gc=S*(j*O.gc+M*A.gc),O.bc=S*(j*O.bc+M*A.bc),O.cnt+=A.cnt,O.mtm=++x,d[A.bk].fw=A.fw,d[A.fw].bk=A.bk,A.mtm=_}let N=[];var P=0;for(x=0;;++P){let e=f(Math.round(d[x].rc),0,255),t=f(Math.round(d[x].gc),0,255),n=f(Math.round(d[x].bc),0,255),r=255;u&&(r=f(Math.round(d[x].ac),0,255),s&&(r=r<=(typeof s==`number`?s:127)?0:255),i&&r<=o&&(e=t=n=a,r=0));let c=u?[e,t,n,r]:[e,t,n];if(v(N,c)||N.push(c),(x=d[x].fw)==0)break}return N}function v(e,t){for(let n=0;n<e.length;n++){let r=e[n],i=r[0]===t[0]&&r[1]===t[1]&&r[2]===t[2],a=r.length>=4&&t.length>=4?r[3]===t[3]:!0;if(i&&a)return!0}return!1}function y(e,t){for(var n=0,r=0;r<e.length;r++){let i=e[r]-t[r];n+=i*i}return n}function b(e,t){return t>1?Math.round(e/t)*t:e}function x(e,{roundRGB:t=5,roundAlpha:n=10,oneBitAlpha:r=null}={}){let i=new Uint32Array(e.buffer);for(let e=0;e<i.length;e++){let a=i[e],o=a>>24&255,s=a>>16&255,c=a>>8&255,l=a&255;o=b(o,n),r&&(o=o<=(typeof r==`number`?r:127)?0:255),l=b(l,t),c=b(c,t),s=b(s,t),i[e]=o<<24|s<<16|c<<8|l}}function S(e,t,n=`rgb565`){if(!e||!e.buffer||!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw Error(`quantize() expected RGBA Uint8Array data`);if(t.length>256)throw Error(`applyPalette() only works with 256 colors or less`);let r=new Uint32Array(e.buffer),i=r.length,a=n===`rgb444`?4096:65536,o=new Uint8Array(i),s=Array(a);if(n===`rgba4444`)for(let e=0;e<i;e++){let n=r[e],i=n>>24&255,a=n>>16&255,c=n>>8&255,l=n&255,d=u(l,c,a,i),f=d in s?s[d]:s[d]=C(l,c,a,i,t);o[e]=f}else{let e=n===`rgb444`?d:l;for(let n=0;n<i;n++){let i=r[n],a=i>>16&255,c=i>>8&255,l=i&255,u=e(l,c,a),d=u in s?s[u]:s[u]=w(l,c,a,t);o[n]=d}}return o}function C(e,t,n,r,i){let a=0,o=1e100;for(let s=0;s<i.length;s++){let c=i[s],l=c[3],u=E(l-r);if(u>o)continue;let d=c[0];if(u+=E(d-e),u>o)continue;let f=c[1];if(u+=E(f-t),u>o)continue;let p=c[2];u+=E(p-n),u>o||(o=u,a=s)}return a}function w(e,t,n,r){let i=0,a=1e100;for(let o=0;o<r.length;o++){let s=r[o],c=s[0],l=E(c-e);if(l>a)continue;let u=s[1];if(l+=E(u-t),l>a)continue;let d=s[2];l+=E(d-n),l>a||(a=l,i=o)}return i}function T(e,t,n=5){if(!e.length||!t.length)return;let r=e.map(e=>e.slice(0,3)),i=n*n,a=e[0].length;for(let n=0;n<t.length;n++){let o=t[n];o=o.length<a?[o[0],o[1],o[2],255]:o.length>a?o.slice(0,3):o.slice();let s=O(r,o.slice(0,3),y),c=s[0],l=s[1];l>0&&l<=i&&(e[c]=o)}}function E(e){return e*e}function D(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return i}function O(e,t,n=y){let r=1/0,i=-1;for(let a=0;a<e.length;a++){let o=e[a],s=n(t,o);s<r&&(r=s,i=a)}return[i,r]}function k(e,t,n=y){return e[D(e,t,n)]}function A(e={}){let{initialCapacity:t=4096,auto:i=!0}=e,a=r(t),o=5003,s=/* @__PURE__ */ new Uint8Array(256),c=new Int32Array(o),l=new Int32Array(o),u=!1;return{reset(){a.reset(),u=!1},finish(){a.writeByte(n.trailer)},bytes(){return a.bytes()},bytesView(){return a.bytesView()},get buffer(){return a.buffer},get stream(){return a},writeHeader:d,writeFrame(e,t,n,r={}){let{transparent:o=!1,transparentIndex:f=0,delay:p=0,palette:m=null,repeat:h=0,colorDepth:g=8,dispose:_=-1}=r,v=!1;if(i?u||=(v=!0,d(),!0):v=!!r.first,t=Math.max(0,Math.floor(t)),n=Math.max(0,Math.floor(n)),v){if(!m)throw Error(`First frame must include a { palette } option`);M(a,t,n,m,g),P(a,m),h>=0&&N(a,h)}let y=Math.round(p/10);j(a,_,y,o,f);let b=!!m&&!v;F(a,t,n,b?m:null),b&&P(a,m),I(a,e,t,n,g,s,c,l)}};function d(){R(a,`GIF89a`)}}function j(e,t,n,r,i){e.writeByte(33),e.writeByte(249),e.writeByte(4),i<0&&(i=0,r=!1);var a,o;r?(a=1,o=2):(a=0,o=0),t>=0&&(o=t&7),o<<=2,e.writeByte(o|0|a),L(e,n),e.writeByte(i||0),e.writeByte(0)}function M(e,t,n,r,i=8){let a=z(r.length)-1,o=i-1<<4|128|a;L(e,t),L(e,n),e.writeBytes([o,0,0])}function N(e,t){e.writeByte(33),e.writeByte(255),e.writeByte(11),R(e,`NETSCAPE2.0`),e.writeByte(3),e.writeByte(1),L(e,t),e.writeByte(0)}function P(e,t){let n=1<<z(t.length);for(let r=0;r<n;r++){let n=[0,0,0];r<t.length&&(n=t[r]),e.writeByte(n[0]),e.writeByte(n[1]),e.writeByte(n[2])}}function F(e,t,n,r){if(e.writeByte(44),L(e,0),L(e,0),L(e,t),L(e,n),r){let t=z(r.length)-1;e.writeByte(128|t)}else e.writeByte(0)}function I(e,t,n,r,i=8,a,o,s){c(n,r,t,i,e,a,o,s)}function L(e,t){e.writeByte(t&255),e.writeByte(t>>8&255)}function R(e,t){for(var n=0;n<t.length;n++)e.writeByte(t.charCodeAt(n))}function z(e){return Math.max(Math.ceil(Math.log2(e)),1)}var B=A})))();function P(e){let{width:t,height:n,loop:r}=e;if(!Number.isInteger(t)||!Number.isInteger(n)||t<1||n<1||t>65535||n>65535)throw RangeError(`A GIF is from 1 × 1 to 65,535 × 65,535 pixels.`);if(r!==null&&(!Number.isInteger(r)||r<0||r>65535))throw RangeError(`A loop count is null, or a whole number from 0 to 65,535.`);let i=(0,N.GIFEncoder)(),a=t*n,o=0,s=!1;return{get frames(){return o},frame(e,c){if(s)throw Error(`The GIF is finished.`);if(e.length!==a*4)throw RangeError(`A frame is ${t} × ${n} RGBA pixels.`);if(!Number.isInteger(c)||c<0||c>65535)throw RangeError(`A delay is a whole number of hundredths of a second, from 0 to 65,535.`);let l=0;for(let t=3;t<e.length;t+=4)e[t]>=128&&(l+=1);let u=new Uint8Array(l*4),d=0;for(let t=0;t<e.length;t+=4)e[t+3]<128||(u[d]=e[t],u[d+1]=e[t+1],u[d+2]=e[t+2],u[d+3]=255,d+=4);let f=l>0?(0,N.quantize)(u,255):[],p=l>0?(0,N.applyPalette)(u,f):/* @__PURE__ */ new Uint8Array,m=new Uint8Array(a),h=0;for(let t=0;t<a;t+=1)e[t*4+3]<128||(m[t]=p[h]+1,h+=1);i.writeFrame(m,t,n,{palette:[[0,0,0],...f],delay:c*10,transparent:l<a,transparentIndex:0,dispose:2,repeat:r===null?-1:r}),o+=1},finish(){if(s)throw Error(`The GIF is finished.`);if(o===0)throw RangeError(`A GIF has at least one frame.`);return s=!0,i.finish(),i.bytes()}}}function F(e){let t=/* @__PURE__ */ new Map,n=e=>{let n=t.get(e);if(!n)throw TypeError(`There's no job with the id \"${e}\".`);return n};M({gifStart({id:e,width:n,height:r,loop:i}){if(t.has(e))throw TypeError(`The job id \"${e}\" is already in use.`);t.set(e,P({width:n,height:r,loop:i}))},gifFrame({id:e,pixels:t,delay:r},{signal:i}){if(i.aborted)throw i.reason;n(e).frame(new Uint8ClampedArray(t),r)},gifFinish({id:e}){let r=n(e).finish();return t.delete(e),new Blob([r],{type:`image/gif`})},gifAbandon({id:e}){t.delete(e)}},{...e,packageVersion:`0.7.3`})}F();\n";
|
|
3
3
|
var blob = typeof self !== "undefined" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", jsContent], { type: "text/javascript;charset=utf-8" });
|
|
4
4
|
function WorkerWrapper(options) {
|
|
5
5
|
let objURL;
|
|
@@ -27,4 +27,4 @@ function createInlineJobWorker() {
|
|
|
27
27
|
}
|
|
28
28
|
export { createInlineJobWorker };
|
|
29
29
|
|
|
30
|
-
//# sourceMappingURL=inline-job-worker-
|
|
30
|
+
//# sourceMappingURL=inline-job-worker-B-NXVhUL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-job-worker-
|
|
1
|
+
{"version":3,"file":"inline-job-worker-B-NXVhUL.js","names":["JobWorker"],"sources":["../../src/adapters/job-worker/inline-job-worker.ts"],"sourcesContent":["import JobWorker from \"../../workers/job.worker.ts?worker&inline\";\n\n/** Starts the inlined job worker, from its own lazy chunk. */\nexport function createInlineJobWorker(): Worker {\n return new JobWorker({ name: \"hm-image-job\" });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,wBAAgC;CAC9C,OAAO,IAAIA,cAAU,EAAE,MAAM,eAAe,CAAC;AAC/C"}
|