route-engine-js 0.1.37 → 0.2.2
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 tn=Object.defineProperty;var nn=(e,t)=>{for(var n in t)tn(e,n,{get:t[n],enumerable:!0})};var tt=Symbol.for("immer-nothing"),Xe=Symbol.for("immer-draftable"),R=Symbol.for("immer-state");function V(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var z=Object.getPrototypeOf;function Y(e){return!!e&&!!e[R]}function j(e){return e?nt(e)||Array.isArray(e)||!!e[Xe]||!!e.constructor?.[Xe]||ue(e)||fe(e):!1}var rn=Object.prototype.constructor.toString();function nt(e){if(!e||typeof e!="object")return!1;let t=z(e);if(t===null)return!0;let n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return n===Object?!0:typeof n=="function"&&Function.toString.call(n)===rn}function se(e,t){ae(e)===0?Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function ae(e){let t=e[R];return t?t.type_:Array.isArray(e)?1:ue(e)?2:fe(e)?3:0}function we(e,t){return ae(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function rt(e,t,n){let r=ae(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function on(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function ue(e){return e instanceof Map}function fe(e){return e instanceof Set}function M(e){return e.copy_||e.base_}function ve(e,t){if(ue(e))return new Map(e);if(fe(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=nt(e);if(t===!0||t==="class_only"&&!n){let r=Object.getOwnPropertyDescriptors(e);delete r[R];let o=Reflect.ownKeys(r);for(let i=0;i<o.length;i++){let l=o[i],a=r[l];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(r[l]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[l]})}return Object.create(z(e),r)}else{let r=z(e);if(r!==null&&n)return{...e};let o=Object.create(r);return Object.assign(o,e)}}function $e(e,t=!1){return de(e)||Y(e)||!j(e)||(ae(e)>1&&(e.set=e.add=e.clear=e.delete=sn),Object.freeze(e),t&&Object.entries(e).forEach(([n,r])=>$e(r,!0))),e}function sn(){V(2)}function de(e){return Object.isFrozen(e)}var ln={};function B(e){let t=ln[e];return t||V(0,e),t}var Q;function ot(){return Q}function cn(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ge(e,t){t&&(B("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function xe(e){_e(e),e.drafts_.forEach(an),e.drafts_=null}function _e(e){e===Q&&(Q=e.parent_)}function Qe(e){return Q=cn(Q,e)}function an(e){let t=e[R];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Ze(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];return e!==void 0&&e!==n?(n[R].modified_&&(xe(t),V(4)),j(e)&&(e=le(t,e),t.parent_||ce(t,e)),t.patches_&&B("Patches").generateReplacementPatches_(n[R].base_,e,t.patches_,t.inversePatches_)):e=le(t,n,[]),xe(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==tt?e:void 0}function le(e,t,n){if(de(t))return t;let r=t[R];if(!r)return se(t,(o,i)=>et(e,r,t,o,i,n)),t;if(r.scope_!==e)return t;if(!r.modified_)return ce(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;let o=r.copy_,i=o,l=!1;r.type_===3&&(i=new Set(o),o.clear(),l=!0),se(i,(a,c)=>et(e,r,o,a,c,n,l)),ce(e,o,!1),n&&e.patches_&&B("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function et(e,t,n,r,o,i,l){if(Y(o)){let a=i&&t&&t.type_!==3&&!we(t.assigned_,r)?i.concat(r):void 0,c=le(e,o,a);if(rt(n,r,c),Y(c))e.canAutoFreeze_=!1;else return}else l&&n.add(o);if(j(o)&&!de(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;le(e,o),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&Object.prototype.propertyIsEnumerable.call(n,r)&&ce(e,o)}}function ce(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&$e(t,n)}function un(e,t){let n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:ot(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=r,i=Le;n&&(o=[r],i=Z);let{revoke:l,proxy:a}=Proxy.revocable(o,i);return r.draft_=a,r.revoke_=l,a}var Le={get(e,t){if(t===R)return e;let n=M(e);if(!we(n,t))return fn(e,n,t);let r=n[t];return e.finalized_||!j(r)?r:r===be(e.base_,t)?(Ie(e),e.copy_[t]=Ee(r,e)):r},has(e,t){return t in M(e)},ownKeys(e){return Reflect.ownKeys(M(e))},set(e,t,n){let r=it(M(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let o=be(M(e),t),i=o?.[R];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(on(n,o)&&(n!==void 0||we(e.base_,t)))return!0;Ie(e),Ae(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return be(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,Ie(e),Ae(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=M(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty(){V(11)},getPrototypeOf(e){return z(e.base_)},setPrototypeOf(){V(12)}},Z={};se(Le,(e,t)=>{Z[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});Z.deleteProperty=function(e,t){return Z.set.call(this,e,t,void 0)};Z.set=function(e,t,n){return Le.set.call(this,e[0],t,n,e[0])};function be(e,t){let n=e[R];return(n?M(n):e)[t]}function fn(e,t,n){let r=it(t,n);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}function it(e,t){if(!(t in e))return;let n=z(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=z(n)}}function Ae(e){e.modified_||(e.modified_=!0,e.parent_&&Ae(e.parent_))}function Ie(e){e.copy_||(e.copy_=ve(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var dn=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){let i=n;n=t;let l=this;return function(c=i,...s){return l.produce(c,f=>n.call(this,f,...s))}}typeof n!="function"&&V(6),r!==void 0&&typeof r!="function"&&V(7);let o;if(j(t)){let i=Qe(this),l=Ee(t,void 0),a=!0;try{o=n(l),a=!1}finally{a?xe(i):_e(i)}return Ge(i,r),Ze(o,i)}else if(!t||typeof t!="object"){if(o=n(t),o===void 0&&(o=t),o===tt&&(o=void 0),this.autoFreeze_&&$e(o,!0),r){let i=[],l=[];B("Patches").generateReplacementPatches_(t,o,i,l),r(i,l)}return o}else V(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(l,...a)=>this.produceWithPatches(l,c=>t(c,...a));let r,o;return[this.produce(t,n,(l,a)=>{r=l,o=a}),r,o]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){j(e)||V(8),Y(e)&&(e=pn(e));let t=Qe(this),n=Ee(e,void 0);return n[R].isManual_=!0,_e(t),n}finishDraft(e,t){let n=e&&e[R];(!n||!n.isManual_)&&V(9);let{scope_:r}=n;return Ge(r,t),Ze(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let o=t[n];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}n>-1&&(t=t.slice(n+1));let r=B("Patches").applyPatches_;return Y(e)?r(e,t):this.produce(e,o=>r(o,t))}};function Ee(e,t){let n=ue(e)?B("MapSet").proxyMap_(e,t):fe(e)?B("MapSet").proxySet_(e,t):un(e,t);return(t?t.scope_:ot()).drafts_.push(n),n}function pn(e){return Y(e)||V(10,e),st(e)}function st(e){if(!j(e)||de(e))return e;let t=e[R],n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=ve(e,t.scope_.immer_.useStrictShallowCopy_)}else n=ve(e,!0);return se(n,(r,o)=>{rt(n,r,st(o))}),t&&(t.finalized_=!1),n}var T=new dn,Ce=T.produce,Co=T.produceWithPatches.bind(T),So=T.setAutoFreeze.bind(T),ko=T.setUseStrictShallowCopy.bind(T),Oo=T.applyPatches.bind(T),Ro=T.createDraft.bind(T),To=T.finishDraft.bind(T);var p={LITERAL:0,VARIABLE:1,INTERPOLATION:2,FUNCTION:3,BINARY:4,UNARY:5,CONDITIONAL:6,LOOP:7,OBJECT:8,ARRAY:9,PARTIAL:10,PATH_REFERENCE:11},_={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},ee={NOT:0};var w=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},k=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var Se=e=>{if(!e||e.trim()==="")throw new w("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let n=e.includes("===")?"==":"!=";throw new w(`Invalid comparison operator '${e.includes("===")?"===":"!=="}' - did you mean '${n}'? (got: '${e}')`)}let t=["<",">","<=",">=","==","!="];for(let n of t)if(e.trim().endsWith(n))throw new w(`Incomplete comparison expression - missing right operand (got: '${e}')`)},lt=e=>{if(e.trim().endsWith(" in"))throw new w(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new w(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,n]=e.split(" in ");if(!n||n.trim()==="")throw new w(`Missing iterable expression after 'in' (got: '$for ${e}')`);let r=t.includes(",")?t.split(",").map(o=>o.trim()):[t.trim()];for(let o of r){if(!o)throw new w(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(o))throw new w(`Invalid loop syntax (got: '$for ${e}')`)}};var ct=(e,t,n=!1)=>{if(t===null)return new k(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new k(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return n?new k(`Cannot iterate over non-array value in loop '${e}' - got ${r} instead`):new k(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},at=(e,t)=>{let n=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new k(`Unknown function '${e}' (${n})`)};var hn=(e,t,n={})=>{let r={},o={};n&&typeof n=="object"&&(n.functions!==void 0||n.partials!==void 0?(r=n.functions||{},o=n.partials||{}):typeof n=="object"&&(r=n));let l=x(e,{functions:r,partials:o},t,{});return l===void 0?{}:l},x=(e,t,n,r)=>{let o=t.functions||t;if(e.var&&!e.type)return $(e.var,n,r);if(e.type===p.LITERAL)return e.value;if(e.type===p.VARIABLE)return $(e.path,n,r);if(e.type===p.INTERPOLATION)return yn(e.parts,t,n,r);switch(e.type){case p.FUNCTION:return ft(e,t,n,r);case p.BINARY:return dt(e,t,n,r);case p.UNARY:return pt(e,t,n,r);case p.CONDITIONAL:return bn(e,t,n,r);case p.LOOP:return _n(e,t,n,r);case p.OBJECT:return En(e,t,n,r);case p.ARRAY:return $n(e,t,n,r);case p.PARTIAL:return Ln(e,t,n,r);case p.PATH_REFERENCE:return Cn(e,t,n,r);default:throw new Error(`Unknown node type: ${e.type}`)}},ut=new Map,gn=e=>{let t=[],n="",r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(i==="[")n&&(t.push({type:"property",value:n}),n=""),r=!0;else if(i==="]"){if(r&&n){let l=n.trim();if(/^\d+$/.test(l))t.push({type:"index",value:parseInt(l,10)});else if(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'")){let a=l.slice(1,-1);t.push({type:"property",value:a})}else t.push({type:"property",value:l});n=""}r=!1}else n+=i}return n&&t.push({type:"property",value:n}),t},$=(e,t,n)=>{if(!e)return;if(e in n)return n[e];let r=ut.get(e);if(!r){let i=[],l="",a=0;for(let c=0;c<e.length;c++){let s=e[c];s==="["?(a++,l+=s):s==="]"?(a--,l+=s):s==="."&&a===0?l&&(i.push(l),l=""):l+=s}l&&i.push(l),r=[];for(let c of i){let s=gn(c.trim());r.push(...s)}ut.set(e,r)}let o=t;for(let i=0;i<r.length;i++){let l=r[i];if(l.type==="property"&&l.value in n){o=n[l.value];continue}if(o==null)return;(l.type==="property"||l.type==="index")&&(o=o[l.value])}return o},yn=(e,t,n,r)=>{let o=[];for(let i of e)if(typeof i=="string")o.push(i);else{let l=x(i,t,n,r);o.push(l!=null?String(l):"")}return o.join("")},ft=(e,t,n,r)=>{let o=t.functions||t,i=o[e.name];if(!i)throw at(e.name,o);let l=e.args.map(a=>x(a,t,n,r));return i(...l)},H=(e,t,n,r)=>{if(e.var&&!e.type)return $(e.var,n,r);switch(e.type){case p.VARIABLE:return $(e.path,n,r);case p.LITERAL:return e.value;case p.BINARY:return dt(e,t,n,r);case p.UNARY:return pt(e,t,n,r);case p.FUNCTION:return ft(e,t,n,r);default:return x(e,t,n,r)}},dt=(e,t,n,r)=>{if(e.op===_.AND||e.op===_.OR){let l=H(e.left,t,n,r),a=H(e.right,t,n,r);switch(e.op){case _.AND:return l&&a;case _.OR:return l||a}}let o=x(e.left,t,n,r),i=x(e.right,t,n,r);switch(e.op){case _.EQ:return o==i;case _.NEQ:return o!=i;case _.GT:return o>i;case _.LT:return o<i;case _.GTE:return o>=i;case _.LTE:return o<=i;case _.IN:return Array.isArray(i)?i.includes(o):!1;case _.ADD:if(typeof o!="number"||typeof i!="number")throw new k(`Arithmetic operations require numbers. Got ${typeof o} + ${typeof i}`);return o+i;case _.SUBTRACT:if(typeof o!="number"||typeof i!="number")throw new k(`Arithmetic operations require numbers. Got ${typeof o} - ${typeof i}`);return o-i;default:throw new Error(`Unknown binary operator: ${e.op}`)}},pt=(e,t,n,r)=>{let o=e.op===ee.NOT?H(e.operand,t,n,r):x(e.operand,t,n,r);if(e.op===ee.NOT)return!o;throw new Error(`Unknown unary operator: ${e.op}`)},mn=(e,t,n,r)=>{if(e.conditions.length===2&&e.conditions[1]===null){let o=e.conditions[0];if(o.type===p.VARIABLE)if($(o.path,n,r)){let l=e.bodies[0];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?x(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=$(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=$(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=x(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=x(f,t,n,r)}return a}}else{let l=e.bodies[1];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?x(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=$(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=$(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=x(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=x(f,t,n,r)}return a}}}return null},bn=(e,t,n,r)=>{let o=mn(e,t,n,r);if(o!==null)return o;for(let i=0;i<e.conditions.length;i++){let l=e.conditions[i];if(l===null||H(l,t,n,r))return x(e.bodies[i],t,n,r)}return ht},In=(e,t)=>{let n=e.body,r=e.itemVar;if(n.type===p.CONDITIONAL&&n.conditions.length===1&&n.conditions[0].type===p.VARIABLE){let o=n.conditions[0].path,i=n.bodies[0];if(o.startsWith(r+".")){let l=o.substring(r.length+1);if(i.type===p.OBJECT&&i.properties.length<=5){for(let c of i.properties)if(c.parsedKey)return null;let a=[];for(let c=0;c<t.length;c++){let s=t[c];if(s[l]){let f={};for(let u of i.properties){let d=u.key,h=u.value;if(h.type===p.LITERAL)f[d]=h.value;else if(h.type===p.VARIABLE){let g=h.path;if(g===r)f[d]=s;else if(g.startsWith(r+".")){let m=g.substring(r.length+1);f[d]=s[m]}else return null}else if(h.type===p.INTERPOLATION){let g=[],m=!0;for(let I of h.parts)if(typeof I=="string")g.push(I);else if(I.type===p.VARIABLE){let y=I.path;if(y===r)g.push(s!=null?String(s):"");else if(y.startsWith(r+".")){let b=y.substring(r.length+1),v=s[b];g.push(v!=null?String(v):"")}else{m=!1;break}}else{m=!1;break}if(!m)return null;f[d]=g.join("")}else return null}a.push(f)}}return a}}}return null},wn=(e,t)=>{let n=e.body,r=e.itemVar,o=In(e,t);if(o!==null)return o;if(n.type===p.OBJECT&&n.properties.length<=5&&!n.whenCondition){for(let a of n.properties)if(a.parsedKey)return null;let i=[],l=!0;for(let a of n.properties){let c=a.key,s=a.value;if(s.type===p.LITERAL)i.push({key:c,type:"literal",value:s.value});else if(s.type===p.VARIABLE){let f=s.path;if(f===r)i.push({key:c,type:"item"});else if(f.startsWith(r+".")){let u=f.substring(r.length+1);if(!u.includes(".")&&!u.includes("["))i.push({key:c,type:"prop",prop:u});else{l=!1;break}}else{l=!1;break}}else if(s.type===p.INTERPOLATION&&s.parts.length===1){let f=s.parts[0];if(f.type===p.VARIABLE){let u=f.path;if(u===r)i.push({key:c,type:"item_string"});else if(u.startsWith(r+".")){let d=u.substring(r.length+1);if(!d.includes(".")&&!d.includes("["))i.push({key:c,type:"prop_string",prop:d});else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}if(l){let a=new Array(t.length);if(i.length===3&&i[0].type==="prop"&&i[0].key==="id"&&i[1].type==="prop_string"&&i[1].key==="title"&&i[2].type==="prop"&&i[2].key==="completed")for(let c=0;c<t.length;c++){let s=t[c];a[c]={id:s.id,title:s.title!=null?String(s.title):"",completed:s.completed}}else for(let c=0;c<t.length;c++){let s=t[c],f={};for(let u of i)if(u.type==="literal")f[u.key]=u.value;else if(u.type==="item")f[u.key]=s;else if(u.type==="prop")f[u.key]=s[u.prop];else if(u.type==="item_string")f[u.key]=s!=null?String(s):"";else if(u.type==="prop_string"){let d=s[u.prop];f[u.key]=d!=null?String(d):""}a[c]=f}return a}}return null},vn=(e,t,n,r,o)=>{let i=[],l=e.body;if(l.type===p.OBJECT&&l.fast!==!1){let a=e.itemVar,c=e.indexVar;for(let s=0;s<o.length;s++){let f=o[s],u={},d={...r,[a]:f,...c&&{[c]:s}};d.__paths__||(d.__paths__=r.__paths__||{});let h=e.iterable.path||"";if(r&&r.__paths__&&h){let g=h.split("."),m=g[0];m in r.__paths__&&(h=r.__paths__[m],g.length>1&&(h+="."+g.slice(1).join(".")))}d.__paths__={...d.__paths__,[a]:`${h}[${s}]`,...c&&{[c]:s}};for(let g of l.properties){let m=g.parsedKey?x(g.parsedKey,t,n,d):g.key,I=g.value;if(I.type===p.LITERAL)u[m]=I.value;else if(I.type===p.VARIABLE){let y=I.path;if(y===a)u[m]=f;else if(y===c)u[m]=s;else if(y.startsWith(a+".")){let b=y.substring(a.length+1);!b.includes(".")&&!b.includes("[")?u[m]=f[b]:u[m]=$(y,n,{...r,[a]:f,...c&&{[c]:s}})}else u[m]=$(y,n,{...r,[a]:f,...c&&{[c]:s}})}else if(I.type===p.INTERPOLATION){let y=[];for(let b of I.parts)if(typeof b=="string")y.push(b);else if(b.type===p.VARIABLE){let v=b.path,A;if(v===a)A=f;else if(v===c)A=s;else if(v.startsWith(a+".")){let E=v.substring(a.length+1);!E.includes(".")&&!E.includes("[")?A=f[E]:A=$(v,n,{...r,[a]:f,...c&&{[c]:s}})}else A=$(v,n,{...r,[a]:f,...c&&{[c]:s}});y.push(A!=null?String(A):"")}else{let v={...r,[a]:f,...c&&{[c]:s}},A=x(b,t,n,v);y.push(A!=null?String(A):"")}u[m]=y.join("")}else{let y={...r,[a]:f,...c&&{[c]:s}};u[m]=x(I,t,n,y)}}i.push(u)}return i}return null},xn=(e,t,n)=>{let r=e.body;if(r.type===p.OBJECT&&r.properties.length===1&&r.properties[0].key==="$if item.visible"){let i=r.properties[0].value;if(i.type===p.CONDITIONAL&&i.conditions.length===1&&i.conditions[0].type===p.VARIABLE&&i.conditions[0].path==="item.visible"){let l=i.bodies[0];if(l.type===p.OBJECT&&l.properties.length===2){let a=l.properties[0],c=l.properties[1];if(a.key==="id"&&a.value.type===p.VARIABLE&&a.value.path==="item.id"&&c.key==="$if item.highlighted"&&c.value.type===p.CONDITIONAL){let s=[];for(let f=0;f<t.length;f++){let u=t[f];if(u.visible){let d={id:u.id};u.highlighted?(d.highlight=!0,d.message=`This item is highlighted: ${u.name}`):(d.highlight=!1,d.message=u.name),s.push(d)}}return s}}}}return null},_n=(e,t,n,r)=>{let o=x(e.iterable,t,n,r);if(!Array.isArray(o)){let s,f=!1;if(e.iterable.type===p.FUNCTION){f=!0;let d=e.iterable.args.map(h=>h.type===p.LITERAL?typeof h.value=="string"?`'${h.value}'`:String(h.value):h.type===p.VARIABLE?h.path:h.type===p.FUNCTION?`${h.name}(...)`:"?").join(", ");s=`${e.iterable.name}(${d})`}else s=e.iterable.path||"undefined";let u=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${s}`;throw ct(u,o,f)}if(!e.indexVar){let s=xn(e,o,e.itemVar);if(s!==null)return s}if(!e.indexVar){let s=wn(e,o);if(s!==null)return s}let i=vn(e,t,n,r,o);if(i!==null)return i;let l=[],a=e.iterable.path||"";if(r&&r.__paths__&&a){let s=a.split("."),f=s[0];f in r.__paths__&&(a=r.__paths__[f],s.length>1&&(a+="."+s.slice(1).join(".")))}let c=!1;e.body.type===p.ARRAY&&(e.body.items.length<=1?c=!1:c=e.body._shouldPreserveArray??=e.body.items.some(s=>s.type===p.OBJECT&&s.properties.some(f=>f.key.startsWith("$if ")||f.key.startsWith("$when "))));for(let s=0;s<o.length;s++){let f=e.indexVar?{...r,[e.itemVar]:o[s],[e.indexVar]:s}:{...r,[e.itemVar]:o[s]};f.__paths__||(f.__paths__=r.__paths__||{}),f.__paths__={...f.__paths__,[e.itemVar]:`${a}[${s}]`},e.indexVar&&(f.__paths__[e.indexVar]=s);let u=x(e.body,t,n,f);if(Array.isArray(u)&&u.length===1&&!c){let d=u[0];l.push(d===void 0?{}:d)}else l.push(u===void 0?{}:u)}return l},An=(e,t,n,r)=>{if(e.whenCondition)return null;if(e.properties.length===1){let o=e.properties[0],i=o.parsedKey?x(o.parsedKey,t,n,r):o.key,l=o.value;if(l.type===p.OBJECT&&l.properties.length<=10&&!l.whenCondition){let a={},c={},s=!0;for(let f of l.properties){let u=f.parsedKey?x(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)c[u]=d.value;else if(d.type===p.VARIABLE)c[u]=$(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let m=$(g.path,n,r);h.push(m!=null?String(m):"")}else{s=!1;break}if(!s)break;c[u]=h.join("")}else if(d.type===p.OBJECT&&d.properties.length<=5){let h={};for(let g of d.properties){let m=g.key,I=g.value;if(I.type===p.LITERAL)h[m]=I.value;else if(I.type===p.VARIABLE)h[m]=$(I.path,n,r);else if(I.type===p.INTERPOLATION){let y=[];for(let b of I.parts)if(typeof b=="string")y.push(b);else if(b.type===p.VARIABLE){let v=$(b.path,n,r);y.push(v!=null?String(v):"")}else{s=!1;break}if(!s)break;h[m]=y.join("")}else{s=!1;break}}if(!s)break;c[u]=h}else{s=!1;break}}if(s)return a[i]=c,a}}return null},En=(e,t,n,r)=>{let o=t.functions||t;if(e.whenCondition&&!H(e.whenCondition,o,n,r))return;let i=An(e,t,n,r);if(i!==null)return i;if(e.fast){let s={};for(let f of e.properties){let u=f.parsedKey?x(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)s[u]=d.value;else if(d.type===p.VARIABLE)s[u]=$(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let m=$(g.path,n,r);h.push(m!=null?String(m):"")}else{let m=x(g,t,n,r);h.push(m!=null?String(m):"")}s[u]=h.join("")}else s[u]=x(d,t,n,r)}return s}let l={},a=null,c=!1;for(let s of e.properties)if(!s.key.startsWith("$if ")&&!s.key.match(/^\$if\s+\w+.*:?$/)&&!s.key.startsWith("$elif")&&!s.key.startsWith("$else")&&!s.key.startsWith("$for ")){c=!0;break}for(let s of e.properties)if(s.key.startsWith("$if ")||s.key.match(/^\$if\s+\w+.*:?$/)){let f=x(s.value,t,n,r);if(!c&&f!==null&&f!==void 0)return Array.isArray(f)&&f.length===1?f[0]:f;typeof f=="object"&&f!==null&&!Array.isArray(f)&&Object.assign(l,f)}else if(s.key.startsWith("$for ")){if(e.properties.length===1)return x(s.value,t,n,r)}else{let f=s.value;if(f&&f.type===p.OBJECT&&f.properties){let u=f.properties.find(d=>d.key.startsWith("$for "));if(u){let d=x(u.value,t,n,r);d!==void 0&&(l[s.key]=d)}else{let d=x(s.value,t,n,r);d!==void 0&&(l[s.key]=d)}}else{let u=s.parsedKey?x(s.parsedKey,t,n,r):s.key,d=x(s.value,t,n,r);d!==void 0&&(l[u]=d)}}return l},ht={},$n=(e,t,n,r)=>{let o=[];for(let i of e.items)if(i.type===p.LOOP){let l=x(i,t,n,r);Array.isArray(l)&&i.flatten!==!1?o.push(...l):o.push(l)}else{let l=x(i,t,n,r);l!==ht&&l!==void 0&&o.push(l)}return o},Ln=(e,t,n,r)=>{let{name:o,data:i,whenCondition:l}=e,a=t.partials||{},c=t.functions||t;if(l&&!H(l,c,n,r))return;if(!a[o])throw new k(`Partial '${o}' is not defined`);let s=r._partialStack||[];if(s.includes(o))throw new k(`Circular partial reference detected: ${o}`);let f=a[o],u=n,d={...r,_partialStack:[...s,o]};if(r){u={...n};for(let h of Object.keys(r))h.startsWith("_")||(u[h]=r[h])}if(i){let h=x(i,t,n,r);u={...u,...h}}return x(f,t,u,d)},Cn=(e,t,n,r)=>{let{path:o}=e,i=o.split("."),l=i[0],a=i.slice(1);if(!r||!(l in r))throw new k(`Path reference '#{${o}}' refers to '${l}' which is not a loop variable in the current scope`);if(r.__paths__||(r.__paths__={}),!(l in r.__paths__))throw new k(`Path reference '#{${o}}' cannot be resolved - path tracking may not be initialized properly`);let c=r.__paths__[l];if(typeof c=="number"){if(a.length>0)throw new k(`Path reference '#{${o}}' - cannot access properties on index variable '${l}'`);return String(c)}return a.length>0&&(c+="."+a.join(".")),c},ke=hn;var Sn=/\$\{([^}]*)\}/g,kn=/#\{([^}]*)\}/g,yt=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,r,o]=n,i=On(o,t);return{isFunction:!0,type:p.FUNCTION,name:r,args:i}},On=(e,t={})=>e.trim()?Rn(e).map(r=>Tn(r.trim(),t)):[],Rn=e=>{let t=[],n="",r=0,o=!1,i="";for(let l=0;l<e.length;l++){let a=e[l],c=l>0?e[l-1]:"";!o&&(a==='"'||a==="'")?(o=!0,i=a,n+=a):o&&a===i&&c!=="\\"?(o=!1,i="",n+=a):!o&&a==="("?(r++,n+=a):!o&&a===")"?(r--,n+=a):!o&&a===","&&r===0?(t.push(n),n=""):n+=a}return n&&t.push(n),t},Tn=(e,t={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:p.LITERAL,value:parseFloat(e)};if(e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};let n=yt(e,t);if(n.isFunction)return{type:n.type,name:n.name,args:n.args};let r=e.trim(),o=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],i=-1,l=null;for(let{op:a,type:c}of o){let s=0;for(;s<r.length;){let f=F(r.substring(s),a);if(f===-1)break;let u=s+f;u>i&&(i=u,l={op:a,type:c}),s=u+a.length}}if(i!==-1)try{return S(r,t)}catch{return{type:p.VARIABLE,path:r}}return{type:p.VARIABLE,path:r}},mt=/^\w+\(.*\)$/,Nn=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,Pn=e=>{if(!(!e||e.trim()===""||mt.test(e))&&Nn.test(e))throw e.includes("?")&&e.includes(":")?new w(`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 w(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new w(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},gt=e=>{let t=e.trim();if(mt.test(t))throw new w(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("["))throw new w(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(t))throw new w(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(t))throw new w(`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 w(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:p.PATH_REFERENCE,path:t}},te=(e,t={})=>{let n=e.trim();Pn(n);let r=yt(n,t);if(r.isFunction)return{type:r.type,name:r.name,args:r.args};if(n.includes("[")&&!/[\s+\-*/%|&?:]/.test(n)){let o=0;for(let i of n)i==="["?o++:i==="]"&&o--;if(o!==0)throw new Error("Invalid array index syntax")}return{type:p.VARIABLE,path:n}},Oe=(e,t={})=>{let n=e,r=[];(e.includes("\\${")||e.includes("\\#{"))&&(n=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC_VAR$1"),n=n.replace(/\\\\(#\{[^}]*\})/g,"\\DOUBLE_ESC_PATH$1"),n=n.replace(/\\(\$\{[^}]*\})/g,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\(#\{[^}]*\})/g,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let o=[...n.matchAll(Sn)],i=[...n.matchAll(kn)],l=[...o.map(s=>({match:s,type:"variable"})),...i.map(s=>({match:s,type:"pathref"}))].sort((s,f)=>s.match.index-f.match.index);if(l.length===0){let s=n;for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);return{type:p.LITERAL,value:s}}if(l.length===1&&l[0].match[0]===n&&r.length===0){let{match:s,type:f}=l[0];try{return f==="variable"?te(s[1],t):gt(s[1])}catch(u){if(u.message==="Invalid array index syntax")return{type:p.LITERAL,value:n};throw u}}let a=[],c=0;for(let{match:s,type:f}of l){let[u,d]=s,h=s.index;if(h>c){let g=n.substring(c,h);for(let m=0;m<r.length;m++)g=g.replace(`__ESCAPED_${m}__`,r[m]);g&&a.push(g)}try{let g;f==="variable"?g=te(d.trim(),t):g=gt(d.trim()),a.push(g)}catch(g){if(g.message==="Invalid array index syntax")a.push(u);else throw g}c=h+u.length}if(c<n.length){let s=n.substring(c);for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);s&&a.push(s)}return{type:p.INTERPOLATION,parts:a}};var D=(e,t)=>typeof e=="string"?Oe(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?Dn(e,t):Mn(e,t):{type:p.LITERAL,value:e},Vn=e=>{let{$each:t,...n}=e;if(typeof t!="string")throw new w("$each value must be a non-empty string");let r=t.trim();if(r==="")throw new w("$each value must be a non-empty string");if(Object.keys(n).length===0)throw new w("Empty $each body not allowed");if(n.$partial!==void 0)throw new w("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${r}`]:n}},Dn=(e,t)=>{let n=[],r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(typeof i=="object"&&i!==null&&!Array.isArray(i)){if(i.$each!==void 0)try{let c=Vn(i),s=Object.keys(c);if(s.length===1&&/^\$for(?::\w+)?\s/.test(s[0])){let f=bt(s[0],c[s[0]],t,!0);n.push(f),r=!0;continue}}catch(c){throw c instanceof w?c:new w(c.message)}let a=Object.keys(i);if(a.length===1&&/^\$for(?::\w+)?\s/.test(a[0])){let c=bt(a[0],i[a[0]],t);n.push(c),r=!0;continue}}let l=D(i,t);n.push(l),(l.type===p.FUNCTION||l.type===p.CONDITIONAL||l.type===p.LOOP||l.type===p.PARTIAL||l.type===p.OBJECT&&!l.fast||l.type===p.ARRAY&&!l.fast)&&(r=!0)}return{type:p.ARRAY,items:n,fast:!r}},Mn=(e,t)=>{let n=[],r=!1,o=null,i=Object.entries(e),l=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new w("$partial value must be a string");if(e.$partial.trim()==="")throw new w("$partial value cannot be an empty string");let c=["$if","$elif","$else","$for"],s=[];for(let[y]of i)for(let b of c)if(y===b||y.startsWith(b+" ")||y.startsWith(b+"#")){s.push(b);break}if(s.length>0)throw new w(`Cannot use $partial with ${s.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:f,$when:u,...d}=e,h={},g=!1;for(let[y,b]of Object.entries(d)){let v=y;(y.startsWith("\\$")||y.startsWith("$$"))&&(v=y.slice(1)),h[v]=b,g=!0}let m=null;if(g&&(m=D(h,t),m.type===p.OBJECT)){let y=!1;for(let b of m.properties)if(b.value.type===p.VARIABLE||b.value.type===p.INTERPOLATION||b.value.type===p.FUNCTION||b.value.type===p.CONDITIONAL||b.value.type===p.OBJECT&&!b.value.fast||b.value.type===p.ARRAY&&!b.value.fast){y=!0;break}y&&(m.fast=!1)}let I={type:p.PARTIAL,name:f,data:m};if(u!==void 0){let y;if(typeof u=="string"){if(u.trim()==="")throw new w("Empty condition expression after '$when'");y=S(u,t)}else y={type:p.LITERAL,value:u};I.whenCondition=y}return I}for(let[c,s]of i)if(c==="$when"){if(o!==null)throw new w("Multiple '$when' directives on the same object are not allowed");if(s==null)throw new w("Missing condition expression after '$when'");let f=typeof s=="string"?s:JSON.stringify(s);if(f.trim()==="")throw new w("Empty condition expression after '$when'");o=S(f,t),r=!0}else if(c.startsWith("$when#")||c.startsWith("$when "))throw new w("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;l<i.length;){let[c,s]=i[l];if(c==="$when"){l++;continue}if(c==="$each")throw new w("$each can only be used inside arrays");if(c.startsWith("$if ")||c.match(/^\$if#\w+\s/)||c.match(/^\$if\s+\w+.*:$/)){let f=jn(i,l,t);n.push({key:c,value:f.node}),r=!0,l=f.nextIndex}else if(/^\$for(?::\w+)?\s/.test(c)){let f=c.match(/^\$for(?::(\w+))?\s/)?.[1]||"",u=f?`:${f}`:"";throw new w(`$for loops must be inside arrays - use '- $for${u} item in items:' instead of '$for${u} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(c.startsWith("$elif ")||c.startsWith("$else"))throw new w(`'${c.split(" ")[0]}' without matching '$if'`);if(c==="$if"||c==="$if:")throw new w("Missing condition expression after '$if'");{let f=D(s,t);(f.type===p.FUNCTION||f.type===p.CONDITIONAL||f.type===p.PARTIAL||f.type===p.OBJECT&&!f.fast||f.type===p.ARRAY&&!f.fast)&&(r=!0);let u=Oe(c,t),d={key:c,value:f};(u.type!==p.LITERAL||u.value!==c)&&(d.parsedKey=u),n.push(d),l++}}}let a={type:p.OBJECT,properties:n,fast:!r};return o&&(a.whenCondition=o),a},jn=(e,t,n={})=>{let r=[],o=[],i=t,[l,a]=e[i],c=null,s;if(l.startsWith("$if#")){let u=l.match(/^\$if#(\w+)\s+(.+)$/);if(u)c=u[1],s=u[2];else throw new w(`Invalid conditional syntax: ${l}`)}else s=l.substring(4),s.endsWith(":")&&(s=s.slice(0,-1).trim());Se(s);let f=S(s,n);for(r.push(f),o.push(D(a,n)),i++;i<e.length;){let[u,d]=e[i],h=!1,g;if(c?u.startsWith(`$elif#${c} `)?(g=u.substring(`$elif#${c} `.length),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u===`$else#${c}`||u===`$else#${c}:`)&&(h=!0,g=null):u.startsWith("$elif ")?(g=u.substring(6),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u==="$else"||u==="$else:")&&(h=!0,g=null),h){if(g===null)r.push(null);else{Se(g);let m=S(g,n);r.push(m)}if(o.push(D(d,n)),i++,g===null)break}else break}return{node:{type:p.CONDITIONAL,conditions:r,bodies:o,id:c},nextIndex:i}},S=(e,t={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let s=e.slice(1,-1),f=0,u=!0;for(let d=0;d<s.length;d++)if(s[d]==="("?f++:s[d]===")"&&f--,f<0){u=!1;break}if(u&&f===0)return S(s,t)}let n=F(e,"||");if(n!==-1)return{type:p.BINARY,op:_.OR,left:S(e.substring(0,n).trim(),t),right:S(e.substring(n+2).trim(),t)};let r=F(e,"&&");if(r!==-1)return{type:p.BINARY,op:_.AND,left:S(e.substring(0,r).trim(),t),right:S(e.substring(r+2).trim(),t)};let o=[{op:">=",type:_.GTE},{op:"<=",type:_.LTE},{op:"==",type:_.EQ},{op:"!=",type:_.NEQ},{op:">",type:_.GT},{op:"<",type:_.LT},{op:" in ",type:_.IN}];for(let{op:s,type:f}of o){let u=F(e,s);if(u!==-1)return{type:p.BINARY,op:f,left:S(e.substring(0,u).trim(),t),right:S(e.substring(u+s.length).trim(),t)}}let i=-1,l=null,a=[{op:" + ",type:_.ADD},{op:" - ",type:_.SUBTRACT}];for(let{op:s,type:f}of a){let u=0;for(;u<e.length;){let d=F(e.substring(u),s);if(d===-1)break;let h=u+d;h>i&&(i=h,l={op:s,type:f}),u=h+s.length}}if(i!==-1&&l)return{type:p.BINARY,op:l.type,left:S(e.substring(0,i).trim(),t),right:S(e.substring(i+l.op.length).trim(),t)};let c=[" * "," / "," % "];for(let s of c)if(F(e,s)!==-1)throw new w(`Arithmetic operations are not allowed in conditionals: "${s}"`);return e.startsWith("!")?{type:p.UNARY,op:ee.NOT,operand:S(e.substring(1).trim(),t)}:It(e,t)},F=(e,t)=>{let n=0,r=0;for(;r<=e.length-t.length;){if(e[r]==="(")n++;else if(e[r]===")")n--;else if(n===0&&e.substring(r,r+t.length)===t)return r;r++}return-1},Bn=e=>{if(e=e.trim(),e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:p.LITERAL,value:""};if(e==="{}")return{type:p.LITERAL,value:{}};if(e==="[]")return{type:p.LITERAL,value:[]};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:p.LITERAL,value:t}:{type:p.VARIABLE,path:e}},It=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return te(n,t);let o=Bn(n);if(o.type===p.LITERAL)return o;if(/^[a-zA-Z_$][\w.$]*$/.test(n))return{type:p.VARIABLE,path:n};try{return te(n,t)}catch(i){if(i.message&&i.message.includes("not supported"))return o;throw i}},Fn=(e,t=!1)=>{let n=t?"$each":"$for";try{lt(e)}catch(r){if(r instanceof w&&t){let o=r.message.replace(/\$for/g,"$each");throw new w(o.replace("Parse Error: ",""))}throw r}},bt=(e,t,n,r=!1)=>{let o=/^\$for(?::(\w+))?\s+(.+)$/,i=e.match(o);if(!i){let I=r?"$each":"$for";throw new w(`Invalid loop syntax (got: '${e.replace("$for",I)}')`)}let l=i[1],a=i[2].trim();Fn(a,r);let c=a.match(/^(.+?)\s+in\s+(.+)$/);if(!c){let I=r?"$each":"$for";throw new w(`Invalid loop syntax - missing 'in' keyword (got: '${I} ${a}')`)}let s=c[1].trim(),f=c[2].trim(),u,d=null;if(s.includes(",")){let I=s.split(",").map(y=>y.trim());if(I.length!==2)throw new w(`Invalid loop variables: ${s}. Expected format: "item" or "item, index"`);u=I[0],d=I[1]}else u=s;let h=["this","undefined","null","true","false"];if(h.includes(u))throw new w(`Reserved variable name: ${u}`);if(d&&h.includes(d))throw new w(`Reserved variable name: ${d}`);let g=It(f,n),m=D(t,n);return{type:p.LOOP,itemVar:u,indexVar:d,iterable:g,body:m,flatten:l!=="nested"}};var Un=(e,t={})=>{let{functions:n={}}=t;return D(e,n)},pe=Un;var Re={};nn(Re,{now:()=>Wn});var Wn=()=>Date.now();var zn=(e,t,n={})=>{let{functions:r={},partials:o={}}=n,i={...Re,...r},l=pe(e,{functions:i}),a={};for(let[c,s]of Object.entries(o))a[c]=pe(s,{functions:i});return ke(l,t,{functions:i,partials:a})},N=zn;var wt=(e,t,n={})=>{let r=structuredClone(e),o={},i={},{transformSelectorFirstArgument:l=c=>c,transformActionFirstArgument:a=c=>c}=n;for(let[c,s]of Object.entries(t))c!=="createInitialState"&&(c.startsWith("select")?o[c]=(...f)=>s(l(r),...f):i[c]=(...f)=>{r=Ce(r,d=>s(a(d),...f))});return{...o,...i}},he=(e,t)=>n=>{let r=e(),o=Array.isArray(n)?n:[n];return Ce(r,i=>{o.forEach(l=>{t.forEach(a=>{a(i,l)})})})};var Yn=(e,t)=>{if(e.default!==void 0)return e.default;let n=["number","boolean","string","object"];if(!n.includes(e.type))throw new Error(`Invalid variable type: ${e.type} for variable ${t}. Expected one of: ${n.join(", ")}`);switch(e.type){case"number":return 0;case"boolean":return!1;case"string":return"";case"object":return{}}},vt=e=>{let t={},n={};return e.resources?.variables?(Object.entries(e.resources.variables).forEach(([r,o])=>{let i=Yn(o,r);o.scope==="context"?t[r]=i:n[r]=i}),{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}):{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}},xt=(e,t)=>{let n=["context","global-device","global-account"];if(!e)throw new Error(`Variable scope is required for variable: ${t}`);if(!n.includes(e))throw new Error(`Invalid variable scope: ${e} for variable ${t}. Expected one of: ${n.join(", ")}`)},_t=(e,t,n)=>{let r={number:["set","increment","decrement","multiply","divide"],boolean:["set","toggle"],string:["set"],object:["set"]},o=r[e];if(!o)throw new Error(`Unknown variable type: ${e} for variable ${n}`);if(!Object.values(r).flat().includes(t))throw new Error(`Unknown operation: ${t}`);if(!o.includes(t))throw new Error(`Operation "${t}" is not valid for variable "${n}" of type "${e}". Valid operations: ${o.join(", ")}`)},Ne=(e,t,n)=>{switch(t){case"set":return n;case"multiply":return(e??1)*n;case"divide":return(e??0)/n;case"increment":return(e??0)+(n??1);case"decrement":return(e??0)-(n??1);case"toggle":return!e;default:throw new Error(`Unknown operation: ${t}`)}},Pe=(e,t,n)=>Object.fromEntries(Object.entries(e).filter(([r])=>t?.[r]?.scope===n)),At=(e,t="DD/MM/YYYY - HH:mm")=>{if(!e)return"";let n=new Date(e),r=o=>String(o).padStart(2,"0");return t.replace("DD",r(n.getDate())).replace("MM",r(n.getMonth()+1)).replace("YYYY",n.getFullYear()).replace("YY",String(n.getFullYear()).slice(-2)).replace("HH",r(n.getHours())).replace("mm",r(n.getMinutes())).replace("ss",r(n.getSeconds()))},Hn=(e,t)=>{let n=e?.ui,r=t?.ui;return JSON.stringify(n)===JSON.stringify(r)?null:n&&!r?{changeType:"delete",data:e}:r&&!e?{changeType:"add",data:t}:r&&e?{changeType:"update",data:t}:null},Ve=(e={},t={})=>{let n={},r=["sfx","voice"],o=l=>{let a=e[l],c=t[l];c&&!a?n[l]={changeType:"add",data:c}:a&&!c?r.includes(l)||(n[l]={changeType:"delete",data:a}):a&&c&&JSON.stringify(a)!==JSON.stringify(c)&&(n[l]={changeType:"update",data:c})};o("background"),o("base"),o("bgm"),o("voice");let i=Hn(e.dialogue,t.dialogue);return i&&(n.dialogue=i),o("choice"),o("layout"),o("animation"),o("keyboard"),o("character"),o("visual"),o("sfx"),n},qn=(e,t)=>{if(!e||!t)return;let n=e;for(let r of t.split(".")){if(n==null||!(r in Object(n)))return;n=n[r]}return n},Jn=(e,t)=>{if(typeof e!="string")return e;if(e==="_event"){if(t==null)throw new Error('Action template binding "_event" requires event context "_event".');return t}if(!e.startsWith("_event."))return e;if(t==null)throw new Error(`Action template binding "${e}" requires event context "_event".`);let n=e.slice(7),r=qn(t,n);if(r===void 0)throw new Error(`Action template binding "${e}" could not be resolved from "_event".`);return r},Te=(e,t)=>Array.isArray(e)?e.map(n=>Te(n,t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Te(r,t)])):Jn(e,t),Et=(e,t)=>{if(!t)return e;if(Object.prototype.hasOwnProperty.call(t,"event"))throw new Error('Action template context key "event" is no longer supported. Use "_event".');let n=Te(e,t._event);return N(n,t)};var ge=(e,t)=>e?!t(e)&&e.animations?{animationsOnly:!0,state:{animations:structuredClone(e.animations)}}:{animationsOnly:!1,state:null}:{animationsOnly:!1,state:null},$t=(e,t)=>{if(!e||e.length===0)return{hasValidItems:!1,processedItems:[]};let n=e.map(r=>structuredClone(r)).filter(r=>t(r)||r.animations);return{hasValidItems:n.length>0,processedItems:n}},Kn=()=>({}),Xn=(e,t)=>{t.base&&(e.base={...t.base})},Gn=(e,t)=>{if(t.background){let{animationsOnly:n,state:r}=ge(t.background,o=>!!o.resourceId);if(n){e.background=r;return}if(!t.background.resourceId){delete e.background;return}e.background=structuredClone(t.background)}else e.background?.animations&&(e.background.animations={})},Qn=(e,t)=>{if(!t.dialogue){e.dialogue&&e.dialogue.mode==="adv"&&(e.dialogue.content=void 0,e.dialogue.characterId=void 0);return}if(e.dialogue||(e.dialogue={}),t.dialogue.ui){let{animationsOnly:n,state:r}=ge(t.dialogue.ui,o=>!!o.resourceId);n?e.dialogue.ui={...e.dialogue.ui,...r}:e.dialogue.ui={...t.dialogue.ui}}else e.dialogue?.ui?.animations&&(e.dialogue.ui.animations={});if(t.dialogue.mode==="adv"&&(e.dialogue.content=e.dialogue.content||void 0,e.dialogue.characterId=e.dialogue.characterId||void 0,e.dialogue.mode="adv"),t.dialogue.mode==="nvl"&&(e.dialogue?.mode!=="nvl"&&(e.dialogue.lines=[]),e.dialogue.mode="nvl"),t.dialogue.content!==void 0&&(e.dialogue.content=t.dialogue.content),delete e.dialogue.characterId,t.dialogue.characterId&&(e.dialogue.characterId=t.dialogue.characterId),t.dialogue.character?e.dialogue.character={...t.dialogue.character}:delete e.dialogue.character,t.dialogue.clear){delete e.dialogue;return}t.dialogue?.clearPage&&e.dialogue?.mode==="nvl"&&(e.dialogue.lines=[]),e.dialogue?.mode==="nvl"&&t.dialogue.content!==void 0&&e.dialogue.lines.push({content:t.dialogue.content,characterId:t.dialogue.characterId||null})},Zn=(e,t)=>{if(t.sfx){if(!t.sfx.items||t.sfx.items.length===0){delete e.sfx;return}e.sfx=t.sfx}else e.sfx&&delete e.sfx},er=(e,t)=>{if(t.bgm){if(!t.bgm.resourceId){e.bgm=void 0;return}e.bgm={...t.bgm,loop:t.bgm.loop||t.bgm.loop===void 0}}},tr=(e,t)=>{if(t.visual){let{hasValidItems:n,processedItems:r}=$t(t.visual.items,o=>!!o.resourceId);n?e.visual={items:r}:delete e.visual}else e.visual?.items&&(e.visual.items=e.visual.items.map(n=>n.animations?{...n,animations:{}}:n))},nr=(e,t)=>{if(!t.character){e.character?.items&&(e.character.items=e.character.items.map(o=>o.animations?{...o,animations:{}}:o));return}let{hasValidItems:n,processedItems:r}=$t(t.character.items,o=>o.sprites&&o.sprites.length>0||o.transformId||o.resourceId);n?e.character={items:r}:delete e.character},rr=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},or=(e,t)=>{if(t.layout){let{animationsOnly:n,state:r}=ge(t.layout,o=>!!o.resourceId);if(n){e.layout=r;return}if(!t.layout.resourceId){delete e.layout;return}e.layout=t.layout}else e.layout&&delete e.layout},ir=(e,t)=>{if(t.choice){let{animationsOnly:n,state:r}=ge(t.choice,o=>!!o.resourceId);if(n){e.choice={...e.choice,...r};return}if(!t.choice.resourceId){delete e.choice;return}e.choice=t.choice}else e.choice&&delete e.choice},sr=(e,t)=>{t.keyboard&&(e.keyboard=t.keyboard)},lr=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},cr=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},ne=e=>he(Kn,[cr,Xn,Gn,Zn,er,tr,Qn,nr,rr,or,ir,sr,lr])(e);var J={objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n})),formatDate:At},Lt=(e,t)=>{if(!e||typeof e!="string"||!e.includes("${"))return e;let n=N(e,t);return n&&typeof n=="object"?e:n},Ct=(e,t)=>{if(e===void 0)return[];if(!Array.isArray(e)||e.some(n=>n===null||typeof n!="object"||Array.isArray(n)))throw new Error(`${t} must be an array of objects`);return e},St=(e,t=0)=>{let n=e?.sprites?.map(({resourceId:r})=>r)||[];return n.length===0?`character-container-${e.id}`:`character-container-${e.id}-${t}-${n.join("-")}`},De=(e,t)=>{if(!t.transformId)throw new Error(`Visual item "${t.id}" requires transformId`);let n=e.transforms?.[t.transformId];if(!n)throw new Error(`Transform "${t.transformId}" not found for visual item "${t.id}"`);return n},ar=(e={})=>e.textStyles||{},ur=(e={})=>e.images||{},fr=(e={})=>e.colors||{},dr=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,re=(e,t)=>e==="root"?`${t}`:`${e}.${t}`,q=(e,t,n)=>{if(typeof e!="string"||e.length===0)throw new Error(`${n} at "${t}" must resolve to a non-empty string`)},kt=(e,t,n)=>{if(e===void 0)return 1;if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${t} for text style "${n}" must be a number between 0 and 1`);if(e<0||e>1)throw new Error(`${t} for text style "${n}" must be a number between 0 and 1`);return e},Nt=(e,t)=>{if(typeof e!="string"||!dr.test(e))throw new Error(`${t} must resolve to a hex color`);return e.length===4?`#${e.slice(1).split("").map(n=>n.repeat(2)).join("")}`:e},Ot=(e,t,n)=>{let r=Nt(e,n);if(t===1)return r;let o=Number.parseInt(r.slice(1,3),16),i=Number.parseInt(r.slice(3,5),16),l=Number.parseInt(r.slice(5,7),16);return`rgba(${o}, ${i}, ${l}, ${t})`},pr=(e={},t)=>{let n=ar(e)?.[t];if(!n)throw new Error(`Text style "${t}" not found`);let r=e.fonts?.[n.fontId];if(!r)throw new Error(`Font "${n.fontId}" not found for text style "${t}"`);let o=e.colors?.[n.colorId];if(!o)throw new Error(`Color "${n.colorId}" not found for text style "${t}"`);let i=kt(n.colorAlpha,"colorAlpha",t),l={fontFamily:r.fileId,fontSize:n.fontSize??16,fontWeight:n.fontWeight??"400",fontStyle:n.fontStyle??"normal",lineHeight:n.lineHeight??1.2,fill:Ot(o.hex,i,`Color "${n.colorId}" for text style "${t}"`)};if(n.align!==void 0&&(l.align=n.align),n.wordWrap!==void 0&&(l.wordWrap=n.wordWrap),n.breakWords!==void 0&&(l.breakWords=n.breakWords),n.wordWrapWidth!==void 0&&(l.wordWrapWidth=n.wordWrapWidth),n.strokeColorId){let a=e.colors?.[n.strokeColorId];if(!a)throw new Error(`Stroke color "${n.strokeColorId}" not found for text style "${t}"`);let c=kt(n.strokeAlpha,"strokeAlpha",t);l.strokeColor=Ot(a.hex,c,`Stroke color "${n.strokeColorId}" for text style "${t}"`)}else if(n.strokeAlpha!==void 0)throw new Error(`strokeAlpha for text style "${t}" requires strokeColorId`);return n.strokeWidth!==void 0&&(l.strokeWidth=n.strokeWidth),l},Be=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>Be(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;if(Object.prototype.hasOwnProperty.call(e,"textStyle"))throw new Error(`Inline textStyle is not allowed in layout elements at "${n}". Use textStyleId instead`);let r={};for(let[o,i]of Object.entries(e))o!=="textStyleId"&&(r[o]=Be(i,t,re(n,o)));return e.textStyleId!==void 0&&(q(e.textStyleId,n,"textStyleId"),r.textStyle=pr(t,e.textStyleId)),r},Pt=(e={},t)=>{let n=fr(e)?.[t];if(!n)throw new Error(`Color "${t}" not found`);return Nt(n.hex,`Color "${t}"`)},Vt=e=>e==="hover.fill"?"hover.colorId":e==="click.fill"?"click.colorId":e==="rightClick.fill"?"rightClick.colorId":"colorId",Me=(e,t,n)=>{let r=e?.[t];if(!(!r||typeof r!="object"||Array.isArray(r))&&Object.prototype.hasOwnProperty.call(r,"fill"))throw new Error(`Inline ${t}.fill is not allowed in rect layout elements at "${n}". Use ${Vt(`${t}.fill`)} instead`)},hr=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>oe(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;let r={};for(let[o,i]of Object.entries(e))o!=="colorId"&&(r[o]=oe(i,t,re(n,o)));return e.colorId!==void 0&&(q(e.colorId,n,"colorId"),r.fill=Pt(t,e.colorId)),r},oe=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>oe(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;if(e.type==="rect"){if(Object.prototype.hasOwnProperty.call(e,"fill"))throw new Error(`Inline fill is not allowed in rect layout elements at "${n}". Use ${Vt("fill")} instead`);Me(e,"hover",n),Me(e,"click",n),Me(e,"rightClick",n)}let r={};for(let[o,i]of Object.entries(e))if(!(e.type==="rect"&&o==="colorId")){if(e.type==="rect"&&(o==="hover"||o==="click"||o==="rightClick")){r[o]=hr(i,t,re(n,o));continue}r[o]=oe(i,t,re(n,o))}return e.type==="rect"&&e.colorId!==void 0&&(q(e.colorId,n,"colorId"),r.fill=Pt(t,e.colorId)),r},je=(e={},t)=>{let n=ur(e)?.[t];return n||null},Dt=e=>e==="hoverUrl"||e==="hoverSrc"||e==="hover.src"?"hoverImageId":e==="clickUrl"||e==="clickSrc"||e==="click.src"?"clickImageId":"imageId",Rt=(e,t,n,r)=>{let o=e?.[t];if(!(!o||typeof o!="object"||Array.isArray(o))&&Object.prototype.hasOwnProperty.call(o,r))throw new Error(`Inline ${t}.${r} is not allowed in sprite layout elements at "${n}". Use ${Dt(`${t}.${r}`)} instead`)},Tt=(e,t,n)=>{let r=e[t];e[t]={...r&&typeof r=="object"&&!Array.isArray(r)?r:{},src:n}},Fe=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>Fe(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;if(e.type==="sprite"){for(let o of["url","src","hoverUrl","hoverSrc","clickUrl","clickSrc"])if(Object.prototype.hasOwnProperty.call(e,o))throw new Error(`Inline ${o} is not allowed in sprite layout elements at "${n}". Use ${Dt(o)} instead`);Rt(e,"hover",n,"src"),Rt(e,"click",n,"src")}let r={};for(let[o,i]of Object.entries(e))e.type==="sprite"&&(o==="imageId"||o==="hoverImageId"||o==="clickImageId")||(r[o]=Fe(i,t,re(n,o)));if(e.type==="sprite"&&e.imageId!==void 0){q(e.imageId,n,"imageId");let o=je(t,e.imageId),i=o?.fileId??e.imageId;r.src=i,r.width===void 0&&o?.width!==void 0&&(r.width=o.width),r.height===void 0&&o?.height!==void 0&&(r.height=o.height)}return e.type==="sprite"&&e.hoverImageId!==void 0&&(q(e.hoverImageId,n,"hoverImageId"),Tt(r,"hover",je(t,e.hoverImageId)?.fileId??e.hoverImageId)),e.type==="sprite"&&e.clickImageId!==void 0&&(q(e.clickImageId,n,"clickImageId"),Tt(r,"click",je(t,e.clickImageId)?.fileId??e.clickImageId)),r},Ue=(e,t={},n="root")=>Fe(oe(Be(e,t,n),t,n),t,n),U=Ue,K=({animations:e,animationsDef:t,resources:n,previousResourceId:r,currentResourceId:o,idPrefix:i,targetId:l,outTargetId:a})=>{if(t){if(t.in){let c=t.in.resourceId||t.in,s=n?.tweens?.[c];s&&!r&&e.push({id:`${i}-animation-in`,type:"tween",targetId:l,properties:structuredClone(s.properties)})}if(t.out){let c=t.out.resourceId||t.out,s=n?.tweens?.[c];s&&r&&r!==o&&e.push({id:`${i}-animation-out`,type:"tween",targetId:a||l,properties:structuredClone(s.properties)})}if(t.update){let c=t.update.resourceId||t.update,s=n?.tweens?.[c];s&&r&&r===o&&e.push({id:`${i}-animation-update`,type:"tween",targetId:l,properties:structuredClone(s.properties)})}}},gr=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),yr=(e,{presentationState:t,resources:n,variables:r})=>{let{elements:o}=e;if(t.base){let i=o.find(l=>l.id==="story");if(!i)return e;if(t.base.resourceId){let l=n?.layouts[t.base.resourceId];if(l){let a={id:"base",type:"container",children:l.elements},c=N(a,{variables:r},{functions:J});i.children.unshift(U(c,n))}}}return e},mr=(e,{presentationState:t,previousPresentationState:n,resources:r={},isLineCompleted:o,skipTransitionsAndAnimations:i,variables:l})=>{let{elements:a,animations:c}=e;if(t.background){let s=a.find(f=>f.id==="story");if(!s)return e;if(t.background.resourceId){let{images:f={},videos:u={}}=r,d=f[t.background.resourceId]||u[t.background.resourceId];if(d){let h=u[t.background.resourceId]!==void 0,g={id:`bg-cg-${t.background.resourceId}`,type:h?"video":"sprite",x:0,y:0,src:d.fileId,width:d.width,height:d.height};h&&(g.loop=t.background.loop??!1,g.volume=d.volume??500),s.children.push(g)}}if(t.background.resourceId){let{layouts:f={}}=r,u=f[t.background.resourceId];if(u){let d={id:`bg-cg-${t.background.resourceId}`,type:"container",children:u.elements},h=N(d,{variables:l},{functions:J});s.children.push(U(h,r))}}if(t.background.animations&&!o&&!i){let f=n?.background?.resourceId,u=t.background.resourceId;K({animations:c,animationsDef:t.background.animations,resources:r,previousResourceId:f,currentResourceId:u,idPrefix:"bg-cg",targetId:`bg-cg-${u}`,outTargetId:`bg-cg-${f}`})}}return e},br=(e,{presentationState:t,previousPresentationState:n,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i})=>{let{elements:l,animations:a}=e;if(t.character&&r){let c=l.find(u=>u.id==="story");if(!c)return e;let s=t.character.items||[],f=n?.character?.items||[];for(let u=0;u<s.length;u++){let d=s[u],{transformId:h,sprites:g}=d,m=f.find(L=>L.id===d.id),I=f.findIndex(L=>L.id===d.id),y=m?.sprites&&m.sprites.length>0,b=g&&g.length>0,v=I>=0?St(m,I):void 0;if(d.animations&&d.animations.out&&!g&&!h){if(!o&&y){let L=d.animations.out.resourceId,C=r?.tweens?.[L];if(C){let me={id:"character-animation-out",type:"tween",targetId:v||`character-container-${d.id}`,properties:structuredClone(C.properties)};a.push(me)}}continue}if(!g||g.length===0||!h){console.warn("Character item missing sprites or transformId:",d);continue}let A=St(d,u),E=r.transforms[h];if(!E){console.warn("Transform not found:",h);continue}let P={type:"container",id:A,x:d.x??E.x,y:d.y??E.y,anchorX:E.anchorX,anchorY:E.anchorY,rotation:E.rotation,scaleX:E.scaleX,scaleY:E.scaleY,children:[]};for(let L of g){let C=r.images[L.resourceId];if(!C){console.warn(`Image resource not found: ${L.resourceId}`);continue}P.children.push({type:"sprite",id:`${A}-${L.id}`,src:C.fileId,width:C.width,height:C.height,x:0,y:0})}c.children.push(P),d.animations&&!o&&!i&&K({animations:a,animationsDef:d.animations,resources:r,previousResourceId:y,currentResourceId:b,idPrefix:"character",targetId:A,outTargetId:v})}}return e},Ir=(e,{presentationState:t,previousPresentationState:n,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i,variables:l})=>{let{elements:a,animations:c}=e;if(t.visual&&r){let s=a.find(u=>u.id==="story");if(!s)return e;let f=t.visual.items;for(let u of f){if(u.resourceId){let{images:d={},videos:h={},spritesheets:g={}}=r,m=g[u.resourceId];if(m){let I=De(r,u),y=u.animationName;if(y){let b=m.animations?.[y];if(!b)throw new Error(`Animation '${y}' not found in spritesheet resource '${u.resourceId}'`);let v={id:`visual-${u.id}`,type:"animated-sprite",x:u.x??I.x,y:u.y??I.y,width:u.width??m.width,height:u.height??m.height,alpha:u.alpha??1,anchorX:I.anchorX,anchorY:I.anchorY,rotation:I.rotation,scaleX:I.scaleX,scaleY:I.scaleY,spritesheetSrc:m.fileId,spritesheetData:m.jsonData,animation:{frames:b.frames,animationSpeed:u.animationSpeed??b.animationSpeed??.5,loop:u.loop??b.loop??!0}};s.children.push(structuredClone(v))}}else{let I=d[u.resourceId]||h[u.resourceId];if(I){let y=h[u.resourceId]!==void 0,b=De(r,u),v={id:`visual-${u.id}`,type:y?"video":"sprite",src:I.fileId,width:I.width,height:I.height,x:b.x,y:b.y,anchorX:b.anchorX,anchorY:b.anchorY,rotation:b.rotation,scaleX:b.scaleX,scaleY:b.scaleY};y&&(v.loop=I.loop??!1,v.volume=I.volume??500),s.children.push(v)}}}if(u.resourceId){let{layouts:d={}}=r,h=d[u.resourceId];if(h){let g=De(r,u),m={id:`visual-${u.id}`,type:"container",children:structuredClone(h.elements),x:g.x,y:g.y,anchorX:g.anchorX,anchorY:g.anchorY,rotation:g.rotation,scaleX:g.scaleX,scaleY:g.scaleY},I=N(m,{variables:l},{functions:J});s.children.push(U(I,r))}}if(u.animations&&!o&&!i){let h=(n?.visual?.items||[]).find(g=>g.id===u.id);K({animations:c,animationsDef:u.animations,resources:r,previousResourceId:h?.resourceId,currentResourceId:u.resourceId,idPrefix:u.id,targetId:`visual-${u.id}`})}}}return e},wr=(e,{presentationState:t,previousPresentationState:n,resources:r={},dialogueUIHidden:o,autoMode:i,skipMode:l,canRollback:a,skipOnlyViewedLines:c,isLineCompleted:s,skipTransitionsAndAnimations:f,variables:u,saveSlots:d=[]})=>{let{elements:h,animations:g}=e;if(!t.dialogue||o)return e;let m=h.find(I=>I.id==="story");if(!m)return e;if(t.dialogue.ui&&t.dialogue.ui.resourceId){let{layouts:I={}}=r,y=I[t.dialogue.ui.resourceId];if(y){let b;t.dialogue.characterId&&(b=r.characters[t.dialogue.characterId]),t.dialogue.character&&(b={...b,name:t.dialogue.character.name});let v={elements:y.elements},A=t.dialogue?.content===void 0?[{text:""}]:Ct(t.dialogue.content,"dialogue.content"),E={variables:u,autoMode:i,skipMode:l,canRollback:a,skipOnlyViewedLines:c,isLineCompleted:s,saveSlots:d,effectiveSoundVolume:u?._muteAll?0:u?._soundVolume??500,textSpeed:u?._textSpeed??50,dialogue:{character:{name:b?.name||""},content:A.map(C=>({...C,text:Lt(C.text,{variables:u})})),lines:(t.dialogue?.lines||[]).map((C,me)=>({content:Ct(C.content,`dialogue.lines[${me}].content`).map(Ke=>({...Ke,text:Lt(Ke.text,{variables:u})})),characterName:C.characterId&&r.characters?.[C.characterId]?.name||""}))}},P=N(v,E,{functions:J}),L=U(P?.elements,r);if(Array.isArray(L))for(let C of L)m.children.push(C);else L&&m.children.push(L)}}return t.dialogue.ui?.animations&&!s&&!f&&K({animations:g,animationsDef:t.dialogue.ui.animations,resources:r,previousResourceId:n?.dialogue?.ui?.resourceId,currentResourceId:t.dialogue.ui?.resourceId,idPrefix:"dialogue-ui",targetId:"dialogue-container"}),e},vr=(e,{presentationState:t,previousPresentationState:n,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i,screen:l})=>{let{elements:a,animations:c}=e;if(t.choice&&r){let s=a.find(u=>u.id==="story");if(!s)return e;s.children.push({id:"choice-blocker",type:"rect",fill:"transparent",width:l.width,height:l.height,x:0,y:0,click:{actionPayload:{actions:{}}}});let f=r?.layouts[t.choice.resourceId];if(f&&f.elements){let u={elements:f.elements},d=N(u,{choice:{items:t.choice?.items??[]}}),h=U(d?.elements,r);if(Array.isArray(h))for(let g of h)s.children.push(g);else h&&s.children.push(h)}t.choice.animations&&!o&&!i&&K({animations:c,animationsDef:t.choice.animations,resources:r,previousResourceId:n?.choice?.resourceId,currentResourceId:t.choice.resourceId,idPrefix:"choice",targetId:"choice-container"})}return e},xr=(e,{presentationState:t,resources:n})=>{if(t.keyboard?.resourceId){let r=n?.keyboards?.[t.keyboard.resourceId];r&&(e.global.keyboard=r)}return e},_r=(e,{presentationState:t,resources:n,variables:r})=>{let{elements:o,audio:i}=e;if(t.bgm&&n){if(!o.find(s=>s.id==="story"))return e;let a=n.sounds[t.bgm.resourceId];if(!a)return e;let c=r?._muteAll?0:r?._musicVolume??500;i.push({id:"bgm",type:"sound",src:a.fileId,loop:t.bgm.loop??!0,volume:c,delay:t.bgm.delay??null})}return e},Ar=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(t.sfx&&n){let o=t.sfx.items;for(let i of o){let l=n.sounds?.[i.resourceId];l&&r.push({id:i.id,type:"sound",src:l.fileId,loop:i.loop??l.loop??!0,volume:i.volume??l.volume??500,delay:i.delay??l.delay??null})}}return e},Er=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(!t?.voice)return e;let{fileId:o,volume:i,loop:l}=t.voice;return r.push({id:`voice-${o}`,type:"sound",src:o,volume:i??500,loop:l??!1}),e},$r=(e,{presentationState:t,previousPresentationState:n,resources:r={},variables:o,autoMode:i,skipMode:l,canRollback:a,saveSlots:c=[],isLineCompleted:s,skipTransitionsAndAnimations:f})=>{let{elements:u,animations:d}=e;if(t.layout){let h=u.find(b=>b.id==="story");if(!h)return e;let g=r.layouts[t.layout.resourceId];if(!g)return e;Array.isArray(g.transitions)&&!s&&!f&&g.transitions.forEach(b=>{d.push(b)});let m={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:g.elements||[]},I={variables:o,saveSlots:c,autoMode:i,skipMode:l,canRollback:a,effectiveSoundVolume:o?._muteAll?0:o?._soundVolume??500,textSpeed:o?._textSpeed??50},y=N(m,I,{functions:J});h.children.push(U(y,r))}if(t.layout?.animations&&!s&&!f){let h=n?.layout?.resourceId,g=t.layout?.resourceId;K({animations:d,animationsDef:t.layout.animations,resources:r,previousResourceId:h,currentResourceId:g,idPrefix:"layout",targetId:`layout-${g}`,outTargetId:`layout-${h}`})}return e},Lr=(e,{resources:t={},variables:n,autoMode:r,skipMode:o,canRollback:i,layeredViews:l=[],dialogueHistory:a=[],saveSlots:c=[],screen:s})=>{let{elements:f,animations:u}=e;return l&&l.length>0&&l.forEach((d,h)=>{let g=t.layouts[d.resourceId];if(!g){console.warn(`LayeredView layout not found: ${d.resourceId}`);return}Array.isArray(g.transitions)&&g.transitions.forEach(P=>{u.push(P)});let m={id:`layeredView-${h}`,type:"container",x:0,y:0,children:[{id:`layeredView-${h}-blocker`,type:"rect",fill:"transparent",width:s.width,height:s.height,x:0,y:0,click:{actionPayload:{actions:{}}}},...g.elements||[]]},I=a.map(P=>{let L=t.characters?.[P.characterId];return{...P,characterName:L?.name||""}}),y={variables:n,autoMode:r,skipMode:o,canRollback:i,saveSlots:c,effectiveSoundVolume:n?._muteAll?0:n?._soundVolume??500,textSpeed:n?._textSpeed??50,historyDialogue:I,characters:t.characters||{}},b=N(m,y,{functions:J}),[v,...A]=b.children||[],E=U({...b,children:A},t);f.push({...E,children:v?[v,...E.children||[]]:E.children})}),e},Mt=e=>he(gr,[yr,mr,br,Ir,wr,vr,xr,$r,_r,Ar,Er,Lr])(e);var X={manual:{enabled:!0,requireLineCompleted:!1},auto:{enabled:!1},applyMode:"persistent"},jt=e=>{if((e.global.nextLineConfig?.applyMode??"persistent")!=="singleLine")return;let n=e.global.nextLineConfig?.auto?.enabled===!0;e.global.nextLineConfig={manual:{...X.manual},auto:{...X.auto},applyMode:X.applyMode},n&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"})},Cr=e=>{let{projectData:t}=e,n=e.global??{},{saveSlots:r={},variables:o={}}=n,i=t.story.initialSceneId,l=t.story.scenes[i],a=l.initialSectionId,c=l.sections[a],s={sceneId:i,sectionId:a,lineId:c.initialLineId??c.lines[0].id},{contextVariableDefaultValues:f,globalVariablesDefaultValues:u}=vt(t),d={...u,...o};return{projectData:t,global:{isLineCompleted:!1,pendingEffects:[],autoMode:!1,skipMode:!1,dialogueUIHidden:!1,isDialogueHistoryShowing:!1,viewedRegistry:{sections:[],resources:[]},nextLineConfig:{manual:{...X.manual},auto:{...X.auto},applyMode:X.applyMode},saveSlots:r,layeredViews:[],variables:d},contexts:[{currentPointerMode:"read",pointers:{read:s,history:{sectionId:void 0,lineId:void 0,historySequenceIndex:void 0}},historySequence:[{sectionId:s.sectionId,initialState:{...f},lines:[{id:s.lineId}]}],configuration:{},views:[],bgm:{resourceId:void 0},variables:f}]}},Sr=({state:e})=>e.global.layeredViews||[],kr=({state:e})=>e.global.pendingEffects,Bt=({state:e})=>e.global.skipMode,Or=({state:e})=>e.global.autoMode,Ft=({state:e})=>e.global.dialogueUIHidden,ze=({state:e})=>{let t=e.contexts[e.contexts.length-1];if(!t)return[];let{sectionId:n,lineId:r}=t.pointers.read,o=O({state:e},{sectionId:n});if(!o?.lines||!Array.isArray(o.lines))return[];let i=o.lines.findIndex(c=>c.id===r);return o.lines.slice(0,i+1).filter(c=>c.actions?.dialogue).map(c=>{let s=c.actions.dialogue,f="";return s.characterId&&(f=e.projectData.resources?.characters?.[s.characterId]?.name||""),{content:s.content,characterId:s.characterId,characterName:f}})},Ye=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(c=>c.sectionId===n);if(!o)return!1;if(o.lastLineId===void 0||r===void 0)return!0;let i=O({state:e},{sectionId:n});if(!i||!i.lines||!Array.isArray(i.lines))return!1;let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);return l===-1||a===-1?o.lastLineId===r:a<l},Rr=({state:e},t)=>{let{resourceId:n}=t;return!!e.global.viewedRegistry.resources.find(o=>o.resourceId===n)},Tr=({state:e})=>e.global.nextLineConfig,Nr=({state:e})=>e.global.saveSlots,Pr=({state:e},t)=>{let{slotKey:n}=t;return e.global.saveSlots[n]},W=({state:e})=>{let t=e.contexts[e.contexts.length-1];if(!t)return;let n=t.pointers?.[t.currentPointerMode];return{currentPointerMode:t.currentPointerMode,pointer:n}},O=({state:e},t)=>{let{sectionId:n}=t,r=e.projectData?.story?.scenes||{};for(let o in r){let i=r[o];if(i.sections&&i.sections[n])return i.sections[n]}},Ut=({state:e})=>{let t=W({state:e});if(!t?.pointer)return;let{sectionId:n,lineId:r}=t.pointer,o=O({state:e},{sectionId:n});if(!(!o?.lines||!Array.isArray(o.lines)))return o.lines.find(i=>i.id===r)},Vr=({state:e})=>{let t=W({state:e})?.pointer,n=t?.sectionId,r=t?.lineId,i=O({state:e},{sectionId:n})?.lines||[],l=i.findIndex(s=>s.id===r);if(l<0)return;let a;return i.slice(0,l+1).forEach(s=>{if(!s?.actions||!Object.prototype.hasOwnProperty.call(s.actions,"choice"))return;let f=s.actions.choice;if(!f?.resourceId){f?.animations||(a=void 0);return}a=f.resourceId}),a},Wt=({state:e})=>{let{sectionId:t,lineId:n}=W({state:e}).pointer,o=O({state:e},{sectionId:t})?.lines||[],i=o.findIndex(s=>s.id===n),a=o.slice(0,i+1).map(s=>{let f=s.actions||{},u={};return Object.keys(f).forEach(d=>{u[d]=f[d]}),u});return ne(a)},Dr=({state:e})=>{let t=zt({state:e}),r=Ut({state:e})?.actions??{},o=ne([t??{},r]);return Ve(t??{},o??{})},Mr=({state:e},{sectionId:t})=>{let n=O({state:e},{sectionId:t});if(!n?.lines)return{lines:[]};let r=[],o={};for(let i of n.lines){let l=i.actions||{},a=ne([o,l]),c=Ve(o,a);r.push({id:i.id,changes:c}),o=a}return{lines:r}},zt=({state:e})=>{let{sectionId:t,lineId:n}=W({state:e}).pointer,o=O({state:e},{sectionId:t})?.lines||[],i=o.findIndex(c=>c.id===n);if(i<=0)return null;let a=o.slice(0,i).map(c=>{let s=c.actions||{},f={};return Object.keys(s).forEach(u=>{f[u]=s[u]}),f});return ne(a)},Yt=({state:e},{slotsPerPage:t=6}={})=>{let o=(({...e.global.variables,...e.contexts[e.contexts.length-1].variables}.loadPage??1)-1)*t+1,i=[];for(let l=0;l<t;l++){let a=o+l,c=e.global.saveSlots&&e.global.saveSlots[a]||{};i.push({slotNumber:a,...c})}return{saveSlots:i}},jr=({state:e})=>{let t=Wt({state:e}),n=zt({state:e}),r={...e.global.variables,...e.contexts[e.contexts.length-1].variables},{saveSlots:o}=Yt({state:e});return Mt({presentationState:t,previousPresentationState:n,resources:e.projectData.resources,screen:e.projectData.screen,dialogueUIHidden:e.global.dialogueUIHidden,autoMode:e.global.autoMode,skipMode:e.global.skipMode,canRollback:Qt({state:e}),skipOnlyViewedLines:!r._skipUnseenText,isLineCompleted:e.global.isLineCompleted,skipTransitionsAndAnimations:!!r._skipTransitionsAndAnimations,layeredViews:e.global.layeredViews,dialogueHistory:ze({state:e}),saveSlots:o,variables:r})},Br=({state:e},t)=>(e.global.layeredViews.push(t),e.global.pendingEffects.push({name:"render"}),e),Fr=({state:e})=>(e.global.layeredViews.pop(),e.global.pendingEffects.push({name:"render"}),e),Ur=({state:e},t)=>(e.global.layeredViews.length>0&&(e.global.layeredViews[e.global.layeredViews.length-1]=t),e.global.pendingEffects.push({name:"render"}),e),Wr=({state:e})=>(e.global.layeredViews=[],e.global.pendingEffects.push({name:"render"}),e),Ht=({state:e})=>{if(e.global.skipMode&&(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"})),e.global.autoMode=!0,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.isLineCompleted){let t=e.global.variables._autoForwardTime??1e3;e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:t}})}return e.global.pendingEffects.push({name:"render"}),e},ye=({state:e})=>(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),zr=({state:e})=>(e.global.autoMode?ye({state:e}):Ht({state:e}),e),qt=({state:e})=>(e.global.autoMode&&(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"})),e.global.skipMode=!0,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"startSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),G=({state:e})=>(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Yr=({state:e})=>(Bt({state:e})?G({state:e}):qt({state:e}),e),Jt=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),e),Kt=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),e),Hr=({state:e})=>(Ft({state:e})?Jt({state:e}):Kt({state:e}),e),qr=({state:e})=>{let t=ze({state:e});return e.global.isDialogueHistoryShowing=!0,e.global.pendingEffects.push({name:"render"}),e},Jr=({state:e})=>(e.global.isDialogueHistoryShowing=!1,e.global.pendingEffects.push({name:"render"}),e),Kr=({state:e})=>(e.global.pendingEffects=[],e),Xr=({state:e},t)=>(e.global.pendingEffects.push(t),e),Xt=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(i=>i.sectionId===n);if(o){let i=O({state:e},{sectionId:n});if(i?.lines&&o.lastLineId!==void 0){let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);(l===-1||a>l)&&(o.lastLineId=r)}else o.lastLineId=r}else e.global.viewedRegistry.sections.push({sectionId:n,lastLineId:r});return e.global.pendingEffects.push({name:"render"}),e},Gr=({state:e},t)=>{let{resourceId:n}=t;return e.global.viewedRegistry.resources.find(o=>o.resourceId===n)||e.global.viewedRegistry.resources.push({resourceId:n}),e.global.pendingEffects.push({name:"render"}),e},Qr=({state:e},t)=>{let{manual:n,auto:r,applyMode:o}=t,i=e.global.nextLineConfig.auto?.enabled,l=e.global.nextLineConfig?.applyMode;n&&r?(e.global.nextLineConfig={manual:n,auto:r},o!==void 0?e.global.nextLineConfig.applyMode=o:l!==void 0&&(e.global.nextLineConfig.applyMode=l)):(n&&(e.global.nextLineConfig.manual=n),r&&(e.global.nextLineConfig.auto=r),o!==void 0&&(e.global.nextLineConfig.applyMode=o));let a=e.global.nextLineConfig.auto?.enabled;return a===!0&&!i?e.global.nextLineConfig.auto?.trigger==="fromStart"?e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}}):e.global.isLineCompleted&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}}):a===!1&&i&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.pendingEffects.push({name:"render"}),e},Zr=({state:e},t)=>{let{slot:n,thumbnailImage:r}=t,o=String(n),i={contexts:[...e.contexts],viewedRegistry:e.global.viewedRegistry},l={slotKey:o,date:Date.now(),image:r,state:i};return e.global.saveSlots[o]=l,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}},{name:"render"}),e},eo=({state:e},t)=>{let{slot:n}=t,r=String(n),o=e.global.saveSlots[r];return o&&(e.global.viewedRegistry=o.state.viewedRegistry,e.contexts=o.state.contexts,e.global.pendingEffects.push({name:"render"})),e},to=({state:e},t)=>{let{projectData:n}=t;return e.projectData=n,e.global.pendingEffects.push({name:"render"}),e},no=({state:e},t)=>{let{sectionId:n,lineId:r}=t;if(!r)return console.warn("jumpToLine requires lineId parameter"),e;let o=e.contexts[e.contexts.length-1];if(!o)return console.warn("No context available for jumpToLine"),e;let i=n||o.pointers.read?.sectionId;if(n&&!O({state:e},{sectionId:n}))return console.warn(`Section not found: ${n}`),e;let l=O({state:e},{sectionId:i});return!l?.lines||!Array.isArray(l.lines)?(console.warn(`Section ${i} has no lines`),e):l.lines.find(c=>c.id===r)?(o.pointers.read={sectionId:i,lineId:r},e.global.isLineCompleted=!1,ie({state:e},{lineId:r}),e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e):(console.warn(`Line not found: ${r} in section ${i}`),e)},Gt=({state:e},t)=>{let{item:n}=t,r=e.contexts[e.contexts.length-1];if(r&&r.historySequence){let o={...r.variables};r.historySequence.push({sectionId:n.sectionId,initialState:o,lines:[]})}return e.global.pendingEffects.push({name:"render"}),e},ie=({state:e},t)=>{let{lineId:n}=t,r=e.contexts[e.contexts.length-1];if(!r?.historySequence)return e;let o=r.historySequence;if(o.length===0)return e;let i=o[o.length-1];return i.lines||(i.lines=[]),i.lines.push({id:n}),e},ro=({state:e})=>{if(!e.global.nextLineConfig.manual.enabled)return e;if(!e.global.isLineCompleted){if(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.autoMode){let c=e.global.variables._autoForwardTime??1e3;e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:c}})}let a=e.global.nextLineConfig;return a?.auto?.enabled&&a.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:a.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e}let t=W({state:e})?.pointer,n=t?.sectionId,o=O({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=!e.global.variables?._skipUnseenText;if(e.global.skipMode&&c&&!Ye({state:e},{sectionId:n,lineId:a.id}))return G({state:e}),e;let s=e.contexts[e.contexts.length-1];if(s){let u=s.pointers.read.lineId;u&&n&&Xt({state:e},{sectionId:n,lineId:u}),s.pointers.read={sectionId:n,lineId:a.id}}e.global.isLineCompleted=!1,ie({state:e},{lineId:a.id}),jt(e),e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"});let f=e.global.nextLineConfig;f?.auto?.enabled&&f.auto.trigger==="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:f.auto.delay}})}else e.global.autoMode&&ye({state:e}),e.global.skipMode&&G({state:e});return e},oo=({state:e})=>{if(e.global.isLineCompleted)return e;if(e.global.isLineCompleted=!0,e.global.autoMode){let n=e.global.variables._autoForwardTime??1e3;e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:n}})}let t=e.global.nextLineConfig;return t?.auto?.enabled&&t.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:t.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e},io=({state:e},t)=>{let{sectionId:n}=t,r=O({state:e},{sectionId:n});if(!r||!r.lines||r.lines.length===0)return e;let o=r.lines,i=e.contexts[e.contexts.length-1];if(!i||!i.pointers)return e;let l=i.pointers.history||i.pointers.read;if(i.currentPointerMode!=="history"||!i.pointers.history){if(!l)return e;i.currentPointerMode="history",i.pointers.history={sectionId:n,lineId:l?.lineId};let f=o.findIndex(u=>u.id===l.lineId)-1;if(f>=0&&f<o.length){let u=o[f];i.pointers.history={sectionId:n,lineId:u.id}}return e.global.pendingEffects.push({name:"render"}),e}let c=o.findIndex(s=>s.id===i.pointers.history.lineId)-1;if(c>=0&&c<o.length){let s=o[c];i.pointers.history={sectionId:n,lineId:s.id},e.global.pendingEffects.push({name:"render"})}return e},so=({state:e},t)=>{let{sectionId:n}=t,r=O({state:e},{sectionId:n});if(!r)return console.warn(`Section not found: ${n}`),e;let o=r.lines?.[0];if(!o)return console.warn(`Section ${n} has no lines`),e;e.global.autoMode&&ye({state:e}),e.global.skipMode&&G({state:e});let i=e.contexts[e.contexts.length-1];return i&&(i.pointers.read={sectionId:n,lineId:o.id},Gt({state:e},{item:{sectionId:n}}),ie({state:e},{lineId:o.id})),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e},lo=({state:e})=>{if(Vr({state:e}))return e;let t=W({state:e})?.pointer,n=t?.sectionId,o=O({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=!e.global.variables?._skipUnseenText;if(e.global.skipMode&&c&&!Ye({state:e},{sectionId:n,lineId:a.id}))return G({state:e}),e;let s=e.contexts[e.contexts.length-1];s&&(s.pointers.read={sectionId:n,lineId:a.id}),e.global.isLineCompleted=!1,ie({state:e},{lineId:a.id}),jt(e),e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e.global.nextLineConfig.auto?.enabled&&e.global.nextLineConfig.auto.trigger==="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}})}else e.global.nextLineConfig.auto?.enabled&&(e.global.nextLineConfig.auto.enabled=!1,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}));return e},co=({state:e},t)=>{let{id:n,operations:r=[]}=t;if(!n)throw new Error("updateVariable requires an id field");if(typeof n!="string"||!/^[a-zA-Z0-9]+$/.test(n))throw new Error(`updateVariable id must be alphanumeric, got: "${n}"`);let o=e.contexts[e.contexts.length-1],i=!1,l=!1,a=!1;if(r.forEach(({variableId:c,op:s,value:f})=>{let u=e.projectData.resources?.variables?.[c],d=u?.scope,h=u?.type;xt(d,c),_t(h,s,c);let g=d==="context"?o.variables:e.global.variables;d==="context"?i=!0:d==="global-device"?l=!0:d==="global-account"&&(a=!0),g[c]=Ne(g[c],s,f)}),i){let c=o.historySequence;if(c&&c.length>0){let s=c[c.length-1];if(s.lines&&s.lines.length>0){let f=s.lines[s.lines.length-1];f.updateVariableIds||(f.updateVariableIds=[]),f.updateVariableIds.push(n)}}}if(l){let c=Pe(e.global.variables,e.projectData.resources?.variables,"global-device");e.global.pendingEffects.push({name:"saveGlobalDeviceVariables",payload:{globalDeviceVariables:c}})}if(a){let c=Pe(e.global.variables,e.projectData.resources?.variables,"global-account");e.global.pendingEffects.push({name:"saveGlobalAccountVariables",payload:{globalAccountVariables:c}})}return e.global.pendingEffects.push({name:"render"}),e},We=(e,t,n="")=>{if(e!=null){if(n==="updateVariable"&&typeof e=="object"&&e.id===t&&Array.isArray(e.operations))return e;if(Array.isArray(e)){for(let r of e){let o=We(r,t,n);if(o)return o}return}if(typeof e=="object")for(let r of Object.keys(e)){let o=We(e[r],t,r);if(o)return o}}},He=({state:e},t)=>{let{offset:n}=t;if(n===void 0||typeof n!="number")return console.warn("selectLineIdByOffset requires a numeric offset"),null;let r=e.contexts[e.contexts.length-1];if(!r)return null;let o=r.pointers.read?.sectionId,i=r.pointers.read?.lineId;if(!o||!i)return null;let a=r.historySequence?.find(u=>u.sectionId===o);if(!a?.lines||a.lines.length===0)return null;let c=a.lines.findLastIndex(u=>u.id===i);if(c===-1)return null;let s=c+n;if(s<0||s>=a.lines.length)return null;let f=a.lines[s];return{sectionId:o,lineId:f.id}},Qt=({state:e})=>He({state:e},{offset:-1})!==null,ao=({state:e},t)=>{let{offset:n=-1}=t;if(n>=0)throw new Error("rollbackByOffset requires a negative offset");let r=He({state:e},{offset:n});return r?Zt({state:e},{sectionId:r.sectionId,lineId:r.lineId}):e},Zt=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.contexts[e.contexts.length-1];if(!o)throw new Error("No context available for rollbackToLine");let l=o.historySequence?.find(s=>s.sectionId===n);if(!l?.lines)throw new Error(`Section ${n} not found in history or has no lines`);let a=l.lines.findIndex(s=>s.id===r);if(a===-1)throw new Error(`Line ${r} not found in section ${n} history`);let c=l.initialState||{};o.variables={...c};for(let s=0;s<a;s++){let u=l.lines[s].updateVariableIds||[];for(let d of u){let h=We(e.projectData,d);if(!h)throw new Error(`Action definition not found for ID: ${d}`);let g=h.operations||[];for(let{variableId:m,op:I,value:y}of g)e.projectData.resources?.variables?.[m]?.scope==="context"&&(o.variables[m]=Ne(o.variables[m],I,y))}}return l.lines=l.lines.slice(0,a),l.lines.push({id:r}),o.pointers.read={sectionId:n,lineId:r},o.currentPointerMode="read",o.pointers.history={sectionId:null,lineId:null,historySequenceIndex:null},e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e},en=e=>{let t=Cr(e);return wt(t,{selectPendingEffects:kr,selectSkipMode:Bt,selectAutoMode:Or,selectDialogueUIHidden:Ft,selectDialogueHistory:ze,selectIsLineViewed:Ye,selectIsResourceViewed:Rr,selectNextLineConfig:Tr,selectSaveSlots:Nr,selectSaveSlot:Pr,selectCurrentPointer:W,selectSection:O,selectCurrentLine:Ut,selectPresentationState:Wt,selectPresentationChanges:Dr,selectSectionLineChanges:Mr,selectCurrentPageSlots:Yt,selectRenderState:jr,selectLayeredViews:Sr,selectLineIdByOffset:He,selectCanRollback:Qt,startAutoMode:Ht,stopAutoMode:ye,toggleAutoMode:zr,startSkipMode:qt,stopSkipMode:G,toggleSkipMode:Yr,showDialogueUI:Jt,hideDialogueUI:Kt,toggleDialogueUI:Hr,showDialogueHistory:qr,hideDialogueHistory:Jr,clearPendingEffects:Kr,appendPendingEffect:Xr,addViewedLine:Xt,addViewedResource:Gr,setNextLineConfig:Qr,saveSaveSlot:Zr,loadSaveSlot:eo,updateProjectData:to,sectionTransition:so,jumpToLine:no,addToHistorySequence:Gt,addLineToHistory:ie,nextLine:ro,markLineCompleted:oo,prevLine:io,rollbackToLine:Zt,rollbackByOffset:ao,pushLayeredView:Br,popLayeredView:Fr,replaceLastLayeredView:Ur,clearLayeredViews:Wr,updateVariable:co,nextLineFromSystem:lo},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function qe(e){let t,n=0,{handlePendingEffects:r}=e,o=()=>{for(;t.selectPendingEffects().length>0;){let y=[...t.selectPendingEffects()];t.clearPendingEffects(),r(y)}},i=({initialState:y})=>{t=en(y),n=0,t.appendPendingEffect({name:"render"}),I(),o()},l=()=>t.selectPresentationState(),a=()=>t.selectPresentationChanges(),c=y=>t.selectSectionLineChanges(y),s=()=>(n+=1,{...t.selectRenderState(),id:`render-${n}`}),f=()=>t.selectSaveSlots(),u=()=>t.selectSkipMode(),d=()=>t.selectAutoMode(),h=(y,b)=>{t[y]&&(t[y](b),o())},g=y=>{if(!y)return;if(Object.prototype.hasOwnProperty.call(y,"event"))throw new Error('eventContext key "event" is no longer supported. Use "_event".');let{_event:b,...v}=y,A=t.selectAllVariables?t.selectAllVariables():void 0;return{...v,_event:b,variables:A}},m=(y,b)=>{let v=g(b),A=Et(y,v);Object.entries(A).forEach(([E,P])=>{h(E,P)})},I=()=>{let y=t.selectCurrentLine();y?.actions&&m(y.actions)};return{init:i,handleAction:h,handleActions:m,selectRenderState:s,selectPresentationState:l,selectPresentationChanges:a,selectSectionLineChanges:c,selectSaveSlots:f,handleLineActions:I}}var Je=()=>{let e=0,t=null;return{getElapsed:()=>e,setElapsed:n=>{e=n},addElapsed:n=>{e+=n},getCallback:()=>t,setCallback:n=>{t=n}}},uo=({engine:e,routeGraphics:t},n)=>{let r=e.selectRenderState();t.render(r)},fo=({engine:e},t)=>{e.handleLineActions()},po=({engine:e,ticker:t,autoTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(t.remove(i),n.setCallback(null),n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},ho=({ticker:e,autoTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},go=({engine:e,ticker:t,skipTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS),n.getElapsed()>=30&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},yo=({ticker:e,skipTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},mo=({engine:e,ticker:t,nextLineConfigTimerState:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}),t.remove(i),n.setCallback(null))};n.setCallback(i),t.add(i)},bo=({ticker:e,nextLineConfigTimerState:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},Io=({},e)=>{localStorage.setItem("saveSlots",JSON.stringify(e.saveSlots))},wo=({},e)=>{localStorage.setItem("globalDeviceVariables",JSON.stringify(e.globalDeviceVariables))},vo=({},e)=>{localStorage.setItem("globalAccountVariables",JSON.stringify(e.globalAccountVariables))},xo={render:uo,saveSlots:Io,saveGlobalDeviceVariables:wo,saveGlobalAccountVariables:vo,handleLineActions:fo,startAutoNextTimer:po,clearAutoNextTimer:ho,startSkipNextTimer:go,clearSkipNextTimer:yo,nextLineConfigTimer:mo,clearNextLineConfigTimer:bo},_o=({getEngine:e,routeGraphics:t,ticker:n})=>{let r=Je(),o=Je(),i=Je();return async l=>{let a=e(),c=l.reduce((u,d)=>(u[d.name]=d,u),{}),s=Object.values(c),f={engine:a,routeGraphics:t,ticker:n,autoTimer:r,skipTimer:o,nextLineConfigTimerState:i};for(let u of s){let d=xo[u.name];d&&d(f,u.payload)}}},Ao=_o;var Eo=(e,t={})=>{let{resources:n={}}=t;return Ue(e,n)};var Ei=qe;export{Ao as createEffectsHandler,Ei as default,Eo as resolveLayoutReferences};
|
|
1
|
+
var rn=Object.defineProperty;var on=(e,t)=>{for(var n in t)rn(e,n,{get:t[n],enumerable:!0})};var nt=Symbol.for("immer-nothing"),Ge=Symbol.for("immer-draftable"),R=Symbol.for("immer-state");function P(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var z=Object.getPrototypeOf;function Y(e){return!!e&&!!e[R]}function j(e){return e?rt(e)||Array.isArray(e)||!!e[Ge]||!!e.constructor?.[Ge]||ue(e)||fe(e):!1}var sn=Object.prototype.constructor.toString();function rt(e){if(!e||typeof e!="object")return!1;let t=z(e);if(t===null)return!0;let n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return n===Object?!0:typeof n=="function"&&Function.toString.call(n)===sn}function se(e,t){ae(e)===0?Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function ae(e){let t=e[R];return t?t.type_:Array.isArray(e)?1:ue(e)?2:fe(e)?3:0}function ve(e,t){return ae(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function ot(e,t,n){let r=ae(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function ln(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function ue(e){return e instanceof Map}function fe(e){return e instanceof Set}function M(e){return e.copy_||e.base_}function xe(e,t){if(ue(e))return new Map(e);if(fe(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=rt(e);if(t===!0||t==="class_only"&&!n){let r=Object.getOwnPropertyDescriptors(e);delete r[R];let o=Reflect.ownKeys(r);for(let i=0;i<o.length;i++){let l=o[i],a=r[l];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(r[l]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[l]})}return Object.create(z(e),r)}else{let r=z(e);if(r!==null&&n)return{...e};let o=Object.create(r);return Object.assign(o,e)}}function Le(e,t=!1){return de(e)||Y(e)||!j(e)||(ae(e)>1&&(e.set=e.add=e.clear=e.delete=cn),Object.freeze(e),t&&Object.entries(e).forEach(([n,r])=>Le(r,!0))),e}function cn(){P(2)}function de(e){return Object.isFrozen(e)}var an={};function B(e){let t=an[e];return t||P(0,e),t}var Q;function it(){return Q}function un(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Qe(e,t){t&&(B("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function Ae(e){_e(e),e.drafts_.forEach(fn),e.drafts_=null}function _e(e){e===Q&&(Q=e.parent_)}function Ze(e){return Q=un(Q,e)}function fn(e){let t=e[R];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function et(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];return e!==void 0&&e!==n?(n[R].modified_&&(Ae(t),P(4)),j(e)&&(e=le(t,e),t.parent_||ce(t,e)),t.patches_&&B("Patches").generateReplacementPatches_(n[R].base_,e,t.patches_,t.inversePatches_)):e=le(t,n,[]),Ae(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==nt?e:void 0}function le(e,t,n){if(de(t))return t;let r=t[R];if(!r)return se(t,(o,i)=>tt(e,r,t,o,i,n)),t;if(r.scope_!==e)return t;if(!r.modified_)return ce(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;let o=r.copy_,i=o,l=!1;r.type_===3&&(i=new Set(o),o.clear(),l=!0),se(i,(a,c)=>tt(e,r,o,a,c,n,l)),ce(e,o,!1),n&&e.patches_&&B("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function tt(e,t,n,r,o,i,l){if(Y(o)){let a=i&&t&&t.type_!==3&&!ve(t.assigned_,r)?i.concat(r):void 0,c=le(e,o,a);if(ot(n,r,c),Y(c))e.canAutoFreeze_=!1;else return}else l&&n.add(o);if(j(o)&&!de(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;le(e,o),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&Object.prototype.propertyIsEnumerable.call(n,r)&&ce(e,o)}}function ce(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Le(t,n)}function dn(e,t){let n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:it(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=r,i=Ce;n&&(o=[r],i=Z);let{revoke:l,proxy:a}=Proxy.revocable(o,i);return r.draft_=a,r.revoke_=l,a}var Ce={get(e,t){if(t===R)return e;let n=M(e);if(!ve(n,t))return pn(e,n,t);let r=n[t];return e.finalized_||!j(r)?r:r===Ie(e.base_,t)?(we(e),e.copy_[t]=$e(r,e)):r},has(e,t){return t in M(e)},ownKeys(e){return Reflect.ownKeys(M(e))},set(e,t,n){let r=st(M(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let o=Ie(M(e),t),i=o?.[R];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(ln(n,o)&&(n!==void 0||ve(e.base_,t)))return!0;we(e),Ee(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return Ie(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,we(e),Ee(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=M(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty(){P(11)},getPrototypeOf(e){return z(e.base_)},setPrototypeOf(){P(12)}},Z={};se(Ce,(e,t)=>{Z[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});Z.deleteProperty=function(e,t){return Z.set.call(this,e,t,void 0)};Z.set=function(e,t,n){return Ce.set.call(this,e[0],t,n,e[0])};function Ie(e,t){let n=e[R];return(n?M(n):e)[t]}function pn(e,t,n){let r=st(t,n);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}function st(e,t){if(!(t in e))return;let n=z(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=z(n)}}function Ee(e){e.modified_||(e.modified_=!0,e.parent_&&Ee(e.parent_))}function we(e){e.copy_||(e.copy_=xe(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var hn=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){let i=n;n=t;let l=this;return function(c=i,...s){return l.produce(c,f=>n.call(this,f,...s))}}typeof n!="function"&&P(6),r!==void 0&&typeof r!="function"&&P(7);let o;if(j(t)){let i=Ze(this),l=$e(t,void 0),a=!0;try{o=n(l),a=!1}finally{a?Ae(i):_e(i)}return Qe(i,r),et(o,i)}else if(!t||typeof t!="object"){if(o=n(t),o===void 0&&(o=t),o===nt&&(o=void 0),this.autoFreeze_&&Le(o,!0),r){let i=[],l=[];B("Patches").generateReplacementPatches_(t,o,i,l),r(i,l)}return o}else P(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(l,...a)=>this.produceWithPatches(l,c=>t(c,...a));let r,o;return[this.produce(t,n,(l,a)=>{r=l,o=a}),r,o]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){j(e)||P(8),Y(e)&&(e=gn(e));let t=Ze(this),n=$e(e,void 0);return n[R].isManual_=!0,_e(t),n}finishDraft(e,t){let n=e&&e[R];(!n||!n.isManual_)&&P(9);let{scope_:r}=n;return Qe(r,t),et(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let o=t[n];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}n>-1&&(t=t.slice(n+1));let r=B("Patches").applyPatches_;return Y(e)?r(e,t):this.produce(e,o=>r(o,t))}};function $e(e,t){let n=ue(e)?B("MapSet").proxyMap_(e,t):fe(e)?B("MapSet").proxySet_(e,t):dn(e,t);return(t?t.scope_:it()).drafts_.push(n),n}function gn(e){return Y(e)||P(10,e),lt(e)}function lt(e){if(!j(e)||de(e))return e;let t=e[R],n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=xe(e,t.scope_.immer_.useStrictShallowCopy_)}else n=xe(e,!0);return se(n,(r,o)=>{ot(n,r,lt(o))}),t&&(t.finalized_=!1),n}var T=new hn,Se=T.produce,Oo=T.produceWithPatches.bind(T),Ro=T.setAutoFreeze.bind(T),To=T.setUseStrictShallowCopy.bind(T),No=T.applyPatches.bind(T),Po=T.createDraft.bind(T),Vo=T.finishDraft.bind(T);var p={LITERAL:0,VARIABLE:1,INTERPOLATION:2,FUNCTION:3,BINARY:4,UNARY:5,CONDITIONAL:6,LOOP:7,OBJECT:8,ARRAY:9,PARTIAL:10,PATH_REFERENCE:11},A={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},ee={NOT:0};var w=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},k=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var ke=e=>{if(!e||e.trim()==="")throw new w("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let n=e.includes("===")?"==":"!=";throw new w(`Invalid comparison operator '${e.includes("===")?"===":"!=="}' - did you mean '${n}'? (got: '${e}')`)}let t=["<",">","<=",">=","==","!="];for(let n of t)if(e.trim().endsWith(n))throw new w(`Incomplete comparison expression - missing right operand (got: '${e}')`)},ct=e=>{if(e.trim().endsWith(" in"))throw new w(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new w(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,n]=e.split(" in ");if(!n||n.trim()==="")throw new w(`Missing iterable expression after 'in' (got: '$for ${e}')`);let r=t.includes(",")?t.split(",").map(o=>o.trim()):[t.trim()];for(let o of r){if(!o)throw new w(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(o))throw new w(`Invalid loop syntax (got: '$for ${e}')`)}};var at=(e,t,n=!1)=>{if(t===null)return new k(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new k(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof t;return n?new k(`Cannot iterate over non-array value in loop '${e}' - got ${r} instead`):new k(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},ut=(e,t)=>{let n=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new k(`Unknown function '${e}' (${n})`)};var yn=(e,t,n={})=>{let r={},o={};n&&typeof n=="object"&&(n.functions!==void 0||n.partials!==void 0?(r=n.functions||{},o=n.partials||{}):typeof n=="object"&&(r=n));let l=x(e,{functions:r,partials:o},t,{});return l===void 0?{}:l},x=(e,t,n,r)=>{let o=t.functions||t;if(e.var&&!e.type)return $(e.var,n,r);if(e.type===p.LITERAL)return e.value;if(e.type===p.VARIABLE)return $(e.path,n,r);if(e.type===p.INTERPOLATION)return bn(e.parts,t,n,r);switch(e.type){case p.FUNCTION:return dt(e,t,n,r);case p.BINARY:return pt(e,t,n,r);case p.UNARY:return ht(e,t,n,r);case p.CONDITIONAL:return wn(e,t,n,r);case p.LOOP:return En(e,t,n,r);case p.OBJECT:return Ln(e,t,n,r);case p.ARRAY:return Cn(e,t,n,r);case p.PARTIAL:return Sn(e,t,n,r);case p.PATH_REFERENCE:return kn(e,t,n,r);default:throw new Error(`Unknown node type: ${e.type}`)}},ft=new Map,mn=e=>{let t=[],n="",r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(i==="[")n&&(t.push({type:"property",value:n}),n=""),r=!0;else if(i==="]"){if(r&&n){let l=n.trim();if(/^\d+$/.test(l))t.push({type:"index",value:parseInt(l,10)});else if(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'")){let a=l.slice(1,-1);t.push({type:"property",value:a})}else t.push({type:"property",value:l});n=""}r=!1}else n+=i}return n&&t.push({type:"property",value:n}),t},$=(e,t,n)=>{if(!e)return;if(e in n)return n[e];let r=ft.get(e);if(!r){let i=[],l="",a=0;for(let c=0;c<e.length;c++){let s=e[c];s==="["?(a++,l+=s):s==="]"?(a--,l+=s):s==="."&&a===0?l&&(i.push(l),l=""):l+=s}l&&i.push(l),r=[];for(let c of i){let s=mn(c.trim());r.push(...s)}ft.set(e,r)}let o=t;for(let i=0;i<r.length;i++){let l=r[i];if(l.type==="property"&&l.value in n){o=n[l.value];continue}if(o==null)return;(l.type==="property"||l.type==="index")&&(o=o[l.value])}return o},bn=(e,t,n,r)=>{let o=[];for(let i of e)if(typeof i=="string")o.push(i);else{let l=x(i,t,n,r);o.push(l!=null?String(l):"")}return o.join("")},dt=(e,t,n,r)=>{let o=t.functions||t,i=o[e.name];if(!i)throw ut(e.name,o);let l=e.args.map(a=>x(a,t,n,r));return i(...l)},H=(e,t,n,r)=>{if(e.var&&!e.type)return $(e.var,n,r);switch(e.type){case p.VARIABLE:return $(e.path,n,r);case p.LITERAL:return e.value;case p.BINARY:return pt(e,t,n,r);case p.UNARY:return ht(e,t,n,r);case p.FUNCTION:return dt(e,t,n,r);default:return x(e,t,n,r)}},pt=(e,t,n,r)=>{if(e.op===A.AND||e.op===A.OR){let l=H(e.left,t,n,r),a=H(e.right,t,n,r);switch(e.op){case A.AND:return l&&a;case A.OR:return l||a}}let o=x(e.left,t,n,r),i=x(e.right,t,n,r);switch(e.op){case A.EQ:return o==i;case A.NEQ:return o!=i;case A.GT:return o>i;case A.LT:return o<i;case A.GTE:return o>=i;case A.LTE:return o<=i;case A.IN:return Array.isArray(i)?i.includes(o):!1;case A.ADD:if(typeof o!="number"||typeof i!="number")throw new k(`Arithmetic operations require numbers. Got ${typeof o} + ${typeof i}`);return o+i;case A.SUBTRACT:if(typeof o!="number"||typeof i!="number")throw new k(`Arithmetic operations require numbers. Got ${typeof o} - ${typeof i}`);return o-i;default:throw new Error(`Unknown binary operator: ${e.op}`)}},ht=(e,t,n,r)=>{let o=e.op===ee.NOT?H(e.operand,t,n,r):x(e.operand,t,n,r);if(e.op===ee.NOT)return!o;throw new Error(`Unknown unary operator: ${e.op}`)},In=(e,t,n,r)=>{if(e.conditions.length===2&&e.conditions[1]===null){let o=e.conditions[0];if(o.type===p.VARIABLE)if($(o.path,n,r)){let l=e.bodies[0];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?x(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=$(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=$(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=x(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=x(f,t,n,r)}return a}}else{let l=e.bodies[1];if(l.type===p.OBJECT&&l.properties.length<=5){let a={};for(let c of l.properties){let s=c.parsedKey?x(c.parsedKey,t,n,r):c.key,f=c.value;if(f.type===p.LITERAL)a[s]=f.value;else if(f.type===p.VARIABLE)a[s]=$(f.path,n,r);else if(f.type===p.INTERPOLATION){let u=[];for(let d of f.parts)if(typeof d=="string")u.push(d);else if(d.type===p.VARIABLE){let h=$(d.path,n,r);u.push(h!=null?String(h):"")}else{let h=x(d,t,n,r);u.push(h!=null?String(h):"")}a[s]=u.join("")}else a[s]=x(f,t,n,r)}return a}}}return null},wn=(e,t,n,r)=>{let o=In(e,t,n,r);if(o!==null)return o;for(let i=0;i<e.conditions.length;i++){let l=e.conditions[i];if(l===null||H(l,t,n,r))return x(e.bodies[i],t,n,r)}return gt},vn=(e,t)=>{let n=e.body,r=e.itemVar;if(n.type===p.CONDITIONAL&&n.conditions.length===1&&n.conditions[0].type===p.VARIABLE){let o=n.conditions[0].path,i=n.bodies[0];if(o.startsWith(r+".")){let l=o.substring(r.length+1);if(i.type===p.OBJECT&&i.properties.length<=5){for(let c of i.properties)if(c.parsedKey)return null;let a=[];for(let c=0;c<t.length;c++){let s=t[c];if(s[l]){let f={};for(let u of i.properties){let d=u.key,h=u.value;if(h.type===p.LITERAL)f[d]=h.value;else if(h.type===p.VARIABLE){let g=h.path;if(g===r)f[d]=s;else if(g.startsWith(r+".")){let m=g.substring(r.length+1);f[d]=s[m]}else return null}else if(h.type===p.INTERPOLATION){let g=[],m=!0;for(let I of h.parts)if(typeof I=="string")g.push(I);else if(I.type===p.VARIABLE){let y=I.path;if(y===r)g.push(s!=null?String(s):"");else if(y.startsWith(r+".")){let b=y.substring(r.length+1),v=s[b];g.push(v!=null?String(v):"")}else{m=!1;break}}else{m=!1;break}if(!m)return null;f[d]=g.join("")}else return null}a.push(f)}}return a}}}return null},xn=(e,t)=>{let n=e.body,r=e.itemVar,o=vn(e,t);if(o!==null)return o;if(n.type===p.OBJECT&&n.properties.length<=5&&!n.whenCondition){for(let a of n.properties)if(a.parsedKey)return null;let i=[],l=!0;for(let a of n.properties){let c=a.key,s=a.value;if(s.type===p.LITERAL)i.push({key:c,type:"literal",value:s.value});else if(s.type===p.VARIABLE){let f=s.path;if(f===r)i.push({key:c,type:"item"});else if(f.startsWith(r+".")){let u=f.substring(r.length+1);if(!u.includes(".")&&!u.includes("["))i.push({key:c,type:"prop",prop:u});else{l=!1;break}}else{l=!1;break}}else if(s.type===p.INTERPOLATION&&s.parts.length===1){let f=s.parts[0];if(f.type===p.VARIABLE){let u=f.path;if(u===r)i.push({key:c,type:"item_string"});else if(u.startsWith(r+".")){let d=u.substring(r.length+1);if(!d.includes(".")&&!d.includes("["))i.push({key:c,type:"prop_string",prop:d});else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}else{l=!1;break}}if(l){let a=new Array(t.length);if(i.length===3&&i[0].type==="prop"&&i[0].key==="id"&&i[1].type==="prop_string"&&i[1].key==="title"&&i[2].type==="prop"&&i[2].key==="completed")for(let c=0;c<t.length;c++){let s=t[c];a[c]={id:s.id,title:s.title!=null?String(s.title):"",completed:s.completed}}else for(let c=0;c<t.length;c++){let s=t[c],f={};for(let u of i)if(u.type==="literal")f[u.key]=u.value;else if(u.type==="item")f[u.key]=s;else if(u.type==="prop")f[u.key]=s[u.prop];else if(u.type==="item_string")f[u.key]=s!=null?String(s):"";else if(u.type==="prop_string"){let d=s[u.prop];f[u.key]=d!=null?String(d):""}a[c]=f}return a}}return null},An=(e,t,n,r,o)=>{let i=[],l=e.body;if(l.type===p.OBJECT&&l.fast!==!1){let a=e.itemVar,c=e.indexVar;for(let s=0;s<o.length;s++){let f=o[s],u={},d={...r,[a]:f,...c&&{[c]:s}};d.__paths__||(d.__paths__=r.__paths__||{});let h=e.iterable.path||"";if(r&&r.__paths__&&h){let g=h.split("."),m=g[0];m in r.__paths__&&(h=r.__paths__[m],g.length>1&&(h+="."+g.slice(1).join(".")))}d.__paths__={...d.__paths__,[a]:`${h}[${s}]`,...c&&{[c]:s}};for(let g of l.properties){let m=g.parsedKey?x(g.parsedKey,t,n,d):g.key,I=g.value;if(I.type===p.LITERAL)u[m]=I.value;else if(I.type===p.VARIABLE){let y=I.path;if(y===a)u[m]=f;else if(y===c)u[m]=s;else if(y.startsWith(a+".")){let b=y.substring(a.length+1);!b.includes(".")&&!b.includes("[")?u[m]=f[b]:u[m]=$(y,n,{...r,[a]:f,...c&&{[c]:s}})}else u[m]=$(y,n,{...r,[a]:f,...c&&{[c]:s}})}else if(I.type===p.INTERPOLATION){let y=[];for(let b of I.parts)if(typeof b=="string")y.push(b);else if(b.type===p.VARIABLE){let v=b.path,_;if(v===a)_=f;else if(v===c)_=s;else if(v.startsWith(a+".")){let E=v.substring(a.length+1);!E.includes(".")&&!E.includes("[")?_=f[E]:_=$(v,n,{...r,[a]:f,...c&&{[c]:s}})}else _=$(v,n,{...r,[a]:f,...c&&{[c]:s}});y.push(_!=null?String(_):"")}else{let v={...r,[a]:f,...c&&{[c]:s}},_=x(b,t,n,v);y.push(_!=null?String(_):"")}u[m]=y.join("")}else{let y={...r,[a]:f,...c&&{[c]:s}};u[m]=x(I,t,n,y)}}i.push(u)}return i}return null},_n=(e,t,n)=>{let r=e.body;if(r.type===p.OBJECT&&r.properties.length===1&&r.properties[0].key==="$if item.visible"){let i=r.properties[0].value;if(i.type===p.CONDITIONAL&&i.conditions.length===1&&i.conditions[0].type===p.VARIABLE&&i.conditions[0].path==="item.visible"){let l=i.bodies[0];if(l.type===p.OBJECT&&l.properties.length===2){let a=l.properties[0],c=l.properties[1];if(a.key==="id"&&a.value.type===p.VARIABLE&&a.value.path==="item.id"&&c.key==="$if item.highlighted"&&c.value.type===p.CONDITIONAL){let s=[];for(let f=0;f<t.length;f++){let u=t[f];if(u.visible){let d={id:u.id};u.highlighted?(d.highlight=!0,d.message=`This item is highlighted: ${u.name}`):(d.highlight=!1,d.message=u.name),s.push(d)}}return s}}}}return null},En=(e,t,n,r)=>{let o=x(e.iterable,t,n,r);if(!Array.isArray(o)){let s,f=!1;if(e.iterable.type===p.FUNCTION){f=!0;let d=e.iterable.args.map(h=>h.type===p.LITERAL?typeof h.value=="string"?`'${h.value}'`:String(h.value):h.type===p.VARIABLE?h.path:h.type===p.FUNCTION?`${h.name}(...)`:"?").join(", ");s=`${e.iterable.name}(${d})`}else s=e.iterable.path||"undefined";let u=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${s}`;throw at(u,o,f)}if(!e.indexVar){let s=_n(e,o,e.itemVar);if(s!==null)return s}if(!e.indexVar){let s=xn(e,o);if(s!==null)return s}let i=An(e,t,n,r,o);if(i!==null)return i;let l=[],a=e.iterable.path||"";if(r&&r.__paths__&&a){let s=a.split("."),f=s[0];f in r.__paths__&&(a=r.__paths__[f],s.length>1&&(a+="."+s.slice(1).join(".")))}let c=!1;e.body.type===p.ARRAY&&(e.body.items.length<=1?c=!1:c=e.body._shouldPreserveArray??=e.body.items.some(s=>s.type===p.OBJECT&&s.properties.some(f=>f.key.startsWith("$if ")||f.key.startsWith("$when "))));for(let s=0;s<o.length;s++){let f=e.indexVar?{...r,[e.itemVar]:o[s],[e.indexVar]:s}:{...r,[e.itemVar]:o[s]};f.__paths__||(f.__paths__=r.__paths__||{}),f.__paths__={...f.__paths__,[e.itemVar]:`${a}[${s}]`},e.indexVar&&(f.__paths__[e.indexVar]=s);let u=x(e.body,t,n,f);if(Array.isArray(u)&&u.length===1&&!c){let d=u[0];l.push(d===void 0?{}:d)}else l.push(u===void 0?{}:u)}return l},$n=(e,t,n,r)=>{if(e.whenCondition)return null;if(e.properties.length===1){let o=e.properties[0],i=o.parsedKey?x(o.parsedKey,t,n,r):o.key,l=o.value;if(l.type===p.OBJECT&&l.properties.length<=10&&!l.whenCondition){let a={},c={},s=!0;for(let f of l.properties){let u=f.parsedKey?x(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)c[u]=d.value;else if(d.type===p.VARIABLE)c[u]=$(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let m=$(g.path,n,r);h.push(m!=null?String(m):"")}else{s=!1;break}if(!s)break;c[u]=h.join("")}else if(d.type===p.OBJECT&&d.properties.length<=5){let h={};for(let g of d.properties){let m=g.key,I=g.value;if(I.type===p.LITERAL)h[m]=I.value;else if(I.type===p.VARIABLE)h[m]=$(I.path,n,r);else if(I.type===p.INTERPOLATION){let y=[];for(let b of I.parts)if(typeof b=="string")y.push(b);else if(b.type===p.VARIABLE){let v=$(b.path,n,r);y.push(v!=null?String(v):"")}else{s=!1;break}if(!s)break;h[m]=y.join("")}else{s=!1;break}}if(!s)break;c[u]=h}else{s=!1;break}}if(s)return a[i]=c,a}}return null},Ln=(e,t,n,r)=>{let o=t.functions||t;if(e.whenCondition&&!H(e.whenCondition,o,n,r))return;let i=$n(e,t,n,r);if(i!==null)return i;if(e.fast){let s={};for(let f of e.properties){let u=f.parsedKey?x(f.parsedKey,t,n,r):f.key,d=f.value;if(d.type===p.LITERAL)s[u]=d.value;else if(d.type===p.VARIABLE)s[u]=$(d.path,n,r);else if(d.type===p.INTERPOLATION){let h=[];for(let g of d.parts)if(typeof g=="string")h.push(g);else if(g.type===p.VARIABLE){let m=$(g.path,n,r);h.push(m!=null?String(m):"")}else{let m=x(g,t,n,r);h.push(m!=null?String(m):"")}s[u]=h.join("")}else s[u]=x(d,t,n,r)}return s}let l={},a=null,c=!1;for(let s of e.properties)if(!s.key.startsWith("$if ")&&!s.key.match(/^\$if\s+\w+.*:?$/)&&!s.key.startsWith("$elif")&&!s.key.startsWith("$else")&&!s.key.startsWith("$for ")){c=!0;break}for(let s of e.properties)if(s.key.startsWith("$if ")||s.key.match(/^\$if\s+\w+.*:?$/)){let f=x(s.value,t,n,r);if(!c&&f!==null&&f!==void 0)return Array.isArray(f)&&f.length===1?f[0]:f;typeof f=="object"&&f!==null&&!Array.isArray(f)&&Object.assign(l,f)}else if(s.key.startsWith("$for ")){if(e.properties.length===1)return x(s.value,t,n,r)}else{let f=s.value;if(f&&f.type===p.OBJECT&&f.properties){let u=f.properties.find(d=>d.key.startsWith("$for "));if(u){let d=x(u.value,t,n,r);d!==void 0&&(l[s.key]=d)}else{let d=x(s.value,t,n,r);d!==void 0&&(l[s.key]=d)}}else{let u=s.parsedKey?x(s.parsedKey,t,n,r):s.key,d=x(s.value,t,n,r);d!==void 0&&(l[u]=d)}}return l},gt={},Cn=(e,t,n,r)=>{let o=[];for(let i of e.items)if(i.type===p.LOOP){let l=x(i,t,n,r);Array.isArray(l)&&i.flatten!==!1?o.push(...l):o.push(l)}else{let l=x(i,t,n,r);l!==gt&&l!==void 0&&o.push(l)}return o},Sn=(e,t,n,r)=>{let{name:o,data:i,whenCondition:l}=e,a=t.partials||{},c=t.functions||t;if(l&&!H(l,c,n,r))return;if(!a[o])throw new k(`Partial '${o}' is not defined`);let s=r._partialStack||[];if(s.includes(o))throw new k(`Circular partial reference detected: ${o}`);let f=a[o],u=n,d={...r,_partialStack:[...s,o]};if(r){u={...n};for(let h of Object.keys(r))h.startsWith("_")||(u[h]=r[h])}if(i){let h=x(i,t,n,r);u={...u,...h}}return x(f,t,u,d)},kn=(e,t,n,r)=>{let{path:o}=e,i=o.split("."),l=i[0],a=i.slice(1);if(!r||!(l in r))throw new k(`Path reference '#{${o}}' refers to '${l}' which is not a loop variable in the current scope`);if(r.__paths__||(r.__paths__={}),!(l in r.__paths__))throw new k(`Path reference '#{${o}}' cannot be resolved - path tracking may not be initialized properly`);let c=r.__paths__[l];if(typeof c=="number"){if(a.length>0)throw new k(`Path reference '#{${o}}' - cannot access properties on index variable '${l}'`);return String(c)}return a.length>0&&(c+="."+a.join(".")),c},Oe=yn;var On=/\$\{([^}]*)\}/g,Rn=/#\{([^}]*)\}/g,mt=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,r,o]=n,i=Tn(o,t);return{isFunction:!0,type:p.FUNCTION,name:r,args:i}},Tn=(e,t={})=>e.trim()?Nn(e).map(r=>Pn(r.trim(),t)):[],Nn=e=>{let t=[],n="",r=0,o=!1,i="";for(let l=0;l<e.length;l++){let a=e[l],c=l>0?e[l-1]:"";!o&&(a==='"'||a==="'")?(o=!0,i=a,n+=a):o&&a===i&&c!=="\\"?(o=!1,i="",n+=a):!o&&a==="("?(r++,n+=a):!o&&a===")"?(r--,n+=a):!o&&a===","&&r===0?(t.push(n),n=""):n+=a}return n&&t.push(n),t},Pn=(e,t={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:p.LITERAL,value:parseFloat(e)};if(e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};let n=mt(e,t);if(n.isFunction)return{type:n.type,name:n.name,args:n.args};let r=e.trim(),o=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],i=-1,l=null;for(let{op:a,type:c}of o){let s=0;for(;s<r.length;){let f=F(r.substring(s),a);if(f===-1)break;let u=s+f;u>i&&(i=u,l={op:a,type:c}),s=u+a.length}}if(i!==-1)try{return S(r,t)}catch{return{type:p.VARIABLE,path:r}}return{type:p.VARIABLE,path:r}},bt=/^\w+\(.*\)$/,Vn=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,Dn=e=>{if(!(!e||e.trim()===""||bt.test(e))&&Vn.test(e))throw e.includes("?")&&e.includes(":")?new w(`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 w(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new w(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},yt=e=>{let t=e.trim();if(bt.test(t))throw new w(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("["))throw new w(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(t))throw new w(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(t))throw new w(`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 w(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:p.PATH_REFERENCE,path:t}},te=(e,t={})=>{let n=e.trim();Dn(n);let r=mt(n,t);if(r.isFunction)return{type:r.type,name:r.name,args:r.args};if(n.includes("[")&&!/[\s+\-*/%|&?:]/.test(n)){let o=0;for(let i of n)i==="["?o++:i==="]"&&o--;if(o!==0)throw new Error("Invalid array index syntax")}return{type:p.VARIABLE,path:n}},Re=(e,t={})=>{let n=e,r=[];(e.includes("\\${")||e.includes("\\#{"))&&(n=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC_VAR$1"),n=n.replace(/\\\\(#\{[^}]*\})/g,"\\DOUBLE_ESC_PATH$1"),n=n.replace(/\\(\$\{[^}]*\})/g,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\(#\{[^}]*\})/g,(s,f)=>{let u=`__ESCAPED_${r.length}__`;return r.push(f),u}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let o=[...n.matchAll(On)],i=[...n.matchAll(Rn)],l=[...o.map(s=>({match:s,type:"variable"})),...i.map(s=>({match:s,type:"pathref"}))].sort((s,f)=>s.match.index-f.match.index);if(l.length===0){let s=n;for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);return{type:p.LITERAL,value:s}}if(l.length===1&&l[0].match[0]===n&&r.length===0){let{match:s,type:f}=l[0];try{return f==="variable"?te(s[1],t):yt(s[1])}catch(u){if(u.message==="Invalid array index syntax")return{type:p.LITERAL,value:n};throw u}}let a=[],c=0;for(let{match:s,type:f}of l){let[u,d]=s,h=s.index;if(h>c){let g=n.substring(c,h);for(let m=0;m<r.length;m++)g=g.replace(`__ESCAPED_${m}__`,r[m]);g&&a.push(g)}try{let g;f==="variable"?g=te(d.trim(),t):g=yt(d.trim()),a.push(g)}catch(g){if(g.message==="Invalid array index syntax")a.push(u);else throw g}c=h+u.length}if(c<n.length){let s=n.substring(c);for(let f=0;f<r.length;f++)s=s.replace(`__ESCAPED_${f}__`,r[f]);s&&a.push(s)}return{type:p.INTERPOLATION,parts:a}};var D=(e,t)=>typeof e=="string"?Re(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?jn(e,t):Bn(e,t):{type:p.LITERAL,value:e},Mn=e=>{let{$each:t,...n}=e;if(typeof t!="string")throw new w("$each value must be a non-empty string");let r=t.trim();if(r==="")throw new w("$each value must be a non-empty string");if(Object.keys(n).length===0)throw new w("Empty $each body not allowed");if(n.$partial!==void 0)throw new w("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${r}`]:n}},jn=(e,t)=>{let n=[],r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(typeof i=="object"&&i!==null&&!Array.isArray(i)){if(i.$each!==void 0)try{let c=Mn(i),s=Object.keys(c);if(s.length===1&&/^\$for(?::\w+)?\s/.test(s[0])){let f=It(s[0],c[s[0]],t,!0);n.push(f),r=!0;continue}}catch(c){throw c instanceof w?c:new w(c.message)}let a=Object.keys(i);if(a.length===1&&/^\$for(?::\w+)?\s/.test(a[0])){let c=It(a[0],i[a[0]],t);n.push(c),r=!0;continue}}let l=D(i,t);n.push(l),(l.type===p.FUNCTION||l.type===p.CONDITIONAL||l.type===p.LOOP||l.type===p.PARTIAL||l.type===p.OBJECT&&!l.fast||l.type===p.ARRAY&&!l.fast)&&(r=!0)}return{type:p.ARRAY,items:n,fast:!r}},Bn=(e,t)=>{let n=[],r=!1,o=null,i=Object.entries(e),l=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new w("$partial value must be a string");if(e.$partial.trim()==="")throw new w("$partial value cannot be an empty string");let c=["$if","$elif","$else","$for"],s=[];for(let[y]of i)for(let b of c)if(y===b||y.startsWith(b+" ")||y.startsWith(b+"#")){s.push(b);break}if(s.length>0)throw new w(`Cannot use $partial with ${s.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:f,$when:u,...d}=e,h={},g=!1;for(let[y,b]of Object.entries(d)){let v=y;(y.startsWith("\\$")||y.startsWith("$$"))&&(v=y.slice(1)),h[v]=b,g=!0}let m=null;if(g&&(m=D(h,t),m.type===p.OBJECT)){let y=!1;for(let b of m.properties)if(b.value.type===p.VARIABLE||b.value.type===p.INTERPOLATION||b.value.type===p.FUNCTION||b.value.type===p.CONDITIONAL||b.value.type===p.OBJECT&&!b.value.fast||b.value.type===p.ARRAY&&!b.value.fast){y=!0;break}y&&(m.fast=!1)}let I={type:p.PARTIAL,name:f,data:m};if(u!==void 0){let y;if(typeof u=="string"){if(u.trim()==="")throw new w("Empty condition expression after '$when'");y=S(u,t)}else y={type:p.LITERAL,value:u};I.whenCondition=y}return I}for(let[c,s]of i)if(c==="$when"){if(o!==null)throw new w("Multiple '$when' directives on the same object are not allowed");if(s==null)throw new w("Missing condition expression after '$when'");let f=typeof s=="string"?s:JSON.stringify(s);if(f.trim()==="")throw new w("Empty condition expression after '$when'");o=S(f,t),r=!0}else if(c.startsWith("$when#")||c.startsWith("$when "))throw new w("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;l<i.length;){let[c,s]=i[l];if(c==="$when"){l++;continue}if(c==="$each")throw new w("$each can only be used inside arrays");if(c.startsWith("$if ")||c.match(/^\$if#\w+\s/)||c.match(/^\$if\s+\w+.*:$/)){let f=Fn(i,l,t);n.push({key:c,value:f.node}),r=!0,l=f.nextIndex}else if(/^\$for(?::\w+)?\s/.test(c)){let f=c.match(/^\$for(?::(\w+))?\s/)?.[1]||"",u=f?`:${f}`:"";throw new w(`$for loops must be inside arrays - use '- $for${u} item in items:' instead of '$for${u} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(c.startsWith("$elif ")||c.startsWith("$else"))throw new w(`'${c.split(" ")[0]}' without matching '$if'`);if(c==="$if"||c==="$if:")throw new w("Missing condition expression after '$if'");{let f=D(s,t);(f.type===p.FUNCTION||f.type===p.CONDITIONAL||f.type===p.PARTIAL||f.type===p.OBJECT&&!f.fast||f.type===p.ARRAY&&!f.fast)&&(r=!0);let u=Re(c,t),d={key:c,value:f};(u.type!==p.LITERAL||u.value!==c)&&(d.parsedKey=u),n.push(d),l++}}}let a={type:p.OBJECT,properties:n,fast:!r};return o&&(a.whenCondition=o),a},Fn=(e,t,n={})=>{let r=[],o=[],i=t,[l,a]=e[i],c=null,s;if(l.startsWith("$if#")){let u=l.match(/^\$if#(\w+)\s+(.+)$/);if(u)c=u[1],s=u[2];else throw new w(`Invalid conditional syntax: ${l}`)}else s=l.substring(4),s.endsWith(":")&&(s=s.slice(0,-1).trim());ke(s);let f=S(s,n);for(r.push(f),o.push(D(a,n)),i++;i<e.length;){let[u,d]=e[i],h=!1,g;if(c?u.startsWith(`$elif#${c} `)?(g=u.substring(`$elif#${c} `.length),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u===`$else#${c}`||u===`$else#${c}:`)&&(h=!0,g=null):u.startsWith("$elif ")?(g=u.substring(6),g.endsWith(":")&&(g=g.slice(0,-1).trim()),h=!0):(u==="$else"||u==="$else:")&&(h=!0,g=null),h){if(g===null)r.push(null);else{ke(g);let m=S(g,n);r.push(m)}if(o.push(D(d,n)),i++,g===null)break}else break}return{node:{type:p.CONDITIONAL,conditions:r,bodies:o,id:c},nextIndex:i}},S=(e,t={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let s=e.slice(1,-1),f=0,u=!0;for(let d=0;d<s.length;d++)if(s[d]==="("?f++:s[d]===")"&&f--,f<0){u=!1;break}if(u&&f===0)return S(s,t)}let n=F(e,"||");if(n!==-1)return{type:p.BINARY,op:A.OR,left:S(e.substring(0,n).trim(),t),right:S(e.substring(n+2).trim(),t)};let r=F(e,"&&");if(r!==-1)return{type:p.BINARY,op:A.AND,left:S(e.substring(0,r).trim(),t),right:S(e.substring(r+2).trim(),t)};let o=[{op:">=",type:A.GTE},{op:"<=",type:A.LTE},{op:"==",type:A.EQ},{op:"!=",type:A.NEQ},{op:">",type:A.GT},{op:"<",type:A.LT},{op:" in ",type:A.IN}];for(let{op:s,type:f}of o){let u=F(e,s);if(u!==-1)return{type:p.BINARY,op:f,left:S(e.substring(0,u).trim(),t),right:S(e.substring(u+s.length).trim(),t)}}let i=-1,l=null,a=[{op:" + ",type:A.ADD},{op:" - ",type:A.SUBTRACT}];for(let{op:s,type:f}of a){let u=0;for(;u<e.length;){let d=F(e.substring(u),s);if(d===-1)break;let h=u+d;h>i&&(i=h,l={op:s,type:f}),u=h+s.length}}if(i!==-1&&l)return{type:p.BINARY,op:l.type,left:S(e.substring(0,i).trim(),t),right:S(e.substring(i+l.op.length).trim(),t)};let c=[" * "," / "," % "];for(let s of c)if(F(e,s)!==-1)throw new w(`Arithmetic operations are not allowed in conditionals: "${s}"`);return e.startsWith("!")?{type:p.UNARY,op:ee.NOT,operand:S(e.substring(1).trim(),t)}:wt(e,t)},F=(e,t)=>{let n=0,r=0;for(;r<=e.length-t.length;){if(e[r]==="(")n++;else if(e[r]===")")n--;else if(n===0&&e.substring(r,r+t.length)===t)return r;r++}return-1},Un=e=>{if(e=e.trim(),e==="true")return{type:p.LITERAL,value:!0};if(e==="false")return{type:p.LITERAL,value:!1};if(e==="null")return{type:p.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:p.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:p.LITERAL,value:""};if(e==="{}")return{type:p.LITERAL,value:{}};if(e==="[]")return{type:p.LITERAL,value:[]};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:p.LITERAL,value:t}:{type:p.VARIABLE,path:e}},wt=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return te(n,t);let o=Un(n);if(o.type===p.LITERAL)return o;if(/^[a-zA-Z_$][\w.$]*$/.test(n))return{type:p.VARIABLE,path:n};try{return te(n,t)}catch(i){if(i.message&&i.message.includes("not supported"))return o;throw i}},Wn=(e,t=!1)=>{let n=t?"$each":"$for";try{ct(e)}catch(r){if(r instanceof w&&t){let o=r.message.replace(/\$for/g,"$each");throw new w(o.replace("Parse Error: ",""))}throw r}},It=(e,t,n,r=!1)=>{let o=/^\$for(?::(\w+))?\s+(.+)$/,i=e.match(o);if(!i){let I=r?"$each":"$for";throw new w(`Invalid loop syntax (got: '${e.replace("$for",I)}')`)}let l=i[1],a=i[2].trim();Wn(a,r);let c=a.match(/^(.+?)\s+in\s+(.+)$/);if(!c){let I=r?"$each":"$for";throw new w(`Invalid loop syntax - missing 'in' keyword (got: '${I} ${a}')`)}let s=c[1].trim(),f=c[2].trim(),u,d=null;if(s.includes(",")){let I=s.split(",").map(y=>y.trim());if(I.length!==2)throw new w(`Invalid loop variables: ${s}. Expected format: "item" or "item, index"`);u=I[0],d=I[1]}else u=s;let h=["this","undefined","null","true","false"];if(h.includes(u))throw new w(`Reserved variable name: ${u}`);if(d&&h.includes(d))throw new w(`Reserved variable name: ${d}`);let g=wt(f,n),m=D(t,n);return{type:p.LOOP,itemVar:u,indexVar:d,iterable:g,body:m,flatten:l!=="nested"}};var zn=(e,t={})=>{let{functions:n={}}=t;return D(e,n)},pe=zn;var Te={};on(Te,{now:()=>Yn});var Yn=()=>Date.now();var Hn=(e,t,n={})=>{let{functions:r={},partials:o={}}=n,i={...Te,...r},l=pe(e,{functions:i}),a={};for(let[c,s]of Object.entries(o))a[c]=pe(s,{functions:i});return Oe(l,t,{functions:i,partials:a})},N=Hn;var vt=(e,t,n={})=>{let r=structuredClone(e),o={},i={},{transformSelectorFirstArgument:l=c=>c,transformActionFirstArgument:a=c=>c}=n;for(let[c,s]of Object.entries(t))c!=="createInitialState"&&(c.startsWith("select")?o[c]=(...f)=>s(l(r),...f):i[c]=(...f)=>{r=Se(r,d=>s(a(d),...f))});return{...o,...i}},he=(e,t)=>n=>{let r=e(),o=Array.isArray(n)?n:[n];return Se(r,i=>{o.forEach(l=>{t.forEach(a=>{a(i,l)})})})};var qn=(e,t)=>{if(e.default!==void 0)return e.default;let n=["number","boolean","string","object"];if(!n.includes(e.type))throw new Error(`Invalid variable type: ${e.type} for variable ${t}. Expected one of: ${n.join(", ")}`);switch(e.type){case"number":return 0;case"boolean":return!1;case"string":return"";case"object":return{}}},xt=e=>{let t={},n={};return e.resources?.variables?(Object.entries(e.resources.variables).forEach(([r,o])=>{let i=qn(o,r);o.scope==="context"?t[r]=i:n[r]=i}),{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}):{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}},At=(e,t)=>{let n=["context","global-device","global-account"];if(!e)throw new Error(`Variable scope is required for variable: ${t}`);if(!n.includes(e))throw new Error(`Invalid variable scope: ${e} for variable ${t}. Expected one of: ${n.join(", ")}`)},_t=(e,t,n)=>{let r={number:["set","increment","decrement","multiply","divide"],boolean:["set","toggle"],string:["set"],object:["set"]},o=r[e];if(!o)throw new Error(`Unknown variable type: ${e} for variable ${n}`);if(!Object.values(r).flat().includes(t))throw new Error(`Unknown operation: ${t}`);if(!o.includes(t))throw new Error(`Operation "${t}" is not valid for variable "${n}" of type "${e}". Valid operations: ${o.join(", ")}`)},Pe=(e,t,n)=>{switch(t){case"set":return n;case"multiply":return(e??1)*n;case"divide":return(e??0)/n;case"increment":return(e??0)+(n??1);case"decrement":return(e??0)-(n??1);case"toggle":return!e;default:throw new Error(`Unknown operation: ${t}`)}},Ve=(e,t,n)=>Object.fromEntries(Object.entries(e).filter(([r])=>t?.[r]?.scope===n)),Et=(e,t="DD/MM/YYYY - HH:mm")=>{if(!e)return"";let n=new Date(e),r=o=>String(o).padStart(2,"0");return t.replace("DD",r(n.getDate())).replace("MM",r(n.getMonth()+1)).replace("YYYY",n.getFullYear()).replace("YY",String(n.getFullYear()).slice(-2)).replace("HH",r(n.getHours())).replace("mm",r(n.getMinutes())).replace("ss",r(n.getSeconds()))},Jn=(e,t)=>{let n=e?.ui,r=t?.ui;return JSON.stringify(n)===JSON.stringify(r)?null:n&&!r?{changeType:"delete",data:e}:r&&!e?{changeType:"add",data:t}:r&&e?{changeType:"update",data:t}:null},De=(e={},t={})=>{let n={},r=["sfx","voice"],o=l=>{let a=e[l],c=t[l];c&&!a?n[l]={changeType:"add",data:c}:a&&!c?r.includes(l)||(n[l]={changeType:"delete",data:a}):a&&c&&JSON.stringify(a)!==JSON.stringify(c)&&(n[l]={changeType:"update",data:c})};o("background"),o("base"),o("bgm"),o("voice");let i=Jn(e.dialogue,t.dialogue);return i&&(n.dialogue=i),o("choice"),o("layout"),o("animation"),o("keyboard"),o("character"),o("visual"),o("sfx"),n},Kn=(e,t)=>{if(!e||!t)return;let n=e;for(let r of t.split(".")){if(n==null||!(r in Object(n)))return;n=n[r]}return n},Xn=(e,t)=>{if(typeof e!="string")return e;if(e==="_event"){if(t==null)throw new Error('Action template binding "_event" requires event context "_event".');return t}if(!e.startsWith("_event."))return e;if(t==null)throw new Error(`Action template binding "${e}" requires event context "_event".`);let n=e.slice(7),r=Kn(t,n);if(r===void 0)throw new Error(`Action template binding "${e}" could not be resolved from "_event".`);return r},Ne=(e,t)=>Array.isArray(e)?e.map(n=>Ne(n,t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ne(r,t)])):Xn(e,t),$t=(e,t)=>{if(!t)return e;if(Object.prototype.hasOwnProperty.call(t,"event"))throw new Error('Action template context key "event" is no longer supported. Use "_event".');let n=Ne(e,t._event);return N(n,t)};var ge=(e,t)=>e?!t(e)&&e.animations?{animationsOnly:!0,state:{animations:structuredClone(e.animations)}}:{animationsOnly:!1,state:null}:{animationsOnly:!1,state:null},Lt=(e,t)=>{if(!e||e.length===0)return{hasValidItems:!1,processedItems:[]};let n=e.map(r=>structuredClone(r)).filter(r=>t(r)||r.animations);return{hasValidItems:n.length>0,processedItems:n}},Gn=()=>({}),Qn=(e,t)=>{t.base&&(e.base={...t.base})},Zn=(e,t)=>{if(t.background){let{animationsOnly:n,state:r}=ge(t.background,o=>!!o.resourceId);if(n){e.background=r;return}if(!t.background.resourceId){delete e.background;return}e.background=structuredClone(t.background)}else e.background?.animations&&(e.background.animations={})},er=(e,t)=>{if(!t.dialogue){e.dialogue&&e.dialogue.mode==="adv"&&(e.dialogue.content=void 0,e.dialogue.characterId=void 0);return}if(e.dialogue||(e.dialogue={}),t.dialogue.ui){let{animationsOnly:n,state:r}=ge(t.dialogue.ui,o=>!!o.resourceId);n?e.dialogue.ui={...e.dialogue.ui,...r}:e.dialogue.ui={...t.dialogue.ui}}else e.dialogue?.ui?.animations&&(e.dialogue.ui.animations={});if(t.dialogue.mode==="adv"&&(e.dialogue.content=e.dialogue.content||void 0,e.dialogue.characterId=e.dialogue.characterId||void 0,e.dialogue.mode="adv"),t.dialogue.mode==="nvl"&&(e.dialogue?.mode!=="nvl"&&(e.dialogue.lines=[]),e.dialogue.mode="nvl"),t.dialogue.content!==void 0&&(e.dialogue.content=t.dialogue.content),delete e.dialogue.characterId,t.dialogue.characterId&&(e.dialogue.characterId=t.dialogue.characterId),t.dialogue.character?e.dialogue.character={...t.dialogue.character}:delete e.dialogue.character,t.dialogue.clear){delete e.dialogue;return}t.dialogue?.clearPage&&e.dialogue?.mode==="nvl"&&(e.dialogue.lines=[]),e.dialogue?.mode==="nvl"&&t.dialogue.content!==void 0&&e.dialogue.lines.push({content:t.dialogue.content,characterId:t.dialogue.characterId||null})},tr=(e,t)=>{if(t.sfx){if(!t.sfx.items||t.sfx.items.length===0){delete e.sfx;return}e.sfx=t.sfx}else e.sfx&&delete e.sfx},nr=(e,t)=>{if(t.bgm){if(!t.bgm.resourceId){e.bgm=void 0;return}e.bgm={...t.bgm,loop:t.bgm.loop||t.bgm.loop===void 0}}},rr=(e,t)=>{if(t.visual){let{hasValidItems:n,processedItems:r}=Lt(t.visual.items,o=>!!o.resourceId);n?e.visual={items:r}:delete e.visual}else e.visual?.items&&(e.visual.items=e.visual.items.map(n=>n.animations?{...n,animations:{}}:n))},or=(e,t)=>{if(!t.character){e.character?.items&&(e.character.items=e.character.items.map(o=>o.animations?{...o,animations:{}}:o));return}let{hasValidItems:n,processedItems:r}=Lt(t.character.items,o=>o.sprites&&o.sprites.length>0||o.transformId||o.resourceId);n?e.character={items:r}:delete e.character},ir=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},sr=(e,t)=>{if(t.layout){let{animationsOnly:n,state:r}=ge(t.layout,o=>!!o.resourceId);if(n){e.layout=r;return}if(!t.layout.resourceId){delete e.layout;return}e.layout=t.layout}else e.layout&&delete e.layout},lr=(e,t)=>{if(t.choice){let{animationsOnly:n,state:r}=ge(t.choice,o=>!!o.resourceId);if(n){e.choice={...e.choice,...r};return}if(!t.choice.resourceId){delete e.choice;return}e.choice=t.choice}else e.choice&&delete e.choice},cr=(e,t)=>{t.keyboard&&(e.keyboard=t.keyboard)},ar=(e,t)=>{t.voice?e.voice=t.voice:e.voice&&delete e.voice},ur=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},ne=e=>he(Gn,[ur,Qn,Zn,tr,nr,rr,er,or,ir,sr,lr,cr,ar])(e);var J={objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n})),formatDate:Et},ye=({id:e,targetId:t,animation:n})=>{let r=structuredClone(n);return delete r.name,r.id=e,r.targetId=t,r},fr=(e,{defaultTargetId:t,defaultId:n}={})=>{if(!e||typeof e!="object"||Array.isArray(e))return e;let r=structuredClone(e);return r.id??=n,r.targetId??=t,r},Pt=({animations:e,transitions:t,defaultTargetId:n,idPrefix:r})=>{t.forEach((o,i)=>{e.push(fr(o,{defaultTargetId:n,defaultId:`${r}-transition-${i}`}))})},Ct=(e,t)=>{if(!e||typeof e!="string"||!e.includes("${"))return e;let n=N(e,t);return n&&typeof n=="object"?e:n},St=(e,t)=>{if(e===void 0)return[];if(!Array.isArray(e)||e.some(n=>n===null||typeof n!="object"||Array.isArray(n)))throw new Error(`${t} must be an array of objects`);return e},kt=(e,t=0)=>{let n=e?.sprites?.map(({resourceId:r})=>r)||[];return n.length===0?`character-container-${e.id}`:`character-container-${e.id}-${t}-${n.join("-")}`},Me=(e,t)=>{if(!t.transformId)throw new Error(`Visual item "${t.id}" requires transformId`);let n=e.transforms?.[t.transformId];if(!n)throw new Error(`Transform "${t.transformId}" not found for visual item "${t.id}"`);return n},dr=(e={})=>e.textStyles||{},pr=(e={})=>e.images||{},hr=(e={})=>e.colors||{},gr=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,re=(e,t)=>e==="root"?`${t}`:`${e}.${t}`,q=(e,t,n)=>{if(typeof e!="string"||e.length===0)throw new Error(`${n} at "${t}" must resolve to a non-empty string`)},Ot=(e,t,n)=>{if(e===void 0)return 1;if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${t} for text style "${n}" must be a number between 0 and 1`);if(e<0||e>1)throw new Error(`${t} for text style "${n}" must be a number between 0 and 1`);return e},Vt=(e,t)=>{if(typeof e!="string"||!gr.test(e))throw new Error(`${t} must resolve to a hex color`);return e.length===4?`#${e.slice(1).split("").map(n=>n.repeat(2)).join("")}`:e},Rt=(e,t,n)=>{let r=Vt(e,n);if(t===1)return r;let o=Number.parseInt(r.slice(1,3),16),i=Number.parseInt(r.slice(3,5),16),l=Number.parseInt(r.slice(5,7),16);return`rgba(${o}, ${i}, ${l}, ${t})`},yr=(e={},t)=>{let n=dr(e)?.[t];if(!n)throw new Error(`Text style "${t}" not found`);let r=e.fonts?.[n.fontId];if(!r)throw new Error(`Font "${n.fontId}" not found for text style "${t}"`);let o=e.colors?.[n.colorId];if(!o)throw new Error(`Color "${n.colorId}" not found for text style "${t}"`);let i=Ot(n.colorAlpha,"colorAlpha",t),l={fontFamily:r.fileId,fontSize:n.fontSize??16,fontWeight:n.fontWeight??"400",fontStyle:n.fontStyle??"normal",lineHeight:n.lineHeight??1.2,fill:Rt(o.hex,i,`Color "${n.colorId}" for text style "${t}"`)};if(n.align!==void 0&&(l.align=n.align),n.wordWrap!==void 0&&(l.wordWrap=n.wordWrap),n.breakWords!==void 0&&(l.breakWords=n.breakWords),n.wordWrapWidth!==void 0&&(l.wordWrapWidth=n.wordWrapWidth),n.strokeColorId){let a=e.colors?.[n.strokeColorId];if(!a)throw new Error(`Stroke color "${n.strokeColorId}" not found for text style "${t}"`);let c=Ot(n.strokeAlpha,"strokeAlpha",t);l.strokeColor=Rt(a.hex,c,`Stroke color "${n.strokeColorId}" for text style "${t}"`)}else if(n.strokeAlpha!==void 0)throw new Error(`strokeAlpha for text style "${t}" requires strokeColorId`);return n.strokeWidth!==void 0&&(l.strokeWidth=n.strokeWidth),l},Fe=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>Fe(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;if(Object.prototype.hasOwnProperty.call(e,"textStyle"))throw new Error(`Inline textStyle is not allowed in layout elements at "${n}". Use textStyleId instead`);let r={};for(let[o,i]of Object.entries(e))o!=="textStyleId"&&(r[o]=Fe(i,t,re(n,o)));return e.textStyleId!==void 0&&(q(e.textStyleId,n,"textStyleId"),r.textStyle=yr(t,e.textStyleId)),r},Dt=(e={},t)=>{let n=hr(e)?.[t];if(!n)throw new Error(`Color "${t}" not found`);return Vt(n.hex,`Color "${t}"`)},Mt=e=>e==="hover.fill"?"hover.colorId":e==="click.fill"?"click.colorId":e==="rightClick.fill"?"rightClick.colorId":"colorId",je=(e,t,n)=>{let r=e?.[t];if(!(!r||typeof r!="object"||Array.isArray(r))&&Object.prototype.hasOwnProperty.call(r,"fill"))throw new Error(`Inline ${t}.fill is not allowed in rect layout elements at "${n}". Use ${Mt(`${t}.fill`)} instead`)},mr=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>oe(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;let r={};for(let[o,i]of Object.entries(e))o!=="colorId"&&(r[o]=oe(i,t,re(n,o)));return e.colorId!==void 0&&(q(e.colorId,n,"colorId"),r.fill=Dt(t,e.colorId)),r},oe=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>oe(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;if(e.type==="rect"){if(Object.prototype.hasOwnProperty.call(e,"fill"))throw new Error(`Inline fill is not allowed in rect layout elements at "${n}". Use ${Mt("fill")} instead`);je(e,"hover",n),je(e,"click",n),je(e,"rightClick",n)}let r={};for(let[o,i]of Object.entries(e))if(!(e.type==="rect"&&o==="colorId")){if(e.type==="rect"&&(o==="hover"||o==="click"||o==="rightClick")){r[o]=mr(i,t,re(n,o));continue}r[o]=oe(i,t,re(n,o))}return e.type==="rect"&&e.colorId!==void 0&&(q(e.colorId,n,"colorId"),r.fill=Dt(t,e.colorId)),r},Be=(e={},t)=>{let n=pr(e)?.[t];return n||null},jt=e=>e==="hoverUrl"||e==="hoverSrc"||e==="hover.src"?"hoverImageId":e==="clickUrl"||e==="clickSrc"||e==="click.src"?"clickImageId":"imageId",Tt=(e,t,n,r)=>{let o=e?.[t];if(!(!o||typeof o!="object"||Array.isArray(o))&&Object.prototype.hasOwnProperty.call(o,r))throw new Error(`Inline ${t}.${r} is not allowed in sprite layout elements at "${n}". Use ${jt(`${t}.${r}`)} instead`)},Nt=(e,t,n)=>{let r=e[t];e[t]={...r&&typeof r=="object"&&!Array.isArray(r)?r:{},src:n}},Ue=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((o,i)=>Ue(o,t,`${n}[${i}]`));if(!e||typeof e!="object")return e;if(e.type==="sprite"){for(let o of["url","src","hoverUrl","hoverSrc","clickUrl","clickSrc"])if(Object.prototype.hasOwnProperty.call(e,o))throw new Error(`Inline ${o} is not allowed in sprite layout elements at "${n}". Use ${jt(o)} instead`);Tt(e,"hover",n,"src"),Tt(e,"click",n,"src")}let r={};for(let[o,i]of Object.entries(e))e.type==="sprite"&&(o==="imageId"||o==="hoverImageId"||o==="clickImageId")||(r[o]=Ue(i,t,re(n,o)));if(e.type==="sprite"&&e.imageId!==void 0){q(e.imageId,n,"imageId");let o=Be(t,e.imageId),i=o?.fileId??e.imageId;r.src=i,r.width===void 0&&o?.width!==void 0&&(r.width=o.width),r.height===void 0&&o?.height!==void 0&&(r.height=o.height)}return e.type==="sprite"&&e.hoverImageId!==void 0&&(q(e.hoverImageId,n,"hoverImageId"),Nt(r,"hover",Be(t,e.hoverImageId)?.fileId??e.hoverImageId)),e.type==="sprite"&&e.clickImageId!==void 0&&(q(e.clickImageId,n,"clickImageId"),Nt(r,"click",Be(t,e.clickImageId)?.fileId??e.clickImageId)),r},We=(e,t={},n="root")=>Ue(oe(Fe(e,t,n),t,n),t,n),U=We,K=({animations:e,animationsDef:t,resources:n,previousResourceId:r,currentResourceId:o,idPrefix:i,targetId:l,outTargetId:a})=>{if(t){if(t.in){let c=t.in.resourceId||t.in,s=n?.animations?.[c];s&&!r&&e.push(ye({id:`${i}-animation-in`,targetId:l,animation:s}))}if(t.out){let c=t.out.resourceId||t.out,s=n?.animations?.[c];s&&r&&r!==o&&e.push(ye({id:`${i}-animation-out`,targetId:a||l,animation:s}))}if(t.update){let c=t.update.resourceId||t.update,s=n?.animations?.[c];s&&r&&r===o&&e.push(ye({id:`${i}-animation-update`,targetId:l,animation:s}))}}},br=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),Ir=(e,{presentationState:t,resources:n,variables:r})=>{let{elements:o}=e;if(t.base){let i=o.find(l=>l.id==="story");if(!i)return e;if(t.base.resourceId){let l=n?.layouts[t.base.resourceId];if(l){let a={id:"base",type:"container",children:l.elements},c=N(a,{variables:r},{functions:J});i.children.unshift(U(c,n))}}}return e},wr=(e,{presentationState:t,previousPresentationState:n,resources:r={},isLineCompleted:o,skipTransitionsAndAnimations:i,variables:l})=>{let{elements:a,animations:c}=e;if(t.background){let s=a.find(f=>f.id==="story");if(!s)return e;if(t.background.resourceId){let{images:f={},videos:u={}}=r,d=f[t.background.resourceId]||u[t.background.resourceId];if(d){let h=u[t.background.resourceId]!==void 0,g={id:`bg-cg-${t.background.resourceId}`,type:h?"video":"sprite",x:0,y:0,src:d.fileId,width:d.width,height:d.height};h&&(g.loop=t.background.loop??!1,g.volume=d.volume??500),s.children.push(g)}}if(t.background.resourceId){let{layouts:f={}}=r,u=f[t.background.resourceId];if(u){let d={id:`bg-cg-${t.background.resourceId}`,type:"container",children:u.elements},h=N(d,{variables:l},{functions:J});s.children.push(U(h,r))}}if(t.background.animations&&!o&&!i){let f=n?.background?.resourceId,u=t.background.resourceId;K({animations:c,animationsDef:t.background.animations,resources:r,previousResourceId:f,currentResourceId:u,idPrefix:"bg-cg",targetId:`bg-cg-${u}`,outTargetId:`bg-cg-${f}`})}}return e},vr=(e,{presentationState:t,previousPresentationState:n,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i})=>{let{elements:l,animations:a}=e;if(t.character&&r){let c=l.find(u=>u.id==="story");if(!c)return e;let s=t.character.items||[],f=n?.character?.items||[];for(let u=0;u<s.length;u++){let d=s[u],{transformId:h,sprites:g}=d,m=f.find(L=>L.id===d.id),I=f.findIndex(L=>L.id===d.id),y=m?.sprites&&m.sprites.length>0,b=g&&g.length>0,v=I>=0?kt(m,I):void 0;if(d.animations&&d.animations.out&&!g&&!h){if(!o&&y){let L=d.animations.out.resourceId,C=r?.animations?.[L];if(C){let be=ye({id:"character-animation-out",targetId:v||`character-container-${d.id}`,animation:C});a.push(be)}}continue}if(!g||g.length===0||!h){console.warn("Character item missing sprites or transformId:",d);continue}let _=kt(d,u),E=r.transforms[h];if(!E){console.warn("Transform not found:",h);continue}let V={type:"container",id:_,x:d.x??E.x,y:d.y??E.y,anchorX:E.anchorX,anchorY:E.anchorY,rotation:E.rotation,scaleX:E.scaleX,scaleY:E.scaleY,children:[]};for(let L of g){let C=r.images[L.resourceId];if(!C){console.warn(`Image resource not found: ${L.resourceId}`);continue}V.children.push({type:"sprite",id:`${_}-${L.id}`,src:C.fileId,width:C.width,height:C.height,x:0,y:0})}c.children.push(V),d.animations&&!o&&!i&&K({animations:a,animationsDef:d.animations,resources:r,previousResourceId:y,currentResourceId:b,idPrefix:"character",targetId:_,outTargetId:v})}}return e},xr=(e,{presentationState:t,previousPresentationState:n,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i,variables:l})=>{let{elements:a,animations:c}=e;if(t.visual&&r){let s=a.find(u=>u.id==="story");if(!s)return e;let f=t.visual.items;for(let u of f){if(u.resourceId){let{images:d={},videos:h={},spritesheets:g={}}=r,m=g[u.resourceId];if(m){let I=Me(r,u),y=u.animationName;if(y){let b=m.animations?.[y];if(!b)throw new Error(`Animation '${y}' not found in spritesheet resource '${u.resourceId}'`);let v={id:`visual-${u.id}`,type:"animated-sprite",x:u.x??I.x,y:u.y??I.y,width:u.width??m.width,height:u.height??m.height,alpha:u.alpha??1,anchorX:I.anchorX,anchorY:I.anchorY,rotation:I.rotation,scaleX:I.scaleX,scaleY:I.scaleY,spritesheetSrc:m.fileId,spritesheetData:m.jsonData,animation:{frames:b.frames,animationSpeed:u.animationSpeed??b.animationSpeed??.5,loop:u.loop??b.loop??!0}};s.children.push(structuredClone(v))}}else{let I=d[u.resourceId]||h[u.resourceId];if(I){let y=h[u.resourceId]!==void 0,b=Me(r,u),v={id:`visual-${u.id}`,type:y?"video":"sprite",src:I.fileId,width:I.width,height:I.height,x:b.x,y:b.y,anchorX:b.anchorX,anchorY:b.anchorY,rotation:b.rotation,scaleX:b.scaleX,scaleY:b.scaleY};y&&(v.loop=I.loop??!1,v.volume=I.volume??500),s.children.push(v)}}}if(u.resourceId){let{layouts:d={}}=r,h=d[u.resourceId];if(h){let g=Me(r,u),m={id:`visual-${u.id}`,type:"container",children:structuredClone(h.elements),x:g.x,y:g.y,anchorX:g.anchorX,anchorY:g.anchorY,rotation:g.rotation,scaleX:g.scaleX,scaleY:g.scaleY},I=N(m,{variables:l},{functions:J});s.children.push(U(I,r))}}if(u.animations&&!o&&!i){let h=(n?.visual?.items||[]).find(g=>g.id===u.id);K({animations:c,animationsDef:u.animations,resources:r,previousResourceId:h?.resourceId,currentResourceId:u.resourceId,idPrefix:u.id,targetId:`visual-${u.id}`})}}}return e},Ar=(e,{presentationState:t,previousPresentationState:n,resources:r={},dialogueUIHidden:o,autoMode:i,skipMode:l,canRollback:a,skipOnlyViewedLines:c,isLineCompleted:s,skipTransitionsAndAnimations:f,variables:u,saveSlots:d=[]})=>{let{elements:h,animations:g}=e;if(!t.dialogue||o)return e;let m=h.find(I=>I.id==="story");if(!m)return e;if(t.dialogue.ui&&t.dialogue.ui.resourceId){let{layouts:I={}}=r,y=I[t.dialogue.ui.resourceId];if(y){let b;t.dialogue.characterId&&(b=r.characters[t.dialogue.characterId]),t.dialogue.character&&(b={...b,name:t.dialogue.character.name});let v={elements:y.elements},_=t.dialogue?.content===void 0?[{text:""}]:St(t.dialogue.content,"dialogue.content"),E={variables:u,autoMode:i,skipMode:l,canRollback:a,skipOnlyViewedLines:c,isLineCompleted:s,saveSlots:d,effectiveSoundVolume:u?._muteAll?0:u?._soundVolume??500,textSpeed:u?._textSpeed??50,dialogue:{character:{name:b?.name||""},content:_.map(C=>({...C,text:Ct(C.text,{variables:u})})),lines:(t.dialogue?.lines||[]).map((C,be)=>({content:St(C.content,`dialogue.lines[${be}].content`).map(Xe=>({...Xe,text:Ct(Xe.text,{variables:u})})),characterName:C.characterId&&r.characters?.[C.characterId]?.name||""}))}},V=N(v,E,{functions:J}),L=U(V?.elements,r);if(Array.isArray(L))for(let C of L)m.children.push(C);else L&&m.children.push(L)}}return t.dialogue.ui?.animations&&!s&&!f&&K({animations:g,animationsDef:t.dialogue.ui.animations,resources:r,previousResourceId:n?.dialogue?.ui?.resourceId,currentResourceId:t.dialogue.ui?.resourceId,idPrefix:"dialogue-ui",targetId:"dialogue-container"}),e},_r=(e,{presentationState:t,previousPresentationState:n,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i,screen:l})=>{let{elements:a,animations:c}=e;if(t.choice&&r){let s=a.find(u=>u.id==="story");if(!s)return e;s.children.push({id:"choice-blocker",type:"rect",fill:"transparent",width:l.width,height:l.height,x:0,y:0,click:{payload:{actions:{}}}});let f=r?.layouts[t.choice.resourceId];if(f&&f.elements){let u={elements:f.elements},d=N(u,{choice:{items:t.choice?.items??[]}}),h=U(d?.elements,r);if(Array.isArray(h))for(let g of h)s.children.push(g);else h&&s.children.push(h)}t.choice.animations&&!o&&!i&&K({animations:c,animationsDef:t.choice.animations,resources:r,previousResourceId:n?.choice?.resourceId,currentResourceId:t.choice.resourceId,idPrefix:"choice",targetId:"choice-container"})}return e},Er=(e,{presentationState:t,resources:n})=>{if(t.keyboard?.resourceId){let r=n?.keyboards?.[t.keyboard.resourceId];r&&(e.global.keyboard=r)}return e},$r=(e,{presentationState:t,resources:n,variables:r})=>{let{elements:o,audio:i}=e;if(t.bgm&&n){if(!o.find(s=>s.id==="story"))return e;let a=n.sounds[t.bgm.resourceId];if(!a)return e;let c=r?._muteAll?0:r?._musicVolume??500;i.push({id:"bgm",type:"sound",src:a.fileId,loop:t.bgm.loop??!0,volume:c,delay:t.bgm.delay??null})}return e},Lr=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(t.sfx&&n){let o=t.sfx.items;for(let i of o){let l=n.sounds?.[i.resourceId];l&&r.push({id:i.id,type:"sound",src:l.fileId,loop:i.loop??l.loop??!0,volume:i.volume??l.volume??500,delay:i.delay??l.delay??null})}}return e},Cr=(e,{presentationState:t,resources:n})=>{let{audio:r}=e;if(!t?.voice)return e;let{fileId:o,volume:i,loop:l}=t.voice;return r.push({id:`voice-${o}`,type:"sound",src:o,volume:i??500,loop:l??!1}),e},Sr=(e,{presentationState:t,previousPresentationState:n,resources:r={},variables:o,autoMode:i,skipMode:l,canRollback:a,saveSlots:c=[],isLineCompleted:s,skipTransitionsAndAnimations:f})=>{let{elements:u,animations:d}=e;if(t.layout){let h=u.find(b=>b.id==="story");if(!h)return e;let g=r.layouts[t.layout.resourceId];if(!g)return e;Array.isArray(g.transitions)&&!s&&!f&&Pt({animations:d,transitions:g.transitions,defaultTargetId:`layout-${t.layout.resourceId}`,idPrefix:`layout-${t.layout.resourceId}`});let m={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:g.elements||[]},I={variables:o,saveSlots:c,autoMode:i,skipMode:l,canRollback:a,effectiveSoundVolume:o?._muteAll?0:o?._soundVolume??500,textSpeed:o?._textSpeed??50},y=N(m,I,{functions:J});h.children.push(U(y,r))}if(t.layout?.animations&&!s&&!f){let h=n?.layout?.resourceId,g=t.layout?.resourceId;K({animations:d,animationsDef:t.layout.animations,resources:r,previousResourceId:h,currentResourceId:g,idPrefix:"layout",targetId:`layout-${g}`,outTargetId:`layout-${h}`})}return e},kr=(e,{resources:t={},variables:n,autoMode:r,skipMode:o,canRollback:i,layeredViews:l=[],dialogueHistory:a=[],saveSlots:c=[],screen:s})=>{let{elements:f,animations:u}=e;return l&&l.length>0&&l.forEach((d,h)=>{let g=t.layouts[d.resourceId];if(!g){console.warn(`LayeredView layout not found: ${d.resourceId}`);return}Array.isArray(g.transitions)&&Pt({animations:u,transitions:g.transitions,defaultTargetId:`layeredView-${h}`,idPrefix:`layeredView-${h}`});let m={id:`layeredView-${h}`,type:"container",x:0,y:0,children:[{id:`layeredView-${h}-blocker`,type:"rect",fill:"transparent",width:s.width,height:s.height,x:0,y:0,click:{payload:{actions:{}}}},...g.elements||[]]},I=a.map(V=>{let L=t.characters?.[V.characterId];return{...V,characterName:L?.name||""}}),y={variables:n,autoMode:r,skipMode:o,canRollback:i,saveSlots:c,effectiveSoundVolume:n?._muteAll?0:n?._soundVolume??500,textSpeed:n?._textSpeed??50,historyDialogue:I,characters:t.characters||{}},b=N(m,y,{functions:J}),[v,..._]=b.children||[],E=U({...b,children:_},t);f.push({...E,children:v?[v,...E.children||[]]:E.children})}),e},Bt=e=>he(br,[Ir,wr,vr,xr,Ar,_r,Er,Sr,$r,Lr,Cr,kr])(e);var X={manual:{enabled:!0,requireLineCompleted:!1},auto:{enabled:!1},applyMode:"persistent"},Ft=e=>{if((e.global.nextLineConfig?.applyMode??"persistent")!=="singleLine")return;let n=e.global.nextLineConfig?.auto?.enabled===!0;e.global.nextLineConfig={manual:{...X.manual},auto:{...X.auto},applyMode:X.applyMode},n&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"})},Or=e=>{let{projectData:t}=e,n=e.global??{},{saveSlots:r={},variables:o={}}=n,i=t.story.initialSceneId,l=t.story.scenes[i],a=l.initialSectionId,c=l.sections[a],s={sceneId:i,sectionId:a,lineId:c.initialLineId??c.lines[0].id},{contextVariableDefaultValues:f,globalVariablesDefaultValues:u}=xt(t),d={...u,...o};return{projectData:t,global:{isLineCompleted:!1,pendingEffects:[],autoMode:!1,skipMode:!1,dialogueUIHidden:!1,isDialogueHistoryShowing:!1,viewedRegistry:{sections:[],resources:[]},nextLineConfig:{manual:{...X.manual},auto:{...X.auto},applyMode:X.applyMode},saveSlots:r,layeredViews:[],variables:d},contexts:[{currentPointerMode:"read",pointers:{read:s,history:{sectionId:void 0,lineId:void 0,historySequenceIndex:void 0}},historySequence:[{sectionId:s.sectionId,initialState:{...f},lines:[{id:s.lineId}]}],configuration:{},views:[],bgm:{resourceId:void 0},variables:f}]}},Rr=({state:e})=>e.global.layeredViews||[],Tr=({state:e})=>e.global.pendingEffects,Ut=({state:e})=>e.global.skipMode,Nr=({state:e})=>e.global.autoMode,Wt=({state:e})=>e.global.dialogueUIHidden,Ye=({state:e})=>{let t=e.contexts[e.contexts.length-1];if(!t)return[];let{sectionId:n,lineId:r}=t.pointers.read,o=O({state:e},{sectionId:n});if(!o?.lines||!Array.isArray(o.lines))return[];let i=o.lines.findIndex(c=>c.id===r);return o.lines.slice(0,i+1).filter(c=>c.actions?.dialogue).map(c=>{let s=c.actions.dialogue,f="";return s.characterId&&(f=e.projectData.resources?.characters?.[s.characterId]?.name||""),{content:s.content,characterId:s.characterId,characterName:f}})},He=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(c=>c.sectionId===n);if(!o)return!1;if(o.lastLineId===void 0||r===void 0)return!0;let i=O({state:e},{sectionId:n});if(!i||!i.lines||!Array.isArray(i.lines))return!1;let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);return l===-1||a===-1?o.lastLineId===r:a<l},Pr=({state:e},t)=>{let{resourceId:n}=t;return!!e.global.viewedRegistry.resources.find(o=>o.resourceId===n)},Vr=({state:e})=>e.global.nextLineConfig,Dr=({state:e})=>e.global.saveSlots,Mr=({state:e},t)=>{let{slotKey:n}=t;return e.global.saveSlots[n]},W=({state:e})=>{let t=e.contexts[e.contexts.length-1];if(!t)return;let n=t.pointers?.[t.currentPointerMode];return{currentPointerMode:t.currentPointerMode,pointer:n}},O=({state:e},t)=>{let{sectionId:n}=t,r=e.projectData?.story?.scenes||{};for(let o in r){let i=r[o];if(i.sections&&i.sections[n])return i.sections[n]}},zt=({state:e})=>{let t=W({state:e});if(!t?.pointer)return;let{sectionId:n,lineId:r}=t.pointer,o=O({state:e},{sectionId:n});if(!(!o?.lines||!Array.isArray(o.lines)))return o.lines.find(i=>i.id===r)},jr=({state:e})=>{let t=W({state:e})?.pointer,n=t?.sectionId,r=t?.lineId,i=O({state:e},{sectionId:n})?.lines||[],l=i.findIndex(s=>s.id===r);if(l<0)return;let a;return i.slice(0,l+1).forEach(s=>{if(!s?.actions||!Object.prototype.hasOwnProperty.call(s.actions,"choice"))return;let f=s.actions.choice;if(!f?.resourceId){f?.animations||(a=void 0);return}a=f.resourceId}),a},Yt=({state:e})=>{let{sectionId:t,lineId:n}=W({state:e}).pointer,o=O({state:e},{sectionId:t})?.lines||[],i=o.findIndex(s=>s.id===n),a=o.slice(0,i+1).map(s=>{let f=s.actions||{},u={};return Object.keys(f).forEach(d=>{u[d]=f[d]}),u});return ne(a)},Br=({state:e})=>{let t=Ht({state:e}),r=zt({state:e})?.actions??{},o=ne([t??{},r]);return De(t??{},o??{})},Fr=({state:e},{sectionId:t})=>{let n=O({state:e},{sectionId:t});if(!n?.lines)return{lines:[]};let r=[],o={};for(let i of n.lines){let l=i.actions||{},a=ne([o,l]),c=De(o,a);r.push({id:i.id,changes:c}),o=a}return{lines:r}},Ht=({state:e})=>{let{sectionId:t,lineId:n}=W({state:e}).pointer,o=O({state:e},{sectionId:t})?.lines||[],i=o.findIndex(c=>c.id===n);if(i<=0)return null;let a=o.slice(0,i).map(c=>{let s=c.actions||{},f={};return Object.keys(s).forEach(u=>{f[u]=s[u]}),f});return ne(a)},qt=({state:e},{slotsPerPage:t=6}={})=>{let o=(({...e.global.variables,...e.contexts[e.contexts.length-1].variables}.loadPage??1)-1)*t+1,i=[];for(let l=0;l<t;l++){let a=o+l,c=e.global.saveSlots&&e.global.saveSlots[a]||{};i.push({slotNumber:a,...c})}return{saveSlots:i}},Ur=({state:e})=>{let t=Yt({state:e}),n=Ht({state:e}),r={...e.global.variables,...e.contexts[e.contexts.length-1].variables},{saveSlots:o}=qt({state:e});return Bt({presentationState:t,previousPresentationState:n,resources:e.projectData.resources,screen:e.projectData.screen,dialogueUIHidden:e.global.dialogueUIHidden,autoMode:e.global.autoMode,skipMode:e.global.skipMode,canRollback:en({state:e}),skipOnlyViewedLines:!r._skipUnseenText,isLineCompleted:e.global.isLineCompleted,skipTransitionsAndAnimations:!!r._skipTransitionsAndAnimations,layeredViews:e.global.layeredViews,dialogueHistory:Ye({state:e}),saveSlots:o,variables:r})},Wr=({state:e},t)=>(e.global.layeredViews.push(t),e.global.pendingEffects.push({name:"render"}),e),zr=({state:e})=>(e.global.layeredViews.pop(),e.global.pendingEffects.push({name:"render"}),e),Yr=({state:e},t)=>(e.global.layeredViews.length>0&&(e.global.layeredViews[e.global.layeredViews.length-1]=t),e.global.pendingEffects.push({name:"render"}),e),Hr=({state:e})=>(e.global.layeredViews=[],e.global.pendingEffects.push({name:"render"}),e),Jt=({state:e})=>{if(e.global.skipMode&&(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"})),e.global.autoMode=!0,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.isLineCompleted){let t=e.global.variables._autoForwardTime??1e3;e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:t}})}return e.global.pendingEffects.push({name:"render"}),e},me=({state:e})=>(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),qr=({state:e})=>(e.global.autoMode?me({state:e}):Jt({state:e}),e),Kt=({state:e})=>(e.global.autoMode&&(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"})),e.global.skipMode=!0,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"startSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),G=({state:e})=>(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Jr=({state:e})=>(Ut({state:e})?G({state:e}):Kt({state:e}),e),Xt=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),e),Gt=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),e),Kr=({state:e})=>(Wt({state:e})?Xt({state:e}):Gt({state:e}),e),Xr=({state:e})=>{let t=Ye({state:e});return e.global.isDialogueHistoryShowing=!0,e.global.pendingEffects.push({name:"render"}),e},Gr=({state:e})=>(e.global.isDialogueHistoryShowing=!1,e.global.pendingEffects.push({name:"render"}),e),Qr=({state:e})=>(e.global.pendingEffects=[],e),Zr=({state:e},t)=>(e.global.pendingEffects.push(t),e),Qt=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.global.viewedRegistry.sections.find(i=>i.sectionId===n);if(o){let i=O({state:e},{sectionId:n});if(i?.lines&&o.lastLineId!==void 0){let l=i.lines.findIndex(c=>c.id===o.lastLineId),a=i.lines.findIndex(c=>c.id===r);(l===-1||a>l)&&(o.lastLineId=r)}else o.lastLineId=r}else e.global.viewedRegistry.sections.push({sectionId:n,lastLineId:r});return e.global.pendingEffects.push({name:"render"}),e},eo=({state:e},t)=>{let{resourceId:n}=t;return e.global.viewedRegistry.resources.find(o=>o.resourceId===n)||e.global.viewedRegistry.resources.push({resourceId:n}),e.global.pendingEffects.push({name:"render"}),e},to=({state:e},t)=>{let{manual:n,auto:r,applyMode:o}=t,i=e.global.nextLineConfig.auto?.enabled,l=e.global.nextLineConfig?.applyMode;n&&r?(e.global.nextLineConfig={manual:n,auto:r},o!==void 0?e.global.nextLineConfig.applyMode=o:l!==void 0&&(e.global.nextLineConfig.applyMode=l)):(n&&(e.global.nextLineConfig.manual=n),r&&(e.global.nextLineConfig.auto=r),o!==void 0&&(e.global.nextLineConfig.applyMode=o));let a=e.global.nextLineConfig.auto?.enabled;return a===!0&&!i?e.global.nextLineConfig.auto?.trigger==="fromStart"?e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}}):e.global.isLineCompleted&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}}):a===!1&&i&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.pendingEffects.push({name:"render"}),e},no=({state:e},t)=>{let{slot:n,thumbnailImage:r}=t,o=String(n),i={contexts:[...e.contexts],viewedRegistry:e.global.viewedRegistry},l={slotKey:o,date:Date.now(),image:r,state:i};return e.global.saveSlots[o]=l,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}},{name:"render"}),e},ro=({state:e},t)=>{let{slot:n}=t,r=String(n),o=e.global.saveSlots[r];return o&&(e.global.viewedRegistry=o.state.viewedRegistry,e.contexts=o.state.contexts,e.global.pendingEffects.push({name:"render"})),e},oo=({state:e},t)=>{let{projectData:n}=t;return e.projectData=n,e.global.pendingEffects.push({name:"render"}),e},io=({state:e},t)=>{let{sectionId:n,lineId:r}=t;if(!r)return console.warn("jumpToLine requires lineId parameter"),e;let o=e.contexts[e.contexts.length-1];if(!o)return console.warn("No context available for jumpToLine"),e;let i=n||o.pointers.read?.sectionId;if(n&&!O({state:e},{sectionId:n}))return console.warn(`Section not found: ${n}`),e;let l=O({state:e},{sectionId:i});return!l?.lines||!Array.isArray(l.lines)?(console.warn(`Section ${i} has no lines`),e):l.lines.find(c=>c.id===r)?(o.pointers.read={sectionId:i,lineId:r},e.global.isLineCompleted=!1,ie({state:e},{lineId:r}),e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e):(console.warn(`Line not found: ${r} in section ${i}`),e)},Zt=({state:e},t)=>{let{item:n}=t,r=e.contexts[e.contexts.length-1];if(r&&r.historySequence){let o={...r.variables};r.historySequence.push({sectionId:n.sectionId,initialState:o,lines:[]})}return e.global.pendingEffects.push({name:"render"}),e},ie=({state:e},t)=>{let{lineId:n}=t,r=e.contexts[e.contexts.length-1];if(!r?.historySequence)return e;let o=r.historySequence;if(o.length===0)return e;let i=o[o.length-1];return i.lines||(i.lines=[]),i.lines.push({id:n}),e},so=({state:e})=>{if(!e.global.nextLineConfig.manual.enabled)return e;if(!e.global.isLineCompleted){if(e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.autoMode){let c=e.global.variables._autoForwardTime??1e3;e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:c}})}let a=e.global.nextLineConfig;return a?.auto?.enabled&&a.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:a.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e}let t=W({state:e})?.pointer,n=t?.sectionId,o=O({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=!e.global.variables?._skipUnseenText;if(e.global.skipMode&&c&&!He({state:e},{sectionId:n,lineId:a.id}))return G({state:e}),e;let s=e.contexts[e.contexts.length-1];if(s){let u=s.pointers.read.lineId;u&&n&&Qt({state:e},{sectionId:n,lineId:u}),s.pointers.read={sectionId:n,lineId:a.id}}e.global.isLineCompleted=!1,ie({state:e},{lineId:a.id}),Ft(e),e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"});let f=e.global.nextLineConfig;f?.auto?.enabled&&f.auto.trigger==="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:f.auto.delay}})}else e.global.autoMode&&me({state:e}),e.global.skipMode&&G({state:e});return e},lo=({state:e})=>{if(e.global.isLineCompleted)return e;if(e.global.isLineCompleted=!0,e.global.autoMode){let n=e.global.variables._autoForwardTime??1e3;e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:n}})}let t=e.global.nextLineConfig;return t?.auto?.enabled&&t.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:t.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e},co=({state:e},t)=>{let{sectionId:n}=t,r=O({state:e},{sectionId:n});if(!r||!r.lines||r.lines.length===0)return e;let o=r.lines,i=e.contexts[e.contexts.length-1];if(!i||!i.pointers)return e;let l=i.pointers.history||i.pointers.read;if(i.currentPointerMode!=="history"||!i.pointers.history){if(!l)return e;i.currentPointerMode="history",i.pointers.history={sectionId:n,lineId:l?.lineId};let f=o.findIndex(u=>u.id===l.lineId)-1;if(f>=0&&f<o.length){let u=o[f];i.pointers.history={sectionId:n,lineId:u.id}}return e.global.pendingEffects.push({name:"render"}),e}let c=o.findIndex(s=>s.id===i.pointers.history.lineId)-1;if(c>=0&&c<o.length){let s=o[c];i.pointers.history={sectionId:n,lineId:s.id},e.global.pendingEffects.push({name:"render"})}return e},ao=({state:e},t)=>{let{sectionId:n}=t,r=O({state:e},{sectionId:n});if(!r)return console.warn(`Section not found: ${n}`),e;let o=r.lines?.[0];if(!o)return console.warn(`Section ${n} has no lines`),e;e.global.autoMode&&me({state:e}),e.global.skipMode&&G({state:e});let i=e.contexts[e.contexts.length-1];return i&&(i.pointers.read={sectionId:n,lineId:o.id},Zt({state:e},{item:{sectionId:n}}),ie({state:e},{lineId:o.id})),e.global.isLineCompleted=!1,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e},uo=({state:e})=>{if(jr({state:e}))return e;let t=W({state:e})?.pointer,n=t?.sectionId,o=O({state:e},{sectionId:n})?.lines||[],l=o.findIndex(a=>a.id===t?.lineId)+1;if(l<o.length){let a=o[l],c=!e.global.variables?._skipUnseenText;if(e.global.skipMode&&c&&!He({state:e},{sectionId:n,lineId:a.id}))return G({state:e}),e;let s=e.contexts[e.contexts.length-1];s&&(s.pointers.read={sectionId:n,lineId:a.id}),e.global.isLineCompleted=!1,ie({state:e},{lineId:a.id}),Ft(e),e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e.global.nextLineConfig.auto?.enabled&&e.global.nextLineConfig.auto.trigger==="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}})}else e.global.nextLineConfig.auto?.enabled&&(e.global.nextLineConfig.auto.enabled=!1,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}));return e},fo=({state:e},t)=>{let{id:n,operations:r=[]}=t;if(!n)throw new Error("updateVariable requires an id field");if(typeof n!="string"||!/^[a-zA-Z0-9]+$/.test(n))throw new Error(`updateVariable id must be alphanumeric, got: "${n}"`);let o=e.contexts[e.contexts.length-1],i=!1,l=!1,a=!1;if(r.forEach(({variableId:c,op:s,value:f})=>{let u=e.projectData.resources?.variables?.[c],d=u?.scope,h=u?.type;At(d,c),_t(h,s,c);let g=d==="context"?o.variables:e.global.variables;d==="context"?i=!0:d==="global-device"?l=!0:d==="global-account"&&(a=!0),g[c]=Pe(g[c],s,f)}),i){let c=o.historySequence;if(c&&c.length>0){let s=c[c.length-1];if(s.lines&&s.lines.length>0){let f=s.lines[s.lines.length-1];f.updateVariableIds||(f.updateVariableIds=[]),f.updateVariableIds.push(n)}}}if(l){let c=Ve(e.global.variables,e.projectData.resources?.variables,"global-device");e.global.pendingEffects.push({name:"saveGlobalDeviceVariables",payload:{globalDeviceVariables:c}})}if(a){let c=Ve(e.global.variables,e.projectData.resources?.variables,"global-account");e.global.pendingEffects.push({name:"saveGlobalAccountVariables",payload:{globalAccountVariables:c}})}return e.global.pendingEffects.push({name:"render"}),e},ze=(e,t,n="")=>{if(e!=null){if(n==="updateVariable"&&typeof e=="object"&&e.id===t&&Array.isArray(e.operations))return e;if(Array.isArray(e)){for(let r of e){let o=ze(r,t,n);if(o)return o}return}if(typeof e=="object")for(let r of Object.keys(e)){let o=ze(e[r],t,r);if(o)return o}}},qe=({state:e},t)=>{let{offset:n}=t;if(n===void 0||typeof n!="number")return console.warn("selectLineIdByOffset requires a numeric offset"),null;let r=e.contexts[e.contexts.length-1];if(!r)return null;let o=r.pointers.read?.sectionId,i=r.pointers.read?.lineId;if(!o||!i)return null;let a=r.historySequence?.find(u=>u.sectionId===o);if(!a?.lines||a.lines.length===0)return null;let c=a.lines.findLastIndex(u=>u.id===i);if(c===-1)return null;let s=c+n;if(s<0||s>=a.lines.length)return null;let f=a.lines[s];return{sectionId:o,lineId:f.id}},en=({state:e})=>qe({state:e},{offset:-1})!==null,po=({state:e},t)=>{let{offset:n=-1}=t;if(n>=0)throw new Error("rollbackByOffset requires a negative offset");let r=qe({state:e},{offset:n});return r?tn({state:e},{sectionId:r.sectionId,lineId:r.lineId}):e},tn=({state:e},t)=>{let{sectionId:n,lineId:r}=t,o=e.contexts[e.contexts.length-1];if(!o)throw new Error("No context available for rollbackToLine");let l=o.historySequence?.find(s=>s.sectionId===n);if(!l?.lines)throw new Error(`Section ${n} not found in history or has no lines`);let a=l.lines.findIndex(s=>s.id===r);if(a===-1)throw new Error(`Line ${r} not found in section ${n} history`);let c=l.initialState||{};o.variables={...c};for(let s=0;s<a;s++){let u=l.lines[s].updateVariableIds||[];for(let d of u){let h=ze(e.projectData,d);if(!h)throw new Error(`Action definition not found for ID: ${d}`);let g=h.operations||[];for(let{variableId:m,op:I,value:y}of g)e.projectData.resources?.variables?.[m]?.scope==="context"&&(o.variables[m]=Pe(o.variables[m],I,y))}}return l.lines=l.lines.slice(0,a),l.lines.push({id:r}),o.pointers.read={sectionId:n,lineId:r},o.currentPointerMode="read",o.pointers.history={sectionId:null,lineId:null,historySequenceIndex:null},e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"render"}),e.global.pendingEffects.push({name:"handleLineActions"}),e},nn=e=>{let t=Or(e);return vt(t,{selectPendingEffects:Tr,selectSkipMode:Ut,selectAutoMode:Nr,selectDialogueUIHidden:Wt,selectDialogueHistory:Ye,selectIsLineViewed:He,selectIsResourceViewed:Pr,selectNextLineConfig:Vr,selectSaveSlots:Dr,selectSaveSlot:Mr,selectCurrentPointer:W,selectSection:O,selectCurrentLine:zt,selectPresentationState:Yt,selectPresentationChanges:Br,selectSectionLineChanges:Fr,selectCurrentPageSlots:qt,selectRenderState:Ur,selectLayeredViews:Rr,selectLineIdByOffset:qe,selectCanRollback:en,startAutoMode:Jt,stopAutoMode:me,toggleAutoMode:qr,startSkipMode:Kt,stopSkipMode:G,toggleSkipMode:Jr,showDialogueUI:Xt,hideDialogueUI:Gt,toggleDialogueUI:Kr,showDialogueHistory:Xr,hideDialogueHistory:Gr,clearPendingEffects:Qr,appendPendingEffect:Zr,addViewedLine:Qt,addViewedResource:eo,setNextLineConfig:to,saveSaveSlot:no,loadSaveSlot:ro,updateProjectData:oo,sectionTransition:ao,jumpToLine:io,addToHistorySequence:Zt,addLineToHistory:ie,nextLine:so,markLineCompleted:lo,prevLine:co,rollbackToLine:tn,rollbackByOffset:po,pushLayeredView:Wr,popLayeredView:zr,replaceLastLayeredView:Yr,clearLayeredViews:Hr,updateVariable:fo,nextLineFromSystem:uo},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};function Je(e){let t,n=0,{handlePendingEffects:r}=e,o=()=>{for(;t.selectPendingEffects().length>0;){let y=[...t.selectPendingEffects()];t.clearPendingEffects(),r(y)}},i=({initialState:y})=>{t=nn(y),n=0,t.appendPendingEffect({name:"render"}),I(),o()},l=()=>t.selectPresentationState(),a=()=>t.selectPresentationChanges(),c=y=>t.selectSectionLineChanges(y),s=()=>(n+=1,{...t.selectRenderState(),id:`render-${n}`}),f=()=>t.selectSaveSlots(),u=()=>t.selectSkipMode(),d=()=>t.selectAutoMode(),h=(y,b)=>{t[y]&&(t[y](b),o())},g=y=>{if(!y)return;if(Object.prototype.hasOwnProperty.call(y,"event"))throw new Error('eventContext key "event" is no longer supported. Use "_event".');let{_event:b,...v}=y,_=t.selectAllVariables?t.selectAllVariables():void 0;return{...v,_event:b,variables:_}},m=(y,b)=>{let v=g(b),_=$t(y,v);Object.entries(_).forEach(([E,V])=>{h(E,V)})},I=()=>{let y=t.selectCurrentLine();y?.actions&&m(y.actions)};return{init:i,handleAction:h,handleActions:m,selectRenderState:s,selectPresentationState:l,selectPresentationChanges:a,selectSectionLineChanges:c,selectSaveSlots:f,handleLineActions:I}}var Ke=()=>{let e=0,t=null;return{getElapsed:()=>e,setElapsed:n=>{e=n},addElapsed:n=>{e+=n},getCallback:()=>t,setCallback:n=>{t=n}}},ho=({engine:e,routeGraphics:t},n)=>{let r=e.selectRenderState();t.render(r)},go=({engine:e},t)=>{e.handleLineActions()},yo=({engine:e,ticker:t,autoTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(t.remove(i),n.setCallback(null),n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},mo=({ticker:e,autoTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},bo=({engine:e,ticker:t,skipTimer:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS),n.getElapsed()>=30&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}))};n.setCallback(i),t.add(i)},Io=({ticker:e,skipTimer:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},wo=({engine:e,ticker:t,nextLineConfigTimerState:n},r)=>{let o=n.getCallback();o&&t.remove(o),n.setElapsed(0);let i=l=>{n.addElapsed(l.deltaMS);let a=r.delay??1e3;n.getElapsed()>=a&&(n.setElapsed(0),e.handleAction("nextLineFromSystem",{}),t.remove(i),n.setCallback(null))};n.setCallback(i),t.add(i)},vo=({ticker:e,nextLineConfigTimerState:t},n)=>{let r=t.getCallback();r&&(e.remove(r),t.setCallback(null)),t.setElapsed(0)},xo=({},e)=>{localStorage.setItem("saveSlots",JSON.stringify(e.saveSlots))},Ao=({},e)=>{localStorage.setItem("globalDeviceVariables",JSON.stringify(e.globalDeviceVariables))},_o=({},e)=>{localStorage.setItem("globalAccountVariables",JSON.stringify(e.globalAccountVariables))},Eo={render:ho,saveSlots:xo,saveGlobalDeviceVariables:Ao,saveGlobalAccountVariables:_o,handleLineActions:go,startAutoNextTimer:yo,clearAutoNextTimer:mo,startSkipNextTimer:bo,clearSkipNextTimer:Io,nextLineConfigTimer:wo,clearNextLineConfigTimer:vo},$o=({getEngine:e,routeGraphics:t,ticker:n})=>{let r=Ke(),o=Ke(),i=Ke();return async l=>{let a=e(),c=l.reduce((u,d)=>(u[d.name]=d,u),{}),s=Object.values(c),f={engine:a,routeGraphics:t,ticker:n,autoTimer:r,skipTimer:o,nextLineConfigTimerState:i};for(let u of s){let d=Eo[u.name];d&&d(f,u.payload)}}},Lo=$o;var Co=(e,t={})=>{let{resources:n={}}=t;return We(e,n)};var Ci=Je;export{Lo as createEffectsHandler,Ci as default,Co as resolveLayoutReferences};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "route-engine-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A lightweight Visual Novel engine built in JavaScript for creating interactive narrative games with branching storylines",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"coverage": "bun run vitest run --coverage",
|
|
42
42
|
"vt:sync-route-graphics": "bun scripts/sync-vt-route-graphics.js",
|
|
43
43
|
"vt:generate": "bun scripts/sync-vt-route-graphics.js && bun run esbuild.js && rtgl vt generate",
|
|
44
|
-
"vt:docker": "bun scripts/sync-vt-route-graphics.js && bun run esbuild.js && docker run --rm ${VT_DOCKER_ARGS:-} --user $(id -u):$(id -g) -e RTGL_VT_DEBUG=true -v \"$PWD:/app\" -w /app han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.0.
|
|
44
|
+
"vt:docker": "bun scripts/sync-vt-route-graphics.js && bun run esbuild.js && docker run --rm ${VT_DOCKER_ARGS:-} --user $(id -u):$(id -g) -e RTGL_VT_DEBUG=true -v \"$PWD:/app\" -w /app docker.io/han4wluc/rtgl:playwright-v1.57.0-rtgl-v1.0.10 rtgl vt screenshot --wait-event vt:ready --concurrency ${VT_DOCKER_CONCURRENCY:-2} --timeout ${VT_DOCKER_TIMEOUT:-60000}",
|
|
45
45
|
"vt:report": "bun run vt:docker && rtgl vt report",
|
|
46
46
|
"vt:accept": "rtgl vt accept",
|
|
47
47
|
"serve": "bun run esbuild.js && bunx serve -p 3004 .rettangoli/vt/_site"
|