@drincs/pixi-vn 1.8.24 → 1.8.25

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.
@@ -26,6 +26,15 @@ interface NarrationHistory {
26
26
  * The input value of the player
27
27
  */
28
28
  inputValue?: StorageElementType;
29
+ /**
30
+ * The number of labels that were opened (via {@link NarrationManagerInterface.call} or {@link NarrationManagerInterface.jump}) when this step ran.
31
+ *
32
+ * This is the size of the label call-stack at this step, and can be used to split a page into paragraphs:
33
+ * every time this number increases compared to the previous step, a `call` opened a new paragraph. A `jump`
34
+ * instead starts a whole new page, so it is already reflected by {@link HistoryManagerInterface.currentLabelHistory}
35
+ * starting over.
36
+ */
37
+ openedLabelsNumber?: number;
29
38
  }
30
39
 
31
40
  /**
@@ -26,6 +26,15 @@ interface NarrationHistory {
26
26
  * The input value of the player
27
27
  */
28
28
  inputValue?: StorageElementType;
29
+ /**
30
+ * The number of labels that were opened (via {@link NarrationManagerInterface.call} or {@link NarrationManagerInterface.jump}) when this step ran.
31
+ *
32
+ * This is the size of the label call-stack at this step, and can be used to split a page into paragraphs:
33
+ * every time this number increases compared to the previous step, a `call` opened a new paragraph. A `jump`
34
+ * instead starts a whole new page, so it is already reflected by {@link HistoryManagerInterface.currentLabelHistory}
35
+ * starting over.
36
+ */
37
+ openedLabelsNumber?: number;
29
38
  }
30
39
 
31
40
  /**
package/dist/history.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var core=require('@drincs/pixi-vn/core');var Yt=Object.defineProperty;var Wt=c=>{throw TypeError(c)};var Xt=(c,t,i)=>t in c?Yt(c,t,{enumerable:true,configurable:true,writable:true,value:i}):c[t]=i;var D=(c,t,i)=>Xt(c,typeof t!="symbol"?t+"":t,i),Mt=(c,t,i)=>t.has(c)||Wt("Cannot "+i);var e=(c,t,i)=>(Mt(c,t,"read from private field"),i?i.call(c):t.get(c)),b=(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),u=(c,t,i,s)=>(Mt(c,t,"write to private field"),t.set(c,i),i),f=(c,t,i)=>(Mt(c,t,"access private method"),i);var Ot=(c,t,i,s)=>({set _(r){u(c,t,r);},get _(){return e(c,t,s)}});var Qt=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Kt=new Set,Gt=typeof process=="object"&&process?process:{},Pt=(c,t,i,s)=>{typeof Gt.emitWarning=="function"?Gt.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=Gt.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 Zt=c=>!Kt.has(c);var rt=c=>c&&c===Math.floor(c)&&c>0&&isFinite(c),$t=c=>rt(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,gt,te=(et=class{heap;length;static create(t){let i=$t(t);if(!i)return [];u(et,gt,true);let s=new et(t,i);return u(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,b(et,gt,false),et),Vt,Ut,P,k,$,ct,B,mt,St,q,T,J,E,x,y,G,W,z,F,Y,C,X,Q,j,V,Z,ht,N,bt,l,Nt,ft,st,Ht,U,qt,ut,vt,At,ot,nt,Rt,Ft,Ct,_,Lt,xt,at,kt,wt,Bt=(wt=class{constructor(t){b(this,l);b(this,P);b(this,k);b(this,$);b(this,ct);b(this,B);b(this,mt);b(this,St);b(this,q);D(this,"ttl");D(this,"ttlResolution");D(this,"ttlAutopurge");D(this,"updateAgeOnGet");D(this,"updateAgeOnHas");D(this,"allowStale");D(this,"noDisposeOnSet");D(this,"noUpdateTTL");D(this,"maxEntrySize");D(this,"sizeCalculation");D(this,"noDeleteOnFetchRejection");D(this,"noDeleteOnStaleGet");D(this,"allowStaleOnFetchAbort");D(this,"allowStaleOnFetchRejection");D(this,"ignoreFetchAbort");b(this,T);b(this,J);b(this,E);b(this,x);b(this,y);b(this,G);b(this,W);b(this,z);b(this,F);b(this,Y);b(this,C);b(this,X);b(this,Q);b(this,j);b(this,V);b(this,Z);b(this,ht);b(this,N);b(this,bt);b(this,ft,()=>{});b(this,st,()=>{});b(this,Ht,()=>{});b(this,U,()=>false);b(this,ut,t=>{});b(this,vt,(t,i,s)=>{});b(this,At,(t,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});D(this,Vt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:n,updateAgeOnHas:a,allowStale:h,dispose:d,onInsert:g,disposeAfter:m,noDisposeOnSet:v,noUpdateTTL:K,maxSize:tt=0,maxEntrySize:H=0,sizeCalculation:w,fetchMethod:S,memoMethod:I,noDeleteOnFetchRejection:R,noDeleteOnStaleGet:M,allowStaleOnFetchRejection:A,allowStaleOnFetchAbort:_t,ignoreFetchAbort:pt,perf:dt}=t;if(dt!==void 0&&typeof dt?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(u(this,q,dt??Qt),i!==0&&!rt(i))throw new TypeError("max option must be a nonnegative integer");let yt=i?$t(i):Array;if(!yt)throw new Error("invalid max value: "+i);if(u(this,P,i),u(this,k,tt),this.maxEntrySize=H||e(this,k),this.sizeCalculation=w,this.sizeCalculation){if(!e(this,k)&&!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(I!==void 0&&typeof I!="function")throw new TypeError("memoMethod must be a function if defined");if(u(this,St,I),S!==void 0&&typeof S!="function")throw new TypeError("fetchMethod must be a function if specified");if(u(this,mt,S),u(this,ht,!!S),u(this,E,new Map),u(this,x,new Array(i).fill(void 0)),u(this,y,new Array(i).fill(void 0)),u(this,G,new yt(i)),u(this,W,new yt(i)),u(this,z,0),u(this,F,0),u(this,Y,te.create(i)),u(this,T,0),u(this,J,0),typeof d=="function"&&u(this,$,d),typeof g=="function"&&u(this,ct,g),typeof m=="function"?(u(this,B,m),u(this,C,[])):(u(this,B,void 0),u(this,C,void 0)),u(this,Z,!!e(this,$)),u(this,bt,!!e(this,ct)),u(this,N,!!e(this,B)),this.noDisposeOnSet=!!v,this.noUpdateTTL=!!K,this.noDeleteOnFetchRejection=!!R,this.allowStaleOnFetchRejection=!!A,this.allowStaleOnFetchAbort=!!_t,this.ignoreFetchAbort=!!pt,this.maxEntrySize!==0){if(e(this,k)!==0&&!rt(e(this,k)))throw new TypeError("maxSize must be a positive integer if specified");if(!rt(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=!!M,this.updateAgeOnGet=!!n,this.updateAgeOnHas=!!a,this.ttlResolution=rt(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!rt(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,l,Nt).call(this);}if(e(this,P)===0&&this.ttl===0&&e(this,k)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!e(this,P)&&!e(this,k)){let It="LRU_CACHE_UNBOUNDED";Zt(It)&&(Kt.add(It),Pt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",It,wt));}}get perf(){return e(this,q)}static unsafeExposeInternals(t){return {starts:e(t,Q),ttls:e(t,j),autopurgeTimers:e(t,V),sizes:e(t,X),keyMap:e(t,E),keyList:e(t,x),valList:e(t,y),next:e(t,G),prev:e(t,W),get head(){return e(t,z)},get tail(){return e(t,F)},free:e(t,Y),isBackgroundFetch:i=>{var s;return f(s=t,l,_).call(s,i)},backgroundFetch:(i,s,r,o)=>{var n;return f(n=t,l,Ct).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,ot).call(s,i)},rindexes:i=>{var s;return f(s=t,l,nt).call(s,i)},isStale:i=>{var s;return e(s=t,U).call(s,i)}}}get max(){return e(this,P)}get maxSize(){return e(this,k)}get calculatedSize(){return e(this,J)}get size(){return e(this,T)}get fetchMethod(){return e(this,mt)}get memoMethod(){return e(this,St)}get dispose(){return e(this,$)}get onInsert(){return e(this,ct)}get disposeAfter(){return e(this,B)}getRemainingTTL(t){return e(this,E).has(t)?1/0:0}*entries(){for(let t of f(this,l,ot).call(this))e(this,y)[t]!==void 0&&e(this,x)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield [e(this,x)[t],e(this,y)[t]]);}*rentries(){for(let t of f(this,l,nt).call(this))e(this,y)[t]!==void 0&&e(this,x)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield [e(this,x)[t],e(this,y)[t]]);}*keys(){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,y)[t])&&(yield i);}}*rkeys(){for(let t of f(this,l,nt).call(this)){let i=e(this,x)[t];i!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield i);}}*values(){for(let t of f(this,l,ot).call(this))e(this,y)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield e(this,y)[t]);}*rvalues(){for(let t of f(this,l,nt).call(this))e(this,y)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield e(this,y)[t]);}[(Ut=Symbol.iterator,Vt=Symbol.toStringTag,Ut)](){return this.entries()}find(t,i={}){for(let s of f(this,l,ot).call(this)){let r=e(this,y)[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,ot).call(this)){let r=e(this,y)[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,nt).call(this)){let r=e(this,y)[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,nt).call(this,{allowStale:true}))e(this,U).call(this,i)&&(f(this,l,at).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,y)[i],r=f(this,l,_).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(e(this,j)&&e(this,Q)){let n=e(this,j)[i],a=e(this,Q)[i];if(n&&a){let h=n-(e(this,q).now()-a);o.ttl=h,o.start=Date.now();}}return e(this,X)&&(o.size=e(this,X)[i]),o}dump(){let t=[];for(let i of f(this,l,ot).call(this,{allowStale:true})){let s=e(this,x)[i],r=e(this,y)[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,j)&&e(this,Q)){n.ttl=e(this,j)[i];let a=e(this,q).now()-e(this,Q)[i];n.start=Math.floor(Date.now()-a);}e(this,X)&&(n.size=e(this,X)[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 v,K,tt,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,g=e(this,At).call(this,t,i,s.size||0,a);if(this.maxEntrySize&&g>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),f(this,l,at).call(this,t,"set"),this;let m=e(this,T)===0?void 0:e(this,E).get(t);if(m===void 0)m=e(this,T)===0?e(this,F):e(this,Y).length!==0?e(this,Y).pop():e(this,T)===e(this,P)?f(this,l,Ft).call(this,false):e(this,T),e(this,x)[m]=t,e(this,y)[m]=i,e(this,E).set(t,m),e(this,G)[e(this,F)]=m,e(this,W)[m]=e(this,F),u(this,F,m),Ot(this,T)._++,e(this,vt).call(this,m,g,h),h&&(h.set="add"),d=false,e(this,bt)&&((v=e(this,ct))==null||v.call(this,i,t,"add"));else {f(this,l,xt).call(this,m);let w=e(this,y)[m];if(i!==w){if(e(this,ht)&&f(this,l,_).call(this,w)){w.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:S}=w;S!==void 0&&!n&&(e(this,Z)&&((K=e(this,$))==null||K.call(this,S,t,"set")),e(this,N)&&e(this,C)?.push([S,t,"set"]));}else n||(e(this,Z)&&((tt=e(this,$))==null||tt.call(this,w,t,"set")),e(this,N)&&e(this,C)?.push([w,t,"set"]));if(e(this,ut).call(this,m),e(this,vt).call(this,m,g,h),e(this,y)[m]=i,h){h.set="replace";let S=w&&f(this,l,_).call(this,w)?w.__staleWhileFetching:w;S!==void 0&&(h.oldValue=S);}}else h&&(h.set="update");e(this,bt)&&this.onInsert?.(i,t,i===w?"update":"replace");}if(r!==0&&!e(this,j)&&f(this,l,Nt).call(this),e(this,j)&&(d||e(this,Ht).call(this,m,r,o),h&&e(this,st).call(this,h,m)),!n&&e(this,N)&&e(this,C)){let w=e(this,C),S;for(;S=w?.shift();)(H=e(this,B))==null||H.call(this,...S);}return this}pop(){var t;try{for(;e(this,T);){let i=e(this,y)[e(this,z)];if(f(this,l,Ft).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,N)&&e(this,C)){let i=e(this,C),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,E).get(t);if(o!==void 0){let n=e(this,y)[o];if(f(this,l,_).call(this,n)&&n.__staleWhileFetching===void 0)return false;if(e(this,U).call(this,o))r&&(r.has="stale",e(this,st).call(this,r,o));else return s&&e(this,ft).call(this,o),r&&(r.has="hit",e(this,st).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,U).call(this,r))return;let o=e(this,y)[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:g=this.noUpdateTTL,noDeleteOnFetchRejection:m=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:v=this.allowStaleOnFetchRejection,ignoreFetchAbort:K=this.ignoreFetchAbort,allowStaleOnFetchAbort:tt=this.allowStaleOnFetchAbort,context:H,forceRefresh:w=false,status:S,signal:I}=i;if(!e(this,ht))return S&&(S.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:S});let R={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:n,noDisposeOnSet:a,size:h,sizeCalculation:d,noUpdateTTL:g,noDeleteOnFetchRejection:m,allowStaleOnFetchRejection:v,allowStaleOnFetchAbort:tt,ignoreFetchAbort:K,status:S,signal:I},M=e(this,E).get(t);if(M===void 0){S&&(S.fetch="miss");let A=f(this,l,Ct).call(this,t,M,R,H);return A.__returned=A}else {let A=e(this,y)[M];if(f(this,l,_).call(this,A)){let yt=s&&A.__staleWhileFetching!==void 0;return S&&(S.fetch="inflight",yt&&(S.returnedStale=true)),yt?A.__staleWhileFetching:A.__returned=A}let _t=e(this,U).call(this,M);if(!w&&!_t)return S&&(S.fetch="hit"),f(this,l,xt).call(this,M),r&&e(this,ft).call(this,M),S&&e(this,st).call(this,S,M),A;let pt=f(this,l,Ct).call(this,t,M,R,H),dt=pt.__staleWhileFetching!==void 0&&s;return S&&(S.fetch=_t?"stale":"refresh",dt&&_t&&(S.returnedStale=true)),dt?pt.__staleWhileFetching:pt.__returned=pt}}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,St);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,y)[a],d=f(this,l,_).call(this,h);return n&&e(this,st).call(this,n,a),e(this,U).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,at).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,ft).call(this,a),h))}else n&&(n.get="miss");}delete(t){return f(this,l,at).call(this,t,"delete")}clear(){return f(this,l,kt).call(this,"delete")}},P=new WeakMap,k=new WeakMap,$=new WeakMap,ct=new WeakMap,B=new WeakMap,mt=new WeakMap,St=new WeakMap,q=new WeakMap,T=new WeakMap,J=new WeakMap,E=new WeakMap,x=new WeakMap,y=new WeakMap,G=new WeakMap,W=new WeakMap,z=new WeakMap,F=new WeakMap,Y=new WeakMap,C=new WeakMap,X=new WeakMap,Q=new WeakMap,j=new WeakMap,V=new WeakMap,Z=new WeakMap,ht=new WeakMap,N=new WeakMap,bt=new WeakMap,l=new WeakSet,Nt=function(){let t=new Tt(e(this,P)),i=new Tt(e(this,P));u(this,j,t),u(this,Q,i);let s=this.ttlAutopurge?new Array(e(this,P)):void 0;u(this,V,s),u(this,Ht,(a,h,d=e(this,q).now())=>{i[a]=h!==0?d:0,t[a]=h,r(a,h);}),u(this,ft,a=>{i[a]=t[a]!==0?e(this,q).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,U).call(this,a)&&f(this,l,at).call(this,e(this,x)[a],"expire");},h+1);d.unref&&d.unref(),s[a]=d;}}:()=>{};u(this,st,(a,h)=>{if(t[h]){let d=t[h],g=i[h];if(!d||!g)return;a.ttl=d,a.start=g,a.now=o||n();let m=a.now-g;a.remainingTTL=d-m;}});let o=0,n=()=>{let a=e(this,q).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],g=i[h];if(!d||!g)return 1/0;let m=(o||n())-g;return d-m},u(this,U,a=>{let h=i[a],d=t[a];return !!d&&!!h&&(o||n())-h>d});},ft=new WeakMap,st=new WeakMap,Ht=new WeakMap,U=new WeakMap,qt=function(){let t=new Tt(e(this,P));u(this,J,0),u(this,X,t),u(this,ut,i=>{u(this,J,e(this,J)-t[i]),t[i]=0;}),u(this,At,(i,s,r,o)=>{if(f(this,l,_).call(this,s))return 0;if(!rt(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,i),!rt(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}),u(this,vt,(i,s,r)=>{if(t[i]=s,e(this,k)){let o=e(this,k)-t[i];for(;e(this,J)>o;)f(this,l,Ft).call(this,true);}u(this,J,e(this,J)+t[i]),r&&(r.entrySize=s,r.totalCalculatedSize=e(this,J));});},ut=new WeakMap,vt=new WeakMap,At=new WeakMap,ot=function*({allowStale:t=this.allowStale}={}){if(e(this,T))for(let i=e(this,F);!(!f(this,l,Rt).call(this,i)||((t||!e(this,U).call(this,i))&&(yield i),i===e(this,z)));)i=e(this,W)[i];},nt=function*({allowStale:t=this.allowStale}={}){if(e(this,T))for(let i=e(this,z);!(!f(this,l,Rt).call(this,i)||((t||!e(this,U).call(this,i))&&(yield i),i===e(this,F)));)i=e(this,G)[i];},Rt=function(t){return t!==void 0&&e(this,E).get(e(this,x)[t])===t},Ft=function(t){var o;let i=e(this,z),s=e(this,x)[i],r=e(this,y)[i];return e(this,ht)&&f(this,l,_).call(this,r)?r.__abortController.abort(new Error("evicted")):(e(this,Z)||e(this,N))&&(e(this,Z)&&((o=e(this,$))==null||o.call(this,r,s,"evict")),e(this,N)&&e(this,C)?.push([r,s,"evict"])),e(this,ut).call(this,i),e(this,V)?.[i]&&(clearTimeout(e(this,V)[i]),e(this,V)[i]=void 0),t&&(e(this,x)[i]=void 0,e(this,y)[i]=void 0,e(this,Y).push(i)),e(this,T)===1?(u(this,z,u(this,F,0)),e(this,Y).length=0):u(this,z,e(this,G)[i]),e(this,E).delete(s),Ot(this,T)._--,i},Ct=function(t,i,s,r){let o=i===void 0?void 0:e(this,y)[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:S}=n.signal,I=s.ignoreFetchAbort&&H!==void 0,R=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&H!==void 0);if(s.status&&(S&&!w?(s.status.fetchAborted=true,s.status.fetchError=n.signal.reason,I&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),S&&!I&&!w)return m(n.signal.reason,R);let M=K,A=e(this,y)[i];return (A===K||I&&w&&A===void 0)&&(H===void 0?M.__staleWhileFetching!==void 0?e(this,y)[i]=M.__staleWhileFetching:f(this,l,at).call(this,t,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(t,H,h.options))),H},g=H=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=H),m(H,false)),m=(H,w)=>{let{aborted:S}=n.signal,I=S&&s.allowStaleOnFetchAbort,R=I||s.allowStaleOnFetchRejection,M=R||s.noDeleteOnFetchRejection,A=K;if(e(this,y)[i]===K&&(!M||!w&&A.__staleWhileFetching===void 0?f(this,l,at).call(this,t,"fetch"):I||(e(this,y)[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 I;let S=(I=e(this,mt))==null?void 0:I.call(this,t,o,h);S&&S instanceof Promise&&S.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 K=new Promise(v).then(d,g),tt=Object.assign(K,{__abortController:n,__staleWhileFetching:o,__returned:void 0});return i===void 0?(this.set(t,tt,{...h.options,status:void 0}),i=e(this,E).get(t)):e(this,y)[i]=tt,tt},_=function(t){if(!e(this,ht))return false;let i=t;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Dt},Lt=function(t,i){e(this,W)[i]=t,e(this,G)[t]=i;},xt=function(t){t!==e(this,F)&&(t===e(this,z)?u(this,z,e(this,G)[t]):f(this,l,Lt).call(this,e(this,W)[t],e(this,G)[t]),f(this,l,Lt).call(this,e(this,F),t),u(this,F,t));},at=function(t,i){var r,o;let s=false;if(e(this,T)!==0){let n=e(this,E).get(t);if(n!==void 0)if(e(this,V)?.[n]&&(clearTimeout(e(this,V)?.[n]),e(this,V)[n]=void 0),s=true,e(this,T)===1)f(this,l,kt).call(this,i);else {e(this,ut).call(this,n);let a=e(this,y)[n];if(f(this,l,_).call(this,a)?a.__abortController.abort(new Error("deleted")):(e(this,Z)||e(this,N))&&(e(this,Z)&&((r=e(this,$))==null||r.call(this,a,t,i)),e(this,N)&&e(this,C)?.push([a,t,i])),e(this,E).delete(t),e(this,x)[n]=void 0,e(this,y)[n]=void 0,n===e(this,F))u(this,F,e(this,W)[n]);else if(n===e(this,z))u(this,z,e(this,G)[n]);else {let h=e(this,W)[n];e(this,G)[h]=e(this,G)[n];let d=e(this,G)[n];e(this,W)[d]=e(this,W)[n];}Ot(this,T)._--,e(this,Y).push(n);}}if(e(this,N)&&e(this,C)?.length){let n=e(this,C),a;for(;a=n?.shift();)(o=e(this,B))==null||o.call(this,...a);}return s},kt=function(t){var i,s;for(let r of f(this,l,nt).call(this,{allowStale:true})){let o=e(this,y)[r];if(f(this,l,_).call(this,o))o.__abortController.abort(new Error("deleted"));else {let n=e(this,x)[r];e(this,Z)&&((i=e(this,$))==null||i.call(this,o,n,t)),e(this,N)&&e(this,C)?.push([o,n,t]);}}if(e(this,E).clear(),e(this,y).fill(void 0),e(this,x).fill(void 0),e(this,j)&&e(this,Q)){e(this,j).fill(0),e(this,Q).fill(0);for(let r of e(this,V)??[])r!==void 0&&clearTimeout(r);e(this,V)?.fill(void 0);}if(e(this,X)&&e(this,X).fill(0),u(this,z,0),u(this,F,0),e(this,Y).length=0,u(this,J,0),u(this,T,0),e(this,N)&&e(this,C)){let r=e(this,C),o;for(;o=r?.shift();)(s=e(this,B))==null||s.call(this,...o);}},wt);var lt=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 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 it(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")}}var p=class c{static _diffHistory=new lt({cacheSize:5});static _stepsInfoHistory=new lt({cacheSize:5});static _narrationHistory=new lt({cacheSize:50});static stepLimitSaved=20;static _originalStepData=void 0;static get originalStepData(){return c._originalStepData?it(c._originalStepData):{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{},filters:void 0},labelIndex:-1,openedLabels:[]}}static set originalStepData(t){c._originalStepData=it(t);}};function Jt(c,t){let i=it(c);return t.length>1&&"type"in t[0]&&(t=t.slice().reverse()),t.forEach(s=>{ie(i,s);}),i}function ie(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 se={Date:true,RegExp:true,String:true,Number:true};function zt(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:c[a]});continue}let g=t[a],m=typeof h=="object"&&typeof g=="object"&&Array.isArray(h)===Array.isArray(g);h&&g&&m&&!se[Object.getPrototypeOf(h)?.constructor?.name]&&(!i.cyclesFix||!s.includes(h))?r.push.apply(r,zt(h,g,i,i.cyclesFix?s.concat([h]):[]).map(v=>(v.path.unshift(d),v))):h!==g&&!(Number.isNaN(h)&&Number.isNaN(g))&&!(m&&(isNaN(h)?h+""==g+"":+h==+g))&&r.push({path:[d],type:"CHANGE",value:g,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 p._stepsInfoHistory}get diffMap(){return p._diffHistory}get narrationMap(){return p._narrationHistory}get size(){return p._stepsInfoHistory.size}get lastKey(){return this.size===0?null:Math.max(...Array.from(this.keys()))}keys(){return p._stepsInfoHistory.keys()}get(t){let i=p._narrationHistory.get(t);if(!(i&&Object.keys(i).length===1&&i.stepIndex!==void 0))return i}delete(t){p._stepsInfoHistory.delete(t),p._diffHistory.delete(t),p._narrationHistory.delete(t);}getOldGameState(t,i){if(t<=0||this.size===0)return i;let s=this.lastKey;if(typeof s!="number")return O.warn("You can't go back, there is no step to go back"),i;let r=p._diffHistory.get(s);if(r)try{let o=Jt(i,r);return core.GameUnifier.stepCounter=s,this.delete(s),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(p._diffHistory.size<1){O.warn("You can't go back, there is no step to go back");return}core.GameUnifier.runningStepsCount++;try{let r=it(this.getOldGameState(s,p.originalStepData));if(r){await core.GameUnifier.restoreGameStepState(r,core.GameUnifier.navigate);let o=core.GameUnifier.stepCounter-1,n=p._narrationHistory.get(o);if(n&&Object.keys(n).length===1&&n.stepIndex!==void 0){let a=p._stepsInfoHistory.get(o);if(a){let h=this.itemMapper({step:a});p._narrationHistory.set(a.index,h);}}}else O.error("Error going back");p.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)}add(t,i={}){let s=p.originalStepData,{ignoreSameStep:r}=i,o=core.GameUnifier.currentGameStepState;if(!r&&this.isSameStep(s,o))return;let n=this.lastKey;(async()=>{try{let h,d;if(typeof n=="number"&&(h=p._stepsInfoHistory.get(n),d=p._narrationHistory.get(n)),p._stepsInfoHistory.set(t.index,t),t.index!==0){let v=zt(s,o);v?p._diffHistory.set(t.index,v):O.warn("It was not possible to create the difference between the two steps");}let g={},m=this.itemMapper({step:t},g);if(p._narrationHistory.set(t.index,m),h&&d&&typeof n=="number"){let v=this.itemMapper({...g,step:h},{});p._narrationHistory.set(n,v);}}catch(h){O.error("Error adding history step",h);}})(),p.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((g,m)=>{let v=false;return g.oneTime&&s.alreadyMadeChoices?.includes(m)&&(v=true),{text:g.text,type:g.type,isResponse:false,hidden:v}});if(d){if(d.every(g=>g.hidden)){let g=d.find(m=>m.hidden===false);g&&(g.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}}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=p._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 g=this.get(h);if(g){if(d===0)return t.push(g),true;let m=p._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(g);}return true}),t.reverse()}removeNarrativeHistory(t){if(t){let i=Array.from(this.keys()).sort((s,r)=>s-r);i=i.slice(0,t),i.forEach(s=>{p._narrationHistory.delete(s),p._stepsInfoHistory.delete(s),p._diffHistory.delete(s);});}else p._stepsInfoHistory.clear(),p._diffHistory.clear(),p._narrationHistory.clear();}get canGoBack(){let t=this.lastKey;return typeof t!="number"?false:p._diffHistory.has(t)}blockGoBack(){core.GameUnifier.runningStepsCount===0&&p._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(){p._stepsInfoHistory.clear(),p._diffHistory.clear(),p._narrationHistory.clear(),p._originalStepData=void 0;}get stepLimitSaved(){return p.stepLimitSaved}set stepLimitSaved(t){p.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=p._stepsInfoHistory.get(s);if(r){let o=p._diffHistory.get(s);i.push({...r,diff:o});}}),{stepsHistory:it(i),originalStepData:it(p._originalStepData)}}restoreNarrativeHistory(){let t=Array.from(this.keys()).sort((s,r)=>s-r),i={};t.forEach(s=>{let r=p._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&&p._narrationHistory.set(s,n);}});}async restore(t){this.clear();try{Object.hasOwn(t,"stepsHistory")?(t.stepsHistory.forEach(s=>{s.diff&&p._diffHistory.set(s.index,s.diff);let r={...s,diff:void 0};p._stepsInfoHistory.set(s.index,r);}),this.restoreNarrativeHistory()):O.warn("Could not import stepsHistory data, so will be ignored"),Object.hasOwn(t,"originalStepData")?p._originalStepData=t.originalStepData:O.warn("Could not import originalStepData data, so will be ignored");}catch(i){O.error("Error importing data",i);}}};var Ge=new Et;exports.HistoryManagerStatic=p;exports.stepHistory=Ge;
1
+ 'use strict';var core=require('@drincs/pixi-vn/core');var Yt=Object.defineProperty;var Wt=c=>{throw TypeError(c)};var Xt=(c,t,i)=>t in c?Yt(c,t,{enumerable:true,configurable:true,writable:true,value:i}):c[t]=i;var D=(c,t,i)=>Xt(c,typeof t!="symbol"?t+"":t,i),It=(c,t,i)=>t.has(c)||Wt("Cannot "+i);var e=(c,t,i)=>(It(c,t,"read from private field"),i?i.call(c):t.get(c)),b=(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),u=(c,t,i,s)=>(It(c,t,"write to private field"),t.set(c,i),i),f=(c,t,i)=>(It(c,t,"access private method"),i);var Ot=(c,t,i,s)=>({set _(r){u(c,t,r);},get _(){return e(c,t,s)}});var Qt=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 Zt=c=>!Kt.has(c);var rt=c=>c&&c===Math.floor(c)&&c>0&&isFinite(c),$t=c=>rt(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,gt,te=(et=class{heap;length;static create(t){let i=$t(t);if(!i)return [];u(et,gt,true);let s=new et(t,i);return u(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,b(et,gt,false),et),Vt,Ut,P,k,$,ct,B,mt,St,q,T,J,E,x,y,L,W,z,F,Y,C,X,Q,j,V,Z,ht,M,bt,l,Mt,ft,st,Ht,U,qt,ut,vt,At,ot,nt,Gt,Ft,Ct,_,Rt,xt,at,kt,wt,Bt=(wt=class{constructor(t){b(this,l);b(this,P);b(this,k);b(this,$);b(this,ct);b(this,B);b(this,mt);b(this,St);b(this,q);D(this,"ttl");D(this,"ttlResolution");D(this,"ttlAutopurge");D(this,"updateAgeOnGet");D(this,"updateAgeOnHas");D(this,"allowStale");D(this,"noDisposeOnSet");D(this,"noUpdateTTL");D(this,"maxEntrySize");D(this,"sizeCalculation");D(this,"noDeleteOnFetchRejection");D(this,"noDeleteOnStaleGet");D(this,"allowStaleOnFetchAbort");D(this,"allowStaleOnFetchRejection");D(this,"ignoreFetchAbort");b(this,T);b(this,J);b(this,E);b(this,x);b(this,y);b(this,L);b(this,W);b(this,z);b(this,F);b(this,Y);b(this,C);b(this,X);b(this,Q);b(this,j);b(this,V);b(this,Z);b(this,ht);b(this,M);b(this,bt);b(this,ft,()=>{});b(this,st,()=>{});b(this,Ht,()=>{});b(this,U,()=>false);b(this,ut,t=>{});b(this,vt,(t,i,s)=>{});b(this,At,(t,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});D(this,Vt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:n,updateAgeOnHas:a,allowStale:h,dispose:d,onInsert:g,disposeAfter:m,noDisposeOnSet:v,noUpdateTTL:K,maxSize:tt=0,maxEntrySize:H=0,sizeCalculation:w,fetchMethod:S,memoMethod:N,noDeleteOnFetchRejection:G,noDeleteOnStaleGet:I,allowStaleOnFetchRejection:A,allowStaleOnFetchAbort:_t,ignoreFetchAbort:pt,perf:dt}=t;if(dt!==void 0&&typeof dt?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(u(this,q,dt??Qt),i!==0&&!rt(i))throw new TypeError("max option must be a nonnegative integer");let yt=i?$t(i):Array;if(!yt)throw new Error("invalid max value: "+i);if(u(this,P,i),u(this,k,tt),this.maxEntrySize=H||e(this,k),this.sizeCalculation=w,this.sizeCalculation){if(!e(this,k)&&!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(N!==void 0&&typeof N!="function")throw new TypeError("memoMethod must be a function if defined");if(u(this,St,N),S!==void 0&&typeof S!="function")throw new TypeError("fetchMethod must be a function if specified");if(u(this,mt,S),u(this,ht,!!S),u(this,E,new Map),u(this,x,new Array(i).fill(void 0)),u(this,y,new Array(i).fill(void 0)),u(this,L,new yt(i)),u(this,W,new yt(i)),u(this,z,0),u(this,F,0),u(this,Y,te.create(i)),u(this,T,0),u(this,J,0),typeof d=="function"&&u(this,$,d),typeof g=="function"&&u(this,ct,g),typeof m=="function"?(u(this,B,m),u(this,C,[])):(u(this,B,void 0),u(this,C,void 0)),u(this,Z,!!e(this,$)),u(this,bt,!!e(this,ct)),u(this,M,!!e(this,B)),this.noDisposeOnSet=!!v,this.noUpdateTTL=!!K,this.noDeleteOnFetchRejection=!!G,this.allowStaleOnFetchRejection=!!A,this.allowStaleOnFetchAbort=!!_t,this.ignoreFetchAbort=!!pt,this.maxEntrySize!==0){if(e(this,k)!==0&&!rt(e(this,k)))throw new TypeError("maxSize must be a positive integer if specified");if(!rt(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=!!I,this.updateAgeOnGet=!!n,this.updateAgeOnHas=!!a,this.ttlResolution=rt(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!rt(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,l,Mt).call(this);}if(e(this,P)===0&&this.ttl===0&&e(this,k)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!e(this,P)&&!e(this,k)){let Nt="LRU_CACHE_UNBOUNDED";Zt(Nt)&&(Kt.add(Nt),Pt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Nt,wt));}}get perf(){return e(this,q)}static unsafeExposeInternals(t){return {starts:e(t,Q),ttls:e(t,j),autopurgeTimers:e(t,V),sizes:e(t,X),keyMap:e(t,E),keyList:e(t,x),valList:e(t,y),next:e(t,L),prev:e(t,W),get head(){return e(t,z)},get tail(){return e(t,F)},free:e(t,Y),isBackgroundFetch:i=>{var s;return f(s=t,l,_).call(s,i)},backgroundFetch:(i,s,r,o)=>{var n;return f(n=t,l,Ct).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,ot).call(s,i)},rindexes:i=>{var s;return f(s=t,l,nt).call(s,i)},isStale:i=>{var s;return e(s=t,U).call(s,i)}}}get max(){return e(this,P)}get maxSize(){return e(this,k)}get calculatedSize(){return e(this,J)}get size(){return e(this,T)}get fetchMethod(){return e(this,mt)}get memoMethod(){return e(this,St)}get dispose(){return e(this,$)}get onInsert(){return e(this,ct)}get disposeAfter(){return e(this,B)}getRemainingTTL(t){return e(this,E).has(t)?1/0:0}*entries(){for(let t of f(this,l,ot).call(this))e(this,y)[t]!==void 0&&e(this,x)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield [e(this,x)[t],e(this,y)[t]]);}*rentries(){for(let t of f(this,l,nt).call(this))e(this,y)[t]!==void 0&&e(this,x)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield [e(this,x)[t],e(this,y)[t]]);}*keys(){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,y)[t])&&(yield i);}}*rkeys(){for(let t of f(this,l,nt).call(this)){let i=e(this,x)[t];i!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield i);}}*values(){for(let t of f(this,l,ot).call(this))e(this,y)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield e(this,y)[t]);}*rvalues(){for(let t of f(this,l,nt).call(this))e(this,y)[t]!==void 0&&!f(this,l,_).call(this,e(this,y)[t])&&(yield e(this,y)[t]);}[(Ut=Symbol.iterator,Vt=Symbol.toStringTag,Ut)](){return this.entries()}find(t,i={}){for(let s of f(this,l,ot).call(this)){let r=e(this,y)[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,ot).call(this)){let r=e(this,y)[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,nt).call(this)){let r=e(this,y)[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,nt).call(this,{allowStale:true}))e(this,U).call(this,i)&&(f(this,l,at).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,y)[i],r=f(this,l,_).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(e(this,j)&&e(this,Q)){let n=e(this,j)[i],a=e(this,Q)[i];if(n&&a){let h=n-(e(this,q).now()-a);o.ttl=h,o.start=Date.now();}}return e(this,X)&&(o.size=e(this,X)[i]),o}dump(){let t=[];for(let i of f(this,l,ot).call(this,{allowStale:true})){let s=e(this,x)[i],r=e(this,y)[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,j)&&e(this,Q)){n.ttl=e(this,j)[i];let a=e(this,q).now()-e(this,Q)[i];n.start=Math.floor(Date.now()-a);}e(this,X)&&(n.size=e(this,X)[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 v,K,tt,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,g=e(this,At).call(this,t,i,s.size||0,a);if(this.maxEntrySize&&g>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),f(this,l,at).call(this,t,"set"),this;let m=e(this,T)===0?void 0:e(this,E).get(t);if(m===void 0)m=e(this,T)===0?e(this,F):e(this,Y).length!==0?e(this,Y).pop():e(this,T)===e(this,P)?f(this,l,Ft).call(this,false):e(this,T),e(this,x)[m]=t,e(this,y)[m]=i,e(this,E).set(t,m),e(this,L)[e(this,F)]=m,e(this,W)[m]=e(this,F),u(this,F,m),Ot(this,T)._++,e(this,vt).call(this,m,g,h),h&&(h.set="add"),d=false,e(this,bt)&&((v=e(this,ct))==null||v.call(this,i,t,"add"));else {f(this,l,xt).call(this,m);let w=e(this,y)[m];if(i!==w){if(e(this,ht)&&f(this,l,_).call(this,w)){w.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:S}=w;S!==void 0&&!n&&(e(this,Z)&&((K=e(this,$))==null||K.call(this,S,t,"set")),e(this,M)&&e(this,C)?.push([S,t,"set"]));}else n||(e(this,Z)&&((tt=e(this,$))==null||tt.call(this,w,t,"set")),e(this,M)&&e(this,C)?.push([w,t,"set"]));if(e(this,ut).call(this,m),e(this,vt).call(this,m,g,h),e(this,y)[m]=i,h){h.set="replace";let S=w&&f(this,l,_).call(this,w)?w.__staleWhileFetching:w;S!==void 0&&(h.oldValue=S);}}else h&&(h.set="update");e(this,bt)&&this.onInsert?.(i,t,i===w?"update":"replace");}if(r!==0&&!e(this,j)&&f(this,l,Mt).call(this),e(this,j)&&(d||e(this,Ht).call(this,m,r,o),h&&e(this,st).call(this,h,m)),!n&&e(this,M)&&e(this,C)){let w=e(this,C),S;for(;S=w?.shift();)(H=e(this,B))==null||H.call(this,...S);}return this}pop(){var t;try{for(;e(this,T);){let i=e(this,y)[e(this,z)];if(f(this,l,Ft).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,M)&&e(this,C)){let i=e(this,C),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,E).get(t);if(o!==void 0){let n=e(this,y)[o];if(f(this,l,_).call(this,n)&&n.__staleWhileFetching===void 0)return false;if(e(this,U).call(this,o))r&&(r.has="stale",e(this,st).call(this,r,o));else return s&&e(this,ft).call(this,o),r&&(r.has="hit",e(this,st).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,U).call(this,r))return;let o=e(this,y)[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:g=this.noUpdateTTL,noDeleteOnFetchRejection:m=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:v=this.allowStaleOnFetchRejection,ignoreFetchAbort:K=this.ignoreFetchAbort,allowStaleOnFetchAbort:tt=this.allowStaleOnFetchAbort,context:H,forceRefresh:w=false,status:S,signal:N}=i;if(!e(this,ht))return S&&(S.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:S});let G={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:n,noDisposeOnSet:a,size:h,sizeCalculation:d,noUpdateTTL:g,noDeleteOnFetchRejection:m,allowStaleOnFetchRejection:v,allowStaleOnFetchAbort:tt,ignoreFetchAbort:K,status:S,signal:N},I=e(this,E).get(t);if(I===void 0){S&&(S.fetch="miss");let A=f(this,l,Ct).call(this,t,I,G,H);return A.__returned=A}else {let A=e(this,y)[I];if(f(this,l,_).call(this,A)){let yt=s&&A.__staleWhileFetching!==void 0;return S&&(S.fetch="inflight",yt&&(S.returnedStale=true)),yt?A.__staleWhileFetching:A.__returned=A}let _t=e(this,U).call(this,I);if(!w&&!_t)return S&&(S.fetch="hit"),f(this,l,xt).call(this,I),r&&e(this,ft).call(this,I),S&&e(this,st).call(this,S,I),A;let pt=f(this,l,Ct).call(this,t,I,G,H),dt=pt.__staleWhileFetching!==void 0&&s;return S&&(S.fetch=_t?"stale":"refresh",dt&&_t&&(S.returnedStale=true)),dt?pt.__staleWhileFetching:pt.__returned=pt}}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,St);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,y)[a],d=f(this,l,_).call(this,h);return n&&e(this,st).call(this,n,a),e(this,U).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,at).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,ft).call(this,a),h))}else n&&(n.get="miss");}delete(t){return f(this,l,at).call(this,t,"delete")}clear(){return f(this,l,kt).call(this,"delete")}},P=new WeakMap,k=new WeakMap,$=new WeakMap,ct=new WeakMap,B=new WeakMap,mt=new WeakMap,St=new WeakMap,q=new WeakMap,T=new WeakMap,J=new WeakMap,E=new WeakMap,x=new WeakMap,y=new WeakMap,L=new WeakMap,W=new WeakMap,z=new WeakMap,F=new WeakMap,Y=new WeakMap,C=new WeakMap,X=new WeakMap,Q=new WeakMap,j=new WeakMap,V=new WeakMap,Z=new WeakMap,ht=new WeakMap,M=new WeakMap,bt=new WeakMap,l=new WeakSet,Mt=function(){let t=new Tt(e(this,P)),i=new Tt(e(this,P));u(this,j,t),u(this,Q,i);let s=this.ttlAutopurge?new Array(e(this,P)):void 0;u(this,V,s),u(this,Ht,(a,h,d=e(this,q).now())=>{i[a]=h!==0?d:0,t[a]=h,r(a,h);}),u(this,ft,a=>{i[a]=t[a]!==0?e(this,q).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,U).call(this,a)&&f(this,l,at).call(this,e(this,x)[a],"expire");},h+1);d.unref&&d.unref(),s[a]=d;}}:()=>{};u(this,st,(a,h)=>{if(t[h]){let d=t[h],g=i[h];if(!d||!g)return;a.ttl=d,a.start=g,a.now=o||n();let m=a.now-g;a.remainingTTL=d-m;}});let o=0,n=()=>{let a=e(this,q).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],g=i[h];if(!d||!g)return 1/0;let m=(o||n())-g;return d-m},u(this,U,a=>{let h=i[a],d=t[a];return !!d&&!!h&&(o||n())-h>d});},ft=new WeakMap,st=new WeakMap,Ht=new WeakMap,U=new WeakMap,qt=function(){let t=new Tt(e(this,P));u(this,J,0),u(this,X,t),u(this,ut,i=>{u(this,J,e(this,J)-t[i]),t[i]=0;}),u(this,At,(i,s,r,o)=>{if(f(this,l,_).call(this,s))return 0;if(!rt(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,i),!rt(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}),u(this,vt,(i,s,r)=>{if(t[i]=s,e(this,k)){let o=e(this,k)-t[i];for(;e(this,J)>o;)f(this,l,Ft).call(this,true);}u(this,J,e(this,J)+t[i]),r&&(r.entrySize=s,r.totalCalculatedSize=e(this,J));});},ut=new WeakMap,vt=new WeakMap,At=new WeakMap,ot=function*({allowStale:t=this.allowStale}={}){if(e(this,T))for(let i=e(this,F);!(!f(this,l,Gt).call(this,i)||((t||!e(this,U).call(this,i))&&(yield i),i===e(this,z)));)i=e(this,W)[i];},nt=function*({allowStale:t=this.allowStale}={}){if(e(this,T))for(let i=e(this,z);!(!f(this,l,Gt).call(this,i)||((t||!e(this,U).call(this,i))&&(yield i),i===e(this,F)));)i=e(this,L)[i];},Gt=function(t){return t!==void 0&&e(this,E).get(e(this,x)[t])===t},Ft=function(t){var o;let i=e(this,z),s=e(this,x)[i],r=e(this,y)[i];return e(this,ht)&&f(this,l,_).call(this,r)?r.__abortController.abort(new Error("evicted")):(e(this,Z)||e(this,M))&&(e(this,Z)&&((o=e(this,$))==null||o.call(this,r,s,"evict")),e(this,M)&&e(this,C)?.push([r,s,"evict"])),e(this,ut).call(this,i),e(this,V)?.[i]&&(clearTimeout(e(this,V)[i]),e(this,V)[i]=void 0),t&&(e(this,x)[i]=void 0,e(this,y)[i]=void 0,e(this,Y).push(i)),e(this,T)===1?(u(this,z,u(this,F,0)),e(this,Y).length=0):u(this,z,e(this,L)[i]),e(this,E).delete(s),Ot(this,T)._--,i},Ct=function(t,i,s,r){let o=i===void 0?void 0:e(this,y)[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:S}=n.signal,N=s.ignoreFetchAbort&&H!==void 0,G=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&H!==void 0);if(s.status&&(S&&!w?(s.status.fetchAborted=true,s.status.fetchError=n.signal.reason,N&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),S&&!N&&!w)return m(n.signal.reason,G);let I=K,A=e(this,y)[i];return (A===K||N&&w&&A===void 0)&&(H===void 0?I.__staleWhileFetching!==void 0?e(this,y)[i]=I.__staleWhileFetching:f(this,l,at).call(this,t,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(t,H,h.options))),H},g=H=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=H),m(H,false)),m=(H,w)=>{let{aborted:S}=n.signal,N=S&&s.allowStaleOnFetchAbort,G=N||s.allowStaleOnFetchRejection,I=G||s.noDeleteOnFetchRejection,A=K;if(e(this,y)[i]===K&&(!I||!w&&A.__staleWhileFetching===void 0?f(this,l,at).call(this,t,"fetch"):N||(e(this,y)[i]=A.__staleWhileFetching)),G)return s.status&&A.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),A.__staleWhileFetching;if(A.__returned===A)throw H},v=(H,w)=>{var N;let S=(N=e(this,mt))==null?void 0:N.call(this,t,o,h);S&&S instanceof Promise&&S.then(G=>H(G===void 0?void 0:G),w),n.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(H(void 0),s.allowStaleOnFetchAbort&&(H=G=>d(G,true)));});};s.status&&(s.status.fetchDispatched=true);let K=new Promise(v).then(d,g),tt=Object.assign(K,{__abortController:n,__staleWhileFetching:o,__returned:void 0});return i===void 0?(this.set(t,tt,{...h.options,status:void 0}),i=e(this,E).get(t)):e(this,y)[i]=tt,tt},_=function(t){if(!e(this,ht))return false;let i=t;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Dt},Rt=function(t,i){e(this,W)[i]=t,e(this,L)[t]=i;},xt=function(t){t!==e(this,F)&&(t===e(this,z)?u(this,z,e(this,L)[t]):f(this,l,Rt).call(this,e(this,W)[t],e(this,L)[t]),f(this,l,Rt).call(this,e(this,F),t),u(this,F,t));},at=function(t,i){var r,o;let s=false;if(e(this,T)!==0){let n=e(this,E).get(t);if(n!==void 0)if(e(this,V)?.[n]&&(clearTimeout(e(this,V)?.[n]),e(this,V)[n]=void 0),s=true,e(this,T)===1)f(this,l,kt).call(this,i);else {e(this,ut).call(this,n);let a=e(this,y)[n];if(f(this,l,_).call(this,a)?a.__abortController.abort(new Error("deleted")):(e(this,Z)||e(this,M))&&(e(this,Z)&&((r=e(this,$))==null||r.call(this,a,t,i)),e(this,M)&&e(this,C)?.push([a,t,i])),e(this,E).delete(t),e(this,x)[n]=void 0,e(this,y)[n]=void 0,n===e(this,F))u(this,F,e(this,W)[n]);else if(n===e(this,z))u(this,z,e(this,L)[n]);else {let h=e(this,W)[n];e(this,L)[h]=e(this,L)[n];let d=e(this,L)[n];e(this,W)[d]=e(this,W)[n];}Ot(this,T)._--,e(this,Y).push(n);}}if(e(this,M)&&e(this,C)?.length){let n=e(this,C),a;for(;a=n?.shift();)(o=e(this,B))==null||o.call(this,...a);}return s},kt=function(t){var i,s;for(let r of f(this,l,nt).call(this,{allowStale:true})){let o=e(this,y)[r];if(f(this,l,_).call(this,o))o.__abortController.abort(new Error("deleted"));else {let n=e(this,x)[r];e(this,Z)&&((i=e(this,$))==null||i.call(this,o,n,t)),e(this,M)&&e(this,C)?.push([o,n,t]);}}if(e(this,E).clear(),e(this,y).fill(void 0),e(this,x).fill(void 0),e(this,j)&&e(this,Q)){e(this,j).fill(0),e(this,Q).fill(0);for(let r of e(this,V)??[])r!==void 0&&clearTimeout(r);e(this,V)?.fill(void 0);}if(e(this,X)&&e(this,X).fill(0),u(this,z,0),u(this,F,0),e(this,Y).length=0,u(this,J,0),u(this,T,0),e(this,M)&&e(this,C)){let r=e(this,C),o;for(;o=r?.shift();)(s=e(this,B))==null||s.call(this,...o);}},wt);var lt=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 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 it(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")}}var p=class c{static _diffHistory=new lt({cacheSize:5});static _stepsInfoHistory=new lt({cacheSize:5});static _narrationHistory=new lt({cacheSize:50});static stepLimitSaved=20;static _originalStepData=void 0;static get originalStepData(){return c._originalStepData?it(c._originalStepData):{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{},filters:void 0},labelIndex:-1,openedLabels:[]}}static set originalStepData(t){c._originalStepData=it(t);}};function Jt(c,t){let i=it(c);return t.length>1&&"type"in t[0]&&(t=t.slice().reverse()),t.forEach(s=>{ie(i,s);}),i}function ie(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 se={Date:true,RegExp:true,String:true,Number:true};function zt(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:c[a]});continue}let g=t[a],m=typeof h=="object"&&typeof g=="object"&&Array.isArray(h)===Array.isArray(g);h&&g&&m&&!se[Object.getPrototypeOf(h)?.constructor?.name]&&(!i.cyclesFix||!s.includes(h))?r.push.apply(r,zt(h,g,i,i.cyclesFix?s.concat([h]):[]).map(v=>(v.path.unshift(d),v))):h!==g&&!(Number.isNaN(h)&&Number.isNaN(g))&&!(m&&(isNaN(h)?h+""==g+"":+h==+g))&&r.push({path:[d],type:"CHANGE",value:g,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 p._stepsInfoHistory}get diffMap(){return p._diffHistory}get narrationMap(){return p._narrationHistory}get size(){return p._stepsInfoHistory.size}get lastKey(){return this.size===0?null:Math.max(...Array.from(this.keys()))}keys(){return p._stepsInfoHistory.keys()}get(t){let i=p._narrationHistory.get(t);if(!(i&&Object.keys(i).length===1&&i.stepIndex!==void 0))return i}delete(t){p._stepsInfoHistory.delete(t),p._diffHistory.delete(t),p._narrationHistory.delete(t);}getOldGameState(t,i){if(t<=0||this.size===0)return i;let s=this.lastKey;if(typeof s!="number")return O.warn("You can't go back, there is no step to go back"),i;let r=p._diffHistory.get(s);if(r)try{let o=Jt(i,r);return core.GameUnifier.stepCounter=s,this.delete(s),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(p._diffHistory.size<1){O.warn("You can't go back, there is no step to go back");return}core.GameUnifier.runningStepsCount++;try{let r=it(this.getOldGameState(s,p.originalStepData));if(r){await core.GameUnifier.restoreGameStepState(r,core.GameUnifier.navigate);let o=core.GameUnifier.stepCounter-1,n=p._narrationHistory.get(o);if(n&&Object.keys(n).length===1&&n.stepIndex!==void 0){let a=p._stepsInfoHistory.get(o);if(a){let h=this.itemMapper({step:a});p._narrationHistory.set(a.index,h);}}}else O.error("Error going back");p.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)}add(t,i={}){let s=p.originalStepData,{ignoreSameStep:r}=i,o=core.GameUnifier.currentGameStepState;if(!r&&this.isSameStep(s,o))return;let n=this.lastKey;(async()=>{try{let h,d;if(typeof n=="number"&&(h=p._stepsInfoHistory.get(n),d=p._narrationHistory.get(n)),p._stepsInfoHistory.set(t.index,t),t.index!==0){let v=zt(s,o);v?p._diffHistory.set(t.index,v):O.warn("It was not possible to create the difference between the two steps");}let g={},m=this.itemMapper({step:t},g);if(p._narrationHistory.set(t.index,m),h&&d&&typeof n=="number"){let v=this.itemMapper({...g,step:h},{});p._narrationHistory.set(n,v);}}catch(h){O.error("Error adding history step",h);}})(),p.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((g,m)=>{let v=false;return g.oneTime&&s.alreadyMadeChoices?.includes(m)&&(v=true),{text:g.text,type:g.type,isResponse:false,hidden:v}});if(d){if(d.every(g=>g.hidden)){let g=d.find(m=>m.hidden===false);g&&(g.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=p._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 g=this.get(h);if(g){if(d===0)return t.push(g),true;let m=p._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(g);}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=>{p._narrationHistory.delete(s),p._stepsInfoHistory.delete(s),p._diffHistory.delete(s);});}else p._stepsInfoHistory.clear(),p._diffHistory.clear(),p._narrationHistory.clear();}get canGoBack(){let t=this.lastKey;return typeof t!="number"?false:p._diffHistory.has(t)}blockGoBack(){core.GameUnifier.runningStepsCount===0&&p._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(){p._stepsInfoHistory.clear(),p._diffHistory.clear(),p._narrationHistory.clear(),p._originalStepData=void 0;}get stepLimitSaved(){return p.stepLimitSaved}set stepLimitSaved(t){p.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=p._stepsInfoHistory.get(s);if(r){let o=p._diffHistory.get(s);i.push({...r,diff:o});}}),{stepsHistory:it(i),originalStepData:it(p._originalStepData)}}restoreNarrativeHistory(){let t=Array.from(this.keys()).sort((s,r)=>s-r),i={};t.forEach(s=>{let r=p._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&&p._narrationHistory.set(s,n);}});}async restore(t){this.clear();try{Object.hasOwn(t,"stepsHistory")?(t.stepsHistory.forEach(s=>{s.diff&&p._diffHistory.set(s.index,s.diff);let r={...s,diff:void 0};p._stepsInfoHistory.set(s.index,r);}),this.restoreNarrativeHistory()):O.warn("Could not import stepsHistory data, so will be ignored"),Object.hasOwn(t,"originalStepData")?p._originalStepData=t.originalStepData:O.warn("Could not import originalStepData data, so will be ignored");}catch(i){O.error("Error importing data",i);}}};var Le=new Et;exports.HistoryManagerStatic=p;exports.stepHistory=Le;
@@ -4,7 +4,7 @@ import { C as CachedMap } from './CachedMap-DZLvJAnA.cjs';
4
4
  import { H as HistoryStep } from './HistoryStep-G9dUn0Lf.cjs';
5
5
  import { H as HistoryGameState } from './HistoryGameState-C28NcKKl.cjs';
6
6
  import { S as StepLabelPropsType, a as StepLabelResultType } from './StepLabelType-CN97wZzm.cjs';
7
- import { N as NarrationHistory } from './HistoryChoiceMenuOption-BMsYentw.cjs';
7
+ import { N as NarrationHistory } from './HistoryChoiceMenuOption-DVMD78W7.cjs';
8
8
  import 'lru-cache';
9
9
  import '@drincs/pixi-vn/canvas';
10
10
  import './StorageElementType-C7ETezlL.cjs';
@@ -18,9 +18,22 @@ interface HistoryManagerInterface {
18
18
  /**
19
19
  * Get the history of the latest steps belonging to the current label and its child labels.
20
20
  *
21
+ * This is effectively the current "page" of an interactive book: it starts over every time a
22
+ * {@link NarrationManagerInterface.jump} is performed.
23
+ *
21
24
  * @returns the history of the dialogues, choices and steps
22
25
  */
23
26
  readonly currentLabelHistory: NarrationHistory[];
27
+ /**
28
+ * Get the current page ({@link HistoryManagerInterface.currentLabelHistory}) split into paragraphs.
29
+ *
30
+ * A new paragraph starts every time the number of opened labels changes compared to the previous step
31
+ * (i.e. a {@link NarrationManagerInterface.call} was made, or a called label returned), using
32
+ * {@link NarrationHistory.openedLabelsNumber}.
33
+ *
34
+ * @returns the current page as an ordered list of paragraphs, each one a list of steps
35
+ */
36
+ readonly currentPageParagraphs: NarrationHistory[][];
24
37
  /**
25
38
  * The number of steps to keep in the history into the save file.
26
39
  *
package/dist/history.d.ts CHANGED
@@ -4,7 +4,7 @@ import { C as CachedMap } from './CachedMap-DZLvJAnA.js';
4
4
  import { H as HistoryStep } from './HistoryStep-G9dUn0Lf.js';
5
5
  import { H as HistoryGameState } from './HistoryGameState-CmjUtlkV.js';
6
6
  import { S as StepLabelPropsType, a as StepLabelResultType } from './StepLabelType-CN97wZzm.js';
7
- import { N as NarrationHistory } from './HistoryChoiceMenuOption-DQ-pnuPU.js';
7
+ import { N as NarrationHistory } from './HistoryChoiceMenuOption-B8RfQz5H.js';
8
8
  import 'lru-cache';
9
9
  import '@drincs/pixi-vn/canvas';
10
10
  import './StorageElementType-C7ETezlL.js';
@@ -18,9 +18,22 @@ interface HistoryManagerInterface {
18
18
  /**
19
19
  * Get the history of the latest steps belonging to the current label and its child labels.
20
20
  *
21
+ * This is effectively the current "page" of an interactive book: it starts over every time a
22
+ * {@link NarrationManagerInterface.jump} is performed.
23
+ *
21
24
  * @returns the history of the dialogues, choices and steps
22
25
  */
23
26
  readonly currentLabelHistory: NarrationHistory[];
27
+ /**
28
+ * Get the current page ({@link HistoryManagerInterface.currentLabelHistory}) split into paragraphs.
29
+ *
30
+ * A new paragraph starts every time the number of opened labels changes compared to the previous step
31
+ * (i.e. a {@link NarrationManagerInterface.call} was made, or a called label returned), using
32
+ * {@link NarrationHistory.openedLabelsNumber}.
33
+ *
34
+ * @returns the current page as an ordered list of paragraphs, each one a list of steps
35
+ */
36
+ readonly currentPageParagraphs: NarrationHistory[][];
24
37
  /**
25
38
  * The number of steps to keep in the history into the save file.
26
39
  *
package/dist/history.mjs CHANGED
@@ -1 +1 @@
1
- import'./chunk-JMOSOAGB.mjs';import {d,f,e}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier}from'@drincs/pixi-vn/core';var i=class y{static _diffHistory=new d({cacheSize:5});static _stepsInfoHistory=new d({cacheSize:5});static _narrationHistory=new d({cacheSize:50});static stepLimitSaved=20;static _originalStepData=void 0;static get originalStepData(){return y._originalStepData?f(y._originalStepData):{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{},filters:void 0},labelIndex:-1,openedLabels:[]}}static set originalStepData(e){y._originalStepData=f(e);}};function b(y,e){let r=f(y);return e.length>1&&"type"in e[0]&&(e=e.slice().reverse()),e.forEach(t=>{x(r,t);}),r}function x(y,e$1){let r=y;e$1.path&&e$1.path.length>0?e$1.path.forEach((t,a)=>{if(e$1.path&&a===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 _={Date:true,RegExp:true,String:true,Number:true};function S(y,e,r={cyclesFix:true},t=[]){let a=[],s=Array.isArray(y);for(let o in y){let n=y[o],u=s?+o:o;if(!(o in e)){a.push({type:"REMOVE",path:[u],oldValue:y[o]});continue}let p=e[o],m=typeof n=="object"&&typeof p=="object"&&Array.isArray(n)===Array.isArray(p);n&&p&&m&&!_[Object.getPrototypeOf(n)?.constructor?.name]&&(!r.cyclesFix||!t.includes(n))?a.push.apply(a,S(n,p,r,r.cyclesFix?t.concat([n]):[]).map(f=>(f.path.unshift(u),f))):n!==p&&!(Number.isNaN(n)&&Number.isNaN(p))&&!(m&&(isNaN(n)?n+""==p+"":+n==+p))&&a.push({path:[u],type:"CHANGE",value:p,oldValue:n});}let c=Array.isArray(e);for(let o in e)o in y||a.push({type:"CREATE",path:[c?+o:o],value:e[o]});return a}var h=class{get stepsInfoMap(){return i._stepsInfoHistory}get diffMap(){return i._diffHistory}get narrationMap(){return i._narrationHistory}get size(){return i._stepsInfoHistory.size}get lastKey(){return this.size===0?null:Math.max(...Array.from(this.keys()))}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);}getOldGameState(e$1,r){if(e$1<=0||this.size===0)return r;let t=this.lastKey;if(typeof t!="number")return e.warn("You can't go back, there is no step to go back"),r;let a=i._diffHistory.get(t);if(a)try{let s=b(r,a);return GameUnifier.stepCounter=t,this.delete(t),this.getOldGameState(e$1-1,s)}catch(s){return e.error("Error applying diff",s),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 a=f(this.getOldGameState(t,i.originalStepData));if(a){await GameUnifier.restoreGameStepState(a,GameUnifier.navigate);let s=GameUnifier.stepCounter-1,c=i._narrationHistory.get(s);if(c&&Object.keys(c).length===1&&c.stepIndex!==void 0){let o=i._stepsInfoHistory.get(s);if(o){let n=this.itemMapper({step:o});i._narrationHistory.set(o.index,n);}}}else e.error("Error going back");i.originalStepData=a;}catch(a){e.error("Error going back",a);}if(GameUnifier.runningStepsCount--,GameUnifier.runningStepsCount===0&&GameUnifier.backRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1)}add(e$1,r={}){let t=i.originalStepData,{ignoreSameStep:a}=r,s=GameUnifier.currentGameStepState;if(!a&&this.isSameStep(t,s))return;let c=this.lastKey;(async()=>{try{let n,u;if(typeof c=="number"&&(n=i._stepsInfoHistory.get(c),u=i._narrationHistory.get(c)),i._stepsInfoHistory.set(e$1.index,e$1),e$1.index!==0){let f=S(t,s);f?i._diffHistory.set(e$1.index,f):e.warn("It was not possible to create the difference between the two steps");}let p={},m=this.itemMapper({step:e$1},p);if(i._narrationHistory.set(e$1.index,m),n&&u&&typeof c=="number"){let f=this.itemMapper({...p,step:n},{});i._narrationHistory.set(c,f);}}catch(n){e.error("Error adding history step",n);}})(),i.originalStepData=s;}itemMapper(e,r){let{step:t,choiceIndexMade:a,inputValue:s,removeDialogue:c}=e,o=t.dialogue;r&&t.isGlued&&(r.removeDialogue=true),c&&(o=void 0);let n=t.choices;if(r&&t.currentLabel&&t.choiceIndexMade!==void 0&&(r.choiceIndexMade=t.choiceIndexMade),t.inputValue&&r&&(r.inputValue=t.inputValue),o||n||s){let u=n?.map((p,m)=>{let f=false;return p.oneTime&&t.alreadyMadeChoices?.includes(m)&&(f=true),{text:p.text,type:p.type,isResponse:false,hidden:f}});if(u){if(u.every(p=>p.hidden)){let p=u.find(m=>m.hidden===false);p&&(p.hidden=false);}a!==void 0&&(u[a].isResponse=true);}return {dialogue:o?{...o,character:o.character?GameUnifier.getCharacter(o.character)||o.character:void 0}:void 0,playerMadeChoice:typeof a=="number",choices:u,stepIndex:t.index,inputValue:s}}return {stepIndex:t.index}}get narrativeHistory(){let e=[];return Array.from(this.keys()).sort((t,a)=>t-a).forEach(t=>{let a=this.get(t);a&&e.push(a);}),e}get currentLabelHistory(){let e=[],r=Array.from(this.keys()).sort((n,u)=>u-n);if(r.length===0)return e;let t=r[0];if(typeof t!="number")return e;let a=i._stepsInfoHistory.get(t);if(!a)return e;let s=a.openedLabels;if(!s||!Array.isArray(s)||s.length===0)return e;let c=s[0].currentStepIndex,o=s[0].label;return r.every((n,u)=>{let p=this.get(n);if(p){if(u===0)return e.push(p),true;let m=i._stepsInfoHistory.get(n);if(!m)return true;let f=m.openedLabels;if(!f||!Array.isArray(f)||f.length===0||f[0].label!==o||f[0].currentStepIndex>=c)return false;c=f[0].currentStepIndex,e.push(p);}return true}),e.reverse()}removeNarrativeHistory(e){if(e){let r=Array.from(this.keys()).sort((t,a)=>t-a);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(){let e=this.lastKey;return typeof e!="number"?false:i._diffHistory.has(e)}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),a=JSON.stringify(r.openedLabels);if(t===a&&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,a)=>t-a);e.length>this.stepLimitSaved&&(e=e.slice(e.length-this.stepLimitSaved));let r=[];return e.forEach(t=>{let a=i._stepsInfoHistory.get(t);if(a){let s=i._diffHistory.get(t);r.push({...a,diff:s});}}),{stepsHistory:f(r),originalStepData:f(i._originalStepData)}}restoreNarrativeHistory(){let e=Array.from(this.keys()).sort((t,a)=>t-a),r={};e.forEach(t=>{let a=i._stepsInfoHistory.get(t);if(a){let s={...r};r={};let c=this.itemMapper({step:a,choiceIndexMade:s.choiceIndexMade,inputValue:s.inputValue,removeDialogue:s.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 a={...t,diff:void 0};i._stepsInfoHistory.set(t.index,a);}),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 h;export{i as HistoryManagerStatic,j as stepHistory};
1
+ import'./chunk-JMOSOAGB.mjs';import {d,f,e}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier}from'@drincs/pixi-vn/core';var i=class y{static _diffHistory=new d({cacheSize:5});static _stepsInfoHistory=new d({cacheSize:5});static _narrationHistory=new d({cacheSize:50});static stepLimitSaved=20;static _originalStepData=void 0;static get originalStepData(){return y._originalStepData?f(y._originalStepData):{path:"",storage:{},canvas:{elementAliasesOrder:[],elements:{},stage:{},tickers:{},tickersSteps:{},tickersOnPause:{},tickersToCompleteOnStepEnd:{tikersIds:[],stepAlias:[]}},sound:{soundAliasesOrder:[],soundsPlaying:{},playInStepIndex:{},filters:void 0},labelIndex:-1,openedLabels:[]}}static set originalStepData(e){y._originalStepData=f(e);}};function S(y,e){let r=f(y);return e.length>1&&"type"in e[0]&&(e=e.slice().reverse()),e.forEach(t=>{x(r,t);}),r}function x(y,e$1){let r=y;e$1.path&&e$1.path.length>0?e$1.path.forEach((t,a)=>{if(e$1.path&&a===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 _={Date:true,RegExp:true,String:true,Number:true};function H(y,e,r={cyclesFix:true},t=[]){let a=[],s=Array.isArray(y);for(let o in y){let n=y[o],u=s?+o:o;if(!(o in e)){a.push({type:"REMOVE",path:[u],oldValue:y[o]});continue}let p=e[o],m=typeof n=="object"&&typeof p=="object"&&Array.isArray(n)===Array.isArray(p);n&&p&&m&&!_[Object.getPrototypeOf(n)?.constructor?.name]&&(!r.cyclesFix||!t.includes(n))?a.push.apply(a,H(n,p,r,r.cyclesFix?t.concat([n]):[]).map(f=>(f.path.unshift(u),f))):n!==p&&!(Number.isNaN(n)&&Number.isNaN(p))&&!(m&&(isNaN(n)?n+""==p+"":+n==+p))&&a.push({path:[u],type:"CHANGE",value:p,oldValue:n});}let c=Array.isArray(e);for(let o in e)o in y||a.push({type:"CREATE",path:[c?+o:o],value:e[o]});return a}var h=class{get stepsInfoMap(){return i._stepsInfoHistory}get diffMap(){return i._diffHistory}get narrationMap(){return i._narrationHistory}get size(){return i._stepsInfoHistory.size}get lastKey(){return this.size===0?null:Math.max(...Array.from(this.keys()))}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);}getOldGameState(e$1,r){if(e$1<=0||this.size===0)return r;let t=this.lastKey;if(typeof t!="number")return e.warn("You can't go back, there is no step to go back"),r;let a=i._diffHistory.get(t);if(a)try{let s=S(r,a);return GameUnifier.stepCounter=t,this.delete(t),this.getOldGameState(e$1-1,s)}catch(s){return e.error("Error applying diff",s),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 a=f(this.getOldGameState(t,i.originalStepData));if(a){await GameUnifier.restoreGameStepState(a,GameUnifier.navigate);let s=GameUnifier.stepCounter-1,c=i._narrationHistory.get(s);if(c&&Object.keys(c).length===1&&c.stepIndex!==void 0){let o=i._stepsInfoHistory.get(s);if(o){let n=this.itemMapper({step:o});i._narrationHistory.set(o.index,n);}}}else e.error("Error going back");i.originalStepData=a;}catch(a){e.error("Error going back",a);}if(GameUnifier.runningStepsCount--,GameUnifier.runningStepsCount===0&&GameUnifier.backRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1)}add(e$1,r={}){let t=i.originalStepData,{ignoreSameStep:a}=r,s=GameUnifier.currentGameStepState;if(!a&&this.isSameStep(t,s))return;let c=this.lastKey;(async()=>{try{let n,u;if(typeof c=="number"&&(n=i._stepsInfoHistory.get(c),u=i._narrationHistory.get(c)),i._stepsInfoHistory.set(e$1.index,e$1),e$1.index!==0){let f=H(t,s);f?i._diffHistory.set(e$1.index,f):e.warn("It was not possible to create the difference between the two steps");}let p={},m=this.itemMapper({step:e$1},p);if(i._narrationHistory.set(e$1.index,m),n&&u&&typeof c=="number"){let f=this.itemMapper({...p,step:n},{});i._narrationHistory.set(c,f);}}catch(n){e.error("Error adding history step",n);}})(),i.originalStepData=s;}itemMapper(e,r){let{step:t,choiceIndexMade:a,inputValue:s,removeDialogue:c}=e,o=t.dialogue;r&&t.isGlued&&(r.removeDialogue=true),c&&(o=void 0);let n=t.choices;if(r&&t.currentLabel&&t.choiceIndexMade!==void 0&&(r.choiceIndexMade=t.choiceIndexMade),t.inputValue&&r&&(r.inputValue=t.inputValue),o||n||s){let u=n?.map((p,m)=>{let f=false;return p.oneTime&&t.alreadyMadeChoices?.includes(m)&&(f=true),{text:p.text,type:p.type,isResponse:false,hidden:f}});if(u){if(u.every(p=>p.hidden)){let p=u.find(m=>m.hidden===false);p&&(p.hidden=false);}a!==void 0&&(u[a].isResponse=true);}return {dialogue:o?{...o,character:o.character?GameUnifier.getCharacter(o.character)||o.character:void 0}:void 0,playerMadeChoice:typeof a=="number",choices:u,stepIndex:t.index,inputValue:s,openedLabelsNumber:t.openedLabels?.length}}return {stepIndex:t.index}}get narrativeHistory(){let e=[];return Array.from(this.keys()).sort((t,a)=>t-a).forEach(t=>{let a=this.get(t);a&&e.push(a);}),e}get currentLabelHistory(){let e=[],r=Array.from(this.keys()).sort((n,u)=>u-n);if(r.length===0)return e;let t=r[0];if(typeof t!="number")return e;let a=i._stepsInfoHistory.get(t);if(!a)return e;let s=a.openedLabels;if(!s||!Array.isArray(s)||s.length===0)return e;let c=s[0].currentStepIndex,o=s[0].label;return r.every((n,u)=>{let p=this.get(n);if(p){if(u===0)return e.push(p),true;let m=i._stepsInfoHistory.get(n);if(!m)return true;let f=m.openedLabels;if(!f||!Array.isArray(f)||f.length===0||f[0].label!==o||f[0].currentStepIndex>c)return false;c=f[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,a)=>t-a);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(){let e=this.lastKey;return typeof e!="number"?false:i._diffHistory.has(e)}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),a=JSON.stringify(r.openedLabels);if(t===a&&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,a)=>t-a);e.length>this.stepLimitSaved&&(e=e.slice(e.length-this.stepLimitSaved));let r=[];return e.forEach(t=>{let a=i._stepsInfoHistory.get(t);if(a){let s=i._diffHistory.get(t);r.push({...a,diff:s});}}),{stepsHistory:f(r),originalStepData:f(i._originalStepData)}}restoreNarrativeHistory(){let e=Array.from(this.keys()).sort((t,a)=>t-a),r={};e.forEach(t=>{let a=i._stepsInfoHistory.get(t);if(a){let s={...r};r={};let c=this.itemMapper({step:a,choiceIndexMade:s.choiceIndexMade,inputValue:s.inputValue,removeDialogue:s.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 a={...t,diff:void 0};i._stepsInfoHistory.set(t.index,a);}),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 h;export{i as HistoryManagerStatic,j as stepHistory};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var nt=require('@drincs/pixi-vn/canvas'),Bt=require('@drincs/pixi-vn/characters'),core=require('@drincs/pixi-vn/core'),et=require('@drincs/pixi-vn/history'),L=require('@drincs/pixi-vn/narration'),pt=require('@drincs/pixi-vn/sound'),G=require('@drincs/pixi-vn/storage'),motion=require('@drincs/pixi-vn/motion');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var nt__namespace=/*#__PURE__*/_interopNamespace(nt);var Bt__namespace=/*#__PURE__*/_interopNamespace(Bt);var et__namespace=/*#__PURE__*/_interopNamespace(et);var L__namespace=/*#__PURE__*/_interopNamespace(L);var pt__namespace=/*#__PURE__*/_interopNamespace(pt);var G__namespace=/*#__PURE__*/_interopNamespace(G);var Xt=Object.defineProperty;var Jt=h=>{throw TypeError(h)};var ue=(h,e,i)=>e in h?Xt(h,e,{enumerable:true,configurable:true,writable:true,value:i}):h[e]=i;var fe=(h,e)=>{for(var i in e)Xt(h,i,{get:e[i],enumerable:true});};var C=(h,e,i)=>ue(h,typeof e!="symbol"?e+"":e,i),jt=(h,e,i)=>e.has(h)||Jt("Cannot "+i);var t=(h,e,i)=>(jt(h,e,"read from private field"),i?i.call(h):e.get(h)),_=(h,e,i)=>e.has(h)?Jt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,i),u=(h,e,i,s)=>(jt(h,e,"write to private field"),e.set(h,i),i),d=(h,e,i)=>(jt(h,e,"access private method"),i);var Rt=(h,e,i,s)=>({set _(r){u(h,e,r);},get _(){return t(h,e,s)}});var me=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,ee=new Set,Gt=typeof process=="object"&&process?process:{},ie=(h,e,i,s)=>{typeof Gt.emitWarning=="function"?Gt.emitWarning(h,e,i,s):console.error(`[${i}] ${e}: ${h}`);},Nt=globalThis.AbortController,Qt=globalThis.AbortSignal;if(typeof Nt>"u"){Qt=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},Nt=class{constructor(){e();}signal=new Qt;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 h=Gt.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{h&&(h=false,ie("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 ge=h=>!ee.has(h);var at=h=>h&&h===Math.floor(h)&&h>0&&isFinite(h),se=h=>at(h)?h<=Math.pow(2,8)?Uint8Array:h<=Math.pow(2,16)?Uint16Array:h<=Math.pow(2,32)?Uint32Array:h<=Number.MAX_SAFE_INTEGER?Dt:null:null,Dt=class extends Array{constructor(h){super(h),this.fill(0);}},it,St,_e=(it=class{heap;length;static create(e){let i=se(e);if(!i)return [];u(it,St,true);let s=new it(e,i);return u(it,St,false),s}constructor(e,i){if(!t(it,St))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]}},St=new WeakMap,_(it,St,false),it),Zt,te,K,M,q,ut,$,yt,xt,B,O,X,T,b,m,P,z,N,R,J,D,Q,Z,V,W,tt,dt,j,Et,l,It,ft,ot,Tt,Y,oe,mt,bt,Ot,lt,ht,Mt,Lt,Ct,E,zt,At,ct,Vt,wt,re=(wt=class{constructor(e){_(this,l);_(this,K);_(this,M);_(this,q);_(this,ut);_(this,$);_(this,yt);_(this,xt);_(this,B);C(this,"ttl");C(this,"ttlResolution");C(this,"ttlAutopurge");C(this,"updateAgeOnGet");C(this,"updateAgeOnHas");C(this,"allowStale");C(this,"noDisposeOnSet");C(this,"noUpdateTTL");C(this,"maxEntrySize");C(this,"sizeCalculation");C(this,"noDeleteOnFetchRejection");C(this,"noDeleteOnStaleGet");C(this,"allowStaleOnFetchAbort");C(this,"allowStaleOnFetchRejection");C(this,"ignoreFetchAbort");_(this,O);_(this,X);_(this,T);_(this,b);_(this,m);_(this,P);_(this,z);_(this,N);_(this,R);_(this,J);_(this,D);_(this,Q);_(this,Z);_(this,V);_(this,W);_(this,tt);_(this,dt);_(this,j);_(this,Et);_(this,ft,()=>{});_(this,ot,()=>{});_(this,Tt,()=>{});_(this,Y,()=>false);_(this,mt,e=>{});_(this,bt,(e,i,s)=>{});_(this,Ot,(e,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});C(this,Zt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:c,allowStale:p,dispose:v,onInsert:U,disposeAfter:S,noDisposeOnSet:rt,noUpdateTTL:I,maxSize:k=0,maxEntrySize:w=0,sizeCalculation:y,fetchMethod:a,memoMethod:x,noDeleteOnFetchRejection:A,noDeleteOnStaleGet:f,allowStaleOnFetchRejection:g,allowStaleOnFetchAbort:F,ignoreFetchAbort:H,perf:_t}=e;if(_t!==void 0&&typeof _t?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(u(this,B,_t??me),i!==0&&!at(i))throw new TypeError("max option must be a nonnegative integer");let vt=i?se(i):Array;if(!vt)throw new Error("invalid max value: "+i);if(u(this,K,i),u(this,M,k),this.maxEntrySize=w||t(this,M),this.sizeCalculation=y,this.sizeCalculation){if(!t(this,M)&&!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(x!==void 0&&typeof x!="function")throw new TypeError("memoMethod must be a function if defined");if(u(this,xt,x),a!==void 0&&typeof a!="function")throw new TypeError("fetchMethod must be a function if specified");if(u(this,yt,a),u(this,dt,!!a),u(this,T,new Map),u(this,b,new Array(i).fill(void 0)),u(this,m,new Array(i).fill(void 0)),u(this,P,new vt(i)),u(this,z,new vt(i)),u(this,N,0),u(this,R,0),u(this,J,_e.create(i)),u(this,O,0),u(this,X,0),typeof v=="function"&&u(this,q,v),typeof U=="function"&&u(this,ut,U),typeof S=="function"?(u(this,$,S),u(this,D,[])):(u(this,$,void 0),u(this,D,void 0)),u(this,tt,!!t(this,q)),u(this,Et,!!t(this,ut)),u(this,j,!!t(this,$)),this.noDisposeOnSet=!!rt,this.noUpdateTTL=!!I,this.noDeleteOnFetchRejection=!!A,this.allowStaleOnFetchRejection=!!g,this.allowStaleOnFetchAbort=!!F,this.ignoreFetchAbort=!!H,this.maxEntrySize!==0){if(t(this,M)!==0&&!at(t(this,M)))throw new TypeError("maxSize must be a positive integer if specified");if(!at(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");d(this,l,oe).call(this);}if(this.allowStale=!!p,this.noDeleteOnStaleGet=!!f,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!c,this.ttlResolution=at(r)||r===0?r:1,this.ttlAutopurge=!!n,this.ttl=s||0,this.ttl){if(!at(this.ttl))throw new TypeError("ttl must be a positive integer if specified");d(this,l,It).call(this);}if(t(this,K)===0&&this.ttl===0&&t(this,M)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!t(this,K)&&!t(this,M)){let Pt="LRU_CACHE_UNBOUNDED";ge(Pt)&&(ee.add(Pt),ie("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Pt,wt));}}get perf(){return t(this,B)}static unsafeExposeInternals(e){return {starts:t(e,Z),ttls:t(e,V),autopurgeTimers:t(e,W),sizes:t(e,Q),keyMap:t(e,T),keyList:t(e,b),valList:t(e,m),next:t(e,P),prev:t(e,z),get head(){return t(e,N)},get tail(){return t(e,R)},free:t(e,J),isBackgroundFetch:i=>{var s;return d(s=e,l,E).call(s,i)},backgroundFetch:(i,s,r,n)=>{var o;return d(o=e,l,Ct).call(o,i,s,r,n)},moveToTail:i=>{var s;return d(s=e,l,At).call(s,i)},indexes:i=>{var s;return d(s=e,l,lt).call(s,i)},rindexes:i=>{var s;return d(s=e,l,ht).call(s,i)},isStale:i=>{var s;return t(s=e,Y).call(s,i)}}}get max(){return t(this,K)}get maxSize(){return t(this,M)}get calculatedSize(){return t(this,X)}get size(){return t(this,O)}get fetchMethod(){return t(this,yt)}get memoMethod(){return t(this,xt)}get dispose(){return t(this,q)}get onInsert(){return t(this,ut)}get disposeAfter(){return t(this,$)}getRemainingTTL(e){return t(this,T).has(e)?1/0:0}*entries(){for(let e of d(this,l,lt).call(this))t(this,m)[e]!==void 0&&t(this,b)[e]!==void 0&&!d(this,l,E).call(this,t(this,m)[e])&&(yield [t(this,b)[e],t(this,m)[e]]);}*rentries(){for(let e of d(this,l,ht).call(this))t(this,m)[e]!==void 0&&t(this,b)[e]!==void 0&&!d(this,l,E).call(this,t(this,m)[e])&&(yield [t(this,b)[e],t(this,m)[e]]);}*keys(){for(let e of d(this,l,lt).call(this)){let i=t(this,b)[e];i!==void 0&&!d(this,l,E).call(this,t(this,m)[e])&&(yield i);}}*rkeys(){for(let e of d(this,l,ht).call(this)){let i=t(this,b)[e];i!==void 0&&!d(this,l,E).call(this,t(this,m)[e])&&(yield i);}}*values(){for(let e of d(this,l,lt).call(this))t(this,m)[e]!==void 0&&!d(this,l,E).call(this,t(this,m)[e])&&(yield t(this,m)[e]);}*rvalues(){for(let e of d(this,l,ht).call(this))t(this,m)[e]!==void 0&&!d(this,l,E).call(this,t(this,m)[e])&&(yield t(this,m)[e]);}[(te=Symbol.iterator,Zt=Symbol.toStringTag,te)](){return this.entries()}find(e,i={}){for(let s of d(this,l,lt).call(this)){let r=t(this,m)[s],n=d(this,l,E).call(this,r)?r.__staleWhileFetching:r;if(n!==void 0&&e(n,t(this,b)[s],this))return this.get(t(this,b)[s],i)}}forEach(e,i=this){for(let s of d(this,l,lt).call(this)){let r=t(this,m)[s],n=d(this,l,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e.call(i,n,t(this,b)[s],this);}}rforEach(e,i=this){for(let s of d(this,l,ht).call(this)){let r=t(this,m)[s],n=d(this,l,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e.call(i,n,t(this,b)[s],this);}}purgeStale(){let e=false;for(let i of d(this,l,ht).call(this,{allowStale:true}))t(this,Y).call(this,i)&&(d(this,l,ct).call(this,t(this,b)[i],"expire"),e=true);return e}info(e){let i=t(this,T).get(e);if(i===void 0)return;let s=t(this,m)[i],r=d(this,l,E).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let n={value:r};if(t(this,V)&&t(this,Z)){let o=t(this,V)[i],c=t(this,Z)[i];if(o&&c){let p=o-(t(this,B).now()-c);n.ttl=p,n.start=Date.now();}}return t(this,Q)&&(n.size=t(this,Q)[i]),n}dump(){let e=[];for(let i of d(this,l,lt).call(this,{allowStale:true})){let s=t(this,b)[i],r=t(this,m)[i],n=d(this,l,E).call(this,r)?r.__staleWhileFetching:r;if(n===void 0||s===void 0)continue;let o={value:n};if(t(this,V)&&t(this,Z)){o.ttl=t(this,V)[i];let c=t(this,B).now()-t(this,Z)[i];o.start=Math.floor(Date.now()-c);}t(this,Q)&&(o.size=t(this,Q)[i]),e.unshift([s,o]);}return e}load(e){this.clear();for(let[i,s]of e){if(s.start){let r=Date.now()-s.start;s.start=t(this,B).now()-r;}this.set(i,s.value,s);}}set(e,i,s={}){var rt,I,k,w;if(i===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:c=this.sizeCalculation,status:p}=s,{noUpdateTTL:v=this.noUpdateTTL}=s,U=t(this,Ot).call(this,e,i,s.size||0,c);if(this.maxEntrySize&&U>this.maxEntrySize)return p&&(p.set="miss",p.maxEntrySizeExceeded=true),d(this,l,ct).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,R):t(this,J).length!==0?t(this,J).pop():t(this,O)===t(this,K)?d(this,l,Lt).call(this,false):t(this,O),t(this,b)[S]=e,t(this,m)[S]=i,t(this,T).set(e,S),t(this,P)[t(this,R)]=S,t(this,z)[S]=t(this,R),u(this,R,S),Rt(this,O)._++,t(this,bt).call(this,S,U,p),p&&(p.set="add"),v=false,t(this,Et)&&((rt=t(this,ut))==null||rt.call(this,i,e,"add"));else {d(this,l,At).call(this,S);let y=t(this,m)[S];if(i!==y){if(t(this,dt)&&d(this,l,E).call(this,y)){y.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:a}=y;a!==void 0&&!o&&(t(this,tt)&&((I=t(this,q))==null||I.call(this,a,e,"set")),t(this,j)&&t(this,D)?.push([a,e,"set"]));}else o||(t(this,tt)&&((k=t(this,q))==null||k.call(this,y,e,"set")),t(this,j)&&t(this,D)?.push([y,e,"set"]));if(t(this,mt).call(this,S),t(this,bt).call(this,S,U,p),t(this,m)[S]=i,p){p.set="replace";let a=y&&d(this,l,E).call(this,y)?y.__staleWhileFetching:y;a!==void 0&&(p.oldValue=a);}}else p&&(p.set="update");t(this,Et)&&this.onInsert?.(i,e,i===y?"update":"replace");}if(r!==0&&!t(this,V)&&d(this,l,It).call(this),t(this,V)&&(v||t(this,Tt).call(this,S,r,n),p&&t(this,ot).call(this,p,S)),!o&&t(this,j)&&t(this,D)){let y=t(this,D),a;for(;a=y?.shift();)(w=t(this,$))==null||w.call(this,...a);}return this}pop(){var e;try{for(;t(this,O);){let i=t(this,m)[t(this,N)];if(d(this,l,Lt).call(this,!0),d(this,l,E).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(t(this,j)&&t(this,D)){let i=t(this,D),s;for(;s=i?.shift();)(e=t(this,$))==null||e.call(this,...s);}}}has(e,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=i,n=t(this,T).get(e);if(n!==void 0){let o=t(this,m)[n];if(d(this,l,E).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(t(this,Y).call(this,n))r&&(r.has="stale",t(this,ot).call(this,r,n));else return s&&t(this,ft).call(this,n),r&&(r.has="hit",t(this,ot).call(this,r,n)),true}else r&&(r.has="miss");return false}peek(e,i={}){let{allowStale:s=this.allowStale}=i,r=t(this,T).get(e);if(r===void 0||!s&&t(this,Y).call(this,r))return;let n=t(this,m)[r];return d(this,l,E).call(this,n)?n.__staleWhileFetching:n}async fetch(e,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:c=this.noDisposeOnSet,size:p=0,sizeCalculation:v=this.sizeCalculation,noUpdateTTL:U=this.noUpdateTTL,noDeleteOnFetchRejection:S=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:rt=this.allowStaleOnFetchRejection,ignoreFetchAbort:I=this.ignoreFetchAbort,allowStaleOnFetchAbort:k=this.allowStaleOnFetchAbort,context:w,forceRefresh:y=false,status:a,signal:x}=i;if(!t(this,dt))return a&&(a.fetch="get"),this.get(e,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,status:a});let A={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:c,size:p,sizeCalculation:v,noUpdateTTL:U,noDeleteOnFetchRejection:S,allowStaleOnFetchRejection:rt,allowStaleOnFetchAbort:k,ignoreFetchAbort:I,status:a,signal:x},f=t(this,T).get(e);if(f===void 0){a&&(a.fetch="miss");let g=d(this,l,Ct).call(this,e,f,A,w);return g.__returned=g}else {let g=t(this,m)[f];if(d(this,l,E).call(this,g)){let vt=s&&g.__staleWhileFetching!==void 0;return a&&(a.fetch="inflight",vt&&(a.returnedStale=true)),vt?g.__staleWhileFetching:g.__returned=g}let F=t(this,Y).call(this,f);if(!y&&!F)return a&&(a.fetch="hit"),d(this,l,At).call(this,f),r&&t(this,ft).call(this,f),a&&t(this,ot).call(this,a,f),g;let H=d(this,l,Ct).call(this,e,f,A,w),_t=H.__staleWhileFetching!==void 0&&s;return a&&(a.fetch=F?"stale":"refresh",_t&&F&&(a.returnedStale=true)),_t?H.__staleWhileFetching:H.__returned=H}}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,xt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:n,...o}=i,c=this.get(e,o);if(!n&&c!==void 0)return c;let p=s(e,c,{options:o,context:r});return this.set(e,p,o),p}get(e,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=i,c=t(this,T).get(e);if(c!==void 0){let p=t(this,m)[c],v=d(this,l,E).call(this,p);return o&&t(this,ot).call(this,o,c),t(this,Y).call(this,c)?(o&&(o.get="stale"),v?(o&&s&&p.__staleWhileFetching!==void 0&&(o.returnedStale=true),s?p.__staleWhileFetching:void 0):(n||d(this,l,ct).call(this,e,"expire"),o&&s&&(o.returnedStale=true),s?p:void 0)):(o&&(o.get="hit"),v?p.__staleWhileFetching:(d(this,l,At).call(this,c),r&&t(this,ft).call(this,c),p))}else o&&(o.get="miss");}delete(e){return d(this,l,ct).call(this,e,"delete")}clear(){return d(this,l,Vt).call(this,"delete")}},K=new WeakMap,M=new WeakMap,q=new WeakMap,ut=new WeakMap,$=new WeakMap,yt=new WeakMap,xt=new WeakMap,B=new WeakMap,O=new WeakMap,X=new WeakMap,T=new WeakMap,b=new WeakMap,m=new WeakMap,P=new WeakMap,z=new WeakMap,N=new WeakMap,R=new WeakMap,J=new WeakMap,D=new WeakMap,Q=new WeakMap,Z=new WeakMap,V=new WeakMap,W=new WeakMap,tt=new WeakMap,dt=new WeakMap,j=new WeakMap,Et=new WeakMap,l=new WeakSet,It=function(){let e=new Dt(t(this,K)),i=new Dt(t(this,K));u(this,V,e),u(this,Z,i);let s=this.ttlAutopurge?new Array(t(this,K)):void 0;u(this,W,s),u(this,Tt,(c,p,v=t(this,B).now())=>{i[c]=p!==0?v:0,e[c]=p,r(c,p);}),u(this,ft,c=>{i[c]=e[c]!==0?t(this,B).now():0,r(c,e[c]);});let r=this.ttlAutopurge?(c,p)=>{if(s?.[c]&&(clearTimeout(s[c]),s[c]=void 0),p&&p!==0&&s){let v=setTimeout(()=>{t(this,Y).call(this,c)&&d(this,l,ct).call(this,t(this,b)[c],"expire");},p+1);v.unref&&v.unref(),s[c]=v;}}:()=>{};u(this,ot,(c,p)=>{if(e[p]){let v=e[p],U=i[p];if(!v||!U)return;c.ttl=v,c.start=U,c.now=n||o();let S=c.now-U;c.remainingTTL=v-S;}});let n=0,o=()=>{let c=t(this,B).now();if(this.ttlResolution>0){n=c;let p=setTimeout(()=>n=0,this.ttlResolution);p.unref&&p.unref();}return c};this.getRemainingTTL=c=>{let p=t(this,T).get(c);if(p===void 0)return 0;let v=e[p],U=i[p];if(!v||!U)return 1/0;let S=(n||o())-U;return v-S},u(this,Y,c=>{let p=i[c],v=e[c];return !!v&&!!p&&(n||o())-p>v});},ft=new WeakMap,ot=new WeakMap,Tt=new WeakMap,Y=new WeakMap,oe=function(){let e=new Dt(t(this,K));u(this,X,0),u(this,Q,e),u(this,mt,i=>{u(this,X,t(this,X)-e[i]),e[i]=0;}),u(this,Ot,(i,s,r,n)=>{if(d(this,l,E).call(this,s))return 0;if(!at(r))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(r=n(s,i),!at(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}),u(this,bt,(i,s,r)=>{if(e[i]=s,t(this,M)){let n=t(this,M)-e[i];for(;t(this,X)>n;)d(this,l,Lt).call(this,true);}u(this,X,t(this,X)+e[i]),r&&(r.entrySize=s,r.totalCalculatedSize=t(this,X));});},mt=new WeakMap,bt=new WeakMap,Ot=new WeakMap,lt=function*({allowStale:e=this.allowStale}={}){if(t(this,O))for(let i=t(this,R);!(!d(this,l,Mt).call(this,i)||((e||!t(this,Y).call(this,i))&&(yield i),i===t(this,N)));)i=t(this,z)[i];},ht=function*({allowStale:e=this.allowStale}={}){if(t(this,O))for(let i=t(this,N);!(!d(this,l,Mt).call(this,i)||((e||!t(this,Y).call(this,i))&&(yield i),i===t(this,R)));)i=t(this,P)[i];},Mt=function(e){return e!==void 0&&t(this,T).get(t(this,b)[e])===e},Lt=function(e){var n;let i=t(this,N),s=t(this,b)[i],r=t(this,m)[i];return t(this,dt)&&d(this,l,E).call(this,r)?r.__abortController.abort(new Error("evicted")):(t(this,tt)||t(this,j))&&(t(this,tt)&&((n=t(this,q))==null||n.call(this,r,s,"evict")),t(this,j)&&t(this,D)?.push([r,s,"evict"])),t(this,mt).call(this,i),t(this,W)?.[i]&&(clearTimeout(t(this,W)[i]),t(this,W)[i]=void 0),e&&(t(this,b)[i]=void 0,t(this,m)[i]=void 0,t(this,J).push(i)),t(this,O)===1?(u(this,N,u(this,R,0)),t(this,J).length=0):u(this,N,t(this,P)[i]),t(this,T).delete(s),Rt(this,O)._--,i},Ct=function(e,i,s,r){let n=i===void 0?void 0:t(this,m)[i];if(d(this,l,E).call(this,n))return n;let o=new Nt,{signal:c}=s;c?.addEventListener("abort",()=>o.abort(c.reason),{signal:o.signal});let p={signal:o.signal,options:s,context:r},v=(w,y=false)=>{let{aborted:a}=o.signal,x=s.ignoreFetchAbort&&w!==void 0,A=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&w!==void 0);if(s.status&&(a&&!y?(s.status.fetchAborted=true,s.status.fetchError=o.signal.reason,x&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),a&&!x&&!y)return S(o.signal.reason,A);let f=I,g=t(this,m)[i];return (g===I||x&&y&&g===void 0)&&(w===void 0?f.__staleWhileFetching!==void 0?t(this,m)[i]=f.__staleWhileFetching:d(this,l,ct).call(this,e,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(e,w,p.options))),w},U=w=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=w),S(w,false)),S=(w,y)=>{let{aborted:a}=o.signal,x=a&&s.allowStaleOnFetchAbort,A=x||s.allowStaleOnFetchRejection,f=A||s.noDeleteOnFetchRejection,g=I;if(t(this,m)[i]===I&&(!f||!y&&g.__staleWhileFetching===void 0?d(this,l,ct).call(this,e,"fetch"):x||(t(this,m)[i]=g.__staleWhileFetching)),A)return s.status&&g.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),g.__staleWhileFetching;if(g.__returned===g)throw w},rt=(w,y)=>{var x;let a=(x=t(this,yt))==null?void 0:x.call(this,e,n,p);a&&a instanceof Promise&&a.then(A=>w(A===void 0?void 0:A),y),o.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(w(void 0),s.allowStaleOnFetchAbort&&(w=A=>v(A,true)));});};s.status&&(s.status.fetchDispatched=true);let I=new Promise(rt).then(v,U),k=Object.assign(I,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return i===void 0?(this.set(e,k,{...p.options,status:void 0}),i=t(this,T).get(e)):t(this,m)[i]=k,k},E=function(e){if(!t(this,dt))return false;let i=e;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Nt},zt=function(e,i){t(this,z)[i]=e,t(this,P)[e]=i;},At=function(e){e!==t(this,R)&&(e===t(this,N)?u(this,N,t(this,P)[e]):d(this,l,zt).call(this,t(this,z)[e],t(this,P)[e]),d(this,l,zt).call(this,t(this,R),e),u(this,R,e));},ct=function(e,i){var r,n;let s=false;if(t(this,O)!==0){let o=t(this,T).get(e);if(o!==void 0)if(t(this,W)?.[o]&&(clearTimeout(t(this,W)?.[o]),t(this,W)[o]=void 0),s=true,t(this,O)===1)d(this,l,Vt).call(this,i);else {t(this,mt).call(this,o);let c=t(this,m)[o];if(d(this,l,E).call(this,c)?c.__abortController.abort(new Error("deleted")):(t(this,tt)||t(this,j))&&(t(this,tt)&&((r=t(this,q))==null||r.call(this,c,e,i)),t(this,j)&&t(this,D)?.push([c,e,i])),t(this,T).delete(e),t(this,b)[o]=void 0,t(this,m)[o]=void 0,o===t(this,R))u(this,R,t(this,z)[o]);else if(o===t(this,N))u(this,N,t(this,P)[o]);else {let p=t(this,z)[o];t(this,P)[p]=t(this,P)[o];let v=t(this,P)[o];t(this,z)[v]=t(this,z)[o];}Rt(this,O)._--,t(this,J).push(o);}}if(t(this,j)&&t(this,D)?.length){let o=t(this,D),c;for(;c=o?.shift();)(n=t(this,$))==null||n.call(this,...c);}return s},Vt=function(e){var i,s;for(let r of d(this,l,ht).call(this,{allowStale:true})){let n=t(this,m)[r];if(d(this,l,E).call(this,n))n.__abortController.abort(new Error("deleted"));else {let o=t(this,b)[r];t(this,tt)&&((i=t(this,q))==null||i.call(this,n,o,e)),t(this,j)&&t(this,D)?.push([n,o,e]);}}if(t(this,T).clear(),t(this,m).fill(void 0),t(this,b).fill(void 0),t(this,V)&&t(this,Z)){t(this,V).fill(0),t(this,Z).fill(0);for(let r of t(this,W)??[])r!==void 0&&clearTimeout(r);t(this,W)?.fill(void 0);}if(t(this,Q)&&t(this,Q).fill(0),u(this,N,0),u(this,R,0),t(this,J).length=0,u(this,X,0),u(this,O,0),t(this,j)&&t(this,D)){let r=t(this,D),n;for(;n=r?.shift();)(s=t(this,$))==null||s.call(this,...n);}},wt);var Ft=class{cache;map=new Map;constructor(e){this.cache=new re({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 Ut="1.8.24";var Wt={version:Ut};var Yt="repeat";function Ht(h){return {type:"pause",duration:h}}var Kt="__game_layer__";var ve={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 ae={};var kt={};fe(kt,{createExportableElement:()=>le});var gt;(r=>(r.log=(n,...o)=>console.log(`[Pixi\u2019VN] ${n}`,...o),r.warn=(n,...o)=>console.warn(`[Pixi\u2019VN] ${n}`,...o),r.error=(n,...o)=>console.error(`[Pixi\u2019VN] ${n}`,...o),r.info=(n,...o)=>console.info(`[Pixi\u2019VN] ${n}`,...o)))(gt||={});function le(h){try{if(typeof h>"u")return h;let e=JSON.stringify(h);return JSON.parse(e)}catch(e){throw gt.error("Error creating exportable element",h,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var ye=typeof window<"u"&&typeof document<"u",he=[" _______ _ _ _ ____ ____ ____ _____ ","|_ __ \\ (_) (_) | | |_ _| |_ _||_ \\|_ _|"," | |__) |__ _ __ __ \\_| \\ \\ / / | \\ | | "," | ___/[ | [ \\ [ ][ | \\ \\ / / | |\\ \\| | "," _| |_ | | > ' < | | \\ ' / _| |_\\ |_ ",`|_____| [___][__]\`\\_][___] \\_/ |_____|\\____| v${Wt.version}`],ce=31,xe="background:#2f90da;color:#fff;font-weight:bold;",Ee="background:#c832bb;color:#fff;font-weight:bold;",be="background:transparent;font-weight:bold;",qt=` v${Wt.version}`;function de(){if(!ye)return;let h=[],e=[];for(let i=0;i<he.length;i++){let s=he[i],r=s.endsWith(qt),n=r?s.slice(0,-qt.length):s,o=n.slice(0,ce),c=n.slice(ce),p=r?"%c%s%c%s%c%s":"%c%s%c%s";h.push(p),e.push(xe,o,Ee,c),r&&e.push(be,qt);}console.info(h.join(`
2
- `),...e);}function $t(){let h=window.location.pathname+window.location.hash;return h.includes("#")&&(h=h.split("#")[1]),h}de();exports.Game=void 0;(y=>{async function h(a,x,A){if(core.GameUnifier.init({navigate:x?.navigate,getCurrentGameStepState:()=>{let f={};try{f=nt__namespace.canvas.export();}catch{}return {path:$t(),storage:G__namespace.storage.export(),canvas:f,sound:pt__namespace.sound.export(),labelIndex:L__namespace.NarrationManagerStatic.currentLabelStepIndex||0,openedLabels:L__namespace.narration.openedLabels}},restoreGameStepState:async(f,g)=>{et__namespace.HistoryManagerStatic._originalStepData=f,L__namespace.NarrationManagerStatic.openedLabels=f.openedLabels,G__namespace.storage.restore(f.storage);try{await nt__namespace.canvas.restore(f.canvas),await pt__namespace.sound.restore(f.sound);}catch(F){gt.error("Error restoring game step state:",F);}await g(f.path);},getStepCounter:()=>L__namespace.narration.stepCounter,setStepCounter:f=>{L__namespace.NarrationManagerStatic._stepCounter=f;},getOpenedLabels:()=>L__namespace.narration.openedLabels.length,addHistoryItem:(f,g)=>et__namespace.stepHistory.add(f,g),getCharacter:f=>Bt__namespace.RegisteredCharacters.get(f),processNavigationRequests:(f,g)=>{let F=f,H=Promise.resolve();return f>0?(F--,H=L__namespace.narration.continue(g)):f<0&&(F=0,H=et__namespace.stepHistory.back(g,{steps:f*-1})),{newValue:F,result:H}},animate:(f,g,F,H)=>motion.motion.animate(f,g,F,H),getVariable:(f,g)=>G__namespace.StorageRegistry.getVariable(f,g),setVariable:(f,g,F)=>G__namespace.StorageRegistry.setVariable(f,g,F),removeVariable:(f,g)=>G__namespace.StorageRegistry.removeVariable(f,g),getFlag:f=>G__namespace.storage.getFlag(f),setFlag:(f,g)=>G__namespace.storage.setFlag(f,g),onLabelClosing:f=>G__namespace.StorageRegistry.clearOldTempVariables(f)}),!a||!x){gt.warn("The canvas element or options are not defined. The canvas will not be initialized.");return}return await nt__namespace.canvas.init(a,x,A)}y.init=h;function e(){G__namespace.storage.clear();try{nt__namespace.canvas.clear();}catch{}pt__namespace.sound.clear(),L__namespace.narration.clear(),et__namespace.stepHistory.clear();}y.clear=e;function i(){let a={};try{a=nt__namespace.canvas.export();}catch{}return {pixivn_version:Ut,stepData:L__namespace.narration.export(),storageData:G__namespace.storage.export(),canvasData:a,soundData:pt__namespace.sound.export(),historyData:et__namespace.stepHistory.export(),path:$t()}}y.exportGameState=i;async function s(a,x){et__namespace.stepHistory.restore(a.historyData);let A=et__namespace.stepHistory.lastKey;if(typeof A=="number"){let f=et__namespace.stepHistory.stepsInfoMap.get(A)||null;await L__namespace.narration.restore(a.stepData,f);}G__namespace.storage.restore(a.storageData);try{await nt__namespace.canvas.restore(a.canvasData),await pt__namespace.sound.restore(a.soundData);}catch{}x?await x(a.path):await core.GameUnifier.navigate(a.path);}y.restoreGameState=s;async function r(a,x){return y.clear(),await L__namespace.narration.call(a,x)}y.start=r;function n(a){return JSON.parse(a)}y.jsonToGameState=n;function o(a){core.GameUnifier.onEnd=a;}y.onEnd=o;function c(a){return gt.warn("Game.onError is deprecated. Use Game.addOnError / Game.removeOnError to register multiple handlers."),core.GameUnifier.addOnError((x,A)=>a("step",x,A))}y.onError=c;function p(a){return core.GameUnifier.addOnError(a)}y.addOnError=p;function v(a){return core.GameUnifier.removeOnError(a)}y.removeOnError=v;function U(a){L__namespace.NarrationManagerStatic.onStepStart=a;}y.onStepStart=U;function S(a){L__namespace.NarrationManagerStatic.onLoadingLabel=a;}y.onLoadingLabel=S;function rt(a){L__namespace.NarrationManagerStatic.onStepEnd=a;}y.onStepEnd=rt;function I(a){core.GameUnifier.navigate=a;}y.onNavigate=I;function k(a){return core.GameUnifier.addOnPreContinue(a)}y.addOnPreContinue=k;function w(a){return core.GameUnifier.removeOnPreContinue(a)}y.removeOnPreContinue=w;})(exports.Game||={});var Ze={characterUtils:Bt__namespace,canvasUtils:nt__namespace,narrationUtils:L__namespace,soundUtils:pt__namespace,CANVAS_APP_GAME_LAYER_ALIAS:Kt,Pause:Ht,Repeat:Yt,PIXIVN_VERSION:Ut,...kt,...ae,canvas:nt__namespace.canvas,narration:L__namespace.narration,sound:pt__namespace.sound,storage:G__namespace.storage,history:et__namespace.stepHistory,Game:exports.Game,GameUnifier:core.GameUnifier};exports.CANVAS_APP_GAME_LAYER_ALIAS=Kt;exports.CachedMap=Ft;exports.PIXIVN_VERSION=Ut;exports.Pause=Ht;exports.Repeat=Yt;exports.SYSTEM_RESERVED_STORAGE_KEYS=ve;exports.createExportableElement=le;exports.default=Ze;Object.keys(nt).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return nt[k]}})});Object.keys(Bt).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return Bt[k]}})});Object.keys(core).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return core[k]}})});Object.keys(et).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return et[k]}})});Object.keys(L).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return L[k]}})});Object.keys(pt).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return pt[k]}})});Object.keys(G).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return G[k]}})});
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var at=require('@drincs/pixi-vn/canvas'),Bt=require('@drincs/pixi-vn/characters'),core=require('@drincs/pixi-vn/core'),it=require('@drincs/pixi-vn/history'),R=require('@drincs/pixi-vn/narration'),ut=require('@drincs/pixi-vn/sound'),G=require('@drincs/pixi-vn/storage'),motion=require('@drincs/pixi-vn/motion');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var at__namespace=/*#__PURE__*/_interopNamespace(at);var Bt__namespace=/*#__PURE__*/_interopNamespace(Bt);var it__namespace=/*#__PURE__*/_interopNamespace(it);var R__namespace=/*#__PURE__*/_interopNamespace(R);var ut__namespace=/*#__PURE__*/_interopNamespace(ut);var G__namespace=/*#__PURE__*/_interopNamespace(G);var Xt=Object.defineProperty;var Jt=l=>{throw TypeError(l)};var ue=(l,e,i)=>e in l?Xt(l,e,{enumerable:true,configurable:true,writable:true,value:i}):l[e]=i;var fe=(l,e)=>{for(var i in e)Xt(l,i,{get:e[i],enumerable:true});};var P=(l,e,i)=>ue(l,typeof e!="symbol"?e+"":e,i),jt=(l,e,i)=>e.has(l)||Jt("Cannot "+i);var t=(l,e,i)=>(jt(l,e,"read from private field"),i?i.call(l):e.get(l)),_=(l,e,i)=>e.has(l)?Jt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(l):e.set(l,i),f=(l,e,i,s)=>(jt(l,e,"write to private field"),e.set(l,i),i),c=(l,e,i)=>(jt(l,e,"access private method"),i);var Rt=(l,e,i,s)=>({set _(r){f(l,e,r);},get _(){return t(l,e,s)}});var me=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,ee=new Set,It=typeof process=="object"&&process?process:{},ie=(l,e,i,s)=>{typeof It.emitWarning=="function"?It.emitWarning(l,e,i,s):console.error(`[${i}] ${e}: ${l}`);},Pt=globalThis.AbortController,Qt=globalThis.AbortSignal;if(typeof Pt>"u"){Qt=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},Pt=class{constructor(){e();}signal=new Qt;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=It.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{l&&(l=false,ie("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 ge=l=>!ee.has(l);var lt=l=>l&&l===Math.floor(l)&&l>0&&isFinite(l),se=l=>lt(l)?l<=Math.pow(2,8)?Uint8Array:l<=Math.pow(2,16)?Uint16Array:l<=Math.pow(2,32)?Uint32Array:l<=Number.MAX_SAFE_INTEGER?Lt:null:null,Lt=class extends Array{constructor(l){super(l),this.fill(0);}},st,St,_e=(st=class{heap;length;static create(e){let i=se(e);if(!i)return [];f(st,St,true);let s=new st(e,i);return f(st,St,false),s}constructor(e,i){if(!t(st,St))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]}},St=new WeakMap,_(st,St,false),st),Zt,te,k,z,$,ft,B,yt,xt,X,U,J,O,b,m,j,V,F,D,Q,C,Z,tt,W,Y,et,pt,I,Et,a,Gt,mt,nt,Tt,H,oe,gt,bt,Ot,ht,ct,Mt,Dt,Ct,E,zt,At,dt,Vt,wt,re=(wt=class{constructor(e){_(this,a);_(this,k);_(this,z);_(this,$);_(this,ft);_(this,B);_(this,yt);_(this,xt);_(this,X);P(this,"ttl");P(this,"ttlResolution");P(this,"ttlAutopurge");P(this,"updateAgeOnGet");P(this,"updateAgeOnHas");P(this,"allowStale");P(this,"noDisposeOnSet");P(this,"noUpdateTTL");P(this,"maxEntrySize");P(this,"sizeCalculation");P(this,"noDeleteOnFetchRejection");P(this,"noDeleteOnStaleGet");P(this,"allowStaleOnFetchAbort");P(this,"allowStaleOnFetchRejection");P(this,"ignoreFetchAbort");_(this,U);_(this,J);_(this,O);_(this,b);_(this,m);_(this,j);_(this,V);_(this,F);_(this,D);_(this,Q);_(this,C);_(this,Z);_(this,tt);_(this,W);_(this,Y);_(this,et);_(this,pt);_(this,I);_(this,Et);_(this,mt,()=>{});_(this,nt,()=>{});_(this,Tt,()=>{});_(this,H,()=>false);_(this,gt,e=>{});_(this,bt,(e,i,s)=>{});_(this,Ot,(e,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});P(this,Zt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:h,allowStale:d,dispose:v,onInsert:L,disposeAfter:S,noDisposeOnSet:ot,noUpdateTTL:M,maxSize:q=0,maxEntrySize:w=0,sizeCalculation:y,fetchMethod:g,memoMethod:u,noDeleteOnFetchRejection:x,noDeleteOnStaleGet:T,allowStaleOnFetchRejection:p,allowStaleOnFetchAbort:A,ignoreFetchAbort:N,perf:K}=e;if(K!==void 0&&typeof K?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(f(this,X,K??me),i!==0&&!lt(i))throw new TypeError("max option must be a nonnegative integer");let vt=i?se(i):Array;if(!vt)throw new Error("invalid max value: "+i);if(f(this,k,i),f(this,z,q),this.maxEntrySize=w||t(this,z),this.sizeCalculation=y,this.sizeCalculation){if(!t(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(u!==void 0&&typeof u!="function")throw new TypeError("memoMethod must be a function if defined");if(f(this,xt,u),g!==void 0&&typeof g!="function")throw new TypeError("fetchMethod must be a function if specified");if(f(this,yt,g),f(this,pt,!!g),f(this,O,new Map),f(this,b,new Array(i).fill(void 0)),f(this,m,new Array(i).fill(void 0)),f(this,j,new vt(i)),f(this,V,new vt(i)),f(this,F,0),f(this,D,0),f(this,Q,_e.create(i)),f(this,U,0),f(this,J,0),typeof v=="function"&&f(this,$,v),typeof L=="function"&&f(this,ft,L),typeof S=="function"?(f(this,B,S),f(this,C,[])):(f(this,B,void 0),f(this,C,void 0)),f(this,et,!!t(this,$)),f(this,Et,!!t(this,ft)),f(this,I,!!t(this,B)),this.noDisposeOnSet=!!ot,this.noUpdateTTL=!!M,this.noDeleteOnFetchRejection=!!x,this.allowStaleOnFetchRejection=!!p,this.allowStaleOnFetchAbort=!!A,this.ignoreFetchAbort=!!N,this.maxEntrySize!==0){if(t(this,z)!==0&&!lt(t(this,z)))throw new TypeError("maxSize must be a positive integer if specified");if(!lt(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");c(this,a,oe).call(this);}if(this.allowStale=!!d,this.noDeleteOnStaleGet=!!T,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!h,this.ttlResolution=lt(r)||r===0?r:1,this.ttlAutopurge=!!n,this.ttl=s||0,this.ttl){if(!lt(this.ttl))throw new TypeError("ttl must be a positive integer if specified");c(this,a,Gt).call(this);}if(t(this,k)===0&&this.ttl===0&&t(this,z)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!t(this,k)&&!t(this,z)){let Ft="LRU_CACHE_UNBOUNDED";ge(Ft)&&(ee.add(Ft),ie("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Ft,wt));}}get perf(){return t(this,X)}static unsafeExposeInternals(e){return {starts:t(e,tt),ttls:t(e,W),autopurgeTimers:t(e,Y),sizes:t(e,Z),keyMap:t(e,O),keyList:t(e,b),valList:t(e,m),next:t(e,j),prev:t(e,V),get head(){return t(e,F)},get tail(){return t(e,D)},free:t(e,Q),isBackgroundFetch:i=>{var s;return c(s=e,a,E).call(s,i)},backgroundFetch:(i,s,r,n)=>{var o;return c(o=e,a,Ct).call(o,i,s,r,n)},moveToTail:i=>{var s;return c(s=e,a,At).call(s,i)},indexes:i=>{var s;return c(s=e,a,ht).call(s,i)},rindexes:i=>{var s;return c(s=e,a,ct).call(s,i)},isStale:i=>{var s;return t(s=e,H).call(s,i)}}}get max(){return t(this,k)}get maxSize(){return t(this,z)}get calculatedSize(){return t(this,J)}get size(){return t(this,U)}get fetchMethod(){return t(this,yt)}get memoMethod(){return t(this,xt)}get dispose(){return t(this,$)}get onInsert(){return t(this,ft)}get disposeAfter(){return t(this,B)}getRemainingTTL(e){return t(this,O).has(e)?1/0:0}*entries(){for(let e of c(this,a,ht).call(this))t(this,m)[e]!==void 0&&t(this,b)[e]!==void 0&&!c(this,a,E).call(this,t(this,m)[e])&&(yield [t(this,b)[e],t(this,m)[e]]);}*rentries(){for(let e of c(this,a,ct).call(this))t(this,m)[e]!==void 0&&t(this,b)[e]!==void 0&&!c(this,a,E).call(this,t(this,m)[e])&&(yield [t(this,b)[e],t(this,m)[e]]);}*keys(){for(let e of c(this,a,ht).call(this)){let i=t(this,b)[e];i!==void 0&&!c(this,a,E).call(this,t(this,m)[e])&&(yield i);}}*rkeys(){for(let e of c(this,a,ct).call(this)){let i=t(this,b)[e];i!==void 0&&!c(this,a,E).call(this,t(this,m)[e])&&(yield i);}}*values(){for(let e of c(this,a,ht).call(this))t(this,m)[e]!==void 0&&!c(this,a,E).call(this,t(this,m)[e])&&(yield t(this,m)[e]);}*rvalues(){for(let e of c(this,a,ct).call(this))t(this,m)[e]!==void 0&&!c(this,a,E).call(this,t(this,m)[e])&&(yield t(this,m)[e]);}[(te=Symbol.iterator,Zt=Symbol.toStringTag,te)](){return this.entries()}find(e,i={}){for(let s of c(this,a,ht).call(this)){let r=t(this,m)[s],n=c(this,a,E).call(this,r)?r.__staleWhileFetching:r;if(n!==void 0&&e(n,t(this,b)[s],this))return this.get(t(this,b)[s],i)}}forEach(e,i=this){for(let s of c(this,a,ht).call(this)){let r=t(this,m)[s],n=c(this,a,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e.call(i,n,t(this,b)[s],this);}}rforEach(e,i=this){for(let s of c(this,a,ct).call(this)){let r=t(this,m)[s],n=c(this,a,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e.call(i,n,t(this,b)[s],this);}}purgeStale(){let e=false;for(let i of c(this,a,ct).call(this,{allowStale:true}))t(this,H).call(this,i)&&(c(this,a,dt).call(this,t(this,b)[i],"expire"),e=true);return e}info(e){let i=t(this,O).get(e);if(i===void 0)return;let s=t(this,m)[i],r=c(this,a,E).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let n={value:r};if(t(this,W)&&t(this,tt)){let o=t(this,W)[i],h=t(this,tt)[i];if(o&&h){let d=o-(t(this,X).now()-h);n.ttl=d,n.start=Date.now();}}return t(this,Z)&&(n.size=t(this,Z)[i]),n}dump(){let e=[];for(let i of c(this,a,ht).call(this,{allowStale:true})){let s=t(this,b)[i],r=t(this,m)[i],n=c(this,a,E).call(this,r)?r.__staleWhileFetching:r;if(n===void 0||s===void 0)continue;let o={value:n};if(t(this,W)&&t(this,tt)){o.ttl=t(this,W)[i];let h=t(this,X).now()-t(this,tt)[i];o.start=Math.floor(Date.now()-h);}t(this,Z)&&(o.size=t(this,Z)[i]),e.unshift([s,o]);}return e}load(e){this.clear();for(let[i,s]of e){if(s.start){let r=Date.now()-s.start;s.start=t(this,X).now()-r;}this.set(i,s.value,s);}}set(e,i,s={}){var ot,M,q,w;if(i===void 0)return this.delete(e),this;let{ttl:r=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:h=this.sizeCalculation,status:d}=s,{noUpdateTTL:v=this.noUpdateTTL}=s,L=t(this,Ot).call(this,e,i,s.size||0,h);if(this.maxEntrySize&&L>this.maxEntrySize)return d&&(d.set="miss",d.maxEntrySizeExceeded=true),c(this,a,dt).call(this,e,"set"),this;let S=t(this,U)===0?void 0:t(this,O).get(e);if(S===void 0)S=t(this,U)===0?t(this,D):t(this,Q).length!==0?t(this,Q).pop():t(this,U)===t(this,k)?c(this,a,Dt).call(this,false):t(this,U),t(this,b)[S]=e,t(this,m)[S]=i,t(this,O).set(e,S),t(this,j)[t(this,D)]=S,t(this,V)[S]=t(this,D),f(this,D,S),Rt(this,U)._++,t(this,bt).call(this,S,L,d),d&&(d.set="add"),v=false,t(this,Et)&&((ot=t(this,ft))==null||ot.call(this,i,e,"add"));else {c(this,a,At).call(this,S);let y=t(this,m)[S];if(i!==y){if(t(this,pt)&&c(this,a,E).call(this,y)){y.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:g}=y;g!==void 0&&!o&&(t(this,et)&&((M=t(this,$))==null||M.call(this,g,e,"set")),t(this,I)&&t(this,C)?.push([g,e,"set"]));}else o||(t(this,et)&&((q=t(this,$))==null||q.call(this,y,e,"set")),t(this,I)&&t(this,C)?.push([y,e,"set"]));if(t(this,gt).call(this,S),t(this,bt).call(this,S,L,d),t(this,m)[S]=i,d){d.set="replace";let g=y&&c(this,a,E).call(this,y)?y.__staleWhileFetching:y;g!==void 0&&(d.oldValue=g);}}else d&&(d.set="update");t(this,Et)&&this.onInsert?.(i,e,i===y?"update":"replace");}if(r!==0&&!t(this,W)&&c(this,a,Gt).call(this),t(this,W)&&(v||t(this,Tt).call(this,S,r,n),d&&t(this,nt).call(this,d,S)),!o&&t(this,I)&&t(this,C)){let y=t(this,C),g;for(;g=y?.shift();)(w=t(this,B))==null||w.call(this,...g);}return this}pop(){var e;try{for(;t(this,U);){let i=t(this,m)[t(this,F)];if(c(this,a,Dt).call(this,!0),c(this,a,E).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(t(this,I)&&t(this,C)){let i=t(this,C),s;for(;s=i?.shift();)(e=t(this,B))==null||e.call(this,...s);}}}has(e,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=i,n=t(this,O).get(e);if(n!==void 0){let o=t(this,m)[n];if(c(this,a,E).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(t(this,H).call(this,n))r&&(r.has="stale",t(this,nt).call(this,r,n));else return s&&t(this,mt).call(this,n),r&&(r.has="hit",t(this,nt).call(this,r,n)),true}else r&&(r.has="miss");return false}peek(e,i={}){let{allowStale:s=this.allowStale}=i,r=t(this,O).get(e);if(r===void 0||!s&&t(this,H).call(this,r))return;let n=t(this,m)[r];return c(this,a,E).call(this,n)?n.__staleWhileFetching:n}async fetch(e,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:d=0,sizeCalculation:v=this.sizeCalculation,noUpdateTTL:L=this.noUpdateTTL,noDeleteOnFetchRejection:S=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:ot=this.allowStaleOnFetchRejection,ignoreFetchAbort:M=this.ignoreFetchAbort,allowStaleOnFetchAbort:q=this.allowStaleOnFetchAbort,context:w,forceRefresh:y=false,status:g,signal:u}=i;if(!t(this,pt))return g&&(g.fetch="get"),this.get(e,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,status:g});let x={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:h,size:d,sizeCalculation:v,noUpdateTTL:L,noDeleteOnFetchRejection:S,allowStaleOnFetchRejection:ot,allowStaleOnFetchAbort:q,ignoreFetchAbort:M,status:g,signal:u},T=t(this,O).get(e);if(T===void 0){g&&(g.fetch="miss");let p=c(this,a,Ct).call(this,e,T,x,w);return p.__returned=p}else {let p=t(this,m)[T];if(c(this,a,E).call(this,p)){let vt=s&&p.__staleWhileFetching!==void 0;return g&&(g.fetch="inflight",vt&&(g.returnedStale=true)),vt?p.__staleWhileFetching:p.__returned=p}let A=t(this,H).call(this,T);if(!y&&!A)return g&&(g.fetch="hit"),c(this,a,At).call(this,T),r&&t(this,mt).call(this,T),g&&t(this,nt).call(this,g,T),p;let N=c(this,a,Ct).call(this,e,T,x,w),K=N.__staleWhileFetching!==void 0&&s;return g&&(g.fetch=A?"stale":"refresh",K&&A&&(g.returnedStale=true)),K?N.__staleWhileFetching:N.__returned=N}}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,xt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:n,...o}=i,h=this.get(e,o);if(!n&&h!==void 0)return h;let d=s(e,h,{options:o,context:r});return this.set(e,d,o),d}get(e,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=i,h=t(this,O).get(e);if(h!==void 0){let d=t(this,m)[h],v=c(this,a,E).call(this,d);return o&&t(this,nt).call(this,o,h),t(this,H).call(this,h)?(o&&(o.get="stale"),v?(o&&s&&d.__staleWhileFetching!==void 0&&(o.returnedStale=true),s?d.__staleWhileFetching:void 0):(n||c(this,a,dt).call(this,e,"expire"),o&&s&&(o.returnedStale=true),s?d:void 0)):(o&&(o.get="hit"),v?d.__staleWhileFetching:(c(this,a,At).call(this,h),r&&t(this,mt).call(this,h),d))}else o&&(o.get="miss");}delete(e){return c(this,a,dt).call(this,e,"delete")}clear(){return c(this,a,Vt).call(this,"delete")}},k=new WeakMap,z=new WeakMap,$=new WeakMap,ft=new WeakMap,B=new WeakMap,yt=new WeakMap,xt=new WeakMap,X=new WeakMap,U=new WeakMap,J=new WeakMap,O=new WeakMap,b=new WeakMap,m=new WeakMap,j=new WeakMap,V=new WeakMap,F=new WeakMap,D=new WeakMap,Q=new WeakMap,C=new WeakMap,Z=new WeakMap,tt=new WeakMap,W=new WeakMap,Y=new WeakMap,et=new WeakMap,pt=new WeakMap,I=new WeakMap,Et=new WeakMap,a=new WeakSet,Gt=function(){let e=new Lt(t(this,k)),i=new Lt(t(this,k));f(this,W,e),f(this,tt,i);let s=this.ttlAutopurge?new Array(t(this,k)):void 0;f(this,Y,s),f(this,Tt,(h,d,v=t(this,X).now())=>{i[h]=d!==0?v:0,e[h]=d,r(h,d);}),f(this,mt,h=>{i[h]=e[h]!==0?t(this,X).now():0,r(h,e[h]);});let r=this.ttlAutopurge?(h,d)=>{if(s?.[h]&&(clearTimeout(s[h]),s[h]=void 0),d&&d!==0&&s){let v=setTimeout(()=>{t(this,H).call(this,h)&&c(this,a,dt).call(this,t(this,b)[h],"expire");},d+1);v.unref&&v.unref(),s[h]=v;}}:()=>{};f(this,nt,(h,d)=>{if(e[d]){let v=e[d],L=i[d];if(!v||!L)return;h.ttl=v,h.start=L,h.now=n||o();let S=h.now-L;h.remainingTTL=v-S;}});let n=0,o=()=>{let h=t(this,X).now();if(this.ttlResolution>0){n=h;let d=setTimeout(()=>n=0,this.ttlResolution);d.unref&&d.unref();}return h};this.getRemainingTTL=h=>{let d=t(this,O).get(h);if(d===void 0)return 0;let v=e[d],L=i[d];if(!v||!L)return 1/0;let S=(n||o())-L;return v-S},f(this,H,h=>{let d=i[h],v=e[h];return !!v&&!!d&&(n||o())-d>v});},mt=new WeakMap,nt=new WeakMap,Tt=new WeakMap,H=new WeakMap,oe=function(){let e=new Lt(t(this,k));f(this,J,0),f(this,Z,e),f(this,gt,i=>{f(this,J,t(this,J)-e[i]),e[i]=0;}),f(this,Ot,(i,s,r,n)=>{if(c(this,a,E).call(this,s))return 0;if(!lt(r))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(r=n(s,i),!lt(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}),f(this,bt,(i,s,r)=>{if(e[i]=s,t(this,z)){let n=t(this,z)-e[i];for(;t(this,J)>n;)c(this,a,Dt).call(this,true);}f(this,J,t(this,J)+e[i]),r&&(r.entrySize=s,r.totalCalculatedSize=t(this,J));});},gt=new WeakMap,bt=new WeakMap,Ot=new WeakMap,ht=function*({allowStale:e=this.allowStale}={}){if(t(this,U))for(let i=t(this,D);!(!c(this,a,Mt).call(this,i)||((e||!t(this,H).call(this,i))&&(yield i),i===t(this,F)));)i=t(this,V)[i];},ct=function*({allowStale:e=this.allowStale}={}){if(t(this,U))for(let i=t(this,F);!(!c(this,a,Mt).call(this,i)||((e||!t(this,H).call(this,i))&&(yield i),i===t(this,D)));)i=t(this,j)[i];},Mt=function(e){return e!==void 0&&t(this,O).get(t(this,b)[e])===e},Dt=function(e){var n;let i=t(this,F),s=t(this,b)[i],r=t(this,m)[i];return t(this,pt)&&c(this,a,E).call(this,r)?r.__abortController.abort(new Error("evicted")):(t(this,et)||t(this,I))&&(t(this,et)&&((n=t(this,$))==null||n.call(this,r,s,"evict")),t(this,I)&&t(this,C)?.push([r,s,"evict"])),t(this,gt).call(this,i),t(this,Y)?.[i]&&(clearTimeout(t(this,Y)[i]),t(this,Y)[i]=void 0),e&&(t(this,b)[i]=void 0,t(this,m)[i]=void 0,t(this,Q).push(i)),t(this,U)===1?(f(this,F,f(this,D,0)),t(this,Q).length=0):f(this,F,t(this,j)[i]),t(this,O).delete(s),Rt(this,U)._--,i},Ct=function(e,i,s,r){let n=i===void 0?void 0:t(this,m)[i];if(c(this,a,E).call(this,n))return n;let o=new Pt,{signal:h}=s;h?.addEventListener("abort",()=>o.abort(h.reason),{signal:o.signal});let d={signal:o.signal,options:s,context:r},v=(w,y=false)=>{let{aborted:g}=o.signal,u=s.ignoreFetchAbort&&w!==void 0,x=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&w!==void 0);if(s.status&&(g&&!y?(s.status.fetchAborted=true,s.status.fetchError=o.signal.reason,u&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),g&&!u&&!y)return S(o.signal.reason,x);let T=M,p=t(this,m)[i];return (p===M||u&&y&&p===void 0)&&(w===void 0?T.__staleWhileFetching!==void 0?t(this,m)[i]=T.__staleWhileFetching:c(this,a,dt).call(this,e,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(e,w,d.options))),w},L=w=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=w),S(w,false)),S=(w,y)=>{let{aborted:g}=o.signal,u=g&&s.allowStaleOnFetchAbort,x=u||s.allowStaleOnFetchRejection,T=x||s.noDeleteOnFetchRejection,p=M;if(t(this,m)[i]===M&&(!T||!y&&p.__staleWhileFetching===void 0?c(this,a,dt).call(this,e,"fetch"):u||(t(this,m)[i]=p.__staleWhileFetching)),x)return s.status&&p.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),p.__staleWhileFetching;if(p.__returned===p)throw w},ot=(w,y)=>{var u;let g=(u=t(this,yt))==null?void 0:u.call(this,e,n,d);g&&g instanceof Promise&&g.then(x=>w(x===void 0?void 0:x),y),o.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(w(void 0),s.allowStaleOnFetchAbort&&(w=x=>v(x,true)));});};s.status&&(s.status.fetchDispatched=true);let M=new Promise(ot).then(v,L),q=Object.assign(M,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return i===void 0?(this.set(e,q,{...d.options,status:void 0}),i=t(this,O).get(e)):t(this,m)[i]=q,q},E=function(e){if(!t(this,pt))return false;let i=e;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Pt},zt=function(e,i){t(this,V)[i]=e,t(this,j)[e]=i;},At=function(e){e!==t(this,D)&&(e===t(this,F)?f(this,F,t(this,j)[e]):c(this,a,zt).call(this,t(this,V)[e],t(this,j)[e]),c(this,a,zt).call(this,t(this,D),e),f(this,D,e));},dt=function(e,i){var r,n;let s=false;if(t(this,U)!==0){let o=t(this,O).get(e);if(o!==void 0)if(t(this,Y)?.[o]&&(clearTimeout(t(this,Y)?.[o]),t(this,Y)[o]=void 0),s=true,t(this,U)===1)c(this,a,Vt).call(this,i);else {t(this,gt).call(this,o);let h=t(this,m)[o];if(c(this,a,E).call(this,h)?h.__abortController.abort(new Error("deleted")):(t(this,et)||t(this,I))&&(t(this,et)&&((r=t(this,$))==null||r.call(this,h,e,i)),t(this,I)&&t(this,C)?.push([h,e,i])),t(this,O).delete(e),t(this,b)[o]=void 0,t(this,m)[o]=void 0,o===t(this,D))f(this,D,t(this,V)[o]);else if(o===t(this,F))f(this,F,t(this,j)[o]);else {let d=t(this,V)[o];t(this,j)[d]=t(this,j)[o];let v=t(this,j)[o];t(this,V)[v]=t(this,V)[o];}Rt(this,U)._--,t(this,Q).push(o);}}if(t(this,I)&&t(this,C)?.length){let o=t(this,C),h;for(;h=o?.shift();)(n=t(this,B))==null||n.call(this,...h);}return s},Vt=function(e){var i,s;for(let r of c(this,a,ct).call(this,{allowStale:true})){let n=t(this,m)[r];if(c(this,a,E).call(this,n))n.__abortController.abort(new Error("deleted"));else {let o=t(this,b)[r];t(this,et)&&((i=t(this,$))==null||i.call(this,n,o,e)),t(this,I)&&t(this,C)?.push([n,o,e]);}}if(t(this,O).clear(),t(this,m).fill(void 0),t(this,b).fill(void 0),t(this,W)&&t(this,tt)){t(this,W).fill(0),t(this,tt).fill(0);for(let r of t(this,Y)??[])r!==void 0&&clearTimeout(r);t(this,Y)?.fill(void 0);}if(t(this,Z)&&t(this,Z).fill(0),f(this,F,0),f(this,D,0),t(this,Q).length=0,f(this,J,0),f(this,U,0),t(this,I)&&t(this,C)){let r=t(this,C),n;for(;n=r?.shift();)(s=t(this,B))==null||s.call(this,...n);}},wt);var Nt=class{cache;map=new Map;constructor(e){this.cache=new re({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 Ut="1.8.25";var Wt={version:Ut};var Yt="repeat";function Ht(l){return {type:"pause",duration:l}}var Kt="__game_layer__";var ve={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 ae={};var kt={};fe(kt,{createExportableElement:()=>le});var _t;(r=>(r.log=(n,...o)=>console.log(`[Pixi\u2019VN] ${n}`,...o),r.warn=(n,...o)=>console.warn(`[Pixi\u2019VN] ${n}`,...o),r.error=(n,...o)=>console.error(`[Pixi\u2019VN] ${n}`,...o),r.info=(n,...o)=>console.info(`[Pixi\u2019VN] ${n}`,...o)))(_t||={});function le(l){try{if(typeof l>"u")return l;let e=JSON.stringify(l);return JSON.parse(e)}catch(e){throw _t.error("Error creating exportable element",l,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var ye=typeof window<"u"&&typeof document<"u",he=[" _______ _ _ _ ____ ____ ____ _____ ","|_ __ \\ (_) (_) | | |_ _| |_ _||_ \\|_ _|"," | |__) |__ _ __ __ \\_| \\ \\ / / | \\ | | "," | ___/[ | [ \\ [ ][ | \\ \\ / / | |\\ \\| | "," _| |_ | | > ' < | | \\ ' / _| |_\\ |_ ",`|_____| [___][__]\`\\_][___] \\_/ |_____|\\____| v${Wt.version}`],ce=31,xe="background:#2f90da;color:#fff;font-weight:bold;",Ee="background:#c832bb;color:#fff;font-weight:bold;",be="background:transparent;font-weight:bold;",qt=` v${Wt.version}`;function de(){if(!ye)return;let l=[],e=[];for(let i=0;i<he.length;i++){let s=he[i],r=s.endsWith(qt),n=r?s.slice(0,-qt.length):s,o=n.slice(0,ce),h=n.slice(ce),d=r?"%c%s%c%s%c%s":"%c%s%c%s";l.push(d),e.push(xe,o,Ee,h),r&&e.push(be,qt);}console.info(l.join(`
2
+ `),...e);}function $t(){let l=window.location.pathname+window.location.hash;return l.includes("#")&&(l=l.split("#")[1]),l}de();exports.Game=void 0;(g=>{async function l(u,x,T){if(core.GameUnifier.init({navigate:x?.navigate,getCurrentGameStepState:()=>{let p={};try{p=at__namespace.canvas.export();}catch{}return {path:$t(),storage:G__namespace.storage.export(),canvas:p,sound:ut__namespace.sound.export(),labelIndex:R__namespace.NarrationManagerStatic.currentLabelStepIndex||0,openedLabels:R__namespace.narration.openedLabels}},restoreGameStepState:async(p,A)=>{it__namespace.HistoryManagerStatic._originalStepData=p,R__namespace.NarrationManagerStatic.openedLabels=p.openedLabels,G__namespace.storage.restore(p.storage);try{await at__namespace.canvas.restore(p.canvas),await ut__namespace.sound.restore(p.sound);}catch(N){_t.error("Error restoring game step state:",N);}await A(p.path);},getStepCounter:()=>R__namespace.narration.stepCounter,setStepCounter:p=>{R__namespace.NarrationManagerStatic._stepCounter=p;},getOpenedLabels:()=>R__namespace.narration.openedLabels.length,addHistoryItem:(p,A)=>it__namespace.stepHistory.add(p,A),getCharacter:p=>Bt__namespace.RegisteredCharacters.get(p),processNavigationRequests:(p,A)=>{let N=p,K=Promise.resolve();return p>0?(N--,K=R__namespace.narration.continue(A)):p<0&&(N=0,K=it__namespace.stepHistory.back(A,{steps:p*-1})),{newValue:N,result:K}},animate:(p,A,N,K)=>motion.motion.animate(p,A,N,K),getVariable:(p,A)=>G__namespace.StorageRegistry.getVariable(p,A),setVariable:(p,A,N)=>G__namespace.StorageRegistry.setVariable(p,A,N),removeVariable:(p,A)=>G__namespace.StorageRegistry.removeVariable(p,A),getFlag:p=>G__namespace.storage.getFlag(p),setFlag:(p,A)=>G__namespace.storage.setFlag(p,A),onLabelClosing:p=>G__namespace.StorageRegistry.clearOldTempVariables(p)}),!u||!x){_t.warn("The canvas element or options are not defined. The canvas will not be initialized.");return}return await at__namespace.canvas.init(u,x,T)}g.init=l;function e(){G__namespace.storage.clear();try{at__namespace.canvas.clear();}catch{}ut__namespace.sound.clear(),R__namespace.narration.clear(),it__namespace.stepHistory.clear();}g.clear=e;function i(){let u={};try{u=at__namespace.canvas.export();}catch{}return {pixivn_version:Ut,stepData:R__namespace.narration.export(),storageData:G__namespace.storage.export(),canvasData:u,soundData:ut__namespace.sound.export(),historyData:it__namespace.stepHistory.export(),path:$t()}}g.exportGameState=i;async function s(u,x){it__namespace.stepHistory.restore(u.historyData);let T=it__namespace.stepHistory.lastKey;if(typeof T=="number"){let p=it__namespace.stepHistory.stepsInfoMap.get(T)||null;await R__namespace.narration.restore(u.stepData,p);}G__namespace.storage.restore(u.storageData);try{await at__namespace.canvas.restore(u.canvasData),await ut__namespace.sound.restore(u.soundData);}catch{}x?await x(u.path):await core.GameUnifier.navigate(u.path);}g.restoreGameState=s;async function r(u,x){return g.clear(),await R__namespace.narration.call(u,x)}g.start=r;function n(u){return JSON.parse(u)}g.jsonToGameState=n;function o(u){core.GameUnifier.onEnd=u;}g.onEnd=o;function h(u){return _t.warn("Game.onError is deprecated. Use Game.addOnError / Game.removeOnError to register multiple handlers."),core.GameUnifier.addOnError((x,T)=>u("step",x,T))}g.onError=h;function d(u){return core.GameUnifier.addOnError(u)}g.addOnError=d;function v(u){return core.GameUnifier.removeOnError(u)}g.removeOnError=v;function L(u){R__namespace.NarrationManagerStatic.onStepStart=u;}g.onStepStart=L;function S(u){R__namespace.NarrationManagerStatic.onLoadingLabel=u;}g.onLoadingLabel=S;function ot(u){R__namespace.NarrationManagerStatic.onStepEnd=u;}g.onStepEnd=ot;function M(u){R__namespace.NarrationManagerStatic.onLabelStarting=u;}g.onLabelStarting=M;function q(u){core.GameUnifier.navigate=u;}g.onNavigate=q;function w(u){return core.GameUnifier.addOnPreContinue(u)}g.addOnPreContinue=w;function y(u){return core.GameUnifier.removeOnPreContinue(u)}g.removeOnPreContinue=y;})(exports.Game||={});var Ze={characterUtils:Bt__namespace,canvasUtils:at__namespace,narrationUtils:R__namespace,soundUtils:ut__namespace,CANVAS_APP_GAME_LAYER_ALIAS:Kt,Pause:Ht,Repeat:Yt,PIXIVN_VERSION:Ut,...kt,...ae,canvas:at__namespace.canvas,narration:R__namespace.narration,sound:ut__namespace.sound,storage:G__namespace.storage,history:it__namespace.stepHistory,Game:exports.Game,GameUnifier:core.GameUnifier};exports.CANVAS_APP_GAME_LAYER_ALIAS=Kt;exports.CachedMap=Nt;exports.PIXIVN_VERSION=Ut;exports.Pause=Ht;exports.Repeat=Yt;exports.SYSTEM_RESERVED_STORAGE_KEYS=ve;exports.createExportableElement=le;exports.default=Ze;Object.keys(at).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return at[k]}})});Object.keys(Bt).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return Bt[k]}})});Object.keys(core).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return core[k]}})});Object.keys(it).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return it[k]}})});Object.keys(R).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return R[k]}})});Object.keys(ut).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return ut[k]}})});Object.keys(G).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return G[k]}})});
package/dist/index.d.cts CHANGED
@@ -29,7 +29,7 @@ import './HistoryStep-G9dUn0Lf.cjs';
29
29
  import 'microdiff';
30
30
  import './StorageElementType-C7ETezlL.cjs';
31
31
 
32
- var version = "1.8.24";
32
+ var version = "1.8.25";
33
33
 
34
34
  /**
35
35
  * @deprecated
@@ -325,6 +325,27 @@ declare namespace Game {
325
325
  * @returns
326
326
  */
327
327
  function onStepEnd(value: (stepId: number, label: narrationUtils.LabelAbstract<any>) => void | Promise<void>): void;
328
+ /**
329
+ * Is a function that will be executed every time a label is about to be started, either via
330
+ * `narration.call`, `narration.jump`, or a choice of type `"call"` / `"jump"`.
331
+ *
332
+ * By default (when this is not set), the label starts immediately, exactly like before this hook
333
+ * existed. If you set it, you take control: call `defaultStart()` yourself whenever you actually
334
+ * want the label to run — right away, or later (e.g. on a subsequent player action in your
335
+ * template). Until `defaultStart()` is called, nothing about the label happens: it is not added to
336
+ * the history and no step of it runs.
337
+ * @example
338
+ * ```ts
339
+ * Game.onLabelStarting((labelId, props, options, defaultStart) => {
340
+ * pendingLabelStart = defaultStart; // keep it for later, don't run it now
341
+ * })
342
+ * ```
343
+ */
344
+ function onLabelStarting(value: (labelId: narrationUtils.LabelIdType, props: narrationUtils.StepLabelPropsType, options: {
345
+ choiceMade?: number;
346
+ closeCurrentLabel?: boolean;
347
+ type: string;
348
+ }, defaultStart: () => Promise<narrationUtils.StepLabelResultType>) => narrationUtils.StepLabelResultType | Promise<narrationUtils.StepLabelResultType>): void;
328
349
  /**
329
350
  * Function to be executed when navigation is requested.
330
351
  * @example
package/dist/index.d.ts CHANGED
@@ -29,7 +29,7 @@ import './HistoryStep-G9dUn0Lf.js';
29
29
  import 'microdiff';
30
30
  import './StorageElementType-C7ETezlL.js';
31
31
 
32
- var version = "1.8.24";
32
+ var version = "1.8.25";
33
33
 
34
34
  /**
35
35
  * @deprecated
@@ -325,6 +325,27 @@ declare namespace Game {
325
325
  * @returns
326
326
  */
327
327
  function onStepEnd(value: (stepId: number, label: narrationUtils.LabelAbstract<any>) => void | Promise<void>): void;
328
+ /**
329
+ * Is a function that will be executed every time a label is about to be started, either via
330
+ * `narration.call`, `narration.jump`, or a choice of type `"call"` / `"jump"`.
331
+ *
332
+ * By default (when this is not set), the label starts immediately, exactly like before this hook
333
+ * existed. If you set it, you take control: call `defaultStart()` yourself whenever you actually
334
+ * want the label to run — right away, or later (e.g. on a subsequent player action in your
335
+ * template). Until `defaultStart()` is called, nothing about the label happens: it is not added to
336
+ * the history and no step of it runs.
337
+ * @example
338
+ * ```ts
339
+ * Game.onLabelStarting((labelId, props, options, defaultStart) => {
340
+ * pendingLabelStart = defaultStart; // keep it for later, don't run it now
341
+ * })
342
+ * ```
343
+ */
344
+ function onLabelStarting(value: (labelId: narrationUtils.LabelIdType, props: narrationUtils.StepLabelPropsType, options: {
345
+ choiceMade?: number;
346
+ closeCurrentLabel?: boolean;
347
+ type: string;
348
+ }, defaultStart: () => Promise<narrationUtils.StepLabelResultType>) => narrationUtils.StepLabelResultType | Promise<narrationUtils.StepLabelResultType>): void;
328
349
  /**
329
350
  * Function to be executed when navigation is requested.
330
351
  * @example
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {f as f$1,b as b$1,g,e,d,h,i}from'./chunk-K7JIC2F2.mjs';import*as nt from'@drincs/pixi-vn/canvas';export*from'@drincs/pixi-vn/canvas';import*as $t from'@drincs/pixi-vn/characters';export*from'@drincs/pixi-vn/characters';import {PixiError,GameUnifier}from'@drincs/pixi-vn/core';export*from'@drincs/pixi-vn/core';import*as et from'@drincs/pixi-vn/history';export*from'@drincs/pixi-vn/history';import*as L from'@drincs/pixi-vn/narration';export*from'@drincs/pixi-vn/narration';import*as pt from'@drincs/pixi-vn/sound';export*from'@drincs/pixi-vn/sound';import*as G from'@drincs/pixi-vn/storage';export*from'@drincs/pixi-vn/storage';import {motion}from'@drincs/pixi-vn/motion';var de=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Qt=new Set,jt=typeof process=="object"&&process?process:{},Zt=(m,e,i,s)=>{typeof jt.emitWarning=="function"?jt.emitWarning(m,e,i,s):console.error(`[${i}] ${e}: ${m}`);},Nt=globalThis.AbortController,Bt=globalThis.AbortSignal;if(typeof Nt>"u"){Bt=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},Nt=class{constructor(){e();}signal=new Bt;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 m=jt.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{m&&(m=false,Zt("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 pe=m=>!Qt.has(m);var at=m=>m&&m===Math.floor(m)&&m>0&&isFinite(m),te=m=>at(m)?m<=Math.pow(2,8)?Uint8Array:m<=Math.pow(2,16)?Uint16Array:m<=Math.pow(2,32)?Uint32Array:m<=Number.MAX_SAFE_INTEGER?Dt:null:null,Dt=class extends Array{constructor(m){super(m),this.fill(0);}},it,St,ue=(it=class{heap;length;static create(e){let i=te(e);if(!i)return [];g(it,St,true);let s=new it(e,i);return g(it,St,false),s}constructor(e$1,i){if(!e(it,St))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new i(e$1),this.length=0;}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},St=new WeakMap,f$1(it,St,false),it),Xt,Jt,K,M,q,ut,$,yt,xt,B,O,X,T,b,f,P,z,N,R,J,D,Q,Z,V,W,tt,dt,j,Et,l,Gt,ft,ot,Tt,Y,ie,mt,bt,Ot,lt,ht,It,Lt,Ct,E,Mt,At,ct,zt,wt,ee=(wt=class{constructor(e$1){f$1(this,l);f$1(this,K);f$1(this,M);f$1(this,q);f$1(this,ut);f$1(this,$);f$1(this,yt);f$1(this,xt);f$1(this,B);d(this,"ttl");d(this,"ttlResolution");d(this,"ttlAutopurge");d(this,"updateAgeOnGet");d(this,"updateAgeOnHas");d(this,"allowStale");d(this,"noDisposeOnSet");d(this,"noUpdateTTL");d(this,"maxEntrySize");d(this,"sizeCalculation");d(this,"noDeleteOnFetchRejection");d(this,"noDeleteOnStaleGet");d(this,"allowStaleOnFetchAbort");d(this,"allowStaleOnFetchRejection");d(this,"ignoreFetchAbort");f$1(this,O);f$1(this,X);f$1(this,T);f$1(this,b);f$1(this,f);f$1(this,P);f$1(this,z);f$1(this,N);f$1(this,R);f$1(this,J);f$1(this,D);f$1(this,Q);f$1(this,Z);f$1(this,V);f$1(this,W);f$1(this,tt);f$1(this,dt);f$1(this,j);f$1(this,Et);f$1(this,ft,()=>{});f$1(this,ot,()=>{});f$1(this,Tt,()=>{});f$1(this,Y,()=>false);f$1(this,mt,e=>{});f$1(this,bt,(e,i,s)=>{});f$1(this,Ot,(e,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});d(this,Xt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:h$1,allowStale:d$1,dispose:v,onInsert:U,disposeAfter:S,noDisposeOnSet:rt,noUpdateTTL:I,maxSize:k=0,maxEntrySize:w=0,sizeCalculation:y,fetchMethod:a,memoMethod:x,noDeleteOnFetchRejection:A,noDeleteOnStaleGet:u,allowStaleOnFetchRejection:g$1,allowStaleOnFetchAbort:F,ignoreFetchAbort:H,perf:_t}=e$1;if(_t!==void 0&&typeof _t?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(g(this,B,_t??de),i!==0&&!at(i))throw new TypeError("max option must be a nonnegative integer");let vt=i?te(i):Array;if(!vt)throw new Error("invalid max value: "+i);if(g(this,K,i),g(this,M,k),this.maxEntrySize=w||e(this,M),this.sizeCalculation=y,this.sizeCalculation){if(!e(this,M)&&!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(x!==void 0&&typeof x!="function")throw new TypeError("memoMethod must be a function if defined");if(g(this,xt,x),a!==void 0&&typeof a!="function")throw new TypeError("fetchMethod must be a function if specified");if(g(this,yt,a),g(this,dt,!!a),g(this,T,new Map),g(this,b,new Array(i).fill(void 0)),g(this,f,new Array(i).fill(void 0)),g(this,P,new vt(i)),g(this,z,new vt(i)),g(this,N,0),g(this,R,0),g(this,J,ue.create(i)),g(this,O,0),g(this,X,0),typeof v=="function"&&g(this,q,v),typeof U=="function"&&g(this,ut,U),typeof S=="function"?(g(this,$,S),g(this,D,[])):(g(this,$,void 0),g(this,D,void 0)),g(this,tt,!!e(this,q)),g(this,Et,!!e(this,ut)),g(this,j,!!e(this,$)),this.noDisposeOnSet=!!rt,this.noUpdateTTL=!!I,this.noDeleteOnFetchRejection=!!A,this.allowStaleOnFetchRejection=!!g$1,this.allowStaleOnFetchAbort=!!F,this.ignoreFetchAbort=!!H,this.maxEntrySize!==0){if(e(this,M)!==0&&!at(e(this,M)))throw new TypeError("maxSize must be a positive integer if specified");if(!at(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");h(this,l,ie).call(this);}if(this.allowStale=!!d$1,this.noDeleteOnStaleGet=!!u,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!h$1,this.ttlResolution=at(r)||r===0?r:1,this.ttlAutopurge=!!n,this.ttl=s||0,this.ttl){if(!at(this.ttl))throw new TypeError("ttl must be a positive integer if specified");h(this,l,Gt).call(this);}if(e(this,K)===0&&this.ttl===0&&e(this,M)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!e(this,K)&&!e(this,M)){let Pt="LRU_CACHE_UNBOUNDED";pe(Pt)&&(Qt.add(Pt),Zt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Pt,wt));}}get perf(){return e(this,B)}static unsafeExposeInternals(e$1){return {starts:e(e$1,Z),ttls:e(e$1,V),autopurgeTimers:e(e$1,W),sizes:e(e$1,Q),keyMap:e(e$1,T),keyList:e(e$1,b),valList:e(e$1,f),next:e(e$1,P),prev:e(e$1,z),get head(){return e(e$1,N)},get tail(){return e(e$1,R)},free:e(e$1,J),isBackgroundFetch:i=>{var s;return h(s=e$1,l,E).call(s,i)},backgroundFetch:(i,s,r,n)=>{var o;return h(o=e$1,l,Ct).call(o,i,s,r,n)},moveToTail:i=>{var s;return h(s=e$1,l,At).call(s,i)},indexes:i=>{var s;return h(s=e$1,l,lt).call(s,i)},rindexes:i=>{var s;return h(s=e$1,l,ht).call(s,i)},isStale:i=>{var s;return e(s=e$1,Y).call(s,i)}}}get max(){return e(this,K)}get maxSize(){return e(this,M)}get calculatedSize(){return e(this,X)}get size(){return e(this,O)}get fetchMethod(){return e(this,yt)}get memoMethod(){return e(this,xt)}get dispose(){return e(this,q)}get onInsert(){return e(this,ut)}get disposeAfter(){return e(this,$)}getRemainingTTL(e$1){return e(this,T).has(e$1)?1/0:0}*entries(){for(let e$1 of h(this,l,lt).call(this))e(this,f)[e$1]!==void 0&&e(this,b)[e$1]!==void 0&&!h(this,l,E).call(this,e(this,f)[e$1])&&(yield [e(this,b)[e$1],e(this,f)[e$1]]);}*rentries(){for(let e$1 of h(this,l,ht).call(this))e(this,f)[e$1]!==void 0&&e(this,b)[e$1]!==void 0&&!h(this,l,E).call(this,e(this,f)[e$1])&&(yield [e(this,b)[e$1],e(this,f)[e$1]]);}*keys(){for(let e$1 of h(this,l,lt).call(this)){let i=e(this,b)[e$1];i!==void 0&&!h(this,l,E).call(this,e(this,f)[e$1])&&(yield i);}}*rkeys(){for(let e$1 of h(this,l,ht).call(this)){let i=e(this,b)[e$1];i!==void 0&&!h(this,l,E).call(this,e(this,f)[e$1])&&(yield i);}}*values(){for(let e$1 of h(this,l,lt).call(this))e(this,f)[e$1]!==void 0&&!h(this,l,E).call(this,e(this,f)[e$1])&&(yield e(this,f)[e$1]);}*rvalues(){for(let e$1 of h(this,l,ht).call(this))e(this,f)[e$1]!==void 0&&!h(this,l,E).call(this,e(this,f)[e$1])&&(yield e(this,f)[e$1]);}[(Jt=Symbol.iterator,Xt=Symbol.toStringTag,Jt)](){return this.entries()}find(e$1,i={}){for(let s of h(this,l,lt).call(this)){let r=e(this,f)[s],n=h(this,l,E).call(this,r)?r.__staleWhileFetching:r;if(n!==void 0&&e$1(n,e(this,b)[s],this))return this.get(e(this,b)[s],i)}}forEach(e$1,i=this){for(let s of h(this,l,lt).call(this)){let r=e(this,f)[s],n=h(this,l,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e$1.call(i,n,e(this,b)[s],this);}}rforEach(e$1,i=this){for(let s of h(this,l,ht).call(this)){let r=e(this,f)[s],n=h(this,l,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e$1.call(i,n,e(this,b)[s],this);}}purgeStale(){let e$1=false;for(let i of h(this,l,ht).call(this,{allowStale:true}))e(this,Y).call(this,i)&&(h(this,l,ct).call(this,e(this,b)[i],"expire"),e$1=true);return e$1}info(e$1){let i=e(this,T).get(e$1);if(i===void 0)return;let s=e(this,f)[i],r=h(this,l,E).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let n={value:r};if(e(this,V)&&e(this,Z)){let o=e(this,V)[i],h=e(this,Z)[i];if(o&&h){let d=o-(e(this,B).now()-h);n.ttl=d,n.start=Date.now();}}return e(this,Q)&&(n.size=e(this,Q)[i]),n}dump(){let e$1=[];for(let i of h(this,l,lt).call(this,{allowStale:true})){let s=e(this,b)[i],r=e(this,f)[i],n=h(this,l,E).call(this,r)?r.__staleWhileFetching:r;if(n===void 0||s===void 0)continue;let o={value:n};if(e(this,V)&&e(this,Z)){o.ttl=e(this,V)[i];let h=e(this,B).now()-e(this,Z)[i];o.start=Math.floor(Date.now()-h);}e(this,Q)&&(o.size=e(this,Q)[i]),e$1.unshift([s,o]);}return e$1}load(e$1){this.clear();for(let[i,s]of e$1){if(s.start){let r=Date.now()-s.start;s.start=e(this,B).now()-r;}this.set(i,s.value,s);}}set(e$1,i$1,s={}){var rt,I,k,w;if(i$1===void 0)return this.delete(e$1),this;let{ttl:r=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:h$1=this.sizeCalculation,status:d}=s,{noUpdateTTL:v=this.noUpdateTTL}=s,U=e(this,Ot).call(this,e$1,i$1,s.size||0,h$1);if(this.maxEntrySize&&U>this.maxEntrySize)return d&&(d.set="miss",d.maxEntrySizeExceeded=true),h(this,l,ct).call(this,e$1,"set"),this;let S=e(this,O)===0?void 0:e(this,T).get(e$1);if(S===void 0)S=e(this,O)===0?e(this,R):e(this,J).length!==0?e(this,J).pop():e(this,O)===e(this,K)?h(this,l,Lt).call(this,false):e(this,O),e(this,b)[S]=e$1,e(this,f)[S]=i$1,e(this,T).set(e$1,S),e(this,P)[e(this,R)]=S,e(this,z)[S]=e(this,R),g(this,R,S),i(this,O)._++,e(this,bt).call(this,S,U,d),d&&(d.set="add"),v=false,e(this,Et)&&((rt=e(this,ut))==null||rt.call(this,i$1,e$1,"add"));else {h(this,l,At).call(this,S);let y=e(this,f)[S];if(i$1!==y){if(e(this,dt)&&h(this,l,E).call(this,y)){y.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:a}=y;a!==void 0&&!o&&(e(this,tt)&&((I=e(this,q))==null||I.call(this,a,e$1,"set")),e(this,j)&&e(this,D)?.push([a,e$1,"set"]));}else o||(e(this,tt)&&((k=e(this,q))==null||k.call(this,y,e$1,"set")),e(this,j)&&e(this,D)?.push([y,e$1,"set"]));if(e(this,mt).call(this,S),e(this,bt).call(this,S,U,d),e(this,f)[S]=i$1,d){d.set="replace";let a=y&&h(this,l,E).call(this,y)?y.__staleWhileFetching:y;a!==void 0&&(d.oldValue=a);}}else d&&(d.set="update");e(this,Et)&&this.onInsert?.(i$1,e$1,i$1===y?"update":"replace");}if(r!==0&&!e(this,V)&&h(this,l,Gt).call(this),e(this,V)&&(v||e(this,Tt).call(this,S,r,n),d&&e(this,ot).call(this,d,S)),!o&&e(this,j)&&e(this,D)){let y=e(this,D),a;for(;a=y?.shift();)(w=e(this,$))==null||w.call(this,...a);}return this}pop(){var e$1;try{for(;e(this,O);){let i=e(this,f)[e(this,N)];if(h(this,l,Lt).call(this,!0),h(this,l,E).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(e(this,j)&&e(this,D)){let i=e(this,D),s;for(;s=i?.shift();)(e$1=e(this,$))==null||e$1.call(this,...s);}}}has(e$1,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=i,n=e(this,T).get(e$1);if(n!==void 0){let o=e(this,f)[n];if(h(this,l,E).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(e(this,Y).call(this,n))r&&(r.has="stale",e(this,ot).call(this,r,n));else return s&&e(this,ft).call(this,n),r&&(r.has="hit",e(this,ot).call(this,r,n)),true}else r&&(r.has="miss");return false}peek(e$1,i={}){let{allowStale:s=this.allowStale}=i,r=e(this,T).get(e$1);if(r===void 0||!s&&e(this,Y).call(this,r))return;let n=e(this,f)[r];return h(this,l,E).call(this,n)?n.__staleWhileFetching:n}async fetch(e$1,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:h$1=this.noDisposeOnSet,size:d=0,sizeCalculation:v=this.sizeCalculation,noUpdateTTL:U=this.noUpdateTTL,noDeleteOnFetchRejection:S=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:rt=this.allowStaleOnFetchRejection,ignoreFetchAbort:I=this.ignoreFetchAbort,allowStaleOnFetchAbort:k=this.allowStaleOnFetchAbort,context:w,forceRefresh:y=false,status:a,signal:x}=i;if(!e(this,dt))return a&&(a.fetch="get"),this.get(e$1,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,status:a});let A={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:h$1,size:d,sizeCalculation:v,noUpdateTTL:U,noDeleteOnFetchRejection:S,allowStaleOnFetchRejection:rt,allowStaleOnFetchAbort:k,ignoreFetchAbort:I,status:a,signal:x},u=e(this,T).get(e$1);if(u===void 0){a&&(a.fetch="miss");let g=h(this,l,Ct).call(this,e$1,u,A,w);return g.__returned=g}else {let g=e(this,f)[u];if(h(this,l,E).call(this,g)){let vt=s&&g.__staleWhileFetching!==void 0;return a&&(a.fetch="inflight",vt&&(a.returnedStale=true)),vt?g.__staleWhileFetching:g.__returned=g}let F=e(this,Y).call(this,u);if(!y&&!F)return a&&(a.fetch="hit"),h(this,l,At).call(this,u),r&&e(this,ft).call(this,u),a&&e(this,ot).call(this,a,u),g;let H=h(this,l,Ct).call(this,e$1,u,A,w),_t=H.__staleWhileFetching!==void 0&&s;return a&&(a.fetch=F?"stale":"refresh",_t&&F&&(a.returnedStale=true)),_t?H.__staleWhileFetching:H.__returned=H}}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$1,i={}){let s=e(this,xt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:n,...o}=i,h=this.get(e$1,o);if(!n&&h!==void 0)return h;let d=s(e$1,h,{options:o,context:r});return this.set(e$1,d,o),d}get(e$1,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=i,h$1=e(this,T).get(e$1);if(h$1!==void 0){let d=e(this,f)[h$1],v=h(this,l,E).call(this,d);return o&&e(this,ot).call(this,o,h$1),e(this,Y).call(this,h$1)?(o&&(o.get="stale"),v?(o&&s&&d.__staleWhileFetching!==void 0&&(o.returnedStale=true),s?d.__staleWhileFetching:void 0):(n||h(this,l,ct).call(this,e$1,"expire"),o&&s&&(o.returnedStale=true),s?d:void 0)):(o&&(o.get="hit"),v?d.__staleWhileFetching:(h(this,l,At).call(this,h$1),r&&e(this,ft).call(this,h$1),d))}else o&&(o.get="miss");}delete(e){return h(this,l,ct).call(this,e,"delete")}clear(){return h(this,l,zt).call(this,"delete")}},K=new WeakMap,M=new WeakMap,q=new WeakMap,ut=new WeakMap,$=new WeakMap,yt=new WeakMap,xt=new WeakMap,B=new WeakMap,O=new WeakMap,X=new WeakMap,T=new WeakMap,b=new WeakMap,f=new WeakMap,P=new WeakMap,z=new WeakMap,N=new WeakMap,R=new WeakMap,J=new WeakMap,D=new WeakMap,Q=new WeakMap,Z=new WeakMap,V=new WeakMap,W=new WeakMap,tt=new WeakMap,dt=new WeakMap,j=new WeakMap,Et=new WeakMap,l=new WeakSet,Gt=function(){let e$1=new Dt(e(this,K)),i=new Dt(e(this,K));g(this,V,e$1),g(this,Z,i);let s=this.ttlAutopurge?new Array(e(this,K)):void 0;g(this,W,s),g(this,Tt,(h,d,v=e(this,B).now())=>{i[h]=d!==0?v:0,e$1[h]=d,r(h,d);}),g(this,ft,h=>{i[h]=e$1[h]!==0?e(this,B).now():0,r(h,e$1[h]);});let r=this.ttlAutopurge?(h$1,d)=>{if(s?.[h$1]&&(clearTimeout(s[h$1]),s[h$1]=void 0),d&&d!==0&&s){let v=setTimeout(()=>{e(this,Y).call(this,h$1)&&h(this,l,ct).call(this,e(this,b)[h$1],"expire");},d+1);v.unref&&v.unref(),s[h$1]=v;}}:()=>{};g(this,ot,(h,d)=>{if(e$1[d]){let v=e$1[d],U=i[d];if(!v||!U)return;h.ttl=v,h.start=U,h.now=n||o();let S=h.now-U;h.remainingTTL=v-S;}});let n=0,o=()=>{let h=e(this,B).now();if(this.ttlResolution>0){n=h;let d=setTimeout(()=>n=0,this.ttlResolution);d.unref&&d.unref();}return h};this.getRemainingTTL=h=>{let d=e(this,T).get(h);if(d===void 0)return 0;let v=e$1[d],U=i[d];if(!v||!U)return 1/0;let S=(n||o())-U;return v-S},g(this,Y,h=>{let d=i[h],v=e$1[h];return !!v&&!!d&&(n||o())-d>v});},ft=new WeakMap,ot=new WeakMap,Tt=new WeakMap,Y=new WeakMap,ie=function(){let e$1=new Dt(e(this,K));g(this,X,0),g(this,Q,e$1),g(this,mt,i=>{g(this,X,e(this,X)-e$1[i]),e$1[i]=0;}),g(this,Ot,(i,s,r,n)=>{if(h(this,l,E).call(this,s))return 0;if(!at(r))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(r=n(s,i),!at(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}),g(this,bt,(i,s,r)=>{if(e$1[i]=s,e(this,M)){let n=e(this,M)-e$1[i];for(;e(this,X)>n;)h(this,l,Lt).call(this,true);}g(this,X,e(this,X)+e$1[i]),r&&(r.entrySize=s,r.totalCalculatedSize=e(this,X));});},mt=new WeakMap,bt=new WeakMap,Ot=new WeakMap,lt=function*({allowStale:e$1=this.allowStale}={}){if(e(this,O))for(let i=e(this,R);!(!h(this,l,It).call(this,i)||((e$1||!e(this,Y).call(this,i))&&(yield i),i===e(this,N)));)i=e(this,z)[i];},ht=function*({allowStale:e$1=this.allowStale}={}){if(e(this,O))for(let i=e(this,N);!(!h(this,l,It).call(this,i)||((e$1||!e(this,Y).call(this,i))&&(yield i),i===e(this,R)));)i=e(this,P)[i];},It=function(e$1){return e$1!==void 0&&e(this,T).get(e(this,b)[e$1])===e$1},Lt=function(e$1){var n;let i$1=e(this,N),s=e(this,b)[i$1],r=e(this,f)[i$1];return e(this,dt)&&h(this,l,E).call(this,r)?r.__abortController.abort(new Error("evicted")):(e(this,tt)||e(this,j))&&(e(this,tt)&&((n=e(this,q))==null||n.call(this,r,s,"evict")),e(this,j)&&e(this,D)?.push([r,s,"evict"])),e(this,mt).call(this,i$1),e(this,W)?.[i$1]&&(clearTimeout(e(this,W)[i$1]),e(this,W)[i$1]=void 0),e$1&&(e(this,b)[i$1]=void 0,e(this,f)[i$1]=void 0,e(this,J).push(i$1)),e(this,O)===1?(g(this,N,g(this,R,0)),e(this,J).length=0):g(this,N,e(this,P)[i$1]),e(this,T).delete(s),i(this,O)._--,i$1},Ct=function(e$1,i,s,r){let n=i===void 0?void 0:e(this,f)[i];if(h(this,l,E).call(this,n))return n;let o=new Nt,{signal:h$1}=s;h$1?.addEventListener("abort",()=>o.abort(h$1.reason),{signal:o.signal});let d={signal:o.signal,options:s,context:r},v=(w,y=false)=>{let{aborted:a}=o.signal,x=s.ignoreFetchAbort&&w!==void 0,A=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&w!==void 0);if(s.status&&(a&&!y?(s.status.fetchAborted=true,s.status.fetchError=o.signal.reason,x&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),a&&!x&&!y)return S(o.signal.reason,A);let u=I,g=e(this,f)[i];return (g===I||x&&y&&g===void 0)&&(w===void 0?u.__staleWhileFetching!==void 0?e(this,f)[i]=u.__staleWhileFetching:h(this,l,ct).call(this,e$1,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(e$1,w,d.options))),w},U=w=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=w),S(w,false)),S=(w,y)=>{let{aborted:a}=o.signal,x=a&&s.allowStaleOnFetchAbort,A=x||s.allowStaleOnFetchRejection,u=A||s.noDeleteOnFetchRejection,g=I;if(e(this,f)[i]===I&&(!u||!y&&g.__staleWhileFetching===void 0?h(this,l,ct).call(this,e$1,"fetch"):x||(e(this,f)[i]=g.__staleWhileFetching)),A)return s.status&&g.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),g.__staleWhileFetching;if(g.__returned===g)throw w},rt=(w,y)=>{var x;let a=(x=e(this,yt))==null?void 0:x.call(this,e$1,n,d);a&&a instanceof Promise&&a.then(A=>w(A===void 0?void 0:A),y),o.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(w(void 0),s.allowStaleOnFetchAbort&&(w=A=>v(A,true)));});};s.status&&(s.status.fetchDispatched=true);let I=new Promise(rt).then(v,U),k=Object.assign(I,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return i===void 0?(this.set(e$1,k,{...d.options,status:void 0}),i=e(this,T).get(e$1)):e(this,f)[i]=k,k},E=function(e$1){if(!e(this,dt))return false;let i=e$1;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Nt},Mt=function(e$1,i){e(this,z)[i]=e$1,e(this,P)[e$1]=i;},At=function(e$1){e$1!==e(this,R)&&(e$1===e(this,N)?g(this,N,e(this,P)[e$1]):h(this,l,Mt).call(this,e(this,z)[e$1],e(this,P)[e$1]),h(this,l,Mt).call(this,e(this,R),e$1),g(this,R,e$1));},ct=function(e$1,i$1){var r,n;let s=false;if(e(this,O)!==0){let o=e(this,T).get(e$1);if(o!==void 0)if(e(this,W)?.[o]&&(clearTimeout(e(this,W)?.[o]),e(this,W)[o]=void 0),s=true,e(this,O)===1)h(this,l,zt).call(this,i$1);else {e(this,mt).call(this,o);let h$1=e(this,f)[o];if(h(this,l,E).call(this,h$1)?h$1.__abortController.abort(new Error("deleted")):(e(this,tt)||e(this,j))&&(e(this,tt)&&((r=e(this,q))==null||r.call(this,h$1,e$1,i$1)),e(this,j)&&e(this,D)?.push([h$1,e$1,i$1])),e(this,T).delete(e$1),e(this,b)[o]=void 0,e(this,f)[o]=void 0,o===e(this,R))g(this,R,e(this,z)[o]);else if(o===e(this,N))g(this,N,e(this,P)[o]);else {let d=e(this,z)[o];e(this,P)[d]=e(this,P)[o];let v=e(this,P)[o];e(this,z)[v]=e(this,z)[o];}i(this,O)._--,e(this,J).push(o);}}if(e(this,j)&&e(this,D)?.length){let o=e(this,D),h;for(;h=o?.shift();)(n=e(this,$))==null||n.call(this,...h);}return s},zt=function(e$1){var i,s;for(let r of h(this,l,ht).call(this,{allowStale:true})){let n=e(this,f)[r];if(h(this,l,E).call(this,n))n.__abortController.abort(new Error("deleted"));else {let o=e(this,b)[r];e(this,tt)&&((i=e(this,q))==null||i.call(this,n,o,e$1)),e(this,j)&&e(this,D)?.push([n,o,e$1]);}}if(e(this,T).clear(),e(this,f).fill(void 0),e(this,b).fill(void 0),e(this,V)&&e(this,Z)){e(this,V).fill(0),e(this,Z).fill(0);for(let r of e(this,W)??[])r!==void 0&&clearTimeout(r);e(this,W)?.fill(void 0);}if(e(this,Q)&&e(this,Q).fill(0),g(this,N,0),g(this,R,0),e(this,J).length=0,g(this,X,0),g(this,O,0),e(this,j)&&e(this,D)){let r=e(this,D),n;for(;n=r?.shift();)(s=e(this,$))==null||s.call(this,...n);}},wt);var Ft=class{cache;map=new Map;constructor(e){this.cache=new ee({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 Ut="1.8.24";var Vt={version:Ut};var Wt="repeat";function Yt(m){return {type:"pause",duration:m}}var Ht="__game_layer__";var fe={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 re={};var Kt={};b$1(Kt,{createExportableElement:()=>oe});var gt;(r=>(r.log=(n,...o)=>console.log(`[Pixi\u2019VN] ${n}`,...o),r.warn=(n,...o)=>console.warn(`[Pixi\u2019VN] ${n}`,...o),r.error=(n,...o)=>console.error(`[Pixi\u2019VN] ${n}`,...o),r.info=(n,...o)=>console.info(`[Pixi\u2019VN] ${n}`,...o)))(gt||={});function oe(m){try{if(typeof m>"u")return m;let e=JSON.stringify(m);return JSON.parse(e)}catch(e){throw gt.error("Error creating exportable element",m,e),new PixiError("not_json_serializable","Error creating exportable element")}}var ge=typeof window<"u"&&typeof document<"u",ne=[" _______ _ _ _ ____ ____ ____ _____ ","|_ __ \\ (_) (_) | | |_ _| |_ _||_ \\|_ _|"," | |__) |__ _ __ __ \\_| \\ \\ / / | \\ | | "," | ___/[ | [ \\ [ ][ | \\ \\ / / | |\\ \\| | "," _| |_ | | > ' < | | \\ ' / _| |_\\ |_ ",`|_____| [___][__]\`\\_][___] \\_/ |_____|\\____| v${Vt.version}`],ae=31,_e="background:#2f90da;color:#fff;font-weight:bold;",ve="background:#c832bb;color:#fff;font-weight:bold;",Se="background:transparent;font-weight:bold;",kt=` v${Vt.version}`;function le(){if(!ge)return;let m=[],e=[];for(let i=0;i<ne.length;i++){let s=ne[i],r=s.endsWith(kt),n=r?s.slice(0,-kt.length):s,o=n.slice(0,ae),h=n.slice(ae),d=r?"%c%s%c%s%c%s":"%c%s%c%s";m.push(d),e.push(_e,o,ve,h),r&&e.push(Se,kt);}console.info(m.join(`
2
- `),...e);}function qt(){let m=window.location.pathname+window.location.hash;return m.includes("#")&&(m=m.split("#")[1]),m}le();var he;(y=>{async function m(a,x,A){if(GameUnifier.init({navigate:x?.navigate,getCurrentGameStepState:()=>{let u={};try{u=nt.canvas.export();}catch{}return {path:qt(),storage:G.storage.export(),canvas:u,sound:pt.sound.export(),labelIndex:L.NarrationManagerStatic.currentLabelStepIndex||0,openedLabels:L.narration.openedLabels}},restoreGameStepState:async(u,g)=>{et.HistoryManagerStatic._originalStepData=u,L.NarrationManagerStatic.openedLabels=u.openedLabels,G.storage.restore(u.storage);try{await nt.canvas.restore(u.canvas),await pt.sound.restore(u.sound);}catch(F){gt.error("Error restoring game step state:",F);}await g(u.path);},getStepCounter:()=>L.narration.stepCounter,setStepCounter:u=>{L.NarrationManagerStatic._stepCounter=u;},getOpenedLabels:()=>L.narration.openedLabels.length,addHistoryItem:(u,g)=>et.stepHistory.add(u,g),getCharacter:u=>$t.RegisteredCharacters.get(u),processNavigationRequests:(u,g)=>{let F=u,H=Promise.resolve();return u>0?(F--,H=L.narration.continue(g)):u<0&&(F=0,H=et.stepHistory.back(g,{steps:u*-1})),{newValue:F,result:H}},animate:(u,g,F,H)=>motion.animate(u,g,F,H),getVariable:(u,g)=>G.StorageRegistry.getVariable(u,g),setVariable:(u,g,F)=>G.StorageRegistry.setVariable(u,g,F),removeVariable:(u,g)=>G.StorageRegistry.removeVariable(u,g),getFlag:u=>G.storage.getFlag(u),setFlag:(u,g)=>G.storage.setFlag(u,g),onLabelClosing:u=>G.StorageRegistry.clearOldTempVariables(u)}),!a||!x){gt.warn("The canvas element or options are not defined. The canvas will not be initialized.");return}return await nt.canvas.init(a,x,A)}y.init=m;function e(){G.storage.clear();try{nt.canvas.clear();}catch{}pt.sound.clear(),L.narration.clear(),et.stepHistory.clear();}y.clear=e;function i(){let a={};try{a=nt.canvas.export();}catch{}return {pixivn_version:Ut,stepData:L.narration.export(),storageData:G.storage.export(),canvasData:a,soundData:pt.sound.export(),historyData:et.stepHistory.export(),path:qt()}}y.exportGameState=i;async function s(a,x){et.stepHistory.restore(a.historyData);let A=et.stepHistory.lastKey;if(typeof A=="number"){let u=et.stepHistory.stepsInfoMap.get(A)||null;await L.narration.restore(a.stepData,u);}G.storage.restore(a.storageData);try{await nt.canvas.restore(a.canvasData),await pt.sound.restore(a.soundData);}catch{}x?await x(a.path):await GameUnifier.navigate(a.path);}y.restoreGameState=s;async function r(a,x){return y.clear(),await L.narration.call(a,x)}y.start=r;function n(a){return JSON.parse(a)}y.jsonToGameState=n;function o(a){GameUnifier.onEnd=a;}y.onEnd=o;function h(a){return gt.warn("Game.onError is deprecated. Use Game.addOnError / Game.removeOnError to register multiple handlers."),GameUnifier.addOnError((x,A)=>a("step",x,A))}y.onError=h;function d(a){return GameUnifier.addOnError(a)}y.addOnError=d;function v(a){return GameUnifier.removeOnError(a)}y.removeOnError=v;function U(a){L.NarrationManagerStatic.onStepStart=a;}y.onStepStart=U;function S(a){L.NarrationManagerStatic.onLoadingLabel=a;}y.onLoadingLabel=S;function rt(a){L.NarrationManagerStatic.onStepEnd=a;}y.onStepEnd=rt;function I(a){GameUnifier.navigate=a;}y.onNavigate=I;function k(a){return GameUnifier.addOnPreContinue(a)}y.addOnPreContinue=k;function w(a){return GameUnifier.removeOnPreContinue(a)}y.removeOnPreContinue=w;})(he||={});var $e={characterUtils:$t,canvasUtils:nt,narrationUtils:L,soundUtils:pt,CANVAS_APP_GAME_LAYER_ALIAS:Ht,Pause:Yt,Repeat:Wt,PIXIVN_VERSION:Ut,...Kt,...re,canvas:nt.canvas,narration:L.narration,sound:pt.sound,storage:G.storage,history:et.stepHistory,Game:he,GameUnifier:GameUnifier};export{Ht as CANVAS_APP_GAME_LAYER_ALIAS,Ft as CachedMap,he as Game,Ut as PIXIVN_VERSION,Yt as Pause,Wt as Repeat,fe as SYSTEM_RESERVED_STORAGE_KEYS,oe as createExportableElement,$e as default};
1
+ import {f as f$1,b as b$1,g,e,d,h,i}from'./chunk-K7JIC2F2.mjs';import*as at from'@drincs/pixi-vn/canvas';export*from'@drincs/pixi-vn/canvas';import*as $t from'@drincs/pixi-vn/characters';export*from'@drincs/pixi-vn/characters';import {PixiError,GameUnifier}from'@drincs/pixi-vn/core';export*from'@drincs/pixi-vn/core';import*as it from'@drincs/pixi-vn/history';export*from'@drincs/pixi-vn/history';import*as R from'@drincs/pixi-vn/narration';export*from'@drincs/pixi-vn/narration';import*as ut from'@drincs/pixi-vn/sound';export*from'@drincs/pixi-vn/sound';import*as G from'@drincs/pixi-vn/storage';export*from'@drincs/pixi-vn/storage';import {motion}from'@drincs/pixi-vn/motion';var de=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Qt=new Set,jt=typeof process=="object"&&process?process:{},Zt=(g,e,i,s)=>{typeof jt.emitWarning=="function"?jt.emitWarning(g,e,i,s):console.error(`[${i}] ${e}: ${g}`);},Pt=globalThis.AbortController,Bt=globalThis.AbortSignal;if(typeof Pt>"u"){Bt=class{onabort;_onabort=[];reason;aborted=false;addEventListener(i,s){this._onabort.push(s);}},Pt=class{constructor(){e();}signal=new Bt;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 g=jt.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{g&&(g=false,Zt("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 pe=g=>!Qt.has(g);var lt=g=>g&&g===Math.floor(g)&&g>0&&isFinite(g),te=g=>lt(g)?g<=Math.pow(2,8)?Uint8Array:g<=Math.pow(2,16)?Uint16Array:g<=Math.pow(2,32)?Uint32Array:g<=Number.MAX_SAFE_INTEGER?Lt:null:null,Lt=class extends Array{constructor(g){super(g),this.fill(0);}},st,St,ue=(st=class{heap;length;static create(e){let i=te(e);if(!i)return [];g(st,St,true);let s=new st(e,i);return g(st,St,false),s}constructor(e$1,i){if(!e(st,St))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new i(e$1),this.length=0;}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},St=new WeakMap,f$1(st,St,false),st),Xt,Jt,k,z,$,ft,B,yt,xt,X,U,J,O,b,f,j,V,F,D,Q,C,Z,tt,W,Y,et,pt,I,Et,a,It,mt,nt,Tt,H,ie,gt,bt,Ot,ht,ct,Gt,Dt,Ct,E,Mt,At,dt,zt,wt,ee=(wt=class{constructor(e$1){f$1(this,a);f$1(this,k);f$1(this,z);f$1(this,$);f$1(this,ft);f$1(this,B);f$1(this,yt);f$1(this,xt);f$1(this,X);d(this,"ttl");d(this,"ttlResolution");d(this,"ttlAutopurge");d(this,"updateAgeOnGet");d(this,"updateAgeOnHas");d(this,"allowStale");d(this,"noDisposeOnSet");d(this,"noUpdateTTL");d(this,"maxEntrySize");d(this,"sizeCalculation");d(this,"noDeleteOnFetchRejection");d(this,"noDeleteOnStaleGet");d(this,"allowStaleOnFetchAbort");d(this,"allowStaleOnFetchRejection");d(this,"ignoreFetchAbort");f$1(this,U);f$1(this,J);f$1(this,O);f$1(this,b);f$1(this,f);f$1(this,j);f$1(this,V);f$1(this,F);f$1(this,D);f$1(this,Q);f$1(this,C);f$1(this,Z);f$1(this,tt);f$1(this,W);f$1(this,Y);f$1(this,et);f$1(this,pt);f$1(this,I);f$1(this,Et);f$1(this,mt,()=>{});f$1(this,nt,()=>{});f$1(this,Tt,()=>{});f$1(this,H,()=>false);f$1(this,gt,e=>{});f$1(this,bt,(e,i,s)=>{});f$1(this,Ot,(e,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});d(this,Xt,"LRUCache");let{max:i=0,ttl:s,ttlResolution:r=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:l,allowStale:c,dispose:v,onInsert:L,disposeAfter:S,noDisposeOnSet:ot,noUpdateTTL:M,maxSize:q=0,maxEntrySize:w=0,sizeCalculation:y,fetchMethod:m,memoMethod:p,noDeleteOnFetchRejection:x,noDeleteOnStaleGet:T,allowStaleOnFetchRejection:d$1,allowStaleOnFetchAbort:A,ignoreFetchAbort:N,perf:K}=e$1;if(K!==void 0&&typeof K?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(g(this,X,K??de),i!==0&&!lt(i))throw new TypeError("max option must be a nonnegative integer");let vt=i?te(i):Array;if(!vt)throw new Error("invalid max value: "+i);if(g(this,k,i),g(this,z,q),this.maxEntrySize=w||e(this,z),this.sizeCalculation=y,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(p!==void 0&&typeof p!="function")throw new TypeError("memoMethod must be a function if defined");if(g(this,xt,p),m!==void 0&&typeof m!="function")throw new TypeError("fetchMethod must be a function if specified");if(g(this,yt,m),g(this,pt,!!m),g(this,O,new Map),g(this,b,new Array(i).fill(void 0)),g(this,f,new Array(i).fill(void 0)),g(this,j,new vt(i)),g(this,V,new vt(i)),g(this,F,0),g(this,D,0),g(this,Q,ue.create(i)),g(this,U,0),g(this,J,0),typeof v=="function"&&g(this,$,v),typeof L=="function"&&g(this,ft,L),typeof S=="function"?(g(this,B,S),g(this,C,[])):(g(this,B,void 0),g(this,C,void 0)),g(this,et,!!e(this,$)),g(this,Et,!!e(this,ft)),g(this,I,!!e(this,B)),this.noDisposeOnSet=!!ot,this.noUpdateTTL=!!M,this.noDeleteOnFetchRejection=!!x,this.allowStaleOnFetchRejection=!!d$1,this.allowStaleOnFetchAbort=!!A,this.ignoreFetchAbort=!!N,this.maxEntrySize!==0){if(e(this,z)!==0&&!lt(e(this,z)))throw new TypeError("maxSize must be a positive integer if specified");if(!lt(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");h(this,a,ie).call(this);}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!T,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!l,this.ttlResolution=lt(r)||r===0?r:1,this.ttlAutopurge=!!n,this.ttl=s||0,this.ttl){if(!lt(this.ttl))throw new TypeError("ttl must be a positive integer if specified");h(this,a,It).call(this);}if(e(this,k)===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,k)&&!e(this,z)){let Ft="LRU_CACHE_UNBOUNDED";pe(Ft)&&(Qt.add(Ft),Zt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Ft,wt));}}get perf(){return e(this,X)}static unsafeExposeInternals(e$1){return {starts:e(e$1,tt),ttls:e(e$1,W),autopurgeTimers:e(e$1,Y),sizes:e(e$1,Z),keyMap:e(e$1,O),keyList:e(e$1,b),valList:e(e$1,f),next:e(e$1,j),prev:e(e$1,V),get head(){return e(e$1,F)},get tail(){return e(e$1,D)},free:e(e$1,Q),isBackgroundFetch:i=>{var s;return h(s=e$1,a,E).call(s,i)},backgroundFetch:(i,s,r,n)=>{var o;return h(o=e$1,a,Ct).call(o,i,s,r,n)},moveToTail:i=>{var s;return h(s=e$1,a,At).call(s,i)},indexes:i=>{var s;return h(s=e$1,a,ht).call(s,i)},rindexes:i=>{var s;return h(s=e$1,a,ct).call(s,i)},isStale:i=>{var s;return e(s=e$1,H).call(s,i)}}}get max(){return e(this,k)}get maxSize(){return e(this,z)}get calculatedSize(){return e(this,J)}get size(){return e(this,U)}get fetchMethod(){return e(this,yt)}get memoMethod(){return e(this,xt)}get dispose(){return e(this,$)}get onInsert(){return e(this,ft)}get disposeAfter(){return e(this,B)}getRemainingTTL(e$1){return e(this,O).has(e$1)?1/0:0}*entries(){for(let e$1 of h(this,a,ht).call(this))e(this,f)[e$1]!==void 0&&e(this,b)[e$1]!==void 0&&!h(this,a,E).call(this,e(this,f)[e$1])&&(yield [e(this,b)[e$1],e(this,f)[e$1]]);}*rentries(){for(let e$1 of h(this,a,ct).call(this))e(this,f)[e$1]!==void 0&&e(this,b)[e$1]!==void 0&&!h(this,a,E).call(this,e(this,f)[e$1])&&(yield [e(this,b)[e$1],e(this,f)[e$1]]);}*keys(){for(let e$1 of h(this,a,ht).call(this)){let i=e(this,b)[e$1];i!==void 0&&!h(this,a,E).call(this,e(this,f)[e$1])&&(yield i);}}*rkeys(){for(let e$1 of h(this,a,ct).call(this)){let i=e(this,b)[e$1];i!==void 0&&!h(this,a,E).call(this,e(this,f)[e$1])&&(yield i);}}*values(){for(let e$1 of h(this,a,ht).call(this))e(this,f)[e$1]!==void 0&&!h(this,a,E).call(this,e(this,f)[e$1])&&(yield e(this,f)[e$1]);}*rvalues(){for(let e$1 of h(this,a,ct).call(this))e(this,f)[e$1]!==void 0&&!h(this,a,E).call(this,e(this,f)[e$1])&&(yield e(this,f)[e$1]);}[(Jt=Symbol.iterator,Xt=Symbol.toStringTag,Jt)](){return this.entries()}find(e$1,i={}){for(let s of h(this,a,ht).call(this)){let r=e(this,f)[s],n=h(this,a,E).call(this,r)?r.__staleWhileFetching:r;if(n!==void 0&&e$1(n,e(this,b)[s],this))return this.get(e(this,b)[s],i)}}forEach(e$1,i=this){for(let s of h(this,a,ht).call(this)){let r=e(this,f)[s],n=h(this,a,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e$1.call(i,n,e(this,b)[s],this);}}rforEach(e$1,i=this){for(let s of h(this,a,ct).call(this)){let r=e(this,f)[s],n=h(this,a,E).call(this,r)?r.__staleWhileFetching:r;n!==void 0&&e$1.call(i,n,e(this,b)[s],this);}}purgeStale(){let e$1=false;for(let i of h(this,a,ct).call(this,{allowStale:true}))e(this,H).call(this,i)&&(h(this,a,dt).call(this,e(this,b)[i],"expire"),e$1=true);return e$1}info(e$1){let i=e(this,O).get(e$1);if(i===void 0)return;let s=e(this,f)[i],r=h(this,a,E).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let n={value:r};if(e(this,W)&&e(this,tt)){let o=e(this,W)[i],l=e(this,tt)[i];if(o&&l){let c=o-(e(this,X).now()-l);n.ttl=c,n.start=Date.now();}}return e(this,Z)&&(n.size=e(this,Z)[i]),n}dump(){let e$1=[];for(let i of h(this,a,ht).call(this,{allowStale:true})){let s=e(this,b)[i],r=e(this,f)[i],n=h(this,a,E).call(this,r)?r.__staleWhileFetching:r;if(n===void 0||s===void 0)continue;let o={value:n};if(e(this,W)&&e(this,tt)){o.ttl=e(this,W)[i];let l=e(this,X).now()-e(this,tt)[i];o.start=Math.floor(Date.now()-l);}e(this,Z)&&(o.size=e(this,Z)[i]),e$1.unshift([s,o]);}return e$1}load(e$1){this.clear();for(let[i,s]of e$1){if(s.start){let r=Date.now()-s.start;s.start=e(this,X).now()-r;}this.set(i,s.value,s);}}set(e$1,i$1,s={}){var ot,M,q,w;if(i$1===void 0)return this.delete(e$1),this;let{ttl:r=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:l=this.sizeCalculation,status:c}=s,{noUpdateTTL:v=this.noUpdateTTL}=s,L=e(this,Ot).call(this,e$1,i$1,s.size||0,l);if(this.maxEntrySize&&L>this.maxEntrySize)return c&&(c.set="miss",c.maxEntrySizeExceeded=true),h(this,a,dt).call(this,e$1,"set"),this;let S=e(this,U)===0?void 0:e(this,O).get(e$1);if(S===void 0)S=e(this,U)===0?e(this,D):e(this,Q).length!==0?e(this,Q).pop():e(this,U)===e(this,k)?h(this,a,Dt).call(this,false):e(this,U),e(this,b)[S]=e$1,e(this,f)[S]=i$1,e(this,O).set(e$1,S),e(this,j)[e(this,D)]=S,e(this,V)[S]=e(this,D),g(this,D,S),i(this,U)._++,e(this,bt).call(this,S,L,c),c&&(c.set="add"),v=false,e(this,Et)&&((ot=e(this,ft))==null||ot.call(this,i$1,e$1,"add"));else {h(this,a,At).call(this,S);let y=e(this,f)[S];if(i$1!==y){if(e(this,pt)&&h(this,a,E).call(this,y)){y.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:m}=y;m!==void 0&&!o&&(e(this,et)&&((M=e(this,$))==null||M.call(this,m,e$1,"set")),e(this,I)&&e(this,C)?.push([m,e$1,"set"]));}else o||(e(this,et)&&((q=e(this,$))==null||q.call(this,y,e$1,"set")),e(this,I)&&e(this,C)?.push([y,e$1,"set"]));if(e(this,gt).call(this,S),e(this,bt).call(this,S,L,c),e(this,f)[S]=i$1,c){c.set="replace";let m=y&&h(this,a,E).call(this,y)?y.__staleWhileFetching:y;m!==void 0&&(c.oldValue=m);}}else c&&(c.set="update");e(this,Et)&&this.onInsert?.(i$1,e$1,i$1===y?"update":"replace");}if(r!==0&&!e(this,W)&&h(this,a,It).call(this),e(this,W)&&(v||e(this,Tt).call(this,S,r,n),c&&e(this,nt).call(this,c,S)),!o&&e(this,I)&&e(this,C)){let y=e(this,C),m;for(;m=y?.shift();)(w=e(this,B))==null||w.call(this,...m);}return this}pop(){var e$1;try{for(;e(this,U);){let i=e(this,f)[e(this,F)];if(h(this,a,Dt).call(this,!0),h(this,a,E).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(e(this,I)&&e(this,C)){let i=e(this,C),s;for(;s=i?.shift();)(e$1=e(this,B))==null||e$1.call(this,...s);}}}has(e$1,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=i,n=e(this,O).get(e$1);if(n!==void 0){let o=e(this,f)[n];if(h(this,a,E).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(e(this,H).call(this,n))r&&(r.has="stale",e(this,nt).call(this,r,n));else return s&&e(this,mt).call(this,n),r&&(r.has="hit",e(this,nt).call(this,r,n)),true}else r&&(r.has="miss");return false}peek(e$1,i={}){let{allowStale:s=this.allowStale}=i,r=e(this,O).get(e$1);if(r===void 0||!s&&e(this,H).call(this,r))return;let n=e(this,f)[r];return h(this,a,E).call(this,n)?n.__staleWhileFetching:n}async fetch(e$1,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:l=this.noDisposeOnSet,size:c=0,sizeCalculation:v=this.sizeCalculation,noUpdateTTL:L=this.noUpdateTTL,noDeleteOnFetchRejection:S=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:ot=this.allowStaleOnFetchRejection,ignoreFetchAbort:M=this.ignoreFetchAbort,allowStaleOnFetchAbort:q=this.allowStaleOnFetchAbort,context:w,forceRefresh:y=false,status:m,signal:p}=i;if(!e(this,pt))return m&&(m.fetch="get"),this.get(e$1,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,status:m});let x={allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:l,size:c,sizeCalculation:v,noUpdateTTL:L,noDeleteOnFetchRejection:S,allowStaleOnFetchRejection:ot,allowStaleOnFetchAbort:q,ignoreFetchAbort:M,status:m,signal:p},T=e(this,O).get(e$1);if(T===void 0){m&&(m.fetch="miss");let d=h(this,a,Ct).call(this,e$1,T,x,w);return d.__returned=d}else {let d=e(this,f)[T];if(h(this,a,E).call(this,d)){let vt=s&&d.__staleWhileFetching!==void 0;return m&&(m.fetch="inflight",vt&&(m.returnedStale=true)),vt?d.__staleWhileFetching:d.__returned=d}let A=e(this,H).call(this,T);if(!y&&!A)return m&&(m.fetch="hit"),h(this,a,At).call(this,T),r&&e(this,mt).call(this,T),m&&e(this,nt).call(this,m,T),d;let N=h(this,a,Ct).call(this,e$1,T,x,w),K=N.__staleWhileFetching!==void 0&&s;return m&&(m.fetch=A?"stale":"refresh",K&&A&&(m.returnedStale=true)),K?N.__staleWhileFetching:N.__returned=N}}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$1,i={}){let s=e(this,xt);if(!s)throw new Error("no memoMethod provided to constructor");let{context:r,forceRefresh:n,...o}=i,l=this.get(e$1,o);if(!n&&l!==void 0)return l;let c=s(e$1,l,{options:o,context:r});return this.set(e$1,c,o),c}get(e$1,i={}){let{allowStale:s=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=i,l=e(this,O).get(e$1);if(l!==void 0){let c=e(this,f)[l],v=h(this,a,E).call(this,c);return o&&e(this,nt).call(this,o,l),e(this,H).call(this,l)?(o&&(o.get="stale"),v?(o&&s&&c.__staleWhileFetching!==void 0&&(o.returnedStale=true),s?c.__staleWhileFetching:void 0):(n||h(this,a,dt).call(this,e$1,"expire"),o&&s&&(o.returnedStale=true),s?c:void 0)):(o&&(o.get="hit"),v?c.__staleWhileFetching:(h(this,a,At).call(this,l),r&&e(this,mt).call(this,l),c))}else o&&(o.get="miss");}delete(e){return h(this,a,dt).call(this,e,"delete")}clear(){return h(this,a,zt).call(this,"delete")}},k=new WeakMap,z=new WeakMap,$=new WeakMap,ft=new WeakMap,B=new WeakMap,yt=new WeakMap,xt=new WeakMap,X=new WeakMap,U=new WeakMap,J=new WeakMap,O=new WeakMap,b=new WeakMap,f=new WeakMap,j=new WeakMap,V=new WeakMap,F=new WeakMap,D=new WeakMap,Q=new WeakMap,C=new WeakMap,Z=new WeakMap,tt=new WeakMap,W=new WeakMap,Y=new WeakMap,et=new WeakMap,pt=new WeakMap,I=new WeakMap,Et=new WeakMap,a=new WeakSet,It=function(){let e$1=new Lt(e(this,k)),i=new Lt(e(this,k));g(this,W,e$1),g(this,tt,i);let s=this.ttlAutopurge?new Array(e(this,k)):void 0;g(this,Y,s),g(this,Tt,(l,c,v=e(this,X).now())=>{i[l]=c!==0?v:0,e$1[l]=c,r(l,c);}),g(this,mt,l=>{i[l]=e$1[l]!==0?e(this,X).now():0,r(l,e$1[l]);});let r=this.ttlAutopurge?(l,c)=>{if(s?.[l]&&(clearTimeout(s[l]),s[l]=void 0),c&&c!==0&&s){let v=setTimeout(()=>{e(this,H).call(this,l)&&h(this,a,dt).call(this,e(this,b)[l],"expire");},c+1);v.unref&&v.unref(),s[l]=v;}}:()=>{};g(this,nt,(l,c)=>{if(e$1[c]){let v=e$1[c],L=i[c];if(!v||!L)return;l.ttl=v,l.start=L,l.now=n||o();let S=l.now-L;l.remainingTTL=v-S;}});let n=0,o=()=>{let l=e(this,X).now();if(this.ttlResolution>0){n=l;let c=setTimeout(()=>n=0,this.ttlResolution);c.unref&&c.unref();}return l};this.getRemainingTTL=l=>{let c=e(this,O).get(l);if(c===void 0)return 0;let v=e$1[c],L=i[c];if(!v||!L)return 1/0;let S=(n||o())-L;return v-S},g(this,H,l=>{let c=i[l],v=e$1[l];return !!v&&!!c&&(n||o())-c>v});},mt=new WeakMap,nt=new WeakMap,Tt=new WeakMap,H=new WeakMap,ie=function(){let e$1=new Lt(e(this,k));g(this,J,0),g(this,Z,e$1),g(this,gt,i=>{g(this,J,e(this,J)-e$1[i]),e$1[i]=0;}),g(this,Ot,(i,s,r,n)=>{if(h(this,a,E).call(this,s))return 0;if(!lt(r))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(r=n(s,i),!lt(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}),g(this,bt,(i,s,r)=>{if(e$1[i]=s,e(this,z)){let n=e(this,z)-e$1[i];for(;e(this,J)>n;)h(this,a,Dt).call(this,true);}g(this,J,e(this,J)+e$1[i]),r&&(r.entrySize=s,r.totalCalculatedSize=e(this,J));});},gt=new WeakMap,bt=new WeakMap,Ot=new WeakMap,ht=function*({allowStale:e$1=this.allowStale}={}){if(e(this,U))for(let i=e(this,D);!(!h(this,a,Gt).call(this,i)||((e$1||!e(this,H).call(this,i))&&(yield i),i===e(this,F)));)i=e(this,V)[i];},ct=function*({allowStale:e$1=this.allowStale}={}){if(e(this,U))for(let i=e(this,F);!(!h(this,a,Gt).call(this,i)||((e$1||!e(this,H).call(this,i))&&(yield i),i===e(this,D)));)i=e(this,j)[i];},Gt=function(e$1){return e$1!==void 0&&e(this,O).get(e(this,b)[e$1])===e$1},Dt=function(e$1){var n;let i$1=e(this,F),s=e(this,b)[i$1],r=e(this,f)[i$1];return e(this,pt)&&h(this,a,E).call(this,r)?r.__abortController.abort(new Error("evicted")):(e(this,et)||e(this,I))&&(e(this,et)&&((n=e(this,$))==null||n.call(this,r,s,"evict")),e(this,I)&&e(this,C)?.push([r,s,"evict"])),e(this,gt).call(this,i$1),e(this,Y)?.[i$1]&&(clearTimeout(e(this,Y)[i$1]),e(this,Y)[i$1]=void 0),e$1&&(e(this,b)[i$1]=void 0,e(this,f)[i$1]=void 0,e(this,Q).push(i$1)),e(this,U)===1?(g(this,F,g(this,D,0)),e(this,Q).length=0):g(this,F,e(this,j)[i$1]),e(this,O).delete(s),i(this,U)._--,i$1},Ct=function(e$1,i,s,r){let n=i===void 0?void 0:e(this,f)[i];if(h(this,a,E).call(this,n))return n;let o=new Pt,{signal:l}=s;l?.addEventListener("abort",()=>o.abort(l.reason),{signal:o.signal});let c={signal:o.signal,options:s,context:r},v=(w,y=false)=>{let{aborted:m}=o.signal,p=s.ignoreFetchAbort&&w!==void 0,x=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&w!==void 0);if(s.status&&(m&&!y?(s.status.fetchAborted=true,s.status.fetchError=o.signal.reason,p&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),m&&!p&&!y)return S(o.signal.reason,x);let T=M,d=e(this,f)[i];return (d===M||p&&y&&d===void 0)&&(w===void 0?T.__staleWhileFetching!==void 0?e(this,f)[i]=T.__staleWhileFetching:h(this,a,dt).call(this,e$1,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(e$1,w,c.options))),w},L=w=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=w),S(w,false)),S=(w,y)=>{let{aborted:m}=o.signal,p=m&&s.allowStaleOnFetchAbort,x=p||s.allowStaleOnFetchRejection,T=x||s.noDeleteOnFetchRejection,d=M;if(e(this,f)[i]===M&&(!T||!y&&d.__staleWhileFetching===void 0?h(this,a,dt).call(this,e$1,"fetch"):p||(e(this,f)[i]=d.__staleWhileFetching)),x)return s.status&&d.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),d.__staleWhileFetching;if(d.__returned===d)throw w},ot=(w,y)=>{var p;let m=(p=e(this,yt))==null?void 0:p.call(this,e$1,n,c);m&&m instanceof Promise&&m.then(x=>w(x===void 0?void 0:x),y),o.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(w(void 0),s.allowStaleOnFetchAbort&&(w=x=>v(x,true)));});};s.status&&(s.status.fetchDispatched=true);let M=new Promise(ot).then(v,L),q=Object.assign(M,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return i===void 0?(this.set(e$1,q,{...c.options,status:void 0}),i=e(this,O).get(e$1)):e(this,f)[i]=q,q},E=function(e$1){if(!e(this,pt))return false;let i=e$1;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof Pt},Mt=function(e$1,i){e(this,V)[i]=e$1,e(this,j)[e$1]=i;},At=function(e$1){e$1!==e(this,D)&&(e$1===e(this,F)?g(this,F,e(this,j)[e$1]):h(this,a,Mt).call(this,e(this,V)[e$1],e(this,j)[e$1]),h(this,a,Mt).call(this,e(this,D),e$1),g(this,D,e$1));},dt=function(e$1,i$1){var r,n;let s=false;if(e(this,U)!==0){let o=e(this,O).get(e$1);if(o!==void 0)if(e(this,Y)?.[o]&&(clearTimeout(e(this,Y)?.[o]),e(this,Y)[o]=void 0),s=true,e(this,U)===1)h(this,a,zt).call(this,i$1);else {e(this,gt).call(this,o);let l=e(this,f)[o];if(h(this,a,E).call(this,l)?l.__abortController.abort(new Error("deleted")):(e(this,et)||e(this,I))&&(e(this,et)&&((r=e(this,$))==null||r.call(this,l,e$1,i$1)),e(this,I)&&e(this,C)?.push([l,e$1,i$1])),e(this,O).delete(e$1),e(this,b)[o]=void 0,e(this,f)[o]=void 0,o===e(this,D))g(this,D,e(this,V)[o]);else if(o===e(this,F))g(this,F,e(this,j)[o]);else {let c=e(this,V)[o];e(this,j)[c]=e(this,j)[o];let v=e(this,j)[o];e(this,V)[v]=e(this,V)[o];}i(this,U)._--,e(this,Q).push(o);}}if(e(this,I)&&e(this,C)?.length){let o=e(this,C),l;for(;l=o?.shift();)(n=e(this,B))==null||n.call(this,...l);}return s},zt=function(e$1){var i,s;for(let r of h(this,a,ct).call(this,{allowStale:true})){let n=e(this,f)[r];if(h(this,a,E).call(this,n))n.__abortController.abort(new Error("deleted"));else {let o=e(this,b)[r];e(this,et)&&((i=e(this,$))==null||i.call(this,n,o,e$1)),e(this,I)&&e(this,C)?.push([n,o,e$1]);}}if(e(this,O).clear(),e(this,f).fill(void 0),e(this,b).fill(void 0),e(this,W)&&e(this,tt)){e(this,W).fill(0),e(this,tt).fill(0);for(let r of e(this,Y)??[])r!==void 0&&clearTimeout(r);e(this,Y)?.fill(void 0);}if(e(this,Z)&&e(this,Z).fill(0),g(this,F,0),g(this,D,0),e(this,Q).length=0,g(this,J,0),g(this,U,0),e(this,I)&&e(this,C)){let r=e(this,C),n;for(;n=r?.shift();)(s=e(this,B))==null||s.call(this,...n);}},wt);var Nt=class{cache;map=new Map;constructor(e){this.cache=new ee({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 Ut="1.8.25";var Vt={version:Ut};var Wt="repeat";function Yt(g){return {type:"pause",duration:g}}var Ht="__game_layer__";var fe={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 re={};var Kt={};b$1(Kt,{createExportableElement:()=>oe});var _t;(r=>(r.log=(n,...o)=>console.log(`[Pixi\u2019VN] ${n}`,...o),r.warn=(n,...o)=>console.warn(`[Pixi\u2019VN] ${n}`,...o),r.error=(n,...o)=>console.error(`[Pixi\u2019VN] ${n}`,...o),r.info=(n,...o)=>console.info(`[Pixi\u2019VN] ${n}`,...o)))(_t||={});function oe(g){try{if(typeof g>"u")return g;let e=JSON.stringify(g);return JSON.parse(e)}catch(e){throw _t.error("Error creating exportable element",g,e),new PixiError("not_json_serializable","Error creating exportable element")}}var ge=typeof window<"u"&&typeof document<"u",ne=[" _______ _ _ _ ____ ____ ____ _____ ","|_ __ \\ (_) (_) | | |_ _| |_ _||_ \\|_ _|"," | |__) |__ _ __ __ \\_| \\ \\ / / | \\ | | "," | ___/[ | [ \\ [ ][ | \\ \\ / / | |\\ \\| | "," _| |_ | | > ' < | | \\ ' / _| |_\\ |_ ",`|_____| [___][__]\`\\_][___] \\_/ |_____|\\____| v${Vt.version}`],ae=31,_e="background:#2f90da;color:#fff;font-weight:bold;",ve="background:#c832bb;color:#fff;font-weight:bold;",Se="background:transparent;font-weight:bold;",kt=` v${Vt.version}`;function le(){if(!ge)return;let g=[],e=[];for(let i=0;i<ne.length;i++){let s=ne[i],r=s.endsWith(kt),n=r?s.slice(0,-kt.length):s,o=n.slice(0,ae),l=n.slice(ae),c=r?"%c%s%c%s%c%s":"%c%s%c%s";g.push(c),e.push(_e,o,ve,l),r&&e.push(Se,kt);}console.info(g.join(`
2
+ `),...e);}function qt(){let g=window.location.pathname+window.location.hash;return g.includes("#")&&(g=g.split("#")[1]),g}le();var he;(m=>{async function g(p,x,T){if(GameUnifier.init({navigate:x?.navigate,getCurrentGameStepState:()=>{let d={};try{d=at.canvas.export();}catch{}return {path:qt(),storage:G.storage.export(),canvas:d,sound:ut.sound.export(),labelIndex:R.NarrationManagerStatic.currentLabelStepIndex||0,openedLabels:R.narration.openedLabels}},restoreGameStepState:async(d,A)=>{it.HistoryManagerStatic._originalStepData=d,R.NarrationManagerStatic.openedLabels=d.openedLabels,G.storage.restore(d.storage);try{await at.canvas.restore(d.canvas),await ut.sound.restore(d.sound);}catch(N){_t.error("Error restoring game step state:",N);}await A(d.path);},getStepCounter:()=>R.narration.stepCounter,setStepCounter:d=>{R.NarrationManagerStatic._stepCounter=d;},getOpenedLabels:()=>R.narration.openedLabels.length,addHistoryItem:(d,A)=>it.stepHistory.add(d,A),getCharacter:d=>$t.RegisteredCharacters.get(d),processNavigationRequests:(d,A)=>{let N=d,K=Promise.resolve();return d>0?(N--,K=R.narration.continue(A)):d<0&&(N=0,K=it.stepHistory.back(A,{steps:d*-1})),{newValue:N,result:K}},animate:(d,A,N,K)=>motion.animate(d,A,N,K),getVariable:(d,A)=>G.StorageRegistry.getVariable(d,A),setVariable:(d,A,N)=>G.StorageRegistry.setVariable(d,A,N),removeVariable:(d,A)=>G.StorageRegistry.removeVariable(d,A),getFlag:d=>G.storage.getFlag(d),setFlag:(d,A)=>G.storage.setFlag(d,A),onLabelClosing:d=>G.StorageRegistry.clearOldTempVariables(d)}),!p||!x){_t.warn("The canvas element or options are not defined. The canvas will not be initialized.");return}return await at.canvas.init(p,x,T)}m.init=g;function e(){G.storage.clear();try{at.canvas.clear();}catch{}ut.sound.clear(),R.narration.clear(),it.stepHistory.clear();}m.clear=e;function i(){let p={};try{p=at.canvas.export();}catch{}return {pixivn_version:Ut,stepData:R.narration.export(),storageData:G.storage.export(),canvasData:p,soundData:ut.sound.export(),historyData:it.stepHistory.export(),path:qt()}}m.exportGameState=i;async function s(p,x){it.stepHistory.restore(p.historyData);let T=it.stepHistory.lastKey;if(typeof T=="number"){let d=it.stepHistory.stepsInfoMap.get(T)||null;await R.narration.restore(p.stepData,d);}G.storage.restore(p.storageData);try{await at.canvas.restore(p.canvasData),await ut.sound.restore(p.soundData);}catch{}x?await x(p.path):await GameUnifier.navigate(p.path);}m.restoreGameState=s;async function r(p,x){return m.clear(),await R.narration.call(p,x)}m.start=r;function n(p){return JSON.parse(p)}m.jsonToGameState=n;function o(p){GameUnifier.onEnd=p;}m.onEnd=o;function l(p){return _t.warn("Game.onError is deprecated. Use Game.addOnError / Game.removeOnError to register multiple handlers."),GameUnifier.addOnError((x,T)=>p("step",x,T))}m.onError=l;function c(p){return GameUnifier.addOnError(p)}m.addOnError=c;function v(p){return GameUnifier.removeOnError(p)}m.removeOnError=v;function L(p){R.NarrationManagerStatic.onStepStart=p;}m.onStepStart=L;function S(p){R.NarrationManagerStatic.onLoadingLabel=p;}m.onLoadingLabel=S;function ot(p){R.NarrationManagerStatic.onStepEnd=p;}m.onStepEnd=ot;function M(p){R.NarrationManagerStatic.onLabelStarting=p;}m.onLabelStarting=M;function q(p){GameUnifier.navigate=p;}m.onNavigate=q;function w(p){return GameUnifier.addOnPreContinue(p)}m.addOnPreContinue=w;function y(p){return GameUnifier.removeOnPreContinue(p)}m.removeOnPreContinue=y;})(he||={});var $e={characterUtils:$t,canvasUtils:at,narrationUtils:R,soundUtils:ut,CANVAS_APP_GAME_LAYER_ALIAS:Ht,Pause:Yt,Repeat:Wt,PIXIVN_VERSION:Ut,...Kt,...re,canvas:at.canvas,narration:R.narration,sound:ut.sound,storage:G.storage,history:it.stepHistory,Game:he,GameUnifier:GameUnifier};export{Ht as CANVAS_APP_GAME_LAYER_ALIAS,Nt as CachedMap,he as Game,Ut as PIXIVN_VERSION,Yt as Pause,Wt as Repeat,fe as SYSTEM_RESERVED_STORAGE_KEYS,oe as createExportableElement,$e as default};
@@ -1,2 +1,2 @@
1
- 'use strict';var core=require('@drincs/pixi-vn/core');var St=Object.create;var We=Object.defineProperty;var yt=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Qe=s=>{throw TypeError(s)};var _t=(s,e,t)=>e in s?We(s,e,{enumerable:true,configurable:true,writable:true,value:t}):s[e]=t;var Be=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ze=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var Tt=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mt(e))!Lt.call(s,i)&&i!==t&&We(s,i,{get:()=>e[i],enumerable:!(n=yt(e,i))||n.enumerable});return s};var Et=(s,e,t)=>(t=s!=null?St(gt(s)):{},Tt(We(t,"default",{value:s,enumerable:true}),s));var z=(s,e,t)=>_t(s,typeof e!="symbol"?e+"":e,t),je=(s,e,t)=>e.has(s)||Qe("Cannot "+t);var r=(s,e,t)=>(je(s,e,"read from private field"),t?t.call(s):e.get(s)),v=(s,e,t)=>e.has(s)?Qe("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),y=(s,e,t,n)=>(je(s,e,"write to private field"),e.set(s,t),t),f=(s,e,t)=>(je(s,e,"access private method"),t);var Ue=(s,e,t,n)=>({set _(i){y(s,e,i);},get _(){return r(s,e,n)}});var ct=Ze((ze,pt)=>{(function(s,e){typeof ze=="object"?pt.exports=ze=e():typeof define=="function"&&define.amd?define([],e):s.CryptoJS=e();})(ze,function(){var s=s||(function(e,t){var n;if(typeof window<"u"&&window.crypto&&(n=window.crypto),typeof self<"u"&&self.crypto&&(n=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(n=globalThis.crypto),!n&&typeof window<"u"&&window.msCrypto&&(n=window.msCrypto),!n&&typeof global<"u"&&global.crypto&&(n=global.crypto),!n&&typeof Be=="function")try{n=Be("crypto");}catch{}var i=function(){if(n){if(typeof n.getRandomValues=="function")try{return n.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof n.randomBytes=="function")try{return n.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||(function(){function l(){}return function(d){var C;return l.prototype=d,C=new l,l.prototype=null,C}})(),o={},h=o.lib={},p=h.Base=(function(){return {extend:function(l){var d=a(this);return l&&d.mixIn(l),(!d.hasOwnProperty("init")||this.init===d.init)&&(d.init=function(){d.$super.init.apply(this,arguments);}),d.init.prototype=d,d.$super=this,d},create:function(){var l=this.extend();return l.init.apply(l,arguments),l},init:function(){},mixIn:function(l){for(var d in l)l.hasOwnProperty(d)&&(this[d]=l[d]);l.hasOwnProperty("toString")&&(this.toString=l.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),S=h.WordArray=p.extend({init:function(l,d){l=this.words=l||[],d!=t?this.sigBytes=d:this.sigBytes=l.length*4;},toString:function(l){return (l||L).stringify(this)},concat:function(l){var d=this.words,C=l.words,E=this.sigBytes,O=l.sigBytes;if(this.clamp(),E%4)for(var P=0;P<O;P++){var oe=C[P>>>2]>>>24-P%4*8&255;d[E+P>>>2]|=oe<<24-(E+P)%4*8;}else for(var G=0;G<O;G+=4)d[E+G>>>2]=C[G>>>2];return this.sigBytes+=O,this},clamp:function(){var l=this.words,d=this.sigBytes;l[d>>>2]&=4294967295<<32-d%4*8,l.length=e.ceil(d/4);},clone:function(){var l=p.clone.call(this);return l.words=this.words.slice(0),l},random:function(l){for(var d=[],C=0;C<l;C+=4)d.push(i());return new S.init(d,l)}}),u=o.enc={},L=u.Hex={stringify:function(l){for(var d=l.words,C=l.sigBytes,E=[],O=0;O<C;O++){var P=d[O>>>2]>>>24-O%4*8&255;E.push((P>>>4).toString(16)),E.push((P&15).toString(16));}return E.join("")},parse:function(l){for(var d=l.length,C=[],E=0;E<d;E+=2)C[E>>>3]|=parseInt(l.substr(E,2),16)<<24-E%8*4;return new S.init(C,d/2)}},M=u.Latin1={stringify:function(l){for(var d=l.words,C=l.sigBytes,E=[],O=0;O<C;O++){var P=d[O>>>2]>>>24-O%4*8&255;E.push(String.fromCharCode(P));}return E.join("")},parse:function(l){for(var d=l.length,C=[],E=0;E<d;E++)C[E>>>2]|=(l.charCodeAt(E)&255)<<24-E%4*8;return new S.init(C,d)}},N=u.Utf8={stringify:function(l){try{return decodeURIComponent(escape(M.stringify(l)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(l){return M.parse(unescape(encodeURIComponent(l)))}},D=h.BufferedBlockAlgorithm=p.extend({reset:function(){this._data=new S.init,this._nDataBytes=0;},_append:function(l){typeof l=="string"&&(l=N.parse(l)),this._data.concat(l),this._nDataBytes+=l.sigBytes;},_process:function(l){var d,C=this._data,E=C.words,O=C.sigBytes,P=this.blockSize,oe=P*4,G=O/oe;l?G=e.ceil(G):G=e.max((G|0)-this._minBufferSize,0);var J=G*P,Le=e.min(J*4,O);if(J){for(var Ke=0;Ke<J;Ke+=P)this._doProcessBlock(E,Ke);d=E.splice(0,J),C.sigBytes-=Le;}return new S.init(d,Le)},clone:function(){var l=p.clone.call(this);return l._data=this._data.clone(),l},_minBufferSize:0});h.Hasher=D.extend({cfg:p.extend(),init:function(l){this.cfg=this.cfg.extend(l),this.reset();},reset:function(){D.reset.call(this),this._doReset();},update:function(l){return this._append(l),this._process(),this},finalize:function(l){l&&this._append(l);var d=this._doFinalize();return d},blockSize:512/32,_createHelper:function(l){return function(d,C){return new l.init(C).finalize(d)}},_createHmacHelper:function(l){return function(d,C){return new T.HMAC.init(l,C).finalize(d)}}});var T=o.algo={};return o})(Math);return s});});var dt=Ze((He,ut)=>{(function(s,e){typeof He=="object"?ut.exports=He=e(ct()):typeof define=="function"&&define.amd?define(["./core"],e):e(s.CryptoJS);})(He,function(s){return (function(){var e=s,t=e.lib,n=t.WordArray,i=t.Hasher,a=e.algo,o=[],h=a.SHA1=i.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(p,S){for(var u=this._hash.words,L=u[0],M=u[1],N=u[2],D=u[3],w=u[4],T=0;T<80;T++){if(T<16)o[T]=p[S+T]|0;else {var l=o[T-3]^o[T-8]^o[T-14]^o[T-16];o[T]=l<<1|l>>>31;}var d=(L<<5|L>>>27)+w+o[T];T<20?d+=(M&N|~M&D)+1518500249:T<40?d+=(M^N^D)+1859775393:T<60?d+=(M&N|M&D|N&D)-1894007588:d+=(M^N^D)-899497514,w=D,D=N,N=M<<30|M>>>2,M=L,L=d;}u[0]=u[0]+L|0,u[1]=u[1]+M|0,u[2]=u[2]+N|0,u[3]=u[3]+D|0,u[4]=u[4]+w|0;},_doFinalize:function(){var p=this._data,S=p.words,u=this._nDataBytes*8,L=p.sigBytes*8;return S[L>>>5]|=128<<24-L%32,S[(L+64>>>9<<4)+14]=Math.floor(u/4294967296),S[(L+64>>>9<<4)+15]=u,p.sigBytes=S.length*4,this._process(),this._hash},clone:function(){var p=i.clone.call(this);return p._hash=this._hash.clone(),p}});e.SHA1=i._createHelper(h),e.HmacSHA1=i._createHmacHelper(h);})(),s.SHA1});});var R="narration";var I={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 Ct=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,nt=new Set,ke=typeof process=="object"&&process?process:{},it=(s,e,t,n)=>{typeof ke.emitWarning=="function"?ke.emitWarning(s,e,t,n):console.error(`[${t}] ${e}: ${s}`);},Ge=globalThis.AbortController,et=globalThis.AbortSignal;if(typeof Ge>"u"){et=class{onabort;_onabort=[];reason;aborted=false;addEventListener(t,n){this._onabort.push(n);}},Ge=class{constructor(){e();}signal=new et;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let n of this.signal._onabort)n(t);this.signal.onabort?.(t);}}};let s=ke.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{s&&(s=false,it("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 It=s=>!nt.has(s);var ue=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),at=s=>ue(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?Ye:null:null,Ye=class extends Array{constructor(s){super(s),this.fill(0);}},le,_e,Ot=(le=class{heap;length;static create(e){let t=at(e);if(!t)return [];y(le,_e,true);let n=new le(e,t);return y(le,_e,false),n}constructor(e,t){if(!r(le,_e))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},_e=new WeakMap,v(le,_e,false),le),tt,rt,X,B,Q,ye,Z,Te,Ee,ee,Y,te,U,A,_,K,j,H,F,re,V,ne,ie,k,$,ae,Se,W,Ce,c,$e,me,he,Me,q,ot,ge,Ie,Ne,de,fe,qe,Fe,Ve,x,Xe,Ae,be,Je,Oe,st=(Oe=class{constructor(e){v(this,c);v(this,X);v(this,B);v(this,Q);v(this,ye);v(this,Z);v(this,Te);v(this,Ee);v(this,ee);z(this,"ttl");z(this,"ttlResolution");z(this,"ttlAutopurge");z(this,"updateAgeOnGet");z(this,"updateAgeOnHas");z(this,"allowStale");z(this,"noDisposeOnSet");z(this,"noUpdateTTL");z(this,"maxEntrySize");z(this,"sizeCalculation");z(this,"noDeleteOnFetchRejection");z(this,"noDeleteOnStaleGet");z(this,"allowStaleOnFetchAbort");z(this,"allowStaleOnFetchRejection");z(this,"ignoreFetchAbort");v(this,Y);v(this,te);v(this,U);v(this,A);v(this,_);v(this,K);v(this,j);v(this,H);v(this,F);v(this,re);v(this,V);v(this,ne);v(this,ie);v(this,k);v(this,$);v(this,ae);v(this,Se);v(this,W);v(this,Ce);v(this,me,()=>{});v(this,he,()=>{});v(this,Me,()=>{});v(this,q,()=>false);v(this,ge,e=>{});v(this,Ie,(e,t,n)=>{});v(this,Ne,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});z(this,tt,"LRUCache");let{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:h,allowStale:p,dispose:S,onInsert:u,disposeAfter:L,noDisposeOnSet:M,noUpdateTTL:N,maxSize:D=0,maxEntrySize:w=0,sizeCalculation:T,fetchMethod:l,memoMethod:d,noDeleteOnFetchRejection:C,noDeleteOnStaleGet:E,allowStaleOnFetchRejection:O,allowStaleOnFetchAbort:P,ignoreFetchAbort:oe,perf:G}=e;if(G!==void 0&&typeof G?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(y(this,ee,G??Ct),t!==0&&!ue(t))throw new TypeError("max option must be a nonnegative integer");let J=t?at(t):Array;if(!J)throw new Error("invalid max value: "+t);if(y(this,X,t),y(this,B,D),this.maxEntrySize=w||r(this,B),this.sizeCalculation=T,this.sizeCalculation){if(!r(this,B)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(d!==void 0&&typeof d!="function")throw new TypeError("memoMethod must be a function if defined");if(y(this,Ee,d),l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(y(this,Te,l),y(this,Se,!!l),y(this,U,new Map),y(this,A,new Array(t).fill(void 0)),y(this,_,new Array(t).fill(void 0)),y(this,K,new J(t)),y(this,j,new J(t)),y(this,H,0),y(this,F,0),y(this,re,Ot.create(t)),y(this,Y,0),y(this,te,0),typeof S=="function"&&y(this,Q,S),typeof u=="function"&&y(this,ye,u),typeof L=="function"?(y(this,Z,L),y(this,V,[])):(y(this,Z,void 0),y(this,V,void 0)),y(this,ae,!!r(this,Q)),y(this,Ce,!!r(this,ye)),y(this,W,!!r(this,Z)),this.noDisposeOnSet=!!M,this.noUpdateTTL=!!N,this.noDeleteOnFetchRejection=!!C,this.allowStaleOnFetchRejection=!!O,this.allowStaleOnFetchAbort=!!P,this.ignoreFetchAbort=!!oe,this.maxEntrySize!==0){if(r(this,B)!==0&&!ue(r(this,B)))throw new TypeError("maxSize must be a positive integer if specified");if(!ue(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");f(this,c,ot).call(this);}if(this.allowStale=!!p,this.noDeleteOnStaleGet=!!E,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!h,this.ttlResolution=ue(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!ue(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,c,$e).call(this);}if(r(this,X)===0&&this.ttl===0&&r(this,B)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!r(this,X)&&!r(this,B)){let Le="LRU_CACHE_UNBOUNDED";It(Le)&&(nt.add(Le),it("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Le,Oe));}}get perf(){return r(this,ee)}static unsafeExposeInternals(e){return {starts:r(e,ie),ttls:r(e,k),autopurgeTimers:r(e,$),sizes:r(e,ne),keyMap:r(e,U),keyList:r(e,A),valList:r(e,_),next:r(e,K),prev:r(e,j),get head(){return r(e,H)},get tail(){return r(e,F)},free:r(e,re),isBackgroundFetch:t=>{var n;return f(n=e,c,x).call(n,t)},backgroundFetch:(t,n,i,a)=>{var o;return f(o=e,c,Ve).call(o,t,n,i,a)},moveToTail:t=>{var n;return f(n=e,c,Ae).call(n,t)},indexes:t=>{var n;return f(n=e,c,de).call(n,t)},rindexes:t=>{var n;return f(n=e,c,fe).call(n,t)},isStale:t=>{var n;return r(n=e,q).call(n,t)}}}get max(){return r(this,X)}get maxSize(){return r(this,B)}get calculatedSize(){return r(this,te)}get size(){return r(this,Y)}get fetchMethod(){return r(this,Te)}get memoMethod(){return r(this,Ee)}get dispose(){return r(this,Q)}get onInsert(){return r(this,ye)}get disposeAfter(){return r(this,Z)}getRemainingTTL(e){return r(this,U).has(e)?1/0:0}*entries(){for(let e of f(this,c,de).call(this))r(this,_)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,c,x).call(this,r(this,_)[e])&&(yield [r(this,A)[e],r(this,_)[e]]);}*rentries(){for(let e of f(this,c,fe).call(this))r(this,_)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,c,x).call(this,r(this,_)[e])&&(yield [r(this,A)[e],r(this,_)[e]]);}*keys(){for(let e of f(this,c,de).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,c,x).call(this,r(this,_)[e])&&(yield t);}}*rkeys(){for(let e of f(this,c,fe).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,c,x).call(this,r(this,_)[e])&&(yield t);}}*values(){for(let e of f(this,c,de).call(this))r(this,_)[e]!==void 0&&!f(this,c,x).call(this,r(this,_)[e])&&(yield r(this,_)[e]);}*rvalues(){for(let e of f(this,c,fe).call(this))r(this,_)[e]!==void 0&&!f(this,c,x).call(this,r(this,_)[e])&&(yield r(this,_)[e]);}[(rt=Symbol.iterator,tt=Symbol.toStringTag,rt)](){return this.entries()}find(e,t={}){for(let n of f(this,c,de).call(this)){let i=r(this,_)[n],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,r(this,A)[n],this))return this.get(r(this,A)[n],t)}}forEach(e,t=this){for(let n of f(this,c,de).call(this)){let i=r(this,_)[n],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}rforEach(e,t=this){for(let n of f(this,c,fe).call(this)){let i=r(this,_)[n],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}purgeStale(){let e=false;for(let t of f(this,c,fe).call(this,{allowStale:true}))r(this,q).call(this,t)&&(f(this,c,be).call(this,r(this,A)[t],"expire"),e=true);return e}info(e){let t=r(this,U).get(e);if(t===void 0)return;let n=r(this,_)[t],i=f(this,c,x).call(this,n)?n.__staleWhileFetching:n;if(i===void 0)return;let a={value:i};if(r(this,k)&&r(this,ie)){let o=r(this,k)[t],h=r(this,ie)[t];if(o&&h){let p=o-(r(this,ee).now()-h);a.ttl=p,a.start=Date.now();}}return r(this,ne)&&(a.size=r(this,ne)[t]),a}dump(){let e=[];for(let t of f(this,c,de).call(this,{allowStale:true})){let n=r(this,A)[t],i=r(this,_)[t],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;let o={value:a};if(r(this,k)&&r(this,ie)){o.ttl=r(this,k)[t];let h=r(this,ee).now()-r(this,ie)[t];o.start=Math.floor(Date.now()-h);}r(this,ne)&&(o.size=r(this,ne)[t]),e.unshift([n,o]);}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let i=Date.now()-n.start;n.start=r(this,ee).now()-i;}this.set(t,n.value,n);}}set(e,t,n={}){var M,N,D,w;if(t===void 0)return this.delete(e),this;let{ttl:i=this.ttl,start:a,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:h=this.sizeCalculation,status:p}=n,{noUpdateTTL:S=this.noUpdateTTL}=n,u=r(this,Ne).call(this,e,t,n.size||0,h);if(this.maxEntrySize&&u>this.maxEntrySize)return p&&(p.set="miss",p.maxEntrySizeExceeded=true),f(this,c,be).call(this,e,"set"),this;let L=r(this,Y)===0?void 0:r(this,U).get(e);if(L===void 0)L=r(this,Y)===0?r(this,F):r(this,re).length!==0?r(this,re).pop():r(this,Y)===r(this,X)?f(this,c,Fe).call(this,false):r(this,Y),r(this,A)[L]=e,r(this,_)[L]=t,r(this,U).set(e,L),r(this,K)[r(this,F)]=L,r(this,j)[L]=r(this,F),y(this,F,L),Ue(this,Y)._++,r(this,Ie).call(this,L,u,p),p&&(p.set="add"),S=false,r(this,Ce)&&((M=r(this,ye))==null||M.call(this,t,e,"add"));else {f(this,c,Ae).call(this,L);let T=r(this,_)[L];if(t!==T){if(r(this,Se)&&f(this,c,x).call(this,T)){T.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:l}=T;l!==void 0&&!o&&(r(this,ae)&&((N=r(this,Q))==null||N.call(this,l,e,"set")),r(this,W)&&r(this,V)?.push([l,e,"set"]));}else o||(r(this,ae)&&((D=r(this,Q))==null||D.call(this,T,e,"set")),r(this,W)&&r(this,V)?.push([T,e,"set"]));if(r(this,ge).call(this,L),r(this,Ie).call(this,L,u,p),r(this,_)[L]=t,p){p.set="replace";let l=T&&f(this,c,x).call(this,T)?T.__staleWhileFetching:T;l!==void 0&&(p.oldValue=l);}}else p&&(p.set="update");r(this,Ce)&&this.onInsert?.(t,e,t===T?"update":"replace");}if(i!==0&&!r(this,k)&&f(this,c,$e).call(this),r(this,k)&&(S||r(this,Me).call(this,L,i,a),p&&r(this,he).call(this,p,L)),!o&&r(this,W)&&r(this,V)){let T=r(this,V),l;for(;l=T?.shift();)(w=r(this,Z))==null||w.call(this,...l);}return this}pop(){var e;try{for(;r(this,Y);){let t=r(this,_)[r(this,H)];if(f(this,c,Fe).call(this,!0),f(this,c,x).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(r(this,W)&&r(this,V)){let t=r(this,V),n;for(;n=t?.shift();)(e=r(this,Z))==null||e.call(this,...n);}}}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=r(this,U).get(e);if(a!==void 0){let o=r(this,_)[a];if(f(this,c,x).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(r(this,q).call(this,a))i&&(i.has="stale",r(this,he).call(this,i,a));else return n&&r(this,me).call(this,a),i&&(i.has="hit",r(this,he).call(this,i,a)),true}else i&&(i.has="miss");return false}peek(e,t={}){let{allowStale:n=this.allowStale}=t,i=r(this,U).get(e);if(i===void 0||!n&&r(this,q).call(this,i))return;let a=r(this,_)[i];return f(this,c,x).call(this,a)?a.__staleWhileFetching:a}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:p=0,sizeCalculation:S=this.sizeCalculation,noUpdateTTL:u=this.noUpdateTTL,noDeleteOnFetchRejection:L=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:M=this.allowStaleOnFetchRejection,ignoreFetchAbort:N=this.ignoreFetchAbort,allowStaleOnFetchAbort:D=this.allowStaleOnFetchAbort,context:w,forceRefresh:T=false,status:l,signal:d}=t;if(!r(this,Se))return l&&(l.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:l});let C={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:o,noDisposeOnSet:h,size:p,sizeCalculation:S,noUpdateTTL:u,noDeleteOnFetchRejection:L,allowStaleOnFetchRejection:M,allowStaleOnFetchAbort:D,ignoreFetchAbort:N,status:l,signal:d},E=r(this,U).get(e);if(E===void 0){l&&(l.fetch="miss");let O=f(this,c,Ve).call(this,e,E,C,w);return O.__returned=O}else {let O=r(this,_)[E];if(f(this,c,x).call(this,O)){let J=n&&O.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",J&&(l.returnedStale=true)),J?O.__staleWhileFetching:O.__returned=O}let P=r(this,q).call(this,E);if(!T&&!P)return l&&(l.fetch="hit"),f(this,c,Ae).call(this,E),i&&r(this,me).call(this,E),l&&r(this,he).call(this,l,E),O;let oe=f(this,c,Ve).call(this,e,E,C,w),G=oe.__staleWhileFetching!==void 0&&n;return l&&(l.fetch=P?"stale":"refresh",G&&P&&(l.returnedStale=true)),G?oe.__staleWhileFetching:oe.__returned=oe}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw new Error("fetch() returned undefined");return n}memo(e,t={}){let n=r(this,Ee);if(!n)throw new Error("no memoMethod provided to constructor");let{context:i,forceRefresh:a,...o}=t,h=this.get(e,o);if(!a&&h!==void 0)return h;let p=n(e,h,{options:o,context:i});return this.set(e,p,o),p}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:o}=t,h=r(this,U).get(e);if(h!==void 0){let p=r(this,_)[h],S=f(this,c,x).call(this,p);return o&&r(this,he).call(this,o,h),r(this,q).call(this,h)?(o&&(o.get="stale"),S?(o&&n&&p.__staleWhileFetching!==void 0&&(o.returnedStale=true),n?p.__staleWhileFetching:void 0):(a||f(this,c,be).call(this,e,"expire"),o&&n&&(o.returnedStale=true),n?p:void 0)):(o&&(o.get="hit"),S?p.__staleWhileFetching:(f(this,c,Ae).call(this,h),i&&r(this,me).call(this,h),p))}else o&&(o.get="miss");}delete(e){return f(this,c,be).call(this,e,"delete")}clear(){return f(this,c,Je).call(this,"delete")}},X=new WeakMap,B=new WeakMap,Q=new WeakMap,ye=new WeakMap,Z=new WeakMap,Te=new WeakMap,Ee=new WeakMap,ee=new WeakMap,Y=new WeakMap,te=new WeakMap,U=new WeakMap,A=new WeakMap,_=new WeakMap,K=new WeakMap,j=new WeakMap,H=new WeakMap,F=new WeakMap,re=new WeakMap,V=new WeakMap,ne=new WeakMap,ie=new WeakMap,k=new WeakMap,$=new WeakMap,ae=new WeakMap,Se=new WeakMap,W=new WeakMap,Ce=new WeakMap,c=new WeakSet,$e=function(){let e=new Ye(r(this,X)),t=new Ye(r(this,X));y(this,k,e),y(this,ie,t);let n=this.ttlAutopurge?new Array(r(this,X)):void 0;y(this,$,n),y(this,Me,(h,p,S=r(this,ee).now())=>{t[h]=p!==0?S:0,e[h]=p,i(h,p);}),y(this,me,h=>{t[h]=e[h]!==0?r(this,ee).now():0,i(h,e[h]);});let i=this.ttlAutopurge?(h,p)=>{if(n?.[h]&&(clearTimeout(n[h]),n[h]=void 0),p&&p!==0&&n){let S=setTimeout(()=>{r(this,q).call(this,h)&&f(this,c,be).call(this,r(this,A)[h],"expire");},p+1);S.unref&&S.unref(),n[h]=S;}}:()=>{};y(this,he,(h,p)=>{if(e[p]){let S=e[p],u=t[p];if(!S||!u)return;h.ttl=S,h.start=u,h.now=a||o();let L=h.now-u;h.remainingTTL=S-L;}});let a=0,o=()=>{let h=r(this,ee).now();if(this.ttlResolution>0){a=h;let p=setTimeout(()=>a=0,this.ttlResolution);p.unref&&p.unref();}return h};this.getRemainingTTL=h=>{let p=r(this,U).get(h);if(p===void 0)return 0;let S=e[p],u=t[p];if(!S||!u)return 1/0;let L=(a||o())-u;return S-L},y(this,q,h=>{let p=t[h],S=e[h];return !!S&&!!p&&(a||o())-p>S});},me=new WeakMap,he=new WeakMap,Me=new WeakMap,q=new WeakMap,ot=function(){let e=new Ye(r(this,X));y(this,te,0),y(this,ne,e),y(this,ge,t=>{y(this,te,r(this,te)-e[t]),e[t]=0;}),y(this,Ne,(t,n,i,a)=>{if(f(this,c,x).call(this,n))return 0;if(!ue(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!ue(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),y(this,Ie,(t,n,i)=>{if(e[t]=n,r(this,B)){let a=r(this,B)-e[t];for(;r(this,te)>a;)f(this,c,Fe).call(this,true);}y(this,te,r(this,te)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=r(this,te));});},ge=new WeakMap,Ie=new WeakMap,Ne=new WeakMap,de=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,F);!(!f(this,c,qe).call(this,t)||((e||!r(this,q).call(this,t))&&(yield t),t===r(this,H)));)t=r(this,j)[t];},fe=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,H);!(!f(this,c,qe).call(this,t)||((e||!r(this,q).call(this,t))&&(yield t),t===r(this,F)));)t=r(this,K)[t];},qe=function(e){return e!==void 0&&r(this,U).get(r(this,A)[e])===e},Fe=function(e){var a;let t=r(this,H),n=r(this,A)[t],i=r(this,_)[t];return r(this,Se)&&f(this,c,x).call(this,i)?i.__abortController.abort(new Error("evicted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((a=r(this,Q))==null||a.call(this,i,n,"evict")),r(this,W)&&r(this,V)?.push([i,n,"evict"])),r(this,ge).call(this,t),r(this,$)?.[t]&&(clearTimeout(r(this,$)[t]),r(this,$)[t]=void 0),e&&(r(this,A)[t]=void 0,r(this,_)[t]=void 0,r(this,re).push(t)),r(this,Y)===1?(y(this,H,y(this,F,0)),r(this,re).length=0):y(this,H,r(this,K)[t]),r(this,U).delete(n),Ue(this,Y)._--,t},Ve=function(e,t,n,i){let a=t===void 0?void 0:r(this,_)[t];if(f(this,c,x).call(this,a))return a;let o=new Ge,{signal:h}=n;h?.addEventListener("abort",()=>o.abort(h.reason),{signal:o.signal});let p={signal:o.signal,options:n,context:i},S=(w,T=false)=>{let{aborted:l}=o.signal,d=n.ignoreFetchAbort&&w!==void 0,C=n.ignoreFetchAbort||!!(n.allowStaleOnFetchAbort&&w!==void 0);if(n.status&&(l&&!T?(n.status.fetchAborted=true,n.status.fetchError=o.signal.reason,d&&(n.status.fetchAbortIgnored=true)):n.status.fetchResolved=true),l&&!d&&!T)return L(o.signal.reason,C);let E=N,O=r(this,_)[t];return (O===N||d&&T&&O===void 0)&&(w===void 0?E.__staleWhileFetching!==void 0?r(this,_)[t]=E.__staleWhileFetching:f(this,c,be).call(this,e,"fetch"):(n.status&&(n.status.fetchUpdated=true),this.set(e,w,p.options))),w},u=w=>(n.status&&(n.status.fetchRejected=true,n.status.fetchError=w),L(w,false)),L=(w,T)=>{let{aborted:l}=o.signal,d=l&&n.allowStaleOnFetchAbort,C=d||n.allowStaleOnFetchRejection,E=C||n.noDeleteOnFetchRejection,O=N;if(r(this,_)[t]===N&&(!E||!T&&O.__staleWhileFetching===void 0?f(this,c,be).call(this,e,"fetch"):d||(r(this,_)[t]=O.__staleWhileFetching)),C)return n.status&&O.__staleWhileFetching!==void 0&&(n.status.returnedStale=true),O.__staleWhileFetching;if(O.__returned===O)throw w},M=(w,T)=>{var d;let l=(d=r(this,Te))==null?void 0:d.call(this,e,a,p);l&&l instanceof Promise&&l.then(C=>w(C===void 0?void 0:C),T),o.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(w(void 0),n.allowStaleOnFetchAbort&&(w=C=>S(C,true)));});};n.status&&(n.status.fetchDispatched=true);let N=new Promise(M).then(S,u),D=Object.assign(N,{__abortController:o,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,D,{...p.options,status:void 0}),t=r(this,U).get(e)):r(this,_)[t]=D,D},x=function(e){if(!r(this,Se))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Ge},Xe=function(e,t){r(this,j)[t]=e,r(this,K)[e]=t;},Ae=function(e){e!==r(this,F)&&(e===r(this,H)?y(this,H,r(this,K)[e]):f(this,c,Xe).call(this,r(this,j)[e],r(this,K)[e]),f(this,c,Xe).call(this,r(this,F),e),y(this,F,e));},be=function(e,t){var i,a;let n=false;if(r(this,Y)!==0){let o=r(this,U).get(e);if(o!==void 0)if(r(this,$)?.[o]&&(clearTimeout(r(this,$)?.[o]),r(this,$)[o]=void 0),n=true,r(this,Y)===1)f(this,c,Je).call(this,t);else {r(this,ge).call(this,o);let h=r(this,_)[o];if(f(this,c,x).call(this,h)?h.__abortController.abort(new Error("deleted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((i=r(this,Q))==null||i.call(this,h,e,t)),r(this,W)&&r(this,V)?.push([h,e,t])),r(this,U).delete(e),r(this,A)[o]=void 0,r(this,_)[o]=void 0,o===r(this,F))y(this,F,r(this,j)[o]);else if(o===r(this,H))y(this,H,r(this,K)[o]);else {let p=r(this,j)[o];r(this,K)[p]=r(this,K)[o];let S=r(this,K)[o];r(this,j)[S]=r(this,j)[o];}Ue(this,Y)._--,r(this,re).push(o);}}if(r(this,W)&&r(this,V)?.length){let o=r(this,V),h;for(;h=o?.shift();)(a=r(this,Z))==null||a.call(this,...h);}return n},Je=function(e){var t,n;for(let i of f(this,c,fe).call(this,{allowStale:true})){let a=r(this,_)[i];if(f(this,c,x).call(this,a))a.__abortController.abort(new Error("deleted"));else {let o=r(this,A)[i];r(this,ae)&&((t=r(this,Q))==null||t.call(this,a,o,e)),r(this,W)&&r(this,V)?.push([a,o,e]);}}if(r(this,U).clear(),r(this,_).fill(void 0),r(this,A).fill(void 0),r(this,k)&&r(this,ie)){r(this,k).fill(0),r(this,ie).fill(0);for(let i of r(this,$)??[])i!==void 0&&clearTimeout(i);r(this,$)?.fill(void 0);}if(r(this,ne)&&r(this,ne).fill(0),y(this,H,0),y(this,F,0),r(this,re).length=0,y(this,te,0),y(this,Y,0),r(this,W)&&r(this,V)){let i=r(this,V),a;for(;a=i?.shift();)(n=r(this,Z))==null||n.call(this,...a);}},Oe);var De=class{cache;map=new Map;constructor(e){this.cache=new st({max:e.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){this.cache.clear(),this.map.clear();}delete(e){let t=this.map.delete(e);return t&&this.cache.delete(e),t}get forEach(){return this.map.forEach}get(e){let t=this.cache.get(e);return t||this.map.get(e)}has(e){return this.map.has(e)}set(e,t){return this.map.set(e,t),this.cache.set(e,t),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var g;(i=>(i.log=(a,...o)=>console.log(`[Pixi\u2019VN] ${a}`,...o),i.warn=(a,...o)=>console.warn(`[Pixi\u2019VN] ${a}`,...o),i.error=(a,...o)=>console.error(`[Pixi\u2019VN] ${a}`,...o),i.info=(a,...o)=>console.info(`[Pixi\u2019VN] ${a}`,...o)))(g||={});var Re=new De({cacheSize:10}),lt;(o=>{function s(h){let p=Re.get(h);if(!p){g.error(`Label "${h}" not found`);return}return p}o.get=s;function e(...h){for(let p of h)Re.set(p.id,p);}o.add=e;function t(){return Array.from(Re.values())}o.values=t;function n(h){return Re.has(h)}o.has=n;function i(){return Array.from(Re.keys())}o.keys=i;function a(){Re.clear();}o.clear=a;})(lt||={});var se=lt;function pe(s){try{if(typeof s>"u")return s;let e=JSON.stringify(s);return JSON.parse(e)}catch(e){throw g.error("Error creating exportable element",s,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var b=class s{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return core.GameUnifier.getVariable(R,I.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){core.GameUnifier.setVariable(R,I.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=s.currentLabelStepIndex;if(t===null)return g.error("currentLabelStepIndex is null"),null;let n=`${t}${e}`,i=s.currentLabelId,a=s._currentLabel;if(!i||t===null||!a)return g.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let o=a.getStepSha(t)||"error",h=core.GameUnifier.getVariable(R,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return h[i]||(h[i]={}),(!h[i][n]||h[i][n].stepSha1!==o)&&(h[i][n]={stepSha1:o}),h[i][n]}static setCurrentStepTimesCounterData(e="",t){let n=s.currentLabelStepIndex,i=n+e,a=s.currentLabelId;if(!a||n===null){g.error("currentLabelId or currentLabelStepIndex is null");return}let o=core.GameUnifier.getVariable(R,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};o[a]||(o[a]={}),o[a][i]=t,core.GameUnifier.setVariable(R,I.CURRENT_STEP_TIMES_COUNTER_KEY,o);}static getCurrentStepTimesCounter(e=""){let t=s._stepCounter,n=s.getCurrentStepTimesCounterData(e);if(!n)return g.error("getCurrentStepTimesCounter obj is null"),0;let i=n.stepCounters||[];return i.find(o=>o===t)||(i.push(t),n.stepCounters=i,s.setCurrentStepTimesCounterData(e,n)),i.length}static getRandomNumber(e,t,n={}){let i=n.nestedId||"";if(n.onceOnly||false){let o=s.getCurrentStepTimesCounterData(i);if(!o)return;let h=o.usedRandomNumbers||{},p=Array.from({length:t-e+1},(L,M)=>M+e).filter(L=>!h[`${e}-${t}`]?.includes(L));if(p.length===0)return;let S=Math.floor(Math.random()*p.length),u=p[S];return h[`${e}-${t}`]||(h[`${e}-${t}`]=[]),h[`${e}-${t}`].push(u),o.usedRandomNumbers=h,s.setCurrentStepTimesCounterData(i,o),u}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=s.currentLabelStepIndex,n=t+e,i=s.currentLabelId;if(!i||t===null){g.error("currentLabelId or currentLabelStepIndex is null");return}let a=core.GameUnifier.getVariable(R,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[i]||(a[i]={}),a[i][n]={stepCounters:[],stepSha1:""},core.GameUnifier.setVariable(R,I.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return core.GameUnifier.getVariable(R,I.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){core.GameUnifier.setVariable(R,I.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){s._stepCounter++;}static _openedLabels=[];static get openedLabels(){return pe(s._openedLabels)}static set openedLabels(e){s._openedLabels=pe(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return pe(s._originalOpenedLabels)}static set originalOpenedLabels(e){s._originalOpenedLabels=pe(e);}static get _currentLabel(){if(s.currentLabelId)return se.get(s.currentLabelId)}static get currentLabelId(){if(s._openedLabels.length>0)return s._openedLabels[s._openedLabels.length-1].label}static get currentLabelStepIndex(){return s._openedLabels.length>0?s._openedLabels[s._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;(!i||i<t)&&(n[e]={biggestStep:t,openCount:a},s.allOpenedLabels=n);}static addChoicesMade(e,t,n,i){let a=s.allChoicesMade,o=a.findIndex(h=>h.labelId===e&&h.stepIndex===t&&h.choiceIndex===i&&h.stepSha1===n);o<0?a.push({labelId:e,stepIndex:t,choiceIndex:i,stepSha1:n,madeTimes:1}):a[o].madeTimes++,s.allChoicesMade=a;}static pushNewLabel(e){if(!se.get(e))throw new core.PixiError("unregistered_element",`Label ${e} not found`);s._openedLabels.push({label:e,currentStepIndex:0});let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;n[e]={biggestStep:i,openCount:a+1},s.allOpenedLabels=n;}static increaseCurrentStepIndex(){if(s._openedLabels.length>0){let e=s._openedLabels[s._openedLabels.length-1];s._openedLabels[s._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){s._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let n=[];return s.onLoadingLabel&&e===0&&n.push(s.onLoadingLabel(e,t)),s._onStepStart&&n.push(s._onStepStart(e,t)),await Promise.all(n)}}static onLoadingLabel;static onStepEnd};var Pe=class{get currentStepTimesCounter(){return b.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){b.resetCurrentStepTimesCounter();}getRandomNumber(e,t,n={}){return b.getRandomNumber(e,t,n)}get stepCounter(){return b._stepCounter}get openedLabels(){return b.openedLabels}get currentLabel(){return b._currentLabel}addStepHistory(e,t={}){let{choiceMade:n,ignoreSameStep:i}=t,a,o,h,p=core.GameUnifier.getVariable(R,I.LAST_STEP_GLUED)===this.stepCounter;core.GameUnifier.getVariable(R,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=core.GameUnifier.getVariable(R,I.CURRENT_DIALOGUE_MEMORY_KEY)),core.GameUnifier.getVariable(R,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(o=core.GameUnifier.getVariable(R,I.CURRENT_MENU_OPTIONS_MEMORY_KEY)),core.GameUnifier.getVariable(R,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(h=core.GameUnifier.getVariable(R,I.CURRENT_INPUT_VALUE_MEMORY_KEY));let S=b.openedLabels,u={currentLabel:b.currentLabelId,dialogue:a,choices:o,stepSha1:e,index:this.stepCounter,labelStepIndex:b.currentLabelStepIndex,choiceIndexMade:n,inputValue:h,alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:p,openedLabels:S};b.originalOpenedLabels=S,core.GameUnifier.addHistoryItem(u,{ignoreSameStep:i}),b.lastHistoryStep=u,b.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=b.currentLabelStepIndex,n=this.currentLabel;if(!(t===null||!n))return b.allChoicesMade.filter(i=>i.labelId===n.id&&i.stepIndex===t&&i.stepSha1===e).map(i=>i.choiceIndex)}closeCurrentLabel(){if(!b.currentLabelId){g.warn("No label to close");return}if(!this.currentLabel){g.error("currentLabel not found");return}let e=b.openedLabels;e.pop(),b.openedLabels=e,core.GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;b.openedLabels.length>0;)this.closeCurrentLabel(),core.GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let i=b.allOpenedLabels[t]?.biggestStep||0;if(i){let a=se.get(t);if(a)return a.stepCount<=i}return false}get alreadyCurrentStepMadeChoicesObj(){let e=b.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let n=t.getStepSha(e);return n||(g.warn("stepSha not found, setting to ERROR"),n="error"),b.allChoicesMade.filter(i=>i.labelId===t?.id&&i.stepIndex===e&&i.stepSha1===n)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=b.currentLabelId;if(e){let t=b.allOpenedLabels[e]?.openCount||0;if(b.currentLabelStepIndex&&t>=b.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return b.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e){let t=e?.showWarn||false,n=this.choices;return n&&n.length>0?(t&&g.warn("The player must make a choice"),false):this.isRequiredInput?(t&&g.warn("The player must enter a value"),false):true}get canContinue(){return core.GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let n=[];return e.onStepStart&&n.push(e.onStepStart(t,e)),b.onStepStart&&n.push(b.onStepStart(t,e)),await Promise.all(n)}async onStepEnd(e,t){let n=[];return e.onStepEnd&&n.push(e.onStepEnd(t,e)),b.onStepEnd&&n.push(b.onStepEnd(t,e)),await Promise.all(n)}async continue(e,t={}){let{runNow:n=false,steps:i=1}=t;if(!Number.isFinite(i)){g.warn(`[continue] The parameter steps must be a valid finite number, received: ${i}`);return}if(i<=0){g.warn(`[continue] The parameter steps must be greater than 0, received: ${i}`);return}if(!n&&!this.getCanContinue({showWarn:true}))return;if(!n&&core.GameUnifier.runningStepsCount!==0){core.GameUnifier.increaseContinueRequest(i);return}i>1&&core.GameUnifier.increaseContinueRequest(i-1),core.GameUnifier.runningStepsCount++;let a;try{core.GameUnifier.runningStepsCount===1&&await core.GameUnifier.onPreContinue(),b.increaseCurrentStepIndex(),a=await this.runCurrentStep(e,t);}catch(o){throw g.error("Error continuing",o),o}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||a}async afterRunCurrentStep(e){if(core.GameUnifier.runningStepsCount===0&&core.GameUnifier.continueRequestsCount!==0)return await core.GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(core.GameUnifier.onEnd)return await core.GameUnifier.onEnd(e,{labelId:"end"});g.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e,t={}){let{choiceMade:n}=t;if(b.currentLabelId){let i=b.currentLabelStepIndex;if(i===null){g.error("currentLabelStepIndex is null");return}let a=b._currentLabel;if(!a){g.error("currentLabel not found");return}if(a.stepCount>i){try{await this.onStepStart(a,i);}catch(u){g.error("Error running onStepStart",u),this.onStepError&&await this.onStepError(u,e);return}let o=a.getStepById(i);if(!o){g.error("step not found");return}let h=a.getStepSha(i);h||(g.warn("stepSha not found, setting to ERROR"),h="error");let p,S;try{p=await o(e,{labelId:a.id});}catch(u){g.error("Error running step",u),S=u;}try{let u=this.choices;if(u?.length===1&&u[0].autoSelect){let L=u[0];p=await this.selectChoice(L,e);}}catch(u){g.error("Error auto-selecting choice",u),S||(S=u);}try{let u=b.lastHistoryStep;n!==void 0&&u&&(h=u.stepSha1,h||(g.warn("stepSha not found, setting to ERROR"),h="error"),b.addChoicesMade(u.currentLabel||"error",typeof u.labelStepIndex=="number"?u.labelStepIndex:-1,u.stepSha1||"error",n),b.choiceMadeTemp=n);}catch(u){g.warn("Error adding choice made to history",u);}try{core.GameUnifier.runningStepsCount===1&&(b.addLabelHistory(a.id,i),this.addStepHistory(h,{...t,choiceMade:b.choiceMadeTemp}),b.choiceMadeTemp=void 0);}catch(u){g.warn("Error adding step to history",u);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,b.currentLabelStepIndex||0);}catch(u){g.warn("Error running onStepEnd",u);}return S&&this.onStepError&&await this.onStepError(S,e),p}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e,t);if(this.openedLabels.length===1){b.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;g.error("currentLabelId not found");}}async call(e,t,n){let{choiceMade:i}=n||{},a;typeof e=="string"?a=e:a=e.id,core.GameUnifier.runningStepsCount++;let o;try{let h=se.get(a);if(!h)throw new core.PixiError("unregistered_element",`Label ${a} not found`);b.pushNewLabel(h.id),o=await this.runCurrentStep(t,{choiceMade:i});}catch(h){throw g.error("Error calling label",h),h}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||o}async jump(e,t,n){if(this.stepCounter===0)return await this.call(e,t,n);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:i}=n||{},a;typeof e=="string"?a=e:a=e.id,core.GameUnifier.runningStepsCount++;let o;try{let h=se.get(a);if(!h)throw new core.PixiError("unregistered_element",`Label ${a} not found`);b.pushNewLabel(h.id),o=await this.runCurrentStep(t,{choiceMade:i});}catch(h){throw g.error("Error jumping to label",h),h}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||o}async selectChoice(e,t){this.choices=void 0;let n=e.type;switch(n){case "call":return await this.call(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "jump":return await this.jump(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "close":return await this.closeChoiceMenu(e,{...e.props,...t});default:throw g.error(`Type ${n} not found`),new core.PixiError("invalid_usage",`Type ${n} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw g.error("For closeChoiceMenu, the type must be close"),new core.PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let n;return typeof e.choiceIndex=="number"&&(n=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:n})}get onStepError(){return async(e,t)=>{try{await core.GameUnifier.runOnError(e,t);}catch(n){g.error("Error in onError handler",n);}}}get dialogue(){let e=core.GameUnifier.getVariable(R,I.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?core.GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){core.GameUnifier.setVariable(R,I.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=core.GameUnifier.getVariable(R,I.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let n=[];Array.isArray(t.text)?n=[...t.text]:n=[t.text],Array.isArray(e.text)?n=[...n,...e.text]:n=[...n,e.text],e.text=n,e.character=e.character||t.character;}core.GameUnifier.setVariable(R,I.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{core.GameUnifier.setVariable(R,I.CURRENT_DIALOGUE_MEMORY_KEY,pe({...e,character:typeof e.character=="string"?e.character:e.character?.id})),core.GameUnifier.setVariable(R,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw g.error("DialogueInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=core.GameUnifier.getVariable(R,I.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],n=e.map((a,o)=>({...a,choiceIndex:o})),i=this.alreadyCurrentStepMadeChoices;if(n=n.filter((a,o)=>a.oneTime&&i?.includes(o)?false:a.onlyHaveNoChoice?(t.push(a),false):true),n.length>0)return n;if(t.length>0)return [t[0]]}}set choices(e){if(!e||e.length===0){core.GameUnifier.setVariable(R,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{core.GameUnifier.setVariable(R,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,pe(e)),core.GameUnifier.setVariable(R,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw g.error("ChoiceInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return core.GameUnifier.getFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){core.GameUnifier.setFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return core.GameUnifier.getVariable(R,I.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),core.GameUnifier.setVariable(R,I.CURRENT_INPUT_VALUE_MEMORY_KEY,e),core.GameUnifier.setVariable(R,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return core.GameUnifier.getVariable(R,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return core.GameUnifier.getVariable(R,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,core.GameUnifier.setVariable(R,I.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?core.GameUnifier.setVariable(R,I.CURRENT_INPUT_VALUE_MEMORY_KEY,t):core.GameUnifier.removeVariable(R,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){core.GameUnifier.removeVariable(R,I.CURRENT_INPUT_INFO_MEMORY_KEY),core.GameUnifier.removeVariable(R,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){b.openedLabels=[],b._stepCounter=0;}export(){return {openedLabels:pe(b.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async n=>{let i=[],a=se.get(n.label);return a&&(a.onLoadingLabel&&i.push(a.onLoadingLabel(e,a)),b.onLoadingLabel&&i.push(b.onLoadingLabel(e,a))),await Promise.all(i)});return await Promise.all(t)}async restore(e,t){this.clear();try{b.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(b.openedLabels=e.openedLabels,b.originalOpenedLabels=b.openedLabels):g.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?b._stepCounter=e.stepCounter:g.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(b.currentLabelStepIndex||0);}catch(n){g.error("Error running onLoadingLabel",n);}}catch(n){g.error("Error importing data",n);}}};function xt(s,e,t,n){let i=typeof e=="string"?e:e.id;return {...n,label:i,props:t,text:s,type:n?.type||"call"}}var ht="close";function At(s,e){return {...e,type:ht,text:s}}var ft=Et(dt());var we=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var xe=class extends we{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,n){super(e,n),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e){let t=this.steps;if(e<0||e>=t.length)return typeof this._steps!="function"&&g.warn("stepSha not found, setting to ERROR"),"error";try{return (0,ft.default)(t[e].toString().toLocaleLowerCase()).toString()}catch(n){return g.warn("stepSha not found, setting to ERROR",n),"error"}}};function bt(s,e,t){let n=new xe(s,e,t);return se.add(n),n}var Er=new Pe;
2
- exports.Label=xe;exports.LabelAbstract=we;exports.NarrationManagerStatic=b;exports.RegisteredLabels=se;exports.narration=Er;exports.newChoiceOption=xt;exports.newCloseChoiceOption=At;exports.newLabel=bt;
1
+ 'use strict';var core=require('@drincs/pixi-vn/core');var yt=Object.create;var We=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Qe=s=>{throw TypeError(s)};var Tt=(s,e,t)=>e in s?We(s,e,{enumerable:true,configurable:true,writable:true,value:t}):s[e]=t;var Be=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ze=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var _t=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mt(e))!Lt.call(s,i)&&i!==t&&We(s,i,{get:()=>e[i],enumerable:!(n=St(e,i))||n.enumerable});return s};var Et=(s,e,t)=>(t=s!=null?yt(gt(s)):{},_t(We(t,"default",{value:s,enumerable:true}),s));var z=(s,e,t)=>Tt(s,typeof e!="symbol"?e+"":e,t),je=(s,e,t)=>e.has(s)||Qe("Cannot "+t);var r=(s,e,t)=>(je(s,e,"read from private field"),t?t.call(s):e.get(s)),v=(s,e,t)=>e.has(s)?Qe("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),S=(s,e,t,n)=>(je(s,e,"write to private field"),e.set(s,t),t),f=(s,e,t)=>(je(s,e,"access private method"),t);var Ue=(s,e,t,n)=>({set _(i){S(s,e,i);},get _(){return r(s,e,n)}});var ct=Ze((ze,ht)=>{(function(s,e){typeof ze=="object"?ht.exports=ze=e():typeof define=="function"&&define.amd?define([],e):s.CryptoJS=e();})(ze,function(){var s=s||(function(e,t){var n;if(typeof window<"u"&&window.crypto&&(n=window.crypto),typeof self<"u"&&self.crypto&&(n=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(n=globalThis.crypto),!n&&typeof window<"u"&&window.msCrypto&&(n=window.msCrypto),!n&&typeof global<"u"&&global.crypto&&(n=global.crypto),!n&&typeof Be=="function")try{n=Be("crypto");}catch{}var i=function(){if(n){if(typeof n.getRandomValues=="function")try{return n.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof n.randomBytes=="function")try{return n.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||(function(){function l(){}return function(d){var C;return l.prototype=d,C=new l,l.prototype=null,C}})(),o={},p=o.lib={},h=p.Base=(function(){return {extend:function(l){var d=a(this);return l&&d.mixIn(l),(!d.hasOwnProperty("init")||this.init===d.init)&&(d.init=function(){d.$super.init.apply(this,arguments);}),d.init.prototype=d,d.$super=this,d},create:function(){var l=this.extend();return l.init.apply(l,arguments),l},init:function(){},mixIn:function(l){for(var d in l)l.hasOwnProperty(d)&&(this[d]=l[d]);l.hasOwnProperty("toString")&&(this.toString=l.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),b=p.WordArray=h.extend({init:function(l,d){l=this.words=l||[],d!=t?this.sigBytes=d:this.sigBytes=l.length*4;},toString:function(l){return (l||g).stringify(this)},concat:function(l){var d=this.words,C=l.words,E=this.sigBytes,R=l.sigBytes;if(this.clamp(),E%4)for(var D=0;D<R;D++){var se=C[D>>>2]>>>24-D%4*8&255;d[E+D>>>2]|=se<<24-(E+D)%4*8;}else for(var G=0;G<R;G+=4)d[E+G>>>2]=C[G>>>2];return this.sigBytes+=R,this},clamp:function(){var l=this.words,d=this.sigBytes;l[d>>>2]&=4294967295<<32-d%4*8,l.length=e.ceil(d/4);},clone:function(){var l=h.clone.call(this);return l.words=this.words.slice(0),l},random:function(l){for(var d=[],C=0;C<l;C+=4)d.push(i());return new b.init(d,l)}}),u=o.enc={},g=u.Hex={stringify:function(l){for(var d=l.words,C=l.sigBytes,E=[],R=0;R<C;R++){var D=d[R>>>2]>>>24-R%4*8&255;E.push((D>>>4).toString(16)),E.push((D&15).toString(16));}return E.join("")},parse:function(l){for(var d=l.length,C=[],E=0;E<d;E+=2)C[E>>>3]|=parseInt(l.substr(E,2),16)<<24-E%8*4;return new b.init(C,d/2)}},M=u.Latin1={stringify:function(l){for(var d=l.words,C=l.sigBytes,E=[],R=0;R<C;R++){var D=d[R>>>2]>>>24-R%4*8&255;E.push(String.fromCharCode(D));}return E.join("")},parse:function(l){for(var d=l.length,C=[],E=0;E<d;E++)C[E>>>2]|=(l.charCodeAt(E)&255)<<24-E%4*8;return new b.init(C,d)}},N=u.Utf8={stringify:function(l){try{return decodeURIComponent(escape(M.stringify(l)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(l){return M.parse(unescape(encodeURIComponent(l)))}},P=p.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new b.init,this._nDataBytes=0;},_append:function(l){typeof l=="string"&&(l=N.parse(l)),this._data.concat(l),this._nDataBytes+=l.sigBytes;},_process:function(l){var d,C=this._data,E=C.words,R=C.sigBytes,D=this.blockSize,se=D*4,G=R/se;l?G=e.ceil(G):G=e.max((G|0)-this._minBufferSize,0);var J=G*D,Le=e.min(J*4,R);if(J){for(var Ke=0;Ke<J;Ke+=D)this._doProcessBlock(E,Ke);d=E.splice(0,J),C.sigBytes-=Le;}return new b.init(d,Le)},clone:function(){var l=h.clone.call(this);return l._data=this._data.clone(),l},_minBufferSize:0});p.Hasher=P.extend({cfg:h.extend(),init:function(l){this.cfg=this.cfg.extend(l),this.reset();},reset:function(){P.reset.call(this),this._doReset();},update:function(l){return this._append(l),this._process(),this},finalize:function(l){l&&this._append(l);var d=this._doFinalize();return d},blockSize:512/32,_createHelper:function(l){return function(d,C){return new l.init(C).finalize(d)}},_createHmacHelper:function(l){return function(d,C){return new _.HMAC.init(l,C).finalize(d)}}});var _=o.algo={};return o})(Math);return s});});var dt=Ze((He,ut)=>{(function(s,e){typeof He=="object"?ut.exports=He=e(ct()):typeof define=="function"&&define.amd?define(["./core"],e):e(s.CryptoJS);})(He,function(s){return (function(){var e=s,t=e.lib,n=t.WordArray,i=t.Hasher,a=e.algo,o=[],p=a.SHA1=i.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(h,b){for(var u=this._hash.words,g=u[0],M=u[1],N=u[2],P=u[3],w=u[4],_=0;_<80;_++){if(_<16)o[_]=h[b+_]|0;else {var l=o[_-3]^o[_-8]^o[_-14]^o[_-16];o[_]=l<<1|l>>>31;}var d=(g<<5|g>>>27)+w+o[_];_<20?d+=(M&N|~M&P)+1518500249:_<40?d+=(M^N^P)+1859775393:_<60?d+=(M&N|M&P|N&P)-1894007588:d+=(M^N^P)-899497514,w=P,P=N,N=M<<30|M>>>2,M=g,g=d;}u[0]=u[0]+g|0,u[1]=u[1]+M|0,u[2]=u[2]+N|0,u[3]=u[3]+P|0,u[4]=u[4]+w|0;},_doFinalize:function(){var h=this._data,b=h.words,u=this._nDataBytes*8,g=h.sigBytes*8;return b[g>>>5]|=128<<24-g%32,b[(g+64>>>9<<4)+14]=Math.floor(u/4294967296),b[(g+64>>>9<<4)+15]=u,h.sigBytes=b.length*4,this._process(),this._hash},clone:function(){var h=i.clone.call(this);return h._hash=this._hash.clone(),h}});e.SHA1=i._createHelper(p),e.HmacSHA1=i._createHmacHelper(p);})(),s.SHA1});});var O="narration";var I={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 Ct=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,nt=new Set,ke=typeof process=="object"&&process?process:{},it=(s,e,t,n)=>{typeof ke.emitWarning=="function"?ke.emitWarning(s,e,t,n):console.error(`[${t}] ${e}: ${s}`);},Ge=globalThis.AbortController,et=globalThis.AbortSignal;if(typeof Ge>"u"){et=class{onabort;_onabort=[];reason;aborted=false;addEventListener(t,n){this._onabort.push(n);}},Ge=class{constructor(){e();}signal=new et;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let n of this.signal._onabort)n(t);this.signal.onabort?.(t);}}};let s=ke.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{s&&(s=false,it("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 It=s=>!nt.has(s);var ue=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),at=s=>ue(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?Ye:null:null,Ye=class extends Array{constructor(s){super(s),this.fill(0);}},oe,Te,Rt=(oe=class{heap;length;static create(e){let t=at(e);if(!t)return [];S(oe,Te,true);let n=new oe(e,t);return S(oe,Te,false),n}constructor(e,t){if(!r(oe,Te))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},Te=new WeakMap,v(oe,Te,false),oe),tt,rt,X,B,Q,Se,Z,_e,Ee,ee,Y,te,U,A,T,K,j,H,F,re,V,ne,ie,k,$,ae,ye,W,Ce,c,$e,me,pe,Ae,q,ot,ge,Ie,Me,de,fe,qe,Fe,Ve,x,Xe,xe,be,Je,Re,st=(Re=class{constructor(e){v(this,c);v(this,X);v(this,B);v(this,Q);v(this,Se);v(this,Z);v(this,_e);v(this,Ee);v(this,ee);z(this,"ttl");z(this,"ttlResolution");z(this,"ttlAutopurge");z(this,"updateAgeOnGet");z(this,"updateAgeOnHas");z(this,"allowStale");z(this,"noDisposeOnSet");z(this,"noUpdateTTL");z(this,"maxEntrySize");z(this,"sizeCalculation");z(this,"noDeleteOnFetchRejection");z(this,"noDeleteOnStaleGet");z(this,"allowStaleOnFetchAbort");z(this,"allowStaleOnFetchRejection");z(this,"ignoreFetchAbort");v(this,Y);v(this,te);v(this,U);v(this,A);v(this,T);v(this,K);v(this,j);v(this,H);v(this,F);v(this,re);v(this,V);v(this,ne);v(this,ie);v(this,k);v(this,$);v(this,ae);v(this,ye);v(this,W);v(this,Ce);v(this,me,()=>{});v(this,pe,()=>{});v(this,Ae,()=>{});v(this,q,()=>false);v(this,ge,e=>{});v(this,Ie,(e,t,n)=>{});v(this,Me,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});z(this,tt,"LRUCache");let{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:p,allowStale:h,dispose:b,onInsert:u,disposeAfter:g,noDisposeOnSet:M,noUpdateTTL:N,maxSize:P=0,maxEntrySize:w=0,sizeCalculation:_,fetchMethod:l,memoMethod:d,noDeleteOnFetchRejection:C,noDeleteOnStaleGet:E,allowStaleOnFetchRejection:R,allowStaleOnFetchAbort:D,ignoreFetchAbort:se,perf:G}=e;if(G!==void 0&&typeof G?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(S(this,ee,G??Ct),t!==0&&!ue(t))throw new TypeError("max option must be a nonnegative integer");let J=t?at(t):Array;if(!J)throw new Error("invalid max value: "+t);if(S(this,X,t),S(this,B,P),this.maxEntrySize=w||r(this,B),this.sizeCalculation=_,this.sizeCalculation){if(!r(this,B)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(d!==void 0&&typeof d!="function")throw new TypeError("memoMethod must be a function if defined");if(S(this,Ee,d),l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(S(this,_e,l),S(this,ye,!!l),S(this,U,new Map),S(this,A,new Array(t).fill(void 0)),S(this,T,new Array(t).fill(void 0)),S(this,K,new J(t)),S(this,j,new J(t)),S(this,H,0),S(this,F,0),S(this,re,Rt.create(t)),S(this,Y,0),S(this,te,0),typeof b=="function"&&S(this,Q,b),typeof u=="function"&&S(this,Se,u),typeof g=="function"?(S(this,Z,g),S(this,V,[])):(S(this,Z,void 0),S(this,V,void 0)),S(this,ae,!!r(this,Q)),S(this,Ce,!!r(this,Se)),S(this,W,!!r(this,Z)),this.noDisposeOnSet=!!M,this.noUpdateTTL=!!N,this.noDeleteOnFetchRejection=!!C,this.allowStaleOnFetchRejection=!!R,this.allowStaleOnFetchAbort=!!D,this.ignoreFetchAbort=!!se,this.maxEntrySize!==0){if(r(this,B)!==0&&!ue(r(this,B)))throw new TypeError("maxSize must be a positive integer if specified");if(!ue(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");f(this,c,ot).call(this);}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!E,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!p,this.ttlResolution=ue(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!ue(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,c,$e).call(this);}if(r(this,X)===0&&this.ttl===0&&r(this,B)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!r(this,X)&&!r(this,B)){let Le="LRU_CACHE_UNBOUNDED";It(Le)&&(nt.add(Le),it("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Le,Re));}}get perf(){return r(this,ee)}static unsafeExposeInternals(e){return {starts:r(e,ie),ttls:r(e,k),autopurgeTimers:r(e,$),sizes:r(e,ne),keyMap:r(e,U),keyList:r(e,A),valList:r(e,T),next:r(e,K),prev:r(e,j),get head(){return r(e,H)},get tail(){return r(e,F)},free:r(e,re),isBackgroundFetch:t=>{var n;return f(n=e,c,x).call(n,t)},backgroundFetch:(t,n,i,a)=>{var o;return f(o=e,c,Ve).call(o,t,n,i,a)},moveToTail:t=>{var n;return f(n=e,c,xe).call(n,t)},indexes:t=>{var n;return f(n=e,c,de).call(n,t)},rindexes:t=>{var n;return f(n=e,c,fe).call(n,t)},isStale:t=>{var n;return r(n=e,q).call(n,t)}}}get max(){return r(this,X)}get maxSize(){return r(this,B)}get calculatedSize(){return r(this,te)}get size(){return r(this,Y)}get fetchMethod(){return r(this,_e)}get memoMethod(){return r(this,Ee)}get dispose(){return r(this,Q)}get onInsert(){return r(this,Se)}get disposeAfter(){return r(this,Z)}getRemainingTTL(e){return r(this,U).has(e)?1/0:0}*entries(){for(let e of f(this,c,de).call(this))r(this,T)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,c,x).call(this,r(this,T)[e])&&(yield [r(this,A)[e],r(this,T)[e]]);}*rentries(){for(let e of f(this,c,fe).call(this))r(this,T)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,c,x).call(this,r(this,T)[e])&&(yield [r(this,A)[e],r(this,T)[e]]);}*keys(){for(let e of f(this,c,de).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,c,x).call(this,r(this,T)[e])&&(yield t);}}*rkeys(){for(let e of f(this,c,fe).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,c,x).call(this,r(this,T)[e])&&(yield t);}}*values(){for(let e of f(this,c,de).call(this))r(this,T)[e]!==void 0&&!f(this,c,x).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}*rvalues(){for(let e of f(this,c,fe).call(this))r(this,T)[e]!==void 0&&!f(this,c,x).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}[(rt=Symbol.iterator,tt=Symbol.toStringTag,rt)](){return this.entries()}find(e,t={}){for(let n of f(this,c,de).call(this)){let i=r(this,T)[n],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,r(this,A)[n],this))return this.get(r(this,A)[n],t)}}forEach(e,t=this){for(let n of f(this,c,de).call(this)){let i=r(this,T)[n],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}rforEach(e,t=this){for(let n of f(this,c,fe).call(this)){let i=r(this,T)[n],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}purgeStale(){let e=false;for(let t of f(this,c,fe).call(this,{allowStale:true}))r(this,q).call(this,t)&&(f(this,c,be).call(this,r(this,A)[t],"expire"),e=true);return e}info(e){let t=r(this,U).get(e);if(t===void 0)return;let n=r(this,T)[t],i=f(this,c,x).call(this,n)?n.__staleWhileFetching:n;if(i===void 0)return;let a={value:i};if(r(this,k)&&r(this,ie)){let o=r(this,k)[t],p=r(this,ie)[t];if(o&&p){let h=o-(r(this,ee).now()-p);a.ttl=h,a.start=Date.now();}}return r(this,ne)&&(a.size=r(this,ne)[t]),a}dump(){let e=[];for(let t of f(this,c,de).call(this,{allowStale:true})){let n=r(this,A)[t],i=r(this,T)[t],a=f(this,c,x).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;let o={value:a};if(r(this,k)&&r(this,ie)){o.ttl=r(this,k)[t];let p=r(this,ee).now()-r(this,ie)[t];o.start=Math.floor(Date.now()-p);}r(this,ne)&&(o.size=r(this,ne)[t]),e.unshift([n,o]);}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let i=Date.now()-n.start;n.start=r(this,ee).now()-i;}this.set(t,n.value,n);}}set(e,t,n={}){var M,N,P,w;if(t===void 0)return this.delete(e),this;let{ttl:i=this.ttl,start:a,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:p=this.sizeCalculation,status:h}=n,{noUpdateTTL:b=this.noUpdateTTL}=n,u=r(this,Me).call(this,e,t,n.size||0,p);if(this.maxEntrySize&&u>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),f(this,c,be).call(this,e,"set"),this;let g=r(this,Y)===0?void 0:r(this,U).get(e);if(g===void 0)g=r(this,Y)===0?r(this,F):r(this,re).length!==0?r(this,re).pop():r(this,Y)===r(this,X)?f(this,c,Fe).call(this,false):r(this,Y),r(this,A)[g]=e,r(this,T)[g]=t,r(this,U).set(e,g),r(this,K)[r(this,F)]=g,r(this,j)[g]=r(this,F),S(this,F,g),Ue(this,Y)._++,r(this,Ie).call(this,g,u,h),h&&(h.set="add"),b=false,r(this,Ce)&&((M=r(this,Se))==null||M.call(this,t,e,"add"));else {f(this,c,xe).call(this,g);let _=r(this,T)[g];if(t!==_){if(r(this,ye)&&f(this,c,x).call(this,_)){_.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:l}=_;l!==void 0&&!o&&(r(this,ae)&&((N=r(this,Q))==null||N.call(this,l,e,"set")),r(this,W)&&r(this,V)?.push([l,e,"set"]));}else o||(r(this,ae)&&((P=r(this,Q))==null||P.call(this,_,e,"set")),r(this,W)&&r(this,V)?.push([_,e,"set"]));if(r(this,ge).call(this,g),r(this,Ie).call(this,g,u,h),r(this,T)[g]=t,h){h.set="replace";let l=_&&f(this,c,x).call(this,_)?_.__staleWhileFetching:_;l!==void 0&&(h.oldValue=l);}}else h&&(h.set="update");r(this,Ce)&&this.onInsert?.(t,e,t===_?"update":"replace");}if(i!==0&&!r(this,k)&&f(this,c,$e).call(this),r(this,k)&&(b||r(this,Ae).call(this,g,i,a),h&&r(this,pe).call(this,h,g)),!o&&r(this,W)&&r(this,V)){let _=r(this,V),l;for(;l=_?.shift();)(w=r(this,Z))==null||w.call(this,...l);}return this}pop(){var e;try{for(;r(this,Y);){let t=r(this,T)[r(this,H)];if(f(this,c,Fe).call(this,!0),f(this,c,x).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(r(this,W)&&r(this,V)){let t=r(this,V),n;for(;n=t?.shift();)(e=r(this,Z))==null||e.call(this,...n);}}}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=r(this,U).get(e);if(a!==void 0){let o=r(this,T)[a];if(f(this,c,x).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(r(this,q).call(this,a))i&&(i.has="stale",r(this,pe).call(this,i,a));else return n&&r(this,me).call(this,a),i&&(i.has="hit",r(this,pe).call(this,i,a)),true}else i&&(i.has="miss");return false}peek(e,t={}){let{allowStale:n=this.allowStale}=t,i=r(this,U).get(e);if(i===void 0||!n&&r(this,q).call(this,i))return;let a=r(this,T)[i];return f(this,c,x).call(this,a)?a.__staleWhileFetching:a}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:p=this.noDisposeOnSet,size:h=0,sizeCalculation:b=this.sizeCalculation,noUpdateTTL:u=this.noUpdateTTL,noDeleteOnFetchRejection:g=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:M=this.allowStaleOnFetchRejection,ignoreFetchAbort:N=this.ignoreFetchAbort,allowStaleOnFetchAbort:P=this.allowStaleOnFetchAbort,context:w,forceRefresh:_=false,status:l,signal:d}=t;if(!r(this,ye))return l&&(l.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:l});let C={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:o,noDisposeOnSet:p,size:h,sizeCalculation:b,noUpdateTTL:u,noDeleteOnFetchRejection:g,allowStaleOnFetchRejection:M,allowStaleOnFetchAbort:P,ignoreFetchAbort:N,status:l,signal:d},E=r(this,U).get(e);if(E===void 0){l&&(l.fetch="miss");let R=f(this,c,Ve).call(this,e,E,C,w);return R.__returned=R}else {let R=r(this,T)[E];if(f(this,c,x).call(this,R)){let J=n&&R.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",J&&(l.returnedStale=true)),J?R.__staleWhileFetching:R.__returned=R}let D=r(this,q).call(this,E);if(!_&&!D)return l&&(l.fetch="hit"),f(this,c,xe).call(this,E),i&&r(this,me).call(this,E),l&&r(this,pe).call(this,l,E),R;let se=f(this,c,Ve).call(this,e,E,C,w),G=se.__staleWhileFetching!==void 0&&n;return l&&(l.fetch=D?"stale":"refresh",G&&D&&(l.returnedStale=true)),G?se.__staleWhileFetching:se.__returned=se}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw new Error("fetch() returned undefined");return n}memo(e,t={}){let n=r(this,Ee);if(!n)throw new Error("no memoMethod provided to constructor");let{context:i,forceRefresh:a,...o}=t,p=this.get(e,o);if(!a&&p!==void 0)return p;let h=n(e,p,{options:o,context:i});return this.set(e,h,o),h}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:o}=t,p=r(this,U).get(e);if(p!==void 0){let h=r(this,T)[p],b=f(this,c,x).call(this,h);return o&&r(this,pe).call(this,o,p),r(this,q).call(this,p)?(o&&(o.get="stale"),b?(o&&n&&h.__staleWhileFetching!==void 0&&(o.returnedStale=true),n?h.__staleWhileFetching:void 0):(a||f(this,c,be).call(this,e,"expire"),o&&n&&(o.returnedStale=true),n?h:void 0)):(o&&(o.get="hit"),b?h.__staleWhileFetching:(f(this,c,xe).call(this,p),i&&r(this,me).call(this,p),h))}else o&&(o.get="miss");}delete(e){return f(this,c,be).call(this,e,"delete")}clear(){return f(this,c,Je).call(this,"delete")}},X=new WeakMap,B=new WeakMap,Q=new WeakMap,Se=new WeakMap,Z=new WeakMap,_e=new WeakMap,Ee=new WeakMap,ee=new WeakMap,Y=new WeakMap,te=new WeakMap,U=new WeakMap,A=new WeakMap,T=new WeakMap,K=new WeakMap,j=new WeakMap,H=new WeakMap,F=new WeakMap,re=new WeakMap,V=new WeakMap,ne=new WeakMap,ie=new WeakMap,k=new WeakMap,$=new WeakMap,ae=new WeakMap,ye=new WeakMap,W=new WeakMap,Ce=new WeakMap,c=new WeakSet,$e=function(){let e=new Ye(r(this,X)),t=new Ye(r(this,X));S(this,k,e),S(this,ie,t);let n=this.ttlAutopurge?new Array(r(this,X)):void 0;S(this,$,n),S(this,Ae,(p,h,b=r(this,ee).now())=>{t[p]=h!==0?b:0,e[p]=h,i(p,h);}),S(this,me,p=>{t[p]=e[p]!==0?r(this,ee).now():0,i(p,e[p]);});let i=this.ttlAutopurge?(p,h)=>{if(n?.[p]&&(clearTimeout(n[p]),n[p]=void 0),h&&h!==0&&n){let b=setTimeout(()=>{r(this,q).call(this,p)&&f(this,c,be).call(this,r(this,A)[p],"expire");},h+1);b.unref&&b.unref(),n[p]=b;}}:()=>{};S(this,pe,(p,h)=>{if(e[h]){let b=e[h],u=t[h];if(!b||!u)return;p.ttl=b,p.start=u,p.now=a||o();let g=p.now-u;p.remainingTTL=b-g;}});let a=0,o=()=>{let p=r(this,ee).now();if(this.ttlResolution>0){a=p;let h=setTimeout(()=>a=0,this.ttlResolution);h.unref&&h.unref();}return p};this.getRemainingTTL=p=>{let h=r(this,U).get(p);if(h===void 0)return 0;let b=e[h],u=t[h];if(!b||!u)return 1/0;let g=(a||o())-u;return b-g},S(this,q,p=>{let h=t[p],b=e[p];return !!b&&!!h&&(a||o())-h>b});},me=new WeakMap,pe=new WeakMap,Ae=new WeakMap,q=new WeakMap,ot=function(){let e=new Ye(r(this,X));S(this,te,0),S(this,ne,e),S(this,ge,t=>{S(this,te,r(this,te)-e[t]),e[t]=0;}),S(this,Me,(t,n,i,a)=>{if(f(this,c,x).call(this,n))return 0;if(!ue(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!ue(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),S(this,Ie,(t,n,i)=>{if(e[t]=n,r(this,B)){let a=r(this,B)-e[t];for(;r(this,te)>a;)f(this,c,Fe).call(this,true);}S(this,te,r(this,te)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=r(this,te));});},ge=new WeakMap,Ie=new WeakMap,Me=new WeakMap,de=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,F);!(!f(this,c,qe).call(this,t)||((e||!r(this,q).call(this,t))&&(yield t),t===r(this,H)));)t=r(this,j)[t];},fe=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,H);!(!f(this,c,qe).call(this,t)||((e||!r(this,q).call(this,t))&&(yield t),t===r(this,F)));)t=r(this,K)[t];},qe=function(e){return e!==void 0&&r(this,U).get(r(this,A)[e])===e},Fe=function(e){var a;let t=r(this,H),n=r(this,A)[t],i=r(this,T)[t];return r(this,ye)&&f(this,c,x).call(this,i)?i.__abortController.abort(new Error("evicted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((a=r(this,Q))==null||a.call(this,i,n,"evict")),r(this,W)&&r(this,V)?.push([i,n,"evict"])),r(this,ge).call(this,t),r(this,$)?.[t]&&(clearTimeout(r(this,$)[t]),r(this,$)[t]=void 0),e&&(r(this,A)[t]=void 0,r(this,T)[t]=void 0,r(this,re).push(t)),r(this,Y)===1?(S(this,H,S(this,F,0)),r(this,re).length=0):S(this,H,r(this,K)[t]),r(this,U).delete(n),Ue(this,Y)._--,t},Ve=function(e,t,n,i){let a=t===void 0?void 0:r(this,T)[t];if(f(this,c,x).call(this,a))return a;let o=new Ge,{signal:p}=n;p?.addEventListener("abort",()=>o.abort(p.reason),{signal:o.signal});let h={signal:o.signal,options:n,context:i},b=(w,_=false)=>{let{aborted:l}=o.signal,d=n.ignoreFetchAbort&&w!==void 0,C=n.ignoreFetchAbort||!!(n.allowStaleOnFetchAbort&&w!==void 0);if(n.status&&(l&&!_?(n.status.fetchAborted=true,n.status.fetchError=o.signal.reason,d&&(n.status.fetchAbortIgnored=true)):n.status.fetchResolved=true),l&&!d&&!_)return g(o.signal.reason,C);let E=N,R=r(this,T)[t];return (R===N||d&&_&&R===void 0)&&(w===void 0?E.__staleWhileFetching!==void 0?r(this,T)[t]=E.__staleWhileFetching:f(this,c,be).call(this,e,"fetch"):(n.status&&(n.status.fetchUpdated=true),this.set(e,w,h.options))),w},u=w=>(n.status&&(n.status.fetchRejected=true,n.status.fetchError=w),g(w,false)),g=(w,_)=>{let{aborted:l}=o.signal,d=l&&n.allowStaleOnFetchAbort,C=d||n.allowStaleOnFetchRejection,E=C||n.noDeleteOnFetchRejection,R=N;if(r(this,T)[t]===N&&(!E||!_&&R.__staleWhileFetching===void 0?f(this,c,be).call(this,e,"fetch"):d||(r(this,T)[t]=R.__staleWhileFetching)),C)return n.status&&R.__staleWhileFetching!==void 0&&(n.status.returnedStale=true),R.__staleWhileFetching;if(R.__returned===R)throw w},M=(w,_)=>{var d;let l=(d=r(this,_e))==null?void 0:d.call(this,e,a,h);l&&l instanceof Promise&&l.then(C=>w(C===void 0?void 0:C),_),o.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(w(void 0),n.allowStaleOnFetchAbort&&(w=C=>b(C,true)));});};n.status&&(n.status.fetchDispatched=true);let N=new Promise(M).then(b,u),P=Object.assign(N,{__abortController:o,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,P,{...h.options,status:void 0}),t=r(this,U).get(e)):r(this,T)[t]=P,P},x=function(e){if(!r(this,ye))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Ge},Xe=function(e,t){r(this,j)[t]=e,r(this,K)[e]=t;},xe=function(e){e!==r(this,F)&&(e===r(this,H)?S(this,H,r(this,K)[e]):f(this,c,Xe).call(this,r(this,j)[e],r(this,K)[e]),f(this,c,Xe).call(this,r(this,F),e),S(this,F,e));},be=function(e,t){var i,a;let n=false;if(r(this,Y)!==0){let o=r(this,U).get(e);if(o!==void 0)if(r(this,$)?.[o]&&(clearTimeout(r(this,$)?.[o]),r(this,$)[o]=void 0),n=true,r(this,Y)===1)f(this,c,Je).call(this,t);else {r(this,ge).call(this,o);let p=r(this,T)[o];if(f(this,c,x).call(this,p)?p.__abortController.abort(new Error("deleted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((i=r(this,Q))==null||i.call(this,p,e,t)),r(this,W)&&r(this,V)?.push([p,e,t])),r(this,U).delete(e),r(this,A)[o]=void 0,r(this,T)[o]=void 0,o===r(this,F))S(this,F,r(this,j)[o]);else if(o===r(this,H))S(this,H,r(this,K)[o]);else {let h=r(this,j)[o];r(this,K)[h]=r(this,K)[o];let b=r(this,K)[o];r(this,j)[b]=r(this,j)[o];}Ue(this,Y)._--,r(this,re).push(o);}}if(r(this,W)&&r(this,V)?.length){let o=r(this,V),p;for(;p=o?.shift();)(a=r(this,Z))==null||a.call(this,...p);}return n},Je=function(e){var t,n;for(let i of f(this,c,fe).call(this,{allowStale:true})){let a=r(this,T)[i];if(f(this,c,x).call(this,a))a.__abortController.abort(new Error("deleted"));else {let o=r(this,A)[i];r(this,ae)&&((t=r(this,Q))==null||t.call(this,a,o,e)),r(this,W)&&r(this,V)?.push([a,o,e]);}}if(r(this,U).clear(),r(this,T).fill(void 0),r(this,A).fill(void 0),r(this,k)&&r(this,ie)){r(this,k).fill(0),r(this,ie).fill(0);for(let i of r(this,$)??[])i!==void 0&&clearTimeout(i);r(this,$)?.fill(void 0);}if(r(this,ne)&&r(this,ne).fill(0),S(this,H,0),S(this,F,0),r(this,re).length=0,S(this,te,0),S(this,Y,0),r(this,W)&&r(this,V)){let i=r(this,V),a;for(;a=i?.shift();)(n=r(this,Z))==null||n.call(this,...a);}},Re);var Ne=class{cache;map=new Map;constructor(e){this.cache=new st({max:e.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){this.cache.clear(),this.map.clear();}delete(e){let t=this.map.delete(e);return t&&this.cache.delete(e),t}get forEach(){return this.map.forEach}get(e){let t=this.cache.get(e);return t||this.map.get(e)}has(e){return this.map.has(e)}set(e,t){return this.map.set(e,t),this.cache.set(e,t),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var L;(i=>(i.log=(a,...o)=>console.log(`[Pixi\u2019VN] ${a}`,...o),i.warn=(a,...o)=>console.warn(`[Pixi\u2019VN] ${a}`,...o),i.error=(a,...o)=>console.error(`[Pixi\u2019VN] ${a}`,...o),i.info=(a,...o)=>console.info(`[Pixi\u2019VN] ${a}`,...o)))(L||={});var Oe=new Ne({cacheSize:10}),lt;(o=>{function s(p){let h=Oe.get(p);if(!h){L.error(`Label "${p}" not found`);return}return h}o.get=s;function e(...p){for(let h of p)Oe.set(h.id,h);}o.add=e;function t(){return Array.from(Oe.values())}o.values=t;function n(p){return Oe.has(p)}o.has=n;function i(){return Array.from(Oe.keys())}o.keys=i;function a(){Oe.clear();}o.clear=a;})(lt||={});var le=lt;function he(s){try{if(typeof s>"u")return s;let e=JSON.stringify(s);return JSON.parse(e)}catch(e){throw L.error("Error creating exportable element",s,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var y=class s{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return core.GameUnifier.getVariable(O,I.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){core.GameUnifier.setVariable(O,I.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=s.currentLabelStepIndex;if(t===null)return L.error("currentLabelStepIndex is null"),null;let n=`${t}${e}`,i=s.currentLabelId,a=s._currentLabel;if(!i||t===null||!a)return L.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let o=a.getStepSha(t)||"error",p=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return p[i]||(p[i]={}),(!p[i][n]||p[i][n].stepSha1!==o)&&(p[i][n]={stepSha1:o}),p[i][n]}static setCurrentStepTimesCounterData(e="",t){let n=s.currentLabelStepIndex,i=n+e,a=s.currentLabelId;if(!a||n===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let o=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};o[a]||(o[a]={}),o[a][i]=t,core.GameUnifier.setVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY,o);}static getCurrentStepTimesCounter(e=""){let t=s._stepCounter,n=s.getCurrentStepTimesCounterData(e);if(!n)return L.error("getCurrentStepTimesCounter obj is null"),0;let i=n.stepCounters||[];return i.find(o=>o===t)||(i.push(t),n.stepCounters=i,s.setCurrentStepTimesCounterData(e,n)),i.length}static getRandomNumber(e,t,n={}){let i=n.nestedId||"";if(n.onceOnly||false){let o=s.getCurrentStepTimesCounterData(i);if(!o)return;let p=o.usedRandomNumbers||{},h=Array.from({length:t-e+1},(g,M)=>M+e).filter(g=>!p[`${e}-${t}`]?.includes(g));if(h.length===0)return;let b=Math.floor(Math.random()*h.length),u=h[b];return p[`${e}-${t}`]||(p[`${e}-${t}`]=[]),p[`${e}-${t}`].push(u),o.usedRandomNumbers=p,s.setCurrentStepTimesCounterData(i,o),u}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=s.currentLabelStepIndex,n=t+e,i=s.currentLabelId;if(!i||t===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let a=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[i]||(a[i]={}),a[i][n]={stepCounters:[],stepSha1:""},core.GameUnifier.setVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return core.GameUnifier.getVariable(O,I.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){core.GameUnifier.setVariable(O,I.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){s._stepCounter++;}static _openedLabels=[];static get openedLabels(){return he(s._openedLabels)}static set openedLabels(e){s._openedLabels=he(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return he(s._originalOpenedLabels)}static set originalOpenedLabels(e){s._originalOpenedLabels=he(e);}static get _currentLabel(){if(s.currentLabelId)return le.get(s.currentLabelId)}static get currentLabelId(){if(s._openedLabels.length>0)return s._openedLabels[s._openedLabels.length-1].label}static get currentLabelStepIndex(){return s._openedLabels.length>0?s._openedLabels[s._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;(!i||i<t)&&(n[e]={biggestStep:t,openCount:a},s.allOpenedLabels=n);}static addChoicesMade(e,t,n,i){let a=s.allChoicesMade,o=a.findIndex(p=>p.labelId===e&&p.stepIndex===t&&p.choiceIndex===i&&p.stepSha1===n);o<0?a.push({labelId:e,stepIndex:t,choiceIndex:i,stepSha1:n,madeTimes:1}):a[o].madeTimes++,s.allChoicesMade=a;}static pushNewLabel(e){if(!le.get(e))throw new core.PixiError("unregistered_element",`Label ${e} not found`);s._openedLabels.push({label:e,currentStepIndex:0});let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;n[e]={biggestStep:i,openCount:a+1},s.allOpenedLabels=n;}static increaseCurrentStepIndex(){if(s._openedLabels.length>0){let e=s._openedLabels[s._openedLabels.length-1];s._openedLabels[s._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){s._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let n=[];return s.onLoadingLabel&&e===0&&n.push(s.onLoadingLabel(e,t)),s._onStepStart&&n.push(s._onStepStart(e,t)),await Promise.all(n)}}static onLoadingLabel;static onStepEnd;static onLabelStarting};var De=class{get currentStepTimesCounter(){return y.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){y.resetCurrentStepTimesCounter();}getRandomNumber(e,t,n={}){return y.getRandomNumber(e,t,n)}get stepCounter(){return y._stepCounter}get openedLabels(){return y.openedLabels}get currentLabel(){return y._currentLabel}addStepHistory(e,t={}){let{choiceMade:n,ignoreSameStep:i}=t,a,o,p,h=core.GameUnifier.getVariable(O,I.LAST_STEP_GLUED)===this.stepCounter;core.GameUnifier.getVariable(O,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY)),core.GameUnifier.getVariable(O,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(o=core.GameUnifier.getVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY)),core.GameUnifier.getVariable(O,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(p=core.GameUnifier.getVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY));let b=y.openedLabels,u={currentLabel:y.currentLabelId,dialogue:a,choices:o,stepSha1:e,index:this.stepCounter,labelStepIndex:y.currentLabelStepIndex,choiceIndexMade:n,inputValue:p,alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:h,openedLabels:b};y.originalOpenedLabels=b,core.GameUnifier.addHistoryItem(u,{ignoreSameStep:i}),y.lastHistoryStep=u,y.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=y.currentLabelStepIndex,n=this.currentLabel;if(!(t===null||!n))return y.allChoicesMade.filter(i=>i.labelId===n.id&&i.stepIndex===t&&i.stepSha1===e).map(i=>i.choiceIndex)}closeCurrentLabel(){if(!y.currentLabelId){L.warn("No label to close");return}if(!this.currentLabel){L.error("currentLabel not found");return}let e=y.openedLabels;e.pop(),y.openedLabels=e,core.GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;y.openedLabels.length>0;)this.closeCurrentLabel(),core.GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let i=y.allOpenedLabels[t]?.biggestStep||0;if(i){let a=le.get(t);if(a)return a.stepCount<=i}return false}get alreadyCurrentStepMadeChoicesObj(){let e=y.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let n=t.getStepSha(e);return n||(L.warn("stepSha not found, setting to ERROR"),n="error"),y.allChoicesMade.filter(i=>i.labelId===t?.id&&i.stepIndex===e&&i.stepSha1===n)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=y.currentLabelId;if(e){let t=y.allOpenedLabels[e]?.openCount||0;if(y.currentLabelStepIndex&&t>=y.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return y.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e){let t=e?.showWarn||false,n=this.choices;return n&&n.length>0?(t&&L.warn("The player must make a choice"),false):this.isRequiredInput?(t&&L.warn("The player must enter a value"),false):true}get canContinue(){return core.GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let n=[];return e.onStepStart&&n.push(e.onStepStart(t,e)),y.onStepStart&&n.push(y.onStepStart(t,e)),await Promise.all(n)}async onStepEnd(e,t){let n=[];return e.onStepEnd&&n.push(e.onStepEnd(t,e)),y.onStepEnd&&n.push(y.onStepEnd(t,e)),await Promise.all(n)}async continue(e,t={}){let{runNow:n=false,steps:i=1}=t;if(!Number.isFinite(i)){L.warn(`[continue] The parameter steps must be a valid finite number, received: ${i}`);return}if(i<=0){L.warn(`[continue] The parameter steps must be greater than 0, received: ${i}`);return}if(!n&&!this.getCanContinue({showWarn:true}))return;if(!n&&core.GameUnifier.runningStepsCount!==0){core.GameUnifier.increaseContinueRequest(i);return}i>1&&core.GameUnifier.increaseContinueRequest(i-1),core.GameUnifier.runningStepsCount++;let a;try{core.GameUnifier.runningStepsCount===1&&await core.GameUnifier.onPreContinue(),y.increaseCurrentStepIndex(),a=await this.runCurrentStep(e,t);}catch(o){throw L.error("Error continuing",o),o}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||a}async afterRunCurrentStep(e){if(core.GameUnifier.runningStepsCount===0&&core.GameUnifier.continueRequestsCount!==0)return await core.GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(core.GameUnifier.onEnd)return await core.GameUnifier.onEnd(e,{labelId:"end"});L.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e,t={}){let{choiceMade:n}=t;if(y.currentLabelId){let i=y.currentLabelStepIndex;if(i===null){L.error("currentLabelStepIndex is null");return}let a=y._currentLabel;if(!a){L.error("currentLabel not found");return}if(a.stepCount>i){try{await this.onStepStart(a,i);}catch(u){L.error("Error running onStepStart",u),this.onStepError&&await this.onStepError(u,e);return}let o=a.getStepById(i);if(!o){L.error("step not found");return}let p=a.getStepSha(i);p||(L.warn("stepSha not found, setting to ERROR"),p="error");let h,b;try{h=await o(e,{labelId:a.id});}catch(u){L.error("Error running step",u),b=u;}try{let u=this.choices;if(u?.length===1&&u[0].autoSelect){let g=u[0];h=await this.selectChoice(g,e);}}catch(u){L.error("Error auto-selecting choice",u),b||(b=u);}try{let u=y.lastHistoryStep;n!==void 0&&u&&(p=u.stepSha1,p||(L.warn("stepSha not found, setting to ERROR"),p="error"),y.addChoicesMade(u.currentLabel||"error",typeof u.labelStepIndex=="number"?u.labelStepIndex:-1,u.stepSha1||"error",n),y.choiceMadeTemp=n);}catch(u){L.warn("Error adding choice made to history",u);}try{core.GameUnifier.runningStepsCount===1&&(y.addLabelHistory(a.id,i),this.addStepHistory(p,{...t,choiceMade:y.choiceMadeTemp}),y.choiceMadeTemp=void 0);}catch(u){L.warn("Error adding step to history",u);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,y.currentLabelStepIndex||0);}catch(u){L.warn("Error running onStepEnd",u);}return b&&this.onStepError&&await this.onStepError(b,e),h}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e,t);if(this.openedLabels.length===1){y.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;L.error("currentLabelId not found");}}async startLabel(e,t,n){let i=async()=>{let{choiceMade:a,closeCurrentLabel:o,type:p}=n;o&&this.openedLabels.length>0&&this.closeCurrentLabel(),core.GameUnifier.runningStepsCount++;let h;try{let b=le.get(e);if(!b)throw new core.PixiError("unregistered_element",`Label ${e} not found`);y.pushNewLabel(b.id),h=await this.runCurrentStep(t,{choiceMade:a});}catch(b){throw L.error(`Error ${p} label`,b),b}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||h};return y.onLabelStarting?await y.onLabelStarting(e,t,n,i):await i()}async call(e,t,n){let{choiceMade:i}=n||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:i,type:"calling"})}async jump(e,t,n){if(this.stepCounter===0)return await this.call(e,t,n);let{choiceMade:i}=n||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:i,closeCurrentLabel:true,type:"jumping to"})}async selectChoice(e,t){this.choices=void 0;let n=e.type;switch(n){case "call":return await this.call(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "jump":return await this.jump(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "close":return await this.closeChoiceMenu(e,{...e.props,...t});default:throw L.error(`Type ${n} not found`),new core.PixiError("invalid_usage",`Type ${n} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw L.error("For closeChoiceMenu, the type must be close"),new core.PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let n;return typeof e.choiceIndex=="number"&&(n=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:n})}get onStepError(){return async(e,t)=>{try{await core.GameUnifier.runOnError(e,t);}catch(n){L.error("Error in onError handler",n);}}}get dialogue(){let e=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?core.GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){core.GameUnifier.setVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let n=[];Array.isArray(t.text)?n=[...t.text]:n=[t.text],Array.isArray(e.text)?n=[...n,...e.text]:n=[...n,e.text],e.text=n,e.character=e.character||t.character;}core.GameUnifier.setVariable(O,I.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{core.GameUnifier.setVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY,he({...e,character:typeof e.character=="string"?e.character:e.character?.id})),core.GameUnifier.setVariable(O,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("DialogueInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=core.GameUnifier.getVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],n=e.map((a,o)=>({...a,choiceIndex:o})),i=this.alreadyCurrentStepMadeChoices;if(n=n.filter((a,o)=>a.oneTime&&i?.includes(o)?false:a.onlyHaveNoChoice?(t.push(a),false):true),n.length>0)return n;if(t.length>0)return [t[0]]}}set choices(e){if(!e||e.length===0){core.GameUnifier.setVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{core.GameUnifier.setVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,he(e)),core.GameUnifier.setVariable(O,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("ChoiceInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return core.GameUnifier.getFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){core.GameUnifier.setFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),core.GameUnifier.setVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY,e),core.GameUnifier.setVariable(O,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,core.GameUnifier.setVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?core.GameUnifier.setVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY,t):core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY),core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){y.openedLabels=[],y._stepCounter=0;}export(){return {openedLabels:he(y.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async n=>{let i=[],a=le.get(n.label);return a&&(a.onLoadingLabel&&i.push(a.onLoadingLabel(e,a)),y.onLoadingLabel&&i.push(y.onLoadingLabel(e,a))),await Promise.all(i)});return await Promise.all(t)}async restore(e,t){this.clear();try{y.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(y.openedLabels=e.openedLabels,y.originalOpenedLabels=y.openedLabels):L.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?y._stepCounter=e.stepCounter:L.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(y.currentLabelStepIndex||0);}catch(n){L.error("Error running onLoadingLabel",n);}}catch(n){L.error("Error importing data",n);}}};function xt(s,e,t,n){let i=typeof e=="string"?e:e.id;return {...n,label:i,props:t,text:s,type:n?.type||"call"}}var pt="close";function At(s,e){return {...e,type:pt,text:s}}var ft=Et(dt());var ve=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var we=class extends ve{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,n){super(e,n),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e){let t=this.steps;if(e<0||e>=t.length)return typeof this._steps!="function"&&L.warn("stepSha not found, setting to ERROR"),"error";try{return (0,ft.default)(t[e].toString().toLocaleLowerCase()).toString()}catch(n){return L.warn("stepSha not found, setting to ERROR",n),"error"}}};function bt(s,e,t){let n=new we(s,e,t);return le.add(n),n}var Er=new De;
2
+ exports.Label=we;exports.LabelAbstract=ve;exports.NarrationManagerStatic=y;exports.RegisteredLabels=le;exports.narration=Er;exports.newChoiceOption=xt;exports.newCloseChoiceOption=At;exports.newLabel=bt;
@@ -2,8 +2,8 @@ import { S as StorageElementType, a as StorageObjectType } from './StorageElemen
2
2
  import { L as LabelIdType, D as DialogueInterface, H as HistoryStep } from './HistoryStep-G9dUn0Lf.cjs';
3
3
  export { P as PixivnLabelIds } from './HistoryStep-G9dUn0Lf.cjs';
4
4
  import { ChoiceInterface as ChoiceInterface$1 } from '@drincs/pixi-vn';
5
- import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-BMsYentw.cjs';
6
- export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-BMsYentw.cjs';
5
+ import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-DVMD78W7.cjs';
6
+ export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-DVMD78W7.cjs';
7
7
  import { S as StepLabelPropsType, a as StepLabelResultType, b as StepLabelType } from './StepLabelType-CN97wZzm.cjs';
8
8
  import { O as OpenedLabel } from './OpenedLabel-BxfL31aQ.cjs';
9
9
  import { LabelProps as LabelProps$1 } from '@drincs/pixi-vn/canvas';
@@ -714,6 +714,21 @@ declare class NarrationManagerStatic {
714
714
  static get onStepStart(): ((stepId: number, label: LabelAbstract<any>) => Promise<void[]>) | undefined;
715
715
  static onLoadingLabel?: (stepId: number, label: LabelAbstract<any>) => void | Promise<void>;
716
716
  static onStepEnd?: (stepId: number, label: LabelAbstract<any>) => void | Promise<void>;
717
+ /**
718
+ * Is a function that will be executed every time a label is about to be started, either via
719
+ * `call` or `jump` (this includes labels started through a choice of type `"call"` or `"jump"`).
720
+ *
721
+ * By default (when this is not set), the label is started immediately, exactly like before this
722
+ * hook existed. If you set it, you take control: call `defaultStart()` yourself whenever you want
723
+ * the label to actually run (right away, or later, e.g. from a subsequent `next()`-like action in
724
+ * your template). Until `defaultStart()` is called, nothing about the label happens: it is not
725
+ * added to the history and no step of it runs.
726
+ */
727
+ static onLabelStarting?: (labelId: LabelIdType, props: StepLabelPropsType, options: {
728
+ choiceMade?: number;
729
+ closeCurrentLabel?: boolean;
730
+ type: string;
731
+ }, defaultStart: () => Promise<StepLabelResultType>) => StepLabelResultType | Promise<StepLabelResultType>;
717
732
  }
718
733
 
719
734
  type InputInfo = {
@@ -2,8 +2,8 @@ import { S as StorageElementType, a as StorageObjectType } from './StorageElemen
2
2
  import { L as LabelIdType, D as DialogueInterface, H as HistoryStep } from './HistoryStep-G9dUn0Lf.js';
3
3
  export { P as PixivnLabelIds } from './HistoryStep-G9dUn0Lf.js';
4
4
  import { ChoiceInterface as ChoiceInterface$1 } from '@drincs/pixi-vn';
5
- import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-DQ-pnuPU.js';
6
- export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-DQ-pnuPU.js';
5
+ import { L as LabelRunModeType, C as CloseType } from './HistoryChoiceMenuOption-B8RfQz5H.js';
6
+ export { H as HistoryChoiceMenuOption, N as NarrationHistory } from './HistoryChoiceMenuOption-B8RfQz5H.js';
7
7
  import { S as StepLabelPropsType, a as StepLabelResultType, b as StepLabelType } from './StepLabelType-CN97wZzm.js';
8
8
  import { O as OpenedLabel } from './OpenedLabel-DLfFuZgk.js';
9
9
  import { LabelProps as LabelProps$1 } from '@drincs/pixi-vn/canvas';
@@ -714,6 +714,21 @@ declare class NarrationManagerStatic {
714
714
  static get onStepStart(): ((stepId: number, label: LabelAbstract<any>) => Promise<void[]>) | undefined;
715
715
  static onLoadingLabel?: (stepId: number, label: LabelAbstract<any>) => void | Promise<void>;
716
716
  static onStepEnd?: (stepId: number, label: LabelAbstract<any>) => void | Promise<void>;
717
+ /**
718
+ * Is a function that will be executed every time a label is about to be started, either via
719
+ * `call` or `jump` (this includes labels started through a choice of type `"call"` or `"jump"`).
720
+ *
721
+ * By default (when this is not set), the label is started immediately, exactly like before this
722
+ * hook existed. If you set it, you take control: call `defaultStart()` yourself whenever you want
723
+ * the label to actually run (right away, or later, e.g. from a subsequent `next()`-like action in
724
+ * your template). Until `defaultStart()` is called, nothing about the label happens: it is not
725
+ * added to the history and no step of it runs.
726
+ */
727
+ static onLabelStarting?: (labelId: LabelIdType, props: StepLabelPropsType, options: {
728
+ choiceMade?: number;
729
+ closeCurrentLabel?: boolean;
730
+ type: string;
731
+ }, defaultStart: () => Promise<StepLabelResultType>) => StepLabelResultType | Promise<StepLabelResultType>;
717
732
  }
718
733
 
719
734
  type InputInfo = {
@@ -1,2 +1,2 @@
1
- import {a}from'./chunk-6GLWL3NH.mjs';import {l,n}from'./chunk-IWAXXFXE.mjs';import {d,c,e,f}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var h=new d({cacheSize:10}),R;(d=>{function i(l){let f=h.get(l);if(!f){e.error(`Label "${l}" not found`);return}return f}d.get=i;function e$1(...l){for(let f of l)h.set(f.id,f);}d.add=e$1;function t(){return Array.from(h.values())}d.values=t;function r(l){return h.has(l)}d.has=r;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(R||={});var L=R;var o=class i{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return GameUnifier.getVariable(l,n.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(l,n.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e$1=""){let t=i.currentLabelStepIndex;if(t===null)return e.error("currentLabelStepIndex is null"),null;let r=`${t}${e$1}`,n$1=i.currentLabelId,a=i._currentLabel;if(!n$1||t===null||!a)return e.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let d=a.getStepSha(t)||"error",l$1=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return l$1[n$1]||(l$1[n$1]={}),(!l$1[n$1][r]||l$1[n$1][r].stepSha1!==d)&&(l$1[n$1][r]={stepSha1:d}),l$1[n$1][r]}static setCurrentStepTimesCounterData(e$1="",t){let r=i.currentLabelStepIndex,n$1=r+e$1,a=i.currentLabelId;if(!a||r===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let d=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};d[a]||(d[a]={}),d[a][n$1]=t,GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,d);}static getCurrentStepTimesCounter(e$1=""){let t=i._stepCounter,r=i.getCurrentStepTimesCounterData(e$1);if(!r)return e.error("getCurrentStepTimesCounter obj is null"),0;let n=r.stepCounters||[];return n.find(d=>d===t)||(n.push(t),r.stepCounters=n,i.setCurrentStepTimesCounterData(e$1,r)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let d=i.getCurrentStepTimesCounterData(n);if(!d)return;let l=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!l[`${e}-${t}`]?.includes(E));if(f.length===0)return;let S=Math.floor(Math.random()*f.length),b=f[S];return l[`${e}-${t}`]||(l[`${e}-${t}`]=[]),l[`${e}-${t}`].push(b),d.usedRandomNumbers=l,i.setCurrentStepTimesCounterData(n,d),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e$1=""){let t=i.currentLabelStepIndex,r=t+e$1,n$1=i.currentLabelId;if(!n$1||t===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n$1]||(a[n$1]={}),a[n$1][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(l,n.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(l,n.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){i._stepCounter++;}static _openedLabels=[];static get openedLabels(){return f(i._openedLabels)}static set openedLabels(e){i._openedLabels=f(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return f(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=f(e);}static get _currentLabel(){if(i.currentLabelId)return L.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,d=a.findIndex(l=>l.labelId===e&&l.stepIndex===t&&l.choiceIndex===n&&l.stepSha1===r);d<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[d].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!L.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}static onLoadingLabel;static onStepEnd};var C=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n$1}=t,a,d,l$1,f=GameUnifier.getVariable(l,n.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(d=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(l$1=GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY));let S=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:l$1,alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:f,openedLabels:S};o.originalOpenedLabels=S,GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=o.currentLabelStepIndex,r=this.currentLabel;if(!(t===null||!r))return o.allChoicesMade.filter(n=>n.labelId===r.id&&n.stepIndex===t&&n.stepSha1===e).map(n=>n.choiceIndex)}closeCurrentLabel(){if(!o.currentLabelId){e.warn("No label to close");return}if(!this.currentLabel){e.error("currentLabel not found");return}let e$1=o.openedLabels;e$1.pop(),o.openedLabels=e$1,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=L.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e$1=o.currentLabelStepIndex,t=this.currentLabel;if(e$1===null||!t)return;let r=t.getStepSha(e$1);return r||(e.warn("stepSha not found, setting to ERROR"),r="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e$1&&n.stepSha1===r)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e$1){let t=e$1?.showWarn||false,r=this.choices;return r&&r.length>0?(t&&e.warn("The player must make a choice"),false):this.isRequiredInput?(t&&e.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e$1,t={}){let{runNow:r=false,steps:n=1}=t;if(!Number.isFinite(n)){e.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){e.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r&&!this.getCanContinue({showWarn:true}))return;if(!r&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e$1,t);}catch(d){throw e.error("Error continuing",d),d}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e$1)||a}async afterRunCurrentStep(e$1){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e$1,{labelId:"end"});e.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e$1,t={}){let{choiceMade:r}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){e.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){e.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){e.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e$1);return}let d=a.getStepById(n);if(!d){e.error("step not found");return}let l=a.getStepSha(n);l||(e.warn("stepSha not found, setting to ERROR"),l="error");let f,S;try{f=await d(e$1,{labelId:a.id});}catch(b){e.error("Error running step",b),S=b;}try{let b=this.choices;if(b?.length===1&&b[0].autoSelect){let E=b[0];f=await this.selectChoice(E,e$1);}}catch(b){e.error("Error auto-selecting choice",b),S||(S=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(l=b.stepSha1,l||(e.warn("stepSha not found, setting to ERROR"),l="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r),o.choiceMadeTemp=r);}catch(b){e.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),this.addStepHistory(l,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){e.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){e.warn("Error running onStepEnd",b);}return S&&this.onStepError&&await this.onStepError(S,e$1),f}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e$1,t);if(this.openedLabels.length===1){o.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;e.error("currentLabelId not found");}}async call(e$1,t,r){let{choiceMade:n}=r||{},a;typeof e$1=="string"?a=e$1:a=e$1.id,GameUnifier.runningStepsCount++;let d;try{let l=L.get(a);if(!l)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(l.id),d=await this.runCurrentStep(t,{choiceMade:n});}catch(l){throw e.error("Error calling label",l),l}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||d}async jump(e$1,t,r){if(this.stepCounter===0)return await this.call(e$1,t,r);this.openedLabels.length>0&&this.closeCurrentLabel();let{choiceMade:n}=r||{},a;typeof e$1=="string"?a=e$1:a=e$1.id,GameUnifier.runningStepsCount++;let d;try{let l=L.get(a);if(!l)throw new PixiError("unregistered_element",`Label ${a} not found`);o.pushNewLabel(l.id),d=await this.runCurrentStep(t,{choiceMade:n});}catch(l){throw e.error("Error jumping to label",l),l}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||d}async selectChoice(e$1,t){this.choices=void 0;let r=e$1.type;switch(r){case "call":return await this.call(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "jump":return await this.jump(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "close":return await this.closeChoiceMenu(e$1,{...e$1.props,...t});default:throw e.error(`Type ${r} not found`),new PixiError("invalid_usage",`Type ${r} not found`)}}async closeChoiceMenu(e$1,t){if(e$1.type!=="close")throw e.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r;return typeof e$1.choiceIndex=="number"&&(r=e$1.choiceIndex),e$1.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r})}get onStepError(){return async(e$1,t)=>{try{await GameUnifier.runOnError(e$1,t);}catch(r){e.error("Error in onError handler",r);}}}get dialogue(){let e=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e$1){if(e$1===void 0){GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e$1=="string"||Array.isArray(e$1))&&(e$1={text:e$1}),this.dialogGlue){let t=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e$1.text)?r=[...r,...e$1.text]:r=[...r,e$1.text],e$1.text=r,e$1.character=e$1.character||t.character;}GameUnifier.setVariable(l,n.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,f({...e$1,character:typeof e$1.character=="string"?e$1.character:e$1.character?.id})),GameUnifier.setVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,d)=>({...a,choiceIndex:d})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,d)=>a.oneTime&&n?.includes(d)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choices(e$1){if(!e$1||e$1.length===0){GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,f(e$1)),GameUnifier.setVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return GameUnifier.getFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,GameUnifier.setVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:f(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=L.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e$1,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e$1,"openedLabels")?(o.openedLabels=e$1.openedLabels,o.originalOpenedLabels=o.openedLabels):e.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e$1,"stepCounter")?o._stepCounter=e$1.stepCounter:e.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r){e.error("Error running onLoadingLabel",r);}}catch(r){e.error("Error importing data",r);}}};function D(i,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:i,type:r?.type||"call"}}var O="close";function U(i,e){return {...e,type:O,text:i}}var M=c(a(),1);var g=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var I=class extends g{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,r){super(e,r),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e$1){let t=this.steps;if(e$1<0||e$1>=t.length)return typeof this._steps!="function"&&e.warn("stepSha not found, setting to ERROR"),"error";try{return (0,M.default)(t[e$1].toString().toLocaleLowerCase()).toString()}catch(r){return e.warn("stepSha not found, setting to ERROR",r),"error"}}};function x(i,e,t){let r=new I(i,e,t);return L.add(r),r}var fe=new C;
2
- export{I as Label,g as LabelAbstract,o as NarrationManagerStatic,L as RegisteredLabels,fe as narration,D as newChoiceOption,U as newCloseChoiceOption,x as newLabel};
1
+ import {a}from'./chunk-6GLWL3NH.mjs';import {l,n}from'./chunk-IWAXXFXE.mjs';import {d,c,e,f}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var h=new d({cacheSize:10}),R;(d=>{function i(c){let f=h.get(c);if(!f){e.error(`Label "${c}" not found`);return}return f}d.get=i;function e$1(...c){for(let f of c)h.set(f.id,f);}d.add=e$1;function t(){return Array.from(h.values())}d.values=t;function r(c){return h.has(c)}d.has=r;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(R||={});var S=R;var o=class i{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return GameUnifier.getVariable(l,n.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(l,n.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e$1=""){let t=i.currentLabelStepIndex;if(t===null)return e.error("currentLabelStepIndex is null"),null;let r=`${t}${e$1}`,n$1=i.currentLabelId,a=i._currentLabel;if(!n$1||t===null||!a)return e.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let d=a.getStepSha(t)||"error",c=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return c[n$1]||(c[n$1]={}),(!c[n$1][r]||c[n$1][r].stepSha1!==d)&&(c[n$1][r]={stepSha1:d}),c[n$1][r]}static setCurrentStepTimesCounterData(e$1="",t){let r=i.currentLabelStepIndex,n$1=r+e$1,a=i.currentLabelId;if(!a||r===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let d=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};d[a]||(d[a]={}),d[a][n$1]=t,GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,d);}static getCurrentStepTimesCounter(e$1=""){let t=i._stepCounter,r=i.getCurrentStepTimesCounterData(e$1);if(!r)return e.error("getCurrentStepTimesCounter obj is null"),0;let n=r.stepCounters||[];return n.find(d=>d===t)||(n.push(t),r.stepCounters=n,i.setCurrentStepTimesCounterData(e$1,r)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let d=i.getCurrentStepTimesCounterData(n);if(!d)return;let c=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!c[`${e}-${t}`]?.includes(E));if(f.length===0)return;let L=Math.floor(Math.random()*f.length),b=f[L];return c[`${e}-${t}`]||(c[`${e}-${t}`]=[]),c[`${e}-${t}`].push(b),d.usedRandomNumbers=c,i.setCurrentStepTimesCounterData(n,d),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e$1=""){let t=i.currentLabelStepIndex,r=t+e$1,n$1=i.currentLabelId;if(!n$1||t===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n$1]||(a[n$1]={}),a[n$1][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(l,n.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(l,n.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){i._stepCounter++;}static _openedLabels=[];static get openedLabels(){return f(i._openedLabels)}static set openedLabels(e){i._openedLabels=f(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return f(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=f(e);}static get _currentLabel(){if(i.currentLabelId)return S.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,d=a.findIndex(c=>c.labelId===e&&c.stepIndex===t&&c.choiceIndex===n&&c.stepSha1===r);d<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[d].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!S.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}static onLoadingLabel;static onStepEnd;static onLabelStarting};var C=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n$1}=t,a,d,c,f=GameUnifier.getVariable(l,n.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(d=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(c=GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY));let L=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:c,alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:f,openedLabels:L};o.originalOpenedLabels=L,GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=o.currentLabelStepIndex,r=this.currentLabel;if(!(t===null||!r))return o.allChoicesMade.filter(n=>n.labelId===r.id&&n.stepIndex===t&&n.stepSha1===e).map(n=>n.choiceIndex)}closeCurrentLabel(){if(!o.currentLabelId){e.warn("No label to close");return}if(!this.currentLabel){e.error("currentLabel not found");return}let e$1=o.openedLabels;e$1.pop(),o.openedLabels=e$1,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=S.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e$1=o.currentLabelStepIndex,t=this.currentLabel;if(e$1===null||!t)return;let r=t.getStepSha(e$1);return r||(e.warn("stepSha not found, setting to ERROR"),r="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e$1&&n.stepSha1===r)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e$1){let t=e$1?.showWarn||false,r=this.choices;return r&&r.length>0?(t&&e.warn("The player must make a choice"),false):this.isRequiredInput?(t&&e.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e$1,t={}){let{runNow:r=false,steps:n=1}=t;if(!Number.isFinite(n)){e.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){e.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r&&!this.getCanContinue({showWarn:true}))return;if(!r&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e$1,t);}catch(d){throw e.error("Error continuing",d),d}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e$1)||a}async afterRunCurrentStep(e$1){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e$1,{labelId:"end"});e.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e$1,t={}){let{choiceMade:r}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){e.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){e.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){e.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e$1);return}let d=a.getStepById(n);if(!d){e.error("step not found");return}let c=a.getStepSha(n);c||(e.warn("stepSha not found, setting to ERROR"),c="error");let f,L;try{f=await d(e$1,{labelId:a.id});}catch(b){e.error("Error running step",b),L=b;}try{let b=this.choices;if(b?.length===1&&b[0].autoSelect){let E=b[0];f=await this.selectChoice(E,e$1);}}catch(b){e.error("Error auto-selecting choice",b),L||(L=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(c=b.stepSha1,c||(e.warn("stepSha not found, setting to ERROR"),c="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r),o.choiceMadeTemp=r);}catch(b){e.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),this.addStepHistory(c,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){e.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){e.warn("Error running onStepEnd",b);}return L&&this.onStepError&&await this.onStepError(L,e$1),f}else {if(this.openedLabels.length>1)return this.closeCurrentLabel(),await this.continue(e$1,t);if(this.openedLabels.length===1){o.openedLabels=[];return}}}else {if(this.openedLabels.length===0)return;e.error("currentLabelId not found");}}async startLabel(e$1,t,r){let n=async()=>{let{choiceMade:a,closeCurrentLabel:d,type:c}=r;d&&this.openedLabels.length>0&&this.closeCurrentLabel(),GameUnifier.runningStepsCount++;let f;try{let L=S.get(e$1);if(!L)throw new PixiError("unregistered_element",`Label ${e$1} not found`);o.pushNewLabel(L.id),f=await this.runCurrentStep(t,{choiceMade:a});}catch(L){throw e.error(`Error ${c} label`,L),L}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||f};return o.onLabelStarting?await o.onLabelStarting(e$1,t,r,n):await n()}async call(e,t,r){let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,type:"calling"})}async jump(e,t,r){if(this.stepCounter===0)return await this.call(e,t,r);let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,closeCurrentLabel:true,type:"jumping to"})}async selectChoice(e$1,t){this.choices=void 0;let r=e$1.type;switch(r){case "call":return await this.call(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "jump":return await this.jump(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "close":return await this.closeChoiceMenu(e$1,{...e$1.props,...t});default:throw e.error(`Type ${r} not found`),new PixiError("invalid_usage",`Type ${r} not found`)}}async closeChoiceMenu(e$1,t){if(e$1.type!=="close")throw e.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r;return typeof e$1.choiceIndex=="number"&&(r=e$1.choiceIndex),e$1.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r})}get onStepError(){return async(e$1,t)=>{try{await GameUnifier.runOnError(e$1,t);}catch(r){e.error("Error in onError handler",r);}}}get dialogue(){let e=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e$1){if(e$1===void 0){GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e$1=="string"||Array.isArray(e$1))&&(e$1={text:e$1}),this.dialogGlue){let t=GameUnifier.getVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e$1.text)?r=[...r,...e$1.text]:r=[...r,e$1.text],e$1.text=r,e$1.character=e$1.character||t.character;}GameUnifier.setVariable(l,n.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,f({...e$1,character:typeof e$1.character=="string"?e$1.character:e$1.character?.id})),GameUnifier.setVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choices(){let e=GameUnifier.getVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,d)=>({...a,choiceIndex:d})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,d)=>a.oneTime&&n?.includes(d)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choices(e$1){if(!e$1||e$1.length===0){GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,f(e$1)),GameUnifier.setVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get dialogGlue(){return GameUnifier.getFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(n.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,GameUnifier.setVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY);}clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:f(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=S.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e$1,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e$1,"openedLabels")?(o.openedLabels=e$1.openedLabels,o.originalOpenedLabels=o.openedLabels):e.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e$1,"stepCounter")?o._stepCounter=e$1.stepCounter:e.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r){e.error("Error running onLoadingLabel",r);}}catch(r){e.error("Error importing data",r);}}};function D(i,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:i,type:r?.type||"call"}}var O="close";function U(i,e){return {...e,type:O,text:i}}var M=c(a(),1);var T=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var g=class extends T{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,r){super(e,r),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e$1){let t=this.steps;if(e$1<0||e$1>=t.length)return typeof this._steps!="function"&&e.warn("stepSha not found, setting to ERROR"),"error";try{return (0,M.default)(t[e$1].toString().toLocaleLowerCase()).toString()}catch(r){return e.warn("stepSha not found, setting to ERROR",r),"error"}}};function x(i,e,t){let r=new g(i,e,t);return S.add(r),r}var fe=new C;
2
+ export{g as Label,T as LabelAbstract,o as NarrationManagerStatic,S as RegisteredLabels,fe as narration,D as newChoiceOption,U as newCloseChoiceOption,x as newLabel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drincs/pixi-vn",
3
- "version": "1.8.24",
3
+ "version": "1.8.25",
4
4
  "type": "module",
5
5
  "description": "Pixi'VN is a npm package that provides various features for creating visual novels.",
6
6
  "main": "./dist/index.cjs",