UNPKG

@huggingface/transformers

Version:

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!

67 lines • 367 kB
import*as e from"fs";import*as t from"onnxruntime-node";import*as r from"path";import*as n from"sharp";import*as o from"url";var s,a,i={fs: /*!*********************!*\ !*** external "fs" ***! \*********************/t=>{t.exports=e},"onnxruntime-node": /*!***********************************!*\ !*** external "onnxruntime-node" ***! \***********************************/e=>{e.exports=t},path: /*!***********************!*\ !*** external "path" ***! \***********************/e=>{e.exports=r},sharp: /*!************************!*\ !*** external "sharp" ***! \************************/e=>{e.exports=n},url: /*!**********************!*\ !*** external "url" ***! \**********************/e=>{e.exports=o},"?cb4d": /*!*************************************!*\ !*** #onnxruntime-webgpu (ignored) ***! \*************************************/()=>{},"./node_modules/@huggingface/jinja/dist/index.js": /*!*******************************************************!*\ !*** ./node_modules/@huggingface/jinja/dist/index.js ***! \*******************************************************/(e,t,r)=>{r.r(t),r.d(t,{Environment:()=>Y,Interpreter:()=>J,Template:()=>ee,parse:()=>B,tokenize:()=>d});var n=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",BooleanLiteral:"BooleanLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Set:"Set",If:"If",For:"For",In:"In",Is:"Is",NotIn:"NotIn",Else:"Else",EndIf:"EndIf",ElseIf:"ElseIf",EndFor:"EndFor",And:"And",Or:"Or",Not:"UnaryOperator",Macro:"Macro",EndMacro:"EndMacro"}),o=Object.freeze({set:n.Set,for:n.For,in:n.In,is:n.Is,if:n.If,else:n.Else,endif:n.EndIf,elif:n.ElseIf,endfor:n.EndFor,and:n.And,or:n.Or,not:n.Not,"not in":n.NotIn,macro:n.Macro,endmacro:n.EndMacro,true:n.BooleanLiteral,false:n.BooleanLiteral,True:n.BooleanLiteral,False:n.BooleanLiteral}),s=class{constructor(e,t){this.value=e,this.type=t}};function a(e){return/\w/.test(e)}function i(e){return/[0-9]/.test(e)}var l=[["{%",n.OpenStatement],["%}",n.CloseStatement],["{{",n.OpenExpression],["}}",n.CloseExpression],["(",n.OpenParen],[")",n.CloseParen],["{",n.OpenCurlyBracket],["}",n.CloseCurlyBracket],["[",n.OpenSquareBracket],["]",n.CloseSquareBracket],[",",n.Comma],[".",n.Dot],[":",n.Colon],["|",n.Pipe],["<=",n.ComparisonBinaryOperator],[">=",n.ComparisonBinaryOperator],["==",n.ComparisonBinaryOperator],["!=",n.ComparisonBinaryOperator],["<",n.ComparisonBinaryOperator],[">",n.ComparisonBinaryOperator],["+",n.AdditiveBinaryOperator],["-",n.AdditiveBinaryOperator],["*",n.MultiplicativeBinaryOperator],["/",n.MultiplicativeBinaryOperator],["%",n.MultiplicativeBinaryOperator],["=",n.Equals]],c=new Map([["n","\n"],["t","\t"],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function d(e,t={}){const r=[],d=function(e,t={}){return e.endsWith("\n")&&(e=e.slice(0,-1)),e=e.replace(/{#.*?#}/gs,"{##}"),t.lstrip_blocks&&(e=e.replace(/^[ \t]*({[#%])/gm,"$1")),t.trim_blocks&&(e=e.replace(/([#%]})\n/g,"$1")),e.replace(/{##}/g,"").replace(/-%}\s*/g,"%}").replace(/\s*{%-/g,"{%").replace(/-}}\s*/g,"}}").replace(/\s*{{-/g,"{{")}(e,t);let u=0;const p=e=>{let t="";for(;e(d[u]);)if("\\"!==d[u]){if(t+=d[u++],u>=d.length)throw new SyntaxError("Unexpected end of input")}else{if(++u,u>=d.length)throw new SyntaxError("Unexpected end of input");const e=d[u++],r=c.get(e);if(void 0===r)throw new SyntaxError(`Unexpected escaped character: ${e}`);t+=r}return t};e:for(;u<d.length;){const e=r.at(-1)?.type;if(void 0===e||e===n.CloseStatement||e===n.CloseExpression){let e="";for(;u<d.length&&("{"!==d[u]||"%"!==d[u+1]&&"{"!==d[u+1]);)e+=d[u++];if(e.length>0){r.push(new s(e,n.Text));continue}}p((e=>/\s/.test(e)));const t=d[u];if("-"===t||"+"===t){const e=r.at(-1)?.type;if(e===n.Text||void 0===e)throw new SyntaxError(`Unexpected character: ${t}`);switch(e){case n.Identifier:case n.NumericLiteral:case n.BooleanLiteral:case n.StringLiteral:case n.CloseParen:case n.CloseSquareBracket:break;default:{++u;const e=p(i);r.push(new s(`${t}${e}`,e.length>0?n.NumericLiteral:n.UnaryOperator));continue}}}for(const[e,t]of l){if(d.slice(u,u+e.length)===e){r.push(new s(e,t)),u+=e.length;continue e}}if("'"!==t&&'"'!==t)if(i(t)){const e=p(i);r.push(new s(e,n.NumericLiteral))}else{if(!a(t))throw new SyntaxError(`Unexpected character: ${t}`);{const e=p(a),t=Object.hasOwn(o,e)?o[e]:n.Identifier;t===n.In&&r.at(-1)?.type===n.Not?(r.pop(),r.push(new s("not in",n.NotIn))):r.push(new s(e,t))}}else{++u;const e=p((e=>e!==t));r.push(new s(e,n.StringLiteral)),++u}}return r}var u=class{type="Statement"},p=class extends u{constructor(e){super(),this.body=e}type="Program"},h=class extends u{constructor(e,t,r){super(),this.test=e,this.body=t,this.alternate=r}type="If"},m=class extends u{constructor(e,t,r,n){super(),this.loopvar=e,this.iterable=t,this.body=r,this.defaultBlock=n}type="For"},_=class extends u{constructor(e,t){super(),this.assignee=e,this.value=t}type="Set"},f=class extends u{constructor(e,t,r){super(),this.name=e,this.args=t,this.body=r}type="Macro"},g=class extends u{type="Expression"},M=class extends g{constructor(e,t,r){super(),this.object=e,this.property=t,this.computed=r}type="MemberExpression"},w=class extends g{constructor(e,t){super(),this.callee=e,this.args=t}type="CallExpression"},T=class extends g{constructor(e){super(),this.value=e}type="Identifier"},b=class extends g{constructor(e){super(),this.value=e}type="Literal"},x=class extends b{type="NumericLiteral"},k=class extends b{type="StringLiteral"},y=class extends b{type="BooleanLiteral"},F=class extends b{type="ArrayLiteral"},P=class extends b{type="TupleLiteral"},C=class extends b{type="ObjectLiteral"},v=class extends g{constructor(e,t,r){super(),this.operator=e,this.left=t,this.right=r}type="BinaryExpression"},S=class extends g{constructor(e,t){super(),this.operand=e,this.filter=t}type="FilterExpression"},A=class extends g{constructor(e,t){super(),this.iterable=e,this.test=t}type="SelectExpression"},E=class extends g{constructor(e,t,r){super(),this.operand=e,this.negate=t,this.test=r}type="TestExpression"},L=class extends g{constructor(e,t){super(),this.operator=e,this.argument=t}type="UnaryExpression"},z=class extends g{constructor(e=void 0,t=void 0,r=void 0){super(),this.start=e,this.stop=t,this.step=r}type="SliceExpression"},I=class extends g{constructor(e,t){super(),this.key=e,this.value=t}type="KeywordArgumentExpression"};function B(e){const t=new p([]);let r=0;function o(t,n){const o=e[r++];if(!o||o.type!==t)throw new Error(`Parser Error: ${n}. ${o.type} !== ${t}.`);return o}function s(){switch(e[r].type){case n.Text:return new k(o(n.Text,"Expected text token").value);case n.OpenStatement:return function(){let t;switch(o(n.OpenStatement,"Expected opening statement token"),e[r].type){case n.Set:++r,t=l(),o(n.CloseStatement,"Expected closing statement token");break;case n.If:++r,t=c(),o(n.OpenStatement,"Expected {% token"),o(n.EndIf,"Expected endif token"),o(n.CloseStatement,"Expected %} token");break;case n.Macro:++r,t=function(){const e=q();if("Identifier"!==e.type)throw new SyntaxError("Expected identifier following macro statement");const t=V();o(n.CloseStatement,"Expected closing statement token");const r=[];for(;a(n.OpenStatement,n.EndMacro);)r.push(s());return new f(e,t,r)}(),o(n.OpenStatement,"Expected {% token"),o(n.EndMacro,"Expected endmacro token"),o(n.CloseStatement,"Expected %} token");break;case n.For:++r,t=function(){const e=d(!0);if(!(e instanceof T||e instanceof P))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${e.type} instead`);o(n.In,"Expected `in` keyword following loop variable");const t=u();o(n.CloseStatement,"Expected closing statement token");const l=[];for(;a(n.OpenStatement,n.EndFor)&&a(n.OpenStatement,n.Else);)l.push(s());const c=[];if(i(n.OpenStatement,n.Else))for(++r,++r,o(n.CloseStatement,"Expected closing statement token");a(n.OpenStatement,n.EndFor);)c.push(s());return new m(e,t,l,c)}(),o(n.OpenStatement,"Expected {% token"),o(n.EndFor,"Expected endfor token"),o(n.CloseStatement,"Expected %} token");break;default:throw new SyntaxError(`Unknown statement type: ${e[r].type}`)}return t}();case n.OpenExpression:return function(){o(n.OpenExpression,"Expected opening expression token");const e=u();return o(n.CloseExpression,"Expected closing expression token"),e}();default:throw new SyntaxError(`Unexpected token type: ${e[r].type}`)}}function a(...t){return r+t.length<=e.length&&t.some(((t,n)=>t!==e[r+n].type))}function i(...t){return r+t.length<=e.length&&t.every(((t,n)=>t===e[r+n].type))}function l(){const e=u();if(i(n.Equals)){++r;const t=l();return new _(e,t)}return e}function c(){const t=u();o(n.CloseStatement,"Expected closing statement token");const a=[],l=[];for(;e[r]?.type!==n.OpenStatement||e[r+1]?.type!==n.ElseIf&&e[r+1]?.type!==n.Else&&e[r+1]?.type!==n.EndIf;)a.push(s());if(e[r]?.type===n.OpenStatement&&e[r+1]?.type!==n.EndIf)if(++r,i(n.ElseIf))o(n.ElseIf,"Expected elseif token"),l.push(c());else for(o(n.Else,"Expected else token"),o(n.CloseStatement,"Expected closing statement token");e[r]?.type!==n.OpenStatement||e[r+1]?.type!==n.EndIf;)l.push(s());return new h(t,a,l)}function d(e=!1){const t=e?q:u,o=[t()],s=i(n.Comma);for(;s&&(++r,o.push(t()),i(n.Comma)););return s?new P(o):o[0]}function u(){return function(){const e=g();if(i(n.If)){++r;const t=g();if(i(n.Else)){++r;const n=g();return new h(t,[e],[n])}return new A(e,t)}return e}()}function g(){let t=b();for(;i(n.Or);){const n=e[r];++r;const o=b();t=new v(n,t,o)}return t}function b(){let t=B();for(;i(n.And);){const n=e[r];++r;const o=B();t=new v(n,t,o)}return t}function B(){let t;for(;i(n.Not);){const n=e[r];++r;const o=B();t=new L(n,o)}return t??function(){let t=N();for(;i(n.ComparisonBinaryOperator)||i(n.In)||i(n.NotIn);){const n=e[r];++r;const o=N();t=new v(n,t,o)}return t}()}function N(){let t=R();for(;i(n.AdditiveBinaryOperator);){const n=e[r];++r;const o=R();t=new v(n,t,o)}return t}function O(){const t=function(){let t=q();for(;i(n.Dot)||i(n.OpenSquareBracket);){const s=e[r];let a;++r;const i=s.type!==n.Dot;if(i)a=j(),o(n.CloseSquareBracket,"Expected closing square bracket");else if(a=q(),"Identifier"!==a.type)throw new SyntaxError("Expected identifier following dot operator");t=new M(t,a,i)}return t}();return i(n.OpenParen)?D(t):t}function D(e){let t=new w(e,V());return i(n.OpenParen)&&(t=D(t)),t}function V(){o(n.OpenParen,"Expected opening parenthesis for arguments list");const e=function(){const e=[];for(;!i(n.CloseParen);){let t=u();if(i(n.Equals)){if(++r,!(t instanceof T))throw new SyntaxError("Expected identifier for keyword argument");const e=u();t=new I(t,e)}e.push(t),i(n.Comma)&&++r}return e}();return o(n.CloseParen,"Expected closing parenthesis for arguments list"),e}function j(){const e=[];let t=!1;for(;!i(n.CloseSquareBracket);)i(n.Colon)?(e.push(void 0),++r,t=!0):(e.push(u()),i(n.Colon)&&(++r,t=!0));if(0===e.length)throw new SyntaxError("Expected at least one argument for member/slice expression");if(t){if(e.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new z(...e)}return e[0]}function R(){let t=G();for(;i(n.MultiplicativeBinaryOperator);){const n=e[r];++r;const o=G();t=new v(n,t,o)}return t}function G(){let e=function(){let e=O();for(;i(n.Pipe);){++r;let t=q();if(!(t instanceof T))throw new SyntaxError("Expected identifier for the filter");i(n.OpenParen)&&(t=D(t)),e=new S(e,t)}return e}();for(;i(n.Is);){++r;const t=i(n.Not);t&&++r;let o=q();if(o instanceof y&&(o=new T(o.value.toString())),!(o instanceof T))throw new SyntaxError("Expected identifier for the test");e=new E(e,t,o)}return e}function q(){const t=e[r];switch(t.type){case n.NumericLiteral:return++r,new x(Number(t.value));case n.StringLiteral:return++r,new k(t.value);case n.BooleanLiteral:return++r,new y("true"===t.value.toLowerCase());case n.Identifier:return++r,new T(t.value);case n.OpenParen:{++r;const t=d();if(e[r].type!==n.CloseParen)throw new SyntaxError(`Expected closing parenthesis, got ${e[r].type} instead`);return++r,t}case n.OpenSquareBracket:{++r;const e=[];for(;!i(n.CloseSquareBracket);)e.push(u()),i(n.Comma)&&++r;return++r,new F(e)}case n.OpenCurlyBracket:{++r;const e=new Map;for(;!i(n.CloseCurlyBracket);){const t=u();o(n.Colon,"Expected colon between key and value in object literal");const s=u();e.set(t,s),i(n.Comma)&&++r}return++r,new C(e)}default:throw new SyntaxError(`Unexpected token: ${t.type}`)}}for(;r<e.length;)t.body.push(s());return t}function N(e,t,r=1){void 0===t&&(t=e,e=0);const n=[];for(let o=e;o<t;o+=r)n.push(o);return n}function O(e,t,r,n=1){const o=Math.sign(n);o>=0?(t=(t??=0)<0?Math.max(e.length+t,0):Math.min(t,e.length),r=(r??=e.length)<0?Math.max(e.length+r,0):Math.min(r,e.length)):(t=(t??=e.length-1)<0?Math.max(e.length+t,-1):Math.min(t,e.length-1),r=(r??=-1)<-1?Math.max(e.length+r,-1):Math.min(r,e.length-1));const s=[];for(let a=t;o*a<o*r;a+=n)s.push(e[a]);return s}function D(e){return e.replace(/\b\w/g,(e=>e.toUpperCase()))}var V=class{type="RuntimeValue";value;builtins=new Map;constructor(e=void 0){this.value=e}__bool__(){return new G(!!this.value)}},j=class extends V{type="NumericValue"},R=class extends V{type="StringValue";builtins=new Map([["upper",new X((()=>new R(this.value.toUpperCase())))],["lower",new X((()=>new R(this.value.toLowerCase())))],["strip",new X((()=>new R(this.value.trim())))],["title",new X((()=>new R(D(this.value))))],["length",new j(this.value.length)]])},G=class extends V{type="BooleanValue"},q=class extends V{type="ObjectValue";__bool__(){return new G(this.value.size>0)}builtins=new Map([["get",new X((([e,t])=>{if(!(e instanceof R))throw new Error(`Object key must be a string: got ${e.type}`);return this.value.get(e.value)??t??new Q}))],["items",new X((()=>new W(Array.from(this.value.entries()).map((([e,t])=>new W([new R(e),t]))))))]])},$=class extends q{type="KeywordArgumentsValue"},W=class extends V{type="ArrayValue";builtins=new Map([["length",new j(this.value.length)]]);__bool__(){return new G(this.value.length>0)}},U=class extends W{type="TupleValue"},X=class extends V{type="FunctionValue"},Q=class extends V{type="NullValue"},H=class extends V{type="UndefinedValue"},Y=class{constructor(e){this.parent=e}variables=new Map([["namespace",new X((e=>{if(0===e.length)return new q(new Map);if(1!==e.length||!(e[0]instanceof q))throw new Error("`namespace` expects either zero arguments or a single object argument");return e[0]}))]]);tests=new Map([["boolean",e=>"BooleanValue"===e.type],["callable",e=>e instanceof X],["odd",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "odd" to type: ${e.type}`);return e.value%2!=0}],["even",e=>{if("NumericValue"!==e.type)throw new Error(`Cannot apply test "even" to type: ${e.type}`);return e.value%2==0}],["false",e=>"BooleanValue"===e.type&&!e.value],["true",e=>"BooleanValue"===e.type&&e.value],["string",e=>"StringValue"===e.type],["number",e=>"NumericValue"===e.type],["integer",e=>"NumericValue"===e.type&&Number.isInteger(e.value)],["iterable",e=>e instanceof W||e instanceof R],["lower",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toLowerCase()}],["upper",e=>{const t=e.value;return"StringValue"===e.type&&t===t.toUpperCase()}],["none",e=>"NullValue"===e.type],["defined",e=>"UndefinedValue"!==e.type],["undefined",e=>"UndefinedValue"===e.type],["equalto",(e,t)=>e.value===t.value],["eq",(e,t)=>e.value===t.value]]);set(e,t){return this.declareVariable(e,K(t))}declareVariable(e,t){if(this.variables.has(e))throw new SyntaxError(`Variable already declared: ${e}`);return this.variables.set(e,t),t}setVariable(e,t){return this.variables.set(e,t),t}resolve(e){if(this.variables.has(e))return this;if(this.parent)return this.parent.resolve(e);throw new Error(`Unknown variable: ${e}`)}lookupVariable(e){try{return this.resolve(e).variables.get(e)??new H}catch{return new H}}},J=class{global;constructor(e){this.global=e??new Y}run(e){return this.evaluate(e,this.global)}evaluateBinaryExpression(e,t){const r=this.evaluate(e.left,t);switch(e.operator.value){case"and":return r.__bool__().value?this.evaluate(e.right,t):r;case"or":return r.__bool__().value?r:this.evaluate(e.right,t)}const n=this.evaluate(e.right,t);switch(e.operator.value){case"==":return new G(r.value==n.value);case"!=":return new G(r.value!=n.value)}if(r instanceof H||n instanceof H)throw new Error("Cannot perform operation on undefined values");if(r instanceof Q||n instanceof Q)throw new Error("Cannot perform operation on null values");if(r instanceof j&&n instanceof j)switch(e.operator.value){case"+":return new j(r.value+n.value);case"-":return new j(r.value-n.value);case"*":return new j(r.value*n.value);case"/":return new j(r.value/n.value);case"%":return new j(r.value%n.value);case"<":return new G(r.value<n.value);case">":return new G(r.value>n.value);case">=":return new G(r.value>=n.value);case"<=":return new G(r.value<=n.value)}else if(r instanceof W&&n instanceof W){if("+"===e.operator.value)return new W(r.value.concat(n.value))}else if(n instanceof W){const t=void 0!==n.value.find((e=>e.value===r.value));switch(e.operator.value){case"in":return new G(t);case"not in":return new G(!t)}}if((r instanceof R||n instanceof R)&&"+"===e.operator.value)return new R(r.value.toString()+n.value.toString());if(r instanceof R&&n instanceof R)switch(e.operator.value){case"in":return new G(n.value.includes(r.value));case"not in":return new G(!n.value.includes(r.value))}if(r instanceof R&&n instanceof q)switch(e.operator.value){case"in":return new G(n.value.has(r.value));case"not in":return new G(!n.value.has(r.value))}throw new SyntaxError(`Unknown operator "${e.operator.value}" between ${r.type} and ${n.type}`)}evaluateArguments(e,t){const r=[],n=new Map;for(const o of e)if("KeywordArgumentExpression"===o.type){const e=o;n.set(e.key.value,this.evaluate(e.value,t))}else{if(n.size>0)throw new Error("Positional arguments must come before keyword arguments");r.push(this.evaluate(o,t))}return[r,n]}evaluateFilterExpression(e,t){const r=this.evaluate(e.operand,t);if("Identifier"===e.filter.type){const t=e.filter;if("tojson"===t.value)return new R(Z(r));if(r instanceof W)switch(t.value){case"list":return r;case"first":return r.value[0];case"last":return r.value[r.value.length-1];case"length":return new j(r.value.length);case"reverse":return new W(r.value.reverse());case"sort":return new W(r.value.sort(((e,t)=>{if(e.type!==t.type)throw new Error(`Cannot compare different types: ${e.type} and ${t.type}`);switch(e.type){case"NumericValue":return e.value-t.value;case"StringValue":return e.value.localeCompare(t.value);default:throw new Error(`Cannot compare type: ${e.type}`)}})));default:throw new Error(`Unknown ArrayValue filter: ${t.value}`)}else if(r instanceof R)switch(t.value){case"length":return new j(r.value.length);case"upper":return new R(r.value.toUpperCase());case"lower":return new R(r.value.toLowerCase());case"title":return new R(D(r.value));case"capitalize":return new R(r.value.charAt(0).toUpperCase()+r.value.slice(1));case"trim":return new R(r.value.trim());case"indent":return new R(r.value.split("\n").map(((e,t)=>0===t||0===e.length?e:" "+e)).join("\n"));case"string":return r;default:throw new Error(`Unknown StringValue filter: ${t.value}`)}else{if(r instanceof j){if("abs"===t.value)return new j(Math.abs(r.value));throw new Error(`Unknown NumericValue filter: ${t.value}`)}if(r instanceof q)switch(t.value){case"items":return new W(Array.from(r.value.entries()).map((([e,t])=>new W([new R(e),t]))));case"length":return new j(r.value.size);default:throw new Error(`Unknown ObjectValue filter: ${t.value}`)}}throw new Error(`Cannot apply filter "${t.value}" to type: ${r.type}`)}if("CallExpression"===e.filter.type){const n=e.filter;if("Identifier"!==n.callee.type)throw new Error(`Unknown filter: ${n.callee.type}`);const o=n.callee.value;if("tojson"===o){const[,e]=this.evaluateArguments(n.args,t),o=e.get("indent")??new Q;if(!(o instanceof j||o instanceof Q))throw new Error("If set, indent must be a number");return new R(Z(r,o.value))}if(r instanceof W){switch(o){case"selectattr":{if(r.value.some((e=>!(e instanceof q))))throw new Error("`selectattr` can only be applied to array of objects");if(n.args.some((e=>"StringLiteral"!==e.type)))throw new Error("arguments of `selectattr` must be strings");const[e,o,s]=n.args.map((e=>this.evaluate(e,t)));let a;if(o){const e=t.tests.get(o.value);if(!e)throw new Error(`Unknown test: ${o.value}`);a=e}else a=(...e)=>e[0].__bool__().value;const i=r.value.filter((t=>{const r=t.value.get(e.value);return!!r&&a(r,s)}));return new W(i)}case"map":{const[,e]=this.evaluateArguments(n.args,t);if(e.has("attribute")){const t=e.get("attribute");if(!(t instanceof R))throw new Error("attribute must be a string");const n=e.get("default"),o=r.value.map((e=>{if(!(e instanceof q))throw new Error("items in map must be an object");return e.value.get(t.value)??n??new H}));return new W(o)}throw new Error("`map` expressions without `attribute` set are not currently supported.")}}throw new Error(`Unknown ArrayValue filter: ${o}`)}if(r instanceof R){if("indent"===o){const[e,o]=this.evaluateArguments(n.args,t),s=e.at(0)??o.get("width")??new j(4);if(!(s instanceof j))throw new Error("width must be a number");const a=e.at(1)??o.get("first")??new G(!1),i=e.at(2)??o.get("blank")??new G(!1),l=r.value.split("\n"),c=" ".repeat(s.value),d=l.map(((e,t)=>!a.value&&0===t||!i.value&&0===e.length?e:c+e));return new R(d.join("\n"))}throw new Error(`Unknown StringValue filter: ${o}`)}throw new Error(`Cannot apply filter "${o}" to type: ${r.type}`)}throw new Error(`Unknown filter: ${e.filter.type}`)}evaluateTestExpression(e,t){const r=this.evaluate(e.operand,t),n=t.tests.get(e.test.value);if(!n)throw new Error(`Unknown test: ${e.test.value}`);const o=n(r);return new G(e.negate?!o:o)}evaluateUnaryExpression(e,t){const r=this.evaluate(e.argument,t);if("not"===e.operator.value)return new G(!r.value);throw new SyntaxError(`Unknown operator: ${e.operator.value}`)}evalProgram(e,t){return this.evaluateBlock(e.body,t)}evaluateBlock(e,t){let r="";for(const n of e){const e=this.evaluate(n,t);"NullValue"!==e.type&&"UndefinedValue"!==e.type&&(r+=e.value)}return new R(r)}evaluateIdentifier(e,t){return t.lookupVariable(e.value)}evaluateCallExpression(e,t){const[r,n]=this.evaluateArguments(e.args,t);n.size>0&&r.push(new $(n));const o=this.evaluate(e.callee,t);if("FunctionValue"!==o.type)throw new Error(`Cannot call something that is not a function: got ${o.type}`);return o.value(r,t)}evaluateSliceExpression(e,t,r){if(!(e instanceof W||e instanceof R))throw new Error("Slice object must be an array or string");const n=this.evaluate(t.start,r),o=this.evaluate(t.stop,r),s=this.evaluate(t.step,r);if(!(n instanceof j||n instanceof H))throw new Error("Slice start must be numeric or undefined");if(!(o instanceof j||o instanceof H))throw new Error("Slice stop must be numeric or undefined");if(!(s instanceof j||s instanceof H))throw new Error("Slice step must be numeric or undefined");return e instanceof W?new W(O(e.value,n.value,o.value,s.value)):new R(O(Array.from(e.value),n.value,o.value,s.value).join(""))}evaluateMemberExpression(e,t){const r=this.evaluate(e.object,t);let n,o;if(e.computed){if("SliceExpression"===e.property.type)return this.evaluateSliceExpression(r,e.property,t);n=this.evaluate(e.property,t)}else n=new R(e.property.value);if(r instanceof q){if(!(n instanceof R))throw new Error(`Cannot access property with non-string: got ${n.type}`);o=r.value.get(n.value)??r.builtins.get(n.value)}else if(r instanceof W||r instanceof R)if(n instanceof j)o=r.value.at(n.value),r instanceof R&&(o=new R(r.value.at(n.value)));else{if(!(n instanceof R))throw new Error(`Cannot access property with non-string/non-number: got ${n.type}`);o=r.builtins.get(n.value)}else{if(!(n instanceof R))throw new Error(`Cannot access property with non-string: got ${n.type}`);o=r.builtins.get(n.value)}return o instanceof V?o:new H}evaluateSet(e,t){const r=this.evaluate(e.value,t);if("Identifier"===e.assignee.type){const n=e.assignee.value;t.setVariable(n,r)}else{if("MemberExpression"!==e.assignee.type)throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(e.assignee)}`);{const n=e.assignee,o=this.evaluate(n.object,t);if(!(o instanceof q))throw new Error("Cannot assign to member of non-object");if("Identifier"!==n.property.type)throw new Error("Cannot assign to member with non-identifier property");o.value.set(n.property.value,r)}}return new Q}evaluateIf(e,t){const r=this.evaluate(e.test,t);return this.evaluateBlock(r.__bool__().value?e.body:e.alternate,t)}evaluateFor(e,t){const r=new Y(t);let n,o;if("SelectExpression"===e.iterable.type){const t=e.iterable;o=this.evaluate(t.iterable,r),n=t.test}else o=this.evaluate(e.iterable,r);if(!(o instanceof W))throw new Error(`Expected iterable type in for loop: got ${o.type}`);const s=[],a=[];for(let t=0;t<o.value.length;++t){const i=new Y(r),l=o.value[t];let c;if("Identifier"===e.loopvar.type)c=t=>t.setVariable(e.loopvar.value,l);else{if("TupleLiteral"!==e.loopvar.type)throw new Error(`Invalid loop variable(s): ${e.loopvar.type}`);{const t=e.loopvar;if("ArrayValue"!==l.type)throw new Error(`Cannot unpack non-iterable type: ${l.type}`);const r=l;if(t.value.length!==r.value.length)throw new Error(`Too ${t.value.length>r.value.length?"few":"many"} items to unpack`);c=e=>{for(let n=0;n<t.value.length;++n){if("Identifier"!==t.value[n].type)throw new Error(`Cannot unpack non-identifier type: ${t.value[n].type}`);e.setVariable(t.value[n].value,r.value[n])}}}}if(n){c(i);if(!this.evaluate(n,i).__bool__().value)continue}s.push(l),a.push(c)}let i="",l=!0;for(let t=0;t<s.length;++t){const n=new Map([["index",new j(t+1)],["index0",new j(t)],["revindex",new j(s.length-t)],["revindex0",new j(s.length-t-1)],["first",new G(0===t)],["last",new G(t===s.length-1)],["length",new j(s.length)],["previtem",t>0?s[t-1]:new H],["nextitem",t<s.length-1?s[t+1]:new H]]);r.setVariable("loop",new q(n)),a[t](r);i+=this.evaluateBlock(e.body,r).value,l=!1}if(l){i+=this.evaluateBlock(e.defaultBlock,r).value}return new R(i)}evaluateMacro(e,t){return t.setVariable(e.name.value,new X(((t,r)=>{const n=new Y(r);let o;t=t.slice(),"KeywordArgumentsValue"===t.at(-1)?.type&&(o=t.pop());for(let r=0;r<e.args.length;++r){const s=e.args[r],a=t[r];if("Identifier"===s.type){const e=s;if(!a)throw new Error(`Missing positional argument: ${e.value}`);n.setVariable(e.value,a)}else{if("KeywordArgumentExpression"!==s.type)throw new Error(`Unknown argument type: ${s.type}`);{const e=s,t=a??o?.value.get(e.key.value)??this.evaluate(e.value,n);n.setVariable(e.key.value,t)}}}return this.evaluateBlock(e.body,n)}))),new Q}evaluate(e,t){if(void 0===e)return new H;switch(e.type){case"Program":return this.evalProgram(e,t);case"Set":return this.evaluateSet(e,t);case"If":return this.evaluateIf(e,t);case"For":return this.evaluateFor(e,t);case"Macro":return this.evaluateMacro(e,t);case"NumericLiteral":return new j(Number(e.value));case"StringLiteral":return new R(e.value);case"BooleanLiteral":return new G(e.value);case"ArrayLiteral":return new W(e.value.map((e=>this.evaluate(e,t))));case"TupleLiteral":return new U(e.value.map((e=>this.evaluate(e,t))));case"ObjectLiteral":{const r=new Map;for(const[n,o]of e.value){const e=this.evaluate(n,t);if(!(e instanceof R))throw new Error(`Object keys must be strings: got ${e.type}`);r.set(e.value,this.evaluate(o,t))}return new q(r)}case"Identifier":return this.evaluateIdentifier(e,t);case"CallExpression":return this.evaluateCallExpression(e,t);case"MemberExpression":return this.evaluateMemberExpression(e,t);case"UnaryExpression":return this.evaluateUnaryExpression(e,t);case"BinaryExpression":return this.evaluateBinaryExpression(e,t);case"FilterExpression":return this.evaluateFilterExpression(e,t);case"TestExpression":return this.evaluateTestExpression(e,t);default:throw new SyntaxError(`Unknown node type: ${e.type}`)}}};function K(e){switch(typeof e){case"number":return new j(e);case"string":return new R(e);case"boolean":return new G(e);case"undefined":return new H;case"object":return null===e?new Q:Array.isArray(e)?new W(e.map(K)):new q(new Map(Object.entries(e).map((([e,t])=>[e,K(t)]))));case"function":return new X(((t,r)=>K(e(...t.map((e=>e.value)))??null)));default:throw new Error(`Cannot convert to runtime value: ${e}`)}}function Z(e,t,r){const n=r??0;switch(e.type){case"NullValue":case"UndefinedValue":return"null";case"NumericValue":case"StringValue":case"BooleanValue":return JSON.stringify(e.value);case"ArrayValue":case"ObjectValue":{const r=t?" ".repeat(t):"",o="\n"+r.repeat(n),s=o+r;if("ArrayValue"===e.type){const r=e.value.map((e=>Z(e,t,n+1)));return t?`[${s}${r.join(`,${s}`)}${o}]`:`[${r.join(", ")}]`}{const r=Array.from(e.value.entries()).map((([e,r])=>{const o=`"${e}": ${Z(r,t,n+1)}`;return t?`${s}${o}`:o}));return t?`{${r.join(",")}${o}}`:`{${r.join(", ")}}`}}default:throw new Error(`Cannot convert to JSON: ${e.type}`)}}var ee=class{parsed;constructor(e){const t=d(e,{lstrip_blocks:!0,trim_blocks:!0});this.parsed=B(t)}render(e){const t=new Y;t.set("false",!1),t.set("true",!0),t.set("raise_exception",(e=>{throw new Error(e)})),t.set("range",N);for(const[r,n]of Object.entries(e))t.set(r,n);return new J(t).run(this.parsed).value}}},"./node_modules/onnxruntime-common/dist/esm/backend-impl.js": /*!******************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/backend-impl.js ***! \******************************************************************/(e,t,r)=>{r.r(t),r.d(t,{registerBackend:()=>s,resolveBackendAndExecutionProviders:()=>i});const n=new Map,o=[],s=(e,t,r)=>{if(!t||"function"!=typeof t.init||"function"!=typeof t.createInferenceSessionHandler)throw new TypeError("not a valid backend");{const s=n.get(e);if(void 0===s)n.set(e,{backend:t,priority:r});else{if(s.priority>r)return;if(s.priority===r&&s.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${r}`)}if(r>=0){const t=o.indexOf(e);-1!==t&&o.splice(t,1);for(let t=0;t<o.length;t++)if(n.get(o[t]).priority<=r)return void o.splice(t,0,e);o.push(e)}}},a=async e=>{const t=n.get(e);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{const r=!!t.initPromise;try{return r||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(e){return r||(t.error=`${e}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},i=async e=>{const t=e.executionProviders||[],r=t.map((e=>"string"==typeof e?e:e.name)),n=0===r.length?o:r;let s;const i=[],l=new Set;for(const e of n){const t=await a(e);"string"==typeof t?i.push({name:e,err:t}):(s||(s=t),s===t&&l.add(e))}if(!s)throw new Error(`no available backend found. ERR: ${i.map((e=>`[${e.name}] ${e.err}`)).join(", ")}`);for(const{name:e,err:t}of i)r.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${t}`);const c=t.filter((e=>l.has("string"==typeof e?e:e.name)));return[s,new Proxy(e,{get:(e,t)=>"executionProviders"===t?c:Reflect.get(e,t)})]}},"./node_modules/onnxruntime-common/dist/esm/backend.js": /*!*************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/backend.js ***! \*************************************************************/(e,t,r)=>{r.r(t),r.d(t,{registerBackend:()=>n.registerBackend});var n=r(/*! ./backend-impl.js */"./node_modules/onnxruntime-common/dist/esm/backend-impl.js")},"./node_modules/onnxruntime-common/dist/esm/env-impl.js": /*!**************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/env-impl.js ***! \**************************************************************/(e,t,r)=>{r.r(t),r.d(t,{env:()=>s});var n=r(/*! ./version.js */"./node_modules/onnxruntime-common/dist/esm/version.js");let o="warning";const s={wasm:{},webgl:{},webgpu:{},versions:{common:n.version},set logLevel(e){if(void 0!==e){if("string"!=typeof e||-1===["verbose","info","warning","error","fatal"].indexOf(e))throw new Error(`Unsupported logging level: ${e}`);o=e}},get logLevel(){return o}};Object.defineProperty(s,"logLevel",{enumerable:!0})},"./node_modules/onnxruntime-common/dist/esm/env.js": /*!*********************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/env.js ***! \*********************************************************/(e,t,r)=>{r.r(t),r.d(t,{env:()=>n});const n=r(/*! ./env-impl.js */"./node_modules/onnxruntime-common/dist/esm/env-impl.js").env},"./node_modules/onnxruntime-common/dist/esm/index.js": /*!***********************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/index.js ***! \***********************************************************/(e,t,r)=>{r.r(t),r.d(t,{InferenceSession:()=>s.InferenceSession,TRACE:()=>i.TRACE,TRACE_FUNC_BEGIN:()=>i.TRACE_FUNC_BEGIN,TRACE_FUNC_END:()=>i.TRACE_FUNC_END,Tensor:()=>a.Tensor,TrainingSession:()=>l.TrainingSession,env:()=>o.env,registerBackend:()=>n.registerBackend});var n=r(/*! ./backend.js */"./node_modules/onnxruntime-common/dist/esm/backend.js"),o=r(/*! ./env.js */"./node_modules/onnxruntime-common/dist/esm/env.js"),s=r(/*! ./inference-session.js */"./node_modules/onnxruntime-common/dist/esm/inference-session.js"),a=r(/*! ./tensor.js */"./node_modules/onnxruntime-common/dist/esm/tensor.js"),i=(r(/*! ./tensor-conversion.js */"./node_modules/onnxruntime-common/dist/esm/tensor-conversion.js"),r(/*! ./tensor-factory.js */"./node_modules/onnxruntime-common/dist/esm/tensor-factory.js"),r(/*! ./trace.js */"./node_modules/onnxruntime-common/dist/esm/trace.js")),l=(r(/*! ./onnx-model.js */"./node_modules/onnxruntime-common/dist/esm/onnx-model.js"),r(/*! ./onnx-value.js */"./node_modules/onnxruntime-common/dist/esm/onnx-value.js"),r(/*! ./training-session.js */"./node_modules/onnxruntime-common/dist/esm/training-session.js"))},"./node_modules/onnxruntime-common/dist/esm/inference-session-impl.js": /*!****************************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/inference-session-impl.js ***! \****************************************************************************/(e,t,r)=>{r.r(t),r.d(t,{InferenceSession:()=>a});var n=r(/*! ./backend-impl.js */"./node_modules/onnxruntime-common/dist/esm/backend-impl.js"),o=r(/*! ./tensor.js */"./node_modules/onnxruntime-common/dist/esm/tensor.js"),s=r(/*! ./trace.js */"./node_modules/onnxruntime-common/dist/esm/trace.js");class a{constructor(e){this.handler=e}async run(e,t,r){(0,s.TRACE_FUNC_BEGIN)();const n={};let a={};if("object"!=typeof e||null===e||e instanceof o.Tensor||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let i=!0;if("object"==typeof t){if(null===t)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof o.Tensor)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(0===t.length)throw new TypeError("'fetches' cannot be an empty array.");i=!1;for(const e of t){if("string"!=typeof e)throw new TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(e))throw new RangeError(`'fetches' contains invalid output name: ${e}.`);n[e]=null}if("object"==typeof r&&null!==r)a=r;else if(void 0!==r)throw new TypeError("'options' must be an object.")}else{let e=!1;const s=Object.getOwnPropertyNames(t);for(const r of this.outputNames)if(-1!==s.indexOf(r)){const s=t[r];(null===s||s instanceof o.Tensor)&&(e=!0,i=!1,n[r]=s)}if(e){if("object"==typeof r&&null!==r)a=r;else if(void 0!==r)throw new TypeError("'options' must be an object.")}else a=t}}else if(void 0!==t)throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const t of this.inputNames)if(void 0===e[t])throw new Error(`input '${t}' is missing in 'feeds'.`);if(i)for(const e of this.outputNames)n[e]=null;const l=await this.handler.run(e,n,a),c={};for(const e in l)if(Object.hasOwnProperty.call(l,e)){const t=l[e];t instanceof o.Tensor?c[e]=t:c[e]=new o.Tensor(t.type,t.data,t.dims)}return(0,s.TRACE_FUNC_END)(),c}async release(){return this.handler.dispose()}static async create(e,t,r,o){let i;(0,s.TRACE_FUNC_BEGIN)();let l={};if("string"==typeof e){if(i=e,"object"==typeof t&&null!==t)l=t;else if(void 0!==t)throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(i=e,"object"==typeof t&&null!==t)l=t;else if(void 0!==t)throw new TypeError("'options' must be an object.")}else{if(!(e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{const n=e;let s=0,a=e.byteLength;if("object"==typeof t&&null!==t)l=t;else if("number"==typeof t){if(s=t,!Number.isSafeInteger(s))throw new RangeError("'byteOffset' must be an integer.");if(s<0||s>=n.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${n.byteLength}).`);if(a=e.byteLength-s,"number"==typeof r){if(a=r,!Number.isSafeInteger(a))throw new RangeError("'byteLength' must be an integer.");if(a<=0||s+a>n.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${n.byteLength-s}].`);if("object"==typeof o&&null!==o)l=o;else if(void 0!==o)throw new TypeError("'options' must be an object.")}else if(void 0!==r)throw new TypeError("'byteLength' must be a number.")}else if(void 0!==t)throw new TypeError("'options' must be an object.");i=new Uint8Array(n,s,a)}}const[c,d]=await(0,n.resolveBackendAndExecutionProviders)(l),u=await c.createInferenceSessionHandler(i,d);return(0,s.TRACE_FUNC_END)(),new a(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}},"./node_modules/onnxruntime-common/dist/esm/inference-session.js": /*!***********************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/inference-session.js ***! \***********************************************************************/(e,t,r)=>{r.r(t),r.d(t,{InferenceSession:()=>n});const n=r(/*! ./inference-session-impl.js */"./node_modules/onnxruntime-common/dist/esm/inference-session-impl.js").InferenceSession},"./node_modules/onnxruntime-common/dist/esm/onnx-model.js": /*!****************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/onnx-model.js ***! \****************************************************************/(e,t,r)=>{r.r(t)},"./node_modules/onnxruntime-common/dist/esm/onnx-value.js": /*!****************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/onnx-value.js ***! \****************************************************************/(e,t,r)=>{r.r(t)},"./node_modules/onnxruntime-common/dist/esm/tensor-conversion-impl.js": /*!****************************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/tensor-conversion-impl.js ***! \****************************************************************************/(e,t,r)=>{r.r(t),r.d(t,{tensorToDataURL:()=>n,tensorToImageData:()=>o});const n=(e,t)=>{const r="undefined"!=typeof document?document.createElement("canvas"):new OffscreenCanvas(1,1);r.width=e.dims[3],r.height=e.dims[2];const n=r.getContext("2d");if(null!=n){let o,s;void 0!==t?.tensorLayout&&"NHWC"===t.tensorLayout?(o=e.dims[2],s=e.dims[3]):(o=e.dims[3],s=e.dims[2]);const a=void 0!==t?.format?t.format:"RGB",i=t?.norm;let l,c;void 0===i||void 0===i.mean?l=[255,255,255,255]:"number"==typeof i.mean?l=[i.mean,i.mean,i.mean,i.mean]:(l=[i.mean[0],i.mean[1],i.mean[2],0],void 0!==i.mean[3]&&(l[3]=i.mean[3])),void 0===i||void 0===i.bias?c=[0,0,0,0]:"number"==typeof i.bias?c=[i.bias,i.bias,i.bias,i.bias]:(c=[i.bias[0],i.bias[1],i.bias[2],0],void 0!==i.bias[3]&&(c[3]=i.bias[3]));const d=s*o;let u=0,p=d,h=2*d,m=-1;"RGBA"===a?(u=0,p=d,h=2*d,m=3*d):"RGB"===a?(u=0,p=d,h=2*d):"RBG"===a&&(u=0,h=d,p=2*d);for(let t=0;t<s;t++)for(let r=0;r<o;r++){const o=(e.data[u++]-c[0])*l[0],s=(e.data[p++]-c[1])*l[1],a=(e.data[h++]-c[2])*l[2],i=-1===m?255:(e.data[m++]-c[3])*l[3];n.fillStyle="rgba("+o+","+s+","+a+","+i+")",n.fillRect(r,t,1,1)}if("toDataURL"in r)return r.toDataURL();throw new Error("toDataURL is not supported")}throw new Error("Can not access image data")},o=(e,t)=>{const r="undefined"!=typeof document?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");let n;if(null==r)throw new Error("Can not access image data");{let o,s,a;void 0!==t?.tensorLayout&&"NHWC"===t.tensorLayout?(o=e.dims[2],s=e.dims[1],a=e.dims[3]):(o=e.dims[3],s=e.dims[2],a=e.dims[1]);const i=void 0!==t&&void 0!==t.format?t.format:"RGB",l=t?.norm;let c,d;void 0===l||void 0===l.mean?c=[255,255,255,255]:"number"==typeof l.mean?c=[l.mean,l.mean,l.mean,l.mean]:(c=[l.mean[0],l.mean[1],l.mean[2],255],void 0!==l.mean[3]&&(c[3]=l.mean[3])),void 0===l||void 0===l.bias?d=[0,0,0,0]:"number"==typeof l.bias?d=[l.bias,l.bias,l.bias,l.bias]:(d=[l.bias[0],l.bias[1],l.bias[2],0],void 0!==l.bias[3]&&(d[3]=l.bias[3]));const u=s*o;if(void 0!==t&&(void 0!==t.format&&4===a&&"RGBA"!==t.format||3===a&&"RGB"!==t.format&&"BGR"!==t.format))throw new Error("Tensor format doesn't match input tensor dims");const p=4;let h=0,m=1,_=2,f=3,g=0,M=u,w=2*u,T=-1;"RGBA"===i?(g=0,M=u,w=2*u,T=3*u):"RGB"===i?(g=0,M=u,w=2*u):"RBG"===i&&(g=0,w=u,M=2*u),n=r.createImageData(o,s);for(let t=0;t<s*o;h+=p,m+=p,_+=p,f+=p,t++)n.data[h]=(e.data[g++]-d[0])*c[0],n.data[m]=(e.data[M++]-d[1])*c[1],n.data[_]=(e.data[w++]-d[2])*c[2],n.data[f]=-1===T?255:(e.data[T++]-d[3])*c[3]}return n}},"./node_modules/onnxruntime-common/dist/esm/tensor-conversion.js": /*!***********************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/tensor-conversion.js ***! \***********************************************************************/(e,t,r)=>{r.r(t)},"./node_modules/onnxruntime-common/dist/esm/tensor-factory-impl.js": /*!*************************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/tensor-factory-impl.js ***! \*************************************************************************/(e,t,r)=>{r.r(t),r.d(t,{bufferToTensor:()=>o,tensorFromGpuBuffer:()=>i,tensorFromImage:()=>s,tensorFromPinnedBuffer:()=>l,tensorFromTexture:()=>a});var n=r(/*! ./tensor-impl.js */"./node_modules/onnxruntime-common/dist/esm/tensor-impl.js");const o=(e,t)=>{if(void 0===e)throw new Error("Image buffer must be defined");if(void 0===t.height||void 0===t.width)throw new Error("Image height and width must be defined");if("NHWC"===t.tensorLayout)throw new Error("NHWC Tensor layout is not supported yet");const{height:r,width:o}=t,s=t.norm??{mean:255,bias:0};let a,i;a="number"==typeof s.mean?[s.mean,s.mean,s.mean,s.mean]:[s.mean[0],s.mean[1],s.mean[2],s.mean[3]??255],i="number"==typeof s.bias?[s.bias,s.bias,s.bias,s.bias]:[s.bias[0],s.bias[1],s.bias[2],s.bias[3]??0];const l=void 0!==t.format?t.format:"RGBA",c=void 0!==t.tensorFormat&&void 0!==t.tensorFormat?t.tensorFormat:"RGB",d=r*o,u="RGBA"===c?new Float32Array(4*d):new Float32Array(3*d);let p=4,h=0,m=1,_=2,f=3,g=0,M=d,w=2*d,T=-1;"RGB"===l&&(p=3,h=0,m=1,_=2,f=-1),"RGBA"===c?T=3*d:"RBG"===c?(g=0,w=d,M=2*d):"BGR"===c&&(w=0,M=d,g=2*d);for(let t=0;t<d;t++,h+=p,_+=p,m+=p,f+=p)u[g++]=(e[h]+i[0])/a[0],u[M++]=(e[m]+i[1])/a[1],u[w++]=(e[_]+i[2])/a[2],-1!==T&&-1!==f&&(u[T++]=(e[f]+i[3])/a[3]);return"RGBA"===c?new n.Tensor("float32",u,[1,4,r,o]):new n.Tensor("float32",u,[1,3,r,o])},s=async(e,t)=>{const r="undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement,n="undefined"!=typeof ImageData&&e instanceof ImageData,s="undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap,a="string"==typeof e;let i,l=t??{};const c=()=>{if("undefined"!=typeof document)return document.createElement("canvas");if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},d=e=>e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext("2d"):null;if(r){const r=c();r.width=e.width,r.height=e.height;const n=d(r);if(null==n)throw new Error("Can not access image data");{let r=e.height,o=e.width;if(void 0!==t&&void 0!==t.resizedHeight&&void 0!==t.resizedWidth&&(r=t.resizedHeight,o=t.resizedWidth),void 0!==t){if(l=t,void 0!==t.tensorFormat)throw new Error("Image input config format must be RGBA for HTMLImageElement");l.tensorFormat="RGBA",l.height=r,l.width=o}else l.tensorFormat="RGBA",l.height=r,l.width=o;n.drawImage(e,0,0),i=n.getImageData(0,0,o,r).data}}else{if(!n){if(s){if(void 0===t)throw new Error("Please provide image config with format for Imagebitmap");const r=c();r.width=e.width,r.height=e.height;const n=d(r);if(null!=n){const t=e.height,r=e.width;return n.drawImage(e,0,0,r,t),i=n.getImageData(0,0,r,t).data,l.height=t,l.width=r,o(i,l)}throw new Error("Can not access image data")}if(a)return new Promise(((t,r)=>{const n=c(),s=d(n);if(!e||!s)return r();const a=new Image;a.crossOrigin="Anonymous",a.src=e,a.onload=()=>{n.width=a.width,n.height=a.height,s.drawImage(a,0,0,n.width,n.height);const e=s.getImageData(0,0,n.width,n.height);l.height=n.height,l.width=n.width,t(o(e.data,l))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{let r,n;if(void 0!==t&&void 0!==t.resizedWidth&&void 0!==t.resizedHeight?(r=t.resizedHeight,n=t.resizedWidth):(r=e.height,n=e.width),void 0!==t&&(l=t),l.format="RGBA",l.height=r,l.width=n,void 0!==t){const t=c();t.width=n,t.height=r;const o=d(t);if(null==o)throw new Error("Can not access image data");o.putImageData(e,0,0),i=o.getImageData(0,0,n,r).data}else i=e.data}}if(void 0!==i)return o(i,l);throw new Error("Input data provided is not supported - aborted tensor creation")},a=(e,t)=>{const{width:r,height:o,download:s,dispose:a}=t,i=[1,o,r,4];return new n.Tensor({location:"texture",type:"float32",texture:e,dims:i,download:s,dispose:a})},i=(e,t)=>{const{dataType:r,dims:o,download:s,dispose:a}=t;return new n.Tensor({location:"gpu-buffer",type:r??"float32",gpuBuffer:e,dims:o,download:s,dispose:a})},l=(e,t,r)=>new n.Tensor({location:"cpu-pinned",type:e,data:t,dims:r??[t.length]})},"./node_modules/onnxruntime-common/dist/esm/tensor-factory.js": /*!********************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/tensor-factory.js ***! \********************************************************************/(e,t,r)=>{r.r(t)},"./node_modules/onnxruntime-common/dist/esm/tensor-impl-type-mapping.js": /*!******************************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/tensor-impl-type-mapping.js ***! \******************************************************************************/(e,t,r)=>{r.r(t),r.d(t,{NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP:()=>o,NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP:()=>n,checkTypedArray:()=>a});const n=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),o=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]);let s=!1;const a=()=>{if(!s){s=!0;const e="undefined"!=typeof BigInt64Array&&BigInt64Array.from,t="undefined"!=typeof BigUint64Array&&BigUint64Array.from,r="undefined"!=typeof Float16Array&&Float16Array.from;e&&(n.set("int64",BigInt64Array),o.set(BigInt64Array,"int64")),t&&(n.set("uint64",BigUint64Array),o.set(BigUint64Array,"uint64")),r?(n.set("float16",Float16Array),o.set(Float16Array,"float16")):n.set("float16",Uint16Array)}}},"./node_modules/onnxruntime-common/dist/esm/tensor-impl.js": /*!*****************************************************************!*\ !*** ./node_modules/onnxruntime-common/dist/esm/tensor-impl.js ***! \*****************************************************************/(e,t,r)=>{r.r(t),r.d(t,{Tensor:()=>i});var n=r(/*! ./tensor-conversion-impl.js */"./node_modules/onnxruntime-common/dist/esm/tensor-conversion-impl.js"),o=r(/*! ./tensor-factory-impl.js */"./node_modules/onnxruntime-common/dist/esm/tensor-factory-impl.js"),s=r(/*! ./tensor-impl-type-mapping.js */"./node_modules/onnxruntime-common/dist/esm/tensor-impl-type-mapping.js"),a=r(/*! ./tensor-utils-impl.js */"./node_modules/onnxruntime-common/dist/esm/tensor-utils-impl.js");class i{constructor(e,t,r){let n,o;if((0,s.checkTypedArray)(),"object"==typeof e&&"location"in e)switch(this.dataLocation=e.location,n=e.type,o=e.dims,e.location){case"cpu-pinned":{const t=s.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(n);if(!t)throw new TypeError(`unsupported type "${n}" to create tensor from pinned buffer`);if(!(e.data instanceof t))throw new TypeError(`buffer should be of type ${t.name}`);this.cpuData=e.data;break}case"texture":if("float32"!==n)thro