route-engine-js 0.0.2-rc11 → 0.0.2-rc12
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 +2 -2
package/dist/RouteEngine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,{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 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};
|
|
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 k(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 i=0;i<s.length;i++){let o=s[i],c=n[o];c.writable===!1&&(c.writable=!0,c.configurable=!0),(c.get||c.set)&&(n[o]={configurable:!0,writable:!0,enumerable:c.enumerable,value:e[o]})}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=Pt),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>le(n,!0))),e}function Pt(){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 kt(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Pe(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=kt(M,e)}function $t(e){let t=e[x];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function ke(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,i)=>$e(e,n,t,s,i,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_,i=s,o=!1;n.type_===3&&(i=new Set(s),s.clear(),o=!0),W(i,(c,a)=>$e(e,n,s,c,a,r,o)),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,i,o){if(C(s)){let c=i&&t&&t.type_!==3&&!ne(t.assigned_,n)?i.concat(n):void 0,a=j(e,s,c);if(Ce(r,n,a),C(a))e.canAutoFreeze_=!1;else return}else o&&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,i=ue;r&&(s=[n],i=B);let{revoke:o,proxy:c}=Proxy.revocable(s,i);return n.draft_=c,n.revoke_=o,c}var ue={get(e,t){if(t===x)return e;let r=k(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 k(e)},ownKeys(e){return Reflect.ownKeys(k(e))},set(e,t,r){let n=Ve(k(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){let s=te(k(e),t),i=s?.[x];if(i&&i.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=k(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?k(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 i=r;r=t;let o=this;return function(a=i,...l){return o.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 i=Ne(this),o=ae(t,void 0),c=!0;try{s=r(o),c=!1}finally{c?ie(i):oe(i)}return Pe(i,n),ke(s,i)}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 i=[],o=[];R("Patches").generateReplacementPatches_(t,s,i,o),n(i,o)}return s}else L(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(o,...c)=>this.produceWithPatches(o,a=>t(a,...c));let n,s;return[this.produce(t,r,(o,c)=>{n=o,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 Pe(n,t),ke(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={},i={},{transformSelectorFirstArgument:o=a=>a,transformActionFirstArgument:c=a=>a}=r;for(let[a,l]of Object.entries(t))a!=="createInitialState"&&(a.startsWith("select")?s[a]=(...u)=>l(o(n),...u):i[a]=(...u)=>{n=fe(n,d=>l(c(d),...u))});return{...s,...i}},de=(e,t)=>r=>{let n=e(),s=Array.isArray(r)?r:[r];return fe(n,i=>{s.forEach(o=>{t.forEach(c=>{c(i,o)})})})};var Ie={};V(Ie,{addBackgrundOrCg:()=>Qe,addBgm:()=>rt,addCharacters:()=>qe,addChoices:()=>tt,addDialogue:()=>et,addSfx:()=>nt,addVisuals:()=>Ze,createInitialState:()=>fr,default:()=>_e,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"}},P=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 P(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new P(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return new P(`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 P(`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 i=_(e,{functions:n,partials:s},t,{});return i===void 0?{}: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 i=e[s];if(i==="[")r&&(t.push({type:"property",value:r}),r=""),n=!0;else if(i==="]"){if(n&&r){let o=r.trim();/^\d+$/.test(o)?t.push({type:"index",value:parseInt(o,10)}):t.push({type:"property",value:`[${r}]`}),r=""}n=!1}else r+=i}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 i=[],o="",c=0;for(let a=0;a<e.length;a++){let l=e[a];l==="["?(c++,o+=l):l==="]"?(c--,o+=l):l==="."&&c===0?o&&(i.push(o),o=""):o+=l}o&&i.push(o),n=[];for(let a of i){let l=Mt(a.trim());n.push(...l)}je.set(e,n)}let s=t;for(let i=0;i<n.length;i++){let o=n[i];if(o.type==="property"&&o.value in r){s=r[o.value];continue}if(s==null)return;(o.type==="property"||o.type==="index")&&(s=s[o.value])}return s},Bt=(e,t,r,n)=>{let s=[];for(let i of e)if(typeof i=="string")s.push(i);else{let o=_(i,t,r,n);s.push(o!=null?String(o):"")}return s.join("")},Ue=(e,t,r,n)=>{let s=t.functions||t,i=s[e.name];if(!i)throw We(e.name,s);let o=e.args.map(c=>_(c,t,r,n));return i(...o)},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 _(e,t,r,n)}},ze=(e,t,r,n)=>{if(e.op===E.AND||e.op===E.OR){let o=D(e.left,t,r,n),c=D(e.right,t,r,n);switch(e.op){case E.AND:return o&&c;case E.OR:return o||c}}let s=_(e.left,t,r,n),i=_(e.right,t,r,n);switch(e.op){case E.EQ:return s==i;case E.NEQ:return s!=i;case E.GT:return s>i;case E.LT:return s<i;case E.GTE:return s>=i;case E.LTE:return s<=i;case E.IN:return Array.isArray(i)?i.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):_(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 o=e.bodies[0];if(o.type===f.OBJECT&&o.properties.length<=5){let c={};for(let a of o.properties){let l=a.parsedKey?_(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=_(d,t,r,n);p.push(h!=null?String(h):"")}c[l]=p.join("")}else c[l]=_(u,t,r,n)}return c}}else{let o=e.bodies[1];if(o.type===f.OBJECT&&o.properties.length<=5){let c={};for(let a of o.properties){let l=a.parsedKey?_(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=_(d,t,r,n);p.push(h!=null?String(h):"")}c[l]=p.join("")}else c[l]=_(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 i=0;i<e.conditions.length;i++){let o=e.conditions[i];if(o===null||D(o,t,r,n))return _(e.bodies[i],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,i=r.bodies[0];if(s.startsWith(n+".")){let o=s.substring(n.length+1);if(i.type===f.OBJECT&&i.properties.length<=5){for(let a of i.properties)if(a.parsedKey)return null;let c=[];for(let a=0;a<t.length;a++){let l=t[a];if(l[o]){let u={};for(let p of i.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 I=g.substring(n.length+1),b=l[I];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 i=[],o=!0;for(let c of r.properties){let a=c.key,l=c.value;if(l.type===f.LITERAL)i.push({key:a,type:"literal",value:l.value});else if(l.type===f.VARIABLE){let u=l.path;if(u===n)i.push({key:a,type:"item"});else if(u.startsWith(n+".")){let p=u.substring(n.length+1);if(!p.includes(".")&&!p.includes("["))i.push({key:a,type:"prop",prop:p});else{o=!1;break}}else{o=!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)i.push({key:a,type:"item_string"});else if(p.startsWith(n+".")){let d=p.substring(n.length+1);if(!d.includes(".")&&!d.includes("["))i.push({key:a,type:"prop_string",prop:d});else{o=!1;break}}else{o=!1;break}}else{o=!1;break}}else{o=!1;break}}if(o){let c=new Array(t.length);if(i.length===3&&i[0].type==="prop"&&i[0].key==="id"&&i[1].type==="prop_string"&&i[1].key==="title"&&i[2].type==="prop"&&i[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 i)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 i=[],o=e.body;if(o.type===f.OBJECT&&o.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 o.properties){let y=h.parsedKey?_(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 I=g.path,b;if(I===c)b=u;else if(I===a)b=l;else if(I.startsWith(c+".")){let ee=I.substring(c.length+1);!ee.includes(".")&&!ee.includes("[")?b=u[ee]:b=w(I,r,{...n,[c]:u,...a&&{[a]:l}})}else b=w(I,r,{...n,[c]:u,...a&&{[a]:l}});A.push(b!=null?String(b):"")}else{let I={...n,[c]:u,...a&&{[a]:l}},b=_(g,t,r,I);A.push(b!=null?String(b):"")}p[y]=A.join("")}else{let A={...n,[c]:u,...a&&{[a]:l}};p[y]=_(m,t,r,A)}}i.push(p)}return i}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 i=n.properties[0].value;if(i.type===f.CONDITIONAL&&i.conditions.length===1&&i.conditions[0].type===f.VARIABLE&&i.conditions[0].path==="item.visible"){let o=i.bodies[0];if(o.type===f.OBJECT&&o.properties.length===2){let c=o.properties[0],a=o.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=_(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 i=zt(e,t,r,n,s);if(i!==null)return i;let o=[];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=_(e.body,t,r,a);Array.isArray(l)&&l.length===1?o.push(l[0]):o.push(l)}return o},Yt=(e,t,r,n)=>{if(e.whenCondition)return null;if(e.properties.length===1){let s=e.properties[0],i=s.parsedKey?_(s.parsedKey,t,r,n):s.key,o=s.value;if(o.type===f.OBJECT&&o.properties.length<=10&&!o.whenCondition){let c={},a={},l=!0;for(let u of o.properties){let p=u.parsedKey?_(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 I of A.parts)if(typeof I=="string")g.push(I);else if(I.type===f.VARIABLE){let b=w(I.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[i]=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 i=Yt(e,t,r,n);if(i!==null)return i;if(e.fast){let l={};for(let u of e.properties){let p=u.parsedKey?_(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=_(y,t,r,n);h.push(m!=null?String(m):"")}l[p]=h.join("")}else l[p]=_(d,t,r,n)}return l}let o={},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=_(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(o,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=_(p.value,t,r,n);d!==void 0&&(o[l.key]=d)}else{let d=_(l.value,t,r,n);d!==void 0&&(o[l.key]=d)}}else{let p=l.parsedKey?_(l.parsedKey,t,r,n):l.key,d=_(l.value,t,r,n);d!==void 0&&(o[p]=d)}}return o},Je={},Gt=(e,t,r,n)=>{let s=[];for(let i of e.items)if(i.type===f.LOOP){let o=_(i,t,r,n);s.push(o)}else{let o=_(i,t,r,n);o!==Je&&o!==void 0&&s.push(o)}return s},Ht=(e,t,r,n)=>{let{name:s,data:i,whenCondition:o}=e,c=t.partials||{},a=t.functions||t;if(o&&!D(o,a,r,n))return;if(!c[s])throw new P(`Partial '${s}' is not defined`);let l=n._partialStack||[];if(l.includes(s))throw new P(`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(i){let h=_(i,t,r,n);p={...p,...h}}return _(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,i="";for(let o=0;o<e.length;o++){let c=e[o],a=o>0?e[o-1]:"";!s&&(c==='"'||c==="'")?(s=!0,i=c,r+=c):s&&c===i&&a!=="\\"?(s=!1,i="",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 i of r)i==="["?s++:i==="]"&&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 i=[],o=0;for(let c of s){let[a,l]=c,u=c.index;if(u>o){let p=r.substring(o,u);for(let d=0;d<n.length;d++)p=p.replace(`__ESCAPED_${d}__`,n[d]);p&&i.push(p)}try{let p=Ye(l.trim(),t);i.push(p)}catch(p){if(p.message==="Invalid array index syntax")i.push(a);else throw p}o=u+a.length}if(o<r.length){let c=r.substring(o);for(let a=0;a<n.length;a++)c=c.replace(`__ESCAPED_${a}__`,n[a]);c&&i.push(c)}return{type:f.INTERPOLATION,parts:i}};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 i=e[s];if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let c=Object.keys(i);if(c.length===1&&c[0].startsWith("$for ")){let a=Ge(c[0],i[c[0]],t);r.push(a),n=!0;continue}}let o=N(i,t);r.push(o),(o.type===f.FUNCTION||o.type===f.CONDITIONAL||o.type===f.LOOP||o.type===f.PARTIAL||o.type===f.OBJECT&&!o.fast||o.type===f.ARRAY&&!o.fast)&&(n=!0)}return{type:f.ARRAY,items:r,fast:!n}},ir=(e,t)=>{let r=[],n=!1,s=null,i=Object.entries(e),o=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 i)for(let I of a)if(g===I||g.startsWith(I+" ")||g.startsWith(I+"#")){l.push(I);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,I]of Object.entries(d)){let b=g;(g.startsWith("\\$")||g.startsWith("$$"))&&(b=g.slice(1)),h[b]=I,y=!0}let m=null;if(y&&(m=N(h,t),m.type===f.OBJECT)){let g=!1;for(let I of m.properties)if(I.value.type===f.VARIABLE||I.value.type===f.INTERPOLATION||I.value.type===f.FUNCTION||I.value.type===f.CONDITIONAL||I.value.type===f.LOOP||I.value.type===f.OBJECT&&!I.value.fast||I.value.type===f.ARRAY&&!I.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 i)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(;o<i.length;){let[a,l]=i[o];if(a==="$when"){o++;continue}if(a.startsWith("$if ")||a.match(/^\$if#\w+\s/)||a.match(/^\$if\s+\w+.*:$/)){let u=or(i,o,t);r.push({key:a,value:u.node}),n=!0,o=u.nextIndex}else if(a.startsWith("$for ")){let u=Ge(a,l,t);r.push({key:a,value:u}),n=!0,o++}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),o++}}}let c={type:f.OBJECT,properties:r,fast:!n};return s&&(c.whenCondition=s),c},or=(e,t,r={})=>{let n=[],s=[],i=t,[o,c]=e[i],a=null,l;if(o.startsWith("$if#")){let p=o.match(/^\$if#(\w+)\s+(.+)$/);if(p)a=p[1],l=p[2];else throw new v(`Invalid conditional syntax: ${o}`)}else l=o.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)),i++;i<e.length;){let[p,d]=e[i],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)),i++,y===null)break}else break}return{node:{type:f.CONDITIONAL,conditions:n,bodies:s,id:a},nextIndex:i}},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:i,type:o}of n){let c=X(e,i);if(c!==-1)return{type:f.BINARY,op:o,left:O(e.substring(0,c).trim()),right:O(e.substring(c+i.length).trim())}}let s=[" + "," - "," * "," / "," % "];for(let i of s)if(X(e,i)!==-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 i=s[1].trim(),o=s[2].trim(),c,a=null;if(i.includes(",")){let p=i.split(",").map(d=>d.trim());if(p.length!==2)throw new v(`Invalid loop variables: ${i}. Expected format: "item" or "item, index"`);c=p[0],a=p[1]}else c=i;let l={type:f.VARIABLE,path:o},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,i={...ge,...n},o=G(e,{functions:i}),c={};for(let[a,l]of Object.entries(s))c[a]=G(l,{functions:i});return ye(o,t,{functions:i,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,resolveFile:s})=>{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:s(i.fileId)})}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",animationProperties: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",animationProperties:i.properties})}}}},qe=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:s})=>{if(r.character){let i=r.character.items;for(let o of i){let{transformId:c,sprites:a}=o,l=a.map(({imageId:h})=>h),u=n.transforms[c],p={type:"container",id:`character-container-${o.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:`${o.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 i=r.visual.items;for(let o of i){if(o.resourceId&&o.resourceType){let c;if(o.resourceType==="image")c=n.images[o.resourceId];else continue;if(c){let a=n.transforms[o.transformId];e.push({id:`visual-${o.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(o.animations){if(o.animations.in){let c=n.animations[o.animations.in];t.push({id:`${o.id}-animation`,type:"keyframes",event:"add",elementId:`visual-${o.id}`,animationProperties:c.properties})}if(o.animations.out){let c=n.animations[o.animations.out];t.push({id:`${o.id}-animation-2`,type:"keyframes",event:"remove",elementId:`visual-${o.id}`,animationProperties:c.properties})}}}}},et=({elements:e},{presentationState:t,ui:r,resources:n,dialogueUIHidden:s})=>{if(!t.dialogue||s)return;let i=r.layouts[t.dialogue.layoutId];if(!i)return;let o;t.dialogue.characterId&&(o=n.characters[t.dialogue.characterId]),t.dialogue.character&&(o={...o,name:t.dialogue.character.name});let c={elements:i.elements},l=H(c,{dialogue:{character:{name:o?.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 o={elements:s.layouts[r.choice.layoutId].elements},a=H(o,{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 i of s){let o=r.audio[i.audioId];e.push({id:i.id,type:"audio",url:n(o.fileId)})}}},_e=[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(i=>i.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:()=>kr,selectAutoMode:()=>q,selectAutoNext:()=>yt,selectCurrentPointer:()=>Ee,selectCurrentPreset:()=>yr,selectCurrentPresetId:()=>ht,selectDialogueUIHidden:()=>_r,selectHistory:()=>mt,selectPendingEffects:()=>hr,selectPointerMode:()=>Z,selectPointers:()=>mr,selectRuntimeState:()=>gr,selectSaveData:()=>_t,selectSkipMode:()=>Q,selectSpecificPointer:()=>gt,selectVariables:()=>Ir,setPreset:()=>Sr,startAutoMode:()=>It,startSkipMode:()=>vt,stopAutoMode:()=>At,stopSkipMode:()=>Et,toggleAutoMode:()=>Lr,toggleDialogueUIHidden:()=>Nr,toggleSkipMode:()=>Pr,updateVariable:()=>xr});var dr=({sectionId:e,lineId:t,presetId:r,autoNext:n,saveData:s,variables:i})=>{let o={pendingEffects:[],variables:i,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 o.story.history.entries.push({sectionId:e}),o},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,_r=({state:e})=>e.story.dialogueUIHidden,mt=({state:e})=>e.story.history,gt=({state:e,mode:t})=>e.story.pointers[t],_t=({state:e})=>e.saveData,Ir=({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 i=yt(e);if(!i)return;let{nextTrigger:o,delay:c}=i;switch(o){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}),i=t.selectSectionLines(n.sectionId),o=i.findIndex(a=>a.id===n.lineId),c=i[o+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),i=s.findIndex(c=>c.id===n.lineId),o=s[i-1];if(!o){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=o.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:i,presetId:o}=r,c=t.selectSectionLines(n);i&&(e.story.currentPointer=i);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,o&&(e.story.pointers[a].presetId=o),e.pendingEffects.push({name:"render"})},xr=({state:e,projectDataStore:t},r)=>{let{operations:n}=r;for(let s of n){let{variableId:i,op:o,value:c}=s;o==="set"?e.variables[i]=c:o==="add"?e.variables[i]=(e.variables[i]||0)+c:o==="subtract"?e.variables[i]=(e.variables[i]||0)-c:o==="multiply"?e.variables[i]=(e.variables[i]||0)*c:o==="divide"?e.variables[i]=(e.variables[i]||0)/c:o==="increment"?e.variables[i]=(e.variables[i]||0)+1:o==="decrement"&&(e.variables[i]=(e.variables[i]||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"})},It=({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}):It({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"})},Pr=({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"})},kr=({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=_t({state:e}).filter(c=>c.slotIndex===r);if(s.length===0){console.warn(`No save data found for slot index ${r}`);return}let{pointer:i,history:o}=s[s.length-1];e.story.currentPointer="read",e.story.pointers.read=i,e.story.history=o,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(i=>Object.entries(i.sections).map(([o,c])=>({...c,id:o}))).find(i=>i.id===t);if(r){let i=s.lines.findIndex(o=>o.id===r);return s.lines.slice(0,i+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}=Ie,{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,_e);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,o=(this._systemStore.selectCurrentPreset()?.eventsMap||{})[r]?.systemActions,c=o?Object.keys(o)[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(o=>o.presentation||{}),s=this._constructPresentationState(n),i=this._constructRenderState({presentationState:s,screen:this._projectDataStore.selectScreen(),resolveFile:o=>`file:${o}`,resources:this._projectDataStore.selectResources(),ui:this._projectDataStore.selectUi()});this._eventCallback({eventType:"render",payload:i})}},Xr=Oe;export{Xr as RouteEngine,xe as constructPresentationState,Se as constructRenderState};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "route-engine-js",
|
|
3
|
-
"version": "0.0.2-
|
|
3
|
+
"version": "0.0.2-rc12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/RouteEngine.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"immer": "^10.1.1",
|
|
25
|
-
"jempl": "
|
|
25
|
+
"jempl": "0.2.0-rc1",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"puty": "^0.0.4-rc2"
|
|
28
28
|
},
|