@drincs/pixi-vn 1.8.1 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +14 -58
  2. package/dist/{HistoryChoiceMenuOption-BP9Tsbyd.d.ts → HistoryChoiceMenuOption-CS41KG13.d.ts} +2 -2
  3. package/dist/{HistoryChoiceMenuOption-DSSNUXEq.d.cts → HistoryChoiceMenuOption-DdwePsOm.d.cts} +2 -2
  4. package/dist/{StorageElementType-DkJ394kq.d.cts → StorageElementType-C7ETezlL.d.cts} +1 -1
  5. package/dist/{StorageElementType-DkJ394kq.d.ts → StorageElementType-C7ETezlL.d.ts} +1 -1
  6. package/dist/{StoredClassModel-a4pvgJXD.d.ts → StoredClassModel-C9mQxPg-.d.cts} +9 -6
  7. package/dist/{StoredClassModel-LtyakzOw.d.cts → StoredClassModel-upXPNQTp.d.ts} +9 -6
  8. package/dist/canvas.cjs +1 -1
  9. package/dist/canvas.mjs +1 -1
  10. package/dist/characters.cjs +1 -1
  11. package/dist/characters.d.cts +55 -51
  12. package/dist/characters.d.ts +55 -51
  13. package/dist/characters.mjs +1 -1
  14. package/dist/chunk-K7JIC2F2.mjs +1 -0
  15. package/dist/{chunk-36I5IN5S.mjs → chunk-V34PMA2H.mjs} +1 -1
  16. package/dist/history.d.cts +2 -2
  17. package/dist/history.d.ts +2 -2
  18. package/dist/index.cjs +2 -2
  19. package/dist/index.d.cts +21 -6
  20. package/dist/index.d.ts +21 -6
  21. package/dist/index.mjs +2 -2
  22. package/dist/narration.cjs +2 -2
  23. package/dist/narration.d.cts +41 -10
  24. package/dist/narration.d.ts +41 -10
  25. package/dist/narration.mjs +2 -2
  26. package/dist/storage.cjs +1 -1
  27. package/dist/storage.d.cts +3 -3
  28. package/dist/storage.d.ts +3 -3
  29. package/dist/storage.mjs +1 -1
  30. package/dist/vite-listener.cjs +1 -1
  31. package/dist/vite-listener.d.cts +13 -4
  32. package/dist/vite-listener.d.ts +13 -4
  33. package/dist/vite-listener.mjs +1 -1
  34. package/dist/vite.cjs +1 -1
  35. package/dist/vite.d.cts +66 -36
  36. package/dist/vite.d.ts +66 -36
  37. package/dist/vite.mjs +1 -1
  38. package/package.json +15 -7
  39. package/dist/chunk-TTRUPDAB.mjs +0 -1
