@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
2 lines • 48.1 kB
JavaScript
'use strict';var core=require('@drincs/pixi-vn/core');var mt=Object.create;var Be=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var gt=Object.getOwnPropertyNames;var Lt=Object.getPrototypeOf,Tt=Object.prototype.hasOwnProperty;var et=h=>{throw TypeError(h)};var _t=(h,e,t)=>e in h?Be(h,e,{enumerable:true,configurable:true,writable:true,value:t}):h[e]=t;var je=(h=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(h,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):h)(function(h){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+h+'" is not supported')});var tt=(h,e)=>()=>(e||h((e={exports:{}}).exports,e),e.exports);var Et=(h,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of gt(e))!Tt.call(h,i)&&i!==t&&Be(h,i,{get:()=>e[i],enumerable:!(n=St(e,i))||n.enumerable});return h};var Ct=(h,e,t)=>(t=h!=null?mt(Lt(h)):{},Et(Be(t,"default",{value:h,enumerable:true}),h));var E=(h,e,t)=>_t(h,typeof e!="symbol"?e+"":e,t),ke=(h,e,t)=>e.has(h)||et("Cannot "+t);var r=(h,e,t)=>(ke(h,e,"read from private field"),t?t.call(h):e.get(h)),x=(h,e,t)=>e.has(h)?et("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,t),S=(h,e,t,n)=>(ke(h,e,"write to private field"),e.set(h,t),t),f=(h,e,t)=>(ke(h,e,"access private method"),t);var Ye=(h,e,t,n)=>({set _(i){S(h,e,i);},get _(){return r(h,e,n)}});var ut=tt((He,ct)=>{(function(h,e){typeof He=="object"?ct.exports=He=e():typeof define=="function"&&define.amd?define([],e):h.CryptoJS=e();})(He,function(){var h=h||(function(e,t){var n;if(typeof window<"u"&&window.crypto&&(n=window.crypto),typeof self<"u"&&self.crypto&&(n=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(n=globalThis.crypto),!n&&typeof window<"u"&&window.msCrypto&&(n=window.msCrypto),!n&&typeof global<"u"&&global.crypto&&(n=global.crypto),!n&&typeof je=="function")try{n=je("crypto");}catch{}var i=function(){if(n){if(typeof n.getRandomValues=="function")try{return n.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof n.randomBytes=="function")try{return n.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function a(){}return function(d){var O;return a.prototype=d,O=new a,a.prototype=null,O}})(),o={},l=o.lib={},p=l.Base=(function(){return {extend:function(a){var d=s(this);return a&&d.mixIn(a),(!d.hasOwnProperty("init")||this.init===d.init)&&(d.init=function(){d.$super.init.apply(this,arguments);}),d.init.prototype=d,d.$super=this,d},create:function(){var a=this.extend();return a.init.apply(a,arguments),a},init:function(){},mixIn:function(a){for(var d in a)a.hasOwnProperty(d)&&(this[d]=a[d]);a.hasOwnProperty("toString")&&(this.toString=a.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),m=l.WordArray=p.extend({init:function(a,d){a=this.words=a||[],d!=t?this.sigBytes=d:this.sigBytes=a.length*4;},toString:function(a){return (a||T).stringify(this)},concat:function(a){var d=this.words,O=a.words,I=this.sigBytes,w=a.sigBytes;if(this.clamp(),I%4)for(var Y=0;Y<w;Y++){var le=O[Y>>>2]>>>24-Y%4*8&255;d[I+Y>>>2]|=le<<24-(I+Y)%4*8;}else for(var H=0;H<w;H+=4)d[I+H>>>2]=O[H>>>2];return this.sigBytes+=w,this},clamp:function(){var a=this.words,d=this.sigBytes;a[d>>>2]&=4294967295<<32-d%4*8,a.length=e.ceil(d/4);},clone:function(){var a=p.clone.call(this);return a.words=this.words.slice(0),a},random:function(a){for(var d=[],O=0;O<a;O+=4)d.push(i());return new m.init(d,a)}}),u=o.enc={},T=u.Hex={stringify:function(a){for(var d=a.words,O=a.sigBytes,I=[],w=0;w<O;w++){var Y=d[w>>>2]>>>24-w%4*8&255;I.push((Y>>>4).toString(16)),I.push((Y&15).toString(16));}return I.join("")},parse:function(a){for(var d=a.length,O=[],I=0;I<d;I+=2)O[I>>>3]|=parseInt(a.substr(I,2),16)<<24-I%8*4;return new m.init(O,d/2)}},D=u.Latin1={stringify:function(a){for(var d=a.words,O=a.sigBytes,I=[],w=0;w<O;w++){var Y=d[w>>>2]>>>24-w%4*8&255;I.push(String.fromCharCode(Y));}return I.join("")},parse:function(a){for(var d=a.length,O=[],I=0;I<d;I++)O[I>>>2]|=(a.charCodeAt(I)&255)<<24-I%4*8;return new m.init(O,d)}},P=u.Utf8={stringify:function(a){try{return decodeURIComponent(escape(D.stringify(a)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(a){return D.parse(unescape(encodeURIComponent(a)))}},U=l.BufferedBlockAlgorithm=p.extend({reset:function(){this._data=new m.init,this._nDataBytes=0;},_append:function(a){typeof a=="string"&&(a=P.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes;},_process:function(a){var d,O=this._data,I=O.words,w=O.sigBytes,Y=this.blockSize,le=Y*4,H=w/le;a?H=e.ceil(H):H=e.max((H|0)-this._minBufferSize,0);var Q=H*Y,Te=e.min(Q*4,w);if(Q){for(var We=0;We<Q;We+=Y)this._doProcessBlock(I,We);d=I.splice(0,Q),O.sigBytes-=Te;}return new m.init(d,Te)},clone:function(){var a=p.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0});l.Hasher=U.extend({cfg:p.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset();},reset:function(){U.reset.call(this),this._doReset();},update:function(a){return this._append(a),this._process(),this},finalize:function(a){a&&this._append(a);var d=this._doFinalize();return d},blockSize:512/32,_createHelper:function(a){return function(d,O){return new a.init(O).finalize(d)}},_createHmacHelper:function(a){return function(d,O){return new C.HMAC.init(a,O).finalize(d)}}});var C=o.algo={};return o})(Math);return h});});var ft=tt((Ke,dt)=>{(function(h,e){typeof Ke=="object"?dt.exports=Ke=e(ut()):typeof define=="function"&&define.amd?define(["./core"],e):e(h.CryptoJS);})(Ke,function(h){return (function(){var e=h,t=e.lib,n=t.WordArray,i=t.Hasher,s=e.algo,o=[],l=s.SHA1=i.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(p,m){for(var u=this._hash.words,T=u[0],D=u[1],P=u[2],U=u[3],A=u[4],C=0;C<80;C++){if(C<16)o[C]=p[m+C]|0;else {var a=o[C-3]^o[C-8]^o[C-14]^o[C-16];o[C]=a<<1|a>>>31;}var d=(T<<5|T>>>27)+A+o[C];C<20?d+=(D&P|~D&U)+1518500249:C<40?d+=(D^P^U)+1859775393:C<60?d+=(D&P|D&U|P&U)-1894007588:d+=(D^P^U)-899497514,A=U,U=P,P=D<<30|D>>>2,D=T,T=d;}u[0]=u[0]+T|0,u[1]=u[1]+D|0,u[2]=u[2]+P|0,u[3]=u[3]+U|0,u[4]=u[4]+A|0;},_doFinalize:function(){var p=this._data,m=p.words,u=this._nDataBytes*8,T=p.sigBytes*8;return m[T>>>5]|=128<<24-T%32,m[(T+64>>>9<<4)+14]=Math.floor(u/4294967296),m[(T+64>>>9<<4)+15]=u,p.sigBytes=m.length*4,this._process(),this._hash},clone:function(){var p=i.clone.call(this);return p._hash=this._hash.clone(),p}});e.SHA1=i._createHelper(l),e.HmacSHA1=i._createHmacHelper(l);})(),h.SHA1});});var v="narration";var R={CURRENT_DIALOGUE_MEMORY_KEY:"dialogue",LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY:"dialogue:step_counter",CURRENT_MENU_OPTIONS_MEMORY_KEY:"choice:options",LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY:"choice:step_counter",CURRENT_INPUT_VALUE_MEMORY_KEY:"input:value",LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY:"input:step_counter",CURRENT_INPUT_INFO_MEMORY_KEY:"input:info",CHARACTER_CATEGORY_KEY:"character",ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY:"___glue___",OPENED_LABELS_COUNTER_KEY:"label:opened",ALL_CHOICES_MADE_KEY:"choices:made",CURRENT_STEP_TIMES_COUNTER_KEY:"label:history",LAST_STEP_GLUED:"glue:last_step"};var It=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,st=new Set,$e=typeof process=="object"&&process?process:{},ot=(h,e,t,n)=>{typeof $e.emitWarning=="function"?$e.emitWarning(h,e,t,n):console.error(`[${t}] ${e}: ${h}`);},ze=globalThis.AbortController,rt=globalThis.AbortSignal;if(typeof ze>"u"){rt=class{constructor(){E(this,"onabort");E(this,"_onabort",[]);E(this,"reason");E(this,"aborted",false);}addEventListener(t,n){this._onabort.push(n);}},ze=class{constructor(){E(this,"signal",new rt);e();}abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let n of this.signal._onabort)n(t);this.signal.onabort?.(t);}}};let h=$e.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{h&&(h=false,ot("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e));};}var Ot=h=>!st.has(h);var de=h=>h&&h===Math.floor(h)&&h>0&&isFinite(h),at=h=>de(h)?h<=Math.pow(2,8)?Uint8Array:h<=Math.pow(2,16)?Uint16Array:h<=Math.pow(2,32)?Uint32Array:h<=Number.MAX_SAFE_INTEGER?Fe:null:null,Fe=class extends Array{constructor(h){super(h),this.fill(0);}},he,_e,Rt=(he=class{constructor(e,t){E(this,"heap");E(this,"length");if(!r(he,_e))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}static create(e){let t=at(e);if(!t)return [];S(he,_e,true);let n=new he(e,t);return S(he,_e,false),n}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},_e=new WeakMap,x(he,_e,false),he),nt,it,J,j,Z,Se,ee,Ee,Ce,te,V,re,F,N,_,W,k,K,G,ne,z,ie,se,$,q,oe,me,B,Ie,c,qe,ge,pe,Ne,X,ht,Le,Oe,De,fe,be,Xe,Ve,Ge,M,Je,Me,ye,Qe,Re,lt=(Re=class{constructor(e){x(this,c);x(this,J);x(this,j);x(this,Z);x(this,Se);x(this,ee);x(this,Ee);x(this,Ce);x(this,te);E(this,"ttl");E(this,"ttlResolution");E(this,"ttlAutopurge");E(this,"updateAgeOnGet");E(this,"updateAgeOnHas");E(this,"allowStale");E(this,"noDisposeOnSet");E(this,"noUpdateTTL");E(this,"maxEntrySize");E(this,"sizeCalculation");E(this,"noDeleteOnFetchRejection");E(this,"noDeleteOnStaleGet");E(this,"allowStaleOnFetchAbort");E(this,"allowStaleOnFetchRejection");E(this,"ignoreFetchAbort");x(this,V);x(this,re);x(this,F);x(this,N);x(this,_);x(this,W);x(this,k);x(this,K);x(this,G);x(this,ne);x(this,z);x(this,ie);x(this,se);x(this,$);x(this,q);x(this,oe);x(this,me);x(this,B);x(this,Ie);x(this,ge,()=>{});x(this,pe,()=>{});x(this,Ne,()=>{});x(this,X,()=>false);x(this,Le,e=>{});x(this,Oe,(e,t,n)=>{});x(this,De,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});E(this,nt,"LRUCache");let{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:s,updateAgeOnGet:o,updateAgeOnHas:l,allowStale:p,dispose:m,onInsert:u,disposeAfter:T,noDisposeOnSet:D,noUpdateTTL:P,maxSize:U=0,maxEntrySize:A=0,sizeCalculation:C,fetchMethod:a,memoMethod:d,noDeleteOnFetchRejection:O,noDeleteOnStaleGet:I,allowStaleOnFetchRejection:w,allowStaleOnFetchAbort:Y,ignoreFetchAbort:le,perf:H}=e;if(H!==void 0&&typeof H?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(S(this,te,H??It),t!==0&&!de(t))throw new TypeError("max option must be a nonnegative integer");let Q=t?at(t):Array;if(!Q)throw new Error("invalid max value: "+t);if(S(this,J,t),S(this,j,U),this.maxEntrySize=A||r(this,j),this.sizeCalculation=C,this.sizeCalculation){if(!r(this,j)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(d!==void 0&&typeof d!="function")throw new TypeError("memoMethod must be a function if defined");if(S(this,Ce,d),a!==void 0&&typeof a!="function")throw new TypeError("fetchMethod must be a function if specified");if(S(this,Ee,a),S(this,me,!!a),S(this,F,new Map),S(this,N,new Array(t).fill(void 0)),S(this,_,new Array(t).fill(void 0)),S(this,W,new Q(t)),S(this,k,new Q(t)),S(this,K,0),S(this,G,0),S(this,ne,Rt.create(t)),S(this,V,0),S(this,re,0),typeof m=="function"&&S(this,Z,m),typeof u=="function"&&S(this,Se,u),typeof T=="function"?(S(this,ee,T),S(this,z,[])):(S(this,ee,void 0),S(this,z,void 0)),S(this,oe,!!r(this,Z)),S(this,Ie,!!r(this,Se)),S(this,B,!!r(this,ee)),this.noDisposeOnSet=!!D,this.noUpdateTTL=!!P,this.noDeleteOnFetchRejection=!!O,this.allowStaleOnFetchRejection=!!w,this.allowStaleOnFetchAbort=!!Y,this.ignoreFetchAbort=!!le,this.maxEntrySize!==0){if(r(this,j)!==0&&!de(r(this,j)))throw new TypeError("maxSize must be a positive integer if specified");if(!de(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");f(this,c,ht).call(this);}if(this.allowStale=!!p,this.noDeleteOnStaleGet=!!I,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!l,this.ttlResolution=de(i)||i===0?i:1,this.ttlAutopurge=!!s,this.ttl=n||0,this.ttl){if(!de(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,c,qe).call(this);}if(r(this,J)===0&&this.ttl===0&&r(this,j)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!r(this,J)&&!r(this,j)){let Te="LRU_CACHE_UNBOUNDED";Ot(Te)&&(st.add(Te),ot("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Te,Re));}}get perf(){return r(this,te)}static unsafeExposeInternals(e){return {starts:r(e,se),ttls:r(e,$),autopurgeTimers:r(e,q),sizes:r(e,ie),keyMap:r(e,F),keyList:r(e,N),valList:r(e,_),next:r(e,W),prev:r(e,k),get head(){return r(e,K)},get tail(){return r(e,G)},free:r(e,ne),isBackgroundFetch:t=>{var n;return f(n=e,c,M).call(n,t)},backgroundFetch:(t,n,i,s)=>{var o;return f(o=e,c,Ge).call(o,t,n,i,s)},moveToTail:t=>{var n;return f(n=e,c,Me).call(n,t)},indexes:t=>{var n;return f(n=e,c,fe).call(n,t)},rindexes:t=>{var n;return f(n=e,c,be).call(n,t)},isStale:t=>{var n;return r(n=e,X).call(n,t)}}}get max(){return r(this,J)}get maxSize(){return r(this,j)}get calculatedSize(){return r(this,re)}get size(){return r(this,V)}get fetchMethod(){return r(this,Ee)}get memoMethod(){return r(this,Ce)}get dispose(){return r(this,Z)}get onInsert(){return r(this,Se)}get disposeAfter(){return r(this,ee)}getRemainingTTL(e){return r(this,F).has(e)?1/0:0}*entries(){for(let e of f(this,c,fe).call(this))r(this,_)[e]!==void 0&&r(this,N)[e]!==void 0&&!f(this,c,M).call(this,r(this,_)[e])&&(yield [r(this,N)[e],r(this,_)[e]]);}*rentries(){for(let e of f(this,c,be).call(this))r(this,_)[e]!==void 0&&r(this,N)[e]!==void 0&&!f(this,c,M).call(this,r(this,_)[e])&&(yield [r(this,N)[e],r(this,_)[e]]);}*keys(){for(let e of f(this,c,fe).call(this)){let t=r(this,N)[e];t!==void 0&&!f(this,c,M).call(this,r(this,_)[e])&&(yield t);}}*rkeys(){for(let e of f(this,c,be).call(this)){let t=r(this,N)[e];t!==void 0&&!f(this,c,M).call(this,r(this,_)[e])&&(yield t);}}*values(){for(let e of f(this,c,fe).call(this))r(this,_)[e]!==void 0&&!f(this,c,M).call(this,r(this,_)[e])&&(yield r(this,_)[e]);}*rvalues(){for(let e of f(this,c,be).call(this))r(this,_)[e]!==void 0&&!f(this,c,M).call(this,r(this,_)[e])&&(yield r(this,_)[e]);}[(it=Symbol.iterator,nt=Symbol.toStringTag,it)](){return this.entries()}find(e,t={}){for(let n of f(this,c,fe).call(this)){let i=r(this,_)[n],s=f(this,c,M).call(this,i)?i.__staleWhileFetching:i;if(s!==void 0&&e(s,r(this,N)[n],this))return this.get(r(this,N)[n],t)}}forEach(e,t=this){for(let n of f(this,c,fe).call(this)){let i=r(this,_)[n],s=f(this,c,M).call(this,i)?i.__staleWhileFetching:i;s!==void 0&&e.call(t,s,r(this,N)[n],this);}}rforEach(e,t=this){for(let n of f(this,c,be).call(this)){let i=r(this,_)[n],s=f(this,c,M).call(this,i)?i.__staleWhileFetching:i;s!==void 0&&e.call(t,s,r(this,N)[n],this);}}purgeStale(){let e=false;for(let t of f(this,c,be).call(this,{allowStale:true}))r(this,X).call(this,t)&&(f(this,c,ye).call(this,r(this,N)[t],"expire"),e=true);return e}info(e){let t=r(this,F).get(e);if(t===void 0)return;let n=r(this,_)[t],i=f(this,c,M).call(this,n)?n.__staleWhileFetching:n;if(i===void 0)return;let s={value:i};if(r(this,$)&&r(this,se)){let o=r(this,$)[t],l=r(this,se)[t];if(o&&l){let p=o-(r(this,te).now()-l);s.ttl=p,s.start=Date.now();}}return r(this,ie)&&(s.size=r(this,ie)[t]),s}dump(){let e=[];for(let t of f(this,c,fe).call(this,{allowStale:true})){let n=r(this,N)[t],i=r(this,_)[t],s=f(this,c,M).call(this,i)?i.__staleWhileFetching:i;if(s===void 0||n===void 0)continue;let o={value:s};if(r(this,$)&&r(this,se)){o.ttl=r(this,$)[t];let l=r(this,te).now()-r(this,se)[t];o.start=Math.floor(Date.now()-l);}r(this,ie)&&(o.size=r(this,ie)[t]),e.unshift([n,o]);}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let i=Date.now()-n.start;n.start=r(this,te).now()-i;}this.set(t,n.value,n);}}set(e,t,n={}){var D,P,U,A;if(t===void 0)return this.delete(e),this;let{ttl:i=this.ttl,start:s,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:l=this.sizeCalculation,status:p}=n,{noUpdateTTL:m=this.noUpdateTTL}=n,u=r(this,De).call(this,e,t,n.size||0,l);if(this.maxEntrySize&&u>this.maxEntrySize)return p&&(p.set="miss",p.maxEntrySizeExceeded=true),f(this,c,ye).call(this,e,"set"),this;let T=r(this,V)===0?void 0:r(this,F).get(e);if(T===void 0)T=r(this,V)===0?r(this,G):r(this,ne).length!==0?r(this,ne).pop():r(this,V)===r(this,J)?f(this,c,Ve).call(this,false):r(this,V),r(this,N)[T]=e,r(this,_)[T]=t,r(this,F).set(e,T),r(this,W)[r(this,G)]=T,r(this,k)[T]=r(this,G),S(this,G,T),Ye(this,V)._++,r(this,Oe).call(this,T,u,p),p&&(p.set="add"),m=false,r(this,Ie)&&((D=r(this,Se))==null||D.call(this,t,e,"add"));else {f(this,c,Me).call(this,T);let C=r(this,_)[T];if(t!==C){if(r(this,me)&&f(this,c,M).call(this,C)){C.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:a}=C;a!==void 0&&!o&&(r(this,oe)&&((P=r(this,Z))==null||P.call(this,a,e,"set")),r(this,B)&&r(this,z)?.push([a,e,"set"]));}else o||(r(this,oe)&&((U=r(this,Z))==null||U.call(this,C,e,"set")),r(this,B)&&r(this,z)?.push([C,e,"set"]));if(r(this,Le).call(this,T),r(this,Oe).call(this,T,u,p),r(this,_)[T]=t,p){p.set="replace";let a=C&&f(this,c,M).call(this,C)?C.__staleWhileFetching:C;a!==void 0&&(p.oldValue=a);}}else p&&(p.set="update");r(this,Ie)&&this.onInsert?.(t,e,t===C?"update":"replace");}if(i!==0&&!r(this,$)&&f(this,c,qe).call(this),r(this,$)&&(m||r(this,Ne).call(this,T,i,s),p&&r(this,pe).call(this,p,T)),!o&&r(this,B)&&r(this,z)){let C=r(this,z),a;for(;a=C?.shift();)(A=r(this,ee))==null||A.call(this,...a);}return this}pop(){var e;try{for(;r(this,V);){let t=r(this,_)[r(this,K)];if(f(this,c,Ve).call(this,!0),f(this,c,M).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(r(this,B)&&r(this,z)){let t=r(this,z),n;for(;n=t?.shift();)(e=r(this,ee))==null||e.call(this,...n);}}}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,s=r(this,F).get(e);if(s!==void 0){let o=r(this,_)[s];if(f(this,c,M).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(r(this,X).call(this,s))i&&(i.has="stale",r(this,pe).call(this,i,s));else return n&&r(this,ge).call(this,s),i&&(i.has="hit",r(this,pe).call(this,i,s)),true}else i&&(i.has="miss");return false}peek(e,t={}){let{allowStale:n=this.allowStale}=t,i=r(this,F).get(e);if(i===void 0||!n&&r(this,X).call(this,i))return;let s=r(this,_)[i];return f(this,c,M).call(this,s)?s.__staleWhileFetching:s}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:l=this.noDisposeOnSet,size:p=0,sizeCalculation:m=this.sizeCalculation,noUpdateTTL:u=this.noUpdateTTL,noDeleteOnFetchRejection:T=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:D=this.allowStaleOnFetchRejection,ignoreFetchAbort:P=this.ignoreFetchAbort,allowStaleOnFetchAbort:U=this.allowStaleOnFetchAbort,context:A,forceRefresh:C=false,status:a,signal:d}=t;if(!r(this,me))return a&&(a.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:s,status:a});let O={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:s,ttl:o,noDisposeOnSet:l,size:p,sizeCalculation:m,noUpdateTTL:u,noDeleteOnFetchRejection:T,allowStaleOnFetchRejection:D,allowStaleOnFetchAbort:U,ignoreFetchAbort:P,status:a,signal:d},I=r(this,F).get(e);if(I===void 0){a&&(a.fetch="miss");let w=f(this,c,Ge).call(this,e,I,O,A);return w.__returned=w}else {let w=r(this,_)[I];if(f(this,c,M).call(this,w)){let Q=n&&w.__staleWhileFetching!==void 0;return a&&(a.fetch="inflight",Q&&(a.returnedStale=true)),Q?w.__staleWhileFetching:w.__returned=w}let Y=r(this,X).call(this,I);if(!C&&!Y)return a&&(a.fetch="hit"),f(this,c,Me).call(this,I),i&&r(this,ge).call(this,I),a&&r(this,pe).call(this,a,I),w;let le=f(this,c,Ge).call(this,e,I,O,A),H=le.__staleWhileFetching!==void 0&&n;return a&&(a.fetch=Y?"stale":"refresh",H&&Y&&(a.returnedStale=true)),H?le.__staleWhileFetching:le.__returned=le}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw new Error("fetch() returned undefined");return n}memo(e,t={}){let n=r(this,Ce);if(!n)throw new Error("no memoMethod provided to constructor");let{context:i,forceRefresh:s,...o}=t,l=this.get(e,o);if(!s&&l!==void 0)return l;let p=n(e,l,{options:o,context:i});return this.set(e,p,o),p}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,status:o}=t,l=r(this,F).get(e);if(l!==void 0){let p=r(this,_)[l],m=f(this,c,M).call(this,p);return o&&r(this,pe).call(this,o,l),r(this,X).call(this,l)?(o&&(o.get="stale"),m?(o&&n&&p.__staleWhileFetching!==void 0&&(o.returnedStale=true),n?p.__staleWhileFetching:void 0):(s||f(this,c,ye).call(this,e,"expire"),o&&n&&(o.returnedStale=true),n?p:void 0)):(o&&(o.get="hit"),m?p.__staleWhileFetching:(f(this,c,Me).call(this,l),i&&r(this,ge).call(this,l),p))}else o&&(o.get="miss");}delete(e){return f(this,c,ye).call(this,e,"delete")}clear(){return f(this,c,Qe).call(this,"delete")}},J=new WeakMap,j=new WeakMap,Z=new WeakMap,Se=new WeakMap,ee=new WeakMap,Ee=new WeakMap,Ce=new WeakMap,te=new WeakMap,V=new WeakMap,re=new WeakMap,F=new WeakMap,N=new WeakMap,_=new WeakMap,W=new WeakMap,k=new WeakMap,K=new WeakMap,G=new WeakMap,ne=new WeakMap,z=new WeakMap,ie=new WeakMap,se=new WeakMap,$=new WeakMap,q=new WeakMap,oe=new WeakMap,me=new WeakMap,B=new WeakMap,Ie=new WeakMap,c=new WeakSet,qe=function(){let e=new Fe(r(this,J)),t=new Fe(r(this,J));S(this,$,e),S(this,se,t);let n=this.ttlAutopurge?new Array(r(this,J)):void 0;S(this,q,n),S(this,Ne,(l,p,m=r(this,te).now())=>{t[l]=p!==0?m:0,e[l]=p,i(l,p);}),S(this,ge,l=>{t[l]=e[l]!==0?r(this,te).now():0,i(l,e[l]);});let i=this.ttlAutopurge?(l,p)=>{if(n?.[l]&&(clearTimeout(n[l]),n[l]=void 0),p&&p!==0&&n){let m=setTimeout(()=>{r(this,X).call(this,l)&&f(this,c,ye).call(this,r(this,N)[l],"expire");},p+1);m.unref&&m.unref(),n[l]=m;}}:()=>{};S(this,pe,(l,p)=>{if(e[p]){let m=e[p],u=t[p];if(!m||!u)return;l.ttl=m,l.start=u,l.now=s||o();let T=l.now-u;l.remainingTTL=m-T;}});let s=0,o=()=>{let l=r(this,te).now();if(this.ttlResolution>0){s=l;let p=setTimeout(()=>s=0,this.ttlResolution);p.unref&&p.unref();}return l};this.getRemainingTTL=l=>{let p=r(this,F).get(l);if(p===void 0)return 0;let m=e[p],u=t[p];if(!m||!u)return 1/0;let T=(s||o())-u;return m-T},S(this,X,l=>{let p=t[l],m=e[l];return !!m&&!!p&&(s||o())-p>m});},ge=new WeakMap,pe=new WeakMap,Ne=new WeakMap,X=new WeakMap,ht=function(){let e=new Fe(r(this,J));S(this,re,0),S(this,ie,e),S(this,Le,t=>{S(this,re,r(this,re)-e[t]),e[t]=0;}),S(this,De,(t,n,i,s)=>{if(f(this,c,M).call(this,n))return 0;if(!de(i))if(s){if(typeof s!="function")throw new TypeError("sizeCalculation must be a function");if(i=s(n,t),!de(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),S(this,Oe,(t,n,i)=>{if(e[t]=n,r(this,j)){let s=r(this,j)-e[t];for(;r(this,re)>s;)f(this,c,Ve).call(this,true);}S(this,re,r(this,re)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=r(this,re));});},Le=new WeakMap,Oe=new WeakMap,De=new WeakMap,fe=function*({allowStale:e=this.allowStale}={}){if(r(this,V))for(let t=r(this,G);!(!f(this,c,Xe).call(this,t)||((e||!r(this,X).call(this,t))&&(yield t),t===r(this,K)));)t=r(this,k)[t];},be=function*({allowStale:e=this.allowStale}={}){if(r(this,V))for(let t=r(this,K);!(!f(this,c,Xe).call(this,t)||((e||!r(this,X).call(this,t))&&(yield t),t===r(this,G)));)t=r(this,W)[t];},Xe=function(e){return e!==void 0&&r(this,F).get(r(this,N)[e])===e},Ve=function(e){var s;let t=r(this,K),n=r(this,N)[t],i=r(this,_)[t];return r(this,me)&&f(this,c,M).call(this,i)?i.__abortController.abort(new Error("evicted")):(r(this,oe)||r(this,B))&&(r(this,oe)&&((s=r(this,Z))==null||s.call(this,i,n,"evict")),r(this,B)&&r(this,z)?.push([i,n,"evict"])),r(this,Le).call(this,t),r(this,q)?.[t]&&(clearTimeout(r(this,q)[t]),r(this,q)[t]=void 0),e&&(r(this,N)[t]=void 0,r(this,_)[t]=void 0,r(this,ne).push(t)),r(this,V)===1?(S(this,K,S(this,G,0)),r(this,ne).length=0):S(this,K,r(this,W)[t]),r(this,F).delete(n),Ye(this,V)._--,t},Ge=function(e,t,n,i){let s=t===void 0?void 0:r(this,_)[t];if(f(this,c,M).call(this,s))return s;let o=new ze,{signal:l}=n;l?.addEventListener("abort",()=>o.abort(l.reason),{signal:o.signal});let p={signal:o.signal,options:n,context:i},m=(A,C=false)=>{let{aborted:a}=o.signal,d=n.ignoreFetchAbort&&A!==void 0,O=n.ignoreFetchAbort||!!(n.allowStaleOnFetchAbort&&A!==void 0);if(n.status&&(a&&!C?(n.status.fetchAborted=true,n.status.fetchError=o.signal.reason,d&&(n.status.fetchAbortIgnored=true)):n.status.fetchResolved=true),a&&!d&&!C)return T(o.signal.reason,O);let I=P,w=r(this,_)[t];return (w===P||d&&C&&w===void 0)&&(A===void 0?I.__staleWhileFetching!==void 0?r(this,_)[t]=I.__staleWhileFetching:f(this,c,ye).call(this,e,"fetch"):(n.status&&(n.status.fetchUpdated=true),this.set(e,A,p.options))),A},u=A=>(n.status&&(n.status.fetchRejected=true,n.status.fetchError=A),T(A,false)),T=(A,C)=>{let{aborted:a}=o.signal,d=a&&n.allowStaleOnFetchAbort,O=d||n.allowStaleOnFetchRejection,I=O||n.noDeleteOnFetchRejection,w=P;if(r(this,_)[t]===P&&(!I||!C&&w.__staleWhileFetching===void 0?f(this,c,ye).call(this,e,"fetch"):d||(r(this,_)[t]=w.__staleWhileFetching)),O)return n.status&&w.__staleWhileFetching!==void 0&&(n.status.returnedStale=true),w.__staleWhileFetching;if(w.__returned===w)throw A},D=(A,C)=>{var d;let a=(d=r(this,Ee))==null?void 0:d.call(this,e,s,p);a&&a instanceof Promise&&a.then(O=>A(O===void 0?void 0:O),C),o.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(A(void 0),n.allowStaleOnFetchAbort&&(A=O=>m(O,true)));});};n.status&&(n.status.fetchDispatched=true);let P=new Promise(D).then(m,u),U=Object.assign(P,{__abortController:o,__staleWhileFetching:s,__returned:void 0});return t===void 0?(this.set(e,U,{...p.options,status:void 0}),t=r(this,F).get(e)):r(this,_)[t]=U,U},M=function(e){if(!r(this,me))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof ze},Je=function(e,t){r(this,k)[t]=e,r(this,W)[e]=t;},Me=function(e){e!==r(this,G)&&(e===r(this,K)?S(this,K,r(this,W)[e]):f(this,c,Je).call(this,r(this,k)[e],r(this,W)[e]),f(this,c,Je).call(this,r(this,G),e),S(this,G,e));},ye=function(e,t){var i,s;let n=false;if(r(this,V)!==0){let o=r(this,F).get(e);if(o!==void 0)if(r(this,q)?.[o]&&(clearTimeout(r(this,q)?.[o]),r(this,q)[o]=void 0),n=true,r(this,V)===1)f(this,c,Qe).call(this,t);else {r(this,Le).call(this,o);let l=r(this,_)[o];if(f(this,c,M).call(this,l)?l.__abortController.abort(new Error("deleted")):(r(this,oe)||r(this,B))&&(r(this,oe)&&((i=r(this,Z))==null||i.call(this,l,e,t)),r(this,B)&&r(this,z)?.push([l,e,t])),r(this,F).delete(e),r(this,N)[o]=void 0,r(this,_)[o]=void 0,o===r(this,G))S(this,G,r(this,k)[o]);else if(o===r(this,K))S(this,K,r(this,W)[o]);else {let p=r(this,k)[o];r(this,W)[p]=r(this,W)[o];let m=r(this,W)[o];r(this,k)[m]=r(this,k)[o];}Ye(this,V)._--,r(this,ne).push(o);}}if(r(this,B)&&r(this,z)?.length){let o=r(this,z),l;for(;l=o?.shift();)(s=r(this,ee))==null||s.call(this,...l);}return n},Qe=function(e){var t,n;for(let i of f(this,c,be).call(this,{allowStale:true})){let s=r(this,_)[i];if(f(this,c,M).call(this,s))s.__abortController.abort(new Error("deleted"));else {let o=r(this,N)[i];r(this,oe)&&((t=r(this,Z))==null||t.call(this,s,o,e)),r(this,B)&&r(this,z)?.push([s,o,e]);}}if(r(this,F).clear(),r(this,_).fill(void 0),r(this,N).fill(void 0),r(this,$)&&r(this,se)){r(this,$).fill(0),r(this,se).fill(0);for(let i of r(this,q)??[])i!==void 0&&clearTimeout(i);r(this,q)?.fill(void 0);}if(r(this,ie)&&r(this,ie).fill(0),S(this,K,0),S(this,G,0),r(this,ne).length=0,S(this,re,0),S(this,V,0),r(this,B)&&r(this,z)){let i=r(this,z),s;for(;s=i?.shift();)(n=r(this,ee))==null||n.call(this,...s);}},Re);var Pe=class{constructor(e){E(this,"cache");E(this,"map",new Map);this.cache=new lt({max:e.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){this.cache.clear(),this.map.clear();}delete(e){let t=this.map.delete(e);return t&&this.cache.delete(e),t}get forEach(){return this.map.forEach}get(e){let t=this.cache.get(e);return t||this.map.get(e)}has(e){return this.map.has(e)}set(e,t){return this.map.set(e,t),this.cache.set(e,t),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var L;(i=>(i.log=(s,...o)=>console.log(`[Pixi\u2019VN] ${s}`,...o),i.warn=(s,...o)=>console.warn(`[Pixi\u2019VN] ${s}`,...o),i.error=(s,...o)=>console.error(`[Pixi\u2019VN] ${s}`,...o),i.info=(s,...o)=>console.info(`[Pixi\u2019VN] ${s}`,...o)))(L||(L={}));var we=new Pe({cacheSize:10}),Ze;(s=>{function h(o){let l=we.get(o);if(!l){L.error(`Label "${o}" not found`);return}return l}s.get=h;function e(o){if(Array.isArray(o)){o.forEach(l=>{e(l);});return}we.has(o.id)&&L.info(`Label "${o.id}" already exists, it will be overwritten`),we.set(o.id,o);}s.add=e;function t(){return Array.from(we.values())}s.values=t;function n(o){return we.has(o)}s.has=n;function i(){return Array.from(we.keys())}s.keys=i;})(Ze||(Ze={}));var ae=Ze;function ce(h){try{if(typeof h>"u")return h;let e=JSON.stringify(h);return JSON.parse(e)}catch(e){throw L.error("Error creating exportable element",h,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var y=class y{constructor(){}static get allOpenedLabels(){return core.GameUnifier.getVariable(v,R.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){core.GameUnifier.setVariable(v,R.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=y.currentLabelStepIndex;if(t===null)return L.error("currentLabelStepIndex is null"),null;let n=`${t}${e}`,i=y.currentLabelId,s=y._currentLabel;if(!i||t===null||!s)return L.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let o=s.getStepSha(t)||"error",l=core.GameUnifier.getVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return l[i]||(l[i]={}),(!l[i][n]||l[i][n].stepSha1!==o)&&(l[i][n]={stepSha1:o}),l[i][n]}static setCurrentStepTimesCounterData(e="",t){let n=y.currentLabelStepIndex,i=n+e,s=y.currentLabelId;if(!s||n===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let o=core.GameUnifier.getVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};o[s]||(o[s]={}),o[s][i]=t,core.GameUnifier.setVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY,o);}static getCurrentStepTimesCounter(e=""){let t=y._stepCounter,n=y.getCurrentStepTimesCounterData(e);if(!n)return L.error("getCurrentStepTimesCounter obj is null"),0;let i=n.stepCounters||[];return i.find(o=>o===t)||(i.push(t),n.stepCounters=i,y.setCurrentStepTimesCounterData(e,n)),i.length}static getRandomNumber(e,t,n={}){let i=n.nestedId||"";if(n.onceOnly||false){let o=y.getCurrentStepTimesCounterData(i);if(!o)return;let l=o.usedRandomNumbers||{},p=Array.from({length:t-e+1},(T,D)=>D+e).filter(T=>!l[`${e}-${t}`]?.includes(T));if(p.length===0)return;let m=Math.floor(Math.random()*p.length),u=p[m];return l[`${e}-${t}`]||(l[`${e}-${t}`]=[]),l[`${e}-${t}`].push(u),o.usedRandomNumbers=l,y.setCurrentStepTimesCounterData(i,o),u}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=y.currentLabelStepIndex,n=t+e,i=y.currentLabelId;if(!i||t===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let s=core.GameUnifier.getVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};s[i]||(s[i]={}),s[i][n]={stepCounters:[],stepSha1:""},core.GameUnifier.setVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY,s);}static get allChoicesMade(){return core.GameUnifier.getVariable(v,R.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){core.GameUnifier.setVariable(v,R.ALL_CHOICES_MADE_KEY,e);}static increaseStepCounter(){y._stepCounter++;}static get openedLabels(){return ce(y._openedLabels)}static set openedLabels(e){y._openedLabels=ce(e);}static get originalOpenedLabels(){return ce(y._originalOpenedLabels)}static set originalOpenedLabels(e){y._originalOpenedLabels=ce(e);}static get _currentLabel(){if(y.currentLabelId)return ae.get(y.currentLabelId)}static get currentLabelId(){if(y._openedLabels.length>0)return y._openedLabels[y._openedLabels.length-1].label}static get currentLabelStepIndex(){return y._openedLabels.length>0?y._openedLabels[y._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let n=y.allOpenedLabels,i=y.allOpenedLabels[e]?.biggestStep||0,s=y.allOpenedLabels[e]?.openCount||0;(!i||i<t)&&(n[e]={biggestStep:t,openCount:s},y.allOpenedLabels=n);}static addChoicesMade(e,t,n,i){let s=y.allChoicesMade,o=s.findIndex(l=>l.labelId===e&&l.stepIndex===t&&l.choiceIndex===i&&l.stepSha1===n);o<0?s.push({labelId:e,stepIndex:t,choiceIndex:i,stepSha1:n,madeTimes:1}):s[o].madeTimes++,y.allChoicesMade=s;}static pushNewLabel(e){if(!ae.get(e))throw new core.PixiError("unregistered_element",`Label ${e} not found`);y._openedLabels.push({label:e,currentStepIndex:0});let n=y.allOpenedLabels,i=y.allOpenedLabels[e]?.biggestStep||0,s=y.allOpenedLabels[e]?.openCount||0;n[e]={biggestStep:i,openCount:s+1},y.allOpenedLabels=n;}static increaseCurrentStepIndex(){if(y._openedLabels.length>0){let e=y._openedLabels[y._openedLabels.length-1];y._openedLabels[y._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static set onStepStart(e){y._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let n=[];return y.onLoadingLabel&&e===0&&n.push(y.onLoadingLabel(e,t)),y._onStepStart&&n.push(y._onStepStart(e,t)),await Promise.all(n)}}};E(y,"choiceMadeTemp"),E(y,"lastHistoryStep",null),E(y,"_stepCounter",0),E(y,"_openedLabels",[]),E(y,"_originalOpenedLabels",[]),E(y,"_onStepStart"),E(y,"onLoadingLabel"),E(y,"onStepEnd");var b=y;var Ue=class{get currentStepTimesCounter(){return b.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){b.resetCurrentStepTimesCounter();}getRandomNumber(e,t,n={}){return b.getRandomNumber(e,t,n)}get stepCounter(){return b._stepCounter}get openedLabels(){return b.openedLabels}get currentLabel(){return b._currentLabel}addStepHistory(e,t={}){let{choiceMade:n,ignoreSameStep:i}=t,s,o,l,p=core.GameUnifier.getVariable(v,R.LAST_STEP_GLUED)===this.stepCounter;core.GameUnifier.getVariable(v,R.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(s=core.GameUnifier.getVariable(v,R.CURRENT_DIALOGUE_MEMORY_KEY)),core.GameUnifier.getVariable(v,R.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(o=core.GameUnifier.getVariable(v,R.CURRENT_MENU_OPTIONS_MEMORY_KEY)),core.GameUnifier.getVariable(v,R.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(l=core.GameUnifier.getVariable(v,R.CURRENT_INPUT_VALUE_MEMORY_KEY));let m=b.openedLabels,u={currentLabel:b.currentLabelId,dialogue:s,choices:o,stepSha1:e,index:this.stepCounter,labelStepIndex:b.currentLabelStepIndex,choiceIndexMade:n,inputValue:l,alreadyMadeChoices:this.alreadyCurrentStepMadeChoices,isGlued:p,openedLabels:m};b.originalOpenedLabels=m,core.GameUnifier.addHistoryItem(u,{ignoreSameStep:i}),b.lastHistoryStep=u,b.increaseStepCounter();}closeCurrentLabel(){if(!b.currentLabelId){L.warn("No label to close");return}if(!this.currentLabel){L.error("currentLabel not found");return}let e=b.openedLabels;e.pop(),b.openedLabels=e,core.GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;b.openedLabels.length>0;)this.closeCurrentLabel(),core.GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let i=b.allOpenedLabels[t]?.biggestStep||0;if(i){let s=ae.get(t);if(s)return s.stepCount<=i}return false}get alreadyCurrentStepMadeChoicesObj(){let e=b.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let n=t.getStepSha(e);return n||(L.warn("stepSha not found, setting to ERROR"),n="error"),b.allChoicesMade.filter(i=>i.labelId===t?.id&&i.stepIndex===e&&i.stepSha1===n)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=b.currentLabelId;if(e){let t=b.allOpenedLabels[e]?.openCount||0;if(b.currentLabelStepIndex&&t>=b.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return b.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e){let t=e?.showWarn||false,n=this.choices;return n&&n.length>0?(t&&L.warn("The player must make a choice"),false):this.isRequiredInput?(t&&L.warn("The player must enter a value"),false):true}get canContinue(){return core.GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let n=[];return e.onStepStart&&n.push(e.onStepStart(t,e)),b.onStepStart&&n.push(b.onStepStart(t,e)),await Promise.all(n)}async onStepEnd(e,t){let n=[];return e.onStepEnd&&n.push(e.onStepEnd(t,e)),b.onStepEnd&&n.push(b.onStepEnd(t,e)),await Promise.all(n)}async continue(e,t={}){let{runNow:n=false,steps:i=1}=t;if(!Number.isFinite(i)){L.warn(`[continue] The parameter steps must be a valid finite number, received: ${i}`);return}if(i<=0){L.warn(`[continue] The parameter steps must be greater than 0, received: ${i}`);return}if(!n&&!this.getCanContinue({showWarn:true}))return;if(!n&&core.GameUnifier.runningStepsCount!==0){core.GameUnifier.increaseContinueRequest(i);return}i>1&&core.GameUnifier.increaseContinueRequest(i-1),core.GameUnifier.runningStepsCount++;let s;try{core.GameUnifier.runningStepsCount===1&&await core.GameUnifier.onPreContinue(),b.increaseCurrentStepIndex(),s=await this.runCurrentStep(e,t);}catch(o){throw L.error("Error continuing",o),o}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||s}async afterRunCurrentStep(e){if(core.GameUnifier.runningStepsCount===0&&core.GameUnifier.continueRequestsCount!==0)return await core.GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(core.GameUnifier.onEnd)return await core.GameUnifier.onEnd(e,{labelId:"end"});L.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.web.app/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e,t={}){let{choiceMade:n}=t;if(b.currentLabelId){let i=b.currentLabelStepIndex;if(i===null){L.error("currentLabelStepIndex is null");return}let s=b._currentLabel;if(!s){L.error("currentLabel not found");return}if(s.stepCount>i){try{await this.onStepStart(s,i);}catch(u){L.error("Error running onStepStart",u),this.onStepError&&await this.onStepError(u,e);return}let o=s.getStepById(i);if(!o){L.error("step not found");return}let l=s.getStepSha(i);l||(L.warn("stepSha not found, setting to ERROR"),l="error");let p,m;try{p=await o(e,{labelId:s.id});}catch(u){L.error("Error running step",u),m=u;}try{let u=this.choices;if(u?.length===1&&u[0].autoSelect){let T=u[0];p=await this.selectChoice(T,e);}}catch(u){L.error("Error auto-selecting choice",u),m||(m=u);}try{let u=b.lastHistoryStep;n!==void 0&&u&&(l=u.stepSha1,l||(L.warn("stepSha not found, setting to ERROR"),l="error"),b.addChoicesMade(u.currentLabel||"error",typeof u.labelStepIndex=="number"?u.labelStepIndex:-1,u.stepSha1||"error",n),b.choiceMadeTemp=n);}catch(u){L.warn("Error adding choice made to history",u);}try{core.GameUnifier.runningStepsCount===1&&(b.addLabelHistory(s.id,i),this.addStepHistory(l,{...t,choiceMade:b.choiceMadeTemp}),b.choiceMadeTemp=void 0);}catch(u){L.warn("Error adding step to history",u);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,b.currentLabelStepIndex||0);}catch(u){L.warn("Error running onStepEnd",u);}return m&&this.onStepError&&await this.onStepError(m,e),p}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e,t);if(this.openedLabels.length===1){b.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;L.error("currentLabelId not found");}}async call(e,t,n){let{choiceMade:i}=n||{},s;typeof e=="string"?s=e:s=e.id,core.GameUnifier.runningStepsCount++;let o;try{let l=ae.get(s);if(!l)throw new core.PixiError("unregistered_element",`Label ${s} not found`);b.pushNewLabel(l.id),o=await this.runCurrentStep(t,{choiceMade:i});}catch(l){throw L.error("Error calling label",l),l}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||o}async jump(e,t,n){if(this.stepCounter===0)return await this.call(e,t,n);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:i}=n||{},s;typeof e=="string"?s=e:s=e.id,core.GameUnifier.runningStepsCount++;let o;try{let l=ae.get(s);if(!l)throw new core.PixiError("unregistered_element",`Label ${s} not found`);b.pushNewLabel(l.id),o=await this.runCurrentStep(t,{choiceMade:i});}catch(l){throw L.error("Error jumping to label",l),l}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||o}async selectChoice(e,t){this.choices=void 0;let n=e.type;switch(n){case "call":return await this.call(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "jump":return await this.jump(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "close":return await this.closeChoiceMenu(e,{...e.props,...t});default:throw L.error(`Type ${n} not found`),new core.PixiError("invalid_usage",`Type ${n} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw L.error("For closeChoiceMenu, the type must be close"),new core.PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let n;return typeof e.choiceIndex=="number"&&(n=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:n})}get onStepError(){return async(e,t)=>{try{await core.GameUnifier.runOnError(e,t);}catch(n){L.error("Error in onError handler",n);}}}get dialogue(){let e=core.GameUnifier.getVariable(v,R.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?core.GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){core.GameUnifier.setVariable(v,R.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=core.GameUnifier.getVariable(v,R.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let n=[];Array.isArray(t.text)?n=[...t.text]:n=[t.text],Array.isArray(e.text)?n=[...n,...e.text]:n=[...n,e.text],e.text=n,e.character=e.character||t.character;}core.GameUnifier.setVariable(v,R.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{core.GameUnifier.setVariable(v,R.CURRENT_DIALOGUE_MEMORY_KEY,ce({...e,character:typeof e.character=="string"?e.character:e.character?.id})),core.GameUnifier.setVariable(v,R.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("DialogueInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=core.GameUnifier.getVariable(v,R.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],n=e.map((s,o)=>({...s,choiceIndex:o})),i=this.alreadyCurrentStepMadeChoices;if(n=n.filter((s,o)=>s.oneTime&&i?.includes(o)?false:s.onlyHaveNoChoice?(t.push(s),false):true),n.length>0)return n;if(t.length>0)return [t[0]]}}set choices(e){if(!e||e.length===0){core.GameUnifier.setVariable(v,R.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{core.GameUnifier.setVariable(v,R.CURRENT_MENU_OPTIONS_MEMORY_KEY,ce(e)),core.GameUnifier.setVariable(v,R.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("ChoiceInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return core.GameUnifier.getFlag(R.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){core.GameUnifier.setFlag(R.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return core.GameUnifier.getVariable(v,R.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),core.GameUnifier.setVariable(v,R.CURRENT_INPUT_VALUE_MEMORY_KEY,e),core.GameUnifier.setVariable(v,R.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return core.GameUnifier.getVariable(v,R.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return core.GameUnifier.getVariable(v,R.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e,t){e.isRequired=true,core.GameUnifier.setVariable(v,R.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?core.GameUnifier.setVariable(v,R.CURRENT_INPUT_VALUE_MEMORY_KEY,t):core.GameUnifier.removeVariable(v,R.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){core.GameUnifier.removeVariable(v,R.CURRENT_INPUT_INFO_MEMORY_KEY),core.GameUnifier.removeVariable(v,R.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){b.openedLabels=[],b._stepCounter=0;}export(){return {openedLabels:ce(b.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async n=>{let i=[],s=ae.get(n.label);return s&&(s.onLoadingLabel&&i.push(s.onLoadingLabel(e,s)),b.onLoadingLabel&&i.push(b.onLoadingLabel(e,s))),await Promise.all(i)});return await Promise.all(t)}async restore(e,t){this.clear();try{b.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(b.openedLabels=e.openedLabels,b.originalOpenedLabels=b.openedLabels):L.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?b._stepCounter=e.stepCounter:L.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(b.currentLabelStepIndex||0);}catch(n){L.error("Error running onLoadingLabel",n);}}catch(n){L.error("Error importing data",n);}}};function At(h,e,t,n){let i=typeof e=="string"?e:e.id;return {...n,label:i,props:t,text:h,type:n?.type||"call"}}var pt="close";function Mt(h,e){return {...e,type:pt,text:h}}var bt=Ct(ft());var xe=class{constructor(e,t){E(this,"id");E(this,"_onStepStart");E(this,"_onLoadingLabel");E(this,"_onStepEnd");this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}get onLoadingLabel(){return this._onLoadingLabel}get onStepEnd(){return this._onStepEnd}};var Ae=class extends xe{constructor(t,n,i){super(t,i);E(this,"_steps");this._steps=n;}get stepCount(){return this.steps.length}getStepById(t){return this.steps[t]}get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(t){if(t<0||t>=this.steps.length)return L.warn("stepSha not found, setting to ERROR"),"error";try{let n=this.steps[t];return (0,bt.default)(n.toString().toLocaleLowerCase()).toString()}catch(n){return L.warn("stepSha not found, setting to ERROR",n),"error"}}};function yt(h,e,t){let n=new Ae(h,e,t);return ae.add(n),n}var wr=new Ue;
exports.Label=Ae;exports.LabelAbstract=xe;exports.NarrationManagerStatic=b;exports.RegisteredLabels=ae;exports.narration=wr;exports.newChoiceOption=At;exports.newCloseChoiceOption=Mt;exports.newLabel=yt;