@az0uz/zarr
Version:
Javascript implementation of Zarr
3 lines (2 loc) • 45.2 kB
JavaScript
const t=new Map;function e(e,r){t.set(e,r)}async function r(e){if(!t.has(e.id))throw new Error(`Compression codec ${e.id} is not supported by Zarr.js yet.`);return(await t.get(e.id)()).fromConfig(e)}function n(t){return new Proxy(t,{set:(t,e,r,n)=>t.setItem(e,r),get:(t,e,r)=>t.getItem(e),deleteProperty:(t,e)=>t.deleteItem(e),has:(t,e)=>t.containsItem(e)})}function i(t){return"object"==typeof(e=t)&&null!==e&&"__zarr__"in e&&"KeyError"===t.__zarr__;var e}class s extends Error{constructor(t){super(`path ${t} contains an array`),this.__zarr__="ContainsArrayError",Object.setPrototypeOf(this,s.prototype)}}class o extends Error{constructor(t){super(`path ${t} contains a group`),this.__zarr__="ContainsGroupError",Object.setPrototypeOf(this,o.prototype)}}class a extends Error{constructor(t){super(`array not found at path ${t}`),this.__zarr__="ArrayNotFoundError",Object.setPrototypeOf(this,a.prototype)}}class h extends Error{constructor(t){super(`group not found at path ${t}`),this.__zarr__="GroupNotFoundError",Object.setPrototypeOf(this,h.prototype)}}class u extends Error{constructor(t){super(`nothing found at path ${t}`),this.__zarr__="PathNotFoundError",Object.setPrototypeOf(this,u.prototype)}}class c extends Error{constructor(t){super(t),this.__zarr__="PermissionError",Object.setPrototypeOf(this,c.prototype)}}class l extends Error{constructor(t){super(`key ${t} not present`),this.__zarr__="KeyError",Object.setPrototypeOf(this,l.prototype)}}class f extends RangeError{constructor(t,e){super(`too many indices for array; expected ${e.length}, got ${t.length}`),this.__zarr__="TooManyIndicesError",Object.setPrototypeOf(this,f.prototype)}}class d extends RangeError{constructor(t){super(t),this.__zarr__="BoundsCheckError",Object.setPrototypeOf(this,d.prototype)}}class p extends RangeError{constructor(t,e,r,n){super(`slice arguments slice(${t}, ${e}, ${r}) invalid: ${n}`),this.__zarr__="InvalidSliceError",Object.setPrototypeOf(this,p.prototype)}}class y extends Error{constructor(){super("Negative step size is not supported when indexing."),this.__zarr__="NegativeStepError",Object.setPrototypeOf(this,y.prototype)}}class w extends Error{constructor(t){super(t),this.__zarr__="ValueError",Object.setPrototypeOf(this,w.prototype)}}class m extends Error{constructor(t){super(t),this.__zarr__="HTTPError",Object.setPrototypeOf(this,m.prototype)}}function g(t,e,r=null){if(void 0===t)throw new p(t,e,r,"The first argument must not be undefined");if("string"==typeof t&&":"!==t||"string"==typeof e&&":"!==e)throw new p(t,e,r,'Arguments can only be integers, ":" or null');return void 0===e&&(e=t,t=null),{start:":"===t?null:t,stop:":"===e?null:e,step:r,_slice:!0}}function _(t,e){let r,n,i;i=null===t.step?1:t.step,null===t.start?r=i<0?Number.MAX_SAFE_INTEGER:0:(r=t.start,r<0&&(r+=e)),null===t.stop?n=i<0?-Number.MAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER:(n=t.stop,n<0&&(n+=e));const s=function(t,e,r,n){if(t<0?(t+=n)<0&&(t=r<0?-1:0):t>=n&&(t=r<0?n-1:n),e<0?(e+=n)<0&&(e=r<0?-1:0):e>=n&&(e=r<0?n-1:n),r<0){if(e<t)return[t,e,r,Math.floor((t-e-1)/-r+1)]}else if(t<e)return[t,e,r,Math.floor((e-t-1)/r+1)];return[t,e,r,0]}(r,n,i,e);if(r=s[0],n=s[1],i=s[2],e=s[3],0===i)throw new Error("Step size 0 is invalid");return[r,n,i,e]}function v(t){return Array.isArray(t)?t:[t]}function b(t,e){const r=[],n=[];for(let i=0;i<t.length;i++){const s=t[i];if("number"==typeof s)r.push(s);else{const t=_(s,e[i]),o=t[3];n.push(o),r.push(t)}}return[r,n]}function I(t,e,r=!1){t=function(t,e){t=v(t);let r=-1,n=0;for(let e=0;e<t.length;e++)"..."===t[e]&&(r=e,n+=1);if(n>1)throw new RangeError("an index can only have a single ellipsis ('...')");if(1===n){const n=r,i=t.length-(n+1),s=t.length-1;if(s>=e.length)t=t.filter((t=>"..."!==t));else{const r=e.length-s;let o=t.slice(0,n).concat(new Array(r).fill(null));i>0&&(o=o.concat(t.slice(t.length-i))),t=o}}if(t.length<e.length){const r=e.length-t.length;t=t.concat(new Array(r).fill(null))}return function(t,e){if(t.length>e.length)throw new f(t,e)}(t,e),t}(t,e);for(let n=0;n<t.length;n++){const i=t[n];if("number"==typeof i)t[n]=r?g(i,i+1,1):S(i,e[n]);else{if(E(i))throw new TypeError("Integer array selections are not supported (yet)");":"!==i&&null!==i||(t[n]=g(null,null,1))}}return t}function S(t,e){if(t<0&&(t=e+t),t>=e||t<0)throw new d(`index out of bounds for dimension with length ${e}`);return t}function E(t){if(!Array.isArray(t))return!1;for(const e of t)if("number"!=typeof e)return!1;return!0}function A(t){return null!==t&&!0===t._slice}function O(t){return A(t)&&(null===t.step||1===t.step)}class k{constructor(t,e){t=I(t,e.shape),this.dimIndexers=[];const r=e.shape;for(let n=0;n<r.length;n++){let i=t[n];const s=r[n],o=e.chunks[n];if(null===i&&(i=g(null)),"number"==typeof i)this.dimIndexers.push(new C(i,s,o));else{if(!A(i))throw new RangeError(`Unspported selection item for basic indexing; expected integer or slice, got ${i}`);this.dimIndexers.push(new P(i,s,o))}}this.shape=[];for(const t of this.dimIndexers)t instanceof P&&this.shape.push(t.numItems);this.dropAxes=null}*iter(){const t=function*(...t){if(0===t.length)return;const e=t.map((t=>t())),r=e.map((t=>t.next()));for(let n=0;;){if(r[n].done){if(e[n]=t[n](),r[n]=e[n].next(),++n>=e.length)return}else yield r.map((({value:t})=>t)),n=0;r[n]=e[n].next()}}(...this.dimIndexers.map((t=>()=>t.iter())));for(const e of t){const t=[],r=[],n=[];for(const i of e)t.push(i.dimChunkIndex),r.push(i.dimChunkSelection),null!==i.dimOutSelection&&n.push(i.dimOutSelection);yield{chunkCoords:t,chunkSelection:r,outSelection:n}}}}class C{constructor(t,e,r){t=S(t,e),this.dimSelection=t,this.dimLength=e,this.dimChunkLength=r,this.numItems=1}*iter(){const t=Math.floor(this.dimSelection/this.dimChunkLength),e=t*this.dimChunkLength,r=this.dimSelection-e;yield{dimChunkIndex:t,dimChunkSelection:r,dimOutSelection:null}}}class P{constructor(t,e,r){const[n,i,s]=_(t,e);if(this.start=n,this.stop=i,this.step=s,this.step<1)throw new y;this.dimLength=e,this.dimChunkLength=r,this.numItems=Math.max(0,Math.ceil((this.stop-this.start)/this.step)),this.numChunks=Math.ceil(this.dimLength/this.dimChunkLength)}*iter(){const t=Math.floor(this.start/this.dimChunkLength),e=Math.ceil(this.stop/this.dimChunkLength);for(let r=t;r<e;r++){const t=r*this.dimChunkLength,e=Math.min(this.dimLength,(r+1)*this.dimChunkLength),n=e-t;let i,s,o;if(this.start<t){i=0;const e=(t-this.start)%this.step;e>0&&(i+=this.step-e),o=Math.ceil((t-this.start)/this.step)}else i=this.start-t,o=0;s=this.stop>e?n:this.stop-t;const a=g(i,s,this.step),h=g(o,o+Math.ceil((s-i)/this.step));yield{dimChunkIndex:r,dimChunkSelection:a,dimOutSelection:h}}}}const T="undefined"!=typeof process&&process.versions&&process.versions.node;function x(){}function N(t){if(null===t)return"";for(t instanceof String&&(t=t.valueOf()),t=t.replace(/\\/g,"/");t.length>0&&"/"===t[0];)t=t.slice(1);for(;t.length>0&&"/"===t[t.length-1];)t=t.slice(0,t.length-1);const e=(t=t.replace(/\/\/+/g,"/")).split("/");for(const t of e)if("."===t||".."===t)throw Error("path containing '.' or '..' segment not allowed");return t}function j(t){return"number"==typeof t&&(t=[t]),t.map((t=>Math.floor(t)))}function M(t,e){if(null===t)return!0;Array.isArray(t)||(t=[t]);for(let r=0;r<Math.min(t.length,e.length);r++){const n=t[r];if(null!==n){if(A(n)){const t=n,i=1===t.step||null===t.step;if(null===t.start&&null===t.stop&&i)continue;if(t.stop-t.start===e[r]&&i)continue;return!1}return!1}}return!0}function z(t,e){const r="string"==typeof t?new URL(t):t;r.pathname.endsWith("/")||(r.pathname+="/");const n=new URL(e,r);return n.search=r.search,n.href}function $(t){const e=t.BYTES_PER_ELEMENT;if(1===e)return;if(T){const r=Buffer.from(t.buffer,t.byteOffset,t.length*e);return 2===e&&r.swap16(),4===e&&r.swap32(),void(8===e&&r.swap64())}const r=new Uint8Array(t.buffer,t.byteOffset,t.length*e),n=e/2,i=e-1;let s;for(let t=0;t<r.length;t+=e)for(let e=0;e<n;e++)s=r[t+e],r[t+e]=r[t+i-e],r[t+i-e]=s}function B(t,e,r){const n=r.length,i=r.reduce(((t,e)=>t*e)),s=r.map(((t,e)=>e+1===n?1:r.slice(e+1).reduce(((t,e)=>t*e),1))),o=Array(n).fill(0);for(let a=0;a<i;a++){let i=0;for(let t=0;t<n;t++)i+=o[t]*s[t];e[i]=t[a],o[0]+=1;for(let t=0;t<n;t++)if(o[t]===r[t]){if(t+1===n)return;o[t]=0,o[t+1]+=1}}}const q={0:x,1:x,2:function(t,e,r){let n=0;const i=r[0],s=r[1],o=s;for(let r=0;r<s;r++)for(let s=0;s<i;s++)e[s*o+r]=t[n++]},3:function(t,e,r){let n=0;const i=r[0],s=r[1],o=r[2],a=o*s,h=o;for(let r=0;r<o;r++)for(let o=0;o<s;o++)for(let s=0;s<i;s++)e[s*a+o*h+r]=t[n++]},4:function(t,e,r){let n=0;const i=r[0],s=r[1],o=r[2],a=r[3],h=a*o*s,u=a*o,c=a;for(let r=0;r<a;r++)for(let a=0;a<o;a++)for(let o=0;o<s;o++)for(let s=0;s<i;s++)e[s*h+o*u+a*c+r]=t[n++]}};function L(t,e,r){return(q[r.length]||B)(t,e,r)}function F(t){return null!==t&&(t instanceof ArrayBuffer||("function"==typeof SharedArrayBuffer&&t instanceof SharedArrayBuffer||!!T&&(t.toString().startsWith("[object ArrayBuffer]")||t.toString().startsWith("[object SharedArrayBuffer]"))))}const D=".zarray",U=".zgroup",V=".zattrs";async function R(t,e=null){const r=Y(e=N(e))+D;return t.containsItem(r)}async function G(t,e=null){const r=Y(e=N(e))+U;return t.containsItem(r)}function Y(t){return t.length>0?t+"/":""}async function J(t,e,r,n){if(0===e.length)return;const i=e.split("/");let s="";for(const e of i.slice(0,i.length-1))s+=e,await R(t,s)?await H(t,s,n):await G(t,s)||await H(t,s),s+="/"}async function H(t,e=null,r=!1){if(e=N(e),r)throw Error("Group overwriting not implemented yet :(");if(await R(t,e))throw new s(e);if(await G(t,e))throw new o(e);const n=Y(e)+U;await t.setItem(n,JSON.stringify({zarr_format:2}))}async function K(t,e=null,r=null,n=!1){e=N(e),await J(t,e,0,n),await H(t,e,n)}async function Q(t,e,r,n,i,a,h,u,c,l,f,d){if(c)throw Error("Array overwriting not implemented yet :(");if(await R(t,i))throw new s(i);if(await G(t,i))throw new o(i);if(r=function(t,e){if(null===t||!0===t)throw new Error("Chunk guessing is not supported yet");return!1===t?e:("number"==typeof t&&(t=[t]),t.length<e.length&&(t=t.concat(e.slice(t.length))),t.map(((t,r)=>-1===t||null===t?e[r]:Math.floor(t))))}(r,e=j(e)),u=function(t){return t.toUpperCase()}(u),null!==f&&f.length>0)throw Error("Filters are not supported yet");let p=h;"number"==typeof h&&(Number.isNaN(h)&&(p="NaN"),Number.POSITIVE_INFINITY===h&&(p="Infinity"),Number.NEGATIVE_INFINITY===h&&(p="-Infinity"));const y={zarr_format:2,shape:e,chunks:r,dtype:n,fill_value:p,order:u,compressor:a,filters:f=null};d&&(y.dimension_separator=d);const w=Y(i)+D;await t.setItem(w,JSON.stringify(y))}async function W(t,e,r,n,i=null,s=null,o=null,a="C",h=!1,u=null,c=null,l){i=N(i),await J(t,i,0,h),await Q(t,e,r,n,i,s,o,a,h,0,c,l)}function X(t){if("string"!=typeof t){if(T&&Buffer.isBuffer(t))return JSON.parse(t.toString());if(F(t)){const e=new TextDecoder,r=new Uint8Array(t);return JSON.parse(e.decode(r))}return t}return JSON.parse(t)}class Z{constructor(t,e,r,n=!0){this.store=t,this.key=e,this.readOnly=r,this.cache=n,this.cachedValue=null}async asObject(){if(this.cache&&null!==this.cachedValue)return this.cachedValue;const t=await this.getNoSync();return this.cache&&(this.cachedValue=t),t}async getNoSync(){try{return X(await this.store.getItem(this.key))}catch(t){return{}}}async setNoSync(t,e){const r=await this.getNoSync();return r[t]=e,await this.putNoSync(r),!0}async putNoSync(t){await this.store.setItem(this.key,JSON.stringify(t)),this.cache&&(this.cachedValue=t)}async delNoSync(t){const e=await this.getNoSync();return delete e[t],await this.putNoSync(e),!0}async put(t){if(this.readOnly)throw new c("attributes are read-only");return this.putNoSync(t)}async setItem(t,e){if(this.readOnly)throw new c("attributes are read-only");return this.setNoSync(t,e)}async getItem(t){return(await this.asObject())[t]}async deleteItem(t){if(this.readOnly)throw new c("attributes are read-only");return this.delNoSync(t)}async containsItem(t){return void 0!==(await this.asObject())[t]}proxy(){return n(this)}}const tt=globalThis.Float16Array,et={"|b":Int8Array,"|b1":Uint8Array,"|B":Uint8Array,"|u1":Uint8Array,"|i1":Int8Array,"<b":Int8Array,"<B":Uint8Array,"<u1":Uint8Array,"<i1":Int8Array,"<u2":Uint16Array,"<i2":Int16Array,"<u4":Uint32Array,"<i4":Int32Array,"<f4":Float32Array,"<f2":tt,"<f8":Float64Array,">b":Int8Array,">B":Uint8Array,">u1":Uint8Array,">i1":Int8Array,">u2":Uint16Array,">i2":Int16Array,">u4":Uint32Array,">i4":Int32Array,">f4":Float32Array,">f2":tt,">f8":Float64Array};function rt(t){const e=et[t];if(!e){if("f2"===t.slice(1))throw Error(`'${t}' is not supported natively in zarr.js. In order to access this dataset you must make Float16Array available as a global. See https://github.com/gzuidhof/zarr.js/issues/127`);throw Error(`Dtype not recognized or not supported in zarr.js, got ${t}.`)}return e}function nt(t){if(t instanceof Uint8Array)return"|u1";if(t instanceof Int8Array)return"|i1";if(t instanceof Uint16Array)return"<u2";if(t instanceof Int16Array)return"<i2";if(t instanceof Uint32Array)return"<u4";if(t instanceof Int32Array)return"<i4";if(t instanceof Float32Array)return"<f4";if(t instanceof Float64Array)return"<f8";throw new w("Mapping for TypedArray to Dtypestring not known")}function it(t){return void 0!==t.byteLength?t.constructor:it(t[0])}function st(t,e,r){const n=I(r,e),[i,s]=b(n,e);return[ot(t,e,i),s]}function ot(t,e,r){const n=r[0];if("number"==typeof n)return 1===e.length?t[n]:ot(t[n],e.slice(1),r.slice(1));const[i,s,o,a]=n;if(0===a)return new(it(t))(0);if(1===e.length){if(1===o)return t.slice(i,s);const e=new t.constructor(a);for(let r=0;r<a;r++)e[r]=t[i+r*o];return e}let h=new Array(a);for(let n=0;n<a;n++)h[n]=ot(t[i+n*o],e.slice(1),r.slice(1));if(a>0&&"number"==typeof h[0]){h=t[0].constructor.from(h)}return h}function at(t,e,r,n,i){const s=I(i,r,!1),[o,a]=b(s,r);if(JSON.stringify(a)!==JSON.stringify(n))throw new w(`Shape mismatch in target and source NestedArray: ${a} and ${n}`);ht(t,e,r,o)}function ht(t,e,r,n){const i=n[0];if("number"==typeof e)return void ut(t,e,r,n.map((t=>"number"==typeof t?[t,t+1,1,1]:t)));if("number"==typeof i)return void ht(t[i],e,r.slice(1),n.slice(1));const[s,o,a,h]=i;if(1!==r.length)for(let i=0;i<h;i++)ht(t[s+i*a],e[i],r.slice(1),n.slice(1));else if(1===a)t.set(e,s);else for(let r=0;r<h;r++)t[s+r*a]=e[r]}function ut(t,e,r,n){const i=n[0],[s,o,a,h]=i;if(1!==r.length)for(let i=0;i<h;i++)ut(t[s+i*a],e,r.slice(1),n.slice(1));else if(1===a)t.fill(e,s,o);else for(let r=0;r<h;r++)t[s+r*a]=e}function ct(t,e,r){void 0===r&&(r=it(t));const n=new r(e.reduce(((t,e)=>t*e),1));return lt(t,e,n,0),n}function lt(t,e,r,n){if(1===e.length)return void r.set(t,n);if(2===e.length){for(let i=0;i<e[0];i++)r.set(t[i],n+e[1]*i);return t}const i=e.slice(1),s=i.reduce(((t,e)=>t*e),1);for(let o=0;o<e[0];o++)lt(t[o],i,r,n+s*o);return t}class ft{constructor(t,e,r){const n=null!==t&&!!t.BYTES_PER_ELEMENT;if(void 0===e){if(!n)throw new w("Shape argument is required unless you pass in a TypedArray");e=[t.length]}if(void 0===r){if(!n)throw new w("Dtype argument is required unless you pass in a TypedArray");r=nt(t)}if(e=j(e),this.shape=e,this.dtype=r,n&&1!==e.length&&(t=t.buffer),0===this.shape.length)this.data=new(rt(r))(1);else if(T&&Buffer.isBuffer(t)||F(t)||null===t){const n=e.reduce(((t,e)=>t*e),1);null===t&&(t=new ArrayBuffer(n*parseInt(r[r.length-1],10)));const i=t.byteLength/parseInt(r[r.length-1],10);if(n!==i)throw new Error(`Buffer has ${i} of dtype ${r}, shape is too large or small ${e} (flat=${n})`);const s=rt(r);this.data=pt(t,s,e)}else this.data=t}get(t){const[e,r]=st(this.data,this.shape,t);return 0===r.length?e:new ft(e,r,this.dtype)}set(t=null,e){null===t&&(t=[g(null)]),"number"==typeof e?0===this.shape.length?this.data[0]=e:function(t,e,r,n){const i=I(n,r,!0),[s,o]=b(i,r);ut(t,e,r,s)}(this.data,e,this.shape,t):at(this.data,e.data,this.shape,e.shape,t)}flatten(){return 1===this.shape.length?this.data:ct(this.data,this.shape,rt(this.dtype))}static arange(t,e="<i4"){const r=dt([t],rt(e));return new ft(r,[t],e)}}function dt(t,e){const r=t.reduce(((t,e)=>t*e),1),n=new e(r);return n.set([...Array(r).keys()]),n}function pt(t,e,r,n=0){if(1===r.length)return new e(t.slice(n,n+r[0]*e.BYTES_PER_ELEMENT));const i=new Array(r[0]);if(2===r.length){for(let s=0;s<r[0];s++)i[s]=new e(t.slice(n+r[1]*s*e.BYTES_PER_ELEMENT,n+r[1]*(s+1)*e.BYTES_PER_ELEMENT));return i}const s=r.slice(1),o=s.reduce(((t,e)=>t*e),1);for(let a=0;a<r[0];a++)i[a]=pt(t,e,s,n+o*a*e.BYTES_PER_ELEMENT);return i}function yt(t,e,r,n,i){const s=I(n,r,!0),[o]=b(s,r);gt(i,t,e,o)}function wt(t,e,r,n,i,s,o){const a=I(n,r,!1),[h,u]=b(a,r);if(JSON.stringify(u)!==JSON.stringify(o))throw new w(`Shape mismatch in target and source RawArray: ${u} and ${o}`);_t(t,e,h,i,s)}function mt(t,e,r,n,i,s,o,a){const h=I(n,r,!0),[u]=b(h,r),c=I(a,o,!1),[l]=b(c,o);vt(t,e,u,i,s,l)}function gt(t,e,r,n){const[i,...s]=n,[o,...a]=r,[h,u,c,l]=i;if(1!==r.length)for(let r=0;r<l;r++)gt(t,e.subarray(o*(h+c*r)),a,s);else if(1===c&&1===o)e.fill(t,h,h+l);else for(let r=0;r<l;r++)e[o*(h+c*r)]=t}function _t(t,e,r,n,i){if(0===r.length)return void t.set(n);const[s,...o]=r,[a,...h]=e;if("number"==typeof s)return void _t(t.subarray(s*a),h,o,n,i);const[u,...c]=i,[l,f,d,p]=s;if(1!==e.length)for(let e=0;e<p;e++)_t(t.subarray(a*(l+e*d)),h,o,n.subarray(u*e),c);else if(1===d&&1===a&&1===u)t.set(n.subarray(0,p),l);else for(let e=0;e<p;e++)t[a*(l+d*e)]=n[u*e]}function vt(t,e,r,n,i,s){if(0===s.length)return void t.set(n.subarray(0,t.length));const[o,...a]=r,[h,...u]=s,[c,...l]=e,[f,...d]=i;if("number"==typeof h)return void vt(t,e,r,n.subarray(f*h),d,u);const[p,y,w,m]=o,[g,_,v,b]=h;if(1!==e.length||1!==i.length)for(let e=0;e<m;e++)vt(t.subarray(c*(p+e*w)),l,a,n.subarray(f*(g+e*v)),d,u);else if(1===w&&1===c&&1===v&&1===f)t.set(n.subarray(g,g+m),p);else for(let e=0;e<m;e++)t[c*(p+w*e)]=n[f*(g+v*e)]}class bt{constructor(t,e,r,n){const i=null!==t&&!!t.BYTES_PER_ELEMENT;if(void 0===e){if(!i)throw new w("Shape argument is required unless you pass in a TypedArray");e=[t.length]}if(e=j(e),void 0===r){if(!i)throw new w("Dtype argument is required unless you pass in a TypedArray");r=nt(t)}if(void 0===n&&(n=function(t){const e=t.length,r=Array(e);let n=1;for(let i=e-1;i>=0;i--)r[i]=n,n*=t[i];return r}(e)),this.shape=e,this.dtype=r,this.strides=n,i&&1!==e.length&&(t=t.buffer),0===this.shape.length)this.data=new(rt(r))(1);else if(T&&Buffer.isBuffer(t)||F(t)||null===t){const n=e.reduce(((t,e)=>t*e),1);null===t&&(t=new ArrayBuffer(n*parseInt(r[r.length-1],10)));const i=t.byteLength/parseInt(r[r.length-1],10);if(n!==i)throw new Error(`Buffer has ${i} of dtype ${r}, shape is too large or small ${e} (flat=${n})`);const s=rt(r);this.data=new s(t)}else this.data=t}set(t=null,e,r){null===t&&(t=[g(null)]),"number"==typeof e?0===this.shape.length?this.data[0]=e:yt(this.data,this.strides,this.shape,t,e):e instanceof bt&&r?mt(this.data,this.strides,this.shape,t,e.data,e.strides,e.shape,r):wt(this.data,this.strides,this.shape,t,e.data,e.strides,e.shape)}}var It={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,r="~";function n(){}function i(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function s(t,e,n,s,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new i(n,s||t,o),h=r?r+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,n,i=[];if(0===this._eventsCount)return i;for(n in t=this._events)e.call(t,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(t)):i},a.prototype.listeners=function(t){var e=r?r+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o},a.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,i,s,o){var a=r?r+t:t;if(!this._events[a])return!1;var h,u,c=this._events[a],l=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,i),!0;case 5:return c.fn.call(c.context,e,n,i,s),!0;case 6:return c.fn.call(c.context,e,n,i,s,o),!0}for(u=1,h=new Array(l-1);u<l;u++)h[u-1]=arguments[u];c.fn.apply(c.context,h)}else{var f,d=c.length;for(u=0;u<d;u++)switch(c[u].once&&this.removeListener(t,c[u].fn,void 0,!0),l){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,e);break;case 3:c[u].fn.call(c[u].context,e,n);break;case 4:c[u].fn.call(c[u].context,e,n,i);break;default:if(!h)for(f=1,h=new Array(l-1);f<l;f++)h[f-1]=arguments[f];c[u].fn.apply(c[u].context,h)}}return!0},a.prototype.on=function(t,e,r){return s(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return s(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,n,i){var s=r?r+t:t;if(!this._events[s])return this;if(!e)return o(this,s),this;var a=this._events[s];if(a.fn)a.fn!==e||i&&!a.once||n&&a.context!==n||o(this,s);else{for(var h=0,u=[],c=a.length;h<c;h++)(a[h].fn!==e||i&&!a[h].once||n&&a[h].context!==n)&&u.push(a[h]);u.length?this._events[s]=1===u.length?u[0]:u:o(this,s)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&o(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a}(It);var St=It.exports;class Et extends Error{constructor(t){super(t),this.name="TimeoutError"}}class At{constructor(){Object.defineProperty(this,"_queue",{enumerable:!0,configurable:!0,writable:!0,value:[]})}enqueue(t,e){var r;const n={priority:(e={priority:0,...e}).priority,run:t};if(this.size&&(null===(r=this._queue[this.size-1])||void 0===r?void 0:r.priority)>=e.priority)return void this._queue.push(n);const i=function(t,e,r){let n=0,i=t.length;for(;i>0;){const s=Math.trunc(i/2);let o=n+s;r(t[o],e)<=0?(n=++o,i-=s+1):i=s}return n}(this._queue,n,((t,e)=>e.priority-t.priority));this._queue.splice(i,0,n)}dequeue(){const t=this._queue.shift();return null==t?void 0:t.run}filter(t){return this._queue.filter((e=>e.priority===t.priority)).map((t=>t.run))}get size(){return this._queue.length}}const Ot=()=>{},kt=new Et;class Ct extends St{constructor(t){var e,r,n,i;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:Ot}),Object.defineProperty(this,"_resolveIdle",{enumerable:!0,configurable:!0,writable:!0,value:Ot}),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}),!("number"==typeof(t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:At,...t}).intervalCap&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${null!==(r=null===(e=t.intervalCap)||void 0===e?void 0:e.toString())&&void 0!==r?r:""}\` (${typeof t.intervalCap})`);if(void 0===t.interval||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${null!==(i=null===(n=t.interval)||void 0===n?void 0:n.toString())&&void 0!==i?i:""}\` (${typeof t.interval})`);this._carryoverConcurrencyCount=t.carryoverConcurrencyCount,this._isIntervalIgnored=t.intervalCap===Number.POSITIVE_INFINITY||0===t.interval,this._intervalCap=t.intervalCap,this._interval=t.interval,this._queue=new t.queueClass,this._queueClass=t.queueClass,this.concurrency=t.concurrency,this._timeout=t.timeout,this._throwOnTimeout=!0===t.throwOnTimeout,this._isPaused=!1===t.autoStart}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=Ot,0===this._pendingCount&&(this._resolveIdle(),this._resolveIdle=Ot,this.emit("idle"))}_onResumeInterval(){this._onInterval(),this._initializeIntervalIfNeeded(),this._timeoutId=void 0}_isIntervalPaused(){const t=Date.now();if(void 0===this._intervalId){const e=this._intervalEnd-t;if(!(e<0))return void 0===this._timeoutId&&(this._timeoutId=setTimeout((()=>{this._onResumeInterval()}),e)),!0;this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0}return!1}_tryToStartAnother(){if(0===this._queue.size)return this._intervalId&&clearInterval(this._intervalId),this._intervalId=void 0,this._resolvePromises(),!1;if(!this._isPaused){const t=!this._isIntervalPaused();if(this._doesIntervalAllowAnother&&this._doesConcurrentAllowAnother){const e=this._queue.dequeue();return!!e&&(this.emit("active"),e(),t&&this._initializeIntervalIfNeeded(),!0)}}return!1}_initializeIntervalIfNeeded(){this._isIntervalIgnored||void 0!==this._intervalId||(this._intervalId=setInterval((()=>{this._onInterval()}),this._interval),this._intervalEnd=Date.now()+this._interval)}_onInterval(){0===this._intervalCount&&0===this._pendingCount&&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(t){if(!("number"==typeof t&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this._concurrency=t,this._processQueue()}async add(t,e={}){return new Promise(((r,n)=>{this._queue.enqueue((async()=>{this._pendingCount++,this._intervalCount++;try{const i=void 0===this._timeout&&void 0===e.timeout?t():function(t,e,r,n){let i;const s=new Promise(((s,o)=>{if("number"!=typeof e||e<0)throw new TypeError("Expected `milliseconds` to be a positive number");e!==Number.POSITIVE_INFINITY?(n={customTimers:{setTimeout:setTimeout,clearTimeout:clearTimeout},...n},i=n.customTimers.setTimeout.call(void 0,(()=>{if("function"==typeof r){try{s(r())}catch(t){o(t)}return}const n=r instanceof Error?r:new Et("string"==typeof r?r:`Promise timed out after ${e} milliseconds`);"function"==typeof t.cancel&&t.cancel(),o(n)}),e),(async()=>{try{s(await t)}catch(t){o(t)}finally{n.customTimers.clearTimeout.call(void 0,i)}})()):s(t)}));return s.clear=()=>{clearTimeout(i),i=void 0},s}(Promise.resolve(t()),void 0===e.timeout?this._timeout:e.timeout,(()=>{(void 0===e.throwOnTimeout?this._throwOnTimeout:e.throwOnTimeout)&&n(kt)})),s=await i;r(s),this.emit("completed",s)}catch(t){n(t),this.emit("error",t)}this._next()}),e),this._tryToStartAnother(),this.emit("add")}))}async addAll(t,e){return Promise.all(t.map((async t=>this.add(t,e))))}start(){return this._isPaused?(this._isPaused=!1,this._processQueue(),this):this}pause(){this._isPaused=!0}clear(){this._queue=new this._queueClass}async onEmpty(){if(0!==this._queue.size)return new Promise((t=>{const e=this._resolveEmpty;this._resolveEmpty=()=>{e(),t()}}))}async onSizeLessThan(t){if(!(this._queue.size<t))return new Promise((e=>{const r=()=>{this._queue.size<t&&(this.removeListener("next",r),e())};this.on("next",r)}))}async onIdle(){if(0!==this._pendingCount||0!==this._queue.size)return new Promise((t=>{const e=this._resolveIdle;this._resolveIdle=()=>{e(),t()}}))}get size(){return this._queue.size}sizeBy(t){return this._queue.filter(t).length}get pending(){return this._pendingCount}get isPaused(){return this._isPaused}get timeout(){return this._timeout}set timeout(t){this._timeout=t}}class Pt{constructor(t,e=null,n,i=!1,s=null,o=!0,a=!0){this.store=t,this._chunkStore=s,this.path=N(e),this.keyPrefix=Y(this.path),this.readOnly=i,this.cacheMetadata=o,this.cacheAttrs=a,this.meta=n,null!==this.meta.compressor?this.compressor=r(this.meta.compressor):this.compressor=null;const h=this.keyPrefix+V;this.attrs=new Z(this.store,h,this.readOnly,a)}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(){const t=this.name;if(null===t)return null;const e=t.split("/");return e[e.length-1]}get shape(){return this.meta.shape}get chunks(){return this.meta.chunks}get chunkSize(){return this.chunks.reduce(((t,e)=>t*e),1)}get dtype(){return this.meta.dtype}get fillValue(){const t=this.meta.fill_value;return"NaN"===t?NaN:"Infinity"===t?1/0:"-Infinity"===t?-1/0:this.meta.fill_value}get nDims(){return this.meta.shape.length}get size(){return this.meta.shape.reduce(((t,e)=>t*e),1)}get length(){return this.shape[0]}get _chunkDataShape(){if(0===this.shape.length)return[1];{const t=[];for(let e=0;e<this.shape.length;e++)t[e]=Math.ceil(this.shape[e]/this.chunks[e]);return t}}get chunkDataShape(){return this._chunkDataShape}get numChunks(){return this.chunkDataShape.reduce(((t,e)=>t*e),1)}static async create(t,e=null,r=!1,n=null,i=!0,s=!0){const o=await this.loadMetadataForConstructor(t,e);return new Pt(t,e,o,r,n,i,s)}static async loadMetadataForConstructor(t,e){try{const r=Y(e=N(e));return X(await t.getItem(r+D))}catch(r){if(await G(t,e))throw new o(null!=e?e:"");throw new Error("Failed to load metadata for ZarrArray:"+r.toString())}}async reloadMetadata(){const t=this.keyPrefix+D,e=this.store.getItem(t);return this.meta=X(await e),this.meta}async refreshMetadata(){this.cacheMetadata||await this.reloadMetadata()}get(t=null,e={}){return this.getBasicSelection(t,!1,e)}getRaw(t=null,e={}){return this.getBasicSelection(t,!0,e)}async getBasicSelection(t,e=!1,{concurrencyLimit:r=10,progressCallback:n,storeOptions:i}={}){if(this.cacheMetadata||await this.reloadMetadata(),0===this.shape.length)throw new Error("Shape [] indexing is not supported yet");return this.getBasicSelectionND(t,e,r,n,i)}getBasicSelectionND(t,e,r,n,i){const s=new k(t,this);return this.getSelection(s,e,r,n,i)}async getSelection(t,e,r,n,i){const s=this.dtype,o=t.shape,a=t.shape.reduce(((t,e)=>t*e),1);if(e&&a===this.chunkSize){const e=t.iter(),r=e.next();if(!1===r.done&&!0===e.next().done){const t=r.value;return await this.decodeDirectToRawArray(t,o,a)}}const h=e?new bt(null,o,s):new ft(null,o,s);if(0===a)return h;const u=new Ct({concurrency:r}),c=[];if(n){let e=0,r=0;for(const e of t.iter())r+=1;n({progress:0,queueSize:r});for(const s of t.iter())c.push(u.add((async()=>{await this.chunkGetItem(s.chunkCoords,s.chunkSelection,h,s.outSelection,t.dropAxes,i),e+=1,n({progress:e,queueSize:r})})))}else for(const e of t.iter())c.push(u.add((()=>this.chunkGetItem(e.chunkCoords,e.chunkSelection,h,e.outSelection,t.dropAxes,i))));return await Promise.all(c),0===h.shape.length?h.data[0]:h}async chunkGetItem(t,e,r,n,s,o){if(t.length!==this._chunkDataShape.length)throw new w(`Inconsistent shapes: chunkCoordsLength: ${t.length}, cDataShapeLength: ${this.chunkDataShape.length}`);const a=this.chunkKey(t);try{const t=await this.chunkStore.getItem(a,o),i=await this.decodeChunk(t);if(r instanceof ft){if(function(t){t=v(t);for(let e=0;e<t.length;e++){const r=t[e];if(!E(r)&&!O(r)&&"..."!==r)return!1}return!0}(n)&&M(e,this.chunks)&&!this.meta.filters)return void r.set(n,this.toNestedArray(i));const t=this.toNestedArray(i).get(e);if(null!==s)throw new Error("Drop axes is not supported yet");r.set(n,t)}else r.set(n,this.chunkBufferToRawArray(i),e)}catch(t){if(!i(t))throw t;null!==this.fillValue&&r.set(n,this.fillValue)}}async getRawChunk(t,e){if(t.length!==this.shape.length)throw new Error(`Chunk coordinates ${t.join(".")} do not correspond to shape ${this.shape}.`);try{for(let e=0;e<t.length;e++){const r=Math.ceil(this.shape[e]/this.chunks[e]);t[e]=S(t[e],r)}}catch(e){throw e instanceof d?new d(`index ${t.join(".")} is out of bounds for shape: ${this.shape} and chunks ${this.chunks}`):e}const r=this.chunkKey(t),n=this.chunkStore.getItem(r,null==e?void 0:e.storeOptions),i=await this.decodeChunk(await n),s=this.chunks.filter((t=>1!==t));return new bt(i,s,this.dtype)}chunkKey(t){var e;const r=null!==(e=this.meta.dimension_separator)&&void 0!==e?e:".";return this.keyPrefix+t.join(r)}ensureByteArray(t){return"string"==typeof t?new Uint8Array(Buffer.from(t).buffer):new Uint8Array(t)}toTypedArray(t){return new(rt(this.dtype))(t)}toNestedArray(t){const e=this.ensureByteArray(t).buffer;return new ft(e,this.chunks,this.dtype)}async decodeChunk(t){let e=this.ensureByteArray(t);if(null!==this.compressor&&(e=await(await this.compressor).decode(e)),this.dtype.includes(">")&&$(this.toTypedArray(e.buffer)),"F"===this.meta.order&&this.nDims>1){const t=this.toTypedArray(e.buffer),r=new(rt(this.dtype))(t.length);return L(t,r,this.chunks),r.buffer}return e.buffer}chunkBufferToRawArray(t){return new bt(t,this.chunks,this.dtype)}async decodeDirectToRawArray({chunkCoords:t},e,r){const n=this.chunkKey(t);try{const t=await this.chunkStore.getItem(n);return new bt(await this.decodeChunk(t),e,this.dtype)}catch(t){if(i(t)){const t=new(rt(this.dtype))(r);return new bt(t.fill(this.fillValue),e)}throw t}}async set(t=null,e,r={}){await this.setBasicSelection(t,e,r)}async setBasicSelection(t,e,{concurrencyLimit:r=10,progressCallback:n}={}){if(this.readOnly)throw new c("Object is read only");if(this.cacheMetadata||await this.reloadMetadata(),0===this.shape.length)throw new Error("Shape [] indexing is not supported yet");await this.setBasicSelectionND(t,e,r,n)}async setBasicSelectionND(t,e,r,n){const i=new k(t,this);await this.setSelection(i,e,r,n)}getChunkValue(t,e,r,n){let i;if(0===n.length)i=r;else if("number"==typeof r)i=r;else if(i=r.get(t.outSelection),null!==e.dropAxes)throw new Error("Handling drop axes not supported yet");return i}async setSelection(t,e,r,n){const i=t.shape;if(0===i.length);else if("number"==typeof e);else{if(!(e instanceof ft))throw new Error("Unknown data type for setting :(");if(!function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}(e.shape,i))throw new w(`Shape mismatch in source NestedArray and set selection: ${e.shape} and ${i}`)}const s=new Ct({concurrency:r}),o=[];if(n){let r=0;for(const e of t.iter())r+=1;let a=0;n({progress:0,queueSize:r});for(const h of t.iter()){const u=this.getChunkValue(h,t,e,i);o.push(s.add((async()=>{await this.chunkSetItem(h.chunkCoords,h.chunkSelection,u),a+=1,n({progress:a,queueSize:r})})))}}else for(const r of t.iter()){const n=this.getChunkValue(r,t,e,i);o.push(s.add((()=>this.chunkSetItem(r.chunkCoords,r.chunkSelection,n))))}await Promise.all(o)}async chunkSetItem(t,e,r){if("F"===this.meta.order&&this.nDims>1)throw new Error("Setting content for arrays in F-order is not supported.");const n=this.chunkKey(t);let s=null;const o=rt(this.dtype),a=this.chunkSize;if(M(e,this.chunks))"number"==typeof r?(s=new o(a),s.fill(r)):s=r.flatten();else{let t;try{const e=await this.chunkStore.getItem(n),r=await this.decodeChunk(e);t=this.toTypedArray(r)}catch(e){if(!i(e))throw e;t=new o(a),null!==this.fillValue&&t.fill(this.fillValue)}const h=new ft(t,this.chunks,this.dtype);h.set(e,r),s=h.flatten()}const h=await this.encodeChunk(s);this.chunkStore.setItem(n,h)}async encodeChunk(t){if(this.dtype.includes(">")&&(t=function(t){const e=t.slice();return $(e),e}(t)),null!==this.compressor){const e=new Uint8Array(t.buffer);return(await(await this.compressor).encode(e)).buffer}return t.buffer}}class Tt{constructor(t={}){this.root=t}proxy(){return n(this)}getParent(t){let e=this.root;const r=t.split("/");for(const n of r.slice(0,r.length-1))if(e=e[n],!e)throw Error(t);return[e,r[r.length-1]]}requireParent(t){let e=this.root;const r=t.split("/");for(const t of r.slice(0,r.length-1))void 0===e[t]&&(e[t]={}),e=e[t];return[e,r[r.length-1]]}getItem(t){const[e,r]=this.getParent(t),n=e[r];if(void 0===n)throw new l(t);return n}setItem(t,e){const[r,n]=this.requireParent(t);return r[n]=e,!0}deleteItem(t){const[e,r]=this.getParent(t);return delete e[r]}containsItem(t){try{return void 0!==this.getItem(t)}catch(t){return!1}}keys(){throw new Error("Method not implemented.")}}var xt;!function(t){t.HEAD="HEAD",t.GET="GET",t.PUT="PUT"}(xt||(xt={}));const Nt=[xt.HEAD,xt.GET,xt.PUT];class jt{constructor(t,e={}){this.url=t;const{fetchOptions:r={},supportedMethods:n=Nt}=e;this.fetchOptions=r,this.supportedMethods=new Set(n)}keys(){throw new Error("Method not implemented.")}async getItem(t,e){const r=z(this.url,t),n=await fetch(r,{...this.fetchOptions,...e});if(404===n.status)throw new l(t);if(200!==n.status)throw new m(String(n.status));return T?Buffer.from(await n.arrayBuffer()):n.arrayBuffer()}async setItem(t,e){if(!this.supportedMethods.has(xt.PUT))throw new Error("HTTP PUT no a supported method for store.");const r=z(this.url,t);"string"==typeof e&&(e=(new TextEncoder).encode(e).buffer);return"2"===(await fetch(r,{...this.fetchOptions,method:xt.PUT,body:e})).status.toString()[0]}deleteItem(t){throw new Error("Method not implemented.")}async containsItem(t){const e=z(this.url,t),r=this.supportedMethods.has(xt.HEAD)?xt.HEAD:xt.GET;return 200===(await fetch(e,{...this.fetchOptions,method:r})).status}}async function Mt({shape:t,chunks:e=!0,dtype:r="<i4",compressor:n=null,fillValue:i=null,order:s="C",store:o,overwrite:a=!1,path:h,chunkStore:u,filters:c,cacheMetadata:l=!0,cacheAttrs:f=!0,readOnly:d=!1,dimensionSeparator:p}){const y=Dt(o);await W(y,t,e,r,h,n,i,s,a,u,c,p);return await Pt.create(y,h,d,u,l,f)}async function zt(t,e={}){return e.fillValue=null,Mt({shape:t,...e})}async function $t(t,e={}){return e.fillValue=0,Mt({shape:t,...e})}async function Bt(t,e={}){return e.fillValue=1,Mt({shape:t,...e})}async function qt(t,e,r={}){return r.fillValue=e,Mt({shape:t,...r})}async function Lt(t,e={}){let r=null;t instanceof ft?(r=t.shape,e.dtype=void 0===e.dtype?t.dtype:e.dtype):r=t.byteLength;const n=void 0!==e.readOnly&&e.readOnly;e.readOnly=!1;const i=await Mt({shape:r,...e});return await i.set(null,t),i.readOnly=n,i}async function Ft({shape:t,mode:e="a",chunks:r=!0,dtype:n="<i4",compressor:i=null,fillValue:h=null,order:u="C",store:c,overwrite:l=!1,path:f=null,chunkStore:d,filters:p,cacheMetadata:y=!0,cacheAttrs:m=!0,dimensionSeparator:g}={}){const _=Dt(c);if(void 0===d&&(d=Dt(_)),f=N(f),"r"===e||"r+"===e){if(!await R(_,f)){if(await G(_,f))throw new o(f);throw new a(f)}}else if("w"===e){if(void 0===t)throw new w("Shape can not be undefined when creating a new array");await W(_,t,r,n,f,i,h,u,l,d,p,g)}else if("a"===e){if(!await R(_,f)){if(await G(_,f))throw new o(f);if(void 0===t)throw new w("Shape can not be undefined when creating a new array");await W(_,t,r,n,f,i,h,u,l,d,p,g)}}else{if("w-"!==e&&"x"!==e)throw new w(`Invalid mode argument: ${e}`);if(await R(_,f))throw new s(f);if(await G(_,f))throw new o(f);if(void 0===t)throw new w("Shape can not be undefined when creating a new array");await W(_,t,r,n,f,i,h,u,l,d,p,g)}const v="r"===e;return Pt.create(_,f,v,d,y,m)}function Dt(t){return void 0===t?new Tt:"string"==typeof t?new jt(t):t}class Ut{constructor(t,e=null,r,n=!1,i=null,s=!0){this.store=t,this._chunkStore=i,this.path=N(e),this.keyPrefix=Y(this.path),this.readOnly=n,this.meta=r;const o=this.keyPrefix+V;this.attrs=new Z(this.store,o,this.readOnly,s)}get name(){return this.path.length>0?"/"!==this.path[0]?"/"+this.path:this.path:"/"}get basename(){const t=this.name.split("/");return t[t.length-1]}get chunkStore(){return this._chunkStore?this._chunkStore:this.store}static async create(t,e=null,r=!1,n=null,i=!0){const s=await this.loadMetadataForConstructor(t,e);return new Ut(t,e,s,r,n,i)}static async loadMetadataForConstructor(t,e){const r=Y(e=N(e));try{return X(await t.getItem(r+U))}catch(r){if(await R(t,e))throw new s(e);throw new h(e)}}itemPath(t){const e="string"==typeof t&&t.length>0&&"/"===t[0],r=N(t);return!e&&this.path.length>0?this.keyPrefix+r:r}async createGroup(t,e=!1){if(this.readOnly)throw new c("group is read only");const r=this.itemPath(t);return await K(this.store,r,this._chunkStore,e),Ut.create(this.store,r,this.readOnly,this._chunkStore,this.attrs.cache)}async requireGroup(t,e=!1){if(this.readOnly)throw new c("group is read only");const r=this.itemPath(t);return await G(this.store,r)||await K(this.store,r,this._chunkStore,e),Ut.create(this.store,r,this.readOnly,this._chunkStore,this.attrs.cache)}getOptsForArrayCreation(t,e={}){const r=this.itemPath(t);return e.path=r,void 0===e.cacheAttrs&&(e.cacheAttrs=this.attrs.cache),e.store=this.store,e.chunkStore=this.chunkStore,e}array(t,e,r,n){if(this.readOnly)throw new c("group is read only");return(r=this.getOptsForArrayCreation(t,r)).overwrite=void 0===n?r.overwrite:n,Lt(e,r)}empty(t,e,r={}){if(this.readOnly)throw new c("group is read only");return zt(e,r=this.getOptsForArrayCreation(t,r))}zeros(t,e,r={}){if(this.readOnly)throw new c("group is read only");return $t(e,r=this.getOptsForArrayCreation(t,r))}ones(t,e,r={}){if(this.readOnly)throw new c("group is read only");return Bt(e,r=this.getOptsForArrayCreation(t,r))}full(t,e,r,n={}){if(this.readOnly)throw new c("group is read only");return qt(e,r,n=this.getOptsForArrayCreation(t,n))}createDataset(t,e,r,n){if(this.readOnly)throw new c("group is read only");let i;if(n=this.getOptsForArrayCreation(t,n),void 0===r){if(void 0===e)throw new w("Shape must be set if no data is passed to CreateDataset");i=Mt({shape:e,...n})}else i=Lt(r,n);return i}async getItem(t){const e=this.itemPath(t);if(await R(this.store,e))return Pt.create(this.store,e,this.readOnly,this.chunkStore,void 0,this.attrs.cache);if(await G(this.store,e))return Ut.create(this.store,e,this.readOnly,this._chunkStore,this.attrs.cache);throw new l(t)}async setItem(t,e){return await this.array(t,e,{},!0),!0}async deleteItem(t){if(this.readOnly)throw new c("group is read only");throw new Error("Method not implemented.")}async containsItem(t){const e=this.itemPath(t);return await R(this.store,e)||G(this.store,e)}proxy(){return n(this)}}async function Vt(t,e=null,r,n=!1,i=!0){return t=Dt(t),e=N(e),(n||await G(t))&&await K(t,e,r,n),Ut.create(t,e,!1,r,i)}async function Rt(t,e=null,r="a",n,i=!0){if(t=Dt(t),void 0!==n&&(n=Dt(t)),e=N(e),"r"===r||"r+"===r){if(!await G(t,e)){if(await R(t,e))throw new s(e);throw new h(e)}}else if("w"===r)await K(t,e,n,!0);else if("a"===r){if(!await G(t,e)){if(await R(t,e))throw new s(e);await K(t,e,n)}}else{if("w-"!==r&&"x"!==r)throw new w(`Invalid mode argument: ${r}`);if(await R(t,e))throw new s(e);if(await G(t,e))throw new o(e);await K(t,e,n)}const a="r"===r;return Ut.create(t,e,a,n,i)}class Gt{constructor(){this.object={}}getItem(t){if(!Object.prototype.hasOwnProperty.call(this.object,t))throw new l(t);return this.object[t]}setItem(t,e){return this.object[t]=e,!0}deleteItem(t){return delete this.object[t]}containsItem(t){return Object.prototype.hasOwnProperty.call(this.object,t)}proxy(){return n(this)}keys(){return Object.getOwnPropertyNames(this.object)}}export{a as ArrayNotFoundError,d as BoundsCheckError,s as ContainsArrayError,o as ContainsGroupError,Ut as Group,h as GroupNotFoundError,m as HTTPError,jt as HTTPStore,p as InvalidSliceError,l as KeyError,Tt as MemoryStore,y as NegativeStepError,ft as NestedArray,Gt as ObjectStore,u as PathNotFoundError,c as PermissionError,f as TooManyIndicesError,w as ValueError,Pt as ZarrArray,e as addCodec,Lt as array,Mt as create,n as createProxy,zt as empty,qt as full,r as getCodec,rt as getTypedArrayCtr,nt as getTypedArrayDtypeString,Vt as group,i as isKeyError,Dt as normalizeStoreArgument,Bt as ones,Ft as openArray,Rt as openGroup,dt as rangeTypedArray,g as slice,_ as sliceIndices,$t as zeros};
//# sourceMappingURL=core.min.mjs.map