@k67/kaitai-struct-ts 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <img src="assets/logo.png" alt="kaitai-struct-ts" width="200"/>
2
+ <img src=".github/logo.png" alt="kaitai-struct-ts" width="200"/>
3
3
 
4
4
  # kaitai-struct-ts
5
5
 
@@ -17,6 +17,19 @@
17
17
 
18
18
  Parse any binary data format by providing a `.ksy` (Kaitai Struct YAML) definition file - no compilation step required!
19
19
 
20
+ ## 🎮 Visual Debugger
21
+
22
+ **NEW in v0.11.0!** Try our interactive visual debugger:
23
+
24
+ **[🚀 Launch Debugger](https://fabianopinto.github.io/kaitai-struct-ts/)** | [📚 Documentation](./debugger/README.md)
25
+
26
+ Features:
27
+ - 🔍 Hex viewer with virtual scrolling
28
+ - 🌳 Interactive parse tree
29
+ - ✏️ Monaco-based schema editor
30
+ - 🐛 Step-by-step debugging
31
+ - ⌨️ Keyboard shortcuts (F5, F9, F10)
32
+
20
33
  ## Features
21
34
 
22
35
  ### Core Features
@@ -98,7 +98,7 @@ ${l}
98
98
  `);)i===`
99
99
  `&&(e+=`
100
100
  `),t+=1,i=n[t+1];return e||(e=" "),{fold:e,offset:t}}var ga={0:"\0",a:"\x07",b:"\b",e:"\x1B",f:"\f",n:`
101
- `,r:"\r",t:" ",v:"\v",N:"\x85",S:"\xA0",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function ya(n,t,e,i){let s=n.substr(t,e),o=s.length===e&&/^[0-9a-fA-F]+$/.test(s)?parseInt(s,16):NaN;if(isNaN(o)){let a=n.substr(t-2,e+2);return i(t-2,"BAD_DQ_ESCAPE",`Invalid escape sequence ${a}`),a}return String.fromCodePoint(o)}function Mi(n,t,e,i){let{value:s,type:r,comment:o,range:a}=t.type==="block-scalar"?Bi(n,t,i):Di(t,n.options.strict,i),c=e?n.directives.tagName(e.source,d=>i(e,"TAG_RESOLVE_FAILED",d)):null,l;n.options.stringKeys&&n.atKey?l=n.schema[W]:c?l=ba(n.schema,s,c,e,i):t.type==="scalar"?l=wa(n,s,t,i):l=n.schema[W];let f;try{let d=l.resolve(s,u=>i(e??t,"TAG_RESOLVE_FAILED",u),n.options);f=O(d)?d:new E(d);}catch(d){let u=d instanceof Error?d.message:String(d);i(e??t,"TAG_RESOLVE_FAILED",u),f=new E(s);}return f.range=a,f.source=s,r&&(f.type=r),c&&(f.tag=c),l.format&&(f.format=l.format),o&&(f.comment=o),f}function ba(n,t,e,i,s){if(e==="!")return n[W];let r=[];for(let a of n.tags)if(!a.collection&&a.tag===e)if(a.default&&a.test)r.push(a);else return a;for(let a of r)if(a.test?.test(t))return a;let o=n.knownTags[e];return o&&!o.collection?(n.tags.push(Object.assign({},o,{default:false,test:void 0})),o):(s(i,"TAG_RESOLVE_FAILED",`Unresolved tag: ${e}`,e!=="tag:yaml.org,2002:str"),n[W])}function wa({atKey:n,directives:t,schema:e},i,s,r){let o=e.tags.find(a=>(a.default===true||n&&a.default==="key")&&a.test?.test(i))||e[W];if(e.compat){let a=e.compat.find(c=>c.default&&c.test?.test(i))??e[W];if(o.tag!==a.tag){let c=t.tagString(o.tag),l=t.tagString(a.tag),f=`Value may be parsed as either ${c} or ${l}`;r(s,"TAG_RESOLVE_FAILED",f,true);}}return o}function tr(n,t,e){if(t){e??(e=t.length);for(let i=e-1;i>=0;--i){let s=t[i];switch(s.type){case "space":case "comment":case "newline":n-=s.source.length;continue}for(s=t[++i];s?.type==="space";)n+=s.source.length,s=t[++i];break}}return n}var _a={composeNode:Ui,composeEmptyNode:jn};function Ui(n,t,e,i){let s=n.atKey,{spaceBefore:r,comment:o,anchor:a,tag:c}=e,l,f=true;switch(t.type){case "alias":l=Sa(n,t,i),(a||c)&&i(t,"ALIAS_PROPS","An alias node must not specify any properties");break;case "scalar":case "single-quoted-scalar":case "double-quoted-scalar":case "block-scalar":l=Mi(n,t,c,i),a&&(l.anchor=a.source.substring(1));break;case "block-map":case "block-seq":case "flow-collection":l=Xs(_a,n,t,e,i),a&&(l.anchor=a.source.substring(1));break;default:{let d=t.type==="error"?t.message:`Unsupported token (type: ${t.type})`;i(t,"UNEXPECTED_TOKEN",d),l=jn(n,t.offset,void 0,null,e,i),f=false;}}return a&&l.anchor===""&&i(a,"BAD_ALIAS","Anchor cannot be an empty string"),s&&n.options.stringKeys&&(!O(l)||typeof l.value!="string"||l.tag&&l.tag!=="tag:yaml.org,2002:str")&&i(c??t,"NON_STRING_KEY","With stringKeys, all keys must be strings"),r&&(l.spaceBefore=true),o&&(t.type==="scalar"&&t.source===""?l.comment=o:l.commentBefore=o),n.options.keepSourceTokens&&f&&(l.srcToken=t),l}function jn(n,t,e,i,{spaceBefore:s,comment:r,anchor:o,tag:a,end:c},l){let f={type:"scalar",offset:tr(t,e,i),indent:-1,source:""},d=Mi(n,f,a,l);return o&&(d.anchor=o.source.substring(1),d.anchor===""&&l(o,"BAD_ALIAS","Anchor cannot be an empty string")),s&&(d.spaceBefore=true),r&&(d.comment=r,d.range[2]=c),d}function Sa({options:n},{offset:t,source:e,end:i},s){let r=new Ee(e.substring(1));r.source===""&&s(t,"BAD_ALIAS","Alias cannot be an empty string"),r.source.endsWith(":")&&s(t+e.length-1,"BAD_ALIAS","Alias ending in : is ambiguous",true);let o=t+e.length,a=we(i,o,n.strict,s);return r.range=[t,o,a.offset],a.comment&&(r.comment=a.comment),r}function nr(n,t,{offset:e,start:i,value:s,end:r},o){let a=Object.assign({p:t},n),c=new Be(void 0,a),l={atKey:false,atRoot:true,directives:c.directives,options:c.options,schema:c.schema},f=be(i,{indicator:"doc-start",next:s??r?.[0],offset:e,onError:o,parentIndent:0,startOnNewline:true});f.found&&(c.directives.docStart=true,s&&(s.type==="block-map"||s.type==="block-seq")&&!f.hasNewline&&o(f.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),c.contents=s?Ui(l,s,f,o):jn(l,f.end,i,null,f,o);let d=c.contents.range[2],u=we(r,d,false,o);return u.comment&&(c.comment=u.comment),c.range=[e,d,u.offset],c}function Ut(n){if(typeof n=="number")return [n,n+1];if(Array.isArray(n))return n.length===2?n:[n[0],n[1]];let{offset:t,source:e}=n;return [t,t+(typeof e=="string"?e.length:1)]}function ir(n){let t="",e=false,i=false;for(let s=0;s<n.length;++s){let r=n[s];switch(r[0]){case "#":t+=(t===""?"":i?`
101
+ `,r:"\r",t:" ",v:"\v",N:"\x85",k:"\xA0",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function ya(n,t,e,i){let s=n.substr(t,e),o=s.length===e&&/^[0-9a-fA-F]+$/.test(s)?parseInt(s,16):NaN;if(isNaN(o)){let a=n.substr(t-2,e+2);return i(t-2,"BAD_DQ_ESCAPE",`Invalid escape sequence ${a}`),a}return String.fromCodePoint(o)}function Mi(n,t,e,i){let{value:s,type:r,comment:o,range:a}=t.type==="block-scalar"?Bi(n,t,i):Di(t,n.options.strict,i),c=e?n.directives.tagName(e.source,d=>i(e,"TAG_RESOLVE_FAILED",d)):null,l;n.options.stringKeys&&n.atKey?l=n.schema[W]:c?l=ba(n.schema,s,c,e,i):t.type==="scalar"?l=wa(n,s,t,i):l=n.schema[W];let f;try{let d=l.resolve(s,u=>i(e??t,"TAG_RESOLVE_FAILED",u),n.options);f=O(d)?d:new E(d);}catch(d){let u=d instanceof Error?d.message:String(d);i(e??t,"TAG_RESOLVE_FAILED",u),f=new E(s);}return f.range=a,f.source=s,r&&(f.type=r),c&&(f.tag=c),l.format&&(f.format=l.format),o&&(f.comment=o),f}function ba(n,t,e,i,s){if(e==="!")return n[W];let r=[];for(let a of n.tags)if(!a.collection&&a.tag===e)if(a.default&&a.test)r.push(a);else return a;for(let a of r)if(a.test?.test(t))return a;let o=n.knownTags[e];return o&&!o.collection?(n.tags.push(Object.assign({},o,{default:false,test:void 0})),o):(s(i,"TAG_RESOLVE_FAILED",`Unresolved tag: ${e}`,e!=="tag:yaml.org,2002:str"),n[W])}function wa({atKey:n,directives:t,schema:e},i,s,r){let o=e.tags.find(a=>(a.default===true||n&&a.default==="key")&&a.test?.test(i))||e[W];if(e.compat){let a=e.compat.find(c=>c.default&&c.test?.test(i))??e[W];if(o.tag!==a.tag){let c=t.tagString(o.tag),l=t.tagString(a.tag),f=`Value may be parsed as either ${c} or ${l}`;r(s,"TAG_RESOLVE_FAILED",f,true);}}return o}function tr(n,t,e){if(t){e??(e=t.length);for(let i=e-1;i>=0;--i){let s=t[i];switch(s.type){case "space":case "comment":case "newline":n-=s.source.length;continue}for(s=t[++i];s?.type==="space";)n+=s.source.length,s=t[++i];break}}return n}var _a={composeNode:Ui,composeEmptyNode:jn};function Ui(n,t,e,i){let s=n.atKey,{spaceBefore:r,comment:o,anchor:a,tag:c}=e,l,f=true;switch(t.type){case "alias":l=Sa(n,t,i),(a||c)&&i(t,"ALIAS_PROPS","An alias node must not specify any properties");break;case "scalar":case "single-quoted-scalar":case "double-quoted-scalar":case "block-scalar":l=Mi(n,t,c,i),a&&(l.anchor=a.source.substring(1));break;case "block-map":case "block-seq":case "flow-collection":l=Xs(_a,n,t,e,i),a&&(l.anchor=a.source.substring(1));break;default:{let d=t.type==="error"?t.message:`Unsupported token (type: ${t.type})`;i(t,"UNEXPECTED_TOKEN",d),l=jn(n,t.offset,void 0,null,e,i),f=false;}}return a&&l.anchor===""&&i(a,"BAD_ALIAS","Anchor cannot be an empty string"),s&&n.options.stringKeys&&(!O(l)||typeof l.value!="string"||l.tag&&l.tag!=="tag:yaml.org,2002:str")&&i(c??t,"NON_STRING_KEY","With stringKeys, all keys must be strings"),r&&(l.spaceBefore=true),o&&(t.type==="scalar"&&t.source===""?l.comment=o:l.commentBefore=o),n.options.keepSourceTokens&&f&&(l.srcToken=t),l}function jn(n,t,e,i,{spaceBefore:s,comment:r,anchor:o,tag:a,end:c},l){let f={type:"scalar",offset:tr(t,e,i),indent:-1,source:""},d=Mi(n,f,a,l);return o&&(d.anchor=o.source.substring(1),d.anchor===""&&l(o,"BAD_ALIAS","Anchor cannot be an empty string")),s&&(d.spaceBefore=true),r&&(d.comment=r,d.range[2]=c),d}function Sa({options:n},{offset:t,source:e,end:i},s){let r=new Ee(e.substring(1));r.source===""&&s(t,"BAD_ALIAS","Alias cannot be an empty string"),r.source.endsWith(":")&&s(t+e.length-1,"BAD_ALIAS","Alias ending in : is ambiguous",true);let o=t+e.length,a=we(i,o,n.strict,s);return r.range=[t,o,a.offset],a.comment&&(r.comment=a.comment),r}function nr(n,t,{offset:e,start:i,value:s,end:r},o){let a=Object.assign({p:t},n),c=new Be(void 0,a),l={atKey:false,atRoot:true,directives:c.directives,options:c.options,schema:c.schema},f=be(i,{indicator:"doc-start",next:s??r?.[0],offset:e,onError:o,parentIndent:0,startOnNewline:true});f.found&&(c.directives.docStart=true,s&&(s.type==="block-map"||s.type==="block-seq")&&!f.hasNewline&&o(f.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),c.contents=s?Ui(l,s,f,o):jn(l,f.end,i,null,f,o);let d=c.contents.range[2],u=we(r,d,false,o);return u.comment&&(c.comment=u.comment),c.range=[e,d,u.offset],c}function Ut(n){if(typeof n=="number")return [n,n+1];if(Array.isArray(n))return n.length===2?n:[n[0],n[1]];let{offset:t,source:e}=n;return [t,t+(typeof e=="string"?e.length:1)]}function ir(n){let t="",e=false,i=false;for(let s=0;s<n.length;++s){let r=n[s];switch(r[0]){case "#":t+=(t===""?"":i?`
102
102
 
103
103
  `:`
104
104
  `)+(r.substring(1)||" "),e=true,i=false;break;case "%":n[s+1]?.[0]!=="#"&&(s+=1),e=false;break;default:e||(i=true),e=false;}}return {comment:t,afterEmptyLine:i}}var Pt=class{constructor(t={}){this.doc=null,this.atDirectives=false,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(e,i,s,r)=>{let o=Ut(e);r?this.warnings.push(new Dt(o,i,s)):this.errors.push(new ce(o,i,s));},this.directives=new ge({version:t.version||"1.2"}),this.options=t;}decorate(t,e){let{comment:i,afterEmptyLine:s}=ir(this.prelude);if(i){let r=t.contents;if(e)t.comment=t.comment?`${t.comment}
@@ -131,7 +131,7 @@ ${e.comment}`:e.comment;}this.doc.range[2]=e.offset;break}default:this.errors.pu
131
131
  `,e)+1;}yield*this.pop();break;default:yield*this.pop(),yield*this.step();}}*blockMap(t){let e=t.items[t.items.length-1];switch(this.type){case "newline":if(this.onKeyLine=false,e.value){let i="end"in e.value?e.value.end:void 0;(Array.isArray(i)?i[i.length-1]:void 0)?.type==="comment"?i?.push(this.sourceToken):t.items.push({start:[this.sourceToken]});}else e.sep?e.sep.push(this.sourceToken):e.start.push(this.sourceToken);return;case "space":case "comment":if(e.value)t.items.push({start:[this.sourceToken]});else if(e.sep)e.sep.push(this.sourceToken);else {if(this.atIndentedComment(e.start,t.indent)){let s=t.items[t.items.length-2]?.value?.end;if(Array.isArray(s)){Array.prototype.push.apply(s,e.start),s.push(this.sourceToken),t.items.pop();return}}e.start.push(this.sourceToken);}return}if(this.indent>=t.indent){let i=!this.onKeyLine&&this.indent===t.indent,s=i&&(e.sep||e.explicitKey)&&this.type!=="seq-item-ind",r=[];if(s&&e.sep&&!e.value){let o=[];for(let a=0;a<e.sep.length;++a){let c=e.sep[a];switch(c.type){case "newline":o.push(a);break;case "space":break;case "comment":c.indent>t.indent&&(o.length=0);break;default:o.length=0;}}o.length>=2&&(r=e.sep.splice(o[1]));}switch(this.type){case "anchor":case "tag":s||e.value?(r.push(this.sourceToken),t.items.push({start:r}),this.onKeyLine=true):e.sep?e.sep.push(this.sourceToken):e.start.push(this.sourceToken);return;case "explicit-key-ind":!e.sep&&!e.explicitKey?(e.start.push(this.sourceToken),e.explicitKey=true):s||e.value?(r.push(this.sourceToken),t.items.push({start:r,explicitKey:true})):this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:true}]}),this.onKeyLine=true;return;case "map-value-ind":if(e.explicitKey)if(e.sep)if(e.value)t.items.push({start:[],key:null,sep:[this.sourceToken]});else if(Me(e.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:r,key:null,sep:[this.sourceToken]}]});else if(fr(e.key)&&!Me(e.sep,"newline")){let o=ut(e.start),a=e.key,c=e.sep;c.push(this.sourceToken),delete e.key,delete e.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:a,sep:c}]});}else r.length>0?e.sep=e.sep.concat(r,this.sourceToken):e.sep.push(this.sourceToken);else if(Me(e.start,"newline"))Object.assign(e,{key:null,sep:[this.sourceToken]});else {let o=ut(e.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:null,sep:[this.sourceToken]}]});}else e.sep?e.value||s?t.items.push({start:r,key:null,sep:[this.sourceToken]}):Me(e.sep,"map-value-ind")?this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):e.sep.push(this.sourceToken):Object.assign(e,{key:null,sep:[this.sourceToken]});this.onKeyLine=true;return;case "alias":case "scalar":case "single-quoted-scalar":case "double-quoted-scalar":{let o=this.flowScalar(this.type);s||e.value?(t.items.push({start:r,key:o,sep:[]}),this.onKeyLine=true):e.sep?this.stack.push(o):(Object.assign(e,{key:o,sep:[]}),this.onKeyLine=true);return}default:{let o=this.startBlockValue(t);if(o){if(o.type==="block-seq"){if(!e.explicitKey&&e.sep&&!Me(e.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else i&&t.items.push({start:r});this.stack.push(o);return}}}}yield*this.pop(),yield*this.step();}*blockSequence(t){let e=t.items[t.items.length-1];switch(this.type){case "newline":if(e.value){let i="end"in e.value?e.value.end:void 0;(Array.isArray(i)?i[i.length-1]:void 0)?.type==="comment"?i?.push(this.sourceToken):t.items.push({start:[this.sourceToken]});}else e.start.push(this.sourceToken);return;case "space":case "comment":if(e.value)t.items.push({start:[this.sourceToken]});else {if(this.atIndentedComment(e.start,t.indent)){let s=t.items[t.items.length-2]?.value?.end;if(Array.isArray(s)){Array.prototype.push.apply(s,e.start),s.push(this.sourceToken),t.items.pop();return}}e.start.push(this.sourceToken);}return;case "anchor":case "tag":if(e.value||this.indent<=t.indent)break;e.start.push(this.sourceToken);return;case "seq-item-ind":if(this.indent!==t.indent)break;e.value||Me(e.start,"seq-item-ind")?t.items.push({start:[this.sourceToken]}):e.start.push(this.sourceToken);return}if(this.indent>t.indent){let i=this.startBlockValue(t);if(i){this.stack.push(i);return}}yield*this.pop(),yield*this.step();}*flowCollection(t){let e=t.items[t.items.length-1];if(this.type==="flow-error-end"){let i;do yield*this.pop(),i=this.peek(1);while(i&&i.type==="flow-collection")}else if(t.end.length===0){switch(this.type){case "comma":case "explicit-key-ind":!e||e.sep?t.items.push({start:[this.sourceToken]}):e.start.push(this.sourceToken);return;case "map-value-ind":!e||e.value?t.items.push({start:[],key:null,sep:[this.sourceToken]}):e.sep?e.sep.push(this.sourceToken):Object.assign(e,{key:null,sep:[this.sourceToken]});return;case "space":case "comment":case "newline":case "anchor":case "tag":!e||e.value?t.items.push({start:[this.sourceToken]}):e.sep?e.sep.push(this.sourceToken):e.start.push(this.sourceToken);return;case "alias":case "scalar":case "single-quoted-scalar":case "double-quoted-scalar":{let s=this.flowScalar(this.type);!e||e.value?t.items.push({start:[],key:s,sep:[]}):e.sep?this.stack.push(s):Object.assign(e,{key:s,sep:[]});return}case "flow-map-end":case "flow-seq-end":t.end.push(this.sourceToken);return}let i=this.startBlockValue(t);i?this.stack.push(i):(yield*this.pop(),yield*this.step());}else {let i=this.peek(2);if(i.type==="block-map"&&(this.type==="map-value-ind"&&i.indent===t.indent||this.type==="newline"&&!i.items[i.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&i.type!=="flow-collection"){let s=Zn(i),r=ut(s);cr(t);let o=t.end.splice(1,t.end.length);o.push(this.sourceToken);let a={type:"block-map",offset:t.offset,indent:t.indent,items:[{start:r,key:t,sep:o}]};this.onKeyLine=true,this.stack[this.stack.length-1]=a;}else yield*this.lineEnd(t);}}flowScalar(t){if(this.onNewLine){let e=this.source.indexOf(`
132
132
  `)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
133
133
  `,e)+1;}return {type:t,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(t){switch(this.type){case "alias":case "scalar":case "single-quoted-scalar":case "double-quoted-scalar":return this.flowScalar(this.type);case "block-scalar-header":return {type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case "flow-map-start":case "flow-seq-start":return {type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case "seq-item-ind":return {type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case "explicit-key-ind":{this.onKeyLine=true;let e=Zn(t),i=ut(e);return i.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,explicitKey:true}]}}case "map-value-ind":{this.onKeyLine=true;let e=Zn(t),i=ut(e);return {type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(t,e){return this.type!=="comment"||this.indent<=e?false:t.every(i=>i.type==="newline"||i.type==="space")}*documentEnd(t){this.type!=="doc-mode"&&(t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()));}*lineEnd(t){switch(this.type){case "comma":case "doc-start":case "doc-end":case "flow-seq-end":case "flow-map-end":case "map-value-ind":yield*this.pop(),yield*this.step();break;case "newline":this.onKeyLine=false;case "space":case "comment":default:t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop());}}};function Na(n){let t=n.prettyErrors!==false;return {lineCounter:n.lineCounter||t&&new Kt||null,prettyErrors:t}}function ur(n,t={}){let{lineCounter:e,prettyErrors:i}=Na(t),s=new Ft(e?.addNewLine),r=new Pt(t),o=null;for(let a of r.compose(s.parse(n),true,n.length))if(!o)o=a;else if(o.options.logLevel!=="silent"){o.errors.push(new ce(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return i&&e&&(o.errors.forEach(Li(n,e)),o.warnings.forEach(Li(n,e))),o}function qi(n,t,e){let i;let s=ur(n,e);if(!s)return null;if(s.warnings.forEach(r=>(s.options.logLevel,void 0)),s.errors.length>0){if(s.options.logLevel!=="silent")throw s.errors[0];s.errors=[];}return s.toJS(Object.assign({reviver:i},e))}var jt=class{parse(t,e={}){let{validate:i=true,strict:s=false}=e,r;try{r=qi(t);}catch(a){throw new k(`Failed to parse YAML: ${a instanceof Error?a.message:String(a)}`)}if(typeof r!="object"||r===null)throw new k("KSY file must contain an object");let o=r;if(i){let a=this.validate(o,{strict:s});if(!a.valid){let c=a.errors.map(l=>l.message).join("; ");throw new je(`Schema validation failed: ${c}`)}a.warnings.length>0;}return o}validate(t,e={}){let{strict:i=false,isNested:s=false}=e,r=[],o=[];return !t.meta&&!s?r.push({message:'Missing required "meta" section',path:[],code:"MISSING_META"}):t.meta&&(t.meta.id?typeof t.meta.id!="string"?r.push({message:'"meta.id" must be a string',path:["meta","id"],code:"INVALID_META_ID_TYPE"}):/^[a-z][a-z0-9_]*$/.test(t.meta.id)||o.push({message:'"meta.id" should follow snake_case naming convention',path:["meta","id"],code:"META_ID_NAMING"}):r.push({message:'Missing required "meta.id" field',path:["meta"],code:"MISSING_META_ID"}),t.meta.endian&&typeof t.meta.endian=="string"&&t.meta.endian!=="le"&&t.meta.endian!=="be"&&r.push({message:'"meta.endian" must be "le" or "be"',path:["meta","endian"],code:"INVALID_ENDIAN"})),t.seq&&(Array.isArray(t.seq)?t.seq.forEach((a,c)=>{this.validateAttribute(a,["seq",String(c)],r,o,i);}):r.push({message:'"seq" must be an array',path:["seq"],code:"INVALID_SEQ_TYPE"})),t.instances&&(typeof t.instances!="object"?r.push({message:'"instances" must be an object',path:["instances"],code:"INVALID_INSTANCES_TYPE"}):Object.entries(t.instances).forEach(([a,c])=>{this.validateAttribute(c,["instances",a],r,o,i);})),t.types&&(typeof t.types!="object"?r.push({message:'"types" must be an object',path:["types"],code:"INVALID_TYPES_TYPE"}):Object.entries(t.types).forEach(([a,c])=>{let l=this.validate(c,{...e,isNested:true});r.push(...l.errors.map(f=>({...f,path:["types",a,...f.path]}))),o.push(...l.warnings.map(f=>({...f,path:["types",a,...f.path]})));})),t.enums&&typeof t.enums!="object"&&r.push({message:'"enums" must be an object',path:["enums"],code:"INVALID_ENUMS_TYPE"}),{valid:r.length===0&&(i?o.length===0:true),errors:r,warnings:o}}validateAttribute(t,e,i,s,r){t.id&&typeof t.id=="string"&&(/^[a-z][a-z0-9_]*$/.test(t.id)||s.push({message:`Field "${t.id}" should follow snake_case naming convention`,path:[...e,"id"],code:"FIELD_ID_NAMING"})),t.repeat&&(t.repeat!=="expr"&&t.repeat!=="eos"&&t.repeat!=="until"&&i.push({message:'"repeat" must be "expr", "eos", or "until"',path:[...e,"repeat"],code:"INVALID_REPEAT"}),t.repeat==="expr"&&!t["repeat-expr"]&&i.push({message:'"repeat-expr" is required when repeat is "expr"',path:[...e,"repeat-expr"],code:"MISSING_REPEAT_EXPR"}),t.repeat==="until"&&!t["repeat-until"]&&i.push({message:'"repeat-until" is required when repeat is "until"',path:[...e,"repeat-until"],code:"MISSING_REPEAT_UNTIL"})),t["size-eos"]&&t.size&&s.push({message:'"size-eos" and "size" are mutually exclusive',path:[...e],code:"SIZE_EOS_WITH_SIZE"}),t.contents&&!Array.isArray(t.contents)&&typeof t.contents!="string"&&i.push({message:'"contents" must be an array or string',path:[...e,"contents"],code:"INVALID_CONTENTS_TYPE"});}parseWithImports(t,e,i={}){let s=this.parse(t,i);if(!s.meta.imports||s.meta.imports.length===0)return s;let r={};for(let o of s.meta.imports){if(!e.has(o))throw new k(`Import not found: ${o}. Available imports: ${Array.from(e.keys()).join(", ")}`);let a=e.get(o),c=this.parse(a,{...i,validate:false}),l=this.extractNamespace(o);if(c.types)for(let[f,d]of Object.entries(c.types)){let u=`${l}::${f}`;r[u]=d;}if(r[l]={meta:c.meta,seq:c.seq,instances:c.instances,types:c.types,enums:c.enums},c.enums){s.enums||(s.enums={});for(let[f,d]of Object.entries(c.enums)){let u=`${l}::${f}`;s.enums[u]=d;}}}return Object.keys(r).length>0&&(s.types={...r,...s.types}),s}extractNamespace(t){let i=(t.startsWith("/")?t.slice(1):t).split("/");return i[i.length-1]}};var qt=class n{constructor(t,e=null,i=null,s){this.h=t;this.d=e;this.parentStack=[];this.o={};this.c={};i!==null&&this.parentStack.push(i),s&&(this.c=s);}get io(){return this.h}get root(){return this.d}get parent(){return this.parentStack.length>0?this.parentStack[this.parentStack.length-1]:null}get current(){return this.o}set current(t){this.o=t;}pushParent(t){this.parentStack.push(t);}popParent(){return this.parentStack.pop()}resolve(t){switch(t){case "_io":return this.h;case "_root":return this.d;case "_parent":return this.parent;case "_index":return this.o._index;default:return t in this.o?this.o[t]:void 0}}set(t,e){this.o[t]=e;}getEnumValue(t,e){let i=this.c[t];if(i){for(let[s,r]of Object.entries(i))if(r===e){let o=Number(s);return isNaN(o)?s:o}}}hasEnum(t){return t in this.c}createChild(t){return new n(t||this.h,this.d||this.o,this.o,this.c)}clone(){let t=new n(this.h,this.d,this.parent,this.c);return t.o={...this.o},t.parentStack=[...this.parentStack],t}};function L(n,t=null,e=0){return {type:n,value:t,position:e}}var Hn=class{constructor(t){this.position=0;this.current=null;this.input=t,this.current=t.length>0?t[0]:null;}tokenize(){let t=[];for(;this.current!==null;){if(this.isWhitespace(this.current)){this.skipWhitespace();continue}if(this.isDigit(this.current)){t.push(this.readNumber());continue}if(this.isIdentifierStart(this.current)){t.push(this.readIdentifierOrKeyword());continue}if(this.current==='"'||this.current==="'"){t.push(this.readString());continue}let e=this.readOperator();if(e){t.push(e);continue}throw new k(`Unexpected character: ${this.current}`,this.position)}return t.push(L("EOF",null,this.position)),t}advance(){this.position++,this.current=this.position<this.input.length?this.input[this.position]:null;}peek(t=1){let e=this.position+t;return e<this.input.length?this.input[e]:null}isWhitespace(t){return /\s/.test(t)}isDigit(t){return /[0-9]/.test(t)}isIdentifierStart(t){return /[a-zA-Z_]/.test(t)}isIdentifierPart(t){return /[a-zA-Z0-9_]/.test(t)}skipWhitespace(){for(;this.current!==null&&this.isWhitespace(this.current);)this.advance();}readNumber(){let t=this.position,e="";if(this.current==="0"&&this.peek()==="x"){for(e+=this.current,this.advance(),e+=this.current,this.advance();this.current!==null&&/[0-9a-fA-F]/.test(this.current);)e+=this.current,this.advance();return L("NUMBER",parseInt(e,16),t)}if(this.current==="0"&&this.peek()==="b"){for(e+=this.current,this.advance(),e+=this.current,this.advance();this.current!==null&&/[01]/.test(this.current);)e+=this.current,this.advance();return L("NUMBER",parseInt(e,2),t)}for(;this.current!==null&&this.isDigit(this.current);)e+=this.current,this.advance();if(this.current==="."&&this.peek()&&this.isDigit(this.peek())){for(e+=this.current,this.advance();this.current!==null&&this.isDigit(this.current);)e+=this.current,this.advance();return L("NUMBER",parseFloat(e),t)}return L("NUMBER",parseInt(e,10),t)}readIdentifierOrKeyword(){let t=this.position,e="";for(;this.current!==null&&this.isIdentifierPart(this.current);)e+=this.current,this.advance();switch(e){case "true":return L("BOOLEAN",true,t);case "false":return L("BOOLEAN",false,t);case "and":return L("AND",e,t);case "or":return L("OR",e,t);case "not":return L("NOT",e,t);default:return L("IDENTIFIER",e,t)}}readString(){let t=this.position,e=this.current,i="";for(this.advance();this.current!==null&&this.current!==e;){if(this.current==="\\"){if(this.advance(),this.current===null)throw new k("Unterminated string",t);let s=this.current;s==="n"?i+=`
134
- `:s==="t"?i+=" ":s==="r"?i+="\r":s==="\\"?i+="\\":s==='"'?i+='"':s==="'"?i+="'":i+=s;}else i+=this.current;this.advance();}if(this.current===null)throw new k("Unterminated string",t);return this.advance(),L("STRING",i,t)}readOperator(){let t=this.position,e=this.current;switch(e){case "+":return this.advance(),L("PLUS",e,t);case "-":return this.advance(),L("MINUS",e,t);case "*":return this.advance(),L("STAR",e,t);case "/":return this.advance(),L("SLASH",e,t);case "%":return this.advance(),L("PERCENT",e,t);case "<":return this.advance(),this.current==="="?(this.advance(),L("LE","<=",t)):this.current==="<"?(this.advance(),L("LSHIFT","<<",t)):L("LT","<",t);case ">":return this.advance(),this.current==="="?(this.advance(),L("GE",">=",t)):this.current===">"?(this.advance(),L("RSHIFT",">>",t)):L("GT",">",t);case "=":if(this.advance(),this.current==="=")return this.advance(),L("EQ","==",t);throw new k("Expected == for equality",t);case "!":if(this.advance(),this.current==="=")return this.advance(),L("NE","!=",t);throw new k("Expected != for inequality",t);case "&":return this.advance(),L("AMPERSAND",e,t);case "|":return this.advance(),L("PIPE",e,t);case "^":return this.advance(),L("CARET",e,t);case "?":return this.advance(),L("QUESTION",e,t);case ":":return this.advance(),this.current===":"?(this.advance(),L("DOUBLE_COLON","::",t)):L("COLON",e,t);case "(":return this.advance(),L("LPAREN",e,t);case ")":return this.advance(),L("RPAREN",e,t);case "[":return this.advance(),L("LBRACKET",e,t);case "]":return this.advance(),L("RBRACKET",e,t);case ".":return this.advance(),L("DOT",e,t);case ",":return this.advance(),L("COMMA",e,t);default:return null}}};function hr(n){return {kind:"Literal",value:n}}function dr(n){return {kind:"Identifier",name:n}}function ue(n,t,e){return {kind:"BinaryOp",operator:n,left:t,right:e}}function pr(n,t){return {kind:"UnaryOp",operator:n,operand:t}}function mr(n,t,e){return {kind:"Ternary",condition:n,ifTrue:t,ifFalse:e}}function gr(n,t){return {kind:"MemberAccess",object:n,property:t}}function yr(n,t){return {kind:"IndexAccess",object:n,index:t}}function br(n,t,e){return {kind:"MethodCall",object:n,method:t,args:e}}function wr(n,t){return {kind:"EnumAccess",enumName:n,value:t}}function _r(n){return {kind:"ArrayLiteral",elements:n}}var Yn=class{constructor(t){this.position=0;this.tokens=t;}parse(){let t=this.parseTernary();if(!this.isAtEnd())throw new k(`Unexpected token: ${this.current().type}`,this.current().position);return t}current(){return this.tokens[this.position]}isAtEnd(){return this.current().type==="EOF"}advance(){return this.isAtEnd()||this.position++,this.tokens[this.position-1]}match(...t){for(let e of t)if(this.current().type===e)return this.advance(),true;return false}expect(t,e){if(this.current().type!==t)throw new k(e,this.current().position);return this.advance()}parseTernary(){let t=this.parseLogicalOr();if(this.match("QUESTION")){let e=this.parseTernary();this.expect("COLON","Expected : in ternary expression");let i=this.parseTernary();return mr(t,e,i)}return t}parseLogicalOr(){let t=this.parseLogicalAnd();for(;this.match("OR");){let i=this.parseLogicalAnd();t=ue("or",t,i);}return t}parseLogicalAnd(){let t=this.parseBitwiseOr();for(;this.match("AND");){let i=this.parseBitwiseOr();t=ue("and",t,i);}return t}parseBitwiseOr(){let t=this.parseBitwiseXor();for(;this.match("PIPE");){let i=this.parseBitwiseXor();t=ue("|",t,i);}return t}parseBitwiseXor(){let t=this.parseBitwiseAnd();for(;this.match("CARET");){let i=this.parseBitwiseAnd();t=ue("^",t,i);}return t}parseBitwiseAnd(){let t=this.parseEquality();for(;this.match("AMPERSAND");){let i=this.parseEquality();t=ue("&",t,i);}return t}parseEquality(){let t=this.parseRelational();for(;this.match("EQ","NE");){let e=this.tokens[this.position-1].value,i=this.parseRelational();t=ue(e,t,i);}return t}parseRelational(){let t=this.parseBitShift();for(;this.match("LT","LE","GT","GE");){let e=this.tokens[this.position-1].value,i=this.parseBitShift();t=ue(e,t,i);}return t}parseBitShift(){let t=this.parseAdditive();for(;this.match("LSHIFT","RSHIFT");){let e=this.tokens[this.position-1].value,i=this.parseAdditive();t=ue(e,t,i);}return t}parseAdditive(){let t=this.parseMultiplicative();for(;this.match("PLUS","MINUS");){let e=this.tokens[this.position-1].value,i=this.parseMultiplicative();t=ue(e,t,i);}return t}parseMultiplicative(){let t=this.parseUnary();for(;this.match("STAR","SLASH","PERCENT");){let e=this.tokens[this.position-1].value,i=this.parseUnary();t=ue(e,t,i);}return t}parseUnary(){if(this.match("MINUS","NOT")){let t=this.tokens[this.position-1].value,e=this.parseUnary();return pr(t,e)}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary();for(;;)if(this.match("DOT")){let e=this.expect("IDENTIFIER","Expected property name after .");t=gr(t,e.value);}else if(this.match("LBRACKET")){let e=this.parseTernary();this.expect("RBRACKET","Expected ] after array index"),t=yr(t,e);}else if(this.current().type==="LPAREN")if(t.kind==="MemberAccess"){this.advance();let e=[];if(this.current().type!=="RPAREN")for(e.push(this.parseTernary());this.match("COMMA");)e.push(this.parseTernary());this.expect("RPAREN","Expected ) after arguments");let i=t;t=br(i.object,i.property,e);}else break;else break;return t}parsePrimary(){if(this.match("NUMBER","STRING","BOOLEAN")){let t=this.tokens[this.position-1];return hr(t.value)}if(this.match("IDENTIFIER")){let t=this.tokens[this.position-1].value;if(this.match("DOUBLE_COLON")){let e=this.expect("IDENTIFIER","Expected enum value after ::");return wr(t,e.value)}return dr(t)}if(this.match("LPAREN")){let t=this.parseTernary();return this.expect("RPAREN","Expected ) after expression"),t}if(this.match("LBRACKET")){let t=[];if(this.current().type!=="RBRACKET")for(t.push(this.parseTernary());this.match("COMMA");)t.push(this.parseTernary());return this.expect("RBRACKET","Expected ] after array literal"),_r(t)}throw new k(`Unexpected token: ${this.current().type}`,this.current().position)}};var Gn=class{evaluate(t,e){let i=t;switch(t.kind){case "Literal":return i.value;case "Identifier":return this.evaluateIdentifier(i.name,e);case "BinaryOp":return this.evaluateBinaryOp(i.operator,i.left,i.right,e);case "UnaryOp":return this.evaluateUnaryOp(i.operator,i.operand,e);case "Ternary":return this.evaluateTernary(i.condition,i.ifTrue,i.ifFalse,e);case "MemberAccess":return this.evaluateMemberAccess(i.object,i.property,e);case "IndexAccess":return this.evaluateIndexAccess(i.object,i.index,e);case "MethodCall":return this.evaluateMethodCall(i.object,i.method,i.args,e);case "EnumAccess":return this.evaluateEnumAccess(i.enumName,i.value,e);case "ArrayLiteral":return this.evaluateArrayLiteral(i.elements,e);default:throw new k(`Unknown AST node kind: ${t.kind}`)}}evaluateIdentifier(t,e){return e.resolve(t)}evaluateBinaryOp(t,e,i,s){let r=this.evaluate(e,s),o=this.evaluate(i,s);switch(t){case "+":return this.add(r,o);case "-":return this.toNumber(r)-this.toNumber(o);case "*":return this.toNumber(r)*this.toNumber(o);case "/":return this.toNumber(r)/this.toNumber(o);case "%":return this.modulo(this.toNumber(r),this.toNumber(o));case "<":return this.compare(r,o)<0;case "<=":return this.compare(r,o)<=0;case ">":return this.compare(r,o)>0;case ">=":return this.compare(r,o)>=0;case "==":return this.equals(r,o);case "!=":return !this.equals(r,o);case "<<":return this.bitwiseOp(r,o,(a,c)=>a<<c);case ">>":return this.bitwiseOp(r,o,(a,c)=>a>>c);case "&":return this.bitwiseOp(r,o,(a,c)=>a&c);case "|":return this.bitwiseOp(r,o,(a,c)=>a|c);case "^":return this.bitwiseOp(r,o,(a,c)=>a^c);case "and":return this.toBoolean(r)&&this.toBoolean(o);case "or":return this.toBoolean(r)||this.toBoolean(o);default:throw new k(`Unknown binary operator: ${t}`)}}evaluateUnaryOp(t,e,i){let s=this.evaluate(e,i);switch(t){case "-":return -this.toNumber(s);case "not":return !this.toBoolean(s);default:throw new k(`Unknown unary operator: ${t}`)}}evaluateTernary(t,e,i,s){let r=this.evaluate(t,s);return this.toBoolean(r)?this.evaluate(e,s):this.evaluate(i,s)}evaluateMemberAccess(t,e,i){let s=this.evaluate(t,i);if(s==null)throw new k(`Cannot access property ${e} of null/undefined`);if(e==="to_i")return typeof s=="number"?Math.floor(s):typeof s=="bigint"?Number(s):typeof s=="string"?parseInt(s,10):typeof s=="boolean"?s?1:0:this.toInt(s);if(e==="to_s")return String(s);if(typeof s=="object")return s[e];throw new k(`Cannot access property ${e} of non-object`)}evaluateIndexAccess(t,e,i){let s=this.evaluate(t,i),r=this.evaluate(e,i);if(Array.isArray(s)){let o=this.toInt(r);return s[o]}if(s instanceof Uint8Array){let o=this.toInt(r);return s[o]}throw new k("Index access requires an array")}evaluateMethodCall(t,e,i,s){let r=this.evaluate(t,s),o=i.map(a=>this.evaluate(a,s));if(e==="length"||e==="size"){if(Array.isArray(r)||r instanceof Uint8Array||typeof r=="string")return r.length;throw new k(`Object does not have a ${e} property`)}if(e==="to_i"){let a=o.length>0?this.toInt(o[0]):10;return typeof r=="string"?parseInt(r,a):this.toInt(r)}if(e==="to_s")return String(r);if(typeof r=="string")return this.evaluateStringMethod(r,e,o);if(Array.isArray(r)||r instanceof Uint8Array)return this.evaluateArrayMethod(r,e,o);throw new k(`Unknown method: ${e}`)}evaluateStringMethod(t,e,i){switch(e){case "substring":{let s=i.length>0?this.toInt(i[0]):0,r=i.length>1?this.toInt(i[1]):void 0;return t.substring(s,r)}case "substr":{let s=i.length>0?this.toInt(i[0]):0,r=i.length>1?this.toInt(i[1]):void 0;return t.substr(s,r)}case "reverse":return t.split("").reverse().join("");case "to_i":{let s=i.length>0?this.toInt(i[0]):10;return parseInt(t,s)}case "length":case "size":return t.length;case "upcase":case "to_upper":return t.toUpperCase();case "downcase":case "to_lower":return t.toLowerCase();case "capitalize":return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase();case "strip":case "trim":return t.trim();case "lstrip":case "trim_start":return t.trimStart();case "rstrip":case "trim_end":return t.trimEnd();case "starts_with":case "startsWith":{if(i.length===0)throw new k("starts_with requires 1 argument");return t.startsWith(String(i[0]))}case "ends_with":case "endsWith":{if(i.length===0)throw new k("ends_with requires 1 argument");return t.endsWith(String(i[0]))}case "includes":case "contains":{if(i.length===0)throw new k("includes requires 1 argument");return t.includes(String(i[0]))}case "index_of":case "indexOf":{if(i.length===0)throw new k("index_of requires 1 argument");return t.indexOf(String(i[0]))}case "split":{if(i.length===0)throw new k("split requires 1 argument");return t.split(String(i[0]))}case "replace":{if(i.length<2)throw new k("replace requires 2 arguments");return t.replace(String(i[0]),String(i[1]))}case "replace_all":case "replaceAll":{if(i.length<2)throw new k("replace_all requires 2 arguments");let s=String(i[0]),r=String(i[1]);return t.split(s).join(r)}case "pad_left":case "padStart":{if(i.length===0)throw new k("pad_left requires at least 1 argument");let s=this.toInt(i[0]),r=i.length>1?String(i[1]):" ";return t.padStart(s,r)}case "pad_right":case "padEnd":{if(i.length===0)throw new k("pad_right requires at least 1 argument");let s=this.toInt(i[0]),r=i.length>1?String(i[1]):" ";return t.padEnd(s,r)}default:throw new k(`Unknown string method: ${e}`)}}evaluateArrayMethod(t,e,i){let s=Array.isArray(t)?t:Array.from(t);switch(e){case "length":case "size":return s.length;case "first":return s[0];case "last":return s[s.length-1];case "min":return Math.min(...s.map(r=>this.toNumber(r)));case "max":return Math.max(...s.map(r=>this.toNumber(r)));case "reverse":return [...s].reverse();case "sort":return [...s].sort((r,o)=>this.compare(r,o));case "includes":case "contains":{if(i.length===0)throw new k("includes requires 1 argument");return s.some(r=>this.equals(r,i[0]))}case "index_of":case "indexOf":{if(i.length===0)throw new k("index_of requires 1 argument");return s.findIndex(r=>this.equals(r,i[0]))}case "slice":{let r=i.length>0?this.toInt(i[0]):0,o=i.length>1?this.toInt(i[1]):void 0;return s.slice(r,o)}default:throw new k(`Unknown array method: ${e}`)}}evaluateEnumAccess(t,e,i){let s=i.getEnumValue(t,e);if(s===void 0)throw new k(`Enum value "${t}::${e}" not found`);return s}add(t,e){return typeof t=="string"||typeof e=="string"?String(t)+String(e):this.toNumber(t)+this.toNumber(e)}modulo(t,e){let i=t%e;return i<0?i+e:i}bitwiseOp(t,e,i){if(typeof t=="bigint"||typeof e=="bigint"){let s=typeof t=="bigint"?t:BigInt(t),r=typeof e=="bigint"?e:BigInt(e);if(i.toString().includes("<<"))return s<<BigInt(Number(r));if(i.toString().includes(">>"))return s>>BigInt(Number(r));if(i.toString().includes("&"))return s&r;if(i.toString().includes("|"))return s|r;if(i.toString().includes("^"))return s^r}if(t==null||e===void 0||e===null)throw new k("Cannot perform bitwise operation on null/undefined");return i(this.toInt(t),this.toInt(e))}compare(t,e){if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;let i=this.toNumber(t),s=this.toNumber(e);return i<s?-1:i>s?1:0}equals(t,e){if(typeof t=="bigint"||typeof e=="bigint")return BigInt(t)===BigInt(e);let i=o=>Array.isArray(o)?o.map(a=>typeof a=="bigint"?Number(a):a):o instanceof Uint8Array?Array.from(o):null,s=i(t),r=i(e);if(s&&r){if(s.length!==r.length)return false;for(let o=0;o<s.length;o++)if(s[o]!==r[o])return false;return true}return t===e}evaluateArrayLiteral(t,e){return t.map(i=>this.evaluate(i,e))}toNumber(t){if(typeof t=="number")return t;if(typeof t=="bigint")return Number(t);if(typeof t=="boolean")return t?1:0;if(typeof t=="string")return parseFloat(t);throw new k(`Cannot convert ${typeof t} to number`)}toInt(t){return Math.floor(this.toNumber(t))}toBoolean(t){return typeof t=="boolean"?t:typeof t=="number"?t!==0:typeof t=="bigint"?t!==0n:typeof t=="string"?t.length>0:t!=null}};function Sr(n,t){let e=n.replace(/\.as<[^>]+>/g,""),s=new Hn(e).tokenize(),o=new Yn(s).parse();return new Gn().evaluate(o,t)}function yt(n){let t=n.length;for(;--t>=0;)n[t]=0;}var La=3,Ca=258,ps=29,on=256,Jt=on+1+ps,pt=30,Ba=512,Ie=new Array((Jt+2)*2);yt(Ie);var Yt=new Array(pt*2);yt(Yt);var Qt=new Array(Ba);yt(Qt);var Xt=new Array(Ca-La+1);yt(Xt);var ys=new Array(ps);yt(ys);var ni=new Array(pt);yt(ni);var Qa=(n,t,e,i)=>{let s=n&65535|0,r=n>>>16&65535|0,o=0;for(;e!==0;){o=e>2e3?2e3:e,e-=o;do s=s+t[i++]|0,r=r+s|0;while(--o);s%=65521,r%=65521;}return s|r<<16|0},tn=Qa,Xa=()=>{let n,t=[];for(var e=0;e<256;e++){n=e;for(var i=0;i<8;i++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n;}return t},el=new Uint32Array(Xa()),tl=(n,t,e,i)=>{let s=el,r=i+e;n^=-1;for(let o=i;o<r;o++)n=n>>>8^s[(n^t[o])&255];return n^-1},F=tl,We={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},bt={Z_NO_FLUSH:0,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_DEFLATED:8};var Vl=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Zl=function(n){let t=Array.prototype.slice.call(arguments,1);for(;t.length;){let e=t.shift();if(e){if(typeof e!="object")throw new TypeError(e+"must be non-object");for(let i in e)Vl(e,i)&&(n[i]=e[i]);}}return n},Hl=n=>{let t=0;for(let i=0,s=n.length;i<s;i++)t+=n[i].length;let e=new Uint8Array(t);for(let i=0,s=0,r=n.length;i<r;i++){let o=n[i];e.set(o,s),s+=o.length;}return e},oi={assign:Zl,flattenChunks:Hl},xo=true;try{String.fromCharCode.apply(null,new Uint8Array(1));}catch{xo=false;}var nn=new Uint8Array(256);for(let n=0;n<256;n++)nn[n]=n>=252?6:n>=248?5:n>=240?4:n>=224?3:n>=192?2:1;nn[254]=nn[254]=1;var Yl=n=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(n);let t,e,i,s,r,o=n.length,a=0;for(s=0;s<o;s++)e=n.charCodeAt(s),(e&64512)===55296&&s+1<o&&(i=n.charCodeAt(s+1),(i&64512)===56320&&(e=65536+(e-55296<<10)+(i-56320),s++)),a+=e<128?1:e<2048?2:e<65536?3:4;for(t=new Uint8Array(a),r=0,s=0;r<a;s++)e=n.charCodeAt(s),(e&64512)===55296&&s+1<o&&(i=n.charCodeAt(s+1),(i&64512)===56320&&(e=65536+(e-55296<<10)+(i-56320),s++)),e<128?t[r++]=e:e<2048?(t[r++]=192|e>>>6,t[r++]=128|e&63):e<65536?(t[r++]=224|e>>>12,t[r++]=128|e>>>6&63,t[r++]=128|e&63):(t[r++]=240|e>>>18,t[r++]=128|e>>>12&63,t[r++]=128|e>>>6&63,t[r++]=128|e&63);return t},Gl=(n,t)=>{if(t<65534&&n.subarray&&xo)return String.fromCharCode.apply(null,n.length===t?n:n.subarray(0,t));let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(n[i]);return e},Wl=(n,t)=>{let e=t||n.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(n.subarray(0,t));let i,s,r=new Array(e*2);for(s=0,i=0;i<e;){let o=n[i++];if(o<128){r[s++]=o;continue}let a=nn[o];if(a>4){r[s++]=65533,i+=a-1;continue}for(o&=a===2?31:a===3?15:7;a>1&&i<e;)o=o<<6|n[i++]&63,a--;if(a>1){r[s++]=65533;continue}o<65536?r[s++]=o:(o-=65536,r[s++]=55296|o>>10&1023,r[s++]=56320|o&1023);}return Gl(r,s)},Jl=(n,t)=>{t=t||n.length,t>n.length&&(t=n.length);let e=t-1;for(;e>=0&&(n[e]&192)===128;)e--;return e<0||e===0?t:e+nn[n[e]]>t?e:t},sn={string2buf:Yl,buf2string:Wl,utf8border:Jl};function Ql(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0;}var To=Ql;var Jn=16209,mc=16191,gc=function(t,e){let i,s,r,o,a,c,l,f,d,u,h,g,p,m,b,_,S,y,A,N,v,w,x,T,I=t.state;i=t.next_in,x=t.input,s=i+(t.avail_in-5),r=t.next_out,T=t.output,o=r-(e-t.avail_out),a=r+(t.avail_out-257),c=I.dmax,l=I.wsize,f=I.whave,d=I.wnext,u=I.window,h=I.hold,g=I.bits,p=I.lencode,m=I.distcode,b=(1<<I.lenbits)-1,_=(1<<I.distbits)-1;e:do{g<15&&(h+=x[i++]<<g,g+=8,h+=x[i++]<<g,g+=8),S=p[h&b];t:for(;;){if(y=S>>>24,h>>>=y,g-=y,y=S>>>16&255,y===0)T[r++]=S&65535;else if(y&16){A=S&65535,y&=15,y&&(g<y&&(h+=x[i++]<<g,g+=8),A+=h&(1<<y)-1,h>>>=y,g-=y),g<15&&(h+=x[i++]<<g,g+=8,h+=x[i++]<<g,g+=8),S=m[h&_];n:for(;;){if(y=S>>>24,h>>>=y,g-=y,y=S>>>16&255,y&16){if(N=S&65535,y&=15,g<y&&(h+=x[i++]<<g,g+=8,g<y&&(h+=x[i++]<<g,g+=8)),N+=h&(1<<y)-1,N>c){t.msg="invalid distance too far back",I.mode=Jn;break e}if(h>>>=y,g-=y,y=r-o,N>y){if(y=N-y,y>f&&I.sane){t.msg="invalid distance too far back",I.mode=Jn;break e}if(v=0,w=u,d===0){if(v+=l-y,y<A){A-=y;do T[r++]=u[v++];while(--y);v=r-N,w=T;}}else if(d<y){if(v+=l+d-y,y-=d,y<A){A-=y;do T[r++]=u[v++];while(--y);if(v=0,d<A){y=d,A-=y;do T[r++]=u[v++];while(--y);v=r-N,w=T;}}}else if(v+=d-y,y<A){A-=y;do T[r++]=u[v++];while(--y);v=r-N,w=T;}for(;A>2;)T[r++]=w[v++],T[r++]=w[v++],T[r++]=w[v++],A-=3;A&&(T[r++]=w[v++],A>1&&(T[r++]=w[v++]));}else {v=r-N;do T[r++]=T[v++],T[r++]=T[v++],T[r++]=T[v++],A-=3;while(A>2);A&&(T[r++]=T[v++],A>1&&(T[r++]=T[v++]));}}else if((y&64)===0){S=m[(S&65535)+(h&(1<<y)-1)];continue n}else {t.msg="invalid distance code",I.mode=Jn;break e}break}}else if((y&64)===0){S=p[(S&65535)+(h&(1<<y)-1)];continue t}else if(y&32){I.mode=mc;break e}else {t.msg="invalid literal/length code",I.mode=Jn;break e}break}}while(i<s&&r<a);A=g>>3,i-=A,g-=A<<3,h&=(1<<g)-1,t.next_in=i,t.next_out=r,t.avail_in=i<s?5+(s-i):5-(i-s),t.avail_out=r<a?257+(a-r):257-(r-a),I.hold=h,I.bits=g;},dt=15,Or=852,Lr=592,Cr=0,Ji=1,Rr=2,yc=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),bc=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),wc=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),_c=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),Sc=(n,t,e,i,s,r,o,a)=>{let c=a.bits,l=0,f=0,d=0,u=0,h=0,g=0,p=0,m=0,b=0,_=0,S,y,A,N,v,w=null,x,T=new Uint16Array(dt+1),I=new Uint16Array(dt+1),M=null,St,un,hn;for(l=0;l<=dt;l++)T[l]=0;for(f=0;f<i;f++)T[t[e+f]]++;for(h=c,u=dt;u>=1&&T[u]===0;u--);if(h>u&&(h=u),u===0)return s[r++]=1<<24|64<<16|0,s[r++]=1<<24|64<<16|0,a.bits=1,0;for(d=1;d<u&&T[d]===0;d++);for(h<d&&(h=d),m=1,l=1;l<=dt;l++)if(m<<=1,m-=T[l],m<0)return -1;if(m>0&&(n===Cr||u!==1))return -1;for(I[1]=0,l=1;l<dt;l++)I[l+1]=I[l]+T[l];for(f=0;f<i;f++)t[e+f]!==0&&(o[I[t[e+f]]++]=f);if(n===Cr?(w=M=o,x=20):n===Ji?(w=yc,M=bc,x=257):(w=wc,M=_c,x=0),_=0,f=0,l=d,v=r,g=h,p=0,A=-1,b=1<<h,N=b-1,n===Ji&&b>Or||n===Rr&&b>Lr)return 1;for(;;){St=l-p,o[f]+1<x?(un=0,hn=o[f]):o[f]>=x?(un=M[o[f]-x],hn=w[o[f]-x]):(un=96,hn=0),S=1<<l-p,y=1<<g,d=y;do y-=S,s[v+(_>>p)+y]=St<<24|un<<16|hn|0;while(y!==0);for(S=1<<l-1;_&S;)S>>=1;if(S!==0?(_&=S-1,_+=S):_=0,f++,--T[l]===0){if(l===u)break;l=t[e+o[f]];}if(l>h&&(_&N)!==A){for(p===0&&(p=h),v+=d,g=l-p,m=1<<g;g+p<u&&(m-=T[g+p],!(m<=0));)g++,m<<=1;if(b+=1<<g,n===Ji&&b>Or||n===Rr&&b>Lr)return 1;A=_&N,s[A]=h<<24|g<<16|v-r|0;}}return _!==0&&(s[v+_]=l-p<<24|64<<16|0),a.bits=h,0},Wt=Sc,kc=0,Oo=1,Lo=2,{Z_FINISH:$r,Z_BLOCK:vc,Z_TREES:Qn,Z_OK:Qe,Z_STREAM_END:Ac,Z_NEED_DICT:Ec,Z_STREAM_ERROR:ne,Z_DATA_ERROR:Co,Z_MEM_ERROR:Ro,Z_BUF_ERROR:Nc,Z_DEFLATED:Br}=bt,ai=16180,Dr=16181,Mr=16182,Ur=16183,Pr=16184,zr=16185,Kr=16186,Fr=16187,jr=16188,qr=16189,si=16190,Te=16191,Qi=16192,Vr=16193,Xi=16194,Zr=16195,Hr=16196,Yr=16197,Gr=16198,Xn=16199,ei=16200,Wr=16201,Jr=16202,Qr=16203,Xr=16204,eo=16205,es=16206,to=16207,no=16208,U=16209,$o=16210,Bo=16211,xc=852,Tc=592,Ic=15,Oc=Ic,io=n=>(n>>>24&255)+(n>>>8&65280)+((n&65280)<<8)+((n&255)<<24);function Lc(){this.strm=null,this.mode=0,this.last=false,this.wrap=0,this.havedict=false,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0;}var Xe=n=>{if(!n)return 1;let t=n.state;return !t||t.strm!==n||t.mode<ai||t.mode>Bo?1:0},Do=n=>{if(Xe(n))return ne;let t=n.state;return n.total_in=n.total_out=t.total=0,n.msg="",t.wrap&&(n.adler=t.wrap&1),t.mode=ai,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(xc),t.distcode=t.distdyn=new Int32Array(Tc),t.sane=1,t.back=-1,Qe},Mo=n=>{if(Xe(n))return ne;let t=n.state;return t.wsize=0,t.whave=0,t.wnext=0,Do(n)},Uo=(n,t)=>{let e;if(Xe(n))return ne;let i=n.state;return t<0?(e=0,t=-t):(e=(t>>4)+5,t<48&&(t&=15)),t&&(t<8||t>15)?ne:(i.window!==null&&i.wbits!==t&&(i.window=null),i.wrap=e,i.wbits=t,Mo(n))},Po=(n,t)=>{if(!n)return ne;let e=new Lc;n.state=e,e.strm=n,e.window=null,e.mode=ai;let i=Uo(n,t);return i!==Qe&&(n.state=null),i},Cc=n=>Po(n,Oc),so=true,ts,ns,Rc=n=>{if(so){ts=new Int32Array(512),ns=new Int32Array(32);let t=0;for(;t<144;)n.lens[t++]=8;for(;t<256;)n.lens[t++]=9;for(;t<280;)n.lens[t++]=7;for(;t<288;)n.lens[t++]=8;for(Wt(Oo,n.lens,0,288,ts,0,n.work,{bits:9}),t=0;t<32;)n.lens[t++]=5;Wt(Lo,n.lens,0,32,ns,0,n.work,{bits:5}),so=false;}n.lencode=ts,n.lenbits=9,n.distcode=ns,n.distbits=5;},zo=(n,t,e,i)=>{let s,r=n.state;return r.window===null&&(r.wsize=1<<r.wbits,r.wnext=0,r.whave=0,r.window=new Uint8Array(r.wsize)),i>=r.wsize?(r.window.set(t.subarray(e-r.wsize,e),0),r.wnext=0,r.whave=r.wsize):(s=r.wsize-r.wnext,s>i&&(s=i),r.window.set(t.subarray(e-i,e-i+s),r.wnext),i-=s,i?(r.window.set(t.subarray(e-i,e),0),r.wnext=i,r.whave=r.wsize):(r.wnext+=s,r.wnext===r.wsize&&(r.wnext=0),r.whave<r.wsize&&(r.whave+=s))),0},$c=(n,t)=>{let e,i,s,r,o,a,c,l,f,d,u,h,g,p,m=0,b,_,S,y,A,N,v,w,x=new Uint8Array(4),T,I,M=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Xe(n)||!n.output||!n.input&&n.avail_in!==0)return ne;e=n.state,e.mode===Te&&(e.mode=Qi),o=n.next_out,s=n.output,c=n.avail_out,r=n.next_in,i=n.input,a=n.avail_in,l=e.hold,f=e.bits,d=a,u=c,w=Qe;e:for(;;)switch(e.mode){case ai:if(e.wrap===0){e.mode=Qi;break}for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.wrap&2&&l===35615){e.wbits===0&&(e.wbits=15),e.check=0,x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0),l=0,f=0,e.mode=Dr;break}if(e.head&&(e.head.done=false),!(e.wrap&1)||(((l&255)<<8)+(l>>8))%31){n.msg="incorrect header check",e.mode=U;break}if((l&15)!==Br){n.msg="unknown compression method",e.mode=U;break}if(l>>>=4,f-=4,v=(l&15)+8,e.wbits===0&&(e.wbits=v),v>15||v>e.wbits){n.msg="invalid window size",e.mode=U;break}e.dmax=1<<e.wbits,e.flags=0,n.adler=e.check=1,e.mode=l&512?qr:Te,l=0,f=0;break;case Dr:for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.flags=l,(e.flags&255)!==Br){n.msg="unknown compression method",e.mode=U;break}if(e.flags&57344){n.msg="unknown header flags set",e.mode=U;break}e.head&&(e.head.text=l>>8&1),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0)),l=0,f=0,e.mode=Mr;case Mr:for(;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.head&&(e.head.time=l),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,x[2]=l>>>16&255,x[3]=l>>>24&255,e.check=F(e.check,x,4,0)),l=0,f=0,e.mode=Ur;case Ur:for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.head&&(e.head.xflags=l&255,e.head.os=l>>8),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0)),l=0,f=0,e.mode=Pr;case Pr:if(e.flags&1024){for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.length=l,e.head&&(e.head.extra_len=l),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0)),l=0,f=0;}else e.head&&(e.head.extra=null);e.mode=zr;case zr:if(e.flags&1024&&(h=e.length,h>a&&(h=a),h&&(e.head&&(v=e.head.extra_len-e.length,e.head.extra||(e.head.extra=new Uint8Array(e.head.extra_len)),e.head.extra.set(i.subarray(r,r+h),v)),e.flags&512&&e.wrap&4&&(e.check=F(e.check,i,h,r)),a-=h,r+=h,e.length-=h),e.length))break e;e.length=0,e.mode=Kr;case Kr:if(e.flags&2048){if(a===0)break e;h=0;do v=i[r+h++],e.head&&v&&e.length<65536&&(e.head.name+=String.fromCharCode(v));while(v&&h<a);if(e.flags&512&&e.wrap&4&&(e.check=F(e.check,i,h,r)),a-=h,r+=h,v)break e}else e.head&&(e.head.name=null);e.length=0,e.mode=Fr;case Fr:if(e.flags&4096){if(a===0)break e;h=0;do v=i[r+h++],e.head&&v&&e.length<65536&&(e.head.comment+=String.fromCharCode(v));while(v&&h<a);if(e.flags&512&&e.wrap&4&&(e.check=F(e.check,i,h,r)),a-=h,r+=h,v)break e}else e.head&&(e.head.comment=null);e.mode=jr;case jr:if(e.flags&512){for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.wrap&4&&l!==(e.check&65535)){n.msg="header crc mismatch",e.mode=U;break}l=0,f=0;}e.head&&(e.head.hcrc=e.flags>>9&1,e.head.done=true),n.adler=e.check=0,e.mode=Te;break;case qr:for(;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}n.adler=e.check=io(l),l=0,f=0,e.mode=si;case si:if(e.havedict===0)return n.next_out=o,n.avail_out=c,n.next_in=r,n.avail_in=a,e.hold=l,e.bits=f,Ec;n.adler=e.check=1,e.mode=Te;case Te:if(t===vc||t===Qn)break e;case Qi:if(e.last){l>>>=f&7,f-=f&7,e.mode=es;break}for(;f<3;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}switch(e.last=l&1,l>>>=1,f-=1,l&3){case 0:e.mode=Vr;break;case 1:if(Rc(e),e.mode=Xn,t===Qn){l>>>=2,f-=2;break e}break;case 2:e.mode=Hr;break;case 3:n.msg="invalid block type",e.mode=U;}l>>>=2,f-=2;break;case Vr:for(l>>>=f&7,f-=f&7;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if((l&65535)!==(l>>>16^65535)){n.msg="invalid stored block lengths",e.mode=U;break}if(e.length=l&65535,l=0,f=0,e.mode=Xi,t===Qn)break e;case Xi:e.mode=Zr;case Zr:if(h=e.length,h){if(h>a&&(h=a),h>c&&(h=c),h===0)break e;s.set(i.subarray(r,r+h),o),a-=h,r+=h,c-=h,o+=h,e.length-=h;break}e.mode=Te;break;case Hr:for(;f<14;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.nlen=(l&31)+257,l>>>=5,f-=5,e.ndist=(l&31)+1,l>>>=5,f-=5,e.ncode=(l&15)+4,l>>>=4,f-=4,e.nlen>286||e.ndist>30){n.msg="too many length or distance symbols",e.mode=U;break}e.have=0,e.mode=Yr;case Yr:for(;e.have<e.ncode;){for(;f<3;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.lens[M[e.have++]]=l&7,l>>>=3,f-=3;}for(;e.have<19;)e.lens[M[e.have++]]=0;if(e.lencode=e.lendyn,e.lenbits=7,T={bits:e.lenbits},w=Wt(kc,e.lens,0,19,e.lencode,0,e.work,T),e.lenbits=T.bits,w){n.msg="invalid code lengths set",e.mode=U;break}e.have=0,e.mode=Gr;case Gr:for(;e.have<e.nlen+e.ndist;){for(;m=e.lencode[l&(1<<e.lenbits)-1],b=m>>>24,_=m>>>16&255,S=m&65535,!(b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(S<16)l>>>=b,f-=b,e.lens[e.have++]=S;else {if(S===16){for(I=b+2;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(l>>>=b,f-=b,e.have===0){n.msg="invalid bit length repeat",e.mode=U;break}v=e.lens[e.have-1],h=3+(l&3),l>>>=2,f-=2;}else if(S===17){for(I=b+3;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=b,f-=b,v=0,h=3+(l&7),l>>>=3,f-=3;}else {for(I=b+7;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=b,f-=b,v=0,h=11+(l&127),l>>>=7,f-=7;}if(e.have+h>e.nlen+e.ndist){n.msg="invalid bit length repeat",e.mode=U;break}for(;h--;)e.lens[e.have++]=v;}}if(e.mode===U)break;if(e.lens[256]===0){n.msg="invalid code -- missing end-of-block",e.mode=U;break}if(e.lenbits=9,T={bits:e.lenbits},w=Wt(Oo,e.lens,0,e.nlen,e.lencode,0,e.work,T),e.lenbits=T.bits,w){n.msg="invalid literal/lengths set",e.mode=U;break}if(e.distbits=6,e.distcode=e.distdyn,T={bits:e.distbits},w=Wt(Lo,e.lens,e.nlen,e.ndist,e.distcode,0,e.work,T),e.distbits=T.bits,w){n.msg="invalid distances set",e.mode=U;break}if(e.mode=Xn,t===Qn)break e;case Xn:e.mode=ei;case ei:if(a>=6&&c>=258){n.next_out=o,n.avail_out=c,n.next_in=r,n.avail_in=a,e.hold=l,e.bits=f,gc(n,u),o=n.next_out,s=n.output,c=n.avail_out,r=n.next_in,i=n.input,a=n.avail_in,l=e.hold,f=e.bits,e.mode===Te&&(e.back=-1);break}for(e.back=0;m=e.lencode[l&(1<<e.lenbits)-1],b=m>>>24,_=m>>>16&255,S=m&65535,!(b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(_&&(_&240)===0){for(y=b,A=_,N=S;m=e.lencode[N+((l&(1<<y+A)-1)>>y)],b=m>>>24,_=m>>>16&255,S=m&65535,!(y+b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=y,f-=y,e.back+=y;}if(l>>>=b,f-=b,e.back+=b,e.length=S,_===0){e.mode=eo;break}if(_&32){e.back=-1,e.mode=Te;break}if(_&64){n.msg="invalid literal/length code",e.mode=U;break}e.extra=_&15,e.mode=Wr;case Wr:if(e.extra){for(I=e.extra;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.length+=l&(1<<e.extra)-1,l>>>=e.extra,f-=e.extra,e.back+=e.extra;}e.was=e.length,e.mode=Jr;case Jr:for(;m=e.distcode[l&(1<<e.distbits)-1],b=m>>>24,_=m>>>16&255,S=m&65535,!(b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if((_&240)===0){for(y=b,A=_,N=S;m=e.distcode[N+((l&(1<<y+A)-1)>>y)],b=m>>>24,_=m>>>16&255,S=m&65535,!(y+b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=y,f-=y,e.back+=y;}if(l>>>=b,f-=b,e.back+=b,_&64){n.msg="invalid distance code",e.mode=U;break}e.offset=S,e.extra=_&15,e.mode=Qr;case Qr:if(e.extra){for(I=e.extra;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.offset+=l&(1<<e.extra)-1,l>>>=e.extra,f-=e.extra,e.back+=e.extra;}if(e.offset>e.dmax){n.msg="invalid distance too far back",e.mode=U;break}e.mode=Xr;case Xr:if(c===0)break e;if(h=u-c,e.offset>h){if(h=e.offset-h,h>e.whave&&e.sane){n.msg="invalid distance too far back",e.mode=U;break}h>e.wnext?(h-=e.wnext,g=e.wsize-h):g=e.wnext-h,h>e.length&&(h=e.length),p=e.window;}else p=s,g=o-e.offset,h=e.length;h>c&&(h=c),c-=h,e.length-=h;do s[o++]=p[g++];while(--h);e.length===0&&(e.mode=ei);break;case eo:if(c===0)break e;s[o++]=e.length,c--,e.mode=ei;break;case es:if(e.wrap){for(;f<32;){if(a===0)break e;a--,l|=i[r++]<<f,f+=8;}if(u-=c,n.total_out+=u,e.total+=u,e.wrap&4&&u&&(n.adler=e.check=e.flags?F(e.check,s,u,o-u):tn(e.check,s,u,o-u)),u=c,e.wrap&4&&(e.flags?l:io(l))!==e.check){n.msg="incorrect data check",e.mode=U;break}l=0,f=0;}e.mode=to;case to:if(e.wrap&&e.flags){for(;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.wrap&4&&l!==(e.total&4294967295)){n.msg="incorrect length check",e.mode=U;break}l=0,f=0;}e.mode=no;case no:w=Ac;break e;case U:w=Co;break e;case $o:return Ro;case Bo:default:return ne}return n.next_out=o,n.avail_out=c,n.next_in=r,n.avail_in=a,e.hold=l,e.bits=f,(e.wsize||u!==n.avail_out&&e.mode<U&&(e.mode<es||t!==$r))&&zo(n,n.output,n.next_out,u-n.avail_out),d-=n.avail_in,u-=n.avail_out,n.total_in+=d,n.total_out+=u,e.total+=u,e.wrap&4&&u&&(n.adler=e.check=e.flags?F(e.check,s,u,n.next_out-u):tn(e.check,s,u,n.next_out-u)),n.data_type=e.bits+(e.last?64:0)+(e.mode===Te?128:0)+(e.mode===Xn||e.mode===Xi?256:0),(d===0&&u===0||t===$r)&&w===Qe&&(w=Nc),w},Bc=n=>{if(Xe(n))return ne;let t=n.state;return t.window&&(t.window=null),n.state=null,Qe},Dc=(n,t)=>{if(Xe(n))return ne;let e=n.state;return (e.wrap&2)===0?ne:(e.head=t,t.done=false,Qe)},Mc=(n,t)=>{let e=t.length,i,s,r;return Xe(n)||(i=n.state,i.wrap!==0&&i.mode!==si)?ne:i.mode===si&&(s=1,s=tn(s,t,e,0),s!==i.check)?Co:(r=zo(n,t,e,e),r?(i.mode=$o,Ro):(i.havedict=1,Qe))},Uc=Mo,Pc=Uo,zc=Do,Kc=Cc,Fc=Po,jc=$c,qc=Bc,Vc=Dc,Zc=Mc,Hc="pako inflate (from Nodeca project)",Oe={inflateReset:Uc,inflateReset2:Pc,inflateResetKeep:zc,inflateInit:Kc,inflateInit2:Fc,inflate:jc,inflateEnd:qc,inflateGetHeader:Vc,inflateSetDictionary:Zc,inflateInfo:Hc};function Yc(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=false;}var Gc=Yc,Ko=Object.prototype.toString,{Z_NO_FLUSH:Wc,Z_FINISH:Jc,Z_OK:rn,Z_STREAM_END:is,Z_NEED_DICT:ss,Z_STREAM_ERROR:Qc,Z_DATA_ERROR:ro,Z_MEM_ERROR:Xc}=bt;function cn(n){this.options=oi.assign({chunkSize:1024*64,windowBits:15,to:""},n||{});let t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,t.windowBits===0&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(n&&n.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(t.windowBits&15)===0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=false,this.chunks=[],this.strm=new To,this.strm.avail_out=0;let e=Oe.inflateInit2(this.strm,t.windowBits);if(e!==rn)throw new Error(We[e]);if(this.header=new Gc,Oe.inflateGetHeader(this.strm,this.header),t.dictionary&&(typeof t.dictionary=="string"?t.dictionary=sn.string2buf(t.dictionary):Ko.call(t.dictionary)==="[object ArrayBuffer]"&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(e=Oe.inflateSetDictionary(this.strm,t.dictionary),e!==rn)))throw new Error(We[e])}cn.prototype.push=function(n,t){let e=this.strm,i=this.options.chunkSize,s=this.options.dictionary,r,o,a;if(this.ended)return false;for(t===~~t?o=t:o=t===true?Jc:Wc,Ko.call(n)==="[object ArrayBuffer]"?e.input=new Uint8Array(n):e.input=n,e.next_in=0,e.avail_in=e.input.length;;){for(e.avail_out===0&&(e.output=new Uint8Array(i),e.next_out=0,e.avail_out=i),r=Oe.inflate(e,o),r===ss&&s&&(r=Oe.inflateSetDictionary(e,s),r===rn?r=Oe.inflate(e,o):r===ro&&(r=ss));e.avail_in>0&&r===is&&e.state.wrap>0&&n[e.next_in]!==0;)Oe.inflateReset(e),r=Oe.inflate(e,o);switch(r){case Qc:case ro:case ss:case Xc:return this.onEnd(r),this.ended=true,false}if(a=e.avail_out,e.next_out&&(e.avail_out===0||r===is))if(this.options.to==="string"){let c=sn.utf8border(e.output,e.next_out),l=e.next_out-c,f=sn.buf2string(e.output,c);e.next_out=l,e.avail_out=i-l,l&&e.output.set(e.output.subarray(c,c+l),0),this.onData(f);}else this.onData(e.output.length===e.next_out?e.output:e.output.subarray(0,e.next_out));if(!(r===rn&&a===0)){if(r===is)return r=Oe.inflateEnd(this.strm),this.onEnd(r),this.ended=true,true;if(e.avail_in===0)break}}return true};cn.prototype.onData=function(n){this.chunks.push(n);};cn.prototype.onEnd=function(n){n===rn&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=oi.flattenChunks(this.chunks)),this.chunks=[],this.err=n,this.msg=this.strm.msg;};function _s(n,t){let e=new cn(t);if(e.push(n),e.err)throw e.msg||We[e.err];return e.result}var nf=_s,af={inflate:nf},{inflate:lf}=af;var Fo=lf;function jo(n,t){let e=typeof t=="string"?{algorithm:t}:t,i=e.algorithm;if(!i)throw new k("Process specification missing algorithm");switch(i){case "zlib":return cf(n);case "xor":return ff(n,e.key);case "rol":return uf(n,e.amount,e.group);case "ror":return hf(n,e.amount,e.group);case "bswap2":return li(n,2);case "bswap4":return li(n,4);case "bswap8":return li(n,8);case "bswap16":return li(n,16);default:throw new k(`Unknown process algorithm: ${i}. Supported: zlib, xor, rol, ror, bswap2, bswap4, bswap8, bswap16`)}}function cf(n){try{return Fo(n)}catch(t){throw new k(`Zlib decompression failed: ${t instanceof Error?t.message:String(t)}`)}}function ff(n,t){if(t===void 0)throw new k("XOR process requires a key parameter");let e=new Uint8Array(n.length),i=Array.isArray(t)?t:[t];if(i.length===0)throw new k("XOR key cannot be empty");for(let s=0;s<n.length;s++)e[s]=n[s]^i[s%i.length];return e}function uf(n,t,e){let i=t??1,s=e??1;if(i<0)throw new k("ROL amount must be non-negative");if(s<1)throw new k("ROL group size must be at least 1");if(n.length%s!==0)throw new k(`Data length ${n.length} is not aligned to group size ${s}`);let r=new Uint8Array(n.length);if(s===1){let c=i%8;for(let l=0;l<n.length;l++){let f=n[l];r[l]=(f<<c|f>>8-c)&255;}return r}let o=s*8,a=i%o;for(let c=0;c<n.length;c+=s){let l=[];for(let d=0;d<s;d++){let u=n[c+d];for(let h=7;h>=0;h--)l.push(u>>h&1);}let f=[...l.slice(a),...l.slice(0,a)];for(let d=0;d<s;d++){let u=0;for(let h=0;h<8;h++)u=u<<1|f[d*8+h];r[c+d]=u;}}return r}function hf(n,t,e){let i=t??1,s=e??1;if(i<0)throw new k("ROR amount must be non-negative");if(s<1)throw new k("ROR group size must be at least 1");if(n.length%s!==0)throw new k(`Data length ${n.length} is not aligned to group size ${s}`);let r=new Uint8Array(n.length);if(s===1){let c=i%8;for(let l=0;l<n.length;l++){let f=n[l];r[l]=(f>>c|f<<8-c)&255;}return r}let o=s*8,a=i%o;for(let c=0;c<n.length;c+=s){let l=[];for(let d=0;d<s;d++){let u=n[c+d];for(let h=7;h>=0;h--)l.push(u>>h&1);}let f=[...l.slice(o-a),...l.slice(0,o-a)];for(let d=0;d<s;d++){let u=0;for(let h=0;h<8;h++)u=u<<1|f[d*8+h];r[c+d]=u;}}return r}function li(n,t){if(![2,4,8,16].includes(t))throw new k(`Invalid byteswap group size: ${t}. Must be 2, 4, 8, or 16`);if(n.length%t!==0)throw new k(`Data length ${n.length} is not aligned to group size ${t}`);let e=new Uint8Array(n.length);for(let i=0;i<n.length;i+=t)for(let s=0;s<t;s++)e[i+s]=n[i+t-1-s];return e}var fn=class n{constructor(t,e){this.schema=t;this.parentMeta=e;if(!t.meta&&!e)throw new k("Schema must have meta section");if(t.meta&&!t.meta.id&&!e)throw new k("Root schema must have meta.id")}static getKaitaiIO(t){if(t&&typeof t=="object"){let i=t._io;if(i instanceof he)return i}return null}parse(t,e,i,s){let r={},o=s||r,a=new qt(t,o,e,this.schema.enums);a.current=r;let c=t.pos;if(r._io=t,s&&(r._root=s),i&&this.schema.params)for(let f=0;f<this.schema.params.length&&f<i.length;f++){let d=this.schema.params[f],u=i[f],h=typeof u=="string"?this.evaluateValue(u,a):u;a.set(d.id,h);}if(this.schema.instances&&this.setupInstances(r,t,a),this.schema.seq)for(let f of this.schema.seq){let d=this.parseAttribute(f,a);f.id&&(r[f.id]=d);}let l=t.pos;return r._sizeof=l-c,r}setupInstances(t,e,i){if(this.schema.instances)for(let[s,r]of Object.entries(this.schema.instances)){let o,a=false;Object.defineProperty(t,s,{get:()=>(a||(o=this.parseInstance(r,e,i),a=true),o),enumerable:true,configurable:true});}}parseInstance(t,e,i){if("value"in t)return this.evaluateValue(t.value,i);let s=e.pos;try{if(t.pos!==void 0){let o=this.evaluateValue(t.pos,i);if(typeof o=="number")e.seek(o);else if(typeof o=="bigint")e.seek(Number(o));else throw new k(`pos must evaluate to a number, got ${typeof o}`)}return this.parseAttribute(t,i)}finally{t.pos!==void 0&&e.seek(s);}}parseAttribute(t,e){let i=e.io;if(t.io!==void 0){let r=this.evaluateValue(t.io,e);if(r instanceof he)i=r;else {let o=n.getKaitaiIO(r);if(o)i=o;else throw new k("io must evaluate to a KaitaiStream or an object with _io")}}if(t.if&&!this.evaluateValue(t.if,e))return;if(t.pos!==void 0){let r=this.evaluateValue(t.pos,e);if(typeof r=="number")i.seek(r);else if(typeof r=="bigint")i.seek(Number(r));else throw new k(`pos must evaluate to a number, got ${typeof r}`)}return t.repeat?this.parseRepeated(t,e):t.contents?this.parseContents(t,e):this.parseValue(t,e)}parseRepeated(t,e){let i=e.io,s=[];switch(t.repeat){case "expr":{let r=this.evaluateValue(t["repeat-expr"],e),o=typeof r=="number"?r:typeof r=="bigint"?Number(r):0;if(o<0)throw new k(`repeat-expr must be non-negative, got ${o}`);for(let a=0;a<o;a++){e.set("_index",a);let c=this.parseAttribute({...t,repeat:void 0,"repeat-expr":void 0},e);s.push(c);}break}case "eos":{for(;!i.isEof();)e.set("_index",s.length),s.push(this.parseValue(t,e));break}case "until":{if(!t["repeat-until"])throw new k("repeat-until expression is required");let r=0;for(;;){e.set("_index",r);let o=this.parseAttribute({...t,repeat:void 0,"repeat-until":void 0},e);if(s.push(o),e.set("_",o),this.evaluateValue(t["repeat-until"],e)||i.isEof())break;r++;}break}default:throw new k(`Unknown repeat type: ${t.repeat}`)}return s}parseContents(t,e){let i=e.io,s=t.contents;if(Array.isArray(s)){let r=i.readBytes(s.length);for(let o=0;o<s.length;o++)if(r[o]!==s[o])throw new je(`Contents mismatch at byte ${o}: expected ${s[o]}, got ${r[o]}`,i.pos-s.length+o);return r}else {let r=t.encoding||this.schema.meta?.encoding||this.parentMeta?.encoding||"UTF-8",o=i.readStr(s.length,r);if(o!==s)throw new je(`Contents mismatch: expected "${s}", got "${o}"`,i.pos-s.length);return o}}parseValue(t,e){let i=e.io,s=t.type;if(t.size!==void 0){let r=this.evaluateValue(t.size,e),o=typeof r=="number"?r:typeof r=="bigint"?Number(r):0;if(o<0)throw new k(`size must be non-negative, got ${o}`);if(s==="str"||!s){let a=t.encoding||this.schema.meta?.encoding||this.parentMeta?.encoding||"UTF-8",c;return s==="str"?(c=i.readBytes(o),t.process&&(c=this.applyProcessing(c,t.process)),new TextDecoder(a).decode(c)):(c=i.readBytes(o),t.process&&(c=this.applyProcessing(c,t.process)),c)}else {let a=i.readBytes(o);t.process&&(a=this.applyProcessing(a,t.process));let c=new he(a);return this.parseType(s,c,e,t["type-args"])}}if(t["size-eos"])if(s==="str"){let r=t.encoding||this.schema.meta?.encoding||this.parentMeta?.encoding||"UTF-8",o=i.readBytesFull();return new TextDecoder(r).decode(o)}else {let r=i.readBytesFull();if(t.process&&(r=this.applyProcessing(r,t.process)),s){let o=new he(r);return this.parseType(s,o,e,t["type-args"])}return r}if(!s)throw new k("Attribute must have either type, size, or contents");return this.parseType(s,i,e,t["type-args"])}parseType(t,e,i,s){if(typeof t=="object")return this.parseSwitchType(t,e,i);let{typeName:r,args:o}=this.parseParameterizedType(t,i),a=o.length>0?o:s;if(fi(r))return this.parseBuiltinType(r,e,i);if(this.schema.types&&r in this.schema.types){let c=this.schema.types[r],l=this.schema.meta||this.parentMeta;return this.schema.enums&&!c.enums&&(c.enums=this.schema.enums),this.schema.types&&!c.types&&(c.types=this.schema.types),new n(c,l).parse(e,i.current,a,i.root)}throw new k(`Unknown type: ${r}`)}parseParameterizedType(t,e){let i=t.match(/^([a-z_][a-z0-9_]*)\((.*)\)$/i);if(!i)return {typeName:t,args:[]};let s=i[1],r=i[2].trim();if(!r)return {typeName:s,args:[]};let o=[],a="",c=false,l="",f=0;for(let d=0;d<r.length;d++){let u=r[d];c?(a+=u,u===l&&r[d-1]!=="\\"&&(c=false)):u==='"'||u==="'"?(c=true,l=u,a+=u):u==="("?(f++,a+=u):u===")"?(f--,a+=u):u===","&&f===0?(o.push(this.parseArgument(a.trim(),e)),a=""):a+=u;}return a.trim()&&o.push(this.parseArgument(a.trim(),e)),{typeName:s,args:o}}parseArgument(t,e){if(t==="true")return true;if(t==="false")return false;if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(/^-?\d+$/.test(t))return parseInt(t,10);if(/^-?\d+\.\d+$/.test(t))return parseFloat(t);if(/^0x[0-9a-f]+$/i.test(t))return parseInt(t,16);try{let i=this.evaluateValue(t,e);return typeof i=="string"||typeof i=="number"||typeof i=="boolean"?i:Number(i)}catch{return t}}parseSwitchType(t,e,i){let s=t["switch-on"],r=t.cases,o=t.default;if(!s||typeof s!="string")throw new k("switch-on expression is required for switch types");if(!r)throw new k("cases are required for switch types");let a=this.evaluateValue(s,i),c=String(a),l=r[c];if(l===void 0&&o&&(l=o),l===void 0)throw new k(`No matching case for switch value "${c}" and no default type specified`);return this.parseType(l,e,i)}parseBuiltinType(t,e,i){let s=vt(t),r=ui(t),a=(this.schema.meta||this.parentMeta)?.endian,c;if(r?c=r:typeof a=="string"?c=a:a&&typeof a=="object"?c=this.evaluateEndianExpression(a,i):c="le",hi(t))return this.readInteger(s,c,e);if(di(t))return this.readFloat(s,c,e);if(/^b\d+$/.test(t)){let l=parseInt(t.slice(1),10),f=e.readBitsIntBe(l),d=BigInt(Number.MAX_SAFE_INTEGER);return f<=d?Number(f):f}if(pi(t)){let l=this.schema.meta?.encoding||"UTF-8";if(t==="strz")return e.readStrz(l,0,false,true,true);if(t==="str")throw new k("str type requires size, size-eos, or terminator attribute")}throw new k(`Unknown built-in type: ${t}`)}readInteger(t,e,i){switch(t){case "u1":return i.readU1();case "u2":return e==="le"?i.readU2le():i.readU2be();case "u4":return e==="le"?i.readU4le():i.readU4be();case "u8":return e==="le"?i.readU8le():i.readU8be();case "s1":return i.readS1();case "s2":return e==="le"?i.readS2le():i.readS2be();case "s4":return e==="le"?i.readS4le():i.readS4be();case "s8":return e==="le"?i.readS8le():i.readS8be();default:throw new k(`Unknown integer type: ${t}`)}}readFloat(t,e,i){switch(t){case "f4":return e==="le"?i.readF4le():i.readF4be();case "f8":return e==="le"?i.readF8le():i.readF8be();default:throw new k(`Unknown float type: ${t}`)}}applyProcessing(t,e){return jo(t,e)}evaluateEndianExpression(t,e){let i=t["switch-on"],s=t.cases;if(!i||typeof i!="string")throw new k('Endian expression missing "switch-on" field');if(!s||typeof s!="object")throw new k('Endian expression missing "cases" field');let r=this.evaluateValue(i,e),o=String(r);if(o in s){let a=s[o];if(a!=="le"&&a!=="be")throw new k(`Invalid endianness value: ${a}`);return a}return "le"}evaluateValue(t,e){if(t!==void 0){if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="string")try{return Sr(t,e)}catch(i){throw new k(`Failed to evaluate expression "${t}": ${i instanceof Error?i.message:String(i)}`)}return t}}};function r0(n,t,e={}){let{validate:i=true,strict:s=false}=e,o=new jt().parse(n,{validate:i,strict:s}),a=new he(t);return new fn(o).parse(a)}/**
134
+ `:s==="t"?i+=" ":s==="r"?i+="\r":s==="\\"?i+="\\":s==='"'?i+='"':s==="'"?i+="'":i+=s;}else i+=this.current;this.advance();}if(this.current===null)throw new k("Unterminated string",t);return this.advance(),L("STRING",i,t)}readOperator(){let t=this.position,e=this.current;switch(e){case "+":return this.advance(),L("PLUS",e,t);case "-":return this.advance(),L("MINUS",e,t);case "*":return this.advance(),L("STAR",e,t);case "/":return this.advance(),L("SLASH",e,t);case "%":return this.advance(),L("PERCENT",e,t);case "<":return this.advance(),this.current==="="?(this.advance(),L("LE","<=",t)):this.current==="<"?(this.advance(),L("LSHIFT","<<",t)):L("LT","<",t);case ">":return this.advance(),this.current==="="?(this.advance(),L("GE",">=",t)):this.current===">"?(this.advance(),L("RSHIFT",">>",t)):L("GT",">",t);case "=":if(this.advance(),this.current==="=")return this.advance(),L("EQ","==",t);throw new k("Expected == for equality",t);case "!":if(this.advance(),this.current==="=")return this.advance(),L("NE","!=",t);throw new k("Expected != for inequality",t);case "&":return this.advance(),L("AMPERSAND",e,t);case "|":return this.advance(),L("PIPE",e,t);case "^":return this.advance(),L("CARET",e,t);case "?":return this.advance(),L("QUESTION",e,t);case ":":return this.advance(),this.current===":"?(this.advance(),L("DOUBLE_COLON","::",t)):L("COLON",e,t);case "(":return this.advance(),L("LPAREN",e,t);case ")":return this.advance(),L("RPAREN",e,t);case "[":return this.advance(),L("LBRACKET",e,t);case "]":return this.advance(),L("RBRACKET",e,t);case ".":return this.advance(),L("DOT",e,t);case ",":return this.advance(),L("COMMA",e,t);default:return null}}};function hr(n){return {kind:"Literal",value:n}}function dr(n){return {kind:"Identifier",name:n}}function ue(n,t,e){return {kind:"BinaryOp",operator:n,left:t,right:e}}function pr(n,t){return {kind:"UnaryOp",operator:n,operand:t}}function mr(n,t,e){return {kind:"Ternary",condition:n,ifTrue:t,ifFalse:e}}function gr(n,t){return {kind:"MemberAccess",object:n,property:t}}function yr(n,t){return {kind:"IndexAccess",object:n,index:t}}function br(n,t,e){return {kind:"MethodCall",object:n,method:t,args:e}}function wr(n,t){return {kind:"EnumAccess",enumName:n,value:t}}function _r(n){return {kind:"ArrayLiteral",elements:n}}var Yn=class{constructor(t){this.position=0;this.tokens=t;}parse(){let t=this.parseTernary();if(!this.isAtEnd())throw new k(`Unexpected token: ${this.current().type}`,this.current().position);return t}current(){return this.tokens[this.position]}isAtEnd(){return this.current().type==="EOF"}advance(){return this.isAtEnd()||this.position++,this.tokens[this.position-1]}match(...t){for(let e of t)if(this.current().type===e)return this.advance(),true;return false}expect(t,e){if(this.current().type!==t)throw new k(e,this.current().position);return this.advance()}parseTernary(){let t=this.parseLogicalOr();if(this.match("QUESTION")){let e=this.parseTernary();this.expect("COLON","Expected : in ternary expression");let i=this.parseTernary();return mr(t,e,i)}return t}parseLogicalOr(){let t=this.parseLogicalAnd();for(;this.match("OR");){let i=this.parseLogicalAnd();t=ue("or",t,i);}return t}parseLogicalAnd(){let t=this.parseBitwiseOr();for(;this.match("AND");){let i=this.parseBitwiseOr();t=ue("and",t,i);}return t}parseBitwiseOr(){let t=this.parseBitwiseXor();for(;this.match("PIPE");){let i=this.parseBitwiseXor();t=ue("|",t,i);}return t}parseBitwiseXor(){let t=this.parseBitwiseAnd();for(;this.match("CARET");){let i=this.parseBitwiseAnd();t=ue("^",t,i);}return t}parseBitwiseAnd(){let t=this.parseEquality();for(;this.match("AMPERSAND");){let i=this.parseEquality();t=ue("&",t,i);}return t}parseEquality(){let t=this.parseRelational();for(;this.match("EQ","NE");){let e=this.tokens[this.position-1].value,i=this.parseRelational();t=ue(e,t,i);}return t}parseRelational(){let t=this.parseBitShift();for(;this.match("LT","LE","GT","GE");){let e=this.tokens[this.position-1].value,i=this.parseBitShift();t=ue(e,t,i);}return t}parseBitShift(){let t=this.parseAdditive();for(;this.match("LSHIFT","RSHIFT");){let e=this.tokens[this.position-1].value,i=this.parseAdditive();t=ue(e,t,i);}return t}parseAdditive(){let t=this.parseMultiplicative();for(;this.match("PLUS","MINUS");){let e=this.tokens[this.position-1].value,i=this.parseMultiplicative();t=ue(e,t,i);}return t}parseMultiplicative(){let t=this.parseUnary();for(;this.match("STAR","SLASH","PERCENT");){let e=this.tokens[this.position-1].value,i=this.parseUnary();t=ue(e,t,i);}return t}parseUnary(){if(this.match("MINUS","NOT")){let t=this.tokens[this.position-1].value,e=this.parseUnary();return pr(t,e)}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary();for(;;)if(this.match("DOT")){let e=this.expect("IDENTIFIER","Expected property name after .");t=gr(t,e.value);}else if(this.match("LBRACKET")){let e=this.parseTernary();this.expect("RBRACKET","Expected ] after array index"),t=yr(t,e);}else if(this.current().type==="LPAREN")if(t.kind==="MemberAccess"){this.advance();let e=[];if(this.current().type!=="RPAREN")for(e.push(this.parseTernary());this.match("COMMA");)e.push(this.parseTernary());this.expect("RPAREN","Expected ) after arguments");let i=t;t=br(i.object,i.property,e);}else break;else break;return t}parsePrimary(){if(this.match("NUMBER","STRING","BOOLEAN")){let t=this.tokens[this.position-1];return hr(t.value)}if(this.match("IDENTIFIER")){let t=this.tokens[this.position-1].value;if(this.match("DOUBLE_COLON")){let e=this.expect("IDENTIFIER","Expected enum value after ::");return wr(t,e.value)}return dr(t)}if(this.match("LPAREN")){let t=this.parseTernary();return this.expect("RPAREN","Expected ) after expression"),t}if(this.match("LBRACKET")){let t=[];if(this.current().type!=="RBRACKET")for(t.push(this.parseTernary());this.match("COMMA");)t.push(this.parseTernary());return this.expect("RBRACKET","Expected ] after array literal"),_r(t)}throw new k(`Unexpected token: ${this.current().type}`,this.current().position)}};var Gn=class{evaluate(t,e){let i=t;switch(t.kind){case "Literal":return i.value;case "Identifier":return this.evaluateIdentifier(i.name,e);case "BinaryOp":return this.evaluateBinaryOp(i.operator,i.left,i.right,e);case "UnaryOp":return this.evaluateUnaryOp(i.operator,i.operand,e);case "Ternary":return this.evaluateTernary(i.condition,i.ifTrue,i.ifFalse,e);case "MemberAccess":return this.evaluateMemberAccess(i.object,i.property,e);case "IndexAccess":return this.evaluateIndexAccess(i.object,i.index,e);case "MethodCall":return this.evaluateMethodCall(i.object,i.method,i.args,e);case "EnumAccess":return this.evaluateEnumAccess(i.enumName,i.value,e);case "ArrayLiteral":return this.evaluateArrayLiteral(i.elements,e);default:throw new k(`Unknown AST node kind: ${t.kind}`)}}evaluateIdentifier(t,e){return e.resolve(t)}evaluateBinaryOp(t,e,i,s){let r=this.evaluate(e,s),o=this.evaluate(i,s);switch(t){case "+":return this.add(r,o);case "-":return this.toNumber(r)-this.toNumber(o);case "*":return this.toNumber(r)*this.toNumber(o);case "/":return this.toNumber(r)/this.toNumber(o);case "%":return this.modulo(this.toNumber(r),this.toNumber(o));case "<":return this.compare(r,o)<0;case "<=":return this.compare(r,o)<=0;case ">":return this.compare(r,o)>0;case ">=":return this.compare(r,o)>=0;case "==":return this.equals(r,o);case "!=":return !this.equals(r,o);case "<<":return this.bitwiseOp(r,o,(a,c)=>a<<c);case ">>":return this.bitwiseOp(r,o,(a,c)=>a>>c);case "&":return this.bitwiseOp(r,o,(a,c)=>a&c);case "|":return this.bitwiseOp(r,o,(a,c)=>a|c);case "^":return this.bitwiseOp(r,o,(a,c)=>a^c);case "and":return this.toBoolean(r)&&this.toBoolean(o);case "or":return this.toBoolean(r)||this.toBoolean(o);default:throw new k(`Unknown binary operator: ${t}`)}}evaluateUnaryOp(t,e,i){let s=this.evaluate(e,i);switch(t){case "-":return -this.toNumber(s);case "not":return !this.toBoolean(s);default:throw new k(`Unknown unary operator: ${t}`)}}evaluateTernary(t,e,i,s){let r=this.evaluate(t,s);return this.toBoolean(r)?this.evaluate(e,s):this.evaluate(i,s)}evaluateMemberAccess(t,e,i){let s=this.evaluate(t,i);if(s==null)throw new k(`Cannot access property ${e} of null/undefined`);if(e==="to_i")return typeof s=="number"?Math.floor(s):typeof s=="bigint"?Number(s):typeof s=="string"?parseInt(s,10):typeof s=="boolean"?s?1:0:this.toInt(s);if(e==="to_s")return String(s);if(typeof s=="object")return s[e];throw new k(`Cannot access property ${e} of non-object`)}evaluateIndexAccess(t,e,i){let s=this.evaluate(t,i),r=this.evaluate(e,i);if(Array.isArray(s)){let o=this.toInt(r);return s[o]}if(s instanceof Uint8Array){let o=this.toInt(r);return s[o]}throw new k("Index access requires an array")}evaluateMethodCall(t,e,i,s){let r=this.evaluate(t,s),o=i.map(a=>this.evaluate(a,s));if(e==="length"||e==="size"){if(Array.isArray(r)||r instanceof Uint8Array||typeof r=="string")return r.length;throw new k(`Object does not have a ${e} property`)}if(e==="to_i"){let a=o.length>0?this.toInt(o[0]):10;return typeof r=="string"?parseInt(r,a):this.toInt(r)}if(e==="to_s")return String(r);if(typeof r=="string")return this.evaluateStringMethod(r,e,o);if(Array.isArray(r)||r instanceof Uint8Array)return this.evaluateArrayMethod(r,e,o);throw new k(`Unknown method: ${e}`)}evaluateStringMethod(t,e,i){switch(e){case "substring":{let s=i.length>0?this.toInt(i[0]):0,r=i.length>1?this.toInt(i[1]):void 0;return t.substring(s,r)}case "substr":{let s=i.length>0?this.toInt(i[0]):0,r=i.length>1?this.toInt(i[1]):void 0;return t.substr(s,r)}case "reverse":return t.split("").reverse().join("");case "to_i":{let s=i.length>0?this.toInt(i[0]):10;return parseInt(t,s)}case "length":case "size":return t.length;case "upcase":case "to_upper":return t.toUpperCase();case "downcase":case "to_lower":return t.toLowerCase();case "capitalize":return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase();case "strip":case "trim":return t.trim();case "lstrip":case "trim_start":return t.trimStart();case "rstrip":case "trim_end":return t.trimEnd();case "starts_with":case "startsWith":{if(i.length===0)throw new k("starts_with requires 1 argument");return t.startsWith(String(i[0]))}case "ends_with":case "endsWith":{if(i.length===0)throw new k("ends_with requires 1 argument");return t.endsWith(String(i[0]))}case "includes":case "contains":{if(i.length===0)throw new k("includes requires 1 argument");return t.includes(String(i[0]))}case "index_of":case "indexOf":{if(i.length===0)throw new k("index_of requires 1 argument");return t.indexOf(String(i[0]))}case "split":{if(i.length===0)throw new k("split requires 1 argument");return t.split(String(i[0]))}case "replace":{if(i.length<2)throw new k("replace requires 2 arguments");return t.replace(String(i[0]),String(i[1]))}case "replace_all":case "replaceAll":{if(i.length<2)throw new k("replace_all requires 2 arguments");let s=String(i[0]),r=String(i[1]);return t.split(s).join(r)}case "pad_left":case "padStart":{if(i.length===0)throw new k("pad_left requires at least 1 argument");let s=this.toInt(i[0]),r=i.length>1?String(i[1]):" ";return t.padStart(s,r)}case "pad_right":case "padEnd":{if(i.length===0)throw new k("pad_right requires at least 1 argument");let s=this.toInt(i[0]),r=i.length>1?String(i[1]):" ";return t.padEnd(s,r)}default:throw new k(`Unknown string method: ${e}`)}}evaluateArrayMethod(t,e,i){let s=Array.isArray(t)?t:Array.from(t);switch(e){case "length":case "size":return s.length;case "first":return s[0];case "last":return s[s.length-1];case "min":return Math.min(...s.map(r=>this.toNumber(r)));case "max":return Math.max(...s.map(r=>this.toNumber(r)));case "reverse":return [...s].reverse();case "sort":return [...s].sort((r,o)=>this.compare(r,o));case "includes":case "contains":{if(i.length===0)throw new k("includes requires 1 argument");return s.some(r=>this.equals(r,i[0]))}case "index_of":case "indexOf":{if(i.length===0)throw new k("index_of requires 1 argument");return s.findIndex(r=>this.equals(r,i[0]))}case "slice":{let r=i.length>0?this.toInt(i[0]):0,o=i.length>1?this.toInt(i[1]):void 0;return s.slice(r,o)}default:throw new k(`Unknown array method: ${e}`)}}evaluateEnumAccess(t,e,i){let s=i.getEnumValue(t,e);if(s===void 0)throw new k(`Enum value "${t}::${e}" not found`);return s}add(t,e){return typeof t=="string"||typeof e=="string"?String(t)+String(e):this.toNumber(t)+this.toNumber(e)}modulo(t,e){let i=t%e;return i<0?i+e:i}bitwiseOp(t,e,i){if(typeof t=="bigint"||typeof e=="bigint"){let s=typeof t=="bigint"?t:BigInt(t),r=typeof e=="bigint"?e:BigInt(e);if(i.toString().includes("<<"))return s<<BigInt(Number(r));if(i.toString().includes(">>"))return s>>BigInt(Number(r));if(i.toString().includes("&"))return s&r;if(i.toString().includes("|"))return s|r;if(i.toString().includes("^"))return s^r}if(t==null||e===void 0||e===null)throw new k("Cannot perform bitwise operation on null/undefined");return i(this.toInt(t),this.toInt(e))}compare(t,e){if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;let i=this.toNumber(t),s=this.toNumber(e);return i<s?-1:i>s?1:0}equals(t,e){if(typeof t=="bigint"||typeof e=="bigint")return BigInt(t)===BigInt(e);let i=o=>Array.isArray(o)?o.map(a=>typeof a=="bigint"?Number(a):a):o instanceof Uint8Array?Array.from(o):null,s=i(t),r=i(e);if(s&&r){if(s.length!==r.length)return false;for(let o=0;o<s.length;o++)if(s[o]!==r[o])return false;return true}return t===e}evaluateArrayLiteral(t,e){return t.map(i=>this.evaluate(i,e))}toNumber(t){if(typeof t=="number")return t;if(typeof t=="bigint")return Number(t);if(typeof t=="boolean")return t?1:0;if(typeof t=="string")return parseFloat(t);throw new k(`Cannot convert ${typeof t} to number`)}toInt(t){return Math.floor(this.toNumber(t))}toBoolean(t){return typeof t=="boolean"?t:typeof t=="number"?t!==0:typeof t=="bigint"?t!==0n:typeof t=="string"?t.length>0:t!=null}};function Sr(n,t){let e=n.replace(/\.as<[^>]+>/g,""),s=new Hn(e).tokenize(),o=new Yn(s).parse();return new Gn().evaluate(o,t)}function yt(n){let t=n.length;for(;--t>=0;)n[t]=0;}var La=3,Ca=258,ps=29,on=256,Jt=on+1+ps,pt=30,Ba=512,Ie=new Array((Jt+2)*2);yt(Ie);var Yt=new Array(pt*2);yt(Yt);var Qt=new Array(Ba);yt(Qt);var Xt=new Array(Ca-La+1);yt(Xt);var ys=new Array(ps);yt(ys);var ni=new Array(pt);yt(ni);var Qa=(n,t,e,i)=>{let s=n&65535|0,r=n>>>16&65535|0,o=0;for(;e!==0;){o=e>2e3?2e3:e,e-=o;do s=s+t[i++]|0,r=r+s|0;while(--o);s%=65521,r%=65521;}return s|r<<16|0},tn=Qa,Xa=()=>{let n,t=[];for(var e=0;e<256;e++){n=e;for(var i=0;i<8;i++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n;}return t},el=new Uint32Array(Xa()),tl=(n,t,e,i)=>{let s=el,r=i+e;n^=-1;for(let o=i;o<r;o++)n=n>>>8^s[(n^t[o])&255];return n^-1},F=tl,We={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},bt={Z_NO_FLUSH:0,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_DEFLATED:8};var Vl=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Zl=function(n){let t=Array.prototype.slice.call(arguments,1);for(;t.length;){let e=t.shift();if(e){if(typeof e!="object")throw new TypeError(e+"must be non-object");for(let i in e)Vl(e,i)&&(n[i]=e[i]);}}return n},Hl=n=>{let t=0;for(let i=0,s=n.length;i<s;i++)t+=n[i].length;let e=new Uint8Array(t);for(let i=0,s=0,r=n.length;i<r;i++){let o=n[i];e.set(o,s),s+=o.length;}return e},oi={assign:Zl,flattenChunks:Hl},xo=true;try{String.fromCharCode.apply(null,new Uint8Array(1));}catch{xo=false;}var nn=new Uint8Array(256);for(let n=0;n<256;n++)nn[n]=n>=252?6:n>=248?5:n>=240?4:n>=224?3:n>=192?2:1;nn[254]=nn[254]=1;var Yl=n=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(n);let t,e,i,s,r,o=n.length,a=0;for(s=0;s<o;s++)e=n.charCodeAt(s),(e&64512)===55296&&s+1<o&&(i=n.charCodeAt(s+1),(i&64512)===56320&&(e=65536+(e-55296<<10)+(i-56320),s++)),a+=e<128?1:e<2048?2:e<65536?3:4;for(t=new Uint8Array(a),r=0,s=0;r<a;s++)e=n.charCodeAt(s),(e&64512)===55296&&s+1<o&&(i=n.charCodeAt(s+1),(i&64512)===56320&&(e=65536+(e-55296<<10)+(i-56320),s++)),e<128?t[r++]=e:e<2048?(t[r++]=192|e>>>6,t[r++]=128|e&63):e<65536?(t[r++]=224|e>>>12,t[r++]=128|e>>>6&63,t[r++]=128|e&63):(t[r++]=240|e>>>18,t[r++]=128|e>>>12&63,t[r++]=128|e>>>6&63,t[r++]=128|e&63);return t},Gl=(n,t)=>{if(t<65534&&n.subarray&&xo)return String.fromCharCode.apply(null,n.length===t?n:n.subarray(0,t));let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(n[i]);return e},Wl=(n,t)=>{let e=t||n.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(n.subarray(0,t));let i,s,r=new Array(e*2);for(s=0,i=0;i<e;){let o=n[i++];if(o<128){r[s++]=o;continue}let a=nn[o];if(a>4){r[s++]=65533,i+=a-1;continue}for(o&=a===2?31:a===3?15:7;a>1&&i<e;)o=o<<6|n[i++]&63,a--;if(a>1){r[s++]=65533;continue}o<65536?r[s++]=o:(o-=65536,r[s++]=55296|o>>10&1023,r[s++]=56320|o&1023);}return Gl(r,s)},Jl=(n,t)=>{t=t||n.length,t>n.length&&(t=n.length);let e=t-1;for(;e>=0&&(n[e]&192)===128;)e--;return e<0||e===0?t:e+nn[n[e]]>t?e:t},sn={string2buf:Yl,buf2string:Wl,utf8border:Jl};function Ql(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0;}var To=Ql;var Jn=16209,mc=16191,gc=function(t,e){let i,s,r,o,a,c,l,f,d,u,h,g,p,m,b,_,S,y,A,N,v,w,x,T,I=t.state;i=t.next_in,x=t.input,s=i+(t.avail_in-5),r=t.next_out,T=t.output,o=r-(e-t.avail_out),a=r+(t.avail_out-257),c=I.dmax,l=I.wsize,f=I.whave,d=I.wnext,u=I.window,h=I.hold,g=I.bits,p=I.lencode,m=I.distcode,b=(1<<I.lenbits)-1,_=(1<<I.distbits)-1;e:do{g<15&&(h+=x[i++]<<g,g+=8,h+=x[i++]<<g,g+=8),S=p[h&b];t:for(;;){if(y=S>>>24,h>>>=y,g-=y,y=S>>>16&255,y===0)T[r++]=S&65535;else if(y&16){A=S&65535,y&=15,y&&(g<y&&(h+=x[i++]<<g,g+=8),A+=h&(1<<y)-1,h>>>=y,g-=y),g<15&&(h+=x[i++]<<g,g+=8,h+=x[i++]<<g,g+=8),S=m[h&_];n:for(;;){if(y=S>>>24,h>>>=y,g-=y,y=S>>>16&255,y&16){if(N=S&65535,y&=15,g<y&&(h+=x[i++]<<g,g+=8,g<y&&(h+=x[i++]<<g,g+=8)),N+=h&(1<<y)-1,N>c){t.msg="invalid distance too far back",I.mode=Jn;break e}if(h>>>=y,g-=y,y=r-o,N>y){if(y=N-y,y>f&&I.sane){t.msg="invalid distance too far back",I.mode=Jn;break e}if(v=0,w=u,d===0){if(v+=l-y,y<A){A-=y;do T[r++]=u[v++];while(--y);v=r-N,w=T;}}else if(d<y){if(v+=l+d-y,y-=d,y<A){A-=y;do T[r++]=u[v++];while(--y);if(v=0,d<A){y=d,A-=y;do T[r++]=u[v++];while(--y);v=r-N,w=T;}}}else if(v+=d-y,y<A){A-=y;do T[r++]=u[v++];while(--y);v=r-N,w=T;}for(;A>2;)T[r++]=w[v++],T[r++]=w[v++],T[r++]=w[v++],A-=3;A&&(T[r++]=w[v++],A>1&&(T[r++]=w[v++]));}else {v=r-N;do T[r++]=T[v++],T[r++]=T[v++],T[r++]=T[v++],A-=3;while(A>2);A&&(T[r++]=T[v++],A>1&&(T[r++]=T[v++]));}}else if((y&64)===0){S=m[(S&65535)+(h&(1<<y)-1)];continue n}else {t.msg="invalid distance code",I.mode=Jn;break e}break}}else if((y&64)===0){S=p[(S&65535)+(h&(1<<y)-1)];continue t}else if(y&32){I.mode=mc;break e}else {t.msg="invalid literal/length code",I.mode=Jn;break e}break}}while(i<s&&r<a);A=g>>3,i-=A,g-=A<<3,h&=(1<<g)-1,t.next_in=i,t.next_out=r,t.avail_in=i<s?5+(s-i):5-(i-s),t.avail_out=r<a?257+(a-r):257-(r-a),I.hold=h,I.bits=g;},dt=15,Or=852,Lr=592,Cr=0,Ji=1,Rr=2,yc=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),bc=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),wc=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),_c=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),Sc=(n,t,e,i,s,r,o,a)=>{let c=a.bits,l=0,f=0,d=0,u=0,h=0,g=0,p=0,m=0,b=0,_=0,S,y,A,N,v,w=null,x,T=new Uint16Array(dt+1),I=new Uint16Array(dt+1),M=null,St,un,hn;for(l=0;l<=dt;l++)T[l]=0;for(f=0;f<i;f++)T[t[e+f]]++;for(h=c,u=dt;u>=1&&T[u]===0;u--);if(h>u&&(h=u),u===0)return s[r++]=1<<24|64<<16|0,s[r++]=1<<24|64<<16|0,a.bits=1,0;for(d=1;d<u&&T[d]===0;d++);for(h<d&&(h=d),m=1,l=1;l<=dt;l++)if(m<<=1,m-=T[l],m<0)return -1;if(m>0&&(n===Cr||u!==1))return -1;for(I[1]=0,l=1;l<dt;l++)I[l+1]=I[l]+T[l];for(f=0;f<i;f++)t[e+f]!==0&&(o[I[t[e+f]]++]=f);if(n===Cr?(w=M=o,x=20):n===Ji?(w=yc,M=bc,x=257):(w=wc,M=_c,x=0),_=0,f=0,l=d,v=r,g=h,p=0,A=-1,b=1<<h,N=b-1,n===Ji&&b>Or||n===Rr&&b>Lr)return 1;for(;;){St=l-p,o[f]+1<x?(un=0,hn=o[f]):o[f]>=x?(un=M[o[f]-x],hn=w[o[f]-x]):(un=96,hn=0),S=1<<l-p,y=1<<g,d=y;do y-=S,s[v+(_>>p)+y]=St<<24|un<<16|hn|0;while(y!==0);for(S=1<<l-1;_&S;)S>>=1;if(S!==0?(_&=S-1,_+=S):_=0,f++,--T[l]===0){if(l===u)break;l=t[e+o[f]];}if(l>h&&(_&N)!==A){for(p===0&&(p=h),v+=d,g=l-p,m=1<<g;g+p<u&&(m-=T[g+p],!(m<=0));)g++,m<<=1;if(b+=1<<g,n===Ji&&b>Or||n===Rr&&b>Lr)return 1;A=_&N,s[A]=h<<24|g<<16|v-r|0;}}return _!==0&&(s[v+_]=l-p<<24|64<<16|0),a.bits=h,0},Wt=Sc,kc=0,Oo=1,Lo=2,{Z_FINISH:$r,Z_BLOCK:vc,Z_TREES:Qn,Z_OK:Qe,Z_STREAM_END:Ac,Z_NEED_DICT:Ec,Z_STREAM_ERROR:ne,Z_DATA_ERROR:Co,Z_MEM_ERROR:Ro,Z_BUF_ERROR:Nc,Z_DEFLATED:Br}=bt,ai=16180,Dr=16181,Mr=16182,Ur=16183,Pr=16184,zr=16185,Kr=16186,Fr=16187,jr=16188,qr=16189,si=16190,Te=16191,Qi=16192,Vr=16193,Xi=16194,Zr=16195,Hr=16196,Yr=16197,Gr=16198,Xn=16199,ei=16200,Wr=16201,Jr=16202,Qr=16203,Xr=16204,eo=16205,es=16206,to=16207,no=16208,U=16209,$o=16210,Bo=16211,xc=852,Tc=592,Ic=15,Oc=Ic,io=n=>(n>>>24&255)+(n>>>8&65280)+((n&65280)<<8)+((n&255)<<24);function Lc(){this.strm=null,this.mode=0,this.last=false,this.wrap=0,this.havedict=false,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0;}var Xe=n=>{if(!n)return 1;let t=n.state;return !t||t.strm!==n||t.mode<ai||t.mode>Bo?1:0},Do=n=>{if(Xe(n))return ne;let t=n.state;return n.total_in=n.total_out=t.total=0,n.msg="",t.wrap&&(n.adler=t.wrap&1),t.mode=ai,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(xc),t.distcode=t.distdyn=new Int32Array(Tc),t.sane=1,t.back=-1,Qe},Mo=n=>{if(Xe(n))return ne;let t=n.state;return t.wsize=0,t.whave=0,t.wnext=0,Do(n)},Uo=(n,t)=>{let e;if(Xe(n))return ne;let i=n.state;return t<0?(e=0,t=-t):(e=(t>>4)+5,t<48&&(t&=15)),t&&(t<8||t>15)?ne:(i.window!==null&&i.wbits!==t&&(i.window=null),i.wrap=e,i.wbits=t,Mo(n))},Po=(n,t)=>{if(!n)return ne;let e=new Lc;n.state=e,e.strm=n,e.window=null,e.mode=ai;let i=Uo(n,t);return i!==Qe&&(n.state=null),i},Cc=n=>Po(n,Oc),so=true,ts,ns,Rc=n=>{if(so){ts=new Int32Array(512),ns=new Int32Array(32);let t=0;for(;t<144;)n.lens[t++]=8;for(;t<256;)n.lens[t++]=9;for(;t<280;)n.lens[t++]=7;for(;t<288;)n.lens[t++]=8;for(Wt(Oo,n.lens,0,288,ts,0,n.work,{bits:9}),t=0;t<32;)n.lens[t++]=5;Wt(Lo,n.lens,0,32,ns,0,n.work,{bits:5}),so=false;}n.lencode=ts,n.lenbits=9,n.distcode=ns,n.distbits=5;},zo=(n,t,e,i)=>{let s,r=n.state;return r.window===null&&(r.wsize=1<<r.wbits,r.wnext=0,r.whave=0,r.window=new Uint8Array(r.wsize)),i>=r.wsize?(r.window.set(t.subarray(e-r.wsize,e),0),r.wnext=0,r.whave=r.wsize):(s=r.wsize-r.wnext,s>i&&(s=i),r.window.set(t.subarray(e-i,e-i+s),r.wnext),i-=s,i?(r.window.set(t.subarray(e-i,e),0),r.wnext=i,r.whave=r.wsize):(r.wnext+=s,r.wnext===r.wsize&&(r.wnext=0),r.whave<r.wsize&&(r.whave+=s))),0},$c=(n,t)=>{let e,i,s,r,o,a,c,l,f,d,u,h,g,p,m=0,b,_,S,y,A,N,v,w,x=new Uint8Array(4),T,I,M=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Xe(n)||!n.output||!n.input&&n.avail_in!==0)return ne;e=n.state,e.mode===Te&&(e.mode=Qi),o=n.next_out,s=n.output,c=n.avail_out,r=n.next_in,i=n.input,a=n.avail_in,l=e.hold,f=e.bits,d=a,u=c,w=Qe;e:for(;;)switch(e.mode){case ai:if(e.wrap===0){e.mode=Qi;break}for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.wrap&2&&l===35615){e.wbits===0&&(e.wbits=15),e.check=0,x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0),l=0,f=0,e.mode=Dr;break}if(e.head&&(e.head.done=false),!(e.wrap&1)||(((l&255)<<8)+(l>>8))%31){n.msg="incorrect header check",e.mode=U;break}if((l&15)!==Br){n.msg="unknown compression method",e.mode=U;break}if(l>>>=4,f-=4,v=(l&15)+8,e.wbits===0&&(e.wbits=v),v>15||v>e.wbits){n.msg="invalid window size",e.mode=U;break}e.dmax=1<<e.wbits,e.flags=0,n.adler=e.check=1,e.mode=l&512?qr:Te,l=0,f=0;break;case Dr:for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.flags=l,(e.flags&255)!==Br){n.msg="unknown compression method",e.mode=U;break}if(e.flags&57344){n.msg="unknown header flags set",e.mode=U;break}e.head&&(e.head.text=l>>8&1),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0)),l=0,f=0,e.mode=Mr;case Mr:for(;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.head&&(e.head.time=l),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,x[2]=l>>>16&255,x[3]=l>>>24&255,e.check=F(e.check,x,4,0)),l=0,f=0,e.mode=Ur;case Ur:for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.head&&(e.head.xflags=l&255,e.head.os=l>>8),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0)),l=0,f=0,e.mode=Pr;case Pr:if(e.flags&1024){for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.length=l,e.head&&(e.head.extra_len=l),e.flags&512&&e.wrap&4&&(x[0]=l&255,x[1]=l>>>8&255,e.check=F(e.check,x,2,0)),l=0,f=0;}else e.head&&(e.head.extra=null);e.mode=zr;case zr:if(e.flags&1024&&(h=e.length,h>a&&(h=a),h&&(e.head&&(v=e.head.extra_len-e.length,e.head.extra||(e.head.extra=new Uint8Array(e.head.extra_len)),e.head.extra.set(i.subarray(r,r+h),v)),e.flags&512&&e.wrap&4&&(e.check=F(e.check,i,h,r)),a-=h,r+=h,e.length-=h),e.length))break e;e.length=0,e.mode=Kr;case Kr:if(e.flags&2048){if(a===0)break e;h=0;do v=i[r+h++],e.head&&v&&e.length<65536&&(e.head.name+=String.fromCharCode(v));while(v&&h<a);if(e.flags&512&&e.wrap&4&&(e.check=F(e.check,i,h,r)),a-=h,r+=h,v)break e}else e.head&&(e.head.name=null);e.length=0,e.mode=Fr;case Fr:if(e.flags&4096){if(a===0)break e;h=0;do v=i[r+h++],e.head&&v&&e.length<65536&&(e.head.comment+=String.fromCharCode(v));while(v&&h<a);if(e.flags&512&&e.wrap&4&&(e.check=F(e.check,i,h,r)),a-=h,r+=h,v)break e}else e.head&&(e.head.comment=null);e.mode=jr;case jr:if(e.flags&512){for(;f<16;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.wrap&4&&l!==(e.check&65535)){n.msg="header crc mismatch",e.mode=U;break}l=0,f=0;}e.head&&(e.head.hcrc=e.flags>>9&1,e.head.done=true),n.adler=e.check=0,e.mode=Te;break;case qr:for(;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}n.adler=e.check=io(l),l=0,f=0,e.mode=si;case si:if(e.havedict===0)return n.next_out=o,n.avail_out=c,n.next_in=r,n.avail_in=a,e.hold=l,e.bits=f,Ec;n.adler=e.check=1,e.mode=Te;case Te:if(t===vc||t===Qn)break e;case Qi:if(e.last){l>>>=f&7,f-=f&7,e.mode=es;break}for(;f<3;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}switch(e.last=l&1,l>>>=1,f-=1,l&3){case 0:e.mode=Vr;break;case 1:if(Rc(e),e.mode=Xn,t===Qn){l>>>=2,f-=2;break e}break;case 2:e.mode=Hr;break;case 3:n.msg="invalid block type",e.mode=U;}l>>>=2,f-=2;break;case Vr:for(l>>>=f&7,f-=f&7;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if((l&65535)!==(l>>>16^65535)){n.msg="invalid stored block lengths",e.mode=U;break}if(e.length=l&65535,l=0,f=0,e.mode=Xi,t===Qn)break e;case Xi:e.mode=Zr;case Zr:if(h=e.length,h){if(h>a&&(h=a),h>c&&(h=c),h===0)break e;s.set(i.subarray(r,r+h),o),a-=h,r+=h,c-=h,o+=h,e.length-=h;break}e.mode=Te;break;case Hr:for(;f<14;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.nlen=(l&31)+257,l>>>=5,f-=5,e.ndist=(l&31)+1,l>>>=5,f-=5,e.ncode=(l&15)+4,l>>>=4,f-=4,e.nlen>286||e.ndist>30){n.msg="too many length or distance symbols",e.mode=U;break}e.have=0,e.mode=Yr;case Yr:for(;e.have<e.ncode;){for(;f<3;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.lens[M[e.have++]]=l&7,l>>>=3,f-=3;}for(;e.have<19;)e.lens[M[e.have++]]=0;if(e.lencode=e.lendyn,e.lenbits=7,T={bits:e.lenbits},w=Wt(kc,e.lens,0,19,e.lencode,0,e.work,T),e.lenbits=T.bits,w){n.msg="invalid code lengths set",e.mode=U;break}e.have=0,e.mode=Gr;case Gr:for(;e.have<e.nlen+e.ndist;){for(;m=e.lencode[l&(1<<e.lenbits)-1],b=m>>>24,_=m>>>16&255,S=m&65535,!(b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(S<16)l>>>=b,f-=b,e.lens[e.have++]=S;else {if(S===16){for(I=b+2;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(l>>>=b,f-=b,e.have===0){n.msg="invalid bit length repeat",e.mode=U;break}v=e.lens[e.have-1],h=3+(l&3),l>>>=2,f-=2;}else if(S===17){for(I=b+3;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=b,f-=b,v=0,h=3+(l&7),l>>>=3,f-=3;}else {for(I=b+7;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=b,f-=b,v=0,h=11+(l&127),l>>>=7,f-=7;}if(e.have+h>e.nlen+e.ndist){n.msg="invalid bit length repeat",e.mode=U;break}for(;h--;)e.lens[e.have++]=v;}}if(e.mode===U)break;if(e.lens[256]===0){n.msg="invalid code -- missing end-of-block",e.mode=U;break}if(e.lenbits=9,T={bits:e.lenbits},w=Wt(Oo,e.lens,0,e.nlen,e.lencode,0,e.work,T),e.lenbits=T.bits,w){n.msg="invalid literal/lengths set",e.mode=U;break}if(e.distbits=6,e.distcode=e.distdyn,T={bits:e.distbits},w=Wt(Lo,e.lens,e.nlen,e.ndist,e.distcode,0,e.work,T),e.distbits=T.bits,w){n.msg="invalid distances set",e.mode=U;break}if(e.mode=Xn,t===Qn)break e;case Xn:e.mode=ei;case ei:if(a>=6&&c>=258){n.next_out=o,n.avail_out=c,n.next_in=r,n.avail_in=a,e.hold=l,e.bits=f,gc(n,u),o=n.next_out,s=n.output,c=n.avail_out,r=n.next_in,i=n.input,a=n.avail_in,l=e.hold,f=e.bits,e.mode===Te&&(e.back=-1);break}for(e.back=0;m=e.lencode[l&(1<<e.lenbits)-1],b=m>>>24,_=m>>>16&255,S=m&65535,!(b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(_&&(_&240)===0){for(y=b,A=_,N=S;m=e.lencode[N+((l&(1<<y+A)-1)>>y)],b=m>>>24,_=m>>>16&255,S=m&65535,!(y+b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=y,f-=y,e.back+=y;}if(l>>>=b,f-=b,e.back+=b,e.length=S,_===0){e.mode=eo;break}if(_&32){e.back=-1,e.mode=Te;break}if(_&64){n.msg="invalid literal/length code",e.mode=U;break}e.extra=_&15,e.mode=Wr;case Wr:if(e.extra){for(I=e.extra;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.length+=l&(1<<e.extra)-1,l>>>=e.extra,f-=e.extra,e.back+=e.extra;}e.was=e.length,e.mode=Jr;case Jr:for(;m=e.distcode[l&(1<<e.distbits)-1],b=m>>>24,_=m>>>16&255,S=m&65535,!(b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if((_&240)===0){for(y=b,A=_,N=S;m=e.distcode[N+((l&(1<<y+A)-1)>>y)],b=m>>>24,_=m>>>16&255,S=m&65535,!(y+b<=f);){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}l>>>=y,f-=y,e.back+=y;}if(l>>>=b,f-=b,e.back+=b,_&64){n.msg="invalid distance code",e.mode=U;break}e.offset=S,e.extra=_&15,e.mode=Qr;case Qr:if(e.extra){for(I=e.extra;f<I;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}e.offset+=l&(1<<e.extra)-1,l>>>=e.extra,f-=e.extra,e.back+=e.extra;}if(e.offset>e.dmax){n.msg="invalid distance too far back",e.mode=U;break}e.mode=Xr;case Xr:if(c===0)break e;if(h=u-c,e.offset>h){if(h=e.offset-h,h>e.whave&&e.sane){n.msg="invalid distance too far back",e.mode=U;break}h>e.wnext?(h-=e.wnext,g=e.wsize-h):g=e.wnext-h,h>e.length&&(h=e.length),p=e.window;}else p=s,g=o-e.offset,h=e.length;h>c&&(h=c),c-=h,e.length-=h;do s[o++]=p[g++];while(--h);e.length===0&&(e.mode=ei);break;case eo:if(c===0)break e;s[o++]=e.length,c--,e.mode=ei;break;case es:if(e.wrap){for(;f<32;){if(a===0)break e;a--,l|=i[r++]<<f,f+=8;}if(u-=c,n.total_out+=u,e.total+=u,e.wrap&4&&u&&(n.adler=e.check=e.flags?F(e.check,s,u,o-u):tn(e.check,s,u,o-u)),u=c,e.wrap&4&&(e.flags?l:io(l))!==e.check){n.msg="incorrect data check",e.mode=U;break}l=0,f=0;}e.mode=to;case to:if(e.wrap&&e.flags){for(;f<32;){if(a===0)break e;a--,l+=i[r++]<<f,f+=8;}if(e.wrap&4&&l!==(e.total&4294967295)){n.msg="incorrect length check",e.mode=U;break}l=0,f=0;}e.mode=no;case no:w=Ac;break e;case U:w=Co;break e;case $o:return Ro;case Bo:default:return ne}return n.next_out=o,n.avail_out=c,n.next_in=r,n.avail_in=a,e.hold=l,e.bits=f,(e.wsize||u!==n.avail_out&&e.mode<U&&(e.mode<es||t!==$r))&&zo(n,n.output,n.next_out,u-n.avail_out),d-=n.avail_in,u-=n.avail_out,n.total_in+=d,n.total_out+=u,e.total+=u,e.wrap&4&&u&&(n.adler=e.check=e.flags?F(e.check,s,u,n.next_out-u):tn(e.check,s,u,n.next_out-u)),n.data_type=e.bits+(e.last?64:0)+(e.mode===Te?128:0)+(e.mode===Xn||e.mode===Xi?256:0),(d===0&&u===0||t===$r)&&w===Qe&&(w=Nc),w},Bc=n=>{if(Xe(n))return ne;let t=n.state;return t.window&&(t.window=null),n.state=null,Qe},Dc=(n,t)=>{if(Xe(n))return ne;let e=n.state;return (e.wrap&2)===0?ne:(e.head=t,t.done=false,Qe)},Mc=(n,t)=>{let e=t.length,i,s,r;return Xe(n)||(i=n.state,i.wrap!==0&&i.mode!==si)?ne:i.mode===si&&(s=1,s=tn(s,t,e,0),s!==i.check)?Co:(r=zo(n,t,e,e),r?(i.mode=$o,Ro):(i.havedict=1,Qe))},Uc=Mo,Pc=Uo,zc=Do,Kc=Cc,Fc=Po,jc=$c,qc=Bc,Vc=Dc,Zc=Mc,Hc="pako inflate (from Nodeca project)",Oe={inflateReset:Uc,inflateReset2:Pc,inflateResetKeep:zc,inflateInit:Kc,inflateInit2:Fc,inflate:jc,inflateEnd:qc,inflateGetHeader:Vc,inflateSetDictionary:Zc,inflateInfo:Hc};function Yc(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=false;}var Gc=Yc,Ko=Object.prototype.toString,{Z_NO_FLUSH:Wc,Z_FINISH:Jc,Z_OK:rn,Z_STREAM_END:is,Z_NEED_DICT:ss,Z_STREAM_ERROR:Qc,Z_DATA_ERROR:ro,Z_MEM_ERROR:Xc}=bt;function cn(n){this.options=oi.assign({chunkSize:1024*64,windowBits:15,to:""},n||{});let t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,t.windowBits===0&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(n&&n.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(t.windowBits&15)===0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=false,this.chunks=[],this.strm=new To,this.strm.avail_out=0;let e=Oe.inflateInit2(this.strm,t.windowBits);if(e!==rn)throw new Error(We[e]);if(this.header=new Gc,Oe.inflateGetHeader(this.strm,this.header),t.dictionary&&(typeof t.dictionary=="string"?t.dictionary=sn.string2buf(t.dictionary):Ko.call(t.dictionary)==="[object ArrayBuffer]"&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(e=Oe.inflateSetDictionary(this.strm,t.dictionary),e!==rn)))throw new Error(We[e])}cn.prototype.push=function(n,t){let e=this.strm,i=this.options.chunkSize,s=this.options.dictionary,r,o,a;if(this.ended)return false;for(t===~~t?o=t:o=t===true?Jc:Wc,Ko.call(n)==="[object ArrayBuffer]"?e.input=new Uint8Array(n):e.input=n,e.next_in=0,e.avail_in=e.input.length;;){for(e.avail_out===0&&(e.output=new Uint8Array(i),e.next_out=0,e.avail_out=i),r=Oe.inflate(e,o),r===ss&&s&&(r=Oe.inflateSetDictionary(e,s),r===rn?r=Oe.inflate(e,o):r===ro&&(r=ss));e.avail_in>0&&r===is&&e.state.wrap>0&&n[e.next_in]!==0;)Oe.inflateReset(e),r=Oe.inflate(e,o);switch(r){case Qc:case ro:case ss:case Xc:return this.onEnd(r),this.ended=true,false}if(a=e.avail_out,e.next_out&&(e.avail_out===0||r===is))if(this.options.to==="string"){let c=sn.utf8border(e.output,e.next_out),l=e.next_out-c,f=sn.buf2string(e.output,c);e.next_out=l,e.avail_out=i-l,l&&e.output.set(e.output.subarray(c,c+l),0),this.onData(f);}else this.onData(e.output.length===e.next_out?e.output:e.output.subarray(0,e.next_out));if(!(r===rn&&a===0)){if(r===is)return r=Oe.inflateEnd(this.strm),this.onEnd(r),this.ended=true,true;if(e.avail_in===0)break}}return true};cn.prototype.onData=function(n){this.chunks.push(n);};cn.prototype.onEnd=function(n){n===rn&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=oi.flattenChunks(this.chunks)),this.chunks=[],this.err=n,this.msg=this.strm.msg;};function _s(n,t){let e=new cn(t);if(e.push(n),e.err)throw e.msg||We[e.err];return e.result}var nf=_s,af={inflate:nf},{inflate:lf}=af;var Fo=lf;function jo(n,t){let e=typeof t=="string"?{algorithm:t}:t,i=e.algorithm;if(!i)throw new k("Process specification missing algorithm");switch(i){case "zlib":return cf(n);case "xor":return ff(n,e.key);case "rol":return uf(n,e.amount,e.group);case "ror":return hf(n,e.amount,e.group);case "bswap2":return li(n,2);case "bswap4":return li(n,4);case "bswap8":return li(n,8);case "bswap16":return li(n,16);default:throw new k(`Unknown process algorithm: ${i}. Supported: zlib, xor, rol, ror, bswap2, bswap4, bswap8, bswap16`)}}function cf(n){try{return Fo(n)}catch(t){throw new k(`Zlib decompression failed: ${t instanceof Error?t.message:String(t)}`)}}function ff(n,t){if(t===void 0)throw new k("XOR process requires a key parameter");let e=new Uint8Array(n.length),i=Array.isArray(t)?t:[t];if(i.length===0)throw new k("XOR key cannot be empty");for(let s=0;s<n.length;s++)e[s]=n[s]^i[s%i.length];return e}function uf(n,t,e){let i=t??1,s=e??1;if(i<0)throw new k("ROL amount must be non-negative");if(s<1)throw new k("ROL group size must be at least 1");if(n.length%s!==0)throw new k(`Data length ${n.length} is not aligned to group size ${s}`);let r=new Uint8Array(n.length);if(s===1){let c=i%8;for(let l=0;l<n.length;l++){let f=n[l];r[l]=(f<<c|f>>8-c)&255;}return r}let o=s*8,a=i%o;for(let c=0;c<n.length;c+=s){let l=[];for(let d=0;d<s;d++){let u=n[c+d];for(let h=7;h>=0;h--)l.push(u>>h&1);}let f=[...l.slice(a),...l.slice(0,a)];for(let d=0;d<s;d++){let u=0;for(let h=0;h<8;h++)u=u<<1|f[d*8+h];r[c+d]=u;}}return r}function hf(n,t,e){let i=t??1,s=e??1;if(i<0)throw new k("ROR amount must be non-negative");if(s<1)throw new k("ROR group size must be at least 1");if(n.length%s!==0)throw new k(`Data length ${n.length} is not aligned to group size ${s}`);let r=new Uint8Array(n.length);if(s===1){let c=i%8;for(let l=0;l<n.length;l++){let f=n[l];r[l]=(f>>c|f<<8-c)&255;}return r}let o=s*8,a=i%o;for(let c=0;c<n.length;c+=s){let l=[];for(let d=0;d<s;d++){let u=n[c+d];for(let h=7;h>=0;h--)l.push(u>>h&1);}let f=[...l.slice(o-a),...l.slice(0,o-a)];for(let d=0;d<s;d++){let u=0;for(let h=0;h<8;h++)u=u<<1|f[d*8+h];r[c+d]=u;}}return r}function li(n,t){if(![2,4,8,16].includes(t))throw new k(`Invalid byteswap group size: ${t}. Must be 2, 4, 8, or 16`);if(n.length%t!==0)throw new k(`Data length ${n.length} is not aligned to group size ${t}`);let e=new Uint8Array(n.length);for(let i=0;i<n.length;i+=t)for(let s=0;s<t;s++)e[i+s]=n[i+t-1-s];return e}var fn=class n{constructor(t,e){this.schema=t;this.parentMeta=e;if(!t.meta&&!e)throw new k("Schema must have meta section");if(t.meta&&!t.meta.id&&!e)throw new k("Root schema must have meta.id")}static getKaitaiIO(t){if(t&&typeof t=="object"){let i=t._io;if(i instanceof he)return i}return null}parse(t,e,i,s){let r={},o=s||r,a=new qt(t,o,e,this.schema.enums);a.current=r;let c=t,l=c.m!==void 0?c.m:t.pos,f=t.pos;if(r._io=t,s&&(r._root=s),i&&this.schema.params)for(let h=0;h<this.schema.params.length&&h<i.length;h++){let g=this.schema.params[h],p=i[h],m=typeof p=="string"?this.evaluateValue(p,a):p;a.set(g.id,m);}if(this.schema.instances&&this.setupInstances(r,t,a),this.schema.seq)for(let h of this.schema.seq){let g=this.parseAttribute(h,a);h.id&&(r[h.id]=g);}let u=t.pos-f;return r._sizeof=u,r._startPos=l,r}setupInstances(t,e,i){if(this.schema.instances)for(let[s,r]of Object.entries(this.schema.instances)){let o,a=false;Object.defineProperty(t,s,{get:()=>(a||(o=this.parseInstance(r,e,i),a=true),o),enumerable:true,configurable:true});}}parseInstance(t,e,i){if("value"in t)return this.evaluateValue(t.value,i);let s=e.pos;try{if(t.pos!==void 0){let o=this.evaluateValue(t.pos,i);if(typeof o=="number")e.seek(o);else if(typeof o=="bigint")e.seek(Number(o));else throw new k(`pos must evaluate to a number, got ${typeof o}`)}return this.parseAttribute(t,i)}finally{t.pos!==void 0&&e.seek(s);}}parseAttribute(t,e){let i=e.io;if(t.io!==void 0){let r=this.evaluateValue(t.io,e);if(r instanceof he)i=r;else {let o=n.getKaitaiIO(r);if(o)i=o;else throw new k("io must evaluate to a KaitaiStream or an object with _io")}}if(t.if&&!this.evaluateValue(t.if,e))return;if(t.pos!==void 0){let r=this.evaluateValue(t.pos,e);if(typeof r=="number")i.seek(r);else if(typeof r=="bigint")i.seek(Number(r));else throw new k(`pos must evaluate to a number, got ${typeof r}`)}return t.repeat?this.parseRepeated(t,e):t.contents?this.parseContents(t,e):this.parseValue(t,e)}parseRepeated(t,e){let i=e.io,s=[];switch(t.repeat){case "expr":{let r=this.evaluateValue(t["repeat-expr"],e),o=typeof r=="number"?r:typeof r=="bigint"?Number(r):0;if(o<0)throw new k(`repeat-expr must be non-negative, got ${o}`);for(let a=0;a<o;a++){e.set("_index",a);let c=this.parseAttribute({...t,repeat:void 0,"repeat-expr":void 0},e);s.push(c);}break}case "eos":{for(;!i.isEof();)e.set("_index",s.length),s.push(this.parseValue(t,e));break}case "until":{if(!t["repeat-until"])throw new k("repeat-until expression is required");let r=0;for(;;){e.set("_index",r);let o=this.parseAttribute({...t,repeat:void 0,"repeat-until":void 0},e);if(s.push(o),e.set("_",o),this.evaluateValue(t["repeat-until"],e)||i.isEof())break;r++;}break}default:throw new k(`Unknown repeat type: ${t.repeat}`)}return s}parseContents(t,e){let i=e.io,s=t.contents;if(Array.isArray(s)){let r=i.readBytes(s.length);for(let o=0;o<s.length;o++)if(r[o]!==s[o])throw new je(`Contents mismatch at byte ${o}: expected ${s[o]}, got ${r[o]}`,i.pos-s.length+o);return r}else {let r=t.encoding||this.schema.meta?.encoding||this.parentMeta?.encoding||"UTF-8",o=i.readStr(s.length,r);if(o!==s)throw new je(`Contents mismatch: expected "${s}", got "${o}"`,i.pos-s.length);return o}}parseValue(t,e){let i=e.io,s=t.type;if(t.size!==void 0){let r=this.evaluateValue(t.size,e),o=typeof r=="number"?r:typeof r=="bigint"?Number(r):0;if(o<0)throw new k(`size must be non-negative, got ${o}`);if(s==="str"||!s){let a=t.encoding||this.schema.meta?.encoding||this.parentMeta?.encoding||"UTF-8",c;return s==="str"?(c=i.readBytes(o),t.process&&(c=this.applyProcessing(c,t.process)),new TextDecoder(a).decode(c)):(c=i.readBytes(o),t.process&&(c=this.applyProcessing(c,t.process)),c)}else {let a=i.pos,c=i.readBytes(o);t.process&&(c=this.applyProcessing(c,t.process));let l=new he(c);return l.m=a,this.parseType(s,l,e,t["type-args"])}}if(t["size-eos"])if(s==="str"){let r=t.encoding||this.schema.meta?.encoding||this.parentMeta?.encoding||"UTF-8",o=i.readBytesFull();return new TextDecoder(r).decode(o)}else {let r=i.readBytesFull();if(t.process&&(r=this.applyProcessing(r,t.process)),s){let o=new he(r);return this.parseType(s,o,e,t["type-args"])}return r}if(!s)throw new k("Attribute must have either type, size, or contents");return this.parseType(s,i,e,t["type-args"])}parseType(t,e,i,s){if(typeof t=="object")return this.parseSwitchType(t,e,i);let{typeName:r,args:o}=this.parseParameterizedType(t,i),a=o.length>0?o:s;if(fi(r))return this.parseBuiltinType(r,e,i);if(this.schema.types&&r in this.schema.types){let c=this.schema.types[r],l=this.schema.meta||this.parentMeta;return this.schema.enums&&!c.enums&&(c.enums=this.schema.enums),this.schema.types&&!c.types&&(c.types=this.schema.types),new n(c,l).parse(e,i.current,a,i.root)}throw new k(`Unknown type: ${r}`)}parseParameterizedType(t,e){let i=t.match(/^([a-z_][a-z0-9_]*)\((.*)\)$/i);if(!i)return {typeName:t,args:[]};let s=i[1],r=i[2].trim();if(!r)return {typeName:s,args:[]};let o=[],a="",c=false,l="",f=0;for(let d=0;d<r.length;d++){let u=r[d];c?(a+=u,u===l&&r[d-1]!=="\\"&&(c=false)):u==='"'||u==="'"?(c=true,l=u,a+=u):u==="("?(f++,a+=u):u===")"?(f--,a+=u):u===","&&f===0?(o.push(this.parseArgument(a.trim(),e)),a=""):a+=u;}return a.trim()&&o.push(this.parseArgument(a.trim(),e)),{typeName:s,args:o}}parseArgument(t,e){if(t==="true")return true;if(t==="false")return false;if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(/^-?\d+$/.test(t))return parseInt(t,10);if(/^-?\d+\.\d+$/.test(t))return parseFloat(t);if(/^0x[0-9a-f]+$/i.test(t))return parseInt(t,16);try{let i=this.evaluateValue(t,e);return typeof i=="string"||typeof i=="number"||typeof i=="boolean"?i:Number(i)}catch{return t}}parseSwitchType(t,e,i){let s=t["switch-on"],r=t.cases,o=t.default;if(!s||typeof s!="string")throw new k("switch-on expression is required for switch types");if(!r)throw new k("cases are required for switch types");let a=this.evaluateValue(s,i),c=String(a),l=r[c];if(l===void 0&&o&&(l=o),l===void 0)throw new k(`No matching case for switch value "${c}" and no default type specified`);return this.parseType(l,e,i)}parseBuiltinType(t,e,i){let s=vt(t),r=ui(t),a=(this.schema.meta||this.parentMeta)?.endian,c;if(r?c=r:typeof a=="string"?c=a:a&&typeof a=="object"?c=this.evaluateEndianExpression(a,i):c="le",hi(t))return this.readInteger(s,c,e);if(di(t))return this.readFloat(s,c,e);if(/^b\d+$/.test(t)){let l=parseInt(t.slice(1),10),f=e.readBitsIntBe(l),d=BigInt(Number.MAX_SAFE_INTEGER);return f<=d?Number(f):f}if(pi(t)){let l=this.schema.meta?.encoding||"UTF-8";if(t==="strz")return e.readStrz(l,0,false,true,true);if(t==="str")throw new k("str type requires size, size-eos, or terminator attribute")}throw new k(`Unknown built-in type: ${t}`)}readInteger(t,e,i){switch(t){case "u1":return i.readU1();case "u2":return e==="le"?i.readU2le():i.readU2be();case "u4":return e==="le"?i.readU4le():i.readU4be();case "u8":return e==="le"?i.readU8le():i.readU8be();case "s1":return i.readS1();case "s2":return e==="le"?i.readS2le():i.readS2be();case "s4":return e==="le"?i.readS4le():i.readS4be();case "s8":return e==="le"?i.readS8le():i.readS8be();default:throw new k(`Unknown integer type: ${t}`)}}readFloat(t,e,i){switch(t){case "f4":return e==="le"?i.readF4le():i.readF4be();case "f8":return e==="le"?i.readF8le():i.readF8be();default:throw new k(`Unknown float type: ${t}`)}}applyProcessing(t,e){return jo(t,e)}evaluateEndianExpression(t,e){let i=t["switch-on"],s=t.cases;if(!i||typeof i!="string")throw new k('Endian expression missing "switch-on" field');if(!s||typeof s!="object")throw new k('Endian expression missing "cases" field');let r=this.evaluateValue(i,e),o=String(r);if(o in s){let a=s[o];if(a!=="le"&&a!=="be")throw new k(`Invalid endianness value: ${a}`);return a}return "le"}evaluateValue(t,e){if(t!==void 0){if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="string")try{return Sr(t,e)}catch(i){throw new k(`Failed to evaluate expression "${t}": ${i instanceof Error?i.message:String(i)}`)}return t}}};function r0(n,t,e={}){let{validate:i=true,strict:s=false}=e,o=new jt().parse(n,{validate:i,strict:s}),a=new he(t);return new fn(o).parse(a)}/**
135
135
  * @fileoverview Custom error classes for Kaitai Struct parsing and validation
136
136
  * @module utils/errors
137
137
  * @author Fabiano Pinto