@@ -1,2 +1,2 @@
1
- '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;
2
- exports.Label=Ae;exports.LabelAbstract=xe;exports.NarrationManagerStatic=b;exports.RegisteredLabels=ae;exports.narration=wr;exports.newChoiceOption=At;exports.newCloseChoiceOption=Mt;exports.newLabel=yt;
1
+ '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,v=a.sigBytes;if(this.clamp(),I%4)for(var Y=0;Y<v;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<v;H+=4)d[I+H>>>2]=O[H>>>2];return this.sigBytes+=v,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=[],v=0;v<O;v++){var Y=d[v>>>2]>>>24-v%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=[],v=0;v<O;v++){var Y=d[v>>>2]>>>24-v%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,v=O.sigBytes,Y=this.blockSize,le=Y*4,H=v/le;a?H=e.ceil(H):H=e.max((H|0)-this._minBufferSize,0);var Q=H*Y,Te=e.min(Q*4,v);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 w="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:v,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=!!v,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 v=f(this,c,Ge).call(this,e,I,O,A);return v.__returned=v}else {let v=r(this,_)[I];if(f(this,c,M).call(this,v)){let Q=n&&v.__staleWhileFetching!==void 0;return a&&(a.fetch="inflight",Q&&(a.returnedStale=true)),Q?v.__staleWhileFetching:v.__returned=v}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),v;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,v=r(this,_)[t];return (v===P||d&&C&&v===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,v=P;if(r(this,_)[t]===P&&(!I||!C&&v.__staleWhileFetching===void 0?f(this,c,ye).call(this,e,"fetch"):d||(r(this,_)[t]=v.__staleWhileFetching)),O)return n.status&&v.__staleWhileFetching!==void 0&&(n.status.returnedStale=true),v.__staleWhileFetching;if(v.__returned===v)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 ve=new Pe({cacheSize:10}),Ze;(s=>{function h(o){let l=ve.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}ve.has(o.id)&&L.info(`Label "${o.id}" already exists, it will be overwritten`),ve.set(o.id,o);}s.add=e;function t(){return Array.from(ve.values())}s.values=t;function n(o){return ve.has(o)}s.has=n;function i(){return Array.from(ve.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(w,R.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){core.GameUnifier.setVariable(w,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(w,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(w,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};o[s]||(o[s]={}),o[s][i]=t,core.GameUnifier.setVariable(w,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(w,R.CURRENT_STEP_TIMES_COUNTER_KEY)||{};s[i]||(s[i]={}),s[i][n]={stepCounters:[],stepSha1:""},core.GameUnifier.setVariable(w,R.CURRENT_STEP_TIMES_COUNTER_KEY,s);}static get allChoicesMade(){return core.GameUnifier.getVariable(w,R.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){core.GameUnifier.setVariable(w,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(w,R.LAST_STEP_GLUED)===this.stepCounter;core.GameUnifier.getVariable(w,R.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(s=core.GameUnifier.getVariable(w,R.CURRENT_DIALOGUE_MEMORY_KEY)),core.GameUnifier.getVariable(w,R.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(o=core.GameUnifier.getVariable(w,R.CURRENT_MENU_OPTIONS_MEMORY_KEY)),core.GameUnifier.getVariable(w,R.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(l=core.GameUnifier.getVariable(w,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.com/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(w,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(w,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(w,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(w,R.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{core.GameUnifier.setVariable(w,R.CURRENT_DIALOGUE_MEMORY_KEY,ce({...e,character:typeof e.character=="string"?e.character:e.character?.id})),core.GameUnifier.setVariable(w,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(w,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(w,R.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{core.GameUnifier.setVariable(w,R.CURRENT_MENU_OPTIONS_MEMORY_KEY,ce(e)),core.GameUnifier.setVariable(w,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(w,R.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),core.GameUnifier.setVariable(w,R.CURRENT_INPUT_VALUE_MEMORY_KEY,e),core.GameUnifier.setVariable(w,R.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return core.GameUnifier.getVariable(w,R.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return core.GameUnifier.getVariable(w,R.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e,t){e.isRequired=true,core.GameUnifier.setVariable(w,R.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?core.GameUnifier.setVariable(w,R.CURRENT_INPUT_VALUE_MEMORY_KEY,t):core.GameUnifier.removeVariable(w,R.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){core.GameUnifier.removeVariable(w,R.CURRENT_INPUT_INFO_MEMORY_KEY),core.GameUnifier.removeVariable(w,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 vr=new Ue;
2
+ exports.Label=Ae;exports.LabelAbstract=xe;exports.NarrationManagerStatic=b;exports.RegisteredLabels=ae;exports.narration=vr;exports.newChoiceOption=At;exports.newCloseChoiceOption=Mt;exports.newLabel=yt;
@@ -1,19 +1,34 @@
1
1
  import { ChoiceInterface as ChoiceInterface$1 } from '@drincs/pixi-vn';
