UNPKG

@drincs/pixi-vn-ink

Version:

Pixi'VN gives you the ability to write your own narrative using Ink

3 lines (2 loc) 48.5 kB
import {a,h,e}from'./chunk-CYMNGEOH.mjs';import {createExportableElement,PixiError}from'@drincs/pixi-vn';import {canvas,VideoSprite,showVideo,Assets,Text,showText,ImageSprite,showImage,ImageContainer,showImageContainer,shakeEffect,pushOut,zoomOut,moveOut,removeWithDissolve,removeWithFade,pushIn,zoomIn,moveIn,showWithDissolve,showWithFade}from'@drincs/pixi-vn/canvas';import {NarrationManagerStatic,narration,RegisteredLabels,LabelAbstract}from'@drincs/pixi-vn/narration';import {sound}from'@drincs/pixi-vn/sound';import {storage}from'@drincs/pixi-vn/storage';import {RegisteredCharacters}from'@drincs/pixi-vn/characters';import {ZodType}from'zod';var ze=Object.defineProperty,Ie=(t,e,r)=>e in t?ze(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,J=(t,e,r)=>Ie(t,typeof e!="symbol"?e+"":e,r),L;(t=>(t.log=(e,...r)=>console.log(`[Pixi\u2019VN Json] ${e}`,...r),t.warn=(e,...r)=>console.warn(`[Pixi\u2019VN Json] ${e}`,...r),t.error=(e,...r)=>console.error(`[Pixi\u2019VN Json] ${e}`,...r),t.info=(e,...r)=>console.info(`[Pixi\u2019VN Json] ${e}`,...r)))(L||(L={}));var E=class A{static init(e){e.loadAssets&&(A._loadAssets=e.loadAssets),e.soundOperation&&(A._soundOperation=e.soundOperation),e.imageOperation&&(A._imageOperation=e.imageOperation),e.videoOperation&&(A._videoOperation=e.videoOperation),e.imageContainerOperation&&(A._imageContainerOperation=e.imageContainerOperation),e.textOperation&&(A._textOperation=e.textOperation),e.canvasElementOperation&&(A._canvasElementOperation=e.canvasElementOperation),e.setStorageValue&&(A._setStorageValue=e.setStorageValue),e.setInitialStorageValue&&(A._setInitialStorageValue=e.setInitialStorageValue),e.narrationOperation&&(A._narrationOperation=e.narrationOperation),e.effectOperation&&(A._effectOperation=e.effectOperation),e.animateOperation&&(A._animateOperation=e.animateOperation),e.getLogichValue&&(A._getLogichValue=e.getLogichValue),e.getConditionalStep&&(A._getConditionalStep=e.getConditionalStep);}static get loadAssets(){return A._loadAssets}static get soundOperation(){return A._soundOperation}static get imageOperation(){return A._imageOperation}static get videoOperation(){return A._videoOperation}static get imageContainerOperation(){return A._imageContainerOperation}static get textOperation(){return A._textOperation}static get canvasElementOperation(){return A._canvasElementOperation}static get setStorageValue(){return A._setStorageValue}static get setInitialStorageValue(){return A._setInitialStorageValue}static get narrationOperation(){return A._narrationOperation}static get effectOperation(){return A._effectOperation}static get animateOperation(){return A._animateOperation}static get getLogichValue(){return A._getLogichValue}static get getConditionalStep(){return A._getConditionalStep}};J(E,"_loadAssets",()=>{}),J(E,"_soundOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_imageOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_videoOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_imageContainerOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_textOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_canvasElementOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_setStorageValue",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_setInitialStorageValue",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_narrationOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_effectOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_animateOperation",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_getLogichValue",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),J(E,"_getConditionalStep",()=>{throw L.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")});var s=E;var $e=Object.defineProperty,Je=(t,e,r)=>e in t?$e(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,oe=(t,e,r)=>Je(t,typeof e!="symbol"?e+"":e,r);function Be(t,e={}){let r="";return t.values.forEach(a=>{if(typeof a=="string")r+=a;else {let n=s.getLogichValue(a,e);r+=`${n}`;}}),r}var Q=class y{static t(e){return Array.isArray(e)?e.map(r=>y.translate(`${r}`)):y.translate(`${e}`)}static set beforeToTranslate(e){y._beforeToTranslate=e;}static set translate(e){y._translate=e;}static get translate(){return e=>{let r=e;return y._beforeToTranslate&&(r=y._beforeToTranslate(r)),r=y._translate(r),y._afterToTranslate&&(r=y._afterToTranslate(r)),r}}static set afterToTranslate(e){y._afterToTranslate=e;}static addKey(e,r,a){let n=a.defaultValue||"empty_string";typeof r=="string"&&(r=[r]),Array.isArray(r)&&r.forEach(o=>{e[o]===void 0&&(n==="empty_string"?e[o]="":n==="copy_key"&&(y._beforeToTranslate?e[o]=y._beforeToTranslate(o):e[o]=o));});}static getConditionalsThenElse(e,r=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&y.getConditionalsThenElse(e.then,r),e.else&&y.getConditionalsThenElse(e.else,r);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(a=>{y.getConditionalsThenElse(a,r);});else if(e.elements.type==="ifelse"){let a=[];y.getConditionalsThenElse(e.elements,a),a.forEach(n=>{r.push(...n);});}else if(e.elements.type==="stepswitch"){let a=[];y.getConditionalsThenElse(e.elements,a),a.forEach(n=>{r.push(...n);});}else y.getConditionalsThenElse(e.elements,r);}else e.type==="resulttocombine"?(e.firstItem&&y.getConditionalsThenElse(e.firstItem,r),e.secondConditionalItem&&e.secondConditionalItem.forEach(a=>{y.getConditionalsThenElse(a,r);})):r.push(e);else e&&r.push(e);return r}static async generateJsonTranslation(e,r={},a={}){let{defaultValue:n="copy_key",operationStringConvert:o}=a,d=e.map(async v=>{if(v.choices){let p=[];Array.isArray(v.choices)?p=[v.choices]:p=y.getConditionalsThenElse(v.choices),p.forEach(f=>f.forEach(u=>{if("type"in u){let m=[];u.type==="ifelse"||u.type==="stepswitch"?y.getConditionalsThenElse(u,m):m=[u],m.map(l=>y.getConditionalsThenElse(l.text)).forEach(l=>{Array.isArray(l)&&l.forEach(h=>{Array.isArray(h)?h.forEach(w=>{typeof w=="string"?y.addKey(r,w,{defaultValue:n}):y.getConditionalsThenElse(w).forEach(O=>{Array.isArray(O)?O.forEach(x=>{typeof x=="string"&&y.addKey(r,x,{defaultValue:n});}):typeof O=="string"&&y.addKey(r,O,{defaultValue:n});});}):typeof h=="string"&&y.addKey(r,h,{defaultValue:n});});});}}));}if(v.dialogue){let p=[];Array.isArray(v.dialogue)?p=[v.dialogue]:p=y.getConditionalsThenElse(v.dialogue),p.forEach(f=>{if(typeof f=="string")y.addKey(r,f,{defaultValue:n});else if("text"in f){let u=y.getConditionalsThenElse(f.text);typeof u=="string"&&(u=[u]),u.forEach(m=>{typeof m=="string"?y.addKey(r,m,{defaultValue:n}):y.getConditionalsThenElse(m).forEach(l=>{typeof l=="string"?y.addKey(r,l,{defaultValue:n}):Array.isArray(l)&&l.forEach(h=>{typeof h=="string"?y.addKey(r,h,{defaultValue:n}):y.getConditionalsThenElse(h).forEach(w=>{typeof w=="string"&&y.addKey(r,w,{defaultValue:n});});});});});}});}if(v.operations)for(let p of v.operations){if(p.type==="operationtoconvert"&&o){let f=Be(p),u=await o(f,v,{});if(!u)return;p=u;}p.type==="text"&&p.operationType==="show"&&y.addKey(r,p.text,{defaultValue:n});}v.conditionalStep&&y.getConditionalsThenElse(v.conditionalStep).forEach(p=>{Array.isArray(p)?y.generateJsonTranslation(p,r,a):y.generateJsonTranslation([p],r,a);});});return await Promise.all(d),r}};oe(Q,"_beforeToTranslate"),oe(Q,"_translate",t=>t),oe(Q,"_afterToTranslate");var Re=Q,k=Re;var st=Object.defineProperty,lt=(t,e,r)=>e in t?st(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,B=(t,e,r)=>lt(t,typeof e!="symbol"?e+"":e,r);async function me(t){let e=s.getLogichValue(t,{});if(e)switch(e.type){case "assets":switch(e.operationType){case "load":await Assets.load(e.aliases);break;case "lazyload":Assets.backgroundLoad(e.aliases);break}break;case "bundle":switch(e.operationType){case "load":await Assets.loadBundle(e.aliases);break;case "lazyload":Assets.backgroundLoadBundle(e.aliases);break}break}}var V;(t=>(t.log=(e,...r)=>console.log(`[Pixi\u2019VN Json] ${e}`,...r),t.warn=(e,...r)=>console.warn(`[Pixi\u2019VN Json] ${e}`,...r),t.error=(e,...r)=>console.error(`[Pixi\u2019VN Json] ${e}`,...r),t.info=(e,...r)=>console.info(`[Pixi\u2019VN Json] ${e}`,...r)))(V||(V={}));async function te(t,e,r){switch(r.type){case "fade":await showWithFade(e.alias,t,r.props,r.priority);break;case "dissolve":await showWithDissolve(e.alias,t,r.props,r.priority);break;case "movein":case "moveout":await moveIn(e.alias,t,r.props,r.priority);break;case "zoomin":case "zoomout":await zoomIn(e.alias,t,r.props,r.priority);break;case "pushin":case "pushout":await pushIn(e.alias,t,r.props,r.priority);break}}function G(t){if(t.transition)switch(t.transition.type){case "fade":removeWithFade(t.alias,t.transition.props,t.transition.priority);break;case "dissolve":removeWithDissolve(t.alias,t.transition.props,t.transition.priority);break;case "movein":case "moveout":moveOut(t.alias,t.transition.props,t.transition.priority);break;case "zoomin":case "zoomout":zoomOut(t.alias,t.transition.props,t.transition.priority);break;case "pushin":case "pushout":pushOut(t.alias,t.transition.props,t.transition.priority);break}else canvas.remove(t.alias);}async function ye(t){switch(t.operationType){case "show":if(t.transition){let e=new ImageSprite(t.props,t.url||t.alias);await te(e,t,t.transition);}else await showImage(t.alias,t.url,t.props);break;case "edit":{let e=canvas.find(t.alias);e?t.props&&await e.setMemory({...e.memory,...t.props}):V.error(`Image with alias ${t.alias} not found.`);break}case "remove":G(t);break}}async function ve(t){switch(t.operationType){case "show":if(t.transition){let e=new VideoSprite(t.props,t.url||t.alias);await te(e,t,t.transition);}else await showVideo(t.alias,t.url,t.props);break;case "edit":{let e=canvas.find(t.alias);e?t.props&&await e.setMemory({...e.memory,...t.props}):V.error(`Video with alias ${t.alias} not found.`);break}case "remove":G(t);break;case "pause":case "resume":{let e=canvas.find(t.alias);e?e.paused=t.operationType==="pause":V.error(`Video with alias ${t.alias} not found.`);break}}}async function we(t){switch(t.operationType){case "show":if(t.transition){let e=new ImageContainer(t.props,t.urls);await te(e,t,t.transition);}else await showImageContainer(t.alias,t.urls,t.props);break;case "edit":{let e=canvas.find(t.alias);e?t.props&&await e.setMemory({...e.memory,...t.props}):V.error(`ImageContainer with alias ${t.alias} not found.`);break}case "remove":G(t);break}}async function xe(t){switch(t.operationType){case "show":if(t.props=t.props||{},t.props.text=k.t(t.text),t.transition){let e=new Text(t.props);await te(e,t,t.transition);}else showText(t.alias,t.text,t.props);break;case "edit":{let e=canvas.find(t.alias);e?t.props&&await e.setMemory({...e.memory,...t.props}):V.error(`Text with alias ${t.alias} not found.`);break}case "remove":G(t);break}}async function Ve(t){switch(t.operationType){case "edit":try{let e=canvas.find(t.alias);e?t.props&&e.setMemory({...e.memory,...t.props}):V.error(`Canvas Element with alias ${t.alias} not found.`);}catch(e){V.error(`There was an error while trying to edit the canvas element with alias ${t.alias}.`,e);}break;case "remove":G(t);break}}async function Oe(t){t.type==="shake"&&await shakeEffect(t.alias,t.props,t.priority);}function Ae(t){switch(t.type){case "animate":canvas.animate(t.alias,t.keyframes,t.options,t.priority);break;case "animate-sequence":canvas.animate(t.alias,t.sequence,t.options,t.priority);break}}function be(t){switch(t.type){case "input":narration.requestInput({type:t.valueType},t.defaultValue);break;case "dialogue":narration.dialogue=void 0;break}}function Pe(t){switch(t.operationType){case "play":t.url?sound.play(t.alias,t.url,t.props):sound.play(t.alias,t.props);break;case "stop":switch(t.type){case "sound":sound.stop(t.alias);break;case "all":sound.stopAll();break}break;case "pause":switch(t.type){case "sound":sound.pause(t.alias);break;case "channel":sound.findChannel(t.alias).pauseAll();break;case "all":sound.pauseAll();break}break;case "resume":switch(t.type){case "sound":sound.resume(t.alias);break;case "channel":sound.findChannel(t.alias).resumeAll();break;case "all":sound.resumeAll();break}break;case "edit":Object.entries(t.props).forEach(([e,r])=>{let a=sound.find(t.alias);a&&(e==="volume"?a.volume.value=r:a.paused=r);});break}}var ne="___param___",z=class b{static init(e){e.loadAssets&&(b._loadAssets=e.loadAssets),e.soundOperation&&(b._soundOperation=e.soundOperation),e.imageOperation&&(b._imageOperation=e.imageOperation),e.videoOperation&&(b._videoOperation=e.videoOperation),e.imageContainerOperation&&(b._imageContainerOperation=e.imageContainerOperation),e.textOperation&&(b._textOperation=e.textOperation),e.canvasElementOperation&&(b._canvasElementOperation=e.canvasElementOperation),e.setStorageValue&&(b._setStorageValue=e.setStorageValue),e.setInitialStorageValue&&(b._setInitialStorageValue=e.setInitialStorageValue),e.narrationOperation&&(b._narrationOperation=e.narrationOperation),e.effectOperation&&(b._effectOperation=e.effectOperation),e.animateOperation&&(b._animateOperation=e.animateOperation),e.getLogichValue&&(b._getLogichValue=e.getLogichValue),e.getConditionalStep&&(b._getConditionalStep=e.getConditionalStep);}static get loadAssets(){return b._loadAssets}static get soundOperation(){return b._soundOperation}static get imageOperation(){return b._imageOperation}static get videoOperation(){return b._videoOperation}static get imageContainerOperation(){return b._imageContainerOperation}static get textOperation(){return b._textOperation}static get canvasElementOperation(){return b._canvasElementOperation}static get setStorageValue(){return b._setStorageValue}static get setInitialStorageValue(){return b._setInitialStorageValue}static get narrationOperation(){return b._narrationOperation}static get effectOperation(){return b._effectOperation}static get animateOperation(){return b._animateOperation}static get getLogichValue(){return b._getLogichValue}static get getConditionalStep(){return b._getConditionalStep}};B(z,"_loadAssets",()=>{}),B(z,"_soundOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_imageOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_videoOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_imageContainerOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_textOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_canvasElementOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_setStorageValue",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_setInitialStorageValue",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_narrationOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_effectOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_animateOperation",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_getLogichValue",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),B(z,"_getConditionalStep",()=>{throw V.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")});var ct=z;function pt(t,e){if(e&&typeof e=="object"&&typeof t.functionName=="string"&&t.functionName in e){let r=e[t.functionName];if(typeof r=="function"){let a=t.args.map(n=>ct.getLogichValue(n,e));return r(...a)}else V.warn(`getLogichValue function ${t.functionName} not found in props`);}}function Se(t,e){let r=s.getLogichValue(t,e);return r&&typeof r=="object"&&"type"in r?s.getLogichValue(r,e):r}function Ne(t,e={}){let r=Se(t.value,e);switch(t.storageType){case "flagStorage":storage.setFlag(t.key,t.value);break;case "storage":storage.set(t.key,r);break;case "tempstorage":storage.setTempVariable(t.key,r);break;case "params":{let a=storage.get(`${ne}${narration.openedLabels.length-1}`)||[];a.length>t.key&&(a[t.key]=r),storage.setTempVariable(`${ne}${narration.openedLabels.length-1}`,a);break}}}function _e(t,e={}){let r=Se(t.value,e);switch(t.storageType){case "storage":case "tempstorage":storage.default={[t.key]:r};break}}function se(t,e={}){let r=le(t,e);if(r&&typeof r=="object"&&"type"in r)switch(r.type){case "value":return gt(r,e);case "arithmetic":case "arithmeticsingle":return ut(r,e);case "compare":case "union":return dt(r,e);case "function":return pt(r,e)}return r}function ut(t,e){let r=s.getLogichValue(t.leftValue,e);switch(t.type){case "arithmetic":{let a=s.getLogichValue(t.rightValue,e);switch(t.operator){case "*":return r*a;case "/":return r/a;case "+":return typeof r=="string"||typeof a=="string"?`${r}${a}`:Array.isArray(r)&&Array.isArray(a)?[...r,...a]:Array.isArray(r)?[...r,a]:Array.isArray(a)?[r,...a]:r+a;case "-":if(Array.isArray(r)&&Array.isArray(a))return r.filter(n=>!a.includes(n));if(Array.isArray(r))return r.filter(n=>n!==a);if(Array.isArray(a)){V.warn("getValueFromArithmeticOperations cannot subtract array from non-array");return}return r-a;case "%":return r%a;case "POW":return r**a;case "RANDOM":return narration.getRandomNumber(r,a);case "INTERSECTION":if(Array.isArray(r)&&Array.isArray(a))return r.filter(n=>a.includes(n));V.warn("getValueFromArithmeticOperations cannot intersect non-array values");return;default:V.warn("getValueFromArithmeticOperations unknown operator",t);return}}case "arithmeticsingle":switch(t.operator){case "INT":return Number(r);case "FLOOR":return Math.floor(r)}break}}function gt(t,e){if(t&&typeof t=="object"&&"type"in t&&t.type==="value"&&t.storageOperationType==="get")switch(t.storageType){case "storage":case "tempstorage":return t.key==="_input_value_"?narration.inputValue:storage.get(t.key);case "flagStorage":return storage.getFlag(t.key);case "label":return narration.getTimesLabelOpened(t.label);case "choice":return narration.getTimesChoiceMade(t.index);case "logic":return s.getLogichValue(t.operation,e);case "params":{let r=storage.get(`${ne}${narration.openedLabels.length-1}`)||[];if(r&&r.length>t.key)return r[t.key];V.warn("getValue params not found");return}}return t}function dt(t,e){if(!t)return false;if(typeof t!="object"||!("type"in t))return !!t;switch(t.type){case "compare":{let r=s.getLogichValue(t.leftValue,e),a=s.getLogichValue(t.rightValue,e);switch(t.operator){case "==":return Array.isArray(r)&&Array.isArray(a)?r.length===a.length&&r.every(n=>a.includes(n)):r===a;case "!=":return Array.isArray(r)&&Array.isArray(a)?r.length!==a.length||!r.every(n=>a.includes(n)):r!==a;case "<":return typeof r=="string"&&typeof a=="string"?r.localeCompare(a)<0:Array.isArray(r)&&Array.isArray(a)?r.length<a.length:r<a;case "<=":return typeof r=="string"&&typeof a=="string"?r.localeCompare(a)<=0:Array.isArray(r)&&Array.isArray(a)?r.length<=a.length:r<=a;case ">":return typeof r=="string"&&typeof a=="string"?r.localeCompare(a)>0:Array.isArray(r)&&Array.isArray(a)?r.length>a.length:r>a;case ">=":return typeof r=="string"&&typeof a=="string"?r.localeCompare(a)>=0:Array.isArray(r)&&Array.isArray(a)?r.length>=a.length:r>=a;case "CONTAINS":return Array.isArray(r)&&Array.isArray(a)?a.every(n=>r.includes(n)):Array.isArray(r)?r.includes(a):r.toString().includes(a.toString())}break}case "value":{let r=s.getLogichValue(t,e);return Array.isArray(r)?r.length>0:r&&typeof r=="object"?Object.keys(r).length>0:!!r}case "union":return ht(t,e)}return !!t}function ht(t,e){if(t.unionType==="not"){let a=se(t.condition,e);return Array.isArray(a)?a.length===0:a&&typeof a=="object"?Object.keys(a).length===0:!a}let r=a=>s.getLogichValue(a,e)||false;return t.unionType==="and"?t.conditions.every(r):t.conditions.some(r)}function ft(t,e){return Math.floor(Math.random()*(e-t+1)+t)}function le(t,e={}){if(Array.isArray(t)||!t)return t;if(t&&typeof t=="object"&&"type"in t)switch(t.type){case "resulttocombine":return mt(t,e);case "ifelse":return s.getLogichValue(t.condition,e)?s.getLogichValue(t.then,e):s.getLogichValue(t.else,e);case "stepswitch":{let r=s.getLogichValue(t.elements,e)||[];if(r.length===0){V.error("getValueFromConditionalStatements elements.length === 0");return}switch(t.choiceType){case "random":{let a=ft(0,r.length-1);return s.getLogichValue(r[a],e)}case "loop":{let a=NarrationManagerStatic.getCurrentStepTimesCounter(t.nestedId)-1;return a>r.length-1?(a=a%r.length,s.getLogichValue(r[a],e)):s.getLogichValue(r[a],e)}case "sequential":{let a,n=NarrationManagerStatic.getCurrentStepTimesCounter(t.nestedId)-1;return t.end==="lastItem"&&(a=s.getLogichValue(r[r.length-1],e)),n>r.length-1?a:s.getLogichValue(r[n],e)}case "sequentialrandom":{let a=NarrationManagerStatic.getRandomNumber(0,r.length-1,{nestedId:t.nestedId,onceOnly:true});if(a===void 0&&t.end==="lastItem"){let n=NarrationManagerStatic.getCurrentStepTimesCounterData(t.nestedId);if(!n?.usedRandomNumbers){V.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let o=n.usedRandomNumbers[`0-${r.length-1}`];return s.getLogichValue(r[o[o.length-1]],e)}if(a===void 0){V.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return s.getLogichValue(r[a],e)}}}}return t}function re(t,e={}){if(t.conditionalStep){let r=createExportableElement(s.getLogichValue(t.conditionalStep,e));if(r?.glueEnabled===void 0&&delete r?.glueEnabled,r?.goNextStep===void 0&&delete r?.goNextStep,r?.end===void 0&&delete r?.end,r?.choices===void 0&&delete r?.choices,r?.dialogue===void 0&&delete r?.dialogue,r?.labelToOpen===void 0&&delete r?.labelToOpen,r?.operations===void 0&&delete r?.operations,r){let a={...t,conditionalStep:void 0,...r};return re(a,e)}else narration.dialogGlue&&(narration.dialogGlue=false);}return t}function mt(t,e){let r=t.firstItem,a=(t.secondConditionalItem??[]).flatMap(o=>Array.isArray(o)?o.map(d=>s.getLogichValue(d,e)):[s.getLogichValue(o,e)]),n=r?[r,...a]:a;if(n.length===0){V.warn("combinateResult toCheck.length === 0");return}if(typeof n[0]=="string")return k.t(n);if(typeof n[0]=="object"){let o=n,d,v=false,p=o.map((i,c)=>{i=re(i,e);let g=s.getLogichValue(i.dialogue,e)||"";return c===0?(d=s.getLogichValue(i.glueEnabled,e)||false,g):(typeof g=="object"&&"text"in g&&(g=`${g.character}: ${g.text}`),d===false&&v&&(g=` ${g}`),g&&(v=true),d=s.getLogichValue(i.glueEnabled,e)||false,g)}),f=s.getLogichValue(p[0],e),u=typeof f=="object"&&"character"in f?f.character:void 0,m=p.flatMap(i=>{let c;i&&typeof i=="object"&&"text"in i?c=i.text:c=i;let g;return Array.isArray(c)?g=c.map(S=>{let j=s.getLogichValue(S,e);return k.t(`${j}`)}):g=s.getLogichValue(c,e)||"",k.t(g)}),l=o.find(i=>i.end),h=o.find(i=>i.choices),w=false,O=false;o.length>0&&(o[0].glueEnabled&&o[0].goNextStep&&o[0].dialogue===void 0&&(narration.dialogGlue=true),w=o[o.length-1].glueEnabled,O=o.reverse().find(i=>!(i.operations&&(!i.dialogue||!i.choices)))?.goNextStep);let x=o.find(i=>i.labelToOpen),N=[];return o.forEach(i=>{i.operations&&(N=[...N,...i.operations]);}),{dialogue:u?{character:u,text:m}:m,end:l?.end,choices:h?.choices,glueEnabled:w,goNextStep:O,labelToOpen:x?.labelToOpen,operations:N}}}var xt=Object.create,ce=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Ot=Object.getOwnPropertyNames,At=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty,Pt=(t,e,r)=>e in t?ce(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,Ce=(t=>typeof a<"u"?a:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof a<"u"?a:e)[r]}):t)(function(t){if(typeof a<"u")return a.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')}),Le=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),St=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ot(e))!bt.call(t,n)&&n!==r&&ce(t,n,{get:()=>e[n],enumerable:!(a=Vt(e,n))||a.enumerable});return t},Nt=(t,e,r)=>(r=t!=null?xt(At(t)):{},St(ce(r,"default",{value:t,enumerable:true}),t)),C=(t,e,r)=>Pt(t,typeof e!="symbol"?e+"":e,r),_t=Le((t,e)=>{(function(r,a){typeof t=="object"?e.exports=t=a():typeof define=="function"&&define.amd?define([],a):r.CryptoJS=a();})(t,function(){var r=r||(function(a,n){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof Ce=="function")try{o=Ce("crypto");}catch{}var d=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},v=Object.create||(function(){function i(){}return function(c){var g;return i.prototype=c,g=new i,i.prototype=null,g}})(),p={},f=p.lib={},u=f.Base=(function(){return {extend:function(i){var c=v(this);return i&&c.mixIn(i),(!c.hasOwnProperty("init")||this.init===c.init)&&(c.init=function(){c.$super.init.apply(this,arguments);}),c.init.prototype=c,c.$super=this,c},create:function(){var i=this.extend();return i.init.apply(i,arguments),i},init:function(){},mixIn:function(i){for(var c in i)i.hasOwnProperty(c)&&(this[c]=i[c]);i.hasOwnProperty("toString")&&(this.toString=i.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),m=f.WordArray=u.extend({init:function(i,c){i=this.words=i||[],c!=n?this.sigBytes=c:this.sigBytes=i.length*4;},toString:function(i){return (i||h).stringify(this)},concat:function(i){var c=this.words,g=i.words,S=this.sigBytes,j=i.sigBytes;if(this.clamp(),S%4)for(var T=0;T<j;T++){var ae=g[T>>>2]>>>24-T%4*8&255;c[S+T>>>2]|=ae<<24-(S+T)%4*8;}else for(var q=0;q<j;q+=4)c[S+q>>>2]=g[q>>>2];return this.sigBytes+=j,this},clamp:function(){var i=this.words,c=this.sigBytes;i[c>>>2]&=4294967295<<32-c%4*8,i.length=a.ceil(c/4);},clone:function(){var i=u.clone.call(this);return i.words=this.words.slice(0),i},random:function(i){for(var c=[],g=0;g<i;g+=4)c.push(d());return new m.init(c,i)}}),l=p.enc={},h=l.Hex={stringify:function(i){for(var c=i.words,g=i.sigBytes,S=[],j=0;j<g;j++){var T=c[j>>>2]>>>24-j%4*8&255;S.push((T>>>4).toString(16)),S.push((T&15).toString(16));}return S.join("")},parse:function(i){for(var c=i.length,g=[],S=0;S<c;S+=2)g[S>>>3]|=parseInt(i.substr(S,2),16)<<24-S%8*4;return new m.init(g,c/2)}},w=l.Latin1={stringify:function(i){for(var c=i.words,g=i.sigBytes,S=[],j=0;j<g;j++){var T=c[j>>>2]>>>24-j%4*8&255;S.push(String.fromCharCode(T));}return S.join("")},parse:function(i){for(var c=i.length,g=[],S=0;S<c;S++)g[S>>>2]|=(i.charCodeAt(S)&255)<<24-S%4*8;return new m.init(g,c)}},O=l.Utf8={stringify:function(i){try{return decodeURIComponent(escape(w.stringify(i)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(i){return w.parse(unescape(encodeURIComponent(i)))}},x=f.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new m.init,this._nDataBytes=0;},_append:function(i){typeof i=="string"&&(i=O.parse(i)),this._data.concat(i),this._nDataBytes+=i.sigBytes;},_process:function(i){var c,g=this._data,S=g.words,j=g.sigBytes,T=this.blockSize,ae=T*4,q=j/ae;i?q=a.ceil(q):q=a.max((q|0)-this._minBufferSize,0);var X=q*T,he=a.min(X*4,j);if(X){for(var ie=0;ie<X;ie+=T)this._doProcessBlock(S,ie);c=S.splice(0,X),g.sigBytes-=he;}return new m.init(c,he)},clone:function(){var i=u.clone.call(this);return i._data=this._data.clone(),i},_minBufferSize:0});f.Hasher=x.extend({cfg:u.extend(),init:function(i){this.cfg=this.cfg.extend(i),this.reset();},reset:function(){x.reset.call(this),this._doReset();},update:function(i){return this._append(i),this._process(),this},finalize:function(i){i&&this._append(i);var c=this._doFinalize();return c},blockSize:16,_createHelper:function(i){return function(c,g){return new i.init(g).finalize(c)}},_createHmacHelper:function(i){return function(c,g){return new N.HMAC.init(i,g).finalize(c)}}});var N=p.algo={};return p})(Math);return r});}),jt=Le((t,e)=>{(function(r,a){typeof t=="object"?e.exports=t=a(_t()):typeof define=="function"&&define.amd?define(["./core"],a):a(r.CryptoJS);})(t,function(r){return (function(){var a=r,n=a.lib,o=n.WordArray,d=n.Hasher,v=a.algo,p=[],f=v.SHA1=d.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,m){for(var l=this._hash.words,h=l[0],w=l[1],O=l[2],x=l[3],N=l[4],i=0;i<80;i++){if(i<16)p[i]=u[m+i]|0;else {var c=p[i-3]^p[i-8]^p[i-14]^p[i-16];p[i]=c<<1|c>>>31;}var g=(h<<5|h>>>27)+N+p[i];i<20?g+=(w&O|~w&x)+1518500249:i<40?g+=(w^O^x)+1859775393:i<60?g+=(w&O|w&x|O&x)-1894007588:g+=(w^O^x)-899497514,N=x,x=O,O=w<<30|w>>>2,w=h,h=g;}l[0]=l[0]+h|0,l[1]=l[1]+w|0,l[2]=l[2]+O|0,l[3]=l[3]+x|0,l[4]=l[4]+N|0;},_doFinalize:function(){var u=this._data,m=u.words,l=this._nDataBytes*8,h=u.sigBytes*8;return m[h>>>5]|=128<<24-h%32,m[(h+64>>>9<<4)+14]=Math.floor(l/4294967296),m[(h+64>>>9<<4)+15]=l,u.sigBytes=m.length*4,this._process(),this._hash},clone:function(){var u=d.clone.call(this);return u._hash=this._hash.clone(),u}});a.SHA1=d._createHelper(f),a.HmacSHA1=d._createHmacHelper(f);})(),r.SHA1});}),Te="___param___",_;(t=>(t.log=(e,...r)=>console.log(`[Pixi\u2019VN Json] ${e}`,...r),t.warn=(e,...r)=>console.warn(`[Pixi\u2019VN Json] ${e}`,...r),t.error=(e,...r)=>console.error(`[Pixi\u2019VN Json] ${e}`,...r),t.info=(e,...r)=>console.info(`[Pixi\u2019VN Json] ${e}`,...r)))(_||(_={}));var $=class P{static init(e){e.loadAssets&&(P._loadAssets=e.loadAssets),e.soundOperation&&(P._soundOperation=e.soundOperation),e.imageOperation&&(P._imageOperation=e.imageOperation),e.videoOperation&&(P._videoOperation=e.videoOperation),e.imageContainerOperation&&(P._imageContainerOperation=e.imageContainerOperation),e.textOperation&&(P._textOperation=e.textOperation),e.canvasElementOperation&&(P._canvasElementOperation=e.canvasElementOperation),e.setStorageValue&&(P._setStorageValue=e.setStorageValue),e.setInitialStorageValue&&(P._setInitialStorageValue=e.setInitialStorageValue),e.narrationOperation&&(P._narrationOperation=e.narrationOperation),e.effectOperation&&(P._effectOperation=e.effectOperation),e.animateOperation&&(P._animateOperation=e.animateOperation),e.getLogichValue&&(P._getLogichValue=e.getLogichValue),e.getConditionalStep&&(P._getConditionalStep=e.getConditionalStep);}static get loadAssets(){return P._loadAssets}static get soundOperation(){return P._soundOperation}static get imageOperation(){return P._imageOperation}static get videoOperation(){return P._videoOperation}static get imageContainerOperation(){return P._imageContainerOperation}static get textOperation(){return P._textOperation}static get canvasElementOperation(){return P._canvasElementOperation}static get setStorageValue(){return P._setStorageValue}static get setInitialStorageValue(){return P._setInitialStorageValue}static get narrationOperation(){return P._narrationOperation}static get effectOperation(){return P._effectOperation}static get animateOperation(){return P._animateOperation}static get getLogichValue(){return P._getLogichValue}static get getConditionalStep(){return P._getConditionalStep}};C($,"_loadAssets",()=>{}),C($,"_soundOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_imageOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_videoOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_imageContainerOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_textOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_canvasElementOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_setStorageValue",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_setInitialStorageValue",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_narrationOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_effectOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_animateOperation",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_getLogichValue",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),C($,"_getConditionalStep",()=>{throw _.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")});var Ct=$;function Tt(t,e){if(e&&typeof e=="object"&&typeof t.functionName=="string"&&t.functionName in e){let r=e[t.functionName];if(typeof r=="function"){let a=t.args.map(n=>Ct.getLogichValue(n,e));return r(...a)}else _.warn(`getLogichValue function ${t.functionName} not found in props`);}}function Et(t,e={}){let r="";return t.values.forEach(a=>{if(typeof a=="string")r+=a;else {let n=s.getLogichValue(a,e);r+=`${n}`;}}),r}async function ke(t,e,r){let a=s.getLogichValue(t,e);if(a)switch(a.type){case "sound":s.soundOperation(a);break;case "assets":case "bundle":await s.loadAssets(a);break;case "image":await s.imageOperation(a);break;case "video":await s.videoOperation(a);break;case "imagecontainer":await s.imageContainerOperation(a);break;case "text":await s.textOperation(a);break;case "canvaselement":await s.canvasElementOperation(a);break;case "value":s.setStorageValue(a,e);break;case "operationtoconvert":if(r){let n=Et(a,e),o=await r(n);o&&await ke(o,e,r);}break;case "input":case "dialogue":s.narrationOperation(a);break;case "shake":await s.effectOperation(a);break;case "animate":case "animate-sequence":s.animateOperation(a);break;case "function":await Tt(a,e);break}}function Ee(t){let e=s.getLogichValue(t,{});e&&e.type==="value"&&e.storageOperationType==="set"&&(e.storageType==="storage"||e.storageType==="tempstorage")&&s.setInitialStorageValue(e);}var Lt=Nt(jt()),kt=class extends LabelAbstract{constructor(t,e,r,a={}){r||(r={}),r.onLoadingLabel=async()=>{for(let n of e){let o;if(typeof n=="function"?o=n():o=n,o=s.getConditionalStep(o),o.operations)try{let d=o.operations.map(v=>s.loadAssets(v));await Promise.all(d);}catch(d){_.error("The operation in the onLoadingLabel function of the label has an error:",d);}}},super(t,r),C(this,"_steps"),C(this,"operationStringConvert"),C(this,"skipEmptyDialogs",false),this._steps=e,this.operationStringConvert=a.operationStringConvert,this.skipEmptyDialogs=a.skipEmptyDialogs||false;}get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let e=this._steps[t];return this.stepConverter(e)}getStepSha(t){if(t<0||t>=this.steps.length)return;let e=this._steps[t];return (0, Lt.default)(e.toString().toLocaleLowerCase()).toString()}getDialogueText(t,e){let r="";if(Array.isArray(t)){let a=[];t.forEach(n=>{if(typeof n=="string")a.push(n);else if(n&&typeof n=="object"){let o=s.getLogichValue(n,e);o?(o&&!Array.isArray(o)&&typeof o=="object"&&(o=s.getLogichValue(o,e)||""),Array.isArray(o)?a=a.map(d=>`${d}`).concat(o):a.push(`${o}`)):a.push(`${n}`);}else a.push(`${n}`);}),r=a;}else {let a=s.getLogichValue(t,e);a&&!Array.isArray(a)&&typeof a=="object"&&(a=s.getLogichValue(a,e)),a&&Array.isArray(a)?r=a.map(n=>`${n}`):r=`${a}`;}return r}getDialogue(t,e){if(t==null)return;let r=s.getLogichValue(t,e);return r==null?`${r}`:typeof r=="object"&&"character"in r&&"text"in r?{character:r.character,text:k.t(this.getDialogueText(r.text,e))}:k.t(this.getDialogueText(r,e))}getChoices(t,e){return s.getLogichValue(t,e)?.map(r=>s.getLogichValue(r,e)).filter(r=>r!==void 0)}stepConverter(t){return async e=>{let r=typeof t=="function"?t():t;r=createExportableElement(r),r=s.getConditionalStep(r,e);let a=this.operationStringConvert?l=>this.operationStringConvert(l,r,e):void 0,{operations:n=[]}=r;for(let l of n)await ke(l,e,a);let{labelToOpen:o=[]}=r,d=this.getChoices(r.choices,e),v=s.getLogichValue(r.glueEnabled,e),p=this.getDialogue(r.dialogue,e),f=[];Array.isArray(o)||(o=[o]),o.forEach(l=>{let h=s.getLogichValue(l,e);h&&f.push(h);});let u=s.getLogichValue(r.goNextStep,e),m=s.getLogichValue(r.end,e);if(d){let l=d.map(h=>{let w="";if(Array.isArray(h.text)){let O=[];h.text.forEach(x=>{if(typeof x=="string")O.push(k.t(x));else if(x&&typeof x=="object"){let N=s.getLogichValue(x,e);N&&!Array.isArray(N)&&typeof N=="object"&&(N=s.getLogichValue(N,e)||""),N&&(Array.isArray(N)?O=O.concat(k.t(N)):O.push(k.t(N)));}}),w=O;}else typeof h.text=="string"&&(w=k.t(h.text));return {label:h.label,text:w,props:h.props,type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect}});narration.choices=l;}else narration.choices=void 0;p!==void 0&&(narration.dialogue=p,this.skipEmptyDialogs&&typeof p=="string"&&(p===""||RegExp(/^\s+$/).test(p))&&(u=true)),v?narration.dialogGlue=true:v===false&&(narration.dialogGlue=false);for(let l of f){let h=l.label;typeof h=="object"&&(h=s.getLogichValue(h,e)||"");let w=l.params?.map(O=>s.getLogichValue(O,e));e={...e,...l.props},l.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${Te}${narration.openedLabels.length}`,w),await narration.call(h,e)):(storage.setTempVariable(`${Te}${narration.openedLabels.length}`,w),await narration.call(h,e));}m==="game_end"?(narration.closeAllLabels(),await narration.continue(e,{runNow:true})):m==="label_end"&&narration.closeCurrentLabel(),u&&await narration.continue(e,{runNow:true});}}};async function pe(t,e={}){if(!Array.isArray(t))if(typeof t=="object"||typeof t=="string")t=[t];else {_.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let r=t.map(o=>{if(typeof o=="string")try{return JSON.parse(o)}catch(d){return _.error("Error parsing imported Pixi'VN JSON",d),{}}return o}),a=r.map(async o=>{if(o.initialOperations)for(let d of o.initialOperations)d.type==="value"&&(typeof d.value!="object"||!d.value||!("type"in d.value))&&Ee(d);return Promise.resolve()});await Promise.all(a);let n=r.map(async o=>{if(o.initialOperations)for(let d of o.initialOperations)(d.type!=="value"||d.type==="value"&&typeof d.value=="object"&&d.value&&"type"in d.value)&&Ee(d);if(o.labels){let d=o.labels;for(let v in d)try{let p=d[v],f=new kt(v,p,void 0,e);RegisteredLabels.add(f);}catch(p){_.error(`Error creating JSON label ${v}`,p);}}return Promise.resolve()});await Promise.all(n);}var ue;(t=>{let e=new Set;function r(o){e.add(o);}t.add=r;function a(){e.clear();}t.clear=a;function n(o,d={}){let v=u=>se(u,d)??void 0,p=le(o,d);if(e.size===0)return v(p);let f=v;for(let u of e){let m=f;f=l=>u(l,m)??void 0;}return f(p)}t.getLogichValue=n;})(ue||(ue={}));var ge;(t=>{t.options={replaceRegex:/\[([^\]]+)\]/};let e=[],r=false,a=false;function n(f,u){e.push({fn:f,opts:u});let m=u.type??"before-translation";m==="before-translation"&&!r?(k.beforeToTranslate=l=>v(l,{type:"before-translation"}),r=true):m==="after-translation"&&!a&&(k.afterToTranslate=l=>v(l,{type:"after-translation"}),a=true);}t.add=n;function o(f){let u=e.findIndex(m=>m.fn===f);u!==-1&&e.splice(u,1);}t.remove=o;function d(){return e.map(f=>f.opts)}t.info=d;function v(f,u){let m=e.filter(l=>(l.opts.type??"before-translation")===u.type);for(let l of m)f=p(f,l.fn,l.opts.validation);return f}t.replace=v;function p(f,u,m){let l=new RegExp(t.options.replaceRegex.source,"g"),h=[...f.matchAll(l)],w=new Set,O=[];for(let x of h)w.has(x[1])||(w.add(x[1]),O.push(x[1]));for(let x of O){if(m==="characterId"){if(!RegisteredCharacters.has(x))continue}else if(m!=="all"){if(m instanceof RegExp){if(!m.test(x))continue}else if(m instanceof ZodType&&!m.safeParse(x).success)continue}let N=u(x);N!==void 0&&(f=f.replaceAll(`[${x}]`,N));}return f}})(ge||(ge={}));function de(){s.init({animateOperation:Ae,canvasElementOperation:Ve,effectOperation:Oe,imageContainerOperation:we,imageOperation:ye,textOperation:xe,narrationOperation:be,loadAssets:me,soundOperation:Pe,videoOperation:ve,setStorageValue:Ne,setInitialStorageValue:_e,getLogichValue:ue.getLogichValue,getConditionalStep:re});}async function Or(t){Array.isArray(t)||(t=[t]),de();let e$1={functions:[],enums:{}},r=t.map(async a=>{let n=h(a,e$1);return n&&await pe(n,{operationStringConvert:e.run,skipEmptyDialogs:true}),a});return await Promise.all(r)}async function Ar(t){return de(),await pe(t,{operationStringConvert:e.run,skipEmptyDialogs:true})}export{k as a,ue as b,ge as c,Or as d,Ar as e};