route-engine-js 0.0.2-rc1 → 0.0.2-rc10

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Route Engine
2
2
 
3
- A Visual Novels built in JavaScript
3
+ A Visual Novel engine built in JavaScript
4
4
 
5
5
  ## Overview
6
6
 
@@ -26,4 +26,3 @@ spec/ # Test specifications
26
26
  vt/ # Visual testing files
27
27
  docs/ # Documentation
28
28
  ```
29
-
@@ -1 +1 @@
1
- var gt=Object.defineProperty;var N=(e,t)=>{for(var r in t)gt(e,r,{get:t[r],enumerable:!0})};var we=Symbol.for("immer-nothing"),Se=Symbol.for("immer-draftable"),I=Symbol.for("immer-state");function S(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var P=Object.getPrototypeOf;function O(e){return!!e&&!!e[I]}function b(e){return e?Pe(e)||Array.isArray(e)||!!e[Se]||!!e.constructor?.[Se]||V(e)||F(e):!1}var _t=Object.prototype.constructor.toString();function Pe(e){if(!e||typeof e!="object")return!1;let t=P(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)===_t}function C(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:V(e)?2:F(e)?3:0}function G(e,t){return M(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Oe(e,t,r){let n=M(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function It(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function V(e){return e instanceof Map}function F(e){return e instanceof Set}function A(e){return e.copy_||e.base_}function J(e,t){if(V(e))return new Map(e);if(F(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let r=Pe(e);if(t===!0||t==="class_only"&&!r){let n=Object.getOwnPropertyDescriptors(e);delete n[I];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(P(e),n)}else{let n=P(e);if(n!==null&&r)return{...e};let s=Object.create(n);return Object.assign(s,e)}}function Z(e,t=!1){return z(e)||O(e)||!b(e)||(M(e)>1&&(e.set=e.add=e.clear=e.delete=xt),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>Z(n,!0))),e}function xt(){S(2)}function z(e){return Object.isFrozen(e)}var St={};function v(e){let t=St[e];return t||S(0,e),t}var k;function $e(){return k}function Et(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ee(e,t){t&&(v("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function H(e){Q(e),e.drafts_.forEach(At),e.drafts_=null}function Q(e){e===k&&(k=e.parent_)}function Ae(e){return k=Et(k,e)}function At(e){let t=e[I];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function be(e,t){t.unfinalizedDrafts_=t.drafts_.length;let r=t.drafts_[0];return e!==void 0&&e!==r?(r[I].modified_&&(H(t),S(4)),b(e)&&(e=R(t,e),t.parent_||T(t,e)),t.patches_&&v("Patches").generateReplacementPatches_(r[I].base_,e,t.patches_,t.inversePatches_)):e=R(t,r,[]),H(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==we?e:void 0}function R(e,t,r){if(z(t))return t;let n=t[I];if(!n)return C(t,(s,o)=>ve(e,n,t,s,o,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 s=n.copy_,o=s,i=!1;n.type_===3&&(o=new Set(s),s.clear(),i=!0),C(o,(c,a)=>ve(e,n,s,c,a,r,i)),T(e,s,!1),r&&e.patches_&&v("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function ve(e,t,r,n,s,o,i){if(O(s)){let c=o&&t&&t.type_!==3&&!G(t.assigned_,n)?o.concat(n):void 0,a=R(e,s,c);if(Oe(r,n,a),O(a))e.canAutoFreeze_=!1;else return}else i&&r.add(s);if(b(s)&&!z(s)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;R(e,s),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&T(e,s)}}function T(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Z(t,r)}function bt(e,t){let r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:$e(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},s=n,o=ee;r&&(s=[n],o=L);let{revoke:i,proxy:c}=Proxy.revocable(s,o);return n.draft_=c,n.revoke_=i,c}var ee={get(e,t){if(t===I)return e;let r=A(e);if(!G(r,t))return vt(e,r,t);let n=r[t];return e.finalized_||!b(n)?n:n===Y(e.base_,t)?(K(e),e.copy_[t]=X(n,e)):n},has(e,t){return t in A(e)},ownKeys(e){return Reflect.ownKeys(A(e))},set(e,t,r){let n=Ne(A(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){let s=Y(A(e),t),o=s?.[I];if(o&&o.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(It(r,s)&&(r!==void 0||G(e.base_,t)))return!0;K(e),q(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 Y(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,K(e),q(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(){S(11)},getPrototypeOf(e){return P(e.base_)},setPrototypeOf(){S(12)}},L={};C(ee,(e,t)=>{L[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});L.deleteProperty=function(e,t){return L.set.call(this,e,t,void 0)};L.set=function(e,t,r){return ee.set.call(this,e[0],t,r,e[0])};function Y(e,t){let r=e[I];return(r?A(r):e)[t]}function vt(e,t,r){let n=Ne(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}function Ne(e,t){if(!(t in e))return;let r=P(e);for(;r;){let n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=P(r)}}function q(e){e.modified_||(e.modified_=!0,e.parent_&&q(e.parent_))}function K(e){e.copy_||(e.copy_=J(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var wt=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,...u){return i.produce(a,f=>r.call(this,f,...u))}}typeof r!="function"&&S(6),n!==void 0&&typeof n!="function"&&S(7);let s;if(b(t)){let o=Ae(this),i=X(t,void 0),c=!0;try{s=r(i),c=!1}finally{c?H(o):Q(o)}return Ee(o,n),be(s,o)}else if(!t||typeof t!="object"){if(s=r(t),s===void 0&&(s=t),s===we&&(s=void 0),this.autoFreeze_&&Z(s,!0),n){let o=[],i=[];v("Patches").generateReplacementPatches_(t,s,o,i),n(o,i)}return s}else S(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){b(e)||S(8),O(e)&&(e=Pt(e));let t=Ae(this),r=X(e,void 0);return r[I].isManual_=!0,Q(t),r}finishDraft(e,t){let r=e&&e[I];(!r||!r.isManual_)&&S(9);let{scope_:n}=r;return Ee(n,t),be(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=v("Patches").applyPatches_;return O(e)?n(e,t):this.produce(e,s=>n(s,t))}};function X(e,t){let r=V(e)?v("MapSet").proxyMap_(e,t):F(e)?v("MapSet").proxySet_(e,t):bt(e,t);return(t?t.scope_:$e()).drafts_.push(r),r}function Pt(e){return O(e)||S(10,e),ke(e)}function ke(e){if(!b(e)||z(e))return e;let t=e[I],r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=J(e,t.scope_.immer_.useStrictShallowCopy_)}else r=J(e,!0);return C(r,(n,s)=>{Oe(r,n,ke(s))}),t&&(t.finalized_=!1),r}var x=new wt,te=x.produce,kr=x.produceWithPatches.bind(x),Lr=x.setAutoFreeze.bind(x),Dr=x.setUseStrictShallowCopy.bind(x),Cr=x.applyPatches.bind(x),Rr=x.createDraft.bind(x),Tr=x.finishDraft.bind(x);var re=(e,t,r={})=>{let n=structuredClone(e),s={},o={},{transformSelectorFirstArgument:i=a=>a,transformActionFirstArgument:c=a=>a}=r;for(let[a,u]of Object.entries(t))a!=="createInitialState"&&(a.startsWith("select")?s[a]=(...f)=>u(i(n),...f):o[a]=(...f)=>{n=te(n,_=>u(c(_),...f))});return{...s,...o}},ne=(e,t)=>r=>{let n=e(),s=Array.isArray(r)?r:[r];return te(n,o=>{s.forEach(i=>{t.forEach(c=>{c(o,i)})})})};var fe={};N(fe,{addBackgrundOrCg:()=>We,addCharacters:()=>Be,addChoices:()=>Je,addDialogue:()=>Ke,addScreens:()=>Ge,addVisuals:()=>Ye,createInitialState:()=>Yt,default:()=>ue,generateScreenBackgroundElement:()=>Ue});var l={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},D={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 se=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}')`)},Le=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(s=>s.trim());for(let s of n)if(!s)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}'`)},Ce=(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 Ot=(e,t,r={})=>h(e,r,t,{}),h=(e,t,r,n)=>{switch(e.type){case l.LITERAL:return e.value;case l.VARIABLE:return Re(e.path,r,n);case l.INTERPOLATION:return $t(e.parts,t,r,n);case l.FUNCTION:return Te(e,t,r,n);case l.BINARY:return Me(e,t,r,n);case l.UNARY:return Ve(e,t,r,n);case l.CONDITIONAL:return Nt(e,t,r,n);case l.LOOP:return kt(e,t,r,n);case l.OBJECT:return Lt(e,t,r,n);case l.ARRAY:return Dt(e,t,r,n);default:throw new Error(`Unknown node type: ${e.type}`)}},Re=(e,t,r)=>{if(!e)return;if(r.hasOwnProperty(e))return r[e];let n=e.split("."),s=t;for(let o=0;o<n.length;o++){let i=n[o];if(r.hasOwnProperty(i)){s=r[i];continue}if(s==null)return;s=s[i]}return s},$t=(e,t,r,n)=>{let s="";for(let o of e)if(typeof o=="string")s+=o;else{let i=h(o,t,r,n);s+=i!=null?String(i):""}return s},Te=(e,t,r,n)=>{let s=t[e.name];if(!s)throw Ce(e.name,t);let o=e.args.map(i=>h(i,t,r,n));return s(...o)},j=(e,t,r,n)=>{switch(e.type){case l.VARIABLE:return Re(e.path,r,n);case l.LITERAL:return e.value;case l.BINARY:return Me(e,t,r,n);case l.UNARY:return Ve(e,t,r,n);case l.FUNCTION:return Te(e,t,r,n);default:return h(e,t,r,n)}},Me=(e,t,r,n)=>{if(e.op===d.AND||e.op===d.OR){let i=j(e.left,t,r,n),c=j(e.right,t,r,n);switch(e.op){case d.AND:return i&&c;case d.OR:return i||c}}let s=h(e.left,t,r,n),o=h(e.right,t,r,n);switch(e.op){case d.EQ:return s==o;case d.NEQ:return s!=o;case d.GT:return s>o;case d.LT:return s<o;case d.GTE:return s>=o;case d.LTE:return s<=o;case d.IN:return Array.isArray(o)?o.includes(s):!1;default:throw new Error(`Unknown binary operator: ${e.op}`)}},Ve=(e,t,r,n)=>{let s=e.op===D.NOT?j(e.operand,t,r,n):h(e.operand,t,r,n);switch(e.op){case D.NOT:return!s;default:throw new Error(`Unknown unary operator: ${e.op}`)}},Nt=(e,t,r,n)=>{for(let s=0;s<e.conditions.length;s++){let o=e.conditions[s];if(o===null||j(o,t,r,n))return h(e.bodies[s],t,r,n)}return{}},kt=(e,t,r,n)=>{let s=h(e.iterable,t,r,n);if(!Array.isArray(s)){let i=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${e.iterable.path}`;throw De(i,s)}let o=[];for(let i=0;i<s.length;i++){let c=Object.create(n);c[e.itemVar]=s[i],e.indexVar&&(c[e.indexVar]=i);let a=h(e.body,t,r,c);Array.isArray(a)&&a.length===1?o.push(a[0]):o.push(a)}return o},Lt=(e,t,r,n)=>{let s={},o=null,i=!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 ")){i=!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(!i&&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(s,a)}else if(!c.key.startsWith("$for ")){let a=c.value;if(a&&a.type===l.OBJECT&&a.properties){let u=a.properties.find(f=>f.key.startsWith("$for "));if(u){let f=h(u.value,t,r,n);f!==void 0&&(s[c.key]=f)}else{let f=h(c.value,t,r,n);f!==void 0&&(s[c.key]=f)}}else{let u=c.parsedKey?h(c.parsedKey,t,r,n):c.key,f=h(c.value,t,r,n);f!==void 0&&(s[u]=f)}}return s},Dt=(e,t,r,n)=>{let s=[];for(let o of e.items)if(o.type===l.LOOP){let i=h(o,t,r,n);s.push(i)}else s.push(h(o,t,r,n));return s},oe=Ot;var Ct=/\$\{([^}]*)\}/g,ze=e=>{let t=e.match(/^(\w+)\((.*)\)$/);if(!t)return{isFunction:!1};let[,r,n]=t,s=Rt(n);return{isFunction:!0,type:l.FUNCTION,name:r,args:s}},Rt=e=>e.trim()?Tt(e).map(r=>Mt(r.trim())):[],Tt=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},Mt=e=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:l.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:l.LITERAL,value:parseFloat(e)};if(e==="true")return{type:l.LITERAL,value:!0};if(e==="false")return{type:l.LITERAL,value:!1};if(e==="null")return{type:l.LITERAL,value:null};let t=ze(e);return t.isFunction?{type:t.type,name:t.name,args:t.args}:{type:l.VARIABLE,path:e}},Fe=(e,t={})=>{let r=e.trim(),n=ze(r);return n.isFunction?{type:n.type,name:n.name,args:n.args}:{type:l.VARIABLE,path:r}},ie=(e,t={})=>{let r=e,n=[];e.includes("\\${")&&(r=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC$1"),r=r.replace(/\\(\$\{[^}]*\})/g,(c,a)=>{let u=`__ESCAPED_${n.length}__`;return n.push(a),u}),r=r.replace(/\\DOUBLE_ESC/g,"\\"));let s=[...r.matchAll(Ct)];if(s.length===0){let c=r;for(let a=0;a<n.length;a++)c=c.replace(`__ESCAPED_${a}__`,n[a]);return{type:l.LITERAL,value:c}}if(s.length===1&&s[0][0]===r&&n.length===0)return Fe(s[0][1],t);let o=[],i=0;for(let c of s){let[a,u]=c,f=c.index;if(f>i){let _=r.substring(i,f);for(let y=0;y<n.length;y++)_=_.replace(`__ESCAPED_${y}__`,n[y]);_&&o.push(_)}let p=Fe(u.trim(),t);o.push(p),i=f+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:l.INTERPOLATION,parts:o}};var w=(e,t)=>typeof e=="string"?ie(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?Vt(e,t):Ft(e,t):{type:l.LITERAL,value:e},Vt=(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=je(c[0],o[c[0]],t);r.push(a),n=!0;continue}}let i=w(o,t);r.push(i),(i.type===l.FUNCTION||i.type===l.CONDITIONAL||i.type===l.LOOP||i.type===l.OBJECT&&!i.fast||i.type===l.ARRAY&&!i.fast)&&(n=!0)}return{type:l.ARRAY,items:r,fast:!n}},Ft=(e,t)=>{let r=[],n=!1,s=Object.entries(e),o=0;for(;o<s.length;){let[i,c]=s[o];if(i.startsWith("$if ")||i.match(/^\$if#\w+\s/)||i.match(/^\$if\s+\w+.*:$/)){let a=zt(s,o,t);r.push({key:i,value:a.node}),n=!0,o=a.nextIndex}else if(i.startsWith("$for ")){let a=je(i,c,t);r.push({key:i,value:a}),n=!0,o++}else{if(i.startsWith("$elif ")||i.startsWith("$else"))throw new g(`'${i.split(" ")[0]}' without matching '$if'`);if(i==="$if"||i==="$if:")throw new g("Missing condition expression after '$if'");{let a=w(c,t);(a.type===l.FUNCTION||a.type===l.CONDITIONAL||a.type===l.LOOP||a.type===l.OBJECT&&!a.fast||a.type===l.ARRAY&&!a.fast)&&(n=!0);let u=ie(i,t),f={key:i,value:a};(u.type!==l.LITERAL||u.value!==i)&&(f.parsedKey=u),r.push(f),o++}}}return{type:l.OBJECT,properties:r,fast:!n}},zt=(e,t,r={})=>{let n=[],s=[],o=t,[i,c]=e[o],a=null,u;if(i.startsWith("$if#")){let p=i.match(/^\$if#(\w+)\s+(.+)$/);if(p)a=p[1],u=p[2];else throw new g(`Invalid conditional syntax: ${i}`)}else u=i.substring(4),u.endsWith(":")&&(u=u.slice(0,-1).trim());se(u);let f=E(u);for(n.push(f),s.push(w(c,r)),o++;o<e.length;){let[p,_]=e[o],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{se(m);let B=E(m);n.push(B)}if(s.push(w(_,r)),o++,m===null)break}else break}return{node:{type:l.CONDITIONAL,conditions:n,bodies:s,id:a},nextIndex:o}},E=e=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")"))return E(e.slice(1,-1));let t=ce(e,"||");if(t!==-1)return{type:l.BINARY,op:d.OR,left:E(e.substring(0,t).trim()),right:E(e.substring(t+2).trim())};let r=ce(e,"&&");if(r!==-1)return{type:l.BINARY,op:d.AND,left:E(e.substring(0,r).trim()),right:E(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:s,type:o}of n){let i=ce(e,s);if(i!==-1)return{type:l.BINARY,op:o,left:E(e.substring(0,i).trim()),right:E(e.substring(i+s.length).trim())}}return e.startsWith("!")?{type:l.UNARY,op:D.NOT,operand:E(e.substring(1).trim())}:jt(e)},ce=(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},jt=e=>{if(e=e.trim(),e==="true")return{type:l.LITERAL,value:!0};if(e==="false")return{type:l.LITERAL,value:!1};if(e==="null")return{type:l.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:l.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:l.LITERAL,value:""};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:l.LITERAL,value:t}:{type:l.VARIABLE,path:e}},je=(e,t,r)=>{let n=e.substring(5).trim();Le(n);let s=n.match(/^(.+?)\s+in\s+(.+)$/);if(!s)throw new g(`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(_=>_.trim());if(p.length!==2)throw new g(`Invalid loop variables: ${o}. Expected format: "item" or "item, index"`);c=p[0],a=p[1]}else c=o;let u={type:l.VARIABLE,path:i},f=w(t,r);return{type:l.LOOP,itemVar:c,indexVar:a,iterable:u,body:f}};var Ut=(e,t={})=>{let{functions:r={}}=t;return w(e,r)},ae=Ut;var le={};N(le,{now:()=>Wt});var Wt=()=>Date.now();var Bt=(e,t,r={})=>{let{functions:n={}}=r,s={...le,...n},o=ae(e,{functions:s});return oe(o,t,s)},U=Bt;var Yt=()=>({elements:[],transitions:[]}),Ue=({elements:e,transitions:t},{screen:r})=>{e.push({id:"bg-screen",type:"graphics",x1:0,x2:r.width,y1:0,y2:r.height,fill:r.backgroundColor,clickEventName:"LeftClick",rightClickEventName:"RightClick",wheelEventName:"ScrollUp"})},We=({elements:e,transitions:t},{presentationState:r,assets:n,resolveFile:s})=>{if(r.background){if(r.background.imageId){let o=n.images[r.background.imageId];e.push({id:"bg-cg",type:"sprite",x:0,y:0,url:s(o.fileId)})}if(r.background.animations){if(r.background.animations.in){let o=n.animations[r.background.animations.in];t.push({id:"bg-cg-animation",type:"keyframes",event:"add",elementId:"bg-cg",animationProperties:o.properties})}if(r.background.animations.out){let o=n.animations[r.background.animations.out];o&&t.push({id:"bg-cg-animation-2",type:"keyframes",event:"remove",elementId:"bg-cg",animationProperties:o.properties})}}}},Be=({elements:e,transitions:t},{presentationState:r,assets:n,resolveFile:s})=>{if(r.character){let o=r.character.items;for(let i of o){let{placementId:c,spriteParts:a}=i,u=a.map(({spritePartId:y})=>y),f=n.placements[c],p={type:"container",id:`character-container-${i.id}`,x:f.x,y:f.y,xa:f.xa,ya:f.ya,anchor:f.anchor,children:[]},_=[];Object.entries(n.characters).flatMap(([y,m])=>{let{spriteParts:B}=m;Object.entries(B).map(([xe,mt])=>{u.includes(xe)&&_.push({partId:xe,fileId:mt.fileId})})});for(let y of _)p.children.push({type:"sprite",id:`${i.id}-${y.partId}`,url:s(y.fileId),x:0,y:0});e.push(p)}}},Ye=({elements:e,transitions:t},{presentationState:r,assets:n,resolveFile:s})=>{if(r.visual){let o=r.visual.items;for(let i of o){if(i.visualId){let c=n.visuals[i.visualId],a=n.placements[i.placementId];e.push({id:`visual-${i.visualId}`,type:"sprite",url:s(c.fileId),x:a.x,y:a.y,xa:a.xa,ya:a.ya})}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}`,animationProperties: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}`,animationProperties:c.properties})}}}}},Ke=({elements:e,transitions:t},{presentationState:r,ui:n,assets:s,dialogueUIHidden:o})=>{if(!o&&r.dialogue){let i=n.screens[r.dialogue.dialogueBoxId],c;r.dialogue.characterId&&(c=s.characters[r.dialogue.characterId]);let a=[{id:"dialogue-container",type:"container",x:100,y:100,children:[{id:"dialogue-character-name",type:"text",text:c?.name||"Unknown",style:{fontSize:24,fill:"white"}},{id:"dialogue-text",type:"text",y:100,text:r.dialogue.text,style:{fontSize:24,fill:"white"}}]}];for(let u of a)e.push(u)}},Ge=({elements:e,transitions:t},{presentationState:r,ui:n,variables:s})=>{if(r.screen){let i={elements:n.screens[r.screen.screenId].elements},a=U(i,{variables:s})?.elements;if(Array.isArray(a))for(let u of a)e.push(u);else a&&e.push(a)}},Je=({elements:e,transitions:t},{presentationState:r,assets:n,ui:s})=>{if(r.choices){let i={elements:s.screens[r.choices.choiceScreenId].elements},a=U(i,{choices:{items:r.choices.items}})?.elements;if(Array.isArray(a))for(let u of a)e.push(u);else a&&e.push(a)}},ue=[Ue,We,Be,Ye,Ke,Ge,Je];var de={};N(de,{applyAnimation:()=>tt,applyBackground:()=>He,applyBgm:()=>qe,applyCharacter:()=>et,applyChoices:()=>nt,applyCleanAll:()=>st,applyDialogue:()=>Ze,applyScreen:()=>rt,applySfx:()=>Qe,applyVisual:()=>Xe,createInitialState:()=>Kt,default:()=>pe});var He=(e,t)=>{t.background&&(e.background={...t.background})},Qe=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},qe=(e,t)=>{t.bgm&&(e.bgm={...t.bgm,loop:t.bgm.loop||t.bgm.loop===void 0})},Xe=(e,t)=>{t.visual&&(e.visual=t.visual)},Ze=(e,t)=>{t.dialogue&&(e.dialogue||(e.dialogue={}),Object.assign(e.dialogue,t.dialogue),t.dialogue.text&&delete e.dialogue.segments,t.dialogue.character&&!t.dialogue.character.characterName&&e.dialogue.character&&delete e.dialogue.character.characterName)},et=(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)})}},tt=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},rt=(e,t)=>{t.screen?e.screen=t.screen:e.screen&&delete e.screen},nt=(e,t)=>{t.choices?e.choices=t.choices:e.choices&&delete e.choices},st=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(r=>{delete e[r]})},Kt=()=>({}),pe=[He,Qe,qe,Xe,Ze,et,tt,rt,nt,st];var ye={};N(ye,{clearCurrentMode:()=>ur,clearPendingEffects:()=>nr,createInitialState:()=>Gt,goToSectionScene:()=>cr,lineCompleted:()=>sr,loadVnData:()=>hr,nextLine:()=>or,prevLine:()=>ir,saveVnData:()=>dr,selectAutoMode:()=>ct,selectAutoNext:()=>at,selectCurrentPointer:()=>he,selectCurrentPreset:()=>Ht,selectCurrentPresetId:()=>ot,selectDialogueUIHidden:()=>Xt,selectHistory:()=>Zt,selectPendingEffects:()=>Jt,selectPointerMode:()=>W,selectPointers:()=>Qt,selectRuntimeState:()=>qt,selectSaveData:()=>tr,selectSkipMode:()=>it,selectSpecificPointer:()=>er,selectVariables:()=>rr,setPreset:()=>lr,startAutoMode:()=>lt,startSkipMode:()=>ft,stopAutoMode:()=>ut,stopSkipMode:()=>pt,toggleAutoMode:()=>fr,toggleSkipMode:()=>pr,updateVariable:()=>ar});var Gt=({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},Jt=({state:e})=>e.pendingEffects,he=({state:e})=>e.story.pointers[e.story.currentPointer],ot=({state:e})=>e.story.pointers[e.story.currentPointer].presetId,Ht=({state:e,projectDataStore:t})=>{let r=ot({state:e});return t.selectPreset(r)},it=({state:e})=>e.story.skipMode,ct=({state:e})=>e.story.autoMode,Qt=({state:e})=>e.story.pointers,at=({state:e})=>e.story.autoNext,qt=({state:e})=>e.runtimeState,W=({state:e})=>e.story.currentPointer,Xt=({state:e})=>e.story.dialogueUIHidden,Zt=({state:e})=>e.story.history,er=({state:e,mode:t})=>e.story.pointers[t],tr=({state:e})=>e.saveData,rr=({state:e})=>e.variables,nr=({state:e})=>{e.pendingEffects=[]},sr=({state:e,projectDataStore:t})=>{let r=ct(e),{pendingEffects:n}=e;if(r){n.push({name:"systemInstructions",options:{delay:1e3,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}if(it(e)){n.push({name:"systemInstructions",options:{delay:300,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}let o=at(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}},or=({state:e,projectDataStore:t})=>{let{pendingEffects:r}=e,n=he({state:e}),s=W({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"}))},ir=({state:e,projectDataStore:t})=>{let r=W(e),n=he(e),s=t.selectSectionLines(n.sectionId),o=s.findIndex(c=>c.id===n.lineId),i=s[o-1];if(!i){if(console.log({pointerMode:r,"state.story.historyEntryIndex":e.story.historyEntryIndex}),r==="history"){if(e.story.historyEntryIndex>0)e.story.historyEntryIndex--;else return;console.log("state.story.historyEntryIndex",e.story.historyEntryIndex),e.story.pointers.history.sectionId=e.story.history.entries[e.story.historyEntryIndex].sectionId;let c=vnDataSelectors.selectSectionLines(vnData,systemState.story.pointers.history.sectionId);console.log("prevSectionLines",c),systemState.story.pointers.history.lineId=c[c.length-1].id,console.log({lineId:systemState.story.pointers.history.lineId,sectionId:systemState.story.pointers.history.sectionId}),systemState.story.lastLineAction="prevLine",effects.push({name:"render"})}return}r==="read"&&(systemState.story.currentPointer="history",systemState.story.historyEntryIndex=systemState.story.history.entries.length-1),systemState.story.pointers.history.lineId=i.id,systemState.story.pointers.history.sectionId=n.sectionId,systemState.story.lastLineAction="prevLine",effects.push({name:"render"})},cr=({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=W({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"})},ar=({payload:e,systemState:t,effects:r,vnData:n})=>{let{operations:s}=e;for(let a of s){let{variableId:u,op:f,value:p}=a;f==="set"?t.variables[u]=p:f==="increment"?t.variables[u]+=p:f==="decrement"&&(t.variables[u]-=p)}let o=vnDataSelectors.selectVariables(n),c=Object.keys(t.variables).filter(a=>o[a].persistence==="local").reduce((a,u)=>(a[u]=t.variables[u],a),{});r.push({name:"render"}),r.push({name:"updateLocalVariables",options:{variables:c}})},lr=({payload:e,systemState:t,effects:r})=>{t.story.pointers[t.story.currentPointer].presetId=e.presetId},ur=({payload:e,systemState:t,effects:r})=>{t.story.currentPointer=e.mode,r.push({name:"render"})},lt=({systemState:e,effects:t})=>{systemStateSelectors.selectSkipMode(e)&&(e.story.skipMode=!1),e.story.autoMode=!0,t.push({name:"cancelTimerEffect"}),t.push({name:"systemInstructions",options:{delay:1e3,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}})},ut=({systemState:e,effects:t})=>{e.story.autoMode=!1,t.push({name:"cancelTimerEffect"})},fr=({systemState:e,effects:t})=>{systemStateSelectors.selectAutoMode(e)?ut({systemState:e,effects:t}):lt({systemState:e,effects:t})},ft=({systemState:e,effects:t})=>{systemStateSelectors.selectAutoMode(e)&&(e.story.autoMode=!1),e.story.skipMode=!0,t.push({name:"cancelTimerEffect"}),t.push({name:"systemInstructions",options:{delay:300,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}})},pt=({systemState:e,effects:t})=>{e.story.skipMode=!1,t.push({name:"cancelTimerEffect"})},pr=({systemState:e,effects:t})=>{systemStateSelectors.selectSkipMode(e)?pt({systemState:e,effects:t}):ft({systemState:e,effects:t})};var dr=({systemState:e,effects:t,payload:r})=>{e.saveData.push({id:Date.now().toString().slice(4,10),slotIndex:r.slotIndex,pointer:systemStateSelectors.selectSpecificPointer(e,"read"),history:systemStateSelectors.selectHistory(e)}),t.push({name:"saveVnData",options:{saveData:[...e.saveData]}})},hr=({systemState:e,effects:t,payload:r})=>{let{slotIndex:n}=r;console.log("systemState.saveData",e.saveData);let o=systemStateSelectors.selectSaveData(e).filter(a=>a.slotIndex===n);if(o.length===0){console.warn(`No save data found for slot index ${n}`);return}let{pointer:i,history:c}=o[o.length-1];e.story.currentPointer="read",e.story.pointers.read=i,e.story.history=c,t.push({name:"render"})};var me={};N(me,{createInitialState:()=>Ar,selectInitialIds:()=>dt,selectInitialPreset:()=>mr,selectPreset:()=>gr,selectPresets:()=>yr,selectScreen:()=>xr,selectSectionLines:()=>Er,selectUi:()=>Ir,selectVariables:()=>Sr,selectassets:()=>_r});var yr=e=>e.presets,mr=e=>e.presets[e.story.initialPresetId],gr=(e,t)=>e.presets[t],_r=e=>e.assets,Ir=e=>e.ui,xr=e=>e.screen,dt=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}},Sr=e=>e.variables||{},Er=(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},Ar=e=>{let t=dt(e),{sectionId:r,lineId:n}=t;if(!r||!n)throw new Error("No initial sectionId found");return e};var{createInitialState:br}=de,{createInitialState:vr}=fe,{createInitialState:wr,...Pr}=ye,{createInitialState:un,...Or}=me,ht=e=>re(e,Or),yt=(e,t)=>re(wr({sectionId:e.sectionId,lineId:e.lineId,presetId:e.presetId,autoNext:e.autoNext,saveData:{},variables:{}}),Pr,{transformActionFirstArgument:r=>({state:r,projectDataStore:t}),transformSelectorFirstArgument:r=>({state:r,projectDataStore:t})}),ge=ne(br,pe),_e=ne(vr,ue);var Ie=class{_projectDataStore;_systemStore;_constructRenderState;_constructPresentationState;_applySystemInstruction;_eventCallback=()=>{};constructor(){}init=({projectData:t})=>{this._projectDataStore=ht(t);let r=this._projectDataStore.selectInitialIds();this._systemStore=yt(r,this._projectDataStore),this._constructPresentationState=ge,this._constructRenderState=_e,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(u=>{u.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}`,assets:this._projectDataStore.selectassets(),ui:this._projectDataStore.selectUi()});console.log("\u{1F50D} RENDER DEBUG - renderState:",o),this._eventCallback({eventType:"render",payload:o})}},$r=Ie;export{$r as RouteEngine,ge as constructPresentationState,_e as constructRenderState};
1
+ var xt=Object.defineProperty;var N=(e,t)=>{for(var r in t)xt(e,r,{get:t[r],enumerable:!0})};var Pe=Symbol.for("immer-nothing"),Ae=Symbol.for("immer-draftable"),I=Symbol.for("immer-state");function x(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 bt=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)===bt}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 s=0;s<o.length;s++){let i=o[s],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(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(){x(2)}function z(e){return Object.isFrozen(e)}var St={};function S(e){let t=St[e];return t||x(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),x(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,s)=>Oe(e,n,t,o,s,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_,s=o,i=!1;n.type_===3&&(s=new Set(o),o.clear(),i=!0),R(s,(c,a)=>Oe(e,n,o,c,a,r,i)),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,s,i){if(P(o)){let c=s&&t&&t.type_!==3&&!K(t.assigned_,n)?s.concat(n):void 0,a=D(e,o,c);if(Ne(r,n,a),P(a))e.canAutoFreeze_=!1;else return}else i&&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,s=re;r&&(o=[n],s=C);let{revoke:i,proxy:c}=Proxy.revocable(o,s);return n.draft_=c,n.revoke_=i,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),s=o?.[I];if(s&&s.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(){x(11)},getPrototypeOf(e){return O(e.base_)},setPrototypeOf(){x(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 s=r;r=t;let i=this;return function(a=s,...l){return i.produce(a,f=>r.call(this,f,...l))}}typeof r!="function"&&x(6),n!==void 0&&typeof n!="function"&&x(7);let o;if(v(t)){let s=Se(this),i=ee(t,void 0),c=!0;try{o=r(i),c=!1}finally{c?Q(s):q(s)}return ve(s,n),we(o,s)}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 s=[],i=[];S("Patches").generateReplacementPatches_(t,o,s,i),n(s,i)}return o}else x(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(i,...c)=>this.produceWithPatches(i,a=>t(a,...c));let n,o;return[this.produce(t,r,(i,c)=>{n=i,o=c}),n,o]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){v(e)||x(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_)&&x(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)||x(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={},s={},{transformSelectorFirstArgument:i=a=>a,transformActionFirstArgument:c=a=>a}=r;for(let[a,l]of Object.entries(t))a!=="createInitialState"&&(a.startsWith("select")?o[a]=(...f)=>l(i(n),...f):s[a]=(...f)=>{n=ne(n,_=>l(c(_),...f))});return{...o,...s}},se=(e,t)=>r=>{let n=e(),o=Array.isArray(r)?r:[r];return ne(n,s=>{o.forEach(i=>{t.forEach(c=>{c(s,i)})})})};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 s=0;s<n.length;s++){let i=n[s];if(r.hasOwnProperty(i)){o=r[i];continue}if(o==null)return;o=o[i]}return o},Lt=(e,t,r,n)=>{let o="";for(let s of e)if(typeof s=="string")o+=s;else{let i=h(s,t,r,n);o+=i!=null?String(i):""}return o},Fe=(e,t,r,n)=>{let o=t[e.name];if(!o)throw Te(e.name,t);let s=e.args.map(i=>h(i,t,r,n));return o(...s)},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 i=j(e.left,t,r,n),c=j(e.right,t,r,n);switch(e.op){case d.AND:return i&&c;case d.OR:return i||c}}let o=h(e.left,t,r,n),s=h(e.right,t,r,n);switch(e.op){case d.EQ:return o==s;case d.NEQ:return o!=s;case d.GT:return o>s;case d.LT:return o<s;case d.GTE:return o>=s;case d.LTE:return o<=s;case d.IN:return Array.isArray(s)?s.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 s=e.conditions[o];if(s===null||j(s,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 i=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${e.iterable.path}`;throw De(i,o)}let s=[];for(let i=0;i<o.length;i++){let c=Object.create(n);c[e.itemVar]=o[i],e.indexVar&&(c[e.indexVar]=i);let a=h(e.body,t,r,c);Array.isArray(a)&&a.length===1?s.push(a[0]):s.push(a)}return s},Tt=(e,t,r,n)=>{let o={},s=null,i=!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 ")){i=!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(!i&&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 s of e.items)if(s.type===u.LOOP){let i=h(s,t,r,n);o.push(i)}else o.push(h(s,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,s="";for(let i=0;i<e.length;i++){let c=e[i],a=i>0?e[i-1]:"";!o&&(c==='"'||c==="'")?(o=!0,s=c,r+=c):o&&c===s&&a!=="\\"?(o=!1,s="",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 s=[],i=0;for(let c of o){let[a,l]=c,f=c.index;if(f>i){let _=r.substring(i,f);for(let y=0;y<n.length;y++)_=_.replace(`__ESCAPED_${y}__`,n[y]);_&&s.push(_)}let p=je(l.trim(),t);s.push(p),i=f+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&&s.push(c)}return{type:u.INTERPOLATION,parts:s}};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 s=e[o];if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=Object.keys(s);if(c.length===1&&c[0].startsWith("$for ")){let a=We(c[0],s[c[0]],t);r.push(a),n=!0;continue}}let i=w(s,t);r.push(i),(i.type===u.FUNCTION||i.type===u.CONDITIONAL||i.type===u.LOOP||i.type===u.OBJECT&&!i.fast||i.type===u.ARRAY&&!i.fast)&&(n=!0)}return{type:u.ARRAY,items:r,fast:!n}},Wt=(e,t)=>{let r=[],n=!1,o=Object.entries(e),s=0;for(;s<o.length;){let[i,c]=o[s];if(i.startsWith("$if ")||i.match(/^\$if#\w+\s/)||i.match(/^\$if\s+\w+.*:$/)){let a=Bt(o,s,t);r.push({key:i,value:a.node}),n=!0,s=a.nextIndex}else if(i.startsWith("$for ")){let a=We(i,c,t);r.push({key:i,value:a}),n=!0,s++}else{if(i.startsWith("$elif ")||i.startsWith("$else"))throw new g(`'${i.split(" ")[0]}' without matching '$if'`);if(i==="$if"||i==="$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(i,t),f={key:i,value:a};(l.type!==u.LITERAL||l.value!==i)&&(f.parsedKey=l),r.push(f),s++}}}return{type:u.OBJECT,properties:r,fast:!n}},Bt=(e,t,r={})=>{let n=[],o=[],s=t,[i,c]=e[s],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 g(`Invalid conditional syntax: ${i}`)}else l=i.substring(4),l.endsWith(":")&&(l=l.slice(0,-1).trim());ie(l);let f=b(l);for(n.push(f),o.push(w(c,r)),s++;s<e.length;){let[p,_]=e[s],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=b(m);n.push(J)}if(o.push(w(_,r)),s++,m===null)break}else break}return{node:{type:u.CONDITIONAL,conditions:n,bodies:o,id:a},nextIndex:s}},b=e=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")"))return b(e.slice(1,-1));let t=ue(e,"||");if(t!==-1)return{type:u.BINARY,op:d.OR,left:b(e.substring(0,t).trim()),right:b(e.substring(t+2).trim())};let r=ue(e,"&&");if(r!==-1)return{type:u.BINARY,op:d.AND,left:b(e.substring(0,r).trim()),right:b(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:s}of n){let i=ue(e,o);if(i!==-1)return{type:u.BINARY,op:s,left:b(e.substring(0,i).trim()),right:b(e.substring(i+o.length).trim())}}return e.startsWith("!")?{type:u.UNARY,op:L.NOT,operand:b(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 s=o[1].trim(),i=o[2].trim(),c,a=null;if(s.includes(",")){let p=s.split(",").map(_=>_.trim());if(p.length!==2)throw new g(`Invalid loop variables: ${s}. Expected format: "item" or "item, index"`);c=p[0],a=p[1]}else c=s;let l={type:u.VARIABLE,path:i},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},s=le(e,{functions:o});return ce(s,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,resolveFile:o})=>{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:o(s.fileId)})}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",animationProperties: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",animationProperties:s.properties})}}}},Je=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:o})=>{if(r.character){let s=r.character.items;for(let i of s){let{transformId:c,sprites:a}=i,l=a.map(({imageId:y})=>y),f=n.transforms[c],p={type:"container",id:`character-container-${i.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(([be,Et])=>{l.includes(be)&&_.push({partId:be,fileId:Et.fileId})})});for(let y of _)p.children.push({type:"sprite",id:`${i.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 s=r.visual.items;for(let i of s){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: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(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}`,animationProperties: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}`,animationProperties:c.properties})}}}}},Ge=({elements:e},{presentationState:t,ui:r,resources:n,dialogueUIHidden:o})=>{if(!t.dialogue||o)return;let s=r.layouts[t.dialogue.layoutId];if(!s)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:s.elements},l=U(c,{dialogue:{character:{name:i?.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 i={elements:o.layouts[r.choice.layoutId].elements},a=U(i,{choices:{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 s of o){let i=r.audio[s.audioId];e.push({id:s.id,type:"audio",url:n(i.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(s=>s.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:s})=>{let i={pendingEffects:[],variables:s,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 i.story.history.entries.push({sectionId:e}),i},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 s=ut(e);if(!s)return;let{nextTrigger:i,delay:c}=s;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}},ir=({state:e,projectDataStore:t})=>{let{pendingEffects:r}=e,n=me({state:e}),o=Y({state:e}),s=t.selectSectionLines(n.sectionId),i=s.findIndex(a=>a.id===n.lineId),c=s[i+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),s=o.findIndex(c=>c.id===n.lineId),i=o[s-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"})},ar=({state:e,projectDataStore:t},r)=>{let{sectionId:n,sceneId:o,mode:s,presetId:i}=r,c=t.selectSectionLines(n);s&&(e.story.currentPointer=s);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,i&&(e.story.pointers[a].presetId=i),e.pendingEffects.push({name:"render"})},ur=({state:e,projectDataStore:t},r)=>{let{operations:n}=r;for(let o of n){let{variableId:s,op:i,value:c}=o;i==="set"?e.variables[s]=c:i==="add"?e.variables[s]=(e.variables[s]||0)+c:i==="subtract"?e.variables[s]=(e.variables[s]||0)-c:i==="multiply"?e.variables[s]=(e.variables[s]||0)*c:i==="divide"?e.variables[s]=(e.variables[s]||0)/c:i==="increment"?e.variables[s]=(e.variables[s]||0)+1:i==="decrement"&&(e.variables[s]=(e.variables[s]||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:s,history:i}=o[o.length-1];e.story.currentPointer="read",e.story.pointers.read=s,e.story.history=i,e.pendingEffects.push({name:"render"})};var _e={};N(_e,{createInitialState:()=>wr,selectInitialIds:()=>gt,selectInitialPreset:()=>_r,selectLayout:()=>Ar,selectPreset:()=>Ir,selectPresets:()=>gr,selectResources:()=>xr,selectScreen:()=>Er,selectSectionLines:()=>Sr,selectUi:()=>br,selectVariables:()=>vr});var gr=e=>e.presets,_r=e=>e.presets[e.story.initialPresetId],Ir=(e,t)=>e.presets[t],Er=e=>e.screen,xr=e=>e.resources,br=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(s=>Object.entries(s.sections).map(([i,c])=>({...c,id:i}))).find(s=>s.id===t);if(r){let s=o.lines.findIndex(i=>i.id===r);return o.lines.slice(0,s+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 xe=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,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(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(i=>i.presentation||{}),o=this._constructPresentationState(n),s=this._constructRenderState({presentationState:o,screen:this._projectDataStore.selectScreen(),resolveFile:i=>`file:${i}`,resources:this._projectDataStore.selectResources(),ui:this._projectDataStore.selectUi()});this._eventCallback({eventType:"render",payload:s})}},Cr=xe;export{Cr as RouteEngine,Ie as constructPresentationState,Ee as constructRenderState};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "route-engine-js",
3
- "version": "0.0.2-rc1",
3
+ "version": "0.0.2-rc10",
4
4
  "type": "module",
5
5
  "main": "dist/RouteEngine.js",
6
6
  "exports": {
@@ -18,14 +18,13 @@
18
18
  "lint:fix": "bunx prettier src tests -w",
19
19
  "coverage": "vitest run --coverage",
20
20
  "vt:generate": "bun run esbuild.js && rtgl vt generate --skip-screenshots",
21
- "prepublishOnly": "bun run build"
21
+ "serve": "bun run esbuild.js && bunx serve -p 3004 .rettangoli/vt/_site"
22
22
  },
23
23
  "dependencies": {
24
24
  "immer": "^10.1.1",
25
25
  "jempl": "^0.1.0",
26
26
  "js-yaml": "^4.1.0",
27
- "puty": "^0.0.4-rc2",
28
- "route-graphics": "^0.0.1"
27
+ "puty": "^0.0.4-rc2"
29
28
  },
30
29
  "devDependencies": {
31
30
  "@vitest/coverage-v8": "^3.2.4",