UNPKG

@drincs/pixi-vn

Version:

Pixi'VN is a npm package that provides various features for creating visual novels.

1 lines 31.2 kB
'use strict';var core=require('@drincs/pixi-vn/core');var Xt=Object.defineProperty;var Vt=f=>{throw TypeError(f)};var Qt=(f,t,i)=>t in f?Xt(f,t,{enumerable:true,configurable:true,writable:true,value:i}):f[t]=i;var w=(f,t,i)=>Qt(f,typeof t!="symbol"?t+"":t,i),Rt=(f,t,i)=>t.has(f)||Vt("Cannot "+i);var e=(f,t,i)=>(Rt(f,t,"read from private field"),i?i.call(f):t.get(f)),b=(f,t,i)=>t.has(f)?Vt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(f):t.set(f,i),c=(f,t,i,s)=>(Rt(f,t,"write to private field"),t.set(f,i),i),u=(f,t,i)=>(Rt(f,t,"access private method"),i);var Tt=(f,t,i,s)=>({set _(r){c(f,t,r);},get _(){return e(f,t,s)}});var Zt={Date:true,RegExp:true,String:true,Number:true};function Ft(f,t,i={cyclesFix:true},s=[]){let r=[],o=Array.isArray(f);for(let a in f){let h=f[a],d=o?+a:a;if(!(a in t)){r.push({type:"REMOVE",path:[d],oldValue:f[a]});continue}let g=t[a],m=typeof h=="object"&&typeof g=="object"&&Array.isArray(h)===Array.isArray(g);h&&g&&m&&!Zt[Object.getPrototypeOf(h)?.constructor?.name]&&(!i.cyclesFix||!s.includes(h))?r.push.apply(r,Ft(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 f||r.push({type:"CREATE",path:[n?+a:a],value:t[a]});return r}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||(O={}));function et(f){try{if(typeof f>"u")return f;let t=JSON.stringify(f);return JSON.parse(t)}catch(t){throw O.error("Error creating exportable element",f,t),new core.PixiError("not_json_serializable","Error creating exportable element")}}function jt(f,t){let i=et(f);return t.length>1&&"type"in t[0]&&(t=t.slice().reverse()),t.forEach(s=>{ee(i,s);}),i}function ee(f,t){let i=f;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 ie=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,$t=new Set,Gt=typeof process=="object"&&process?process:{},Bt=(f,t,i,s)=>{typeof Gt.emitWarning=="function"?Gt.emitWarning(f,t,i,s):console.error(`[${i}] ${t}: ${f}`);},It=globalThis.AbortController,Ut=globalThis.AbortSignal;if(typeof It>"u"){Ut=class{constructor(){w(this,"onabort");w(this,"_onabort",[]);w(this,"reason");w(this,"aborted",false);}addEventListener(i,s){this._onabort.push(s);}},It=class{constructor(){w(this,"signal",new Ut);t();}abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=true;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i);}}};let f=Gt.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{f&&(f=false,Bt("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 se=f=>!$t.has(f);var ot=f=>f&&f===Math.floor(f)&&f>0&&isFinite(f),qt=f=>ot(f)?f<=Math.pow(2,8)?Uint8Array:f<=Math.pow(2,16)?Uint16Array:f<=Math.pow(2,32)?Uint32Array:f<=Number.MAX_SAFE_INTEGER?Ct:null:null,Ct=class extends Array{constructor(f){super(f),this.fill(0);}},it,mt,re=(it=class{constructor(t,i){w(this,"heap");w(this,"length");if(!e(it,mt))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new i(t),this.length=0;}static create(t){let i=qt(t);if(!i)return [];c(it,mt,true);let s=new it(t,i);return c(it,mt,false),s}push(t){this.heap[this.length++]=t;}pop(){return this.heap[--this.length]}},mt=new WeakMap,b(it,mt,false),it),Kt,Pt,P,k,$,ut,B,St,bt,q,F,J,T,A,y,R,W,z,C,Y,D,X,Q,V,j,Z,lt,G,wt,l,Lt,ct,rt,Et,U,Yt,pt,vt,Ht,nt,at,Mt,Dt,zt,x,kt,At,ht,Wt,_t,Jt=(_t=class{constructor(t){b(this,l);b(this,P);b(this,k);b(this,$);b(this,ut);b(this,B);b(this,St);b(this,bt);b(this,q);w(this,"ttl");w(this,"ttlResolution");w(this,"ttlAutopurge");w(this,"updateAgeOnGet");w(this,"updateAgeOnHas");w(this,"allowStale");w(this,"noDisposeOnSet");w(this,"noUpdateTTL");w(this,"maxEntrySize");w(this,"sizeCalculation");w(this,"noDeleteOnFetchRejection");w(this,"noDeleteOnStaleGet");w(this,"allowStaleOnFetchAbort");w(this,"allowStaleOnFetchRejection");w(this,"ignoreFetchAbort");b(this,F);b(this,J);b(this,T);b(this,A);b(this,y);b(this,R);b(this,W);b(this,z);b(this,C);b(this,Y);b(this,D);b(this,X);b(this,Q);b(this,V);b(this,j);b(this,Z);b(this,lt);b(this,G);b(this,wt);b(this,ct,()=>{});b(this,rt,()=>{});b(this,Et,()=>{});b(this,U,()=>false);b(this,pt,t=>{});b(this,vt,(t,i,s)=>{});b(this,Ht,(t,i,s,r)=>{if(s||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});w(this,Kt,"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:E=0,sizeCalculation:_,fetchMethod:S,memoMethod:I,noDeleteOnFetchRejection:L,noDeleteOnStaleGet:N,allowStaleOnFetchRejection:H,allowStaleOnFetchAbort:xt,ignoreFetchAbort:dt,perf:yt}=t;if(yt!==void 0&&typeof yt?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(c(this,q,yt??ie),i!==0&&!ot(i))throw new TypeError("max option must be a nonnegative integer");let gt=i?qt(i):Array;if(!gt)throw new Error("invalid max value: "+i);if(c(this,P,i),c(this,k,tt),this.maxEntrySize=E||e(this,k),this.sizeCalculation=_,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(c(this,bt,I),S!==void 0&&typeof S!="function")throw new TypeError("fetchMethod must be a function if specified");if(c(this,St,S),c(this,lt,!!S),c(this,T,new Map),c(this,A,new Array(i).fill(void 0)),c(this,y,new Array(i).fill(void 0)),c(this,R,new gt(i)),c(this,W,new gt(i)),c(this,z,0),c(this,C,0),c(this,Y,re.create(i)),c(this,F,0),c(this,J,0),typeof d=="function"&&c(this,$,d),typeof g=="function"&&c(this,ut,g),typeof m=="function"?(c(this,B,m),c(this,D,[])):(c(this,B,void 0),c(this,D,void 0)),c(this,Z,!!e(this,$)),c(this,wt,!!e(this,ut)),c(this,G,!!e(this,B)),this.noDisposeOnSet=!!v,this.noUpdateTTL=!!K,this.noDeleteOnFetchRejection=!!L,this.allowStaleOnFetchRejection=!!H,this.allowStaleOnFetchAbort=!!xt,this.ignoreFetchAbort=!!dt,this.maxEntrySize!==0){if(e(this,k)!==0&&!ot(e(this,k)))throw new TypeError("maxSize must be a positive integer if specified");if(!ot(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");u(this,l,Yt).call(this);}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!N,this.updateAgeOnGet=!!n,this.updateAgeOnHas=!!a,this.ttlResolution=ot(r)||r===0?r:1,this.ttlAutopurge=!!o,this.ttl=s||0,this.ttl){if(!ot(this.ttl))throw new TypeError("ttl must be a positive integer if specified");u(this,l,Lt).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";se(Nt)&&($t.add(Nt),Bt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Nt,_t));}}get perf(){return e(this,q)}static unsafeExposeInternals(t){return {starts:e(t,Q),ttls:e(t,V),autopurgeTimers:e(t,j),sizes:e(t,X),keyMap:e(t,T),keyList:e(t,A),valList:e(t,y),next:e(t,R),prev:e(t,W),get head(){return e(t,z)},get tail(){return e(t,C)},free:e(t,Y),isBackgroundFetch:i=>{var s;return u(s=t,l,x).call(s,i)},backgroundFetch:(i,s,r,o)=>{var n;return u(n=t,l,zt).call(n,i,s,r,o)},moveToTail:i=>{var s;return u(s=t,l,At).call(s,i)},indexes:i=>{var s;return u(s=t,l,nt).call(s,i)},rindexes:i=>{var s;return u(s=t,l,at).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,F)}get fetchMethod(){return e(this,St)}get memoMethod(){return e(this,bt)}get dispose(){return e(this,$)}get onInsert(){return e(this,ut)}get disposeAfter(){return e(this,B)}getRemainingTTL(t){return e(this,T).has(t)?1/0:0}*entries(){for(let t of u(this,l,nt).call(this))e(this,y)[t]!==void 0&&e(this,A)[t]!==void 0&&!u(this,l,x).call(this,e(this,y)[t])&&(yield [e(this,A)[t],e(this,y)[t]]);}*rentries(){for(let t of u(this,l,at).call(this))e(this,y)[t]!==void 0&&e(this,A)[t]!==void 0&&!u(this,l,x).call(this,e(this,y)[t])&&(yield [e(this,A)[t],e(this,y)[t]]);}*keys(){for(let t of u(this,l,nt).call(this)){let i=e(this,A)[t];i!==void 0&&!u(this,l,x).call(this,e(this,y)[t])&&(yield i);}}*rkeys(){for(let t of u(this,l,at).call(this)){let i=e(this,A)[t];i!==void 0&&!u(this,l,x).call(this,e(this,y)[t])&&(yield i);}}*values(){for(let t of u(this,l,nt).call(this))e(this,y)[t]!==void 0&&!u(this,l,x).call(this,e(this,y)[t])&&(yield e(this,y)[t]);}*rvalues(){for(let t of u(this,l,at).call(this))e(this,y)[t]!==void 0&&!u(this,l,x).call(this,e(this,y)[t])&&(yield e(this,y)[t]);}[(Pt=Symbol.iterator,Kt=Symbol.toStringTag,Pt)](){return this.entries()}find(t,i={}){for(let s of u(this,l,nt).call(this)){let r=e(this,y)[s],o=u(this,l,x).call(this,r)?r.__staleWhileFetching:r;if(o!==void 0&&t(o,e(this,A)[s],this))return this.get(e(this,A)[s],i)}}forEach(t,i=this){for(let s of u(this,l,nt).call(this)){let r=e(this,y)[s],o=u(this,l,x).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(i,o,e(this,A)[s],this);}}rforEach(t,i=this){for(let s of u(this,l,at).call(this)){let r=e(this,y)[s],o=u(this,l,x).call(this,r)?r.__staleWhileFetching:r;o!==void 0&&t.call(i,o,e(this,A)[s],this);}}purgeStale(){let t=false;for(let i of u(this,l,at).call(this,{allowStale:true}))e(this,U).call(this,i)&&(u(this,l,ht).call(this,e(this,A)[i],"expire"),t=true);return t}info(t){let i=e(this,T).get(t);if(i===void 0)return;let s=e(this,y)[i],r=u(this,l,x).call(this,s)?s.__staleWhileFetching:s;if(r===void 0)return;let o={value:r};if(e(this,V)&&e(this,Q)){let n=e(this,V)[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 u(this,l,nt).call(this,{allowStale:true})){let s=e(this,A)[i],r=e(this,y)[i],o=u(this,l,x).call(this,r)?r.__staleWhileFetching:r;if(o===void 0||s===void 0)continue;let n={value:o};if(e(this,V)&&e(this,Q)){n.ttl=e(this,V)[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,E;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,Ht).call(this,t,i,s.size||0,a);if(this.maxEntrySize&&g>this.maxEntrySize)return h&&(h.set="miss",h.maxEntrySizeExceeded=true),u(this,l,ht).call(this,t,"set"),this;let m=e(this,F)===0?void 0:e(this,T).get(t);if(m===void 0)m=e(this,F)===0?e(this,C):e(this,Y).length!==0?e(this,Y).pop():e(this,F)===e(this,P)?u(this,l,Dt).call(this,false):e(this,F),e(this,A)[m]=t,e(this,y)[m]=i,e(this,T).set(t,m),e(this,R)[e(this,C)]=m,e(this,W)[m]=e(this,C),c(this,C,m),Tt(this,F)._++,e(this,vt).call(this,m,g,h),h&&(h.set="add"),d=false,e(this,wt)&&((v=e(this,ut))==null||v.call(this,i,t,"add"));else {u(this,l,At).call(this,m);let _=e(this,y)[m];if(i!==_){if(e(this,lt)&&u(this,l,x).call(this,_)){_.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:S}=_;S!==void 0&&!n&&(e(this,Z)&&((K=e(this,$))==null||K.call(this,S,t,"set")),e(this,G)&&e(this,D)?.push([S,t,"set"]));}else n||(e(this,Z)&&((tt=e(this,$))==null||tt.call(this,_,t,"set")),e(this,G)&&e(this,D)?.push([_,t,"set"]));if(e(this,pt).call(this,m),e(this,vt).call(this,m,g,h),e(this,y)[m]=i,h){h.set="replace";let S=_&&u(this,l,x).call(this,_)?_.__staleWhileFetching:_;S!==void 0&&(h.oldValue=S);}}else h&&(h.set="update");e(this,wt)&&this.onInsert?.(i,t,i===_?"update":"replace");}if(r!==0&&!e(this,V)&&u(this,l,Lt).call(this),e(this,V)&&(d||e(this,Et).call(this,m,r,o),h&&e(this,rt).call(this,h,m)),!n&&e(this,G)&&e(this,D)){let _=e(this,D),S;for(;S=_?.shift();)(E=e(this,B))==null||E.call(this,...S);}return this}pop(){var t;try{for(;e(this,F);){let i=e(this,y)[e(this,z)];if(u(this,l,Dt).call(this,!0),u(this,l,x).call(this,i)){if(i.__staleWhileFetching)return i.__staleWhileFetching}else if(i!==void 0)return i}}finally{if(e(this,G)&&e(this,D)){let i=e(this,D),s;for(;s=i?.shift();)(t=e(this,B))==null||t.call(this,...s);}}}has(t,i={}){let{updateAgeOnHas:s=this.updateAgeOnHas,status:r}=i,o=e(this,T).get(t);if(o!==void 0){let n=e(this,y)[o];if(u(this,l,x).call(this,n)&&n.__staleWhileFetching===void 0)return false;if(e(this,U).call(this,o))r&&(r.has="stale",e(this,rt).call(this,r,o));else return s&&e(this,ct).call(this,o),r&&(r.has="hit",e(this,rt).call(this,r,o)),true}else r&&(r.has="miss");return false}peek(t,i={}){let{allowStale:s=this.allowStale}=i,r=e(this,T).get(t);if(r===void 0||!s&&e(this,U).call(this,r))return;let o=e(this,y)[r];return u(this,l,x).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:E,forceRefresh:_=false,status:S,signal:I}=i;if(!e(this,lt))return S&&(S.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:S});let L={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},N=e(this,T).get(t);if(N===void 0){S&&(S.fetch="miss");let H=u(this,l,zt).call(this,t,N,L,E);return H.__returned=H}else {let H=e(this,y)[N];if(u(this,l,x).call(this,H)){let gt=s&&H.__staleWhileFetching!==void 0;return S&&(S.fetch="inflight",gt&&(S.returnedStale=true)),gt?H.__staleWhileFetching:H.__returned=H}let xt=e(this,U).call(this,N);if(!_&&!xt)return S&&(S.fetch="hit"),u(this,l,At).call(this,N),r&&e(this,ct).call(this,N),S&&e(this,rt).call(this,S,N),H;let dt=u(this,l,zt).call(this,t,N,L,E),yt=dt.__staleWhileFetching!==void 0&&s;return S&&(S.fetch=xt?"stale":"refresh",yt&&xt&&(S.returnedStale=true)),yt?dt.__staleWhileFetching:dt.__returned=dt}}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,bt);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,T).get(t);if(a!==void 0){let h=e(this,y)[a],d=u(this,l,x).call(this,h);return n&&e(this,rt).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||u(this,l,ht).call(this,t,"expire"),n&&s&&(n.returnedStale=true),s?h:void 0)):(n&&(n.get="hit"),d?h.__staleWhileFetching:(u(this,l,At).call(this,a),r&&e(this,ct).call(this,a),h))}else n&&(n.get="miss");}delete(t){return u(this,l,ht).call(this,t,"delete")}clear(){return u(this,l,Wt).call(this,"delete")}},P=new WeakMap,k=new WeakMap,$=new WeakMap,ut=new WeakMap,B=new WeakMap,St=new WeakMap,bt=new WeakMap,q=new WeakMap,F=new WeakMap,J=new WeakMap,T=new WeakMap,A=new WeakMap,y=new WeakMap,R=new WeakMap,W=new WeakMap,z=new WeakMap,C=new WeakMap,Y=new WeakMap,D=new WeakMap,X=new WeakMap,Q=new WeakMap,V=new WeakMap,j=new WeakMap,Z=new WeakMap,lt=new WeakMap,G=new WeakMap,wt=new WeakMap,l=new WeakSet,Lt=function(){let t=new Ct(e(this,P)),i=new Ct(e(this,P));c(this,V,t),c(this,Q,i);let s=this.ttlAutopurge?new Array(e(this,P)):void 0;c(this,j,s),c(this,Et,(a,h,d=e(this,q).now())=>{i[a]=h!==0?d:0,t[a]=h,r(a,h);}),c(this,ct,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)&&u(this,l,ht).call(this,e(this,A)[a],"expire");},h+1);d.unref&&d.unref(),s[a]=d;}}:()=>{};c(this,rt,(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,T).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},c(this,U,a=>{let h=i[a],d=t[a];return !!d&&!!h&&(o||n())-h>d});},ct=new WeakMap,rt=new WeakMap,Et=new WeakMap,U=new WeakMap,Yt=function(){let t=new Ct(e(this,P));c(this,J,0),c(this,X,t),c(this,pt,i=>{c(this,J,e(this,J)-t[i]),t[i]=0;}),c(this,Ht,(i,s,r,o)=>{if(u(this,l,x).call(this,s))return 0;if(!ot(r))if(o){if(typeof o!="function")throw new TypeError("sizeCalculation must be a function");if(r=o(s,i),!ot(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}),c(this,vt,(i,s,r)=>{if(t[i]=s,e(this,k)){let o=e(this,k)-t[i];for(;e(this,J)>o;)u(this,l,Dt).call(this,true);}c(this,J,e(this,J)+t[i]),r&&(r.entrySize=s,r.totalCalculatedSize=e(this,J));});},pt=new WeakMap,vt=new WeakMap,Ht=new WeakMap,nt=function*({allowStale:t=this.allowStale}={}){if(e(this,F))for(let i=e(this,C);!(!u(this,l,Mt).call(this,i)||((t||!e(this,U).call(this,i))&&(yield i),i===e(this,z)));)i=e(this,W)[i];},at=function*({allowStale:t=this.allowStale}={}){if(e(this,F))for(let i=e(this,z);!(!u(this,l,Mt).call(this,i)||((t||!e(this,U).call(this,i))&&(yield i),i===e(this,C)));)i=e(this,R)[i];},Mt=function(t){return t!==void 0&&e(this,T).get(e(this,A)[t])===t},Dt=function(t){var o;let i=e(this,z),s=e(this,A)[i],r=e(this,y)[i];return e(this,lt)&&u(this,l,x).call(this,r)?r.__abortController.abort(new Error("evicted")):(e(this,Z)||e(this,G))&&(e(this,Z)&&((o=e(this,$))==null||o.call(this,r,s,"evict")),e(this,G)&&e(this,D)?.push([r,s,"evict"])),e(this,pt).call(this,i),e(this,j)?.[i]&&(clearTimeout(e(this,j)[i]),e(this,j)[i]=void 0),t&&(e(this,A)[i]=void 0,e(this,y)[i]=void 0,e(this,Y).push(i)),e(this,F)===1?(c(this,z,c(this,C,0)),e(this,Y).length=0):c(this,z,e(this,R)[i]),e(this,T).delete(s),Tt(this,F)._--,i},zt=function(t,i,s,r){let o=i===void 0?void 0:e(this,y)[i];if(u(this,l,x).call(this,o))return o;let n=new It,{signal:a}=s;a?.addEventListener("abort",()=>n.abort(a.reason),{signal:n.signal});let h={signal:n.signal,options:s,context:r},d=(E,_=false)=>{let{aborted:S}=n.signal,I=s.ignoreFetchAbort&&E!==void 0,L=s.ignoreFetchAbort||!!(s.allowStaleOnFetchAbort&&E!==void 0);if(s.status&&(S&&!_?(s.status.fetchAborted=true,s.status.fetchError=n.signal.reason,I&&(s.status.fetchAbortIgnored=true)):s.status.fetchResolved=true),S&&!I&&!_)return m(n.signal.reason,L);let N=K,H=e(this,y)[i];return (H===K||I&&_&&H===void 0)&&(E===void 0?N.__staleWhileFetching!==void 0?e(this,y)[i]=N.__staleWhileFetching:u(this,l,ht).call(this,t,"fetch"):(s.status&&(s.status.fetchUpdated=true),this.set(t,E,h.options))),E},g=E=>(s.status&&(s.status.fetchRejected=true,s.status.fetchError=E),m(E,false)),m=(E,_)=>{let{aborted:S}=n.signal,I=S&&s.allowStaleOnFetchAbort,L=I||s.allowStaleOnFetchRejection,N=L||s.noDeleteOnFetchRejection,H=K;if(e(this,y)[i]===K&&(!N||!_&&H.__staleWhileFetching===void 0?u(this,l,ht).call(this,t,"fetch"):I||(e(this,y)[i]=H.__staleWhileFetching)),L)return s.status&&H.__staleWhileFetching!==void 0&&(s.status.returnedStale=true),H.__staleWhileFetching;if(H.__returned===H)throw E},v=(E,_)=>{var I;let S=(I=e(this,St))==null?void 0:I.call(this,t,o,h);S&&S instanceof Promise&&S.then(L=>E(L===void 0?void 0:L),_),n.signal.addEventListener("abort",()=>{(!s.ignoreFetchAbort||s.allowStaleOnFetchAbort)&&(E(void 0),s.allowStaleOnFetchAbort&&(E=L=>d(L,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,T).get(t)):e(this,y)[i]=tt,tt},x=function(t){if(!e(this,lt))return false;let i=t;return !!i&&i instanceof Promise&&i.hasOwnProperty("__staleWhileFetching")&&i.__abortController instanceof It},kt=function(t,i){e(this,W)[i]=t,e(this,R)[t]=i;},At=function(t){t!==e(this,C)&&(t===e(this,z)?c(this,z,e(this,R)[t]):u(this,l,kt).call(this,e(this,W)[t],e(this,R)[t]),u(this,l,kt).call(this,e(this,C),t),c(this,C,t));},ht=function(t,i){var r,o;let s=false;if(e(this,F)!==0){let n=e(this,T).get(t);if(n!==void 0)if(e(this,j)?.[n]&&(clearTimeout(e(this,j)?.[n]),e(this,j)[n]=void 0),s=true,e(this,F)===1)u(this,l,Wt).call(this,i);else {e(this,pt).call(this,n);let a=e(this,y)[n];if(u(this,l,x).call(this,a)?a.__abortController.abort(new Error("deleted")):(e(this,Z)||e(this,G))&&(e(this,Z)&&((r=e(this,$))==null||r.call(this,a,t,i)),e(this,G)&&e(this,D)?.push([a,t,i])),e(this,T).delete(t),e(this,A)[n]=void 0,e(this,y)[n]=void 0,n===e(this,C))c(this,C,e(this,W)[n]);else if(n===e(this,z))c(this,z,e(this,R)[n]);else {let h=e(this,W)[n];e(this,R)[h]=e(this,R)[n];let d=e(this,R)[n];e(this,W)[d]=e(this,W)[n];}Tt(this,F)._--,e(this,Y).push(n);}}if(e(this,G)&&e(this,D)?.length){let n=e(this,D),a;for(;a=n?.shift();)(o=e(this,B))==null||o.call(this,...a);}return s},Wt=function(t){var i,s;for(let r of u(this,l,at).call(this,{allowStale:true})){let o=e(this,y)[r];if(u(this,l,x).call(this,o))o.__abortController.abort(new Error("deleted"));else {let n=e(this,A)[r];e(this,Z)&&((i=e(this,$))==null||i.call(this,o,n,t)),e(this,G)&&e(this,D)?.push([o,n,t]);}}if(e(this,T).clear(),e(this,y).fill(void 0),e(this,A).fill(void 0),e(this,V)&&e(this,Q)){e(this,V).fill(0),e(this,Q).fill(0);for(let r of e(this,j)??[])r!==void 0&&clearTimeout(r);e(this,j)?.fill(void 0);}if(e(this,X)&&e(this,X).fill(0),c(this,z,0),c(this,C,0),e(this,Y).length=0,c(this,J,0),c(this,F,0),e(this,G)&&e(this,D)){let r=e(this,D),o;for(;o=r?.shift();)(s=e(this,B))==null||s.call(this,...o);}},_t);var ft=class{constructor(t){w(this,"cache");w(this,"map",new Map);this.cache=new Jt({max:t.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){return this.cache.clear(),this.map.clear()}delete(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 st=class st{static get originalStepData(){return st._originalStepData?et(st._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){st._originalStepData=et(t);}};w(st,"_diffHistory",new ft({cacheSize:5})),w(st,"_stepsInfoHistory",new ft({cacheSize:5})),w(st,"_narrationHistory",new ft({cacheSize:50})),w(st,"stepLimitSaved",20),w(st,"_originalStepData");var p=st;var Ot=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=et(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);}finally{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=Ft(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&&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:et(i),originalStepData:et(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{t.hasOwnProperty("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"),t.hasOwnProperty("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 Me=new Ot;exports.HistoryManagerStatic=p;exports.stepHistory=Me;