route-engine-js 0.0.6 → 0.1.0
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 Ht=Object.defineProperty;var K=(e,t)=>{for(var r in t)Ht(e,r,{get:t[r],enumerable:!0})};var Ye=Symbol.for("immer-nothing"),je=Symbol.for("immer-draftable"),R=Symbol.for("immer-state");function S(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var J=Object.getPrototypeOf;function Y(e){return!!e&&!!e[R]}function W(e){return e?Ge(e)||Array.isArray(e)||!!e[je]||!!e.constructor?.[je]||le(e)||ue(e):!1}var Xt=Object.prototype.constructor.toString();function Ge(e){if(!e||typeof e!="object")return!1;let t=J(e);if(t===null)return!0;let r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object?!0:typeof r=="function"&&Function.toString.call(r)===Xt}function oe(e,t){ce(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function ce(e){let t=e[R];return t?t.type_:Array.isArray(e)?1:le(e)?2:ue(e)?3:0}function ge(e,t){return ce(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function He(e,t,r){let n=ce(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function Qt(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function le(e){return e instanceof Map}function ue(e){return e instanceof Set}function F(e){return e.copy_||e.base_}function Ie(e,t){if(le(e))return new Map(e);if(ue(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let r=Ge(e);if(t===!0||t==="class_only"&&!r){let n=Object.getOwnPropertyDescriptors(e);delete n[R];let s=Reflect.ownKeys(n);for(let i=0;i<s.length;i++){let o=s[i],a=n[o];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(n[o]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[o]})}return Object.create(J(e),n)}else{let n=J(e);if(n!==null&&r)return{...e};let s=Object.create(n);return Object.assign(s,e)}}function Ee(e,t=!1){return fe(e)||Y(e)||!W(e)||(ce(e)>1&&(e.set=e.add=e.clear=e.delete=qt),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>Ee(n,!0))),e}function qt(){S(2)}function fe(e){return Object.isFrozen(e)}var Zt={};function j(e){let t=Zt[e];return t||S(0,e),t}var Q;function Xe(){return Q}function er(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ue(e,t){t&&(j("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function ve(e){_e(e),e.drafts_.forEach(tr),e.drafts_=null}function _e(e){e===Q&&(Q=e.parent_)}function ze(e){return Q=er(Q,e)}function tr(e){let t=e[R];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[R].modified_&&(ve(t),S(4)),W(e)&&(e=se(t,e),t.parent_||ae(t,e)),t.patches_&&j("Patches").generateReplacementPatches_(r[R].base_,e,t.patches_,t.inversePatches_)):e=se(t,r,[]),ve(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Ye?e:void 0}function se(e,t,r){if(fe(t))return t;let n=t[R];if(!n)return oe(t,(s,i)=>Je(e,n,t,s,i,r)),t;if(n.scope_!==e)return t;if(!n.modified_)return ae(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),oe(i,(a,l)=>Je(e,n,s,a,l,r,o)),ae(e,s,!1),r&&e.patches_&&j("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function Je(e,t,r,n,s,i,o){if(Y(s)){let a=i&&t&&t.type_!==3&&!ge(t.assigned_,n)?i.concat(n):void 0,l=se(e,s,a);if(He(r,n,l),Y(l))e.canAutoFreeze_=!1;else return}else o&&r.add(s);if(W(s)&&!fe(s)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;se(e,s),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&ae(e,s)}}function ae(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Ee(t,r)}function rr(e,t){let r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:Xe(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},s=n,i=we;r&&(s=[n],i=q);let{revoke:o,proxy:a}=Proxy.revocable(s,i);return n.draft_=a,n.revoke_=o,a}var we={get(e,t){if(t===R)return e;let r=F(e);if(!ge(r,t))return nr(e,r,t);let n=r[t];return e.finalized_||!W(n)?n:n===ye(e.base_,t)?(me(e),e.copy_[t]=Ae(n,e)):n},has(e,t){return t in F(e)},ownKeys(e){return Reflect.ownKeys(F(e))},set(e,t,r){let n=Qe(F(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){let s=ye(F(e),t),i=s?.[R];if(i&&i.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(Qt(r,s)&&(r!==void 0||ge(e.base_,t)))return!0;me(e),be(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 ye(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,me(e),be(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let r=F(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty(){S(11)},getPrototypeOf(e){return J(e.base_)},setPrototypeOf(){S(12)}},q={};oe(we,(e,t)=>{q[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});q.deleteProperty=function(e,t){return q.set.call(this,e,t,void 0)};q.set=function(e,t,r){return we.set.call(this,e[0],t,r,e[0])};function ye(e,t){let r=e[R];return(r?F(r):e)[t]}function nr(e,t,r){let n=Qe(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}function Qe(e,t){if(!(t in e))return;let r=J(e);for(;r;){let n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=J(r)}}function be(e){e.modified_||(e.modified_=!0,e.parent_&&be(e.parent_))}function me(e){e.copy_||(e.copy_=Ie(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var ir=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(l=i,...c){return o.produce(l,u=>r.call(this,u,...c))}}typeof r!="function"&&S(6),n!==void 0&&typeof n!="function"&&S(7);let s;if(W(t)){let i=ze(this),o=Ae(t,void 0),a=!0;try{s=r(o),a=!1}finally{a?ve(i):_e(i)}return Ue(i,n),Ke(s,i)}else if(!t||typeof t!="object"){if(s=r(t),s===void 0&&(s=t),s===Ye&&(s=void 0),this.autoFreeze_&&Ee(s,!0),n){let i=[],o=[];j("Patches").generateReplacementPatches_(t,s,i,o),n(i,o)}return s}else S(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(o,...a)=>this.produceWithPatches(o,l=>t(l,...a));let n,s;return[this.produce(t,r,(o,a)=>{n=o,s=a}),n,s]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){W(e)||S(8),Y(e)&&(e=or(e));let t=ze(this),r=Ae(e,void 0);return r[R].isManual_=!0,_e(t),r}finishDraft(e,t){let r=e&&e[R];(!r||!r.isManual_)&&S(9);let{scope_:n}=r;return Ue(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=j("Patches").applyPatches_;return Y(e)?n(e,t):this.produce(e,s=>n(s,t))}};function Ae(e,t){let r=le(e)?j("MapSet").proxyMap_(e,t):ue(e)?j("MapSet").proxySet_(e,t):rr(e,t);return(t?t.scope_:Xe()).drafts_.push(r),r}function or(e){return Y(e)||S(10,e),qe(e)}function qe(e){if(!W(e)||fe(e))return e;let t=e[R],r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=Ie(e,t.scope_.immer_.useStrictShallowCopy_)}else r=Ie(e,!0);return oe(r,(n,s)=>{He(r,n,qe(s))}),t&&(t.finalized_=!1),r}var T=new ir,xe=T.produce,qn=T.produceWithPatches.bind(T),Zn=T.setAutoFreeze.bind(T),ei=T.setUseStrictShallowCopy.bind(T),ti=T.applyPatches.bind(T),ri=T.createDraft.bind(T),ni=T.finishDraft.bind(T);var $e=(e,t,r={})=>{let n=structuredClone(e),s={},i={},{transformSelectorFirstArgument:o=l=>l,transformActionFirstArgument:a=l=>l}=r;for(let[l,c]of Object.entries(t))l!=="createInitialState"&&(l.startsWith("select")?s[l]=(...u)=>c(o(n),...u):i[l]=(...u)=>{n=xe(n,p=>c(a(p),...u))});return{...s,...i}},Pe=(e,t)=>r=>{let n=e(),s=Array.isArray(r)?r:[r];return xe(n,i=>{s.forEach(o=>{t.forEach(a=>{a(i,o)})})})};var de=e=>{let t=window.atob(e.replace(/^data:image\/[a-z]+;base64,/,"")),r=t.length,n=new Uint8Array(r);for(let s=0;s<r;s++)n[s]=t.charCodeAt(s);return n.buffer};var Se={};K(Se,{addBackgrundOrCg:()=>pt,addBgm:()=>It,addCharacters:()=>ht,addChoices:()=>gt,addDialogue:()=>mt,addGlobalAudios:()=>Et,addLayout:()=>bt,addModals:()=>At,addScreen:()=>dt,addSfx:()=>vt,addVisuals:()=>yt,addVoice:()=>_t,createInitialState:()=>Mr,default:()=>Te});var d={LITERAL:0,VARIABLE:1,INTERPOLATION:2,FUNCTION:3,BINARY:4,UNARY:5,CONDITIONAL:6,LOOP:7,OBJECT:8,ARRAY:9,PARTIAL:10,PATH_REFERENCE:11},w={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},Z={NOT:0};var _=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},L=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var ke=e=>{if(!e||e.trim()==="")throw new _("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let r=e.includes("===")?"==":"!=";throw new _(`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 _(`Incomplete comparison expression - missing right operand (got: '${e}')`)},Ze=e=>{if(e.trim().endsWith(" in"))throw new _(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new _(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,r]=e.split(" in ");if(!r||r.trim()==="")throw new _(`Missing iterable expression after 'in' (got: '$for ${e}')`);let n=t.includes(",")?t.split(",").map(s=>s.trim()):[t.trim()];for(let s of n){if(!s)throw new _(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s))throw new _(`Invalid loop syntax (got: '$for ${e}')`)}};var et=(e,t,r=!1)=>{if(t===null)return new L(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new L(`Cannot iterate over undefined value at '$for ${e}'`);let n=typeof t;return r?new L(`Cannot iterate over non-array value in loop '${e}' - got ${n} instead`):new L(`Cannot iterate over non-array value (got: ${n}) at '$for ${e}'`)},tt=(e,t)=>{let r=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new L(`Unknown function '${e}' (${r})`)};var sr=(e,t,r={})=>{let n={},s={};r&&typeof r=="object"&&(r.functions!==void 0||r.partials!==void 0?(n=r.functions||{},s=r.partials||{}):typeof r=="object"&&(n=r));let o=b(e,{functions:n,partials:s},t,{});return o===void 0?{}:o},b=(e,t,r,n)=>{let s=t.functions||t;if(e.var&&!e.type)return P(e.var,r,n);if(e.type===d.LITERAL)return e.value;if(e.type===d.VARIABLE)return P(e.path,r,n);if(e.type===d.INTERPOLATION)return cr(e.parts,t,r,n);switch(e.type){case d.FUNCTION:return nt(e,t,r,n);case d.BINARY:return it(e,t,r,n);case d.UNARY:return ot(e,t,r,n);case d.CONDITIONAL:return ur(e,t,r,n);case d.LOOP:return yr(e,t,r,n);case d.OBJECT:return gr(e,t,r,n);case d.ARRAY:return Ir(e,t,r,n);case d.PARTIAL:return vr(e,t,r,n);case d.PATH_REFERENCE:return _r(e,t,r,n);default:throw new Error(`Unknown node type: ${e.type}`)}},rt=new Map,ar=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();if(/^\d+$/.test(o))t.push({type:"index",value:parseInt(o,10)});else if(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'")){let a=o.slice(1,-1);t.push({type:"property",value:a})}else t.push({type:"property",value:o});r=""}n=!1}else r+=i}return r&&t.push({type:"property",value:r}),t},P=(e,t,r)=>{if(!e)return;if(e in r)return r[e];let n=rt.get(e);if(!n){let i=[],o="",a=0;for(let l=0;l<e.length;l++){let c=e[l];c==="["?(a++,o+=c):c==="]"?(a--,o+=c):c==="."&&a===0?o&&(i.push(o),o=""):o+=c}o&&i.push(o),n=[];for(let l of i){let c=ar(l.trim());n.push(...c)}rt.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},cr=(e,t,r,n)=>{let s=[];for(let i of e)if(typeof i=="string")s.push(i);else{let o=b(i,t,r,n);s.push(o!=null?String(o):"")}return s.join("")},nt=(e,t,r,n)=>{let s=t.functions||t,i=s[e.name];if(!i)throw tt(e.name,s);let o=e.args.map(a=>b(a,t,r,n));return i(...o)},G=(e,t,r,n)=>{if(e.var&&!e.type)return P(e.var,r,n);switch(e.type){case d.VARIABLE:return P(e.path,r,n);case d.LITERAL:return e.value;case d.BINARY:return it(e,t,r,n);case d.UNARY:return ot(e,t,r,n);case d.FUNCTION:return nt(e,t,r,n);default:return b(e,t,r,n)}},it=(e,t,r,n)=>{if(e.op===w.AND||e.op===w.OR){let o=G(e.left,t,r,n),a=G(e.right,t,r,n);switch(e.op){case w.AND:return o&&a;case w.OR:return o||a}}let s=b(e.left,t,r,n),i=b(e.right,t,r,n);switch(e.op){case w.EQ:return s==i;case w.NEQ:return s!=i;case w.GT:return s>i;case w.LT:return s<i;case w.GTE:return s>=i;case w.LTE:return s<=i;case w.IN:return Array.isArray(i)?i.includes(s):!1;case w.ADD:if(typeof s!="number"||typeof i!="number")throw new L(`Arithmetic operations require numbers. Got ${typeof s} + ${typeof i}`);return s+i;case w.SUBTRACT:if(typeof s!="number"||typeof i!="number")throw new L(`Arithmetic operations require numbers. Got ${typeof s} - ${typeof i}`);return s-i;default:throw new Error(`Unknown binary operator: ${e.op}`)}},ot=(e,t,r,n)=>{let s=e.op===Z.NOT?G(e.operand,t,r,n):b(e.operand,t,r,n);switch(e.op){case Z.NOT:return!s;default:throw new Error(`Unknown unary operator: ${e.op}`)}},lr=(e,t,r,n)=>{if(e.conditions.length===2&&e.conditions[1]===null){let s=e.conditions[0];if(s.type===d.VARIABLE)if(P(s.path,r,n)){let o=e.bodies[0];if(o.type===d.OBJECT&&o.properties.length<=5){let a={};for(let l of o.properties){let c=l.parsedKey?b(l.parsedKey,t,r,n):l.key,u=l.value;if(u.type===d.LITERAL)a[c]=u.value;else if(u.type===d.VARIABLE)a[c]=P(u.path,r,n);else if(u.type===d.INTERPOLATION){let f=[];for(let p of u.parts)if(typeof p=="string")f.push(p);else if(p.type===d.VARIABLE){let y=P(p.path,r,n);f.push(y!=null?String(y):"")}else{let y=b(p,t,r,n);f.push(y!=null?String(y):"")}a[c]=f.join("")}else a[c]=b(u,t,r,n)}return a}}else{let o=e.bodies[1];if(o.type===d.OBJECT&&o.properties.length<=5){let a={};for(let l of o.properties){let c=l.parsedKey?b(l.parsedKey,t,r,n):l.key,u=l.value;if(u.type===d.LITERAL)a[c]=u.value;else if(u.type===d.VARIABLE)a[c]=P(u.path,r,n);else if(u.type===d.INTERPOLATION){let f=[];for(let p of u.parts)if(typeof p=="string")f.push(p);else if(p.type===d.VARIABLE){let y=P(p.path,r,n);f.push(y!=null?String(y):"")}else{let y=b(p,t,r,n);f.push(y!=null?String(y):"")}a[c]=f.join("")}else a[c]=b(u,t,r,n)}return a}}}return null},ur=(e,t,r,n)=>{let s=lr(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||G(o,t,r,n))return b(e.bodies[i],t,r,n)}return st},fr=(e,t)=>{let r=e.body,n=e.itemVar;if(r.type===d.CONDITIONAL&&r.conditions.length===1&&r.conditions[0].type===d.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===d.OBJECT&&i.properties.length<=5){for(let l of i.properties)if(l.parsedKey)return null;let a=[];for(let l=0;l<t.length;l++){let c=t[l];if(c[o]){let u={};for(let f of i.properties){let p=f.key,y=f.value;if(y.type===d.LITERAL)u[p]=y.value;else if(y.type===d.VARIABLE){let h=y.path;if(h===n)u[p]=c;else if(h.startsWith(n+".")){let g=h.substring(n.length+1);u[p]=c[g]}else return null}else if(y.type===d.INTERPOLATION){let h=[],g=!0;for(let I of y.parts)if(typeof I=="string")h.push(I);else if(I.type===d.VARIABLE){let m=I.path;if(m===n)h.push(c!=null?String(c):"");else if(m.startsWith(n+".")){let v=m.substring(n.length+1),A=c[v];h.push(A!=null?String(A):"")}else{g=!1;break}}else{g=!1;break}if(!g)return null;u[p]=h.join("")}else return null}a.push(u)}}return a}}}return null},dr=(e,t)=>{let r=e.body,n=e.itemVar,s=fr(e,t);if(s!==null)return s;if(r.type===d.OBJECT&&r.properties.length<=5&&!r.whenCondition){for(let a of r.properties)if(a.parsedKey)return null;let i=[],o=!0;for(let a of r.properties){let l=a.key,c=a.value;if(c.type===d.LITERAL)i.push({key:l,type:"literal",value:c.value});else if(c.type===d.VARIABLE){let u=c.path;if(u===n)i.push({key:l,type:"item"});else if(u.startsWith(n+".")){let f=u.substring(n.length+1);if(!f.includes(".")&&!f.includes("["))i.push({key:l,type:"prop",prop:f});else{o=!1;break}}else{o=!1;break}}else if(c.type===d.INTERPOLATION&&c.parts.length===1){let u=c.parts[0];if(u.type===d.VARIABLE){let f=u.path;if(f===n)i.push({key:l,type:"item_string"});else if(f.startsWith(n+".")){let p=f.substring(n.length+1);if(!p.includes(".")&&!p.includes("["))i.push({key:l,type:"prop_string",prop:p});else{o=!1;break}}else{o=!1;break}}else{o=!1;break}}else{o=!1;break}}if(o){let a=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 l=0;l<t.length;l++){let c=t[l];a[l]={id:c.id,title:c.title!=null?String(c.title):"",completed:c.completed}}else for(let l=0;l<t.length;l++){let c=t[l],u={};for(let f of i)if(f.type==="literal")u[f.key]=f.value;else if(f.type==="item")u[f.key]=c;else if(f.type==="prop")u[f.key]=c[f.prop];else if(f.type==="item_string")u[f.key]=c!=null?String(c):"";else if(f.type==="prop_string"){let p=c[f.prop];u[f.key]=p!=null?String(p):""}a[l]=u}return a}}return null},pr=(e,t,r,n,s)=>{let i=[],o=e.body;if(o.type===d.OBJECT&&o.fast!==!1){let a=e.itemVar,l=e.indexVar;for(let c=0;c<s.length;c++){let u=s[c],f={},p={...n,[a]:u,...l&&{[l]:c}};p.__paths__||(p.__paths__=n.__paths__||{});let y=e.iterable.path||"";if(n&&n.__paths__&&y){let h=y.split("."),g=h[0];g in n.__paths__&&(y=n.__paths__[g],h.length>1&&(y+="."+h.slice(1).join(".")))}p.__paths__={...p.__paths__,[a]:`${y}[${c}]`,...l&&{[l]:c}};for(let h of o.properties){let g=h.parsedKey?b(h.parsedKey,t,r,p):h.key,I=h.value;if(I.type===d.LITERAL)f[g]=I.value;else if(I.type===d.VARIABLE){let m=I.path;if(m===a)f[g]=u;else if(m===l)f[g]=c;else if(m.startsWith(a+".")){let v=m.substring(a.length+1);!v.includes(".")&&!v.includes("[")?f[g]=u[v]:f[g]=P(m,r,{...n,[a]:u,...l&&{[l]:c}})}else f[g]=P(m,r,{...n,[a]:u,...l&&{[l]:c}})}else if(I.type===d.INTERPOLATION){let m=[];for(let v of I.parts)if(typeof v=="string")m.push(v);else if(v.type===d.VARIABLE){let A=v.path,E;if(A===a)E=u;else if(A===l)E=c;else if(A.startsWith(a+".")){let x=A.substring(a.length+1);!x.includes(".")&&!x.includes("[")?E=u[x]:E=P(A,r,{...n,[a]:u,...l&&{[l]:c}})}else E=P(A,r,{...n,[a]:u,...l&&{[l]:c}});m.push(E!=null?String(E):"")}else{let A={...n,[a]:u,...l&&{[l]:c}},E=b(v,t,r,A);m.push(E!=null?String(E):"")}f[g]=m.join("")}else{let m={...n,[a]:u,...l&&{[l]:c}};f[g]=b(I,t,r,m)}}i.push(f)}return i}return null},hr=(e,t,r)=>{let n=e.body;if(n.type===d.OBJECT&&n.properties.length===1&&n.properties[0].key==="$if item.visible"){let i=n.properties[0].value;if(i.type===d.CONDITIONAL&&i.conditions.length===1&&i.conditions[0].type===d.VARIABLE&&i.conditions[0].path==="item.visible"){let o=i.bodies[0];if(o.type===d.OBJECT&&o.properties.length===2){let a=o.properties[0],l=o.properties[1];if(a.key==="id"&&a.value.type===d.VARIABLE&&a.value.path==="item.id"&&l.key==="$if item.highlighted"&&l.value.type===d.CONDITIONAL){let c=[];for(let u=0;u<t.length;u++){let f=t[u];if(f.visible){let p={id:f.id};f.highlighted?(p.highlight=!0,p.message=`This item is highlighted: ${f.name}`):(p.highlight=!1,p.message=f.name),c.push(p)}}return c}}}}return null},yr=(e,t,r,n)=>{let s=b(e.iterable,t,r,n);if(!Array.isArray(s)){let c,u=!1;if(e.iterable.type===d.FUNCTION){u=!0;let p=e.iterable.args.map(y=>y.type===d.LITERAL?typeof y.value=="string"?`'${y.value}'`:String(y.value):y.type===d.VARIABLE?y.path:y.type===d.FUNCTION?`${y.name}(...)`:"?").join(", ");c=`${e.iterable.name}(${p})`}else c=e.iterable.path||"undefined";let f=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${c}`;throw et(f,s,u)}if(!e.indexVar){let c=hr(e,s,e.itemVar);if(c!==null)return c}if(!e.indexVar){let c=dr(e,s);if(c!==null)return c}let i=pr(e,t,r,n,s);if(i!==null)return i;let o=[],a=e.iterable.path||"";if(n&&n.__paths__&&a){let c=a.split("."),u=c[0];u in n.__paths__&&(a=n.__paths__[u],c.length>1&&(a+="."+c.slice(1).join(".")))}let l=!1;e.body.type===d.ARRAY&&(e.body.items.length<=1?l=!1:l=e.body._shouldPreserveArray??=e.body.items.some(c=>c.type===d.OBJECT&&c.properties.some(u=>u.key.startsWith("$if ")||u.key.startsWith("$when "))));for(let c=0;c<s.length;c++){let u=e.indexVar?{...n,[e.itemVar]:s[c],[e.indexVar]:c}:{...n,[e.itemVar]:s[c]};u.__paths__||(u.__paths__=n.__paths__||{}),u.__paths__={...u.__paths__,[e.itemVar]:`${a}[${c}]`},e.indexVar&&(u.__paths__[e.indexVar]=c);let f=b(e.body,t,r,u);if(Array.isArray(f)&&f.length===1&&!l){let p=f[0];o.push(p===void 0?{}:p)}else o.push(f===void 0?{}:f)}return o},mr=(e,t,r,n)=>{if(e.whenCondition)return null;if(e.properties.length===1){let s=e.properties[0],i=s.parsedKey?b(s.parsedKey,t,r,n):s.key,o=s.value;if(o.type===d.OBJECT&&o.properties.length<=10&&!o.whenCondition){let a={},l={},c=!0;for(let u of o.properties){let f=u.parsedKey?b(u.parsedKey,t,r,n):u.key,p=u.value;if(p.type===d.LITERAL)l[f]=p.value;else if(p.type===d.VARIABLE)l[f]=P(p.path,r,n);else if(p.type===d.INTERPOLATION){let y=[];for(let h of p.parts)if(typeof h=="string")y.push(h);else if(h.type===d.VARIABLE){let g=P(h.path,r,n);y.push(g!=null?String(g):"")}else{c=!1;break}if(!c)break;l[f]=y.join("")}else if(p.type===d.OBJECT&&p.properties.length<=5){let y={};for(let h of p.properties){let g=h.key,I=h.value;if(I.type===d.LITERAL)y[g]=I.value;else if(I.type===d.VARIABLE)y[g]=P(I.path,r,n);else if(I.type===d.INTERPOLATION){let m=[];for(let v of I.parts)if(typeof v=="string")m.push(v);else if(v.type===d.VARIABLE){let A=P(v.path,r,n);m.push(A!=null?String(A):"")}else{c=!1;break}if(!c)break;y[g]=m.join("")}else{c=!1;break}}if(!c)break;l[f]=y}else{c=!1;break}}if(c)return a[i]=l,a}}return null},gr=(e,t,r,n)=>{let s=t.functions||t;if(e.whenCondition&&!G(e.whenCondition,s,r,n))return;let i=mr(e,t,r,n);if(i!==null)return i;if(e.fast){let c={};for(let u of e.properties){let f=u.parsedKey?b(u.parsedKey,t,r,n):u.key,p=u.value;if(p.type===d.LITERAL)c[f]=p.value;else if(p.type===d.VARIABLE)c[f]=P(p.path,r,n);else if(p.type===d.INTERPOLATION){let y=[];for(let h of p.parts)if(typeof h=="string")y.push(h);else if(h.type===d.VARIABLE){let g=P(h.path,r,n);y.push(g!=null?String(g):"")}else{let g=b(h,t,r,n);y.push(g!=null?String(g):"")}c[f]=y.join("")}else c[f]=b(p,t,r,n)}return c}let o={},a=null,l=!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 ")){l=!0;break}for(let c of e.properties)if(c.key.startsWith("$if ")||c.key.match(/^\$if\s+\w+.*:?$/)){let u=b(c.value,t,r,n);if(!l&&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(c.key.startsWith("$for ")){if(e.properties.length===1)return b(c.value,t,r,n)}else{let u=c.value;if(u&&u.type===d.OBJECT&&u.properties){let f=u.properties.find(p=>p.key.startsWith("$for "));if(f){let p=b(f.value,t,r,n);p!==void 0&&(o[c.key]=p)}else{let p=b(c.value,t,r,n);p!==void 0&&(o[c.key]=p)}}else{let f=c.parsedKey?b(c.parsedKey,t,r,n):c.key,p=b(c.value,t,r,n);p!==void 0&&(o[f]=p)}}return o},st={},Ir=(e,t,r,n)=>{let s=[];for(let i of e.items)if(i.type===d.LOOP){let o=b(i,t,r,n);Array.isArray(o)&&i.flatten!==!1?s.push(...o):s.push(o)}else{let o=b(i,t,r,n);o!==st&&o!==void 0&&s.push(o)}return s},vr=(e,t,r,n)=>{let{name:s,data:i,whenCondition:o}=e,a=t.partials||{},l=t.functions||t;if(o&&!G(o,l,r,n))return;if(!a[s])throw new L(`Partial '${s}' is not defined`);let c=n._partialStack||[];if(c.includes(s))throw new L(`Circular partial reference detected: ${s}`);let u=a[s],f=r,p={...n,_partialStack:[...c,s]};if(n){f={...r};for(let y of Object.keys(n))y.startsWith("_")||(f[y]=n[y])}if(i){let y=b(i,t,r,n);f={...f,...y}}return b(u,t,f,p)},_r=(e,t,r,n)=>{let{path:s}=e,i=s.split("."),o=i[0],a=i.slice(1);if(!n||!(o in n))throw new L(`Path reference '#{${s}}' refers to '${o}' which is not a loop variable in the current scope`);if(n.__paths__||(n.__paths__={}),!(o in n.__paths__))throw new L(`Path reference '#{${s}}' cannot be resolved - path tracking may not be initialized properly`);let l=n.__paths__[o];if(typeof l=="number"){if(a.length>0)throw new L(`Path reference '#{${s}}' - cannot access properties on index variable '${o}'`);return String(l)}return a.length>0&&(l+="."+a.join(".")),l},Oe=sr;var br=/\$\{([^}]*)\}/g,Ar=/#\{([^}]*)\}/g,ct=(e,t={})=>{let r=e.match(/^(\w+)\((.*)\)$/);if(!r)return{isFunction:!1};let[,n,s]=r,i=Er(s,t);return{isFunction:!0,type:d.FUNCTION,name:n,args:i}},Er=(e,t={})=>e.trim()?wr(e).map(n=>xr(n.trim(),t)):[],wr=e=>{let t=[],r="",n=0,s=!1,i="";for(let o=0;o<e.length;o++){let a=e[o],l=o>0?e[o-1]:"";!s&&(a==='"'||a==="'")?(s=!0,i=a,r+=a):s&&a===i&&l!=="\\"?(s=!1,i="",r+=a):!s&&a==="("?(n++,r+=a):!s&&a===")"?(n--,r+=a):!s&&a===","&&n===0?(t.push(r),r=""):r+=a}return r&&t.push(r),t},xr=(e,t={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:d.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:d.LITERAL,value:parseFloat(e)};if(e==="true")return{type:d.LITERAL,value:!0};if(e==="false")return{type:d.LITERAL,value:!1};if(e==="null")return{type:d.LITERAL,value:null};let r=ct(e,t);if(r.isFunction)return{type:r.type,name:r.name,args:r.args};let n=e.trim(),s=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],i=-1,o=null;for(let{op:a,type:l}of s){let c=0;for(;c<n.length;){let u=U(n.substring(c),a);if(u===-1)break;let f=c+u;f>i&&(i=f,o={op:a,type:l}),c=f+a.length}}if(i!==-1)try{return O(n,t)}catch{return{type:d.VARIABLE,path:n}}return{type:d.VARIABLE,path:n}},lt=/^\w+\(.*\)$/,$r=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,Pr=e=>{if(!(!e||e.trim()===""||lt.test(e))&&$r.test(e))throw e.includes("?")&&e.includes(":")?new _(`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 _(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new _(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},at=e=>{let t=e.trim();if(lt.test(t))throw new _(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("["))throw new _(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(t))throw new _(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(t))throw new _(`Logical operators not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("?")&&t.includes(":"))throw new _(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:d.PATH_REFERENCE,path:t}},ee=(e,t={})=>{let r=e.trim();Pr(r);let n=ct(r,t);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:d.VARIABLE,path:r}},Le=(e,t={})=>{let r=e,n=[];(e.includes("\\${")||e.includes("\\#{"))&&(r=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC_VAR$1"),r=r.replace(/\\\\(#\{[^}]*\})/g,"\\DOUBLE_ESC_PATH$1"),r=r.replace(/\\(\$\{[^}]*\})/g,(c,u)=>{let f=`__ESCAPED_${n.length}__`;return n.push(u),f}),r=r.replace(/\\(#\{[^}]*\})/g,(c,u)=>{let f=`__ESCAPED_${n.length}__`;return n.push(u),f}),r=r.replace(/\\DOUBLE_ESC_VAR/g,"\\"),r=r.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let s=[...r.matchAll(br)],i=[...r.matchAll(Ar)],o=[...s.map(c=>({match:c,type:"variable"})),...i.map(c=>({match:c,type:"pathref"}))].sort((c,u)=>c.match.index-u.match.index);if(o.length===0){let c=r;for(let u=0;u<n.length;u++)c=c.replace(`__ESCAPED_${u}__`,n[u]);return{type:d.LITERAL,value:c}}if(o.length===1&&o[0].match[0]===r&&n.length===0){let{match:c,type:u}=o[0];try{return u==="variable"?ee(c[1],t):at(c[1])}catch(f){if(f.message==="Invalid array index syntax")return{type:d.LITERAL,value:r};throw f}}let a=[],l=0;for(let{match:c,type:u}of o){let[f,p]=c,y=c.index;if(y>l){let h=r.substring(l,y);for(let g=0;g<n.length;g++)h=h.replace(`__ESCAPED_${g}__`,n[g]);h&&a.push(h)}try{let h;u==="variable"?h=ee(p.trim(),t):h=at(p.trim()),a.push(h)}catch(h){if(h.message==="Invalid array index syntax")a.push(f);else throw h}l=y+f.length}if(l<r.length){let c=r.substring(l);for(let u=0;u<n.length;u++)c=c.replace(`__ESCAPED_${u}__`,n[u]);c&&a.push(c)}return{type:d.INTERPOLATION,parts:a}};var V=(e,t)=>typeof e=="string"?Le(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?Or(e,t):Lr(e,t):{type:d.LITERAL,value:e},kr=e=>{let{$each:t,...r}=e;if(typeof t!="string")throw new _("$each value must be a non-empty string");let n=t.trim();if(n==="")throw new _("$each value must be a non-empty string");if(Object.keys(r).length===0)throw new _("Empty $each body not allowed");if(r.$partial!==void 0)throw new _("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${n}`]:r}},Or=(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)){if(i.$each!==void 0)try{let l=kr(i),c=Object.keys(l);if(c.length===1&&/^\$for(?::\w+)?\s/.test(c[0])){let u=ut(c[0],l[c[0]],t,!0);r.push(u),n=!0;continue}}catch(l){throw l instanceof _?l:new _(l.message)}let a=Object.keys(i);if(a.length===1&&/^\$for(?::\w+)?\s/.test(a[0])){let l=ut(a[0],i[a[0]],t);r.push(l),n=!0;continue}}let o=V(i,t);r.push(o),(o.type===d.FUNCTION||o.type===d.CONDITIONAL||o.type===d.LOOP||o.type===d.PARTIAL||o.type===d.OBJECT&&!o.fast||o.type===d.ARRAY&&!o.fast)&&(n=!0)}return{type:d.ARRAY,items:r,fast:!n}},Lr=(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 _("$partial value must be a string");if(e.$partial.trim()==="")throw new _("$partial value cannot be an empty string");let l=["$if","$elif","$else","$for"],c=[];for(let[m]of i)for(let v of l)if(m===v||m.startsWith(v+" ")||m.startsWith(v+"#")){c.push(v);break}if(c.length>0)throw new _(`Cannot use $partial with ${c.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:u,$when:f,...p}=e,y={},h=!1;for(let[m,v]of Object.entries(p)){let A=m;(m.startsWith("\\$")||m.startsWith("$$"))&&(A=m.slice(1)),y[A]=v,h=!0}let g=null;if(h&&(g=V(y,t),g.type===d.OBJECT)){let m=!1;for(let v of g.properties)if(v.value.type===d.VARIABLE||v.value.type===d.INTERPOLATION||v.value.type===d.FUNCTION||v.value.type===d.CONDITIONAL||v.value.type===d.OBJECT&&!v.value.fast||v.value.type===d.ARRAY&&!v.value.fast){m=!0;break}m&&(g.fast=!1)}let I={type:d.PARTIAL,name:u,data:g};if(f!==void 0){let m;if(typeof f=="string"){if(f.trim()==="")throw new _("Empty condition expression after '$when'");m=O(f,t)}else m={type:d.LITERAL,value:f};I.whenCondition=m}return I}for(let[l,c]of i)if(l==="$when"){if(s!==null)throw new _("Multiple '$when' directives on the same object are not allowed");if(c==null)throw new _("Missing condition expression after '$when'");let u=typeof c=="string"?c:JSON.stringify(c);if(u.trim()==="")throw new _("Empty condition expression after '$when'");s=O(u,t),n=!0}else if(l.startsWith("$when#")||l.startsWith("$when "))throw new _("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;o<i.length;){let[l,c]=i[o];if(l==="$when"){o++;continue}if(l==="$each")throw new _("$each can only be used inside arrays");if(l.startsWith("$if ")||l.match(/^\$if#\w+\s/)||l.match(/^\$if\s+\w+.*:$/)){let u=Cr(i,o,t);r.push({key:l,value:u.node}),n=!0,o=u.nextIndex}else if(/^\$for(?::\w+)?\s/.test(l)){let u=l.match(/^\$for(?::(\w+))?\s/)?.[1]||"",f=u?`:${u}`:"";throw new _(`$for loops must be inside arrays - use '- $for${f} item in items:' instead of '$for${f} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(l.startsWith("$elif ")||l.startsWith("$else"))throw new _(`'${l.split(" ")[0]}' without matching '$if'`);if(l==="$if"||l==="$if:")throw new _("Missing condition expression after '$if'");{let u=V(c,t);(u.type===d.FUNCTION||u.type===d.CONDITIONAL||u.type===d.PARTIAL||u.type===d.OBJECT&&!u.fast||u.type===d.ARRAY&&!u.fast)&&(n=!0);let f=Le(l,t),p={key:l,value:u};(f.type!==d.LITERAL||f.value!==l)&&(p.parsedKey=f),r.push(p),o++}}}let a={type:d.OBJECT,properties:r,fast:!n};return s&&(a.whenCondition=s),a},Cr=(e,t,r={})=>{let n=[],s=[],i=t,[o,a]=e[i],l=null,c;if(o.startsWith("$if#")){let f=o.match(/^\$if#(\w+)\s+(.+)$/);if(f)l=f[1],c=f[2];else throw new _(`Invalid conditional syntax: ${o}`)}else c=o.substring(4),c.endsWith(":")&&(c=c.slice(0,-1).trim());ke(c);let u=O(c,r);for(n.push(u),s.push(V(a,r)),i++;i<e.length;){let[f,p]=e[i],y=!1,h;if(l?f.startsWith(`$elif#${l} `)?(h=f.substring(`$elif#${l} `.length),h.endsWith(":")&&(h=h.slice(0,-1).trim()),y=!0):(f===`$else#${l}`||f===`$else#${l}:`)&&(y=!0,h=null):f.startsWith("$elif ")?(h=f.substring(6),h.endsWith(":")&&(h=h.slice(0,-1).trim()),y=!0):(f==="$else"||f==="$else:")&&(y=!0,h=null),y){if(h===null)n.push(null);else{ke(h);let g=O(h,r);n.push(g)}if(s.push(V(p,r)),i++,h===null)break}else break}return{node:{type:d.CONDITIONAL,conditions:n,bodies:s,id:l},nextIndex:i}},O=(e,t={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let c=e.slice(1,-1),u=0,f=!0;for(let p=0;p<c.length;p++)if(c[p]==="("?u++:c[p]===")"&&u--,u<0){f=!1;break}if(f&&u===0)return O(c,t)}let r=U(e,"||");if(r!==-1)return{type:d.BINARY,op:w.OR,left:O(e.substring(0,r).trim(),t),right:O(e.substring(r+2).trim(),t)};let n=U(e,"&&");if(n!==-1)return{type:d.BINARY,op:w.AND,left:O(e.substring(0,n).trim(),t),right:O(e.substring(n+2).trim(),t)};let s=[{op:">=",type:w.GTE},{op:"<=",type:w.LTE},{op:"==",type:w.EQ},{op:"!=",type:w.NEQ},{op:">",type:w.GT},{op:"<",type:w.LT},{op:" in ",type:w.IN}];for(let{op:c,type:u}of s){let f=U(e,c);if(f!==-1)return{type:d.BINARY,op:u,left:O(e.substring(0,f).trim(),t),right:O(e.substring(f+c.length).trim(),t)}}let i=-1,o=null,a=[{op:" + ",type:w.ADD},{op:" - ",type:w.SUBTRACT}];for(let{op:c,type:u}of a){let f=0;for(;f<e.length;){let p=U(e.substring(f),c);if(p===-1)break;let y=f+p;y>i&&(i=y,o={op:c,type:u}),f=y+c.length}}if(i!==-1&&o)return{type:d.BINARY,op:o.type,left:O(e.substring(0,i).trim(),t),right:O(e.substring(i+o.op.length).trim(),t)};let l=[" * "," / "," % "];for(let c of l)if(U(e,c)!==-1)throw new _(`Arithmetic operations are not allowed in conditionals: "${c}"`);return e.startsWith("!")?{type:d.UNARY,op:Z.NOT,operand:O(e.substring(1).trim(),t)}:ft(e,t)},U=(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},Rr=e=>{if(e=e.trim(),e==="true")return{type:d.LITERAL,value:!0};if(e==="false")return{type:d.LITERAL,value:!1};if(e==="null")return{type:d.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:d.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:d.LITERAL,value:""};if(e==="{}")return{type:d.LITERAL,value:{}};if(e==="[]")return{type:d.LITERAL,value:[]};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:d.LITERAL,value:t}:{type:d.VARIABLE,path:e}},ft=(e,t)=>{let r=e.trim();if(r.match(/^(\w+)\((.*)\)$/))return ee(r,t);let s=Rr(r);if(s.type===d.LITERAL)return s;if(/^[a-zA-Z_$][\w.$]*$/.test(r))return{type:d.VARIABLE,path:r};try{return ee(r,t)}catch(i){if(i.message&&i.message.includes("not supported"))return s;throw i}},Tr=(e,t=!1)=>{let r=t?"$each":"$for";try{Ze(e)}catch(n){if(n instanceof _&&t){let s=n.message.replace(/\$for/g,"$each");throw new _(s.replace("Parse Error: ",""))}throw n}},ut=(e,t,r,n=!1)=>{let s=/^\$for(?::(\w+))?\s+(.+)$/,i=e.match(s);if(!i){let I=n?"$each":"$for";throw new _(`Invalid loop syntax (got: '${e.replace("$for",I)}')`)}let o=i[1],a=i[2].trim();Tr(a,n);let l=a.match(/^(.+?)\s+in\s+(.+)$/);if(!l){let I=n?"$each":"$for";throw new _(`Invalid loop syntax - missing 'in' keyword (got: '${I} ${a}')`)}let c=l[1].trim(),u=l[2].trim(),f,p=null;if(c.includes(",")){let I=c.split(",").map(m=>m.trim());if(I.length!==2)throw new _(`Invalid loop variables: ${c}. Expected format: "item" or "item, index"`);f=I[0],p=I[1]}else f=c;let y=["this","undefined","null","true","false"];if(y.includes(f))throw new _(`Reserved variable name: ${f}`);if(p&&y.includes(p))throw new _(`Reserved variable name: ${p}`);let h=ft(u,r),g=V(t,r);return{type:d.LOOP,itemVar:f,indexVar:p,iterable:h,body:g,flatten:o!=="nested"}};var Sr=(e,t={})=>{let{functions:r={}}=t;return V(e,r)},pe=Sr;var Ce={};K(Ce,{now:()=>Nr});var Nr=()=>Date.now();var Dr=(e,t,r={})=>{let{functions:n={},partials:s={}}=r,i={...Ce,...n},o=pe(e,{functions:i}),a={};for(let[l,c]of Object.entries(s))a[l]=pe(c,{functions:i});return Oe(o,t,{functions:i,partials:a})},M=Dr;var Re={objectValues:e=>Object.entries(e).map(([t,r])=>({id:t,...r}))},Mr=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],transitions:[]}),dt=({elements:e},{presentationState:t,resources:r})=>{if(t.screen){let n=e.find(s=>s.id==="story");if(!n)return;if(t.screen.resourceId&&t.screen.resourceType==="layout"){let s=r.layouts[t.screen.resourceId];s&&n.children.unshift({id:"screen",type:"container",children:s.elements})}}},pt=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:s})=>{if(r.background){let i=e.find(o=>o.id==="story");if(!i)return;if(r.background.resourceId&&r.background.resourceType==="image"){let o=n.images[r.background.resourceId];i.children.push({id:`bg-cg-${r.background.resourceId}`,type:"sprite",x:0,y:0,url:s(o.fileId)})}if(r.background.resourceId&&r.background.resourceType==="layout"){let o=n.layouts[r.background.resourceId];i.children.push({id:`bg-cg-${r.background.resourceId}`,type:"container",children:o.elements})}if(r.background.animations){if(r.background.animations.in){let o=r.background.animations.in.animationId,a=n.animations[o];a&&t.push({id:"bg-cg-animation-in",type:"keyframes",event:"add",elementId:`bg-cg-${r.background.resourceId}`,properties:a.properties})}if(r.background.animations.out){let o=r.background.animations.out.animationId,a=r.background.animations.out.resourceId,l=n.animations[o];l&&t.push({id:"bg-cg-animation-out",type:"keyframes",event:"remove",elementId:`bg-cg-${a}`,properties:l.properties})}if(r.background.animations.update){let o=r.background.animations.update.animationId,a=n.animations[o];a&&t.push({id:"bg-cg-animation-update",type:"keyframes",event:"update",elementId:`bg-cg-${r.background.resourceId}`,properties:a.properties})}}}},ht=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:s})=>{if(r.character){let i=e.find(a=>a.id==="story");if(!i)return;let o=r.character.items||[];for(let a of o){let{transformId:l,sprites:c}=a;if(a.animations&&a.animations.out&&!c&&!l){let h=a.animations.out.animationId,g=n.animations[h];if(g){let I={id:"character-animation-out",type:"keyframes",event:"remove",elementId:`character-container-${a.id}`,properties:g.properties};t.push(I)}continue}if(!c||!l){console.warn("Character item missing sprites or transformId:",a);continue}let u=c.map(({imageId:h})=>h),f=n.transforms[l],p={type:"container",id:`character-container-${a.id}`,x:f.x,y:f.y,anchorX:f.anchorX,anchorY:f.anchorY,rotation:f.rotation,scaleX:f.scaleX,scaleY:f.scaleY,children:[]},y=[];Object.entries(n.characters).flatMap(([h,g])=>{let{sprites:I}=g;Object.entries(I).map(([m,v])=>{u.includes(m)&&y.push({partId:m,fileId:v.fileId})})});for(let h of y)p.children.push({type:"sprite",id:`${a.id}-${h.partId}`,url:s(h.fileId),x:0,y:0});if(i.children.push(p),a.animations){if(a.animations.in){let h=a.animations.in.animationId,g=n.animations[h];g&&t.push({id:"character-animation-in",type:"keyframes",event:"add",elementId:`character-container-${a.id}`,properties:g.properties})}if(a.animations.update){let h=a.animations.update.animationId,g=n.animations[h];if(g){let I={id:"character-animation-update",type:"keyframes",event:"update",elementId:`character-container-${a.id}`,properties:g.properties};t.push(I)}}}}}},yt=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:s})=>{if(r.visual){let i=e.find(a=>a.id==="story");if(!i)return;let o=r.visual.items;for(let a of o){if(a.resourceId&&a.resourceType){let l;if(a.resourceType==="image")l=n.images[a.resourceId];else continue;if(l){let c=n.transforms[a.transformId];i.children.push({id:`visual-${a.id}`,type:"sprite",url:s(l.fileId),x:c.x,y:c.y,anchorX:c.anchorX,anchorY:c.anchorY,rotation:c.rotation,scaleX:c.scaleX,scaleY:c.scaleY})}}if(a.animations){if(a.animations.in){let l=a.animations.in.animationId||a.animations.in,c=n.animations[l];c&&t.push({id:`${a.id}-animation`,type:"keyframes",event:"add",elementId:`visual-${a.id}`,properties:c.properties})}if(a.animations.out){let l=a.animations.out.animationId||a.animations.out,c=n.animations[l];c&&t.push({id:`${a.id}-animation-2`,type:"keyframes",event:"remove",elementId:`visual-${a.id}`,properties:c.properties})}}}}},mt=({elements:e},{presentationState:t,resources:r,systemState:n,systemStore:s})=>{if(!t.dialogue||n?.dialogueUIHidden)return;let i=e.find(p=>p.id==="story");if(!i)return;let o=r.layouts[t.dialogue.layoutId];if(!o)return;let a;t.dialogue.characterId&&(a=r.characters[t.dialogue.characterId]),t.dialogue.character&&(a={...a,name:t.dialogue.character.name});let l={elements:o.elements},c={variables:n?.variables||{},saveDataArray:s.selectSaveDataPage({page:n?.variables.currentSavePageIndex,numberPerPage:6}),autoMode:s.selectAutoMode(),skipMode:s.selectSkipMode(),dialogue:{character:{name:a?.name||""},content:t.dialogue?.content||[],lines:t.dialogue?.lines||[]},currentLanguagePackId:s.selectCurrentLanguagePackId(),i18n:s.selectCurrentLanguagePackKeys()},u=M(l,c,{functions:Re});u=M(u,{i18n:s.selectCurrentLanguagePackKeys()});let f=u?.elements;if(Array.isArray(f))for(let p of f)i.children.push(structuredClone(p));else f&&i.children.push(structuredClone(f))},gt=({elements:e},{presentationState:t,resources:r})=>{if(t.choice){let n=e.find(l=>l.id==="story");if(!n)return;let i={elements:r.layouts[t.choice.layoutId].elements},a=M(i,{choice:{items:t.choice.items}})?.elements;if(Array.isArray(a))for(let l of a)n.children.push(structuredClone(l));else a&&n.children.push(structuredClone(a))}},It=({elements:e},{presentationState:t,resources:r,resolveFile:n})=>{if(t.bgm){let s=e.find(o=>o.id==="story");if(!s)return;let i=r.audio[t.bgm.audioId];s.children.push({id:"bgm",type:"audio",url:n(i.fileId),loop:i.loop??!0,volume:i.volume??.5,delay:i.delay})}},vt=({elements:e},{presentationState:t,resources:r,resolveFile:n})=>{if(t.sfx){let s=e.find(o=>o.id==="story");if(!s)return;let i=t.sfx.items;for(let o of i){let a=r.audio[o.audioId];s.children.push({id:o.id,type:"audio",url:n(a.fileId),loop:o.loop??!1,volume:o.volume??.5,delay:o.delay})}}},_t=({elements:e},{presentationState:t,resolveFile:r})=>{if(!t.voice)return;let n=e.find(a=>a.id==="story");if(!n)return;let{fileId:s,volume:i,loop:o}=t.voice;n.children.push({id:`voice-${s}`,type:"audio",url:r(s),volume:i,loop:o})},bt=({elements:e,transitions:t},{presentationState:r,resources:n,resolveFile:s,systemState:i,systemStore:o})=>{if(r.layout){let a=e.find(h=>h.id==="story");if(!a)return;let l=n.layouts[r.layout.layoutId];if(!l)return;Array.isArray(l.transitions)&&l.transitions.forEach(h=>{t.push(h)});let c=h=>{let g={...h};if(h.url&&h.url.startsWith("file:")){let I=h.url.replace("file:","");g.url=s(I)}return h.children&&Array.isArray(h.children)&&(g.children=h.children.map(c)),g},u={id:`layout-${r.layout.layoutId}`,type:"container",x:0,y:0,children:l.elements||[]},f={variables:i?.variables||{},saveDataArray:o.selectSaveDataPage({page:i?.variables.currentSavePageIndex,numberPerPage:6}),autoMode:o.selectAutoMode(),skipMode:o.selectSkipMode(),globalAudios:o.selectGlobalAudios()||[],currentLanguagePackId:o.selectCurrentLanguagePackId(),i18n:o.selectCurrentLanguagePackKeys(),languagePacks:o.selectLanguagePacks()},p=M(u,f,{functions:Re});p=M(p,{i18n:o.selectCurrentLanguagePackKeys()});let y=h=>{let g={...h};if(h.url&&h.url.startsWith("file:")){let I=h.url.replace("file:","");g.url=s(I)}return h.children&&Array.isArray(h.children)&&(g.children=h.children.map(y)),g};a.children.push(y(p))}},At=({elements:e,transitions:t},{systemState:r,resources:n,resolveFile:s,systemStore:i})=>{let o=r.modes[r.currentMode].modals;o&&o.length>0&&o.forEach((a,l)=>{if(a.resourceType==="layout"){let c=n.layouts[a.resourceId];if(!c){console.warn(`Modal layout not found: ${a.resourceId}`);return}Array.isArray(c.transitions)&&c.transitions.forEach(m=>{t.push(m)});let u=m=>{let v={...m};if(m.url&&m.url.startsWith("file:")){let A=m.url.replace("file:","");v.url=s(A)}return m.children&&Array.isArray(m.children)&&(v.children=m.children.map(u)),v},f={id:`modal-${l}`,type:"container",x:0,y:0,children:c.elements||[]},p,y=!1;if(r.variables.activeGalleryIndex!==void 0){let m=r.variables.gallery.items;m&&Array.isArray(m)&&r.variables.activeGalleryIndex<m.length&&(p=m[r.variables.activeGalleryIndex]?.fileIds[r.variables.activeGalleryFileIndex]),r.variables.activeGalleryFileIndex<m[r.variables.activeGalleryIndex]?.fileIds.length-1?y=!1:y=!0}let h={variables:r.variables||{},currentActiveGalleryFileId:p,isLastFileIdIndex:y,saveDataArray:i.selectSaveDataPage({page:r?.variables.currentSavePageIndex,numberPerPage:6}),autoMode:i.selectAutoMode(),skipMode:i.selectSkipMode(),globalAudios:i.selectGlobalAudios()||[],historyDialogue:i.selectHistoryDialogue()||[],currentLanguagePackId:i.selectCurrentLanguagePackId(),i18n:i.selectCurrentLanguagePackKeys(),languagePacks:i.selectLanguagePacks()},g=M(f,h,{functions:Re});g=M(g,{i18n:i.selectCurrentLanguagePackKeys()});let I=m=>{let v={...m};if(m.url&&m.url.startsWith("file:")){let A=m.url.replace("file:","");v.url=s(A)}return m.children&&Array.isArray(m.children)&&(v.children=m.children.map(I)),v};e.push(I(g))}})},Et=({elements:e},{systemState:t,resources:r,resolveFile:n})=>{let s=t.globalAudios;s&&s.length>0&&s.forEach((i,o)=>{e.push({id:`global-audio-${o}-${i.audioId}`,type:"audio",url:n(i.fileId)})})},Te=[dt,pt,ht,yt,mt,gt,bt,It,vt,_t,At,Et];var te={};K(te,{animation:()=>Ct,background:()=>xt,bgm:()=>Pt,character:()=>Lt,choice:()=>Tt,cleanAll:()=>Nt,createInitialState:()=>Vr,default:()=>Ne,dialogue:()=>Ot,layout:()=>Rt,screen:()=>wt,sfx:()=>$t,visual:()=>kt,voice:()=>St});var wt=(e,t)=>{t.screen&&(e.screen={...t.screen})},xt=(e,t)=>{t.background&&(e.background={...t.background})},$t=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},Pt=(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}}},kt=(e,t)=>{t.visual&&(e.visual=t.visual)},Ot=(e,t)=>{if(!t.dialogue){e.dialogue&&e.dialogue.mode==="adv"&&(e.dialogue.content=void 0,e.dialogue.characterId=void 0);return}if(e.dialogue||(t.dialogue.mode==="adv"&&(e.dialogue={layoutId:t.dialogue.layoutId,content:void 0,characterId:void 0,mode:"adv"}),t.dialogue.mode==="nvl"&&e.dialogue?.mode!=="nvl"&&(e.dialogue={layoutId:t.dialogue.layoutId,lines:[],mode:"nvl"})),e.dialogue?.mode==="adv"&&(e.dialogue.content=t.dialogue.content,e.dialogue.characterId=t.dialogue.characterId,t.dialogue.layoutId&&(e.dialogue.layoutId=t.dialogue.layoutId),t.dialogue.clear&&delete e.dialogue),t.dialogue?.mode==="nvl"){t.dialogue.clear&&(e.dialogue.lines=[]),e.dialogue.lines.push({content:t.dialogue.content});return}},Lt=(e,t)=>{t.character&&(t.character.items||delete e.character,e.character=structuredClone(t.character))},Ct=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},Rt=(e,t)=>{t.layout?e.layout=t.layout:e.layout&&delete e.layout},Tt=(e,t)=>{t.choice?e.choice=t.choice:e.choice&&delete e.choice},St=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},Nt=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(r=>{delete e[r]})},Vr=()=>({}),Ne=[Nt,wt,xt,$t,Pt,kt,Ot,Lt,Ct,Rt,Tt,St];var ie={};K(ie,{addGlobalAudio:()=>An,addModal:()=>wn,clearAllGlobalAudio:()=>En,clearCurrentMode:()=>dn,clearLastModal:()=>xn,clearPendingEffects:()=>sn,createInitialState:()=>Br,handleCompleted:()=>Pn,lineCompleted:()=>an,loadVnData:()=>_n,nextConfig:()=>mn,nextLine:()=>cn,prevLine:()=>ln,render:()=>bn,saveVnData:()=>vn,sectionTransition:()=>un,selectAutoMode:()=>ne,selectCurrentLanguagePackId:()=>Zr,selectCurrentLanguagePackKeys:()=>tn,selectCurrentPointer:()=>De,selectCurrentPreset:()=>zr,selectCurrentPresetId:()=>Ur,selectCurrentReplayPointer:()=>Hr,selectDeviceVariables:()=>rn,selectDialogueUIHidden:()=>Yr,selectGlobalAudios:()=>qr,selectHistory:()=>Mt,selectHistoryDialogue:()=>nn,selectLanguagePacks:()=>en,selectModals:()=>on,selectNextConfig:()=>he,selectPendingEffects:()=>Wr,selectPointerMode:()=>Dt,selectPointers:()=>Kr,selectReplayPointer:()=>Gr,selectRuntimeState:()=>Jr,selectSaveData:()=>Bt,selectSaveDataPage:()=>Xr,selectSkipMode:()=>re,selectSortedPendingEffects:()=>jr,selectSpecificPointer:()=>Vt,selectState:()=>Fr,selectVariables:()=>Qr,setDeviceVariables:()=>In,setLanguagePackId:()=>$n,setSaveData:()=>gn,startAutoMode:()=>Ft,startSkipMode:()=>jt,stopAutoMode:()=>Wt,stopSkipMode:()=>Ut,toggleAutoMode:()=>pn,toggleDialogueUIHidden:()=>yn,toggleSkipMode:()=>hn,updateVariable:()=>fn});var Br=({sectionId:e,lineId:t,saveData:r,variables:n,projectDataStore:s})=>{let i=s.selectI18n(),o={pendingEffects:[],variables:n,saveData:r||{},lastLineAction:void 0,dialogueUIHidden:!1,autoMode:!1,skipMode:!1,currentLanguagePackId:i?.defaultPackId,history:{entries:[]},globalAudios:[],historyEntryIndex:void 0,currentMode:"main",nextConfig:{},modes:{main:{currentPointer:"read",modals:[],read:{sectionId:e,lineId:t},history:{sectionId:void 0,lineId:void 0,historyEntryIndex:void 0}},replay:{currentPointer:"read",modals:[],read:{sectionId:void 0,lineId:void 0},history:{sectionId:void 0,lineId:void 0,historyEntryIndex:void 0}}}};return o.history.entries.push({sectionId:e}),o},Fr=({state:e})=>e,Wr=({state:e})=>e.pendingEffects,jr=({state:e})=>{let t=e.pendingEffects,r=new Map;return t.forEach(n=>{r.set(n.name,n)}),Array.from(r.values())},De=({state:e})=>{let t=e.modes[e.currentMode];return t[t.currentPointer]},Ur=({state:e})=>null,zr=({state:e,projectDataStore:t})=>null,re=({state:e})=>e.skipMode,ne=({state:e})=>e.autoMode,Kr=({state:e})=>e.modes[e.currentMode],he=({state:e})=>e.nextConfig,Jr=({state:e})=>e.runtimeState,Dt=({state:e})=>e.modes[e.currentMode].currentPointer,Yr=({state:e})=>e.dialogueUIHidden,Mt=({state:e})=>e.history,Vt=({state:e,mode:t})=>e.modes[e.currentMode][t],Gr=({state:e,mode:t})=>e.modes.replay[t],Hr=({state:e})=>{let t=e.modes.replay;return t[t.currentPointer]},Bt=({state:e})=>e.saveData,Xr=({state:e},t)=>{let{page:r,numberPerPage:n}=t,s=r*n,i=[];for(let o=s;o<s+n;o++){let a=e.saveData[o]?{id:o,label:new Date(e.saveData[o].date).toISOString().split("T")[0],hasData:!0}:{id:o,label:"No Data",hasData:!1};i.push(a)}return i},Qr=({state:e})=>e.variables,qr=({state:e})=>e.globalAudios,Zr=({state:e})=>e.currentLanguagePackId,en=({projectDataStore:e})=>e.selectI18n()?.packs,tn=({state:e,projectDataStore:t})=>{let r=t.selectI18n(),n=e.currentLanguagePackId;if(r?.packs)return r?.packs[n].keys},rn=({state:e,projectDataStore:t})=>{let r=t.selectVariables(),n=e.variables,s={};return Object.entries(r).forEach(([i,o])=>{o.persistence==="device"&&n.hasOwnProperty(i)&&(s[i]=n[i])}),s},nn=({state:e,projectDataStore:t})=>{let r=De({state:e}),{sectionId:n,lineId:s}=r;if(!n||!s)return[];let i=t.selectSectionLines(n),o=i.findIndex(c=>c.id===s);if(o===-1)return[];let a=i.slice(0,o+1),l=[];return a.forEach((c,u)=>{c.actions?.dialogue?.content&&Array.isArray(c.actions.dialogue.content)&&c.actions.dialogue.content.forEach(f=>{l.push({content:f.text})})}),l},on=({state:e})=>e.modes[e.currentMode].modals,sn=({state:e})=>{e.pendingEffects=[]},an=({state:e,projectDataStore:t})=>{let r=ne(e),{pendingEffects:n}=e;if(r){n.push({name:"systemInstructions",options:{delay:1e3,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}if(re(e)){n.push({name:"systemInstructions",options:{delay:300,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});return}let i=he(e);if(!i||!i.auto)return;let{trigger:o,delay:a}=i.auto;switch(o){case"fromComplete":n.push({name:"systemInstructions",options:{delay:a,systemInstructions:{nextLine:{forceSkipAutonext:!0}}}});break;case"fromStart":delete e.nextConfig;break;default:delete e.nextConfig;break}},cn=({state:e,projectDataStore:t},r={})=>{let{pendingEffects:n}=e;if(e.dialogueUIHidden){e.dialogueUIHidden=!1,n.push({name:"render"});return}let{forceSkipAutonext:s=!1,targetMode:i}=r,o=i||e.currentMode,a=he({state:e});if(!s&&a&&a.manual&&(!a.manual.enabled||a.manual.requireComplete&&!e.lineComplete))return;let l=e.modes[o],c=l[l.currentPointer],u=t.selectSectionLines(c.sectionId),f=u.findIndex(y=>y.id===c.lineId),p=u[f+1];if(!p){e.skipMode=!1,e.autoMode=!1,n.push({name:"clearAutoNextTimer"}),n.push({name:"clearSkipNextTimer"});return}l[l.currentPointer].lineId=p.id,delete e.nextConfig,n.push({name:"render"})},ln=({state:e,projectDataStore:t})=>{let r=Dt({state:e}),n=De({state:e}),s=t.selectSectionLines(n.sectionId),i=s.findIndex(a=>a.id===n.lineId),o=s[i-1];if(!o){if(r==="history"){if(e.historyEntryIndex>0)e.historyEntryIndex--;else return;e.modes[e.currentMode].history.sectionId=e.history.entries[e.historyEntryIndex].sectionId;let a=t.selectSectionLines(e.modes[e.currentMode].history.sectionId);e.modes[e.currentMode].history.lineId=a[a.length-1].id,e.lastLineAction="prevLine",e.pendingEffects.push({name:"render"})}return}r==="read"&&(e.modes[e.currentMode].currentPointer="history",e.historyEntryIndex=e.history.entries.length-1),e.modes[e.currentMode].history.lineId=o.id,e.modes[e.currentMode].history.sectionId=n.sectionId,e.lastLineAction="prevLine",e.pendingEffects.push({name:"render"})},un=({state:e,projectDataStore:t},r)=>{let{sectionId:n,sceneId:s,mode:i,targetMode:o,endReplay:a}=r;if(e.currentMode==="replay"&&a){e.currentMode="main",e.modes.replay.currentPointer="read",e.modes.replay.modals=[],e.modes.replay.read={sectionId:void 0,lineId:void 0},e.modes.replay.history={sectionId:void 0,lineId:void 0,historyEntryIndex:void 0},e.pendingEffects.push({name:"render"});return}let l=t.selectSectionLines(n),c=o||(i&&e.modes[i]?i:e.currentMode);i&&e.modes[i]&&i!==e.currentMode&&!o&&(e.modes[i].modals=[]),o&&o!==e.currentMode?e.currentMode=o:i&&e.modes[i]&&i!==e.currentMode&&(e.currentMode=i),i&&!e.modes[i]&&(e.modes[c].currentPointer=i);let u=e.modes[c].currentPointer;u==="read"&&c===e.currentMode?e.history.entries.push({sectionId:n}):u==="history"&&n===e.history.entries[e.historyEntryIndex+1].sectionId&&e.historyEntryIndex++,e.modes[c][u].sectionId=n,e.modes[c][u].sceneId=s,e.modes[c][u].lineId=l[0].id,c===e.currentMode&&(e.nextConfig=l[0].actions?.nextConfig),e.pendingEffects.push({name:"render"})},fn=({state:e,projectDataStore:t},r)=>{let{operations:n}=r;for(let s of n){let{variableId:i,op:o,value:a}=s;if(o==="set")e.variables[i]=a;else if(o==="add")e.variables[i]=(e.variables[i]||0)+a;else if(o==="subtract")e.variables[i]=(e.variables[i]||0)-a;else if(o==="multiply")e.variables[i]=(e.variables[i]||0)*a;else if(o==="divide")e.variables[i]=(e.variables[i]||0)/a;else if(o==="increment"){let{max:l}=s,c=(e.variables[i]||0)+1;(l===void 0||c<=l)&&(e.variables[i]=(e.variables[i]||0)+1)}else if(o==="decrement"){let{min:l}=s,c=(e.variables[i]||0)-1;l!==void 0&&c>=l&&(e.variables[i]=(e.variables[i]||0)-1)}}e.pendingEffects.push({name:"render"}),e.pendingEffects.push({name:"saveVariables"})},dn=({state:e},t)=>{e.modes[e.currentMode].currentPointer=t.mode,e.pendingEffects.push({name:"render"})},Ft=({state:e})=>{re({state:e})&&(e.skipMode=!1,e.pendingEffects.push({name:"clearSkipNextTimer"})),e.autoMode=!0,e.pendingEffects.push({name:"clearAutoNextTimer"}),e.pendingEffects.push({name:"startAutoNextTimer"}),e.pendingEffects.push({name:"render"})},Wt=({state:e})=>{e.autoMode=!1,e.pendingEffects.push({name:"render"}),e.pendingEffects.push({name:"clearAutoNextTimer"})},pn=({state:e})=>{ne({state:e})?Wt({state:e}):Ft({state:e})},jt=({state:e})=>{ne({state:e})&&(e.autoMode=!1,e.pendingEffects.push({name:"clearAutoNextTimer"})),e.skipMode=!0,e.pendingEffects.push({name:"clearSkipNextTimer"}),e.pendingEffects.push({name:"startSkipNextTimer"}),e.pendingEffects.push({name:"render"})},Ut=({state:e})=>{e.skipMode=!1,e.pendingEffects.push({name:"clearSkipNextTimer"}),e.pendingEffects.push({name:"render"})},hn=({state:e})=>{re({state:e})?Ut({state:e}):jt({state:e})},yn=({state:e})=>{e.dialogueUIHidden=!e.dialogueUIHidden,e.pendingEffects.push({name:"render"})},mn=({state:e},t)=>{e.nextConfig=t},gn=({state:e},t)=>{let{saveData:r}=t;e.saveData=r},In=({state:e},t)=>{let{variables:r}=t;Object.entries(r).forEach(([n,s])=>{e.variables[n]=s})},vn=({state:e},t)=>{let{slotIndex:r}=t;e.saveData[r]={id:String(r),pointer:Vt({state:e,mode:"read"}),history:Mt({state:e}),date:Date.now()},e.pendingEffects.push({name:"saveVnData",options:{saveData:{...e.saveData},slotIndex:r}})},_n=({state:e},t)=>{let{slotIndex:r}=t,s=Bt({state:e})[r];if(!s){console.warn(`No save data found for slot index ${r}`);return}let{pointer:i,history:o}=s;e.modes[e.currentMode].currentPointer="read",e.modes[e.currentMode].read=i,e.history=o,e.modes[e.currentMode].modals=[],e.pendingEffects.push({name:"render"})},bn=({state:e})=>{e.pendingEffects.push({name:"render"})},An=({state:e},t)=>{let{fileId:r}=t;e.globalAudios.push({fileId:r}),e.pendingEffects.push({name:"render"})},En=({state:e})=>{e.globalAudios=[],e.pendingEffects.push({name:"render"})},wn=({state:e},t)=>{let r=e.currentMode;e.modes[r].modals.push({resourceId:t.resourceId,resourceType:"layout"}),e.pendingEffects.push({name:"render"})},xn=({state:e},t)=>{let r=e.modes[e.currentMode].modals;r.length>0&&(r.pop(),e.pendingEffects.push({name:"render"}))},$n=({state:e},t)=>{let{languagePackId:r}=t;e.currentLanguagePackId=r,e.pendingEffects.push({name:"render"})},Pn=({state:e})=>{let t=he({state:e});if(t){t.auto&&t.auto.trigger==="fromComplete"&&e.pendingEffects.push({name:"startTimer",options:{timerId:"nextConfig",payload:{nextLine:{forceSkipAutonext:!0}},delay:t.auto.delay??1e3}});return}ne({state:e})?e.pendingEffects.push({name:"startTimer",options:{timerId:"autoMode",payload:{nextLine:{forceSkipAutonext:!0}},delay:1e3}}):re({state:e})&&e.pendingEffects.push({name:"startTimer",options:{timerId:"skipMode",payload:{nextLine:{forceSkipAutonext:!0}},delay:300}})};var Me={};K(Me,{createInitialState:()=>Nn,selectI18n:()=>Rn,selectInitialIds:()=>zt,selectLayout:()=>Cn,selectResources:()=>On,selectScreen:()=>kn,selectSectionLines:()=>Sn,selectUi:()=>Ln,selectVariables:()=>Tn});var kn=e=>e.screen,On=e=>e.resources,Ln=e=>e.ui,Cn=e=>e.layout,Rn=e=>e.i18n,zt=e=>{let t=e.story.scenes[e.story.initialSceneId],r=t.sections[t.initialSectionId];return{sceneId:e.story.initialSceneId,sectionId:t.initialSectionId,lineId:r.lines[0].id}},Tn=e=>e.resources.variables||{},Sn=(e,t,r)=>{let s=Object.values(e.story.scenes).flatMap(i=>Object.entries(i.sections).map(([o,a])=>({...a,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},Nn=e=>{let t=zt(e),{sectionId:r,lineId:n}=t;if(!r||!n)throw new Error("No initial sectionId found");return e};var{createInitialState:Dn}=te,{createInitialState:Mn}=Se,{createInitialState:Vn,...Bn}=ie,{createInitialState:Ri,...Fn}=Me,Kt=e=>$e(e,Fn),Jt=(e,t)=>{let r=t.selectVariables(),n={};return Object.entries(r).forEach(([s,i])=>{i.hasOwnProperty("default")&&(n[s]=i.default)}),$e(Vn({sectionId:e.sectionId,lineId:e.lineId,saveData:{},variables:n,projectDataStore:t}),Bn,{transformActionFirstArgument:s=>({state:s,projectDataStore:t}),transformSelectorFirstArgument:s=>({state:s,projectDataStore:t})})},Ve=Pe(Dn,Ne),Be=Pe(Mn,Te);var Wn=e=>{let t=new Map,r=new Set,n=(i,o)=>{let a={eventType:i,payload:o,timestamp:performance.now()};r.forEach(l=>l(a))},s=i=>{let o=i.deltaMS;t.forEach((a,l)=>{if(!a.paused&&(a.elapsed+=o,a.elapsed>=a.delay)){let c={id:l,elapsed:a.elapsed,delay:a.delay,type:a.type,triggerCount:a.triggerCount+1,overshoot:a.elapsed-a.delay,payload:a.payload};n(l,c),a.triggerCount++,a.type==="timeout"?t.delete(l):a.type==="interval"&&(a.elapsed=a.elapsed-a.delay)}})};return e.add(s),{setTimeout:(i,o,a)=>(t.has(i)&&console.warn(`Timer '${i}' already exists, replacing it`),t.set(i,{type:"timeout",delay:a,payload:o,elapsed:0,triggerCount:0,paused:!1}),i),setInterval:(i,o,a)=>(t.has(i)&&console.warn(`Timer '${i}' already exists, replacing it`),t.set(i,{type:"interval",delay:a,payload:o,elapsed:0,triggerCount:0,paused:!1}),i),clear:i=>{t.delete(i)},pause:i=>{let o=t.get(i);o&&(o.paused=!0)},resume:i=>{let o=t.get(i);o&&o.paused&&(o.paused=!1)},pauseAll:()=>{t.forEach((i,o)=>{i.paused=!0})},resumeAll:()=>{t.forEach((i,o)=>{i.paused=!1})},clearAll:()=>{t.clear()},onEvent:i=>(r.add(i),()=>r.delete(i)),getTimer:i=>{let o=t.get(i);return o?{id:i,...o}:null},getActiveTimers:()=>Array.from(t.keys()),destroy:()=>{t.clear(),r.clear(),e.remove(s)}}},Yt=Wn;var Fe={};K(Fe,{clearAutoNextTimer:()=>Jn,clearSkipNextTimer:()=>Gn,render:()=>jn,saveVariables:()=>zn,saveVnData:()=>Un,startAutoNextTimer:()=>Kn,startSkipNextTimer:()=>Yn,startTimer:()=>Hn});var jn=({processAndRender:e})=>{e()},Un=async({timer:e,localStorage:t,captureElement:r,loadAssets:n},s)=>{let{saveData:i,slotIndex:o}=s.options,a=structuredClone(i),l=await r("story");console.log("saveData",a),console.log("slotindex",o),a[o].image=l;let c={[`saveImage:${o}`]:{buffer:de(l),type:"image/png"}};await n(c),t.setItem("saveData",JSON.stringify(a)),e.setTimeout("saveData",{render:{}},100)},zn=({localStorage:e,systemStore:t})=>{let r=t.selectDeviceVariables();e.setItem("deviceVariables",JSON.stringify(r))},Kn=({timer:e})=>{e.setTimeout("autoMode",{nextLine:{forceSkipAutonext:!0}},1e3)},Jn=({timer:e})=>{e.clear("autoMode")},Yn=({timer:e})=>{e.setTimeout("skipMode",{nextLine:{forceSkipAutonext:!0}},300)},Gn=({timer:e})=>{e.clear("skipMode")},Hn=({timer:e},t)=>{let{timerId:r,payload:n,delay:s}=t.options;e.setTimeout(r,n,s)};var Gt=Object.keys(te).filter(e=>e!=="default"&&e!=="createInitialState"),Xn=Object.keys(ie).filter(e=>!e.startsWith("select")&&e!=="createInitialState");function We(){let e,t,r,n,s,i=()=>{},o,a,l=({projectData:I,ticker:m,captureElement:v,loadAssets:A})=>{e=Kt(I);let E=e.selectInitialIds();t=Jt(E,e),n=Ve,r=Be,o=v,a=A,s=Yt(m),s.onEvent(c);let x=localStorage.getItem("saveData")||"{}",N=JSON.parse(x),H=Object.entries(N).filter(([k,$])=>!!$.image).map(([k,$])=>{let z=`saveImage:${k}`,X=de($.image);return{[z]:{buffer:X,type:"image/png"}}}).reduce((k,$)=>({...k,...$}),{});A(H).then(()=>{console.log("All save images loaded")}).catch(k=>{console.log("Error loading save images",k)}),t.setSaveData({saveData:N});let B=e.selectVariables(),C={};Object.entries(B).forEach(([k,$])=>{$.persistence==="device"&&$.hasOwnProperty("default")&&(C[k]=$.default)});let D=localStorage.getItem("deviceVariables");if(D)try{let k=JSON.parse(D);Object.entries(k).forEach(([$,z])=>{B[$]&&B[$].persistence==="device"&&(C[$]=z)})}catch(k){console.error("Failed to load device variables:",k)}Object.keys(C).length>0&&(t.setDeviceVariables({variables:C}),localStorage.setItem("deviceVariables",JSON.stringify(C))),y()},c=({eventType:I,payload:m})=>{Object.keys(m.payload).forEach(v=>{if(typeof t[v]=="function")t[v](m.payload[v]);else throw new Error(`System action ${v} not found on system store`)}),y()},u=I=>{i=I},f=()=>{i=()=>{}},p=I=>{let{payload:m}=I,v=m.actions;Object.keys(v).forEach(E=>{if(typeof t[E]=="function"){let x=v[E];E==="nextLine"&&!x.targetMode&&t.selectState().modes.replay.read.sectionId&&(x={...x,targetMode:"replay"}),t[E](x)}else throw new Error(`System action ${E} not found on system store`)});let A=t.selectSortedPendingEffects();if(A.length>0){let E={processAndRender:y,timer:s,localStorage,systemStore:t,captureElement:o,loadAssets:a};A.forEach(x=>{let N=Fe[x.name];if(!N)throw new Error(`No handler found for effect: ${x.name}`);N(E,x)}),t.clearPendingEffects()}},y=()=>{h(),g()},h=()=>{let I=t.selectCurrentPointer(),m=e.selectSectionLines(I.sectionId,I.lineId);m.length&&m.forEach(v=>{let A=v.actions||{};Xn.filter(x=>x in A).forEach(x=>{t[x](A[x])})})},g=()=>{let I=t.selectCurrentPointer(),m=e.selectSectionLines(I.sectionId,I.lineId);if(!m.length)throw new Error(`No lines found for section: ${I.sectionId}, line: ${I.lineId}`);let v=m.map(C=>{let D=C.actions||{},k={};return Object.keys(D).forEach($=>{Gt.includes($)&&(k[$]=D[$])}),k}),A=n(v),E=null,x=t.selectCurrentReplayPointer();if(x&&x.sectionId&&x.lineId){let C=e.selectSectionLines(x.sectionId,x.lineId);if(C.length){let D=C.map(k=>{let $=k.actions||{},z={};return Object.keys($).forEach(X=>{Gt.includes(X)&&(z[X]=$[X])}),z});E=n(D)}}let N=t.selectState(),H=r({presentationState:A,systemState:N,systemStore:t,screen:e.selectScreen(),resolveFile:C=>`file:${C}`,resources:e.selectResources(),ui:e.selectUi(),i18n:e.selectI18n()}),B=null;if(E){let C=structuredClone(N);B=r({presentationState:E,systemState:C,systemStore:t,screen:e.selectScreen(),resolveFile:D=>`file:${D}`,resources:e.selectResources(),ui:e.selectUi(),i18n:e.selectI18n()})}console.log({systemState:N,mainPresentationState:A,mainRenderState:H,replayPresentationState:E,replayRenderState:B}),i({eventType:"render",payload:B||H})};return{init:l,onEvent:u,offEvent:f,handleEvent:p}}var ji=We;export{Ve as constructPresentationState,Be as constructRenderState,ji as default};
|
|
1
|
+
var nt=Object.defineProperty;var rt=(e,t)=>{for(var n in t)nt(e,n,{get:t[n],enumerable:!0})};var ve=Symbol.for("immer-nothing"),Ie=Symbol.for("immer-draftable"),L=Symbol.for("immer-state");function O(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var V=Object.getPrototypeOf;function M(e){return!!e&&!!e[L]}function S(e){return e?xe(e)||Array.isArray(e)||!!e[Ie]||!!e.constructor?.[Ie]||X(e)||q(e):!1}var it=Object.prototype.constructor.toString();function xe(e){if(!e||typeof e!="object")return!1;let t=V(e);if(t===null)return!0;let n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return n===Object?!0:typeof n=="function"&&Function.toString.call(n)===it}function Y(e,t){G(e)===0?Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function G(e){let t=e[L];return t?t.type_:Array.isArray(e)?1:X(e)?2:q(e)?3:0}function ie(e,t){return G(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function $e(e,t,n){let r=G(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function ot(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function X(e){return e instanceof Map}function q(e){return e instanceof Set}function P(e){return e.copy_||e.base_}function oe(e,t){if(X(e))return new Map(e);if(q(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=xe(e);if(t===!0||t==="class_only"&&!n){let r=Object.getOwnPropertyDescriptors(e);delete r[L];let i=Reflect.ownKeys(r);for(let s=0;s<i.length;s++){let c=i[s],l=r[c];l.writable===!1&&(l.writable=!0,l.configurable=!0),(l.get||l.set)&&(r[c]={configurable:!0,writable:!0,enumerable:l.enumerable,value:e[c]})}return Object.create(V(e),r)}else{let r=V(e);if(r!==null&&n)return{...e};let i=Object.create(r);return Object.assign(i,e)}}function ue(e,t=!1){return Q(e)||M(e)||!S(e)||(G(e)>1&&(e.set=e.add=e.clear=e.delete=st),Object.freeze(e),t&&Object.entries(e).forEach(([n,r])=>ue(r,!0))),e}function st(){O(2)}function Q(e){return Object.isFrozen(e)}var at={};function D(e){let t=at[e];return t||O(0,e),t}var W;function Le(){return W}function ct(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ae(e,t){t&&(D("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function se(e){ae(e),e.drafts_.forEach(lt),e.drafts_=null}function ae(e){e===W&&(W=e.parent_)}function be(e){return W=ct(W,e)}function lt(e){let t=e[L];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function we(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];return e!==void 0&&e!==n?(n[L].modified_&&(se(t),O(4)),S(e)&&(e=J(t,e),t.parent_||H(t,e)),t.patches_&&D("Patches").generateReplacementPatches_(n[L].base_,e,t.patches_,t.inversePatches_)):e=J(t,n,[]),se(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==ve?e:void 0}function J(e,t,n){if(Q(t))return t;let r=t[L];if(!r)return Y(t,(i,s)=>Ee(e,r,t,i,s,n)),t;if(r.scope_!==e)return t;if(!r.modified_)return H(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;let i=r.copy_,s=i,c=!1;r.type_===3&&(s=new Set(i),i.clear(),c=!0),Y(s,(l,a)=>Ee(e,r,i,l,a,n,c)),H(e,i,!1),n&&e.patches_&&D("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function Ee(e,t,n,r,i,s,c){if(M(i)){let l=s&&t&&t.type_!==3&&!ie(t.assigned_,r)?s.concat(r):void 0,a=J(e,i,l);if($e(n,r,a),M(a))e.canAutoFreeze_=!1;else return}else c&&n.add(i);if(S(i)&&!Q(i)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;J(e,i),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&Object.prototype.propertyIsEnumerable.call(n,r)&&H(e,i)}}function H(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&ue(t,n)}function ut(e,t){let n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:Le(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},i=r,s=fe;n&&(i=[r],s=z);let{revoke:c,proxy:l}=Proxy.revocable(i,s);return r.draft_=l,r.revoke_=c,l}var fe={get(e,t){if(t===L)return e;let n=P(e);if(!ie(n,t))return ft(e,n,t);let r=n[t];return e.finalized_||!S(r)?r:r===ne(e.base_,t)?(re(e),e.copy_[t]=le(r,e)):r},has(e,t){return t in P(e)},ownKeys(e){return Reflect.ownKeys(P(e))},set(e,t,n){let r=Re(P(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let i=ne(P(e),t),s=i?.[L];if(s&&s.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(ot(n,i)&&(n!==void 0||ie(e.base_,t)))return!0;re(e),ce(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return ne(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 n=P(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty(){O(11)},getPrototypeOf(e){return V(e.base_)},setPrototypeOf(){O(12)}},z={};Y(fe,(e,t)=>{z[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});z.deleteProperty=function(e,t){return z.set.call(this,e,t,void 0)};z.set=function(e,t,n){return fe.set.call(this,e[0],t,n,e[0])};function ne(e,t){let n=e[L];return(n?P(n):e)[t]}function ft(e,t,n){let r=Re(t,n);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}function Re(e,t){if(!(t in e))return;let n=V(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=V(n)}}function ce(e){e.modified_||(e.modified_=!0,e.parent_&&ce(e.parent_))}function re(e){e.copy_||(e.copy_=oe(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var dt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){let s=n;n=t;let c=this;return function(a=s,...o){return c.produce(a,u=>n.call(this,u,...o))}}typeof n!="function"&&O(6),r!==void 0&&typeof r!="function"&&O(7);let i;if(S(t)){let s=be(this),c=le(t,void 0),l=!0;try{i=n(c),l=!1}finally{l?se(s):ae(s)}return Ae(s,r),we(i,s)}else if(!t||typeof t!="object"){if(i=n(t),i===void 0&&(i=t),i===ve&&(i=void 0),this.autoFreeze_&&ue(i,!0),r){let s=[],c=[];D("Patches").generateReplacementPatches_(t,i,s,c),r(s,c)}return i}else O(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(c,...l)=>this.produceWithPatches(c,a=>t(a,...l));let r,i;return[this.produce(t,n,(c,l)=>{r=c,i=l}),r,i]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){S(e)||O(8),M(e)&&(e=pt(e));let t=be(this),n=le(e,void 0);return n[L].isManual_=!0,ae(t),n}finishDraft(e,t){let n=e&&e[L];(!n||!n.isManual_)&&O(9);let{scope_:r}=n;return Ae(r,t),we(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let i=t[n];if(i.path.length===0&&i.op==="replace"){e=i.value;break}}n>-1&&(t=t.slice(n+1));let r=D("Patches").applyPatches_;return M(e)?r(e,t):this.produce(e,i=>r(i,t))}};function le(e,t){let n=X(e)?D("MapSet").proxyMap_(e,t):q(e)?D("MapSet").proxySet_(e,t):ut(e,t);return(t?t.scope_:Le()).drafts_.push(n),n}function pt(e){return M(e)||O(10,e),Oe(e)}function Oe(e){if(!S(e)||Q(e))return e;let t=e[L],n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=oe(e,t.scope_.immer_.useStrictShallowCopy_)}else n=oe(e,!0);return Y(n,(r,i)=>{$e(n,r,Oe(i))}),t&&(t.finalized_=!1),n}var R=new dt,de=R.produce,Kn=R.produceWithPatches.bind(R),Yn=R.setAutoFreeze.bind(R),Jn=R.setUseStrictShallowCopy.bind(R),Hn=R.applyPatches.bind(R),Gn=R.createDraft.bind(R),Xn=R.finishDraft.bind(R);var Ce=(e,t,n={})=>{let r=structuredClone(e),i={},s={},{transformSelectorFirstArgument:c=a=>a,transformActionFirstArgument:l=a=>a}=n;for(let[a,o]of Object.entries(t))a!=="createInitialState"&&(a.startsWith("select")?i[a]=(...u)=>o(c(r),...u):s[a]=(...u)=>{r=de(r,p=>o(l(p),...u))});return{...i,...s}},Z=(e,t)=>n=>{let r=e(),i=Array.isArray(n)?n:[n];return de(r,s=>{i.forEach(c=>{t.forEach(l=>{l(s,c)})})})};var ht=()=>({}),yt=(e,t)=>{t.screen&&(e.screen={...t.screen})},gt=(e,t)=>{t.background&&(e.background={...t.background})},mt=(e,t)=>{if(!t.dialogue){e.dialogue&&e.dialogue.mode==="adv"&&(e.dialogue.content=void 0,e.dialogue.characterId=void 0);return}if(e.dialogue||(e.dialogue={}),t.dialogue.gui&&(e.dialogue.gui={...t.dialogue.gui}),t.dialogue.mode==="adv"&&(e.dialogue.content=e.dialogue.content||void 0,e.dialogue.characterId=e.dialogue.characterId||void 0,e.dialogue.mode="adv"),t.dialogue.mode==="nvl"&&(e.dialogue?.mode!=="nvl"&&(e.dialogue.lines=[]),e.dialogue.mode="nvl"),t.dialogue.content!==void 0&&(e.dialogue.content=t.dialogue.content),t.dialogue.characterId!==void 0&&(e.dialogue.characterId=t.dialogue.characterId),t.dialogue.character&&(e.dialogue.character={...t.dialogue.character}),t.dialogue.clear){delete e.dialogue;return}t.dialogue?.mode==="nvl"&&t.dialogue.content!==void 0&&(t.dialogue.clear&&(e.dialogue.lines=[]),e.dialogue.lines.push({content:t.dialogue.content}))},_t=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},It=(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}}},At=(e,t)=>{t.visual&&(e.visual=t.visual)},bt=(e,t)=>{t.character&&(t.character.items||delete e.character,e.character=structuredClone(t.character))},wt=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},Et=(e,t)=>{t.layout?e.layout=t.layout:e.layout&&delete e.layout},vt=(e,t)=>{t.choice?e.choice=t.choice:e.choice&&delete e.choice},xt=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},$t=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},Te=e=>Z(ht,[$t,yt,gt,_t,It,At,mt,bt,wt,Et,vt,xt])(e);var d={LITERAL:0,VARIABLE:1,INTERPOLATION:2,FUNCTION:3,BINARY:4,UNARY:5,CONDITIONAL:6,LOOP:7,OBJECT:8,ARRAY:9,PARTIAL:10,PATH_REFERENCE:11},w={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},U={NOT:0};var I=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 pe=e=>{if(!e||e.trim()==="")throw new I("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let n=e.includes("===")?"==":"!=";throw new I(`Invalid comparison operator '${e.includes("===")?"===":"!=="}' - did you mean '${n}'? (got: '${e}')`)}let t=["<",">","<=",">=","==","!="];for(let n of t)if(e.trim().endsWith(n))throw new I(`Incomplete comparison expression - missing right operand (got: '${e}')`)},ke=e=>{if(e.trim().endsWith(" in"))throw new I(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new I(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,n]=e.split(" in ");if(!n||n.trim()==="")throw new I(`Missing iterable expression after 'in' (got: '$for ${e}')`);let r=t.includes(",")?t.split(",").map(i=>i.trim()):[t.trim()];for(let i of r){if(!i)throw new I(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(i))throw new I(`Invalid loop syntax (got: '$for ${e}')`)}};var Ne=(e,t,n=!1)=>{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 n?new $(`Cannot iterate over non-array value in loop '${e}' - got ${r} instead`):new $(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},Pe=(e,t)=>{let n=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new $(`Unknown function '${e}' (${n})`)};var Lt=(e,t,n={})=>{let r={},i={};n&&typeof n=="object"&&(n.functions!==void 0||n.partials!==void 0?(r=n.functions||{},i=n.partials||{}):typeof n=="object"&&(r=n));let c=A(e,{functions:r,partials:i},t,{});return c===void 0?{}:c},A=(e,t,n,r)=>{let i=t.functions||t;if(e.var&&!e.type)return E(e.var,n,r);if(e.type===d.LITERAL)return e.value;if(e.type===d.VARIABLE)return E(e.path,n,r);if(e.type===d.INTERPOLATION)return Ot(e.parts,t,n,r);switch(e.type){case d.FUNCTION:return De(e,t,n,r);case d.BINARY:return Be(e,t,n,r);case d.UNARY:return Ve(e,t,n,r);case d.CONDITIONAL:return Tt(e,t,n,r);case d.LOOP:return Dt(e,t,n,r);case d.OBJECT:return Vt(e,t,n,r);case d.ARRAY:return Mt(e,t,n,r);case d.PARTIAL:return Ft(e,t,n,r);case d.PATH_REFERENCE:return Wt(e,t,n,r);default:throw new Error(`Unknown node type: ${e.type}`)}},Se=new Map,Rt=e=>{let t=[],n="",r=!1;for(let i=0;i<e.length;i++){let s=e[i];if(s==="[")n&&(t.push({type:"property",value:n}),n=""),r=!0;else if(s==="]"){if(r&&n){let c=n.trim();if(/^\d+$/.test(c))t.push({type:"index",value:parseInt(c,10)});else if(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")){let l=c.slice(1,-1);t.push({type:"property",value:l})}else t.push({type:"property",value:c});n=""}r=!1}else n+=s}return n&&t.push({type:"property",value:n}),t},E=(e,t,n)=>{if(!e)return;if(e in n)return n[e];let r=Se.get(e);if(!r){let s=[],c="",l=0;for(let a=0;a<e.length;a++){let o=e[a];o==="["?(l++,c+=o):o==="]"?(l--,c+=o):o==="."&&l===0?c&&(s.push(c),c=""):c+=o}c&&s.push(c),r=[];for(let a of s){let o=Rt(a.trim());r.push(...o)}Se.set(e,r)}let i=t;for(let s=0;s<r.length;s++){let c=r[s];if(c.type==="property"&&c.value in n){i=n[c.value];continue}if(i==null)return;(c.type==="property"||c.type==="index")&&(i=i[c.value])}return i},Ot=(e,t,n,r)=>{let i=[];for(let s of e)if(typeof s=="string")i.push(s);else{let c=A(s,t,n,r);i.push(c!=null?String(c):"")}return i.join("")},De=(e,t,n,r)=>{let i=t.functions||t,s=i[e.name];if(!s)throw Pe(e.name,i);let c=e.args.map(l=>A(l,t,n,r));return s(...c)},F=(e,t,n,r)=>{if(e.var&&!e.type)return E(e.var,n,r);switch(e.type){case d.VARIABLE:return E(e.path,n,r);case d.LITERAL:return e.value;case d.BINARY:return Be(e,t,n,r);case d.UNARY:return Ve(e,t,n,r);case d.FUNCTION:return De(e,t,n,r);default:return A(e,t,n,r)}},Be=(e,t,n,r)=>{if(e.op===w.AND||e.op===w.OR){let c=F(e.left,t,n,r),l=F(e.right,t,n,r);switch(e.op){case w.AND:return c&&l;case w.OR:return c||l}}let i=A(e.left,t,n,r),s=A(e.right,t,n,r);switch(e.op){case w.EQ:return i==s;case w.NEQ:return i!=s;case w.GT:return i>s;case w.LT:return i<s;case w.GTE:return i>=s;case w.LTE:return i<=s;case w.IN:return Array.isArray(s)?s.includes(i):!1;case w.ADD:if(typeof i!="number"||typeof s!="number")throw new $(`Arithmetic operations require numbers. Got ${typeof i} + ${typeof s}`);return i+s;case w.SUBTRACT:if(typeof i!="number"||typeof s!="number")throw new $(`Arithmetic operations require numbers. Got ${typeof i} - ${typeof s}`);return i-s;default:throw new Error(`Unknown binary operator: ${e.op}`)}},Ve=(e,t,n,r)=>{let i=e.op===U.NOT?F(e.operand,t,n,r):A(e.operand,t,n,r);switch(e.op){case U.NOT:return!i;default:throw new Error(`Unknown unary operator: ${e.op}`)}},Ct=(e,t,n,r)=>{if(e.conditions.length===2&&e.conditions[1]===null){let i=e.conditions[0];if(i.type===d.VARIABLE)if(E(i.path,n,r)){let c=e.bodies[0];if(c.type===d.OBJECT&&c.properties.length<=5){let l={};for(let a of c.properties){let o=a.parsedKey?A(a.parsedKey,t,n,r):a.key,u=a.value;if(u.type===d.LITERAL)l[o]=u.value;else if(u.type===d.VARIABLE)l[o]=E(u.path,n,r);else if(u.type===d.INTERPOLATION){let f=[];for(let p of u.parts)if(typeof p=="string")f.push(p);else if(p.type===d.VARIABLE){let h=E(p.path,n,r);f.push(h!=null?String(h):"")}else{let h=A(p,t,n,r);f.push(h!=null?String(h):"")}l[o]=f.join("")}else l[o]=A(u,t,n,r)}return l}}else{let c=e.bodies[1];if(c.type===d.OBJECT&&c.properties.length<=5){let l={};for(let a of c.properties){let o=a.parsedKey?A(a.parsedKey,t,n,r):a.key,u=a.value;if(u.type===d.LITERAL)l[o]=u.value;else if(u.type===d.VARIABLE)l[o]=E(u.path,n,r);else if(u.type===d.INTERPOLATION){let f=[];for(let p of u.parts)if(typeof p=="string")f.push(p);else if(p.type===d.VARIABLE){let h=E(p.path,n,r);f.push(h!=null?String(h):"")}else{let h=A(p,t,n,r);f.push(h!=null?String(h):"")}l[o]=f.join("")}else l[o]=A(u,t,n,r)}return l}}}return null},Tt=(e,t,n,r)=>{let i=Ct(e,t,n,r);if(i!==null)return i;for(let s=0;s<e.conditions.length;s++){let c=e.conditions[s];if(c===null||F(c,t,n,r))return A(e.bodies[s],t,n,r)}return Me},kt=(e,t)=>{let n=e.body,r=e.itemVar;if(n.type===d.CONDITIONAL&&n.conditions.length===1&&n.conditions[0].type===d.VARIABLE){let i=n.conditions[0].path,s=n.bodies[0];if(i.startsWith(r+".")){let c=i.substring(r.length+1);if(s.type===d.OBJECT&&s.properties.length<=5){for(let a of s.properties)if(a.parsedKey)return null;let l=[];for(let a=0;a<t.length;a++){let o=t[a];if(o[c]){let u={};for(let f of s.properties){let p=f.key,h=f.value;if(h.type===d.LITERAL)u[p]=h.value;else if(h.type===d.VARIABLE){let y=h.path;if(y===r)u[p]=o;else if(y.startsWith(r+".")){let g=y.substring(r.length+1);u[p]=o[g]}else return null}else if(h.type===d.INTERPOLATION){let y=[],g=!0;for(let m of h.parts)if(typeof m=="string")y.push(m);else if(m.type===d.VARIABLE){let _=m.path;if(_===r)y.push(o!=null?String(o):"");else if(_.startsWith(r+".")){let b=_.substring(r.length+1),v=o[b];y.push(v!=null?String(v):"")}else{g=!1;break}}else{g=!1;break}if(!g)return null;u[p]=y.join("")}else return null}l.push(u)}}return l}}}return null},Nt=(e,t)=>{let n=e.body,r=e.itemVar,i=kt(e,t);if(i!==null)return i;if(n.type===d.OBJECT&&n.properties.length<=5&&!n.whenCondition){for(let l of n.properties)if(l.parsedKey)return null;let s=[],c=!0;for(let l of n.properties){let a=l.key,o=l.value;if(o.type===d.LITERAL)s.push({key:a,type:"literal",value:o.value});else if(o.type===d.VARIABLE){let u=o.path;if(u===r)s.push({key:a,type:"item"});else if(u.startsWith(r+".")){let f=u.substring(r.length+1);if(!f.includes(".")&&!f.includes("["))s.push({key:a,type:"prop",prop:f});else{c=!1;break}}else{c=!1;break}}else if(o.type===d.INTERPOLATION&&o.parts.length===1){let u=o.parts[0];if(u.type===d.VARIABLE){let f=u.path;if(f===r)s.push({key:a,type:"item_string"});else if(f.startsWith(r+".")){let p=f.substring(r.length+1);if(!p.includes(".")&&!p.includes("["))s.push({key:a,type:"prop_string",prop:p});else{c=!1;break}}else{c=!1;break}}else{c=!1;break}}else{c=!1;break}}if(c){let l=new Array(t.length);if(s.length===3&&s[0].type==="prop"&&s[0].key==="id"&&s[1].type==="prop_string"&&s[1].key==="title"&&s[2].type==="prop"&&s[2].key==="completed")for(let a=0;a<t.length;a++){let o=t[a];l[a]={id:o.id,title:o.title!=null?String(o.title):"",completed:o.completed}}else for(let a=0;a<t.length;a++){let o=t[a],u={};for(let f of s)if(f.type==="literal")u[f.key]=f.value;else if(f.type==="item")u[f.key]=o;else if(f.type==="prop")u[f.key]=o[f.prop];else if(f.type==="item_string")u[f.key]=o!=null?String(o):"";else if(f.type==="prop_string"){let p=o[f.prop];u[f.key]=p!=null?String(p):""}l[a]=u}return l}}return null},Pt=(e,t,n,r,i)=>{let s=[],c=e.body;if(c.type===d.OBJECT&&c.fast!==!1){let l=e.itemVar,a=e.indexVar;for(let o=0;o<i.length;o++){let u=i[o],f={},p={...r,[l]:u,...a&&{[a]:o}};p.__paths__||(p.__paths__=r.__paths__||{});let h=e.iterable.path||"";if(r&&r.__paths__&&h){let y=h.split("."),g=y[0];g in r.__paths__&&(h=r.__paths__[g],y.length>1&&(h+="."+y.slice(1).join(".")))}p.__paths__={...p.__paths__,[l]:`${h}[${o}]`,...a&&{[a]:o}};for(let y of c.properties){let g=y.parsedKey?A(y.parsedKey,t,n,p):y.key,m=y.value;if(m.type===d.LITERAL)f[g]=m.value;else if(m.type===d.VARIABLE){let _=m.path;if(_===l)f[g]=u;else if(_===a)f[g]=o;else if(_.startsWith(l+".")){let b=_.substring(l.length+1);!b.includes(".")&&!b.includes("[")?f[g]=u[b]:f[g]=E(_,n,{...r,[l]:u,...a&&{[a]:o}})}else f[g]=E(_,n,{...r,[l]:u,...a&&{[a]:o}})}else if(m.type===d.INTERPOLATION){let _=[];for(let b of m.parts)if(typeof b=="string")_.push(b);else if(b.type===d.VARIABLE){let v=b.path,C;if(v===l)C=u;else if(v===a)C=o;else if(v.startsWith(l+".")){let te=v.substring(l.length+1);!te.includes(".")&&!te.includes("[")?C=u[te]:C=E(v,n,{...r,[l]:u,...a&&{[a]:o}})}else C=E(v,n,{...r,[l]:u,...a&&{[a]:o}});_.push(C!=null?String(C):"")}else{let v={...r,[l]:u,...a&&{[a]:o}},C=A(b,t,n,v);_.push(C!=null?String(C):"")}f[g]=_.join("")}else{let _={...r,[l]:u,...a&&{[a]:o}};f[g]=A(m,t,n,_)}}s.push(f)}return s}return null},St=(e,t,n)=>{let r=e.body;if(r.type===d.OBJECT&&r.properties.length===1&&r.properties[0].key==="$if item.visible"){let s=r.properties[0].value;if(s.type===d.CONDITIONAL&&s.conditions.length===1&&s.conditions[0].type===d.VARIABLE&&s.conditions[0].path==="item.visible"){let c=s.bodies[0];if(c.type===d.OBJECT&&c.properties.length===2){let l=c.properties[0],a=c.properties[1];if(l.key==="id"&&l.value.type===d.VARIABLE&&l.value.path==="item.id"&&a.key==="$if item.highlighted"&&a.value.type===d.CONDITIONAL){let o=[];for(let u=0;u<t.length;u++){let f=t[u];if(f.visible){let p={id:f.id};f.highlighted?(p.highlight=!0,p.message=`This item is highlighted: ${f.name}`):(p.highlight=!1,p.message=f.name),o.push(p)}}return o}}}}return null},Dt=(e,t,n,r)=>{let i=A(e.iterable,t,n,r);if(!Array.isArray(i)){let o,u=!1;if(e.iterable.type===d.FUNCTION){u=!0;let p=e.iterable.args.map(h=>h.type===d.LITERAL?typeof h.value=="string"?`'${h.value}'`:String(h.value):h.type===d.VARIABLE?h.path:h.type===d.FUNCTION?`${h.name}(...)`:"?").join(", ");o=`${e.iterable.name}(${p})`}else o=e.iterable.path||"undefined";let f=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${o}`;throw Ne(f,i,u)}if(!e.indexVar){let o=St(e,i,e.itemVar);if(o!==null)return o}if(!e.indexVar){let o=Nt(e,i);if(o!==null)return o}let s=Pt(e,t,n,r,i);if(s!==null)return s;let c=[],l=e.iterable.path||"";if(r&&r.__paths__&&l){let o=l.split("."),u=o[0];u in r.__paths__&&(l=r.__paths__[u],o.length>1&&(l+="."+o.slice(1).join(".")))}let a=!1;e.body.type===d.ARRAY&&(e.body.items.length<=1?a=!1:a=e.body._shouldPreserveArray??=e.body.items.some(o=>o.type===d.OBJECT&&o.properties.some(u=>u.key.startsWith("$if ")||u.key.startsWith("$when "))));for(let o=0;o<i.length;o++){let u=e.indexVar?{...r,[e.itemVar]:i[o],[e.indexVar]:o}:{...r,[e.itemVar]:i[o]};u.__paths__||(u.__paths__=r.__paths__||{}),u.__paths__={...u.__paths__,[e.itemVar]:`${l}[${o}]`},e.indexVar&&(u.__paths__[e.indexVar]=o);let f=A(e.body,t,n,u);if(Array.isArray(f)&&f.length===1&&!a){let p=f[0];c.push(p===void 0?{}:p)}else c.push(f===void 0?{}:f)}return c},Bt=(e,t,n,r)=>{if(e.whenCondition)return null;if(e.properties.length===1){let i=e.properties[0],s=i.parsedKey?A(i.parsedKey,t,n,r):i.key,c=i.value;if(c.type===d.OBJECT&&c.properties.length<=10&&!c.whenCondition){let l={},a={},o=!0;for(let u of c.properties){let f=u.parsedKey?A(u.parsedKey,t,n,r):u.key,p=u.value;if(p.type===d.LITERAL)a[f]=p.value;else if(p.type===d.VARIABLE)a[f]=E(p.path,n,r);else if(p.type===d.INTERPOLATION){let h=[];for(let y of p.parts)if(typeof y=="string")h.push(y);else if(y.type===d.VARIABLE){let g=E(y.path,n,r);h.push(g!=null?String(g):"")}else{o=!1;break}if(!o)break;a[f]=h.join("")}else if(p.type===d.OBJECT&&p.properties.length<=5){let h={};for(let y of p.properties){let g=y.key,m=y.value;if(m.type===d.LITERAL)h[g]=m.value;else if(m.type===d.VARIABLE)h[g]=E(m.path,n,r);else if(m.type===d.INTERPOLATION){let _=[];for(let b of m.parts)if(typeof b=="string")_.push(b);else if(b.type===d.VARIABLE){let v=E(b.path,n,r);_.push(v!=null?String(v):"")}else{o=!1;break}if(!o)break;h[g]=_.join("")}else{o=!1;break}}if(!o)break;a[f]=h}else{o=!1;break}}if(o)return l[s]=a,l}}return null},Vt=(e,t,n,r)=>{let i=t.functions||t;if(e.whenCondition&&!F(e.whenCondition,i,n,r))return;let s=Bt(e,t,n,r);if(s!==null)return s;if(e.fast){let o={};for(let u of e.properties){let f=u.parsedKey?A(u.parsedKey,t,n,r):u.key,p=u.value;if(p.type===d.LITERAL)o[f]=p.value;else if(p.type===d.VARIABLE)o[f]=E(p.path,n,r);else if(p.type===d.INTERPOLATION){let h=[];for(let y of p.parts)if(typeof y=="string")h.push(y);else if(y.type===d.VARIABLE){let g=E(y.path,n,r);h.push(g!=null?String(g):"")}else{let g=A(y,t,n,r);h.push(g!=null?String(g):"")}o[f]=h.join("")}else o[f]=A(p,t,n,r)}return o}let c={},l=null,a=!1;for(let o of e.properties)if(!o.key.startsWith("$if ")&&!o.key.match(/^\$if\s+\w+.*:?$/)&&!o.key.startsWith("$elif")&&!o.key.startsWith("$else")&&!o.key.startsWith("$for ")){a=!0;break}for(let o of e.properties)if(o.key.startsWith("$if ")||o.key.match(/^\$if\s+\w+.*:?$/)){let u=A(o.value,t,n,r);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(c,u)}else if(o.key.startsWith("$for ")){if(e.properties.length===1)return A(o.value,t,n,r)}else{let u=o.value;if(u&&u.type===d.OBJECT&&u.properties){let f=u.properties.find(p=>p.key.startsWith("$for "));if(f){let p=A(f.value,t,n,r);p!==void 0&&(c[o.key]=p)}else{let p=A(o.value,t,n,r);p!==void 0&&(c[o.key]=p)}}else{let f=o.parsedKey?A(o.parsedKey,t,n,r):o.key,p=A(o.value,t,n,r);p!==void 0&&(c[f]=p)}}return c},Me={},Mt=(e,t,n,r)=>{let i=[];for(let s of e.items)if(s.type===d.LOOP){let c=A(s,t,n,r);Array.isArray(c)&&s.flatten!==!1?i.push(...c):i.push(c)}else{let c=A(s,t,n,r);c!==Me&&c!==void 0&&i.push(c)}return i},Ft=(e,t,n,r)=>{let{name:i,data:s,whenCondition:c}=e,l=t.partials||{},a=t.functions||t;if(c&&!F(c,a,n,r))return;if(!l[i])throw new $(`Partial '${i}' is not defined`);let o=r._partialStack||[];if(o.includes(i))throw new $(`Circular partial reference detected: ${i}`);let u=l[i],f=n,p={...r,_partialStack:[...o,i]};if(r){f={...n};for(let h of Object.keys(r))h.startsWith("_")||(f[h]=r[h])}if(s){let h=A(s,t,n,r);f={...f,...h}}return A(u,t,f,p)},Wt=(e,t,n,r)=>{let{path:i}=e,s=i.split("."),c=s[0],l=s.slice(1);if(!r||!(c in r))throw new $(`Path reference '#{${i}}' refers to '${c}' which is not a loop variable in the current scope`);if(r.__paths__||(r.__paths__={}),!(c in r.__paths__))throw new $(`Path reference '#{${i}}' cannot be resolved - path tracking may not be initialized properly`);let a=r.__paths__[c];if(typeof a=="number"){if(l.length>0)throw new $(`Path reference '#{${i}}' - cannot access properties on index variable '${c}'`);return String(a)}return l.length>0&&(a+="."+l.join(".")),a},he=Lt;var zt=/\$\{([^}]*)\}/g,Ut=/#\{([^}]*)\}/g,We=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,r,i]=n,s=jt(i,t);return{isFunction:!0,type:d.FUNCTION,name:r,args:s}},jt=(e,t={})=>e.trim()?Kt(e).map(r=>Yt(r.trim(),t)):[],Kt=e=>{let t=[],n="",r=0,i=!1,s="";for(let c=0;c<e.length;c++){let l=e[c],a=c>0?e[c-1]:"";!i&&(l==='"'||l==="'")?(i=!0,s=l,n+=l):i&&l===s&&a!=="\\"?(i=!1,s="",n+=l):!i&&l==="("?(r++,n+=l):!i&&l===")"?(r--,n+=l):!i&&l===","&&r===0?(t.push(n),n=""):n+=l}return n&&t.push(n),t},Yt=(e,t={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:d.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:d.LITERAL,value:parseFloat(e)};if(e==="true")return{type:d.LITERAL,value:!0};if(e==="false")return{type:d.LITERAL,value:!1};if(e==="null")return{type:d.LITERAL,value:null};let n=We(e,t);if(n.isFunction)return{type:n.type,name:n.name,args:n.args};let r=e.trim(),i=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],s=-1,c=null;for(let{op:l,type:a}of i){let o=0;for(;o<r.length;){let u=B(r.substring(o),l);if(u===-1)break;let f=o+u;f>s&&(s=f,c={op:l,type:a}),o=f+l.length}}if(s!==-1)try{return x(r,t)}catch{return{type:d.VARIABLE,path:r}}return{type:d.VARIABLE,path:r}},ze=/^\w+\(.*\)$/,Jt=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,Ht=e=>{if(!(!e||e.trim()===""||ze.test(e))&&Jt.test(e))throw e.includes("?")&&e.includes(":")?new I(`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 I(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new I(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},Fe=e=>{let t=e.trim();if(ze.test(t))throw new I(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("["))throw new I(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(t))throw new I(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(t))throw new I(`Logical operators not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("?")&&t.includes(":"))throw new I(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:d.PATH_REFERENCE,path:t}},j=(e,t={})=>{let n=e.trim();Ht(n);let r=We(n,t);if(r.isFunction)return{type:r.type,name:r.name,args:r.args};if(n.includes("[")&&!/[\s+\-*/%|&?:]/.test(n)){let i=0;for(let s of n)s==="["?i++:s==="]"&&i--;if(i!==0)throw new Error("Invalid array index syntax")}return{type:d.VARIABLE,path:n}},ye=(e,t={})=>{let n=e,r=[];(e.includes("\\${")||e.includes("\\#{"))&&(n=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC_VAR$1"),n=n.replace(/\\\\(#\{[^}]*\})/g,"\\DOUBLE_ESC_PATH$1"),n=n.replace(/\\(\$\{[^}]*\})/g,(o,u)=>{let f=`__ESCAPED_${r.length}__`;return r.push(u),f}),n=n.replace(/\\(#\{[^}]*\})/g,(o,u)=>{let f=`__ESCAPED_${r.length}__`;return r.push(u),f}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let i=[...n.matchAll(zt)],s=[...n.matchAll(Ut)],c=[...i.map(o=>({match:o,type:"variable"})),...s.map(o=>({match:o,type:"pathref"}))].sort((o,u)=>o.match.index-u.match.index);if(c.length===0){let o=n;for(let u=0;u<r.length;u++)o=o.replace(`__ESCAPED_${u}__`,r[u]);return{type:d.LITERAL,value:o}}if(c.length===1&&c[0].match[0]===n&&r.length===0){let{match:o,type:u}=c[0];try{return u==="variable"?j(o[1],t):Fe(o[1])}catch(f){if(f.message==="Invalid array index syntax")return{type:d.LITERAL,value:n};throw f}}let l=[],a=0;for(let{match:o,type:u}of c){let[f,p]=o,h=o.index;if(h>a){let y=n.substring(a,h);for(let g=0;g<r.length;g++)y=y.replace(`__ESCAPED_${g}__`,r[g]);y&&l.push(y)}try{let y;u==="variable"?y=j(p.trim(),t):y=Fe(p.trim()),l.push(y)}catch(y){if(y.message==="Invalid array index syntax")l.push(f);else throw y}a=h+f.length}if(a<n.length){let o=n.substring(a);for(let u=0;u<r.length;u++)o=o.replace(`__ESCAPED_${u}__`,r[u]);o&&l.push(o)}return{type:d.INTERPOLATION,parts:l}};var k=(e,t)=>typeof e=="string"?ye(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?Xt(e,t):qt(e,t):{type:d.LITERAL,value:e},Gt=e=>{let{$each:t,...n}=e;if(typeof t!="string")throw new I("$each value must be a non-empty string");let r=t.trim();if(r==="")throw new I("$each value must be a non-empty string");if(Object.keys(n).length===0)throw new I("Empty $each body not allowed");if(n.$partial!==void 0)throw new I("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${r}`]:n}},Xt=(e,t)=>{let n=[],r=!1;for(let i=0;i<e.length;i++){let s=e[i];if(typeof s=="object"&&s!==null&&!Array.isArray(s)){if(s.$each!==void 0)try{let a=Gt(s),o=Object.keys(a);if(o.length===1&&/^\$for(?::\w+)?\s/.test(o[0])){let u=Ue(o[0],a[o[0]],t,!0);n.push(u),r=!0;continue}}catch(a){throw a instanceof I?a:new I(a.message)}let l=Object.keys(s);if(l.length===1&&/^\$for(?::\w+)?\s/.test(l[0])){let a=Ue(l[0],s[l[0]],t);n.push(a),r=!0;continue}}let c=k(s,t);n.push(c),(c.type===d.FUNCTION||c.type===d.CONDITIONAL||c.type===d.LOOP||c.type===d.PARTIAL||c.type===d.OBJECT&&!c.fast||c.type===d.ARRAY&&!c.fast)&&(r=!0)}return{type:d.ARRAY,items:n,fast:!r}},qt=(e,t)=>{let n=[],r=!1,i=null,s=Object.entries(e),c=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new I("$partial value must be a string");if(e.$partial.trim()==="")throw new I("$partial value cannot be an empty string");let a=["$if","$elif","$else","$for"],o=[];for(let[_]of s)for(let b of a)if(_===b||_.startsWith(b+" ")||_.startsWith(b+"#")){o.push(b);break}if(o.length>0)throw new I(`Cannot use $partial with ${o.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:u,$when:f,...p}=e,h={},y=!1;for(let[_,b]of Object.entries(p)){let v=_;(_.startsWith("\\$")||_.startsWith("$$"))&&(v=_.slice(1)),h[v]=b,y=!0}let g=null;if(y&&(g=k(h,t),g.type===d.OBJECT)){let _=!1;for(let b of g.properties)if(b.value.type===d.VARIABLE||b.value.type===d.INTERPOLATION||b.value.type===d.FUNCTION||b.value.type===d.CONDITIONAL||b.value.type===d.OBJECT&&!b.value.fast||b.value.type===d.ARRAY&&!b.value.fast){_=!0;break}_&&(g.fast=!1)}let m={type:d.PARTIAL,name:u,data:g};if(f!==void 0){let _;if(typeof f=="string"){if(f.trim()==="")throw new I("Empty condition expression after '$when'");_=x(f,t)}else _={type:d.LITERAL,value:f};m.whenCondition=_}return m}for(let[a,o]of s)if(a==="$when"){if(i!==null)throw new I("Multiple '$when' directives on the same object are not allowed");if(o==null)throw new I("Missing condition expression after '$when'");let u=typeof o=="string"?o:JSON.stringify(o);if(u.trim()==="")throw new I("Empty condition expression after '$when'");i=x(u,t),r=!0}else if(a.startsWith("$when#")||a.startsWith("$when "))throw new I("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;c<s.length;){let[a,o]=s[c];if(a==="$when"){c++;continue}if(a==="$each")throw new I("$each can only be used inside arrays");if(a.startsWith("$if ")||a.match(/^\$if#\w+\s/)||a.match(/^\$if\s+\w+.*:$/)){let u=Qt(s,c,t);n.push({key:a,value:u.node}),r=!0,c=u.nextIndex}else if(/^\$for(?::\w+)?\s/.test(a)){let u=a.match(/^\$for(?::(\w+))?\s/)?.[1]||"",f=u?`:${u}`:"";throw new I(`$for loops must be inside arrays - use '- $for${f} item in items:' instead of '$for${f} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(a.startsWith("$elif ")||a.startsWith("$else"))throw new I(`'${a.split(" ")[0]}' without matching '$if'`);if(a==="$if"||a==="$if:")throw new I("Missing condition expression after '$if'");{let u=k(o,t);(u.type===d.FUNCTION||u.type===d.CONDITIONAL||u.type===d.PARTIAL||u.type===d.OBJECT&&!u.fast||u.type===d.ARRAY&&!u.fast)&&(r=!0);let f=ye(a,t),p={key:a,value:u};(f.type!==d.LITERAL||f.value!==a)&&(p.parsedKey=f),n.push(p),c++}}}let l={type:d.OBJECT,properties:n,fast:!r};return i&&(l.whenCondition=i),l},Qt=(e,t,n={})=>{let r=[],i=[],s=t,[c,l]=e[s],a=null,o;if(c.startsWith("$if#")){let f=c.match(/^\$if#(\w+)\s+(.+)$/);if(f)a=f[1],o=f[2];else throw new I(`Invalid conditional syntax: ${c}`)}else o=c.substring(4),o.endsWith(":")&&(o=o.slice(0,-1).trim());pe(o);let u=x(o,n);for(r.push(u),i.push(k(l,n)),s++;s<e.length;){let[f,p]=e[s],h=!1,y;if(a?f.startsWith(`$elif#${a} `)?(y=f.substring(`$elif#${a} `.length),y.endsWith(":")&&(y=y.slice(0,-1).trim()),h=!0):(f===`$else#${a}`||f===`$else#${a}:`)&&(h=!0,y=null):f.startsWith("$elif ")?(y=f.substring(6),y.endsWith(":")&&(y=y.slice(0,-1).trim()),h=!0):(f==="$else"||f==="$else:")&&(h=!0,y=null),h){if(y===null)r.push(null);else{pe(y);let g=x(y,n);r.push(g)}if(i.push(k(p,n)),s++,y===null)break}else break}return{node:{type:d.CONDITIONAL,conditions:r,bodies:i,id:a},nextIndex:s}},x=(e,t={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let o=e.slice(1,-1),u=0,f=!0;for(let p=0;p<o.length;p++)if(o[p]==="("?u++:o[p]===")"&&u--,u<0){f=!1;break}if(f&&u===0)return x(o,t)}let n=B(e,"||");if(n!==-1)return{type:d.BINARY,op:w.OR,left:x(e.substring(0,n).trim(),t),right:x(e.substring(n+2).trim(),t)};let r=B(e,"&&");if(r!==-1)return{type:d.BINARY,op:w.AND,left:x(e.substring(0,r).trim(),t),right:x(e.substring(r+2).trim(),t)};let i=[{op:">=",type:w.GTE},{op:"<=",type:w.LTE},{op:"==",type:w.EQ},{op:"!=",type:w.NEQ},{op:">",type:w.GT},{op:"<",type:w.LT},{op:" in ",type:w.IN}];for(let{op:o,type:u}of i){let f=B(e,o);if(f!==-1)return{type:d.BINARY,op:u,left:x(e.substring(0,f).trim(),t),right:x(e.substring(f+o.length).trim(),t)}}let s=-1,c=null,l=[{op:" + ",type:w.ADD},{op:" - ",type:w.SUBTRACT}];for(let{op:o,type:u}of l){let f=0;for(;f<e.length;){let p=B(e.substring(f),o);if(p===-1)break;let h=f+p;h>s&&(s=h,c={op:o,type:u}),f=h+o.length}}if(s!==-1&&c)return{type:d.BINARY,op:c.type,left:x(e.substring(0,s).trim(),t),right:x(e.substring(s+c.op.length).trim(),t)};let a=[" * "," / "," % "];for(let o of a)if(B(e,o)!==-1)throw new I(`Arithmetic operations are not allowed in conditionals: "${o}"`);return e.startsWith("!")?{type:d.UNARY,op:U.NOT,operand:x(e.substring(1).trim(),t)}:je(e,t)},B=(e,t)=>{let n=0,r=0;for(;r<=e.length-t.length;){if(e[r]==="(")n++;else if(e[r]===")")n--;else if(n===0&&e.substring(r,r+t.length)===t)return r;r++}return-1},Zt=e=>{if(e=e.trim(),e==="true")return{type:d.LITERAL,value:!0};if(e==="false")return{type:d.LITERAL,value:!1};if(e==="null")return{type:d.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:d.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:d.LITERAL,value:""};if(e==="{}")return{type:d.LITERAL,value:{}};if(e==="[]")return{type:d.LITERAL,value:[]};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:d.LITERAL,value:t}:{type:d.VARIABLE,path:e}},je=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return j(n,t);let i=Zt(n);if(i.type===d.LITERAL)return i;if(/^[a-zA-Z_$][\w.$]*$/.test(n))return{type:d.VARIABLE,path:n};try{return j(n,t)}catch(s){if(s.message&&s.message.includes("not supported"))return i;throw s}},en=(e,t=!1)=>{let n=t?"$each":"$for";try{ke(e)}catch(r){if(r instanceof I&&t){let i=r.message.replace(/\$for/g,"$each");throw new I(i.replace("Parse Error: ",""))}throw r}},Ue=(e,t,n,r=!1)=>{let i=/^\$for(?::(\w+))?\s+(.+)$/,s=e.match(i);if(!s){let m=r?"$each":"$for";throw new I(`Invalid loop syntax (got: '${e.replace("$for",m)}')`)}let c=s[1],l=s[2].trim();en(l,r);let a=l.match(/^(.+?)\s+in\s+(.+)$/);if(!a){let m=r?"$each":"$for";throw new I(`Invalid loop syntax - missing 'in' keyword (got: '${m} ${l}')`)}let o=a[1].trim(),u=a[2].trim(),f,p=null;if(o.includes(",")){let m=o.split(",").map(_=>_.trim());if(m.length!==2)throw new I(`Invalid loop variables: ${o}. Expected format: "item" or "item, index"`);f=m[0],p=m[1]}else f=o;let h=["this","undefined","null","true","false"];if(h.includes(f))throw new I(`Reserved variable name: ${f}`);if(p&&h.includes(p))throw new I(`Reserved variable name: ${p}`);let y=je(u,n),g=k(t,n);return{type:d.LOOP,itemVar:f,indexVar:p,iterable:y,body:g,flatten:c!=="nested"}};var tn=(e,t={})=>{let{functions:n={}}=t;return k(e,n)},ee=tn;var ge={};rt(ge,{now:()=>nn});var nn=()=>Date.now();var rn=(e,t,n={})=>{let{functions:r={},partials:i={}}=n,s={...ge,...r},c=ee(e,{functions:s}),l={};for(let[a,o]of Object.entries(i))l[a]=ee(o,{functions:s});return he(c,t,{functions:s,partials:l})},T=rn;var me={objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n}))},on=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[]}),sn=(e,{presentationState:t,resources:n})=>{let{elements:r}=e;if(t.screen){let i=r.find(s=>s.id==="story");if(!i)return e;if(t.screen.resourceId){let s=n?.layouts[t.screen.resourceId];s&&i.children.unshift({id:"screen",type:"container",children:s.elements})}}return e},an=(e,{presentationState:t,resources:n={},variables:r,autoMode:i,skipMode:s,currentLocalizationPackageId:c})=>{let{elements:l}=e,a=e.animations||[];if(t.background){let o=l.find(u=>u.id==="story");if(!o)return e;if(t.background.resourceId){let{images:u={}}=n,f=u[t.background.resourceId];f&&o.children.push({id:`bg-cg-${t.background.resourceId}`,type:"sprite",x:0,y:0,src:f.fileId,width:f.width,height:f.height})}if(t.background.resourceId){let{layouts:u={}}=n,f=u[t.background.resourceId];f&&o.children.push({id:`bg-cg-${t.background.resourceId}`,type:"container",children:f.elements})}if(t.background.animations){if(t.background.animations.in){let u=t.background.animations.in.animationId,f=n?.animations[u];f&&a.push({id:"bg-cg-animation-in",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:f.properties})}if(t.background.animations.out){let u=t.background.animations.out.animationId,f=t.background.animations.out.resourceId,p=n?.animations[u];p&&a.push({id:"bg-cg-animation-out",type:"tween",targetId:`bg-cg-${f}`,properties:p.properties})}if(t.background.animations.update){let u=t.background.animations.update.animationId,f=n?.animations[u];f&&a.push({id:"bg-cg-animation-update",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:f.properties})}}}return e},cn=(e,{presentationState:t,resources:n})=>{let{elements:r}=e,i=e.animations||[];if(t.character&&n){let s=r.find(l=>l.id==="story");if(!s)return e;let c=t.character.items||[];for(let l of c){let{transformId:a,sprites:o}=l;if(l.animations&&l.animations.out&&!o&&!a){let h=l.animations.out.animationId,y=n?.animations[h];if(y){let g={id:"character-animation-out",type:"tween",targetId:`character-container-${l.id}`,properties:y.properties};i.push(g)}continue}if(!o||o.length===0||!a){console.warn("Character item missing sprites or transformId:",l);continue}let u=o.map(({resourceId:h})=>h),f=n.transforms[a];if(!f){console.warn("Transform not found:",a);continue}let p={type:"container",id:`character-container-${l.id}`,x:f.x,y:f.y,anchorX:f.anchorX,anchorY:f.anchorY,rotation:f.rotation,scaleX:f.scaleX,scaleY:f.scaleY,children:[]};for(let h of o){let y=n.images[h.resourceId];if(!y){console.warn(`Image resource not found: ${h.resourceId}`);continue}p.children.push({type:"sprite",id:`${l.id}-${h.id}`,url:y.fileId,width:y.width,height:y.height,x:0,y:0})}if(s.children.push(p),l.animations){if(l.animations.in){let h=l.animations.in.animationId,y=n?.animations[h];y&&i.push({id:"character-animation-in",type:"tween",targetId:`character-container-${l.id}`,properties:y.properties})}if(l.animations.update){let h=l.animations.update.animationId,y=n?.animations[h];if(y){let g={id:"character-animation-update",type:"tween",targetId:`character-container-${l.id}`,properties:y.properties};i.push(g)}}}}}return e},ln=(e,{presentationState:t,resources:n})=>{let{elements:r}=e,i=e.animations||[];if(t.visual&&n){let s=r.find(l=>l.id==="story");if(!s)return e;let c=t.visual.items;for(let l of c){if(l.resourceId){let a=n.images[l.resourceId];if(a){let o=n.transforms[l.transformId];s.children.push({id:`visual-${l.id}`,type:"sprite",url:a.fileId,width:a.width,height:a.height,x:o.x,y:o.y,anchorX:o.anchorX,anchorY:o.anchorY,rotation:o.rotation,scaleX:o.scaleX,scaleY:o.scaleY})}}if(l.animations){if(l.animations.in){let a=l.animations.in.animationId||l.animations.in,o=n?.animations[a];o&&i.push({id:`${l.id}-animation`,type:"tween",targetId:`visual-${l.id}`,properties:o.properties})}if(l.animations.out){let a=l.animations.out.animationId||l.animations.out,o=n?.animations[a];o&&i.push({id:`${l.id}-animation-2`,type:"tween",targetId:`visual-${l.id}`,properties:o.properties})}}}}return e},un=(e,{presentationState:t,resources:n={},dialogueUIHidden:r,autoMode:i,skipMode:s,l10n:c,variables:l})=>{let{elements:a}=e;if(!t.dialogue||r)return e;let o=a.find(u=>u.id==="story");if(!o)return e;if(t.dialogue.gui&&t.dialogue.gui.resourceId){let{layouts:u={}}=n,f=u[t.dialogue.gui.resourceId];if(f){let p;t.dialogue.characterId&&(p=n.characters[t.dialogue.characterId]),t.dialogue.character&&(p={...p,name:t.dialogue.character.name});let h={elements:f.elements},y={variables:l,autoMode:i,skipMode:s,dialogue:{character:{name:p?.name||""},content:t.dialogue?.content||[{text:""}],lines:t.dialogue?.lines||[]},l10n:c},g=T(h,y,{functions:me});g=T(g,{l10n:c});let m=g?.elements;if(Array.isArray(m))for(let _ of m)o.children.push(structuredClone(_));else m&&o.children.push(structuredClone(m))}}return e},fn=(e,{presentationState:t,resources:n})=>{let{elements:r}=e;if(t.choice&&n){let i=r.find(o=>o.id==="story");if(!i)return e;let s=n?.layouts[t.choice.resourceId];if(!s||!s.elements)return e;let c={elements:s.elements},a=T(c,{choice:{items:t.choice.items}})?.elements;if(Array.isArray(a))for(let o of a)i.children.push(structuredClone(o));else a&&i.children.push(structuredClone(a))}return e},dn=(e,{presentationState:t,resources:n})=>{let{elements:r,audio:i}=e;if(t.bgm&&n){if(!r.find(l=>l.id==="story"))return e;let c=n.audio[t.bgm.audioId];if(!c)return e;i.push({id:"bgm",type:"sound",url:c.fileId,loop:c.loop??!0,volume:c.volume??.5,delay:c.delay??null})}return e},pn=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(t.sfx&&n){let i=t.sfx.items;for(let s of i){let c=n.audio?.[s.audioId];c&&r.push({id:s.id,type:"sound",url:c.fileId,loop:s.loop??c.loop??!0,volume:s.volume??c.volume??.5,delay:s.delay??c.delay??null})}}return e},hn=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(!t?.voice)return e;let{fileId:i,volume:s,loop:c}=t.voice;return r.push({id:`voice-${i}`,type:"sound",url:i,volume:s??.5,loop:c??!1}),e},yn=(e,{presentationState:t,resources:n={},variables:r,autoMode:i,skipMode:s,currentLocalizationPackageId:c})=>{let{elements:l}=e,a=e.animations||[];if(t.layout){let o=l.find(g=>g.id==="story");if(!o)return e;let u=n.layouts[t.layout.resourceId];if(!u)return e;Array.isArray(u.transitions)&&u.transitions.forEach(g=>{a.push(g)});let f={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:u.elements||[]},h=T(f,{variables:r,autoMode:i,skipMode:s,currentLocalizationPackageId:c},{functions:me});h=T(h,{i18n:{}});let y=g=>{let m={...g};if(g.url&&g.url.startsWith("file:")){let _=g.url.replace("file:","");m.url=_}return g.children&&Array.isArray(g.children)&&(m.children=g.children.map(y)),m};o.children.push(y(h))}return e},gn=(e,{resources:t={},variables:n,autoMode:r,skipMode:i,currentLocalizationPackageId:s})=>{let{elements:c}=e,l=e.animations||[],a=[];return a&&a.length>0&&a.forEach((o,u)=>{if(o.resourceType==="layout"){let f=t.layouts[o.resourceId];if(!f){console.warn(`Modal layout not found: ${o.resourceId}`);return}Array.isArray(f.transitions)&&f.transitions.forEach(m=>{l.push(m)});let p={id:`modal-${u}`,type:"container",x:0,y:0,children:f.elements||[]},y=T(p,{variables:n,autoMode:r,skipMode:i,currentLocalizationPackageId:s},{functions:me});y=T(y,{i18n:{}});let g=m=>{let _={...m};if(m.url&&m.url.startsWith("file:")){let b=m.url.replace("file:","");_.url=resolveFile(b)}return m.children&&Array.isArray(m.children)&&(_.children=m.children.map(g)),_};c.push(g(y))}}),e},Ke=e=>Z(on,[sn,an,cn,ln,un,fn,yn,dn,pn,hn,gn])(e);var mn=e=>{let{global:{currentLocalizationPackageId:t},projectData:n}=e,r={sceneId:n.story.initialSceneId,sectionId:n.story.scenes[n.story.initialSceneId].initialSectionId,lineId:n.story.scenes[n.story.initialSceneId].sections[n.story.scenes[n.story.initialSceneId].initialSectionId].lines[0].id};return{projectData:n,global:{isLineCompleted:!1,pendingEffects:[],autoMode:!1,skipMode:!1,dialogueUIHidden:!1,currentLocalizationPackageId:t,viewedRegistry:{sections:[],resources:[]},nextLineConfig:{manual:{enabled:!0,requireLineCompleted:!1},auto:{enabled:!1}},saveSlots:{}},contexts:[{currentPointerMode:"read",pointers:{read:r,history:{sectionId:void 0,lineId:void 0,historySequenceIndex:void 0}},historySequence:[{sectionId:"..."}],configuration:{},views:[],bgm:{resourceId:void 0},variables:{}}]}},_n=({state:e})=>e.global.pendingEffects,Ye=({state:e})=>e.global.skipMode,In=({state:e})=>e.global.autoMode,Je=({state:e})=>e.global.dialogueUIHidden,An=({state:e})=>e.global.currentLocalizationPackageId,bn=({state:e},t)=>{let{sectionId:n,lineId:r}=t,i=e.global.viewedRegistry.sections.find(a=>a.sectionId===n);if(!i)return!1;if(i.lastLineId===void 0||r===void 0)return!0;let s=N({state:e},{sectionId:n});if(!s||!s.lines||!Array.isArray(s.lines))return!1;let c=s.lines.findIndex(a=>a.id===i.lastLineId),l=s.lines.findIndex(a=>a.id===r);return c===-1||l===-1?i.lastLineId===r:l<c},wn=({state:e},t)=>{let{resourceId:n}=t;return!!e.global.viewedRegistry.resources.find(i=>i.resourceId===n)},En=({state:e})=>e.global.nextLineConfig,vn=({state:e})=>e.global.saveSlots,xn=({state:e},t)=>{let{slotKey:n}=t;return e.global.saveSlots[n]},K=({state:e})=>{let t=e.contexts[e.contexts.length-1];if(!t)return;let n=t.pointers?.[t.currentPointerMode];return{currentPointerMode:t.currentPointerMode,pointer:n}},N=({state:e},t)=>{let{sectionId:n}=t,r=e.projectData?.story?.scenes||{};for(let i in r){let s=r[i];if(s.sections&&s.sections[n])return s.sections[n]}},$n=({state:e})=>{let t=K({state:e});if(!t?.pointer)return;let{sectionId:n,lineId:r}=t.pointer,i=N({state:e},{sectionId:n});if(!(!i?.lines||!Array.isArray(i.lines)))return i.lines.find(s=>s.id===r)},He=({state:e})=>{let{sectionId:t,lineId:n}=K({state:e}).pointer,i=N({state:e},{sectionId:t})?.lines||[],s=i.findIndex(o=>o.id===n),c=i.slice(0,s+1);console.log("currentLines",c);let l=c.map(o=>{let u=o.actions||{},f={};return Object.keys(u).forEach(p=>{f[p]=u[p]}),f});return Te(l)},Ln=({state:e})=>{let t=He({state:e});console.log("presentationState",t);let n=Ke({presentationState:t,resources:e.projectData.resources,l10n:e.projectData.localization.packages[e.global.currentLocalizationPackageId]});return console.log("renderState",n),n},Ge=({state:e})=>(e.global.skipMode&&(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"})),e.global.autoMode=!0,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"startAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Xe=({state:e})=>(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Rn=({state:e})=>(e.global.autoMode?Xe({state:e}):Ge({state:e}),e),qe=({state:e})=>(e.global.autoMode&&(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"})),e.global.skipMode=!0,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"startSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Qe=({state:e})=>(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),On=({state:e})=>(Ye({state:e})?Qe({state:e}):qe({state:e}),e),Ze=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),e),et=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),e),Cn=({state:e})=>(Je({state:e})?Ze({state:e}):et({state:e}),e),Tn=({state:e},t)=>{let{localizationPackageId:n}=t;return e.global.currentLocalizationPackageId=n,e.global.pendingEffects.push({name:"render"}),e},kn=({state:e})=>(e.global.pendingEffects=[],e),Nn=({state:e},t)=>(e.global.pendingEffects.push(t),e),Pn=({state:e},t)=>{let{sectionId:n,lineId:r}=t,i=e.global.viewedRegistry.sections.find(s=>s.sectionId===n);return i?i.lastLineId=r:e.global.viewedRegistry.sections.push({sectionId:n,lastLineId:r}),e.global.pendingEffects.push({name:"render"}),e},Sn=({state:e},t)=>{let{resourceId:n}=t;return e.global.viewedRegistry.resources.find(i=>i.resourceId===n)||e.global.viewedRegistry.resources.push({resourceId:n}),e.global.pendingEffects.push({name:"render"}),e},Dn=({state:e},t)=>{let{manual:n,auto:r}=t;return n&&r?e.global.nextLineConfig={manual:n,auto:r}:(n&&(e.global.nextLineConfig.manual=n),r&&(e.global.nextLineConfig.auto=r)),e.global.pendingEffects.push({name:"render"}),e},Bn=({state:e},t)=>{let{slotKey:n,date:r,image:i,state:s}=t;return e.global.saveSlots[n]={slotKey:n,date:r,image:i,state:s},e.global.pendingEffects.push({name:"render"}),e},Vn=({state:e},t)=>{let{item:n}=t,r=e.contexts[e.contexts.length-1];return r&&r.historySequence&&r.historySequence.push(n),e.global.pendingEffects.push({name:"render"}),e},Mn=({state:e})=>{if(e.global.nextLineConfig?.auto?.enabled!==!0||e.global.nextLineConfig?.auto?.trigger!=="fromComplete")return e;let t=K({state:e})?.pointer,n=t?.sectionId,i=N({state:e},{sectionId:n})?.lines||[],c=i.findIndex(l=>l.id===t?.lineId)+1;if(c<i.length){let l=i[c],a=e.contexts[e.contexts.length-1];a&&(a.pointers.read={sectionId:n,lineId:l.id}),e.global.isLineCompleted=!1,e.global.nextLineConfig.auto={},e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"})}return e},Fn=({state:e})=>{if(!e.global.nextLineConfig.manual.enabled)return e;let t=K({state:e})?.pointer,n=t?.sectionId,i=N({state:e},{sectionId:n})?.lines||[],c=i.findIndex(l=>l.id===t?.lineId)+1;if(c<i.length){let l=i[c],a=e.contexts[e.contexts.length-1];a&&(a.pointers.read={sectionId:n,lineId:l.id}),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"})}return e},Wn=({state:e})=>(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e),zn=({state:e},t)=>{let{sectionId:n}=t,r=N({state:e},{sectionId:n});if(!r||!r.lines||r.lines.length===0)return e;let i=r.lines,s=e.contexts[e.contexts.length-1];if(!s||!s.pointers)return e;let c=s.pointers.history||s.pointers.read;if(s.currentPointerMode!=="history"||!s.pointers.history){if(!c)return e;s.currentPointerMode="history",s.pointers.history={sectionId:n,lineId:c?.lineId};let u=i.findIndex(f=>f.id===c.lineId)-1;if(u>=0&&u<i.length){let f=i[u];s.pointers.history={sectionId:n,lineId:f.id}}return e.global.pendingEffects.push({name:"render"}),e}let a=i.findIndex(o=>o.id===s.pointers.history.lineId)-1;if(a>=0&&a<i.length){let o=i[a];s.pointers.history={sectionId:n,lineId:o.id},e.global.pendingEffects.push({name:"render"})}return e},Un=({state:e},t)=>{let{sectionId:n}=t,r=N({state:e},{sectionId:n});if(!r)return console.warn(`Section not found: ${n}`),e;let i=r.lines?.[0];if(!i)return console.warn(`Section ${n} has no lines`),e;let s=e.contexts[e.contexts.length-1];return s&&(s.pointers.read={sectionId:n,lineId:i.id}),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e},tt=e=>{let t=mn(e);return Ce(t,{selectPendingEffects:_n,selectSkipMode:Ye,selectAutoMode:In,selectDialogueUIHidden:Je,selectCurrentLocalizationPackageId:An,selectIsLineViewed:bn,selectIsResourceViewed:wn,selectNextLineConfig:En,selectSaveSlots:vn,selectSaveSlot:xn,selectCurrentPointer:K,selectSection:N,selectCurrentLine:$n,selectPresentationState:He,selectRenderState:Ln,startAutoMode:Ge,stopAutoMode:Xe,toggleAutoMode:Rn,startSkipMode:qe,stopSkipMode:Qe,toggleSkipMode:On,showDialogueUI:Ze,hideDialogueUI:et,toggleDialogueUI:Cn,setCurrentLocalizationPackageId:Tn,clearPendingEffects:kn,appendPendingEffect:Nn,addViewedLine:Pn,addViewedResource:Sn,setNextLineConfig:Dn,replaceSaveSlot:Bn,addToHistory:Vn,nextLine:Fn,nextLineFromCompleted:Mn,markLineCompleted:Wn,prevLine:zn,sectionTransition:Un},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function _e(e){let t,{handlePendingEffects:n}=e,r=({initialState:a})=>{t=tt(a),t.appendPendingEffect({name:"render"}),console.log("AAAAAAAAAAAAAAAAAAAAAAA"),l(),n(t.selectPendingEffects()),t.clearPendingEffects()},i=()=>t.selectRenderState(),s=(a,o)=>{console.log("RouteEngine handleAction",{actionType:a,payload:o}),console.log("_systemStore",t),console.log("found action handler",t[a]),t[a]&&(t[a](o),console.log("_systemStore.selectPendingEffects()",t.selectPendingEffects()),n(t.selectPendingEffects()),t.clearPendingEffects())},c=a=>{console.log("RouteEngine handleActions",a),Object.entries(a).forEach(([o,u])=>{s(o,u)})},l=()=>{let a=t.selectCurrentLine();console.log("BBBBBBBBBBBBBBBBBB line",a),a&&a.actions&&c(a.actions)};return{init:r,handleAction:s,handleActions:c,selectRenderState:i,handleLineActions:l}}var jr=_e;export{jr as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "route-engine-js",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/RouteEngine.js",
|
|
6
6
|
"exports": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"immer": "^10.1.1",
|
|
25
25
|
"jempl": "1.0.0",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
|
-
"puty": "^0.0.
|
|
27
|
+
"puty": "^0.0.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@vitest/coverage-v8": "^3.2.4",
|