@hussmartinez/image-sdk 0.5.0 → 0.6.0

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/README.md CHANGED
@@ -139,7 +139,7 @@ Headless, a layer is a command: `image.insertLayers`, or `session.insertImage(fi
139
139
 
140
140
  ## Formats and browsers
141
141
 
142
- The engine reads PNG, JPEG, WebP, GIF, BMP and AVIF with the browser's decoder after checking headers and limits in its worker. Animated inputs open as a single first frame. HEIC is recognised, but decoding depends on the browser: all three pinned test engines reject it with `DECODE_FAILED`. SVG is unsupported. Export formats are PNG, JPEG and WebP; an unavailable encoder fails with `UNSUPPORTED_FORMAT`. Exports are sRGB; colours outside sRGB can be clipped.
142
+ The engine reads PNG, JPEG, WebP, BMP and AVIF with the browser's decoder after checking headers and limits in its worker, and GIF with its own decoder, which the browser's never sees: a malformed GIF opens when browsers show it and its first frame is whole. Animated inputs open as a single first frame. HEIC is recognised, but decoding depends on the browser: all three pinned test engines reject it with `DECODE_FAILED`. SVG is unsupported. Export formats are PNG, JPEG and WebP; an unavailable encoder fails with `UNSUPPORTED_FORMAT`. Exports are sRGB; colours outside sRGB can be clipped.
143
143
 
144
144
  The family's [support target](https://github.com/ie-huss-martinez/sdk-core/blob/main/docs/adr/0013-browser-and-react-support.md) is the last two major versions of Chrome, Edge, Firefox and Safari on desktop and mobile, with ES2022 output and no polyfills. The [measured capability matrix](docs/capabilities.md) records the exact pinned Chromium, Firefox and WebKit builds checked in CI. These runs prove the generated fixtures, orientation handling and worker canvas paths in those builds; they do not constitute testing of every browser version or device. Playwright WebKit is not Safari and does not prove Apple system HEIC decoding or iOS canvas limits. Validate your target devices and choose limits suitable for them.
145
145
 
@@ -1,2 +1,2 @@
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))b(`${t}.default`,n.default),n.warning!==void 0&&b(`${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]=ee(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 ee(e,t,n){if(typeof n==`number`)return b(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 b(`${e}.maximum`,r),b(`${e}.warning`,i),{maximum:r,warning:i}}function b(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 te=`hm-rpc`;function x(e){return{protocol:te,version:1,...e}}function ne(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 re(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=ae(e)?e:oe(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return ce(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))}):S(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),le(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function ie(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function ae(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function oe(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 se=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function ce(e){let t=globalThis;return se.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function S(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function le(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 ue(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(x({type:`error`,id:e,error:d(t,{includeStack:i})}))},c=(e,t,i)=>{let a=re(i,!0);try{ie((e,t)=>n.postMessage(e,t),x({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(x({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(x({type:`crash`,error:d(e,{includeStack:i})}))};n.addEventListener(`message`,e=>{let t=ne(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(x({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var C=class extends r{name=`ImageError`},w=/* @__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},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:C}),de=[`maxFileSize`,`maxImageDimension`,`maxImagePixels`,`maxFrames`,`maxDecodedSize`];function T(e,t,n){let{width:r,height:i}=n.oriented,a={maxFileSize:t,maxImageDimension:Math.max(r,i),maxImagePixels:r*i,maxFrames:n.frames,maxDecodedSize:n.decodedPixelBound*4};return de.filter(t=>e.check(t,a[t])===`warning`)}function E(e,t){e.check(`maxImageDimension`,Math.max(t.width,t.height)),e.check(`maxImagePixels`,t.width*t.height)}function fe(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 pe(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 me(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 C(`UNSUPPORTED_PLAN`,`This renderer can't draw the plan's ${e}.`,{details:{reason:e}})}var he=Object.freeze({location:!1,camera:!1,timestamps:!1,thumbnail:!1,colourProfile:!1,other:!1}),ge=Object.freeze({title:``,description:``,artist:``,copyright:``}),D=2e3;function O(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}function k(e,t){return new C(`INVALID_IMAGE`,`Invalid ${e}: ${t}.`,{details:{format:e,problem:t}})}async function A(e,t,n,r,i){if(n+r>e.size)throw k(t,`${i} ends past the end of the file`);return e.bytes(n,r)}function j(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 P(e,t){return t.every((t,n)=>e[n]===t)}function F(e,t){return(e[t]??0)|(e[t+1]??0)<<8}function I(e,t){return(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16}function L(e,t){return((e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24)>>>0}function R(e,t){return L(e,t)|0}var _e=/* @__PURE__ */ new Set([12,40,52,56,108,124]);function ve(e){return N(e,0,2)===`BM`}async function ye(e){let t=await A(e,`bmp`,0,18,`the file header`),n=L(t,10),r=L(t,14);if(!_e.has(r))throw k(`bmp`,`the DIB header size is unknown`);let i=await A(e,`bmp`,14,r,`the DIB header`),a,o,s;if(r===12?(a=F(i,4),o=F(i,6),s=F(i,10)):(a=R(i,4),o=Math.abs(R(i,8)),s=F(i,14)),F(i,r===12?8:12)!==1)throw k(`bmp`,`the plane count isn't 1`);if(a<1||o<1||a>2147483647||o>2147483647)throw k(`bmp`,`the dimensions are out of range`);if(![1,4,8,16,24,32].includes(s))throw k(`bmp`,`the bit depth is unsupported`);if(n<14+r||n>=e.size)throw k(`bmp`,`the pixel data starts outside the file`);let c=r===124&&[1279872587,1296188740].includes(L(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:{...he,colourProfile:c},keepable:ge}}var be=1e6;function xe(e){let t=N(e,0,6);return t===`GIF87a`||t===`GIF89a`}async function Se(e,t){let n=t;for(;;){let t=(await A(e,`gif`,n,1,`a data sub-block`))[0]??0;if(n+=1,t===0)return n;if(n+t>e.size)throw k(`gif`,`a data sub-block ends past the end of the file`);n+=t}}async function Ce(e){let t=await A(e,`gif`,0,13,`the logical screen descriptor`),n=F(t,6),r=F(t,8);if(n<1||r<1)throw k(`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>=be)throw k(`gif`,`the file has too many blocks`);let i=(await A(e,`gif`,a,1,`a block`))[0];if(i===59)break;if(i===33){let t=(await A(e,`gif`,a+1,1,`an extension label`))[0];if(t===249){let t=await A(e,`gif`,a+2,6,`a graphic control extension`);if(t[0]!==4)throw k(`gif`,`a graphic control extension is the wrong size`);if((t[1]??0)&1&&(s=!0),((t[1]??0)>>>2&7)>3)throw k(`gif`,`a frame uses a reserved disposal method`)}else if(t===255){let t=N(await A(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 Se(e,a+2)}else if(i===44){let t=await A(e,`gif`,a,10,`an image descriptor`),i=F(t,1),s=F(t,3),c=F(t,5),l=F(t,7);if(c<1||l<1||i+c>n||s+l>r)throw k(`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 A(e,`gif`,a,1,`an LZW minimum code size`))[0]??0;if(d<2||d>8)throw k(`gif`,`a frame's LZW minimum code size is out of range`);a=await Se(e,a+1),o+=1}else throw k(`gif`,`an unknown block`)}if(o===0)throw k(`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:{...he,other:c},keepable:ge}}function we(e,t){return t>=5?{width:e.height,height:e.width}:e}function z(e,t){return e??{x:0,y:0,width:t.width,height:t.height}}function Te(e,t){let{width:n,height:r}=z(e.base.crop,t);return e.base.orientation.rotate%180==0?{width:n,height:r}:{width:r,height:n}}function Ee(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 De(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 B(){return{orientation:1,location:!1,camera:!1,timestamps:!1,thumbnail:!1,other:!1,title:``,description:``,artist:``,copyright:``}}function Oe(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}var ke=8,Ae=1e3,je=/* @__PURE__ */ new Set([271,272,42033,42035,42036,42037,37500]),Me=/* @__PURE__ */ new Set([306,36867,36868,36880,36881,36882]),Ne=/* @__PURE__ */ new Set([34665,34853,40965,513,514]),Pe={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 Fe(e,t){let n=B();if(e.length<8)throw k(t,`the EXIF block is too short`);let r=e[0]===73&&e[1]===73;if(!r&&(e[0]!==77||e[1]!==77))throw k(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 k(t,`the EXIF block isn't TIFF`);let o=(n,r,i,o)=>{let s=r*(Pe[n]??1),c=s<=4?i:a(i);if(c+s>e.length)throw k(t,`an EXIF value ends past the block`);let l=e.subarray(c,c+s),u=(o?new TextDecoder(`utf-16le`).decode(l):Oe(l)).replace(/\0+$/,``);return O(u,2e3)?[...u].slice(0,D).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 k(t,`EXIF directories loop`);if(s.size>=ke)throw k(t,`the EXIF block has too many directories`);if(s.add(r),r+2>e.length)throw k(t,`an EXIF directory starts past the block`);let u=i(r);if(u>Ae||r+2+u*12+4>e.length)throw k(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):je.has(s)?n.camera=!0:Me.has(s)?n.timestamps=!0:Ne.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 Ie=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`,`heic`,`heix`,`heim`,`heis`,`hevc`,`hevx`,`mif1`,`mif2`,`msf1`]),Le=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`]),Re=/* @__PURE__ */ new Set([`av01`,`hvc1`]),ze=/* @__PURE__ */ new Set([`urn:mpeg:mpegB:cicp:systems:auxiliary:alpha`,`urn:mpeg:hevc:2015:auxid:1`]),Be=/* @__PURE__ */ new Set([`dimg`,`auxl`,`thmb`]),Ve=1024,He=4<<20,Ue=4096,We=1024,Ge=1<<20;function Ke(e){return N(e,4,4)===`ftyp`&&Ie.has(N(e,8,4))}function qe(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 k(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,j(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,qe(t,a.at-8);throw k(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 k(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>=Ue)throw k(e,`a box holds too many boxes`);if(a+8>r)throw k(e,`a box header ends past its parent`);let n=M(t,a),o=8;if(n===1){if(a+16>r)throw k(e,`a box header ends past its parent`);n=qe(t,a+8),o=16}else n===0&&(n=r-a);if(n<o||a+n>r)throw k(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 k(e,`a box that may appear once appears twice`);return r[0]}var Je=[[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 Ye(e){return Je.find(([t])=>t===e)?.[1]??[1,0,0,1]}function Xe(e,t){let[n=0,r=0,i=0,a=0]=Ye(t),[o=0,s=0,c=0,l=0]=Ye(e),u=[n*o+r*c,n*s+r*l,i*o+a*c,i*s+a*l];return Je.find(([,e])=>e.every((e,t)=>e===u[t]))?.[0]??1}function Ze(e,t,n){let r=n=>{let r=t.u32(),i=t.u32();if(i===0)throw k(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 k(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 k(e,`a clean aperture lies outside the image`);return{width:i,height:a}}var Qe=[1,8,3,6];async function $e(e){let t=M(await A(e,`heif`,0,8,`the ftyp box`),0);if(t<16||t>4096)throw k(`heif`,`the ftyp box has an invalid size`);let n=await A(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=>Le.has(e))?`avif`:`heif`,a,o=t;for(let t=0;o<e.size;t+=1){if(t>=Ve)throw k(i,`the file has too many boxes`);let n=await A(e,i,o,8,`a box header`),r=M(n,0),s=8;if(r===1?(r=qe(await A(e,i,o+8,8,`a box header`),0),s=16):r===0&&(r=e.size-o),r<s||o+r>e.size)throw k(i,`a box ends past the end of the file`);let c=N(n,4,4);if(c===`moov`)throw new C(`UNSUPPORTED_FORMAT`,`Image sequences in ${i} aren't supported.`,{details:{format:i}});if(c===`meta`){if(a!==void 0)throw k(i,`there are two meta boxes`);a={start:o+s,end:o+r}}o+=r}if(a===void 0)throw k(i,`there's no meta box`);if(a.end-a.start>He)throw k(i,`the meta box is too large`);let s=await A(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 k(i,`the meta box isn't for a picture`);let d=U(i,c,`pitm`);if(d===void 0)throw k(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 k(i,`there's no item information`);let _=V(i,s,g.start,g.end),v=_.u8();_.at+=3;let y=v===0?_.u16():_.u32(),ee=H(i,s,_.at,g.end).filter(e=>e.type===`infe`);if(ee.length!==y)throw k(i,`the item count doesn't match the item entries`);for(let e of ee){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 k(i,`two items share an ID`);h.set(r.id,r)}let b=h.get(m);if(b===void 0)throw k(i,`the primary item isn't declared`);if(b.type!==`grid`&&!Re.has(b.type))throw new C(`UNSUPPORTED_FORMAT`,`The ${i} file's primary image type isn't supported.`,{details:{format:i}});let te=[],x=U(i,c,`iref`);if(x!==void 0){let e=s[x.start]??0;for(let t of H(i,s,x.start+4,x.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());te.push({type:t.type,from:r,to:o})}}let ne=U(i,c,`iprp`);if(ne===void 0)throw k(i,`there are no item properties`);let re=H(i,s,ne.start,ne.end),ie=U(i,re,`ipco`);if(ie===void 0)throw k(i,`there's no property container`);let ae=H(i,s,ie.start,ie.end),oe=/* @__PURE__ */ new Map;for(let e of re.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>Ue)throw k(i,`too many property associations`);for(let e=0;e<a;e+=1){let e=n<1?t.u16():t.u32();if(oe.has(e))throw k(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=ae[e-1];if(n===void 0)throw k(i,`an item refers to a property that doesn't exist`);a.push(n)}oe.set(e,a)}}let se=(e,t)=>(oe.get(e)??[]).filter(e=>e.type===t),ce=e=>{let t=se(e,`ispe`),n=t[0];if(n===void 0||t.length>1)throw k(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 k(i,`an image item has no pixels`);return a},S=U(i,c,`idat`),le=/* @__PURE__ */ new Map,ue=U(i,c,`iloc`);if(ue!==void 0){let t=V(i,s,ue.start,ue.end),n=t.u8();if(t.at+=3,n>2)throw k(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>Ue)throw k(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?(S?.end??0)-(S?.start??0):1/0,d=r===0?l-n:r;if(n+d>l||d<0)throw k(i,`an item's data lies outside the file`);f.push({offset:n,length:d})}if(le.has(r))throw k(i,`an item is located twice`);le.set(r,{method:a,extents:f})}}let w=async(t,n)=>{let r=le.get(t);if(r===void 0)throw k(i,`an item's data has no location`);let a=r.extents.reduce((e,t)=>e+t.length,0);if(a>n)throw k(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&&S!==void 0){let e=S.start+t.offset;o.push(s.subarray(e,e+t.length))}else throw k(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},de=te.filter(e=>Be.has(e.type)),T=/* @__PURE__ */ new Set([m]);for(let e=[m];e.length>0;){let t=e.pop()??m;for(let n of de){let r=n.from===t?n.to:n.to.includes(t)?[n.from]:[];for(let t of r){if(!h.has(t))throw k(i,`a reference names an item that isn't declared`);T.has(t)||(T.add(t),e.push(t))}}}let E=new Map([...T].map(e=>[e,0])),fe=de.filter(e=>T.has(e.from));for(let e of fe)for(let t of e.to)E.set(t,(E.get(t)??0)+1);let pe=[...E].filter(([,e])=>e===0).map(([e])=>e),me=0;for(;pe.length>0;){let e=pe.pop()??0;me+=1;for(let t of fe)if(t.from===e)for(let e of t.to){let t=(E.get(e)??0)-1;E.set(e,t),t===0&&pe.push(e)}}if(me!==T.size)throw k(i,`item references form a cycle`);let he=0;for(let e of T){let t=ce(e);he+=t.width*t.height,h.get(e)?.type===`grid`&&await ge(e,t)}async function ge(e,t){let n=te.filter(t=>t.type===`dimg`&&t.from===e),r=n[0]?.to??[];if(n.length!==1||r.length===0)throw k(i,`a grid doesn't name its tiles once`);if(r.length>We)throw k(i,`a grid has too many tiles`);let a=await w(e,64),o=V(i,a,0,a.length);if(o.u8()!==0)throw k(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 k(i,`a grid's tile count doesn't match its rows and columns`);if(u.width!==t.width||u.height!==t.height)throw k(i,`a grid's output differs from its ispe`);let d;for(let e of r){if(!Re.has(h.get(e)?.type??``))throw k(i,`a grid tile isn't a coded image`);let t=ce(e);if(d!==void 0&&(t.width!==d.width||t.height!==d.height))throw k(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 k(i,`a grid's output doesn't fit its tiles`)}let D=ce(m),O=D,j=1,P=!1;for(let e of oe.get(m)??[])if(e.type===`clap`){if(P||O!==D)throw k(i,`a clean aperture follows a transformation`);O=Ze(i,V(i,s,e.start,e.end),D)}else if(e.type===`irot`){P=!0;let t=V(i,s,e.start,e.end);j=Xe(j,Qe[t.u8()&3]??1)}else if(e.type===`imir`){P=!0;let t=V(i,s,e.start,e.end);j=Xe(j,t.u8()&1?2:4)}let F=e=>te.filter(t=>t.type===e&&t.to.includes(m)),I=F(`auxl`).some(e=>se(e.from,`auxC`).some(e=>{let t=V(i,s,e.start+4,e.end);return ze.has(t.string())})),L=se(m,`colr`).some(e=>{let t=V(i,s,e.start,e.end).fourcc();return t===`prof`||t===`rICC`}),R=B(),_e=[...h.values()].find(e=>e.type===`Exif`);if(_e!==void 0){let e=await w(_e.id,Ge);if(e.length<4||4+M(e,0)>e.length)throw k(i,`the EXIF item's header offset is out of range`);Object.assign(R,Fe(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:O,oriented:we(O,j),orientation:j,frames:1,hasAlpha:I,decodedPixelBound:he,metadata:{location:R.location,camera:R.camera,timestamps:R.timestamps,thumbnail:R.thumbnail||F(`thmb`).length>0,colourProfile:L,other:ve},keepable:{title:R.title,description:R.description,artist:R.artist,copyright:R.copyright}}}var et=[255,216,255],tt=1e4;function nt(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}async function rt(e){let t=2,n,r=!1,i=B(),a=!1,o=!1;for(let s=0;!r;s+=1){if(s>=tt)throw k(`jpeg`,`the file has too many segments`);let c=await A(e,`jpeg`,t,2,`a marker`);if(c[0]!==255)throw k(`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 k(`jpeg`,`the image ends before its first scan`);t+=2;continue}let u=j(await A(e,`jpeg`,t+2,2,`a segment length`),0);if(u<2)throw k(`jpeg`,`a segment length is out of range`);let d=t+4,f=u-2;if(d+f>e.size)throw k(`jpeg`,`a segment ends past the end of the file`);if(nt(l)){if(n!==void 0)throw k(`jpeg`,`there's more than one frame header before the scan`);if(f<6)throw k(`jpeg`,`the frame header is too short`);let t=await e.bytes(d,f),r=j(t,1),i=j(t,3),a=t[5]??0;if(r===0)throw k(`jpeg`,`the height is only defined after the scan`);if(i===0||a<1||a>4||f<6+a*3)throw k(`jpeg`,`the frame header is invalid`);n={width:i,height:r,components:a}}else if(l===218){if(n===void 0)throw k(`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=Fe((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:we(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 it=[137,80,78,71,13,10,26,10],at=2**31-1,ot=1e5,st=1<<20,ct={Title:`title`,Description:`description`,Author:`artist`,Copyright:`copyright`};async function lt(e){let t=8,n=0,r=0,i=!1,a,o=0,s=!1,c=!1,l=B(),u=!1;for(let d=0;!c;d+=1){if(d>=ot)throw k(`png`,`the file has too many chunks`);let f=await A(e,`png`,t,8,`a chunk header`),p=M(f,0),m=N(f,4,4);if(p>2147483647)throw k(`png`,`a chunk length is out of range`);let h=t+8;if(h+p+4>e.size)throw k(`png`,`a chunk ends past the end of the file`);if(d===0&&m!==`IHDR`)throw k(`png`,`IHDR isn't the first chunk`);let g=async()=>{if(p>st)throw k(`png`,`the ${m} chunk is too large`);return e.bytes(h,p)};switch(m){case`IHDR`:{if(d!==0||p!==13)throw k(`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>at||r>at)throw k(`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 k(`png`,`acTL is misplaced, repeated or the wrong size`);if(a=M(await g(),0),a<1)throw k(`png`,`acTL declares no frames`);break;case`fcTL`:{if(p!==26)throw k(`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 k(`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=Fe(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=ct[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,D);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,D)}else l.other=!0;break}case`IEND`:c=!0}t=h+p+4}if(!s)throw k(`png`,`there's no image data`);if(a!==void 0&&o!==a)throw k(`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:we(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 ut=1e5,dt=1<<20;function ft(e){return N(e,0,4)===`RIFF`&&N(e,8,4)===`WEBP`}async function pt(e){let t=8+L(await A(e,`webp`,0,12,`the RIFF header`),4);if(t>e.size||t<20)throw k(`webp`,`the RIFF size doesn't match the file`);let n=0,r=0,i=!1,a,o=!1,s=0,c=B(),l=!1,u=12;for(let d=0;u<t;d+=1){if(d>=ut)throw k(`webp`,`the file has too many chunks`);let f=await A(e,`webp`,u,8,`a chunk header`),p=N(f,0,4),m=L(f,4),h=u+8;if(h+m>t)throw k(`webp`,`a chunk ends past the RIFF data`);if(d===0&&p!==`VP8 `&&p!==`VP8L`&&p!==`VP8X`)throw k(`webp`,`the first chunk isn't an image header`);switch(p){case`VP8X`:{if(d!==0||m<10)throw k(`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=I(t,4)+1,r=I(t,7)+1;break}case`VP8 `:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<10)throw k(`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 k(`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 k(`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 k(`webp`,`the VP8L header is too short`);let t=await e.bytes(h,5);if(t[0]!==47)throw k(`webp`,`the VP8L signature is missing`);let a=L(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 k(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`ANMF`:{if(a?.animated!==!0)throw k(`webp`,`an animation frame without the animation flag`);if(m<16)throw k(`webp`,`an ANMF header is too short`);let t=await e.bytes(h,16),i=I(t,0)*2,o=I(t,3)*2,c=I(t,6)+1,l=I(t,9)+1;if(i+c>n||o+l>r)throw k(`webp`,`a frame doesn't fit inside the canvas`);s+=1;break}case`EXIF`:{if(m>dt)throw k(`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,Fe(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 k(`webp`,`an animation without frames`);if(s===0||n<1||r<1)throw k(`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 mt(e){let t=await ht(e);return t.orientation===1?t:{...t,decodedPixelBound:t.decodedPixelBound+t.oriented.width*t.oriented.height}}async function ht(e){let t=await e.bytes(0,16);if(P(t,it))return lt(e);if(P(t,et))return rt(e);if(ft(t))return pt(e);if(xe(t))return Ce(e);if(Ke(t))return $e(e);if(ve(t))return ye(e);throw new C(`UNSUPPORTED_FORMAT`,`The file isn't an image format the SDK reads.`,{details:{format:`unknown`}})}var gt=`AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUEAAAD/bWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAAAAAAAOcGl0bQAAAAAAAQAAAB5pbG9jAAAAAEQAAAEAAQAAAAEAAAEnAAAAcgAAAChpaW5mAAAAAAABAAAAGmluZmUCAAAAAAEAAGF2MDFDb2xvcgAAAAB+aXBycAAAAF1pcGNvAAAAFGlzcGUAAAAAAAAAMAAAACAAAAAQcGl4aQAAAAADCAgIAAAADGF2MUOBIAAAAAAAE2NvbHJuY2x4AAEADQAAgAAAAAlpcm90AQAAAAlpbWlyAAAAABlpcG1hAAAAAAAAAAEAAQYBAoMEhYYAAAB6bWRhdBIACgg4FS/7CAhoATJkRAAA66GyTOByOdAYkRkr4m7XruCgkx+mYn1Qgy/LhM4TZqjxnONsI9XbAWAHGMpcPWGmUkXOiY7S7v9FNX7P7LNof17If68icGW/sP+HwSL0D+g3eqOYaSrFfjiDyX15CtJnQA==`,_t=`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 vt(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 yt(e,t){let n={width:e.width,height:e.height},r=we(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(...vt(t,n)),a.drawImage(e,0,0),e.close(),i.transferToImageBitmap()}var bt=[[255,0,0],[0,255,0],[0,0,255],[255,255,0]];function xt(e){let[t,n,r,i]=vt(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 St=(e,t)=>t.every((t,n)=>Math.abs((e[n]??NaN)-t)<=64);function Ct(e,t,n){for(let r of[1,2,3,4,5,6,7,8]){let i=we(n,r);if(i.width===e.width&&i.height===e.height&&xt(r).every((e,n)=>St(t[n]??[],bt[e]??[])))return r}}function wt(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 Tt={width:48,height:32};function Et(){let e=new OffscreenCanvas(Tt.width,Tt.height),t=e.getContext(`2d`);if(!t)throw Error(`The worker has no 2D canvas.`);return bt.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 Dt(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 Ot=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 kt(e){let t=4294967295;for(let n of e)t=(Ot[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}var At=(e,t)=>Array.from({length:t},(n,r)=>e>>>8*(t-1-r)&255);async function jt(){let e=new Uint8Array(await(await Et().convertToBlob()).arrayBuffer()),t=Uint8Array.of(101,88,73,102,...Dt(7)),n=Uint8Array.of(...At(t.length-4,4),...t,...At(kt(t),4));return new Blob([e.slice(0,33),n,e.slice(33)],{type:`image/png`})}function Mt(e){return e[2]===255&&e[3]===224?4+((e[4]??0)<<8|(e[5]??0)):2}async function Nt(){let e=new Uint8Array(await(await Et().convertToBlob({type:`image/jpeg`,quality:1})).arrayBuffer()),t=Uint8Array.of(69,120,105,102,0,0,...Dt(7)),n=Uint8Array.of(255,225,...At(t.length+2,2),...t),r=Mt(e);return new Blob([e.slice(0,r),n,e.slice(r)],{type:`image/jpeg`})}var Pt=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function Ft(e){switch(e){case`jpeg`:return Nt();case`png`:return jt();case`avif`:return new Blob([Pt(gt)]);case`heif`:return new Blob([Pt(_t)]);default:return}}async function It(e){let t=await Ft(e);if(!t)return`unknown`;let n=await mt(s(t)),r=await createImageBitmap(t,{imageOrientation:`from-image`});try{let e=Ct(r,wt(r),n.stored);return n.orientation!==1&&e===n.orientation?`applied`:e===1?`not applied`:`unknown`}finally{r.close()}}var Lt=/* @__PURE__ */ new Map;function Rt(e,t=It){let n=Lt.get(e);return n||(n=t(e).catch(()=>(Lt.delete(e),`unknown`)),Lt.set(e,n)),n}var zt={decode:e=>createImageBitmap(e,{imageOrientation:`from-image`,premultiplyAlpha:`none`,colorSpaceConversion:`default`}),calibrate:Rt},Bt=(e,t)=>new C(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:e.format,problem:t}});async function Vt(e,t,n=zt){let r;try{r=await n.decode(e)}catch(e){throw new C(`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(),Bt(t,`this browser's orientation handling is unknown`);if(e===`not applied`)try{r=yt(r,t.orientation)}catch(e){throw new C(`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 C(`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 Ht=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 Ut=e=>Object.values(e).some(e=>e!==``);function Wt(e){let t=[];if(e.description&&t.push({tag:270,type:2,value:q([Ht(e.description),[0]])}),e.artist&&t.push({tag:315,type:2,value:q([Ht(e.artist),[0]])}),e.copyright&&t.push({tag:33432,type:2,value:q([Ht(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 Gt(e,t){let n=[e.subarray(0,2)],r=2,i=!1,a=()=>{if(i||!Ut(t))return;i=!0;let e=q([W(`Exif\0\0`),Wt(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 Kt=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 qt(e,t){let n=q([W(e),t]),r=4294967295;for(let e of n)r=(Kt[(r^e)&255]??0)^r>>>8;return q([K(t.length),n,K((r^4294967295)>>>0)])}var Jt=/* @__PURE__ */ new Set([`IHDR`,`PLTE`,`tRNS`,`IDAT`,`IEND`]),Yt={title:`Title`,description:`Description`,artist:`Author`,copyright:`Copyright`};function Xt(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(Jt.has(a)&&n.push(e.subarray(r,o)),a===`IHDR`)for(let[e,r]of Object.entries(Yt)){let i=t[e];i&&n.push(qt(`iTXt`,q([W(r),[0,0,0,0,0],Ht(i)])))}r=o}return q(n)}function Zt(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 Qt=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 $t=.2126,en=.7152,tn=.0722,nn=[$t,en,tn],J=(e,t)=>[[0,e],[255,t]],rn={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:nn},noir:{develop:{contrast:50,shadows:-20},mono:nn},sepia:{mono:nn,curves:[J(40,255),J(20,235),J(0,190)]}},an=2**20,on=e=>Math.round(e*an)/an,sn=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,cn=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,Y=4095,ln=Float32Array.from({length:256},(e,t)=>on(sn(t/255))),X=Float32Array.from({length:4096},(e,t)=>on(sn(t/Y))),Z=Float32Array.from({length:4096},(e,t)=>on(cn(t/Y))),un=Float64Array.from(X,e=>e>0?1/e:0),dn=e=>Math.min(1,Math.max(0,e)),fn=e=>Math.round(dn(e)*Y),pn=e=>Math.round(dn(e)*255),mn=(e,t)=>t===0?e:dn(e+t*(e*e*(3-2*e)-e)),Q=e=>[e(0),e(1),e(2)];function hn(e){let t=on(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(ln,t=>Z[fn(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=$t*i+en*h+tn*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=$t*r+en*a+tn*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))])*un[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=>fn(mn(e,c))));return{perChannel:p||m?void 0:Q(e=>Uint8Array.from([a,o,s][e],e=>pn(mn(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=$t*s+en*c+tn*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))])*un[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 gn(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 _n=e=>Object.values(e).every(e=>e===0);function vn(e,t){return!_n(e)||t!==null&&t.strength>0}var yn=e=>new Uint8Array(e.buffer,e.byteOffset,e.length),$=Uint8Array.from({length:256},(e,t)=>t);function bn(e,t){let n=_n(e)?void 0:hn(e),r=t===null||t.strength===0?void 0:rn[t.preset],i=(t?.strength??0)/100,a=r?.develop?hn({...Qt,...r.develop}):void 0,o=r?.curves?Q(e=>gn(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=yn(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=yn(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 xn(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 Sn(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 Cn(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=De({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 wn(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 Tn(e,t,n,r){return Sn(wn(e),Cn(t,n,r))}function En(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 Dn(e,t){let n=[t.width/e.width,0,0,t.height/e.height,t.x,t.y];return Sn(En(wn(e)),n)}function On(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 An(e){for(let t of e){if(jn.test(t))return!0;if(Mn.test(t))return!1}return!1}var jn=/[֐-ࣿיִ-﷿ﹰ-\u{10800}-\u{10FFF}\u{1E800}-\u{1EFFF}]/u,Mn=/\p{L}/u,Nn=8,Pn=12;function Fn(e){return Math.max(Nn,Math.ceil(Math.max(e.width,e.height)/Pn))}function In(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 Ln(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 Rn=(e,t,n)=>Math.min(n,Math.max(t,e));function zn(e,t){let n=Fn(e),r=(e,t,n)=>e.map(e=>Rn(e,t,n));return Ln(r(In(e.x,e.width,n),t.x,t.x+t.width),r(In(e.y,e.height,n),t.y,t.y+t.height))}function Bn(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=De({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 Vn(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,Rn(n===0?Math.floor(e):n===r?Math.ceil(e):Math.round(e),0,t)),i))}function Hn(e,t,n,r){let{turned:i,fromX:a,fromY:o}=Bn(t,n,r),s=[a(e.x),a(e.x+e.width)],c=[o(e.y),o(e.y+e.height)],[l,u]=Vn(i?c:s,r.width),[d,f]=Vn(i?s:c,r.height);return u<=l||f<=d?null:{x:l,y:d,width:u-l,height:f-d}}function Un(e,t,n,r){let i=Fn(e),{turned:a,fromX:o,fromY:s}=Bn(t,n,r),c=In(e.x,e.width,i).map(o),l=In(e.y,e.height,i).map(s);return Ln(Vn(a?l:c,r.width),Vn(a?c:l,r.height))}function Wn(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(void 0)})}async function Gn(e){if(e&&(await Wn(),e.aborted))throw e.reason}var Kn=4e6;function qn(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 Jn(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 Yn=/* @__PURE__ */ new WeakMap,Xn=/* @__PURE__ */ new WeakMap;function Zn(e){let t=Yn.get(e);t&&(t.canvas.width=0),Yn.delete(e);for(let t of Xn.get(e)?.values()??[])t.canvas.width=0;Xn.delete(e)}var Qn={x:-1e9,y:-1e9,width:2e9,height:2e9};function $n(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])=>On(e,{x:t,y:n}))}function er(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 qn({x:i,y:a,width:Math.ceil(Math.max(...n))-i,height:Math.ceil(Math.max(...r))-a},t)}async function tr(e,t,n,r,i){let a=er($n(t,n),r);if(!a)return[0,0,0,0];let o=En(t),s=Math.max(1,Math.floor(Kn/(a.width*4))),c=[0,0,0,0],l=0;for(let t=0;t<a.height;t+=s){await Gn(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=On(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 nr(e,t,n,r){let i={x:0,y:0,width:e.width,height:e.height},a=z(t.crop,e),o=Dn(t,a),s=er($n(wn(t),{x:0,y:0,width:t.width,height:t.height}),Qn),c=n.redactions.filter(e=>s!==null&&qn(e,s)!==null),l=Xn.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:cr(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 tr(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 ee=l??/* @__PURE__ */ new Map;return ee.set(t.key,{key:g,canvas:v}),Xn.set(e,ee),v}function rr(e,t){let n=Xn.get(e);if(n)for(let e of[...n.keys()])t.has(e)||n.delete(e)}async function ir(e,t,n){let r={x:0,y:0,width:e.width,height:e.height},i=z(t.base.crop,e),a=t.redactions.filter(e=>qn(e,r)!==null);if(a.length===0)return e;let o=JSON.stringify([a,i]),s=Yn.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=qn(e,r);if(e.mode===`solid`)Jn(l,t,e.colour);else{let r=zn(e,i),a=await ar(l,r,n);Jn(l,t,`#000000`),a.forEach((e,t)=>{or(l,r[t],e)})}}if(n?.aborted)throw c.width=0,n.reason;return Yn.set(e,{key:o,canvas:c}),c}async function ar(e,t,n){let r=[];for(let{x:i,y:a,width:o,height:s}of t){await Gn(n);let t=Math.max(1,Math.floor(Kn/(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 or(e,{x:t,y:n,width:r,height:i},a){let o=Math.max(1,Math.floor(Kn/(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 sr(e,t,n,r,i){let a=z(t.base.crop,n),{orientation:o}=t.base;for(let n of t.redactions)if(n.mode===`solid`){let t=Hn(n,a,o,r);t&&Jn(e,t,n.colour)}else{let t=Un(n,a,o,r);(await ar(e,t,i)).forEach((n,r)=>{or(e,t[r],n)})}}function cr(e){return e.some(e=>e.mode===`pixelate`)}var lr=100;function ur(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 dr(e,t){if(t.text===``)return;let n=t.text.split(`
2
- `);e.font=`${t.bold?`bold `:``}${lr}px ${t.font}`;let r=An(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 fr(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 nr(a,t,n,i),s=z(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 pr(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 mr(e,t){let n=xn(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 hr(e,t,n,r,i,a){let o=z(t.base.crop,n),s;for(let n of t.layers){if(!n.visible||n.opacity===0)continue;await Gn(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(...Cn(o,t.base.orientation,r)),n.kind===`drawing`?pr(c,n):mr(c,n)):(c.setTransform(...Tn(n,o,t.base.orientation,r)),n.kind===`shape`?ur(c,n):n.kind===`text`?dr(c,n):await fr(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&&rr(t,c)}}var gr=4e6;function _r(e,t){return Ee(e.output,Te(e,t))}async function vr(e,t,n,r,i=()=>void 0){let{develop:a,filter:o}=t.base,s=vn(a,o),c=z(t.base.crop,e),l=Te(t,e),u=Ee(t.output,l),d=new OffscreenCanvas(u.width,u.height),f=d.getContext(`2d`,{colorSpace:`srgb`,alpha:!n,willReadFrequently:s||cr(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 ir(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=bn(a,o),t=Math.max(1,Math.floor(gr/(u.width*4)));for(let n=0;n<u.height;n+=t){if(r&&(await Wn(),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 hr(f,t,e,u,i,r),await sr(f,t,e,u,r),d}var yr={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`};async function br(e,t,n,r,i){let a=yr[n.type],o=await vr(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 C(`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`?Gt(c,t.metadata):n.type===`png`?Xt(c,t.metadata):Zt(c);return new Blob([l.slice()],{type:a})}async function xr(e,t,n,r,i,a){let o=Te(n,t),{width:s,height:c}=fe(r),l=Math.min(r.pixelRatio,4),u=pe(o,r),d=u.scale*l,f=Math.min(1,d),p=await vr(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 Sr(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 Cr=[`layers`,`drawings`,`redactions`];function wr(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=(e,n,r)=>{E(e,r);for(let r of n.layers){let n=r.kind===`image`?t.get(r.source):void 0;n&&E(e,n)}};ue({probe:({file:e})=>mt(s(e)),async register({id:e,file:n,probe:r,limits:i},{signal:a}){if(t.has(e))throw TypeError(`The source id "${e}" is already in use.`);let o=await mt(s(n));if(!Sr(o,r))throw new C(`INVALID_IMAGE`,`The probe doesn't describe this file.`,{details:{format:o.format,problem:`the probe describes another file`}});T(w.resolve(i),n.size,o);let c=await Vt(n,o);if(a.aborted)throw c.close(),a.reason;return t.set(e,c),{width:c.width,height:c.height}},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,limits:i},{signal:a}){me(e,Cr);let o=t.get(e.base.source);if(!o)throw TypeError(`There's no source with the id "${e.base.source}".`);let s=w.resolve(i);return E(s,_r(e,o)),e.redactions.length>0&&r(s,e,o),br(o,e,n,a,e=>t.get(e))},attachCanvas({id:e,canvas:t}){let r=t.getContext(`2d`,{colorSpace:`srgb`});if(!r)throw Error(`The worker has no 2D canvas.`);n.set(e,r)},async render({id:e,plan:i,view:a,limits:o},{signal:s}){me(i,Cr),E(w.resolve(o),fe(a));let c=n.get(e);if(!c)throw TypeError(`There's no canvas with the id "${e}".`);let l=t.get(i.base.source);if(!l)throw TypeError(`There's no source with the id "${i.base.source}".`);i.redactions.length>0&&r(w.resolve(o),i,l),await xr(c,l,i,a,s,e=>t.get(e))},detachCanvas({id:e}){let t=n.get(e);t&&(t.canvas.width=0,t.canvas.height=0),n.delete(e)},snapshot({id:e}){let t=n.get(e);if(!t)throw TypeError(`There's no canvas with the id "${e}".`);return createImageBitmap(t.canvas)},release({id:e}){let n=t.get(e);n&&Zn(n),n?.close(),t.delete(e)}},{...e,packageVersion:`0.5.0`})}wr();
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},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){let{width:r,height:i}=n.oriented,a={maxFileSize:t,maxImageDimension:Math.max(r,i),maxImagePixels:r*i,maxFrames:n.frames,maxDecodedSize:n.decodedPixelBound*4};return D.filter(t=>e.check(t,a[t])===`warning`)}function k(e,t){e.check(`maxImageDimension`,Math.max(t.width,t.height)),e.check(`maxImagePixels`,t.width*t.height)}function A(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 ue(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 de(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 j(e,t){return new w(`INVALID_IMAGE`,`Invalid ${e}: ${t}.`,{details:{format:e,problem:t}})}async function M(e,t,n,r,i){if(n+r>e.size)throw j(t,`${i} ends past the end of the file`);return e.bytes(n,r)}function fe(e,t){return(e[t]??0)<<8|(e[t+1]??0)}function N(e,t){return((e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0}function P(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 pe(e,t){return t.every((t,n)=>e[n]===t)}function F(e,t){return(e[t]??0)|(e[t+1]??0)<<8}function I(e,t){return(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16}function L(e,t){return((e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24)>>>0}function me(e,t){return L(e,t)|0}var R=4096;function he(e,t,n,r){let i=1<<n,a=i+1,o=new Uint16Array(R),s=new Uint8Array(R),c=new Uint8Array(R);for(let e=0;e<i;e+=1)s[e]=e,c[e]=e;let l=new Uint8Array(R),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 j(`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 j(`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 j(`gif`,`a frame's data starts with a code that isn't a colour`)}else if(t>d)throw j(`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 j(`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<R&&(o[d]=f,s[d]=b,c[d]=c[f],d+=1),d>=1<<u&&u<12&&(u+=1),f=t}throw j(`gif`,`a frame's data holds fewer pixels than the frame`)}var z={offset:0,size:0},ge=[[0,8],[4,8],[2,4],[1,2]];function _e(e,t){let{width:n,height:r}=t,i=new Uint8Array(n*r);if(he(e,t.data,t.codeSize,i),!t.interlaced)return i;let a=new Uint8Array(n*r),o=0;for(let[e,t]of ge)for(let s=e;s<r;s+=t)a.set(i.subarray(o,o+n),s*n),o+=n;return a}function ve(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},reset(){n.fill(0),r=-1,i=void 0},next(){let o=t.frames[r+1];if(!o)throw RangeError(`The GIF has no more frames.`);let s=_e(e,o),c=o.table??t.table??z,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 ye=4096,be=17408;function xe(e,t){let n=t;for(;;){if(n>=e.length)throw j(`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 j(`gif`,`a data sub-block ends past the end of the file`);n+=t}}function B(e,t,n,r){if(t+n>e.length)throw j(`gif`,`${r} ends past the end of the file`)}function Se(e,t,n){let r=2**(n+1);return B(e,t,3*r,`a colour table`),{offset:t,size:r}}function Ce(e){B(e,0,13,`the logical screen descriptor`);let t=P(e,0,6);if(t!==`GIF87a`&&t!==`GIF89a`)throw j(`gif`,`not a GIF`);let n=F(e,6),r=F(e,8);if(n<1||r<1)throw j(`gif`,`the logical screen has no pixels`);let i=e[10],a=13,o=null;i&128&&(o=Se(e,a,i&7),a+=3*o.size);let s=[],c=null,l=0,u=0,d=null;for(let t=0;;t+=1){if(t>=be)throw j(`gif`,`the file has too many blocks`);try{B(e,a,1,`a block`);let t=e[a];if(t===59)break;if(t===33){B(e,a,2,`an extension label`);let t=e[a+1];if(t===249){if(B(e,a+2,6,`a graphic control extension`),e[a+2]!==4)throw j(`gif`,`a graphic control extension is the wrong size`);let t=e[a+3],n=t>>>2&7;u=n===4?3:n>4?0:n,l=F(e,a+4),d=t&1?e[a+6]:null}else if(t===255){B(e,a+2,12,`an application extension`);let t=P(e,a+3,11);e[a+2]===11&&(t===`NETSCAPE2.0`||t===`ANIMEXTS1.0`)&&a+18<=e.length&&e[a+14]===3&&e[a+15]===1&&(c=F(e,a+16))}a=xe(e,a+2);continue}if(t!==44)throw j(`gif`,`an unknown block`);B(e,a,10,`an image descriptor`);let i=F(e,a+1),o=F(e,a+3),f=F(e,a+5),p=F(e,a+7);if(s.length===0&&i===0&&o===0&&f>=n&&p>=r&&(n=f,r=p),f<1||p<1||i+f>n||o+p>r)throw j(`gif`,`a frame doesn't fit inside the logical screen`);let m=e[a+9];a+=10;let h=null;m&128&&(h=Se(e,a,m&7),a+=3*h.size),B(e,a,1,`an LZW minimum code size`);let g=e[a];if(g<1||g>8)throw j(`gif`,`a frame's LZW minimum code size is out of range`);let _=a+1;if(a=xe(e,_),s.length>=4096)throw new w(`TOO_MANY_FRAMES`,`A GIF holds at most ${ye} frames.`,{details:{limit:`maxFrames`,maximum:ye,actual:s.length+1,unit:`count`}});s.push({x:i,y:o,width:f,height:p,delay:l,disposal:u,transparent:d,interlaced:!!(m&64),table:h,codeSize:g,data:_}),l=0,u=0,d=null}catch(e){if(s.length>0&&T(e)&&e.code===`INVALID_IMAGE`)break;throw e}}if(s.length===0)throw j(`gif`,`there are no frames`);return{width:n,height:r,loop:c,table:o,frames:s}}var we=Object.freeze({location:!1,camera:!1,timestamps:!1,thumbnail:!1,colourProfile:!1,other:!1}),Te=Object.freeze({title:``,description:``,artist:``,copyright:``}),Ee=2e3;function De(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 Oe=/* @__PURE__ */ new Set([12,40,52,56,108,124]);function ke(e){return P(e,0,2)===`BM`}async function Ae(e){let t=await M(e,`bmp`,0,18,`the file header`),n=L(t,10),r=L(t,14);if(!Oe.has(r))throw j(`bmp`,`the DIB header size is unknown`);let i=await M(e,`bmp`,14,r,`the DIB header`),a,o,s;if(r===12?(a=F(i,4),o=F(i,6),s=F(i,10)):(a=me(i,4),o=Math.abs(me(i,8)),s=F(i,14)),F(i,r===12?8:12)!==1)throw j(`bmp`,`the plane count isn't 1`);if(a<1||o<1||a>2147483647||o>2147483647)throw j(`bmp`,`the dimensions are out of range`);if(![1,4,8,16,24,32].includes(s))throw j(`bmp`,`the bit depth is unsupported`);if(n<14+r||n>=e.size)throw j(`bmp`,`the pixel data starts outside the file`);let c=r===124&&[1279872587,1296188740].includes(L(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:{...we,colourProfile:c},keepable:Te}}var je=1e6;function Me(e){let t=P(e,0,6);return t===`GIF87a`||t===`GIF89a`}async function Ne(e,t){let n=t;for(;;){let t=(await M(e,`gif`,n,1,`a data sub-block`))[0]??0;if(n+=1,t===0)return n;if(n+t>e.size)throw j(`gif`,`a data sub-block ends past the end of the file`);n+=t}}async function Pe(e){let t=await M(e,`gif`,0,13,`the logical screen descriptor`),n=F(t,6),r=F(t,8);if(n<1||r<1)throw j(`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>=je)throw j(`gif`,`the file has too many blocks`);try{let t=(await M(e,`gif`,a,1,`a block`))[0];if(t===59)break;if(t===33){let t=(await M(e,`gif`,a+1,1,`an extension label`))[0];if(t===249){let t=await M(e,`gif`,a+2,6,`a graphic control extension`);if(t[0]!==4)throw j(`gif`,`a graphic control extension is the wrong size`);(t[1]??0)&1&&(s=!0)}else if(t===255){let t=P(await M(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 Ne(e,a+2);continue}if(t===44){let t=await M(e,`gif`,a,10,`an image descriptor`),i=F(t,1),s=F(t,3),c=F(t,5),l=F(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 j(`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 M(e,`gif`,a,1,`an LZW minimum code size`))[0]??0;if(d<1||d>8)throw j(`gif`,`a frame's LZW minimum code size is out of range`);a=await Ne(e,a+1),o+=1;continue}throw j(`gif`,`an unknown block`)}catch(e){if(o>0&&T(e)&&e.code===`INVALID_IMAGE`)break;throw e}}if(o===0)throw j(`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:{...we,other:c},keepable:Te}}function Fe(e,t){return t>=5?{width:e.height,height:e.width}:e}function V(e,t){return e??{x:0,y:0,width:t.width,height:t.height}}function Ie(e,t){let{width:n,height:r}=V(e.base.crop,t);return e.base.orientation.rotate%180==0?{width:n,height:r}:{width:r,height:n}}function Le(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 Re(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 ze(){return{orientation:1,location:!1,camera:!1,timestamps:!1,thumbnail:!1,other:!1,title:``,description:``,artist:``,copyright:``}}function Be(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}var Ve=8,He=1e3,Ue=/* @__PURE__ */ new Set([271,272,42033,42035,42036,42037,37500]),We=/* @__PURE__ */ new Set([306,36867,36868,36880,36881,36882]),Ge=/* @__PURE__ */ new Set([34665,34853,40965,513,514]),Ke={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 qe(e,t){let n=ze();if(e.length<8)throw j(t,`the EXIF block is too short`);let r=e[0]===73&&e[1]===73;if(!r&&(e[0]!==77||e[1]!==77))throw j(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 j(t,`the EXIF block isn't TIFF`);let o=(n,r,i,o)=>{let s=r*(Ke[n]??1),c=s<=4?i:a(i);if(c+s>e.length)throw j(t,`an EXIF value ends past the block`);let l=e.subarray(c,c+s),u=(o?new TextDecoder(`utf-16le`).decode(l):Be(l)).replace(/\0+$/,``);return De(u,2e3)?[...u].slice(0,Ee).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 j(t,`EXIF directories loop`);if(s.size>=Ve)throw j(t,`the EXIF block has too many directories`);if(s.add(r),r+2>e.length)throw j(t,`an EXIF directory starts past the block`);let u=i(r);if(u>He||r+2+u*12+4>e.length)throw j(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):Ue.has(s)?n.camera=!0:We.has(s)?n.timestamps=!0:Ge.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 Je=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`,`heic`,`heix`,`heim`,`heis`,`hevc`,`hevx`,`mif1`,`mif2`,`msf1`]),Ye=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`]),Xe=/* @__PURE__ */ new Set([`av01`,`hvc1`]),Ze=/* @__PURE__ */ new Set([`urn:mpeg:mpegB:cicp:systems:auxiliary:alpha`,`urn:mpeg:hevc:2015:auxid:1`]),Qe=/* @__PURE__ */ new Set([`dimg`,`auxl`,`thmb`]),$e=1024,et=4<<20,tt=4096,nt=1024,rt=1<<20;function it(e){return P(e,4,4)===`ftyp`&&Je.has(P(e,8,4))}function at(e,t){return N(e,t)*2**32+N(e,t+4)}function H(e,t,n,r){let i=(t,n)=>{if(t.at+n>r)throw j(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,fe(t,a.at-2)},u32(){return i(a,4),a.at+=4,N(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,at(t,a.at-8);throw j(e,`a field has an unsupported size`)},fourcc(){return i(a,4),a.at+=4,P(t,a.at-4,4)},string(){let n=t.subarray(a.at,r).indexOf(0);if(n<0)throw j(e,`a string isn't terminated inside its box`);let i=P(t,a.at,n);return a.at+=n+1,i}};return a}function ot(e,t,n,r){let i=[],a=n;for(;a<r;){if(i.length>=tt)throw j(e,`a box holds too many boxes`);if(a+8>r)throw j(e,`a box header ends past its parent`);let n=N(t,a),o=8;if(n===1){if(a+16>r)throw j(e,`a box header ends past its parent`);n=at(t,a+8),o=16}else n===0&&(n=r-a);if(n<o||a+n>r)throw j(e,`a box ends past its parent`);i.push({type:P(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 j(e,`a box that may appear once appears twice`);return r[0]}var st=[[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 ct(e){return st.find(([t])=>t===e)?.[1]??[1,0,0,1]}function lt(e,t){let[n=0,r=0,i=0,a=0]=ct(t),[o=0,s=0,c=0,l=0]=ct(e),u=[n*o+r*c,n*s+r*l,i*o+a*c,i*s+a*l];return st.find(([,e])=>e.every((e,t)=>e===u[t]))?.[0]??1}function ut(e,t,n){let r=n=>{let r=t.u32(),i=t.u32();if(i===0)throw j(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 j(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 j(e,`a clean aperture lies outside the image`);return{width:i,height:a}}var dt=[1,8,3,6];async function ft(e){let t=N(await M(e,`heif`,0,8,`the ftyp box`),0);if(t<16||t>4096)throw j(`heif`,`the ftyp box has an invalid size`);let n=await M(e,`heif`,8,t-8,`the ftyp box`),r=[P(n,0,4)];for(let e=8;e+4<=n.length;e+=4)r.push(P(n,e,4));let i=r.some(e=>Ye.has(e))?`avif`:`heif`,a,o=t;for(let t=0;o<e.size;t+=1){if(t>=$e)throw j(i,`the file has too many boxes`);let n=await M(e,i,o,8,`a box header`),r=N(n,0),s=8;if(r===1?(r=at(await M(e,i,o+8,8,`a box header`),0),s=16):r===0&&(r=e.size-o),r<s||o+r>e.size)throw j(i,`a box ends past the end of the file`);let c=P(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 j(i,`there are two meta boxes`);a={start:o+s,end:o+r}}o+=r}if(a===void 0)throw j(i,`there's no meta box`);if(a.end-a.start>et)throw j(i,`the meta box is too large`);let s=await M(e,i,a.start,a.end-a.start,`the meta box`),c=ot(i,s,4,s.length),l=U(i,c,`hdlr`),u=l&&H(i,s,l.start+8,l.end);if(u===void 0||u.fourcc()!==`pict`)throw j(i,`the meta box isn't for a picture`);let d=U(i,c,`pitm`);if(d===void 0)throw j(i,`there's no primary item`);let f=H(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 j(i,`there's no item information`);let _=H(i,s,g.start,g.end),v=_.u8();_.at+=3;let y=v===0?_.u16():_.u32(),b=ot(i,s,_.at,g.end).filter(e=>e.type===`infe`);if(b.length!==y)throw j(i,`the item count doesn't match the item entries`);for(let e of b){let t=H(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 j(i,`two items share an ID`);h.set(r.id,r)}let x=h.get(m);if(x===void 0)throw j(i,`the primary item isn't declared`);if(x.type!==`grid`&&!Xe.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 ot(i,s,C.start+4,C.end)){let n=H(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 j(i,`there are no item properties`);let te=ot(i,s,ee.start,ee.end),ne=U(i,te,`ipco`);if(ne===void 0)throw j(i,`there's no property container`);let re=ot(i,s,ne.start,ne.end),ie=/* @__PURE__ */ new Map;for(let e of te.filter(e=>e.type===`ipma`)){let t=H(i,s,e.start,e.end),n=t.u8();t.u16();let r=(t.u8()&1)==1,a=t.u32();if(a>tt)throw j(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 j(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 j(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 j(i,`an image item has no single ispe`);let r=H(i,s,n.start+4,n.end),a={width:r.u32(),height:r.u32()};if(a.width<1||a.height<1)throw j(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=H(i,s,le.start,le.end),n=t.u8();if(t.at+=3,n>2)throw j(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>tt)throw j(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 j(i,`an item's data lies outside the file`);f.push({offset:n,length:d})}if(ce.has(r))throw j(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 j(i,`an item's data has no location`);let a=r.extents.reduce((e,t)=>e+t.length,0);if(a>n)throw j(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 j(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=>Qe.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 j(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 A=[...O].filter(([,e])=>e===0).map(([e])=>e),ue=0;for(;A.length>0;){let e=A.pop()??0;ue+=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&&A.push(e)}}if(ue!==D.size)throw j(i,`item references form a cycle`);let de=0;for(let e of D){let t=oe(e);de+=t.width*t.height,h.get(e)?.type===`grid`&&await fe(e,t)}async function fe(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 j(i,`a grid doesn't name its tiles once`);if(r.length>nt)throw j(i,`a grid has too many tiles`);let a=await T(e,64),o=H(i,a,0,a.length);if(o.u8()!==0)throw j(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 j(i,`a grid's tile count doesn't match its rows and columns`);if(u.width!==t.width||u.height!==t.height)throw j(i,`a grid's output differs from its ispe`);let d;for(let e of r){if(!Xe.has(h.get(e)?.type??``))throw j(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 j(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 j(i,`a grid's output doesn't fit its tiles`)}let pe=oe(m),F=pe,I=1,L=!1;for(let e of ie.get(m)??[])if(e.type===`clap`){if(L||F!==pe)throw j(i,`a clean aperture follows a transformation`);F=ut(i,H(i,s,e.start,e.end),pe)}else if(e.type===`irot`){L=!0;let t=H(i,s,e.start,e.end);I=lt(I,dt[t.u8()&3]??1)}else if(e.type===`imir`){L=!0;let t=H(i,s,e.start,e.end);I=lt(I,t.u8()&1?2:4)}let me=e=>S.filter(t=>t.type===e&&t.to.includes(m)),R=me(`auxl`).some(e=>ae(e.from,`auxC`).some(e=>{let t=H(i,s,e.start+4,e.end);return Ze.has(t.string())})),he=ae(m,`colr`).some(e=>{let t=H(i,s,e.start,e.end).fourcc();return t===`prof`||t===`rICC`}),z=ze(),ge=[...h.values()].find(e=>e.type===`Exif`);if(ge!==void 0){let e=await T(ge.id,rt);if(e.length<4||4+N(e,0)>e.length)throw j(i,`the EXIF item's header offset is out of range`);Object.assign(z,qe(e.subarray(4+N(e,0)),i))}let _e=z.other||[...h.values()].some(e=>e.type===`mime`||e.type===`uri `);return{format:i,stored:F,oriented:Fe(F,I),orientation:I,frames:1,hasAlpha:R,decodedPixelBound:de,metadata:{location:z.location,camera:z.camera,timestamps:z.timestamps,thumbnail:z.thumbnail||me(`thmb`).length>0,colourProfile:he,other:_e},keepable:{title:z.title,description:z.description,artist:z.artist,copyright:z.copyright}}}var pt=[255,216,255],mt=1e4;function ht(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}async function gt(e){let t=2,n,r=!1,i=ze(),a=!1,o=!1;for(let s=0;!r;s+=1){if(s>=mt)throw j(`jpeg`,`the file has too many segments`);let c=await M(e,`jpeg`,t,2,`a marker`);if(c[0]!==255)throw j(`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 j(`jpeg`,`the image ends before its first scan`);t+=2;continue}let u=fe(await M(e,`jpeg`,t+2,2,`a segment length`),0);if(u<2)throw j(`jpeg`,`a segment length is out of range`);let d=t+4,f=u-2;if(d+f>e.size)throw j(`jpeg`,`a segment ends past the end of the file`);if(ht(l)){if(n!==void 0)throw j(`jpeg`,`there's more than one frame header before the scan`);if(f<6)throw j(`jpeg`,`the frame header is too short`);let t=await e.bytes(d,f),r=fe(t,1),i=fe(t,3),a=t[5]??0;if(r===0)throw j(`jpeg`,`the height is only defined after the scan`);if(i===0||a<1||a>4||f<6+a*3)throw j(`jpeg`,`the frame header is invalid`);n={width:i,height:r,components:a}}else if(l===218){if(n===void 0)throw j(`jpeg`,`the scan comes before a frame header`);r=!0}else if(l===225&&f>=6){if(P(await e.bytes(d,Math.min(f,64)),0,6)===`Exif\0\0`){if(a)i.other=!0;else{a=!0;let t=qe((await e.bytes(d,f)).subarray(6),`jpeg`);Object.assign(i,t)}}else i.other=!0}else l===226&&f>=12?P(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:Fe(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 _t=[137,80,78,71,13,10,26,10],vt=2**31-1,yt=1e5,bt=1<<20,xt={Title:`title`,Description:`description`,Author:`artist`,Copyright:`copyright`};async function St(e){let t=8,n=0,r=0,i=!1,a,o=0,s=!1,c=!1,l=ze(),u=!1;for(let d=0;!c;d+=1){if(d>=yt)throw j(`png`,`the file has too many chunks`);let f=await M(e,`png`,t,8,`a chunk header`),p=N(f,0),m=P(f,4,4);if(p>2147483647)throw j(`png`,`a chunk length is out of range`);let h=t+8;if(h+p+4>e.size)throw j(`png`,`a chunk ends past the end of the file`);if(d===0&&m!==`IHDR`)throw j(`png`,`IHDR isn't the first chunk`);let g=async()=>{if(p>bt)throw j(`png`,`the ${m} chunk is too large`);return e.bytes(h,p)};switch(m){case`IHDR`:{if(d!==0||p!==13)throw j(`png`,`IHDR is repeated or the wrong size`);let e=await g();if(n=N(e,0),r=N(e,4),n<1||r<1||n>vt||r>vt)throw j(`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 j(`png`,`acTL is misplaced, repeated or the wrong size`);if(a=N(await g(),0),a<1)throw j(`png`,`acTL declares no frames`);break;case`fcTL`:{if(p!==26)throw j(`png`,`an fcTL is the wrong size`);let e=await g(),t=N(e,4),i=N(e,8),a=N(e,12),s=N(e,16);if(t<1||i<1||a+t>n||s+i>r)throw j(`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=qe(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=xt[P(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,Ee);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,Ee)}else l.other=!0;break}case`IEND`:c=!0}t=h+p+4}if(!s)throw j(`png`,`there's no image data`);if(a!==void 0&&o!==a)throw j(`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:Fe(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 Ct=1e5,wt=1<<20;function Tt(e){return P(e,0,4)===`RIFF`&&P(e,8,4)===`WEBP`}async function Et(e){let t=8+L(await M(e,`webp`,0,12,`the RIFF header`),4);if(t>e.size||t<20)throw j(`webp`,`the RIFF size doesn't match the file`);let n=0,r=0,i=!1,a,o=!1,s=0,c=ze(),l=!1,u=12;for(let d=0;u<t;d+=1){if(d>=Ct)throw j(`webp`,`the file has too many chunks`);let f=await M(e,`webp`,u,8,`a chunk header`),p=P(f,0,4),m=L(f,4),h=u+8;if(h+m>t)throw j(`webp`,`a chunk ends past the RIFF data`);if(d===0&&p!==`VP8 `&&p!==`VP8L`&&p!==`VP8X`)throw j(`webp`,`the first chunk isn't an image header`);switch(p){case`VP8X`:{if(d!==0||m<10)throw j(`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=I(t,4)+1,r=I(t,7)+1;break}case`VP8 `:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<10)throw j(`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 j(`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 j(`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 j(`webp`,`the VP8L header is too short`);let t=await e.bytes(h,5);if(t[0]!==47)throw j(`webp`,`the VP8L signature is missing`);let a=L(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 j(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`ANMF`:{if(a?.animated!==!0)throw j(`webp`,`an animation frame without the animation flag`);if(m<16)throw j(`webp`,`an ANMF header is too short`);let t=await e.bytes(h,16),i=I(t,0)*2,o=I(t,3)*2,c=I(t,6)+1,l=I(t,9)+1;if(i+c>n||o+l>r)throw j(`webp`,`a frame doesn't fit inside the canvas`);s+=1;break}case`EXIF`:{if(m>wt)throw j(`webp`,`the EXIF chunk is too large`);let t=await e.bytes(h,m),n=P(t,0,6)===`Exif\0\0`?t.subarray(6):t;Object.assign(c,qe(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 j(`webp`,`an animation without frames`);if(s===0||n<1||r<1)throw j(`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 Dt(e){let t=await Ot(e);return t.orientation===1?t:{...t,decodedPixelBound:t.decodedPixelBound+t.oriented.width*t.oriented.height}}async function Ot(e){let t=await e.bytes(0,16);if(pe(t,_t))return St(e);if(pe(t,pt))return gt(e);if(Tt(t))return Et(e);if(Me(t))return Pe(e);if(it(t))return ft(e);if(ke(t))return Ae(e);throw new w(`UNSUPPORTED_FORMAT`,`The file isn't an image format the SDK reads.`,{details:{format:`unknown`}})}var kt=`AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUEAAAD/bWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAAAAAAAOcGl0bQAAAAAAAQAAAB5pbG9jAAAAAEQAAAEAAQAAAAEAAAEnAAAAcgAAAChpaW5mAAAAAAABAAAAGmluZmUCAAAAAAEAAGF2MDFDb2xvcgAAAAB+aXBycAAAAF1pcGNvAAAAFGlzcGUAAAAAAAAAMAAAACAAAAAQcGl4aQAAAAADCAgIAAAADGF2MUOBIAAAAAAAE2NvbHJuY2x4AAEADQAAgAAAAAlpcm90AQAAAAlpbWlyAAAAABlpcG1hAAAAAAAAAAEAAQYBAoMEhYYAAAB6bWRhdBIACgg4FS/7CAhoATJkRAAA66GyTOByOdAYkRkr4m7XruCgkx+mYn1Qgy/LhM4TZqjxnONsI9XbAWAHGMpcPWGmUkXOiY7S7v9FNX7P7LNof17If68icGW/sP+HwSL0D+g3eqOYaSrFfjiDyX15CtJnQA==`,At=`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 jt(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 Mt(e,t){let n={width:e.width,height:e.height},r=Fe(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(...jt(t,n)),a.drawImage(e,0,0),e.close(),i.transferToImageBitmap()}var Nt=[[255,0,0],[0,255,0],[0,0,255],[255,255,0]];function Pt(e){let[t,n,r,i]=jt(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 Ft=(e,t)=>t.every((t,n)=>Math.abs((e[n]??NaN)-t)<=64);function It(e,t,n){for(let r of[1,2,3,4,5,6,7,8]){let i=Fe(n,r);if(i.width===e.width&&i.height===e.height&&Pt(r).every((e,n)=>Ft(t[n]??[],Nt[e]??[])))return r}}function Lt(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 Rt={width:48,height:32};function zt(){let e=new OffscreenCanvas(Rt.width,Rt.height),t=e.getContext(`2d`);if(!t)throw Error(`The worker has no 2D canvas.`);return Nt.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 Bt(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 Vt=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 Ht(e){let t=4294967295;for(let n of e)t=(Vt[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}var Ut=(e,t)=>Array.from({length:t},(n,r)=>e>>>8*(t-1-r)&255);async function Wt(){let e=new Uint8Array(await(await zt().convertToBlob()).arrayBuffer()),t=Uint8Array.of(101,88,73,102,...Bt(7)),n=Uint8Array.of(...Ut(t.length-4,4),...t,...Ut(Ht(t),4));return new Blob([e.slice(0,33),n,e.slice(33)],{type:`image/png`})}function Gt(e){return e[2]===255&&e[3]===224?4+((e[4]??0)<<8|(e[5]??0)):2}async function Kt(){let e=new Uint8Array(await(await zt().convertToBlob({type:`image/jpeg`,quality:1})).arrayBuffer()),t=Uint8Array.of(69,120,105,102,0,0,...Bt(7)),n=Uint8Array.of(255,225,...Ut(t.length+2,2),...t),r=Gt(e);return new Blob([e.slice(0,r),n,e.slice(r)],{type:`image/jpeg`})}var qt=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function Jt(e){switch(e){case`jpeg`:return Kt();case`png`:return Wt();case`avif`:return new Blob([qt(kt)]);case`heif`:return new Blob([qt(At)]);default:return}}async function Yt(e){let t=await Jt(e);if(!t)return`unknown`;let n=await Dt(s(t)),r=await createImageBitmap(t,{imageOrientation:`from-image`});try{let e=It(r,Lt(r),n.stored);return n.orientation!==1&&e===n.orientation?`applied`:e===1?`not applied`:`unknown`}finally{r.close()}}var Xt=/* @__PURE__ */ new Map;function Zt(e,t=Yt){let n=Xt.get(e);return n||(n=t(e).catch(()=>(Xt.delete(e),`unknown`)),Xt.set(e,n)),n}var Qt={decode:e=>createImageBitmap(e,{imageOrientation:`from-image`,premultiplyAlpha:`none`,colorSpaceConversion:`default`}),calibrate:Zt},$t=(e,t,n)=>createImageBitmap(new ImageData(e,t,n),{premultiplyAlpha:`none`});async function en(e,t,n){let r=new Uint8Array(await e.arrayBuffer()),i=Ce(r);if(i.frames.length!==t.frames||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=ve(r,i).next();return(n.fromPixels??$t)(a,i.width,i.height)}var tn=(e,t)=>new w(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:e.format,problem:t}});async function nn(e,t,n=Qt){let r;try{r=t.format===`gif`?await en(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(),tn(t,`this browser's orientation handling is unknown`);if(e===`not applied`)try{r=Mt(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 rn=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 an=e=>Object.values(e).some(e=>e!==``);function on(e){let t=[];if(e.description&&t.push({tag:270,type:2,value:q([rn(e.description),[0]])}),e.artist&&t.push({tag:315,type:2,value:q([rn(e.artist),[0]])}),e.copyright&&t.push({tag:33432,type:2,value:q([rn(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 sn(e,t){let n=[e.subarray(0,2)],r=2,i=!1,a=()=>{if(i||!an(t))return;i=!0;let e=q([W(`Exif\0\0`),on(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 cn=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 ln(e,t){let n=q([W(e),t]),r=4294967295;for(let e of n)r=(cn[(r^e)&255]??0)^r>>>8;return q([K(t.length),n,K((r^4294967295)>>>0)])}var un=/* @__PURE__ */ new Set([`IHDR`,`PLTE`,`tRNS`,`IDAT`,`IEND`]),dn={title:`Title`,description:`Description`,artist:`Author`,copyright:`Copyright`};function fn(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(un.has(a)&&n.push(e.subarray(r,o)),a===`IHDR`)for(let[e,r]of Object.entries(dn)){let i=t[e];i&&n.push(ln(`iTXt`,q([W(r),[0,0,0,0,0],rn(i)])))}r=o}return q(n)}function pn(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 mn=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 hn=.2126,gn=.7152,_n=.0722,vn=[hn,gn,_n],J=(e,t)=>[[0,e],[255,t]],yn={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:vn},noir:{develop:{contrast:50,shadows:-20},mono:vn},sepia:{mono:vn,curves:[J(40,255),J(20,235),J(0,190)]}},bn=2**20,xn=e=>Math.round(e*bn)/bn,Sn=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Cn=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,Y=4095,wn=Float32Array.from({length:256},(e,t)=>xn(Sn(t/255))),X=Float32Array.from({length:4096},(e,t)=>xn(Sn(t/Y))),Z=Float32Array.from({length:4096},(e,t)=>xn(Cn(t/Y))),Tn=Float64Array.from(X,e=>e>0?1/e:0),En=e=>Math.min(1,Math.max(0,e)),Dn=e=>Math.round(En(e)*Y),On=e=>Math.round(En(e)*255),kn=(e,t)=>t===0?e:En(e+t*(e*e*(3-2*e)-e)),Q=e=>[e(0),e(1),e(2)];function An(e){let t=xn(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(wn,t=>Z[Dn(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=hn*i+gn*h+_n*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=hn*r+gn*a+_n*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))])*Tn[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=>Dn(kn(e,c))));return{perChannel:p||m?void 0:Q(e=>Uint8Array.from([a,o,s][e],e=>On(kn(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=hn*s+gn*c+_n*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))])*Tn[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 jn(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 Mn=e=>Object.values(e).every(e=>e===0);function Nn(e,t){return!Mn(e)||t!==null&&t.strength>0}var Pn=e=>new Uint8Array(e.buffer,e.byteOffset,e.length),$=Uint8Array.from({length:256},(e,t)=>t);function Fn(e,t){let n=Mn(e)?void 0:An(e),r=t===null||t.strength===0?void 0:yn[t.preset],i=(t?.strength??0)/100,a=r?.develop?An({...mn,...r.develop}):void 0,o=r?.curves?Q(e=>jn(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=Pn(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=Pn(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 In(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 Ln(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 Rn(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=Re({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 zn(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 Bn(e,t,n,r){return Ln(zn(e),Rn(t,n,r))}function Vn(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 Hn(e,t){let n=[t.width/e.width,0,0,t.height/e.height,t.x,t.y];return Ln(Vn(zn(e)),n)}function Un(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 Wn(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 Gn(e){for(let t of e){if(Kn.test(t))return!0;if(qn.test(t))return!1}return!1}var Kn=/[֐-ࣿיִ-﷿ﹰ-\u{10800}-\u{10FFF}\u{1E800}-\u{1EFFF}]/u,qn=/\p{L}/u,Jn=8,Yn=12;function Xn(e){return Math.max(Jn,Math.ceil(Math.max(e.width,e.height)/Yn))}function Zn(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 Qn(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 $n=(e,t,n)=>Math.min(n,Math.max(t,e));function er(e,t){let n=Xn(e),r=(e,t,n)=>e.map(e=>$n(e,t,n));return Qn(r(Zn(e.x,e.width,n),t.x,t.x+t.width),r(Zn(e.y,e.height,n),t.y,t.y+t.height))}function tr(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=Re({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 nr(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,$n(n===0?Math.floor(e):n===r?Math.ceil(e):Math.round(e),0,t)),i))}function rr(e,t,n,r){let{turned:i,fromX:a,fromY:o}=tr(t,n,r),s=[a(e.x),a(e.x+e.width)],c=[o(e.y),o(e.y+e.height)],[l,u]=nr(i?c:s,r.width),[d,f]=nr(i?s:c,r.height);return u<=l||f<=d?null:{x:l,y:d,width:u-l,height:f-d}}function ir(e,t,n,r){let i=Xn(e),{turned:a,fromX:o,fromY:s}=tr(t,n,r),c=Zn(e.x,e.width,i).map(o),l=Zn(e.y,e.height,i).map(s);return Qn(nr(a?l:c,r.width),nr(a?c:l,r.height))}function ar(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(void 0)})}async function or(e){if(e&&(await ar(),e.aborted))throw e.reason}var sr=4e6;function cr(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 lr(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 ur=/* @__PURE__ */ new WeakMap,dr=/* @__PURE__ */ new WeakMap;function fr(e){let t=ur.get(e);t&&(t.canvas.width=0),ur.delete(e);for(let t of dr.get(e)?.values()??[])t.canvas.width=0;dr.delete(e)}var pr={x:-1e9,y:-1e9,width:2e9,height:2e9};function mr(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])=>Un(e,{x:t,y:n}))}function hr(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 cr({x:i,y:a,width:Math.ceil(Math.max(...n))-i,height:Math.ceil(Math.max(...r))-a},t)}async function gr(e,t,n,r,i){let a=hr(mr(t,n),r);if(!a)return[0,0,0,0];let o=Vn(t),s=Math.max(1,Math.floor(sr/(a.width*4))),c=[0,0,0,0],l=0;for(let t=0;t<a.height;t+=s){await or(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=Un(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 _r(e,t,n,r){let i={x:0,y:0,width:e.width,height:e.height},a=V(t.crop,e),o=Hn(t,a),s=hr(mr(zn(t),{x:0,y:0,width:t.width,height:t.height}),pr),c=n.redactions.filter(e=>s!==null&&cr(e,s)!==null),l=dr.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:Cr(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 gr(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}),dr.set(e,b),v}function vr(e,t){let n=dr.get(e);if(n)for(let e of[...n.keys()])t.has(e)||n.delete(e)}async function yr(e,t,n){let r={x:0,y:0,width:e.width,height:e.height},i=V(t.base.crop,e),a=t.redactions.filter(e=>cr(e,r)!==null);if(a.length===0)return e;let o=JSON.stringify([a,i]),s=ur.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=cr(e,r);if(e.mode===`solid`)lr(l,t,e.colour);else{let r=er(e,i),a=await br(l,r,n);lr(l,t,`#000000`),a.forEach((e,t)=>{xr(l,r[t],e)})}}if(n?.aborted)throw c.width=0,n.reason;return ur.set(e,{key:o,canvas:c}),c}async function br(e,t,n){let r=[];for(let{x:i,y:a,width:o,height:s}of t){await or(n);let t=Math.max(1,Math.floor(sr/(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 xr(e,{x:t,y:n,width:r,height:i},a){let o=Math.max(1,Math.floor(sr/(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 Sr(e,t,n,r,i){let a=V(t.base.crop,n),{orientation:o}=t.base;for(let n of t.redactions)if(n.mode===`solid`){let t=rr(n,a,o,r);t&&lr(e,t,n.colour)}else{let t=ir(n,a,o,r);(await br(e,t,i)).forEach((n,r)=>{xr(e,t[r],n)})}}function Cr(e){return e.some(e=>e.mode===`pixelate`)}var wr=100;function Tr(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 Er(e,t){if(t.text===``)return;let n=t.text.split(`
2
+ `);e.font=`${t.bold?`bold `:``}${wr}px ${t.font}`;let r=Gn(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=Wn(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 Dr(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 _r(a,t,n,i),s=V(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 Or(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 kr(e,t){let n=In(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 Ar(e,t,n,r,i,a){let o=V(t.base.crop,n),s;for(let n of t.layers){if(!n.visible||n.opacity===0)continue;await or(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(...Rn(o,t.base.orientation,r)),n.kind===`drawing`?Or(c,n):kr(c,n)):(c.setTransform(...Bn(n,o,t.base.orientation,r)),n.kind===`shape`?Tr(c,n):n.kind===`text`?Er(c,n):await Dr(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&&vr(t,c)}}var jr=4e6;function Mr(e,t){return Le(e.output,Ie(e,t))}async function Nr(e,t,n,r,i=()=>void 0){let{develop:a,filter:o}=t.base,s=Nn(a,o),c=V(t.base.crop,e),l=Ie(t,e),u=Le(t.output,l),d=new OffscreenCanvas(u.width,u.height),f=d.getContext(`2d`,{colorSpace:`srgb`,alpha:!n,willReadFrequently:s||Cr(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 yr(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=Fn(a,o),t=Math.max(1,Math.floor(jr/(u.width*4)));for(let n=0;n<u.height;n+=t){if(r&&(await ar(),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 Ar(f,t,e,u,i,r),await Sr(f,t,e,u,r),d}var Pr={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`};async function Fr(e,t,n,r,i){let a=Pr[n.type],o=await Nr(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`?sn(c,t.metadata):n.type===`png`?fn(c,t.metadata):pn(c);return new Blob([l.slice()],{type:a})}async function Ir(e,t,n,r,i,a){let o=Ie(n,t),{width:s,height:c}=A(r),l=Math.min(r.pixelRatio,4),u=ue(o,r),d=u.scale*l,f=Math.min(1,d),p=await Nr(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 Lr(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 Rr=[`layers`,`drawings`,`redactions`];function zr(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=(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})=>Dt(s(e)),async register({id:e,file:n,probe:r,limits:i},{signal:a}){if(t.has(e))throw TypeError(`The source id "${e}" is already in use.`);let o=await Dt(s(n));if(!Lr(o,r))throw new w(`INVALID_IMAGE`,`The probe doesn't describe this file.`,{details:{format:o.format,problem:`the probe describes another file`}});O(E.resolve(i),n.size,o);let c=await nn(n,o);if(a.aborted)throw c.close(),a.reason;return t.set(e,c),{width:c.width,height:c.height}},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,limits:i},{signal:a}){de(e,Rr);let o=t.get(e.base.source);if(!o)throw TypeError(`There's no source with the id "${e.base.source}".`);let s=E.resolve(i);return k(s,Mr(e,o)),e.redactions.length>0&&r(s,e,o),Fr(o,e,n,a,e=>t.get(e))},attachCanvas({id:e,canvas:t}){let r=t.getContext(`2d`,{colorSpace:`srgb`});if(!r)throw Error(`The worker has no 2D canvas.`);n.set(e,r)},async render({id:e,plan:i,view:a,limits:o},{signal:s}){de(i,Rr),k(E.resolve(o),A(a));let c=n.get(e);if(!c)throw TypeError(`There's no canvas with the id "${e}".`);let l=t.get(i.base.source);if(!l)throw TypeError(`There's no source with the id "${i.base.source}".`);i.redactions.length>0&&r(E.resolve(o),i,l),await Ir(c,l,i,a,s,e=>t.get(e))},detachCanvas({id:e}){let t=n.get(e);t&&(t.canvas.width=0,t.canvas.height=0),n.delete(e)},snapshot({id:e}){let t=n.get(e);if(!t)throw TypeError(`There's no canvas with the id "${e}".`);return createImageBitmap(t.canvas)},release({id:e}){let n=t.get(e);n&&fr(n),n?.close(),t.delete(e)}},{...e,packageVersion:`0.6.0`})}zr();
package/dist/element.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Vt as ImageError } from "./shared/core-DKUm3jGZ.js";
2
- import { d as imageEditorMessages, p as ExportListenerContext, t as ImageEditor } from "./shared/editor-DrTd1KgQ.js";
1
+ import { Vt as ImageError } from "./shared/core-VHeENp7j.js";
2
+ import { d as imageEditorMessages, p as ExportListenerContext, t as ImageEditor } from "./shared/editor-Bj9Xo5nf.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 invalid, A as fitAspect, At as placement, B as sourceToComposition, C as drawingPoints, Ct as REDACTION_MODES, D as compositionDeltaToSource, Dt as MAX_PIXEL_RATIO, E as aspectRatio, Et as createImageRenderer, F as compositionSize, Ft as PER_FILE_LIMITS, G as checkOutput, H as checkFilter, Ht as isImageError, I as compositionToSource, It as checkFileLimits, J as checkLayer, K as createImageReducer, L as cropRect, Lt as checkOutputLimits, M as moveCrop, Mt as createImageEngine, N as nudgeCropOnScreen, O as cropInComposition, Ot as backingSize, Pt as OUTPUT_LIMITS, Q as checkCropInSource, R as orientedSize, Rt as imageLimitDefinitions, S as drawingBounds, St as NEUTRAL_DEVELOP, T as ASPECT_PRESETS, Tt as createPlan, U as checkMetadata, V as checkDevelop, Vt as ImageError, W as checkOrientation, X as Invalid, Y as checkRedaction, Z as checkCrop, _ as sceneToLayerSource, _t as MAX_PLAN_ITEMS, a as fitRedactionRegion, b as arrowBounds, bt as MAX_STROKE_RUNS, c as redactionBlocksInScene, ct as FULL_SIZE, d as applyMatrix, dt as LAYER_KINDS, et as isRecord, f as fitTextLines, ft as LAYER_SHAPES, g as layerToScene, gt as MAX_LAYER_TEXT_LENGTH, h as layerToOutput, ht as MAX_LAYER_NAME_LENGTH, i as compositionRectToScene, it as NO_METADATA, j as handleInSource, jt as createImageProcessor, k as dragHandle, kt as fittedView, l as redactionRectInOutput, lt as LAYER_ALIGNMENTS, m as isRightToLeft, mt as MAX_KEY_LENGTH, n as createImageSession, nt as EMPTY_KEEPABLE_METADATA, o as redactionBlockSize, ot as DEVELOP_ADJUSTMENTS, p as invertMatrix, pt as MAX_DRAWING_STROKES, rt as MAX_METADATA_LENGTH, s as redactionBlocksInOutput, st as FILTER_PRESETS, t as imageMessages, tt as onlyFields, u as sceneRectToComposition, ut as LAYER_FONTS, v as sceneToOutput, vt as MAX_RUN_POINTS, w as simplifyStroke, wt as UPRIGHT, x as arrowOutline, xt as MAX_STROKE_WIDTH, y as createImageKey, yt as MAX_SCENE_COORDINATE, z as outputSize, zt as imageLimits } from "./shared/core-DKUm3jGZ.js";
1
+ import { $ as invalid, A as fitAspect, At as placement, B as sourceToComposition, C as drawingPoints, Ct as REDACTION_MODES, D as compositionDeltaToSource, Dt as MAX_PIXEL_RATIO, E as aspectRatio, Et as createImageRenderer, F as compositionSize, Ft as PER_FILE_LIMITS, G as checkOutput, H as checkFilter, Ht as isImageError, I as compositionToSource, It as checkFileLimits, J as checkLayer, K as createImageReducer, L as cropRect, Lt as checkOutputLimits, M as moveCrop, Mt as createImageEngine, N as nudgeCropOnScreen, O as cropInComposition, Ot as backingSize, Pt as OUTPUT_LIMITS, Q as checkCropInSource, R as orientedSize, Rt as imageLimitDefinitions, S as drawingBounds, St as NEUTRAL_DEVELOP, T as ASPECT_PRESETS, Tt as createPlan, U as checkMetadata, V as checkDevelop, Vt as ImageError, W as checkOrientation, X as Invalid, Y as checkRedaction, Z as checkCrop, _ as sceneToLayerSource, _t as MAX_PLAN_ITEMS, a as fitRedactionRegion, b as arrowBounds, bt as MAX_STROKE_RUNS, c as redactionBlocksInScene, ct as FULL_SIZE, d as applyMatrix, dt as LAYER_KINDS, et as isRecord, f as fitTextLines, ft as LAYER_SHAPES, g as layerToScene, gt as MAX_LAYER_TEXT_LENGTH, h as layerToOutput, ht as MAX_LAYER_NAME_LENGTH, i as compositionRectToScene, it as NO_METADATA, j as handleInSource, jt as createImageProcessor, k as dragHandle, kt as fittedView, l as redactionRectInOutput, lt as LAYER_ALIGNMENTS, m as isRightToLeft, mt as MAX_KEY_LENGTH, n as createImageSession, nt as EMPTY_KEEPABLE_METADATA, o as redactionBlockSize, ot as DEVELOP_ADJUSTMENTS, p as invertMatrix, pt as MAX_DRAWING_STROKES, rt as MAX_METADATA_LENGTH, s as redactionBlocksInOutput, st as FILTER_PRESETS, t as imageMessages, tt as onlyFields, u as sceneRectToComposition, ut as LAYER_FONTS, v as sceneToOutput, vt as MAX_RUN_POINTS, w as simplifyStroke, wt as UPRIGHT, x as arrowOutline, xt as MAX_STROKE_WIDTH, y as createImageKey, yt as MAX_SCENE_COORDINATE, z as outputSize, zt as imageLimits } from "./shared/core-VHeENp7j.js";
2
2
  // src/core/format/plan-document.ts
3
3
  var IMAGE_PLAN_FORMAT = "hm-image-plan";
4
4
  var IMAGE_PLAN_VERSION = 3;
@@ -0,0 +1,30 @@
1
+ // src/workers/render.worker.ts?worker&inline
2
+ var jsContent = "function e(){try{return process.env.NODE_ENV!==`production`}catch{return!1}}function t(t){e()&&console.warn(`[@hussmartinez/sdk-core] ${t}`)}var n=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core`),r={},i=!1;function a(){return`0.4.4`}function o(){if(!i&&(i=!0,typeof process<`u`&&process.env.NODE_ENV!==`production`)){let e=globalThis,i=e[n]??/* @__PURE__ */ new Map;e[n]=i,i.set(r,a()),i.size>1&&t(`${i.size} copies of @hussmartinez/sdk-core are in use (${[...i.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 s=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),c=class extends Error{name=`SdkError`;code;constructor(e,t,n={}){super(t,`cause`in n?{cause:n.cause}:void 0),o(),this.code=e,Object.defineProperty(this,s,{value:!0}),n.details!==void 0&&(this.details=n.details)}};function l(e,t){if(typeof e!=`object`||!e)return!1;let n=e;return(e instanceof c||n[s]===!0)&&typeof n.code==`string`&&typeof n.message==`string`&&(t===void 0||n.code===t)}var u=1<<20;function d(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 f(e,t={}){let n=t.windowSize??u;d(`window size`,n,1);let r=e.size,i=0,a=/* @__PURE__ */ new Uint8Array;return{size:r,async bytes(t,o){d(`offset`,t,0),d(`length`,o,0);let s=Math.min(t,r),c=Math.min(r,s+o);if(s<i||c>i+a.length){let t=Math.min(r,s+Math.max(o,n));a=new Uint8Array(await e.slice(s,t).arrayBuffer()),i=s}return a.subarray(s-i,c-i)}}}var p=8,m=16,h=`UNKNOWN`;function g(e,t={}){let n=t.includeStack??!1,r=ee(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=_(e),s=n&&b(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),b(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function _(e){if(l(e)){let t={name:e.name,code:e.code,message:e.message},n=v(e.details);return n!==void 0&&(t.details=n),t}if(b(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:h,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:h,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:h,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function v(e){if(!x(e))return;let t=y(e,0);return x(t)?t:void 0}function y(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>=m)){if(Array.isArray(e))return e.flatMap(e=>{let n=y(e,t+1);return n===void 0?[]:[n]});if(x(e)){let n={};for(let[r,i]of Object.entries(e)){let e=y(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function b(e){return typeof e==`object`&&!!e}function x(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ee(e){if(e===void 0)return p;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}var te={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 ne(e,t={}){let n=t.errorClass??c;for(let[t,n]of Object.entries(e))S(`${t}.default`,n.default),n.warning!==void 0&&S(`${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]=re(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 re(e,t,n){if(typeof n==`number`)return S(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 S(`${e}.maximum`,r),S(`${e}.warning`,i),{maximum:r,warning:i}}function S(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 ie=`hm-rpc`;function C(e){return{protocol:ie,version:1,...e}}function ae(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 oe(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=ce(e)?e:le(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return de(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))}):w(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),T(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function se(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function ce(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function le(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 ue=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function de(e){let t=globalThis;return ue.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function w(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function T(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 fe(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(C({type:`error`,id:e,error:g(t,{includeStack:r})}))},s=(e,t,r)=>{let i=oe(r,!0);try{se((e,t)=>n.postMessage(e,t),C({type:`result`,id:e,output:i.value}),i.transferables)}catch(n){o(e,new c(`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:r}=t,l=Object.hasOwn(e,r)?e[r]:void 0;if(typeof l!=`function`){o(n,new c(`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(C({type:`progress`,id:n,value:e}))}};Promise.resolve().then(()=>l.call(e,t.input,d)).then(e=>{i.delete(n),s(n,r,e)},e=>{i.delete(n),o(n,e)})},u=e=>{a(C({type:`crash`,error:g(e,{includeStack:r})}))};n.addEventListener(`message`,e=>{let t=ae(e.data);t!==void 0&&t.version===1&&(t.type===`call`?l(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(C({type:`ready`,...t.packageVersion===void 0?{}:{packageVersion:t.packageVersion}}))}var E=class extends c{name=`ImageError`};function D(e,t){return l(e,t)&&e.name===`ImageError`}const O=/* @__PURE__ */ ne({...te,maxDecodedSize:{...te.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},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:E}),pe=[`maxFileSize`,`maxImageDimension`,`maxImagePixels`,`maxFrames`,`maxDecodedSize`];function me(e,t,n){let{width:r,height:i}=n.oriented,a={maxFileSize:t,maxImageDimension:Math.max(r,i),maxImagePixels:r*i,maxFrames:n.frames,maxDecodedSize:n.decodedPixelBound*4};return pe.filter(t=>e.check(t,a[t])===`warning`)}function k(e,t){e.check(`maxImageDimension`,Math.max(t.width,t.height)),e.check(`maxImagePixels`,t.width*t.height)}function A(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 j(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 he(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 E(`UNSUPPORTED_PLAN`,`This renderer can't draw the plan's ${e}.`,{details:{reason:e}})}function M(e,t){return new E(`INVALID_IMAGE`,`Invalid ${e}: ${t}.`,{details:{format:e,problem:t}})}async function N(e,t,n,r,i){if(n+r>e.size)throw M(t,`${i} ends past the end of the file`);return e.bytes(n,r)}function P(e,t){return(e[t]??0)<<8|(e[t+1]??0)}function F(e,t){return((e[t]??0)<<24|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0}function I(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 ge(e,t){return t.every((t,n)=>e[n]===t)}function L(e,t){return(e[t]??0)|(e[t+1]??0)<<8}function R(e,t){return(e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16}function z(e,t){return((e[t]??0)|(e[t+1]??0)<<8|(e[t+2]??0)<<16|(e[t+3]??0)<<24)>>>0}function _e(e,t){return z(e,t)|0}const ve=4096;function ye(e,t,n,r){let i=1<<n,a=i+1,o=new Uint16Array(ve),s=new Uint8Array(ve),c=new Uint8Array(ve);for(let e=0;e<i;e+=1)s[e]=e,c[e]=e;let l=new Uint8Array(ve),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 M(`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 M(`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 M(`gif`,`a frame's data starts with a code that isn't a colour`)}else if(t>d)throw M(`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 M(`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<ve&&(o[d]=f,s[d]=b,c[d]=c[f],d+=1),d>=1<<u&&u<12&&(u+=1),f=t}throw M(`gif`,`a frame's data holds fewer pixels than the frame`)}const be={offset:0,size:0},xe=[[0,8],[4,8],[2,4],[1,2]];function Se(e,t){let{width:n,height:r}=t,i=new Uint8Array(n*r);if(ye(e,t.data,t.codeSize,i),!t.interlaced)return i;let a=new Uint8Array(n*r),o=0;for(let[e,t]of xe)for(let s=e;s<r;s+=t)a.set(i.subarray(o,o+n),s*n),o+=n;return a}function Ce(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},reset(){n.fill(0),r=-1,i=void 0},next(){let o=t.frames[r+1];if(!o)throw RangeError(`The GIF has no more frames.`);let s=Se(e,o),c=o.table??t.table??be,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}}}const we=4096;function Te(e,t){let n=t;for(;;){if(n>=e.length)throw M(`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 M(`gif`,`a data sub-block ends past the end of the file`);n+=t}}function B(e,t,n,r){if(t+n>e.length)throw M(`gif`,`${r} ends past the end of the file`)}function Ee(e,t,n){let r=2**(n+1);return B(e,t,3*r,`a colour table`),{offset:t,size:r}}function De(e){B(e,0,13,`the logical screen descriptor`);let t=I(e,0,6);if(t!==`GIF87a`&&t!==`GIF89a`)throw M(`gif`,`not a GIF`);let n=L(e,6),r=L(e,8);if(n<1||r<1)throw M(`gif`,`the logical screen has no pixels`);let i=e[10],a=13,o=null;i&128&&(o=Ee(e,a,i&7),a+=3*o.size);let s=[],c=null,l=0,u=0,d=null;for(let t=0;;t+=1){if(t>=17408)throw M(`gif`,`the file has too many blocks`);try{B(e,a,1,`a block`);let t=e[a];if(t===59)break;if(t===33){B(e,a,2,`an extension label`);let t=e[a+1];if(t===249){if(B(e,a+2,6,`a graphic control extension`),e[a+2]!==4)throw M(`gif`,`a graphic control extension is the wrong size`);let t=e[a+3],n=t>>>2&7;u=n===4?3:n>4?0:n,l=L(e,a+4),d=t&1?e[a+6]:null}else if(t===255){B(e,a+2,12,`an application extension`);let t=I(e,a+3,11);e[a+2]===11&&(t===`NETSCAPE2.0`||t===`ANIMEXTS1.0`)&&a+18<=e.length&&e[a+14]===3&&e[a+15]===1&&(c=L(e,a+16))}a=Te(e,a+2);continue}if(t!==44)throw M(`gif`,`an unknown block`);B(e,a,10,`an image descriptor`);let i=L(e,a+1),o=L(e,a+3),f=L(e,a+5),p=L(e,a+7);if(s.length===0&&i===0&&o===0&&f>=n&&p>=r&&(n=f,r=p),f<1||p<1||i+f>n||o+p>r)throw M(`gif`,`a frame doesn't fit inside the logical screen`);let m=e[a+9];a+=10;let h=null;m&128&&(h=Ee(e,a,m&7),a+=3*h.size),B(e,a,1,`an LZW minimum code size`);let g=e[a];if(g<1||g>8)throw M(`gif`,`a frame's LZW minimum code size is out of range`);let _=a+1;if(a=Te(e,_),s.length>=4096)throw new E(`TOO_MANY_FRAMES`,`A GIF holds at most ${we} frames.`,{details:{limit:`maxFrames`,maximum:we,actual:s.length+1,unit:`count`}});s.push({x:i,y:o,width:f,height:p,delay:l,disposal:u,transparent:d,interlaced:!!(m&64),table:h,codeSize:g,data:_}),l=0,u=0,d=null}catch(e){if(s.length>0&&D(e)&&e.code===`INVALID_IMAGE`)break;throw e}}if(s.length===0)throw M(`gif`,`there are no frames`);return{width:n,height:r,loop:c,table:o,frames:s}}const Oe=Object.freeze({location:!1,camera:!1,timestamps:!1,thumbnail:!1,colourProfile:!1,other:!1}),ke=Object.freeze({title:``,description:``,artist:``,copyright:``}),Ae=2e3;function je(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}const Me=/* @__PURE__ */ new Set([12,40,52,56,108,124]);function Ne(e){return I(e,0,2)===`BM`}async function Pe(e){let t=await N(e,`bmp`,0,18,`the file header`),n=z(t,10),r=z(t,14);if(!Me.has(r))throw M(`bmp`,`the DIB header size is unknown`);let i=await N(e,`bmp`,14,r,`the DIB header`),a,o,s;if(r===12?(a=L(i,4),o=L(i,6),s=L(i,10)):(a=_e(i,4),o=Math.abs(_e(i,8)),s=L(i,14)),L(i,r===12?8:12)!==1)throw M(`bmp`,`the plane count isn't 1`);if(a<1||o<1||a>2147483647||o>2147483647)throw M(`bmp`,`the dimensions are out of range`);if(![1,4,8,16,24,32].includes(s))throw M(`bmp`,`the bit depth is unsupported`);if(n<14+r||n>=e.size)throw M(`bmp`,`the pixel data starts outside the file`);let c=r===124&&[1279872587,1296188740].includes(z(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:{...Oe,colourProfile:c},keepable:ke}}function Fe(e){let t=I(e,0,6);return t===`GIF87a`||t===`GIF89a`}async function Ie(e,t){let n=t;for(;;){let t=(await N(e,`gif`,n,1,`a data sub-block`))[0]??0;if(n+=1,t===0)return n;if(n+t>e.size)throw M(`gif`,`a data sub-block ends past the end of the file`);n+=t}}async function Le(e){let t=await N(e,`gif`,0,13,`the logical screen descriptor`),n=L(t,6),r=L(t,8);if(n<1||r<1)throw M(`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>=1e6)throw M(`gif`,`the file has too many blocks`);try{let t=(await N(e,`gif`,a,1,`a block`))[0];if(t===59)break;if(t===33){let t=(await N(e,`gif`,a+1,1,`an extension label`))[0];if(t===249){let t=await N(e,`gif`,a+2,6,`a graphic control extension`);if(t[0]!==4)throw M(`gif`,`a graphic control extension is the wrong size`);(t[1]??0)&1&&(s=!0)}else if(t===255){let t=I(await N(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 Ie(e,a+2);continue}if(t===44){let t=await N(e,`gif`,a,10,`an image descriptor`),i=L(t,1),s=L(t,3),c=L(t,5),l=L(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 M(`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 N(e,`gif`,a,1,`an LZW minimum code size`))[0]??0;if(d<1||d>8)throw M(`gif`,`a frame's LZW minimum code size is out of range`);a=await Ie(e,a+1),o+=1;continue}throw M(`gif`,`an unknown block`)}catch(e){if(o>0&&D(e)&&e.code===`INVALID_IMAGE`)break;throw e}}if(o===0)throw M(`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:{...Oe,other:c},keepable:ke}}function Re(e,t){return t>=5?{width:e.height,height:e.width}:e}function V(e,t){return e??{x:0,y:0,width:t.width,height:t.height}}function ze(e,t){let{width:n,height:r}=V(e.base.crop,t);return e.base.orientation.rotate%180==0?{width:n,height:r}:{width:r,height:n}}function Be(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 Ve(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 He(){return{orientation:1,location:!1,camera:!1,timestamps:!1,thumbnail:!1,other:!1,title:``,description:``,artist:``,copyright:``}}function Ue(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}const We=/* @__PURE__ */ new Set([271,272,42033,42035,42036,42037,37500]),Ge=/* @__PURE__ */ new Set([306,36867,36868,36880,36881,36882]),Ke=/* @__PURE__ */ new Set([34665,34853,40965,513,514]),qe={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 Je(e,t){let n=He();if(e.length<8)throw M(t,`the EXIF block is too short`);let r=e[0]===73&&e[1]===73;if(!r&&(e[0]!==77||e[1]!==77))throw M(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 M(t,`the EXIF block isn't TIFF`);let o=(n,r,i,o)=>{let s=r*(qe[n]??1),c=s<=4?i:a(i);if(c+s>e.length)throw M(t,`an EXIF value ends past the block`);let l=e.subarray(c,c+s),u=(o?new TextDecoder(`utf-16le`).decode(l):Ue(l)).replace(/\\0+$/,``);return je(u,2e3)?[...u].slice(0,Ae).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 M(t,`EXIF directories loop`);if(s.size>=8)throw M(t,`the EXIF block has too many directories`);if(s.add(r),r+2>e.length)throw M(t,`an EXIF directory starts past the block`);let u=i(r);if(u>1e3||r+2+u*12+4>e.length)throw M(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):We.has(s)?n.camera=!0:Ge.has(s)?n.timestamps=!0:Ke.has(s)||(n.other=!0)}}l===`main`?c.push({offset:a(r+2+u*12),kind:`next`}):l===`next`&&(n.thumbnail=!0)}return n}const Ye=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`,`heic`,`heix`,`heim`,`heis`,`hevc`,`hevx`,`mif1`,`mif2`,`msf1`]),Xe=/* @__PURE__ */ new Set([`avif`,`avis`,`avio`]),Ze=/* @__PURE__ */ new Set([`av01`,`hvc1`]),Qe=/* @__PURE__ */ new Set([`urn:mpeg:mpegB:cicp:systems:auxiliary:alpha`,`urn:mpeg:hevc:2015:auxid:1`]),$e=/* @__PURE__ */ new Set([`dimg`,`auxl`,`thmb`]),et=4096;function tt(e){return I(e,4,4)===`ftyp`&&Ye.has(I(e,8,4))}function nt(e,t){return F(e,t)*2**32+F(e,t+4)}function H(e,t,n,r){let i=(t,n)=>{if(t.at+n>r)throw M(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,P(t,a.at-2)},u32(){return i(a,4),a.at+=4,F(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,nt(t,a.at-8);throw M(e,`a field has an unsupported size`)},fourcc(){return i(a,4),a.at+=4,I(t,a.at-4,4)},string(){let n=t.subarray(a.at,r).indexOf(0);if(n<0)throw M(e,`a string isn't terminated inside its box`);let i=I(t,a.at,n);return a.at+=n+1,i}};return a}function rt(e,t,n,r){let i=[],a=n;for(;a<r;){if(i.length>=et)throw M(e,`a box holds too many boxes`);if(a+8>r)throw M(e,`a box header ends past its parent`);let n=F(t,a),o=8;if(n===1){if(a+16>r)throw M(e,`a box header ends past its parent`);n=nt(t,a+8),o=16}else n===0&&(n=r-a);if(n<o||a+n>r)throw M(e,`a box ends past its parent`);i.push({type:I(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 M(e,`a box that may appear once appears twice`);return r[0]}const it=[[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 at(e){return it.find(([t])=>t===e)?.[1]??[1,0,0,1]}function ot(e,t){let[n=0,r=0,i=0,a=0]=at(t),[o=0,s=0,c=0,l=0]=at(e),u=[n*o+r*c,n*s+r*l,i*o+a*c,i*s+a*l];return it.find(([,e])=>e.every((e,t)=>e===u[t]))?.[0]??1}function st(e,t,n){let r=n=>{let r=t.u32(),i=t.u32();if(i===0)throw M(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 M(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 M(e,`a clean aperture lies outside the image`);return{width:i,height:a}}const ct=[1,8,3,6];async function lt(e){let t=F(await N(e,`heif`,0,8,`the ftyp box`),0);if(t<16||t>4096)throw M(`heif`,`the ftyp box has an invalid size`);let n=await N(e,`heif`,8,t-8,`the ftyp box`),r=[I(n,0,4)];for(let e=8;e+4<=n.length;e+=4)r.push(I(n,e,4));let i=r.some(e=>Xe.has(e))?`avif`:`heif`,a,o=t;for(let t=0;o<e.size;t+=1){if(t>=1024)throw M(i,`the file has too many boxes`);let n=await N(e,i,o,8,`a box header`),r=F(n,0),s=8;if(r===1?(r=nt(await N(e,i,o+8,8,`a box header`),0),s=16):r===0&&(r=e.size-o),r<s||o+r>e.size)throw M(i,`a box ends past the end of the file`);let c=I(n,4,4);if(c===`moov`)throw new E(`UNSUPPORTED_FORMAT`,`Image sequences in ${i} aren't supported.`,{details:{format:i}});if(c===`meta`){if(a!==void 0)throw M(i,`there are two meta boxes`);a={start:o+s,end:o+r}}o+=r}if(a===void 0)throw M(i,`there's no meta box`);if(a.end-a.start>4194304)throw M(i,`the meta box is too large`);let s=await N(e,i,a.start,a.end-a.start,`the meta box`),c=rt(i,s,4,s.length),l=U(i,c,`hdlr`),u=l&&H(i,s,l.start+8,l.end);if(u===void 0||u.fourcc()!==`pict`)throw M(i,`the meta box isn't for a picture`);let d=U(i,c,`pitm`);if(d===void 0)throw M(i,`there's no primary item`);let f=H(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 M(i,`there's no item information`);let _=H(i,s,g.start,g.end),v=_.u8();_.at+=3;let y=v===0?_.u16():_.u32(),b=rt(i,s,_.at,g.end).filter(e=>e.type===`infe`);if(b.length!==y)throw M(i,`the item count doesn't match the item entries`);for(let e of b){let t=H(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 M(i,`two items share an ID`);h.set(r.id,r)}let x=h.get(m);if(x===void 0)throw M(i,`the primary item isn't declared`);if(x.type!==`grid`&&!Ze.has(x.type))throw new E(`UNSUPPORTED_FORMAT`,`The ${i} file's primary image type isn't supported.`,{details:{format:i}});let ee=[],te=U(i,c,`iref`);if(te!==void 0){let e=s[te.start]??0;for(let t of rt(i,s,te.start+4,te.end)){let n=H(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());ee.push({type:t.type,from:r,to:o})}}let ne=U(i,c,`iprp`);if(ne===void 0)throw M(i,`there are no item properties`);let re=rt(i,s,ne.start,ne.end),S=U(i,re,`ipco`);if(S===void 0)throw M(i,`there's no property container`);let ie=rt(i,s,S.start,S.end),C=/* @__PURE__ */ new Map;for(let e of re.filter(e=>e.type===`ipma`)){let t=H(i,s,e.start,e.end),n=t.u8();t.u16();let r=(t.u8()&1)==1,a=t.u32();if(a>et)throw M(i,`too many property associations`);for(let e=0;e<a;e+=1){let e=n<1?t.u16():t.u32();if(C.has(e))throw M(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=ie[e-1];if(n===void 0)throw M(i,`an item refers to a property that doesn't exist`);a.push(n)}C.set(e,a)}}let ae=(e,t)=>(C.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 M(i,`an image item has no single ispe`);let r=H(i,s,n.start+4,n.end),a={width:r.u32(),height:r.u32()};if(a.width<1||a.height<1)throw M(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=H(i,s,le.start,le.end),n=t.u8();if(t.at+=3,n>2)throw M(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>et)throw M(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 M(i,`an item's data lies outside the file`);f.push({offset:n,length:d})}if(ce.has(r))throw M(i,`an item is located twice`);ce.set(r,{method:a,extents:f})}}let ue=async(t,n)=>{let r=ce.get(t);if(r===void 0)throw M(i,`an item's data has no location`);let a=r.extents.reduce((e,t)=>e+t.length,0);if(a>n)throw M(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 M(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},de=ee.filter(e=>$e.has(e.type)),w=/* @__PURE__ */ new Set([m]);for(let e=[m];e.length>0;){let t=e.pop()??m;for(let n of de){let r=n.from===t?n.to:n.to.includes(t)?[n.from]:[];for(let t of r){if(!h.has(t))throw M(i,`a reference names an item that isn't declared`);w.has(t)||(w.add(t),e.push(t))}}}let T=new Map([...w].map(e=>[e,0])),fe=de.filter(e=>w.has(e.from));for(let e of fe)for(let t of e.to)T.set(t,(T.get(t)??0)+1);let D=[...T].filter(([,e])=>e===0).map(([e])=>e),O=0;for(;D.length>0;){let e=D.pop()??0;O+=1;for(let t of fe)if(t.from===e)for(let e of t.to){let t=(T.get(e)??0)-1;T.set(e,t),t===0&&D.push(e)}}if(O!==w.size)throw M(i,`item references form a cycle`);let pe=0;for(let e of w){let t=oe(e);pe+=t.width*t.height,h.get(e)?.type===`grid`&&await me(e,t)}async function me(e,t){let n=ee.filter(t=>t.type===`dimg`&&t.from===e),r=n[0]?.to??[];if(n.length!==1||r.length===0)throw M(i,`a grid doesn't name its tiles once`);if(r.length>1024)throw M(i,`a grid has too many tiles`);let a=await ue(e,64),o=H(i,a,0,a.length);if(o.u8()!==0)throw M(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 M(i,`a grid's tile count doesn't match its rows and columns`);if(u.width!==t.width||u.height!==t.height)throw M(i,`a grid's output differs from its ispe`);let d;for(let e of r){if(!Ze.has(h.get(e)?.type??``))throw M(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 M(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 M(i,`a grid's output doesn't fit its tiles`)}let k=oe(m),A=k,j=1,he=!1;for(let e of C.get(m)??[])if(e.type===`clap`){if(he||A!==k)throw M(i,`a clean aperture follows a transformation`);A=st(i,H(i,s,e.start,e.end),k)}else if(e.type===`irot`){he=!0;let t=H(i,s,e.start,e.end);j=ot(j,ct[t.u8()&3]??1)}else if(e.type===`imir`){he=!0;let t=H(i,s,e.start,e.end);j=ot(j,t.u8()&1?2:4)}let P=e=>ee.filter(t=>t.type===e&&t.to.includes(m)),ge=P(`auxl`).some(e=>ae(e.from,`auxC`).some(e=>{let t=H(i,s,e.start+4,e.end);return Qe.has(t.string())})),L=ae(m,`colr`).some(e=>{let t=H(i,s,e.start,e.end).fourcc();return t===`prof`||t===`rICC`}),R=He(),z=[...h.values()].find(e=>e.type===`Exif`);if(z!==void 0){let e=await ue(z.id,1048576);if(e.length<4||4+F(e,0)>e.length)throw M(i,`the EXIF item's header offset is out of range`);Object.assign(R,Je(e.subarray(4+F(e,0)),i))}let _e=R.other||[...h.values()].some(e=>e.type===`mime`||e.type===`uri `);return{format:i,stored:A,oriented:Re(A,j),orientation:j,frames:1,hasAlpha:ge,decodedPixelBound:pe,metadata:{location:R.location,camera:R.camera,timestamps:R.timestamps,thumbnail:R.thumbnail||P(`thmb`).length>0,colourProfile:L,other:_e},keepable:{title:R.title,description:R.description,artist:R.artist,copyright:R.copyright}}}const ut=[255,216,255];function dt(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}async function ft(e){let t=2,n,r=!1,i=He(),a=!1,o=!1;for(let s=0;!r;s+=1){if(s>=1e4)throw M(`jpeg`,`the file has too many segments`);let c=await N(e,`jpeg`,t,2,`a marker`);if(c[0]!==255)throw M(`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 M(`jpeg`,`the image ends before its first scan`);t+=2;continue}let u=P(await N(e,`jpeg`,t+2,2,`a segment length`),0);if(u<2)throw M(`jpeg`,`a segment length is out of range`);let d=t+4,f=u-2;if(d+f>e.size)throw M(`jpeg`,`a segment ends past the end of the file`);if(dt(l)){if(n!==void 0)throw M(`jpeg`,`there's more than one frame header before the scan`);if(f<6)throw M(`jpeg`,`the frame header is too short`);let t=await e.bytes(d,f),r=P(t,1),i=P(t,3),a=t[5]??0;if(r===0)throw M(`jpeg`,`the height is only defined after the scan`);if(i===0||a<1||a>4||f<6+a*3)throw M(`jpeg`,`the frame header is invalid`);n={width:i,height:r,components:a}}else if(l===218){if(n===void 0)throw M(`jpeg`,`the scan comes before a frame header`);r=!0}else if(l===225&&f>=6){if(I(await e.bytes(d,Math.min(f,64)),0,6)===`Exif\\0\\0`){if(a)i.other=!0;else{a=!0;let t=Je((await e.bytes(d,f)).subarray(6),`jpeg`);Object.assign(i,t)}}else i.other=!0}else l===226&&f>=12?I(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:Re(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}}}const pt=[137,80,78,71,13,10,26,10],mt=2**31-1,ht={Title:`title`,Description:`description`,Author:`artist`,Copyright:`copyright`};async function gt(e){let t=8,n=0,r=0,i=!1,a,o=0,s=!1,c=!1,l=He(),u=!1;for(let d=0;!c;d+=1){if(d>=1e5)throw M(`png`,`the file has too many chunks`);let f=await N(e,`png`,t,8,`a chunk header`),p=F(f,0),m=I(f,4,4);if(p>2147483647)throw M(`png`,`a chunk length is out of range`);let h=t+8;if(h+p+4>e.size)throw M(`png`,`a chunk ends past the end of the file`);if(d===0&&m!==`IHDR`)throw M(`png`,`IHDR isn't the first chunk`);let g=async()=>{if(p>1048576)throw M(`png`,`the ${m} chunk is too large`);return e.bytes(h,p)};switch(m){case`IHDR`:{if(d!==0||p!==13)throw M(`png`,`IHDR is repeated or the wrong size`);let e=await g();if(n=F(e,0),r=F(e,4),n<1||r<1||n>mt||r>mt)throw M(`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 M(`png`,`acTL is misplaced, repeated or the wrong size`);if(a=F(await g(),0),a<1)throw M(`png`,`acTL declares no frames`);break;case`fcTL`:{if(p!==26)throw M(`png`,`an fcTL is the wrong size`);let e=await g(),t=F(e,4),i=F(e,8),a=F(e,12),s=F(e,16);if(t<1||i<1||a+t>n||s+i>r)throw M(`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=Je(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=I(e,0,t<0?Math.min(e.length,79):t),r=ht[n];if(r===void 0)l.other=!0;else if(m===`tEXt`&&t>=0)l[r]=new TextDecoder(`latin1`).decode(e.subarray(t+1)).slice(0,Ae);else if(m===`iTXt`&&t>=0&&e[t+1]===0){let n=t+3;for(let t=0;t<2&&n<e.length;n+=1)e[n]===0&&(t+=1);l[r]=new TextDecoder().decode(e.subarray(n)).slice(0,Ae)}else l.other=!0;break}case`IEND`:c=!0}t=h+p+4}if(!s)throw M(`png`,`there's no image data`);if(a!==void 0&&o!==a)throw M(`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:Re(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}}}function _t(e){return I(e,0,4)===`RIFF`&&I(e,8,4)===`WEBP`}async function vt(e){let t=8+z(await N(e,`webp`,0,12,`the RIFF header`),4);if(t>e.size||t<20)throw M(`webp`,`the RIFF size doesn't match the file`);let n=0,r=0,i=!1,a,o=!1,s=0,c=He(),l=!1,u=12;for(let d=0;u<t;d+=1){if(d>=1e5)throw M(`webp`,`the file has too many chunks`);let f=await N(e,`webp`,u,8,`a chunk header`),p=I(f,0,4),m=z(f,4),h=u+8;if(h+m>t)throw M(`webp`,`a chunk ends past the RIFF data`);if(d===0&&p!==`VP8 `&&p!==`VP8L`&&p!==`VP8X`)throw M(`webp`,`the first chunk isn't an image header`);switch(p){case`VP8X`:{if(d!==0||m<10)throw M(`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=R(t,4)+1,r=R(t,7)+1;break}case`VP8 `:if(d===0&&(o=!0),o||a!==void 0&&!a.animated){if(m<10)throw M(`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 M(`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 M(`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 M(`webp`,`the VP8L header is too short`);let t=await e.bytes(h,5);if(t[0]!==47)throw M(`webp`,`the VP8L signature is missing`);let a=z(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 M(`webp`,`the bitstream's size differs from the canvas`);s=1}break;case`ANMF`:{if(a?.animated!==!0)throw M(`webp`,`an animation frame without the animation flag`);if(m<16)throw M(`webp`,`an ANMF header is too short`);let t=await e.bytes(h,16),i=R(t,0)*2,o=R(t,3)*2,c=R(t,6)+1,l=R(t,9)+1;if(i+c>n||o+l>r)throw M(`webp`,`a frame doesn't fit inside the canvas`);s+=1;break}case`EXIF`:{if(m>1048576)throw M(`webp`,`the EXIF chunk is too large`);let t=await e.bytes(h,m),n=I(t,0,6)===`Exif\\0\\0`?t.subarray(6):t;Object.assign(c,Je(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 M(`webp`,`an animation without frames`);if(s===0||n<1||r<1)throw M(`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 yt(e){let t=await bt(e);return t.orientation===1?t:{...t,decodedPixelBound:t.decodedPixelBound+t.oriented.width*t.oriented.height}}async function bt(e){let t=await e.bytes(0,16);if(ge(t,pt))return gt(e);if(ge(t,ut))return ft(e);if(_t(t))return vt(e);if(Fe(t))return Le(e);if(tt(t))return lt(e);if(Ne(t))return Pe(e);throw new E(`UNSUPPORTED_FORMAT`,`The file isn't an image format the SDK reads.`,{details:{format:`unknown`}})}function xt(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 St(e,t){let n={width:e.width,height:e.height},r=Re(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(...xt(t,n)),a.drawImage(e,0,0),e.close(),i.transferToImageBitmap()}const Ct=[[255,0,0],[0,255,0],[0,0,255],[255,255,0]];function wt(e){let[t,n,r,i]=xt(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}const Tt=(e,t)=>t.every((t,n)=>Math.abs((e[n]??NaN)-t)<=64);function Et(e,t,n){for(let r of[1,2,3,4,5,6,7,8]){let i=Re(n,r);if(i.width===e.width&&i.height===e.height&&wt(r).every((e,n)=>Tt(t[n]??[],Ct[e]??[])))return r}}function Dt(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))}const Ot={width:48,height:32};function kt(){let e=new OffscreenCanvas(Ot.width,Ot.height),t=e.getContext(`2d`);if(!t)throw Error(`The worker has no 2D canvas.`);return Ct.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 At(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)}const jt=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 Mt(e){let t=4294967295;for(let n of e)t=(jt[(t^n)&255]??0)^t>>>8;return(t^4294967295)>>>0}const Nt=(e,t)=>Array.from({length:t},(n,r)=>e>>>8*(t-1-r)&255);async function Pt(){let e=new Uint8Array(await(await kt().convertToBlob()).arrayBuffer()),t=Uint8Array.of(101,88,73,102,...At(7)),n=Uint8Array.of(...Nt(t.length-4,4),...t,...Nt(Mt(t),4));return new Blob([e.slice(0,33),n,e.slice(33)],{type:`image/png`})}function Ft(e){return e[2]===255&&e[3]===224?4+((e[4]??0)<<8|(e[5]??0)):2}async function It(){let e=new Uint8Array(await(await kt().convertToBlob({type:`image/jpeg`,quality:1})).arrayBuffer()),t=Uint8Array.of(69,120,105,102,0,0,...At(7)),n=Uint8Array.of(255,225,...Nt(t.length+2,2),...t),r=Ft(e);return new Blob([e.slice(0,r),n,e.slice(r)],{type:`image/jpeg`})}const Lt=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));async function Rt(e){switch(e){case`jpeg`:return It();case`png`:return Pt();case`avif`:return new Blob([Lt(`AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUEAAAD/bWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAAAAAAAOcGl0bQAAAAAAAQAAAB5pbG9jAAAAAEQAAAEAAQAAAAEAAAEnAAAAcgAAAChpaW5mAAAAAAABAAAAGmluZmUCAAAAAAEAAGF2MDFDb2xvcgAAAAB+aXBycAAAAF1pcGNvAAAAFGlzcGUAAAAAAAAAMAAAACAAAAAQcGl4aQAAAAADCAgIAAAADGF2MUOBIAAAAAAAE2NvbHJuY2x4AAEADQAAgAAAAAlpcm90AQAAAAlpbWlyAAAAABlpcG1hAAAAAAAAAAEAAQYBAoMEhYYAAAB6bWRhdBIACgg4FS/7CAhoATJkRAAA66GyTOByOdAYkRkr4m7XruCgkx+mYn1Qgy/LhM4TZqjxnONsI9XbAWAHGMpcPWGmUkXOiY7S7v9FNX7P7LNof17If68icGW/sP+HwSL0D+g3eqOYaSrFfjiDyX15CtJnQA==`)]);case`heif`:return new Blob([Lt(`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==`)]);default:return}}async function zt(e){let t=await Rt(e);if(!t)return`unknown`;let n=await yt(f(t)),r=await createImageBitmap(t,{imageOrientation:`from-image`});try{let e=Et(r,Dt(r),n.stored);return n.orientation!==1&&e===n.orientation?`applied`:e===1?`not applied`:`unknown`}finally{r.close()}}const Bt=/* @__PURE__ */ new Map;function Vt(e,t=zt){let n=Bt.get(e);return n||(n=t(e).catch(()=>(Bt.delete(e),`unknown`)),Bt.set(e,n)),n}const Ht={decode:e=>createImageBitmap(e,{imageOrientation:`from-image`,premultiplyAlpha:`none`,colorSpaceConversion:`default`}),calibrate:Vt},Ut=(e,t,n)=>createImageBitmap(new ImageData(e,t,n),{premultiplyAlpha:`none`});async function Wt(e,t,n){let r=new Uint8Array(await e.arrayBuffer()),i=De(r);if(i.frames.length!==t.frames||i.width!==t.stored.width||i.height!==t.stored.height)throw new E(`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=Ce(r,i).next();return(n.fromPixels??Ut)(a,i.width,i.height)}const Gt=(e,t)=>new E(`DECODE_FAILED`,`The browser couldn't decode the image.`,{details:{format:e.format,problem:t}});async function Kt(e,t,n=Ht){let r;try{r=t.format===`gif`?await Wt(e,t,n):await n.decode(e)}catch(e){throw D(e)?e:new E(`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(),Gt(t,`this browser's orientation handling is unknown`);if(e===`not applied`)try{r=St(r,t.orientation)}catch(e){throw new E(`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 E(`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}const qt=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}const Jt=e=>Object.values(e).some(e=>e!==``);function Yt(e){let t=[];if(e.description&&t.push({tag:270,type:2,value:q([qt(e.description),[0]])}),e.artist&&t.push({tag:315,type:2,value:q([qt(e.artist),[0]])}),e.copyright&&t.push({tag:33432,type:2,value:q([qt(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 Xt(e,t){let n=[e.subarray(0,2)],r=2,i=!1,a=()=>{if(i||!Jt(t))return;i=!0;let e=q([W(`Exif\\0\\0`),Yt(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)}const Zt=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 Qt(e,t){let n=q([W(e),t]),r=4294967295;for(let e of n)r=(Zt[(r^e)&255]??0)^r>>>8;return q([K(t.length),n,K((r^4294967295)>>>0)])}const $t=/* @__PURE__ */ new Set([`IHDR`,`PLTE`,`tRNS`,`IDAT`,`IEND`]),en={title:`Title`,description:`Description`,artist:`Author`,copyright:`Copyright`};function tn(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($t.has(a)&&n.push(e.subarray(r,o)),a===`IHDR`)for(let[e,r]of Object.entries(en)){let i=t[e];i&&n.push(Qt(`iTXt`,q([W(r),[0,0,0,0,0],qt(i)])))}r=o}return q(n)}function nn(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])}const rn=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});const an=.2126,on=.7152,sn=.0722,cn=[an,on,sn],J=(e,t)=>[[0,e],[255,t]],ln={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:cn},noir:{develop:{contrast:50,shadows:-20},mono:cn},sepia:{mono:cn,curves:[J(40,255),J(20,235),J(0,190)]}},un=2**20,dn=e=>Math.round(e*un)/un,fn=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,pn=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,Y=4095,mn=Float32Array.from({length:256},(e,t)=>dn(fn(t/255))),X=Float32Array.from({length:4096},(e,t)=>dn(fn(t/Y))),Z=Float32Array.from({length:4096},(e,t)=>dn(pn(t/Y))),hn=Float64Array.from(X,e=>e>0?1/e:0),gn=e=>Math.min(1,Math.max(0,e)),_n=e=>Math.round(gn(e)*Y),vn=e=>Math.round(gn(e)*255),yn=(e,t)=>t===0?e:gn(e+t*(e*e*(3-2*e)-e)),Q=e=>[e(0),e(1),e(2)];function bn(e){let t=dn(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(mn,t=>Z[_n(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=an*i+on*h+sn*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=an*r+on*a+sn*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))])*hn[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=>_n(yn(e,c))));return{perChannel:p||m?void 0:Q(e=>Uint8Array.from([a,o,s][e],e=>vn(yn(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=an*s+on*c+sn*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))])*hn[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 xn(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})}const Sn=e=>Object.values(e).every(e=>e===0);function Cn(e,t){return!Sn(e)||t!==null&&t.strength>0}const wn=e=>new Uint8Array(e.buffer,e.byteOffset,e.length),$=Uint8Array.from({length:256},(e,t)=>t);function Tn(e,t){let n=Sn(e)?void 0:bn(e),r=t===null||t.strength===0?void 0:ln[t.preset],i=(t?.strength??0)/100,a=r?.develop?bn({...rn,...r.develop}):void 0,o=r?.curves?Q(e=>xn(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=wn(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=wn(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 En(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 Dn(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 On(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=Ve({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 kn(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 An(e,t,n,r){return Dn(kn(e),On(t,n,r))}function jn(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 Mn(e,t){let n=[t.width/e.width,0,0,t.height/e.height,t.x,t.y];return Dn(jn(kn(e)),n)}function Nn(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 Pn(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 Fn(e){for(let t of e){if(In.test(t))return!0;if(Ln.test(t))return!1}return!1}const In=/[֐-ࣿיִ-﷿ﹰ-\\u{10800}-\\u{10FFF}\\u{1E800}-\\u{1EFFF}]/u,Ln=/\\p{L}/u;function Rn(e){return Math.max(8,Math.ceil(Math.max(e.width,e.height)/12))}function zn(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 Bn(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}const Vn=(e,t,n)=>Math.min(n,Math.max(t,e));function Hn(e,t){let n=Rn(e),r=(e,t,n)=>e.map(e=>Vn(e,t,n));return Bn(r(zn(e.x,e.width,n),t.x,t.x+t.width),r(zn(e.y,e.height,n),t.y,t.y+t.height))}function Un(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=Ve({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 Wn(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,Vn(n===0?Math.floor(e):n===r?Math.ceil(e):Math.round(e),0,t)),i))}function Gn(e,t,n,r){let{turned:i,fromX:a,fromY:o}=Un(t,n,r),s=[a(e.x),a(e.x+e.width)],c=[o(e.y),o(e.y+e.height)],[l,u]=Wn(i?c:s,r.width),[d,f]=Wn(i?s:c,r.height);return u<=l||f<=d?null:{x:l,y:d,width:u-l,height:f-d}}function Kn(e,t,n,r){let i=Rn(e),{turned:a,fromX:o,fromY:s}=Un(t,n,r),c=zn(e.x,e.width,i).map(o),l=zn(e.y,e.height,i).map(s);return Bn(Wn(a?l:c,r.width),Wn(a?c:l,r.height))}function qn(){return new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),e()},t.port2.postMessage(void 0)})}async function Jn(e){if(e&&(await qn(),e.aborted))throw e.reason}const Yn=4e6;function Xn(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 Zn(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()}const Qn=/* @__PURE__ */ new WeakMap,$n=/* @__PURE__ */ new WeakMap;function er(e){let t=Qn.get(e);t&&(t.canvas.width=0),Qn.delete(e);for(let t of $n.get(e)?.values()??[])t.canvas.width=0;$n.delete(e)}const tr={x:-1e9,y:-1e9,width:2e9,height:2e9};function nr(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])=>Nn(e,{x:t,y:n}))}function rr(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 Xn({x:i,y:a,width:Math.ceil(Math.max(...n))-i,height:Math.ceil(Math.max(...r))-a},t)}async function ir(e,t,n,r,i){let a=rr(nr(t,n),r);if(!a)return[0,0,0,0];let o=jn(t),s=Math.max(1,Math.floor(Yn/(a.width*4))),c=[0,0,0,0],l=0;for(let t=0;t<a.height;t+=s){await Jn(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=Nn(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 ar(e,t,n,r){let i={x:0,y:0,width:e.width,height:e.height},a=V(t.crop,e),o=Mn(t,a),s=rr(nr(kn(t),{x:0,y:0,width:t.width,height:t.height}),tr),c=n.redactions.filter(e=>s!==null&&Xn(e,s)!==null),l=$n.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:dr(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 ir(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}),$n.set(e,b),v}function or(e,t){let n=$n.get(e);if(n)for(let e of[...n.keys()])t.has(e)||n.delete(e)}async function sr(e,t,n){let r={x:0,y:0,width:e.width,height:e.height},i=V(t.base.crop,e),a=t.redactions.filter(e=>Xn(e,r)!==null);if(a.length===0)return e;let o=JSON.stringify([a,i]),s=Qn.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=Xn(e,r);if(e.mode===`solid`)Zn(l,t,e.colour);else{let r=Hn(e,i),a=await cr(l,r,n);Zn(l,t,`#000000`),a.forEach((e,t)=>{lr(l,r[t],e)})}}if(n?.aborted)throw c.width=0,n.reason;return Qn.set(e,{key:o,canvas:c}),c}async function cr(e,t,n){let r=[];for(let{x:i,y:a,width:o,height:s}of t){await Jn(n);let t=Math.max(1,Math.floor(Yn/(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 lr(e,{x:t,y:n,width:r,height:i},a){let o=Math.max(1,Math.floor(Yn/(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 ur(e,t,n,r,i){let a=V(t.base.crop,n),{orientation:o}=t.base;for(let n of t.redactions)if(n.mode===`solid`){let t=Gn(n,a,o,r);t&&Zn(e,t,n.colour)}else{let t=Kn(n,a,o,r);(await cr(e,t,i)).forEach((n,r)=>{lr(e,t[r],n)})}}function dr(e){return e.some(e=>e.mode===`pixelate`)}function fr(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 pr(e,t){if(t.text===``)return;let n=t.text.split(`\n`);e.font=`${t.bold?`bold `:``}100px ${t.font}`;let r=Fn(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=Pn(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 mr(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 ar(a,t,n,i),s=V(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 hr(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 gr(e,t){let n=En(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 _r(e,t,n,r,i,a){let o=V(t.base.crop,n),s;for(let n of t.layers){if(!n.visible||n.opacity===0)continue;await Jn(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(...On(o,t.base.orientation,r)),n.kind===`drawing`?hr(c,n):gr(c,n)):(c.setTransform(...An(n,o,t.base.orientation,r)),n.kind===`shape`?fr(c,n):n.kind===`text`?pr(c,n):await mr(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&&or(t,c)}}function vr(e,t){return Be(e.output,ze(e,t))}async function yr(e,t,n,r,i=()=>void 0){let{develop:a,filter:o}=t.base,s=Cn(a,o),c=V(t.base.crop,e),l=ze(t,e),u=Be(t.output,l),d=new OffscreenCanvas(u.width,u.height),f=d.getContext(`2d`,{colorSpace:`srgb`,alpha:!n,willReadFrequently:s||dr(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 sr(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=Tn(a,o),t=Math.max(1,Math.floor(4e6/(u.width*4)));for(let n=0;n<u.height;n+=t){if(r&&(await qn(),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 _r(f,t,e,u,i,r),await ur(f,t,e,u,r),d}const br={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`};async function xr(e,t,n,r,i){let a=br[n.type],o=await yr(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 E(`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`?Xt(c,t.metadata):n.type===`png`?tn(c,t.metadata):nn(c);return new Blob([l.slice()],{type:a})}async function Sr(e,t,n,r,i,a){let o=ze(n,t),{width:s,height:c}=A(r),l=Math.min(r.pixelRatio,4),u=j(o,r),d=u.scale*l,f=Math.min(1,d),p=await yr(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 Cr(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}const wr=[`layers`,`drawings`,`redactions`];function Tr(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map,r=(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)}};fe({probe:({file:e})=>yt(f(e)),async register({id:e,file:n,probe:r,limits:i},{signal:a}){if(t.has(e))throw TypeError(`The source id \"${e}\" is already in use.`);let o=await yt(f(n));if(!Cr(o,r))throw new E(`INVALID_IMAGE`,`The probe doesn't describe this file.`,{details:{format:o.format,problem:`the probe describes another file`}});me(O.resolve(i),n.size,o);let s=await Kt(n,o);if(a.aborted)throw s.close(),a.reason;return t.set(e,s),{width:s.width,height:s.height}},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,limits:i},{signal:a}){he(e,wr);let o=t.get(e.base.source);if(!o)throw TypeError(`There's no source with the id \"${e.base.source}\".`);let s=O.resolve(i);return k(s,vr(e,o)),e.redactions.length>0&&r(s,e,o),xr(o,e,n,a,e=>t.get(e))},attachCanvas({id:e,canvas:t}){let r=t.getContext(`2d`,{colorSpace:`srgb`});if(!r)throw Error(`The worker has no 2D canvas.`);n.set(e,r)},async render({id:e,plan:i,view:a,limits:o},{signal:s}){he(i,wr),k(O.resolve(o),A(a));let c=n.get(e);if(!c)throw TypeError(`There's no canvas with the id \"${e}\".`);let l=t.get(i.base.source);if(!l)throw TypeError(`There's no source with the id \"${i.base.source}\".`);i.redactions.length>0&&r(O.resolve(o),i,l),await Sr(c,l,i,a,s,e=>t.get(e))},detachCanvas({id:e}){let t=n.get(e);t&&(t.canvas.width=0,t.canvas.height=0),n.delete(e)},snapshot({id:e}){let t=n.get(e);if(!t)throw TypeError(`There's no canvas with the id \"${e}\".`);return createImageBitmap(t.canvas)},release({id:e}){let n=t.get(e);n&&er(n),n?.close(),t.delete(e)}},{...e,packageVersion:`0.6.0`})}Tr();\n";
3
+ var blob = typeof self !== "undefined" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", jsContent], { type: "text/javascript;charset=utf-8" });
4
+ function WorkerWrapper(options) {
5
+ let objURL;
6
+ try {
7
+ objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
8
+ if (!objURL) throw "";
9
+ const worker = new Worker(objURL, {
10
+ type: "module",
11
+ name: options?.name
12
+ });
13
+ worker.addEventListener("error", () => {
14
+ (self.URL || self.webkitURL).revokeObjectURL(objURL);
15
+ });
16
+ return worker;
17
+ } catch (e) {
18
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent), {
19
+ type: "module",
20
+ name: options?.name
21
+ });
22
+ }
23
+ }
24
+ // src/adapters/render-worker/inline-worker.ts
25
+ function createInlineWorker() {
26
+ return new WorkerWrapper({ name: "hm-image-render" });
27
+ }
28
+ export { createInlineWorker };
29
+
30
+ //# sourceMappingURL=inline-worker-COOlwTsC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline-worker-BGAoQbIR.js","names":["RenderWorker"],"sources":["../../src/adapters/render-worker/inline-worker.ts"],"sourcesContent":["import RenderWorker from \"../../workers/render.worker.ts?worker&inline\";\n\n/** Starts the inlined render worker, from its own lazy chunk. */\nexport function createInlineWorker(): Worker {\n return new RenderWorker({ name: \"hm-image-render\" });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,qBAA6B;CAC3C,OAAO,IAAIA,cAAa,EAAE,MAAM,kBAAkB,CAAC;AACrD"}
1
+ {"version":3,"file":"inline-worker-COOlwTsC.js","names":["RenderWorker"],"sources":["../../src/adapters/render-worker/inline-worker.ts"],"sourcesContent":["import RenderWorker from \"../../workers/render.worker.ts?worker&inline\";\n\n/** Starts the inlined render worker, from its own lazy chunk. */\nexport function createInlineWorker(): Worker {\n return new RenderWorker({ name: \"hm-image-render\" });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,qBAA6B;CAC3C,OAAO,IAAIA,cAAa,EAAE,MAAM,kBAAkB,CAAC;AACrD"}
package/dist/react.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- export { s as ImageAdjustPanel, h as ImageCropPanel, m as ImageDrawPanel, t as ImageEditor, u as ImageEditorProvider, f as ImageExportDialog, o as ImageFilterPanel, a as ImageInfoPanel, l as ImageLayersPanel, c as ImageRedactPanel, i as ImageStage, r as ImageToolbar, d as imageEditorMessages, n as imageIcons, x as imageTools, g as useImageDocument, _ as useImageEditorState, v as useImageMessages, y as useImageSession, b as useImageView } from "./shared/editor-DrTd1KgQ.js";
2
+ export { s as ImageAdjustPanel, h as ImageCropPanel, m as ImageDrawPanel, t as ImageEditor, u as ImageEditorProvider, f as ImageExportDialog, o as ImageFilterPanel, a as ImageInfoPanel, l as ImageLayersPanel, c as ImageRedactPanel, i as ImageStage, r as ImageToolbar, d as imageEditorMessages, n as imageIcons, x as imageTools, g as useImageDocument, _ as useImageEditorState, v as useImageMessages, y as useImageSession, b as useImageView } from "./shared/editor-Bj9Xo5nf.js";
@@ -174,8 +174,8 @@ function createImageEngine(options = {}) {
174
174
  type: "module",
175
175
  name: "hm-image-render"
176
176
  });
177
- } : async () => (await import("../lazy/inline-worker-BGAoQbIR.js")).createInlineWorker,
178
- version: "0.5.0",
177
+ } : async () => (await import("../lazy/inline-worker-COOlwTsC.js")).createInlineWorker,
178
+ version: "0.6.0",
179
179
  get asset() {
180
180
  return workerUrl ?? "inline";
181
181
  }
@@ -3006,4 +3006,4 @@ var imageMessages = /* @__PURE__ */ defineMessages({
3006
3006
  });
3007
3007
  export { invalid as $, fitAspect as A, placement as At, sourceToComposition as B, asImageError as Bt, drawingPoints as C, REDACTION_MODES as Ct, compositionDeltaToSource as D, MAX_PIXEL_RATIO as Dt, aspectRatio as E, createImageRenderer as Et, compositionSize as F, PER_FILE_LIMITS as Ft, checkOutput as G, checkFilter as H, isImageError as Ht, compositionToSource as I, checkFileLimits as It, checkLayer as J, createImageReducer as K, cropRect as L, checkOutputLimits as Lt, moveCrop as M, createImageEngine as Mt, nudgeCropOnScreen as N, engineInternals as Nt, cropInComposition as O, backingSize as Ot, wholeCrop as P, OUTPUT_LIMITS as Pt, checkCropInSource as Q, orientedSize as R, imageLimitDefinitions as Rt, drawingBounds as S, NEUTRAL_DEVELOP as St, ASPECT_PRESETS as T, createPlan as Tt, checkMetadata as U, checkDevelop as V, ImageError as Vt, checkOrientation as W, Invalid as X, checkRedaction as Y, checkCrop as Z, sceneToLayerSource as _, MAX_PLAN_ITEMS as _t, fitRedactionRegion as a, longerThan as at, arrowBounds as b, MAX_STROKE_RUNS as bt, redactionBlocksInScene as c, FULL_SIZE as ct, applyMatrix as d, LAYER_KINDS as dt, isRecord as et, fitTextLines as f, LAYER_SHAPES as ft, layerToScene as g, MAX_LAYER_TEXT_LENGTH as gt, layerToOutput as h, MAX_LAYER_NAME_LENGTH as ht, compositionRectToScene as i, NO_METADATA as it, handleInSource as j, createImageProcessor as jt, dragHandle as k, fittedView as kt, redactionRectInOutput as l, LAYER_ALIGNMENTS as lt, isRightToLeft as m, MAX_KEY_LENGTH as mt, createImageSession as n, EMPTY_KEEPABLE_METADATA as nt, redactionBlockSize as o, DEVELOP_ADJUSTMENTS as ot, invertMatrix as p, MAX_DRAWING_STROKES as pt, FORBIDDEN_IN_TEXT as q, newLayerBox as r, MAX_METADATA_LENGTH as rt, redactionBlocksInOutput as s, FILTER_PRESETS as st, imageMessages as t, onlyFields as tt, sceneRectToComposition as u, LAYER_FONTS as ut, sceneToOutput as v, MAX_RUN_POINTS as vt, simplifyStroke as w, UPRIGHT as wt, arrowOutline as x, MAX_STROKE_WIDTH as xt, createImageKey as y, MAX_SCENE_COORDINATE as yt, outputSize as z, imageLimits as zt };
3008
3008
 
3009
- //# sourceMappingURL=core-DKUm3jGZ.js.map
3009
+ //# sourceMappingURL=core-VHeENp7j.js.map