@loaders.gl/zarr
Version:
Framework-independent loaders for Zarr
7 lines • 530 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if (typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if (typeof define === 'function' && define.amd) define([], factory);
else if (typeof exports === 'object') exports['loaders'] = factory();
else root['loaders'] = factory();})(globalThis, function () {
"use strict";var __exports__=(()=>{var aE=Object.create;var VI=Object.defineProperty;var DE=Object.getOwnPropertyDescriptor;var tE=Object.getOwnPropertyNames;var sE=Object.getPrototypeOf,hE=Object.prototype.hasOwnProperty;var eE=(A,I)=>()=>(I||A((I={exports:{}}).exports,I),I.exports),yE=(A,I)=>{for(var g in I)VI(A,g,{get:I[g],enumerable:!0})},OI=(A,I,g,B)=>{if(I&&typeof I=="object"||typeof I=="function")for(let C of tE(I))!hE.call(A,C)&&C!==g&&VI(A,C,{get:()=>I[C],enumerable:!(B=DE(I,C))||B.enumerable});return A},_I=(A,I,g)=>(OI(A,I,"default"),g&&OI(g,I,"default")),FE=(A,I,g)=>(g=A!=null?aE(sE(A)):{},OI(I||!A||!A.__esModule?VI(g,"default",{value:A,enumerable:!0}):g,A)),wE=A=>OI(VI({},"__esModule",{value:!0}),A);var VB=eE((DD,OB)=>{OB.exports=globalThis.loaders});var xI={};yE(xI,{ZarrPixelSource:()=>Ug,loadZarr:()=>XQ});_I(xI,FE(VB(),1));var Yg=new Map;function SI(A,I){Yg.set(A,I)}async function vB(A){if(!Yg.has(A.id))throw new Error(`Compression codec ${A.id} is not supported by Zarr.js yet.`);return(await Yg.get(A.id)()).fromConfig(A)}function Eg(A){return new Proxy(A,{set(I,g,B,C){return I.setItem(g,B)},get(I,g,B){return I.getItem(g)},deleteProperty(I,g){return I.deleteItem(g)},has(I,g){return I.containsItem(g)}})}function GE(A){return typeof A=="object"&&A!==null&&"__zarr__"in A}function vI(A){return GE(A)&&A.__zarr__==="KeyError"}var CA=class extends Error{constructor(I){super(`path ${I} contains an array`),this.__zarr__="ContainsArrayError",Object.setPrototypeOf(this,CA.prototype)}},NA=class extends Error{constructor(I){super(`path ${I} contains a group`),this.__zarr__="ContainsGroupError",Object.setPrototypeOf(this,NA.prototype)}};var TA=class extends Error{constructor(I){super(`ground not found at path ${I}`),this.__zarr__="GroupNotFoundError",Object.setPrototypeOf(this,TA.prototype)}};var X=class extends Error{constructor(I){super(I),this.__zarr__="PermissionError",Object.setPrototypeOf(this,X.prototype)}},JA=class extends Error{constructor(I){super(`key ${I} not present`),this.__zarr__="KeyError",Object.setPrototypeOf(this,JA.prototype)}},BI=class extends RangeError{constructor(I,g){super(`too many indices for array; expected ${g.length}, got ${I.length}`),this.__zarr__="TooManyIndicesError",Object.setPrototypeOf(this,BI.prototype)}},EA=class extends RangeError{constructor(I){super(I),this.__zarr__="BoundsCheckError",Object.setPrototypeOf(this,EA.prototype)}},mA=class extends RangeError{constructor(I,g,B,C){super(`slice arguments slice(${I}, ${g}, ${B}) invalid: ${C}`),this.__zarr__="InvalidSliceError",Object.setPrototypeOf(this,mA.prototype)}},CI=class extends Error{constructor(){super("Negative step size is not supported when indexing."),this.__zarr__="NegativeStepError",Object.setPrototypeOf(this,CI.prototype)}},P=class extends Error{constructor(I){super(I),this.__zarr__="ValueError",Object.setPrototypeOf(this,P.prototype)}},QI=class extends Error{constructor(I){super(I),this.__zarr__="HTTPError",Object.setPrototypeOf(this,QI.prototype)}};function iA(A,I=void 0,g=null){if(A===void 0)throw new mA(A,I,g,"The first argument must not be undefined");if(typeof A=="string"&&A!==":"||typeof I=="string"&&I!==":")throw new mA(A,I,g,'Arguments can only be integers, ":" or null');return I===void 0&&(I=A,A=null),{start:A===":"?null:A,stop:I===":"?null:I,step:g,_slice:!0}}function SE(A,I,g,B){if(A<0?(A+=B,A<0&&(A=g<0?-1:0)):A>=B&&(A=g<0?B-1:B),I<0?(I+=B,I<0&&(I=g<0?-1:0)):I>=B&&(I=g<0?B-1:B),g<0){if(I<A){let C=Math.floor((A-I-1)/-g+1);return[A,I,g,C]}}else if(A<I){let C=Math.floor((I-A-1)/g+1);return[A,I,g,C]}return[A,I,g,0]}function Zg(A,I){let g,B,C;A.step===null?C=1:C=A.step,A.start===null?g=C<0?Number.MAX_SAFE_INTEGER:0:(g=A.start,g<0&&(g+=I)),A.stop===null?B=C<0?-Number.MAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER:(B=A.stop,B<0&&(B+=I));let Q=SE(g,B,C,I);if(g=Q[0],B=Q[1],C=Q[2],I=Q[3],C===0)throw new Error("Step size 0 is invalid");return[g,B,C,I]}function jB(A){return Array.isArray(A)?A:[A]}function nE(A,I){if(A.length>I.length)throw new BI(A,I)}function ZA(A,I){let g=[],B=[];for(let C=0;C<A.length;C++){let Q=A[C];if(typeof Q=="number")g.push(Q);else{let o=Zg(Q,I[C]),E=o[3];B.push(E),g.push(o)}}return[g,B]}function qA(A,I,g=!1){A=rE(A,I);for(let B=0;B<A.length;B++){let C=A[B];if(typeof C=="number")g?A[B]=iA(C,C+1,1):A[B]=Xg(C,I[B]);else{if(zB(C))throw new TypeError("Integer array selections are not supported (yet)");(C===":"||C===null)&&(A[B]=iA(null,null,1))}}return A}function rE(A,I){A=jB(A);let g=-1,B=0;for(let C=0;C<A.length;C++)A[C]==="..."&&(g=C,B+=1);if(B>1)throw new RangeError("an index can only have a single ellipsis ('...')");if(B===1){let C=g,Q=A.length-(C+1),o=A.length-1;if(o>=I.length)A=A.filter(E=>E!=="...");else{let E=I.length-o,t=A.slice(0,C).concat(new Array(E).fill(null));Q>0&&(t=t.concat(A.slice(A.length-Q))),A=t}}if(A.length<I.length){let C=I.length-A.length;A=A.concat(new Array(C).fill(null))}return nE(A,I),A}function Xg(A,I){if(A<0&&(A=I+A),A>=I||A<0)throw new EA(`index out of bounds for dimension with length ${I}`);return A}function NE(A){return typeof A=="number"}function zB(A){if(!Array.isArray(A))return!1;for(let I of A)if(typeof I!="number")return!1;return!0}function Og(A){return A!==null&&A._slice===!0}function RE(A){return Og(A)&&(A.step===null||A.step===1)}function cE(A){A=jB(A);for(let I=0;I<A.length;I++){let g=A[I];if(!(zB(g)||RE(g)||g==="..."))return!1}return!0}function*UE(...A){if(A.length===0)return;let I=A.map(B=>B()),g=I.map(B=>B.next());for(let B=0;;){if(g[B].done){if(I[B]=A[B](),g[B]=I[B].next(),++B>=I.length)return}else yield g.map(({value:C})=>C),B=0;g[B]=I[B].next()}}var jI=class{constructor(I,g){I=qA(I,g.shape),this.dimIndexers=[];let B=g.shape;for(let C=0;C<B.length;C++){let Q=I[C],o=B[C],E=g.chunks[C];if(Q===null&&(Q=iA(null)),NE(Q))this.dimIndexers.push(new lg(Q,o,E));else if(Og(Q))this.dimIndexers.push(new zI(Q,o,E));else throw new RangeError(`Unspported selection item for basic indexing; expected integer or slice, got ${Q}`)}this.shape=[];for(let C of this.dimIndexers)C instanceof zI&&this.shape.push(C.numItems);this.dropAxes=null}*iter(){let I=this.dimIndexers.map(B=>()=>B.iter()),g=UE(...I);for(let B of g){let C=[],Q=[],o=[];for(let E of B)C.push(E.dimChunkIndex),Q.push(E.dimChunkSelection),E.dimOutSelection!==null&&o.push(E.dimOutSelection);yield{chunkCoords:C,chunkSelection:Q,outSelection:o}}}},lg=class{constructor(I,g,B){I=Xg(I,g),this.dimSelection=I,this.dimLength=g,this.dimChunkLength=B,this.numItems=1}*iter(){let I=Math.floor(this.dimSelection/this.dimChunkLength),g=I*this.dimChunkLength,B=this.dimSelection-g;yield{dimChunkIndex:I,dimChunkSelection:B,dimOutSelection:null}}},zI=class{constructor(I,g,B){let[C,Q,o]=Zg(I,g);if(this.start=C,this.stop=Q,this.step=o,this.step<1)throw new CI;this.dimLength=g,this.dimChunkLength=B,this.numItems=Math.max(0,Math.ceil((this.stop-this.start)/this.step)),this.numChunks=Math.ceil(this.dimLength/this.dimChunkLength)}*iter(){let I=Math.floor(this.start/this.dimChunkLength),g=Math.ceil(this.stop/this.dimChunkLength);for(let B=I;B<g;B++){let C=B*this.dimChunkLength,Q=Math.min(this.dimLength,(B+1)*this.dimChunkLength),o=Q-C,E,t,i;if(this.start<C){E=0;let e=(C-this.start)%this.step;e>0&&(E+=this.step-e),i=Math.ceil((C-this.start)/this.step)}else E=this.start-C,i=0;this.stop>Q?t=o:t=this.stop-C;let a=iA(E,t,this.step),G=Math.ceil((t-E)/this.step),F=iA(i,i+G);yield{dimChunkIndex:B,dimChunkSelection:a,dimOutSelection:F}}}},iI=typeof process<"u"&&process.versions&&process.versions.node;function _B(){}function QA(A){if(A===null)return"";for(A instanceof String&&(A=A.valueOf()),A=A.replace(/\\/g,"/");A.length>0&&A[0]==="/";)A=A.slice(1);for(;A.length>0&&A[A.length-1]==="/";)A=A.slice(0,A.length-1);A=A.replace(/\/\/+/g,"/");let I=A.split("/");for(let g of I)if(g==="."||g==="..")throw Error("path containing '.' or '..' segment not allowed");return A}function Vg(A){return typeof A=="number"&&(A=[A]),A.map(I=>Math.floor(I))}function kE(A,I){if(A===null||A===!0)throw new Error("Chunk guessing is not supported yet");return A===!1?I:(typeof A=="number"&&(A=[A]),A.length<I.length&&(A=A.concat(I.slice(A.length))),A.map((g,B)=>g===-1||g===null?I[B]:Math.floor(g)))}function JE(A){return A=A.toUpperCase(),A}function PB(A,I){if(A===null)return!0;Array.isArray(A)||(A=[A]);for(let g=0;g<Math.min(A.length,I.length);g++){let B=A[g];if(B!==null){if(Og(B)){let C=B,Q=C.step===1||C.step===null;if(C.start===null&&C.stop===null&&Q||C.stop-C.start===I[g]&&Q)continue;return!1}return!1}}return!0}function qE(A,I){if(A.length!==I.length)return!1;for(let g=0;g<A.length;g++)if(A[g]!==I[g])return!1;return!0}function LE(A){let I=A.length,g=Array(I),B=1;for(let C=I-1;C>=0;C--)g[C]=B,B*=A[C];return g}function dg(A,I){let g=typeof A=="string"?new URL(A):A;g.pathname.endsWith("/")||(g.pathname+="/");let B=new URL(I,g);return B.search=g.search,B.href}function $B(A){let I=A.BYTES_PER_ELEMENT;if(I===1)return;if(iI){let o=Buffer.from(A.buffer,A.byteOffset,A.length*I);I===2&&o.swap16(),I===4&&o.swap32(),I===8&&o.swap64();return}let g=new Uint8Array(A.buffer,A.byteOffset,A.length*I),B=I/2,C=I-1,Q;for(let o=0;o<g.length;o+=I)for(let E=0;E<B;E++)Q=g[o+E],g[o+E]=g[o+C-E],g[o+C-E]=Q}function fE(A){let I=A.slice();return $B(I),I}function ME(A,I,g){let B=0,C=g[0],Q=g[1],o=Q;for(let E=0;E<Q;E++)for(let t=0;t<C;t++)I[t*o+E]=A[B++]}function KE(A,I,g){let B=0,C=g[0],Q=g[1],o=g[2],E=o*Q,t=o;for(let i=0;i<o;i++)for(let a=0;a<Q;a++)for(let G=0;G<C;G++)I[G*E+a*t+i]=A[B++]}function HE(A,I,g){let B=0,C=g[0],Q=g[1],o=g[2],E=g[3],t=E*o*Q,i=E*o,a=E;for(let G=0;G<E;G++)for(let F=0;F<o;F++)for(let e=0;e<Q;e++)for(let n=0;n<C;n++)I[n*t+e*i+F*a+G]=A[B++]}function dE(A,I,g){let B=g.length,C=g.reduce((E,t)=>E*t),Q=g.map((E,t)=>t+1===B?1:g.slice(t+1).reduce((i,a)=>i*a,1)),o=Array(B).fill(0);for(let E=0;E<C;E++){let t=0;for(let i=0;i<B;i++)t+=o[i]*Q[i];I[t]=A[E],o[0]+=1;for(let i=0;i<B;i++)if(o[i]===g[i]){if(i+1===B)return;o[i]=0,o[i+1]+=1}}}var YE={[0]:_B,[1]:_B,[2]:ME,[3]:KE,[4]:HE};function lE(A,I,g){return(YE[g.length]||dE)(A,I,g)}function _g(A){return A===null?!1:A instanceof ArrayBuffer||typeof SharedArrayBuffer=="function"&&A instanceof SharedArrayBuffer?!0:iI?A.toString().startsWith("[object ArrayBuffer]")||A.toString().startsWith("[object SharedArrayBuffer]"):!1}var $I=".zarray",Pg=".zgroup",AC=".zattrs";async function rA(A,I=null){I=QA(I);let B=LA(I)+$I;return A.containsItem(B)}async function sA(A,I=null){I=QA(I);let B=LA(I)+Pg;return A.containsItem(B)}function LA(A){return A.length>0?A+"/":""}async function IC(A,I,g,B){if(I.length===0)return;let C=I.split("/"),Q="";for(let o of C.slice(0,C.length-1))Q+=o,await rA(A,Q)?await ug(A,Q,B):await sA(A,Q)||await ug(A,Q),Q+="/"}async function ug(A,I=null,g=!1){if(I=QA(I),g)throw Error("Group overwriting not implemented yet :(");if(await rA(A,I))throw new CA(I);if(await sA(A,I))throw new NA(I);let B={zarr_format:2},C=LA(I)+Pg;await A.setItem(C,JSON.stringify(B))}async function GI(A,I=null,g=null,B=!1){I=QA(I),await IC(A,I,g,B),await ug(A,I,B)}async function uE(A,I,g,B,C,Q,o,E,t,i,a,G){if(t)throw Error("Array overwriting not implemented yet :(");if(await rA(A,C))throw new CA(C);if(await sA(A,C))throw new NA(C);if(B=B,I=Vg(I),g=kE(g,I),E=JE(E),o=o,a!==null&&a.length>0)throw Error("Filters are not supported yet");let F=o;typeof o=="number"&&(Number.isNaN(o)&&(F="NaN"),Number.POSITIVE_INFINITY===o&&(F="Infinity"),Number.NEGATIVE_INFINITY===o&&(F="-Infinity")),a=null;let e={zarr_format:2,shape:I,chunks:g,dtype:B,fill_value:F,order:E,compressor:Q,filters:a};G&&(e.dimension_separator=G);let n=LA(C)+$I;await A.setItem(n,JSON.stringify(e))}async function pE(A,I,g,B,C=null,Q=null,o=null,E="C",t=!1,i=null,a=null,G){C=QA(C),await IC(A,C,i,t),await uE(A,I,g,B,C,Q,o,E,t,i,a,G)}function Ag(A){if(typeof A!="string"){if(iI&&Buffer.isBuffer(A))return JSON.parse(A.toString());if(_g(A)){let I=new TextDecoder,g=new Uint8Array(A);return JSON.parse(I.decode(g))}else return A}return JSON.parse(A)}var Ig=class{constructor(I,g,B,C=!0){this.store=I,this.key=g,this.readOnly=B,this.cache=C,this.cachedValue=null}async asObject(){if(this.cache&&this.cachedValue!==null)return this.cachedValue;let I=await this.getNoSync();return this.cache&&(this.cachedValue=I),I}async getNoSync(){try{let I=await this.store.getItem(this.key);return Ag(I)}catch{return{}}}async setNoSync(I,g){let B=await this.getNoSync();return B[I]=g,await this.putNoSync(B),!0}async putNoSync(I){await this.store.setItem(this.key,JSON.stringify(I)),this.cache&&(this.cachedValue=I)}async delNoSync(I){let g=await this.getNoSync();return delete g[I],await this.putNoSync(g),!0}async put(I){if(this.readOnly)throw new X("attributes are read-only");return this.putNoSync(I)}async setItem(I,g){if(this.readOnly)throw new X("attributes are read-only");return this.setNoSync(I,g)}async getItem(I){return(await this.asObject())[I]}async deleteItem(I){if(this.readOnly)throw new X("attributes are read-only");return this.delNoSync(I)}async containsItem(I){return(await this.asObject())[I]!==void 0}proxy(){return Eg(this)}},xE={"|b":Int8Array,"|B":Uint8Array,"|u1":Uint8Array,"|i1":Int8Array,"<b":Int8Array,"<B":Uint8Array,"<u1":Uint8Array,"<i1":Int8Array,"<u2":Uint16Array,"<i2":Int16Array,"<u4":Uint32Array,"<i4":Int32Array,"<f4":Float32Array,"<f8":Float64Array,">b":Int8Array,">B":Uint8Array,">u1":Uint8Array,">i1":Int8Array,">u2":Uint16Array,">i2":Int16Array,">u4":Uint32Array,">i4":Int32Array,">f4":Float32Array,">f8":Float64Array};function BA(A){let I=xE[A];if(!I)throw Error(`Dtype not recognized or not supported in zarr.js, got ${A}.`);return I}function vg(A){if(A instanceof Uint8Array)return"|u1";if(A instanceof Int8Array)return"|i1";if(A instanceof Uint16Array)return"<u2";if(A instanceof Int16Array)return"<i2";if(A instanceof Uint32Array)return"<u4";if(A instanceof Int32Array)return"<i4";if(A instanceof Float32Array)return"<f4";if(A instanceof Float64Array)return"<f8";throw new P("Mapping for TypedArray to Dtypestring not known")}function jg(A){return A.byteLength!==void 0?A.constructor:jg(A[0])}function bE(A,I,g){let B=qA(g,I),[C,Q]=ZA(B,I);return[pg(A,I,C),Q]}function pg(A,I,g){let B=g[0];if(typeof B=="number")return I.length===1?A[B]:pg(A[B],I.slice(1),g.slice(1));let[C,Q,o,E]=B;if(E===0)return new(jg(A))(0);if(I.length===1){if(o===1)return A.slice(C,Q);let i=new A.constructor(E);for(let a=0;a<E;a++)i[a]=A[C+a*o];return i}let t=new Array(E);for(let i=0;i<E;i++)t[i]=pg(A[C+i*o],I.slice(1),g.slice(1));return E>0&&typeof t[0]=="number"&&(t=A[0].constructor.from(t)),t}function WE(A,I,g,B){let C=qA(B,g,!0),[Q,o]=ZA(C,g);zg(A,I,g,Q)}function TE(A,I,g,B,C){let Q=qA(C,g,!1),[o,E]=ZA(Q,g);if(JSON.stringify(E)!==JSON.stringify(B))throw new P(`Shape mismatch in target and source NestedArray: ${E} and ${B}`);xg(A,I,g,o)}function xg(A,I,g,B){let C=B[0];if(typeof I=="number"){zg(A,I,g,B.map(i=>typeof i=="number"?[i,i+1,1,1]:i));return}if(typeof C=="number"){xg(A[C],I,g.slice(1),B.slice(1));return}let[Q,o,E,t]=C;if(g.length===1){if(E===1)A.set(I,Q);else for(let i=0;i<t;i++)A[Q+i*E]=I[i];return}for(let i=0;i<t;i++)xg(A[Q+i*E],I[i],g.slice(1),B.slice(1))}function zg(A,I,g,B){let C=B[0],[Q,o,E,t]=C;if(g.length===1){if(E===1)A.fill(I,Q,o);else for(let i=0;i<t;i++)A[Q+i*E]=I;return}for(let i=0;i<t;i++)zg(A[Q+i*E],I,g.slice(1),B.slice(1))}function mE(A,I,g){g===void 0&&(g=jg(A));let B=I.reduce((Q,o)=>Q*o,1),C=new g(B);return gC(A,I,C,0),C}function gC(A,I,g,B){if(I.length===1){g.set(A,B);return}if(I.length===2){for(let o=0;o<I[0];o++)g.set(A[o],B+I[1]*o);return A}let C=I.slice(1),Q=C.reduce((o,E)=>o*E,1);for(let o=0;o<I[0];o++)gC(A[o],C,g,B+Q*o);return A}var z=class{constructor(I,g,B){let C=I!==null&&!!I.BYTES_PER_ELEMENT;if(g===void 0){if(!C)throw new P("Shape argument is required unless you pass in a TypedArray");g=[I.length]}if(B===void 0){if(!C)throw new P("Dtype argument is required unless you pass in a TypedArray");B=vg(I)}if(g=Vg(g),this.shape=g,this.dtype=B,C&&g.length!==1&&(I=I.buffer),this.shape.length===0)this.data=new(BA(B))(1);else if(iI&&Buffer.isBuffer(I)||_g(I)||I===null){let Q=g.reduce((t,i)=>t*i,1);I===null&&(I=new ArrayBuffer(Q*parseInt(B[B.length-1],10)));let o=I.byteLength/parseInt(B[B.length-1],10);if(Q!==o)throw new Error(`Buffer has ${o} of dtype ${B}, shape is too large or small ${g} (flat=${Q})`);let E=BA(B);this.data=CC(I,E,g)}else this.data=I}get(I){let[g,B]=bE(this.data,this.shape,I);return B.length===0?g:new z(g,B,this.dtype)}set(I=null,g){I===null&&(I=[iA(null)]),typeof g=="number"?this.shape.length===0?this.data[0]=g:WE(this.data,g,this.shape,I):TE(this.data,g.data,this.shape,g.shape,I)}flatten(){return this.shape.length===1?this.data:mE(this.data,this.shape,BA(this.dtype))}static arange(I,g="<i4"){let B=BA(g),C=BC([I],B);return new z(C,[I],g)}};function BC(A,I){let g=A.reduce((C,Q)=>C*Q,1),B=new I(g);return B.set([...Array(g).keys()]),B}function CC(A,I,g,B=0){if(g.length===1)return new I(A.slice(B,B+g[0]*I.BYTES_PER_ELEMENT));let C=new Array(g[0]);if(g.length===2){for(let E=0;E<g[0];E++)C[E]=new I(A.slice(B+g[1]*E*I.BYTES_PER_ELEMENT,B+g[1]*(E+1)*I.BYTES_PER_ELEMENT));return C}let Q=g.slice(1),o=Q.reduce((E,t)=>E*t,1);for(let E=0;E<g[0];E++)C[E]=CC(A,I,Q,B+o*E*I.BYTES_PER_ELEMENT);return C}function ZE(A,I,g,B,C){let Q=qA(B,g,!0),[o]=ZA(Q,g);QC(C,A,I,o)}function XE(A,I,g,B,C,Q,o){let E=qA(B,g,!1),[t,i]=ZA(E,g);if(JSON.stringify(i)!==JSON.stringify(o))throw new P(`Shape mismatch in target and source RawArray: ${i} and ${o}`);bg(A,I,t,C,Q)}function OE(A,I,g,B,C,Q,o,E){let t=qA(B,g,!0),[i]=ZA(t,g),a=qA(E,o,!1),[G]=ZA(a,o);Wg(A,I,i,C,Q,G)}function QC(A,I,g,B){let[C,...Q]=B,[o,...E]=g,[t,i,a,G]=C;if(g.length===1){if(a===1&&o===1)I.fill(A,t,t+G);else for(let F=0;F<G;F++)I[o*(t+a*F)]=A;return}for(let F=0;F<G;F++)QC(A,I.subarray(o*(t+a*F)),E,Q)}function bg(A,I,g,B,C){if(g.length===0){A.set(B);return}let[Q,...o]=g,[E,...t]=I;if(typeof Q=="number"){bg(A.subarray(Q*E),t,o,B,C);return}let[i,...a]=C,[G,F,e,n]=Q;if(I.length===1){if(e===1&&E===1&&i===1)A.set(B.subarray(0,n),G);else for(let q=0;q<n;q++)A[E*(G+e*q)]=B[i*q];return}for(let q=0;q<n;q++)bg(A.subarray(E*(G+q*e)),t,o,B.subarray(i*q),a)}function Wg(A,I,g,B,C,Q){if(Q.length===0){A.set(B.subarray(0,A.length));return}let[o,...E]=g,[t,...i]=Q,[a,...G]=I,[F,...e]=C;if(typeof t=="number"){Wg(A,I,g,B.subarray(F*t),e,i);return}let[n,q,N,J]=o,[L,c,r,d]=t;if(I.length===1&&C.length===1){if(N===1&&a===1&&r===1&&F===1)A.set(B.subarray(L,L+J),n);else for(let u=0;u<J;u++)A[a*(n+N*u)]=B[F*(L+r*u)];return}for(let u=0;u<J;u++)Wg(A.subarray(a*(n+u*N)),G,E,B.subarray(F*(L+u*r)),e,i)}var SA=class{constructor(I,g,B,C){let Q=I!==null&&!!I.BYTES_PER_ELEMENT;if(g===void 0){if(!Q)throw new P("Shape argument is required unless you pass in a TypedArray");g=[I.length]}if(g=Vg(g),B===void 0){if(!Q)throw new P("Dtype argument is required unless you pass in a TypedArray");B=vg(I)}if(C===void 0&&(C=LE(g)),this.shape=g,this.dtype=B,this.strides=C,Q&&g.length!==1&&(I=I.buffer),this.shape.length===0)this.data=new(BA(B))(1);else if(iI&&Buffer.isBuffer(I)||_g(I)||I===null){let o=g.reduce((i,a)=>i*a,1);I===null&&(I=new ArrayBuffer(o*parseInt(B[B.length-1],10)));let E=I.byteLength/parseInt(B[B.length-1],10);if(o!==E)throw new Error(`Buffer has ${E} of dtype ${B}, shape is too large or small ${g} (flat=${o})`);let t=BA(B);this.data=new t(I)}else this.data=I}set(I=null,g,B){I===null&&(I=[iA(null)]),typeof g=="number"?this.shape.length===0?this.data[0]=g:ZE(this.data,this.strides,this.shape,I,g):g instanceof SA&&B?OE(this.data,this.strides,this.shape,I,g.data,g.strides,g.shape,B):XE(this.data,this.strides,this.shape,I,g.data,g.strides,g.shape)}},EC={exports:{}};(function(A){var I=Object.prototype.hasOwnProperty,g="~";function B(){}Object.create&&(B.prototype=Object.create(null),new B().__proto__||(g=!1));function C(t,i,a){this.fn=t,this.context=i,this.once=a||!1}function Q(t,i,a,G,F){if(typeof a!="function")throw new TypeError("The listener must be a function");var e=new C(a,G||t,F),n=g?g+i:i;return t._events[n]?t._events[n].fn?t._events[n]=[t._events[n],e]:t._events[n].push(e):(t._events[n]=e,t._eventsCount++),t}function o(t,i){--t._eventsCount===0?t._events=new B:delete t._events[i]}function E(){this._events=new B,this._eventsCount=0}E.prototype.eventNames=function(){var i=[],a,G;if(this._eventsCount===0)return i;for(G in a=this._events)I.call(a,G)&&i.push(g?G.slice(1):G);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(a)):i},E.prototype.listeners=function(i){var a=g?g+i:i,G=this._events[a];if(!G)return[];if(G.fn)return[G.fn];for(var F=0,e=G.length,n=new Array(e);F<e;F++)n[F]=G[F].fn;return n},E.prototype.listenerCount=function(i){var a=g?g+i:i,G=this._events[a];return G?G.fn?1:G.length:0},E.prototype.emit=function(i,a,G,F,e,n){var q=g?g+i:i;if(!this._events[q])return!1;var N=this._events[q],J=arguments.length,L,c;if(N.fn){switch(N.once&&this.removeListener(i,N.fn,void 0,!0),J){case 1:return N.fn.call(N.context),!0;case 2:return N.fn.call(N.context,a),!0;case 3:return N.fn.call(N.context,a,G),!0;case 4:return N.fn.call(N.context,a,G,F),!0;case 5:return N.fn.call(N.context,a,G,F,e),!0;case 6:return N.fn.call(N.context,a,G,F,e,n),!0}for(c=1,L=new Array(J-1);c<J;c++)L[c-1]=arguments[c];N.fn.apply(N.context,L)}else{var r=N.length,d;for(c=0;c<r;c++)switch(N[c].once&&this.removeListener(i,N[c].fn,void 0,!0),J){case 1:N[c].fn.call(N[c].context);break;case 2:N[c].fn.call(N[c].context,a);break;case 3:N[c].fn.call(N[c].context,a,G);break;case 4:N[c].fn.call(N[c].context,a,G,F);break;default:if(!L)for(d=1,L=new Array(J-1);d<J;d++)L[d-1]=arguments[d];N[c].fn.apply(N[c].context,L)}}return!0},E.prototype.on=function(i,a,G){return Q(this,i,a,G,!1)},E.prototype.once=function(i,a,G){return Q(this,i,a,G,!0)},E.prototype.removeListener=function(i,a,G,F){var e=g?g+i:i;if(!this._events[e])return this;if(!a)return o(this,e),this;var n=this._events[e];if(n.fn)n.fn===a&&(!F||n.once)&&(!G||n.context===G)&&o(this,e);else{for(var q=0,N=[],J=n.length;q<J;q++)(n[q].fn!==a||F&&!n[q].once||G&&n[q].context!==G)&&N.push(n[q]);N.length?this._events[e]=N.length===1?N[0]:N:o(this,e)}return this},E.prototype.removeAllListeners=function(i){var a;return i?(a=g?g+i:i,this._events[a]&&o(this,a)):(this._events=new B,this._eventsCount=0),this},E.prototype.off=E.prototype.removeListener,E.prototype.addListener=E.prototype.on,E.prefixed=g,E.EventEmitter=E,A.exports=E})(EC);var VE=EC.exports,gg=class extends Error{constructor(I){super(I),this.name="TimeoutError"}};function _E(A,I,g,B){let C,Q=new Promise((o,E)=>{if(typeof I!="number"||I<0)throw new TypeError("Expected `milliseconds` to be a positive number");if(I===Number.POSITIVE_INFINITY){o(A);return}B={customTimers:{setTimeout,clearTimeout},...B},C=B.customTimers.setTimeout.call(void 0,()=>{if(typeof g=="function"){try{o(g())}catch(a){E(a)}return}let t=typeof g=="string"?g:`Promise timed out after ${I} milliseconds`,i=g instanceof Error?g:new gg(t);typeof A.cancel=="function"&&A.cancel(),E(i)},I),(async()=>{try{o(await A)}catch(t){E(t)}finally{B.customTimers.clearTimeout.call(void 0,C)}})()});return Q.clear=()=>{clearTimeout(C),C=void 0},Q}function PE(A,I,g){let B=0,C=A.length;for(;C>0;){let Q=Math.trunc(C/2),o=B+Q;g(A[o],I)<=0?(B=++o,C-=Q+1):C=Q}return B}var Tg=class{constructor(){Object.defineProperty(this,"_queue",{enumerable:!0,configurable:!0,writable:!0,value:[]})}enqueue(I,g){var B;g={priority:0,...g};let C={priority:g.priority,run:I};if(this.size&&((B=this._queue[this.size-1])===null||B===void 0?void 0:B.priority)>=g.priority){this._queue.push(C);return}let Q=PE(this._queue,C,(o,E)=>E.priority-o.priority);this._queue.splice(Q,0,C)}dequeue(){let I=this._queue.shift();return I?.run}filter(I){return this._queue.filter(g=>g.priority===I.priority).map(g=>g.run)}get size(){return this._queue.length}},PI=()=>{},vE=new gg,Bg=class extends VE{constructor(I){var g,B,C,Q;if(super(),Object.defineProperty(this,"_carryoverConcurrencyCount",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_isIntervalIgnored",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_intervalCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_intervalCap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_interval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_intervalEnd",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_intervalId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_timeoutId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_queue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_queueClass",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pendingCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_concurrency",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_isPaused",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_resolveEmpty",{enumerable:!0,configurable:!0,writable:!0,value:PI}),Object.defineProperty(this,"_resolveIdle",{enumerable:!0,configurable:!0,writable:!0,value:PI}),Object.defineProperty(this,"_timeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_throwOnTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),I={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Tg,...I},!(typeof I.intervalCap=="number"&&I.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(B=(g=I.intervalCap)===null||g===void 0?void 0:g.toString())!==null&&B!==void 0?B:""}\` (${typeof I.intervalCap})`);if(I.interval===void 0||!(Number.isFinite(I.interval)&&I.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(Q=(C=I.interval)===null||C===void 0?void 0:C.toString())!==null&&Q!==void 0?Q:""}\` (${typeof I.interval})`);this._carryoverConcurrencyCount=I.carryoverConcurrencyCount,this._isIntervalIgnored=I.intervalCap===Number.POSITIVE_INFINITY||I.interval===0,this._intervalCap=I.intervalCap,this._interval=I.interval,this._queue=new I.queueClass,this._queueClass=I.queueClass,this.concurrency=I.concurrency,this._timeout=I.timeout,this._throwOnTimeout=I.throwOnTimeout===!0,this._isPaused=I.autoStart===!1}get _doesIntervalAllowAnother(){return this._isIntervalIgnored||this._intervalCount<this._intervalCap}get _doesConcurrentAllowAnother(){return this._pendingCount<this._concurrency}_next(){this._pendingCount--,this._tryToStartAnother(),this.emit("next")}_resolvePromises(){this._resolveEmpty(),this._resolveEmpty=PI,this._pendingCount===0&&(this._resolveIdle(),this._resolveIdle=PI,this.emit("idle"))}_onResumeInterval(){this._onInterval(),this._initializeIntervalIfNeeded(),this._timeoutId=void 0}_isIntervalPaused(){let I=Date.now();if(this._intervalId===void 0){let g=this._intervalEnd-I;if(g<0)this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0;else return this._timeoutId===void 0&&(this._timeoutId=setTimeout(()=>{this._onResumeInterval()},g)),!0}return!1}_tryToStartAnother(){if(this._queue.size===0)return this._intervalId&&clearInterval(this._intervalId),this._intervalId=void 0,this._resolvePromises(),!1;if(!this._isPaused){let I=!this._isIntervalPaused();if(this._doesIntervalAllowAnother&&this._doesConcurrentAllowAnother){let g=this._queue.dequeue();return g?(this.emit("active"),g(),I&&this._initializeIntervalIfNeeded(),!0):!1}}return!1}_initializeIntervalIfNeeded(){this._isIntervalIgnored||this._intervalId!==void 0||(this._intervalId=setInterval(()=>{this._onInterval()},this._interval),this._intervalEnd=Date.now()+this._interval)}_onInterval(){this._intervalCount===0&&this._pendingCount===0&&this._intervalId&&(clearInterval(this._intervalId),this._intervalId=void 0),this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0,this._processQueue()}_processQueue(){for(;this._tryToStartAnother(););}get concurrency(){return this._concurrency}set concurrency(I){if(!(typeof I=="number"&&I>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${I}\` (${typeof I})`);this._concurrency=I,this._processQueue()}async add(I,g={}){return new Promise((B,C)=>{let Q=async()=>{this._pendingCount++,this._intervalCount++;try{let E=await(this._timeout===void 0&&g.timeout===void 0?I():_E(Promise.resolve(I()),g.timeout===void 0?this._timeout:g.timeout,()=>{(g.throwOnTimeout===void 0?this._throwOnTimeout:g.throwOnTimeout)&&C(vE)}));B(E),this.emit("completed",E)}catch(o){C(o),this.emit("error",o)}this._next()};this._queue.enqueue(Q,g),this._tryToStartAnother(),this.emit("add")})}async addAll(I,g){return Promise.all(I.map(async B=>this.add(B,g)))}start(){return this._isPaused?(this._isPaused=!1,this._processQueue(),this):this}pause(){this._isPaused=!0}clear(){this._queue=new this._queueClass}async onEmpty(){if(this._queue.size!==0)return new Promise(I=>{let g=this._resolveEmpty;this._resolveEmpty=()=>{g(),I()}})}async onSizeLessThan(I){if(!(this._queue.size<I))return new Promise(g=>{let B=()=>{this._queue.size<I&&(this.removeListener("next",B),g())};this.on("next",B)})}async onIdle(){if(!(this._pendingCount===0&&this._queue.size===0))return new Promise(I=>{let g=this._resolveIdle;this._resolveIdle=()=>{g(),I()}})}get size(){return this._queue.size}sizeBy(I){return this._queue.filter(I).length}get pending(){return this._pendingCount}get isPaused(){return this._isPaused}get timeout(){return this._timeout}set timeout(I){this._timeout=I}},XA=class{constructor(I,g=null,B,C=!1,Q=null,o=!0,E=!0){this.store=I,this._chunkStore=Q,this.path=QA(g),this.keyPrefix=LA(this.path),this.readOnly=C,this.cacheMetadata=o,this.cacheAttrs=E,this.meta=B,this.meta.compressor!==null?this.compressor=vB(this.meta.compressor):this.compressor=null;let t=this.keyPrefix+AC;this.attrs=new Ig(this.store,t,this.readOnly,E)}get chunkStore(){return this._chunkStore?this._chunkStore:this.store}get name(){return this.path.length>0?this.path[0]!=="/"?"/"+this.path:this.path:null}get basename(){let I=this.name;if(I===null)return null;let g=I.split("/");return g[g.length-1]}get shape(){return this.meta.shape}get chunks(){return this.meta.chunks}get chunkSize(){return this.chunks.reduce((I,g)=>I*g,1)}get dtype(){return this.meta.dtype}get fillValue(){let I=this.meta.fill_value;return I==="NaN"?NaN:I==="Infinity"?1/0:I==="-Infinity"?-1/0:this.meta.fill_value}get nDims(){return this.meta.shape.length}get size(){return this.meta.shape.reduce((I,g)=>I*g,1)}get length(){return this.shape[0]}get _chunkDataShape(){if(this.shape.length===0)return[1];{let I=[];for(let g=0;g<this.shape.length;g++)I[g]=Math.ceil(this.shape[g]/this.chunks[g]);return I}}get chunkDataShape(){return this._chunkDataShape}get numChunks(){return this.chunkDataShape.reduce((I,g)=>I*g,1)}static async create(I,g=null,B=!1,C=null,Q=!0,o=!0){let E=await this.loadMetadataForConstructor(I,g);return new XA(I,g,E,B,C,Q,o)}static async loadMetadataForConstructor(I,g){try{g=QA(g);let B=LA(g),C=await I.getItem(B+$I);return Ag(C)}catch(B){throw await sA(I,g)?new NA(g??""):new Error("Failed to load metadata for ZarrArray:"+B.toString())}}async reloadMetadata(){let I=this.keyPrefix+$I,g=this.store.getItem(I);return this.meta=Ag(await g),this.meta}async refreshMetadata(){this.cacheMetadata||await this.reloadMetadata()}get(I=null,g={}){return this.getBasicSelection(I,!1,g)}getRaw(I=null,g={}){return this.getBasicSelection(I,!0,g)}async getBasicSelection(I,g=!1,{concurrencyLimit:B=10,progressCallback:C}={}){if(this.cacheMetadata||await this.reloadMetadata(),this.shape.length===0)throw new Error("Shape [] indexing is not supported yet");return this.getBasicSelectionND(I,g,B,C)}getBasicSelectionND(I,g,B,C){let Q=new jI(I,this);return this.getSelection(Q,g,B,C)}async getSelection(I,g,B,C){let Q=this.dtype,o=I.shape,E=I.shape.reduce((a,G)=>a*G,1);if(g&&E===this.chunkSize){let a=I.iter(),G=a.next();if(G.done===!1&&a.next().done===!0){let F=G.value;return await this.decodeDirectToRawArray(F,o,E)}}let t=g?new SA(null,o,Q):new z(null,o,Q);if(E===0)return t;let i=new Bg({concurrency:B});if(C){let a=0,G=0;for(let F of I.iter())G+=1;C({progress:0,queueSize:G});for(let F of I.iter())(async()=>(await i.add(()=>this.chunkGetItem(F.chunkCoords,F.chunkSelection,t,F.outSelection,I.dropAxes)),a+=1,C({progress:a,queueSize:G})))()}else for(let a of I.iter())i.add(()=>this.chunkGetItem(a.chunkCoords,a.chunkSelection,t,a.outSelection,I.dropAxes));return await i.onIdle(),t.shape.length===0?t.data[0]:t}async chunkGetItem(I,g,B,C,Q){if(I.length!==this._chunkDataShape.length)throw new P(`Inconsistent shapes: chunkCoordsLength: ${I.length}, cDataShapeLength: ${this.chunkDataShape.length}`);let o=this.chunkKey(I);try{let E=await this.chunkStore.getItem(o),t=await this.decodeChunk(E);if(B instanceof z){if(cE(C)&&PB(g,this.chunks)&&!this.meta.filters){B.set(C,this.toNestedArray(t));return}let a=this.toNestedArray(t).get(g);if(Q!==null)throw new Error("Drop axes is not supported yet");B.set(C,a)}else B.set(C,this.chunkBufferToRawArray(t),g)}catch(E){if(vI(E))this.fillValue!==null&&B.set(C,this.fillValue);else throw E}}async getRawChunk(I,g){if(I.length!==this.shape.length)throw new Error(`Chunk coordinates ${I.join(".")} do not correspond to shape ${this.shape}.`);try{for(let E=0;E<I.length;E++){let t=Math.ceil(this.shape[E]/this.chunks[E]);I[E]=Xg(I[E],t)}}catch(E){throw E instanceof EA?new EA(`index ${I.join(".")} is out of bounds for shape: ${this.shape} and chunks ${this.chunks}`):E}let B=this.chunkKey(I),C=this.chunkStore.getItem(B,g?.storeOptions),Q=await this.decodeChunk(await C),o=this.chunks.filter(E=>E!==1);return new SA(Q,o,this.dtype)}chunkKey(I){var g;let B=(g=this.meta.dimension_separator)!==null&&g!==void 0?g:".";return this.keyPrefix+I.join(B)}ensureByteArray(I){return typeof I=="string"?new Uint8Array(Buffer.from(I).buffer):new Uint8Array(I)}toTypedArray(I){return new(BA(this.dtype))(I)}toNestedArray(I){let g=this.ensureByteArray(I).buffer;return new z(g,this.chunks,this.dtype)}async decodeChunk(I){let g=this.ensureByteArray(I);if(this.compressor!==null&&(g=await(await this.compressor).decode(g)),this.dtype.includes(">")&&$B(this.toTypedArray(g.buffer)),this.meta.order==="F"&&this.nDims>1){let B=this.toTypedArray(g.buffer),C=new(BA(this.dtype))(B.length);return lE(B,C,this.chunks),C.buffer}return g.buffer}chunkBufferToRawArray(I){return new SA(I,this.chunks,this.dtype)}async decodeDirectToRawArray({chunkCoords:I},g,B){let C=this.chunkKey(I);try{let Q=await this.chunkStore.getItem(C);return new SA(await this.decodeChunk(Q),g,this.dtype)}catch(Q){if(vI(Q)){let o=new(BA(this.dtype))(B);return new SA(o.fill(this.fillValue),g)}else throw Q}}async set(I=null,g,B={}){await this.setBasicSelection(I,g,B)}async setBasicSelection(I,g,{concurrencyLimit:B=10,progressCallback:C}={}){if(this.readOnly)throw new X("Object is read only");if(this.cacheMetadata||await this.reloadMetadata(),this.shape.length===0)throw new Error("Shape [] indexing is not supported yet");await this.setBasicSelectionND(I,g,B,C)}async setBasicSelectionND(I,g,B,C){let Q=new jI(I,this);await this.setSelection(Q,g,B,C)}getChunkValue(I,g,B,C){let Q;if(C.length===0)Q=B;else if(typeof B=="number")Q=B;else if(Q=B.get(I.outSelection),g.dropAxes!==null)throw new Error("Handling drop axes not supported yet");return Q}async setSelection(I,g,B,C){let Q=I.shape;if(Q.length!==0){if(typeof g!="number")if(g instanceof z){if(!qE(g.shape,Q))throw new P(`Shape mismatch in source NestedArray and set selection: ${g.shape} and ${Q}`)}else throw new Error("Unknown data type for setting :(")}let o=new Bg({concurrency:B});if(C){let E=0;for(let i of I.iter())E+=1;let t=0;C({progress:0,queueSize:E});for(let i of I.iter()){let a=this.getChunkValue(i,I,g,Q);(async()=>(await o.add(()=>this.chunkSetItem(i.chunkCoords,i.chunkSelection,a)),t+=1,C({progress:t,queueSize:E})))()}}else for(let E of I.iter()){let t=this.getChunkValue(E,I,g,Q);o.add(()=>this.chunkSetItem(E.chunkCoords,E.chunkSelection,t))}await o.onIdle()}async chunkSetItem(I,g,B){if(this.meta.order==="F"&&this.nDims>1)throw new Error("Setting content for arrays in F-order is not supported.");let C=this.chunkKey(I),Q=null,o=BA(this.dtype),E=this.chunkSize;if(PB(g,this.chunks))typeof B=="number"?(Q=new o(E),Q.fill(B)):Q=B.flatten();else{let i;try{let G=await this.chunkStore.getItem(C),F=await this.decodeChunk(G);i=this.toTypedArray(F)}catch(G){if(vI(G))i=new o(E),this.fillValue!==null&&i.fill(this.fillValue);else throw G}let a=new z(i,this.chunks,this.dtype);a.set(g,B),Q=a.flatten()}let t=await this.encodeChunk(Q);this.chunkStore.setItem(C,t)}async encodeChunk(I){if(this.dtype.includes(">")&&(I=fE(I)),this.compressor!==null){let g=new Uint8Array(I.buffer);return(await(await this.compressor).encode(g)).buffer}return I.buffer}},Cg=class{constructor(I={}){this.root=I}proxy(){return Eg(this)}getParent(I){let g=this.root,B=I.split("/");for(let C of B.slice(0,B.length-1))if(g=g[C],!g)throw Error(I);return[g,B[B.length-1]]}requireParent(I){let g=this.root,B=I.split("/");for(let C of B.slice(0,B.length-1))g[C]===void 0&&(g[C]={}),g=g[C];return[g,B[B.length-1]]}getItem(I){let[g,B]=this.getParent(I),C=g[B];if(C===void 0)throw new JA(I);return C}setItem(I,g){let[B,C]=this.requireParent(I);return B[C]=g,!0}deleteItem(I){let[g,B]=this.getParent(I);return delete g[B]}containsItem(I){try{return this.getItem(I)!==void 0}catch{return!1}}keys(){throw new Error("Method not implemented.")}},tA;(function(A){A.HEAD="HEAD",A.GET="GET",A.PUT="PUT"})(tA||(tA={}));var jE=[tA.HEAD,tA.GET,tA.PUT],EI=class{constructor(I,g={}){this.url=I;let{fetchOptions:B={},supportedMethods:C=jE}=g;this.fetchOptions=B,this.supportedMethods=new Set(C)}keys(){throw new Error("Method not implemented.")}async getItem(I,g){let B=dg(this.url,I),C=await fetch(B,{...this.fetchOptions,...g});if(C.status===404)throw new JA(I);if(C.status!==200)throw new QI(String(C.status));return iI?Buffer.from(await C.arrayBuffer()):C.arrayBuffer()}async setItem(I,g){if(!this.supportedMethods.has(tA.PUT))throw new Error("HTTP PUT no a supported method for store.");let B=dg(this.url,I);return typeof g=="string"&&(g=new TextEncoder().encode(g).buffer),(await fetch(B,{...this.fetchOptions,method:tA.PUT,body:g})).status.toString()[0]==="2"}deleteItem(I){throw new Error("Method not implemented.")}async containsItem(I){let g=dg(this.url,I),B=this.supportedMethods.has(tA.HEAD)?tA.HEAD:tA.GET;return(await fetch(g,{...this.fetchOptions,method:B})).status===200}};async function OA({shape:A,chunks:I=!0,dtype:g="<i4",compressor:B=null,fillValue:C=null,order:Q="C",store:o,overwrite:E=!1,path:t,chunkStore:i,filters:a,cacheMetadata:G=!0,cacheAttrs:F=!0,readOnly:e=!1,dimensionSeparator:n}){return o=Qg(o),await pE(o,A,I,g,t,B,C,Q,E,i,a,n),await XA.create(o,t,e,i,G,F)}async function iC(A,I={}){return I.fillValue=null,OA({shape:A,...I})}async function oC(A,I={}){return I.fillValue=0,OA({shape:A,...I})}async function aC(A,I={}){return I.fillValue=1,OA({shape:A,...I})}async function DC(A,I,g={}){return g.fillValue=I,OA({shape:A,...g})}async function mg(A,I={}){let g=null;A instanceof z?(g=A.shape,I.dtype=I.dtype===void 0?A.dtype:I.dtype):g=A.byteLength;let B=I.readOnly===void 0?!1:I.readOnly;I.readOnly=!1;let C=await OA({shape:g,...I});return await C.set(null,A),C.readOnly=B,C}function Qg(A){return A===void 0?new Cg:typeof A=="string"?new EI(A):A}var nA=class{constructor(I,g=null,B,C=!1,Q=null,o=!0){this.store=I,this._chunkStore=Q,this.path=QA(g),this.keyPrefix=LA(this.path),this.readOnly=C,this.meta=B;let E=this.keyPrefix+AC;this.attrs=new Ig(this.store,E,this.readOnly,o)}get name(){return this.path.length>0?this.path[0]!=="/"?"/"+this.path:this.path:"/"}get basename(){let I=this.name.split("/");return I[I.length-1]}get chunkStore(){return this._chunkStore?this._chunkStore:this.store}static async create(I,g=null,B=!1,C=null,Q=!0){let o=await this.loadMetadataForConstructor(I,g);return new nA(I,g,o,B,C,Q)}static async loadMetadataForConstructor(I,g){g=QA(g);let B=LA(g);try{let C=await I.getItem(B+Pg);return Ag(C)}catch{throw await rA(I,g)?new CA(g):new TA(g)}}itemPath(I){let g=typeof I=="string"&&I.length>0&&I[0]==="/",B=QA(I);return!g&&this.path.length>0?this.keyPrefix+B:B}async createGroup(I,g=!1){if(this.readOnly)throw new X("group is read only");let B=this.itemPath(I);return await GI(this.store,B,this._chunkStore,g),nA.create(this.store,B,this.readOnly,this._chunkStore,this.attrs.cache)}async requireGroup(I,g=!1){if(this.readOnly)throw new X("group is read only");let B=this.itemPath(I);return await sA(this.store,B)||await GI(this.store,B,this._chunkStore,g),nA.create(this.store,B,this.readOnly,this._chunkStore,this.attrs.cache)}getOptsForArrayCreation(I,g={}){let B=this.itemPath(I);return g.path=B,g.cacheAttrs===void 0&&(g.cacheAttrs=this.attrs.cache),g.store=this.store,g.chunkStore=this.chunkStore,g}array(I,g,B,C){if(this.readOnly)throw new X("group is read only");return B=this.getOptsForArrayCreation(I,B),B.overwrite=C===void 0?B.overwrite:C,mg(g,B)}empty(I,g,B={}){if(this.readOnly)throw new X("group is read only");return B=this.getOptsForArrayCreation(I,B),iC(g,B)}zeros(I,g,B={}){if(this.readOnly)throw new X("group is read only");return B=this.getOptsForArrayCreation(I,B),oC(g,B)}ones(I,g,B={}){if(this.readOnly)throw new X("group is read only");return B=this.getOptsForArrayCreation(I,B),aC(g,B)}full(I,g,B,C={}){if(this.readOnly)throw new X("group is read only");return C=this.getOptsForArrayCreation(I,C),DC(g,B,C)}createDataset(I,g,B,C){if(this.readOnly)throw new X("group is read only");C=this.getOptsForArrayCreation(I,C);let Q;if(B===void 0){if(g===void 0)throw new P("Shape must be set if no data is passed to CreateDataset");Q=OA({shape:g,...C})}else Q=mg(B,C);return Q}async getItem(I){let g=this.itemPath(I);if(await rA(this.store,g))return XA.create(this.store,g,this.readOnly,this.chunkStore,void 0,this.attrs.cache);if(await sA(this.store,g))return nA.create(this.store,g,this.readOnly,this._chunkStore,this.attrs.cache);throw new JA(I)}async setItem(I,g){return await this.array(I,g,{},!0),!0}async deleteItem(I){throw this.readOnly?new X("group is read only"):new Error("Method not implemented.")}async containsItem(I){let g=this.itemPath(I);return await rA(this.store,g)||sA(this.store,g)}proxy(){return Eg(this)}};async function $g(A,I=null,g="a",B,C=!0){if(A=Qg(A),B!==void 0&&(B=Qg(A)),I=QA(I),g==="r"||g==="r+"){if(!await sA(A,I))throw await rA(A,I)?new CA(I):new TA(I)}else if(g==="w")await GI(A,I,B,!0);else if(g==="a"){if(!await sA(A,I)){if(await rA(A,I))throw new CA(I);await GI(A,I,B)}}else if(g==="w-"||g==="x"){if(await rA(A,I))throw new CA(I);if(await sA(A,I))throw new NA(I);await GI(A,I,B)}else throw new P(`Invalid mode argument: ${g}`);let Q=g==="r";return nA.create(A,I,Q,B,C)}var zE=4,tC=0,sC=1,$E=2;function sI(A){let I=A.length;for(;--I>=0;)A[I]=0}var Ai=0,BQ=1,Ii=2,gi=3,Bi=258,GB=29,dI=256,kI=dI+1+GB,tI=30,SB=19,CQ=2*kI+1,VA=15,AB=16,Ci=7,nB=256,QQ=16,EQ=17,iQ=18,eB=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),eg=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),Qi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),oQ=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ei=512,UA=new Array((kI+2)*2);sI(UA);var RI=new Array(tI*2);sI(RI);var JI=new Array(Ei);sI(JI);var qI=new Array(Bi-gi+1);sI(qI);var rB=new Array(GB);sI(rB);var Gg=new Array(tI);sI(Gg);function IB(A,I,g,B,C){this.static_tree=A,this.extra_bits=I,this.extra_base=g,this.elems=B,this.max_length=C,this.has_stree=A&&A.length}var aQ,DQ,tQ;function gB(A,I){this.dyn_tree=A,this.max_code=0,this.stat_desc=I}var sQ=A=>A<256?JI[A]:JI[256+(A>>>7)],LI=(A,I)=>{A.pending_buf[A.pending++]=I&255,A.pending_buf[A.pending++]=I>>>8&255},v=(A,I,g)=>{A.bi_valid>AB-g?(A.bi_buf|=I<<A.bi_valid&65535,LI(A,A.bi_buf),A.bi_buf=I>>AB-A.bi_valid,A.bi_valid+=g-AB):(A.bi_buf|=I<<A.bi_valid&65535,A.bi_valid+=g)},eA=(A,I,g)=>{v(A,g[I*2],g[I*2+1])},hQ=(A,I)=>{let g=0;do g|=A&1,A>>>=1,g<<=1;while(--I>0);return g>>>1},ii=A=>{A.bi_valid===16?(LI(A,A.bi_buf),A.bi_buf=0,A.bi_valid=0):A.bi_valid>=8&&(A.pending_buf[A.pending++]=A.bi_buf&255,A.bi_buf>>=8,A.bi_valid-=8)},oi=(A,I)=>{let g=I.dyn_tree,B=I.max_code,C=I.stat_desc.static_tree,Q=I.stat_desc.has_stree,o=I.stat_desc.extra_bits,E=I.stat_desc.extra_base,t=I.stat_desc.max_length,i,a,G,F,e,n,q=0;for(F=0;F<=VA;F++)A.bl_count[F]=0;for(g[A.heap[A.heap_max]*2+1]=0,i=A.heap_max+1;i<CQ;i++)a=A.heap[i],F=g[g[a*2+1]*2+1]+1,F>t&&(F=t,q++),g[a*2+1]=F,!(a>B)&&(A.bl_count[F]++,e=0,a>=E&&(e=o[a-E]),n=g[a*2],A.opt_len+=n*(F+e),Q&&(A.static_len+=n*(C[a*2+1]+e)));if(q!==0){do{for(F=t-1;A.bl_count[F]===0;)F--;A.bl_count[F]--,A.bl_count[F+1]+=2,A.bl_count[t]--,q-=2}while(q>0);for(F=t;F!==0;F--)for(a=A.bl_count[F];a!==0;)G=A.heap[--i],!(G>B)&&(g[G*2+1]!==F&&(A.opt_len+=(F-g[G*2+1])*g[G*2],g[G*2+1]=F),a--)}},eQ=(A,I,g)=>{let B=new Array(VA+1),C=0,Q,o;for(Q=1;Q<=VA;Q++)B[Q]=C=C+g[Q-1]<<1;for(o=0;o<=I;o++){let E=A[o*2+1];E!==0&&(A[o*2]=hQ(B[E]++,E))}},ai=()=>{let A,I,g,B,C,Q=new Array(VA+1);for(g=0,B=0;B<GB-1;B++)for(rB[B]=g,A=0;A<1<<eB[B];A++)qI[g++]=B;for(qI[g-1]=B,C=0,B=0;B<16;B++)for(Gg[B]=C,A=0;A<1<<eg[B];A++)JI[C++]=B;for(C>>=7;B<tI;B++)for(Gg[B]=C<<7,A=0;A<1<<eg[B]-7;A++)JI[256+C++]=B;for(I=0;I<=VA;I++)Q[I]=0;for(A=0;A<=143;)UA[A*2+1]=8,A++,Q[8]++;for(;A<=255;)UA[A*2+1]=9,A++,Q[9]++;for(;A<=279;)UA[A*2+1]=7,A++,Q[7]++;for(;A<=287;)UA[A*2+1]=8,A++,Q[8]++;for(eQ(UA,kI+1,Q),A=0;A<tI;A++)RI[A*2+1]=5,RI[A*2]=hQ(A,5);aQ=new IB(UA,eB,dI+1,kI,VA),DQ=new IB(RI,eg,0,tI,VA),tQ=new IB(new Array(0),Qi,0,SB,Ci)},yQ=A=>{let I;for(I=0;I<kI;I++)A.dyn_ltree[I*2]=0;for(I=0;I<tI;I++)A.dyn_dtree[I*2]=0;for(I=0;I<SB;I++)A.bl_tree[I*2]=0;A.dyn_ltree[nB*2]=1,A.opt_len=A.static_len=0,A.last_lit=A.matches=0},FQ=A=>{A.bi_valid>8?LI(A,A.bi_buf):A.bi_valid>0&&(A.pending_buf[A.pending++]=A.bi_buf),A.bi_buf=0,A.bi_valid=0},Di=(A,I,g,B)=>{FQ(A),B&&(LI(A,g),LI(A,~g)),A.pending_buf.set(A.window.subarray(I,I+g),A.pending),A.pending+=g},hC=(A,I,g,B)=>{let C=I*2,Q=g*2;return A[C]<A[Q]||A[C]===A[Q]&&B[I]<=B[g]},BB=(A,I,g)=>{let B=A.heap[g],C=g<<1;for(;C<=A.heap_len&&(C<A.heap_len&&hC(I,A.heap[C+1],A.heap[C],A.depth)&&C++,!hC(I,B,A.heap[C],A.depth));)A.heap[g]=A.heap[C],g=C,C<<=1;A.heap[g]=B},eC=(A,I,g)=>{let B,C,Q=0,o,E;if(A.last_lit!==0)do B=A.pending_buf[A.d_buf+Q*2]<<8|A.pending_buf[A.d_buf+Q*2+1],C=A.pending_buf[A.l_buf+Q],Q++,B===0?eA(A,C,I):(o=qI[C],eA(A,o+dI+1,I),E=eB[o],E!==0&&(C-=rB[o],v(A,C,E)),B--,o=sQ(B),eA(A,o,g),E=eg[o],E!==0&&(B-=Gg[o],v(A,B,E)));while(Q<A.last_lit);eA(A,nB,I)},yB=(A,I)=>{let g=I.dyn_tree,B=I.stat_desc.static_tree,C=I.stat_desc.has_stree,Q=I.stat_desc.elems,o,E,t=-1,i;for(A.heap_len=0,A.heap_max=CQ,o=0;o<Q;o++)g[o*2]!==0?(A.heap[++A.heap_len]=t=o,A.depth[o]=0):g[o*2+1]=0;for(;A.heap_len<2;)i=A.heap[++A.heap_len]=t<2?++t:0,g[i*2]=1,A.depth[i]=0,A.opt_len--,C&&(A.static_len-=B[i*2+1]);for(I.max_code=t,o=A.heap_len>>1;o>=1;o--)BB(A,g,o);i=Q;do o=A.heap[1],A.heap[1]=A.heap[A.heap_len--],BB(A,g,1),E=A.heap[1],A.heap[--A.heap_max]=o,A.heap[--A.heap_max]=E,g[i*2]=g[o*2]+g[E*2],A.depth[i]=(A.depth[o]>=A.depth[E]?A.depth[o]:A.depth[E])+1,g[o*2+1]=g[E*2+1]=i,A.heap[1]=i++,BB(A,g,1);while(A.heap_len>=2);A.heap[--A.heap_max]=A.heap[1],oi(A,I),eQ(g,t,A.bl_count)},yC=(A,I,g)=>{let B,C=-1,Q,o=I[0*2+1],E=0,t=7,i=4;for(o===0&&(t=138,i=3),I[(g+1)*2+1]=65535,B=0;B<=g;B++)Q=o,o=I[(B+1)*2+1],!(++E<t&&Q===o)&&(E<i?A.bl_tree[Q*2]+=E:Q!==0?(Q!==C&&A.bl_tree[Q*2]++,A.bl_tree[QQ*2]++):E<=10?A.bl_tree[EQ*2]++:A.bl_tree[iQ*2]++,E=0,C=Q,o===0?(t=138,i=3):Q===o?(t=6,i=3):(t=7,i=4))},FC=(A,I,g)=>{let B,C=-1,Q,o=I[0*2+1],E=0,t=7,i=4;for(o===0&&(t=138,i=3),B=0;B<=g;B++)if(Q=o,o=I[(B+1)*2+1],!(++E<t&&Q===o)){if(E<i)do eA(A,Q,A.bl_tree);while(--E!==0);else Q!==0?(Q!==C&&(eA(A,Q,A.bl_tree),E--),eA(A,QQ,A.bl_tree),v(A,E-3,2)):E<=10?(eA(A,EQ,A.bl_tree),v(A,E-3,3)):(eA(A,iQ,A.bl_tree),v(A,E-11,7));E=0,C=Q,o===0?(t=138,i=3):Q===o?(t=6,i=3):(t=7,i=4)}},ti=A=>{let I;for(yC(A,A.dyn_ltree,A.l_desc.max_code),yC(A,A.dyn_dtree,A.d_desc.max_code),yB(A,A.bl_desc),I=SB-1;I>=3&&A.bl_tree[oQ[I]*2+1]===0;I--);return A.opt_len+=3*(I+1)+5+5+4,I},si=(A,I,g,B)=>{let C;for(v(A,I-257,5),v(A,g-1,5),v(A,B-4,4),C=0;C<B;C++)v(A,A.bl_tree[oQ[C]*2+1],3);FC(A,A.dyn_ltree,I-1),FC(A,A.dyn_dtree,g-1)},hi=A=>{let I=4093624447,g;for(g=0;g<=31;g++,I>>>=1)if(I&1&&A.dyn_ltree[g*2]!==0)return tC;if(A.dyn_ltree[9*2]!==0||A.dyn_ltree[10*2]!==0||A.dyn_ltree[13*2]!==0)return sC;for(g=32;g<dI;g++)if(A.dyn_ltree[g*2]!==0)return sC;return tC},wC=!1,ei=A=>{wC||(ai(),wC=!0),A.l_desc=new gB(A.dyn_ltree,aQ),A.d_desc=new gB(A.dyn_dtree,DQ),A.bl_desc=new gB(A.bl_tree,tQ),A.bi_buf=0,A.bi_valid=0,yQ(A)},wQ=(A,I,g,B)=>{v(A,(Ai<<1)+(B?1:0),3),Di(A,I,g,!0)},yi=A=>{v(A,BQ<<1,3),eA(A,nB,UA),ii(A)},Fi=(A,I,g,B)=>{let C,Q,o=0;A.level>0?(A.strm.data_type===$E&&(A.strm.data_type=hi(A)),yB(A,A.l_desc),yB(A,A.d_desc),o=ti(A),C=A.opt_len+3+7>>>3,Q=A.static_len+3+7>>>3,Q<=C&&(C=Q)):C=Q=g+5,g+4<=C&&I!==-1?wQ(A,I,g,B):A.strategy===zE||Q===C?(v(A,(BQ<<1)+(B?1:0),3),eC(A,UA,RI)):(v(A,(Ii<<1)+(B?1:0),3),si(A,A.l_desc.max_code+1,A.d_desc.max_code+1,o+1),eC(A,A.dyn_ltree,A.dyn_dtree)),yQ(A),B&&FQ(A)},wi=(A,I,g)=>(A.pending_buf[A.d_buf+A.last_lit*2]=I>>>8&255,A.pending_buf[A.d_buf+A.last_lit*2+1]=I&255,A.pending_bu