route-engine-js 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RouteEngine.js +1 -1
- package/package.json +1 -1
package/dist/RouteEngine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var 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};
|
|
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 M=Object.getPrototypeOf;function B(e){return!!e&&!!e[L]}function S(e){return e?$e(e)||Array.isArray(e)||!!e[Ie]||!!e.constructor?.[Ie]||X(e)||q(e):!1}var it=Object.prototype.constructor.toString();function $e(e){if(!e||typeof e!="object")return!1;let t=M(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 xe(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 N(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=$e(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 a=i[s],l=r[a];l.writable===!1&&(l.writable=!0,l.configurable=!0),(l.get||l.set)&&(r[a]={configurable:!0,writable:!0,enumerable:l.enumerable,value:e[a]})}return Object.create(M(e),r)}else{let r=M(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)||B(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 be(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 Ae(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,a=!1;r.type_===3&&(s=new Set(i),i.clear(),a=!0),Y(s,(l,c)=>Ee(e,r,i,l,c,n,a)),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,a){if(B(i)){let l=s&&t&&t.type_!==3&&!ie(t.assigned_,r)?s.concat(r):void 0,c=J(e,i,l);if(xe(n,r,c),B(c))e.canAutoFreeze_=!1;else return}else a&&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:a,proxy:l}=Proxy.revocable(i,s);return r.draft_=l,r.revoke_=a,l}var fe={get(e,t){if(t===L)return e;let n=N(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 N(e)},ownKeys(e){return Reflect.ownKeys(N(e))},set(e,t,n){let r=Re(N(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let i=ne(N(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=N(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 M(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?N(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=M(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=M(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 a=this;return function(c=s,...o){return a.produce(c,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=Ae(this),a=le(t,void 0),l=!0;try{i=n(a),l=!1}finally{l?se(s):ae(s)}return be(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=[],a=[];D("Patches").generateReplacementPatches_(t,i,s,a),r(s,a)}return i}else O(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(a,...l)=>this.produceWithPatches(a,c=>t(c,...l));let r,i;return[this.produce(t,n,(a,l)=>{r=a,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),B(e)&&(e=pt(e));let t=Ae(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 be(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 B(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 B(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)=>{xe(n,r,Oe(i))}),t&&(t.finalized_=!1),n}var R=new dt,de=R.produce,Jn=R.produceWithPatches.bind(R),Hn=R.setAutoFreeze.bind(R),Gn=R.setUseStrictShallowCopy.bind(R),Xn=R.applyPatches.bind(R),qn=R.createDraft.bind(R),Qn=R.finishDraft.bind(R);var Ce=(e,t,n={})=>{let r=structuredClone(e),i={},s={},{transformSelectorFirstArgument:a=c=>c,transformActionFirstArgument:l=c=>c}=n;for(let[c,o]of Object.entries(t))c!=="createInitialState"&&(c.startsWith("select")?i[c]=(...u)=>o(a(r),...u):s[c]=(...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(a=>{t.forEach(l=>{l(s,a)})})})};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}}},bt=(e,t)=>{t.visual&&(e.visual=t.visual)},At=(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},$t=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},xt=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},Te=e=>Z(ht,[xt,yt,gt,_t,It,bt,mt,At,wt,Et,vt,$t])(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"}},x=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 Pe=(e,t,n=!1)=>{if(t===null)return new x(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new x(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return n?new x(`Cannot iterate over non-array value in loop '${e}' - got ${r} instead`):new x(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},Ne=(e,t)=>{let n=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new x(`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 a=b(e,{functions:r,partials:i},t,{});return a===void 0?{}:a},b=(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 Ve(e,t,n,r);case d.UNARY:return Me(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 Mt(e,t,n,r);case d.ARRAY:return Bt(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 a=n.trim();if(/^\d+$/.test(a))t.push({type:"index",value:parseInt(a,10)});else if(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'")){let l=a.slice(1,-1);t.push({type:"property",value:l})}else t.push({type:"property",value:a});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=[],a="",l=0;for(let c=0;c<e.length;c++){let o=e[c];o==="["?(l++,a+=o):o==="]"?(l--,a+=o):o==="."&&l===0?a&&(s.push(a),a=""):a+=o}a&&s.push(a),r=[];for(let c of s){let o=Rt(c.trim());r.push(...o)}Se.set(e,r)}let i=t;for(let s=0;s<r.length;s++){let a=r[s];if(a.type==="property"&&a.value in n){i=n[a.value];continue}if(i==null)return;(a.type==="property"||a.type==="index")&&(i=i[a.value])}return i},Ot=(e,t,n,r)=>{let i=[];for(let s of e)if(typeof s=="string")i.push(s);else{let a=b(s,t,n,r);i.push(a!=null?String(a):"")}return i.join("")},De=(e,t,n,r)=>{let i=t.functions||t,s=i[e.name];if(!s)throw Ne(e.name,i);let a=e.args.map(l=>b(l,t,n,r));return s(...a)},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 Ve(e,t,n,r);case d.UNARY:return Me(e,t,n,r);case d.FUNCTION:return De(e,t,n,r);default:return b(e,t,n,r)}},Ve=(e,t,n,r)=>{if(e.op===w.AND||e.op===w.OR){let a=F(e.left,t,n,r),l=F(e.right,t,n,r);switch(e.op){case w.AND:return a&&l;case w.OR:return a||l}}let i=b(e.left,t,n,r),s=b(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 x(`Arithmetic operations require numbers. Got ${typeof i} + ${typeof s}`);return i+s;case w.SUBTRACT:if(typeof i!="number"||typeof s!="number")throw new x(`Arithmetic operations require numbers. Got ${typeof i} - ${typeof s}`);return i-s;default:throw new Error(`Unknown binary operator: ${e.op}`)}},Me=(e,t,n,r)=>{let i=e.op===U.NOT?F(e.operand,t,n,r):b(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 a=e.bodies[0];if(a.type===d.OBJECT&&a.properties.length<=5){let l={};for(let c of a.properties){let o=c.parsedKey?b(c.parsedKey,t,n,r):c.key,u=c.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=b(p,t,n,r);f.push(h!=null?String(h):"")}l[o]=f.join("")}else l[o]=b(u,t,n,r)}return l}}else{let a=e.bodies[1];if(a.type===d.OBJECT&&a.properties.length<=5){let l={};for(let c of a.properties){let o=c.parsedKey?b(c.parsedKey,t,n,r):c.key,u=c.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=b(p,t,n,r);f.push(h!=null?String(h):"")}l[o]=f.join("")}else l[o]=b(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 a=e.conditions[s];if(a===null||F(a,t,n,r))return b(e.bodies[s],t,n,r)}return Be},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 a=i.substring(r.length+1);if(s.type===d.OBJECT&&s.properties.length<=5){for(let c of s.properties)if(c.parsedKey)return null;let l=[];for(let c=0;c<t.length;c++){let o=t[c];if(o[a]){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 A=_.substring(r.length+1),v=o[A];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},Pt=(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=[],a=!0;for(let l of n.properties){let c=l.key,o=l.value;if(o.type===d.LITERAL)s.push({key:c,type:"literal",value:o.value});else if(o.type===d.VARIABLE){let u=o.path;if(u===r)s.push({key:c,type:"item"});else if(u.startsWith(r+".")){let f=u.substring(r.length+1);if(!f.includes(".")&&!f.includes("["))s.push({key:c,type:"prop",prop:f});else{a=!1;break}}else{a=!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:c,type:"item_string"});else if(f.startsWith(r+".")){let p=f.substring(r.length+1);if(!p.includes(".")&&!p.includes("["))s.push({key:c,type:"prop_string",prop:p});else{a=!1;break}}else{a=!1;break}}else{a=!1;break}}else{a=!1;break}}if(a){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 c=0;c<t.length;c++){let o=t[c];l[c]={id:o.id,title:o.title!=null?String(o.title):"",completed:o.completed}}else for(let c=0;c<t.length;c++){let o=t[c],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[c]=u}return l}}return null},Nt=(e,t,n,r,i)=>{let s=[],a=e.body;if(a.type===d.OBJECT&&a.fast!==!1){let l=e.itemVar,c=e.indexVar;for(let o=0;o<i.length;o++){let u=i[o],f={},p={...r,[l]:u,...c&&{[c]: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}]`,...c&&{[c]:o}};for(let y of a.properties){let g=y.parsedKey?b(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(_===c)f[g]=o;else if(_.startsWith(l+".")){let A=_.substring(l.length+1);!A.includes(".")&&!A.includes("[")?f[g]=u[A]:f[g]=E(_,n,{...r,[l]:u,...c&&{[c]:o}})}else f[g]=E(_,n,{...r,[l]:u,...c&&{[c]:o}})}else if(m.type===d.INTERPOLATION){let _=[];for(let A of m.parts)if(typeof A=="string")_.push(A);else if(A.type===d.VARIABLE){let v=A.path,C;if(v===l)C=u;else if(v===c)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,...c&&{[c]:o}})}else C=E(v,n,{...r,[l]:u,...c&&{[c]:o}});_.push(C!=null?String(C):"")}else{let v={...r,[l]:u,...c&&{[c]:o}},C=b(A,t,n,v);_.push(C!=null?String(C):"")}f[g]=_.join("")}else{let _={...r,[l]:u,...c&&{[c]:o}};f[g]=b(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 a=s.bodies[0];if(a.type===d.OBJECT&&a.properties.length===2){let l=a.properties[0],c=a.properties[1];if(l.key==="id"&&l.value.type===d.VARIABLE&&l.value.path==="item.id"&&c.key==="$if item.highlighted"&&c.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=b(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 Pe(f,i,u)}if(!e.indexVar){let o=St(e,i,e.itemVar);if(o!==null)return o}if(!e.indexVar){let o=Pt(e,i);if(o!==null)return o}let s=Nt(e,t,n,r,i);if(s!==null)return s;let a=[],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 c=!1;e.body.type===d.ARRAY&&(e.body.items.length<=1?c=!1:c=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=b(e.body,t,n,u);if(Array.isArray(f)&&f.length===1&&!c){let p=f[0];a.push(p===void 0?{}:p)}else a.push(f===void 0?{}:f)}return a},Vt=(e,t,n,r)=>{if(e.whenCondition)return null;if(e.properties.length===1){let i=e.properties[0],s=i.parsedKey?b(i.parsedKey,t,n,r):i.key,a=i.value;if(a.type===d.OBJECT&&a.properties.length<=10&&!a.whenCondition){let l={},c={},o=!0;for(let u of a.properties){let f=u.parsedKey?b(u.parsedKey,t,n,r):u.key,p=u.value;if(p.type===d.LITERAL)c[f]=p.value;else if(p.type===d.VARIABLE)c[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;c[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 A of m.parts)if(typeof A=="string")_.push(A);else if(A.type===d.VARIABLE){let v=E(A.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;c[f]=h}else{o=!1;break}}if(o)return l[s]=c,l}}return null},Mt=(e,t,n,r)=>{let i=t.functions||t;if(e.whenCondition&&!F(e.whenCondition,i,n,r))return;let s=Vt(e,t,n,r);if(s!==null)return s;if(e.fast){let o={};for(let u of e.properties){let f=u.parsedKey?b(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=b(y,t,n,r);h.push(g!=null?String(g):"")}o[f]=h.join("")}else o[f]=b(p,t,n,r)}return o}let a={},l=null,c=!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 ")){c=!0;break}for(let o of e.properties)if(o.key.startsWith("$if ")||o.key.match(/^\$if\s+\w+.*:?$/)){let u=b(o.value,t,n,r);if(!c&&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(a,u)}else if(o.key.startsWith("$for ")){if(e.properties.length===1)return b(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=b(f.value,t,n,r);p!==void 0&&(a[o.key]=p)}else{let p=b(o.value,t,n,r);p!==void 0&&(a[o.key]=p)}}else{let f=o.parsedKey?b(o.parsedKey,t,n,r):o.key,p=b(o.value,t,n,r);p!==void 0&&(a[f]=p)}}return a},Be={},Bt=(e,t,n,r)=>{let i=[];for(let s of e.items)if(s.type===d.LOOP){let a=b(s,t,n,r);Array.isArray(a)&&s.flatten!==!1?i.push(...a):i.push(a)}else{let a=b(s,t,n,r);a!==Be&&a!==void 0&&i.push(a)}return i},Ft=(e,t,n,r)=>{let{name:i,data:s,whenCondition:a}=e,l=t.partials||{},c=t.functions||t;if(a&&!F(a,c,n,r))return;if(!l[i])throw new x(`Partial '${i}' is not defined`);let o=r._partialStack||[];if(o.includes(i))throw new x(`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=b(s,t,n,r);f={...f,...h}}return b(u,t,f,p)},Wt=(e,t,n,r)=>{let{path:i}=e,s=i.split("."),a=s[0],l=s.slice(1);if(!r||!(a in r))throw new x(`Path reference '#{${i}}' refers to '${a}' which is not a loop variable in the current scope`);if(r.__paths__||(r.__paths__={}),!(a in r.__paths__))throw new x(`Path reference '#{${i}}' cannot be resolved - path tracking may not be initialized properly`);let c=r.__paths__[a];if(typeof c=="number"){if(l.length>0)throw new x(`Path reference '#{${i}}' - cannot access properties on index variable '${a}'`);return String(c)}return l.length>0&&(c+="."+l.join(".")),c},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 a=0;a<e.length;a++){let l=e[a],c=a>0?e[a-1]:"";!i&&(l==='"'||l==="'")?(i=!0,s=l,n+=l):i&&l===s&&c!=="\\"?(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,a=null;for(let{op:l,type:c}of i){let o=0;for(;o<r.length;){let u=V(r.substring(o),l);if(u===-1)break;let f=o+u;f>s&&(s=f,a={op:l,type:c}),o=f+l.length}}if(s!==-1)try{return $(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)],a=[...i.map(o=>({match:o,type:"variable"})),...s.map(o=>({match:o,type:"pathref"}))].sort((o,u)=>o.match.index-u.match.index);if(a.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(a.length===1&&a[0].match[0]===n&&r.length===0){let{match:o,type:u}=a[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=[],c=0;for(let{match:o,type:u}of a){let[f,p]=o,h=o.index;if(h>c){let y=n.substring(c,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}c=h+f.length}if(c<n.length){let o=n.substring(c);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 P=(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 c=Gt(s),o=Object.keys(c);if(o.length===1&&/^\$for(?::\w+)?\s/.test(o[0])){let u=Ue(o[0],c[o[0]],t,!0);n.push(u),r=!0;continue}}catch(c){throw c instanceof I?c:new I(c.message)}let l=Object.keys(s);if(l.length===1&&/^\$for(?::\w+)?\s/.test(l[0])){let c=Ue(l[0],s[l[0]],t);n.push(c),r=!0;continue}}let a=P(s,t);n.push(a),(a.type===d.FUNCTION||a.type===d.CONDITIONAL||a.type===d.LOOP||a.type===d.PARTIAL||a.type===d.OBJECT&&!a.fast||a.type===d.ARRAY&&!a.fast)&&(r=!0)}return{type:d.ARRAY,items:n,fast:!r}},qt=(e,t)=>{let n=[],r=!1,i=null,s=Object.entries(e),a=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 c=["$if","$elif","$else","$for"],o=[];for(let[_]of s)for(let A of c)if(_===A||_.startsWith(A+" ")||_.startsWith(A+"#")){o.push(A);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[_,A]of Object.entries(p)){let v=_;(_.startsWith("\\$")||_.startsWith("$$"))&&(v=_.slice(1)),h[v]=A,y=!0}let g=null;if(y&&(g=P(h,t),g.type===d.OBJECT)){let _=!1;for(let A of g.properties)if(A.value.type===d.VARIABLE||A.value.type===d.INTERPOLATION||A.value.type===d.FUNCTION||A.value.type===d.CONDITIONAL||A.value.type===d.OBJECT&&!A.value.fast||A.value.type===d.ARRAY&&!A.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'");_=$(f,t)}else _={type:d.LITERAL,value:f};m.whenCondition=_}return m}for(let[c,o]of s)if(c==="$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=$(u,t),r=!0}else if(c.startsWith("$when#")||c.startsWith("$when "))throw new I("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;a<s.length;){let[c,o]=s[a];if(c==="$when"){a++;continue}if(c==="$each")throw new I("$each can only be used inside arrays");if(c.startsWith("$if ")||c.match(/^\$if#\w+\s/)||c.match(/^\$if\s+\w+.*:$/)){let u=Qt(s,a,t);n.push({key:c,value:u.node}),r=!0,a=u.nextIndex}else if(/^\$for(?::\w+)?\s/.test(c)){let u=c.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(c.startsWith("$elif ")||c.startsWith("$else"))throw new I(`'${c.split(" ")[0]}' without matching '$if'`);if(c==="$if"||c==="$if:")throw new I("Missing condition expression after '$if'");{let u=P(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(c,t),p={key:c,value:u};(f.type!==d.LITERAL||f.value!==c)&&(p.parsedKey=f),n.push(p),a++}}}let l={type:d.OBJECT,properties:n,fast:!r};return i&&(l.whenCondition=i),l},Qt=(e,t,n={})=>{let r=[],i=[],s=t,[a,l]=e[s],c=null,o;if(a.startsWith("$if#")){let f=a.match(/^\$if#(\w+)\s+(.+)$/);if(f)c=f[1],o=f[2];else throw new I(`Invalid conditional syntax: ${a}`)}else o=a.substring(4),o.endsWith(":")&&(o=o.slice(0,-1).trim());pe(o);let u=$(o,n);for(r.push(u),i.push(P(l,n)),s++;s<e.length;){let[f,p]=e[s],h=!1,y;if(c?f.startsWith(`$elif#${c} `)?(y=f.substring(`$elif#${c} `.length),y.endsWith(":")&&(y=y.slice(0,-1).trim()),h=!0):(f===`$else#${c}`||f===`$else#${c}:`)&&(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=$(y,n);r.push(g)}if(i.push(P(p,n)),s++,y===null)break}else break}return{node:{type:d.CONDITIONAL,conditions:r,bodies:i,id:c},nextIndex:s}},$=(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 $(o,t)}let n=V(e,"||");if(n!==-1)return{type:d.BINARY,op:w.OR,left:$(e.substring(0,n).trim(),t),right:$(e.substring(n+2).trim(),t)};let r=V(e,"&&");if(r!==-1)return{type:d.BINARY,op:w.AND,left:$(e.substring(0,r).trim(),t),right:$(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=V(e,o);if(f!==-1)return{type:d.BINARY,op:u,left:$(e.substring(0,f).trim(),t),right:$(e.substring(f+o.length).trim(),t)}}let s=-1,a=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=V(e.substring(f),o);if(p===-1)break;let h=f+p;h>s&&(s=h,a={op:o,type:u}),f=h+o.length}}if(s!==-1&&a)return{type:d.BINARY,op:a.type,left:$(e.substring(0,s).trim(),t),right:$(e.substring(s+a.op.length).trim(),t)};let c=[" * "," / "," % "];for(let o of c)if(V(e,o)!==-1)throw new I(`Arithmetic operations are not allowed in conditionals: "${o}"`);return e.startsWith("!")?{type:d.UNARY,op:U.NOT,operand:$(e.substring(1).trim(),t)}:je(e,t)},V=(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 a=s[1],l=s[2].trim();en(l,r);let c=l.match(/^(.+?)\s+in\s+(.+)$/);if(!c){let m=r?"$each":"$for";throw new I(`Invalid loop syntax - missing 'in' keyword (got: '${m} ${l}')`)}let o=c[1].trim(),u=c[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=P(t,n);return{type:d.LOOP,itemVar:f,indexVar:p,iterable:y,body:g,flatten:a!=="nested"}};var tn=(e,t={})=>{let{functions:n={}}=t;return P(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},a=ee(e,{functions:s}),l={};for(let[c,o]of Object.entries(i))l[c]=ee(o,{functions:s});return he(a,t,{functions:s,partials:l})},k=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:a})=>{let{elements:l}=e,c=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&&c.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&&c.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&&c.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 a=t.character.items||[];for(let l of a){let{transformId:c,sprites:o}=l;if(l.animations&&l.animations.out&&!o&&!c){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||!c){console.warn("Character item missing sprites or transformId:",l);continue}let u=o.map(({resourceId:h})=>h),f=n.transforms[c];if(!f){console.warn("Transform not found:",c);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 a=t.visual.items;for(let l of a){if(l.resourceId){let c=n.images[l.resourceId];if(c){let o=n.transforms[l.transformId];s.children.push({id:`visual-${l.id}`,type:"sprite",url:c.fileId,width:c.width,height:c.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 c=l.animations.in.animationId||l.animations.in,o=n?.animations[c];o&&i.push({id:`${l.id}-animation`,type:"tween",targetId:`visual-${l.id}`,properties:o.properties})}if(l.animations.out){let c=l.animations.out.animationId||l.animations.out,o=n?.animations[c];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:a,variables:l})=>{let{elements:c}=e;if(!t.dialogue||r)return e;let o=c.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:a},g=k(h,y,{functions:me});g=k(g,{l10n:a});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 a={elements:s.elements},c=k(a,{choice:{items:t.choice.items}})?.elements;if(Array.isArray(c))for(let o of c)i.children.push(structuredClone(o));else c&&i.children.push(structuredClone(c))}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 a=n.audio[t.bgm.audioId];if(!a)return e;i.push({id:"bgm",type:"sound",url:a.fileId,loop:a.loop??!0,volume:a.volume??.5,delay:a.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 a=n.audio?.[s.audioId];a&&r.push({id:s.id,type:"sound",url:a.fileId,loop:s.loop??a.loop??!0,volume:s.volume??a.volume??.5,delay:s.delay??a.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:a}=t.voice;return r.push({id:`voice-${i}`,type:"sound",url:i,volume:s??.5,loop:a??!1}),e},yn=(e,{presentationState:t,resources:n={},variables:r,autoMode:i,skipMode:s,currentLocalizationPackageId:a})=>{let{elements:l}=e,c=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=>{c.push(g)});let f={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:u.elements||[]},h=k(f,{variables:r,autoMode:i,skipMode:s,currentLocalizationPackageId:a},{functions:me});h=k(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:a}=e,l=e.animations||[],c=[];return c&&c.length>0&&c.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=k(p,{variables:n,autoMode:r,skipMode:i,currentLocalizationPackageId:s},{functions:me});y=k(y,{i18n:{}});let g=m=>{let _={...m};if(m.url&&m.url.startsWith("file:")){let A=m.url.replace("file:","");_.url=resolveFile(A)}return m.children&&Array.isArray(m.children)&&(_.children=m.children.map(g)),_};a.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,bn=({state:e})=>e.global.currentLocalizationPackageId,An=({state:e},t)=>{let{sectionId:n,lineId:r}=t,i=e.global.viewedRegistry.sections.find(c=>c.sectionId===n);if(!i)return!1;if(i.lastLineId===void 0||r===void 0)return!0;let s=T({state:e},{sectionId:n});if(!s||!s.lines||!Array.isArray(s.lines))return!1;let a=s.lines.findIndex(c=>c.id===i.lastLineId),l=s.lines.findIndex(c=>c.id===r);return a===-1||l===-1?i.lastLineId===r:l<a},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,$n=({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}},T=({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]}},xn=({state:e})=>{let t=K({state:e});if(!t?.pointer)return;let{sectionId:n,lineId:r}=t.pointer,i=T({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=T({state:e},{sectionId:t})?.lines||[],s=i.findIndex(o=>o.id===n),a=i.slice(0,s+1);console.log("currentLines",a);let l=a.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.l10n.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),Pn=({state:e},t)=>(e.global.pendingEffects.push(t),e),Nn=({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},Vn=({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},Mn=({state:e},t)=>{let{projectData:n}=t;return e.projectData=n,e.global.pendingEffects.push({name:"render"}),e},Bn=({state:e},t)=>{let{sectionId:n,lineId:r}=t;if(!r)return console.warn("jumpToLine requires lineId parameter"),e;let i=e.contexts[e.contexts.length-1];if(!i)return console.warn("No context available for jumpToLine"),e;let s=n||i.pointers.read?.sectionId;if(n&&!T({state:e},{sectionId:n}))return console.warn(`Section not found: ${n}`),e;let a=T({state:e},{sectionId:s});return!a?.lines||!Array.isArray(a.lines)?(console.warn(`Section ${s} has no lines`),e):a.lines.find(c=>c.id===r)?(i.pointers.read={sectionId:s,lineId:r},e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e):(console.warn(`Line not found: ${r} in section ${s}`),e)},Fn=({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},Wn=({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=T({state:e},{sectionId:n})?.lines||[],a=i.findIndex(l=>l.id===t?.lineId)+1;if(a<i.length){let l=i[a],c=e.contexts[e.contexts.length-1];c&&(c.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},zn=({state:e})=>{if(!e.global.nextLineConfig.manual.enabled)return e;let t=K({state:e})?.pointer,n=t?.sectionId,i=T({state:e},{sectionId:n})?.lines||[],a=i.findIndex(l=>l.id===t?.lineId)+1;if(a<i.length){let l=i[a],c=e.contexts[e.contexts.length-1];c&&(c.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},Un=({state:e})=>(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e),jn=({state:e},t)=>{let{sectionId:n}=t,r=T({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 a=s.pointers.history||s.pointers.read;if(s.currentPointerMode!=="history"||!s.pointers.history){if(!a)return e;s.currentPointerMode="history",s.pointers.history={sectionId:n,lineId:a?.lineId};let u=i.findIndex(f=>f.id===a.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 c=i.findIndex(o=>o.id===s.pointers.history.lineId)-1;if(c>=0&&c<i.length){let o=i[c];s.pointers.history={sectionId:n,lineId:o.id},e.global.pendingEffects.push({name:"render"})}return e},Kn=({state:e},t)=>{let{sectionId:n}=t,r=T({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:bn,selectIsLineViewed:An,selectIsResourceViewed:wn,selectNextLineConfig:En,selectSaveSlots:vn,selectSaveSlot:$n,selectCurrentPointer:K,selectSection:T,selectCurrentLine:xn,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:Pn,addViewedLine:Nn,addViewedResource:Sn,setNextLineConfig:Dn,replaceSaveSlot:Vn,updateProjectData:Mn,sectionTransition:Kn,jumpToLine:Bn,addToHistory:Fn,nextLine:zn,nextLineFromCompleted:Wn,markLineCompleted:Un,prevLine:jn},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function _e(e){let t,{handlePendingEffects:n}=e,r=({initialState:c})=>{t=tt(c),t.appendPendingEffect({name:"render"}),l(),n(t.selectPendingEffects()),t.clearPendingEffects()},i=()=>t.selectRenderState(),s=(c,o)=>{t[c]&&(t[c](o),n(t.selectPendingEffects()),t.clearPendingEffects())},a=c=>{Object.entries(c).forEach(([o,u])=>{s(o,u)})},l=()=>{let c=t.selectCurrentLine();c&&c.actions&&a(c.actions)};return{init:r,handleAction:s,handleActions:a,selectRenderState:i,handleLineActions:l}}var Vr=_e;export{Vr as default};
|