route-engine-js 0.0.2-rc10 → 0.0.2-rc11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RouteEngine.js +1 -1
- package/package.json +1 -1
package/dist/RouteEngine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var 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};
|
|
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};
|