route-engine-js 0.1.13 → 0.1.14
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 pt=Object.defineProperty;var ht=(e,t)=>{for(var n in t)pt(e,n,{get:t[n],enumerable:!0})};var Oe=Symbol.for("immer-nothing"),xe=Symbol.for("immer-draftable"),C=Symbol.for("immer-state");function O(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var B=Object.getPrototypeOf;function F(e){return!!e&&!!e[C]}function T(e){return e?Re(e)||Array.isArray(e)||!!e[xe]||!!e.constructor?.[xe]||G(e)||q(e):!1}var gt=Object.prototype.constructor.toString();function Re(e){if(!e||typeof e!="object")return!1;let t=B(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)===gt}function H(e,t){X(e)===0?Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function X(e){let t=e[C];return t?t.type_:Array.isArray(e)?1:G(e)?2:q(e)?3:0}function ie(e,t){return X(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Se(e,t,n){let r=X(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function yt(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function G(e){return e instanceof Map}function q(e){return e instanceof Set}function P(e){return e.copy_||e.base_}function se(e,t){if(G(e))return new Map(e);if(q(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=Re(e);if(t===!0||t==="class_only"&&!n){let r=Object.getOwnPropertyDescriptors(e);delete r[C];let o=Reflect.ownKeys(r);for(let i=0;i<o.length;i++){let l=o[i],a=r[l];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(r[l]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[l]})}return Object.create(B(e),r)}else{let r=B(e);if(r!==null&&n)return{...e};let o=Object.create(r);return Object.assign(o,e)}}function fe(e,t=!1){return Q(e)||F(e)||!T(e)||(X(e)>1&&(e.set=e.add=e.clear=e.delete=mt),Object.freeze(e),t&&Object.entries(e).forEach(([n,r])=>fe(r,!0))),e}function mt(){O(2)}function Q(e){return Object.isFrozen(e)}var bt={};function V(e){let t=bt[e];return t||O(0,e),t}var U;function Ne(){return U}function It(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Le(e,t){t&&(V("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function ae(e){le(e),e.drafts_.forEach(wt),e.drafts_=null}function le(e){e===U&&(U=e.parent_)}function $e(e){return U=It(U,e)}function wt(e){let t=e[C];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Ce(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];return e!==void 0&&e!==n?(n[C].modified_&&(ae(t),O(4)),T(e)&&(e=K(t,e),t.parent_||J(t,e)),t.patches_&&V("Patches").generateReplacementPatches_(n[C].base_,e,t.patches_,t.inversePatches_)):e=K(t,n,[]),ae(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Oe?e:void 0}function K(e,t,n){if(Q(t))return t;let r=t[C];if(!r)return H(t,(o,i)=>ke(e,r,t,o,i,n)),t;if(r.scope_!==e)return t;if(!r.modified_)return J(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;let o=r.copy_,i=o,l=!1;r.type_===3&&(i=new Set(o),o.clear(),l=!0),H(i,(a,c)=>ke(e,r,o,a,c,n,l)),J(e,o,!1),n&&e.patches_&&V("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function ke(e,t,n,r,o,i,l){if(F(o)){let a=i&&t&&t.type_!==3&&!ie(t.assigned_,r)?i.concat(r):void 0,c=K(e,o,a);if(Se(n,r,c),F(c))e.canAutoFreeze_=!1;else return}else l&&n.add(o);if(T(o)&&!Q(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;K(e,o),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&Object.prototype.propertyIsEnumerable.call(n,r)&&J(e,o)}}function J(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&fe(t,n)}function _t(e,t){let n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:Ne(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=r,i=de;n&&(o=[r],i=W);let{revoke:l,proxy:a}=Proxy.revocable(o,i);return r.draft_=a,r.revoke_=l,a}var de={get(e,t){if(t===C)return e;let n=P(e);if(!ie(n,t))return Et(e,n,t);let r=n[t];return e.finalized_||!T(r)?r:r===re(e.base_,t)?(oe(e),e.copy_[t]=ue(r,e)):r},has(e,t){return t in P(e)},ownKeys(e){return Reflect.ownKeys(P(e))},set(e,t,n){let r=Pe(P(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let o=re(P(e),t),i=o?.[C];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(yt(n,o)&&(n!==void 0||ie(e.base_,t)))return!0;oe(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 re(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,oe(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 B(e.base_)},setPrototypeOf(){O(12)}},W={};H(de,(e,t)=>{W[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});W.deleteProperty=function(e,t){return W.set.call(this,e,t,void 0)};W.set=function(e,t,n){return de.set.call(this,e[0],t,n,e[0])};function re(e,t){let n=e[C];return(n?P(n):e)[t]}function Et(e,t,n){let r=Pe(t,n);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}function Pe(e,t){if(!(t in e))return;let n=B(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=B(n)}}function ce(e){e.modified_||(e.modified_=!0,e.parent_&&ce(e.parent_))}function oe(e){e.copy_||(e.copy_=se(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var vt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){let i=n;n=t;let l=this;return function(c=i,...s){return l.produce(c,f=>n.call(this,f,...s))}}typeof n!="function"&&O(6),r!==void 0&&typeof r!="function"&&O(7);let o;if(T(t)){let i=$e(this),l=ue(t,void 0),a=!0;try{o=n(l),a=!1}finally{a?ae(i):le(i)}return Le(i,r),Ce(o,i)}else if(!t||typeof t!="object"){if(o=n(t),o===void 0&&(o=t),o===Oe&&(o=void 0),this.autoFreeze_&&fe(o,!0),r){let i=[],l=[];V("Patches").generateReplacementPatches_(t,o,i,l),r(i,l)}return o}else O(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(l,...a)=>this.produceWithPatches(l,c=>t(c,...a));let r,o;return[this.produce(t,n,(l,a)=>{r=l,o=a}),r,o]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){T(e)||O(8),F(e)&&(e=At(e));let t=$e(this),n=ue(e,void 0);return n[C].isManual_=!0,le(t),n}finishDraft(e,t){let n=e&&e[C];(!n||!n.isManual_)&&O(9);let{scope_:r}=n;return Le(r,t),Ce(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 o=t[n];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}n>-1&&(t=t.slice(n+1));let r=V("Patches").applyPatches_;return F(e)?r(e,t):this.produce(e,o=>r(o,t))}};function ue(e,t){let n=G(e)?V("MapSet").proxyMap_(e,t):q(e)?V("MapSet").proxySet_(e,t):_t(e,t);return(t?t.scope_:Ne()).drafts_.push(n),n}function At(e){return F(e)||O(10,e),Te(e)}function Te(e){if(!T(e)||Q(e))return e;let t=e[C],n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=se(e,t.scope_.immer_.useStrictShallowCopy_)}else n=se(e,!0);return H(n,(r,o)=>{Se(n,r,Te(o))}),t&&(t.finalized_=!1),n}var k=new vt,pe=k.produce,Tr=k.produceWithPatches.bind(k),Vr=k.setAutoFreeze.bind(k),Dr=k.setUseStrictShallowCopy.bind(k),Mr=k.applyPatches.bind(k),Br=k.createDraft.bind(k),Fr=k.finishDraft.bind(k);var Ve=(e,t,n={})=>{let r=structuredClone(e),o={},i={},{transformSelectorFirstArgument:l=c=>c,transformActionFirstArgument:a=c=>c}=n;for(let[c,s]of Object.entries(t))c!=="createInitialState"&&(c.startsWith("select")?o[c]=(...f)=>s(l(r),...f):i[c]=(...f)=>{r=pe(r,d=>s(a(d),...f))});return{...o,...i}},Z=(e,t)=>n=>{let r=e(),o=Array.isArray(n)?n:[n];return pe(r,i=>{o.forEach(l=>{t.forEach(a=>{a(i,l)})})})};var xt=(e,t)=>{if(e.default!==void 0)return e.default;let n=["number","boolean","string","object"];if(!n.includes(e.type))throw new Error(`Invalid variable type: ${e.type} for variable ${t}. Expected one of: ${n.join(", ")}`);switch(e.type){case"number":return 0;case"boolean":return!1;case"string":return"";case"object":return{}}},De=e=>{let t={},n={};return e.resources?.variables?(Object.entries(e.resources.variables).forEach(([r,o])=>{let i=xt(o,r);o.scope==="context"?t[r]=i:n[r]=i}),{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}):{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}},Me=(e,t)=>{let n=["context","global-device","global-account"];if(!e)throw new Error(`Variable scope is required for variable: ${t}`);if(!n.includes(e))throw new Error(`Invalid variable scope: ${e} for variable ${t}. Expected one of: ${n.join(", ")}`)},Be=(e,t,n)=>{let r={number:["set","increment","decrement","multiply","divide"],boolean:["set","toggle"],string:["set"],object:["set"]},o=r[e];if(!o)throw new Error(`Unknown variable type: ${e} for variable ${n}`);if(!Object.values(r).flat().includes(t))throw new Error(`Unknown operation: ${t}`);if(!o.includes(t))throw new Error(`Operation "${t}" is not valid for variable "${n}" of type "${e}". Valid operations: ${o.join(", ")}`)},Fe=(e,t,n)=>{switch(t){case"set":return n;case"multiply":return(e??1)*n;case"divide":return(e??0)/n;case"increment":return(e??0)+(n??1);case"decrement":return(e??0)-(n??1);case"toggle":return!e;default:throw new Error(`Unknown operation: ${t}`)}},he=(e,t,n)=>Object.fromEntries(Object.entries(e).filter(([r])=>t?.[r]?.scope===n)),je=(e,t="DD/MM/YYYY - HH:mm")=>{if(!e)return"";let n=new Date(e),r=o=>String(o).padStart(2,"0");return t.replace("DD",r(n.getDate())).replace("MM",r(n.getMonth()+1)).replace("YYYY",n.getFullYear()).replace("YY",String(n.getFullYear()).slice(-2)).replace("HH",r(n.getHours())).replace("mm",r(n.getMinutes())).replace("ss",r(n.getSeconds()))};var Lt=()=>({}),$t=(e,t)=>{t.base&&(e.base={...t.base})},Ct=(e,t)=>{t.background&&(e.background={...t.background})},kt=(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),delete e.dialogue.characterId,t.dialogue.characterId&&(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}))},Ot=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},Rt=(e,t)=>{if(t.bgm){if(!t.bgm.resourceId){e.bgm=void 0;return}e.bgm={...t.bgm,loop:t.bgm.loop||t.bgm.loop===void 0}}},St=(e,t)=>{t.visual&&(e.visual=t.visual)},Nt=(e,t)=>{t.character&&(t.character.items||delete e.character,e.character=structuredClone(t.character))},Pt=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},Tt=(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},Dt=(e,t)=>{t.keyboard&&(e.keyboard=t.keyboard)},Mt=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},Bt=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},ge=e=>Z(Lt,[Bt,$t,Ct,Ot,Rt,St,kt,Nt,Pt,Tt,Vt,Dt,Mt])(e);var p={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},E={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},z={NOT:0};var b=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},L=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var ye=e=>{if(!e||e.trim()==="")throw new b("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let n=e.includes("===")?"==":"!=";throw new b(`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 b(`Incomplete comparison expression - missing right operand (got: '${e}')`)},Ue=e=>{if(e.trim().endsWith(" in"))throw new b(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new b(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,n]=e.split(" in ");if(!n||n.trim()==="")throw new b(`Missing iterable expression after 'in' (got: '$for ${e}')`);let r=t.includes(",")?t.split(",").map(o=>o.trim()):[t.trim()];for(let o of r){if(!o)throw new b(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(o))throw new b(`Invalid loop syntax (got: '$for ${e}')`)}};var We=(e,t,n=!1)=>{if(t===null)return new L(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new L(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return n?new L(`Cannot iterate over non-array value in loop '${e}' - got ${r} instead`):new L(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},ze=(e,t)=>{let n=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new L(`Unknown function '${e}' (${n})`)};var Ft=(e,t,n={})=>{let r={},o={};n&&typeof n=="object"&&(n.functions!==void 0||n.partials!==void 0?(r=n.functions||{},o=n.partials||{}):typeof n=="object"&&(r=n));let l=_(e,{functions:r,partials:o},t,{});return l===void 0?{}:l},_=(e,t,n,r)=>{let o=t.functions||t;if(e.var&&!e.type)return A(e.var,n,r);if(e.type===p.LITERAL)return e.value;if(e.type===p.VARIABLE)return A(e.path,n,r);if(e.type===p.INTERPOLATION)return Ut(e.parts,t,n,r);switch(e.type){case p.FUNCTION:return He(e,t,n,r);case p.BINARY:return Ke(e,t,n,r);case p.UNARY:return Je(e,t,n,r);case p.CONDITIONAL:return zt(e,t,n,r);case p.LOOP:return Xt(e,t,n,r);case p.OBJECT:return qt(e,t,n,r);case p.ARRAY:return Qt(e,t,n,r);case p.PARTIAL:return Zt(e,t,n,r);case p.PATH_REFERENCE:return en(e,t,n,r);default:throw new Error(`Unknown node type: ${e.type}`)}},Ye=new Map,jt=e=>{let t=[],n="",r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(i==="[")n&&(t.push({type:"property",value:n}),n=""),r=!0;else if(i==="]"){if(r&&n){let l=n.trim();if(/^\d+$/.test(l))t.push({type:"index",value:parseInt(l,10)});else if(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'")){let a=l.slice(1,-1);t.push({type:"property",value:a})}else t.push({type:"property",value:l});n=""}r=!1}else n+=i}return n&&t.push({type:"property",value:n}),t},A=(e,t,n)=>{if(!e)return;if(e in n)return n[e];let r=Ye.get(e);if(!r){let i=[],l="",a=0;for(let c=0;c<e.length;c++){let s=e[c];s==="["?(a++,l+=s):s==="]"?(a--,l+=s):s==="."&&a===0?l&&(i.push(l),l=""):l+=s}l&&i.push(l),r=[];for(let c of i){let s=jt(c.trim());r.push(...s)}Ye.set(e,r)}let o=t;for(let i=0;i<r.length;i++){let l=r[i];if(l.type==="property"&&l.value in n){o=n[l.value];continue}if(o==null)return;(l.type==="property"||l.type==="index")&&(o=o[l.value])}return o},Ut=(e,t,n,r)=>{let o=[];for(let i of e)if(typeof i=="string")o.push(i);else{let l=_(i,t,n,r);o.push(l!=null?String(l):"")}return o.join("")},He=(e,t,n,r)=>{let o=t.functions||t,i=o[e.name];if(!i)throw ze(e.name,o);let l=e.args.map(a=>_(a,t,n,r));return i(...l)},j=(e,t,n,r)=>{if(e.var&&!e.type)return A(e.var,n,r);switch(e.type){case p.VARIABLE:return A(e.path,n,r);case p.LITERAL:return e.value;case p.BINARY:return Ke(e,t,n,r);case p.UNARY:return Je(e,t,n,r);case p.FUNCTION:return He(e,t,n,r);default:return _(e,t,n,r)}},Ke=(e,t,n,r)=>{if(e.op===E.AND||e.op===E.OR){let l=j(e.left,t,n,r),a=j(e.right,t,n,r);switch(e.op){case E.AND:return l&&a;case E.OR:return l||a}}let o=_(e.left,t,n,r),i=_(e.right,t,n,r);switch(e.op){case E.EQ:return o==i;case E.NEQ:return o!=i;case E.GT:return o>i;case E.LT:return o<i;case E.GTE:return o>=i;case E.LTE:return o<=i;case E.IN:return Array.isArray(i)?i.includes(o):!1;case E.ADD:if(typeof o!="number"||typeof i!="number")throw new L(`Arithmetic operations require numbers. Got ${typeof o} + ${typeof i}`);return o+i;case E.SUBTRACT:if(typeof o!="number"||typeof i!="number")throw new L(`Arithmetic operations require numbers. Got ${typeof o} - ${typeof i}`);return o-i;default:throw new Error(`Unknown binary operator: ${e.op}`)}},Je=(e,t,n,r)=>{let o=e.op===z.NOT?j(e.operand,t,n,r):_(e.operand,t,n,r);if(e.op===z.NOT)return!o;throw new Error(`Unknown unary operator: ${e.op}`)},Wt=(e,t,n,r)=>{if(e.conditions.length===2&&e.conditions[1]===null){let o=e.conditions[0];if(o.type===p.VARIABLE)if(A(o.path,n,r)){let l=e.bodies[0];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?_(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=A(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=A(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=_(f,t,n,r)}return a}}else{let l=e.bodies[1];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?_(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=A(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=A(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=_(f,t,n,r)}return a}}}return null},zt=(e,t,n,r)=>{let o=Wt(e,t,n,r);if(o!==null)return o;for(let i=0;i<e.conditions.length;i++){let l=e.conditions[i];if(l===null||j(l,t,n,r))return _(e.bodies[i],t,n,r)}return Xe},Yt=(e,t)=>{let n=e.body,r=e.itemVar;if(n.type===p.CONDITIONAL&&n.conditions.length===1&&n.conditions[0].type===p.VARIABLE){let o=n.conditions[0].path,i=n.bodies[0];if(o.startsWith(r+".")){let l=o.substring(r.length+1);if(i.type===p.OBJECT&&i.properties.length<=5){for(let c of i.properties)if(c.parsedKey)return null;let a=[];for(let c=0;c<t.length;c++){let s=t[c];if(s[l]){let f={};for(let u of i.properties){let d=u.key,h=u.value;if(h.type===p.LITERAL)f[d]=h.value;else if(h.type===p.VARIABLE){let g=h.path;if(g===r)f[d]=s;else if(g.startsWith(r+".")){let y=g.substring(r.length+1);f[d]=s[y]}else return null}else if(h.type===p.INTERPOLATION){let g=[],y=!0;for(let I of h.parts)if(typeof I=="string")g.push(I);else if(I.type===p.VARIABLE){let m=I.path;if(m===r)g.push(s!=null?String(s):"");else if(m.startsWith(r+".")){let w=m.substring(r.length+1),v=s[w];g.push(v!=null?String(v):"")}else{y=!1;break}}else{y=!1;break}if(!y)return null;f[d]=g.join("")}else return null}a.push(f)}}return a}}}return null},Ht=(e,t)=>{let n=e.body,r=e.itemVar,o=Yt(e,t);if(o!==null)return o;if(n.type===p.OBJECT&&n.properties.length<=5&&!n.whenCondition){for(let a of n.properties)if(a.parsedKey)return null;let i=[],l=!0;for(let a of n.properties){let c=a.key,s=a.value;if(s.type===p.LITERAL)i.push({key:c,type:"literal",value:s.value});else if(s.type===p.VARIABLE){let f=s.path;if(f===r)i.push({key:c,type:"item"});else if(f.startsWith(r+".")){let u=f.substring(r.length+1);if(!u.includes(".")&&!u.includes("["))i.push({key:c,type:"prop",prop:u});else{l=!1;break}}else{l=!1;break}}else if(s.type===p.INTERPOLATION&&s.parts.length===1){let f=s.parts[0];if(f.type===p.VARIABLE){let u=f.path;if(u===r)i.push({key:c,type:"item_string"});else if(u.startsWith(r+".")){let d=u.substring(r.length+1);if(!d.includes(".")&&!d.includes("["))i.push({key:c,type:"prop_string",prop:d});else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}if(l){let a=new Array(t.length);if(i.length===3&&i[0].type==="prop"&&i[0].key==="id"&&i[1].type==="prop_string"&&i[1].key==="title"&&i[2].type==="prop"&&i[2].key==="completed")for(let c=0;c<t.length;c++){let s=t[c];a[c]={id:s.id,title:s.title!=null?String(s.title):"",completed:s.completed}}else for(let c=0;c<t.length;c++){let s=t[c],f={};for(let u of i)if(u.type==="literal")f[u.key]=u.value;else if(u.type==="item")f[u.key]=s;else if(u.type==="prop")f[u.key]=s[u.prop];else if(u.type==="item_string")f[u.key]=s!=null?String(s):"";else if(u.type==="prop_string"){let d=s[u.prop];f[u.key]=d!=null?String(d):""}a[c]=f}return a}}return null},Kt=(e,t,n,r,o)=>{let i=[],l=e.body;if(l.type===p.OBJECT&&l.fast!==!1){let a=e.itemVar,c=e.indexVar;for(let s=0;s<o.length;s++){let f=o[s],u={},d={...r,[a]:f,...c&&{[c]:s}};d.__paths__||(d.__paths__=r.__paths__||{});let h=e.iterable.path||"";if(r&&r.__paths__&&h){let g=h.split("."),y=g[0];y in r.__paths__&&(h=r.__paths__[y],g.length>1&&(h+="."+g.slice(1).join(".")))}d.__paths__={...d.__paths__,[a]:`${h}[${s}]`,...c&&{[c]:s}};for(let g of l.properties){let y=g.parsedKey?_(g.parsedKey,t,n,d):g.key,I=g.value;if(I.type===p.LITERAL)u[y]=I.value;else if(I.type===p.VARIABLE){let m=I.path;if(m===a)u[y]=f;else if(m===c)u[y]=s;else if(m.startsWith(a+".")){let w=m.substring(a.length+1);!w.includes(".")&&!w.includes("[")?u[y]=f[w]:u[y]=A(m,n,{...r,[a]:f,...c&&{[c]:s}})}else u[y]=A(m,n,{...r,[a]:f,...c&&{[c]:s}})}else if(I.type===p.INTERPOLATION){let m=[];for(let w of I.parts)if(typeof w=="string")m.push(w);else if(w.type===p.VARIABLE){let v=w.path,R;if(v===a)R=f;else if(v===c)R=s;else if(v.startsWith(a+".")){let ne=v.substring(a.length+1);!ne.includes(".")&&!ne.includes("[")?R=f[ne]:R=A(v,n,{...r,[a]:f,...c&&{[c]:s}})}else R=A(v,n,{...r,[a]:f,...c&&{[c]:s}});m.push(R!=null?String(R):"")}else{let v={...r,[a]:f,...c&&{[c]:s}},R=_(w,t,n,v);m.push(R!=null?String(R):"")}u[y]=m.join("")}else{let m={...r,[a]:f,...c&&{[c]:s}};u[y]=_(I,t,n,m)}}i.push(u)}return i}return null},Jt=(e,t,n)=>{let r=e.body;if(r.type===p.OBJECT&&r.properties.length===1&&r.properties[0].key==="$if item.visible"){let i=r.properties[0].value;if(i.type===p.CONDITIONAL&&i.conditions.length===1&&i.conditions[0].type===p.VARIABLE&&i.conditions[0].path==="item.visible"){let l=i.bodies[0];if(l.type===p.OBJECT&&l.properties.length===2){let a=l.properties[0],c=l.properties[1];if(a.key==="id"&&a.value.type===p.VARIABLE&&a.value.path==="item.id"&&c.key==="$if item.highlighted"&&c.value.type===p.CONDITIONAL){let s=[];for(let f=0;f<t.length;f++){let u=t[f];if(u.visible){let d={id:u.id};u.highlighted?(d.highlight=!0,d.message=`This item is highlighted: ${u.name}`):(d.highlight=!1,d.message=u.name),s.push(d)}}return s}}}}return null},Xt=(e,t,n,r)=>{let o=_(e.iterable,t,n,r);if(!Array.isArray(o)){let s,f=!1;if(e.iterable.type===p.FUNCTION){f=!0;let d=e.iterable.args.map(h=>h.type===p.LITERAL?typeof h.value=="string"?`'${h.value}'`:String(h.value):h.type===p.VARIABLE?h.path:h.type===p.FUNCTION?`${h.name}(...)`:"?").join(", ");s=`${e.iterable.name}(${d})`}else s=e.iterable.path||"undefined";let u=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${s}`;throw We(u,o,f)}if(!e.indexVar){let s=Jt(e,o,e.itemVar);if(s!==null)return s}if(!e.indexVar){let s=Ht(e,o);if(s!==null)return s}let i=Kt(e,t,n,r,o);if(i!==null)return i;let l=[],a=e.iterable.path||"";if(r&&r.__paths__&&a){let s=a.split("."),f=s[0];f in r.__paths__&&(a=r.__paths__[f],s.length>1&&(a+="."+s.slice(1).join(".")))}let c=!1;e.body.type===p.ARRAY&&(e.body.items.length<=1?c=!1:c=e.body._shouldPreserveArray??=e.body.items.some(s=>s.type===p.OBJECT&&s.properties.some(f=>f.key.startsWith("$if ")||f.key.startsWith("$when "))));for(let s=0;s<o.length;s++){let f=e.indexVar?{...r,[e.itemVar]:o[s],[e.indexVar]:s}:{...r,[e.itemVar]:o[s]};f.__paths__||(f.__paths__=r.__paths__||{}),f.__paths__={...f.__paths__,[e.itemVar]:`${a}[${s}]`},e.indexVar&&(f.__paths__[e.indexVar]=s);let u=_(e.body,t,n,f);if(Array.isArray(u)&&u.length===1&&!c){let d=u[0];l.push(d===void 0?{}:d)}else l.push(u===void 0?{}:u)}return l},Gt=(e,t,n,r)=>{if(e.whenCondition)return null;if(e.properties.length===1){let o=e.properties[0],i=o.parsedKey?_(o.parsedKey,t,n,r):o.key,l=o.value;if(l.type===p.OBJECT&&l.properties.length<=10&&!l.whenCondition){let a={},c={},s=!0;for(let f of l.properties){let u=f.parsedKey?_(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)c[u]=d.value;else if(d.type===p.VARIABLE)c[u]=A(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let y=A(g.path,n,r);h.push(y!=null?String(y):"")}else{s=!1;break}if(!s)break;c[u]=h.join("")}else if(d.type===p.OBJECT&&d.properties.length<=5){let h={};for(let g of d.properties){let y=g.key,I=g.value;if(I.type===p.LITERAL)h[y]=I.value;else if(I.type===p.VARIABLE)h[y]=A(I.path,n,r);else if(I.type===p.INTERPOLATION){let m=[];for(let w of I.parts)if(typeof w=="string")m.push(w);else if(w.type===p.VARIABLE){let v=A(w.path,n,r);m.push(v!=null?String(v):"")}else{s=!1;break}if(!s)break;h[y]=m.join("")}else{s=!1;break}}if(!s)break;c[u]=h}else{s=!1;break}}if(s)return a[i]=c,a}}return null},qt=(e,t,n,r)=>{let o=t.functions||t;if(e.whenCondition&&!j(e.whenCondition,o,n,r))return;let i=Gt(e,t,n,r);if(i!==null)return i;if(e.fast){let s={};for(let f of e.properties){let u=f.parsedKey?_(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)s[u]=d.value;else if(d.type===p.VARIABLE)s[u]=A(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let y=A(g.path,n,r);h.push(y!=null?String(y):"")}else{let y=_(g,t,n,r);h.push(y!=null?String(y):"")}s[u]=h.join("")}else s[u]=_(d,t,n,r)}return s}let l={},a=null,c=!1;for(let s of e.properties)if(!s.key.startsWith("$if ")&&!s.key.match(/^\$if\s+\w+.*:?$/)&&!s.key.startsWith("$elif")&&!s.key.startsWith("$else")&&!s.key.startsWith("$for ")){c=!0;break}for(let s of e.properties)if(s.key.startsWith("$if ")||s.key.match(/^\$if\s+\w+.*:?$/)){let f=_(s.value,t,n,r);if(!c&&f!==null&&f!==void 0)return Array.isArray(f)&&f.length===1?f[0]:f;typeof f=="object"&&f!==null&&!Array.isArray(f)&&Object.assign(l,f)}else if(s.key.startsWith("$for ")){if(e.properties.length===1)return _(s.value,t,n,r)}else{let f=s.value;if(f&&f.type===p.OBJECT&&f.properties){let u=f.properties.find(d=>d.key.startsWith("$for "));if(u){let d=_(u.value,t,n,r);d!==void 0&&(l[s.key]=d)}else{let d=_(s.value,t,n,r);d!==void 0&&(l[s.key]=d)}}else{let u=s.parsedKey?_(s.parsedKey,t,n,r):s.key,d=_(s.value,t,n,r);d!==void 0&&(l[u]=d)}}return l},Xe={},Qt=(e,t,n,r)=>{let o=[];for(let i of e.items)if(i.type===p.LOOP){let l=_(i,t,n,r);Array.isArray(l)&&i.flatten!==!1?o.push(...l):o.push(l)}else{let l=_(i,t,n,r);l!==Xe&&l!==void 0&&o.push(l)}return o},Zt=(e,t,n,r)=>{let{name:o,data:i,whenCondition:l}=e,a=t.partials||{},c=t.functions||t;if(l&&!j(l,c,n,r))return;if(!a[o])throw new L(`Partial '${o}' is not defined`);let s=r._partialStack||[];if(s.includes(o))throw new L(`Circular partial reference detected: ${o}`);let f=a[o],u=n,d={...r,_partialStack:[...s,o]};if(r){u={...n};for(let h of Object.keys(r))h.startsWith("_")||(u[h]=r[h])}if(i){let h=_(i,t,n,r);u={...u,...h}}return _(f,t,u,d)},en=(e,t,n,r)=>{let{path:o}=e,i=o.split("."),l=i[0],a=i.slice(1);if(!r||!(l in r))throw new L(`Path reference '#{${o}}' refers to '${l}' which is not a loop variable in the current scope`);if(r.__paths__||(r.__paths__={}),!(l in r.__paths__))throw new L(`Path reference '#{${o}}' cannot be resolved - path tracking may not be initialized properly`);let c=r.__paths__[l];if(typeof c=="number"){if(a.length>0)throw new L(`Path reference '#{${o}}' - cannot access properties on index variable '${l}'`);return String(c)}return a.length>0&&(c+="."+a.join(".")),c},me=Ft;var tn=/\$\{([^}]*)\}/g,nn=/#\{([^}]*)\}/g,qe=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,r,o]=n,i=rn(o,t);return{isFunction:!0,type:p.FUNCTION,name:r,args:i}},rn=(e,t={})=>e.trim()?on(e).map(r=>sn(r.trim(),t)):[],on=e=>{let t=[],n="",r=0,o=!1,i="";for(let l=0;l<e.length;l++){let a=e[l],c=l>0?e[l-1]:"";!o&&(a==='"'||a==="'")?(o=!0,i=a,n+=a):o&&a===i&&c!=="\\"?(o=!1,i="",n+=a):!o&&a==="("?(r++,n+=a):!o&&a===")"?(r--,n+=a):!o&&a===","&&r===0?(t.push(n),n=""):n+=a}return n&&t.push(n),t},sn=(e,t={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:p.LITERAL,value:parseFloat(e)};if(e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};let n=qe(e,t);if(n.isFunction)return{type:n.type,name:n.name,args:n.args};let r=e.trim(),o=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],i=-1,l=null;for(let{op:a,type:c}of o){let s=0;for(;s<r.length;){let f=D(r.substring(s),a);if(f===-1)break;let u=s+f;u>i&&(i=u,l={op:a,type:c}),s=u+a.length}}if(i!==-1)try{return x(r,t)}catch{return{type:p.VARIABLE,path:r}}return{type:p.VARIABLE,path:r}},Qe=/^\w+\(.*\)$/,an=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,ln=e=>{if(!(!e||e.trim()===""||Qe.test(e))&&an.test(e))throw e.includes("?")&&e.includes(":")?new b(`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 b(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new b(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},Ge=e=>{let t=e.trim();if(Qe.test(t))throw new b(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("["))throw new b(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(t))throw new b(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(t))throw new b(`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 b(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:p.PATH_REFERENCE,path:t}},Y=(e,t={})=>{let n=e.trim();ln(n);let r=qe(n,t);if(r.isFunction)return{type:r.type,name:r.name,args:r.args};if(n.includes("[")&&!/[\s+\-*/%|&?:]/.test(n)){let o=0;for(let i of n)i==="["?o++:i==="]"&&o--;if(o!==0)throw new Error("Invalid array index syntax")}return{type:p.VARIABLE,path:n}},be=(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,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\(#\{[^}]*\})/g,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let o=[...n.matchAll(tn)],i=[...n.matchAll(nn)],l=[...o.map(s=>({match:s,type:"variable"})),...i.map(s=>({match:s,type:"pathref"}))].sort((s,f)=>s.match.index-f.match.index);if(l.length===0){let s=n;for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);return{type:p.LITERAL,value:s}}if(l.length===1&&l[0].match[0]===n&&r.length===0){let{match:s,type:f}=l[0];try{return f==="variable"?Y(s[1],t):Ge(s[1])}catch(u){if(u.message==="Invalid array index syntax")return{type:p.LITERAL,value:n};throw u}}let a=[],c=0;for(let{match:s,type:f}of l){let[u,d]=s,h=s.index;if(h>c){let g=n.substring(c,h);for(let y=0;y<r.length;y++)g=g.replace(`__ESCAPED_${y}__`,r[y]);g&&a.push(g)}try{let g;f==="variable"?g=Y(d.trim(),t):g=Ge(d.trim()),a.push(g)}catch(g){if(g.message==="Invalid array index syntax")a.push(u);else throw g}c=h+u.length}if(c<n.length){let s=n.substring(c);for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);s&&a.push(s)}return{type:p.INTERPOLATION,parts:a}};var N=(e,t)=>typeof e=="string"?be(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?un(e,t):fn(e,t):{type:p.LITERAL,value:e},cn=e=>{let{$each:t,...n}=e;if(typeof t!="string")throw new b("$each value must be a non-empty string");let r=t.trim();if(r==="")throw new b("$each value must be a non-empty string");if(Object.keys(n).length===0)throw new b("Empty $each body not allowed");if(n.$partial!==void 0)throw new b("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${r}`]:n}},un=(e,t)=>{let n=[],r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(typeof i=="object"&&i!==null&&!Array.isArray(i)){if(i.$each!==void 0)try{let c=cn(i),s=Object.keys(c);if(s.length===1&&/^\$for(?::\w+)?\s/.test(s[0])){let f=Ze(s[0],c[s[0]],t,!0);n.push(f),r=!0;continue}}catch(c){throw c instanceof b?c:new b(c.message)}let a=Object.keys(i);if(a.length===1&&/^\$for(?::\w+)?\s/.test(a[0])){let c=Ze(a[0],i[a[0]],t);n.push(c),r=!0;continue}}let l=N(i,t);n.push(l),(l.type===p.FUNCTION||l.type===p.CONDITIONAL||l.type===p.LOOP||l.type===p.PARTIAL||l.type===p.OBJECT&&!l.fast||l.type===p.ARRAY&&!l.fast)&&(r=!0)}return{type:p.ARRAY,items:n,fast:!r}},fn=(e,t)=>{let n=[],r=!1,o=null,i=Object.entries(e),l=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new b("$partial value must be a string");if(e.$partial.trim()==="")throw new b("$partial value cannot be an empty string");let c=["$if","$elif","$else","$for"],s=[];for(let[m]of i)for(let w of c)if(m===w||m.startsWith(w+" ")||m.startsWith(w+"#")){s.push(w);break}if(s.length>0)throw new b(`Cannot use $partial with ${s.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:f,$when:u,...d}=e,h={},g=!1;for(let[m,w]of Object.entries(d)){let v=m;(m.startsWith("\\$")||m.startsWith("$$"))&&(v=m.slice(1)),h[v]=w,g=!0}let y=null;if(g&&(y=N(h,t),y.type===p.OBJECT)){let m=!1;for(let w of y.properties)if(w.value.type===p.VARIABLE||w.value.type===p.INTERPOLATION||w.value.type===p.FUNCTION||w.value.type===p.CONDITIONAL||w.value.type===p.OBJECT&&!w.value.fast||w.value.type===p.ARRAY&&!w.value.fast){m=!0;break}m&&(y.fast=!1)}let I={type:p.PARTIAL,name:f,data:y};if(u!==void 0){let m;if(typeof u=="string"){if(u.trim()==="")throw new b("Empty condition expression after '$when'");m=x(u,t)}else m={type:p.LITERAL,value:u};I.whenCondition=m}return I}for(let[c,s]of i)if(c==="$when"){if(o!==null)throw new b("Multiple '$when' directives on the same object are not allowed");if(s==null)throw new b("Missing condition expression after '$when'");let f=typeof s=="string"?s:JSON.stringify(s);if(f.trim()==="")throw new b("Empty condition expression after '$when'");o=x(f,t),r=!0}else if(c.startsWith("$when#")||c.startsWith("$when "))throw new b("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;l<i.length;){let[c,s]=i[l];if(c==="$when"){l++;continue}if(c==="$each")throw new b("$each can only be used inside arrays");if(c.startsWith("$if ")||c.match(/^\$if#\w+\s/)||c.match(/^\$if\s+\w+.*:$/)){let f=dn(i,l,t);n.push({key:c,value:f.node}),r=!0,l=f.nextIndex}else if(/^\$for(?::\w+)?\s/.test(c)){let f=c.match(/^\$for(?::(\w+))?\s/)?.[1]||"",u=f?`:${f}`:"";throw new b(`$for loops must be inside arrays - use '- $for${u} item in items:' instead of '$for${u} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(c.startsWith("$elif ")||c.startsWith("$else"))throw new b(`'${c.split(" ")[0]}' without matching '$if'`);if(c==="$if"||c==="$if:")throw new b("Missing condition expression after '$if'");{let f=N(s,t);(f.type===p.FUNCTION||f.type===p.CONDITIONAL||f.type===p.PARTIAL||f.type===p.OBJECT&&!f.fast||f.type===p.ARRAY&&!f.fast)&&(r=!0);let u=be(c,t),d={key:c,value:f};(u.type!==p.LITERAL||u.value!==c)&&(d.parsedKey=u),n.push(d),l++}}}let a={type:p.OBJECT,properties:n,fast:!r};return o&&(a.whenCondition=o),a},dn=(e,t,n={})=>{let r=[],o=[],i=t,[l,a]=e[i],c=null,s;if(l.startsWith("$if#")){let u=l.match(/^\$if#(\w+)\s+(.+)$/);if(u)c=u[1],s=u[2];else throw new b(`Invalid conditional syntax: ${l}`)}else s=l.substring(4),s.endsWith(":")&&(s=s.slice(0,-1).trim());ye(s);let f=x(s,n);for(r.push(f),o.push(N(a,n)),i++;i<e.length;){let[u,d]=e[i],h=!1,g;if(c?u.startsWith(`$elif#${c} `)?(g=u.substring(`$elif#${c} `.length),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u===`$else#${c}`||u===`$else#${c}:`)&&(h=!0,g=null):u.startsWith("$elif ")?(g=u.substring(6),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u==="$else"||u==="$else:")&&(h=!0,g=null),h){if(g===null)r.push(null);else{ye(g);let y=x(g,n);r.push(y)}if(o.push(N(d,n)),i++,g===null)break}else break}return{node:{type:p.CONDITIONAL,conditions:r,bodies:o,id:c},nextIndex:i}},x=(e,t={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let s=e.slice(1,-1),f=0,u=!0;for(let d=0;d<s.length;d++)if(s[d]==="("?f++:s[d]===")"&&f--,f<0){u=!1;break}if(u&&f===0)return x(s,t)}let n=D(e,"||");if(n!==-1)return{type:p.BINARY,op:E.OR,left:x(e.substring(0,n).trim(),t),right:x(e.substring(n+2).trim(),t)};let r=D(e,"&&");if(r!==-1)return{type:p.BINARY,op:E.AND,left:x(e.substring(0,r).trim(),t),right:x(e.substring(r+2).trim(),t)};let o=[{op:">=",type:E.GTE},{op:"<=",type:E.LTE},{op:"==",type:E.EQ},{op:"!=",type:E.NEQ},{op:">",type:E.GT},{op:"<",type:E.LT},{op:" in ",type:E.IN}];for(let{op:s,type:f}of o){let u=D(e,s);if(u!==-1)return{type:p.BINARY,op:f,left:x(e.substring(0,u).trim(),t),right:x(e.substring(u+s.length).trim(),t)}}let i=-1,l=null,a=[{op:" + ",type:E.ADD},{op:" - ",type:E.SUBTRACT}];for(let{op:s,type:f}of a){let u=0;for(;u<e.length;){let d=D(e.substring(u),s);if(d===-1)break;let h=u+d;h>i&&(i=h,l={op:s,type:f}),u=h+s.length}}if(i!==-1&&l)return{type:p.BINARY,op:l.type,left:x(e.substring(0,i).trim(),t),right:x(e.substring(i+l.op.length).trim(),t)};let c=[" * "," / "," % "];for(let s of c)if(D(e,s)!==-1)throw new b(`Arithmetic operations are not allowed in conditionals: "${s}"`);return e.startsWith("!")?{type:p.UNARY,op:z.NOT,operand:x(e.substring(1).trim(),t)}:et(e,t)},D=(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},pn=e=>{if(e=e.trim(),e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:p.LITERAL,value:""};if(e==="{}")return{type:p.LITERAL,value:{}};if(e==="[]")return{type:p.LITERAL,value:[]};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:p.LITERAL,value:t}:{type:p.VARIABLE,path:e}},et=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return Y(n,t);let o=pn(n);if(o.type===p.LITERAL)return o;if(/^[a-zA-Z_$][\w.$]*$/.test(n))return{type:p.VARIABLE,path:n};try{return Y(n,t)}catch(i){if(i.message&&i.message.includes("not supported"))return o;throw i}},hn=(e,t=!1)=>{let n=t?"$each":"$for";try{Ue(e)}catch(r){if(r instanceof b&&t){let o=r.message.replace(/\$for/g,"$each");throw new b(o.replace("Parse Error: ",""))}throw r}},Ze=(e,t,n,r=!1)=>{let o=/^\$for(?::(\w+))?\s+(.+)$/,i=e.match(o);if(!i){let I=r?"$each":"$for";throw new b(`Invalid loop syntax (got: '${e.replace("$for",I)}')`)}let l=i[1],a=i[2].trim();hn(a,r);let c=a.match(/^(.+?)\s+in\s+(.+)$/);if(!c){let I=r?"$each":"$for";throw new b(`Invalid loop syntax - missing 'in' keyword (got: '${I} ${a}')`)}let s=c[1].trim(),f=c[2].trim(),u,d=null;if(s.includes(",")){let I=s.split(",").map(m=>m.trim());if(I.length!==2)throw new b(`Invalid loop variables: ${s}. Expected format: "item" or "item, index"`);u=I[0],d=I[1]}else u=s;let h=["this","undefined","null","true","false"];if(h.includes(u))throw new b(`Reserved variable name: ${u}`);if(d&&h.includes(d))throw new b(`Reserved variable name: ${d}`);let g=et(f,n),y=N(t,n);return{type:p.LOOP,itemVar:u,indexVar:d,iterable:g,body:y,flatten:l!=="nested"}};var gn=(e,t={})=>{let{functions:n={}}=t;return N(e,n)},ee=gn;var Ie={};ht(Ie,{now:()=>yn});var yn=()=>Date.now();var mn=(e,t,n={})=>{let{functions:r={},partials:o={}}=n,i={...Ie,...r},l=ee(e,{functions:i}),a={};for(let[c,s]of Object.entries(o))a[c]=ee(s,{functions:i});return me(l,t,{functions:i,partials:a})},S=mn;var we={objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n})),formatDate:je},bn=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),In=(e,{presentationState:t,resources:n})=>{let{elements:r}=e;if(t.base){let o=r.find(i=>i.id==="story");if(!o)return e;if(t.base.resourceId){let i=n?.layouts[t.base.resourceId];i&&o.children.unshift({id:"base",type:"container",children:i.elements})}}return e},wn=(e,{presentationState:t,previousPresentationState:n,resources:r={},variables:o,autoMode:i,skipMode:l,currentLocalizationPackageId:a})=>{let{elements:c}=e,s=e.animations||[];if(t.background){let f=c.find(u=>u.id==="story");if(!f)return e;if(t.background.resourceId){let{images:u={},videos:d={}}=r,h=u[t.background.resourceId]||d[t.background.resourceId];if(h){let g=d[t.background.resourceId]!==void 0,y={id:`bg-cg-${t.background.resourceId}`,type:g?"video":"sprite",x:0,y:0,src:h.fileId,width:h.width,height:h.height};g&&(y.loop=h.loop??!1,y.volume=h.volume??500),f.children.push(y)}}if(t.background.resourceId){let{layouts:u={}}=r,d=u[t.background.resourceId];d&&f.children.push({id:`bg-cg-${t.background.resourceId}`,type:"container",children:d.elements})}if(t.background.animations){if(t.background.animations.in){let u=t.background.animations.in.resourceId,d=r?.tweens[u];d&&s.push({id:"bg-cg-animation-in",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:d.properties})}if(t.background.animations.out){let u=t.background.animations.out.resourceId,d=n?.background?.resourceId,h=r?.tweens[u];h&&d&&s.push({id:"bg-cg-animation-out",type:"tween",targetId:`bg-cg-${d}`,properties:h.properties})}if(t.background.animations.update){let u=t.background.animations.update.resourceId,d=r?.tweens[u];d&&s.push({id:"bg-cg-animation-update",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:d.properties})}}}return e},_n=(e,{presentationState:t,resources:n})=>{let{elements:r}=e,o=e.animations||[];if(t.character&&n){let i=r.find(a=>a.id==="story");if(!i)return e;let l=t.character.items||[];for(let a of l){let{transformId:c,sprites:s}=a;if(a.animations&&a.animations.out&&!s&&!c){let h=a.animations.out.resourceId,g=n?.tweens[h];if(g){let y={id:"character-animation-out",type:"tween",targetId:`character-container-${a.id}`,properties:g.properties};o.push(y)}continue}if(!s||s.length===0||!c){console.warn("Character item missing sprites or transformId:",a);continue}let f=s.map(({resourceId:h})=>h),u=n.transforms[c];if(!u){console.warn("Transform not found:",c);continue}let d={type:"container",id:`character-container-${a.id}`,x:a.x??u.x,y:a.y??u.y,anchorX:u.anchorX,anchorY:u.anchorY,rotation:u.rotation,scaleX:u.scaleX,scaleY:u.scaleY,children:[]};for(let h of s){let g=n.images[h.resourceId];if(!g){console.warn(`Image resource not found: ${h.resourceId}`);continue}d.children.push({type:"sprite",id:`${a.id}-${h.id}`,src:g.fileId,width:g.width,height:g.height,x:0,y:0})}if(i.children.push(d),a.animations){if(a.animations.in){let h=a.animations.in.resourceId,g=n?.tweens[h];g&&o.push({id:"character-animation-in",type:"tween",targetId:`character-container-${a.id}`,properties:g.properties})}if(a.animations.update){let h=a.animations.update.resourceId,g=n?.tweens[h];if(g){let y={id:"character-animation-update",type:"tween",targetId:`character-container-${a.id}`,properties:g.properties};o.push(y)}}}}}return e},En=(e,{presentationState:t,resources:n})=>{let{elements:r}=e,o=e.animations||[];if(t.visual&&n){let i=r.find(a=>a.id==="story");if(!i)return e;let l=t.visual.items;for(let a of l){if(a.resourceId){let{images:c={},videos:s={},spritesheets:f={}}=n,u=f[a.resourceId];if(u){let d=n.transforms?.[a.transformId]||{},h=a.animationName;if(h){let g=u.animations?.[h];if(!g)throw new Error(`Animation '${h}' not found in spritesheet resource '${a.resourceId}'`);let y={id:`visual-${a.id}`,type:"animated-sprite",x:a.x??d.x??0,y:a.y??d.y??0,width:a.width??100,height:a.height??100,alpha:a.alpha??1,anchorX:d.anchorX,anchorY:d.anchorY,rotation:d.rotation,scaleX:d.scaleX,scaleY:d.scaleY,spritesheetSrc:u.fileId,spritesheetData:u.jsonData,animation:{frames:g.frames,animationSpeed:a.animationSpeed??g.animationSpeed??.5,loop:a.loop??g.loop??!0}};i.children.push(y)}}else{let d=c[a.resourceId]||s[a.resourceId];if(d){let h=s[a.resourceId]!==void 0,g=n.transforms[a.transformId],y={id:`visual-${a.id}`,type:h?"video":"sprite",src:d.fileId,width:d.width,height:d.height,x:g.x,y:g.y,anchorX:g.anchorX,anchorY:g.anchorY,rotation:g.rotation,scaleX:g.scaleX,scaleY:g.scaleY};h&&(y.loop=d.loop??!1,y.volume=d.volume??500),i.children.push(y)}}}if(a.resourceId){let{layouts:c={}}=n,s=c[a.resourceId];if(s){let f=n.transforms[a.transformId];i.children.push({id:`visual-${a.id}`,type:"container",children:s.elements,x:f.x,y:f.y,anchorX:f.anchorX,anchorY:f.anchorY,rotation:f.rotation,scaleX:f.scaleX,scaleY:f.scaleY})}}if(a.animations){if(a.animations.in){let c=a.animations.in.resourceId||a.animations.in,s=n?.tweens[c];s&&o.push({id:`${a.id}-animation`,type:"tween",targetId:`visual-${a.id}`,properties:s.properties})}if(a.animations.out){let c=a.animations.out.resourceId||a.animations.out,s=n?.tweens[c];s&&o.push({id:`${a.id}-animation-2`,type:"tween",targetId:`visual-${a.id}`,properties:s.properties})}}}}return e},vn=(e,{presentationState:t,resources:n={},dialogueUIHidden:r,autoMode:o,skipMode:i,skipOnlyViewedLines:l,l10n:a,variables:c,saveSlots:s=[]})=>{let{elements:f}=e;if(!t.dialogue||r)return e;let u=f.find(d=>d.id==="story");if(!u)return e;if(t.dialogue.gui&&t.dialogue.gui.resourceId){let{layouts:d={}}=n,h=d[t.dialogue.gui.resourceId];if(h){let g;t.dialogue.characterId&&(g=n.characters[t.dialogue.characterId]),t.dialogue.character&&(g={...g,name:t.dialogue.character.name});let y={elements:h.elements},I={variables:c,autoMode:o,skipMode:i,skipOnlyViewedLines:l,saveSlots:s,dialogue:{character:{name:g?.name||""},content:t.dialogue?.content||[{text:""}],lines:t.dialogue?.lines||[]},l10n:a},m=S(y,I,{functions:we});m=S(m,{l10n:a});let w=m?.elements;if(Array.isArray(w))for(let v of w)u.children.push(structuredClone(v));else w&&u.children.push(structuredClone(w))}}return e},An=(e,{presentationState:t,resources:n})=>{let{elements:r}=e;if(t.choice&&n){let o=r.find(s=>s.id==="story");if(!o)return e;o.children.push({id:"choice-blocker",type:"rect",width:1920,height:1080,x:0,y:0,click:{actionPayload:{actions:{}}}});let i=n?.layouts[t.choice.resourceId];if(!i||!i.elements)return e;let l={elements:i.elements},c=S(l,{choice:{items:t.choice?.items??[]}})?.elements;if(Array.isArray(c))for(let s of c)o.children.push(structuredClone(s));else c&&o.children.push(structuredClone(c))}return e},xn=(e,{presentationState:t,resources:n})=>{if(t.keyboard?.resourceId){let r=n?.keyboards?.[t.keyboard.resourceId];r&&(e.global.keyboard=r)}return e},Ln=(e,{presentationState:t,resources:n})=>{let{elements:r,audio:o}=e;if(t.bgm&&n){if(!r.find(a=>a.id==="story"))return e;let l=n.sounds[t.bgm.resourceId];if(!l)return e;o.push({id:"bgm",type:"sound",src:l.fileId,loop:t.bgm.loop??!0,volume:t.bgm.volume??500,delay:t.bgm.delay??null})}return e},$n=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(t.sfx&&n){let o=t.sfx.items;for(let i of o){let l=n.sounds?.[i.resourceId];l&&r.push({id:i.id,type:"sound",src:l.fileId,loop:i.loop??l.loop??!0,volume:i.volume??l.volume??500,delay:i.delay??l.delay??null})}}return e},Cn=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(!t?.voice)return e;let{fileId:o,volume:i,loop:l}=t.voice;return r.push({id:`voice-${o}`,type:"sound",src:o,volume:i??500,loop:l??!1}),e},kn=(e,{presentationState:t,resources:n={},variables:r,autoMode:o,skipMode:i,currentLocalizationPackageId:l,saveSlots:a=[]})=>{let{elements:c}=e,s=e.animations||[];if(t.layout){let f=c.find(I=>I.id==="story");if(!f)return e;let u=n.layouts[t.layout.resourceId];if(!u)return e;Array.isArray(u.transitions)&&u.transitions.forEach(I=>{s.push(I)});let d={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:u.elements||[]},g=S(d,{variables:r,saveSlots:a,autoMode:o,skipMode:i,currentLocalizationPackageId:l},{functions:we});g=S(g,{i18n:{}});let y=I=>{let m={...I};return I.src&&I.src.startsWith("file:")&&(m.src=I.src),I.children&&Array.isArray(I.children)&&(m.children=I.children.map(y)),m};f.children.push(y(g))}return e},On=(e,{resources:t={},variables:n,autoMode:r,skipMode:o,currentLocalizationPackageId:i,layeredViews:l=[],dialogueHistory:a=[],saveSlots:c=[]})=>{let{elements:s}=e,f=e.animations||[];return l&&l.length>0&&l.forEach((u,d)=>{let h=t.layouts[u.resourceId];if(!h){console.warn(`LayeredView layout not found: ${u.resourceId}`);return}Array.isArray(h.transitions)&&h.transitions.forEach(w=>{f.push(w)});let g={id:`layeredView-${d}`,type:"container",x:0,y:0,children:h.elements||[]},y=a.map(w=>{let v=t.characters?.[w.characterId];return{...w,characterName:v?.name||""}}),I={variables:n,autoMode:r,skipMode:o,currentLocalizationPackageId:i,saveSlots:c,historyDialogue:y,characters:t.characters||{}},m=S(g,I,{functions:we});m=S(m,{i18n:{}}),s.push(m)}),e},tt=e=>Z(bn,[In,wn,_n,En,vn,An,xn,kn,Ln,$n,Cn,On])(e);var Rn=e=>{let{global:{currentLocalizationPackageId:t,saveSlots:n={},variables:r={}},projectData:o}=e,i={sceneId:o.story.initialSceneId,sectionId:o.story.scenes[o.story.initialSceneId].initialSectionId,lineId:o.story.scenes[o.story.initialSceneId].sections[o.story.scenes[o.story.initialSceneId].initialSectionId].lines[0].id},{contextVariableDefaultValues:l,globalVariablesDefaultValues:a}=De(o),c={...a,...r},s={projectData:o,global:{autoplayDelay:1e3,isLineCompleted:!1,pendingEffects:[],autoMode:!1,skipMode:!1,skipOnlyViewedLines:!0,dialogueUIHidden:!1,isDialogueHistoryShowing:!1,currentLocalizationPackageId:t,viewedRegistry:{sections:[],resources:[]},nextLineConfig:{manual:{enabled:!0,requireLineCompleted:!1},auto:{enabled:!1}},saveSlots:n,layeredViews:[],variables:c},contexts:[{currentPointerMode:"read",pointers:{read:i,history:{sectionId:void 0,lineId:void 0,historySequenceIndex:void 0}},historySequence:[{sectionId:"..."}],configuration:{},views:[],bgm:{resourceId:void 0},variables:l}]};return console.log("Initial State:",s),s},Sn=({state:e})=>e.global.layeredViews||[],Nn=({state:e})=>e.global.pendingEffects,nt=({state:e})=>e.global.skipMode,Pn=({state:e})=>e.global.skipOnlyViewedLines,Tn=({state:e})=>e.global.autoMode,rt=({state:e})=>e.global.dialogueUIHidden,Vn=({state:e})=>e.global.autoplayDelay,_e=({state:e})=>{let t=e.contexts[e.contexts.length-1];if(!t)return[];let{sectionId:n,lineId:r}=t.pointers.read,o=$({state:e},{sectionId:n});if(!o?.lines||!Array.isArray(o.lines))return[];let i=o.lines.findIndex(c=>c.id===r);return o.lines.slice(0,i+1).filter(c=>c.actions?.dialogue).map(c=>{let s=c.actions.dialogue,f="";return s.characterId&&(f=e.projectData.resources?.characters?.[s.characterId]?.name||""),{content:s.content,characterId:s.characterId,characterName:f}})},Dn=({state:e})=>e.global.currentLocalizationPackageId,ot=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(c=>c.sectionId===n);if(!o)return!1;if(o.lastLineId===void 0||r===void 0)return!0;let i=$({state:e},{sectionId:n});if(!i||!i.lines||!Array.isArray(i.lines))return!1;let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);return l===-1||a===-1?o.lastLineId===r:a<l},Mn=({state:e},t)=>{let{resourceId:n}=t;return!!e.global.viewedRegistry.resources.find(o=>o.resourceId===n)},Bn=({state:e})=>e.global.nextLineConfig,Fn=({state:e})=>e.global.saveSlots,jn=({state:e},t)=>{let{slotKey:n}=t;return e.global.saveSlots[n]},M=({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}},$=({state:e},t)=>{let{sectionId:n}=t,r=e.projectData?.story?.scenes||{};for(let o in r){let i=r[o];if(i.sections&&i.sections[n])return i.sections[n]}},Un=({state:e})=>{let t=M({state:e});if(!t?.pointer)return;let{sectionId:n,lineId:r}=t.pointer,o=$({state:e},{sectionId:n});if(!(!o?.lines||!Array.isArray(o.lines)))return o.lines.find(i=>i.id===r)},it=({state:e})=>{let{sectionId:t,lineId:n}=M({state:e}).pointer,o=$({state:e},{sectionId:t})?.lines||[],i=o.findIndex(s=>s.id===n),l=o.slice(0,i+1);console.log("currentLines",l);let a=l.map(s=>{let f=s.actions||{},u={};return Object.keys(f).forEach(d=>{u[d]=f[d]}),u});return ge(a)},Wn=({state:e})=>{let{sectionId:t,lineId:n}=M({state:e}).pointer,o=$({state:e},{sectionId:t})?.lines||[],i=o.findIndex(c=>c.id===n);if(i<=0)return null;let a=o.slice(0,i).map(c=>{let s=c.actions||{},f={};return Object.keys(s).forEach(u=>{f[u]=s[u]}),f});return ge(a)},st=({state:e},{slotsPerPage:t=6}={})=>{let o=(({...e.global.variables,...e.contexts[e.contexts.length-1].variables}.loadPage??1)-1)*t+1,i=[];for(let l=0;l<t;l++){let a=o+l,c=e.global.saveSlots&&e.global.saveSlots[a]||{};i.push({slotNumber:a,...c})}return{saveSlots:i}},zn=({state:e})=>{let t=it({state:e}),n=Wn({state:e});console.log("presentationState",t);let r={...e.global.variables,...e.contexts[e.contexts.length-1].variables},{saveSlots:o}=st({state:e}),i=tt({presentationState:t,previousPresentationState:n,resources:e.projectData.resources,l10n:e.projectData.l10n.packages[e.global.currentLocalizationPackageId],currentLocalizationPackageId:e.global.currentLocalizationPackageId,dialogueUIHidden:e.global.dialogueUIHidden,autoMode:e.global.autoMode,skipMode:e.global.skipMode,skipOnlyViewedLines:e.global.skipOnlyViewedLines,layeredViews:e.global.layeredViews,dialogueHistory:_e({state:e}),saveSlots:o,variables:r});return console.log("renderState",i),i},Yn=({state:e},t)=>(e.global.layeredViews.push(t),e.global.pendingEffects.push({name:"render"}),e),Hn=({state:e})=>(e.global.layeredViews.pop(),e.global.pendingEffects.push({name:"render"}),e),Kn=({state:e},t)=>(e.global.layeredViews.length>0&&(e.global.layeredViews[e.global.layeredViews.length-1]=t),e.global.pendingEffects.push({name:"render"}),e),Jn=({state:e})=>(e.global.layeredViews=[],e.global.pendingEffects.push({name:"render"}),e),at=({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",payload:{delay:e.global.autoplayDelay}}),e.global.pendingEffects.push({name:"render"}),e),Ee=({state:e})=>(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Xn=({state:e})=>(e.global.autoMode?Ee({state:e}):at({state:e}),e),lt=({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),te=({state:e})=>(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Gn=({state:e})=>(nt({state:e})?te({state:e}):lt({state:e}),e),qn=({state:e},t)=>{let{skipOnlyViewedLines:n}=t;return e.global.skipOnlyViewedLines=n,e.global.pendingEffects.push({name:"render"}),e},Qn=({state:e})=>(e.global.skipOnlyViewedLines=!e.global.skipOnlyViewedLines,e.global.pendingEffects.push({name:"render"}),e),ct=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),e),ut=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),e),Zn=({state:e})=>(rt({state:e})?ct({state:e}):ut({state:e}),e),er=({state:e})=>{let t=_e({state:e});return e.global.isDialogueHistoryShowing=!0,e.global.pendingEffects.push({name:"render"}),e},tr=({state:e})=>(e.global.isDialogueHistoryShowing=!1,e.global.pendingEffects.push({name:"render"}),e),nr=({state:e},t)=>{let{localizationPackageId:n}=t;return e.global.currentLocalizationPackageId=n,e.global.pendingEffects.push({name:"render"}),e},rr=({state:e})=>(e.global.pendingEffects=[],e),or=({state:e},t)=>(e.global.pendingEffects.push(t),e),ft=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(i=>i.sectionId===n);if(o){let i=$({state:e},{sectionId:n});if(i?.lines&&o.lastLineId!==void 0){let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);(l===-1||a>l)&&(o.lastLineId=r)}else o.lastLineId=r}else e.global.viewedRegistry.sections.push({sectionId:n,lastLineId:r});return e.global.pendingEffects.push({name:"render"}),e},ir=({state:e},t)=>{let{resourceId:n}=t;return e.global.viewedRegistry.resources.find(o=>o.resourceId===n)||e.global.viewedRegistry.resources.push({resourceId:n}),e.global.pendingEffects.push({name:"render"}),e},sr=({state:e},t)=>{let{manual:n,auto:r}=t,o=e.global.nextLineConfig.auto?.enabled,i=r?.enabled;return n&&r?e.global.nextLineConfig={manual:n,auto:r}:(n&&(e.global.nextLineConfig.manual=n),r&&(e.global.nextLineConfig.auto=r)),i===!0&&!o?e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}}):i===!1&&o&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.pendingEffects.push({name:"render"}),e},ar=({state:e},{delay:t})=>(e.global.autoplayDelay=t,e.global.autoMode&&(e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:e.global.autoplayDelay}})),e.global.pendingEffects.push({name:"render"}),e),lr=({state:e},t)=>{let{slot:n,thumbnailImage:r}=t,o=String(n),i={contexts:[...e.contexts],viewedRegistry:e.global.viewedRegistry},l={slotKey:o,date:Date.now(),image:r,state:i};return e.global.saveSlots[o]=l,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}},{name:"render"}),e},cr=({state:e},t)=>{let{slot:n}=t,r=String(n),o=e.global.saveSlots[r];return o&&(e.global.viewedRegistry=o.state.viewedRegistry,e.contexts=o.state.contexts,e.global.pendingEffects.push({name:"render"})),e},ur=({state:e},t)=>{let{projectData:n}=t;return e.projectData=n,e.global.pendingEffects.push({name:"render"}),e},fr=({state:e},t)=>{let{sectionId:n,lineId:r}=t;if(!r)return console.warn("jumpToLine requires lineId parameter"),e;let o=e.contexts[e.contexts.length-1];if(!o)return console.warn("No context available for jumpToLine"),e;let i=n||o.pointers.read?.sectionId;if(n&&!$({state:e},{sectionId:n}))return console.warn(`Section not found: ${n}`),e;let l=$({state:e},{sectionId:i});return!l?.lines||!Array.isArray(l.lines)?(console.warn(`Section ${i} has no lines`),e):l.lines.find(c=>c.id===r)?(o.pointers.read={sectionId:i,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 ${i}`),e)},dr=({state:e},t)=>{let{item:n}=t,r=e.contexts[e.contexts.length-1];return r&&r.historySequence&&r.historySequence.push({sectionId:n.sectionId}),e.global.pendingEffects.push({name:"render"}),e},pr=({state:e})=>{if(e.global.nextLineConfig?.auto?.enabled!==!0||e.global.nextLineConfig?.auto?.trigger!=="fromComplete")return e;let t=M({state:e})?.pointer,n=t?.sectionId,o=$({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=e.contexts[e.contexts.length-1];c&&(c.pointers.read={sectionId:n,lineId:a.id}),e.global.isLineCompleted=!1,e.global.nextLineConfig.auto={},e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"})}return e},hr=({state:e})=>{if(!e.global.nextLineConfig.manual.enabled)return e;let t=M({state:e})?.pointer,n=t?.sectionId,o=$({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l];e.global.skipMode&&e.global.skipOnlyViewedLines&&(ot({state:e},{sectionId:n,lineId:a.id})||te({state:e}));let c=e.contexts[e.contexts.length-1];if(c){let s=c.pointers.read.lineId;s&&n&&ft({state:e},{sectionId:n,lineId:s}),c.pointers.read={sectionId:n,lineId:a.id}}e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"})}else e.global.autoMode&&Ee({state:e}),e.global.skipMode&&te({state:e});return console.log("state",e),e},gr=({state:e})=>(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e),yr=({state:e},t)=>{let{sectionId:n}=t,r=$({state:e},{sectionId:n});if(!r||!r.lines||r.lines.length===0)return e;let o=r.lines,i=e.contexts[e.contexts.length-1];if(!i||!i.pointers)return e;let l=i.pointers.history||i.pointers.read;if(i.currentPointerMode!=="history"||!i.pointers.history){if(!l)return e;i.currentPointerMode="history",i.pointers.history={sectionId:n,lineId:l?.lineId};let f=o.findIndex(u=>u.id===l.lineId)-1;if(f>=0&&f<o.length){let u=o[f];i.pointers.history={sectionId:n,lineId:u.id}}return e.global.pendingEffects.push({name:"render"}),e}let c=o.findIndex(s=>s.id===i.pointers.history.lineId)-1;if(c>=0&&c<o.length){let s=o[c];i.pointers.history={sectionId:n,lineId:s.id},e.global.pendingEffects.push({name:"render"})}return e},mr=({state:e},t)=>{let{sectionId:n}=t,r=$({state:e},{sectionId:n});if(!r)return console.warn(`Section not found: ${n}`),e;let o=r.lines?.[0];if(!o)return console.warn(`Section ${n} has no lines`),e;let i=e.contexts[e.contexts.length-1];return i&&(i.pointers.read={sectionId:n,lineId:o.id}),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e},br=({state:e})=>{let t=M({state:e})?.pointer,n=t?.sectionId,o=$({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=e.contexts[e.contexts.length-1];c&&(c.pointers.read={sectionId:n,lineId:a.id}),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e.global.nextLineConfig.auto?.enabled&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}})}else e.global.nextLineConfig.auto?.enabled&&(e.global.nextLineConfig.auto.enabled=!1,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}));return e},Ir=({state:e},t)=>{let{operations:n=[]}=t,r=!1,o=!1;if(n.forEach(({variableId:i,op:l,value:a})=>{let c=e.projectData.resources?.variables?.[i],s=c?.scope,f=c?.type;Me(s,i),Be(f,l,i);let u=s==="context"?e.contexts[e.contexts.length-1].variables:e.global.variables;s==="global-device"?r=!0:s==="global-account"&&(o=!0),u[i]=Fe(u[i],l,a)}),r){let i=he(e.global.variables,e.projectData.resources?.variables,"global-device");e.global.pendingEffects.push({name:"saveGlobalDeviceVariables",payload:{globalDeviceVariables:i}})}if(o){let i=he(e.global.variables,e.projectData.resources?.variables,"global-account");e.global.pendingEffects.push({name:"saveGlobalAccountVariables",payload:{globalAccountVariables:i}})}return e.global.pendingEffects.push({name:"render"}),e},dt=e=>{let t=Rn(e);return Ve(t,{selectPendingEffects:Nn,selectSkipMode:nt,selectSkipOnlyViewedLines:Pn,selectAutoMode:Tn,selectDialogueUIHidden:rt,selectDialogueHistory:_e,selectCurrentLocalizationPackageId:Dn,selectIsLineViewed:ot,selectIsResourceViewed:Mn,selectNextLineConfig:Bn,selectSaveSlots:Fn,selectSaveSlot:jn,selectCurrentPointer:M,selectSection:$,selectCurrentLine:Un,selectPresentationState:it,selectAutoplayDelay:Vn,selectCurrentPageSlots:st,selectRenderState:zn,selectLayeredViews:Sn,startAutoMode:at,stopAutoMode:Ee,toggleAutoMode:Xn,startSkipMode:lt,stopSkipMode:te,toggleSkipMode:Gn,setSkipOnlyViewedLines:qn,toggleSkipOnlyViewedLines:Qn,showDialogueUI:ct,hideDialogueUI:ut,toggleDialogueUI:Zn,showDialogueHistory:er,hideDialogueHistory:tr,setCurrentLocalizationPackageId:nr,clearPendingEffects:rr,appendPendingEffect:or,addViewedLine:ft,addViewedResource:ir,setNextLineConfig:sr,saveSaveSlot:lr,loadSaveSlot:cr,setAutoplayDelay:ar,updateProjectData:ur,sectionTransition:mr,jumpToLine:fr,addToHistorySequence:dr,nextLine:hr,nextLineFromCompleted:pr,markLineCompleted:gr,prevLine:yr,pushLayeredView:Yn,popLayeredView:Hn,replaceLastLayeredView:Kn,clearLayeredViews:Jn,updateVariable:Ir,nextLineFromSystem:br},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function ve(e){let t,{handlePendingEffects:n}=e,r=()=>{for(;t.selectPendingEffects().length>0;){let u=[...t.selectPendingEffects()];t.clearPendingEffects(),n(u)}},o=({initialState:u})=>{t=dt(u),t.appendPendingEffect({name:"render"}),f(),r()},i=()=>t.selectPresentationState(),l=()=>t.selectRenderState(),a=()=>t.selectSaveSlots(),c=(u,d)=>{t[u]&&(t[u](d),r())},s=u=>{Object.entries(u).forEach(([d,h])=>{c(d,h)})},f=()=>{let u=t.selectCurrentLine();u&&u.actions&&s(u.actions)};return{init:o,handleAction:c,handleActions:s,selectRenderState:l,selectPresentationState:i,selectSaveSlots:a,handleLineActions:f}}var Ae=()=>{let e=0,t=null;return{getElapsed:()=>e,setElapsed:n=>{e=n},addElapsed:n=>{e+=n},getCallback:()=>t,setCallback:n=>{t=n}}},wr=({engine:e,routeGraphics:t},n)=>{let r=e.selectRenderState();t.render(r)},_r=({engine:e},t)=>{e.handleLineActions()},Er=({engine:e,ticker:t,autoTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},vr=({ticker:e,autoTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Ar=({engine:e,ticker:t,skipTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS),n.getElapsed()>=30&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},xr=({ticker:e,skipTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Lr=({engine:e,ticker:t,nextLineConfigTimerState:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}),t.remove(i),n.setCallback(null))};n.setCallback(i),t.add(i)},$r=({ticker:e,nextLineConfigTimerState:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Cr=({},e)=>{localStorage.setItem("saveSlots",JSON.stringify(e.saveSlots))},kr=({},e)=>{localStorage.setItem("globalDeviceVariables",JSON.stringify(e.globalDeviceVariables))},Or=({},e)=>{localStorage.setItem("globalAccountVariables",JSON.stringify(e.globalAccountVariables))},Rr={render:wr,saveSlots:Cr,saveGlobalDeviceVariables:kr,saveGlobalAccountVariables:Or,handleLineActions:_r,startAutoNextTimer:Er,clearAutoNextTimer:vr,startSkipNextTimer:Ar,clearSkipNextTimer:xr,nextLineConfigTimer:Lr,clearNextLineConfigTimer:$r},Sr=({getEngine:e,routeGraphics:t,ticker:n})=>{let r=Ae(),o=Ae(),i=Ae();return async l=>{let a=e(),c=l.reduce((u,d)=>(u[d.name]=d,u),{}),s=Object.values(c),f={engine:a,routeGraphics:t,ticker:n,autoTimer:r,skipTimer:o,nextLineConfigTimerState:i};for(let u of s){let d=Rr[u.name];d&&d(f,u.payload)}}},Nr=Sr;var Co=ve;export{Nr as createEffectsHandler,Co as default};
|
|
1
|
+
var pt=Object.defineProperty;var ht=(e,t)=>{for(var n in t)pt(e,n,{get:t[n],enumerable:!0})};var Oe=Symbol.for("immer-nothing"),xe=Symbol.for("immer-draftable"),C=Symbol.for("immer-state");function O(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var B=Object.getPrototypeOf;function F(e){return!!e&&!!e[C]}function T(e){return e?Re(e)||Array.isArray(e)||!!e[xe]||!!e.constructor?.[xe]||G(e)||q(e):!1}var gt=Object.prototype.constructor.toString();function Re(e){if(!e||typeof e!="object")return!1;let t=B(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)===gt}function H(e,t){X(e)===0?Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function X(e){let t=e[C];return t?t.type_:Array.isArray(e)?1:G(e)?2:q(e)?3:0}function ie(e,t){return X(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Se(e,t,n){let r=X(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function yt(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function G(e){return e instanceof Map}function q(e){return e instanceof Set}function P(e){return e.copy_||e.base_}function se(e,t){if(G(e))return new Map(e);if(q(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=Re(e);if(t===!0||t==="class_only"&&!n){let r=Object.getOwnPropertyDescriptors(e);delete r[C];let o=Reflect.ownKeys(r);for(let i=0;i<o.length;i++){let l=o[i],a=r[l];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(r[l]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[l]})}return Object.create(B(e),r)}else{let r=B(e);if(r!==null&&n)return{...e};let o=Object.create(r);return Object.assign(o,e)}}function fe(e,t=!1){return Q(e)||F(e)||!T(e)||(X(e)>1&&(e.set=e.add=e.clear=e.delete=mt),Object.freeze(e),t&&Object.entries(e).forEach(([n,r])=>fe(r,!0))),e}function mt(){O(2)}function Q(e){return Object.isFrozen(e)}var bt={};function V(e){let t=bt[e];return t||O(0,e),t}var U;function Ne(){return U}function It(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Le(e,t){t&&(V("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function ae(e){le(e),e.drafts_.forEach(wt),e.drafts_=null}function le(e){e===U&&(U=e.parent_)}function $e(e){return U=It(U,e)}function wt(e){let t=e[C];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Ce(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];return e!==void 0&&e!==n?(n[C].modified_&&(ae(t),O(4)),T(e)&&(e=K(t,e),t.parent_||J(t,e)),t.patches_&&V("Patches").generateReplacementPatches_(n[C].base_,e,t.patches_,t.inversePatches_)):e=K(t,n,[]),ae(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Oe?e:void 0}function K(e,t,n){if(Q(t))return t;let r=t[C];if(!r)return H(t,(o,i)=>ke(e,r,t,o,i,n)),t;if(r.scope_!==e)return t;if(!r.modified_)return J(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;let o=r.copy_,i=o,l=!1;r.type_===3&&(i=new Set(o),o.clear(),l=!0),H(i,(a,c)=>ke(e,r,o,a,c,n,l)),J(e,o,!1),n&&e.patches_&&V("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function ke(e,t,n,r,o,i,l){if(F(o)){let a=i&&t&&t.type_!==3&&!ie(t.assigned_,r)?i.concat(r):void 0,c=K(e,o,a);if(Se(n,r,c),F(c))e.canAutoFreeze_=!1;else return}else l&&n.add(o);if(T(o)&&!Q(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;K(e,o),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&Object.prototype.propertyIsEnumerable.call(n,r)&&J(e,o)}}function J(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&fe(t,n)}function _t(e,t){let n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:Ne(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=r,i=de;n&&(o=[r],i=W);let{revoke:l,proxy:a}=Proxy.revocable(o,i);return r.draft_=a,r.revoke_=l,a}var de={get(e,t){if(t===C)return e;let n=P(e);if(!ie(n,t))return Et(e,n,t);let r=n[t];return e.finalized_||!T(r)?r:r===re(e.base_,t)?(oe(e),e.copy_[t]=ue(r,e)):r},has(e,t){return t in P(e)},ownKeys(e){return Reflect.ownKeys(P(e))},set(e,t,n){let r=Pe(P(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let o=re(P(e),t),i=o?.[C];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(yt(n,o)&&(n!==void 0||ie(e.base_,t)))return!0;oe(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 re(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,oe(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 B(e.base_)},setPrototypeOf(){O(12)}},W={};H(de,(e,t)=>{W[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});W.deleteProperty=function(e,t){return W.set.call(this,e,t,void 0)};W.set=function(e,t,n){return de.set.call(this,e[0],t,n,e[0])};function re(e,t){let n=e[C];return(n?P(n):e)[t]}function Et(e,t,n){let r=Pe(t,n);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}function Pe(e,t){if(!(t in e))return;let n=B(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=B(n)}}function ce(e){e.modified_||(e.modified_=!0,e.parent_&&ce(e.parent_))}function oe(e){e.copy_||(e.copy_=se(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var vt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){let i=n;n=t;let l=this;return function(c=i,...s){return l.produce(c,f=>n.call(this,f,...s))}}typeof n!="function"&&O(6),r!==void 0&&typeof r!="function"&&O(7);let o;if(T(t)){let i=$e(this),l=ue(t,void 0),a=!0;try{o=n(l),a=!1}finally{a?ae(i):le(i)}return Le(i,r),Ce(o,i)}else if(!t||typeof t!="object"){if(o=n(t),o===void 0&&(o=t),o===Oe&&(o=void 0),this.autoFreeze_&&fe(o,!0),r){let i=[],l=[];V("Patches").generateReplacementPatches_(t,o,i,l),r(i,l)}return o}else O(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(l,...a)=>this.produceWithPatches(l,c=>t(c,...a));let r,o;return[this.produce(t,n,(l,a)=>{r=l,o=a}),r,o]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){T(e)||O(8),F(e)&&(e=At(e));let t=$e(this),n=ue(e,void 0);return n[C].isManual_=!0,le(t),n}finishDraft(e,t){let n=e&&e[C];(!n||!n.isManual_)&&O(9);let{scope_:r}=n;return Le(r,t),Ce(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 o=t[n];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}n>-1&&(t=t.slice(n+1));let r=V("Patches").applyPatches_;return F(e)?r(e,t):this.produce(e,o=>r(o,t))}};function ue(e,t){let n=G(e)?V("MapSet").proxyMap_(e,t):q(e)?V("MapSet").proxySet_(e,t):_t(e,t);return(t?t.scope_:Ne()).drafts_.push(n),n}function At(e){return F(e)||O(10,e),Te(e)}function Te(e){if(!T(e)||Q(e))return e;let t=e[C],n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=se(e,t.scope_.immer_.useStrictShallowCopy_)}else n=se(e,!0);return H(n,(r,o)=>{Se(n,r,Te(o))}),t&&(t.finalized_=!1),n}var k=new vt,pe=k.produce,Tr=k.produceWithPatches.bind(k),Vr=k.setAutoFreeze.bind(k),Dr=k.setUseStrictShallowCopy.bind(k),Mr=k.applyPatches.bind(k),Br=k.createDraft.bind(k),Fr=k.finishDraft.bind(k);var Ve=(e,t,n={})=>{let r=structuredClone(e),o={},i={},{transformSelectorFirstArgument:l=c=>c,transformActionFirstArgument:a=c=>c}=n;for(let[c,s]of Object.entries(t))c!=="createInitialState"&&(c.startsWith("select")?o[c]=(...f)=>s(l(r),...f):i[c]=(...f)=>{r=pe(r,d=>s(a(d),...f))});return{...o,...i}},Z=(e,t)=>n=>{let r=e(),o=Array.isArray(n)?n:[n];return pe(r,i=>{o.forEach(l=>{t.forEach(a=>{a(i,l)})})})};var xt=(e,t)=>{if(e.default!==void 0)return e.default;let n=["number","boolean","string","object"];if(!n.includes(e.type))throw new Error(`Invalid variable type: ${e.type} for variable ${t}. Expected one of: ${n.join(", ")}`);switch(e.type){case"number":return 0;case"boolean":return!1;case"string":return"";case"object":return{}}},De=e=>{let t={},n={};return e.resources?.variables?(Object.entries(e.resources.variables).forEach(([r,o])=>{let i=xt(o,r);o.scope==="context"?t[r]=i:n[r]=i}),{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}):{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}},Me=(e,t)=>{let n=["context","global-device","global-account"];if(!e)throw new Error(`Variable scope is required for variable: ${t}`);if(!n.includes(e))throw new Error(`Invalid variable scope: ${e} for variable ${t}. Expected one of: ${n.join(", ")}`)},Be=(e,t,n)=>{let r={number:["set","increment","decrement","multiply","divide"],boolean:["set","toggle"],string:["set"],object:["set"]},o=r[e];if(!o)throw new Error(`Unknown variable type: ${e} for variable ${n}`);if(!Object.values(r).flat().includes(t))throw new Error(`Unknown operation: ${t}`);if(!o.includes(t))throw new Error(`Operation "${t}" is not valid for variable "${n}" of type "${e}". Valid operations: ${o.join(", ")}`)},Fe=(e,t,n)=>{switch(t){case"set":return n;case"multiply":return(e??1)*n;case"divide":return(e??0)/n;case"increment":return(e??0)+(n??1);case"decrement":return(e??0)-(n??1);case"toggle":return!e;default:throw new Error(`Unknown operation: ${t}`)}},he=(e,t,n)=>Object.fromEntries(Object.entries(e).filter(([r])=>t?.[r]?.scope===n)),je=(e,t="DD/MM/YYYY - HH:mm")=>{if(!e)return"";let n=new Date(e),r=o=>String(o).padStart(2,"0");return t.replace("DD",r(n.getDate())).replace("MM",r(n.getMonth()+1)).replace("YYYY",n.getFullYear()).replace("YY",String(n.getFullYear()).slice(-2)).replace("HH",r(n.getHours())).replace("mm",r(n.getMinutes())).replace("ss",r(n.getSeconds()))};var Lt=()=>({}),$t=(e,t)=>{t.base&&(e.base={...t.base})},Ct=(e,t)=>{t.background&&(e.background={...t.background})},kt=(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),delete e.dialogue.characterId,t.dialogue.characterId&&(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}))},Ot=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},Rt=(e,t)=>{if(t.bgm){if(!t.bgm.resourceId){e.bgm=void 0;return}e.bgm={...t.bgm,loop:t.bgm.loop||t.bgm.loop===void 0}}},St=(e,t)=>{t.visual&&(e.visual=t.visual)},Nt=(e,t)=>{t.character&&(t.character.items||delete e.character,e.character=structuredClone(t.character))},Pt=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},Tt=(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},Dt=(e,t)=>{t.keyboard&&(e.keyboard=t.keyboard)},Mt=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},Bt=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},ge=e=>Z(Lt,[Bt,$t,Ct,Ot,Rt,St,kt,Nt,Pt,Tt,Vt,Dt,Mt])(e);var p={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},E={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},z={NOT:0};var b=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},L=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var ye=e=>{if(!e||e.trim()==="")throw new b("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let n=e.includes("===")?"==":"!=";throw new b(`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 b(`Incomplete comparison expression - missing right operand (got: '${e}')`)},Ue=e=>{if(e.trim().endsWith(" in"))throw new b(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new b(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,n]=e.split(" in ");if(!n||n.trim()==="")throw new b(`Missing iterable expression after 'in' (got: '$for ${e}')`);let r=t.includes(",")?t.split(",").map(o=>o.trim()):[t.trim()];for(let o of r){if(!o)throw new b(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(o))throw new b(`Invalid loop syntax (got: '$for ${e}')`)}};var We=(e,t,n=!1)=>{if(t===null)return new L(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new L(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return n?new L(`Cannot iterate over non-array value in loop '${e}' - got ${r} instead`):new L(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},ze=(e,t)=>{let n=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new L(`Unknown function '${e}' (${n})`)};var Ft=(e,t,n={})=>{let r={},o={};n&&typeof n=="object"&&(n.functions!==void 0||n.partials!==void 0?(r=n.functions||{},o=n.partials||{}):typeof n=="object"&&(r=n));let l=_(e,{functions:r,partials:o},t,{});return l===void 0?{}:l},_=(e,t,n,r)=>{let o=t.functions||t;if(e.var&&!e.type)return A(e.var,n,r);if(e.type===p.LITERAL)return e.value;if(e.type===p.VARIABLE)return A(e.path,n,r);if(e.type===p.INTERPOLATION)return Ut(e.parts,t,n,r);switch(e.type){case p.FUNCTION:return He(e,t,n,r);case p.BINARY:return Ke(e,t,n,r);case p.UNARY:return Je(e,t,n,r);case p.CONDITIONAL:return zt(e,t,n,r);case p.LOOP:return Xt(e,t,n,r);case p.OBJECT:return qt(e,t,n,r);case p.ARRAY:return Qt(e,t,n,r);case p.PARTIAL:return Zt(e,t,n,r);case p.PATH_REFERENCE:return en(e,t,n,r);default:throw new Error(`Unknown node type: ${e.type}`)}},Ye=new Map,jt=e=>{let t=[],n="",r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(i==="[")n&&(t.push({type:"property",value:n}),n=""),r=!0;else if(i==="]"){if(r&&n){let l=n.trim();if(/^\d+$/.test(l))t.push({type:"index",value:parseInt(l,10)});else if(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'")){let a=l.slice(1,-1);t.push({type:"property",value:a})}else t.push({type:"property",value:l});n=""}r=!1}else n+=i}return n&&t.push({type:"property",value:n}),t},A=(e,t,n)=>{if(!e)return;if(e in n)return n[e];let r=Ye.get(e);if(!r){let i=[],l="",a=0;for(let c=0;c<e.length;c++){let s=e[c];s==="["?(a++,l+=s):s==="]"?(a--,l+=s):s==="."&&a===0?l&&(i.push(l),l=""):l+=s}l&&i.push(l),r=[];for(let c of i){let s=jt(c.trim());r.push(...s)}Ye.set(e,r)}let o=t;for(let i=0;i<r.length;i++){let l=r[i];if(l.type==="property"&&l.value in n){o=n[l.value];continue}if(o==null)return;(l.type==="property"||l.type==="index")&&(o=o[l.value])}return o},Ut=(e,t,n,r)=>{let o=[];for(let i of e)if(typeof i=="string")o.push(i);else{let l=_(i,t,n,r);o.push(l!=null?String(l):"")}return o.join("")},He=(e,t,n,r)=>{let o=t.functions||t,i=o[e.name];if(!i)throw ze(e.name,o);let l=e.args.map(a=>_(a,t,n,r));return i(...l)},j=(e,t,n,r)=>{if(e.var&&!e.type)return A(e.var,n,r);switch(e.type){case p.VARIABLE:return A(e.path,n,r);case p.LITERAL:return e.value;case p.BINARY:return Ke(e,t,n,r);case p.UNARY:return Je(e,t,n,r);case p.FUNCTION:return He(e,t,n,r);default:return _(e,t,n,r)}},Ke=(e,t,n,r)=>{if(e.op===E.AND||e.op===E.OR){let l=j(e.left,t,n,r),a=j(e.right,t,n,r);switch(e.op){case E.AND:return l&&a;case E.OR:return l||a}}let o=_(e.left,t,n,r),i=_(e.right,t,n,r);switch(e.op){case E.EQ:return o==i;case E.NEQ:return o!=i;case E.GT:return o>i;case E.LT:return o<i;case E.GTE:return o>=i;case E.LTE:return o<=i;case E.IN:return Array.isArray(i)?i.includes(o):!1;case E.ADD:if(typeof o!="number"||typeof i!="number")throw new L(`Arithmetic operations require numbers. Got ${typeof o} + ${typeof i}`);return o+i;case E.SUBTRACT:if(typeof o!="number"||typeof i!="number")throw new L(`Arithmetic operations require numbers. Got ${typeof o} - ${typeof i}`);return o-i;default:throw new Error(`Unknown binary operator: ${e.op}`)}},Je=(e,t,n,r)=>{let o=e.op===z.NOT?j(e.operand,t,n,r):_(e.operand,t,n,r);if(e.op===z.NOT)return!o;throw new Error(`Unknown unary operator: ${e.op}`)},Wt=(e,t,n,r)=>{if(e.conditions.length===2&&e.conditions[1]===null){let o=e.conditions[0];if(o.type===p.VARIABLE)if(A(o.path,n,r)){let l=e.bodies[0];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?_(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=A(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=A(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=_(f,t,n,r)}return a}}else{let l=e.bodies[1];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?_(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=A(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=A(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=_(f,t,n,r)}return a}}}return null},zt=(e,t,n,r)=>{let o=Wt(e,t,n,r);if(o!==null)return o;for(let i=0;i<e.conditions.length;i++){let l=e.conditions[i];if(l===null||j(l,t,n,r))return _(e.bodies[i],t,n,r)}return Xe},Yt=(e,t)=>{let n=e.body,r=e.itemVar;if(n.type===p.CONDITIONAL&&n.conditions.length===1&&n.conditions[0].type===p.VARIABLE){let o=n.conditions[0].path,i=n.bodies[0];if(o.startsWith(r+".")){let l=o.substring(r.length+1);if(i.type===p.OBJECT&&i.properties.length<=5){for(let c of i.properties)if(c.parsedKey)return null;let a=[];for(let c=0;c<t.length;c++){let s=t[c];if(s[l]){let f={};for(let u of i.properties){let d=u.key,h=u.value;if(h.type===p.LITERAL)f[d]=h.value;else if(h.type===p.VARIABLE){let g=h.path;if(g===r)f[d]=s;else if(g.startsWith(r+".")){let y=g.substring(r.length+1);f[d]=s[y]}else return null}else if(h.type===p.INTERPOLATION){let g=[],y=!0;for(let I of h.parts)if(typeof I=="string")g.push(I);else if(I.type===p.VARIABLE){let m=I.path;if(m===r)g.push(s!=null?String(s):"");else if(m.startsWith(r+".")){let w=m.substring(r.length+1),v=s[w];g.push(v!=null?String(v):"")}else{y=!1;break}}else{y=!1;break}if(!y)return null;f[d]=g.join("")}else return null}a.push(f)}}return a}}}return null},Ht=(e,t)=>{let n=e.body,r=e.itemVar,o=Yt(e,t);if(o!==null)return o;if(n.type===p.OBJECT&&n.properties.length<=5&&!n.whenCondition){for(let a of n.properties)if(a.parsedKey)return null;let i=[],l=!0;for(let a of n.properties){let c=a.key,s=a.value;if(s.type===p.LITERAL)i.push({key:c,type:"literal",value:s.value});else if(s.type===p.VARIABLE){let f=s.path;if(f===r)i.push({key:c,type:"item"});else if(f.startsWith(r+".")){let u=f.substring(r.length+1);if(!u.includes(".")&&!u.includes("["))i.push({key:c,type:"prop",prop:u});else{l=!1;break}}else{l=!1;break}}else if(s.type===p.INTERPOLATION&&s.parts.length===1){let f=s.parts[0];if(f.type===p.VARIABLE){let u=f.path;if(u===r)i.push({key:c,type:"item_string"});else if(u.startsWith(r+".")){let d=u.substring(r.length+1);if(!d.includes(".")&&!d.includes("["))i.push({key:c,type:"prop_string",prop:d});else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}if(l){let a=new Array(t.length);if(i.length===3&&i[0].type==="prop"&&i[0].key==="id"&&i[1].type==="prop_string"&&i[1].key==="title"&&i[2].type==="prop"&&i[2].key==="completed")for(let c=0;c<t.length;c++){let s=t[c];a[c]={id:s.id,title:s.title!=null?String(s.title):"",completed:s.completed}}else for(let c=0;c<t.length;c++){let s=t[c],f={};for(let u of i)if(u.type==="literal")f[u.key]=u.value;else if(u.type==="item")f[u.key]=s;else if(u.type==="prop")f[u.key]=s[u.prop];else if(u.type==="item_string")f[u.key]=s!=null?String(s):"";else if(u.type==="prop_string"){let d=s[u.prop];f[u.key]=d!=null?String(d):""}a[c]=f}return a}}return null},Kt=(e,t,n,r,o)=>{let i=[],l=e.body;if(l.type===p.OBJECT&&l.fast!==!1){let a=e.itemVar,c=e.indexVar;for(let s=0;s<o.length;s++){let f=o[s],u={},d={...r,[a]:f,...c&&{[c]:s}};d.__paths__||(d.__paths__=r.__paths__||{});let h=e.iterable.path||"";if(r&&r.__paths__&&h){let g=h.split("."),y=g[0];y in r.__paths__&&(h=r.__paths__[y],g.length>1&&(h+="."+g.slice(1).join(".")))}d.__paths__={...d.__paths__,[a]:`${h}[${s}]`,...c&&{[c]:s}};for(let g of l.properties){let y=g.parsedKey?_(g.parsedKey,t,n,d):g.key,I=g.value;if(I.type===p.LITERAL)u[y]=I.value;else if(I.type===p.VARIABLE){let m=I.path;if(m===a)u[y]=f;else if(m===c)u[y]=s;else if(m.startsWith(a+".")){let w=m.substring(a.length+1);!w.includes(".")&&!w.includes("[")?u[y]=f[w]:u[y]=A(m,n,{...r,[a]:f,...c&&{[c]:s}})}else u[y]=A(m,n,{...r,[a]:f,...c&&{[c]:s}})}else if(I.type===p.INTERPOLATION){let m=[];for(let w of I.parts)if(typeof w=="string")m.push(w);else if(w.type===p.VARIABLE){let v=w.path,R;if(v===a)R=f;else if(v===c)R=s;else if(v.startsWith(a+".")){let ne=v.substring(a.length+1);!ne.includes(".")&&!ne.includes("[")?R=f[ne]:R=A(v,n,{...r,[a]:f,...c&&{[c]:s}})}else R=A(v,n,{...r,[a]:f,...c&&{[c]:s}});m.push(R!=null?String(R):"")}else{let v={...r,[a]:f,...c&&{[c]:s}},R=_(w,t,n,v);m.push(R!=null?String(R):"")}u[y]=m.join("")}else{let m={...r,[a]:f,...c&&{[c]:s}};u[y]=_(I,t,n,m)}}i.push(u)}return i}return null},Jt=(e,t,n)=>{let r=e.body;if(r.type===p.OBJECT&&r.properties.length===1&&r.properties[0].key==="$if item.visible"){let i=r.properties[0].value;if(i.type===p.CONDITIONAL&&i.conditions.length===1&&i.conditions[0].type===p.VARIABLE&&i.conditions[0].path==="item.visible"){let l=i.bodies[0];if(l.type===p.OBJECT&&l.properties.length===2){let a=l.properties[0],c=l.properties[1];if(a.key==="id"&&a.value.type===p.VARIABLE&&a.value.path==="item.id"&&c.key==="$if item.highlighted"&&c.value.type===p.CONDITIONAL){let s=[];for(let f=0;f<t.length;f++){let u=t[f];if(u.visible){let d={id:u.id};u.highlighted?(d.highlight=!0,d.message=`This item is highlighted: ${u.name}`):(d.highlight=!1,d.message=u.name),s.push(d)}}return s}}}}return null},Xt=(e,t,n,r)=>{let o=_(e.iterable,t,n,r);if(!Array.isArray(o)){let s,f=!1;if(e.iterable.type===p.FUNCTION){f=!0;let d=e.iterable.args.map(h=>h.type===p.LITERAL?typeof h.value=="string"?`'${h.value}'`:String(h.value):h.type===p.VARIABLE?h.path:h.type===p.FUNCTION?`${h.name}(...)`:"?").join(", ");s=`${e.iterable.name}(${d})`}else s=e.iterable.path||"undefined";let u=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${s}`;throw We(u,o,f)}if(!e.indexVar){let s=Jt(e,o,e.itemVar);if(s!==null)return s}if(!e.indexVar){let s=Ht(e,o);if(s!==null)return s}let i=Kt(e,t,n,r,o);if(i!==null)return i;let l=[],a=e.iterable.path||"";if(r&&r.__paths__&&a){let s=a.split("."),f=s[0];f in r.__paths__&&(a=r.__paths__[f],s.length>1&&(a+="."+s.slice(1).join(".")))}let c=!1;e.body.type===p.ARRAY&&(e.body.items.length<=1?c=!1:c=e.body._shouldPreserveArray??=e.body.items.some(s=>s.type===p.OBJECT&&s.properties.some(f=>f.key.startsWith("$if ")||f.key.startsWith("$when "))));for(let s=0;s<o.length;s++){let f=e.indexVar?{...r,[e.itemVar]:o[s],[e.indexVar]:s}:{...r,[e.itemVar]:o[s]};f.__paths__||(f.__paths__=r.__paths__||{}),f.__paths__={...f.__paths__,[e.itemVar]:`${a}[${s}]`},e.indexVar&&(f.__paths__[e.indexVar]=s);let u=_(e.body,t,n,f);if(Array.isArray(u)&&u.length===1&&!c){let d=u[0];l.push(d===void 0?{}:d)}else l.push(u===void 0?{}:u)}return l},Gt=(e,t,n,r)=>{if(e.whenCondition)return null;if(e.properties.length===1){let o=e.properties[0],i=o.parsedKey?_(o.parsedKey,t,n,r):o.key,l=o.value;if(l.type===p.OBJECT&&l.properties.length<=10&&!l.whenCondition){let a={},c={},s=!0;for(let f of l.properties){let u=f.parsedKey?_(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)c[u]=d.value;else if(d.type===p.VARIABLE)c[u]=A(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let y=A(g.path,n,r);h.push(y!=null?String(y):"")}else{s=!1;break}if(!s)break;c[u]=h.join("")}else if(d.type===p.OBJECT&&d.properties.length<=5){let h={};for(let g of d.properties){let y=g.key,I=g.value;if(I.type===p.LITERAL)h[y]=I.value;else if(I.type===p.VARIABLE)h[y]=A(I.path,n,r);else if(I.type===p.INTERPOLATION){let m=[];for(let w of I.parts)if(typeof w=="string")m.push(w);else if(w.type===p.VARIABLE){let v=A(w.path,n,r);m.push(v!=null?String(v):"")}else{s=!1;break}if(!s)break;h[y]=m.join("")}else{s=!1;break}}if(!s)break;c[u]=h}else{s=!1;break}}if(s)return a[i]=c,a}}return null},qt=(e,t,n,r)=>{let o=t.functions||t;if(e.whenCondition&&!j(e.whenCondition,o,n,r))return;let i=Gt(e,t,n,r);if(i!==null)return i;if(e.fast){let s={};for(let f of e.properties){let u=f.parsedKey?_(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)s[u]=d.value;else if(d.type===p.VARIABLE)s[u]=A(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let y=A(g.path,n,r);h.push(y!=null?String(y):"")}else{let y=_(g,t,n,r);h.push(y!=null?String(y):"")}s[u]=h.join("")}else s[u]=_(d,t,n,r)}return s}let l={},a=null,c=!1;for(let s of e.properties)if(!s.key.startsWith("$if ")&&!s.key.match(/^\$if\s+\w+.*:?$/)&&!s.key.startsWith("$elif")&&!s.key.startsWith("$else")&&!s.key.startsWith("$for ")){c=!0;break}for(let s of e.properties)if(s.key.startsWith("$if ")||s.key.match(/^\$if\s+\w+.*:?$/)){let f=_(s.value,t,n,r);if(!c&&f!==null&&f!==void 0)return Array.isArray(f)&&f.length===1?f[0]:f;typeof f=="object"&&f!==null&&!Array.isArray(f)&&Object.assign(l,f)}else if(s.key.startsWith("$for ")){if(e.properties.length===1)return _(s.value,t,n,r)}else{let f=s.value;if(f&&f.type===p.OBJECT&&f.properties){let u=f.properties.find(d=>d.key.startsWith("$for "));if(u){let d=_(u.value,t,n,r);d!==void 0&&(l[s.key]=d)}else{let d=_(s.value,t,n,r);d!==void 0&&(l[s.key]=d)}}else{let u=s.parsedKey?_(s.parsedKey,t,n,r):s.key,d=_(s.value,t,n,r);d!==void 0&&(l[u]=d)}}return l},Xe={},Qt=(e,t,n,r)=>{let o=[];for(let i of e.items)if(i.type===p.LOOP){let l=_(i,t,n,r);Array.isArray(l)&&i.flatten!==!1?o.push(...l):o.push(l)}else{let l=_(i,t,n,r);l!==Xe&&l!==void 0&&o.push(l)}return o},Zt=(e,t,n,r)=>{let{name:o,data:i,whenCondition:l}=e,a=t.partials||{},c=t.functions||t;if(l&&!j(l,c,n,r))return;if(!a[o])throw new L(`Partial '${o}' is not defined`);let s=r._partialStack||[];if(s.includes(o))throw new L(`Circular partial reference detected: ${o}`);let f=a[o],u=n,d={...r,_partialStack:[...s,o]};if(r){u={...n};for(let h of Object.keys(r))h.startsWith("_")||(u[h]=r[h])}if(i){let h=_(i,t,n,r);u={...u,...h}}return _(f,t,u,d)},en=(e,t,n,r)=>{let{path:o}=e,i=o.split("."),l=i[0],a=i.slice(1);if(!r||!(l in r))throw new L(`Path reference '#{${o}}' refers to '${l}' which is not a loop variable in the current scope`);if(r.__paths__||(r.__paths__={}),!(l in r.__paths__))throw new L(`Path reference '#{${o}}' cannot be resolved - path tracking may not be initialized properly`);let c=r.__paths__[l];if(typeof c=="number"){if(a.length>0)throw new L(`Path reference '#{${o}}' - cannot access properties on index variable '${l}'`);return String(c)}return a.length>0&&(c+="."+a.join(".")),c},me=Ft;var tn=/\$\{([^}]*)\}/g,nn=/#\{([^}]*)\}/g,qe=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,r,o]=n,i=rn(o,t);return{isFunction:!0,type:p.FUNCTION,name:r,args:i}},rn=(e,t={})=>e.trim()?on(e).map(r=>sn(r.trim(),t)):[],on=e=>{let t=[],n="",r=0,o=!1,i="";for(let l=0;l<e.length;l++){let a=e[l],c=l>0?e[l-1]:"";!o&&(a==='"'||a==="'")?(o=!0,i=a,n+=a):o&&a===i&&c!=="\\"?(o=!1,i="",n+=a):!o&&a==="("?(r++,n+=a):!o&&a===")"?(r--,n+=a):!o&&a===","&&r===0?(t.push(n),n=""):n+=a}return n&&t.push(n),t},sn=(e,t={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:p.LITERAL,value:parseFloat(e)};if(e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};let n=qe(e,t);if(n.isFunction)return{type:n.type,name:n.name,args:n.args};let r=e.trim(),o=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],i=-1,l=null;for(let{op:a,type:c}of o){let s=0;for(;s<r.length;){let f=D(r.substring(s),a);if(f===-1)break;let u=s+f;u>i&&(i=u,l={op:a,type:c}),s=u+a.length}}if(i!==-1)try{return x(r,t)}catch{return{type:p.VARIABLE,path:r}}return{type:p.VARIABLE,path:r}},Qe=/^\w+\(.*\)$/,an=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,ln=e=>{if(!(!e||e.trim()===""||Qe.test(e))&&an.test(e))throw e.includes("?")&&e.includes(":")?new b(`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 b(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new b(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},Ge=e=>{let t=e.trim();if(Qe.test(t))throw new b(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("["))throw new b(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(t))throw new b(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(t))throw new b(`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 b(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:p.PATH_REFERENCE,path:t}},Y=(e,t={})=>{let n=e.trim();ln(n);let r=qe(n,t);if(r.isFunction)return{type:r.type,name:r.name,args:r.args};if(n.includes("[")&&!/[\s+\-*/%|&?:]/.test(n)){let o=0;for(let i of n)i==="["?o++:i==="]"&&o--;if(o!==0)throw new Error("Invalid array index syntax")}return{type:p.VARIABLE,path:n}},be=(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,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\(#\{[^}]*\})/g,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let o=[...n.matchAll(tn)],i=[...n.matchAll(nn)],l=[...o.map(s=>({match:s,type:"variable"})),...i.map(s=>({match:s,type:"pathref"}))].sort((s,f)=>s.match.index-f.match.index);if(l.length===0){let s=n;for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);return{type:p.LITERAL,value:s}}if(l.length===1&&l[0].match[0]===n&&r.length===0){let{match:s,type:f}=l[0];try{return f==="variable"?Y(s[1],t):Ge(s[1])}catch(u){if(u.message==="Invalid array index syntax")return{type:p.LITERAL,value:n};throw u}}let a=[],c=0;for(let{match:s,type:f}of l){let[u,d]=s,h=s.index;if(h>c){let g=n.substring(c,h);for(let y=0;y<r.length;y++)g=g.replace(`__ESCAPED_${y}__`,r[y]);g&&a.push(g)}try{let g;f==="variable"?g=Y(d.trim(),t):g=Ge(d.trim()),a.push(g)}catch(g){if(g.message==="Invalid array index syntax")a.push(u);else throw g}c=h+u.length}if(c<n.length){let s=n.substring(c);for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);s&&a.push(s)}return{type:p.INTERPOLATION,parts:a}};var N=(e,t)=>typeof e=="string"?be(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?un(e,t):fn(e,t):{type:p.LITERAL,value:e},cn=e=>{let{$each:t,...n}=e;if(typeof t!="string")throw new b("$each value must be a non-empty string");let r=t.trim();if(r==="")throw new b("$each value must be a non-empty string");if(Object.keys(n).length===0)throw new b("Empty $each body not allowed");if(n.$partial!==void 0)throw new b("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${r}`]:n}},un=(e,t)=>{let n=[],r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(typeof i=="object"&&i!==null&&!Array.isArray(i)){if(i.$each!==void 0)try{let c=cn(i),s=Object.keys(c);if(s.length===1&&/^\$for(?::\w+)?\s/.test(s[0])){let f=Ze(s[0],c[s[0]],t,!0);n.push(f),r=!0;continue}}catch(c){throw c instanceof b?c:new b(c.message)}let a=Object.keys(i);if(a.length===1&&/^\$for(?::\w+)?\s/.test(a[0])){let c=Ze(a[0],i[a[0]],t);n.push(c),r=!0;continue}}let l=N(i,t);n.push(l),(l.type===p.FUNCTION||l.type===p.CONDITIONAL||l.type===p.LOOP||l.type===p.PARTIAL||l.type===p.OBJECT&&!l.fast||l.type===p.ARRAY&&!l.fast)&&(r=!0)}return{type:p.ARRAY,items:n,fast:!r}},fn=(e,t)=>{let n=[],r=!1,o=null,i=Object.entries(e),l=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new b("$partial value must be a string");if(e.$partial.trim()==="")throw new b("$partial value cannot be an empty string");let c=["$if","$elif","$else","$for"],s=[];for(let[m]of i)for(let w of c)if(m===w||m.startsWith(w+" ")||m.startsWith(w+"#")){s.push(w);break}if(s.length>0)throw new b(`Cannot use $partial with ${s.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:f,$when:u,...d}=e,h={},g=!1;for(let[m,w]of Object.entries(d)){let v=m;(m.startsWith("\\$")||m.startsWith("$$"))&&(v=m.slice(1)),h[v]=w,g=!0}let y=null;if(g&&(y=N(h,t),y.type===p.OBJECT)){let m=!1;for(let w of y.properties)if(w.value.type===p.VARIABLE||w.value.type===p.INTERPOLATION||w.value.type===p.FUNCTION||w.value.type===p.CONDITIONAL||w.value.type===p.OBJECT&&!w.value.fast||w.value.type===p.ARRAY&&!w.value.fast){m=!0;break}m&&(y.fast=!1)}let I={type:p.PARTIAL,name:f,data:y};if(u!==void 0){let m;if(typeof u=="string"){if(u.trim()==="")throw new b("Empty condition expression after '$when'");m=x(u,t)}else m={type:p.LITERAL,value:u};I.whenCondition=m}return I}for(let[c,s]of i)if(c==="$when"){if(o!==null)throw new b("Multiple '$when' directives on the same object are not allowed");if(s==null)throw new b("Missing condition expression after '$when'");let f=typeof s=="string"?s:JSON.stringify(s);if(f.trim()==="")throw new b("Empty condition expression after '$when'");o=x(f,t),r=!0}else if(c.startsWith("$when#")||c.startsWith("$when "))throw new b("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;l<i.length;){let[c,s]=i[l];if(c==="$when"){l++;continue}if(c==="$each")throw new b("$each can only be used inside arrays");if(c.startsWith("$if ")||c.match(/^\$if#\w+\s/)||c.match(/^\$if\s+\w+.*:$/)){let f=dn(i,l,t);n.push({key:c,value:f.node}),r=!0,l=f.nextIndex}else if(/^\$for(?::\w+)?\s/.test(c)){let f=c.match(/^\$for(?::(\w+))?\s/)?.[1]||"",u=f?`:${f}`:"";throw new b(`$for loops must be inside arrays - use '- $for${u} item in items:' instead of '$for${u} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(c.startsWith("$elif ")||c.startsWith("$else"))throw new b(`'${c.split(" ")[0]}' without matching '$if'`);if(c==="$if"||c==="$if:")throw new b("Missing condition expression after '$if'");{let f=N(s,t);(f.type===p.FUNCTION||f.type===p.CONDITIONAL||f.type===p.PARTIAL||f.type===p.OBJECT&&!f.fast||f.type===p.ARRAY&&!f.fast)&&(r=!0);let u=be(c,t),d={key:c,value:f};(u.type!==p.LITERAL||u.value!==c)&&(d.parsedKey=u),n.push(d),l++}}}let a={type:p.OBJECT,properties:n,fast:!r};return o&&(a.whenCondition=o),a},dn=(e,t,n={})=>{let r=[],o=[],i=t,[l,a]=e[i],c=null,s;if(l.startsWith("$if#")){let u=l.match(/^\$if#(\w+)\s+(.+)$/);if(u)c=u[1],s=u[2];else throw new b(`Invalid conditional syntax: ${l}`)}else s=l.substring(4),s.endsWith(":")&&(s=s.slice(0,-1).trim());ye(s);let f=x(s,n);for(r.push(f),o.push(N(a,n)),i++;i<e.length;){let[u,d]=e[i],h=!1,g;if(c?u.startsWith(`$elif#${c} `)?(g=u.substring(`$elif#${c} `.length),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u===`$else#${c}`||u===`$else#${c}:`)&&(h=!0,g=null):u.startsWith("$elif ")?(g=u.substring(6),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u==="$else"||u==="$else:")&&(h=!0,g=null),h){if(g===null)r.push(null);else{ye(g);let y=x(g,n);r.push(y)}if(o.push(N(d,n)),i++,g===null)break}else break}return{node:{type:p.CONDITIONAL,conditions:r,bodies:o,id:c},nextIndex:i}},x=(e,t={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let s=e.slice(1,-1),f=0,u=!0;for(let d=0;d<s.length;d++)if(s[d]==="("?f++:s[d]===")"&&f--,f<0){u=!1;break}if(u&&f===0)return x(s,t)}let n=D(e,"||");if(n!==-1)return{type:p.BINARY,op:E.OR,left:x(e.substring(0,n).trim(),t),right:x(e.substring(n+2).trim(),t)};let r=D(e,"&&");if(r!==-1)return{type:p.BINARY,op:E.AND,left:x(e.substring(0,r).trim(),t),right:x(e.substring(r+2).trim(),t)};let o=[{op:">=",type:E.GTE},{op:"<=",type:E.LTE},{op:"==",type:E.EQ},{op:"!=",type:E.NEQ},{op:">",type:E.GT},{op:"<",type:E.LT},{op:" in ",type:E.IN}];for(let{op:s,type:f}of o){let u=D(e,s);if(u!==-1)return{type:p.BINARY,op:f,left:x(e.substring(0,u).trim(),t),right:x(e.substring(u+s.length).trim(),t)}}let i=-1,l=null,a=[{op:" + ",type:E.ADD},{op:" - ",type:E.SUBTRACT}];for(let{op:s,type:f}of a){let u=0;for(;u<e.length;){let d=D(e.substring(u),s);if(d===-1)break;let h=u+d;h>i&&(i=h,l={op:s,type:f}),u=h+s.length}}if(i!==-1&&l)return{type:p.BINARY,op:l.type,left:x(e.substring(0,i).trim(),t),right:x(e.substring(i+l.op.length).trim(),t)};let c=[" * "," / "," % "];for(let s of c)if(D(e,s)!==-1)throw new b(`Arithmetic operations are not allowed in conditionals: "${s}"`);return e.startsWith("!")?{type:p.UNARY,op:z.NOT,operand:x(e.substring(1).trim(),t)}:et(e,t)},D=(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},pn=e=>{if(e=e.trim(),e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:p.LITERAL,value:""};if(e==="{}")return{type:p.LITERAL,value:{}};if(e==="[]")return{type:p.LITERAL,value:[]};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:p.LITERAL,value:t}:{type:p.VARIABLE,path:e}},et=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return Y(n,t);let o=pn(n);if(o.type===p.LITERAL)return o;if(/^[a-zA-Z_$][\w.$]*$/.test(n))return{type:p.VARIABLE,path:n};try{return Y(n,t)}catch(i){if(i.message&&i.message.includes("not supported"))return o;throw i}},hn=(e,t=!1)=>{let n=t?"$each":"$for";try{Ue(e)}catch(r){if(r instanceof b&&t){let o=r.message.replace(/\$for/g,"$each");throw new b(o.replace("Parse Error: ",""))}throw r}},Ze=(e,t,n,r=!1)=>{let o=/^\$for(?::(\w+))?\s+(.+)$/,i=e.match(o);if(!i){let I=r?"$each":"$for";throw new b(`Invalid loop syntax (got: '${e.replace("$for",I)}')`)}let l=i[1],a=i[2].trim();hn(a,r);let c=a.match(/^(.+?)\s+in\s+(.+)$/);if(!c){let I=r?"$each":"$for";throw new b(`Invalid loop syntax - missing 'in' keyword (got: '${I} ${a}')`)}let s=c[1].trim(),f=c[2].trim(),u,d=null;if(s.includes(",")){let I=s.split(",").map(m=>m.trim());if(I.length!==2)throw new b(`Invalid loop variables: ${s}. Expected format: "item" or "item, index"`);u=I[0],d=I[1]}else u=s;let h=["this","undefined","null","true","false"];if(h.includes(u))throw new b(`Reserved variable name: ${u}`);if(d&&h.includes(d))throw new b(`Reserved variable name: ${d}`);let g=et(f,n),y=N(t,n);return{type:p.LOOP,itemVar:u,indexVar:d,iterable:g,body:y,flatten:l!=="nested"}};var gn=(e,t={})=>{let{functions:n={}}=t;return N(e,n)},ee=gn;var Ie={};ht(Ie,{now:()=>yn});var yn=()=>Date.now();var mn=(e,t,n={})=>{let{functions:r={},partials:o={}}=n,i={...Ie,...r},l=ee(e,{functions:i}),a={};for(let[c,s]of Object.entries(o))a[c]=ee(s,{functions:i});return me(l,t,{functions:i,partials:a})},S=mn;var we={objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n})),formatDate:je},bn=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),In=(e,{presentationState:t,resources:n})=>{let{elements:r}=e;if(t.base){let o=r.find(i=>i.id==="story");if(!o)return e;if(t.base.resourceId){let i=n?.layouts[t.base.resourceId];i&&o.children.unshift({id:"base",type:"container",children:i.elements})}}return e},wn=(e,{presentationState:t,previousPresentationState:n,resources:r={},variables:o,autoMode:i,skipMode:l,currentLocalizationPackageId:a})=>{let{elements:c}=e,s=e.animations||[];if(t.background){let f=c.find(u=>u.id==="story");if(!f)return e;if(t.background.resourceId){let{images:u={},videos:d={}}=r,h=u[t.background.resourceId]||d[t.background.resourceId];if(h){let g=d[t.background.resourceId]!==void 0,y={id:`bg-cg-${t.background.resourceId}`,type:g?"video":"sprite",x:0,y:0,src:h.fileId,width:h.width,height:h.height};g&&(y.loop=h.loop??!1,y.volume=h.volume??500),f.children.push(y)}}if(t.background.resourceId){let{layouts:u={}}=r,d=u[t.background.resourceId];d&&f.children.push({id:`bg-cg-${t.background.resourceId}`,type:"container",children:d.elements})}if(t.background.animations){if(t.background.animations.in){let u=t.background.animations.in.resourceId,d=r?.tweens[u];d&&s.push({id:"bg-cg-animation-in",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:d.properties})}if(t.background.animations.out){let u=t.background.animations.out.resourceId,d=n?.background?.resourceId,h=r?.tweens[u];h&&d&&s.push({id:"bg-cg-animation-out",type:"tween",targetId:`bg-cg-${d}`,properties:h.properties})}if(t.background.animations.update){let u=t.background.animations.update.resourceId,d=r?.tweens[u];d&&s.push({id:"bg-cg-animation-update",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:d.properties})}}}return e},_n=(e,{presentationState:t,resources:n})=>{let{elements:r}=e,o=e.animations||[];if(t.character&&n){let i=r.find(a=>a.id==="story");if(!i)return e;let l=t.character.items||[];for(let a of l){let{transformId:c,sprites:s}=a;if(a.animations&&a.animations.out&&!s&&!c){let h=a.animations.out.resourceId,g=n?.tweens[h];if(g){let y={id:"character-animation-out",type:"tween",targetId:`character-container-${a.id}`,properties:g.properties};o.push(y)}continue}if(!s||s.length===0||!c){console.warn("Character item missing sprites or transformId:",a);continue}let f=s.map(({resourceId:h})=>h),u=n.transforms[c];if(!u){console.warn("Transform not found:",c);continue}let d={type:"container",id:`character-container-${a.id}`,x:a.x??u.x,y:a.y??u.y,anchorX:u.anchorX,anchorY:u.anchorY,rotation:u.rotation,scaleX:u.scaleX,scaleY:u.scaleY,children:[]};for(let h of s){let g=n.images[h.resourceId];if(!g){console.warn(`Image resource not found: ${h.resourceId}`);continue}d.children.push({type:"sprite",id:`${a.id}-${h.id}`,src:g.fileId,width:g.width,height:g.height,x:0,y:0})}if(i.children.push(d),a.animations){if(a.animations.in){let h=a.animations.in.resourceId,g=n?.tweens[h];g&&o.push({id:"character-animation-in",type:"tween",targetId:`character-container-${a.id}`,properties:g.properties})}if(a.animations.update){let h=a.animations.update.resourceId,g=n?.tweens[h];if(g){let y={id:"character-animation-update",type:"tween",targetId:`character-container-${a.id}`,properties:g.properties};o.push(y)}}}}}return e},En=(e,{presentationState:t,resources:n})=>{let{elements:r}=e,o=e.animations||[];if(t.visual&&n){let i=r.find(a=>a.id==="story");if(!i)return e;let l=t.visual.items;for(let a of l){if(a.resourceId){let{images:c={},videos:s={},spritesheets:f={}}=n,u=f[a.resourceId];if(u){let d=n.transforms?.[a.transformId]||{},h=a.animationName;if(h){let g=u.animations?.[h];if(!g)throw new Error(`Animation '${h}' not found in spritesheet resource '${a.resourceId}'`);let y={id:`visual-${a.id}`,type:"animated-sprite",x:a.x??d.x??0,y:a.y??d.y??0,width:a.width??100,height:a.height??100,alpha:a.alpha??1,anchorX:d.anchorX,anchorY:d.anchorY,rotation:d.rotation,scaleX:d.scaleX,scaleY:d.scaleY,spritesheetSrc:u.fileId,spritesheetData:u.jsonData,animation:{frames:g.frames,animationSpeed:a.animationSpeed??g.animationSpeed??.5,loop:a.loop??g.loop??!0}};i.children.push(y)}}else{let d=c[a.resourceId]||s[a.resourceId];if(d){let h=s[a.resourceId]!==void 0,g=n.transforms[a.transformId],y={id:`visual-${a.id}`,type:h?"video":"sprite",src:d.fileId,width:d.width,height:d.height,x:g.x,y:g.y,anchorX:g.anchorX,anchorY:g.anchorY,rotation:g.rotation,scaleX:g.scaleX,scaleY:g.scaleY};h&&(y.loop=d.loop??!1,y.volume=d.volume??500),i.children.push(y)}}}if(a.resourceId){let{layouts:c={}}=n,s=c[a.resourceId];if(s){let f=n.transforms[a.transformId];i.children.push({id:`visual-${a.id}`,type:"container",children:s.elements,x:f.x,y:f.y,anchorX:f.anchorX,anchorY:f.anchorY,rotation:f.rotation,scaleX:f.scaleX,scaleY:f.scaleY})}}if(a.animations){if(a.animations.in){let c=a.animations.in.resourceId||a.animations.in,s=n?.tweens[c];s&&o.push({id:`${a.id}-animation`,type:"tween",targetId:`visual-${a.id}`,properties:s.properties})}if(a.animations.out){let c=a.animations.out.resourceId||a.animations.out,s=n?.tweens[c];s&&o.push({id:`${a.id}-animation-2`,type:"tween",targetId:`visual-${a.id}`,properties:s.properties})}}}}return e},vn=(e,{presentationState:t,resources:n={},dialogueUIHidden:r,autoMode:o,skipMode:i,skipOnlyViewedLines:l,l10n:a,variables:c,saveSlots:s=[]})=>{let{elements:f}=e;if(!t.dialogue||r)return e;let u=f.find(d=>d.id==="story");if(!u)return e;if(t.dialogue.gui&&t.dialogue.gui.resourceId){let{layouts:d={}}=n,h=d[t.dialogue.gui.resourceId];if(h){let g;t.dialogue.characterId&&(g=n.characters[t.dialogue.characterId]),t.dialogue.character&&(g={...g,name:t.dialogue.character.name});let y={elements:h.elements},I={variables:c,autoMode:o,skipMode:i,skipOnlyViewedLines:l,saveSlots:s,dialogue:{character:{name:g?.name||""},content:t.dialogue?.content||[{text:""}],lines:t.dialogue?.lines||[]},l10n:a},m=S(y,I,{functions:we});m=S(m,{l10n:a});let w=m?.elements;if(Array.isArray(w))for(let v of w)u.children.push(structuredClone(v));else w&&u.children.push(structuredClone(w))}}return e},An=(e,{presentationState:t,resources:n})=>{let{elements:r}=e;if(t.choice&&n){let o=r.find(s=>s.id==="story");if(!o)return e;o.children.push({id:"choice-blocker",type:"rect",fill:"transparent",width:1920,height:1080,x:0,y:0,click:{actionPayload:{actions:{}}}});let i=n?.layouts[t.choice.resourceId];if(!i||!i.elements)return e;let l={elements:i.elements},c=S(l,{choice:{items:t.choice?.items??[]}})?.elements;if(Array.isArray(c))for(let s of c)o.children.push(structuredClone(s));else c&&o.children.push(structuredClone(c))}return e},xn=(e,{presentationState:t,resources:n})=>{if(t.keyboard?.resourceId){let r=n?.keyboards?.[t.keyboard.resourceId];r&&(e.global.keyboard=r)}return e},Ln=(e,{presentationState:t,resources:n})=>{let{elements:r,audio:o}=e;if(t.bgm&&n){if(!r.find(a=>a.id==="story"))return e;let l=n.sounds[t.bgm.resourceId];if(!l)return e;o.push({id:"bgm",type:"sound",src:l.fileId,loop:t.bgm.loop??!0,volume:t.bgm.volume??500,delay:t.bgm.delay??null})}return e},$n=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(t.sfx&&n){let o=t.sfx.items;for(let i of o){let l=n.sounds?.[i.resourceId];l&&r.push({id:i.id,type:"sound",src:l.fileId,loop:i.loop??l.loop??!0,volume:i.volume??l.volume??500,delay:i.delay??l.delay??null})}}return e},Cn=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(!t?.voice)return e;let{fileId:o,volume:i,loop:l}=t.voice;return r.push({id:`voice-${o}`,type:"sound",src:o,volume:i??500,loop:l??!1}),e},kn=(e,{presentationState:t,resources:n={},variables:r,autoMode:o,skipMode:i,currentLocalizationPackageId:l,saveSlots:a=[]})=>{let{elements:c}=e,s=e.animations||[];if(t.layout){let f=c.find(I=>I.id==="story");if(!f)return e;let u=n.layouts[t.layout.resourceId];if(!u)return e;Array.isArray(u.transitions)&&u.transitions.forEach(I=>{s.push(I)});let d={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:u.elements||[]},g=S(d,{variables:r,saveSlots:a,autoMode:o,skipMode:i,currentLocalizationPackageId:l},{functions:we});g=S(g,{i18n:{}});let y=I=>{let m={...I};return I.src&&I.src.startsWith("file:")&&(m.src=I.src),I.children&&Array.isArray(I.children)&&(m.children=I.children.map(y)),m};f.children.push(y(g))}return e},On=(e,{resources:t={},variables:n,autoMode:r,skipMode:o,currentLocalizationPackageId:i,layeredViews:l=[],dialogueHistory:a=[],saveSlots:c=[]})=>{let{elements:s}=e,f=e.animations||[];return l&&l.length>0&&l.forEach((u,d)=>{let h=t.layouts[u.resourceId];if(!h){console.warn(`LayeredView layout not found: ${u.resourceId}`);return}Array.isArray(h.transitions)&&h.transitions.forEach(w=>{f.push(w)});let g={id:`layeredView-${d}`,type:"container",x:0,y:0,children:h.elements||[]},y=a.map(w=>{let v=t.characters?.[w.characterId];return{...w,characterName:v?.name||""}}),I={variables:n,autoMode:r,skipMode:o,currentLocalizationPackageId:i,saveSlots:c,historyDialogue:y,characters:t.characters||{}},m=S(g,I,{functions:we});m=S(m,{i18n:{}}),s.push(m)}),e},tt=e=>Z(bn,[In,wn,_n,En,vn,An,xn,kn,Ln,$n,Cn,On])(e);var Rn=e=>{let{global:{currentLocalizationPackageId:t,saveSlots:n={},variables:r={}},projectData:o}=e,i={sceneId:o.story.initialSceneId,sectionId:o.story.scenes[o.story.initialSceneId].initialSectionId,lineId:o.story.scenes[o.story.initialSceneId].sections[o.story.scenes[o.story.initialSceneId].initialSectionId].lines[0].id},{contextVariableDefaultValues:l,globalVariablesDefaultValues:a}=De(o),c={...a,...r},s={projectData:o,global:{autoplayDelay:1e3,isLineCompleted:!1,pendingEffects:[],autoMode:!1,skipMode:!1,skipOnlyViewedLines:!0,dialogueUIHidden:!1,isDialogueHistoryShowing:!1,currentLocalizationPackageId:t,viewedRegistry:{sections:[],resources:[]},nextLineConfig:{manual:{enabled:!0,requireLineCompleted:!1},auto:{enabled:!1}},saveSlots:n,layeredViews:[],variables:c},contexts:[{currentPointerMode:"read",pointers:{read:i,history:{sectionId:void 0,lineId:void 0,historySequenceIndex:void 0}},historySequence:[{sectionId:"..."}],configuration:{},views:[],bgm:{resourceId:void 0},variables:l}]};return console.log("Initial State:",s),s},Sn=({state:e})=>e.global.layeredViews||[],Nn=({state:e})=>e.global.pendingEffects,nt=({state:e})=>e.global.skipMode,Pn=({state:e})=>e.global.skipOnlyViewedLines,Tn=({state:e})=>e.global.autoMode,rt=({state:e})=>e.global.dialogueUIHidden,Vn=({state:e})=>e.global.autoplayDelay,_e=({state:e})=>{let t=e.contexts[e.contexts.length-1];if(!t)return[];let{sectionId:n,lineId:r}=t.pointers.read,o=$({state:e},{sectionId:n});if(!o?.lines||!Array.isArray(o.lines))return[];let i=o.lines.findIndex(c=>c.id===r);return o.lines.slice(0,i+1).filter(c=>c.actions?.dialogue).map(c=>{let s=c.actions.dialogue,f="";return s.characterId&&(f=e.projectData.resources?.characters?.[s.characterId]?.name||""),{content:s.content,characterId:s.characterId,characterName:f}})},Dn=({state:e})=>e.global.currentLocalizationPackageId,ot=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(c=>c.sectionId===n);if(!o)return!1;if(o.lastLineId===void 0||r===void 0)return!0;let i=$({state:e},{sectionId:n});if(!i||!i.lines||!Array.isArray(i.lines))return!1;let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);return l===-1||a===-1?o.lastLineId===r:a<l},Mn=({state:e},t)=>{let{resourceId:n}=t;return!!e.global.viewedRegistry.resources.find(o=>o.resourceId===n)},Bn=({state:e})=>e.global.nextLineConfig,Fn=({state:e})=>e.global.saveSlots,jn=({state:e},t)=>{let{slotKey:n}=t;return e.global.saveSlots[n]},M=({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}},$=({state:e},t)=>{let{sectionId:n}=t,r=e.projectData?.story?.scenes||{};for(let o in r){let i=r[o];if(i.sections&&i.sections[n])return i.sections[n]}},Un=({state:e})=>{let t=M({state:e});if(!t?.pointer)return;let{sectionId:n,lineId:r}=t.pointer,o=$({state:e},{sectionId:n});if(!(!o?.lines||!Array.isArray(o.lines)))return o.lines.find(i=>i.id===r)},it=({state:e})=>{let{sectionId:t,lineId:n}=M({state:e}).pointer,o=$({state:e},{sectionId:t})?.lines||[],i=o.findIndex(s=>s.id===n),l=o.slice(0,i+1);console.log("currentLines",l);let a=l.map(s=>{let f=s.actions||{},u={};return Object.keys(f).forEach(d=>{u[d]=f[d]}),u});return ge(a)},Wn=({state:e})=>{let{sectionId:t,lineId:n}=M({state:e}).pointer,o=$({state:e},{sectionId:t})?.lines||[],i=o.findIndex(c=>c.id===n);if(i<=0)return null;let a=o.slice(0,i).map(c=>{let s=c.actions||{},f={};return Object.keys(s).forEach(u=>{f[u]=s[u]}),f});return ge(a)},st=({state:e},{slotsPerPage:t=6}={})=>{let o=(({...e.global.variables,...e.contexts[e.contexts.length-1].variables}.loadPage??1)-1)*t+1,i=[];for(let l=0;l<t;l++){let a=o+l,c=e.global.saveSlots&&e.global.saveSlots[a]||{};i.push({slotNumber:a,...c})}return{saveSlots:i}},zn=({state:e})=>{let t=it({state:e}),n=Wn({state:e});console.log("presentationState",t);let r={...e.global.variables,...e.contexts[e.contexts.length-1].variables},{saveSlots:o}=st({state:e}),i=tt({presentationState:t,previousPresentationState:n,resources:e.projectData.resources,l10n:e.projectData.l10n.packages[e.global.currentLocalizationPackageId],currentLocalizationPackageId:e.global.currentLocalizationPackageId,dialogueUIHidden:e.global.dialogueUIHidden,autoMode:e.global.autoMode,skipMode:e.global.skipMode,skipOnlyViewedLines:e.global.skipOnlyViewedLines,layeredViews:e.global.layeredViews,dialogueHistory:_e({state:e}),saveSlots:o,variables:r});return console.log("renderState",i),i},Yn=({state:e},t)=>(e.global.layeredViews.push(t),e.global.pendingEffects.push({name:"render"}),e),Hn=({state:e})=>(e.global.layeredViews.pop(),e.global.pendingEffects.push({name:"render"}),e),Kn=({state:e},t)=>(e.global.layeredViews.length>0&&(e.global.layeredViews[e.global.layeredViews.length-1]=t),e.global.pendingEffects.push({name:"render"}),e),Jn=({state:e})=>(e.global.layeredViews=[],e.global.pendingEffects.push({name:"render"}),e),at=({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",payload:{delay:e.global.autoplayDelay}}),e.global.pendingEffects.push({name:"render"}),e),Ee=({state:e})=>(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Xn=({state:e})=>(e.global.autoMode?Ee({state:e}):at({state:e}),e),lt=({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),te=({state:e})=>(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Gn=({state:e})=>(nt({state:e})?te({state:e}):lt({state:e}),e),qn=({state:e},t)=>{let{skipOnlyViewedLines:n}=t;return e.global.skipOnlyViewedLines=n,e.global.pendingEffects.push({name:"render"}),e},Qn=({state:e})=>(e.global.skipOnlyViewedLines=!e.global.skipOnlyViewedLines,e.global.pendingEffects.push({name:"render"}),e),ct=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),e),ut=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),e),Zn=({state:e})=>(rt({state:e})?ct({state:e}):ut({state:e}),e),er=({state:e})=>{let t=_e({state:e});return e.global.isDialogueHistoryShowing=!0,e.global.pendingEffects.push({name:"render"}),e},tr=({state:e})=>(e.global.isDialogueHistoryShowing=!1,e.global.pendingEffects.push({name:"render"}),e),nr=({state:e},t)=>{let{localizationPackageId:n}=t;return e.global.currentLocalizationPackageId=n,e.global.pendingEffects.push({name:"render"}),e},rr=({state:e})=>(e.global.pendingEffects=[],e),or=({state:e},t)=>(e.global.pendingEffects.push(t),e),ft=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(i=>i.sectionId===n);if(o){let i=$({state:e},{sectionId:n});if(i?.lines&&o.lastLineId!==void 0){let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);(l===-1||a>l)&&(o.lastLineId=r)}else o.lastLineId=r}else e.global.viewedRegistry.sections.push({sectionId:n,lastLineId:r});return e.global.pendingEffects.push({name:"render"}),e},ir=({state:e},t)=>{let{resourceId:n}=t;return e.global.viewedRegistry.resources.find(o=>o.resourceId===n)||e.global.viewedRegistry.resources.push({resourceId:n}),e.global.pendingEffects.push({name:"render"}),e},sr=({state:e},t)=>{let{manual:n,auto:r}=t,o=e.global.nextLineConfig.auto?.enabled,i=r?.enabled;return n&&r?e.global.nextLineConfig={manual:n,auto:r}:(n&&(e.global.nextLineConfig.manual=n),r&&(e.global.nextLineConfig.auto=r)),i===!0&&!o?e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}}):i===!1&&o&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.pendingEffects.push({name:"render"}),e},ar=({state:e},{delay:t})=>(e.global.autoplayDelay=t,e.global.autoMode&&(e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:e.global.autoplayDelay}})),e.global.pendingEffects.push({name:"render"}),e),lr=({state:e},t)=>{let{slot:n,thumbnailImage:r}=t,o=String(n),i={contexts:[...e.contexts],viewedRegistry:e.global.viewedRegistry},l={slotKey:o,date:Date.now(),image:r,state:i};return e.global.saveSlots[o]=l,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}},{name:"render"}),e},cr=({state:e},t)=>{let{slot:n}=t,r=String(n),o=e.global.saveSlots[r];return o&&(e.global.viewedRegistry=o.state.viewedRegistry,e.contexts=o.state.contexts,e.global.pendingEffects.push({name:"render"})),e},ur=({state:e},t)=>{let{projectData:n}=t;return e.projectData=n,e.global.pendingEffects.push({name:"render"}),e},fr=({state:e},t)=>{let{sectionId:n,lineId:r}=t;if(!r)return console.warn("jumpToLine requires lineId parameter"),e;let o=e.contexts[e.contexts.length-1];if(!o)return console.warn("No context available for jumpToLine"),e;let i=n||o.pointers.read?.sectionId;if(n&&!$({state:e},{sectionId:n}))return console.warn(`Section not found: ${n}`),e;let l=$({state:e},{sectionId:i});return!l?.lines||!Array.isArray(l.lines)?(console.warn(`Section ${i} has no lines`),e):l.lines.find(c=>c.id===r)?(o.pointers.read={sectionId:i,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 ${i}`),e)},dr=({state:e},t)=>{let{item:n}=t,r=e.contexts[e.contexts.length-1];return r&&r.historySequence&&r.historySequence.push({sectionId:n.sectionId}),e.global.pendingEffects.push({name:"render"}),e},pr=({state:e})=>{if(e.global.nextLineConfig?.auto?.enabled!==!0||e.global.nextLineConfig?.auto?.trigger!=="fromComplete")return e;let t=M({state:e})?.pointer,n=t?.sectionId,o=$({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=e.contexts[e.contexts.length-1];c&&(c.pointers.read={sectionId:n,lineId:a.id}),e.global.isLineCompleted=!1,e.global.nextLineConfig.auto={},e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"})}return e},hr=({state:e})=>{if(!e.global.nextLineConfig.manual.enabled)return e;let t=M({state:e})?.pointer,n=t?.sectionId,o=$({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l];e.global.skipMode&&e.global.skipOnlyViewedLines&&(ot({state:e},{sectionId:n,lineId:a.id})||te({state:e}));let c=e.contexts[e.contexts.length-1];if(c){let s=c.pointers.read.lineId;s&&n&&ft({state:e},{sectionId:n,lineId:s}),c.pointers.read={sectionId:n,lineId:a.id}}e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"})}else e.global.autoMode&&Ee({state:e}),e.global.skipMode&&te({state:e});return console.log("state",e),e},gr=({state:e})=>(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e),yr=({state:e},t)=>{let{sectionId:n}=t,r=$({state:e},{sectionId:n});if(!r||!r.lines||r.lines.length===0)return e;let o=r.lines,i=e.contexts[e.contexts.length-1];if(!i||!i.pointers)return e;let l=i.pointers.history||i.pointers.read;if(i.currentPointerMode!=="history"||!i.pointers.history){if(!l)return e;i.currentPointerMode="history",i.pointers.history={sectionId:n,lineId:l?.lineId};let f=o.findIndex(u=>u.id===l.lineId)-1;if(f>=0&&f<o.length){let u=o[f];i.pointers.history={sectionId:n,lineId:u.id}}return e.global.pendingEffects.push({name:"render"}),e}let c=o.findIndex(s=>s.id===i.pointers.history.lineId)-1;if(c>=0&&c<o.length){let s=o[c];i.pointers.history={sectionId:n,lineId:s.id},e.global.pendingEffects.push({name:"render"})}return e},mr=({state:e},t)=>{let{sectionId:n}=t,r=$({state:e},{sectionId:n});if(!r)return console.warn(`Section not found: ${n}`),e;let o=r.lines?.[0];if(!o)return console.warn(`Section ${n} has no lines`),e;let i=e.contexts[e.contexts.length-1];return i&&(i.pointers.read={sectionId:n,lineId:o.id}),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e},br=({state:e})=>{let t=M({state:e})?.pointer,n=t?.sectionId,o=$({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=e.contexts[e.contexts.length-1];c&&(c.pointers.read={sectionId:n,lineId:a.id}),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e.global.nextLineConfig.auto?.enabled&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}})}else e.global.nextLineConfig.auto?.enabled&&(e.global.nextLineConfig.auto.enabled=!1,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}));return e},Ir=({state:e},t)=>{let{operations:n=[]}=t,r=!1,o=!1;if(n.forEach(({variableId:i,op:l,value:a})=>{let c=e.projectData.resources?.variables?.[i],s=c?.scope,f=c?.type;Me(s,i),Be(f,l,i);let u=s==="context"?e.contexts[e.contexts.length-1].variables:e.global.variables;s==="global-device"?r=!0:s==="global-account"&&(o=!0),u[i]=Fe(u[i],l,a)}),r){let i=he(e.global.variables,e.projectData.resources?.variables,"global-device");e.global.pendingEffects.push({name:"saveGlobalDeviceVariables",payload:{globalDeviceVariables:i}})}if(o){let i=he(e.global.variables,e.projectData.resources?.variables,"global-account");e.global.pendingEffects.push({name:"saveGlobalAccountVariables",payload:{globalAccountVariables:i}})}return e.global.pendingEffects.push({name:"render"}),e},dt=e=>{let t=Rn(e);return Ve(t,{selectPendingEffects:Nn,selectSkipMode:nt,selectSkipOnlyViewedLines:Pn,selectAutoMode:Tn,selectDialogueUIHidden:rt,selectDialogueHistory:_e,selectCurrentLocalizationPackageId:Dn,selectIsLineViewed:ot,selectIsResourceViewed:Mn,selectNextLineConfig:Bn,selectSaveSlots:Fn,selectSaveSlot:jn,selectCurrentPointer:M,selectSection:$,selectCurrentLine:Un,selectPresentationState:it,selectAutoplayDelay:Vn,selectCurrentPageSlots:st,selectRenderState:zn,selectLayeredViews:Sn,startAutoMode:at,stopAutoMode:Ee,toggleAutoMode:Xn,startSkipMode:lt,stopSkipMode:te,toggleSkipMode:Gn,setSkipOnlyViewedLines:qn,toggleSkipOnlyViewedLines:Qn,showDialogueUI:ct,hideDialogueUI:ut,toggleDialogueUI:Zn,showDialogueHistory:er,hideDialogueHistory:tr,setCurrentLocalizationPackageId:nr,clearPendingEffects:rr,appendPendingEffect:or,addViewedLine:ft,addViewedResource:ir,setNextLineConfig:sr,saveSaveSlot:lr,loadSaveSlot:cr,setAutoplayDelay:ar,updateProjectData:ur,sectionTransition:mr,jumpToLine:fr,addToHistorySequence:dr,nextLine:hr,nextLineFromCompleted:pr,markLineCompleted:gr,prevLine:yr,pushLayeredView:Yn,popLayeredView:Hn,replaceLastLayeredView:Kn,clearLayeredViews:Jn,updateVariable:Ir,nextLineFromSystem:br},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function ve(e){let t,{handlePendingEffects:n}=e,r=()=>{for(;t.selectPendingEffects().length>0;){let u=[...t.selectPendingEffects()];t.clearPendingEffects(),n(u)}},o=({initialState:u})=>{t=dt(u),t.appendPendingEffect({name:"render"}),f(),r()},i=()=>t.selectPresentationState(),l=()=>t.selectRenderState(),a=()=>t.selectSaveSlots(),c=(u,d)=>{t[u]&&(t[u](d),r())},s=u=>{Object.entries(u).forEach(([d,h])=>{c(d,h)})},f=()=>{let u=t.selectCurrentLine();u&&u.actions&&s(u.actions)};return{init:o,handleAction:c,handleActions:s,selectRenderState:l,selectPresentationState:i,selectSaveSlots:a,handleLineActions:f}}var Ae=()=>{let e=0,t=null;return{getElapsed:()=>e,setElapsed:n=>{e=n},addElapsed:n=>{e+=n},getCallback:()=>t,setCallback:n=>{t=n}}},wr=({engine:e,routeGraphics:t},n)=>{let r=e.selectRenderState();t.render(r)},_r=({engine:e},t)=>{e.handleLineActions()},Er=({engine:e,ticker:t,autoTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},vr=({ticker:e,autoTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Ar=({engine:e,ticker:t,skipTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS),n.getElapsed()>=30&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},xr=({ticker:e,skipTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Lr=({engine:e,ticker:t,nextLineConfigTimerState:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}),t.remove(i),n.setCallback(null))};n.setCallback(i),t.add(i)},$r=({ticker:e,nextLineConfigTimerState:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Cr=({},e)=>{localStorage.setItem("saveSlots",JSON.stringify(e.saveSlots))},kr=({},e)=>{localStorage.setItem("globalDeviceVariables",JSON.stringify(e.globalDeviceVariables))},Or=({},e)=>{localStorage.setItem("globalAccountVariables",JSON.stringify(e.globalAccountVariables))},Rr={render:wr,saveSlots:Cr,saveGlobalDeviceVariables:kr,saveGlobalAccountVariables:Or,handleLineActions:_r,startAutoNextTimer:Er,clearAutoNextTimer:vr,startSkipNextTimer:Ar,clearSkipNextTimer:xr,nextLineConfigTimer:Lr,clearNextLineConfigTimer:$r},Sr=({getEngine:e,routeGraphics:t,ticker:n})=>{let r=Ae(),o=Ae(),i=Ae();return async l=>{let a=e(),c=l.reduce((u,d)=>(u[d.name]=d,u),{}),s=Object.values(c),f={engine:a,routeGraphics:t,ticker:n,autoTimer:r,skipTimer:o,nextLineConfigTimerState:i};for(let u of s){let d=Rr[u.name];d&&d(f,u.payload)}}},Nr=Sr;var Co=ve;export{Nr as createEffectsHandler,Co as default};
|