narraleaf-react 0.8.1-beta.1 → 0.8.1
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.
- package/dist/main.js +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -47,7 +47,7 @@ NarraLeaf cannot find the element with the id from the saved game`);let d={scene
|
|
|
47
47
|
NarraLeaf cannot find the element with the id from the saved game`);return l.fromData(c),l})}getLastSceneIfNot(e){let t=e||this.getLastScene();if(!t||!this.sceneExists(t))throw new b('Scene not found, please call "scene.activate()" first.');return t}createElementSnapshot(e){return{scene:e.scene,layers:new Map(Array.from(e.layers.entries()).map(([t,n])=>[t,n.map(o=>[o,o.toData()])]))}}fromElementSnapshot(e){return{scene:e.scene,layers:new Map(Array.from(e.layers.entries()).map(([t,n])=>[t,n.map(([o,i])=>(o.fromData(i),o))])),texts:[],menus:[]}}removeElements(e){let t=this.state.elements.findIndex(n=>n.scene===e);return t===-1?(this.logger.weakWarn("Scene not found when removing elements",e.getId()),this):(this.resetLayers(this.state.elements[t].layers),this.state.elements.splice(t,1),this.logger.debug("GameState","Removing elements",e.getId()),this)}resetLayers(e){e.forEach(t=>{t.forEach(n=>{n.reset()})})}createWaitableAction(e,t){return{action:e,onClick:o=>{t&&t(o)}}}sceneNotFound(){return new b("Scene not found, target scene may not be activated. This is an internal error, please report this to the developer.")}layerNotFound(){return new b("Layer not found, target layer may not be activated. You may forget to add the layer to the scene config")}constructLayerMap(e,t){return new Map(Object.entries(e).map(([n,o])=>{let i=t.get(n);if(!i)throw new b("Layer not found, id: "+n+`
|
|
48
48
|
NarraLeaf cannot find the element with the id from the saved game`);return[i,o.map(r=>{if(!t.has(r))throw new b("Displayable not found, id: "+r+`
|
|
49
49
|
NarraLeaf cannot find the element with the id from the saved game
|
|
50
|
-
This may be caused by the damage of the saved game file or the change of the story file`);return t.get(r)})]}))}};zt.EventTypes={"event:state.end":"event:state.end","event:state.player.skip":"event:state.player.skip","event:state.player.requestFlush":"event:state.player.requestFlush","event.state.onExpose":"event.state.onExpose","event:state.onRender":"event:state.onRender","event:state:flushPreloadedScenes":"event:state:flushPreloadedScenes"};var U=zt;var Ee=class s{constructor(e,t=void 0){this.liveGame=e;this.__tag=void 0;this.waitingAction=null;this.__tag=t,this.stack=new Hn().addPushValidator(n=>{let o=this.stack.peek();if(n===o)throw new ge("StackModel: Unexpected self-push in stack.");if(s.isCalledActionResult(o)){if(o.wait&&s.isStackModelsAwaiting(o.wait.type,o.wait.stackModels))throw new ge("StackModel: Unexpected waiting action in stack. (is calledActionResult: true, wait: true)")}else if(h.isAwaitable(o)&&!o.isSettled())throw new ge("StackModel: Unexpected unsettled Awaitable in stack.");if(!s.isCalledActionResult(n)&&!h.isAwaitable(n))throw new ge("StackModel: Unexpected non-CalledActionResult or Awaitable in stack.");return!0})}static isStackModel(e){return e instanceof s}static createStackModel(e,t,n){let o=new s(e);return o.deserialize(t,n),o}static isCalledActionResult(e){return!!e&&!this.isStackModel(e)&&!h.isAwaitable(e)&&"type"in e}static fromAction(e){return{type:e.type,node:e.contentNode}}static executeStackModelGroup(e,t){return e==="any"?h.any(...t.map(n=>n.execute())):h.all(...t.map(n=>n.execute()))}static isStackModelsAwaiting(e,t){if(t.length===0)throw new Error("StackModel: StackModels are empty.");return e==="any"?t.every(n=>!n.isEmpty()):t.some(n=>!n.isEmpty())}rollNext(){if(this.stack.isEmpty())return null;let e=this.stack.peek();if(h.isAwaitable(e)&&!e.isSettled())return e;if(s.isCalledActionResult(e)&&e.wait){let n=e.wait.stackModels;if(!n.length)throw new Error("StackModel: Waiting action contains empty stackModels.");if(s.isStackModelsAwaiting(e.wait.type,n))return n.forEach(o=>o.rollNext()),e}this.waitingAction=null;let t=this.stack.pop();if(h.isAwaitable(t)){let n=t.result;if(n)return this.stack.push(n),this.liveGame.getGameStateForce().logger.debug("next action (resolved awaitable)",n.node?.action),n}else return this.waitingAction=t,this.executeActions(t);return null}execute(){let e=new h,t=null,n=!1;return(async()=>{let i=0;for(;!n;){if(i++>this.liveGame.game.config.maxStackModelLoop)throw new Error("StackModel: Suspiciously long waiting loop.");if(this.stack.isEmpty()){n=!0;break}let r=this.rollNext();if(r){if(h.isAwaitable(r)){if(r.isSettled())continue;t=r,await r}else if(s.isCalledActionResult(r))if(r.wait)t=s.executeStackModelGroup(r.wait.type,r.wait.stackModels),await t;else continue}}})().then(()=>e.resolve()),e.onSkipControllerRegister(i=>{i.onAbort(()=>{t&&(n=!0,t.abort())})}),e}abortStackTop(){if(this.stack.isEmpty())return null;let e=this.stack.peek();return e&&h.isAwaitable(e)?(this.stack.pop().abort(),this.waitingAction=null):s.isCalledActionResult(e)&&e.wait&&(e.wait.stackModels.forEach(t=>t.abortStackTop()),this.waitingAction=null),this.waitingAction}getTopSync(){if(this.stack.isEmpty())return null;let e=!1;for(let t=this.stack.size()-1;t>=0;t--){let n=this.stack.get(t);if(n){if(s.isCalledActionResult(n))return n;if(e)throw new ge("StackModel: Unexpected non-CalledActionResult in stack.")}else return null;e=!0}return null}executeActions(e){if(!e.node?.action)return null;let t=this.liveGame.executeAction(this.liveGame.getGameStateForce(),e.node.action,{stackModel:this}),n=o=>o?h.isAwaitable(o)?(this.liveGame.getGameStateForce().logger.debug("next action (executed awaitable)",o),this.stack.push(o),o):o.node?.action?(this.liveGame.getGameStateForce().logger.debug("next action (executed)",o),this.stack.push(o),o):null:null;if(Array.isArray(t)){let o=null;for(let i of t){let r=n(i);r&&(o=r)}return o}else{let o=n(t);if(o)return o}return null}isWaiting(){let e=this.stack.peek();return e?h.isAwaitable(e)?!e.isSettled():s.isCalledActionResult(e)&&e.wait?s.isStackModelsAwaiting(e.wait.type,e.wait.stackModels):!1:!1}serialize(e=!0){let t=o=>{if(s.isCalledActionResult(o)){let i=o.node?.action?.getId()??null,r=o.node?.action?.type??null;return o.wait?.stackModels?{type:"link",actionType:r,action:i,stacks:o.wait.stackModels.map(a=>a.serialize()),stackWaitType:o.wait.type}:{type:"action",actionType:r,action:i}}return null},n=this.stack.map(t).filter(function(o){return o!==null});if(e&&this.waitingAction){let o=t(this.waitingAction);o&&n.push(o)}return n}reset(){this.stack.forEach(e=>{s.isCalledActionResult(e)?e.wait?.stackModels.forEach(t=>t.reset()):h.isAwaitable(e)&&e.abort()}),this.waitingAction&&this.waitingAction.wait?.stackModels.forEach(e=>e.reset()),this.waitingAction=null,this.stack.clear()}deserialize(e,t){this.reset();for(let n of e)if(n.type==="action"){if(!n.action)continue;let{actionType:o,action:i}=n,r=t.get(i);if(!r)throw new Error(`Action not found: ${i}`);this.stack.push({type:o,node:r.contentNode,wait:null})}else if(n.type==="link"){let{actionType:o,action:i,stacks:r,stackWaitType:a}=n;if(a==null)throw new Error(`Missing stackWaitType for link action: ${i}`);this.stack.push({type:o,node:i?t.get(i)?.contentNode??null:null,wait:{type:a,stackModels:r.map(c=>s.createStackModel(this.liveGame,c,t))}})}return this}isEmpty(){return this.stack.isEmpty()}push(...e){return this.stack.push(...e),this}};var st=class st{constructor(e){this.events=new K;this.story=null;this.gameLock=new Nt;this.currentSavedGame=null;this.gameState=void 0;this.stackModel=null;this.asyncStackModels=new Set;this.lastDialog=null;this.mapCache=null;this.game=e,this._storable=new an,this.initNamespaces()}initNamespaces(){return this._storable.clear().addNamespace(new it(st.GameSpacesKey.game,st.DefaultNamespaces.game)),this.story&&this.story.initPersistent(this._storable),this}getStorable(){return this._storable}get storable(){return this._storable}loadStory(e){return this.story=e.constructStory(),this}serialize(){this.assertGameState();let e=this.gameState,t=this.story;if(!t)throw new Error("No story loaded");if(!this.currentSavedGame||!this.stackModel)throw new Error("Failed when trying to serialize the game: The game has not started");let n=this._storable.toData(),o=e.toData(),i=t.getAllElementStates(),r=this.stackModel.serialize(),a=Array.from(this.asyncStackModels).map(c=>c.serialize());return{name:this.currentSavedGame.name,meta:{created:this.currentSavedGame.meta.created,updated:Date.now(),id:this.currentSavedGame.meta.id,lastSentence:this.lastDialog?.sentence||null,lastSpeaker:this.lastDialog?.speaker||null,storyHash:t.hash()},game:{store:n,stage:o,elementStates:i,stackModel:r,asyncStackModels:a,services:t.serializeServices()}}}deserialize(e){this.assertGameState();let t=this.gameState,n=this.story;if(!n)throw new Error("No story loaded");t.rollLock.lock(),this.reset(),t.stage.forceRemount();let{game:{store:o,stage:i,elementStates:r,services:a,stackModel:c,asyncStackModels:l}}=e,[d,p]=this.constructMaps();this._storable.clear().load(o),r.forEach(({id:m,data:g})=>{t.logger.debug("restore element",m);let u=p.get(m);if(!u)throw new Error("Element not found, id: "+m+`
|
|
50
|
+
This may be caused by the damage of the saved game file or the change of the story file`);return t.get(r)})]}))}};zt.EventTypes={"event:state.end":"event:state.end","event:state.player.skip":"event:state.player.skip","event:state.player.requestFlush":"event:state.player.requestFlush","event.state.onExpose":"event.state.onExpose","event:state.onRender":"event:state.onRender","event:state:flushPreloadedScenes":"event:state:flushPreloadedScenes"};var U=zt;var Ee=class s{constructor(e,t=void 0){this.liveGame=e;this.__tag=void 0;this.waitingAction=null;this.__tag=t,this.stack=new Hn().addPushValidator(n=>{let o=this.stack.peek();if(n===o)throw new ge("StackModel: Unexpected self-push in stack.");if(s.isCalledActionResult(o)){if(o.wait&&s.isStackModelsAwaiting(o.wait.type,o.wait.stackModels))throw new ge("StackModel: Unexpected waiting action in stack. (is calledActionResult: true, wait: true)")}else if(h.isAwaitable(o)&&!o.isSettled())throw new ge("StackModel: Unexpected unsettled Awaitable in stack.");if(!s.isCalledActionResult(n)&&!h.isAwaitable(n))throw new ge("StackModel: Unexpected non-CalledActionResult or Awaitable in stack.");return!0})}static isStackModel(e){return e instanceof s}static createStackModel(e,t,n){let o=new s(e);return o.deserialize(t,n),o}static isCalledActionResult(e){return!!e&&!this.isStackModel(e)&&!h.isAwaitable(e)&&"type"in e}static fromAction(e){return{type:e.type,node:e.contentNode}}static executeStackModelGroup(e,t){return e==="any"?h.any(...t.map(n=>n.execute())):h.all(...t.map(n=>n.execute()))}static isStackModelsAwaiting(e,t){if(t.length===0)throw new Error("StackModel: StackModels are empty.");return e==="any"?t.every(n=>!n.isEmpty()):t.some(n=>!n.isEmpty())}rollNext(){if(this.stack.isEmpty())return null;let e=this.stack.peek();if(h.isAwaitable(e)&&!e.isSettled())return e;if(s.isCalledActionResult(e)&&e.wait){let n=e.wait.stackModels;if(!n.length)throw new Error("StackModel: Waiting action contains empty stackModels.");if(s.isStackModelsAwaiting(e.wait.type,n))return n.forEach(o=>o.rollNext()),e}this.waitingAction=null;let t=this.stack.pop();if(h.isAwaitable(t)){let n=t.result;if(n)return this.stack.push(n),this.liveGame.getGameStateForce().logger.debug("next action (resolved awaitable)",n.node?.action),n}else return this.waitingAction=t,this.executeActions(t);return null}execute(){let e=new h,t=null,n=!1;return(async()=>{let i=0;for(;!n;){if(i++>this.liveGame.game.config.maxStackModelLoop)throw new Error("StackModel: Suspiciously long waiting loop.");if(this.stack.isEmpty()){n=!0;break}let r=this.rollNext();if(r){if(h.isAwaitable(r)){if(r.isSettled())continue;t=r,await r}else if(s.isCalledActionResult(r))if(r.wait)t=s.executeStackModelGroup(r.wait.type,r.wait.stackModels),await t;else continue}}})().then(()=>e.resolve()),e.onSkipControllerRegister(i=>{i.onAbort(()=>{t&&(n=!0,t.abort())})}),e}abortStackTop(){if(this.stack.isEmpty())return null;let e=this.stack.peek();return e&&h.isAwaitable(e)?(this.stack.pop().abort(),this.waitingAction=null):s.isCalledActionResult(e)&&e.wait&&(e.wait.stackModels.forEach(t=>t.abortStackTop()),this.waitingAction=null),this.waitingAction}getTopSync(){if(this.stack.isEmpty())return null;let e=!1;for(let t=this.stack.size()-1;t>=0;t--){let n=this.stack.get(t);if(n){if(s.isCalledActionResult(n))return n;if(e)throw new ge("StackModel: Unexpected non-CalledActionResult in stack.")}else return null;e=!0}return null}executeActions(e){if(!e.node?.action)return null;let t=this.liveGame.executeAction(this.liveGame.getGameStateForce(),e.node.action,{stackModel:this}),n=o=>o?h.isAwaitable(o)?(this.liveGame.getGameStateForce().logger.debug("next action (executed awaitable)",o),this.stack.push(o),o):o.node?.action?(this.liveGame.getGameStateForce().logger.debug("next action (executed)",o),this.stack.push(o),o):null:null;if(Array.isArray(t)){let o=null;for(let i of t){let r=n(i);r&&(o=r)}return o}else{let o=n(t);if(o)return o}return null}isWaiting(){let e=this.stack.peek();return e?h.isAwaitable(e)?!e.isSettled():s.isCalledActionResult(e)&&e.wait?s.isStackModelsAwaiting(e.wait.type,e.wait.stackModels):!1:!1}serialize(e=!0){let t=o=>{if(s.isCalledActionResult(o)){let i=o.node?.action?.getId()??null,r=o.node?.action?.type??null;return o.wait?.stackModels?{type:"link",actionType:r,action:i,stacks:o.wait.stackModels.map(a=>a.serialize()),stackWaitType:o.wait.type}:{type:"action",actionType:r,action:i}}return null},n=this.stack.map(t).filter(function(o){return o!==null});if(e&&this.waitingAction){let o=t(this.waitingAction);o&&n.push(o)}return n}reset(){this.stack.forEach(e=>{s.isCalledActionResult(e)?e.wait?.stackModels.forEach(t=>t.reset()):h.isAwaitable(e)&&e.abort()}),this.waitingAction&&this.waitingAction.wait?.stackModels.forEach(e=>e.reset()),this.waitingAction=null,this.stack.clear()}deserialize(e,t){this.reset();for(let n of e)if(n.type==="action"){if(!n.action)continue;let{actionType:o,action:i}=n,r=t.get(i);if(!r)throw new Error(`Action not found: ${i}`);this.stack.push({type:o,node:r.contentNode,wait:null})}else if(n.type==="link"){let{actionType:o,action:i,stacks:r,stackWaitType:a}=n;if(a==null)throw new Error(`Missing stackWaitType for link action: ${i}`);this.stack.push({type:o,node:i?t.get(i)?.contentNode??null:null,wait:{type:a,stackModels:r.map(c=>s.createStackModel(this.liveGame,c,t))}})}return this}isEmpty(){return this.stack.isEmpty()}push(...e){return this.stack.push(...e),this}};var st=class st{constructor(e){this.events=new K;this.story=null;this.gameLock=new Nt;this.currentSavedGame=null;this.gameState=void 0;this.stackModel=null;this.asyncStackModels=new Set;this.lastDialog=null;this.mapCache=null;this.game=e,this._storable=new an,this.initNamespaces()}initNamespaces(){return this._storable.clear().addNamespace(new it(st.GameSpacesKey.game,st.DefaultNamespaces.game)),this.story&&this.story.initPersistent(this._storable),this}getStorable(){return this._storable}get storable(){return this._storable}loadStory(e){return this.story=e.constructStory(),this}serialize(){this.assertGameState();let e=this.gameState,t=this.story;if(!t)throw new Error("No story loaded");if(!this.currentSavedGame||!this.stackModel)throw new Error("Failed when trying to serialize the game: The game has not started");let n=this._storable.toData(),o=e.toData(),i=t.getAllElementStates(),r=this.stackModel.serialize(),a=Array.from(this.asyncStackModels).map(c=>c.serialize());return{name:this.currentSavedGame.name,meta:{created:this.currentSavedGame.meta.created,updated:Date.now(),id:this.currentSavedGame.meta.id,lastSentence:this.lastDialog?.sentence||null,lastSpeaker:this.lastDialog?.speaker||null,storyHash:t.hash()},game:{store:n,stage:o,elementStates:i,stackModel:r,asyncStackModels:a,services:t.serializeServices()}}}deserialize(e){if(!e)throw new Error("No saved game provided when trying to deserialize game state");this.assertGameState();let t=this.gameState,n=this.story;if(!n)throw new Error("No story loaded");t.rollLock.lock(),this.reset(),t.stage.forceRemount();let{game:{store:o,stage:i,elementStates:r,services:a,stackModel:c,asyncStackModels:l}}=e,[d,p]=this.constructMaps();this._storable.clear().load(o),r.forEach(({id:m,data:g})=>{t.logger.debug("restore element",m);let u=p.get(m);if(!u)throw new Error("Element not found, id: "+m+`
|
|
51
51
|
NarraLeaf cannot find the element with the id from the saved game`);u.reset(),u.fromData(g)}),this.currentSavedGame=e,t.loadData(i,p),this.stackModel.deserialize(c,d),l.forEach(m=>this.asyncStackModels.add(Ee.createStackModel(this,m,d))),this.asyncStackModels.forEach(m=>t.timelines.attachTimeline(m.execute())),n.deserializeServices(a),t.events.once(U.EventTypes["event:state.onRender"],()=>{t.schedule(()=>{t.rollLock.unlock(),t.stage.next()},0)}),t.stage.forceUpdate()}getHistory(){return this.assertGameState(),this.gameState.gameHistory.getHistory()}undo(e){if(this.assertGameState(),!this.gameState.actionHistory.ableToUndo(this.gameState.gameHistory)){this.gameState.logger.warn("LiveGame.undo","No action to undo");return}let t=this.gameLock.register().lock();this.stackModel.abortStackTop();let n=e?this.gameState.actionHistory.undoUntil(e):this.gameState.actionHistory.undo(this.gameState.gameHistory);if(n){let[o]=this.constructMaps(),{rootStackSnapshot:i,stackModel:r}=n;this.stackModel.deserialize(i,o),r===this.stackModel&&this.stackModel.push(Ee.fromAction(n.action)),this.gameLock.off(t.unlock()),this.gameState.logger.info("LiveGame.undo","Undo until",e,"action",n),this.gameState.stage.forceUpdate(),this.gameState.stage.next(),this.gameState.schedule(()=>{this.gameState&&this.gameState.forceAnimation()},0)}else this.gameState.logger.warn("LiveGame.undo","No action found"),this.gameLock.off(t.unlock())}dispose(){this.events.clear(),this.gameState?.dispose()}notify(e,t=3e3){this.assertGameState();let n=this.gameState.idManager.generateId(),o=this.gameState.notificationMgr.consume({id:n,message:e,duration:t}),i=h.toPromiseForce(o);return{cancel:()=>{o.abort()},promise:i}}skipDialog(){this.assertGameState(),this.gameState.events.emit(U.EventTypes["event:state.player.skip"],!0)}assertScreenshot(){this.assertGameState(),this.assertPlayerElement()}capturePng(){return this.assertScreenshot(),this.gameState.htmlToImage.toPng(this.gameState.mainContentNode,this.getScreenshotOptions())}captureJpeg(){return this.assertScreenshot(),this.gameState.htmlToImage.toJpeg(this.gameState.mainContentNode,this.getScreenshotOptions())}captureSvg(){return this.assertScreenshot(),this.gameState.htmlToImage.toSvg(this.gameState.mainContentNode,this.getScreenshotOptions())}capturePngBlob(){return this.assertScreenshot(),this.assertGameState(),this.assertPlayerElement(),this.gameState.htmlToImage.toBlob(this.gameState.mainContentNode,this.getScreenshotOptions())}onCharacterPrompt(e){return this.events.on(st.EventTypes["event:character.prompt"],e)}onMenuChoose(e){return this.events.on(st.EventTypes["event:menu.choose"],e)}newGame(){this.assertGameState();let e=this.gameState,t=e.logger.group("LiveGame (newGame)",!0);this.reset(),this.initNamespaces();let n=this.getNewSavedGame();n.name="NewGame-"+Date.now(),this.currentSavedGame=n;let o=this.story?.entryScene?.getSceneRoot();o?this.stackModel.push(Ee.fromAction(o)):e.logger.warn("No scene root found");let i=this.story?.getAllElementMap(this.story,this.story?.entryScene?.getSceneRoot()||[]);return i?i.forEach(r=>{e.logger.debug("reset element",r),r.reset()}):e.logger.warn("No elements found"),e.stage.forceUpdate(),e.stage.next(),t.end(),this}waitForRouterExit(){let e=null;return{promise:new Promise(t=>{e=this.game.router.onceExitComplete(()=>{t()})}),cancel:()=>{e&&e.cancel()}}}waitForPageMount(){let e=null;return{promise:new Promise(t=>{e=this.game.router.oncePageMount(()=>{t()})}),cancel:()=>{e&&e.cancel()}}}requestFullScreen(e){this.assertGameState();let t="LiveGame.requestFullScreen";try{let n=this.gameState.playerCurrent;if(!n){this.gameState.logger.warn(t,"No player element found");return}if(n.requestFullscreen)return n.requestFullscreen(e);this.gameState.logger.warn(t,"Fullscreen is not supported")}catch(n){this.gameState.logger.error(t,n)}}exitFullScreen(){this.assertGameState();let e="LiveGame.exitFullScreen";try{if(document.exitFullscreen)return document.exitFullscreen();this.gameState.logger.warn(e,"Fullscreen is not supported")}catch(t){this.gameState.logger.error(e,t)}}constructMaps(){let e=this.story;if(!e)throw new Error("No story loaded");if(this.mapCache)return this.mapCache;let t=new Map,n=new Map;return e.forEachChild(e,e.entryScene?.getSceneRoot()||[],o=>{t.set(o.getId(),o),n.set(o.callee.getId(),o.callee)},{allowFutureScene:!0}),this.mapCache=[t,n],this.mapCache}getScreenshotOptions(){return{quality:this.game.config.screenshotQuality}}onPlayerEvent(e,t,n){this.assertPlayerElement();let o=this.gameState.playerCurrent;return o?(o.addEventListener(e,t,n),{cancel:()=>o.removeEventListener(e,t,n)}):(this.gameState.logger.warn("LiveGame.onEvent","No player element found"),{cancel:()=>{}})}onWindowEvent(e,t,n){return window.addEventListener(e,t,n),{cancel:()=>window.removeEventListener(e,t,n)}}reset(){this.assertGameState();let e=this.gameState;this.resetStackModels(),this.stackModel.reset(),this.currentSavedGame=null,this.lastDialog=null,e.forceReset()}next(){this.assertGameState();let e=this.gameState;if(this.gameLock.isLocked())return this.gameLock;if(!this.story)throw new Error("No story loaded");return this.stackModel.isEmpty()?(e.logger.weakWarn("LiveGame","No current action"),this.currentSavedGame?e.events.emit("event:state.end"):this.currentSavedGame=null,null):this.stackModel.rollNext()}setLastDialog(e,t){this.lastDialog={sentence:e,speaker:t}}requestAsyncStackModel(e){this.assertGameState();let t=new Ee(this);return this.asyncStackModels.add(t),t.push(...e),t}createStackModel(e){let t=new Ee(this);return t.push(...e),t}resetStackModels(){this.asyncStackModels.forEach(e=>e.reset()),this.asyncStackModels.clear()}isPlaying(){return this.stackModel&&!this.stackModel.isEmpty()}executeAction(e,t,n){if(!this.stackModel)throw new Error("Stack model is not initialized");let o=t.executeAction(e,n);return h.isAwaitable(o)?o:o||null}setGameState(e){if(e&&this.gameState)throw new ge("GameState already set");return this.gameState=e,e&&!this.stackModel&&(this.stackModel=new Ee(this,"$root")),this}getGameState(){return this.gameState}getGameStateForce(){if(!this.gameState)throw new ge("GameState not set");return this.gameState}getAllPredictableActions(e,t,n){let o=t?.contentNode||null,i=[],r=[],a=new Set;for(;(o||r.length)&&!(n&&i.length>=n);){if(o||(o=r.pop().contentNode),[gt].some(c=>o?.action&&o.action instanceof c)){o=null;continue}if(o.action&&o.action.is(se,_.jumpTo)){let[c]=o.action.contentNode.getContent(),l=e.getScene(c);if(!l)throw o.action._sceneNotFoundError(o.action.getSceneName(c));if(a.has(l)){o=null;continue}a.add(l),o=l.getSceneRoot()?.contentNode||null;continue}else if(o.action&&o.action.is(ee,We.do)){let[c]=o.action.contentNode.getContent();o.getChild()?.action&&r.push(o.getChild().action),o=c[0]?.contentNode||null}o.action&&i.push(o.action),o=o.getChild()}return i}clearMainStack(){if(!this.stackModel)throw new ge("No stack model found");return this.stackModel.reset(),this}getStackModelForce(){if(!this.stackModel)throw new ge("No stack model found");return this.stackModel}getNewSavedGame(){return{name:"",meta:{created:Date.now(),updated:Date.now(),id:Oi(),lastSentence:null,lastSpeaker:null,storyHash:this.story?.hash()||""},game:{store:{},stage:{scenes:[],audio:{sounds:[],groups:[]},videos:[]},elementStates:[],services:{},stackModel:[],asyncStackModels:[]}}}assertGameState(){if(!this.gameState)throw new b("No game state found, make sure you call this method in effect hooks or event handlers")}assertPlayerElement(){if(this.assertGameState(),!this.gameState.playerCurrent)throw new b("Player Element Not Mounted")}};st.DefaultNamespaces={game:{}},st.GameSpacesKey={game:"game"},st.EventTypes={"event:character.prompt":"event:character.prompt","event:menu.choose":"event:menu.choose"};var yt=st;var un=class un{constructor(e){this.settings=e;this.events=new K;this.events.setMaxListeners(64)}setPreference(e,t){this.settings[e]=t,this.events.emit(un.EventTypes["event:game.preference.change"],e,t)}getPreference(e){return this.settings[e]}getPreferences(){return this.settings}onPreferenceChange(e,t){return this.events.on(un.EventTypes["event:game.preference.change"],(n,o)=>{typeof e=="string"?e===n&&t&&t(o):e(n,o)})}importPreferences(e){for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&this.setPreference(t,e[t])}exportPreferences(){let e={};for(let t in this.settings)Object.prototype.hasOwnProperty.call(this.settings,t)&&(e[t]=this.settings[t]);return e}togglePreference(e){if(typeof this.settings[e]!="boolean")throw new Error(`Preference ${e} is not a boolean`);this.setPreference(e,!this.getPreference(e))}};un.EventTypes={"event:game.preference.change":"event:game.preference.change"};var pn=un;import"client-only";import Tr,{useEffect as ua,useRef as ai}from"react";import"client-only";import Xi,{useContext as as,useState as cs}from"react";var Ji=Xi.createContext(null);function Yi({children:s,game:e}){"use client";let t=new q({}),[n]=cs(e||t);return Xi.createElement(Ji,{value:n},s)}function w(){let s=as(Ji);if(!s)throw new Error("useGame must be used within a GameProvider");return s}import ls,{createContext as us,useContext as Zi}from"react";var _i="/",ao=class ao{constructor(e,t=ao.rootPath){this.events=new K;this.currentPath="";this.currentQuery={};this.history=[];this.historyIndex=-1;this.mountedPaths=new Set;this.defaultHandlerPaths=new Set;this.unmountingPaths=new Set;this.updateSyncHooks=new Set;this.transitioning=!1;this.game=e;let{path:n,query:o}=this.parseUrl(t);this.currentPath=n,this.currentQuery=o,this.history.push(t),this.historyIndex=0}getCurrentPath(){return this.currentPath}getPathname(){return this.currentPath}getCurrentQuery(){return{...this.currentQuery}}getQueryParams(){return this.getCurrentQuery()}getCurrentUrl(){return this.buildUrl(this.currentPath,this.currentQuery)}parseUrl(e){let[t,n]=e.split("?"),o={};if(n){let i=n.split("&");for(let r of i){let[a,c]=r.split("=");a&&(o[decodeURIComponent(a)]=c?decodeURIComponent(c):"")}}return{path:t||"/",query:o}}buildUrl(e,t){if(Object.keys(t).length===0)return e;let n=Object.entries(t).map(([o,i])=>`${encodeURIComponent(o)}=${encodeURIComponent(i)}`).join("&");return`${e}?${n}`}getQueryParam(e){return this.currentQuery[e]}setQueryParam(e,t){return this.currentQuery[e]=t,this.updateHistory(),this.emitOnChange(),this}setQueryParams(e){return Object.assign(this.currentQuery,e),this.updateHistory(),this.emitOnChange(),this}removeQueryParam(e){return delete this.currentQuery[e],this.updateHistory(),this.emitOnChange(),this}clearQueryParams(){return this.currentQuery={},this.updateHistory(),this.emitOnChange(),this}hasQueryParam(e){return e in this.currentQuery}getQueryParamKeys(){return Object.keys(this.currentQuery)}getQueryParamCount(){return Object.keys(this.currentQuery).length}getHistory(){return[...this.history]}getHistoryIndex(){return this.historyIndex}canGoBack(){return this.historyIndex>0}canGoForward(){return this.historyIndex<this.history.length-1}navigate(e,t){let{path:n,query:o}=this.parseUrl(e),i=this.resolvePath(n),r={...o,...t};if(this.currentPath===i)return this.currentQuery=r,this.historyIndex>=0&&(this.history[this.historyIndex]=this.buildUrl(i,r)),this.emitOnChange(),this;this.historyIndex<this.history.length-1&&(this.history.length=this.historyIndex+1);let a=this.buildUrl(i,r);return this.history.push(a),this.history.length>this.game.config.maxRouterHistory&&(this.history.shift(),this.historyIndex--),this.historyIndex++,this.currentPath=i,this.currentQuery=r,this.emitOnChange(),this.requestPageTransition(),this}back(){if(this.canGoBack()){this.historyIndex--;let{path:e,query:t}=this.parseUrl(this.history[this.historyIndex]);this.currentPath=e,this.currentQuery=t,this.emitOnChange(),this.requestPageTransition()}return this}forward(){if(this.canGoForward()){this.historyIndex++;let{path:e,query:t}=this.parseUrl(this.history[this.historyIndex]);this.currentPath=e,this.currentQuery=t,this.emitOnChange(),this.requestPageTransition()}return this}replace(e,t){let{path:n,query:o}=this.parseUrl(e),i=this.resolvePath(n),r={...o,...t};return this.currentPath=i,this.currentQuery=r,this.historyIndex>=0?this.history[this.historyIndex]=this.buildUrl(i,r):(this.history.push(this.buildUrl(i,r)),this.historyIndex=0),this.emitOnChange(),this}clear(){return this.currentPath="",this.currentQuery={},this.history=[],this.historyIndex=-1,this.emitOnChange(),this.requestPageTransition(),this}cleanHistory(){return this.history=this.currentPath?[this.buildUrl(this.currentPath,this.currentQuery)]:[],this.historyIndex=this.currentPath?0:-1,this}parsePath(e){return e.split("/").filter(t=>t.length>0)}buildPath(e){return"/"+e.join("/")}getParentPath(e){let t=this.parsePath(e);return t.length<=1?"":this.buildPath(t.slice(0,-1))}matchPath(e,t){let n=this.parsePath(e),o=this.parsePath(t);if(n.length<o.length)return!1;for(let i=0;i<o.length;i++){let r=n[i],a=o[i];if(a!=="*"){if(a.startsWith(":"))continue;if(r!==a)return!1}}return!0}exactMatch(e,t){let n=this.parsePath(e),o=this.parsePath(t);if(n.length!==o.length)return!1;for(let i=0;i<o.length;i++){let r=n[i],a=o[i];if(a!=="*"){if(a.startsWith(":"))continue;if(r!==a)return!1}}return!0}extractParams(e,t){let n={},o=this.parsePath(e),i=this.parsePath(t);if(o.length!==i.length)return n;for(let r=0;r<i.length;r++){let a=i[r];if(a.startsWith(":")){let c=a.slice(1);n[c]=o[r]}}return n}onExitComplete(e){return this.events.on("event:router.onExitComplete",e)}onceExitComplete(e){return this.events.once("event:router.onExitComplete",e)}onPageMount(e){return this.events.on("event:router.onPageMount",e)}oncePageMount(e){return this.events.once("event:router.onPageMount",e)}onUpdate(e){return this.updateSyncHooks.add(e),{cancel:()=>{this.updateSyncHooks.delete(e)}}}emitUpdateSync(){this.updateSyncHooks.forEach(e=>e())}mount(e){if(this.mountedPaths.has(e))throw new b(`Path ${e} is already mounted. This may be caused by multiple capture segments in the same path.`);return this.mountedPaths.add(e),{cancel:()=>{this.unmount(e)}}}unmount(e){this.mountedPaths.delete(e)}mountDefaultHandler(e){if(this.defaultHandlerPaths.has(e))throw new b(`Default handler path ${e} is already mounted.`);return this.defaultHandlerPaths.add(e),{cancel:()=>{this.unmountDefaultHandler(e)}}}unmountDefaultHandler(e){this.defaultHandlerPaths.delete(e)}emitOnPageMount(){this.events.emit("event:router.onPageMount")}onRootExitComplete(e){return this.events.on("event:router.onExitComplete",e)}isActive(){return this.currentPath!==""}onChange(e){return this.events.on("event:router.onChange",e)}emitOnChange(){this.events.emit("event:router.onChange")}resolvePath(e){let t=e.split("?")[0];if(t.startsWith("/"))return t;if(t==="")return this.currentPath;let n=this.parsePath(this.currentPath),o=t.split("/"),i=[];i.push(...n);for(let r=0;r<o.length;r++){let a=o[r];a===""||a==="."||(a===".."?i.length>0&&i.pop():i.push(a))}return this.buildPath(i)}normalizePath(e){let t=e.replace(/\/\/+/g,"/").replace(/\/$/,"");return t===""?"/":(t.startsWith("/"),t)}joinPath(e,...t){let n=this.normalizePath(e),r=[n.startsWith("/")?n:"/"+n,...t.filter(a=>a.length>0)].join("/");return this.normalizePath(r)}updateHistory(){this.historyIndex>=0&&(this.history[this.historyIndex]=this.buildUrl(this.currentPath,this.currentQuery))}requestPageTransition(){let e=()=>{this.transitioning=!0,this.emitUpdateSync(),this.emitOnChange()},t=()=>{this.events.emit("event:router.onTransitionEnd"),this.transitioning=!1,this.emitUpdateSync(),this.emitOnChange(),this.events.emit("event:router.onExitComplete")};if(e(),this.isPathsUnmounting()){let n=this.events.on("event:router.onPathUnmount",()=>{this.isPathsUnmounting()||(n.cancel(),Ie(()=>{t()}))})}else Ie(()=>{t()})}registerUnmountingPath(e){this.unmountingPaths.add(e)}isPathsUnmounting(){return this.unmountingPaths.size>0}unregisterUnmountingPath(e){this.unmountingPaths.delete(e),this.events.emit("event:router.onPathUnmount")}isTransitioning(){return this.transitioning}createToken(e){return Symbol(e)}};ao.rootPath=_i;var Tt=ao,Jo=us(null);function er({children:s}){let e=w();return ls.createElement(Jo,{value:{router:e.router}},s)}function Je(){if(!Zi(Jo))throw new Error("useRouter must be used within a RouterProvider");return Zi(Jo).router}import nr from"react";import ys from"clsx";import ps,{createContext as ms,useContext as ds,useEffect as fs,useReducer as gs,useState as hs}from"react";var at=class at{constructor(){this.state={width:0,height:0,minWidth:800,minHeight:450,paused:!1,scale:0};this.events=new K().setMaxListeners(1/0);this.lockers=[];this.updater=null}update(e,t,n){this.state.width=e,this.state.height=t,this.state.scale=n,this.events.emit(at.EventTypes["event:aspectRatio.update"],e,t)}updateMin(e,t){this.state.minWidth=e,this.state.minHeight=t}lock(){let e=Symbol();return this.lockers.push(e),e}unlock(e){if(e&&!this.lockers.includes(e))throw new Error("Locker not found");return this.lockers=this.lockers.filter(t=>t!==e),this.triggerUpdate(),null}isLocked(){return!!this.lockers.length}getStyle(){return{width:`${this.state.width}px`,height:`${this.state.height}px`}}setUpdate(e){this.updater=e}pause(){this.state.paused=!0,this.events.emit(at.EventTypes["event:aspectRatio.pause"])}resume(){this.state.paused=!1,this.events.emit(at.EventTypes["event:aspectRatio.resume"])}onUpdate(e){return this.events.on(at.EventTypes["event:aspectRatio.update"],e).cancel}requestUpdate(){this.events.emit(at.EventTypes["event:aspectRatio.requestUpdate"])}onRequestedUpdate(e){return this.events.on(at.EventTypes["event:aspectRatio.requestUpdate"],e).cancel}triggerUpdate(){this.updater&&this.updater()}};at.EventTypes={"event:aspectRatio.update":"event:aspectRatio.update","event:aspectRatio.pause":"event:aspectRatio.pause","event:aspectRatio.resume":"event:aspectRatio.resume","event:aspectRatio.requestUpdate":"event:aspectRatio.requestUpdate"};var Yo=at,Zo=ms(null);function tr({children:s}){"use client";let[e]=hs(()=>new Yo);return ps.createElement(Zo,{value:{ratio:e}},s)}function Y(){let s=ds(Zo),[,e]=gs(n=>n+1,0);if(!Zo||!s)throw new Error("useRatio must be used within a RatioProvider");let{ratio:t}=s;return fs(()=>t.onUpdate(()=>{e()}),[]),s}function Ye({children:s,className:e,style:t,ref:n,...o}){let{ratio:i}=Y(),r=i.getStyle();return nr.createElement("div",{className:ys("inset-0",e),style:{width:"100%",height:"100%",minWidth:`${i.state.minWidth}px`,minHeight:`${i.state.minHeight}px`},...o},nr.createElement("div",{style:{...r,position:"relative",...t||{}},...o||{},ref:n},s))}import Ts,{useEffect as Ss}from"react";function ze(s){let e=w(),[t,n]=Ts.useState(e.preference.getPreference(s)),o=i=>{e.preference.setPreference(s,i),n(i)};return Ss(()=>e.preference.onPreferenceChange(s,n).cancel,[s,e.preference,n]),[t,o]}import _o from"react";import co from"react";import or from"clsx";function lo({children:s,className:e,style:t,...n}){let{ratio:o}=Y(),i=w();return co.createElement(Ye,{className:or("absolute pointer-events-none w-full h-full"),style:{transform:`scale(${o.state.scale})`,transformOrigin:"left top",width:i.config.width,height:i.config.height,pointerEvents:"none"},"data-element-type":"full",...n},co.createElement("div",{className:"absolute inset-0 w-full h-full"},co.createElement("div",{className:"inset-0 w-full h-full"},co.createElement("div",{className:or("pointer-events-auto-rest",e),style:t},s))))}function bs({children:s,className:e,style:t}){return _o.createElement(_o.Fragment,null,_o.createElement(lo,{style:t,className:e,"data-element-type":"stage","data-code-source":"Stage.tsx"},s))}import ir from"clsx";import rr from"react";function uo({className:s,children:e,...t}){let{ratio:n}=Y();return rr.createElement("div",{style:{transform:`scale(${n.state.scale})`,transformOrigin:"left top"},className:ir("w-full h-full")},rr.createElement("div",{className:ir("z-20",s),...t},e))}import Hs from"clsx";import go,{useEffect as Us,useLayoutEffect as Ks,useRef as Fs,useState as Ws}from"react";import po from"react";var ei=po.createContext(null);function sr(){let s=po.useContext(ei);if(!s)throw new Error("useUIMenuContext must be used within a UIMenuContext");return s}var ti=po.createContext(null);function ar(){let s=po.useContext(ti);if(!s)throw new Error("useUIListContext must be used within a UIListContext");return s}import Ue,{useState as cr}from"react";import{motion as vs}from"motion/react";function mo({children:s,border:e="solid",color:t="red",tag:n,borderWidth:o=1,as:i="div",ref:r,...a}){let c=w(),[l,d]=cr(!1);if(!c.config.app.inspector)return Ue.createElement(i,{...a,ref:r},s);let p={...a,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),style:{...a.style||{},outline:`${o}px ${e} ${t}`,zIndex:l?1e3:"auto"}};return Ue.createElement(i,{...p,ref:r},n&&l&&Ue.createElement("span",{className:"absolute top-0 left-0 bg-white text-black border-2 border-black text-sm"},n),s)}function As({border:s="solid",color:e="red",tag:t,borderWidth:n=1,as:o="img",...i}){let r=w(),[a,c]=cr(!1);if(!r.config.app.inspector)return Ue.createElement(o,{...i});let l={...i,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),style:{...i.style||{},outline:`${s} ${n}px ${e}`,zIndex:a?1e3:"auto"}};return Ue.createElement("div",null,Ue.createElement(o,{...l}),t&&a&&Ue.createElement("span",{className:"absolute top-0 left-0 bg-white text-black border-2 border-black"},t))}function Cs(s){return Ue.createElement(mo,{...s,as:"div"})}function xs(s){return Ue.createElement(mo,{...s,as:"span"})}function ws(s){return Ue.createElement(As,{...s,as:"img"})}function ks(s){return Ue.createElement(mo,{...s,as:"button"})}function Ps(s){return Ue.createElement(mo,{...s,as:vs.div,ref:s.ref,layout:s.layout})}var Es={Div:Cs,Span:xs,Button:ks,Img:ws,mDiv:Ps},Dt=Es;import pr from"clsx";import Rt,{useEffect as oi,useRef as Ms,useState as Gs}from"react";import{useEffect as Ds,useState as Rs}from"react";function $(s){let[e,t]=Rs(0);Ds(()=>{n()},s??[]);function n(){t(o=>o+1)}return[n,e]}import lr from"react";var ni=lr.createContext(null);function ct(){let s=lr.useContext(ni);if(!s)throw new Error("useDialogContext must be used within a DialogContext");return s}import fo,{useLayoutEffect as ur,useMemo as Ls,useState as Is}from"react";var $e=class $e{constructor(e){this.events=new K;this._forceSkipped=!1;this._idle=!1;this.config=e,this._state="pending",this.autoForwardScheduler=new In,this._count=0}get state(){return this._state}get deps(){return[this._count]}isIdle(){return this._idle}setIdle(e){this._idle=e}requestComplete(){this.state==="ended"?this.safeEmit($e.Events.complete):this.safeEmit($e.Events.requestComplete)}forceSkip(){this.state==="ended"?this.emitComplete():(this._forceSkipped=!0,this.safeEmit($e.Events.forceSkip))}dispatchComplete(){if(this.state==="ended"){this.config.gameState.logger.weakWarn("DialogState","Dialog is already ended. Cannot dispatch complete.");return}if(!this.events.hasListeners($e.Events.complete)){this.config.gameState.logger.weakWarn("DialogState","No listener for complete event. Cannot dispatch complete.");return}let e=this.config.gameState.game.preference;return this._state="ended",e.getPreference(q.Preferences.autoForward)&&this.scheduleAutoForward(),this.emitComplete(),this}emitComplete(){return this.safeEmit($e.Events.complete),this.emitFlush(),this}isEnded(){return this.state==="ended"}setPause(e){this.isEnded()||(e?this._state="paused":this._state="pending")}isForceSkipped(){return this._forceSkipped}tryScheduleAutoForward(){this.isEnded()&&this.scheduleAutoForward()}cancelAutoForward(){this.autoForwardScheduler.cancelTask()}emitFlush(){return this._count++,this.events.emit($e.Events.onFlush),this}onFlush(e){return this.events.on($e.Events.onFlush,e)}safeEmit(e,...t){return this.events.emit(e,...t)===0&&this.config.gameState.logger.weakWarn("DialogState",`Failed to emit event: ${e}. Target Component is not mounted.`),this}scheduleAutoForward(){let e=this.config.gameState.game.preference;!e.getPreference(q.Preferences.autoForward)||this.state!=="ended"||this.autoForwardScheduler.cancelTask().scheduleTask(()=>{this.events.emit($e.Events.simulateClick)},this.config.gameState.game.config.autoForwardDelay/e.getPreference(q.Preferences.gameSpeed))}};$e.Events={requestComplete:"event:dialog.requestComplete",complete:"event:dialog.complete",forceSkip:"event:dialog.forceSkip",onFlush:"event:dialog.onFlush",simulateClick:"event:dialog.simulateClick"};var De=$e;function mn({action:s,onFinished:e,useTypeEffect:t=!0,gameState:n}){let o=Ls(()=>s.sentence?.evaluate(He.getCtx({gameState:n})),[s.sentence,n]),[i]=Is(()=>new De({useTypeEffect:t,action:s,evaluatedWords:o||[],gameState:n})),r=n.game.config.dialog;return ur(()=>(n.logger.debug("NarraLeaf-React: Say","dialogState",i),i.events.on(De.Events.complete,a=>{n.logger.log("NarraLeaf-React: Say","Complete",i.isIdle()),i.isIdle()||a?e?.(!1):i.setIdle(!0)}).cancel),[i]),ur(()=>n.events.on(U.EventTypes["event:state.player.skip"],a=>{a?(i.setIdle(!0),i.forceSkip()):i.isIdle()?e?.(!0):i.forceSkip()}).cancel,[i]),fo.createElement(fo.Fragment,null,fo.createElement(ni,{value:i,key:s.id},fo.createElement(r,null)))}function*mr(s){let e=[...s];for(let t=0;t<e.length;t++){let n=e[t];if(Te.isPause(n.text)){yield Te.from(n.text);continue}for(let o=0;o<n.text.length;o++){let i=n.text[o];i===`
|
|
52
52
|
`?yield`
|
|
53
53
|
`:yield{text:i,config:n.config,tag:t,tag2:o,cps:n.config.cps}}}}function dr({defaultColor:s,className:e,style:t,dialog:n,...o}){let i=w(),r=i.getLiveGame().getGameState(),a=Ms(null),[c,l]=Gs(()=>n&&!n.config.useTypeEffect?g(n.config.evaluatedWords):[]),[d,p]=$();if(!n)throw new Error("Dialog state is required");oi(()=>{if(!(!n.config.action.sentence||a.current))return r.logger.info("Initializing the sentence",n,a.current),r.schedule(({onCleanup:f})=>{if(!n.config.useTypeEffect){n.dispatchComplete();return}l([]),a.current=m(),d(),a.current.onComplete(()=>{n.dispatchComplete()}),f(()=>{a.current?.timeline?.abort()})},0)},[]),oi(()=>n.events.depends([n.events.on(De.Events.requestComplete,()=>{a.current?.interact()}),n.events.on(De.Events.forceSkip,()=>{n.isEnded()||a.current?.forceSkip()})]).cancel,[n,p]),oi(()=>i.preference.events.depends([i.preference.onPreferenceChange(q.Preferences.gameSpeed,()=>{a.current?.update()}),i.preference.onPreferenceChange(q.Preferences.autoForward,()=>{a.current?.update()}),i.preference.onPreferenceChange(q.Preferences.cps,()=>{a.current?.update()})]).cancel,[]);function m(){let f=new h,A=new re(f).setGuard(r.guard),G=new Set,he=new Set,_e=new Set,Mt=mr(n.config.evaluatedWords),Ke=null,bt=[],Fe=[],pt=()=>{bt.forEach(P=>P()),bt.length=0},et=()=>{if(Fe.length!==0)return{done:!1,value:Fe.shift()};let{done:P,value:E}=Mt.next();return{done:P,value:E}},ne=P=>{let E=X=>{P(X),he.delete(E)};return he.add(E),{cancel:()=>{he.delete(E)}}},k=P=>{l(E=>{let X=E[E.length-1];return X&&X!==`
|