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