@drincs/pixi-vn 1.9.2 → 1.9.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.
@@ -0,0 +1 @@
1
+ var jt=Object.create;var Rt=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var $t=Object.getPrototypeOf,Bt=Object.prototype.hasOwnProperty;var Lt=l=>{throw TypeError(l)};var Xt=(l,e,i)=>e in l?Rt(l,e,{enumerable:true,configurable:true,writable:true,value:i}):l[e]=i;var ee=(l=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(l,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):l)(function(l){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+l+'" is not supported')});var ie=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports);var qt=(l,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let h of kt(e))!Bt.call(l,h)&&h!==i&&Rt(l,h,{get:()=>e[h],enumerable:!(s=Ht(e,h))||s.enumerable});return l};var se=(l,e,i)=>(i=l!=null?jt($t(l)):{},qt(e||!l||!l.__esModule?Rt(i,"default",{value:l,enumerable:true}):i,l));var x=(l,e,i)=>Xt(l,typeof e!="symbol"?e+"":e,i),xt=(l,e,i)=>e.has(l)||Lt("Cannot "+i);var t=(l,e,i)=>(xt(l,e,"read from private field"),i?i.call(l):e.get(l)),_=(l,e,i)=>e.has(l)?Lt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(l):e.set(l,i),f=(l,e,i,s)=>(xt(l,e,"write to private field"),e.set(l,i),i),a=(l,e,i)=>(xt(l,e,"access private method"),i);var mt=(l,e,i,s)=>({set _(h){f(l,e,h);},get _(){return t(l,e,s)}});var oe="__game_layer__",ne="Container",re="ImageContainer",le="Image",ae="Sprite",ce="Text",ue="Video",fe="general",de="storage",pe="temp",_e="narration",ge="flags",Se={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 Jt=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Wt=new Set,Ft=typeof process=="object"&&process?process:{},Yt=(l,e,i,s)=>{typeof Ft.emitWarning=="function"?Ft.emitWarning(l,e,i,s):console.error(`[${i}] ${e}: ${l}`);},yt=globalThis.AbortController,Mt=globalThis.AbortSignal;if(typeof yt>"u"){Mt=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},yt=class{constructor(){e();}signal=new Mt;abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=true;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i);}}};let l=Ft.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{l&&(l=false,Yt("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 Qt=l=>!Wt.has(l);var tt=l=>l&&l===Math.floor(l)&&l>0&&isFinite(l),Pt=l=>tt(l)?l<=Math.pow(2,8)?Uint8Array:l<=Math.pow(2,16)?Uint16Array:l<=Math.pow(2,32)?Uint32Array:l<=Number.MAX_SAFE_INTEGER?vt:null:null,vt=class extends Array{constructor(l){super(l),this.fill(0);}},J,ut,Zt=(J=class{heap;length;static create(e){let i=Pt(e);if(!i)return [];f(J,ut,true);let s=new J(e,i);return f(J,ut,false),s}constructor(e,i){if(!t(J,ut))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new i(e),this.length=0;}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},ut=new WeakMap,_(J,ut,false),J),Ut,Gt,P,L,V,ot,K,ft,dt,j,O,H,T,w,d,N,M,F,y,k,b,$,B,U,G,X,ht,z,pt,r,Ct,nt,Q,At,W,Kt,rt,_t,wt,et,it,Dt,Tt,Ot,A,Nt,Et,st,zt,gt,Vt=(gt=class{constructor(e){_(this,r);_(this,P);_(this,L);_(this,V);_(this,ot);_(this,K);_(this,ft);_(this,dt);_(this,j);x(this,"ttl");x(this,"ttlResolution");x(this,"ttlAutopurge");x(this,"updateAgeOnGet");x(this,"updateAgeOnHas");x(this,"allowStale");x(this,"noDisposeOnSet");x(this,"noUpdateTTL");x(this,"maxEntrySize");x(this,"sizeCalculation");x(this,"noDeleteOnFetchRejection");x(this,"noDeleteOnStaleGet");x(this,"allowStaleOnFetchAbort");x(this,"allowStaleOnFetchRejection");x(this,"ignoreFetchAbort");_(this,O);_(this,H);_(this,T);_(this,w);_(this,d);_(this,N);_(this,M);_(this,F);_(this,y);_(this,k);_(this,b);_(this,$);_(this,B);_(this,U);_(this,G);_(this,X);_(this,ht);_(this,z);_(this,pt);_(this,nt,()=>{});_(this,Q,()=>{});_(this,At,()=>{});_(this,W,()=>false);_(this,rt,e=>{});_(this,_t,(e,i,s)=>{});_(this,wt,(e,i,s,h)=>{if(s||h)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});x(this,Ut,"LRUCache");let{max:i=0,ttl:s,ttlResolution:h=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:c,allowStale:u,dispose:g,onInsert:R,disposeAfter:S,noDisposeOnSet:Z,noUpdateTTL:Y,maxSize:q=0,maxEntrySize:m=0,sizeCalculation:E,fetchMethod:p,memoMethod:C,noDeleteOnFetchRejection:I,noDeleteOnStaleGet:D,allowStaleOnFetchRejection:v,allowStaleOnFetchAbort:St,ignoreFetchAbort:lt,perf:at}=e;if(at!==void 0&&typeof at?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(f(this,j,at??Jt),i!==0&&!tt(i))throw new TypeError("max option must be a nonnegative integer");let ct=i?Pt(i):Array;if(!ct)throw new Error("invalid max value: "+i);if(f(this,P,i),f(this,L,q),this.maxEntrySize=m||t(this,L),this.sizeCalculation=E,this.sizeCalculation){if(!t(this,L)&&!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(C!==void 0&&typeof C!="function")throw new TypeError("memoMethod must be a function if defined");if(f(this,dt,C),p!==void 0&&typeof p!="function")throw new TypeError("fetchMethod must be a function if specified");if(f(this,ft,p),f(this,ht,!!p),f(this,T,new Map),f(this,w,new Array(i).fill(void 0)),f(this,d,new Array(i).fill(void 0)),f(this,N,new ct(i)),f(this,M,new ct(i)),f(this,F,0),f(this,y,0),f(this,k,Zt.create(i)),f(this,O,0),f(this,H,0),typeof g=="function"&&f(this,V,g),typeof R=="function"&&f(this,ot,R),typeof S=="function"?(f(this,K,S),f(this,b,[])):(f(this,K,void 0),f(this,b,void 0)),f(this,X,!!t(this,V)),f(this,pt,!!t(this,ot)),f(this,z,!!t(this,K)),this.noDisposeOnSet=!!Z,this.noUpdateTTL=!!Y,this.noDeleteOnFetchRejection=!!I,this.allowStaleOnFetchRejection=!!v,this.allowStaleOnFetchAbort=!!St,this.ignoreFetchAbort=!!lt,this.maxEntrySize!==0){if(t(this,L)!==0&&!tt(t(this,L)))throw new TypeError("maxSize must be a positive integer if specified");if(!tt(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");a(this,r,Kt).call(this);}if(this.allowStale=!!u,this.noDeleteOnStaleGet=!!D,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!c,this.ttlResolution=tt(h)||h===0?h:1,this.ttlAutopurge=!!n,this.ttl=s||0,this.ttl){if(!tt(this.ttl))throw new TypeError("ttl must be a positive integer if specified");a(this,r,Ct).call(this);}if(t(this,P)===0&&this.ttl===0&&t(this,L)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!t(this,P)&&!t(this,L)){let bt="LRU_CACHE_UNBOUNDED";Qt(bt)&&(Wt.add(bt),Yt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",bt,gt));}}get perf(){return t(this,j)}static unsafeExposeInternals(e){return {starts:t(e,B),ttls:t(e,U),autopurgeTimers:t(e,G),sizes:t(e,$),keyMap:t(e,T),keyList:t(e,w),valList:t(e,d),next:t(e,N),prev:t(e,M),get head(){return t(e,F)},get tail(){return t(e,y)},free:t(e,k),isBackgroundFetch:i=>{var s;return a(s=e,r,A).call(s,i)},backgroundFetch:(i,s,h,n)=>{var o;return a(o=e,r,Ot).call(o,i,s,h,n)},moveToTail:i=>{var s;return a(s=e,r,Et).call(s,i)},indexes:i=>{var s;return a(s=e,r,et).call(s,i)},rindexes:i=>{var s;return a(s=e,r,it).call(s,i)},isStale:i=>{var s;return t(s=e,W).call(s,i)}}}get max(){return t(this,P)}get maxSize(){return t(this,L)}get calculatedSize(){return t(this,H)}get size(){return t(this,O)}get fetchMethod(){return t(this,ft)}get memoMethod(){return t(this,dt)}get dispose(){return t(this,V)}get onInsert(){return t(this,ot)}get disposeAfter(){return t(this,K)}getRemainingTTL(e){return t(this,T).has(e)?1/0:0}*entries(){for(let e of a(this,r,et).call(this))t(this,d)[e]!==void 0&&t(this,w)[e]!==void 0&&!a(this,r,A).call(this,t(this,d)[e])&&(yield [t(this,w)[e],t(this,d)[e]]);}*rentries(){for(let e of a(this,r,it).call(this))t(this,d)[e]!==void 0&&t(this,w)[e]!==void 0&&!a(this,r,A).call(this,t(this,d)[e])&&(yield [t(this,w)[e],t(this,d)[e]]);}*keys(){for(let e of a(this,r,et).call(this)){let i=t(this,w)[e];i!==void 0&&!a(this,r,A).call(this,t(this,d)[e])&&(yield i);}}*rkeys(){for(let e of a(this,r,it).call(this)){let i=t(this,w)[e];i!==void 0&&!a(this,r,A).call(this,t(this,d)[e])&&(yield i);}}*values(){for(let e of a(this,r,et).call(this))t(this,d)[e]!==void 0&&!a(this,r,A).call(this,t(this,d)[e])&&(yield t(this,d)[e]);}*rvalues(){for(let e of a(this,r,it).call(this))t(this,d)[e]!==void 0&&!a(this,r,A).call(this,t(this,d)[e])&&(yield t(this,d)[e]);}[(Gt=Symbol.iterator,Ut=Symbol.toStringTag,Gt)](){return this.entries()}find(e,i={}){for(let s of a(this,r,et).call(this)){let h=t(this,d)[s],n=a(this,r,A).call(this,h)?h.__staleWhileFetching:h;if(n!==void 0&&e(n,t(this,w)[s],this))return this.get(t(this,w)[s],i)}}forEach(e,i=this){for(let s of a(this,r,et).call(this)){let h=t(this,d)[s],n=a(this,r,A).call(this,h)?h.__staleWhileFetching:h;n!==void 0&&e.call(i,n,t(this,w)[s],this);}}rforEach(e,i=this){for(let s of a(this,r,it).call(this)){let h=t(this,d)[s],n=a(this,r,A).call(this,h)?h.__staleWhileFetching:h;n!==void 0&&e.call(i,n,t(this,w)[s],this);}}purgeStale(){let e=false;for(let i of a(this,r,it).call(this,{allowStale:true}))t(this,W).call(this,i)&&(a(this,r,st).call(this,t(this,w)[i],"expire"),e=true);return e}info(e){let i=t(this,T).get(e);if(i===void 0)return;let s=t(this,d)[i],h=a(this,r,A).call(this,s)?s.__staleWhileFetching:s;if(h===void 0)return;let n={value:h};if(t(this,U)&&t(this,B)){let o=t(this,U)[i],c=t(this,B)[i];if(o&&c){let u=o-(t(this,j).now()-c);n.ttl=u,n.start=Date.now();}}return t(this,$)&&(n.size=t(this,$)[i]),n}dump(){let e=[];for(let i of a(this,r,et).call(this,{allowStale:true})){let s=t(this,w)[i],h=t(this,d)[i],n=a(this,r,A).call(this,h)?h.__staleWhileFetching:h;if(n===void 0||s===void 0)continue;let o={value:n};if(t(this,U)&&t(this,B)){o.ttl=t(this,U)[i];let c=t(this,j).now()-t(this,B)[i];o.start=Math.floor(Date.now()-c);}t(this,$)&&(o.size=t(this,$)[i]),e.unshift([s,o]);}return e}load(e){this.clear();for(let[i,s]of e){if(s.start){let h=Date.now()-s.start;s.start=t(this,j).now()-h;}this.set(i,s.value,s);}}set(e,i,s={}){var Z,Y,q,m;if(i===void 0)return this.delete(e),this;let{ttl:h=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:c=this.sizeCalculation,status:u}=s,{noUpdateTTL:g=this.noUpdateTTL}=s,R=t(this,wt).call(this,e,i,s.size||0,c);if(this.maxEntrySize&&R>this.maxEntrySize)return u&&(u.set="miss",u.maxEntrySizeExceeded=true),a(this,r,st).call(this,e,"set"),this;let S=t(this,O)===0?void 0:t(this,T).get(e);if(S===void 0)S=t(this,O)===0?t(this,y):t(this,k).length!==0?t(this,k).pop():t(this,O)===t(this,P)?a(this,r,Tt).call(this,false):t(this,O),t(this,w)[S]=e,t(this,d)[S]=i,t(this,T).set(e,S),t(this,N)[t(this,y)]=S,t(this,M)[S]=t(this,y),f(this,y,S),mt(this,O)._++,t(this,_t).call(this,S,R,u),u&&(u.set="add"),g=false,t(this,pt)&&((Z=t(this,ot))==null||Z.call(this,i,e,"add"));else {a(this,r,Et).call(this,S);let E=t(this,d)[S];if(i!==E){if(t(this,ht)&&a(this,r,A).call(this,E)){E.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:p}=E;p!==void 0&&!o&&(t(this,X)&&((Y=t(this,V))==null||Y.call(this,p,e,"set")),t(this,z)&&t(this,b)?.push([p,e,"set"]));}else o||(t(this,X)&&((q=t(this,V))==null||q.call(this,E,e,"set")),t(this,z)&&t(this,b)?.push([E,e,"set"]));if(t(this,rt).call(this,S),t(this,_t).call(this,S,R,u),t(this,d)[S]=i,u){u.set="replace";let p=E&&a(this,r,A).call(this,E)?E.__staleWhileFetching:E;p!==void 0&&(u.oldValue=p);}}else u&&(u.set="update");t(this,pt)&&this.onInsert?.(i,e,i===E?"update":"replace");}if(h!==0&&!t(this,U)&&a(this,r,Ct).call(this),t(this,U)&&(g||t(this,At).call(this,S,h,n),u&&t(this,Q).call(this,u,S)),!o&&t(this,z)&&t(this,b)){let E=t(this,b),p;for(;p=E?.shift();)(m=t(this,K))==null||m.call(this,...p);}return this}pop(){var e;try{for(;t(this,O);){let i=t(this,d)[t(this,F)];if(a(this,r,Tt).call(this,!0),a(this,r,A).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(t(this,z)&&t(this,b)){let i=t(this,b),s;for(;s=i?.shift();)(e=t(this,K))==null||e.call(this,...s);}}}has(e,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:h}=i,n=t(this,T).get(e);if(n!==void 0){let o=t(this,d)[n];if(a(this,r,A).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(t(this,W).call(this,n))h&&(h.has="stale",t(this,Q).call(this,h,n));else return s&&t(this,nt).call(this,n),h&&(h.has="hit",t(this,Q).call(this,h,n)),true}else h&&(h.has="miss");return false}peek(e,i={}){let{allowStale:s=this.allowStale}=i,h=t(this,T).get(e);if(h===void 0||!s&&t(this,W).call(this,h))return;let n=t(this,d)[h];return a(this,r,A).call(this,n)?n.__staleWhileFetching:n}async fetch(e,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:h=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:c=this.noDisposeOnSet,size:u=0,sizeCalculation:g=this.sizeCalculation,noUpdateTTL:R=this.noUpdateTTL,noDeleteOnFetchRejection:S=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:Z=this.allowStaleOnFetchRejection,ignoreFetchAbort:Y=this.ignoreFetchAbort,allowStaleOnFetchAbort:q=this.allowStaleOnFetchAbort,context:m,forceRefresh:E=false,status:p,signal:C}=i;if(!t(this,ht))return p&&(p.fetch="get"),this.get(e,{allowStale:s,updateAgeOnGet:h,noDeleteOnStaleGet:n,status:p});let I={allowStale:s,updateAgeOnGet:h,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:c,size:u,sizeCalculation:g,noUpdateTTL:R,noDeleteOnFetchRejection:S,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:q,ignoreFetchAbort:Y,status:p,signal:C},D=t(this,T).get(e);if(D===void 0){p&&(p.fetch="miss");let v=a(this,r,Ot).call(this,e,D,I,m);return v.__returned=v}else {let v=t(this,d)[D];if(a(this,r,A).call(this,v)){let ct=s&&v.__staleWhileFetching!==void 0;return p&&(p.fetch="inflight",ct&&(p.returnedStale=true)),ct?v.__staleWhileFetching:v.__returned=v}let St=t(this,W).call(this,D);if(!E&&!St)return p&&(p.fetch="hit"),a(this,r,Et).call(this,D),h&&t(this,nt).call(this,D),p&&t(this,Q).call(this,p,D),v;let lt=a(this,r,Ot).call(this,e,D,I,m),at=lt.__staleWhileFetching!==void 0&&s;return p&&(p.fetch=St?"stale":"refresh",at&&St&&(p.returnedStale=true)),at?lt.__staleWhileFetching:lt.__returned=lt}}async forceFetch(e,i={}){let s=await this.fetch(e,i);if(s===void 0)throw new Error("fetch() returned undefined");return s}memo(e,i={}){let s=t(this,dt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:h,forceRefresh:n,...o}=i,c=this.get(e,o);if(!n&&c!==void 0)return c;let u=s(e,c,{options:o,context:h});return this.set(e,u,o),u}get(e,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:h=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=i,c=t(this,T).get(e);if(c!==void 0){let u=t(this,d)[c],g=a(this,r,A).call(this,u);return o&&t(this,Q).call(this,o,c),t(this,W).call(this,c)?(o&&(o.get="stale"),g?(o&&s&&u.__staleWhileFetching!==void 0&&(o.returnedStale=true),s?u.__staleWhileFetching:void 0):(n||a(this,r,st).call(this,e,"expire"),o&&s&&(o.returnedStale=true),s?u:void 0)):(o&&(o.get="hit"),g?u.__staleWhileFetching:(a(this,r,Et).call(this,c),h&&t(this,nt).call(this,c),u))}else o&&(o.get="miss");}delete(e){return a(this,r,st).call(this,e,"delete")}clear(){return a(this,r,zt).call(this,"delete")}},P=new WeakMap,L=new WeakMap,V=new WeakMap,ot=new WeakMap,K=new WeakMap,ft=new WeakMap,dt=new WeakMap,j=new WeakMap,O=new WeakMap,H=new WeakMap,T=new WeakMap,w=new WeakMap,d=new WeakMap,N=new WeakMap,M=new WeakMap,F=new WeakMap,y=new WeakMap,k=new WeakMap,b=new WeakMap,$=new WeakMap,B=new WeakMap,U=new WeakMap,G=new WeakMap,X=new WeakMap,ht=new WeakMap,z=new WeakMap,pt=new WeakMap,r=new WeakSet,Ct=function(){let e=new vt(t(this,P)),i=new vt(t(this,P));f(this,U,e),f(this,B,i);let s=this.ttlAutopurge?new Array(t(this,P)):void 0;f(this,G,s),f(this,At,(c,u,g=t(this,j).now())=>{i[c]=u!==0?g:0,e[c]=u,h(c,u);}),f(this,nt,c=>{i[c]=e[c]!==0?t(this,j).now():0,h(c,e[c]);});let h=this.ttlAutopurge?(c,u)=>{if(s?.[c]&&(clearTimeout(s[c]),s[c]=void 0),u&&u!==0&&s){let g=setTimeout(()=>{t(this,W).call(this,c)&&a(this,r,st).call(this,t(this,w)[c],"expire");},u+1);g.unref&&g.unref(),s[c]=g;}}:()=>{};f(this,Q,(c,u)=>{if(e[u]){let g=e[u],R=i[u];if(!g||!R)return;c.ttl=g,c.start=R,c.now=n||o();let S=c.now-R;c.remainingTTL=g-S;}});let n=0,o=()=>{let c=t(this,j).now();if(this.ttlResolution>0){n=c;let u=setTimeout(()=>n=0,this.ttlResolution);u.unref&&u.unref();}return c};this.getRemainingTTL=c=>{let u=t(this,T).get(c);if(u===void 0)return 0;let g=e[u],R=i[u];if(!g||!R)return 1/0;let S=(n||o())-R;return g-S},f(this,W,c=>{let u=i[c],g=e[c];return !!g&&!!u&&(n||o())-u>g});},nt=new WeakMap,Q=new WeakMap,At=new WeakMap,W=new WeakMap,Kt=function(){let e=new vt(t(this,P));f(this,H,0),f(this,$,e),f(this,rt,i=>{f(this,H,t(this,H)-e[i]),e[i]=0;}),f(this,wt,(i,s,h,n)=>{if(a(this,r,A).call(this,s))return 0;if(!tt(h))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(h=n(s,i),!tt(h))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 h}),f(this,_t,(i,s,h)=>{if(e[i]=s,t(this,L)){let n=t(this,L)-e[i];for(;t(this,H)>n;)a(this,r,Tt).call(this,true);}f(this,H,t(this,H)+e[i]),h&&(h.entrySize=s,h.totalCalculatedSize=t(this,H));});},rt=new WeakMap,_t=new WeakMap,wt=new WeakMap,et=function*({allowStale:e=this.allowStale}={}){if(t(this,O))for(let i=t(this,y);!(!a(this,r,Dt).call(this,i)||((e||!t(this,W).call(this,i))&&(yield i),i===t(this,F)));)i=t(this,M)[i];},it=function*({allowStale:e=this.allowStale}={}){if(t(this,O))for(let i=t(this,F);!(!a(this,r,Dt).call(this,i)||((e||!t(this,W).call(this,i))&&(yield i),i===t(this,y)));)i=t(this,N)[i];},Dt=function(e){return e!==void 0&&t(this,T).get(t(this,w)[e])===e},Tt=function(e){var n;let i=t(this,F),s=t(this,w)[i],h=t(this,d)[i];return t(this,ht)&&a(this,r,A).call(this,h)?h.__abortController.abort(new Error("evicted")):(t(this,X)||t(this,z))&&(t(this,X)&&((n=t(this,V))==null||n.call(this,h,s,"evict")),t(this,z)&&t(this,b)?.push([h,s,"evict"])),t(this,rt).call(this,i),t(this,G)?.[i]&&(clearTimeout(t(this,G)[i]),t(this,G)[i]=void 0),e&&(t(this,w)[i]=void 0,t(this,d)[i]=void 0,t(this,k).push(i)),t(this,O)===1?(f(this,F,f(this,y,0)),t(this,k).length=0):f(this,F,t(this,N)[i]),t(this,T).delete(s),mt(this,O)._--,i},Ot=function(e,i,s,h){let n=i===void 0?void 0:t(this,d)[i];if(a(this,r,A).call(this,n))return n;let o=new yt,{signal:c}=s;c?.addEventListener("abort",()=>o.abort(c.reason),{signal:o.signal});let u={signal:o.signal,options:s,context:h},g=(m,E=false)=>{let{aborted:p}=o.signal,C=s.ignoreFetchAbort&&m!==void 0,I=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&m!==void 0);if(s.status&&(p&&!E?(s.status.fetchAborted=true,s.status.fetchError=o.signal.reason,C&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),p&&!C&&!E)return S(o.signal.reason,I);let D=Y,v=t(this,d)[i];return (v===Y||C&&E&&v===void 0)&&(m===void 0?D.__staleWhileFetching!==void 0?t(this,d)[i]=D.__staleWhileFetching:a(this,r,st).call(this,e,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(e,m,u.options))),m},R=m=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=m),S(m,false)),S=(m,E)=>{let{aborted:p}=o.signal,C=p&&s.allowStaleOnFetchAbort,I=C||s.allowStaleOnFetchRejection,D=I||s.noDeleteOnFetchRejection,v=Y;if(t(this,d)[i]===Y&&(!D||!E&&v.__staleWhileFetching===void 0?a(this,r,st).call(this,e,"fetch"):C||(t(this,d)[i]=v.__staleWhileFetching)),I)return s.status&&v.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),v.__staleWhileFetching;if(v.__returned===v)throw m},Z=(m,E)=>{var C;let p=(C=t(this,ft))==null?void 0:C.call(this,e,n,u);p&&p instanceof Promise&&p.then(I=>m(I===void 0?void 0:I),E),o.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(m(void 0),s.allowStaleOnFetchAbort&&(m=I=>g(I,true)));});};s.status&&(s.status.fetchDispatched=true);let Y=new Promise(Z).then(g,R),q=Object.assign(Y,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return i===void 0?(this.set(e,q,{...u.options,status:void 0}),i=t(this,T).get(e)):t(this,d)[i]=q,q},A=function(e){if(!t(this,ht))return false;let i=e;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof yt},Nt=function(e,i){t(this,M)[i]=e,t(this,N)[e]=i;},Et=function(e){e!==t(this,y)&&(e===t(this,F)?f(this,F,t(this,N)[e]):a(this,r,Nt).call(this,t(this,M)[e],t(this,N)[e]),a(this,r,Nt).call(this,t(this,y),e),f(this,y,e));},st=function(e,i){var h,n;let s=false;if(t(this,O)!==0){let o=t(this,T).get(e);if(o!==void 0)if(t(this,G)?.[o]&&(clearTimeout(t(this,G)?.[o]),t(this,G)[o]=void 0),s=true,t(this,O)===1)a(this,r,zt).call(this,i);else {t(this,rt).call(this,o);let c=t(this,d)[o];if(a(this,r,A).call(this,c)?c.__abortController.abort(new Error("deleted")):(t(this,X)||t(this,z))&&(t(this,X)&&((h=t(this,V))==null||h.call(this,c,e,i)),t(this,z)&&t(this,b)?.push([c,e,i])),t(this,T).delete(e),t(this,w)[o]=void 0,t(this,d)[o]=void 0,o===t(this,y))f(this,y,t(this,M)[o]);else if(o===t(this,F))f(this,F,t(this,N)[o]);else {let u=t(this,M)[o];t(this,N)[u]=t(this,N)[o];let g=t(this,N)[o];t(this,M)[g]=t(this,M)[o];}mt(this,O)._--,t(this,k).push(o);}}if(t(this,z)&&t(this,b)?.length){let o=t(this,b),c;for(;c=o?.shift();)(n=t(this,K))==null||n.call(this,...c);}return s},zt=function(e){var i,s;for(let h of a(this,r,it).call(this,{allowStale:true})){let n=t(this,d)[h];if(a(this,r,A).call(this,n))n.__abortController.abort(new Error("deleted"));else {let o=t(this,w)[h];t(this,X)&&((i=t(this,V))==null||i.call(this,n,o,e)),t(this,z)&&t(this,b)?.push([n,o,e]);}}if(t(this,T).clear(),t(this,d).fill(void 0),t(this,w).fill(void 0),t(this,U)&&t(this,B)){t(this,U).fill(0),t(this,B).fill(0);for(let h of t(this,G)??[])h!==void 0&&clearTimeout(h);t(this,G)?.fill(void 0);}if(t(this,$)&&t(this,$).fill(0),f(this,F,0),f(this,y,0),t(this,k).length=0,f(this,H,0),f(this,O,0),t(this,z)&&t(this,b)){let h=t(this,b),n;for(;n=h?.shift();)(s=t(this,K))==null||s.call(this,...n);}},gt);var It=class{cache;map=new Map;constructor(e){this.cache=new Vt({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 i=this.map.delete(e);return i&&this.cache.delete(e),i}get forEach(){return this.map.forEach}get(e){let i=this.cache.get(e);return i||this.map.get(e)}has(e){return this.map.has(e)}set(e,i){return this.map.set(e,i),this.cache.set(e,i),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var te;(h=>(h.log=(n,...o)=>console.log(`[Pixi\u2019VN] ${n}`,...o),h.warn=(n,...o)=>console.warn(`[Pixi\u2019VN] ${n}`,...o),h.error=(n,...o)=>console.error(`[Pixi\u2019VN] ${n}`,...o),h.info=(n,...o)=>console.info(`[Pixi\u2019VN] ${n}`,...o)))(te||={});export{ee as a,ie as b,se as c,oe as d,ne as e,re as f,le as g,ae as h,ce as i,ue as j,fe as k,de as l,pe as m,_e as n,ge as o,Se as p,It as q,te as r};
@@ -0,0 +1 @@
1
+ import {r}from'./chunk-U5BSF6X3.mjs';import {PixiError}from'@drincs/pixi-vn/core';function a(r$1){try{if(typeof r$1>"u")return r$1;let e=JSON.stringify(r$1);return JSON.parse(e)}catch(e){throw r.error("Error creating exportable element",r$1,e),new PixiError("not_json_serializable","Error creating exportable element")}}export{a};
package/dist/core.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var a;(o=>(o.log=(r,...s)=>console.log(`[Pixi\u2019VN] ${r}`,...s),o.warn=(r,...s)=>console.warn(`[Pixi\u2019VN] ${r}`,...s),o.error=(r,...s)=>console.error(`[Pixi\u2019VN] ${r}`,...s),o.info=(r,...s)=>console.info(`[Pixi\u2019VN] ${r}`,...s)))(a||={});var n=class extends Error{code;constructor(t,i,m,o,r){super(`[Pixi\u2019VN] ${i}`),this.code=t,m==="canvas"&&(this.canvasElementInfo=o,this.parent=r);}canvasElementInfo;parent};var l=class e{static init(t){t.navigate&&(e._navigate=t.navigate),e._getStepCounter=t.getStepCounter,e._setStepCounter=t.setStepCounter,e._getCurrentGameStepState=t.getCurrentGameStepState,e._restoreGameStepState=t.restoreGameStepState,e._getOpenedLabels=t.getOpenedLabels,e._processNavigationRequests=t.processNavigationRequests,e._getVariable=t.getVariable,e._setVariable=t.setVariable,e._removeVariable=t.removeVariable,e._getFlag=t.getFlag,e._setFlag=t.setFlag,t.onLabelClosing&&(e._onLabelClosing=t.onLabelClosing),e._addHistoryItem=t.addHistoryItem,e._getCharacter=t.getCharacter,e._animate=t.animate;}static _navigate=()=>{a.warn("Navigate function not initialized. You should add the navigate function in the Game.init() method.");};static get navigate(){return e._navigate}static set navigate(t){e._navigate=t;}static _getStepCounter=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static _setStepCounter=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get stepCounter(){return e._getStepCounter()}static set stepCounter(t){e._setStepCounter(t);}static _getCurrentGameStepState=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get currentGameStepState(){return e._getCurrentGameStepState()}static _restoreGameStepState=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get restoreGameStepState(){return e._restoreGameStepState}static _getOpenedLabels=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get openedLabels(){return e._getOpenedLabels()}static _onPreContinueHandlers=[];static addOnPreContinue(t){e._onPreContinueHandlers.push(t);}static removeOnPreContinue(t){e._onPreContinueHandlers=e._onPreContinueHandlers.filter(i=>i!==t);}static clearOnPreContinueHandlers(){e._onPreContinueHandlers=[];}static async runOnPreContinue(){let t=e._onPreContinueHandlers.slice();await Promise.all(t.map(i=>i()));}static get onPreContinue(){return e.runOnPreContinue}static navigationRequestsCount=0;static processNavigationLock=Promise.resolve();static get continueRequestsCount(){return e.navigationRequestsCount}static increaseContinueRequest(t=1){e.navigationRequestsCount+=t;}static get backRequestsCount(){return -1*e.navigationRequestsCount}static increaseBackRequest(t=1){e.navigationRequestsCount-=t;}static _processNavigationRequests=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static async processNavigationRequests(t){let i=e._processNavigationRequests(e.navigationRequestsCount,t);return e.navigationRequestsCount=i.newValue,await i.result}static _getVariable=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get getVariable(){return e._getVariable}static _setVariable=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get setVariable(){return e._setVariable}static _removeVariable=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get removeVariable(){return e._removeVariable}static _getFlag=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get getFlag(){return e._getFlag}static _setFlag=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get setFlag(){return e._setFlag}static _onLabelClosing=()=>{};static get onLabelClosing(){return e._onLabelClosing}static _addHistoryItem=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get addHistoryItem(){return e._addHistoryItem}static runningStepsCount=0;static _getCharacter=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented.")};static get getCharacter(){return e._getCharacter}static onEnd;static _onErrorHandlers=[];static addOnError(t){return e._onErrorHandlers.push(t),()=>e.removeOnError(t)}static removeOnError(t){e._onErrorHandlers=e._onErrorHandlers.filter(i=>i!==t);}static clearOnErrorHandlers(){e._onErrorHandlers.length=0;}static async runOnError(t,i){for(let m of e._onErrorHandlers.slice())try{await m(t,i);}catch(o){a.error("Error in onError handler",o);}}static _animate=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get animate(){return e._animate}};exports.GameUnifier=l;exports.PixiError=n;
1
+ 'use strict';var a=class extends Error{code;constructor(t,n,m,o,r){super(`[Pixi\u2019VN] ${n}`),this.code=t,m==="canvas"&&(this.canvasElementInfo=o,this.parent=r);}canvasElementInfo;parent};var i;(o=>(o.log=(r,...s)=>console.log(`[Pixi\u2019VN] ${r}`,...s),o.warn=(r,...s)=>console.warn(`[Pixi\u2019VN] ${r}`,...s),o.error=(r,...s)=>console.error(`[Pixi\u2019VN] ${r}`,...s),o.info=(r,...s)=>console.info(`[Pixi\u2019VN] ${r}`,...s)))(i||={});var l=class e{static init(t){t.navigate&&(e._navigate=t.navigate),e._getStepCounter=t.getStepCounter,e._setStepCounter=t.setStepCounter,e._getCurrentGameStepState=t.getCurrentGameStepState,e._restoreGameStepState=t.restoreGameStepState,e._getOpenedLabels=t.getOpenedLabels,e._processNavigationRequests=t.processNavigationRequests,e._getVariable=t.getVariable,e._setVariable=t.setVariable,e._removeVariable=t.removeVariable,e._getFlag=t.getFlag,e._setFlag=t.setFlag,t.onLabelClosing&&(e._onLabelClosing=t.onLabelClosing),e._addHistoryItem=t.addHistoryItem,e._getCharacter=t.getCharacter,e._animate=t.animate;}static _navigate=()=>{i.warn("Navigate function not initialized. You should add the navigate function in the Game.init() method.");};static get navigate(){return e._navigate}static set navigate(t){e._navigate=t;}static _getStepCounter=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static _setStepCounter=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get stepCounter(){return e._getStepCounter()}static set stepCounter(t){e._setStepCounter(t);}static _getCurrentGameStepState=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get currentGameStepState(){return e._getCurrentGameStepState()}static _restoreGameStepState=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get restoreGameStepState(){return e._restoreGameStepState}static _getOpenedLabels=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get openedLabels(){return e._getOpenedLabels()}static _onPreContinueHandlers=[];static addOnPreContinue(t){e._onPreContinueHandlers.push(t);}static removeOnPreContinue(t){e._onPreContinueHandlers=e._onPreContinueHandlers.filter(n=>n!==t);}static clearOnPreContinueHandlers(){e._onPreContinueHandlers=[];}static async runOnPreContinue(){let t=e._onPreContinueHandlers.slice();await Promise.all(t.map(n=>n()));}static get onPreContinue(){return e.runOnPreContinue}static navigationRequestsCount=0;static processNavigationLock=Promise.resolve();static get continueRequestsCount(){return e.navigationRequestsCount}static increaseContinueRequest(t=1){e.navigationRequestsCount+=t;}static get backRequestsCount(){return -1*e.navigationRequestsCount}static increaseBackRequest(t=1){e.navigationRequestsCount-=t;}static _processNavigationRequests=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static async processNavigationRequests(t){let n=e._processNavigationRequests(e.navigationRequestsCount,t);return e.navigationRequestsCount=n.newValue,await n.result}static _getVariable=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get getVariable(){return e._getVariable}static _setVariable=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get setVariable(){return e._setVariable}static _removeVariable=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get removeVariable(){return e._removeVariable}static _getFlag=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get getFlag(){return e._getFlag}static _setFlag=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get setFlag(){return e._setFlag}static _onLabelClosing=()=>{};static get onLabelClosing(){return e._onLabelClosing}static _addHistoryItem=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get addHistoryItem(){return e._addHistoryItem}static runningStepsCount=0;static _getCharacter=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented.")};static get getCharacter(){return e._getCharacter}static onEnd;static _onErrorHandlers=[];static addOnError(t){return e._onErrorHandlers.push(t),()=>e.removeOnError(t)}static removeOnError(t){e._onErrorHandlers=e._onErrorHandlers.filter(n=>n!==t);}static clearOnErrorHandlers(){e._onErrorHandlers.length=0;}static async runOnError(t,n){for(let m of e._onErrorHandlers.slice())try{await m(t,n);}catch(o){i.error("Error in onError handler",o);}}static _animate=()=>{throw i.error("Method not implemented, you should initialize the Game: Game.init()"),new a("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get animate(){return e._animate}};exports.GameUnifier=l;exports.PixiError=a;
package/dist/core.d.cts CHANGED
@@ -37,7 +37,7 @@ declare class GameUnifier {
37
37
  *
38
38
  * If your game engine does not have a history of steps, you can return an empty object.
39
39
  */
40
- getCurrentGameStepState: () => GameStepState;
40
+ getCurrentGameStepState: () => GameStepState | Promise<GameStepState>;
41
41
  /**
42
42
  * This function restores the game step state.
43
43
  *
@@ -109,7 +109,7 @@ declare class GameUnifier {
109
109
  * If true, the step will not be added to the history if the current step is the same as the last step.
110
110
  */
111
111
  ignoreSameStep?: boolean;
112
- }): void;
112
+ }): void | Promise<void>;
113
113
  /**
114
114
  * This function returns the character by its id.
115
115
  * @param id The id of the character.
@@ -152,7 +152,7 @@ declare class GameUnifier {
152
152
  * Returns the current state of the game step.
153
153
  * @throws {PixiError} when `Game.init()` has not been called yet.
154
154
  */
155
- static get currentGameStepState(): GameStepState;
155
+ static get currentGameStepState(): GameStepState | Promise<GameStepState>;
156
156
  private static _restoreGameStepState;
157
157
  /**
158
158
  * Restores the game step state.
@@ -279,7 +279,7 @@ declare class GameUnifier {
279
279
  * If true, the step will not be added to the history if the current step is the same as the last step.
280
280
  */
281
281
  ignoreSameStep?: boolean;
282
- }) => void;
282
+ }) => void | Promise<void>;
283
283
  /**
284
284
  * Count of currently executing steps.
285
285
  * If a step triggers a narration.continue(), this number is greater than 1.
package/dist/core.d.ts CHANGED
@@ -37,7 +37,7 @@ declare class GameUnifier {
37
37
  *
38
38
  * If your game engine does not have a history of steps, you can return an empty object.
39
39
  */
