route-engine-js 0.0.2-rc14 → 0.0.2-rc15
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/RouteEngine.js +1 -1
- package/package.json +1 -1
package/dist/RouteEngine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var bt=Object.defineProperty;var N=(e,t)=>{for(var r in t)bt(e,r,{get:t[r],enumerable:!0})};var Pe=Symbol.for("immer-nothing"),Ae=Symbol.for("immer-draftable"),I=Symbol.for("immer-state");function b(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var O=Object.getPrototypeOf;function P(e){return!!e&&!!e[I]}function v(e){return e?$e(e)||Array.isArray(e)||!!e[Ae]||!!e.constructor?.[Ae]||F(e)||V(e):!1}var xt=Object.prototype.constructor.toString();function $e(e){if(!e||typeof e!="object")return!1;let t=O(e);if(t===null)return!0;let r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object?!0:typeof r=="function"&&Function.toString.call(r)===xt}function R(e,t){M(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function M(e){let t=e[I];return t?t.type_:Array.isArray(e)?1:F(e)?2:V(e)?3:0}function K(e,t){return M(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Ne(e,t,r){let n=M(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function At(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function F(e){return e instanceof Map}function V(e){return e instanceof Set}function A(e){return e.copy_||e.base_}function H(e,t){if(F(e))return new Map(e);if(V(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let r=$e(e);if(t===!0||t==="class_only"&&!r){let n=Object.getOwnPropertyDescriptors(e);delete n[I];let o=Reflect.ownKeys(n);for(let i=0;i<o.length;i++){let s=o[i],c=n[s];c.writable===!1&&(c.writable=!0,c.configurable=!0),(c.get||c.set)&&(n[s]={configurable:!0,writable:!0,enumerable:c.enumerable,value:e[s]})}return Object.create(O(e),n)}else{let n=O(e);if(n!==null&&r)return{...e};let o=Object.create(n);return Object.assign(o,e)}}function te(e,t=!1){return z(e)||P(e)||!v(e)||(M(e)>1&&(e.set=e.add=e.clear=e.delete=vt),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>te(n,!0))),e}function vt(){b(2)}function z(e){return Object.isFrozen(e)}var St={};function S(e){let t=St[e];return t||b(0,e),t}var k;function ke(){return k}function wt(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function ve(e,t){t&&(S("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function Q(e){q(e),e.drafts_.forEach(Ot),e.drafts_=null}function q(e){e===k&&(k=e.parent_)}function Se(e){return k=wt(k,e)}function Ot(e){let t=e[I];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function we(e,t){t.unfinalizedDrafts_=t.drafts_.length;let r=t.drafts_[0];return e!==void 0&&e!==r?(r[I].modified_&&(Q(t),b(4)),v(e)&&(e=D(t,e),t.parent_||T(t,e)),t.patches_&&S("Patches").generateReplacementPatches_(r[I].base_,e,t.patches_,t.inversePatches_)):e=D(t,r,[]),Q(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Pe?e:void 0}function D(e,t,r){if(z(t))return t;let n=t[I];if(!n)return R(t,(o,i)=>Oe(e,n,t,o,i,r)),t;if(n.scope_!==e)return t;if(!n.modified_)return T(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;let o=n.copy_,i=o,s=!1;n.type_===3&&(i=new Set(o),o.clear(),s=!0),R(i,(c,a)=>Oe(e,n,o,c,a,r,s)),T(e,o,!1),r&&e.patches_&&S("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function Oe(e,t,r,n,o,i,s){if(P(o)){let c=i&&t&&t.type_!==3&&!K(t.assigned_,n)?i.concat(n):void 0,a=D(e,o,c);if(Ne(r,n,a),P(a))e.canAutoFreeze_=!1;else return}else s&&r.add(o);if(v(o)&&!z(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;D(e,o),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&T(e,o)}}function T(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&te(t,r)}function Pt(e,t){let r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:ke(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=n,i=re;r&&(o=[n],i=C);let{revoke:s,proxy:c}=Proxy.revocable(o,i);return n.draft_=c,n.revoke_=s,c}var re={get(e,t){if(t===I)return e;let r=A(e);if(!K(r,t))return $t(e,r,t);let n=r[t];return e.finalized_||!v(n)?n:n===X(e.base_,t)?(G(e),e.copy_[t]=ee(n,e)):n},has(e,t){return t in A(e)},ownKeys(e){return Reflect.ownKeys(A(e))},set(e,t,r){let n=Ce(A(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){let o=X(A(e),t),i=o?.[I];if(i&&i.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(At(r,o)&&(r!==void 0||K(e.base_,t)))return!0;G(e),Z(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty(e,t){return X(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,G(e),Z(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let r=A(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty(){b(11)},getPrototypeOf(e){return O(e.base_)},setPrototypeOf(){b(12)}},C={};R(re,(e,t)=>{C[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});C.deleteProperty=function(e,t){return C.set.call(this,e,t,void 0)};C.set=function(e,t,r){return re.set.call(this,e[0],t,r,e[0])};function X(e,t){let r=e[I];return(r?A(r):e)[t]}function $t(e,t,r){let n=Ce(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}function Ce(e,t){if(!(t in e))return;let r=O(e);for(;r;){let n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=O(r)}}function Z(e){e.modified_||(e.modified_=!0,e.parent_&&Z(e.parent_))}function G(e){e.copy_||(e.copy_=H(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Nt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,r,n)=>{if(typeof t=="function"&&typeof r!="function"){let i=r;r=t;let s=this;return function(a=i,...l){return s.produce(a,f=>r.call(this,f,...l))}}typeof r!="function"&&b(6),n!==void 0&&typeof n!="function"&&b(7);let o;if(v(t)){let i=Se(this),s=ee(t,void 0),c=!0;try{o=r(s),c=!1}finally{c?Q(i):q(i)}return ve(i,n),we(o,i)}else if(!t||typeof t!="object"){if(o=r(t),o===void 0&&(o=t),o===Pe&&(o=void 0),this.autoFreeze_&&te(o,!0),n){let i=[],s=[];S("Patches").generateReplacementPatches_(t,o,i,s),n(i,s)}return o}else b(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(s,...c)=>this.produceWithPatches(s,a=>t(a,...c));let n,o;return[this.produce(t,r,(s,c)=>{n=s,o=c}),n,o]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){v(e)||b(8),P(e)&&(e=kt(e));let t=Se(this),r=ee(e,void 0);return r[I].isManual_=!0,q(t),r}finishDraft(e,t){let r=e&&e[I];(!r||!r.isManual_)&&b(9);let{scope_:n}=r;return ve(n,t),we(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){let o=t[r];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}r>-1&&(t=t.slice(r+1));let n=S("Patches").applyPatches_;return P(e)?n(e,t):this.produce(e,o=>n(o,t))}};function ee(e,t){let r=F(e)?S("MapSet").proxyMap_(e,t):V(e)?S("MapSet").proxySet_(e,t):Pt(e,t);return(t?t.scope_:ke()).drafts_.push(r),r}function kt(e){return P(e)||b(10,e),Le(e)}function Le(e){if(!v(e)||z(e))return e;let t=e[I],r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=H(e,t.scope_.immer_.useStrictShallowCopy_)}else r=H(e,!0);return R(r,(n,o)=>{Ne(r,n,Le(o))}),t&&(t.finalized_=!1),r}var E=new Nt,ne=E.produce,Rr=E.produceWithPatches.bind(E),Dr=E.setAutoFreeze.bind(E),Tr=E.setUseStrictShallowCopy.bind(E),Mr=E.applyPatches.bind(E),Fr=E.createDraft.bind(E),Vr=E.finishDraft.bind(E);var oe=(e,t,r={})=>{let n=structuredClone(e),o={},i={},{transformSelectorFirstArgument:s=a=>a,transformActionFirstArgument:c=a=>a}=r;for(let[a,l]of Object.entries(t))a!=="createInitialState"&&(a.startsWith("select")?o[a]=(...f)=>l(s(n),...f):i[a]=(...f)=>{n=ne(n,_=>l(c(_),...f))});return{...o,...i}},se=(e,t)=>r=>{let n=e(),o=Array.isArray(r)?r:[r];return ne(n,i=>{o.forEach(s=>{t.forEach(c=>{c(i,s)})})})};var de={};N(de,{addBackgrundOrCg:()=>Ye,addBgm:()=>He,addCharacters:()=>Je,addChoices:()=>Ke,addDialogue:()=>Ge,addSfx:()=>Qe,addVisuals:()=>Xe,createInitialState:()=>Kt,default:()=>pe,generateScreenBackgroundElement:()=>Be});var u={LITERAL:0,VARIABLE:1,INTERPOLATION:2,FUNCTION:3,BINARY:4,UNARY:5,CONDITIONAL:6,LOOP:7,OBJECT:8,ARRAY:9},d={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8},L={NOT:0};var g=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},$=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var ie=e=>{if(!e||e.trim()==="")throw new g("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let r=e.includes("===")?"==":"!=";throw new g(`Invalid comparison operator '${e.includes("===")?"===":"!=="}' - did you mean '${r}'? (got: '${e}')`)}let t=["<",">","<=",">=","==","!="];for(let r of t)if(e.trim().endsWith(r))throw new g(`Incomplete comparison expression - missing right operand (got: '${e}')`)},Re=e=>{if(e.trim().endsWith(" in"))throw new g(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new g(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,r]=e.split(" in ");if(!r||r.trim()==="")throw new g(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(t.includes(",")){let n=t.split(",").map(o=>o.trim());for(let o of n)if(!o)throw new g(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`)}else if(!t.trim())throw new g(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`)};var De=(e,t)=>{if(t===null)return new $(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new $(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return new $(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},Te=(e,t)=>{let r=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new $(`Unknown function '${e}' (${r})`)};var Ct=(e,t,r={})=>h(e,r,t,{}),h=(e,t,r,n)=>{switch(e.type){case u.LITERAL:return e.value;case u.VARIABLE:return Me(e.path,r,n);case u.INTERPOLATION:return Lt(e.parts,t,r,n);case u.FUNCTION:return Fe(e,t,r,n);case u.BINARY:return Ve(e,t,r,n);case u.UNARY:return ze(e,t,r,n);case u.CONDITIONAL:return Rt(e,t,r,n);case u.LOOP:return Dt(e,t,r,n);case u.OBJECT:return Tt(e,t,r,n);case u.ARRAY:return Mt(e,t,r,n);default:throw new Error(`Unknown node type: ${e.type}`)}},Me=(e,t,r)=>{if(!e)return;if(r.hasOwnProperty(e))return r[e];let n=e.split("."),o=t;for(let i=0;i<n.length;i++){let s=n[i];if(r.hasOwnProperty(s)){o=r[s];continue}if(o==null)return;o=o[s]}return o},Lt=(e,t,r,n)=>{let o="";for(let i of e)if(typeof i=="string")o+=i;else{let s=h(i,t,r,n);o+=s!=null?String(s):""}return o},Fe=(e,t,r,n)=>{let o=t[e.name];if(!o)throw Te(e.name,t);let i=e.args.map(s=>h(s,t,r,n));return o(...i)},j=(e,t,r,n)=>{switch(e.type){case u.VARIABLE:return Me(e.path,r,n);case u.LITERAL:return e.value;case u.BINARY:return Ve(e,t,r,n);case u.UNARY:return ze(e,t,r,n);case u.FUNCTION:return Fe(e,t,r,n);default:return h(e,t,r,n)}},Ve=(e,t,r,n)=>{if(e.op===d.AND||e.op===d.OR){let s=j(e.left,t,r,n),c=j(e.right,t,r,n);switch(e.op){case d.AND:return s&&c;case d.OR:return s||c}}let o=h(e.left,t,r,n),i=h(e.right,t,r,n);switch(e.op){case d.EQ:return o==i;case d.NEQ:return o!=i;case d.GT:return o>i;case d.LT:return o<i;case d.GTE:return o>=i;case d.LTE:return o<=i;case d.IN:return Array.isArray(i)?i.includes(o):!1;default:throw new Error(`Unknown binary operator: ${e.op}`)}},ze=(e,t,r,n)=>{let o=e.op===L.NOT?j(e.operand,t,r,n):h(e.operand,t,r,n);switch(e.op){case L.NOT:return!o;default:throw new Error(`Unknown unary operator: ${e.op}`)}},Rt=(e,t,r,n)=>{for(let o=0;o<e.conditions.length;o++){let i=e.conditions[o];if(i===null||j(i,t,r,n))return h(e.bodies[o],t,r,n)}return{}},Dt=(e,t,r,n)=>{let o=h(e.iterable,t,r,n);if(!Array.isArray(o)){let s=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${e.iterable.path}`;throw De(s,o)}let i=[];for(let s=0;s<o.length;s++){let c=Object.create(n);c[e.itemVar]=o[s],e.indexVar&&(c[e.indexVar]=s);let a=h(e.body,t,r,c);Array.isArray(a)&&a.length===1?i.push(a[0]):i.push(a)}return i},Tt=(e,t,r,n)=>{let o={},i=null,s=!1;for(let c of e.properties)if(!c.key.startsWith("$if ")&&!c.key.match(/^\$if\s+\w+.*:?$/)&&!c.key.startsWith("$elif")&&!c.key.startsWith("$else")&&!c.key.startsWith("$for ")){s=!0;break}for(let c of e.properties)if(c.key.startsWith("$if ")||c.key.match(/^\$if\s+\w+.*:?$/)){let a=h(c.value,t,r,n);if(!s&&a!==null&&a!==void 0)return Array.isArray(a)&&a.length===1?a[0]:a;typeof a=="object"&&a!==null&&!Array.isArray(a)&&Object.assign(o,a)}else if(!c.key.startsWith("$for ")){let a=c.value;if(a&&a.type===u.OBJECT&&a.properties){let l=a.properties.find(f=>f.key.startsWith("$for "));if(l){let f=h(l.value,t,r,n);f!==void 0&&(o[c.key]=f)}else{let f=h(c.value,t,r,n);f!==void 0&&(o[c.key]=f)}}else{let l=c.parsedKey?h(c.parsedKey,t,r,n):c.key,f=h(c.value,t,r,n);f!==void 0&&(o[l]=f)}}return o},Mt=(e,t,r,n)=>{let o=[];for(let i of e.items)if(i.type===u.LOOP){let s=h(i,t,r,n);o.push(s)}else o.push(h(i,t,r,n));return o},ce=Ct;var Ft=/\$\{([^}]*)\}/g,Ue=e=>{let t=e.match(/^(\w+)\((.*)\)$/);if(!t)return{isFunction:!1};let[,r,n]=t,o=Vt(n);return{isFunction:!0,type:u.FUNCTION,name:r,args:o}},Vt=e=>e.trim()?zt(e).map(r=>jt(r.trim())):[],zt=e=>{let t=[],r="",n=0,o=!1,i="";for(let s=0;s<e.length;s++){let c=e[s],a=s>0?e[s-1]:"";!o&&(c==='"'||c==="'")?(o=!0,i=c,r+=c):o&&c===i&&a!=="\\"?(o=!1,i="",r+=c):!o&&c==="("?(n++,r+=c):!o&&c===")"?(n--,r+=c):!o&&c===","&&n===0?(t.push(r),r=""):r+=c}return r&&t.push(r),t},jt=e=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:u.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:u.LITERAL,value:parseFloat(e)};if(e==="true")return{type:u.LITERAL,value:!0};if(e==="false")return{type:u.LITERAL,value:!1};if(e==="null")return{type:u.LITERAL,value:null};let t=Ue(e);return t.isFunction?{type:t.type,name:t.name,args:t.args}:{type:u.VARIABLE,path:e}},je=(e,t={})=>{let r=e.trim(),n=Ue(r);return n.isFunction?{type:n.type,name:n.name,args:n.args}:{type:u.VARIABLE,path:r}},ae=(e,t={})=>{let r=e,n=[];e.includes("\\${")&&(r=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC$1"),r=r.replace(/\\(\$\{[^}]*\})/g,(c,a)=>{let l=`__ESCAPED_${n.length}__`;return n.push(a),l}),r=r.replace(/\\DOUBLE_ESC/g,"\\"));let o=[...r.matchAll(Ft)];if(o.length===0){let c=r;for(let a=0;a<n.length;a++)c=c.replace(`__ESCAPED_${a}__`,n[a]);return{type:u.LITERAL,value:c}}if(o.length===1&&o[0][0]===r&&n.length===0)return je(o[0][1],t);let i=[],s=0;for(let c of o){let[a,l]=c,f=c.index;if(f>s){let _=r.substring(s,f);for(let y=0;y<n.length;y++)_=_.replace(`__ESCAPED_${y}__`,n[y]);_&&i.push(_)}let p=je(l.trim(),t);i.push(p),s=f+a.length}if(s<r.length){let c=r.substring(s);for(let a=0;a<n.length;a++)c=c.replace(`__ESCAPED_${a}__`,n[a]);c&&i.push(c)}return{type:u.INTERPOLATION,parts:i}};var w=(e,t)=>typeof e=="string"?ae(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?Ut(e,t):Wt(e,t):{type:u.LITERAL,value:e},Ut=(e,t)=>{let r=[],n=!1;for(let o=0;o<e.length;o++){let i=e[o];if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let c=Object.keys(i);if(c.length===1&&c[0].startsWith("$for ")){let a=We(c[0],i[c[0]],t);r.push(a),n=!0;continue}}let s=w(i,t);r.push(s),(s.type===u.FUNCTION||s.type===u.CONDITIONAL||s.type===u.LOOP||s.type===u.OBJECT&&!s.fast||s.type===u.ARRAY&&!s.fast)&&(n=!0)}return{type:u.ARRAY,items:r,fast:!n}},Wt=(e,t)=>{let r=[],n=!1,o=Object.entries(e),i=0;for(;i<o.length;){let[s,c]=o[i];if(s.startsWith("$if ")||s.match(/^\$if#\w+\s/)||s.match(/^\$if\s+\w+.*:$/)){let a=Bt(o,i,t);r.push({key:s,value:a.node}),n=!0,i=a.nextIndex}else if(s.startsWith("$for ")){let a=We(s,c,t);r.push({key:s,value:a}),n=!0,i++}else{if(s.startsWith("$elif ")||s.startsWith("$else"))throw new g(`'${s.split(" ")[0]}' without matching '$if'`);if(s==="$if"||s==="$if:")throw new g("Missing condition expression after '$if'");{let a=w(c,t);(a.type===u.FUNCTION||a.type===u.CONDITIONAL||a.type===u.LOOP||a.type===u.OBJECT&&!a.fast||a.type===u.ARRAY&&!a.fast)&&(n=!0);let l=ae(s,t),f={key:s,value:a};(l.type!==u.LITERAL||l.value!==s)&&(f.parsedKey=l),r.push(f),i++}}}return{type:u.OBJECT,properties:r,fast:!n}},Bt=(e,t,r={})=>{let n=[],o=[],i=t,[s,c]=e[i],a=null,l;if(s.startsWith("$if#")){let p=s.match(/^\$if#(\w+)\s+(.+)$/);if(p)a=p[1],l=p[2];else throw new g(`Invalid conditional syntax: ${s}`)}else l=s.substring(4),l.endsWith(":")&&(l=l.slice(0,-1).trim());ie(l);let f=x(l);for(n.push(f),o.push(w(c,r)),i++;i<e.length;){let[p,_]=e[i],y=!1,m;if(a?p.startsWith(`$elif#${a} `)?(m=p.substring(`$elif#${a} `.length),m.endsWith(":")&&(m=m.slice(0,-1).trim()),y=!0):(p===`$else#${a}`||p===`$else#${a}:`)&&(y=!0,m=null):p.startsWith("$elif ")?(m=p.substring(6),m.endsWith(":")&&(m=m.slice(0,-1).trim()),y=!0):(p==="$else"||p==="$else:")&&(y=!0,m=null),y){if(m===null)n.push(null);else{ie(m);let J=x(m);n.push(J)}if(o.push(w(_,r)),i++,m===null)break}else break}return{node:{type:u.CONDITIONAL,conditions:n,bodies:o,id:a},nextIndex:i}},x=e=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")"))return x(e.slice(1,-1));let t=ue(e,"||");if(t!==-1)return{type:u.BINARY,op:d.OR,left:x(e.substring(0,t).trim()),right:x(e.substring(t+2).trim())};let r=ue(e,"&&");if(r!==-1)return{type:u.BINARY,op:d.AND,left:x(e.substring(0,r).trim()),right:x(e.substring(r+2).trim())};let n=[{op:">=",type:d.GTE},{op:"<=",type:d.LTE},{op:"==",type:d.EQ},{op:"!=",type:d.NEQ},{op:">",type:d.GT},{op:"<",type:d.LT},{op:" in ",type:d.IN}];for(let{op:o,type:i}of n){let s=ue(e,o);if(s!==-1)return{type:u.BINARY,op:i,left:x(e.substring(0,s).trim()),right:x(e.substring(s+o.length).trim())}}return e.startsWith("!")?{type:u.UNARY,op:L.NOT,operand:x(e.substring(1).trim())}:Yt(e)},ue=(e,t)=>{let r=0,n=0;for(;n<=e.length-t.length;){if(e[n]==="(")r++;else if(e[n]===")")r--;else if(r===0&&e.substring(n,n+t.length)===t)return n;n++}return-1},Yt=e=>{if(e=e.trim(),e==="true")return{type:u.LITERAL,value:!0};if(e==="false")return{type:u.LITERAL,value:!1};if(e==="null")return{type:u.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:u.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:u.LITERAL,value:""};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:u.LITERAL,value:t}:{type:u.VARIABLE,path:e}},We=(e,t,r)=>{let n=e.substring(5).trim();Re(n);let o=n.match(/^(.+?)\s+in\s+(.+)$/);if(!o)throw new g(`Invalid loop syntax - missing 'in' keyword (got: '$for ${n}')`);let i=o[1].trim(),s=o[2].trim(),c,a=null;if(i.includes(",")){let p=i.split(",").map(_=>_.trim());if(p.length!==2)throw new g(`Invalid loop variables: ${i}. Expected format: "item" or "item, index"`);c=p[0],a=p[1]}else c=i;let l={type:u.VARIABLE,path:s},f=w(t,r);return{type:u.LOOP,itemVar:c,indexVar:a,iterable:l,body:f}};var Jt=(e,t={})=>{let{functions:r={}}=t;return w(e,r)},le=Jt;var fe={};N(fe,{now:()=>Xt});var Xt=()=>Date.now();var Gt=(e,t,r={})=>{let{functions:n={}}=r,o={...fe,...n},i=le(e,{functions:o});return ce(i,t,o)},U=Gt;var Kt=()=>({elements:[],transitions:[]}),Be=({elements:e},{screen:t})=>{e.push({id:"bg-screen",type:"rect",x:0,width:t.width,y:0,height:t.height,fill:t.backgroundColor,clickEventName:"LeftClick",rightClickEventName:"RightClick",wheelEventName:"ScrollUp"})},Ye=({elements:e,transitions:t},{presentationState:r,resources:n,ui:o,resolveFile:i})=>{if(r.background){if(r.background.resourceId&&r.background.resourceType==="image"){let s=n.images[r.background.resourceId];e.push({id:"bg-cg",type:"sprite",x:0,y:0,url:i(s.fileId)})}if(r.background.resourceId&&r.background.resourceType==="layout"){let s=o.layouts[r.background.resourceId];e.push({id:"bg-cg",type:"container",children:s.elements})}if(r.background.animations){if(r.background.animations.in){let s=n.animations[r.background.animations.in];t.push({id:"bg-cg-animation",type:"keyframes",event:"add",elementId:"bg-cg",properties:s.properties})}if(r.background.animations.out){let s=n.animations[r.background.animations.out];s&&t.push({id:"bg-cg-animation-2",type:"keyframes",event:"remove",elementId:"bg-cg",properties:s.properties})}}}},Je=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:o})=>{if(r.character){let i=r.character.items;for(let s of i){let{transformId:c,sprites:a}=s,l=a.map(({imageId:y})=>y),f=n.transforms[c],p={type:"container",id:`character-container-${s.id}`,x:f.x,y:f.y,anchorX:f.anchorX,anchorY:f.anchorY,rotation:f.rotation,scaleX:f.scaleX,scaleY:f.scaleY,children:[]},_=[];Object.entries(n.characters).flatMap(([y,m])=>{let{sprites:J}=m;Object.entries(J).map(([xe,Et])=>{l.includes(xe)&&_.push({partId:xe,fileId:Et.fileId})})});for(let y of _)p.children.push({type:"sprite",id:`${s.id}-${y.partId}`,url:o(y.fileId),x:0,y:0});e.push(p)}}},Xe=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:o})=>{if(r.visual){let i=r.visual.items;for(let s of i){if(s.resourceId&&s.resourceType){let c;if(s.resourceType==="image")c=n.images[s.resourceId];else continue;if(c){let a=n.transforms[s.transformId];e.push({id:`visual-${s.id}`,type:"sprite",url:o(c.fileId),x:a.x,y:a.y,anchorX:a.anchorX,anchorY:a.anchorY,rotation:a.rotation,scaleX:a.scaleX,scaleY:a.scaleY})}}if(s.animations){if(s.animations.in){let c=n.animations[s.animations.in];t.push({id:`${s.id}-animation`,type:"keyframes",event:"add",elementId:`visual-${s.id}`,properties:c.properties})}if(s.animations.out){let c=n.animations[s.animations.out];t.push({id:`${s.id}-animation-2`,type:"keyframes",event:"remove",elementId:`visual-${s.id}`,properties:c.properties})}}}}},Ge=({elements:e},{presentationState:t,ui:r,resources:n,dialogueUIHidden:o})=>{if(!t.dialogue||o)return;let i=r.layouts[t.dialogue.layoutId];if(!i)return;let s;t.dialogue.characterId&&(s=n.characters[t.dialogue.characterId]),t.dialogue.character&&(s={...s,name:t.dialogue.character.name});let c={elements:i.elements},l=U(c,{dialogue:{character:{name:s?.name||""},content:t.dialogue.content}})?.elements;if(Array.isArray(l))for(let f of l)e.push(structuredClone(f));else l&&e.push(structuredClone(l))},Ke=({elements:e,transitions:t},{presentationState:r,resources:n,ui:o})=>{if(r.choice){let s={elements:o.layouts[r.choice.layoutId].elements},a=U(s,{choice:{items:r.choice.items}})?.elements;if(Array.isArray(a))for(let l of a)e.push(structuredClone(l));else a&&e.push(structuredClone(a))}},He=({elements:e},{presentationState:t,resources:r,resolveFile:n})=>{if(t.bgm){let o=r.audio[t.bgm.audioId];e.push({id:"bgm",type:"audio",url:n(o.fileId)})}},Qe=({elements:e},{presentationState:t,resources:r,resolveFile:n})=>{if(t.sfx){let o=t.sfx.items;for(let i of o){let s=r.audio[i.audioId];e.push({id:i.id,type:"audio",url:n(s.fileId)})}}},pe=[Be,Ye,Je,Xe,Ge,Ke,He,Qe];var ye={};N(ye,{applyAnimation:()=>ot,applyBackground:()=>qe,applyBgm:()=>et,applyCharacter:()=>nt,applyChoice:()=>it,applyCleanAll:()=>ct,applyDialogue:()=>rt,applyLayout:()=>st,applySfx:()=>Ze,applyVisual:()=>tt,createInitialState:()=>Ht,default:()=>he});var qe=(e,t)=>{t.background&&(e.background={...t.background})},Ze=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},et=(e,t)=>{if(t.bgm){if(!t.bgm.audioId){e.bgm=void 0;return}e.bgm={...t.bgm,loop:t.bgm.loop||t.bgm.loop===void 0}}},tt=(e,t)=>{t.visual&&(e.visual=t.visual)},rt=(e,t)=>{t.dialogue&&(e.dialogue||(e.dialogue={}),Object.assign(e.dialogue,t.dialogue),t.dialogue.content&&delete e.dialogue.segments,t.dialogue.character&&!t.dialogue.character.characterName&&e.dialogue.character&&delete e.dialogue.character.characterName)},nt=(e,t)=>{if(t.character){if(!e.character){e.character=JSON.parse(JSON.stringify(t.character));return}Object.assign(e.character,t.character),e.character.items||(e.character.items=[]);for(let r=0;r<e.character.items.length;r++){let n=e.character.items[r],o=t.character.items.find(i=>i.id===n.id);o?(Object.assign(n,o),o.inAnimation||delete n.inAnimation,o.outAnimation||delete n.outAnimation):delete n.inAnimation}t.character.items.forEach(r=>{e.character.items.some(n=>n.id===r.id)||e.character.items.push(r)})}},ot=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},st=(e,t)=>{t.layout?e.layout=t.layout:e.layout&&delete e.layout},it=(e,t)=>{t.choice?e.choice=t.choice:e.choice&&delete e.choice},ct=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(r=>{delete e[r]})},Ht=()=>({}),he=[ct,qe,Ze,et,tt,rt,nt,ot,st,it];var ge={};N(ge,{clearCurrentMode:()=>fr,clearPendingEffects:()=>or,createInitialState:()=>Qt,goToSectionScene:()=>ar,lineCompleted:()=>sr,loadVnData:()=>mr,nextLine:()=>ir,prevLine:()=>cr,saveVnData:()=>yr,selectAutoMode:()=>B,selectAutoNext:()=>ut,selectCurrentPointer:()=>me,selectCurrentPreset:()=>Zt,selectCurrentPresetId:()=>at,selectDialogueUIHidden:()=>rr,selectHistory:()=>lt,selectPendingEffects:()=>qt,selectPointerMode:()=>Y,selectPointers:()=>er,selectRuntimeState:()=>tr,selectSaveData:()=>pt,selectSkipMode:()=>W,selectSpecificPointer:()=>ft,selectVariables:()=>nr,setPreset:()=>lr,startAutoMode:()=>dt,startSkipMode:()=>yt,stopAutoMode:()=>ht,stopSkipMode:()=>mt,toggleAutoMode:()=>pr,toggleDialogueUIHidden:()=>hr,toggleSkipMode:()=>dr,updateVariable:()=>ur});var Qt=({sectionId:e,lineId:t,presetId:r,autoNext:n,saveData:o,variables:i})=>{let s={pendingEffects:[],variables:i,saveData:o,story:{lastLineAction:void 0,dialogueUIHidden:!1,currentPointer:"read",autoNext:n,autoMode:!1,skipMode:!1,pointers:{read:{presetId:r,sectionId:e,lineId:t},menu:{presetId:"3ijasdk3",sectionId:void 0,lineId:void 0},history:{presetId:r,sectionId:void 0,lineId:void 0,historyEntryIndex:void 0}},history:{entries:[]}}};return s.story.history.entries.push({sectionId:e}),s},qt=({state:e})=>e.pendingEffects,me=({state:e})=>e.story.pointers[e.story.currentPointer],at=({state:e})=>e.story.pointers[e.story.currentPointer].presetId,Zt=({state:e,projectDataStore:t})=>{let r=at({state:e});return t.selectPreset(r)},W=({state:e})=>e.story.skipMode,B=({state:e})=>e.story.autoMode,er=({state:e})=>e.story.pointers,ut=({state:e})=>e.story.autoNext,tr=({state:e})=>e.runtimeState,Y=({state:e})=>e.story.currentPointer,rr=({state:e})=>e.story.dialogueUIHidden,lt=({state:e})=>e.story.history,ft=({state:e,mode:t})=>e.story.pointers[t],pt=({state:e})=>e.saveData,nr=({state:e})=>e.variables,or=({state:e})=>{e.pendingEffects=[]},sr=({state:e,projectDataStore:t})=>{let r=B(e),{pendingEffects:n}=e;if(r){n.push({name:"systemInstructions",options:{delay:1e3,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}if(W(e)){n.push({name:"systemInstructions",options:{delay:300,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}let i=ut(e);if(!i)return;let{nextTrigger:s,delay:c}=i;switch(s){case"onComplete":delete e.story.autoNext;break;case"fromComplete":n.push({name:"systemInstructions",options:{delay:c,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});break;case"manual":delete e.story.autoNext;break;default:delete e.story.autoNext;break}},ir=({state:e,projectDataStore:t})=>{let{pendingEffects:r}=e,n=me({state:e}),o=Y({state:e}),i=t.selectSectionLines(n.sectionId),s=i.findIndex(a=>a.id===n.lineId),c=i[s+1];c&&(e.story.pointers[e.story.currentPointer].lineId=c.id,r.push({name:"render"}))},cr=({state:e,projectDataStore:t})=>{let r=Y({state:e}),n=me({state:e}),o=t.selectSectionLines(n.sectionId),i=o.findIndex(c=>c.id===n.lineId),s=o[i-1];if(!s){if(r==="history"){if(e.story.historyEntryIndex>0)e.story.historyEntryIndex--;else return;e.story.pointers.history.sectionId=e.story.history.entries[e.story.historyEntryIndex].sectionId;let c=t.selectSectionLines(e.story.pointers.history.sectionId);e.story.pointers.history.lineId=c[c.length-1].id,e.story.lastLineAction="prevLine",e.pendingEffects.push({name:"render"})}return}r==="read"&&(e.story.currentPointer="history",e.story.historyEntryIndex=e.story.history.entries.length-1),e.story.pointers.history.lineId=s.id,e.story.pointers.history.sectionId=n.sectionId,e.story.lastLineAction="prevLine",e.pendingEffects.push({name:"render"})},ar=({state:e,projectDataStore:t},r)=>{let{sectionId:n,sceneId:o,mode:i,presetId:s}=r,c=t.selectSectionLines(n);i&&(e.story.currentPointer=i);let a=Y({state:e});a==="read"?e.story.history.entries.push({sectionId:n}):a==="history"&&n===e.story.history.entries[e.story.historyEntryIndex+1].sectionId&&e.story.historyEntryIndex++,e.story.pointers[a].sectionId=n,e.story.pointers[a].sceneId=o,e.story.pointers[a].lineId=c[0].id,e.story.autoNext=c[0].autoNext,s&&(e.story.pointers[a].presetId=s),e.pendingEffects.push({name:"render"})},ur=({state:e,projectDataStore:t},r)=>{let{operations:n}=r;for(let o of n){let{variableId:i,op:s,value:c}=o;s==="set"?e.variables[i]=c:s==="add"?e.variables[i]=(e.variables[i]||0)+c:s==="subtract"?e.variables[i]=(e.variables[i]||0)-c:s==="multiply"?e.variables[i]=(e.variables[i]||0)*c:s==="divide"?e.variables[i]=(e.variables[i]||0)/c:s==="increment"?e.variables[i]=(e.variables[i]||0)+1:s==="decrement"&&(e.variables[i]=(e.variables[i]||0)-1)}e.pendingEffects.push({name:"render"})},lr=({state:e},t)=>{e.story.pointers[e.story.currentPointer].presetId=t.presetId},fr=({state:e},t)=>{e.story.currentPointer=t.mode,e.pendingEffects.push({name:"render"})},dt=({state:e})=>{W({state:e})&&(e.story.skipMode=!1),e.story.autoMode=!0,e.pendingEffects.push({name:"cancelTimerEffect"}),e.pendingEffects.push({name:"systemInstructions",options:{delay:1e3,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}})},ht=({state:e})=>{e.story.autoMode=!1,e.pendingEffects.push({name:"cancelTimerEffect"})},pr=({state:e})=>{B({state:e})?ht({state:e}):dt({state:e})},yt=({state:e})=>{B({state:e})&&(e.story.autoMode=!1),e.story.skipMode=!0,e.pendingEffects.push({name:"cancelTimerEffect"}),e.pendingEffects.push({name:"systemInstructions",options:{delay:300,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}})},mt=({state:e})=>{e.story.skipMode=!1,e.pendingEffects.push({name:"cancelTimerEffect"})},dr=({state:e})=>{W({state:e})?mt({state:e}):yt({state:e})},hr=({state:e})=>{e.story.dialogueUIHidden=!e.story.dialogueUIHidden,e.pendingEffects.push({name:"render"})},yr=({state:e},t)=>{e.saveData.push({id:Date.now().toString().slice(4,10),slotIndex:t.slotIndex,pointer:ft({state:e,mode:"read"}),history:lt({state:e})}),e.pendingEffects.push({name:"saveVnData",options:{saveData:[...e.saveData]}})},mr=({state:e},t)=>{let{slotIndex:r}=t,o=pt({state:e}).filter(c=>c.slotIndex===r);if(o.length===0){console.warn(`No save data found for slot index ${r}`);return}let{pointer:i,history:s}=o[o.length-1];e.story.currentPointer="read",e.story.pointers.read=i,e.story.history=s,e.pendingEffects.push({name:"render"})};var _e={};N(_e,{createInitialState:()=>wr,selectInitialIds:()=>gt,selectInitialPreset:()=>_r,selectLayout:()=>Ar,selectPreset:()=>Ir,selectPresets:()=>gr,selectResources:()=>br,selectScreen:()=>Er,selectSectionLines:()=>Sr,selectUi:()=>xr,selectVariables:()=>vr});var gr=e=>e.presets,_r=e=>e.presets[e.story.initialPresetId],Ir=(e,t)=>e.presets[t],Er=e=>e.screen,br=e=>e.resources,xr=e=>e.ui,Ar=e=>e.layout,gt=e=>{let t=e.story.scenes[e.story.initialSceneId],r=t.sections[t.initialSectionId];return{sceneId:e.story.initialSceneId,sectionId:t.initialSectionId,presetId:e.story.initialPresetId,lineId:r.lines[0].id,autoNext:r.lines[0].autoNext}},vr=e=>e.variables||{},Sr=(e,t,r)=>{let o=Object.values(e.story.scenes).flatMap(i=>Object.entries(i.sections).map(([s,c])=>({...c,id:s}))).find(i=>i.id===t);if(r){let i=o.lines.findIndex(s=>s.id===r);return o.lines.slice(0,i+1)}return o.lines},wr=e=>{let t=gt(e),{sectionId:r,lineId:n}=t;if(!r||!n)throw new Error("No initial sectionId found");return e};var{createInitialState:Or}=ye,{createInitialState:Pr}=de,{createInitialState:$r,...Nr}=ge,{createInitialState:dn,...kr}=_e,_t=e=>oe(e,kr),It=(e,t)=>oe($r({sectionId:e.sectionId,lineId:e.lineId,presetId:e.presetId,autoNext:e.autoNext,saveData:{},variables:{}}),Nr,{transformActionFirstArgument:r=>({state:r,projectDataStore:t}),transformSelectorFirstArgument:r=>({state:r,projectDataStore:t})}),Ie=se(Or,he),Ee=se(Pr,pe);var be=class{_projectDataStore;_systemStore;_constructRenderState;_constructPresentationState;_applySystemInstruction;_eventCallback=()=>{};constructor(){}init=({projectData:t})=>{this._projectDataStore=_t(t);let r=this._projectDataStore.selectInitialIds();this._systemStore=It(r,this._projectDataStore),this._constructPresentationState=Ie,this._constructRenderState=Ee,this._render()};onEvent=t=>(this._eventCallback=t,this);offEvent=()=>(this._eventCallback=()=>{},this);handleEvent=t=>{let{eventType:r,payload:n}=t,s=(this._systemStore.selectCurrentPreset()?.eventsMap||{})[r]?.systemActions,c=s?Object.keys(s)[0]:null;c&&typeof this._systemStore[c]=="function"?this._systemStore[c](n):c&&console.error(`Method ${c} not found on system store`),this._systemStore.selectPendingEffects().forEach(l=>{l.name==="render"&&(this._processSystemActions(),this._render())}),this._systemStore.clearPendingEffects()};_processSystemActions=()=>{let t=this._systemStore.selectCurrentPointer(),r=this._projectDataStore.selectSectionLines(t.sectionId,t.lineId);r.length&&r.forEach(n=>{n.system&&Object.keys(n.system).forEach(o=>{typeof this._systemStore[o]=="function"?this._systemStore[o](n.system[o]):console.error(`System action ${o} not found on system store`)})})};_render=()=>{let t=this._systemStore.selectCurrentPointer(),r=this._projectDataStore.selectSectionLines(t.sectionId,t.lineId);if(!r.length){console.warn(`No lines found for section: ${t.sectionId}, line: ${t.lineId}`);return}let n=r.map(s=>s.presentation||{}),o=this._constructPresentationState(n),i=this._constructRenderState({presentationState:o,screen:this._projectDataStore.selectScreen(),resolveFile:s=>`file:${s}`,resources:this._projectDataStore.selectResources(),ui:this._projectDataStore.selectUi()});this._eventCallback({eventType:"render",payload:i})}},Cr=be;export{Cr as RouteEngine,Ie as constructPresentationState,Ee as constructRenderState};
|
|
1
|
+
var St=Object.defineProperty;var V=(e,t)=>{for(var r in t)St(e,r,{get:t[r],enumerable:!0})};var Re=Symbol.for("immer-nothing"),Le=Symbol.for("immer-draftable"),x=Symbol.for("immer-state");function L(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var T=Object.getPrototypeOf;function C(e){return!!e&&!!e[x]}function $(e){return e?Te(e)||Array.isArray(e)||!!e[Le]||!!e.constructor?.[Le]||K(e)||J(e):!1}var Ot=Object.prototype.constructor.toString();function Te(e){if(!e||typeof e!="object")return!1;let t=T(e);if(t===null)return!0;let r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object?!0:typeof r=="function"&&Function.toString.call(r)===Ot}function W(e,t){z(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function z(e){let t=e[x];return t?t.type_:Array.isArray(e)?1:K(e)?2:J(e)?3:0}function ne(e,t){return z(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Ce(e,t,r){let n=z(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function Lt(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function K(e){return e instanceof Map}function J(e){return e instanceof Set}function P(e){return e.copy_||e.base_}function se(e,t){if(K(e))return new Map(e);if(J(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let r=Te(e);if(t===!0||t==="class_only"&&!r){let n=Object.getOwnPropertyDescriptors(e);delete n[x];let s=Reflect.ownKeys(n);for(let o=0;o<s.length;o++){let i=s[o],c=n[i];c.writable===!1&&(c.writable=!0,c.configurable=!0),(c.get||c.set)&&(n[i]={configurable:!0,writable:!0,enumerable:c.enumerable,value:e[i]})}return Object.create(T(e),n)}else{let n=T(e);if(n!==null&&r)return{...e};let s=Object.create(n);return Object.assign(s,e)}}function le(e,t=!1){return Y(e)||C(e)||!$(e)||(z(e)>1&&(e.set=e.add=e.clear=e.delete=kt),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>le(n,!0))),e}function kt(){L(2)}function Y(e){return Object.isFrozen(e)}var Nt={};function R(e){let t=Nt[e];return t||L(0,e),t}var M;function De(){return M}function Pt(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function ke(e,t){t&&(R("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function ie(e){oe(e),e.drafts_.forEach($t),e.drafts_=null}function oe(e){e===M&&(M=e.parent_)}function Ne(e){return M=Pt(M,e)}function $t(e){let t=e[x];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Pe(e,t){t.unfinalizedDrafts_=t.drafts_.length;let r=t.drafts_[0];return e!==void 0&&e!==r?(r[x].modified_&&(ie(t),L(4)),$(e)&&(e=j(t,e),t.parent_||U(t,e)),t.patches_&&R("Patches").generateReplacementPatches_(r[x].base_,e,t.patches_,t.inversePatches_)):e=j(t,r,[]),ie(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Re?e:void 0}function j(e,t,r){if(Y(t))return t;let n=t[x];if(!n)return W(t,(s,o)=>$e(e,n,t,s,o,r)),t;if(n.scope_!==e)return t;if(!n.modified_)return U(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;let s=n.copy_,o=s,i=!1;n.type_===3&&(o=new Set(s),s.clear(),i=!0),W(o,(c,a)=>$e(e,n,s,c,a,r,i)),U(e,s,!1),r&&e.patches_&&R("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function $e(e,t,r,n,s,o,i){if(C(s)){let c=o&&t&&t.type_!==3&&!ne(t.assigned_,n)?o.concat(n):void 0,a=j(e,s,c);if(Ce(r,n,a),C(a))e.canAutoFreeze_=!1;else return}else i&&r.add(s);if($(s)&&!Y(s)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;j(e,s),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&U(e,s)}}function U(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&le(t,r)}function Rt(e,t){let r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:De(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},s=n,o=ue;r&&(s=[n],o=B);let{revoke:i,proxy:c}=Proxy.revocable(s,o);return n.draft_=c,n.revoke_=i,c}var ue={get(e,t){if(t===x)return e;let r=P(e);if(!ne(r,t))return Tt(e,r,t);let n=r[t];return e.finalized_||!$(n)?n:n===te(e.base_,t)?(re(e),e.copy_[t]=ae(n,e)):n},has(e,t){return t in P(e)},ownKeys(e){return Reflect.ownKeys(P(e))},set(e,t,r){let n=Ve(P(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){let s=te(P(e),t),o=s?.[x];if(o&&o.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(Lt(r,s)&&(r!==void 0||ne(e.base_,t)))return!0;re(e),ce(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty(e,t){return te(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,re(e),ce(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let r=P(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty(){L(11)},getPrototypeOf(e){return T(e.base_)},setPrototypeOf(){L(12)}},B={};W(ue,(e,t)=>{B[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});B.deleteProperty=function(e,t){return B.set.call(this,e,t,void 0)};B.set=function(e,t,r){return ue.set.call(this,e[0],t,r,e[0])};function te(e,t){let r=e[x];return(r?P(r):e)[t]}function Tt(e,t,r){let n=Ve(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}function Ve(e,t){if(!(t in e))return;let r=T(e);for(;r;){let n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=T(r)}}function ce(e){e.modified_||(e.modified_=!0,e.parent_&&ce(e.parent_))}function re(e){e.copy_||(e.copy_=se(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Ct=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,r,n)=>{if(typeof t=="function"&&typeof r!="function"){let o=r;r=t;let i=this;return function(a=o,...l){return i.produce(a,u=>r.call(this,u,...l))}}typeof r!="function"&&L(6),n!==void 0&&typeof n!="function"&&L(7);let s;if($(t)){let o=Ne(this),i=ae(t,void 0),c=!0;try{s=r(i),c=!1}finally{c?ie(o):oe(o)}return ke(o,n),Pe(s,o)}else if(!t||typeof t!="object"){if(s=r(t),s===void 0&&(s=t),s===Re&&(s=void 0),this.autoFreeze_&&le(s,!0),n){let o=[],i=[];R("Patches").generateReplacementPatches_(t,s,o,i),n(o,i)}return s}else L(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(i,...c)=>this.produceWithPatches(i,a=>t(a,...c));let n,s;return[this.produce(t,r,(i,c)=>{n=i,s=c}),n,s]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){$(e)||L(8),C(e)&&(e=Dt(e));let t=Ne(this),r=ae(e,void 0);return r[x].isManual_=!0,oe(t),r}finishDraft(e,t){let r=e&&e[x];(!r||!r.isManual_)&&L(9);let{scope_:n}=r;return ke(n,t),Pe(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){let s=t[r];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}r>-1&&(t=t.slice(r+1));let n=R("Patches").applyPatches_;return C(e)?n(e,t):this.produce(e,s=>n(s,t))}};function ae(e,t){let r=K(e)?R("MapSet").proxyMap_(e,t):J(e)?R("MapSet").proxySet_(e,t):Rt(e,t);return(t?t.scope_:De()).drafts_.push(r),r}function Dt(e){return C(e)||L(10,e),Me(e)}function Me(e){if(!$(e)||Y(e))return e;let t=e[x],r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=se(e,t.scope_.immer_.useStrictShallowCopy_)}else r=se(e,!0);return W(r,(n,s)=>{Ce(r,n,Me(s))}),t&&(t.finalized_=!1),r}var S=new Ct,fe=S.produce,Hr=S.produceWithPatches.bind(S),Qr=S.setAutoFreeze.bind(S),qr=S.setUseStrictShallowCopy.bind(S),Zr=S.applyPatches.bind(S),en=S.createDraft.bind(S),tn=S.finishDraft.bind(S);var pe=(e,t,r={})=>{let n=structuredClone(e),s={},o={},{transformSelectorFirstArgument:i=a=>a,transformActionFirstArgument:c=a=>a}=r;for(let[a,l]of Object.entries(t))a!=="createInitialState"&&(a.startsWith("select")?s[a]=(...u)=>l(i(n),...u):o[a]=(...u)=>{n=fe(n,d=>l(c(d),...u))});return{...s,...o}},de=(e,t)=>r=>{let n=e(),s=Array.isArray(r)?r:[r];return fe(n,o=>{s.forEach(i=>{t.forEach(c=>{c(o,i)})})})};var _e={};V(_e,{addBackgrundOrCg:()=>Qe,addBgm:()=>rt,addCharacters:()=>qe,addChoices:()=>tt,addDialogue:()=>et,addSfx:()=>nt,addVisuals:()=>Ze,createInitialState:()=>fr,default:()=>Ie,generateScreenBackgroundElement:()=>He});var f={LITERAL:0,VARIABLE:1,INTERPOLATION:2,FUNCTION:3,BINARY:4,UNARY:5,CONDITIONAL:6,LOOP:7,OBJECT:8,ARRAY:9,PARTIAL:10},E={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8},F={NOT:0};var v=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},k=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var he=e=>{if(!e||e.trim()==="")throw new v("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let r=e.includes("===")?"==":"!=";throw new v(`Invalid comparison operator '${e.includes("===")?"===":"!=="}' - did you mean '${r}'? (got: '${e}')`)}let t=["<",">","<=",">=","==","!="];for(let r of t)if(e.trim().endsWith(r))throw new v(`Incomplete comparison expression - missing right operand (got: '${e}')`)},Be=e=>{if(e.trim().endsWith(" in"))throw new v(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new v(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,r]=e.split(" in ");if(!r||r.trim()==="")throw new v(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(t.includes(",")){let n=t.split(",").map(s=>s.trim());for(let s of n)if(!s)throw new v(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`)}else if(!t.trim())throw new v(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`)};var Fe=(e,t)=>{if(t===null)return new k(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new k(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return new k(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},We=(e,t)=>{let r=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new k(`Unknown function '${e}' (${r})`)};var Vt=(e,t,r={})=>{let n={},s={};r&&typeof r=="object"&&(r.functions!==void 0||r.partials!==void 0?(n=r.functions||{},s=r.partials||{}):typeof r=="object"&&(n=r));let o=I(e,{functions:n,partials:s},t,{});return o===void 0?{}:o},I=(e,t,r,n)=>{let s=t.functions||t;if(e.var&&!e.type)return w(e.var,r,n);if(e.type===f.LITERAL)return e.value;if(e.type===f.VARIABLE)return w(e.path,r,n);if(e.type===f.INTERPOLATION)return Bt(e.parts,t,r,n);switch(e.type){case f.FUNCTION:return Ue(e,t,r,n);case f.BINARY:return ze(e,t,r,n);case f.UNARY:return Ke(e,t,r,n);case f.CONDITIONAL:return Wt(e,t,r,n);case f.LOOP:return Jt(e,t,r,n);case f.OBJECT:return Xt(e,t,r,n);case f.ARRAY:return Gt(e,t,r,n);case f.PARTIAL:return Ht(e,t,r,n);default:throw new Error(`Unknown node type: ${e.type}`)}},je=new Map,Mt=e=>{let t=[],r="",n=!1;for(let s=0;s<e.length;s++){let o=e[s];if(o==="[")r&&(t.push({type:"property",value:r}),r=""),n=!0;else if(o==="]"){if(n&&r){let i=r.trim();/^\d+$/.test(i)?t.push({type:"index",value:parseInt(i,10)}):t.push({type:"property",value:`[${r}]`}),r=""}n=!1}else r+=o}return r&&t.push({type:"property",value:r}),t},w=(e,t,r)=>{if(!e)return;if(e in r)return r[e];let n=je.get(e);if(!n){let o=[],i="",c=0;for(let a=0;a<e.length;a++){let l=e[a];l==="["?(c++,i+=l):l==="]"?(c--,i+=l):l==="."&&c===0?i&&(o.push(i),i=""):i+=l}i&&o.push(i),n=[];for(let a of o){let l=Mt(a.trim());n.push(...l)}je.set(e,n)}let s=t;for(let o=0;o<n.length;o++){let i=n[o];if(i.type==="property"&&i.value in r){s=r[i.value];continue}if(s==null)return;(i.type==="property"||i.type==="index")&&(s=s[i.value])}return s},Bt=(e,t,r,n)=>{let s=[];for(let o of e)if(typeof o=="string")s.push(o);else{let i=I(o,t,r,n);s.push(i!=null?String(i):"")}return s.join("")},Ue=(e,t,r,n)=>{let s=t.functions||t,o=s[e.name];if(!o)throw We(e.name,s);let i=e.args.map(c=>I(c,t,r,n));return o(...i)},D=(e,t,r,n)=>{if(e.var&&!e.type)return w(e.var,r,n);switch(e.type){case f.VARIABLE:return w(e.path,r,n);case f.LITERAL:return e.value;case f.BINARY:return ze(e,t,r,n);case f.UNARY:return Ke(e,t,r,n);case f.FUNCTION:return Ue(e,t,r,n);default:return I(e,t,r,n)}},ze=(e,t,r,n)=>{if(e.op===E.AND||e.op===E.OR){let i=D(e.left,t,r,n),c=D(e.right,t,r,n);switch(e.op){case E.AND:return i&&c;case E.OR:return i||c}}let s=I(e.left,t,r,n),o=I(e.right,t,r,n);switch(e.op){case E.EQ:return s==o;case E.NEQ:return s!=o;case E.GT:return s>o;case E.LT:return s<o;case E.GTE:return s>=o;case E.LTE:return s<=o;case E.IN:return Array.isArray(o)?o.includes(s):!1;default:throw new Error(`Unknown binary operator: ${e.op}`)}},Ke=(e,t,r,n)=>{let s=e.op===F.NOT?D(e.operand,t,r,n):I(e.operand,t,r,n);switch(e.op){case F.NOT:return!s;default:throw new Error(`Unknown unary operator: ${e.op}`)}},Ft=(e,t,r,n)=>{if(e.conditions.length===2&&e.conditions[1]===null){let s=e.conditions[0];if(s.type===f.VARIABLE)if(w(s.path,r,n)){let i=e.bodies[0];if(i.type===f.OBJECT&&i.properties.length<=5){let c={};for(let a of i.properties){let l=a.parsedKey?I(a.parsedKey,t,r,n):a.key,u=a.value;if(u.type===f.LITERAL)c[l]=u.value;else if(u.type===f.VARIABLE)c[l]=w(u.path,r,n);else if(u.type===f.INTERPOLATION){let p=[];for(let d of u.parts)if(typeof d=="string")p.push(d);else if(d.type===f.VARIABLE){let h=w(d.path,r,n);p.push(h!=null?String(h):"")}else{let h=I(d,t,r,n);p.push(h!=null?String(h):"")}c[l]=p.join("")}else c[l]=I(u,t,r,n)}return c}}else{let i=e.bodies[1];if(i.type===f.OBJECT&&i.properties.length<=5){let c={};for(let a of i.properties){let l=a.parsedKey?I(a.parsedKey,t,r,n):a.key,u=a.value;if(u.type===f.LITERAL)c[l]=u.value;else if(u.type===f.VARIABLE)c[l]=w(u.path,r,n);else if(u.type===f.INTERPOLATION){let p=[];for(let d of u.parts)if(typeof d=="string")p.push(d);else if(d.type===f.VARIABLE){let h=w(d.path,r,n);p.push(h!=null?String(h):"")}else{let h=I(d,t,r,n);p.push(h!=null?String(h):"")}c[l]=p.join("")}else c[l]=I(u,t,r,n)}return c}}}return null},Wt=(e,t,r,n)=>{let s=Ft(e,t,r,n);if(s!==null)return s;for(let o=0;o<e.conditions.length;o++){let i=e.conditions[o];if(i===null||D(i,t,r,n))return I(e.bodies[o],t,r,n)}return Je},jt=(e,t)=>{let r=e.body,n=e.itemVar;if(r.type===f.CONDITIONAL&&r.conditions.length===1&&r.conditions[0].type===f.VARIABLE){let s=r.conditions[0].path,o=r.bodies[0];if(s.startsWith(n+".")){let i=s.substring(n.length+1);if(o.type===f.OBJECT&&o.properties.length<=5){for(let a of o.properties)if(a.parsedKey)return null;let c=[];for(let a=0;a<t.length;a++){let l=t[a];if(l[i]){let u={};for(let p of o.properties){let d=p.key,h=p.value;if(h.type===f.LITERAL)u[d]=h.value;else if(h.type===f.VARIABLE){let y=h.path;if(y===n)u[d]=l;else if(y.startsWith(n+".")){let m=y.substring(n.length+1);u[d]=l[m]}else return null}else if(h.type===f.INTERPOLATION){let y=[],m=!0;for(let A of h.parts)if(typeof A=="string")y.push(A);else if(A.type===f.VARIABLE){let g=A.path;if(g===n)y.push(l!=null?String(l):"");else if(g.startsWith(n+".")){let _=g.substring(n.length+1),b=l[_];y.push(b!=null?String(b):"")}else{m=!1;break}}else{m=!1;break}if(!m)return null;u[d]=y.join("")}else return null}c.push(u)}}return c}}}return null},Ut=(e,t)=>{let r=e.body,n=e.itemVar,s=jt(e,t);if(s!==null)return s;if(r.type===f.OBJECT&&r.properties.length<=5){for(let c of r.properties)if(c.parsedKey)return null;let o=[],i=!0;for(let c of r.properties){let a=c.key,l=c.value;if(l.type===f.LITERAL)o.push({key:a,type:"literal",value:l.value});else if(l.type===f.VARIABLE){let u=l.path;if(u===n)o.push({key:a,type:"item"});else if(u.startsWith(n+".")){let p=u.substring(n.length+1);if(!p.includes(".")&&!p.includes("["))o.push({key:a,type:"prop",prop:p});else{i=!1;break}}else{i=!1;break}}else if(l.type===f.INTERPOLATION&&l.parts.length===1){let u=l.parts[0];if(u.type===f.VARIABLE){let p=u.path;if(p===n)o.push({key:a,type:"item_string"});else if(p.startsWith(n+".")){let d=p.substring(n.length+1);if(!d.includes(".")&&!d.includes("["))o.push({key:a,type:"prop_string",prop:d});else{i=!1;break}}else{i=!1;break}}else{i=!1;break}}else{i=!1;break}}if(i){let c=new Array(t.length);if(o.length===3&&o[0].type==="prop"&&o[0].key==="id"&&o[1].type==="prop_string"&&o[1].key==="title"&&o[2].type==="prop"&&o[2].key==="completed")for(let a=0;a<t.length;a++){let l=t[a];c[a]={id:l.id,title:l.title!=null?String(l.title):"",completed:l.completed}}else for(let a=0;a<t.length;a++){let l=t[a],u={};for(let p of o)if(p.type==="literal")u[p.key]=p.value;else if(p.type==="item")u[p.key]=l;else if(p.type==="prop")u[p.key]=l[p.prop];else if(p.type==="item_string")u[p.key]=l!=null?String(l):"";else if(p.type==="prop_string"){let d=l[p.prop];u[p.key]=d!=null?String(d):""}c[a]=u}return c}}return null},zt=(e,t,r,n,s)=>{let o=[],i=e.body;if(i.type===f.OBJECT&&i.fast!==!1){let c=e.itemVar,a=e.indexVar;for(let l=0;l<s.length;l++){let u=s[l],p={},d={...n,[c]:u,...a&&{[a]:l}};for(let h of i.properties){let y=h.parsedKey?I(h.parsedKey,t,r,d):h.key,m=h.value;if(m.type===f.LITERAL)p[y]=m.value;else if(m.type===f.VARIABLE){let A=m.path;if(A===c)p[y]=u;else if(A===a)p[y]=l;else if(A.startsWith(c+".")){let g=A.substring(c.length+1);!g.includes(".")&&!g.includes("[")?p[y]=u[g]:p[y]=w(A,r,{...n,[c]:u,...a&&{[a]:l}})}else p[y]=w(A,r,{...n,[c]:u,...a&&{[a]:l}})}else if(m.type===f.INTERPOLATION){let A=[];for(let g of m.parts)if(typeof g=="string")A.push(g);else if(g.type===f.VARIABLE){let _=g.path,b;if(_===c)b=u;else if(_===a)b=l;else if(_.startsWith(c+".")){let ee=_.substring(c.length+1);!ee.includes(".")&&!ee.includes("[")?b=u[ee]:b=w(_,r,{...n,[c]:u,...a&&{[a]:l}})}else b=w(_,r,{...n,[c]:u,...a&&{[a]:l}});A.push(b!=null?String(b):"")}else{let _={...n,[c]:u,...a&&{[a]:l}},b=I(g,t,r,_);A.push(b!=null?String(b):"")}p[y]=A.join("")}else{let A={...n,[c]:u,...a&&{[a]:l}};p[y]=I(m,t,r,A)}}o.push(p)}return o}return null},Kt=(e,t,r)=>{let n=e.body;if(n.type===f.OBJECT&&n.properties.length===1&&n.properties[0].key==="$if item.visible"){let o=n.properties[0].value;if(o.type===f.CONDITIONAL&&o.conditions.length===1&&o.conditions[0].type===f.VARIABLE&&o.conditions[0].path==="item.visible"){let i=o.bodies[0];if(i.type===f.OBJECT&&i.properties.length===2){let c=i.properties[0],a=i.properties[1];if(c.key==="id"&&c.value.type===f.VARIABLE&&c.value.path==="item.id"&&a.key==="$if item.highlighted"&&a.value.type===f.CONDITIONAL){let l=[];for(let u=0;u<t.length;u++){let p=t[u];if(p.visible){let d={id:p.id};p.highlighted?(d.highlight=!0,d.message=`This item is highlighted: ${p.name}`):(d.highlight=!1,d.message=p.name),l.push(d)}}return l}}}}return null},Jt=(e,t,r,n)=>{let s=I(e.iterable,t,r,n);if(!Array.isArray(s)){let c=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${e.iterable.path}`;throw Fe(c,s)}if(!e.indexVar){let c=Kt(e,s,e.itemVar);if(c!==null)return c}if(!e.indexVar){let c=Ut(e,s);if(c!==null)return c}let o=zt(e,t,r,n,s);if(o!==null)return o;let i=[];for(let c=0;c<s.length;c++){let a=e.indexVar?{...n,[e.itemVar]:s[c],[e.indexVar]:c}:{...n,[e.itemVar]:s[c]},l=I(e.body,t,r,a);Array.isArray(l)&&l.length===1?i.push(l[0]):i.push(l)}return i},Yt=(e,t,r,n)=>{if(e.whenCondition)return null;if(e.properties.length===1){let s=e.properties[0],o=s.parsedKey?I(s.parsedKey,t,r,n):s.key,i=s.value;if(i.type===f.OBJECT&&i.properties.length<=10&&!i.whenCondition){let c={},a={},l=!0;for(let u of i.properties){let p=u.parsedKey?I(u.parsedKey,t,r,n):u.key,d=u.value;if(d.type===f.LITERAL)a[p]=d.value;else if(d.type===f.VARIABLE)a[p]=w(d.path,r,n);else if(d.type===f.INTERPOLATION){let h=[];for(let y of d.parts)if(typeof y=="string")h.push(y);else if(y.type===f.VARIABLE){let m=w(y.path,r,n);h.push(m!=null?String(m):"")}else{l=!1;break}if(!l)break;a[p]=h.join("")}else if(d.type===f.OBJECT&&d.properties.length<=5){let h={};for(let y of d.properties){let m=y.key,A=y.value;if(A.type===f.LITERAL)h[m]=A.value;else if(A.type===f.VARIABLE)h[m]=w(A.path,r,n);else if(A.type===f.INTERPOLATION){let g=[];for(let _ of A.parts)if(typeof _=="string")g.push(_);else if(_.type===f.VARIABLE){let b=w(_.path,r,n);g.push(b!=null?String(b):"")}else{l=!1;break}if(!l)break;h[m]=g.join("")}else{l=!1;break}}if(!l)break;a[p]=h}else{l=!1;break}}if(l)return c[o]=a,c}}return null},Xt=(e,t,r,n)=>{let s=t.functions||t;if(e.whenCondition&&!D(e.whenCondition,s,r,n))return;let o=Yt(e,t,r,n);if(o!==null)return o;if(e.fast){let l={};for(let u of e.properties){let p=u.parsedKey?I(u.parsedKey,t,r,n):u.key,d=u.value;if(d.type===f.LITERAL)l[p]=d.value;else if(d.type===f.VARIABLE)l[p]=w(d.path,r,n);else if(d.type===f.INTERPOLATION){let h=[];for(let y of d.parts)if(typeof y=="string")h.push(y);else if(y.type===f.VARIABLE){let m=w(y.path,r,n);h.push(m!=null?String(m):"")}else{let m=I(y,t,r,n);h.push(m!=null?String(m):"")}l[p]=h.join("")}else l[p]=I(d,t,r,n)}return l}let i={},c=null,a=!1;for(let l of e.properties)if(!l.key.startsWith("$if ")&&!l.key.match(/^\$if\s+\w+.*:?$/)&&!l.key.startsWith("$elif")&&!l.key.startsWith("$else")&&!l.key.startsWith("$for ")){a=!0;break}for(let l of e.properties)if(l.key.startsWith("$if ")||l.key.match(/^\$if\s+\w+.*:?$/)){let u=I(l.value,t,r,n);if(!a&&u!==null&&u!==void 0)return Array.isArray(u)&&u.length===1?u[0]:u;typeof u=="object"&&u!==null&&!Array.isArray(u)&&Object.assign(i,u)}else if(!l.key.startsWith("$for ")){let u=l.value;if(u&&u.type===f.OBJECT&&u.properties){let p=u.properties.find(d=>d.key.startsWith("$for "));if(p){let d=I(p.value,t,r,n);d!==void 0&&(i[l.key]=d)}else{let d=I(l.value,t,r,n);d!==void 0&&(i[l.key]=d)}}else{let p=l.parsedKey?I(l.parsedKey,t,r,n):l.key,d=I(l.value,t,r,n);d!==void 0&&(i[p]=d)}}return i},Je={},Gt=(e,t,r,n)=>{let s=[];for(let o of e.items)if(o.type===f.LOOP){let i=I(o,t,r,n);s.push(i)}else{let i=I(o,t,r,n);i!==Je&&i!==void 0&&s.push(i)}return s},Ht=(e,t,r,n)=>{let{name:s,data:o,whenCondition:i}=e,c=t.partials||{},a=t.functions||t;if(i&&!D(i,a,r,n))return;if(!c[s])throw new k(`Partial '${s}' is not defined`);let l=n._partialStack||[];if(l.includes(s))throw new k(`Circular partial reference detected: ${s}`);let u=c[s],p=r,d={...n,_partialStack:[...l,s]};if(n){p={...r};for(let h of Object.keys(n))h.startsWith("_")||(p[h]=n[h])}if(o){let h=I(o,t,r,n);p={...p,...h}}return I(u,t,p,d)},ye=Vt;var Qt=/\$\{([^}]*)\}/g,Xe=e=>{let t=e.match(/^(\w+)\((.*)\)$/);if(!t)return{isFunction:!1};let[,r,n]=t,s=qt(n);return{isFunction:!0,type:f.FUNCTION,name:r,args:s}},qt=e=>e.trim()?Zt(e).map(r=>er(r.trim())):[],Zt=e=>{let t=[],r="",n=0,s=!1,o="";for(let i=0;i<e.length;i++){let c=e[i],a=i>0?e[i-1]:"";!s&&(c==='"'||c==="'")?(s=!0,o=c,r+=c):s&&c===o&&a!=="\\"?(s=!1,o="",r+=c):!s&&c==="("?(n++,r+=c):!s&&c===")"?(n--,r+=c):!s&&c===","&&n===0?(t.push(r),r=""):r+=c}return r&&t.push(r),t},er=e=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:f.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:f.LITERAL,value:parseFloat(e)};if(e==="true")return{type:f.LITERAL,value:!0};if(e==="false")return{type:f.LITERAL,value:!1};if(e==="null")return{type:f.LITERAL,value:null};let t=Xe(e);return t.isFunction?{type:t.type,name:t.name,args:t.args}:{type:f.VARIABLE,path:e}},tr=/^\w+\(.*\)$/,rr=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,nr=e=>{if(!(!e||e.trim()===""||tr.test(e))&&rr.test(e))throw e.includes("?")&&e.includes(":")?new v(`Complex expressions not supported in variable replacements - consider calculating the value in your data instead. Offending expression: "${e}"`):e.includes("||")||e.includes("&&")||e.includes("??")?new v(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new v(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},Ye=(e,t={})=>{let r=e.trim();nr(r);let n=Xe(r);if(n.isFunction)return{type:n.type,name:n.name,args:n.args};if(r.includes("[")&&!/[\s+\-*/%|&?:]/.test(r)){let s=0;for(let o of r)o==="["?s++:o==="]"&&s--;if(s!==0)throw new Error("Invalid array index syntax")}return{type:f.VARIABLE,path:r}},me=(e,t={})=>{let r=e,n=[];e.includes("\\${")&&(r=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC$1"),r=r.replace(/\\(\$\{[^}]*\})/g,(c,a)=>{let l=`__ESCAPED_${n.length}__`;return n.push(a),l}),r=r.replace(/\\DOUBLE_ESC/g,"\\"));let s=[...r.matchAll(Qt)];if(s.length===0){let c=r;for(let a=0;a<n.length;a++)c=c.replace(`__ESCAPED_${a}__`,n[a]);return{type:f.LITERAL,value:c}}if(s.length===1&&s[0][0]===r&&n.length===0)try{return Ye(s[0][1],t)}catch(c){if(c.message==="Invalid array index syntax")return{type:f.LITERAL,value:r};throw c}let o=[],i=0;for(let c of s){let[a,l]=c,u=c.index;if(u>i){let p=r.substring(i,u);for(let d=0;d<n.length;d++)p=p.replace(`__ESCAPED_${d}__`,n[d]);p&&o.push(p)}try{let p=Ye(l.trim(),t);o.push(p)}catch(p){if(p.message==="Invalid array index syntax")o.push(a);else throw p}i=u+a.length}if(i<r.length){let c=r.substring(i);for(let a=0;a<n.length;a++)c=c.replace(`__ESCAPED_${a}__`,n[a]);c&&o.push(c)}return{type:f.INTERPOLATION,parts:o}};var N=(e,t)=>typeof e=="string"?me(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?sr(e,t):ir(e,t):{type:f.LITERAL,value:e},sr=(e,t)=>{let r=[],n=!1;for(let s=0;s<e.length;s++){let o=e[s];if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let c=Object.keys(o);if(c.length===1&&c[0].startsWith("$for ")){let a=Ge(c[0],o[c[0]],t);r.push(a),n=!0;continue}}let i=N(o,t);r.push(i),(i.type===f.FUNCTION||i.type===f.CONDITIONAL||i.type===f.LOOP||i.type===f.PARTIAL||i.type===f.OBJECT&&!i.fast||i.type===f.ARRAY&&!i.fast)&&(n=!0)}return{type:f.ARRAY,items:r,fast:!n}},ir=(e,t)=>{let r=[],n=!1,s=null,o=Object.entries(e),i=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new v("$partial value must be a string");if(e.$partial.trim()==="")throw new v("$partial value cannot be an empty string");let a=["$if","$elif","$else","$for"],l=[];for(let[g]of o)for(let _ of a)if(g===_||g.startsWith(_+" ")||g.startsWith(_+"#")){l.push(_);break}if(l.length>0)throw new v(`Cannot use $partial with ${l.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:u,$when:p,...d}=e,h={},y=!1;for(let[g,_]of Object.entries(d)){let b=g;(g.startsWith("\\$")||g.startsWith("$$"))&&(b=g.slice(1)),h[b]=_,y=!0}let m=null;if(y&&(m=N(h,t),m.type===f.OBJECT)){let g=!1;for(let _ of m.properties)if(_.value.type===f.VARIABLE||_.value.type===f.INTERPOLATION||_.value.type===f.FUNCTION||_.value.type===f.CONDITIONAL||_.value.type===f.LOOP||_.value.type===f.OBJECT&&!_.value.fast||_.value.type===f.ARRAY&&!_.value.fast){g=!0;break}g&&(m.fast=!1)}let A={type:f.PARTIAL,name:u,data:m};if(p!==void 0){let g;if(typeof p=="string"){if(p.trim()==="")throw new v("Empty condition expression after '$when'");g=O(p)}else g={type:f.LITERAL,value:p};A.whenCondition=g}return A}for(let[a,l]of o)if(a==="$when"){if(s!==null)throw new v("Multiple '$when' directives on the same object are not allowed");if(l==null)throw new v("Missing condition expression after '$when'");let u=typeof l=="string"?l:JSON.stringify(l);if(u.trim()==="")throw new v("Empty condition expression after '$when'");s=O(u),n=!0}else if(a.startsWith("$when#")||a.startsWith("$when "))throw new v("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;i<o.length;){let[a,l]=o[i];if(a==="$when"){i++;continue}if(a.startsWith("$if ")||a.match(/^\$if#\w+\s/)||a.match(/^\$if\s+\w+.*:$/)){let u=or(o,i,t);r.push({key:a,value:u.node}),n=!0,i=u.nextIndex}else if(a.startsWith("$for ")){let u=Ge(a,l,t);r.push({key:a,value:u}),n=!0,i++}else{if(a.startsWith("$elif ")||a.startsWith("$else"))throw new v(`'${a.split(" ")[0]}' without matching '$if'`);if(a==="$if"||a==="$if:")throw new v("Missing condition expression after '$if'");{let u=N(l,t);(u.type===f.FUNCTION||u.type===f.CONDITIONAL||u.type===f.LOOP||u.type===f.PARTIAL||u.type===f.OBJECT&&!u.fast||u.type===f.ARRAY&&!u.fast)&&(n=!0);let p=me(a,t),d={key:a,value:u};(p.type!==f.LITERAL||p.value!==a)&&(d.parsedKey=p),r.push(d),i++}}}let c={type:f.OBJECT,properties:r,fast:!n};return s&&(c.whenCondition=s),c},or=(e,t,r={})=>{let n=[],s=[],o=t,[i,c]=e[o],a=null,l;if(i.startsWith("$if#")){let p=i.match(/^\$if#(\w+)\s+(.+)$/);if(p)a=p[1],l=p[2];else throw new v(`Invalid conditional syntax: ${i}`)}else l=i.substring(4),l.endsWith(":")&&(l=l.slice(0,-1).trim());he(l);let u=O(l);for(n.push(u),s.push(N(c,r)),o++;o<e.length;){let[p,d]=e[o],h=!1,y;if(a?p.startsWith(`$elif#${a} `)?(y=p.substring(`$elif#${a} `.length),y.endsWith(":")&&(y=y.slice(0,-1).trim()),h=!0):(p===`$else#${a}`||p===`$else#${a}:`)&&(h=!0,y=null):p.startsWith("$elif ")?(y=p.substring(6),y.endsWith(":")&&(y=y.slice(0,-1).trim()),h=!0):(p==="$else"||p==="$else:")&&(h=!0,y=null),h){if(y===null)n.push(null);else{he(y);let m=O(y);n.push(m)}if(s.push(N(d,r)),o++,y===null)break}else break}return{node:{type:f.CONDITIONAL,conditions:n,bodies:s,id:a},nextIndex:o}},O=e=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")"))return O(e.slice(1,-1));let t=X(e,"||");if(t!==-1)return{type:f.BINARY,op:E.OR,left:O(e.substring(0,t).trim()),right:O(e.substring(t+2).trim())};let r=X(e,"&&");if(r!==-1)return{type:f.BINARY,op:E.AND,left:O(e.substring(0,r).trim()),right:O(e.substring(r+2).trim())};let n=[{op:">=",type:E.GTE},{op:"<=",type:E.LTE},{op:"==",type:E.EQ},{op:"!=",type:E.NEQ},{op:">",type:E.GT},{op:"<",type:E.LT},{op:" in ",type:E.IN}];for(let{op:o,type:i}of n){let c=X(e,o);if(c!==-1)return{type:f.BINARY,op:i,left:O(e.substring(0,c).trim()),right:O(e.substring(c+o.length).trim())}}let s=[" + "," - "," * "," / "," % "];for(let o of s)if(X(e,o)!==-1)throw new v(`Arithmetic expressions not supported in conditionals - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`);return e.startsWith("!")?{type:f.UNARY,op:F.NOT,operand:O(e.substring(1).trim())}:cr(e)},X=(e,t)=>{let r=0,n=0;for(;n<=e.length-t.length;){if(e[n]==="(")r++;else if(e[n]===")")r--;else if(r===0&&e.substring(n,n+t.length)===t)return n;n++}return-1},cr=e=>{if(e=e.trim(),e==="true")return{type:f.LITERAL,value:!0};if(e==="false")return{type:f.LITERAL,value:!1};if(e==="null")return{type:f.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:f.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:f.LITERAL,value:""};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:f.LITERAL,value:t}:{type:f.VARIABLE,path:e}},Ge=(e,t,r)=>{let n=e.substring(5).trim();Be(n);let s=n.match(/^(.+?)\s+in\s+(.+)$/);if(!s)throw new v(`Invalid loop syntax - missing 'in' keyword (got: '$for ${n}')`);let o=s[1].trim(),i=s[2].trim(),c,a=null;if(o.includes(",")){let p=o.split(",").map(d=>d.trim());if(p.length!==2)throw new v(`Invalid loop variables: ${o}. Expected format: "item" or "item, index"`);c=p[0],a=p[1]}else c=o;let l={type:f.VARIABLE,path:i},u=N(t,r);return{type:f.LOOP,itemVar:c,indexVar:a,iterable:l,body:u}};var ar=(e,t={})=>{let{functions:r={}}=t;return N(e,r)},G=ar;var ge={};V(ge,{now:()=>lr});var lr=()=>Date.now();var ur=(e,t,r={})=>{let{functions:n={},partials:s={}}=r,o={...ge,...n},i=G(e,{functions:o}),c={};for(let[a,l]of Object.entries(s))c[a]=G(l,{functions:o});return ye(i,t,{functions:o,partials:c})},H=ur;var fr=()=>({elements:[],transitions:[]}),He=({elements:e},{screen:t})=>{e.push({id:"bg-screen",type:"rect",x:0,width:t.width,y:0,height:t.height,fill:t.backgroundColor,clickEventName:"LeftClick",rightClickEventName:"RightClick",wheelEventName:"ScrollUp"})},Qe=({elements:e,transitions:t},{presentationState:r,resources:n,ui:s,resolveFile:o})=>{if(r.background){if(r.background.resourceId&&r.background.resourceType==="image"){let i=n.images[r.background.resourceId];e.push({id:"bg-cg",type:"sprite",x:0,y:0,url:o(i.fileId)})}if(r.background.resourceId&&r.background.resourceType==="layout"){let i=s.layouts[r.background.resourceId];e.push({id:"bg-cg",type:"container",children:i.elements})}if(r.background.animations){if(r.background.animations.in){let i=n.animations[r.background.animations.in];t.push({id:"bg-cg-animation",type:"keyframes",event:"add",elementId:"bg-cg",properties:i.properties})}if(r.background.animations.out){let i=n.animations[r.background.animations.out];i&&t.push({id:"bg-cg-animation-2",type:"keyframes",event:"remove",elementId:"bg-cg",properties:i.properties})}}}},qe=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:s})=>{if(r.character){let o=r.character.items;for(let i of o){let{transformId:c,sprites:a}=i,l=a.map(({imageId:h})=>h),u=n.transforms[c],p={type:"container",id:`character-container-${i.id}`,x:u.x,y:u.y,anchorX:u.anchorX,anchorY:u.anchorY,rotation:u.rotation,scaleX:u.scaleX,scaleY:u.scaleY,children:[]},d=[];Object.entries(n.characters).flatMap(([h,y])=>{let{sprites:m}=y;Object.entries(m).map(([A,g])=>{l.includes(A)&&d.push({partId:A,fileId:g.fileId})})});for(let h of d)p.children.push({type:"sprite",id:`${i.id}-${h.partId}`,url:s(h.fileId),x:0,y:0});e.push(p)}}},Ze=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:s})=>{if(r.visual){let o=r.visual.items;for(let i of o){if(i.resourceId&&i.resourceType){let c;if(i.resourceType==="image")c=n.images[i.resourceId];else continue;if(c){let a=n.transforms[i.transformId];e.push({id:`visual-${i.id}`,type:"sprite",url:s(c.fileId),x:a.x,y:a.y,anchorX:a.anchorX,anchorY:a.anchorY,rotation:a.rotation,scaleX:a.scaleX,scaleY:a.scaleY})}}if(i.animations){if(i.animations.in){let c=n.animations[i.animations.in];t.push({id:`${i.id}-animation`,type:"keyframes",event:"add",elementId:`visual-${i.id}`,properties:c.properties})}if(i.animations.out){let c=n.animations[i.animations.out];t.push({id:`${i.id}-animation-2`,type:"keyframes",event:"remove",elementId:`visual-${i.id}`,properties:c.properties})}}}}},et=({elements:e},{presentationState:t,ui:r,resources:n,dialogueUIHidden:s})=>{if(!t.dialogue||s)return;let o=r.layouts[t.dialogue.layoutId];if(!o)return;let i;t.dialogue.characterId&&(i=n.characters[t.dialogue.characterId]),t.dialogue.character&&(i={...i,name:t.dialogue.character.name});let c={elements:o.elements},l=H(c,{dialogue:{character:{name:i?.name||""},content:t.dialogue.content}})?.elements;if(Array.isArray(l))for(let u of l)e.push(structuredClone(u));else l&&e.push(structuredClone(l))},tt=({elements:e,transitions:t},{presentationState:r,resources:n,ui:s})=>{if(r.choice){let i={elements:s.layouts[r.choice.layoutId].elements},a=H(i,{choice:{items:r.choice.items}})?.elements;if(Array.isArray(a))for(let l of a)e.push(structuredClone(l));else a&&e.push(structuredClone(a))}},rt=({elements:e},{presentationState:t,resources:r,resolveFile:n})=>{if(t.bgm){let s=r.audio[t.bgm.audioId];e.push({id:"bgm",type:"audio",url:n(s.fileId)})}},nt=({elements:e},{presentationState:t,resources:r,resolveFile:n})=>{if(t.sfx){let s=t.sfx.items;for(let o of s){let i=r.audio[o.audioId];e.push({id:o.id,type:"audio",url:n(i.fileId)})}}},Ie=[He,Qe,qe,Ze,et,tt,rt,nt];var ve={};V(ve,{applyAnimation:()=>ut,applyBackground:()=>st,applyBgm:()=>ot,applyCharacter:()=>lt,applyChoice:()=>pt,applyCleanAll:()=>dt,applyDialogue:()=>at,applyLayout:()=>ft,applySfx:()=>it,applyVisual:()=>ct,createInitialState:()=>pr,default:()=>Ae});var st=(e,t)=>{t.background&&(e.background={...t.background})},it=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},ot=(e,t)=>{if(t.bgm){if(!t.bgm.audioId){e.bgm=void 0;return}e.bgm={...t.bgm,loop:t.bgm.loop||t.bgm.loop===void 0}}},ct=(e,t)=>{t.visual&&(e.visual=t.visual)},at=(e,t)=>{t.dialogue&&(e.dialogue||(e.dialogue={}),Object.assign(e.dialogue,t.dialogue),t.dialogue.content&&delete e.dialogue.segments,t.dialogue.character&&!t.dialogue.character.characterName&&e.dialogue.character&&delete e.dialogue.character.characterName)},lt=(e,t)=>{if(t.character){if(!e.character){e.character=JSON.parse(JSON.stringify(t.character));return}Object.assign(e.character,t.character),e.character.items||(e.character.items=[]);for(let r=0;r<e.character.items.length;r++){let n=e.character.items[r],s=t.character.items.find(o=>o.id===n.id);s?(Object.assign(n,s),s.inAnimation||delete n.inAnimation,s.outAnimation||delete n.outAnimation):delete n.inAnimation}t.character.items.forEach(r=>{e.character.items.some(n=>n.id===r.id)||e.character.items.push(r)})}},ut=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},ft=(e,t)=>{t.layout?e.layout=t.layout:e.layout&&delete e.layout},pt=(e,t)=>{t.choice?e.choice=t.choice:e.choice&&delete e.choice},dt=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(r=>{delete e[r]})},pr=()=>({}),Ae=[dt,st,it,ot,ct,at,lt,ut,ft,pt];var be={};V(be,{clearCurrentMode:()=>Or,clearPendingEffects:()=>Ar,createInitialState:()=>dr,goToSectionScene:()=>wr,lineCompleted:()=>vr,loadVnData:()=>$r,nextLine:()=>Er,prevLine:()=>br,saveVnData:()=>Pr,selectAutoMode:()=>q,selectAutoNext:()=>yt,selectCurrentPointer:()=>Ee,selectCurrentPreset:()=>yr,selectCurrentPresetId:()=>ht,selectDialogueUIHidden:()=>Ir,selectHistory:()=>mt,selectPendingEffects:()=>hr,selectPointerMode:()=>Z,selectPointers:()=>mr,selectRuntimeState:()=>gr,selectSaveData:()=>It,selectSkipMode:()=>Q,selectSpecificPointer:()=>gt,selectVariables:()=>_r,setPreset:()=>Sr,startAutoMode:()=>_t,startSkipMode:()=>vt,stopAutoMode:()=>At,stopSkipMode:()=>Et,toggleAutoMode:()=>Lr,toggleDialogueUIHidden:()=>Nr,toggleSkipMode:()=>kr,updateVariable:()=>xr});var dr=({sectionId:e,lineId:t,presetId:r,autoNext:n,saveData:s,variables:o})=>{let i={pendingEffects:[],variables:o,saveData:s,story:{lastLineAction:void 0,dialogueUIHidden:!1,currentPointer:"read",autoNext:n,autoMode:!1,skipMode:!1,pointers:{read:{presetId:r,sectionId:e,lineId:t},menu:{presetId:"3ijasdk3",sectionId:void 0,lineId:void 0},history:{presetId:r,sectionId:void 0,lineId:void 0,historyEntryIndex:void 0}},history:{entries:[]}}};return i.story.history.entries.push({sectionId:e}),i},hr=({state:e})=>e.pendingEffects,Ee=({state:e})=>e.story.pointers[e.story.currentPointer],ht=({state:e})=>e.story.pointers[e.story.currentPointer].presetId,yr=({state:e,projectDataStore:t})=>{let r=ht({state:e});return t.selectPreset(r)},Q=({state:e})=>e.story.skipMode,q=({state:e})=>e.story.autoMode,mr=({state:e})=>e.story.pointers,yt=({state:e})=>e.story.autoNext,gr=({state:e})=>e.runtimeState,Z=({state:e})=>e.story.currentPointer,Ir=({state:e})=>e.story.dialogueUIHidden,mt=({state:e})=>e.story.history,gt=({state:e,mode:t})=>e.story.pointers[t],It=({state:e})=>e.saveData,_r=({state:e})=>e.variables,Ar=({state:e})=>{e.pendingEffects=[]},vr=({state:e,projectDataStore:t})=>{let r=q(e),{pendingEffects:n}=e;if(r){n.push({name:"systemInstructions",options:{delay:1e3,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}if(Q(e)){n.push({name:"systemInstructions",options:{delay:300,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}let o=yt(e);if(!o)return;let{nextTrigger:i,delay:c}=o;switch(i){case"onComplete":delete e.story.autoNext;break;case"fromComplete":n.push({name:"systemInstructions",options:{delay:c,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});break;case"manual":delete e.story.autoNext;break;default:delete e.story.autoNext;break}},Er=({state:e,projectDataStore:t})=>{let{pendingEffects:r}=e,n=Ee({state:e}),s=Z({state:e}),o=t.selectSectionLines(n.sectionId),i=o.findIndex(a=>a.id===n.lineId),c=o[i+1];c&&(e.story.pointers[e.story.currentPointer].lineId=c.id,r.push({name:"render"}))},br=({state:e,projectDataStore:t})=>{let r=Z({state:e}),n=Ee({state:e}),s=t.selectSectionLines(n.sectionId),o=s.findIndex(c=>c.id===n.lineId),i=s[o-1];if(!i){if(r==="history"){if(e.story.historyEntryIndex>0)e.story.historyEntryIndex--;else return;e.story.pointers.history.sectionId=e.story.history.entries[e.story.historyEntryIndex].sectionId;let c=t.selectSectionLines(e.story.pointers.history.sectionId);e.story.pointers.history.lineId=c[c.length-1].id,e.story.lastLineAction="prevLine",e.pendingEffects.push({name:"render"})}return}r==="read"&&(e.story.currentPointer="history",e.story.historyEntryIndex=e.story.history.entries.length-1),e.story.pointers.history.lineId=i.id,e.story.pointers.history.sectionId=n.sectionId,e.story.lastLineAction="prevLine",e.pendingEffects.push({name:"render"})},wr=({state:e,projectDataStore:t},r)=>{let{sectionId:n,sceneId:s,mode:o,presetId:i}=r,c=t.selectSectionLines(n);o&&(e.story.currentPointer=o);let a=Z({state:e});a==="read"?e.story.history.entries.push({sectionId:n}):a==="history"&&n===e.story.history.entries[e.story.historyEntryIndex+1].sectionId&&e.story.historyEntryIndex++,e.story.pointers[a].sectionId=n,e.story.pointers[a].sceneId=s,e.story.pointers[a].lineId=c[0].id,e.story.autoNext=c[0].autoNext,i&&(e.story.pointers[a].presetId=i),e.pendingEffects.push({name:"render"})},xr=({state:e,projectDataStore:t},r)=>{let{operations:n}=r;for(let s of n){let{variableId:o,op:i,value:c}=s;i==="set"?e.variables[o]=c:i==="add"?e.variables[o]=(e.variables[o]||0)+c:i==="subtract"?e.variables[o]=(e.variables[o]||0)-c:i==="multiply"?e.variables[o]=(e.variables[o]||0)*c:i==="divide"?e.variables[o]=(e.variables[o]||0)/c:i==="increment"?e.variables[o]=(e.variables[o]||0)+1:i==="decrement"&&(e.variables[o]=(e.variables[o]||0)-1)}e.pendingEffects.push({name:"render"})},Sr=({state:e},t)=>{e.story.pointers[e.story.currentPointer].presetId=t.presetId},Or=({state:e},t)=>{e.story.currentPointer=t.mode,e.pendingEffects.push({name:"render"})},_t=({state:e})=>{Q({state:e})&&(e.story.skipMode=!1),e.story.autoMode=!0,e.pendingEffects.push({name:"cancelTimerEffect"}),e.pendingEffects.push({name:"systemInstructions",options:{delay:1e3,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}})},At=({state:e})=>{e.story.autoMode=!1,e.pendingEffects.push({name:"cancelTimerEffect"})},Lr=({state:e})=>{q({state:e})?At({state:e}):_t({state:e})},vt=({state:e})=>{q({state:e})&&(e.story.autoMode=!1),e.story.skipMode=!0,e.pendingEffects.push({name:"cancelTimerEffect"}),e.pendingEffects.push({name:"systemInstructions",options:{delay:300,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}})},Et=({state:e})=>{e.story.skipMode=!1,e.pendingEffects.push({name:"cancelTimerEffect"})},kr=({state:e})=>{Q({state:e})?Et({state:e}):vt({state:e})},Nr=({state:e})=>{e.story.dialogueUIHidden=!e.story.dialogueUIHidden,e.pendingEffects.push({name:"render"})},Pr=({state:e},t)=>{e.saveData.push({id:Date.now().toString().slice(4,10),slotIndex:t.slotIndex,pointer:gt({state:e,mode:"read"}),history:mt({state:e})}),e.pendingEffects.push({name:"saveVnData",options:{saveData:[...e.saveData]}})},$r=({state:e},t)=>{let{slotIndex:r}=t,s=It({state:e}).filter(c=>c.slotIndex===r);if(s.length===0){console.warn(`No save data found for slot index ${r}`);return}let{pointer:o,history:i}=s[s.length-1];e.story.currentPointer="read",e.story.pointers.read=o,e.story.history=i,e.pendingEffects.push({name:"render"})};var we={};V(we,{createInitialState:()=>jr,selectInitialIds:()=>bt,selectInitialPreset:()=>Tr,selectLayout:()=>Br,selectPreset:()=>Cr,selectPresets:()=>Rr,selectResources:()=>Vr,selectScreen:()=>Dr,selectSectionLines:()=>Wr,selectUi:()=>Mr,selectVariables:()=>Fr});var Rr=e=>e.presets,Tr=e=>e.presets[e.story.initialPresetId],Cr=(e,t)=>e.presets[t],Dr=e=>e.screen,Vr=e=>e.resources,Mr=e=>e.ui,Br=e=>e.layout,bt=e=>{let t=e.story.scenes[e.story.initialSceneId],r=t.sections[t.initialSectionId];return{sceneId:e.story.initialSceneId,sectionId:t.initialSectionId,presetId:e.story.initialPresetId,lineId:r.lines[0].id,autoNext:r.lines[0].autoNext}},Fr=e=>e.variables||{},Wr=(e,t,r)=>{let s=Object.values(e.story.scenes).flatMap(o=>Object.entries(o.sections).map(([i,c])=>({...c,id:i}))).find(o=>o.id===t);if(r){let o=s.lines.findIndex(i=>i.id===r);return s.lines.slice(0,o+1)}return s.lines},jr=e=>{let t=bt(e),{sectionId:r,lineId:n}=t;if(!r||!n)throw new Error("No initial sectionId found");return e};var{createInitialState:Ur}=ve,{createInitialState:zr}=_e,{createInitialState:Kr,...Jr}=be,{createInitialState:Nn,...Yr}=we,wt=e=>pe(e,Yr),xt=(e,t)=>pe(Kr({sectionId:e.sectionId,lineId:e.lineId,presetId:e.presetId,autoNext:e.autoNext,saveData:{},variables:{}}),Jr,{transformActionFirstArgument:r=>({state:r,projectDataStore:t}),transformSelectorFirstArgument:r=>({state:r,projectDataStore:t})}),xe=de(Ur,Ae),Se=de(zr,Ie);var Oe=class{_projectDataStore;_systemStore;_constructRenderState;_constructPresentationState;_applySystemInstruction;_eventCallback=()=>{};constructor(){}init=({projectData:t})=>{this._projectDataStore=wt(t);let r=this._projectDataStore.selectInitialIds();this._systemStore=xt(r,this._projectDataStore),this._constructPresentationState=xe,this._constructRenderState=Se,this._render()};onEvent=t=>(this._eventCallback=t,this);offEvent=()=>(this._eventCallback=()=>{},this);handleEvent=t=>{let{eventType:r,payload:n}=t,i=(this._systemStore.selectCurrentPreset()?.eventsMap||{})[r]?.systemActions,c=i?Object.keys(i)[0]:null;c&&typeof this._systemStore[c]=="function"?this._systemStore[c](n):c&&console.error(`Method ${c} not found on system store`),this._systemStore.selectPendingEffects().forEach(l=>{l.name==="render"&&(this._processSystemActions(),this._render())}),this._systemStore.clearPendingEffects()};_processSystemActions=()=>{let t=this._systemStore.selectCurrentPointer(),r=this._projectDataStore.selectSectionLines(t.sectionId,t.lineId);r.length&&r.forEach(n=>{n.system&&Object.keys(n.system).forEach(s=>{typeof this._systemStore[s]=="function"?this._systemStore[s](n.system[s]):console.error(`System action ${s} not found on system store`)})})};_render=()=>{let t=this._systemStore.selectCurrentPointer(),r=this._projectDataStore.selectSectionLines(t.sectionId,t.lineId);if(!r.length){console.warn(`No lines found for section: ${t.sectionId}, line: ${t.lineId}`);return}let n=r.map(i=>i.presentation||{}),s=this._constructPresentationState(n),o=this._constructRenderState({presentationState:s,screen:this._projectDataStore.selectScreen(),resolveFile:i=>`file:${i}`,resources:this._projectDataStore.selectResources(),ui:this._projectDataStore.selectUi()});this._eventCallback({eventType:"render",payload:o})}},Xr=Oe;export{Xr as RouteEngine,xe as constructPresentationState,Se as constructRenderState};
|