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!

4 lines • 432 kB
var Lk=Object.defineProperty;var Os=(t,e)=>{for(var s in e)Lk(t,s,{get:e[s],enumerable:!0})};var Fe={};var Ye={};var Dy={};var $k="4.2.0",Bc=typeof self<"u",Is=!Wy(Fe),By=!Wy(Ye),ra=Bc&&"caches"in self,Fk=typeof globalThis.Deno<"u",BM=typeof globalThis.Bun<"u",oa=Fk&&ra&&!Is,Uy=typeof process<"u",Gy=Uy&&process?.release?.name==="node"&&!oa,Uc=typeof window<"u"&&typeof window.document<"u",Gc=Bc&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),Rk=Uc||Gc||oa,Dk=Gy||typeof navigator<"u"&&"gpu"in navigator,qk=typeof navigator<"u"&&"ml"in navigator,jk=typeof crypto<"u"&&typeof crypto.getRandomValues=="function",Bk=typeof chrome<"u"&&typeof chrome.runtime<"u"&&typeof chrome.runtime.id=="string",Uk=typeof ServiceWorkerGlobalScope<"u"&&Bc&&self instanceof ServiceWorkerGlobalScope,Gk=()=>{if(typeof navigator>"u")return!1;let t=navigator.userAgent,s=(navigator.vendor||"").indexOf("Apple")>-1,r=!t.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i)&&!t.includes("Chrome")&&!t.includes("Android");return s&&r},Wk=Gk(),K=Object.freeze({IS_BROWSER_ENV:Uc,IS_WEBWORKER_ENV:Gc,IS_WEB_ENV:Rk,IS_SERVICE_WORKER_ENV:Uk,IS_DENO_WEB_RUNTIME:oa,IS_WEB_CACHE_AVAILABLE:ra,IS_WEBGPU_AVAILABLE:Dk,IS_WEBNN_AVAILABLE:qk,IS_SAFARI:Wk,IS_PROCESS_AVAILABLE:Uy,IS_NODE_ENV:Gy,IS_FS_AVAILABLE:Is,IS_PATH_AVAILABLE:By,IS_CRYPTO_AVAILABLE:jk,IS_CHROME_AVAILABLE:Bk}),Wc=Is&&By,na="./";if(Wc){let t=Object(import.meta).url;t?na=Ye.dirname(Ye.dirname(Dy.fileURLToPath(t))):typeof __dirname<"u"&&(na=Ye.dirname(__dirname))}var Vk=Wc?Ye.join(na,"/.cache/"):null,qy="/models/",Hk=Wc?Ye.join(na,qy):qy,Kk=typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,Ge=Object.freeze({DEBUG:10,INFO:20,WARNING:30,ERROR:40,NONE:50}),jy=Ge.WARNING,J={version:$k,backends:{onnx:{}},get logLevel(){return jy},set logLevel(t){jy=t,J.backends.onnx?.setLogLevel?.(t)},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(Uc||Gc||oa),localModelPath:Hk,useFS:Is,useBrowserCache:ra,useFSCache:Is,cacheDir:Vk,useCustomCache:!1,customCache:null,useWasmCache:ra||Is,cacheKey:"transformers-cache",experimental_useCrossOriginStorage:!1,fetch:Kk};function Wy(t){return Object.keys(t).length===0}var xe=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}_call(...t){throw Error("Must implement _call method in subclass")}};function _t(t,e){t&&t(e)}var ts=class extends xe{constructor(e,s){super(),this.callback=e,this.files_loading=s}_call(e){if(e.status==="progress"){this.files_loading[e.file]={loaded:e.loaded,total:e.total};let s=Object.values(this.files_loading).reduce((o,i)=>o+i.loaded,0),r=Object.values(this.files_loading).reduce((o,i)=>o+i.total,0),n=r>0?s/r*100:0;this.callback({status:"progress_total",name:e.name,progress:n,loaded:s,total:r,files:structuredClone(this.files_loading)})}this.callback(e)}};function Vy(t){return Number.isInteger(t)||typeof t=="bigint"}function Vc(t){return t==null||t===-1}function Hc(t){let e=[],s=t;for(;Array.isArray(s);)e.push(s.length),s=s[0];return e}function Re(...t){return Array.prototype.concat.apply([],t)}function Hy(...t){return t.reduce((e,s)=>e.flatMap(r=>s.map(n=>[r,n])))}function zs(t,e){return Math.abs((t+e)%(2*e)-e)}function we(t,e){return Object.assign({},...e.map(s=>{if(t[s]!==void 0)return{[s]:t[s]}}))}function Ky(t,e){let s=0;for(let r of t)r===e&&++s;return s}var F={error(...t){J.logLevel<=Ge.ERROR&&console.error(...t)},warn(...t){J.logLevel<=Ge.WARNING&&console.warn(...t)},info(...t){J.logLevel<=Ge.INFO&&console.log(...t)},debug(...t){J.logLevel<=Ge.DEBUG&&console.log(...t)},log(...t){this.info(...t)}};var Xk=class{constructor(t){this.trie=this._build_trie(t)}_build_trie(t){let e=Object.create(null);for(let s of t){let r=e;for(let n=0;n<s.length;++n){let o=s[n];r=r[o]??=Object.create(null)}r.end=s}return e}split(t){let e=[],s=t.length,r=0,n=0;for(;n<s;){let o=this.trie,i=null,a=n;for(;a<s&&(o=o[t[a]]);)o.end&&(i=o.end),++a;i?(n>r&&e.push(t.slice(r,n)),e.push(i),n+=i.length,r=n):++n}return r<s&&e.push(t.slice(r)),e}},Xy=Xk,Qk=class{constructor(t){this.content=t.content,this.id=t.id,this.single_word=t.single_word??!1,this.lstrip=t.lstrip??!1,this.rstrip=t.rstrip??!1,this.special=t.special??!1,this.normalized=t.normalized??!this.special}},Yk=Qk,s0=(()=>{let t=[...Array.from({length:94},(n,o)=>o+33),...Array.from({length:12},(n,o)=>o+161),...Array.from({length:82},(n,o)=>o+174)],e=t.slice(),s=0;for(let n=0;n<256;++n)t.includes(n)||(t.push(n),e.push(256+s),s+=1);let r=e.map(n=>String.fromCharCode(n));return Object.fromEntries(t.map((n,o)=>[n,r[o]]))})(),Jk=t=>Object.fromEntries(Object.entries(t).map(([e,s])=>[s,e])),Zk=Jk(s0),Qy=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",e1=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],["(?i:[sdmt]|ll|ve|re)","(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])"],["[^\\r\\n\\p{L}\\p{N}]?+","[^\\r\\n\\p{L}\\p{N}]?"],["[^\\s\\p{L}\\p{N}]++","[^\\s\\p{L}\\p{N}]+"],["(?>\\p{Nd}{510})","(?:\\p{Nd}{510})"],["\\p{Nd}{3}+","(?:\\p{Nd}{3})+"],["\\G",""],[` ?[^(\\s|[${Qy}])]+`,` ?[^\\s${Qy}]+`]]),ia="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",Xc=t=>t.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n't/g,"n't").replace(/ 'm/g,"'m").replace(/ 's/g,"'s").replace(/ 've/g,"'ve").replace(/ 're/g,"'re"),aa=(t,e=!0)=>{if(t.Regex!==void 0){let s=t.Regex.replace(/\\([#&~])/g,"$1");s=s.replace(/\\A/g,"^").replace(/\\z/g,"$").replace(/\\Z/g,"(?=\\r?\\n?$)");for(let[r,n]of e1)s=s.replaceAll(r,n);try{return new RegExp(s,"gu")}catch(r){if(!(r instanceof SyntaxError)||!r.message.toLowerCase().includes("invalid property name"))throw r;let n=!1,o=s.replace(/(\\[pP])\{([^}=]+)\}/g,(i,a,l)=>{try{return new RegExp(`\\p{${l}}`,"u"),`${a}{${l}}`}catch{return n=!0,`${a}{Script=${l}}`}});if(!n)throw r;try{return new RegExp(o,"gu")}catch{throw r}}}else if(t.String!==void 0){let s=t1(t.String);return new RegExp(e?s:`(${s})`,"gu")}else return console.warn("Unknown pattern type:",t),null},t1=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s1=(t,e,s)=>{let r=[],n=0;for(;n<t.length;){if(r.push(t[n]),(e.get(t[n])??s)!==s){++n;continue}for(;++n<t.length&&(e.get(t[n])??s)===s;)e.get(r.at(-1))!==s&&(r[r.length-1]+=t[n])}return r},r1=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,n1=t=>Number.isInteger(t)||typeof t=="bigint",o1=t=>{let e=0;for(let s of t)++e;return e},i1=t=>r0(t.toLowerCase()),rt=(...t)=>Array.prototype.concat.apply([],t),Qc=t=>new Map(Object.entries(t)),a1=(t,e)=>{let s=[],r=0;for(let n of t.matchAll(e)){let o=n[0];r<n.index&&s.push(t.slice(r,n.index)),o.length>0&&s.push(o),r=n.index+o.length}return r<t.length&&s.push(t.slice(r)),s},r0=t=>t.replace(/\p{M}/gu,""),Yy=(t,e,s=[])=>{if(!t||Array.isArray(t)||typeof t!="object")return`${e} must be a valid object`;for(let r of s)if(!(r in t))return`${e} must contain a "${r}" property`;return null},l1=t=>t.match(/\S+/g)||[],c1=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},Or=c1,p1=class extends Or{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},yt=p1,u1=class extends yt{tokenize_chinese_chars(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s],n=r.charCodeAt(0);r1(n)?(e.push(" "),e.push(r),e.push(" ")):e.push(r)}return e.join("")}strip_accents(t){return t.normalize("NFD").replace(/\p{Mn}/gu,"")}is_control(t){switch(t){case" ":case` `:case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(t)}}clean_text(t){let e=[];for(let s of t){let r=s.charCodeAt(0);r===0||r===65533||this.is_control(s)||(/^\s$/.test(s)?e.push(" "):e.push(s))}return e.join("")}normalize(t){return this.config.clean_text&&(t=this.clean_text(t)),this.config.handle_chinese_chars&&(t=this.tokenize_chinese_chars(t)),this.config.lowercase?(t=t.toLowerCase(),this.config.strip_accents!==!1&&(t=this.strip_accents(t))):this.config.strip_accents&&(t=this.strip_accents(t)),t}},_1=u1,d1=class extends yt{constructor(t){super(t),this.charsmap=t.precompiled_charsmap??null}normalize(t){return t=t.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm,""),t=t.replace(/[\u0009\u000A\u000C\u000D\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u2581\u3000\uFEFF\uFFFD]/gm," "),t.includes("\uFF5E")?t=t.split("\uFF5E").map(s=>s.normalize("NFKC")).join("\uFF5E"):t=t.normalize("NFKC"),t}},f1=d1,m1=class extends yt{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>n0(e))}normalize(t){return this.normalizers.reduce((e,s)=>s?s.normalize(e):e,t)}},h1=m1,g1=class extends yt{normalize(t){let e=aa(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},x1=g1,w1=class extends yt{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},la=w1,y1=class extends la{constructor(){super(...arguments),this.form="NFC"}},b1=y1,k1=class extends la{constructor(){super(...arguments),this.form="NFD"}},v1=k1,E1=class extends la{constructor(){super(...arguments),this.form="NFKC"}},A1=E1,M1=class extends la{constructor(){super(...arguments),this.form="NFKD"}},S1=M1,O1=class extends yt{normalize(t){return this.config.strip_left&&this.config.strip_right?t=t.trim():(this.config.strip_left&&(t=t.trimStart()),this.config.strip_right&&(t=t.trimEnd())),t}},I1=O1,z1=class extends yt{normalize(t){return r0(t)}},T1=z1,C1=class extends yt{normalize(t){return t.toLowerCase()}},P1=C1,N1=class extends yt{normalize(t){return t=this.config.prepend+t,t}},L1=N1;function $1(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new _1(t);case"Precompiled":return new f1(t);case"Sequence":return new h1(t);case"Replace":return new x1(t);case"NFC":return new b1(t);case"NFD":return new v1(t);case"NFKC":return new A1(t);case"NFKD":return new S1(t);case"Strip":return new I1(t);case"StripAccents":return new T1(t);case"Lowercase":return new P1(t);case"Prepend":return new L1(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var n0=$1,F1=class extends Or{pre_tokenize(t,e){return(Array.isArray(t)?t.map(s=>this.pre_tokenize_text(s,e)):this.pre_tokenize_text(t,e)).flat()}_call(t,e){return this.pre_tokenize(t,e)}},nt=F1,R1=class extends nt{constructor(t){super(),this.config=t,this.add_prefix_space=this.config.add_prefix_space??!1,this.trim_offsets=this.config.trim_offsets??!1,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=s0,this.text_encoder=new TextEncoder}pre_tokenize_text(t,e){return this.add_prefix_space&&!t.startsWith(" ")&&(t=" "+t),(this.use_regex?t.match(this.pattern)||[]:[t]).map(r=>Array.from(this.text_encoder.encode(r),n=>this.byte_encoder[n]).join(""))}},D1=R1,q1=class extends nt{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},j1=q1,B1=class extends nt{constructor(t){super(),this.replacement=t.replacement??"\u2581",this.str_rep=t.str_rep||this.replacement,this.prepend_scheme=t.prepend_scheme??"always"}pre_tokenize_text(t,e){let{section_index:s=void 0}=e??{},r=t.replaceAll(" ",this.str_rep);return!r.startsWith(this.replacement)&&(this.prepend_scheme==="always"||this.prepend_scheme==="first"&&s===0)&&(r=this.str_rep+r),[r]}},U1=B1,G1=class extends nt{constructor(t){super(),this.config=t,this.pattern=aa(this.config.pattern??{},this.config.invert??!0)}pre_tokenize_text(t){return this.pattern===null?[]:this.config.invert?t.match(this.pattern)||[]:this.config.behavior?.toLowerCase()==="removed"?t.split(this.pattern).filter(e=>e):a1(t,this.pattern)}},W1=G1,V1=class extends nt{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${ia}]+|[${ia}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},H1=V1,K1=class extends nt{constructor(t){super(),this.config=t;let e=`[^\\d]+|\\d${this.config.individual_digits?"":"+"}`;this.pattern=new RegExp(e,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},X1=K1,Q1=class extends nt{constructor(){super(),this.pattern=new RegExp(`[^\\s${ia}]+|[${ia}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},Y1=Q1,J1=class extends nt{constructor(t){super(),this.config=t,this.pattern=aa(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},Z1=J1,ev=class extends nt{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>o0(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((s,r)=>r?r.pre_tokenize(s,e):s,[t])}},tv=ev,sv=class extends nt{pre_tokenize_text(t){return l1(t)}},rv=sv,nv=class extends nt{constructor(t){super(),this.config=t,this._length=t.length}pre_tokenize_text(t){let e=[];for(let s=0;s<t.length;s+=this._length)e.push(t.slice(s,s+this._length));return e}},ov=nv;function iv(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new Y1;case"Sequence":return new tv(t);case"Whitespace":return new j1;case"WhitespaceSplit":return new rv;case"Metaspace":return new U1(t);case"ByteLevel":return new D1(t);case"Split":return new W1(t);case"Punctuation":return new H1(t);case"Digits":return new X1(t);case"Replace":return new Z1(t);case"FixedLength":return new ov(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var o0=iv,av=class extends Or{constructor(t){super(),this.config=t,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}_call(t){let e=this.encode(t);return this.fuse_unk&&(e=s1(e,this.tokens_to_ids,this.unk_token_id)),e}},ca=av,lv=class extends ca{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=Qc(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.max_input_chars_per_word=t.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(let[e,s]of this.tokens_to_ids)this.vocab[s]=e}encode(t){let e=[];for(let s of t){let r=[...s];if(r.length>this.max_input_chars_per_word){e.push(this.unk_token);continue}let n=!1,o=0,i=[];for(;o<r.length;){let a=r.length,l=null;for(;o<a;){let c=r.slice(o,a).join("");if(o>0&&(c=this.config.continuing_subword_prefix+c),this.tokens_to_ids.has(c)){l=c;break}--a}if(l===null){n=!0;break}i.push(l),o=a}n?e.push(this.unk_token):e.push(...i)}return e}},Jy=lv,Zy=class i0{constructor(e,s){this.is_leaf=e,this.children=s}static default(){return new i0(!1,new Map)}},cv=class{constructor(){this.root=Zy.default()}extend(t){for(let e of t)this.push(e)}push(t){let e=this.root;for(let s of t){let r=e.children.get(s);r===void 0&&(r=Zy.default(),e.children.set(s,r)),e=r}e.is_leaf=!0}*common_prefix_search(t){let e=this.root;if(e===void 0)return;let s="";for(let r of t){if(s+=r,e=e.children.get(r),e===void 0)return;e.is_leaf&&(yield s)}}},pv=cv,Kc=class a0{constructor(e,s,r,n,o){this.token_id=e,this.node_id=s,this.pos=r,this.length=n,this.score=o,this.prev=null,this.backtrace_score=0}clone(){let e=new a0(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},uv=class{constructor(t,e,s){this.chars=Array.from(t),this.len=this.chars.length,this.bos_token_id=e,this.eos_token_id=s,this.nodes=[],this.begin_nodes=Array.from({length:this.len+1},()=>[]),this.end_nodes=Array.from({length:this.len+1},()=>[]);let r=new Kc(this.bos_token_id??0,0,0,0,0),n=new Kc(this.eos_token_id??0,1,this.len,0,0);this.nodes.push(r.clone()),this.nodes.push(n.clone()),this.begin_nodes[this.len].push(n),this.end_nodes[0].push(r)}insert(t,e,s,r){let n=this.nodes.length,o=new Kc(r,n,t,e,s);this.begin_nodes[t].push(o),this.end_nodes[t+e].push(o),this.nodes.push(o)}viterbi(){let t=this.len,e=0;for(;e<=t;){if(this.begin_nodes[e].length==0)return[];for(let i of this.begin_nodes[e]){i.prev=null;let a=0,l=null;for(let c of this.end_nodes[e]){let p=c.backtrace_score+i.score;(l===null||p>a)&&(l=c.clone(),a=p)}if(l!==null)i.prev=l,i.backtrace_score=a;else return[]}++e}let s=[],n=this.begin_nodes[t][0].prev;if(n===null)return[];let o=n.clone();for(;o.prev!==null;)s.push(o.clone()),o=o.clone().prev.clone();return s.reverse(),s}piece(t){return this.chars.slice(t.pos,t.pos+t.length).join("")}tokens(){return this.viterbi().map(e=>this.piece(e))}token_ids(){return this.viterbi().map(e=>e.token_id)}},_v=uv;function dv(t){if(t.length===0)throw new Error("Array must not be empty");let e=t[0],s=0;for(let r=1;r<t.length;++r)t[r]<e&&(e=t[r],s=r);return[e,s]}var fv=class extends ca{constructor(t,e){super(t);let s=t.vocab.length;this.vocab=new Array(s),this.scores=new Array(s);for(let r=0;r<s;++r)[this.vocab[r],this.scores[r]]=t.vocab[r];this.unk_token_id=t.unk_id,this.unk_token=this.vocab[t.unk_id],this.tokens_to_ids=new Map(this.vocab.map((r,n)=>[r,n])),this.bos_token=" ",this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.min_score=dv(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new pv,this.trie.extend(this.vocab),this.fuse_unk=!0}populate_nodes(t){let e=t.chars,s=1,r=0;for(;r<e.length;){let n=!1,o=[],i=e.slice(r).join(""),a=this.trie.common_prefix_search(i);for(let l of a){o.push(l);let c=this.tokens_to_ids.get(l),p=this.scores[c],u=o1(l);t.insert(r,u,p,c),!n&&u===s&&(n=!0)}n||t.insert(r,s,this.unk_score,this.unk_token_id),r+=s}}tokenize(t){let e=new _v(t,this.bos_token_id,this.eos_token_id);return this.populate_nodes(e),e.tokens()}encode(t){let e=[];for(let s of t){let r=this.tokenize(s);e.push(...r)}return e}},e0=fv,mv=class{constructor(t=(s,r)=>s>r,e=1/0){this._heap=[],this._comparator=t,this._max_size=e}get size(){return this._heap.length}is_empty(){return this.size===0}peek(){return this._heap[0]}push(...t){return this.extend(t)}extend(t){for(let e of t)if(this.size<this._max_size)this._heap.push(e),this._sift_up();else{let s=this._smallest();this._comparator(e,this._heap[s])&&(this._heap[s]=e,this._sift_up_from(s))}return this.size}pop(){let t=this.peek(),e=this.size-1;return e>0&&this._swap(0,e),this._heap.pop(),this._sift_down(),t}replace(t){let e=this.peek();return this._heap[0]=t,this._sift_down(),e}_parent(t){return(t+1>>>1)-1}_left(t){return(t<<1)+1}_right(t){return t+1<<1}_greater(t,e){return this._comparator(this._heap[t],this._heap[e])}_swap(t,e){let s=this._heap[t];this._heap[t]=this._heap[e],this._heap[e]=s}_sift_up(){this._sift_up_from(this.size-1)}_sift_up_from(t){for(;t>0&&this._greater(t,this._parent(t));)this._swap(t,this._parent(t)),t=this._parent(t)}_sift_down(){let t=0;for(;this._left(t)<this.size&&this._greater(this._left(t),t)||this._right(t)<this.size&&this._greater(this._right(t),t);){let e=this._right(t)<this.size&&this._greater(this._right(t),this._left(t))?this._right(t):this._left(t);this._swap(t,e),t=e}}_smallest(){return 2**Math.floor(Math.log2(this.size))-1}},hv=mv,gv=class{constructor(t){this.capacity=t,this.cache=new Map}get(t){if(!this.cache.has(t))return;let e=this.cache.get(t);return this.cache.delete(t),this.cache.set(t,e),e}put(t,e){this.cache.has(t)&&this.cache.delete(t),this.cache.set(t,e),this.cache.size>this.capacity&&this.cache.delete(this.cache.keys().next().value)}clear(){this.cache.clear()}},xv=gv,wv=class extends ca{constructor(t){super(t),this.tokens_to_ids=Qc(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(let[s,r]of this.tokens_to_ids)this.vocab[r]=s;let e=Array.isArray(t.merges[0]);this.merges=e?t.merges:t.merges.map(s=>s.split(" ",2)),this.bpe_ranks=new Map(this.merges.map((s,r)=>[JSON.stringify(s),r])),this.end_of_word_suffix=t.end_of_word_suffix,this.continuing_subword_suffix=t.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.max_length_to_cache=256,this.cache_capacity=1e4,this.cache=new xv(this.cache_capacity)}clear_cache(){this.cache.clear()}bpe(t){if(t.length===0)return[];let e=this.cache.get(t);if(e!==void 0)return e;let s=Array.from(t);this.end_of_word_suffix&&(s[s.length-1]+=this.end_of_word_suffix);let r=[];if(s.length>1){let n=new hv((a,l)=>a.score<l.score),o={token:s[0],bias:0,prev:null,next:null},i=o;for(let a=1;a<s.length;++a){let l={bias:a/s.length,token:s[a],prev:i,next:null};i.next=l,this.add_node(n,i),i=l}for(;!n.is_empty();){let a=n.pop();if(a.deleted||!a.next||a.next.deleted)continue;if(a.deleted=!0,a.next.deleted=!0,a.prev){let c={...a.prev};a.prev.deleted=!0,a.prev=c,c.prev?c.prev.next=c:o=c}let l={token:a.token+a.next.token,bias:a.bias,prev:a.prev,next:a.next.next};l.prev?(l.prev.next=l,this.add_node(n,l.prev)):o=l,l.next&&(l.next.prev=l,this.add_node(n,l))}for(let a=o;a!==null;a=a.next)r.push(a.token)}else r=s;if(this.continuing_subword_suffix)for(let n=0;n<r.length-1;++n)r[n]+=this.continuing_subword_suffix;return t.length<this.max_length_to_cache&&this.cache.put(t,r),r}add_node(t,e){let s=this.bpe_ranks.get(JSON.stringify([e.token,e.next.token]));s!==void 0&&(e.score=s+e.bias,t.push(e))}encode(t){let e=[];for(let s of t){if(this.ignore_merges&&this.tokens_to_ids.has(s)){e.push(s);continue}let r=this.bpe(s);for(let n of r)if(this.tokens_to_ids.has(n))e.push(n);else if(this.byte_fallback){let o=Array.from(this.text_encoder.encode(n)).map(i=>`<0x${i.toString(16).toUpperCase().padStart(2,"0")}>`);o.every(i=>this.tokens_to_ids.has(i))?e.push(...o):this.unk_token!=null&&e.push(this.unk_token)}else this.unk_token!=null&&e.push(this.unk_token)}return e}},t0=wv,yv=class extends ca{constructor(t,e){super(t);let s=t.vocab;this.tokens_to_ids=Qc(e.target_lang?s[e.target_lang]:s),this.bos_token=e.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=e.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=e.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(let[r,n]of this.tokens_to_ids)this.vocab[n]=r}encode(t){return t}},bv=yv;function kv(t,e){switch(t.type){case"WordPiece":return new Jy(t);case"Unigram":return new e0(t,e.eos_token);case"BPE":return new t0(t);default:if(t.vocab)return Array.isArray(t.vocab)?new e0(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new t0(t):new Jy(t):new bv(t,{target_lang:e.target_lang,bos_token:e.bos_token,eos_token:e.eos_token,pad_token:e.pad_token,unk_token:e.unk_token});throw new Error(`Unknown TokenizerModel type: ${t?.type}`)}}var vv=kv,Ev=class extends Or{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},Ir=Ev,Av=class extends Ir{post_process(t,e=null,s=!0){let r=e===null?this.config.single:this.config.pair,n=[],o=[];for(let i of r)"SpecialToken"in i?s&&(n.push(i.SpecialToken.id),o.push(i.SpecialToken.type_id)):"Sequence"in i&&(i.Sequence.id==="A"?(n=rt(n,t),o=rt(o,new Array(t.length).fill(i.Sequence.type_id))):i.Sequence.id==="B"&&(n=rt(n,e),o=rt(o,new Array(e.length).fill(i.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},Mv=Av,Sv=class extends Ir{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},Ov=Sv,Iv=class extends Ir{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,s=!0){s&&(t=rt([this.cls[0]],t,[this.sep[0]]));let r=new Array(t.length).fill(0);if(e){let n=[],o=s?[this.sep[0]]:[];t=rt(t,n,e,o),r=rt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},zv=Iv,Tv=class extends Ir{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,s=!0){s&&(t=rt([this.cls[0]],t,[this.sep[0]]));let r=new Array(t.length).fill(0);if(e){let n=s?[this.sep[0]]:[],o=s?[this.sep[0]]:[];t=rt(t,n,e,o),r=rt(r,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:r}}},Cv=Tv,Pv=class extends Ir{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>l0(e))}post_process(t,e=null,s=!0){let r={tokens:t,tokens_pair:e};for(let n of this.processors)r=n.post_process(r.tokens,r.tokens_pair,s);return r}},Nv=Pv;function Lv(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new Mv(t);case"ByteLevel":return new Ov(t);case"BertProcessing":return new zv(t);case"RobertaProcessing":return new Cv(t);case"Sequence":return new Nv(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var l0=Lv,$v=class extends Or{constructor(t){super(),this.config=t,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets="trim_offsets"in t?t.trim_offsets:!1}_call(t){return this.decode(t)}decode(t){return this.decode_chain(t).join("")}},Je=$v,Fv=class extends Je{constructor(t){super(t),this.byte_decoder=Zk,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(t){let e=t.join(""),s=new Uint8Array([...e].map(r=>this.byte_decoder[r]));return this.text_decoder.decode(s)}decode_chain(t){let e=[],s=[];for(let r of t)this.added_tokens.find(n=>n.content===r)!==void 0?(s.length>0&&(e.push(this.convert_tokens_to_string(s)),s=[]),e.push(r)):s.push(r);return s.length>0&&e.push(this.convert_tokens_to_string(s)),e}},Rv=Fv,Dv=class extends Je{constructor(t){super(t),this.cleanup=t.cleanup}decode_chain(t){return t.map((e,s)=>{if(s!==0){let r=this.config.prefix;r&&e.startsWith(r)?e=e.replace(r,""):e=" "+e}return this.cleanup&&(e=Xc(e)),e})}},qv=Dv,jv=class extends Je{constructor(t){super(t),this.replacement=t.replacement??"\u2581"}decode_chain(t){let e=[];for(let s=0;s<t.length;++s){let r=t[s].replaceAll(this.replacement," ");s==0&&r.startsWith(" ")&&(r=r.substring(1)),e.push(r)}return e}},Bv=jv,Uv=class extends Je{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,s)=>e.replaceAll(this.suffix,s===t.length-1?"":" "))}},Gv=Uv,Wv=class extends Je{constructor(t){super(t),this.pad_token=t.pad_token??"",this.word_delimiter_token=t.word_delimiter_token??"",this.cleanup=t.cleanup}convert_tokens_to_string(t){if(t.length===0)return"";let e=[t[0]];for(let n=1;n<t.length;++n)t[n]!==e.at(-1)&&e.push(t[n]);let r=e.filter(n=>n!==this.pad_token).join("");return this.cleanup&&(r=Xc(r).replaceAll(this.word_delimiter_token," ").trim()),r}decode_chain(t){return[this.convert_tokens_to_string(t)]}},Vv=Wv,Hv=class extends Je{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>c0(e))}decode_chain(t){return this.decoders.reduce((e,s)=>s.decode_chain(e),t)}},Kv=Hv,Xv=class extends Je{decode_chain(t){let e=aa(this.config.pattern),s=this.config.content??"";return e===null?t:t.map(r=>r.replaceAll(e,s))}},Qv=Xv,Yv=class extends Je{decode_chain(t){return[t.join("")]}},Jv=Yv,Zv=class extends Je{constructor(t){super(t),this.content=t.content??"",this.start=t.start??0,this.stop=t.stop??0}decode_chain(t){return t.map(e=>{let s=0;for(let n=0;n<this.start&&e[n]===this.content;++n){s=n+1;continue}let r=e.length;for(let n=0;n<this.stop;++n){let o=e.length-n-1;if(e[o]===this.content){r=o;continue}else break}return e.slice(s,r)})}},eE=Zv,tE=class extends Je{constructor(t){super(t),this.text_decoder=new TextDecoder}decode_chain(t){let e=[],s=[];for(let r of t){let n=null;if(r.length===6&&r.startsWith("<0x")&&r.endsWith(">")){let o=parseInt(r.slice(3,5),16);isNaN(o)||(n=o)}if(n!==null)s.push(n);else{if(s.length>0){let o=this.text_decoder.decode(Uint8Array.from(s));e.push(o),s=[]}e.push(r)}}if(s.length>0){let r=this.text_decoder.decode(Uint8Array.from(s));e.push(r),s=[]}return e}},sE=tE;function rE(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new Rv(t);case"WordPiece":return new qv(t);case"Metaspace":return new Bv(t);case"BPEDecoder":return new Gv(t);case"CTC":return new Vv(t);case"Sequence":return new Kv(t);case"Replace":return new Qv(t);case"Fuse":return new Jv(t);case"Strip":return new eE(t);case"ByteFallback":return new sE(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var c0=rE,nE=class{constructor(t,e){let s=Yy(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(s)throw new Error(s);let r=Yy(e,"Config");if(r)throw new Error(r);this.tokenizer=t,this.config=e,this.normalizer=n0(this.tokenizer.normalizer),this.pre_tokenizer=o0(this.tokenizer.pre_tokenizer),this.model=vv(this.tokenizer.model,this.config),this.post_processor=l0(this.tokenizer.post_processor),this.decoder=c0(this.tokenizer.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];let n=[],o=[];this.added_tokens_map=new Map;for(let i of this.tokenizer.added_tokens){let a=new Yk(i);if(this.added_tokens.push(a),this.model.tokens_to_ids.set(a.content,a.id),this.model.vocab[a.id]=a.content,a.special&&(this.special_tokens.push(a.content),this.all_special_ids.push(a.id)),this.added_tokens_map.set(a.content,a),a.normalized&&this.normalizer!==null){let l=this.normalizer(a.content);o.push(l),this.added_tokens_map.set(l,a)}else n.push(a.content)}(this.config.additional_special_tokens??[]).forEach(i=>{this.special_tokens.includes(i)||this.special_tokens.push(i)}),this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.splitter_unnormalized=new Xy(n),this.splitter_normalized=new Xy(o),this.remove_space=this.config.remove_space,this.clean_up_tokenization_spaces=this.config.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=this.config.do_lowercase_and_remove_accent??!1}encode(t,{text_pair:e=null,add_special_tokens:s=!0,return_token_type_ids:r=null}={}){let{tokens:n,token_type_ids:o}=this.tokenize_helper(t,{text_pair:e,add_special_tokens:s}),i=n.map(l=>this.added_tokens_map.get(l)?.id??this.model.tokens_to_ids.get(l)??this.model.unk_token_id),a={ids:i,tokens:n,attention_mask:new Array(i.length).fill(1)};return r&&o&&(a.token_type_ids=o),a}decode(t,e={}){if(!Array.isArray(t)||t.length===0||!n1(t[0]))throw Error("token_ids must be a non-empty array of integers.");let s=t.map(n=>this.model.vocab[Number(n)]??this.model.unk_token);e.skip_special_tokens&&(s=s.filter(n=>!this.special_tokens.includes(n)));let r=this.decoder?this.decoder(s):s.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(r=r.replaceAll(this.decoder.end_of_word_suffix," "),e.skip_special_tokens&&(r=r.trim())),(e.clean_up_tokenization_spaces??this.clean_up_tokenization_spaces)&&(r=Xc(r)),r}tokenize(t,{text_pair:e=null,add_special_tokens:s=!1}={}){return this.tokenize_helper(t,{text_pair:e,add_special_tokens:s}).tokens}encode_text(t){if(t===null)return null;let e=this.splitter_unnormalized.split(t);return e.forEach((s,r)=>{let n=this.added_tokens_map.get(s);n&&(n.lstrip&&r>0&&(e[r-1]=e[r-1].trimEnd()),n.rstrip&&r<e.length-1&&(e[r+1]=e[r+1].trimStart()))}),e.flatMap((s,r)=>{if(s.length===0)return[];if(this.added_tokens_map.has(s))return[s];if(this.remove_space===!0&&(s=s.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(s=i1(s)),this.normalizer!==null&&(s=this.normalizer(s)),s.length===0)return[];let n=this.splitter_normalized.split(s);return n.forEach((o,i)=>{let a=this.added_tokens_map.get(o);a&&(a.lstrip&&i>0&&(n[i-1]=n[i-1].trimEnd()),a.rstrip&&i<n.length-1&&(n[i+1]=n[i+1].trimStart()))}),n.flatMap(o=>{if(o.length===0)return[];if(this.added_tokens_map.has(o))return[o];let i=this.pre_tokenizer!==null?this.pre_tokenizer(o,{section_index:r}):[o];return this.model(i)})})}tokenize_helper(t,{text_pair:e=null,add_special_tokens:s=!0}){let r=this.encode_text(t),n=this.encode_text(e||null);return this.post_processor?this.post_processor(r,n,s):{tokens:rt(r??[],n??[])}}token_to_id(t){return this.model.tokens_to_ids.get(t)}id_to_token(t){return this.model.vocab[t]}get_added_tokens_decoder(){let t=new Map;for(let e of this.added_tokens)t.set(e.id,e);return t}get_vocab(t=!0){let e=new Map;for(let s=0;s<this.model.vocab.length;++s){let r=this.model.vocab[s];(t||!this.added_tokens_map.has(r))&&e.set(r,s)}return e}},p0=nE;var M=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",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",Comment:"Comment"}),Ze=class{constructor(t,e){this.value=t,this.type=e}};function u0(t){return/\w/.test(t)}function zr(t){return/[0-9]/.test(t)}function _0(t){return/\s/.test(t)}var oE=[["{%",M.OpenStatement],["%}",M.CloseStatement],["{{",M.OpenExpression],["}}",M.CloseExpression],["(",M.OpenParen],[")",M.CloseParen],["{",M.OpenCurlyBracket],["}",M.CloseCurlyBracket],["[",M.OpenSquareBracket],["]",M.CloseSquareBracket],[",",M.Comma],[".",M.Dot],[":",M.Colon],["|",M.Pipe],["<=",M.ComparisonBinaryOperator],[">=",M.ComparisonBinaryOperator],["==",M.ComparisonBinaryOperator],["!=",M.ComparisonBinaryOperator],["<",M.ComparisonBinaryOperator],[">",M.ComparisonBinaryOperator],["+",M.AdditiveBinaryOperator],["-",M.AdditiveBinaryOperator],["~",M.AdditiveBinaryOperator],["*",M.MultiplicativeBinaryOperator],["/",M.MultiplicativeBinaryOperator],["%",M.MultiplicativeBinaryOperator],["=",M.Equals]],iE=new Map([["n",` `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function aE(t,e={}){return t.endsWith(` `)&&(t=t.slice(0,-1)),e.lstrip_blocks&&(t=t.replace(/^[ \t]*({[#%-])/gm,"$1")),e.trim_blocks&&(t=t.replace(/([#%-]})\n/g,"$1")),t.replace(/{%\s*(end)?generation\s*%}/gs,"")}function lE(t,e={}){let s=[],r=aE(t,e),n=0,o=0,i=c=>{let p="";for(;c(r[n]);){if(r[n]==="\\"){if(++n,n>=r.length)throw new SyntaxError("Unexpected end of input");let u=r[n++],_=iE.get(u);if(_===void 0)throw new SyntaxError(`Unexpected escaped character: ${u}`);p+=_;continue}if(p+=r[n++],n>=r.length)throw new SyntaxError("Unexpected end of input")}return p},a=()=>{let c=s.at(-1);c&&c.type===M.Text&&(c.value=c.value.trimEnd(),c.value===""&&s.pop())},l=()=>{for(;n<r.length&&_0(r[n]);)++n};e:for(;n<r.length;){let c=s.at(-1)?.type;if(c===void 0||c===M.CloseStatement||c===M.CloseExpression||c===M.Comment){let u="";for(;n<r.length&&!(r[n]==="{"&&(r[n+1]==="%"||r[n+1]==="{"||r[n+1]==="#"));)u+=r[n++];if(u.length>0){s.push(new Ze(u,M.Text));continue}}if(r[n]==="{"&&r[n+1]==="#"){n+=2;let u=r[n]==="-";u&&++n;let _="";for(;r[n]!=="#"||r[n+1]!=="}";){if(n+2>=r.length)throw new SyntaxError("Missing end of comment tag");_+=r[n++]}let d=_.endsWith("-");d&&(_=_.slice(0,-1)),u&&a(),s.push(new Ze(_,M.Comment)),n+=2,d&&l();continue}if(r.slice(n,n+3)==="{%-"){a(),s.push(new Ze("{%",M.OpenStatement)),n+=3;continue}if(r.slice(n,n+3)==="{{-"){a(),s.push(new Ze("{{",M.OpenExpression)),o=0,n+=3;continue}if(i(_0),r.slice(n,n+3)==="-%}"){s.push(new Ze("%}",M.CloseStatement)),n+=3,l();continue}if(r.slice(n,n+3)==="-}}"){s.push(new Ze("}}",M.CloseExpression)),n+=3,l();continue}let p=r[n];if(p==="-"||p==="+"){let u=s.at(-1)?.type;if(u===M.Text||u===void 0)throw new SyntaxError(`Unexpected character: ${p}`);switch(u){case M.Identifier:case M.NumericLiteral:case M.StringLiteral:case M.CloseParen:case M.CloseSquareBracket:break;default:{++n;let _=i(zr);s.push(new Ze(`${p}${_}`,_.length>0?M.NumericLiteral:M.UnaryOperator));continue}}}for(let[u,_]of oE){if(u==="}}"&&o>0)continue;if(r.slice(n,n+u.length)===u){s.push(new Ze(u,_)),_===M.OpenExpression?o=0:_===M.OpenCurlyBracket?++o:_===M.CloseCurlyBracket&&--o,n+=u.length;continue e}}if(p==="'"||p==='"'){++n;let u=i(_=>_!==p);s.push(new Ze(u,M.StringLiteral)),++n;continue}if(zr(p)){let u=i(zr);if(r[n]==="."&&zr(r[n+1])){++n;let _=i(zr);u=`${u}.${_}`}s.push(new Ze(u,M.NumericLiteral));continue}if(u0(p)){let u=i(u0);s.push(new Ze(u,M.Identifier));continue}throw new SyntaxError(`Unexpected character: ${p}`)}return s}var it=class{type="Statement"},cE=class extends it{constructor(t){super(),this.body=t}type="Program"},pE=class extends it{constructor(t,e,s){super(),this.test=t,this.body=e,this.alternate=s}type="If"},uE=class extends it{constructor(t,e,s,r){super(),this.loopvar=t,this.iterable=e,this.body=s,this.defaultBlock=r}type="For"},_E=class extends it{type="Break"},dE=class extends it{type="Continue"},fE=class extends it{constructor(t,e,s){super(),this.assignee=t,this.value=e,this.body=s}type="Set"},mE=class extends it{constructor(t,e,s){super(),this.name=t,this.args=e,this.body=s}type="Macro"},hE=class extends it{constructor(t){super(),this.value=t}type="Comment"},Ke=class extends it{type="Expression"},gE=class extends Ke{constructor(t,e,s){super(),this.object=t,this.property=e,this.computed=s}type="MemberExpression"},d0=class extends Ke{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},Ts=class extends Ke{constructor(t){super(),this.value=t}type="Identifier"},Cs=class extends Ke{constructor(t){super(),this.value=t}type="Literal"},xE=class extends Cs{type="IntegerLiteral"},wE=class extends Cs{type="FloatLiteral"},f0=class extends Cs{type="StringLiteral"},yE=class extends Cs{type="ArrayLiteral"},m0=class extends Cs{type="TupleLiteral"},bE=class extends Cs{type="ObjectLiteral"},Tr=class extends Ke{constructor(t,e,s){super(),this.operator=t,this.left=e,this.right=s}type="BinaryExpression"},kE=class extends Ke{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},vE=class extends it{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},EE=class extends Ke{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},AE=class extends Ke{constructor(t,e,s){super(),this.operand=t,this.negate=e,this.test=s}type="TestExpression"},ME=class extends Ke{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},SE=class extends Ke{constructor(t=void 0,e=void 0,s=void 0){super(),this.start=t,this.stop=e,this.step=s}type="SliceExpression"},OE=class extends Ke{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},IE=class extends Ke{constructor(t){super(),this.argument=t}type="SpreadExpression"},zE=class extends it{constructor(t,e,s){super(),this.call=t,this.callerArgs=e,this.body=s}type="CallStatement"},TE=class extends Ke{constructor(t,e,s){super(),this.condition=t,this.trueExpr=e,this.falseExpr=s}type="Ternary"};function CE(t){let e=new cE([]),s=0;function r(A,O){let T=t[s++];if(!T||T.type!==A)throw new Error(`Parser Error: ${O}. ${T.type} !== ${A}.`);return T}function n(A){if(!l(A))throw new SyntaxError(`Expected ${A}`);++s}function o(){switch(t[s].type){case M.Comment:return new hE(t[s++].value);case M.Text:return c();case M.OpenStatement:return p();case M.OpenExpression:return u();default:throw new SyntaxError(`Unexpected token type: ${t[s].type}`)}}function i(...A){return s+A.length<=t.length&&A.every((O,T)=>O===t[s+T].type)}function a(...A){return t[s]?.type===M.OpenStatement&&t[s+1]?.type===M.Identifier&&A.includes(t[s+1]?.value)}function l(...A){return s+A.length<=t.length&&A.every((O,T)=>t[s+T].type==="Identifier"&&O===t[s+T].value)}function c(){return new f0(r(M.Text,"Expected text token").value)}function p(){if(r(M.OpenStatement,"Expected opening statement token"),t[s].type!==M.Identifier)throw new SyntaxError(`Unknown statement, got ${t[s].type}`);let A=t[s].value,O;switch(A){case"set":++s,O=_();break;case"if":++s,O=d(),r(M.OpenStatement,"Expected {% token"),n("endif"),r(M.CloseStatement,"Expected %} token");break;case"macro":++s,O=m(),r(M.OpenStatement,"Expected {% token"),n("endmacro"),r(M.CloseStatement,"Expected %} token");break;case"for":++s,O=g(),r(M.OpenStatement,"Expected {% token"),n("endfor"),r(M.CloseStatement,"Expected %} token");break;case"call":{++s;let T=null;i(M.OpenParen)&&(T=C());let G=D();if(G.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let ee=C();r(M.CloseStatement,"Expected closing statement token");let $e=[];for(;!a("endcall");)$e.push(o());r(M.OpenStatement,"Expected '{%'"),n("endcall"),r(M.CloseStatement,"Expected closing statement token");let re=new d0(G,ee);O=new zE(re,T,$e);break}case"break":++s,r(M.CloseStatement,"Expected closing statement token"),O=new _E;break;case"continue":++s,r(M.CloseStatement,"Expected closing statement token"),O=new dE;break;case"filter":{++s;let T=D();T instanceof Ts&&i(M.OpenParen)&&(T=$(T)),r(M.CloseStatement,"Expected closing statement token");let G=[];for(;!a("endfilter");)G.push(o());r(M.OpenStatement,"Expected '{%'"),n("endfilter"),r(M.CloseStatement,"Expected '%}'"),O=new vE(T,G);break}default:throw new SyntaxError(`Unknown statement type: ${A}`)}return O}function u(){r(M.OpenExpression,"Expected opening expression token");let A=w();return r(M.CloseExpression,"Expected closing expression token"),A}function _(){let A=f(),O=null,T=[];if(i(M.Equals))++s,O=f();else{for(r(M.CloseStatement,"Expected %} token");!a("endset");)T.push(o());r(M.OpenStatement,"Expected {% token"),n("endset")}return r(M.CloseStatement,"Expected closing statement token"),new fE(A,O,T)}function d(){let A=w();r(M.CloseStatement,"Expected closing statement token");let O=[],T=[];for(;!a("elif","else","endif");)O.push(o());if(a("elif")){++s,++s;let G=d();T.push(G)}else if(a("else"))for(++s,++s,r(M.CloseStatement,"Expected closing statement token");!a("endif");)T.push(o());return new pE(A,O,T)}function m(){let A=D();if(A.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let O=C();r(M.CloseStatement,"Expected closing statement token");let T=[];for(;!a("endmacro");)T.push(o());return new mE(A,O,T)}function f(A=!1){let O=A?D:w,T=[O()],G=i(M.Comma);for(;G&&(++s,T.push(O()),!!i(M.Comma)););return G?new m0(T):T[0]}function g(){let A=f(!0);if(!(A instanceof Ts||A instanceof m0))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${A.type} instead`);if(!l("in"))throw new SyntaxError("Expected `in` keyword following loop variable");++s;let O=w();r(M.CloseStatement,"Expected closing statement token");let T=[];for(;!a("endfor","else");)T.push(o());let G=[];if(a("else"))for(++s,++s,r(M.CloseStatement,"Expected closing statement token");!a("endfor");)G.push(o());return new uE(A,O,T,G)}function w(){return x()}function x(){let A=y();if(l("if")){++s;let O=y();if(l("else")){++s;let T=x();return new TE(O,A,T)}else return new EE(A,O)}return A}function y(){let A=b();for(;l("or");){let O=t[s];++s;let T=b();A=new Tr(O,A,T)}return A}function b(){let A=v();for(;l("and");){let O=t[s];++s;let T=v();A=new Tr(O,A,T)}return A}function v(){let A;for(;l("not");){let O=t[s];++s;let T=v();A=new ME(O,T)}return A??k()}function k(){let A=S();for(;;){let O;if(l("not","in"))O=new Ze("not in",M.Identifier),s+=2;else if(l("in"))O=t[s++];else if(i(M.ComparisonBinaryOperator))O=t[s++];else break;let T=S();A=new Tr(O,A,T)}return A}function S(){let A=j();for(;i(M.AdditiveBinaryOperator);){let O=t[s];++s;let T=j();A=new Tr(O,A,T)}return A}function I(){let A=H(D());return i(M.OpenParen)?$(A):A}function $(A){let O=new d0(A,C());return O=H(O),i(M.OpenParen)&&(O=$(O)),O}function C(){r(M.OpenParen,"Expected opening parenthesis for arguments list");let A=R();return r(M.CloseParen,"Expected closing parenthesis for arguments list"),A}function R(){let A=[];for(;!i(M.CloseParen);){let O;if(t[s].type===M.MultiplicativeBinaryOperator&&t[s].value==="*"){++s;let T=w();O=new IE(T)}else if(O=w(),i(M.Equals)){if(++s,!(O instanceof Ts))throw new SyntaxError("Expected identifier for keyword argument");let T=w();O=new OE(O,T)}A.push(O),i(M.Comma)&&++s}return A}function V(){let A=[],O=!1;for(;!i(M.CloseSquareBracket);)i(M.Colon)?(A.push(void 0),++s,O=!0):(A.push(w()),i(M.Colon)&&(++s,O=!0));if(A.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if(O){if(A.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new SE(...A)}return A[0]}function H(A){for(;i(M.Dot)||i(M.OpenSquareBracket);){let O=t[s];++s;let T,G=O.type===M.OpenSquareBracket;if(G)T=V(),r(M.CloseSquareBracket,"Expected closing square bracket");else if(T=D(),T.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");A=new gE(A,T,G)}return A}function j(){let A=B();for(;i(M.MultiplicativeBinaryOperator);){let O=t[s++],T=B();A=new Tr(O,A,T)}return A}function B(){let A=Z();for(;l("is");){++s;let O=l("not");O&&++s;let T=D();if(!(T instanceof Ts))throw new SyntaxError("Expected identifier for the test");A=new AE(A,O,T)}return A}function Z(){let A=I();for(;i(M.Pipe);){++s;let O=D();if(!(O instanceof Ts))throw new SyntaxError("Expected identifier for the filter");i(M.OpenParen)&&(O=$(O)),A=new kE(A,O)}return A}function D(){let A=t[s++];switch(A.type){case M.NumericLiteral:{let O=A.value;return O.includes(".")?new wE(Number(O)):new xE(Number(O))}case M.StringLiteral:{let O=A.value;for(;i(M.StringLiteral);)O+=t[s++].value;return new f0(O)}case M.Identifier:return new Ts(A.value);case M.OpenParen:{let O=f();return r(M.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),O}case M.OpenSquareBracket:{let O=[];for(;!i(M.CloseSquareBracket);)O.push(w()),i(M.Comma)&&++s;return++s,new yE(O)}case M.OpenCurlyBracket:{let O=new Map;for(;!i(M.CloseCurlyBracket);){let T=w();r(M.Colon,"Expected colon between key and value in object literal");let G=w();O.set(T,G),i(M.Comma)&&++s}return++s,new bE(O)}default:throw new SyntaxError(`Unexpected token: ${A.type}`)}}for(;s<t.length;)e.body.push(o());return e}function PE(t,e,s=1){if(e===void 0&&(e=t,t=0),s===0)throw new Error("range() step must not be zero");let r=[];if(s>0)for(let n=t;n<e;n+=s)r.push(n);else for(let n=t;n>e;n+=s)r.push(n);return r}function h0(t,e,s,r=1){let n=Math.sign(r);n>=0?(e=(e??=0)<0?Math.max(t.length+e,0):Math.min(e,t.length),s=(s??=t.length)<0?Math.max(t.length+s,0):Math.min(s,t.length)):(e=(e??=t.length-1)<0?Math.max(t.length+e,-1):Math.min(e,t.length-1),s=(s??=-1)<-1?Math.max(t.length+s,-1):Math.min(s,t.length-1));let o=[];for(let i=e;n*i<n*s;i+=r)o.push(t[i]);return o}function NE(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function LE(t){return $E(new Date,t)}function $E(t,e){let s=new Intl.DateTimeFormat(void 0,{month:"long"}),r=new Intl.DateTimeFormat(void 0,{month:"short"}),n=o=>o<10?"0"+o:o.toString();return e.replace(/%[YmdbBHM%]/g,o=>{switch(o){case"%Y":return t.getFullYear().toString();case"%m":return n(t.getMonth()+1);case"%d":return n(t.getDate());case"%b":return r.format(t);case"%B":return s.format(t);case"%H":return n(t.getHours());case"%M":return n(t.getMinutes());case"%%":return"%";default:return o}})}function FE(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function RE(t,e,s,r){if(r===0)return t;let n=r==null||r<0?1/0:r,o=e.length===0?new RegExp("(?=)","gu"):new RegExp(FE(e),"gu");return t.replaceAll(o,i=>n>0?(--n,s):i)}var g0=class extends Error{},x0=class extends Error{},dt=class{type="RuntimeValue";value;builtins=new Map;constructor(t=void 0){this.value=t}__bool__(){return new Q(!!this.value)}toString(){return String(this.value)}},te=class extends dt{type="IntegerValue"},Ae=class extends dt{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},q=class extends dt{type="StringValue";builtins=new Map([["upper",new be(()=>new q(this.value.toUpperCase()))],["lower",new be(()=>new q(this.value.toLowerCase()))],["strip",new be(()=>new q(this.value.trim()))],["title",new be(()=>new q(NE(this.value)))],["capitalize",new be(()=>new q(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],["length",new te(this.value.length)],["rstrip",new be(()=>new q(this.value.trimEnd()))],["lstrip",new be(()=>new q(this.value.trimStart()))],["startswith",new be(t=>{if(t.length===0)throw new Error("startswith() requires at least one argument");let e=t[0];if(e instanceof q)return new Q(this.value.startsWith(e.value));if(e instanceof oe){for(let s of e.value){if(!(s instanceof q))throw new Error("startswith() tuple elements must be strings");if(this.value.startsWith(s.value))return new Q(!0)}return new Q(!1)}throw new Error("startswith() argument must be a string or tuple of strings")})],["endswith",new be(t=>{if(t.length===0)throw new Error("endswith() requires at least one argument");let e=t[0];if(e instanceof q)return new Q(this.value.endsWith(e.value));if(e instanceof oe){for(let s of e.value){if(!(s instanceof q))throw new Error("endswith() tuple elements must be strings");if(this.value.endsWith(s.value))return new Q(!0)}return new Q(!1)}throw new Error("endswith() argument must be a string or tuple of strings")})],["split",new be(t=>{let e=t[0]??new ke;if(!(e instanceof q||e instanceof ke))throw new Error("sep argument must be a string or null");let s=t[1]??new te(-1);if(!(s instanceof te))throw new Error("maxsplit argument must be a number");let r=[];if(e instanceof ke){let n=this.value.trimStart();for(let{0:o,index:i}of n.matchAll(/\S+/g)){if(s.value!==-1&&r.length>=s.value&&i!==void 0){r.push(o+n.slice(i+o.length));break}r.push(o)}}else{if(e.value==="")throw new Error("empty separator");r=this.value.split(e.value),s.value!