jpegxl 8.4.0 → 8.4.1

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.
Files changed (88) hide show
  1. package/README.md +294 -229
  2. package/dist/animation.browser.mjs +2 -2
  3. package/dist/animation.mjs +2 -2
  4. package/dist/capture-complete.browser.mjs +2 -2
  5. package/dist/capture-complete.mjs +2 -2
  6. package/dist/capture-groups.mjs +2 -2
  7. package/dist/capture.browser.mjs +2 -2
  8. package/dist/capture.mjs +2 -2
  9. package/dist/cli-add.mjs +2 -2
  10. package/dist/cli-astro.mjs +2 -2
  11. package/dist/cli-cloudflare.mjs +2 -2
  12. package/dist/cli-emdash.mjs +2 -2
  13. package/dist/cli-places.mjs +2 -2
  14. package/dist/cli-selftest.mjs +2 -2
  15. package/dist/cli-workers.mjs +2 -2
  16. package/dist/cli.mjs +2 -2
  17. package/dist/decode.browser.mjs +2 -2
  18. package/dist/decode.mjs +2 -2
  19. package/dist/decode.node.mjs +2 -2
  20. package/dist/format.browser.mjs +2 -2
  21. package/dist/format.mjs +2 -2
  22. package/dist/hdr.mjs +2 -2
  23. package/dist/helpers.mjs +2 -2
  24. package/dist/index.browser.mjs +2 -2
  25. package/dist/index.mjs +2 -2
  26. package/dist/jpeg.browser.mjs +2 -2
  27. package/dist/jpeg.mjs +2 -2
  28. package/dist/jpeg.node.mjs +2 -2
  29. package/dist/metadata.mjs +2 -2
  30. package/dist/polyfill.mjs +2 -2
  31. package/dist/resumable.mjs +2 -2
  32. package/dist/resumable.node.mjs +2 -2
  33. package/dist/serve.mjs +2 -2
  34. package/dist/serve.node.mjs +2 -2
  35. package/dist/upload.browser.mjs +2 -2
  36. package/dist/upload.mjs +2 -2
  37. package/dist/verify.mjs +2 -2
  38. package/dist/verify.node.mjs +2 -2
  39. package/dist/wasm-modules.mjs +2 -2
  40. package/examples/agents/jxl-tools.mjs +8 -8
  41. package/examples/android/prepare-assets.mjs +2 -2
  42. package/examples/capacitor/prepare-assets.mjs +2 -2
  43. package/examples/emdash/admin-work.mjs +1 -1
  44. package/examples/emdash/backfill.mjs +4 -4
  45. package/examples/emdash/background.mjs +5 -5
  46. package/examples/emdash/browser-candidate.mjs +1 -1
  47. package/examples/emdash/deliver.mjs +2 -2
  48. package/examples/emdash/host-policy.mjs +6 -6
  49. package/examples/emdash/index.mjs +3 -3
  50. package/examples/emdash/job-runner.mjs +31 -31
  51. package/examples/emdash/job-store.mjs +21 -21
  52. package/examples/emdash/jpeg-source.mjs +2 -2
  53. package/examples/emdash/library-jobs.mjs +21 -21
  54. package/examples/emdash/local-store.mjs +16 -16
  55. package/examples/emdash/media-admin.mjs +9 -9
  56. package/examples/emdash/media-plugin.mjs +62 -62
  57. package/examples/emdash/media-storage.mjs +55 -55
  58. package/examples/emdash/media-words.mjs +89 -89
  59. package/examples/emdash/media-worker.mjs +1 -1
  60. package/examples/emdash/original-envelope.mjs +2 -2
  61. package/examples/emdash/originals.mjs +77 -77
  62. package/examples/emdash/r2-store.mjs +3 -3
  63. package/examples/emdash/read-all.mjs +14 -14
  64. package/examples/emdash/server-only.mjs +1 -1
  65. package/examples/emdash/storage.mjs +1 -1
  66. package/examples/emdash/structural-delivery.mjs +42 -42
  67. package/examples/emdash/thread-driver.mjs +15 -15
  68. package/examples/emdash/thread-worker.mjs +3 -3
  69. package/examples/emdash/work-queue.mjs +11 -11
  70. package/examples/flutter/prepare-assets.mjs +3 -3
  71. package/examples/ios/prepare-assets.mjs +3 -3
  72. package/examples/page-rects.js +14 -14
  73. package/examples/react-native/src/JXLProvider.tsx +19 -9
  74. package/examples/snapdom/jxl.js +3 -2
  75. package/examples/svg-jxl.js +10 -10
  76. package/package.json +1 -1
  77. package/types/animation.d.mts +2 -2
  78. package/types/capture-complete.d.mts +5 -5
  79. package/types/capture.d.mts +1 -1
  80. package/types/format.d.mts +2 -2
  81. package/types/index.d.mts +6 -6
  82. package/types/jpeg.d.mts +1 -1
  83. package/types/result.d.mts +5 -4
  84. package/types/resumable.d.mts +7 -7
  85. package/types/serve.d.mts +1 -1
  86. package/types/types.d.mts +19 -18
  87. package/types/upload.d.mts +1 -1
  88. package/types/verify.d.mts +4 -4
@@ -1,2 +1,2 @@
1
- /*! rapier-jxl 8.4.0 | MIT */
2
- function e(e,t,r=Wr){if("number"==typeof r&&(r={edge:Wr.edge,pixels:r}),!Number.isInteger(e)||!Number.isInteger(t)||e<1||t<1)throw Vr("JXL_INPUT","Width and height are whole numbers of at least 1.");if(e>r.edge||t>r.edge)throw Vr("JXL_DIMENSIONS","A side is at most "+r.edge+" pixels"+(r.edge===Wr.edge?", the JPEG XL size field.":"."));if(e*t>r.pixels)throw Vr("JXL_DIMENSIONS","A picture is at most "+r.pixels.toLocaleString("en-US")+" pixels (maxPixels).")}async function t(e){let t=URL.createObjectURL(e),r=new Image;try{r.src=t,await r.decode()}finally{URL.revokeObjectURL(t)}return{image:r,width:r.naturalWidth,height:r.naturalHeight,close:()=>r.removeAttribute("src")}}async function r(t,r,n){if(!r||"object"!=typeof r||Array.isArray(r))throw Vr("JXL_INPUT","Native picture options are an object.");let{width:a,height:i,colorSpace:o="srgb",signal:l,maxPixels:s=Wr.pixels,orientation:u=1,sampleFormat:c="uint",bitDepth:f=8,alphaPremultiplied:h=!1,animation:d=!1,alpha:m,...p}=r;if(l?.aborted)throw l.reason;if(!(t instanceof Uint8Array&&t.length))throw Vr("JXL_INPUT","Native picture bytes are a nonempty Uint8Array.");if(!Number.isSafeInteger(s)||s<1)throw Vr("JXL_INPUT","Native picture maxPixels is a positive whole number.");if(e(a,i,{pixels:s,edge:1073741824}),!["srgb","display-p3"].includes(o)||1!==u||"uint"!==c||8!==f||!1!==h||!1!==d||![void 0,!0,!1].includes(m)||Object.keys(p).length)throw Qr("Native picture readback supports only orientation-1 still RGB8, unassociated alpha, and sRGB or Display-P3; other sample, color, ICC and animation metadata is unsupported.");if(null!=l&&("boolean"!=typeof l.aborted||"function"!=typeof l.addEventListener||"function"!=typeof l.removeEventListener))throw Vr("JXL_INPUT","Native picture signal must support abort events.");let y=globalThis.createImageBitmap,g=globalThis.OffscreenCanvas,M=globalThis.Blob;if("function"!=typeof y||"function"!=typeof g||"function"!=typeof M)throw Vr("JXL_PLATFORM","Measuring a photo needs a browser that decodes JPEG XL (createImageBitmap and OffscreenCanvas). Use effort 3 or lower here.");let b,w,v,L,I,A,x,N=!1,O=!1,P=e=>{N||(N=!0,x=e)},E=()=>{try{P(l.reason)}catch(e){P(e)}},T=()=>{if(!N&&l?.aborted&&E(),N)throw x},U=(e,t)=>{try{return t()}catch(t){throw Qr(e,t)}},S=(e,t)=>{try{t()}catch(t){P(Qr(e,t))}};try{l&&(O=!0,l.addEventListener("abort",E,{once:!0})),T();let e=U("Native picture bytes could not be placed in a Blob.",()=>n(y,M));T();try{b=await e()}catch(e){P(Qr("This browser could not decode the JPEG XL file.",e))}if(T(),!b||"function"!=typeof b.close)throw Qr("Native JPEG XL decoding did not return a closable ImageBitmap.");let t=U("Native picture dimensions could not be read.",()=>[b.width,b.height]);if(t[0]!==a||t[1]!==i)throw Vr("JXL_DIMENSIONS","Native picture dimensions differ from the admitted still producer.");w=U("This realm could not allocate the native picture canvas.",()=>new g(1,1)),T();let r=U("This realm could not create the native picture WebGL2 context.",()=>w.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,antialias:!1,depth:!1,stencil:!1}));if(v=r,r){if($r.some(e=>"function"!=typeof r[e]))throw Qr("Native picture readback needs a WebGL2 context.");if(!1!==U("Native picture context loss state could not be read.",()=>r.isContextLost()))throw Qr("The native picture WebGL2 context is lost.");let e=new Uint8ClampedArray(a*i*4);if(U("The native JPEG XL picture could not be read back.",()=>{let t=Math.min(r.getParameter(r.MAX_TEXTURE_SIZE),4096);if(!Number.isSafeInteger(t)||t<1)throw new Error("No texture size.");L=r.createTexture(),I=r.createFramebuffer(),r.bindTexture(r.TEXTURE_2D,L),r.bindFramebuffer(r.FRAMEBUFFER,I),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.NONE),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_ALIGNMENT,1),r.pixelStorei(r.PACK_ALIGNMENT,1),r.pixelStorei(r.PACK_ROW_LENGTH,a);for(let n=0;n<i;n+=t)for(let o=0;o<a;o+=t){let l=Math.min(t,a-o),s=Math.min(t,i-n);if(r.pixelStorei(r.UNPACK_SKIP_PIXELS,o),r.pixelStorei(r.UNPACK_SKIP_ROWS,n),r.texImage2D(r.TEXTURE_2D,0,r.RGBA8,l,s,0,r.RGBA,r.UNSIGNED_BYTE,b.image??b),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,L,0),r.checkFramebufferStatus(r.FRAMEBUFFER)!==r.FRAMEBUFFER_COMPLETE)throw new Error("Incomplete framebuffer.");r.readPixels(0,0,l,s,r.RGBA,r.UNSIGNED_BYTE,e,4*(n*a+o))}let n=r.getError();if(n!==r.NO_ERROR)throw new Error("WebGL error "+n+".")}),T(),!1!==U("Native picture context loss state could not be read.",()=>r.isContextLost()))throw Qr("The native picture WebGL2 context was lost during readback.");A={data:e,width:a,height:i,colorSpace:o,sampleFormat:"uint",bitDepth:8,alphaPremultiplied:!1}}else{if("srgb"!==o)throw Qr("Reading back a Display P3 JPEG XL decode needs WebGL2, which this realm lacks.");v=null,U("The native picture canvas could not be sized.",()=>{w.width=a,w.height=i});let e=U("This realm could not create the native picture 2D context.",()=>w.getContext("2d",{willReadFrequently:!0}));if(!e||"function"!=typeof e.drawImage||"function"!=typeof e.getImageData)throw Qr("Native picture readback needs a WebGL2 or a 2D context.");let t=U("The native JPEG XL picture could not be read back.",()=>(e.drawImage(b.image??b,0,0),e.getImageData(0,0,a,i).data));for(let e=3;e<t.length;e+=4)if(255!==t[e])throw Qr("Reading back a JPEG XL decode with transparency needs WebGL2, which this realm lacks.");T(),A={data:new Uint8ClampedArray(t.buffer,t.byteOffset,t.length),width:a,height:i,colorSpace:o,sampleFormat:"uint",bitDepth:8,alphaPremultiplied:!1}}}catch(e){P(e)}finally{b&&S("The native picture ImageBitmap could not be closed.",()=>b.close()),L&&S("The native picture texture could not be deleted.",()=>v.deleteTexture(L)),I&&S("The native picture framebuffer could not be deleted.",()=>v.deleteFramebuffer(I)),w&&(S("The native picture canvas width could not be released.",()=>{w.width=0}),S("The native picture canvas height could not be released.",()=>{w.height=0})),O&&S("The native picture abort listener could not be removed.",()=>l.removeEventListener("abort",E))}return T(),A}function n(){let e=globalThis.createImageBitmap;if(!on||on.api!==e){let t=on={api:e,reads:"function"!=typeof e||"function"!=typeof globalThis.OffscreenCanvas||"function"!=typeof globalThis.Blob?Promise.resolve(!1):r(an,{width:1,height:1},rn(an)).then(()=>!0,()=>!1)};t.reads=t.reads.then(e=>(!e&&on===t&&(on=null),e))}return on.reads}async function a(e,t){let n=(t,n,a)=>r(t,{width:1,height:1,colorSpace:n},e(t)).then(({data:e})=>200===e[0]&&100===e[1]&&50===e[2]&&e[3]===a);return{alpha:await n(ln,"srgb",128),displayP3:await n(sn,"display-p3",255),image:t}}function i(){let e=globalThis.createImageBitmap;if(!cn||cn.api!==e){let t=cn={api:e,reads:null},r=()=>(cn===t&&(cn=null),{...un,bitmap:un});t.reads=n().then(async e=>{if(!e)return r();let t=await a(rn,!1);if(t.alpha&&t.displayP3||"function"!=typeof globalThis.Image||"function"!=typeof URL.createObjectURL)return{...t,bitmap:t};let n=await a(nn,!0);return n.alpha+n.displayP3>t.alpha+t.displayP3?{...n,bitmap:t}:{...t,bitmap:t}}).catch(r)}return cn.reads}function o(e){try{null!==e&&("object"==typeof e||"function"==typeof e)&&mn.add(e)}catch{}return e}function l(e){try{if(mn.has(e))return e;if(Yr(e))return Object.assign(new Error(`Not enough memory for this picture${qr(e)}; free memory or use a smaller picture.`,{cause:e}),{code:"JXL_MEMORY"});let t=e?.code;if("JXL_DICTIONARY"===t&&"This runtime has no Brotli decoder for RFC 7932's dictionary."===e?.message)return Object.assign(new Error("This runtime has no Brotli decoder for RFC 7932's dictionary; use a runtime with Brotli support.",{cause:e}),{code:"JXL_PLATFORM"});if("string"!=typeof t||!t.startsWith("JXL_")||hn.has(t))return e;let r=Object.hasOwn(dn,t)?dn[t]:"JXL_INTERNAL";return Object.assign(new Error(String(e.message??""),{cause:e}),{code:r})}catch{return e}}function s(e){if(void 0===e)return;if(!e||"object"!=typeof e&&"function"!=typeof e)throw fn("JXL_OPTIONS","Invalid signal; pass an AbortSignal.");let t,r;try{t=e.aborted,r=e.addEventListener}catch(e){throw o(e)}if("boolean"!=typeof t||"function"!=typeof r)throw fn("JXL_OPTIONS","Invalid signal; pass an AbortSignal.");return e}function u(e){if(null==e)return;let t,r;try{t=e.aborted,t&&(r=e.reason)}catch(e){throw o(e)}if(t)throw o(void 0===r?Kr():r)}function c(e,t="Options"){if(void 0===e)return{};if(!e||"object"!=typeof e||Array.isArray(e))throw fn("JXL_OPTIONS",`${t} must be an object; pass named fields in {}.`);return e}function f(e,t,r=[]){let n=c(e,t);try{let e={...n};for(let t of r)!Object.hasOwn(e,t)&&t in n&&(e[t]=n[t]);return e}catch(e){throw o(e)}}function h(e,t,r=Dr,n=1073741824){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<1||t<1||e>n||t>n)throw fn("JXL_DIMENSIONS",`Image sides must be whole numbers from 1 to ${n} pixels${1073741824===n?", the JPEG XL size field":""}; resize the image to fit.`);if(e*t>r)throw fn("JXL_DIMENSIONS",`${e*t} pixels is over maxPixels (${r}): resize or raise maxPixels.`)}function d(e){if(void 0===e)return Dr;if(!Number.isSafeInteger(e)||e<1)throw fn("JXL_OPTIONS","Invalid maxPixels; use a positive whole number.");return e}function m(e){if(!e||"object"!=typeof e||Array.isArray(e)||!Object.keys(e).length)throw Ln("Supply named precompiled WebAssembly.Module objects.");let t=Object.entries(e);for(let[e,r]of t){if(!Object.hasOwn(yn,e))throw Ln(`Unknown WebAssembly module: ${e}.`);let t,n;try{t=WebAssembly.Module.imports(r),n=WebAssembly.Module.exports(r)}catch{throw Ln(`${e} must be a compiled WebAssembly.Module.`)}let a="kernels"===e||"general"===e;if(Mn(n)!==yn[e]||(a?1!==t.length||"env"!==t[0].module||"memory"!==t[0].name||"memory"!==t[0].kind:0!==t.length))throw Ln(`The ${e} module does not match; use this package's.`);if(bn.has(e)&&bn.get(e)!==r||wn.has(e)&&wn.get(e)!==r)throw Ln(`The ${e} module is already set; configure modules before any work.`)}for(let[e,r]of t)bn.set(e,r);vn=!0}async function p(e,t){return xn(),!(!wn.get(e)&&!bn.has(e))||(On.has(e)||(wn.has(e)||wn.set(e,null),On.set(e,(async()=>{let r=await WebAssembly.compile(t());return await WebAssembly.instantiate(Uint8Array.of(0,97,115,109,1,0,0,0)),wn.get(e)||wn.set(e,r),Pn.delete(e),!0})().catch(t=>(On.delete(e),Pn.set(e,t),!1)))),On.get(e))}function y(e,t){if(xn(),wn.get(e))return wn.get(e);wn.set(e,null);let r,n=bn.get(e);if(n)return wn.set(e,n),n;try{r=new WebAssembly.Module(t())}catch(t){throw vn?Ln(`The ${e} module is missing; supply this package's.`):t}return wn.set(e,r),r}function g(){if(!_n){let e=new WebAssembly.Memory({initial:48});_n={memory:e,exports:new WebAssembly.Instance(y("kernels",()=>gn(Fn)),{env:{memory:e}}).exports}}return _n}function M(e,t=null,r=null){let n={lose:e,refresh:t,gain:r};return Bn.push(n),n}function b(e){if(Rn===e)return;let t=Rn;Rn=e;for(let t of Bn)t!==e&&t.lose();t&&e.gain?.()}function w(e,t){let r={};for(let[n,a]of Object.entries(e))r[n]="function"==typeof a?(...e)=>(b(t),a(...e)):a;return r}function v(e){return e>=0?2*e:2*-e-1}function L(e,t,r,n){let[a,i,o,l,s,u,c,f]=e;for(let e=r;e+64<=n;e+=64){for(let r=0;r<16;r++){let n=e+4*r;Yn[r]=t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3]}for(let e=16;e<64;e++){let t=Yn[e-15],r=Yn[e-2];Yn[e]=((t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3)+Yn[e-7]+((r>>>17|r<<15)^(r>>>19|r<<13)^r>>>10)+Yn[e-16]|0}let r=a,n=i,h=o,d=l,m=s,p=u,y=c,g=f;for(let e=0;e<64;e++){let t=g+((m>>>6|m<<26)^(m>>>11|m<<21)^(m>>>25|m<<7))+(m&p^~m&y)+Hn[e]+Yn[e]|0,a=((r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10))+(r&n^r&h^n&h)|0;g=y,y=p,p=m,m=d+t|0,d=h,h=n,n=r,r=t+a|0}a=a+r|0,i=i+n|0,o=o+h|0,l=l+d|0,s=s+m|0,u=u+p|0,c=c+y|0,f=f+g|0}e.set([a,i,o,l,s,u,c,f])}function I(e,t){let r=Int32Array.from(e.h),n=e.tail,a=0;if(n.length){let i=Uint8Array.from([...n,...t.subarray(0,64-n.length)]);if(i.length<64)return{h:e.h,length:e.length+t.length,tail:[...i]};L(r,i,0,64),a=64-n.length}let i=a+(t.length-a&-64);return L(r,t,a,i),{h:[...r],length:e.length+t.length,tail:[...t.subarray(i)]}}function A(e){let t=8*e.length,r=new Uint8Array(e.tail.length+72&-64);r.set(e.tail),r[e.tail.length]=128;let n=new DataView(r.buffer);n.setUint32(r.length-8,Math.floor(t/2**32)),n.setUint32(r.length-4,t>>>0);let a=Int32Array.from(e.h);return L(a,r,0,r.length),Array.from(a,e=>(e>>>0).toString(16).padStart(8,"0")).join("")}function x(e){try{return e()}catch(e){throw"JXL_INPUT"===e?.code?e:oa("Invalid checkpoint data.")}}function N(e,t=Qn){if(!(e instanceof Uint8Array))throw oa("Checkpoint bytes must be a Uint8Array.");let r=ra.call(e),n=aa.call(e),a=na.call(e);if(ia.call(n),r>t)throw oa("Checkpoint bytes exceed their limit.");return new Uint8Array(n,a,r)}function O(e){if(null===e||"object"!=typeof e)throw oa("A checkpoint record must contain plain data.");let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&null!==t)throw oa("A checkpoint record must contain plain data.");let r=Reflect.ownKeys(e);if(r.some(e=>"string"!=typeof e))throw oa("Invalid checkpoint fields.");return r.map(t=>{let r=Object.getOwnPropertyDescriptor(e,t);if(!r||!r.enumerable||!Object.hasOwn(r,"value"))throw oa("Checkpoint accessors and hidden fields are unsupported.");return[t,r.value]})}function P(e){if(!Array.isArray(e)||Object.getPrototypeOf(e)!==Array.prototype)throw oa("A checkpoint array must contain plain data.");let t=e.length;if(t>$n>>1||Reflect.ownKeys(e).length!==t+1)throw oa("Invalid checkpoint array.");let r=new Array(t);for(let n=0;n<t;n++){let t=Object.getOwnPropertyDescriptor(e,String(n));if(!t||!t.enumerable||!Object.hasOwn(t,"value"))throw oa("Checkpoint arrays must be dense data arrays.");r[n]=t.value}return r}function E(e,t){let r=new Set,n=()=>oa("A checkpoint record exceeds 1 MiB."),a=e=>la.test(e)?'"'+e+'"':JSON.stringify(e),i="",o=e=>{if((i+=e).length>$n)throw n()},l=[],s=e=>{if(null===e)return o("null");let i=typeof e;if("boolean"===i)return o(e?"true":"false");if("number"===i){if(!Number.isFinite(e))throw oa("Checkpoint numbers must be finite.");return o(Object.is(e,-0)?"0":""+e)}if("string"===i){if(e.length>$n)throw n();return o(a(e))}if("object"!==i||t&&r.has(e))throw oa("Checkpoints cannot contain unsupported values or cycles.");if(t&&r.add(e),Array.isArray(e))return o("["),void l.push({v:e,items:t?P(e):e,record:!1,at:0});let s=t?O(e):Object.keys(e).map(t=>[t,e[t]]);if(s.length>$n/5)throw n();s.sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0),o("{"),l.push({v:e,items:s,record:!0,at:0})};for(s(e);l.length;){let e=l[l.length-1],{items:i,record:u}=e;if(e.at===i.length){o(u?"}":"]"),l.pop(),t&&r.delete(e.v);continue}let c=i[e.at];if(e.at++&&o(","),u){if(c[0].length>$n)throw n();o(a(c[0])+":"),s(c[1])}else s(c)}return i}function T(e){return x(()=>{let t=Zn.encode(E(e,!0));if(t.length>$n)throw oa("A checkpoint record exceeds 1 MiB.");return t})}function U(e,t=null){return x(()=>{let r=Zn.encode(t??JSON.stringify(e));if(r.length>$n)throw oa("A checkpoint record exceeds 1 MiB.");return r})}function S(e){return x(()=>JSON.parse(ea.decode(N(e,$n))))}function j(e){return x(()=>{let t=ea.decode(N(e,$n)),r=JSON.parse(t);if(t!==E(r,!1))throw oa("Checkpoint JSON is not canonical.");return r})}async function J(e){let t=x(()=>N(e));try{if(!globalThis.crypto?.subtle)return A(I(qn(),t));let e=await globalThis.crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,"0")).join("")}catch(e){throw"JXL_INPUT"===e?.code?e:oa("Cannot hash checkpoint bytes.")}}async function F(e,t,r){Array.isArray(t)||ua("A part frontier is an ordered array.");let n=new Map;for(let e of t)(!e||"string"!=typeof e.hash||!e.hash.length||!Number.isSafeInteger(e.length)||e.length<0||e.length>1048576||2!==Object.keys(e).length)&&ua("Invalid part frontier reference."),n.has(e.hash)&&n.get(e.hash).length!==e.length&&ua("Conflicting part frontier lengths."),n.set(e.hash,e);if(!n.size)return;if(!1===e.durable)return void await(r?.([...n.values()]));"function"!=typeof e.prefetch&&ua("The immutable part reader must support declared read frontiers.");let a=[],i=0;for(let t of n.values())(128===a.length||i+t.length>sa)&&(await e.prefetch(a),await(r?.(a)),a=[],i=0),a.push(t),i+=t.length;a.length&&(await e.prefetch(a),await(r?.(a)))}function k(e){let t=new Map,r=0,n=e=>{let n=t.get(e);n&&(r-=n.length,t.delete(e))};return{get size(){return t.size},has:e=>t.has(e),get(e){let r=t.get(e);return r&&(t.delete(e),t.set(e,r)),r},delete:n,set(a,i){if(n(a),!(i.length>e)){for(;r+i.length>e;)n(t.keys().next().value);t.set(a,i),r+=i.length}}}}function X(e,t,r=!0,n){let a=new Map,i=k(sa),o=0,l=0,s=async e=>{La(t),(!(e instanceof Uint8Array)||e.length>ca)&&ya("An immutable part is at most 1 MiB.");let r=new Uint8Array(e),n=await J(r),o={hash:n,length:r.length};return La(t),a.has(n)||a.set(n,{ref:o,bytes:r}),i.delete(n),o},u=async n=>{Ia(n),La(t);let s=a.get(n.hash)?.bytes??i.get(n.hash);if(!s){"function"!=typeof e&&ya("The host must read immutable parts."),l++;let a=await e(n);La(t),(!(a instanceof Uint8Array)||a.length!==n.length)&&ya("Missing or truncated immutable part."),s=new Uint8Array(a),await J(s)!==n.hash&&ya("Corrupted immutable part."),La(t),o+=s.length,r&&i.set(n.hash,s)}return s.length!==n.length&&ya("Part length does not match its digest."),r||i.delete(n.hash),s};return{read:async e=>new Uint8Array(await u(e)),write:s,durable:!0,fetch:async e=>{La(t),(!Array.isArray(e)||e.length>128||e.reduce((e,t)=>e+Ia(t).length,0)>sa)&&ya("Invalid part read batch."),"function"!=typeof n&&ya("The host must provide bounded batched part reads."),l++;let r=await n(e.map(e=>({hash:e.hash,length:e.length})));return La(t),(!Array.isArray(r)||r.length!==e.length)&&ya("A part read batch has the wrong number of results."),r.forEach((t,r)=>{(!(t instanceof Uint8Array)||t.length!==e[r].length)&&ya("Missing or truncated immutable part."),o+=t.length}),r},borrow:u,prefetch:async e=>{La(t),(!Array.isArray(e)||e.length>128)&&ya("A part read batch has at most 128 references.");let r=0,s=new Map;for(let t of e){Ia(t),r+=t.length,r>sa&&ya("A part read batch is at most 8 MiB.");let e=a.get(t.hash)?.bytes??i.get(t.hash);(s.has(t.hash)&&s.get(t.hash).length!==t.length||e&&e.length!==t.length)&&ya("Part length does not match its digest."),e||s.set(t.hash,{hash:t.hash,length:t.length})}if(!s.size)return;"function"!=typeof n&&ya("The host must provide bounded batched part reads.");let u=[...s.values()];l++;let c=await n(u.map(e=>({...e})));La(t),(!Array.isArray(c)||c.length!==u.length)&&ya("A part read batch has the wrong number of results.");let f=c.map((e,t)=>((!(e instanceof Uint8Array)||e.length!==u[t].length)&&ya("Missing or truncated immutable part."),new Uint8Array(e))),h=await Promise.all(f.map(J));La(t);for(let e=0;e<h.length;e++)h[e]!==u[e].hash&&ya("Corrupted immutable part.");for(let e=0;e<f.length;e++)i.set(u[e].hash,f[e]),o+=f[e].length},bytesRead:()=>o,callsRead:()=>l,readJSON:async e=>j(await u(e)),writeJSON:e=>s(T(e)),parts:()=>[...a.values()]}}async function _(e){let t=T(e);return t.length>ha&&ya("The checkpoint manifest exceeds 16 KiB."),{...e,hash:await J(t)}}async function R(e,t,r){let n=Ma(e);(!n||"rapier-jxl/checkpoint"!==n.format)&&ya("This is not a rapier-jxl checkpoint."),n.codec!==t&&ya("This checkpoint is of another operation."),n.build!==r&&ya("This checkpoint was written by another rapier-jxl version; start the job again."),(!da.test(n.hash)||!da.test(n.job)||!Number.isSafeInteger(n.revision)||n.revision<0||!["active","done"].includes(n.status)||null!==n.previous&&!da.test(n.previous))&&ya("Invalid checkpoint manifest.");let{hash:a,...i}=n,o=T(i);if((o.length>ha||await J(o)!==a)&&ya("Corrupted checkpoint manifest."),Aa(n.source),("done"!==n.status||null!==n.state)&&Ia(n.state),pa(n.reads),await J(T({codec:t,build:r,source:n.source,plan:n.plan}))!==n.job&&ya("The checkpoint job identity changed."),"done"===n.status){(!n.output||!Number.isSafeInteger(n.output.byteLength)||n.output.byteLength<0||n.output.byteLength>4294967295)&&ya("Invalid completed output.");let{refs:e,index:t}=n.output;(n.output.byteLength?null===e?(Ia(t),!1):!Array.isArray(e)||!e.length||e.length>16||null!==t||(e.forEach(Ia),e.reduce((e,t)=>e+t.length,0)!==n.output.byteLength):null!==e||null!==t)&&ya("Invalid completed output."),void 0===n.output.result&&ya("Invalid completed output.")}else null!==n.output&&ya("An unfinished checkpoint cannot expose output.");return n}function B(e){let t=T(e);return t.length>ha&&ya("Completion metadata exceeds 16 KiB."),j(t)}function G(e,t){return async(r,n)=>{if((!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<0||n<0||r+n>t.byteLength)&&ya("A source read is a bounded byte range."),!n)return new Uint8Array;"function"!=typeof e.readSource&&ya("The host must read the original (readSource).");let a=await e.readSource(r,n);return La(e.signal),(!(a instanceof Uint8Array)||a.length!==n)&&ya("Missing or truncated source range."),new Uint8Array(a)}}function C(e,t,r,n){let a=wa(t.byteLength),i=Math.ceil(t.byteLength/a),o=k(ma);(!Array.isArray(n)||n.length!==i||!n.every(e=>da.test(e)))&&ya("Invalid source chunk digests.");let l=async(e,t)=>{let i=await Promise.all(Array.from({length:Math.ceil(t.length/a)},(e,r)=>J(t.subarray(r*a,Math.min(t.length,(r+1)*a)))));La(r);for(let t=0;t<i.length;t++)if(i[t]!==n[e+t])throw Vr("JXL_INPUT","The source bytes do not match their pinned digest.")};return async(r,n)=>{if((!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<0||n<0||r+n>t.byteLength)&&ya("A source read is a bounded byte range."),!n)return new Uint8Array;let i=Math.floor(r/a),s=Math.ceil((r+n)/a);if(!r&&n===t.byteLength&&!o.size){let t=await e(0,n);return await l(0,t),t}let u=new Uint8Array(n),c=(e,t)=>{let i=e*a,o=Math.max(r,i),l=Math.min(r+n,i+t.length);u.set(t.subarray(o-i,l-i),o-r)},f=s,h=i;for(let e=i;e<s;e++){let t=o.get(e);t?c(e,t):(f=Math.min(f,e),h=e+1)}if(f<h){let r=await e(f*a,Math.min(t.byteLength,h*a)-f*a);await l(f,r);for(let e=f;e<h;e++){let t=r.subarray((e-f)*a,Math.min(r.length,(e-f+1)*a));c(e,t),t.length<=ma&&!o.has(e)&&o.set(e,t.slice())}}return u}}function D(e){async function t(e,t){La(t?.signal);let r=await R(e,i,o);return"done"!==r.status&&ya("The encode is not complete."),(!t||!ba(Aa(t.source),r.source))&&ya("The source generation or digest changed."),t.expectedRevision!==r.revision&&ga("The host revision does not match this checkpoint."),ba(l(r.plan.options??r.plan,r.source,r.plan.verify??!1),r.plan)||ya("The normalized codec plan changed."),await(t.admit?.(r.plan,r.source)),r}if(!e||"string"!=typeof e.id||!e.id.length||e.id.length>128||!da.test(e.build)||!["normalize","start","step"].every(t=>"function"==typeof e[t]))throw Vr("JXL_INPUT","A stepper needs a named codec, exact build digest and data-state operations.");let{normalize:r,start:n,step:a}=e,i=e.id,o=e.build,l=(e,t,n=!1)=>{if("boolean"!=typeof n)throw Vr("JXL_OPTIONS","verify is a boolean.");let a=Ma(r(Ma(e),t));return n?{...a,verify:!0}:a};return Object.freeze({start:async function({source:e,options:t={},verify:r=!1,admit:n}){e=Aa(e);let a=l(t,e,r);await(n?.(a,e));let s=X(),u=await J(T({codec:i,build:o,source:e,plan:a})),c=await s.writeJSON({phase:"verify",offset:0,hash:qn(),chunks:[]});return{checkpoint:await _({format:"rapier-jxl/checkpoint",codec:i,build:o,job:u,source:e,plan:a,revision:0,previous:null,state:c,reads:[],status:"active",output:null}),parts:s.parts()}},advance:async function(t,r,s={units:1}){La(r?.signal),s=xa(s);let u=await R(t,i,o);if(!r||!ba(Aa(r.source),u.source))throw Vr("JXL_INPUT","The source generation or digest changed.");(!Number.isSafeInteger(r.expectedRevision)||r.expectedRevision!==u.revision)&&ga("The host revision does not match this checkpoint."),"done"===u.status&&ga("This checkpoint already completed."),u.revision===Number.MAX_SAFE_INTEGER&&ya("The checkpoint revision cannot advance."),ba(l(u.plan.options??u.plan,u.source,u.plan.verify??!1),u.plan)||ya("The normalized codec plan changed."),await(r.admit?.(u.plan,u.source));let c=await J(T({checkpoint:u.hash,budget:s})),f=X(r.read,r.signal,!0,r.readMany),h=G(r,u.source),d=null,m=!1,p=0,y=0;await F(f,[u.state,...u.reads]);let g,M=await f.readJSON(u.state),b=[],w=[],v=(t,r,n=[])=>{let a=[t.state,...t.reads??[],...t.output?.refs??[],t.output?.index,...n,...r&&e.refs?e.refs(r):[]].filter(Boolean);return new Map(a.map(e=>[e.hash,e]))},L=v(u,"encode"===M?.phase?M.codec:null),x=[],N=Number.isFinite(r.deadline)?r.deadline:1/0;for(let e=0;e<s.units&&void 0===g&&(0===e||performance.now()<N);e++)if(La(r.signal),"verify"===M.phase){let e=M.hash;(!Number.isSafeInteger(M.offset)||M.offset<0||M.offset>=u.source.byteLength||!e||e.length!==M.offset||!Array.isArray(e.h)||8!==e.h.length||!e.h.every(Number.isSafeInteger)||!Array.isArray(e.tail)||e.tail.length!==M.offset%64||!e.tail.every(e=>Number.isInteger(e)&&e>=0&&e<256)||!Array.isArray(M.chunks)||M.offset%va(u.source.byteLength)||M.chunks.length!==M.offset/wa(u.source.byteLength)||!M.chunks.every(e=>da.test(e)))&&ya("Invalid source checkpoint.");let t=Math.min(va(u.source.byteLength),u.source.byteLength-M.offset),r=M.offset,a=wa(u.source.byteLength),i=!r&&u.source.byteLength<=2097152,o=i?u.source.byteLength:t,l=await h(r,o),s=await Promise.all(Array.from({length:Math.ceil(o/a)},(e,t)=>J(l.subarray(t*a,Math.min(o,(t+1)*a))))),c=i?await J(l):null;if(M={...M,hash:i?e:I(e,l),offset:r+o,chunks:[...M.chunks,...s]},x.push({phase:"source",offset:r,bytes:o}),M.offset===u.source.byteLength){if((c??A(M.hash))!==u.source.sha256)throw Vr("JXL_INPUT","The source bytes do not match their pinned digest.");M={phase:"encode",codec:n(u.plan,u.source),chunks:M.chunks}}}else if("encode"===M.phase){d??=C(async(e,t)=>{y++;let r=await h(e,t);return p+=r.length,r},u.source,r.signal,M.chunks),m||(await(r.prepare?.(u.plan,u.source,d)),m=!0);let e=N-performance.now(),t=Number.isFinite(e)?Math.max(1,e):r.budgetMs,n=await a(M.codec,{...f,readSource:d,bytesRead:()=>p+f.bytesRead(),callsRead:()=>y+f.callsRead(),signal:r.signal,...Number.isFinite(t)&&t>0&&{budgetMs:t},...r.reads&&{reads:r.reads},...void 0!==r.memoryBytes&&{memoryBytes:r.memoryBytes},...r.straight&&{straight:r.straight},...r.verify&&{verify:r.verify},...Vn in r&&{[Vn]:r[Vn]}});if(La(r.signal),(!n||!Object.hasOwn(n,"state"))&&ya("The codec returned no next state."),M={phase:"encode",codec:n.state,chunks:M.chunks},w=n.reads??[],x.push(n.work??{phase:"encode"}),void 0!==n.output){let e=n.output;null!==e&&!(e instanceof Uint8Array)&&ya("A codec output is its bytes.");let t=[];if(n.outputRefs)(!Array.isArray(n.outputRefs)||n.outputRefs.reduce((e,t)=>e+Ia(t).length,0)!==(e?.length??0))&&ya("Invalid codec output parts."),t.push(...n.outputRefs);else if(e)for(let r=0;r<e.length;r+=ca)t.push(await f.write(e.subarray(r,Math.min(e.length,r+ca))));b=t,g={refs:t.length&&t.length<=16?t:null,index:t.length>16?await f.writeJSON(t):null,byteLength:e?.length??0,result:void 0===n.result?null:B(n.result)},M=null}if(n.yield)break}else ya("Invalid codec phase.");La(r.signal);let O=void 0!==g,P=O?null:await f.writeJSON(M),{hash:E,...U}=u,S=await _({...U,previous:E,state:P,reads:O?[]:pa(w),revision:u.revision+1,status:O?"done":"active",output:O?g:null});La(r.signal);let j=v(S,"encode"===M?.phase?M.codec:null,b),k=[...L].filter(([e])=>!j.has(e)).map(([,e])=>({hash:e.hash,length:e.length}));return{checkpoint:S,parts:f.parts(),released:k,work:x,units:x.length,transition:c,done:O,output:O?g:null}},completion:async function(e,r){let n=await t(e,r);return{result:n.output.result,byteLength:n.output.byteLength}},output:async function(e,r,n){let a=await t(e,r);if(!a.output.byteLength)return n(0);let i=X(r.read,r.signal,!1,r.readMany),o=a.output.refs??await i.readJSON(a.output.index);(!Array.isArray(o)||!o.length)&&ya("Invalid output index.");let l=0;for(let e of o)Ia(e),l+=e.length;l!==a.output.byteLength&&ya("The output index does not cover the finished file.");let s=null,u=0;for(let e=0;e<o.length;){let t=e+1,a=o[e].length;for(;t<o.length&&t-e<128&&a+o[t].length<=sa;)a+=o[t++].length;let c=o.slice(e,t),f=await i.fetch(c);e=t,s??=n(l);for(let e=0;e<c.length;e++){let t=c[e];s.set(f[e],u),f[e]=null,await J(s.subarray(u,u+t.length))!==t.hash&&ya("Corrupted immutable part."),La(r.signal),u+=t.length}}return s}})}function W(e,t,r){let n=globalThis[Xa];globalThis[Xa]=r;try{return e.next(t)}finally{globalThis[Xa]=n}}function*V(e,t,r,n=!1,a=!1){return globalThis[Xa]?yield*globalThis[Xa].step(e,t,r,0,n,a):t()}function*K(e,t,r,n=!1,a=!1){return globalThis[Xa]?yield*globalThis[Xa].step(e,t,r,1,n,a):t()}function*z(e,t,r,n=!1,a=!1){return globalThis[Xa]?yield*globalThis[Xa].step(e,t,r,2,n,a):yield*t()}function H(e){return e.step=Y,e}function*Y(e,t,r,n,a,i){let o={unit:e};1===n&&(o.carry=!0),2===n?(a&&(o.whole=!0),r?.tool&&(o.answer=r.tool)):a&&(o.tail=!0),i&&(o.cold=!0);let l,s=yield o;if(s&&Object.hasOwn(s,Na))return s[Na];try{l=2===n?yield*t():t()}catch(t){throw yield{unitFailed:e},t}return yield{unitDone:e,value:l,save:r},l}async function q(e,t,r){if(!e)return r();let n,a=await e({unit:t});if(a&&Object.hasOwn(a,Na))return a[Na];try{n=await r()}catch(r){throw await e({unitFailed:t}),r}return await e({unitDone:t,value:n}),n}function $(e){let t=null,r=e.map(e=>{try{return e()}catch(e){if(!0!==e?.[Oa])throw e;t??=e}});if(t)throw t;return r}function Q(e,t,r,n,a,i=null){let o=()=>{throw a(t[0]),new Ya("An unread journal value was used.")},l=a=>{let l=i?.(t[0],t[1]);if(!l)return o();let s=l instanceof ArrayBuffer?l:l.buffer,u=l.byteOffset??0;if(r+n*e.BYTES_PER_ELEMENT>l.byteLength)throw Wa("Invalid unit value.");let c=new e(s,u+r,n),f=Reflect.get(c,a);return"function"==typeof f?f.bind(c):f},s=Ha(Ca.indexOf(e.name),t,r,n),u=new Proxy(new e(0),{get:(t,r)=>r===Oa||(r===Va?s:r===Ka?(e,t)=>ie(u,e,t):"length"===r?n:"byteLength"===r?n*e.BYTES_PER_ELEMENT:"then"===r?void 0:i?l(r):o()),set:o,has:o,ownKeys:o,getOwnPropertyDescriptor:o,defineProperty:o,deleteProperty:o,getPrototypeOf:()=>e.prototype});return u}function Z(e,t,r=[],n=0,a=null){let i={length:e,byteLength:e,byteOffset:0,BYTES_PER_ELEMENT:1,constructor:Uint8Array},o=Ha(Ca.indexOf("Uint8Array"),["source",0],n,e),l=()=>{throw t(n||a?`source:${n}:${n+e}`:"source"),new Ya("An unread source was used.")},s=(t,r)=>{if(void 0===t)return r;let n=Math.trunc(Number(t))||0;return n<0?Math.max(0,e+n):Math.min(e,n)},u=(i,o)=>{let l=s(i,0),u=Math.max(l,s(o,e));if(a){let e=a(n+l,n+u);if(e)return e;if(l===u)return new Uint8Array(0);throw t(`source:${n+l}:${n+u}`),new Ya("An unread source range was used.")}let c=r.find(e=>e.at<=n+l&&n+u<=e.at+e.bytes.length);if(c)return c.used=[Math.min(c.used?.[0]??n+l,n+l),Math.max(c.used?.[1]??n+u,n+u)],c.bytes.subarray(n+l-c.at,n+u-c.at);if(l===u)return new Uint8Array(0);throw t(`source:${n+l}:${n+u}`),new Ya("An unread source range was used.")},c=a||n?Ja(e,u):null,f=new Proxy(new Uint8Array(0),{get:(e,t)=>t===Oa||(t===Va?o:t===Ka?(e,t)=>ie(f,e,t):"subarray"===t?u:Object.hasOwn(i,t)?i[t]:t===Symbol.toStringTag?"Uint8Array":Sa(t)||"then"===t?void 0:c&&"string"==typeof t&&/^(0|[1-9]\d*)$/.test(t)?c(Number(t)):l()),set:l,has:l,ownKeys:l,getOwnPropertyDescriptor:l,defineProperty:l,deleteProperty:l,getPrototypeOf:()=>Uint8Array.prototype});return f}function ee(e,t){let r="a"===e?[]:"m"===e?new Map:"s"===e?new Set:{},n=Object.getPrototypeOf(r),a=()=>{throw t(),new Ya("An unread journal value was used.")};return new Proxy(r,{get:(e,t)=>t===Oa||(t===Va||t===Ka||"then"===t?void 0:a()),set:a,has:a,ownKeys:a,getOwnPropertyDescriptor:a,defineProperty:a,deleteProperty:a,getPrototypeOf:()=>n})}function te(e,t,r,n,a,i=1){let o=t*r,l=new Set,s=null,u=(t,r,n,a)=>e.filter(([,e,i,o,l])=>e<t+n&&t<e+o&&i<r+a&&r<i+l),c=(e,t,a,i,o)=>{let s=u(e,t,a,i),c=s.map(([e])=>e);for(let e of c)l.add(e),n(e);let f=1===r?$(s.map(([t,r,,n])=>()=>t.subarray(Math.max(0,e-r),Math.min(n,e+a-r)))):null;if(f||$a(c),f&&1===s.length&&!o)return f[0];let h=new Uint8Array(a*i);if(f){for(let t=0;t<f.length;t++)h.set(f[t],Math.max(e,s[t][1])-e);return h}for(let[r,n,o,l,u]of s){let s=Math.max(e,n),c=Math.min(e+a,n+l);for(let f=Math.max(t,o);f<Math.min(t+i,o+u);f++)h.set(r.subarray((f-o)*l+s-n,(f-o)*l+c-n),(f-t)*a+s-e)}return h},f=(e,t)=>void 0===e?t:Math.min(o,Math.max(0,(e=>e<0?o+e:e)(Math.trunc(Number(e))||0))),h=(e,n)=>{let a=f(e,0),i=Math.max(a,f(n,o));if(1===r)return[a,0,i-a,1,a,i];let l=Math.floor(a/t),s=Math.ceil(i/t);return[0,l,t,s-l,a-l*t,i-l*t]},d=(e,n)=>{let[a,i,o,l,u,f]=h(e,n);if(s)return s.subarray(i*t+u,i*t+f);if(!l||u===f)return new Uint8Array(0);let d=c(a,i,o,l);return 1===r?d:d.subarray(u,f)};return ja({length:o,byteLength:o,byteOffset:0,BYTES_PER_ELEMENT:1,constructor:Uint8Array,subarray:d,rect:(e,r,n,a)=>{if(e*=i,!(n*=i)||!a)return new Uint8Array(0);if(!s)return c(e,r,n,a);let o=new Uint8Array(n*a);for(let i=0;i<a;i++)o.set(s.subarray((r+i)*t+e,(r+i)*t+e+n),i*n);return o},ahead:(e,a,o=0,s=t/i)=>{let[c,f,d,m]=h(e,a),p=new Set(m&&d?u(1===r?c:o*i,f,1===r?d:s*i,m).map(([e])=>e):[]);for(let e of l)p.has(e)||n(e,!1);l.clear();for(let e of p)n(e)},then:void 0,[Oa]:!1,...a},()=>s??=c(0,0,t,r,!0),Ja(o,d))}function re(e,t,r,n,a,i=()=>{},o=void 0){return te(e.flatMap((e,i)=>e.map((e,o)=>[e,o*a*4,i*n,4*Math.min(a,t-o*a),Math.min(n,r-i*n)])),4*t,r,i,{[Ta]:e.flat(),[Ua]:o,[Za]:!0},4)}function ne(e,t=()=>{},r=void 0){let n=e.map(e=>za(e)?.length??e.length),a=[],i=0;e.forEach((e,t)=>{a.push([e,i,0,n[t],1]),i+=n[t]});let o=te(a,i,1,t,{sizes:n,[Ta]:e,[Ua]:r,[Ka]:(e,t)=>ie(o,e,t)});return o}function ae(e,t,r){let n=e[Ka];return n?n(t,r):e.subarray(t,r)}function ie(e,t=0,r=void 0){let n=za(e),a=n?.length??e.length,i=e=>Math.max(0,Math.min(a,e<0?a+Math.trunc(e):Math.trunc(e)));if(t=i(t),r=Math.max(t,void 0===r?a:i(r)),t===r)return new Uint8Array(0);let o=Fa(e,Ta);if(o&&!Fa(e,Za)){let n=[],a=0;for(let i=0;i<o.length&&a<r;i++){let l=a+e.sizes[i];l>t&&n.push(ae(o[i],Math.max(0,t-a),Math.min(l,r)-a)),a=l}return ne(n)}if(!n)return e.subarray(t,r);let l=r-t,s=(r=0,n=l)=>e.subarray(t+Math.max(0,r<0?l+r:Math.min(l,r)),t+Math.max(0,n<0?l+n:Math.min(l,n))),u=ja({length:l,byteLength:l,byteOffset:0,BYTES_PER_ELEMENT:1,constructor:Uint8Array,subarray:s,[Oa]:!1,[Va]:Object.freeze({...n,offset:n.offset+t,length:l}),[Ka]:(e,t)=>ie(u,e,t)},()=>e.subarray(t,r),Ja(l,s));return u}function oe(e,t=null){let r=new Map,n=[],a=[],i=e=>{let t=r.get(e);return void 0===t&&(t=r.size,r.set(e,t),n.push({buffer:e,from:1/0,to:0})),t},o=new Map,l=new Set,s=e=>{if(null===e)return null;switch(typeof e){case"undefined":return{u:1};case"boolean":case"string":return e;case"number":return Number.isFinite(e)&&!Object.is(e,-0)?e:{n:Object.is(e,-0)?"-0":String(e)};case"object":break;default:throw Wa(`A unit value cannot hold a ${typeof e}.`)}let r=za(e),u=!r&&Fa(e,Ta);if(r)return l.add(r.ref[0]),{t:r.type,r:r.ref,o:r.offset,l:r.length};if(!r&&Fa(e,Za))throw Wa("A unit value holds a picture's pixels.");if(u)return{j:u.map(s)};if(ArrayBuffer.isView(e)&&Object.getPrototypeOf(Object.getPrototypeOf(e))===Da){let r=Ca.indexOf(e.constructor.name);if(r<0)throw Wa("Unknown typed array in a unit value.");let o=t?.get(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);if(o)return l.add(o[0]),{t:r,r:[o[0],o[1]],o:e.byteOffset-o[2],l:e.length};let s=i(e.buffer),u=n[s],c={t:r,b:s,o:e.byteOffset,l:e.length};return u.from=Math.min(u.from,e.byteOffset),u.to=Math.max(u.to,e.byteOffset+e.byteLength),a.push(c),c}if(o.has(e))return{p:o.get(e)};let c=Object.getPrototypeOf(e);if(!(Array.isArray(e)||e instanceof Map||e instanceof Set||c===Object.prototype||null===c))throw Wa(`A unit value holds a ${e.constructor?.name??"class"} instance.`);return o.set(e,o.size),Array.isArray(e)?{a:e.map(s)}:e instanceof Map?{m:[...e].map(([e,t])=>[s(e),s(t)])}:e instanceof Set?{s:[...e].map(s)}:{o:Object.keys(e).map(t=>[t,s(e[t])])}},u=s(e),c=0;for(let e of n)e.from=e.to?-8&e.from:0,e.at=c,c+=e.to-e.from;for(let e of a)e.o-=n[e.b].from;let f={v:u,buffers:n.map(e=>[e.at,e.to-e.from])},h=new Uint8Array(c);for(let{at:e,buffer:t,from:r,to:a}of n)h.set(new Uint8Array(t,r,a-r),e);return{meta:f,bytes:h,buffers:n.map(e=>e.buffer),spans:n.map(e=>[e.from,e.to]),refers:l}}function le(e,t,r=null,n=null,a=null,i=null,o=void 0,l=null,s=null){if(!e||!Array.isArray(e.buffers))throw Wa("Invalid unit value.");for(let r of e.buffers)if(!Array.isArray(r)||2!==r.length||!Number.isSafeInteger(r[0])||!Number.isSafeInteger(r[1])||r[0]<0||r[1]<0||t&&r[0]+r[1]>t.length)throw Wa("Invalid unit value.");let u=s?null:l??(t?e.buffers.map(([e,r])=>t.slice(e,e+r).buffer):null),c=[],f=t=>{if(null===t||"object"!=typeof t)return t;if(!t.u){if(void 0!==t.n)return"-0"===t.n?-0:Number(t.n);if(void 0!==t.t){let o=globalThis[Ca[t.t]];if(!o||!Number.isSafeInteger(t.o)||!Number.isSafeInteger(t.l)||t.o<0||t.l<0||t.o%o.BYTES_PER_ELEMENT||(t.r?!Array.isArray(t.r)||2!==t.r.length||"string"!=typeof t.r[0]||!Number.isSafeInteger(t.r[1])||t.r[1]<0:!Number.isSafeInteger(t.b)||t.b<0||t.b>=e.buffers.length))throw Wa("Invalid unit value.");if(s&&"source"!==t.r?.[0])return Q(o,t.r??[n,t.b],t.o,t.l,a,s);let l=t.r?r?.(t.r[0],t.r[1]):u?u[t.b]:null;if(null===l&&"source"===t.r?.[0]&&i){let e=t.o+t.l*o.BYTES_PER_ELEMENT,r=i(t.o,e);return r?r.byteOffset%o.BYTES_PER_ELEMENT?new o(r.slice().buffer):new o(r.buffer,r.byteOffset,t.l):o===Uint8Array?Z(t.l,a,[],t.o,i):Q(o,t.r,t.o,t.l,()=>a?.(`source:${t.o}:${e}`))}if(null===l)return Q(o,t.r??[n,t.b],t.o,t.l,a);if(!l||t.o+t.l*o.BYTES_PER_ELEMENT>l.byteLength)throw Wa("Invalid unit value.");return new o(l,t.o,t.l)}if(t.j){if(!Array.isArray(t.j))throw Wa("Invalid unit value.");let e=t.j.map(f);if(!e.every(e=>e instanceof Uint8Array))throw Wa("Invalid unit value.");return ne(e,o)}if(void 0!==t.p){if(!Number.isSafeInteger(t.p)||t.p<0||t.p>=c.length)throw Wa("Invalid unit value.");return c[t.p]}if(t.a){let e=[];c.push(e);for(let r of t.a)e.push(f(r));return e}if(t.m){let e=new Map;c.push(e);for(let[r,n]of t.m)e.set(f(r),f(n));return e}if(t.s){let e=new Set;c.push(e);for(let r of t.s)e.add(f(r));return e}if(t.o){let e={};c.push(e);for(let[r,n]of t.o)"__proto__"===r?Object.defineProperty(e,r,{value:f(n),enumerable:!0,writable:!0,configurable:!0}):e[r]=f(n);return e}throw Wa("Invalid unit value.")}};return{value:f(e.v),buffers:u}}function se(e){let t=new Int32Array(e,0,e.byteLength>>2),r=new Uint8Array(e,4*t.length),n=2654435769^e.byteLength,a=2246822507;for(let e=0;e<t.length;e++)n=Math.imul(n^t[e],16777619),a=a+n|0;for(let e=0;e<r.length;e++)n=Math.imul(n^r[e],16777619);return(n^Math.imul(a,668265263))>>>0}async function ue(e,t){let r,n,a=!1;try{for(;!(n=W(e,r,t)).done;){let e=n.value;r=ni(e)?await t(e):void 0,!ni(e)&&void 0===e?.gpu&&"number"!=typeof e&&ti("A resumable step made a request it cannot answer here.")}return a=!0,n.value}finally{if(!a)try{e.return?.()}catch{}}}async function ce(e,t){let r,n=!1,a=Ba(t);try{for(;!(r=W(e,void 0,a)).done;){if(t.aborted)throw t.reason;let e=r.value;void 0===e?.gpu&&"number"!=typeof e&&void 0!==e&&ti("A resumable step made a request it cannot answer here.")}return n=!0,r.value}finally{if(!n)try{e.return?.()}catch{}}}async function fe(e,t,r){let n=[];for(let a=0;a<e.length;a+=ca){let i,o=Math.min(e.length,a+ca),l=await t({unit:"file-part"});if(l)n.push(l[Na]);else{try{i=await r.write(e.subarray(a,o))}catch(e){throw await t({unitFailed:"file-part"}),e}e.ahead(o,o+ca),await t({unitDone:"file-part",value:i}),n.push(i)}}return n}function he(e,t){if(void 0===e.metaLength)return{meta:e.meta,bytes:t};let r=ui.get(t);if(r&&r.entry===e)return r.value;(!Number.isSafeInteger(e.metaLength)||e.metaLength<2||e.metaLength>t.length||!["a","o","m","s"].includes(e.kind))&&ti("Invalid journal value.");let n=t.subarray(0,e.metaLength),a=S(n instanceof hi?n.slice(0):n);si(a?.v)!==e.kind&&ti("Invalid journal value.");let i={meta:a,bytes:t.subarray(e.metaLength)};return ui.set(t,{entry:e,value:i}),i}async function de(e,t){let r=[],n=0,a=async()=>{if(!n)return;let t=new Uint8Array(n),a=0;for(let e of r)t.set(e.bytes,a),a+=e.bytes.length;let i=await e.write(t);a=0;for(let e of r)e.slices.push([i,a,e.bytes.length]),a+=e.bytes.length;r=[],n=0};for(let{entry:e,bytes:i,alone:o}of t){let t=[],l=i;(o||e.carry)&&await a();for(let e=0;e<l.length;){let i=Math.min(l.length-e,ca-n);r.push({bytes:l.subarray(e,e+i),slices:t}),n+=i,e+=i,n===ca&&await a()}(o||e.carry)&&await a(),e.bytes=t}await a()}async function me(e,t){let r=new Map,n=t.map(e=>{(!Number.isSafeInteger(e.length)||e.length<0)&&ti("A journal value has the wrong length.");let t={length:e.length,spans:[]},n=0;for(let[a,i,o]of ci(e)){Ia(a),i+o>a.length&&ti("A journal value lies outside its page.");let e=r.get(a.hash)??{ref:a,spans:[]};e.ref.length!==a.length&&ti("Part length does not match its digest."),e.spans.push({value:t,from:i,length:o,at:n}),r.set(a.hash,e),n+=o}return(n!==e.length||!e.length&&ci(e).length)&&ti("A journal value has the wrong length."),t});return await F(e,[...r.values()].map(e=>e.ref),async t=>{for(let n of t){let t=await e.borrow(n);for(let{value:e,from:a,length:i,at:o}of r.get(n.hash).spans)e.spans.push({at:o,bytes:t.subarray(a,a+i)})}}),n.map(({spans:e})=>(e.sort((e,t)=>e.at-t.at),e.length?1===e.length?e[0].bytes:new hi(e.map(e=>e.bytes)):new Uint8Array(0)))}function pe(e){let t=new Map,r=[];for(let r of Object.values(e.journal)){if(!r.meta)continue;let e=JSON.stringify(r.meta);if(e.length<32)continue;let n=t.get(e);n?n.push(r):t.set(e,[r])}for(let e of t.values()){if(e.length<2)continue;let t=r.length;r.push(e[0].meta);for(let r of e)delete r.meta,r.metaIndex=t}return r.length?{...e,metas:r}:e}function ye(e,t){void 0!==t&&!Array.isArray(t)&&ti("Invalid journal layouts.");for(let r of Object.values(e)){if(void 0===r?.metaIndex)continue;let e=r.metaIndex;(!Number.isSafeInteger(e)||e<0||!t||e>=t.length||void 0!==r.meta||void 0!==r.metaLength||r.passed||!t[e]||"object"!=typeof t[e]||!Array.isArray(t[e].buffers))&&ti("Invalid journal layout reference."),r.meta=t[e],delete r.metaIndex}}function ge({id:e,build:t,normalize:r,open:n,run:a,verify:i,eager:o=!1,tools:l={},straight:s}){s??=n&&((e,t,r,a)=>ce(n(e,t,r,!0),a));let u=e=>(Object.hasOwn(l,e)||ti("A step names a journal tool this build has not."),l[e]);return D({id:e,build:t,normalize:r,start:(e,t)=>({journal:{},plan:e,source:t,hot:[]}),refs:e=>Object.values(e?.journal??{}).flatMap(e=>e.passed||!Array.isArray(e.bytes)?[]:e.bytes.map(e=>e[0])),async step(e,t){let{journal:r,plan:c,source:f,hot:h=[],tried:d=!1,costs:m={}}=e,p=t,y=t.reads??1/0,g=p.callsRead(),M=()=>p.callsRead()-g,b=!1;(!r||"object"!=typeof r||Array.isArray(r)||!c||!f||!Array.isArray(h)||!h.every(e=>"string"==typeof e)||"boolean"!=typeof d||!m||"object"!=typeof m||Array.isArray(m)||!Object.values(m).every(e=>Number.isFinite(e)&&e>=0))&&ti("Invalid journal state."),ye(r,e.metas);let w=ai(),v=p.budgetMs??c.budgetMs??20,L=t.memoryBytes??1/0,I=0,A=0,x=null,N=(e=0)=>{let t=new Set,r=e,n=e=>{let n=e?.buffer;n&&!t.has(n)&&(t.add(n),r+=n.byteLength)},a=e=>{e instanceof hi?e.spans.forEach(n):n(e)};if(Pe)n(Pe);else for(let e of Ee)n(e.bytes);for(let e of P.values())a(e);for(let{buffers:e}of S.values())for(let n of e)n&&!t.has(n)&&(t.add(n),r+=n.byteLength);for(let{bytes:e}of k)e&&a(e);if(A=r-e,r>I&&(I=r),r>L)throw x=Vr("JXL_MEMORY",`A resumable call held ${r} bytes, over the host's memoryBytes (${L}).`)},O=!d&&!Object.keys(r).length&&"function"==typeof p.straight&&await p.straight(await p.readSource(0,Math.min(f.byteLength,65536)),v),P=new Map,E=e=>+e.toFixed(1),T=new Set,S=new Map,j=(e,t)=>{!t?.length||S.has(e)||(S.set(e,{buffers:t,sums:t.map(se)}),A+=t.reduce((e,t)=>e+(t?.byteLength??0),0),A>L&&N())},J=e=>{let t=S.get(e);return t&&t.buffers.every((e,r)=>se(e)===t.sums[r])?t.buffers:(S.delete(e),null)},k=[],X=new Set,_=new Set,R=new Map,B=new Map,G=e=>{let t=B.get(e);t&&(W-=t.bytes.length,e.carry&&(V-=t.bytes.length),t.bytes=null,B.delete(e))},C=new Set,D=new WeakMap,W=0,V=0,K=!1,z=0,Y=[],q=["",0],$=null,Q=0,te=0,re=null,ae=!1,ie=!1,ce=!1,ge=new Map(Object.entries(m)),Me=0,be=0,we=0,ve=0,Le=0,Ie=0,Ae=0,xe=0,Ne=null,Oe=null,Pe=null,Ee=[],Te=async e=>{let t=ai();for(let[t,r]of e){if(Ee.some(e=>e.at<=t&&r<=e.at+e.bytes.length))continue;let e=Ee.filter(e=>e.at<=r&&t<=e.at+e.bytes.length),n=Math.min(t,...e.map(e=>e.at)),a=Math.max(r,...e.map(e=>e.at+e.bytes.length)),i=new Uint8Array(a-n),o=n,l=async(e,t)=>{for(let r=e;r<t;r+=oi){let e=await p.readSource(r,Math.min(oi,t-r));i.set(e,r-n),Ie+=e.length}};for(let t of e.sort((e,t)=>e.at-t.at))t.at>o&&await l(o,t.at),i.set(t.bytes,t.at-n),o=Math.max(o,t.at+t.bytes.length);o<a&&await l(o,a);for(let t of e)Ee.splice(Ee.indexOf(t),1);Ee.push({at:n,bytes:i})}ve+=ai()-t},Ue=async e=>{if(e.includes("source")&&!Pe){ce||(ae=!0,null===$&&(ie=!0)),N(f.byteLength);let e=ai();Pe=await p.readSource(0,f.byteLength),ve+=ai()-e,Ie+=Pe.length,ce||(z=Pe.length),Ee.length=0}let t=Pe?[]:e.filter(e=>e.startsWith("source:")).map(e=>e.split(":").slice(1).map(Number));t.length&&await Te(t);let n=e.filter(e=>!e.startsWith("source")&&r[e]&&!r[e].passed&&!P.has(e));if(!n.length)return;let a=ai(),i=n.map(e=>r[e]);i.forEach(fi),N(i.reduce((e,t)=>e+t.length,0));let o=await me(p,i);for(let[e,t]of n.entries())P.set(t,o[e]),Le+=i[e].length;N(),we+=ai()-a},Se="function"==typeof o?o(f):o,je=h.find(e=>e.startsWith("source@"))?.slice(7),Je="*"===je,Fe=h.filter(e=>"!"===e[0]).map(e=>e.slice(1)),ke=new Set(h.filter(e=>"~"===e[0]).map(e=>e.slice(1))),Xe=[...Se&&f.byteLength<=li||void 0!==je?["source"]:[],...h.filter(e=>r[e]||e.startsWith("source:")),...Fe.filter(e=>r[e])];if(ce=!0,O&&await Ue(["source"]),O&&s&&!c.verify){let t,r=new AbortController,n=r.signal,a=w+v,i=!1;Object.defineProperty(n,"aborted",{get:()=>(!i&&(ai()>=a||p.signal?.aborted)&&(i=!0,r.abort(p.signal?.aborted?p.signal.reason:ri)),i)});try{t=await s(c,Pe,f,n,async e=>(await F(p,[e]),p.borrow(e)),p)}catch(t){if(!i||p.signal?.aborted)throw t;return{state:{...e,tried:!0},work:{phase:"straight",stepMs:+(ai()-w).toFixed(1)},reads:[],yield:!0}}let o=t instanceof Uint8Array?t:t?.bytes,l=t instanceof Uint8Array?null:t?.facts??null;return o instanceof Uint8Array||ti("The steps returned no file."),{state:{journal:{},plan:c,source:f,hot:[]},work:{phase:"straight",stepMs:+(ai()-w).toFixed(1)},output:o.length?o:null,result:{length:o.length,facts:l}}}Xe.length&&await Ue(Xe),ce=!1,N();let _e,Re,Be=Math.max(Le+Ie,p.bytesRead()),Ge=new WeakMap,Ce=(e,t)=>_e(e,t),De=e=>Re(e);for(;;){Ae++,$=null,Q=ai();let e=new Set,o=t=>e.add(t),s=Pe??Z(f.byteLength,o,Ee),h=new Map,d=new Map,m=new Map,g={get:(e,t,r)=>{let n=d.get(e);return n&&n[2]<=t&&r<=n[3]&&("source"===n[0]?r-t>=65536:m.get(e)===se(e))?n:void 0}},I=(e,t)=>{let r=Ee.find(r=>r.at<=e&&t<=r.at+r.bytes.length);return r?r.bytes.subarray(e-r.at,t-r.at):null},E=(e,t)=>{if("source"===e)return 0!==t?void 0:Pe?Pe.buffer:null;if(!h.has(e)){r[e]||ti("A journal value refers to a missing value.");let t=P.get(e);if(!t)return null;let{meta:n,bytes:a}=he(r[e],t),i=a?J(e):null;a&&!i&&A+a.length>L&&N(a.length);let l=le(n,a,E,e,o,I,void 0,i);a&&j(e,l.buffers),ie(e,l.buffers)}return h.get(e)?.[t]??null},ae=(e,t)=>{r[e]||ti("A journal value refers to a missing value.");let n=P.get(e);if(!n)return null;let{meta:a,bytes:i}=he(r[e],n),o=a?.buffers?.[t];return(!Array.isArray(o)||2!==o.length||!o.every(e=>Number.isSafeInteger(e)&&e>=0)||o[0]+o[1]>i.length)&&ti("Invalid journal buffer span."),i instanceof Uint8Array&&(i.byteOffset+o[0])%8==0?i.subarray(o[0],o[0]+o[1]):E(e,t)};_e=ae,Re=o;let ie=(e,t,r=null)=>{h.set(e,t);let n=S.get(e)?.buffers===t?S.get(e).sums:null;t?.forEach((t,a)=>{d.set(t,[e,a,r?r[a][0]:0,r?r[a][1]:t.byteLength]),m.set(t,n?n[a]:se(t))})};Pe&&d.set(Pe.buffer,["source",0,0,Pe.byteLength]);let ce,de=[{path:"",children:0}],me=!1,pe=async t=>{if(x)throw x;if(e.size||me)throw ri;if(O){if(ai()-w>=v)throw me=!0,ri;return void 0!==t.unit?void de.push({name:t.unit}):void(de.pop()?.name!==(t.unitDone??t.unitFailed)&&ti("Unbalanced unit steps."))}if(void 0!==t.unit){if(K&&!t.tail&&!de.some(e=>e.whole))throw me=!0,ri;let e=de.at(-1),n=(e.path?e.path+".":"")+e.children++,a=r[n];if(a){if((a.name!==t.unit||!!a.carry!=!!t.carry)&&ti("The journal does not match this operation's steps."),a.passed)return xe++,{[Na]:Ga};let e=P.get(n)??null;if(void 0!==a.metaLength&&!e){if(void 0!==t.answer)throw o(n),ri;xe++;let e=ee(a.kind,()=>o(n));return D.set(e,n),{[Na]:e}}let{meta:r,bytes:i}=he(a,e),l=!!a.borrowed&&!t.answer,s=i&&!l?J(n):null;i&&!l&&!s&&A+i.length>L&&N(i.length);let c=ai(),f=l&&void 0!==r.v?.t&&!r.v.r,h=f&&Ge.get(a);h||(h=le(r,i,E,n,f?De:o,I,(e,t)=>pe.touched(e,t),s,l?f?Ce:ae:null),f&&Ge.set(a,h)),i&&!l&&j(n,h.buffers),e&&X.add(n),!a.carry&&!l&&ie(n,i?h.buffers:null),te+=ai()-c,xe++;let d=void 0!==t.answer?u(t.answer).answer(h.value):h.value;return null!==d&&"object"==typeof d&&D.set(d,n),{[Na]:d}}if(Me&&!t.tail&&!de.some(e=>e.whole)&&(W-V>=16777216||ai()-w-ve+(ge.get(t.unit)??q[1])>=v))throw me=!0,ri;return t.tail&&(K=!1),null===$&&($=ai()-Q),re=e.path,void de.push({path:n,children:0,name:t.unit,carry:!!t.carry,whole:!!t.whole,cold:!!t.cold,borrowed:!!t.borrowed,alone:!!t.alone,started:ai()})}let n=de.pop(),a=ai()-n.started;if(n?.name&&!n.whole&&ge.set(n.name,a),a>q[1]&&(q=[de.map(e=>e.name).filter(Boolean).concat(n.name).join("/"),+a.toFixed(1)]),(!n?.name||n.name!==(t.unitDone??t.unitFailed))&&ti("Unbalanced unit steps."),void 0!==t.unitFailed)return;let i=n.path+".",l="function"==typeof t.save?t.save(t.value):t.save?u(t.save.tool).save(t.value,t.save.extra?.(t.value)):t.value,s=ai(),c=oe(l,{get:(e,t,r)=>{let n=g.get(e,t,r);return!n||"string"==typeof n[0]&&n[0].startsWith(i)?void 0:n}});if(n.children){let e=new Set(c.refers);for(let t of e)for(let n of r[t]?.refers??[])e.add(n);for(let t of Object.keys(r))t.startsWith(i)&&!e.has(t)&&(G(r[t]),delete r[t],h.delete(t),P.delete(t),S.delete(t));for(let[e,t]of d)"string"==typeof t[0]&&t[0].startsWith(i)&&(d.delete(e),m.delete(e))}let{meta:f,bytes:y,buffers:M,spans:b}=c;if(n.carry){let e=n.path.slice(0,n.path.lastIndexOf(".")+1),t=+n.path.slice(e.length);for(let a=0;a<t;a++){let t=e+a,i=r[t];i?.carry&&!i.passed&&i.name===n.name&&(G(i),r[t]={name:i.name,carry:!0,passed:!0},h.delete(t),P.delete(t),S.delete(t))}}let T=si(f.v),F=void 0!==T?JSON.stringify(f):null,_=null!==F&&F.length>1024,R=_?U(f,F):null,C=_?ne([R,y]):y,H=[...c.refers].filter(e=>"source"!==e),Y=r[n.path]={name:n.name,...n.carry&&{carry:!0},...n.cold&&{cold:!0},...n.borrowed&&{borrowed:!0},..._?{kind:T,metaLength:R.length}:{meta:f},...H.length&&{refers:H},length:C.length,bytes:[]};_&&ui.set(C,{entry:Y,value:{meta:f,bytes:y}});let Z={entry:Y,bytes:C,alone:n.alone};k.push(Z),B.set(Y,Z),W+=C.length,n.carry&&(V+=C.length),P.set(n.path,C),n.carry?h.set(n.path,M):ie(n.path,M,b),be+=ai()-s,Me++,de.some(e=>e.whole)||(K=Math.max(Le+Ie,p.bytesRead())-Be-z>=sa),N()},ye=null,we=!1;pe.tools=l,pe.host=p,H(pe),pe.part=async e=>{if(M()>=y)throw me=!0,ri;return await F(p,[e]),p.borrow(e)},pe.join=e=>ne(e,pe.touched),pe.done=e=>{let t=D.get(e)??ei(e)??d.get(e?.buffer)?.[0];void 0===t||!r[t]||(T.add(t),C.delete(t),P.delete(t),S.delete(t))},pe.touched=(e,t=!0)=>{let n=D.get(e)??ei(e)??d.get(e?.buffer)?.[0];if(void 0!==n){if(t)return C.add(n),void T.delete(n);if(C.delete(n),r[n]?.borrowed&&!B.has(r[n])){T.add(n),_.delete(n),P.delete(n),S.delete(n),h.delete(n);for(let[e,t]of d)t[0]===n&&(d.delete(e),m.delete(e))}}};try{ce=await(a?a(c,s,f,pe):ue(n(c,s,f),pe)),c.verify&&("function"!=typeof i&&ti("This operation has no resumable verification."),ce=await i(ce,c,s,f,pe,t));let e=ce instanceof Uint8Array?ce:ce?.bytes;Fa(e,Ta)&&(ye=await fe(e,pe,p))}catch(t){if(!e.size&&!me)throw t}e.size&&(we=!0);let Te=!we&&me;if(we){let t=0;for(let n of[...e]){if(!r[n]||(_.add(n),r[n].borrowed))continue;let a=r[n].name;if((R.get(a)??0)<1){R.set(a,1);continue}let i=n.slice(0,n.lastIndexOf(".")+1),o=r[n].name;for(let[n,a]of Object.entries(r))if(!(e.has(n)||P.has(n)||T.has(n)||a.passed||a.name!==o||!n.startsWith(i)||n.slice(i.length).includes("."))){if((t+=a.length)>4194304)break;e.add(n)}}for(let t of e)t.startsWith("source:")&&Y.push(t);if(M()>=y){b=!0,Ne=null;break}let n=Y.length>1?Math.min(1048576,32768*2**Math.min(Y.length,16)):0;await Ue([...e].map(e=>{if(!n||!e.startsWith("source:"))return e;let[t,r]=e.split(":").slice(1).map(Number);return`source:${t}:${Math.min(f.byteLength,Math.max(r,t+n))}`})),N();continue}Ne=Te?null:ce,Oe=ye;break}if(O&&null===Ne)return{state:{...e,tried:!0},work:{phase:"straight",stepMs:+(ai()-w).toFixed(1),attempts:Ae},reads:[],yield:!0};let We=ai(),Ve=new Map(Object.entries(r).map(([e,t])=>[t,e]));null===Ne&&await de(p,k.filter(({entry:e})=>Ve.has(e)));let Ke=ai()-We,ze={phase:"journal",stepMs:+(ai()-w).toFixed(1),decodeMs:+te.toFixed(1),longest:q,replayMs:+($??ai()-Q).toFixed(1),attempts:Ae,answered:xe,fresh:Me,entries:Object.keys(r).length,readBytes:Le,sourceBytes:Ie,sourceMs:E(ve),loadMs:E(we),saveMs:E(be),pageMs:E(Ke),savedBytes:k.reduce((e,{bytes:t})=>e+(t?.length??0),0),hold:{peak:I,limit:L}};if(globalThis[ii]?.(ze),null!==Ne){let e=Ne instanceof Uint8Array?Ne:Ne?.bytes,t=Ne instanceof Uint8Array?null:Ne?.facts??null;return e instanceof Uint8Array||ti("The steps returned no file."),{state:{journal:{},plan:c,source:f,hot:[]},work:ze,output:e.length?e:null,...Oe&&{outputRefs:Oe},result:{length:e.length,facts:t,...c.verify&&{verification:Ne.verification}}}}let He=new Set([..._,...C]);if(b)for(let e of P.keys())r[e]&&!r[e].passed&&He.add(e);for(let{entry:e}of k)Ve.has(e)&&!e.cold&&He.add(Ve.get(e));let Ye=null,qe=e=>{if(!Ye){Ye=new Map;for(let e of Object.keys(r)){let t=e.slice(0,e.lastIndexOf(".")+1)+"\0"+r[e].name,n=Ye.get(t);n?n.push(e):Ye.set(t,[e])}for(let[e,t]of Ye){let r=e.indexOf("\0");t.sort((e,t)=>+e.slice(r)-+t.slice(r))}}return Ye.get(e.slice(0,e.lastIndexOf(".")+1)+"\0"+r[e].name)};for(let e of h)X.has(e)&&r[e]&&!r[e].passed&&!r[e].cold&&qe(e).at(-1)===e&&He.add(e);let $e=new Map;for(let e of _)if(r[e]){let t=qe(e),r=t[0];$e.set(r,{list:t,at:Math.max($e.get(r)?.at??-1,t.indexOf(e)),count:($e.get(r)?.count??0)+1})}for(let{list:e,at:t,count:n}of $e.values())for(let a of e.slice(t+1,t+1+n))r[a].passed||He.add(a);let Qe=0,Ze=e=>ci(r[e]).reduce((e,[t])=>e+t.length,0);for(let e of He)r[e]&&!r[e].passed&&(Qe+=Ze(e));let et=Math.min(sa,Math.max(1048576,262144*($??ai()-Q)));for(let e of[...X].reverse())!He.has(e)&&r[e]&&!r[e].passed&&!r[e].cold&&(Qe+=Ze(e))<=et&&He.add(e);let tt=e=>r[e]&&!r[e].passed,rt=new Set([...Fe,...[..._].filter(e=>ke.has(e))].filter(e=>tt(e)&&!r[e].cold)),nt=[...new Set([...h.filter(e=>r[e]&&!He.has(e)),...ke])].filter(e=>tt(e)&&!rt.has(e)&&!_.has(e)&&!He.has(e)).slice(0,256),at=Je||ie?"*":f.byteLength>li?null:ae?re:Pe&&void 0!==je&&re===je?je:null,it=0,ot=null!==at||Pe?[]:[...Y.map(e=>{let[t,r]=e.split(":").slice(1).map(Number);return[t,Math.min(f.byteLength,r+(r-t))]}),...Ee.filter(e=>e.used).map(e=>e.used)].filter(([e,t])=>(it+=t-e)<=li).map(([e,t])=>`source:${e}:${t}`);for(let e of T)_.has(e)||(He.delete(e),rt.delete(e));let lt={journal:r,plan:c,source:f,...d&&{tried:d},costs:Object.fromEntries([...ge].map(([e,t])=>[e,Math.round(t)])),hot:[...null!==at?["source@"+at]:[],...ot,...[...He].filter(e=>tt(e)&&!rt.has(e)),...[...rt].map(e=>"!"+e),...nt.map(e=>"~"+e)]},st=[],ut=0;for(let e of new Map([...rt,...lt.hot.filter(e=>r[e])].flatMap(e=>ci(r[e]).map(([e])=>[e.hash,e]))).values()){if(64===st.length||ut+e.length>sa)break;st.push(e),ut+=e.length}return{state:pe(lt),work:ze,reads:st,yield:!0}}})}function Me(e){let[t,r,n,a,i,o,l,s,u]=e,c=i*u-o*s,f=o*l-a*u,h=a*s-i*l,d=t*c+r*f+n*h;return[c,n*s-r*u,r*o-n*i,f,t*u-n*l,n*a-t*o,h,r*l-t*s,t*i-r*a].map(e=>e/d)}function be(e,t){let r=new Array(9);for(let n=0;n<3;n++)for(let a=0;a<3;a++)r[3*n+a]=e[3*n]*t[a]+e[3*n+1]*t[3+a]+e[3*n+2]*t[6+a];return r}function we(e,t,r,n){let a=String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3));if("curv"===a){let a=e.getUint32(t+8);if(12+2*a>r)return null;if(0===a)return e=>e;if(1===a){let r=e.getUint16(t+12)/256;return e=>mi(e,r)}let i=n?n(t+12,a):Float64Array.from({length:a},(r,n)=>e.getUint16(t+12+2*n)/65535),o=n?i:e=>i[e];return e=>{let t=e*(a-1),r=Math.min(a-2,Math.floor(t)),n=o(r);return n+(o(r+1)-n)*(t-r)}}if("para"===a){let n=e.getUint16(t+8),a=[1,3,4,5,7][n];if(void 0===a||12+4*a>r)return null;let[i,o=1,l=0,s=0,u=0,c=0,f=0]=Array.from({length:a},(r,n)=>pi(e,t+12+4*n));return 0===n?e=>mi(e,i):1===n?e=>o*e+l>=0?mi(o*e+l,i):0:2===n?e=>o*e+l>=0?mi(o*e+l,i)+s:s:3===n?e=>e>=u?mi(o*e+l,i):s*e:e=>e>=u?mi(o*e+l,i)+c:s*e+f}return null}function ve(e){let t=yi(e),r=t(16);return"RGB "!==r&&"GRAY"!==r||"XYZ "!==t(20)?null:{space:r,count:e.getUint32(128)}}function Le(e,t,r,n=132){let a=yi(e);for(let i=0;i<t;i++,n+=12){let t=a(n),i=e.getUint32(n+4),o=e.getUint32(n+8);["rXYZ","gXYZ","bXYZ","rTRC","gTRC","bTRC","kTRC","A2B0","A2B1","A2B2"].includes(t)&&r.set(t,{offset:i,length:o})}return r}function Ie(e,t,r){return r<20||"XYZ "!==yi(e)(t)?null:[pi(e,t+8),pi(e,t+12),pi(e,t+16)]}function Ae(e){return Mi(()=>{if(!e||e.length<132)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=ve(t);if(!r)return null;let{space:n,count:a}=r,i=Le(t,a,new Map);if(i.has("A2B0")||i.has("A2B1")||i.has("A2B2"))return null;let o=e=>{let r=i.get(e);return r&&we(t,r.offset,r.length)},l=e=>Float64Array.from({length:256},(t,r)=>Math.max(0,Math.min(1,e(r/255))));if("GRAY"===n){let e=o("kTRC");return e&&{gray:!0,tables:[l(e)],curves:[e]}}let s=["rXYZ","gXYZ","bXYZ"].map(e=>{let r=i.get(e);return r?Ie(t,r.offset,r.length):null}),u=["rTRC","gTRC","bTRC"].map(o);return s.includes(null)||u.includes(null)?null:{gray:!1,tables:u.map(l),curves:u,xyz:gi(s)}})}function xe(e,t){let r=vi(wi,e),n=vi(wi,t);return be(Me(wi),be([n[0]/r[0],0,0,0,n[1]/r[1],0,0,0,n[2]/r[2]],wi))}function Ne(e,t){let r=[0,1,2].map(t=>Ii(e[t])),n=[r[0][0],r[1][0],r[2][0],r[0][1],r[1][1],r[2][1],r[0][2],r[1][2],r[2][2]],a=vi(Me(n),Ii(t));return n.map((e,t)=>e*a[t%3])}function Oe(e){let t=Ae(e);if(!t)return null;let r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=r.getUint32(64);if(n>3)return null;let a=t.gray?[t.curves[0]]:t.curves;if(!a.every(e=>{for(let t=0;t<=255;t++){let r=e(t/255);if(!(r>=0&&r<=1))return!1}return!0}))return null;for(let t=0,n=r.getUint32(128);t<n;t++){let r=132+12*t,n=String.fromCharCode(e[r],e[r+1],e[r+2]);if("B2A"===n||"B2D"===n||"D2B"===n)return null}let i,o,l=a[0](.5);if(!(l>=0&&l<=1))return null;let s=di(Math.max(1e-9,l))/di(.5);if(s>.05&&a.every(e=>Ei(e,e=>mi(e,s)))&&(Math.abs(s-1)<.001?i=8:8192*Math.round(1e7/s)>=1e7&&s>1&&(o=Math.round(1e7/s)/1e7)),void 0===i&&void 0===o){let e=Pi.find(([,e])=>a.every(t=>Ei(t,e)));if(!e)return null;i=e[0]}let u=new Map;for(let t=0,n=r.getUint32(128);t<n;t++){let n=132+12*t,a=String.fromCharCode(e[n],e[n+1],e[n+2],e[n+3]);u.set(a,{offset:r.getUint32(n+4),length:r.getUint32(n+8)})}let c=u.get("chad"),f=u.get("wtpt"),h=bi;c&&c.length>=44?h=vi(Me(Array.from({length:9},(e,t)=>pi(r,c.offset+8+4*t))),bi):f&&f.length>=20&&(h=[0,1,2].map(e=>pi(r,f.offset+8+4*e)));let d=Li(h);if(![...d].every(Number.isFinite))return null;let m=Ai.find(([,e])=>Ni(e,d)),p=m?{enum:m[0],xy:m[1]}:{enum:2,xy:Oi(d)},y={gray:t.gray,white:p,transfer:i,gamma:o,intent:n};if(t.gray)return y;let g=be(xe(bi,Ii(p.xy)),t.xyz),M=[0,1,2].map(e=>Li([g[e],g[3+e],g[6+e]]));if(!M.flat().every(Number.isFinite))return null;let b=xi.find(([,e])=>e.every((e,t)=>Ni(e,M[t])));return y.primaries=b?{enum:b[0],xy:b[1]}:{enum:2,xy:M.map(Oi)},be(xe(Ii(p.xy),bi),Ne(y.primaries.xy,p.xy)).every((e,r)=>Math.abs(e-t.xyz[r])<.002)?y:null}function Pe(e,t){let r=e?.data;if(!t||!e.icc||void 0!==e.colorEncoding||!(r instanceof Uint8Array||r instanceof Uint8ClampedArray)||8!==(e.bitDepth??8)||"uint"!==(e.sampleFormat??"uint")||"srgb"!==(e.colorSpace??"srgb"))return e;let n=Ji(e.icc);if(!n)return e;let{icc:a,colorSpace:i,...o}=e;return{...o,colorEncoding:n}}function Ee(e){try{let t=t=>(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0,r=255===e[0]&&10===e[1]?e:null;for(let n=0;!r&&n+8<=e.length;){let a=t(n),i=n+8,o=t(n+4);1===a?(a=4294967296*t(n+8)+t(n+12),i+=8):a||(a=e.length-n);let l=n+a;if(l<i||l>e.length)return null;1786276963===o?r=e.subarray(i,l):1786276976===o&&l-i>=4&&!(2147483647&t(i))&&(r=e.subarray(i+4,l)),n=l}if(!r)return null;let n=0,a=e=>{let t=0;for(let a=0;a<e;a++,n++){if(n>>3>=r.length)throw 0;t+=(r[n>>3]>>(7&n)&1)*2**a}return t},i=()=>a([9,13,18,30][a(2)])+1;if(2815!==a(16))return null;let o=a(1),l=o?8*(a(5)+1):i(),s=a(3);return{height:l,width:s?Math.floor(l*[0,1,12,4,3,16,5,2][s]/[1,1,10,3,2,9,4,1][s]):o?8*(a(5)+1):i()}}catch{return null}}async function Te(e,t,r,n){if(!Xi(r))throw fn("JXL_INPUT","Invalid finished record; pass the result record returned by the job.");let a,{width:i,height:o,format:l="jxl",fidelity:s,kept:u,measurements:c,transform:f,readAs:h,originalBytes:d,usedWebGPU:m}=r,p=f??{width:i,height:o};if(void 0!==d&&"file"===n.kind&&d!==n.byteLength)throw fn("JXL_INPUT","Finished record has no original size; restore the complete result record.");if(t&&"jxl"===l){let e=Ee(t);if(!e||!(e.width===p.width&&e.height===p.height||e.width===p.height&&e.height===p.width))throw fn("JXL_INPUT","Finished record describes another file; pass the record belonging to this file.")}try{a=await e(t,{width:i,height:o},{fidelity:s,measurements:c,format:l,...t&&void 0!==u&&{kept:u},...void 0!==f&&{transform:f},...void 0!==h&&{readAs:h},...void 0!==d&&{originalBytes:d},...void 0!==m&&{usedWebGPU:m},owned:!0})}catch{throw fn("JXL_INPUT","Invalid finished record; pass the result record returned by the job.")}for(let e of new Set([...Object.keys(r),...Object.keys(a)]))if("bytes"!==e&&"source"!==e&&_i(a[e])!==_i(r[e]))throw fn("JXL_INPUT","Finished record describes another file; pass the record belonging to this file.");let y="decode"===n.kind?r.source:void 0;if(void 0===y)return a;if(!Xi(y)||"bytes"!==y.kind||!/^sha256:[0-9a-f]{64}$/.test(y.digest)||2!==Object.keys(y).length)throw fn("JXL_INPUT","Finished record has no valid original; restore the complete result record.");return{...a,source:{kind:"bytes",digest:y.digest}}}function Ue(e,t=0){return!(null!==e&&!["string","number","boolean"].includes(typeof e))||!(t>8||"object"!=typeof e)&&(Array.isArray(e)?e.every(e=>Ue(e,t+1)):Object.getPrototypeOf(e)===Object.prototype&&Object.values(e).every(e=>Ue(e,t+1)))}async function Se(e,t){let{decode:r,restore:n}=(void 0!==t?t:Wn())??{};if(!r)throw fn("JXL_PLATFORM","This host has no configured decoder; call configureDecoder(decode) with decode from rapier-jxl/decode.");let a,i=await r(e);if("uint8"!==i.format||"string"!=typeof i.colorSpace)throw fn("JXL_UNSUPPORTED","The decoded picture is not 8-bit with a named color space; configure the decoder to return 8-bit pixels in sRGB or another named color space.");if(n&&i.header?.reconstruction){let t=(await n(e)).bytes;a="sha256:"+A(I(qn(),t))}return{data:new Uint8Array(i.data.buffer,i.data.byteOffset,i.data.length),width:i.width,height:i.height,...0===i.colorEncoding?.renderingIntent||i.colorEncoding?.renderingIntent>1?{colorEncoding:i.colorEncoding}:{colorSpace:i.colorSpace},...a&&{source:a}}}async function je(e){let t=await e;if(Array.isArray(t)){let e=t.map(({bytes:e,...t})=>({...t,length:e?e.length:null})),r=new Uint8Array(e.reduce((e,t)=>e+(t.length??0),0)),n=0;for(let e of t)e.bytes&&(r.set(e.bytes,n),n+=e.bytes.length);return{bytes:r,facts:{records:e}}}let{bytes:r,...n}=t;return{bytes:r??new Uint8Array(0),facts:{record:n,missed:!r}}}async function Je(e,t){let r=await e,{bytes:n}=r;if(!t||n.length<=Ci||Fa(n,Ta))return r;let a=[];for(let e=0;e<n.length;e=Math.min(n.length,e?e+Di:Ci)){let r=Math.min(n.length,e?e+Di:Ci),i=await t({unit:"output-piece",cold:!0});if(i&&Object.hasOwn(i,Na)){a.push(i[Na]);continue}let o=n.slice(e,r);await t({unitDone:"output-piece",value:o}),a.push(o)}return{...r,bytes:t.join(a)}}async function Fe(e,t){let r=await e,n=r.facts?.record;return"file"===(t.kind??"pixels")&&n&&void 0===n.originalBytes&&Number.isSafeInteger(t.byteLength)&&r.bytes.length?{...r,facts:{...r.facts,record:{...n,originalBytes:t.byteLength,largerThanOriginal:r.bytes.length>t.byteLength}}}:r}function ke(e){return e.components.forEach((t,r)=>{let{coeffs:n}=t,a=e.nonZero?.[r]??Xe(n),i=0;for(let e=0;e<a.length;e++)i+=a[e];let o=new Uint8Array(i),l=new Int16Array(i),s=t.stride,u=new Uint32Array(a.length/s);for(let e=0,t=0;e<a.length;e++){let r=64*e;e%s===0&&(u[e/s]=t);for(let i=1,s=a[e];s;i++){let e=n[r+i];e&&(o[t]=i,l[t++]=e,s--)}}t.packed={at:o,levels:l,counts:a,starts:u,segment:s,length:n.length},t.coeffs=null}),e}function Xe(e){let t=new Uint8Array(e.length/64);for(let r=0;r<t.length;r++){let n=0;for(let t=1;t<64;t++)n+=0!==e[64*r+t];t[r]=n}return t}function _e(e){let t=e[0];if(!t||Object.getPrototypeOf(t)!==Object.prototype)return null;let r=Object.keys(t).filter(e=>!Vi.has(e)),n=r.map(e=>"number"==typeof t[e]?"n":Hi(t[e])?"v":Yi(t[e])?"d"+t[e].length+":"+Wi.indexOf(t[e][0].constructor.name):null);if(n.includes(null))return null;let a=[],i=[],o=new Map,l=[];for(let t of e){if(Object.getPrototypeOf(t)!==Object.prototype)return null;let e=Object.keys(t).filter(e=>!Vi.has(e));if(e.length!==r.length||e.some((e,t)=>e!==r[t]))return null;for(let e=0;e<r.length;e++){let s=t[r[e]],u=n[e];if("n"===u){if("number"!=typeof s)return null;a.push(s)}else if("v"===u){if(!Hi(s))return null;let e=o.get(s);void 0===e&&(e=l.length,o.set(s,e),l.push(s)),i.push(e)}else{let[e,t]=u.slice(1).split(":").map(Number);if(!Yi(s)||s.length!==e||s.some(e=>Wi.indexOf(e.constructor.name)!==t))return null;for(let e of s)a.push(e[0])}}}return{count:e.length,keys:r,kinds:n,numbers:Float64Array.from(a),views:Int32Array.from(i),shared:l}}function Re({count:e,keys:t,kinds:r,numbers:n,views:a,shared:i},o=null){let l=r.map(e=>"d"===e[0]?e.slice(1).split(":").map(Number):null),s=new Array(e),u=0,c=0;for(let f=0;f<e;f++){let e={};for(let o=0;o<t.length;o++){let s=r[o];if("n"===s)e[t[o]]=n[u++];else if("v"===s)e[t[o]]=i[a[c++]];else{let[r,a]=l[o],i=globalThis[Wi[a]],s=new Array(r);for(let e=0;e<r;e++)s[e]=i.of(n[u++]);e[t[o]]=s}}s[f]=o?o(e,f):e}return s}function Be(e){let{coeffs:t}=e;if(e.packed)return e;if(!(t instanceof Int16Array))return null;let r=t.length/64,n=new Int16Array(r),a=new Uint32Array(64);for(let e=0,i=0;e<r;e++,i+=64){n[e]=t[i];for(let e=1;e<64;e++)t[i+e]&&a[e]++}let i={components:[{...e}]};return ke(i),{...i.components[0],packed:{...i.components[0].packed,dc:n,natural:a}}}function Ge(e){if(ArrayBuffer.isView(e))return null;try{return Qi.call(e)}catch{return null}}function Ce(e,t=!1){if("Uint8Array"!==to.call(e)||null===Ge(eo.buffer.call(e))||!t&&0===eo.byteLength.call(e))throw fn("JXL_INPUT","Invalid encoded input; pass a nonempty Uint8Array on an attached ArrayBuffer.");return eo.byteLength.call(e)}function De(e,t=!1){let r=Ce(e,t);try{return new Uint8Array(eo.buffer.call(e),eo.byteOffset.call(e),r)}catch{throw fn("JXL_INPUT","Input buffer is detached; pass bytes from an attached ArrayBuffer.")}}function We(e,t){if(t===Uint8Array)return e;let r=t.BYTES_PER_ELEMENT,n=e.length/r,a=(e,t)=>void 0===e?t:(e=Math.trunc(e)||0)<0?Math.max(0,n+e):Math.min(n,e),i=(i,o)=>{i=a(i,0),o=Math.max(i,a(o,n));let l=e.subarray(i*r,o*r);return l.byteOffset%r&&(l=l.slice()),new t(l.buffer,l.byteOffset,l.byteLength/r)},o={length:n,byteLength:e.length,byteOffset:0,BYTES_PER_ELEMENT:r,constructor:t,subarray:i,then:void 0,ahead:"function"==typeof e.ahead?(t,n)=>e.ahead(t*r,n*r):void 0};return new Proxy(new t(0),{get:(e,r)=>Object.hasOwn(o,r)?o[r]:r===Symbol.toStringTag?t.name:"symbol"==typeof r&&Symbol.keyFor(r)?.startsWith("rapier-jxl.journal")?void 0:(e=>{let t=Reflect.get(e,r);return"function"==typeof t?t.bind(e):t})(i()),getPrototypeOf:()=>t.prototype})}function Ve(e,t){let r=e.length,n=new Uint16Array(16);for(let t=0;t<r;t++)n[e[t]]++;n[0]=0;let a=15;for(;a&&!n[a];)a--;for(let e=1,r=1;e<=15;e++)r=(r<<1)-n[e],r<0&&no(),15===e&&r>0&&a&&(!t||1!==a)&&no();let i=new Uint16Array(17),o=new Uint16Array(r);for(let e=1;e<=15;e++)i[e+1]=i[e]+n[e];let l=i.slice();for(let t=0;t<r;t++)e[t]&&(o[l[e[t]]++]=t);let s=new Uint32Array(1024);for(let e=1,t=0;e<=10;e++,t<<=1)for(let r=0;r<n[e];r++,t++){let n=0;for(let r=0;r<e;r++)n|=(t>>r&1)<<e-1-r;let a=o[i[e]+r]<<4|e;for(let t=n;t<=1023;t+=1<<e)s[t]=a}return{table:s,counts:n,symbols:o}}function Ke(e,t,r,n){let{pos:a,bits:i,count:o,final:l,type:s,left:u,lengths:c,hlit:f,copy:h,distance:d,a:m,b:p,produced:y}=e,g=n.read(a,Math.min(n.length,a+e.span)),M=0,b=()=>{let t=a;return!(t>=n.length)&&(g=n.read(t,Math.min(n.length,t+Math.max(65536,e.span))),M=0,g.length>0)},w=e=>{for(;o<e;)M>=g.length&&!b()&&no(),i|=g[M++]<<o,a++,o+=8},v=e=>{w(e);let t=i&(1<<e)-1;return i>>>=e,o-=e,t},L=e=>{for(;o<15&&(!(M>=g.length)||b());)i|=g[M++]<<o,a++,o+=8;let t=e.table[1023&i],r=15&t;if(t&&r<=o)return i>>>=r,o-=r,t>>4;for(let t=1,r=0,n=0,a=0;t<=15;t++){r|=v(1);let i=e.counts[t];if(r-i<n)return e.symbols[a+r-n];a+=i,n+=i,n<<=1,r<<=1}return no()},I=()=>{let e=v(5)+257,t=v(5)+1,r=v(4)+4;(e>286||t>30)&&no();let n=new Uint8Array(19);for(let e=0;e<r;e++)n[mo[e]]=v(3);let a=Ve(n,!1),i=new Uint8Array(e+t);for(let e=0;e<i.length;){let t=L(a);if(t<16){i[e++]=t;continue}let r,n=0;16===t?(e||no(),n=i[e-1],r=3+v(2)):r=17===t?3+v(3):11+v(7),e+r>i.length&&no(),i.fill(n,e,e+r),e+=r}return i[256]||no(),f=e,i},A=e.window,x=new Uint8Array(lo+t),N=lo-A.length,O=lo+t;x.set(A,N);let P=lo,E=1===s?yo():2===s?go(c,f):null;for(;;){for(;h>0&&P<O;h--,P++)x[P]=x[P-d];if(h>0){r&&ao();break}if(-1===s){if(l)break;if(l=v(1),s=v(2),0===s){i>>>=7&o,o-=7&o;let e=v(16);e!==(65535&~v(16))&&no(),u=e}else 1===s?E=yo():2===s?(c=I(),E=go(c,f)):no();continue}if(0===s){if(!u){s=-1;continue}if(P>=O){r&&ao();break}x[P++]=v(8),u--;continue}if(P>=O&&!r)break;let t=L(E.lit);if(t<256){P>=O&&ao(),x[P++]=t;continue}if(256===t){s=-1;continue}t>285&&no();let n=fo[t-257]+v(so[t-257]),a=L(E.dist);a>29&&no(),d=ho[a]+v(uo[a]),(d>P-N||d>(e.windowSize??lo))&&no(),h=n}P<O&&ro("Compressed source data is incomplete; pass a valid PNG file.");let T=x.subarray(lo,P);for(let e=0;e<T.length;){for(let t=Math.min(T.length,e+5552);e<t;e++)m+=T[e],p+=m;m%=65521,p%=65521}r&&(i>>>=7&o,o-=7&o,(16777216*v(8)+(v(8)<<16)+(v(8)<<8)+v(8)>>>0!=65536*p+m>>>0||o||a!==n.length)&&no());let U=y+T.length,S=Math.min(lo,U);return{output:T,state:{pos:a,bits:i,count:o,final:l,type:s,left:u,lengths:c,hlit:f,copy:h,distance:d,a:m,b:p,produced:U,span:e.span,windowSize:e.windowSize,window:x.slice(P-S,P)}}}async function ze(e,t,r,n=!1,a=!1,i=!1,o=!1){let l,s=await e({unit:t,...n&&{carry:!0},...a&&{cold:!0},...i&&{alone:!0},...o&&{tail:!0}});if(s&&Object.hasOwn(s,Na))return{value:s[Na]};try{l=await r()}catch(r){throw await e({unitFailed:t}),r}return await e({unitDone:t,value:l}),{value:l}}async function He(e,t,r,{pngRows:n,pngPassRows:a,unfilterRow:i}){let{width:o,height:l,depth:s,channels:u}=t,c=a(t),f=Math.max(1,u*s>>3),h=c.reduce((e,t)=>e+Math.ceil(t[5]/io),0),d={pos:2,bits:0,count:0,final:0,type:-1,left:0,lengths:null,hlit:0,copy:0,distance:0,a:1,b:0,produced:0,span:Math.ceil(t.stream/h*1.25)+4096,windowSize:t.windowSize,window:new Uint8Array(0),previous:new Uint8Array(0)},m=[];for(let t=0;t<c.length;t++){let[,,,,,n,a]=c[t],o=[];for(let l=0;l<n;l+=io){let s,u=Math.min(io,n-l),h=()=>{let{output:e,state:o}=Ke(d,u*(a+1),t===c.length-1&&l+u===n,r),h=new Uint8Array(u*a),m=l?d.previous.slice():new Uint8Array(a),p=new Uint8Array(a);for(let t=0,r=0;t<u;t++){let n=e[r++];n>4&&ro("PNG contains an unknown row filter; pass a valid PNG file."),i(n,e,r,p,m,a,f),r+=a,h.set(p,t*a),[m,p]=[p,m]}return s={...o,previous:m},h};o.push((await ze(e,"png-pass-rows",h,!1,!0,!0)).value);let{value:m}=await ze(e,"png-pass-inflate",()=>s??(h(),s),!0,!1,!1,!0);m!==Ga&&(d=m)}m.push(ne(o,e.touched))}let p=16===s?Uint16Array:Uint8Array,y=p.BYTES_PER_ELEMENT,g=[];for(let r=0;r<l;r+=io){let a,i=Math.min(io,l-r),s=()=>{let e=new p(i*o*4),l=n(t,e,r);for(let e=0;e<c.length;e++){let[t,n,a,o,s,u,f]=c[e],h=Math.max(0,Math.ceil((r-n)/o)),d=Math.min(u,Math.ceil((r+i-n)/o));if(d<=h)continue;m[e].ahead(h*f,d*f);let p=m[e].subarray(h*f,d*f);for(let e=h;e<d;e++)l(p.subarray((e-h)*f,(e-h+1)*f),s,t,n,a,o,e)}a=[];for(let t=0;t<o;t+=oo){let r=Math.min(oo,o-t),n=new p(i*r*4);for(let a=0;a<i;a++)n.set(e.subarray(4*(a*o+t),4*(a*o+t+r)),a*r*4);a.push(new Uint8Array(n.buffer,n.byteOffset,n.byteLength))}return a},u=[];for(let t=0;t*oo<o;t++)u.push((await ze(e,"png-reference-rows",()=>(a??s())[t],!1,!0,!0,t>0)).value);g.push(u)}return{data:We(re(g,o*y,l,io,oo*y,e.touched),p),width:o,height:l,bitDepth:16===s?16:8,sampleFormat:"uint",...t.colour,alphaPremultiplied:!1,...t.orientation>1&&{orientation:t.orientation}}}function*Ye(e,t){return yield*z("icc-matches",function*(){let r=[],n=null,a=!1;for(;!a;){let i=yield*z("icc-match-part",function*(){let r=[];n=t.matches(e,(e,t,n)=>r.push(t||e,n),4,7,n,4096);let a=new Uint8Array(4*r.length),i=new DataView(a.buffer);return r.forEach((e,t)=>i.setUint32(4*t,e,!0)),{bytes:a,done:n.i===e.length}},void 0,!1,!0);r.push(i.bytes),a=i.done;let o=yield*K("icc-match-state",()=>null,()=>a?null:n,!0);null!==o&&o!==Ga&&(n=o)}return _a(r)})}function qe(e,t,r,n,a,i){for(;n.position<a;){let a=t.subarray(n.index,n.index+8),o=new DataView(a.buffer,a.byteOffset,a.byteLength),l=o.getUint32(0,!0),s=o.getUint32(4,!0),u=s?l:0,c=u||1,f=Math.min(c-n.within,e.length>65536?Mo:c);r.match(e,i,n.position,u?0:l,u?f:0,s),n.position+=f,n.within+=f,n.within===c&&(n.index+=8,n.within=0)}}function*$e(e,t,r){let n=!!t;return yield*z(n?"icc-lz":"icc-prefix",function*(){let a=yield*z("icc-frequencies",function*(){let a={position:0,within:0,index:0,frequencies:new Uint32Array(n?320:256),...n&&{distances:new Uint32Array(64)}};for(let i=0;i<e.length;i+=Mo){let o=Math.min(e.length,i+Mo),l=yield*K("icc-count",()=>{if(n)qe(e,t,r,a,o,(e,t,n)=>r.symbol(null,a,e,t,n));else for(let t of e.subarray(i,o))a.frequencies[t]++;return a});a=wo(l,a)}return{frequencies:a.frequencies,distances:a.distances}}),i=yield*V("icc-code",()=>{let t=r.model(e.length,a.frequencies,a.distances);return{...t,writer:bo(t.writer)}}),o=[],l={position:0,within:0,index:0},s=0,u=0,c=0;for(let a=0;a<e.length;a+=Mo){let f=Math.min(e.length,a+Mo),h=yield*z("icc-write-part",function*(){let o=new r.BitWriter(65536);a?(o.acc=s,o.pending=u):o.append(i.writer);let c=(e,t,n)=>r.symbol(o,i,e,t,n);if(n)qe(e,t,r,l,f,c);else for(let t of e.subarray(a,f))c(t,0,0);return bo(o)},void 0,!1,!0);if(o.push(h.bytes),c+=h.at,s=h.acc,u=h.pending,n){let e=yield*K("icc-write-state",()=>null,()=>l,!0);null!==e&&e!==Ga&&(l=e)}}return{bytes:_a(o),at:c,acc:s,pending:u,bitLength:8*c+u}})}function Qe(e){if(ArrayBuffer.isView(e))return t=>e[t];let t=new Map;return r=>{let n=65536*Math.floor(r/65536),a=t.get(n);return a||(a=e.subarray(n,Math.min(e.length,n+65536)),t.set(n,a),t.size>8&&t.delete(t.keys().next().value)),a[r-n]}}function Ze(e,t){let r=new Map;return n=>{if(n<0)return;let a=0,i=e.length;for(;a<i;){let t=a+i>>>1;e[t].at<=n?a=t+1:i=t}let o=e[a];if(t(o&&o.from<=n),ArrayBuffer.isView(o.bytes))return o.bytes[n-o.from];let l=r.get(a);return l||(l=o.bytes.subarray(0,o.at-o.from),r.set(a,l),r.size>8&&r.delete(r.keys().next().value)),l[n-o.from]}}function et(e,t){let{history:r,...n}=t;Object.assign(e,n),e.finished=!1,r&&(e.begin(),e.history.set(r))}function*tt(e,t,r){return yield*z("decode-input",function*(){if(yield*V("decode-input-signature",()=>r.admitInput(e,t)))return{codestream:e,boxes:[],container:null};let n={at:12,count:0,rawMetadata:0};for(;n.at<e.length;){let a=yield*V("decode-storage",()=>{let a={...n},i=r.uint32View(ae(e,0)),o=null;for(let n=0;n<64&&a.at<e.length;n++)o=r.storageNext(e,t,a,i)||o;return{state:a,repair:o}});if(n=a.state,a.repair){let t=yield*V("decode-cut-header",()=>r.repairedHeader(e,a.repair));e=ne([ae(e,0,a.repair.at),t,ae(e,a.repair.at+t.length)])}}let a=r.cutEnd(n);if(void 0!==a.end&&(e=ae(e,0,a.end)),a.last){let t=yield*V("decode-cut-fragment",()=>r.repairedHeader(e,a.last));e=ne([ae(e,0,a.last.at),t,ae(e,a.last.at+t.length)])}let i=yield*V("decode-container",()=>r.readContainer(e,{maxBytes:t.maxInputBytes,maxBoxes:t.maxBoxes})),o=[],l=0;for(let e of i.auxiliary){let n=yield*z("decode-metadata",function*(){let n="brob"===e.boxType,a=e.boxType,i=e.data;return n&&(a=yield*V("decode-metadata-type",()=>r.fourCC(r.uint32View(i.subarray(0,4)).getUint32(0))),i=yield*r.part("brotli").decompressBrotliSteps(ae(i,4),{maxOutput:t.maxMetadataBytes-l,dictionary:t.dictionary})),yield*V("decode-metadata-size",()=>(r.requireDecode(l+i.length<=t.maxMetadataBytes,"JPEG XL metadata exceeds the byte limit."),null)),{type:a,data:i,compressed:n}});o.push(n),l+=n.data.length}return{codestream:i.codestream,boxes:o,container:{level:i.level,minorVersion:i.minorVersion}}})}function rt(e){return function*(t,r,n){return yield*z(e,function*(){let a=yield*V(e+"-header",()=>n.start(t,r?.maxBytes,Qe(t))),i=a.state,o=[{bytes:a.bytes,from:0,at:i.at}];for(;!i.done;){let r=yield*V(e+"-part",()=>{let e=i.at,r=n.part(t,i,Ze(o,n.require),Qe(t));return i=r.state,{bytes:r.bytes,from:e,at:i.at}});o.push(r);let a=yield*K(e+"-state",()=>null,()=>i,!0);null!==a&&a!==Ga&&(i=a)}return _a(o.map(e=>e.bytes))})}}function nt(e,t,r){return function*(n,a,i){let o=i.limits(n,a);return yield*z(t,function*(){let t=yield*V(e+"-window",()=>i.start(n)),a=[];for(;!t.last;){let l=yield*z(e+"-meta",function*(){let l=yield*V(e+"-header",()=>i.header(n,t,o)),s=l.state;if("end"===l.kind||"skip"===l.kind)return{parts:[],state:s};let u=null;"compressed"===l.kind&&(u=yield*z(e+"-models",function*(){let e=l.state.bit,t=[];for(let[a,o]of i.groups(l)){let l=[];t.push(l);for(let t=0;t<a;t+=16){let s=yield*V(r,()=>{let r=i.reader(n,e);return{trees:i.trees(r,Math.min(16,a-t),o),bit:r.bit}});l.push(...s.trees),e=s.bit}}return{trees:t,bit:e}})),u&&(s={...s,bit:u.bit});let c=[];for(;s.at<l.end;){let t=yield*V(e+"-output",()=>{let e=s.at,t=i.part(n,l,u,s,Ze([...a,...c],i.require),o.dictionary);return s=t.state,{bytes:t.bytes,from:e,at:s.at}});c.push(t);let r=yield*K(e+"-state",()=>null,()=>s,!0);null!==r&&r!==Ga&&(s=r)}return{parts:c,state:i.metaEnd(s)}});a.push(...l.parts),t=l.state}return yield*V(e+"-end",()=>(i.end(n,t),null)),_a(a.map(e=>e.bytes))})}}function at(e,t=e.data??e.frames?.[0]?.data){let r=to.call(t),n=e.sampleFormat??("Float32Array"===r?"float32":"Float16Array"===r?"float16":"uint"),a=e.bitDepth??("float32"===n?32:"Uint16Array"===r||"float16"===n?16:8),i=e.colorEncoding?.transferFunction??e.transferFunction??("uint"===n?"srgb":"linear");return{sampleFormat:n,bitDepth:a,colorSpace:e.icc||e.colorEncoding?void 0:e.colorSpace??"srgb",transferFunction:e.icc||e.colorEncoding?void 0:i,intensityTarget:e.intensityTarget??("pq"===i?1e4:"hlg"===i?1e3:255),alphaPremultiplied:e.alphaPremultiplied??!1,orientation:e.orientation??1}}async function it({kind:e,width:t,height:r,colorSpace:n,sha256:a}){let i="sha256:"+a;if("file"===e||void 0===t)return{kind:"bytes",digest:i};let o=(new TextEncoder).encode(JSON.stringify(Po({width:t,height:r,...at({...n&&{colorSpace:n}},new Uint8Array(0)),data:i})));return{kind:"pixels",digest:"sha256:"+(globalThis.crypto?.subtle?Eo(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",o))):A(I(qn(),o)))}}function ot(e,t="Invalid JPEG XL data.",r){if(e)return;let n=Object.assign(new Error(t),{code:"JXL_DECODE"});throw r&&(n.bitOffset=r.bit),n}function lt(e,t){let r=0;for(let n=0;n<t;n++)r=r<<1|1&e,e>>=1;return r}function st(e){let t=new Uint32Array(17),r=new Uint32Array(17),n=new Uint16Array(e.length);for(let r of e)t[r]++;t[0]=0;for(let e=1,n=0;e<=16;e++)n=n+t[e-1]<<1,r[e]=n;for(let t=0;t<e.length;t++)e[t]&&(n[t]=lt(r[e[t]]++,e[t]));return n}function ut(e){let t=e.u64BigInt(),r=[];for(;t;)1n&t&&r.push(e.u64()),t>>=1n;for(let t of r)e.skip(t)}function ct(e){let t=e.u32([[0,0],[4,0],[5,16],[10,48]]),r=new Uint8Array(t);for(let n=0;n<t;n++)r[n]=e.read(8);try{return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{ot(!1,"Invalid UTF-8 JPEG XL name.",e)}}function ft(e,t=!1){let r=Co(e),n=t?r?[[0,16],[0,32],[5,1],[9,33]]:[[6,1],[8,65],[10,321],[12,1345]]:_o,a=()=>t?e.u32(n)*(r?8:1):r?8*(1+e.read(5)):e.u32(n),i=a(),o=e.read(3);return{width:o?Math.floor(i*Ro[o][0]/Ro[o][1]):a(),height:i}}function ht(e){let t=Co(e),r=e.u32(t?[[0,32],[0,16],[0,24],[6,1]]:[[0,8],[0,10],[0,12],[6,1]]),n=t?e.read(4)+1:0;return ot(r<=(t?32:31)&&(!t||n<=8&&r>n+1),"Invalid JPEG XL sample depth.",e),{float:t,bits:r,exponentBits:n}}function dt(e){if(Co(e))return{type:0,bitDepth:{...Bo},dimShift:0,name:"",associated:!1};let t=e.enum();ot(t<=6||15===t||16===t,"Invalid JPEG XL extra channel type.",e);let r=ht(e),n=e.u32([[0,0],[0,3],[0,4],[3,1]]);ot(n<=3,"Invalid JPEG XL extra channel dimension shift.",e);let a={type:t,bitDepth:r,dimShift:n,name:ct(e),associated:!1};return 0===t&&(a.associated=Co(e)),2===t&&(a.spotColor=Go(4,()=>e.f16())),5===t&&(a.cfaChannel=e.u32([[0,1],[2,0],[4,3],[8,19]])),a}function mt(e){return Go(2,()=>To(e.u32([[19,0],[19,524288],[20,1048576],[21,2097152]]))/1e6)}function pt(e){let t={space:"rgb",spaceId:0,wantICC:!1,whitePoint:"d65",whitePointId:1,primaries:"srgb",primariesId:1,transferFunction:"srgb",transferId:13,renderingIntent:1};return Co(e)||(t.wantICC=Co(e),t.spaceId=e.enum(),ot(t.spaceId<=3,"Invalid JPEG XL color space.",e),t.space=["rgb","gray","xyb","unknown"][t.spaceId],t.wantICC)||(2!==t.spaceId&&(t.whitePointId=e.enum(),ot([1,2,10,11].includes(t.whitePointId),"Invalid JPEG XL white point.",e),t.whitePoint=2===t.whitePointId?mt(e):{1:"d65",10:"e",11:"dci"}[t.whitePointId]),1!==t.spaceId&&2!==t.spaceId&&(t.primariesId=e.enum(),ot([1,2,9,11].includes(t.primariesId),"Invalid JPEG XL primaries.",e),t.primaries=2===t.primariesId?Go(3,()=>mt(e)):{1:"srgb",9:"rec2020",11:"display-p3"}[t.primariesId]),2===t.spaceId?(t.transferFunction="gamma",t.gamma=1/3,t.transferId=null):Co(e)?(t.transferId=null,t.transferFunction="gamma",t.gamma=e.read(24)/1e7,ot(t.gamma>0,"Invalid JPEG XL gamma.",e)):(t.transferId=e.enum(),t.transferFunction={1:"bt709",2:"unknown",8:"linear",13:"srgb",16:"pq",17:"dci",18:"hlg"}[t.transferId],ot(void 0!==t.transferFunction,"Invalid JPEG XL transfer function.",e)),t.renderingIntent=e.enum(),ot(t.renderingIntent<=3,"Invalid JPEG XL rendering intent.",e)),t}function yt(e,t){let r={intensityTarget:255,minNits:0,relativeToMaxDisplay:!1,linearBelow:0};return t&&!Co(e)&&(r.intensityTarget=e.f16(),r.minNits=e.f16(),r.relativeToMaxDisplay=Co(e),r.linearBelow=e.f16(),ot(r.intensityTarget>0&&r.minNits>=0&&r.minNits<=r.intensityTarget&&r.linearBelow>=0&&(!r.relativeToMaxDisplay||r.linearBelow<=1),"Invalid JPEG XL tone mapping.",e)),r}function gt({width:e,height:t},r,n,a){let i=`A ${Do(e)} x ${Do(t)} ${a}`;if(e>n||t>n)throw Object.assign(new Error(`${i} is over maxDimension (${Do(n)} pixels a side): raise maxDimension.`),{code:"JXL_DIMENSIONS"});if(e*t>r)throw Object.assign(new Error(`${i} (${Do(e*t)} pixels) is over maxPixels (${Do(r)}): raise maxPixels.`),{code:"JXL_DIMENSIONS"})}function Mt(e,t={}){e.expect(16,2815);let r={...ft(e),orientation:1,intrinsicSize:null,preview:null,animation:null},n=t.maxDimension??1073741824;ot(r.width>0&&r.height>0,"Invalid JPEG XL image size.",e),gt(r,t.maxPixels??Dr,n,"picture");let a=Co(e),i=!a&&Co(e);i&&(r.orientation=e.read(3)+1,Co(e)&&(r.intrinsicSize=ft(e)),Co(e)&&(r.preview=ft(e,!0)),Co(e)&&(r.animation={numerator:e.u32([[0,100],[0,1e3],[10,1],[30,1]]),denominator:e.u32([[0,1],[0,1001],[8,1],[10,1]]),loops:e.u32([[0,0],[3,0],[16,0],[32,0]]),timecodes:Co(e)})),r.bitDepth=a?{...Bo}:ht(e),r.modular16=a||Co(e);let o=a?0:e.u32([[0,0],[0,1],[4,2],[12,1]]);ot(o<=256,"Too many JPEG XL extra channels.",e),r.extraChannels=Go(o,()=>dt(e)),r.xyb=a||Co(e);let l=e.bit;if(r.colorEncoding=a?{space:"rgb",spaceId:0,wantICC:!1,whitePoint:"d65",whitePointId:1,primaries:"srgb",primariesId:1,transferFunction:"srgb",transferId:13,renderingIntent:1}:pt(e),r.colorBits=a?null:[l,e.bit],r.colorChannels=1===r.colorEncoding.spaceId?1:3,r.toneMapping=yt(e,i),a||ut(e),r.opsinInverseMatrix={inverseMatrix:[...So.inverseMatrix],opsinBiases:[...So.opsinBiases],quantBias:So.quantizationBiases.slice(0,3),quantBiasNumerator:So.quantizationBiases[3]},r.upsamplingWeights={},!Co(e)){r.xyb&&!Co(e)&&(r.opsinInverseMatrix={inverseMatrix:Go(9,()=>e.f16()),opsinBiases:Go(3,()=>e.f16()),quantBias:Go(3,()=>e.f16()),quantBiasNumerator:e.f16()});let t=e.read(3);for(let[n,a,i]of[[1,2,15],[2,4,55],[4,8,210]])t&n&&(r.upsamplingWeights[a]=Go(i,()=>e.f16()))}return r.iccBitOffset=e.bit,r}function bt(e,t={}){let r=t.maxInputBytes??Number.MAX_SAFE_INTEGER,n=t.maxBoxes??Number.MAX_SAFE_INTEGER;if(!Number.isSafeInteger(r)||r<1)throw fn("JXL_OPTIONS","Invalid maxInputBytes; use a positive safe integer.");if(!Number.isSafeInteger(n)||n<1)throw fn("JXL_OPTIONS","Invalid maxBoxes; use a positive safe integer.");for(let e of["maxPixels","maxDimension","maxMetadataBytes"])if(void 0!==t[e]&&!(Number.isSafeInteger(t[e])&&t[e]>0))throw fn("JXL_OPTIONS",`Invalid ${e}; use a positive safe integer.`);if(e.byteLength>r)throw fn("JXL_LIMIT","Input exceeds maxInputBytes; pass a smaller file or raise maxInputBytes.");let{maxInputBytes:a,maxBoxes:i,complete:o=!1,...l}=t,s=Lt(e,n,o),u=xt(s,e=>Mt(new Uo(e,!0),{maxPixels:1/0,maxDimension:l.maxDimension,...void 0!==l.maxPixels&&{maxPixels:l.maxPixels}}));return u.reconstruction=s.reconstruction,u}function wt(e){try{return xt(Lt(e),e=>{let t=new Uo(e,!0),r=Mt(t,{maxPixels:1/0});return r.colorEncoding.wantICC||r.preview?null:(t.align(),!t.read(1)&&(t.read(3),0n!=(1n&t.u64BigInt())))})}catch(e){if(Wo.has(e?.code))return null;throw e}}function*vt(e,t={}){return globalThis[Xa]&&!globalThis[Xa].plain?yield*Ra("boundedHeader")(e,t,{header:bt}):Vo(e,t)}function Lt(e,t=Number.MAX_SAFE_INTEGER,r=!1){let n=e.subarray(0,Math.min(e.length,12));if(255===n[0]&&10===n[1]){let t=t=>e.subarray(0,Math.min(t,e.length));return{codestream:t(Ho),window:t,total:e.length,reconstruction:!1}}if(n.length<12||!jo.every((e,t)=>n[t]===e))throw Yo("Invalid JPEG XL signature");let a=new Map,i=0,o=0,l=!1,s=null,u=0,c=-1,f=-1,h=0,d=0,m=!1,p=!1;for(let n=12;n<e.length&&!p;){if(i>=t)throw Yo("JPEG XL box count exceeds maxBoxes","pass a simpler file or raise maxBoxes");if(e.length-n<8){p=!0;break}let y=e.subarray(n,Math.min(e.length,n+28)),g=qo(y,0),M=qo(y,4),b=1===g?16:8;if(y.length<b){p=!0;break}let w=1===g?4294967296*qo(y,8)+qo(y,12):g||e.length-n;if(!Number.isSafeInteger(w)||w<b)throw Yo("Invalid JPEG XL box size");p=w>e.length-n;let v=n+b,L=p?e.length:n+w,I=L-v;if(i){if(M===Jo||1247300640===M)throw Yo("Repeated JPEG XL file header")}else{if(M!==Jo)throw Yo("Second JPEG XL box must declare the jxl file type");if(I<8){if(p&&!r)break;throw Yo("Second JPEG XL box must declare the jxl file type")}if((!p||r)&&(I<12||I%4)||qo(y,b)!==Fo)throw Yo("Second JPEG XL box must declare the jxl file type");if(o=qo(y,b+4),o>1)throw Yo("JPEG XL file-format minorVersion is 0 or 1");let t=!1;for(let r=v+8;r<L&&!t;r+=Ho){let n=e.subarray(r,Math.min(L,r+Ho));for(let e=0;e+4<=n.length;e+=4)t||=qo(n,e)===Fo}if(!t&&(!p||r))throw Yo("File type lacks the jxl compatibility brand")}let A=M;if(1786276972===M){if(1!==i||l||I>1||(!p||r)&&1!==I||1===I&&5!==y[b]&&10!==y[b])throw Yo("Level box (5 or 10) follows the file type");l=!0}else if(1786276963===M){if(s||u)throw Yo("Repeated or mixed JPEG XL codestream boxes");s=[v,L]}else if(1786276976===M){if(s||(!p||r)&&I<4)throw Yo("Invalid JPEG XL codestream fragment");if(I>=4){let e=qo(y,b),t=2147483647&e,r=e>=2147483648;if(a.has(t)||0===o&&t!==u)throw Yo("Repeated or out-of-order version 0 codestream fragment");if(r){if(c>=0)throw Yo("Repeated final codestream fragment");c=t}if(f=Math.max(f,t),c>=0&&f>c)throw Yo("JPEG XL container has no complete codestream");a.set(t,[v+4,L]),u++}}else if(M===ko){if((!p||r)&&I<4)throw Yo("Truncated compressed JPEG XL box");if(I>=4&&(A=qo(y,b),A===ko||A===Xo||A>>>8==6977644))throw Yo("Brotli cannot wrap codestream, index, reconstruction or Brotli boxes")}if(A===Ko&&++h>1||A===zo&&++d>1)throw Yo("At most one frame index and one gain map");M===Xo&&(m=!0),i++,n=L}if(r&&(p||u&&(c<0||u!==c+1))||!s&&!a.has(0))throw Yo("JPEG XL container has no complete codestream");let y=s?[s]:[];for(let e=0;!s&&a.has(e);e++)y.push(a.get(e));let g=y.reduce((e,[t,r])=>e+r-t,0),M=t=>At(e,y,Math.min(t,g));return It({codestream:M(Ho),window:M,total:g,reconstruction:m},r)}function It(e,t){let{codestream:r}=e;if((t||r.length>=2)&&(r.length<2||255!==r[0]||10!==r[1]))throw Yo("Invalid logical JPEG XL codestream signature");return e}function At(e,t,r){if(1===t.length)return e.subarray(t[0][0],t[0][0]+r);let n=new Uint8Array(r);for(let a=0,i=0;i<r;i+=t[a][1]-t[a][0],a++)n.set(e.subarray(t[a][0],Math.min(t[a][1],t[a][0]+r-i)),i);return n}function xt(e,t){for(let r=Ho,n=e.codestream;;n=e.window(r*=4))try{return t(n)}catch(t){if(n.length===e.total||"JXL_DECODE"!==t?.code)throw t}}function Nt(e){if(!e||"object"!=typeof e||Array.isArray(e))return e;let{transferFunction:t,primaries:r,...n}=e;("gamma"!==t||void 0===e.gamma)&&(n.transferFunction=t),("gray"!==e.space||"srgb"!==r)&&(n.primaries=r),Number.isInteger(e.renderingIntent)&&$o[e.renderingIntent]&&(n.renderingIntent=$o[e.renderingIntent]),"d50"===e.whitePoint&&(n.whitePoint=[.345669,.358496]);for(let e of Object.keys(n))void 0===n[e]&&delete n[e];return n}function Ot(e){let t={...Qo[e.format]};if(e.rgbaICC)return t;let r=e.rgbaColorEncoding??{},n=void 0===r.whitePoint||"d65"===r.whitePoint,a="gray"===r.space?"srgb":r.primaries;return Zo.includes(a)&&n&&(t.colorSpace=a),el.includes(r.transferFunction)&&(t.transferFunction=r.transferFunction),t}function Pt(e){if(!Object.hasOwn(Qo,e.format))throw fn("JXL_INPUT","Invalid decoded sample format; use uint8, uint16, or float32.");let t=Ot(e),r=e.header,n=r?.toneMapping?.intensityTarget;"number"==typeof n&&(t.intensityTarget=n);for(let r of rl)if(void 0!==e[r]&&e[r]!==t[r])throw fn("JXL_INPUT",`${r} is ${String(e[r])} but the samples are ${String(t[r]??"unnamed")}; to retag, pass {data, width, height, ${r}}.`);let a=e.frames?.[0],i=a&&["icc","colorEncoding","alphaPremultiplied"].find(t=>!nl(e[t]??null,a[t]??null))||r&&e.orientation!==r.orientation&&"orientation";if(i)throw fn("JXL_INPUT",`${i} on a decoded picture is the file's; to retag, pass {data, width, height, ${i}}.`);let o=e.rgbaColorEncoding;if(e.rgbaICC)t.icc=e.rgbaICC;else if(void 0===t.colorSpace||void 0===t.transferFunction||"rgb"!==o?.space||1!==(o.renderingIntent??1)){if(!["rgb","gray"].includes(o?.space)||["unknown","icc"].includes(o.transferFunction))throw fn("JXL_INPUT","Encode cannot name this color; decode with colorSpace srgb, display-p3 or rec2020.");delete t.colorSpace,delete t.transferFunction,t.colorEncoding=Nt(o)}if(e.alphaPremultiplied&&(t.alphaPremultiplied=!0),!e.orientationApplied&&e.orientation>1&&(t.orientation=e.orientation),null!=e.extraChannels&&!Array.isArray(e.extraChannels))throw fn("JXL_INPUT","Invalid decoded extraChannels field; pass an array.");if((e.extraChannels??[]).filter(e=>0!==e?.type).length)throw fn("JXL_UNSUPPORTED","Encode drops extra channels beyond alpha; pass {data, width, height}, or use format({kind: 'channels'}).");return t}function Et(e){let t=Pt(e);if(e.animation){if(!Array.isArray(e.frames))throw fn("JXL_INPUT","Decoded animation has no frame list; pass its frames array.");for(let t of e.frames)if(!t||"object"!=typeof t||!ArrayBuffer.isView(t.data)||t.data instanceof DataView||!Number.isFinite(t.durationSeconds)||t.durationSeconds<0)throw fn("JXL_INPUT","Invalid decoded frame; pass sample data and finite, nonnegative durationSeconds.");return{width:e.width,height:e.height,loops:e.animation.loops,...t,frames:e.frames.map(e=>({data:e.data,duration:1e3*e.durationSeconds}))}}return{data:e.data,width:e.width,height:e.height,...t}}async function Tt(e,t,r,n){let a=!!ol(r)?.decode,{[Vn]:i,...l}=r;try{return await e(t,l,n)}catch(e){throw a?o(e):e}}function Ut(e,t){let r=e.colorEncoding,n=e.extraChannels;return t.region?"Banded verification":e.animation?"Verifying an animation":e.bitDepth.float||8!==e.bitDepth.bits?"Verifying a file of more than 8 bits or float samples":!r.wantICC&&["rgb","gray"].includes(r.space)&&"d65"===r.whitePoint&&["srgb","display-p3"].includes(r.primaries)&&"srgb"===r.transferFunction&&255===e.toneMapping?.intensityTarget?1!==e.orientation||n.length>1||n.some(e=>0!==e.type||e.associated||e.bitDepth.float||8!==e.bitDepth.bits||e.dimShift)?"Verifying a file with orientation or extra channels":"original"!==(t.colorSpace??"original")||t.unpremultiplyAlpha?"Verifying in another color space":null:"Verifying a file whose color is not sRGB or Display P3"}function St(e,t,r){let{primaries:n,renderingIntent:a}=e.colorEncoding,i={space:"rgb",whitePoint:"d65",primaries:n,transferFunction:"srgb",renderingIntent:a};return{width:t.width,height:t.height,data:new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.length),format:"uint8",planes:[],extraChannels:e.extraChannels.map(e=>({...e})),colorEncoding:i,icc:null,rgbaColorEncoding:i,rgbaICC:null,duration:0,durationSeconds:0,alphaPremultiplied:!1,orientation:1,orientationApplied:!1,animation:null,bitDepth:8,sampleFormat:"uint",colorSpace:n,transferFunction:"srgb",header:e,..."opaque"===r&&{colorScope:"opaque"}}}async function jt(e,t,r=!1){if(Ut(e,t)||!await n())return!1;let a=await i(),o=r?a.bitmap:a;return!("display-p3"===e.colorEncoding.primaries&&!o.displayP3)&&(!e.extraChannels.length||!ol(t)?.decode&&(o.alpha||"opaque"))}function Jt(e,t){if(u(t.signal),ol(t)?.decode&&e&&"object"==typeof e&&!Array.isArray(e)&&(e=f(e,"Decoder result")),!tl(e))throw fn("JXL_PLATFORM","Invalid decoder output; configure decode from rapier-jxl/decode.");return e}async function Ft(e,t){let r=ll("decode",t)?.[sl];return r?Jt(await Tt(r,e.slice(),t),t):null}function kt(e,t){let r=ml(t)?.open;if(!r)throw fn("JXL_PLATFORM","Bounded verification"+il);return r(e,t)}async function Xt(e,t){let r=ll("decode",t);if(!r)throw fn("JXL_PLATFORM","Verifying a JPEG XL file"+il);return Jt(await Tt(r,e.slice(),t),t)}async function _t(e,t,r,n=!1){let a=ml(t)?.[n?"withoutNoise":"region"];if(!a)throw fn("JXL_PLATFORM","Bounded verification"+il);let{maxTotalSamples:i,...o}=t;return Jt(await Tt(a,e,o,r),t)}function Rt(e,t,r){if(void 0!==r&&!["rgb","gray","cmyk"].includes(r))throw Vr("JXL_INPUT","The expected ICC source space is rgb, gray or cmyk.");if(!(e instanceof Uint8Array)||e.length<132)throw Vr("JXL_INPUT","ICC is a Uint8Array of the complete profile.");if(5===t&&e.length>4194304)throw Vr("JXL_SIZE","Level 5 ICC profiles are at most 4 MiB.");let n=e.subarray(0,132),a=new DataView(n.buffer,n.byteOffset,n.byteLength),i=e=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]);if(a.getUint32(0)!==e.length||"acsp"!==i(36))throw Vr("JXL_INPUT","ICC size or profile signature is invalid.");let o=i(16),l=i(20);if(!["RGB ","XYZ ","Lab ","Luv ","YCbr","Yxy ","HSV ","HLS ","CMY ","3CLR","GRAY"].includes(o)&&("CMYK"!==o||"cmyk"!==r))throw Vr("JXL_INPUT","ICC needs RGB, GRAY, or CMYK with a planar-channel context.");if(void 0!==r&&o!=={rgb:"RGB ",gray:"GRAY",cmyk:"CMYK"}[r])throw Vr("JXL_INPUT","The ICC space does not match the channels.");if("CMYK"===o&&5===t)throw Vr("JXL_INPUT","CMYK and black channels need level 10.");if("XYZ "!==l&&"Lab "!==l)throw Vr("JXL_INPUT","ICC profile connection space must be XYZ or Lab.");let s=a.getUint32(128);if(s>Math.floor((e.length-132)/12))throw Vr("JXL_INPUT","ICC tag table exceeds the profile.");return{count:s,end:132+12*s,channels:"GRAY"===o?1:3}}function Bt(e,t,r,n){let a=e.subarray(132+12*r,132+12*n),i=new DataView(a.buffer,a.byteOffset,a.byteLength);for(let a=0;a<n-r;a++){let r=12*a,n=i.getUint32(r+4),o=i.getUint32(r+8);if(n<t.end||n%4||o<8||n>e.length||o>e.length-n)throw Vr("JXL_INPUT","ICC tag data is unaligned or outside the profile.")}}function Gt(e,t,r){let n=Rt(e,t,r);for(let t=0;t<n.count;t+=4096)Bt(e,n,t,Math.min(n.count,t+4096));return n.channels}function Ct(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw Vr("JXL_INPUT",t+" is an object.")}function Dt(e,t,r){if("rendering intent"===r&&Number.isInteger(e)&&(e=Object.keys(t)[e]),"string"!=typeof e||!Object.hasOwn(t,e))throw Vr("JXL_INPUT","Unsupported "+r+": "+e+".");return t[e]}function Wt(e){if(!Array.isArray(e)||2!==e.length)throw Vr("JXL_INPUT","A chromaticity is [x, y].");let t=e.map(e=>{if("number"!=typeof e||!Number.isFinite(e))throw Vr("JXL_INPUT","Chromaticity coordinates are finite numbers.");let t=Math.round(1e6*e);if(t<-2097152||t>2097151)throw Vr("JXL_INPUT","Chromaticity exceeds the signed JPEG XL field, in millionths.");return t});if(!t[1])throw Vr("JXL_INPUT","Chromaticity y is zero in millionths.");return t}function Vt(e,t){for(let r of t)e.writeU32(wl,v(r))}function Kt(e={},t={}){Ct(e,"colorEncoding");let r=e.space??"rgb";if("unknown"===r)throw Vr("JXL_INPUT","An unknown color encoding requires an ICC profile.");if("xyb"===r){if(["whitePoint","primaries","transferFunction","gamma"].some(t=>void 0!==e[t]))throw Vr("JXL_INPUT","XYB color is implicit; omit white point, primaries and gamma.");let t=Dt(e.renderingIntent??"perceptual",Al,"rendering intent"),r=new Cn(16);return r.write(2,0),r.writeU32(bl,2),r.writeU32(bl,t),{colorData:r,colorChannels:3,transferFunction:void 0}}if("rgb"!==r&&"gray"!==r)throw Vr("JXL_INPUT","colorEncoding.space is rgb, gray or xyb; otherwise use ICC.");let n="gray"===r?1:3,a=e.whitePoint??"d65",i=Array.isArray(a)?Wt(a):null,o=i?2:Dt(a,vl,"white point"),l=e.primaries??t.colorSpace??"srgb",s=null,u=1;if(1===n&&void 0!==e.primaries)throw Vr("JXL_INPUT","Gray color encoding has no RGB primaries.");if(3===n)if(Array.isArray(l)){if(3!==l.length)throw Vr("JXL_INPUT","Primaries are three [x, y] pairs: red, green, blue.");s=l.map(Wt);let[e,t,r]=s;if((e[0]-r[0])*(t[1]-r[1])===(t[0]-r[0])*(e[1]-r[1]))throw Vr("JXL_INPUT","RGB primaries must define a nonzero color triangle.");u=2}else u=Dt(l,Ll,"RGB primaries");let c=void 0!==e.gamma;if(c&&void 0!==e.transferFunction)throw Vr("JXL_INPUT","Declare either gamma or transferFunction, not both.");let f=0,h=13,d=e.transferFunction??t.transferFunction??"srgb";if(c){if("number"!=typeof e.gamma||!Number.isFinite(e.gamma)||e.gamma<1/8192||e.gamma>1)throw Vr("JXL_INPUT","Gamma is from 1/8192 to 1 (for example 1/2.2).");if(f=Math.round(1e7*e.gamma),8192*f<1e7)throw Vr("JXL_INPUT","Gamma is too small after codestream rounding.")}else h=Dt(d,Il,"transfer function");let m=Dt(e.renderingIntent??"relative",Al,"rendering intent"),p=new Cn(64);if(p.write(2,0),p.writeU32(bl,3===n?0:1),p.writeU32(bl,o),i&&Vt(p,i),3===n&&(p.writeU32(bl,u),s))for(let e of s)Vt(p,e);return p.write(1,c?1:0),c?p.write(24,f):p.writeU32(bl,h),p.writeU32(bl,m),{colorData:p,colorChannels:n,transferFunction:c?void 0:d}}function zt(e,t,r,n){let a=73===e[t]&&73===e[t+1];if(!a&&(77!==e[t]||77!==e[t+1]))return null;let i=new DataView(e.buffer,e.byteOffset,e.byteLength),o=e=>e+2>r?0:i.getUint16(e,a),l=e=>e+4>r?0:i.getUint32(e,a);if(42!==o(t+2)||l(t+4)<8)return null;let s=t+l(t+4),u=o(s);for(let e=0,t=s+2;e<u&&t+12<=r;e++,t+=12){let e=o(t+8);if(274===o(t)&&3===o(t+2)&&1===l(t+4)&&e>=1&&e<=8)return n?.(t+8,!a),e}return null}function Ht(e,t,r=!0){for(let[r,n]of Object.entries(Dl))if(n.every((r,n)=>Math.abs(r-e[n])<=t))return r;r&&Gl("Primaries must be sRGB, Display P3 or Rec. 2020, D65.")}async function Yt(e,t,r){let n=!1;try{n="function"==typeof DecompressionStream}catch{}if(!n)throw Vr("JXL_PLATFORM","This runtime has no DecompressionStream, which reads a PNG; pass pixels ({data, width, height}) read where a PNG can be decoded, or run on a runtime that has it (on Next.js, the Node.js runtime).");let a=1032*e.reduce((e,t)=>e+t.length,0),i=void 0===t,o=i?"The compressed ICC profile is incomplete.":"Compressed source data is incomplete.";!i&&t>a&&Gl(o);let l=new Uint8Array(i?4:Math.min(t,65536)),s=new ReadableStream({start(t){for(let r of e)t.enqueue(r);t.close()}}).pipeThrough(new DecompressionStream("deflate")).getReader(),u=0;try{for(;;){let{value:e,done:n}=await s.read();if(n)break;let c=e;if(i&&void 0===t){let e=Math.min(4-u,c.length);if(l.set(c.subarray(0,e),u),u+=e,c=c.subarray(e),u<4)continue;if((t=Cl(l).getUint32(0))<132&&Gl(o),void 0!==r&&t>r)throw Vr("JXL_LIMIT","Decoded metadata exceeds maxMetadataBytes; raise it or pass a smaller picture.");t>a&&Gl(o)}if(u+c.length>t&&Gl(i?"The ICC profile expands beyond its declared size.":"Compressed source data exceeds its declared dimensions."),u+c.length>l.length){let e=new Uint8Array(Math.min(t,Math.max(u+c.length,4*l.length)));e.set(l.subarray(0,u)),l=e}l.set(c,u),u+=c.length}return(void 0===t||u!==t)&&Gl(o),l}catch(e){if(await s.cancel().catch(()=>{}),String(e?.code).startsWith("JXL_")||Yr(e))throw e;Gl("The source contains an invalid deflate stream.")}finally{s.releaseLock()}}function qt(e,t=0){let r=0;t=~t;let n=Vl,a=e.length-7;for(;r<a;r+=8){let a=(t^(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24))>>>0;t=n[1792+(255&a)]^n[1536+(a>>>8&255)]^n[1280+(a>>>16&255)]^n[1024+(a>>>24)]^n[768+e[r+4]]^n[512+e[r+5]]^n[256+e[r+6]]^n[e[r+7]]}for(;r<e.length;r++)t=t>>>8^n[255&(t^e[r])];return~t>>>0}function $t(e,t){let r={space:e,...t};return Kt(r),{colorEncoding:r}}function Qt(e,t){let r=0===t||4===t?"gray":"rgb",n=e.get("cICP");if(n){let e={1:"srgb",9:"rec2020",11:"display-p3",12:"display-p3"}[n[0]],t={1:"bt709",8:"linear",13:"srgb",16:"pq",17:"dci",18:"hlg"}[n[1]];return(!e||!t||0!==n[2]||1!==n[3])&&Gl("PNG cICP needs supported RGB primaries and transfer, full range, identity matrix."),11===n[0]||"bt709"===t||"dci"===t?$t(r,{whitePoint:11===n[0]?"dci":"d65",..."rgb"===r?{primaries:e}:{},transferFunction:t}):{colorSpace:e,transferFunction:t}}let a=e.get("iCCP");if(a){let e=a.indexOf(0),t=a.subarray(0,e);return(e<1||e>79||e+2>=a.length||0!==a[e+1]||32===t[0]||32===t[t.length-1]||t.some((e,r)=>e<32||e>126&&e<161||32===e&&32===t[r-1]))&&Gl("PNG iCCP needs a valid name, method 0 and a complete deflate stream."),{packed:a.subarray(e+2)}}let i=e.get("sRGB");if(i)return 1!==i[0]?$t(r,{transferFunction:"srgb",renderingIntent:["perceptual","relative","saturation","absolute"][i[0]]}):{colorSpace:"srgb",transferFunction:"srgb"};let o,l=e.get("gAMA"),s=e.get("cHRM"),u=l?Cl(l).getUint32(0)/1e5:void 0,c="srgb",f="d65";if(s){let e=Cl(s),t=Array.from({length:8},(t,r)=>e.getUint32(4*r)/1e5);c=Ht([...t.slice(2),...t.slice(0,2)],51e-7,!1),c||(f=t.slice(0,2),o=[t.slice(2,4),t.slice(4,6),t.slice(6,8)])}return!c||void 0!==u&&1!==u?$t(r,{whitePoint:f,..."rgb"===r?{primaries:c??o}:{},...void 0===u?{transferFunction:"srgb"}:{gamma:u}}):{colorSpace:c,transferFunction:l?"linear":"srgb"}}function Zt(t,r,n,a,i){let o=Cl(r),l=n+r.length,{offset:s=8,crcAt:u=0,crc:c=0,length:f=0,seen:h=0,ended:d=!1,chunks:m=new Map,parts:p=[],exifAt:y}=t??{},g=(e,t=0,r=!1)=>({offset:s,crcAt:u,crc:c,length:f,seen:h,ended:d,chunks:m,parts:p,exifAt:y,next:e,least:t,done:r});for(;;){if(d||s+12>a)return g(s,0,!0);if(s+8>l)return g(s);let t=s<n;t||(f=o.getUint32(s-n));let M=s+12+f;(f>2147483647||M>a)&&Gl("The PNG contains a truncated chunk.");let b=t?[]:r.subarray(s+4-n,s+8-n),w=t?"IDAT":String.fromCharCode(...b);(!/^[A-Za-z]{4}$/.test(w)||32&b[2])&&Gl("The PNG contains an invalid chunk name."),u<s+4&&(u=s+4,c=0);let v=Math.min(M-4,l);if(c=qt(r.subarray(u-n,v-n),c),u=v,M>l)return"IDAT"===w?g(v):(u=0,g(s,M-s));c!==o.getUint32(M-4-n)&&Gl("A PNG chunk checksum does not match.");let L="IDAT"===w?null:r.slice(s+8-n,M-4-n);8===s&&"IHDR"!==w&&Gl("PNG must begin with IHDR."),1===h&&"IDAT"!==w&&(h=2);let I="IHDR"===w?L:m.get("IHDR"),A=I?.[8],x=I?.[9];if("IHDR"===w){(m.has(w)||13!==f)&&Gl("PNG requires one complete IHDR."),e(Cl(L).getUint32(0),Cl(L).getUint32(4),i);let t=Kl[x];(!(16===A?t&&3!==x:8===A?t:!(1!==A&&2!==A&&4!==A||0!==x&&3!==x))||L[10]||L[11]||L[12]>1)&&Gl("PNG must be 8- or 16-bit gray, RGB or RGBA, palette up to 8 bits, or gray at 1, 2 or 4 bits."),m.set(w,L)}else if("IDAT"===w)2===h&&Gl("PNG image data chunks must be consecutive."),h=1,p.push([s+8,f]);else if("IEND"===w)(f||!h||M!==a)&&Gl("PNG requires a final empty IEND after image data."),d=!0;else if("eXIf"===w)!h&&!m.has(w)&&(m.set(w,L),y=s+8);else{if("acTL"===w||"fcTL"===w||"fdAT"===w)throw Vr("JXL_UNSUPPORTED","This is an animated PNG: decode its frames and pass {width, height, frames} to rapier-jxl/animation.");if(["cICP","sRGB","iCCP","gAMA","cHRM","tRNS","sBIT","PLTE","mDCV","cLLI"].includes(w)){(h||m.has(w))&&Gl("PNG color and transparency chunks occur once, before image data.");let e={cICP:4,sRGB:1,gAMA:4,cHRM:32,mDCV:24,cLLI:8};void 0!==e[w]&&f!==e[w]&&Gl("A PNG color chunk has an invalid size."),"sRGB"===w&&L[0]>3&&Gl("PNG sRGB rendering intent is invalid."),"sBIT"===w&&(f!=={0:1,2:3,3:3,4:2,6:4}[x]||L.some(e=>e<1||e>(3===x?8:A)))&&Gl("PNG significant sample depths are invalid."),"tRNS"===w&&!(0===x&&2===f||2===x&&6===f||3===x&&f>=1&&f<=(m.get("PLTE")?.length??0)/3)&&Gl("PNG transparency does not match the channels or palette."),"PLTE"===w&&(0===x||4===x||!f||f>768||f%3||3===x&&f/3>1<<A)&&Gl("The PNG palette is invalid for its channel layout."),m.set(w,L)}else 32&b[0]||Gl("The PNG has an unsupported critical chunk.")}s=M}}async function er(e,t){let r=Qt(e,t);if(!r.packed)return r;let n=0===t||4===t?"gray":"rgb",a=await Yt([r.packed]);return Gt(a,void 0,n)!==("gray"===n?1:3)&&zl("PNG channels and ICC space differ."),{icc:a}}function tr(e,t,r,n,a,i,o){kl(n,i,a,t,r,e,o)}async function rr(){if(!await Ul()||!El())throw jn()}function nr({chunks:e,exifAt:t}){let r,n,a=Hl(e.get("IHDR")),i=e.get("eXIf"),o=i?zt(i,0,i.length,(e,a)=>{r=t+e,n=a}):null;return{width:a.getUint32(0),height:a.getUint32(4),orientation:o??1,orientationAt:r,orientationBig:n,...void 0!==r&&{exifAt:t,exifLength:i.length}}}async function ar({chunks:e,parts:t,ended:r},n){r||zl("PNG image data or its end marker is missing.");let a=e.get("IHDR"),i=Hl(a).getUint32(0),o=Hl(a).getUint32(4),l=a[8],s=a[9],u=Kl[s],c=a[12],f=e.get("PLTE");3===s&&!f&&zl("A palette PNG requires a PLTE chunk.");let h=await er(e,s);if(n&&h.colorEncoding&&Fi(h)[0]===h)throw Vr("JXL_UNSUPPORTED","fit and variants need a named color space; this PNG sets gamma, primaries or intent. Use encode.");let d=c?Yl:[[0,0,1,1]],m=u*l,p=0;for(let[e,t,r,n]of d){let a=Math.max(0,Math.ceil((i-e)/r)),l=Math.max(0,Math.ceil((o-t)/n));a&&l&&(p+=l*(1+Math.ceil(a*m/8)))}let y=e.get("tRNS"),g=y&&3!==s?Array.from({length:y.length/2},(e,t)=>Hl(y).getUint16(2*t)):null,M=e.get("eXIf"),b=M?zt(M,0,M.length):null;return{width:i,height:o,depth:l,colourType:s,channels:u,interlace:c,expected:p,palette:f??null,paletteAlpha:3===s?y??null:null,transparent:g,colour:h,orientation:b,parts:t}}function ir({width:e,depth:t,colourType:r,channels:n,palette:a,paletteAlpha:i,transparent:o},l,s=0){let u=16===t,c=u?65535:255,f=a?a.length/3:0,h=u||8===t?1:255/((1<<t)-1),d=!u&&8===t&&3!==r&&!o;return(m,p,y,g,M,b,w)=>{if(d&&1===M){let t=(g+w*b-s)*e*4;return void(4===n?l.set(m.subarray(0,4*p),t):kl(m,p*n,null,null,0,0,0,l,t,p,n))}let v=Hl(m),L=u?e=>v.getUint16(2*e):8===t?e=>m[e]:e=>m[e*t>>3]>>8-t-(e*t&7)&(1<<t)-1;for(let t=0;t<p;t++){let u=4*((g+w*b-s)*e+y+t*M);if(3===r){let e=L(t);e>=f&&zl("A PNG palette index is past its palette."),l[u]=a[3*e],l[u+1]=a[3*e+1],l[u+2]=a[3*e+2],l[u+3]=e<(i?.length??0)?i[e]:255;continue}let d=L(t*n),m=n<3?d:L(t*n+1),p=n<3?d:L(t*n+2);l[u]=d*h,l[u+1]=m*h,l[u+2]=p*h,l[u+3]=4===r||6===r?L(t*n+n-1):o&&d===o[0]&&(0===r||m===o[1]&&p===o[2])?0:c}}}function or({width:e,height:t,depth:r,channels:n,interlace:a}){let i=n*r;return(a?Yl:[[0,0,1,1]]).map(([r,n,a,o])=>{let l=Math.max(0,Math.ceil((e-r)/a));return[r,n,a,o,l,Math.max(0,Math.ceil((t-n)/o)),Math.ceil(l*i/8)]}).filter(e=>e[4]&&e[5])}function lr(e,t=!1){if("exact"===e)return!0;if(!e||"object"!=typeof e||Array.isArray(e))return!1;let r=Object.keys(e);if(1!==r.length)return!1;let n=r[0],a=e[n];return"quality"===n?!!es(a)||!!(t&&a&&"object"==typeof a&&!Array.isArray(a)&&2===Object.keys(a).length&&Object.hasOwn(a,"min")&&Object.hasOwn(a,"max")&&es(a.min)&&es(a.max)&&a.min<=a.max):"maxError"===n?Zl(a)&&a>=0:"ssimulacra2"===n&&Zl(a)&&a<=100}function sr(e){if("predicted"===e?.domain)return"ssimulacra2"===e.metric&&Number.isFinite(e.floor)&&void 0===e.score&&void 0===e.limit&&void 0===e.region&&(void 0===e.view||"pu21"===e.view||"without-noise"===e.view);if(!(e&&["ssimulacra2","max-error"].includes(e.metric)&&Number.isFinite(e.score)&&["encoder-reconstruction","decoded-output","predicted"].includes(e.domain)&&(void 0===e.floor||Number.isFinite(e.floor)&&"ssimulacra2"===e.metric)&&(void 0===e.limit||Number.isFinite(e.limit)&&"ssimulacra2"!==e.metric))||void 0!==e.view&&"pu21"!==e.view&&"without-noise"!==e.view)return!1;let t=e.region;return void 0===t||t&&Number.isSafeInteger(t.x)&&t.x>=0&&Number.isSafeInteger(t.y)&&t.y>=0&&Ql(t.width)&&Ql(t.height)}function ur(e){return!(!e||"object"!=typeof e||!Number.isSafeInteger(e.width)||e.width<1||!Number.isSafeInteger(e.height)||e.height<1||!["jxl","jpeg","png"].includes(e.format)||null!==e.source&&(!["bytes","pixels"].includes(e.source?.kind)||!ql(e.source.digest))||"boolean"!=typeof e.meetsTarget||!lr(e.fidelity,null===e.bytes)||!Array.isArray(e.measurements)||!e.measurements.every(sr)||void 0!==e.transform&&(!Ql(e.transform?.width)||!Ql(e.transform?.height)||void 0!==e.transform.frame&&(!Number.isSafeInteger(e.transform.frame)||e.transform.frame<0)||void 0!==e.transform.resizer&&"browser"!==e.transform.resizer||void 0!==e.transform.via&&("browser"!==e.transform.resizer||!Array.isArray(e.transform.via)||!e.transform.via.length||!e.transform.via.every(e=>Ql(e?.width)&&Ql(e?.height))))||void 0!==e.readAs&&!["srgb","display-p3"].includes(e.readAs)||void 0!==e.timing&&!["exact","rounded"].includes(e.timing)||void 0!==e.usedWebGPU&&"boolean"!=typeof e.usedWebGPU||void 0!==e.originalBytes&&!Ql(e.originalBytes)||void 0===e.originalBytes&&void 0!==e.largerThanOriginal)&&(null===e.bytes?null===e.kept&&!1===e.meetsTarget&&void 0===e.largerThanOriginal&&$l(e.reason)&&"JXL_TARGET"===e.reason.code:!("[object Uint8Array]"!==Object.prototype.toString.call(e.bytes)||!e.bytes.byteLength||!["jpeg-bytes","pixels","lossy"].includes(e.kept)||void 0!==e.originalBytes&&e.largerThanOriginal!==e.bytes.byteLength>e.originalBytes||!e.meetsTarget&&!$l(e.reason)||e.meetsTarget&&void 0!==e.reason))}function cr(e){if(!ur(e))return!1;if(e.meetsTarget){let t=e.fidelity;if(("exact"===t||100===t?.quality||0===t?.maxError)&&"lossy"===e.kept)return!1;for(let t of e.measurements)if(void 0!==t.floor&&t.score<t.floor||void 0!==t.limit&&t.score>t.limit)return!1;if("lossy"===e.kept&&t&&"object"==typeof t)for(let r of["ssimulacra2"]){if("number"!=typeof t[r])continue;let n=e.measurements.find(e=>e.metric===r&&void 0===e.region);if(!n||("ssimulacra2"===r?n.score<t[r]:n.score>t[r]))return!1}}return!0}function fr({width:e,height:t,orientation:r,orientationAt:n,orientationBig:a},i){if(void 0===e||void 0===t)throw fn("JXL_JPEG","JPEG dimensions are missing; pass a valid JPEG file.");return h(e,t,i),{width:e,height:t,orientation:r??1,orientationAt:n,orientationBig:a}}function*hr(e,t,r){let n=yield*z("jpeg-geometry",function*(){let r={at:0,phase:"signature",width:void 0,height:void 0,orientation:null,done:!1};for(;!r.done;){let t=yield*K("jpeg-geometry-window",()=>dr(e,r));t!==Ga&&(r=t)}return fr(r,t)});return r?.({...n}),ts(n)}function dr(e,t){let r={...t},n=r.at,a=e.length,i=Math.min(a,n+131072),o=e.subarray(n,Math.min(a,i+65540)),l=e=>o[e-n],s=()=>"marker-code"===r.phase||"entropy-code"===r.phase;if("signature"===r.phase){if(255!==l(0)||216!==l(1))throw fn("JXL_JPEG","Input is not a JPEG; pass a valid JPEG file.");r.at=2,r.phase="marker"}for(;!r.done&&(r.at<i||r.at>=a&&s());){if("entropy"===r.phase){for(;r.at<i&&255!==l(r.at);)r.at++;r.at<i&&(r.at++,r.phase="entropy-code");continue}if("marker"===r.phase){if(255!==l(r.at++))throw fn("JXL_JPEG","Invalid JPEG marker; pass a valid JPEG file.");r.phase="marker-code"}for(;r.at<i&&255===l(r.at);)r.at++;if(r.at>=i&&r.at<a)break;if("entropy-code"===r.phase){let e=l(r.at);if(0===e||e>=208&&e<=215){r.at++,r.phase="entropy";continue}r.phase="marker-code"}let e=l(r.at++);if(217===e){r.done=!0;break}if(r.phase="marker",1===e||e>=208&&e<=215)continue;let t=256*l(r.at)+l(r.at+1),s=r.at+t,u=r.at+2;if(!Number.isInteger(t)||t<2||s>a)throw fn("JXL_JPEG","JPEG segment is incomplete; pass a valid JPEG file.");if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(e)){if(t<8)throw fn("JXL_JPEG","JPEG dimensions are incomplete; pass a valid JPEG file.");if(r.height=256*l(u+1)+l(u+2),r.width=256*l(u+3)+l(u+4),!r.width||!r.height)throw fn("JXL_JPEG","JPEG defers its height to a scan marker; decode it with a host reader and pass its pixels.")}225===e&&null===r.orientation&&s-u>=6&&[69,120,105,102,0].every((e,t)=>l(u+t)===e)&&(r.orientation=zt(o,u+6-n,s-n,(e,t)=>{r.orientationAt=n+e,r.orientationBig=t})),r.at=s,218===e&&(r.phase="entropy")}return r.at>=a&&!s()&&(r.done=!0),r}async function mr(e,t,r,n,a,i="binary64"){let o="libjxl"===i?"verify-score-libjxl-":"verify-score-";return(await a.unit(o+"result",()=>pr(e,t,r,n,a,i,o))).value}async function pr(e,t,r,n,a,i,o){let{unit:l,tools:s}=a,u=e.width,c=e.height,f=!0,h=rs(u);for(let r=0;r<c;r+=h){let n=Math.min(h,c-r),a=f,{value:i}=await l(o+"alpha",()=>a&&[e,t].every(e=>(e.data.ahead?.(r*u*4,(r+n)*u*4),s.opaque(e.data.subarray(r*u*4,(r+n)*u*4)))),{carry:!0});i!==Ga&&(f=i)}if(f)return yr(e,t,r,n,a,i,o,null);let d=1/0;for(let l of[255,0])d=Math.min(d,await yr(e,t,r,n,a,i,o+"over-"+l+"-",l));return d}async function yr(e,t,r,n,{journal:a,unit:i,tools:o},l,s,u){let c="libjxl"===l,{scaleBand:f,bandState:h,downsample:d,referenceArena:m,useReferenceArena:p,releaseReferenceArena:y,GAUSS32:g,scaleNorm:M,scoreNorms:b,s2Pad:w,compileKernels:v,metricSamples:L,composedOver:I}=o;await v();let A=e.width,x=e.height,N=(a,i)=>{if(!i)return[{rgba:new Uint8Array(0)},{rgba:new Uint8Array(0)}];let o=Math.min(a,x-1),l=Math.min(i,x-o);for(let r of[e,t])r.data.ahead?.(o*A*4,(o+l)*A*4);let s=$([e,t].map(e=>()=>({...e,width:A,height:l,data:e.data.subarray(o*A*4,(o+l)*A*4)})));return L(...null===u?s:s.map(e=>I(e,u)),r,n).map(e=>A<8||x<8?w(e,A,l):e)},O=Math.max(8,A),P=Math.max(8,x),E=[],T=m([]);try{for(let e=0;e<6;e++){let t=rs(O,4),r=null;for(let n=-4;n<P;n+=t){let a=Math.min(P,n+t),o=Math.min(P,4*Math.ceil((n+4)/4)),l=Math.min(P,4*Math.ceil((a+4)/4)),{value:u}=await i(s+"row-"+e,()=>{r&&$a([r.states,r.sums]);let e=r?Math.max(0,o-12):o,[t,i]=N(e,l-e),s=p(T);try{let o=f(t,i,O,P,g,n,a,r,r?e:null,c);return a===P?{sums:o.sums}:h(o,O)}finally{s()}},{carry:!0});u!==Ga&&(r=u)}let n={ssim:new Float64Array(6),edge:new Float64Array(12)};for(let e=0;e<3;e++)M(n,e,r.sums.subarray(6*e,6*e+6),O*P);if(E.push(n),5===e||O<8||P<8)break;let o=[[],[],[]],l=[[],[],[]];for(let r=0;r<P;r+=t){let n=Math.min(t,P-r),{value:a}=await i(s+"pyramid-"+e,()=>{let[e,t]=N(r,n),a=p(T);try{return[ns(d(e,O,n).planes),ns(d(t,O,n).planes)]}finally{a()}},{cold:!0,alone:!0});for(let e=0;e<3;e++)o[e].push(a[0][e]),l[e].push(a[1][e])}O=Math.ceil(O/2),P=Math.ceil(P/2);let u=as(o.map(e=>ne(e,a.touched)),O),m=as(l.map(e=>ne(e,a.touched)),O);N=(e,t)=>$([()=>u(e,t),()=>m(e,t)])}return b(E).score}finally{y(T)}}async function gr(e,{journal:t,unit:r,tools:n}){let{prepareKernels:a,ensureKernels:i,orientBlock:o,wasmRequired:l}=n,{orientation:s=1,width:u,height:c,data:f,...h}=e;if(!Number.isInteger(s)||s<1||s>8)throw fn("JXL_INPUT","Invalid orientation; use an integer from 1 through 8.");if(1===s)return{data:f,width:u,height:c,...h};if(void 0!==h.extraChannels)throw fn("JXL_UNSUPPORTED","Extra channels cannot use this orientation transform; supply already oriented samples.");if(!await a()||!i())throw l();let d=f.constructor,m=d.BYTES_PER_ELEMENT,p={subarray:(e,t)=>{let r=f.subarray(e/m,t/m);return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}},y=new Proxy(new Uint8Array(0),{get:(e,t)=>"subarray"===t?p.subarray:void 0}),g=s>=5,M=g?c:u,b=g?u:c,w=[];for(let e=0;e<b;e+=256){let t=[];for(let n=0;n<M;n+=256){let a=Math.min(256,M-n),i=Math.min(256,b-e),{value:l}=await r("verify-orient-block",()=>{let t=g?s>=7?u-e-i:e:2===s||3===s?u-n-a:n,r=g?6===s||7===s?c-n-a:n:3===s||4===s?c-e-i:e,l=new Uint8Array(a*i*4*m);return o(y,l,u,a,t,r,g?i:a,g?a:i,0,0,4*m,s),l},{cold:!0,alone:!0});t.push(l)}w.push(t)}return{...h,width:M,height:b,data:We(re(w,M*m,b,256,256*m,t.touched),d)}}async function Mr(e,t,r,n,{journal:a,unit:i,tools:o}){let{prepareKernels:l,ensureKernels:s,sampleBands:u,wasmRequired:c,sampleResizeConfig:f,sampleResizeStep:d}=o;if(h(t,r,n.maxPixels),t===e.width&&r===e.height)return e;if(!await l()||!s())throw c();let m=e.data.constructor,p=m.BYTES_PER_ELEMENT,{value:y}=await i("verify-resize-config",()=>f({...e,data:new m(0)},n)),{config:g,table:M,levels:b}=y,w=Math.max(1,Math.min(64,Math.floor(262144/Math.max(t,e.width)))),v=u(e.width,e.height,t,r,g,M,b,p),L=n=>{let a=new m(Math.min(w,v.outRows)*t*4),{state:i,written:o}=d(v,e.data,e.height,r,n,a,0,Math.min(w,v.outRows));return{bytes:new Uint8Array(a.buffer,0,o*t*4*p),state:i}},I={y:0,row:null,sum:null},A=[];do{let e,{value:t}=await i("verify-resize-rows",()=>(e=L(I)).bytes,{cold:!0,alone:!0});A.push(t);let{value:r}=await i("verify-resize-state",()=>(e??=L(I)).state,{carry:!0,tail:!0});r!==Ga&&(I=r)}while(I.y<r);return{...e,width:t,height:r,data:We(ne(A,a.touched),m)}}function br(e,t=Blob){let r=[];for(let t=0;t<e.length;t+=ls)r.push(()=>e.subarray(t,Math.min(e.length,t+ls)));return new t($(r))}async function wr(e,t,{journal:r},n=!1){let a=e.subarray(0,Math.min(e.length,32));if(![137,80,78,71,13,10,26,10].every((e,t)=>a[t]===e))return null;if(a.length<24)throw fn("JXL_INPUT","Incomplete PNG header; pass the complete PNG file.");let i=new DataView(a.buffer,a.byteOffset,a.byteLength);h(i.getUint32(16),i.getUint32(20),t.maxPixels),await rr();let o=Object.assign(e=>r(e.cold?{...e,borrowed:!0}:e),r);return r.tools.pngPixels(o,e,{readAs:t.readAs,deep:!0,orient:!0,metadata:n,reader:{pngWalk:Zt,pngLayout:ar,pngRows:ir,pngPassRows:or,pngOrientationLocation:nr,unfilterRow:tr}})}async function vr(e,t,r,n){let{journal:a,unit:i}=n,{nativeBitmap:o,requirePNGReader:l}=n.tools,s=e.subarray(0,Math.min(e.length,32)),u=t;255===s[0]&&216===s[1]?await Ar(hr(e,r.maxPixels,e=>{u=e}),a):[137,80,78,71,13,10,26,10].every((e,t)=>s[t]===e)?(16===s[24]&&l({readAs:r.readAs}),u=await wr(e,r,n,!0)):hs(s)&&(u=fs(await Ar(vt(e),a)));let{width:c,height:f,orientation:d=1,orientationAt:m,orientationBig:p,exifAt:y,exifLength:g}=u;h(c,f,r.maxPixels);let M,b,w=()=>{let t=br(e);if(!(d>1))return t;let r=Uint8Array.of(p?0:1,p?1:0);if(void 0!==y){let n=e.subarray(y-4,y+g).slice();n.set(r,m-y+4);let a=new Uint8Array(4);return new DataView(a.buffer).setUint32(0,qt(n)),new Blob([t.slice(0,y-4),n,a,t.slice(y+g+4)])}return new Blob([t.slice(0,m),r,t.slice(m+2)])},v=[];for(let e=0;e<f;e+=os){let t=[];for(let n=0;n<c;n+=os){let a=Math.min(os,c-n),l=Math.min(os,f-e),{value:s}=await i("verify-native-group",async()=>{M??=w();let t=await o(M,r,{maxPixels:r.maxPixels,signal:r.signal},{region:{x:n,y:e,width:a,height:l},platform:()=>"Pass RGBA pixels, or a PNG; for a JPEG use recompress from rapier-jxl/jpeg."});if(t.width!==a||t.height!==l)throw fn("JXL_PLATFORM","Image decoder returned the wrong crop size; configure a decoder that preserves dimensions.");return{data:new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.byteLength),colorSpace:t.colorSpace}},{cold:!0,alone:!0});b??={colorSpace:s.colorSpace},t.push(s.data)}v.push(t)}return gr({...b,width:c,height:f,data:re(v,c,f,os,os,a.touched),...d>1&&{orientation:d}},n)}async function Lr(e,t){let r=qn(),n=ds(t);for(let t=0;t<e.length;t+=ls){let{value:a}=await n("output-hash",()=>I(r,e.subarray(t,Math.min(e.length,t+ls))),{carry:!0});a!==Ga&&(r=a)}return"sha256:"+A(r)}function Ir(e,t){return Object.freeze({id:"verify",eager:!1,normalize(e,t){let r=c(e),n=Object.keys(r).find(e=>!["result","parts","maxPixels"].includes(e));if(n)throw fn("JXL_OPTIONS",`Unknown verification field: ${n}; use result, parts or maxPixels.`);let a=c(r.result,"Stored result");if(Object.hasOwn(a,"bytes")||Object.hasOwn(a,"verification")||!cr({...a,bytes:Uint8Array.of(0)}))throw fn("JXL_INPUT","Stored verification metadata is invalid; pass the encode result without bytes or a verification receipt.");let i=void 0===r.maxPixels&&"jpeg-bytes"===a.kept?Dr:d(r.maxPixels);h(a.width,a.height,i);let o=t.kind??"pixels";if("pixels"===o){if(h(t.width,t.height,i),t.byteLength!==t.width*t.height*4)throw fn("JXL_INPUT","Pixels need width * height * 4 RGBA8 bytes; pass kind: 'file' for a PNG or JPEG.")}else if("file"!==o)throw fn("JXL_INPUT","Invalid verification source kind; use pixels or file.");if(!Array.isArray(r.parts)||!r.parts.length||r.parts.some(e=>!Ia(e).length)||r.parts.reduce((e,t)=>e+t.length,0)>4294967295)throw fn("JXL_INPUT","Stored candidate has invalid parts; pass a nonempty ordered list of immutable byte parts.");return{options:{...r},maxPixels:i}},async run(t,r,n,a){let i=ds(a),o=[];for(let e of t.options.parts){let{value:t}=await i("verify-candidate-part",()=>a.part(e),{cold:!0,alone:!0});o.push(t)}let l=a.join(o),s={...t.options.result,bytes:l},u="file"===(n.kind??"pixels")?r:{data:r,width:n.width,height:n.height,...n.colorSpace&&{colorSpace:n.colorSpace}},c=await e(u,s,{journal:a,source:n,sourceIdentity:await it(n),outputDigest:await Lr(l,a),pixelResult:Tr,restored:xr,maxPixels:t.maxPixels});return{bytes:new Uint8Array(0),facts:c}},...t&&{async straight(e,r,n,a,i,o){let l=[];for(let t of e.options.parts)l.push(await i(t));let s=new Uint8Array(l.reduce((e,t)=>e+t.length,0)),u=0;for(let e of l)s.set(e,u),u+=e.length;let c="file"===(n.kind??"pixels")?r:{data:r,width:n.width,height:n.height,...n.colorSpace&&{colorSpace:n.colorSpace}},f=await t(c,{...e.options.result,bytes:s},{signal:a,maxPixels:e.maxPixels,...o&&Vn in o&&{[Vn]:o[Vn]}});return{bytes:new Uint8Array(0),facts:f}}},record(e,t,r,n){if(e.length||!0!==n?.verified)throw fn("JXL_INPUT","Verification job has no completed receipt; finish advancing it before reading its result.");return n}})}async function Ar(e,t){let r,n=!1;try{for(;;){let n=W(e,r,t);if(n.done)return n.value;r=ka(n.value)?await t(n.value):void 0}}catch(e){throw n=!0,e}finally{try{e.return?.()}catch(e){if(!n)throw e}}}async function xr(e,t,r,n){let a=n.restoreSteps??dl(n);if(!a?.open||!a?.normalize)throw fn("JXL_PLATFORM","JPEG verification has no restoration function; configureDecoder with restore from rapier-jxl/jpeg.");let i=Math.min(r.maxPixels,Dr),o=a.normalize({maxPixels:i}),l=await Ar(a.open(o,e),n.journal),s=ds(n.journal),u={hash:qn(),equal:l.bytes.length===t.length};for(let e=0;e<l.bytes.length;e+=ls){let r=Math.min(l.bytes.length,e+ls),{value:n}=await s("verify-restored-bytes",()=>{let[n,a]=$([()=>l.bytes.subarray(e,r),()=>t.subarray(e,Math.min(t.length,r))]);return{hash:I(u.hash,n),equal:u.equal&&n.length===a.length&&n.every((e,t)=>e===a[t])}},{carry:!0});n!==Ga&&(u=n)}return{size:"jpeg"===r.format?u.equal?l.facts:await Ar(hr(t,r.maxPixels),n.journal):fs(await Ar(vt(e),n.journal)),equal:u.equal,digest:"sha256:"+A(u.hash)}}async function Nr(e,t,{journal:r,unit:n,tools:a},i=!1,o=!1,l=!1){let{nativePictureWith:s,NATIVE_PICTURE_OPTIONS:c}=a,f=await Ar(vt(e),r);if(h(f.width,f.height,t.maxPixels),f.animation)throw fn("JXL_UNSUPPORTED","Resumable verification cannot read an animation; verify the complete result with verify().");let{value:d}=await n("verify-decode-reader",()=>!i&&jt(f,cs(t),!0)),m=()=>Or(e,f,t,n,o&&!d?a:null,l?ys:Xt),p=d?null:await Ar(kt(e,cs(t)),r),y=d?os:p.group;if(![128,256,512,1024].includes(y))throw fn("JXL_DECODE","Decoder returned an invalid group size; configure a decoder that returns complete JPEG XL groups.");let g,M=null,b=async(r,n,a,i)=>{let o;try{o=d?St(f,await s(e.subarray(0,Math.min(e.length,32)),{width:a,height:i,colorSpace:f.colorEncoding.primaries,maxPixels:t.maxPixels,signal:t.signal},(t,o)=>(g??=br(e,o),()=>t.call(globalThis,g,r,n,a,i,c))),d):await _t(e,{...cs(t),region:{x:r,y:n,width:a,height:i},maxTotalSamples:Math.max(1048576,7077888)},p,l)}catch(e){if(!d&&!0===e?.[is])return{whole:!0};throw e}if(![Uint8Array,Uint8ClampedArray,Uint16Array,Float32Array].some(e=>o.data instanceof e)||o.width!==a||o.height!==i)throw fn("JXL_UNSUPPORTED","Decoder returned incomplete sample groups; configure a decoder that returns complete typed RGBA groups.");return{type:o.data instanceof Uint16Array?"Uint16Array":o.data instanceof Float32Array?"Float32Array":"Uint8Array",data:new Uint8Array(o.data.buffer,o.data.byteOffset,o.data.byteLength),description:Object.fromEntries(us.filter(e=>void 0!==o[e]).map(e=>[e,"extraChannels"===e?o[e].map(({data:e,plane:t,...r})=>r):o[e]]))}},{value:w}=await n("verify-decode-description",async()=>{let e=await b(0,0,Math.min(y,f.width),Math.min(y,f.height));return e.whole?e:(M=e.data,{type:e.type,description:e.description})});if(w.whole)return m();let v=w.description,L={Uint8Array,Uint16Array,Float32Array}[w.type],I=[],A=L.BYTES_PER_ELEMENT,x=!o||d||!a.nativeGammaRGBA||"Uint8Array"!==w.type||8!==v.bitDepth||"uint"!==v.sampleFormat||"srgb"!==v.colorSpace||"srgb"!==v.transferFunction||1!==v.orientation&&!v.orientationApplied||v.animation?null:[],N=async(r,n,i,o)=>{let s;try{s=await _t(e,{...cs(t),colorSpace:"srgb",format:"float32",region:{x:r,y:n,width:i,height:o},maxTotalSamples:Math.max(1048576,7077888)},p,l)}catch(e){if(u(t.signal),"JXL_UNSUPPORTED"===e?.code||Ml(e))return null;throw e}let c=i*o,f=s.data,h=f.length/c;if(!(f instanceof Float32Array)||3!==h&&4!==h)return null;let d=[new Float32Array(c),new Float32Array(c),new Float32Array(c)];for(let e=0,t=0;e<c;e++,t+=h)for(let r=0;r<3;r++)d[r][e]=f[t+r];let m=a.nativeGammaRGBA(d,i,o,{x:r,y:n});for(let e=0;e<c;e++)m[4*e+3]=4===h?Math.round(255*Math.min(1,Math.max(0,f[4*e+3]))):255;return m};for(let e=0;e<f.height;e+=y){let t=Math.min(y,f.height-e),r=Array.from({length:Math.ceil(t/ps)},()=>[]),a=x&&r.map(()=>[]);for(let i=0;i<f.width;i+=y){let o=Math.min(y,f.width-i),l=4*o*A,s=null;for(let a=0;a<r.length;a++){let{value:u}=await n(a?"verify-decode-group-rows":"verify-decode-group",async()=>{if(!s)if(i||e||!M){let r=await b(i,e,o,t);if(r.whole)return r;s=r.data}else s=M;return s.slice(a*ps*l,Math.min(t,(a+1)*ps)*l)},{cold:!0,alone:!0,...a&&{tail:!0}});if(!(u instanceof Uint8Array)&&u.whole)return m();r[a].push(u)}M=null;let u=null;if(x)for(let l=0;l<r.length;l++){let{value:r}=await n(l?"verify-djxl-group-rows":"verify-djxl-group",async()=>(u??=await N(i,e,o,t),u&&u.slice(l*ps*o*4,Math.min(t,(l+1)*ps)*o*4)),{cold:!0,alone:!0,...l&&{tail:!0}});if(null===r){x=null;break}a[l].push(r)}}I.push(...r),x&&x.push(...a)}return{...v,width:f.width,height:f.height,data:We(re(I,f.width*A,f.height,ps,y*A,r.touched),L),...x&&{native:We(re(x,f.width,f.height,ps,y,r.touched),Uint8Array)}}}async function Or(e,t,r,n,a=null,i=Xt){let{value:o}=await n("verify-decode-whole",async()=>{let n=await i(e,cs(r));if(![Uint8Array,Uint8ClampedArray,Uint16Array,Float32Array].some(e=>n.data instanceof e)||n.width!==t.width||n.height!==t.height)throw fn("JXL_UNSUPPORTED","Decoder returned an incomplete picture; configure a decoder that returns complete typed RGBA samples.");return{type:n.data instanceof Uint16Array?"Uint16Array":n.data instanceof Float32Array?"Float32Array":"Uint8Array",data:new Uint8Array(n.data.buffer,n.data.byteOffset,n.data.byteLength),description:Object.fromEntries(us.filter(e=>void 0!==n[e]).map(e=>[e,"extraChannels"===e?n[e].map(({data:e,plane:t,...r})=>r):n[e]]))}},{cold:!0,alone:!0}),l=o.description,s=null;return a?.nativeGammaRGBA&&"Uint8Array"===o.type&&8===l.bitDepth&&"uint"===l.sampleFormat&&"srgb"===l.colorSpace&&"srgb"===l.transferFunction&&(1===l.orientation||l.orientationApplied)&&!l.animation&&({value:s}=await n("verify-djxl-whole",async()=>{let n;try{n=await i(e,{...cs(r),colorSpace:"srgb",format:"float32"})}catch(e){if(u(r.signal),"JXL_UNSUPPORTED"===e?.code||Ml(e))return null;throw e}let o=t.width*t.height,l=n.data,s=l.length/o;if(!(l instanceof Float32Array)||3!==s&&4!==s||n.width!==t.width||n.height!==t.height)return null;let c=[new Float32Array(o),new Float32Array(o),new Float32Array(o)];for(let e=0,t=0;e<o;e++,t+=s)for(let r=0;r<3;r++)c[r][e]=l[t+r];let f=a.nativeGammaRGBA(c,t.width,t.height);for(let e=0;e<o;e++)f[4*e+3]=4===s?Math.round(255*Math.min(1,Math.max(0,l[4*e+3]))):255;return f},{cold:!0,alone:!0})),{...l,width:t.width,height:t.height,data:We(o.data,{Uint8Array,Uint16Array,Float32Array}[o.type]),...s&&{native:We(s,Uint8Array)}}}async function Pr(e,t,r){if(r.reference)return r.reference;let n=e,a=!1;if("file"===(r.source?.kind??"pixels")){let i=e.subarray(0,Math.min(e.length,32));if(hs(i))n=void 0===t.readAs?Et(await Nr(e,t,r)):await vr(e,t.size,t,r);else if(255===i[0]&&216===i[1]&&void 0===t.readAs&&fl(r)){let i=hl(r);if(!i)throw fn("JXL_PLATFORM","JPEG verification has no restoration function; configureDecoder with restore from rapier-jxl/jpeg.");await(i.prepare?.());let o=await Ar(i.open(i.normalize({effort:1,maxPixels:Math.min(t.maxPixels,Dr)}),e),r.journal);n=Et(await Nr(o.bytes,t,r,!0)),a=!0}else n=await wr(e,t,r),a=!!n;if(!n){if(!(255===i[0]&&216===i[1]||[137,80,78,71,13,10,26,10].every((e,t)=>i[t]===e)))throw fn("JXL_UNSUPPORTED","This source cannot be read in resumable verification; verify the complete result with verify().");n=await vr(e,t.size,t,r)}}if((a||t.transform)&&(n=await gr(n,r)),"browser"===t.transform?.resizer)throw fn("JXL_UNSUPPORTED","Browser-resized output cannot use resumable verification; call verify() on its complete result.");return t.transform&&(n=await Mr(n,t.transform.width,t.transform.height,t,r)),n}async function Er(e,t,r,n,a,i,o,l){let s=n.proof.score,{value:u}=await l.unit("verify-noise-flag",()=>wt(e));if(!1===u)return n;if(!ul(o))return!0===u&&a.alphaExact?l.tools.noiseUnread(n):n;let c=yl(o)?await Nr(e,o,l,!0,!0,!0):await Or(e,{width:r.width,height:r.height},o,l.unit,l.tools,ys),f=0,h=await l.tools.pixelEvidence(t,c,i,o,a,(e,t,r,n,a,i)=>mr(e,t,r,n,"libjxl"===i?l:f++?ms(l,"djxl-"):l,i));return{...h,proof:{...h.proof,view:"without-noise",...Number.isFinite(s)&&{decodedScore:s}}}}async function Tr(e,t,{fidelity:r,format:n,size:a,outputDigest:i,details:o,options:l,noiseOff:s=!1},c){let{comparison:f,comparisonContext:h,pictureICC:d,conversionProfile:m,sameBytes:p,pixelEvidence:y,protectionDomain:g,protectionEvidence:M,describedIdentity:b,sampleBytes:w,profileTransformSteps:v}=c.tools,L=ds(c.journal),x={...c,unit:L},N={...l,...c&&Vn in c&&{[Vn]:c[Vn]}},O=await Pr(t,{...N,size:a},ms(x,"reference-")),P=ms(x,"output-"),E="jxl"===n&&"exact"!==r&&!!c.tools.measurementTarget&&"ssimulacra2"===c.tools.measurementTarget(r,l).metric,T="jxl"===n?await Nr(e,N,P,!1,E):await wr(e,{...l,readAs:void 0},P);if(!T)throw fn("JXL_UNSUPPORTED","This output cannot be read in resumable verification; verify the complete result with verify().");l.protection&&g(l.protection,O,T);let U=d(O),S=d(T),j=!!U&&!!S&&U.length===S.length;if(j)for(let e=0;e<U.length;e+=ss){let{value:t}=await L("verify-profile-bytes",()=>{let[t,r]=$([U,S].map(t=>()=>t.subarray(e,Math.min(t.length,e+ss))));return j&&p(t,r)},{carry:!0});t!==Ga&&(j=t)}let J=m(O,T),F=J?await Ar(v(J),c.journal):null,{value:k}=await L("verify-compare-description",()=>h(O,T,F,j)),X=O===t?c.sourceIdentity:null,_={compared:f({...O,data:new O.data.constructor(0)},{...T,data:new T.data.constructor(0)},l.protection,0,k),hash:X?null:qn()},R=rs(O.width);for(let e=0;e<O.height;e+=R){let t=Math.min(R,O.height-e),{value:r}=await L("verify-compare-rows",()=>{for(let r of[O,T])r.data.ahead?.(e*r.width*4,(e+t)*r.width*4);let[r,n]=$([O,T].map(r=>()=>({...r,height:t,data:r.data.subarray(e*r.width*4,(e+t)*r.width*4)}))),a=f(r,n,l.protection,e*O.width,k),i=_.compared;return{compared:{...i,...a,exact:i.exact&&a.exact,alphaExact:i.alphaExact&&a.alphaExact,supported:i.supported&&a.supported,maxError:Math.max(i.maxError,a.maxError),...(i.colorScope||a.colorScope)&&{colourSamples:(i.colourSamples??0)+(a.colourSamples??0),visible:!(!i.visible&&!a.visible)},...l.protection&&{protectedSamples:i.protectedSamples+(a.protectedSamples??0),protectedExact:i.protectedExact&&!0===a.protectedExact}},hash:_.hash&&I(_.hash,w(r.data))}},{carry:!0});r!==Ga&&(_=r)}let B=X??await b(O,{data:"sha256:"+A(_.hash)},new O.data.constructor(0),async e=>{let t=qn();for(let r=0;r<e.length;r+=ss){let{value:n}=await L("verify-reference-icc-hash",()=>I(t,e.subarray(r,Math.min(e.length,r+ss))),{carry:!0});n!==Ga&&(t=n)}return"sha256:"+A(t)}),G=0,C=await y(O,T,r,l,_.compared,(e,t,r,n,a,i)=>mr(e,t,r,n,"libjxl"===i?x:G++?ms(x,"djxl-"):x,i));return s&&"jxl"===n&&"ssimulacra2"===C.proof.metric&&(C=await Er(e,O,T,C,_.compared,r,N,ms(x,"noise-off-"))),C=M(C,_.compared,l),u(l.signal),{...fs(T),kept:C.kept,proof:{...C.proof,outputDigest:i,referenceDigest:B.digest,...o},meetsTarget:C.proof.verified,...C.reason&&{reason:C.reason}}}async function Ur(e,t,r,n,a,i,o){let l=Ls(o?.verify);if(!l)throw fn("JXL_OPTIONS",Is);let s=t instanceof Uint8Array?t:t.bytes,u=t instanceof Uint8Array?null:t.facts,c=await e.record(s,r,a,u),f=await it(a),h=a,d="file"===a.kind||void 0===a.width?n:{data:n,width:a.width,height:a.height,...ki(a)};if("decode"===a.kind){let e=(Array.isArray(c)?c[0]:c)?.source;if(e?.digest&&e.digest!==f.digest){let t=(o&&Vn in o?o[Vn]:Wn())?.restore;if(!t)throw fn("JXL_PLATFORM","Missing JPEG reconstruction reader; call configureDecoder(decode, restore).");let r=await q(i,"verify-decode-original",async()=>(await t(n)).bytes),l=A(I(qn(),r));if("sha256:"+l!==e.digest)throw fn("JXL_INPUT","Stored JPEG XL does not restore its named JPEG; use the matching original and result.");d=r,f={kind:"bytes",digest:e.digest},h={kind:"file",generation:a.generation,sha256:l,byteLength:r.length}}else h={...a,kind:"file"}}let m=t=>q(i,"verify-output",async()=>{let n=t.source?t:{...t,source:f};return l[ws](d,n,{journal:i,source:h,sourceIdentity:f,...o&&Vn in o&&{[Vn]:o[Vn]},outputDigest:await Lr(t.bytes??new Uint8Array(0),i),pixelResult:Tr,restored:xr,maxPixels:r.maxPixels??r.options?.maxPixels,restoreSteps:e.restore??("jpeg:restore"===e.id?e:void 0)})}),p=[];for(let e of Array.isArray(c)?c:[c])p.push(await m(e));return{bytes:s,facts:u,verification:Array.isArray(c)?p:p[0]}}function Sr(e){if("function"!=typeof e)throw fn("JXL_OPTIONS","Invalid operation; pass an imported function such as capture from rapier-jxl/capture.");let t="function"==typeof e?e[Ms]:void 0,r=Object.hasOwn(xs,t?.kind??"")?Ns(t,e):t;if(!r)throw fn("JXL_UNSUPPORTED","This operation has no resumable steps; pass the verb itself, such as capture from rapier-jxl/capture.");let n=bs.get(r);if(!n){let e=A(I(qn(),vs.encode(pn+"\0"+r.id)));n=ge({id:r.id,build:e,normalize:r.normalize,open:r.open,run:r.run,verify:(...e)=>Ur(r,...e),eager:r.eager,tools:Oo,straight:r.straight}),bs.set(r,n)}return{steps:r,stepper:n}}function jr(e){let t=f(e,"store",["readSource","read","readMany","write","writeMany"]);if("function"!=typeof t.readSource||"function"!=typeof t.read||"function"!=typeof t.write&&"function"!=typeof t.writeMany||["readMany","write","writeMany"].some(e=>void 0!==t[e]&&"function"!=typeof t[e]))throw fn("JXL_OPTIONS","Store cannot read and keep parts; provide readSource, read and write or writeMany functions.");let r=async(r,...n)=>{try{return await Reflect.apply(t[r],e,n)}catch(e){throw o(e)}},n=new Map;return{unsaved:n,read:async e=>n.get(e.hash)??await r("read",{hash:e.hash,length:e.length}),readMany:async e=>{let a=e.filter(e=>!n.has(e.hash)),i=a.length?t.readMany?await r("readMany",a.map(e=>({hash:e.hash,length:e.length}))):await Promise.all(a.map(e=>r("read",{hash:e.hash,length:e.length}))):[];if(!Array.isArray(i)||i.length!==a.length)throw fn("JXL_INPUT","Store readMany answered the wrong number of parts; return one entry for each reference asked.");let o=0;return e.map(e=>n.get(e.hash)??i[o++])},readSource:(e,t)=>r("readSource",e,t),write:(e,t)=>r("write",e,t),...t.writeMany&&{writeMany:e=>r("writeMany",e)}}}async function Jr(e){let t=[...e.unsaved].map(([e,t])=>({ref:{hash:e,length:t.length},bytes:t}));if(t.length){if(e.writeMany)await e.writeMany(t);else for(let{ref:r,bytes:n}of t)await e.write(r,n);e.unsaved.clear()}}function Fr(e,t,r){if(e=f(e,`${t} options`),r)for(let n of Object.keys(e))if(!r.includes(n))throw fn("JXL_OPTIONS",`Unknown ${t} option ${n}; remove it.`);return e}async function kr(e){let t=Wn();try{let{operation:r,input:n,options:a={},store:i,verify:o,memoryBytes:l}=Fr(e,"start",["operation","input","options","store","verify","memoryBytes"]);if(void 0!==o&&!Ls(o))throw fn("JXL_OPTIONS","Invalid verifier; import verify from rapier-jxl/verify.");let{steps:s,stepper:u}=Sr(r),c=jr(i);if("verify"===s.id&&o)throw fn("JXL_OPTIONS","A verify operation already returns its receipt; remove the extra verify option.");if(o&&!pl({[Vn]:t}))throw fn("JXL_PLATFORM",gl);let f=Gr(s,c,l),{checkpoint:h,parts:d}=await u.start({source:n,options:a,verify:!!o,admit:f});if("decode"===h.source.kind&&!t?.decode)throw fn("JXL_PLATFORM","Source has no decoder; call configureDecoder(decode) with decode from rapier-jxl/decode.");let m=a.fidelity;if("file"===h.source.kind&&/^(encode|fit|variants):/.test(s.id)&&"exact"!==m&&100!==m?.quality&&("function"!=typeof createImageBitmap||"function"!=typeof OffscreenCanvas)){let e=await c.readSource(0,Math.min(2,h.source.byteLength));if(255===e?.[0]&&216===e[1])throw fn("JXL_PLATFORM","Host cannot read this JPEG; use recompress() from jpegxl/jpeg or pass RGBA8 pixels.")}return Os(c,d),await Jr(c),h}catch(e){throw l(e)}}async function Xr(e,t){let r=Wn();try{let{operation:n,input:a,store:i,verify:o,budget:l={ms:30},signal:c,memoryBytes:f}=Fr(t,"advance",["operation","input","options","store","verify","budget","signal","memoryBytes"]);if(e=j(T(e)),s(c),null===l||"object"!=typeof l||Array.isArray(l))throw fn("JXL_OPTIONS","Invalid budget; pass {ms} with a value from 1 to 60000.");let{ms:h,reads:d}=Fr(l,"budget",["ms","reads"]);if(!Number.isFinite(h)||h<=0||h>6e4)throw fn("JXL_OPTIONS","Invalid budget; pass {ms} with a value from 1 to 60000.");if(void 0!==d&&(!Number.isSafeInteger(d)||d<1||d>1e6))throw fn("JXL_OPTIONS","Invalid budget.reads; pass a positive whole number.");let{steps:m,stepper:p}=Sr(n),y=jr(i),g=performance.now(),M=Gr(m,y,f);if(u(c),e?.plan?.verify&&!Ls(o))throw fn("JXL_OPTIONS",Is);let b=e?.plan?.options,w=e?.source,v=(e,t)=>!!e&&t>=1.25*e.ms,L=Br(m,b,1,1,!0,w?.kind,f),I=L.admitted&&v(L.measured,.7*h)&&((e,t)=>{let r="file"===w?.kind||"decode"===w?.kind?Cr(e):{width:w?.width,height:w?.height},n=r&&Br(m,b,r.width,r.height,!0,w?.kind,f);return!!n?.admitted&&v(n.measured,t)}),A=async(e,t,r)=>{await(Gr(m,{readSource:r},f)?.(e,t)),await(m.prepare?.()),u(c)},x=await p.advance(e,Ps(e,a,y,{signal:c,verify:o,admit:M,prepare:A,[Vn]:r,deadline:g+.7*h,...I&&{straight:I},...d&&{reads:d},...void 0!==f&&{memoryBytes:f}}),{units:64});return Os(y,x.parts),await Jr(y),{checkpoint:x.checkpoint,done:x.done,released:x.released}}catch(e){throw l(e)}}async function _r(e,t){try{let{operation:r,input:n,store:a,signal:i,memoryBytes:o}=Fr(t,"finish",["operation","input","options","store","verify","budget","signal","memoryBytes"]);e=j(T(e)),s(i),u(i);let{steps:l,stepper:c}=Sr(r),f=jr(a),h=Ps(e,n,f,{signal:i,admit:Gr(l,f,o),...void 0!==o&&{memoryBytes:o}}),{byteLength:d,result:m}=await c.completion(e,h);if(void 0!==o&&d+Es>o)throw fn("JXL_MEMORY",`Finished file needs ${d} bytes, above memoryBytes ${o}; raise that allowance or keep its output parts in storage.`);let p=await c.output(e,h,e=>{if(e!==d)throw fn("JXL_INPUT","Saved output parts are incomplete; read every saved part before finishing the job.");try{return new Uint8Array(e)}catch{throw fn("JXL_MEMORY","This runtime cannot allocate the finished file; keep its output parts in persistent storage.")}});u(i);let y=await l.record(p,e.plan,e.source,m?.facts??null),g=await it(e.source),M=(t,r=0)=>{let n=t.source?t:{...t,source:g};if(!e.plan.verify)return n;let a=Array.isArray(y)?m?.verification?.[r]:m?.verification;if(!a?.verified||a.source?.kind!==n.source?.kind||a.source?.digest!==n.source?.digest||a.width!==n.width||a.height!==n.height||a.format!==n.format)throw fn("JXL_INPUT","Verification does not describe its result; verify the matching original and result again.");return{...n,verification:a}};return Array.isArray(y)?y.map(M):M(y)}catch(e){throw l(e)}}function Rr(e){try{let{operation:t,options:r={},width:n,height:a,kind:i}=Fr(e,"workerAdmission",["operation","options","width","height","kind"]),{steps:o}=Sr(t);if(void 0!==i&&"pixels"!==i&&"file"!==i&&"decode"!==i)throw fn("JXL_OPTIONS","Invalid source kind; use 'pixels', 'file', or 'decode'.");if("verify"!==o.id&&o.normalize?.(r,{kind:i??"pixels",width:1,height:1,byteLength:4}),!Number.isSafeInteger(n)||!Number.isSafeInteger(a)||n<1||a<1)throw fn("JXL_OPTIONS","Invalid worker dimensions; pass width and height in whole pixels.");return Br(o,r,n,a,!1,i)}catch(e){throw l(e)}}function Br(e,t,r,n,a=!1,i,o){if(!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<1||n<1)return{admitted:!1,measured:null};let l=t?.fidelity,s="exact"===l||100===l?.quality,u="encode:rapier-jxl/upload"===e.id||"fit:rapier-jxl/upload"===e.id,c=u||"encode:rapier-jxl"===e.id||"fit:rapier-jxl"===e.id?`${e.id} ${s?"exact":"lossy"}`:"verify"===e.id?"verify "+("jpeg-bytes"===t?.result?.kept?"jpeg":"pixels"):e.id,f=gs["decode"===i?c+" decode":c],h=f?.any??f?.[t?.effort??(u?3:7)]??[],d=r*n;for(let e of h){let[t]=e,[r,n,i]=a?e.slice(3):e.slice(1),l=void 0===o?n:1.1*r+Es<=o;if(void 0===r)return{admitted:!1,measured:null};if(!l||t>=d)return{admitted:!!l,measured:{pixels:t,estimate:r,...a&&{ms:i??1/0}}}}return{admitted:!1,measured:null}}function Gr(e,t,r){if(void 0!==r){if(!Number.isSafeInteger(r)||r<1)throw fn("JXL_OPTIONS","Invalid memoryBytes; use a positive safe integer byte count.");return async(n,a)=>{let i,o="file"===a.kind||"decode"===a.kind?null:{width:a.width,height:a.height};if(!o){let e=Math.min(a.byteLength,Ts),r=De(await t.readSource(0,e));if(r.length!==e)throw fn("JXL_INPUT","Source header is missing or truncated; pass a complete original file.");o=Cr(r),i=o?.jpeg420?"jpeg420":r.length>=29&&137===r[0]&&80===r[1]&&8===r[24]?"png8":void 0}let l=o?`${o.width}x${o.height} (${o.width*o.height} pixels)`:"a picture with dimensions beyond its first 65536 bytes",s=!n.verify&&"file"===a.kind&&("jpeg:recompress"===e.id?"jpeg420"===i:/^(encode|fit):rapier-jxl(?:\/upload)?$/.test(e.id)&&"png8"===i)&&o&&Br(e,n.options??n,o.width,o.height,!1,a.kind,r);if(!s?.admitted)throw fn("JXL_MEMORY",`${l} cannot be admitted within memoryBytes ${r}: `+(s?.measured?`the admission row at ${s.measured.pixels} pixels needs ${Math.ceil(1.1*s.measured.estimate+Es)} bytes including host allowance.`:"no measured working-set bound covers this operation, source representation and verification choice."))}}}function Cr(e){let t=t=>e[t]<<8|e[t+1],r=e=>65536*t(e)+t(e+2);if(e.length>=24&&2303741511===r(0)&&218765834===r(4)&&1229472850===r(12))return{width:r(16),height:r(20)};if(255===e[0]&&216===e[1]){for(let r=2;r+9<=e.length;){if(255!==e[r])return null;let n=e[r+1];if(255!==n){if(n>=192&&n<=207&&196!==n&&200!==n&&204!==n)return{width:t(r+7),height:t(r+5),jpeg420:192===n&&r+19<=e.length&&17===t(r+2)&&8===e[r+4]&&3===e[r+9]&&34===e[r+11]&&17===e[r+14]&&17===e[r+17]};if(217===n||218===n)return null;r+=2+t(r+2)}else r++}return null}if(255!==e[0]||10!==e[1])for(let t=0;t+8<=e.length;){let n=r(t),a=t+8,i=r(t+4);if(1===n){if(t+16>e.length)return null;n=4294967296*r(t+8)+r(t+12),a+=8}if(1786276963===i)return Ee(e.subarray(a));if(1786276976===i)return Ee(e.subarray(a+4));if(!n||n<a-t)return null;t+=n}return Ee(e)}var Dr=Number.MAX_SAFE_INTEGER,Wr=Object.freeze({pixels:Dr,edge:1073741824}),Vr=(e,t)=>Object.assign(new Error(t),{code:e}),Kr=()=>"function"==typeof DOMException?new DOMException("The operation was aborted.","AbortError"):Object.assign(new Error("The operation was aborted."),{name:"AbortError"}),zr=e=>{let t;try{t=e?.reason}catch(e){t=e}return void 0===t?Kr():t},Hr=/allocation failed|out of memory|(?:cannot|could not) allocate|failed to grow|maximum memory size|declared maximum|allocation size overflow|invalid string length/i,Yr=e=>{try{return(e instanceof RangeError||"RangeError"===e?.name||"InternalError"===e?.name)&&!e.code&&Hr.test(String(e.message))}catch{return!1}},qr=e=>e?.message?` (${String(e.message)})`:"",$r=["isContextLost","getParameter","createTexture","createFramebuffer","bindTexture","bindFramebuffer","pixelStorei","texImage2D","framebufferTexture2D","checkFramebufferStatus","readPixels","getError","deleteTexture","deleteFramebuffer"],Qr=(e,t)=>Object.assign(Vr("JXL_PLATFORM",e),{cause:t}),Zr={colorSpaceConversion:"none",premultiplyAlpha:"none",imageOrientation:"from-image"},en=(e,t)=>e.call(globalThis,t,Zr),tn=e=>r=>(n,a)=>{let i=new a([r],{type:"image/jxl"});return e?()=>t(i):()=>en(n,i)},rn=tn(!1),nn=tn(!0),an=Uint8Array.of(255,10,0,0,0,128,160,184,17,8,2,1,0,52,0,75,24,139,13,81,2,86,128,112,18,35,7,0),on=null,ln=Uint8Array.of(255,10,0,0,0,128,149,8,24,16,0,92,0,75,56,65,118,224,226,160,140,44,65,1,224,72,120,36,20,146,40,1,123,1,130,56),sn=Uint8Array.of(255,10,0,0,0,128,128,76,110,4,8,6,1,0,80,0,75,56,65,110,224,244,68,14,79,18,20,9,131,36,74,192,46,64,16,7),un=Object.freeze({alpha:!1,displayP3:!1,image:!1}),cn=null,fn=(e,t)=>Object.assign(new Error(t),{code:e}),hn=new Set(["JXL_OPTIONS","JXL_INPUT","JXL_DIMENSIONS","JXL_JPEG","JXL_DECODE","JXL_RECONSTRUCTION","JXL_TARGET","JXL_PLATFORM","JXL_MEMORY","JXL_LIMIT","JXL_WASM","JXL_WEBGPU","JXL_WORKER","JXL_CLOSED","JXL_UNSUPPORTED","JXL_INTERNAL","JXL_IO","JXL_SETUP"]),dn={JXL_SIZE:"JXL_LIMIT",JXL_INVALID:"JXL_DECODE",JXL_FRAMING:"JXL_INPUT",JXL_RGBA:"JXL_INPUT",JXL_PROTOCOL:"JXL_WORKER",JXL_WORKER_LEASE:"JXL_WORKER",JXL_THREAD_REQUIRED:"JXL_PLATFORM",JXL_UNAVAILABLE:"JXL_PLATFORM",JXL_QUEUE_FULL:"JXL_MEMORY",JXL_BUSY:"JXL_INTERNAL",JXL_CODEC:"JXL_INTERNAL",JXL_DICTIONARY:"JXL_INTERNAL",JXL_ENCODE:"JXL_INTERNAL",JXL_GPU:"JXL_INTERNAL",JXL_GPU_NATIVE_UNPROVEN:"JXL_INTERNAL",JXL_INITIALIZE:"JXL_INTERNAL",JXL_MEMORY_GPU_UNPROVEN:"JXL_INTERNAL",JXL_OPERATION:"JXL_INTERNAL",JXL_PART:"JXL_INTERNAL"},mn=new WeakSet,pn="8.4.0",yn={kernels:"6gzyrq",jpeg:"1fjin7z",decode:"17x8vsf",rebuild:"fgbogf",general:"1sc0v86"},gn=e=>{let t=e.length,r=new Uint8Array(t),n=e.charCodeAt(0);for(let a=0;a<t;a++){let t=e.charCodeAt(a)^n;r[a]=65===t?119:119===t?65:t}return r},Mn=e=>{let t=2166136261;for(let r of e.map(e=>e.name+":"+e.kind).sort().join(" "))t=Math.imul(t^r.charCodeAt(0),16777619);return(t>>>0).toString(36)},bn=new Map,wn=new Map,vn=!1,Ln=e=>Object.assign(new Error(e),{code:"JXL_WASM"}),In=Symbol.for("rapier-jxl/8.4.0 wasm "+Object.entries(yn).map(([e,t])=>e+":"+t).join(";")),An=null,xn=()=>{let e=globalThis[In];if(!e||e===An)return;An=e;let t=Object.entries(e).filter(([e])=>!bn.has(e));t.length&&m(Object.fromEntries(t))},Nn=e=>(xn(),bn.has(e)),On=new Map,Pn=new Map,En=e=>void 0===e?Pn.values().next().value:Pn.get(e),Tn=[0,97,115,109,1,0,0,0],Un=()=>{try{return new WebAssembly.Instance(new WebAssembly.Module(Uint8Array.of(...Tn))),!1}catch{return"object"==typeof WebAssembly}},Sn=()=>{try{return!WebAssembly.validate(Uint8Array.of(...Tn,1,4,1,96,0,0,3,2,1,0,10,23,1,21,0,253,12,...Array(16).fill(0),26,11))}catch{return!0}},jn=(e=En())=>Object.assign(Vr("JXL_WASM",Un()?"Host refuses WebAssembly; allow 'wasm-unsafe-eval' in script-src or use the workerd or edge-light condition.":Sn()?"WebAssembly SIMD is unavailable; use a host with SIMD.":`The WebAssembly module failed${qr(e)}; check the host's memory.`),e?{cause:e}:{}),Jn={channel:null,weighted:null,fill:null,palette:null,rct:null,tuple:null,passLevels:null,group:null,screen:null,sampled:null,dct:null,ycbcrTile:null,ycbcrTiles:null,rgbTiles:null,rgbBand:null,photoTile:null,acGroup:null,acGroupPair:null,acDeferred:null,nonzero:null,entropy:null,varblock:null,gaborish:null,strategyFill:null,strategyWrite:null,xybPlanes:null,gabBand:null,dcEvents:null,dcPlan:null,planTokens:null,shape:null,nativeRGBA:null,s2cChannel:null,opaque:null,arena:null,ensure:null},Fn="M,> LMMML*A-K222222M-L1L1-O12L1-I2222M-L2L1-O11L1-I2221L1-L1L2-N121L1-I2222L2-W22222222222122111122222222L2-N222MOBLN(#;K ( \"?4OMLN\\]MILLHOONKJEDGFMNJJG\"?$(#9\n:MMF>, =!(,/!(MJG>, =!(!,#MFG>, =!(,#)MAG>, =!(,+(M@F=#*#+$!9(?MCE=#*$)(#MBGÊ]ÏOLH2mOmLmI:HVlGN\r:MlKN\rmKlEmJlDO\rmI:L\v@MmI:O\vI\rmL:L&mK&lEALFmI:N\vI\rmL:L&mK&lEmO:L&mJ&lDALFmI:I\vI\rmO:L&mJ&lDALFmI:H\vI\rmJlEmKlDALFmI:K\vI\rmO:L&mJ&lEmKlDALFmI:J\vI\rmO:L&mJ&lEmL:L&mK&lDALFmJlEmL:L&mK&lDFmHmDmG!mE'mN!'mMmLmJ!mK'mN!'mN±GMMmK:L'oKmL@MFmJ:L'oJmO@MFF@MmM:²J'áyËòFôONO2N1L3mM\tMMMMMMMM)\bI\r\tMMMMMM½²\tMMMMMMµ2mM\tMMMMMMMM,VBFmM\tMMMMMM½2,I\rmMBFmM\tMMMMMM]M.I\r:lLmM\tMMMMMMïlMFmMðoKyÅê:²J&mL'lLmK²²²²²²²JÎÍÍÍÍÍÍ͵rÉòoM\t€v2+Óí»r)I\rmL:L'lLmM\tMMMMMM­rïlMFmM\tMMMMMM½òímM\tMMMMMM½ríîoMmMïlImMlN:NlON\rO\rmMmNmIïoNmOúîoHílMmHÔmMÔ\tៜ?qï.@MmO:O'oO:e@LFFmLú\tMM­³c«rïmLú\t;q4x¢t§pïmMmMíííFçOOO2O1mMmM/I\r\tMMMMMMµ2BFmM\t¢t·³cË\r)I\r\tMMMMMM½2BFmM\t}`˜]ʍ.I\r\tMMMMMMMMBFmMmM\t¢t·³c«rîoMÑoN\tMMMMMM½r\tMMMMMMMMmMmNì\tMMMMMM­r+VíçoLú\tMM­³c«rïìmLú\t;q4x¢t§pïìlI\tMMMMMM½rlN\tMMMMMM½rlM:LlON\rO\rmMmNmImOúîïoNílMmNÔmM\tڙ\v\v¸C*qï.@MmO:L'oO:S@LFFmL:²JI\rmM:²J]LïmL:²J&]LïBFmL:Ï5I\rmM:Ï5]LïmL:³J']LïBFmMmL]LïF›LOL1L2mL\tMMMMMMMM,I\r\tMMMMMM½rBFmLÐmL,mLÔ\tMMMMMM\r(<I\rmLÔçlN\tMMMMMM½rlON\rmOmMïmOmN:L<VlOmMmMïlMmN:L;oN@MF\tMMMMMM½rmOîmOmL\tMMMMMMMM.VBFmM\tMMMMMMMM,I\r\tMMMMMMMM\tMMMMMM½2mL\tMMMMMMMM)VBFmM\tMMMMMMMM.I\r\tMMMMMMµ2BFmLmM]Oï]NF•OMmL\bI\rmMBFmL:II\rmMÔ\tMMMM_.:mLõî]ImMëBFmL:I\vI\rmMÔ\tn–´3'ñùr.I\rmM\tMMMMMM_\rîBFmMÔ\t¿Ÿ\0/]ôrí\tbiKÌØ¼rî\t?QŠ<QŠL\r]ImMëBFmL:L\vI\rmMÔ\t_Yr‹‘øér(I\rmM\tšî=pGšd\rîBFmMÔ\td¸eárí\t¬7Yã\n¬½rî\t~~~~~~N\r]ImMëBFmL:O\vI\rmM\tüÄDËø´Är]IoM\tMMMMM§òí\tMMMMMMMMè\tMMMMM—\rmM\tMMMMMý\rïìî\tf[ª@QT\r]IBFmM\tMMMMMM­r(I\rmMmMï\tMMMMMME\rîBFmM\tÀ¼\r¥„§¬òí\t@\0L³®‹rî]N\t«Ö(°NuŸrí\tMMMMMMe\rîF§OMmL\bI\rmMBFmL:II\rmMÔmLõ\tMMMM_.:î]ImMëBFmL:I\vI\rmMÔ\tv’ÀÚ#ßr.I\rmM\tMMMMMM_\rïBFmMÔ\t€‘r]I\tbiKÌØ¼rï\t¿Ÿ\0/]ôòímMëBFmL:L\vI\rmMÔ\tTúÊ>Žè$r(I\rmM\tšî=pGšd\rïBFmMÔ\tæççççç—r]I\t¬7Yã\n¬½rï\td¸eáòímMëBFmL:O\vI\rmM\tMMMMMMMMè\tMMMMM)‰r]IoM\tMMMMM—\rï\tMMMMM§rímM\tMMMMMý\rï\tMMMMMM½ríî\tMMMMMû\r]IBFmM\tør(I\rmM\tMMMMMME\rï\tMMMMMMMMèÒBFmM\tMMMMMMe\rï\t«Ö(°NuŸòí]O\t@\0L³®‹rï\tÀ¼\r¥„§¬ríFÏOOO2N3N\rmOmI:N9'mIõmLõîmM]HtNMmI:L'oImL\0@MFmNI\r:MlO:LlIN\rÍÍÍÍÍÍÍ͍MlJN\rmKmJI\rmKmJ1LÅoEòmMmLõ]GmIõ+I\rmElJHmEL1lKFALFFmNmI:L&:N9'\tMMMMMM½2mKòmKòmMmLõ]GmIõ.VtNMmI:L'oImL\0@MFN\rN\rO\rmLmO\0@MmNmO:N9'fNMmHõ\tMMMMMM\rrï)@MmO:L'lOALFFmN:ÍÍO'mH:O9'mO{OMmH:L'oH:Ím\0@MFFFîLMmO\bI\rmMmL'`MMõmNîBFmO:N\vI\rmMmL:O9'gOMöBFmMmL:L9'bLMlMmO:L\vI\rmMõmNîBFmM:²J<lLmM:G;:R<oOI1mO:R\vI1\tMMMMMMµ2\tMMMMMM½2mLVHmL:ÍE'õmO:T&]LïFHmLõ\tMMMMMM=sïFoN×mNmM:ÍÍO<VF€LON2L1mMð}Åê:ÍÍO<lOmM\tMMMMMMMM,I\rmOBFmMÔoMlIN\rmI\tMMMMMMM\r.\bI\rmI\tMMMMMM­rïlImL:L'lLALFFN\rmI\tMMMMMM½r+\bI\rmImIílImL:L&lLALFFmL:?I1:<lLmM\tMMMMMM\rïHmI\tMMMMMM½òíF\tMMMMMMÝ\rïÓæoN:ÍE\vI\r:MlNmL:L'lLFmOmL:B':G9mN??FMmM\tMMMMMM½rïmL]K\tMMMMMM½rï\tMMMMMM½ré\tMMMMMMMMèmOïoMÑ\tMMMMMM½r\tMMMMMMMMmMmMÑì\tMMMMMM­r+VíFËOOK2I1mMmL\0lEN\rmEI\r:O:LmM:L&õmHõ\tMMMMMM­rímMõïmLõî\tMMMMMM­òíé\tMMMMMMMMèoGÑæoI:L'mMVmI'lJ\tMMMMMM½rmGmIõìo@ìlFHmHõmMõïmLõîoGÑælImH:L'õmMõïmLõîoAÖælJFmOmH:A!'oDmI{OMmDmJmI&{OImDmK{OEN\rmNmK:N9'mEI1mFHmAmI:L'õémGmIõèìmAmGìîFtNMmK:L'lKm@lFmJmI:L'oI@MFmH:L'oHmL@MFmKF¸YN_2J1N6mI:I:NmG:N\vV:OmGV9ldmK:I:NmG:N\vV:OmGV9lgmZmU:N!'limK:O9lj:2lh:2lkmHmJ\0lemEloN\rmNmEmo\v<\bI\rmi:Mmj:N9±FMFmOmeI2mH:L&õmoõ\tMMMMMM­rímHõïmJõî\tMMMMMM­òíé\tMMMMMMMMèobÑælmmbmmõìlbmHmm:O'mHmm:O'VHmoõmHõïmJõîo}Ñælmmo:L'õmHõïmJõîo|ÖæFonmOmnVmLmmmLmmVoRI\rN\rmeI1\tMMMMMM½rmbìmbmRmm\vVHm|mR:L'õém}mRõèìm|m}ìîFoc\tMMMMMMMM/I\rmRmh\vI\r:MllHmRmk\vI\r:LllHmhmkllO2mMmRmL&md!'lS:MlPmG\bmC\tMMMMMM½r,<m_:M\n<I\rmFælQN\r\tMMMMMM½rmSmP:O9'eOMoV:U;õmFîmV:U;mQ\vVl`mZmP:H9'oWm_mV:²L<:N9'fNMm`ïtNMmWm_mV:E;:²L<:N9'fNMm`ïtNEmWm_mV:];:²L<:N9'fNMm`ïtN]mWm`tNUmP:L'oPmI@MF:MALFm_I\rN\rmZmP:H9'lWmSmP:O9oV:N'mGmF]El`:MlQN\rmWmQ:N9'm_mGI2mSmVmQ':L9'bLMHmSmVmQ''`MMF:N9'fNMtNMmQ:L'oQ:N@MF\tMMMMMM½rlamC\tMMMMMM½r/I\rmWfNMmBï\tMMMMMMMMímWfNEm]ïímWfN]m\\ïíoamC\tMMMMMM½òí]I\tMMMMMMMMma\tMMMMMMMM)VlaFmWmWfNMmaïm`ïtNMmWmWfNEmaïm`ïtNEmWmWfN]maïm`ïtN]mWm`tNUmP:L'oPmI@MF:MALFN\rmZmP:H9'lW:LmSmP:O9oV:N'mGmF]Eo`\tMMMMMM½r(m`\tMMMMMMMM+<\b@LW:MlQN\r:OmSmVmQ'mGmF]EoaÔ\tMMMMMM½2.\b@OWm@I\rmam`î\tMMMMMMMMm`\tMMMMMMMM/VlaF:Nma\tMMMMMMMM.ma\tMMMMMM½r)?mA:O\v<@OW:ImA:N\vma\tMMMMMMMM.<@OWmWmQ:N9'm_I1m_mGI2mSmVmQ':L9'bLMHmSmVmQ''`MMF:N9'fNMHmamA]HFtNMmQ:L'oQ:N@MF\tMMMMMM½rlamC\tMMMMMM½r/I\rmWfNMmBï\tMMMMMMMMímWfNEm]ïímWfN]m\\ïíoamC\tMMMMMM½òí]I\tMMMMMMMMma\tMMMMMMMM)VlaF:MlQN\rmWmQ:N9'oVmVfNMmaïm`ïtNMmQ:L'oQ:N@MFmWm`tNUmP:L'oPmI@MF:MFoWI\rmWBFmZmUml:L'!'lf:MlVN\rmXmV:A!'oWeOMlQmQmWeOI'lSmWeOElP°AMMMMMMMMMMMMMMMMly°AMMMMMMMMMMMMMMMMl~N\rm[mP:N9'fNMoa\tMMMMMMMM/I\rmymZmQ:H9'oW°MIMma°Yox°¿L°½Llym~mW°MI]mx°¿L°½Ll~FmP:L'lPmSmQ:L'oQ@MFmfmV:H9'oWmy°FIMmWm~°FI]mV:L'oVmK@MFmlI\rmRlkHmRlhFFFmZmUml:L'!'lV:MlWmc°Yl~N\rmWmi'oQmQ°MIMmWmV'°MIMm~°¿L°½L°FIMmW:]'oWmj:N9@MFFmR:L'oRmOmnmOmnV@MFFmOmnI\r:MBFO2mTmomE&mg!'lP:MlmN\rmimm:H9'oSfNU\tMMMMMM½ré\tMMMMMMMMèl`mG:OI2m`mFï\tMMMMMM­r.HmG:O\vI2m`]D\bHm`ûMMMMFFll:MlVN\rmSmV:N9'oWmWfNMm`î\tMMMMMMMMm`\tMMMMMMMM/VtNMmV:L'oV:N@MF\tMMMMMM½rlcmC\tMMMMMM½r/I\rmSfNMmBï\tMMMMMMMMímSfNEm]ïímSfN]m\\ïíoa\tMMMMMM½rmCî\tMMMMMM½òí]I\tMMMMMMMMma\tMMMMMMMM)VlcF:MlVN\rmY:M\nmV:N<I\rmSmV:N9'fNMoa\tMMMMMMM\r.ma\tMMMMMMMM+<I\rmYma\tMMMMMM­\rïæ:L9'bLMoRI\rmm:O9mV'lW\tMMMMMMMMmR:L&õmlVlamGI\rmPmW:L9'maævLMHmWmP'maæwMMFmV:L'lVANFFFm^:M\nmV:N<mSmV:N9'fNMoa\tMMMMMMM\r(ma\tMMMMMMMM+<<I\rmFæW:²Rma\tMMMMMMí\rïæma\tMMMMMMM\r+V:O9oWm^:ÍÍO''eOMlQm^:ÍÍO'mW'eOIlWN\rmWmQI\rm^mWmQ':L;oR:N9'fNMma(I\rmR:L'lQHmRlWFALFFmQ\bma\tMMMMMM=pïomam^mQ:L&:N9'fNMì.?mQmFæm^mQ:N9'fNMmaìm)?<I\rmm:O9mV'lW\tMMMMMMMMmQõmlVlamGI\rmPmW:L9'maævLMHmWmP'maæwMMFmV:L'lVAOFF:H\tMMMMMMMMmV:N\vI1m`HmSmV:N9'fNMmcïmA]Km`\tMMMMMM½rm@VïFmV:Nml<VoaÔ\tMMMMMM½2.\b@OWmm:O9mV'lWmG:OI\rma\tMMMMMM½ré\tMMMMMMMMèmFïoaÑ\tMMMMMM½r\tMMMMMMMMmamaÑì\tMMMMMM­r+VílamGI\rmPmW:L9'maævLMHmWmP'maæwMMFHmG:O\vI\r:HmaÔ\tMMMMM³¢\r+@IWmPmW:L9'ma]DvLMH:HmaÔ\tMMM­²²¢\n)@IWmPmW:O9'maûuOMFFmV:L'oV:I@MFmm:L'ommK@MF:MFoWI\rmWBFmo:L'oomD@MF:MFàLOO2N1N\rmIõ\tMMMMMMMrïlHmI:L'õ\tMMMMMMMrïoJ\tMMMMMM=pïlKN\rO\rmLmN\0@MmMmN:N9'fNMmH)@MmN:L'lNALFFmOmI:L9'mN:L':MmLmN\0mMmN:N9'fNMmJìmK)?mN\bmHmMmN:L&:N9'fNMìmK)?<VvLMmI:L'oI:ÍÍI@MFF½NLH2mM\bI\rmOmLmI±GMMBFmM:O\vI\rmI:=<lMN\rmMmK\0\bI\rmOmK'mLmK'°MIMmNmK'°MIM°#°FIMmK:]'lKALFFN\rmImK\0\bI\rmOmK'mLmK'`MMmNmK'`MM'wMMmK:L'lKALFFBFmHmImImHVlEN\rmKmE\bI\rmOmK'mLmK'`MMmNmK'`MMoJ:L;mJmM:N\vV:MmM:L\nV'wMMmK:L'lKALFFmM:L\vI\rN\rmImK\0\bI\rmOmK'mLmK'`MMmOmK'mH&`MM'wMMmK:L'lKALFFBFmM:N\vI\rN\rmImK\0\bI\rmOmK'mLmK'`MMmOmK'mH&`MMmNmK'`MM':L;'wMMmK:L'lKALFFBFN\rmImK\0\bI\rmNmK'`MMoJmNmK'mH&`MMoD&oM:MmM&mM:MVlMmOmK'mH&`MMoGmD&oE:MmE&mE:MVlEmOmK'mLmK'`MMmGmJmDmJmG'mD:L9&oJ:MmJ&mJ:MVoJmEVmMmE\0mMmJ\0<V'wMMmK:L'lKALFFF·LLO2mO:N\vI\rmL:H&:MmL:HVlHN\rmImH\bI\rmNmI:O9'mMmI:N!'°MIM°AMLOÍNIHÍKJEÍDGFͰC°AMMM²MMM²MMM²MMM²°°FIMmI:I'lIALFFFN\rmLmII\rmO:N\vI\rmNmI:O9'mMmI:N!'`MMmMmI:N!'`ML:E9mMmI:N!'`MO:]9??:ÍÍÍ5?{OMHmNmI:O9'mMmOmI!'`MM:ÌÏI!:²LmMmI:L9'`MLmO:O\nV:U9?{OMFmI:L'lIALFFF",kn=e=>{try{return WebAssembly.validate(e)}catch{return!1}},Xn=()=>"object"==typeof WebAssembly&&1===new Uint8Array(new Uint32Array([1]).buffer)[0]&&(Nn("kernels")||kn(gn('M,> LMMMLHL-ML2NOLMJDLH=?"/(MMGFLDM:M°\\°VMF'))),_n=null,Rn=null,Bn=[],Gn=[1];for(let e=1;e<=32;e++)Gn.push(2*Gn[e-1]);new Uint8Array(Uint32Array.of(1).buffer)[0];var Cn=class{constructor(e=4096,t=1/0){if(t!==1/0&&(!Number.isSafeInteger(t)||t<0))throw Vr("JXL_INTERNAL","Invalid encoded picture allocation limit.");this.bytes=new Uint8Array(t===1/0?e:Math.min(e,t)),this.maxBytes=t,this.at=0,this.acc=0,this.pending=0}write(e,t){if(!(t>=0&&t<Gn[e]))throw Vr("JXL_INTERNAL","bit write out of range: "+e+" bits, "+t);let r=this.pending+e;this.at+5>=this.bytes.length&&this.grow();let n=this.bytes;if(r<32){let e=this.acc|t<<this.pending;for(;r>=8;)n[this.at++]=255&e,e>>>=8,r-=8;return this.acc=e,void(this.pending=r)}let a=this.acc+t*(1<<this.pending);for(;r>=8;)n[this.at++]=255&a,a=Math.floor(a/256),r-=8;this.acc=a,this.pending=r}writeU32(e,t){for(let r=0;r<4;r++){let[n,a]=e[r];if(t>=a&&t-a<Gn[n])return this.write(2,r),void(n&&this.write(n,t-a))}throw Vr("JXL_INTERNAL","U32 value out of range: "+t)}zeroPadToByte(){this.pending&&(this.at+1>=this.bytes.length&&this.grow(),this.bytes[this.at++]=this.acc,this.acc=0,this.pending=0)}get bitLength(){return 8*this.at+this.pending}grow(e=0){let t=this.at+e+16;if(!Number.isSafeInteger(t)||t<0)throw Vr("JXL_INTERNAL","The encoded picture cannot be allocated.");if(t>this.maxBytes)throw Object.assign(new RangeError("The encoded picture exceeds its allocation limit."),{code:"JXL_MEMORY"});let r,n=Math.min(this.maxBytes,Math.max(2*this.bytes.length,t));try{r=new Uint8Array(n)}catch(e){if(!Yr(e)||n===t)throw e;r=new Uint8Array(t)}r.set(this.bytes.subarray(0,this.at)),this.bytes=r}append(e){if(this.at+e.at+8>=this.bytes.length&&this.grow(e.at+8),this.pending){let t=this.bytes,r=e.bytes,n=this.pending,a=e.at,i=this.acc,o=this.at;for(let e=0;e<a;e++){let a=i|r[e]<<n;t[o++]=255&a,i=a>>>8}this.at=o,this.acc=i}else this.bytes.set(e.bytes.subarray(0,e.at),this.at),this.at+=e.at;e.pending&&this.write(e.pending,e.acc)}finish(){let e=this.at+(this.pending?1:0),t=this.bytes.slice(0,e);return this.pending&&(t[this.at]=this.acc),t}},Dn=(Float32Array.from(atob("PNS2d2Sr7wN9L8AkeT6HmjZ/vPBCry1jIsNOM+lnnAGpI1DdNiZLlNwU+0df8hNT59coigfGVOW1DniuFITA/32V6gaK+sNwXKaIzAm6pmges1qlaP0YkHA68F/KRCtYEr1DYbCdDj/stjZulN4vzneSEeI3gaBGzd+jBZfcc+Q1bfLHHVZ7zioXVOkhfk7rO/lHynW52QtaJ4pN9R+3jtCkKIHZMuSjj2XYm0KyBIsZvpsAUSIx9ny/GmywPGMK+VMVk2e4SwH0gr4R/WHEpFdtLN3tsZJjqOI1yH/VnUmFruJBDP52xSBFrDDLcyTv2oCrXolu0hZAmFL7ECzowwRgc8qaqFk43V5wClGEmDRED/YbOEkIu+pyA6qNWXcgOdgv7hwrh7OV7dGi9uEW0mm3zZTFo/1YhiXaZe5Cupf0tIxIv23nCBl8KY47uUqniwdVdCXgfDDNtTrEohjOaRGhWgZ+2k/JQrtWHWoCeln8LeY/sBOaahuQTAuBKeBOeSPU+Kw2m/tnp/DbrcbqIcCeg9ViUOxDqvfjc1f/rYnpvD5qFWAjjRMzhUiZMGLZO20Y848BvtoNX58xxpMCNMlSmIXP7LV208IJcfgUgpIMqkq4MspxiCt90h+wY0RvGd8JLaVFAOFNXeUkzEG2T/XRXXsioT3xVLxG9BLW7p5dsnb0v1iVKoGgso9Xpd51KsIG4P5nFbGWBmyKOni5J/pHkRw3b8jxPRr/OGsD7hyciTmok0bV4yXIp+iZVQiIM9Fk54PXDqxpvQzXfy69XkVu6FQPg1p1NPhcGizM46kNxKASt0wjjN54SJfrr4vN+xfHLtCtwAmOTYDdvmZAfVJxJj/8p2L1VSzRYSBPPQ2ierNk7yA/6py3PQR0ox/xsYncW5V6MQOetBDBpHTk2SdNjwKZfmvXFGXPrP5LlNYBMOu7DNPB5UOE7Tf5BYVouPM+3jT6T6Uu8SKLMhPBYfedSWwdPJBwyxdokVbHL5tbEMJyXbwLh8V4UeBc6YM7dxfIrYbyWCamTHzfG7JG1B6Az58aqybnQ5cPu2+gJM9mkeMpUNu2Ev7VuCmhcuaM/K4tR+KN025f96k+zAuuVboIOH6hBWaaNWAAQfNiCjlTbATveTlOswAf1n8qS/zYRO1g0PlFxnmI6MKWgssVpL/YllnHEf2ZxDeOZfCWhx2omCGvchbfKEypHlYytOx7JUGGtSFphCjrduFTBcU1cdyAwVcxkLn1Ds51+NtJkVvhEPYz5qa9XEiqFrqi5F4PLkr3CuZAW5xqOo0HZhkrb6vJnXRQDds8B9BrJ0B6sfKMaxify4Ie07RS5Z+v1MP/AkpkG9KTe/OehvqS1hxRyQ=="),e=>Math.round(13125*(2*e.charCodeAt(0)-255)/68)/1e5),Symbol.for("rapier-jxl.decoder")),Wn=()=>globalThis[Dn]??null,Vn=Symbol.for("rapier-jxl.decoder.snapshot"),Kn=[];for(let e=2;Kn.length<64;e++)Kn.every(t=>e%t)&&Kn.push(e);var zn=Kn.slice(0,8).map(e=>e**.5%1*2**32|0),Hn=Int32Array.from(Kn,e=>Math.cbrt(e)%1*2**32|0),Yn=new Int32Array(64),qn=()=>({h:[...zn],length:0,tail:[]}),$n=1<<20,Qn=2**32,Zn=new TextEncoder,ea=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),ta=Object.getPrototypeOf(Uint8Array.prototype),ra=Object.getOwnPropertyDescriptor(ta,"byteLength").get,na=Object.getOwnPropertyDescriptor(ta,"byteOffset").get,aa=Object.getOwnPropertyDescriptor(ta,"buffer").get,ia=Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get,oa=e=>Vr("JXL_INPUT",e),la=/^[ !#-[\]-~]*$/,sa=8388608,ua=e=>{throw Vr("JXL_INPUT",e)},ca=1048576,fa=ca,ha=16384,da=/^[a-f0-9]{64}$/,ma=4*ca,pa=e=>((!Array.isArray(e)||e.length>64||e.reduce((e,t)=>e+Ia(t).length,0)>sa)&&ya("Invalid checkpoint reads."),e),ya=e=>{throw Vr("JXL_INPUT",e)},ga=e=>{throw Vr("JXL_INPUT",e)},Ma=e=>j(T(e)),ba=(e,t)=>{let r=T(e),n=T(t);return r.length===n.length&&r.every((e,t)=>e===n[t])},wa=e=>{let t=262144;for(;Math.ceil(e/t)>64;)t*=2;return t},va=e=>Math.max(fa,wa(e)),La=e=>{if(e?.aborted)throw zr(e)},Ia=e=>((!e||!da.test(e.hash)||!Number.isSafeInteger(e.length)||e.length<0||e.length>ca||2!==Object.keys(e).length)&&ya("Invalid immutable part reference."),e),Aa=e=>{let t=Ma(e);if(!t||"object"!=typeof t||Array.isArray(t)||!da.test(t.sha256)||"string"!=typeof t.generation||!t.generation.length||t.generation.length>256||!Number.isSafeInteger(t.byteLength)||t.byteLength<1||t.byteLength>4294967295)throw Vr("JXL_INPUT",'The input needs generation (text), sha256 (64 lowercase hex digits, no "sha256:" prefix) and byteLength (1 to 4294967295).');return t},xa=e=>{if(!e||"object"!=typeof e||Array.isArray(e)||Object.keys(e).some(e=>"units"!==e)||!Number.isSafeInteger(e.units)||e.units<1||e.units>64)throw Vr("JXL_INPUT","A work budget is {units: 1..64}.");return{units:e.units}},Na=Symbol.for("rapier-jxl.journal.saved"),Oa=Symbol.for("rapier-jxl.journal.unread"),Pa=Symbol.for("rapier-jxl.journal"),Ea=Symbol.for("rapier-jxl.journal.file"),Ta=Symbol.for("rapier-jxl.journal.join"),Ua=Symbol.for("rapier-jxl.journal.facts"),Sa=e=>"symbol"==typeof e&&Symbol.keyFor(e)?.startsWith("rapier-jxl.journal"),ja=(e,t,r)=>new Proxy(new Uint8Array(0),{get:(n,a)=>Object.hasOwn(e,a)?e[a]:a===Symbol.toStringTag?"Uint8Array":Sa(a)?void 0:r&&"string"==typeof a&&/^(0|[1-9]\d*)$/.test(a)?r(Number(a)):(e=>"function"==typeof e?e.bind(t()):e)(Reflect.get(t(),a)),getPrototypeOf:()=>Uint8Array.prototype,has:(e,r)=>Reflect.has(t(),r),ownKeys:()=>Reflect.ownKeys(t()),getOwnPropertyDescriptor:(e,r)=>Reflect.getOwnPropertyDescriptor(t(),r),set:(e,r,n)=>Reflect.set(t(),r,n)}),Ja=(e,t)=>{let r,n=-1;return a=>{if(!(a>=e))return(!r||a<n||a>=n+r.length)&&(n=65536*Math.floor(a/65536),r=t(n,Math.min(e,n+65536))),r[a-n]}},Fa=(e,t)=>null!==e&&"object"==typeof e&&!0!==e[Oa]?e[t]:void 0,ka=e=>null!==e&&"object"==typeof e&&(Object.hasOwn(e,"unit")||Object.hasOwn(e,"unitDone")||Object.hasOwn(e,"unitFailed")),Xa=Symbol.for("rapier-jxl.journal.active"),_a=e=>globalThis[Xa].join(e),Ra=e=>globalThis[Xa].tools[e],Ba=e=>({plain:!0,*step(t,r,n,a){if(e.aborted)throw e.reason;return 2===a?yield*r():r()}}),Ga=Symbol.for("rapier-jxl.journal.passed"),Ca=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Float16Array"],Da=Object.getPrototypeOf(Uint8Array.prototype),Wa=e=>Vr("JXL_INPUT",e),Va=Symbol.for("rapier-jxl.journal.span"),Ka=Symbol.for("rapier-jxl.journal.slice"),za=e=>null!==e&&"object"==typeof e?e[Va]:void 0,Ha=(e,t,r,n)=>Object.freeze({type:e,ref:Object.freeze([...t]),offset:r,length:n}),Ya=(()=>{class e extends Error{get[Oa](){return!0}}return e})(),qa=Ta,$a=e=>($(e.map(e=>()=>e?.[qa])),e),Qa=e=>!0===e?.[Oa],Za=Symbol.for("rapier-jxl.journal.tiles"),ei=e=>za(e)?.ref[0],ti=e=>{throw Vr("JXL_INPUT",e)},ri=Object.freeze(new Error("A resumable call ended its attempt.")),ni=e=>void 0!==e?.unit||void 0!==e?.unitDone||void 0!==e?.unitFailed,ai=()=>performance.now(),ii=Symbol.for("rapier-jxl.journal.observe"),oi=524288,li=4194304,si=e=>e&&"object"==typeof e&&void 0===e.t?Array.isArray(e.a)?"a":Array.isArray(e.o)?"o":Array.isArray(e.m)?"m":Array.isArray(e.s)?"s":void 0:void 0,ui=new WeakMap,ci=e=>((!Array.isArray(e.bytes)||e.bytes.some(e=>!Array.isArray(e)||3!==e.length||!Number.isSafeInteger(e[1])||!Number.isSafeInteger(e[2])||e[1]<0||e[2]<0||e[1]+e[2]>ca))&&ti("Invalid journal value pages."),e.bytes),fi=e=>{(!Number.isSafeInteger(e.length)||e.length<0||ci(e).reduce((e,t)=>e+t[2],0)!==e.length||!e.length&&e.bytes.length)&&ti("A journal value has the wrong length.")},hi=class e{constructor(e,t=e.reduce((e,t)=>e+t.length,0)){this.spans=e,this.length=t}#e(e,t){let r=[],n=0;for(let a of this.spans){let i=n+a.length;if(i>e&&n<t&&r.push(a.subarray(Math.max(e-n,0),Math.min(t,i)-n)),n=i,n>=t)break}return r}subarray(t,r=this.length){let n=this.#e(t,r);return 1===n.length?n[0]:n.length?new e(n,r-t):new Uint8Array(0)}slice(e,t=this.length){let r=new Uint8Array(t-e),n=0;for(let a of this.#e(e,t))r.set(a,n),n+=a.length;return r}},di=Math.log,mi=(e,t)=>e<=0?0:1===t?e:Math.pow(e,t),pi=(e,t)=>e.getInt32(t)/65536,yi=e=>t=>String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3)),gi=e=>[e[0][0],e[1][0],e[2][0],e[0][1],e[1][1],e[2][1],e[0][2],e[1][2],e[2][2]],Mi=e=>{try{return e()}catch(e){if(Qa(e))throw e;return null}},bi=[.9642,1,.8249],wi=[.8951,.2664,-.1614,-.7502,1.7135,.0367,.0389,-.0685,1.0296],vi=(e,[t,r,n])=>[e[0]*t+e[1]*r+e[2]*n,e[3]*t+e[4]*r+e[5]*n,e[6]*t+e[7]*r+e[8]*n],Li=([e,t,r])=>[e/(e+t+r),t/(e+t+r)],Ii=([e,t])=>[e/t,1,(1-e-t)/t],Ai=[[1,[.3127,.329]],[10,[1/3,1/3]],[11,[.314,.351]]],xi=[[1,[[.64,.33],[.3,.6],[.15,.06]]],[9,[[.708,.292],[.17,.797],[.131,.046]]],[11,[[.68,.32],[.265,.69],[.15,.06]]]],Ni=(e,t)=>Math.abs(e[0]-t[0])<.001&&Math.abs(e[1]-t[1])<.001,Oi=e=>e.map(e=>Math.round(1e6*e)/1e6),Pi=[[1,e=>e<.081?e/4.5:mi((e+.099)/1.099,1/.45)],[8,e=>e],[13,e=>e<=.04045?e/12.92:mi((e+.055)/1.055,2.4)],[17,e=>mi(e,2.6)]],Ei=(e,t)=>{for(let r=0;r<=255;r++){let n=r/255,a=e(n),i=0,o=1;for(let e=0;e<24;e++){let e=(i+o)/2;t(e)<a?i=e:o=e}if(255*Math.abs(i-n)>.5)return!1}return!0},Ti=["perceptual","relative","saturation","absolute"],Ui={1:"d65",10:"e",11:"dci"},Si={1:"srgb",11:"display-p3",9:"rec2020"},ji={1:"bt709",8:"linear",13:"srgb",17:"dci"},Ji=function(e){let t=Oe(e);return!t||t.gray?null:{space:"rgb",whitePoint:Ui[t.white.enum]??t.white.xy,primaries:Si[t.primaries.enum]??t.primaries.xy,...void 0!==t.gamma?{gamma:t.gamma}:{transferFunction:ji[t.transfer]},renderingIntent:Ti[t.intent]}},Fi=function(e,{lossy:t=!1}={}){e=Pe(e,t);let r=e?.colorEncoding;if(!r||"rgb"!==r.space&&"gray"!==r.space||"srgb"!==r.transferFunction||void 0!==r.gamma)return[e,void 0];let n=Object.keys(r).every(e=>["space","transferFunction","renderingIntent"].includes(e))?"srgb":t&&"rgb"===r.space&&"d65"===(r.whitePoint??"d65")&&Object.keys(r).every(e=>["space","whitePoint","primaries","transferFunction","renderingIntent"].includes(e))?{srgb:"srgb","display-p3":"display-p3"}[r.primaries??"srgb"]:void 0;if(!n)return[e,void 0];let{colorEncoding:a,...i}=e;return[{...i,colorSpace:n,transferFunction:"srgb"},"number"==typeof r.renderingIntent?Ti[r.renderingIntent]:r.renderingIntent]},ki=({colorSpace:e,renderingIntent:t})=>void 0!==t&&1!==t?{colorEncoding:{space:"rgb",whitePoint:"d65",primaries:e??"srgb",transferFunction:"srgb",renderingIntent:t}}:e?{colorSpace:e}:{},Xi=e=>e&&"object"==typeof e&&!Array.isArray(e),_i=e=>JSON.stringify(e,(e,t)=>void 0===t?null:Xi(t)?Object.fromEntries(Object.keys(t).sort().map(e=>[e,t[e]])):t),Ri=async(e,t)=>{let r=await t;if(!r.facts.record)return r;let{source:n,...a}=r.facts.record;return{...r,facts:{...r.facts,record:e?{...a,source:{kind:"bytes",digest:e}}:a}}},Bi=({source:e,...t})=>t,Gi=(e,t,r)=>"file"===(t.kind??"pixels")?r?{[Ea]:e}:new Blob([e]):{data:e,width:t.width,height:t.height,...ki(t)},Ci=65536,Di=1048576,Wi=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array"],Vi=new Set(["coeffs","levels"]),Ki="rapier-jxl.band-summary.1",zi=Object.getPrototypeOf(Uint8Array.prototype),Hi=e=>ArrayBuffer.isView(e)&&Object.getPrototypeOf(Object.getPrototypeOf(e))===zi&&Wi.includes(e.constructor.name),Yi=e=>Array.isArray(e)&&e.length>0&&e.length<=4&&e.every(e=>Hi(e)&&1===e.length),qi=Object.freeze({save:function(e,t=null){let r=e?.strategyData;if(!r&&Array.isArray(e?.components)){let r=e.components.map(Be);return r.includes(null)?e:{[Ki]:"plain",band:{...e,components:r},extra:t}}if(!r||!Array.isArray(r.blocks)||!Array.isArray(r.groups))return e;let n=new Map(r.blocks.map((e,t)=>[e,t]));if(n.size!==r.blocks.length)return e;let a=[],i=[];for(let t=0;t<r.groups.length;t++){if(!(t in r.groups)){a.push(-1);continue}let o=r.groups[t];if(!Array.isArray(o))return e;a.push(o.length);for(let t=0;t<o.length;t++){let r=n.get(o[t]);if(!(t in o)||void 0===r)return e;i.push(r)}}let o=_e(r.blocks);return o?{[Ki]:!0,band:{...e,strategyData:{...r,blocks:null,groups:null}},keys:Object.keys(r),blocks:o,groupCount:r.groups.length,lengths:Int32Array.from(a),members:Int32Array.from(i),extra:t}:e},answer:function(e){if(!e?.[Ki])return e;if("plain"===e[Ki])return Object.defineProperties({...e.band},{answered:{value:!0},extra:{value:e.extra}});let t=null,r=null,n=()=>t??=Re(e.blocks),a=()=>{if(r)return r;n(),r=new Array(e.groupCount);for(let n=0,a=0;n<e.groupCount;n++){let i=e.lengths[n];i<0||(r[n]=Array.from({length:i},(r,n)=>t[e.members[a+n]]),a+=i)}return r},i=e.band.strategyData,o={};for(let l of e.keys)"groups"===l?Object.defineProperty(o,l,{get:a,set:e=>{r=e},enumerable:!0,configurable:!0}):"blocks"===l?Object.defineProperty(o,l,{get:n,set:e=>{t=e},enumerable:!0,configurable:!0}):o[l]=i[l];return Object.defineProperties({...e.band,strategyData:o},{summary:{value:!0},extra:{value:e.extra},frameBlocks:{value:(t,r)=>Re(e.blocks,(e,n)=>(e.by+=t,Object.defineProperty(e,"coeffs",{get:()=>r(n),enumerable:!0,configurable:!0})))}})}}),$i=(e,t)=>q(e,"settle-band",t),Qi=Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get,Zi=Object.getPrototypeOf(Uint8Array.prototype),eo=Object.fromEntries(["buffer","byteOffset","byteLength"].map(e=>[e,Object.getOwnPropertyDescriptor(Zi,e).get])),to=Object.getOwnPropertyDescriptor(Zi,Symbol.toStringTag).get,ro=e=>{throw Vr("JXL_INPUT",e)},no=()=>ro("Source contains an invalid deflate stream; pass a valid PNG file."),ao=()=>ro("Compressed source data exceeds its declared dimensions; pass a valid PNG file."),io=32,oo=1024,lo=32768,so=Array.from({length:29},(e,t)=>t<8||28===t?0:t-4>>2),uo=Array.from({length:30},(e,t)=>t<4?0:t-2>>1),co=(e,t)=>e.map((r,n)=>t+=n&&1<<e[n-1]),fo=co(so,3),ho=co(uo,1);fo[28]=258;var mo=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],po=null,yo=()=>po??={lit:Ve(Uint8Array.from({length:288},(e,t)=>t<144?8:t<256?9:t<280?7:8),!0),dist:Ve(new Uint8Array(32).fill(5),!0)},go=(e,t)=>({lit:Ve(e.subarray(0,t),!0),dist:Ve(e.subarray(t),!0)}),Mo=8192,bo=e=>({bytes:e.bytes.subarray(0,e.at),at:e.at,acc:e.acc,pending:e.pending,bitLength:8*e.at+e.pending}),wo=(e,t)=>e===Ga?t:e,vo=e=>({remaining:e.remaining,state:e.state,position:e.position,left:e.left,distance:e.distance,history:e.history?.slice(0,Math.min(e.position,e.history.length))??null}),Lo=rt("decode-icc-profile"),Io=nt("decode-brotli","decode-brotli","decode-brotli-trees"),Ao=nt("brotli","brotli-read","brotli-models"),xo=Object.freeze({openImage:function*(e,t,r){return yield*z("decode-open",function*(){let n=yield*tt(e,t,r),a=yield*V("decode-image-header",()=>{let e=new r.JxlBits(ae(n.codestream,0),!0),a=r.readDecodeImageHeader(e,t);return a.level=n.container?.level??5,{h:a,bit:e.bit}}),i=a.h,o=new r.JxlBits(ae(n.codestream,0),!0);if(o.bit=a.bit,i.colorEncoding.wantICC){let e=n.container?.level??5,a=Math.min(t.maxMetadataBytes,268435456),l=yield*r.part("icc").readICCSteps(o,{maxBytes:a,maxProfileBytes:r.iccProfileLimit(e,a)});i={...i,icc:l},yield*r.admitDecodedICCSteps(l,i,e)}let l=yield*V("decode-image-align",()=>(o.align(),o.bit)),s=yield*V("decode-first-frame",()=>{o.bit=l;let e=i.preview?null:r.readDecodeFrameHeader(o,i,t);return e&&r.readDecodeTOC(o,e),e?.modular?e.groupDim:256});return{input:n,h:i,bit:l,group:s}})},readEntropyModel:function*(e,t,r,n){let a=yield*z("decode-entropy-model",function*(){let a=yield*V("decode-entropy-header",()=>n.header(e,t,r));e.bit=a.bit;let i=[];for(let t=0;t<a.model.configs.length;t++){let r=yield*V("decode-entropy-code",()=>({code:n.code(e,a,t),bit:e.bit}));i.push(r.code),e.bit=r.bit}return{model:{...a.model,codes:i},bit:e.bit}});return e.bit=a.bit,a.model},readICC:function*(e,{maxBytes:t,maxProfileBytes:r},n){let a=yield*z("decode-icc",function*(){let a=yield*V("decode-icc-length",()=>n.length(e,t,r));e.bit=a.bit;let i=yield*n.model(e,41),o=n.stream(e,i,{values:a.size,byteHistory:!0}),l=yield*V("decode-icc-prefix",()=>n.prefix(e,o,a,r));e.bit=l.bit;let s=[l.bytes];for(let t=l.bytes.length;;t+=65536){let r=yield*K("decode-icc-state",()=>null,()=>vo(o),!0);if(null!==r&&r!==Ga&&et(o,r),t>=a.size)break;l=yield*V("decode-icc-values",()=>n.part(e,o,t,Math.min(65536,a.size-t),l,a.start)),e.bit=l.bit,s.push(l.bytes)}return yield*V("decode-icc-end",()=>(o.finish(),null)),{bytes:yield*n.decode(_a(s),{maxBytes:r}),bit:e.bit}});return e.bit=a.bit,a.bytes},decodeICC:Lo,admitDecodedICC:function*(e,t,r,n){let a,i=yield*V("decode-icc-space",()=>n.cmyk(e));try{a=yield*n.inspect(e,r,i?"cmyk":void 0)}catch(e){if(e?.[Symbol.for("rapier-jxl.journal.unread")])throw e;n.require(!1,e.message)}yield*V("decode-icc-channels",()=>(n.channels(a,i,t,r),null))},decodeBrotli:Io,readBrotli:Ao}),No=rt("icc-profile"),Oo=Object.freeze({"band-summary":qi,settleFacts:async function(e,t,r,n,a,i=2097152){let o,{shapeScan:l,shapeScanPixels:s,shapeScanNext:u,shapeResult:c,gradientRows:f,flatSampleAt:h,flatSampleY:d,photoPreferenceDifference:m}=t,p=Math.max(2,Math.floor(i/(4*n))),y=Math.ceil(a/p),g=n*a,M=Fa(r,Ua);if(M?.scans?.[0]&&M.flats&&M.gradient&&"function"==typeof M.preference){let t=structuredClone(M.scans[0]);for(;u(t)<g;){let i=Math.floor(u(t)/n/p)*p,o=Math.min(a,i+p),l=await $i(e,()=>{let e=structuredClone(t);return s(e,r.subarray(i*n*4,o*n*4),i*n,(o-i)*n),e});l!==Ga&&(t=l)}o={shape:t,gradient:M.gradient,flats:M.flats,xyb:M.preference()}}else{o={shape:l(g),gradient:{sum:0,n:0},flats:new Uint8Array(256),xyb:0,swept:0};let t=(e,t)=>{let i=structuredClone(e),o=t*p,l=Math.min(a,o+p),c=r.subarray(o*n*4,Math.min(a,l+1)*n*4);if(i.swept===t){if(f(i.gradient,c,n,a,o,l,{row0:o}),n>=32&&a>=32)for(let e=0;e<256;e++){let t=d(a,e);t>=o&&t<l&&(i.flats[e]=h(c,n,a,e,n,0,0,o))}i.xyb+=m(c,n,a,o,l,o),i.swept++}return Math.floor(u(i.shape)/n)>=o&&Math.floor(u(i.shape)/n)<l&&s(i.shape,c,o*n,(l-o)*n),i};for(;;){let r=u(o.shape),a=o.swept<y?o.swept:r<g?Math.floor(r/n/p):-1;if(a<0)break;let i=await $i(e,()=>t(o,a));i!==Ga&&(o=i)}}let b=c(o.shape),w=o.gradient,v=n>=32&&a>=32&&t.screenFromFlags(o.flats),L=w.n?w.chroma/w.n:0,I=b.palette?.colours.length??null,A=!v&&L<2&&Math.min(n,a)>=128&&(I??0)>64;return{eligible:!0,width:n,height:a,pixels:g,shorterSide:Math.min(n,a),gradient:w.n?w.sum/w.n:0,blocks:t.blockFacts(w),visibleShare:w.n?1-(w.clear??0)/w.n:1,smooth:t.exactlyPredicted(w),soft:t.softEdges(w),chroma:L,palette:!!b.palette&&!A,paletteSlots:I,alpha:b.alpha,screenLike:v,preferXYB:Math.min(n,a)<128||o.xyb<=0}},pngPixels:async function(e,t,{readAs:r,deep:n=!0,orient:a=!1,metadata:i=!1,reader:{pngWalk:o,pngLayout:l,pngRows:s,pngPassRows:u,pngOrientationLocation:c,unfilterRow:f,smoothProbes:h,smoothProbe:d,grainSteps:m,grainRow:p,grainShares:y,gradientRows:g,shapeScan:M,shapeScanPixels:b,flatSampleX:w,flatSampleY:v,rankingPositions:L,photoPreferenceDifference:I}}={}){if(void 0!==r&&!i||!n)return null;let A=null;do{let{value:r}=await ze(e,"png-chunks",()=>{let e=A?.next??0,r=Math.min(t.length,e+Math.max(2097152,A?.least??0));return o(structuredClone(A),t.subarray(e,r),e,t.length)},!0);r!==Ga&&(A=r)}while(!A?.done);if(i)return(await ze(e,"png-geometry",()=>c(A))).value;let{value:x}=await ze(e,"png-structure",async()=>{let{width:e,height:r,depth:n,colourType:i,channels:o,interlace:s,expected:u,palette:c,paletteAlpha:f,transparent:h,colour:d,orientation:m,parts:p}=await l(A,!1),y=p.reduce((e,[,t])=>e+t,0),[g,b]=p.length?t.subarray(p[0][0],p[0][0]+2):[];return{taken:(!M||n<=8&&!s)&&(a||!(m>1))&&p[0]?.[1]>=2&&8==(15&g)&&g>>>4<=7&&!((256*g+b)%31)&&!(32&b),width:e,height:r,depth:n,colourType:i,channels:o,interlace:s,expected:u,palette:c,paletteAlpha:f,transparent:h,colour:d,orientation:m,windowSize:1<<(g>>>4)+8,parts:p,stream:y}});if(!x.taken)return null;let{width:N,height:O,depth:P,channels:E,parts:T,stream:U}=x,S=Math.ceil(N*E*P/8),j=Math.max(1,E*P>>3),J=[];for(let e=0,t=0;e<T.length;t+=T[e][1],e++)J.push(t);let F={length:U,read(e,r){if(r<=e)return new Uint8Array(0);let n=0;for(;n+1<T.length&&J[n+1]<=e;)n++;let a=n;for(;a+1<T.length&&J[a+1]<r;)a++;let i=T[n][0]+(e-J[n]),o=T[a][0]+(r-J[a]),l=t.subarray(i,o);if(n===a)return l;let s=new Uint8Array(r-e);for(let t=n,o=0;t<=a;t++){let n=Math.max(e,J[t]),a=Math.min(r,J[t]+T[t][1]);s.set(l.subarray(T[t][0]+(n-J[t])-i,T[t][0]+(a-J[t])-i),o),o+=a-n}return s}};if(!M&&(16===x.depth||x.interlace))return He(e,x,F,{pngRows:s,pngPassRows:u,unfilterRow:f});let k=[],X=Math.ceil(O/io),_=Math.ceil(U/X*1.25)+4096,R=!(0!==x.colourType&&2!==x.colourType&&3!==x.colourType||x.transparent||x.paletteAlpha),B=h?.(N,O)??null,[G,C]=m?.(N,O)??[1/0,1],D={pos:2,bits:0,count:0,final:0,type:-1,left:0,lengths:null,hlit:0,copy:0,distance:0,a:1,b:0,produced:0,span:_,windowSize:x.windowSize,window:new Uint8Array(0),previous:new Uint8Array(S),scans:M?[null,{colour:3}].map(e=>M(N*O,{opacity:!R},e)):[],flags:new Uint8Array(256),edge:[],xyb:0,tail:null,smooth:!!B,grain:[0,0,0,0],gradient:g?{sum:0,n:0}:null,carried:null},W=L?.(N*O)??[],V=[],K=Math.max(1,O/32|0);for(let t=0;t<X;t++){let r=t*io,n=Math.min(io,O-r),a=null,i=null,o=null,l=async()=>{let e=n*(S+1),{output:l,state:u}=Ke(D,e,t===X-1,F),c=new Uint8Array(n*N*4),h=s(x,c,r),m=D.previous.slice(),y=new Uint8Array(S);for(let e=0,t=0;e<n;e++){let n=l[t++];n>4&&ro("PNG contains an unknown row filter; pass a valid PNG file."),f(n,l,t,y,m,S,j),t+=S,h(y,N,0,r+e,1,1,0),[m,y]=[y,m]}let M=structuredClone(D.scans);for(let e of M)b(e,c,r*N,n*N);let L=new Uint32Array(c.buffer),A=D.flags.slice(),P=[];for(let[e,t,r,n]of D.edge)A[e]=(t&&r===L[w(N,e)]?1:0)|(!n||L[w(N,e)]>>>24?0:2);for(let e=0;w&&e<256;e++){let t=w(N,e),a=v(O,e)-r,i=a*N+t;if(a<0||a>=n)continue;let o=L[i]===L[i+1],l=!(L[i]>>>24|L[i+1]>>>24);a+1<n?A[e]=(o&&L[i]===L[i+N]?1:0)|(!l||L[i+N]>>>24?0:2):P.push([e,o,L[i],l])}let E=D.xyb;if(D.tail){let e=new Uint8Array(8*N);e.set(D.tail),e.set(c.subarray(0,4*N),4*N),E+=I(e,N,O,r-1,r,r-1)}let T=t===X-1,U=I&&!T&&(r+n-1)%K==0?c.slice((n-1)*N*4):null;E+=I?.(c,N,O,r,T?r+n:r+n-1,r)??0;let J=4*N,k=e=>e>=r?c.subarray((e-r)*J,(e-r+1)*J):D.carried.subarray((e-r+2)*J,(e-r+3)*J),_=D.smooth;if(_)for(let e of B.ys)if(e>=r&&e<r+n&&_)for(let t of B.xs)if(!d(k(e),k(e-1),t)){_=!1;break}let R=D.grain.slice(),V=t?r-1:1,z=T?O-1:r+n-1;for(let e=1+Math.ceil(Math.max(0,V-1)/G)*G;e<z;e+=G)p(R,k(e-1),k(e),k(e+1),N,C);let H=null;D.gradient&&(H=structuredClone(D.gradient),g(H,c,N,O,r,r+n,{row0:r}));let Y=T?null:n>=2?c.slice((n-2)*J):null;a={...u,previous:m,scans:M,flags:A,edge:P,xyb:E,tail:U,smooth:_,grain:R,gradient:H,carried:Y};let q=[],$=(r+n)*N,Q=0;for(let e=W.length;Q<e;){let t=Q+e>>1;W[t]<r*N?Q=t+1:e=t}for(;Q<W.length&&W[Q]<$+N;Q++){let e=W[Q],t=e/N|0,n=e-t*N,a=n?e-1:t?e-N:-1;[e,a,t?e-N:a,n&&t?e-N-1:a].forEach((e,t)=>{e>=r*N&&e<$&&q.push(4*Q+t,L[e-r*N])})}i=Uint32Array.from(q),o=[];for(let e=0;e<N;e+=oo){let t=Math.min(oo,N-e),r=new Uint8Array(n*t*4);for(let a=0;a<n;a++)r.set(c.subarray(4*(a*N+e),4*(a*N+e+t)),a*t*4);o.push(r)}return o},u=[];for(let t=0;t*oo<N;t++)u.push((await ze(e,"png-rows",async()=>(o??await l())[t],!1,!0,!0,t>0)).value);k.push(u),L&&V.push((await ze(e,"png-picks",async()=>i??(await l(),i),!1,!1,!0,!0)).value);let{value:c}=await ze(e,"png-inflate",async()=>a??(await l(),a),!0,!1,!1,!0);c!==Ga&&(D=c)}let z=D.xyb;return{data:re(k,N,O,io,oo,e.touched,{opaque:R,scans:D.scans,flats:D.flags,smooth:D.smooth,...y&&{grain:y(D.grain)},ranking:()=>{let e=new Uint32Array(4*W.length);for(let t of $a(V))for(let r=0;r<t.length;r+=2)e[t[r]]=t[r+1];return new Uint8Array(e.buffer)},preference:()=>z,...D.gradient&&{gradient:D.gradient}}),width:N,height:O,bitDepth:8,sampleFormat:"uint",...x.colour,alphaPremultiplied:!1,...x.orientation>1&&{orientation:x.orientation}}},prepareICC:function*(e,t,r){return e=ae(e),yield*z("icc-prepare",function*(){let n,a=r.options(t),i=yield*r.inspect(e,t.level,t.colorSpace),o=yield*V("icc-fields",()=>{let n=r.fields(e,t,i);return{...n,colorData:bo(n.colorData)}}),l=yield*V("icc-transform",()=>r.transform(e,!1)),s=_a([l,ae(e,128)]),u=null;if("lz77"!==a)try{u=yield*$e(s,null,r)}catch(e){if("auto"!==a||"JXL_SIZE"!==e.code)throw e;n=e}if("prefix"!==a)try{let e=yield*$e(s,yield*Ye(s,r),r);(!u||e.bitLength<u.bitLength)&&(u=e)}catch(e){if(!u||"JXL_SIZE"!==e.code)throw e}if(!u)throw n;return{...o,iccData:u}})},varDCTFile:function*(e,t,r,n){return yield*z("codestream",function*(){let a=[];for(let e of t)a.push(yield*z("codestream-section",function*(){return e?e.finish():new Uint8Array(0)},void 0,!1,!0));let i=_a(a).sizes,o=yield*V("codestream-header",()=>{let t=new n.BitWriter(256),r=[],a=()=>{(t.at||t.pending)&&(r.push({bytes:t.bytes,at:t.at,pending:t.pending,acc:t.acc}),o+=8*t.at+t.pending,t.bytes=new Uint8Array(256),t.at=t.acc=t.pending=0)},o=0;return Object.defineProperties(t,{bitLength:{get:()=>o+8*t.at+t.pending},append:{value:e=>{a(),(e.at||e.pending)&&(r.push({bytes:e.bytes,at:e.at,pending:e.pending,acc:e.acc}),o+=8*e.at+e.pending)}},zeroPadToByte:{value:()=>{let e=7&-t.bitLength;e&&t.write(e,0)}}}),e(t),n.writeTOC(t,i),a(),{bits:o,parts:r}}),l=[],s=0,u=0;for(let e of o.parts)for(let t=0;t<e.at||!t&&e.pending;t+=65535){let r=Math.min(e.at,t+65535),a=r===e.at,i=yield*z("codestream-header-part",function*(){let i=new n.BitWriter(r-t+16);return i.acc=s,i.pending=u,i.append({bytes:e.bytes.subarray(t,r),at:r-t,acc:a?e.acc:0,pending:a?e.pending:0}),bo(i)},void 0,!1,!0);l.push(i.bytes),s=i.acc,u=i.pending}return n.codestreamFromParts(_a(l),a,r,_a)})},inspectICC:function*(e,t,r,n){return yield*z("icc-admission",function*(){let a=yield*V("icc-admission-header",()=>n.header(e,t,r));for(let t=0;t<a.count;t+=4096)yield*V("icc-admission-tags",()=>(n.tags(e,a,t,Math.min(a.count,t+4096)),null));return a.channels})},jpegProgressive:function*(e,t,r,n,a,i,o,l,s,u,c,f){let{ScanReader:h,readUnits:d,finishScan:m}=f,p=yield*z("scan-"+r.scans,function*(){let f=1===n.length,p=n[0].component,y=f?p.blocksW*p.blocksH:r.mcusX*r.mcusY,g=f?p.blocksW*p.v:r.mcusX,M=new h(e,t,r,n,a,i,o,l,u,c);for(let e of n)e.component.pred=0;M.load();let b=()=>({...M.here(),preds:n.map(e=>e.component.pred),block:M.blockIndex,eobrun:M.eobrun,resets:u?.resets??null,zeros:u?.zeros??null,padding:c&&{bits:c.bits,zero:c.zero}});for(let e=0,t=0;e<y;e+=g,t++){let a=yield*z("scan-coefficients",function*(){$a(n.map(e=>e.component.parts[t]));for(let{component:e}of n)e.coeffs=e.parts[t]?Int16Array.from(e.parts[t]):new Int16Array(e.stride*e.v*64),e.row0=t*e.v;return d(M,r,n,e,Math.min(y,e+g),s),n.map(e=>e.component.coeffs)},void 0,!1,!0);n.forEach((e,r)=>{e.component.parts[t]=a[r]});let i=yield*K("scan-state",()=>null,b,!0);null===i||i===Ga||(M.pos=i.pos,M.load(),M.bit=i.bit,M.blockIndex=i.block,M.eobrun=i.eobrun,n.forEach((e,t)=>{e.component.pred=i.preds[t]}),u&&(u.resets=i.resets,u.zeros=i.zeros),c&&(c.bits=i.padding.bits,c.zero=i.padding.zero))}M.atMarker(!0);let w=m(e,M.pos,y,s,u);for(let{component:e}of n)e.coeffs=null,e.row0=-1;return{pos:w,parts:n.map(e=>e.component.parts),choices:u,padding:c&&{bits:c.bits,zero:c.zero}}},void 0,!1,!0);return n.forEach((e,t)=>{e.component.parts=p.parts[t]}),u&&Object.assign(u,p.choices),c&&Object.assign(c,p.padding),p.pos},jpegSummary:function*(e){let t=yield*z("coefficient-summary",function*(){let t=e.components.map(e=>({dc:new Int16Array(e.stride*e.rows),natural:new Uint32Array(64)}));for(let r=0;r<e.mcusY;r++){let n=yield*z("row-summary",function*(){return $a(e.components.map(e=>e.parts[r])),e.components.map(e=>{let t=e.parts[r],n=new Int16Array(e.stride*e.v),a=new Uint32Array(64);for(let e=0;e<t.length;e+=64){n[e/64]=t[e];for(let r=0;r<64;r++)t[e+r]&&a[r]++}return{dc:n,natural:a}})});for(let a=0;a<t.length;a++){t[a].dc.set(n[a].dc,r*e.components[a].stride*e.components[a].v);for(let e=0;e<64;e++)t[a].natural[e]+=n[a].natural[e]}}return t});e.components.forEach((e,r)=>{e.dc=t[r].dc,e.natural=t[r].natural})},containerBoxes:function*(e,t,r,n){let{admitBoxes:a,boxCursor:i,boxWords:o,nextBox:l,endBoxes:s,reconstructionBox:u}=n;a(e,t);let c=i(),f=[];for(;c.at<e.length;){let n=yield*V("container-boxes",()=>{let n=new Map,a={...c,prefixes:{has:e=>n.has(e)||c.prefixes.has(e),set:(e,t)=>n.set(e,t)}},i=o(e),s=[];for(let n=0;n<64&&a.at<e.length;n++){let n=l(e,t,a,i);if(!n)break;r&&u(n,a),s.push(n)}let{prefixes:f,...h}=a;return{rows:s,cursor:h,additions:[...n]}});Object.assign(c,n.cursor);for(let[e,t]of n.additions)c.prefixes.set(e,t);f.push(...n.rows)}return yield*V("container-end",()=>(s(c),null)),f},jpegContainer:function*(e,t){let{reconstructionStart:r,containerBoxesSteps:n,reconstructionPart:a,reconstructionEnd:i,maximum:o}=t;return yield*z("jpeg-container",function*(){let t=r(e);if(!t)return null;let l=(t,r)=>ae(e,t,r);for(let r of yield*n(e,o,!0))a(t,r,l);return i(t,_a)})},containerRead:function*(e,t,r){let{limit:n,boxLimit:a,containerStart:i,containerNext:o,containerEnd:l,containerSignature:s,boxWords:u,fourcc:c,invalid:f,ignored:h}=r,d=n(t),m=a(t);return yield*z("container-read",function*(){let t=yield*V("container-start",()=>i(e,d));if(t.raw)return{codestream:e,level:5,minorVersion:0,auxiliary:[]};let r=[],n=new Map,a=(t,r)=>ae(e,t,r);for(;t.at<e.length;){let i=yield*V("container-boxes",()=>{let r=new Map,n=new Map,i=u(e),l=[],s={...t,prefixes:{has:e=>n.has(e)||t.prefixes.has(e),set:(e,t)=>n.set(e,t)}},f={set:(e,t)=>r.set(e,t)};for(let t=0;t<64&&s.at<e.length;t++){let t=o(e,m,s,i,a,f);if(!t)break;h.includes(t.entry.type)||l.push({boxType:c(t.entry.type),data:t.entry.data,extended:16===t.entry.headerLength})}let{prefixes:d,...p}=s;return{state:p,prefixes:[...n],auxiliary:l,additions:[...r]}});Object.assign(t,i.state);for(let[e,r]of i.prefixes)t.prefixes.set(e,r);r.push(...i.auxiliary);for(let[e,t]of i.additions)n.set(e,t)}yield*V("container-end",()=>(l(t),null));let p=t.full;if(!p){let e=[];for(let r=0;r<t.next;r+=64)e.push(...yield*V("container-fragments",()=>{let e=[];for(let a=r;a<Math.min(t.next,r+64);a++){if(!n.has(a))throw f("Missing JPEG XL codestream fragment.");e.push(n.get(a))}return e}));p=_a(e)}return yield*V("container-signature",()=>(s(p),null)),{codestream:p,level:t.level,minorVersion:t.minorVersion,auxiliary:r}})},boundedHeader:function*(e,t,{header:r}){return yield*z("complete-image-header",function*(){return yield*V("image-header-prefix",()=>r(e,{...t,complete:!0}))})},jpegScanRows:function*({out:e,jpeg:t,writer:r,preds:n,ny:a,per:i,pad:o},l){let{rows:s}=l;if(e.parts)for(let u=0;u<a;u+=i){e.parts.push(yield*V("scan-part",()=>(s(u,Math.min(a,u+i)),e.take())));let c=yield*K("scan-state",()=>null,()=>({done:e.done,acc:e.acc,pending:e.pending,block:r.blockIndex,preds:n,nextReset:l.nextReset(),pad:o?.at??0,eob:r.eob,eobTable:r.eobTable,corrections:r.pending.subarray(0,r.pendingBits),coefficients:t.checkpoint()}),!0);null===c||c===Ga||(Object.assign(e,{done:c.done,acc:c.acc,pending:c.pending,at:0,chunks:[]}),r.blockIndex=c.block,n.set(c.preds),l.restoreReset(c.nextReset),o&&(o.at=c.pad),r.eob=c.eob,r.eobTable=c.eobTable,r.pending=c.corrections.slice(),r.pendingBits=r.pending.length,t.resume(c.coefficients))}else for(let t=0,u=i%2?i:i/2;t<a;t+=u){let i=yield*K("scan-rows",()=>s(t,Math.min(a,t+u)),()=>(e.spill(0),{done:e.done,same:e.same,acc:e.acc,pending:e.pending,block:r.blockIndex,preds:n,nextReset:l.nextReset(),pad:o?.at??0,eob:r.eob,eobTable:r.eobTable,corrections:r.pending.subarray(0,r.pendingBits)}));null===i||i===Ga||(Object.assign(e,{done:i.done,same:i.same,acc:i.acc,pending:i.pending,at:0}),r.blockIndex=i.block,n.set(i.preds),l.restoreReset(i.nextReset),o&&(o.at=i.pad),r.eob=i.eob,r.eobTable=i.eobTable,r.pending=i.corrections.slice(),r.pendingBits=r.pending.length)}},jpegMarker:function*(e,t){let r=yield*V("jpeg-marker",()=>(t(),{bytes:e.expected?(e.spill(0),null):e.take(),done:e.done,same:e.same}));e.parts&&e.parts.push(r.bytes),Object.assign(e,{done:r.done,same:r.same,at:0,chunks:[]})},jpegScan:function*(e,t,r){if(e.expected){let n=yield*z("jpeg-scan",function*(){return yield*r(),e.spill(0),{done:e.done,same:e.same,pad:t?.at??0}});Object.assign(e,{done:n.done,same:n.same,at:0,acc:0,pending:0}),t&&(t.at=n.pad)}else{let n=e.parts.length,a=yield*z("jpeg-scan",function*(){yield*r();let a=yield*V("scan-end",()=>e.take());return{bytes:_a([...e.parts.slice(n),a]),done:e.done,pad:t?.at??0}});e.parts.length=n,e.parts.push(a.bytes),Object.assign(e,{done:a.done,acc:0,pending:0,at:0,chunks:[]}),t&&(t.at=a.pad)}},jpegEnd:function*(e,t,r){r(!e.pending&&e.done+e.at+t.length<=e.limit);let n=yield*V("jpeg-end",()=>e.take());return _a([...e.parts,n,t])},jpegStructure:function*(e,t,r){let n=r.create(t),a=r.start(t);for(;!a.ended;){let i=yield*V("structure-window",()=>r.window(e,t,a));a=i.state;let o=[];for(let e of i.data.scans){let n=e.resets?yield*z("structure-resets",function*(){return r.choices(t,e.index,!1)},void 0,!1,!0):new Uint32Array(0),a=e.zeros?yield*z("structure-zeros",function*(){return r.choices(t,e.index,!0)},void 0,!1,!0):new Uint32Array(0);o.push(r.scan(e,n,a))}r.append(n,i,o)}return r.finish(n,a,t)},jpegSyntax:function*(e,t){let r=[],n=0,a=0;for(let[i,o,l,s]of e)for(let e=0;e<o;e+=l){let u=yield*z(i,function*(){let r=new t;return r.pending=n,r.acc=a,s(r,e,Math.min(o,e+l)),{bytes:r.bytes.subarray(0,r.at),pending:r.pending,acc:r.acc}},void 0,!1,!0);r.push(u.bytes),n=u.pending,a=u.acc}return _a(r)},jpegPayload:function*(e,t,r){let n,a=[];for(let i=0;i<e.apps.length;i+=64){let o=yield*V("jpeg-payload-apps",()=>r.apps(e.apps.slice(i,i+64),t,n));n=o.state,a.push(...o.cuts)}let i=r.offset(e,n?.curOff??0);for(n={at:0,phase:"search",done:!1};!n.done;){let t=yield*V("jpeg-payload-tail",()=>r.tail(e.tail,n));n=t.state;for(let e of t.cuts)a.push(i+e)}return r.finish(a,i+e.tail.length)},jpegICC:No,jpegICCEntropy:function*(e,t){return yield*z("icc-entropy",function*(){let r=yield*V("icc-entropy-header",()=>t.header(e));e.bit=r.bit;let n=t.reader(r.model,e,r.size),a=[],i=0,o=0;for(let l=0;l<r.size;l+=65536){let s=yield*V("icc-entropy-part",()=>t.part(e,n,r,l,i,o));a.push(s.bytes),i=s.previous,o=s.older,e.bit=s.bit;let u=yield*K("icc-entropy-state",()=>null,()=>n.checkpoint(),!0);null!==u&&u!==Ga&&n.resume(u)}return yield*V("icc-entropy-end",()=>(n.finish(),null)),{bytes:_a(a),bit:e.bit}})},...xo}),Po=e=>Array.isArray(e)?e.map(Po):e&&"object"==typeof e?Object.fromEntries(Object.keys(e).sort().filter(t=>void 0!==e[t]).map(t=>[t,Po(e[t])])):e,Eo=e=>[...e].map(e=>e.toString(16).padStart(2,"0")).join(""),To=e=>e>>>1^-(1&e),Uo=class{constructor(e,t=!1){if(!(e instanceof Uint8Array))throw Vr("JXL_INPUT","JPEG XL bytes must be a Uint8Array.");this.bytes=e,this.borrowed=t;let r=!t&&e.length<=67108864?new Uint8Array(e.length+8):e;r!==e&&r.set(e),this.buf=r,this.bit=0}get remaining(){return 8*this.bytes.length-this.bit}peek(e){if((0|e)===e&&e>=0&&e<=32||ot(!1,"Invalid JPEG XL bit count.",this),!e)return 0;let t=this.bit<4294967296?this.bit>>>3:Math.floor(this.bit/8),r=7&this.bit,n=this.buf,a=n[t]>>>r|n[t+1]<<8-r|n[t+2]<<16-r|n[t+3]<<24-r;return r&&(a|=n[t+4]<<32-r),32===e?a>>>0:a&(1<<e)-1}skip(e){Number.isSafeInteger(e)&&e>=0&&e<=8*this.bytes.length-this.bit||ot(!1,"Truncated JPEG XL data.",this),this.bit+=e}read(e){if((0|e)===e&&e>=0&&e<=32||ot(!1,"Invalid JPEG XL bit count.",this),!e)return 0;let t=this.bit;e>8*this.bytes.length-t&&ot(!1,"Truncated JPEG XL data.",this);let r=t<4294967296?t>>>3:Math.floor(t/8),n=7&t,a=this.buf,i=a[r]>>>n|a[r+1]<<8-n|a[r+2]<<16-n|a[r+3]<<24-n;return n&&(i|=a[r+4]<<32-n),this.bit=t+e,32===e?i>>>0:i&(1<<e)-1}expect(e,t){ot(this.read(e)===t,"Invalid JPEG XL field.",this)}u32(e){let[t,r]=e[this.read(2)],n=this.read(t)+r;return ot(n<=4294967295,"JPEG XL integer exceeds 32 bits.",this),n}u64BigInt(){let e=this.read(2);if(0===e)return 0n;if(1===e)return BigInt(this.read(4)+1);if(2===e)return BigInt(this.read(8)+17);let t=BigInt(this.read(12));for(let e=12;this.read(1)&&(t|=BigInt(this.read(60===e?4:8))<<BigInt(e),60!==e);e+=8);return t}u64(){let e=this.u64BigInt();if(e>9007199254740991n)throw Object.assign(new RangeError("JPEG XL integer exceeds the safe range."),{code:"JXL_LIMIT",bitOffset:this.bit});return Number(e)}f16(){let e=this.read(16),t=e>>>10&31,r=1023&e;ot(31!==t,"Nonfinite JPEG XL half float.",this);let n=t?(1024+r)*(1<<t>>>0)/33554432:r/16777216;return 32768&e?-n:n}enum(){return this.u32([[0,0],[0,1],[4,2],[6,18]])}align(){this.expect(7&-this.bit,0)}end(){this.align(),ot(0===this.remaining,"Trailing JPEG XL section data.",this)}endSection(){for(this.align();this.remaining;)ot(0===this.read(8),"Trailing JPEG XL section data.",this)}};{let e=new Uo(new Uint8Array(8));for(let t=0;t<20;t++)e.bit=0,e.peek(0),e.peek(1),e.peek(32),e.read(0),e.read(1),e.read(32)}var So=Object.freeze({inverseMatrix:Object.freeze([11.031566901960783,-9.866943921568629,-.16462299647058826,-3.254147380392157,4.418770392156863,-.16462299647058826,-3.6588512862745097,2.7129230470588235,1.9459282392156863]),opsinBiases:Object.freeze(Array(3).fill(-.0037930732552754493)),quantizationBiases:Object.freeze([.945349926692846,.9299455010825141,.9500648966626563,.145])}),jo=new Uint8Array([0,0,0,12,74,88,76,32,13,10,135,10]),Jo=1718909296,Fo=1786276896,ko=1651666786,Xo=1784836708,_o=(function(e){let t=0,r=0,n=0,a=0;for(let i=0;i<e.length;i++)if(e[i]){let o=e[i];ot(o<=15,"Invalid JPEG XL prefix length."),t=Math.max(t,o),r++,n=i,a+=32768>>>o}if(ot(r>0&&(1===r||32768===a),"Invalid JPEG XL prefix tree."),1===r)return{single:n,bits:0,mask:0,table:null};let i=[17,11,15,3,9,7,4,2,5,6,0,33,1,65]||st(e),o=new Uint32Array(1<<t);for(let t=0;t<e.length;t++)if(e[t]){let r=e[t],n=32*t+r;for(let e=i[t];e<o.length;e+=1<<r)o[e]=n}}([5,4,4,4,4,4,3,3,3,3,3,6,7,7]),[[9,1],[13,1],[18,1],[30,1]]),Ro=[[0,1],[1,1],[12,10],[4,3],[3,2],[16,9],[5,4],[2,1]],Bo={bits:8,exponentBits:0,float:!1},Go=(e,t)=>Array.from({length:e},t),Co=e=>!!e.read(1),Do=e=>e.toLocaleString("en-US"),Wo=new Set(["JXL_DECODE","JXL_DIMENSIONS","JXL_INPUT","JXL_LIMIT"]),Vo=(e,t={})=>bt(e,{...t,complete:!0}),Ko=1786276969,zo=1785227117,Ho=65536,Yo=(e,t="pass a valid JPEG XL file")=>Vr("JXL_INPUT",`${e}; ${t}.`),qo=(e,t)=>(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0,$o=["perceptual","relative","saturation","absolute"],Qo={uint8:{bitDepth:8,sampleFormat:"uint"},uint16:{bitDepth:16,sampleFormat:"uint"},float32:{bitDepth:32,sampleFormat:"float32"}},Zo=["srgb","display-p3","rec2020"],el=["srgb","linear","pq","hlg"],tl=e=>!!e&&"object"==typeof e&&Object.hasOwn(e,"rgbaColorEncoding")&&Object.hasOwn(e,"format")&&ArrayBuffer.isView(e.data),rl=["colorSpace","transferFunction","bitDepth","sampleFormat","intensityTarget"],nl=(e,t)=>e===t||JSON.stringify(e)===JSON.stringify(t),al={readJPEGSteps:e=>(e&&Vn in e?e[Vn]:Wn())?.restore?.[Symbol.for("rapier-jxl.verify.source")]},il=(new Uint8Array([0,0,0,12,74,88,76,32,13,10,135,10])," is unavailable here; call configureDecoder(decode, restore) from rapier-jxl/verify, with decode from rapier-jxl/decode and restore from rapier-jxl/jpeg."),ol=e=>e&&Vn in e?e[Vn]:Wn(),ll=(e,t)=>ol(t)?.[e]??al?.[e],sl=Symbol.for("rapier-jxl.verify.without-noise"),ul=e=>!!ll("decode",e)?.[sl],cl=e=>ol(e)?.restore?.[Symbol.for("rapier-jxl.verify.source")],fl=e=>null!==al||("function"!=typeof globalThis.createImageBitmap||"function"!=typeof globalThis.OffscreenCanvas)&&"function"==typeof cl(e)?.open,hl=e=>al?.readJPEGSteps?.(e)??cl(e),dl=e=>ol(e)?.restore?.[Symbol.for("rapier-jxl.steps")]??al?.restoreSteps,ml=e=>ll("decode",e)?.[Symbol.for("rapier-jxl.verify.groups")],pl=e=>!!ml(e)?.open&&!!ml(e)?.region,yl=e=>!!ml(e)?.open&&!!ml(e)?.withoutNoise,gl="Bounded verification"+il,Ml=e=>"JXL_PLATFORM"===e?.code&&"string"==typeof e.message&&e.message.endsWith(il),bl=[[0,0],[0,1],[4,2],[6,18]],wl=[[19,0],[19,524288],[20,1048576],[21,2097152]],vl={d65:1,e:10,dci:11},Ll={srgb:1,"display-p3":11,rec2020:9},Il={bt709:1,linear:8,srgb:13,pq:16,dci:17,hlg:18},Al={perceptual:0,relative:1,saturation:2,absolute:3},xl=[];for(let e=1,t=0;t<16;t++){xl.push(e);let t=2*e*e;do{e++}while(e*e<t)}xl.slice().reverse().map(e=>-e);var Nl=new Set,Ol=new Set,Pl=(e,t)=>{Nl.add(e),Ol.add(t)},{ensureKernels:El,disableEntropyKernels:Tl,prepareKernels:Ul,arenaKernels:Sl,releaseArena:jl,lendEntropy:Jl,orientBlock:Fl,pngRow:kl,sampleTable:Xl,sampleBands:_l,captureAnsWrite:Rl,writeAnsTokens:Bl}=(()=>{function e(){let{memory:e,exports:t}=g();i=M(()=>{if(F)throw Vr("JXL_INTERNAL","The kernels' arena was taken under deferred AC counts.");T=!1,U=null,S=!1,j=!1,P=null,O=null,J=null,B=null,R=-1,X=-1,v=-1,N="",E++},()=>{r.u8=new Uint8Array(e.buffer),r.i32=new Int32Array(e.buffer)},()=>u?.(new Int32Array(e.buffer)));let n=w(t,i),a=new Uint8Array(e.buffer),o=new Int32Array(e.buffer);return u?.(o),{memory:e,simd:n,u8:a,i32:o}}function t(){if("simd"===n)return!0;try{if("object"!=typeof WebAssembly||1!==new Uint8Array(new Uint32Array([1]).buffer)[0]||!Xn())return!1;r||=e(),n="simd";for(let e of s)Jn[e]&&(Jn[e]=l(Jn[e]))}catch{n="off";for(let e of s)Jn[e]=null}return"simd"===n}let r,n="off",a=!0,i=null,o=new Map,l=e=>o.get(e)??o.set(e,function(...t){return b(i),e.apply(this,t)}).get(e),s=["channel","weighted","fill","palette","rct","tuple","passLevels","group","screen","sampled","dct","ycbcrTile","ycbcrTiles","rgbTiles","rgbBand","photoTile","acGroup","acGroupPair","acDeferred","opaque","nonzero","entropy","varblock","gaborish","strategyFill","strategyWrite","xybPlanes","gabBand","dcEvents","dcPlan","planTokens","shape","nativeRGBA","s2cChannel"],u=null,c=65536,f=589824,h=638984,d=770056,m=262144,y=null,v=-1,L=function(e=1294344){if("simd"!==n||!r.simd.sampleBand)throw Vr("JXL_WASM","The sample resampling kernel is unavailable.");let t=v===E;if(T=!1,U=null,S=!1,j=!1,P=null,J=null,E++,t&&(v=E),r.memory.buffer.byteLength<e){try{r.memory.grow(Math.ceil((e-r.memory.buffer.byteLength)/65536))}catch(e){throw Object.assign(Vr("JXL_MEMORY","Not enough memory for the resampling kernel."),{cause:e})}r.u8=new Uint8Array(r.memory.buffer),r.i32=new Int32Array(r.memory.buffer)}return r.memory.buffer},I=function(e){if(e)throw Vr("JXL_INPUT",[null,"Resampling requires finite alpha between zero and one.","Resampling requires finite color samples.","PQ resampling requires samples between zero and one.","HLG resampling requires nonnegative samples.","The resampled value exceeds the sample format."][e])},A=null,x=null,N="",O=(new WeakMap,new WeakMap,new WeakMap,null),P=null,E=0,T=!1,U=null,S=!1,j=!1,J=null,F=null,k=(new WeakMap,new WeakMap,null);Pl(()=>{k&&(k.at=0)},()=>{k=null});let X=-1,_=(new Int32Array(81),new Uint8Array(6144));for(let e=0;e<256;e++)for(let t=0,r=0;t<8;t++)e>>t&1&&(_[16*e+2*r]=2*t,_[16*e+2*r+1]=2*t+1,_[4096+8*e+r++]=t);let R=-1,B=null;return new Map,Jn.ensure=t,{ensureKernels:t,disableEntropyKernels:function(){a=!1,Jn.entropy=null},prepareKernels:async function(){return!("object"!=typeof WebAssembly||1!==new Uint8Array(new Uint32Array([1]).buffer)[0]||!Xn())&&p("kernels",()=>gn(Fn))},arenaKernels:null,releaseArena:null,lendEntropy:()=>null,orientBlock:function(e,t,a,i,o,l,s,u,c,f,h,d){if("simd"!==n||!r.simd.orientRGBA)throw Vr("JXL_WASM","The sample orientation kernel is unavailable.");if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array)||![4,8,16].includes(h)||!Number.isInteger(s)||!Number.isInteger(u)||s<1||u<1||s>256||u>256||!Number.isInteger(d)||d<1||d>8)throw Vr("JXL_INTERNAL","Invalid sample orientation block.");T=!1,U=null,S=!1,j=!1,P=null,J=null,E++;let m=65536+s*u*h,p=new Uint8Array(r.memory.buffer),y=s*h;for(let t=0;t<u;t++){let r=((l+t)*a+o)*h;p.set(e.subarray(r,r+y),65536+t*y)}r.simd.orientRGBA(65536,s,u,h,d,m);let g=d>=5?s:u,M=(d>=5?u:s)*h;for(let e=0;e<g;e++){let r=m+e*M;t.set(p.subarray(r,r+M),((f+e)*i+c)*h)}},pngRow:function(e,t,n,a,i,o,l,s,u,c,f){let h=new Uint8Array(L(65536+3*t+4*c));if(h.set(e.subarray(0,t),65536),s)return r.simd.pngWiden(65536,c,f,65536+t),s.set(h.subarray(65536+t,65536+t+4*c),u);h.set(n.subarray(0,t),65536+t),h.set(a.subarray(i,i+t),65536+2*t),r.simd.pngUnfilter(o,65536+2*t,65536,65536+t,t,l),e.set(h.subarray(65536,65536+t))},sampleTable:function(e,t){if(![255,1023,4095,65535].includes(e)||!Number.isInteger(t)||!(t>=0&&t<=4||t>=1221&&t<=1e7))throw Vr("JXL_INTERNAL","Invalid sample transfer table.");let n=L();return r.simd.sampleTable(t,e,c,0),y=new Float64Array(n,c,e+1).slice(),v=E,y},sampleBands:function(e,t,n,a,i,o,l,s){if(![e,t,n,a].every(e=>Number.isInteger(e)&&e>=1)||![1,2,4].includes(s)||l&&(!(i[0]<2&&[255,1023,4095].includes(i[1]))||i[3]||1!==i[4]))throw Vr("JXL_INTERNAL","Invalid sample resampling band.");let u=32*Math.max(e,n),p=4*e*s,g=4*n*s,M=Math.max(1,Math.min(t,Math.floor(m/e))),b=Math.max(1,Math.min(a,Math.floor(m/n))),w=d,O=w+3*u,P=w+4*u,T=P+12*n+7&-8,U=T+8*(e+2*n),S=U+M*p,j=S+b*g;return{sourceRows:M,outRows:b,run(s,m,J,F,k,X,_,R,B){if(J-m>M||J<=m||k-F>b||F<0||k>a||F>=k||m<0||J>t||R&&R.length!==4*n)throw Vr("JXL_INTERNAL","Invalid sample resampling band.");let G=L(j),C=new Uint8Array(G);o&&(y!==o||v!==E)&&(new Float64Array(G).set(o,8192),y=o,v=E);let D=i[1]+":"+i[2];l&&N!==D?(r.simd.sampleTable(i[2],i[1],d,f),r.simd.sampleSafe(f,i[1],h),A=C.slice(f,638980),x=C.slice(h,770056),N=D):l&&(C.set(A,f),C.set(x,h)),C.set(new Uint8Array(s.buffer,s.byteOffset+m*p,(J-m)*p),U),R&&new Float64Array(G).set(R,O>>3),r.simd.samplePlan(e,n,P,T),I(r.simd.sampleBand(U,m,J,R?1:0,e,t,n,a,F,k,...i,o?c:0,l?f:0,l?h:0,P,T,w,u,S));let W=k-F-(B?1:0);return new Uint8Array(X.buffer,X.byteOffset+_*g,W*g).set(C.subarray(S,S+W*g)),B?new Float64Array(G,O,4*n).slice():null}}},captureAnsWrite:null,writeAnsTokens:null}})(),Gl=e=>{throw Vr("JXL_INPUT",e)},Cl=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Dl={srgb:[.64,.33,.3,.6,.15,.06,.3127,.329],"display-p3":[.68,.32,.265,.69,.15,.06,.3127,.329],rec2020:[.708,.292,.17,.797,.131,.046,.3127,.329]},Wl=Uint32Array.from({length:256},(e,t)=>{for(let e=0;e<8;e++)t=t>>>1^(1&t?3988292384:0);return t>>>0}),Vl=(()=>{let e=new Uint32Array(2048);e.set(Wl);for(let t=0;t<256;t++)for(let r=1;r<8;r++){let n=e[256*(r-1)+t];e[256*r+t]=n>>>8^Wl[255&n]}return e})(),Kl={0:1,2:3,3:1,4:2,6:4},zl=e=>{throw Vr("JXL_INPUT",e)},Hl=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Yl=[[0,0,8,8],[4,0,8,8],[0,4,4,8],[2,0,4,4],[0,2,2,4],[1,0,2,2],[0,1,1,2]],ql=e=>"string"==typeof e&&/^sha256:[a-f0-9]{64}$/.test(e),$l=e=>e&&"string"==typeof e.code&&/^JXL_[A-Z_0-9]+$/.test(e.code)&&"string"==typeof e.message&&l(e)===e,Ql=e=>Number.isSafeInteger(e)&&e>0,Zl=e=>"number"==typeof e&&Number.isFinite(e),es=e=>Zl(e)&&e>=1&&e<=100,ts=(Number.MAX_SAFE_INTEGER,Symbol.for("rapier-jxl.retain-input"),Object.fromEntries(["buffer","byteOffset","byteLength"].map(e=>[e,Object.getOwnPropertyDescriptor(DataView.prototype,e).get])),Uint8Array.prototype.slice,Uint8Array,Uint8ClampedArray,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,"function"==typeof Float16Array&&Float16Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array,DataView,({width:e,height:t,orientation:r})=>r>=5?{width:t,height:e}:{width:e,height:t}),rs=(e,t=1)=>Math.max(t,Math.min(64,Math.floor(16384/e/t)*t)),ns=e=>e.map(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),as=(e,t)=>(r,n)=>$(e.map(e=>()=>{e.ahead?.(r*t*4,(r+n)*t*4);let a=e.subarray(r*t*4,(r+n)*t*4);return new Float32Array(a.buffer,a.byteOffset,a.byteLength/4)})),is=Symbol.for("rapier-jxl.verify.whole-frame"),os=256,ls=1<<20,ss=65536,us=["format","extraChannels","colorEncoding","icc","rgbaColorEncoding","rgbaICC","alphaPremultiplied","orientation","orientationApplied","animation","bitDepth","sampleFormat","colorSpace","transferFunction","header","colorScope"],cs=e=>({colorSpace:"original",applyOrientation:!1,unpremultiplyAlpha:!1,renderSpotColors:!1,maxPixels:e.maxPixels,signal:e.signal,...e&&Vn in e&&{[Vn]:e[Vn]}}),fs=e=>e.orientation>=5?{width:e.height,height:e.width}:{width:e.width,height:e.height},hs=e=>255===e[0]&&10===e[1]||0===e[0]&&74===e[4]&&88===e[5]&&76===e[6],ds=e=>async(t,r,n={})=>{let a,i=await e({unit:t,...n,...n.cold&&{borrowed:!0}});if(i&&Object.hasOwn(i,Na))return{value:i[Na]};try{a=await r()}catch(r){throw await e({unitFailed:t}),r}return await e({unitDone:t,value:a}),{value:a}},ms=(e,t)=>{let r=Object.assign(r=>e.journal(Object.fromEntries(Object.entries(r).map(([e,r])=>[e,["unit","unitDone","unitFailed"].includes(e)?t+r:r]))),{tools:e.journal.tools,touched:e.journal.touched,join:e.journal.join,step:e.journal.step});return{...e,journal:r,unit:ds(r)}},ps=64,ys=async(e,t)=>await Ft(e,t)??Promise.reject(fn("JXL_UNSUPPORTED","Decoder cannot read samples without noise; configure a decoder that provides them.")),gs={"encode:rapier-jxl lossy decode":{1:[[1000230,100663296,0,109051904,0,872]],2:[[1000230,103809024,0,112197632,0,877]],3:[[1000230,106954752,0,113246208,0,974]],4:[[1000230,102760448,0,115343360,0,1077]],5:[[1000230,101711872,0,116391936,0,982]]},"fit:rapier-jxl lossy decode":{1:[[1000230,104857600,0,113246208,0,941]],2:[[1000230,111149056,0,117440512,0,995]],3:[[1000230,104857600,0,118489088,0,952]],4:[[1000230,108003328,0,117440512,0,1149]],5:[[1000230,109051904,0,117440512,0,1124]]},"jpeg:recompress":{1:[[1000230,45508198,1,37748736,1,322],[3999188,57042534,1,56623104,1,568],[12192768,84305510,1,85983232,1,1021]],2:[[1000230,45508198,1,46137344,1,403],[3999188,62285414,1,62914560,1,814],[12192768,69625446,1,91226112,0,1491]],3:[[1000230,46556774,1,46137344,1,550],[3999188,55993958,1,62914560,1,754],[12192768,76021760,1,94371840,0,1546]],4:[[1000230,48653926,1,57671680,1,915],[3999188,63333990,1,75497472,1,1484],[12192768,70778880,1,119537664,0,2570]],5:[[1000230,55993958,1,61865984,1,1377],[3999188,61236838,1,80740352,1,1812],[12192768,82208358,1,134217728,0,3445]],6:[[1000230,53896806,1,63963136,1,1335],[3999188,66479718,1,80740352,1,1793],[12192768,87451238,0,135266304,0,3225]],7:[[1000230,51799654,1,60817408,1,1400],[3999188,61236838,1,87031808,1,2123],[12192768,82208358,1,135266304,0,4245],[24387454,107374182,0]],8:[[1000230,62285414,1,75497472,1,2098],[3999188,84305510,1,94371840,0,3154],[12192768,111568486,0]],9:[[1000230,74868326,1,105906176,0,3258],[3999188,91645542,0],[12192768,154560102,0]]},"jpeg:restore":{any:[[1000230,40370176,1,38797312,1,366],[3999188,47710208,1,48234496,1,619],[12192768,75078042,1,71303168,1,1045],[24387454,78118912,1,78643200,1,1749]]},"verify jpeg":{any:[[1000230,44564480,1,39845888,1,394],[3999188,55050240,1,63963136,1,843],[12192768,67633152,1,85983232,1,1210],[24387454,85458944,1,114294784,0,1780]]},"encode:rapier-jxl/upload lossy":{3:[[249841,55574528,1,57671680,1,468],[499392,63963136,1,66060288,1,632],[1000230,84934656,1,88080384,0,929],[1500254,106954752,0,111149056,0,1093]],2:[[249841,49283072,1,55574528,1,503],[499392,66060288,1,66060288,1,649],[1000230,80740352,1,92274688,0,832],[1500254,103809024,0,102760448,0,1113]],1:[[249841,50331648,1,59768832,1,487],[499392,67108864,1,67108864,1,685],[1000230,84934656,1,87031808,1,928],[1500254,110100480,0,106954752,0,1068]]},"encode:rapier-jxl/upload exact":{1:[[249841,49283072,1,50331648,1,274],[499392,50331648,1,59768832,1,315],[1000230,66060288,1,75497472,1,542],[1500254,73400320,1,87031808,1,701],[2000425,76546048,1,99614720,0,727],[2499794,82837504,1,109051904,0,938],[3e6,80740352,1],[3499200,90177536,0]],2:[[249841,70254592,1,83886080,1,647],[499392,99614720,0,118489088,0,871]],3:[[249841,70254592,1,79691776,1,590],[499392,98566144,0,113246208,0,865]]},"fit:rapier-jxl/upload lossy":{2:[[249841,55574528,1,55574528,1,385],[499392,61865984,1,67108864,1,486],[1000230,81788928,1,133169152,0,1295],[1500254,136314880,0,175112192,0,3315]],1:[[249841,54525952,1,56623104,1,406],[499392,61865984,1,67108864,1,499],[1000230,85983232,1,127926272,0,1442],[1500254,133169152,0,168820736,0,2986]],3:[[249841,49283072,1,59768832,1,368],[499392,61865984,1,65011712,1,508],[1000230,80740352,1,115343360,0,1177],[1500254,131072e3,0,173015040,0,3284]]},"encode:rapier-jxl lossy":{1:[[249841,60817408,1,53477376,1,259],[499392,77594624,1,68157440,1,342],[1000230,104857600,0,80740352,1,428]],2:[[249841,71303168,1,53477376,1,243],[499392,77594624,1,68157440,1,324],[1000230,104857600,0,83886080,1,435]],3:[[249841,59768832,1,71303168,1,418],[499392,78643200,1,82837504,1,581],[1000230,105906176,0,102760448,0,852]],4:[[249841,57671680,1,83886080,1,918],[499392,77594624,1,110100480,0,1405],[1000230,103809024,0,140509184,0,1745]],5:[[249841,59768832,1,99614720,0,1058],[499392,77594624,1,119537664,0,1695],[1000230,108003328,0,143654912,0,2232]],7:[[249841,130023424,0,255852544,0,4661]],8:[[249841,155189248,0,264241152,0,10070]],6:[[249841,105906176,0,167772160,0,2456]],9:[[249841,195035136,0]]},"encode:rapier-jxl exact":{1:[[249841,52428800,1,42991616,1,133],[499392,63963136,1,50331648,1,172],[1000230,63963136,1,63963136,1,287],[1500254,73400320,1,94371840,0,674],[2000425,77594624,1,102760448,0,707],[2499794,72351744,1,104857600,0,953],[3e6,79691776,1],[3499200,83886080,1],[3999188,87031808,1]],2:[[249841,77594624,1,75497472,1,493],[499392,109051904,0,109051904,0,641]],3:[[249841,74448896,1,70254592,1,436],[499392,103809024,0,99614720,0,658]],4:[[249841,92274688,0,89128960,0,661]],5:[[249841,103809024,0,102760448,0,895]],6:[[249841,134217728,0,131072e3,0,1897]],7:[[249841,183500800,0,191889408,0,3702]],8:[[249841,246415360,0,252706816,0,9883]],9:[[249841,304087040,0,309329920,0,17770]]},"fit:rapier-jxl lossy":{1:[[249841,50331648,1,57671680,1,281],[499392,65011712,1,68157440,1,356],[1000230,72351744,1,123731968,0,1470],[1500254,119537664,0,180355072,0,2842]],2:[[249841,53477376,1,57671680,1,237],[499392,58720256,1,67108864,1,366],[1000230,70254592,1,130023424,0,1234],[1500254,116391936,0,181403648,0,3138]],3:[[249841,52428800,1,56623104,1,254],[499392,62914560,1,68157440,1,343],[1000230,70254592,1,120586240,0,1562],[1500254,123731968,0,186646528,0,3227]],4:[[249841,55574528,1,63963136,1,494],[499392,56623104,1,76546048,1,548],[1000230,68157440,1,145752064,0,1865],[1500254,118489088,0,185597952,0,3275]],5:[[249841,51380224,1,63963136,1,510],[499392,58720256,1,73400320,1,527],[1000230,71303168,1,139460608,0,1759],[1500254,112197632,0,193986560,0,3338]],6:[[249841,115343360,0,191889408,0,2365]],7:[[249841,133169152,0,216006656,0,3387]],8:[[249841,136314880,0,254803968,0,4267]],9:[[249841,186646528,0,273678336,0,9784]]},"fit:rapier-jxl/upload exact":{1:[[249841,48234496,1,51380224,1,273],[499392,55574528,1,58720256,1,332],[1000230,73400320,1,78643200,1,500],[1500254,82837504,1,95420416,0,696],[2000425,75497472,1,104857600,0,802],[2499794,87031808,1,122683392,0,889],[3e6,91226112,0]],2:[[249841,72351744,1,80740352,1,678],[499392,101711872,0]],3:[[249841,69206016,1,79691776,1,641],[499392,104857600,0]]},"fit:rapier-jxl exact":{1:[[249841,56623104,1,56623104,1,335],[499392,59768832,1,63963136,1,443],[1000230,66060288,1,80740352,1,551],[1500254,79691776,1,92274688,0,719],[2000425,81788928,1,101711872,0,857],[2499794,82837504,1,119537664,0,935],[3e6,98566144,0]],2:[[249841,75497472,1,81788928,1,745],[499392,100663296,0]],3:[[249841,73400320,1,83886080,1,651],[499392,101711872,0]],4:[[249841,88080384,0]],5:[[249841,101711872,0]],6:[[249841,134217728,0]],7:[[249841,187695104,0]],8:[[249841,239075328,0]],9:[[249841,294649856,0]]}},Ms=Symbol.for("rapier-jxl.steps"),bs=new WeakMap,ws=Symbol.for("rapier-jxl.verify.steps"),vs=new TextEncoder,Ls=e=>"function"==typeof e&&"function"==typeof e[ws]?e:null,Is="Missing verifier; pass verify from rapier-jxl/verify with each call.",As=new WeakMap,xs={verb:function({id:e,verb:t,taken:r,admit:n=()=>{},rows:a=!1,files:i=!1,result:o}){return Object.freeze({id:e,eager:e=>"decode"===e.kind||("file"===(e.kind??"pixels")?!i:!a),normalize(e,t){if(!Xi(e)||!Ue(e))throw fn("JXL_OPTIONS","Invalid resumable options; pass plain data values.");let a=Object.keys(e).find(e=>!r.includes(e));if(a)throw fn("JXL_OPTIONS",`Unknown resumable option: ${a}; use ${r.join(", ")}.`);let i=t.kind??"pixels";if("pixels"===i){let{width:r,height:n}=t;if(!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<1||n<1||t.byteLength!==r*n*4)throw fn("JXL_INPUT","Pixel source has the wrong byte count; pass width * height * 4 RGBA8 bytes or kind: 'file' for an encoded image.");h(r,n,d(e.maxPixels))}else if("file"!==i&&"decode"!==i)throw fn("JXL_INPUT","Invalid resumable source kind; use pixels, file, or decode.");return n(e),{options:{...e}}},async run(e,r,n,a){if("decode"!==n.kind)return Je(Fe(je(t(Gi(r,n,i),{...e.options,[Pa]:a})),n),a);let o=a?.host&&Vn in a.host?a.host[Vn]:Wn(),l=await q(a,"decode",()=>Se(r,o));return Je(Ri(l.source,je(t(Bi(l),{...e.options,[Pa]:a}))),a)},async straight(e,r,n,a,i,o){if("decode"!==n.kind)return Fe(je(t(Gi(r,n,!1),{...e.options,signal:a})),n);let l=o&&Vn in o?o[Vn]:Wn(),s=await Se(r,l);return Ri(s.source,je(t(Bi(s),{...e.options,signal:a})))},async record(e,t,r,n){if(!Xi(n))throw fn("JXL_INPUT","Invalid finished record; pass the result record returned by the job.");if(void 0!==n.records){if(!Array.isArray(n.records)||!n.records.length)throw fn("JXL_INPUT","Invalid finished records; pass a list of result records.");let t=0,a=[];for(let{length:i,...l}of n.records){if(null!==i&&(!Number.isSafeInteger(i)||i<1||t+i>e.length))throw fn("JXL_INPUT","Finished records do not cover the file; restore the complete saved records.");a.push(await Te(o,null===i?null:e.slice(t,t+=i),l,r))}if(t!==e.length)throw fn("JXL_INPUT","Finished records do not cover the file; restore the complete saved records.");return a}if("boolean"!=typeof n.missed||n.missed&&e.length)throw fn("JXL_INPUT","Finished record describes another file; pass the record belonging to this file.");return Te(o,n.missed?null:e,n.record,r)}})},verify:(e,t)=>Ir(t[ws],t)},Ns=(e,t)=>As.get(e)??As.set(e,xs[e.kind](e,t)).get(e),Os=(e,t)=>{for(let{ref:r,bytes:n}of t??[])e.unsaved.set(r.hash,n)},Ps=(e,t,r,n)=>({source:t,expectedRevision:e?.revision,read:r.read,readMany:r.readMany,readSource:r.readSource,...n}),Es=32e6,Ts=65536;export{Xr as advance,_r as finish,kr as start,Rr as workerAdmission};
1
+ /*! rapier-jxl 8.4.1 | MIT */
2
+ function e(e,t,r=Wr){if("number"==typeof r&&(r={edge:Wr.edge,pixels:r}),!Number.isInteger(e)||!Number.isInteger(t)||e<1||t<1)throw Vr("JXL_INPUT","width, height: positive integers");if(e>r.edge||t>r.edge)throw Vr("JXL_DIMENSIONS","side: max "+r.edge);if(e*t>r.pixels)throw Vr("JXL_DIMENSIONS","pixels: max "+r.pixels.toLocaleString("en-US")+" (maxPixels)")}async function t(e){let t=URL.createObjectURL(e),r=new Image;try{r.src=t,await r.decode()}finally{URL.revokeObjectURL(t)}return{image:r,width:r.naturalWidth,height:r.naturalHeight,close:()=>r.removeAttribute("src")}}async function r(t,r,n){if(!r||"object"!=typeof r||Array.isArray(r))throw Vr("JXL_INPUT","options: object");let{width:a,height:i,colorSpace:l="srgb",signal:o,maxPixels:s=Wr.pixels,orientation:u=1,sampleFormat:c="uint",bitDepth:f=8,alphaPremultiplied:h=!1,animation:d=!1,alpha:m,...p}=r;if(o?.aborted)throw o.reason;if(!(t instanceof Uint8Array&&t.length))throw Vr("JXL_INPUT","bytes: nonempty Uint8Array");if(!Number.isSafeInteger(s)||s<1)throw Vr("JXL_INPUT","maxPixels: positive integer");if(e(a,i,{pixels:s,edge:1073741824}),!["srgb","display-p3"].includes(l)||1!==u||"uint"!==c||8!==f||!1!==h||!1!==d||![void 0,!0,!1].includes(m)||Object.keys(p).length)throw Qr("readback: upright still 8-bit sRGB or Display P3");if(null!=o&&("boolean"!=typeof o.aborted||"function"!=typeof o.addEventListener||"function"!=typeof o.removeEventListener))throw Vr("JXL_INPUT","signal: AbortSignal");let y=globalThis.createImageBitmap,g=globalThis.OffscreenCanvas,M=globalThis.Blob;if("function"!=typeof y||"function"!=typeof g||"function"!=typeof M)throw Vr("JXL_PLATFORM","no JPEG XL decode: use effort 1-3");let b,w,L,A,v,I,x,N=!1,O=!1,P=e=>{N||(N=!0,x=e)},U=()=>{try{P(o.reason)}catch(e){P(e)}},S=()=>{if(!N&&o?.aborted&&U(),N)throw x},j=(e,t)=>{try{return t()}catch(t){throw Qr(e,t)}},E=(e,t)=>{try{t()}catch(t){P(Qr(e,t))}};try{o&&(O=!0,o.addEventListener("abort",U,{once:!0})),S();let e=j("Blob failed",()=>n(y,M));S();try{b=await e()}catch(e){P(Qr("browser JPEG XL decode failed",e))}if(S(),!b||"function"!=typeof b.close)throw Qr("ImageBitmap: not closable");let t=j("dimensions unreadable",()=>[b.width,b.height]);if(t[0]!==a||t[1]!==i)throw Vr("JXL_DIMENSIONS","decoded size mismatch");w=j("canvas allocation failed",()=>new g(1,1)),S();let r=j("no WebGL2 context",()=>w.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,antialias:!1,depth:!1,stencil:!1}));if(L=r,r){if($r.some(e=>"function"!=typeof r[e]))throw Qr("readback: needs WebGL2");if(!1!==j("WebGL2 context state unreadable",()=>r.isContextLost()))throw Qr("WebGL2 context lost");let e=new Uint8ClampedArray(a*i*4);if(j("readback failed",()=>{let t=Math.min(r.getParameter(r.MAX_TEXTURE_SIZE),4096);if(!Number.isSafeInteger(t)||t<1)throw new Error("no texture size");A=r.createTexture(),v=r.createFramebuffer(),r.bindTexture(r.TEXTURE_2D,A),r.bindFramebuffer(r.FRAMEBUFFER,v),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.NONE),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_ALIGNMENT,1),r.pixelStorei(r.PACK_ALIGNMENT,1),r.pixelStorei(r.PACK_ROW_LENGTH,a);for(let n=0;n<i;n+=t)for(let l=0;l<a;l+=t){let o=Math.min(t,a-l),s=Math.min(t,i-n);if(r.pixelStorei(r.UNPACK_SKIP_PIXELS,l),r.pixelStorei(r.UNPACK_SKIP_ROWS,n),r.texImage2D(r.TEXTURE_2D,0,r.RGBA8,o,s,0,r.RGBA,r.UNSIGNED_BYTE,b.image??b),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,A,0),r.checkFramebufferStatus(r.FRAMEBUFFER)!==r.FRAMEBUFFER_COMPLETE)throw new Error("framebuffer: incomplete");r.readPixels(0,0,o,s,r.RGBA,r.UNSIGNED_BYTE,e,4*(n*a+l))}let n=r.getError();if(n!==r.NO_ERROR)throw new Error("WebGL: "+n)}),S(),!1!==j("WebGL2 context state unreadable",()=>r.isContextLost()))throw Qr("WebGL2 context lost");I={data:e,width:a,height:i,colorSpace:l,sampleFormat:"uint",bitDepth:8,alphaPremultiplied:!1}}else{if("srgb"!==l)throw Qr("Display P3 readback: needs WebGL2");L=null,j("canvas resize failed",()=>{w.width=a,w.height=i});let e=j("no 2D context",()=>w.getContext("2d",{willReadFrequently:!0}));if(!e||"function"!=typeof e.drawImage||"function"!=typeof e.getImageData)throw Qr("readback: needs WebGL2 or 2D context");let t=j("readback failed",()=>(e.drawImage(b.image??b,0,0),e.getImageData(0,0,a,i).data));for(let e=3;e<t.length;e+=4)if(255!==t[e])throw Qr("alpha readback: needs WebGL2");S(),I={data:new Uint8ClampedArray(t.buffer,t.byteOffset,t.length),width:a,height:i,colorSpace:l,sampleFormat:"uint",bitDepth:8,alphaPremultiplied:!1}}}catch(e){P(e)}finally{b&&E("ImageBitmap close failed",()=>b.close()),A&&E("texture delete failed",()=>L.deleteTexture(A)),v&&E("framebuffer delete failed",()=>L.deleteFramebuffer(v)),w&&(E("canvas release failed",()=>{w.width=0}),E("canvas release failed",()=>{w.height=0})),O&&E("abort listener remove failed",()=>o.removeEventListener("abort",U))}return S(),I}function n(){let e=globalThis.createImageBitmap;if(!ln||ln.api!==e){let t=ln={api:e,reads:"function"!=typeof e||"function"!=typeof globalThis.OffscreenCanvas||"function"!=typeof globalThis.Blob?Promise.resolve(!1):r(an,{width:1,height:1},rn(an)).then(()=>!0,()=>!1)};t.reads=t.reads.then(e=>(!e&&ln===t&&(ln=null),e))}return ln.reads}async function a(e,t){let n=(t,n,a)=>r(t,{width:1,height:1,colorSpace:n},e(t)).then(({data:e})=>200===e[0]&&100===e[1]&&50===e[2]&&e[3]===a);return{alpha:await n(on,"srgb",128),displayP3:await n(sn,"display-p3",255),image:t}}function i(){let e=globalThis.createImageBitmap;if(!cn||cn.api!==e){let t=cn={api:e,reads:null},r=()=>(cn===t&&(cn=null),{...un,bitmap:un});t.reads=n().then(async e=>{if(!e)return r();let t=await a(rn,!1);if(t.alpha&&t.displayP3||"function"!=typeof globalThis.Image||"function"!=typeof URL.createObjectURL)return{...t,bitmap:t};let n=await a(nn,!0);return n.alpha+n.displayP3>t.alpha+t.displayP3?{...n,bitmap:t}:{...t,bitmap:t}}).catch(r)}return cn.reads}function l(e){try{null!==e&&("object"==typeof e||"function"==typeof e)&&mn.add(e)}catch{}return e}function o(e){try{if(mn.has(e))return e;if(Yr(e))return Object.assign(new Error(`memory: shrink picture${qr(e)}`,{cause:e}),{code:"JXL_MEMORY"});let t=e?.code;if("string"!=typeof t||!t.startsWith("JXL_")||hn.has(t))return e;let r=Object.hasOwn(dn,t)?dn[t]:"JXL_INTERNAL";return Object.assign(new Error(String(e.message??""),{cause:e}),{code:r})}catch{return e}}function s(e){if(void 0===e)return;if(!e||"object"!=typeof e&&"function"!=typeof e)throw fn("JXL_OPTIONS","signal: AbortSignal");let t,r;try{t=e.aborted,r=e.addEventListener}catch(e){throw l(e)}if("boolean"!=typeof t||"function"!=typeof r)throw fn("JXL_OPTIONS","signal: AbortSignal");return e}function u(e){if(null==e)return;let t,r;try{t=e.aborted,t&&(r=e.reason)}catch(e){throw l(e)}if(t)throw l(void 0===r?Kr():r)}function c(e,t="Options"){if(void 0===e)return{};if(!e||"object"!=typeof e||Array.isArray(e))throw fn("JXL_OPTIONS",`${t}: object`);return e}function f(e,t,r=[]){let n=c(e,t);try{let e={...n};for(let t of r)!Object.hasOwn(e,t)&&t in n&&(e[t]=n[t]);return e}catch(e){throw l(e)}}function h(e,t,r=Gr,n=1073741824){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<1||t<1||e>n||t>n)throw fn("JXL_DIMENSIONS",`sides: integer 1-${n}${1073741824===n?", JPEG XL size field":""}`);if(e*t>r)throw fn("JXL_DIMENSIONS",`${e*t} pixels: maxPixels ${r} exceeded`)}function d(e){if(void 0===e)return Gr;if(!Number.isSafeInteger(e)||e<1)throw fn("JXL_OPTIONS","maxPixels: positive integer");return e}function m(e){if(!e||"object"!=typeof e||Array.isArray(e)||!Object.keys(e).length)throw An("modules: {name: WebAssembly.Module}");let t=Object.entries(e);for(let[e,r]of t){if(!Object.hasOwn(yn,e))throw An(`unknown module: ${e}`);let t,n;try{t=WebAssembly.Module.imports(r),n=WebAssembly.Module.exports(r)}catch{throw An(`${e}: WebAssembly.Module`)}let a="kernels"===e||"general"===e;if(Mn(n)!==yn[e]||(a?1!==t.length||"env"!==t[0].module||"memory"!==t[0].name||"memory"!==t[0].kind:0!==t.length))throw An(`${e}: interface mismatch`);if(bn.has(e)&&bn.get(e)!==r||wn.has(e)&&wn.get(e)!==r)throw An(`${e}: already configured`)}for(let[e,r]of t)bn.set(e,r);Ln=!0}async function p(e,t){return xn(),!(!wn.get(e)&&!bn.has(e))||(On.has(e)||(wn.has(e)||wn.set(e,null),On.set(e,(async()=>{let r=await WebAssembly.compile(t());return await WebAssembly.instantiate(Uint8Array.of(0,97,115,109,1,0,0,0)),wn.get(e)||wn.set(e,r),Pn.delete(e),!0})().catch(t=>(On.delete(e),Pn.set(e,t),!1)))),On.get(e))}function y(e,t){if(xn(),wn.get(e))return wn.get(e);wn.set(e,null);let r,n=bn.get(e);if(n)return wn.set(e,n),n;try{r=new WebAssembly.Module(t())}catch(t){throw Ln?An(`${e}: missing`):t}return wn.set(e,r),r}function g(){if(!Bn){let e=new WebAssembly.Memory({initial:48});Bn={memory:e,exports:new WebAssembly.Instance(y("kernels",()=>gn(kn)),{env:{memory:e}}).exports}}return Bn}function M(e,t=null,r=null){let n={lose:e,refresh:t,gain:r};return Xn.push(n),n}function b(e){if(Rn===e)return;let t=Rn;Rn=e;for(let t of Xn)t!==e&&t.lose();t&&e.gain?.()}function w(e,t){let r={};for(let[n,a]of Object.entries(e))r[n]="function"==typeof a?(...e)=>(b(t),a(...e)):a;return r}function L(e){return e>=0?2*e:2*-e-1}function A(e,t,r,n){let[a,i,l,o,s,u,c,f]=e;for(let e=r;e+64<=n;e+=64){for(let r=0;r<16;r++){let n=e+4*r;Yn[r]=t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3]}for(let e=16;e<64;e++){let t=Yn[e-15],r=Yn[e-2];Yn[e]=((t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3)+Yn[e-7]+((r>>>17|r<<15)^(r>>>19|r<<13)^r>>>10)+Yn[e-16]|0}let r=a,n=i,h=l,d=o,m=s,p=u,y=c,g=f;for(let e=0;e<64;e++){let t=g+((m>>>6|m<<26)^(m>>>11|m<<21)^(m>>>25|m<<7))+(m&p^~m&y)+Hn[e]+Yn[e]|0,a=((r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10))+(r&n^r&h^n&h)|0;g=y,y=p,p=m,m=d+t|0,d=h,h=n,n=r,r=t+a|0}a=a+r|0,i=i+n|0,l=l+h|0,o=o+d|0,s=s+m|0,u=u+p|0,c=c+y|0,f=f+g|0}e.set([a,i,l,o,s,u,c,f])}function v(e,t){let r=Int32Array.from(e.h),n=e.tail,a=0;if(n.length){let i=Uint8Array.from([...n,...t.subarray(0,64-n.length)]);if(i.length<64)return{h:e.h,length:e.length+t.length,tail:[...i]};A(r,i,0,64),a=64-n.length}let i=a+(t.length-a&-64);return A(r,t,a,i),{h:[...r],length:e.length+t.length,tail:[...t.subarray(i)]}}function I(e){let t=8*e.length,r=new Uint8Array(e.tail.length+72&-64);r.set(e.tail),r[e.tail.length]=128;let n=new DataView(r.buffer);n.setUint32(r.length-8,Math.floor(t/2**32)),n.setUint32(r.length-4,t>>>0);let a=Int32Array.from(e.h);return A(a,r,0,r.length),Array.from(a,e=>(e>>>0).toString(16).padStart(8,"0")).join("")}function x(e){try{return e()}catch(e){throw"JXL_INPUT"===e?.code?e:la("checkpoint data")}}function N(e,t=Qn){if(!(e instanceof Uint8Array))throw la("checkpoint: Uint8Array");let r=ra.call(e),n=aa.call(e),a=na.call(e);if(ia.call(n),r>t)throw la("checkpoint: too large");return new Uint8Array(n,a,r)}function O(e){if(null===e||"object"!=typeof e)throw la("checkpoint record: plain object");let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&null!==t)throw la("checkpoint record: plain object");let r=Reflect.ownKeys(e);if(r.some(e=>"string"!=typeof e))throw la("checkpoint fields");return r.map(t=>{let r=Object.getOwnPropertyDescriptor(e,t);if(!r||!r.enumerable||!Object.hasOwn(r,"value"))throw la("checkpoint: plain fields only");return[t,r.value]})}function P(e){if(!Array.isArray(e)||Object.getPrototypeOf(e)!==Array.prototype)throw la("checkpoint: plain array");let t=e.length;if(t>$n>>1||Reflect.ownKeys(e).length!==t+1)throw la("checkpoint array");let r=new Array(t);for(let n=0;n<t;n++){let t=Object.getOwnPropertyDescriptor(e,String(n));if(!t||!t.enumerable||!Object.hasOwn(t,"value"))throw la("checkpoint array: no holes");r[n]=t.value}return r}function U(e,t){let r=new Set,n=()=>la("checkpoint record: max 1 MiB"),a=e=>oa.test(e)?'"'+e+'"':JSON.stringify(e),i="",l=e=>{if((i+=e).length>$n)throw n()},o=[],s=e=>{if(null===e)return l("null");let i=typeof e;if("boolean"===i)return l(e?"true":"false");if("number"===i){if(!Number.isFinite(e))throw la("checkpoint number: finite");return l(Object.is(e,-0)?"0":""+e)}if("string"===i){if(e.length>$n)throw n();return l(a(e))}if("object"!==i||t&&r.has(e))throw la("checkpoint: unsupported value or cycle");if(t&&r.add(e),Array.isArray(e))return l("["),void o.push({v:e,items:t?P(e):e,record:!1,at:0});let s=t?O(e):Object.keys(e).map(t=>[t,e[t]]);if(s.length>$n/5)throw n();s.sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0),l("{"),o.push({v:e,items:s,record:!0,at:0})};for(s(e);o.length;){let e=o[o.length-1],{items:i,record:u}=e;if(e.at===i.length){l(u?"}":"]"),o.pop(),t&&r.delete(e.v);continue}let c=i[e.at];if(e.at++&&l(","),u){if(c[0].length>$n)throw n();l(a(c[0])+":"),s(c[1])}else s(c)}return i}function S(e){return x(()=>{let t=Zn.encode(U(e,!0));if(t.length>$n)throw la("checkpoint record: max 1 MiB");return t})}function j(e,t=null){return x(()=>{let r=Zn.encode(t??JSON.stringify(e));if(r.length>$n)throw la("checkpoint record: max 1 MiB");return r})}function E(e){return x(()=>JSON.parse(ea.decode(N(e,$n))))}function T(e){return x(()=>{let t=ea.decode(N(e,$n)),r=JSON.parse(t);if(t!==U(r,!1))throw la("checkpoint JSON: not canonical");return r})}async function F(e){let t=x(()=>N(e));try{if(!globalThis.crypto?.subtle)return I(v(qn(),t));let e=await globalThis.crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(e),e=>e.toString(16).padStart(2,"0")).join("")}catch(e){throw"JXL_INPUT"===e?.code?e:la("checkpoint hash failed")}}async function k(e,t,r){Array.isArray(t)||ua("frontier: array");let n=new Map;for(let e of t)(!e||"string"!=typeof e.hash||!e.hash.length||!Number.isSafeInteger(e.length)||e.length<0||e.length>1048576||2!==Object.keys(e).length)&&ua("frontier ref"),n.has(e.hash)&&n.get(e.hash).length!==e.length&&ua("frontier: length conflict"),n.set(e.hash,e);if(!n.size)return;if(!1===e.durable)return void await(r?.([...n.values()]));"function"!=typeof e.prefetch&&ua("io.prefetch: function");let a=[],i=0;for(let t of n.values())(128===a.length||i+t.length>sa)&&(await e.prefetch(a),await(r?.(a)),a=[],i=0),a.push(t),i+=t.length;a.length&&(await e.prefetch(a),await(r?.(a)))}function J(e){let t=new Map,r=0,n=e=>{let n=t.get(e);n&&(r-=n.length,t.delete(e))};return{get size(){return t.size},has:e=>t.has(e),get(e){let r=t.get(e);return r&&(t.delete(e),t.set(e,r)),r},delete:n,set(a,i){if(n(a),!(i.length>e)){for(;r+i.length>e;)n(t.keys().next().value);t.set(a,i),r+=i.length}}}}function _(e,t,r=!0,n){let a=new Map,i=J(sa),l=0,o=0,s=async e=>{Aa(t),(!(e instanceof Uint8Array)||e.length>ca)&&ya("part: Uint8Array <=1 MiB");let r=new Uint8Array(e),n=await F(r),l={hash:n,length:r.length};return Aa(t),a.has(n)||a.set(n,{ref:l,bytes:r}),i.delete(n),l},u=async n=>{va(n),Aa(t);let s=a.get(n.hash)?.bytes??i.get(n.hash);if(!s){"function"!=typeof e&&ya("read: function"),o++;let a=await e(n);Aa(t),(!(a instanceof Uint8Array)||a.length!==n.length)&&ya("immutable part: missing/truncated"),s=new Uint8Array(a),await F(s)!==n.hash&&ya("immutable part: digest mismatch"),Aa(t),l+=s.length,r&&i.set(n.hash,s)}return s.length!==n.length&&ya("part length: digest mismatch"),r||i.delete(n.hash),s};return{read:async e=>new Uint8Array(await u(e)),write:s,durable:!0,fetch:async e=>{Aa(t),(!Array.isArray(e)||e.length>128||e.reduce((e,t)=>e+va(t).length,0)>sa)&&ya("part batch: <=128, <=8 MiB"),"function"!=typeof n&&ya("readMany: function"),o++;let r=await n(e.map(e=>({hash:e.hash,length:e.length})));return Aa(t),(!Array.isArray(r)||r.length!==e.length)&&ya("part batch: result count mismatch"),r.forEach((t,r)=>{(!(t instanceof Uint8Array)||t.length!==e[r].length)&&ya("immutable part: missing/truncated"),l+=t.length}),r},borrow:u,prefetch:async e=>{Aa(t),(!Array.isArray(e)||e.length>128)&&ya("part batch: <=128 references");let r=0,s=new Map;for(let t of e){va(t),r+=t.length,r>sa&&ya("part batch: <=8 MiB");let e=a.get(t.hash)?.bytes??i.get(t.hash);(s.has(t.hash)&&s.get(t.hash).length!==t.length||e&&e.length!==t.length)&&ya("part length: digest mismatch"),e||s.set(t.hash,{hash:t.hash,length:t.length})}if(!s.size)return;"function"!=typeof n&&ya("readMany: function");let u=[...s.values()];o++;let c=await n(u.map(e=>({...e})));Aa(t),(!Array.isArray(c)||c.length!==u.length)&&ya("part batch: result count mismatch");let f=c.map((e,t)=>((!(e instanceof Uint8Array)||e.length!==u[t].length)&&ya("immutable part: missing/truncated"),new Uint8Array(e))),h=await Promise.all(f.map(F));Aa(t);for(let e=0;e<h.length;e++)h[e]!==u[e].hash&&ya("immutable part: digest mismatch");for(let e=0;e<f.length;e++)i.set(u[e].hash,f[e]),l+=f[e].length},bytesRead:()=>l,callsRead:()=>o,readJSON:async e=>T(await u(e)),writeJSON:e=>s(S(e)),parts:()=>[...a.values()]}}async function B(e){let t=S(e);return t.length>ha&&ya("checkpoint manifest: <=16 KiB"),{...e,hash:await F(t)}}async function R(e,t,r){let n=Ma(e);(!n||"rapier-jxl/checkpoint"!==n.format)&&ya("checkpoint: expected format 'rapier-jxl/checkpoint'"),n.codec!==t&&ya("checkpoint: codec mismatch"),n.build!==r&&ya("checkpoint: build mismatch; restart"),(!da.test(n.hash)||!da.test(n.job)||!Number.isSafeInteger(n.revision)||n.revision<0||!["active","done"].includes(n.status)||null!==n.previous&&!da.test(n.previous))&&ya("checkpoint: manifest fields");let{hash:a,...i}=n,l=S(i);if((l.length>ha||await F(l)!==a)&&ya("checkpoint: digest mismatch"),Ia(n.source),("done"!==n.status||null!==n.state)&&va(n.state),pa(n.reads),await F(S({codec:t,build:r,source:n.source,plan:n.plan}))!==n.job&&ya("checkpoint: job mismatch"),"done"===n.status){(!n.output||!Number.isSafeInteger(n.output.byteLength)||n.output.byteLength<0||n.output.byteLength>4294967295)&&ya("output: byteLength, refs, result");let{refs:e,index:t}=n.output;(n.output.byteLength?null===e?(va(t),!1):!Array.isArray(e)||!e.length||e.length>16||null!==t||(e.forEach(va),e.reduce((e,t)=>e+t.length,0)!==n.output.byteLength):null!==e||null!==t)&&ya("output: byteLength, refs, result"),void 0===n.output.result&&ya("output: byteLength, refs, result")}else null!==n.output&&ya("checkpoint: output only when done");return n}function X(e){let t=S(e);return t.length>ha&&ya("completion metadata: <=16 KiB"),T(t)}function D(e,t){return async(r,n)=>{if((!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<0||n<0||r+n>t.byteLength)&&ya("source read: bounded range"),!n)return new Uint8Array;"function"!=typeof e.readSource&&ya("readSource: function");let a=await e.readSource(r,n);return Aa(e.signal),(!(a instanceof Uint8Array)||a.length!==n)&&ya("source range: missing/truncated"),new Uint8Array(a)}}function C(e,t,r,n){let a=wa(t.byteLength),i=Math.ceil(t.byteLength/a),l=J(ma);(!Array.isArray(n)||n.length!==i||!n.every(e=>da.test(e)))&&ya("source chunks: sha256 list");let o=async(e,t)=>{let i=await Promise.all(Array.from({length:Math.ceil(t.length/a)},(e,r)=>F(t.subarray(r*a,Math.min(t.length,(r+1)*a)))));Aa(r);for(let t=0;t<i.length;t++)if(i[t]!==n[e+t])throw Vr("JXL_INPUT","source bytes: digest mismatch")};return async(r,n)=>{if((!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<0||n<0||r+n>t.byteLength)&&ya("source read: bounded range"),!n)return new Uint8Array;let i=Math.floor(r/a),s=Math.ceil((r+n)/a);if(!r&&n===t.byteLength&&!l.size){let t=await e(0,n);return await o(0,t),t}let u=new Uint8Array(n),c=(e,t)=>{let i=e*a,l=Math.max(r,i),o=Math.min(r+n,i+t.length);u.set(t.subarray(l-i,o-i),l-r)},f=s,h=i;for(let e=i;e<s;e++){let t=l.get(e);t?c(e,t):(f=Math.min(f,e),h=e+1)}if(f<h){let r=await e(f*a,Math.min(t.byteLength,h*a)-f*a);await o(f,r);for(let e=f;e<h;e++){let t=r.subarray((e-f)*a,Math.min(r.length,(e-f+1)*a));c(e,t),t.length<=ma&&!l.has(e)&&l.set(e,t.slice())}}return u}}function G(e){async function t(e,t){Aa(t?.signal);let r=await R(e,i,l);return"done"!==r.status&&ya("checkpoint: not done"),(!t||!ba(Ia(t.source),r.source))&&ya("source: generation/digest mismatch"),t.expectedRevision!==r.revision&&ga("expectedRevision: checkpoint mismatch"),ba(o(r.plan.options??r.plan,r.source,r.plan.verify??!1),r.plan)||ya("codec plan: mismatch"),await(t.admit?.(r.plan,r.source)),r}if(!e||"string"!=typeof e.id||!e.id.length||e.id.length>128||!da.test(e.build)||!["normalize","start","step"].every(t=>"function"==typeof e[t]))throw Vr("JXL_INPUT","stepper: id, build, normalize/start/step");let{normalize:r,start:n,step:a}=e,i=e.id,l=e.build,o=(e,t,n=!1)=>{if("boolean"!=typeof n)throw Vr("JXL_OPTIONS","verify: boolean");let a=Ma(r(Ma(e),t));return n?{...a,verify:!0}:a};return Object.freeze({start:async function({source:e,options:t={},verify:r=!1,admit:n}){e=Ia(e);let a=o(t,e,r);await(n?.(a,e));let s=_(),u=await F(S({codec:i,build:l,source:e,plan:a})),c=await s.writeJSON({phase:"verify",offset:0,hash:qn(),chunks:[]});return{checkpoint:await B({format:"rapier-jxl/checkpoint",codec:i,build:l,job:u,source:e,plan:a,revision:0,previous:null,state:c,reads:[],status:"active",output:null}),parts:s.parts()}},advance:async function(t,r,s={units:1}){Aa(r?.signal),s=xa(s);let u=await R(t,i,l);if(!r||!ba(Ia(r.source),u.source))throw Vr("JXL_INPUT","source: generation/digest mismatch");(!Number.isSafeInteger(r.expectedRevision)||r.expectedRevision!==u.revision)&&ga("expectedRevision: checkpoint mismatch"),"done"===u.status&&ga("checkpoint: completed"),u.revision===Number.MAX_SAFE_INTEGER&&ya("checkpoint revision: at maximum"),ba(o(u.plan.options??u.plan,u.source,u.plan.verify??!1),u.plan)||ya("codec plan: mismatch"),await(r.admit?.(u.plan,u.source));let c=await F(S({checkpoint:u.hash,budget:s})),f=_(r.read,r.signal,!0,r.readMany),h=D(r,u.source),d=null,m=!1,p=0,y=0;await k(f,[u.state,...u.reads]);let g,M=await f.readJSON(u.state),b=[],w=[],L=(t,r,n=[])=>{let a=[t.state,...t.reads??[],...t.output?.refs??[],t.output?.index,...n,...r&&e.refs?e.refs(r):[]].filter(Boolean);return new Map(a.map(e=>[e.hash,e]))},A=L(u,"encode"===M?.phase?M.codec:null),x=[],N=Number.isFinite(r.deadline)?r.deadline:1/0;for(let e=0;e<s.units&&void 0===g&&(0===e||performance.now()<N);e++)if(Aa(r.signal),"verify"===M.phase){let e=M.hash;(!Number.isSafeInteger(M.offset)||M.offset<0||M.offset>=u.source.byteLength||!e||e.length!==M.offset||!Array.isArray(e.h)||8!==e.h.length||!e.h.every(Number.isSafeInteger)||!Array.isArray(e.tail)||e.tail.length!==M.offset%64||!e.tail.every(e=>Number.isInteger(e)&&e>=0&&e<256)||!Array.isArray(M.chunks)||M.offset%La(u.source.byteLength)||M.chunks.length!==M.offset/wa(u.source.byteLength)||!M.chunks.every(e=>da.test(e)))&&ya("source checkpoint: phase/chunks");let t=Math.min(La(u.source.byteLength),u.source.byteLength-M.offset),r=M.offset,a=wa(u.source.byteLength),i=!r&&u.source.byteLength<=2097152,l=i?u.source.byteLength:t,o=await h(r,l),s=await Promise.all(Array.from({length:Math.ceil(l/a)},(e,t)=>F(o.subarray(t*a,Math.min(l,(t+1)*a))))),c=i?await F(o):null;if(M={...M,hash:i?e:v(e,o),offset:r+l,chunks:[...M.chunks,...s]},x.push({phase:"source",offset:r,bytes:l}),M.offset===u.source.byteLength){if((c??I(M.hash))!==u.source.sha256)throw Vr("JXL_INPUT","source bytes: digest mismatch");M={phase:"encode",codec:n(u.plan,u.source),chunks:M.chunks}}}else if("encode"===M.phase){d??=C(async(e,t)=>{y++;let r=await h(e,t);return p+=r.length,r},u.source,r.signal,M.chunks),m||(await(r.prepare?.(u.plan,u.source,d)),m=!0);let e=N-performance.now(),t=Number.isFinite(e)?Math.max(1,e):r.budgetMs,n=await a(M.codec,{...f,readSource:d,bytesRead:()=>p+f.bytesRead(),callsRead:()=>y+f.callsRead(),signal:r.signal,...Number.isFinite(t)&&t>0&&{budgetMs:t},...r.reads&&{reads:r.reads},...void 0!==r.memoryBytes&&{memoryBytes:r.memoryBytes},...r.straight&&{straight:r.straight},...r.verify&&{verify:r.verify},...Vn in r&&{[Vn]:r[Vn]}});if(Aa(r.signal),(!n||!Object.hasOwn(n,"state"))&&ya("step: state required"),M={phase:"encode",codec:n.state,chunks:M.chunks},w=n.reads??[],x.push(n.work??{phase:"encode"}),void 0!==n.output){let e=n.output;null!==e&&!(e instanceof Uint8Array)&&ya("output: Uint8Array");let t=[];if(n.outputRefs)(!Array.isArray(n.outputRefs)||n.outputRefs.reduce((e,t)=>e+va(t).length,0)!==(e?.length??0))&&ya("outputRefs: byteLength mismatch"),t.push(...n.outputRefs);else if(e)for(let r=0;r<e.length;r+=ca)t.push(await f.write(e.subarray(r,Math.min(e.length,r+ca))));b=t,g={refs:t.length&&t.length<=16?t:null,index:t.length>16?await f.writeJSON(t):null,byteLength:e?.length??0,result:void 0===n.result?null:X(n.result)},M=null}if(n.yield)break}else ya("codec phase: unknown");Aa(r.signal);let O=void 0!==g,P=O?null:await f.writeJSON(M),{hash:U,...j}=u,E=await B({...j,previous:U,state:P,reads:O?[]:pa(w),revision:u.revision+1,status:O?"done":"active",output:O?g:null});Aa(r.signal);let T=L(E,"encode"===M?.phase?M.codec:null,b),J=[...A].filter(([e])=>!T.has(e)).map(([,e])=>({hash:e.hash,length:e.length}));return{checkpoint:E,parts:f.parts(),released:J,work:x,units:x.length,transition:c,done:O,output:O?g:null}},completion:async function(e,r){let n=await t(e,r);return{result:n.output.result,byteLength:n.output.byteLength}},output:async function(e,r,n){let a=await t(e,r);if(!a.output.byteLength)return n(0);let i=_(r.read,r.signal,!1,r.readMany),l=a.output.refs??await i.readJSON(a.output.index);(!Array.isArray(l)||!l.length)&&ya("output index: nonempty array");let o=0;for(let e of l)va(e),o+=e.length;o!==a.output.byteLength&&ya("output index: length mismatch");let s=null,u=0;for(let e=0;e<l.length;){let t=e+1,a=l[e].length;for(;t<l.length&&t-e<128&&a+l[t].length<=sa;)a+=l[t++].length;let c=l.slice(e,t),f=await i.fetch(c);e=t,s??=n(o);for(let e=0;e<c.length;e++){let t=c[e];s.set(f[e],u),f[e]=null,await F(s.subarray(u,u+t.length))!==t.hash&&ya("immutable part: digest mismatch"),Aa(r.signal),u+=t.length}}return s}})}function W(e,t,r){let n=globalThis[_a];globalThis[_a]=r;try{return e.next(t)}finally{globalThis[_a]=n}}function*V(e,t,r,n=!1,a=!1){return globalThis[_a]?yield*globalThis[_a].step(e,t,r,0,n,a):t()}function*K(e,t,r,n=!1,a=!1){return globalThis[_a]?yield*globalThis[_a].step(e,t,r,1,n,a):t()}function*z(e,t,r,n=!1,a=!1){return globalThis[_a]?yield*globalThis[_a].step(e,t,r,2,n,a):yield*t()}function H(e){return e.step=Y,e}function*Y(e,t,r,n,a,i){let l={unit:e};1===n&&(l.carry=!0),2===n?(a&&(l.whole=!0),r?.tool&&(l.answer=r.tool)):a&&(l.tail=!0),i&&(l.cold=!0);let o,s=yield l;if(s&&Object.hasOwn(s,Na))return s[Na];try{o=2===n?yield*t():t()}catch(t){throw yield{unitFailed:e},t}return yield{unitDone:e,value:o,save:r},o}async function q(e,t,r){if(!e)return r();let n,a=await e({unit:t});if(a&&Object.hasOwn(a,Na))return a[Na];try{n=await r()}catch(r){throw await e({unitFailed:t}),r}return await e({unitDone:t,value:n}),n}function $(e){let t=null,r=e.map(e=>{try{return e()}catch(e){if(!0!==e?.[Oa])throw e;t??=e}});if(t)throw t;return r}function Q(e,t,r,n,a,i=null){let l=()=>{throw a(t[0]),new Ya("unread value")},o=a=>{let o=i?.(t[0],t[1]);if(!o)return l();let s=o instanceof ArrayBuffer?o:o.buffer,u=o.byteOffset??0;if(r+n*e.BYTES_PER_ELEMENT>o.byteLength)throw Wa("Invalid unit value.");let c=new e(s,u+r,n),f=Reflect.get(c,a);return"function"==typeof f?f.bind(c):f},s=Ha(Ca.indexOf(e.name),t,r,n),u=new Proxy(new e(0),{get:(t,r)=>r===Oa||(r===Va?s:r===Ka?(e,t)=>ie(u,e,t):"length"===r?n:"byteLength"===r?n*e.BYTES_PER_ELEMENT:"then"===r?void 0:i?o(r):l()),set:l,has:l,ownKeys:l,getOwnPropertyDescriptor:l,defineProperty:l,deleteProperty:l,getPrototypeOf:()=>e.prototype});return u}function Z(e,t,r=[],n=0,a=null){let i={length:e,byteLength:e,byteOffset:0,BYTES_PER_ELEMENT:1,constructor:Uint8Array},l=Ha(Ca.indexOf("Uint8Array"),["source",0],n,e),o=()=>{throw t(n||a?`source:${n}:${n+e}`:"source"),new Ya("unread source")},s=(t,r)=>{if(void 0===t)return r;let n=Math.trunc(Number(t))||0;return n<0?Math.max(0,e+n):Math.min(e,n)},u=(i,l)=>{let o=s(i,0),u=Math.max(o,s(l,e));if(a){let e=a(n+o,n+u);if(e)return e;if(o===u)return new Uint8Array(0);throw t(`source:${n+o}:${n+u}`),new Ya("unread range")}let c=r.find(e=>e.at<=n+o&&n+u<=e.at+e.bytes.length);if(c)return c.used=[Math.min(c.used?.[0]??n+o,n+o),Math.max(c.used?.[1]??n+u,n+u)],c.bytes.subarray(n+o-c.at,n+u-c.at);if(o===u)return new Uint8Array(0);throw t(`source:${n+o}:${n+u}`),new Ya("unread range")},c=a||n?Fa(e,u):null,f=new Proxy(new Uint8Array(0),{get:(e,t)=>t===Oa||(t===Va?l:t===Ka?(e,t)=>ie(f,e,t):"subarray"===t?u:Object.hasOwn(i,t)?i[t]:t===Symbol.toStringTag?"Uint8Array":Ea(t)||"then"===t?void 0:c&&"string"==typeof t&&/^(0|[1-9]\d*)$/.test(t)?c(Number(t)):o()),set:o,has:o,ownKeys:o,getOwnPropertyDescriptor:o,defineProperty:o,deleteProperty:o,getPrototypeOf:()=>Uint8Array.prototype});return f}function ee(e,t){let r="a"===e?[]:"m"===e?new Map:"s"===e?new Set:{},n=Object.getPrototypeOf(r),a=()=>{throw t(),new Ya("unread value")};return new Proxy(r,{get:(e,t)=>t===Oa||(t===Va||t===Ka||"then"===t?void 0:a()),set:a,has:a,ownKeys:a,getOwnPropertyDescriptor:a,defineProperty:a,deleteProperty:a,getPrototypeOf:()=>n})}function te(e,t,r,n,a,i=1){let l=t*r,o=new Set,s=null,u=(t,r,n,a)=>e.filter(([,e,i,l,o])=>e<t+n&&t<e+l&&i<r+a&&r<i+o),c=(e,t,a,i,l)=>{let s=u(e,t,a,i),c=s.map(([e])=>e);for(let e of c)o.add(e),n(e);let f=1===r?$(s.map(([t,r,,n])=>()=>t.subarray(Math.max(0,e-r),Math.min(n,e+a-r)))):null;if(f||$a(c),f&&1===s.length&&!l)return f[0];let h=new Uint8Array(a*i);if(f){for(let t=0;t<f.length;t++)h.set(f[t],Math.max(e,s[t][1])-e);return h}for(let[r,n,l,o,u]of s){let s=Math.max(e,n),c=Math.min(e+a,n+o);for(let f=Math.max(t,l);f<Math.min(t+i,l+u);f++)h.set(r.subarray((f-l)*o+s-n,(f-l)*o+c-n),(f-t)*a+s-e)}return h},f=(e,t)=>void 0===e?t:Math.min(l,Math.max(0,(e=>e<0?l+e:e)(Math.trunc(Number(e))||0))),h=(e,n)=>{let a=f(e,0),i=Math.max(a,f(n,l));if(1===r)return[a,0,i-a,1,a,i];let o=Math.floor(a/t),s=Math.ceil(i/t);return[0,o,t,s-o,a-o*t,i-o*t]},d=(e,n)=>{let[a,i,l,o,u,f]=h(e,n);if(s)return s.subarray(i*t+u,i*t+f);if(!o||u===f)return new Uint8Array(0);let d=c(a,i,l,o);return 1===r?d:d.subarray(u,f)};return Ta({length:l,byteLength:l,byteOffset:0,BYTES_PER_ELEMENT:1,constructor:Uint8Array,subarray:d,rect:(e,r,n,a)=>{if(e*=i,!(n*=i)||!a)return new Uint8Array(0);if(!s)return c(e,r,n,a);let l=new Uint8Array(n*a);for(let i=0;i<a;i++)l.set(s.subarray((r+i)*t+e,(r+i)*t+e+n),i*n);return l},ahead:(e,a,l=0,s=t/i)=>{let[c,f,d,m]=h(e,a),p=new Set(m&&d?u(1===r?c:l*i,f,1===r?d:s*i,m).map(([e])=>e):[]);for(let e of o)p.has(e)||n(e,!1);o.clear();for(let e of p)n(e)},then:void 0,[Oa]:!1,...a},()=>s??=c(0,0,t,r,!0),Fa(l,d))}function re(e,t,r,n,a,i=()=>{},l=void 0){return te(e.flatMap((e,i)=>e.map((e,l)=>[e,l*a*4,i*n,4*Math.min(a,t-l*a),Math.min(n,r-i*n)])),4*t,r,i,{[Sa]:e.flat(),[ja]:l,[Za]:!0},4)}function ne(e,t=()=>{},r=void 0){let n=e.map(e=>za(e)?.length??e.length),a=[],i=0;e.forEach((e,t)=>{a.push([e,i,0,n[t],1]),i+=n[t]});let l=te(a,i,1,t,{sizes:n,[Sa]:e,[ja]:r,[Ka]:(e,t)=>ie(l,e,t)});return l}function ae(e,t,r){let n=e[Ka];return n?n(t,r):e.subarray(t,r)}function ie(e,t=0,r=void 0){let n=za(e),a=n?.length??e.length,i=e=>Math.max(0,Math.min(a,e<0?a+Math.trunc(e):Math.trunc(e)));if(t=i(t),r=Math.max(t,void 0===r?a:i(r)),t===r)return new Uint8Array(0);let l=ka(e,Sa);if(l&&!ka(e,Za)){let n=[],a=0;for(let i=0;i<l.length&&a<r;i++){let o=a+e.sizes[i];o>t&&n.push(ae(l[i],Math.max(0,t-a),Math.min(o,r)-a)),a=o}return ne(n)}if(!n)return e.subarray(t,r);let o=r-t,s=(r=0,n=o)=>e.subarray(t+Math.max(0,r<0?o+r:Math.min(o,r)),t+Math.max(0,n<0?o+n:Math.min(o,n))),u=Ta({length:o,byteLength:o,byteOffset:0,BYTES_PER_ELEMENT:1,constructor:Uint8Array,subarray:s,[Oa]:!1,[Va]:Object.freeze({...n,offset:n.offset+t,length:o}),[Ka]:(e,t)=>ie(u,e,t)},()=>e.subarray(t,r),Fa(o,s));return u}function le(e,t=null){let r=new Map,n=[],a=[],i=e=>{let t=r.get(e);return void 0===t&&(t=r.size,r.set(e,t),n.push({buffer:e,from:1/0,to:0})),t},l=new Map,o=new Set,s=e=>{if(null===e)return null;switch(typeof e){case"undefined":return{u:1};case"boolean":case"string":return e;case"number":return Number.isFinite(e)&&!Object.is(e,-0)?e:{n:Object.is(e,-0)?"-0":String(e)};case"object":break;default:throw Wa("unit value: "+typeof e)}let r=za(e),u=!r&&ka(e,Sa);if(r)return o.add(r.ref[0]),{t:r.type,r:r.ref,o:r.offset,l:r.length};if(!r&&ka(e,Za))throw Wa("unit value: holds pixels");if(u)return{j:u.map(s)};if(ArrayBuffer.isView(e)&&Object.getPrototypeOf(Object.getPrototypeOf(e))===Ga){let r=Ca.indexOf(e.constructor.name);if(r<0)throw Wa("unit value: typed array");let l=t?.get(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);if(l)return o.add(l[0]),{t:r,r:[l[0],l[1]],o:e.byteOffset-l[2],l:e.length};let s=i(e.buffer),u=n[s],c={t:r,b:s,o:e.byteOffset,l:e.length};return u.from=Math.min(u.from,e.byteOffset),u.to=Math.max(u.to,e.byteOffset+e.byteLength),a.push(c),c}if(l.has(e))return{p:l.get(e)};let c=Object.getPrototypeOf(e);if(!(Array.isArray(e)||e instanceof Map||e instanceof Set||c===Object.prototype||null===c))throw Wa(`unit value: ${e.constructor?.name??"class"}`);return l.set(e,l.size),Array.isArray(e)?{a:e.map(s)}:e instanceof Map?{m:[...e].map(([e,t])=>[s(e),s(t)])}:e instanceof Set?{s:[...e].map(s)}:{o:Object.keys(e).map(t=>[t,s(e[t])])}},u=s(e),c=0;for(let e of n)e.from=e.to?-8&e.from:0,e.at=c,c+=e.to-e.from;for(let e of a)e.o-=n[e.b].from;let f={v:u,buffers:n.map(e=>[e.at,e.to-e.from])},h=new Uint8Array(c);for(let{at:e,buffer:t,from:r,to:a}of n)h.set(new Uint8Array(t,r,a-r),e);return{meta:f,bytes:h,buffers:n.map(e=>e.buffer),spans:n.map(e=>[e.from,e.to]),refers:o}}function oe(e,t,r=null,n=null,a=null,i=null,l=void 0,o=null,s=null){if(!e||!Array.isArray(e.buffers))throw Wa("unit value");for(let r of e.buffers)if(!Array.isArray(r)||2!==r.length||!Number.isSafeInteger(r[0])||!Number.isSafeInteger(r[1])||r[0]<0||r[1]<0||t&&r[0]+r[1]>t.length)throw Wa("unit value");let u=s?null:o??(t?e.buffers.map(([e,r])=>t.slice(e,e+r).buffer):null),c=[],f=t=>{if(null===t||"object"!=typeof t)return t;if(!t.u){if(void 0!==t.n)return"-0"===t.n?-0:Number(t.n);if(void 0!==t.t){let l=globalThis[Ca[t.t]];if(!l||!Number.isSafeInteger(t.o)||!Number.isSafeInteger(t.l)||t.o<0||t.l<0||t.o%l.BYTES_PER_ELEMENT||(t.r?!Array.isArray(t.r)||2!==t.r.length||"string"!=typeof t.r[0]||!Number.isSafeInteger(t.r[1])||t.r[1]<0:!Number.isSafeInteger(t.b)||t.b<0||t.b>=e.buffers.length))throw Wa("unit value");if(s&&"source"!==t.r?.[0])return Q(l,t.r??[n,t.b],t.o,t.l,a,s);let o=t.r?r?.(t.r[0],t.r[1]):u?u[t.b]:null;if(null===o&&"source"===t.r?.[0]&&i){let e=t.o+t.l*l.BYTES_PER_ELEMENT,r=i(t.o,e);return r?r.byteOffset%l.BYTES_PER_ELEMENT?new l(r.slice().buffer):new l(r.buffer,r.byteOffset,t.l):l===Uint8Array?Z(t.l,a,[],t.o,i):Q(l,t.r,t.o,t.l,()=>a?.(`source:${t.o}:${e}`))}if(null===o)return Q(l,t.r??[n,t.b],t.o,t.l,a);if(!o||t.o+t.l*l.BYTES_PER_ELEMENT>o.byteLength)throw Wa("unit value");return new l(o,t.o,t.l)}if(t.j){if(!Array.isArray(t.j))throw Wa("unit value");let e=t.j.map(f);if(!e.every(e=>e instanceof Uint8Array))throw Wa("unit value");return ne(e,l)}if(void 0!==t.p){if(!Number.isSafeInteger(t.p)||t.p<0||t.p>=c.length)throw Wa("unit value");return c[t.p]}if(t.a){let e=[];c.push(e);for(let r of t.a)e.push(f(r));return e}if(t.m){let e=new Map;c.push(e);for(let[r,n]of t.m)e.set(f(r),f(n));return e}if(t.s){let e=new Set;c.push(e);for(let r of t.s)e.add(f(r));return e}if(t.o){let e={};c.push(e);for(let[r,n]of t.o)"__proto__"===r?Object.defineProperty(e,r,{value:f(n),enumerable:!0,writable:!0,configurable:!0}):e[r]=f(n);return e}throw Wa("unit value")}};return{value:f(e.v),buffers:u}}function se(e){let t=new Int32Array(e,0,e.byteLength>>2),r=new Uint8Array(e,4*t.length),n=2654435769^e.byteLength,a=2246822507;for(let e=0;e<t.length;e++)n=Math.imul(n^t[e],16777619),a=a+n|0;for(let e=0;e<r.length;e++)n=Math.imul(n^r[e],16777619);return(n^Math.imul(a,668265263))>>>0}async function ue(e,t){let r,n,a=!1;try{for(;!(n=W(e,r,t)).done;){let e=n.value;r=ni(e)?await t(e):void 0,!ni(e)&&void 0===e?.gpu&&"number"!=typeof e&&ti("step: unsupported request")}return a=!0,n.value}finally{if(!a)try{e.return?.()}catch{}}}async function ce(e,t){let r,n=!1,a=Xa(t);try{for(;!(r=W(e,void 0,a)).done;){if(t.aborted)throw t.reason;let e=r.value;void 0===e?.gpu&&"number"!=typeof e&&void 0!==e&&ti("step: unsupported request")}return n=!0,r.value}finally{if(!n)try{e.return?.()}catch{}}}async function fe(e,t,r){let n=[];for(let a=0;a<e.length;a+=ca){let i,l=Math.min(e.length,a+ca),o=await t({unit:"file-part"});if(o)n.push(o[Na]);else{try{i=await r.write(e.subarray(a,l))}catch(e){throw await t({unitFailed:"file-part"}),e}e.ahead(l,l+ca),await t({unitDone:"file-part",value:i}),n.push(i)}}return n}function he(e,t){if(void 0===e.metaLength)return{meta:e.meta,bytes:t};let r=ui.get(t);if(r&&r.entry===e)return r.value;(!Number.isSafeInteger(e.metaLength)||e.metaLength<2||e.metaLength>t.length||!["a","o","m","s"].includes(e.kind))&&ti("invalid journal value");let n=t.subarray(0,e.metaLength),a=E(n instanceof hi?n.slice(0):n);si(a?.v)!==e.kind&&ti("invalid journal value");let i={meta:a,bytes:t.subarray(e.metaLength)};return ui.set(t,{entry:e,value:i}),i}async function de(e,t){let r=[],n=0,a=async()=>{if(!n)return;let t=new Uint8Array(n),a=0;for(let e of r)t.set(e.bytes,a),a+=e.bytes.length;let i=await e.write(t);a=0;for(let e of r)e.slices.push([i,a,e.bytes.length]),a+=e.bytes.length;r=[],n=0};for(let{entry:e,bytes:i,alone:l}of t){let t=[],o=i;(l||e.carry)&&await a();for(let e=0;e<o.length;){let i=Math.min(o.length-e,ca-n);r.push({bytes:o.subarray(e,e+i),slices:t}),n+=i,e+=i,n===ca&&await a()}(l||e.carry)&&await a(),e.bytes=t}await a()}async function me(e,t){let r=new Map,n=t.map(e=>{(!Number.isSafeInteger(e.length)||e.length<0)&&ti("journal value length");let t={length:e.length,spans:[]},n=0;for(let[a,i,l]of ci(e)){va(a),i+l>a.length&&ti("journal slice: out of bounds");let e=r.get(a.hash)??{ref:a,spans:[]};e.ref.length!==a.length&&ti("part length mismatch"),e.spans.push({value:t,from:i,length:l,at:n}),r.set(a.hash,e),n+=l}return(n!==e.length||!e.length&&ci(e).length)&&ti("journal value length"),t});return await k(e,[...r.values()].map(e=>e.ref),async t=>{for(let n of t){let t=await e.borrow(n);for(let{value:e,from:a,length:i,at:l}of r.get(n.hash).spans)e.spans.push({at:l,bytes:t.subarray(a,a+i)})}}),n.map(({spans:e})=>(e.sort((e,t)=>e.at-t.at),e.length?1===e.length?e[0].bytes:new hi(e.map(e=>e.bytes)):new Uint8Array(0)))}function pe(e){let t=new Map,r=[];for(let r of Object.values(e.journal)){if(!r.meta)continue;let e=JSON.stringify(r.meta);if(e.length<32)continue;let n=t.get(e);n?n.push(r):t.set(e,[r])}for(let e of t.values()){if(e.length<2)continue;let t=r.length;r.push(e[0].meta);for(let r of e)delete r.meta,r.metaIndex=t}return r.length?{...e,metas:r}:e}function ye(e,t){void 0!==t&&!Array.isArray(t)&&ti("Invalid journal layouts.");for(let r of Object.values(e)){if(void 0===r?.metaIndex)continue;let e=r.metaIndex;(!Number.isSafeInteger(e)||e<0||!t||e>=t.length||void 0!==r.meta||void 0!==r.metaLength||r.passed||!t[e]||"object"!=typeof t[e]||!Array.isArray(t[e].buffers))&&ti("Invalid journal layout reference."),r.meta=t[e],delete r.metaIndex}}function ge({id:e,build:t,normalize:r,open:n,run:a,verify:i,eager:l=!1,tools:o={},straight:s}){s??=n&&((e,t,r,a)=>ce(n(e,t,r,!0),a));let u=e=>(Object.hasOwn(o,e)||ti("unknown journal tool"),o[e]);return G({id:e,build:t,normalize:r,start:(e,t)=>({journal:{},plan:e,source:t,hot:[]}),refs:e=>Object.values(e?.journal??{}).flatMap(e=>e.passed||!Array.isArray(e.bytes)?[]:e.bytes.map(e=>e[0])),async step(e,t){let{journal:r,plan:c,source:f,hot:h=[],tried:d=!1,costs:m={}}=e,p=t,y=t.reads??1/0,g=p.callsRead(),M=()=>p.callsRead()-g,b=!1;(!r||"object"!=typeof r||Array.isArray(r)||!c||!f||!Array.isArray(h)||!h.every(e=>"string"==typeof e)||"boolean"!=typeof d||!m||"object"!=typeof m||Array.isArray(m)||!Object.values(m).every(e=>Number.isFinite(e)&&e>=0))&&ti("invalid journal state"),ye(r,e.metas);let w=ai(),L=p.budgetMs??c.budgetMs??20,A=t.memoryBytes??1/0,v=0,I=0,x=null,N=(e=0)=>{let t=new Set,r=e,n=e=>{let n=e?.buffer;n&&!t.has(n)&&(t.add(n),r+=n.byteLength)},a=e=>{e instanceof hi?e.spans.forEach(n):n(e)};if(Pe)n(Pe);else for(let e of Ue)n(e.bytes);for(let e of P.values())a(e);for(let{buffers:e}of E.values())for(let n of e)n&&!t.has(n)&&(t.add(n),r+=n.byteLength);for(let{bytes:e}of J)e&&a(e);if(I=r-e,r>v&&(v=r),r>A)throw x=Vr("JXL_MEMORY",`held ${r} B: over memoryBytes ${A}`)},O=!d&&!Object.keys(r).length&&"function"==typeof p.straight&&await p.straight(await p.readSource(0,Math.min(f.byteLength,65536)),L),P=new Map,U=e=>+e.toFixed(1),S=new Set,E=new Map,T=(e,t)=>{!t?.length||E.has(e)||(E.set(e,{buffers:t,sums:t.map(se)}),I+=t.reduce((e,t)=>e+(t?.byteLength??0),0),I>A&&N())},F=e=>{let t=E.get(e);return t&&t.buffers.every((e,r)=>se(e)===t.sums[r])?t.buffers:(E.delete(e),null)},J=[],_=new Set,B=new Set,R=new Map,X=new Map,D=e=>{let t=X.get(e);t&&(W-=t.bytes.length,e.carry&&(V-=t.bytes.length),t.bytes=null,X.delete(e))},C=new Set,G=new WeakMap,W=0,V=0,K=!1,z=0,Y=[],q=["",0],$=null,Q=0,te=0,re=null,ae=!1,ie=!1,ce=!1,ge=new Map(Object.entries(m)),Me=0,be=0,we=0,Le=0,Ae=0,ve=0,Ie=0,xe=0,Ne=null,Oe=null,Pe=null,Ue=[],Se=async e=>{let t=ai();for(let[t,r]of e){if(Ue.some(e=>e.at<=t&&r<=e.at+e.bytes.length))continue;let e=Ue.filter(e=>e.at<=r&&t<=e.at+e.bytes.length),n=Math.min(t,...e.map(e=>e.at)),a=Math.max(r,...e.map(e=>e.at+e.bytes.length)),i=new Uint8Array(a-n),l=n,o=async(e,t)=>{for(let r=e;r<t;r+=li){let e=await p.readSource(r,Math.min(li,t-r));i.set(e,r-n),ve+=e.length}};for(let t of e.sort((e,t)=>e.at-t.at))t.at>l&&await o(l,t.at),i.set(t.bytes,t.at-n),l=Math.max(l,t.at+t.bytes.length);l<a&&await o(l,a);for(let t of e)Ue.splice(Ue.indexOf(t),1);Ue.push({at:n,bytes:i})}Le+=ai()-t},je=async e=>{if(e.includes("source")&&!Pe){ce||(ae=!0,null===$&&(ie=!0)),N(f.byteLength);let e=ai();Pe=await p.readSource(0,f.byteLength),Le+=ai()-e,ve+=Pe.length,ce||(z=Pe.length),Ue.length=0}let t=Pe?[]:e.filter(e=>e.startsWith("source:")).map(e=>e.split(":").slice(1).map(Number));t.length&&await Se(t);let n=e.filter(e=>!e.startsWith("source")&&r[e]&&!r[e].passed&&!P.has(e));if(!n.length)return;let a=ai(),i=n.map(e=>r[e]);i.forEach(fi),N(i.reduce((e,t)=>e+t.length,0));let l=await me(p,i);for(let[e,t]of n.entries())P.set(t,l[e]),Ae+=i[e].length;N(),we+=ai()-a},Ee="function"==typeof l?l(f):l,Te=h.find(e=>e.startsWith("source@"))?.slice(7),Fe="*"===Te,ke=h.filter(e=>"!"===e[0]).map(e=>e.slice(1)),Je=new Set(h.filter(e=>"~"===e[0]).map(e=>e.slice(1))),_e=[...Ee&&f.byteLength<=oi||void 0!==Te?["source"]:[],...h.filter(e=>r[e]||e.startsWith("source:")),...ke.filter(e=>r[e])];if(ce=!0,O&&await je(["source"]),O&&s&&!c.verify){let t,r=new AbortController,n=r.signal,a=w+L,i=!1;Object.defineProperty(n,"aborted",{get:()=>(!i&&(ai()>=a||p.signal?.aborted)&&(i=!0,r.abort(p.signal?.aborted?p.signal.reason:ri)),i)});try{t=await s(c,Pe,f,n,async e=>(await k(p,[e]),p.borrow(e)),p)}catch(t){if(!i||p.signal?.aborted)throw t;return{state:{...e,tried:!0},work:{phase:"straight",stepMs:+(ai()-w).toFixed(1)},reads:[],yield:!0}}let l=t instanceof Uint8Array?t:t?.bytes,o=t instanceof Uint8Array?null:t?.facts??null;return l instanceof Uint8Array||ti("steps: missing output"),{state:{journal:{},plan:c,source:f,hot:[]},work:{phase:"straight",stepMs:+(ai()-w).toFixed(1)},output:l.length?l:null,result:{length:l.length,facts:o}}}_e.length&&await je(_e),ce=!1,N();let Be,Re,Xe=Math.max(Ae+ve,p.bytesRead()),De=new WeakMap,Ce=(e,t)=>Be(e,t),Ge=e=>Re(e);for(;;){Ie++,$=null,Q=ai();let e=new Set,l=t=>e.add(t),s=Pe??Z(f.byteLength,l,Ue),h=new Map,d=new Map,m=new Map,g={get:(e,t,r)=>{let n=d.get(e);return n&&n[2]<=t&&r<=n[3]&&("source"===n[0]?r-t>=65536:m.get(e)===se(e))?n:void 0}},v=(e,t)=>{let r=Ue.find(r=>r.at<=e&&t<=r.at+r.bytes.length);return r?r.bytes.subarray(e-r.at,t-r.at):null},U=(e,t)=>{if("source"===e)return 0!==t?void 0:Pe?Pe.buffer:null;if(!h.has(e)){r[e]||ti("journal reference: missing");let t=P.get(e);if(!t)return null;let{meta:n,bytes:a}=he(r[e],t),i=a?F(e):null;a&&!i&&I+a.length>A&&N(a.length);let o=oe(n,a,U,e,l,v,void 0,i);a&&T(e,o.buffers),ie(e,o.buffers)}return h.get(e)?.[t]??null},ae=(e,t)=>{r[e]||ti("A journal value refers to a missing value.");let n=P.get(e);if(!n)return null;let{meta:a,bytes:i}=he(r[e],n),l=a?.buffers?.[t];return(!Array.isArray(l)||2!==l.length||!l.every(e=>Number.isSafeInteger(e)&&e>=0)||l[0]+l[1]>i.length)&&ti("Invalid journal buffer span."),i instanceof Uint8Array&&(i.byteOffset+l[0])%8==0?i.subarray(l[0],l[0]+l[1]):U(e,t)};Be=ae,Re=l;let ie=(e,t,r=null)=>{h.set(e,t);let n=E.get(e)?.buffers===t?E.get(e).sums:null;t?.forEach((t,a)=>{d.set(t,[e,a,r?r[a][0]:0,r?r[a][1]:t.byteLength]),m.set(t,n?n[a]:se(t))})};Pe&&d.set(Pe.buffer,["source",0,0,Pe.byteLength]);let ce,de=[{path:"",children:0}],me=!1,pe=async t=>{if(x)throw x;if(e.size||me)throw ri;if(O){if(ai()-w>=L)throw me=!0,ri;return void 0!==t.unit?void de.push({name:t.unit}):void(de.pop()?.name!==(t.unitDone??t.unitFailed)&&ti("journal units: unbalanced"))}if(void 0!==t.unit){if(K&&!t.tail&&!de.some(e=>e.whole))throw me=!0,ri;let e=de.at(-1),n=(e.path?e.path+".":"")+e.children++,a=r[n];if(a){if((a.name!==t.unit||!!a.carry!=!!t.carry)&&ti("journal: step mismatch"),a.passed)return xe++,{[Na]:Da};let e=P.get(n)??null;if(void 0!==a.metaLength&&!e){if(void 0!==t.answer)throw l(n),ri;xe++;let e=ee(a.kind,()=>l(n));return G.set(e,n),{[Na]:e}}let{meta:r,bytes:i}=he(a,e),o=!!a.borrowed&&!t.answer,s=i&&!o?F(n):null;i&&!o&&!s&&I+i.length>A&&N(i.length);let c=ai(),f=o&&void 0!==r.v?.t&&!r.v.r,h=f&&De.get(a);h||(h=oe(r,i,U,n,f?Ge:l,v,(e,t)=>pe.touched(e,t),s,o?f?Ce:ae:null),f&&De.set(a,h)),i&&!o&&T(n,h.buffers),e&&_.add(n),!a.carry&&!o&&ie(n,i?h.buffers:null),te+=ai()-c,xe++;let d=void 0!==t.answer?u(t.answer).answer(h.value):h.value;return null!==d&&"object"==typeof d&&G.set(d,n),{[Na]:d}}if(Me&&!t.tail&&!de.some(e=>e.whole)&&(W-V>=16777216||ai()-w-Le+(ge.get(t.unit)??q[1])>=L))throw me=!0,ri;return t.tail&&(K=!1),null===$&&($=ai()-Q),re=e.path,void de.push({path:n,children:0,name:t.unit,carry:!!t.carry,whole:!!t.whole,cold:!!t.cold,borrowed:!!t.borrowed,alone:!!t.alone,started:ai()})}let n=de.pop(),a=ai()-n.started;if(n?.name&&!n.whole&&ge.set(n.name,a),a>q[1]&&(q=[de.map(e=>e.name).filter(Boolean).concat(n.name).join("/"),+a.toFixed(1)]),(!n?.name||n.name!==(t.unitDone??t.unitFailed))&&ti("journal units: unbalanced"),void 0!==t.unitFailed)return;let i=n.path+".",o="function"==typeof t.save?t.save(t.value):t.save?u(t.save.tool).save(t.value,t.save.extra?.(t.value)):t.value,s=ai(),c=le(o,{get:(e,t,r)=>{let n=g.get(e,t,r);return!n||"string"==typeof n[0]&&n[0].startsWith(i)?void 0:n}});if(n.children){let e=new Set(c.refers);for(let t of e)for(let n of r[t]?.refers??[])e.add(n);for(let t of Object.keys(r))t.startsWith(i)&&!e.has(t)&&(D(r[t]),delete r[t],h.delete(t),P.delete(t),E.delete(t));for(let[e,t]of d)"string"==typeof t[0]&&t[0].startsWith(i)&&(d.delete(e),m.delete(e))}let{meta:f,bytes:y,buffers:M,spans:b}=c;if(n.carry){let e=n.path.slice(0,n.path.lastIndexOf(".")+1),t=+n.path.slice(e.length);for(let a=0;a<t;a++){let t=e+a,i=r[t];i?.carry&&!i.passed&&i.name===n.name&&(D(i),r[t]={name:i.name,carry:!0,passed:!0},h.delete(t),P.delete(t),E.delete(t))}}let S=si(f.v),k=void 0!==S?JSON.stringify(f):null,B=null!==k&&k.length>1024,R=B?j(f,k):null,C=B?ne([R,y]):y,H=[...c.refers].filter(e=>"source"!==e),Y=r[n.path]={name:n.name,...n.carry&&{carry:!0},...n.cold&&{cold:!0},...n.borrowed&&{borrowed:!0},...B?{kind:S,metaLength:R.length}:{meta:f},...H.length&&{refers:H},length:C.length,bytes:[]};B&&ui.set(C,{entry:Y,value:{meta:f,bytes:y}});let Z={entry:Y,bytes:C,alone:n.alone};J.push(Z),X.set(Y,Z),W+=C.length,n.carry&&(V+=C.length),P.set(n.path,C),n.carry?h.set(n.path,M):ie(n.path,M,b),be+=ai()-s,Me++,de.some(e=>e.whole)||(K=Math.max(Ae+ve,p.bytesRead())-Xe-z>=sa),N()},ye=null,we=!1;pe.tools=o,pe.host=p,H(pe),pe.part=async e=>{if(M()>=y)throw me=!0,ri;return await k(p,[e]),p.borrow(e)},pe.join=e=>ne(e,pe.touched),pe.done=e=>{let t=G.get(e)??ei(e)??d.get(e?.buffer)?.[0];void 0===t||!r[t]||(S.add(t),C.delete(t),P.delete(t),E.delete(t))},pe.touched=(e,t=!0)=>{let n=G.get(e)??ei(e)??d.get(e?.buffer)?.[0];if(void 0!==n){if(t)return C.add(n),void S.delete(n);if(C.delete(n),r[n]?.borrowed&&!X.has(r[n])){S.add(n),B.delete(n),P.delete(n),E.delete(n),h.delete(n);for(let[e,t]of d)t[0]===n&&(d.delete(e),m.delete(e))}}};try{ce=await(a?a(c,s,f,pe):ue(n(c,s,f),pe)),c.verify&&("function"!=typeof i&&ti("verify: unsupported"),ce=await i(ce,c,s,f,pe,t));let e=ce instanceof Uint8Array?ce:ce?.bytes;ka(e,Sa)&&(ye=await fe(e,pe,p))}catch(t){if(!e.size&&!me)throw t}e.size&&(we=!0);let Se=!we&&me;if(we){let t=0;for(let n of[...e]){if(!r[n]||(B.add(n),r[n].borrowed))continue;let a=r[n].name;if((R.get(a)??0)<1){R.set(a,1);continue}let i=n.slice(0,n.lastIndexOf(".")+1),l=r[n].name;for(let[n,a]of Object.entries(r))if(!(e.has(n)||P.has(n)||S.has(n)||a.passed||a.name!==l||!n.startsWith(i)||n.slice(i.length).includes("."))){if((t+=a.length)>4194304)break;e.add(n)}}for(let t of e)t.startsWith("source:")&&Y.push(t);if(M()>=y){b=!0,Ne=null;break}let n=Y.length>1?Math.min(1048576,32768*2**Math.min(Y.length,16)):0;await je([...e].map(e=>{if(!n||!e.startsWith("source:"))return e;let[t,r]=e.split(":").slice(1).map(Number);return`source:${t}:${Math.min(f.byteLength,Math.max(r,t+n))}`})),N();continue}Ne=Se?null:ce,Oe=ye;break}if(O&&null===Ne)return{state:{...e,tried:!0},work:{phase:"straight",stepMs:+(ai()-w).toFixed(1),attempts:Ie},reads:[],yield:!0};let We=ai(),Ve=new Map(Object.entries(r).map(([e,t])=>[t,e]));null===Ne&&await de(p,J.filter(({entry:e})=>Ve.has(e)));let Ke=ai()-We,ze={phase:"journal",stepMs:+(ai()-w).toFixed(1),decodeMs:+te.toFixed(1),longest:q,replayMs:+($??ai()-Q).toFixed(1),attempts:Ie,answered:xe,fresh:Me,entries:Object.keys(r).length,readBytes:Ae,sourceBytes:ve,sourceMs:U(Le),loadMs:U(we),saveMs:U(be),pageMs:U(Ke),savedBytes:J.reduce((e,{bytes:t})=>e+(t?.length??0),0),hold:{peak:v,limit:A}};if(globalThis[ii]?.(ze),null!==Ne){let e=Ne instanceof Uint8Array?Ne:Ne?.bytes,t=Ne instanceof Uint8Array?null:Ne?.facts??null;return e instanceof Uint8Array||ti("steps: missing output"),{state:{journal:{},plan:c,source:f,hot:[]},work:ze,output:e.length?e:null,...Oe&&{outputRefs:Oe},result:{length:e.length,facts:t,...c.verify&&{verification:Ne.verification}}}}let He=new Set([...B,...C]);if(b)for(let e of P.keys())r[e]&&!r[e].passed&&He.add(e);for(let{entry:e}of J)Ve.has(e)&&!e.cold&&He.add(Ve.get(e));let Ye=null,qe=e=>{if(!Ye){Ye=new Map;for(let e of Object.keys(r)){let t=e.slice(0,e.lastIndexOf(".")+1)+"\0"+r[e].name,n=Ye.get(t);n?n.push(e):Ye.set(t,[e])}for(let[e,t]of Ye){let r=e.indexOf("\0");t.sort((e,t)=>+e.slice(r)-+t.slice(r))}}return Ye.get(e.slice(0,e.lastIndexOf(".")+1)+"\0"+r[e].name)};for(let e of h)_.has(e)&&r[e]&&!r[e].passed&&!r[e].cold&&qe(e).at(-1)===e&&He.add(e);let $e=new Map;for(let e of B)if(r[e]){let t=qe(e),r=t[0];$e.set(r,{list:t,at:Math.max($e.get(r)?.at??-1,t.indexOf(e)),count:($e.get(r)?.count??0)+1})}for(let{list:e,at:t,count:n}of $e.values())for(let a of e.slice(t+1,t+1+n))r[a].passed||He.add(a);let Qe=0,Ze=e=>ci(r[e]).reduce((e,[t])=>e+t.length,0);for(let e of He)r[e]&&!r[e].passed&&(Qe+=Ze(e));let et=Math.min(sa,Math.max(1048576,262144*($??ai()-Q)));for(let e of[..._].reverse())!He.has(e)&&r[e]&&!r[e].passed&&!r[e].cold&&(Qe+=Ze(e))<=et&&He.add(e);let tt=e=>r[e]&&!r[e].passed,rt=new Set([...ke,...[...B].filter(e=>Je.has(e))].filter(e=>tt(e)&&!r[e].cold)),nt=[...new Set([...h.filter(e=>r[e]&&!He.has(e)),...Je])].filter(e=>tt(e)&&!rt.has(e)&&!B.has(e)&&!He.has(e)).slice(0,256),at=Fe||ie?"*":f.byteLength>oi?null:ae?re:Pe&&void 0!==Te&&re===Te?Te:null,it=0,lt=null!==at||Pe?[]:[...Y.map(e=>{let[t,r]=e.split(":").slice(1).map(Number);return[t,Math.min(f.byteLength,r+(r-t))]}),...Ue.filter(e=>e.used).map(e=>e.used)].filter(([e,t])=>(it+=t-e)<=oi).map(([e,t])=>`source:${e}:${t}`);for(let e of S)B.has(e)||(He.delete(e),rt.delete(e));let ot={journal:r,plan:c,source:f,...d&&{tried:d},costs:Object.fromEntries([...ge].map(([e,t])=>[e,Math.round(t)])),hot:[...null!==at?["source@"+at]:[],...lt,...[...He].filter(e=>tt(e)&&!rt.has(e)),...[...rt].map(e=>"!"+e),...nt.map(e=>"~"+e)]},st=[],ut=0;for(let e of new Map([...rt,...ot.hot.filter(e=>r[e])].flatMap(e=>ci(r[e]).map(([e])=>[e.hash,e]))).values()){if(64===st.length||ut+e.length>sa)break;st.push(e),ut+=e.length}return{state:pe(ot),work:ze,reads:st,yield:!0}}})}function Me(e){let[t,r,n,a,i,l,o,s,u]=e,c=i*u-l*s,f=l*o-a*u,h=a*s-i*o,d=t*c+r*f+n*h;return[c,n*s-r*u,r*l-n*i,f,t*u-n*o,n*a-t*l,h,r*o-t*s,t*i-r*a].map(e=>e/d)}function be(e,t){let r=new Array(9);for(let n=0;n<3;n++)for(let a=0;a<3;a++)r[3*n+a]=e[3*n]*t[a]+e[3*n+1]*t[3+a]+e[3*n+2]*t[6+a];return r}function we(e,t,r,n){let a=String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3));if("curv"===a){let a=e.getUint32(t+8);if(12+2*a>r)return null;if(0===a)return e=>e;if(1===a){let r=e.getUint16(t+12)/256;return e=>mi(e,r)}let i=n?n(t+12,a):Float64Array.from({length:a},(r,n)=>e.getUint16(t+12+2*n)/65535),l=n?i:e=>i[e];return e=>{let t=e*(a-1),r=Math.min(a-2,Math.floor(t)),n=l(r);return n+(l(r+1)-n)*(t-r)}}if("para"===a){let n=e.getUint16(t+8),a=[1,3,4,5,7][n];if(void 0===a||12+4*a>r)return null;let[i,l=1,o=0,s=0,u=0,c=0,f=0]=Array.from({length:a},(r,n)=>pi(e,t+12+4*n));return 0===n?e=>mi(e,i):1===n?e=>l*e+o>=0?mi(l*e+o,i):0:2===n?e=>l*e+o>=0?mi(l*e+o,i)+s:s:3===n?e=>e>=u?mi(l*e+o,i):s*e:e=>e>=u?mi(l*e+o,i)+c:s*e+f}return null}function Le(e){let t=yi(e),r=t(16);return"RGB "!==r&&"GRAY"!==r||"XYZ "!==t(20)?null:{space:r,count:e.getUint32(128)}}function Ae(e,t,r,n=132){let a=yi(e);for(let i=0;i<t;i++,n+=12){let t=a(n),i=e.getUint32(n+4),l=e.getUint32(n+8);["rXYZ","gXYZ","bXYZ","rTRC","gTRC","bTRC","kTRC","A2B0","A2B1","A2B2"].includes(t)&&r.set(t,{offset:i,length:l})}return r}function ve(e,t,r){return r<20||"XYZ "!==yi(e)(t)?null:[pi(e,t+8),pi(e,t+12),pi(e,t+16)]}function Ie(e){return Mi(()=>{if(!e||e.length<132)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=Le(t);if(!r)return null;let{space:n,count:a}=r,i=Ae(t,a,new Map);if(i.has("A2B0")||i.has("A2B1")||i.has("A2B2"))return null;let l=e=>{let r=i.get(e);return r&&we(t,r.offset,r.length)},o=e=>Float64Array.from({length:256},(t,r)=>Math.max(0,Math.min(1,e(r/255))));if("GRAY"===n){let e=l("kTRC");return e&&{gray:!0,tables:[o(e)],curves:[e]}}let s=["rXYZ","gXYZ","bXYZ"].map(e=>{let r=i.get(e);return r?ve(t,r.offset,r.length):null}),u=["rTRC","gTRC","bTRC"].map(l);return s.includes(null)||u.includes(null)?null:{gray:!1,tables:u.map(o),curves:u,xyz:gi(s)}})}function xe(e,t){let r=Li(wi,e),n=Li(wi,t);return be(Me(wi),be([n[0]/r[0],0,0,0,n[1]/r[1],0,0,0,n[2]/r[2]],wi))}function Ne(e,t){let r=[0,1,2].map(t=>vi(e[t])),n=[r[0][0],r[1][0],r[2][0],r[0][1],r[1][1],r[2][1],r[0][2],r[1][2],r[2][2]],a=Li(Me(n),vi(t));return n.map((e,t)=>e*a[t%3])}function Oe(e){let t=Ie(e);if(!t)return null;let r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=r.getUint32(64);if(n>3)return null;let a=t.gray?[t.curves[0]]:t.curves;if(!a.every(e=>{for(let t=0;t<=255;t++){let r=e(t/255);if(!(r>=0&&r<=1))return!1}return!0}))return null;for(let t=0,n=r.getUint32(128);t<n;t++){let r=132+12*t,n=String.fromCharCode(e[r],e[r+1],e[r+2]);if("B2A"===n||"B2D"===n||"D2B"===n)return null}let i,l,o=a[0](.5);if(!(o>=0&&o<=1))return null;let s=di(Math.max(1e-9,o))/di(.5);if(s>.05&&a.every(e=>Ui(e,e=>mi(e,s)))&&(Math.abs(s-1)<.001?i=8:8192*Math.round(1e7/s)>=1e7&&s>1&&(l=Math.round(1e7/s)/1e7)),void 0===i&&void 0===l){let e=Pi.find(([,e])=>a.every(t=>Ui(t,e)));if(!e)return null;i=e[0]}let u=new Map;for(let t=0,n=r.getUint32(128);t<n;t++){let n=132+12*t,a=String.fromCharCode(e[n],e[n+1],e[n+2],e[n+3]);u.set(a,{offset:r.getUint32(n+4),length:r.getUint32(n+8)})}let c=u.get("chad"),f=u.get("wtpt"),h=bi;c&&c.length>=44?h=Li(Me(Array.from({length:9},(e,t)=>pi(r,c.offset+8+4*t))),bi):f&&f.length>=20&&(h=[0,1,2].map(e=>pi(r,f.offset+8+4*e)));let d=Ai(h);if(![...d].every(Number.isFinite))return null;let m=Ii.find(([,e])=>Ni(e,d)),p=m?{enum:m[0],xy:m[1]}:{enum:2,xy:Oi(d)},y={gray:t.gray,white:p,transfer:i,gamma:l,intent:n};if(t.gray)return y;let g=be(xe(bi,vi(p.xy)),t.xyz),M=[0,1,2].map(e=>Ai([g[e],g[3+e],g[6+e]]));if(!M.flat().every(Number.isFinite))return null;let b=xi.find(([,e])=>e.every((e,t)=>Ni(e,M[t])));return y.primaries=b?{enum:b[0],xy:b[1]}:{enum:2,xy:M.map(Oi)},be(xe(vi(p.xy),bi),Ne(y.primaries.xy,p.xy)).every((e,r)=>Math.abs(e-t.xyz[r])<.002)?y:null}function Pe(e,t){let r=e?.data;if(!t||!e.icc||void 0!==e.colorEncoding||!(r instanceof Uint8Array||r instanceof Uint8ClampedArray)||8!==(e.bitDepth??8)||"uint"!==(e.sampleFormat??"uint")||"srgb"!==(e.colorSpace??"srgb"))return e;let n=Fi(e.icc);if(!n)return e;let{icc:a,colorSpace:i,...l}=e;return{...l,colorEncoding:n}}function Ue(e){try{let t=t=>(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0,r=255===e[0]&&10===e[1]?e:null;for(let n=0;!r&&n+8<=e.length;){let a=t(n),i=n+8,l=t(n+4);1===a?(a=4294967296*t(n+8)+t(n+12),i+=8):a||(a=e.length-n);let o=n+a;if(o<i||o>e.length)return null;1786276963===l?r=e.subarray(i,o):1786276976===l&&o-i>=4&&!(2147483647&t(i))&&(r=e.subarray(i+4,o)),n=o}if(!r)return null;let n=0,a=e=>{let t=0;for(let a=0;a<e;a++,n++){if(n>>3>=r.length)throw 0;t+=(r[n>>3]>>(7&n)&1)*2**a}return t},i=()=>a([9,13,18,30][a(2)])+1;if(2815!==a(16))return null;let l=a(1),o=l?8*(a(5)+1):i(),s=a(3);return{height:o,width:s?Math.floor(o*[0,1,12,4,3,16,5,2][s]/[1,1,10,3,2,9,4,1][s]):l?8*(a(5)+1):i()}}catch{return null}}async function Se(e,t,r,n){if(!_i(r))throw fn("JXL_INPUT","finished record: job result record");let a,{width:i,height:l,format:o="jxl",fidelity:s,kept:u,measurements:c,transform:f,readAs:h,originalBytes:d,usedWebGPU:m}=r,p=f??{width:i,height:l};if(void 0!==d&&"file"===n.kind&&d!==n.byteLength)throw fn("JXL_INPUT","finished record: original size required");if(t&&"jxl"===o){let e=Ue(t);if(!e||!(e.width===p.width&&e.height===p.height||e.width===p.height&&e.height===p.width))throw fn("JXL_INPUT","finished record: file mismatch")}try{a=await e(t,{width:i,height:l},{fidelity:s,measurements:c,format:o,...t&&void 0!==u&&{kept:u},...void 0!==f&&{transform:f},...void 0!==h&&{readAs:h},...void 0!==d&&{originalBytes:d},...void 0!==m&&{usedWebGPU:m},owned:!0})}catch{throw fn("JXL_INPUT","finished record: job result record")}for(let e of new Set([...Object.keys(r),...Object.keys(a)]))if("bytes"!==e&&"source"!==e&&Bi(a[e])!==Bi(r[e]))throw fn("JXL_INPUT","finished record: file mismatch");let y="decode"===n.kind?r.source:void 0;if(void 0===y)return a;if(!_i(y)||"bytes"!==y.kind||!/^sha256:[0-9a-f]{64}$/.test(y.digest)||2!==Object.keys(y).length)throw fn("JXL_INPUT","finished record: original required");return{...a,source:{kind:"bytes",digest:y.digest}}}function je(e,t=0){return!(null!==e&&!["string","number","boolean"].includes(typeof e))||!(t>8||"object"!=typeof e)&&(Array.isArray(e)?e.every(e=>je(e,t+1)):Object.getPrototypeOf(e)===Object.prototype&&Object.values(e).every(e=>je(e,t+1)))}async function Ee(e,t){let{decode:r,restore:n}=(void 0!==t?t:Wn())??{};if(!r)throw fn("JXL_PLATFORM","decoder: configureDecoder(decode) with decode from jpegxl/decode");let a,i=await r(e);if("uint8"!==i.format||"string"!=typeof i.colorSpace)throw fn("JXL_UNSUPPORTED","decoded pixels: 8-bit named colorSpace");if(n&&i.header?.reconstruction){let t=(await n(e)).bytes;a="sha256:"+I(v(qn(),t))}return{data:new Uint8Array(i.data.buffer,i.data.byteOffset,i.data.length),width:i.width,height:i.height,...0===i.colorEncoding?.renderingIntent||i.colorEncoding?.renderingIntent>1?{colorEncoding:i.colorEncoding}:{colorSpace:i.colorSpace},...a&&{source:a}}}async function Te(e){let t=await e;if(Array.isArray(t)){let e=t.map(({bytes:e,...t})=>({...t,length:e?e.length:null})),r=new Uint8Array(e.reduce((e,t)=>e+(t.length??0),0)),n=0;for(let e of t)e.bytes&&(r.set(e.bytes,n),n+=e.bytes.length);return{bytes:r,facts:{records:e}}}let{bytes:r,...n}=t;return{bytes:r??new Uint8Array(0),facts:{record:n,missed:!r}}}async function Fe(e,t){let r=await e,{bytes:n}=r;if(!t||n.length<=Ci||ka(n,Sa))return r;let a=[];for(let e=0;e<n.length;e=Math.min(n.length,e?e+Gi:Ci)){let r=Math.min(n.length,e?e+Gi:Ci),i=await t({unit:"output-piece",cold:!0});if(i&&Object.hasOwn(i,Na)){a.push(i[Na]);continue}let l=n.slice(e,r);await t({unitDone:"output-piece",value:l}),a.push(l)}return{...r,bytes:t.join(a)}}async function ke(e,t){let r=await e,n=r.facts?.record;return"file"===(t.kind??"pixels")&&n&&void 0===n.originalBytes&&Number.isSafeInteger(t.byteLength)&&r.bytes.length?{...r,facts:{...r.facts,record:{...n,originalBytes:t.byteLength,largerThanOriginal:r.bytes.length>t.byteLength}}}:r}function Je(e){return e.components.forEach((t,r)=>{let{coeffs:n}=t,a=e.nonZero?.[r]??_e(n),i=0;for(let e=0;e<a.length;e++)i+=a[e];let l=new Uint8Array(i),o=new Int16Array(i),s=t.stride,u=new Uint32Array(a.length/s);for(let e=0,t=0;e<a.length;e++){let r=64*e;e%s===0&&(u[e/s]=t);for(let i=1,s=a[e];s;i++){let e=n[r+i];e&&(l[t]=i,o[t++]=e,s--)}}t.packed={at:l,levels:o,counts:a,starts:u,segment:s,length:n.length},t.coeffs=null}),e}function _e(e){let t=new Uint8Array(e.length/64);for(let r=0;r<t.length;r++){let n=0;for(let t=1;t<64;t++)n+=0!==e[64*r+t];t[r]=n}return t}function Be(e){let t=e[0];if(!t||Object.getPrototypeOf(t)!==Object.prototype)return null;let r=Object.keys(t).filter(e=>!Vi.has(e)),n=r.map(e=>"number"==typeof t[e]?"n":Hi(t[e])?"v":Yi(t[e])?"d"+t[e].length+":"+Wi.indexOf(t[e][0].constructor.name):null);if(n.includes(null))return null;let a=[],i=[],l=new Map,o=[];for(let t of e){if(Object.getPrototypeOf(t)!==Object.prototype)return null;let e=Object.keys(t).filter(e=>!Vi.has(e));if(e.length!==r.length||e.some((e,t)=>e!==r[t]))return null;for(let e=0;e<r.length;e++){let s=t[r[e]],u=n[e];if("n"===u){if("number"!=typeof s)return null;a.push(s)}else if("v"===u){if(!Hi(s))return null;let e=l.get(s);void 0===e&&(e=o.length,l.set(s,e),o.push(s)),i.push(e)}else{let[e,t]=u.slice(1).split(":").map(Number);if(!Yi(s)||s.length!==e||s.some(e=>Wi.indexOf(e.constructor.name)!==t))return null;for(let e of s)a.push(e[0])}}}return{count:e.length,keys:r,kinds:n,numbers:Float64Array.from(a),views:Int32Array.from(i),shared:o}}function Re({count:e,keys:t,kinds:r,numbers:n,views:a,shared:i},l=null){let o=r.map(e=>"d"===e[0]?e.slice(1).split(":").map(Number):null),s=new Array(e),u=0,c=0;for(let f=0;f<e;f++){let e={};for(let l=0;l<t.length;l++){let s=r[l];if("n"===s)e[t[l]]=n[u++];else if("v"===s)e[t[l]]=i[a[c++]];else{let[r,a]=o[l],i=globalThis[Wi[a]],s=new Array(r);for(let e=0;e<r;e++)s[e]=i.of(n[u++]);e[t[l]]=s}}s[f]=l?l(e,f):e}return s}function Xe(e){let{coeffs:t}=e;if(e.packed)return e;if(!(t instanceof Int16Array))return null;let r=t.length/64,n=new Int16Array(r),a=new Uint32Array(64);for(let e=0,i=0;e<r;e++,i+=64){n[e]=t[i];for(let e=1;e<64;e++)t[i+e]&&a[e]++}let i={components:[{...e}]};return Je(i),{...i.components[0],packed:{...i.components[0].packed,dc:n,natural:a}}}function De(e){if(ArrayBuffer.isView(e))return null;try{return Qi.call(e)}catch{return null}}function Ce(e,t=!1){if("Uint8Array"!==tl.call(e)||null===De(el.buffer.call(e))||!t&&0===el.byteLength.call(e))throw fn("JXL_INPUT","encoded bytes: nonempty attached Uint8Array");return el.byteLength.call(e)}function Ge(e,t=!1){let r=Ce(e,t);try{return new Uint8Array(el.buffer.call(e),el.byteOffset.call(e),r)}catch{throw fn("JXL_INPUT","buffer: attached ArrayBuffer")}}function We(e,t){if(t===Uint8Array)return e;let r=t.BYTES_PER_ELEMENT,n=e.length/r,a=(e,t)=>void 0===e?t:(e=Math.trunc(e)||0)<0?Math.max(0,n+e):Math.min(n,e),i=(i,l)=>{i=a(i,0),l=Math.max(i,a(l,n));let o=e.subarray(i*r,l*r);return o.byteOffset%r&&(o=o.slice()),new t(o.buffer,o.byteOffset,o.byteLength/r)},l={length:n,byteLength:e.length,byteOffset:0,BYTES_PER_ELEMENT:r,constructor:t,subarray:i,then:void 0,ahead:"function"==typeof e.ahead?(t,n)=>e.ahead(t*r,n*r):void 0};return new Proxy(new t(0),{get:(e,r)=>Object.hasOwn(l,r)?l[r]:r===Symbol.toStringTag?t.name:"symbol"==typeof r&&Symbol.keyFor(r)?.startsWith("rapier-jxl.journal")?void 0:(e=>{let t=Reflect.get(e,r);return"function"==typeof t?t.bind(e):t})(i()),getPrototypeOf:()=>t.prototype})}function Ve(e,t){let r=e.length,n=new Uint16Array(16);for(let t=0;t<r;t++)n[e[t]]++;n[0]=0;let a=15;for(;a&&!n[a];)a--;for(let e=1,r=1;e<=15;e++)r=(r<<1)-n[e],r<0&&nl(),15===e&&r>0&&a&&(!t||1!==a)&&nl();let i=new Uint16Array(17),l=new Uint16Array(r);for(let e=1;e<=15;e++)i[e+1]=i[e]+n[e];let o=i.slice();for(let t=0;t<r;t++)e[t]&&(l[o[e[t]]++]=t);let s=new Uint32Array(1024);for(let e=1,t=0;e<=10;e++,t<<=1)for(let r=0;r<n[e];r++,t++){let n=0;for(let r=0;r<e;r++)n|=(t>>r&1)<<e-1-r;let a=l[i[e]+r]<<4|e;for(let t=n;t<=1023;t+=1<<e)s[t]=a}return{table:s,counts:n,symbols:l}}function Ke(e,t,r,n){let{pos:a,bits:i,count:l,final:o,type:s,left:u,lengths:c,hlit:f,copy:h,distance:d,a:m,b:p,produced:y}=e,g=n.read(a,Math.min(n.length,a+e.span)),M=0,b=()=>{let t=a;return!(t>=n.length)&&(g=n.read(t,Math.min(n.length,t+Math.max(65536,e.span))),M=0,g.length>0)},w=e=>{for(;l<e;)M>=g.length&&!b()&&nl(),i|=g[M++]<<l,a++,l+=8},L=e=>{w(e);let t=i&(1<<e)-1;return i>>>=e,l-=e,t},A=e=>{for(;l<15&&(!(M>=g.length)||b());)i|=g[M++]<<l,a++,l+=8;let t=e.table[1023&i],r=15&t;if(t&&r<=l)return i>>>=r,l-=r,t>>4;for(let t=1,r=0,n=0,a=0;t<=15;t++){r|=L(1);let i=e.counts[t];if(r-i<n)return e.symbols[a+r-n];a+=i,n+=i,n<<=1,r<<=1}return nl()},v=()=>{let e=L(5)+257,t=L(5)+1,r=L(4)+4;(e>286||t>30)&&nl();let n=new Uint8Array(19);for(let e=0;e<r;e++)n[dl[e]]=L(3);let a=Ve(n,!1),i=new Uint8Array(e+t);for(let e=0;e<i.length;){let t=A(a);if(t<16){i[e++]=t;continue}let r,n=0;16===t?(e||nl(),n=i[e-1],r=3+L(2)):r=17===t?3+L(3):11+L(7),e+r>i.length&&nl(),i.fill(n,e,e+r),e+=r}return i[256]||nl(),f=e,i},I=e.window,x=new Uint8Array(ol+t),N=ol-I.length,O=ol+t;x.set(I,N);let P=ol,U=1===s?pl():2===s?yl(c,f):null;for(;;){for(;h>0&&P<O;h--,P++)x[P]=x[P-d];if(h>0){r&&al();break}if(-1===s){if(o)break;if(o=L(1),s=L(2),0===s){i>>>=7&l,l-=7&l;let e=L(16);e!==(65535&~L(16))&&nl(),u=e}else 1===s?U=pl():2===s?(c=v(),U=yl(c,f)):nl();continue}if(0===s){if(!u){s=-1;continue}if(P>=O){r&&al();break}x[P++]=L(8),u--;continue}if(P>=O&&!r)break;let t=A(U.lit);if(t<256){P>=O&&al(),x[P++]=t;continue}if(256===t){s=-1;continue}t>285&&nl();let n=fl[t-257]+L(sl[t-257]),a=A(U.dist);a>29&&nl(),d=hl[a]+L(ul[a]),(d>P-N||d>(e.windowSize??ol))&&nl(),h=n}P<O&&rl("PNG data: incomplete");let S=x.subarray(ol,P);for(let e=0;e<S.length;){for(let t=Math.min(S.length,e+5552);e<t;e++)m+=S[e],p+=m;m%=65521,p%=65521}r&&(i>>>=7&l,l-=7&l,(16777216*L(8)+(L(8)<<16)+(L(8)<<8)+L(8)>>>0!=65536*p+m>>>0||l||a!==n.length)&&nl());let j=y+S.length,E=Math.min(ol,j);return{output:S,state:{pos:a,bits:i,count:l,final:o,type:s,left:u,lengths:c,hlit:f,copy:h,distance:d,a:m,b:p,produced:j,span:e.span,windowSize:e.windowSize,window:x.slice(P-E,P)}}}async function ze(e,t,r,n=!1,a=!1,i=!1,l=!1){let o,s=await e({unit:t,...n&&{carry:!0},...a&&{cold:!0},...i&&{alone:!0},...l&&{tail:!0}});if(s&&Object.hasOwn(s,Na))return{value:s[Na]};try{o=await r()}catch(r){throw await e({unitFailed:t}),r}return await e({unitDone:t,value:o}),{value:o}}async function He(e,t,r,{pngRows:n,pngPassRows:a,unfilterRow:i}){let{width:l,height:o,depth:s,channels:u}=t,c=a(t),f=Math.max(1,u*s>>3),h=c.reduce((e,t)=>e+Math.ceil(t[5]/il),0),d={pos:2,bits:0,count:0,final:0,type:-1,left:0,lengths:null,hlit:0,copy:0,distance:0,a:1,b:0,produced:0,span:Math.ceil(t.stream/h*1.25)+4096,windowSize:t.windowSize,window:new Uint8Array(0),previous:new Uint8Array(0)},m=[];for(let t=0;t<c.length;t++){let[,,,,,n,a]=c[t],l=[];for(let o=0;o<n;o+=il){let s,u=Math.min(il,n-o),h=()=>{let{output:e,state:l}=Ke(d,u*(a+1),t===c.length-1&&o+u===n,r),h=new Uint8Array(u*a),m=o?d.previous.slice():new Uint8Array(a),p=new Uint8Array(a);for(let t=0,r=0;t<u;t++){let n=e[r++];n>4&&rl("PNG row filter: 0-4"),i(n,e,r,p,m,a,f),r+=a,h.set(p,t*a),[m,p]=[p,m]}return s={...l,previous:m},h};l.push((await ze(e,"png-pass-rows",h,!1,!0,!0)).value);let{value:m}=await ze(e,"png-pass-inflate",()=>s??(h(),s),!0,!1,!1,!0);m!==Da&&(d=m)}m.push(ne(l,e.touched))}let p=16===s?Uint16Array:Uint8Array,y=p.BYTES_PER_ELEMENT,g=[];for(let r=0;r<o;r+=il){let a,i=Math.min(il,o-r),s=()=>{let e=new p(i*l*4),o=n(t,e,r);for(let e=0;e<c.length;e++){let[t,n,a,l,s,u,f]=c[e],h=Math.max(0,Math.ceil((r-n)/l)),d=Math.min(u,Math.ceil((r+i-n)/l));if(d<=h)continue;m[e].ahead(h*f,d*f);let p=m[e].subarray(h*f,d*f);for(let e=h;e<d;e++)o(p.subarray((e-h)*f,(e-h+1)*f),s,t,n,a,l,e)}a=[];for(let t=0;t<l;t+=ll){let r=Math.min(ll,l-t),n=new p(i*r*4);for(let a=0;a<i;a++)n.set(e.subarray(4*(a*l+t),4*(a*l+t+r)),a*r*4);a.push(new Uint8Array(n.buffer,n.byteOffset,n.byteLength))}return a},u=[];for(let t=0;t*ll<l;t++)u.push((await ze(e,"png-reference-rows",()=>(a??s())[t],!1,!0,!0,t>0)).value);g.push(u)}return{data:We(re(g,l*y,o,il,ll*y,e.touched),p),width:l,height:o,bitDepth:16===s?16:8,sampleFormat:"uint",...t.colour,alphaPremultiplied:!1,...t.orientation>1&&{orientation:t.orientation}}}function*Ye(e,t){return yield*z("icc-matches",function*(){let r=[],n=null,a=!1;for(;!a;){let i=yield*z("icc-match-part",function*(){let r=[];n=t.matches(e,(e,t,n)=>r.push(t||e,n),4,7,n,4096);let a=new Uint8Array(4*r.length),i=new DataView(a.buffer);return r.forEach((e,t)=>i.setUint32(4*t,e,!0)),{bytes:a,done:n.i===e.length}},void 0,!1,!0);r.push(i.bytes),a=i.done;let l=yield*K("icc-match-state",()=>null,()=>a?null:n,!0);null!==l&&l!==Da&&(n=l)}return Ba(r)})}function qe(e,t,r,n,a,i){for(;n.position<a;){let a=t.subarray(n.index,n.index+8),l=new DataView(a.buffer,a.byteOffset,a.byteLength),o=l.getUint32(0,!0),s=l.getUint32(4,!0),u=s?o:0,c=u||1,f=Math.min(c-n.within,e.length>65536?gl:c);r.match(e,i,n.position,u?0:o,u?f:0,s),n.position+=f,n.within+=f,n.within===c&&(n.index+=8,n.within=0)}}function*$e(e,t,r){let n=!!t;return yield*z(n?"icc-lz":"icc-prefix",function*(){let a=yield*z("icc-frequencies",function*(){let a={position:0,within:0,index:0,frequencies:new Uint32Array(n?320:256),...n&&{distances:new Uint32Array(64)}};for(let i=0;i<e.length;i+=gl){let l=Math.min(e.length,i+gl),o=yield*K("icc-count",()=>{if(n)qe(e,t,r,a,l,(e,t,n)=>r.symbol(null,a,e,t,n));else for(let t of e.subarray(i,l))a.frequencies[t]++;return a});a=bl(o,a)}return{frequencies:a.frequencies,distances:a.distances}}),i=yield*V("icc-code",()=>{let t=r.model(e.length,a.frequencies,a.distances);return{...t,writer:Ml(t.writer)}}),l=[],o={position:0,within:0,index:0},s=0,u=0,c=0;for(let a=0;a<e.length;a+=gl){let f=Math.min(e.length,a+gl),h=yield*z("icc-write-part",function*(){let l=new r.BitWriter(65536);a?(l.acc=s,l.pending=u):l.append(i.writer);let c=(e,t,n)=>r.symbol(l,i,e,t,n);if(n)qe(e,t,r,o,f,c);else for(let t of e.subarray(a,f))c(t,0,0);return Ml(l)},void 0,!1,!0);if(l.push(h.bytes),c+=h.at,s=h.acc,u=h.pending,n){let e=yield*K("icc-write-state",()=>null,()=>o,!0);null!==e&&e!==Da&&(o=e)}}return{bytes:Ba(l),at:c,acc:s,pending:u,bitLength:8*c+u}})}function Qe(e){if(ArrayBuffer.isView(e))return t=>e[t];let t=new Map;return r=>{let n=65536*Math.floor(r/65536),a=t.get(n);return a||(a=e.subarray(n,Math.min(e.length,n+65536)),t.set(n,a),t.size>8&&t.delete(t.keys().next().value)),a[r-n]}}function Ze(e,t){let r=new Map;return n=>{if(n<0)return;let a=0,i=e.length;for(;a<i;){let t=a+i>>>1;e[t].at<=n?a=t+1:i=t}let l=e[a];if(t(l&&l.from<=n),ArrayBuffer.isView(l.bytes))return l.bytes[n-l.from];let o=r.get(a);return o||(o=l.bytes.subarray(0,l.at-l.from),r.set(a,o),r.size>8&&r.delete(r.keys().next().value)),o[n-l.from]}}function et(e,t){let{history:r,...n}=t;Object.assign(e,n),e.finished=!1,r&&(e.begin(),e.history.set(r))}function*tt(e,t,r){return yield*z("decode-input",function*(){if(yield*V("decode-input-signature",()=>r.admitInput(e,t)))return{codestream:e,boxes:[],container:null};let n={at:12,count:0,rawMetadata:0};for(;n.at<e.length;){let a=yield*V("decode-storage",()=>{let a={...n},i=r.uint32View(ae(e,0)),l=null;for(let n=0;n<64&&a.at<e.length;n++)l=r.storageNext(e,t,a,i)||l;return{state:a,repair:l}});if(n=a.state,a.repair){let t=yield*V("decode-cut-header",()=>r.repairedHeader(e,a.repair));e=ne([ae(e,0,a.repair.at),t,ae(e,a.repair.at+t.length)])}}let a=r.cutEnd(n);if(void 0!==a.end&&(e=ae(e,0,a.end)),a.last){let t=yield*V("decode-cut-fragment",()=>r.repairedHeader(e,a.last));e=ne([ae(e,0,a.last.at),t,ae(e,a.last.at+t.length)])}let i=yield*V("decode-container",()=>r.readContainer(e,{maxBytes:t.maxInputBytes,maxBoxes:t.maxBoxes})),l=[],o=0;for(let e of i.auxiliary){let n=yield*z("decode-metadata",function*(){let n="brob"===e.boxType,a=e.boxType,i=e.data;return n&&(a=yield*V("decode-metadata-type",()=>r.fourCC(r.uint32View(i.subarray(0,4)).getUint32(0))),i=yield*r.part("brotli").decompressBrotliSteps(ae(i,4),{maxOutput:t.maxMetadataBytes-o,dictionary:t.dictionary})),yield*V("decode-metadata-size",()=>(r.requireDecode(o+i.length<=t.maxMetadataBytes,"JPEG XL metadata exceeds the byte limit."),null)),{type:a,data:i,compressed:n}});l.push(n),o+=n.data.length}return{codestream:i.codestream,boxes:l,container:{level:i.level,minorVersion:i.minorVersion}}})}function rt(e){return function*(t,r,n){return yield*z(e,function*(){let a=yield*V(e+"-header",()=>n.start(t,r?.maxBytes,Qe(t))),i=a.state,l=[{bytes:a.bytes,from:0,at:i.at}];for(;!i.done;){let r=yield*V(e+"-part",()=>{let e=i.at,r=n.part(t,i,Ze(l,n.require),Qe(t));return i=r.state,{bytes:r.bytes,from:e,at:i.at}});l.push(r);let a=yield*K(e+"-state",()=>null,()=>i,!0);null!==a&&a!==Da&&(i=a)}return Ba(l.map(e=>e.bytes))})}}function nt(e,t,r){return function*(n,a,i){let l=i.limits(n,a);return yield*z(t,function*(){let t=yield*V(e+"-window",()=>i.start(n)),a=[];for(;!t.last;){let o=yield*z(e+"-meta",function*(){let o=yield*V(e+"-header",()=>i.header(n,t,l)),s=o.state;if("end"===o.kind||"skip"===o.kind)return{parts:[],state:s};let u=null;"compressed"===o.kind&&(u=yield*z(e+"-models",function*(){let e=o.state.bit,t=[];for(let[a,l]of i.groups(o)){let o=[];t.push(o);for(let t=0;t<a;t+=16){let s=yield*V(r,()=>{let r=i.reader(n,e);return{trees:i.trees(r,Math.min(16,a-t),l),bit:r.bit}});o.push(...s.trees),e=s.bit}}return{trees:t,bit:e}})),u&&(s={...s,bit:u.bit});let c=[];for(;s.at<o.end;){let t=yield*V(e+"-output",()=>{let e=s.at,t=i.part(n,o,u,s,Ze([...a,...c],i.require),l.dictionary);return s=t.state,{bytes:t.bytes,from:e,at:s.at}});c.push(t);let r=yield*K(e+"-state",()=>null,()=>s,!0);null!==r&&r!==Da&&(s=r)}return{parts:c,state:i.metaEnd(s)}});a.push(...o.parts),t=o.state}return yield*V(e+"-end",()=>(i.end(n,t),null)),Ba(a.map(e=>e.bytes))})}}function at(e,t=e.data??e.frames?.[0]?.data){let r=tl.call(t),n=e.sampleFormat??("Float32Array"===r?"float32":"Float16Array"===r?"float16":"uint"),a=e.bitDepth??("float32"===n?32:"Uint16Array"===r||"float16"===n?16:8),i=e.colorEncoding?.transferFunction??e.transferFunction??("uint"===n?"srgb":"linear");return{sampleFormat:n,bitDepth:a,colorSpace:e.icc||e.colorEncoding?void 0:e.colorSpace??"srgb",transferFunction:e.icc||e.colorEncoding?void 0:i,intensityTarget:e.intensityTarget??("pq"===i?1e4:"hlg"===i?1e3:255),alphaPremultiplied:e.alphaPremultiplied??!1,orientation:e.orientation??1}}async function it({kind:e,width:t,height:r,colorSpace:n,sha256:a}){let i="sha256:"+a;if("file"===e||void 0===t)return{kind:"bytes",digest:i};let l=(new TextEncoder).encode(JSON.stringify(Ol({width:t,height:r,...at({...n&&{colorSpace:n}},new Uint8Array(0)),data:i})));return{kind:"pixels",digest:"sha256:"+(globalThis.crypto?.subtle?Pl(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",l))):I(v(qn(),l)))}}function lt(e,t="invalid data",r,n=!1){if(e)return;let a=Object.assign(new Error(t),{code:"JXL_DECODE"});throw r&&(a.bitOffset=r.bit),n&&(a[Ul]=!0),a}function ot(e,t){let r=0;for(let n=0;n<t;n++)r=r<<1|1&e,e>>=1;return r}function st(e){let t=new Uint32Array(17),r=new Uint32Array(17),n=new Uint16Array(e.length);for(let r of e)t[r]++;t[0]=0;for(let e=1,n=0;e<=16;e++)n=n+t[e-1]<<1,r[e]=n;for(let t=0;t<e.length;t++)e[t]&&(n[t]=ot(r[e[t]]++,e[t]));return n}function ut(e){let t=e.u64BigInt(),r=[];for(;t;)1n&t&&r.push(e.u64()),t>>=1n;for(let t of r)e.skip(t)}function ct(e){let t=e.u32([[0,0],[4,0],[5,16],[10,48]]),r=new Uint8Array(t);for(let n=0;n<t;n++)r[n]=e.read(8);try{return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{lt(!1,"name: UTF-8",e)}}function ft(e,t=!1){let r=Cl(e),n=t?r?[[0,16],[0,32],[5,1],[9,33]]:[[6,1],[8,65],[10,321],[12,1345]]:Bl,a=()=>t?e.u32(n)*(r?8:1):r?8*(1+e.read(5)):e.u32(n),i=a(),l=e.read(3);return{width:l?Math.floor(i*Rl[l][0]/Rl[l][1]):a(),height:i}}function ht(e){let t=Cl(e),r=e.u32(t?[[0,32],[0,16],[0,24],[6,1]]:[[0,8],[0,10],[0,12],[6,1]]),n=t?e.read(4)+1:0;return lt(r<=(t?32:31)&&(!t||n<=8&&r>n+1),"bit depth",e),{float:t,bits:r,exponentBits:n}}function dt(e){if(Cl(e))return{type:0,bitDepth:{...Xl},dimShift:0,name:"",associated:!1};let t=e.enum();lt(t<=6||15===t||16===t,"extra channel type",e);let r=ht(e),n=e.u32([[0,0],[0,3],[0,4],[3,1]]);lt(n<=3,"extra channel shift",e);let a={type:t,bitDepth:r,dimShift:n,name:ct(e),associated:!1};return 0===t&&(a.associated=Cl(e)),2===t&&(a.spotColor=Dl(4,()=>e.f16())),5===t&&(a.cfaChannel=e.u32([[0,1],[2,0],[4,3],[8,19]])),a}function mt(e){return Dl(2,()=>Sl(e.u32([[19,0],[19,524288],[20,1048576],[21,2097152]]))/1e6)}function pt(e){let t={space:"rgb",spaceId:0,wantICC:!1,whitePoint:"d65",whitePointId:1,primaries:"srgb",primariesId:1,transferFunction:"srgb",transferId:13,renderingIntent:1};return Cl(e)||(t.wantICC=Cl(e),t.spaceId=e.enum(),lt(t.spaceId<=3,"color space",e),t.space=["rgb","gray","xyb","unknown"][t.spaceId],t.wantICC)||(2!==t.spaceId&&(t.whitePointId=e.enum(),lt([1,2,10,11].includes(t.whitePointId),"white point",e),t.whitePoint=2===t.whitePointId?mt(e):{1:"d65",10:"e",11:"dci"}[t.whitePointId]),1!==t.spaceId&&2!==t.spaceId&&(t.primariesId=e.enum(),lt([1,2,9,11].includes(t.primariesId),"primaries",e),t.primaries=2===t.primariesId?Dl(3,()=>mt(e)):{1:"srgb",9:"rec2020",11:"display-p3"}[t.primariesId]),2===t.spaceId?(t.transferFunction="gamma",t.gamma=1/3,t.transferId=null):Cl(e)?(t.transferId=null,t.transferFunction="gamma",t.gamma=e.read(24)/1e7,lt(t.gamma>0,"gamma",e)):(t.transferId=e.enum(),t.transferFunction={1:"bt709",2:"unknown",8:"linear",13:"srgb",16:"pq",17:"dci",18:"hlg"}[t.transferId],lt(void 0!==t.transferFunction,"transfer function",e)),t.renderingIntent=e.enum(),lt(t.renderingIntent<=3,"rendering intent",e)),t}function yt(e,t){let r={intensityTarget:255,minNits:0,relativeToMaxDisplay:!1,linearBelow:0};return t&&!Cl(e)&&(r.intensityTarget=e.f16(),r.minNits=e.f16(),r.relativeToMaxDisplay=Cl(e),r.linearBelow=e.f16(),lt(r.intensityTarget>0&&r.minNits>=0&&r.minNits<=r.intensityTarget&&r.linearBelow>=0&&(!r.relativeToMaxDisplay||r.linearBelow<=1),"tone mapping",e)),r}function gt({width:e,height:t},r,n,a){let i=`${a} ${Gl(e)} x ${Gl(t)}`;if(e>n||t>n)throw Object.assign(new Error(`${i}: over maxDimension ${Gl(n)}`),{code:"JXL_DIMENSIONS"});if(e*t>r)throw Object.assign(new Error(`${i}: over maxPixels ${Gl(r)}`),{code:"JXL_DIMENSIONS"})}function Mt(e,t={}){e.expect(16,2815);let r={...ft(e),orientation:1,intrinsicSize:null,preview:null,animation:null},n=t.maxDimension??1073741824;lt(r.width>0&&r.height>0,"image size",e),gt(r,t.maxPixels??Gr,n,"picture");let a=Cl(e),i=!a&&Cl(e);i&&(r.orientation=e.read(3)+1,Cl(e)&&(r.intrinsicSize=ft(e)),Cl(e)&&(r.preview=ft(e,!0)),Cl(e)&&(r.animation={numerator:e.u32([[0,100],[0,1e3],[10,1],[30,1]]),denominator:e.u32([[0,1],[0,1001],[8,1],[10,1]]),loops:e.u32([[0,0],[3,0],[16,0],[32,0]]),timecodes:Cl(e)})),r.bitDepth=a?{...Xl}:ht(e),r.modular16=a||Cl(e);let l=a?0:e.u32([[0,0],[0,1],[4,2],[12,1]]);lt(l<=256,"extra channels: max 256",e),r.extraChannels=Dl(l,()=>dt(e)),r.xyb=a||Cl(e);let o=e.bit;if(r.colorEncoding=a?{space:"rgb",spaceId:0,wantICC:!1,whitePoint:"d65",whitePointId:1,primaries:"srgb",primariesId:1,transferFunction:"srgb",transferId:13,renderingIntent:1}:pt(e),r.colorBits=a?null:[o,e.bit],r.colorChannels=1===r.colorEncoding.spaceId?1:3,r.toneMapping=yt(e,i),a||ut(e),r.opsinInverseMatrix={inverseMatrix:[...El.inverseMatrix],opsinBiases:[...El.opsinBiases],quantBias:El.quantizationBiases.slice(0,3),quantBiasNumerator:El.quantizationBiases[3]},r.upsamplingWeights={},!Cl(e)){r.xyb&&!Cl(e)&&(r.opsinInverseMatrix={inverseMatrix:Dl(9,()=>e.f16()),opsinBiases:Dl(3,()=>e.f16()),quantBias:Dl(3,()=>e.f16()),quantBiasNumerator:e.f16()});let t=e.read(3);for(let[n,a,i]of[[1,2,15],[2,4,55],[4,8,210]])t&n&&(r.upsamplingWeights[a]=Dl(i,()=>e.f16()))}return r.iccBitOffset=e.bit,r}function bt(e,t={}){let r=t.maxInputBytes??Number.MAX_SAFE_INTEGER,n=t.maxBoxes??Number.MAX_SAFE_INTEGER;if(!Number.isSafeInteger(r)||r<1)throw fn("JXL_OPTIONS","maxInputBytes: positive safe integer");if(!Number.isSafeInteger(n)||n<1)throw fn("JXL_OPTIONS","maxBoxes: positive safe integer");for(let e of["maxPixels","maxDimension","maxMetadataBytes"])if(void 0!==t[e]&&!(Number.isSafeInteger(t[e])&&t[e]>0))throw fn("JXL_OPTIONS",`${e}: positive safe integer`);if(e.byteLength>r)throw fn("JXL_LIMIT","maxInputBytes: exceeded");let{maxInputBytes:a,maxBoxes:i,complete:l=!1,...o}=t,s=At(e,n,l),u=xt(s,e=>Mt(new jl(e,!0),{maxPixels:1/0,maxDimension:o.maxDimension,...void 0!==o.maxPixels&&{maxPixels:o.maxPixels}}));return u.reconstruction=s.reconstruction,u}function wt(e){try{return xt(At(e),e=>{let t=new jl(e,!0),r=Mt(t,{maxPixels:1/0});return r.colorEncoding.wantICC||r.preview?null:(t.align(),!t.read(1)&&(t.read(3),0n!=(1n&t.u64BigInt())))})}catch(e){if(Wl.has(e?.code))return null;throw e}}function*Lt(e,t={}){return globalThis[_a]&&!globalThis[_a].plain?yield*Ra("boundedHeader")(e,t,{header:bt}):Vl(e,t)}function At(e,t=Number.MAX_SAFE_INTEGER,r=!1){let n=e.subarray(0,Math.min(e.length,12));if(255===n[0]&&10===n[1]){let t=t=>e.subarray(0,Math.min(t,e.length));return{codestream:t(Hl),window:t,total:e.length,reconstruction:!1}}if(n.length<12||!Tl.every((e,t)=>n[t]===e))throw Yl("signature");let a=new Map,i=0,l=0,o=!1,s=null,u=0,c=-1,f=-1,h=0,d=0,m=!1,p=!1;for(let n=12;n<e.length&&!p;){if(i>=t)throw Yl("maxBoxes: exceeded","simplify file or raise maxBoxes");if(e.length-n<8){p=!0;break}let y=e.subarray(n,Math.min(e.length,n+28)),g=ql(y,0),M=ql(y,4),b=1===g?16:8;if(y.length<b){p=!0;break}let w=1===g?4294967296*ql(y,8)+ql(y,12):g||e.length-n;if(!Number.isSafeInteger(w)||w<b)throw Yl("box size");p=w>e.length-n;let L=n+b,A=p?e.length:n+w,v=A-L;if(i){if(M===Fl||1247300640===M)throw Yl("file header: duplicate")}else{if(M!==Fl)throw Yl("second box: jxl file type");if(v<8){if(p&&!r)break;throw Yl("second box: jxl file type")}if((!p||r)&&(v<12||v%4)||ql(y,b)!==kl)throw Yl("second box: jxl file type");if(l=ql(y,b+4),l>1)throw Yl("minorVersion: 0 or 1");let t=!1;for(let r=L+8;r<A&&!t;r+=Hl){let n=e.subarray(r,Math.min(A,r+Hl));for(let e=0;e+4<=n.length;e+=4)t||=ql(n,e)===kl}if(!t&&(!p||r))throw Yl("file type: jxl brand required")}let I=M;if(1786276972===M){if(1!==i||o||v>1||(!p||r)&&1!==v||1===v&&5!==y[b]&&10!==y[b])throw Yl("level box: 5 or 10 after file type");o=!0}else if(1786276963===M){if(s||u)throw Yl("codestream boxes: duplicate or mixed");s=[L,A]}else if(1786276976===M){if(s||(!p||r)&&v<4)throw Yl("codestream fragment");if(v>=4){let e=ql(y,b),t=2147483647&e,r=e>=2147483648;if(a.has(t)||0===l&&t!==u)throw Yl("fragment v0: duplicate or unordered");if(r){if(c>=0)throw Yl("final fragment: duplicate");c=t}if(f=Math.max(f,t),c>=0&&f>c)throw Yl("codestream: incomplete");a.set(t,[L+4,A]),u++}}else if(M===Jl){if((!p||r)&&v<4)throw Yl("compressed box: incomplete");if(v>=4&&(I=ql(y,b),I===Jl||I===_l||I>>>8==6977644))throw Yl("Brotli box: not codestream/index/reconstruction/Brotli")}if(I===Kl&&++h>1||I===zl&&++d>1)throw Yl("frame index/gain map: max 1 each");M===_l&&(m=!0),i++,n=A}if(r&&(p||u&&(c<0||u!==c+1))||!s&&!a.has(0))throw Yl("codestream: incomplete");let y=s?[s]:[];for(let e=0;!s&&a.has(e);e++)y.push(a.get(e));let g=y.reduce((e,[t,r])=>e+r-t,0),M=t=>It(e,y,Math.min(t,g));return vt({codestream:M(Hl),window:M,total:g,reconstruction:m},r)}function vt(e,t){let{codestream:r}=e;if((t||r.length>=2)&&(r.length<2||255!==r[0]||10!==r[1]))throw Yl("logical codestream signature");return e}function It(e,t,r){if(1===t.length)return e.subarray(t[0][0],t[0][0]+r);let n=new Uint8Array(r);for(let a=0,i=0;i<r;i+=t[a][1]-t[a][0],a++)n.set(e.subarray(t[a][0],Math.min(t[a][1],t[a][0]+r-i)),i);return n}function xt(e,t){for(let r=Hl,n=e.codestream;;n=e.window(r*=4))try{return t(n)}catch(t){if(n.length===e.total||"JXL_DECODE"!==t?.code)throw t}}function Nt(e){if(!e||"object"!=typeof e||Array.isArray(e))return e;let{transferFunction:t,primaries:r,...n}=e;("gamma"!==t||void 0===e.gamma)&&(n.transferFunction=t),("gray"!==e.space||"srgb"!==r)&&(n.primaries=r),Number.isInteger(e.renderingIntent)&&$l[e.renderingIntent]&&(n.renderingIntent=$l[e.renderingIntent]),"d50"===e.whitePoint&&(n.whitePoint=[.345669,.358496]);for(let e of Object.keys(n))void 0===n[e]&&delete n[e];return n}function Ot(e){let t={...Ql[e.format]};if(e.rgbaICC)return t;let r=e.rgbaColorEncoding??{},n=void 0===r.whitePoint||"d65"===r.whitePoint,a="gray"===r.space?"srgb":r.primaries;return Zl.includes(a)&&n&&(t.colorSpace=a),eo.includes(r.transferFunction)&&(t.transferFunction=r.transferFunction),t}function Pt(e){if(!Object.hasOwn(Ql,e.format))throw fn("JXL_INPUT","decoded format: uint8, uint16, float32");let t=Ot(e),r=e.header,n=r?.toneMapping?.intensityTarget;"number"==typeof n&&(t.intensityTarget=n);for(let r of ro)if(void 0!==e[r]&&e[r]!==t[r])throw fn("JXL_INPUT",`${r}: ${String(e[r])} vs ${String(t[r]??"unnamed")}, use {data, width, height, ${r}}`);let a=e.frames?.[0],i=a&&["icc","colorEncoding","alphaPremultiplied"].find(t=>!no(e[t]??null,a[t]??null))||r&&e.orientation!==r.orientation&&"orientation";if(i)throw fn("JXL_INPUT",`${i}: file-owned, use {data, width, height, ${i}}`);let l=e.rgbaColorEncoding;if(e.rgbaICC)t.icc=e.rgbaICC;else if(void 0===t.colorSpace||void 0===t.transferFunction||"rgb"!==l?.space||1!==(l.renderingIntent??1)){if(!["rgb","gray"].includes(l?.space)||["unknown","icc"].includes(l.transferFunction))throw fn("JXL_INPUT","colorSpace: srgb, display-p3 or rec2020");delete t.colorSpace,delete t.transferFunction,t.colorEncoding=Nt(l)}if(e.alphaPremultiplied&&(t.alphaPremultiplied=!0),!e.orientationApplied&&e.orientation>1&&(t.orientation=e.orientation),null!=e.extraChannels&&!Array.isArray(e.extraChannels))throw fn("JXL_INPUT","extraChannels: array");if((e.extraChannels??[]).filter(e=>0!==e?.type).length)throw fn("JXL_UNSUPPORTED","extraChannels: use format({kind: 'channels'}) or pixels");return t}function Ut(e){let t=Pt(e);if(e.animation){if(!Array.isArray(e.frames))throw fn("JXL_INPUT","frames: array");for(let t of e.frames)if(!t||"object"!=typeof t||!ArrayBuffer.isView(t.data)||t.data instanceof DataView||!Number.isFinite(t.durationSeconds)||t.durationSeconds<0)throw fn("JXL_INPUT","frame: data, durationSeconds >=0");return{width:e.width,height:e.height,loops:e.animation.loops,...t,frames:e.frames.map(e=>({data:e.data,duration:1e3*e.durationSeconds}))}}return{data:e.data,width:e.width,height:e.height,...t}}async function St(e,t,r,n){let a=!!so(r)?.decode,{[Vn]:i,...o}=r;try{return await e(t,o,n)}catch(e){throw a?l(e):e}}function jt(e,t){let r=e.colorEncoding,n=e.extraChannels;return t.region?"Banded verification":e.animation?"Verifying an animation":e.bitDepth.float||8!==e.bitDepth.bits?"Verifying a file of more than 8 bits or float samples":!r.wantICC&&["rgb","gray"].includes(r.space)&&"d65"===r.whitePoint&&["srgb","display-p3"].includes(r.primaries)&&"srgb"===r.transferFunction&&255===e.toneMapping?.intensityTarget?1!==e.orientation||n.length>1||n.some(e=>0!==e.type||e.associated||e.bitDepth.float||8!==e.bitDepth.bits||e.dimShift)?"Verifying a file with orientation or extra channels":"original"!==(t.colorSpace??"original")||t.unpremultiplyAlpha?"Verifying in another color space":null:"Verifying a file whose color is not sRGB or Display P3"}function Et(e,t,r){let{primaries:n,renderingIntent:a}=e.colorEncoding,i={space:"rgb",whitePoint:"d65",primaries:n,transferFunction:"srgb",renderingIntent:a};return{width:t.width,height:t.height,data:new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.length),format:"uint8",planes:[],extraChannels:e.extraChannels.map(e=>({...e})),colorEncoding:i,icc:null,rgbaColorEncoding:i,rgbaICC:null,duration:0,durationSeconds:0,alphaPremultiplied:!1,orientation:1,orientationApplied:!1,animation:null,bitDepth:8,sampleFormat:"uint",colorSpace:n,transferFunction:"srgb",header:e,..."opaque"===r&&{colorScope:"opaque"}}}async function Tt(e,t,r=!1){if(jt(e,t)||!await n())return!1;let a=await i(),l=r?a.bitmap:a;return!("display-p3"===e.colorEncoding.primaries&&!l.displayP3)&&(!e.extraChannels.length||!so(t)?.decode&&(l.alpha||"opaque"))}function Ft(e,t){if(u(t.signal),so(t)?.decode&&e&&"object"==typeof e&&!Array.isArray(e)&&(e=f(e,"Decoder result")),!to(e))throw fn("JXL_PLATFORM","decoder output: use jpegxl/decode");return e}async function kt(e,t){let r=uo("decode",t)?.[co];return r?Ft(await St(r,e.slice(),t),t):null}function Jt(e,t){let r=go(t)?.open;if(!r)throw oo("bounded verify");return r(e,t)}async function _t(e,t){let r=uo("decode",t);if(!r)throw oo("jxl verify");return Ft(await St(r,e.slice(),t),t)}async function Bt(e,t,r,n=!1){let a=go(t)?.[n?"withoutNoise":"region"];if(!a)throw oo("bounded verify");let{maxTotalSamples:i,...l}=t;return Ft(await St(a,e,l,r),t)}function Rt(e,t,r){if(void 0!==r&&!["rgb","gray","cmyk"].includes(r))throw Vr("JXL_INPUT","expectedColorSpace: rgb, gray or cmyk");if(!(e instanceof Uint8Array)||e.length<132)throw Vr("JXL_INPUT","icc: Uint8Array");if(5===t&&e.length>4194304)throw Vr("JXL_SIZE","level 5 icc: max 4 MiB");let n=e.subarray(0,132),a=new DataView(n.buffer,n.byteOffset,n.byteLength),i=e=>String.fromCharCode(n[e],n[e+1],n[e+2],n[e+3]);if(a.getUint32(0)!==e.length||"acsp"!==i(36))throw Vr("JXL_INPUT","icc header");let l=i(16),o=i(20);if(!["RGB ","XYZ ","Lab ","Luv ","YCbr","Yxy ","HSV ","HLS ","CMY ","3CLR","GRAY"].includes(l)&&("CMYK"!==l||"cmyk"!==r))throw Vr("JXL_INPUT","icc space: RGB, GRAY or planar CMYK");if(void 0!==r&&l!=={rgb:"RGB ",gray:"GRAY",cmyk:"CMYK"}[r])throw Vr("JXL_INPUT","icc space: channel mismatch");if("CMYK"===l&&5===t)throw Vr("JXL_INPUT","CMYK: needs level 10");if("XYZ "!==o&&"Lab "!==o)throw Vr("JXL_INPUT","icc PCS: XYZ or Lab");let s=a.getUint32(128);if(s>Math.floor((e.length-132)/12))throw Vr("JXL_INPUT","icc tag table: truncated");return{count:s,end:132+12*s,channels:"GRAY"===l?1:3}}function Xt(e,t,r,n){let a=e.subarray(132+12*r,132+12*n),i=new DataView(a.buffer,a.byteOffset,a.byteLength);for(let a=0;a<n-r;a++){let r=12*a,n=i.getUint32(r+4),l=i.getUint32(r+8);if(n<t.end||n%4||l<8||n>e.length||l>e.length-n)throw Vr("JXL_INPUT","icc tag extent")}}function Dt(e,t,r){let n=Rt(e,t,r);for(let t=0;t<n.count;t+=4096)Xt(e,n,t,Math.min(n.count,t+4096));return n.channels}function Ct(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw Vr("JXL_INPUT",t+": object")}function Gt(e,t,r){if("rendering intent"===r&&Number.isInteger(e)&&(e=Object.keys(t)[e]),"string"!=typeof e||!Object.hasOwn(t,e))throw Vr("JXL_INPUT","unsupported "+r+": "+e);return t[e]}function Wt(e){if(!Array.isArray(e)||2!==e.length)throw Vr("JXL_INPUT","chromaticity: [x, y]");let t=e.map(e=>{if("number"!=typeof e||!Number.isFinite(e))throw Vr("JXL_INPUT","chromaticity: finite numbers");let t=Math.round(1e6*e);if(t<-2097152||t>2097151)throw Vr("JXL_INPUT","chromaticity: signed 22-bit millionths");return t});if(!t[1])throw Vr("JXL_INPUT","chromaticity.y: nonzero millionths");return t}function Vt(e,t){for(let r of t)e.writeU32(vo,L(r))}function Kt(e={},t={}){Ct(e,"colorEncoding");let r=e.space??"rgb";if("unknown"===r)throw Vr("JXL_INPUT","color encoding: ICC for unknown");if("xyb"===r){if(["whitePoint","primaries","transferFunction","gamma"].some(t=>void 0!==e[t]))throw Vr("JXL_INPUT","XYB: omit whitePoint/primaries/transferFunction/gamma");let t=Gt(e.renderingIntent??"perceptual",Oo,"rendering intent"),r=new Cn(16);return r.write(2,0),r.writeU32(Ao,2),r.writeU32(Ao,t),{colorData:r,colorChannels:3,transferFunction:void 0}}if("rgb"!==r&&"gray"!==r)throw Vr("JXL_INPUT","colorEncoding.space: rgb/gray/xyb or ICC");let n="gray"===r?1:3,a=e.whitePoint??"d65",i=Array.isArray(a)?Wt(a):null,l=i?2:Gt(a,Io,"white point"),o=e.primaries??t.colorSpace??"srgb",s=null,u=1;if(1===n&&void 0!==e.primaries)throw Vr("JXL_INPUT","gray: omit primaries");if(3===n)if(Array.isArray(o)){if(3!==o.length)throw Vr("JXL_INPUT","primaries: 3 [x, y] pairs");s=o.map(Wt);let[e,t,r]=s;if((e[0]-r[0])*(t[1]-r[1])===(t[0]-r[0])*(e[1]-r[1]))throw Vr("JXL_INPUT","primaries: nonzero color triangle");u=2}else u=Gt(o,xo,"RGB primaries");let c=void 0!==e.gamma;if(c&&void 0!==e.transferFunction)throw Vr("JXL_INPUT","gamma/transferFunction: choose one");let f=0,h=13,d=e.transferFunction??t.transferFunction??"srgb";if(c){if("number"!=typeof e.gamma||!Number.isFinite(e.gamma)||e.gamma<1/8192||e.gamma>1)throw Vr("JXL_INPUT","gamma: 1/8192-1");if(f=Math.round(1e7*e.gamma),8192*f<1e7)throw Vr("JXL_INPUT","gamma: too small after rounding")}else h=Gt(d,No,"transfer function");let m=Gt(e.renderingIntent??"relative",Oo,"rendering intent"),p=new Cn(64);if(p.write(2,0),p.writeU32(Ao,3===n?0:1),p.writeU32(Ao,l),i&&Vt(p,i),3===n&&(p.writeU32(Ao,u),s))for(let e of s)Vt(p,e);return p.write(1,c?1:0),c?p.write(24,f):p.writeU32(Ao,h),p.writeU32(Ao,m),{colorData:p,colorChannels:n,transferFunction:c?void 0:d}}function zt(e,t,r,n){let a=73===e[t]&&73===e[t+1];if(!a&&(77!==e[t]||77!==e[t+1]))return null;let i=new DataView(e.buffer,e.byteOffset,e.byteLength),l=e=>e+2>r?0:i.getUint16(e,a),o=e=>e+4>r?0:i.getUint32(e,a);if(42!==l(t+2)||o(t+4)<8)return null;let s=t+o(t+4),u=l(s);for(let e=0,t=s+2;e<u&&t+12<=r;e++,t+=12){let e=l(t+8);if(274===l(t)&&3===l(t+2)&&1===o(t+4)&&e>=1&&e<=8)return n?.(t+8,!a),e}return null}function Ht(e,t,r=!0){for(let[r,n]of Object.entries(Ko))if(n.every((r,n)=>Math.abs(r-e[n])<=t))return r;r&&Wo("primaries: srgb|display-p3|rec2020, D65")}async function Yt(e,t,r){let n=!1;try{n="function"==typeof DecompressionStream}catch{}if(!n)throw Vr("JXL_PLATFORM","DecompressionStream: required; use pixels {data,width,height} or Node.js runtime");let a=1032*e.reduce((e,t)=>e+t.length,0),i=void 0===t,l=i?"ICC profile: incomplete":"source data: incomplete";!i&&t>a&&Wo(l);let o=new Uint8Array(i?4:Math.min(t,65536)),s=new ReadableStream({start(t){for(let r of e)t.enqueue(r);t.close()}}).pipeThrough(new DecompressionStream("deflate")).getReader(),u=0;try{for(;;){let{value:e,done:n}=await s.read();if(n)break;let c=e;if(i&&void 0===t){let e=Math.min(4-u,c.length);if(o.set(c.subarray(0,e),u),u+=e,c=c.subarray(e),u<4)continue;if((t=Vo(o).getUint32(0))<132&&Wo(l),void 0!==r&&t>r)throw Vr("JXL_LIMIT","maxMetadataBytes: increase or smaller input");t>a&&Wo(l)}if(u+c.length>t&&Wo(i?"ICC profile: exceeds declared size":"source data: exceeds declared dimensions"),u+c.length>o.length){let e=new Uint8Array(Math.min(t,Math.max(u+c.length,4*o.length)));e.set(o.subarray(0,u)),o=e}o.set(c,u),u+=c.length}return(void 0===t||u!==t)&&Wo(l),o}catch(e){if(await s.cancel().catch(()=>{}),String(e?.code).startsWith("JXL_")||Yr(e))throw e;Wo("deflate stream: malformed")}finally{s.releaseLock()}}function qt(e,t=0){let r=0;t=~t;let n=Ho,a=e.length-7;for(;r<a;r+=8){let a=(t^(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24))>>>0;t=n[1792+(255&a)]^n[1536+(a>>>8&255)]^n[1280+(a>>>16&255)]^n[1024+(a>>>24)]^n[768+e[r+4]]^n[512+e[r+5]]^n[256+e[r+6]]^n[e[r+7]]}for(;r<e.length;r++)t=t>>>8^n[255&(t^e[r])];return~t>>>0}function $t(e,t){let r={space:e,...t};return Kt(r),{colorEncoding:r}}function Qt(e,t){let r=0===t||4===t?"gray":"rgb",n=e.get("cICP");if(n){let e={1:"srgb",9:"rec2020",11:"display-p3",12:"display-p3"}[n[0]],t={1:"bt709",8:"linear",13:"srgb",16:"pq",17:"dci",18:"hlg"}[n[1]];return(!e||!t||0!==n[2]||1!==n[3])&&Wo("cICP: RGB primaries/transfer, full range, identity"),11===n[0]||"bt709"===t||"dci"===t?$t(r,{whitePoint:11===n[0]?"dci":"d65",..."rgb"===r?{primaries:e}:{},transferFunction:t}):{colorSpace:e,transferFunction:t}}let a=e.get("iCCP");if(a){let e=a.indexOf(0),t=a.subarray(0,e);return(e<1||e>79||e+2>=a.length||0!==a[e+1]||32===t[0]||32===t[t.length-1]||t.some((e,r)=>e<32||e>126&&e<161||32===e&&32===t[r-1]))&&Wo("iCCP: name, method 0, complete deflate"),{packed:a.subarray(e+2)}}let i=e.get("sRGB");if(i)return 1!==i[0]?$t(r,{transferFunction:"srgb",renderingIntent:["perceptual","relative","saturation","absolute"][i[0]]}):{colorSpace:"srgb",transferFunction:"srgb"};let l,o=e.get("gAMA"),s=e.get("cHRM"),u=o?Vo(o).getUint32(0)/1e5:void 0,c="srgb",f="d65";if(s){let e=Vo(s),t=Array.from({length:8},(t,r)=>e.getUint32(4*r)/1e5);c=Ht([...t.slice(2),...t.slice(0,2)],51e-7,!1),c||(f=t.slice(0,2),l=[t.slice(2,4),t.slice(4,6),t.slice(6,8)])}return!c||void 0!==u&&1!==u?$t(r,{whitePoint:f,..."rgb"===r?{primaries:c??l}:{},...void 0===u?{transferFunction:"srgb"}:{gamma:u}}):{colorSpace:c,transferFunction:o?"linear":"srgb"}}function Zt(t,r,n,a,i){let l=Vo(r),o=n+r.length,{offset:s=8,crcAt:u=0,crc:c=0,length:f=0,seen:h=0,ended:d=!1,chunks:m=new Map,parts:p=[],exifAt:y}=t??{},g=(e,t=0,r=!1)=>({offset:s,crcAt:u,crc:c,length:f,seen:h,ended:d,chunks:m,parts:p,exifAt:y,next:e,least:t,done:r});for(;;){if(d||s+12>a)return g(s,0,!0);if(s+8>o)return g(s);let t=s<n;t||(f=l.getUint32(s-n));let M=s+12+f;(f>2147483647||M>a)&&Wo("PNG chunk: incomplete");let b=t?[]:r.subarray(s+4-n,s+8-n),w=t?"IDAT":String.fromCharCode(...b);(!/^[A-Za-z]{4}$/.test(w)||32&b[2])&&Wo("PNG chunk name: four letters"),u<s+4&&(u=s+4,c=0);let L=Math.min(M-4,o);if(c=qt(r.subarray(u-n,L-n),c),u=L,M>o)return"IDAT"===w?g(L):(u=0,g(s,M-s));c!==l.getUint32(M-4-n)&&Wo("PNG chunk: checksum mismatch");let A="IDAT"===w?null:r.slice(s+8-n,M-4-n);8===s&&"IHDR"!==w&&Wo("PNG: IHDR first"),1===h&&"IDAT"!==w&&(h=2);let v="IHDR"===w?A:m.get("IHDR"),I=v?.[8],x=v?.[9];if("IHDR"===w){(m.has(w)||13!==f)&&Wo("IHDR: exactly one complete"),e(Vo(A).getUint32(0),Vo(A).getUint32(4),i);let t=Yo[x];(!(16===I?t&&3!==x:8===I?t:!(1!==I&&2!==I&&4!==I||0!==x&&3!==x))||A[10]||A[11]||A[12]>1)&&Wo("depth: gray 1|2|4|8|16, RGB(A) 8|16, palette <=8"),m.set(w,A)}else if("IDAT"===w)2===h&&Wo("IDAT: consecutive"),h=1,p.push([s+8,f]);else if("IEND"===w)(f||!h||M!==a)&&Wo("IEND: final empty after IDAT"),d=!0;else if("eXIf"===w)!h&&!m.has(w)&&(m.set(w,A),y=s+8);else{if("acTL"===w||"fcTL"===w||"fdAT"===w)throw Vr("JXL_UNSUPPORTED","animated PNG: use jpegxl/animation");if(["cICP","sRGB","iCCP","gAMA","cHRM","tRNS","sBIT","PLTE","mDCV","cLLI"].includes(w)){(h||m.has(w))&&Wo("PNG color/transparency: once before IDAT");let e={cICP:4,sRGB:1,gAMA:4,cHRM:32,mDCV:24,cLLI:8};void 0!==e[w]&&f!==e[w]&&Wo("PNG color chunk: invalid length"),"sRGB"===w&&A[0]>3&&Wo("sRGB intent: 0-3"),"sBIT"===w&&(f!=={0:1,2:3,3:3,4:2,6:4}[x]||A.some(e=>e<1||e>(3===x?8:I)))&&Wo("sBIT: invalid channel depths"),"tRNS"===w&&!(0===x&&2===f||2===x&&6===f||3===x&&f>=1&&f<=(m.get("PLTE")?.length??0)/3)&&Wo("tRNS: channel/palette mismatch"),"PLTE"===w&&(0===x||4===x||!f||f>768||f%3||3===x&&f/3>1<<I)&&Wo("PLTE: invalid for channel layout"),m.set(w,A)}else 32&b[0]||Wo("PNG critical chunk: unknown")}s=M}}async function er(e,t){let r=Qt(e,t);if(!r.packed)return r;let n=0===t||4===t?"gray":"rgb",a=await Yt([r.packed]);return Dt(a,void 0,n)!==("gray"===n?1:3)&&qo("PNG: ICC channel mismatch"),{icc:a}}function tr(e,t,r,n,a,i,l){Ro(n,i,a,t,r,e,l)}async function rr(){if(!await Fo()||!Eo())throw Tn()}function nr({chunks:e,exifAt:t}){let r,n,a=$o(e.get("IHDR")),i=e.get("eXIf"),l=i?zt(i,0,i.length,(e,a)=>{r=t+e,n=a}):null;return{width:a.getUint32(0),height:a.getUint32(4),orientation:l??1,orientationAt:r,orientationBig:n,...void 0!==r&&{exifAt:t,exifLength:i.length}}}async function ar({chunks:e,parts:t,ended:r},n){r||qo("PNG: truncated");let a=e.get("IHDR"),i=$o(a).getUint32(0),l=$o(a).getUint32(4),o=a[8],s=a[9],u=Yo[s],c=a[12],f=e.get("PLTE");3===s&&!f&&qo("palette PNG: missing PLTE");let h=await er(e,s);if(n&&h.colorEncoding&&ki(h)[0]===h)throw Vr("JXL_UNSUPPORTED","PNG color chunks: use encode");let d=c?Qo:[[0,0,1,1]],m=u*o,p=0;for(let[e,t,r,n]of d){let a=Math.max(0,Math.ceil((i-e)/r)),o=Math.max(0,Math.ceil((l-t)/n));a&&o&&(p+=o*(1+Math.ceil(a*m/8)))}let y=e.get("tRNS"),g=y&&3!==s?Array.from({length:y.length/2},(e,t)=>$o(y).getUint16(2*t)):null,M=e.get("eXIf"),b=M?zt(M,0,M.length):null;return{width:i,height:l,depth:o,colourType:s,channels:u,interlace:c,expected:p,palette:f??null,paletteAlpha:3===s?y??null:null,transparent:g,colour:h,orientation:b,parts:t}}function ir({width:e,depth:t,colourType:r,channels:n,palette:a,paletteAlpha:i,transparent:l},o,s=0){let u=16===t,c=u?65535:255,f=a?a.length/3:0,h=u||8===t?1:255/((1<<t)-1),d=!u&&8===t&&3!==r&&!l;return(m,p,y,g,M,b,w)=>{if(d&&1===M){let t=(g+w*b-s)*e*4;return void(4===n?o.set(m.subarray(0,4*p),t):Ro(m,p*n,null,null,0,0,0,o,t,p,n))}let L=$o(m),A=u?e=>L.getUint16(2*e):8===t?e=>m[e]:e=>m[e*t>>3]>>8-t-(e*t&7)&(1<<t)-1;for(let t=0;t<p;t++){let u=4*((g+w*b-s)*e+y+t*M);if(3===r){let e=A(t);e>=f&&qo("palette index: out of range"),o[u]=a[3*e],o[u+1]=a[3*e+1],o[u+2]=a[3*e+2],o[u+3]=e<(i?.length??0)?i[e]:255;continue}let d=A(t*n),m=n<3?d:A(t*n+1),p=n<3?d:A(t*n+2);o[u]=d*h,o[u+1]=m*h,o[u+2]=p*h,o[u+3]=4===r||6===r?A(t*n+n-1):l&&d===l[0]&&(0===r||m===l[1]&&p===l[2])?0:c}}}function lr({width:e,height:t,depth:r,channels:n,interlace:a}){let i=n*r;return(a?Qo:[[0,0,1,1]]).map(([r,n,a,l])=>{let o=Math.max(0,Math.ceil((e-r)/a));return[r,n,a,l,o,Math.max(0,Math.ceil((t-n)/l)),Math.ceil(o*i/8)]}).filter(e=>e[4]&&e[5])}function or(e,t=!1){if("exact"===e)return!0;if(!e||"object"!=typeof e||Array.isArray(e))return!1;let r=Object.keys(e);if(1!==r.length)return!1;let n=r[0],a=e[n];return"quality"===n?!!ns(a)||!!(t&&a&&"object"==typeof a&&!Array.isArray(a)&&2===Object.keys(a).length&&Object.hasOwn(a,"min")&&Object.hasOwn(a,"max")&&ns(a.min)&&ns(a.max)&&a.min<=a.max):"maxError"===n?rs(a)&&a>=0:"ssimulacra2"===n&&rs(a)&&a<=100}function sr(e){if("predicted"===e?.domain)return"ssimulacra2"===e.metric&&Number.isFinite(e.floor)&&void 0===e.score&&void 0===e.limit&&void 0===e.region&&(void 0===e.view||"pu21"===e.view||"without-noise"===e.view);if(!(e&&["ssimulacra2","max-error"].includes(e.metric)&&Number.isFinite(e.score)&&["encoder-reconstruction","decoded-output","predicted"].includes(e.domain)&&(void 0===e.floor||Number.isFinite(e.floor)&&"ssimulacra2"===e.metric)&&(void 0===e.limit||Number.isFinite(e.limit)&&"ssimulacra2"!==e.metric))||void 0!==e.view&&"pu21"!==e.view&&"without-noise"!==e.view)return!1;let t=e.region;return void 0===t||t&&Number.isSafeInteger(t.x)&&t.x>=0&&Number.isSafeInteger(t.y)&&t.y>=0&&ts(t.width)&&ts(t.height)}function ur(e){return!(!e||"object"!=typeof e||!Number.isSafeInteger(e.width)||e.width<1||!Number.isSafeInteger(e.height)||e.height<1||!["jxl","jpeg","png"].includes(e.format)||null!==e.source&&(!["bytes","pixels"].includes(e.source?.kind)||!Zo(e.source.digest))||"boolean"!=typeof e.meetsTarget||!or(e.fidelity,null===e.bytes)||!Array.isArray(e.measurements)||!e.measurements.every(sr)||void 0!==e.transform&&(!ts(e.transform?.width)||!ts(e.transform?.height)||void 0!==e.transform.frame&&(!Number.isSafeInteger(e.transform.frame)||e.transform.frame<0)||void 0!==e.transform.resizer&&"browser"!==e.transform.resizer||void 0!==e.transform.via&&("browser"!==e.transform.resizer||!Array.isArray(e.transform.via)||!e.transform.via.length||!e.transform.via.every(e=>ts(e?.width)&&ts(e?.height))))||void 0!==e.readAs&&!["srgb","display-p3"].includes(e.readAs)||void 0!==e.timing&&!["exact","rounded"].includes(e.timing)||void 0!==e.usedWebGPU&&"boolean"!=typeof e.usedWebGPU||void 0!==e.originalBytes&&!ts(e.originalBytes)||void 0===e.originalBytes&&void 0!==e.largerThanOriginal)&&(null===e.bytes?null===e.kept&&!1===e.meetsTarget&&void 0===e.largerThanOriginal&&es(e.reason)&&"JXL_TARGET"===e.reason.code:!("[object Uint8Array]"!==Object.prototype.toString.call(e.bytes)||!e.bytes.byteLength||!["jpeg-bytes","pixels","lossy"].includes(e.kept)||void 0!==e.originalBytes&&e.largerThanOriginal!==e.bytes.byteLength>e.originalBytes||!e.meetsTarget&&!es(e.reason)||e.meetsTarget&&void 0!==e.reason))}function cr(e){if(!ur(e))return!1;if(e.meetsTarget){let t=e.fidelity;if(("exact"===t||100===t?.quality||0===t?.maxError)&&"lossy"===e.kept)return!1;for(let t of e.measurements)if(void 0!==t.floor&&t.score<t.floor||void 0!==t.limit&&t.score>t.limit)return!1;if("lossy"===e.kept&&t&&"object"==typeof t)for(let r of["ssimulacra2"]){if("number"!=typeof t[r])continue;let n=e.measurements.find(e=>e.metric===r&&void 0===e.region);if(!n||("ssimulacra2"===r?n.score<t[r]:n.score>t[r]))return!1}}return!0}function fr({width:e,height:t,orientation:r,orientationAt:n,orientationBig:a},i){if(void 0===e||void 0===t)throw fn("JXL_JPEG","JPEG dimensions: missing or truncated");return h(e,t,i),{width:e,height:t,orientation:r??1,orientationAt:n,orientationBig:a}}function*hr(e,t,r){let n=yield*z("jpeg-geometry",function*(){let r={at:0,phase:"signature",width:void 0,height:void 0,orientation:null,done:!1};for(;!r.done;){let t=yield*K("jpeg-geometry-window",()=>dr(e,r));t!==Da&&(r=t)}return fr(r,t)});return r?.({...n}),as(n)}function dr(e,t){let r={...t},n=r.at,a=e.length,i=Math.min(a,n+131072),l=e.subarray(n,Math.min(a,i+65540)),o=e=>l[e-n],s=()=>"marker-code"===r.phase||"entropy-code"===r.phase;if("signature"===r.phase){if(255!==o(0)||216!==o(1))throw fn("JXL_JPEG","JPEG signature: not a JPEG");r.at=2,r.phase="marker"}for(;!r.done&&(r.at<i||r.at>=a&&s());){if("entropy"===r.phase){for(;r.at<i&&255!==o(r.at);)r.at++;r.at<i&&(r.at++,r.phase="entropy-code");continue}if("marker"===r.phase){if(255!==o(r.at++))throw fn("JXL_JPEG","JPEG marker: invalid");r.phase="marker-code"}for(;r.at<i&&255===o(r.at);)r.at++;if(r.at>=i&&r.at<a)break;if("entropy-code"===r.phase){let e=o(r.at);if(0===e||e>=208&&e<=215){r.at++,r.phase="entropy";continue}r.phase="marker-code"}let e=o(r.at++);if(217===e){r.done=!0;break}if(r.phase="marker",1===e||e>=208&&e<=215)continue;let t=256*o(r.at)+o(r.at+1),s=r.at+t,u=r.at+2;if(!Number.isInteger(t)||t<2||s>a)throw fn("JXL_JPEG","JPEG segment: incomplete");if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(e)){if(t<8)throw fn("JXL_JPEG","JPEG dimensions: missing or truncated");if(r.height=256*o(u+1)+o(u+2),r.width=256*o(u+3)+o(u+4),!r.width||!r.height)throw fn("JXL_JPEG","JPEG deferred height: use host pixels")}225===e&&null===r.orientation&&s-u>=6&&[69,120,105,102,0].every((e,t)=>o(u+t)===e)&&(r.orientation=zt(l,u+6-n,s-n,(e,t)=>{r.orientationAt=n+e,r.orientationBig=t})),r.at=s,218===e&&(r.phase="entropy")}return r.at>=a&&!s()&&(r.done=!0),r}async function mr(e,t,r,n,a,i="binary64"){let l="libjxl"===i?"verify-score-libjxl-":"verify-score-";return(await a.unit(l+"result",()=>pr(e,t,r,n,a,i,l))).value}async function pr(e,t,r,n,a,i,l){let{unit:o,tools:s}=a,u=e.width,c=e.height,f=!0,h=is(u);for(let r=0;r<c;r+=h){let n=Math.min(h,c-r),a=f,{value:i}=await o(l+"alpha",()=>a&&[e,t].every(e=>(e.data.ahead?.(r*u*4,(r+n)*u*4),s.opaque(e.data.subarray(r*u*4,(r+n)*u*4)))),{carry:!0});i!==Da&&(f=i)}if(f)return yr(e,t,r,n,a,i,l,null);let d=1/0;for(let o of[255,0])d=Math.min(d,await yr(e,t,r,n,a,i,l+"over-"+o+"-",o));return d}async function yr(e,t,r,n,{journal:a,unit:i,tools:l},o,s,u){let c="libjxl"===o,{scaleBand:f,bandState:h,downsample:d,referenceArena:m,useReferenceArena:p,releaseReferenceArena:y,GAUSS32:g,scaleNorm:M,scoreNorms:b,s2Pad:w,compileKernels:L,metricSamples:A,composedOver:v}=l;await L();let I=e.width,x=e.height,N=(a,i)=>{if(!i)return[{rgba:new Uint8Array(0)},{rgba:new Uint8Array(0)}];let l=Math.min(a,x-1),o=Math.min(i,x-l);for(let r of[e,t])r.data.ahead?.(l*I*4,(l+o)*I*4);let s=$([e,t].map(e=>()=>({...e,width:I,height:o,data:e.data.subarray(l*I*4,(l+o)*I*4)})));return A(...null===u?s:s.map(e=>v(e,u)),r,n).map(e=>I<8||x<8?w(e,I,o):e)},O=Math.max(8,I),P=Math.max(8,x),U=[],S=m([]);try{for(let e=0;e<6;e++){let t=is(O,4),r=null;for(let n=-4;n<P;n+=t){let a=Math.min(P,n+t),l=Math.min(P,4*Math.ceil((n+4)/4)),o=Math.min(P,4*Math.ceil((a+4)/4)),{value:u}=await i(s+"row-"+e,()=>{r&&$a([r.states,r.sums]);let e=r?Math.max(0,l-12):l,[t,i]=N(e,o-e),s=p(S);try{let l=f(t,i,O,P,g,n,a,r,r?e:null,c);return a===P?{sums:l.sums}:h(l,O)}finally{s()}},{carry:!0});u!==Da&&(r=u)}let n={ssim:new Float64Array(6),edge:new Float64Array(12)};for(let e=0;e<3;e++)M(n,e,r.sums.subarray(6*e,6*e+6),O*P);if(U.push(n),5===e||O<8||P<8)break;let l=[[],[],[]],o=[[],[],[]];for(let r=0;r<P;r+=t){let n=Math.min(t,P-r),{value:a}=await i(s+"pyramid-"+e,()=>{let[e,t]=N(r,n),a=p(S);try{return[ls(d(e,O,n).planes),ls(d(t,O,n).planes)]}finally{a()}},{cold:!0,alone:!0});for(let e=0;e<3;e++)l[e].push(a[0][e]),o[e].push(a[1][e])}O=Math.ceil(O/2),P=Math.ceil(P/2);let u=os(l.map(e=>ne(e,a.touched)),O),m=os(o.map(e=>ne(e,a.touched)),O);N=(e,t)=>$([()=>u(e,t),()=>m(e,t)])}return b(U).score}finally{y(S)}}async function gr(e,{journal:t,unit:r,tools:n}){let{prepareKernels:a,ensureKernels:i,orientBlock:l,wasmRequired:o}=n,{orientation:s=1,width:u,height:c,data:f,...h}=e;if(!Number.isInteger(s)||s<1||s>8)throw fn("JXL_INPUT","orientation: integer 1-8");if(1===s)return{data:f,width:u,height:c,...h};if(void 0!==h.extraChannels)throw fn("JXL_UNSUPPORTED","extraChannels: supply oriented samples");if(!await a()||!i())throw o();let d=f.constructor,m=d.BYTES_PER_ELEMENT,p={subarray:(e,t)=>{let r=f.subarray(e/m,t/m);return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}},y=new Proxy(new Uint8Array(0),{get:(e,t)=>"subarray"===t?p.subarray:void 0}),g=s>=5,M=g?c:u,b=g?u:c,w=[];for(let e=0;e<b;e+=256){let t=[];for(let n=0;n<M;n+=256){let a=Math.min(256,M-n),i=Math.min(256,b-e),{value:o}=await r("verify-orient-block",()=>{let t=g?s>=7?u-e-i:e:2===s||3===s?u-n-a:n,r=g?6===s||7===s?c-n-a:n:3===s||4===s?c-e-i:e,o=new Uint8Array(a*i*4*m);return l(y,o,u,a,t,r,g?i:a,g?a:i,0,0,4*m,s),o},{cold:!0,alone:!0});t.push(o)}w.push(t)}return{...h,width:M,height:b,data:We(re(w,M*m,b,256,256*m,t.touched),d)}}async function Mr(e,t,r,n,{journal:a,unit:i,tools:l}){let{prepareKernels:o,ensureKernels:s,sampleBands:u,wasmRequired:c,sampleResizeConfig:f,sampleResizeStep:d}=l;if(h(t,r,n.maxPixels),t===e.width&&r===e.height)return e;if(!await o()||!s())throw c();let m=e.data.constructor,p=m.BYTES_PER_ELEMENT,{value:y}=await i("verify-resize-config",()=>f({...e,data:new m(0)},n)),{config:g,table:M,levels:b}=y,w=Math.max(1,Math.min(64,Math.floor(262144/Math.max(t,e.width)))),L=u(e.width,e.height,t,r,g,M,b,p),A=n=>{let a=new m(Math.min(w,L.outRows)*t*4),{state:i,written:l}=d(L,e.data,e.height,r,n,a,0,Math.min(w,L.outRows));return{bytes:new Uint8Array(a.buffer,0,l*t*4*p),state:i}},v={y:0,row:null,sum:null},I=[];do{let e,{value:t}=await i("verify-resize-rows",()=>(e=A(v)).bytes,{cold:!0,alone:!0});I.push(t);let{value:r}=await i("verify-resize-state",()=>(e??=A(v)).state,{carry:!0,tail:!0});r!==Da&&(v=r)}while(v.y<r);return{...e,width:t,height:r,data:We(ne(I,a.touched),m)}}function br(e,t=Blob){let r=[];for(let t=0;t<e.length;t+=cs)r.push(()=>e.subarray(t,Math.min(e.length,t+cs)));return new t($(r))}async function wr(e,t,{journal:r},n=!1){let a=e.subarray(0,Math.min(e.length,32));if(![137,80,78,71,13,10,26,10].every((e,t)=>a[t]===e))return null;if(a.length<24)throw fn("JXL_INPUT","png header: incomplete");let i=new DataView(a.buffer,a.byteOffset,a.byteLength);h(i.getUint32(16),i.getUint32(20),t.maxPixels),await rr();let l=Object.assign(e=>r(e.cold?{...e,borrowed:!0}:e),r);return r.tools.pngPixels(l,e,{readAs:t.readAs,deep:!0,orient:!0,metadata:n,reader:{pngWalk:Zt,pngLayout:ar,pngRows:ir,pngPassRows:lr,pngOrientationLocation:nr,unfilterRow:tr}})}async function Lr(e,t,r,n){let{journal:a,unit:i}=n,{nativeBitmap:l,requirePNGReader:o}=n.tools,s=e.subarray(0,Math.min(e.length,32)),u=t;255===s[0]&&216===s[1]?await Ir(hr(e,r.maxPixels,e=>{u=e}),a):[137,80,78,71,13,10,26,10].every((e,t)=>s[t]===e)?(16===s[24]&&o({readAs:r.readAs}),u=await wr(e,r,n,!0)):ps(s)&&(u=ms(await Ir(Lt(e),a)));let{width:c,height:f,orientation:d=1,orientationAt:m,orientationBig:p,exifAt:y,exifLength:g}=u;h(c,f,r.maxPixels);let M,b,w=()=>{let t=br(e);if(!(d>1))return t;let r=Uint8Array.of(p?0:1,p?1:0);if(void 0!==y){let n=e.subarray(y-4,y+g).slice();n.set(r,m-y+4);let a=new Uint8Array(4);return new DataView(a.buffer).setUint32(0,qt(n)),new Blob([t.slice(0,y-4),n,a,t.slice(y+g+4)])}return new Blob([t.slice(0,m),r,t.slice(m+2)])},L=[];for(let e=0;e<f;e+=us){let t=[];for(let n=0;n<c;n+=us){let a=Math.min(us,c-n),o=Math.min(us,f-e),{value:s}=await i("verify-native-group",async()=>{M??=w();let t=await l(M,r,{maxPixels:r.maxPixels,signal:r.signal},{region:{x:n,y:e,width:a,height:o},platform:()=>"source: RGBA/PNG; JPEG: jpegxl/jpeg recompress"});if(t.width!==a||t.height!==o)throw fn("JXL_PLATFORM","decoder: crop dimensions");return{data:new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.byteLength),colorSpace:t.colorSpace}},{cold:!0,alone:!0});b??={colorSpace:s.colorSpace},t.push(s.data)}L.push(t)}return gr({...b,width:c,height:f,data:re(L,c,f,us,us,a.touched),...d>1&&{orientation:d}},n)}async function Ar(e,t){let r=qn(),n=ys(t);for(let t=0;t<e.length;t+=cs){let{value:a}=await n("output-hash",()=>v(r,e.subarray(t,Math.min(e.length,t+cs))),{carry:!0});a!==Da&&(r=a)}return"sha256:"+I(r)}function vr(e,t){return Object.freeze({id:"verify",eager:!1,normalize(e,t){let r=c(e),n=Object.keys(r).find(e=>!["result","parts","maxPixels"].includes(e));if(n)throw fn("JXL_OPTIONS",`unknown field: ${n}; use result, parts, maxPixels`);let a=c(r.result,"Stored result");if(Object.hasOwn(a,"bytes")||Object.hasOwn(a,"verification")||!cr({...a,bytes:Uint8Array.of(0)}))throw fn("JXL_INPUT","verification metadata: encode metadata without bytes or verification");let i=void 0===r.maxPixels&&"jpeg-bytes"===a.kept?Gr:d(r.maxPixels);h(a.width,a.height,i);let l=t.kind??"pixels";if("pixels"===l){if(h(t.width,t.height,i),t.byteLength!==t.width*t.height*4)throw fn("JXL_INPUT","pixels: width*height*4 RGBA8; kind: 'file' for PNG/JPEG")}else if("file"!==l)throw fn("JXL_INPUT","source kind: pixels or file");if(!Array.isArray(r.parts)||!r.parts.length||r.parts.some(e=>!va(e).length)||r.parts.reduce((e,t)=>e+t.length,0)>4294967295)throw fn("JXL_INPUT","parts: nonempty ordered immutable");return{options:{...r},maxPixels:i}},async run(t,r,n,a){let i=ys(a),l=[];for(let e of t.options.parts){let{value:t}=await i("verify-candidate-part",()=>a.part(e),{cold:!0,alone:!0});l.push(t)}let o=a.join(l),s={...t.options.result,bytes:o},u="file"===(n.kind??"pixels")?r:{data:r,width:n.width,height:n.height,...n.colorSpace&&{colorSpace:n.colorSpace}},c=await e(u,s,{journal:a,source:n,sourceIdentity:await it(n),outputDigest:await Ar(o,a),pixelResult:Sr,restored:xr,maxPixels:t.maxPixels});return{bytes:new Uint8Array(0),facts:c}},...t&&{async straight(e,r,n,a,i,l){let o=[];for(let t of e.options.parts)o.push(await i(t));let s=new Uint8Array(o.reduce((e,t)=>e+t.length,0)),u=0;for(let e of o)s.set(e,u),u+=e.length;let c="file"===(n.kind??"pixels")?r:{data:r,width:n.width,height:n.height,...n.colorSpace&&{colorSpace:n.colorSpace}},f=await t(c,{...e.options.result,bytes:s},{signal:a,maxPixels:e.maxPixels,...l&&Vn in l&&{[Vn]:l[Vn]}});return{bytes:new Uint8Array(0),facts:f}}},record(e,t,r,n){if(e.length||!0!==n?.verified)throw fn("JXL_INPUT","verification: completed receipt");return n}})}async function Ir(e,t){let r,n=!1;try{for(;;){let n=W(e,r,t);if(n.done)return n.value;r=Ja(n.value)?await t(n.value):void 0}}catch(e){throw n=!0,e}finally{try{e.return?.()}catch(e){if(!n)throw e}}}async function xr(e,t,r,n){let a=n.restoreSteps??yo(n);if(!a?.open||!a?.normalize)throw fn("JXL_PLATFORM","restore: configureDecoder(decode, restore) from jpegxl/jpeg");let i=Math.min(r.maxPixels,Gr),l=a.normalize({maxPixels:i}),o=await Ir(a.open(l,e),n.journal),s=ys(n.journal),u={hash:qn(),equal:o.bytes.length===t.length};for(let e=0;e<o.bytes.length;e+=cs){let r=Math.min(o.bytes.length,e+cs),{value:n}=await s("verify-restored-bytes",()=>{let[n,a]=$([()=>o.bytes.subarray(e,r),()=>t.subarray(e,Math.min(t.length,r))]);return{hash:v(u.hash,n),equal:u.equal&&n.length===a.length&&n.every((e,t)=>e===a[t])}},{carry:!0});n!==Da&&(u=n)}return{size:"jpeg"===r.format?u.equal?o.facts:await Ir(hr(t,r.maxPixels),n.journal):ms(await Ir(Lt(e),n.journal)),equal:u.equal,digest:"sha256:"+I(u.hash)}}async function Nr(e,t,{journal:r,unit:n,tools:a},i=!1,l=!1,o=!1){let{nativePictureWith:s,NATIVE_PICTURE_OPTIONS:c}=a,f=await Ir(Lt(e),r);if(h(f.width,f.height,t.maxPixels),f.animation)throw fn("JXL_UNSUPPORTED","animation: use verify()");let{value:d}=await n("verify-decode-reader",()=>!i&&Tt(f,ds(t),!0)),m=()=>Or(e,f,t,n,l&&!d?a:null,o?bs:_t),p=d?null:await Ir(Jt(e,ds(t)),r),y=d?us:p.group;if(![128,256,512,1024].includes(y))throw fn("JXL_DECODE","decoder group: 128|256|512|1024");let g,M=null,b=async(r,n,a,i)=>{let l;try{l=d?Et(f,await s(e.subarray(0,Math.min(e.length,32)),{width:a,height:i,colorSpace:f.colorEncoding.primaries,maxPixels:t.maxPixels,signal:t.signal},(t,l)=>(g??=br(e,l),()=>t.call(globalThis,g,r,n,a,i,c))),d):await Bt(e,{...ds(t),region:{x:r,y:n,width:a,height:i},maxTotalSamples:Math.max(1048576,7077888)},p,o)}catch(e){if(!d&&!0===e?.[ss])return{whole:!0};throw e}if(![Uint8Array,Uint8ClampedArray,Uint16Array,Float32Array].some(e=>l.data instanceof e)||l.width!==a||l.height!==i)throw fn("JXL_UNSUPPORTED","decoder: complete typed RGBA groups");return{type:l.data instanceof Uint16Array?"Uint16Array":l.data instanceof Float32Array?"Float32Array":"Uint8Array",data:new Uint8Array(l.data.buffer,l.data.byteOffset,l.data.byteLength),description:Object.fromEntries(hs.filter(e=>void 0!==l[e]).map(e=>[e,"extraChannels"===e?l[e].map(({data:e,plane:t,...r})=>r):l[e]]))}},{value:w}=await n("verify-decode-description",async()=>{let e=await b(0,0,Math.min(y,f.width),Math.min(y,f.height));return e.whole?e:(M=e.data,{type:e.type,description:e.description})});if(w.whole)return m();let L=w.description,A={Uint8Array,Uint16Array,Float32Array}[w.type],v=[],I=A.BYTES_PER_ELEMENT,x=!l||d||!a.nativeGammaRGBA||"Uint8Array"!==w.type||8!==L.bitDepth||"uint"!==L.sampleFormat||"srgb"!==L.colorSpace||"srgb"!==L.transferFunction||1!==L.orientation&&!L.orientationApplied||L.animation?null:[],N=async(r,n,i,l)=>{let s;try{s=await Bt(e,{...ds(t),colorSpace:"srgb",format:"float32",region:{x:r,y:n,width:i,height:l},maxTotalSamples:Math.max(1048576,7077888)},p,o)}catch(e){if(u(t.signal),"JXL_UNSUPPORTED"===e?.code||Lo(e))return null;throw e}let c=i*l,f=s.data,h=f.length/c;if(!(f instanceof Float32Array)||3!==h&&4!==h)return null;let d=[new Float32Array(c),new Float32Array(c),new Float32Array(c)];for(let e=0,t=0;e<c;e++,t+=h)for(let r=0;r<3;r++)d[r][e]=f[t+r];let m=a.nativeGammaRGBA(d,i,l,{x:r,y:n});for(let e=0;e<c;e++)m[4*e+3]=4===h?Math.round(255*Math.min(1,Math.max(0,f[4*e+3]))):255;return m};for(let e=0;e<f.height;e+=y){let t=Math.min(y,f.height-e),r=Array.from({length:Math.ceil(t/Ms)},()=>[]),a=x&&r.map(()=>[]);for(let i=0;i<f.width;i+=y){let l=Math.min(y,f.width-i),o=4*l*I,s=null;for(let a=0;a<r.length;a++){let{value:u}=await n(a?"verify-decode-group-rows":"verify-decode-group",async()=>{if(!s)if(i||e||!M){let r=await b(i,e,l,t);if(r.whole)return r;s=r.data}else s=M;return s.slice(a*Ms*o,Math.min(t,(a+1)*Ms)*o)},{cold:!0,alone:!0,...a&&{tail:!0}});if(!(u instanceof Uint8Array)&&u.whole)return m();r[a].push(u)}M=null;let u=null;if(x)for(let o=0;o<r.length;o++){let{value:r}=await n(o?"verify-djxl-group-rows":"verify-djxl-group",async()=>(u??=await N(i,e,l,t),u&&u.slice(o*Ms*l*4,Math.min(t,(o+1)*Ms)*l*4)),{cold:!0,alone:!0,...o&&{tail:!0}});if(null===r){x=null;break}a[o].push(r)}}v.push(...r),x&&x.push(...a)}return{...L,width:f.width,height:f.height,data:We(re(v,f.width*I,f.height,Ms,y*I,r.touched),A),...x&&{native:We(re(x,f.width,f.height,Ms,y,r.touched),Uint8Array)}}}async function Or(e,t,r,n,a=null,i=_t){let{value:l}=await n("verify-decode-whole",async()=>{let n=await i(e,ds(r));if(![Uint8Array,Uint8ClampedArray,Uint16Array,Float32Array].some(e=>n.data instanceof e)||n.width!==t.width||n.height!==t.height)throw fn("JXL_UNSUPPORTED","decoder: complete typed RGBA samples");return{type:n.data instanceof Uint16Array?"Uint16Array":n.data instanceof Float32Array?"Float32Array":"Uint8Array",data:new Uint8Array(n.data.buffer,n.data.byteOffset,n.data.byteLength),description:Object.fromEntries(hs.filter(e=>void 0!==n[e]).map(e=>[e,"extraChannels"===e?n[e].map(({data:e,plane:t,...r})=>r):n[e]]))}},{cold:!0,alone:!0}),o=l.description,s=null;return a?.nativeGammaRGBA&&"Uint8Array"===l.type&&8===o.bitDepth&&"uint"===o.sampleFormat&&"srgb"===o.colorSpace&&"srgb"===o.transferFunction&&(1===o.orientation||o.orientationApplied)&&!o.animation&&({value:s}=await n("verify-djxl-whole",async()=>{let n;try{n=await i(e,{...ds(r),colorSpace:"srgb",format:"float32"})}catch(e){if(u(r.signal),"JXL_UNSUPPORTED"===e?.code||Lo(e))return null;throw e}let l=t.width*t.height,o=n.data,s=o.length/l;if(!(o instanceof Float32Array)||3!==s&&4!==s||n.width!==t.width||n.height!==t.height)return null;let c=[new Float32Array(l),new Float32Array(l),new Float32Array(l)];for(let e=0,t=0;e<l;e++,t+=s)for(let r=0;r<3;r++)c[r][e]=o[t+r];let f=a.nativeGammaRGBA(c,t.width,t.height);for(let e=0;e<l;e++)f[4*e+3]=4===s?Math.round(255*Math.min(1,Math.max(0,o[4*e+3]))):255;return f},{cold:!0,alone:!0})),{...o,width:t.width,height:t.height,data:We(l.data,{Uint8Array,Uint16Array,Float32Array}[l.type]),...s&&{native:We(s,Uint8Array)}}}async function Pr(e,t,r){if(r.reference)return r.reference;let n=e,a=!1;if("file"===(r.source?.kind??"pixels")){let i=e.subarray(0,Math.min(e.length,32));if(ps(i))n=void 0===t.readAs?Ut(await Nr(e,t,r)):await Lr(e,t.size,t,r);else if(255===i[0]&&216===i[1]&&void 0===t.readAs&&mo(r)){let i=po(r);if(!i)throw fn("JXL_PLATFORM","restore: configureDecoder(decode, restore) from jpegxl/jpeg");await(i.prepare?.());let l=await Ir(i.open(i.normalize({effort:1,maxPixels:Math.min(t.maxPixels,Gr)}),e),r.journal);n=Ut(await Nr(l.bytes,t,r,!0)),a=!0}else n=await wr(e,t,r),a=!!n;if(!n){if(!(255===i[0]&&216===i[1]||[137,80,78,71,13,10,26,10].every((e,t)=>i[t]===e)))throw fn("JXL_UNSUPPORTED","source: use verify()");n=await Lr(e,t.size,t,r)}}if((a||t.transform)&&(n=await gr(n,r)),"browser"===t.transform?.resizer)throw fn("JXL_UNSUPPORTED","resizer: use verify()");return t.transform&&(n=await Mr(n,t.transform.width,t.transform.height,t,r)),n}async function Ur(e,t,r,n,a,i,l,o){let s=n.proof.score,{value:u}=await o.unit("verify-noise-flag",()=>wt(e));if(!1===u)return n;if(!fo(l))return!0===u&&a.alphaExact?o.tools.noiseUnread(n):n;let c=bo(l)?await Nr(e,l,o,!0,!0,!0):await Or(e,{width:r.width,height:r.height},l,o.unit,o.tools,bs),f=0,h=await o.tools.pixelEvidence(t,c,i,l,a,(e,t,r,n,a,i)=>mr(e,t,r,n,"libjxl"===i?o:f++?gs(o,"djxl-"):o,i));return{...h,proof:{...h.proof,view:"without-noise",...Number.isFinite(s)&&{decodedScore:s}}}}async function Sr(e,t,{fidelity:r,format:n,size:a,outputDigest:i,details:l,options:o,noiseOff:s=!1},c){let{comparison:f,comparisonContext:h,pictureICC:d,conversionProfile:m,sameBytes:p,pixelEvidence:y,protectionDomain:g,protectionEvidence:M,describedIdentity:b,sampleBytes:w,profileTransformSteps:L}=c.tools,A=ys(c.journal),x={...c,unit:A},N={...o,...c&&Vn in c&&{[Vn]:c[Vn]}},O=await Pr(t,{...N,size:a},gs(x,"reference-")),P=gs(x,"output-"),U="jxl"===n&&"exact"!==r&&!!c.tools.measurementTarget&&"ssimulacra2"===c.tools.measurementTarget(r,o).metric,S="jxl"===n?await Nr(e,N,P,!1,U):await wr(e,{...o,readAs:void 0},P);if(!S)throw fn("JXL_UNSUPPORTED","output: use verify()");o.protection&&g(o.protection,O,S);let j=d(O),E=d(S),T=!!j&&!!E&&j.length===E.length;if(T)for(let e=0;e<j.length;e+=fs){let{value:t}=await A("verify-profile-bytes",()=>{let[t,r]=$([j,E].map(t=>()=>t.subarray(e,Math.min(t.length,e+fs))));return T&&p(t,r)},{carry:!0});t!==Da&&(T=t)}let F=m(O,S),k=F?await Ir(L(F),c.journal):null,{value:J}=await A("verify-compare-description",()=>h(O,S,k,T)),_=O===t?c.sourceIdentity:null,B={compared:f({...O,data:new O.data.constructor(0)},{...S,data:new S.data.constructor(0)},o.protection,0,J),hash:_?null:qn()},R=is(O.width);for(let e=0;e<O.height;e+=R){let t=Math.min(R,O.height-e),{value:r}=await A("verify-compare-rows",()=>{for(let r of[O,S])r.data.ahead?.(e*r.width*4,(e+t)*r.width*4);let[r,n]=$([O,S].map(r=>()=>({...r,height:t,data:r.data.subarray(e*r.width*4,(e+t)*r.width*4)}))),a=f(r,n,o.protection,e*O.width,J),i=B.compared;return{compared:{...i,...a,exact:i.exact&&a.exact,alphaExact:i.alphaExact&&a.alphaExact,supported:i.supported&&a.supported,maxError:Math.max(i.maxError,a.maxError),...(i.colorScope||a.colorScope)&&{colourSamples:(i.colourSamples??0)+(a.colourSamples??0),visible:!(!i.visible&&!a.visible)},...o.protection&&{protectedSamples:i.protectedSamples+(a.protectedSamples??0),protectedExact:i.protectedExact&&!0===a.protectedExact}},hash:B.hash&&v(B.hash,w(r.data))}},{carry:!0});r!==Da&&(B=r)}let X=_??await b(O,{data:"sha256:"+I(B.hash)},new O.data.constructor(0),async e=>{let t=qn();for(let r=0;r<e.length;r+=fs){let{value:n}=await A("verify-reference-icc-hash",()=>v(t,e.subarray(r,Math.min(e.length,r+fs))),{carry:!0});n!==Da&&(t=n)}return"sha256:"+I(t)}),D=0,C=await y(O,S,r,o,B.compared,(e,t,r,n,a,i)=>mr(e,t,r,n,"libjxl"===i?x:D++?gs(x,"djxl-"):x,i));return s&&"jxl"===n&&"ssimulacra2"===C.proof.metric&&(C=await Ur(e,O,S,C,B.compared,r,N,gs(x,"noise-off-"))),C=M(C,B.compared,o),u(o.signal),{...ms(S),kept:C.kept,proof:{...C.proof,outputDigest:i,referenceDigest:X.digest,...l},meetsTarget:C.proof.verified,...C.reason&&{reason:C.reason}}}async function jr(e,t,r,n,a,i,l){let o=xs(l?.verify);if(!o)throw fn("JXL_OPTIONS",Ns);let s=t instanceof Uint8Array?t:t.bytes,u=t instanceof Uint8Array?null:t.facts,c=await e.record(s,r,a,u),f=await it(a),h=a,d="file"===a.kind||void 0===a.width?n:{data:n,width:a.width,height:a.height,...Ji(a)};if("decode"===a.kind){let e=(Array.isArray(c)?c[0]:c)?.source;if(e?.digest&&e.digest!==f.digest){let t=(l&&Vn in l?l[Vn]:Wn())?.restore;if(!t)throw fn("JXL_PLATFORM","restore: configureDecoder(decode, restore)");let r=await q(i,"verify-decode-original",async()=>(await t(n)).bytes),o=I(v(qn(),r));if("sha256:"+o!==e.digest)throw fn("JXL_INPUT","stored JPEG: original/result mismatch");d=r,f={kind:"bytes",digest:e.digest},h={kind:"file",generation:a.generation,sha256:o,byteLength:r.length}}else h={...a,kind:"file"}}let m=t=>q(i,"verify-output",async()=>{let n=t.source?t:{...t,source:f};return o[vs](d,n,{journal:i,source:h,sourceIdentity:f,...l&&Vn in l&&{[Vn]:l[Vn]},outputDigest:await Ar(t.bytes??new Uint8Array(0),i),pixelResult:Sr,restored:xr,maxPixels:r.maxPixels??r.options?.maxPixels,restoreSteps:e.restore??("jpeg:restore"===e.id?e:void 0)})}),p=[];for(let e of Array.isArray(c)?c:[c])p.push(await m(e));return{bytes:s,facts:u,verification:Array.isArray(c)?p:p[0]}}function Er(e){if("function"!=typeof e)throw fn("JXL_OPTIONS","operation: imported function");let t="function"==typeof e?e[Ls]:void 0,r=Object.hasOwn(Ps,t?.kind??"")?Us(t,e):t;if(!r)throw fn("JXL_UNSUPPORTED","operation: resumable verb");let n=As.get(r);if(!n){let e=I(v(qn(),Is.encode(pn+"\0"+r.id)));n=ge({id:r.id,build:e,normalize:r.normalize,open:r.open,run:r.run,verify:(...e)=>jr(r,...e),eager:r.eager,tools:Nl,straight:r.straight}),As.set(r,n)}return{steps:r,stepper:n}}function Tr(e){let t=f(e,"store",["readSource","read","readMany","write","writeMany"]);if("function"!=typeof t.readSource||"function"!=typeof t.read||"function"!=typeof t.write&&"function"!=typeof t.writeMany||["readMany","write","writeMany"].some(e=>void 0!==t[e]&&"function"!=typeof t[e]))throw fn("JXL_OPTIONS","store: readSource/read and write/writeMany functions");let r=async(r,...n)=>{try{return await Reflect.apply(t[r],e,n)}catch(e){throw l(e)}},n=new Map;return{unsaved:n,read:async e=>n.get(e.hash)??await r("read",{hash:e.hash,length:e.length}),readMany:async e=>{let a=e.filter(e=>!n.has(e.hash)),i=a.length?t.readMany?await r("readMany",a.map(e=>({hash:e.hash,length:e.length}))):await Promise.all(a.map(e=>r("read",{hash:e.hash,length:e.length}))):[];if(!Array.isArray(i)||i.length!==a.length)throw fn("JXL_INPUT","readMany: one part per reference");let l=0;return e.map(e=>n.get(e.hash)??i[l++])},readSource:(e,t)=>r("readSource",e,t),write:(e,t)=>r("write",e,t),...t.writeMany&&{writeMany:e=>r("writeMany",e)}}}async function Fr(e){let t=[...e.unsaved].map(([e,t])=>({ref:{hash:e,length:t.length},bytes:t}));if(t.length){if(e.writeMany)await e.writeMany(t);else for(let{ref:r,bytes:n}of t)await e.write(r,n);e.unsaved.clear()}}function kr(e,t,r){if(e=f(e,`${t} options`),r)for(let n of Object.keys(e))if(!r.includes(n))throw fn("JXL_OPTIONS",`unknown option: ${t}.${n}`);return e}async function Jr(e){let t=Wn();try{let{operation:r,input:n,options:a={},store:i,verify:l,memoryBytes:o}=kr(e,"start",["operation","input","options","store","verify","memoryBytes"]);if(void 0!==l&&!xs(l))throw fn("JXL_OPTIONS","verify: pass verify from jpegxl/verify");let{steps:s,stepper:u}=Er(r),c=Tr(i);if("verify"===s.id&&l)throw fn("JXL_OPTIONS","verify: omit for verify operation");if(l&&!Mo({[Vn]:t}))throw fn("JXL_PLATFORM",wo);let f=Dr(s,c,o),{checkpoint:h,parts:d}=await u.start({source:n,options:a,verify:!!l,admit:f});if("decode"===h.source.kind&&!t?.decode)throw fn("JXL_PLATFORM","decoder: configureDecoder(decode) with decode from jpegxl/decode");let m=a.fidelity,p="function"==typeof createImageBitmap&&"function"==typeof OffscreenCanvas||"function"==typeof t?.recompress?.[Symbol.for("rapier-jxl.jpeg.pixels")];if("file"===h.source.kind&&/^(encode|fit|variants):/.test(s.id)&&("exact"!==m&&100!==m?.quality||"pixels"===a.jpeg)&&!p){let e=await c.readSource(0,Math.min(2,h.source.byteLength));if(255===e?.[0]&&216===e[1])throw fn("JXL_PLATFORM","JPEG: use jpegxl/jpeg or RGBA8")}return Ss(c,d),await Fr(c),h}catch(e){throw o(e)}}async function _r(e,t){let r=Wn();try{let{operation:n,input:a,store:i,verify:l,budget:o={ms:30},signal:c,memoryBytes:f}=kr(t,"advance",["operation","input","options","store","verify","budget","signal","memoryBytes"]);if(e=T(S(e)),s(c),null===o||"object"!=typeof o||Array.isArray(o))throw fn("JXL_OPTIONS","budget.ms: 1-60000");let{ms:h,reads:d}=kr(o,"budget",["ms","reads"]);if(!Number.isFinite(h)||h<=0||h>6e4)throw fn("JXL_OPTIONS","budget.ms: 1-60000");if(void 0!==d&&(!Number.isSafeInteger(d)||d<1||d>1e6))throw fn("JXL_OPTIONS","budget.reads: positive integer");let{steps:m,stepper:p}=Er(n),y=Tr(i),g=performance.now(),M=Dr(m,y,f);if(u(c),e?.plan?.verify&&!xs(l))throw fn("JXL_OPTIONS",Ns);let b=e?.plan?.options,w=e?.source,L=(e,t)=>!!e&&t>=1.25*e.ms,A=Xr(m,b,1,1,!0,w?.kind,f),v=A.admitted&&L(A.measured,.7*h)&&((e,t)=>{let r="file"===w?.kind||"decode"===w?.kind?Cr(e):{width:w?.width,height:w?.height},n=r&&Xr(m,b,r.width,r.height,!0,w?.kind,f);return!!n?.admitted&&L(n.measured,t)}),I=async(e,t,r)=>{await(Dr(m,{readSource:r},f)?.(e,t)),await(m.prepare?.()),u(c)},x=await p.advance(e,js(e,a,y,{signal:c,verify:l,admit:M,prepare:I,[Vn]:r,deadline:g+.7*h,...v&&{straight:v},...d&&{reads:d},...void 0!==f&&{memoryBytes:f}}),{units:64});return Ss(y,x.parts),await Fr(y),{checkpoint:x.checkpoint,done:x.done,released:x.released}}catch(e){throw o(e)}}async function Br(e,t){try{let{operation:r,input:n,store:a,signal:i,memoryBytes:l}=kr(t,"finish",["operation","input","options","store","verify","budget","signal","memoryBytes"]);e=T(S(e)),s(i),u(i);let{steps:o,stepper:c}=Er(r),f=Tr(a),h=js(e,n,f,{signal:i,admit:Dr(o,f,l),...void 0!==l&&{memoryBytes:l}}),{byteLength:d,result:m}=await c.completion(e,h);if(void 0!==l&&d+Es>l)throw fn("JXL_MEMORY",`memoryBytes ${l}: need ${d} or store parts`);let p=await c.output(e,h,e=>{if(e!==d)throw fn("JXL_INPUT","saved output: incomplete parts");try{return new Uint8Array(e)}catch{throw fn("JXL_MEMORY","allocation: store output parts")}});u(i);let y=await o.record(p,e.plan,e.source,m?.facts??null),g=await it(e.source),M=(t,r=0)=>{let n=t.source?t:{...t,source:g};if(!e.plan.verify)return n;let a=Array.isArray(y)?m?.verification?.[r]:m?.verification;if(!a?.verified||a.source?.kind!==n.source?.kind||a.source?.digest!==n.source?.digest||a.width!==n.width||a.height!==n.height||a.format!==n.format)throw fn("JXL_INPUT","verification: missing result");return{...n,verification:a}};return Array.isArray(y)?y.map(M):M(y)}catch(e){throw o(e)}}function Rr(e){try{let{operation:t,options:r={},width:n,height:a,kind:i}=kr(e,"workerAdmission",["operation","options","width","height","kind"]),{steps:l}=Er(t);if(void 0!==i&&"pixels"!==i&&"file"!==i&&"decode"!==i)throw fn("JXL_OPTIONS","source kind: pixels|file|decode");if("verify"!==l.id&&l.normalize?.(r,{kind:i??"pixels",width:1,height:1,byteLength:4}),!Number.isSafeInteger(n)||!Number.isSafeInteger(a)||n<1||a<1)throw fn("JXL_OPTIONS","dimensions: positive integer pixels");return Xr(l,r,n,a,!1,i)}catch(e){throw o(e)}}function Xr(e,t,r,n,a=!1,i,l){if(!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<1||n<1)return{admitted:!1,measured:null};let o=t?.fidelity,s="exact"===o||100===o?.quality,u="encode:rapier-jxl/upload"===e.id||"fit:rapier-jxl/upload"===e.id,c=u||"encode:rapier-jxl"===e.id||"fit:rapier-jxl"===e.id?`${e.id} ${s?"exact":"lossy"}`:"verify"===e.id?"verify "+("jpeg-bytes"===t?.result?.kept?"jpeg":"pixels"):e.id,f=ws["decode"===i?c+" decode":c],h=f?.any??f?.[t?.effort??(u?3:7)]??[],d=r*n;for(let e of h){let[t]=e,[r,n,i]=a?e.slice(3):e.slice(1),o=void 0===l?n:1.1*r+Es<=l;if(void 0===r)return{admitted:!1,measured:null};if(!o||t>=d)return{admitted:!!o,measured:{pixels:t,estimate:r,...a&&{ms:i??1/0}}}}return{admitted:!1,measured:null}}function Dr(e,t,r){if(void 0!==r){if(!Number.isSafeInteger(r)||r<1)throw fn("JXL_OPTIONS","memoryBytes: positive safe integer");return async(n,a)=>{let i,l="file"===a.kind||"decode"===a.kind?null:{width:a.width,height:a.height};if(!l){let e=Math.min(a.byteLength,Ts),r=Ge(await t.readSource(0,e));if(r.length!==e)throw fn("JXL_INPUT","source header: incomplete");l=Cr(r),i=l?.jpeg420?"jpeg420":r.length>=29&&137===r[0]&&80===r[1]&&8===r[24]?"png8":void 0}let o=l?`${l.width}x${l.height} (${l.width*l.height} pixels)`:"a picture with dimensions beyond its first 65536 bytes",s=!n.verify&&"file"===a.kind&&("jpeg:recompress"===e.id?"jpeg420"===i:/^(encode|fit):rapier-jxl(?:\/upload)?$/.test(e.id)&&"png8"===i)&&l&&Xr(e,n.options??n,l.width,l.height,!1,a.kind,r);if(!s?.admitted)throw fn("JXL_MEMORY",`${o}: memoryBytes ${r}; `+(s?.measured?`${s.measured.pixels} pixels: ${Math.ceil(1.1*s.measured.estimate+Es)} bytes needed`:"no measured bound"))}}}function Cr(e){let t=t=>e[t]<<8|e[t+1],r=e=>65536*t(e)+t(e+2);if(e.length>=24&&2303741511===r(0)&&218765834===r(4)&&1229472850===r(12))return{width:r(16),height:r(20)};if(255===e[0]&&216===e[1]){for(let r=2;r+9<=e.length;){if(255!==e[r])return null;let n=e[r+1];if(255!==n){if(n>=192&&n<=207&&196!==n&&200!==n&&204!==n)return{width:t(r+7),height:t(r+5),jpeg420:192===n&&r+19<=e.length&&17===t(r+2)&&8===e[r+4]&&3===e[r+9]&&34===e[r+11]&&17===e[r+14]&&17===e[r+17]};if(217===n||218===n)return null;r+=2+t(r+2)}else r++}return null}if(255!==e[0]||10!==e[1])for(let t=0;t+8<=e.length;){let n=r(t),a=t+8,i=r(t+4);if(1===n){if(t+16>e.length)return null;n=4294967296*r(t+8)+r(t+12),a+=8}if(1786276963===i)return Ue(e.subarray(a));if(1786276976===i)return Ue(e.subarray(a+4));if(!n||n<a-t)return null;t+=n}return Ue(e)}var Gr=Number.MAX_SAFE_INTEGER,Wr=Object.freeze({pixels:Gr,edge:1073741824}),Vr=(e,t)=>Object.assign(new Error(t),{code:e}),Kr=()=>"function"==typeof DOMException?new DOMException("The operation was aborted.","AbortError"):Object.assign(new Error("The operation was aborted."),{name:"AbortError"}),zr=e=>{let t;try{t=e?.reason}catch(e){t=e}return void 0===t?Kr():t},Hr=/allocation failed|out of memory|(?:cannot|could not) allocate|failed to grow|maximum memory size|declared maximum|allocation size overflow|invalid string length/i,Yr=e=>{try{return(e instanceof RangeError||"RangeError"===e?.name||"InternalError"===e?.name)&&!e.code&&Hr.test(String(e.message))}catch{return!1}},qr=e=>e?.message?` (${String(e.message)})`:"",$r=["isContextLost","getParameter","createTexture","createFramebuffer","bindTexture","bindFramebuffer","pixelStorei","texImage2D","framebufferTexture2D","checkFramebufferStatus","readPixels","getError","deleteTexture","deleteFramebuffer"],Qr=(e,t)=>Object.assign(Vr("JXL_PLATFORM",e),{cause:t}),Zr={colorSpaceConversion:"none",premultiplyAlpha:"none",imageOrientation:"from-image"},en=(e,t)=>e.call(globalThis,t,Zr),tn=e=>r=>(n,a)=>{let i=new a([r],{type:"image/jxl"});return e?()=>t(i):()=>en(n,i)},rn=tn(!1),nn=tn(!0),an=Uint8Array.of(255,10,0,0,0,128,160,184,17,8,2,1,0,52,0,75,24,139,13,81,2,86,128,112,18,35,7,0),ln=null,on=Uint8Array.of(255,10,0,0,0,128,149,8,24,16,0,92,0,75,56,65,118,224,226,160,140,44,65,1,224,72,120,36,20,146,40,1,123,1,130,56),sn=Uint8Array.of(255,10,0,0,0,128,128,76,110,4,8,6,1,0,80,0,75,56,65,110,224,244,68,14,79,18,20,9,131,36,74,192,46,64,16,7),un=Object.freeze({alpha:!1,displayP3:!1,image:!1}),cn=null,fn=(e,t)=>Object.assign(new Error(t),{code:e}),hn=new Set(["JXL_OPTIONS","JXL_INPUT","JXL_DIMENSIONS","JXL_JPEG","JXL_DECODE","JXL_RECONSTRUCTION","JXL_TARGET","JXL_PLATFORM","JXL_MEMORY","JXL_LIMIT","JXL_WASM","JXL_WEBGPU","JXL_WORKER","JXL_CLOSED","JXL_UNSUPPORTED","JXL_INTERNAL","JXL_IO","JXL_SETUP"]),dn={JXL_SIZE:"JXL_LIMIT",JXL_INVALID:"JXL_DECODE",JXL_FRAMING:"JXL_INPUT",JXL_RGBA:"JXL_INPUT",JXL_PROTOCOL:"JXL_WORKER",JXL_WORKER_LEASE:"JXL_WORKER",JXL_THREAD_REQUIRED:"JXL_PLATFORM",JXL_UNAVAILABLE:"JXL_PLATFORM",JXL_QUEUE_FULL:"JXL_MEMORY",JXL_BUSY:"JXL_INTERNAL",JXL_CODEC:"JXL_INTERNAL",JXL_DICTIONARY:"JXL_INTERNAL",JXL_ENCODE:"JXL_INTERNAL",JXL_GPU:"JXL_INTERNAL",JXL_GPU_NATIVE_UNPROVEN:"JXL_INTERNAL",JXL_INITIALIZE:"JXL_INTERNAL",JXL_MEMORY_GPU_UNPROVEN:"JXL_INTERNAL",JXL_OPERATION:"JXL_INTERNAL",JXL_PART:"JXL_INTERNAL"},mn=new WeakSet,pn="8.4.1",yn={kernels:"6gzyrq",jpeg:"1fjin7z",decode:"17x8vsf",rebuild:"fgbogf",general:"1sc0v86"},gn=e=>{let t=e.length,r=new Uint8Array(t),n=e.charCodeAt(0);for(let a=0;a<t;a++){let t=e.charCodeAt(a)^n;r[a]=65===t?119:119===t?65:t}return r},Mn=e=>{let t=2166136261;for(let r of e.map(e=>e.name+":"+e.kind).sort().join(" "))t=Math.imul(t^r.charCodeAt(0),16777619);return(t>>>0).toString(36)},bn=new Map,wn=new Map,Ln=!1,An=e=>Object.assign(new Error(e),{code:"JXL_WASM"}),vn=Symbol.for("rapier-jxl/8.4.1 wasm "+Object.entries(yn).map(([e,t])=>e+":"+t).join(";")),In=null,xn=()=>{let e=globalThis[vn];if(!e||e===In)return;In=e;let t=Object.entries(e).filter(([e])=>!bn.has(e));t.length&&m(Object.fromEntries(t))},Nn=e=>(xn(),bn.has(e)),On=new Map,Pn=new Map,Un=e=>void 0===e?Pn.values().next().value:Pn.get(e),Sn=[0,97,115,109,1,0,0,0],jn=()=>{try{return new WebAssembly.Instance(new WebAssembly.Module(Uint8Array.of(...Sn))),!1}catch{return"object"==typeof WebAssembly}},En=()=>{try{return!WebAssembly.validate(Uint8Array.of(...Sn,1,4,1,96,0,0,3,2,1,0,10,23,1,21,0,253,12,...Array(16).fill(0),26,11))}catch{return!0}},Tn=(e=Un())=>Object.assign(Vr("JXL_WASM",jn()?"allow 'wasm-unsafe-eval' or use workerd/edge-light":En()?"WebAssembly SIMD required":`The WebAssembly module failed${qr(e)}; check the host's memory.`),e?{cause:e}:{}),Fn={channel:null,weighted:null,fill:null,palette:null,rct:null,tuple:null,passLevels:null,group:null,screen:null,sampled:null,dct:null,ycbcrTile:null,ycbcrTiles:null,rgbTiles:null,rgbBand:null,photoTile:null,acGroup:null,acGroupPair:null,acDeferred:null,nonzero:null,entropy:null,varblock:null,gaborish:null,strategyFill:null,strategyWrite:null,xybPlanes:null,gabBand:null,dcEvents:null,dcPlan:null,planTokens:null,shape:null,nativeRGBA:null,s2cChannel:null,opaque:null,arena:null,ensure:null},kn="M,> LMMML*A-K222222M-L1L1-O12L1-I2222M-L2L1-O11L1-I2221L1-L1L2-N121L1-I2222L2-W22222222222122111122222222L2-N222MOBLN(#;K ( \"?4OMLN\\]MILLHOONKJEDGFMNJJG\"?$(#9\n:MMF>, =!(,/!(MJG>, =!(!,#MFG>, =!(,#)MAG>, =!(,+(M@F=#*#+$!9(?MCE=#*$)(#MBGÊ]ÏOLH2mOmLmI:HVlGN\r:MlKN\rmKlEmJlDO\rmI:L\v@MmI:O\vI\rmL:L&mK&lEALFmI:N\vI\rmL:L&mK&lEmO:L&mJ&lDALFmI:I\vI\rmO:L&mJ&lDALFmI:H\vI\rmJlEmKlDALFmI:K\vI\rmO:L&mJ&lEmKlDALFmI:J\vI\rmO:L&mJ&lEmL:L&mK&lDALFmJlEmL:L&mK&lDFmHmDmG!mE'mN!'mMmLmJ!mK'mN!'mN±GMMmK:L'oKmL@MFmJ:L'oJmO@MFF@MmM:²J'áyËòFôONO2N1L3mM\tMMMMMMMM)\bI\r\tMMMMMM½²\tMMMMMMµ2mM\tMMMMMMMM,VBFmM\tMMMMMM½2,I\rmMBFmM\tMMMMMM]M.I\r:lLmM\tMMMMMMïlMFmMðoKyÅê:²J&mL'lLmK²²²²²²²JÎÍÍÍÍÍÍ͵rÉòoM\t€v2+Óí»r)I\rmL:L'lLmM\tMMMMMM­rïlMFmM\tMMMMMM½òímM\tMMMMMM½ríîoMmMïlImMlN:NlON\rO\rmMmNmIïoNmOúîoHílMmHÔmMÔ\tៜ?qï.@MmO:O'oO:e@LFFmLú\tMM­³c«rïmLú\t;q4x¢t§pïmMmMíííFçOOO2O1mMmM/I\r\tMMMMMMµ2BFmM\t¢t·³cË\r)I\r\tMMMMMM½2BFmM\t}`˜]ʍ.I\r\tMMMMMMMMBFmMmM\t¢t·³c«rîoMÑoN\tMMMMMM½r\tMMMMMMMMmMmNì\tMMMMMM­r+VíçoLú\tMM­³c«rïìmLú\t;q4x¢t§pïìlI\tMMMMMM½rlN\tMMMMMM½rlM:LlON\rO\rmMmNmImOúîïoNílMmNÔmM\tڙ\v\v¸C*qï.@MmO:L'oO:S@LFFmL:²JI\rmM:²J]LïmL:²J&]LïBFmL:Ï5I\rmM:Ï5]LïmL:³J']LïBFmMmL]LïF›LOL1L2mL\tMMMMMMMM,I\r\tMMMMMM½rBFmLÐmL,mLÔ\tMMMMMM\r(<I\rmLÔçlN\tMMMMMM½rlON\rmOmMïmOmN:L<VlOmMmMïlMmN:L;oN@MF\tMMMMMM½rmOîmOmL\tMMMMMMMM.VBFmM\tMMMMMMMM,I\r\tMMMMMMMM\tMMMMMM½2mL\tMMMMMMMM)VBFmM\tMMMMMMMM.I\r\tMMMMMMµ2BFmLmM]Oï]NF•OMmL\bI\rmMBFmL:II\rmMÔ\tMMMM_.:mLõî]ImMëBFmL:I\vI\rmMÔ\tn–´3'ñùr.I\rmM\tMMMMMM_\rîBFmMÔ\t¿Ÿ\0/]ôrí\tbiKÌØ¼rî\t?QŠ<QŠL\r]ImMëBFmL:L\vI\rmMÔ\t_Yr‹‘øér(I\rmM\tšî=pGšd\rîBFmMÔ\td¸eárí\t¬7Yã\n¬½rî\t~~~~~~N\r]ImMëBFmL:O\vI\rmM\tüÄDËø´Är]IoM\tMMMMM§òí\tMMMMMMMMè\tMMMMM—\rmM\tMMMMMý\rïìî\tf[ª@QT\r]IBFmM\tMMMMMM­r(I\rmMmMï\tMMMMMME\rîBFmM\tÀ¼\r¥„§¬òí\t@\0L³®‹rî]N\t«Ö(°NuŸrí\tMMMMMMe\rîF§OMmL\bI\rmMBFmL:II\rmMÔmLõ\tMMMM_.:î]ImMëBFmL:I\vI\rmMÔ\tv’ÀÚ#ßr.I\rmM\tMMMMMM_\rïBFmMÔ\t€‘r]I\tbiKÌØ¼rï\t¿Ÿ\0/]ôòímMëBFmL:L\vI\rmMÔ\tTúÊ>Žè$r(I\rmM\tšî=pGšd\rïBFmMÔ\tæççççç—r]I\t¬7Yã\n¬½rï\td¸eáòímMëBFmL:O\vI\rmM\tMMMMMMMMè\tMMMMM)‰r]IoM\tMMMMM—\rï\tMMMMM§rímM\tMMMMMý\rï\tMMMMMM½ríî\tMMMMMû\r]IBFmM\tør(I\rmM\tMMMMMME\rï\tMMMMMMMMèÒBFmM\tMMMMMMe\rï\t«Ö(°NuŸòí]O\t@\0L³®‹rï\tÀ¼\r¥„§¬ríFÏOOO2N3N\rmOmI:N9'mIõmLõîmM]HtNMmI:L'oImL\0@MFmNI\r:MlO:LlIN\rÍÍÍÍÍÍÍ͍MlJN\rmKmJI\rmKmJ1LÅoEòmMmLõ]GmIõ+I\rmElJHmEL1lKFALFFmNmI:L&:N9'\tMMMMMM½2mKòmKòmMmLõ]GmIõ.VtNMmI:L'oImL\0@MFN\rN\rO\rmLmO\0@MmNmO:N9'fNMmHõ\tMMMMMM\rrï)@MmO:L'lOALFFmN:ÍÍO'mH:O9'mO{OMmH:L'oH:Ím\0@MFFFîLMmO\bI\rmMmL'`MMõmNîBFmO:N\vI\rmMmL:O9'gOMöBFmMmL:L9'bLMlMmO:L\vI\rmMõmNîBFmM:²J<lLmM:G;:R<oOI1mO:R\vI1\tMMMMMMµ2\tMMMMMM½2mLVHmL:ÍE'õmO:T&]LïFHmLõ\tMMMMMM=sïFoN×mNmM:ÍÍO<VF€LON2L1mMð}Åê:ÍÍO<lOmM\tMMMMMMMM,I\rmOBFmMÔoMlIN\rmI\tMMMMMMM\r.\bI\rmI\tMMMMMM­rïlImL:L'lLALFFN\rmI\tMMMMMM½r+\bI\rmImIílImL:L&lLALFFmL:?I1:<lLmM\tMMMMMM\rïHmI\tMMMMMM½òíF\tMMMMMMÝ\rïÓæoN:ÍE\vI\r:MlNmL:L'lLFmOmL:B':G9mN??FMmM\tMMMMMM½rïmL]K\tMMMMMM½rï\tMMMMMM½ré\tMMMMMMMMèmOïoMÑ\tMMMMMM½r\tMMMMMMMMmMmMÑì\tMMMMMM­r+VíFËOOK2I1mMmL\0lEN\rmEI\r:O:LmM:L&õmHõ\tMMMMMM­rímMõïmLõî\tMMMMMM­òíé\tMMMMMMMMèoGÑæoI:L'mMVmI'lJ\tMMMMMM½rmGmIõìo@ìlFHmHõmMõïmLõîoGÑælImH:L'õmMõïmLõîoAÖælJFmOmH:A!'oDmI{OMmDmJmI&{OImDmK{OEN\rmNmK:N9'mEI1mFHmAmI:L'õémGmIõèìmAmGìîFtNMmK:L'lKm@lFmJmI:L'oI@MFmH:L'oHmL@MFmKF¸YN_2J1N6mI:I:NmG:N\vV:OmGV9ldmK:I:NmG:N\vV:OmGV9lgmZmU:N!'limK:O9lj:2lh:2lkmHmJ\0lemEloN\rmNmEmo\v<\bI\rmi:Mmj:N9±FMFmOmeI2mH:L&õmoõ\tMMMMMM­rímHõïmJõî\tMMMMMM­òíé\tMMMMMMMMèobÑælmmbmmõìlbmHmm:O'mHmm:O'VHmoõmHõïmJõîo}Ñælmmo:L'õmHõïmJõîo|ÖæFonmOmnVmLmmmLmmVoRI\rN\rmeI1\tMMMMMM½rmbìmbmRmm\vVHm|mR:L'õém}mRõèìm|m}ìîFoc\tMMMMMMMM/I\rmRmh\vI\r:MllHmRmk\vI\r:LllHmhmkllO2mMmRmL&md!'lS:MlPmG\bmC\tMMMMMM½r,<m_:M\n<I\rmFælQN\r\tMMMMMM½rmSmP:O9'eOMoV:U;õmFîmV:U;mQ\vVl`mZmP:H9'oWm_mV:²L<:N9'fNMm`ïtNMmWm_mV:E;:²L<:N9'fNMm`ïtNEmWm_mV:];:²L<:N9'fNMm`ïtN]mWm`tNUmP:L'oPmI@MF:MALFm_I\rN\rmZmP:H9'lWmSmP:O9oV:N'mGmF]El`:MlQN\rmWmQ:N9'm_mGI2mSmVmQ':L9'bLMHmSmVmQ''`MMF:N9'fNMtNMmQ:L'oQ:N@MF\tMMMMMM½rlamC\tMMMMMM½r/I\rmWfNMmBï\tMMMMMMMMímWfNEm]ïímWfN]m\\ïíoamC\tMMMMMM½òí]I\tMMMMMMMMma\tMMMMMMMM)VlaFmWmWfNMmaïm`ïtNMmWmWfNEmaïm`ïtNEmWmWfN]maïm`ïtN]mWm`tNUmP:L'oPmI@MF:MALFN\rmZmP:H9'lW:LmSmP:O9oV:N'mGmF]Eo`\tMMMMMM½r(m`\tMMMMMMMM+<\b@LW:MlQN\r:OmSmVmQ'mGmF]EoaÔ\tMMMMMM½2.\b@OWm@I\rmam`î\tMMMMMMMMm`\tMMMMMMMM/VlaF:Nma\tMMMMMMMM.ma\tMMMMMM½r)?mA:O\v<@OW:ImA:N\vma\tMMMMMMMM.<@OWmWmQ:N9'm_I1m_mGI2mSmVmQ':L9'bLMHmSmVmQ''`MMF:N9'fNMHmamA]HFtNMmQ:L'oQ:N@MF\tMMMMMM½rlamC\tMMMMMM½r/I\rmWfNMmBï\tMMMMMMMMímWfNEm]ïímWfN]m\\ïíoamC\tMMMMMM½òí]I\tMMMMMMMMma\tMMMMMMMM)VlaF:MlQN\rmWmQ:N9'oVmVfNMmaïm`ïtNMmQ:L'oQ:N@MFmWm`tNUmP:L'oPmI@MF:MFoWI\rmWBFmZmUml:L'!'lf:MlVN\rmXmV:A!'oWeOMlQmQmWeOI'lSmWeOElP°AMMMMMMMMMMMMMMMMly°AMMMMMMMMMMMMMMMMl~N\rm[mP:N9'fNMoa\tMMMMMMMM/I\rmymZmQ:H9'oW°MIMma°Yox°¿L°½Llym~mW°MI]mx°¿L°½Ll~FmP:L'lPmSmQ:L'oQ@MFmfmV:H9'oWmy°FIMmWm~°FI]mV:L'oVmK@MFmlI\rmRlkHmRlhFFFmZmUml:L'!'lV:MlWmc°Yl~N\rmWmi'oQmQ°MIMmWmV'°MIMm~°¿L°½L°FIMmW:]'oWmj:N9@MFFmR:L'oRmOmnmOmnV@MFFmOmnI\r:MBFO2mTmomE&mg!'lP:MlmN\rmimm:H9'oSfNU\tMMMMMM½ré\tMMMMMMMMèl`mG:OI2m`mFï\tMMMMMM­r.HmG:O\vI2m`]D\bHm`ûMMMMFFll:MlVN\rmSmV:N9'oWmWfNMm`î\tMMMMMMMMm`\tMMMMMMMM/VtNMmV:L'oV:N@MF\tMMMMMM½rlcmC\tMMMMMM½r/I\rmSfNMmBï\tMMMMMMMMímSfNEm]ïímSfN]m\\ïíoa\tMMMMMM½rmCî\tMMMMMM½òí]I\tMMMMMMMMma\tMMMMMMMM)VlcF:MlVN\rmY:M\nmV:N<I\rmSmV:N9'fNMoa\tMMMMMMM\r.ma\tMMMMMMMM+<I\rmYma\tMMMMMM­\rïæ:L9'bLMoRI\rmm:O9mV'lW\tMMMMMMMMmR:L&õmlVlamGI\rmPmW:L9'maævLMHmWmP'maæwMMFmV:L'lVANFFFm^:M\nmV:N<mSmV:N9'fNMoa\tMMMMMMM\r(ma\tMMMMMMMM+<<I\rmFæW:²Rma\tMMMMMMí\rïæma\tMMMMMMM\r+V:O9oWm^:ÍÍO''eOMlQm^:ÍÍO'mW'eOIlWN\rmWmQI\rm^mWmQ':L;oR:N9'fNMma(I\rmR:L'lQHmRlWFALFFmQ\bma\tMMMMMM=pïomam^mQ:L&:N9'fNMì.?mQmFæm^mQ:N9'fNMmaìm)?<I\rmm:O9mV'lW\tMMMMMMMMmQõmlVlamGI\rmPmW:L9'maævLMHmWmP'maæwMMFmV:L'lVAOFF:H\tMMMMMMMMmV:N\vI1m`HmSmV:N9'fNMmcïmA]Km`\tMMMMMM½rm@VïFmV:Nml<VoaÔ\tMMMMMM½2.\b@OWmm:O9mV'lWmG:OI\rma\tMMMMMM½ré\tMMMMMMMMèmFïoaÑ\tMMMMMM½r\tMMMMMMMMmamaÑì\tMMMMMM­r+VílamGI\rmPmW:L9'maævLMHmWmP'maæwMMFHmG:O\vI\r:HmaÔ\tMMMMM³¢\r+@IWmPmW:L9'ma]DvLMH:HmaÔ\tMMM­²²¢\n)@IWmPmW:O9'maûuOMFFmV:L'oV:I@MFmm:L'ommK@MF:MFoWI\rmWBFmo:L'oomD@MF:MFàLOO2N1N\rmIõ\tMMMMMMMrïlHmI:L'õ\tMMMMMMMrïoJ\tMMMMMM=pïlKN\rO\rmLmN\0@MmMmN:N9'fNMmH)@MmN:L'lNALFFmOmI:L9'mN:L':MmLmN\0mMmN:N9'fNMmJìmK)?mN\bmHmMmN:L&:N9'fNMìmK)?<VvLMmI:L'oI:ÍÍI@MFF½NLH2mM\bI\rmOmLmI±GMMBFmM:O\vI\rmI:=<lMN\rmMmK\0\bI\rmOmK'mLmK'°MIMmNmK'°MIM°#°FIMmK:]'lKALFFN\rmImK\0\bI\rmOmK'mLmK'`MMmNmK'`MM'wMMmK:L'lKALFFBFmHmImImHVlEN\rmKmE\bI\rmOmK'mLmK'`MMmNmK'`MMoJ:L;mJmM:N\vV:MmM:L\nV'wMMmK:L'lKALFFmM:L\vI\rN\rmImK\0\bI\rmOmK'mLmK'`MMmOmK'mH&`MM'wMMmK:L'lKALFFBFmM:N\vI\rN\rmImK\0\bI\rmOmK'mLmK'`MMmOmK'mH&`MMmNmK'`MM':L;'wMMmK:L'lKALFFBFN\rmImK\0\bI\rmNmK'`MMoJmNmK'mH&`MMoD&oM:MmM&mM:MVlMmOmK'mH&`MMoGmD&oE:MmE&mE:MVlEmOmK'mLmK'`MMmGmJmDmJmG'mD:L9&oJ:MmJ&mJ:MVoJmEVmMmE\0mMmJ\0<V'wMMmK:L'lKALFFF·LLO2mO:N\vI\rmL:H&:MmL:HVlHN\rmImH\bI\rmNmI:O9'mMmI:N!'°MIM°AMLOÍNIHÍKJEÍDGFͰC°AMMM²MMM²MMM²MMM²°°FIMmI:I'lIALFFFN\rmLmII\rmO:N\vI\rmNmI:O9'mMmI:N!'`MMmMmI:N!'`ML:E9mMmI:N!'`MO:]9??:ÍÍÍ5?{OMHmNmI:O9'mMmOmI!'`MM:ÌÏI!:²LmMmI:L9'`MLmO:O\nV:U9?{OMFmI:L'lIALFFF",Jn=e=>{try{return WebAssembly.validate(e)}catch{return!1}},_n=()=>"object"==typeof WebAssembly&&1===new Uint8Array(new Uint32Array([1]).buffer)[0]&&(Nn("kernels")||Jn(gn('M,> LMMMLHL-ML2NOLMJDLH=?"/(MMGFLDM:M°\\°VMF'))),Bn=null,Rn=null,Xn=[],Dn=[1];for(let e=1;e<=32;e++)Dn.push(2*Dn[e-1]);new Uint8Array(Uint32Array.of(1).buffer)[0];var Cn=class{constructor(e=4096,t=1/0){if(t!==1/0&&(!Number.isSafeInteger(t)||t<0))throw Vr("JXL_INTERNAL","bits:maxBytes");this.bytes=new Uint8Array(t===1/0?e:Math.min(e,t)),this.maxBytes=t,this.at=0,this.acc=0,this.pending=0}write(e,t){if(!(t>=0&&t<Dn[e]))throw Vr("JXL_INTERNAL","bits:write "+e+" "+t);let r=this.pending+e;this.at+5>=this.bytes.length&&this.grow();let n=this.bytes;if(r<32){let e=this.acc|t<<this.pending;for(;r>=8;)n[this.at++]=255&e,e>>>=8,r-=8;return this.acc=e,void(this.pending=r)}let a=this.acc+t*(1<<this.pending);for(;r>=8;)n[this.at++]=255&a,a=Math.floor(a/256),r-=8;this.acc=a,this.pending=r}writeU32(e,t){for(let r=0;r<4;r++){let[n,a]=e[r];if(t>=a&&t-a<Dn[n])return this.write(2,r),void(n&&this.write(n,t-a))}throw Vr("JXL_INTERNAL","bits:u32 "+t)}zeroPadToByte(){this.pending&&(this.at+1>=this.bytes.length&&this.grow(),this.bytes[this.at++]=this.acc,this.acc=0,this.pending=0)}get bitLength(){return 8*this.at+this.pending}grow(e=0){let t=this.at+e+16;if(!Number.isSafeInteger(t)||t<0)throw Vr("JXL_INTERNAL","bits:alloc");if(t>this.maxBytes)throw Object.assign(new RangeError("output: over maxBytes"),{code:"JXL_MEMORY"});let r,n=Math.min(this.maxBytes,Math.max(2*this.bytes.length,t));try{r=new Uint8Array(n)}catch(e){if(!Yr(e)||n===t)throw e;r=new Uint8Array(t)}r.set(this.bytes.subarray(0,this.at)),this.bytes=r}append(e){if(this.at+e.at+8>=this.bytes.length&&this.grow(e.at+8),this.pending){let t=this.bytes,r=e.bytes,n=this.pending,a=e.at,i=this.acc,l=this.at;for(let e=0;e<a;e++){let a=i|r[e]<<n;t[l++]=255&a,i=a>>>8}this.at=l,this.acc=i}else this.bytes.set(e.bytes.subarray(0,e.at),this.at),this.at+=e.at;e.pending&&this.write(e.pending,e.acc)}finish(){let e=this.at+(this.pending?1:0),t=this.bytes.slice(0,e);return this.pending&&(t[this.at]=this.acc),t}},Gn=(Float32Array.from(atob("PNS2d2Sr7wN9L8AkeT6HmjZ/vPBCry1jIsNOM+lnnAGpI1DdNiZLlNwU+0df8hNT59coigfGVOW1DniuFITA/32V6gaK+sNwXKaIzAm6pmges1qlaP0YkHA68F/KRCtYEr1DYbCdDj/stjZulN4vzneSEeI3gaBGzd+jBZfcc+Q1bfLHHVZ7zioXVOkhfk7rO/lHynW52QtaJ4pN9R+3jtCkKIHZMuSjj2XYm0KyBIsZvpsAUSIx9ny/GmywPGMK+VMVk2e4SwH0gr4R/WHEpFdtLN3tsZJjqOI1yH/VnUmFruJBDP52xSBFrDDLcyTv2oCrXolu0hZAmFL7ECzowwRgc8qaqFk43V5wClGEmDRED/YbOEkIu+pyA6qNWXcgOdgv7hwrh7OV7dGi9uEW0mm3zZTFo/1YhiXaZe5Cupf0tIxIv23nCBl8KY47uUqniwdVdCXgfDDNtTrEohjOaRGhWgZ+2k/JQrtWHWoCeln8LeY/sBOaahuQTAuBKeBOeSPU+Kw2m/tnp/DbrcbqIcCeg9ViUOxDqvfjc1f/rYnpvD5qFWAjjRMzhUiZMGLZO20Y848BvtoNX58xxpMCNMlSmIXP7LV208IJcfgUgpIMqkq4MspxiCt90h+wY0RvGd8JLaVFAOFNXeUkzEG2T/XRXXsioT3xVLxG9BLW7p5dsnb0v1iVKoGgso9Xpd51KsIG4P5nFbGWBmyKOni5J/pHkRw3b8jxPRr/OGsD7hyciTmok0bV4yXIp+iZVQiIM9Fk54PXDqxpvQzXfy69XkVu6FQPg1p1NPhcGizM46kNxKASt0wjjN54SJfrr4vN+xfHLtCtwAmOTYDdvmZAfVJxJj/8p2L1VSzRYSBPPQ2ierNk7yA/6py3PQR0ox/xsYncW5V6MQOetBDBpHTk2SdNjwKZfmvXFGXPrP5LlNYBMOu7DNPB5UOE7Tf5BYVouPM+3jT6T6Uu8SKLMhPBYfedSWwdPJBwyxdokVbHL5tbEMJyXbwLh8V4UeBc6YM7dxfIrYbyWCamTHzfG7JG1B6Az58aqybnQ5cPu2+gJM9mkeMpUNu2Ev7VuCmhcuaM/K4tR+KN025f96k+zAuuVboIOH6hBWaaNWAAQfNiCjlTbATveTlOswAf1n8qS/zYRO1g0PlFxnmI6MKWgssVpL/YllnHEf2ZxDeOZfCWhx2omCGvchbfKEypHlYytOx7JUGGtSFphCjrduFTBcU1cdyAwVcxkLn1Ds51+NtJkVvhEPYz5qa9XEiqFrqi5F4PLkr3CuZAW5xqOo0HZhkrb6vJnXRQDds8B9BrJ0B6sfKMaxify4Ie07RS5Z+v1MP/AkpkG9KTe/OehvqS1hxRyQ=="),e=>Math.round(13125*(2*e.charCodeAt(0)-255)/68)/1e5),Symbol.for("rapier-jxl.decoder")),Wn=()=>globalThis[Gn]??null,Vn=Symbol.for("rapier-jxl.decoder.snapshot"),Kn=[];for(let e=2;Kn.length<64;e++)Kn.every(t=>e%t)&&Kn.push(e);var zn=Kn.slice(0,8).map(e=>e**.5%1*2**32|0),Hn=Int32Array.from(Kn,e=>Math.cbrt(e)%1*2**32|0),Yn=new Int32Array(64),qn=()=>({h:[...zn],length:0,tail:[]}),$n=1<<20,Qn=2**32,Zn=new TextEncoder,ea=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),ta=Object.getPrototypeOf(Uint8Array.prototype),ra=Object.getOwnPropertyDescriptor(ta,"byteLength").get,na=Object.getOwnPropertyDescriptor(ta,"byteOffset").get,aa=Object.getOwnPropertyDescriptor(ta,"buffer").get,ia=Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get,la=e=>Vr("JXL_INPUT",e),oa=/^[ !#-[\]-~]*$/,sa=8388608,ua=e=>{throw Vr("JXL_INPUT",e)},ca=1048576,fa=ca,ha=16384,da=/^[a-f0-9]{64}$/,ma=4*ca,pa=e=>((!Array.isArray(e)||e.length>64||e.reduce((e,t)=>e+va(t).length,0)>sa)&&ya("checkpoint reads: <=64, <=8 MiB"),e),ya=e=>{throw Vr("JXL_INPUT",e)},ga=e=>{throw Vr("JXL_INPUT",e)},Ma=e=>T(S(e)),ba=(e,t)=>{let r=S(e),n=S(t);return r.length===n.length&&r.every((e,t)=>e===n[t])},wa=e=>{let t=262144;for(;Math.ceil(e/t)>64;)t*=2;return t},La=e=>Math.max(fa,wa(e)),Aa=e=>{if(e?.aborted)throw zr(e)},va=e=>((!e||!da.test(e.hash)||!Number.isSafeInteger(e.length)||e.length<0||e.length>ca||2!==Object.keys(e).length)&&ya("part reference: hash, length"),e),Ia=e=>{let t=Ma(e);if(!t||"object"!=typeof t||Array.isArray(t)||!da.test(t.sha256)||"string"!=typeof t.generation||!t.generation.length||t.generation.length>256||!Number.isSafeInteger(t.byteLength)||t.byteLength<1||t.byteLength>4294967295)throw Vr("JXL_INPUT","source: generation, sha256(64 lowercase hex), byteLength(1-4294967295)");return t},xa=e=>{if(!e||"object"!=typeof e||Array.isArray(e)||Object.keys(e).some(e=>"units"!==e)||!Number.isSafeInteger(e.units)||e.units<1||e.units>64)throw Vr("JXL_INPUT","budget: {units: 1-64}");return{units:e.units}},Na=Symbol.for("rapier-jxl.journal.saved"),Oa=Symbol.for("rapier-jxl.journal.unread"),Pa=Symbol.for("rapier-jxl.journal"),Ua=Symbol.for("rapier-jxl.journal.file"),Sa=Symbol.for("rapier-jxl.journal.join"),ja=Symbol.for("rapier-jxl.journal.facts"),Ea=e=>"symbol"==typeof e&&Symbol.keyFor(e)?.startsWith("rapier-jxl.journal"),Ta=(e,t,r)=>new Proxy(new Uint8Array(0),{get:(n,a)=>Object.hasOwn(e,a)?e[a]:a===Symbol.toStringTag?"Uint8Array":Ea(a)?void 0:r&&"string"==typeof a&&/^(0|[1-9]\d*)$/.test(a)?r(Number(a)):(e=>"function"==typeof e?e.bind(t()):e)(Reflect.get(t(),a)),getPrototypeOf:()=>Uint8Array.prototype,has:(e,r)=>Reflect.has(t(),r),ownKeys:()=>Reflect.ownKeys(t()),getOwnPropertyDescriptor:(e,r)=>Reflect.getOwnPropertyDescriptor(t(),r),set:(e,r,n)=>Reflect.set(t(),r,n)}),Fa=(e,t)=>{let r,n=-1;return a=>{if(!(a>=e))return(!r||a<n||a>=n+r.length)&&(n=65536*Math.floor(a/65536),r=t(n,Math.min(e,n+65536))),r[a-n]}},ka=(e,t)=>null!==e&&"object"==typeof e&&!0!==e[Oa]?e[t]:void 0,Ja=e=>null!==e&&"object"==typeof e&&(Object.hasOwn(e,"unit")||Object.hasOwn(e,"unitDone")||Object.hasOwn(e,"unitFailed")),_a=Symbol.for("rapier-jxl.journal.active"),Ba=e=>globalThis[_a].join(e),Ra=e=>globalThis[_a].tools[e],Xa=e=>({plain:!0,*step(t,r,n,a){if(e.aborted)throw e.reason;return 2===a?yield*r():r()}}),Da=Symbol.for("rapier-jxl.journal.passed"),Ca=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Float16Array"],Ga=Object.getPrototypeOf(Uint8Array.prototype),Wa=e=>Vr("JXL_INPUT",e),Va=Symbol.for("rapier-jxl.journal.span"),Ka=Symbol.for("rapier-jxl.journal.slice"),za=e=>null!==e&&"object"==typeof e?e[Va]:void 0,Ha=(e,t,r,n)=>Object.freeze({type:e,ref:Object.freeze([...t]),offset:r,length:n}),Ya=(()=>{class e extends Error{get[Oa](){return!0}}return e})(),qa=Sa,$a=e=>($(e.map(e=>()=>e?.[qa])),e),Qa=e=>!0===e?.[Oa],Za=Symbol.for("rapier-jxl.journal.tiles"),ei=e=>za(e)?.ref[0],ti=e=>{throw Vr("JXL_INPUT",e)},ri=Object.freeze(new Error("attempt ended")),ni=e=>void 0!==e?.unit||void 0!==e?.unitDone||void 0!==e?.unitFailed,ai=()=>performance.now(),ii=Symbol.for("rapier-jxl.journal.observe"),li=524288,oi=4194304,si=e=>e&&"object"==typeof e&&void 0===e.t?Array.isArray(e.a)?"a":Array.isArray(e.o)?"o":Array.isArray(e.m)?"m":Array.isArray(e.s)?"s":void 0:void 0,ui=new WeakMap,ci=e=>((!Array.isArray(e.bytes)||e.bytes.some(e=>!Array.isArray(e)||3!==e.length||!Number.isSafeInteger(e[1])||!Number.isSafeInteger(e[2])||e[1]<0||e[2]<0||e[1]+e[2]>ca))&&ti("invalid journal pages"),e.bytes),fi=e=>{(!Number.isSafeInteger(e.length)||e.length<0||ci(e).reduce((e,t)=>e+t[2],0)!==e.length||!e.length&&e.bytes.length)&&ti("journal value length")},hi=class e{constructor(e,t=e.reduce((e,t)=>e+t.length,0)){this.spans=e,this.length=t}#e(e,t){let r=[],n=0;for(let a of this.spans){let i=n+a.length;if(i>e&&n<t&&r.push(a.subarray(Math.max(e-n,0),Math.min(t,i)-n)),n=i,n>=t)break}return r}subarray(t,r=this.length){let n=this.#e(t,r);return 1===n.length?n[0]:n.length?new e(n,r-t):new Uint8Array(0)}slice(e,t=this.length){let r=new Uint8Array(t-e),n=0;for(let a of this.#e(e,t))r.set(a,n),n+=a.length;return r}},di=Math.log,mi=(e,t)=>e<=0?0:1===t?e:Math.pow(e,t),pi=(e,t)=>e.getInt32(t)/65536,yi=e=>t=>String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3)),gi=e=>[e[0][0],e[1][0],e[2][0],e[0][1],e[1][1],e[2][1],e[0][2],e[1][2],e[2][2]],Mi=e=>{try{return e()}catch(e){if(Qa(e))throw e;return null}},bi=[.9642,1,.8249],wi=[.8951,.2664,-.1614,-.7502,1.7135,.0367,.0389,-.0685,1.0296],Li=(e,[t,r,n])=>[e[0]*t+e[1]*r+e[2]*n,e[3]*t+e[4]*r+e[5]*n,e[6]*t+e[7]*r+e[8]*n],Ai=([e,t,r])=>[e/(e+t+r),t/(e+t+r)],vi=([e,t])=>[e/t,1,(1-e-t)/t],Ii=[[1,[.3127,.329]],[10,[1/3,1/3]],[11,[.314,.351]]],xi=[[1,[[.64,.33],[.3,.6],[.15,.06]]],[9,[[.708,.292],[.17,.797],[.131,.046]]],[11,[[.68,.32],[.265,.69],[.15,.06]]]],Ni=(e,t)=>Math.abs(e[0]-t[0])<.001&&Math.abs(e[1]-t[1])<.001,Oi=e=>e.map(e=>Math.round(1e6*e)/1e6),Pi=[[1,e=>e<.081?e/4.5:mi((e+.099)/1.099,1/.45)],[8,e=>e],[13,e=>e<=.04045?e/12.92:mi((e+.055)/1.055,2.4)],[17,e=>mi(e,2.6)]],Ui=(e,t)=>{for(let r=0;r<=255;r++){let n=r/255,a=e(n),i=0,l=1;for(let e=0;e<24;e++){let e=(i+l)/2;t(e)<a?i=e:l=e}if(255*Math.abs(i-n)>.5)return!1}return!0},Si=["perceptual","relative","saturation","absolute"],ji={1:"d65",10:"e",11:"dci"},Ei={1:"srgb",11:"display-p3",9:"rec2020"},Ti={1:"bt709",8:"linear",13:"srgb",17:"dci"},Fi=function(e){let t=Oe(e);return!t||t.gray?null:{space:"rgb",whitePoint:ji[t.white.enum]??t.white.xy,primaries:Ei[t.primaries.enum]??t.primaries.xy,...void 0!==t.gamma?{gamma:t.gamma}:{transferFunction:Ti[t.transfer]},renderingIntent:Si[t.intent]}},ki=function(e,{lossy:t=!1}={}){e=Pe(e,t);let r=e?.colorEncoding;if(!r||"rgb"!==r.space&&"gray"!==r.space||"srgb"!==r.transferFunction||void 0!==r.gamma)return[e,void 0];let n=Object.keys(r).every(e=>["space","transferFunction","renderingIntent"].includes(e))?"srgb":t&&"rgb"===r.space&&"d65"===(r.whitePoint??"d65")&&Object.keys(r).every(e=>["space","whitePoint","primaries","transferFunction","renderingIntent"].includes(e))?{srgb:"srgb","display-p3":"display-p3"}[r.primaries??"srgb"]:void 0;if(!n)return[e,void 0];let{colorEncoding:a,...i}=e;return[{...i,colorSpace:n,transferFunction:"srgb"},"number"==typeof r.renderingIntent?Si[r.renderingIntent]:r.renderingIntent]},Ji=({colorSpace:e,renderingIntent:t})=>void 0!==t&&1!==t?{colorEncoding:{space:"rgb",whitePoint:"d65",primaries:e??"srgb",transferFunction:"srgb",renderingIntent:t}}:e?{colorSpace:e}:{},_i=e=>e&&"object"==typeof e&&!Array.isArray(e),Bi=e=>JSON.stringify(e,(e,t)=>void 0===t?null:_i(t)?Object.fromEntries(Object.keys(t).sort().map(e=>[e,t[e]])):t),Ri=async(e,t)=>{let r=await t;if(!r.facts.record)return r;let{source:n,...a}=r.facts.record;return{...r,facts:{...r.facts,record:e?{...a,source:{kind:"bytes",digest:e}}:a}}},Xi=({source:e,...t})=>t,Di=(e,t,r)=>"file"===(t.kind??"pixels")?r?{[Ua]:e}:new Blob([e]):{data:e,width:t.width,height:t.height,...Ji(t)},Ci=65536,Gi=1048576,Wi=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array"],Vi=new Set(["coeffs","levels"]),Ki="rapier-jxl.band-summary.1",zi=Object.getPrototypeOf(Uint8Array.prototype),Hi=e=>ArrayBuffer.isView(e)&&Object.getPrototypeOf(Object.getPrototypeOf(e))===zi&&Wi.includes(e.constructor.name),Yi=e=>Array.isArray(e)&&e.length>0&&e.length<=4&&e.every(e=>Hi(e)&&1===e.length),qi=Object.freeze({save:function(e,t=null){let r=e?.strategyData;if(!r&&Array.isArray(e?.components)){let r=e.components.map(Xe);return r.includes(null)?e:{[Ki]:"plain",band:{...e,components:r},extra:t}}if(!r||!Array.isArray(r.blocks)||!Array.isArray(r.groups))return e;let n=new Map(r.blocks.map((e,t)=>[e,t]));if(n.size!==r.blocks.length)return e;let a=[],i=[];for(let t=0;t<r.groups.length;t++){if(!(t in r.groups)){a.push(-1);continue}let l=r.groups[t];if(!Array.isArray(l))return e;a.push(l.length);for(let t=0;t<l.length;t++){let r=n.get(l[t]);if(!(t in l)||void 0===r)return e;i.push(r)}}let l=Be(r.blocks);return l?{[Ki]:!0,band:{...e,strategyData:{...r,blocks:null,groups:null}},keys:Object.keys(r),blocks:l,groupCount:r.groups.length,lengths:Int32Array.from(a),members:Int32Array.from(i),extra:t}:e},answer:function(e){if(!e?.[Ki])return e;if("plain"===e[Ki])return Object.defineProperties({...e.band},{answered:{value:!0},extra:{value:e.extra}});let t=null,r=null,n=()=>t??=Re(e.blocks),a=()=>{if(r)return r;n(),r=new Array(e.groupCount);for(let n=0,a=0;n<e.groupCount;n++){let i=e.lengths[n];i<0||(r[n]=Array.from({length:i},(r,n)=>t[e.members[a+n]]),a+=i)}return r},i=e.band.strategyData,l={};for(let o of e.keys)"groups"===o?Object.defineProperty(l,o,{get:a,set:e=>{r=e},enumerable:!0,configurable:!0}):"blocks"===o?Object.defineProperty(l,o,{get:n,set:e=>{t=e},enumerable:!0,configurable:!0}):l[o]=i[o];return Object.defineProperties({...e.band,strategyData:l},{summary:{value:!0},extra:{value:e.extra},frameBlocks:{value:(t,r)=>Re(e.blocks,(e,n)=>(e.by+=t,Object.defineProperty(e,"coeffs",{get:()=>r(n),enumerable:!0,configurable:!0})))}})}}),$i=(e,t)=>q(e,"settle-band",t),Qi=Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get,Zi=Object.getPrototypeOf(Uint8Array.prototype),el=Object.fromEntries(["buffer","byteOffset","byteLength"].map(e=>[e,Object.getOwnPropertyDescriptor(Zi,e).get])),tl=Object.getOwnPropertyDescriptor(Zi,Symbol.toStringTag).get,rl=e=>{throw Vr("JXL_INPUT",e)},nl=()=>rl("PNG deflate: invalid"),al=()=>rl("PNG dimensions: exceeded"),il=32,ll=1024,ol=32768,sl=Array.from({length:29},(e,t)=>t<8||28===t?0:t-4>>2),ul=Array.from({length:30},(e,t)=>t<4?0:t-2>>1),cl=(e,t)=>e.map((r,n)=>t+=n&&1<<e[n-1]),fl=cl(sl,3),hl=cl(ul,1);fl[28]=258;var dl=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],ml=null,pl=()=>ml??={lit:Ve(Uint8Array.from({length:288},(e,t)=>t<144?8:t<256?9:t<280?7:8),!0),dist:Ve(new Uint8Array(32).fill(5),!0)},yl=(e,t)=>({lit:Ve(e.subarray(0,t),!0),dist:Ve(e.subarray(t),!0)}),gl=8192,Ml=e=>({bytes:e.bytes.subarray(0,e.at),at:e.at,acc:e.acc,pending:e.pending,bitLength:8*e.at+e.pending}),bl=(e,t)=>e===Da?t:e,wl=e=>({remaining:e.remaining,state:e.state,position:e.position,left:e.left,distance:e.distance,history:e.history?.slice(0,Math.min(e.position,e.history.length))??null}),Ll=rt("decode-icc-profile"),Al=nt("decode-brotli","decode-brotli","decode-brotli-trees"),vl=nt("brotli","brotli-read","brotli-models"),Il=Object.freeze({openImage:function*(e,t,r){return yield*z("decode-open",function*(){let n=yield*tt(e,t,r),a=yield*V("decode-image-header",()=>{let e=new r.JxlBits(ae(n.codestream,0),!0),a=r.readDecodeImageHeader(e,t);return a.level=n.container?.level??5,{h:a,bit:e.bit}}),i=a.h,l=new r.JxlBits(ae(n.codestream,0),!0);if(l.bit=a.bit,i.colorEncoding.wantICC){let e=n.container?.level??5,a=Math.min(t.maxMetadataBytes,268435456),o=yield*r.part("icc").readICCSteps(l,{maxBytes:a,maxProfileBytes:r.iccProfileLimit(e,a)});i={...i,icc:o},yield*r.admitDecodedICCSteps(o,i,e)}let o=yield*V("decode-image-align",()=>(l.align(),l.bit)),s=yield*V("decode-first-frame",()=>{l.bit=o;let e=i.preview?null:r.readDecodeFrameHeader(l,i,t);return e&&r.readDecodeTOC(l,e),e?.modular?e.groupDim:256});return{input:n,h:i,bit:o,group:s}})},readEntropyModel:function*(e,t,r,n){let a=yield*z("decode-entropy-model",function*(){let a=yield*V("decode-entropy-header",()=>n.header(e,t,r));e.bit=a.bit;let i=[];for(let t=0;t<a.model.configs.length;t++){let r=yield*V("decode-entropy-code",()=>({code:n.code(e,a,t),bit:e.bit}));i.push(r.code),e.bit=r.bit}return{model:{...a.model,codes:i},bit:e.bit}});return e.bit=a.bit,a.model},readICC:function*(e,{maxBytes:t,maxProfileBytes:r},n){let a=yield*z("decode-icc",function*(){let a=yield*V("decode-icc-length",()=>n.length(e,t,r));e.bit=a.bit;let i=yield*n.model(e,41),l=n.stream(e,i,{values:a.size,byteHistory:!0}),o=yield*V("decode-icc-prefix",()=>n.prefix(e,l,a,r));e.bit=o.bit;let s=[o.bytes];for(let t=o.bytes.length;;t+=65536){let r=yield*K("decode-icc-state",()=>null,()=>wl(l),!0);if(null!==r&&r!==Da&&et(l,r),t>=a.size)break;o=yield*V("decode-icc-values",()=>n.part(e,l,t,Math.min(65536,a.size-t),o,a.start)),e.bit=o.bit,s.push(o.bytes)}return yield*V("decode-icc-end",()=>(l.finish(),null)),{bytes:yield*n.decode(Ba(s),{maxBytes:r}),bit:e.bit}});return e.bit=a.bit,a.bytes},decodeICC:Ll,admitDecodedICC:function*(e,t,r,n){let a,i=yield*V("decode-icc-space",()=>n.cmyk(e));try{a=yield*n.inspect(e,r,i?"cmyk":void 0)}catch(e){if(e?.[Symbol.for("rapier-jxl.journal.unread")])throw e;n.require(!1,e.message)}yield*V("decode-icc-channels",()=>(n.channels(a,i,t,r),null))},decodeBrotli:Al,readBrotli:vl}),xl=rt("icc-profile"),Nl=Object.freeze({"band-summary":qi,settleFacts:async function(e,t,r,n,a,i=2097152){let l,{shapeScan:o,shapeScanPixels:s,shapeScanNext:u,shapeResult:c,gradientRows:f,flatSampleAt:h,flatSampleY:d,photoPreferenceDifference:m}=t,p=Math.max(2,Math.floor(i/(4*n))),y=Math.ceil(a/p),g=n*a,M=ka(r,ja);if(M?.scans?.[0]&&M.flats&&M.gradient&&"function"==typeof M.preference){let t=structuredClone(M.scans[0]);for(;u(t)<g;){let i=Math.floor(u(t)/n/p)*p,l=Math.min(a,i+p),o=await $i(e,()=>{let e=structuredClone(t);return s(e,r.subarray(i*n*4,l*n*4),i*n,(l-i)*n),e});o!==Da&&(t=o)}l={shape:t,gradient:M.gradient,flats:M.flats,xyb:M.preference()}}else{l={shape:o(g),gradient:{sum:0,n:0},flats:new Uint8Array(256),xyb:0,swept:0};let t=(e,t)=>{let i=structuredClone(e),l=t*p,o=Math.min(a,l+p),c=r.subarray(l*n*4,Math.min(a,o+1)*n*4);if(i.swept===t){if(f(i.gradient,c,n,a,l,o,{row0:l}),n>=32&&a>=32)for(let e=0;e<256;e++){let t=d(a,e);t>=l&&t<o&&(i.flats[e]=h(c,n,a,e,n,0,0,l))}i.xyb+=m(c,n,a,l,o,l),i.swept++}return Math.floor(u(i.shape)/n)>=l&&Math.floor(u(i.shape)/n)<o&&s(i.shape,c,l*n,(o-l)*n),i};for(;;){let r=u(l.shape),a=l.swept<y?l.swept:r<g?Math.floor(r/n/p):-1;if(a<0)break;let i=await $i(e,()=>t(l,a));i!==Da&&(l=i)}}let b=c(l.shape),w=l.gradient,L=n>=32&&a>=32&&t.screenFromFlags(l.flats),A=w.n?w.chroma/w.n:0,v=b.palette?.colours.length??null,I=!L&&A<2&&Math.min(n,a)>=128&&(v??0)>64;return{eligible:!0,width:n,height:a,pixels:g,shorterSide:Math.min(n,a),gradient:w.n?w.sum/w.n:0,blocks:t.blockFacts(w),visibleShare:w.n?1-(w.clear??0)/w.n:1,smooth:t.exactlyPredicted(w),soft:t.softEdges(w),chroma:A,palette:!!b.palette&&!I,paletteSlots:v,alpha:b.alpha,screenLike:L,preferXYB:Math.min(n,a)<128||l.xyb<=0}},pngPixels:async function(e,t,{readAs:r,deep:n=!0,orient:a=!1,metadata:i=!1,reader:{pngWalk:l,pngLayout:o,pngRows:s,pngPassRows:u,pngOrientationLocation:c,unfilterRow:f,smoothProbes:h,smoothProbe:d,grainSteps:m,grainRow:p,grainShares:y,gradientRows:g,shapeScan:M,shapeScanPixels:b,flatSampleX:w,flatSampleY:L,rankingPositions:A,photoPreferenceDifference:v}}={}){if(void 0!==r&&!i||!n)return null;let I=null;do{let{value:r}=await ze(e,"png-chunks",()=>{let e=I?.next??0,r=Math.min(t.length,e+Math.max(2097152,I?.least??0));return l(structuredClone(I),t.subarray(e,r),e,t.length)},!0);r!==Da&&(I=r)}while(!I?.done);if(i)return(await ze(e,"png-geometry",()=>c(I))).value;let{value:x}=await ze(e,"png-structure",async()=>{let{width:e,height:r,depth:n,colourType:i,channels:l,interlace:s,expected:u,palette:c,paletteAlpha:f,transparent:h,colour:d,orientation:m,parts:p}=await o(I,!1),y=p.reduce((e,[,t])=>e+t,0),[g,b]=p.length?t.subarray(p[0][0],p[0][0]+2):[];return{taken:(!M||n<=8&&!s)&&(a||!(m>1))&&p[0]?.[1]>=2&&8==(15&g)&&g>>>4<=7&&!((256*g+b)%31)&&!(32&b),width:e,height:r,depth:n,colourType:i,channels:l,interlace:s,expected:u,palette:c,paletteAlpha:f,transparent:h,colour:d,orientation:m,windowSize:1<<(g>>>4)+8,parts:p,stream:y}});if(!x.taken)return null;let{width:N,height:O,depth:P,channels:U,parts:S,stream:j}=x,E=Math.ceil(N*U*P/8),T=Math.max(1,U*P>>3),F=[];for(let e=0,t=0;e<S.length;t+=S[e][1],e++)F.push(t);let k={length:j,read(e,r){if(r<=e)return new Uint8Array(0);let n=0;for(;n+1<S.length&&F[n+1]<=e;)n++;let a=n;for(;a+1<S.length&&F[a+1]<r;)a++;let i=S[n][0]+(e-F[n]),l=S[a][0]+(r-F[a]),o=t.subarray(i,l);if(n===a)return o;let s=new Uint8Array(r-e);for(let t=n,l=0;t<=a;t++){let n=Math.max(e,F[t]),a=Math.min(r,F[t]+S[t][1]);s.set(o.subarray(S[t][0]+(n-F[t])-i,S[t][0]+(a-F[t])-i),l),l+=a-n}return s}};if(!M&&(16===x.depth||x.interlace))return He(e,x,k,{pngRows:s,pngPassRows:u,unfilterRow:f});let J=[],_=Math.ceil(O/il),B=Math.ceil(j/_*1.25)+4096,R=!(0!==x.colourType&&2!==x.colourType&&3!==x.colourType||x.transparent||x.paletteAlpha),X=h?.(N,O)??null,[D,C]=m?.(N,O)??[1/0,1],G={pos:2,bits:0,count:0,final:0,type:-1,left:0,lengths:null,hlit:0,copy:0,distance:0,a:1,b:0,produced:0,span:B,windowSize:x.windowSize,window:new Uint8Array(0),previous:new Uint8Array(E),scans:M?[null,{colour:3}].map(e=>M(N*O,{opacity:!R},e)):[],flags:new Uint8Array(256),edge:[],xyb:0,tail:null,smooth:!!X,grain:[0,0,0,0],gradient:g?{sum:0,n:0}:null,carried:null},W=A?.(N*O)??[],V=[],K=Math.max(1,O/32|0);for(let t=0;t<_;t++){let r=t*il,n=Math.min(il,O-r),a=null,i=null,l=null,o=async()=>{let e=n*(E+1),{output:o,state:u}=Ke(G,e,t===_-1,k),c=new Uint8Array(n*N*4),h=s(x,c,r),m=G.previous.slice(),y=new Uint8Array(E);for(let e=0,t=0;e<n;e++){let n=o[t++];n>4&&rl("PNG row filter: 0-4"),f(n,o,t,y,m,E,T),t+=E,h(y,N,0,r+e,1,1,0),[m,y]=[y,m]}let M=structuredClone(G.scans);for(let e of M)b(e,c,r*N,n*N);let A=new Uint32Array(c.buffer),I=G.flags.slice(),P=[];for(let[e,t,r,n]of G.edge)I[e]=(t&&r===A[w(N,e)]?1:0)|(!n||A[w(N,e)]>>>24?0:2);for(let e=0;w&&e<256;e++){let t=w(N,e),a=L(O,e)-r,i=a*N+t;if(a<0||a>=n)continue;let l=A[i]===A[i+1],o=!(A[i]>>>24|A[i+1]>>>24);a+1<n?I[e]=(l&&A[i]===A[i+N]?1:0)|(!o||A[i+N]>>>24?0:2):P.push([e,l,A[i],o])}let U=G.xyb;if(G.tail){let e=new Uint8Array(8*N);e.set(G.tail),e.set(c.subarray(0,4*N),4*N),U+=v(e,N,O,r-1,r,r-1)}let S=t===_-1,j=v&&!S&&(r+n-1)%K==0?c.slice((n-1)*N*4):null;U+=v?.(c,N,O,r,S?r+n:r+n-1,r)??0;let F=4*N,J=e=>e>=r?c.subarray((e-r)*F,(e-r+1)*F):G.carried.subarray((e-r+2)*F,(e-r+3)*F),B=G.smooth;if(B)for(let e of X.ys)if(e>=r&&e<r+n&&B)for(let t of X.xs)if(!d(J(e),J(e-1),t)){B=!1;break}let R=G.grain.slice(),V=t?r-1:1,z=S?O-1:r+n-1;for(let e=1+Math.ceil(Math.max(0,V-1)/D)*D;e<z;e+=D)p(R,J(e-1),J(e),J(e+1),N,C);let H=null;G.gradient&&(H=structuredClone(G.gradient),g(H,c,N,O,r,r+n,{row0:r}));let Y=S?null:n>=2?c.slice((n-2)*F):null;a={...u,previous:m,scans:M,flags:I,edge:P,xyb:U,tail:j,smooth:B,grain:R,gradient:H,carried:Y};let q=[],$=(r+n)*N,Q=0;for(let e=W.length;Q<e;){let t=Q+e>>1;W[t]<r*N?Q=t+1:e=t}for(;Q<W.length&&W[Q]<$+N;Q++){let e=W[Q],t=e/N|0,n=e-t*N,a=n?e-1:t?e-N:-1;[e,a,t?e-N:a,n&&t?e-N-1:a].forEach((e,t)=>{e>=r*N&&e<$&&q.push(4*Q+t,A[e-r*N])})}i=Uint32Array.from(q),l=[];for(let e=0;e<N;e+=ll){let t=Math.min(ll,N-e),r=new Uint8Array(n*t*4);for(let a=0;a<n;a++)r.set(c.subarray(4*(a*N+e),4*(a*N+e+t)),a*t*4);l.push(r)}return l},u=[];for(let t=0;t*ll<N;t++)u.push((await ze(e,"png-rows",async()=>(l??await o())[t],!1,!0,!0,t>0)).value);J.push(u),A&&V.push((await ze(e,"png-picks",async()=>i??(await o(),i),!1,!1,!0,!0)).value);let{value:c}=await ze(e,"png-inflate",async()=>a??(await o(),a),!0,!1,!1,!0);c!==Da&&(G=c)}let z=G.xyb;return{data:re(J,N,O,il,ll,e.touched,{opaque:R,scans:G.scans,flats:G.flags,smooth:G.smooth,...y&&{grain:y(G.grain)},ranking:()=>{let e=new Uint32Array(4*W.length);for(let t of $a(V))for(let r=0;r<t.length;r+=2)e[t[r]]=t[r+1];return new Uint8Array(e.buffer)},preference:()=>z,...G.gradient&&{gradient:G.gradient}}),width:N,height:O,bitDepth:8,sampleFormat:"uint",...x.colour,alphaPremultiplied:!1,...x.orientation>1&&{orientation:x.orientation}}},prepareICC:function*(e,t,r){return e=ae(e),yield*z("icc-prepare",function*(){let n,a=r.options(t),i=yield*r.inspect(e,t.level,t.colorSpace),l=yield*V("icc-fields",()=>{let n=r.fields(e,t,i);return{...n,colorData:Ml(n.colorData)}}),o=yield*V("icc-transform",()=>r.transform(e,!1)),s=Ba([o,ae(e,128)]),u=null;if("lz77"!==a)try{u=yield*$e(s,null,r)}catch(e){if("auto"!==a||"JXL_SIZE"!==e.code)throw e;n=e}if("prefix"!==a)try{let e=yield*$e(s,yield*Ye(s,r),r);(!u||e.bitLength<u.bitLength)&&(u=e)}catch(e){if(!u||"JXL_SIZE"!==e.code)throw e}if(!u)throw n;return{...l,iccData:u}})},varDCTFile:function*(e,t,r,n){return yield*z("codestream",function*(){let a=[];for(let e of t)a.push(yield*z("codestream-section",function*(){return e?e.finish():new Uint8Array(0)},void 0,!1,!0));let i=Ba(a).sizes,l=yield*V("codestream-header",()=>{let t=new n.BitWriter(256),r=[],a=()=>{(t.at||t.pending)&&(r.push({bytes:t.bytes,at:t.at,pending:t.pending,acc:t.acc}),l+=8*t.at+t.pending,t.bytes=new Uint8Array(256),t.at=t.acc=t.pending=0)},l=0;return Object.defineProperties(t,{bitLength:{get:()=>l+8*t.at+t.pending},append:{value:e=>{a(),(e.at||e.pending)&&(r.push({bytes:e.bytes,at:e.at,pending:e.pending,acc:e.acc}),l+=8*e.at+e.pending)}},zeroPadToByte:{value:()=>{let e=7&-t.bitLength;e&&t.write(e,0)}}}),e(t),n.writeTOC(t,i),a(),{bits:l,parts:r}}),o=[],s=0,u=0;for(let e of l.parts)for(let t=0;t<e.at||!t&&e.pending;t+=65535){let r=Math.min(e.at,t+65535),a=r===e.at,i=yield*z("codestream-header-part",function*(){let i=new n.BitWriter(r-t+16);return i.acc=s,i.pending=u,i.append({bytes:e.bytes.subarray(t,r),at:r-t,acc:a?e.acc:0,pending:a?e.pending:0}),Ml(i)},void 0,!1,!0);o.push(i.bytes),s=i.acc,u=i.pending}return n.codestreamFromParts(Ba(o),a,r,Ba)})},inspectICC:function*(e,t,r,n){return yield*z("icc-admission",function*(){let a=yield*V("icc-admission-header",()=>n.header(e,t,r));for(let t=0;t<a.count;t+=4096)yield*V("icc-admission-tags",()=>(n.tags(e,a,t,Math.min(a.count,t+4096)),null));return a.channels})},jpegProgressive:function*(e,t,r,n,a,i,l,o,s,u,c,f){let{ScanReader:h,readUnits:d,finishScan:m}=f,p=yield*z("scan-"+r.scans,function*(){let f=1===n.length,p=n[0].component,y=f?p.blocksW*p.blocksH:r.mcusX*r.mcusY,g=f?p.blocksW*p.v:r.mcusX,M=new h(e,t,r,n,a,i,l,o,u,c);for(let e of n)e.component.pred=0;M.load();let b=()=>({...M.here(),preds:n.map(e=>e.component.pred),block:M.blockIndex,eobrun:M.eobrun,resets:u?.resets??null,zeros:u?.zeros??null,padding:c&&{bits:c.bits,zero:c.zero}});for(let e=0,t=0;e<y;e+=g,t++){let a=yield*z("scan-coefficients",function*(){$a(n.map(e=>e.component.parts[t]));for(let{component:e}of n)e.coeffs=e.parts[t]?Int16Array.from(e.parts[t]):new Int16Array(e.stride*e.v*64),e.row0=t*e.v;return d(M,r,n,e,Math.min(y,e+g),s),n.map(e=>e.component.coeffs)},void 0,!1,!0);n.forEach((e,r)=>{e.component.parts[t]=a[r]});let i=yield*K("scan-state",()=>null,b,!0);null===i||i===Da||(M.pos=i.pos,M.load(),M.bit=i.bit,M.blockIndex=i.block,M.eobrun=i.eobrun,n.forEach((e,t)=>{e.component.pred=i.preds[t]}),u&&(u.resets=i.resets,u.zeros=i.zeros),c&&(c.bits=i.padding.bits,c.zero=i.padding.zero))}M.atMarker(!0);let w=m(e,M.pos,y,s,u);for(let{component:e}of n)e.coeffs=null,e.row0=-1;return{pos:w,parts:n.map(e=>e.component.parts),choices:u,padding:c&&{bits:c.bits,zero:c.zero}}},void 0,!1,!0);return n.forEach((e,t)=>{e.component.parts=p.parts[t]}),u&&Object.assign(u,p.choices),c&&Object.assign(c,p.padding),p.pos},jpegSummary:function*(e){let t=yield*z("coefficient-summary",function*(){let t=e.components.map(e=>({dc:new Int16Array(e.stride*e.rows),natural:new Uint32Array(64)}));for(let r=0;r<e.mcusY;r++){let n=yield*z("row-summary",function*(){return $a(e.components.map(e=>e.parts[r])),e.components.map(e=>{let t=e.parts[r],n=new Int16Array(e.stride*e.v),a=new Uint32Array(64);for(let e=0;e<t.length;e+=64){n[e/64]=t[e];for(let r=0;r<64;r++)t[e+r]&&a[r]++}return{dc:n,natural:a}})});for(let a=0;a<t.length;a++){t[a].dc.set(n[a].dc,r*e.components[a].stride*e.components[a].v);for(let e=0;e<64;e++)t[a].natural[e]+=n[a].natural[e]}}return t});e.components.forEach((e,r)=>{e.dc=t[r].dc,e.natural=t[r].natural})},containerBoxes:function*(e,t,r,n){let{admitBoxes:a,boxCursor:i,boxWords:l,nextBox:o,endBoxes:s,reconstructionBox:u}=n;a(e,t);let c=i(),f=[];for(;c.at<e.length;){let n=yield*V("container-boxes",()=>{let n=new Map,a={...c,prefixes:{has:e=>n.has(e)||c.prefixes.has(e),set:(e,t)=>n.set(e,t)}},i=l(e),s=[];for(let n=0;n<64&&a.at<e.length;n++){let n=o(e,t,a,i);if(!n)break;r&&u(n,a),s.push(n)}let{prefixes:f,...h}=a;return{rows:s,cursor:h,additions:[...n]}});Object.assign(c,n.cursor);for(let[e,t]of n.additions)c.prefixes.set(e,t);f.push(...n.rows)}return yield*V("container-end",()=>(s(c),null)),f},jpegContainer:function*(e,t){let{reconstructionStart:r,containerBoxesSteps:n,reconstructionPart:a,reconstructionEnd:i,maximum:l}=t;return yield*z("jpeg-container",function*(){let t=r(e);if(!t)return null;let o=(t,r)=>ae(e,t,r);for(let r of yield*n(e,l,!0))a(t,r,o);return i(t,Ba)})},containerRead:function*(e,t,r){let{limit:n,boxLimit:a,containerStart:i,containerNext:l,containerEnd:o,containerSignature:s,boxWords:u,fourcc:c,invalid:f,ignored:h}=r,d=n(t),m=a(t);return yield*z("container-read",function*(){let t=yield*V("container-start",()=>i(e,d));if(t.raw)return{codestream:e,level:5,minorVersion:0,auxiliary:[]};let r=[],n=new Map,a=(t,r)=>ae(e,t,r);for(;t.at<e.length;){let i=yield*V("container-boxes",()=>{let r=new Map,n=new Map,i=u(e),o=[],s={...t,prefixes:{has:e=>n.has(e)||t.prefixes.has(e),set:(e,t)=>n.set(e,t)}},f={set:(e,t)=>r.set(e,t)};for(let t=0;t<64&&s.at<e.length;t++){let t=l(e,m,s,i,a,f);if(!t)break;h.includes(t.entry.type)||o.push({boxType:c(t.entry.type),data:t.entry.data,extended:16===t.entry.headerLength})}let{prefixes:d,...p}=s;return{state:p,prefixes:[...n],auxiliary:o,additions:[...r]}});Object.assign(t,i.state);for(let[e,r]of i.prefixes)t.prefixes.set(e,r);r.push(...i.auxiliary);for(let[e,t]of i.additions)n.set(e,t)}yield*V("container-end",()=>(o(t),null));let p=t.full;if(!p){let e=[];for(let r=0;r<t.next;r+=64)e.push(...yield*V("container-fragments",()=>{let e=[];for(let a=r;a<Math.min(t.next,r+64);a++){if(!n.has(a))throw f("Missing JPEG XL codestream fragment.");e.push(n.get(a))}return e}));p=Ba(e)}return yield*V("container-signature",()=>(s(p),null)),{codestream:p,level:t.level,minorVersion:t.minorVersion,auxiliary:r}})},boundedHeader:function*(e,t,{header:r}){return yield*z("complete-image-header",function*(){return yield*V("image-header-prefix",()=>r(e,{...t,complete:!0}))})},jpegScanRows:function*({out:e,jpeg:t,writer:r,preds:n,ny:a,per:i,pad:l},o){let{rows:s}=o;if(e.parts)for(let u=0;u<a;u+=i){e.parts.push(yield*V("scan-part",()=>(s(u,Math.min(a,u+i)),e.take())));let c=yield*K("scan-state",()=>null,()=>({done:e.done,acc:e.acc,pending:e.pending,block:r.blockIndex,preds:n,nextReset:o.nextReset(),pad:l?.at??0,eob:r.eob,eobTable:r.eobTable,corrections:r.pending.subarray(0,r.pendingBits),coefficients:t.checkpoint()}),!0);null===c||c===Da||(Object.assign(e,{done:c.done,acc:c.acc,pending:c.pending,at:0,chunks:[]}),r.blockIndex=c.block,n.set(c.preds),o.restoreReset(c.nextReset),l&&(l.at=c.pad),r.eob=c.eob,r.eobTable=c.eobTable,r.pending=c.corrections.slice(),r.pendingBits=r.pending.length,t.resume(c.coefficients))}else for(let t=0,u=i%2?i:i/2;t<a;t+=u){let i=yield*K("scan-rows",()=>s(t,Math.min(a,t+u)),()=>(e.spill(0),{done:e.done,same:e.same,acc:e.acc,pending:e.pending,block:r.blockIndex,preds:n,nextReset:o.nextReset(),pad:l?.at??0,eob:r.eob,eobTable:r.eobTable,corrections:r.pending.subarray(0,r.pendingBits)}));null===i||i===Da||(Object.assign(e,{done:i.done,same:i.same,acc:i.acc,pending:i.pending,at:0}),r.blockIndex=i.block,n.set(i.preds),o.restoreReset(i.nextReset),l&&(l.at=i.pad),r.eob=i.eob,r.eobTable=i.eobTable,r.pending=i.corrections.slice(),r.pendingBits=r.pending.length)}},jpegMarker:function*(e,t){let r=yield*V("jpeg-marker",()=>(t(),{bytes:e.expected?(e.spill(0),null):e.take(),done:e.done,same:e.same}));e.parts&&e.parts.push(r.bytes),Object.assign(e,{done:r.done,same:r.same,at:0,chunks:[]})},jpegScan:function*(e,t,r){if(e.expected){let n=yield*z("jpeg-scan",function*(){return yield*r(),e.spill(0),{done:e.done,same:e.same,pad:t?.at??0}});Object.assign(e,{done:n.done,same:n.same,at:0,acc:0,pending:0}),t&&(t.at=n.pad)}else{let n=e.parts.length,a=yield*z("jpeg-scan",function*(){yield*r();let a=yield*V("scan-end",()=>e.take());return{bytes:Ba([...e.parts.slice(n),a]),done:e.done,pad:t?.at??0}});e.parts.length=n,e.parts.push(a.bytes),Object.assign(e,{done:a.done,acc:0,pending:0,at:0,chunks:[]}),t&&(t.at=a.pad)}},jpegEnd:function*(e,t,r){r(!e.pending&&e.done+e.at+t.length<=e.limit);let n=yield*V("jpeg-end",()=>e.take());return Ba([...e.parts,n,t])},jpegStructure:function*(e,t,r){let n=r.create(t),a=r.start(t);for(;!a.ended;){let i=yield*V("structure-window",()=>r.window(e,t,a));a=i.state;let l=[];for(let e of i.data.scans){let n=e.resets?yield*z("structure-resets",function*(){return r.choices(t,e.index,!1)},void 0,!1,!0):new Uint32Array(0),a=e.zeros?yield*z("structure-zeros",function*(){return r.choices(t,e.index,!0)},void 0,!1,!0):new Uint32Array(0);l.push(r.scan(e,n,a))}r.append(n,i,l)}return r.finish(n,a,t)},jpegSyntax:function*(e,t){let r=[],n=0,a=0;for(let[i,l,o,s]of e)for(let e=0;e<l;e+=o){let u=yield*z(i,function*(){let r=new t;return r.pending=n,r.acc=a,s(r,e,Math.min(l,e+o)),{bytes:r.bytes.subarray(0,r.at),pending:r.pending,acc:r.acc}},void 0,!1,!0);r.push(u.bytes),n=u.pending,a=u.acc}return Ba(r)},jpegPayload:function*(e,t,r){let n,a=[];for(let i=0;i<e.apps.length;i+=64){let l=yield*V("jpeg-payload-apps",()=>r.apps(e.apps.slice(i,i+64),t,n));n=l.state,a.push(...l.cuts)}let i=r.offset(e,n?.curOff??0);for(n={at:0,phase:"search",done:!1};!n.done;){let t=yield*V("jpeg-payload-tail",()=>r.tail(e.tail,n));n=t.state;for(let e of t.cuts)a.push(i+e)}return r.finish(a,i+e.tail.length)},jpegICC:xl,jpegICCEntropy:function*(e,t){return yield*z("icc-entropy",function*(){let r=yield*V("icc-entropy-header",()=>t.header(e));e.bit=r.bit;let n=t.reader(r.model,e,r.size),a=[],i=0,l=0;for(let o=0;o<r.size;o+=65536){let s=yield*V("icc-entropy-part",()=>t.part(e,n,r,o,i,l));a.push(s.bytes),i=s.previous,l=s.older,e.bit=s.bit;let u=yield*K("icc-entropy-state",()=>null,()=>n.checkpoint(),!0);null!==u&&u!==Da&&n.resume(u)}return yield*V("icc-entropy-end",()=>(n.finish(),null)),{bytes:Ba(a),bit:e.bit}})},...Il}),Ol=e=>Array.isArray(e)?e.map(Ol):e&&"object"==typeof e?Object.fromEntries(Object.keys(e).sort().filter(t=>void 0!==e[t]).map(t=>[t,Ol(e[t])])):e,Pl=e=>[...e].map(e=>e.toString(16).padStart(2,"0")).join(""),Ul=Symbol("truncated"),Sl=e=>e>>>1^-(1&e),jl=class{constructor(e,t=!1){if(!(e instanceof Uint8Array))throw Vr("JXL_INPUT","bytes: Uint8Array");this.bytes=e,this.borrowed=t;let r=!t&&e.length<=67108864?new Uint8Array(e.length+8):e;r!==e&&r.set(e),this.buf=r,this.bit=0}get remaining(){return 8*this.bytes.length-this.bit}peek(e){if((0|e)===e&&e>=0&&e<=32||lt(!1,"bit count",this),!e)return 0;let t=this.bit<4294967296?this.bit>>>3:Math.floor(this.bit/8),r=7&this.bit,n=this.buf,a=n[t]>>>r|n[t+1]<<8-r|n[t+2]<<16-r|n[t+3]<<24-r;return r&&(a|=n[t+4]<<32-r),32===e?a>>>0:a&(1<<e)-1}skip(e){Number.isSafeInteger(e)&&e>=0&&e<=8*this.bytes.length-this.bit||lt(!1,"truncated",this,!0),this.bit+=e}read(e){if((0|e)===e&&e>=0&&e<=32||lt(!1,"bit count",this),!e)return 0;let t=this.bit;e>8*this.bytes.length-t&&lt(!1,"truncated",this,!0);let r=t<4294967296?t>>>3:Math.floor(t/8),n=7&t,a=this.buf,i=a[r]>>>n|a[r+1]<<8-n|a[r+2]<<16-n|a[r+3]<<24-n;return n&&(i|=a[r+4]<<32-n),this.bit=t+e,32===e?i>>>0:i&(1<<e)-1}expect(e,t){lt(this.read(e)===t,"invalid field",this)}u32(e){let[t,r]=e[this.read(2)],n=this.read(t)+r;return lt(n<=4294967295,"integer: over 32 bits",this),n}u64BigInt(){let e=this.read(2);if(0===e)return 0n;if(1===e)return BigInt(this.read(4)+1);if(2===e)return BigInt(this.read(8)+17);let t=BigInt(this.read(12));for(let e=12;this.read(1)&&(t|=BigInt(this.read(60===e?4:8))<<BigInt(e),60!==e);e+=8);return t}u64(){let e=this.u64BigInt();if(e>9007199254740991n)throw Object.assign(new RangeError("integer: over safe range"),{code:"JXL_LIMIT",bitOffset:this.bit});return Number(e)}f16(){let e=this.read(16),t=e>>>10&31,r=1023&e;lt(31!==t,"nonfinite float16",this);let n=t?(1024+r)*(1<<t>>>0)/33554432:r/16777216;return 32768&e?-n:n}enum(){return this.u32([[0,0],[0,1],[4,2],[6,18]])}align(){this.expect(7&-this.bit,0)}end(){this.align(),lt(0===this.remaining,"trailing section data",this)}endSection(){for(this.align();this.remaining;)lt(0===this.read(8),"trailing section data",this)}};{let e=new jl(new Uint8Array(8));for(let t=0;t<20;t++)e.bit=0,e.peek(0),e.peek(1),e.peek(32),e.read(0),e.read(1),e.read(32)}var El=Object.freeze({inverseMatrix:Object.freeze([11.031566901960783,-9.866943921568629,-.16462299647058826,-3.254147380392157,4.418770392156863,-.16462299647058826,-3.6588512862745097,2.7129230470588235,1.9459282392156863]),opsinBiases:Object.freeze(Array(3).fill(-.0037930732552754493)),quantizationBiases:Object.freeze([.945349926692846,.9299455010825141,.9500648966626563,.145])}),Tl=new Uint8Array([0,0,0,12,74,88,76,32,13,10,135,10]),Fl=1718909296,kl=1786276896,Jl=1651666786,_l=1784836708,Bl=(function(e){let t=0,r=0,n=0,a=0;for(let i=0;i<e.length;i++)if(e[i]){let l=e[i];lt(l<=15,"Invalid JPEG XL prefix length."),t=Math.max(t,l),r++,n=i,a+=32768>>>l}if(lt(r>0&&(1===r||32768===a),"Invalid JPEG XL prefix tree."),1===r)return{single:n,bits:0,mask:0,table:null};let i=[17,11,15,3,9,7,4,2,5,6,0,33,1,65]||st(e),l=new Uint32Array(1<<t);for(let t=0;t<e.length;t++)if(e[t]){let r=e[t],n=32*t+r;for(let e=i[t];e<l.length;e+=1<<r)l[e]=n}}([5,4,4,4,4,4,3,3,3,3,3,6,7,7]),[[9,1],[13,1],[18,1],[30,1]]),Rl=[[0,1],[1,1],[12,10],[4,3],[3,2],[16,9],[5,4],[2,1]],Xl={bits:8,exponentBits:0,float:!1},Dl=(e,t)=>Array.from({length:e},t),Cl=e=>!!e.read(1),Gl=e=>e.toLocaleString("en-US"),Wl=new Set(["JXL_DECODE","JXL_DIMENSIONS","JXL_INPUT","JXL_LIMIT"]),Vl=(e,t={})=>bt(e,{...t,complete:!0}),Kl=1786276969,zl=1785227117,Hl=65536,Yl=(e,t="")=>Vr("JXL_INPUT",t?`${e}; ${t}`:e),ql=(e,t)=>(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0,$l=["perceptual","relative","saturation","absolute"],Ql={uint8:{bitDepth:8,sampleFormat:"uint"},uint16:{bitDepth:16,sampleFormat:"uint"},float32:{bitDepth:32,sampleFormat:"float32"}},Zl=["srgb","display-p3","rec2020"],eo=["srgb","linear","pq","hlg"],to=e=>!!e&&"object"==typeof e&&Object.hasOwn(e,"rgbaColorEncoding")&&Object.hasOwn(e,"format")&&ArrayBuffer.isView(e.data),ro=["colorSpace","transferFunction","bitDepth","sampleFormat","intensityTarget"],no=(e,t)=>e===t||JSON.stringify(e)===JSON.stringify(t),ao={readJPEGSteps:e=>(e&&Vn in e?e[Vn]:Wn())?.restore?.[Symbol.for("rapier-jxl.verify.source")]},io=(new Uint8Array([0,0,0,12,74,88,76,32,13,10,135,10]),": configureDecoder(decode, restore); decode: jpegxl/decode; restore: jpegxl/jpeg"),lo=Symbol("setup"),oo=e=>Object.assign(fn("JXL_PLATFORM",e+io),{[lo]:!0}),so=e=>e&&Vn in e?e[Vn]:Wn(),uo=(e,t)=>so(t)?.[e]??ao?.[e],co=Symbol.for("rapier-jxl.verify.without-noise"),fo=e=>!!uo("decode",e)?.[co],ho=e=>so(e)?.restore?.[Symbol.for("rapier-jxl.verify.source")],mo=e=>null!==ao||("function"!=typeof globalThis.createImageBitmap||"function"!=typeof globalThis.OffscreenCanvas)&&"function"==typeof ho(e)?.open,po=e=>ao?.readJPEGSteps?.(e)??ho(e),yo=e=>so(e)?.restore?.[Symbol.for("rapier-jxl.steps")]??ao?.restoreSteps,go=e=>uo("decode",e)?.[Symbol.for("rapier-jxl.verify.groups")],Mo=e=>!!go(e)?.open&&!!go(e)?.region,bo=e=>!!go(e)?.open&&!!go(e)?.withoutNoise,wo="bounded verify"+io,Lo=e=>!0===e?.[lo],Ao=[[0,0],[0,1],[4,2],[6,18]],vo=[[19,0],[19,524288],[20,1048576],[21,2097152]],Io={d65:1,e:10,dci:11},xo={srgb:1,"display-p3":11,rec2020:9},No={bt709:1,linear:8,srgb:13,pq:16,dci:17,hlg:18},Oo={perceptual:0,relative:1,saturation:2,absolute:3},Po=[];for(let e=1,t=0;t<16;t++){Po.push(e);let t=2*e*e;do{e++}while(e*e<t)}Po.slice().reverse().map(e=>-e);var Uo=new Set,So=new Set,jo=(e,t)=>{Uo.add(e),So.add(t)},{ensureKernels:Eo,disableEntropyKernels:To,prepareKernels:Fo,arenaKernels:ko,releaseArena:Jo,lendEntropy:_o,orientBlock:Bo,pngRow:Ro,sampleTable:Xo,sampleBands:Do,captureAnsWrite:Co,writeAnsTokens:Go}=(()=>{function e(){let{memory:e,exports:t}=g();i=M(()=>{if(k)throw Vr("JXL_INTERNAL","kernels:arena-deferred-ac");S=!1,j=null,E=!1,T=!1,P=null,O=null,F=null,X=null,R=-1,_=-1,L=-1,N="",U++},()=>{r.u8=new Uint8Array(e.buffer),r.i32=new Int32Array(e.buffer)},()=>u?.(new Int32Array(e.buffer)));let n=w(t,i),a=new Uint8Array(e.buffer),l=new Int32Array(e.buffer);return u?.(l),{memory:e,simd:n,u8:a,i32:l}}function t(){if("simd"===n)return!0;try{if("object"!=typeof WebAssembly||1!==new Uint8Array(new Uint32Array([1]).buffer)[0]||!_n())return!1;r||=e(),n="simd";for(let e of s)Fn[e]&&(Fn[e]=o(Fn[e]))}catch{n="off";for(let e of s)Fn[e]=null}return"simd"===n}let r,n="off",a=!0,i=null,l=new Map,o=e=>l.get(e)??l.set(e,function(...t){return b(i),e.apply(this,t)}).get(e),s=["channel","weighted","fill","palette","rct","tuple","passLevels","group","screen","sampled","dct","ycbcrTile","ycbcrTiles","rgbTiles","rgbBand","photoTile","acGroup","acGroupPair","acDeferred","opaque","nonzero","entropy","varblock","gaborish","strategyFill","strategyWrite","xybPlanes","gabBand","dcEvents","dcPlan","planTokens","shape","nativeRGBA","s2cChannel"],u=null,c=65536,f=589824,h=638984,d=770056,m=262144,y=null,L=-1,A=function(e=1294344){if("simd"!==n||!r.simd.sampleBand)throw Vr("JXL_WASM","resampling kernel: unavailable");let t=L===U;if(S=!1,j=null,E=!1,T=!1,P=null,F=null,U++,t&&(L=U),r.memory.buffer.byteLength<e){try{r.memory.grow(Math.ceil((e-r.memory.buffer.byteLength)/65536))}catch(e){throw Object.assign(Vr("JXL_MEMORY","resampling kernel: grow failed"),{cause:e})}r.u8=new Uint8Array(r.memory.buffer),r.i32=new Int32Array(r.memory.buffer)}return r.memory.buffer},v=function(e){if(e)throw Vr("JXL_INPUT",[null,"alpha: finite 0-1","color samples: finite","PQ samples: 0-1","HLG samples: nonnegative","resampled value: out of range"][e])},I=null,x=null,N="",O=(new WeakMap,new WeakMap,new WeakMap,null),P=null,U=0,S=!1,j=null,E=!1,T=!1,F=null,k=null,J=(new WeakMap,new WeakMap,null);jo(()=>{J&&(J.at=0)},()=>{J=null});let _=-1,B=(new Int32Array(81),new Uint8Array(6144));for(let e=0;e<256;e++)for(let t=0,r=0;t<8;t++)e>>t&1&&(B[16*e+2*r]=2*t,B[16*e+2*r+1]=2*t+1,B[4096+8*e+r++]=t);let R=-1,X=null;return new Map,Fn.ensure=t,{ensureKernels:t,disableEntropyKernels:function(){a=!1,Fn.entropy=null},prepareKernels:async function(){return!("object"!=typeof WebAssembly||1!==new Uint8Array(new Uint32Array([1]).buffer)[0]||!_n())&&p("kernels",()=>gn(kn))},arenaKernels:null,releaseArena:null,lendEntropy:()=>null,orientBlock:function(e,t,a,i,l,o,s,u,c,f,h,d){if("simd"!==n||!r.simd.orientRGBA)throw Vr("JXL_WASM","orientation kernel: unavailable");if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array)||![4,8,16].includes(h)||!Number.isInteger(s)||!Number.isInteger(u)||s<1||u<1||s>256||u>256||!Number.isInteger(d)||d<1||d>8)throw Vr("JXL_INTERNAL","kernels:orientation-block");S=!1,j=null,E=!1,T=!1,P=null,F=null,U++;let m=65536+s*u*h,p=new Uint8Array(r.memory.buffer),y=s*h;for(let t=0;t<u;t++){let r=((o+t)*a+l)*h;p.set(e.subarray(r,r+y),65536+t*y)}r.simd.orientRGBA(65536,s,u,h,d,m);let g=d>=5?s:u,M=(d>=5?u:s)*h;for(let e=0;e<g;e++){let r=m+e*M;t.set(p.subarray(r,r+M),((f+e)*i+c)*h)}},pngRow:function(e,t,n,a,i,l,o,s,u,c,f){let h=new Uint8Array(A(65536+3*t+4*c));if(h.set(e.subarray(0,t),65536),s)return r.simd.pngWiden(65536,c,f,65536+t),s.set(h.subarray(65536+t,65536+t+4*c),u);h.set(n.subarray(0,t),65536+t),h.set(a.subarray(i,i+t),65536+2*t),r.simd.pngUnfilter(l,65536+2*t,65536,65536+t,t,o),e.set(h.subarray(65536,65536+t))},sampleTable:function(e,t){if(![255,1023,4095,65535].includes(e)||!Number.isInteger(t)||!(t>=0&&t<=4||t>=1221&&t<=1e7))throw Vr("JXL_INTERNAL","kernels:sample-transfer-table");let n=A();return r.simd.sampleTable(t,e,c,0),y=new Float64Array(n,c,e+1).slice(),L=U,y},sampleBands:function(e,t,n,a,i,l,o,s){if(![e,t,n,a].every(e=>Number.isInteger(e)&&e>=1)||![1,2,4].includes(s)||o&&(!(i[0]<2&&[255,1023,4095].includes(i[1]))||i[3]||1!==i[4]))throw Vr("JXL_INTERNAL","kernels:resample-band-config");let u=32*Math.max(e,n),p=4*e*s,g=4*n*s,M=Math.max(1,Math.min(t,Math.floor(m/e))),b=Math.max(1,Math.min(a,Math.floor(m/n))),w=d,O=w+3*u,P=w+4*u,S=P+12*n+7&-8,j=S+8*(e+2*n),E=j+M*p,T=E+b*g;return{sourceRows:M,outRows:b,run(s,m,F,k,J,_,B,R,X){if(F-m>M||F<=m||J-k>b||k<0||J>a||k>=J||m<0||F>t||R&&R.length!==4*n)throw Vr("JXL_INTERNAL","kernels:resample-band-carry");let D=A(T),C=new Uint8Array(D);l&&(y!==l||L!==U)&&(new Float64Array(D).set(l,8192),y=l,L=U);let G=i[1]+":"+i[2];o&&N!==G?(r.simd.sampleTable(i[2],i[1],d,f),r.simd.sampleSafe(f,i[1],h),I=C.slice(f,638980),x=C.slice(h,770056),N=G):o&&(C.set(I,f),C.set(x,h)),C.set(new Uint8Array(s.buffer,s.byteOffset+m*p,(F-m)*p),j),R&&new Float64Array(D).set(R,O>>3),r.simd.samplePlan(e,n,P,S),v(r.simd.sampleBand(j,m,F,R?1:0,e,t,n,a,k,J,...i,l?c:0,o?f:0,o?h:0,P,S,w,u,E));let W=J-k-(X?1:0);return new Uint8Array(_.buffer,_.byteOffset+B*g,W*g).set(C.subarray(E,E+W*g)),X?new Float64Array(D,O,4*n).slice():null}}},captureAnsWrite:null,writeAnsTokens:null}})(),Wo=e=>{throw Vr("JXL_INPUT",e)},Vo=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ko={srgb:[.64,.33,.3,.6,.15,.06,.3127,.329],"display-p3":[.68,.32,.265,.69,.15,.06,.3127,.329],rec2020:[.708,.292,.17,.797,.131,.046,.3127,.329]},zo=Uint32Array.from({length:256},(e,t)=>{for(let e=0;e<8;e++)t=t>>>1^(1&t?3988292384:0);return t>>>0}),Ho=(()=>{let e=new Uint32Array(2048);e.set(zo);for(let t=0;t<256;t++)for(let r=1;r<8;r++){let n=e[256*(r-1)+t];e[256*r+t]=n>>>8^zo[255&n]}return e})(),Yo={0:1,2:3,3:1,4:2,6:4},qo=e=>{throw Vr("JXL_INPUT",e)},$o=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Qo=[[0,0,8,8],[4,0,8,8],[0,4,4,8],[2,0,4,4],[0,2,2,4],[1,0,2,2],[0,1,1,2]],Zo=e=>"string"==typeof e&&/^sha256:[a-f0-9]{64}$/.test(e),es=e=>e&&"string"==typeof e.code&&/^JXL_[A-Z_0-9]+$/.test(e.code)&&"string"==typeof e.message&&o(e)===e,ts=e=>Number.isSafeInteger(e)&&e>0,rs=e=>"number"==typeof e&&Number.isFinite(e),ns=e=>rs(e)&&e>=1&&e<=100,as=(Number.MAX_SAFE_INTEGER,Symbol.for("rapier-jxl.retain-input"),Object.fromEntries(["buffer","byteOffset","byteLength"].map(e=>[e,Object.getOwnPropertyDescriptor(DataView.prototype,e).get])),Uint8Array.prototype.slice,Uint8Array,Uint8ClampedArray,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,"function"==typeof Float16Array&&Float16Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array,DataView,({width:e,height:t,orientation:r})=>r>=5?{width:t,height:e}:{width:e,height:t}),is=(e,t=1)=>Math.max(t,Math.min(64,Math.floor(16384/e/t)*t)),ls=e=>e.map(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),os=(e,t)=>(r,n)=>$(e.map(e=>()=>{e.ahead?.(r*t*4,(r+n)*t*4);let a=e.subarray(r*t*4,(r+n)*t*4);return new Float32Array(a.buffer,a.byteOffset,a.byteLength/4)})),ss=Symbol.for("rapier-jxl.verify.whole-frame"),us=256,cs=1<<20,fs=65536,hs=["format","extraChannels","colorEncoding","icc","rgbaColorEncoding","rgbaICC","alphaPremultiplied","orientation","orientationApplied","animation","bitDepth","sampleFormat","colorSpace","transferFunction","header","colorScope"],ds=e=>({colorSpace:"original",applyOrientation:!1,unpremultiplyAlpha:!1,renderSpotColors:!1,maxPixels:e.maxPixels,signal:e.signal,...e&&Vn in e&&{[Vn]:e[Vn]}}),ms=e=>e.orientation>=5?{width:e.height,height:e.width}:{width:e.width,height:e.height},ps=e=>255===e[0]&&10===e[1]||0===e[0]&&74===e[4]&&88===e[5]&&76===e[6],ys=e=>async(t,r,n={})=>{let a,i=await e({unit:t,...n,...n.cold&&{borrowed:!0}});if(i&&Object.hasOwn(i,Na))return{value:i[Na]};try{a=await r()}catch(r){throw await e({unitFailed:t}),r}return await e({unitDone:t,value:a}),{value:a}},gs=(e,t)=>{let r=Object.assign(r=>e.journal(Object.fromEntries(Object.entries(r).map(([e,r])=>[e,["unit","unitDone","unitFailed"].includes(e)?t+r:r]))),{tools:e.journal.tools,touched:e.journal.touched,join:e.journal.join,step:e.journal.step});return{...e,journal:r,unit:ys(r)}},Ms=64,bs=async(e,t)=>await kt(e,t)??Promise.reject(fn("JXL_UNSUPPORTED","decoder: noise-free samples")),ws={"encode:rapier-jxl lossy decode":{1:[[1000230,100663296,0,109051904,0,872]],2:[[1000230,103809024,0,112197632,0,877]],3:[[1000230,106954752,0,113246208,0,974]],4:[[1000230,102760448,0,115343360,0,1077]],5:[[1000230,101711872,0,116391936,0,982]]},"fit:rapier-jxl lossy decode":{1:[[1000230,104857600,0,113246208,0,941]],2:[[1000230,111149056,0,117440512,0,995]],3:[[1000230,104857600,0,118489088,0,952]],4:[[1000230,108003328,0,117440512,0,1149]],5:[[1000230,109051904,0,117440512,0,1124]]},"jpeg:recompress":{1:[[1000230,45508198,1,37748736,1,322],[3999188,57042534,1,56623104,1,568],[12192768,84305510,1,85983232,1,1021]],2:[[1000230,45508198,1,46137344,1,403],[3999188,62285414,1,62914560,1,814],[12192768,69625446,1,91226112,0,1491]],3:[[1000230,46556774,1,46137344,1,550],[3999188,55993958,1,62914560,1,754],[12192768,76021760,1,94371840,0,1546]],4:[[1000230,48653926,1,57671680,1,915],[3999188,63333990,1,75497472,1,1484],[12192768,70778880,1,119537664,0,2570]],5:[[1000230,55993958,1,61865984,1,1377],[3999188,61236838,1,80740352,1,1812],[12192768,82208358,1,134217728,0,3445]],6:[[1000230,53896806,1,63963136,1,1335],[3999188,66479718,1,80740352,1,1793],[12192768,87451238,0,135266304,0,3225]],7:[[1000230,51799654,1,60817408,1,1400],[3999188,61236838,1,87031808,1,2123],[12192768,82208358,1,135266304,0,4245],[24387454,107374182,0]],8:[[1000230,62285414,1,75497472,1,2098],[3999188,84305510,1,94371840,0,3154],[12192768,111568486,0]],9:[[1000230,74868326,1,105906176,0,3258],[3999188,91645542,0],[12192768,154560102,0]]},"jpeg:restore":{any:[[1000230,40370176,1,38797312,1,366],[3999188,47710208,1,48234496,1,619],[12192768,75078042,1,71303168,1,1045],[24387454,78118912,1,78643200,1,1749]]},"verify jpeg":{any:[[1000230,44564480,1,39845888,1,394],[3999188,55050240,1,63963136,1,843],[12192768,67633152,1,85983232,1,1210],[24387454,85458944,1,114294784,0,1780]]},"encode:rapier-jxl/upload lossy":{3:[[249841,55574528,1,57671680,1,468],[499392,63963136,1,66060288,1,632],[1000230,84934656,1,88080384,0,929],[1500254,106954752,0,111149056,0,1093]],2:[[249841,49283072,1,55574528,1,503],[499392,66060288,1,66060288,1,649],[1000230,80740352,1,92274688,0,832],[1500254,103809024,0,102760448,0,1113]],1:[[249841,50331648,1,59768832,1,487],[499392,67108864,1,67108864,1,685],[1000230,84934656,1,87031808,1,928],[1500254,110100480,0,106954752,0,1068]]},"encode:rapier-jxl/upload exact":{1:[[249841,49283072,1,50331648,1,274],[499392,50331648,1,59768832,1,315],[1000230,66060288,1,75497472,1,542],[1500254,73400320,1,87031808,1,701],[2000425,76546048,1,99614720,0,727],[2499794,82837504,1,109051904,0,938],[3e6,80740352,1],[3499200,90177536,0]],2:[[249841,70254592,1,83886080,1,647],[499392,99614720,0,118489088,0,871]],3:[[249841,70254592,1,79691776,1,590],[499392,98566144,0,113246208,0,865]]},"fit:rapier-jxl/upload lossy":{2:[[249841,55574528,1,55574528,1,385],[499392,61865984,1,67108864,1,486],[1000230,81788928,1,133169152,0,1295],[1500254,136314880,0,175112192,0,3315]],1:[[249841,54525952,1,56623104,1,406],[499392,61865984,1,67108864,1,499],[1000230,85983232,1,127926272,0,1442],[1500254,133169152,0,168820736,0,2986]],3:[[249841,49283072,1,59768832,1,368],[499392,61865984,1,65011712,1,508],[1000230,80740352,1,115343360,0,1177],[1500254,131072e3,0,173015040,0,3284]]},"encode:rapier-jxl lossy":{1:[[249841,60817408,1,53477376,1,259],[499392,77594624,1,68157440,1,342],[1000230,104857600,0,80740352,1,428]],2:[[249841,71303168,1,53477376,1,243],[499392,77594624,1,68157440,1,324],[1000230,104857600,0,83886080,1,435]],3:[[249841,59768832,1,71303168,1,418],[499392,78643200,1,82837504,1,581],[1000230,105906176,0,102760448,0,852]],4:[[249841,57671680,1,83886080,1,918],[499392,77594624,1,110100480,0,1405],[1000230,103809024,0,140509184,0,1745]],5:[[249841,59768832,1,99614720,0,1058],[499392,77594624,1,119537664,0,1695],[1000230,108003328,0,143654912,0,2232]],7:[[249841,130023424,0,255852544,0,4661]],8:[[249841,155189248,0,264241152,0,10070]],6:[[249841,105906176,0,167772160,0,2456]],9:[[249841,195035136,0]]},"encode:rapier-jxl exact":{1:[[249841,52428800,1,42991616,1,133],[499392,63963136,1,50331648,1,172],[1000230,63963136,1,63963136,1,287],[1500254,73400320,1,94371840,0,674],[2000425,77594624,1,102760448,0,707],[2499794,72351744,1,104857600,0,953],[3e6,79691776,1],[3499200,83886080,1],[3999188,87031808,1]],2:[[249841,77594624,1,75497472,1,493],[499392,109051904,0,109051904,0,641]],3:[[249841,74448896,1,70254592,1,436],[499392,103809024,0,99614720,0,658]],4:[[249841,92274688,0,89128960,0,661]],5:[[249841,103809024,0,102760448,0,895]],6:[[249841,134217728,0,131072e3,0,1897]],7:[[249841,183500800,0,191889408,0,3702]],8:[[249841,246415360,0,252706816,0,9883]],9:[[249841,304087040,0,309329920,0,17770]]},"fit:rapier-jxl lossy":{1:[[249841,50331648,1,57671680,1,281],[499392,65011712,1,68157440,1,356],[1000230,72351744,1,123731968,0,1470],[1500254,119537664,0,180355072,0,2842]],2:[[249841,53477376,1,57671680,1,237],[499392,58720256,1,67108864,1,366],[1000230,70254592,1,130023424,0,1234],[1500254,116391936,0,181403648,0,3138]],3:[[249841,52428800,1,56623104,1,254],[499392,62914560,1,68157440,1,343],[1000230,70254592,1,120586240,0,1562],[1500254,123731968,0,186646528,0,3227]],4:[[249841,55574528,1,63963136,1,494],[499392,56623104,1,76546048,1,548],[1000230,68157440,1,145752064,0,1865],[1500254,118489088,0,185597952,0,3275]],5:[[249841,51380224,1,63963136,1,510],[499392,58720256,1,73400320,1,527],[1000230,71303168,1,139460608,0,1759],[1500254,112197632,0,193986560,0,3338]],6:[[249841,115343360,0,191889408,0,2365]],7:[[249841,133169152,0,216006656,0,3387]],8:[[249841,136314880,0,254803968,0,4267]],9:[[249841,186646528,0,273678336,0,9784]]},"fit:rapier-jxl/upload exact":{1:[[249841,48234496,1,51380224,1,273],[499392,55574528,1,58720256,1,332],[1000230,73400320,1,78643200,1,500],[1500254,82837504,1,95420416,0,696],[2000425,75497472,1,104857600,0,802],[2499794,87031808,1,122683392,0,889],[3e6,91226112,0]],2:[[249841,72351744,1,80740352,1,678],[499392,101711872,0]],3:[[249841,69206016,1,79691776,1,641],[499392,104857600,0]]},"fit:rapier-jxl exact":{1:[[249841,56623104,1,56623104,1,335],[499392,59768832,1,63963136,1,443],[1000230,66060288,1,80740352,1,551],[1500254,79691776,1,92274688,0,719],[2000425,81788928,1,101711872,0,857],[2499794,82837504,1,119537664,0,935],[3e6,98566144,0]],2:[[249841,75497472,1,81788928,1,745],[499392,100663296,0]],3:[[249841,73400320,1,83886080,1,651],[499392,101711872,0]],4:[[249841,88080384,0]],5:[[249841,101711872,0]],6:[[249841,134217728,0]],7:[[249841,187695104,0]],8:[[249841,239075328,0]],9:[[249841,294649856,0]]}},Ls=Symbol.for("rapier-jxl.steps"),As=new WeakMap,vs=Symbol.for("rapier-jxl.verify.steps"),Is=new TextEncoder,xs=e=>"function"==typeof e&&"function"==typeof e[vs]?e:null,Ns="verify: pass verify from jpegxl/verify",Os=new WeakMap,Ps={verb:function({id:e,verb:t,taken:r,admit:n=()=>{},rows:a=!1,files:i=!1,result:l}){return Object.freeze({id:e,eager:e=>"decode"===e.kind||("file"===(e.kind??"pixels")?!i:!a),normalize(e,t){if(!_i(e)||!je(e))throw fn("JXL_OPTIONS","resumable options: plain data");let a=Object.keys(e).find(e=>!r.includes(e));if(a)throw fn("JXL_OPTIONS",`unknown option: ${a}; use ${r.join(", ")}`);let i=t.kind??"pixels";if("pixels"===i){let{width:r,height:n}=t;if(!Number.isSafeInteger(r)||!Number.isSafeInteger(n)||r<1||n<1||t.byteLength!==r*n*4)throw fn("JXL_INPUT","pixels: width*height*4 RGBA8 or kind:file");h(r,n,d(e.maxPixels))}else if("file"!==i&&"decode"!==i)throw fn("JXL_INPUT","source kind: pixels|file|decode");return n(e),{options:{...e}}},async run(e,r,n,a){if("decode"!==n.kind)return Fe(ke(Te(t(Di(r,n,i),{...e.options,[Pa]:a})),n),a);let l=a?.host&&Vn in a.host?a.host[Vn]:Wn(),o=await q(a,"decode",()=>Ee(r,l));return Fe(Ri(o.source,Te(t(Xi(o),{...e.options,[Pa]:a}))),a)},async straight(e,r,n,a,i,l){if("decode"!==n.kind)return ke(Te(t(Di(r,n,!1),{...e.options,signal:a})),n);let o=l&&Vn in l?l[Vn]:Wn(),s=await Ee(r,o);return Ri(s.source,Te(t(Xi(s),{...e.options,signal:a})))},async record(e,t,r,n){if(!_i(n))throw fn("JXL_INPUT","finished record: job result record");if(void 0!==n.records){if(!Array.isArray(n.records)||!n.records.length)throw fn("JXL_INPUT","finished records: nonempty array");let t=0,a=[];for(let{length:i,...o}of n.records){if(null!==i&&(!Number.isSafeInteger(i)||i<1||t+i>e.length))throw fn("JXL_INPUT","finished records: incomplete file");a.push(await Se(l,null===i?null:e.slice(t,t+=i),o,r))}if(t!==e.length)throw fn("JXL_INPUT","finished records: incomplete file");return a}if("boolean"!=typeof n.missed||n.missed&&e.length)throw fn("JXL_INPUT","finished record: file mismatch");return Se(l,n.missed?null:e,n.record,r)}})},verify:(e,t)=>vr(t[vs],t)},Us=(e,t)=>Os.get(e)??Os.set(e,Ps[e.kind](e,t)).get(e),Ss=(e,t)=>{for(let{ref:r,bytes:n}of t??[])e.unsaved.set(r.hash,n)},js=(e,t,r,n)=>({source:t,expectedRevision:e?.revision,read:r.read,readMany:r.readMany,readSource:r.readSource,...n}),Es=32e6,Ts=65536;export{_r as advance,Br as finish,Jr as start,Rr as workerAdmission};