UNPKG

@drincs/pixi-vn

Version:

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

1 lines 34.6 kB
'use strict';var Qe=Object.defineProperty;var je=u=>{throw TypeError(u)};var Ze=(u,e,t)=>e in u?Qe(u,e,{enumerable:true,configurable:true,writable:true,value:t}):u[e]=t;var p=(u,e,t)=>Ze(u,typeof e!="symbol"?e+"":e,t),Me=(u,e,t)=>e.has(u)||je("Cannot "+t);var i=(u,e,t)=>(Me(u,e,"read from private field"),t?t.call(u):e.get(u)),E=(u,e,t)=>e.has(u)?je("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(u):e.set(u,t),d=(u,e,t,r)=>(Me(u,e,"write to private field"),e.set(u,t),t),f=(u,e,t)=>(Me(u,e,"access private method"),t);var Ce=(u,e,t,r)=>({set _(s){d(u,e,s);},get _(){return i(u,e,r)}});var et={Date:true,RegExp:true,String:true,Number:true};function Te(u,e,t={cyclesFix:true},r=[]){let s=[],n=Array.isArray(u);for(let h in u){let l=u[h],b=n?+h:h;if(!(h in e)){s.push({type:"REMOVE",path:[b],oldValue:u[h]});continue}let w=e[h],v=typeof l=="object"&&typeof w=="object"&&Array.isArray(l)===Array.isArray(w);l&&w&&v&&!et[Object.getPrototypeOf(l)?.constructor?.name]&&(!t.cyclesFix||!r.includes(l))?s.push.apply(s,Te(l,w,t,t.cyclesFix?r.concat([l]):[]).map(_=>(_.path.unshift(b),_))):l!==w&&!(Number.isNaN(l)&&Number.isNaN(w))&&!(v&&(isNaN(l)?l+""==w+"":+l==+w))&&s.push({path:[b],type:"CHANGE",value:w,oldValue:l});}let o=Array.isArray(e);for(let h in e)h in u||s.push({type:"CREATE",path:[o?+h:h],value:e[h]});return s}var S;(s=>(s.log=(n,...o)=>console.log(`[Pixi\u2019VN] ${n}`,...o),s.warn=(n,...o)=>console.warn(`[Pixi\u2019VN] ${n}`,...o),s.error=(n,...o)=>console.error(`[Pixi\u2019VN] ${n}`,...o),s.info=(n,...o)=>console.info(`[Pixi\u2019VN] ${n}`,...o)))(S||(S={}));var m=class m{static init(e){m._getStepCounter=e.getStepCounter,m._setStepCounter=e.setStepCounter,m._getCurrentGameStepState=e.getCurrentGameStepState,m._restoreGameStepState=e.restoreGameStepState,m._getOpenedLabels=e.getOpenedLabels,e.onGoNextEnd&&(m._onGoNextEnd=e.onGoNextEnd),m._getVariable=e.getVariable,m._setVariable=e.setVariable,m._removeVariable=e.removeVariable,m._getFlag=e.getFlag,m._setFlag=e.setFlag,e.onLabelClosing&&(m._onLabelClosing=e.onLabelClosing),m._addHistoryItem=e.addHistoryItem,m._getCurrentStepsRunningNumber=e.getCurrentStepsRunningNumber,m._getCharacter=e.getCharacter;}static get stepCounter(){return m._getStepCounter()}static set stepCounter(e){m._setStepCounter(e);}static get currentGameStepState(){return m._getCurrentGameStepState()}static get restoreGameStepState(){return m._restoreGameStepState}static get openedLabels(){return m._getOpenedLabels()}static get onGoNextEnd(){return m._onGoNextEnd}static get getVariable(){return m._getVariable}static get setVariable(){return m._setVariable}static get removeVariable(){return m._removeVariable}static get getFlag(){return m._getFlag}static get setFlag(){return m._setFlag}static get onLabelClosing(){return m._onLabelClosing}static get addHistoryItem(){return m._addHistoryItem}static get currentStepsRunningNumber(){return m._getCurrentStepsRunningNumber()}static get getCharacter(){return m._getCharacter}};p(m,"_getStepCounter",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_setStepCounter",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_getCurrentGameStepState",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_restoreGameStepState",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_getOpenedLabels",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_onGoNextEnd",async()=>{}),p(m,"_getVariable",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_setVariable",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_removeVariable",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_getFlag",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_setFlag",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_onLabelClosing",()=>{}),p(m,"_addHistoryItem",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_getCurrentStepsRunningNumber",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented, you should initialize the Game: Game.init()")}),p(m,"_getCharacter",()=>{throw S.error("Method not implemented, you should initialize the Game: Game.init()"),new Error("Method not implemented.")}),p(m,"onEnd"),p(m,"onError");var ee=m;function te(u){try{if(typeof u>"u")return u;let e=JSON.stringify(u);return JSON.parse(e)}catch(e){throw S.error("Error creating exportable element",u,e),new Error("[Pixi\u2019VN] Error creating exportable element")}}function Ke(u,e){let t=te(u);return e.length>1&&"type"in e[0]&&(e=e.reverse()),e.forEach(r=>{"type"in r?tt(t,r):it(t,r);}),t}function tt(u,e){let t=u;e.path&&e.path.length>0?e.path.forEach((r,s)=>{if(e.path&&s===e.path.length-1)switch(e.type){case "CHANGE":case "REMOVE":t[r]=e.oldValue;break;case "CREATE":Array.isArray(t)&&typeof r=="number"?t.splice(r,1):delete t[r];break}else t=t[r];}):S.warn("No path found, skipping diff",e);}function it(u,e){let t=u;e.path&&e.path.length>0?e.path.forEach((r,s)=>{if(e.path&&s===e.path.length-1){if(e.kind==="E"||e.kind==="D")t[r]=e.lhs;else if(e.kind==="N")Number.isInteger(r)?Array.isArray(t)&&t.splice(r,1):typeof r=="string"&&delete t[r];else if(e.kind==="A"){let n=e.index;e.item.kind==="N"?t[r].splice(n,1):e.item.kind==="E"||e.item.kind==="D"?t[r][n]=e.item.lhs:e.item.kind==="A"?S.warn("Nested array found, skipping diff",e):S.warn("No array found, skipping diff",e);}}else t=t[r];}):S.warn("No path found, skipping diff",e);}var me=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Ye=new Set,Ne=typeof process=="object"&&process?process:{},Je=(u,e,t,r)=>{typeof Ne.emitWarning=="function"?Ne.emitWarning(u,e,t,r):console.error(`[${t}] ${e}: ${u}`);},Fe=globalThis.AbortController,Be=globalThis.AbortSignal;if(typeof Fe>"u"){Be=class{constructor(){p(this,"onabort");p(this,"_onabort",[]);p(this,"reason");p(this,"aborted",false);}addEventListener(r,s){this._onabort.push(s);}},Fe=class{constructor(){p(this,"signal",new Be);e();}abort(r){if(!this.signal.aborted){this.signal.reason=r,this.signal.aborted=true;for(let s of this.signal._onabort)s(r);this.signal.onabort?.(r);}}};let u=Ne.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{u&&(u=false,Je("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e));};}var rt=u=>!Ye.has(u),re=u=>u&&u===Math.floor(u)&&u>0&&isFinite(u),qe=u=>re(u)?u<=Math.pow(2,8)?Uint8Array:u<=Math.pow(2,16)?Uint16Array:u<=Math.pow(2,32)?Uint32Array:u<=Number.MAX_SAFE_INTEGER?ge:null:null,ge=class extends Array{constructor(e){super(e),this.fill(0);}},ye,he=class he{constructor(e,t){p(this,"heap");p(this,"length");if(!i(he,ye))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}static create(e){let t=qe(e);if(!t)return [];d(he,ye,true);let r=new he(e,t);return d(he,ye,false),r}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}};ye=new WeakMap,E(he,ye,false);var Le=he,$e,Ue,K,R,B,ue,$,Se,be,T,U,C,x,g,D,k,I,z,Y,O,J,q,V,X,ae,M,we,a,Re,fe,ie,He,W,Xe,ce,ve,xe,se,ne,ke,ze,Oe,H,Ve,_e,oe,We,Pe=class Pe{constructor(e){E(this,a);E(this,K);E(this,R);E(this,B);E(this,ue);E(this,$);E(this,Se);E(this,be);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");E(this,T);E(this,U);E(this,C);E(this,x);E(this,g);E(this,D);E(this,k);E(this,I);E(this,z);E(this,Y);E(this,O);E(this,J);E(this,q);E(this,V);E(this,X);E(this,ae);E(this,M);E(this,we);E(this,fe,()=>{});E(this,ie,()=>{});E(this,He,()=>{});E(this,W,()=>false);E(this,ce,e=>{});E(this,ve,(e,t,r)=>{});E(this,xe,(e,t,r,s)=>{if(r||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});p(this,$e,"LRUCache");let{max:t=0,ttl:r,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:h,allowStale:l,dispose:b,onInsert:w,disposeAfter:v,noDisposeOnSet:_,noUpdateTTL:P,maxSize:Z=0,maxEntrySize:G=0,sizeCalculation:A,fetchMethod:y,memoMethod:N,noDeleteOnFetchRejection:L,noDeleteOnStaleGet:F,allowStaleOnFetchRejection:j,allowStaleOnFetchAbort:Ee,ignoreFetchAbort:de}=e;if(t!==0&&!re(t))throw new TypeError("max option must be a nonnegative integer");let Ge=t?qe(t):Array;if(!Ge)throw new Error("invalid max value: "+t);if(d(this,K,t),d(this,R,Z),this.maxEntrySize=G||i(this,R),this.sizeCalculation=A,this.sizeCalculation){if(!i(this,R)&&!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(d(this,be,N),y!==void 0&&typeof y!="function")throw new TypeError("fetchMethod must be a function if specified");if(d(this,Se,y),d(this,ae,!!y),d(this,C,new Map),d(this,x,new Array(t).fill(void 0)),d(this,g,new Array(t).fill(void 0)),d(this,D,new Ge(t)),d(this,k,new Ge(t)),d(this,I,0),d(this,z,0),d(this,Y,Le.create(t)),d(this,T,0),d(this,U,0),typeof b=="function"&&d(this,B,b),typeof w=="function"&&d(this,ue,w),typeof v=="function"?(d(this,$,v),d(this,O,[])):(d(this,$,void 0),d(this,O,void 0)),d(this,X,!!i(this,B)),d(this,we,!!i(this,ue)),d(this,M,!!i(this,$)),this.noDisposeOnSet=!!_,this.noUpdateTTL=!!P,this.noDeleteOnFetchRejection=!!L,this.allowStaleOnFetchRejection=!!j,this.allowStaleOnFetchAbort=!!Ee,this.ignoreFetchAbort=!!de,this.maxEntrySize!==0){if(i(this,R)!==0&&!re(i(this,R)))throw new TypeError("maxSize must be a positive integer if specified");if(!re(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");f(this,a,Xe).call(this);}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!F,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!h,this.ttlResolution=re(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=r||0,this.ttl){if(!re(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,a,Re).call(this);}if(i(this,K)===0&&this.ttl===0&&i(this,R)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!i(this,K)&&!i(this,R)){let pe="LRU_CACHE_UNBOUNDED";rt(pe)&&(Ye.add(pe),Je("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",pe,Pe));}}static unsafeExposeInternals(e){return {starts:i(e,q),ttls:i(e,V),sizes:i(e,J),keyMap:i(e,C),keyList:i(e,x),valList:i(e,g),next:i(e,D),prev:i(e,k),get head(){return i(e,I)},get tail(){return i(e,z)},free:i(e,Y),isBackgroundFetch:t=>{var r;return f(r=e,a,H).call(r,t)},backgroundFetch:(t,r,s,n)=>{var o;return f(o=e,a,Oe).call(o,t,r,s,n)},moveToTail:t=>{var r;return f(r=e,a,_e).call(r,t)},indexes:t=>{var r;return f(r=e,a,se).call(r,t)},rindexes:t=>{var r;return f(r=e,a,ne).call(r,t)},isStale:t=>{var r;return i(r=e,W).call(r,t)}}}get max(){return i(this,K)}get maxSize(){return i(this,R)}get calculatedSize(){return i(this,U)}get size(){return i(this,T)}get fetchMethod(){return i(this,Se)}get memoMethod(){return i(this,be)}get dispose(){return i(this,B)}get onInsert(){return i(this,ue)}get disposeAfter(){return i(this,$)}getRemainingTTL(e){return i(this,C).has(e)?1/0:0}*entries(){for(let e of f(this,a,se).call(this))i(this,g)[e]!==void 0&&i(this,x)[e]!==void 0&&!f(this,a,H).call(this,i(this,g)[e])&&(yield [i(this,x)[e],i(this,g)[e]]);}*rentries(){for(let e of f(this,a,ne).call(this))i(this,g)[e]!==void 0&&i(this,x)[e]!==void 0&&!f(this,a,H).call(this,i(this,g)[e])&&(yield [i(this,x)[e],i(this,g)[e]]);}*keys(){for(let e of f(this,a,se).call(this)){let t=i(this,x)[e];t!==void 0&&!f(this,a,H).call(this,i(this,g)[e])&&(yield t);}}*rkeys(){for(let e of f(this,a,ne).call(this)){let t=i(this,x)[e];t!==void 0&&!f(this,a,H).call(this,i(this,g)[e])&&(yield t);}}*values(){for(let e of f(this,a,se).call(this))i(this,g)[e]!==void 0&&!f(this,a,H).call(this,i(this,g)[e])&&(yield i(this,g)[e]);}*rvalues(){for(let e of f(this,a,ne).call(this))i(this,g)[e]!==void 0&&!f(this,a,H).call(this,i(this,g)[e])&&(yield i(this,g)[e]);}[(Ue=Symbol.iterator,$e=Symbol.toStringTag,Ue)](){return this.entries()}find(e,t={}){for(let r of f(this,a,se).call(this)){let s=i(this,g)[r],n=f(this,a,H).call(this,s)?s.__staleWhileFetching:s;if(n!==void 0&&e(n,i(this,x)[r],this))return this.get(i(this,x)[r],t)}}forEach(e,t=this){for(let r of f(this,a,se).call(this)){let s=i(this,g)[r],n=f(this,a,H).call(this,s)?s.__staleWhileFetching:s;n!==void 0&&e.call(t,n,i(this,x)[r],this);}}rforEach(e,t=this){for(let r of f(this,a,ne).call(this)){let s=i(this,g)[r],n=f(this,a,H).call(this,s)?s.__staleWhileFetching:s;n!==void 0&&e.call(t,n,i(this,x)[r],this);}}purgeStale(){let e=false;for(let t of f(this,a,ne).call(this,{allowStale:true}))i(this,W).call(this,t)&&(f(this,a,oe).call(this,i(this,x)[t],"expire"),e=true);return e}info(e){let t=i(this,C).get(e);if(t===void 0)return;let r=i(this,g)[t],s=f(this,a,H).call(this,r)?r.__staleWhileFetching:r;if(s===void 0)return;let n={value:s};if(i(this,V)&&i(this,q)){let o=i(this,V)[t],h=i(this,q)[t];if(o&&h){let l=o-(me.now()-h);n.ttl=l,n.start=Date.now();}}return i(this,J)&&(n.size=i(this,J)[t]),n}dump(){let e=[];for(let t of f(this,a,se).call(this,{allowStale:true})){let r=i(this,x)[t],s=i(this,g)[t],n=f(this,a,H).call(this,s)?s.__staleWhileFetching:s;if(n===void 0||r===void 0)continue;let o={value:n};if(i(this,V)&&i(this,q)){o.ttl=i(this,V)[t];let h=me.now()-i(this,q)[t];o.start=Math.floor(Date.now()-h);}i(this,J)&&(o.size=i(this,J)[t]),e.unshift([r,o]);}return e}load(e){this.clear();for(let[t,r]of e){if(r.start){let s=Date.now()-r.start;r.start=me.now()-s;}this.set(t,r.value,r);}}set(e,t,r={}){var _,P,Z,G;if(t===void 0)return this.delete(e),this;let{ttl:s=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:h=this.sizeCalculation,status:l}=r,{noUpdateTTL:b=this.noUpdateTTL}=r,w=i(this,xe).call(this,e,t,r.size||0,h);if(this.maxEntrySize&&w>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=true),f(this,a,oe).call(this,e,"set"),this;let v=i(this,T)===0?void 0:i(this,C).get(e);if(v===void 0)v=i(this,T)===0?i(this,z):i(this,Y).length!==0?i(this,Y).pop():i(this,T)===i(this,K)?f(this,a,ze).call(this,false):i(this,T),i(this,x)[v]=e,i(this,g)[v]=t,i(this,C).set(e,v),i(this,D)[i(this,z)]=v,i(this,k)[v]=i(this,z),d(this,z,v),Ce(this,T)._++,i(this,ve).call(this,v,w,l),l&&(l.set="add"),b=false,i(this,we)&&((_=i(this,ue))==null||_.call(this,t,e,"add"));else {f(this,a,_e).call(this,v);let A=i(this,g)[v];if(t!==A){if(i(this,ae)&&f(this,a,H).call(this,A)){A.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:y}=A;y!==void 0&&!o&&(i(this,X)&&((P=i(this,B))==null||P.call(this,y,e,"set")),i(this,M)&&i(this,O)?.push([y,e,"set"]));}else o||(i(this,X)&&((Z=i(this,B))==null||Z.call(this,A,e,"set")),i(this,M)&&i(this,O)?.push([A,e,"set"]));if(i(this,ce).call(this,v),i(this,ve).call(this,v,w,l),i(this,g)[v]=t,l){l.set="replace";let y=A&&f(this,a,H).call(this,A)?A.__staleWhileFetching:A;y!==void 0&&(l.oldValue=y);}}else l&&(l.set="update");i(this,we)&&this.onInsert?.(t,e,t===A?"update":"replace");}if(s!==0&&!i(this,V)&&f(this,a,Re).call(this),i(this,V)&&(b||i(this,He).call(this,v,s,n),l&&i(this,ie).call(this,l,v)),!o&&i(this,M)&&i(this,O)){let A=i(this,O),y;for(;y=A?.shift();)(G=i(this,$))==null||G.call(this,...y);}return this}pop(){var e;try{for(;i(this,T);){let t=i(this,g)[i(this,I)];if(f(this,a,ze).call(this,!0),f(this,a,H).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(i(this,M)&&i(this,O)){let t=i(this,O),r;for(;r=t?.shift();)(e=i(this,$))==null||e.call(this,...r);}}}has(e,t={}){let{updateAgeOnHas:r=this.updateAgeOnHas,status:s}=t,n=i(this,C).get(e);if(n!==void 0){let o=i(this,g)[n];if(f(this,a,H).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(i(this,W).call(this,n))s&&(s.has="stale",i(this,ie).call(this,s,n));else return r&&i(this,fe).call(this,n),s&&(s.has="hit",i(this,ie).call(this,s,n)),true}else s&&(s.has="miss");return false}peek(e,t={}){let{allowStale:r=this.allowStale}=t,s=i(this,C).get(e);if(s===void 0||!r&&i(this,W).call(this,s))return;let n=i(this,g)[s];return f(this,a,H).call(this,n)?n.__staleWhileFetching:n}async fetch(e,t={}){let{allowStale:r=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:l=0,sizeCalculation:b=this.sizeCalculation,noUpdateTTL:w=this.noUpdateTTL,noDeleteOnFetchRejection:v=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:_=this.allowStaleOnFetchRejection,ignoreFetchAbort:P=this.ignoreFetchAbort,allowStaleOnFetchAbort:Z=this.allowStaleOnFetchAbort,context:G,forceRefresh:A=false,status:y,signal:N}=t;if(!i(this,ae))return y&&(y.fetch="get"),this.get(e,{allowStale:r,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:y});let L={allowStale:r,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:h,size:l,sizeCalculation:b,noUpdateTTL:w,noDeleteOnFetchRejection:v,allowStaleOnFetchRejection:_,allowStaleOnFetchAbort:Z,ignoreFetchAbort:P,status:y,signal:N},F=i(this,C).get(e);if(F===void 0){y&&(y.fetch="miss");let j=f(this,a,Oe).call(this,e,F,L,G);return j.__returned=j}else {let j=i(this,g)[F];if(f(this,a,H).call(this,j)){let De=r&&j.__staleWhileFetching!==void 0;return y&&(y.fetch="inflight",De&&(y.returnedStale=true)),De?j.__staleWhileFetching:j.__returned=j}let Ee=i(this,W).call(this,F);if(!A&&!Ee)return y&&(y.fetch="hit"),f(this,a,_e).call(this,F),s&&i(this,fe).call(this,F),y&&i(this,ie).call(this,y,F),j;let de=f(this,a,Oe).call(this,e,F,L,G),pe=de.__staleWhileFetching!==void 0&&r;return y&&(y.fetch=Ee?"stale":"refresh",pe&&Ee&&(y.returnedStale=true)),pe?de.__staleWhileFetching:de.__returned=de}}async forceFetch(e,t={}){let r=await this.fetch(e,t);if(r===void 0)throw new Error("fetch() returned undefined");return r}memo(e,t={}){let r=i(this,be);if(!r)throw new Error("no memoMethod provided to constructor");let{context:s,forceRefresh:n,...o}=t,h=this.get(e,o);if(!n&&h!==void 0)return h;let l=r(e,h,{options:o,context:s});return this.set(e,l,o),l}get(e,t={}){let{allowStale:r=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=t,h=i(this,C).get(e);if(h!==void 0){let l=i(this,g)[h],b=f(this,a,H).call(this,l);return o&&i(this,ie).call(this,o,h),i(this,W).call(this,h)?(o&&(o.get="stale"),b?(o&&r&&l.__staleWhileFetching!==void 0&&(o.returnedStale=true),r?l.__staleWhileFetching:void 0):(n||f(this,a,oe).call(this,e,"expire"),o&&r&&(o.returnedStale=true),r?l:void 0)):(o&&(o.get="hit"),b?l.__staleWhileFetching:(f(this,a,_e).call(this,h),s&&i(this,fe).call(this,h),l))}else o&&(o.get="miss");}delete(e){return f(this,a,oe).call(this,e,"delete")}clear(){return f(this,a,We).call(this,"delete")}};K=new WeakMap,R=new WeakMap,B=new WeakMap,ue=new WeakMap,$=new WeakMap,Se=new WeakMap,be=new WeakMap,T=new WeakMap,U=new WeakMap,C=new WeakMap,x=new WeakMap,g=new WeakMap,D=new WeakMap,k=new WeakMap,I=new WeakMap,z=new WeakMap,Y=new WeakMap,O=new WeakMap,J=new WeakMap,q=new WeakMap,V=new WeakMap,X=new WeakMap,ae=new WeakMap,M=new WeakMap,we=new WeakMap,a=new WeakSet,Re=function(){let e=new ge(i(this,K)),t=new ge(i(this,K));d(this,V,e),d(this,q,t),d(this,He,(n,o,h=me.now())=>{if(t[n]=o!==0?h:0,e[n]=o,o!==0&&this.ttlAutopurge){let l=setTimeout(()=>{i(this,W).call(this,n)&&f(this,a,oe).call(this,i(this,x)[n],"expire");},o+1);l.unref&&l.unref();}}),d(this,fe,n=>{t[n]=e[n]!==0?me.now():0;}),d(this,ie,(n,o)=>{if(e[o]){let h=e[o],l=t[o];if(!h||!l)return;n.ttl=h,n.start=l,n.now=r||s();let b=n.now-l;n.remainingTTL=h-b;}});let r=0,s=()=>{let n=me.now();if(this.ttlResolution>0){r=n;let o=setTimeout(()=>r=0,this.ttlResolution);o.unref&&o.unref();}return n};this.getRemainingTTL=n=>{let o=i(this,C).get(n);if(o===void 0)return 0;let h=e[o],l=t[o];if(!h||!l)return 1/0;let b=(r||s())-l;return h-b},d(this,W,n=>{let o=t[n],h=e[n];return !!h&&!!o&&(r||s())-o>h});},fe=new WeakMap,ie=new WeakMap,He=new WeakMap,W=new WeakMap,Xe=function(){let e=new ge(i(this,K));d(this,U,0),d(this,J,e),d(this,ce,t=>{d(this,U,i(this,U)-e[t]),e[t]=0;}),d(this,xe,(t,r,s,n)=>{if(f(this,a,H).call(this,r))return 0;if(!re(s))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(r,t),!re(s))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 s}),d(this,ve,(t,r,s)=>{if(e[t]=r,i(this,R)){let n=i(this,R)-e[t];for(;i(this,U)>n;)f(this,a,ze).call(this,true);}d(this,U,i(this,U)+e[t]),s&&(s.entrySize=r,s.totalCalculatedSize=i(this,U));});},ce=new WeakMap,ve=new WeakMap,xe=new WeakMap,se=function*({allowStale:e=this.allowStale}={}){if(i(this,T))for(let t=i(this,z);!(!f(this,a,ke).call(this,t)||((e||!i(this,W).call(this,t))&&(yield t),t===i(this,I)));)t=i(this,k)[t];},ne=function*({allowStale:e=this.allowStale}={}){if(i(this,T))for(let t=i(this,I);!(!f(this,a,ke).call(this,t)||((e||!i(this,W).call(this,t))&&(yield t),t===i(this,z)));)t=i(this,D)[t];},ke=function(e){return e!==void 0&&i(this,C).get(i(this,x)[e])===e},ze=function(e){var n;let t=i(this,I),r=i(this,x)[t],s=i(this,g)[t];return i(this,ae)&&f(this,a,H).call(this,s)?s.__abortController.abort(new Error("evicted")):(i(this,X)||i(this,M))&&(i(this,X)&&((n=i(this,B))==null||n.call(this,s,r,"evict")),i(this,M)&&i(this,O)?.push([s,r,"evict"])),i(this,ce).call(this,t),e&&(i(this,x)[t]=void 0,i(this,g)[t]=void 0,i(this,Y).push(t)),i(this,T)===1?(d(this,I,d(this,z,0)),i(this,Y).length=0):d(this,I,i(this,D)[t]),i(this,C).delete(r),Ce(this,T)._--,t},Oe=function(e,t,r,s){let n=t===void 0?void 0:i(this,g)[t];if(f(this,a,H).call(this,n))return n;let o=new Fe,{signal:h}=r;h?.addEventListener("abort",()=>o.abort(h.reason),{signal:o.signal});let l={signal:o.signal,options:r,context:s},b=(G,A=false)=>{let{aborted:y}=o.signal,N=r.ignoreFetchAbort&&G!==void 0;if(r.status&&(y&&!A?(r.status.fetchAborted=true,r.status.fetchError=o.signal.reason,N&&(r.status.fetchAbortIgnored=true)):r.status.fetchResolved=true),y&&!N&&!A)return v(o.signal.reason);let L=P;return i(this,g)[t]===P&&(G===void 0?L.__staleWhileFetching?i(this,g)[t]=L.__staleWhileFetching:f(this,a,oe).call(this,e,"fetch"):(r.status&&(r.status.fetchUpdated=true),this.set(e,G,l.options))),G},w=G=>(r.status&&(r.status.fetchRejected=true,r.status.fetchError=G),v(G)),v=G=>{let{aborted:A}=o.signal,y=A&&r.allowStaleOnFetchAbort,N=y||r.allowStaleOnFetchRejection,L=N||r.noDeleteOnFetchRejection,F=P;if(i(this,g)[t]===P&&(!L||F.__staleWhileFetching===void 0?f(this,a,oe).call(this,e,"fetch"):y||(i(this,g)[t]=F.__staleWhileFetching)),N)return r.status&&F.__staleWhileFetching!==void 0&&(r.status.returnedStale=true),F.__staleWhileFetching;if(F.__returned===F)throw G},_=(G,A)=>{var N;let y=(N=i(this,Se))==null?void 0:N.call(this,e,n,l);y&&y instanceof Promise&&y.then(L=>G(L===void 0?void 0:L),A),o.signal.addEventListener("abort",()=>{(!r.ignoreFetchAbort||r.allowStaleOnFetchAbort)&&(G(void 0),r.allowStaleOnFetchAbort&&(G=L=>b(L,true)));});};r.status&&(r.status.fetchDispatched=true);let P=new Promise(_).then(b,w),Z=Object.assign(P,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return t===void 0?(this.set(e,Z,{...l.options,status:void 0}),t=i(this,C).get(e)):i(this,g)[t]=Z,Z},H=function(e){if(!i(this,ae))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Fe},Ve=function(e,t){i(this,k)[t]=e,i(this,D)[e]=t;},_e=function(e){e!==i(this,z)&&(e===i(this,I)?d(this,I,i(this,D)[e]):f(this,a,Ve).call(this,i(this,k)[e],i(this,D)[e]),f(this,a,Ve).call(this,i(this,z),e),d(this,z,e));},oe=function(e,t){var s,n;let r=false;if(i(this,T)!==0){let o=i(this,C).get(e);if(o!==void 0)if(r=true,i(this,T)===1)f(this,a,We).call(this,t);else {i(this,ce).call(this,o);let h=i(this,g)[o];if(f(this,a,H).call(this,h)?h.__abortController.abort(new Error("deleted")):(i(this,X)||i(this,M))&&(i(this,X)&&((s=i(this,B))==null||s.call(this,h,e,t)),i(this,M)&&i(this,O)?.push([h,e,t])),i(this,C).delete(e),i(this,x)[o]=void 0,i(this,g)[o]=void 0,o===i(this,z))d(this,z,i(this,k)[o]);else if(o===i(this,I))d(this,I,i(this,D)[o]);else {let l=i(this,k)[o];i(this,D)[l]=i(this,D)[o];let b=i(this,D)[o];i(this,k)[b]=i(this,k)[o];}Ce(this,T)._--,i(this,Y).push(o);}}if(i(this,M)&&i(this,O)?.length){let o=i(this,O),h;for(;h=o?.shift();)(n=i(this,$))==null||n.call(this,...h);}return r},We=function(e){var t,r;for(let s of f(this,a,ne).call(this,{allowStale:true})){let n=i(this,g)[s];if(f(this,a,H).call(this,n))n.__abortController.abort(new Error("deleted"));else {let o=i(this,x)[s];i(this,X)&&((t=i(this,B))==null||t.call(this,n,o,e)),i(this,M)&&i(this,O)?.push([n,o,e]);}}if(i(this,C).clear(),i(this,g).fill(void 0),i(this,x).fill(void 0),i(this,V)&&i(this,q)&&(i(this,V).fill(0),i(this,q).fill(0)),i(this,J)&&i(this,J).fill(0),d(this,I,0),d(this,z,0),i(this,Y).length=0,d(this,U,0),d(this,T,0),i(this,M)&&i(this,O)){let s=i(this,O),n;for(;n=s?.shift();)(r=i(this,$))==null||r.call(this,...n);}};var Ie=Pe;var le=class{constructor(e){p(this,"cache");p(this,"map",new Map);this.cache=new Ie({max:e.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){return this.cache.clear(),this.map.clear()}delete(e){let t=this.map.delete(e);return t&&this.cache.delete(e),t}get forEach(){return this.map.forEach}get(e){let t=this.cache.get(e);return t||this.map.get(e)}has(e){return this.map.has(e)}set(e,t){return this.map.set(e,t),this.cache.set(e,t),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var Q=class Q{static get originalStepData(){return Q._originalStepData?te(Q._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){Q._originalStepData=te(e);}};p(Q,"_diffHistory",new le({cacheSize:5})),p(Q,"_stepsInfoHistory",new le({cacheSize:5})),p(Q,"_narrationHistory",new le({cacheSize:50})),p(Q,"stepLimitSaved",20),p(Q,"goBackRunning",false),p(Q,"_originalStepData");var c=Q;var Ae=class{get stepsInfoMap(){return c._stepsInfoHistory}get diffMap(){return c._diffHistory}get narrationMap(){return c._narrationHistory}get size(){return c._stepsInfoHistory.size}get lastKey(){return this.size===0?null:Math.max(...Array.from(this.keys()))}keys(){return c._stepsInfoHistory.keys()}get(e){let t=c._narrationHistory.get(e);if(!(t&&Object.keys(t).length===1&&t.stepIndex!==void 0))return t}delete(e){c._stepsInfoHistory.delete(e),c._diffHistory.delete(e),c._narrationHistory.delete(e);}internalRestoreOldGameState(e,t){if(e<=0||this.size==0)return t;let r=this.lastKey;if(typeof r!="number")return S.error("You can't go back, there is no step to go back"),t;let s=c._diffHistory.get(r);if(s)try{let n=Ke(t,s);return ee.stepCounter=r,this.delete(r),this.internalRestoreOldGameState(e-1,n)}catch(n){return S.error("Error applying diff",n),t}else return S.error("You can't go back, there is no step to go back"),t}async goBack(e,t=1){if(t<=0){S.warn("The parameter steps must be greater than 0");return}if(c._diffHistory.size<1){S.warn("You can't go back, there is no step to go back");return}if(c.goBackRunning){S.warn("Go back is already running");return}c.goBackRunning=true;try{let r=te(this.internalRestoreOldGameState(t,c.originalStepData));if(r){await ee.restoreGameStepState(r,e);let s=ee.stepCounter-1,n=c._narrationHistory.get(s);if(n&&Object.keys(n).length===1&&n.stepIndex!==void 0){let o=c._stepsInfoHistory.get(s);if(o){let h=this.itemMapper({step:o});c._narrationHistory.set(o.index,h);}}}else S.error("Error going back");c.originalStepData=r,c.goBackRunning=!1;}catch(r){S.error("Error going back",r),c.goBackRunning=false;}}add(e,t={}){let r=c.originalStepData,{ignoreSameStep:s}=t,n=ee.currentGameStepState;if(!s&&this.isSameStep(r,n))return;let o=this.lastKey;(async()=>{try{let l,b;if(typeof o=="number"&&(l=c._stepsInfoHistory.get(o),b=c._narrationHistory.get(o)),c._stepsInfoHistory.set(e.index,e),e.index!==0){let _=Te(r,n);_?c._diffHistory.set(e.index,_):S.warn("It was not possible to create the difference between the two steps");}let w={},v=this.itemMapper({step:e},w);if(c._narrationHistory.set(e.index,v),l&&b&&typeof o=="number"){let _=this.itemMapper({...w,step:l},{});c._narrationHistory.set(o,_);}}catch(l){S.error("Error adding history step",l);}})(),c.originalStepData=n;}itemMapper(e,t){let{step:r,choiceIndexMade:s,inputValue:n,removeDialogue:o}=e,h=r.dialogue||r.dialoge;t&&r.isGlued&&(t.removeDialogue=true),o&&(h=void 0);let l=r.choices;if(t&&r.currentLabel&&r.choiceIndexMade!==void 0&&(t.choiceIndexMade=r.choiceIndexMade),r.inputValue&&t&&(t.inputValue=r.inputValue),h||l||n){let b=l?.map((w,v)=>{let _=false;return w.oneTime&&r.alreadyMadeChoices&&r.alreadyMadeChoices.includes(v)&&(_=true),{text:w.text,type:w.type,isResponse:false,hidden:_}});if(b){if(b.every(w=>w.hidden)){let w=b.find(v=>v.hidden===false);w&&(w.hidden=false);}s!==void 0&&(b[s].isResponse=true);}return {dialogue:h?{...h,character:h.character?ee.getCharacter(h.character)||h.character:void 0}:void 0,playerMadeChoice:typeof s=="number",choices:b,stepIndex:r.index,inputValue:n}}return {stepIndex:r.index}}get narrativeHistory(){let e=[];return Array.from(this.keys()).sort((r,s)=>r-s).forEach(r=>{let s=this.get(r);s&&e.push(s);}),e}get currentLabelHistory(){let e=[],t=Array.from(this.keys()).sort((l,b)=>b-l);if(t.length===0)return e;let r=t[0];if(typeof r!="number")return e;let s=c._stepsInfoHistory.get(r);if(!s)return e;let n=s.openedLabels;if(!n||!Array.isArray(n)||n.length===0)return e;let o=n[0].currentStepIndex,h=n[0].label;return t.every((l,b)=>{let w=this.get(l);if(w){if(b===0)return e.push(w),true;let v=c._stepsInfoHistory.get(l);if(!v)return true;let _=v.openedLabels;if(!_||!Array.isArray(_)||_.length===0||_[0].label!==h||_[0].currentStepIndex>=o)return false;o=_[0].currentStepIndex,e.push(w);}return true}),e.reverse()}removeNarrativeHistory(e){if(e){let t=Array.from(this.keys()).sort((r,s)=>r-s);t=t.slice(0,e),t.forEach(r=>{c._narrationHistory.delete(r),c._stepsInfoHistory.delete(r),c._diffHistory.delete(r);});}else c._stepsInfoHistory.clear(),c._diffHistory.clear(),c._narrationHistory.clear();}get canGoBack(){let e=this.lastKey;return typeof e!="number"?false:c._diffHistory.has(e)}blockGoBack(){ee.currentStepsRunningNumber===0&&c._diffHistory.clear();}isSameStep(e,t){if(e.openedLabels.length===t.openedLabels.length)try{let r=JSON.stringify(e.openedLabels),s=JSON.stringify(t.openedLabels);if(r===s&&e.path===t.path&&e.labelIndex===t.labelIndex)return !0}catch(r){return S.error("Error comparing opened labels",r),true}return false}clear(){c._stepsInfoHistory.clear(),c._diffHistory.clear(),c._narrationHistory.clear(),c._originalStepData=void 0;}get stepLimitSaved(){return c.stepLimitSaved}set stepLimitSaved(e){c.stepLimitSaved=e;}export(){let e=Array.from(this.keys()).sort((r,s)=>r-s);e.length>this.stepLimitSaved&&(e=e.slice(e.length-this.stepLimitSaved));let t=[];return e.forEach(r=>{let s=c._stepsInfoHistory.get(r);if(s){let n=c._diffHistory.get(r);t.push({...s,diff:n});}}),{stepsHistory:te(t),originalStepData:te(c._originalStepData)}}restoreNarrativeHistory(){let e=Array.from(this.keys()).sort((r,s)=>r-s),t={};e.forEach(r=>{let s=c._stepsInfoHistory.get(r);if(s){let n={...t};t={};let o=this.itemMapper({step:s,choiceIndexMade:n.choiceIndexMade,inputValue:n.inputValue,removeDialogue:n.removeDialogue},t);o&&c._narrationHistory.set(r,o);}});}async restore(e){this.clear();try{e.hasOwnProperty("stepsHistory")?(e.stepsHistory.forEach(r=>{r.diff&&c._diffHistory.set(r.index,r.diff);let s={...r,diff:void 0};c._stepsInfoHistory.set(r.index,s);}),this.restoreNarrativeHistory()):S.warn("Could not import stepsHistory data, so will be ignored"),e.hasOwnProperty("originalStepData")?c._originalStepData=e.originalStepData:S.warn("Could not import originalStepData data, so will be ignored");}catch(t){S.error("Error importing data",t);}}};var kt=new Ae;exports.HistoryManagerStatic=c;exports.stepHistory=kt;