40
- getCurrentGameStepState: () => GameStepState;
40
+ getCurrentGameStepState: () => GameStepState | Promise<GameStepState>;
41
41
  /**
42
42
  * This function restores the game step state.
43
43
  *
@@ -109,7 +109,7 @@ declare class GameUnifier {
109
109
  * If true, the step will not be added to the history if the current step is the same as the last step.
110
110
  */
111
111
  ignoreSameStep?: boolean;
112
- }): void;
112
+ }): void | Promise<void>;
113
113
  /**
114
114
  * This function returns the character by its id.
115
115
  * @param id The id of the character.
@@ -152,7 +152,7 @@ declare class GameUnifier {
152
152
  * Returns the current state of the game step.
153
153
  * @throws {PixiError} when `Game.init()` has not been called yet.
154
154
  */
155
- static get currentGameStepState(): GameStepState;
155
+ static get currentGameStepState(): GameStepState | Promise<GameStepState>;
156
156
  private static _restoreGameStepState;
157
157
  /**
158
158
  * Restores the game step state.
@@ -279,7 +279,7 @@ declare class GameUnifier {
279
279
  * If true, the step will not be added to the history if the current step is the same as the last step.
280
280
  */
281
281
  ignoreSameStep?: boolean;
282
- }) => void;
282
+ }) => void | Promise<void>;
283
283
  /**
284
284
  * Count of currently executing steps.
285
285
  * If a step triggers a narration.continue(), this number is greater than 1.
package/dist/core.mjs CHANGED
@@ -1 +1 @@
1
- var a;(o=>(o.log=(r,...s)=>console.log(`[Pixi\u2019VN] ${r}`,...s),o.warn=(r,...s)=>console.warn(`[Pixi\u2019VN] ${r}`,...s),o.error=(r,...s)=>console.error(`[Pixi\u2019VN] ${r}`,...s),o.info=(r,...s)=>console.info(`[Pixi\u2019VN] ${r}`,...s)))(a||={});var n=class extends Error{code;constructor(t,i,m,o,r){super(`[Pixi\u2019VN] ${i}`),this.code=t,m==="canvas"&&(this.canvasElementInfo=o,this.parent=r);}canvasElementInfo;parent};var l=class e{static init(t){t.navigate&&(e._navigate=t.navigate),e._getStepCounter=t.getStepCounter,e._setStepCounter=t.setStepCounter,e._getCurrentGameStepState=t.getCurrentGameStepState,e._restoreGameStepState=t.restoreGameStepState,e._getOpenedLabels=t.getOpenedLabels,e._processNavigationRequests=t.processNavigationRequests,e._getVariable=t.getVariable,e._setVariable=t.setVariable,e._removeVariable=t.removeVariable,e._getFlag=t.getFlag,e._setFlag=t.setFlag,t.onLabelClosing&&(e._onLabelClosing=t.onLabelClosing),e._addHistoryItem=t.addHistoryItem,e._getCharacter=t.getCharacter,e._animate=t.animate;}static _navigate=()=>{a.warn("Navigate function not initialized. You should add the navigate function in the Game.init() method.");};static get navigate(){return e._navigate}static set navigate(t){e._navigate=t;}static _getStepCounter=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static _setStepCounter=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get stepCounter(){return e._getStepCounter()}static set stepCounter(t){e._setStepCounter(t);}static _getCurrentGameStepState=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get currentGameStepState(){return e._getCurrentGameStepState()}static _restoreGameStepState=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get restoreGameStepState(){return e._restoreGameStepState}static _getOpenedLabels=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get openedLabels(){return e._getOpenedLabels()}static _onPreContinueHandlers=[];static addOnPreContinue(t){e._onPreContinueHandlers.push(t);}static removeOnPreContinue(t){e._onPreContinueHandlers=e._onPreContinueHandlers.filter(i=>i!==t);}static clearOnPreContinueHandlers(){e._onPreContinueHandlers=[];}static async runOnPreContinue(){let t=e._onPreContinueHandlers.slice();await Promise.all(t.map(i=>i()));}static get onPreContinue(){return e.runOnPreContinue}static navigationRequestsCount=0;static processNavigationLock=Promise.resolve();static get continueRequestsCount(){return e.navigationRequestsCount}static increaseContinueRequest(t=1){e.navigationRequestsCount+=t;}static get backRequestsCount(){return -1*e.navigationRequestsCount}static increaseBackRequest(t=1){e.navigationRequestsCount-=t;}static _processNavigationRequests=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static async processNavigationRequests(t){let i=e._processNavigationRequests(e.navigationRequestsCount,t);return e.navigationRequestsCount=i.newValue,await i.result}static _getVariable=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get getVariable(){return e._getVariable}static _setVariable=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get setVariable(){return e._setVariable}static _removeVariable=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get removeVariable(){return e._removeVariable}static _getFlag=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get getFlag(){return e._getFlag}static _setFlag=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get setFlag(){return e._setFlag}static _onLabelClosing=()=>{};static get onLabelClosing(){return e._onLabelClosing}static _addHistoryItem=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get addHistoryItem(){return e._addHistoryItem}static runningStepsCount=0;static _getCharacter=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented.")};static get getCharacter(){return e._getCharacter}static onEnd;static _onErrorHandlers=[];static addOnError(t){return e._onErrorHandlers.push(t),()=>e.removeOnError(t)}static removeOnError(t){e._onErrorHandlers=e._onErrorHandlers.filter(i=>i!==t);}static clearOnErrorHandlers(){e._onErrorHandlers.length=0;}static async runOnError(t,i){for(let m of e._onErrorHandlers.slice())try{await m(t,i);}catch(o){a.error("Error in onError handler",o);}}static _animate=()=>{throw a.error("Method not implemented, you should initialize the Game: Game.init()"),new n("not_implemented","Method not implemented, you should initialize the Game: Game.init()")};static get animate(){return e._animate}};export{l as GameUnifier,n as PixiError};
1
+ export{c as GameUnifier,a as PixiError}from'./chunk-AWU37VV6.mjs';
package/dist/history.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var core=require('@drincs/pixi-vn/core');var Qt=Object.defineProperty;var Wt=c=>{throw TypeError(c)};var Zt=(c,t,i)=>t in c?Qt(c,t,{enumerable:true,configurable:true,writable:true,value:i}):c[t]=i;var M=(c,t,i)=>Zt(c,typeof t!="symbol"?t+"":t,i),zt=(c,t,i)=>t.has(c)||Wt("Cannot "+i);var e=(c,t,i)=>(zt(c,t,"read from private field"),i?i.call(c):t.get(c)),S=(c,t,i)=>t.has(c)?Wt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(c):t.set(c,i),p=(c,t,i,s)=>(zt(c,t,"write to private field"),t.set(c,i),i),f=(c,t,i)=>(zt(c,t,"access private method"),i);var Ot=(c,t,i,s)=>({set _(r){p(c,t,r);},get _(){return e(c,t,s)}});var te=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Kt=new Set,Lt=typeof process=="object"&&process?process:{},Pt=(c,t,i,s)=>{typeof Lt.emitWarning=="function"?Lt.emitWarning(c,t,i,s):console.error(`[${i}] ${t}: ${c}`);},Dt=globalThis.AbortController,jt=globalThis.AbortSignal;if(typeof Dt>"u"){jt=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},Dt=class{constructor(){t();}signal=new jt;abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=true;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i);}}};let c=Lt.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{c&&(c=false,Pt("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",t));};}var ee=c=>!Kt.has(c);var st=c=>c&&c===Math.floor(c)&&c>0&&isFinite(c),Bt=c=>st(c)?c<=Math.pow(2,8)?Uint8Array:c<=Math.pow(2,16)?Uint16Array:c<=Math.pow(2,32)?Uint32Array:c<=Number.MAX_SAFE_INTEGER?Tt:null:null,Tt=class extends Array{constructor(c){super(c),this.fill(0);}},et,yt,ie=(et=class{heap;length;static create(t){let i=Bt(t);if(!i)return [];p(et,yt,true);let s=new et(t,i);return p(et,yt,false),s}constructor(t,i){if(!e(et,yt))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new i(t),this.length=0;}push(t){this.heap[this.length++]=t;}pop(){return this.heap[--this.length]}},yt=new WeakMap,S(et,yt,false),et),Vt,Ut,B,j,$,lt,q,gt,mt,J,C,Y,E,x,g,G,V,k,F,X,D,Q,Z,U,K,tt,at,I,bt,l,Gt,ct,it,Ht,P,qt,ft,St,At,rt,ot,It,Ct,Ft,_,Rt,xt,nt,Nt,vt,$t=(vt=class{constructor(t){S(this,l);S(this,B);S(this,j);S(this,$);S(this,lt);S(this,q);S(this,gt);S(this,mt);S(this,J);M(this,"ttl");M(this,"ttlResolution");M(this,"ttlAutopurge");M(this,"updateAgeOnGet");M(this,"updateAgeOnHas");M(this,"allowStale");M(this,"noDisposeOnSet");M(this,"noUpdateTTL");M(this,"maxEntrySize");M(this,"sizeCalculation");M(this,"noDeleteOnFetchRejection");M(this,"noDeleteOnStaleGet");M(this,"allowStaleOnFetchAbort");M(this,"allowStaleOnFetchRejection");M(this,"ignoreFetchAbort");S(this,C);S(this,Y);S(this,E);S(this,x);S(this,g);S(this,G);S(this,V);S(this,k);S(this,F);S(this,X);S(this,D);S(this,Q);S(this,Z);S(this,U);S(this,K);S(this,tt);S(this,at);S(this,I);S(this,bt);S(this,ct,()=>{});S(this,it,()=>{});S(this,Ht,()=>{});S(this,P,()=>false);S(this,ft,t=>{});S(this,St,(t,i,s)=>{});S(this,At,(t,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});M(this,Vt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:n,updateAgeOnHas:a,allowStale:h,dispose:d,onInsert:y,disposeAfter:m,noDisposeOnSet:v,noUpdateTTL:T,maxSize:W=0,maxEntrySize:H=0,sizeCalculation:w,fetchMethod:b,memoMethod:z,noDeleteOnFetchRejection:R,noDeleteOnStaleGet:L,allowStaleOnFetchRejection:A,allowStaleOnFetchAbort:_t,ignoreFetchAbort:ut,perf:pt}=t;if(pt!==void 0&&typeof pt?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(p(this,J,pt??te),i!==0&&!st(i))throw new TypeError("max option must be a nonnegative integer");let dt=i?Bt(i):Array;if(!dt)throw new Error("invalid max value: "+i);if(p(this,B,i),p(this,j,W),this.maxEntrySize=H||e(this,j),this.sizeCalculation=w,this.sizeCalculation){if(!e(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(z!==void 0&&typeof z!="function")throw new TypeError("memoMethod must be a function if defined");if(p(this,mt,z),b!==void 0&&typeof b!="function")throw new TypeError("fetchMethod must be a function if specified");if(p(this,gt,b),p(this,at,!!b),p(this,E,new Map),p(this,x,new Array(i).fill(void 0)),p(this,g,new Array(i).fill(void 0)),p(this,G,new dt(i)),p(this,V,new dt(i)),p(this,k,0),p(this,F,0),p(this,X,ie.create(i)),p(this,C,0),p(this,Y,0),typeof d=="function"&&p(this,$,d),typeof y=="function"&&p(this,lt,y),typeof m=="function"?(p(this,q,m),p(this,D,[])):(p(this,q,void 0),p(this,D,void 0)),p(this,tt,!!e(this,$)),p(this,bt,!!e(this,lt)),p(this,I,!!e(this,q)),this.noDisposeOnSet=!!v,this.noUpdateTTL=!!T,this.noDeleteOnFetchRejection=!!R,this.allowStaleOnFetchRejection=!!A,this.allowStaleOnFetchAbort=!!_t,this.ignoreFetchAbort=!!ut,this.maxEntrySize!==0){if(e(this,j)!==0&&!st(e(this,j)))throw new TypeError("maxSize must be a positive integer if specified");if(!st(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");f(this,l,qt).call(this);}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!L,this.updateAgeOnGet=!!n,this.updateAgeOnHas=!!a,this.ttlResolution=st(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!st(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,l,Gt).call(this);}if(e(this,B)===0&&this.ttl===0&&e(this,j)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!e(this,B)&&!e(this,j)){let kt="LRU_CACHE_UNBOUNDED";ee(kt)&&(Kt.add(kt),Pt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",kt,vt));}}get perf(){return e(this,J)}static unsafeExposeInternals(t){return {starts:e(t,Z),ttls:e(t,U),autopurgeTimers:e(t,K),sizes:e(t,Q),keyMap:e(t,E),keyList:e(t,x),valList:e(t,g),next:e(t,G),prev:e(t,V),get head(){return e(t,k)},get tail(){return e(t,F)},free:e(t,X),isBackgroundFetch:i=>{var s;return f(s=t,l,_).call(s,i)},backgroundFetch:(i,s,r,o)=>{var n;return f(n=t,l,Ft).call(n,i,s,r,o)},moveToTail:i=>{var s;return f(s=t,l,xt).call(s,i)},indexes:i=>{var s;return f(s=t,l,rt).call(s,i)},rindexes:i=>{var s;return f(s=t,l,ot).call(s,i)},isStale:i=>{var s;return e(s=t,P).call(s,i)}}}get max(){return e(this,B)}get maxSize(){return e(this,j)}get calculatedSize(){return e(this,Y)}get size(){return e(this,C)}get fetchMethod(){return e(this,gt)}get memoMethod(){return e(this,mt)}get dispose(){return e(this,$)}get onInsert(){return e(this,lt)}get disposeAfter(){return e(this,q)}getRemainingTTL(t){return e(this,E).has(t)?1/0:0}*entries(){for(let t of f(this,l,rt).call(this))e(this,g)[t]!==void 0&&e(this,x)[t]!==void 0&&!f(this,l,_).call(this,e(this,g)[t])&&(yield [e(this,x)[t],e(this,g)[t]]);}*rentries(){for(let t of f(this,l,ot).call(this))e(this,g)[t]!==void 0&&e(this,x)[t]!==void 0&&!f(this,l,_).call(this,e(this,g)[t])&&(yield [e(this,x)[t],e(this,g)[t]]);}*keys(){for(let t of f(this,l,rt).call(this)){let i=e(this,x)[t];i!==void 0&&!f(this,l,_).call(this,e(this,g)[t])&&(yield i);}}*rkeys(){for(let t of f(this,l,ot).call(this)){let i=e(this,x)[t];i!==void 0&&!f(this,l,_).call(this,e(this,g)[t])&&(yield i);}}*values(){for(let t of f(this,l,rt).call(this))e(this,g)[t]!==void 0&&!f(this,l,_).call(this,e(this,g)[t])&&(yield e(this,g)[t]);}*rvalues(){for(let t of f(this,l,ot).call(this))e(this,g)[t]!==void 0&&!f(this,l,_).call(this,e(this,g)[t])&&(yield e(this,g)[t]);}[(Ut=Symbol.iterator,Vt=Symbol.toStringTag,Ut)](){return this.entries()}find(t,i={}){for(let s of f(this,l,rt).call(this)){let r=e(this,g)[s],o=f(this,l,_).call(this,r)?r.__staleWhileFetching:r;if(o!==void 0&&t(o,e(this,x)[s],this))return this.get(e(this,x)[s],i)}}forEach(t,i=this){for(let s of f(this,l,rt).call(this)){let r=e(this,g)[s],o=f(this,l,_).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(i,o,e(this,x)[s],this);}}rforEach(t,i=this){for(let s of f(this,l,ot).call(this)){let r=e(this,g)[s],o=f(this,l,_).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(i,o,e(this,x)[s],this);}}purgeStale(){let t=false;for(let i of f(this,l,ot).call(this,{allowStale:true}))e(this,P).call(this,i)&&(f(this,l,nt).call(this,e(this,x)[i],"expire"),t=true);return t}info(t){let i=e(this,E).get(t);if(i===void 0)return;let s=e(this,g)[i],r=f(this,l,_).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(e(this,U)&&e(this,Z)){let n=e(this,U)[i],a=e(this,Z)[i];if(n&&a){let h=n-(e(this,J).now()-a);o.ttl=h,o.start=Date.now();}}return e(this,Q)&&(o.size=e(this,Q)[i]),o}dump(){let t=[];for(let i of f(this,l,rt).call(this,{allowStale:true})){let s=e(this,x)[i],r=e(this,g)[i],o=f(this,l,_).call(this,r)?r.__staleWhileFetching:r;if(o===void 0||s===void 0)continue;let n={value:o};if(e(this,U)&&e(this,Z)){n.ttl=e(this,U)[i];let a=e(this,J).now()-e(this,Z)[i];n.start=Math.floor(Date.now()-a);}e(this,Q)&&(n.size=e(this,Q)[i]),t.unshift([s,n]);}return t}load(t){this.clear();for(let[i,s]of t){if(s.start){let r=Date.now()-s.start;s.start=e(this,J).now()-r;}this.set(i,s.value,s);}}set(t,i,s={}){var v,T,W,H;if(i===void 0)return this.delete(t),this;let{ttl:r=this.ttl,start:o,noDisposeOnSet:n=this.noDisposeOnSet,sizeCalculation:a=this.sizeCalculation,status:h}=s,{noUpdateTTL:d=this.noUpdateTTL}=s,y=e(this,At).call(this,t,i,s.size||0,a);if(this.maxEntrySize&&y>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),f(this,l,nt).call(this,t,"set"),this;let m=e(this,C)===0?void 0:e(this,E).get(t);if(m===void 0)m=e(this,C)===0?e(this,F):e(this,X).length!==0?e(this,X).pop():e(this,C)===e(this,B)?f(this,l,Ct).call(this,false):e(this,C),e(this,x)[m]=t,e(this,g)[m]=i,e(this,E).set(t,m),e(this,G)[e(this,F)]=m,e(this,V)[m]=e(this,F),p(this,F,m),Ot(this,C)._++,e(this,St).call(this,m,y,h),h&&(h.set="add"),d=false,e(this,bt)&&((v=e(this,lt))==null||v.call(this,i,t,"add"));else {f(this,l,xt).call(this,m);let w=e(this,g)[m];if(i!==w){if(e(this,at)&&f(this,l,_).call(this,w)){w.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:b}=w;b!==void 0&&!n&&(e(this,tt)&&((T=e(this,$))==null||T.call(this,b,t,"set")),e(this,I)&&e(this,D)?.push([b,t,"set"]));}else n||(e(this,tt)&&((W=e(this,$))==null||W.call(this,w,t,"set")),e(this,I)&&e(this,D)?.push([w,t,"set"]));if(e(this,ft).call(this,m),e(this,St).call(this,m,y,h),e(this,g)[m]=i,h){h.set="replace";let b=w&&f(this,l,_).call(this,w)?w.__staleWhileFetching:w;b!==void 0&&(h.oldValue=b);}}else h&&(h.set="update");e(this,bt)&&this.onInsert?.(i,t,i===w?"update":"replace");}if(r!==0&&!e(this,U)&&f(this,l,Gt).call(this),e(this,U)&&(d||e(this,Ht).call(this,m,r,o),h&&e(this,it).call(this,h,m)),!n&&e(this,I)&&e(this,D)){let w=e(this,D),b;for(;b=w?.shift();)(H=e(this,q))==null||H.call(this,...b);}return this}pop(){var t;try{for(;e(this,C);){let i=e(this,g)[e(this,k)];if(f(this,l,Ct).call(this,!0),f(this,l,_).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(e(this,I)&&e(this,D)){let i=e(this,D),s;for(;s=i?.shift();)(t=e(this,q))==null||t.call(this,...s);}}}has(t,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=i,o=e(this,E).get(t);if(o!==void 0){let n=e(this,g)[o];if(f(this,l,_).call(this,n)&&n.__staleWhileFetching===void 0)return false;if(e(this,P).call(this,o))r&&(r.has="stale",e(this,it).call(this,r,o));else return s&&e(this,ct).call(this,o),r&&(r.has="hit",e(this,it).call(this,r,o)),true}else r&&(r.has="miss");return false}peek(t,i={}){let{allowStale:s=this.allowStale}=i,r=e(this,E).get(t);if(r===void 0||!s&&e(this,P).call(this,r))return;let o=e(this,g)[r];return f(this,l,_).call(this,o)?o.__staleWhileFetching:o}async fetch(t,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:a=this.noDisposeOnSet,size:h=0,sizeCalculation:d=this.sizeCalculation,noUpdateTTL:y=this.noUpdateTTL,noDeleteOnFetchRejection:m=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:v=this.allowStaleOnFetchRejection,ignoreFetchAbort:T=this.ignoreFetchAbort,allowStaleOnFetchAbort:W=this.allowStaleOnFetchAbort,context:H,forceRefresh:w=false,status:b,signal:z}=i;if(!e(this,at))return b&&(b.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:b});let R={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:n,noDisposeOnSet:a,size:h,sizeCalculation:d,noUpdateTTL:y,noDeleteOnFetchRejection:m,allowStaleOnFetchRejection:v,allowStaleOnFetchAbort:W,ignoreFetchAbort:T,status:b,signal:z},L=e(this,E).get(t);if(L===void 0){b&&(b.fetch="miss");let A=f(this,l,Ft).call(this,t,L,R,H);return A.__returned=A}else {let A=e(this,g)[L];if(f(this,l,_).call(this,A)){let dt=s&&A.__staleWhileFetching!==void 0;return b&&(b.fetch="inflight",dt&&(b.returnedStale=true)),dt?A.__staleWhileFetching:A.__returned=A}let _t=e(this,P).call(this,L);if(!w&&!_t)return b&&(b.fetch="hit"),f(this,l,xt).call(this,L),r&&e(this,ct).call(this,L),b&&e(this,it).call(this,b,L),A;let ut=f(this,l,Ft).call(this,t,L,R,H),pt=ut.__staleWhileFetching!==void 0&&s;return b&&(b.fetch=_t?"stale":"refresh",pt&&_t&&(b.returnedStale=true)),pt?ut.__staleWhileFetching:ut.__returned=ut}}async forceFetch(t,i={}){let s=await this.fetch(t,i);if(s===void 0)throw new Error("fetch() returned undefined");return s}memo(t,i={}){let s=e(this,mt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:o,...n}=i,a=this.get(t,n);if(!o&&a!==void 0)return a;let h=s(t,a,{options:n,context:r});return this.set(t,h,n),h}get(t,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:n}=i,a=e(this,E).get(t);if(a!==void 0){let h=e(this,g)[a],d=f(this,l,_).call(this,h);return n&&e(this,it).call(this,n,a),e(this,P).call(this,a)?(n&&(n.get="stale"),d?(n&&s&&h.__staleWhileFetching!==void 0&&(n.returnedStale=true),s?h.__staleWhileFetching:void 0):(o||f(this,l,nt).call(this,t,"expire"),n&&s&&(n.returnedStale=true),s?h:void 0)):(n&&(n.get="hit"),d?h.__staleWhileFetching:(f(this,l,xt).call(this,a),r&&e(this,ct).call(this,a),h))}else n&&(n.get="miss");}delete(t){return f(this,l,nt).call(this,t,"delete")}clear(){return f(this,l,Nt).call(this,"delete")}},B=new WeakMap,j=new WeakMap,$=new WeakMap,lt=new WeakMap,q=new WeakMap,gt=new WeakMap,mt=new WeakMap,J=new WeakMap,C=new WeakMap,Y=new WeakMap,E=new WeakMap,x=new WeakMap,g=new WeakMap,G=new WeakMap,V=new WeakMap,k=new WeakMap,F=new WeakMap,X=new WeakMap,D=new WeakMap,Q=new WeakMap,Z=new WeakMap,U=new WeakMap,K=new WeakMap,tt=new WeakMap,at=new WeakMap,I=new WeakMap,bt=new WeakMap,l=new WeakSet,Gt=function(){let t=new Tt(e(this,B)),i=new Tt(e(this,B));p(this,U,t),p(this,Z,i);let s=this.ttlAutopurge?new Array(e(this,B)):void 0;p(this,K,s),p(this,Ht,(a,h,d=e(this,J).now())=>{i[a]=h!==0?d:0,t[a]=h,r(a,h);}),p(this,ct,a=>{i[a]=t[a]!==0?e(this,J).now():0,r(a,t[a]);});let r=this.ttlAutopurge?(a,h)=>{if(s?.[a]&&(clearTimeout(s[a]),s[a]=void 0),h&&h!==0&&s){let d=setTimeout(()=>{e(this,P).call(this,a)&&f(this,l,nt).call(this,e(this,x)[a],"expire");},h+1);d.unref&&d.unref(),s[a]=d;}}:()=>{};p(this,it,(a,h)=>{if(t[h]){let d=t[h],y=i[h];if(!d||!y)return;a.ttl=d,a.start=y,a.now=o||n();let m=a.now-y;a.remainingTTL=d-m;}});let o=0,n=()=>{let a=e(this,J).now();if(this.ttlResolution>0){o=a;let h=setTimeout(()=>o=0,this.ttlResolution);h.unref&&h.unref();}return a};this.getRemainingTTL=a=>{let h=e(this,E).get(a);if(h===void 0)return 0;let d=t[h],y=i[h];if(!d||!y)return 1/0;let m=(o||n())-y;return d-m},p(this,P,a=>{let h=i[a],d=t[a];return !!d&&!!h&&(o||n())-h>d});},ct=new WeakMap,it=new WeakMap,Ht=new WeakMap,P=new WeakMap,qt=function(){let t=new Tt(e(this,B));p(this,Y,0),p(this,Q,t),p(this,ft,i=>{p(this,Y,e(this,Y)-t[i]),t[i]=0;}),p(this,At,(i,s,r,o)=>{if(f(this,l,_).call(this,s))return 0;if(!st(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,i),!st(r))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 r}),p(this,St,(i,s,r)=>{if(t[i]=s,e(this,j)){let o=e(this,j)-t[i];for(;e(this,Y)>o;)f(this,l,Ct).call(this,true);}p(this,Y,e(this,Y)+t[i]),r&&(r.entrySize=s,r.totalCalculatedSize=e(this,Y));});},ft=new WeakMap,St=new WeakMap,At=new WeakMap,rt=function*({allowStale:t=this.allowStale}={}){if(e(this,C))for(let i=e(this,F);!(!f(this,l,It).call(this,i)||((t||!e(this,P).call(this,i))&&(yield i),i===e(this,k)));)i=e(this,V)[i];},ot=function*({allowStale:t=this.allowStale}={}){if(e(this,C))for(let i=e(this,k);!(!f(this,l,It).call(this,i)||((t||!e(this,P).call(this,i))&&(yield i),i===e(this,F)));)i=e(this,G)[i];},It=function(t){return t!==void 0&&e(this,E).get(e(this,x)[t])===t},Ct=function(t){var o;let i=e(this,k),s=e(this,x)[i],r=e(this,g)[i];return e(this,at)&&f(this,l,_).call(this,r)?r.__abortController.abort(new Error("evicted")):(e(this,tt)||e(this,I))&&(e(this,tt)&&((o=e(this,$))==null||o.call(this,r,s,"evict")),e(this,I)&&e(this,D)?.push([r,s,"evict"])),e(this,ft).call(this,i),e(this,K)?.[i]&&(clearTimeout(e(this,K)[i]),e(this,K)[i]=void 0),t&&(e(this,x)[i]=void 0,e(this,g)[i]=void 0,e(this,X).push(i)),e(this,C)===1?(p(this,k,p(this,F,0)),e(this,X).length=0):p(this,k,e(this,G)[i]),e(this,E).delete(s),Ot(this,C)._--,i},Ft=function(t,i,s,r){let o=i===void 0?void 0:e(this,g)[i];if(f(this,l,_).call(this,o))return o;let n=new Dt,{signal:a}=s;a?.addEventListener("abort",()=>n.abort(a.reason),{signal:n.signal});let h={signal:n.signal,options:s,context:r},d=(H,w=false)=>{let{aborted:b}=n.signal,z=s.ignoreFetchAbort&&H!==void 0,R=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&H!==void 0);if(s.status&&(b&&!w?(s.status.fetchAborted=true,s.status.fetchError=n.signal.reason,z&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),b&&!z&&!w)return m(n.signal.reason,R);let L=T,A=e(this,g)[i];return (A===T||z&&w&&A===void 0)&&(H===void 0?L.__staleWhileFetching!==void 0?e(this,g)[i]=L.__staleWhileFetching:f(this,l,nt).call(this,t,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(t,H,h.options))),H},y=H=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=H),m(H,false)),m=(H,w)=>{let{aborted:b}=n.signal,z=b&&s.allowStaleOnFetchAbort,R=z||s.allowStaleOnFetchRejection,L=R||s.noDeleteOnFetchRejection,A=T;if(e(this,g)[i]===T&&(!L||!w&&A.__staleWhileFetching===void 0?f(this,l,nt).call(this,t,"fetch"):z||(e(this,g)[i]=A.__staleWhileFetching)),R)return s.status&&A.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),A.__staleWhileFetching;if(A.__returned===A)throw H},v=(H,w)=>{var z;let b=(z=e(this,gt))==null?void 0:z.call(this,t,o,h);b&&b instanceof Promise&&b.then(R=>H(R===void 0?void 0:R),w),n.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(H(void 0),s.allowStaleOnFetchAbort&&(H=R=>d(R,true)));});};s.status&&(s.status.fetchDispatched=true);let T=new Promise(v).then(d,y),W=Object.assign(T,{__abortController:n,__staleWhileFetching:o,__returned:void 0});return i===void 0?(this.set(t,W,{...h.options,status:void 0}),i=e(this,E).get(t)):e(this,g)[i]=W,W},_=function(t){if(!e(this,at))return false;let i=t;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Dt},Rt=function(t,i){e(this,V)[i]=t,e(this,G)[t]=i;},xt=function(t){t!==e(this,F)&&(t===e(this,k)?p(this,k,e(this,G)[t]):f(this,l,Rt).call(this,e(this,V)[t],e(this,G)[t]),f(this,l,Rt).call(this,e(this,F),t),p(this,F,t));},nt=function(t,i){var r,o;let s=false;if(e(this,C)!==0){let n=e(this,E).get(t);if(n!==void 0)if(e(this,K)?.[n]&&(clearTimeout(e(this,K)?.[n]),e(this,K)[n]=void 0),s=true,e(this,C)===1)f(this,l,Nt).call(this,i);else {e(this,ft).call(this,n);let a=e(this,g)[n];if(f(this,l,_).call(this,a)?a.__abortController.abort(new Error("deleted")):(e(this,tt)||e(this,I))&&(e(this,tt)&&((r=e(this,$))==null||r.call(this,a,t,i)),e(this,I)&&e(this,D)?.push([a,t,i])),e(this,E).delete(t),e(this,x)[n]=void 0,e(this,g)[n]=void 0,n===e(this,F))p(this,F,e(this,V)[n]);else if(n===e(this,k))p(this,k,e(this,G)[n]);else {let h=e(this,V)[n];e(this,G)[h]=e(this,G)[n];let d=e(this,G)[n];e(this,V)[d]=e(this,V)[n];}Ot(this,C)._--,e(this,X).push(n);}}if(e(this,I)&&e(this,D)?.length){let n=e(this,D),a;for(;a=n?.shift();)(o=e(this,q))==null||o.call(this,...a);}return s},Nt=function(t){var i,s;for(let r of f(this,l,ot).call(this,{allowStale:true})){let o=e(this,g)[r];if(f(this,l,_).call(this,o))o.__abortController.abort(new Error("deleted"));else {let n=e(this,x)[r];e(this,tt)&&((i=e(this,$))==null||i.call(this,o,n,t)),e(this,I)&&e(this,D)?.push([o,n,t]);}}if(e(this,E).clear(),e(this,g).fill(void 0),e(this,x).fill(void 0),e(this,U)&&e(this,Z)){e(this,U).fill(0),e(this,Z).fill(0);for(let r of e(this,K)??[])r!==void 0&&clearTimeout(r);e(this,K)?.fill(void 0);}if(e(this,Q)&&e(this,Q).fill(0),p(this,k,0),p(this,F,0),e(this,X).length=0,p(this,Y,0),p(this,C,0),e(this,I)&&e(this,D)){let r=e(this,D),o;for(;o=r?.shift();)(s=e(this,q))==null||s.call(this,...o);}},vt);var ht=class{cache;map=new Map;constructor(t){this.cache=new $t({max:t.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(t){let i=this.map.delete(t);return i&&this.cache.delete(t),i}get forEach(){return this.map.forEach}get(t){let i=this.cache.get(t);return i||this.map.get(t)}has(t){return this.map.has(t)}set(t,i){return this.map.set(t,i),this.cache.set(t,i),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var u=class c{static _diffHistory=new ht({cacheSize:5});static _stepsInfoHistory=new ht({cacheSize:5});static _narrationHistory=new ht({cacheSize:50});static stepLimitSaved=20;static goBackMode="step";static _originalStepData=void 0;static get originalStepData(){return c._originalStepData?c._originalStepData:{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{}},labelIndex:-1,openedLabels:[]}}static set originalStepData(t){c._originalStepData=t;}};var O;(r=>(r.log=(o,...n)=>console.log(`[Pixi\u2019VN] ${o}`,...n),r.warn=(o,...n)=>console.warn(`[Pixi\u2019VN] ${o}`,...n),r.error=(o,...n)=>console.error(`[Pixi\u2019VN] ${o}`,...n),r.info=(o,...n)=>console.info(`[Pixi\u2019VN] ${o}`,...n)))(O||={});function wt(c){try{if(typeof c>"u")return c;let t=JSON.stringify(c);return JSON.parse(t)}catch(t){throw O.error("Error creating exportable element",c,t),new core.PixiError("not_json_serializable","Error creating exportable element")}}function Jt(c,t){let i=wt(c);return t.length>1&&"type"in t[0]&&(t=t.slice().reverse()),t.forEach(s=>{re(i,s);}),i}function re(c,t){let i=c;t.path&&t.path.length>0?t.path.forEach((s,r)=>{if(t.path&&r===t.path.length-1)switch(t.type){case "CHANGE":case "REMOVE":i[s]=t.oldValue;break;case "CREATE":Array.isArray(i)&&typeof s=="number"?i.splice(s,1):delete i[s];break}else i=i[s];}):O.warn("No path found, skipping diff",t);}var Yt=["Date","RegExp","String","Number"],Xt=Object.getOwnPropertyNames(globalThis.Temporal||{});function Mt(c,t,i={cyclesFix:true},s=[]){let r=[],o=Array.isArray(c);for(let a in c){let h=c[a],d=o?+a:a;if(!(a in t)){r.push({type:"REMOVE",path:[d],oldValue:h});continue}let y=t[a],m=typeof h=="object"&&typeof y=="object"&&Array.isArray(h)===Array.isArray(y),v=m&&h?Object.getPrototypeOf(h)?.constructor?.name:void 0;if(h&&y&&m&&!Yt.includes(v)&&!Xt.includes(v)&&(!i.cyclesFix||!s.includes(h))){i.cyclesFix&&s.push(h);let T=Mt(h,y,i,s);i.cyclesFix&&s.pop();for(let W of T)W.path.unshift(d),r.push(W);}else Object.is(h,y)||Xt.includes(v)&&String(h)===String(y)||Yt.includes(v)&&(isNaN(h)?h+""==y+"":+h==+y)||r.push({path:[d],type:"CHANGE",value:y,oldValue:h});}let n=Array.isArray(t);for(let a in t)a in c||r.push({type:"CREATE",path:[n?+a:a],value:t[a]});return r}var Et=class{get stepsInfoMap(){return u._stepsInfoHistory}get diffMap(){return u._diffHistory}get narrationMap(){return u._narrationHistory}get size(){return u._stepsInfoHistory.size}get lastKey(){if(this.size===0)return null;let t=null;for(let i of this.keys())(t===null||i>t)&&(t=i);return t}get lastDiffKey(){let t=null;for(let i of u._diffHistory.keys())(t===null||i>t)&&(t=i);return t}get goBackMode(){return u.goBackMode}set goBackMode(t){u.goBackMode=t;}keys(){return u._stepsInfoHistory.keys()}get(t){let i=u._narrationHistory.get(t);if(!(i&&Object.keys(i).length===1&&i.stepIndex!==void 0))return i}delete(t){u._stepsInfoHistory.delete(t),u._diffHistory.delete(t),u._narrationHistory.delete(t);}deleteFromKeyOnward(t){Array.from(this.keys()).filter(i=>i>=t).forEach(i=>{this.delete(i);});}previousCheckpointKey(t){let i=0;for(let s of u._diffHistory.keys())s<t&&s>i&&(i=s);return i}getOldGameState(t,i){if(t<=0||this.size===0)return i;let s=this.lastDiffKey;if(typeof s!="number")return O.warn("You can't go back, there is no step to go back"),i;let r=u._diffHistory.get(s);if(r)try{let o=Jt(i,r),n=this.previousCheckpointKey(s)+1;return core.GameUnifier.stepCounter=n,this.deleteFromKeyOnward(n),this.getOldGameState(t-1,o)}catch(o){return O.error("Error applying diff",o),i}else return O.warn("No diff found for the last step, cannot go back"),i}async back(t,i={}){let{steps:s=1}=i;if(!Number.isFinite(s)){O.warn(`[back] The parameter steps must be a valid finite number, received: ${s}`);return}if(s<=0){O.warn(`[back] The parameter steps must be greater than 0, received: ${s}`);return}if(core.GameUnifier.runningStepsCount>0){core.GameUnifier.increaseBackRequest(s);return}if(u._diffHistory.size<1){O.warn("You can't go back, there is no step to go back");return}core.GameUnifier.runningStepsCount++;try{let r=wt(this.getOldGameState(s,u.originalStepData));if(r){await core.GameUnifier.restoreGameStepState(r,core.GameUnifier.navigate);let o=core.GameUnifier.stepCounter-1,n=u._narrationHistory.get(o);if(n&&Object.keys(n).length===1&&n.stepIndex!==void 0){let a=u._stepsInfoHistory.get(o);if(a){let h=this.itemMapper({step:a});u._narrationHistory.set(a.index,h);}}}else O.error("Error going back");u.originalStepData=r;}catch(r){O.error("Error going back",r);}if(core.GameUnifier.runningStepsCount--,core.GameUnifier.runningStepsCount===0&&core.GameUnifier.backRequestsCount!==0)return await core.GameUnifier.processNavigationRequests(t)}isCheckpointStep(t,i){if(u.goBackMode==="step"||t.choices&&t.choices.length>0||t.isRequiredInput)return true;let s=t.openedLabels??[],r=i?.openedLabels??[];return s.length!==r.length?true:s.some((o,n)=>o.label!==r[n]?.label)}add(t,i={}){let s=u.originalStepData,{ignoreSameStep:r}=i,o=core.GameUnifier.currentGameStepState;if(!r&&this.isSameStep(s,o))return;let n=this.lastKey,a=typeof n=="number"?u._stepsInfoHistory.get(n):void 0,h=t.index===0||this.isCheckpointStep(t,a);(async()=>{try{let y=typeof n=="number"?u._narrationHistory.get(n):void 0;if(u._stepsInfoHistory.set(t.index,t),t.index!==0&&h){let T=Mt(s,o);T?u._diffHistory.set(t.index,T):O.warn("It was not possible to create the difference between the two steps");}let m={},v=this.itemMapper({step:t},m);if(u._narrationHistory.set(t.index,v),a&&y&&typeof n=="number"){let T=this.itemMapper({...m,step:a},{});u._narrationHistory.set(n,T);}}catch(y){O.error("Error adding history step",y);}})(),(t.index===0||h)&&(u.originalStepData=o);}itemMapper(t,i){let{step:s,choiceIndexMade:r,inputValue:o,removeDialogue:n}=t,a=s.dialogue;i&&s.isGlued&&(i.removeDialogue=true),n&&(a=void 0);let h=s.choices;if(i&&s.currentLabel&&s.choiceIndexMade!==void 0&&(i.choiceIndexMade=s.choiceIndexMade),s.inputValue&&i&&(i.inputValue=s.inputValue),a||h||o){let d=h?.map((y,m)=>{let v=false;return y.oneTime&&s.alreadyMadeChoices?.includes(m)&&(v=true),{text:y.text,type:y.type,isResponse:false,hidden:v}});if(d){if(d.every(y=>y.hidden)){let y=d.find(m=>m.hidden===false);y&&(y.hidden=false);}r!==void 0&&(d[r].isResponse=true);}return {dialogue:a?{...a,character:a.character?core.GameUnifier.getCharacter(a.character)||a.character:void 0}:void 0,playerMadeChoice:typeof r=="number",choices:d,stepIndex:s.index,inputValue:o,openedLabelsNumber:s.openedLabels?.length}}return {stepIndex:s.index}}get narrativeHistory(){let t=[];return Array.from(this.keys()).sort((s,r)=>s-r).forEach(s=>{let r=this.get(s);r&&t.push(r);}),t}get currentLabelHistory(){let t=[],i=Array.from(this.keys()).sort((h,d)=>d-h);if(i.length===0)return t;let s=i[0];if(typeof s!="number")return t;let r=u._stepsInfoHistory.get(s);if(!r)return t;let o=r.openedLabels;if(!o||!Array.isArray(o)||o.length===0)return t;let n=o[0].currentStepIndex,a=o[0].label;return i.every((h,d)=>{let y=this.get(h);if(y){if(d===0)return t.push(y),true;let m=u._stepsInfoHistory.get(h);if(!m)return true;let v=m.openedLabels;if(!v||!Array.isArray(v)||v.length===0||v[0].label!==a||v[0].currentStepIndex>n)return false;n=v[0].currentStepIndex,t.push(y);}return true}),t.reverse()}get currentPageParagraphs(){let t=[],i;return this.currentLabelHistory.forEach(s=>{t.length===0||s.openedLabelsNumber!==i?t.push([s]):t[t.length-1].push(s),i=s.openedLabelsNumber;}),t}removeNarrativeHistory(t){if(t){let i=Array.from(this.keys()).sort((s,r)=>s-r);i=i.slice(0,t),i.forEach(s=>{u._narrationHistory.delete(s),u._stepsInfoHistory.delete(s),u._diffHistory.delete(s);});}else u._stepsInfoHistory.clear(),u._diffHistory.clear(),u._narrationHistory.clear();}get canGoBack(){return u._diffHistory.size>0}blockGoBack(){core.GameUnifier.runningStepsCount===0&&u._diffHistory.clear();}isSameStep(t,i){if(t.openedLabels.length===i.openedLabels.length)try{let s=JSON.stringify(t.openedLabels),r=JSON.stringify(i.openedLabels);if(s===r&&t.path===i.path&&t.labelIndex===i.labelIndex)return !0}catch(s){return O.error("Error comparing opened labels",s),true}return false}clear(){u._stepsInfoHistory.clear(),u._diffHistory.clear(),u._narrationHistory.clear(),u._originalStepData=void 0;}get stepLimitSaved(){return u.stepLimitSaved}set stepLimitSaved(t){u.stepLimitSaved=t;}export(){let t=Array.from(this.keys()).sort((s,r)=>s-r);t.length>this.stepLimitSaved&&(t=t.slice(t.length-this.stepLimitSaved));let i=[];return t.forEach(s=>{let r=u._stepsInfoHistory.get(s);if(r){let o=u._diffHistory.get(s);i.push({...r,diff:o});}}),{stepsHistory:wt(i),originalStepData:wt(u._originalStepData)}}restoreNarrativeHistory(){let t=Array.from(this.keys()).sort((s,r)=>s-r),i={};t.forEach(s=>{let r=u._stepsInfoHistory.get(s);if(r){let o={...i};i={};let n=this.itemMapper({step:r,choiceIndexMade:o.choiceIndexMade,inputValue:o.inputValue,removeDialogue:o.removeDialogue},i);n&&u._narrationHistory.set(s,n);}});}async restore(t){this.clear();try{Object.hasOwn(t,"stepsHistory")?(t.stepsHistory.forEach(s=>{s.diff&&u._diffHistory.set(s.index,s.diff);let r={...s,diff:void 0};u._stepsInfoHistory.set(s.index,r);}),this.restoreNarrativeHistory()):O.warn("Could not import stepsHistory data, so will be ignored"),Object.hasOwn(t,"originalStepData")?u._originalStepData=t.originalStepData:O.warn("Could not import originalStepData data, so will be ignored");}catch(i){O.error("Error importing data",i);}}};var ke=new Et;exports.HistoryManagerStatic=u;exports.stepHistory=ke;
1
+ 'use strict';var core=require('@drincs/pixi-vn/core'),worker=require('@drincs/pixi-vn/worker');var Xt=Object.defineProperty;var kt=f=>{throw TypeError(f)};var Jt=(f,t,i)=>t in f?Xt(f,t,{enumerable:true,configurable:true,writable:true,value:i}):f[t]=i;var R=(f,t,i)=>Jt(f,typeof t!="symbol"?t+"":t,i),Dt=(f,t,i)=>t.has(f)||kt("Cannot "+i);var e=(f,t,i)=>(Dt(f,t,"read from private field"),i?i.call(f):t.get(f)),S=(f,t,i)=>t.has(f)?kt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(f):t.set(f,i),p=(f,t,i,s)=>(Dt(f,t,"write to private field"),t.set(f,i),i),u=(f,t,i)=>(Dt(f,t,"access private method"),i);var Tt=(f,t,i,s)=>({set _(r){p(f,t,r);},get _(){return e(f,t,s)}});var zt="narration";var Vt={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 Qt=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Yt=new Set,Mt=typeof process=="object"&&process?process:{},Wt=(f,t,i,s)=>{typeof Mt.emitWarning=="function"?Mt.emitWarning(f,t,i,s):console.error(`[${i}] ${t}: ${f}`);},Rt=globalThis.AbortController,Ut=globalThis.AbortSignal;if(typeof Rt>"u"){Ut=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},Rt=class{constructor(){t();}signal=new Ut;abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=true;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i);}}};let f=Mt.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{f&&(f=false,Wt("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",t));};}var Zt=f=>!Yt.has(f);var st=f=>f&&f===Math.floor(f)&&f>0&&isFinite(f),jt=f=>st(f)?f<=Math.pow(2,8)?Uint8Array:f<=Math.pow(2,16)?Uint16Array:f<=Math.pow(2,32)?Uint32Array:f<=Number.MAX_SAFE_INTEGER?Ht:null:null,Ht=class extends Array{constructor(f){super(f),this.fill(0);}},et,gt,te=(et=class{heap;length;static create(t){let i=jt(t);if(!i)return [];p(et,gt,true);let s=new et(t,i);return p(et,gt,false),s}constructor(t,i){if(!e(et,gt))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new i(t),this.length=0;}push(t){this.heap[this.length++]=t;}pop(){return this.heap[--this.length]}},gt=new WeakMap,S(et,gt,false),et),Kt,Pt,W,z,j,lt,B,yt,mt,q,H,$,T,v,g,L,V,D,x,X,I,J,Q,U,K,Z,at,G,St,h,Nt,ut,it,wt,P,qt,ct,_t,At,rt,nt,Lt,xt,It,E,Gt,vt,ot,Ft,bt,Bt=(bt=class{constructor(t){S(this,h);S(this,W);S(this,z);S(this,j);S(this,lt);S(this,B);S(this,yt);S(this,mt);S(this,q);R(this,"ttl");R(this,"ttlResolution");R(this,"ttlAutopurge");R(this,"updateAgeOnGet");R(this,"updateAgeOnHas");R(this,"allowStale");R(this,"noDisposeOnSet");R(this,"noUpdateTTL");R(this,"maxEntrySize");R(this,"sizeCalculation");R(this,"noDeleteOnFetchRejection");R(this,"noDeleteOnStaleGet");R(this,"allowStaleOnFetchAbort");R(this,"allowStaleOnFetchRejection");R(this,"ignoreFetchAbort");S(this,H);S(this,$);S(this,T);S(this,v);S(this,g);S(this,L);S(this,V);S(this,D);S(this,x);S(this,X);S(this,I);S(this,J);S(this,Q);S(this,U);S(this,K);S(this,Z);S(this,at);S(this,G);S(this,St);S(this,ut,()=>{});S(this,it,()=>{});S(this,wt,()=>{});S(this,P,()=>false);S(this,ct,t=>{});S(this,_t,(t,i,s)=>{});S(this,At,(t,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});R(this,Kt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:n,updateAgeOnHas:a,allowStale:l,dispose:d,onInsert:_,disposeAfter:m,noDisposeOnSet:O,noUpdateTTL:Y,maxSize:tt=0,maxEntrySize:w=0,sizeCalculation:b,fetchMethod:y,memoMethod:M,noDeleteOnFetchRejection:k,noDeleteOnStaleGet:N,allowStaleOnFetchRejection:A,allowStaleOnFetchAbort:Et,ignoreFetchAbort:ft,perf:pt}=t;if(pt!==void 0&&typeof pt?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(p(this,q,pt??Qt),i!==0&&!st(i))throw new TypeError("max option must be a nonnegative integer");let dt=i?jt(i):Array;if(!dt)throw new Error("invalid max value: "+i);if(p(this,W,i),p(this,z,tt),this.maxEntrySize=w||e(this,z),this.sizeCalculation=b,this.sizeCalculation){if(!e(this,z)&&!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(M!==void 0&&typeof M!="function")throw new TypeError("memoMethod must be a function if defined");if(p(this,mt,M),y!==void 0&&typeof y!="function")throw new TypeError("fetchMethod must be a function if specified");if(p(this,yt,y),p(this,at,!!y),p(this,T,new Map),p(this,v,new Array(i).fill(void 0)),p(this,g,new Array(i).fill(void 0)),p(this,L,new dt(i)),p(this,V,new dt(i)),p(this,D,0),p(this,x,0),p(this,X,te.create(i)),p(this,H,0),p(this,$,0),typeof d=="function"&&p(this,j,d),typeof _=="function"&&p(this,lt,_),typeof m=="function"?(p(this,B,m),p(this,I,[])):(p(this,B,void 0),p(this,I,void 0)),p(this,Z,!!e(this,j)),p(this,St,!!e(this,lt)),p(this,G,!!e(this,B)),this.noDisposeOnSet=!!O,this.noUpdateTTL=!!Y,this.noDeleteOnFetchRejection=!!k,this.allowStaleOnFetchRejection=!!A,this.allowStaleOnFetchAbort=!!Et,this.ignoreFetchAbort=!!ft,this.maxEntrySize!==0){if(e(this,z)!==0&&!st(e(this,z)))throw new TypeError("maxSize must be a positive integer if specified");if(!st(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");u(this,h,qt).call(this);}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!N,this.updateAgeOnGet=!!n,this.updateAgeOnHas=!!a,this.ttlResolution=st(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!st(this.ttl))throw new TypeError("ttl must be a positive integer if specified");u(this,h,Nt).call(this);}if(e(this,W)===0&&this.ttl===0&&e(this,z)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!e(this,W)&&!e(this,z)){let Ct="LRU_CACHE_UNBOUNDED";Zt(Ct)&&(Yt.add(Ct),Wt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Ct,bt));}}get perf(){return e(this,q)}static unsafeExposeInternals(t){return {starts:e(t,Q),ttls:e(t,U),autopurgeTimers:e(t,K),sizes:e(t,J),keyMap:e(t,T),keyList:e(t,v),valList:e(t,g),next:e(t,L),prev:e(t,V),get head(){return e(t,D)},get tail(){return e(t,x)},free:e(t,X),isBackgroundFetch:i=>{var s;return u(s=t,h,E).call(s,i)},backgroundFetch:(i,s,r,o)=>{var n;return u(n=t,h,It).call(n,i,s,r,o)},moveToTail:i=>{var s;return u(s=t,h,vt).call(s,i)},indexes:i=>{var s;return u(s=t,h,rt).call(s,i)},rindexes:i=>{var s;return u(s=t,h,nt).call(s,i)},isStale:i=>{var s;return e(s=t,P).call(s,i)}}}get max(){return e(this,W)}get maxSize(){return e(this,z)}get calculatedSize(){return e(this,$)}get size(){return e(this,H)}get fetchMethod(){return e(this,yt)}get memoMethod(){return e(this,mt)}get dispose(){return e(this,j)}get onInsert(){return e(this,lt)}get disposeAfter(){return e(this,B)}getRemainingTTL(t){return e(this,T).has(t)?1/0:0}*entries(){for(let t of u(this,h,rt).call(this))e(this,g)[t]!==void 0&&e(this,v)[t]!==void 0&&!u(this,h,E).call(this,e(this,g)[t])&&(yield [e(this,v)[t],e(this,g)[t]]);}*rentries(){for(let t of u(this,h,nt).call(this))e(this,g)[t]!==void 0&&e(this,v)[t]!==void 0&&!u(this,h,E).call(this,e(this,g)[t])&&(yield [e(this,v)[t],e(this,g)[t]]);}*keys(){for(let t of u(this,h,rt).call(this)){let i=e(this,v)[t];i!==void 0&&!u(this,h,E).call(this,e(this,g)[t])&&(yield i);}}*rkeys(){for(let t of u(this,h,nt).call(this)){let i=e(this,v)[t];i!==void 0&&!u(this,h,E).call(this,e(this,g)[t])&&(yield i);}}*values(){for(let t of u(this,h,rt).call(this))e(this,g)[t]!==void 0&&!u(this,h,E).call(this,e(this,g)[t])&&(yield e(this,g)[t]);}*rvalues(){for(let t of u(this,h,nt).call(this))e(this,g)[t]!==void 0&&!u(this,h,E).call(this,e(this,g)[t])&&(yield e(this,g)[t]);}[(Pt=Symbol.iterator,Kt=Symbol.toStringTag,Pt)](){return this.entries()}find(t,i={}){for(let s of u(this,h,rt).call(this)){let r=e(this,g)[s],o=u(this,h,E).call(this,r)?r.__staleWhileFetching:r;if(o!==void 0&&t(o,e(this,v)[s],this))return this.get(e(this,v)[s],i)}}forEach(t,i=this){for(let s of u(this,h,rt).call(this)){let r=e(this,g)[s],o=u(this,h,E).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(i,o,e(this,v)[s],this);}}rforEach(t,i=this){for(let s of u(this,h,nt).call(this)){let r=e(this,g)[s],o=u(this,h,E).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(i,o,e(this,v)[s],this);}}purgeStale(){let t=false;for(let i of u(this,h,nt).call(this,{allowStale:true}))e(this,P).call(this,i)&&(u(this,h,ot).call(this,e(this,v)[i],"expire"),t=true);return t}info(t){let i=e(this,T).get(t);if(i===void 0)return;let s=e(this,g)[i],r=u(this,h,E).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(e(this,U)&&e(this,Q)){let n=e(this,U)[i],a=e(this,Q)[i];if(n&&a){let l=n-(e(this,q).now()-a);o.ttl=l,o.start=Date.now();}}return e(this,J)&&(o.size=e(this,J)[i]),o}dump(){let t=[];for(let i of u(this,h,rt).call(this,{allowStale:true})){let s=e(this,v)[i],r=e(this,g)[i],o=u(this,h,E).call(this,r)?r.__staleWhileFetching:r;if(o===void 0||s===void 0)continue;let n={value:o};if(e(this,U)&&e(this,Q)){n.ttl=e(this,U)[i];let a=e(this,q).now()-e(this,Q)[i];n.start=Math.floor(Date.now()-a);}e(this,J)&&(n.size=e(this,J)[i]),t.unshift([s,n]);}return t}load(t){this.clear();for(let[i,s]of t){if(s.start){let r=Date.now()-s.start;s.start=e(this,q).now()-r;}this.set(i,s.value,s);}}set(t,i,s={}){var O,Y,tt,w;if(i===void 0)return this.delete(t),this;let{ttl:r=this.ttl,start:o,noDisposeOnSet:n=this.noDisposeOnSet,sizeCalculation:a=this.sizeCalculation,status:l}=s,{noUpdateTTL:d=this.noUpdateTTL}=s,_=e(this,At).call(this,t,i,s.size||0,a);if(this.maxEntrySize&&_>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=true),u(this,h,ot).call(this,t,"set"),this;let m=e(this,H)===0?void 0:e(this,T).get(t);if(m===void 0)m=e(this,H)===0?e(this,x):e(this,X).length!==0?e(this,X).pop():e(this,H)===e(this,W)?u(this,h,xt).call(this,false):e(this,H),e(this,v)[m]=t,e(this,g)[m]=i,e(this,T).set(t,m),e(this,L)[e(this,x)]=m,e(this,V)[m]=e(this,x),p(this,x,m),Tt(this,H)._++,e(this,_t).call(this,m,_,l),l&&(l.set="add"),d=false,e(this,St)&&((O=e(this,lt))==null||O.call(this,i,t,"add"));else {u(this,h,vt).call(this,m);let b=e(this,g)[m];if(i!==b){if(e(this,at)&&u(this,h,E).call(this,b)){b.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:y}=b;y!==void 0&&!n&&(e(this,Z)&&((Y=e(this,j))==null||Y.call(this,y,t,"set")),e(this,G)&&e(this,I)?.push([y,t,"set"]));}else n||(e(this,Z)&&((tt=e(this,j))==null||tt.call(this,b,t,"set")),e(this,G)&&e(this,I)?.push([b,t,"set"]));if(e(this,ct).call(this,m),e(this,_t).call(this,m,_,l),e(this,g)[m]=i,l){l.set="replace";let y=b&&u(this,h,E).call(this,b)?b.__staleWhileFetching:b;y!==void 0&&(l.oldValue=y);}}else l&&(l.set="update");e(this,St)&&this.onInsert?.(i,t,i===b?"update":"replace");}if(r!==0&&!e(this,U)&&u(this,h,Nt).call(this),e(this,U)&&(d||e(this,wt).call(this,m,r,o),l&&e(this,it).call(this,l,m)),!n&&e(this,G)&&e(this,I)){let b=e(this,I),y;for(;y=b?.shift();)(w=e(this,B))==null||w.call(this,...y);}return this}pop(){var t;try{for(;e(this,H);){let i=e(this,g)[e(this,D)];if(u(this,h,xt).call(this,!0),u(this,h,E).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(e(this,G)&&e(this,I)){let i=e(this,I),s;for(;s=i?.shift();)(t=e(this,B))==null||t.call(this,...s);}}}has(t,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=i,o=e(this,T).get(t);if(o!==void 0){let n=e(this,g)[o];if(u(this,h,E).call(this,n)&&n.__staleWhileFetching===void 0)return false;if(e(this,P).call(this,o))r&&(r.has="stale",e(this,it).call(this,r,o));else return s&&e(this,ut).call(this,o),r&&(r.has="hit",e(this,it).call(this,r,o)),true}else r&&(r.has="miss");return false}peek(t,i={}){let{allowStale:s=this.allowStale}=i,r=e(this,T).get(t);if(r===void 0||!s&&e(this,P).call(this,r))return;let o=e(this,g)[r];return u(this,h,E).call(this,o)?o.__staleWhileFetching:o}async fetch(t,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:a=this.noDisposeOnSet,size:l=0,sizeCalculation:d=this.sizeCalculation,noUpdateTTL:_=this.noUpdateTTL,noDeleteOnFetchRejection:m=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:O=this.allowStaleOnFetchRejection,ignoreFetchAbort:Y=this.ignoreFetchAbort,allowStaleOnFetchAbort:tt=this.allowStaleOnFetchAbort,context:w,forceRefresh:b=false,status:y,signal:M}=i;if(!e(this,at))return y&&(y.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:y});let k={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:n,noDisposeOnSet:a,size:l,sizeCalculation:d,noUpdateTTL:_,noDeleteOnFetchRejection:m,allowStaleOnFetchRejection:O,allowStaleOnFetchAbort:tt,ignoreFetchAbort:Y,status:y,signal:M},N=e(this,T).get(t);if(N===void 0){y&&(y.fetch="miss");let A=u(this,h,It).call(this,t,N,k,w);return A.__returned=A}else {let A=e(this,g)[N];if(u(this,h,E).call(this,A)){let dt=s&&A.__staleWhileFetching!==void 0;return y&&(y.fetch="inflight",dt&&(y.returnedStale=true)),dt?A.__staleWhileFetching:A.__returned=A}let Et=e(this,P).call(this,N);if(!b&&!Et)return y&&(y.fetch="hit"),u(this,h,vt).call(this,N),r&&e(this,ut).call(this,N),y&&e(this,it).call(this,y,N),A;let ft=u(this,h,It).call(this,t,N,k,w),pt=ft.__staleWhileFetching!==void 0&&s;return y&&(y.fetch=Et?"stale":"refresh",pt&&Et&&(y.returnedStale=true)),pt?ft.__staleWhileFetching:ft.__returned=ft}}async forceFetch(t,i={}){let s=await this.fetch(t,i);if(s===void 0)throw new Error("fetch() returned undefined");return s}memo(t,i={}){let s=e(this,mt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:o,...n}=i,a=this.get(t,n);if(!o&&a!==void 0)return a;let l=s(t,a,{options:n,context:r});return this.set(t,l,n),l}get(t,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:n}=i,a=e(this,T).get(t);if(a!==void 0){let l=e(this,g)[a],d=u(this,h,E).call(this,l);return n&&e(this,it).call(this,n,a),e(this,P).call(this,a)?(n&&(n.get="stale"),d?(n&&s&&l.__staleWhileFetching!==void 0&&(n.returnedStale=true),s?l.__staleWhileFetching:void 0):(o||u(this,h,ot).call(this,t,"expire"),n&&s&&(n.returnedStale=true),s?l:void 0)):(n&&(n.get="hit"),d?l.__staleWhileFetching:(u(this,h,vt).call(this,a),r&&e(this,ut).call(this,a),l))}else n&&(n.get="miss");}delete(t){return u(this,h,ot).call(this,t,"delete")}clear(){return u(this,h,Ft).call(this,"delete")}},W=new WeakMap,z=new WeakMap,j=new WeakMap,lt=new WeakMap,B=new WeakMap,yt=new WeakMap,mt=new WeakMap,q=new WeakMap,H=new WeakMap,$=new WeakMap,T=new WeakMap,v=new WeakMap,g=new WeakMap,L=new WeakMap,V=new WeakMap,D=new WeakMap,x=new WeakMap,X=new WeakMap,I=new WeakMap,J=new WeakMap,Q=new WeakMap,U=new WeakMap,K=new WeakMap,Z=new WeakMap,at=new WeakMap,G=new WeakMap,St=new WeakMap,h=new WeakSet,Nt=function(){let t=new Ht(e(this,W)),i=new Ht(e(this,W));p(this,U,t),p(this,Q,i);let s=this.ttlAutopurge?new Array(e(this,W)):void 0;p(this,K,s),p(this,wt,(a,l,d=e(this,q).now())=>{i[a]=l!==0?d:0,t[a]=l,r(a,l);}),p(this,ut,a=>{i[a]=t[a]!==0?e(this,q).now():0,r(a,t[a]);});let r=this.ttlAutopurge?(a,l)=>{if(s?.[a]&&(clearTimeout(s[a]),s[a]=void 0),l&&l!==0&&s){let d=setTimeout(()=>{e(this,P).call(this,a)&&u(this,h,ot).call(this,e(this,v)[a],"expire");},l+1);d.unref&&d.unref(),s[a]=d;}}:()=>{};p(this,it,(a,l)=>{if(t[l]){let d=t[l],_=i[l];if(!d||!_)return;a.ttl=d,a.start=_,a.now=o||n();let m=a.now-_;a.remainingTTL=d-m;}});let o=0,n=()=>{let a=e(this,q).now();if(this.ttlResolution>0){o=a;let l=setTimeout(()=>o=0,this.ttlResolution);l.unref&&l.unref();}return a};this.getRemainingTTL=a=>{let l=e(this,T).get(a);if(l===void 0)return 0;let d=t[l],_=i[l];if(!d||!_)return 1/0;let m=(o||n())-_;return d-m},p(this,P,a=>{let l=i[a],d=t[a];return !!d&&!!l&&(o||n())-l>d});},ut=new WeakMap,it=new WeakMap,wt=new WeakMap,P=new WeakMap,qt=function(){let t=new Ht(e(this,W));p(this,$,0),p(this,J,t),p(this,ct,i=>{p(this,$,e(this,$)-t[i]),t[i]=0;}),p(this,At,(i,s,r,o)=>{if(u(this,h,E).call(this,s))return 0;if(!st(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,i),!st(r))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 r}),p(this,_t,(i,s,r)=>{if(t[i]=s,e(this,z)){let o=e(this,z)-t[i];for(;e(this,$)>o;)u(this,h,xt).call(this,true);}p(this,$,e(this,$)+t[i]),r&&(r.entrySize=s,r.totalCalculatedSize=e(this,$));});},ct=new WeakMap,_t=new WeakMap,At=new WeakMap,rt=function*({allowStale:t=this.allowStale}={}){if(e(this,H))for(let i=e(this,x);!(!u(this,h,Lt).call(this,i)||((t||!e(this,P).call(this,i))&&(yield i),i===e(this,D)));)i=e(this,V)[i];},nt=function*({allowStale:t=this.allowStale}={}){if(e(this,H))for(let i=e(this,D);!(!u(this,h,Lt).call(this,i)||((t||!e(this,P).call(this,i))&&(yield i),i===e(this,x)));)i=e(this,L)[i];},Lt=function(t){return t!==void 0&&e(this,T).get(e(this,v)[t])===t},xt=function(t){var o;let i=e(this,D),s=e(this,v)[i],r=e(this,g)[i];return e(this,at)&&u(this,h,E).call(this,r)?r.__abortController.abort(new Error("evicted")):(e(this,Z)||e(this,G))&&(e(this,Z)&&((o=e(this,j))==null||o.call(this,r,s,"evict")),e(this,G)&&e(this,I)?.push([r,s,"evict"])),e(this,ct).call(this,i),e(this,K)?.[i]&&(clearTimeout(e(this,K)[i]),e(this,K)[i]=void 0),t&&(e(this,v)[i]=void 0,e(this,g)[i]=void 0,e(this,X).push(i)),e(this,H)===1?(p(this,D,p(this,x,0)),e(this,X).length=0):p(this,D,e(this,L)[i]),e(this,T).delete(s),Tt(this,H)._--,i},It=function(t,i,s,r){let o=i===void 0?void 0:e(this,g)[i];if(u(this,h,E).call(this,o))return o;let n=new Rt,{signal:a}=s;a?.addEventListener("abort",()=>n.abort(a.reason),{signal:n.signal});let l={signal:n.signal,options:s,context:r},d=(w,b=false)=>{let{aborted:y}=n.signal,M=s.ignoreFetchAbort&&w!==void 0,k=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&w!==void 0);if(s.status&&(y&&!b?(s.status.fetchAborted=true,s.status.fetchError=n.signal.reason,M&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),y&&!M&&!b)return m(n.signal.reason,k);let N=Y,A=e(this,g)[i];return (A===Y||M&&b&&A===void 0)&&(w===void 0?N.__staleWhileFetching!==void 0?e(this,g)[i]=N.__staleWhileFetching:u(this,h,ot).call(this,t,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(t,w,l.options))),w},_=w=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=w),m(w,false)),m=(w,b)=>{let{aborted:y}=n.signal,M=y&&s.allowStaleOnFetchAbort,k=M||s.allowStaleOnFetchRejection,N=k||s.noDeleteOnFetchRejection,A=Y;if(e(this,g)[i]===Y&&(!N||!b&&A.__staleWhileFetching===void 0?u(this,h,ot).call(this,t,"fetch"):M||(e(this,g)[i]=A.__staleWhileFetching)),k)return s.status&&A.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),A.__staleWhileFetching;if(A.__returned===A)throw w},O=(w,b)=>{var M;let y=(M=e(this,yt))==null?void 0:M.call(this,t,o,l);y&&y instanceof Promise&&y.then(k=>w(k===void 0?void 0:k),b),n.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(w(void 0),s.allowStaleOnFetchAbort&&(w=k=>d(k,true)));});};s.status&&(s.status.fetchDispatched=true);let Y=new Promise(O).then(d,_),tt=Object.assign(Y,{__abortController:n,__staleWhileFetching:o,__returned:void 0});return i===void 0?(this.set(t,tt,{...l.options,status:void 0}),i=e(this,T).get(t)):e(this,g)[i]=tt,tt},E=function(t){if(!e(this,at))return false;let i=t;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Rt},Gt=function(t,i){e(this,V)[i]=t,e(this,L)[t]=i;},vt=function(t){t!==e(this,x)&&(t===e(this,D)?p(this,D,e(this,L)[t]):u(this,h,Gt).call(this,e(this,V)[t],e(this,L)[t]),u(this,h,Gt).call(this,e(this,x),t),p(this,x,t));},ot=function(t,i){var r,o;let s=false;if(e(this,H)!==0){let n=e(this,T).get(t);if(n!==void 0)if(e(this,K)?.[n]&&(clearTimeout(e(this,K)?.[n]),e(this,K)[n]=void 0),s=true,e(this,H)===1)u(this,h,Ft).call(this,i);else {e(this,ct).call(this,n);let a=e(this,g)[n];if(u(this,h,E).call(this,a)?a.__abortController.abort(new Error("deleted")):(e(this,Z)||e(this,G))&&(e(this,Z)&&((r=e(this,j))==null||r.call(this,a,t,i)),e(this,G)&&e(this,I)?.push([a,t,i])),e(this,T).delete(t),e(this,v)[n]=void 0,e(this,g)[n]=void 0,n===e(this,x))p(this,x,e(this,V)[n]);else if(n===e(this,D))p(this,D,e(this,L)[n]);else {let l=e(this,V)[n];e(this,L)[l]=e(this,L)[n];let d=e(this,L)[n];e(this,V)[d]=e(this,V)[n];}Tt(this,H)._--,e(this,X).push(n);}}if(e(this,G)&&e(this,I)?.length){let n=e(this,I),a;for(;a=n?.shift();)(o=e(this,B))==null||o.call(this,...a);}return s},Ft=function(t){var i,s;for(let r of u(this,h,nt).call(this,{allowStale:true})){let o=e(this,g)[r];if(u(this,h,E).call(this,o))o.__abortController.abort(new Error("deleted"));else {let n=e(this,v)[r];e(this,Z)&&((i=e(this,j))==null||i.call(this,o,n,t)),e(this,G)&&e(this,I)?.push([o,n,t]);}}if(e(this,T).clear(),e(this,g).fill(void 0),e(this,v).fill(void 0),e(this,U)&&e(this,Q)){e(this,U).fill(0),e(this,Q).fill(0);for(let r of e(this,K)??[])r!==void 0&&clearTimeout(r);e(this,K)?.fill(void 0);}if(e(this,J)&&e(this,J).fill(0),p(this,D,0),p(this,x,0),e(this,X).length=0,p(this,$,0),p(this,H,0),e(this,G)&&e(this,I)){let r=e(this,I),o;for(;o=r?.shift();)(s=e(this,B))==null||s.call(this,...o);}},bt);var ht=class{cache;map=new Map;constructor(t){this.cache=new Bt({max:t.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(t){let i=this.map.delete(t);return i&&this.cache.delete(t),i}get forEach(){return this.map.forEach}get(t){let i=this.cache.get(t);return i||this.map.get(t)}has(t){return this.map.has(t)}set(t,i){return this.map.set(t,i),this.cache.set(t,i),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var c=class f{static _diffHistory=new ht({cacheSize:5});static _stepsInfoHistory=new ht({cacheSize:5});static _narrationHistory=new ht({cacheSize:50});static stepLimitSaved=20;static goBackMode="step";static _originalStepData=void 0;static get originalStepData(){return f._originalStepData?f._originalStepData:{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{}},labelIndex:-1,openedLabels:[]}}static set originalStepData(t){f._originalStepData=t;}};var C;(r=>(r.log=(o,...n)=>console.log(`[Pixi\u2019VN] ${o}`,...n),r.warn=(o,...n)=>console.warn(`[Pixi\u2019VN] ${o}`,...n),r.error=(o,...n)=>console.error(`[Pixi\u2019VN] ${o}`,...n),r.info=(o,...n)=>console.info(`[Pixi\u2019VN] ${o}`,...n)))(C||={});var Ot=class{get stepsInfoMap(){return c._stepsInfoHistory}get diffMap(){return c._diffHistory}get narrationMap(){return c._narrationHistory}get size(){return c._stepsInfoHistory.size}get lastKey(){if(this.size===0)return null;let t=null;for(let i of this.keys())(t===null||i>t)&&(t=i);return t}get lastDiffKey(){let t=null;for(let i of c._diffHistory.keys())(t===null||i>t)&&(t=i);return t}get goBackMode(){return c.goBackMode}set goBackMode(t){c.goBackMode=t;}keys(){return c._stepsInfoHistory.keys()}get(t){let i=c._narrationHistory.get(t);if(!(i&&Object.keys(i).length===1&&i.stepIndex!==void 0))return i}delete(t){c._stepsInfoHistory.delete(t),c._diffHistory.delete(t),c._narrationHistory.delete(t);}deleteFromKeyOnward(t){Array.from(this.keys()).filter(i=>i>=t).forEach(i=>{this.delete(i);});}previousCheckpointKey(t){let i=0;for(let s of c._diffHistory.keys())s<t&&s>i&&(i=s);return i}pendingInputRestoreValue;findPreviousInputAnswer(t){if(c._stepsInfoHistory.get(t-1)?.isRequiredInput)return c._stepsInfoHistory.get(t)?.inputValue}async getOldGameState(t,i){if(t<=0||this.size===0)return i;let s=this.lastDiffKey;if(typeof s!="number")return C.warn("You can't go back, there is no step to go back"),i;let r=c._diffHistory.get(s);if(r)try{let o=await worker.restoreDiffMaybeOffloaded(i,r),n=this.previousCheckpointKey(s)+1;return core.GameUnifier.stepCounter=n,t===1&&(this.pendingInputRestoreValue=this.findPreviousInputAnswer(n)),this.deleteFromKeyOnward(n),this.getOldGameState(t-1,o)}catch(o){return C.error("Error applying diff",o),i}else return C.warn("No diff found for the last step, cannot go back"),i}async back(t,i={}){let{steps:s=1}=i;if(!Number.isFinite(s)){C.warn(`[back] The parameter steps must be a valid finite number, received: ${s}`);return}if(s<=0){C.warn(`[back] The parameter steps must be greater than 0, received: ${s}`);return}if(core.GameUnifier.runningStepsCount>0){core.GameUnifier.increaseBackRequest(s);return}if(c._diffHistory.size<1){C.warn("You can't go back, there is no step to go back");return}core.GameUnifier.runningStepsCount++;try{this.pendingInputRestoreValue=void 0;let r=await this.getOldGameState(s,c.originalStepData);if(r){await core.GameUnifier.restoreGameStepState(r,core.GameUnifier.navigate),this.pendingInputRestoreValue!==void 0&&core.GameUnifier.setVariable(zt,Vt.CURRENT_INPUT_VALUE_MEMORY_KEY,this.pendingInputRestoreValue);let o=core.GameUnifier.stepCounter-1,n=c._stepsInfoHistory.get(o),a=c._narrationHistory.get(o),l=a&&Object.keys(a).length===1&&a.stepIndex!==void 0;if(n&&(l||n.isRequiredInput)){let d=this.itemMapper({step:n,inputValue:n.isRequiredInput?this.pendingInputRestoreValue:void 0});c._narrationHistory.set(n.index,d);}}else C.error("Error going back");c.originalStepData=r;}catch(r){C.error("Error going back",r);}if(core.GameUnifier.runningStepsCount--,core.GameUnifier.runningStepsCount===0&&core.GameUnifier.backRequestsCount!==0)return await core.GameUnifier.processNavigationRequests(t)}isCheckpointStep(t,i){if(c.goBackMode==="step"||t.choices&&t.choices.length>0||t.isRequiredInput)return true;let s=t.openedLabels??[],r=i?.openedLabels??[];return s.length!==r.length?true:s.some((o,n)=>o.label!==r[n]?.label)}async add(t,i={}){let s=c.originalStepData,{ignoreSameStep:r}=i,o=await core.GameUnifier.currentGameStepState;if(!r&&this.isSameStep(s,o))return;let n=this.lastKey,a=typeof n=="number"?c._stepsInfoHistory.get(n):void 0,l=t.index===0||this.isCheckpointStep(t,a);try{let d=typeof n=="number"?c._narrationHistory.get(n):void 0;c._stepsInfoHistory.set(t.index,t);let _={},m=this.itemMapper({step:t},_);if(c._narrationHistory.set(t.index,m),a&&d&&typeof n=="number"){let O=this.itemMapper({..._,step:a},{});c._narrationHistory.set(n,O);}}catch(d){C.error("Error adding history step",d);}t.index!==0&&l&&(async()=>{try{let d=await worker.diffMaybeOffloaded(s,o);d?c._diffHistory.set(t.index,d):C.warn("It was not possible to create the difference between the two steps");}catch(d){C.error("Error adding history step",d);}})(),(t.index===0||l)&&(c.originalStepData=o);}itemMapper(t,i){let{step:s,choiceIndexMade:r,inputValue:o,removeDialogue:n}=t,a=s.dialogue;i&&s.isGlued&&(i.removeDialogue=true),n&&(a=void 0);let l=s.choices;if(i&&s.currentLabel&&s.choiceIndexMade!==void 0&&(i.choiceIndexMade=s.choiceIndexMade),s.inputValue&&i&&(i.inputValue=s.inputValue),a||l||o){let d=l?.map((_,m)=>{let O=false;return _.oneTime&&s.alreadyMadeChoices?.includes(m)&&(O=true),{text:_.text,type:_.type,isResponse:false,hidden:O}});if(d){if(d.every(_=>_.hidden)){let _=d.find(m=>m.hidden===false);_&&(_.hidden=false);}r!==void 0&&(d[r].isResponse=true);}return {dialogue:a?{...a,character:a.character?core.GameUnifier.getCharacter(a.character)||a.character:void 0}:void 0,playerMadeChoice:typeof r=="number",choices:d,stepIndex:s.index,inputValue:o,openedLabelsNumber:s.openedLabels?.length}}return {stepIndex:s.index}}get narrativeHistory(){let t=[];return Array.from(this.keys()).sort((s,r)=>s-r).forEach(s=>{let r=this.get(s);r&&t.push(r);}),t}get currentLabelHistory(){let t=[],i=Array.from(this.keys()).sort((l,d)=>d-l);if(i.length===0)return t;let s=i[0];if(typeof s!="number")return t;let r=c._stepsInfoHistory.get(s);if(!r)return t;let o=r.openedLabels;if(!o||!Array.isArray(o)||o.length===0)return t;let n=o[0].currentStepIndex,a=o[0].label;return i.every((l,d)=>{let _=this.get(l);if(_){if(d===0)return t.push(_),true;let m=c._stepsInfoHistory.get(l);if(!m)return true;let O=m.openedLabels;if(!O||!Array.isArray(O)||O.length===0||O[0].label!==a||O[0].currentStepIndex>n)return false;n=O[0].currentStepIndex,t.push(_);}return true}),t.reverse()}get currentPageParagraphs(){let t=[],i;return this.currentLabelHistory.forEach(s=>{t.length===0||s.openedLabelsNumber!==i?t.push([s]):t[t.length-1].push(s),i=s.openedLabelsNumber;}),t}removeNarrativeHistory(t){if(t){let i=Array.from(this.keys()).sort((s,r)=>s-r);i=i.slice(0,t),i.forEach(s=>{c._narrationHistory.delete(s),c._stepsInfoHistory.delete(s),c._diffHistory.delete(s);});}else c._stepsInfoHistory.clear(),c._diffHistory.clear(),c._narrationHistory.clear();}get canGoBack(){return c._diffHistory.size>0}blockGoBack(){core.GameUnifier.runningStepsCount===0&&c._diffHistory.clear();}isSameStep(t,i){if(t.openedLabels.length===i.openedLabels.length)try{let s=JSON.stringify(t.openedLabels),r=JSON.stringify(i.openedLabels);if(s===r&&t.path===i.path&&t.labelIndex===i.labelIndex)return !0}catch(s){return C.error("Error comparing opened labels",s),true}return false}clear(){c._stepsInfoHistory.clear(),c._diffHistory.clear(),c._narrationHistory.clear(),c._originalStepData=void 0;}get stepLimitSaved(){return c.stepLimitSaved}set stepLimitSaved(t){c.stepLimitSaved=t;}async export(){let t=Array.from(this.keys()).sort((n,a)=>n-a);t.length>this.stepLimitSaved&&(t=t.slice(t.length-this.stepLimitSaved));let i=[];t.forEach(n=>{let a=c._stepsInfoHistory.get(n);if(a){let l=c._diffHistory.get(n);i.push({...a,diff:l});}});let s=c._originalStepData,[r,o]=await Promise.all([worker.cloneMaybeOffloaded(i),s?worker.cloneMaybeOffloaded(s):void 0]);return {stepsHistory:r,originalStepData:o}}restoreNarrativeHistory(){let t=Array.from(this.keys()).sort((s,r)=>s-r),i={};t.forEach(s=>{let r=c._stepsInfoHistory.get(s);if(r){let o={...i};i={};let n=this.itemMapper({step:r,choiceIndexMade:o.choiceIndexMade,inputValue:o.inputValue,removeDialogue:o.removeDialogue},i);n&&c._narrationHistory.set(s,n);}});}async restore(t){this.clear();try{Object.hasOwn(t,"stepsHistory")?(t.stepsHistory.forEach(s=>{s.diff&&c._diffHistory.set(s.index,s.diff);let r={...s,diff:void 0};c._stepsInfoHistory.set(s.index,r);}),this.restoreNarrativeHistory()):C.warn("Could not import stepsHistory data, so will be ignored"),Object.hasOwn(t,"originalStepData")?c._originalStepData=t.originalStepData:C.warn("Could not import originalStepData data, so will be ignored");}catch(i){C.error("Error importing data",i);}}};var Ae=new Ot;exports.HistoryManagerStatic=c;exports.stepHistory=Ae;
@@ -113,7 +113,7 @@ interface HistoryManagerInterface {
113
113
  * If true, the step will not be added to the history if the current step is the same as the last step.
114
114
  */
