@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
3 lines • 48.2 kB
JavaScript
'use strict';var core=require('@drincs/pixi-vn/core');var St=Object.create;var Be=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var Lt=Object.getPrototypeOf,_t=Object.prototype.hasOwnProperty;var tt=h=>{throw TypeError(h)};var Tt=(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 rt=(h,e)=>()=>(e||h((e={exports:{}}).exports,e),e.exports);var Et=(h,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of yt(e))!_t.call(h,n)&&n!==t&&Be(h,n,{get:()=>e[n],enumerable:!(i=gt(e,n))||i.enumerable});return h};var Ct=(h,e,t)=>(t=h!=null?St(Lt(h)):{},Et(Be(t,"default",{value:h,enumerable:true}),h));var E=(h,e,t)=>Tt(h,typeof e!="symbol"?e+"":e,t),ke=(h,e,t)=>e.has(h)||tt("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)?tt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,t),g=(h,e,t,i)=>(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,i)=>({set _(n){g(h,e,n);},get _(){return r(h,e,i)}});var ct=rt((Ke,pt)=>{(function(h,e){typeof Ke=="object"?pt.exports=Ke=e():typeof define=="function"&&define.amd?define([],e):h.CryptoJS=e();})(Ke,function(){var h=h||(function(e,t){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof global<"u"&&global.crypto&&(i=global.crypto),!i&&typeof je=="function")try{i=je("crypto");}catch{}var n=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function o(){}return function(d){var O;return o.prototype=d,O=new o,o.prototype=null,O}})(),a={},l=a.lib={},u=l.Base=(function(){return {extend:function(o){var d=s(this);return o&&d.mixIn(o),(!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 o=this.extend();return o.init.apply(o,arguments),o},init:function(){},mixIn:function(o){for(var d in o)o.hasOwnProperty(d)&&(this[d]=o[d]);o.hasOwnProperty("toString")&&(this.toString=o.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),S=l.WordArray=u.extend({init:function(o,d){o=this.words=o||[],d!=t?this.sigBytes=d:this.sigBytes=o.length*4;},toString:function(o){return (o||_).stringify(this)},concat:function(o){var d=this.words,O=o.words,I=this.sigBytes,w=o.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 K=0;K<w;K+=4)d[I+K>>>2]=O[K>>>2];return this.sigBytes+=w,this},clamp:function(){var o=this.words,d=this.sigBytes;o[d>>>2]&=4294967295<<32-d%4*8,o.length=e.ceil(d/4);},clone:function(){var o=u.clone.call(this);return o.words=this.words.slice(0),o},random:function(o){for(var d=[],O=0;O<o;O+=4)d.push(n());return new S.init(d,o)}}),c=a.enc={},_=c.Hex={stringify:function(o){for(var d=o.words,O=o.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(o){for(var d=o.length,O=[],I=0;I<d;I+=2)O[I>>>3]|=parseInt(o.substr(I,2),16)<<24-I%8*4;return new S.init(O,d/2)}},D=c.Latin1={stringify:function(o){for(var d=o.words,O=o.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(o){for(var d=o.length,O=[],I=0;I<d;I++)O[I>>>2]|=(o.charCodeAt(I)&255)<<24-I%4*8;return new S.init(O,d)}},P=c.Utf8={stringify:function(o){try{return decodeURIComponent(escape(D.stringify(o)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(o){return D.parse(unescape(encodeURIComponent(o)))}},U=l.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new S.init,this._nDataBytes=0;},_append:function(o){typeof o=="string"&&(o=P.parse(o)),this._data.concat(o),this._nDataBytes+=o.sigBytes;},_process:function(o){var d,O=this._data,I=O.words,w=O.sigBytes,Y=this.blockSize,le=Y*4,K=w/le;o?K=e.ceil(K):K=e.max((K|0)-this._minBufferSize,0);var Q=K*Y,_e=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-=_e;}return new S.init(d,_e)},clone:function(){var o=u.clone.call(this);return o._data=this._data.clone(),o},_minBufferSize:0});l.Hasher=U.extend({cfg:u.extend(),init:function(o){this.cfg=this.cfg.extend(o),this.reset();},reset:function(){U.reset.call(this),this._doReset();},update:function(o){return this._append(o),this._process(),this},finalize:function(o){o&&this._append(o);var d=this._doFinalize();return d},blockSize:512/32,_createHelper:function(o){return function(d,O){return new o.init(O).finalize(d)}},_createHmacHelper:function(o){return function(d,O){return new C.HMAC.init(o,O).finalize(d)}}});var C=a.algo={};return a})(Math);return h});});var ft=rt((He,dt)=>{(function(h,e){typeof He=="object"?dt.exports=He=e(ct()):typeof define=="function"&&define.amd?define(["./core"],e):e(h.CryptoJS);})(He,function(h){return (function(){var e=h,t=e.lib,i=t.WordArray,n=t.Hasher,s=e.algo,a=[],l=s.SHA1=n.extend({_doReset:function(){this._hash=new i.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,S){for(var c=this._hash.words,_=c[0],D=c[1],P=c[2],U=c[3],A=c[4],C=0;C<80;C++){if(C<16)a[C]=u[S+C]|0;else {var o=a[C-3]^a[C-8]^a[C-14]^a[C-16];a[C]=o<<1|o>>>31;}var d=(_<<5|_>>>27)+A+a[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=_,_=d;}c[0]=c[0]+_|0,c[1]=c[1]+D|0,c[2]=c[2]+P|0,c[3]=c[3]+U|0,c[4]=c[4]+A|0;},_doFinalize:function(){var u=this._data,S=u.words,c=this._nDataBytes*8,_=u.sigBytes*8;return S[_>>>5]|=128<<24-_%32,S[(_+64>>>9<<4)+14]=Math.floor(c/4294967296),S[(_+64>>>9<<4)+15]=c,u.sigBytes=S.length*4,this._process(),this._hash},clone:function(){var u=n.clone.call(this);return u._hash=this._hash.clone(),u}});e.SHA1=n._createHelper(l),e.HmacSHA1=n._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 L;(n=>(n.log=(s,...a)=>console.log(`[Pixi\u2019VN] ${s}`,...a),n.warn=(s,...a)=>console.warn(`[Pixi\u2019VN] ${s}`,...a),n.error=(s,...a)=>console.error(`[Pixi\u2019VN] ${s}`,...a),n.info=(s,...a)=>console.info(`[Pixi\u2019VN] ${s}`,...a)))(L||(L={}));function he(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 Ot=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,at=new Set,$e=typeof process=="object"&&process?process:{},ot=(h,e,t,i)=>{typeof $e.emitWarning=="function"?$e.emitWarning(h,e,t,i):console.error(`[${t}] ${e}: ${h}`);},ze=globalThis.AbortController,it=globalThis.AbortSignal;if(typeof ze>"u"){it=class{constructor(){E(this,"onabort");E(this,"_onabort",[]);E(this,"reason");E(this,"aborted",false);}addEventListener(t,i){this._onabort.push(i);}},ze=class{constructor(){E(this,"signal",new it);e();}abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let i of this.signal._onabort)i(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 Rt=h=>!at.has(h);var de=h=>h&&h===Math.floor(h)&&h>0&&isFinite(h),lt=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);}},ue,Te,wt=(ue=class{constructor(e,t){E(this,"heap");E(this,"length");if(!r(ue,Te))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}static create(e){let t=lt(e);if(!t)return [];g(ue,Te,true);let i=new ue(e,t);return g(ue,Te,false),i}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},Te=new WeakMap,x(ue,Te,false),ue),nt,st,J,j,Z,ge,ee,Ee,Ce,te,V,re,F,N,T,W,k,H,G,ie,z,ne,se,$,q,ae,Se,B,Ie,p,qe,ye,pe,De,X,ut,Le,Oe,Pe,fe,be,Xe,Ve,Ge,M,Je,Ne,me,Qe,Re,ht=(Re=class{constructor(e){x(this,p);x(this,J);x(this,j);x(this,Z);x(this,ge);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,T);x(this,W);x(this,k);x(this,H);x(this,G);x(this,ie);x(this,z);x(this,ne);x(this,se);x(this,$);x(this,q);x(this,ae);x(this,Se);x(this,B);x(this,Ie);x(this,ye,()=>{});x(this,pe,()=>{});x(this,De,()=>{});x(this,X,()=>false);x(this,Le,e=>{});x(this,Oe,(e,t,i)=>{});x(this,Pe,(e,t,i,n)=>{if(i||n)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});E(this,nt,"LRUCache");let{max:t=0,ttl:i,ttlResolution:n=1,ttlAutopurge:s,updateAgeOnGet:a,updateAgeOnHas:l,allowStale:u,dispose:S,onInsert:c,disposeAfter:_,noDisposeOnSet:D,noUpdateTTL:P,maxSize:U=0,maxEntrySize:A=0,sizeCalculation:C,fetchMethod:o,memoMethod:d,noDeleteOnFetchRejection:O,noDeleteOnStaleGet:I,allowStaleOnFetchRejection:w,allowStaleOnFetchAbort:Y,ignoreFetchAbort:le,perf:K}=e;if(K!==void 0&&typeof K?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(g(this,te,K??Ot),t!==0&&!de(t))throw new TypeError("max option must be a nonnegative integer");let Q=t?lt(t):Array;if(!Q)throw new Error("invalid max value: "+t);if(g(this,J,t),g(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(g(this,Ce,d),o!==void 0&&typeof o!="function")throw new TypeError("fetchMethod must be a function if specified");if(g(this,Ee,o),g(this,Se,!!o),g(this,F,new Map),g(this,N,new Array(t).fill(void 0)),g(this,T,new Array(t).fill(void 0)),g(this,W,new Q(t)),g(this,k,new Q(t)),g(this,H,0),g(this,G,0),g(this,ie,wt.create(t)),g(this,V,0),g(this,re,0),typeof S=="function"&&g(this,Z,S),typeof c=="function"&&g(this,ge,c),typeof _=="function"?(g(this,ee,_),g(this,z,[])):(g(this,ee,void 0),g(this,z,void 0)),g(this,ae,!!r(this,Z)),g(this,Ie,!!r(this,ge)),g(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,p,ut).call(this);}if(this.allowStale=!!u,this.noDeleteOnStaleGet=!!I,this.updateAgeOnGet=!!a,this.updateAgeOnHas=!!l,this.ttlResolution=de(n)||n===0?n:1,this.ttlAutopurge=!!s,this.ttl=i||0,this.ttl){if(!de(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,p,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 _e="LRU_CACHE_UNBOUNDED";Rt(_e)&&(at.add(_e),ot("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",_e,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,ne),keyMap:r(e,F),keyList:r(e,N),valList:r(e,T),next:r(e,W),prev:r(e,k),get head(){return r(e,H)},get tail(){return r(e,G)},free:r(e,ie),isBackgroundFetch:t=>{var i;return f(i=e,p,M).call(i,t)},backgroundFetch:(t,i,n,s)=>{var a;return f(a=e,p,Ge).call(a,t,i,n,s)},moveToTail:t=>{var i;return f(i=e,p,Ne).call(i,t)},indexes:t=>{var i;return f(i=e,p,fe).call(i,t)},rindexes:t=>{var i;return f(i=e,p,be).call(i,t)},isStale:t=>{var i;return r(i=e,X).call(i,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,ge)}get disposeAfter(){return r(this,ee)}getRemainingTTL(e){return r(this,F).has(e)?1/0:0}*entries(){for(let e of f(this,p,fe).call(this))r(this,T)[e]!==void 0&&r(this,N)[e]!==void 0&&!f(this,p,M).call(this,r(this,T)[e])&&(yield [r(this,N)[e],r(this,T)[e]]);}*rentries(){for(let e of f(this,p,be).call(this))r(this,T)[e]!==void 0&&r(this,N)[e]!==void 0&&!f(this,p,M).call(this,r(this,T)[e])&&(yield [r(this,N)[e],r(this,T)[e]]);}*keys(){for(let e of f(this,p,fe).call(this)){let t=r(this,N)[e];t!==void 0&&!f(this,p,M).call(this,r(this,T)[e])&&(yield t);}}*rkeys(){for(let e of f(this,p,be).call(this)){let t=r(this,N)[e];t!==void 0&&!f(this,p,M).call(this,r(this,T)[e])&&(yield t);}}*values(){for(let e of f(this,p,fe).call(this))r(this,T)[e]!==void 0&&!f(this,p,M).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}*rvalues(){for(let e of f(this,p,be).call(this))r(this,T)[e]!==void 0&&!f(this,p,M).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}[(st=Symbol.iterator,nt=Symbol.toStringTag,st)](){return this.entries()}find(e,t={}){for(let i of f(this,p,fe).call(this)){let n=r(this,T)[i],s=f(this,p,M).call(this,n)?n.__staleWhileFetching:n;if(s!==void 0&&e(s,r(this,N)[i],this))return this.get(r(this,N)[i],t)}}forEach(e,t=this){for(let i of f(this,p,fe).call(this)){let n=r(this,T)[i],s=f(this,p,M).call(this,n)?n.__staleWhileFetching:n;s!==void 0&&e.call(t,s,r(this,N)[i],this);}}rforEach(e,t=this){for(let i of f(this,p,be).call(this)){let n=r(this,T)[i],s=f(this,p,M).call(this,n)?n.__staleWhileFetching:n;s!==void 0&&e.call(t,s,r(this,N)[i],this);}}purgeStale(){let e=false;for(let t of f(this,p,be).call(this,{allowStale:true}))r(this,X).call(this,t)&&(f(this,p,me).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 i=r(this,T)[t],n=f(this,p,M).call(this,i)?i.__staleWhileFetching:i;if(n===void 0)return;let s={value:n};if(r(this,$)&&r(this,se)){let a=r(this,$)[t],l=r(this,se)[t];if(a&&l){let u=a-(r(this,te).now()-l);s.ttl=u,s.start=Date.now();}}return r(this,ne)&&(s.size=r(this,ne)[t]),s}dump(){let e=[];for(let t of f(this,p,fe).call(this,{allowStale:true})){let i=r(this,N)[t],n=r(this,T)[t],s=f(this,p,M).call(this,n)?n.__staleWhileFetching:n;if(s===void 0||i===void 0)continue;let a={value:s};if(r(this,$)&&r(this,se)){a.ttl=r(this,$)[t];let l=r(this,te).now()-r(this,se)[t];a.start=Math.floor(Date.now()-l);}r(this,ne)&&(a.size=r(this,ne)[t]),e.unshift([i,a]);}return e}load(e){this.clear();for(let[t,i]of e){if(i.start){let n=Date.now()-i.start;i.start=r(this,te).now()-n;}this.set(t,i.value,i);}}set(e,t,i={}){var D,P,U,A;if(t===void 0)return this.delete(e),this;let{ttl:n=this.ttl,start:s,noDisposeOnSet:a=this.noDisposeOnSet,sizeCalculation:l=this.sizeCalculation,status:u}=i,{noUpdateTTL:S=this.noUpdateTTL}=i,c=r(this,Pe).call(this,e,t,i.size||0,l);if(this.maxEntrySize&&c>this.maxEntrySize)return u&&(u.set="miss",u.maxEntrySizeExceeded=true),f(this,p,me).call(this,e,"set"),this;let _=r(this,V)===0?void 0:r(this,F).get(e);if(_===void 0)_=r(this,V)===0?r(this,G):r(this,ie).length!==0?r(this,ie).pop():r(this,V)===r(this,J)?f(this,p,Ve).call(this,false):r(this,V),r(this,N)[_]=e,r(this,T)[_]=t,r(this,F).set(e,_),r(this,W)[r(this,G)]=_,r(this,k)[_]=r(this,G),g(this,G,_),Ye(this,V)._++,r(this,Oe).call(this,_,c,u),u&&(u.set="add"),S=false,r(this,Ie)&&((D=r(this,ge))==null||D.call(this,t,e,"add"));else {f(this,p,Ne).call(this,_);let C=r(this,T)[_];if(t!==C){if(r(this,Se)&&f(this,p,M).call(this,C)){C.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:o}=C;o!==void 0&&!a&&(r(this,ae)&&((P=r(this,Z))==null||P.call(this,o,e,"set")),r(this,B)&&r(this,z)?.push([o,e,"set"]));}else a||(r(this,ae)&&((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,_),r(this,Oe).call(this,_,c,u),r(this,T)[_]=t,u){u.set="replace";let o=C&&f(this,p,M).call(this,C)?C.__staleWhileFetching:C;o!==void 0&&(u.oldValue=o);}}else u&&(u.set="update");r(this,Ie)&&this.onInsert?.(t,e,t===C?"update":"replace");}if(n!==0&&!r(this,$)&&f(this,p,qe).call(this),r(this,$)&&(S||r(this,De).call(this,_,n,s),u&&r(this,pe).call(this,u,_)),!a&&r(this,B)&&r(this,z)){let C=r(this,z),o;for(;o=C?.shift();)(A=r(this,ee))==null||A.call(this,...o);}return this}pop(){var e;try{for(;r(this,V);){let t=r(this,T)[r(this,H)];if(f(this,p,Ve).call(this,!0),f(this,p,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),i;for(;i=t?.shift();)(e=r(this,ee))==null||e.call(this,...i);}}}has(e,t={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:n}=t,s=r(this,F).get(e);if(s!==void 0){let a=r(this,T)[s];if(f(this,p,M).call(this,a)&&a.__staleWhileFetching===void 0)return false;if(r(this,X).call(this,s))n&&(n.has="stale",r(this,pe).call(this,n,s));else return i&&r(this,ye).call(this,s),n&&(n.has="hit",r(this,pe).call(this,n,s)),true}else n&&(n.has="miss");return false}peek(e,t={}){let{allowStale:i=this.allowStale}=t,n=r(this,F).get(e);if(n===void 0||!i&&r(this,X).call(this,n))return;let s=r(this,T)[n];return f(this,p,M).call(this,s)?s.__staleWhileFetching:s}async fetch(e,t={}){let{allowStale:i=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:l=this.noDisposeOnSet,size:u=0,sizeCalculation:S=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:_=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:D=this.allowStaleOnFetchRejection,ignoreFetchAbort:P=this.ignoreFetchAbort,allowStaleOnFetchAbort:U=this.allowStaleOnFetchAbort,context:A,forceRefresh:C=false,status:o,signal:d}=t;if(!r(this,Se))return o&&(o.fetch="get"),this.get(e,{allowStale:i,updateAgeOnGet:n,noDeleteOnStaleGet:s,status:o});let O={allowStale:i,updateAgeOnGet:n,noDeleteOnStaleGet:s,ttl:a,noDisposeOnSet:l,size:u,sizeCalculation:S,noUpdateTTL:c,noDeleteOnFetchRejection:_,allowStaleOnFetchRejection:D,allowStaleOnFetchAbort:U,ignoreFetchAbort:P,status:o,signal:d},I=r(this,F).get(e);if(I===void 0){o&&(o.fetch="miss");let w=f(this,p,Ge).call(this,e,I,O,A);return w.__returned=w}else {let w=r(this,T)[I];if(f(this,p,M).call(this,w)){let Q=i&&w.__staleWhileFetching!==void 0;return o&&(o.fetch="inflight",Q&&(o.returnedStale=true)),Q?w.__staleWhileFetching:w.__returned=w}let Y=r(this,X).call(this,I);if(!C&&!Y)return o&&(o.fetch="hit"),f(this,p,Ne).call(this,I),n&&r(this,ye).call(this,I),o&&r(this,pe).call(this,o,I),w;let le=f(this,p,Ge).call(this,e,I,O,A),K=le.__staleWhileFetching!==void 0&&i;return o&&(o.fetch=Y?"stale":"refresh",K&&Y&&(o.returnedStale=true)),K?le.__staleWhileFetching:le.__returned=le}}async forceFetch(e,t={}){let i=await this.fetch(e,t);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(e,t={}){let i=r(this,Ce);if(!i)throw new Error("no memoMethod provided to constructor");let{context:n,forceRefresh:s,...a}=t,l=this.get(e,a);if(!s&&l!==void 0)return l;let u=i(e,l,{options:a,context:n});return this.set(e,u,a),u}get(e,t={}){let{allowStale:i=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,status:a}=t,l=r(this,F).get(e);if(l!==void 0){let u=r(this,T)[l],S=f(this,p,M).call(this,u);return a&&r(this,pe).call(this,a,l),r(this,X).call(this,l)?(a&&(a.get="stale"),S?(a&&i&&u.__staleWhileFetching!==void 0&&(a.returnedStale=true),i?u.__staleWhileFetching:void 0):(s||f(this,p,me).call(this,e,"expire"),a&&i&&(a.returnedStale=true),i?u:void 0)):(a&&(a.get="hit"),S?u.__staleWhileFetching:(f(this,p,Ne).call(this,l),n&&r(this,ye).call(this,l),u))}else a&&(a.get="miss");}delete(e){return f(this,p,me).call(this,e,"delete")}clear(){return f(this,p,Qe).call(this,"delete")}},J=new WeakMap,j=new WeakMap,Z=new WeakMap,ge=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,T=new WeakMap,W=new WeakMap,k=new WeakMap,H=new WeakMap,G=new WeakMap,ie=new WeakMap,z=new WeakMap,ne=new WeakMap,se=new WeakMap,$=new WeakMap,q=new WeakMap,ae=new WeakMap,Se=new WeakMap,B=new WeakMap,Ie=new WeakMap,p=new WeakSet,qe=function(){let e=new Fe(r(this,J)),t=new Fe(r(this,J));g(this,$,e),g(this,se,t);let i=this.ttlAutopurge?new Array(r(this,J)):void 0;g(this,q,i),g(this,De,(l,u,S=r(this,te).now())=>{t[l]=u!==0?S:0,e[l]=u,n(l,u);}),g(this,ye,l=>{t[l]=e[l]!==0?r(this,te).now():0,n(l,e[l]);});let n=this.ttlAutopurge?(l,u)=>{if(i?.[l]&&(clearTimeout(i[l]),i[l]=void 0),u&&u!==0&&i){let S=setTimeout(()=>{r(this,X).call(this,l)&&f(this,p,me).call(this,r(this,N)[l],"expire");},u+1);S.unref&&S.unref(),i[l]=S;}}:()=>{};g(this,pe,(l,u)=>{if(e[u]){let S=e[u],c=t[u];if(!S||!c)return;l.ttl=S,l.start=c,l.now=s||a();let _=l.now-c;l.remainingTTL=S-_;}});let s=0,a=()=>{let l=r(this,te).now();if(this.ttlResolution>0){s=l;let u=setTimeout(()=>s=0,this.ttlResolution);u.unref&&u.unref();}return l};this.getRemainingTTL=l=>{let u=r(this,F).get(l);if(u===void 0)return 0;let S=e[u],c=t[u];if(!S||!c)return 1/0;let _=(s||a())-c;return S-_},g(this,X,l=>{let u=t[l],S=e[l];return !!S&&!!u&&(s||a())-u>S});},ye=new WeakMap,pe=new WeakMap,De=new WeakMap,X=new WeakMap,ut=function(){let e=new Fe(r(this,J));g(this,re,0),g(this,ne,e),g(this,Le,t=>{g(this,re,r(this,re)-e[t]),e[t]=0;}),g(this,Pe,(t,i,n,s)=>{if(f(this,p,M).call(this,i))return 0;if(!de(n))if(s){if(typeof s!="function")throw new TypeError("sizeCalculation must be a function");if(n=s(i,t),!de(n))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 n}),g(this,Oe,(t,i,n)=>{if(e[t]=i,r(this,j)){let s=r(this,j)-e[t];for(;r(this,re)>s;)f(this,p,Ve).call(this,true);}g(this,re,r(this,re)+e[t]),n&&(n.entrySize=i,n.totalCalculatedSize=r(this,re));});},Le=new WeakMap,Oe=new WeakMap,Pe=new WeakMap,fe=function*({allowStale:e=this.allowStale}={}){if(r(this,V))for(let t=r(this,G);!(!f(this,p,Xe).call(this,t)||((e||!r(this,X).call(this,t))&&(yield t),t===r(this,H)));)t=r(this,k)[t];},be=function*({allowStale:e=this.allowStale}={}){if(r(this,V))for(let t=r(this,H);!(!f(this,p,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,H),i=r(this,N)[t],n=r(this,T)[t];return r(this,Se)&&f(this,p,M).call(this,n)?n.__abortController.abort(new Error("evicted")):(r(this,ae)||r(this,B))&&(r(this,ae)&&((s=r(this,Z))==null||s.call(this,n,i,"evict")),r(this,B)&&r(this,z)?.push([n,i,"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)[t]=void 0,r(this,ie).push(t)),r(this,V)===1?(g(this,H,g(this,G,0)),r(this,ie).length=0):g(this,H,r(this,W)[t]),r(this,F).delete(i),Ye(this,V)._--,t},Ge=function(e,t,i,n){let s=t===void 0?void 0:r(this,T)[t];if(f(this,p,M).call(this,s))return s;let a=new ze,{signal:l}=i;l?.addEventListener("abort",()=>a.abort(l.reason),{signal:a.signal});let u={signal:a.signal,options:i,context:n},S=(A,C=false)=>{let{aborted:o}=a.signal,d=i.ignoreFetchAbort&&A!==void 0,O=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&A!==void 0);if(i.status&&(o&&!C?(i.status.fetchAborted=true,i.status.fetchError=a.signal.reason,d&&(i.status.fetchAbortIgnored=true)):i.status.fetchResolved=true),o&&!d&&!C)return _(a.signal.reason,O);let I=P,w=r(this,T)[t];return (w===P||d&&C&&w===void 0)&&(A===void 0?I.__staleWhileFetching!==void 0?r(this,T)[t]=I.__staleWhileFetching:f(this,p,me).call(this,e,"fetch"):(i.status&&(i.status.fetchUpdated=true),this.set(e,A,u.options))),A},c=A=>(i.status&&(i.status.fetchRejected=true,i.status.fetchError=A),_(A,false)),_=(A,C)=>{let{aborted:o}=a.signal,d=o&&i.allowStaleOnFetchAbort,O=d||i.allowStaleOnFetchRejection,I=O||i.noDeleteOnFetchRejection,w=P;if(r(this,T)[t]===P&&(!I||!C&&w.__staleWhileFetching===void 0?f(this,p,me).call(this,e,"fetch"):d||(r(this,T)[t]=w.__staleWhileFetching)),O)return i.status&&w.__staleWhileFetching!==void 0&&(i.status.returnedStale=true),w.__staleWhileFetching;if(w.__returned===w)throw A},D=(A,C)=>{var d;let o=(d=r(this,Ee))==null?void 0:d.call(this,e,s,u);o&&o instanceof Promise&&o.then(O=>A(O===void 0?void 0:O),C),a.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(A(void 0),i.allowStaleOnFetchAbort&&(A=O=>S(O,true)));});};i.status&&(i.status.fetchDispatched=true);let P=new Promise(D).then(S,c),U=Object.assign(P,{__abortController:a,__staleWhileFetching:s,__returned:void 0});return t===void 0?(this.set(e,U,{...u.options,status:void 0}),t=r(this,F).get(e)):r(this,T)[t]=U,U},M=function(e){if(!r(this,Se))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;},Ne=function(e){e!==r(this,G)&&(e===r(this,H)?g(this,H,r(this,W)[e]):f(this,p,Je).call(this,r(this,k)[e],r(this,W)[e]),f(this,p,Je).call(this,r(this,G),e),g(this,G,e));},me=function(e,t){var n,s;let i=false;if(r(this,V)!==0){let a=r(this,F).get(e);if(a!==void 0)if(r(this,q)?.[a]&&(clearTimeout(r(this,q)?.[a]),r(this,q)[a]=void 0),i=true,r(this,V)===1)f(this,p,Qe).call(this,t);else {r(this,Le).call(this,a);let l=r(this,T)[a];if(f(this,p,M).call(this,l)?l.__abortController.abort(new Error("deleted")):(r(this,ae)||r(this,B))&&(r(this,ae)&&((n=r(this,Z))==null||n.call(this,l,e,t)),r(this,B)&&r(this,z)?.push([l,e,t])),r(this,F).delete(e),r(this,N)[a]=void 0,r(this,T)[a]=void 0,a===r(this,G))g(this,G,r(this,k)[a]);else if(a===r(this,H))g(this,H,r(this,W)[a]);else {let u=r(this,k)[a];r(this,W)[u]=r(this,W)[a];let S=r(this,W)[a];r(this,k)[S]=r(this,k)[a];}Ye(this,V)._--,r(this,ie).push(a);}}if(r(this,B)&&r(this,z)?.length){let a=r(this,z),l;for(;l=a?.shift();)(s=r(this,ee))==null||s.call(this,...l);}return i},Qe=function(e){var t,i;for(let n of f(this,p,be).call(this,{allowStale:true})){let s=r(this,T)[n];if(f(this,p,M).call(this,s))s.__abortController.abort(new Error("deleted"));else {let a=r(this,N)[n];r(this,ae)&&((t=r(this,Z))==null||t.call(this,s,a,e)),r(this,B)&&r(this,z)?.push([s,a,e]);}}if(r(this,F).clear(),r(this,T).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 n of r(this,q)??[])n!==void 0&&clearTimeout(n);r(this,q)?.fill(void 0);}if(r(this,ne)&&r(this,ne).fill(0),g(this,H,0),g(this,G,0),r(this,ie).length=0,g(this,re,0),g(this,V,0),r(this,B)&&r(this,z)){let n=r(this,z),s;for(;s=n?.shift();)(i=r(this,ee))==null||i.call(this,...s);}},Re);var we=class{constructor(e){E(this,"cache");E(this,"map",new Map);this.cache=new ht({max:e.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){return 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 ve=new we({cacheSize:10}),Ze;(s=>{function h(a){let l=ve.get(a);if(!l){L.error(`Label "${a}" not found`);return}return l}s.get=h;function e(a){if(Array.isArray(a)){a.forEach(l=>e(l));return}ve.has(a.id)&&L.info(`Label "${a.id}" already exists, it will be overwritten`),ve.set(a.id,a);}s.add=e;function t(){return Array.from(ve.values())}s.values=t;function i(a){return ve.has(a)}s.has=i;function n(){return Array.from(ve.keys())}s.keys=n;})(Ze||(Ze={}));var oe=Ze;var m=class m{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=m.currentLabelStepIndex;if(t===null)return L.error("currentLabelStepIndex is null"),null;let i=`${t}${e}`,n=m.currentLabelId,s=m._currentLabel;if(!n||t===null||!s)return L.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let a=s.getStepSha(t)||"error",l=core.GameUnifier.getVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return l[n]||(l[n]={}),(!l[n][i]||l[n][i].stepSha1!=a)&&(l[n][i]={stepSha1:a}),l[n][i]}static setCurrentStepTimesCounterData(e="",t){let i=m.currentLabelStepIndex,n=i+e,s=m.currentLabelId;if(!s||i===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let a=core.GameUnifier.getVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[s]||(a[s]={}),a[s][n]=t,core.GameUnifier.setVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static getCurrentStepTimesCounter(e=""){let t=m._stepCounter,i=m.getCurrentStepTimesCounterData(e);if(!i)return L.error("getCurrentStepTimesCounter obj is null"),0;let n=i.stepCounters||[];return n.find(a=>a===t)||(n.push(t),i.stepCounters=n,m.setCurrentStepTimesCounterData(e,i)),n.length}static getRandomNumber(e,t,i={}){let n=i.nestedId||"";if(i.onceOnly||false){let a=m.getCurrentStepTimesCounterData(n);if(!a)return;let l=a.usedRandomNumbers||{},u=Array.from({length:t-e+1},(_,D)=>D+e).filter(_=>!l[`${e}-${t}`]?.includes(_));if(u.length===0)return;let S=Math.floor(Math.random()*u.length),c=u[S];return l[`${e}-${t}`]||(l[`${e}-${t}`]=[]),l[`${e}-${t}`].push(c),a.usedRandomNumbers=l,m.setCurrentStepTimesCounterData(n,a),c}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=m.currentLabelStepIndex,i=t+e,n=m.currentLabelId;if(!n||t===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let s=core.GameUnifier.getVariable(v,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};s[n]||(s[n]={}),s[n][i]={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(){m._stepCounter++;}static get openedLabels(){return he(m._openedLabels)}static set openedLabels(e){m._openedLabels=he(e);}static get originalOpenedLabels(){return he(m._originalOpenedLabels)}static set originalOpenedLabels(e){m._originalOpenedLabels=he(e);}static get _currentLabel(){if(m.currentLabelId)return oe.get(m.currentLabelId)}static get currentLabelId(){if(m._openedLabels.length>0)return m._openedLabels[m._openedLabels.length-1].label}static get currentLabelStepIndex(){return m._openedLabels.length>0?m._openedLabels[m._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let i=m.allOpenedLabels,n=m.allOpenedLabels[e]?.biggestStep||0,s=m.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(i[e]={biggestStep:t,openCount:s},m.allOpenedLabels=i);}static addChoicesMade(e,t,i,n){let s=m.allChoicesMade,a=s.findIndex(l=>l.labelId===e&&l.stepIndex===t&&l.choiceIndex===n&&l.stepSha1===i);a<0?s.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:i,madeTimes:1}):s[a].madeTimes++,m.allChoicesMade=s;}static pushNewLabel(e){if(!oe.get(e))throw new core.PixiError("unregistered_element",`Label ${e} not found`);m._openedLabels.push({label:e,currentStepIndex:0});let i=m.allOpenedLabels,n=m.allOpenedLabels[e]?.biggestStep||0,s=m.allOpenedLabels[e]?.openCount||0;i[e]={biggestStep:n,openCount:s+1},m.allOpenedLabels=i;}static increaseCurrentStepIndex(){if(m._openedLabels.length>0){let e=m._openedLabels[m._openedLabels.length-1];m._openedLabels[m._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static set onStepStart(e){m._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let i=[];return m.onLoadingLabel&&e===0&&i.push(m.onLoadingLabel(e,t)),m._onStepStart&&i.push(m._onStepStart(e,t)),await Promise.all(i)}}};E(m,"choiceMadeTemp"),E(m,"lastHistoryStep",null),E(m,"_stepCounter",0),E(m,"_openedLabels",[]),E(m,"_originalOpenedLabels",[]),E(m,"_onStepStart"),E(m,"onLoadingLabel"),E(m,"onStepEnd");var b=m;var Ue=class{get currentStepTimesCounter(){return b.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){b.resetCurrentStepTimesCounter();}getRandomNumber(e,t,i={}){return b.getRandomNumber(e,t,i)}get stepCounter(){return b._stepCounter}get openedLabels(){return b.openedLabels}get currentLabel(){return b._currentLabel}addStepHistory(e,t={}){let{choiceMade:i,ignoreSameStep:n}=t,s,a,l,u=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&&(a=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 S=b.openedLabels,c={currentLabel:b.currentLabelId,dialogue:s,choices:a,stepSha1:e,index:this.stepCounter,labelStepIndex:b.currentLabelStepIndex,choiceIndexMade:i,inputValue:l,alreadyMadeChoices:this.alreadyCurrentStepMadeChoices,isGlued:u,openedLabels:S};b.originalOpenedLabels=S,core.GameUnifier.addHistoryItem(c,{ignoreSameStep:n}),b.lastHistoryStep=c,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 n=b.allOpenedLabels[t]?.biggestStep||0;if(n){let s=oe.get(t);if(s)return s.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e=b.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let i=t.getStepSha(e);return i||(L.warn("stepSha not found, setting to ERROR"),i="error"),b.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e&&n.stepSha1===i)}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,i=this.choices;return i&&i.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 i=[];return e.onStepStart&&i.push(e.onStepStart(t,e)),b.onStepStart&&i.push(b.onStepStart(t,e)),await Promise.all(i)}async onStepEnd(e,t){let i=[];return e.onStepEnd&&i.push(e.onStepEnd(t,e)),b.onStepEnd&&i.push(b.onStepEnd(t,e)),await Promise.all(i)}async continue(e,t={}){let{runNow:i=false,steps:n=1}=t;if(!Number.isFinite(n)){L.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){L.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!i&&!this.getCanContinue({showWarn:true}))return;if(!i&&core.GameUnifier.runningStepsCount!==0){core.GameUnifier.increaseContinueRequest(n);return}n>1&&core.GameUnifier.increaseContinueRequest(n-1),core.GameUnifier.runningStepsCount++;let s;try{core.GameUnifier.runningStepsCount===1&&await core.GameUnifier.onPreContinue(),b.increaseCurrentStepIndex(),s=await this.runCurrentStep(e,t);}catch(a){throw L.error("Error continuing",a),a}finally{core.GameUnifier.runningStepsCount--,s=await this.afterRunCurrentStep(e)||s;}return 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:i}=t;if(b.currentLabelId){let n=b.currentLabelStepIndex;if(n===null){L.error("currentLabelStepIndex is null");return}let s=b._currentLabel;if(!s){L.error("currentLabel not found");return}if(s.stepCount>n){try{await this.onStepStart(s,n);}catch(c){L.error("Error running onStepStart",c),this.onStepError&&await this.onStepError(c,e);return}let a=s.getStepById(n);if(!a){L.error("step not found");return}let l=s.getStepSha(n);l||(L.warn("stepSha not found, setting to ERROR"),l="error");let u,S;try{u=await a(e,{labelId:s.id});}catch(c){L.error("Error running step",c),S=c;}try{let c=this.choices;if(c?.length===1&&c[0].autoSelect){let _=c[0];u=await this.selectChoice(_,e);}}catch(c){L.error("Error auto-selecting choice",c),S===void 0&&(S=c);}try{let c=b.lastHistoryStep;i!==void 0&&c&&(l=c.stepSha1,l||(L.warn("stepSha not found, setting to ERROR"),l="error"),b.addChoicesMade(c.currentLabel||"error",typeof c.labelStepIndex=="number"?c.labelStepIndex:-1,c.stepSha1||"error",i),b.choiceMadeTemp=i);}catch(c){L.warn("Error adding choice made to history",c);}try{core.GameUnifier.runningStepsCount===1&&(b.addLabelHistory(s.id,n),this.addStepHistory(l,{...t,choiceMade:b.choiceMadeTemp}),b.choiceMadeTemp=void 0);}catch(c){L.warn("Error adding step to history",c);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,b.currentLabelStepIndex||0);}catch(c){L.warn("Error running onStepEnd",c);}return S&&this.onStepError&&await this.onStepError(S,e),u}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,i){let{choiceMade:n}=i||{},s;typeof e=="string"?s=e:s=e.id,core.GameUnifier.runningStepsCount++;let a;try{let l=oe.get(s);if(!l)throw new core.PixiError("unregistered_element",`Label ${s} not found`);b.pushNewLabel(l.id),a=await this.runCurrentStep(t,{choiceMade:n});}catch(l){throw L.error("Error calling label",l),l}finally{core.GameUnifier.runningStepsCount--,a=await this.afterRunCurrentStep(t)||a;}return a}async jump(e,t,i){if(this.stepCounter===0)return await this.call(e,t,i);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:n}=i||{},s;typeof e=="string"?s=e:s=e.id,core.GameUnifier.runningStepsCount++;let a;try{let l=oe.get(s);if(!l)throw new core.PixiError("unregistered_element",`Label ${s} not found`);b.pushNewLabel(l.id),a=await this.runCurrentStep(t,{choiceMade:n});}catch(l){throw L.error("Error jumping to label",l),l}finally{core.GameUnifier.runningStepsCount--,a=await this.afterRunCurrentStep(t)||a;}return a}async selectChoice(e,t){this.choices=void 0;let i=e.type;switch(i){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 ${i} not found`),new core.PixiError("invalid_usage",`Type ${i} 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 i;return typeof e.choiceIndex=="number"&&(i=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:i})}get onStepError(){return async(e,t)=>{try{await core.GameUnifier.runOnError(e,t);}catch(i){L.error("Error in onError handler",i);}}}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 i=[];Array.isArray(t.text)?i=[...t.text]:i=[t.text],Array.isArray(e.text)?i=[...i,...e.text]:i=[...i,e.text],e.text=i,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,he({...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=[],i=e.map((s,a)=>({...s,choiceIndex:a})),n=this.alreadyCurrentStepMadeChoices;if(i=i.filter((s,a)=>s.oneTime&&n&&n.includes(a)?false:s.onlyHaveNoChoice?(t.push(s),false):true),i.length>0)return i;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,he(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:he(b.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async i=>{let n=[],s=oe.get(i.label);return s&&(s.onLoadingLabel&&n.push(s.onLoadingLabel(e,s)),b.onLoadingLabel&&n.push(b.onLoadingLabel(e,s))),await Promise.all(n)});return await Promise.all(t)}async restore(e,t){this.clear();try{b.lastHistoryStep=t,e.hasOwnProperty("openedLabels")?(b.openedLabels=e.openedLabels,b.originalOpenedLabels=b.openedLabels):L.warn("Could not import openedLabels data, so will be ignored"),e.hasOwnProperty("stepCounter")?b._stepCounter=e.stepCounter:L.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(b.currentLabelStepIndex||0);}catch(i){L.error("Error running onLoadingLabel",i);}}catch(i){L.error("Error importing data",i);}}};function At(h,e,t,i){let n=typeof e=="string"?e:e.id;return {...i,label:n,props:t,text:h,type:i?.type||"call"}}var et="close";function Mt(h,e){return {...e,type:et,text:h}}var bt=Ct(ft());var Ae=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 Me=class extends Ae{constructor(t,i,n){super(t,n);E(this,"_steps");this._steps=i;}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 i=this.steps[t];return (0,bt.default)(i.toString().toLocaleLowerCase()).toString()}catch(i){return L.warn("stepSha not found, setting to ERROR",i),"error"}}};function mt(h,e,t){let i=new Me(h,e,t);return oe.add(i),i}var Nr=new Ue;
exports.Close=et;exports.Label=Me;exports.LabelAbstract=Ae;exports.NarrationManagerStatic=b;exports.RegisteredLabels=oe;exports.narration=Nr;exports.newChoiceOption=At;exports.newCloseChoiceOption=Mt;exports.newLabel=mt;//# sourceMappingURL=narration.cjs.map
//# sourceMappingURL=narration.cjs.map