2
- import { S as StorageObjectType, a as StorageElementType } from './StorageElementType-DkJ394kq.cjs';
3
- import { L as LabelIdType, S as StepLabelType, a as LabelRunModeType, C as ChoiceOptionInterface, b as CloseChoiceOptionInterface, c as CloseType, O as OpenedLabel, d as StepLabelPropsType, e as StepLabelResultType, f as StoredIndexedChoiceInterface, D as DialogueInterface, g as StoredChoiceInterface, H as HistoryStep } from './HistoryChoiceMenuOption-DSSNUXEq.cjs';
4
- export { h as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-DSSNUXEq.cjs';
2
+ import { a as StorageObjectType, S as StorageElementType } from './StorageElementType-C7ETezlL.cjs';
3
+ import { L as LabelIdType, f as StepLabelType, d as LabelRunModeType, C as ChoiceOptionInterface, a as CloseChoiceOptionInterface, b as CloseType, O as OpenedLabel, S as StepLabelPropsType, e as StepLabelResultType, h as StoredIndexedChoiceInterface, D as DialogueInterface, g as StoredChoiceInterface, c as HistoryStep } from './HistoryChoiceMenuOption-DdwePsOm.cjs';
4
+ export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-DdwePsOm.cjs';
5
5
  import 'microdiff';
6
6
 
7
7
  interface LabelProps<T, StepIdType = number> {
8
8
  /**
9
- * Is a function that will be executed before any step is executed.
9
+ * A function executed before each `step`.
10
10
  * @param stepId Step id
11
11
  * @param label Label
12
12
  * @returns
13
+ * @example
14
+ * ```ts
15
+ * const startLabel = newLabel("start", [
16
+ * () => {
17
+ * narration.dialogue = "Step 1"
18
+ * },
19
+ * () => {
20
+ * narration.dialogue = "Step 2"
21
+ * }
22
+ * ], {
23
+ * onStepStart: (stepIndex, label) => {
24
+ * console.log(`Step ${stepIndex} started`)
25
+ * }
26
+ * })
27
+ * ```
13
28
  */
14
29
  onStepStart?: (stepId: StepIdType, label: T) => void | Promise<void>;
15
30
  /**
16
- * Is a function that will be executed in {@link Label.onStepStart} if the id of the step is 0
31
+ * Is a function that will be executed in {@link onStepStart} if the id of the step is 0
17
32
  * and when the user laods a save file.
18
33
  * When you load a save file, will be executed all onLoadingLabel functions of the {@link narration.openedLabels}.
19
34
  * It is useful for example to make sure all images used have been cached
@@ -21,7 +36,7 @@ interface LabelProps<T, StepIdType = number> {
21
36
  * @param label Label
22
37
  * @returns
23
38
  * @example
24
- * ```typescript
39
+ * ```ts
25
40
  * newLabel("id", [], {
26
41
  * onLoadingLabel: async (stepId, label) => {
27
42
  * await Assets.load('path/to/image1.png')
@@ -32,10 +47,24 @@ interface LabelProps<T, StepIdType = number> {
32
47
  */
33
48
  onLoadingLabel?: (stepId: StepIdType, label: T) => void | Promise<void>;
34
49
  /**
35
- * Is a function that will be executed when the step ends.
50
+ * A function executed after each `step`. See more <DynamicLink href="/start/labels-advanced#onstepend">here</DynamicLink>.
36
51
  * @param stepId Step id
37
52
  * @param label Label
38
53
  * @returns
54
+ * @example
55
+ * ```ts
56
+ * const startLabel = newLabel("start", [
57
+ * async () => {
58
+ * await showImage("image1", "path/to/image1.png")
59
+ * await showImage("image2", "path/to/image2.png")
60
+ * }
61
+ * ], {
62
+ * onLoadingLabel: async (stepIndex, label) => {
63
+ * await Assets.load("path/to/image1.png")
64
+ * await Assets.load("path/to/image2.png")
65
+ * }
66
+ * })
67
+ * ```
39
68
  */
40
69
  onStepEnd?: (stepId: StepIdType, label: T) => void | Promise<void>;
41
70
  }
@@ -150,9 +179,9 @@ type LabelSteps<T extends {}> = [StepLabelType<T>, ...StepLabelType<Partial<T>>[
150
179
  /**
151
180
  * Creates a new label and registers it in the system.
152
181
  * **This function must be called at least once at system startup to register the label, otherwise the system cannot be used.**
153
- * @param id The id of the label, it must be unique
154
- * @param steps The steps of the label
155
- * @param props The properties of the label
182
+ * @param id A unique identifier. Used to reference the `label` in the game (must be unique).
183
+ * @param steps An array of functions to be executed in order. To create a dynamic array.
184
+ * @param props An object with the `label`'s options
156
185
  * @returns The created label
157
186
  */
158
187
  declare function newLabel<T extends {} = {}>(id: LabelIdType, steps: LabelSteps<T> | (() => LabelSteps<T>), props?: LabelProps<Label<T>>): Label<T>;
@@ -501,6 +530,7 @@ interface NarrationManagerInterface {
501
530
  /**
502
531
  * StepLabelPropsType is the type of the props that will be passed to the StepLabel.
503
532
  * You can override this interface to add your own props.
533
+ * @default {}
504
534
  * @example
505
535
  * ```typescript
506
536
  * // pixi-vn.d.ts
@@ -519,6 +549,7 @@ interface StepLabelProps {
519
549
  * StepLabelResultType is the return type of the StepLabel function.
520
550
  * It can be useful for returning to the information calling function to perform other operations that cannot be performed within the StepLabel.
521
551
  * You can override this interface to add your own return types.
552
+ * @default {}
522
553
  * @example
523
554
  * ```typescript
524
555
  * // pixi-vn.d.ts
@@ -1,19 +1,34 @@
1
1
  import { ChoiceInterface as ChoiceInterface$1 } from '@drincs/pixi-vn';
2
- import { S as StorageObjectType, a as StorageElementType } from './StorageElementType-DkJ394kq.js';
3
- import { L as LabelIdType, S as StepLabelType, a as LabelRunModeType, C as ChoiceOptionInterface, b as CloseChoiceOptionInterface, c as CloseType, O as OpenedLabel, d as StepLabelPropsType, e as StepLabelResultType, f as StoredIndexedChoiceInterface, D as DialogueInterface, g as StoredChoiceInterface, H as HistoryStep } from './HistoryChoiceMenuOption-BP9Tsbyd.js';
4
- export { h as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-BP9Tsbyd.js';
2
+ import { a as StorageObjectType, S as StorageElementType } from './StorageElementType-C7ETezlL.js';
3
+ import { L as LabelIdType, f as StepLabelType, d as LabelRunModeType, C as ChoiceOptionInterface, a as CloseChoiceOptionInterface, b as CloseType, O as OpenedLabel, S as StepLabelPropsType, e as StepLabelResultType, h as StoredIndexedChoiceInterface, D as DialogueInterface, g as StoredChoiceInterface, c as HistoryStep } from './HistoryChoiceMenuOption-CS41KG13.js';
4
+ export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-CS41KG13.js';
5
5
  import 'microdiff';
6
6
 
7
7
  interface LabelProps<T, StepIdType = number> {
8
8
  /**
9
- * Is a function that will be executed before any step is executed.
9
+ * A function executed before each `step`.
10
10
  * @param stepId Step id
11
11
  * @param label Label
12
12
  * @returns
13
+ * @example
14
+ * ```ts
15
+ * const startLabel = newLabel("start", [
16
+ * () => {
17
+ * narration.dialogue = "Step 1"
18
+ * },
19
+ * () => {
20
+ * narration.dialogue = "Step 2"
21
+ * }
22
+ * ], {
23
+ * onStepStart: (stepIndex, label) => {
24
+ * console.log(`Step ${stepIndex} started`)
25
+ * }
26
+ * })
27
+ * ```
13
28
  */
14
29
  onStepStart?: (stepId: StepIdType, label: T) => void | Promise<void>;
15
30
  /**
16
- * Is a function that will be executed in {@link Label.onStepStart} if the id of the step is 0
31
+ * Is a function that will be executed in {@link onStepStart} if the id of the step is 0
17
32
  * and when the user laods a save file.
18
33
  * When you load a save file, will be executed all onLoadingLabel functions of the {@link narration.openedLabels}.
19
34
  * It is useful for example to make sure all images used have been cached
@@ -21,7 +36,7 @@ interface LabelProps<T, StepIdType = number> {
21
36
  * @param label Label
22
37
  * @returns
23
38
  * @example
24
- * ```typescript
39
+ * ```ts
25
40
  * newLabel("id", [], {
26
41
  * onLoadingLabel: async (stepId, label) => {
27
42
  * await Assets.load('path/to/image1.png')
@@ -32,10 +47,24 @@ interface LabelProps<T, StepIdType = number> {
32
47
  */
33
48
  onLoadingLabel?: (stepId: StepIdType, label: T) => void | Promise<void>;
34
49
  /**
35
- * Is a function that will be executed when the step ends.
50
+ * A function executed after each `step`. See more <DynamicLink href="/start/labels-advanced#onstepend">here</DynamicLink>.
36
51
  * @param stepId Step id
37
52
  * @param label Label
38
53
  * @returns
54
+ * @example
55
+ * ```ts
56
+ * const startLabel = newLabel("start", [
57
+ * async () => {
58
+ * await showImage("image1", "path/to/image1.png")
59
+ * await showImage("image2", "path/to/image2.png")
60
+ * }
61
+ * ], {
62
+ * onLoadingLabel: async (stepIndex, label) => {
63
+ * await Assets.load("path/to/image1.png")
64
+ * await Assets.load("path/to/image2.png")
65
+ * }
66
+ * })
67
+ * ```
39
68
  */
40
69
  onStepEnd?: (stepId: StepIdType, label: T) => void | Promise<void>;
41
70
  }
@@ -150,9 +179,9 @@ type LabelSteps<T extends {}> = [StepLabelType<T>, ...StepLabelType<Partial<T>>[
150
179
  /**
151
180
  * Creates a new label and registers it in the system.
152
181
  * **This function must be called at least once at system startup to register the label, otherwise the system cannot be used.**
153
- * @param id The id of the label, it must be unique
154
- * @param steps The steps of the label
155
- * @param props The properties of the label
182
+ * @param id A unique identifier. Used to reference the `label` in the game (must be unique).
183
+ * @param steps An array of functions to be executed in order. To create a dynamic array.
184
+ * @param props An object with the `label`'s options
156
185
  * @returns The created label
157
186
  */
158
187
  declare function newLabel<T extends {} = {}>(id: LabelIdType, steps: LabelSteps<T> | (() => LabelSteps<T>), props?: LabelProps<Label<T>>): Label<T>;
@@ -501,6 +530,7 @@ interface NarrationManagerInterface {
501
530
  /**
502
531
  * StepLabelPropsType is the type of the props that will be passed to the StepLabel.
503
532
  * You can override this interface to add your own props.
533
+ * @default {}
504
534
  * @example
505
535
  * ```typescript
506
536
  * // pixi-vn.d.ts
@@ -519,6 +549,7 @@ interface StepLabelProps {
519
549
  * StepLabelResultType is the return type of the StepLabel function.
520
550
  * It can be useful for returning to the information calling function to perform other operations that cannot be performed within the StepLabel.
521
551
  * You can override this interface to add your own return types.
552
+ * @default {}
522
553
  * @example
523
554
  * ```typescript
524
555
  * // pixi-vn.d.ts
@@ -1,2 +1,2 @@
1
- import {a}from'./chunk-YCWXA3OR.mjs';import {l,n}from'./chunk-IWAXXFXE.mjs';import {e,d,c,f,g as g$1}from'./chunk-Z4GZCINS.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var I=new e({cacheSize:10}),O;(a=>{function y(p){let u=I.get(p);if(!u){f.error(`Label "${p}" not found`);return}return u}a.get=y;function e(p){if(Array.isArray(p)){p.forEach(u=>{e(u);});return}I.has(p.id)&&f.info(`Label "${p.id}" already exists, it will be overwritten`),I.set(p.id,p);}a.add=e;function t(){return Array.from(I.values())}a.values=t;function r(p){return I.has(p)}a.has=r;function n(){return Array.from(I.keys())}a.keys=n;})(O||(O={}));var L=O;var i=class i{constructor(){}static get allOpenedLabels(){return GameUnifier.getVariable(l,n.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(l,n.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=i.currentLabelStepIndex;if(t===null)return f.error("currentLabelStepIndex is null"),null;let r=`${t}${e}`,n$1=i.currentLabelId,a=i._currentLabel;if(!n$1||t===null||!a)return f.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let p=a.getStepSha(t)||"error",u=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return u[n$1]||(u[n$1]={}),(!u[n$1][r]||u[n$1][r].stepSha1!==p)&&(u[n$1][r]={stepSha1:p}),u[n$1][r]}static setCurrentStepTimesCounterData(e="",t){let r=i.currentLabelStepIndex,n$1=r+e,a=i.currentLabelId;if(!a||r===null){f.error("currentLabelId or currentLabelStepIndex is null");return}let p=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};p[a]||(p[a]={}),p[a][n$1]=t,GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,p);}static getCurrentStepTimesCounter(e=""){let t=i._stepCounter,r=i.getCurrentStepTimesCounterData(e);if(!r)return f.error("getCurrentStepTimesCounter obj is null"),0;let n=r.stepCounters||[];return n.find(p=>p===t)||(n.push(t),r.stepCounters=n,i.setCurrentStepTimesCounterData(e,r)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let p=i.getCurrentStepTimesCounterData(n);if(!p)return;let u=p.usedRandomNumbers||{},S=Array.from({length:t-e+1},(_,A)=>A+e).filter(_=>!u[`${e}-${t}`]?.includes(_));if(S.length===0)return;let m=Math.floor(Math.random()*S.length),b=S[m];return u[`${e}-${t}`]||(u[`${e}-${t}`]=[]),u[`${e}-${t}`].push(b),p.usedRandomNumbers=u,i.setCurrentStepTimesCounterData(n,p),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=i.currentLabelStepIndex,r=t+e,n$1=i.currentLabelId;if(!n$1||t===null){f.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n$1]||(a[n$1]={}),a[n$1][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(l,n.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(l,n.ALL_CHOICES_MADE_KEY,e);}static increaseStepCounter(){i._stepCounter++;}static get openedLabels(){return g$1(i._openedLabels)}static set openedLabels(e){i._openedLabels=g$1(e);}static get originalOpenedLabels(){return g$1(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=g$1(e);}static get _currentLabel(){if(i.currentLabelId)return L.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,p=a.findIndex(u=>u.labelId===e&&u.stepIndex===t&&u.choiceIndex===n&&u.stepSha1===r);p<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[p].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!L.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}};d(i,"choiceMadeTemp"),d(i,"lastHistoryStep",null),d(i,"_stepCounter",0),d(i,"_openedLabels",[]),d(i,"_originalOpenedLabels",[]),d(i,"_onStepStart"),d(i,"onLoadingLabel"),d(i,"onStepEnd");var o=i;var R=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n$1}=t,a,p,u,S=GameUnifier.getVariable(l,n.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(p=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(u=GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY));let m=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:p,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:u,alreadyMadeChoices:this.alreadyCurrentStepMadeChoices,isGlued:S,openedLabels:m};o.originalOpenedLabels=m,GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}closeCurrentLabel(){if(!o.currentLabelId){f.warn("No label to close");return}if(!this.currentLabel){f.error("currentLabel not found");return}let e=o.openedLabels;e.pop(),o.openedLabels=e,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=L.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e=o.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let r=t.getStepSha(e);return r||(f.warn("stepSha not found, setting to ERROR"),r="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e&&n.stepSha1===r)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.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,r=this.choices;return r&&r.length>0?(t&&f.warn("The player must make a choice"),false):this.isRequiredInput?(t&&f.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e,t={}){let{runNow:r=false,steps:n=1}=t;if(!Number.isFinite(n)){f.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){f.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r&&!this.getCanContinue({showWarn:true}))return;if(!r&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e,t);}catch(p){throw f.error("Error continuing",p),p}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||a}async afterRunCurrentStep(e){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e,{labelId:"end"});f.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:r}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){f.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){f.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){f.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e);return}let p=a.getStepById(n);if(!p){f.error("step not found");return}let u=a.getStepSha(n);u||(f.warn("stepSha not found, setting to ERROR"),u="error");let S,m;try{S=await p(e,{labelId:a.id});}catch(b){f.error("Error running step",b),m=b;}try{let b=this.choices;if(b?.length===1&&b[0].autoSelect){let _=b[0];S=await this.selectChoice(_,e);}}catch(b){f.error("Error auto-selecting choice",b),m||(m=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(u=b.stepSha1,u||(f.warn("stepSha not found, setting to ERROR"),u="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r),o.choiceMadeTemp=r);}catch(b){f.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),this.addStepHistory(u,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){f.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){f.warn("Error running onStepEnd",b);}return m&&this.onStepError&&await this.onStepError(m,e),S}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e,t);if(this.openedLabels.length===1){o.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;f.error("currentLabelId not found");}}async call(e,t,r){let{choiceMade:n}=r||{},a;typeof e=="string"?a=e:a=e.id,GameUnifier.runningStepsCount++;let p;try{let u=L.get(a);if(!u)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(u.id),p=await this.runCurrentStep(t,{choiceMade:n});}catch(u){throw f.error("Error calling label",u),u}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||p}async jump(e,t,r){if(this.stepCounter===0)return await this.call(e,t,r);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:n}=r||{},a;typeof e=="string"?a=e:a=e.id,GameUnifier.runningStepsCount++;let p;try{let u=L.get(a);if(!u)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(u.id),p=await this.runCurrentStep(t,{choiceMade:n});}catch(u){throw f.error("Error jumping to label",u),u}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||p}async selectChoice(e,t){this.choices=void 0;let r=e.type;switch(r){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 f.error(`Type ${r} not found`),new PixiError("invalid_usage",`Type ${r} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw f.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r;return typeof e.choiceIndex=="number"&&(r=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r})}get onStepError(){return async(e,t)=>{try{await GameUnifier.runOnError(e,t);}catch(r){f.error("Error in onError handler",r);}}}get dialogue(){let e=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e.text)?r=[...r,...e.text]:r=[...r,e.text],e.text=r,e.character=e.character||t.character;}GameUnifier.setVariable(l,n.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,g$1({...e,character:typeof e.character=="string"?e.character:e.character?.id})),GameUnifier.setVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw f.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,p)=>({...a,choiceIndex:p})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,p)=>a.oneTime&&n?.includes(p)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choices(e){if(!e||e.length===0){GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,g$1(e)),GameUnifier.setVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw f.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return GameUnifier.getFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e,t){e.isRequired=true,GameUnifier.setVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:g$1(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=L.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(o.openedLabels=e.openedLabels,o.originalOpenedLabels=o.openedLabels):f.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?o._stepCounter=e.stepCounter:f.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r){f.error("Error running onLoadingLabel",r);}}catch(r){f.error("Error importing data",r);}}};function Y(y,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:y,type:r?.type||"call"}}var x="close";function V(y,e){return {...e,type:x,text:y}}var N=c(a(),1);var g=class{constructor(e,t){d(this,"id");d(this,"_onStepStart");d(this,"_onLoadingLabel");d(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 E=class extends g{constructor(t,r,n){super(t,n);d(this,"_steps");this._steps=r;}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 f.warn("stepSha not found, setting to ERROR"),"error";try{let r=this.steps[t];return (0,N.default)(r.toString().toLocaleLowerCase()).toString()}catch(r){return f.warn("stepSha not found, setting to ERROR",r),"error"}}};function w(y,e,t){let r=new E(y,e,t);return L.add(r),r}var he=new R;
2
- export{E as Label,g as LabelAbstract,o as NarrationManagerStatic,L as RegisteredLabels,he as narration,Y as newChoiceOption,V as newCloseChoiceOption,w as newLabel};
1
+ import {a}from'./chunk-YCWXA3OR.mjs';import {l,n}from'./chunk-IWAXXFXE.mjs';import {e,d,c,f,g as g$1}from'./chunk-Z4GZCINS.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var I=new e({cacheSize:10}),O;(a=>{function y(p){let u=I.get(p);if(!u){f.error(`Label "${p}" not found`);return}return u}a.get=y;function e(p){if(Array.isArray(p)){p.forEach(u=>{e(u);});return}I.has(p.id)&&f.info(`Label "${p.id}" already exists, it will be overwritten`),I.set(p.id,p);}a.add=e;function t(){return Array.from(I.values())}a.values=t;function r(p){return I.has(p)}a.has=r;function n(){return Array.from(I.keys())}a.keys=n;})(O||(O={}));var L=O;var i=class i{constructor(){}static get allOpenedLabels(){return GameUnifier.getVariable(l,n.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(l,n.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=i.currentLabelStepIndex;if(t===null)return f.error("currentLabelStepIndex is null"),null;let r=`${t}${e}`,n$1=i.currentLabelId,a=i._currentLabel;if(!n$1||t===null||!a)return f.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let p=a.getStepSha(t)||"error",u=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return u[n$1]||(u[n$1]={}),(!u[n$1][r]||u[n$1][r].stepSha1!==p)&&(u[n$1][r]={stepSha1:p}),u[n$1][r]}static setCurrentStepTimesCounterData(e="",t){let r=i.currentLabelStepIndex,n$1=r+e,a=i.currentLabelId;if(!a||r===null){f.error("currentLabelId or currentLabelStepIndex is null");return}let p=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};p[a]||(p[a]={}),p[a][n$1]=t,GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,p);}static getCurrentStepTimesCounter(e=""){let t=i._stepCounter,r=i.getCurrentStepTimesCounterData(e);if(!r)return f.error("getCurrentStepTimesCounter obj is null"),0;let n=r.stepCounters||[];return n.find(p=>p===t)||(n.push(t),r.stepCounters=n,i.setCurrentStepTimesCounterData(e,r)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let p=i.getCurrentStepTimesCounterData(n);if(!p)return;let u=p.usedRandomNumbers||{},S=Array.from({length:t-e+1},(_,w)=>w+e).filter(_=>!u[`${e}-${t}`]?.includes(_));if(S.length===0)return;let m=Math.floor(Math.random()*S.length),b=S[m];return u[`${e}-${t}`]||(u[`${e}-${t}`]=[]),u[`${e}-${t}`].push(b),p.usedRandomNumbers=u,i.setCurrentStepTimesCounterData(n,p),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=i.currentLabelStepIndex,r=t+e,n$1=i.currentLabelId;if(!n$1||t===null){f.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n$1]||(a[n$1]={}),a[n$1][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(l,n.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(l,n.ALL_CHOICES_MADE_KEY,e);}static increaseStepCounter(){i._stepCounter++;}static get openedLabels(){return g$1(i._openedLabels)}static set openedLabels(e){i._openedLabels=g$1(e);}static get originalOpenedLabels(){return g$1(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=g$1(e);}static get _currentLabel(){if(i.currentLabelId)return L.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,p=a.findIndex(u=>u.labelId===e&&u.stepIndex===t&&u.choiceIndex===n&&u.stepSha1===r);p<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[p].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!L.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}};d(i,"choiceMadeTemp"),d(i,"lastHistoryStep",null),d(i,"_stepCounter",0),d(i,"_openedLabels",[]),d(i,"_originalOpenedLabels",[]),d(i,"_onStepStart"),d(i,"onLoadingLabel"),d(i,"onStepEnd");var o=i;var R=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n$1}=t,a,p,u,S=GameUnifier.getVariable(l,n.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(p=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(u=GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY));let m=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:p,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:u,alreadyMadeChoices:this.alreadyCurrentStepMadeChoices,isGlued:S,openedLabels:m};o.originalOpenedLabels=m,GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}closeCurrentLabel(){if(!o.currentLabelId){f.warn("No label to close");return}if(!this.currentLabel){f.error("currentLabel not found");return}let e=o.openedLabels;e.pop(),o.openedLabels=e,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=L.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e=o.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let r=t.getStepSha(e);return r||(f.warn("stepSha not found, setting to ERROR"),r="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e&&n.stepSha1===r)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.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,r=this.choices;return r&&r.length>0?(t&&f.warn("The player must make a choice"),false):this.isRequiredInput?(t&&f.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e,t={}){let{runNow:r=false,steps:n=1}=t;if(!Number.isFinite(n)){f.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){f.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r&&!this.getCanContinue({showWarn:true}))return;if(!r&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e,t);}catch(p){throw f.error("Error continuing",p),p}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||a}async afterRunCurrentStep(e){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e,{labelId:"end"});f.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.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e,t={}){let{choiceMade:r}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){f.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){f.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){f.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e);return}let p=a.getStepById(n);if(!p){f.error("step not found");return}let u=a.getStepSha(n);u||(f.warn("stepSha not found, setting to ERROR"),u="error");let S,m;try{S=await p(e,{labelId:a.id});}catch(b){f.error("Error running step",b),m=b;}try{let b=this.choices;if(b?.length===1&&b[0].autoSelect){let _=b[0];S=await this.selectChoice(_,e);}}catch(b){f.error("Error auto-selecting choice",b),m||(m=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(u=b.stepSha1,u||(f.warn("stepSha not found, setting to ERROR"),u="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r),o.choiceMadeTemp=r);}catch(b){f.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),this.addStepHistory(u,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){f.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){f.warn("Error running onStepEnd",b);}return m&&this.onStepError&&await this.onStepError(m,e),S}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e,t);if(this.openedLabels.length===1){o.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;f.error("currentLabelId not found");}}async call(e,t,r){let{choiceMade:n}=r||{},a;typeof e=="string"?a=e:a=e.id,GameUnifier.runningStepsCount++;let p;try{let u=L.get(a);if(!u)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(u.id),p=await this.runCurrentStep(t,{choiceMade:n});}catch(u){throw f.error("Error calling label",u),u}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||p}async jump(e,t,r){if(this.stepCounter===0)return await this.call(e,t,r);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:n}=r||{},a;typeof e=="string"?a=e:a=e.id,GameUnifier.runningStepsCount++;let p;try{let u=L.get(a);if(!u)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(u.id),p=await this.runCurrentStep(t,{choiceMade:n});}catch(u){throw f.error("Error jumping to label",u),u}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||p}async selectChoice(e,t){this.choices=void 0;let r=e.type;switch(r){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 f.error(`Type ${r} not found`),new PixiError("invalid_usage",`Type ${r} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw f.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r;return typeof e.choiceIndex=="number"&&(r=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r})}get onStepError(){return async(e,t)=>{try{await GameUnifier.runOnError(e,t);}catch(r){f.error("Error in onError handler",r);}}}get dialogue(){let e=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e.text)?r=[...r,...e.text]:r=[...r,e.text],e.text=r,e.character=e.character||t.character;}GameUnifier.setVariable(l,n.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,g$1({...e,character:typeof e.character=="string"?e.character:e.character?.id})),GameUnifier.setVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw f.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,p)=>({...a,choiceIndex:p})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,p)=>a.oneTime&&n?.includes(p)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choices(e){if(!e||e.length===0){GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,g$1(e)),GameUnifier.setVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw f.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return GameUnifier.getFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e,t){e.isRequired=true,GameUnifier.setVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:g$1(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=L.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(o.openedLabels=e.openedLabels,o.originalOpenedLabels=o.openedLabels):f.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?o._stepCounter=e.stepCounter:f.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r){f.error("Error running onLoadingLabel",r);}}catch(r){f.error("Error importing data",r);}}};function Y(y,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:y,type:r?.type||"call"}}var x="close";function V(y,e){return {...e,type:x,text:y}}var N=c(a(),1);var g=class{constructor(e,t){d(this,"id");d(this,"_onStepStart");d(this,"_onLoadingLabel");d(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 E=class extends g{constructor(t,r,n){super(t,n);d(this,"_steps");this._steps=r;}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 f.warn("stepSha not found, setting to ERROR"),"error";try{let r=this.steps[t];return (0,N.default)(r.toString().toLocaleLowerCase()).toString()}catch(r){return f.warn("stepSha not found, setting to ERROR",r),"error"}}};function A(y,e,t){let r=new E(y,e,t);return L.add(r),r}var he=new R;
2
+ export{E as Label,g as LabelAbstract,o as NarrationManagerStatic,L as RegisteredLabels,he as narration,Y as newChoiceOption,V as newCloseChoiceOption,A as newLabel};