115
115
  ignoreSameStep?: boolean;
116
- }): void;
116
+ }): Promise<void>;
117
117
  /**
118
118
  * Clear the history.
119
119
  */
@@ -167,7 +167,7 @@ interface HistoryManagerInterface {
167
167
  * Export the history to an object.
168
168
  * @returns The history in an object.
169
169
  */
170
- export(): HistoryGameState;
170
+ export(): Promise<HistoryGameState>;
171
171
  /**
172
172
  * Restore the history from an object.
173
173
  * @param data The history in an object.
package/dist/history.d.ts CHANGED
@@ -113,7 +113,7 @@ interface HistoryManagerInterface {
113
113
  * If true, the step will not be added to the history if the current step is the same as the last step.
114
114
  */
115
115
  ignoreSameStep?: boolean;
116
- }): void;
116
+ }): Promise<void>;
117
117
  /**
118
118
  * Clear the history.
119
119
  */
@@ -167,7 +167,7 @@ interface HistoryManagerInterface {
167
167
  * Export the history to an object.
168
168
  * @returns The history in an object.
169
169
  */
170
- export(): HistoryGameState;
170
+ export(): Promise<HistoryGameState>;
171
171
  /**
172
172
  * Restore the history from an object.
173
173
  * @param data The history in an object.
package/dist/history.mjs CHANGED
@@ -1 +1 @@
1
- import'./chunk-JMOSOAGB.mjs';import {d,e,f}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier}from'@drincs/pixi-vn/core';var i=class d$1{static _diffHistory=new d({cacheSize:5});static _stepsInfoHistory=new d({cacheSize:5});static _narrationHistory=new d({cacheSize:50});static stepLimitSaved=20;static goBackMode="step";static _originalStepData=void 0;static get originalStepData(){return d$1._originalStepData?d$1._originalStepData:{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{}},labelIndex:-1,openedLabels:[]}}static set originalStepData(e){d$1._originalStepData=e;}};function k(d,e){let r=f(d);return e.length>1&&"type"in e[0]&&(e=e.slice().reverse()),e.forEach(t=>{_(r,t);}),r}function _(d,e$1){let r=d;e$1.path&&e$1.path.length>0?e$1.path.forEach((t,n)=>{if(e$1.path&&n===e$1.path.length-1)switch(e$1.type){case "CHANGE":case "REMOVE":r[t]=e$1.oldValue;break;case "CREATE":Array.isArray(r)&&typeof t=="number"?r.splice(t,1):delete r[t];break}else r=r[t];}):e.warn("No path found, skipping diff",e$1);}var v=["Date","RegExp","String","Number"],M=Object.getOwnPropertyNames(globalThis.Temporal||{});function S(d,e,r={cyclesFix:true},t=[]){let n=[],a=Array.isArray(d);for(let s in d){let o=d[s],u=a?+s:s;if(!(s in e)){n.push({type:"REMOVE",path:[u],oldValue:o});continue}let p=e[s],m=typeof o=="object"&&typeof p=="object"&&Array.isArray(o)===Array.isArray(p),l=m&&o?Object.getPrototypeOf(o)?.constructor?.name:void 0;if(o&&p&&m&&!v.includes(l)&&!M.includes(l)&&(!r.cyclesFix||!t.includes(o))){r.cyclesFix&&t.push(o);let g=S(o,p,r,t);r.cyclesFix&&t.pop();for(let x of g)x.path.unshift(u),n.push(x);}else Object.is(o,p)||M.includes(l)&&String(o)===String(p)||v.includes(l)&&(isNaN(o)?o+""==p+"":+o==+p)||n.push({path:[u],type:"CHANGE",value:p,oldValue:o});}let c=Array.isArray(e);for(let s in e)s in d||n.push({type:"CREATE",path:[c?+s:s],value:e[s]});return n}var b=class{get stepsInfoMap(){return i._stepsInfoHistory}get diffMap(){return i._diffHistory}get narrationMap(){return i._narrationHistory}get size(){return i._stepsInfoHistory.size}get lastKey(){if(this.size===0)return null;let e=null;for(let r of this.keys())(e===null||r>e)&&(e=r);return e}get lastDiffKey(){let e=null;for(let r of i._diffHistory.keys())(e===null||r>e)&&(e=r);return e}get goBackMode(){return i.goBackMode}set goBackMode(e){i.goBackMode=e;}keys(){return i._stepsInfoHistory.keys()}get(e){let r=i._narrationHistory.get(e);if(!(r&&Object.keys(r).length===1&&r.stepIndex!==void 0))return r}delete(e){i._stepsInfoHistory.delete(e),i._diffHistory.delete(e),i._narrationHistory.delete(e);}deleteFromKeyOnward(e){Array.from(this.keys()).filter(r=>r>=e).forEach(r=>{this.delete(r);});}previousCheckpointKey(e){let r=0;for(let t of i._diffHistory.keys())t<e&&t>r&&(r=t);return r}getOldGameState(e$1,r){if(e$1<=0||this.size===0)return r;let t=this.lastDiffKey;if(typeof t!="number")return e.warn("You can't go back, there is no step to go back"),r;let n=i._diffHistory.get(t);if(n)try{let a=k(r,n),c=this.previousCheckpointKey(t)+1;return GameUnifier.stepCounter=c,this.deleteFromKeyOnward(c),this.getOldGameState(e$1-1,a)}catch(a){return e.error("Error applying diff",a),r}else return e.warn("No diff found for the last step, cannot go back"),r}async back(e$1,r={}){let{steps:t=1}=r;if(!Number.isFinite(t)){e.warn(`[back] The parameter steps must be a valid finite number, received: ${t}`);return}if(t<=0){e.warn(`[back] The parameter steps must be greater than 0, received: ${t}`);return}if(GameUnifier.runningStepsCount>0){GameUnifier.increaseBackRequest(t);return}if(i._diffHistory.size<1){e.warn("You can't go back, there is no step to go back");return}GameUnifier.runningStepsCount++;try{let n=f(this.getOldGameState(t,i.originalStepData));if(n){await GameUnifier.restoreGameStepState(n,GameUnifier.navigate);let a=GameUnifier.stepCounter-1,c=i._narrationHistory.get(a);if(c&&Object.keys(c).length===1&&c.stepIndex!==void 0){let s=i._stepsInfoHistory.get(a);if(s){let o=this.itemMapper({step:s});i._narrationHistory.set(s.index,o);}}}else e.error("Error going back");i.originalStepData=n;}catch(n){e.error("Error going back",n);}if(GameUnifier.runningStepsCount--,GameUnifier.runningStepsCount===0&&GameUnifier.backRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1)}isCheckpointStep(e,r){if(i.goBackMode==="step"||e.choices&&e.choices.length>0||e.isRequiredInput)return true;let t=e.openedLabels??[],n=r?.openedLabels??[];return t.length!==n.length?true:t.some((a,c)=>a.label!==n[c]?.label)}add(e$1,r={}){let t=i.originalStepData,{ignoreSameStep:n}=r,a=GameUnifier.currentGameStepState;if(!n&&this.isSameStep(t,a))return;let c=this.lastKey,s=typeof c=="number"?i._stepsInfoHistory.get(c):void 0,o=e$1.index===0||this.isCheckpointStep(e$1,s);(async()=>{try{let p=typeof c=="number"?i._narrationHistory.get(c):void 0;if(i._stepsInfoHistory.set(e$1.index,e$1),e$1.index!==0&&o){let g=S(t,a);g?i._diffHistory.set(e$1.index,g):e.warn("It was not possible to create the difference between the two steps");}let m={},l=this.itemMapper({step:e$1},m);if(i._narrationHistory.set(e$1.index,l),s&&p&&typeof c=="number"){let g=this.itemMapper({...m,step:s},{});i._narrationHistory.set(c,g);}}catch(p){e.error("Error adding history step",p);}})(),(e$1.index===0||o)&&(i.originalStepData=a);}itemMapper(e,r){let{step:t,choiceIndexMade:n,inputValue:a,removeDialogue:c}=e,s=t.dialogue;r&&t.isGlued&&(r.removeDialogue=true),c&&(s=void 0);let o=t.choices;if(r&&t.currentLabel&&t.choiceIndexMade!==void 0&&(r.choiceIndexMade=t.choiceIndexMade),t.inputValue&&r&&(r.inputValue=t.inputValue),s||o||a){let u=o?.map((p,m)=>{let l=false;return p.oneTime&&t.alreadyMadeChoices?.includes(m)&&(l=true),{text:p.text,type:p.type,isResponse:false,hidden:l}});if(u){if(u.every(p=>p.hidden)){let p=u.find(m=>m.hidden===false);p&&(p.hidden=false);}n!==void 0&&(u[n].isResponse=true);}return {dialogue:s?{...s,character:s.character?GameUnifier.getCharacter(s.character)||s.character:void 0}:void 0,playerMadeChoice:typeof n=="number",choices:u,stepIndex:t.index,inputValue:a,openedLabelsNumber:t.openedLabels?.length}}return {stepIndex:t.index}}get narrativeHistory(){let e=[];return Array.from(this.keys()).sort((t,n)=>t-n).forEach(t=>{let n=this.get(t);n&&e.push(n);}),e}get currentLabelHistory(){let e=[],r=Array.from(this.keys()).sort((o,u)=>u-o);if(r.length===0)return e;let t=r[0];if(typeof t!="number")return e;let n=i._stepsInfoHistory.get(t);if(!n)return e;let a=n.openedLabels;if(!a||!Array.isArray(a)||a.length===0)return e;let c=a[0].currentStepIndex,s=a[0].label;return r.every((o,u)=>{let p=this.get(o);if(p){if(u===0)return e.push(p),true;let m=i._stepsInfoHistory.get(o);if(!m)return true;let l=m.openedLabels;if(!l||!Array.isArray(l)||l.length===0||l[0].label!==s||l[0].currentStepIndex>c)return false;c=l[0].currentStepIndex,e.push(p);}return true}),e.reverse()}get currentPageParagraphs(){let e=[],r;return this.currentLabelHistory.forEach(t=>{e.length===0||t.openedLabelsNumber!==r?e.push([t]):e[e.length-1].push(t),r=t.openedLabelsNumber;}),e}removeNarrativeHistory(e){if(e){let r=Array.from(this.keys()).sort((t,n)=>t-n);r=r.slice(0,e),r.forEach(t=>{i._narrationHistory.delete(t),i._stepsInfoHistory.delete(t),i._diffHistory.delete(t);});}else i._stepsInfoHistory.clear(),i._diffHistory.clear(),i._narrationHistory.clear();}get canGoBack(){return i._diffHistory.size>0}blockGoBack(){GameUnifier.runningStepsCount===0&&i._diffHistory.clear();}isSameStep(e$1,r){if(e$1.openedLabels.length===r.openedLabels.length)try{let t=JSON.stringify(e$1.openedLabels),n=JSON.stringify(r.openedLabels);if(t===n&&e$1.path===r.path&&e$1.labelIndex===r.labelIndex)return !0}catch(t){return e.error("Error comparing opened labels",t),true}return false}clear(){i._stepsInfoHistory.clear(),i._diffHistory.clear(),i._narrationHistory.clear(),i._originalStepData=void 0;}get stepLimitSaved(){return i.stepLimitSaved}set stepLimitSaved(e){i.stepLimitSaved=e;}export(){let e=Array.from(this.keys()).sort((t,n)=>t-n);e.length>this.stepLimitSaved&&(e=e.slice(e.length-this.stepLimitSaved));let r=[];return e.forEach(t=>{let n=i._stepsInfoHistory.get(t);if(n){let a=i._diffHistory.get(t);r.push({...n,diff:a});}}),{stepsHistory:f(r),originalStepData:f(i._originalStepData)}}restoreNarrativeHistory(){let e=Array.from(this.keys()).sort((t,n)=>t-n),r={};e.forEach(t=>{let n=i._stepsInfoHistory.get(t);if(n){let a={...r};r={};let c=this.itemMapper({step:n,choiceIndexMade:a.choiceIndexMade,inputValue:a.inputValue,removeDialogue:a.removeDialogue},r);c&&i._narrationHistory.set(t,c);}});}async restore(e$1){this.clear();try{Object.hasOwn(e$1,"stepsHistory")?(e$1.stepsHistory.forEach(t=>{t.diff&&i._diffHistory.set(t.index,t.diff);let n={...t,diff:void 0};i._stepsInfoHistory.set(t.index,n);}),this.restoreNarrativeHistory()):e.warn("Could not import stepsHistory data, so will be ignored"),Object.hasOwn(e$1,"originalStepData")?i._originalStepData=e$1.originalStepData:e.warn("Could not import originalStepData data, so will be ignored");}catch(r){e.error("Error importing data",r);}}};var j=new b;export{i as HistoryManagerStatic,j as stepHistory};
1
+ import'./chunk-JMOSOAGB.mjs';import {q,r,n,p}from'./chunk-U5BSF6X3.mjs';import {GameUnifier}from'@drincs/pixi-vn/core';import {restoreDiffMaybeOffloaded,diffMaybeOffloaded,cloneMaybeOffloaded}from'@drincs/pixi-vn/worker';var i=class g{static _diffHistory=new q({cacheSize:5});static _stepsInfoHistory=new q({cacheSize:5});static _narrationHistory=new q({cacheSize:50});static stepLimitSaved=20;static goBackMode="step";static _originalStepData=void 0;static get originalStepData(){return g._originalStepData?g._originalStepData:{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{}},labelIndex:-1,openedLabels:[]}}static set originalStepData(e){g._originalStepData=e;}};var m=class{get stepsInfoMap(){return i._stepsInfoHistory}get diffMap(){return i._diffHistory}get narrationMap(){return i._narrationHistory}get size(){return i._stepsInfoHistory.size}get lastKey(){if(this.size===0)return null;let e=null;for(let r of this.keys())(e===null||r>e)&&(e=r);return e}get lastDiffKey(){let e=null;for(let r of i._diffHistory.keys())(e===null||r>e)&&(e=r);return e}get goBackMode(){return i.goBackMode}set goBackMode(e){i.goBackMode=e;}keys(){return i._stepsInfoHistory.keys()}get(e){let r=i._narrationHistory.get(e);if(!(r&&Object.keys(r).length===1&&r.stepIndex!==void 0))return r}delete(e){i._stepsInfoHistory.delete(e),i._diffHistory.delete(e),i._narrationHistory.delete(e);}deleteFromKeyOnward(e){Array.from(this.keys()).filter(r=>r>=e).forEach(r=>{this.delete(r);});}previousCheckpointKey(e){let r=0;for(let t of i._diffHistory.keys())t<e&&t>r&&(r=t);return r}pendingInputRestoreValue;findPreviousInputAnswer(e){if(i._stepsInfoHistory.get(e-1)?.isRequiredInput)return i._stepsInfoHistory.get(e)?.inputValue}async getOldGameState(e,r$1){if(e<=0||this.size===0)return r$1;let t=this.lastDiffKey;if(typeof t!="number")return r.warn("You can't go back, there is no step to go back"),r$1;let n=i._diffHistory.get(t);if(n)try{let s=await restoreDiffMaybeOffloaded(r$1,n),a=this.previousCheckpointKey(t)+1;return GameUnifier.stepCounter=a,e===1&&(this.pendingInputRestoreValue=this.findPreviousInputAnswer(a)),this.deleteFromKeyOnward(a),this.getOldGameState(e-1,s)}catch(s){return r.error("Error applying diff",s),r$1}else return r.warn("No diff found for the last step, cannot go back"),r$1}async back(e,r$1={}){let{steps:t=1}=r$1;if(!Number.isFinite(t)){r.warn(`[back] The parameter steps must be a valid finite number, received: ${t}`);return}if(t<=0){r.warn(`[back] The parameter steps must be greater than 0, received: ${t}`);return}if(GameUnifier.runningStepsCount>0){GameUnifier.increaseBackRequest(t);return}if(i._diffHistory.size<1){r.warn("You can't go back, there is no step to go back");return}GameUnifier.runningStepsCount++;try{this.pendingInputRestoreValue=void 0;let n$1=await this.getOldGameState(t,i.originalStepData);if(n$1){await GameUnifier.restoreGameStepState(n$1,GameUnifier.navigate),this.pendingInputRestoreValue!==void 0&&GameUnifier.setVariable(n,p.CURRENT_INPUT_VALUE_MEMORY_KEY,this.pendingInputRestoreValue);let s=GameUnifier.stepCounter-1,a=i._stepsInfoHistory.get(s),o=i._narrationHistory.get(s),c=o&&Object.keys(o).length===1&&o.stepIndex!==void 0;if(a&&(c||a.isRequiredInput)){let p=this.itemMapper({step:a,inputValue:a.isRequiredInput?this.pendingInputRestoreValue:void 0});i._narrationHistory.set(a.index,p);}}else r.error("Error going back");i.originalStepData=n$1;}catch(n){r.error("Error going back",n);}if(GameUnifier.runningStepsCount--,GameUnifier.runningStepsCount===0&&GameUnifier.backRequestsCount!==0)return await GameUnifier.processNavigationRequests(e)}isCheckpointStep(e,r){if(i.goBackMode==="step"||e.choices&&e.choices.length>0||e.isRequiredInput)return true;let t=e.openedLabels??[],n=r?.openedLabels??[];return t.length!==n.length?true:t.some((s,a)=>s.label!==n[a]?.label)}async add(e,r$1={}){let t=i.originalStepData,{ignoreSameStep:n}=r$1,s=await GameUnifier.currentGameStepState;if(!n&&this.isSameStep(t,s))return;let a=this.lastKey,o=typeof a=="number"?i._stepsInfoHistory.get(a):void 0,c=e.index===0||this.isCheckpointStep(e,o);try{let p=typeof a=="number"?i._narrationHistory.get(a):void 0;i._stepsInfoHistory.set(e.index,e);let u={},y=this.itemMapper({step:e},u);if(i._narrationHistory.set(e.index,y),o&&p&&typeof a=="number"){let d=this.itemMapper({...u,step:o},{});i._narrationHistory.set(a,d);}}catch(p){r.error("Error adding history step",p);}e.index!==0&&c&&(async()=>{try{let p=await diffMaybeOffloaded(t,s);p?i._diffHistory.set(e.index,p):r.warn("It was not possible to create the difference between the two steps");}catch(p){r.error("Error adding history step",p);}})(),(e.index===0||c)&&(i.originalStepData=s);}itemMapper(e,r){let{step:t,choiceIndexMade:n,inputValue:s,removeDialogue:a}=e,o=t.dialogue;r&&t.isGlued&&(r.removeDialogue=true),a&&(o=void 0);let c=t.choices;if(r&&t.currentLabel&&t.choiceIndexMade!==void 0&&(r.choiceIndexMade=t.choiceIndexMade),t.inputValue&&r&&(r.inputValue=t.inputValue),o||c||s){let p=c?.map((u,y)=>{let d=false;return u.oneTime&&t.alreadyMadeChoices?.includes(y)&&(d=true),{text:u.text,type:u.type,isResponse:false,hidden:d}});if(p){if(p.every(u=>u.hidden)){let u=p.find(y=>y.hidden===false);u&&(u.hidden=false);}n!==void 0&&(p[n].isResponse=true);}return {dialogue:o?{...o,character:o.character?GameUnifier.getCharacter(o.character)||o.character:void 0}:void 0,playerMadeChoice:typeof n=="number",choices:p,stepIndex:t.index,inputValue:s,openedLabelsNumber:t.openedLabels?.length}}return {stepIndex:t.index}}get narrativeHistory(){let e=[];return Array.from(this.keys()).sort((t,n)=>t-n).forEach(t=>{let n=this.get(t);n&&e.push(n);}),e}get currentLabelHistory(){let e=[],r=Array.from(this.keys()).sort((c,p)=>p-c);if(r.length===0)return e;let t=r[0];if(typeof t!="number")return e;let n=i._stepsInfoHistory.get(t);if(!n)return e;let s=n.openedLabels;if(!s||!Array.isArray(s)||s.length===0)return e;let a=s[0].currentStepIndex,o=s[0].label;return r.every((c,p)=>{let u=this.get(c);if(u){if(p===0)return e.push(u),true;let y=i._stepsInfoHistory.get(c);if(!y)return true;let d=y.openedLabels;if(!d||!Array.isArray(d)||d.length===0||d[0].label!==o||d[0].currentStepIndex>a)return false;a=d[0].currentStepIndex,e.push(u);}return true}),e.reverse()}get currentPageParagraphs(){let e=[],r;return this.currentLabelHistory.forEach(t=>{e.length===0||t.openedLabelsNumber!==r?e.push([t]):e[e.length-1].push(t),r=t.openedLabelsNumber;}),e}removeNarrativeHistory(e){if(e){let r=Array.from(this.keys()).sort((t,n)=>t-n);r=r.slice(0,e),r.forEach(t=>{i._narrationHistory.delete(t),i._stepsInfoHistory.delete(t),i._diffHistory.delete(t);});}else i._stepsInfoHistory.clear(),i._diffHistory.clear(),i._narrationHistory.clear();}get canGoBack(){return i._diffHistory.size>0}blockGoBack(){GameUnifier.runningStepsCount===0&&i._diffHistory.clear();}isSameStep(e,r$1){if(e.openedLabels.length===r$1.openedLabels.length)try{let t=JSON.stringify(e.openedLabels),n=JSON.stringify(r$1.openedLabels);if(t===n&&e.path===r$1.path&&e.labelIndex===r$1.labelIndex)return !0}catch(t){return r.error("Error comparing opened labels",t),true}return false}clear(){i._stepsInfoHistory.clear(),i._diffHistory.clear(),i._narrationHistory.clear(),i._originalStepData=void 0;}get stepLimitSaved(){return i.stepLimitSaved}set stepLimitSaved(e){i.stepLimitSaved=e;}async export(){let e=Array.from(this.keys()).sort((a,o)=>a-o);e.length>this.stepLimitSaved&&(e=e.slice(e.length-this.stepLimitSaved));let r=[];e.forEach(a=>{let o=i._stepsInfoHistory.get(a);if(o){let c=i._diffHistory.get(a);r.push({...o,diff:c});}});let t=i._originalStepData,[n,s]=await Promise.all([cloneMaybeOffloaded(r),t?cloneMaybeOffloaded(t):void 0]);return {stepsHistory:n,originalStepData:s}}restoreNarrativeHistory(){let e=Array.from(this.keys()).sort((t,n)=>t-n),r={};e.forEach(t=>{let n=i._stepsInfoHistory.get(t);if(n){let s={...r};r={};let a=this.itemMapper({step:n,choiceIndexMade:s.choiceIndexMade,inputValue:s.inputValue,removeDialogue:s.removeDialogue},r);a&&i._narrationHistory.set(t,a);}});}async restore(e){this.clear();try{Object.hasOwn(e,"stepsHistory")?(e.stepsHistory.forEach(t=>{t.diff&&i._diffHistory.set(t.index,t.diff);let n={...t,diff:void 0};i._stepsInfoHistory.set(t.index,n);}),this.restoreNarrativeHistory()):r.warn("Could not import stepsHistory data, so will be ignored"),Object.hasOwn(e,"originalStepData")?i._originalStepData=e.originalStepData:r.warn("Could not import originalStepData data, so will be ignored");}catch(r$1){r.error("Error importing data",r$1);}}};var N=new m;export{i as HistoryManagerStatic,N as stepHistory};