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 • 558 kB
var WI=Object.defineProperty;var _s=(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 hs=(t,e)=>{for(var r in e)WI(t,r,{get:e[r],enumerable:!0})};var gt={};var Ut={};var gE={};var VI="4.2.0",Of=typeof self<"u",on=!kE(gt),yE=!kE(Ut),oc=Of&&"caches"in self,HI=typeof globalThis.Deno<"u",T3=typeof globalThis.Bun<"u",ic=HI&&oc&&!on,bE=typeof process<"u",vE=bE&&process?.release?.name==="node"&&!ic,If=typeof window<"u"&&typeof window.document<"u",Cf=Of&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),XI=If||Cf||ic,YI=vE||typeof navigator<"u"&&"gpu"in navigator,KI=typeof navigator<"u"&&"ml"in navigator,QI=typeof crypto<"u"&&typeof crypto.getRandomValues=="function",JI=typeof chrome<"u"&&typeof chrome.runtime<"u"&&typeof chrome.runtime.id=="string",ZI=typeof ServiceWorkerGlobalScope<"u"&&Of&&self instanceof ServiceWorkerGlobalScope,eC=()=>{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},tC=eC(),ie=Object.freeze({IS_BROWSER_ENV:If,IS_WEBWORKER_ENV:Cf,IS_WEB_ENV:XI,IS_SERVICE_WORKER_ENV:ZI,IS_DENO_WEB_RUNTIME:ic,IS_WEB_CACHE_AVAILABLE:oc,IS_WEBGPU_AVAILABLE:YI,IS_WEBNN_AVAILABLE:KI,IS_SAFARI:tC,IS_PROCESS_AVAILABLE:bE,IS_NODE_ENV:vE,IS_FS_AVAILABLE:on,IS_PATH_AVAILABLE:yE,IS_CRYPTO_AVAILABLE:QI,IS_CHROME_AVAILABLE:JI}),Pf=on&&yE,ac="./";if(Pf){let t=Object(import.meta).url;t?ac=Ut.dirname(Ut.dirname(gE.fileURLToPath(t))):typeof __dirname<"u"&&(ac=Ut.dirname(__dirname))}var rC=Pf?Ut.join(ac,"/.cache/"):null,wE="/models/",sC=Pf?Ut.join(ac,wE):wE,nC=typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,It=Object.freeze({DEBUG:10,INFO:20,WARNING:30,ERROR:40,NONE:50}),xE=It.WARNING,_e={version:VI,backends:{onnx:{}},get logLevel(){return xE},set logLevel(t){xE=t,_e.backends.onnx?.setLogLevel?.(t)},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(If||Cf||ic),localModelPath:sC,useFS:on,useBrowserCache:oc,useFSCache:on,cacheDir:rC,useCustomCache:!1,customCache:null,useWasmCache:oc||on,cacheKey:"transformers-cache",experimental_useCrossOriginStorage:!1,fetch:nC};function kE(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 lr(t,e){t&&t(e)}var gs=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 EE(t){return Number.isInteger(t)||typeof t=="bigint"}function Lf(t){return t==null||t===-1}function zf(t){let e=[],r=t;for(;Array.isArray(r);)e.push(r.length),r=r[0];return e}function wt(...t){return Array.prototype.concat.apply([],t)}function AE(...t){return t.reduce((e,r)=>e.flatMap(s=>r.map(n=>[s,n])))}function an(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 TE(t,e){let r=0;for(let s of t)s===e&&++r;return r}var ee={error(...t){_e.logLevel<=It.ERROR&&console.error(...t)},warn(...t){_e.logLevel<=It.WARNING&&console.warn(...t)},info(...t){_e.logLevel<=It.INFO&&console.log(...t)},debug(...t){_e.logLevel<=It.DEBUG&&console.log(...t)},log(...t){this.info(...t)}};var oC=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}},ME=oC,aC=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}},iC=aC,zE=(()=>{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]]))})(),lC=t=>Object.fromEntries(Object.entries(t).map(([e,r])=>[r,e])),cC=lC(zE),SE=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",uC=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|[${SE}])]+`,` ?[^\\s${SE}]+`]]),lc="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",Rf=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"),cc=(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 uC)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=pC(t.String);return new RegExp(e?r:`(${r})`,"gu")}else return console.warn("Unknown pattern type:",t),null},pC=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),fC=(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},dC=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,mC=t=>Number.isInteger(t)||typeof t=="bigint",_C=t=>{let e=0;for(let r of t)++e;return e},hC=t=>NE(t.toLowerCase()),Yt=(...t)=>Array.prototype.concat.apply([],t),$f=t=>new Map(Object.entries(t)),gC=(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},NE=t=>t.replace(/\p{M}/gu,""),OE=(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},wC=t=>t.match(/\S+/g)||[],xC=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},po=xC,yC=class extends po{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},vr=yC,bC=class extends vr{tokenize_chinese_chars(t){let e=[];for(let r=0;r<t.length;++r){let s=t[r],n=s.charCodeAt(0);dC(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}},vC=bC,kC=class extends vr{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}},EC=kC,AC=class extends vr{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>RE(e))}normalize(t){return this.normalizers.reduce((e,r)=>r?r.normalize(e):e,t)}},TC=AC,MC=class extends vr{normalize(t){let e=cc(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},SC=MC,OC=class extends vr{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},uc=OC,IC=class extends uc{constructor(){super(...arguments),this.form="NFC"}},CC=IC,PC=class extends uc{constructor(){super(...arguments),this.form="NFD"}},LC=PC,zC=class extends uc{constructor(){super(...arguments),this.form="NFKC"}},NC=zC,RC=class extends uc{constructor(){super(...arguments),this.form="NFKD"}},$C=RC,DC=class extends vr{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=DC,UC=class extends vr{normalize(t){return NE(t)}},FC=UC,GC=class extends vr{normalize(t){return t.toLowerCase()}},jC=GC,qC=class extends vr{normalize(t){return t=this.config.prepend+t,t}},WC=qC;function VC(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new vC(t);case"Precompiled":return new EC(t);case"Sequence":return new TC(t);case"Replace":return new SC(t);case"NFC":return new CC(t);case"NFD":return new LC(t);case"NFKC":return new NC(t);case"NFKD":return new $C(t);case"Strip":return new BC(t);case"StripAccents":return new FC(t);case"Lowercase":return new jC(t);case"Prepend":return new WC(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var RE=VC,HC=class extends po{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)}},Kt=HC,XC=class extends Kt{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=zE,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(""))}},YC=XC,KC=class extends Kt{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},QC=KC,JC=class extends Kt{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]}},ZC=JC,eP=class extends Kt{constructor(t){super(),this.config=t,this.pattern=cc(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):gC(t,this.pattern)}},tP=eP,rP=class extends Kt{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${lc}]+|[${lc}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},sP=rP,nP=class extends Kt{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)||[]}},oP=nP,aP=class extends Kt{constructor(){super(),this.pattern=new RegExp(`[^\\s${lc}]+|[${lc}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},iP=aP,lP=class extends Kt{constructor(t){super(),this.config=t,this.pattern=cc(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},cP=lP,uP=class extends Kt{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>$E(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((r,s)=>s?s.pre_tokenize(r,e):r,[t])}},pP=uP,fP=class extends Kt{pre_tokenize_text(t){return wC(t)}},dP=fP,mP=class extends Kt{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}},_P=mP;function hP(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new iP;case"Sequence":return new pP(t);case"Whitespace":return new QC;case"WhitespaceSplit":return new dP;case"Metaspace":return new ZC(t);case"ByteLevel":return new YC(t);case"Split":return new tP(t);case"Punctuation":return new sP(t);case"Digits":return new oP(t);case"Replace":return new cP(t);case"FixedLength":return new _P(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var $E=hP,gP=class extends po{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=fC(e,this.tokens_to_ids,this.unk_token_id)),e}},pc=gP,wP=class extends pc{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=$f(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}},IE=wP,CE=class DE{constructor(e,r){this.is_leaf=e,this.children=r}static default(){return new DE(!1,new Map)}},xP=class{constructor(){this.root=CE.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=CE.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)}}},yP=xP,Nf=class BE{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 BE(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},bP=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 Nf(this.bos_token_id??0,0,0,0,0),n=new Nf(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 Nf(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 u=c.backtrace_score+a.score;(l===null||u>i)&&(l=c.clone(),i=u)}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)}},vP=bP;function kP(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 EP=class extends pc{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=kP(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new yP,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),u=this.scores[c],f=_C(l);t.insert(s,f,u,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 vP(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}},PE=EP,AP=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}},TP=AP,MP=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()}},SP=MP,OP=class extends pc{constructor(t){super(t),this.tokens_to_ids=$f(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 SP(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 TP((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}},LE=OP,IP=class extends pc{constructor(t,e){super(t);let r=t.vocab;this.tokens_to_ids=$f(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}},CP=IP;function PP(t,e){switch(t.type){case"WordPiece":return new IE(t);case"Unigram":return new PE(t,e.eos_token);case"BPE":return new LE(t);default:if(t.vocab)return Array.isArray(t.vocab)?new PE(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new LE(t):new IE(t):new CP(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 LP=PP,zP=class extends po{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},fo=zP,NP=class extends fo{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=Yt(n,t),o=Yt(o,new Array(t.length).fill(a.Sequence.type_id))):a.Sequence.id==="B"&&(n=Yt(n,e),o=Yt(o,new Array(e.length).fill(a.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},RP=NP,$P=class extends fo{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},DP=$P,BP=class extends fo{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,r=!0){r&&(t=Yt([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=Yt(t,n,e,o),s=Yt(s,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:s}}},UP=BP,FP=class extends fo{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,r=!0){r&&(t=Yt([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=Yt(t,n,e,o),s=Yt(s,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:s}}},GP=FP,jP=class extends fo{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>UE(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}},qP=jP;function WP(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new RP(t);case"ByteLevel":return new DP(t);case"BertProcessing":return new UP(t);case"RobertaProcessing":return new GP(t);case"Sequence":return new qP(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var UE=WP,VP=class extends po{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("")}},Ft=VP,HP=class extends Ft{constructor(t){super(t),this.byte_decoder=cC,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}},XP=HP,YP=class extends Ft{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=Rf(e)),e})}},KP=YP,QP=class extends Ft{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}},JP=QP,ZP=class extends Ft{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,r)=>e.replaceAll(this.suffix,r===t.length-1?"":" "))}},eL=ZP,tL=class extends Ft{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=Rf(s).replaceAll(this.word_delimiter_token," ").trim()),s}decode_chain(t){return[this.convert_tokens_to_string(t)]}},rL=tL,sL=class extends Ft{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>FE(e))}decode_chain(t){return this.decoders.reduce((e,r)=>r.decode_chain(e),t)}},nL=sL,oL=class extends Ft{decode_chain(t){let e=cc(this.config.pattern),r=this.config.content??"";return e===null?t:t.map(s=>s.replaceAll(e,r))}},aL=oL,iL=class extends Ft{decode_chain(t){return[t.join("")]}},lL=iL,cL=class extends Ft{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)})}},uL=cL,pL=class extends Ft{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}},fL=pL;function dL(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new XP(t);case"WordPiece":return new KP(t);case"Metaspace":return new JP(t);case"BPEDecoder":return new eL(t);case"CTC":return new rL(t);case"Sequence":return new nL(t);case"Replace":return new aL(t);case"Fuse":return new lL(t);case"Strip":return new uL(t);case"ByteFallback":return new fL(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var FE=dL,mL=class{constructor(t,e){let r=OE(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(r)throw new Error(r);let s=OE(e,"Config");if(s)throw new Error(s);this.tokenizer=t,this.config=e,this.normalizer=RE(this.tokenizer.normalizer),this.pre_tokenizer=$E(this.tokenizer.pre_tokenizer),this.model=LP(this.tokenizer.model,this.config),this.post_processor=UE(this.tokenizer.post_processor),this.decoder=FE(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 iC(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 ME(n),this.splitter_normalized=new ME(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||!mC(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=Rf(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=hC(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:Yt(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}},GE=mL;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"}),Gt=class{constructor(t,e){this.value=t,this.type=e}};function jE(t){return/\w/.test(t)}function mo(t){return/[0-9]/.test(t)}function qE(t){return/\s/.test(t)}var _L=[["{%",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]],hL=new Map([["n",` `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function gL(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 wL(t,e={}){let r=[],s=gL(t,e),n=0,o=0,a=c=>{let u="";for(;c(s[n]);){if(s[n]==="\\"){if(++n,n>=s.length)throw new SyntaxError("Unexpected end of input");let f=s[n++],m=hL.get(f);if(m===void 0)throw new SyntaxError(`Unexpected escaped character: ${f}`);u+=m;continue}if(u+=s[n++],n>=s.length)throw new SyntaxError("Unexpected end of input")}return u},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&&qE(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 Gt(f,D.Text));continue}}if(s[n]==="{"&&s[n+1]==="#"){n+=2;let f=s[n]==="-";f&&++n;let m="";for(;s[n]!=="#"||s[n+1]!=="}";){if(n+2>=s.length)throw new SyntaxError("Missing end of comment tag");m+=s[n++]}let _=m.endsWith("-");_&&(m=m.slice(0,-1)),f&&i(),r.push(new Gt(m,D.Comment)),n+=2,_&&l();continue}if(s.slice(n,n+3)==="{%-"){i(),r.push(new Gt("{%",D.OpenStatement)),n+=3;continue}if(s.slice(n,n+3)==="{{-"){i(),r.push(new Gt("{{",D.OpenExpression)),o=0,n+=3;continue}if(a(qE),s.slice(n,n+3)==="-%}"){r.push(new Gt("%}",D.CloseStatement)),n+=3,l();continue}if(s.slice(n,n+3)==="-}}"){r.push(new Gt("}}",D.CloseExpression)),n+=3,l();continue}let u=s[n];if(u==="-"||u==="+"){let f=r.at(-1)?.type;if(f===D.Text||f===void 0)throw new SyntaxError(`Unexpected character: ${u}`);switch(f){case D.Identifier:case D.NumericLiteral:case D.StringLiteral:case D.CloseParen:case D.CloseSquareBracket:break;default:{++n;let m=a(mo);r.push(new Gt(`${u}${m}`,m.length>0?D.NumericLiteral:D.UnaryOperator));continue}}}for(let[f,m]of _L){if(f==="}}"&&o>0)continue;if(s.slice(n,n+f.length)===f){r.push(new Gt(f,m)),m===D.OpenExpression?o=0:m===D.OpenCurlyBracket?++o:m===D.CloseCurlyBracket&&--o,n+=f.length;continue e}}if(u==="'"||u==='"'){++n;let f=a(m=>m!==u);r.push(new Gt(f,D.StringLiteral)),++n;continue}if(mo(u)){let f=a(mo);if(s[n]==="."&&mo(s[n+1])){++n;let m=a(mo);f=`${f}.${m}`}r.push(new Gt(f,D.NumericLiteral));continue}if(jE(u)){let f=a(jE);r.push(new Gt(f,D.Identifier));continue}throw new SyntaxError(`Unexpected character: ${u}`)}return r}var Jt=class{type="Statement"},xL=class extends Jt{constructor(t){super(),this.body=t}type="Program"},yL=class extends Jt{constructor(t,e,r){super(),this.test=t,this.body=e,this.alternate=r}type="If"},bL=class extends Jt{constructor(t,e,r,s){super(),this.loopvar=t,this.iterable=e,this.body=r,this.defaultBlock=s}type="For"},vL=class extends Jt{type="Break"},kL=class extends Jt{type="Continue"},EL=class extends Jt{constructor(t,e,r){super(),this.assignee=t,this.value=e,this.body=r}type="Set"},AL=class extends Jt{constructor(t,e,r){super(),this.name=t,this.args=e,this.body=r}type="Macro"},TL=class extends Jt{constructor(t){super(),this.value=t}type="Comment"},Lt=class extends Jt{type="Expression"},ML=class extends Lt{constructor(t,e,r){super(),this.object=t,this.property=e,this.computed=r}type="MemberExpression"},WE=class extends Lt{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},ln=class extends Lt{constructor(t){super(),this.value=t}type="Identifier"},cn=class extends Lt{constructor(t){super(),this.value=t}type="Literal"},SL=class extends cn{type="IntegerLiteral"},OL=class extends cn{type="FloatLiteral"},VE=class extends cn{type="StringLiteral"},IL=class extends cn{type="ArrayLiteral"},HE=class extends cn{type="TupleLiteral"},CL=class extends cn{type="ObjectLiteral"},_o=class extends Lt{constructor(t,e,r){super(),this.operator=t,this.left=e,this.right=r}type="BinaryExpression"},PL=class extends Lt{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},LL=class extends Jt{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},zL=class extends Lt{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},NL=class extends Lt{constructor(t,e,r){super(),this.operand=t,this.negate=e,this.test=r}type="TestExpression"},RL=class extends Lt{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},$L=class extends Lt{constructor(t=void 0,e=void 0,r=void 0){super(),this.start=t,this.stop=e,this.step=r}type="SliceExpression"},DL=class extends Lt{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},BL=class extends Lt{constructor(t){super(),this.argument=t}type="SpreadExpression"},UL=class extends Jt{constructor(t,e,r){super(),this.call=t,this.callerArgs=e,this.body=r}type="CallStatement"},FL=class extends Lt{constructor(t,e,r){super(),this.condition=t,this.trueExpr=e,this.falseExpr=r}type="Ternary"};function GL(t){let e=new xL([]),r=0;function s(L,R){let U=t[r++];if(!U||U.type!==L)throw new Error(`Parser Error: ${R}. ${U.type} !== ${L}.`);return U}function n(L){if(!l(L))throw new SyntaxError(`Expected ${L}`);++r}function o(){switch(t[r].type){case D.Comment:return new TL(t[r++].value);case D.Text:return c();case D.OpenStatement:return u();case D.OpenExpression:return f();default:throw new SyntaxError(`Unexpected token type: ${t[r].type}`)}}function a(...L){return r+L.length<=t.length&&L.every((R,U)=>R===t[r+U].type)}function i(...L){return t[r]?.type===D.OpenStatement&&t[r+1]?.type===D.Identifier&&L.includes(t[r+1]?.value)}function l(...L){return r+L.length<=t.length&&L.every((R,U)=>t[r+U].type==="Identifier"&&R===t[r+U].value)}function c(){return new VE(s(D.Text,"Expected text token").value)}function u(){if(s(D.OpenStatement,"Expected opening statement token"),t[r].type!==D.Identifier)throw new SyntaxError(`Unknown statement, got ${t[r].type}`);let L=t[r].value,R;switch(L){case"set":++r,R=m();break;case"if":++r,R=_(),s(D.OpenStatement,"Expected {% token"),n("endif"),s(D.CloseStatement,"Expected %} token");break;case"macro":++r,R=w(),s(D.OpenStatement,"Expected {% token"),n("endmacro"),s(D.CloseStatement,"Expected %} token");break;case"for":++r,R=b(),s(D.OpenStatement,"Expected {% token"),n("endfor"),s(D.CloseStatement,"Expected %} token");break;case"call":{++r;let U=null;a(D.OpenParen)&&(U=F());let Q=K();if(Q.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let le=F();s(D.CloseStatement,"Expected closing statement token");let je=[];for(;!i("endcall");)je.push(o());s(D.OpenStatement,"Expected '{%'"),n("endcall"),s(D.CloseStatement,"Expected closing statement token");let ce=new WE(Q,le);R=new UL(ce,U,je);break}case"break":++r,s(D.CloseStatement,"Expected closing statement token"),R=new vL;break;case"continue":++r,s(D.CloseStatement,"Expected closing statement token"),R=new kL;break;case"filter":{++r;let U=K();U instanceof ln&&a(D.OpenParen)&&(U=G(U)),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 '%}'"),R=new LL(U,Q);break}default:throw new SyntaxError(`Unknown statement type: ${L}`)}return R}function f(){s(D.OpenExpression,"Expected opening expression token");let L=A();return s(D.CloseExpression,"Expected closing expression token"),L}function m(){let L=x(),R=null,U=[];if(a(D.Equals))++r,R=x();else{for(s(D.CloseStatement,"Expected %} token");!i("endset");)U.push(o());s(D.OpenStatement,"Expected {% token"),n("endset")}return s(D.CloseStatement,"Expected closing statement token"),new EL(L,R,U)}function _(){let L=A();s(D.CloseStatement,"Expected closing statement token");let R=[],U=[];for(;!i("elif","else","endif");)R.push(o());if(i("elif")){++r,++r;let Q=_();U.push(Q)}else if(i("else"))for(++r,++r,s(D.CloseStatement,"Expected closing statement token");!i("endif");)U.push(o());return new yL(L,R,U)}function w(){let L=K();if(L.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let R=F();s(D.CloseStatement,"Expected closing statement token");let U=[];for(;!i("endmacro");)U.push(o());return new AL(L,R,U)}function x(L=!1){let R=L?K:A,U=[R()],Q=a(D.Comma);for(;Q&&(++r,U.push(R()),!!a(D.Comma)););return Q?new HE(U):U[0]}function b(){let L=x(!0);if(!(L instanceof ln||L instanceof HE))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${L.type} instead`);if(!l("in"))throw new SyntaxError("Expected `in` keyword following loop variable");++r;let R=A();s(D.CloseStatement,"Expected closing statement token");let U=[];for(;!i("endfor","else");)U.push(o());let Q=[];if(i("else"))for(++r,++r,s(D.CloseStatement,"Expected closing statement token");!i("endfor");)Q.push(o());return new bL(L,R,U,Q)}function A(){return k()}function k(){let L=S();if(l("if")){++r;let R=S();if(l("else")){++r;let U=k();return new FL(R,L,U)}else return new zL(L,R)}return L}function S(){let L=M();for(;l("or");){let R=t[r];++r;let U=M();L=new _o(R,L,U)}return L}function M(){let L=O();for(;l("and");){let R=t[r];++r;let U=O();L=new _o(R,L,U)}return L}function O(){let L;for(;l("not");){let R=t[r];++r;let U=O();L=new RL(R,U)}return L??I()}function I(){let L=v();for(;;){let R;if(l("not","in"))R=new Gt("not in",D.Identifier),r+=2;else if(l("in"))R=t[r++];else if(a(D.ComparisonBinaryOperator))R=t[r++];else break;let U=v();L=new _o(R,L,U)}return L}function v(){let L=$();for(;a(D.AdditiveBinaryOperator);){let R=t[r];++r;let U=$();L=new _o(R,L,U)}return L}function B(){let L=J(K());return a(D.OpenParen)?G(L):L}function G(L){let R=new WE(L,F());return R=J(R),a(D.OpenParen)&&(R=G(R)),R}function F(){s(D.OpenParen,"Expected opening parenthesis for arguments list");let L=X();return s(D.CloseParen,"Expected closing parenthesis for arguments list"),L}function X(){let L=[];for(;!a(D.CloseParen);){let R;if(t[r].type===D.MultiplicativeBinaryOperator&&t[r].value==="*"){++r;let U=A();R=new BL(U)}else if(R=A(),a(D.Equals)){if(++r,!(R instanceof ln))throw new SyntaxError("Expected identifier for keyword argument");let U=A();R=new DL(R,U)}L.push(R),a(D.Comma)&&++r}return L}function Y(){let L=[],R=!1;for(;!a(D.CloseSquareBracket);)a(D.Colon)?(L.push(void 0),++r,R=!0):(L.push(A()),a(D.Colon)&&(++r,R=!0));if(L.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if(R){if(L.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new $L(...L)}return L[0]}function J(L){for(;a(D.Dot)||a(D.OpenSquareBracket);){let R=t[r];++r;let U,Q=R.type===D.OpenSquareBracket;if(Q)U=Y(),s(D.CloseSquareBracket,"Expected closing square bracket");else if(U=K(),U.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");L=new ML(L,U,Q)}return L}function $(){let L=C();for(;a(D.MultiplicativeBinaryOperator);){let R=t[r++],U=C();L=new _o(R,L,U)}return L}function C(){let L=se();for(;l("is");){++r;let R=l("not");R&&++r;let U=K();if(!(U instanceof ln))throw new SyntaxError("Expected identifier for the test");L=new NL(L,R,U)}return L}function se(){let L=B();for(;a(D.Pipe);){++r;let R=K();if(!(R instanceof ln))throw new SyntaxError("Expected identifier for the filter");a(D.OpenParen)&&(R=G(R)),L=new PL(L,R)}return L}function K(){let L=t[r++];switch(L.type){case D.NumericLiteral:{let R=L.value;return R.includes(".")?new OL(Number(R)):new SL(Number(R))}case D.StringLiteral:{let R=L.value;for(;a(D.StringLiteral);)R+=t[r++].value;return new VE(R)}case D.Identifier:return new ln(L.value);case D.OpenParen:{let R=x();return s(D.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),R}case D.OpenSquareBracket:{let R=[];for(;!a(D.CloseSquareBracket);)R.push(A()),a(D.Comma)&&++r;return++r,new IL(R)}case D.OpenCurlyBracket:{let R=new Map;for(;!a(D.CloseCurlyBracket);){let U=A();s(D.Colon,"Expected colon between key and value in object literal");let Q=A();R.set(U,Q),a(D.Comma)&&++r}return++r,new CL(R)}default:throw new SyntaxError(`Unexpected token: ${L.type}`)}}for(;r<t.length;)e.body.push(o());return e}function jL(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 XE(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 qL(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function WL(t){return VL(new Date,t)}function VL(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 HL(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function XL(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(HL(e),"gu");return t.replaceAll(o,a=>n>0?(--n,r):a)}var YE=class extends Error{},KE=class extends Error{},cr=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 cr{type="IntegerValue"},Ze=class extends cr{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},te=class extends cr{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(qL(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 Ye;if(!(e instanceof te||e instanceof Ye))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 argument must be a number");let s=[]