@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 • 545 kB
JavaScript
var AI=Object.defineProperty;var fs=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var en=(t,e)=>{for(var r in e)AI(t,r,{get:e[r],enumerable:!0})};import MI from"fs";import tn from"path";import TI from"url";var SI="4.2.0",Mf=typeof self<"u",rn=!gE(MI),_E=!gE(tn),sc=Mf&&"caches"in self,OI=typeof globalThis.Deno<"u",a3=typeof globalThis.Bun<"u",oc=OI&&sc&&!rn,mE=typeof process<"u",hE=mE&&process?.release?.name==="node"&&!oc,Tf=typeof window<"u"&&typeof window.document<"u",Sf=Mf&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),II=Tf||Sf||oc,CI=hE||typeof navigator<"u"&&"gpu"in navigator,PI=typeof navigator<"u"&&"ml"in navigator,zI=typeof crypto<"u"&&typeof crypto.getRandomValues=="function",LI=typeof chrome<"u"&&typeof chrome.runtime<"u"&&typeof chrome.runtime.id=="string",NI=typeof ServiceWorkerGlobalScope<"u"&&Mf&&self instanceof ServiceWorkerGlobalScope,$I=()=>{if(typeof navigator>"u")return!1;let t=navigator.userAgent,r=(navigator.vendor||"").indexOf("Apple")>-1,s=!t.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i)&&!t.includes("Chrome")&&!t.includes("Android");return r&&s},RI=$I(),ie=Object.freeze({IS_BROWSER_ENV:Tf,IS_WEBWORKER_ENV:Sf,IS_WEB_ENV:II,IS_SERVICE_WORKER_ENV:NI,IS_DENO_WEB_RUNTIME:oc,IS_WEB_CACHE_AVAILABLE:sc,IS_WEBGPU_AVAILABLE:CI,IS_WEBNN_AVAILABLE:PI,IS_SAFARI:RI,IS_PROCESS_AVAILABLE:mE,IS_NODE_ENV:hE,IS_FS_AVAILABLE:rn,IS_PATH_AVAILABLE:_E,IS_CRYPTO_AVAILABLE:zI,IS_CHROME_AVAILABLE:LI}),Of=rn&&_E,nc="./";if(Of){let t=Object(import.meta).url;t?nc=tn.dirname(tn.dirname(TI.fileURLToPath(t))):typeof __dirname<"u"&&(nc=tn.dirname(__dirname))}var DI=Of?tn.join(nc,"/.cache/"):null,fE="/models/",FI=Of?tn.join(nc,fE):fE,BI=typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,St=Object.freeze({DEBUG:10,INFO:20,WARNING:30,ERROR:40,NONE:50}),dE=St.WARNING,me={version:SI,backends:{onnx:{}},get logLevel(){return dE},set logLevel(t){dE=t,me.backends.onnx?.setLogLevel?.(t)},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(Tf||Sf||oc),localModelPath:FI,useFS:rn,useBrowserCache:sc,useFSCache:rn,cacheDir:DI,useCustomCache:!1,customCache:null,useWasmCache:sc||rn,cacheKey:"transformers-cache",experimental_useCrossOriginStorage:!1,fetch:BI};function gE(t){return Object.keys(t).length===0}var We=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 or(t,e){t&&t(e)}var ds=class extends We{constructor(e,r){super(),this.callback=e,this.files_loading=r}_call(e){if(e.status==="progress"){this.files_loading[e.file]={loaded:e.loaded,total:e.total};let r=Object.values(this.files_loading).reduce((o,a)=>o+a.loaded,0),s=Object.values(this.files_loading).reduce((o,a)=>o+a.total,0),n=s>0?r/s*100:0;this.callback({status:"progress_total",name:e.name,progress:n,loaded:r,total:s,files:structuredClone(this.files_loading)})}this.callback(e)}};function wE(t){return Number.isInteger(t)||typeof t=="bigint"}function If(t){return t==null||t===-1}function Cf(t){let e=[],r=t;for(;Array.isArray(r);)e.push(r.length),r=r[0];return e}function gt(...t){return Array.prototype.concat.apply([],t)}function xE(...t){return t.reduce((e,r)=>e.flatMap(s=>r.map(n=>[s,n])))}function sn(t,e){return Math.abs((t+e)%(2*e)-e)}function Ve(t,e){return Object.assign({},...e.map(r=>{if(t[r]!==void 0)return{[r]:t[r]}}))}function yE(t,e){let r=0;for(let s of t)s===e&&++r;return r}var ee={error(...t){me.logLevel<=St.ERROR&&console.error(...t)},warn(...t){me.logLevel<=St.WARNING&&console.warn(...t)},info(...t){me.logLevel<=St.INFO&&console.log(...t)},debug(...t){me.logLevel<=St.DEBUG&&console.log(...t)},log(...t){this.info(...t)}};var UI=class{constructor(t){this.trie=this._build_trie(t)}_build_trie(t){let e=Object.create(null);for(let r of t){let s=e;for(let n=0;n<r.length;++n){let o=r[n];s=s[o]??=Object.create(null)}s.end=r}return e}split(t){let e=[],r=t.length,s=0,n=0;for(;n<r;){let o=this.trie,a=null,i=n;for(;i<r&&(o=o[t[i]]);)o.end&&(a=o.end),++i;a?(n>s&&e.push(t.slice(s,n)),e.push(a),n+=a.length,s=n):++n}return s<r&&e.push(t.slice(s)),e}},bE=UI,jI=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}},GI=jI,SE=(()=>{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(),r=0;for(let n=0;n<256;++n)t.includes(n)||(t.push(n),e.push(256+r),r+=1);let s=e.map(n=>String.fromCharCode(n));return Object.fromEntries(t.map((n,o)=>[n,s[o]]))})(),qI=t=>Object.fromEntries(Object.entries(t).map(([e,r])=>[r,e])),WI=qI(SE),vE=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",VI=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|[${vE}])]+`,` ?[^\\s${vE}]+`]]),ac="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",zf=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"),ic=(t,e=!0)=>{if(t.Regex!==void 0){let r=t.Regex.replace(/\\([#&~])/g,"$1");r=r.replace(/\\A/g,"^").replace(/\\z/g,"$").replace(/\\Z/g,"(?=\\r?\\n?$)");for(let[s,n]of VI)r=r.replaceAll(s,n);try{return new RegExp(r,"gu")}catch(s){if(!(s instanceof SyntaxError)||!s.message.toLowerCase().includes("invalid property name"))throw s;let n=!1,o=r.replace(/(\\[pP])\{([^}=]+)\}/g,(a,i,l)=>{try{return new RegExp(`\\p{${l}}`,"u"),`${i}{${l}}`}catch{return n=!0,`${i}{Script=${l}}`}});if(!n)throw s;try{return new RegExp(o,"gu")}catch{throw s}}}else if(t.String!==void 0){let r=HI(t.String);return new RegExp(e?r:`(${r})`,"gu")}else return console.warn("Unknown pattern type:",t),null},HI=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),XI=(t,e,r)=>{let s=[],n=0;for(;n<t.length;){if(s.push(t[n]),(e.get(t[n])??r)!==r){++n;continue}for(;++n<t.length&&(e.get(t[n])??r)===r;)e.get(s.at(-1))!==r&&(s[s.length-1]+=t[n])}return s},KI=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,YI=t=>Number.isInteger(t)||typeof t=="bigint",QI=t=>{let e=0;for(let r of t)++e;return e},JI=t=>OE(t.toLowerCase()),Vt=(...t)=>Array.prototype.concat.apply([],t),Lf=t=>new Map(Object.entries(t)),ZI=(t,e)=>{let r=[],s=0;for(let n of t.matchAll(e)){let o=n[0];s<n.index&&r.push(t.slice(s,n.index)),o.length>0&&r.push(o),s=n.index+o.length}return s<t.length&&r.push(t.slice(s)),r},OE=t=>t.replace(/\p{M}/gu,""),kE=(t,e,r=[])=>{if(!t||Array.isArray(t)||typeof t!="object")return`${e} must be a valid object`;for(let s of r)if(!(s in t))return`${e} must contain a "${s}" property`;return null},eC=t=>t.match(/\S+/g)||[],tC=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},co=tC,rC=class extends co{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},xr=rC,sC=class extends xr{tokenize_chinese_chars(t){let e=[];for(let r=0;r<t.length;++r){let s=t[r],n=s.charCodeAt(0);KI(n)?(e.push(" "),e.push(s),e.push(" ")):e.push(s)}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 r of t){let s=r.charCodeAt(0);s===0||s===65533||this.is_control(r)||(/^\s$/.test(r)?e.push(" "):e.push(r))}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}},nC=sC,oC=class extends xr{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(r=>r.normalize("NFKC")).join("\uFF5E"):t=t.normalize("NFKC"),t}},aC=oC,iC=class extends xr{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>IE(e))}normalize(t){return this.normalizers.reduce((e,r)=>r?r.normalize(e):e,t)}},lC=iC,cC=class extends xr{normalize(t){let e=ic(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},uC=cC,pC=class extends xr{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},lc=pC,fC=class extends lc{constructor(){super(...arguments),this.form="NFC"}},dC=fC,_C=class extends lc{constructor(){super(...arguments),this.form="NFD"}},mC=_C,hC=class extends lc{constructor(){super(...arguments),this.form="NFKC"}},gC=hC,wC=class extends lc{constructor(){super(...arguments),this.form="NFKD"}},xC=wC,yC=class extends xr{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}},bC=yC,vC=class extends xr{normalize(t){return OE(t)}},kC=vC,EC=class extends xr{normalize(t){return t.toLowerCase()}},AC=EC,MC=class extends xr{normalize(t){return t=this.config.prepend+t,t}},TC=MC;function SC(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new nC(t);case"Precompiled":return new aC(t);case"Sequence":return new lC(t);case"Replace":return new uC(t);case"NFC":return new dC(t);case"NFD":return new mC(t);case"NFKC":return new gC(t);case"NFKD":return new xC(t);case"Strip":return new bC(t);case"StripAccents":return new kC(t);case"Lowercase":return new AC(t);case"Prepend":return new TC(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var IE=SC,OC=class extends co{pre_tokenize(t,e){return(Array.isArray(t)?t.map(r=>this.pre_tokenize_text(r,e)):this.pre_tokenize_text(t,e)).flat()}_call(t,e){return this.pre_tokenize(t,e)}},Ht=OC,IC=class extends Ht{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=SE,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(s=>Array.from(this.text_encoder.encode(s),n=>this.byte_encoder[n]).join(""))}},CC=IC,PC=class extends Ht{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},zC=PC,LC=class extends Ht{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:r=void 0}=e??{},s=t.replaceAll(" ",this.str_rep);return!s.startsWith(this.replacement)&&(this.prepend_scheme==="always"||this.prepend_scheme==="first"&&r===0)&&(s=this.str_rep+s),[s]}},NC=LC,$C=class extends Ht{constructor(t){super(),this.config=t,this.pattern=ic(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):ZI(t,this.pattern)}},RC=$C,DC=class extends Ht{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${ac}]+|[${ac}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},FC=DC,BC=class extends Ht{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)||[]}},UC=BC,jC=class extends Ht{constructor(){super(),this.pattern=new RegExp(`[^\\s${ac}]+|[${ac}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},GC=jC,qC=class extends Ht{constructor(t){super(),this.config=t,this.pattern=ic(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},WC=qC,VC=class extends Ht{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>CE(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((r,s)=>s?s.pre_tokenize(r,e):r,[t])}},HC=VC,XC=class extends Ht{pre_tokenize_text(t){return eC(t)}},KC=XC,YC=class extends Ht{constructor(t){super(),this.config=t,this._length=t.length}pre_tokenize_text(t){let e=[];for(let r=0;r<t.length;r+=this._length)e.push(t.slice(r,r+this._length));return e}},QC=YC;function JC(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new GC;case"Sequence":return new HC(t);case"Whitespace":return new zC;case"WhitespaceSplit":return new KC;case"Metaspace":return new NC(t);case"ByteLevel":return new CC(t);case"Split":return new RC(t);case"Punctuation":return new FC(t);case"Digits":return new UC(t);case"Replace":return new WC(t);case"FixedLength":return new QC(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var CE=JC,ZC=class extends co{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=XI(e,this.tokens_to_ids,this.unk_token_id)),e}},cc=ZC,eP=class extends cc{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=Lf(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,r]of this.tokens_to_ids)this.vocab[r]=e}encode(t){let e=[];for(let r of t){let s=[...r];if(s.length>this.max_input_chars_per_word){e.push(this.unk_token);continue}let n=!1,o=0,a=[];for(;o<s.length;){let i=s.length,l=null;for(;o<i;){let c=s.slice(o,i).join("");if(o>0&&(c=this.config.continuing_subword_prefix+c),this.tokens_to_ids.has(c)){l=c;break}--i}if(l===null){n=!0;break}a.push(l),o=i}n?e.push(this.unk_token):e.push(...a)}return e}},EE=eP,AE=class PE{constructor(e,r){this.is_leaf=e,this.children=r}static default(){return new PE(!1,new Map)}},tP=class{constructor(){this.root=AE.default()}extend(t){for(let e of t)this.push(e)}push(t){let e=this.root;for(let r of t){let s=e.children.get(r);s===void 0&&(s=AE.default(),e.children.set(r,s)),e=s}e.is_leaf=!0}*common_prefix_search(t){let e=this.root;if(e===void 0)return;let r="";for(let s of t){if(r+=s,e=e.children.get(s),e===void 0)return;e.is_leaf&&(yield r)}}},rP=tP,Pf=class zE{constructor(e,r,s,n,o){this.token_id=e,this.node_id=r,this.pos=s,this.length=n,this.score=o,this.prev=null,this.backtrace_score=0}clone(){let e=new zE(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},sP=class{constructor(t,e,r){this.chars=Array.from(t),this.len=this.chars.length,this.bos_token_id=e,this.eos_token_id=r,this.nodes=[],this.begin_nodes=Array.from({length:this.len+1},()=>[]),this.end_nodes=Array.from({length:this.len+1},()=>[]);let s=new Pf(this.bos_token_id??0,0,0,0,0),n=new Pf(this.eos_token_id??0,1,this.len,0,0);this.nodes.push(s.clone()),this.nodes.push(n.clone()),this.begin_nodes[this.len].push(n),this.end_nodes[0].push(s)}insert(t,e,r,s){let n=this.nodes.length,o=new Pf(s,n,t,e,r);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 a of this.begin_nodes[e]){a.prev=null;let i=0,l=null;for(let c of this.end_nodes[e]){let p=c.backtrace_score+a.score;(l===null||p>i)&&(l=c.clone(),i=p)}if(l!==null)a.prev=l,a.backtrace_score=i;else return[]}++e}let r=[],n=this.begin_nodes[t][0].prev;if(n===null)return[];let o=n.clone();for(;o.prev!==null;)r.push(o.clone()),o=o.clone().prev.clone();return r.reverse(),r}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)}},nP=sP;function oP(t){if(t.length===0)throw new Error("Array must not be empty");let e=t[0],r=0;for(let s=1;s<t.length;++s)t[s]<e&&(e=t[s],r=s);return[e,r]}var aP=class extends cc{constructor(t,e){super(t);let r=t.vocab.length;this.vocab=new Array(r),this.scores=new Array(r);for(let s=0;s<r;++s)[this.vocab[s],this.scores[s]]=t.vocab[s];this.unk_token_id=t.unk_id,this.unk_token=this.vocab[t.unk_id],this.tokens_to_ids=new Map(this.vocab.map((s,n)=>[s,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=oP(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new rP,this.trie.extend(this.vocab),this.fuse_unk=!0}populate_nodes(t){let e=t.chars,r=1,s=0;for(;s<e.length;){let n=!1,o=[],a=e.slice(s).join(""),i=this.trie.common_prefix_search(a);for(let l of i){o.push(l);let c=this.tokens_to_ids.get(l),p=this.scores[c],f=QI(l);t.insert(s,f,p,c),!n&&f===r&&(n=!0)}n||t.insert(s,r,this.unk_score,this.unk_token_id),s+=r}}tokenize(t){let e=new nP(t,this.bos_token_id,this.eos_token_id);return this.populate_nodes(e),e.tokens()}encode(t){let e=[];for(let r of t){let s=this.tokenize(r);e.push(...s)}return e}},ME=aP,iP=class{constructor(t=(r,s)=>r>s,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 r=this._smallest();this._comparator(e,this._heap[r])&&(this._heap[r]=e,this._sift_up_from(r))}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 r=this._heap[t];this._heap[t]=this._heap[e],this._heap[e]=r}_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}},lP=iP,cP=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()}},uP=cP,pP=class extends cc{constructor(t){super(t),this.tokens_to_ids=Lf(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[r,s]of this.tokens_to_ids)this.vocab[s]=r;let e=Array.isArray(t.merges[0]);this.merges=e?t.merges:t.merges.map(r=>r.split(" ",2)),this.bpe_ranks=new Map(this.merges.map((r,s)=>[JSON.stringify(r),s])),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 uP(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 r=Array.from(t);this.end_of_word_suffix&&(r[r.length-1]+=this.end_of_word_suffix);let s=[];if(r.length>1){let n=new lP((i,l)=>i.score<l.score),o={token:r[0],bias:0,prev:null,next:null},a=o;for(let i=1;i<r.length;++i){let l={bias:i/r.length,token:r[i],prev:a,next:null};a.next=l,this.add_node(n,a),a=l}for(;!n.is_empty();){let i=n.pop();if(i.deleted||!i.next||i.next.deleted)continue;if(i.deleted=!0,i.next.deleted=!0,i.prev){let c={...i.prev};i.prev.deleted=!0,i.prev=c,c.prev?c.prev.next=c:o=c}let l={token:i.token+i.next.token,bias:i.bias,prev:i.prev,next:i.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 i=o;i!==null;i=i.next)s.push(i.token)}else s=r;if(this.continuing_subword_suffix)for(let n=0;n<s.length-1;++n)s[n]+=this.continuing_subword_suffix;return t.length<this.max_length_to_cache&&this.cache.put(t,s),s}add_node(t,e){let r=this.bpe_ranks.get(JSON.stringify([e.token,e.next.token]));r!==void 0&&(e.score=r+e.bias,t.push(e))}encode(t){let e=[];for(let r of t){if(this.ignore_merges&&this.tokens_to_ids.has(r)){e.push(r);continue}let s=this.bpe(r);for(let n of s)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(a=>`<0x${a.toString(16).toUpperCase().padStart(2,"0")}>`);o.every(a=>this.tokens_to_ids.has(a))?e.push(...o):this.unk_token!=null&&e.push(this.unk_token)}else this.unk_token!=null&&e.push(this.unk_token)}return e}},TE=pP,fP=class extends cc{constructor(t,e){super(t);let r=t.vocab;this.tokens_to_ids=Lf(e.target_lang?r[e.target_lang]:r),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[s,n]of this.tokens_to_ids)this.vocab[n]=s}encode(t){return t}},dP=fP;function _P(t,e){switch(t.type){case"WordPiece":return new EE(t);case"Unigram":return new ME(t,e.eos_token);case"BPE":return new TE(t);default:if(t.vocab)return Array.isArray(t.vocab)?new ME(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new TE(t):new EE(t):new dP(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 mP=_P,hP=class extends co{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},uo=hP,gP=class extends uo{post_process(t,e=null,r=!0){let s=e===null?this.config.single:this.config.pair,n=[],o=[];for(let a of s)"SpecialToken"in a?r&&(n.push(a.SpecialToken.id),o.push(a.SpecialToken.type_id)):"Sequence"in a&&(a.Sequence.id==="A"?(n=Vt(n,t),o=Vt(o,new Array(t.length).fill(a.Sequence.type_id))):a.Sequence.id==="B"&&(n=Vt(n,e),o=Vt(o,new Array(e.length).fill(a.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},wP=gP,xP=class extends uo{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},yP=xP,bP=class extends uo{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,r=!0){r&&(t=Vt([this.cls[0]],t,[this.sep[0]]));let s=new Array(t.length).fill(0);if(e){let n=[],o=r?[this.sep[0]]:[];t=Vt(t,n,e,o),s=Vt(s,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:s}}},vP=bP,kP=class extends uo{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,r=!0){r&&(t=Vt([this.cls[0]],t,[this.sep[0]]));let s=new Array(t.length).fill(0);if(e){let n=r?[this.sep[0]]:[],o=r?[this.sep[0]]:[];t=Vt(t,n,e,o),s=Vt(s,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:s}}},EP=kP,AP=class extends uo{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>LE(e))}post_process(t,e=null,r=!0){let s={tokens:t,tokens_pair:e};for(let n of this.processors)s=n.post_process(s.tokens,s.tokens_pair,r);return s}},MP=AP;function TP(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new wP(t);case"ByteLevel":return new yP(t);case"BertProcessing":return new vP(t);case"RobertaProcessing":return new EP(t);case"Sequence":return new MP(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var LE=TP,SP=class extends co{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("")}},Dt=SP,OP=class extends Dt{constructor(t){super(t),this.byte_decoder=WI,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(""),r=new Uint8Array([...e].map(s=>this.byte_decoder[s]));return this.text_decoder.decode(r)}decode_chain(t){let e=[],r=[];for(let s of t)this.added_tokens.find(n=>n.content===s)!==void 0?(r.length>0&&(e.push(this.convert_tokens_to_string(r)),r=[]),e.push(s)):r.push(s);return r.length>0&&e.push(this.convert_tokens_to_string(r)),e}},IP=OP,CP=class extends Dt{constructor(t){super(t),this.cleanup=t.cleanup}decode_chain(t){return t.map((e,r)=>{if(r!==0){let s=this.config.prefix;s&&e.startsWith(s)?e=e.replace(s,""):e=" "+e}return this.cleanup&&(e=zf(e)),e})}},PP=CP,zP=class extends Dt{constructor(t){super(t),this.replacement=t.replacement??"\u2581"}decode_chain(t){let e=[];for(let r=0;r<t.length;++r){let s=t[r].replaceAll(this.replacement," ");r==0&&s.startsWith(" ")&&(s=s.substring(1)),e.push(s)}return e}},LP=zP,NP=class extends Dt{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,r)=>e.replaceAll(this.suffix,r===t.length-1?"":" "))}},$P=NP,RP=class extends Dt{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 s=e.filter(n=>n!==this.pad_token).join("");return this.cleanup&&(s=zf(s).replaceAll(this.word_delimiter_token," ").trim()),s}decode_chain(t){return[this.convert_tokens_to_string(t)]}},DP=RP,FP=class extends Dt{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>NE(e))}decode_chain(t){return this.decoders.reduce((e,r)=>r.decode_chain(e),t)}},BP=FP,UP=class extends Dt{decode_chain(t){let e=ic(this.config.pattern),r=this.config.content??"";return e===null?t:t.map(s=>s.replaceAll(e,r))}},jP=UP,GP=class extends Dt{decode_chain(t){return[t.join("")]}},qP=GP,WP=class extends Dt{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 r=0;for(let n=0;n<this.start&&e[n]===this.content;++n){r=n+1;continue}let s=e.length;for(let n=0;n<this.stop;++n){let o=e.length-n-1;if(e[o]===this.content){s=o;continue}else break}return e.slice(r,s)})}},VP=WP,HP=class extends Dt{constructor(t){super(t),this.text_decoder=new TextDecoder}decode_chain(t){let e=[],r=[];for(let s of t){let n=null;if(s.length===6&&s.startsWith("<0x")&&s.endsWith(">")){let o=parseInt(s.slice(3,5),16);isNaN(o)||(n=o)}if(n!==null)r.push(n);else{if(r.length>0){let o=this.text_decoder.decode(Uint8Array.from(r));e.push(o),r=[]}e.push(s)}}if(r.length>0){let s=this.text_decoder.decode(Uint8Array.from(r));e.push(s),r=[]}return e}},XP=HP;function KP(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new IP(t);case"WordPiece":return new PP(t);case"Metaspace":return new LP(t);case"BPEDecoder":return new $P(t);case"CTC":return new DP(t);case"Sequence":return new BP(t);case"Replace":return new jP(t);case"Fuse":return new qP(t);case"Strip":return new VP(t);case"ByteFallback":return new XP(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var NE=KP,YP=class{constructor(t,e){let r=kE(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(r)throw new Error(r);let s=kE(e,"Config");if(s)throw new Error(s);this.tokenizer=t,this.config=e,this.normalizer=IE(this.tokenizer.normalizer),this.pre_tokenizer=CE(this.tokenizer.pre_tokenizer),this.model=mP(this.tokenizer.model,this.config),this.post_processor=LE(this.tokenizer.post_processor),this.decoder=NE(this.tokenizer.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];let n=[],o=[];this.added_tokens_map=new Map;for(let a of this.tokenizer.added_tokens){let i=new GI(a);if(this.added_tokens.push(i),this.model.tokens_to_ids.set(i.content,i.id),this.model.vocab[i.id]=i.content,i.special&&(this.special_tokens.push(i.content),this.all_special_ids.push(i.id)),this.added_tokens_map.set(i.content,i),i.normalized&&this.normalizer!==null){let l=this.normalizer(i.content);o.push(l),this.added_tokens_map.set(l,i)}else n.push(i.content)}(this.config.additional_special_tokens??[]).forEach(a=>{this.special_tokens.includes(a)||this.special_tokens.push(a)}),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 bE(n),this.splitter_normalized=new bE(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:r=!0,return_token_type_ids:s=null}={}){let{tokens:n,token_type_ids:o}=this.tokenize_helper(t,{text_pair:e,add_special_tokens:r}),a=n.map(l=>this.added_tokens_map.get(l)?.id??this.model.tokens_to_ids.get(l)??this.model.unk_token_id),i={ids:a,tokens:n,attention_mask:new Array(a.length).fill(1)};return s&&o&&(i.token_type_ids=o),i}decode(t,e={}){if(!Array.isArray(t)||t.length===0||!YI(t[0]))throw Error("token_ids must be a non-empty array of integers.");let r=t.map(n=>this.model.vocab[Number(n)]??this.model.unk_token);e.skip_special_tokens&&(r=r.filter(n=>!this.special_tokens.includes(n)));let s=this.decoder?this.decoder(r):r.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(s=s.replaceAll(this.decoder.end_of_word_suffix," "),e.skip_special_tokens&&(s=s.trim())),(e.clean_up_tokenization_spaces??this.clean_up_tokenization_spaces)&&(s=zf(s)),s}tokenize(t,{text_pair:e=null,add_special_tokens:r=!1}={}){return this.tokenize_helper(t,{text_pair:e,add_special_tokens:r}).tokens}encode_text(t){if(t===null)return null;let e=this.splitter_unnormalized.split(t);return e.forEach((r,s)=>{let n=this.added_tokens_map.get(r);n&&(n.lstrip&&s>0&&(e[s-1]=e[s-1].trimEnd()),n.rstrip&&s<e.length-1&&(e[s+1]=e[s+1].trimStart()))}),e.flatMap((r,s)=>{if(r.length===0)return[];if(this.added_tokens_map.has(r))return[r];if(this.remove_space===!0&&(r=r.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(r=JI(r)),this.normalizer!==null&&(r=this.normalizer(r)),r.length===0)return[];let n=this.splitter_normalized.split(r);return n.forEach((o,a)=>{let i=this.added_tokens_map.get(o);i&&(i.lstrip&&a>0&&(n[a-1]=n[a-1].trimEnd()),i.rstrip&&a<n.length-1&&(n[a+1]=n[a+1].trimStart()))}),n.flatMap(o=>{if(o.length===0)return[];if(this.added_tokens_map.has(o))return[o];let a=this.pre_tokenizer!==null?this.pre_tokenizer(o,{section_index:s}):[o];return this.model(a)})})}tokenize_helper(t,{text_pair:e=null,add_special_tokens:r=!0}){let s=this.encode_text(t),n=this.encode_text(e||null);return this.post_processor?this.post_processor(s,n,r):{tokens:Vt(s??[],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 r=0;r<this.model.vocab.length;++r){let s=this.model.vocab[r];(t||!this.added_tokens_map.has(s))&&e.set(s,r)}return e}},$E=YP;var D=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"}),Ft=class{constructor(t,e){this.value=t,this.type=e}};function RE(t){return/\w/.test(t)}function po(t){return/[0-9]/.test(t)}function DE(t){return/\s/.test(t)}var QP=[["{%",D.OpenStatement],["%}",D.CloseStatement],["{{",D.OpenExpression],["}}",D.CloseExpression],["(",D.OpenParen],[")",D.CloseParen],["{",D.OpenCurlyBracket],["}",D.CloseCurlyBracket],["[",D.OpenSquareBracket],["]",D.CloseSquareBracket],[",",D.Comma],[".",D.Dot],[":",D.Colon],["|",D.Pipe],["<=",D.ComparisonBinaryOperator],[">=",D.ComparisonBinaryOperator],["==",D.ComparisonBinaryOperator],["!=",D.ComparisonBinaryOperator],["<",D.ComparisonBinaryOperator],[">",D.ComparisonBinaryOperator],["+",D.AdditiveBinaryOperator],["-",D.AdditiveBinaryOperator],["~",D.AdditiveBinaryOperator],["*",D.MultiplicativeBinaryOperator],["/",D.MultiplicativeBinaryOperator],["%",D.MultiplicativeBinaryOperator],["=",D.Equals]],JP=new Map([["n",`
`],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function ZP(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 ez(t,e={}){let r=[],s=ZP(t,e),n=0,o=0,a=c=>{let p="";for(;c(s[n]);){if(s[n]==="\\"){if(++n,n>=s.length)throw new SyntaxError("Unexpected end of input");let f=s[n++],_=JP.get(f);if(_===void 0)throw new SyntaxError(`Unexpected escaped character: ${f}`);p+=_;continue}if(p+=s[n++],n>=s.length)throw new SyntaxError("Unexpected end of input")}return p},i=()=>{let c=r.at(-1);c&&c.type===D.Text&&(c.value=c.value.trimEnd(),c.value===""&&r.pop())},l=()=>{for(;n<s.length&&DE(s[n]);)++n};e:for(;n<s.length;){let c=r.at(-1)?.type;if(c===void 0||c===D.CloseStatement||c===D.CloseExpression||c===D.Comment){let f="";for(;n<s.length&&!(s[n]==="{"&&(s[n+1]==="%"||s[n+1]==="{"||s[n+1]==="#"));)f+=s[n++];if(f.length>0){r.push(new Ft(f,D.Text));continue}}if(s[n]==="{"&&s[n+1]==="#"){n+=2;let f=s[n]==="-";f&&++n;let _="";for(;s[n]!=="#"||s[n+1]!=="}";){if(n+2>=s.length)throw new SyntaxError("Missing end of comment tag");_+=s[n++]}let m=_.endsWith("-");m&&(_=_.slice(0,-1)),f&&i(),r.push(new Ft(_,D.Comment)),n+=2,m&&l();continue}if(s.slice(n,n+3)==="{%-"){i(),r.push(new Ft("{%",D.OpenStatement)),n+=3;continue}if(s.slice(n,n+3)==="{{-"){i(),r.push(new Ft("{{",D.OpenExpression)),o=0,n+=3;continue}if(a(DE),s.slice(n,n+3)==="-%}"){r.push(new Ft("%}",D.CloseStatement)),n+=3,l();continue}if(s.slice(n,n+3)==="-}}"){r.push(new Ft("}}",D.CloseExpression)),n+=3,l();continue}let p=s[n];if(p==="-"||p==="+"){let f=r.at(-1)?.type;if(f===D.Text||f===void 0)throw new SyntaxError(`Unexpected character: ${p}`);switch(f){case D.Identifier:case D.NumericLiteral:case D.StringLiteral:case D.CloseParen:case D.CloseSquareBracket:break;default:{++n;let _=a(po);r.push(new Ft(`${p}${_}`,_.length>0?D.NumericLiteral:D.UnaryOperator));continue}}}for(let[f,_]of QP){if(f==="}}"&&o>0)continue;if(s.slice(n,n+f.length)===f){r.push(new Ft(f,_)),_===D.OpenExpression?o=0:_===D.OpenCurlyBracket?++o:_===D.CloseCurlyBracket&&--o,n+=f.length;continue e}}if(p==="'"||p==='"'){++n;let f=a(_=>_!==p);r.push(new Ft(f,D.StringLiteral)),++n;continue}if(po(p)){let f=a(po);if(s[n]==="."&&po(s[n+1])){++n;let _=a(po);f=`${f}.${_}`}r.push(new Ft(f,D.NumericLiteral));continue}if(RE(p)){let f=a(RE);r.push(new Ft(f,D.Identifier));continue}throw new SyntaxError(`Unexpected character: ${p}`)}return r}var Kt=class{type="Statement"},tz=class extends Kt{constructor(t){super(),this.body=t}type="Program"},rz=class extends Kt{constructor(t,e,r){super(),this.test=t,this.body=e,this.alternate=r}type="If"},sz=class extends Kt{constructor(t,e,r,s){super(),this.loopvar=t,this.iterable=e,this.body=r,this.defaultBlock=s}type="For"},nz=class extends Kt{type="Break"},oz=class extends Kt{type="Continue"},az=class extends Kt{constructor(t,e,r){super(),this.assignee=t,this.value=e,this.body=r}type="Set"},iz=class extends Kt{constructor(t,e,r){super(),this.name=t,this.args=e,this.body=r}type="Macro"},lz=class extends Kt{constructor(t){super(),this.value=t}type="Comment"},Ct=class extends Kt{type="Expression"},cz=class extends Ct{constructor(t,e,r){super(),this.object=t,this.property=e,this.computed=r}type="MemberExpression"},FE=class extends Ct{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},nn=class extends Ct{constructor(t){super(),this.value=t}type="Identifier"},on=class extends Ct{constructor(t){super(),this.value=t}type="Literal"},uz=class extends on{type="IntegerLiteral"},pz=class extends on{type="FloatLiteral"},BE=class extends on{type="StringLiteral"},fz=class extends on{type="ArrayLiteral"},UE=class extends on{type="TupleLiteral"},dz=class extends on{type="ObjectLiteral"},fo=class extends Ct{constructor(t,e,r){super(),this.operator=t,this.left=e,this.right=r}type="BinaryExpression"},_z=class extends Ct{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},mz=class extends Kt{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},hz=class extends Ct{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},gz=class extends Ct{constructor(t,e,r){super(),this.operand=t,this.negate=e,this.test=r}type="TestExpression"},wz=class extends Ct{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},xz=class extends Ct{constructor(t=void 0,e=void 0,r=void 0){super(),this.start=t,this.stop=e,this.step=r}type="SliceExpression"},yz=class extends Ct{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},bz=class extends Ct{constructor(t){super(),this.argument=t}type="SpreadExpression"},vz=class extends Kt{constructor(t,e,r){super(),this.call=t,this.callerArgs=e,this.body=r}type="CallStatement"},kz=class extends Ct{constructor(t,e,r){super(),this.condition=t,this.trueExpr=e,this.falseExpr=r}type="Ternary"};function Ez(t){let e=new tz([]),r=0;function s(z,$){let B=t[r++];if(!B||B.type!==z)throw new Error(`Parser Error: ${$}. ${B.type} !== ${z}.`);return B}function n(z){if(!l(z))throw new SyntaxError(`Expected ${z}`);++r}function o(){switch(t[r].type){case D.Comment:return new lz(t[r++].value);case D.Text:return c();case D.OpenStatement:return p();case D.OpenExpression:return f();default:throw new SyntaxError(`Unexpected token type: ${t[r].type}`)}}function a(...z){return r+z.length<=t.length&&z.every(($,B)=>$===t[r+B].type)}function i(...z){return t[r]?.type===D.OpenStatement&&t[r+1]?.type===D.Identifier&&z.includes(t[r+1]?.value)}function l(...z){return r+z.length<=t.length&&z.every(($,B)=>t[r+B].type==="Identifier"&&$===t[r+B].value)}function c(){return new BE(s(D.Text,"Expected text token").value)}function p(){if(s(D.OpenStatement,"Expected opening statement token"),t[r].type!==D.Identifier)throw new SyntaxError(`Unknown statement, got ${t[r].type}`);let z=t[r].value,$;switch(z){case"set":++r,$=_();break;case"if":++r,$=m(),s(D.OpenStatement,"Expected {% token"),n("endif"),s(D.CloseStatement,"Expected %} token");break;case"macro":++r,$=w(),s(D.OpenStatement,"Expected {% token"),n("endmacro"),s(D.CloseStatement,"Expected %} token");break;case"for":++r,$=k(),s(D.OpenStatement,"Expected {% token"),n("endfor"),s(D.CloseStatement,"Expected %} token");break;case"call":{++r;let B=null;a(D.OpenParen)&&(B=U());let Q=Y();if(Q.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let le=U();s(D.CloseStatement,"Expected closing statement token");let Ge=[];for(;!i("endcall");)Ge.push(o());s(D.OpenStatement,"Expected '{%'"),n("endcall"),s(D.CloseStatement,"Expected closing statement token");let ce=new FE(Q,le);$=new vz(ce,B,Ge);break}case"break":++r,s(D.CloseStatement,"Expected closing statement token"),$=new nz;break;case"continue":++r,s(D.CloseStatement,"Expected closing statement token"),$=new oz;break;case"filter":{++r;let B=Y();B instanceof nn&&a(D.OpenParen)&&(B=j(B)),s(D.CloseStatement,"Expected closing statement token");let Q=[];for(;!i("endfilter");)Q.push(o());s(D.OpenStatement,"Expected '{%'"),n("endfilter"),s(D.CloseStatement,"Expected '%}'"),$=new mz(B,Q);break}default:throw new SyntaxError(`Unknown statement type: ${z}`)}return $}function f(){s(D.OpenExpression,"Expected opening expression token");let z=A();return s(D.CloseExpression,"Expected closing expression token"),z}function _(){let z=x(),$=null,B=[];if(a(D.Equals))++r,$=x();else{for(s(D.CloseStatement,"Expected %} token");!i("endset");)B.push(o());s(D.OpenStatement,"Expected {% token"),n("endset")}return s(D.CloseStatement,"Expected closing statement token"),new az(z,$,B)}function m(){let z=A();s(D.CloseStatement,"Expected closing statement token");let $=[],B=[];for(;!i("elif","else","endif");)$.push(o());if(i("elif")){++r,++r;let Q=m();B.push(Q)}else if(i("else"))for(++r,++r,s(D.CloseStatement,"Expected closing statement token");!i("endif");)B.push(o());return new rz(z,$,B)}function w(){let z=Y();if(z.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let $=U();s(D.CloseStatement,"Expected closing statement token");let B=[];for(;!i("endmacro");)B.push(o());return new iz(z,$,B)}function x(z=!1){let $=z?Y:A,B=[$()],Q=a(D.Comma);for(;Q&&(++r,B.push($()),!!a(D.Comma)););return Q?new UE(B):B[0]}function k(){let z=x(!0);if(!(z instanceof nn||z instanceof UE))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${z.type} instead`);if(!l("in"))throw new SyntaxError("Expected `in` keyword following loop variable");++r;let $=A();s(D.CloseStatement,"Expected closing statement token");let B=[];for(;!i("endfor","else");)B.push(o());let Q=[];if(i("else"))for(++r,++r,s(D.CloseStatement,"Expected closing statement token");!i("endfor");)Q.push(o());return new sz(z,$,B,Q)}function A(){return E()}function E(){let z=S();if(l("if")){++r;let $=S();if(l("else")){++r;let B=E();return new kz($,z,B)}else return new hz(z,$)}return z}function S(){let z=T();for(;l("or");){let $=t[r];++r;let B=T();z=new fo($,z,B)}return z}function T(){let z=I();for(;l("and");){let $=t[r];++r;let B=I();z=new fo($,z,B)}return z}function I(){let z;for(;l("not");){let $=t[r];++r;let B=I();z=new wz($,B)}return z??O()}function O(){let z=b();for(;;){let $;if(l("not","in"))$=new Ft("not in",D.Identifier),r+=2;else if(l("in"))$=t[r++];else if(a(D.ComparisonBinaryOperator))$=t[r++];else break;let B=b();z=new fo($,z,B)}return z}function b(){let z=R();for(;a(D.AdditiveBinaryOperator);){let $=t[r];++r;let B=R();z=new fo($,z,B)}return z}function F(){let z=J(Y());return a(D.OpenParen)?j(z):z}function j(z){let $=new FE(z,U());return $=J($),a(D.OpenParen)&&($=j($)),$}function U(){s(D.OpenParen,"Expected opening parenthesis for arguments list");let z=X();return s(D.CloseParen,"Expected closing parenthesis for arguments list"),z}function X(){let z=[];for(;!a(D.CloseParen);){let $;if(t[r].type===D.MultiplicativeBinaryOperator&&t[r].value==="*"){++r;let B=A();$=new bz(B)}else if($=A(),a(D.Equals)){if(++r,!($ instanceof nn))throw new SyntaxError("Expected identifier for keyword argument");let B=A();$=new yz($,B)}z.push($),a(D.Comma)&&++r}return z}function K(){let z=[],$=!1;for(;!a(D.CloseSquareBracket);)a(D.Colon)?(z.push(void 0),++r,$=!0):(z.push(A()),a(D.Colon)&&(++r,$=!0));if(z.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if($){if(z.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new xz(...z)}return z[0]}function J(z){for(;a(D.Dot)||a(D.OpenSquareBracket);){let $=t[r];++r;let B,Q=$.type===D.OpenSquareBracket;if(Q)B=K(),s(D.CloseSquareBracket,"Expected closing square bracket");else if(B=Y(),B.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");z=new cz(z,B,Q)}return z}function R(){let z=C();for(;a(D.MultiplicativeBinaryOperator);){let $=t[r++],B=C();z=new fo($,z,B)}return z}function C(){let z=se();for(;l("is");){++r;let $=l("not");$&&++r;let B=Y();if(!(B instanceof nn))throw new SyntaxError("Expected identifier for the test");z=new gz(z,$,B)}return z}function se(){let z=F();for(;a(D.Pipe);){++r;let $=Y();if(!($ instanceof nn))throw new SyntaxError("Expected identifier for the filter");a(D.OpenParen)&&($=j($)),z=new _z(z,$)}return z}function Y(){let z=t[r++];switch(z.type){case D.NumericLiteral:{let $=z.value;return $.includes(".")?new pz(Number($)):new uz(Number($))}case D.StringLiteral:{let $=z.value;for(;a(D.StringLiteral);)$+=t[r++].value;return new BE($)}case D.Identifier:return new nn(z.value);case D.OpenParen:{let $=x();return s(D.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),$}case D.OpenSquareBracket:{let $=[];for(;!a(D.CloseSquareBracket);)$.push(A()),a(D.Comma)&&++r;return++r,new fz($)}case D.OpenCurlyBracket:{let $=new Map;for(;!a(D.CloseCurlyBracket);){let B=A();s(D.Colon,"Expected colon between key and value in object literal");let Q=A();$.set(B,Q),a(D.Comma)&&++r}return++r,new dz($)}default:throw new SyntaxError(`Unexpected token: ${z.type}`)}}for(;r<t.length;)e.body.push(o());return e}function Az(t,e,r=1){if(e===void 0&&(e=t,t=0),r===0)throw new Error("range() step must not be zero");let s=[];if(r>0)for(let n=t;n<e;n+=r)s.push(n);else for(let n=t;n>e;n+=r)s.push(n);return s}function jE(t,e,r,s=1){let n=Math.sign(s);n>=0?(e=(e??=0)<0?Math.max(t.length+e,0):Math.min(e,t.length),r=(r??=t.length)<0?Math.max(t.length+r,0):Math.min(r,t.length)):(e=(e??=t.length-1)<0?Math.max(t.length+e,-1):Math.min(e,t.length-1),r=(r??=-1)<-1?Math.max(t.length+r,-1):Math.min(r,t.length-1));let o=[];for(let a=e;n*a<n*r;a+=s)o.push(t[a]);return o}function Mz(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function Tz(t){return Sz(new Date,t)}function Sz(t,e){let r=new Intl.DateTimeFormat(void 0,{month:"long"}),s=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 s.format(t);case"%B":return r.format(t);case"%H":return n(t.getHours());case"%M":return n(t.getMinutes());case"%%":return"%";default:return o}})}function Oz(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Iz(t,e,r,s){if(s===0)return t;let n=s==null||s<0?1/0:s,o=e.length===0?new RegExp("(?=)","gu"):new RegExp(Oz(e),"gu");return t.replaceAll(o,a=>n>0?(--n,r):a)}var GE=class extends Error{},qE=class extends Error{},ar=class{type="RuntimeValue";value;builtins=new Map;constructor(t=void 0){this.value=t}__bool__(){return new de(!!this.value)}toString(){return String(this.value)}},he=class extends ar{type="IntegerValue"},Ze=class extends ar{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},te=class extends ar{type="StringValue";builtins=new Map([["upper",new Xe(()=>new te(this.value.toUpperCase()))],["lower",new Xe(()=>new te(this.value.toLowerCase()))],["strip",new Xe(()=>new te(this.value.trim()))],["title",new Xe(()=>new te(Mz(this.value)))],["capitalize",new Xe(()=>new te(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],["length",new he(this.value.length)],["rstrip",new Xe(()=>new te(this.value.trimEnd()))],["lstrip",new Xe(()=>new te(this.value.trimStart()))],["startswith",new Xe(t=>{if(t.length===0)throw new Error("startswith() requires at least one argument");let e=t[0];if(e instanceof te)return new de(this.value.startsWith(e.value));if(e instanceof ye){for(let r of e.value){if(!(r instanceof te))throw new Error("startswith() tuple elements must be strings");if(this.value.startsWith(r.value))return new de(!0)}return new de(!1)}throw new Error("startswith() argument must be a string or tuple of strings")})],["endswith",new Xe(t=>{if(t.length===0)throw new Error("endswith() requires at least one argument");let e=t[0];if(e instanceof te)return new de(this.value.endsWith(e.value));if(e instanceof ye){for(let r of e.value){if(!(r instanceof te))throw new Error("endswith() tuple elements must be strings");if(this.value.endsWith(r.value))return new de(!0)}return new de(!1)}throw new Error("endswith() argument must be a string or tuple of strings")})],["split",new Xe(t=>{let e=t[0]??new Ke;if(!(e instanceof te||e instanceof Ke))throw new Error("sep argument must be a string or null");let r=t[1]??new he(-1);if(!(r instanceof he))throw new Error("maxsplit argume