route-engine-js 0.1.9 → 0.1.11
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 ft=Object.defineProperty;var dt=(e,t)=>{for(var n in t)ft(e,n,{get:t[n],enumerable:!0})};var ke=Symbol.for("immer-nothing"),xe=Symbol.for("immer-draftable"),C=Symbol.for("immer-state");function k(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var B=Object.getPrototypeOf;function j(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 pt=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)===pt}function K(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 ht(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)||j(e)||!T(e)||(X(e)>1&&(e.set=e.add=e.clear=e.delete=gt),Object.freeze(e),t&&Object.entries(e).forEach(([n,r])=>fe(r,!0))),e}function gt(){k(2)}function Q(e){return Object.isFrozen(e)}var yt={};function V(e){let t=yt[e];return t||k(0,e),t}var U;function Ne(){return U}function mt(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(bt),e.drafts_=null}function le(e){e===U&&(U=e.parent_)}function $e(e){return U=mt(U,e)}function bt(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),k(4)),T(e)&&(e=H(t,e),t.parent_||J(t,e)),t.patches_&&V("Patches").generateReplacementPatches_(n[C].base_,e,t.patches_,t.inversePatches_)):e=H(t,n,[]),ae(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==ke?e:void 0}function H(e,t,n){if(Q(t))return t;let r=t[C];if(!r)return K(t,(o,i)=>Oe(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),K(i,(a,c)=>Oe(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 Oe(e,t,n,r,o,i,l){if(j(o)){let a=i&&t&&t.type_!==3&&!ie(t.assigned_,r)?i.concat(r):void 0,c=H(e,o,a);if(Se(n,r,c),j(c))e.canAutoFreeze_=!1;else return}else l&&n.add(o);if(T(o)&&!Q(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;H(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 It(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 wt(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(ht(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(){k(11)},getPrototypeOf(e){return B(e.base_)},setPrototypeOf(){k(12)}},W={};K(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 wt(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 _t=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,u=>n.call(this,u,...s))}}typeof n!="function"&&k(6),r!==void 0&&typeof r!="function"&&k(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===ke&&(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 k(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)||k(8),j(e)&&(e=Et(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_)&&k(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 j(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):It(e,t);return(t?t.scope_:Ne()).drafts_.push(n),n}function Et(e){return j(e)||k(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 K(n,(r,o)=>{Se(n,r,Te(o))}),t&&(t.finalized_=!1),n}var O=new _t,pe=O.produce,Nr=O.produceWithPatches.bind(O),Pr=O.setAutoFreeze.bind(O),Tr=O.setUseStrictShallowCopy.bind(O),Vr=O.applyPatches.bind(O),Dr=O.createDraft.bind(O),Mr=O.finishDraft.bind(O);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]=(...u)=>s(l(r),...u):i[c]=(...u)=>{r=pe(r,d=>s(a(d),...u))});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 vt=(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=vt(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(", ")}`)},je=(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));var At=()=>({}),xt=(e,t)=>{t.base&&(e.base={...t.base})},Lt=(e,t)=>{t.background&&(e.background={...t.background})},$t=(e,t)=>{if(!t.dialogue){e.dialogue&&e.dialogue.mode==="adv"&&(e.dialogue.content=void 0,e.dialogue.characterId=void 0);return}if(e.dialogue||(e.dialogue={}),t.dialogue.gui&&(e.dialogue.gui={...t.dialogue.gui}),t.dialogue.mode==="adv"&&(e.dialogue.content=e.dialogue.content||void 0,e.dialogue.characterId=e.dialogue.characterId||void 0,e.dialogue.mode="adv"),t.dialogue.mode==="nvl"&&(e.dialogue?.mode!=="nvl"&&(e.dialogue.lines=[]),e.dialogue.mode="nvl"),t.dialogue.content!==void 0&&(e.dialogue.content=t.dialogue.content),t.dialogue.characterId!==void 0&&(e.dialogue.characterId=t.dialogue.characterId),t.dialogue.character&&(e.dialogue.character={...t.dialogue.character}),t.dialogue.clear){delete e.dialogue;return}t.dialogue?.mode==="nvl"&&t.dialogue.content!==void 0&&(t.dialogue.clear&&(e.dialogue.lines=[]),e.dialogue.lines.push({content:t.dialogue.content}))},Ct=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},Ot=(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}}},kt=(e,t)=>{t.visual&&(e.visual=t.visual)},Rt=(e,t)=>{t.character&&(t.character.items||delete e.character,e.character=structuredClone(t.character))},St=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},Nt=(e,t)=>{t.layout?e.layout=t.layout:e.layout&&delete e.layout},Pt=(e,t)=>{t.choice?e.choice=t.choice:e.choice&&delete e.choice},Tt=(e,t)=>{t.keyboard&&(e.keyboard=t.keyboard)},Vt=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},Dt=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},ge=e=>Z(At,[Dt,xt,Lt,Ct,Ot,kt,$t,Rt,St,Nt,Pt,Tt,Vt])(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}')`)},Fe=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 Ue=(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}'`)},We=(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 Mt=(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 v(e.var,n,r);if(e.type===p.LITERAL)return e.value;if(e.type===p.VARIABLE)return v(e.path,n,r);if(e.type===p.INTERPOLATION)return jt(e.parts,t,n,r);switch(e.type){case p.FUNCTION:return Ye(e,t,n,r);case p.BINARY:return Ke(e,t,n,r);case p.UNARY:return He(e,t,n,r);case p.CONDITIONAL:return Ut(e,t,n,r);case p.LOOP:return Ht(e,t,n,r);case p.OBJECT:return Xt(e,t,n,r);case p.ARRAY:return Gt(e,t,n,r);case p.PARTIAL:return qt(e,t,n,r);case p.PATH_REFERENCE:return Qt(e,t,n,r);default:throw new Error(`Unknown node type: ${e.type}`)}},ze=new Map,Bt=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},v=(e,t,n)=>{if(!e)return;if(e in n)return n[e];let r=ze.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=Bt(c.trim());r.push(...s)}ze.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},jt=(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("")},Ye=(e,t,n,r)=>{let o=t.functions||t,i=o[e.name];if(!i)throw We(e.name,o);let l=e.args.map(a=>_(a,t,n,r));return i(...l)},F=(e,t,n,r)=>{if(e.var&&!e.type)return v(e.var,n,r);switch(e.type){case p.VARIABLE:return v(e.path,n,r);case p.LITERAL:return e.value;case p.BINARY:return Ke(e,t,n,r);case p.UNARY:return He(e,t,n,r);case p.FUNCTION:return Ye(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=F(e.left,t,n,r),a=F(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}`)}},He=(e,t,n,r)=>{let o=e.op===z.NOT?F(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}`)},Ft=(e,t,n,r)=>{if(e.conditions.length===2&&e.conditions[1]===null){let o=e.conditions[0];if(o.type===p.VARIABLE)if(v(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,u=c.value;if(u.type===p.LITERAL)a[s]=u.value;else if(u.type===p.VARIABLE)a[s]=v(u.path,n,r);else if(u.type===p.INTERPOLATION){let f=[];for(let d of u.parts)if(typeof d=="string")f.push(d);else if(d.type===p.VARIABLE){let h=v(d.path,n,r);f.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);f.push(h!=null?String(h):"")}a[s]=f.join("")}else a[s]=_(u,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,u=c.value;if(u.type===p.LITERAL)a[s]=u.value;else if(u.type===p.VARIABLE)a[s]=v(u.path,n,r);else if(u.type===p.INTERPOLATION){let f=[];for(let d of u.parts)if(typeof d=="string")f.push(d);else if(d.type===p.VARIABLE){let h=v(d.path,n,r);f.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);f.push(h!=null?String(h):"")}a[s]=f.join("")}else a[s]=_(u,t,n,r)}return a}}}return null},Ut=(e,t,n,r)=>{let o=Ft(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||F(l,t,n,r))return _(e.bodies[i],t,n,r)}return Je},Wt=(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 u={};for(let f of i.properties){let d=f.key,h=f.value;if(h.type===p.LITERAL)u[d]=h.value;else if(h.type===p.VARIABLE){let g=h.path;if(g===r)u[d]=s;else if(g.startsWith(r+".")){let y=g.substring(r.length+1);u[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),A=s[w];g.push(A!=null?String(A):"")}else{y=!1;break}}else{y=!1;break}if(!y)return null;u[d]=g.join("")}else return null}a.push(u)}}return a}}}return null},zt=(e,t)=>{let n=e.body,r=e.itemVar,o=Wt(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 u=s.path;if(u===r)i.push({key:c,type:"item"});else if(u.startsWith(r+".")){let f=u.substring(r.length+1);if(!f.includes(".")&&!f.includes("["))i.push({key:c,type:"prop",prop:f});else{l=!1;break}}else{l=!1;break}}else if(s.type===p.INTERPOLATION&&s.parts.length===1){let u=s.parts[0];if(u.type===p.VARIABLE){let f=u.path;if(f===r)i.push({key:c,type:"item_string"});else if(f.startsWith(r+".")){let d=f.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],u={};for(let f of i)if(f.type==="literal")u[f.key]=f.value;else if(f.type==="item")u[f.key]=s;else if(f.type==="prop")u[f.key]=s[f.prop];else if(f.type==="item_string")u[f.key]=s!=null?String(s):"";else if(f.type==="prop_string"){let d=s[f.prop];u[f.key]=d!=null?String(d):""}a[c]=u}return a}}return null},Yt=(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 u=o[s],f={},d={...r,[a]:u,...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)f[y]=I.value;else if(I.type===p.VARIABLE){let m=I.path;if(m===a)f[y]=u;else if(m===c)f[y]=s;else if(m.startsWith(a+".")){let w=m.substring(a.length+1);!w.includes(".")&&!w.includes("[")?f[y]=u[w]:f[y]=v(m,n,{...r,[a]:u,...c&&{[c]:s}})}else f[y]=v(m,n,{...r,[a]:u,...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 A=w.path,R;if(A===a)R=u;else if(A===c)R=s;else if(A.startsWith(a+".")){let ne=A.substring(a.length+1);!ne.includes(".")&&!ne.includes("[")?R=u[ne]:R=v(A,n,{...r,[a]:u,...c&&{[c]:s}})}else R=v(A,n,{...r,[a]:u,...c&&{[c]:s}});m.push(R!=null?String(R):"")}else{let A={...r,[a]:u,...c&&{[c]:s}},R=_(w,t,n,A);m.push(R!=null?String(R):"")}f[y]=m.join("")}else{let m={...r,[a]:u,...c&&{[c]:s}};f[y]=_(I,t,n,m)}}i.push(f)}return i}return null},Kt=(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 u=0;u<t.length;u++){let f=t[u];if(f.visible){let d={id:f.id};f.highlighted?(d.highlight=!0,d.message=`This item is highlighted: ${f.name}`):(d.highlight=!1,d.message=f.name),s.push(d)}}return s}}}}return null},Ht=(e,t,n,r)=>{let o=_(e.iterable,t,n,r);if(!Array.isArray(o)){let s,u=!1;if(e.iterable.type===p.FUNCTION){u=!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 f=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${s}`;throw Ue(f,o,u)}if(!e.indexVar){let s=Kt(e,o,e.itemVar);if(s!==null)return s}if(!e.indexVar){let s=zt(e,o);if(s!==null)return s}let i=Yt(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("."),u=s[0];u in r.__paths__&&(a=r.__paths__[u],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(u=>u.key.startsWith("$if ")||u.key.startsWith("$when "))));for(let s=0;s<o.length;s++){let u=e.indexVar?{...r,[e.itemVar]:o[s],[e.indexVar]:s}:{...r,[e.itemVar]:o[s]};u.__paths__||(u.__paths__=r.__paths__||{}),u.__paths__={...u.__paths__,[e.itemVar]:`${a}[${s}]`},e.indexVar&&(u.__paths__[e.indexVar]=s);let f=_(e.body,t,n,u);if(Array.isArray(f)&&f.length===1&&!c){let d=f[0];l.push(d===void 0?{}:d)}else l.push(f===void 0?{}:f)}return l},Jt=(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 u of l.properties){let f=u.parsedKey?_(u.parsedKey,t,n,r):u.key,d=u.value;if(d.type===p.LITERAL)c[f]=d.value;else if(d.type===p.VARIABLE)c[f]=v(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=v(g.path,n,r);h.push(y!=null?String(y):"")}else{s=!1;break}if(!s)break;c[f]=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]=v(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 A=v(w.path,n,r);m.push(A!=null?String(A):"")}else{s=!1;break}if(!s)break;h[y]=m.join("")}else{s=!1;break}}if(!s)break;c[f]=h}else{s=!1;break}}if(s)return a[i]=c,a}}return null},Xt=(e,t,n,r)=>{let o=t.functions||t;if(e.whenCondition&&!F(e.whenCondition,o,n,r))return;let i=Jt(e,t,n,r);if(i!==null)return i;if(e.fast){let s={};for(let u of e.properties){let f=u.parsedKey?_(u.parsedKey,t,n,r):u.key,d=u.value;if(d.type===p.LITERAL)s[f]=d.value;else if(d.type===p.VARIABLE)s[f]=v(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=v(g.path,n,r);h.push(y!=null?String(y):"")}else{let y=_(g,t,n,r);h.push(y!=null?String(y):"")}s[f]=h.join("")}else s[f]=_(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 u=_(s.value,t,n,r);if(!c&&u!==null&&u!==void 0)return Array.isArray(u)&&u.length===1?u[0]:u;typeof u=="object"&&u!==null&&!Array.isArray(u)&&Object.assign(l,u)}else if(s.key.startsWith("$for ")){if(e.properties.length===1)return _(s.value,t,n,r)}else{let u=s.value;if(u&&u.type===p.OBJECT&&u.properties){let f=u.properties.find(d=>d.key.startsWith("$for "));if(f){let d=_(f.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 f=s.parsedKey?_(s.parsedKey,t,n,r):s.key,d=_(s.value,t,n,r);d!==void 0&&(l[f]=d)}}return l},Je={},Gt=(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!==Je&&l!==void 0&&o.push(l)}return o},qt=(e,t,n,r)=>{let{name:o,data:i,whenCondition:l}=e,a=t.partials||{},c=t.functions||t;if(l&&!F(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 u=a[o],f=n,d={...r,_partialStack:[...s,o]};if(r){f={...n};for(let h of Object.keys(r))h.startsWith("_")||(f[h]=r[h])}if(i){let h=_(i,t,n,r);f={...f,...h}}return _(u,t,f,d)},Qt=(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=Mt;var Zt=/\$\{([^}]*)\}/g,en=/#\{([^}]*)\}/g,Ge=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,r,o]=n,i=tn(o,t);return{isFunction:!0,type:p.FUNCTION,name:r,args:i}},tn=(e,t={})=>e.trim()?nn(e).map(r=>rn(r.trim(),t)):[],nn=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},rn=(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=Ge(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 u=D(r.substring(s),a);if(u===-1)break;let f=s+u;f>i&&(i=f,l={op:a,type:c}),s=f+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+\(.*\)$/,on=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,sn=e=>{if(!(!e||e.trim()===""||qe.test(e))&&on.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}"`)},Xe=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();sn(n);let r=Ge(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,u)=>{let f=`__ESCAPED_${r.length}__`;return r.push(u),f}),n=n.replace(/\\(#\{[^}]*\})/g,(s,u)=>{let f=`__ESCAPED_${r.length}__`;return r.push(u),f}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let o=[...n.matchAll(Zt)],i=[...n.matchAll(en)],l=[...o.map(s=>({match:s,type:"variable"})),...i.map(s=>({match:s,type:"pathref"}))].sort((s,u)=>s.match.index-u.match.index);if(l.length===0){let s=n;for(let u=0;u<r.length;u++)s=s.replace(`__ESCAPED_${u}__`,r[u]);return{type:p.LITERAL,value:s}}if(l.length===1&&l[0].match[0]===n&&r.length===0){let{match:s,type:u}=l[0];try{return u==="variable"?Y(s[1],t):Xe(s[1])}catch(f){if(f.message==="Invalid array index syntax")return{type:p.LITERAL,value:n};throw f}}let a=[],c=0;for(let{match:s,type:u}of l){let[f,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;u==="variable"?g=Y(d.trim(),t):g=Xe(d.trim()),a.push(g)}catch(g){if(g.message==="Invalid array index syntax")a.push(f);else throw g}c=h+f.length}if(c<n.length){let s=n.substring(c);for(let u=0;u<r.length;u++)s=s.replace(`__ESCAPED_${u}__`,r[u]);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)?ln(e,t):cn(e,t):{type:p.LITERAL,value:e},an=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}},ln=(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=an(i),s=Object.keys(c);if(s.length===1&&/^\$for(?::\w+)?\s/.test(s[0])){let u=Qe(s[0],c[s[0]],t,!0);n.push(u),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=Qe(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}},cn=(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:u,$when:f,...d}=e,h={},g=!1;for(let[m,w]of Object.entries(d)){let A=m;(m.startsWith("\\$")||m.startsWith("$$"))&&(A=m.slice(1)),h[A]=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:u,data:y};if(f!==void 0){let m;if(typeof f=="string"){if(f.trim()==="")throw new b("Empty condition expression after '$when'");m=x(f,t)}else m={type:p.LITERAL,value:f};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 u=typeof s=="string"?s:JSON.stringify(s);if(u.trim()==="")throw new b("Empty condition expression after '$when'");o=x(u,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 u=un(i,l,t);n.push({key:c,value:u.node}),r=!0,l=u.nextIndex}else if(/^\$for(?::\w+)?\s/.test(c)){let u=c.match(/^\$for(?::(\w+))?\s/)?.[1]||"",f=u?`:${u}`:"";throw new b(`$for loops must be inside arrays - use '- $for${f} item in items:' instead of '$for${f} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(c.startsWith("$elif ")||c.startsWith("$else"))throw new b(`'${c.split(" ")[0]}' without matching '$if'`);if(c==="$if"||c==="$if:")throw new b("Missing condition expression after '$if'");{let u=N(s,t);(u.type===p.FUNCTION||u.type===p.CONDITIONAL||u.type===p.PARTIAL||u.type===p.OBJECT&&!u.fast||u.type===p.ARRAY&&!u.fast)&&(r=!0);let f=be(c,t),d={key:c,value:u};(f.type!==p.LITERAL||f.value!==c)&&(d.parsedKey=f),n.push(d),l++}}}let a={type:p.OBJECT,properties:n,fast:!r};return o&&(a.whenCondition=o),a},un=(e,t,n={})=>{let r=[],o=[],i=t,[l,a]=e[i],c=null,s;if(l.startsWith("$if#")){let f=l.match(/^\$if#(\w+)\s+(.+)$/);if(f)c=f[1],s=f[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 u=x(s,n);for(r.push(u),o.push(N(a,n)),i++;i<e.length;){let[f,d]=e[i],h=!1,g;if(c?f.startsWith(`$elif#${c} `)?(g=f.substring(`$elif#${c} `.length),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(f===`$else#${c}`||f===`$else#${c}:`)&&(h=!0,g=null):f.startsWith("$elif ")?(g=f.substring(6),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(f==="$else"||f==="$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),u=0,f=!0;for(let d=0;d<s.length;d++)if(s[d]==="("?u++:s[d]===")"&&u--,u<0){f=!1;break}if(f&&u===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:u}of o){let f=D(e,s);if(f!==-1)return{type:p.BINARY,op:u,left:x(e.substring(0,f).trim(),t),right:x(e.substring(f+s.length).trim(),t)}}let i=-1,l=null,a=[{op:" + ",type:E.ADD},{op:" - ",type:E.SUBTRACT}];for(let{op:s,type:u}of a){let f=0;for(;f<e.length;){let d=D(e.substring(f),s);if(d===-1)break;let h=f+d;h>i&&(i=h,l={op:s,type:u}),f=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)}:Ze(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},fn=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}},Ze=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return Y(n,t);let o=fn(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}},dn=(e,t=!1)=>{let n=t?"$each":"$for";try{Fe(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}},Qe=(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();dn(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(),u=c[2].trim(),f,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"`);f=I[0],d=I[1]}else f=s;let h=["this","undefined","null","true","false"];if(h.includes(f))throw new b(`Reserved variable name: ${f}`);if(d&&h.includes(d))throw new b(`Reserved variable name: ${d}`);let g=Ze(u,n),y=N(t,n);return{type:p.LOOP,itemVar:f,indexVar:d,iterable:g,body:y,flatten:l!=="nested"}};var pn=(e,t={})=>{let{functions:n={}}=t;return N(e,n)},ee=pn;var Ie={};dt(Ie,{now:()=>hn});var hn=()=>Date.now();var gn=(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=gn;var we={objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n}))},yn=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),mn=(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},bn=(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 u=c.find(f=>f.id==="story");if(!u)return e;if(t.background.resourceId){let{images:f={},videos:d={}}=r,h=f[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),u.children.push(y)}}if(t.background.resourceId){let{layouts:f={}}=r,d=f[t.background.resourceId];d&&u.children.push({id:`bg-cg-${t.background.resourceId}`,type:"container",children:d.elements})}if(t.background.animations){if(t.background.animations.in){let f=t.background.animations.in.resourceId,d=r?.tweens[f];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 f=t.background.animations.out.resourceId,d=n?.background?.resourceId,h=r?.tweens[f];h&&d&&s.push({id:"bg-cg-animation-out",type:"tween",targetId:`bg-cg-${d}`,properties:h.properties})}if(t.background.animations.update){let f=t.background.animations.update.resourceId,d=r?.tweens[f];d&&s.push({id:"bg-cg-animation-update",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:d.properties})}}}return e},In=(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 u=s.map(({resourceId:h})=>h),f=n.transforms[c];if(!f){console.warn("Transform not found:",c);continue}let d={type:"container",id:`character-container-${a.id}`,x:a.x??f.x,y:a.y??f.y,anchorX:f.anchorX,anchorY:f.anchorY,rotation:f.rotation,scaleX:f.scaleX,scaleY:f.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},wn=(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:u={}}=n,f=u[a.resourceId];if(f){let d=n.transforms?.[a.transformId]||{},h=a.animationName;if(h){let g=f.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:f.fileId,spritesheetData:f.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 u=n.transforms[a.transformId];i.children.push({id:`visual-${a.id}`,type:"container",children:s.elements,x:u.x,y:u.y,anchorX:u.anchorX,anchorY:u.anchorY,rotation:u.rotation,scaleX:u.scaleX,scaleY:u.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},_n=(e,{presentationState:t,resources:n={},dialogueUIHidden:r,autoMode:o,skipMode:i,skipOnlyViewedLines:l,l10n:a,variables:c})=>{let{elements:s}=e;if(!t.dialogue||r)return e;let u=s.find(f=>f.id==="story");if(!u)return e;if(t.dialogue.gui&&t.dialogue.gui.resourceId){let{layouts:f={}}=n,d=f[t.dialogue.gui.resourceId];if(d){let h;t.dialogue.characterId&&(h=n.characters[t.dialogue.characterId]),t.dialogue.character&&(h={...h,name:t.dialogue.character.name});let g={elements:d.elements},y={variables:c,autoMode:o,skipMode:i,skipOnlyViewedLines:l,dialogue:{character:{name:h?.name||""},content:t.dialogue?.content||[{text:""}],lines:t.dialogue?.lines||[]},l10n:a},I=S(g,y,{functions:we});I=S(I,{l10n:a});let m=I?.elements;if(Array.isArray(m))for(let w of m)u.children.push(structuredClone(w));else m&&u.children.push(structuredClone(m))}}return e},En=(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;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},vn=(e,{presentationState:t,resources:n})=>{if(t.keyboard?.resourceId){let r=n?.keyboards?.[t.keyboard.resourceId];r&&(e.global.keyboard=r)}return e},An=(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},xn=(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},Ln=(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},$n=(e,{presentationState:t,resources:n={},variables:r,autoMode:o,skipMode:i,currentLocalizationPackageId:l})=>{let{elements:a}=e,c=e.animations||[];if(t.layout){let s=a.find(y=>y.id==="story");if(!s)return e;let u=n.layouts[t.layout.resourceId];if(!u)return e;Array.isArray(u.transitions)&&u.transitions.forEach(y=>{c.push(y)});let f={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:u.elements||[]},h=S(f,{variables:r,autoMode:o,skipMode:i,currentLocalizationPackageId:l},{functions:we});h=S(h,{i18n:{}});let g=y=>{let I={...y};return y.src&&y.src.startsWith("file:")&&(I.src=y.src),y.children&&Array.isArray(y.children)&&(I.children=y.children.map(g)),I};s.children.push(g(h))}return e},Cn=(e,{resources:t={},variables:n,autoMode:r,skipMode:o,currentLocalizationPackageId:i,layeredViews:l=[],dialogueHistory:a=[]})=>{let{elements:c}=e,s=e.animations||[];return l&&l.length>0&&l.forEach((u,f)=>{let d=t.layouts[u.resourceId];if(!d){console.warn(`LayeredView layout not found: ${u.resourceId}`);return}Array.isArray(d.transitions)&&d.transitions.forEach(m=>{s.push(m)});let h={id:`layeredView-${f}`,type:"container",x:0,y:0,children:d.elements||[]},g=a.map(m=>{let w=t.characters?.[m.characterId];return{...m,characterName:w?.name||""}}),y={variables:n,autoMode:r,skipMode:o,currentLocalizationPackageId:i,historyDialogue:g,characters:t.characters||{}},I=S(h,y,{functions:we});I=S(I,{i18n:{}}),c.push(I)}),e},et=e=>Z(yn,[mn,bn,In,wn,_n,En,vn,$n,An,xn,Ln,Cn])(e);var On=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},kn=({state:e})=>e.global.layeredViews||[],Rn=({state:e})=>e.global.pendingEffects,tt=({state:e})=>e.global.skipMode,Sn=({state:e})=>e.global.skipOnlyViewedLines,Nn=({state:e})=>e.global.autoMode,nt=({state:e})=>e.global.dialogueUIHidden,Pn=({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,u="";return s.characterId&&(u=e.projectData.resources?.characters?.[s.characterId]?.name||""),{content:s.content,characterId:s.characterId,characterName:u}})},Tn=({state:e})=>e.global.currentLocalizationPackageId,rt=({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},Vn=({state:e},t)=>{let{resourceId:n}=t;return!!e.global.viewedRegistry.resources.find(o=>o.resourceId===n)},Dn=({state:e})=>e.global.nextLineConfig,Mn=({state:e})=>e.global.saveSlots,Bn=({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]}},jn=({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)},ot=({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 u=s.actions||{},f={};return Object.keys(u).forEach(d=>{f[d]=u[d]}),f});return ge(a)},Fn=({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||{},u={};return Object.keys(s).forEach(f=>{u[f]=s[f]}),u});return ge(a)},Un=({state:e})=>{let t=ot({state:e}),n=Fn({state:e});console.log("presentationState",t);let r=et({presentationState:t,previousPresentationState:n,resources:e.projectData.resources,l10n:e.projectData.l10n.packages[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}),variables:{...e.global.variables,...e.contexts[e.contexts.length-1].variables}});return console.log("renderState",r),r},Wn=({state:e},t)=>(e.global.layeredViews.push(t),e.global.pendingEffects.push({name:"render"}),e),zn=({state:e})=>(e.global.layeredViews.pop(),e.global.pendingEffects.push({name:"render"}),e),Yn=({state:e},t)=>(e.global.layeredViews.length>0&&(e.global.layeredViews[e.global.layeredViews.length-1]=t),e.global.pendingEffects.push({name:"render"}),e),Kn=({state:e})=>(e.global.layeredViews=[],e.global.pendingEffects.push({name:"render"}),e),it=({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),Hn=({state:e})=>(e.global.autoMode?Ee({state:e}):it({state:e}),e),st=({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),Jn=({state:e})=>(tt({state:e})?te({state:e}):st({state:e}),e),Xn=({state:e},t)=>{let{skipOnlyViewedLines:n}=t;return e.global.skipOnlyViewedLines=n,e.global.pendingEffects.push({name:"render"}),e},Gn=({state:e})=>(e.global.skipOnlyViewedLines=!e.global.skipOnlyViewedLines,e.global.pendingEffects.push({name:"render"}),e),at=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),e),lt=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),e),qn=({state:e})=>(nt({state:e})?at({state:e}):lt({state:e}),e),Qn=({state:e})=>{let t=_e({state:e});return e.global.isDialogueHistoryShowing=!0,e.global.pendingEffects.push({name:"render"}),e},Zn=({state:e})=>(e.global.isDialogueHistoryShowing=!1,e.global.pendingEffects.push({name:"render"}),e),er=({state:e},t)=>{let{localizationPackageId:n}=t;return e.global.currentLocalizationPackageId=n,e.global.pendingEffects.push({name:"render"}),e},tr=({state:e})=>(e.global.pendingEffects=[],e),nr=({state:e},t)=>(e.global.pendingEffects.push(t),e),ct=({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},rr=({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},or=({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},ir=({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),sr=({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},ar=({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},lr=({state:e},t)=>{let{projectData:n}=t;return e.projectData=n,e.global.pendingEffects.push({name:"render"}),e},cr=({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)},ur=({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},fr=({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},dr=({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&&(rt({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&&ct({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},pr=({state:e})=>(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e),hr=({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 u=o.findIndex(f=>f.id===l.lineId)-1;if(u>=0&&u<o.length){let f=o[u];i.pointers.history={sectionId:n,lineId:f.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},gr=({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},yr=({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},mr=({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,u=c?.type;Me(s,i),Be(u,l,i);let f=s==="context"?e.contexts[e.contexts.length-1].variables:e.global.variables;s==="global-device"?r=!0:s==="global-account"&&(o=!0),f[i]=je(f[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},ut=e=>{let t=On(e);return Ve(t,{selectPendingEffects:Rn,selectSkipMode:tt,selectSkipOnlyViewedLines:Sn,selectAutoMode:Nn,selectDialogueUIHidden:nt,selectDialogueHistory:_e,selectCurrentLocalizationPackageId:Tn,selectIsLineViewed:rt,selectIsResourceViewed:Vn,selectNextLineConfig:Dn,selectSaveSlots:Mn,selectSaveSlot:Bn,selectCurrentPointer:M,selectSection:$,selectCurrentLine:jn,selectPresentationState:ot,selectAutoplayDelay:Pn,selectRenderState:Un,selectLayeredViews:kn,startAutoMode:it,stopAutoMode:Ee,toggleAutoMode:Hn,startSkipMode:st,stopSkipMode:te,toggleSkipMode:Jn,setSkipOnlyViewedLines:Xn,toggleSkipOnlyViewedLines:Gn,showDialogueUI:at,hideDialogueUI:lt,toggleDialogueUI:qn,showDialogueHistory:Qn,hideDialogueHistory:Zn,setCurrentLocalizationPackageId:er,clearPendingEffects:tr,appendPendingEffect:nr,addViewedLine:ct,addViewedResource:rr,setNextLineConfig:or,saveSaveSlot:sr,loadSaveSlot:ar,setAutoplayDelay:ir,updateProjectData:lr,sectionTransition:gr,jumpToLine:cr,addToHistorySequence:ur,nextLine:dr,nextLineFromCompleted:fr,markLineCompleted:pr,prevLine:hr,pushLayeredView:Wn,popLayeredView:zn,replaceLastLayeredView:Yn,clearLayeredViews:Kn,updateVariable:mr,nextLineFromSystem:yr},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function ve(e){let t,{handlePendingEffects:n}=e,r=({initialState:u})=>{t=ut(u),t.appendPendingEffect({name:"render"}),s(),n(t.selectPendingEffects()),t.clearPendingEffects()},o=()=>t.selectPresentationState(),i=()=>t.selectRenderState(),l=()=>t.selectSaveSlots(),a=(u,f)=>{t[u]&&(t[u](f),n(t.selectPendingEffects()),t.clearPendingEffects())},c=u=>{Object.entries(u).forEach(([f,d])=>{a(f,d)})},s=()=>{let u=t.selectCurrentLine();u&&u.actions&&Object.entries(u.actions).forEach(([f,d])=>{t[f]&&t[f](d)})};return{init:r,handleAction:a,handleActions:c,selectRenderState:i,selectPresentationState:o,selectSaveSlots:l,handleLineActions:s}}var Ae=()=>{let e=0,t=null;return{getElapsed:()=>e,setElapsed:n=>{e=n},addElapsed:n=>{e+=n},getCallback:()=>t,setCallback:n=>{t=n}}},br=({engine:e,routeGraphics:t},n)=>{let r=e.selectRenderState();t.render(r)},Ir=({engine:e},t)=>{e.handleLineActions()},wr=({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)},_r=({ticker:e,autoTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Er=({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)},vr=({ticker:e,skipTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Ar=({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)},xr=({ticker:e,nextLineConfigTimerState:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Lr=({},e)=>{localStorage.setItem("saveSlots",JSON.stringify(e.saveSlots))},$r=({},e)=>{localStorage.setItem("globalDeviceVariables",JSON.stringify(e.globalDeviceVariables))},Cr=({},e)=>{localStorage.setItem("globalAccountVariables",JSON.stringify(e.globalAccountVariables))},Or={render:br,saveSlots:Lr,saveGlobalDeviceVariables:$r,saveGlobalAccountVariables:Cr,handleLineActions:Ir,startAutoNextTimer:wr,clearAutoNextTimer:_r,startSkipNextTimer:Er,clearSkipNextTimer:vr,nextLineConfigTimer:Ar,clearNextLineConfigTimer:xr},kr=({getEngine:e,routeGraphics:t,ticker:n})=>{let r=Ae(),o=Ae(),i=Ae();return async l=>{let a=e(),c=l.reduce((f,d)=>(f[d.name]=d,f),{}),s=Object.values(c),u={engine:a,routeGraphics:t,ticker:n,autoTimer:r,skipTimer:o,nextLineConfigTimerState:i};for(let f of s){let d=Or[f.name];d&&d(u,f.payload)}}},Rr=kr;var Lo=ve;export{Rr as createEffectsHandler,Lo as default};
|
|
1
|
+
var dt=Object.defineProperty;var pt=(e,t)=>{for(var n in t)dt(e,n,{get:t[n],enumerable:!0})};var ke=Symbol.for("immer-nothing"),xe=Symbol.for("immer-draftable"),C=Symbol.for("immer-state");function k(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var B=Object.getPrototypeOf;function j(e){return!!e&&!!e[C]}function V(e){return e?Re(e)||Array.isArray(e)||!!e[xe]||!!e.constructor?.[xe]||G(e)||q(e):!1}var ht=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)===ht}function K(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 gt(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)||j(e)||!V(e)||(X(e)>1&&(e.set=e.add=e.clear=e.delete=yt),Object.freeze(e),t&&Object.entries(e).forEach(([n,r])=>fe(r,!0))),e}function yt(){k(2)}function Q(e){return Object.isFrozen(e)}var mt={};function T(e){let t=mt[e];return t||k(0,e),t}var U;function Ne(){return U}function bt(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Le(e,t){t&&(T("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function ae(e){le(e),e.drafts_.forEach(It),e.drafts_=null}function le(e){e===U&&(U=e.parent_)}function $e(e){return U=bt(U,e)}function It(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),k(4)),V(e)&&(e=H(t,e),t.parent_||J(t,e)),t.patches_&&T("Patches").generateReplacementPatches_(n[C].base_,e,t.patches_,t.inversePatches_)):e=H(t,n,[]),ae(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==ke?e:void 0}function H(e,t,n){if(Q(t))return t;let r=t[C];if(!r)return K(t,(o,i)=>Oe(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),K(i,(a,c)=>Oe(e,r,o,a,c,n,l)),J(e,o,!1),n&&e.patches_&&T("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function Oe(e,t,n,r,o,i,l){if(j(o)){let a=i&&t&&t.type_!==3&&!ie(t.assigned_,r)?i.concat(r):void 0,c=H(e,o,a);if(Se(n,r,c),j(c))e.canAutoFreeze_=!1;else return}else l&&n.add(o);if(V(o)&&!Q(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;H(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 wt(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 _t(e,n,t);let r=n[t];return e.finalized_||!V(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(gt(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(){k(11)},getPrototypeOf(e){return B(e.base_)},setPrototypeOf(){k(12)}},W={};K(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 _t(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 Et=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,u=>n.call(this,u,...s))}}typeof n!="function"&&k(6),r!==void 0&&typeof r!="function"&&k(7);let o;if(V(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===ke&&(o=void 0),this.autoFreeze_&&fe(o,!0),r){let i=[],l=[];T("Patches").generateReplacementPatches_(t,o,i,l),r(i,l)}return o}else k(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){V(e)||k(8),j(e)&&(e=vt(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_)&&k(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=T("Patches").applyPatches_;return j(e)?r(e,t):this.produce(e,o=>r(o,t))}};function ue(e,t){let n=G(e)?T("MapSet").proxyMap_(e,t):q(e)?T("MapSet").proxySet_(e,t):wt(e,t);return(t?t.scope_:Ne()).drafts_.push(n),n}function vt(e){return j(e)||k(10,e),Ve(e)}function Ve(e){if(!V(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 K(n,(r,o)=>{Se(n,r,Ve(o))}),t&&(t.finalized_=!1),n}var O=new Et,pe=O.produce,Pr=O.produceWithPatches.bind(O),Vr=O.setAutoFreeze.bind(O),Tr=O.setUseStrictShallowCopy.bind(O),Dr=O.applyPatches.bind(O),Mr=O.createDraft.bind(O),Br=O.finishDraft.bind(O);var Te=(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]=(...u)=>s(l(r),...u):i[c]=(...u)=>{r=pe(r,d=>s(a(d),...u))});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 At=(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=At(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(", ")}`)},je=(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));var xt=()=>({}),Lt=(e,t)=>{t.base&&(e.base={...t.base})},$t=(e,t)=>{t.background&&(e.background={...t.background})},Ct=(e,t)=>{if(!t.dialogue){e.dialogue&&e.dialogue.mode==="adv"&&(e.dialogue.content=void 0,e.dialogue.characterId=void 0);return}if(e.dialogue||(e.dialogue={}),t.dialogue.gui&&(e.dialogue.gui={...t.dialogue.gui}),t.dialogue.mode==="adv"&&(e.dialogue.content=e.dialogue.content||void 0,e.dialogue.characterId=e.dialogue.characterId||void 0,e.dialogue.mode="adv"),t.dialogue.mode==="nvl"&&(e.dialogue?.mode!=="nvl"&&(e.dialogue.lines=[]),e.dialogue.mode="nvl"),t.dialogue.content!==void 0&&(e.dialogue.content=t.dialogue.content),t.dialogue.characterId!==void 0&&(e.dialogue.characterId=t.dialogue.characterId),t.dialogue.character&&(e.dialogue.character={...t.dialogue.character}),t.dialogue.clear){delete e.dialogue;return}t.dialogue?.mode==="nvl"&&t.dialogue.content!==void 0&&(t.dialogue.clear&&(e.dialogue.lines=[]),e.dialogue.lines.push({content:t.dialogue.content}))},Ot=(e,t)=>{t.sfx?e.sfx=t.sfx:e.sfx&&delete e.sfx},kt=(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}}},Rt=(e,t)=>{t.visual&&(e.visual=t.visual)},St=(e,t)=>{t.character&&(t.character.items||delete e.character,e.character=structuredClone(t.character))},Nt=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},Pt=(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},Tt=(e,t)=>{t.keyboard&&(e.keyboard=t.keyboard)},Dt=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},Mt=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},ge=e=>Z(xt,[Mt,Lt,$t,Ot,kt,Rt,Ct,St,Nt,Pt,Vt,Tt,Dt])(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}')`)},Fe=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 Ue=(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}'`)},We=(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 Bt=(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 Ft(e.parts,t,n,r);switch(e.type){case p.FUNCTION:return Ye(e,t,n,r);case p.BINARY:return Ke(e,t,n,r);case p.UNARY:return He(e,t,n,r);case p.CONDITIONAL:return Wt(e,t,n,r);case p.LOOP:return Jt(e,t,n,r);case p.OBJECT:return Gt(e,t,n,r);case p.ARRAY:return qt(e,t,n,r);case p.PARTIAL:return Qt(e,t,n,r);case p.PATH_REFERENCE:return Zt(e,t,n,r);default:throw new Error(`Unknown node type: ${e.type}`)}},ze=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=ze.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)}ze.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},Ft=(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("")},Ye=(e,t,n,r)=>{let o=t.functions||t,i=o[e.name];if(!i)throw We(e.name,o);let l=e.args.map(a=>_(a,t,n,r));return i(...l)},F=(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 He(e,t,n,r);case p.FUNCTION:return Ye(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=F(e.left,t,n,r),a=F(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}`)}},He=(e,t,n,r)=>{let o=e.op===z.NOT?F(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}`)},Ut=(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,u=c.value;if(u.type===p.LITERAL)a[s]=u.value;else if(u.type===p.VARIABLE)a[s]=A(u.path,n,r);else if(u.type===p.INTERPOLATION){let f=[];for(let d of u.parts)if(typeof d=="string")f.push(d);else if(d.type===p.VARIABLE){let h=A(d.path,n,r);f.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);f.push(h!=null?String(h):"")}a[s]=f.join("")}else a[s]=_(u,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,u=c.value;if(u.type===p.LITERAL)a[s]=u.value;else if(u.type===p.VARIABLE)a[s]=A(u.path,n,r);else if(u.type===p.INTERPOLATION){let f=[];for(let d of u.parts)if(typeof d=="string")f.push(d);else if(d.type===p.VARIABLE){let h=A(d.path,n,r);f.push(h!=null?String(h):"")}else{let h=_(d,t,n,r);f.push(h!=null?String(h):"")}a[s]=f.join("")}else a[s]=_(u,t,n,r)}return a}}}return null},Wt=(e,t,n,r)=>{let o=Ut(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||F(l,t,n,r))return _(e.bodies[i],t,n,r)}return Je},zt=(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 u={};for(let f of i.properties){let d=f.key,h=f.value;if(h.type===p.LITERAL)u[d]=h.value;else if(h.type===p.VARIABLE){let g=h.path;if(g===r)u[d]=s;else if(g.startsWith(r+".")){let y=g.substring(r.length+1);u[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;u[d]=g.join("")}else return null}a.push(u)}}return a}}}return null},Yt=(e,t)=>{let n=e.body,r=e.itemVar,o=zt(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 u=s.path;if(u===r)i.push({key:c,type:"item"});else if(u.startsWith(r+".")){let f=u.substring(r.length+1);if(!f.includes(".")&&!f.includes("["))i.push({key:c,type:"prop",prop:f});else{l=!1;break}}else{l=!1;break}}else if(s.type===p.INTERPOLATION&&s.parts.length===1){let u=s.parts[0];if(u.type===p.VARIABLE){let f=u.path;if(f===r)i.push({key:c,type:"item_string"});else if(f.startsWith(r+".")){let d=f.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],u={};for(let f of i)if(f.type==="literal")u[f.key]=f.value;else if(f.type==="item")u[f.key]=s;else if(f.type==="prop")u[f.key]=s[f.prop];else if(f.type==="item_string")u[f.key]=s!=null?String(s):"";else if(f.type==="prop_string"){let d=s[f.prop];u[f.key]=d!=null?String(d):""}a[c]=u}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 u=o[s],f={},d={...r,[a]:u,...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)f[y]=I.value;else if(I.type===p.VARIABLE){let m=I.path;if(m===a)f[y]=u;else if(m===c)f[y]=s;else if(m.startsWith(a+".")){let w=m.substring(a.length+1);!w.includes(".")&&!w.includes("[")?f[y]=u[w]:f[y]=A(m,n,{...r,[a]:u,...c&&{[c]:s}})}else f[y]=A(m,n,{...r,[a]:u,...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=u;else if(v===c)R=s;else if(v.startsWith(a+".")){let ne=v.substring(a.length+1);!ne.includes(".")&&!ne.includes("[")?R=u[ne]:R=A(v,n,{...r,[a]:u,...c&&{[c]:s}})}else R=A(v,n,{...r,[a]:u,...c&&{[c]:s}});m.push(R!=null?String(R):"")}else{let v={...r,[a]:u,...c&&{[c]:s}},R=_(w,t,n,v);m.push(R!=null?String(R):"")}f[y]=m.join("")}else{let m={...r,[a]:u,...c&&{[c]:s}};f[y]=_(I,t,n,m)}}i.push(f)}return i}return null},Ht=(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 u=0;u<t.length;u++){let f=t[u];if(f.visible){let d={id:f.id};f.highlighted?(d.highlight=!0,d.message=`This item is highlighted: ${f.name}`):(d.highlight=!1,d.message=f.name),s.push(d)}}return s}}}}return null},Jt=(e,t,n,r)=>{let o=_(e.iterable,t,n,r);if(!Array.isArray(o)){let s,u=!1;if(e.iterable.type===p.FUNCTION){u=!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 f=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${s}`;throw Ue(f,o,u)}if(!e.indexVar){let s=Ht(e,o,e.itemVar);if(s!==null)return s}if(!e.indexVar){let s=Yt(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("."),u=s[0];u in r.__paths__&&(a=r.__paths__[u],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(u=>u.key.startsWith("$if ")||u.key.startsWith("$when "))));for(let s=0;s<o.length;s++){let u=e.indexVar?{...r,[e.itemVar]:o[s],[e.indexVar]:s}:{...r,[e.itemVar]:o[s]};u.__paths__||(u.__paths__=r.__paths__||{}),u.__paths__={...u.__paths__,[e.itemVar]:`${a}[${s}]`},e.indexVar&&(u.__paths__[e.indexVar]=s);let f=_(e.body,t,n,u);if(Array.isArray(f)&&f.length===1&&!c){let d=f[0];l.push(d===void 0?{}:d)}else l.push(f===void 0?{}:f)}return l},Xt=(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 u of l.properties){let f=u.parsedKey?_(u.parsedKey,t,n,r):u.key,d=u.value;if(d.type===p.LITERAL)c[f]=d.value;else if(d.type===p.VARIABLE)c[f]=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[f]=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[f]=h}else{s=!1;break}}if(s)return a[i]=c,a}}return null},Gt=(e,t,n,r)=>{let o=t.functions||t;if(e.whenCondition&&!F(e.whenCondition,o,n,r))return;let i=Xt(e,t,n,r);if(i!==null)return i;if(e.fast){let s={};for(let u of e.properties){let f=u.parsedKey?_(u.parsedKey,t,n,r):u.key,d=u.value;if(d.type===p.LITERAL)s[f]=d.value;else if(d.type===p.VARIABLE)s[f]=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[f]=h.join("")}else s[f]=_(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 u=_(s.value,t,n,r);if(!c&&u!==null&&u!==void 0)return Array.isArray(u)&&u.length===1?u[0]:u;typeof u=="object"&&u!==null&&!Array.isArray(u)&&Object.assign(l,u)}else if(s.key.startsWith("$for ")){if(e.properties.length===1)return _(s.value,t,n,r)}else{let u=s.value;if(u&&u.type===p.OBJECT&&u.properties){let f=u.properties.find(d=>d.key.startsWith("$for "));if(f){let d=_(f.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 f=s.parsedKey?_(s.parsedKey,t,n,r):s.key,d=_(s.value,t,n,r);d!==void 0&&(l[f]=d)}}return l},Je={},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!==Je&&l!==void 0&&o.push(l)}return o},Qt=(e,t,n,r)=>{let{name:o,data:i,whenCondition:l}=e,a=t.partials||{},c=t.functions||t;if(l&&!F(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 u=a[o],f=n,d={...r,_partialStack:[...s,o]};if(r){f={...n};for(let h of Object.keys(r))h.startsWith("_")||(f[h]=r[h])}if(i){let h=_(i,t,n,r);f={...f,...h}}return _(u,t,f,d)},Zt=(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=Bt;var en=/\$\{([^}]*)\}/g,tn=/#\{([^}]*)\}/g,Ge=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,r,o]=n,i=nn(o,t);return{isFunction:!0,type:p.FUNCTION,name:r,args:i}},nn=(e,t={})=>e.trim()?rn(e).map(r=>on(r.trim(),t)):[],rn=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},on=(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=Ge(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 u=D(r.substring(s),a);if(u===-1)break;let f=s+u;f>i&&(i=f,l={op:a,type:c}),s=f+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+\(.*\)$/,sn=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,an=e=>{if(!(!e||e.trim()===""||qe.test(e))&&sn.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}"`)},Xe=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();an(n);let r=Ge(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,u)=>{let f=`__ESCAPED_${r.length}__`;return r.push(u),f}),n=n.replace(/\\(#\{[^}]*\})/g,(s,u)=>{let f=`__ESCAPED_${r.length}__`;return r.push(u),f}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let o=[...n.matchAll(en)],i=[...n.matchAll(tn)],l=[...o.map(s=>({match:s,type:"variable"})),...i.map(s=>({match:s,type:"pathref"}))].sort((s,u)=>s.match.index-u.match.index);if(l.length===0){let s=n;for(let u=0;u<r.length;u++)s=s.replace(`__ESCAPED_${u}__`,r[u]);return{type:p.LITERAL,value:s}}if(l.length===1&&l[0].match[0]===n&&r.length===0){let{match:s,type:u}=l[0];try{return u==="variable"?Y(s[1],t):Xe(s[1])}catch(f){if(f.message==="Invalid array index syntax")return{type:p.LITERAL,value:n};throw f}}let a=[],c=0;for(let{match:s,type:u}of l){let[f,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;u==="variable"?g=Y(d.trim(),t):g=Xe(d.trim()),a.push(g)}catch(g){if(g.message==="Invalid array index syntax")a.push(f);else throw g}c=h+f.length}if(c<n.length){let s=n.substring(c);for(let u=0;u<r.length;u++)s=s.replace(`__ESCAPED_${u}__`,r[u]);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)?cn(e,t):un(e,t):{type:p.LITERAL,value:e},ln=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}},cn=(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=ln(i),s=Object.keys(c);if(s.length===1&&/^\$for(?::\w+)?\s/.test(s[0])){let u=Qe(s[0],c[s[0]],t,!0);n.push(u),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=Qe(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}},un=(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:u,$when:f,...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:u,data:y};if(f!==void 0){let m;if(typeof f=="string"){if(f.trim()==="")throw new b("Empty condition expression after '$when'");m=x(f,t)}else m={type:p.LITERAL,value:f};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 u=typeof s=="string"?s:JSON.stringify(s);if(u.trim()==="")throw new b("Empty condition expression after '$when'");o=x(u,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 u=fn(i,l,t);n.push({key:c,value:u.node}),r=!0,l=u.nextIndex}else if(/^\$for(?::\w+)?\s/.test(c)){let u=c.match(/^\$for(?::(\w+))?\s/)?.[1]||"",f=u?`:${u}`:"";throw new b(`$for loops must be inside arrays - use '- $for${f} item in items:' instead of '$for${f} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(c.startsWith("$elif ")||c.startsWith("$else"))throw new b(`'${c.split(" ")[0]}' without matching '$if'`);if(c==="$if"||c==="$if:")throw new b("Missing condition expression after '$if'");{let u=N(s,t);(u.type===p.FUNCTION||u.type===p.CONDITIONAL||u.type===p.PARTIAL||u.type===p.OBJECT&&!u.fast||u.type===p.ARRAY&&!u.fast)&&(r=!0);let f=be(c,t),d={key:c,value:u};(f.type!==p.LITERAL||f.value!==c)&&(d.parsedKey=f),n.push(d),l++}}}let a={type:p.OBJECT,properties:n,fast:!r};return o&&(a.whenCondition=o),a},fn=(e,t,n={})=>{let r=[],o=[],i=t,[l,a]=e[i],c=null,s;if(l.startsWith("$if#")){let f=l.match(/^\$if#(\w+)\s+(.+)$/);if(f)c=f[1],s=f[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 u=x(s,n);for(r.push(u),o.push(N(a,n)),i++;i<e.length;){let[f,d]=e[i],h=!1,g;if(c?f.startsWith(`$elif#${c} `)?(g=f.substring(`$elif#${c} `.length),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(f===`$else#${c}`||f===`$else#${c}:`)&&(h=!0,g=null):f.startsWith("$elif ")?(g=f.substring(6),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(f==="$else"||f==="$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),u=0,f=!0;for(let d=0;d<s.length;d++)if(s[d]==="("?u++:s[d]===")"&&u--,u<0){f=!1;break}if(f&&u===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:u}of o){let f=D(e,s);if(f!==-1)return{type:p.BINARY,op:u,left:x(e.substring(0,f).trim(),t),right:x(e.substring(f+s.length).trim(),t)}}let i=-1,l=null,a=[{op:" + ",type:E.ADD},{op:" - ",type:E.SUBTRACT}];for(let{op:s,type:u}of a){let f=0;for(;f<e.length;){let d=D(e.substring(f),s);if(d===-1)break;let h=f+d;h>i&&(i=h,l={op:s,type:u}),f=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)}:Ze(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},dn=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}},Ze=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return Y(n,t);let o=dn(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}},pn=(e,t=!1)=>{let n=t?"$each":"$for";try{Fe(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}},Qe=(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();pn(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(),u=c[2].trim(),f,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"`);f=I[0],d=I[1]}else f=s;let h=["this","undefined","null","true","false"];if(h.includes(f))throw new b(`Reserved variable name: ${f}`);if(d&&h.includes(d))throw new b(`Reserved variable name: ${d}`);let g=Ze(u,n),y=N(t,n);return{type:p.LOOP,itemVar:f,indexVar:d,iterable:g,body:y,flatten:l!=="nested"}};var hn=(e,t={})=>{let{functions:n={}}=t;return N(e,n)},ee=hn;var Ie={};pt(Ie,{now:()=>gn});var gn=()=>Date.now();var yn=(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=yn;var we={objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n}))},mn=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),bn=(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},In=(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 u=c.find(f=>f.id==="story");if(!u)return e;if(t.background.resourceId){let{images:f={},videos:d={}}=r,h=f[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),u.children.push(y)}}if(t.background.resourceId){let{layouts:f={}}=r,d=f[t.background.resourceId];d&&u.children.push({id:`bg-cg-${t.background.resourceId}`,type:"container",children:d.elements})}if(t.background.animations){if(t.background.animations.in){let f=t.background.animations.in.resourceId,d=r?.tweens[f];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 f=t.background.animations.out.resourceId,d=n?.background?.resourceId,h=r?.tweens[f];h&&d&&s.push({id:"bg-cg-animation-out",type:"tween",targetId:`bg-cg-${d}`,properties:h.properties})}if(t.background.animations.update){let f=t.background.animations.update.resourceId,d=r?.tweens[f];d&&s.push({id:"bg-cg-animation-update",type:"tween",targetId:`bg-cg-${t.background.resourceId}`,properties:d.properties})}}}return e},wn=(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 u=s.map(({resourceId:h})=>h),f=n.transforms[c];if(!f){console.warn("Transform not found:",c);continue}let d={type:"container",id:`character-container-${a.id}`,x:a.x??f.x,y:a.y??f.y,anchorX:f.anchorX,anchorY:f.anchorY,rotation:f.rotation,scaleX:f.scaleX,scaleY:f.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},_n=(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:u={}}=n,f=u[a.resourceId];if(f){let d=n.transforms?.[a.transformId]||{},h=a.animationName;if(h){let g=f.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:f.fileId,spritesheetData:f.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 u=n.transforms[a.transformId];i.children.push({id:`visual-${a.id}`,type:"container",children:s.elements,x:u.x,y:u.y,anchorX:u.anchorX,anchorY:u.anchorY,rotation:u.rotation,scaleX:u.scaleX,scaleY:u.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},En=(e,{presentationState:t,resources:n={},dialogueUIHidden:r,autoMode:o,skipMode:i,skipOnlyViewedLines:l,l10n:a,variables:c,saveSlots:s=[]})=>{let{elements:u}=e;if(!t.dialogue||r)return e;let f=u.find(d=>d.id==="story");if(!f)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)f.children.push(structuredClone(v));else w&&f.children.push(structuredClone(w))}}return e},vn=(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;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},An=(e,{presentationState:t,resources:n})=>{if(t.keyboard?.resourceId){let r=n?.keyboards?.[t.keyboard.resourceId];r&&(e.global.keyboard=r)}return e},xn=(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},Ln=(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},$n=(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},Cn=(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 u=c.find(I=>I.id==="story");if(!u)return e;let f=n.layouts[t.layout.resourceId];if(!f)return e;Array.isArray(f.transitions)&&f.transitions.forEach(I=>{s.push(I)});let d={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:f.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};u.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,u=e.animations||[];return l&&l.length>0&&l.forEach((f,d)=>{let h=t.layouts[f.resourceId];if(!h){console.warn(`LayeredView layout not found: ${f.resourceId}`);return}Array.isArray(h.transitions)&&h.transitions.forEach(w=>{u.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},et=e=>Z(mn,[bn,In,wn,_n,En,vn,An,Cn,xn,Ln,$n,On])(e);var kn=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},Rn=({state:e})=>e.global.layeredViews||[],Sn=({state:e})=>e.global.pendingEffects,tt=({state:e})=>e.global.skipMode,Nn=({state:e})=>e.global.skipOnlyViewedLines,Pn=({state:e})=>e.global.autoMode,nt=({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,u="";return s.characterId&&(u=e.projectData.resources?.characters?.[s.characterId]?.name||""),{content:s.content,characterId:s.characterId,characterName:u}})},Tn=({state:e})=>e.global.currentLocalizationPackageId,rt=({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},Dn=({state:e},t)=>{let{resourceId:n}=t;return!!e.global.viewedRegistry.resources.find(o=>o.resourceId===n)},Mn=({state:e})=>e.global.nextLineConfig,Bn=({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]}},Fn=({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)},ot=({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 u=s.actions||{},f={};return Object.keys(u).forEach(d=>{f[d]=u[d]}),f});return ge(a)},Un=({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||{},u={};return Object.keys(s).forEach(f=>{u[f]=s[f]}),u});return ge(a)},it=({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}},Wn=({state:e})=>{let t=ot({state:e}),n=Un({state:e});console.log("presentationState",t);let r={...e.global.variables,...e.contexts[e.contexts.length-1].variables},{saveSlots:o}=it({state:e}),i=et({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},zn=({state:e},t)=>(e.global.layeredViews.push(t),e.global.pendingEffects.push({name:"render"}),e),Yn=({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),Hn=({state:e})=>(e.global.layeredViews=[],e.global.pendingEffects.push({name:"render"}),e),st=({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),Jn=({state:e})=>(e.global.autoMode?Ee({state:e}):st({state:e}),e),at=({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),Xn=({state:e})=>(tt({state:e})?te({state:e}):at({state:e}),e),Gn=({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),lt=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),e),ct=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),e),Qn=({state:e})=>(nt({state:e})?lt({state:e}):ct({state:e}),e),Zn=({state:e})=>{let t=_e({state:e});return e.global.isDialogueHistoryShowing=!0,e.global.pendingEffects.push({name:"render"}),e},er=({state:e})=>(e.global.isDialogueHistoryShowing=!1,e.global.pendingEffects.push({name:"render"}),e),tr=({state:e},t)=>{let{localizationPackageId:n}=t;return e.global.currentLocalizationPackageId=n,e.global.pendingEffects.push({name:"render"}),e},nr=({state:e})=>(e.global.pendingEffects=[],e),rr=({state:e},t)=>(e.global.pendingEffects.push(t),e),ut=({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},or=({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},ir=({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},sr=({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),ar=({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},lr=({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},cr=({state:e},t)=>{let{projectData:n}=t;return e.projectData=n,e.global.pendingEffects.push({name:"render"}),e},ur=({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)},fr=({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},dr=({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},pr=({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&&(rt({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&&ut({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},hr=({state:e})=>(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e),gr=({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 u=o.findIndex(f=>f.id===l.lineId)-1;if(u>=0&&u<o.length){let f=o[u];i.pointers.history={sectionId:n,lineId:f.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},yr=({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},mr=({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},br=({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,u=c?.type;Me(s,i),Be(u,l,i);let f=s==="context"?e.contexts[e.contexts.length-1].variables:e.global.variables;s==="global-device"?r=!0:s==="global-account"&&(o=!0),f[i]=je(f[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},ft=e=>{let t=kn(e);return Te(t,{selectPendingEffects:Sn,selectSkipMode:tt,selectSkipOnlyViewedLines:Nn,selectAutoMode:Pn,selectDialogueUIHidden:nt,selectDialogueHistory:_e,selectCurrentLocalizationPackageId:Tn,selectIsLineViewed:rt,selectIsResourceViewed:Dn,selectNextLineConfig:Mn,selectSaveSlots:Bn,selectSaveSlot:jn,selectCurrentPointer:M,selectSection:$,selectCurrentLine:Fn,selectPresentationState:ot,selectAutoplayDelay:Vn,selectCurrentPageSlots:it,selectRenderState:Wn,selectLayeredViews:Rn,startAutoMode:st,stopAutoMode:Ee,toggleAutoMode:Jn,startSkipMode:at,stopSkipMode:te,toggleSkipMode:Xn,setSkipOnlyViewedLines:Gn,toggleSkipOnlyViewedLines:qn,showDialogueUI:lt,hideDialogueUI:ct,toggleDialogueUI:Qn,showDialogueHistory:Zn,hideDialogueHistory:er,setCurrentLocalizationPackageId:tr,clearPendingEffects:nr,appendPendingEffect:rr,addViewedLine:ut,addViewedResource:or,setNextLineConfig:ir,saveSaveSlot:ar,loadSaveSlot:lr,setAutoplayDelay:sr,updateProjectData:cr,sectionTransition:yr,jumpToLine:ur,addToHistorySequence:fr,nextLine:pr,nextLineFromCompleted:dr,markLineCompleted:hr,prevLine:gr,pushLayeredView:zn,popLayeredView:Yn,replaceLastLayeredView:Kn,clearLayeredViews:Hn,updateVariable:br,nextLineFromSystem:mr},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function ve(e){let t,{handlePendingEffects:n}=e,r=({initialState:u})=>{t=ft(u),t.appendPendingEffect({name:"render"}),s(),n(t.selectPendingEffects()),t.clearPendingEffects()},o=()=>t.selectPresentationState(),i=()=>t.selectRenderState(),l=()=>t.selectSaveSlots(),a=(u,f)=>{t[u]&&(t[u](f),n(t.selectPendingEffects()),t.clearPendingEffects())},c=u=>{Object.entries(u).forEach(([f,d])=>{a(f,d)})},s=()=>{let u=t.selectCurrentLine();u&&u.actions&&Object.entries(u.actions).forEach(([f,d])=>{t[f]&&t[f](d)})};return{init:r,handleAction:a,handleActions:c,selectRenderState:i,selectPresentationState:o,selectSaveSlots:l,handleLineActions:s}}var Ae=()=>{let e=0,t=null;return{getElapsed:()=>e,setElapsed:n=>{e=n},addElapsed:n=>{e+=n},getCallback:()=>t,setCallback:n=>{t=n}}},Ir=({engine:e,routeGraphics:t},n)=>{let r=e.selectRenderState();t.render(r)},wr=({engine:e},t)=>{e.handleLineActions()},_r=({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)},Er=({ticker:e,autoTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},vr=({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)},Ar=({ticker:e,skipTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},xr=({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)},Lr=({ticker:e,nextLineConfigTimerState:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},$r=({},e)=>{localStorage.setItem("saveSlots",JSON.stringify(e.saveSlots))},Cr=({},e)=>{localStorage.setItem("globalDeviceVariables",JSON.stringify(e.globalDeviceVariables))},Or=({},e)=>{localStorage.setItem("globalAccountVariables",JSON.stringify(e.globalAccountVariables))},kr={render:Ir,saveSlots:$r,saveGlobalDeviceVariables:Cr,saveGlobalAccountVariables:Or,handleLineActions:wr,startAutoNextTimer:_r,clearAutoNextTimer:Er,startSkipNextTimer:vr,clearSkipNextTimer:Ar,nextLineConfigTimer:xr,clearNextLineConfigTimer:Lr},Rr=({getEngine:e,routeGraphics:t,ticker:n})=>{let r=Ae(),o=Ae(),i=Ae();return async l=>{let a=e(),c=l.reduce((f,d)=>(f[d.name]=d,f),{}),s=Object.values(c),u={engine:a,routeGraphics:t,ticker:n,autoTimer:r,skipTimer:o,nextLineConfigTimerState:i};for(let f of s){let d=kr[f.name];d&&d(u,f.payload)}}},Sr=Rr;var $o=ve;export{Sr as createEffectsHandler,$o as default};
|