route-engine-js 1.33.1 → 1.34.0

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.
@@ -1,2 +1,2 @@
1
- var Uc=Object.defineProperty;var Bc=(e,n)=>{for(var t in n)Uc(e,t,{get:n[t],enumerable:!0})};var oi=Symbol.for("immer-nothing"),Zo=Symbol.for("immer-draftable"),ye=Symbol.for("immer-state");function Ee(e,...n){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var bn=Object.getPrototypeOf;function ie(e){return!!e&&!!e[ye]}function nn(e){return e?ii(e)||Array.isArray(e)||!!e[Zo]||!!e.constructor?.[Zo]||ht(e)||yt(e):!1}var Gc=Object.prototype.constructor.toString();function ii(e){if(!e||typeof e!="object")return!1;let n=bn(e);if(n===null)return!0;let t=Object.hasOwnProperty.call(n,"constructor")&&n.constructor;return t===Object?!0:typeof t=="function"&&Function.toString.call(t)===Gc}function ur(e){return ie(e)||Ee(15,e),e[ye].base_}function ft(e,n){gt(e)===0?Reflect.ownKeys(e).forEach(t=>{n(t,e[t],e)}):e.forEach((t,r)=>n(r,t,e))}function gt(e){let n=e[ye];return n?n.type_:Array.isArray(e)?1:ht(e)?2:yt(e)?3:0}function or(e,n){return gt(e)===2?e.has(n):Object.prototype.hasOwnProperty.call(e,n)}function si(e,n,t){let r=gt(e);r===2?e.set(n,t):r===3?e.add(t):e[n]=t}function zc(e,n){return e===n?e!==0||1/e===1/n:e!==e&&n!==n}function ht(e){return e instanceof Map}function yt(e){return e instanceof Set}function en(e){return e.copy_||e.base_}function ir(e,n){if(ht(e))return new Map(e);if(yt(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let t=ii(e);if(n===!0||n==="class_only"&&!t){let r=Object.getOwnPropertyDescriptors(e);delete r[ye];let o=Reflect.ownKeys(r);for(let i=0;i<o.length;i++){let s=o[i],l=r[s];l.writable===!1&&(l.writable=!0,l.configurable=!0),(l.get||l.set)&&(r[s]={configurable:!0,writable:!0,enumerable:l.enumerable,value:e[s]})}return Object.create(bn(e),r)}else{let r=bn(e);if(r!==null&&t)return{...e};let o=Object.create(r);return Object.assign(o,e)}}function dr(e,n=!1){return bt(e)||ie(e)||!nn(e)||(gt(e)>1&&(e.set=e.add=e.clear=e.delete=qc),Object.freeze(e),n&&Object.entries(e).forEach(([t,r])=>dr(r,!0))),e}function qc(){Ee(2)}function bt(e){return Object.isFrozen(e)}var Yc={};function tn(e){let n=Yc[e];return n||Ee(0,e),n}var Ln;function ai(){return Ln}function Hc(e,n){return{drafts_:[],parent_:e,immer_:n,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function ei(e,n){n&&(tn("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=n)}function sr(e){ar(e),e.drafts_.forEach(Wc),e.drafts_=null}function ar(e){e===Ln&&(Ln=e.parent_)}function ni(e){return Ln=Hc(Ln,e)}function Wc(e){let n=e[ye];n.type_===0||n.type_===1?n.revoke_():n.revoked_=!0}function ti(e,n){n.unfinalizedDrafts_=n.drafts_.length;let t=n.drafts_[0];return e!==void 0&&e!==t?(t[ye].modified_&&(sr(n),Ee(4)),nn(e)&&(e=pt(n,e),n.parent_||mt(n,e)),n.patches_&&tn("Patches").generateReplacementPatches_(t[ye].base_,e,n.patches_,n.inversePatches_)):e=pt(n,t,[]),sr(n),n.patches_&&n.patchListener_(n.patches_,n.inversePatches_),e!==oi?e:void 0}function pt(e,n,t){if(bt(n))return n;let r=n[ye];if(!r)return ft(n,(o,i)=>ri(e,r,n,o,i,t)),n;if(r.scope_!==e)return n;if(!r.modified_)return mt(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;let o=r.copy_,i=o,s=!1;r.type_===3&&(i=new Set(o),o.clear(),s=!0),ft(i,(l,a)=>ri(e,r,o,l,a,t,s)),mt(e,o,!1),t&&e.patches_&&tn("Patches").generatePatches_(r,t,e.patches_,e.inversePatches_)}return r.copy_}function ri(e,n,t,r,o,i,s){if(ie(o)){let l=i&&n&&n.type_!==3&&!or(n.assigned_,r)?i.concat(r):void 0,a=pt(e,o,l);if(si(t,r,a),ie(a))e.canAutoFreeze_=!1;else return}else s&&t.add(o);if(nn(o)&&!bt(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;pt(e,o),(!n||!n.scope_.parent_)&&typeof r!="symbol"&&Object.prototype.propertyIsEnumerable.call(t,r)&&mt(e,o)}}function mt(e,n,t=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&dr(n,t)}function Kc(e,n){let t=Array.isArray(e),r={type_:t?1:0,scope_:n?n.scope_:ai(),modified_:!1,finalized_:!1,assigned_:{},parent_:n,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=r,i=fr;t&&(o=[r],i=Pn);let{revoke:s,proxy:l}=Proxy.revocable(o,i);return r.draft_=l,r.revoke_=s,l}var fr={get(e,n){if(n===ye)return e;let t=en(e);if(!or(t,n))return Jc(e,t,n);let r=t[n];return e.finalized_||!nn(r)?r:r===tr(e.base_,n)?(rr(e),e.copy_[n]=lr(r,e)):r},has(e,n){return n in en(e)},ownKeys(e){return Reflect.ownKeys(en(e))},set(e,n,t){let r=ci(en(e),n);if(r?.set)return r.set.call(e.draft_,t),!0;if(!e.modified_){let o=tr(en(e),n),i=o?.[ye];if(i&&i.base_===t)return e.copy_[n]=t,e.assigned_[n]=!1,!0;if(zc(t,o)&&(t!==void 0||or(e.base_,n)))return!0;rr(e),cr(e)}return e.copy_[n]===t&&(t!==void 0||n in e.copy_)||Number.isNaN(t)&&Number.isNaN(e.copy_[n])||(e.copy_[n]=t,e.assigned_[n]=!0),!0},deleteProperty(e,n){return tr(e.base_,n)!==void 0||n in e.base_?(e.assigned_[n]=!1,rr(e),cr(e)):delete e.assigned_[n],e.copy_&&delete e.copy_[n],!0},getOwnPropertyDescriptor(e,n){let t=en(e),r=Reflect.getOwnPropertyDescriptor(t,n);return r&&{writable:!0,configurable:e.type_!==1||n!=="length",enumerable:r.enumerable,value:t[n]}},defineProperty(){Ee(11)},getPrototypeOf(e){return bn(e.base_)},setPrototypeOf(){Ee(12)}},Pn={};ft(fr,(e,n)=>{Pn[e]=function(){return arguments[0]=arguments[0][0],n.apply(this,arguments)}});Pn.deleteProperty=function(e,n){return Pn.set.call(this,e,n,void 0)};Pn.set=function(e,n,t){return fr.set.call(this,e[0],n,t,e[0])};function tr(e,n){let t=e[ye];return(t?en(t):e)[n]}function Jc(e,n,t){let r=ci(n,t);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}function ci(e,n){if(!(n in e))return;let t=bn(e);for(;t;){let r=Object.getOwnPropertyDescriptor(t,n);if(r)return r;t=bn(t)}}function cr(e){e.modified_||(e.modified_=!0,e.parent_&&cr(e.parent_))}function rr(e){e.copy_||(e.copy_=ir(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Xc=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(n,t,r)=>{if(typeof n=="function"&&typeof t!="function"){let i=t;t=n;let s=this;return function(a=i,...c){return s.produce(a,u=>t.call(this,u,...c))}}typeof t!="function"&&Ee(6),r!==void 0&&typeof r!="function"&&Ee(7);let o;if(nn(n)){let i=ni(this),s=lr(n,void 0),l=!0;try{o=t(s),l=!1}finally{l?sr(i):ar(i)}return ei(i,r),ti(o,i)}else if(!n||typeof n!="object"){if(o=t(n),o===void 0&&(o=n),o===oi&&(o=void 0),this.autoFreeze_&&dr(o,!0),r){let i=[],s=[];tn("Patches").generateReplacementPatches_(n,o,i,s),r(i,s)}return o}else Ee(1,n)},this.produceWithPatches=(n,t)=>{if(typeof n=="function")return(s,...l)=>this.produceWithPatches(s,a=>n(a,...l));let r,o;return[this.produce(n,t,(s,l)=>{r=s,o=l}),r,o]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){nn(e)||Ee(8),ie(e)&&(e=Ue(e));let n=ni(this),t=lr(e,void 0);return t[ye].isManual_=!0,ar(n),t}finishDraft(e,n){let t=e&&e[ye];(!t||!t.isManual_)&&Ee(9);let{scope_:r}=t;return ei(r,n),ti(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,n){let t;for(t=n.length-1;t>=0;t--){let o=n[t];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}t>-1&&(n=n.slice(t+1));let r=tn("Patches").applyPatches_;return ie(e)?r(e,n):this.produce(e,o=>r(o,n))}};function lr(e,n){let t=ht(e)?tn("MapSet").proxyMap_(e,n):yt(e)?tn("MapSet").proxySet_(e,n):Kc(e,n);return(n?n.scope_:ai()).drafts_.push(t),t}function Ue(e){return ie(e)||Ee(10,e),li(e)}function li(e){if(!nn(e)||bt(e))return e;let n=e[ye],t;if(n){if(!n.modified_)return n.base_;n.finalized_=!0,t=ir(e,n.scope_.immer_.useStrictShallowCopy_)}else t=ir(e,!0);return ft(t,(r,o)=>{si(t,r,li(o))}),n&&(n.finalized_=!1),t}var we=new Xc,pr=we.produce,Eh=we.produceWithPatches.bind(we),xh=we.setAutoFreeze.bind(we),vh=we.setUseStrictShallowCopy.bind(we),Sh=we.applyPatches.bind(we),Rh=we.createDraft.bind(we),Ch=we.finishDraft.bind(we);var y={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},M={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},In={NOT:0};var R=class extends Error{constructor(n){super(`Parse Error: ${n}`),this.name="JemplParseError"}},pe=class extends Error{constructor(n){super(`Render Error: ${n}`),this.name="JemplRenderError"}};var mr=e=>{if(!e||e.trim()==="")throw new R("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let t=e.includes("===")?"==":"!=";throw new R(`Invalid comparison operator '${e.includes("===")?"===":"!=="}' - did you mean '${t}'? (got: '${e}')`)}let n=["<",">","<=",">=","==","!="];for(let t of n)if(e.trim().endsWith(t))throw new R(`Incomplete comparison expression - missing right operand (got: '${e}')`)},ui=e=>{if(e.trim().endsWith(" in"))throw new R(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new R(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[n,t]=e.split(" in ");if(!t||t.trim()==="")throw new R(`Missing iterable expression after 'in' (got: '$for ${e}')`);let r=n.includes(",")?n.split(",").map(o=>o.trim()):[n.trim()];for(let o of r){if(!o)throw new R(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(o))throw new R(`Invalid loop syntax (got: '$for ${e}')`)}};var di=(e,n,t=!1)=>{if(n===null)return new pe(`Cannot iterate over null value at '$for ${e}'`);if(n===void 0)return new pe(`Cannot iterate over undefined value at '$for ${e}'`);let r=typeof n;return t?new pe(`Cannot iterate over non-array value in loop '${e}' - got ${r} instead`):new pe(`Cannot iterate over non-array value (got: ${r}) at '$for ${e}'`)},fi=(e,n)=>{let t=n&&Object.keys(n).length>0?Object.keys(n).join(", "):"no custom functions provided";return new pe(`Unknown function '${e}' (${t})`)};var Qc=(e,n,t={})=>{let r={},o={};t&&typeof t=="object"&&(t.functions!==void 0||t.partials!==void 0?(r=t.functions||{},o=t.partials||{}):typeof t=="object"&&(r=t));let s=V(e,{functions:r,partials:o},n,{});return s===void 0?{}:s},V=(e,n,t,r)=>{let o=n.functions||n;if(e.var&&!e.type)return ee(e.var,t,r);if(e.type===y.LITERAL)return e.value;if(e.type===y.VARIABLE)return ee(e.path,t,r);if(e.type===y.INTERPOLATION)return el(e.parts,n,t,r);switch(e.type){case y.FUNCTION:return mi(e,n,t,r);case y.BINARY:return gi(e,n,t,r);case y.UNARY:return hi(e,n,t,r);case y.CONDITIONAL:return tl(e,n,t,r);case y.LOOP:return al(e,n,t,r);case y.OBJECT:return ll(e,n,t,r);case y.ARRAY:return ul(e,n,t,r);case y.PARTIAL:return dl(e,n,t,r);case y.PATH_REFERENCE:return fl(e,n,t,r);default:throw new Error(`Unknown node type: ${e.type}`)}},pi=new Map,Zc=e=>{let n=[],t="",r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(i==="[")t&&(n.push({type:"property",value:t}),t=""),r=!0;else if(i==="]"){if(r&&t){let s=t.trim();if(/^\d+$/.test(s))n.push({type:"index",value:parseInt(s,10)});else if(s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'")){let l=s.slice(1,-1);n.push({type:"property",value:l})}else n.push({type:"property",value:s});t=""}r=!1}else t+=i}return t&&n.push({type:"property",value:t}),n},ee=(e,n,t)=>{if(!e)return;if(e in t)return t[e];let r=pi.get(e);if(!r){let i=[],s="",l=0;for(let a=0;a<e.length;a++){let c=e[a];c==="["?(l++,s+=c):c==="]"?(l--,s+=c):c==="."&&l===0?s&&(i.push(s),s=""):s+=c}s&&i.push(s),r=[];for(let a of i){let c=Zc(a.trim());r.push(...c)}pi.set(e,r)}let o=n;for(let i=0;i<r.length;i++){let s=r[i];if(s.type==="property"&&s.value in t){o=t[s.value];continue}if(o==null)return;(s.type==="property"||s.type==="index")&&(o=o[s.value])}return o},el=(e,n,t,r)=>{let o=[];for(let i of e)if(typeof i=="string")o.push(i);else{let s=V(i,n,t,r);o.push(s!=null?String(s):"")}return o.join("")},mi=(e,n,t,r)=>{let o=n.functions||n,i=o[e.name];if(!i)throw fi(e.name,o);let s=e.args.map(l=>V(l,n,t,r));return i(...s)},Be=(e,n,t,r)=>{if(e.var&&!e.type)return ee(e.var,t,r);switch(e.type){case y.VARIABLE:return ee(e.path,t,r);case y.LITERAL:return e.value;case y.BINARY:return gi(e,n,t,r);case y.UNARY:return hi(e,n,t,r);case y.FUNCTION:return mi(e,n,t,r);default:return V(e,n,t,r)}},gi=(e,n,t,r)=>{if(e.op===M.AND||e.op===M.OR){let s=Be(e.left,n,t,r),l=Be(e.right,n,t,r);switch(e.op){case M.AND:return s&&l;case M.OR:return s||l}}let o=V(e.left,n,t,r),i=V(e.right,n,t,r);switch(e.op){case M.EQ:return o==i;case M.NEQ:return o!=i;case M.GT:return o>i;case M.LT:return o<i;case M.GTE:return o>=i;case M.LTE:return o<=i;case M.IN:return Array.isArray(i)?i.includes(o):!1;case M.ADD:if(typeof o!="number"||typeof i!="number")throw new pe(`Arithmetic operations require numbers. Got ${typeof o} + ${typeof i}`);return o+i;case M.SUBTRACT:if(typeof o!="number"||typeof i!="number")throw new pe(`Arithmetic operations require numbers. Got ${typeof o} - ${typeof i}`);return o-i;default:throw new Error(`Unknown binary operator: ${e.op}`)}},hi=(e,n,t,r)=>{let o=e.op===In.NOT?Be(e.operand,n,t,r):V(e.operand,n,t,r);if(e.op===In.NOT)return!o;throw new Error(`Unknown unary operator: ${e.op}`)},nl=(e,n,t,r)=>{if(e.conditions.length===2&&e.conditions[1]===null){let o=e.conditions[0];if(o.type===y.VARIABLE)if(ee(o.path,t,r)){let s=e.bodies[0];if(s.type===y.OBJECT&&s.properties.length<=5){let l={};for(let a of s.properties){let c=a.parsedKey?V(a.parsedKey,n,t,r):a.key,u=a.value;if(u.type===y.LITERAL)l[c]=u.value;else if(u.type===y.VARIABLE)l[c]=ee(u.path,t,r);else if(u.type===y.INTERPOLATION){let d=[];for(let f of u.parts)if(typeof f=="string")d.push(f);else if(f.type===y.VARIABLE){let p=ee(f.path,t,r);d.push(p!=null?String(p):"")}else{let p=V(f,n,t,r);d.push(p!=null?String(p):"")}l[c]=d.join("")}else l[c]=V(u,n,t,r)}return l}}else{let s=e.bodies[1];if(s.type===y.OBJECT&&s.properties.length<=5){let l={};for(let a of s.properties){let c=a.parsedKey?V(a.parsedKey,n,t,r):a.key,u=a.value;if(u.type===y.LITERAL)l[c]=u.value;else if(u.type===y.VARIABLE)l[c]=ee(u.path,t,r);else if(u.type===y.INTERPOLATION){let d=[];for(let f of u.parts)if(typeof f=="string")d.push(f);else if(f.type===y.VARIABLE){let p=ee(f.path,t,r);d.push(p!=null?String(p):"")}else{let p=V(f,n,t,r);d.push(p!=null?String(p):"")}l[c]=d.join("")}else l[c]=V(u,n,t,r)}return l}}}return null},tl=(e,n,t,r)=>{let o=nl(e,n,t,r);if(o!==null)return o;for(let i=0;i<e.conditions.length;i++){let s=e.conditions[i];if(s===null||Be(s,n,t,r))return V(e.bodies[i],n,t,r)}return yi},rl=(e,n)=>{let t=e.body,r=e.itemVar;if(t.type===y.CONDITIONAL&&t.conditions.length===1&&t.conditions[0].type===y.VARIABLE){let o=t.conditions[0].path,i=t.bodies[0];if(o.startsWith(r+".")){let s=o.substring(r.length+1);if(i.type===y.OBJECT&&i.properties.length<=5){for(let a of i.properties)if(a.parsedKey)return null;let l=[];for(let a=0;a<n.length;a++){let c=n[a];if(c[s]){let u={};for(let d of i.properties){let f=d.key,p=d.value;if(p.type===y.LITERAL)u[f]=p.value;else if(p.type===y.VARIABLE){let g=p.path;if(g===r)u[f]=c;else if(g.startsWith(r+".")){let h=g.substring(r.length+1);u[f]=c[h]}else return null}else if(p.type===y.INTERPOLATION){let g=[],h=!0;for(let b of p.parts)if(typeof b=="string")g.push(b);else if(b.type===y.VARIABLE){let I=b.path;if(I===r)g.push(c!=null?String(c):"");else if(I.startsWith(r+".")){let E=I.substring(r.length+1),A=c[E];g.push(A!=null?String(A):"")}else{h=!1;break}}else{h=!1;break}if(!h)return null;u[f]=g.join("")}else return null}l.push(u)}}return l}}}return null},ol=(e,n)=>{let t=e.body,r=e.itemVar,o=rl(e,n);if(o!==null)return o;if(t.type===y.OBJECT&&t.properties.length<=5&&!t.whenCondition){for(let l of t.properties)if(l.parsedKey)return null;let i=[],s=!0;for(let l of t.properties){let a=l.key,c=l.value;if(c.type===y.LITERAL)i.push({key:a,type:"literal",value:c.value});else if(c.type===y.VARIABLE){let u=c.path;if(u===r)i.push({key:a,type:"item"});else if(u.startsWith(r+".")){let d=u.substring(r.length+1);if(!d.includes(".")&&!d.includes("["))i.push({key:a,type:"prop",prop:d});else{s=!1;break}}else{s=!1;break}}else if(c.type===y.INTERPOLATION&&c.parts.length===1){let u=c.parts[0];if(u.type===y.VARIABLE){let d=u.path;if(d===r)i.push({key:a,type:"item_string"});else if(d.startsWith(r+".")){let f=d.substring(r.length+1);if(!f.includes(".")&&!f.includes("["))i.push({key:a,type:"prop_string",prop:f});else{s=!1;break}}else{s=!1;break}}else{s=!1;break}}else{s=!1;break}}if(s){let l=new Array(n.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 a=0;a<n.length;a++){let c=n[a];l[a]={id:c.id,title:c.title!=null?String(c.title):"",completed:c.completed}}else for(let a=0;a<n.length;a++){let c=n[a],u={};for(let d of i)if(d.type==="literal")u[d.key]=d.value;else if(d.type==="item")u[d.key]=c;else if(d.type==="prop")u[d.key]=c[d.prop];else if(d.type==="item_string")u[d.key]=c!=null?String(c):"";else if(d.type==="prop_string"){let f=c[d.prop];u[d.key]=f!=null?String(f):""}l[a]=u}return l}}return null},il=(e,n,t,r,o)=>{let i=[],s=e.body;if(s.type===y.OBJECT&&s.fast!==!1){let l=e.itemVar,a=e.indexVar;for(let c=0;c<o.length;c++){let u=o[c],d={},f={...r,[l]:u,...a&&{[a]:c}};f.__paths__||(f.__paths__=r.__paths__||{});let p=e.iterable.path||"";if(r&&r.__paths__&&p){let g=p.split("."),h=g[0];h in r.__paths__&&(p=r.__paths__[h],g.length>1&&(p+="."+g.slice(1).join(".")))}f.__paths__={...f.__paths__,[l]:`${p}[${c}]`,...a&&{[a]:c}};for(let g of s.properties){let h=g.parsedKey?V(g.parsedKey,n,t,f):g.key,b=g.value;if(b.type===y.LITERAL)d[h]=b.value;else if(b.type===y.VARIABLE){let I=b.path;if(I===l)d[h]=u;else if(I===a)d[h]=c;else if(I.startsWith(l+".")){let E=I.substring(l.length+1);!E.includes(".")&&!E.includes("[")?d[h]=u[E]:d[h]=ee(I,t,{...r,[l]:u,...a&&{[a]:c}})}else d[h]=ee(I,t,{...r,[l]:u,...a&&{[a]:c}})}else if(b.type===y.INTERPOLATION){let I=[];for(let E of b.parts)if(typeof E=="string")I.push(E);else if(E.type===y.VARIABLE){let A=E.path,$;if(A===l)$=u;else if(A===a)$=c;else if(A.startsWith(l+".")){let B=A.substring(l.length+1);!B.includes(".")&&!B.includes("[")?$=u[B]:$=ee(A,t,{...r,[l]:u,...a&&{[a]:c}})}else $=ee(A,t,{...r,[l]:u,...a&&{[a]:c}});I.push($!=null?String($):"")}else{let A={...r,[l]:u,...a&&{[a]:c}},$=V(E,n,t,A);I.push($!=null?String($):"")}d[h]=I.join("")}else{let I={...r,[l]:u,...a&&{[a]:c}};d[h]=V(b,n,t,I)}}i.push(d)}return i}return null},sl=(e,n,t)=>{let r=e.body;if(r.type===y.OBJECT&&r.properties.length===1&&r.properties[0].key==="$if item.visible"){let i=r.properties[0].value;if(i.type===y.CONDITIONAL&&i.conditions.length===1&&i.conditions[0].type===y.VARIABLE&&i.conditions[0].path==="item.visible"){let s=i.bodies[0];if(s.type===y.OBJECT&&s.properties.length===2){let l=s.properties[0],a=s.properties[1];if(l.key==="id"&&l.value.type===y.VARIABLE&&l.value.path==="item.id"&&a.key==="$if item.highlighted"&&a.value.type===y.CONDITIONAL){let c=[];for(let u=0;u<n.length;u++){let d=n[u];if(d.visible){let f={id:d.id};d.highlighted?(f.highlight=!0,f.message=`This item is highlighted: ${d.name}`):(f.highlight=!1,f.message=d.name),c.push(f)}}return c}}}}return null},al=(e,n,t,r)=>{let o=V(e.iterable,n,t,r);if(!Array.isArray(o)){let c,u=!1;if(e.iterable.type===y.FUNCTION){u=!0;let f=e.iterable.args.map(p=>p.type===y.LITERAL?typeof p.value=="string"?`'${p.value}'`:String(p.value):p.type===y.VARIABLE?p.path:p.type===y.FUNCTION?`${p.name}(...)`:"?").join(", ");c=`${e.iterable.name}(${f})`}else c=e.iterable.path||"undefined";let d=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${c}`;throw di(d,o,u)}if(!e.indexVar){let c=sl(e,o,e.itemVar);if(c!==null)return c}if(!e.indexVar){let c=ol(e,o);if(c!==null)return c}let i=il(e,n,t,r,o);if(i!==null)return i;let s=[],l=e.iterable.path||"";if(r&&r.__paths__&&l){let c=l.split("."),u=c[0];u in r.__paths__&&(l=r.__paths__[u],c.length>1&&(l+="."+c.slice(1).join(".")))}let a=!1;e.body.type===y.ARRAY&&(e.body.items.length<=1?a=!1:a=e.body._shouldPreserveArray??=e.body.items.some(c=>c.type===y.OBJECT&&c.properties.some(u=>u.key.startsWith("$if ")||u.key.startsWith("$when "))));for(let c=0;c<o.length;c++){let u=e.indexVar?{...r,[e.itemVar]:o[c],[e.indexVar]:c}:{...r,[e.itemVar]:o[c]};u.__paths__||(u.__paths__=r.__paths__||{}),u.__paths__={...u.__paths__,[e.itemVar]:`${l}[${c}]`},e.indexVar&&(u.__paths__[e.indexVar]=c);let d=V(e.body,n,t,u);if(Array.isArray(d)&&d.length===1&&!a){let f=d[0];s.push(f===void 0?{}:f)}else s.push(d===void 0?{}:d)}return s},cl=(e,n,t,r)=>{if(e.whenCondition)return null;if(e.properties.length===1){let o=e.properties[0],i=o.parsedKey?V(o.parsedKey,n,t,r):o.key,s=o.value;if(s.type===y.OBJECT&&s.properties.length<=10&&!s.whenCondition){let l={},a={},c=!0;for(let u of s.properties){let d=u.parsedKey?V(u.parsedKey,n,t,r):u.key,f=u.value;if(f.type===y.LITERAL)a[d]=f.value;else if(f.type===y.VARIABLE)a[d]=ee(f.path,t,r);else if(f.type===y.INTERPOLATION){let p=[];for(let g of f.parts)if(typeof g=="string")p.push(g);else if(g.type===y.VARIABLE){let h=ee(g.path,t,r);p.push(h!=null?String(h):"")}else{c=!1;break}if(!c)break;a[d]=p.join("")}else if(f.type===y.OBJECT&&f.properties.length<=5){let p={};for(let g of f.properties){let h=g.key,b=g.value;if(b.type===y.LITERAL)p[h]=b.value;else if(b.type===y.VARIABLE)p[h]=ee(b.path,t,r);else if(b.type===y.INTERPOLATION){let I=[];for(let E of b.parts)if(typeof E=="string")I.push(E);else if(E.type===y.VARIABLE){let A=ee(E.path,t,r);I.push(A!=null?String(A):"")}else{c=!1;break}if(!c)break;p[h]=I.join("")}else{c=!1;break}}if(!c)break;a[d]=p}else{c=!1;break}}if(c)return l[i]=a,l}}return null},ll=(e,n,t,r)=>{let o=n.functions||n;if(e.whenCondition&&!Be(e.whenCondition,o,t,r))return;let i=cl(e,n,t,r);if(i!==null)return i;if(e.fast){let c={};for(let u of e.properties){let d=u.parsedKey?V(u.parsedKey,n,t,r):u.key,f=u.value;if(f.type===y.LITERAL)c[d]=f.value;else if(f.type===y.VARIABLE)c[d]=ee(f.path,t,r);else if(f.type===y.INTERPOLATION){let p=[];for(let g of f.parts)if(typeof g=="string")p.push(g);else if(g.type===y.VARIABLE){let h=ee(g.path,t,r);p.push(h!=null?String(h):"")}else{let h=V(g,n,t,r);p.push(h!=null?String(h):"")}c[d]=p.join("")}else c[d]=V(f,n,t,r)}return c}let s={},l=null,a=!1;for(let c of e.properties)if(!c.key.startsWith("$if ")&&!c.key.match(/^\$if\s+\w+.*:?$/)&&!c.key.startsWith("$elif")&&!c.key.startsWith("$else")&&!c.key.startsWith("$for ")){a=!0;break}for(let c of e.properties)if(c.key.startsWith("$if ")||c.key.match(/^\$if\s+\w+.*:?$/)){let u=V(c.value,n,t,r);if(!a&&u!==null&&u!==void 0)return Array.isArray(u)&&u.length===1?u[0]:u;typeof u=="object"&&u!==null&&!Array.isArray(u)&&Object.assign(s,u)}else if(c.key.startsWith("$for ")){if(e.properties.length===1)return V(c.value,n,t,r)}else{let u=c.value;if(u&&u.type===y.OBJECT&&u.properties){let d=u.properties.find(f=>f.key.startsWith("$for "));if(d){let f=V(d.value,n,t,r);f!==void 0&&(s[c.key]=f)}else{let f=V(c.value,n,t,r);f!==void 0&&(s[c.key]=f)}}else{let d=c.parsedKey?V(c.parsedKey,n,t,r):c.key,f=V(c.value,n,t,r);f!==void 0&&(s[d]=f)}}return s},yi={},ul=(e,n,t,r)=>{let o=[];for(let i of e.items)if(i.type===y.LOOP){let s=V(i,n,t,r);Array.isArray(s)&&i.flatten!==!1?o.push(...s):o.push(s)}else{let s=V(i,n,t,r);s!==yi&&s!==void 0&&o.push(s)}return o},dl=(e,n,t,r)=>{let{name:o,data:i,whenCondition:s}=e,l=n.partials||{},a=n.functions||n;if(s&&!Be(s,a,t,r))return;if(!l[o])throw new pe(`Partial '${o}' is not defined`);let c=r._partialStack||[];if(c.includes(o))throw new pe(`Circular partial reference detected: ${o}`);let u=l[o],d=t,f={...r,_partialStack:[...c,o]};if(r){d={...t};for(let p of Object.keys(r))p.startsWith("_")||(d[p]=r[p])}if(i){let p=V(i,n,t,r);d={...d,...p}}return V(u,n,d,f)},fl=(e,n,t,r)=>{let{path:o}=e,i=o.split("."),s=i[0],l=i.slice(1);if(!r||!(s in r))throw new pe(`Path reference '#{${o}}' refers to '${s}' which is not a loop variable in the current scope`);if(r.__paths__||(r.__paths__={}),!(s in r.__paths__))throw new pe(`Path reference '#{${o}}' cannot be resolved - path tracking may not be initialized properly`);let a=r.__paths__[s];if(typeof a=="number"){if(l.length>0)throw new pe(`Path reference '#{${o}}' - cannot access properties on index variable '${s}'`);return String(a)}return l.length>0&&(a+="."+l.join(".")),a};var gr=Qc;var pl=/\$\{([^}]*)\}/g,ml=/#\{([^}]*)\}/g,Ii=(e,n={})=>{let t=e.match(/^(\w+)\((.*)\)$/);if(!t)return{isFunction:!1};let[,r,o]=t,i=gl(o,n);return{isFunction:!0,type:y.FUNCTION,name:r,args:i}},gl=(e,n={})=>e.trim()?hl(e).map(r=>yl(r.trim(),n)):[],hl=e=>{let n=[],t="",r=0,o=!1,i="";for(let s=0;s<e.length;s++){let l=e[s],a=s>0?e[s-1]:"";!o&&(l==='"'||l==="'")?(o=!0,i=l,t+=l):o&&l===i&&a!=="\\"?(o=!1,i="",t+=l):!o&&l==="("?(r++,t+=l):!o&&l===")"?(r--,t+=l):!o&&l===","&&r===0?(n.push(t),t=""):t+=l}return t&&n.push(t),n},yl=(e,n={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:y.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:y.LITERAL,value:parseFloat(e)};if(e==="true")return{type:y.LITERAL,value:!0};if(e==="false")return{type:y.LITERAL,value:!1};if(e==="null")return{type:y.LITERAL,value:null};let t=Ii(e,n);if(t.isFunction)return{type:t.type,name:t.name,args:t.args};let r=e.trim(),o=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],i=-1,s=null;for(let{op:l,type:a}of o){let c=0;for(;c<r.length;){let u=rn(r.substring(c),l);if(u===-1)break;let d=c+u;d>i&&(i=d,s={op:l,type:a}),c=d+l.length}}if(i!==-1)try{return re(r,n)}catch{return{type:y.VARIABLE,path:r}}return{type:y.VARIABLE,path:r}},wi=/^\w+\(.*\)$/,bl=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,Il=e=>{if(!(!e||e.trim()===""||wi.test(e))&&bl.test(e))throw e.includes("?")&&e.includes(":")?new R(`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 R(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new R(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},bi=e=>{let n=e.trim();if(wi.test(n))throw new R(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(n.includes("["))throw new R(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(n))throw new R(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(n))throw new R(`Logical operators not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(n.includes("?")&&n.includes(":"))throw new R(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:y.PATH_REFERENCE,path:n}},Nn=(e,n={})=>{let t=e.trim();Il(t);let r=Ii(t,n);if(r.isFunction)return{type:r.type,name:r.name,args:r.args};if(t.includes("[")&&!/[\s+\-*/%|&?:]/.test(t)){let o=0;for(let i of t)i==="["?o++:i==="]"&&o--;if(o!==0)throw new Error("Invalid array index syntax")}return{type:y.VARIABLE,path:t}},hr=(e,n={})=>{let t=e,r=[];(e.includes("\\${")||e.includes("\\#{"))&&(t=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC_VAR$1"),t=t.replace(/\\\\(#\{[^}]*\})/g,"\\DOUBLE_ESC_PATH$1"),t=t.replace(/\\(\$\{[^}]*\})/g,(c,u)=>{let d=`__ESCAPED_${r.length}__`;return r.push(u),d}),t=t.replace(/\\(#\{[^}]*\})/g,(c,u)=>{let d=`__ESCAPED_${r.length}__`;return r.push(u),d}),t=t.replace(/\\DOUBLE_ESC_VAR/g,"\\"),t=t.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let o=[...t.matchAll(pl)],i=[...t.matchAll(ml)],s=[...o.map(c=>({match:c,type:"variable"})),...i.map(c=>({match:c,type:"pathref"}))].sort((c,u)=>c.match.index-u.match.index);if(s.length===0){let c=t;for(let u=0;u<r.length;u++)c=c.replace(`__ESCAPED_${u}__`,r[u]);return{type:y.LITERAL,value:c}}if(s.length===1&&s[0].match[0]===t&&r.length===0){let{match:c,type:u}=s[0];try{return u==="variable"?Nn(c[1],n):bi(c[1])}catch(d){if(d.message==="Invalid array index syntax")return{type:y.LITERAL,value:t};throw d}}let l=[],a=0;for(let{match:c,type:u}of s){let[d,f]=c,p=c.index;if(p>a){let g=t.substring(a,p);for(let h=0;h<r.length;h++)g=g.replace(`__ESCAPED_${h}__`,r[h]);g&&l.push(g)}try{let g;u==="variable"?g=Nn(f.trim(),n):g=bi(f.trim()),l.push(g)}catch(g){if(g.message==="Invalid array index syntax")l.push(d);else throw g}a=p+d.length}if(a<t.length){let c=t.substring(a);for(let u=0;u<r.length;u++)c=c.replace(`__ESCAPED_${u}__`,r[u]);c&&l.push(c)}return{type:y.INTERPOLATION,parts:l}};var Ir=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),xi=e=>Object.keys(e),ue=e=>e.join("."),Ge=(e,n,t)=>{let r=xi(e).filter(o=>!n.has(o));if(r.length>0)throw new R(`Unexpected key '${r[0]}' in condition JSON at '${ue(t)}'`)},ze=(e,n)=>typeof e=="string"?hr(e,n):typeof e=="object"&&e!==null?Array.isArray(e)?Al(e,n):El(e,n):{type:y.LITERAL,value:e},wl=e=>{let{$each:n,...t}=e;if(typeof n!="string")throw new R("$each value must be a non-empty string");let r=n.trim();if(r==="")throw new R("$each value must be a non-empty string");if(Object.keys(t).length===0)throw new R("Empty $each body not allowed");if(t.$partial!==void 0)throw new R("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${r}`]:t}},Al=(e,n)=>{let t=[],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 a=wl(i),c=Object.keys(a);if(c.length===1&&/^\$for(?::\w+)?\s/.test(c[0])){let u=Ei(c[0],a[c[0]],n,!0);t.push(u),r=!0;continue}}catch(a){throw a instanceof R?a:new R(a.message)}let l=Object.keys(i);if(l.length===1&&/^\$for(?::\w+)?\s/.test(l[0])){let a=Ei(l[0],i[l[0]],n);t.push(a),r=!0;continue}}let s=ze(i,n);t.push(s),(s.type===y.FUNCTION||s.type===y.CONDITIONAL||s.type===y.LOOP||s.type===y.PARTIAL||s.type===y.OBJECT&&!s.fast||s.type===y.ARRAY&&!s.fast)&&(r=!0)}return{type:y.ARRAY,items:t,fast:!r}},El=(e,n)=>{let t=[],r=!1,o=null,i=Object.entries(e),s=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new R("$partial value must be a string");if(e.$partial.trim()==="")throw new R("$partial value cannot be an empty string");let a=["$if","$elif","$else","$for"],c=[];for(let[I]of i)for(let E of a)if(I===E||I.startsWith(E+" ")||I.startsWith(E+"#")){c.push(E);break}if(c.length>0)throw new R(`Cannot use $partial with ${c.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:u,$when:d,...f}=e,p={},g=!1;for(let[I,E]of Object.entries(f)){let A=I;(I.startsWith("\\$")||I.startsWith("$$"))&&(A=I.slice(1)),p[A]=E,g=!0}let h=null;if(g&&(h=ze(p,n),h.type===y.OBJECT)){let I=!1;for(let E of h.properties)if(E.value.type===y.VARIABLE||E.value.type===y.INTERPOLATION||E.value.type===y.FUNCTION||E.value.type===y.CONDITIONAL||E.value.type===y.OBJECT&&!E.value.fast||E.value.type===y.ARRAY&&!E.value.fast){I=!0;break}I&&(h.fast=!1)}let b={type:y.PARTIAL,name:u,data:h};return d!==void 0&&(b.whenCondition=Ai(d,n)),b}for(let[a,c]of i)if(a==="$when"){if(o!==null)throw new R("Multiple '$when' directives on the same object are not allowed");if(c==null)throw new R("Missing condition expression after '$when'");o=Ai(c,n),r=!0}else if(a.startsWith("$when#")||a.startsWith("$when "))throw new R("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;s<i.length;){let[a,c]=i[s];if(a==="$when"){s++;continue}if(a==="$each")throw new R("$each can only be used inside arrays");if(a.startsWith("$if ")||a.match(/^\$if#\w+\s/)||a.match(/^\$if\s+\w+.*:$/)){let u=xl(i,s,n);t.push({key:a,value:u.node}),r=!0,s=u.nextIndex}else if(/^\$for(?::\w+)?\s/.test(a)){let u=a.match(/^\$for(?::(\w+))?\s/)?.[1]||"",d=u?`:${u}`:"";throw new R(`$for loops must be inside arrays - use '- $for${d} item in items:' instead of '$for${d} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(a.startsWith("$elif ")||a.startsWith("$else"))throw new R(`'${a.split(" ")[0]}' without matching '$if'`);if(a==="$if"||a==="$if:")throw new R("Missing condition expression after '$if'");{let u=ze(c,n);(u.type===y.FUNCTION||u.type===y.CONDITIONAL||u.type===y.PARTIAL||u.type===y.OBJECT&&!u.fast||u.type===y.ARRAY&&!u.fast)&&(r=!0);let d=hr(a,n),f={key:a,value:u};(d.type!==y.LITERAL||d.value!==a)&&(f.parsedKey=d),t.push(f),s++}}}let l={type:y.OBJECT,properties:t,fast:!r};return o&&(l.whenCondition=o),l},xl=(e,n,t={})=>{let r=[],o=[],i=n,[s,l]=e[i],a=null,c;if(s.startsWith("$if#")){let d=s.match(/^\$if#(\w+)\s+(.+)$/);if(d)a=d[1],c=d[2];else throw new R(`Invalid conditional syntax: ${s}`)}else c=s.substring(4),c.endsWith(":")&&(c=c.slice(0,-1).trim());mr(c);let u=re(c,t);for(r.push(u),o.push(ze(l,t)),i++;i<e.length;){let[d,f]=e[i],p=!1,g;if(a?d.startsWith(`$elif#${a} `)?(g=d.substring(`$elif#${a} `.length),g.endsWith(":")&&(g=g.slice(0,-1).trim()),p=!0):(d===`$else#${a}`||d===`$else#${a}:`)&&(p=!0,g=null):d.startsWith("$elif ")?(g=d.substring(6),g.endsWith(":")&&(g=g.slice(0,-1).trim()),p=!0):(d==="$else"||d==="$else:")&&(p=!0,g=null),p){if(g===null)r.push(null);else{mr(g);let h=re(g,t);r.push(h)}if(o.push(ze(f,t)),i++,g===null)break}else break}return{node:{type:y.CONDITIONAL,conditions:r,bodies:o,id:a},nextIndex:i}},yr={eq:M.EQ,neq:M.NEQ,gt:M.GT,gte:M.GTE,lt:M.LT,lte:M.LTE,in:M.IN,add:M.ADD,sub:M.SUBTRACT},br={all:M.AND,any:M.OR},vl=new Set(["var","literal","call","not",...Object.keys(yr),...Object.keys(br)]),Sl=(e,n,t)=>{if(!Array.isArray(e))throw new R(`Condition JSON operator '${n}' at '${ue(t)}' requires an array`);if(e.length!==2)throw new R(`Condition JSON operator '${n}' at '${ue(t)}' requires exactly 2 operands`);return e},Rl=(e,n,t,r,o)=>{if(!Array.isArray(e))throw new R(`Condition JSON operator '${n}' at '${ue(o)}' requires an array`);if(e.length===0)throw new R(`Condition JSON operator '${n}' at '${ue(o)}' requires at least 1 condition`);return e.map((s,l)=>be(s,r,[...o,l])).reduce((s,l)=>({type:y.BINARY,op:t,left:s,right:l}))},Cl=(e,n,t)=>{let r,o;if(typeof e.call=="string")r=e.call,o=e.args??[],Ge(e,new Set(["call","args"]),t);else if(Ir(e.call))r=e.call.name,o=e.call.args??[],Ge(e,new Set(["call"]),t),Ge(e.call,new Set(["name","args"]),[...t,"call"]);else throw new R(`Condition JSON call at '${ue(t)}' requires a function name`);if(typeof r!="string"||r.trim()==="")throw new R(`Condition JSON call at '${ue(t)}' requires a non-empty function name`);if(!/^\w+$/.test(r))throw new R(`Invalid condition JSON function name '${r}' at '${ue(t)}'`);if(!Array.isArray(o))throw new R(`Condition JSON call '${r}' at '${ue(t)}' requires args to be an array`);return{type:y.FUNCTION,name:r,args:o.map((i,s)=>be(i,n,[...t,"args",s]))}},be=(e,n={},t=["$when"])=>{if(typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null)return{type:y.LITERAL,value:e};if(Array.isArray(e))throw new R(`Condition JSON array at '${ue(t)}' must be wrapped in an operator or { literal: [...] }`);if(!Ir(e))throw new R(`Invalid condition JSON value at '${ue(t)}'`);let r=xi(e);if(r.length===0)throw new R(`Condition JSON object at '${ue(t)}' must contain an operator`);let o=r.filter(s=>vl.has(s));if(o.length===0)throw new R(`Unknown condition JSON operator '${r[0]}' at '${ue(t)}'`);if(o.length>1)throw new R(`Condition JSON at '${ue(t)}' must contain exactly one operator`);let i=o.includes("call")?"call":o[0];if(i==="var"){if(Ge(e,new Set(["var"]),t),typeof e.var!="string"||e.var.trim()==="")throw new R(`Condition JSON var at '${ue(t)}' requires a non-empty path`);return{type:y.VARIABLE,path:e.var}}if(i==="literal")return Ge(e,new Set(["literal"]),t),{type:y.LITERAL,value:e.literal};if(i==="call")return Cl(e,n,t);if(i==="not")return Ge(e,new Set(["not"]),t),{type:y.UNARY,op:In.NOT,operand:be(e.not,n,[...t,"not"])};if(i in br)return Ge(e,new Set([i]),t),Rl(e[i],i,br[i],n,[...t,i]);if(i in yr){Ge(e,new Set([i]),t);let s=Sl(e[i],i,[...t,i]);return{type:y.BINARY,op:yr[i],left:be(s[0],n,[...t,i,0]),right:be(s[1],n,[...t,i,1])}}throw new R(`Unknown condition JSON operator '${i}' at '${ue(t)}'`)},Ai=(e,n={})=>{if(e==null)throw new R("Missing condition expression after '$when'");if(typeof e=="string"){if(e.trim()==="")throw new R("Empty condition expression after '$when'");return re(e,n)}return Ir(e)||Array.isArray(e)?be(e,n):{type:y.LITERAL,value:e}},re=(e,n={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let c=e.slice(1,-1),u=0,d=!0;for(let f=0;f<c.length;f++)if(c[f]==="("?u++:c[f]===")"&&u--,u<0){d=!1;break}if(d&&u===0)return re(c,n)}let t=rn(e,"||");if(t!==-1)return{type:y.BINARY,op:M.OR,left:re(e.substring(0,t).trim(),n),right:re(e.substring(t+2).trim(),n)};let r=rn(e,"&&");if(r!==-1)return{type:y.BINARY,op:M.AND,left:re(e.substring(0,r).trim(),n),right:re(e.substring(r+2).trim(),n)};let o=[{op:">=",type:M.GTE},{op:"<=",type:M.LTE},{op:"==",type:M.EQ},{op:"!=",type:M.NEQ},{op:">",type:M.GT},{op:"<",type:M.LT},{op:" in ",type:M.IN}];for(let{op:c,type:u}of o){let d=rn(e,c);if(d!==-1)return{type:y.BINARY,op:u,left:re(e.substring(0,d).trim(),n),right:re(e.substring(d+c.length).trim(),n)}}let i=-1,s=null,l=[{op:" + ",type:M.ADD},{op:" - ",type:M.SUBTRACT}];for(let{op:c,type:u}of l){let d=0;for(;d<e.length;){let f=rn(e.substring(d),c);if(f===-1)break;let p=d+f;p>i&&(i=p,s={op:c,type:u}),d=p+c.length}}if(i!==-1&&s)return{type:y.BINARY,op:s.type,left:re(e.substring(0,i).trim(),n),right:re(e.substring(i+s.op.length).trim(),n)};let a=[" * "," / "," % "];for(let c of a)if(rn(e,c)!==-1)throw new R(`Arithmetic operations are not allowed in conditionals: "${c}"`);return e.startsWith("!")?{type:y.UNARY,op:In.NOT,operand:re(e.substring(1).trim(),n)}:vi(e,n)},rn=(e,n)=>{let t=0,r=0;for(;r<=e.length-n.length;){if(e[r]==="(")t++;else if(e[r]===")")t--;else if(t===0&&e.substring(r,r+n.length)===n)return r;r++}return-1},_l=e=>{if(e=e.trim(),e==="true")return{type:y.LITERAL,value:!0};if(e==="false")return{type:y.LITERAL,value:!1};if(e==="null")return{type:y.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:y.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:y.LITERAL,value:""};if(e==="{}")return{type:y.LITERAL,value:{}};if(e==="[]")return{type:y.LITERAL,value:[]};let n=Number(e);return!isNaN(n)&&isFinite(n)?{type:y.LITERAL,value:n}:{type:y.VARIABLE,path:e}},vi=(e,n)=>{let t=e.trim();if(t.match(/^(\w+)\((.*)\)$/))return Nn(t,n);let o=_l(t);if(o.type===y.LITERAL)return o;if(/^[a-zA-Z_$][\w.$]*$/.test(t))return{type:y.VARIABLE,path:t};try{return Nn(t,n)}catch(i){if(i.message&&i.message.includes("not supported"))return o;throw i}},kl=(e,n=!1)=>{let t=n?"$each":"$for";try{ui(e)}catch(r){if(r instanceof R&&n){let o=r.message.replace(/\$for/g,"$each");throw new R(o.replace("Parse Error: ",""))}throw r}},Ei=(e,n,t,r=!1)=>{let o=/^\$for(?::(\w+))?\s+(.+)$/,i=e.match(o);if(!i){let b=r?"$each":"$for";throw new R(`Invalid loop syntax (got: '${e.replace("$for",b)}')`)}let s=i[1],l=i[2].trim();kl(l,r);let a=l.match(/^(.+?)\s+in\s+(.+)$/);if(!a){let b=r?"$each":"$for";throw new R(`Invalid loop syntax - missing 'in' keyword (got: '${b} ${l}')`)}let c=a[1].trim(),u=a[2].trim(),d,f=null;if(c.includes(",")){let b=c.split(",").map(I=>I.trim());if(b.length!==2)throw new R(`Invalid loop variables: ${c}. Expected format: "item" or "item, index"`);d=b[0],f=b[1]}else d=c;let p=["this","undefined","null","true","false"];if(p.includes(d))throw new R(`Reserved variable name: ${d}`);if(f&&p.includes(f))throw new R(`Reserved variable name: ${f}`);let g=vi(u,t),h=ze(n,t);return{type:y.LOOP,itemVar:d,indexVar:f,iterable:g,body:h,flatten:s!=="nested"}};var Ol=(e,n={})=>{let{functions:t={}}=n;return ze(e,t)},It=Ol;var Dn={};Bc(Dn,{now:()=>$l});var $l=()=>Date.now();var Tl=(e,n,t={})=>{let{functions:r={},partials:o={}}=t,i={...Dn,...r},s=It(e,{functions:i}),l={};for(let[a,c]of Object.entries(o))l[a]=It(c,{functions:i});return gr(s,n,{functions:i,partials:l})},on=Tl;var Ll=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&typeof e.type=="number",Pl=(e={})=>!e||typeof e!="object"?{}:Object.prototype.hasOwnProperty.call(e,"functions")||Object.prototype.hasOwnProperty.call(e,"partials")?e.functions||{}:e,Nl=(e,n)=>{if(Ll(e))return e;if(typeof e=="string"){if(e.trim()==="")throw new R("Empty condition expression");return re(e,n)}return be(e,n)},Dl=(e,n={},t={})=>{let r=Pl(t),o={...Dn,...r},i=Nl(e,o);return!!Be(i,{functions:o,partials:{}},n,{})},wr=Dl;var kr=Symbol("runStoreTransaction"),vr="__routeEngineConditionComparison",wt=(e,n)=>typeof e=="number"&&typeof n=="number"&&Number.isFinite(e)&&Number.isFinite(n)||typeof e=="string"&&typeof n=="string",qe=Object.freeze({eq:(e,n)=>e===n,neq:(e,n)=>e!==n,gt:(e,n)=>wt(e,n)&&e>n,gte:(e,n)=>wt(e,n)&&e>=n,lt:(e,n)=>wt(e,n)&&e<n,lte:(e,n)=>wt(e,n)&&e<=n}),$i=Object.freeze(Object.fromEntries(Object.keys(qe).map(e=>[e,`${vr}${e}`]))),Ml=Object.freeze(Object.fromEntries(Object.entries($i).map(([e,n])=>[n,qe[e]]))),Si=(e,n)=>Object.prototype.hasOwnProperty.call(e??{},n),Vl=e=>{if(typeof e?.call=="string")return e.call;if(e?.call!==null&&typeof e?.call=="object"&&!Array.isArray(e.call))return e.call.name},At=e=>{if(Array.isArray(e))return e.map(At);if(e===null||typeof e!="object"||Si(e,"literal")||Si(e,"var"))return e;if(Vl(e)?.startsWith(vr))throw new Error(`Condition function names beginning with "${vr}" are reserved`);let t=Object.entries(e);if(t.length===1){let[[r,o]]=t,i=$i[r];if(i)return{call:i,args:o.map(At)}}return Object.fromEntries(t.map(([r,o])=>[r,At(o)]))},Vn=(e,n={})=>{if(typeof e=="string")throw new Error("String condition expressions are not supported; use semantic JSON conditions");return be(e),wr(At(e),n,{functions:Ml})},jl=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ti=(e,n,t={})=>{let r=structuredClone(e),o={},i={},{transformSelectorFirstArgument:s=c=>c,transformActionFirstArgument:l=c=>c}=t;for(let[c,u]of Object.entries(n))c!=="createInitialState"&&(c.startsWith("select")?o[c]=(...d)=>u(s(r),...d):i[c]=(...d)=>{let f;return r=pr(r,g=>{let h=u(l(g),...d);f=h!==void 0&&!ie(h)?h:void 0}),f});let a=c=>{if(typeof c!="function")throw new Error("Store transaction requires a callback");let u=r;try{return c()}catch(d){throw r=u,d}};return{...o,...i,[kr]:a}},St=(e,n)=>t=>{let r=e(),o=Array.isArray(t)?t:[t];return pr(r,i=>{o.forEach(s=>{n.forEach(l=>{l(i,s)})})})};var Fl=(e,n)=>{if(e.default!==void 0)return e.default;let t=["number","boolean","string","object"];if(!t.includes(e.type))throw new Error(`Invalid variable type: ${e.type} for variable ${n}. Expected one of: ${t.join(", ")}`);switch(e.type){case"number":return 0;case"boolean":return!1;case"string":return"";case"object":return{}}},P=(e,n)=>Object.prototype.hasOwnProperty.call(e??{},n),Sr=(e,n,t)=>{Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0})},ne=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Ul=new Set(["pageSize","groups"]),Bl=new Set(["id","variants"]),Gl=new Set(["id","imageId"]),zl=new Set(["pageSize","tracks"]),ql=new Set(["id","soundId","title","artist","album","description","coverImageId"]),Yl=new Set(["pageSize","replays"]),Hl=new Set(["id","title","thumbnailImageId","startSectionId","initialVariables"]),sn=(e,n,t)=>{Object.keys(e).forEach(r=>{if(!n.has(r))throw new Error(`${t} contains unsupported property "${r}"`)})},wn=(e,n)=>{if(typeof e!="string"||e.length===0)throw new Error(`${n} must be a non-empty string`)},jn=(e={})=>{let n=e?.resources?.imageGallery;if(n===void 0)return;if(!ne(n))throw new Error("resources.imageGallery must be an object");if(sn(n,Ul,"resources.imageGallery"),!Number.isInteger(n.pageSize)||n.pageSize<1)throw new Error("resources.imageGallery.pageSize must be an integer greater than or equal to 1");if(!Array.isArray(n.groups))throw new Error("resources.imageGallery.groups must be an array");let t=new Set;for(let[r,o]of n.groups.entries()){let i=`resources.imageGallery.groups[${r}]`;if(!ne(o))throw new Error(`${i} must be an object`);if(sn(o,Bl,i),wn(o.id,`${i}.id`),t.has(o.id))throw new Error(`Duplicate image gallery group id "${o.id}"`);if(t.add(o.id),!Array.isArray(o.variants)||o.variants.length===0)throw new Error(`${i}.variants must be a non-empty array`);let s=new Set;for(let[l,a]of o.variants.entries()){let c=`${i}.variants[${l}]`;if(!ne(a))throw new Error(`${c} must be an object`);if(sn(a,Gl,c),wn(a.id,`${c}.id`),wn(a.imageId,`${c}.imageId`),s.has(a.id))throw new Error(`Duplicate image gallery variant id "${a.id}" in group "${o.id}"`);if(s.add(a.id),!P(e?.resources?.images,a.imageId))throw new Error(`Image gallery variant "${o.id}.${a.id}" references unknown image "${a.imageId}"`)}}},Fn=(e={})=>{let n=e?.resources?.musicRoom;if(n===void 0)return;if(!ne(n))throw new Error("resources.musicRoom must be an object");if(sn(n,zl,"resources.musicRoom"),!Number.isInteger(n.pageSize)||n.pageSize<1)throw new Error("resources.musicRoom.pageSize must be an integer greater than or equal to 1");if(!Array.isArray(n.tracks))throw new Error("resources.musicRoom.tracks must be an array");let t=new Set;for(let[r,o]of n.tracks.entries()){let i=`resources.musicRoom.tracks[${r}]`;if(!ne(o))throw new Error(`${i} must be an object`);sn(o,ql,i);for(let a of["id","soundId","title"])wn(o[a],`${i}.${a}`);for(let a of["artist","album","description","coverImageId"])o[a]!==void 0&&wn(o[a],`${i}.${a}`);if(t.has(o.id))throw new Error(`Duplicate music room track id "${o.id}"`);t.add(o.id);let s=e?.resources?.sounds?.[o.soundId];if(!P(e?.resources?.sounds,o.soundId))throw new Error(`Music room track "${o.id}" references unknown sound "${o.soundId}"`);if(!ne(s))throw new Error(`Music room track "${o.id}" references invalid sound "${o.soundId}"`);if(s.playbackRate!==void 0&&(typeof s.playbackRate!="number"||!Number.isFinite(s.playbackRate)||s.playbackRate<=0))throw new Error(`Music room sound "${o.soundId}" playbackRate must be a finite number greater than 0`);let l=s.startAt??0;if(typeof l!="number"||!Number.isFinite(l)||l<0)throw new Error(`Music room sound "${o.soundId}" startAt must be a finite non-negative number`);if(s.endAt!==void 0&&s.endAt!==null&&(typeof s.endAt!="number"||!Number.isFinite(s.endAt)||s.endAt<=l))throw new Error(`Music room sound "${o.soundId}" endAt must be a finite number greater than startAt`);if(o.coverImageId!==void 0&&!P(e?.resources?.images,o.coverImageId))throw new Error(`Music room track "${o.id}" references unknown cover image "${o.coverImageId}"`)}},Wl=(e,n,t)=>{let r=Array.isArray(t)?"array":typeof t;switch(n.type){case"number":if(typeof t!="number"||!Number.isFinite(t))throw new Error(`Scene replay initial variable "${e}" expected type number, got ${r}`);return;case"boolean":if(typeof t!="boolean")throw new Error(`Scene replay initial variable "${e}" expected type boolean, got ${r}`);return;case"string":if(typeof t!="string")throw new Error(`Scene replay initial variable "${e}" expected type string, got ${r}`);return;case"object":if(t===null||typeof t!="object")throw new Error(`Scene replay initial variable "${e}" expected type object, got ${r}`);return;default:throw new Error(`Scene replay initial variable "${e}" has invalid variable type "${n.type}"`)}},Un=(e={})=>{let n=e?.resources?.sceneReplay;if(n===void 0)return;if(!ne(n))throw new Error("resources.sceneReplay must be an object");if(sn(n,Yl,"resources.sceneReplay"),!Number.isInteger(n.pageSize)||n.pageSize<1)throw new Error("resources.sceneReplay.pageSize must be an integer greater than or equal to 1");if(!Array.isArray(n.replays))throw new Error("resources.sceneReplay.replays must be an array");let t=new Map;Object.values(e?.story?.scenes??{}).forEach(o=>{Object.entries(o?.sections??{}).forEach(([i,s])=>{t.set(i,s)})});let r=new Set;for(let[o,i]of n.replays.entries()){let s=`resources.sceneReplay.replays[${o}]`;if(!ne(i))throw new Error(`${s} must be an object`);sn(i,Hl,s);for(let a of["id","title","thumbnailImageId","startSectionId"])wn(i[a],`${s}.${a}`);if(r.has(i.id))throw new Error(`Duplicate scene replay id "${i.id}"`);if(r.add(i.id),!P(e?.resources?.images,i.thumbnailImageId))throw new Error(`Scene replay "${i.id}" references unknown thumbnail image "${i.thumbnailImageId}"`);if(!t.has(i.startSectionId))throw new Error(`Scene replay "${i.id}" references unknown start section "${i.startSectionId}"`);let l=t.get(i.startSectionId);if(l.initialLineId!==void 0&&!l.lines?.some(a=>a.id===l.initialLineId))throw new Error(`Scene replay "${i.id}" start section "${i.startSectionId}" references unknown initial line "${l.initialLineId}"`);if(i.initialVariables!==void 0){if(!ne(i.initialVariables))throw new Error(`${s}.initialVariables must be an object`);for(let[a,c]of Object.entries(i.initialVariables)){let u=e?.resources?.variables?.[a];if(!u)throw new Error(`Scene replay "${i.id}" initialVariables references unknown variable "${a}"`);if(Se(u))throw new Error(`Scene replay "${i.id}" cannot initialize computed variable "${a}"`);if(u.readonly===!0)throw new Error(`Scene replay "${i.id}" cannot initialize readonly variable "${a}"`);if(u.scope!=="context")throw new Error(`Scene replay "${i.id}" can only initialize context variable "${a}"`);Wl(a,u,c)}}}},Li=e=>{let n=ie(e)?Ue(e):e;return structuredClone(n)},Kl=({characterId:e,resourceCharacter:n,variables:t={}}={})=>{if(!P(n,"nameVariableId"))return;let r=n.nameVariableId,o=t?.[r];if(typeof o!="string")throw new Error(`Character "${e}" nameVariableId "${r}" must resolve to a string variable`);return o},Rt=({characterId:e,character:n,characterName:t,characters:r={},variables:o={}}={})=>{let i=e?r?.[e]:void 0;if(n?.name!==void 0)return n.name;if(t!==void 0)return t;let s=Kl({characterId:e,resourceCharacter:i,variables:o});return s!==void 0?s:i?.name||""},Se=e=>P(e,"computed"),An=(e={},n={})=>Object.fromEntries(Object.entries(e??{}).filter(([t])=>!Se(n[t]))),ve=(e,n)=>new Error(`${n} has invalid path: ${JSON.stringify(e)}`),Jl=(e,n,t)=>{if(e[0]==='"')try{return JSON.parse(e)}catch{throw ve(n,t)}let o="";for(let i=1;i<e.length-1;i+=1){let s=e[i];if(s!=="\\"){if(s.charCodeAt(0)<32)throw ve(n,t);o+=s;continue}if(i+=1,i>=e.length-1)throw ve(n,t);let l=e[i];if(l==="u"){let c=e.slice(i+1,i+5);if(c.length!==4||!/^[0-9a-fA-F]{4}$/.test(c))throw ve(n,t);o+=String.fromCharCode(Number.parseInt(c,16)),i+=4;continue}let a={"\\":"\\",'"':'"',"'":"'","/":"/",n:`
2
- `,r:"\r",t:" ",b:"\b",f:"\f"};if(!P(a,l))throw ve(n,t);o+=a[l]}return o},Pi=(e,n="Computed expression var")=>{if(typeof e!="string"||e.length===0||e.trim()!==e)throw ve(e,n);let t=[],r=0,o=()=>{let s=r;for(;r<e.length&&e[r]!=="."&&e[r]!=="["&&e[r]!=="]";)r+=1;let l=e.slice(s,r);if(l.length===0||l.trim()!==l||/\s/.test(l))throw ve(e,n);t.push(l)},i=()=>{for(r+=1;r<e.length&&/\s/.test(e[r]);)r+=1;let s=e[r];if(/\d/.test(s??"")){let u=r;for(;r<e.length&&/\d/.test(e[r]);)r+=1;let d=e.slice(u,r);for(;r<e.length&&/\s/.test(e[r]);)r+=1;if(e[r]!=="]"||d.length>1&&d.startsWith("0"))throw ve(e,n);r+=1,t.push(d);return}if(s!=='"'&&s!=="'")throw ve(e,n);let l=s,a=r;r+=1;let c=!1;for(;r<e.length;){let u=e[r];if(c)c=!1;else if(u==="\\")c=!0;else if(u===l){let d=e.slice(a,r+1);for(r+=1;r<e.length&&/\s/.test(e[r]);)r+=1;if(e[r]!=="]")throw ve(e,n);r+=1,t.push(Jl(d,e,n));return}r+=1}if(c||r>=e.length)throw ve(e,n)};for(o();r<e.length;){if(e[r]==="."){r+=1,o();continue}if(e[r]==="["){i();continue}throw ve(e,n)}return t},Ar=(e,n)=>{let t=e;for(let r of n){if(t==null||!P(t,r))return;t=t[r]}return t},Ni=(e,n={})=>{if(typeof e!="string"||e.trim()==="")throw new Error("Computed expression var requires a non-empty string path");let t=Pi(e),[r,o,...i]=t;if(r==="variables"){if(!o)return n.variables;let s=typeof n.resolveVariable=="function"?n.resolveVariable(o):n.variables?.[o];return Ar(s,i)}return r==="runtime"?Ar(n.runtime,t.slice(1)):Ar(n,t)},Di=(e,n,t)=>{if(!Array.isArray(n))throw new Error(`Computed expression operator "${e}" requires an array`);if(t!==void 0&&n.length!==t)throw new Error(`Computed expression operator "${e}" requires ${t} operand(s)`)},Rr=(e,n)=>{if(!Array.isArray(n))throw new Error(`Computed expression operator "${e}" requires an array`);if(n.length===0)throw new Error(`Computed expression operator "${e}" requires at least one operand`)},Xl=(e,n)=>{if(typeof n!="number"||!Number.isFinite(n))throw new Error(`Computed expression operator "${e}" requires finite numeric operands`)},_e=(e,n,t,r)=>(Di(e,n,r),n.map(o=>vt(o,t))),xe=(e,n,t,r)=>{let o=_e(e,n,t,r);return o.forEach(i=>Xl(e,i)),o},Ql=(e,n,t)=>{switch(e){case"var":return Ni(n,t);case"add":{let[r,o]=xe(e,n,t,2);return r+o}case"sub":{let[r,o]=xe(e,n,t,2);return r-o}case"mul":{let[r,o]=xe(e,n,t,2);return r*o}case"div":{let[r,o]=xe(e,n,t,2);return r/o}case"mod":{let[r,o]=xe(e,n,t,2);return r%o}case"neg":{let[r]=xe(e,n,t,1);return-r}case"round":{let[r]=xe(e,n,t,1);return Math.round(r)}case"floor":{let[r]=xe(e,n,t,1);return Math.floor(r)}case"ceil":{let[r]=xe(e,n,t,1);return Math.ceil(r)}case"min":{let[r,o]=xe(e,n,t,2);return Math.min(r,o)}case"max":{let[r,o]=xe(e,n,t,2);return Math.max(r,o)}case"clamp":{let[r,o,i]=xe(e,n,t,3);return Math.min(i,Math.max(o,r))}case"eq":{let[r,o]=_e(e,n,t,2);return qe.eq(r,o)}case"neq":{let[r,o]=_e(e,n,t,2);return qe.neq(r,o)}case"gt":{let[r,o]=_e(e,n,t,2);return qe.gt(r,o)}case"gte":{let[r,o]=_e(e,n,t,2);return qe.gte(r,o)}case"lt":{let[r,o]=_e(e,n,t,2);return qe.lt(r,o)}case"lte":{let[r,o]=_e(e,n,t,2);return qe.lte(r,o)}case"in":{let[r,o]=_e(e,n,t,2);return Array.isArray(o)?o.includes(r):!1}case"and":case"all":return Rr(e,n),n.every(r=>!!vt(r,t));case"or":case"any":return Rr(e,n),n.some(r=>!!vt(r,t));case"not":{let[r]=_e(e,n,t,1);return!r}case"length":{let[r]=_e(e,n,t,1);return typeof r=="string"||Array.isArray(r)?r.length:ne(r)?Object.keys(r).length:0}case"includes":{let[r,o]=_e(e,n,t,2);return typeof r=="string"?typeof o=="string"&&r.includes(o):Array.isArray(r)?r.includes(o):!1}case"literal":return Li(n);default:throw new Error(`Unknown computed expression operator: ${e}`)}},vt=(e,n={})=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))throw new Error("Computed expression arrays are not valid; use value for literal arrays");let t=Object.entries(e);if(t.length!==1)throw new Error("Computed expression objects must contain exactly one operator");let[[r,o]]=t;return Ql(r,o,n)},Cr=(e,n)=>{if(e===null||typeof e!="object"||P(e,"literal"))return e;if(P(e,"var"))return{literal:Ni(e.var,n)};if(P(e,"call"))throw new Error("Function calls are not supported in computed-variable conditions");return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?r.map(o=>Cr(o,n)):Cr(r,n)]))},Zl=(e,n={})=>{if(typeof e=="string")throw new Error("String condition expressions are not supported; use semantic JSON conditions");return be(e),Vn(Cr(e,n))},Mi=(e,n)=>{if(!ne(e))throw new Error(`${n} must be an object`);let t=P(e,"expr"),r=P(e,"value");if(t===r)throw new Error(`${n} must contain exactly one of expr or value`)},Er=(e,n,t)=>(Mi(e,n),P(e,"value")?Li(e.value):vt(e.expr,t)),eu=(e,n={},t="unknown")=>{if(!ne(e))throw new Error(`Computed variable "${t}" computed must be an object`);let r=P(e,"expr"),o=P(e,"value");if(P(e,"branches")){if(r||o)throw new Error(`Computed variable "${t}" cannot combine branches with expr or value`);if(!Array.isArray(e.branches))throw new Error(`Computed variable "${t}" branches must be an array`);if(e.branches.length===0)throw new Error(`Computed variable "${t}" branches must not be empty`);if(!ne(e.default))throw new Error(`Computed variable "${t}" requires default`);for(let s=0;s<e.branches.length;s+=1){let l=e.branches[s];if(!ne(l))throw new Error(`Computed variable "${t}" branch ${s} must be an object`);if(!P(l,"when"))throw new Error(`Computed variable "${t}" branch ${s} requires when`);if(Zl(l.when,n))return Er(l,`Computed variable "${t}" branch ${s}`,n)}return Er(e.default,`Computed variable "${t}" default`,n)}if(r===o)throw new Error(`Computed variable "${t}" must contain exactly one of expr, value, or branches`);return Er(e,`Computed variable "${t}"`,n)},Vi=(e,n,t)=>{switch(n){case"number":if(typeof t!="number"||!Number.isFinite(t))throw new Error(`Computed variable "${e}" expected type number, got ${Array.isArray(t)?"array":typeof t}`);return;case"boolean":if(typeof t!="boolean")throw new Error(`Computed variable "${e}" expected type boolean, got ${Array.isArray(t)?"array":typeof t}`);return;case"string":if(typeof t!="string")throw new Error(`Computed variable "${e}" expected type string, got ${Array.isArray(t)?"array":typeof t}`);return;case"object":if(t===null||typeof t!="object")throw new Error(`Computed variable "${e}" expected type object, got ${typeof t}`);return;default:throw new Error(`Invalid variable type: ${n} for computed variable ${e}`)}},nu=Object.freeze({add:2,sub:2,mul:2,div:2,mod:2,neg:1,round:1,floor:1,ceil:1,min:2,max:2,clamp:3,eq:2,neq:2,gt:2,gte:2,lt:2,lte:2,in:2,not:1,length:1,includes:2}),tu=new Set(["and","or","all","any"]),ru=new Set(["add","sub","mul","div","mod","neg","round","floor","ceil","min","max","clamp","length"]),ou=new Set(["add","sub","mul","div","mod","neg","round","floor","ceil","min","max","clamp"]),iu=new Set(["eq","neq","gt","gte","lt","lte","in","and","or","all","any","not","includes"]),su=new Set(["all","any","eq","neq","gt","gte","lt","lte","in","add","sub"]),ji=new WeakMap,Ri=e=>e===null?"null":Array.isArray(e)?"object":typeof e,Et=(e,n,t)=>{for(let r of Object.keys(e))if(!n.has(r))throw new Error(`${t} contains unsupported property "${r}"`)},au=(e,n,t,r)=>{if(t!==void 0&&t!==n)throw new Error(`Computed variable "${e}" ${r} expected type ${n}, got ${t}`)},Fi=(e,{variableId:n,variableConfigs:t,dependencies:r,path:o})=>{let i=`Computed variable "${n}" ${o} var`,[s,l,...a]=Pi(e,i);if(s!=="variables"&&s!=="runtime")throw new Error(`${i} must reference variables.* or runtime.*, got ${JSON.stringify(e)}`);if(!l)throw new Error(`${i} must reference a concrete ${s} member, got ${JSON.stringify(e)}`);if(s==="runtime")return;if(!P(t,l))throw new Error(`Computed variable "${n}" ${o} references unknown variable "${l}"`);let c=t[l];return Se(c)&&r.add(l),a.length===0?c?.type:void 0},Ui=(e,{variableId:n,variableConfigs:t,dependencies:r,path:o})=>{if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new Error(`Computed variable "${n}" ${o} must use finite numeric literals`);return Ri(e)}if(Array.isArray(e))throw new Error("Computed expression arrays are not valid; use value for literal arrays");let i=Object.entries(e);if(i.length!==1)throw new Error("Computed expression objects must contain exactly one operator");let[[s,l]]=i;if(s==="var"){if(typeof l!="string"||l.trim()==="")throw new Error("Computed expression var requires a non-empty string path");return Fi(l,{variableId:n,variableConfigs:t,dependencies:r,path:o})}if(s==="literal"){if(typeof l=="number"&&!Number.isFinite(l))throw new Error(`Computed variable "${n}" ${o} must use finite numeric literals`);return Ri(l)}let a=nu[s];if(a===void 0&&!tu.has(s))throw new Error(`Unknown computed expression operator: ${s}`);a===void 0?Rr(s,l):Di(s,l,a);let c=l.map((u,d)=>Ui(u,{variableId:n,variableConfigs:t,dependencies:r,path:`${o}.${s}[${d}]`}));if(ou.has(s)&&c.forEach(u=>{if(u!==void 0&&u!=="number")throw new Error(`Computed expression operator "${s}" requires numeric operands`)}),ru.has(s))return"number";if(iu.has(s))return"boolean"},cu=(e,{variableId:n,variableConfigs:t,dependencies:r,path:o})=>{if(typeof e=="string")throw new Error("String condition expressions are not supported; use semantic JSON conditions");try{be(e)}catch(s){throw new Error(`Computed variable "${n}" ${o} is invalid: ${s.message}`,{cause:s})}let i=(s,l)=>{if(s===null||typeof s!="object"||P(s,"literal"))return;if(P(s,"var")){Fi(s.var,{variableId:n,variableConfigs:t,dependencies:r,path:l});return}if(P(s,"call"))throw new Error(`Computed variable "${n}" ${l} function calls are not supported`);if(P(s,"not")){i(s.not,`${l}.not`);return}let a=Object.keys(s).find(c=>su.has(c));s[a].forEach((c,u)=>{i(c,`${l}.${a}[${u}]`)})};i(e,o)},xr=(e,{variableId:n,variableConfig:t,variableConfigs:r,dependencies:o,path:i,allowedKeys:s=new Set(["expr","value"])})=>{if(Mi(e,`Computed variable "${n}" ${i}`),Et(e,s,i),P(e,"value")){Vi(n,t.type,e.value);return}let l=Ui(e.expr,{variableId:n,variableConfigs:r,dependencies:o,path:`${i}.expr`});au(n,t.type,l,`${i}.expr`)},lu=(e,n,t)=>{let r=n.computed;if(!ne(r))throw new Error(`Computed variable "${e}" computed must be an object`);let o=new Set,i=P(r,"expr"),s=P(r,"value");if(P(r,"branches")){if(Et(r,new Set(["branches","default"]),`Computed variable "${e}" computed`),i||s)throw new Error(`Computed variable "${e}" cannot combine branches with expr or value`);if(!Array.isArray(r.branches))throw new Error(`Computed variable "${e}" branches must be an array`);if(r.branches.length===0)throw new Error(`Computed variable "${e}" branches must not be empty`);if(!ne(r.default))throw new Error(`Computed variable "${e}" requires default`);return r.branches.forEach((a,c)=>{if(!ne(a))throw new Error(`Computed variable "${e}" branch ${c} must be an object`);if(Et(a,new Set(["when","expr","value"]),`Computed variable "${e}" branch ${c}`),!P(a,"when"))throw new Error(`Computed variable "${e}" branch ${c} requires when`);cu(a.when,{variableId:e,variableConfigs:t,dependencies:o,path:`computed.branches[${c}].when`}),xr(a,{variableId:e,variableConfig:n,variableConfigs:t,dependencies:o,path:`computed.branches[${c}]`,allowedKeys:new Set(["when","expr","value"])})}),xr(r.default,{variableId:e,variableConfig:n,variableConfigs:t,dependencies:o,path:"computed.default"}),o}if(Et(r,new Set(["expr","value"]),`Computed variable "${e}" computed`),i===s)throw new Error(`Computed variable "${e}" must contain exactly one of expr, value, or branches`);return xr(r,{variableId:e,variableConfig:n,variableConfigs:t,dependencies:o,path:"computed"}),o},an=(e={})=>{if(!ne(e))throw new Error("Variable configs must be an object");if(P(e,"__proto__"))throw new Error('Variable id "__proto__" is reserved');if(P(e,""))throw new Error("Variable ids must not be empty");let n=new Map;Object.entries(e).forEach(([i,s])=>{if(Se(s)){if(!ne(s))throw new Error(`Computed variable "${i}" must be an object`);if(!P(s,"type"))throw new Error(`Computed variable "${i}" requires type`);if(!P(s,"scope"))throw new Error(`Computed variable "${i}" requires scope`);if(P(s,"default"))throw new Error(`Computed variable "${i}" must not declare a top-level default`);if(Gn(s.scope,i),!["number","boolean","string","object"].includes(s.type))throw new Error(`Invalid variable type: ${s.type} for computed variable ${i}`);n.set(i,lu(i,s,e))}});let t=new Set,r=[];n.forEach((i,s)=>{if(t.has(s))return;let l=[{variableId:s,dependencies:[...n.get(s)??[]],nextDependencyIndex:0}],a=new Map([[s,0]]);for(;l.length>0;){let c=l.at(-1);if(c.nextDependencyIndex>=c.dependencies.length){l.pop(),a.delete(c.variableId),t.add(c.variableId),r.push(c.variableId);continue}let u=c.dependencies[c.nextDependencyIndex];if(c.nextDependencyIndex+=1,t.has(u))continue;let d=a.get(u);if(d!==void 0){let f=[...l.slice(d).map(({variableId:p})=>p),u].join(" -> ");throw new Error(`Computed variable cycle detected: ${f}`)}a.set(u,l.length),l.push({variableId:u,dependencies:[...n.get(u)??[]],nextDependencyIndex:0})}});let o=Object.freeze({evaluationOrder:Object.freeze(r)});return ji.set(e,o),o},Bn=({variables:e={},runtime:n={},variableConfigs:t={},eager:r=!0}={})=>{let{evaluationOrder:o}=ji.get(t)??an(t),i=An(e,t),s=Object.entries(t).filter(([,b])=>Se(b)).map(([b])=>b),l=Object.create(null),a=[],c=new Map(o.map((b,I)=>[b,I])),u=-1,d=!1,f=b=>{if(P(l,b))return l[b];let I=t[b];if(!Se(I))return P(i,b)?i[b]:void 0;let E=a.indexOf(b);if(E>=0){let A=[...a.slice(E),b].join(" -> ");throw new Error(`Computed variable cycle detected: ${A}`)}a.push(b);try{let A=eu(I.computed,h,b);return Vi(b,I.type,A),Sr(l,b,A),A}finally{a.pop()}},p=b=>{if(P(l,b))return l[b];let I=t[b];if(!Se(I))return P(i,b)?i[b]:void 0;let E=c.get(b);if(r&&!d&&E!==void 0&&E>u){d=!0;try{for(let A=u+1;A<=E;A+=1)f(o[A]),u=A}finally{d=!1}return l[b]}return f(b)},g=new Proxy({},{get:(b,I)=>{if(typeof I=="string")return p(I)},has:(b,I)=>typeof I=="string"&&(P(i,I)||s.includes(I)),ownKeys:()=>[...new Set([...Object.keys(i),...s])],getOwnPropertyDescriptor:(b,I)=>{if(!(typeof I!="string"||!P(i,I)&&!s.includes(I)))return{enumerable:!0,configurable:!0}}}),h={variables:g,runtime:n,resolveVariable:p};return r?(s.forEach(b=>{p(b)}),{...i,...l}):g},uu=({variables:e={},runtime:n={},variableConfigs:t,projectData:r}={})=>{let o=t??r?.resources?.variables??{};return an(o),Bn({variables:e,runtime:n,variableConfigs:o,eager:!0})},Ct=e=>{let n={},t={};return e.resources?.variables?(Object.entries(e.resources.variables).forEach(([r,o])=>{if(Se(o))return;let i=Fl(o,r);o.scope==="context"?Sr(n,r,i):Sr(t,r,i)}),{contextVariableDefaultValues:n,globalVariablesDefaultValues:t}):{contextVariableDefaultValues:n,globalVariablesDefaultValues:t}},Gn=(e,n)=>{let t=["context","device","account"];if(!e)throw new Error(`Variable scope is required for variable: ${n}`);if(!t.includes(e))throw new Error(`Invalid variable scope: ${e} for variable ${n}. Expected one of: ${t.join(", ")}`)},_t=(e,n,t)=>{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 ${t}`);if(!Object.values(r).flat().includes(n))throw new Error(`Unknown operation: ${n}`);if(!o.includes(n))throw new Error(`Operation "${n}" is not valid for variable "${t}" of type "${e}". Valid operations: ${o.join(", ")}`)},du=2,Ci=12,Bi=(e=du)=>{if(!Number.isInteger(e)||e<0||e>Ci)throw new Error(`Operation "divide" requires roundTo to be an integer between 0 and ${Ci}.`);return e},fu=(e,n)=>{let t=10**n;return Math.round((e+Number.EPSILON)*t)/t},xt=e=>typeof e=="number"&&Number.isFinite(e),Or=(e,n,t,r,o={})=>{if(e==="number"){if(n==="set"&&!xt(t))throw new Error(`Operation "set" requires value to be a number for variable "${r}".`);if(n==="multiply"&&!xt(t))throw new Error(`Operation "multiply" requires value to be a number for variable "${r}".`);if(n==="divide"&&!xt(t))throw new Error(`Operation "divide" requires value to be a number for variable "${r}".`);if(n==="divide"){if(t===0)throw new Error(`Operation "divide" requires value to be a non-zero number for variable "${r}".`);Bi(o.roundTo)}}},kt=(e,n,t,r={})=>{let o=(s,l,a)=>{let c=s??l;if(!xt(c))throw new Error(`Operation "${n}" requires ${a} to be a number.`);return c},i=s=>{let l=o(s,void 0,"value");if(l===0)throw new Error(`Operation "${n}" requires value to be a non-zero number.`);return l};switch(n){case"set":return t;case"multiply":return o(e,1,"current value")*o(t,void 0,"value");case"divide":return fu(o(e,0,"current value")/i(t),Bi(r.roundTo));case"increment":return o(e,0,"current value")+o(t,1,"value");case"decrement":return o(e,0,"current value")-o(t,1,"value");case"toggle":return!e;default:throw new Error(`Unknown operation: ${n}`)}};var $r=(e,n="DD/MM/YYYY - HH:mm")=>{if(!e)return"";let t=new Date(e),r=s=>String(s).padStart(2,"0"),o=String(t.getFullYear()),i={DD:r(t.getDate()),MM:r(t.getMonth()+1),MMM:jl[t.getMonth()],YYYY:o,YY:o.slice(-2),HH:r(t.getHours()),mm:r(t.getMinutes()),ss:r(t.getSeconds())};return n.replace(/YYYY|MMM|YY|MM|DD|HH|mm|ss/g,s=>i[s])},pu=(e,n)=>{let t=i=>i?.ui,r=t(e),o=t(n);return JSON.stringify(r)===JSON.stringify(o)?null:r&&!o?{changeType:"delete",data:e}:o&&!r?{changeType:"add",data:n}:o&&r?{changeType:"update",data:n}:null},Mn=e=>!!e?.transformId&&Array.isArray(e.items)&&e.items.length>0,mu=(e,n)=>{let t=e?.character?.sprite,r=n?.character?.sprite,o=Mn(t)?t:void 0,i=Mn(r)?r:void 0;return JSON.stringify(o)===JSON.stringify(i)?null:o&&!i?{changeType:"delete",data:o}:i&&!o?{changeType:"add",data:i}:i&&o?{changeType:"update",data:i}:null},_i=e=>{if(e?.resourceId===void 0)return;let n={resourceId:e.resourceId};e.transformId!==void 0&&(n.transformId=e.transformId);for(let t of["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"])e[t]!==void 0&&(n[t]=e[t]);for(let t of["animationName","animationSpeed","loop"])e[t]!==void 0&&(n[t]=e[t]);return n},ki=e=>{if(e?.colorId!==void 0)return{colorId:e.colorId}},Oi=(e,n)=>n&&!e?{changeType:"add",data:n}:e&&!n?{changeType:"delete",data:e}:e&&n&&JSON.stringify(e)!==JSON.stringify(n)?{changeType:"update",data:n}:null,gu=(e,n)=>{let t={},r=Oi(_i(e),_i(n)),o=Oi(ki(e),ki(n));return r&&(t.resource=r),o&&(t.color=o),Object.keys(t).length>0?t:null},Tr=(e={},n={})=>{let t={},r=["sfx","voice"],o=a=>{let c=e[a],u=n[a];u&&!c?t[a]={changeType:"add",data:u}:c&&!u?r.includes(a)||(t[a]={changeType:"delete",data:c}):c&&u&&JSON.stringify(c)!==JSON.stringify(u)&&(t[a]={changeType:"update",data:u})},i=gu(e.background,n.background);i&&(t.background=i),o("screen"),o("bgm"),o("voice");let s=pu(e.dialogue,n.dialogue);s&&(t.dialogue=s);let l=mu(e.dialogue,n.dialogue);return l&&(t.dialogueSprite=l),o("choice"),o("form"),o("layout"),o("animation"),o("control"),o("character"),o("visual"),o("sfx"),t},Lr=(e={})=>{let n=structuredClone(e);n.background&&(n.background.animations?.playback?.continuity!=="persistent"&&delete n.background.animations,!n.background.resourceId&&!n.background.colorId&&delete n.background);let t=o=>{n[o]&&(delete n[o].animations,Object.keys(n[o]).length===0&&delete n[o])};t("layout"),t("choice"),t("form"),t("screen"),n.dialogue?.ui&&(delete n.dialogue.ui.animations,Object.keys(n.dialogue.ui).length===0&&delete n.dialogue.ui,Object.keys(n.dialogue).length===0&&delete n.dialogue),n.dialogue?.character?.sprite&&(delete n.dialogue.character.sprite.animations,Object.keys(n.dialogue.character.sprite).length===0&&delete n.dialogue.character.sprite,Object.keys(n.dialogue.character).length===0&&delete n.dialogue.character,Object.keys(n.dialogue).length===0&&delete n.dialogue);let r=(o,i)=>{let s=n[o]?.items;Array.isArray(s)&&(n[o].items=s.map(l=>{let a={...l};return delete a.animations,i(a)?a:null}).filter(Boolean),n[o].items.length===0&&delete n[o])};return r("character",o=>o.sprites&&o.sprites.length>0||o.transformId||o.resourceId),r("visual",o=>o.resourceId||o.transformId),n},hu=(e,n)=>{if(!e||!n)return;let t=e;for(let r of n.split(".")){if(t==null||!(r in Object(t)))return;t=t[r]}return t},yu=(e,n)=>{if(typeof e!="string")return e;if(e==="_event"){if(n==null)throw new Error('Action template binding "_event" requires event context "_event".');return n}if(!e.startsWith("_event."))return e;if(n==null)throw new Error(`Action template binding "${e}" requires event context "_event".`);let t=e.slice(7),r=hu(n,t);if(r===void 0)throw new Error(`Action template binding "${e}" could not be resolved from "_event".`);return r},bu={conditional:new Set(["branches"]),updateProjectData:new Set(["projectData"]),showConfirmDialog:new Set(["confirmActions","cancelActions"]),form:new Set(["submitActions","cancelActions"]),submitForm:new Set(["actions"]),cancelForm:new Set(["actions"])},Iu=(e,n)=>{let t=e[e.length-1];return t?bu[t]?.has(n)===!0:!1},_r=(e,n,t=[])=>Array.isArray(e)?e.map(r=>_r(r,n,t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,Iu(t,r)?o:_r(o,n,[...t,r])])):typeof e=="string"?e==="_event"||e.startsWith("_event.")?yu(e,n._event):on(e,n):e,Pr=(e,n)=>{if(!n)return e;if(Object.prototype.hasOwnProperty.call(n,"event"))throw new Error('Action template context key "event" is no longer supported. Use "_event".');return _r(e,n)};var K=e=>structuredClone(ie(e)?Ue(e):e),U=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),Gi=e=>e?.animations?.playback?.continuity==="persistent",j=(e,n)=>U(e??{},n)&&e[n]!==void 0,zn=(e,n)=>e?!n(e)&&e.animations?{animationsOnly:!0,state:{animations:K(e.animations)}}:{animationsOnly:!1,state:null}:{animationsOnly:!1,state:null},wu=e=>j(e,"opacity")||j(e,"blur"),Ki=["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"],Ji=["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"],Nr=["animationName","animationSpeed","loop"],Au=e=>Ki.some(n=>j(e,n)),Xi=e=>e?.text&&j(e.text,"content")&&j(e.text,"textStyleId"),Qi=e=>j(e,"text"),Eu=(e,n)=>e.resourceId?!0:Xi(e)?!n?.text:!1,xu=(e,n)=>{let t={...K(e),...n};return n.text&&e.text&&(t.text={...K(e.text),...K(n.text)}),t},vu=(e,n)=>{if(Qi(e)){if(e.resourceId)throw new Error(`Visual item "${e.id}" cannot define both resourceId and text`);if(!Xi(e)&&!n?.text)throw new Error(`Visual item "${e.id}" text requires content and textStyleId`)}},zi=e=>Ji.some(n=>j(e,n)),qi=e=>Nr.some(n=>j(e,n)),Su=(e,n,{hasAuthoredTransformId:t=!1}={})=>{if(!n)return e;for(let r of Ji)!t&&!j(e,r)&&j(n,r)&&(e[r]=n[r]),U(e,r)&&e[r]===void 0&&delete e[r];return e},Zi=(e,n,t)=>{let r=e[t];return r?.id===n?.id?r:e.find(o=>o.id===n?.id)},Ru=(e,n)=>{if(!n)return e;for(let t of Ki)!j(e,t)&&j(n,t)&&(e[t]=n[t]),U(e,t)&&e[t]===void 0&&delete e[t];return e},Cu=(e,n)=>(n&&(!j(e,"opacity")&&j(n,"opacity")&&(e.opacity=n.opacity),!j(e,"blur")&&j(n,"blur")&&(e.blur=K(n.blur)),U(e,"opacity")&&e.opacity===void 0&&delete e.opacity,U(e,"blur")&&e.blur===void 0&&delete e.blur),e),es=(e,n,t=[],{hasPatchFn:r=()=>!1,mergeItemFn:o}={})=>{if(!e||e.length===0)return{hasValidItems:!1,processedItems:[]};let i=e.map((s,l)=>{let a=Zi(t,s,l),c=n(s,a),u=wu(s),d=Au(s),f=r(s),p=U(s,"animations"),g=K(s);return!c&&(u||d||f)&&a&&(g=o?o(a,g):{...K(a),...g},p||delete g.animations),Cu(Ru(g,a),a)}).filter(s=>n(s)||s.animations);return{hasValidItems:i.length>0,processedItems:i}},_u=e=>{if(e){if(e.character&&U(e.character,"name"))return e.character.name;if(U(e,"characterName"))return e.characterName}},ns=e=>!!e?.character&&U(e.character,"sprite"),ku=e=>{let n={},t=!1,r=_u(e);return r!==void 0&&(n.name=r,t=!0),ns(e)&&(n.sprite=K(e.character.sprite),t=!0),t?n:void 0},Yi=e=>{e?.character?.sprite?.animations&&(e.character.sprite.animations={})},Hi=({dialogueState:e,dialogueAction:n,persistCharacter:t})=>U(n,"persistSprite")?n.persistSprite===!0:U(e,"persistSprite")?e.persistSprite===!0:t&&!U(n,"characterId"),Wi=({previousCharacter:e,characterFields:n,hasCharacterId:t,persistCharacter:r,persistSprite:o,hasExplicitPersistSprite:i,isAppendingAdvDialogueContent:s})=>{let l={},a=e??{},c=n??{},u=s&&!t,d=u&&!i;return U(c,"name")?l.name=c.name:(r&&!t||u)&&U(a,"name")&&(l.name=K(a.name)),U(c,"sprite")?l.sprite=K(c.sprite):(o||d)&&U(a,"sprite")&&(l.sprite=K(a.sprite)),Object.keys(l).length>0?l:void 0},Ou=({dialogueState:e,content:n,append:t=!1})=>{if(!t||!Array.isArray(n)){e.content=n,delete e.initialRevealedContent;return}let r=Array.isArray(e.content)?e.content:[];r.length>0?e.initialRevealedContent=r.map(o=>K(o)):delete e.initialRevealedContent,e.content=[...r,...n]},$u=()=>({}),Tu=(e,n)=>{if(!n.screen)return;let t=j(n.screen,"opacity"),r=j(n.screen,"blur"),o=U(n.screen,"animations");if(!t&&!r){o||delete e.screen;return}let i=e.screen,s={};if(t?s.opacity=n.screen.opacity:j(i,"opacity")&&(s.opacity=i.opacity),r?s.blur=K(n.screen.blur):j(i,"blur")&&(s.blur=K(i.blur)),U(s,"opacity")&&s.opacity===void 0&&delete s.opacity,U(s,"blur")&&s.blur===void 0&&delete s.blur,Object.keys(s).length===0){delete e.screen;return}e.screen=s},Lu=(e,n)=>{if(n.background){let t=j(n.background,"resourceId"),r=j(n.background,"colorId"),o=j(n.background,"opacity"),i=j(n.background,"blur"),s=j(n.background,"transformId"),l=zi(n.background),a=qi(n.background),{animationsOnly:c,state:u}=zn(n.background,p=>j(p,"resourceId")||j(p,"colorId")||j(p,"opacity")||j(p,"blur")||j(p,"transformId")||zi(p)||qi(p));if(c){e.background=e.background?{...K(e.background),...u}:u;return}if(!t&&!r&&!o&&!i&&!s&&!l&&!a){delete e.background;return}let d=e.background,f=K(n.background);if(!t&&d?.resourceId){f.resourceId=d.resourceId,!U(f,"transformId")&&d.transformId&&(f.transformId=d.transformId);for(let p of Nr)!j(f,p)&&j(d,p)&&(f[p]=d[p])}Su(f,d,{hasAuthoredTransformId:s}),!r&&d?.colorId&&(f.colorId=d.colorId),!o&&j(d,"opacity")&&(f.opacity=d.opacity),!i&&j(d,"blur")&&(f.blur=K(d.blur)),U(f,"resourceId")&&f.resourceId===void 0&&delete f.resourceId,U(f,"colorId")&&f.colorId===void 0&&delete f.colorId,U(f,"animations")&&f.animations===void 0&&delete f.animations,U(f,"transformId")&&f.transformId===void 0&&delete f.transformId,U(f,"opacity")&&f.opacity===void 0&&delete f.opacity,U(f,"blur")&&f.blur===void 0&&delete f.blur;for(let p of Nr)U(f,p)&&f[p]===void 0&&delete f[p];if(!f.resourceId&&!f.colorId){delete e.background;return}d?.resourceId===f.resourceId&&d?.transformId===f.transformId&&!U(f,"animations")&&Gi(d)&&(f.animations=K(d.animations)),e.background=f}else e.background?.animations&&!Gi(e.background)&&(e.background.animations={})},Pu=(e,n)=>{if(!n.dialogue){if(e.dialogue&&(Yi(e.dialogue),e.dialogue.mode==="adv")){e.dialogue.content=void 0,delete e.dialogue.initialRevealedContent,delete e.dialogue.textSpeed;let u=e.dialogue.persistCharacter===!0,d=Hi({dialogueState:e.dialogue,dialogueAction:{},persistCharacter:u});u||delete e.dialogue.characterId,e.dialogue.character=Wi({previousCharacter:e.dialogue.character,characterFields:{},hasCharacterId:!1,persistCharacter:u,persistSprite:d,hasExplicitPersistSprite:!1,isAppendingAdvDialogueContent:!1}),e.dialogue.character||delete e.dialogue.character}return}e.dialogue||(e.dialogue={});let t=e.dialogue.mode;if(n.dialogue.ui){let{animationsOnly:u,state:d}=zn(n.dialogue.ui,f=>!!f.resourceId);u?e.dialogue.ui={...e.dialogue.ui,...d}:e.dialogue.ui={...n.dialogue.ui}}else e.dialogue?.ui?.animations&&(e.dialogue.ui.animations={});n.dialogue.mode==="adv"&&(e.dialogue.content=e.dialogue.content||void 0,e.dialogue.characterId=e.dialogue.characterId||void 0,e.dialogue.mode="adv"),n.dialogue.mode==="nvl"&&(e.dialogue?.mode!=="nvl"&&(e.dialogue.lines=[]),e.dialogue.mode="nvl");let r=n.dialogue.append===!0&&t!=="nvl"&&e.dialogue?.mode!=="nvl"&&Array.isArray(n.dialogue.content);n.dialogue.content!==void 0&&Ou({dialogueState:e.dialogue,content:n.dialogue.content,append:r}),U(n.dialogue,"textSpeed")?e.dialogue.textSpeed=n.dialogue.textSpeed:delete e.dialogue.textSpeed;let o=U(n.dialogue,"persistCharacter")?n.dialogue.persistCharacter===!0:e.dialogue.persistCharacter===!0;o?e.dialogue.persistCharacter=!0:delete e.dialogue.persistCharacter;let i=Hi({dialogueState:e.dialogue,dialogueAction:n.dialogue,persistCharacter:o});U(n.dialogue,"persistSprite")&&(e.dialogue.persistSprite=i);let s=U(n.dialogue,"characterId"),l=ku(n.dialogue),a=ns(n.dialogue);s?n.dialogue.characterId?e.dialogue.characterId=n.dialogue.characterId:delete e.dialogue.characterId:!o&&!r&&delete e.dialogue.characterId;let c=Wi({previousCharacter:e.dialogue.character,characterFields:l,hasCharacterId:s,persistCharacter:o,persistSprite:i,hasExplicitPersistSprite:U(n.dialogue,"persistSprite"),isAppendingAdvDialogueContent:r});if(c?e.dialogue.character=c:delete e.dialogue.character,a||Yi(e.dialogue),n.dialogue.clear){delete e.dialogue;return}if(n.dialogue?.clearPage&&e.dialogue?.mode==="nvl"&&(e.dialogue.lines=[]),e.dialogue?.mode==="nvl"&&n.dialogue.content!==void 0){let u={content:n.dialogue.content,characterId:e.dialogue.characterId??null};e.dialogue.textSpeed!==void 0&&(u.textSpeed=e.dialogue.textSpeed),e.dialogue.character&&(u.character=K(e.dialogue.character)),e.dialogue.lines.push(u)}},Nu=(e,n)=>{if(n.sfx){let t=Array.isArray(n.sfx.items)&&n.sfx.items.length>0,r=Array.isArray(n.sfx.channels)&&n.sfx.channels.length>0;if(!t&&!r){delete e.sfx;return}e.sfx=K(n.sfx)}else e.sfx&&delete e.sfx},Du=(e,n)=>{if(n.bgm){let t=Array.isArray(n.bgm.sounds);if(!n.bgm.resourceId&&!t||t&&n.bgm.sounds.length===0){e.bgm=void 0;return}e.bgm=K(n.bgm),n.bgm.resourceId&&(e.bgm.loop=n.bgm.loop??!0)}},Mu=(e,n)=>{if(n.visual){let t=e.visual?.items||[];n.visual.items?.forEach((i,s)=>{vu(i,Zi(t,i,s))});let{hasValidItems:r,processedItems:o}=es(n.visual.items,Eu,t,{hasPatchFn:Qi,mergeItemFn:xu});r?e.visual={items:o}:delete e.visual}else e.visual?.items&&(e.visual.items=e.visual.items.map(t=>t.animations?{...t,animations:{}}:t))},Vu=(e,n)=>{if(!n.character){e.character?.items&&(e.character.items=e.character.items.map(o=>o.animations?{...o,animations:{}}:o));return}let{hasValidItems:t,processedItems:r}=es(n.character.items,o=>o.sprites&&o.sprites.length>0||o.transformId||o.resourceId,e.character?.items||[]);t?e.character={items:r}:delete e.character},ju=(e,n)=>{n.animation?e.animation=n.animation:e.animation&&delete e.animation},Fu=(e,n)=>{if(n.layout){let{animationsOnly:t,state:r}=zn(n.layout,o=>!!o.resourceId);if(t){e.layout=r;return}if(!n.layout.resourceId){delete e.layout;return}e.layout=n.layout}else e.layout&&delete e.layout},Uu=(e,n)=>{if(n.choice){let{animationsOnly:t,state:r}=zn(n.choice,o=>!!o.resourceId);if(t){e.choice={...e.choice,...r};return}if(!n.choice.resourceId){delete e.choice;return}e.choice=n.choice}else e.choice&&delete e.choice},Bu=(e,n)=>{if(n.form){let{animationsOnly:t,state:r}=zn(n.form,o=>!!o.resourceId);if(t){e.form={...e.form,...r};return}if(!n.form.resourceId){delete e.form;return}e.form=K(n.form)}else e.form&&delete e.form},Gu=(e,n)=>{if(n.control){if(!n.control.resourceId){delete e.control;return}e.control=n.control}},zu=(e,n)=>{if(n.voice){let t=Array.isArray(n.voice.sounds);if(!n.voice.resourceId&&!t||t&&n.voice.sounds.length===0){delete e.voice;return}e.voice=K(n.voice)}else e.voice&&delete e.voice},qu=(e,n)=>{n.cleanAll&&Object.keys(e).forEach(t=>{delete e[t]})},cn=e=>St($u,[qu,Tu,Lu,Nu,Du,Mu,Pu,Vu,ju,Fu,Uu,Bu,Gu,zu])(e);var En=(e,n)=>{if(!e||typeof e!="string"||!e.includes("${"))return e;let t=on(e,n);return t&&typeof t=="object"?e:t};var Yu=Object.freeze({dialogueTextSpeed:{source:"global.dialogueTextSpeed"},autoForwardDelay:{source:"global.autoForwardDelay"},autoForwardSpeed:{source:"global.autoForwardSpeed"},skipUnseenText:{source:"global.skipUnseenText"},skipTransitionsAndAnimations:{source:"global.skipTransitionsAndAnimations"},soundVolume:{source:"global.soundVolume"},musicVolume:{source:"global.musicVolume"},muteAll:{source:"global.muteAll"},saveLoadPagination:{source:"context.runtime.saveLoadPagination"},menuPage:{source:"context.runtime.menuPage"},menuEntryPoint:{source:"context.runtime.menuEntryPoint"},autoMode:{source:"global.autoMode"},skipMode:{source:"global.skipMode"},dialogueUIHidden:{source:"global.dialogueUIHidden"},isLineCompleted:{source:"global.isLineCompleted"}}),ln=Object.freeze({dialogueTextSpeed:50,autoForwardDelay:1e3,autoForwardSpeed:50,skipUnseenText:!1,skipTransitionsAndAnimations:!1,soundVolume:50,musicVolume:50,muteAll:!1,autoMode:!1,skipMode:!1,dialogueUIHidden:!1,isLineCompleted:!1}),qn=Object.freeze({saveLoadPagination:1,menuPage:"",menuEntryPoint:""}),ts=Object.freeze({dialogueTextSpeed:"number",autoForwardDelay:"number",autoForwardSpeed:"number",skipUnseenText:"boolean",skipTransitionsAndAnimations:"boolean",soundVolume:"number",musicVolume:"number",muteAll:"boolean",saveLoadPagination:"number",menuPage:"string",menuEntryPoint:"string",autoMode:"boolean",skipMode:"boolean",dialogueUIHidden:"boolean",isLineCompleted:"boolean"}),Dr=Object.freeze(["dialogueTextSpeed","autoForwardDelay","autoForwardSpeed","skipUnseenText","skipTransitionsAndAnimations","soundVolume","musicVolume","muteAll"]),Mr=Object.freeze(["saveLoadPagination","menuPage","menuEntryPoint"]),Hu=(e,n)=>{if(n.startsWith("global.")){let t=n.slice(7);return e?.global?.[t]}if(n.startsWith("context.runtime.")){let t=n.slice(16),r=Array.isArray(e?.contexts)?e.contexts:[];return r[r.length-1]?.runtime?.[t]}},un=e=>Object.fromEntries(Object.entries(Yu).map(([n,t])=>{let r=Hu(e,t.source),o=r!==void 0?r:ln[n]??qn[n];return[n,o]})),Ye=(e,n)=>un(e)[n],rs=(e={})=>Object.fromEntries(Dr.map(n=>[n,e[n]??ln[n]]));var xn=Object.freeze({VISUAL_BEHIND_BACKGROUND:10,BACKGROUND:20,VISUAL_BEHIND_CHARACTER:30,CHARACTER:40,VISUAL_BEHIND_DIALOGUE:50,DIALOGUE:60,VISUAL_BEHIND_CHOICE:70,CHOICE:80,VISUAL_FOREGROUND:90}),Ne=Object.freeze({BEHIND_BACKGROUND:xn.VISUAL_BEHIND_BACKGROUND,BEHIND_CHARACTER:xn.VISUAL_BEHIND_CHARACTER,BEHIND_DIALOGUE:xn.VISUAL_BEHIND_DIALOGUE,BEHIND_CHOICE:xn.VISUAL_BEHIND_CHOICE,FOREGROUND:xn.VISUAL_FOREGROUND}),Vr=Ne.BEHIND_DIALOGUE,jr=Object.freeze(Object.values(Ne).sort((e,n)=>e-n));var Wu={__arrayOrEmpty:e=>Array.isArray(e)?e:[],objectValues:e=>Object.entries(e).map(([n,t])=>({id:n,...t})),formatDate:$r},Ku=/^\$for\s+([A-Za-z_][A-Za-z0-9_]*)(?:\s*,\s*([A-Za-z_][A-Za-z0-9_]*))?\s+in\s+(.+?)(?::)?$/,Yn=e=>Array.isArray(e)?e.map(n=>{if(!n||typeof n!="object"||Array.isArray(n)||Object.keys(n).length!==1)return Yn(n);let[t]=Object.keys(n),r=Ku.exec(t);if(!r)return Yn(n);let[,o,i,s]=r,l=`$for ${o}${i?`, ${i}`:""} in __arrayOrEmpty(${s.trim()})`,a=Array.isArray(n[t])?n[t]:[];return{[l]:Yn(a)}}):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).map(([n,t])=>[n,Yn(t)])),Me=(e,n)=>{let t={functions:Wu};return on(Yn(e),n,t)},to=({animationType:e,animationId:n,animationPath:t})=>{if(e!==void 0&&!(e==="update"||e==="transition"))throw new Error(`[${t}] Animation "${n}" has unsupported type "${e}". Use "update" or "transition".`)},Ju=({id:e,targetId:n,animation:t,playback:r,animationPath:o="animation"})=>{let i=structuredClone(t);if(to({animationType:i.type,animationId:e,animationPath:o}),delete i.name,delete i.playback,i.id=e,i.targetId=n,r!==void 0){let s=ed(r,`${o}.playback`);if(s!==void 0){let l=s.loop===!0?Is(i):null;if(s.loop===!0&&i.type!=="update")throw new Error(`[${o}.playback] playback.loop is only supported for type "update".`);if(s.loop===!0&&i.complete!==void 0)throw new Error(`[${o}.playback] animation.complete is not allowed when playback.loop is true because a loop never completes.`);if(s.loop===!0&&(!Number.isFinite(l)||l<=0))throw new Error(`[${o}.playback] playback.loop requires an animation with a finite duration greater than 0.`);i.playback=s}}return i},Xu=(e,{animationId:n="animation",animationPath:t="animation"}={})=>{if(!(!e||typeof e!="object"||Array.isArray(e))&&typeof e.type=="string")return to({animationType:e.type,animationId:n,animationPath:t}),e.type},Qu=e=>{if(typeof e=="string")return e;if(!(!e||typeof e!="object"||Array.isArray(e)))return e.resourceId},Zu=e=>{if(!(!e||typeof e!="object"||Array.isArray(e)))return e.playback},ed=(e,n="animation.playback")=>{if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`[${n}] playback must be an object.`);if(e.continuity!==void 0&&e.continuity!=="render"&&e.continuity!=="persistent")throw new Error(`[${n}] playback.continuity must be "render" or "persistent".`);if(e.speed!==void 0&&(typeof e.speed!="number"||!Number.isFinite(e.speed)||e.speed<=0))throw new Error(`[${n}] playback.speed must be a finite number greater than 0.`);if(e.loop!==void 0&&typeof e.loop!="boolean")throw new Error(`[${n}] playback.loop must be a boolean.`);let t={};return e.continuity!==void 0&&(t.continuity=e.continuity),e.speed!==void 0&&e.speed!==1&&(t.speed=e.speed),e.loop===!0&&(t.loop=!0),Object.keys(t).length>0?t:void 0},nd=e=>{let n=e?.playback?.speed;return typeof n=="number"&&Number.isFinite(n)&&n>0?n:1},dn=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),hs=e=>e?.playback?.continuity==="persistent",Hr=e=>Array.isArray(e)?e.map(Hr):!e||typeof e!="object"?e:Object.keys(e).sort().reduce((n,t)=>(n[t]=Hr(e[t]),n),{}),Lt=e=>{if(!e||typeof e!="object"||Array.isArray(e))return null;let n=structuredClone(e);return n.playback&&(delete n.playback.continuity,n.playback.speed===1&&delete n.playback.speed,Object.keys(n.playback).length===0&&delete n.playback),JSON.stringify(Hr(n))},ys=(e=[])=>e.filter(n=>hs(n)).map(n=>structuredClone(n)),bs=e=>Array.isArray(e?.keyframes)?e.keyframes.reduce((n,t)=>{let r=typeof t?.duration=="number"&&Number.isFinite(t.duration)?t.duration:0;return n+r},0):0,Fr=e=>!e||typeof e!="object"||Array.isArray(e)?0:Object.values(e).reduce((n,t)=>Math.max(n,bs(t)),0),Is=e=>Math.max(Fr(e?.tween),Fr(e?.prev?.tween),Fr(e?.next?.tween),bs(e?.mask?.progress)),ws=e=>!e||typeof e!="object"||Array.isArray(e)?0:e.playback?.loop===!0?Number.POSITIVE_INFINITY:Is(e)/nd(e),td=e=>e.some(n=>n?.playback?.loop===!0),os=({animationInstances:e,activePersistentAnimations:n})=>{if(!Array.isArray(e)||e.length===0||!Array.isArray(n)||n.length===0)return!1;let t=new Set(n.map(Lt).filter(Boolean));return e.some(r=>{if(!hs(r))return!1;let o=Lt(r);return o?t.has(o):!1})},ke=({animationInstances:e,isLineCompleted:n,skipTransitionsAndAnimations:t,activePersistentAnimations:r,restoredPersistentAnimations:o,isAuthoredOnCurrentLine:i=!0})=>!Array.isArray(e)||e.length===0||t?!1:td(e)||i&&!n||os({animationInstances:e,activePersistentAnimations:r})?!0:i?!1:os({animationInstances:e,activePersistentAnimations:o}),rd=e=>!e||typeof e!="object"||Array.isArray(e)?!1:["in","out","update"].some(n=>e[n]!==void 0),od=(e,n)=>{if(rd(e))throw new Error(`[${n}] Legacy animations.in/out/update is no longer supported. Use a single animations.resourceId reference.`)},id=({resources:e,animationId:n,playback:t,instanceId:r,targetId:o,animationPath:i="animation"})=>{if(!n||!o)return!1;let s=e?.animations?.[n];return s?Ju({id:r,targetId:o,animation:s,playback:t,animationPath:i}):null},sd=(e,{defaultTargetId:n,defaultId:t,animationPath:r="animation"}={})=>{if(!e||typeof e!="object"||Array.isArray(e))return e;let o=structuredClone(e);return to({animationType:o.type,animationId:o.id??t,animationPath:r}),o.id??=t,o.targetId??=n,o},ro=({animations:e,transitions:n,defaultTargetId:t,idPrefix:r,animationPathPrefix:o=r})=>{n.forEach((i,s)=>{e.push(sd(i,{defaultTargetId:t,defaultId:`${r}-transition-${s}`,animationPath:`${o}.transitions[${s}]`}))})},Wr=(e,n)=>{if(e===void 0)return[];if(!Array.isArray(e)||e.some(t=>t===null||typeof t!="object"||Array.isArray(t)))throw new Error(`${n} must be an array of objects`);return e},ad=({content:e,path:n,variables:t})=>Wr(e,n).reduce((r,o)=>{let i=En(o.text,{variables:t});return r+`${i??""}`.length},0),is=(e=[])=>{let n=new Map;for(let t of e)t?.id&&n.set(t.id,(n.get(t.id)??0)+1);return new Set(Array.from(n.entries()).filter(([,t])=>t>1).map(([t])=>t))},Ot=(e,n=0,t=new Set)=>{if(!t.has(e?.id))return`character-container-${e.id}`;let r=e?.sprites?.map(({resourceId:o})=>o)||[];return r.length===0?`character-container-${e.id}`:`character-container-${e.id}-${n}-${r.join("-")}`},Hn=(e,n)=>{if(!n.transformId)throw new Error(`Visual item "${n.id}" requires transformId`);let t=e.transforms?.[n.transformId];if(!t)throw new Error(`Transform "${n.transformId}" not found for visual item "${n.id}"`);return t},cd=(e,n={})=>{if(!n?.transformId)return;let t=e.transforms?.[n.transformId];if(!t)throw new Error(`Transform "${n.transformId}" not found for background`);return t},ld=["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"],ud=(e={})=>ld.some(n=>dn(e,n)),As=(e={},n)=>{if(n){if(e.images?.[n])return"sprite";if(e.videos?.[n])return"video";if(e.spritesheets?.[n])return"spritesheet-animation";if(e.layouts?.[n])return"container"}},Tt=({resourceId:e,kind:n})=>{if(e)return n?`bg-cg-background-${n}`:`bg-cg-${e}`},dd=(e={})=>e.textStyles||{},fd=(e={})=>e.images||{},pd=.5,md=(e={},n,t)=>{if(n){if(!e.animations?.[n])throw new Error(`Animation '${n}' not found in spritesheet resource '${t}'`);return n}return Object.keys(e.animations??{})[0]},Es=({id:e,resourceId:n,spritesheet:t,animationName:r,animationSpeed:o,loop:i,transform:s={}}={})=>{let l=md(t,r,n),a=l?t.animations?.[l]:void 0;if(!a){console.warn(`Spritesheet animation not found: ${n}`);return}return{id:e,type:"spritesheet-animation",...s,width:t.width,height:t.height,src:t.fileId,atlas:t.jsonData,playback:{frames:a.frames,animationSpeed:o??a.animationSpeed??pd,loop:i??a.loop??!0}}},xs=({id:e,item:n,resources:t={}}={})=>{let r=t.images?.[n.resourceId];if(r)return{type:"sprite",id:e,src:r.fileId,width:r.width,height:r.height,x:0,y:0};let o=t.spritesheets?.[n.resourceId];if(o)return Es({id:e,resourceId:n.resourceId,spritesheet:o,animationName:n.animationName,animationSpeed:n.animationSpeed,loop:n.loop,transform:{x:0,y:0}});console.warn(`Character sprite resource not found: ${n.resourceId}`)},gd=(e={})=>e.colors||{},hd=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Kn=(e,n)=>e==="root"?`${n}`:`${e}.${n}`,Rn=(e,n,t)=>{if(typeof e!="string"||e.length===0)throw new Error(`${t} at "${n}" must resolve to a non-empty string`)},Ur=(e,n,t)=>{if(e===void 0)return 1;if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${n} for text style "${t}" must be a number between 0 and 1`);if(e<0||e>1)throw new Error(`${n} for text style "${t}" must be a number between 0 and 1`);return e},Br=(e,n,t,r,{minimum:o}={})=>{if(e===void 0)return r;if(typeof e!="number"||!Number.isFinite(e)||o!==void 0&&e<o){let i=o===void 0?"a finite number":`a finite number >= ${o}`;throw new Error(`shadow.${n} for text style "${t}" must be ${i}`)}return e},Dt=(e,n)=>{if(typeof e!="string"||!hd.test(e))throw new Error(`${n} must resolve to a hex color`);return e.length===4?`#${e.slice(1).split("").map(t=>t.repeat(2)).join("")}`:e},ss=(e,n,t)=>{let r=Dt(e,t);if(n===1)return r;let o=Number.parseInt(r.slice(1,3),16),i=Number.parseInt(r.slice(3,5),16),s=Number.parseInt(r.slice(5,7),16);return`rgba(${o}, ${i}, ${s}, ${n})`},yd=(e={},n)=>{let t=dd(e)?.[n];if(!t)throw new Error(`Text style "${n}" not found`);let o=(Array.isArray(t.fontId)?t.fontId:[t.fontId]).map(a=>{let c=e.fonts?.[a];if(!c)throw new Error(`Font "${a}" not found for text style "${n}"`);return c.fileId}),i=e.colors?.[t.colorId];if(!i)throw new Error(`Color "${t.colorId}" not found for text style "${n}"`);let s=Ur(t.colorAlpha,"colorAlpha",n),l={fontFamily:Array.isArray(t.fontId)?o.join(", "):o[0],fontSize:t.fontSize??16,fontWeight:t.fontWeight??"400",fontStyle:t.fontStyle??"normal",lineHeight:t.lineHeight??1.2,fill:ss(i.hex,s,`Color "${t.colorId}" for text style "${n}"`)};if(t.align!==void 0&&(l.align=t.align),t.wordWrap!==void 0&&(l.wordWrap=t.wordWrap),t.breakWords!==void 0&&(l.breakWords=t.breakWords),t.wordWrapWidth!==void 0&&(l.wordWrapWidth=t.wordWrapWidth),t.strokeColorId){let a=e.colors?.[t.strokeColorId];if(!a)throw new Error(`Stroke color "${t.strokeColorId}" not found for text style "${n}"`);let c=Ur(t.strokeAlpha,"strokeAlpha",n);l.strokeColor=ss(a.hex,c,`Stroke color "${t.strokeColorId}" for text style "${n}"`)}else if(t.strokeAlpha!==void 0)throw new Error(`strokeAlpha for text style "${n}" requires strokeColorId`);if(t.strokeWidth!==void 0&&(l.strokeWidth=t.strokeWidth),t.shadow!==void 0){let a=e.colors?.[t.shadow.colorId];if(!a)throw new Error(`Shadow color "${t.shadow.colorId}" not found for text style "${n}"`);l.shadow={color:Dt(a.hex,`Shadow color "${t.shadow.colorId}" for text style "${n}"`),alpha:Ur(t.shadow.alpha,"shadow.alpha",n),blur:Br(t.shadow.blur,"blur",n,0,{minimum:0}),offsetX:Br(t.shadow.offsetX,"offsetX",n,2),offsetY:Br(t.shadow.offsetY,"offsetY",n,2)}}return l},Kr=(e,n={},t="root")=>{if(Array.isArray(e))return e.map((o,i)=>Kr(o,n,`${t}[${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 "${t}". Use textStyleId instead`);let r={};for(let[o,i]of Object.entries(e))o!=="textStyleId"&&(r[o]=Kr(i,n,Kn(t,o)));return e.textStyleId!==void 0&&(Rn(e.textStyleId,t,"textStyleId"),r.textStyle=yd(n,e.textStyleId)),r},oo=(e={},n)=>{let t=gd(e)?.[n];if(!t)throw new Error(`Color "${n}" not found`);return Dt(t.hex,`Color "${n}"`)},vs=e=>e==="hover.fill"?"hover.colorId":e==="click.fill"?"click.colorId":e==="rightClick.fill"?"rightClick.colorId":"colorId",Gr=(e,n,t)=>{let r=e?.[n];if(!(!r||typeof r!="object"||Array.isArray(r))&&Object.prototype.hasOwnProperty.call(r,"fill"))throw new Error(`Inline ${n}.fill is not allowed in rect layout elements at "${t}". Use ${vs(`${n}.fill`)} instead`)},bd=(e,n={},t="root")=>{if(Array.isArray(e))return e.map((o,i)=>Jn(o,n,`${t}[${i}]`));if(!e||typeof e!="object")return e;let r={};for(let[o,i]of Object.entries(e))o!=="colorId"&&(r[o]=Jn(i,n,Kn(t,o)));return e.colorId!==void 0&&(Rn(e.colorId,t,"colorId"),r.fill=oo(n,e.colorId)),r},Jn=(e,n={},t="root")=>{if(Array.isArray(e))return e.map((o,i)=>Jn(o,n,`${t}[${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 "${t}". Use ${vs("fill")} instead`);Gr(e,"hover",t),Gr(e,"click",t),Gr(e,"rightClick",t)}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]=bd(i,n,Kn(t,o));continue}r[o]=Jn(i,n,Kn(t,o))}return e.type==="rect"&&e.colorId!==void 0&&(Rn(e.colorId,t,"colorId"),r.fill=oo(n,e.colorId)),r},zr=(e={},n)=>{let t=fd(e)?.[n];return t||null},Ss=e=>e==="hoverUrl"||e==="hoverSrc"||e==="hover.src"?"hoverImageId":e==="clickUrl"||e==="clickSrc"||e==="click.src"?"clickImageId":"imageId",as=(e,n,t,r)=>{let o=e?.[n];if(!(!o||typeof o!="object"||Array.isArray(o))&&Object.prototype.hasOwnProperty.call(o,r))throw new Error(`Inline ${n}.${r} is not allowed in sprite layout elements at "${t}". Use ${Ss(`${n}.${r}`)} instead`)},cs=(e,n,t)=>{let r=e[n];e[n]={...r&&typeof r=="object"&&!Array.isArray(r)?r:{},src:t}},Jr=(e,n={},t="root")=>{if(Array.isArray(e))return e.map((o,i)=>Jr(o,n,`${t}[${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 "${t}". Use ${Ss(o)} instead`);as(e,"hover",t,"src"),as(e,"click",t,"src")}let r={};for(let[o,i]of Object.entries(e))e.type==="sprite"&&(o==="imageId"||o==="hoverImageId"||o==="clickImageId")||(r[o]=Jr(i,n,Kn(t,o)));if(e.type==="sprite"&&e.imageId!==void 0){Rn(e.imageId,t,"imageId");let o=zr(n,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&&(Rn(e.hoverImageId,t,"hoverImageId"),cs(r,"hover",zr(n,e.hoverImageId)?.fileId??e.hoverImageId)),e.type==="sprite"&&e.clickImageId!==void 0&&(Rn(e.clickImageId,t,"clickImageId"),cs(r,"click",zr(n,e.clickImageId)?.fileId??e.clickImageId)),r},io=(e,n={},t="root")=>Jr(Jn(Kr(e,n,t),n,t),n,t),Ve=io,fn=(e=[])=>e.find(n=>n.id==="story"),Id="#000000",Xr="bg-cg-background-color",wd=({resources:e={},background:n={},screen:t})=>n?.colorId===void 0?Dt(t?.backgroundColor??Id,"screen.backgroundColor"):oo(e,n.colorId),Rs=(e={})=>{if(dn(e,"opacity"))return typeof e.opacity=="number"?e.opacity:void 0},Ad=(e={})=>{if(!(!e.blur||typeof e.blur!="object"||Array.isArray(e.blur)))return e.blur},ls=(e={},{includeDefaultAlpha:n=!1}={})=>{let t=Rs(e),r=Ad(e),o={};return(n||t!==void 0)&&(o.alpha=t??1),r&&(o.blur=r),o},Ed=(e={})=>{if(dn(e,"opacity"))return typeof e.opacity=="number"?e.opacity:void 0},xd=(e={})=>{if(!(!e.blur||typeof e.blur!="object"||Array.isArray(e.blur)))return e.blur},Cs=(e={})=>{let n=Ed(e),t=xd(e),r={};return n!==void 0&&(r.alpha=n),t&&(r.blur=t),r},Sn=(e={})=>Cs(e),De=(e={},n={})=>{let t={x:n.x??e.x,y:n.y??e.y,anchorX:n.anchorX??e.anchorX,anchorY:n.anchorY??e.anchorY,rotation:n.rotation??e.rotation,scaleX:n.scaleX??e.scaleX,scaleY:n.scaleY??e.scaleY},r=n.originX??e.originX,o=n.originY??e.originY;return r!==void 0&&(t.originX=r),o!==void 0&&(t.originY=o),t},vd=["id","type","resourceId","transformId","x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY","layer","opacity","blur","animations"],so=(e={})=>e.text&&dn(e.text,"content")&&dn(e.text,"textStyleId"),us=(e={})=>{if(e.resourceId)return e.resourceId;if(so(e))return"text"},ds=(e,n={})=>typeof e=="string"?n.images?.[e]?.fileId??e:!e||typeof e!="object"||Array.isArray(e)?e:e.imageId?n.images?.[e.imageId]?.fileId??e.imageId:Array.isArray(e.items)?{...e,items:e.items.map(t=>{if(typeof t=="string")return n.images?.[t]?.fileId??t;if(!t||typeof t!="object"||Array.isArray(t))return t;if(t.imageId){let{imageId:r,...o}=t;return{...o,src:n.images?.[r]?.fileId??r}}return typeof t.src=="string"?{...t,src:n.images?.[t.src]?.fileId??t.src}:t})}:e,Sd=({item:e,particle:n,resources:t})=>{let r=Hn(t,e),o=structuredClone(n),i=o.modules?.appearance?.texture;i!==void 0&&(o.modules.appearance.texture=ds(i,t)),o.texture!==void 0&&(o.texture=ds(o.texture,t));let s={id:`visual-${e.id}`,type:"container",children:[{...o,id:`visual-${e.id}-particles`,type:"particles",x:0,y:0}],...De(r,e)};return Object.assign(s,Sn(e)),s},Rd=e=>{if(e.text){if(e.resourceId)throw new Error(`Visual item "${e.id}" cannot define both resourceId and text`);if(!so(e))throw new Error(`Visual item "${e.id}" text requires content and textStyleId`);for(let n of vd)if(dn(e.text,n))throw new Error(`Visual item "${e.id}" text.${n} is reserved for the visual item`)}},Cd=({resources:e,background:n,screen:t={width:1920,height:1080},includeOpacity:r=!1})=>{let o={id:Xr,type:"rect",x:0,y:0,width:t?.width??1920,height:t?.height??1080,fill:wd({resources:e,background:n,screen:t})};if(r){let i=Rs(n);i!==void 0&&(o.alpha=i)}return o},_d=(e={},n)=>n?!!(e.images?.[n]||e.videos?.[n]||e.spritesheets?.[n]||e.layouts?.[n]):!1,fs=({resources:e={},resourceId:n,colorId:t})=>{let r=As(e,n);return n&&(r||t===void 0)?{resourceId:n,targetId:Tt({resourceId:n,kind:r})}:t!==void 0?{resourceId:Xr,targetId:Xr}:{resourceId:void 0,targetId:void 0}},_s=100,He=_s,kd="channel:bgm",Od="channel:music-room",$d="music-room:player",Td="channel:voice",Ld="default",Pd=e=>String(e).replaceAll("%","%25").replaceAll(":","%3A"),Wn=(...e)=>e.map(Pd).join(":"),Pt=(e,n,t)=>{let r=new Set;e.forEach(({id:o})=>{if(r.has(o)){let i=t?` in ${t}`:"";throw new Error(`Duplicate ${n} id "${o}"${i}.`)}r.add(o)})},Nd=(e,n)=>e*n/_s,ks=(e={},n)=>e?.[n]??ln[n],Mt=(e={},n,t=He)=>Nd(t,ks(e,n)),Vt=({id:e,volume:n,muted:t,pan:r,loop:o,playback:i,interruption:s,children:l,runtime:a})=>{let c={id:e,type:"audio-channel",volume:n,muted:!!a?.muteAll||(t??!1),pan:r??0,children:l};return o!==void 0&&(c.loop=o),i!==void 0&&(c.playback=structuredClone(i)),s!==void 0&&(c.interruption=s),c},$t=(e,n,t,r)=>e[t]!==void 0?e[t]:n[t]!==void 0?n[t]:r,Dd=["muted","pan","playbackRate","startAt","endAt"],jt=({id:e,sound:n,resource:t,defaultLoop:r=!1})=>{let o={id:e,type:"sound",src:t.fileId,loop:$t(n,t,"loop",r),volume:$t(n,t,"volume",He),startDelayMs:$t(n,t,"startDelayMs",0)};Dd.forEach(s=>{let l=$t(n,t,s,void 0);l!==void 0&&(o[s]=l)}),n.playback!==void 0&&(o.playback=structuredClone(n.playback));let i=o.startAt??0;if(o.endAt!==void 0&&o.endAt!==null&&o.endAt<i)throw new Error(`Sound "${e}" endAt (${o.endAt}) must be greater than or equal to startAt (${i}).`);return o},Re=({variables:e,imageGallery:n,musicRoom:t,sceneReplay:r,runtime:o,saveSlots:i=[],dialogueState:s,includeInactiveAdvDialogue:l=!1,isLineCompleted:a,autoMode:c,skipMode:u,isChoiceVisible:d,isFormVisible:f,canRollback:p,confirmDialog:g,form:h,historyDialogue:b=[],characters:I={},dialogueUIHidden:E,skipOnlyViewedLines:A,skipTransitionsAndAnimations:$}={})=>{let B={dialogueTextSpeed:o?.dialogueTextSpeed??50,autoForwardDelay:o?.autoForwardDelay??1e3,autoForwardSpeed:o?.autoForwardSpeed??50,skipUnseenText:o?.skipUnseenText??!1,skipTransitionsAndAnimations:o?.skipTransitionsAndAnimations??!1,soundVolume:o?.soundVolume??50,musicVolume:o?.musicVolume??50,muteAll:o?.muteAll??!1,saveLoadPagination:o?.saveLoadPagination??1,menuPage:o?.menuPage??"",menuEntryPoint:o?.menuEntryPoint??"",autoMode:o?.autoMode??c??!1,skipMode:o?.skipMode??u??!1,dialogueUIHidden:o?.dialogueUIHidden??E??!1,isLineCompleted:o?.isLineCompleted??a??!1},L=Ud({dialogueState:s,includeInactiveAdvDialogue:l,characters:I,variables:e,runtime:B}),T={variables:e,imageGallery:n,musicRoom:t,sceneReplay:r,runtime:B,saveSlots:i,isChoiceVisible:d,isFormVisible:f,canRollback:p,confirmDialog:g,form:h,historyDialogue:b,characters:I};return L&&(T.dialogue=L,T.dialogueLines=L.lines),T},ps=100,Nt=(e,n)=>{if(Array.isArray(e))return e.map(r=>Nt(r,n));if(!e||typeof e!="object")return e;let t={...e};return Object.keys(t).forEach(r=>{t[r]=Nt(t[r],n)}),t.type==="text-revealing"?n(t):t},Md=e=>Nt(e,n=>({...n,revealEffect:"none"})),Vd=e=>Nt(e,n=>{let t=Number(n.speed??n.displaySpeed),r=Number.isFinite(t)?Math.max(t,ps):ps;return{...n,speed:r,...Object.prototype.hasOwnProperty.call(n,"displaySpeed")?{displaySpeed:r}:{}}}),We=(e,{isLineCompleted:n=!1,skipMode:t=!1,skipTransitionsAndAnimations:r=!1}={})=>n||r?Md(e):t?Vd(e):e,Os=({id:e,screen:n={width:1920,height:1080}})=>({id:e,type:"rect",fill:"transparent",width:n.width,height:n.height,x:0,y:0,click:{payload:{actions:{}}}}),Qr=e=>{if(Array.isArray(e))return e.map(Qr);if(!e||typeof e!="object")return e;let n={};for(let[i,s]of Object.entries(e))n[i]=Qr(s);let t=n.click?.payload;if(!t||typeof t!="object"||Array.isArray(t))return n;let r=t.actions,o=r&&typeof r=="object"&&!Array.isArray(r)&&Object.prototype.hasOwnProperty.call(r,"nextLine")?{...r.nextLine,bypassChoice:!0}:void 0;return{...n,click:{...n.click,payload:{...t,bypassChoice:!0,...o?{actions:{...r,nextLine:o}}:{}}}}},jd=new Set(["click","change","submit","focusEvent","blurEvent","selectionChange","compositionStart","compositionUpdate","compositionEnd"]),ms="submit",qr=(e,n,t={})=>{let r=e?.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{},o=r.actions&&typeof r.actions=="object"?r.actions:{},i=t.replaceActions===!0?n:{...o,...n};return{...e||{},payload:{...r,actions:i}}},Zr=(e,n,t={})=>{if(Array.isArray(e))return e.map(c=>Zr(c,n,t));if(!e||typeof e!="object")return e;let r=typeof e.type=="string",o=r&&e.formRole===ms,i=r&&t.submitRoleAncestor,s=o||i?{submitRoleAncestor:!0}:{},l={};for(let[c,u]of Object.entries(e))l[c]=Zr(u,n,c==="children"?s:{});let a=l;if(a.type==="input"&&typeof a.field=="string"){let c=n?.fields?.[a.field];if(c){let u={updateFormField:{formKey:n.key,field:c.id,value:"_event.value"}};a={...a,value:c.value,placeholder:a.placeholder===void 0?c.placeholder:a.placeholder,multiline:a.multiline===void 0?c.multiline:a.multiline,...a.maxLength===void 0&&c.maxLength!==void 0?{maxLength:c.maxLength}:{},change:qr(a.change,u),submit:qr(a.submit,n.submitActions)}}}return a.formRole===ms||i?{...a,click:qr(a.click,n.submitActions,{replaceActions:!0})}:a},eo=(e,n)=>{if(Array.isArray(e))return e.map(r=>eo(r,n));if(!e||typeof e!="object")return e;let t={};for(let[r,o]of Object.entries(e))t[r]=eo(o,n);for(let r of jd){let o=t[r]?.payload;!o||typeof o!="object"||Array.isArray(o)||(t[r]={...t[r],payload:{...o,_interactionSource:"form"}})}return t},no=({characterId:e,character:n,characterName:t,characters:r={},variables:o={}}={})=>{let i=e?r?.[e]:void 0,s=Rt({characterId:e,character:n,characterName:t,characters:r,variables:o});return{...i||{},...n||{},name:s}},$s=(e=[],n={},t={})=>e.map(r=>{let o=no({characterId:r.characterId,character:r.character,characterName:r.characterName,characters:n,variables:t}),i=typeof r.text=="string"?r.text:Array.isArray(r.content)?r.content.map(s=>s?.text??"").join(""):"";return{...r,text:i,character:o,characterName:o.name}}),Fd=e=>!(!e||e.mode==="adv"&&e.content===void 0),Ud=({dialogueState:e,includeInactiveAdvDialogue:n=!1,characters:t={},variables:r,runtime:o}={})=>{if(!n&&!Fd(e))return;let i=e.content===void 0?[{text:""}]:Wr(e.content,"dialogue.content"),s=e.content===void 0?0:ad({content:e.initialRevealedContent,path:"dialogue.initialRevealedContent",variables:r}),l=o?.dialogueTextSpeed??ln.dialogueTextSpeed,a=e.textSpeed??l,c=(e.lines||[]).map((d,f)=>{let p=Wr(d.content,`dialogue.lines[${f}].content`),g=no({characterId:d.characterId,character:d.character,characterName:d.characterName,characters:t,variables:r});return{...d,textSpeed:d.textSpeed??l,content:p.map(h=>({...h,text:En(h.text,{variables:r})})),character:g,characterName:g.name}}),u=no({characterId:e.characterId,character:e.character,characters:t,variables:r});return{characterId:e.characterId,persistCharacter:e.persistCharacter,persistSprite:e.persistSprite,character:u,textSpeed:a,content:i.map(d=>({...d,text:En(d.text,{variables:r})})),initialRevealedCharacters:s,lines:c}},Ts=({container:e,resources:n,templateData:t,isLineCompleted:r=!1,skipMode:o=!1,skipTransitionsAndAnimations:i=!1})=>{let s=Me(e,t);return Ve(We(s,{isLineCompleted:r,skipMode:o,skipTransitionsAndAnimations:i}),n)},Yr=(e,n={})=>e?.payload&&typeof e.payload=="object"?structuredClone(e.payload):e?.actions&&typeof e.actions=="object"?{actions:structuredClone(e.actions)}:structuredClone(n),gs=({renderStateKeyboard:e,keyboard:n,phase:t})=>{!n||typeof n!="object"||Array.isArray(n)||Object.entries(n).forEach(([r,o])=>{let i=e[r]??{},s=t==="keydown"?o?.keydown:o?.keyup;if(t==="keydown"&&s&&typeof s=="object"){e[r]={...i,keydown:{payload:Yr(s)}},o?.keyup&&typeof o.keyup=="object"&&(e[r].keyup={payload:Yr(o.keyup)});return}e[r]={...i,[t]:{payload:Yr(o)}}})},Bd=(e={},n={})=>{let t={};return gs({renderStateKeyboard:t,keyboard:e,phase:"keydown"}),gs({renderStateKeyboard:t,keyboard:n,phase:"keyup"}),Object.keys(t).length>0?t:void 0},je=({animationsDef:e,resources:n,previousResourceId:t,currentResourceId:r,previousTargetId:o,currentTargetId:i,animationPath:s,idPrefix:l})=>{if(!e)return[];let a=[],c=({instanceId:I,targetId:E})=>{let A=id({resources:n,animationId:p,playback:g,instanceId:I,targetId:E,animationPath:s});A&&a.push(A)},u=t!=null&&t!==!1,d=r!=null&&r!==!1,f=o&&i&&o===i;od(e,s);let p=Qu(e),g=Zu(e),h=n?.animations?.[p],b=Xu(h,{animationId:p,animationPath:s});if(b==="update")return d&&i?c({instanceId:`${l}-animation-update`,targetId:i}):u&&o&&c({instanceId:`${l}-animation-update`,targetId:o}),a;if(b==="transition"){let I=`${l}-animation-transition`,E=g?.continuity==="persistent"?I:`${l}-animation-in`;if(u&&d&&f)return c({instanceId:I,targetId:i}),a;u&&c({instanceId:`${l}-animation-out`,targetId:o}),d&&c({instanceId:E,targetId:i})}return a},Gd=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),zd=(e,{presentationState:n,previousPresentationState:t,currentLineActions:r,resources:o={},screen:i={width:1920,height:1080},isLineCompleted:s,skipTransitionsAndAnimations:l,variables:a,imageGallery:c,musicRoom:u,sceneReplay:d,runtime:f,activePersistentAnimations:p,restoredPersistentAnimations:g,autoMode:h,skipMode:b,isChoiceVisible:I,isFormVisible:E,canRollback:A,form:$,saveSlots:B=[]})=>{let{elements:L,animations:T}=e;if(n.background){let z=r===void 0?!0:dn(r?.background??{},"animations"),G=L.find(fe=>fe.id==="story");if(!G)return e;let S=cd(o,n.background),q=S||ud(n.background),W=t?.background?.resourceId,me=t?.background?.colorId,Y=n.background.resourceId??(n.background.animations?W:void 0),ae=n.background.colorId??(n.background.animations?me:void 0),oe=_d(o,Y),ge={...n.background,colorId:ae};if((ae!==void 0||oe)&&G.children.push(Cd({resources:o,background:ge,screen:i,includeOpacity:!oe})),Y){let{images:fe={},videos:le={},spritesheets:x={}}=o,C=As(o,Y),O;if(C==="sprite"?O=fe[Y]:C==="video"?O=le[Y]:C==="spritesheet-animation"&&(O=x[Y]),O){let Q=C==="video",Ie=C==="spritesheet-animation",H={x:(i?.width??1920)/2,y:(i?.height??1080)/2,anchorX:.5,anchorY:.5,rotation:0,scaleX:1,scaleY:1,...S},Te={...ls(n.background,{includeDefaultAlpha:!0}),...De(H,n.background)},he;Ie?he=Es({id:Tt({resourceId:Y,kind:C}),resourceId:Y,spritesheet:O,animationName:n.background.animationName,animationSpeed:n.background.animationSpeed,loop:n.background.loop,transform:Te}):he={id:Tt({resourceId:Y,kind:C}),type:Q?"video":"sprite",src:O.fileId,width:O.width,height:O.height,...Te},Q&&(he.loop=n.background.loop??!1,he.volume=O.volume??50),he&&G.children.push(he)}}if(Y){let{layouts:fe={}}=o,le=fe[Y];if(le){let x={id:Tt({resourceId:Y,kind:"container"}),type:"container",children:le.elements,...ls(n.background)};q&&Object.assign(x,De({x:0,y:0,anchorX:0,anchorY:0,rotation:0,scaleX:1,scaleY:1,...S},n.background));let C=Me(x,Re({variables:a,imageGallery:c,musicRoom:u,sceneReplay:d,runtime:f,saveSlots:B,dialogueState:n.dialogue,isLineCompleted:s,autoMode:h,skipMode:b,isChoiceVisible:I,isFormVisible:E,canRollback:A,form:$,characters:o.characters||{},skipTransitionsAndAnimations:l}));G.children.push(Ve(We(C,{isLineCompleted:s,skipMode:b,skipTransitionsAndAnimations:l}),o))}}let $e=fs({resources:o,resourceId:W,colorId:me}),ce=fs({resources:o,resourceId:Y,colorId:ae}),te=je({animationsDef:n.background.animations,resources:o,previousResourceId:$e.resourceId,currentResourceId:ce.resourceId,previousTargetId:$e.targetId,currentTargetId:ce.targetId,animationPath:"background.animations",idPrefix:"bg-cg"});ke({animationInstances:te,isLineCompleted:s,skipTransitionsAndAnimations:l,activePersistentAnimations:p,restoredPersistentAnimations:g,isAuthoredOnCurrentLine:z})&&T.push(...te)}return e},qd=(e,{presentationState:n,previousPresentationState:t,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})=>{let{elements:l,animations:a}=e;if(n.character&&r){let c=l.find(g=>g.id==="story");if(!c)return e;let u=n.character.items||[],d=t?.character?.items||[],f=is(u),p=is(d);for(let g=0;g<u.length;g++){let h=u[g],{transformId:b,sprites:I}=h,E=d.find(q=>q.id===h.id),A=d.findIndex(q=>q.id===h.id),$=E?.sprites&&E.sprites.length>0,B=I&&I.length>0,L=A>=0?Ot(E,A,p):void 0,T=je({animationsDef:h.animations,resources:r,previousResourceId:L,currentResourceId:B?Ot(h,g,f):void 0,previousTargetId:L,currentTargetId:B?Ot(h,g,f):void 0,animationPath:`character.items[${g}].animations`,idPrefix:"character"});if(h.animations&&!I&&!b&&$&&ke({animationInstances:T,isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})){a.push(...T);continue}if(h.animations&&!I&&!b)continue;if(!I||I.length===0||!b){console.warn("Character item missing sprites or transformId:",h);continue}let z=Ot(h,g,f),G=r.transforms[b];if(!G){console.warn("Transform not found:",b);continue}let S={type:"container",id:z,...De(G,h),...Sn(h),children:[]};for(let q of I){let W=xs({id:`${z}-${q.id}`,item:q,resources:r});W&&S.children.push(W)}c.children.push(S),ke({animationInstances:T,isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})&&a.push(...T)}}return e},Ls=(e,n)=>{if(!jr.includes(e))throw new Error(`${n} must be one of: ${jr.join(", ")}.`)},Yd=(e,n)=>{let t=!!e.resourceId||so(e),r=e.layer??(t?void 0:n?.layer)??Vr;return Ls(r,`Visual item "${e.id}" layer`),r},Hd=(e,{presentationState:n,previousPresentationState:t,resources:r,isLineCompleted:o,skipTransitionsAndAnimations:i,variables:s,imageGallery:l,musicRoom:a,sceneReplay:c,runtime:u,activePersistentAnimations:d,autoMode:f,skipMode:p,isChoiceVisible:g,isFormVisible:h,canRollback:b,form:I,saveSlots:E=[],visualLayer:A})=>{let{elements:$,animations:B}=e;if(n.visual&&r){let L=$.find(S=>S.id==="story");if(!L)return e;let T=n.visual.items,z=t?.visual?.items||[],G=Re({variables:s,imageGallery:l,musicRoom:a,sceneReplay:c,runtime:u,saveSlots:E,dialogueState:n.dialogue,isLineCompleted:o,autoMode:f,skipMode:p,isChoiceVisible:g,isFormVisible:h,canRollback:b,form:I,characters:r.characters||{},skipTransitionsAndAnimations:i});A!==void 0&&Ls(A,"visualLayer");for(let S of T){let q=z.find(oe=>oe.id===S.id),W=Yd(S,q);if(A!==void 0&&W!==A)continue;if(Rd(S),S.text){let oe=Hn(r,S),ge={...structuredClone(S.text),id:`visual-${S.id}`,type:"text",...De(oe,S)};Object.assign(ge,Sn(S)),L.children.push(Ve(Me(ge,G),r))}if(S.resourceId){let{images:oe={},videos:ge={},spritesheets:$e={}}=r,ce=$e[S.resourceId];if(ce){let te=Hn(r,S),fe=S.animationName;if(fe){let le=ce.animations?.[fe];if(!le)throw new Error(`Animation '${fe}' not found in spritesheet resource '${S.resourceId}'`);let x=Sn(S),C={id:`visual-${S.id}`,type:"spritesheet-animation",...De(te,S),width:S.width??ce.width,height:S.height??ce.height,alpha:x.alpha??S.alpha??1,src:ce.fileId,atlas:ce.jsonData,playback:{frames:le.frames,animationSpeed:S.animationSpeed??le.animationSpeed??.5,loop:S.loop??le.loop??!0}};x.blur&&(C.blur=x.blur),L.children.push(structuredClone(C))}}else{let te=oe[S.resourceId]||ge[S.resourceId];if(te){let fe=ge[S.resourceId]!==void 0,le=Hn(r,S),x={id:`visual-${S.id}`,type:fe?"video":"sprite",src:te.fileId,width:te.width,height:te.height,...De(le,S)};Object.assign(x,Sn(S)),fe&&(x.loop=te.loop??!1,x.volume=te.volume??50),L.children.push(x)}}}if(S.resourceId){let oe=r.particles?.[S.resourceId];oe&&L.children.push(Sd({item:S,particle:oe,resources:r}))}if(S.resourceId){let{layouts:oe={}}=r,ge=oe[S.resourceId];if(ge){let $e=Hn(r,S),ce={id:`visual-${S.id}`,type:"container",children:structuredClone(ge.elements),...De($e,S)};Object.assign(ce,Sn(S));let te=Me(ce,G);L.children.push(Ve(We(te,{isLineCompleted:o,skipMode:p,skipTransitionsAndAnimations:i}),r))}}let me=us(q),Y=us(S),ae=je({animationsDef:S.animations,resources:r,previousResourceId:me,currentResourceId:Y,previousTargetId:me?`visual-${S.id}`:void 0,currentTargetId:Y?`visual-${S.id}`:void 0,animationPath:`visual.items[${S.id}].animations`,idPrefix:S.id});ke({animationInstances:ae,isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:d})&&B.push(...ae)}}return e},vn="dialogue-character-sprite",Wd=(e,{presentationState:n,previousPresentationState:t,resources:r={},isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})=>{let{animations:l}=e,a=fn(e.elements);if(!a)return e;let c=n.dialogue?.character?.sprite,u=t?.dialogue?.character?.sprite,d=Mn(c),f=Mn(u),p=je({animationsDef:c?.animations,resources:r,previousResourceId:f?vn:void 0,currentResourceId:d?vn:void 0,previousTargetId:f?vn:void 0,currentTargetId:d?vn:void 0,animationPath:"dialogue.character.sprite.animations",idPrefix:"dialogue-character-sprite"});if(!d)return c?.animations&&f&&ke({animationInstances:p,isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})&&l.push(...p),e;let g=r.transforms?.[c.transformId];if(!g)return console.warn("Transform not found:",c.transformId),e;let h={type:"container",id:vn,...De(g),children:[]};for(let b of c.items){let I=xs({id:`${vn}-${b.id}`,item:b,resources:r});I&&h.children.push(I)}return a.children.push(h),ke({animationInstances:p,isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})&&l.push(...p),e},Kd=(e,{presentationState:n,previousPresentationState:t,resources:r={},dialogueUIHidden:o,autoMode:i,skipMode:s,isChoiceVisible:l,isFormVisible:a,canRollback:c,form:u,skipOnlyViewedLines:d,isLineCompleted:f,skipTransitionsAndAnimations:p,variables:g,imageGallery:h,musicRoom:b,sceneReplay:I,runtime:E,activePersistentAnimations:A,saveSlots:$=[]})=>{let{elements:B,animations:L}=e;if(!n.dialogue||o)return e;let T=B.find(G=>G.id==="story");if(!T)return e;if(n.dialogue.ui&&n.dialogue.ui.resourceId){let{layouts:G={}}=r,S=G[n.dialogue.ui.resourceId];if(S){let q={elements:S.elements},W=Re({variables:g,imageGallery:h,musicRoom:b,sceneReplay:I,runtime:E,saveSlots:$,dialogueState:n.dialogue,includeInactiveAdvDialogue:!0,isLineCompleted:f,autoMode:i,skipMode:s,isChoiceVisible:l,isFormVisible:a,canRollback:c,form:u,characters:r.characters||{},dialogueUIHidden:o,skipOnlyViewedLines:d,skipTransitionsAndAnimations:p}),me=Me(q,W),Y=Ve(We(me?.elements,{isLineCompleted:f,skipMode:s,skipTransitionsAndAnimations:p}),r);if(Array.isArray(Y))for(let ae of Y)T.children.push(ae);else Y&&T.children.push(Y)}}Wd(e,{presentationState:n,previousPresentationState:t,resources:r,isLineCompleted:f,skipTransitionsAndAnimations:p,activePersistentAnimations:A});let z=je({animationsDef:n.dialogue.ui?.animations,resources:r,previousResourceId:t?.dialogue?.ui?.resourceId,currentResourceId:n.dialogue.ui?.resourceId,previousTargetId:t?.dialogue?.ui?.resourceId?"dialogue-container":void 0,currentTargetId:n.dialogue.ui?.resourceId?"dialogue-container":void 0,animationPath:"dialogue.ui.animations",idPrefix:"dialogue-ui"});return ke({animationInstances:z,isLineCompleted:f,skipTransitionsAndAnimations:p,activePersistentAnimations:A})&&L.push(...z),e},Jd=(e,{presentationState:n,previousPresentationState:t,resources:r,screen:o,isLineCompleted:i,skipTransitionsAndAnimations:s,variables:l,imageGallery:a,musicRoom:c,sceneReplay:u,runtime:d,autoMode:f,skipMode:p,isChoiceVisible:g,isFormVisible:h,canRollback:b,form:I,activePersistentAnimations:E,saveSlots:A=[]})=>{let{elements:$,animations:B}=e;if(n.choice&&r){let L=fn($);if(!L)return e;let T=r?.layouts[n.choice.resourceId];if(T&&T.elements){let G={elements:T.elements},S=Me(G,{...Re({variables:l,imageGallery:a,musicRoom:c,sceneReplay:u,runtime:d,saveSlots:A,dialogueState:n.dialogue,isLineCompleted:i,autoMode:f,skipMode:p,isChoiceVisible:g??!!n.choice,isFormVisible:h,canRollback:b,form:I,characters:r.characters||{},skipTransitionsAndAnimations:s}),choice:{items:n.choice?.items??[]}}),q=Qr(Ve(We(S?.elements,{isLineCompleted:i,skipMode:p,skipTransitionsAndAnimations:s}),r));if(Array.isArray(q))for(let W of q)L.children.push(W);else q&&L.children.push(q)}let z=je({animationsDef:n.choice.animations,resources:r,previousResourceId:t?.choice?.resourceId,currentResourceId:n.choice.resourceId,previousTargetId:t?.choice?.resourceId?"choice-container":void 0,currentTargetId:n.choice.resourceId?"choice-container":void 0,animationPath:"choice.animations",idPrefix:"choice"});ke({animationInstances:z,isLineCompleted:i,skipTransitionsAndAnimations:s,activePersistentAnimations:E})&&B.push(...z)}return e},Xd=(e,{presentationState:n,previousPresentationState:t,resources:r,screen:o,isLineCompleted:i,skipTransitionsAndAnimations:s,variables:l,imageGallery:a,musicRoom:c,sceneReplay:u,runtime:d,autoMode:f,skipMode:p,isChoiceVisible:g,isFormVisible:h,canRollback:b,activePersistentAnimations:I,saveSlots:E=[],form:A})=>{let{elements:$,animations:B}=e;if(!A?.resourceId||!r)return e;let L=fn($);if(!L)return e;let T=r?.layouts?.[A.resourceId];if(!T)return console.warn(`Form layout not found: ${A.resourceId}`),e;let z={id:"form-container",type:"container",x:0,y:0,children:T.elements||[]},G={...Re({variables:l,imageGallery:a,musicRoom:c,sceneReplay:u,runtime:d,saveSlots:E,dialogueState:n.dialogue,isLineCompleted:i,autoMode:f,skipMode:p,isChoiceVisible:g,isFormVisible:h,canRollback:b,characters:r.characters||{},skipTransitionsAndAnimations:s,form:A}),form:A},S=Me(z,G),q=eo(Ve(We(Zr(S,A),{isLineCompleted:i,skipMode:p,skipTransitionsAndAnimations:s}),r),A);q&&L.children.push(q);let W=je({animationsDef:A.animations,resources:r,previousResourceId:t?.form?.resourceId,currentResourceId:A.resourceId,previousTargetId:t?.form?.resourceId?"form-container":void 0,currentTargetId:A.resourceId?"form-container":void 0,animationPath:"form.animations",idPrefix:"form"});return ke({animationInstances:W,isLineCompleted:i,skipTransitionsAndAnimations:s,activePersistentAnimations:I})&&B.push(...W),e},Qd=(e,{presentationState:n,resources:t={},variables:r,imageGallery:o,musicRoom:i,sceneReplay:s,runtime:l,isLineCompleted:a,autoMode:c,skipMode:u,isChoiceVisible:d,isFormVisible:f,canRollback:p,form:g,saveSlots:h=[],skipTransitionsAndAnimations:b})=>{if(!n.control?.resourceId)return e;let I=t.controls?.[n.control.resourceId];if(!I)return e;let E=Bd(I.keyboard,I.keyup);if(E&&Object.keys(E).length>0&&(e.global.keyboard=E),!Array.isArray(I.elements)||I.elements.length===0)return e;let A=fn(e.elements);if(!A)return e;let $={id:`control-${n.control.resourceId}`,type:"container",x:0,y:0,children:I.elements};return A.children.push(Ts({container:$,resources:t,templateData:Re({variables:r,imageGallery:o,musicRoom:i,sceneReplay:s,runtime:l,saveSlots:h,dialogueState:n.dialogue,isLineCompleted:a,autoMode:c,skipMode:u,isChoiceVisible:d,isFormVisible:f,canRollback:p,form:g,characters:t.characters||{},skipTransitionsAndAnimations:b}),isLineCompleted:a,skipMode:u,skipTransitionsAndAnimations:b})),e},Zd=(e,{presentationState:n,resources:t,runtime:r,variables:o,musicRoomPlayer:i})=>{let{elements:s,audio:l}=e;if(n.bgm&&t){if(!fn(s))return e;let c=n.bgm,u=!Array.isArray(c.sounds),d=u?c.resourceId?[{id:"default",resourceId:c.resourceId,loop:c.loop??!0,volume:c.volume,startDelayMs:c.startDelayMs??0}]:[]:c.sounds,f=!u&&c.loop===!0,p=[];if(u||Pt(d,"BGM sound"),f){let h=d.find(b=>b.loop===!0);if(h)throw new Error(`BGM sound "${h.id}" cannot loop inside a looping BGM channel.`)}if(d.forEach(h=>{let b=t.sounds?.[h.resourceId];if(!b)return;let I=f?{...h,loop:h.loop??!1}:h;p.push(jt({id:Wn("bgm",u?"default":h.id),sound:I,resource:b,defaultLoop:!f}))}),p.length===0)return e;let g=Re({variables:o,runtime:r}).runtime;l.push(Vt({id:kd,volume:Mt(g,"musicVolume",u?He:c.volume??He),muted:c.muted,pan:c.pan,loop:u?void 0:c.loop,playback:i?.bgmPlayback,interruption:c.interruption,children:p,runtime:g}))}return e},ef=(e,{resources:n={},runtime:t,variables:r,musicRoomPlayer:o})=>{let i=n.musicRoom;if(!i||!o?.trackId||!o.playback)return e;let s=i.tracks.find(u=>u.id===o.trackId),l=s?n.sounds?.[s.soundId]:void 0;if(!s||!l)return e;let a=Re({variables:r,runtime:t}).runtime,c=jt({id:$d,sound:{loop:!1,startDelayMs:0,playback:o.playback},resource:l});return e.audio.push(Vt({id:Od,volume:Mt(a,"musicVolume",He),children:[c],runtime:a})),e},nf=(e,{presentationState:n,resources:t,runtime:r})=>{let{audio:o}=e;if(n.sfx&&t){let i=n.sfx,s=!Array.isArray(i.channels),l=s?[{id:Ld,sounds:i.items??[]}]:i.channels;s||Pt(l,"SFX channel"),l.forEach(a=>{let c=!s&&a.loop===!0,u=[];if(s||Pt(a.sounds,"SFX sound",`SFX channel "${a.id}"`),c){let d=a.sounds.find(f=>f.loop===!0);if(d)throw new Error(`SFX sound "${d.id}" cannot loop inside looping SFX channel "${a.id}".`)}a.sounds.forEach((d,f)=>{let p=t.sounds?.[d.resourceId];if(!p)return;let g=c?{...d,loop:d.loop??!1}:d;u.push(jt({id:s?Wn("sfx","default",f,d.id):Wn("sfx",a.id,d.id),sound:g,resource:p,defaultLoop:c?!1:void 0}))}),u.length!==0&&o.push(Vt({id:Wn("channel","sfx",a.id),volume:Mt(r,"soundVolume",a.volume??He),muted:a.muted,pan:a.pan,loop:s?void 0:a.loop,interruption:s?void 0:a.interruption,children:u,runtime:r}))})}return e},tf=(e,n,t)=>{if(!(!n||!t))return e?.voices?.[n]?.[t]},rf=(e,{presentationState:n,resources:t,currentSceneId:r,runtime:o,variables:i})=>{let{audio:s}=e;if(!n?.voice)return e;let l=n.voice,a=!Array.isArray(l.sounds),c=a?l.resourceId?[{id:"default",resourceId:l.resourceId,loop:l.loop??!1,volume:He,startDelayMs:l.startDelayMs??0}]:[]:l.sounds,u=!a&&l.loop===!0,d=[];if(a||Pt(c,"Voice sound"),u){let p=c.find(g=>g.loop===!0);if(p)throw new Error(`Voice sound "${p.id}" cannot loop inside a looping Voice channel.`)}if(c.forEach(p=>{let g=tf(t,r,p.resourceId);if(!g)return;let h=u?{...p,loop:p.loop??!1}:p;d.push(jt({id:Wn("voice",r,a?"default":p.id),sound:h,resource:g,defaultLoop:u?!1:void 0}))}),d.length===0)return e;let f=Re({variables:i,runtime:o}).runtime;return s.push(Vt({id:Td,volume:a?l.volume??ks(f,"soundVolume"):Mt(f,"soundVolume",l.volume??He),muted:l.muted,pan:l.pan,loop:a?void 0:l.loop,interruption:l.interruption,children:d,runtime:f})),e},of=(e,{presentationState:n,previousPresentationState:t,resources:r={},variables:o,imageGallery:i,musicRoom:s,sceneReplay:l,runtime:a,autoMode:c,skipMode:u,isChoiceVisible:d,isFormVisible:f,canRollback:p,form:g,saveSlots:h=[],isLineCompleted:b,skipTransitionsAndAnimations:I,activePersistentAnimations:E})=>{let{elements:A,animations:$}=e;if(n.layout){let z=fn(A);if(!z)return e;let G=r.layouts[n.layout.resourceId];if(!G)return e;Array.isArray(G.transitions)&&!b&&!I&&ro({animations:$,transitions:G.transitions,defaultTargetId:`layout-${n.layout.resourceId}`,idPrefix:`layout-${n.layout.resourceId}`,animationPathPrefix:"layout"});let S={id:`layout-${n.layout.resourceId}`,type:"container",x:0,y:0,children:G.elements||[]};z.children.push(Ts({container:S,resources:r,templateData:Re({variables:o,imageGallery:i,musicRoom:s,sceneReplay:l,runtime:a,saveSlots:h,dialogueState:n.dialogue,isLineCompleted:b,autoMode:c,skipMode:u,isChoiceVisible:d,isFormVisible:f,canRollback:p,form:g,characters:r.characters||{},skipTransitionsAndAnimations:I}),isLineCompleted:b,skipMode:u,skipTransitionsAndAnimations:I}))}let B=t?.layout?.resourceId,L=n.layout?.resourceId,T=je({animationsDef:n.layout?.animations,resources:r,previousResourceId:B,currentResourceId:L,previousTargetId:B?`layout-${B}`:void 0,currentTargetId:L?`layout-${L}`:void 0,animationPath:"layout.animations",idPrefix:"layout"});return ke({animationInstances:T,isLineCompleted:b,skipTransitionsAndAnimations:I,activePersistentAnimations:E})&&$.push(...T),e},sf=(e,{currentLineActions:n,previousPresentationState:t,resources:r={},isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})=>{let{animations:l}=e,a=n?.screen?.animations;if(!a)return e;let c=t!=null,u=je({animationsDef:a,resources:r,previousResourceId:c?"story":void 0,currentResourceId:"story",previousTargetId:c?"story":void 0,currentTargetId:"story",animationPath:"screen.animations",idPrefix:"screen"});return ke({animationInstances:u,isLineCompleted:o,skipTransitionsAndAnimations:i,activePersistentAnimations:s})&&l.push(...u),e},af=(e,{presentationState:n})=>{let t=fn(e.elements);return!t||!n?.screen||Object.assign(t,Cs(n.screen)),e},cf=(e,{presentationState:n,resources:t={},variables:r,imageGallery:o,musicRoom:i,sceneReplay:s,runtime:l,autoMode:a,skipMode:c,isChoiceVisible:u,isFormVisible:d,canRollback:f,form:p,overlayStack:g=[],dialogueHistory:h=[],saveSlots:b=[],screen:I,isLineCompleted:E,skipTransitionsAndAnimations:A})=>{let{elements:$,animations:B}=e;return g&&g.length>0&&g.forEach((L,T)=>{let z=t.layouts[L.resourceId];if(!z){console.warn(`Overlay layout not found: ${L.resourceId}`);return}Array.isArray(z.transitions)&&(A||ro({animations:B,transitions:z.transitions,defaultTargetId:`overlayStack-${T}`,idPrefix:`overlayStack-${T}`,animationPathPrefix:`overlayStack[${T}]`}));let G={id:`overlayStack-${T}`,type:"container",x:0,y:0,children:[Os({id:`overlayStack-${T}-blocker`,screen:I}),...z.elements||[]]},S=$s(h,t.characters,r),q=Re({variables:r,imageGallery:o,musicRoom:i,sceneReplay:s,runtime:l,saveSlots:b,dialogueState:n?.dialogue,isLineCompleted:E,autoMode:a,skipMode:c,isChoiceVisible:u,isFormVisible:d,canRollback:f,form:p,historyDialogue:S,characters:t.characters||{},skipTransitionsAndAnimations:A}),W=Me(G,q),[me,...Y]=W.children||[],ae=Ve(We({...W,children:Y},{isLineCompleted:E,skipMode:c,skipTransitionsAndAnimations:A}),t);$.push({...ae,children:me?[me,...ae.children||[]]:ae.children})}),e},lf=(e,{presentationState:n,resources:t={},variables:r,imageGallery:o,musicRoom:i,sceneReplay:s,runtime:l,saveSlots:a=[],autoMode:c,skipMode:u,isChoiceVisible:d,isFormVisible:f,canRollback:p,form:g,confirmDialog:h,dialogueHistory:b=[],screen:I,isLineCompleted:E,skipTransitionsAndAnimations:A})=>{let{elements:$,animations:B}=e;if(!h?.resourceId)return e;let L=t.layouts?.[h.resourceId];if(!L)return console.warn(`ConfirmDialog layout not found: ${h.resourceId}`),e;Array.isArray(L.transitions)&&!A&&ro({animations:B,transitions:L.transitions,defaultTargetId:"confirmDialog",idPrefix:"confirmDialog",animationPathPrefix:"confirmDialog"});let T={id:"confirmDialog",type:"container",x:0,y:0,children:[Os({id:"confirmDialog-blocker",screen:I}),...L.elements||[]]},z=$s(b,t.characters,r),G=Me(T,Re({variables:r,imageGallery:o,musicRoom:i,sceneReplay:s,runtime:l,saveSlots:a,dialogueState:n?.dialogue,isLineCompleted:E,autoMode:c,skipMode:u,isChoiceVisible:d,isFormVisible:f,canRollback:p,form:g,confirmDialog:h,historyDialogue:z,characters:t.characters||{},skipTransitionsAndAnimations:A})),[S,...q]=G.children||[],W=Ve(We({...G,children:q},{isLineCompleted:E,skipMode:u,skipTransitionsAndAnimations:A}),t);return $.push({...W,children:S?[S,...W.children||[]]:W.children}),e},Xn=e=>(n,t)=>Hd(n,{...t,visualLayer:e}),uf=Xn(Ne.BEHIND_BACKGROUND),df=Xn(Ne.BEHIND_CHARACTER),ff=Xn(Ne.BEHIND_DIALOGUE),pf=Xn(Ne.BEHIND_CHOICE),mf=Xn(Ne.FOREGROUND),Ps=e=>St(Gd,[Qd,uf,zd,df,qd,ff,Kd,pf,Jd,Xd,of,mf,af,sf,Zd,ef,nf,rf,cf,lf])(e);function Ns(e,n=""){let t=[],r=e.length,o=0,i=0,s=-1,l=()=>{let a=0,c=0,u;do u=parseInt(e[o++],36),a+=(u&15)<<c,c+=4;while(u&16);return a};for(;o<r;){let a=s+1+l();s=a+l(),t.push([a,s,n?parseInt(n[i++],36):0])}return t}function Ds(e,n,t){let r=0,o=n.length-1;for(;r<=o;){let i=r+o>>>1,s=t[i];if(e<n[i])o=i-1;else if(e>s>>>5)r=i+1;else return s&31}return 0}var Ms="090001000h1v5g2903000hl2v6jh16ng1s210111110o35aa10u2k1g10l6600152113h2010u1q1r5aq3890o13181214r22k3158q2n1000v100h1k20000001207030001160721k171001h1j11610332010010321210090411021c1c02100o301201412230u1130b100h1j116111420120411001100k11l10051001h1j11611142011000321210072411021d0g10r3000000132120090o200200g1j11f2012031213711271t1001o301001000001121371b1f0c101h1l2011001031212000080a1t1001m40400102101600i11t301006c7i601008b6p41r10101041h3d0004115a1j290p3q223000511010100g1501010302003172030c0010016000e0i6v50n40n5tl12ir33s12t11u11cj30100060700010a90t220000l71i20m7203010241000502rd101004k300000006101027050920g3t22bk1300616g209030207u18c1000t10003010501b2o20000102000004g37070101o921c000640602001mcv3rg20000001o16d0c0m1fg6g2h30m10q55f1vm11c0ma0p1a42nc0ne1a090q3314902021204020112030318250105bb1201110i1021i15101131502141b15120511011k1155132040202510201010603060a1f02040104210b1g3290e0e0kn11vs12j11j3040pp12t80g6v1vmo7319g21g51gh103040n11010040j51i3f01q1h1d0m27p1a0000cs13200523j200010301010100v140018a4q2501010101c08000i1f12601011g3012215110u1a0001015000pcq181000100011000iji5fvc0u91g5bhg20ie0l94lo6002115303121s12240la1tj23h44tj11t45m4ah33q700000l3ep2021a200t220301012040a0i320j2040007f00100r20c100g3208000011531000s520201036020t900207l1101n311000000321210090a12634b910201l22001051020120011020000e1i520701020000n10h5001050000010000010001re0010323010001r11i520701000001q6000000107l600000230004gg12080001lc62027111n1000411230000000000t820321030030r10090n205001380800501020n2050c0001mc00002000000nc006150000i5l1100600010001q753011160000i441111000000rl11019100000c1h201043102n10ltk1f006eoss2b0202gs94r36si2033ku101m373h50b1rqs4113sli1t22m1uh2435070726u13k92rr7m34h380e0m141egl561g1261114k60ga6nn10t33sv13uf1jf0207150qt16t66pr60n23k6bf1f0e1l29g71c1e029j1n30p11ea0k1028139m16rb2v621122i52213040tf1u3b51n17127c0232041d120819052c28220104060306l5g3l4572g130152cqdl2c3o37a5o27u11c32d9m2cu2191obo57eh9gg1tv3",Vs="262122424333333393233393339333333333393393bf3b3b3b3b3f3f3bffff33b3bb33ff3f33b3b3333333bffff3b33bb33f33bffff33b3bb33ff3f33b3bbb333b3ff33b333f33b3b3b3b3333b3bf33b3bb39333b33b33b3b3b333b333333b3b33333f3b33b3ffb3f3fff3f3b33f35dc33333f3b3b3b33323333b3bb3b33b3fb3b3333b33333bff3b3f33bfb3b3ff3b3b3b3b3b333b333b3323e22442344444444444444444444444444444444444444444444444444444444444444444444444444444443333333333b3b3bb33333b353bff3b3b3b3f3ff3b3b333bfff3f33333fb3bb3fb3b3bb33232333f333fff333333333b3b3333bb3b39393f3b3fbf33bb3b393b3b3b3333b33b33b3bbb33b33ffff3b3333bb3933b3b3b333b3b3b3b3b33b3b3b33b3b3b33b3b33b33b3b3b3fffff3bb39b9b3b33b3bf3f3b33f3b3f93b33b3b3bb33b33b3b3b3333393b3b3b33b39bffb3b332333b333dd3b3333233332333333333333333333333333333444444444444a4444444444444344444444444444444444444444444444444444444444",js="0001000000010010000000100000000000000000000000000001000000010014000100000001001000010101100101100000000000000000000100000001111000010000000110101001110111111111000100000021001000010000000100100001000000011010000100000001111000013000000100140001000000010010";var Fs=65535,ao=40960,Ft=126976,Gs=new Uint8Array(12288),zs=new Uint8Array(3072),qs=new Uint8Array(2816),Ys,Hs;{let e=(o,i,s,l,a)=>{let c=i+o.length-1;for(let u=s<i?i:s,d=l>c?c:l;u<=d;u++)o[u-i]=a},n=new Uint32Array(320),t=new Uint32Array(320),r=0;for(let[o,i,s]of Ns(Ms,Vs))e(Gs,0,o,i,s),e(zs,ao,o,i,s),e(qs,Ft,o,i,s),i>=65040&&!(o>=Ft&&i<=129791)&&(n[r]=o,t[r++]=i<<5|s);Ys=n.slice(0,r),Hs=t.slice(0,r)}function Us(e){return e<12288?Gs[e]:e<ao?e<12336?e>=12330?3:0:e<12443?e===12336||e===12349?4:e>=12441?3:0:e===12951||e===12953?4:0:e<44032?zs[e-ao]:e<55204?(e-44032)%28?8:7:e<57344?e<=55238?e>=55216?13:0:e>=55243&&e<=55291?12:0:e<65024?e===64286?3:0:e<65040?3:e>=Ft&&e<129792?qs[e-Ft]:e>=917504?e>921599?0:e>=917536&&e<917632||e>=917760&&e<918e3?3:2:Ds(e,Ys,Hs)}var Ws=Uint8Array.from(js,Number);function gf(e){return e===2381||e===2509||e===2637||e===2765||e===2893||e===3149||e===3405||e===4153||e===6098||e===6752||e===6980||e===7083||e===43456||e===43766||e===68159||e===69939||e===70608||e===71998||e===72263||e===72345||e===73538}function Bs(e,n,t){switch(n){case 3:return e&24?t===8204?e&6:(e&24)===16||gf(t)?e&6|16:e&6|8:e&6;case 4:return 2;case 10:return e&1^1;case 14:return(e&2)<<1|e&24;default:return 8}}function*Ks(e){let n=e.length;if(n===0)return;let t=e.codePointAt(0),r=t>Fs?2:1,o=Us(t),i=50200>>o&1?Bs(0,o,t):0,s=0,l=t,a=o;for(;r<n;){t=e.codePointAt(r);let c=t>Fs?2:1,u=Us(t),d=Ws[o<<4|u],f;d===0?f=!0:d===1?f=!1:d===2?f=!(i&1):d===3?f=!(i&4):f=(i&24)!==16,i=50200>>u&1&&(i!==0||u!==3)?Bs(i,u,t):0,f&&(yield{segment:e.slice(s,r),index:s,input:e,_hd:l,_catBegin:a===15?0:a,_catEnd:o===15?0:o},s=r,l=t,a=u),r+=c,o=u}yield{segment:e.slice(s),index:s,input:e,_hd:l,_catBegin:a===15?0:a,_catEnd:o===15?0:o}}function*Js(e){for(let n of Ks(e))yield n.segment}{let e=Ks("_");Ws._keep=[e,e.next()]}var Xs=1e3,na=50,hf=0,Qs=100,Zs=50,yf=60,bf=3,If=.5,wf=2e4,Af=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,Ef=/^\s+$/u,ea,xf=e=>{let n=`${e??""}`.normalize("NFC"),t=globalThis.Intl?.Segmenter;return typeof t!="function"?Array.from(Js(n)):(ea??=new t(void 0,{granularity:"grapheme"}),Array.from(ea.segment(n),({segment:r})=>r))},vf=e=>xf(e).reduce((n,t)=>Ef.test(t)?n+If:Af.test(t)?n+bf:n+1,0),Sf=e=>2**(((Number.isFinite(e)?Math.min(Qs,Math.max(hf,e)):na)-Zs)/(Qs-Zs)),ta=({text:e="",baseDelay:n=Xs,speed:t=na}={})=>{let r=Number.isFinite(n)?Math.max(0,n):Xs,o=Sf(t),i=vf(e)*yf/o,s=Math.max(r,wf);return Math.min(r+i,s)};var Ut={manual:{enabled:!0,requireLineCompleted:!1},auto:{enabled:!1},applyMode:"persistent"},la=1,fo=1,_n="choice",Ke="form",et=()=>({manual:{...Ut.manual},auto:{...Ut.auto},applyMode:Ut.applyMode}),po=()=>({groupId:null,variantId:null,pageIndex:0}),Rf="music-room:player",Cf=new Set(["asset-unavailable","decode-failed","invalid-segment","invalid-position","playback-failed"]),zt=({bgmPlayback:e={commandId:0,operation:"resume"}}={})=>({trackId:null,pageIndex:0,status:"stopped",readiness:"idle",positionMs:0,durationMs:null,playback:null,seekFallback:null,bgmPlayback:e}),mo=new Set,_f=new Set(["groupId","variantId"]),kf=new Set(["pageIndex"]),kn=new Set,Of=new Set(["trackId"]),$f=new Set(["positionMs"]),Tf=new Set(["pageIndex"]),go=new Set,Lf=new Set(["replayId"]),Pf=new Set(["pageIndex"]),ho=()=>({pageIndex:0}),yo=e=>{if((e.global.nextLineConfig?.applyMode??"persistent")!=="singleLine")return;let t=e.global.nextLineConfig?.auto?.enabled===!0;e.global.nextLineConfig={...et()},t&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"})},k=e=>{let n=ie(e)?Ue(e):e;return structuredClone(n)},N=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),qt=e=>{let n=e.global.audioCommandId;if(!Number.isSafeInteger(n)||n<0)throw new Error("Internal audio command counter is invalid");if(n===Number.MAX_SAFE_INTEGER)throw new Error("Audio command counter is exhausted");return e.global.audioCommandId=n+1,e.global.audioCommandId},ua=e=>{let n=e.global.sceneReplayEntryId;if(!Number.isSafeInteger(n)||n<0)throw new Error("Internal scene replay entry counter is invalid");if(n===Number.MAX_SAFE_INTEGER)throw new Error("Scene replay entry counter is exhausted");return e.global.sceneReplayEntryId=n+1,e.global.sceneReplayEntryId},nt=(e,n,t)=>({commandId:qt(e),operation:n,...t===void 0?{}:{positionMs:t}}),bo=e=>{if(!Object.prototype.hasOwnProperty.call(e.global??{},"musicRoomPlayer"))return;let n=e.global.musicRoomPlayer,t=n.bgmPlayback;n.trackId!==null&&(t={commandId:qt(e),operation:"resume"}),e.global.musicRoomPlayer=zt({bgmPlayback:t})},da=(e,n)=>{if(typeof n!="string"||n.length===0)throw new Error("Achievement action requires a non-empty resourceId");let t=e.projectData.resources?.achievements?.[n];if(!t)throw new Error(`Achievement resource "${n}" not found`);if(t.type!=="boolean"&&t.type!=="number")throw new Error(`Achievement resource "${n}" has invalid type "${t.type}"`);return t},tt=e=>String(e),fa=()=>({sections:[],resources:[]}),Nf=e=>N(e)?(Array.isArray(e.sections)||(e.sections=[]),Array.isArray(e.resources)||(e.resources=[]),e):fa(),Df=e=>Array.isArray(e)?e.map(n=>n?.text??"").join(""):"",Mf=({sectionId:e,lineId:n,content:t,dialogueState:r,characterName:o})=>({sectionId:e,lineId:n,content:t,text:Df(t),characterId:r.characterId,character:{...r.character||{},name:o},characterName:o}),Vf=()=>({resourceId:void 0}),jf=e=>{if(!N(e))return e;let n={...e};return Object.prototype.hasOwnProperty.call(n,"requireComplete")&&!Object.prototype.hasOwnProperty.call(n,"requireLineCompleted")&&(n.requireLineCompleted=n.requireComplete),delete n.requireComplete,n},hn=(e,n)=>{let t=e?.story?.scenes??{};for(let[r,o]of Object.entries(t))if(o?.sections?.[n])return{sceneId:r,section:o.sections[n]};return{sceneId:void 0,section:void 0}},pa=e=>{let n=e?.story?.scenes??{},t=new Map;for(let[r,o]of Object.entries(n)){let i=o?.sections??{};for(let s of Object.keys(i)){let l=t.get(s);if(l!==void 0)throw new Error(`Duplicate sectionId "${s}" found in scenes "${l}" and "${r}". Section IDs must be globally unique.`);t.set(s,r)}}},ma=e=>{if(typeof e=="number"||typeof e!="string")return e;let n=Number(e);return Number.isFinite(n)?n:e},ga=e=>{if(!Number.isInteger(e)||e<1)throw new Error("Malformed save slot formatVersion.");if(e!==la)throw new Error(`Unsupported save slot formatVersion "${e}".`);return e},Ff=(e,n={})=>{let t;try{t=ga(n.formatVersion)}catch(o){throw new Error(`Hydrated save slot "${e}" failed validation: ${o.message}`)}let r={...n,formatVersion:t,slotId:ma(n.slotId??n.slotKey??e),savedAt:typeof n.savedAt=="number"?n.savedAt:n.date};return delete r.slotKey,delete r.date,r},Uf=(e={})=>Object.fromEntries(Object.entries(e).map(([n,t])=>[n,Ff(n,t)])),ha=e=>{if(!Array.isArray(e))return;let n=e.filter(({type:t})=>Cg(t));return n.length>0?n:void 0},Bf=e=>{!N(e)||!Array.isArray(e.timeline)||(e.returnabilityVersion=fo,e.timeline.forEach(n=>{if(!N(n))return;typeof n.returnable!="boolean"&&delete n.returnable;let t=ha(n.executedActions);if(t){n.executedActions=t;return}delete n.executedActions}))},ra=(e,n,t,r="viewedRegistry")=>{let o=n==="sections"?"sectionId":"resourceId";if(typeof e=="string"||typeof e=="number")return{[o]:String(e)};if(!N(e))throw new Error(`Malformed ${r}.${n}[${t}] entry.`);if(typeof e[o]!="string"||e[o].length===0)throw new Error(`Malformed ${r}.${n}[${t}] entry: missing ${o}.`);if(n==="sections"){let i={sectionId:e.sectionId};if(e.lastLineId!==void 0&&e.lastLineId!==null&&typeof e.lastLineId!="string")throw new Error(`Malformed ${r}.sections[${t}] entry: invalid lastLineId.`);return typeof e.lastLineId=="string"&&e.lastLineId.length>0&&(i.lastLineId=e.lastLineId),i}return{resourceId:e.resourceId}},Gf=(e,n="viewedRegistry")=>{if(e===void 0)return fa();if(!N(e))throw new Error(`Malformed ${n}.`);if(e.sections!==void 0&&!Array.isArray(e.sections))throw new Error(`Malformed ${n}.sections.`);if(e.resources!==void 0&&!Array.isArray(e.resources))throw new Error(`Malformed ${n}.resources.`);let t=e.sections??[],r=e.resources??[];return{sections:Object.values(Object.fromEntries(t.map((o,i)=>{let s=ra(o,"sections",i,n);return[s.sectionId,s]}))),resources:Object.values(Object.fromEntries(r.map((o,i)=>{let s=ra(o,"resources",i,n);return[s.resourceId,s]})))}},ya=(e,n,t)=>{if(!N(e))throw new Error(`Malformed save slot ${t}.`);let{sectionId:r,lineId:o}=e;if(typeof r!="string"||r.length===0)throw new Error(`Malformed save slot ${t}: missing sectionId.`);if(typeof o!="string"||o.length===0)throw new Error(`Malformed save slot ${t}: missing lineId.`);let{sceneId:i,section:s}=hn(n,r);if(!s)throw new Error(`Malformed save slot ${t}: section "${r}" does not exist in projectData.`);if(!s.lines?.some(a=>a.id===o))throw new Error(`Malformed save slot ${t}: line "${o}" does not exist in section "${r}".`);return{sceneId:i,sectionId:r,lineId:o}},ba=(e,n)=>e?.sectionId===n?.sectionId&&e?.lineId===n?.lineId,zf=(e,n)=>{let{section:t}=hn(e,n?.sectionId);return t?.lines?.find(r=>r.id===n?.lineId)},qf=(e,n)=>{let{section:t}=hn(e,n?.sectionId),r=t?.lines?.findIndex(i=>i.id===n?.lineId);if(typeof r!="number"||r<0)return null;let o=t.lines[r+1];return o?{sectionId:n.sectionId,lineId:o.id}:null},Ia=(e,n,t)=>{if(typeof n?.sectionId!="string")return!1;let{section:r}=hn(e,n.sectionId);return ba({sectionId:n.sectionId,lineId:r?.lines?.[0]?.id},t)},Yf=new Set(["jumpToLine","rollbackByOffset","rollbackToLine","sectionTransition","resetStoryAtSection"]),Cn={always:"always",maybe:"maybe",never:"never"},Hf=e=>{if(!Object.prototype.hasOwnProperty.call(e??{},"when"))return Cn.always;let n=e.when,t;if(n===null||typeof n=="boolean"||typeof n=="number")t=n;else if(N(n)&&Object.keys(n).length===1&&Object.prototype.hasOwnProperty.call(n,"literal"))t=n.literal;else return Cn.maybe;return t?Cn.always:Cn.never},wa=(e,n)=>{if(!Array.isArray(e?.branches))return!1;for(let t of e.branches){let r=Hf(t);if(r!==Cn.never){if(n(t))return!0;if(r===Cn.always)return!1}}return!1},Aa=e=>wa(e,n=>Object.entries(n?.actions??{}).some(([t,r])=>t==="conditional"?Aa(r):Yf.has(t))),Ea=(e,n,t)=>wa(n,r=>Object.entries(r?.actions??{}).some(([o,i])=>o==="sectionTransition"?Ia(e,i,t):o==="conditional"?Ea(e,i,t):!1)),Wf=(e,n,t)=>{if(!n)return!0;let r=zf(t,e)?.actions;if(!N(r))return!0;if(Ia(t,r.sectionTransition,n))return!1;let o=r.conditional;return o?!(Ea(t,o,n)||!(r.choice?.resourceId||r.form?.resourceId)&&!Aa(o)&&ba(qf(t,e),n)):!0},Kf=(e,n,t)=>{if(!N(e)||!Array.isArray(e.timeline))return Zn({pointer:n,replayStartIndex:1});let r=new WeakSet,o=e.timeline.flatMap((c,u)=>{if(!N(c))return[];try{let d=ya(c,t,`rollback.timeline[${u}]`),f=Gt({sectionId:d.sectionId,lineId:d.lineId,rollbackPolicy:c.rollbackPolicy,returnable:c.returnable});typeof c.returnable=="boolean"&&r.add(f);let p=ha(k(c.executedActions));return p&&(f.executedActions=p),[f]}catch{return[]}});if(o.length===0)return Zn({pointer:n,replayStartIndex:1});e.returnabilityVersion!==fo&&o.forEach((c,u)=>{!r.has(c)&&!Wf(c,o[u+1],t)&&(c.returnable=!1)});let s=typeof e.currentIndex=="number"?Math.trunc(e.currentIndex):o.length-1;(s<0||s>=o.length)&&(s=o.length-1);let l=o[s];if(l?.sectionId!==n.sectionId||l?.lineId!==n.lineId){let c=o.findLastIndex(u=>u.sectionId===n.sectionId&&u.lineId===n.lineId);c>=0?s=c:(o.push(Gt({sectionId:n.sectionId,lineId:n.lineId})),s=o.length-1)}let a=typeof e.replayStartIndex=="number"?Math.min(Math.max(Math.trunc(e.replayStartIndex),0),s):0;return{currentIndex:s,isRestoring:!1,replayStartIndex:a,timeline:o}},Jf=(e,n,t)=>{if(!N(e))throw new Error(`Malformed save slot contexts[${t}] entry.`);let r=Ao(n),o=ya(e.pointers?.read,n,`contexts[${t}].pointers.read`);if(e.variables!==void 0&&!N(e.variables))throw new Error(`Malformed save slot contexts[${t}].variables entry.`);if(e.runtime!==void 0&&!N(e.runtime))throw new Error(`Malformed save slot contexts[${t}].runtime entry.`);let i=e.variables?An(k(e.variables),n.resources?.variables??{}):{},s=lp({loadedContextRuntime:N(e.runtime)?k(e.runtime):{}}),l={currentPointerMode:"read",pointers:{read:o},configuration:N(e.configuration)?k(e.configuration):{},views:Array.isArray(e.views)?k(e.views):[],bgm:N(e.bgm)?k(e.bgm):{resourceId:void 0},variables:{...r,...i},rollback:Kf(e.rollback,o,n)};return s&&(l.runtime=s),l},Xf=(e,n)=>{if(!N(e))throw new Error("Malformed save slot state.");if(!Array.isArray(e.contexts)||e.contexts.length===0)throw new Error("Malformed save slot state: contexts must be a non-empty array.");return{contexts:e.contexts.map((t,r)=>Jf(t,n,r))}},Qf=(e,n)=>{if(!N(e))throw new Error("Malformed save slot.");let t=ga(e.formatVersion);return{...e,formatVersion:t,state:Xf(e.state,n)}},oa=(e,n,{required:t=!1}={})=>{if(e===void 0){if(t)throw new Error(`showConfirmDialog requires ${n}`);return{hideConfirmDialog:{}}}if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`showConfirmDialog ${n} must be an action object`);let r=k(e),o=r.hideConfirmDialog??{};return delete r.hideConfirmDialog,{hideConfirmDialog:o,...r}},Zf=(e={})=>{if(!e?.resourceId)throw new Error("showConfirmDialog requires resourceId");return{resourceId:e.resourceId,confirmActions:oa(e.confirmActions,"confirmActions",{required:!0}),cancelActions:oa(e.cancelActions,"cancelActions")}},On=e=>{Object.prototype.hasOwnProperty.call(e.global,"confirmDialog")&&(e.global.confirmDialog=null)},ep=e=>(N(e.global.formDrafts)||(e.global.formDrafts={}),e.global.formDrafts),$n=e=>{Object.prototype.hasOwnProperty.call(e.global,"formDrafts")&&(e.global.formDrafts={})},xa=e=>{if(!(!N(e)||!e.animations))return{animations:k(e.animations)}},np=(e,n)=>{let t=xa(n);if(t){e.global.pendingScreenTransition=t;return}delete e.global.pendingScreenTransition},tp=e=>{let n=e?.id??e?.resourceId;return typeof n=="string"&&n.length>0?n:void 0},rp=(e,n)=>{let t=e?.sectionId,r=e?.lineId;if(!(!t||!r||!n))return`${t}:${r}:${n}`},Bt=e=>String(e??""),va=(e,n)=>{let t=Bt(n);return e?.trim===!0?t.trim():t},op=e=>N(e?.fields)?Object.fromEntries(Object.entries(e.fields).filter(([,n])=>N(n)).map(([n,t])=>[n,{id:n,...k(t)}])):{},ip=(e,n)=>{if(!n||!N(e.global.formDrafts))return;let t=e.global.formDrafts[n];return N(t)?t:void 0},Sa=(e,n)=>{let t=ep(e);N(t[n])||(t[n]={values:{},touched:{},errors:{},submitted:!1});let r=t[n];return N(r.values)||(r.values={}),N(r.touched)||(r.touched={}),N(r.errors)||(r.errors={}),typeof r.submitted!="boolean"&&(r.submitted=!1),r},Io=(e,n)=>{let t=va(e,n);return e?.required===!0&&t.length===0?"required":null},sp=({state:e,pointer:n})=>{if(!n?.sectionId||!n?.lineId)return{};let r=de({state:e},{sectionId:n.sectionId})?.lines||[],o=r.findIndex(i=>i.id===n.lineId);return o<0?{}:cn(r.slice(0,o+1).map(i=>i.actions||{}))},ap=({state:e,form:n,pointer:t})=>{if(!n?.resourceId)return null;let r=tp(n),o=rp(t,r);if(!r||!o)return null;let i=ip(e,o),s=op(n),l=Yt({state:e}),a={},c=[],u={},d=!0;return Object.entries(s).forEach(([f,p])=>{let g=Bt(l?.[p.variableId]),h=Object.prototype.hasOwnProperty.call(i?.values??{},f)?Bt(i.values[f]):g,b=i?.touched?.[f]===!0,I=Io(p,h),E=i?.submitted||b?I:null,A=typeof p.maxLength=="number"?Math.max(0,Math.round(p.maxLength)):void 0,$={id:f,variableId:p.variableId,value:h,initialValue:g,valid:!I,error:E,touched:b,required:p.required===!0,trim:p.trim===!0,placeholder:p.placeholder===void 0?"":String(p.placeholder),multiline:p.multiline===!0,...A!==void 0?{maxLength:A}:{}};I&&(d=!1),a[f]=$,c.push($),u[f]=h}),{id:r,key:o,resourceId:n.resourceId,animations:n.animations,valid:d,submitted:i?.submitted===!0,fields:a,fieldList:c,values:u,submitActions:{submitForm:{formKey:o,actions:k(n.submitActions??{})}},cancelActions:{cancelForm:{formKey:o,actions:k(n.cancelActions??{})}}}},mn=[],ia="line",wo="interaction",Gt=({sectionId:e,lineId:n,rollbackPolicy:t,returnable:r})=>({sectionId:e,lineId:n,rollbackPolicy:t??"free",...typeof r=="boolean"?{returnable:r}:{}}),Ao=e=>{let n=ie(e)?Ue(e):e,{contextVariableDefaultValues:t}=Ct(n??{});return k(t)},Ra=()=>({...k(qn)}),Ca=({loadedRuntime:e,runtimeIds:n,defaults:t={},path:r})=>{if(e===void 0)return{runtimeState:k(t),hasLoadedValues:!1};if(!N(e))throw new Error(`Malformed ${r}.`);let o=k(t),i=!1;return n.forEach(s=>{e[s]!==void 0&&(o[s]=ka(s,k(e[s])),i=!0)}),{runtimeState:o,hasLoadedValues:i}},cp=({loadedGlobalRuntime:e={}})=>Ca({loadedRuntime:e,runtimeIds:Dr,defaults:ln,path:"global.runtime"}).runtimeState,lp=({loadedContextRuntime:e={}})=>{let{runtimeState:n,hasLoadedValues:t}=Ca({loadedRuntime:e,runtimeIds:Mr,defaults:Ra(),path:"context.runtime"});return t?n:void 0},rt=e=>{let n=Array.isArray(e?.contexts)?e.contexts:[];return n[n.length-1]},J=e=>{let n=rt(e);return n?.kind==="sceneReplay"&&N(n.sceneReplay)?n:null},_a=(e,n)=>{let t=n?.sceneReplay?.replayId,r=e.projectData?.resources?.sceneReplay?.replays?.find(o=>o.id===t);Object.entries(r?.initialVariables??{}).forEach(([o,i])=>{n.variables[o]=k(i)})},up=e=>({autoMode:e.global.autoMode,skipMode:e.global.skipMode,dialogueUIHidden:e.global.dialogueUIHidden,nextLineConfig:k(e.global.nextLineConfig),overlayStack:k(e.global.overlayStack),confirmDialog:k(e.global.confirmDialog),formDrafts:k(e.global.formDrafts),isLineCompleted:e.global.isLineCompleted,...e.global.isDialogueHistoryShowing===void 0?{}:{isDialogueHistoryShowing:e.global.isDialogueHistoryShowing},...e.global.pendingScreenTransition===void 0?{}:{pendingScreenTransition:k(e.global.pendingScreenTransition)}}),dp=e=>{e.global.autoMode=!1,e.global.skipMode=!1,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,delete e.global.pendingScreenTransition,e.global.nextLineConfig=et(),e.global.overlayStack=[],e.global.confirmDialog=null,e.global.formDrafts={},e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"})},fp=(e,n)=>{e.global.autoMode=n.autoMode,e.global.skipMode=n.skipMode,e.global.dialogueUIHidden=n.dialogueUIHidden,e.global.nextLineConfig=k(n.nextLineConfig),e.global.overlayStack=k(n.overlayStack),e.global.confirmDialog=k(n.confirmDialog),e.global.formDrafts=k(n.formDrafts),e.global.isLineCompleted=n.isLineCompleted,n.isDialogueHistoryShowing===void 0?delete e.global.isDialogueHistoryShowing:e.global.isDialogueHistoryShowing=n.isDialogueHistoryShowing,n.pendingScreenTransition===void 0?delete e.global.pendingScreenTransition:e.global.pendingScreenTransition=k(n.pendingScreenTransition),e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"});let t=Ae({state:e});e.global.autoMode&&e.global.isLineCompleted&&!t&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:it({state:e})}}),e.global.skipMode&&!t&&e.global.pendingEffects.push({name:"startSkipNextTimer"}),e.global.nextLineConfig.auto?.enabled&&!t&&(e.global.nextLineConfig.auto.trigger==="fromStart"||e.global.isLineCompleted)&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}})},pp=e=>e.runtime?(Mr.forEach(n=>{e.runtime[n]===void 0&&(e.runtime[n]=k(qn[n]))}),e.runtime):(e.runtime=Ra(),e.runtime),mp=e=>rs(e.global),gp=e=>{e.global.pendingEffects.push({name:"saveGlobalRuntime",payload:{globalRuntime:mp(e)}})},hp=e=>ts[e],yp=(e,n)=>{let t=hp(e);if(t==="number"){if(typeof n!="number"||!Number.isFinite(n))throw new Error(`${e} requires a finite numeric value`);return}if(t==="boolean"){if(typeof n!="boolean")throw new Error(`${e} requires a boolean value`);return}if(t==="string"){if(typeof n!="string")throw new Error(`${e} requires a string value`);return}throw new Error(`Unsupported runtime field "${e}"`)},ka=(e,n)=>{if(yp(e,n),e==="autoForwardSpeed"&&(n<0||n>100))throw new Error("autoForwardSpeed requires a value between 0 and 100");return e==="saveLoadPagination"?Math.max(1,Math.trunc(n)):n},Oa=(e,n,t)=>{let r=ka(n,t);if(n in qn){let o=rt(e);if(!o)return r;let i=pp(o);return i[n]=r,r}return e.global[n]=r,r},Eo=({pointer:e,projectData:n,kind:t,sceneReplay:r})=>({...t===void 0?{}:{kind:t},...r===void 0?{}:{sceneReplay:k(r)},currentPointerMode:"read",pointers:{read:k(e)},configuration:{},views:[],bgm:Vf(),variables:Ao(n),rollback:Zn({pointer:e})}),Tn=e=>e?(e.currentPointerMode="read",N(e.pointers)||(e.pointers={}),Object.prototype.hasOwnProperty.call(e.pointers,"history")&&delete e.pointers.history,e.pointers):null,bp=(e,{queueRender:n=!0}={})=>{let t=e.contexts?.[e.contexts.length-1],r=t?.pointers?.read;if(!t||!r?.sectionId||!r?.lineId)return null;let o=Eo({pointer:r,projectData:e.projectData});return e.contexts[e.contexts.length-1]=o,Ip(e,{queueRender:n}),o},Ip=(e,{queueRender:n=!0}={})=>{e.global.autoMode=!1,e.global.skipMode=!1,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,On(e),$n(e),e.global.nextLineConfig=et(),e.global.overlayStack=[],e.global.isLineCompleted=!0,bo(e),e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"}),n&&e.global.pendingEffects.push({name:"render"})},$a=e=>{!e||!("baselineVariables"in e)||delete e.baselineVariables},Zn=({pointer:e,replayStartIndex:n=0})=>{let t=e?.sectionId&&e?.lineId;return{currentIndex:t?0:-1,isRestoring:!1,replayStartIndex:n,timeline:t?[Gt({sectionId:e.sectionId,lineId:e.lineId})]:[]}},yn=(e,n={})=>{if(e?.rollback)return $a(e.rollback),Array.isArray(e.rollback.timeline)||(e.rollback.timeline=[]),typeof e.rollback.currentIndex!="number"&&(e.rollback.currentIndex=e.rollback.timeline.length>0?e.rollback.timeline.length-1:-1),typeof e.rollback.isRestoring!="boolean"&&(e.rollback.isRestoring=!1),typeof e.rollback.replayStartIndex!="number"&&(e.rollback.replayStartIndex=0),e.rollback;let t=e?.pointers?.read;return e.rollback=Zn({pointer:t,replayStartIndex:n.compatibilityAnchor?1:0}),e.rollback},xo=(e,n)=>{let t=e.contexts?.[e.contexts.length-1];if(!t)return;let r=yn(t);r.isRestoring||(r.currentIndex<r.timeline.length-1&&(r.timeline=r.timeline.slice(0,r.currentIndex+1)),r.timeline.push(Gt(n)),r.currentIndex=r.timeline.length-1)},wp=({state:e})=>{let t=e.contexts?.[e.contexts.length-1]?.rollback;return!Array.isArray(t?.timeline)||typeof t.currentIndex!="number"?null:{checkpointIndex:t.currentIndex,checkpoint:t.timeline[t.currentIndex]??null}},Ap=({state:e},n={})=>{let{checkpointIndex:t,checkpointIdentity:r,sectionId:o,lineId:i}=n,l=e.contexts?.[e.contexts.length-1]?.rollback;if(!Number.isInteger(t)||!Array.isArray(l?.timeline)||typeof l.currentIndex!="number")return e;let a=l.timeline[t];return(ie(a)?ur(a):a)!==r||a?.sectionId!==o||a?.lineId!==i||(a.returnable=!1),e},Ep=({state:e},n={})=>{let{slotId:t,saveSlotIdentity:r,checkpointIndex:o,sectionId:i,lineId:s}=n,l=tt(t),a=e.global.saveSlots?.[l],c=ie(a)?ur(a):a;if(!a||c!==r)return e;let u=a.state?.contexts,d=Array.isArray(u)?u.at(-1):null,f=d?.rollback,p=f?.timeline?.[o];return!Number.isInteger(o)||f?.currentIndex!==o||d?.pointers?.read?.sectionId!==i||d?.pointers?.read?.lineId!==s||p?.sectionId!==i||p?.lineId!==s||(p.returnable=!1,f.returnabilityVersion=fo,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}})),e},xp=e=>{let t=e.contexts?.[e.contexts.length-1]?.rollback;if(!t||t.isRestoring||!Array.isArray(t.timeline)||typeof t.currentIndex!="number")return null;let r=mn[mn.length-1],o=typeof r?.checkpointIndex=="number"?r.checkpointIndex:t.currentIndex;return o<0||o>=t.timeline.length?null:(typeof r?.checkpointIndex!="number"&&o<t.timeline.length-1&&(t.timeline=t.timeline.slice(0,o+1)),t.timeline[o]??null)},vp=({state:e},n={})=>{let t=n?.source===ia?ia:wo,o=e.contexts?.[e.contexts.length-1]?.rollback;return!o||o.isRestoring||!Array.isArray(o.timeline)||typeof o.currentIndex!="number"||o.currentIndex<0||o.currentIndex>=o.timeline.length?(mn.push({checkpointIndex:null,source:t}),e):(o.currentIndex<o.timeline.length-1&&(o.timeline=o.timeline.slice(0,o.currentIndex+1)),mn.push({checkpointIndex:o.currentIndex,source:t}),e)},Sp=({state:e})=>(mn.pop(),e),Le=(e,n,t)=>{let o=mn[mn.length-1]?.source??wo;if(!_g(n,o))return;let i=xp(e);i&&(Array.isArray(i.executedActions)||(i.executedActions=[]),i.executedActions.push({type:n,payload:k(t)}))},sa=(e,n)=>{let t=e.contexts?.[e.contexts.length-1];if(!t)return;let r=n?.operations??[];for(let{variableId:o,op:i,value:s,roundTo:l}of r){let a=e.projectData.resources?.variables?.[o],c=a?.scope,u=a?.type;if(Se(a))throw new Error(`Cannot update computed variable: ${o}`);if(a?.readonly===!0)throw new Error(`Cannot update readonly variable: ${o}`);Gn(c,o),_t(u,i,o),Or(u,i,s,o,{roundTo:l}),c==="context"&&(t.variables[o]=kt(t.variables[o],i,s,{roundTo:l}))}},Rp=(e,n)=>{Array.isArray(n?.executedActions)&&n.executedActions.forEach(({type:t,payload:r})=>{kg(e,t,r)})},Cp=(e,n)=>{let{sectionId:t,lineId:r}=n,s=de({state:e},{sectionId:t})?.lines?.find(l=>l.id===r)?.actions;s&&Object.entries(s).forEach(([l,a])=>{lc(e,l,a)})},Ta=(e,n)=>{let t=e.contexts?.[e.contexts.length-1];if(!t)return e;let r=yn(t),o=r.timeline[n];if(!o)return e;e.global.autoMode&&at({state:e}),e.global.skipMode&&Je({state:e}),e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),r.isRestoring=!0,r.currentIndex=n;try{t.variables=Ao(e.projectData),t.kind==="sceneReplay"&&(_a(e,t),t.sceneReplay.finishOnNextAdvance=!1,t.sceneReplay.exitOnLineCompleted=!1),delete t.runtime,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,e.global.nextLineConfig=k(Ut),e.global.overlayStack=[],On(e),$n(e),e.global.isLineCompleted=!0;let i=r.replayStartIndex??0;for(let l=i;l<=n;l++)l>i&&yo(e),Cp(e,r.timeline[l]),Rp(e,r.timeline[l]);let s=Tn(t);s.read={sectionId:o.sectionId,lineId:o.lineId},t.kind==="sceneReplay"&&(t.sceneReplay.entryId=ua(e)),e.global.pendingEffects=e.global.pendingEffects.filter(l=>l?.name!=="render"),e.global.pendingEffects.push({name:"render"})}finally{r.isRestoring=!1}return e},_p=e=>{let{projectData:n}=e,t=e.global??{},{saveSlots:r={},variables:o={},runtime:i={},accountViewedRegistry:s={}}=t;pa(n),jn(n),Fn(n),Un(n),an(n?.resources?.variables??{});let l=n.story.initialSceneId,a=n.story.scenes[l],c=a.initialSectionId,u=a.sections[c],d={sceneId:l,sectionId:c,lineId:u.initialLineId??u.lines[0].id},{globalVariablesDefaultValues:f}=Ct(n),p={...f,...An(o,n.resources?.variables??{})};return{projectData:n,global:{pendingEffects:[],confirmDialog:null,formDrafts:{},accountViewedRegistry:Gf(s,"accountViewedRegistry"),nextLineConfig:et(),imageGalleryNavigation:po(),sceneReplayNavigation:ho(),sceneReplayEntryId:0,audioCommandId:0,musicRoomPlayer:zt(),saveSlots:Uf(r),overlayStack:[],variables:p,...cp({loadedGlobalRuntime:i})},contexts:[Eo({pointer:d,projectData:n})]}},kp=({state:e})=>e.global.overlayStack||[],Op=({state:e})=>e.global.pendingEffects,La=({state:e})=>e.global.skipMode,$p=({state:e})=>e.global.autoMode,Pa=({state:e})=>e.global.dialogueUIHidden,Na=({state:e})=>{let n=Array.isArray(e.contexts)?e.contexts:[],t=n[n.length-1];if(!t)return[];let{sectionId:r,lineId:o}=t.pointers.read,i=de({state:e},{sectionId:r});if(!i?.lines||!Array.isArray(i.lines))return[];let s=i.lines.findIndex(d=>d.id===o),l=i.lines.slice(0,s+1),a=[],c={},u=Bn({variables:{...e.global?.variables??{},...rt(e)?.variables??{}},runtime:un(e),variableConfigs:e.projectData.resources?.variables??{},eager:!1});for(let d of l){let f=d.actions||{};if(c=cn([c,f]),!f.dialogue)continue;let p=c.dialogue||{},g=Rt({characterId:p.characterId,character:p.character,characters:e.projectData.resources?.characters??{},variables:u}),h=Mf({sectionId:r,lineId:d.id,content:f.dialogue.append===!0?p.content:f.dialogue.content,dialogueState:p,characterName:g});if(f.dialogue.append===!0&&a.length>0){a[a.length-1]={...a[a.length-1],content:h.content,text:h.text,characterId:h.characterId,character:h.character,characterName:h.characterName};continue}a.push(h)}return a},Tp=({state:e})=>e.global.confirmDialog??null,ot=({state:e},{pointer:n}={})=>{let t=n??Ce({state:e})?.pointer,r=sp({state:e,pointer:t});return ap({state:e,form:r.form,pointer:t})},Lp=({state:e},{pointer:n}={})=>!!ot({state:e},{pointer:n}),Ae=({state:e},{pointer:n}={})=>{let t=ot({state:e},{pointer:n});if(t)return{source:Ke,formId:t.id,formKey:t.key};let r=Fa({state:e,pointer:n});return r?{source:_n,resourceId:r}:null},Pp=({state:e,registry:n},t)=>{let{sectionId:r,lineId:o}=t,s=(Array.isArray(n?.sections)?n.sections:[]).find(u=>u.sectionId===r);if(!s)return!1;if(s.lastLineId===void 0||o===void 0)return!0;let l=de({state:e},{sectionId:r});if(!l||!l.lines||!Array.isArray(l.lines))return s.lastLineId===o;let a=l.lines.findIndex(u=>u.id===s.lastLineId),c=l.lines.findIndex(u=>u.id===o);return a===-1||c===-1?s.lastLineId===o:c<=a},vo=({registry:e},n)=>{let{resourceId:t}=n;return!!(Array.isArray(e?.resources)?e.resources:[]).find(i=>i.resourceId===t)},So=({state:e},n)=>Pp({state:e,registry:e.global.accountViewedRegistry},n),Np=({state:e},n)=>vo({registry:e.global.accountViewedRegistry},n),Qn=(e,n)=>!vo({registry:e.global.accountViewedRegistry},{resourceId:n.imageId}),Ro=e=>e.groups.length===0?0:Math.ceil(e.groups.length/e.pageSize),Co=(e,n)=>{let t=Ro(e);if(t===0)return 0;let r=Number.isInteger(n?.pageIndex)?n.pageIndex:0;return Math.min(Math.max(r,0),t-1)},co=(e,n,t,r)=>{for(let o=t+r;o>=0&&o<n.length;o+=r)if(!Qn(e,n[o]))return n[o]},Dp=({state:e})=>{let n=e.projectData?.resources?.imageGallery;return n===void 0?void 0:k(n)},Da=({state:e})=>{let n=e.projectData?.resources?.imageGallery;if(n===void 0)return null;let t=e.global.imageGalleryNavigation??po(),r=Ro(n),o=Co(n,t),i=o*n.pageSize,s=n.groups.slice(i,i+n.pageSize).map(a=>({groupId:a.id,locked:Qn(e,a.variants[0]),variants:a.variants.map(c=>({variantId:c.id,imageId:c.imageId,locked:Qn(e,c)}))})),l=null;if(typeof t.groupId=="string"&&typeof t.variantId=="string"){let a=n.groups.findIndex(p=>p.id===t.groupId),c=n.groups[a],u=c?.variants.findIndex(p=>p.id===t.variantId),d=u===void 0||u<0?void 0:c.variants[u],f=a<0?-1:Math.floor(a/n.pageSize);d&&f===o&&!Qn(e,d)&&(l={groupId:c.id,variantId:d.id,imageId:d.imageId,canMoveToPreviousVariant:co(e,c.variants,u,-1)!==void 0,canMoveToNextVariant:co(e,c.variants,u,1)!==void 0})}return{pageGroups:s,selection:l,pagination:{pageIndex:o,pageCount:r,canMoveToPreviousPage:o>0,canMoveToNextPage:o+1<r}}},_o=(e,n)=>!vo({registry:e.global.accountViewedRegistry},{resourceId:n.soundId}),ko=e=>e.tracks.length===0?0:Math.ceil(e.tracks.length/e.pageSize),Oo=(e,n)=>{let t=ko(e);if(t===0)return 0;let r=Number.isInteger(n?.pageIndex)?n.pageIndex:0;return Math.min(Math.max(r,0),t-1)},lo=(e,n,t,r)=>{for(let o=t+r;o>=0&&o<n.length;o+=r)if(!_o(e,n[o]))return n[o]},Ma=e=>({trackId:e.id,soundId:e.soundId,title:e.title,artist:e.artist??null,album:e.album??null,description:e.description??null,coverImageId:e.coverImageId??null}),Mp=(e,n)=>({...Ma(n),locked:_o(e,n)}),aa=e=>{let n=Math.floor(e/1e3),t=n%60,r=Math.floor(n/60);if(r<60)return`${r}:${String(t).padStart(2,"0")}`;let o=Math.floor(r/60),i=r%60;return`${o}:${String(i).padStart(2,"0")}:${String(t).padStart(2,"0")}`},Vp=({state:e})=>{let n=e.projectData?.resources?.musicRoom;return n===void 0?void 0:k(n)},Va=({state:e})=>{let n=e.projectData?.resources?.musicRoom;if(n===void 0)return null;let t=e.global.musicRoomPlayer??zt(),r=ko(n),o=Oo(n,t),i=o*n.pageSize,s=n.tracks.slice(i,i+n.pageSize).map(u=>Mp(e,u)),l=n.tracks.findIndex(u=>u.id===t.trackId),a=n.tracks[l],c=a?{...Ma(a),canPlayPreviousTrack:lo(e,n.tracks,l,-1)!==void 0,canPlayNextTrack:lo(e,n.tracks,l,1)!==void 0}:null;return{pageTracks:s,selection:c,playback:c?{status:t.status,readiness:t.readiness,positionMs:t.positionMs,durationMs:t.durationMs,positionText:aa(t.positionMs),durationText:t.durationMs===null?null:aa(t.durationMs),canPlay:t.status!=="playing",canPause:t.status==="playing",canSeek:t.readiness==="ready"&&t.durationMs!==null}:null,pagination:{pageIndex:o,pageCount:r,canMoveToPreviousPage:o>0,canMoveToNextPage:o+1<r}}},$o=e=>e.replays.length===0?0:Math.ceil(e.replays.length/e.pageSize),To=(e,n)=>{let t=$o(e);if(t===0)return 0;let r=Number.isInteger(n?.pageIndex)?n.pageIndex:0;return Math.min(Math.max(r,0),t-1)},jp=({state:e})=>{let n=e.projectData?.resources?.sceneReplay;return n===void 0?void 0:k(n)},Fp=({state:e})=>J(e)!==null,Up=({state:e})=>{let n=J(e);return n?{replayId:n.sceneReplay.replayId,entryId:n.sceneReplay.entryId}:null},ja=({state:e})=>{let n=e.projectData?.resources?.sceneReplay;if(n===void 0)return null;let t=e.global.sceneReplayNavigation??ho(),r=$o(n),o=To(n,t),i=o*n.pageSize,s=n.replays.slice(i,i+n.pageSize).map(a=>({replayId:a.id,title:a.title,thumbnailImageId:a.thumbnailImageId})),l=J(e);return{isActive:l!==null,activeReplayId:l?.sceneReplay.replayId??null,pageReplays:s,pagination:{pageIndex:o,pageCount:r,canMoveToPreviousPage:o>0,canMoveToNextPage:o+1<r}}},Bp=({state:e})=>e.global.nextLineConfig,Fa=({state:e,pointer:n}={})=>{let t=n??Ce({state:e})?.pointer;if(!t)return;let r=t?.sectionId,o=t?.lineId,s=de({state:e},{sectionId:r})?.lines||[],l=s.findIndex(c=>c.id===o);if(l<0)return;let a;for(let c of s.slice(0,l+1)){let u=c?.actions;if(u?.cleanAll&&(a=void 0),!u||!Object.prototype.hasOwnProperty.call(u,"choice")){a=void 0;continue}let d=u.choice;if(d?.resourceId){a=d.resourceId;continue}d?.animations||(a=void 0)}return a},Ua=({state:e})=>!!Fa({state:e}),Gp=({state:e})=>structuredClone(e),zp=({state:e})=>k(e.projectData.resources?.achievements??{}),qp=({state:e},n)=>{let t=e.projectData.resources?.achievements?.[n?.resourceId];return t===void 0?void 0:k(t)},Ba=({state:e})=>e.global.saveSlots,Yp=({state:e},n)=>{let t=n?.slotId,r=tt(t);return e.global.saveSlots[r]},Lo=({state:e})=>un(e),Hp=({state:e},n)=>Ye(e,n?.runtimeId),Yt=({state:e})=>{let n={...e.global?.variables??{},...rt(e)?.variables??{}};return Bn({variables:n,runtime:un(e),variableConfigs:e.projectData.resources?.variables??{}})},Ce=({state:e})=>{let n=Array.isArray(e.contexts)?e.contexts:[],t=n[n.length-1];if(t)return{currentPointerMode:"read",pointer:t.pointers?.read}},de=({state:e},n)=>{let{sectionId:t}=n;return hn(e.projectData,t).section},Ht=({state:e})=>{let n=Ce({state:e});if(!n?.pointer)return;let{sectionId:t,lineId:r}=n.pointer,o=de({state:e},{sectionId:t});if(!(!o?.lines||!Array.isArray(o.lines)))return o.lines.find(i=>i.id===r)},Ga=({state:e})=>{let{sectionId:n,lineId:t}=Ce({state:e}).pointer,o=de({state:e},{sectionId:n})?.lines||[],i=o.findIndex(c=>c.id===t),l=o.slice(0,i+1).map(c=>{let u=c.actions||{},d={};return Object.keys(u).forEach(f=>{d[f]=u[f]}),d});return cn(l)},Wp=e=>{let n=Ht({state:e})?.actions?.dialogue;if(n?.clear===!0||!Array.isArray(n?.content))return"";let t=Yt({state:e});return n.content.map(r=>`${En(r?.text,{variables:t})??""}`).join("")},it=({state:e})=>ta({text:Wp(e),baseDelay:Ye(e,"autoForwardDelay"),speed:Ye(e,"autoForwardSpeed")}),Kp=({state:e})=>{let n=za({state:e}),r=Ht({state:e})?.actions??{},o=cn([n??{},r]);return Tr(n??{},o??{})},Jp=({state:e},{sectionId:n})=>{let t=de({state:e},{sectionId:n});if(!t?.lines)return[];let r=[],o={};for(let i of t.lines){let s=i.actions||{},l=cn([o,s]),a=Tr(o,l);r.push({id:i.id,changes:a,presentationState:l}),o=Lr(l)}return r},Xp=({state:e},{sectionId:n,includePresentationState:t=!1})=>{let r=Jp({state:e},{sectionId:n});return t?{lines:r}:{lines:r.map(({presentationState:o,...i})=>i)}},za=({state:e})=>{let{sectionId:n,lineId:t}=Ce({state:e}).pointer,o=de({state:e},{sectionId:n})?.lines||[],i=o.findIndex(a=>a.id===t);if(i<=0)return null;let l=o.slice(0,i).map(a=>{let c=a.actions||{},u={};return Object.keys(c).forEach(d=>{u[d]=c[d]}),u});return Lr(cn(l))},Po=({state:e},{slotsPerPage:n=6}={})=>{let o=((Lo({state:e}).saveLoadPagination??1)-1)*n+1,i=[];for(let s=0;s<n;s++){let l=o+s,a=e.global.saveSlots&&e.global.saveSlots[tt(l)]||{};i.push({...a,slotId:l})}return{saveSlots:i}},Qp=Ba,Zp=Po,em=e=>{let t=e.contexts?.[e.contexts.length-1]?.rollback;return!t||!Array.isArray(t.timeline)||typeof t.currentIndex!="number"?!1:t.currentIndex>=0&&t.currentIndex<t.timeline.length-1},nm=({state:e},n={})=>{let t=Ga({state:e}),r=za({state:e}),o=Ht({state:e})?.actions??{},i=e.global.pendingScreenTransition,s=i?.animations?{...o,screen:k(i)}:o,l=i?.animations&&r===null?{}:r,{sectionId:a}=Ce({state:e}).pointer,{sceneId:c}=hn(e.projectData,a),u=Lo({state:e}),d=n?.activePersistentAnimations??[],f=n?.restoredPersistentAnimations??[],p=ot({state:e}),g=Ua({state:e}),h=Da({state:e}),b=Va({state:e}),I=ja({state:e}),E=Yt({state:e}),{saveSlots:A}=Po({state:e}),$=em(e);return Ps({presentationState:t,previousPresentationState:l,currentLineActions:s,resources:e.projectData.resources,currentSceneId:c,screen:e.projectData.screen,dialogueUIHidden:u.dialogueUIHidden,autoMode:u.autoMode,skipMode:u.skipMode,isChoiceVisible:g,isFormVisible:!!p,canRollback:fc({state:e}),skipOnlyViewedLines:!u.skipUnseenText,isLineCompleted:u.isLineCompleted,skipTransitionsAndAnimations:!!u.skipTransitionsAndAnimations||$,overlayStack:e.global.overlayStack,confirmDialog:e.global.confirmDialog,form:p,dialogueHistory:Na({state:e}),saveSlots:A,variables:E,runtime:u,activePersistentAnimations:d,restoredPersistentAnimations:f,imageGallery:h,musicRoom:b,sceneReplay:I,musicRoomPlayer:k(e.global.musicRoomPlayer)})},tm=({state:e},n)=>(e.global.confirmDialog=Zf(n),e.global.pendingEffects.push({name:"render"}),e),rm=({state:e})=>(e.global.confirmDialog&&(On(e),e.global.pendingEffects.push({name:"render"})),e),om=({state:e},n)=>(e.global.overlayStack.push(n),e.global.pendingEffects.push({name:"render"}),Le(e,"pushOverlay",n),e),im=({state:e})=>(e.global.overlayStack.pop(),e.global.pendingEffects.push({name:"render"}),Le(e,"popOverlay",void 0),e),sm=({state:e},n)=>(e.global.overlayStack.length>0&&(e.global.overlayStack[e.global.overlayStack.length-1]=n),e.global.pendingEffects.push({name:"render"}),Le(e,"replaceLastOverlay",n),e),am=({state:e})=>(e.global.overlayStack=[],On(e),$n(e),e.global.pendingEffects.push({name:"render"}),Le(e,"clearOverlays",void 0),e),cm=(e,{activeInteraction:n})=>{e.global.autoMode&&e.global.pendingEffects.push({name:"clearAutoNextTimer"}),n&&e.global.skipMode&&e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.nextLineConfig?.auto?.enabled&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"})},st=(e,n,{screenTransition:t}={})=>{e.global.isLineCompleted=!1,np(e,t),$n(e);let r=Ae({state:e},{pointer:n}),o=r?.source===_n,i=r?.source===Ke;cm(e,{activeInteraction:r});let s=J(e),l={name:"handleLineActions"};if(typeof s?.sceneReplay?.replayId=="string"){let a=ua(e);s.sceneReplay.entryId=a,l.payload={sceneReplayId:s.sceneReplay.replayId,entryId:a}}return e.global.pendingEffects.push(l),{isChoiceVisible:o,isFormVisible:i,activeInteraction:r}},Wt=(e,n,t)=>{!(n?.source===_n||n?.source===Ke)||t||!e.global.skipMode||e.global.pendingEffects.push({name:"startSkipNextTimer"})},qa=({state:e})=>(Ae({state:e})||(e.global.skipMode&&(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"})),e.global.autoMode=!0,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.isLineCompleted&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:it({state:e})}}),e.global.pendingEffects.push({name:"render"})),e),at=({state:e})=>(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),lm=({state:e})=>{let n=e.global.autoMode;return Ae({state:e})&&!n||(n?at({state:e}):qa({state:e})),e},Ya=({state:e})=>(Ae({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),Je=({state:e})=>(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),um=({state:e})=>{let n=La({state:e});return Ae({state:e})&&!n||(n?Je({state:e}):Ya({state:e})),e},Kt=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),Le(e,"showDialogueUI",void 0),e),Ha=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),Le(e,"hideDialogueUI",void 0),e),dm=({state:e})=>(Pa({state:e})?Kt({state:e}):Ha({state:e}),e),Xe=(e,n,t)=>(Oa(e,n,t),gp(e),e.global.pendingEffects.push({name:"render"}),e),ct=(e,n,t,r)=>{let o=Oa(e,n,t);return e.global.pendingEffects.push({name:"render"}),Le(e,r,{value:o}),e},fm=({state:e},n)=>Xe(e,"dialogueTextSpeed",n?.value),pm=({state:e},n)=>Xe(e,"autoForwardDelay",n?.value),mm=({state:e},n)=>Xe(e,"autoForwardSpeed",n?.value),gm=({state:e},n)=>Xe(e,"skipUnseenText",n?.value),hm=({state:e},n)=>Xe(e,"skipTransitionsAndAnimations",n?.value),ym=({state:e},n)=>Xe(e,"soundVolume",n?.value),bm=({state:e},n)=>Xe(e,"musicVolume",n?.value),Im=({state:e},n)=>Xe(e,"muteAll",n?.value),wm=({state:e},n)=>ct(e,"saveLoadPagination",n?.value,"setSaveLoadPagination"),Am=({state:e})=>{let n=Ye(e,"saveLoadPagination")+1;return ct(e,"saveLoadPagination",n,"incrementSaveLoadPagination"),e},Em=({state:e})=>{let n=Ye(e,"saveLoadPagination")-1;return ct(e,"saveLoadPagination",n,"decrementSaveLoadPagination"),e},xm=({state:e},n)=>ct(e,"menuPage",n?.value,"setMenuPage"),vm=({state:e},n)=>ct(e,"menuEntryPoint",n?.value,"setMenuEntryPoint"),Sm=({state:e})=>(e.global.pendingEffects=[],e),Rm=({state:e},n)=>(e.global.pendingEffects.push(n),e),Cm=({state:e},n)=>{if(J(e))return e;let t=n?.resourceId;return da(e,t),e.global.pendingEffects.push({name:"completeAchievement",payload:{resourceId:t}}),e},_m=({state:e},n)=>{if(J(e))return e;let t=n?.resourceId,r=da(e,t);if(r.type!=="number")throw new Error(`Achievement resource "${t}" does not support numeric progress`);let o=n?.current;if(!Number.isInteger(o)||o<0)throw new Error(`Achievement progress for "${t}" must be a non-negative integer`);if(!Number.isInteger(r.target)||r.target<1)throw new Error(`Achievement resource "${t}" must have a positive integer target`);let i=Math.min(o,r.target);return e.global.pendingEffects.push({name:"setAchievementProgress",payload:{resourceId:t,current:i,target:r.target,completed:i>=r.target}}),e},Wa=(e,{sectionId:n,resetStoryState:t=!1,screen:r})=>{let o=!!xa(r),i=de({state:e},{sectionId:n});if(!i)return console.warn(`Section not found: ${n}`),e;let s=i.lines?.[0];if(!s)return console.warn(`Section ${n} has no lines`),e;if(t&&!bp(e,{queueRender:!o}))return e;let l=Ae({state:e});t&&e.global.skipMode&&Je({state:e});let a=e.contexts?.[e.contexts.length-1];if(a){let u=Tn(a),d=u.read;t||gn(e,{sectionId:d?.sectionId,lineId:d?.lineId}),a.rollback||yn(a,{compatibilityAnchor:!0}),u.read={sectionId:n,lineId:s.id},t?a.rollback=Zn({pointer:u.read}):xo(e,{sectionId:n,lineId:s.id})}let{activeInteraction:c}=st(e,a?.pointers?.read,{screenTransition:r});return Wt(e,l,c),e},km=({state:e},n)=>{if(J(e))throw new Error("Cannot reset the story while a scene replay is active");return Wa(e,{sectionId:n?.sectionId,resetStoryState:!0,screen:n?.screen})},Ka=e=>(e.global.accountViewedRegistry=Nf(e.global.accountViewedRegistry),e.global.accountViewedRegistry),No=(e,n)=>{!Array.isArray(n)||n.length===0||e.global.pendingEffects.push({name:"applyScopedDataUpdates",payload:{updates:n.map(t=>({scope:t.scope,path:t.path,op:t.op,value:k(t.value)}))}})},Ja=(e,n)=>{No(e,[{scope:"account",path:"viewedRegistry",op:"markViewed",value:{sections:(Array.isArray(n?.sections)?n.sections:[]).map(t=>({sectionId:t.sectionId,...t.lastLineId===void 0?{}:{lineId:t.lastLineId}})),resources:Array.isArray(n?.resources)?n.resources:[]}}])},Om=(e,n,{sectionId:t,lineId:r})=>{if(!t||!r)return!1;let o=N(n)?n:{};Array.isArray(o.sections)||(o.sections=[]);let i=o.sections.find(s=>s.sectionId===t);if(i){if(i.lastLineId===void 0)return!1;let s=de({state:e},{sectionId:t});if(s?.lines){let l=s.lines.findIndex(c=>c.id===i.lastLineId),a=s.lines.findIndex(c=>c.id===r);if(l===-1||a>l)return i.lastLineId===r?!1:(i.lastLineId=r,!0)}else return i.lastLineId===r?!1:(i.lastLineId=r,!0);return!1}else return o.sections.push({sectionId:t,lastLineId:r}),!0},gn=(e,n)=>{if(J(e)||e.global.accountViewedRegistry===void 0)return;Om(e,Ka(e),n)&&Ja(e,{sections:[{sectionId:n.sectionId,lastLineId:n.lineId}],resources:[]})},$m=({state:e},n)=>(gn(e,n),e.global.pendingEffects.push({name:"render"}),e),Tm=({state:e},n)=>{if(J(e))return e;let{resourceId:t}=n;if(e.global.accountViewedRegistry!==void 0){let r=Ka(e);r.resources.find(i=>i.resourceId===t)||(r.resources.push({resourceId:t}),Ja(e,{sections:[],resources:[{resourceId:t}]}))}return e.global.pendingEffects.push({name:"render"}),e},Pe=(e,n,t)=>{if(!N(n))throw new Error(`${e} payload must be an object`);Object.keys(n).forEach(r=>{if(!t.has(r))throw new Error(`${e} payload contains unsupported property "${r}"`)})},uo=(e,n,t)=>{if(typeof t!="string"||t.length===0)throw new Error(`${e} requires a non-empty ${n}`)},Jt=(e,n)=>{let t=e.global.imageGalleryNavigation;t.groupId===n.groupId&&t.variantId===n.variantId&&t.pageIndex===n.pageIndex||(e.global.imageGalleryNavigation=n,e.global.pendingEffects.push({name:"render"}))},Lm=({state:e},n)=>{let t="showImageGalleryVariant";Pe(t,n,_f),uo(t,"groupId",n.groupId),Object.prototype.hasOwnProperty.call(n,"variantId")&&uo(t,"variantId",n.variantId);let r=e.projectData?.resources?.imageGallery;if(r===void 0)return e;let o=r.groups.findIndex(l=>l.id===n.groupId),i=r.groups[o];if(!i)return e;let s=n.variantId===void 0?i.variants[0]:i.variants.find(l=>l.id===n.variantId);return!s||Qn(e,s)||Jt(e,{groupId:i.id,variantId:s.id,pageIndex:Math.floor(o/r.pageSize)}),e},Xa=(e,n,t,r)=>{Pe(r,n,mo);let o=e.projectData?.resources?.imageGallery;if(o===void 0)return e;let i=e.global.imageGalleryNavigation;if(typeof i.groupId!="string"||typeof i.variantId!="string")return e;let s=o.groups.find(c=>c.id===i.groupId),l=s?.variants.findIndex(c=>c.id===i.variantId);if(!s||l===void 0||l<0)return e;let a=co(e,s.variants,l,t);return a&&Jt(e,{...i,variantId:a.id}),e},Pm=({state:e},n)=>Xa(e,n,-1,"moveToPreviousImageGalleryVariant"),Nm=({state:e},n)=>Xa(e,n,1,"moveToNextImageGalleryVariant"),Dm=({state:e},n)=>{if(Pe("clearImageGallerySelection",n,mo),e.projectData?.resources?.imageGallery===void 0)return e;let r=e.global.imageGalleryNavigation;return Jt(e,{groupId:null,variantId:null,pageIndex:r.pageIndex}),e},Qa=(e,n)=>{let t=e.projectData?.resources?.imageGallery;if(t===void 0)return e;let r=Ro(t);if(n>=r)return e;let o=e.global.imageGalleryNavigation,i=Co(t,o);return n===i||Jt(e,{groupId:null,variantId:null,pageIndex:n}),e},Mm=({state:e},n)=>{if(Pe("moveToImageGalleryPage",n,kf),!Number.isInteger(n.pageIndex)||n.pageIndex<0)throw new Error("moveToImageGalleryPage requires a non-negative integer pageIndex");return Qa(e,n.pageIndex)},Za=(e,n,t,r)=>{Pe(r,n,mo);let o=e.projectData?.resources?.imageGallery;if(o===void 0)return e;let s=Co(o,e.global.imageGalleryNavigation)+t;return s<0?e:Qa(e,s)},Vm=({state:e},n)=>Za(e,n,1,"moveToNextImageGalleryPage"),jm=({state:e},n)=>Za(e,n,-1,"moveToPreviousImageGalleryPage"),Fe=(e,n,t)=>{if(!N(n))throw new Error(`${e} payload must be an object`);Object.keys(n).forEach(r=>{if(!t.has(r))throw new Error(`${e} payload contains unsupported property "${r}"`)})},Fm=(e,n)=>{if(typeof n!="string"||n.length===0)throw new Error(`${e} requires a non-empty trackId`)},Oe=e=>{e.global.pendingEffects.push({name:"render"})},ec=(e,n)=>{let t=e.projectData.resources.musicRoom,r=e.global.musicRoomPlayer,o=r.trackId!==null,i=r.trackId===n.id,s=r.bgmPlayback;o||(s={commandId:qt(e),operation:"pause"});let l=nt(e,"play",0),a=t.tracks.indexOf(n),c=i?r.durationMs:null;e.global.musicRoomPlayer={trackId:n.id,pageIndex:Math.floor(a/t.pageSize),status:"playing",readiness:c===null?"loading":"ready",positionMs:0,durationMs:c,playback:l,seekFallback:null,bgmPlayback:s},Oe(e)},Um=({state:e},n)=>{let t="playMusicRoomTrack";Fe(t,n,Of),Fm(t,n.trackId);let o=e.projectData?.resources?.musicRoom?.tracks.find(i=>i.id===n.trackId);return!o||_o(e,o)||ec(e,o),e},Bm=({state:e},n)=>{Fe("playMusicRoom",n,kn);let r=e.global.musicRoomPlayer;if(r.trackId===null||r.status==="playing")return e;let o=r.status==="ended",i=r.readiness==="error",s=r.status==="paused"&&!i?"resume":"play",l=o?0:r.positionMs;return r.playback=nt(e,s,s==="play"?l:void 0),r.seekFallback=null,r.status="playing",r.positionMs=l,i&&(r.readiness=r.durationMs===null?"loading":"ready"),Oe(e),e},Gm=({state:e},n)=>{Fe("pauseMusicRoom",n,kn);let r=e.global.musicRoomPlayer;return r.trackId===null||r.status!=="playing"||(r.playback=nt(e,"pause"),r.seekFallback=null,r.status="paused",Oe(e)),e},zm=({state:e},n)=>{Fe("stopMusicRoom",n,kn);let r=e.global.musicRoomPlayer;return r.trackId===null||r.status==="stopped"&&r.positionMs===0||(r.playback=nt(e,"stop"),r.seekFallback=null,r.status="stopped",r.positionMs=0,Oe(e)),e},qm=({state:e},n)=>{if(Fe("seekMusicRoom",n,$f),typeof n.positionMs!="number"||!Number.isFinite(n.positionMs)||n.positionMs<0)throw new Error("seekMusicRoom requires a finite non-negative positionMs");let r=e.global.musicRoomPlayer;if(r.trackId===null||r.readiness!=="ready"||r.durationMs===null||n.positionMs>r.durationMs)return e;let o=nt(e,"seek",n.positionMs);return r.seekFallback={commandId:o.commandId,status:r.status,positionMs:r.positionMs},r.playback=o,r.positionMs=n.positionMs,n.positionMs===r.durationMs?r.status="ended":r.status==="ended"&&(r.status="stopped"),Oe(e),e},nc=(e,n,t,r)=>{Fe(r,n,kn);let o=e.projectData?.resources?.musicRoom,i=e.global.musicRoomPlayer;if(!o||i.trackId===null)return e;let s=o.tracks.findIndex(a=>a.id===i.trackId);if(s<0)return e;let l=lo(e,o.tracks,s,t);return l&&ec(e,l),e},Ym=({state:e},n)=>nc(e,n,-1,"playPreviousMusicRoomTrack"),Hm=({state:e},n)=>nc(e,n,1,"playNextMusicRoomTrack"),Wm=({state:e},n)=>{Fe("clearMusicRoomSelection",n,kn);let r=e.global.musicRoomPlayer;if(r.trackId===null)return e;let o=r.pageIndex,i={commandId:qt(e),operation:"resume"};return e.global.musicRoomPlayer={...zt({bgmPlayback:i}),pageIndex:o},Oe(e),e},tc=(e,n)=>{let t=e.projectData?.resources?.musicRoom;if(!t||n>=ko(t))return e;let r=e.global.musicRoomPlayer,o=Oo(t,r);return n===o||(r.pageIndex=n,Oe(e)),e},Km=({state:e},n)=>{if(Fe("moveToMusicRoomPage",n,Tf),!Number.isInteger(n.pageIndex)||n.pageIndex<0)throw new Error("moveToMusicRoomPage requires a non-negative integer pageIndex");return tc(e,n.pageIndex)},rc=(e,n,t,r)=>{Fe(r,n,kn);let o=e.projectData?.resources?.musicRoom;if(!o)return e;let i=Oo(o,e.global.musicRoomPlayer)+t;return i<0?e:tc(e,i)},Jm=({state:e},n)=>rc(e,n,1,"moveToNextMusicRoomPage"),Xm=({state:e},n)=>rc(e,n,-1,"moveToPreviousMusicRoomPage"),pn=e=>{let n=J(e);if(!n)return!1;if(e.contexts.length<2)throw new Error("Scene replay context has no caller context to restore");let t=k(n.sceneReplay.returnState),r=n.sceneReplay.replayId;return e.global.pendingEffects=e.global.pendingEffects.filter(o=>o?.name!=="handleLineActions"||o?.payload?.sceneReplayId!==r),e.contexts.pop(),fp(e,t),e.global.pendingEffects.push({name:"render"}),!0},Qm=({state:e},n)=>{let t="startSceneReplay";if(Pe(t,n,Lf),uo(t,"replayId",n.replayId),J(e))throw new Error("Cannot start a scene replay while another replay is active");let o=e.projectData?.resources?.sceneReplay?.replays.find(u=>u.id===n.replayId);if(!o)return e;let{sceneId:i,section:s}=hn(e.projectData,o.startSectionId),l=s?.initialLineId??s?.lines?.[0]?.id;if(!s||!l||!s.lines.some(u=>u.id===l))throw new Error(`Scene replay "${o.id}" has an invalid start section`);let a=up(e);dp(e);let c=Eo({pointer:{sceneId:i,sectionId:o.startSectionId,lineId:l},projectData:e.projectData,kind:"sceneReplay",sceneReplay:{replayId:o.id,entryId:0,finishOnNextAdvance:!1,exitOnLineCompleted:!1,returnState:a}});return _a(e,c),e.contexts.push(c),st(e,c.pointers.read),e},oc=({state:e},n)=>{Pe("finishSceneReplay",n,go);let r=J(e);return r&&(r.sceneReplay.finishOnNextAdvance=!0),e},Zm=({state:e},n)=>(Pe("exitSceneReplay",n,go),pn(e),e),ic=(e,n)=>{let t=e.projectData?.resources?.sceneReplay;if(!t||n>=$o(t))return e;let r=To(t,e.global.sceneReplayNavigation);return n===r||(e.global.sceneReplayNavigation.pageIndex=n,e.global.pendingEffects.push({name:"render"})),e},eg=({state:e},n)=>{if(Pe("moveToSceneReplayPage",n,Pf),!Number.isInteger(n.pageIndex)||n.pageIndex<0)throw new Error("moveToSceneReplayPage requires a non-negative integer pageIndex");return ic(e,n.pageIndex)},sc=(e,n,t,r)=>{Pe(r,n,go);let o=e.projectData?.resources?.sceneReplay;if(!o)return e;let i=To(o,e.global.sceneReplayNavigation)+t;return i<0?e:ic(e,i)},ng=({state:e},n)=>sc(e,n,1,"moveToNextSceneReplayPage"),tg=({state:e},n)=>sc(e,n,-1,"moveToPreviousSceneReplayPage"),Xt=(e,n)=>{let t=e.global.musicRoomPlayer;return!N(n)||n.id!==Rf||t.trackId===null||!t.playback||n.commandId!==t.playback.commandId?null:t},Do=e=>typeof e.positionMs=="number"&&Number.isFinite(e.positionMs)&&e.positionMs>=0&&typeof e.durationMs=="number"&&Number.isFinite(e.durationMs)&&e.durationMs>0&&e.positionMs<=e.durationMs,ac=(e,n,t,{readiness:r=n.readiness}={})=>((n.readiness!==r||n.positionMs!==t.positionMs||n.durationMs!==t.durationMs||n.seekFallback!==null)&&(n.readiness=r,n.positionMs=t.positionMs,n.durationMs=t.durationMs,n.seekFallback=null,Oe(e)),e),rg=({state:e},n)=>{let t=Xt(e,n);return!t||t.readiness!=="loading"||!Do(n)?e:ac(e,t,n,{readiness:"ready"})},og=({state:e},n)=>{let t=Xt(e,n);return!t||t.readiness!=="ready"||!Do(n)||t.status==="stopped"&&n.positionMs!==0||t.status==="ended"&&n.positionMs!==n.durationMs?e:ac(e,t,n)},ig=({state:e},n)=>{let t=Xt(e,n);return!t||t.readiness!=="ready"||t.status!=="playing"||!Do(n)||n.positionMs!==n.durationMs||(t.status="ended",t.positionMs=n.positionMs,t.durationMs=n.durationMs,t.seekFallback=null,Oe(e)),e},sg=({state:e},n)=>{let t=Xt(e,n);if(!t||typeof n.errorCode!="string"||!Cf.has(n.errorCode)||t.readiness==="error"&&t.status==="stopped")return e;if(n.errorCode==="invalid-position"){let r=t.seekFallback;if(t.playback.operation!=="seek"||r?.commandId!==n.commandId)return e;let o=t.status!==r.status||t.positionMs!==r.positionMs;return t.status=r.status,t.positionMs=r.positionMs,t.seekFallback=null,o&&Oe(e),e}return t.readiness="error",t.status="stopped",t.positionMs=0,t.seekFallback=null,Oe(e),e},cc=({state:e},n)=>{let t=jf(n.manual),{auto:r,applyMode:o}=n,i=e.global.nextLineConfig.auto?.enabled,s=e.global.nextLineConfig?.applyMode,l=e.contexts?.[e.contexts.length-1]?.rollback?.isRestoring===!0;t&&r?(e.global.nextLineConfig={manual:t,auto:r},o!==void 0?e.global.nextLineConfig.applyMode=o:s!==void 0&&(e.global.nextLineConfig.applyMode=s)):(t&&(e.global.nextLineConfig.manual=t),r&&(e.global.nextLineConfig.auto=r),o!==void 0&&(e.global.nextLineConfig.applyMode=o));let a=e.global.nextLineConfig.auto?.enabled,c=Ae({state:e});return!l&&!c&&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}}):!l&&a===!1&&i&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.pendingEffects.push({name:"render"}),Le(e,"setNextLineConfig",n),e},ag=({state:e},n)=>{if(J(e))throw new Error("Cannot save while a scene replay is active");let t=n?.slotId;if(t==null||t==="")throw new Error("saveSlot requires slotId");let{thumbnailImage:r}=n,o=n?.savedAt,i=tt(t),s=k(e.contexts);s?.forEach(c=>{Tn(c),$a(c.rollback),Bf(c.rollback)});let l={contexts:s},a={formatVersion:la,slotId:ma(t),savedAt:typeof o=="number"?o:Date.now(),image:r,state:l};return e.global.saveSlots[i]=a,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}},{name:"render"}),e},cg=({state:e},n)=>{if(J(e))throw new Error("Cannot load while a scene replay is active");let t=n?.slotId;if(t==null||t==="")throw new Error("loadSlot requires slotId");let r=tt(t),o=e.global.saveSlots[r];if(o){let i=Qf(o,e.projectData);e.contexts=i.state.contexts,e.global.autoMode=!1,e.global.skipMode=!1,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,e.global.nextLineConfig=et(),e.global.overlayStack=[],e.global.isLineCompleted=!0,On(e),$n(e),bo(e),e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"},{name:"render"})}return e},lg=({state:e},n)=>{if(J(e))throw new Error("Cannot update project data while a scene replay is active");let{projectData:t}=n;pa(t),jn(t),Fn(t),Un(t),an(t?.resources?.variables??{}),e.projectData=t,e.global.imageGalleryNavigation=po(),e.global.sceneReplayNavigation=ho(),bo(e);let r=t?.resources?.variables??{},{contextVariableDefaultValues:o,globalVariablesDefaultValues:i}=Ct(t??{});return Object.prototype.hasOwnProperty.call(e.global??{},"variables")&&(e.global.variables={...i,...An(e.global.variables,r)}),e.contexts?.forEach(s=>{Object.prototype.hasOwnProperty.call(s??{},"variables")&&(s.variables={...o,...An(s.variables,r)})}),On(e),$n(e),e.global.pendingEffects.push({name:"render"}),e},ug=({state:e},n)=>{let{sectionId:t,lineId:r}=n;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=t||o.pointers.read?.sectionId;if(t&&!de({state:e},{sectionId:t}))return console.warn(`Section not found: ${t}`),e;let s=de({state:e},{sectionId:i});if(!s?.lines||!Array.isArray(s.lines))return console.warn(`Section ${i} has no lines`),e;if(!s.lines.find(d=>d.id===r))return console.warn(`Line not found: ${r} in section ${i}`),e;let a=Ae({state:e}),c=Tn(o);c.read={sectionId:i,lineId:r};let{activeInteraction:u}=st(e,c.read);return Wt(e,a,u),e},dg=({state:e},n)=>{if(!e.global.nextLineConfig.manual.enabled)return e;if(e.global.dialogueUIHidden)return Kt({state:e}),e;let t=Ae({state:e});if(t?.source===_n&&n?.bypassChoice!==!0||t?.source===Ke&&n?._interactionSource!==Ke)return e;if(!e.global.isLineCompleted){if(e.global.isLineCompleted=!0,delete e.global.pendingScreenTransition,J(e)?.sceneReplay.exitOnLineCompleted)return pn(e),e;let f=Ce({state:e})?.pointer,p=f?.sectionId,g=f?.lineId;p&&g&&gn(e,{sectionId:p,lineId:g}),e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.autoMode&&!t&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:it({state:e})}});let h=e.global.nextLineConfig;return h?.auto?.enabled&&!t&&h.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:h.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e}if(J(e)?.sceneReplay.finishOnNextAdvance)return pn(e),e;let o=Ce({state:e})?.pointer,i=o?.sectionId,s=de({state:e},{sectionId:i}),l=e.contexts[e.contexts.length-1],a=s?.lines||[],u=a.findIndex(d=>d.id===o?.lineId)+1;if(u<a.length){let d=a[u],f=!Ye(e,"skipUnseenText");if(e.global.skipMode&&f&&!So({state:e},{sectionId:i,lineId:d.id}))return Je({state:e}),e;if(l&&!l.rollback&&yn(l,{compatibilityAnchor:!0}),l){let g=Tn(l),h=g.read?.lineId;h&&i&&gn(e,{sectionId:i,lineId:h}),g.read={sectionId:i,lineId:d.id}}xo(e,{sectionId:i,lineId:d.id}),yo(e);let{activeInteraction:p}=st(e,{sectionId:i,lineId:d.id});Wt(e,t,p)}else{if(J(e))return console.warn("Scene replay reached the end of a section without finishSceneReplay; exiting replay."),pn(e),e;e.global.autoMode&&at({state:e}),e.global.skipMode&&Je({state:e})}return e},fg=({state:e})=>{if(e.global.isLineCompleted)return e;if(e.global.isLineCompleted=!0,delete e.global.pendingScreenTransition,J(e)?.sceneReplay.exitOnLineCompleted)return pn(e),e;let t=Ae({state:e});e.global.autoMode&&!t&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:it({state:e})}});let r=Ce({state:e})?.pointer,o=r?.sectionId,i=r?.lineId;o&&i&&gn(e,{sectionId:o,lineId:i});let s=e.global.nextLineConfig;return s?.auto?.enabled&&!t&&s.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:s.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e},pg=({state:e},n)=>Wa(e,{sectionId:n?.sectionId,screen:n?.screen}),mg=({state:e},n)=>{let t=n?._conditionalContinuation===!0;if(e.global.dialogueUIHidden&&!t)return Kt({state:e}),e;let r=Ae({state:e});if(r?.source===_n&&n?.bypassChoice!==!0||r?.source===Ke&&n?._interactionSource!==Ke||r&&r.source!==_n&&r.source!==Ke)return e;let o=J(e);if(o?.sceneReplay.finishOnNextAdvance)return e.global.isLineCompleted?(pn(e),e):(o.sceneReplay.exitOnLineCompleted=!0,e);let i=Ce({state:e})?.pointer,s=i?.sectionId,l=de({state:e},{sectionId:s}),a=e.contexts[e.contexts.length-1],c=l?.lines||[],d=c.findIndex(f=>f.id===i?.lineId)+1;if(d<c.length){let f=c[d],p=!Ye(e,"skipUnseenText");if(e.global.skipMode&&p&&!So({state:e},{sectionId:s,lineId:f.id})&&(Je({state:e}),!t))return e;if(a&&!a.rollback&&yn(a,{compatibilityAnchor:!0}),a){let h=Tn(a),b=h.read?.lineId;b&&s&&gn(e,{sectionId:s,lineId:b}),h.read={sectionId:s,lineId:f.id}}xo(e,{sectionId:s,lineId:f.id}),yo(e);let{activeInteraction:g}=st(e,{sectionId:s,lineId:f.id});Wt(e,r,g)}else{if(J(e))return console.warn("Scene replay reached the end of a section without finishSceneReplay; exiting replay."),pn(e),e;e.global.autoMode&&at({state:e}),e.global.skipMode&&Je({state:e}),e.global.nextLineConfig.auto?.enabled&&(e.global.nextLineConfig.auto.enabled=!1,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}))}return e},Mo=(e,n={})=>{let t=ot({state:e});return!t||n.formKey&&n.formKey!==t.key||n.formId&&n.formId!==t.id?null:t},gg=(e,n)=>{if(!n.variableId)throw new Error(`form field "${n.id}" requires variableId`);let t=e.projectData.resources?.variables?.[n.variableId],r=t?.scope,o=t?.type;if(Se(t))throw new Error(`Cannot update computed variable: ${n.variableId}`);if(t?.readonly===!0)throw new Error(`Cannot update readonly variable: ${n.variableId}`);if(Gn(r,n.variableId),_t(o,"set",n.variableId),J(e)&&r!=="context")throw new Error(`Cannot update ${r}-scoped variable "${n.variableId}" while a scene replay is active`);return{variableConfig:t,scope:r}},hg=(e,n)=>({id:e.id,key:e.key,valid:!0,values:k(n),fields:k(e.fields),fieldList:k(e.fieldList)}),yg=e=>{if(e.global.isLineCompleted)return;e.global.isLineCompleted=!0,delete e.global.pendingScreenTransition;let n=Ce({state:e})?.pointer,t=n?.sectionId,r=n?.lineId;t&&r&&gn(e,{sectionId:t,lineId:r})},bg=({state:e},n={})=>{let t=Mo(e,n),r=n.field;if(!t?.fields?.[r])return e;let o=Sa(e,t.key),i=Bt(n.value),s=t.fields[r],l=Io(s,i);return o.values[r]=i,o.touched[r]=!0,l?o.errors[r]=l:delete o.errors[r],e.global.pendingEffects.push({name:"render"}),e},Ig=({state:e},n={})=>{let t=Mo(e,n);if(!t)return{submitted:!1,valid:!1,reason:"inactive"};let r=Sa(e,t.key);r.submitted=!0;let o={},i={};if(Object.entries(t.fields).forEach(([d,f])=>{let p=Object.prototype.hasOwnProperty.call(r.values,d)?r.values[d]:f.value,g=Io(f,p);r.touched[d]=!0,g&&(i[d]=g),o[d]=va(f,p)}),r.errors=i,Object.keys(i).length>0)return e.global.pendingEffects.push({name:"render"}),{submitted:!0,valid:!1,errors:k(i),form:{id:t.id,key:t.key,values:k(o)}};let s=e.contexts[e.contexts.length-1];if(s?.rollback?.isRestoring)return{submitted:!1,valid:!1,reason:"restoring"};let l=!1,a=[],c=[];Object.entries(t.fields).forEach(([d,f])=>{let{scope:p}=gg(e,f),g=p==="context"?s.variables:e.global.variables,h=o[d];g[f.variableId]=kt(g[f.variableId],"set",h),p==="context"&&(l=!0,c.push({variableId:f.variableId,op:"set",value:h})),(p==="device"||p==="account")&&a.push({scope:p,path:`variables.${f.variableId}`,op:"set",value:k(g[f.variableId])})}),l&&Le(e,"updateVariable",{id:"submitForm",operations:c}),No(e,a);let u=hg(t,o);return yg(e),delete e.global.formDrafts[t.key],e.global.pendingEffects.push({name:"render"}),{submitted:!0,valid:!0,form:u}},wg=({state:e},n={})=>{let t=Mo(e,n);return t?(delete e.global.formDrafts?.[t.key],e.global.pendingEffects.push({name:"render"}),{cancelled:!0,form:{id:t.id,key:t.key,values:k(t.values),fields:k(t.fields),fieldList:k(t.fieldList)}}):{cancelled:!1,reason:"inactive"}},Ag=({state:e},n)=>{let{id:t,operations:r=[]}=n;if(!t)throw new Error("updateVariable requires an id field");if(typeof t!="string"||!/^[a-zA-Z0-9]+$/.test(t))throw new Error(`updateVariable id must be alphanumeric, got: "${t}"`);let o=e.contexts[e.contexts.length-1];if(o?.rollback?.isRestoring)return e;let i=!1,s=[],l=[];return r.forEach(({variableId:a,op:c,value:u,roundTo:d})=>{let f=e.projectData.resources?.variables?.[a],p=f?.scope,g=f?.type;if(Se(f))throw new Error(`Cannot update computed variable: ${a}`);if(f?.readonly===!0)throw new Error(`Cannot update readonly variable: ${a}`);if(Gn(p,a),_t(g,c,a),Or(g,c,u,a,{roundTo:d}),J(e)&&p!=="context")throw new Error(`Cannot update ${p}-scoped variable "${a}" while a scene replay is active`);let h=p==="context"?o.variables:e.global.variables;if(p==="context"){i=!0;let b={variableId:a,op:c,value:u};d!==void 0&&(b.roundTo=d),l.push(b)}h[a]=kt(h[a],c,u,{roundTo:d}),(p==="device"||p==="account")&&s.push({scope:p,path:`variables.${a}`,op:"set",value:k(h[a])})}),i&&Le(e,"updateVariable",{id:t,operations:l}),No(e,s),e.global.pendingEffects.push({name:"render"}),e},ca=e=>(n,t)=>e({state:n},t),Eg=e=>({variables:Bn({variables:{...e.global?.variables??{},...rt(e)?.variables??{}},runtime:un(e),variableConfigs:e.projectData.resources?.variables??{},eager:!1}),runtime:un(e)}),xg=e=>{if(!N(e))throw new Error("conditional action payload must be an object");if(!Array.isArray(e.branches))throw new Error("conditional action requires branches array");if(e.branches.length===0)throw new Error("conditional action requires at least one branch")},vg=(e,n,t)=>{if(!N(e))throw new Error(`conditional branch at index ${n} must be an object`);if(!N(e.actions))throw new Error(`conditional branch at index ${n} requires actions object`);if(!Object.prototype.hasOwnProperty.call(e,"when")&&n!==t-1)throw new Error("conditional else branch must be the last branch")},Sg=(e,n)=>{xg(n);for(let t=0;t<n.branches.length;t+=1){let r=n.branches[t];if(vg(r,t,n.branches.length),!(Object.prototype.hasOwnProperty.call(r,"when")&&!Vn(r.when,Eg(e)))){Object.entries(r.actions).forEach(([i,s])=>{lc(e,i,s)});return}}},Rg={conditional:{replayLine:Sg},updateVariable:{recordSources:[wo],replayLine:sa,replayRecorded:sa,persistInSaveSlot:!0},setNextLineConfig:{replayLine:ca(cc)},finishSceneReplay:{replayLine:ca(oc)}},Qt=e=>Rg[e]??null,Cg=e=>Qt(e)?.persistInSaveSlot===!0,_g=(e,n)=>{let t=Qt(e)?.recordSources;return Array.isArray(t)&&t.includes(n)},kg=(e,n,t)=>{Qt(n)?.replayRecorded?.(e,t)},lc=(e,n,t)=>{Qt(n)?.replayLine?.(e,t)},Og=e=>e?.returnable!==!1,uc=(e,n)=>{if(n>=0)return e.currentIndex+n;let t=Math.abs(n);for(let r=e.currentIndex-1;r>=0;r-=1)if(Og(e.timeline[r])&&(t-=1,t===0))return r;return-1},dc=({state:e},n)=>{let{offset:t}=n;if(t===void 0||typeof t!="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.rollback;if(!Array.isArray(o?.timeline)||typeof o?.currentIndex!="number")return null;let i=uc(o,t);if(i<0||i>=o.timeline.length)return null;let s=o.timeline[i];return{sectionId:s.sectionId,lineId:s.lineId}},fc=({state:e})=>dc({state:e},{offset:-1})!==null,$g=({state:e},n)=>{let{offset:t=-1}=n;if(t>=0)throw new Error("rollbackByOffset requires a negative offset");let r=e.contexts?.[e.contexts.length-1];if(!r)return e;let o=yn(r,{compatibilityAnchor:!r.rollback}),i=uc(o,t);return i<0||i>=o.timeline.length?e:Ta(e,i)},Tg=({state:e},n)=>{let{sectionId:t,lineId:r}=n,o=e.contexts[e.contexts.length-1];if(!o)throw new Error("No context available for rollbackToLine");let i=yn(o,{compatibilityAnchor:!o.rollback}),l=i.timeline.slice(0,i.currentIndex+1).findLastIndex(a=>a.sectionId===t&&a.lineId===r);if(l===-1)throw new Error(`Line ${r} not found in section ${t} rollback timeline`);return l===i.currentIndex?e:Ta(e,l)},pc=e=>{let n=_p(e);return Ti(n,{selectPendingEffects:Op,selectSkipMode:La,selectAutoMode:$p,selectIsChoiceVisible:Ua,selectIsFormVisible:Lp,selectActiveInteraction:Ae,selectActiveForm:ot,selectDialogueUIHidden:Pa,selectDialogueHistory:Na,selectConfirmDialog:Tp,selectIsLineAccountViewed:So,selectIsResourceAccountViewed:Np,selectImageGalleryConfig:Dp,selectImageGallery:Da,selectMusicRoomConfig:Vp,selectMusicRoom:Va,selectSceneReplayConfig:jp,selectSceneReplay:ja,selectIsSceneReplayActive:Fp,selectActiveSceneReplayEntry:Up,selectNextLineConfig:Bp,selectSystemState:Gp,selectAchievements:zp,selectAchievement:qp,selectSaveSlotMap:Ba,selectSaveSlots:Qp,selectSaveSlot:Yp,selectRuntime:Lo,selectRuntimeValue:Hp,selectAllVariables:Yt,selectCurrentPointer:Ce,selectSection:de,selectCurrentLine:Ht,selectPresentationState:Ga,selectAutoForwardTimerDelay:it,selectPresentationChanges:Kp,selectSectionLineChanges:Xp,selectSaveSlotPage:Po,selectCurrentPageSlots:Zp,selectRenderState:nm,selectOverlayStack:kp,selectLineIdByOffset:dc,selectCanRollback:fc,selectRollbackCursor:wp,startAutoMode:qa,stopAutoMode:at,toggleAutoMode:lm,startSkipMode:Ya,stopSkipMode:Je,toggleSkipMode:um,showDialogueUI:Kt,hideDialogueUI:Ha,toggleDialogueUI:dm,setDialogueTextSpeed:fm,setAutoForwardDelay:pm,setAutoForwardSpeed:mm,setSkipUnseenText:gm,setSkipTransitionsAndAnimations:hm,setSoundVolume:ym,setMusicVolume:bm,setMuteAll:Im,setSaveLoadPagination:wm,incrementSaveLoadPagination:Am,decrementSaveLoadPagination:Em,setMenuPage:xm,setMenuEntryPoint:vm,showConfirmDialog:tm,hideConfirmDialog:rm,resetStoryAtSection:km,clearPendingEffects:Sm,appendPendingEffect:Rm,completeAchievement:Cm,setAchievementProgress:_m,beginRollbackActionBatch:vp,endRollbackActionBatch:Sp,markRollbackCheckpointTransient:Ap,markSavedRollbackCheckpointTransient:Ep,addViewedLine:$m,addViewedResource:Tm,showImageGalleryVariant:Lm,moveToPreviousImageGalleryVariant:Pm,moveToNextImageGalleryVariant:Nm,clearImageGallerySelection:Dm,moveToImageGalleryPage:Mm,moveToNextImageGalleryPage:Vm,moveToPreviousImageGalleryPage:jm,playMusicRoomTrack:Um,playMusicRoom:Bm,pauseMusicRoom:Gm,stopMusicRoom:zm,seekMusicRoom:qm,playPreviousMusicRoomTrack:Ym,playNextMusicRoomTrack:Hm,clearMusicRoomSelection:Wm,moveToMusicRoomPage:Km,moveToNextMusicRoomPage:Jm,moveToPreviousMusicRoomPage:Xm,musicRoomSoundReady:rg,musicRoomSoundProgress:og,musicRoomSoundComplete:ig,musicRoomSoundError:sg,startSceneReplay:Qm,finishSceneReplay:oc,exitSceneReplay:Zm,moveToSceneReplayPage:eg,moveToNextSceneReplayPage:ng,moveToPreviousSceneReplayPage:tg,setNextLineConfig:cc,saveSlot:ag,loadSlot:cg,updateProjectData:lg,sectionTransition:pg,jumpToLine:ug,nextLine:dg,markLineCompleted:fg,rollbackToLine:Tg,rollbackByOffset:$g,pushOverlay:om,popOverlay:im,replaceLastOverlay:sm,clearOverlays:am,updateFormField:bg,submitForm:Ig,cancelForm:wg,updateVariable:Ag,nextLineFromSystem:mg},{transformActionFirstArgument:r=>({state:r}),transformSelectorFirstArgument:r=>({state:r})})};var Lg="route-engine",Pg="projectPersistence";var gc=()=>({saveSlots:{},globalDeviceVariables:{},globalAccountVariables:{},globalRuntime:{},accountViewedRegistry:{}}),se=e=>Object.prototype.toString.call(e)==="[object Object]",mc="variables.",Ng=(e={})=>{let n=se(e)?e:{};return{sections:(Array.isArray(n.sections)?n.sections:[]).map(t=>typeof t=="string"||typeof t=="number"?{sectionId:String(t)}:!se(t)||typeof t.sectionId!="string"||t.sectionId.length===0?null:{sectionId:t.sectionId,...typeof t.lineId=="string"?{lineId:t.lineId}:{}}).filter(Boolean),resources:(Array.isArray(n.resources)?n.resources:[]).map(t=>typeof t=="string"||typeof t=="number"?{resourceId:String(t)}:!se(t)||typeof t.resourceId!="string"||t.resourceId.length===0?null:{resourceId:t.resourceId}).filter(Boolean)}},Dg=(e={})=>{let n=se(e)?e:{};return{sections:(Array.isArray(n.sections)?n.sections:[]).map(t=>typeof t=="string"||typeof t=="number"?{sectionId:String(t)}:!se(t)||typeof t.sectionId!="string"||t.sectionId.length===0?null:{sectionId:t.sectionId,...typeof t.lastLineId=="string"?{lastLineId:t.lastLineId}:{}}).filter(Boolean),resources:(Array.isArray(n.resources)?n.resources:[]).map(t=>typeof t=="string"||typeof t=="number"?{resourceId:String(t)}:!se(t)||typeof t.resourceId!="string"||t.resourceId.length===0?null:{resourceId:t.resourceId}).filter(Boolean)}},Mg=(e,n)=>{let t=Dg(e),r=Ng(n),o=t.sections.map(s=>({...s})),i=t.resources.map(s=>({...s}));return r.sections.forEach(s=>{let l=o.find(a=>a.sectionId===s.sectionId);if(!l){o.push({sectionId:s.sectionId,...s.lineId===void 0?{}:{lastLineId:s.lineId}});return}if(l.lastLineId!==void 0){if(s.lineId===void 0){delete l.lastLineId;return}l.lastLineId=s.lineId}}),r.resources.forEach(s=>{i.find(a=>a.resourceId===s.resourceId)||i.push({...s})}),{sections:o,resources:i}},hc=(e={})=>{let n=se(e)?e:{};return{saveSlots:se(n.saveSlots)?n.saveSlots:{},globalDeviceVariables:se(n.globalDeviceVariables)?n.globalDeviceVariables:{},globalAccountVariables:se(n.globalAccountVariables)?n.globalAccountVariables:{},globalRuntime:se(n.globalRuntime)?n.globalRuntime:{},accountViewedRegistry:se(n.accountViewedRegistry)?n.accountViewedRegistry:{}}},Vg=(e=[])=>{if(e===void 0)return[];if(!Array.isArray(e))throw new Error("applyScopedDataUpdates requires an updates array.");return e.map((n,t)=>{if(!se(n))throw new Error(`Malformed applyScopedDataUpdates.updates[${t}] entry.`);let r=n.path?.startsWith(mc)?n.path.slice(mc.length):null;if(r!==null){if(!["device","account"].includes(n.scope))throw new Error(`Unsupported applyScopedDataUpdates scope "${n.scope}" at updates[${t}].`);if(r.length===0)throw new Error(`Malformed applyScopedDataUpdates path "${n.path}" at updates[${t}].`);if(n.op!=="set")throw new Error(`Unsupported applyScopedDataUpdates operation "${n.op}" at updates[${t}].`);return{scope:n.scope,path:n.path,op:n.op,value:n.value,variableId:r}}if(n.path==="viewedRegistry"){if(n.scope!=="account")throw new Error(`Unsupported applyScopedDataUpdates scope "${n.scope}" at updates[${t}].`);if(n.op!=="markViewed")throw new Error(`Unsupported applyScopedDataUpdates operation "${n.op}" at updates[${t}].`);return n}throw typeof n.path!="string"?new Error(`Malformed applyScopedDataUpdates path at updates[${t}].`):new Error(`Unsupported applyScopedDataUpdates path "${n.path}" at updates[${t}].`)})},jg=(e,n)=>{let t={};return Vg(n).forEach(r=>{if(r.path==="viewedRegistry"){t.accountViewedRegistry=Mg(t.accountViewedRegistry??e.accountViewedRegistry,r.value);return}let o=r.scope==="device"?"globalDeviceVariables":"globalAccountVariables";t[o]={...e[o],...t[o],[r.variableId]:r.value}}),t},Vo=e=>{if(typeof e!="string")return null;let n=e.trim();return n.length>0?n:null},Fg=e=>{let n=Vo(e);if(!n)throw new Error("createIndexedDbPersistence requires a non-empty namespace.");return n},Ug=e=>{let n=e??globalThis.indexedDB;if(!n)throw new Error("IndexedDB is not available in this environment.");return n},Bg=({indexedDB:e,databaseName:n,objectStoreName:t})=>new Promise((r,o)=>{let i=e.open(n,1);i.onupgradeneeded=()=>{let s=i.result;s.objectStoreNames.contains(t)||s.createObjectStore(t,{keyPath:"namespace"})},i.onsuccess=()=>{r(i.result)},i.onerror=()=>{o(i.error??new Error(`Failed to open IndexedDB database "${n}".`))}}),Gg=async({databasePromise:e,objectStoreName:n,namespace:t})=>{let r=await e;return new Promise((o,i)=>{let a=r.transaction(n,"readonly").objectStore(n).get(t);a.onsuccess=()=>{o(a.result??null)},a.onerror=()=>{i(a.error??new Error(`Failed to read persisted namespace "${t}" from IndexedDB.`))}})},lt=async({databasePromise:e,objectStoreName:n,namespace:t,patch:r})=>{let o=await e;return new Promise((i,s)=>{let l=o.transaction(n,"readwrite"),a=l.objectStore(n),c=a.get(t),u=!1,d=p=>{u||(u=!0,s(p))},f=()=>{u||(u=!0,i())};c.onerror=()=>{d(c.error??new Error(`Failed to read persisted namespace "${t}" before updating IndexedDB.`))},c.onsuccess=()=>{let p=hc(c.result),g=typeof r=="function"?r(p):r,h={namespace:t,version:1,...gc(),...p,...g},b=a.put(h);b.onerror=()=>{d(b.error??new Error(`Failed to persist namespace "${t}" to IndexedDB.`))}},l.oncomplete=()=>{f()},l.onerror=()=>{d(l.error??new Error(`IndexedDB transaction failed while updating namespace "${t}".`))},l.onabort=()=>{d(l.error??new Error(`IndexedDB transaction aborted while updating namespace "${t}".`))}})},zg=async({databasePromise:e,objectStoreName:n,namespace:t})=>{let r=await e;return new Promise((o,i)=>{let s=r.transaction(n,"readwrite"),a=s.objectStore(n).delete(t),c=!1,u=f=>{c||(c=!0,i(f))},d=()=>{c||(c=!0,o())};a.onerror=()=>{u(a.error??new Error(`Failed to clear persisted namespace "${t}" from IndexedDB.`))},s.oncomplete=()=>{d()},s.onerror=()=>{u(s.error??new Error(`IndexedDB transaction failed while clearing namespace "${t}".`))},s.onabort=()=>{u(s.error??new Error(`IndexedDB transaction aborted while clearing namespace "${t}".`))}})},jo=(e={})=>{let{indexedDB:n,databaseName:t=Lg,objectStoreName:r=Pg,namespace:o}=e,i=Ug(n),s=Fg(o),l=Bg({indexedDB:i,databaseName:t,objectStoreName:r});return{namespace:s,load:async()=>{let a=await Gg({databasePromise:l,objectStoreName:r,namespace:s});return{...gc(),...hc(a)}},clear:async()=>zg({databasePromise:l,objectStoreName:r,namespace:s}),saveSlots:async a=>lt({databasePromise:l,objectStoreName:r,namespace:s,patch:{saveSlots:se(a)?a:{}}}),saveGlobalDeviceVariables:async a=>lt({databasePromise:l,objectStoreName:r,namespace:s,patch:{globalDeviceVariables:se(a)?a:{}}}),saveGlobalAccountVariables:async a=>lt({databasePromise:l,objectStoreName:r,namespace:s,patch:{globalAccountVariables:se(a)?a:{}}}),saveGlobalRuntime:async a=>lt({databasePromise:l,objectStoreName:r,namespace:s,patch:{globalRuntime:se(a)?a:{}}}),applyScopedDataUpdates:async a=>lt({databasePromise:l,objectStoreName:r,namespace:s,patch:c=>jg(c,a)})}},qg=jo;var Yg=new Set(["loadSlot","resetStoryAtSection","rollbackByOffset","rollbackToLine","updateProjectData"]),Hg=new Set(["loadSlot","rollbackByOffset","rollbackToLine"]),yc="conditional",Bo=Symbol("conditionalAutoContinue"),Wg=new Set(["sectionTransition","resetStoryAtSection"]),Kg=new Set(["nextLine","nextLineFromSystem","resetStoryAtSection","sectionTransition"]),Jg=new Set(["loadSlot","rollbackByOffset","rollbackToLine"]),Fo="form",Xg=new Set(["submitForm","cancelForm"]),Qg="showImageGalleryVariant",Zg="playMusicRoomTrack",eh="startSceneReplay",Qe=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Zt=e=>e?.type===Bo,Uo=(e,n)=>e?.sectionId===n?.sectionId&&e?.lineId===n?.lineId;function Go(e){let n,t=0,r=null,o=0,i=!1,s=0,l=[],a=null,c=new Map,u=new Map,d=new Map,{handlePendingEffects:f}=e,p=(m=new Map,w=Date.now())=>new Map(Array.from(m.entries()).filter(([,v])=>w<v.expiresAt).map(([v,_])=>[v,{animation:structuredClone(_.animation),startedAt:_.startedAt,expiresAt:_.expiresAt}])),g=(m=new Map)=>Array.from(m.values()).map(w=>structuredClone(w.animation)),h=(m=Date.now())=>{c=new Map(Array.from(c.entries()).filter(([,w])=>m<w.expiresAt))},b=()=>{if(!(o>0||i)){i=!0;try{for(;n.selectPendingEffects().length>0;){let m=[...n.selectPendingEffects()];n.clearPendingEffects();try{f(m)}catch(w){throw n.clearPendingEffects(),m.forEach(v=>{n.appendPendingEffect(v)}),w}}}finally{i=!1}}},I=m=>{o+=1;let w=!1;try{let v=m();return w=!0,v}finally{o-=1,w&&b()}},E=({initialState:m,namespace:w})=>{n=pc(m),t=0,r=Vo(w),o=0,i=!1,s=0,l=[],a=null,c=new Map,u=new Map,d=new Map,n.appendPendingEffect({name:"handleLineActions"}),b()},A=()=>r,$=()=>n.selectPresentationState(),B=()=>n.selectPresentationChanges(),L=m=>n.selectSectionLineChanges(m),T=(m={})=>{t+=1;let w=Date.now();h(w);let v=u.size>0,_=p(c,w),D=v?p(u,w):new Map,X={...n.selectRenderState({activePersistentAnimations:g(_),restoredPersistentAnimations:g(D)}),id:`render-${t}`};return d.set(X.id,{builtAt:w,persistentAnimationSessions:new Map([...D.entries(),..._.entries()]),usedRestoredPersistentAnimationSessions:v}),X},z=(m={})=>T(m),G=(m={})=>T(m),S=m=>{let w=typeof m?.id=="string"&&m.id.length>0?m.id:null,v=w?d.get(w):null;w&&d.delete(w);let _=new Map;ys(m?.animations).forEach(D=>{let F=Lt(D);if(!F)return;let X=v?.persistentAnimationSessions?.get(F)??c.get(F),Z=Math.max(0,ws(D)),Ze=X?.startedAt??v?.builtAt??Date.now();_.set(F,{animation:structuredClone(D),startedAt:Ze,expiresAt:Ze+Z})}),c=_,v?.usedRestoredPersistentAnimationSessions&&(u=new Map)},q=()=>n.selectSystemState(),W=()=>n.selectAchievements(),me=m=>n.selectAchievement(m),Y=()=>n.selectSaveSlotMap(),ae=m=>n.selectSaveSlot(m),oe=m=>n.selectSaveSlotPage(m),ge=()=>n.selectImageGallery(),$e=()=>n.selectMusicRoom(),ce=()=>n.selectSceneReplay(),te=()=>n.selectIsSceneReplayActive(),fe=()=>n.selectSkipMode(),le=()=>n.selectAutoMode(),x=()=>n.selectRuntime(),C=()=>n.selectIsChoiceVisible(),O=()=>n.selectIsFormVisible(),Q=()=>n.selectActiveInteraction(),Ie=()=>n.selectPendingEffects().some(m=>m?.name==="handleLineActions"||m?.name==="render"),H=(m,w,v={})=>!Qe(w)||m!=="nextLine"?w:v.bypassChoice===!0?{...w,bypassChoice:!0}:v.interactionSource===Fo?{...w,_interactionSource:Fo}:w,Te=(m={})=>({type:Bo,payload:H("nextLine",{_conditionalContinuation:!0},m)}),he=(m,w)=>Zt(m)?{type:Bo,payload:{...m.payload,...w.payload}}:w,Ec=m=>{m.savedCheckpointOccurrences.forEach(w=>{n.markSavedRollbackCheckpointTransient(w)}),m.savedCheckpointOccurrences=[]},xc=(m,w)=>{let v=a;return a=null,!v||!Uo(v.pointer,m)||v.checkpointIndex!==w?.checkpointIndex||v.checkpointIdentity!==w?.checkpoint?[]:v.savedCheckpointOccurrences},qo=m=>{m.markCurrentCheckpointTransient&&(n.markRollbackCheckpointTransient({checkpointIndex:m.rollbackCursor?.checkpointIndex,checkpointIdentity:m.rollbackCursor?.checkpoint,sectionId:m.pointer?.sectionId,lineId:m.pointer?.lineId}),Ec(m))},vc=(m,w,v)=>Kg.has(m)?m==="resetStoryAtSection"?v?.checkpoint!==w?.checkpoint:v?.checkpoint!==w?.checkpoint&&v?.checkpointIndex>w?.checkpointIndex:!1,Sc=m=>{let w=l.at(-1);if(!w?.markCurrentCheckpointTransient)return;let v=n.selectSaveSlot({slotId:m?.slotId});v&&w.savedCheckpointOccurrences.push({slotId:m.slotId,saveSlotIdentity:v,checkpointIndex:w.rollbackCursor?.checkpointIndex,sectionId:w.pointer?.sectionId,lineId:w.pointer?.lineId})},Rc=(m,w,v)=>{let _=l.at(-1);if(!_)return;let D=n.selectCurrentPointer()?.pointer,F=vc(m,w,v);if(Uo(_.pointer,D)){let X=v?.checkpoint!==w?.checkpoint||v?.checkpointIndex!==w?.checkpointIndex;(F||X&&Jg.has(m))&&(qo(_),_.pointer=D,_.rollbackCursor=v,_.markCurrentCheckpointTransient=F,_.savedCheckpointOccurrences=[]);return}qo(_),_.pointer=D,_.rollbackCursor=n.selectRollbackCursor?.()??null,_.markCurrentCheckpointTransient=F,_.savedCheckpointOccurrences=[]},dt=(m,w)=>{if(!n[m])return;m==="updateProjectData"&&Cc(w),Wg.has(m)&&(s+=1);let v=n.selectIsSceneReplayActive?.()===!0,_=Hg.has(m)?p(c):null,D=n.selectRollbackCursor?.()??null,F=n[m](w);Yg.has(m)&&(u=_??new Map,c=new Map);let X=n.selectIsSceneReplayActive?.()===!0;v!==X&&(c=new Map,u=new Map);let Z=n.selectRollbackCursor?.()??null;return m==="saveSlot"&&Sc(w),Rc(m,D,Z),b(),F},Cc=m=>{if(!Object.prototype.hasOwnProperty.call(m??{},"projectData"))throw new Error("updateProjectData requires projectData");an(m?.projectData?.resources?.variables??{}),jn(m.projectData),Fn(m.projectData),Un(m.projectData)},_c=(m,w,v)=>{let _=n.selectCurrentPointer()?.pointer;w!==_||v!==s||(n.appendPendingEffect({name:"clearAutoNextTimer"}),n.appendPendingEffect({name:"clearNextLineConfigTimer"}),dt("nextLineFromSystem",m.payload))},kc=()=>({renderSequence:t,conditionalRoutingSequence:s,rollbackNavigationContexts:l.slice(),pendingRollbackLineEntrySaveHandoff:a,persistentAnimationSessions:new Map(c),restoredPersistentAnimationSessions:new Map(u),renderPersistentAnimationMetadata:new Map(d)}),Oc=m=>{t=m.renderSequence,s=m.conditionalRoutingSequence,l=m.rollbackNavigationContexts.slice(),a=m.pendingRollbackLineEntrySaveHandoff,c=new Map(m.persistentAnimationSessions),u=new Map(m.restoredPersistentAnimationSessions),d=new Map(m.renderPersistentAnimationMetadata)},Yo=(m,w={})=>I(()=>{let v=kc();try{return n[kr](()=>{let _,D=n.selectCurrentPointer()?.pointer??null,F=n.selectRollbackCursor?.()??null,X=s,Z={pointer:D,rollbackCursor:F,markCurrentCheckpointTransient:w.rollbackSource==="line",savedCheckpointOccurrences:w.savedCheckpointOccurrences?.slice()??[]};l.push(Z);try{n.beginRollbackActionBatch({source:w.rollbackSource});try{_=m()}finally{n.endRollbackActionBatch({})}Zt(_)&&_c(_,D,X)}finally{l.pop(),(!Uo(D,Z.pointer)||F?.checkpoint!==Z.rollbackCursor?.checkpoint)&&Z.markCurrentCheckpointTransient&&Z.savedCheckpointOccurrences.length>0&&(a={pointer:Z.pointer,checkpointIndex:Z.rollbackCursor?.checkpointIndex,checkpointIdentity:Z.rollbackCursor?.checkpoint,savedCheckpointOccurrences:Z.savedCheckpointOccurrences})}})}catch(_){throw Oc(v),_}}),Ho=(m,w,v,_={})=>{if(m===yc)return Yo(()=>{let D=er(v),F=Pr({[m]:w},D);return Wo(F[m],v,_)},_);dt(m,w)},$c=(m,w)=>{Ho(m,w)},er=m=>{if(!m)return{variables:n.selectAllVariables?n.selectAllVariables():void 0,runtime:n.selectRuntime?n.selectRuntime():{}};if(Object.prototype.hasOwnProperty.call(m,"event"))throw new Error('eventContext key "event" is no longer supported. Use "_event".');let{_event:w,...v}=m,_=n.selectAllVariables?n.selectAllVariables():void 0;return{...v,_event:w,variables:_,runtime:n.selectRuntime?n.selectRuntime():{}}},Tc=m=>{if(!Qe(m))return{templatePayload:m,literalTargetIds:null};let w=n.selectImageGalleryConfig();if(!Array.isArray(w?.groups))return{templatePayload:m,literalTargetIds:null};let v=typeof m.groupId=="string"?w.groups.find(D=>D.id===m.groupId):void 0;if(!v)return{templatePayload:m,literalTargetIds:null};let _=typeof m.variantId=="string"&&v.variants.some(D=>D.id===m.variantId);return{templatePayload:{...m,groupId:null,..._?{variantId:null}:{}},literalTargetIds:{groupId:m.groupId,..._?{variantId:m.variantId}:{}}}},Lc=m=>!Qe(m)||typeof m.trackId!="string"?{templatePayload:m,literalTargetIds:null}:n.selectMusicRoomConfig()?.tracks?.some(_=>_.id===m.trackId)?{templatePayload:{...m,trackId:null},literalTargetIds:{trackId:m.trackId}}:{templatePayload:m,literalTargetIds:null},Pc=m=>!Qe(m)||typeof m.replayId!="string"?{templatePayload:m,literalTargetIds:null}:n.selectSceneReplayConfig()?.replays?.some(_=>_.id===m.replayId)?{templatePayload:{...m,replayId:null},literalTargetIds:{replayId:m.replayId}}:{templatePayload:m,literalTargetIds:null},Nc=m=>{if(!Qe(m))throw new Error("conditional action payload must be an object");if(!Array.isArray(m.branches))throw new Error("conditional action requires branches array");if(m.branches.length===0)throw new Error("conditional action requires at least one branch")},Dc=(m,w,v)=>{if(!Qe(m))throw new Error(`conditional branch at index ${w} must be an object`);if(!Qe(m.actions))throw new Error(`conditional branch at index ${w} requires actions object`);if(!Object.prototype.hasOwnProperty.call(m,"when")&&w!==v-1)throw new Error("conditional else branch must be the last branch")},Wo=(m,w,v)=>{Nc(m);let _=Te(v);for(let D=0;D<m.branches.length;D+=1){let F=m.branches[D];Dc(F,D,m.branches.length);let X=er(w);if(Object.prototype.hasOwnProperty.call(F,"when")&&!Vn(F.when,X))continue;let Ze=nr(F.actions,w,v);return Zt(Ze)?he(_,Ze):_}return _},Mc=(m,w)=>({...m??{},_form:w}),Vc=(m,w,v,_)=>{let D=dt(m,w),F=D?.submitted===!0&&D.valid===!0,X=D?.cancelled===!0;if(!(!F&&!X)&&Qe(w.actions))return nr(w.actions,Mc(v,D.form),{..._,interactionSource:Fo})},jc=(m,w,v,_)=>{let D=er(v),F={templatePayload:w,literalTargetIds:null};m===Qg?F=Tc(w):m===Zg?F=Lc(w):m===eh&&(F=Pc(w));let{templatePayload:X,literalTargetIds:Z}=F,Jo=Pr({[m]:X},D)[m],Xo=Z?{...Jo,...Z}:Jo;if(m===yc)return Wo(Xo,v,_);let Qo=H(m,Xo,_);if(Xg.has(m))return Vc(m,Qo,v,_);dt(m,Qo)},nr=(m,w,v)=>{let _;return Object.entries(m).forEach(([D,F])=>{let X=jc(D,F,w,v);Zt(X)&&(_=he(_,X))}),_},Ko=(m,w,v={})=>Yo(()=>nr(m,w,v),v),Fc=m=>{let w=n.selectCurrentPointer()?.pointer;if(m!==w||n.selectActiveInteraction())return;let v=n.selectNextLineConfig();v?.auto?.enabled&&v.auto.trigger==="fromStart"&&n.appendPendingEffect({name:"nextLineConfigTimer",payload:{delay:v.auto.delay}})};return{init:E,handleAction:Ho,handleInternalAction:$c,handleActions:Ko,selectRenderState:z,prepareRenderState:G,commitRenderState:S,selectPresentationState:$,selectPresentationChanges:B,selectSectionLineChanges:L,selectSystemState:q,selectAchievements:W,selectAchievement:me,selectSaveSlotMap:Y,selectSaveSlot:ae,selectSaveSlotPage:oe,selectSaveSlots:Y,selectImageGallery:ge,selectMusicRoom:$e,selectSceneReplay:ce,selectIsSceneReplayActive:te,selectRuntime:x,selectIsChoiceVisible:C,selectIsFormVisible:O,selectActiveInteraction:Q,selectHasPendingRenderWork:Ie,handleLineActions:m=>{if(typeof m?.sceneReplayId=="string"){let w=n.selectActiveSceneReplayEntry?.();if(w?.replayId!==m.sceneReplayId||w?.entryId!==m.entryId)return!1}return I(()=>{let w=n.selectCurrentPointer()?.pointer,v=n.selectRollbackCursor?.()??null,_=a,D=xc(w,v),F=n.selectCurrentLine(),X=!1;if(F?.actions){try{Ko(F.actions,void 0,{rollbackSource:"line",savedCheckpointOccurrences:D})}catch(Z){throw a=_,Z}X=!0}return Fc(w),X})},getNamespace:A}}var zo=()=>{let e=0,n=null;return{getElapsed:()=>e,setElapsed:t=>{e=t},addElapsed:t=>{e+=t},getCallback:()=>n,setCallback:t=>{n=t}}},nh=80,th="music-room:player",wc=new Map([["soundReady","musicRoomSoundReady"],["soundProgress","musicRoomSoundProgress"],["soundComplete","musicRoomSoundComplete"],["soundError","musicRoomSoundError"]]),bc=(e,n)=>wc.has(e)&&n?._event?.id===th,Ac=({engine:e,routeGraphics:n,trackRenderDispatch:t},r)=>{if(e.selectHasPendingRenderWork?.())return;let o=e.prepareRenderState?.(r)??e.selectRenderState(r);t?.(o),n.render(o),e.commitRenderState?.(o)},rh=({engine:e,routeGraphics:n,trackRenderDispatch:t,getRenderDispatchCount:r},o)=>{let i=r?.()??0,s=e.handleLineActions(o);(r?.()??0)===i&&Ac({engine:e,routeGraphics:n,trackRenderDispatch:t},o)},oh=({engine:e,ticker:n,autoTimer:t},r)=>{let o=t.getCallback();o&&n.remove(o),t.setElapsed(0);let i=s=>{t.addElapsed(s.deltaMS);let l=r.delay??1e3;t.getElapsed()>=l&&(n.remove(i),t.setCallback(null),t.setElapsed(0),ut(e,"nextLineFromSystem",{}))};t.setCallback(i),n.add(i)},ih=({ticker:e,autoTimer:n},t)=>{let r=n.getCallback();r&&(e.remove(r),n.setCallback(null)),n.setElapsed(0)},sh=({engine:e,ticker:n,skipTimer:t},r)=>{let o=t.getCallback();o&&n.remove(o),t.setElapsed(0);let i=s=>{t.addElapsed(s.deltaMS);let l=r?.delay??nh;t.getElapsed()>=l&&(t.setElapsed(0),ut(e,"nextLineFromSystem",{}))};t.setCallback(i),n.add(i)},ah=({ticker:e,skipTimer:n},t)=>{let r=n.getCallback();r&&(e.remove(r),n.setCallback(null)),n.setElapsed(0)},ch=({engine:e,ticker:n,nextLineConfigTimerState:t},r)=>{let o=t.getCallback();o&&n.remove(o),t.setElapsed(0);let i=s=>{t.addElapsed(s.deltaMS);let l=r.delay??1e3;t.getElapsed()>=l&&(t.setElapsed(0),ut(e,"nextLineFromSystem",{}),n.remove(i),t.getCallback()===i&&t.setCallback(null))};t.setCallback(i),n.add(i)},lh=({ticker:e,nextLineConfigTimerState:n},t)=>{let r=n.getCallback();r&&(e.remove(r),n.setCallback(null)),n.setElapsed(0)},uh=({enqueuePersistenceWrite:e},n)=>{e(t=>t.saveSlots(n?.saveSlots))},dh=({enqueuePersistenceWrite:e},n)=>{e(t=>t.saveGlobalDeviceVariables(n?.globalDeviceVariables))},fh=({enqueuePersistenceWrite:e},n)=>{e(t=>t.saveGlobalAccountVariables(n?.globalAccountVariables))},ph=({enqueuePersistenceWrite:e},n)=>{e(t=>t.saveGlobalRuntime(n?.globalRuntime))},mh=({enqueuePersistenceWrite:e},n)=>{e(t=>{if(typeof t.applyScopedDataUpdates!="function")throw new Error("RouteEngine persistence adapter must implement applyScopedDataUpdates.");return t.applyScopedDataUpdates(n?.updates)})},Ic={render:Ac,saveSlots:uh,saveGlobalDeviceVariables:dh,saveGlobalAccountVariables:fh,saveGlobalRuntime:ph,applyScopedDataUpdates:mh,handleLineActions:rh,startAutoNextTimer:oh,clearAutoNextTimer:ih,startSkipNextTimer:sh,clearSkipNextTimer:ah,nextLineConfigTimer:ch,clearNextLineConfigTimer:lh},gh=new Set(["render","handleLineActions","saveSlots","saveGlobalDeviceVariables","saveGlobalAccountVariables","saveGlobalRuntime","startAutoNextTimer","clearAutoNextTimer","startSkipNextTimer","clearSkipNextTimer","nextLineConfigTimer","clearNextLineConfigTimer"]),ut=(e,n,t)=>{(e.handleInternalAction??e.handleAction?.bind(e))?.(n,t)},hh=(e=[])=>{let n=new Set,t=[];for(let r=e.length-1;r>=0;r-=1){let o=e[r];if(typeof o?.name!="string"||o.name.length===0)throw new Error("Pending effect is missing a valid name.");if(!gh.has(o.name)){t.unshift(o);continue}n.has(o.name)||(n.add(o.name),t.unshift(o))}return t},yh=({getEngine:e,routeGraphics:n,ticker:t,handleUnhandledEffect:r,handlePersistenceError:o,indexedDB:i,persistence:s,namespace:l})=>{let a=zo(),c=zo(),u=zo(),d=s??null,f=Promise.resolve(),p=null,g=null,h=!1,b=0,I=x=>{if(o){o(x);return}console.error("RouteEngine persistence write failed.",x)},E=()=>{if(d)return d;let x=e();return d=jo({indexedDB:i,namespace:l??x?.getNamespace?.()}),d},A=x=>{f=f.catch(()=>{}).then(()=>{let C=E();return x(C)}).catch(C=>{I(C)})},$=x=>{let C=typeof x?.id=="string"&&x.id.length>0?x.id:null;b+=1,p=C,h=!1},B=()=>b,L=(x={})=>{if(x?.aborted===!0)return!1;let C=typeof x?.id=="string"&&x.id.length>0?x.id:null;return C?C!==p||C===g?!1:(g=C,!0):p!==null||h?!1:(h=!0,!0)},T=(x,C={})=>{if(bc(x,C)){let Q=wc.get(x),Ie=e();return ut(Ie,Q,C?._event),!0}if(x!=="renderComplete"||!L(C))return!1;let O=e();return ut(O,"markLineCompleted",{}),!0},z=new Set(["updateFormField","submitForm","cancelForm"]),G=new Set(["updateVariable"]),S=x=>typeof x?.selectActiveInteraction=="function"?x.selectActiveInteraction():typeof x?.selectIsChoiceVisible=="function"&&x.selectIsChoiceVisible()?{source:"choice"}:null,q=x=>x?._formKey??x?.formKey,W=(x,C)=>q(x)===C?.formKey,me=(x,C)=>!x||typeof x!="object"||Array.isArray(x)?!1:x._interactionSource===C?.source,Y=(x,C)=>me(x,C)?C.source==="form"?W(x,C):!0:!1,ae=(x,C)=>!x||typeof x!="object"||Array.isArray(x)||C?.source!=="form"?!1:W(x,C),oe=(x={})=>Object.keys(x).some(C=>z.has(C)),ge=(x={},C)=>Object.entries(x).some(([O,Q])=>z.has(O)&&ae(Q,C)),$e=(x={})=>Object.keys(x).length>0&&Object.keys(x).every(C=>G.has(C)),ce=(x={},C)=>{let O=x?.actions;return C?.source==="form"?!O||typeof O!="object"||Array.isArray(O)?!1:ge(O,C)?!0:oe(O)?!1:$e(O):Y(x,C)?!0:!O||typeof O!="object"||Array.isArray(O)?!1:Object.values(O).some(Q=>Y(Q,C))},te=(x,C={})=>{if(!C?.actions)return!1;let O=S(x);return!O||O.source==="choice"?!1:!ce(C,O)},fe=({preprocessPayload:x,onEvent:C}={})=>async(O,Q={})=>{if(bc(O,Q))return T(O,Q),C?.(O,Q);let Ie=e();if(te(Ie,Q))return C?.(O,Q);let H=await x?.(O,Q)??Q;if(te(Ie,H))return C?.(O,H);if(T(O,H),H?.actions){let Te=H?._event?{_event:H._event}:H?.event?{_event:H.event}:void 0,he;H?.bypassChoice===!0?he={bypassChoice:!0}:H?._interactionSource&&(he={interactionSource:H._interactionSource}),he?Ie.handleActions(H.actions,Te,he):Ie.handleActions(H.actions,Te)}return C?.(O,H)},le=x=>{let C=e(),O=hh(x),Q=O.some(H=>H.name==="handleLineActions");O.forEach(H=>{if(!Ic[H.name]&&!r)throw new Error(`Unhandled pending effect "${H.name}".`)});let Ie={engine:C,routeGraphics:n,ticker:t,autoTimer:a,skipTimer:c,nextLineConfigTimerState:u,trackRenderDispatch:$,getRenderDispatchCount:B,enqueuePersistenceWrite:A};for(let H of O){if(Q&&H.name==="render")continue;let Te=Ic[H.name];if(Te){Te(Ie,H.payload);continue}r(H,Ie)}};return le.handleRouteGraphicsEvent=T,le.createRouteGraphicsEventHandler=fe,le},bh=yh;var Ih=(e,n={})=>{let{resources:t={}}=n;return io(e,t)};var Xy=Go;export{Vr as DEFAULT_VISUAL_LAYER,xn as RENDER_LAYER,Ne as VISUAL_LAYER,bh as createEffectsHandler,qg as createIndexedDbPersistence,Xy as default,$r as formatDate,uu as resolveComputedVariables,Ih as resolveLayoutReferences};
1
+ var mp=Object.defineProperty;var yp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),hp=(e,t)=>{for(var n in t)mp(e,n,{get:t[n],enumerable:!0})};var _c=yp(Ji=>{"use strict";Object.defineProperty(Ji,"__esModule",{value:!0});function Cc(e){let t=e.length,n=0,i=0,a;for(;i<t;)n++,a=e.charCodeAt(i++),a>=55296&&a<=56319&&i<t&&(a=e.charCodeAt(i),(a&64512)===56320&&i++);return n}Ji.default=Cc;Cc.code='require("ajv/dist/runtime/ucs2length").default'});var ho=Symbol.for("immer-nothing"),uo=Symbol.for("immer-draftable"),Ae=Symbol.for("immer-state");function _e(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var jr=Object.getPrototypeOf;function ye(e){return!!e&&!!e[Ae]}function fr(e){return e?go(e)||Array.isArray(e)||!!e[uo]||!!e.constructor?.[uo]||qt(e)||Vt(e):!1}var gp=Object.prototype.constructor.toString();function go(e){if(!e||typeof e!="object")return!1;let t=jr(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)===gp}function vs(e){return ye(e)||_e(15,e),e[Ae].base_}function Dt(e,t){Mt(e)===0?Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)}):e.forEach((n,i)=>t(i,n,e))}function Mt(e){let t=e[Ae];return t?t.type_:Array.isArray(e)?1:qt(e)?2:Vt(e)?3:0}function ys(e,t){return Mt(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function bo(e,t,n){let i=Mt(e);i===2?e.set(t,n):i===3?e.add(n):e[t]=n}function bp(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function qt(e){return e instanceof Map}function Vt(e){return e instanceof Set}function pr(e){return e.copy_||e.base_}function hs(e,t){if(qt(e))return new Map(e);if(Vt(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=go(e);if(t===!0||t==="class_only"&&!n){let i=Object.getOwnPropertyDescriptors(e);delete i[Ae];let a=Reflect.ownKeys(i);for(let r=0;r<a.length;r++){let s=a[r],o=i[s];o.writable===!1&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(i[s]={configurable:!0,writable:!0,enumerable:o.enumerable,value:e[s]})}return Object.create(jr(e),i)}else{let i=jr(e);if(i!==null&&n)return{...e};let a=Object.create(i);return Object.assign(a,e)}}function As(e,t=!1){return Ft(e)||ye(e)||!fr(e)||(Mt(e)>1&&(e.set=e.add=e.clear=e.delete=wp),Object.freeze(e),t&&Object.entries(e).forEach(([n,i])=>As(i,!0))),e}function wp(){_e(2)}function Ft(e){return Object.isFrozen(e)}var Ip={};function dr(e){let t=Ip[e];return t||_e(0,e),t}var et;function wo(){return et}function vp(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function po(e,t){t&&(dr("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function gs(e){bs(e),e.drafts_.forEach(Ap),e.drafts_=null}function bs(e){e===et&&(et=e.parent_)}function fo(e){return et=vp(et,e)}function Ap(e){let t=e[Ae];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function mo(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];return e!==void 0&&e!==n?(n[Ae].modified_&&(gs(t),_e(4)),fr(e)&&(e=Tt(t,e),t.parent_||Lt(t,e)),t.patches_&&dr("Patches").generateReplacementPatches_(n[Ae].base_,e,t.patches_,t.inversePatches_)):e=Tt(t,n,[]),gs(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==ho?e:void 0}function Tt(e,t,n){if(Ft(t))return t;let i=t[Ae];if(!i)return Dt(t,(a,r)=>yo(e,i,t,a,r,n)),t;if(i.scope_!==e)return t;if(!i.modified_)return Lt(e,i.base_,!0),i.base_;if(!i.finalized_){i.finalized_=!0,i.scope_.unfinalizedDrafts_--;let a=i.copy_,r=a,s=!1;i.type_===3&&(r=new Set(a),a.clear(),s=!0),Dt(r,(o,l)=>yo(e,i,a,o,l,n,s)),Lt(e,a,!1),n&&e.patches_&&dr("Patches").generatePatches_(i,n,e.patches_,e.inversePatches_)}return i.copy_}function yo(e,t,n,i,a,r,s){if(ye(a)){let o=r&&t&&t.type_!==3&&!ys(t.assigned_,i)?r.concat(i):void 0,l=Tt(e,a,o);if(bo(n,i,l),ye(l))e.canAutoFreeze_=!1;else return}else s&&n.add(a);if(fr(a)&&!Ft(a)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;Tt(e,a),(!t||!t.scope_.parent_)&&typeof i!="symbol"&&Object.prototype.propertyIsEnumerable.call(n,i)&&Lt(e,a)}}function Lt(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&As(t,n)}function kp(e,t){let n=Array.isArray(e),i={type_:n?1:0,scope_:t?t.scope_:wo(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},a=i,r=ks;n&&(a=[i],r=rt);let{revoke:s,proxy:o}=Proxy.revocable(a,r);return i.draft_=o,i.revoke_=s,o}var ks={get(e,t){if(t===Ae)return e;let n=pr(e);if(!ys(n,t))return Pp(e,n,t);let i=n[t];return e.finalized_||!fr(i)?i:i===ds(e.base_,t)?(ms(e),e.copy_[t]=Is(i,e)):i},has(e,t){return t in pr(e)},ownKeys(e){return Reflect.ownKeys(pr(e))},set(e,t,n){let i=Io(pr(e),t);if(i?.set)return i.set.call(e.draft_,n),!0;if(!e.modified_){let a=ds(pr(e),t),r=a?.[Ae];if(r&&r.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(bp(n,a)&&(n!==void 0||ys(e.base_,t)))return!0;ms(e),ws(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 ds(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,ms(e),ws(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=pr(e),i=Reflect.getOwnPropertyDescriptor(n,t);return i&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:i.enumerable,value:n[t]}},defineProperty(){_e(11)},getPrototypeOf(e){return jr(e.base_)},setPrototypeOf(){_e(12)}},rt={};Dt(ks,(e,t)=>{rt[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});rt.deleteProperty=function(e,t){return rt.set.call(this,e,t,void 0)};rt.set=function(e,t,n){return ks.set.call(this,e[0],t,n,e[0])};function ds(e,t){let n=e[Ae];return(n?pr(n):e)[t]}function Pp(e,t,n){let i=Io(t,n);return i?"value"in i?i.value:i.get?.call(e.draft_):void 0}function Io(e,t){if(!(t in e))return;let n=jr(e);for(;n;){let i=Object.getOwnPropertyDescriptor(n,t);if(i)return i;n=jr(n)}}function ws(e){e.modified_||(e.modified_=!0,e.parent_&&ws(e.parent_))}function ms(e){e.copy_||(e.copy_=hs(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var xp=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,n,i)=>{if(typeof t=="function"&&typeof n!="function"){let r=n;n=t;let s=this;return function(l=r,...c){return s.produce(l,u=>n.call(this,u,...c))}}typeof n!="function"&&_e(6),i!==void 0&&typeof i!="function"&&_e(7);let a;if(fr(t)){let r=fo(this),s=Is(t,void 0),o=!0;try{a=n(s),o=!1}finally{o?gs(r):bs(r)}return po(r,i),mo(a,r)}else if(!t||typeof t!="object"){if(a=n(t),a===void 0&&(a=t),a===ho&&(a=void 0),this.autoFreeze_&&As(a,!0),i){let r=[],s=[];dr("Patches").generateReplacementPatches_(t,a,r,s),i(r,s)}return a}else _e(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(s,...o)=>this.produceWithPatches(s,l=>t(l,...o));let i,a;return[this.produce(t,n,(s,o)=>{i=s,a=o}),i,a]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){fr(e)||_e(8),ye(e)&&(e=er(e));let t=fo(this),n=Is(e,void 0);return n[Ae].isManual_=!0,bs(t),n}finishDraft(e,t){let n=e&&e[Ae];(!n||!n.isManual_)&&_e(9);let{scope_:i}=n;return po(i,t),mo(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let a=t[n];if(a.path.length===0&&a.op==="replace"){e=a.value;break}}n>-1&&(t=t.slice(n+1));let i=dr("Patches").applyPatches_;return ye(e)?i(e,t):this.produce(e,a=>i(a,t))}};function Is(e,t){let n=qt(e)?dr("MapSet").proxyMap_(e,t):Vt(e)?dr("MapSet").proxySet_(e,t):kp(e,t);return(t?t.scope_:wo()).drafts_.push(n),n}function er(e){return ye(e)||_e(10,e),vo(e)}function vo(e){if(!fr(e)||Ft(e))return e;let t=e[Ae],n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=hs(e,t.scope_.immer_.useStrictShallowCopy_)}else n=hs(e,!0);return Dt(n,(i,a)=>{bo(n,i,vo(a))}),t&&(t.finalized_=!1),n}var Se=new xp,Ps=Se.produce,q0=Se.produceWithPatches.bind(Se),V0=Se.setAutoFreeze.bind(Se),F0=Se.setUseStrictShallowCopy.bind(Se),U0=Se.applyPatches.bind(Se),B0=Se.createDraft.bind(Se),Y0=Se.finishDraft.bind(Se);var A={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},z={EQ:0,NEQ:1,GT:2,LT:3,GTE:4,LTE:5,AND:6,OR:7,IN:8,ADD:10,SUBTRACT:11},Nr={NOT:0};var $=class extends Error{constructor(t){super(`Parse Error: ${t}`),this.name="JemplParseError"}},Ie=class extends Error{constructor(t){super(`Render Error: ${t}`),this.name="JemplRenderError"}};var xs=e=>{if(!e||e.trim()==="")throw new $("Missing condition expression after '$if'");if(e.includes("===")||e.includes("!==")){let n=e.includes("===")?"==":"!=";throw new $(`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 $(`Incomplete comparison expression - missing right operand (got: '${e}')`)},Ao=e=>{if(e.trim().endsWith(" in"))throw new $(`Missing iterable expression after 'in' (got: '$for ${e}')`);if(!e.includes(" in "))throw new $(`Invalid loop syntax - missing 'in' keyword (got: '$for ${e}')`);let[t,n]=e.split(" in ");if(!n||n.trim()==="")throw new $(`Missing iterable expression after 'in' (got: '$for ${e}')`);let i=t.includes(",")?t.split(",").map(a=>a.trim()):[t.trim()];for(let a of i){if(!a)throw new $(`Invalid loop variable - variable name cannot be empty (got: '$for ${e}')`);if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(a))throw new $(`Invalid loop syntax (got: '$for ${e}')`)}};var ko=(e,t,n=!1)=>{if(t===null)return new Ie(`Cannot iterate over null value at '$for ${e}'`);if(t===void 0)return new Ie(`Cannot iterate over undefined value at '$for ${e}'`);let i=typeof t;return n?new Ie(`Cannot iterate over non-array value in loop '${e}' - got ${i} instead`):new Ie(`Cannot iterate over non-array value (got: ${i}) at '$for ${e}'`)},Po=(e,t)=>{let n=t&&Object.keys(t).length>0?Object.keys(t).join(", "):"no custom functions provided";return new Ie(`Unknown function '${e}' (${n})`)};var Ep=(e,t,n={})=>{let i={},a={};n&&typeof n=="object"&&(n.functions!==void 0||n.partials!==void 0?(i=n.functions||{},a=n.partials||{}):typeof n=="object"&&(i=n));let s=X(e,{functions:i,partials:a},t,{});return s===void 0?{}:s},X=(e,t,n,i)=>{let a=t.functions||t;if(e.var&&!e.type)return ue(e.var,n,i);if(e.type===A.LITERAL)return e.value;if(e.type===A.VARIABLE)return ue(e.path,n,i);if(e.type===A.INTERPOLATION)return Op(e.parts,t,n,i);switch(e.type){case A.FUNCTION:return Eo(e,t,n,i);case A.BINARY:return So(e,t,n,i);case A.UNARY:return Oo(e,t,n,i);case A.CONDITIONAL:return Cp(e,t,n,i);case A.LOOP:return Dp(e,t,n,i);case A.OBJECT:return Lp(e,t,n,i);case A.ARRAY:return Mp(e,t,n,i);case A.PARTIAL:return qp(e,t,n,i);case A.PATH_REFERENCE:return Vp(e,t,n,i);default:throw new Error(`Unknown node type: ${e.type}`)}},xo=new Map,Sp=e=>{let t=[],n="",i=!1;for(let a=0;a<e.length;a++){let r=e[a];if(r==="[")n&&(t.push({type:"property",value:n}),n=""),i=!0;else if(r==="]"){if(i&&n){let s=n.trim();if(/^\d+$/.test(s))t.push({type:"index",value:parseInt(s,10)});else if(s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'")){let o=s.slice(1,-1);t.push({type:"property",value:o})}else t.push({type:"property",value:s});n=""}i=!1}else n+=r}return n&&t.push({type:"property",value:n}),t},ue=(e,t,n)=>{if(!e)return;if(e in n)return n[e];let i=xo.get(e);if(!i){let r=[],s="",o=0;for(let l=0;l<e.length;l++){let c=e[l];c==="["?(o++,s+=c):c==="]"?(o--,s+=c):c==="."&&o===0?s&&(r.push(s),s=""):s+=c}s&&r.push(s),i=[];for(let l of r){let c=Sp(l.trim());i.push(...c)}xo.set(e,i)}let a=t;for(let r=0;r<i.length;r++){let s=i[r];if(s.type==="property"&&s.value in n){a=n[s.value];continue}if(a==null)return;(s.type==="property"||s.type==="index")&&(a=a[s.value])}return a},Op=(e,t,n,i)=>{let a=[];for(let r of e)if(typeof r=="string")a.push(r);else{let s=X(r,t,n,i);a.push(s!=null?String(s):"")}return a.join("")},Eo=(e,t,n,i)=>{let a=t.functions||t,r=a[e.name];if(!r)throw Po(e.name,a);let s=e.args.map(o=>X(o,t,n,i));return r(...s)},rr=(e,t,n,i)=>{if(e.var&&!e.type)return ue(e.var,n,i);switch(e.type){case A.VARIABLE:return ue(e.path,n,i);case A.LITERAL:return e.value;case A.BINARY:return So(e,t,n,i);case A.UNARY:return Oo(e,t,n,i);case A.FUNCTION:return Eo(e,t,n,i);default:return X(e,t,n,i)}},So=(e,t,n,i)=>{if(e.op===z.AND||e.op===z.OR){let s=rr(e.left,t,n,i),o=rr(e.right,t,n,i);switch(e.op){case z.AND:return s&&o;case z.OR:return s||o}}let a=X(e.left,t,n,i),r=X(e.right,t,n,i);switch(e.op){case z.EQ:return a==r;case z.NEQ:return a!=r;case z.GT:return a>r;case z.LT:return a<r;case z.GTE:return a>=r;case z.LTE:return a<=r;case z.IN:return Array.isArray(r)?r.includes(a):!1;case z.ADD:if(typeof a!="number"||typeof r!="number")throw new Ie(`Arithmetic operations require numbers. Got ${typeof a} + ${typeof r}`);return a+r;case z.SUBTRACT:if(typeof a!="number"||typeof r!="number")throw new Ie(`Arithmetic operations require numbers. Got ${typeof a} - ${typeof r}`);return a-r;default:throw new Error(`Unknown binary operator: ${e.op}`)}},Oo=(e,t,n,i)=>{let a=e.op===Nr.NOT?rr(e.operand,t,n,i):X(e.operand,t,n,i);if(e.op===Nr.NOT)return!a;throw new Error(`Unknown unary operator: ${e.op}`)},Rp=(e,t,n,i)=>{if(e.conditions.length===2&&e.conditions[1]===null){let a=e.conditions[0];if(a.type===A.VARIABLE)if(ue(a.path,n,i)){let s=e.bodies[0];if(s.type===A.OBJECT&&s.properties.length<=5){let o={};for(let l of s.properties){let c=l.parsedKey?X(l.parsedKey,t,n,i):l.key,u=l.value;if(u.type===A.LITERAL)o[c]=u.value;else if(u.type===A.VARIABLE)o[c]=ue(u.path,n,i);else if(u.type===A.INTERPOLATION){let p=[];for(let m of u.parts)if(typeof m=="string")p.push(m);else if(m.type===A.VARIABLE){let d=ue(m.path,n,i);p.push(d!=null?String(d):"")}else{let d=X(m,t,n,i);p.push(d!=null?String(d):"")}o[c]=p.join("")}else o[c]=X(u,t,n,i)}return o}}else{let s=e.bodies[1];if(s.type===A.OBJECT&&s.properties.length<=5){let o={};for(let l of s.properties){let c=l.parsedKey?X(l.parsedKey,t,n,i):l.key,u=l.value;if(u.type===A.LITERAL)o[c]=u.value;else if(u.type===A.VARIABLE)o[c]=ue(u.path,n,i);else if(u.type===A.INTERPOLATION){let p=[];for(let m of u.parts)if(typeof m=="string")p.push(m);else if(m.type===A.VARIABLE){let d=ue(m.path,n,i);p.push(d!=null?String(d):"")}else{let d=X(m,t,n,i);p.push(d!=null?String(d):"")}o[c]=p.join("")}else o[c]=X(u,t,n,i)}return o}}}return null},Cp=(e,t,n,i)=>{let a=Rp(e,t,n,i);if(a!==null)return a;for(let r=0;r<e.conditions.length;r++){let s=e.conditions[r];if(s===null||rr(s,t,n,i))return X(e.bodies[r],t,n,i)}return Ro},_p=(e,t)=>{let n=e.body,i=e.itemVar;if(n.type===A.CONDITIONAL&&n.conditions.length===1&&n.conditions[0].type===A.VARIABLE){let a=n.conditions[0].path,r=n.bodies[0];if(a.startsWith(i+".")){let s=a.substring(i.length+1);if(r.type===A.OBJECT&&r.properties.length<=5){for(let l of r.properties)if(l.parsedKey)return null;let o=[];for(let l=0;l<t.length;l++){let c=t[l];if(c[s]){let u={};for(let p of r.properties){let m=p.key,d=p.value;if(d.type===A.LITERAL)u[m]=d.value;else if(d.type===A.VARIABLE){let f=d.path;if(f===i)u[m]=c;else if(f.startsWith(i+".")){let y=f.substring(i.length+1);u[m]=c[y]}else return null}else if(d.type===A.INTERPOLATION){let f=[],y=!0;for(let g of d.parts)if(typeof g=="string")f.push(g);else if(g.type===A.VARIABLE){let h=g.path;if(h===i)f.push(c!=null?String(c):"");else if(h.startsWith(i+".")){let w=h.substring(i.length+1),b=c[w];f.push(b!=null?String(b):"")}else{y=!1;break}}else{y=!1;break}if(!y)return null;u[m]=f.join("")}else return null}o.push(u)}}return o}}}return null},$p=(e,t)=>{let n=e.body,i=e.itemVar,a=_p(e,t);if(a!==null)return a;if(n.type===A.OBJECT&&n.properties.length<=5&&!n.whenCondition){for(let o of n.properties)if(o.parsedKey)return null;let r=[],s=!0;for(let o of n.properties){let l=o.key,c=o.value;if(c.type===A.LITERAL)r.push({key:l,type:"literal",value:c.value});else if(c.type===A.VARIABLE){let u=c.path;if(u===i)r.push({key:l,type:"item"});else if(u.startsWith(i+".")){let p=u.substring(i.length+1);if(!p.includes(".")&&!p.includes("["))r.push({key:l,type:"prop",prop:p});else{s=!1;break}}else{s=!1;break}}else if(c.type===A.INTERPOLATION&&c.parts.length===1){let u=c.parts[0];if(u.type===A.VARIABLE){let p=u.path;if(p===i)r.push({key:l,type:"item_string"});else if(p.startsWith(i+".")){let m=p.substring(i.length+1);if(!m.includes(".")&&!m.includes("["))r.push({key:l,type:"prop_string",prop:m});else{s=!1;break}}else{s=!1;break}}else{s=!1;break}}else{s=!1;break}}if(s){let o=new Array(t.length);if(r.length===3&&r[0].type==="prop"&&r[0].key==="id"&&r[1].type==="prop_string"&&r[1].key==="title"&&r[2].type==="prop"&&r[2].key==="completed")for(let l=0;l<t.length;l++){let c=t[l];o[l]={id:c.id,title:c.title!=null?String(c.title):"",completed:c.completed}}else for(let l=0;l<t.length;l++){let c=t[l],u={};for(let p of r)if(p.type==="literal")u[p.key]=p.value;else if(p.type==="item")u[p.key]=c;else if(p.type==="prop")u[p.key]=c[p.prop];else if(p.type==="item_string")u[p.key]=c!=null?String(c):"";else if(p.type==="prop_string"){let m=c[p.prop];u[p.key]=m!=null?String(m):""}o[l]=u}return o}}return null},jp=(e,t,n,i,a)=>{let r=[],s=e.body;if(s.type===A.OBJECT&&s.fast!==!1){let o=e.itemVar,l=e.indexVar;for(let c=0;c<a.length;c++){let u=a[c],p={},m={...i,[o]:u,...l&&{[l]:c}};m.__paths__||(m.__paths__=i.__paths__||{});let d=e.iterable.path||"";if(i&&i.__paths__&&d){let f=d.split("."),y=f[0];y in i.__paths__&&(d=i.__paths__[y],f.length>1&&(d+="."+f.slice(1).join(".")))}m.__paths__={...m.__paths__,[o]:`${d}[${c}]`,...l&&{[l]:c}};for(let f of s.properties){let y=f.parsedKey?X(f.parsedKey,t,n,m):f.key,g=f.value;if(g.type===A.LITERAL)p[y]=g.value;else if(g.type===A.VARIABLE){let h=g.path;if(h===o)p[y]=u;else if(h===l)p[y]=c;else if(h.startsWith(o+".")){let w=h.substring(o.length+1);!w.includes(".")&&!w.includes("[")?p[y]=u[w]:p[y]=ue(h,n,{...i,[o]:u,...l&&{[l]:c}})}else p[y]=ue(h,n,{...i,[o]:u,...l&&{[l]:c}})}else if(g.type===A.INTERPOLATION){let h=[];for(let w of g.parts)if(typeof w=="string")h.push(w);else if(w.type===A.VARIABLE){let b=w.path,E;if(b===o)E=u;else if(b===l)E=c;else if(b.startsWith(o+".")){let v=b.substring(o.length+1);!v.includes(".")&&!v.includes("[")?E=u[v]:E=ue(b,n,{...i,[o]:u,...l&&{[l]:c}})}else E=ue(b,n,{...i,[o]:u,...l&&{[l]:c}});h.push(E!=null?String(E):"")}else{let b={...i,[o]:u,...l&&{[l]:c}},E=X(w,t,n,b);h.push(E!=null?String(E):"")}p[y]=h.join("")}else{let h={...i,[o]:u,...l&&{[l]:c}};p[y]=X(g,t,n,h)}}r.push(p)}return r}return null},Np=(e,t,n)=>{let i=e.body;if(i.type===A.OBJECT&&i.properties.length===1&&i.properties[0].key==="$if item.visible"){let r=i.properties[0].value;if(r.type===A.CONDITIONAL&&r.conditions.length===1&&r.conditions[0].type===A.VARIABLE&&r.conditions[0].path==="item.visible"){let s=r.bodies[0];if(s.type===A.OBJECT&&s.properties.length===2){let o=s.properties[0],l=s.properties[1];if(o.key==="id"&&o.value.type===A.VARIABLE&&o.value.path==="item.id"&&l.key==="$if item.highlighted"&&l.value.type===A.CONDITIONAL){let c=[];for(let u=0;u<t.length;u++){let p=t[u];if(p.visible){let m={id:p.id};p.highlighted?(m.highlight=!0,m.message=`This item is highlighted: ${p.name}`):(m.highlight=!1,m.message=p.name),c.push(m)}}return c}}}}return null},Dp=(e,t,n,i)=>{let a=X(e.iterable,t,n,i);if(!Array.isArray(a)){let c,u=!1;if(e.iterable.type===A.FUNCTION){u=!0;let m=e.iterable.args.map(d=>d.type===A.LITERAL?typeof d.value=="string"?`'${d.value}'`:String(d.value):d.type===A.VARIABLE?d.path:d.type===A.FUNCTION?`${d.name}(...)`:"?").join(", ");c=`${e.iterable.name}(${m})`}else c=e.iterable.path||"undefined";let p=`${e.itemVar}${e.indexVar?`, ${e.indexVar}`:""} in ${c}`;throw ko(p,a,u)}if(!e.indexVar){let c=Np(e,a,e.itemVar);if(c!==null)return c}if(!e.indexVar){let c=$p(e,a);if(c!==null)return c}let r=jp(e,t,n,i,a);if(r!==null)return r;let s=[],o=e.iterable.path||"";if(i&&i.__paths__&&o){let c=o.split("."),u=c[0];u in i.__paths__&&(o=i.__paths__[u],c.length>1&&(o+="."+c.slice(1).join(".")))}let l=!1;e.body.type===A.ARRAY&&(e.body.items.length<=1?l=!1:l=e.body._shouldPreserveArray??=e.body.items.some(c=>c.type===A.OBJECT&&c.properties.some(u=>u.key.startsWith("$if ")||u.key.startsWith("$when "))));for(let c=0;c<a.length;c++){let u=e.indexVar?{...i,[e.itemVar]:a[c],[e.indexVar]:c}:{...i,[e.itemVar]:a[c]};u.__paths__||(u.__paths__=i.__paths__||{}),u.__paths__={...u.__paths__,[e.itemVar]:`${o}[${c}]`},e.indexVar&&(u.__paths__[e.indexVar]=c);let p=X(e.body,t,n,u);if(Array.isArray(p)&&p.length===1&&!l){let m=p[0];s.push(m===void 0?{}:m)}else s.push(p===void 0?{}:p)}return s},Tp=(e,t,n,i)=>{if(e.whenCondition)return null;if(e.properties.length===1){let a=e.properties[0],r=a.parsedKey?X(a.parsedKey,t,n,i):a.key,s=a.value;if(s.type===A.OBJECT&&s.properties.length<=10&&!s.whenCondition){let o={},l={},c=!0;for(let u of s.properties){let p=u.parsedKey?X(u.parsedKey,t,n,i):u.key,m=u.value;if(m.type===A.LITERAL)l[p]=m.value;else if(m.type===A.VARIABLE)l[p]=ue(m.path,n,i);else if(m.type===A.INTERPOLATION){let d=[];for(let f of m.parts)if(typeof f=="string")d.push(f);else if(f.type===A.VARIABLE){let y=ue(f.path,n,i);d.push(y!=null?String(y):"")}else{c=!1;break}if(!c)break;l[p]=d.join("")}else if(m.type===A.OBJECT&&m.properties.length<=5){let d={};for(let f of m.properties){let y=f.key,g=f.value;if(g.type===A.LITERAL)d[y]=g.value;else if(g.type===A.VARIABLE)d[y]=ue(g.path,n,i);else if(g.type===A.INTERPOLATION){let h=[];for(let w of g.parts)if(typeof w=="string")h.push(w);else if(w.type===A.VARIABLE){let b=ue(w.path,n,i);h.push(b!=null?String(b):"")}else{c=!1;break}if(!c)break;d[y]=h.join("")}else{c=!1;break}}if(!c)break;l[p]=d}else{c=!1;break}}if(c)return o[r]=l,o}}return null},Lp=(e,t,n,i)=>{let a=t.functions||t;if(e.whenCondition&&!rr(e.whenCondition,a,n,i))return;let r=Tp(e,t,n,i);if(r!==null)return r;if(e.fast){let c={};for(let u of e.properties){let p=u.parsedKey?X(u.parsedKey,t,n,i):u.key,m=u.value;if(m.type===A.LITERAL)c[p]=m.value;else if(m.type===A.VARIABLE)c[p]=ue(m.path,n,i);else if(m.type===A.INTERPOLATION){let d=[];for(let f of m.parts)if(typeof f=="string")d.push(f);else if(f.type===A.VARIABLE){let y=ue(f.path,n,i);d.push(y!=null?String(y):"")}else{let y=X(f,t,n,i);d.push(y!=null?String(y):"")}c[p]=d.join("")}else c[p]=X(m,t,n,i)}return c}let s={},o=null,l=!1;for(let c of e.properties)if(!c.key.startsWith("$if ")&&!c.key.match(/^\$if\s+\w+.*:?$/)&&!c.key.startsWith("$elif")&&!c.key.startsWith("$else")&&!c.key.startsWith("$for ")){l=!0;break}for(let c of e.properties)if(c.key.startsWith("$if ")||c.key.match(/^\$if\s+\w+.*:?$/)){let u=X(c.value,t,n,i);if(!l&&u!==null&&u!==void 0)return Array.isArray(u)&&u.length===1?u[0]:u;typeof u=="object"&&u!==null&&!Array.isArray(u)&&Object.assign(s,u)}else if(c.key.startsWith("$for ")){if(e.properties.length===1)return X(c.value,t,n,i)}else{let u=c.value;if(u&&u.type===A.OBJECT&&u.properties){let p=u.properties.find(m=>m.key.startsWith("$for "));if(p){let m=X(p.value,t,n,i);m!==void 0&&(s[c.key]=m)}else{let m=X(c.value,t,n,i);m!==void 0&&(s[c.key]=m)}}else{let p=c.parsedKey?X(c.parsedKey,t,n,i):c.key,m=X(c.value,t,n,i);m!==void 0&&(s[p]=m)}}return s},Ro={},Mp=(e,t,n,i)=>{let a=[];for(let r of e.items)if(r.type===A.LOOP){let s=X(r,t,n,i);Array.isArray(s)&&r.flatten!==!1?a.push(...s):a.push(s)}else{let s=X(r,t,n,i);s!==Ro&&s!==void 0&&a.push(s)}return a},qp=(e,t,n,i)=>{let{name:a,data:r,whenCondition:s}=e,o=t.partials||{},l=t.functions||t;if(s&&!rr(s,l,n,i))return;if(!o[a])throw new Ie(`Partial '${a}' is not defined`);let c=i._partialStack||[];if(c.includes(a))throw new Ie(`Circular partial reference detected: ${a}`);let u=o[a],p=n,m={...i,_partialStack:[...c,a]};if(i){p={...n};for(let d of Object.keys(i))d.startsWith("_")||(p[d]=i[d])}if(r){let d=X(r,t,n,i);p={...p,...d}}return X(u,t,p,m)},Vp=(e,t,n,i)=>{let{path:a}=e,r=a.split("."),s=r[0],o=r.slice(1);if(!i||!(s in i))throw new Ie(`Path reference '#{${a}}' refers to '${s}' which is not a loop variable in the current scope`);if(i.__paths__||(i.__paths__={}),!(s in i.__paths__))throw new Ie(`Path reference '#{${a}}' cannot be resolved - path tracking may not be initialized properly`);let l=i.__paths__[s];if(typeof l=="number"){if(o.length>0)throw new Ie(`Path reference '#{${a}}' - cannot access properties on index variable '${s}'`);return String(l)}return o.length>0&&(l+="."+o.join(".")),l};var Es=Ep;var Fp=/\$\{([^}]*)\}/g,Up=/#\{([^}]*)\}/g,_o=(e,t={})=>{let n=e.match(/^(\w+)\((.*)\)$/);if(!n)return{isFunction:!1};let[,i,a]=n,r=Bp(a,t);return{isFunction:!0,type:A.FUNCTION,name:i,args:r}},Bp=(e,t={})=>e.trim()?Yp(e).map(i=>zp(i.trim(),t)):[],Yp=e=>{let t=[],n="",i=0,a=!1,r="";for(let s=0;s<e.length;s++){let o=e[s],l=s>0?e[s-1]:"";!a&&(o==='"'||o==="'")?(a=!0,r=o,n+=o):a&&o===r&&l!=="\\"?(a=!1,r="",n+=o):!a&&o==="("?(i++,n+=o):!a&&o===")"?(i--,n+=o):!a&&o===","&&i===0?(t.push(n),n=""):n+=o}return n&&t.push(n),t},zp=(e,t={})=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:A.LITERAL,value:e.slice(1,-1)};if(/^-?\d+(\.\d+)?$/.test(e))return{type:A.LITERAL,value:parseFloat(e)};if(e==="true")return{type:A.LITERAL,value:!0};if(e==="false")return{type:A.LITERAL,value:!1};if(e==="null")return{type:A.LITERAL,value:null};let n=_o(e,t);if(n.isFunction)return{type:n.type,name:n.name,args:n.args};let i=e.trim(),a=[{op:" + ",type:"ADD"},{op:" - ",type:"SUBTRACT"}],r=-1,s=null;for(let{op:o,type:l}of a){let c=0;for(;c<i.length;){let u=mr(i.substring(c),o);if(u===-1)break;let p=c+u;p>r&&(r=p,s={op:o,type:l}),c=p+o.length}}if(r!==-1)try{return de(i,t)}catch{return{type:A.VARIABLE,path:i}}return{type:A.VARIABLE,path:i}},$o=/^\w+\(.*\)$/,Gp=/\s[+\-*/%]\s|\|\||&&|\?\?|.*\?.*:/,Xp=e=>{if(!(!e||e.trim()===""||$o.test(e))&&Gp.test(e))throw e.includes("?")&&e.includes(":")?new $(`Complex expressions not supported in variable replacements - consider calculating the value in your data instead. Offending expression: "${e}"`):e.includes("||")||e.includes("&&")||e.includes("??")?new $(`Logical operators not supported in variable replacements - consider calculating the value in your data instead (operators like ||, &&, ?? are not supported). Offending expression: "${e}"`):new $(`Arithmetic expressions not supported in variable replacements - consider calculating '${e}' in your data instead (expressions with +, -, *, /, % are not supported). Offending expression: "${e}"`)},Co=e=>{let t=e.trim();if($o.test(t))throw new $(`Functions are not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("["))throw new $(`Array indices not supported in path references - use simple variable names or properties. Offending expression: "#{${e}}"`);if(/[+\-*/%]/.test(t))throw new $(`Arithmetic expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(/\|\||&&/.test(t))throw new $(`Logical operators not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);if(t.includes("?")&&t.includes(":"))throw new $(`Complex expressions not supported in path references - path references can only refer to loop variables. Offending expression: "#{${e}}"`);return{type:A.PATH_REFERENCE,path:t}},tt=(e,t={})=>{let n=e.trim();Xp(n);let i=_o(n,t);if(i.isFunction)return{type:i.type,name:i.name,args:i.args};if(n.includes("[")&&!/[\s+\-*/%|&?:]/.test(n)){let a=0;for(let r of n)r==="["?a++:r==="]"&&a--;if(a!==0)throw new Error("Invalid array index syntax")}return{type:A.VARIABLE,path:n}},Ss=(e,t={})=>{let n=e,i=[];(e.includes("\\${")||e.includes("\\#{"))&&(n=e.replace(/\\\\(\$\{[^}]*\})/g,"\\DOUBLE_ESC_VAR$1"),n=n.replace(/\\\\(#\{[^}]*\})/g,"\\DOUBLE_ESC_PATH$1"),n=n.replace(/\\(\$\{[^}]*\})/g,(c,u)=>{let p=`__ESCAPED_${i.length}__`;return i.push(u),p}),n=n.replace(/\\(#\{[^}]*\})/g,(c,u)=>{let p=`__ESCAPED_${i.length}__`;return i.push(u),p}),n=n.replace(/\\DOUBLE_ESC_VAR/g,"\\"),n=n.replace(/\\DOUBLE_ESC_PATH/g,"\\"));let a=[...n.matchAll(Fp)],r=[...n.matchAll(Up)],s=[...a.map(c=>({match:c,type:"variable"})),...r.map(c=>({match:c,type:"pathref"}))].sort((c,u)=>c.match.index-u.match.index);if(s.length===0){let c=n;for(let u=0;u<i.length;u++)c=c.replace(`__ESCAPED_${u}__`,i[u]);return{type:A.LITERAL,value:c}}if(s.length===1&&s[0].match[0]===n&&i.length===0){let{match:c,type:u}=s[0];try{return u==="variable"?tt(c[1],t):Co(c[1])}catch(p){if(p.message==="Invalid array index syntax")return{type:A.LITERAL,value:n};throw p}}let o=[],l=0;for(let{match:c,type:u}of s){let[p,m]=c,d=c.index;if(d>l){let f=n.substring(l,d);for(let y=0;y<i.length;y++)f=f.replace(`__ESCAPED_${y}__`,i[y]);f&&o.push(f)}try{let f;u==="variable"?f=tt(m.trim(),t):f=Co(m.trim()),o.push(f)}catch(f){if(f.message==="Invalid array index syntax")o.push(p);else throw f}l=d+p.length}if(l<n.length){let c=n.substring(l);for(let u=0;u<i.length;u++)c=c.replace(`__ESCAPED_${u}__`,i[u]);c&&o.push(c)}return{type:A.INTERPOLATION,parts:o}};var Cs=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Do=e=>Object.keys(e),be=e=>e.join("."),tr=(e,t,n)=>{let i=Do(e).filter(a=>!t.has(a));if(i.length>0)throw new $(`Unexpected key '${i[0]}' in condition JSON at '${be(n)}'`)},nr=(e,t)=>typeof e=="string"?Ss(e,t):typeof e=="object"&&e!==null?Array.isArray(e)?Hp(e,t):Kp(e,t):{type:A.LITERAL,value:e},Wp=e=>{let{$each:t,...n}=e;if(typeof t!="string")throw new $("$each value must be a non-empty string");let i=t.trim();if(i==="")throw new $("$each value must be a non-empty string");if(Object.keys(n).length===0)throw new $("Empty $each body not allowed");if(n.$partial!==void 0)throw new $("Cannot use $partial with $each at the same level. Wrap $partial in a parent object if you need conditionals.");return{[`$for ${i}`]:n}},Hp=(e,t)=>{let n=[],i=!1;for(let a=0;a<e.length;a++){let r=e[a];if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(r.$each!==void 0)try{let l=Wp(r),c=Object.keys(l);if(c.length===1&&/^\$for(?::\w+)?\s/.test(c[0])){let u=No(c[0],l[c[0]],t,!0);n.push(u),i=!0;continue}}catch(l){throw l instanceof $?l:new $(l.message)}let o=Object.keys(r);if(o.length===1&&/^\$for(?::\w+)?\s/.test(o[0])){let l=No(o[0],r[o[0]],t);n.push(l),i=!0;continue}}let s=nr(r,t);n.push(s),(s.type===A.FUNCTION||s.type===A.CONDITIONAL||s.type===A.LOOP||s.type===A.PARTIAL||s.type===A.OBJECT&&!s.fast||s.type===A.ARRAY&&!s.fast)&&(i=!0)}return{type:A.ARRAY,items:n,fast:!i}},Kp=(e,t)=>{let n=[],i=!1,a=null,r=Object.entries(e),s=0;if(e.$partial!==void 0){if(typeof e.$partial!="string")throw new $("$partial value must be a string");if(e.$partial.trim()==="")throw new $("$partial value cannot be an empty string");let l=["$if","$elif","$else","$for"],c=[];for(let[h]of r)for(let w of l)if(h===w||h.startsWith(w+" ")||h.startsWith(w+"#")){c.push(w);break}if(c.length>0)throw new $(`Cannot use $partial with ${c.join(", ")} at the same level. Wrap $partial in a parent object if you need conditionals.`);let{$partial:u,$when:p,...m}=e,d={},f=!1;for(let[h,w]of Object.entries(m)){let b=h;(h.startsWith("\\$")||h.startsWith("$$"))&&(b=h.slice(1)),d[b]=w,f=!0}let y=null;if(f&&(y=nr(d,t),y.type===A.OBJECT)){let h=!1;for(let w of y.properties)if(w.value.type===A.VARIABLE||w.value.type===A.INTERPOLATION||w.value.type===A.FUNCTION||w.value.type===A.CONDITIONAL||w.value.type===A.OBJECT&&!w.value.fast||w.value.type===A.ARRAY&&!w.value.fast){h=!0;break}h&&(y.fast=!1)}let g={type:A.PARTIAL,name:u,data:y};return p!==void 0&&(g.whenCondition=jo(p,t)),g}for(let[l,c]of r)if(l==="$when"){if(a!==null)throw new $("Multiple '$when' directives on the same object are not allowed");if(c==null)throw new $("Missing condition expression after '$when'");a=jo(c,t),i=!0}else if(l.startsWith("$when#")||l.startsWith("$when "))throw new $("'$when' does not support ID syntax or inline conditions - use '$when' as a property");for(;s<r.length;){let[l,c]=r[s];if(l==="$when"){s++;continue}if(l==="$each")throw new $("$each can only be used inside arrays");if(l.startsWith("$if ")||l.match(/^\$if#\w+\s/)||l.match(/^\$if\s+\w+.*:$/)){let u=Jp(r,s,t);n.push({key:l,value:u.node}),i=!0,s=u.nextIndex}else if(/^\$for(?::\w+)?\s/.test(l)){let u=l.match(/^\$for(?::(\w+))?\s/)?.[1]||"",p=u?`:${u}`:"";throw new $(`$for loops must be inside arrays - use '- $for${p} item in items:' instead of '$for${p} item in items:'. For cleaner object generation syntax, consider using $each.`)}else{if(l.startsWith("$elif ")||l.startsWith("$else"))throw new $(`'${l.split(" ")[0]}' without matching '$if'`);if(l==="$if"||l==="$if:")throw new $("Missing condition expression after '$if'");{let u=nr(c,t);(u.type===A.FUNCTION||u.type===A.CONDITIONAL||u.type===A.PARTIAL||u.type===A.OBJECT&&!u.fast||u.type===A.ARRAY&&!u.fast)&&(i=!0);let p=Ss(l,t),m={key:l,value:u};(p.type!==A.LITERAL||p.value!==l)&&(m.parsedKey=p),n.push(m),s++}}}let o={type:A.OBJECT,properties:n,fast:!i};return a&&(o.whenCondition=a),o},Jp=(e,t,n={})=>{let i=[],a=[],r=t,[s,o]=e[r],l=null,c;if(s.startsWith("$if#")){let p=s.match(/^\$if#(\w+)\s+(.+)$/);if(p)l=p[1],c=p[2];else throw new $(`Invalid conditional syntax: ${s}`)}else c=s.substring(4),c.endsWith(":")&&(c=c.slice(0,-1).trim());xs(c);let u=de(c,n);for(i.push(u),a.push(nr(o,n)),r++;r<e.length;){let[p,m]=e[r],d=!1,f;if(l?p.startsWith(`$elif#${l} `)?(f=p.substring(`$elif#${l} `.length),f.endsWith(":")&&(f=f.slice(0,-1).trim()),d=!0):(p===`$else#${l}`||p===`$else#${l}:`)&&(d=!0,f=null):p.startsWith("$elif ")?(f=p.substring(6),f.endsWith(":")&&(f=f.slice(0,-1).trim()),d=!0):(p==="$else"||p==="$else:")&&(d=!0,f=null),d){if(f===null)i.push(null);else{xs(f);let y=de(f,n);i.push(y)}if(a.push(nr(m,n)),r++,f===null)break}else break}return{node:{type:A.CONDITIONAL,conditions:i,bodies:a,id:l},nextIndex:r}},Os={eq:z.EQ,neq:z.NEQ,gt:z.GT,gte:z.GTE,lt:z.LT,lte:z.LTE,in:z.IN,add:z.ADD,sub:z.SUBTRACT},Rs={all:z.AND,any:z.OR},Qp=new Set(["var","literal","call","not",...Object.keys(Os),...Object.keys(Rs)]),Zp=(e,t,n)=>{if(!Array.isArray(e))throw new $(`Condition JSON operator '${t}' at '${be(n)}' requires an array`);if(e.length!==2)throw new $(`Condition JSON operator '${t}' at '${be(n)}' requires exactly 2 operands`);return e},ef=(e,t,n,i,a)=>{if(!Array.isArray(e))throw new $(`Condition JSON operator '${t}' at '${be(a)}' requires an array`);if(e.length===0)throw new $(`Condition JSON operator '${t}' at '${be(a)}' requires at least 1 condition`);return e.map((s,o)=>ke(s,i,[...a,o])).reduce((s,o)=>({type:A.BINARY,op:n,left:s,right:o}))},rf=(e,t,n)=>{let i,a;if(typeof e.call=="string")i=e.call,a=e.args??[],tr(e,new Set(["call","args"]),n);else if(Cs(e.call))i=e.call.name,a=e.call.args??[],tr(e,new Set(["call"]),n),tr(e.call,new Set(["name","args"]),[...n,"call"]);else throw new $(`Condition JSON call at '${be(n)}' requires a function name`);if(typeof i!="string"||i.trim()==="")throw new $(`Condition JSON call at '${be(n)}' requires a non-empty function name`);if(!/^\w+$/.test(i))throw new $(`Invalid condition JSON function name '${i}' at '${be(n)}'`);if(!Array.isArray(a))throw new $(`Condition JSON call '${i}' at '${be(n)}' requires args to be an array`);return{type:A.FUNCTION,name:i,args:a.map((r,s)=>ke(r,t,[...n,"args",s]))}},ke=(e,t={},n=["$when"])=>{if(typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null)return{type:A.LITERAL,value:e};if(Array.isArray(e))throw new $(`Condition JSON array at '${be(n)}' must be wrapped in an operator or { literal: [...] }`);if(!Cs(e))throw new $(`Invalid condition JSON value at '${be(n)}'`);let i=Do(e);if(i.length===0)throw new $(`Condition JSON object at '${be(n)}' must contain an operator`);let a=i.filter(s=>Qp.has(s));if(a.length===0)throw new $(`Unknown condition JSON operator '${i[0]}' at '${be(n)}'`);if(a.length>1)throw new $(`Condition JSON at '${be(n)}' must contain exactly one operator`);let r=a.includes("call")?"call":a[0];if(r==="var"){if(tr(e,new Set(["var"]),n),typeof e.var!="string"||e.var.trim()==="")throw new $(`Condition JSON var at '${be(n)}' requires a non-empty path`);return{type:A.VARIABLE,path:e.var}}if(r==="literal")return tr(e,new Set(["literal"]),n),{type:A.LITERAL,value:e.literal};if(r==="call")return rf(e,t,n);if(r==="not")return tr(e,new Set(["not"]),n),{type:A.UNARY,op:Nr.NOT,operand:ke(e.not,t,[...n,"not"])};if(r in Rs)return tr(e,new Set([r]),n),ef(e[r],r,Rs[r],t,[...n,r]);if(r in Os){tr(e,new Set([r]),n);let s=Zp(e[r],r,[...n,r]);return{type:A.BINARY,op:Os[r],left:ke(s[0],t,[...n,r,0]),right:ke(s[1],t,[...n,r,1])}}throw new $(`Unknown condition JSON operator '${r}' at '${be(n)}'`)},jo=(e,t={})=>{if(e==null)throw new $("Missing condition expression after '$when'");if(typeof e=="string"){if(e.trim()==="")throw new $("Empty condition expression after '$when'");return de(e,t)}return Cs(e)||Array.isArray(e)?ke(e,t):{type:A.LITERAL,value:e}},de=(e,t={})=>{if(e=e.trim(),e.startsWith("(")&&e.endsWith(")")){let c=e.slice(1,-1),u=0,p=!0;for(let m=0;m<c.length;m++)if(c[m]==="("?u++:c[m]===")"&&u--,u<0){p=!1;break}if(p&&u===0)return de(c,t)}let n=mr(e,"||");if(n!==-1)return{type:A.BINARY,op:z.OR,left:de(e.substring(0,n).trim(),t),right:de(e.substring(n+2).trim(),t)};let i=mr(e,"&&");if(i!==-1)return{type:A.BINARY,op:z.AND,left:de(e.substring(0,i).trim(),t),right:de(e.substring(i+2).trim(),t)};let a=[{op:">=",type:z.GTE},{op:"<=",type:z.LTE},{op:"==",type:z.EQ},{op:"!=",type:z.NEQ},{op:">",type:z.GT},{op:"<",type:z.LT},{op:" in ",type:z.IN}];for(let{op:c,type:u}of a){let p=mr(e,c);if(p!==-1)return{type:A.BINARY,op:u,left:de(e.substring(0,p).trim(),t),right:de(e.substring(p+c.length).trim(),t)}}let r=-1,s=null,o=[{op:" + ",type:z.ADD},{op:" - ",type:z.SUBTRACT}];for(let{op:c,type:u}of o){let p=0;for(;p<e.length;){let m=mr(e.substring(p),c);if(m===-1)break;let d=p+m;d>r&&(r=d,s={op:c,type:u}),p=d+c.length}}if(r!==-1&&s)return{type:A.BINARY,op:s.type,left:de(e.substring(0,r).trim(),t),right:de(e.substring(r+s.op.length).trim(),t)};let l=[" * "," / "," % "];for(let c of l)if(mr(e,c)!==-1)throw new $(`Arithmetic operations are not allowed in conditionals: "${c}"`);return e.startsWith("!")?{type:A.UNARY,op:Nr.NOT,operand:de(e.substring(1).trim(),t)}:To(e,t)},mr=(e,t)=>{let n=0,i=0;for(;i<=e.length-t.length;){if(e[i]==="(")n++;else if(e[i]===")")n--;else if(n===0&&e.substring(i,i+t.length)===t)return i;i++}return-1},tf=e=>{if(e=e.trim(),e==="true")return{type:A.LITERAL,value:!0};if(e==="false")return{type:A.LITERAL,value:!1};if(e==="null")return{type:A.LITERAL,value:null};if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{type:A.LITERAL,value:e.slice(1,-1)};if(e==='""'||e==="''")return{type:A.LITERAL,value:""};if(e==="{}")return{type:A.LITERAL,value:{}};if(e==="[]")return{type:A.LITERAL,value:[]};let t=Number(e);return!isNaN(t)&&isFinite(t)?{type:A.LITERAL,value:t}:{type:A.VARIABLE,path:e}},To=(e,t)=>{let n=e.trim();if(n.match(/^(\w+)\((.*)\)$/))return tt(n,t);let a=tf(n);if(a.type===A.LITERAL)return a;if(/^[a-zA-Z_$][\w.$]*$/.test(n))return{type:A.VARIABLE,path:n};try{return tt(n,t)}catch(r){if(r.message&&r.message.includes("not supported"))return a;throw r}},nf=(e,t=!1)=>{let n=t?"$each":"$for";try{Ao(e)}catch(i){if(i instanceof $&&t){let a=i.message.replace(/\$for/g,"$each");throw new $(a.replace("Parse Error: ",""))}throw i}},No=(e,t,n,i=!1)=>{let a=/^\$for(?::(\w+))?\s+(.+)$/,r=e.match(a);if(!r){let g=i?"$each":"$for";throw new $(`Invalid loop syntax (got: '${e.replace("$for",g)}')`)}let s=r[1],o=r[2].trim();nf(o,i);let l=o.match(/^(.+?)\s+in\s+(.+)$/);if(!l){let g=i?"$each":"$for";throw new $(`Invalid loop syntax - missing 'in' keyword (got: '${g} ${o}')`)}let c=l[1].trim(),u=l[2].trim(),p,m=null;if(c.includes(",")){let g=c.split(",").map(h=>h.trim());if(g.length!==2)throw new $(`Invalid loop variables: ${c}. Expected format: "item" or "item, index"`);p=g[0],m=g[1]}else p=c;let d=["this","undefined","null","true","false"];if(d.includes(p))throw new $(`Reserved variable name: ${p}`);if(m&&d.includes(m))throw new $(`Reserved variable name: ${m}`);let f=To(u,n),y=nr(t,n);return{type:A.LOOP,itemVar:p,indexVar:m,iterable:f,body:y,flatten:s!=="nested"}};var sf=(e,t={})=>{let{functions:n={}}=t;return nr(e,n)},Ut=sf;var nt={};hp(nt,{now:()=>of});var of=()=>Date.now();var af=(e,t,n={})=>{let{functions:i={},partials:a={}}=n,r={...nt,...i},s=Ut(e,{functions:r}),o={};for(let[l,c]of Object.entries(a))o[l]=Ut(c,{functions:r});return Es(s,t,{functions:r,partials:o})},yr=af;var lf=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&typeof e.type=="number",cf=(e={})=>!e||typeof e!="object"?{}:Object.prototype.hasOwnProperty.call(e,"functions")||Object.prototype.hasOwnProperty.call(e,"partials")?e.functions||{}:e,uf=(e,t)=>{if(lf(e))return e;if(typeof e=="string"){if(e.trim()==="")throw new $("Empty condition expression");return de(e,t)}return ke(e,t)},pf=(e,t={},n={})=>{let i=cf(n),a={...nt,...i},r=uf(e,a);return!!rr(r,{functions:a,partials:{}},t,{})},_s=pf;var Vs=Symbol("runStoreTransaction"),Ds="__routeEngineConditionComparison",Bt=(e,t)=>typeof e=="number"&&typeof t=="number"&&Number.isFinite(e)&&Number.isFinite(t)||typeof e=="string"&&typeof t=="string",sr=Object.freeze({eq:(e,t)=>e===t,neq:(e,t)=>e!==t,gt:(e,t)=>Bt(e,t)&&e>t,gte:(e,t)=>Bt(e,t)&&e>=t,lt:(e,t)=>Bt(e,t)&&e<t,lte:(e,t)=>Bt(e,t)&&e<=t}),Bo=Object.freeze(Object.fromEntries(Object.keys(sr).map(e=>[e,`${Ds}${e}`]))),ff=Object.freeze(Object.fromEntries(Object.entries(Bo).map(([e,t])=>[t,sr[e]]))),Lo=(e,t)=>Object.prototype.hasOwnProperty.call(e??{},t),df=e=>{if(typeof e?.call=="string")return e.call;if(e?.call!==null&&typeof e?.call=="object"&&!Array.isArray(e.call))return e.call.name},Yt=e=>{if(Array.isArray(e))return e.map(Yt);if(e===null||typeof e!="object"||Lo(e,"literal")||Lo(e,"var"))return e;if(df(e)?.startsWith(Ds))throw new Error(`Condition function names beginning with "${Ds}" are reserved`);let n=Object.entries(e);if(n.length===1){let[[i,a]]=n,r=Bo[i];if(r)return{call:r,args:a.map(Yt)}}return Object.fromEntries(n.map(([i,a])=>[i,Yt(a)]))},it=(e,t={})=>{if(typeof e=="string")throw new Error("String condition expressions are not supported; use semantic JSON conditions");return ke(e),_s(Yt(e),t,{functions:ff})},mf=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Yo=(e,t,n={})=>{let i=structuredClone(e),a={},r={},{transformSelectorFirstArgument:s=c=>c,transformActionFirstArgument:o=c=>c}=n;for(let[c,u]of Object.entries(t))c!=="createInitialState"&&(c.startsWith("select")?a[c]=(...p)=>u(s(i),...p):r[c]=(...p)=>{let m;return i=Ps(i,f=>{let y=u(o(f),...p);m=y!==void 0&&!ye(y)?y:void 0}),m});let l=c=>{if(typeof c!="function")throw new Error("Store transaction requires a callback");let u=i;try{return c()}catch(p){throw i=u,p}};return{...a,...r,[Vs]:l}},Wt=(e,t)=>n=>{let i=e(),a=Array.isArray(n)?n:[n];return Ps(i,r=>{a.forEach(s=>{t.forEach(o=>{o(r,s)})})})};var yf=(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{}}},U=(e,t)=>Object.prototype.hasOwnProperty.call(e??{},t),Ts=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})},pe=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),hf=new Set(["pageSize","groups"]),gf=new Set(["id","variants"]),bf=new Set(["id","imageId"]),wf=new Set(["pageSize","tracks"]),If=new Set(["id","soundId","title","artist","album","description","coverImageId"]),vf=new Set(["pageSize","replays"]),Af=new Set(["id","title","thumbnailImageId","startSectionId","initialVariables"]),hr=(e,t,n)=>{Object.keys(e).forEach(i=>{if(!t.has(i))throw new Error(`${n} contains unsupported property "${i}"`)})},Dr=(e,t)=>{if(typeof e!="string"||e.length===0)throw new Error(`${t} must be a non-empty string`)},ot=(e={})=>{let t=e?.resources?.imageGallery;if(t===void 0)return;if(!pe(t))throw new Error("resources.imageGallery must be an object");if(hr(t,hf,"resources.imageGallery"),!Number.isInteger(t.pageSize)||t.pageSize<1)throw new Error("resources.imageGallery.pageSize must be an integer greater than or equal to 1");if(!Array.isArray(t.groups))throw new Error("resources.imageGallery.groups must be an array");let n=new Set;for(let[i,a]of t.groups.entries()){let r=`resources.imageGallery.groups[${i}]`;if(!pe(a))throw new Error(`${r} must be an object`);if(hr(a,gf,r),Dr(a.id,`${r}.id`),n.has(a.id))throw new Error(`Duplicate image gallery group id "${a.id}"`);if(n.add(a.id),!Array.isArray(a.variants)||a.variants.length===0)throw new Error(`${r}.variants must be a non-empty array`);let s=new Set;for(let[o,l]of a.variants.entries()){let c=`${r}.variants[${o}]`;if(!pe(l))throw new Error(`${c} must be an object`);if(hr(l,bf,c),Dr(l.id,`${c}.id`),Dr(l.imageId,`${c}.imageId`),s.has(l.id))throw new Error(`Duplicate image gallery variant id "${l.id}" in group "${a.id}"`);if(s.add(l.id),!U(e?.resources?.images,l.imageId))throw new Error(`Image gallery variant "${a.id}.${l.id}" references unknown image "${l.imageId}"`)}}},at=(e={})=>{let t=e?.resources?.musicRoom;if(t===void 0)return;if(!pe(t))throw new Error("resources.musicRoom must be an object");if(hr(t,wf,"resources.musicRoom"),!Number.isInteger(t.pageSize)||t.pageSize<1)throw new Error("resources.musicRoom.pageSize must be an integer greater than or equal to 1");if(!Array.isArray(t.tracks))throw new Error("resources.musicRoom.tracks must be an array");let n=new Set;for(let[i,a]of t.tracks.entries()){let r=`resources.musicRoom.tracks[${i}]`;if(!pe(a))throw new Error(`${r} must be an object`);hr(a,If,r);for(let l of["id","soundId","title"])Dr(a[l],`${r}.${l}`);for(let l of["artist","album","description","coverImageId"])a[l]!==void 0&&Dr(a[l],`${r}.${l}`);if(n.has(a.id))throw new Error(`Duplicate music room track id "${a.id}"`);n.add(a.id);let s=e?.resources?.sounds?.[a.soundId];if(!U(e?.resources?.sounds,a.soundId))throw new Error(`Music room track "${a.id}" references unknown sound "${a.soundId}"`);if(!pe(s))throw new Error(`Music room track "${a.id}" references invalid sound "${a.soundId}"`);if(s.playbackRate!==void 0&&(typeof s.playbackRate!="number"||!Number.isFinite(s.playbackRate)||s.playbackRate<=0))throw new Error(`Music room sound "${a.soundId}" playbackRate must be a finite number greater than 0`);let o=s.startAt??0;if(typeof o!="number"||!Number.isFinite(o)||o<0)throw new Error(`Music room sound "${a.soundId}" startAt must be a finite non-negative number`);if(s.endAt!==void 0&&s.endAt!==null&&(typeof s.endAt!="number"||!Number.isFinite(s.endAt)||s.endAt<=o))throw new Error(`Music room sound "${a.soundId}" endAt must be a finite number greater than startAt`);if(a.coverImageId!==void 0&&!U(e?.resources?.images,a.coverImageId))throw new Error(`Music room track "${a.id}" references unknown cover image "${a.coverImageId}"`)}},kf=(e,t,n)=>{let i=Array.isArray(n)?"array":typeof n;switch(t.type){case"number":if(typeof n!="number"||!Number.isFinite(n))throw new Error(`Scene replay initial variable "${e}" expected type number, got ${i}`);return;case"boolean":if(typeof n!="boolean")throw new Error(`Scene replay initial variable "${e}" expected type boolean, got ${i}`);return;case"string":if(typeof n!="string")throw new Error(`Scene replay initial variable "${e}" expected type string, got ${i}`);return;case"object":if(n===null||typeof n!="object")throw new Error(`Scene replay initial variable "${e}" expected type object, got ${i}`);return;default:throw new Error(`Scene replay initial variable "${e}" has invalid variable type "${t.type}"`)}},lt=(e={})=>{let t=e?.resources?.sceneReplay;if(t===void 0)return;if(!pe(t))throw new Error("resources.sceneReplay must be an object");if(hr(t,vf,"resources.sceneReplay"),!Number.isInteger(t.pageSize)||t.pageSize<1)throw new Error("resources.sceneReplay.pageSize must be an integer greater than or equal to 1");if(!Array.isArray(t.replays))throw new Error("resources.sceneReplay.replays must be an array");let n=new Map;Object.values(e?.story?.scenes??{}).forEach(a=>{Object.entries(a?.sections??{}).forEach(([r,s])=>{n.set(r,s)})});let i=new Set;for(let[a,r]of t.replays.entries()){let s=`resources.sceneReplay.replays[${a}]`;if(!pe(r))throw new Error(`${s} must be an object`);hr(r,Af,s);for(let l of["id","title","thumbnailImageId","startSectionId"])Dr(r[l],`${s}.${l}`);if(i.has(r.id))throw new Error(`Duplicate scene replay id "${r.id}"`);if(i.add(r.id),!U(e?.resources?.images,r.thumbnailImageId))throw new Error(`Scene replay "${r.id}" references unknown thumbnail image "${r.thumbnailImageId}"`);if(!n.has(r.startSectionId))throw new Error(`Scene replay "${r.id}" references unknown start section "${r.startSectionId}"`);let o=n.get(r.startSectionId);if(o.initialLineId!==void 0&&!o.lines?.some(l=>l.id===o.initialLineId))throw new Error(`Scene replay "${r.id}" start section "${r.startSectionId}" references unknown initial line "${o.initialLineId}"`);if(r.initialVariables!==void 0){if(!pe(r.initialVariables))throw new Error(`${s}.initialVariables must be an object`);for(let[l,c]of Object.entries(r.initialVariables)){let u=e?.resources?.variables?.[l];if(!u)throw new Error(`Scene replay "${r.id}" initialVariables references unknown variable "${l}"`);if(Ne(u))throw new Error(`Scene replay "${r.id}" cannot initialize computed variable "${l}"`);if(u.readonly===!0)throw new Error(`Scene replay "${r.id}" cannot initialize readonly variable "${l}"`);if(u.scope!=="context")throw new Error(`Scene replay "${r.id}" can only initialize context variable "${l}"`);kf(l,u,c)}}}},zo=e=>{let t=ye(e)?er(e):e;return structuredClone(t)},Pf=({characterId:e,resourceCharacter:t,variables:n={}}={})=>{if(!U(t,"nameVariableId"))return;let i=t.nameVariableId,a=n?.[i];if(typeof a!="string")throw new Error(`Character "${e}" nameVariableId "${i}" must resolve to a string variable`);return a},Ht=({characterId:e,character:t,characterName:n,characters:i={},variables:a={}}={})=>{let r=e?i?.[e]:void 0;if(t?.name!==void 0)return t.name;if(n!==void 0)return n;let s=Pf({characterId:e,resourceCharacter:r,variables:a});return s!==void 0?s:r?.name||""},Ne=e=>U(e,"computed"),Tr=(e={},t={})=>Object.fromEntries(Object.entries(e??{}).filter(([n])=>!Ne(t[n]))),je=(e,t)=>new Error(`${t} has invalid path: ${JSON.stringify(e)}`),xf=(e,t,n)=>{if(e[0]==='"')try{return JSON.parse(e)}catch{throw je(t,n)}let a="";for(let r=1;r<e.length-1;r+=1){let s=e[r];if(s!=="\\"){if(s.charCodeAt(0)<32)throw je(t,n);a+=s;continue}if(r+=1,r>=e.length-1)throw je(t,n);let o=e[r];if(o==="u"){let c=e.slice(r+1,r+5);if(c.length!==4||!/^[0-9a-fA-F]{4}$/.test(c))throw je(t,n);a+=String.fromCharCode(Number.parseInt(c,16)),r+=4;continue}let l={"\\":"\\",'"':'"',"'":"'","/":"/",n:`
2
+ `,r:"\r",t:" ",b:"\b",f:"\f"};if(!U(l,o))throw je(t,n);a+=l[o]}return a},Go=(e,t="Computed expression var")=>{if(typeof e!="string"||e.length===0||e.trim()!==e)throw je(e,t);let n=[],i=0,a=()=>{let s=i;for(;i<e.length&&e[i]!=="."&&e[i]!=="["&&e[i]!=="]";)i+=1;let o=e.slice(s,i);if(o.length===0||o.trim()!==o||/\s/.test(o))throw je(e,t);n.push(o)},r=()=>{for(i+=1;i<e.length&&/\s/.test(e[i]);)i+=1;let s=e[i];if(/\d/.test(s??"")){let u=i;for(;i<e.length&&/\d/.test(e[i]);)i+=1;let p=e.slice(u,i);for(;i<e.length&&/\s/.test(e[i]);)i+=1;if(e[i]!=="]"||p.length>1&&p.startsWith("0"))throw je(e,t);i+=1,n.push(p);return}if(s!=='"'&&s!=="'")throw je(e,t);let o=s,l=i;i+=1;let c=!1;for(;i<e.length;){let u=e[i];if(c)c=!1;else if(u==="\\")c=!0;else if(u===o){let p=e.slice(l,i+1);for(i+=1;i<e.length&&/\s/.test(e[i]);)i+=1;if(e[i]!=="]")throw je(e,t);i+=1,n.push(xf(p,e,t));return}i+=1}if(c||i>=e.length)throw je(e,t)};for(a();i<e.length;){if(e[i]==="."){i+=1,a();continue}if(e[i]==="["){r();continue}throw je(e,t)}return n},$s=(e,t)=>{let n=e;for(let i of t){if(n==null||!U(n,i))return;n=n[i]}return n},Xo=(e,t={})=>{if(typeof e!="string"||e.trim()==="")throw new Error("Computed expression var requires a non-empty string path");let n=Go(e),[i,a,...r]=n;if(i==="variables"){if(!a)return t.variables;let s=typeof t.resolveVariable=="function"?t.resolveVariable(a):t.variables?.[a];return $s(s,r)}return i==="runtime"?$s(t.runtime,n.slice(1)):$s(t,n)},Wo=(e,t,n)=>{if(!Array.isArray(t))throw new Error(`Computed expression operator "${e}" requires an array`);if(n!==void 0&&t.length!==n)throw new Error(`Computed expression operator "${e}" requires ${n} operand(s)`)},Ls=(e,t)=>{if(!Array.isArray(t))throw new Error(`Computed expression operator "${e}" requires an array`);if(t.length===0)throw new Error(`Computed expression operator "${e}" requires at least one operand`)},Ef=(e,t)=>{if(typeof t!="number"||!Number.isFinite(t))throw new Error(`Computed expression operator "${e}" requires finite numeric operands`)},Me=(e,t,n,i)=>(Wo(e,t,i),t.map(a=>Xt(a,n))),$e=(e,t,n,i)=>{let a=Me(e,t,n,i);return a.forEach(r=>Ef(e,r)),a},Sf=(e,t,n)=>{switch(e){case"var":return Xo(t,n);case"add":{let[i,a]=$e(e,t,n,2);return i+a}case"sub":{let[i,a]=$e(e,t,n,2);return i-a}case"mul":{let[i,a]=$e(e,t,n,2);return i*a}case"div":{let[i,a]=$e(e,t,n,2);return i/a}case"mod":{let[i,a]=$e(e,t,n,2);return i%a}case"neg":{let[i]=$e(e,t,n,1);return-i}case"round":{let[i]=$e(e,t,n,1);return Math.round(i)}case"floor":{let[i]=$e(e,t,n,1);return Math.floor(i)}case"ceil":{let[i]=$e(e,t,n,1);return Math.ceil(i)}case"min":{let[i,a]=$e(e,t,n,2);return Math.min(i,a)}case"max":{let[i,a]=$e(e,t,n,2);return Math.max(i,a)}case"clamp":{let[i,a,r]=$e(e,t,n,3);return Math.min(r,Math.max(a,i))}case"eq":{let[i,a]=Me(e,t,n,2);return sr.eq(i,a)}case"neq":{let[i,a]=Me(e,t,n,2);return sr.neq(i,a)}case"gt":{let[i,a]=Me(e,t,n,2);return sr.gt(i,a)}case"gte":{let[i,a]=Me(e,t,n,2);return sr.gte(i,a)}case"lt":{let[i,a]=Me(e,t,n,2);return sr.lt(i,a)}case"lte":{let[i,a]=Me(e,t,n,2);return sr.lte(i,a)}case"in":{let[i,a]=Me(e,t,n,2);return Array.isArray(a)?a.includes(i):!1}case"and":case"all":return Ls(e,t),t.every(i=>!!Xt(i,n));case"or":case"any":return Ls(e,t),t.some(i=>!!Xt(i,n));case"not":{let[i]=Me(e,t,n,1);return!i}case"length":{let[i]=Me(e,t,n,1);return typeof i=="string"||Array.isArray(i)?i.length:pe(i)?Object.keys(i).length:0}case"includes":{let[i,a]=Me(e,t,n,2);return typeof i=="string"?typeof a=="string"&&i.includes(a):Array.isArray(i)?i.includes(a):!1}case"literal":return zo(t);default:throw new Error(`Unknown computed expression operator: ${e}`)}},Xt=(e,t={})=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))throw new Error("Computed expression arrays are not valid; use value for literal arrays");let n=Object.entries(e);if(n.length!==1)throw new Error("Computed expression objects must contain exactly one operator");let[[i,a]]=n;return Sf(i,a,t)},Ms=(e,t)=>{if(e===null||typeof e!="object"||U(e,"literal"))return e;if(U(e,"var"))return{literal:Xo(e.var,t)};if(U(e,"call"))throw new Error("Function calls are not supported in computed-variable conditions");return Object.fromEntries(Object.entries(e).map(([n,i])=>[n,Array.isArray(i)?i.map(a=>Ms(a,t)):Ms(i,t)]))},Of=(e,t={})=>{if(typeof e=="string")throw new Error("String condition expressions are not supported; use semantic JSON conditions");return ke(e),it(Ms(e,t))},Ho=(e,t)=>{if(!pe(e))throw new Error(`${t} must be an object`);let n=U(e,"expr"),i=U(e,"value");if(n===i)throw new Error(`${t} must contain exactly one of expr or value`)},js=(e,t,n)=>(Ho(e,t),U(e,"value")?zo(e.value):Xt(e.expr,n)),Rf=(e,t={},n="unknown")=>{if(!pe(e))throw new Error(`Computed variable "${n}" computed must be an object`);let i=U(e,"expr"),a=U(e,"value");if(U(e,"branches")){if(i||a)throw new Error(`Computed variable "${n}" cannot combine branches with expr or value`);if(!Array.isArray(e.branches))throw new Error(`Computed variable "${n}" branches must be an array`);if(e.branches.length===0)throw new Error(`Computed variable "${n}" branches must not be empty`);if(!pe(e.default))throw new Error(`Computed variable "${n}" requires default`);for(let s=0;s<e.branches.length;s+=1){let o=e.branches[s];if(!pe(o))throw new Error(`Computed variable "${n}" branch ${s} must be an object`);if(!U(o,"when"))throw new Error(`Computed variable "${n}" branch ${s} requires when`);if(Of(o.when,t))return js(o,`Computed variable "${n}" branch ${s}`,t)}return js(e.default,`Computed variable "${n}" default`,t)}if(i===a)throw new Error(`Computed variable "${n}" must contain exactly one of expr, value, or branches`);return js(e,`Computed variable "${n}"`,t)},Ko=(e,t,n)=>{switch(t){case"number":if(typeof n!="number"||!Number.isFinite(n))throw new Error(`Computed variable "${e}" expected type number, got ${Array.isArray(n)?"array":typeof n}`);return;case"boolean":if(typeof n!="boolean")throw new Error(`Computed variable "${e}" expected type boolean, got ${Array.isArray(n)?"array":typeof n}`);return;case"string":if(typeof n!="string")throw new Error(`Computed variable "${e}" expected type string, got ${Array.isArray(n)?"array":typeof n}`);return;case"object":if(n===null||typeof n!="object")throw new Error(`Computed variable "${e}" expected type object, got ${typeof n}`);return;default:throw new Error(`Invalid variable type: ${t} for computed variable ${e}`)}},Cf=Object.freeze({add:2,sub:2,mul:2,div:2,mod:2,neg:1,round:1,floor:1,ceil:1,min:2,max:2,clamp:3,eq:2,neq:2,gt:2,gte:2,lt:2,lte:2,in:2,not:1,length:1,includes:2}),_f=new Set(["and","or","all","any"]),$f=new Set(["add","sub","mul","div","mod","neg","round","floor","ceil","min","max","clamp","length"]),jf=new Set(["add","sub","mul","div","mod","neg","round","floor","ceil","min","max","clamp"]),Nf=new Set(["eq","neq","gt","gte","lt","lte","in","and","or","all","any","not","includes"]),Df=new Set(["all","any","eq","neq","gt","gte","lt","lte","in","add","sub"]),Jo=new WeakMap,Mo=e=>e===null?"null":Array.isArray(e)?"object":typeof e,zt=(e,t,n)=>{for(let i of Object.keys(e))if(!t.has(i))throw new Error(`${n} contains unsupported property "${i}"`)},Tf=(e,t,n,i)=>{if(n!==void 0&&n!==t)throw new Error(`Computed variable "${e}" ${i} expected type ${t}, got ${n}`)},Qo=(e,{variableId:t,variableConfigs:n,dependencies:i,path:a})=>{let r=`Computed variable "${t}" ${a} var`,[s,o,...l]=Go(e,r);if(s!=="variables"&&s!=="runtime")throw new Error(`${r} must reference variables.* or runtime.*, got ${JSON.stringify(e)}`);if(!o)throw new Error(`${r} must reference a concrete ${s} member, got ${JSON.stringify(e)}`);if(s==="runtime")return;if(!U(n,o))throw new Error(`Computed variable "${t}" ${a} references unknown variable "${o}"`);let c=n[o];return Ne(c)&&i.add(o),l.length===0?c?.type:void 0},Zo=(e,{variableId:t,variableConfigs:n,dependencies:i,path:a})=>{if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new Error(`Computed variable "${t}" ${a} must use finite numeric literals`);return Mo(e)}if(Array.isArray(e))throw new Error("Computed expression arrays are not valid; use value for literal arrays");let r=Object.entries(e);if(r.length!==1)throw new Error("Computed expression objects must contain exactly one operator");let[[s,o]]=r;if(s==="var"){if(typeof o!="string"||o.trim()==="")throw new Error("Computed expression var requires a non-empty string path");return Qo(o,{variableId:t,variableConfigs:n,dependencies:i,path:a})}if(s==="literal"){if(typeof o=="number"&&!Number.isFinite(o))throw new Error(`Computed variable "${t}" ${a} must use finite numeric literals`);return Mo(o)}let l=Cf[s];if(l===void 0&&!_f.has(s))throw new Error(`Unknown computed expression operator: ${s}`);l===void 0?Ls(s,o):Wo(s,o,l);let c=o.map((u,p)=>Zo(u,{variableId:t,variableConfigs:n,dependencies:i,path:`${a}.${s}[${p}]`}));if(jf.has(s)&&c.forEach(u=>{if(u!==void 0&&u!=="number")throw new Error(`Computed expression operator "${s}" requires numeric operands`)}),$f.has(s))return"number";if(Nf.has(s))return"boolean"},Lf=(e,{variableId:t,variableConfigs:n,dependencies:i,path:a})=>{if(typeof e=="string")throw new Error("String condition expressions are not supported; use semantic JSON conditions");try{ke(e)}catch(s){throw new Error(`Computed variable "${t}" ${a} is invalid: ${s.message}`,{cause:s})}let r=(s,o)=>{if(s===null||typeof s!="object"||U(s,"literal"))return;if(U(s,"var")){Qo(s.var,{variableId:t,variableConfigs:n,dependencies:i,path:o});return}if(U(s,"call"))throw new Error(`Computed variable "${t}" ${o} function calls are not supported`);if(U(s,"not")){r(s.not,`${o}.not`);return}let l=Object.keys(s).find(c=>Df.has(c));s[l].forEach((c,u)=>{r(c,`${o}.${l}[${u}]`)})};r(e,a)},Ns=(e,{variableId:t,variableConfig:n,variableConfigs:i,dependencies:a,path:r,allowedKeys:s=new Set(["expr","value"])})=>{if(Ho(e,`Computed variable "${t}" ${r}`),zt(e,s,r),U(e,"value")){Ko(t,n.type,e.value);return}let o=Zo(e.expr,{variableId:t,variableConfigs:i,dependencies:a,path:`${r}.expr`});Tf(t,n.type,o,`${r}.expr`)},Mf=(e,t,n)=>{let i=t.computed;if(!pe(i))throw new Error(`Computed variable "${e}" computed must be an object`);let a=new Set,r=U(i,"expr"),s=U(i,"value");if(U(i,"branches")){if(zt(i,new Set(["branches","default"]),`Computed variable "${e}" computed`),r||s)throw new Error(`Computed variable "${e}" cannot combine branches with expr or value`);if(!Array.isArray(i.branches))throw new Error(`Computed variable "${e}" branches must be an array`);if(i.branches.length===0)throw new Error(`Computed variable "${e}" branches must not be empty`);if(!pe(i.default))throw new Error(`Computed variable "${e}" requires default`);return i.branches.forEach((l,c)=>{if(!pe(l))throw new Error(`Computed variable "${e}" branch ${c} must be an object`);if(zt(l,new Set(["when","expr","value"]),`Computed variable "${e}" branch ${c}`),!U(l,"when"))throw new Error(`Computed variable "${e}" branch ${c} requires when`);Lf(l.when,{variableId:e,variableConfigs:n,dependencies:a,path:`computed.branches[${c}].when`}),Ns(l,{variableId:e,variableConfig:t,variableConfigs:n,dependencies:a,path:`computed.branches[${c}]`,allowedKeys:new Set(["when","expr","value"])})}),Ns(i.default,{variableId:e,variableConfig:t,variableConfigs:n,dependencies:a,path:"computed.default"}),a}if(zt(i,new Set(["expr","value"]),`Computed variable "${e}" computed`),r===s)throw new Error(`Computed variable "${e}" must contain exactly one of expr, value, or branches`);return Ns(i,{variableId:e,variableConfig:t,variableConfigs:n,dependencies:a,path:"computed"}),a},gr=(e={})=>{if(!pe(e))throw new Error("Variable configs must be an object");if(U(e,"__proto__"))throw new Error('Variable id "__proto__" is reserved');if(U(e,""))throw new Error("Variable ids must not be empty");let t=new Map;Object.entries(e).forEach(([r,s])=>{if(Ne(s)){if(!pe(s))throw new Error(`Computed variable "${r}" must be an object`);if(!U(s,"type"))throw new Error(`Computed variable "${r}" requires type`);if(!U(s,"scope"))throw new Error(`Computed variable "${r}" requires scope`);if(U(s,"default"))throw new Error(`Computed variable "${r}" must not declare a top-level default`);if(ut(s.scope,r),!["number","boolean","string","object"].includes(s.type))throw new Error(`Invalid variable type: ${s.type} for computed variable ${r}`);t.set(r,Mf(r,s,e))}});let n=new Set,i=[];t.forEach((r,s)=>{if(n.has(s))return;let o=[{variableId:s,dependencies:[...t.get(s)??[]],nextDependencyIndex:0}],l=new Map([[s,0]]);for(;o.length>0;){let c=o.at(-1);if(c.nextDependencyIndex>=c.dependencies.length){o.pop(),l.delete(c.variableId),n.add(c.variableId),i.push(c.variableId);continue}let u=c.dependencies[c.nextDependencyIndex];if(c.nextDependencyIndex+=1,n.has(u))continue;let p=l.get(u);if(p!==void 0){let m=[...o.slice(p).map(({variableId:d})=>d),u].join(" -> ");throw new Error(`Computed variable cycle detected: ${m}`)}l.set(u,o.length),o.push({variableId:u,dependencies:[...t.get(u)??[]],nextDependencyIndex:0})}});let a=Object.freeze({evaluationOrder:Object.freeze(i)});return Jo.set(e,a),a},ct=({variables:e={},runtime:t={},variableConfigs:n={},eager:i=!0}={})=>{let{evaluationOrder:a}=Jo.get(n)??gr(n),r=Tr(e,n),s=Object.entries(n).filter(([,g])=>Ne(g)).map(([g])=>g),o=Object.create(null),l=[],c=new Map(a.map((g,h)=>[g,h])),u=-1,p=!1,m=g=>{if(U(o,g))return o[g];let h=n[g];if(!Ne(h))return U(r,g)?r[g]:void 0;let w=l.indexOf(g);if(w>=0){let b=[...l.slice(w),g].join(" -> ");throw new Error(`Computed variable cycle detected: ${b}`)}l.push(g);try{let b=Rf(h.computed,y,g);return Ko(g,h.type,b),Ts(o,g,b),b}finally{l.pop()}},d=g=>{if(U(o,g))return o[g];let h=n[g];if(!Ne(h))return U(r,g)?r[g]:void 0;let w=c.get(g);if(i&&!p&&w!==void 0&&w>u){p=!0;try{for(let b=u+1;b<=w;b+=1)m(a[b]),u=b}finally{p=!1}return o[g]}return m(g)},f=new Proxy({},{get:(g,h)=>{if(typeof h=="string")return d(h)},has:(g,h)=>typeof h=="string"&&(U(r,h)||s.includes(h)),ownKeys:()=>[...new Set([...Object.keys(r),...s])],getOwnPropertyDescriptor:(g,h)=>{if(!(typeof h!="string"||!U(r,h)&&!s.includes(h)))return{enumerable:!0,configurable:!0}}}),y={variables:f,runtime:t,resolveVariable:d};return i?(s.forEach(g=>{d(g)}),{...r,...o}):f},qf=({variables:e={},runtime:t={},variableConfigs:n,projectData:i}={})=>{let a=n??i?.resources?.variables??{};return gr(a),ct({variables:e,runtime:t,variableConfigs:a,eager:!0})},Kt=e=>{let t={},n={};return e.resources?.variables?(Object.entries(e.resources.variables).forEach(([i,a])=>{if(Ne(a))return;let r=yf(a,i);a.scope==="context"?Ts(t,i,r):Ts(n,i,r)}),{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}):{contextVariableDefaultValues:t,globalVariablesDefaultValues:n}},ut=(e,t)=>{let n=["context","device","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(", ")}`)},Jt=(e,t,n)=>{let i={number:["set","increment","decrement","multiply","divide"],boolean:["set","toggle"],string:["set"],object:["set"]},a=i[e];if(!a)throw new Error(`Unknown variable type: ${e} for variable ${n}`);if(!Object.values(i).flat().includes(t))throw new Error(`Unknown operation: ${t}`);if(!a.includes(t))throw new Error(`Operation "${t}" is not valid for variable "${n}" of type "${e}". Valid operations: ${a.join(", ")}`)},Vf=2,qo=12,ea=(e=Vf)=>{if(!Number.isInteger(e)||e<0||e>qo)throw new Error(`Operation "divide" requires roundTo to be an integer between 0 and ${qo}.`);return e},Ff=(e,t)=>{let n=10**t;return Math.round((e+Number.EPSILON)*n)/n},Gt=e=>typeof e=="number"&&Number.isFinite(e),Fs=(e,t,n,i,a={})=>{if(e==="number"){if(t==="set"&&!Gt(n))throw new Error(`Operation "set" requires value to be a number for variable "${i}".`);if(t==="multiply"&&!Gt(n))throw new Error(`Operation "multiply" requires value to be a number for variable "${i}".`);if(t==="divide"&&!Gt(n))throw new Error(`Operation "divide" requires value to be a number for variable "${i}".`);if(t==="divide"){if(n===0)throw new Error(`Operation "divide" requires value to be a non-zero number for variable "${i}".`);ea(a.roundTo)}}},Qt=(e,t,n,i={})=>{let a=(s,o,l)=>{let c=s??o;if(!Gt(c))throw new Error(`Operation "${t}" requires ${l} to be a number.`);return c},r=s=>{let o=a(s,void 0,"value");if(o===0)throw new Error(`Operation "${t}" requires value to be a non-zero number.`);return o};switch(t){case"set":return n;case"multiply":return a(e,1,"current value")*a(n,void 0,"value");case"divide":return Ff(a(e,0,"current value")/r(n),ea(i.roundTo));case"increment":return a(e,0,"current value")+a(n,1,"value");case"decrement":return a(e,0,"current value")-a(n,1,"value");case"toggle":return!e;default:throw new Error(`Unknown operation: ${t}`)}};var Us=(e,t="DD/MM/YYYY - HH:mm")=>{if(!e)return"";let n=new Date(e),i=s=>String(s).padStart(2,"0"),a=String(n.getFullYear()),r={DD:i(n.getDate()),MM:i(n.getMonth()+1),MMM:mf[n.getMonth()],YYYY:a,YY:a.slice(-2),HH:i(n.getHours()),mm:i(n.getMinutes()),ss:i(n.getSeconds())};return t.replace(/YYYY|MMM|YY|MM|DD|HH|mm|ss/g,s=>r[s])},Uf=(e,t)=>{let n=r=>r?.ui,i=n(e),a=n(t);return JSON.stringify(i)===JSON.stringify(a)?null:i&&!a?{changeType:"delete",data:e}:a&&!i?{changeType:"add",data:t}:a&&i?{changeType:"update",data:t}:null},st=e=>!!e?.transformId&&Array.isArray(e.items)&&e.items.length>0,Bf=(e,t)=>{let n=e?.character?.sprite,i=t?.character?.sprite,a=st(n)?n:void 0,r=st(i)?i:void 0;return JSON.stringify(a)===JSON.stringify(r)?null:a&&!r?{changeType:"delete",data:a}:r&&!a?{changeType:"add",data:r}:r&&a?{changeType:"update",data:r}:null},Vo=e=>{if(e?.resourceId===void 0)return;let t={resourceId:e.resourceId};e.transformId!==void 0&&(t.transformId=e.transformId);for(let n of["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"])e[n]!==void 0&&(t[n]=e[n]);for(let n of["animationName","animationSpeed","loop"])e[n]!==void 0&&(t[n]=e[n]);return t},Fo=e=>{if(e?.colorId!==void 0)return{colorId:e.colorId}},Uo=(e,t)=>t&&!e?{changeType:"add",data:t}:e&&!t?{changeType:"delete",data:e}:e&&t&&JSON.stringify(e)!==JSON.stringify(t)?{changeType:"update",data:t}:null,Yf=(e,t)=>{let n={},i=Uo(Vo(e),Vo(t)),a=Uo(Fo(e),Fo(t));return i&&(n.resource=i),a&&(n.color=a),Object.keys(n).length>0?n:null},Bs=(e={},t={})=>{let n={},i=["sfx","voice"],a=l=>{let c=e[l],u=t[l];u&&!c?n[l]={changeType:"add",data:u}:c&&!u?i.includes(l)||(n[l]={changeType:"delete",data:c}):c&&u&&JSON.stringify(c)!==JSON.stringify(u)&&(n[l]={changeType:"update",data:u})},r=Yf(e.background,t.background);r&&(n.background=r),a("screen"),a("bgm"),a("voice");let s=Uf(e.dialogue,t.dialogue);s&&(n.dialogue=s);let o=Bf(e.dialogue,t.dialogue);return o&&(n.dialogueSprite=o),a("choice"),a("form"),a("layout"),a("animation"),a("control"),a("character"),a("visual"),a("sfx"),n},Ys=(e={})=>{let t=structuredClone(e);t.background&&(t.background.animations?.playback?.continuity!=="persistent"&&delete t.background.animations,!t.background.resourceId&&!t.background.colorId&&delete t.background);let n=a=>{t[a]&&(delete t[a].animations,Object.keys(t[a]).length===0&&delete t[a])};n("layout"),n("choice"),n("form"),n("screen"),t.dialogue?.ui&&(delete t.dialogue.ui.animations,Object.keys(t.dialogue.ui).length===0&&delete t.dialogue.ui,Object.keys(t.dialogue).length===0&&delete t.dialogue),t.dialogue?.character?.sprite&&(delete t.dialogue.character.sprite.animations,Object.keys(t.dialogue.character.sprite).length===0&&delete t.dialogue.character.sprite,Object.keys(t.dialogue.character).length===0&&delete t.dialogue.character,Object.keys(t.dialogue).length===0&&delete t.dialogue);let i=(a,r)=>{let s=t[a]?.items;Array.isArray(s)&&(t[a].items=s.map(o=>{let l={...o};return delete l.animations,r(l)?l:null}).filter(Boolean),t[a].items.length===0&&delete t[a])};return i("character",a=>a.sprites&&a.sprites.length>0||a.transformId||a.resourceId),i("visual",a=>a.resourceId||a.transformId),t},zf=(e,t)=>{if(!e||!t)return;let n=e;for(let i of t.split(".")){if(n==null||!(i in Object(n)))return;n=n[i]}return n},Gf=(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),i=zf(t,n);if(i===void 0)throw new Error(`Action template binding "${e}" could not be resolved from "_event".`);return i},Xf={conditional:new Set(["branches"]),updateProjectData:new Set(["projectData"]),showConfirmDialog:new Set(["confirmActions","cancelActions"]),form:new Set(["submitActions","cancelActions"]),submitForm:new Set(["actions"]),cancelForm:new Set(["actions"])},Wf=(e,t)=>{let n=e[e.length-1];return n?Xf[n]?.has(t)===!0:!1},qs=(e,t,n=[])=>Array.isArray(e)?e.map(i=>qs(i,t,n)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([i,a])=>[i,Wf(n,i)?a:qs(a,t,[...n,i])])):typeof e=="string"?e==="_event"||e.startsWith("_event.")?Gf(e,t._event):yr(e,t):e,zs=(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".');return qs(e,t)};var re=e=>structuredClone(ye(e)?er(e):e),H=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ra=e=>e?.animations?.playback?.continuity==="persistent",W=(e,t)=>H(e??{},t)&&e[t]!==void 0,pt=(e,t)=>e?!t(e)&&e.animations?{animationsOnly:!0,state:{animations:re(e.animations)}}:{animationsOnly:!1,state:null}:{animationsOnly:!1,state:null},Hf=e=>W(e,"opacity")||W(e,"blur"),aa=["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"],la=["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"],Gs=["animationName","animationSpeed","loop"],Kf=e=>aa.some(t=>W(e,t)),ca=e=>e?.text&&W(e.text,"content")&&W(e.text,"textStyleId"),ua=e=>W(e,"text"),Jf=(e,t)=>e.resourceId?!0:ca(e)?!t?.text:!1,Qf=(e,t)=>{let n={...re(e),...t};return t.text&&e.text&&(n.text={...re(e.text),...re(t.text)}),n},Zf=(e,t)=>{if(ua(e)){if(e.resourceId)throw new Error(`Visual item "${e.id}" cannot define both resourceId and text`);if(!ca(e)&&!t?.text)throw new Error(`Visual item "${e.id}" text requires content and textStyleId`)}},ta=e=>la.some(t=>W(e,t)),na=e=>Gs.some(t=>W(e,t)),ed=(e,t,{hasAuthoredTransformId:n=!1}={})=>{if(!t)return e;for(let i of la)!n&&!W(e,i)&&W(t,i)&&(e[i]=t[i]),H(e,i)&&e[i]===void 0&&delete e[i];return e},pa=(e,t,n)=>{let i=e[n];return i?.id===t?.id?i:e.find(a=>a.id===t?.id)},rd=(e,t)=>{if(!t)return e;for(let n of aa)!W(e,n)&&W(t,n)&&(e[n]=t[n]),H(e,n)&&e[n]===void 0&&delete e[n];return e},td=(e,t)=>(t&&(!W(e,"opacity")&&W(t,"opacity")&&(e.opacity=t.opacity),!W(e,"blur")&&W(t,"blur")&&(e.blur=re(t.blur)),H(e,"opacity")&&e.opacity===void 0&&delete e.opacity,H(e,"blur")&&e.blur===void 0&&delete e.blur),e),fa=(e,t,n=[],{hasPatchFn:i=()=>!1,mergeItemFn:a}={})=>{if(!e||e.length===0)return{hasValidItems:!1,processedItems:[]};let r=e.map((s,o)=>{let l=pa(n,s,o),c=t(s,l),u=Hf(s),p=Kf(s),m=i(s),d=H(s,"animations"),f=re(s);return!c&&(u||p||m)&&l&&(f=a?a(l,f):{...re(l),...f},d||delete f.animations),td(rd(f,l),l)}).filter(s=>t(s)||s.animations);return{hasValidItems:r.length>0,processedItems:r}},nd=e=>{if(e){if(e.character&&H(e.character,"name"))return e.character.name;if(H(e,"characterName"))return e.characterName}},da=e=>!!e?.character&&H(e.character,"sprite"),sd=e=>{let t={},n=!1,i=nd(e);return i!==void 0&&(t.name=i,n=!0),da(e)&&(t.sprite=re(e.character.sprite),n=!0),n?t:void 0},sa=e=>{e?.character?.sprite?.animations&&(e.character.sprite.animations={})},ia=({dialogueState:e,dialogueAction:t,persistCharacter:n})=>H(t,"persistSprite")?t.persistSprite===!0:H(e,"persistSprite")?e.persistSprite===!0:n&&!H(t,"characterId"),oa=({previousCharacter:e,characterFields:t,hasCharacterId:n,persistCharacter:i,persistSprite:a,hasExplicitPersistSprite:r,isAppendingAdvDialogueContent:s})=>{let o={},l=e??{},c=t??{},u=s&&!n,p=u&&!r;return H(c,"name")?o.name=c.name:(i&&!n||u)&&H(l,"name")&&(o.name=re(l.name)),H(c,"sprite")?o.sprite=re(c.sprite):(a||p)&&H(l,"sprite")&&(o.sprite=re(l.sprite)),Object.keys(o).length>0?o:void 0},id=({dialogueState:e,content:t,append:n=!1})=>{if(!n||!Array.isArray(t)){e.content=t,delete e.initialRevealedContent;return}let i=Array.isArray(e.content)?e.content:[];i.length>0?e.initialRevealedContent=i.map(a=>re(a)):delete e.initialRevealedContent,e.content=[...i,...t]},od=()=>({}),ad=(e,t)=>{if(!t.screen)return;let n=W(t.screen,"opacity"),i=W(t.screen,"blur"),a=H(t.screen,"animations");if(!n&&!i){a||delete e.screen;return}let r=e.screen,s={};if(n?s.opacity=t.screen.opacity:W(r,"opacity")&&(s.opacity=r.opacity),i?s.blur=re(t.screen.blur):W(r,"blur")&&(s.blur=re(r.blur)),H(s,"opacity")&&s.opacity===void 0&&delete s.opacity,H(s,"blur")&&s.blur===void 0&&delete s.blur,Object.keys(s).length===0){delete e.screen;return}e.screen=s},ld=(e,t)=>{if(t.background){let n=W(t.background,"resourceId"),i=W(t.background,"colorId"),a=W(t.background,"opacity"),r=W(t.background,"blur"),s=W(t.background,"transformId"),o=ta(t.background),l=na(t.background),{animationsOnly:c,state:u}=pt(t.background,d=>W(d,"resourceId")||W(d,"colorId")||W(d,"opacity")||W(d,"blur")||W(d,"transformId")||ta(d)||na(d));if(c){e.background=e.background?{...re(e.background),...u}:u;return}if(!n&&!i&&!a&&!r&&!s&&!o&&!l){delete e.background;return}let p=e.background,m=re(t.background);if(!n&&p?.resourceId){m.resourceId=p.resourceId,!H(m,"transformId")&&p.transformId&&(m.transformId=p.transformId);for(let d of Gs)!W(m,d)&&W(p,d)&&(m[d]=p[d])}ed(m,p,{hasAuthoredTransformId:s}),!i&&p?.colorId&&(m.colorId=p.colorId),!a&&W(p,"opacity")&&(m.opacity=p.opacity),!r&&W(p,"blur")&&(m.blur=re(p.blur)),H(m,"resourceId")&&m.resourceId===void 0&&delete m.resourceId,H(m,"colorId")&&m.colorId===void 0&&delete m.colorId,H(m,"animations")&&m.animations===void 0&&delete m.animations,H(m,"transformId")&&m.transformId===void 0&&delete m.transformId,H(m,"opacity")&&m.opacity===void 0&&delete m.opacity,H(m,"blur")&&m.blur===void 0&&delete m.blur;for(let d of Gs)H(m,d)&&m[d]===void 0&&delete m[d];if(!m.resourceId&&!m.colorId){delete e.background;return}p?.resourceId===m.resourceId&&p?.transformId===m.transformId&&!H(m,"animations")&&ra(p)&&(m.animations=re(p.animations)),e.background=m}else e.background?.animations&&!ra(e.background)&&(e.background.animations={})},cd=(e,t)=>{if(!t.dialogue){if(e.dialogue&&(sa(e.dialogue),e.dialogue.mode==="adv")){e.dialogue.content=void 0,delete e.dialogue.initialRevealedContent,delete e.dialogue.textSpeed;let u=e.dialogue.persistCharacter===!0,p=ia({dialogueState:e.dialogue,dialogueAction:{},persistCharacter:u});u||delete e.dialogue.characterId,e.dialogue.character=oa({previousCharacter:e.dialogue.character,characterFields:{},hasCharacterId:!1,persistCharacter:u,persistSprite:p,hasExplicitPersistSprite:!1,isAppendingAdvDialogueContent:!1}),e.dialogue.character||delete e.dialogue.character}return}e.dialogue||(e.dialogue={});let n=e.dialogue.mode;if(t.dialogue.ui){let{animationsOnly:u,state:p}=pt(t.dialogue.ui,m=>!!m.resourceId);u?e.dialogue.ui={...e.dialogue.ui,...p}:e.dialogue.ui={...t.dialogue.ui}}else e.dialogue?.ui?.animations&&(e.dialogue.ui.animations={});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");let i=t.dialogue.append===!0&&n!=="nvl"&&e.dialogue?.mode!=="nvl"&&Array.isArray(t.dialogue.content);t.dialogue.content!==void 0&&id({dialogueState:e.dialogue,content:t.dialogue.content,append:i}),H(t.dialogue,"textSpeed")?e.dialogue.textSpeed=t.dialogue.textSpeed:delete e.dialogue.textSpeed;let a=H(t.dialogue,"persistCharacter")?t.dialogue.persistCharacter===!0:e.dialogue.persistCharacter===!0;a?e.dialogue.persistCharacter=!0:delete e.dialogue.persistCharacter;let r=ia({dialogueState:e.dialogue,dialogueAction:t.dialogue,persistCharacter:a});H(t.dialogue,"persistSprite")&&(e.dialogue.persistSprite=r);let s=H(t.dialogue,"characterId"),o=sd(t.dialogue),l=da(t.dialogue);s?t.dialogue.characterId?e.dialogue.characterId=t.dialogue.characterId:delete e.dialogue.characterId:!a&&!i&&delete e.dialogue.characterId;let c=oa({previousCharacter:e.dialogue.character,characterFields:o,hasCharacterId:s,persistCharacter:a,persistSprite:r,hasExplicitPersistSprite:H(t.dialogue,"persistSprite"),isAppendingAdvDialogueContent:i});if(c?e.dialogue.character=c:delete e.dialogue.character,l||sa(e.dialogue),t.dialogue.clear){delete e.dialogue;return}if(t.dialogue?.clearPage&&e.dialogue?.mode==="nvl"&&(e.dialogue.lines=[]),e.dialogue?.mode==="nvl"&&t.dialogue.content!==void 0){let u={content:t.dialogue.content,characterId:e.dialogue.characterId??null};e.dialogue.textSpeed!==void 0&&(u.textSpeed=e.dialogue.textSpeed),e.dialogue.character&&(u.character=re(e.dialogue.character)),e.dialogue.lines.push(u)}},ud=(e,t)=>{if(t.sfx){let n=Array.isArray(t.sfx.items)&&t.sfx.items.length>0,i=Array.isArray(t.sfx.channels)&&t.sfx.channels.length>0;if(!n&&!i){delete e.sfx;return}e.sfx=re(t.sfx)}else e.sfx&&delete e.sfx},pd=(e,t)=>{if(t.bgm){let n=Array.isArray(t.bgm.sounds);if(!t.bgm.resourceId&&!n||n&&t.bgm.sounds.length===0){e.bgm=void 0;return}e.bgm=re(t.bgm),t.bgm.resourceId&&(e.bgm.loop=t.bgm.loop??!0)}},fd=(e,t)=>{if(t.visual){let n=e.visual?.items||[];t.visual.items?.forEach((r,s)=>{Zf(r,pa(n,r,s))});let{hasValidItems:i,processedItems:a}=fa(t.visual.items,Jf,n,{hasPatchFn:ua,mergeItemFn:Qf});i?e.visual={items:a}:delete e.visual}else e.visual?.items&&(e.visual.items=e.visual.items.map(n=>n.animations?{...n,animations:{}}:n))},dd=(e,t)=>{if(!t.character){e.character?.items&&(e.character.items=e.character.items.map(a=>a.animations?{...a,animations:{}}:a));return}let{hasValidItems:n,processedItems:i}=fa(t.character.items,a=>a.sprites&&a.sprites.length>0||a.transformId||a.resourceId,e.character?.items||[]);n?e.character={items:i}:delete e.character},md=(e,t)=>{t.animation?e.animation=t.animation:e.animation&&delete e.animation},yd=(e,t)=>{if(t.layout){let{animationsOnly:n,state:i}=pt(t.layout,a=>!!a.resourceId);if(n){e.layout=i;return}if(!t.layout.resourceId){delete e.layout;return}e.layout=t.layout}else e.layout&&delete e.layout},hd=(e,t)=>{if(t.choice){let{animationsOnly:n,state:i}=pt(t.choice,a=>!!a.resourceId);if(n){e.choice={...e.choice,...i};return}if(!t.choice.resourceId){delete e.choice;return}e.choice=t.choice}else e.choice&&delete e.choice},gd=(e,t)=>{if(t.form){let{animationsOnly:n,state:i}=pt(t.form,a=>!!a.resourceId);if(n){e.form={...e.form,...i};return}if(!t.form.resourceId){delete e.form;return}e.form=re(t.form)}else e.form&&delete e.form},bd=(e,t)=>{if(t.control){if(!t.control.resourceId){delete e.control;return}e.control=t.control}},wd=(e,t)=>{if(t.voice){let n=Array.isArray(t.voice.sounds);if(!t.voice.resourceId&&!n||n&&t.voice.sounds.length===0){delete e.voice;return}e.voice=re(t.voice)}else e.voice&&delete e.voice},Id=(e,t)=>{t.cleanAll&&Object.keys(e).forEach(n=>{delete e[n]})},br=e=>Wt(od,[Id,ad,ld,ud,pd,fd,cd,dd,md,yd,hd,gd,bd,wd])(e);var Lr=(e,t)=>{if(!e||typeof e!="string"||!e.includes("${"))return e;let n=yr(e,t);return n&&typeof n=="object"?e:n};var vd=Object.freeze({dialogueTextSpeed:{source:"global.dialogueTextSpeed"},autoForwardDelay:{source:"global.autoForwardDelay"},autoForwardSpeed:{source:"global.autoForwardSpeed"},skipUnseenText:{source:"global.skipUnseenText"},skipTransitionsAndAnimations:{source:"global.skipTransitionsAndAnimations"},soundVolume:{source:"global.soundVolume"},musicVolume:{source:"global.musicVolume"},muteAll:{source:"global.muteAll"},localizationPackageId:{source:"global.localizationPackageId"},saveLoadPagination:{source:"context.runtime.saveLoadPagination"},menuPage:{source:"context.runtime.menuPage"},menuEntryPoint:{source:"context.runtime.menuEntryPoint"},autoMode:{source:"global.autoMode"},skipMode:{source:"global.skipMode"},dialogueUIHidden:{source:"global.dialogueUIHidden"},isLineCompleted:{source:"global.isLineCompleted"}}),wr=Object.freeze({dialogueTextSpeed:50,autoForwardDelay:1e3,autoForwardSpeed:50,skipUnseenText:!1,skipTransitionsAndAnimations:!1,soundVolume:50,musicVolume:50,muteAll:!1,localizationPackageId:null,autoMode:!1,skipMode:!1,dialogueUIHidden:!1,isLineCompleted:!1}),ft=Object.freeze({saveLoadPagination:1,menuPage:"",menuEntryPoint:""}),ma=Object.freeze({dialogueTextSpeed:"number",autoForwardDelay:"number",autoForwardSpeed:"number",skipUnseenText:"boolean",skipTransitionsAndAnimations:"boolean",soundVolume:"number",musicVolume:"number",muteAll:"boolean",localizationPackageId:"nullableString",saveLoadPagination:"number",menuPage:"string",menuEntryPoint:"string",autoMode:"boolean",skipMode:"boolean",dialogueUIHidden:"boolean",isLineCompleted:"boolean"}),Xs=Object.freeze(["dialogueTextSpeed","autoForwardDelay","autoForwardSpeed","skipUnseenText","skipTransitionsAndAnimations","soundVolume","musicVolume","muteAll","localizationPackageId"]),Ws=Object.freeze(["saveLoadPagination","menuPage","menuEntryPoint"]),Ad=(e,t)=>{if(t.startsWith("global.")){let n=t.slice(7);return e?.global?.[n]}if(t.startsWith("context.runtime.")){let n=t.slice(16),i=Array.isArray(e?.contexts)?e.contexts:[];return i[i.length-1]?.runtime?.[n]}},Ir=e=>Object.fromEntries(Object.entries(vd).map(([t,n])=>{let i=Ad(e,n.source),a=i!==void 0?i:wr[t]??ft[t];return[t,a]})),ir=(e,t)=>Ir(e)[t],ya=(e={})=>Object.fromEntries(Xs.map(t=>[t,e[t]??wr[t]]));var Mr=Object.freeze({VISUAL_BEHIND_BACKGROUND:10,BACKGROUND:20,VISUAL_BEHIND_CHARACTER:30,CHARACTER:40,VISUAL_BEHIND_DIALOGUE:50,DIALOGUE:60,VISUAL_BEHIND_CHOICE:70,CHOICE:80,VISUAL_FOREGROUND:90}),Xe=Object.freeze({BEHIND_BACKGROUND:Mr.VISUAL_BEHIND_BACKGROUND,BEHIND_CHARACTER:Mr.VISUAL_BEHIND_CHARACTER,BEHIND_DIALOGUE:Mr.VISUAL_BEHIND_DIALOGUE,BEHIND_CHOICE:Mr.VISUAL_BEHIND_CHOICE,FOREGROUND:Mr.VISUAL_FOREGROUND}),Hs=Xe.BEHIND_DIALOGUE,Ks=Object.freeze(Object.values(Xe).sort((e,t)=>e-t));var kd={__arrayOrEmpty:e=>Array.isArray(e)?e:[],objectValues:e=>Object.entries(e).map(([t,n])=>({id:t,...n})),formatDate:Us},Pd=/^\$for\s+([A-Za-z_][A-Za-z0-9_]*)(?:\s*,\s*([A-Za-z_][A-Za-z0-9_]*))?\s+in\s+(.+?)(?::)?$/,dt=e=>Array.isArray(e)?e.map(t=>{if(!t||typeof t!="object"||Array.isArray(t)||Object.keys(t).length!==1)return dt(t);let[n]=Object.keys(t),i=Pd.exec(n);if(!i)return dt(t);let[,a,r,s]=i,o=`$for ${a}${r?`, ${r}`:""} in __arrayOrEmpty(${s.trim()})`,l=Array.isArray(t[n])?t[n]:[];return{[o]:dt(l)}}):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).map(([t,n])=>[t,dt(n)])),He=(e,t)=>{let n={functions:kd};return yr(dt(e),t,n)},di=({animationType:e,animationId:t,animationPath:n})=>{if(e!==void 0&&!(e==="update"||e==="transition"))throw new Error(`[${n}] Animation "${t}" has unsupported type "${e}". Use "update" or "transition".`)},xd=({id:e,targetId:t,animation:n,playback:i,animationPath:a="animation"})=>{let r=structuredClone(n);if(di({animationType:r.type,animationId:e,animationPath:a}),delete r.name,delete r.playback,r.id=e,r.targetId=t,i!==void 0){let s=Rd(i,`${a}.playback`);if(s!==void 0){let o=s.loop===!0?_a(r):null;if(s.loop===!0&&r.type!=="update")throw new Error(`[${a}.playback] playback.loop is only supported for type "update".`);if(s.loop===!0&&r.complete!==void 0)throw new Error(`[${a}.playback] animation.complete is not allowed when playback.loop is true because a loop never completes.`);if(s.loop===!0&&(!Number.isFinite(o)||o<=0))throw new Error(`[${a}.playback] playback.loop requires an animation with a finite duration greater than 0.`);r.playback=s}}return r},Ed=(e,{animationId:t="animation",animationPath:n="animation"}={})=>{if(!(!e||typeof e!="object"||Array.isArray(e))&&typeof e.type=="string")return di({animationType:e.type,animationId:t,animationPath:n}),e.type},Sd=e=>{if(typeof e=="string")return e;if(!(!e||typeof e!="object"||Array.isArray(e)))return e.resourceId},Od=e=>{if(!(!e||typeof e!="object"||Array.isArray(e)))return e.playback},Rd=(e,t="animation.playback")=>{if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`[${t}] playback must be an object.`);if(e.continuity!==void 0&&e.continuity!=="render"&&e.continuity!=="persistent")throw new Error(`[${t}] playback.continuity must be "render" or "persistent".`);if(e.speed!==void 0&&(typeof e.speed!="number"||!Number.isFinite(e.speed)||e.speed<=0))throw new Error(`[${t}] playback.speed must be a finite number greater than 0.`);if(e.loop!==void 0&&typeof e.loop!="boolean")throw new Error(`[${t}] playback.loop must be a boolean.`);let n={};return e.continuity!==void 0&&(n.continuity=e.continuity),e.speed!==void 0&&e.speed!==1&&(n.speed=e.speed),e.loop===!0&&(n.loop=!0),Object.keys(n).length>0?n:void 0},Cd=e=>{let t=e?.playback?.speed;return typeof t=="number"&&Number.isFinite(t)&&t>0?t:1},vr=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Oa=e=>e?.playback?.continuity==="persistent",si=e=>Array.isArray(e)?e.map(si):!e||typeof e!="object"?e:Object.keys(e).sort().reduce((t,n)=>(t[n]=si(e[n]),t),{}),tn=e=>{if(!e||typeof e!="object"||Array.isArray(e))return null;let t=structuredClone(e);return t.playback&&(delete t.playback.continuity,t.playback.speed===1&&delete t.playback.speed,Object.keys(t.playback).length===0&&delete t.playback),JSON.stringify(si(t))},Ra=(e=[])=>e.filter(t=>Oa(t)).map(t=>structuredClone(t)),Ca=e=>Array.isArray(e?.keyframes)?e.keyframes.reduce((t,n)=>{let i=typeof n?.duration=="number"&&Number.isFinite(n.duration)?n.duration:0;return t+i},0):0,Js=e=>!e||typeof e!="object"||Array.isArray(e)?0:Object.values(e).reduce((t,n)=>Math.max(t,Ca(n)),0),_a=e=>Math.max(Js(e?.tween),Js(e?.prev?.tween),Js(e?.next?.tween),Ca(e?.mask?.progress)),$a=e=>!e||typeof e!="object"||Array.isArray(e)?0:e.playback?.loop===!0?Number.POSITIVE_INFINITY:_a(e)/Cd(e),_d=e=>e.some(t=>t?.playback?.loop===!0),ha=({animationInstances:e,activePersistentAnimations:t})=>{if(!Array.isArray(e)||e.length===0||!Array.isArray(t)||t.length===0)return!1;let n=new Set(t.map(tn).filter(Boolean));return e.some(i=>{if(!Oa(i))return!1;let a=tn(i);return a?n.has(a):!1})},qe=({animationInstances:e,isLineCompleted:t,skipTransitionsAndAnimations:n,activePersistentAnimations:i,restoredPersistentAnimations:a,isAuthoredOnCurrentLine:r=!0})=>!Array.isArray(e)||e.length===0||n?!1:_d(e)||r&&!t||ha({animationInstances:e,activePersistentAnimations:i})?!0:r?!1:ha({animationInstances:e,activePersistentAnimations:a}),$d=e=>!e||typeof e!="object"||Array.isArray(e)?!1:["in","out","update"].some(t=>e[t]!==void 0),jd=(e,t)=>{if($d(e))throw new Error(`[${t}] Legacy animations.in/out/update is no longer supported. Use a single animations.resourceId reference.`)},Nd=({resources:e,animationId:t,playback:n,instanceId:i,targetId:a,animationPath:r="animation"})=>{if(!t||!a)return!1;let s=e?.animations?.[t];return s?xd({id:i,targetId:a,animation:s,playback:n,animationPath:r}):null},Dd=(e,{defaultTargetId:t,defaultId:n,animationPath:i="animation"}={})=>{if(!e||typeof e!="object"||Array.isArray(e))return e;let a=structuredClone(e);return di({animationType:a.type,animationId:a.id??n,animationPath:i}),a.id??=n,a.targetId??=t,a},mi=({animations:e,transitions:t,defaultTargetId:n,idPrefix:i,animationPathPrefix:a=i})=>{t.forEach((r,s)=>{e.push(Dd(r,{defaultTargetId:n,defaultId:`${i}-transition-${s}`,animationPath:`${a}.transitions[${s}]`}))})},ii=(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},Td=({content:e,path:t,variables:n})=>ii(e,t).reduce((i,a)=>{let r=Lr(a.text,{variables:n});return i+`${r??""}`.length},0),ga=(e=[])=>{let t=new Map;for(let n of e)n?.id&&t.set(n.id,(t.get(n.id)??0)+1);return new Set(Array.from(t.entries()).filter(([,n])=>n>1).map(([n])=>n))},Zt=(e,t=0,n=new Set)=>{if(!n.has(e?.id))return`character-container-${e.id}`;let i=e?.sprites?.map(({resourceId:a})=>a)||[];return i.length===0?`character-container-${e.id}`:`character-container-${e.id}-${t}-${i.join("-")}`},mt=(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},Ld=(e,t={})=>{if(!t?.transformId)return;let n=e.transforms?.[t.transformId];if(!n)throw new Error(`Transform "${t.transformId}" not found for background`);return n},Md=["x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY"],qd=(e={})=>Md.some(t=>vr(e,t)),ja=(e={},t)=>{if(t){if(e.images?.[t])return"sprite";if(e.videos?.[t])return"video";if(e.spritesheets?.[t])return"spritesheet-animation";if(e.layouts?.[t])return"container"}},rn=({resourceId:e,kind:t})=>{if(e)return t?`bg-cg-background-${t}`:`bg-cg-${e}`},Vd=(e={})=>e.textStyles||{},Fd=(e={})=>e.images||{},Ud=.5,Bd=(e={},t,n)=>{if(t){if(!e.animations?.[t])throw new Error(`Animation '${t}' not found in spritesheet resource '${n}'`);return t}return Object.keys(e.animations??{})[0]},Na=({id:e,resourceId:t,spritesheet:n,animationName:i,animationSpeed:a,loop:r,transform:s={}}={})=>{let o=Bd(n,i,t),l=o?n.animations?.[o]:void 0;if(!l){console.warn(`Spritesheet animation not found: ${t}`);return}return{id:e,type:"spritesheet-animation",...s,width:n.width,height:n.height,src:n.fileId,atlas:n.jsonData,playback:{frames:l.frames,animationSpeed:a??l.animationSpeed??Ud,loop:r??l.loop??!0}}},Da=({id:e,item:t,resources:n={}}={})=>{let i=n.images?.[t.resourceId];if(i)return{type:"sprite",id:e,src:i.fileId,width:i.width,height:i.height,x:0,y:0};let a=n.spritesheets?.[t.resourceId];if(a)return Na({id:e,resourceId:t.resourceId,spritesheet:a,animationName:t.animationName,animationSpeed:t.animationSpeed,loop:t.loop,transform:{x:0,y:0}});console.warn(`Character sprite resource not found: ${t.resourceId}`)},Yd=(e={})=>e.colors||{},zd=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,ht=(e,t)=>e==="root"?`${t}`:`${e}.${t}`,Fr=(e,t,n)=>{if(typeof e!="string"||e.length===0)throw new Error(`${n} at "${t}" must resolve to a non-empty string`)},Qs=(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},Zs=(e,t,n,i,{minimum:a}={})=>{if(e===void 0)return i;if(typeof e!="number"||!Number.isFinite(e)||a!==void 0&&e<a){let r=a===void 0?"a finite number":`a finite number >= ${a}`;throw new Error(`shadow.${t} for text style "${n}" must be ${r}`)}return e},on=(e,t)=>{if(typeof e!="string"||!zd.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},ba=(e,t,n)=>{let i=on(e,n);if(t===1)return i;let a=Number.parseInt(i.slice(1,3),16),r=Number.parseInt(i.slice(3,5),16),s=Number.parseInt(i.slice(5,7),16);return`rgba(${a}, ${r}, ${s}, ${t})`},Gd=(e={},t)=>{let n=Vd(e)?.[t];if(!n)throw new Error(`Text style "${t}" not found`);let a=(Array.isArray(n.fontId)?n.fontId:[n.fontId]).map(l=>{let c=e.fonts?.[l];if(!c)throw new Error(`Font "${l}" not found for text style "${t}"`);return c.fileId}),r=e.colors?.[n.colorId];if(!r)throw new Error(`Color "${n.colorId}" not found for text style "${t}"`);let s=Qs(n.colorAlpha,"colorAlpha",t),o={fontFamily:Array.isArray(n.fontId)?a.join(", "):a[0],fontSize:n.fontSize??16,fontWeight:n.fontWeight??"400",fontStyle:n.fontStyle??"normal",lineHeight:n.lineHeight??1.2,fill:ba(r.hex,s,`Color "${n.colorId}" for text style "${t}"`)};if(n.align!==void 0&&(o.align=n.align),n.wordWrap!==void 0&&(o.wordWrap=n.wordWrap),n.breakWords!==void 0&&(o.breakWords=n.breakWords),n.wordWrapWidth!==void 0&&(o.wordWrapWidth=n.wordWrapWidth),n.strokeColorId){let l=e.colors?.[n.strokeColorId];if(!l)throw new Error(`Stroke color "${n.strokeColorId}" not found for text style "${t}"`);let c=Qs(n.strokeAlpha,"strokeAlpha",t);o.strokeColor=ba(l.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`);if(n.strokeWidth!==void 0&&(o.strokeWidth=n.strokeWidth),n.shadow!==void 0){let l=e.colors?.[n.shadow.colorId];if(!l)throw new Error(`Shadow color "${n.shadow.colorId}" not found for text style "${t}"`);o.shadow={color:on(l.hex,`Shadow color "${n.shadow.colorId}" for text style "${t}"`),alpha:Qs(n.shadow.alpha,"shadow.alpha",t),blur:Zs(n.shadow.blur,"blur",t,0,{minimum:0}),offsetX:Zs(n.shadow.offsetX,"offsetX",t,2),offsetY:Zs(n.shadow.offsetY,"offsetY",t,2)}}return o},oi=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((a,r)=>oi(a,t,`${n}[${r}]`));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 i={};for(let[a,r]of Object.entries(e))a!=="textStyleId"&&(i[a]=oi(r,t,ht(n,a)));return e.textStyleId!==void 0&&(Fr(e.textStyleId,n,"textStyleId"),i.textStyle=Gd(t,e.textStyleId)),i},yi=(e={},t)=>{let n=Yd(e)?.[t];if(!n)throw new Error(`Color "${t}" not found`);return on(n.hex,`Color "${t}"`)},Ta=e=>e==="hover.fill"?"hover.colorId":e==="click.fill"?"click.colorId":e==="rightClick.fill"?"rightClick.colorId":"colorId",ei=(e,t,n)=>{let i=e?.[t];if(!(!i||typeof i!="object"||Array.isArray(i))&&Object.prototype.hasOwnProperty.call(i,"fill"))throw new Error(`Inline ${t}.fill is not allowed in rect layout elements at "${n}". Use ${Ta(`${t}.fill`)} instead`)},Xd=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((a,r)=>gt(a,t,`${n}[${r}]`));if(!e||typeof e!="object")return e;let i={};for(let[a,r]of Object.entries(e))a!=="colorId"&&(i[a]=gt(r,t,ht(n,a)));return e.colorId!==void 0&&(Fr(e.colorId,n,"colorId"),i.fill=yi(t,e.colorId)),i},gt=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((a,r)=>gt(a,t,`${n}[${r}]`));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 ${Ta("fill")} instead`);ei(e,"hover",n),ei(e,"click",n),ei(e,"rightClick",n)}let i={};for(let[a,r]of Object.entries(e))if(!(e.type==="rect"&&a==="colorId")){if(e.type==="rect"&&(a==="hover"||a==="click"||a==="rightClick")){i[a]=Xd(r,t,ht(n,a));continue}i[a]=gt(r,t,ht(n,a))}return e.type==="rect"&&e.colorId!==void 0&&(Fr(e.colorId,n,"colorId"),i.fill=yi(t,e.colorId)),i},ri=(e={},t)=>{let n=Fd(e)?.[t];return n||null},La=e=>e==="hoverUrl"||e==="hoverSrc"||e==="hover.src"?"hoverImageId":e==="clickUrl"||e==="clickSrc"||e==="click.src"?"clickImageId":"imageId",wa=(e,t,n,i)=>{let a=e?.[t];if(!(!a||typeof a!="object"||Array.isArray(a))&&Object.prototype.hasOwnProperty.call(a,i))throw new Error(`Inline ${t}.${i} is not allowed in sprite layout elements at "${n}". Use ${La(`${t}.${i}`)} instead`)},Ia=(e,t,n)=>{let i=e[t];e[t]={...i&&typeof i=="object"&&!Array.isArray(i)?i:{},src:n}},ai=(e,t={},n="root")=>{if(Array.isArray(e))return e.map((a,r)=>ai(a,t,`${n}[${r}]`));if(!e||typeof e!="object")return e;if(e.type==="sprite"){for(let a of["url","src","hoverUrl","hoverSrc","clickUrl","clickSrc"])if(Object.prototype.hasOwnProperty.call(e,a))throw new Error(`Inline ${a} is not allowed in sprite layout elements at "${n}". Use ${La(a)} instead`);wa(e,"hover",n,"src"),wa(e,"click",n,"src")}let i={};for(let[a,r]of Object.entries(e))e.type==="sprite"&&(a==="imageId"||a==="hoverImageId"||a==="clickImageId")||(i[a]=ai(r,t,ht(n,a)));if(e.type==="sprite"&&e.imageId!==void 0){Fr(e.imageId,n,"imageId");let a=ri(t,e.imageId),r=a?.fileId??e.imageId;i.src=r,i.width===void 0&&a?.width!==void 0&&(i.width=a.width),i.height===void 0&&a?.height!==void 0&&(i.height=a.height)}return e.type==="sprite"&&e.hoverImageId!==void 0&&(Fr(e.hoverImageId,n,"hoverImageId"),Ia(i,"hover",ri(t,e.hoverImageId)?.fileId??e.hoverImageId)),e.type==="sprite"&&e.clickImageId!==void 0&&(Fr(e.clickImageId,n,"clickImageId"),Ia(i,"click",ri(t,e.clickImageId)?.fileId??e.clickImageId)),i},hi=(e,t={},n="root")=>ai(gt(oi(e,t,n),t,n),t,n),Ke=hi,Ar=(e=[])=>e.find(t=>t.id==="story"),Wd="#000000",li="bg-cg-background-color",Hd=({resources:e={},background:t={},screen:n})=>t?.colorId===void 0?on(n?.backgroundColor??Wd,"screen.backgroundColor"):yi(e,t.colorId),Ma=(e={})=>{if(vr(e,"opacity"))return typeof e.opacity=="number"?e.opacity:void 0},Kd=(e={})=>{if(!(!e.blur||typeof e.blur!="object"||Array.isArray(e.blur)))return e.blur},va=(e={},{includeDefaultAlpha:t=!1}={})=>{let n=Ma(e),i=Kd(e),a={};return(t||n!==void 0)&&(a.alpha=n??1),i&&(a.blur=i),a},Jd=(e={})=>{if(vr(e,"opacity"))return typeof e.opacity=="number"?e.opacity:void 0},Qd=(e={})=>{if(!(!e.blur||typeof e.blur!="object"||Array.isArray(e.blur)))return e.blur},qa=(e={})=>{let t=Jd(e),n=Qd(e),i={};return t!==void 0&&(i.alpha=t),n&&(i.blur=n),i},Vr=(e={})=>qa(e),We=(e={},t={})=>{let n={x:t.x??e.x,y:t.y??e.y,anchorX:t.anchorX??e.anchorX,anchorY:t.anchorY??e.anchorY,rotation:t.rotation??e.rotation,scaleX:t.scaleX??e.scaleX,scaleY:t.scaleY??e.scaleY},i=t.originX??e.originX,a=t.originY??e.originY;return i!==void 0&&(n.originX=i),a!==void 0&&(n.originY=a),n},Zd=["id","type","resourceId","transformId","x","y","anchorX","anchorY","scaleX","scaleY","rotation","originX","originY","layer","opacity","blur","animations"],gi=(e={})=>e.text&&vr(e.text,"content")&&vr(e.text,"textStyleId"),Aa=(e={})=>{if(e.resourceId)return e.resourceId;if(gi(e))return"text"},ka=(e,t={})=>typeof e=="string"?t.images?.[e]?.fileId??e:!e||typeof e!="object"||Array.isArray(e)?e:e.imageId?t.images?.[e.imageId]?.fileId??e.imageId:Array.isArray(e.items)?{...e,items:e.items.map(n=>{if(typeof n=="string")return t.images?.[n]?.fileId??n;if(!n||typeof n!="object"||Array.isArray(n))return n;if(n.imageId){let{imageId:i,...a}=n;return{...a,src:t.images?.[i]?.fileId??i}}return typeof n.src=="string"?{...n,src:t.images?.[n.src]?.fileId??n.src}:n})}:e,em=({item:e,particle:t,resources:n})=>{let i=mt(n,e),a=structuredClone(t),r=a.modules?.appearance?.texture;r!==void 0&&(a.modules.appearance.texture=ka(r,n)),a.texture!==void 0&&(a.texture=ka(a.texture,n));let s={id:`visual-${e.id}`,type:"container",children:[{...a,id:`visual-${e.id}-particles`,type:"particles",x:0,y:0}],...We(i,e)};return Object.assign(s,Vr(e)),s},rm=e=>{if(e.text){if(e.resourceId)throw new Error(`Visual item "${e.id}" cannot define both resourceId and text`);if(!gi(e))throw new Error(`Visual item "${e.id}" text requires content and textStyleId`);for(let t of Zd)if(vr(e.text,t))throw new Error(`Visual item "${e.id}" text.${t} is reserved for the visual item`)}},tm=({resources:e,background:t,screen:n={width:1920,height:1080},includeOpacity:i=!1})=>{let a={id:li,type:"rect",x:0,y:0,width:n?.width??1920,height:n?.height??1080,fill:Hd({resources:e,background:t,screen:n})};if(i){let r=Ma(t);r!==void 0&&(a.alpha=r)}return a},nm=(e={},t)=>t?!!(e.images?.[t]||e.videos?.[t]||e.spritesheets?.[t]||e.layouts?.[t]):!1,Pa=({resources:e={},resourceId:t,colorId:n})=>{let i=ja(e,t);return t&&(i||n===void 0)?{resourceId:t,targetId:rn({resourceId:t,kind:i})}:n!==void 0?{resourceId:li,targetId:li}:{resourceId:void 0,targetId:void 0}},Va=100,or=Va,sm="channel:bgm",im="channel:music-room",om="music-room:player",am="channel:voice",lm="default",cm=e=>String(e).replaceAll("%","%25").replaceAll(":","%3A"),yt=(...e)=>e.map(cm).join(":"),nn=(e,t,n)=>{let i=new Set;e.forEach(({id:a})=>{if(i.has(a)){let r=n?` in ${n}`:"";throw new Error(`Duplicate ${t} id "${a}"${r}.`)}i.add(a)})},um=(e,t)=>e*t/Va,Fa=(e={},t)=>e?.[t]??wr[t],an=(e={},t,n=or)=>um(n,Fa(e,t)),ln=({id:e,volume:t,muted:n,pan:i,loop:a,playback:r,interruption:s,children:o,runtime:l})=>{let c={id:e,type:"audio-channel",volume:t,muted:!!l?.muteAll||(n??!1),pan:i??0,children:o};return a!==void 0&&(c.loop=a),r!==void 0&&(c.playback=structuredClone(r)),s!==void 0&&(c.interruption=s),c},en=(e,t,n,i)=>e[n]!==void 0?e[n]:t[n]!==void 0?t[n]:i,pm=["muted","pan","playbackRate","startAt","endAt"],cn=({id:e,sound:t,resource:n,defaultLoop:i=!1})=>{let a={id:e,type:"sound",src:n.fileId,loop:en(t,n,"loop",i),volume:en(t,n,"volume",or),startDelayMs:en(t,n,"startDelayMs",0)};pm.forEach(s=>{let o=en(t,n,s,void 0);o!==void 0&&(a[s]=o)}),t.playback!==void 0&&(a.playback=structuredClone(t.playback));let r=a.startAt??0;if(a.endAt!==void 0&&a.endAt!==null&&a.endAt<r)throw new Error(`Sound "${e}" endAt (${a.endAt}) must be greater than or equal to startAt (${r}).`);return a},De=({variables:e,imageGallery:t,musicRoom:n,sceneReplay:i,runtime:a,saveSlots:r=[],dialogueState:s,includeInactiveAdvDialogue:o=!1,isLineCompleted:l,autoMode:c,skipMode:u,isChoiceVisible:p,isFormVisible:m,canRollback:d,confirmDialog:f,form:y,historyDialogue:g=[],characters:h={},dialogueUIHidden:w,skipOnlyViewedLines:b,skipTransitionsAndAnimations:E}={})=>{let v={dialogueTextSpeed:a?.dialogueTextSpeed??50,autoForwardDelay:a?.autoForwardDelay??1e3,autoForwardSpeed:a?.autoForwardSpeed??50,skipUnseenText:a?.skipUnseenText??!1,skipTransitionsAndAnimations:a?.skipTransitionsAndAnimations??!1,soundVolume:a?.soundVolume??50,musicVolume:a?.musicVolume??50,muteAll:a?.muteAll??!1,localizationPackageId:a?.localizationPackageId??null,saveLoadPagination:a?.saveLoadPagination??1,menuPage:a?.menuPage??"",menuEntryPoint:a?.menuEntryPoint??"",autoMode:a?.autoMode??c??!1,skipMode:a?.skipMode??u??!1,dialogueUIHidden:a?.dialogueUIHidden??w??!1,isLineCompleted:a?.isLineCompleted??l??!1},k=hm({dialogueState:s,includeInactiveAdvDialogue:o,characters:h,variables:e,runtime:v}),x={variables:e,imageGallery:t,musicRoom:n,sceneReplay:i,localizationPackages:a?.localizationPackages??[],localizationPackageId:v.localizationPackageId,runtime:v,saveSlots:r,isChoiceVisible:p,isFormVisible:m,canRollback:d,confirmDialog:f,form:y,historyDialogue:g,characters:h};return k&&(x.dialogue=k,x.dialogueLines=k.lines),x},xa=100,sn=(e,t)=>{if(Array.isArray(e))return e.map(i=>sn(i,t));if(!e||typeof e!="object")return e;let n={...e};return Object.keys(n).forEach(i=>{n[i]=sn(n[i],t)}),n.type==="text-revealing"?t(n):n},fm=e=>sn(e,t=>({...t,revealEffect:"none"})),dm=e=>sn(e,t=>{let n=Number(t.speed??t.displaySpeed),i=Number.isFinite(n)?Math.max(n,xa):xa;return{...t,speed:i,...Object.prototype.hasOwnProperty.call(t,"displaySpeed")?{displaySpeed:i}:{}}}),ar=(e,{isLineCompleted:t=!1,skipMode:n=!1,skipTransitionsAndAnimations:i=!1}={})=>t||i?fm(e):n?dm(e):e,Ua=({id:e,screen:t={width:1920,height:1080}})=>({id:e,type:"rect",fill:"transparent",width:t.width,height:t.height,x:0,y:0,click:{payload:{actions:{}}}}),ci=e=>{if(Array.isArray(e))return e.map(ci);if(!e||typeof e!="object")return e;let t={};for(let[r,s]of Object.entries(e))t[r]=ci(s);let n=t.click?.payload;if(!n||typeof n!="object"||Array.isArray(n))return t;let i=n.actions,a=i&&typeof i=="object"&&!Array.isArray(i)&&Object.prototype.hasOwnProperty.call(i,"nextLine")?{...i.nextLine,bypassChoice:!0}:void 0;return{...t,click:{...t.click,payload:{...n,bypassChoice:!0,...a?{actions:{...i,nextLine:a}}:{}}}}},mm=new Set(["click","change","submit","focusEvent","blurEvent","selectionChange","compositionStart","compositionUpdate","compositionEnd"]),Ea="submit",ti=(e,t,n={})=>{let i=e?.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{},a=i.actions&&typeof i.actions=="object"?i.actions:{},r=n.replaceActions===!0?t:{...a,...t};return{...e||{},payload:{...i,actions:r}}},ui=(e,t,n={})=>{if(Array.isArray(e))return e.map(c=>ui(c,t,n));if(!e||typeof e!="object")return e;let i=typeof e.type=="string",a=i&&e.formRole===Ea,r=i&&n.submitRoleAncestor,s=a||r?{submitRoleAncestor:!0}:{},o={};for(let[c,u]of Object.entries(e))o[c]=ui(u,t,c==="children"?s:{});let l=o;if(l.type==="input"&&typeof l.field=="string"){let c=t?.fields?.[l.field];if(c){let u={updateFormField:{formKey:t.key,field:c.id,value:"_event.value"}};l={...l,value:c.value,placeholder:l.placeholder===void 0?c.placeholder:l.placeholder,multiline:l.multiline===void 0?c.multiline:l.multiline,...l.maxLength===void 0&&c.maxLength!==void 0?{maxLength:c.maxLength}:{},change:ti(l.change,u),submit:ti(l.submit,t.submitActions)}}}return l.formRole===Ea||r?{...l,click:ti(l.click,t.submitActions,{replaceActions:!0})}:l},pi=(e,t)=>{if(Array.isArray(e))return e.map(i=>pi(i,t));if(!e||typeof e!="object")return e;let n={};for(let[i,a]of Object.entries(e))n[i]=pi(a,t);for(let i of mm){let a=n[i]?.payload;!a||typeof a!="object"||Array.isArray(a)||(n[i]={...n[i],payload:{...a,_interactionSource:"form"}})}return n},fi=({characterId:e,character:t,characterName:n,characters:i={},variables:a={}}={})=>{let r=e?i?.[e]:void 0,s=Ht({characterId:e,character:t,characterName:n,characters:i,variables:a});return{...r||{},...t||{},name:s}},Ba=(e=[],t={},n={})=>e.map(i=>{let a=fi({characterId:i.characterId,character:i.character,characterName:i.characterName,characters:t,variables:n}),r=typeof i.text=="string"?i.text:Array.isArray(i.content)?i.content.map(s=>s?.text??"").join(""):"";return{...i,text:r,character:a,characterName:a.name}}),ym=e=>!(!e||e.mode==="adv"&&e.content===void 0),hm=({dialogueState:e,includeInactiveAdvDialogue:t=!1,characters:n={},variables:i,runtime:a}={})=>{if(!t&&!ym(e))return;let r=e.content===void 0?[{text:""}]:ii(e.content,"dialogue.content"),s=e.content===void 0?0:Td({content:e.initialRevealedContent,path:"dialogue.initialRevealedContent",variables:i}),o=a?.dialogueTextSpeed??wr.dialogueTextSpeed,l=e.textSpeed??o,c=(e.lines||[]).map((p,m)=>{let d=ii(p.content,`dialogue.lines[${m}].content`),f=fi({characterId:p.characterId,character:p.character,characterName:p.characterName,characters:n,variables:i});return{...p,textSpeed:p.textSpeed??o,content:d.map(y=>({...y,text:Lr(y.text,{variables:i})})),character:f,characterName:f.name}}),u=fi({characterId:e.characterId,character:e.character,characters:n,variables:i});return{characterId:e.characterId,persistCharacter:e.persistCharacter,persistSprite:e.persistSprite,character:u,textSpeed:l,content:r.map(p=>({...p,text:Lr(p.text,{variables:i})})),initialRevealedCharacters:s,lines:c}},Ya=({container:e,resources:t,templateData:n,isLineCompleted:i=!1,skipMode:a=!1,skipTransitionsAndAnimations:r=!1})=>{let s=He(e,n);return Ke(ar(s,{isLineCompleted:i,skipMode:a,skipTransitionsAndAnimations:r}),t)},ni=(e,t={})=>e?.payload&&typeof e.payload=="object"?structuredClone(e.payload):e?.actions&&typeof e.actions=="object"?{actions:structuredClone(e.actions)}:structuredClone(t),Sa=({renderStateKeyboard:e,keyboard:t,phase:n})=>{!t||typeof t!="object"||Array.isArray(t)||Object.entries(t).forEach(([i,a])=>{let r=e[i]??{},s=n==="keydown"?a?.keydown:a?.keyup;if(n==="keydown"&&s&&typeof s=="object"){e[i]={...r,keydown:{payload:ni(s)}},a?.keyup&&typeof a.keyup=="object"&&(e[i].keyup={payload:ni(a.keyup)});return}e[i]={...r,[n]:{payload:ni(a)}}})},gm=(e={},t={})=>{let n={};return Sa({renderStateKeyboard:n,keyboard:e,phase:"keydown"}),Sa({renderStateKeyboard:n,keyboard:t,phase:"keyup"}),Object.keys(n).length>0?n:void 0},Je=({animationsDef:e,resources:t,previousResourceId:n,currentResourceId:i,previousTargetId:a,currentTargetId:r,animationPath:s,idPrefix:o})=>{if(!e)return[];let l=[],c=({instanceId:h,targetId:w})=>{let b=Nd({resources:t,animationId:d,playback:f,instanceId:h,targetId:w,animationPath:s});b&&l.push(b)},u=n!=null&&n!==!1,p=i!=null&&i!==!1,m=a&&r&&a===r;jd(e,s);let d=Sd(e),f=Od(e),y=t?.animations?.[d],g=Ed(y,{animationId:d,animationPath:s});if(g==="update")return p&&r?c({instanceId:`${o}-animation-update`,targetId:r}):u&&a&&c({instanceId:`${o}-animation-update`,targetId:a}),l;if(g==="transition"){let h=`${o}-animation-transition`,w=f?.continuity==="persistent"?h:`${o}-animation-in`;if(u&&p&&m)return c({instanceId:h,targetId:r}),l;u&&c({instanceId:`${o}-animation-out`,targetId:a}),p&&c({instanceId:w,targetId:r})}return l},bm=()=>({elements:[{id:"story",type:"container",x:0,y:0,children:[]}],animations:[],audio:[],global:{}}),wm=(e,{presentationState:t,previousPresentationState:n,currentLineActions:i,resources:a={},screen:r={width:1920,height:1080},isLineCompleted:s,skipTransitionsAndAnimations:o,variables:l,imageGallery:c,musicRoom:u,sceneReplay:p,runtime:m,activePersistentAnimations:d,restoredPersistentAnimations:f,autoMode:y,skipMode:g,isChoiceVisible:h,isFormVisible:w,canRollback:b,form:E,saveSlots:v=[]})=>{let{elements:k,animations:x}=e;if(t.background){let C=i===void 0?!0:vr(i?.background??{},"animations"),N=k.find(ce=>ce.id==="story");if(!N)return e;let P=Ld(a,t.background),T=P||qd(t.background),q=n?.background?.resourceId,ae=n?.background?.colorId,B=t.background.resourceId??(t.background.animations?q:void 0),ne=t.background.colorId??(t.background.animations?ae:void 0),ie=nm(a,B),fe={...t.background,colorId:ne};if((ne!==void 0||ie)&&N.children.push(tm({resources:a,background:fe,screen:r,includeOpacity:!ie})),B){let{images:ce={},videos:oe={},spritesheets:R={}}=a,j=ja(a,B),M;if(j==="sprite"?M=ce[B]:j==="video"?M=oe[B]:j==="spritesheet-animation"&&(M=R[B]),M){let Z=j==="video",ge=j==="spritesheet-animation",K={x:(r?.width??1920)/2,y:(r?.height??1080)/2,anchorX:.5,anchorY:.5,rotation:0,scaleX:1,scaleY:1,...P},xe={...va(t.background,{includeDefaultAlpha:!0}),...We(K,t.background)},me;ge?me=Na({id:rn({resourceId:B,kind:j}),resourceId:B,spritesheet:M,animationName:t.background.animationName,animationSpeed:t.background.animationSpeed,loop:t.background.loop,transform:xe}):me={id:rn({resourceId:B,kind:j}),type:Z?"video":"sprite",src:M.fileId,width:M.width,height:M.height,...xe},Z&&(me.loop=t.background.loop??!1,me.volume=M.volume??50),me&&N.children.push(me)}}if(B){let{layouts:ce={}}=a,oe=ce[B];if(oe){let R={id:rn({resourceId:B,kind:"container"}),type:"container",children:oe.elements,...va(t.background)};T&&Object.assign(R,We({x:0,y:0,anchorX:0,anchorY:0,rotation:0,scaleX:1,scaleY:1,...P},t.background));let j=He(R,De({variables:l,imageGallery:c,musicRoom:u,sceneReplay:p,runtime:m,saveSlots:v,dialogueState:t.dialogue,isLineCompleted:s,autoMode:y,skipMode:g,isChoiceVisible:h,isFormVisible:w,canRollback:b,form:E,characters:a.characters||{},skipTransitionsAndAnimations:o}));N.children.push(Ke(ar(j,{isLineCompleted:s,skipMode:g,skipTransitionsAndAnimations:o}),a))}}let ve=Pa({resources:a,resourceId:q,colorId:ae}),le=Pa({resources:a,resourceId:B,colorId:ne}),se=Je({animationsDef:t.background.animations,resources:a,previousResourceId:ve.resourceId,currentResourceId:le.resourceId,previousTargetId:ve.targetId,currentTargetId:le.targetId,animationPath:"background.animations",idPrefix:"bg-cg"});qe({animationInstances:se,isLineCompleted:s,skipTransitionsAndAnimations:o,activePersistentAnimations:d,restoredPersistentAnimations:f,isAuthoredOnCurrentLine:C})&&x.push(...se)}return e},Im=(e,{presentationState:t,previousPresentationState:n,resources:i,isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})=>{let{elements:o,animations:l}=e;if(t.character&&i){let c=o.find(f=>f.id==="story");if(!c)return e;let u=t.character.items||[],p=n?.character?.items||[],m=ga(u),d=ga(p);for(let f=0;f<u.length;f++){let y=u[f],{transformId:g,sprites:h}=y,w=p.find(T=>T.id===y.id),b=p.findIndex(T=>T.id===y.id),E=w?.sprites&&w.sprites.length>0,v=h&&h.length>0,k=b>=0?Zt(w,b,d):void 0,x=Je({animationsDef:y.animations,resources:i,previousResourceId:k,currentResourceId:v?Zt(y,f,m):void 0,previousTargetId:k,currentTargetId:v?Zt(y,f,m):void 0,animationPath:`character.items[${f}].animations`,idPrefix:"character"});if(y.animations&&!h&&!g&&E&&qe({animationInstances:x,isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})){l.push(...x);continue}if(y.animations&&!h&&!g)continue;if(!h||h.length===0||!g){console.warn("Character item missing sprites or transformId:",y);continue}let C=Zt(y,f,m),N=i.transforms[g];if(!N){console.warn("Transform not found:",g);continue}let P={type:"container",id:C,...We(N,y),...Vr(y),children:[]};for(let T of h){let q=Da({id:`${C}-${T.id}`,item:T,resources:i});q&&P.children.push(q)}c.children.push(P),qe({animationInstances:x,isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})&&l.push(...x)}}return e},za=(e,t)=>{if(!Ks.includes(e))throw new Error(`${t} must be one of: ${Ks.join(", ")}.`)},vm=(e,t)=>{let n=!!e.resourceId||gi(e),i=e.layer??(n?void 0:t?.layer)??Hs;return za(i,`Visual item "${e.id}" layer`),i},Am=(e,{presentationState:t,previousPresentationState:n,resources:i,isLineCompleted:a,skipTransitionsAndAnimations:r,variables:s,imageGallery:o,musicRoom:l,sceneReplay:c,runtime:u,activePersistentAnimations:p,autoMode:m,skipMode:d,isChoiceVisible:f,isFormVisible:y,canRollback:g,form:h,saveSlots:w=[],visualLayer:b})=>{let{elements:E,animations:v}=e;if(t.visual&&i){let k=E.find(P=>P.id==="story");if(!k)return e;let x=t.visual.items,C=n?.visual?.items||[],N=De({variables:s,imageGallery:o,musicRoom:l,sceneReplay:c,runtime:u,saveSlots:w,dialogueState:t.dialogue,isLineCompleted:a,autoMode:m,skipMode:d,isChoiceVisible:f,isFormVisible:y,canRollback:g,form:h,characters:i.characters||{},skipTransitionsAndAnimations:r});b!==void 0&&za(b,"visualLayer");for(let P of x){let T=C.find(ie=>ie.id===P.id),q=vm(P,T);if(b!==void 0&&q!==b)continue;if(rm(P),P.text){let ie=mt(i,P),fe={...structuredClone(P.text),id:`visual-${P.id}`,type:"text",...We(ie,P)};Object.assign(fe,Vr(P)),k.children.push(Ke(He(fe,N),i))}if(P.resourceId){let{images:ie={},videos:fe={},spritesheets:ve={}}=i,le=ve[P.resourceId];if(le){let se=mt(i,P),ce=P.animationName;if(ce){let oe=le.animations?.[ce];if(!oe)throw new Error(`Animation '${ce}' not found in spritesheet resource '${P.resourceId}'`);let R=Vr(P),j={id:`visual-${P.id}`,type:"spritesheet-animation",...We(se,P),width:P.width??le.width,height:P.height??le.height,alpha:R.alpha??P.alpha??1,src:le.fileId,atlas:le.jsonData,playback:{frames:oe.frames,animationSpeed:P.animationSpeed??oe.animationSpeed??.5,loop:P.loop??oe.loop??!0}};R.blur&&(j.blur=R.blur),k.children.push(structuredClone(j))}}else{let se=ie[P.resourceId]||fe[P.resourceId];if(se){let ce=fe[P.resourceId]!==void 0,oe=mt(i,P),R={id:`visual-${P.id}`,type:ce?"video":"sprite",src:se.fileId,width:se.width,height:se.height,...We(oe,P)};Object.assign(R,Vr(P)),ce&&(R.loop=se.loop??!1,R.volume=se.volume??50),k.children.push(R)}}}if(P.resourceId){let ie=i.particles?.[P.resourceId];ie&&k.children.push(em({item:P,particle:ie,resources:i}))}if(P.resourceId){let{layouts:ie={}}=i,fe=ie[P.resourceId];if(fe){let ve=mt(i,P),le={id:`visual-${P.id}`,type:"container",children:structuredClone(fe.elements),...We(ve,P)};Object.assign(le,Vr(P));let se=He(le,N);k.children.push(Ke(ar(se,{isLineCompleted:a,skipMode:d,skipTransitionsAndAnimations:r}),i))}}let ae=Aa(T),B=Aa(P),ne=Je({animationsDef:P.animations,resources:i,previousResourceId:ae,currentResourceId:B,previousTargetId:ae?`visual-${P.id}`:void 0,currentTargetId:B?`visual-${P.id}`:void 0,animationPath:`visual.items[${P.id}].animations`,idPrefix:P.id});qe({animationInstances:ne,isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:p})&&v.push(...ne)}}return e},qr="dialogue-character-sprite",km=(e,{presentationState:t,previousPresentationState:n,resources:i={},isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})=>{let{animations:o}=e,l=Ar(e.elements);if(!l)return e;let c=t.dialogue?.character?.sprite,u=n?.dialogue?.character?.sprite,p=st(c),m=st(u),d=Je({animationsDef:c?.animations,resources:i,previousResourceId:m?qr:void 0,currentResourceId:p?qr:void 0,previousTargetId:m?qr:void 0,currentTargetId:p?qr:void 0,animationPath:"dialogue.character.sprite.animations",idPrefix:"dialogue-character-sprite"});if(!p)return c?.animations&&m&&qe({animationInstances:d,isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})&&o.push(...d),e;let f=i.transforms?.[c.transformId];if(!f)return console.warn("Transform not found:",c.transformId),e;let y={type:"container",id:qr,...We(f),children:[]};for(let g of c.items){let h=Da({id:`${qr}-${g.id}`,item:g,resources:i});h&&y.children.push(h)}return l.children.push(y),qe({animationInstances:d,isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})&&o.push(...d),e},Pm=(e,{presentationState:t,previousPresentationState:n,resources:i={},dialogueUIHidden:a,autoMode:r,skipMode:s,isChoiceVisible:o,isFormVisible:l,canRollback:c,form:u,skipOnlyViewedLines:p,isLineCompleted:m,skipTransitionsAndAnimations:d,variables:f,imageGallery:y,musicRoom:g,sceneReplay:h,runtime:w,activePersistentAnimations:b,saveSlots:E=[]})=>{let{elements:v,animations:k}=e;if(!t.dialogue||a)return e;let x=v.find(N=>N.id==="story");if(!x)return e;if(t.dialogue.ui&&t.dialogue.ui.resourceId){let{layouts:N={}}=i,P=N[t.dialogue.ui.resourceId];if(P){let T={elements:P.elements},q=De({variables:f,imageGallery:y,musicRoom:g,sceneReplay:h,runtime:w,saveSlots:E,dialogueState:t.dialogue,includeInactiveAdvDialogue:!0,isLineCompleted:m,autoMode:r,skipMode:s,isChoiceVisible:o,isFormVisible:l,canRollback:c,form:u,characters:i.characters||{},dialogueUIHidden:a,skipOnlyViewedLines:p,skipTransitionsAndAnimations:d}),ae=He(T,q),B=Ke(ar(ae?.elements,{isLineCompleted:m,skipMode:s,skipTransitionsAndAnimations:d}),i);if(Array.isArray(B))for(let ne of B)x.children.push(ne);else B&&x.children.push(B)}}km(e,{presentationState:t,previousPresentationState:n,resources:i,isLineCompleted:m,skipTransitionsAndAnimations:d,activePersistentAnimations:b});let C=Je({animationsDef:t.dialogue.ui?.animations,resources:i,previousResourceId:n?.dialogue?.ui?.resourceId,currentResourceId:t.dialogue.ui?.resourceId,previousTargetId:n?.dialogue?.ui?.resourceId?"dialogue-container":void 0,currentTargetId:t.dialogue.ui?.resourceId?"dialogue-container":void 0,animationPath:"dialogue.ui.animations",idPrefix:"dialogue-ui"});return qe({animationInstances:C,isLineCompleted:m,skipTransitionsAndAnimations:d,activePersistentAnimations:b})&&k.push(...C),e},xm=(e,{presentationState:t,previousPresentationState:n,resources:i,screen:a,isLineCompleted:r,skipTransitionsAndAnimations:s,variables:o,imageGallery:l,musicRoom:c,sceneReplay:u,runtime:p,autoMode:m,skipMode:d,isChoiceVisible:f,isFormVisible:y,canRollback:g,form:h,activePersistentAnimations:w,saveSlots:b=[]})=>{let{elements:E,animations:v}=e;if(t.choice&&i){let k=Ar(E);if(!k)return e;let x=i?.layouts[t.choice.resourceId];if(x&&x.elements){let N={elements:x.elements},P=He(N,{...De({variables:o,imageGallery:l,musicRoom:c,sceneReplay:u,runtime:p,saveSlots:b,dialogueState:t.dialogue,isLineCompleted:r,autoMode:m,skipMode:d,isChoiceVisible:f??!!t.choice,isFormVisible:y,canRollback:g,form:h,characters:i.characters||{},skipTransitionsAndAnimations:s}),choice:{items:t.choice?.items??[]}}),T=ci(Ke(ar(P?.elements,{isLineCompleted:r,skipMode:d,skipTransitionsAndAnimations:s}),i));if(Array.isArray(T))for(let q of T)k.children.push(q);else T&&k.children.push(T)}let C=Je({animationsDef:t.choice.animations,resources:i,previousResourceId:n?.choice?.resourceId,currentResourceId:t.choice.resourceId,previousTargetId:n?.choice?.resourceId?"choice-container":void 0,currentTargetId:t.choice.resourceId?"choice-container":void 0,animationPath:"choice.animations",idPrefix:"choice"});qe({animationInstances:C,isLineCompleted:r,skipTransitionsAndAnimations:s,activePersistentAnimations:w})&&v.push(...C)}return e},Em=(e,{presentationState:t,previousPresentationState:n,resources:i,screen:a,isLineCompleted:r,skipTransitionsAndAnimations:s,variables:o,imageGallery:l,musicRoom:c,sceneReplay:u,runtime:p,autoMode:m,skipMode:d,isChoiceVisible:f,isFormVisible:y,canRollback:g,activePersistentAnimations:h,saveSlots:w=[],form:b})=>{let{elements:E,animations:v}=e;if(!b?.resourceId||!i)return e;let k=Ar(E);if(!k)return e;let x=i?.layouts?.[b.resourceId];if(!x)return console.warn(`Form layout not found: ${b.resourceId}`),e;let C={id:"form-container",type:"container",x:0,y:0,children:x.elements||[]},N={...De({variables:o,imageGallery:l,musicRoom:c,sceneReplay:u,runtime:p,saveSlots:w,dialogueState:t.dialogue,isLineCompleted:r,autoMode:m,skipMode:d,isChoiceVisible:f,isFormVisible:y,canRollback:g,characters:i.characters||{},skipTransitionsAndAnimations:s,form:b}),form:b},P=He(C,N),T=pi(Ke(ar(ui(P,b),{isLineCompleted:r,skipMode:d,skipTransitionsAndAnimations:s}),i),b);T&&k.children.push(T);let q=Je({animationsDef:b.animations,resources:i,previousResourceId:n?.form?.resourceId,currentResourceId:b.resourceId,previousTargetId:n?.form?.resourceId?"form-container":void 0,currentTargetId:b.resourceId?"form-container":void 0,animationPath:"form.animations",idPrefix:"form"});return qe({animationInstances:q,isLineCompleted:r,skipTransitionsAndAnimations:s,activePersistentAnimations:h})&&v.push(...q),e},Sm=(e,{presentationState:t,resources:n={},variables:i,imageGallery:a,musicRoom:r,sceneReplay:s,runtime:o,isLineCompleted:l,autoMode:c,skipMode:u,isChoiceVisible:p,isFormVisible:m,canRollback:d,form:f,saveSlots:y=[],skipTransitionsAndAnimations:g})=>{if(!t.control?.resourceId)return e;let h=n.controls?.[t.control.resourceId];if(!h)return e;let w=gm(h.keyboard,h.keyup);if(w&&Object.keys(w).length>0&&(e.global.keyboard=w),!Array.isArray(h.elements)||h.elements.length===0)return e;let b=Ar(e.elements);if(!b)return e;let E={id:`control-${t.control.resourceId}`,type:"container",x:0,y:0,children:h.elements};return b.children.push(Ya({container:E,resources:n,templateData:De({variables:i,imageGallery:a,musicRoom:r,sceneReplay:s,runtime:o,saveSlots:y,dialogueState:t.dialogue,isLineCompleted:l,autoMode:c,skipMode:u,isChoiceVisible:p,isFormVisible:m,canRollback:d,form:f,characters:n.characters||{},skipTransitionsAndAnimations:g}),isLineCompleted:l,skipMode:u,skipTransitionsAndAnimations:g})),e},Om=(e,{presentationState:t,resources:n,runtime:i,variables:a,musicRoomPlayer:r})=>{let{elements:s,audio:o}=e;if(t.bgm&&n){if(!Ar(s))return e;let c=t.bgm,u=!Array.isArray(c.sounds),p=u?c.resourceId?[{id:"default",resourceId:c.resourceId,loop:c.loop??!0,volume:c.volume,startDelayMs:c.startDelayMs??0}]:[]:c.sounds,m=!u&&c.loop===!0,d=[];if(u||nn(p,"BGM sound"),m){let y=p.find(g=>g.loop===!0);if(y)throw new Error(`BGM sound "${y.id}" cannot loop inside a looping BGM channel.`)}if(p.forEach(y=>{let g=n.sounds?.[y.resourceId];if(!g)return;let h=m?{...y,loop:y.loop??!1}:y;d.push(cn({id:yt("bgm",u?"default":y.id),sound:h,resource:g,defaultLoop:!m}))}),d.length===0)return e;let f=De({variables:a,runtime:i}).runtime;o.push(ln({id:sm,volume:an(f,"musicVolume",u?or:c.volume??or),muted:c.muted,pan:c.pan,loop:u?void 0:c.loop,playback:r?.bgmPlayback,interruption:c.interruption,children:d,runtime:f}))}return e},Rm=(e,{resources:t={},runtime:n,variables:i,musicRoomPlayer:a})=>{let r=t.musicRoom;if(!r||!a?.trackId||!a.playback)return e;let s=r.tracks.find(u=>u.id===a.trackId),o=s?t.sounds?.[s.soundId]:void 0;if(!s||!o)return e;let l=De({variables:i,runtime:n}).runtime,c=cn({id:om,sound:{loop:!1,startDelayMs:0,playback:a.playback},resource:o});return e.audio.push(ln({id:im,volume:an(l,"musicVolume",or),children:[c],runtime:l})),e},Cm=(e,{presentationState:t,resources:n,runtime:i})=>{let{audio:a}=e;if(t.sfx&&n){let r=t.sfx,s=!Array.isArray(r.channels),o=s?[{id:lm,sounds:r.items??[]}]:r.channels;s||nn(o,"SFX channel"),o.forEach(l=>{let c=!s&&l.loop===!0,u=[];if(s||nn(l.sounds,"SFX sound",`SFX channel "${l.id}"`),c){let p=l.sounds.find(m=>m.loop===!0);if(p)throw new Error(`SFX sound "${p.id}" cannot loop inside looping SFX channel "${l.id}".`)}l.sounds.forEach((p,m)=>{let d=n.sounds?.[p.resourceId];if(!d)return;let f=c?{...p,loop:p.loop??!1}:p;u.push(cn({id:s?yt("sfx","default",m,p.id):yt("sfx",l.id,p.id),sound:f,resource:d,defaultLoop:c?!1:void 0}))}),u.length!==0&&a.push(ln({id:yt("channel","sfx",l.id),volume:an(i,"soundVolume",l.volume??or),muted:l.muted,pan:l.pan,loop:s?void 0:l.loop,interruption:s?void 0:l.interruption,children:u,runtime:i}))})}return e},_m=(e,t,n)=>{if(!(!t||!n))return e?.voices?.[t]?.[n]},$m=(e,{presentationState:t,resources:n,currentSceneId:i,runtime:a,variables:r})=>{let{audio:s}=e;if(!t?.voice)return e;let o=t.voice,l=!Array.isArray(o.sounds),c=l?o.resourceId?[{id:"default",resourceId:o.resourceId,loop:o.loop??!1,volume:or,startDelayMs:o.startDelayMs??0}]:[]:o.sounds,u=!l&&o.loop===!0,p=[];if(l||nn(c,"Voice sound"),u){let d=c.find(f=>f.loop===!0);if(d)throw new Error(`Voice sound "${d.id}" cannot loop inside a looping Voice channel.`)}if(c.forEach(d=>{let f=_m(n,i,d.resourceId);if(!f)return;let y=u?{...d,loop:d.loop??!1}:d;p.push(cn({id:yt("voice",i,l?"default":d.id),sound:y,resource:f,defaultLoop:u?!1:void 0}))}),p.length===0)return e;let m=De({variables:r,runtime:a}).runtime;return s.push(ln({id:am,volume:l?o.volume??Fa(m,"soundVolume"):an(m,"soundVolume",o.volume??or),muted:o.muted,pan:o.pan,loop:l?void 0:o.loop,interruption:o.interruption,children:p,runtime:m})),e},jm=(e,{presentationState:t,previousPresentationState:n,resources:i={},variables:a,imageGallery:r,musicRoom:s,sceneReplay:o,runtime:l,autoMode:c,skipMode:u,isChoiceVisible:p,isFormVisible:m,canRollback:d,form:f,saveSlots:y=[],isLineCompleted:g,skipTransitionsAndAnimations:h,activePersistentAnimations:w})=>{let{elements:b,animations:E}=e;if(t.layout){let C=Ar(b);if(!C)return e;let N=i.layouts[t.layout.resourceId];if(!N)return e;Array.isArray(N.transitions)&&!g&&!h&&mi({animations:E,transitions:N.transitions,defaultTargetId:`layout-${t.layout.resourceId}`,idPrefix:`layout-${t.layout.resourceId}`,animationPathPrefix:"layout"});let P={id:`layout-${t.layout.resourceId}`,type:"container",x:0,y:0,children:N.elements||[]};C.children.push(Ya({container:P,resources:i,templateData:De({variables:a,imageGallery:r,musicRoom:s,sceneReplay:o,runtime:l,saveSlots:y,dialogueState:t.dialogue,isLineCompleted:g,autoMode:c,skipMode:u,isChoiceVisible:p,isFormVisible:m,canRollback:d,form:f,characters:i.characters||{},skipTransitionsAndAnimations:h}),isLineCompleted:g,skipMode:u,skipTransitionsAndAnimations:h}))}let v=n?.layout?.resourceId,k=t.layout?.resourceId,x=Je({animationsDef:t.layout?.animations,resources:i,previousResourceId:v,currentResourceId:k,previousTargetId:v?`layout-${v}`:void 0,currentTargetId:k?`layout-${k}`:void 0,animationPath:"layout.animations",idPrefix:"layout"});return qe({animationInstances:x,isLineCompleted:g,skipTransitionsAndAnimations:h,activePersistentAnimations:w})&&E.push(...x),e},Nm=(e,{currentLineActions:t,previousPresentationState:n,resources:i={},isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})=>{let{animations:o}=e,l=t?.screen?.animations;if(!l)return e;let c=n!=null,u=Je({animationsDef:l,resources:i,previousResourceId:c?"story":void 0,currentResourceId:"story",previousTargetId:c?"story":void 0,currentTargetId:"story",animationPath:"screen.animations",idPrefix:"screen"});return qe({animationInstances:u,isLineCompleted:a,skipTransitionsAndAnimations:r,activePersistentAnimations:s})&&o.push(...u),e},Dm=(e,{presentationState:t})=>{let n=Ar(e.elements);return!n||!t?.screen||Object.assign(n,qa(t.screen)),e},Tm=(e,{presentationState:t,resources:n={},variables:i,imageGallery:a,musicRoom:r,sceneReplay:s,runtime:o,autoMode:l,skipMode:c,isChoiceVisible:u,isFormVisible:p,canRollback:m,form:d,overlayStack:f=[],dialogueHistory:y=[],saveSlots:g=[],screen:h,isLineCompleted:w,skipTransitionsAndAnimations:b})=>{let{elements:E,animations:v}=e;return f&&f.length>0&&f.forEach((k,x)=>{let C=n.layouts[k.resourceId];if(!C){console.warn(`Overlay layout not found: ${k.resourceId}`);return}Array.isArray(C.transitions)&&(b||mi({animations:v,transitions:C.transitions,defaultTargetId:`overlayStack-${x}`,idPrefix:`overlayStack-${x}`,animationPathPrefix:`overlayStack[${x}]`}));let N={id:`overlayStack-${x}`,type:"container",x:0,y:0,children:[Ua({id:`overlayStack-${x}-blocker`,screen:h}),...C.elements||[]]},P=Ba(y,n.characters,i),T=De({variables:i,imageGallery:a,musicRoom:r,sceneReplay:s,runtime:o,saveSlots:g,dialogueState:t?.dialogue,isLineCompleted:w,autoMode:l,skipMode:c,isChoiceVisible:u,isFormVisible:p,canRollback:m,form:d,historyDialogue:P,characters:n.characters||{},skipTransitionsAndAnimations:b}),q=He(N,T),[ae,...B]=q.children||[],ne=Ke(ar({...q,children:B},{isLineCompleted:w,skipMode:c,skipTransitionsAndAnimations:b}),n);E.push({...ne,children:ae?[ae,...ne.children||[]]:ne.children})}),e},Lm=(e,{presentationState:t,resources:n={},variables:i,imageGallery:a,musicRoom:r,sceneReplay:s,runtime:o,saveSlots:l=[],autoMode:c,skipMode:u,isChoiceVisible:p,isFormVisible:m,canRollback:d,form:f,confirmDialog:y,dialogueHistory:g=[],screen:h,isLineCompleted:w,skipTransitionsAndAnimations:b})=>{let{elements:E,animations:v}=e;if(!y?.resourceId)return e;let k=n.layouts?.[y.resourceId];if(!k)return console.warn(`ConfirmDialog layout not found: ${y.resourceId}`),e;Array.isArray(k.transitions)&&!b&&mi({animations:v,transitions:k.transitions,defaultTargetId:"confirmDialog",idPrefix:"confirmDialog",animationPathPrefix:"confirmDialog"});let x={id:"confirmDialog",type:"container",x:0,y:0,children:[Ua({id:"confirmDialog-blocker",screen:h}),...k.elements||[]]},C=Ba(g,n.characters,i),N=He(x,De({variables:i,imageGallery:a,musicRoom:r,sceneReplay:s,runtime:o,saveSlots:l,dialogueState:t?.dialogue,isLineCompleted:w,autoMode:c,skipMode:u,isChoiceVisible:p,isFormVisible:m,canRollback:d,form:f,confirmDialog:y,historyDialogue:C,characters:n.characters||{},skipTransitionsAndAnimations:b})),[P,...T]=N.children||[],q=Ke(ar({...N,children:T},{isLineCompleted:w,skipMode:u,skipTransitionsAndAnimations:b}),n);return E.push({...q,children:P?[P,...q.children||[]]:q.children}),e},bt=e=>(t,n)=>Am(t,{...n,visualLayer:e}),Mm=bt(Xe.BEHIND_BACKGROUND),qm=bt(Xe.BEHIND_CHARACTER),Vm=bt(Xe.BEHIND_DIALOGUE),Fm=bt(Xe.BEHIND_CHOICE),Um=bt(Xe.FOREGROUND),Ga=e=>Wt(bm,[Sm,Mm,wm,qm,Im,Vm,Pm,Fm,xm,Em,jm,Um,Dm,Nm,Om,Rm,Cm,$m,Tm,Lm])(e);function Xa(e,t=""){let n=[],i=e.length,a=0,r=0,s=-1,o=()=>{let l=0,c=0,u;do u=parseInt(e[a++],36),l+=(u&15)<<c,c+=4;while(u&16);return l};for(;a<i;){let l=s+1+o();s=l+o(),n.push([l,s,t?parseInt(t[r++],36):0])}return n}function Wa(e,t,n){let i=0,a=t.length-1;for(;i<=a;){let r=i+a>>>1,s=n[r];if(e<t[r])a=r-1;else if(e>s>>>5)i=r+1;else return s&31}return 0}var Ha="090001000h1v5g2903000hl2v6jh16ng1s210111110o35aa10u2k1g10l6600152113h2010u1q1r5aq3890o13181214r22k3158q2n1000v100h1k20000001207030001160721k171001h1j11610332010010321210090411021c1c02100o301201412230u1130b100h1j116111420120411001100k11l10051001h1j11611142011000321210072411021d0g10r3000000132120090o200200g1j11f2012031213711271t1001o301001000001121371b1f0c101h1l2011001031212000080a1t1001m40400102101600i11t301006c7i601008b6p41r10101041h3d0004115a1j290p3q223000511010100g1501010302003172030c0010016000e0i6v50n40n5tl12ir33s12t11u11cj30100060700010a90t220000l71i20m7203010241000502rd101004k300000006101027050920g3t22bk1300616g209030207u18c1000t10003010501b2o20000102000004g37070101o921c000640602001mcv3rg20000001o16d0c0m1fg6g2h30m10q55f1vm11c0ma0p1a42nc0ne1a090q3314902021204020112030318250105bb1201110i1021i15101131502141b15120511011k1155132040202510201010603060a1f02040104210b1g3290e0e0kn11vs12j11j3040pp12t80g6v1vmo7319g21g51gh103040n11010040j51i3f01q1h1d0m27p1a0000cs13200523j200010301010100v140018a4q2501010101c08000i1f12601011g3012215110u1a0001015000pcq181000100011000iji5fvc0u91g5bhg20ie0l94lo6002115303121s12240la1tj23h44tj11t45m4ah33q700000l3ep2021a200t220301012040a0i320j2040007f00100r20c100g3208000011531000s520201036020t900207l1101n311000000321210090a12634b910201l22001051020120011020000e1i520701020000n10h5001050000010000010001re0010323010001r11i520701000001q6000000107l600000230004gg12080001lc62027111n1000411230000000000t820321030030r10090n205001380800501020n2050c0001mc00002000000nc006150000i5l1100600010001q753011160000i441111000000rl11019100000c1h201043102n10ltk1f006eoss2b0202gs94r36si2033ku101m373h50b1rqs4113sli1t22m1uh2435070726u13k92rr7m34h380e0m141egl561g1261114k60ga6nn10t33sv13uf1jf0207150qt16t66pr60n23k6bf1f0e1l29g71c1e029j1n30p11ea0k1028139m16rb2v621122i52213040tf1u3b51n17127c0232041d120819052c28220104060306l5g3l4572g130152cqdl2c3o37a5o27u11c32d9m2cu2191obo57eh9gg1tv3",Ka="262122424333333393233393339333333333393393bf3b3b3b3b3f3f3bffff33b3bb33ff3f33b3b3333333bffff3b33bb33f33bffff33b3bb33ff3f33b3bbb333b3ff33b333f33b3b3b3b3333b3bf33b3bb39333b33b33b3b3b333b333333b3b33333f3b33b3ffb3f3fff3f3b33f35dc33333f3b3b3b33323333b3bb3b33b3fb3b3333b33333bff3b3f33bfb3b3ff3b3b3b3b3b333b333b3323e22442344444444444444444444444444444444444444444444444444444444444444444444444444444443333333333b3b3bb33333b353bff3b3b3b3f3ff3b3b333bfff3f33333fb3bb3fb3b3bb33232333f333fff333333333b3b3333bb3b39393f3b3fbf33bb3b393b3b3b3333b33b33b3bbb33b33ffff3b3333bb3933b3b3b333b3b3b3b3b33b3b3b33b3b3b33b3b33b33b3b3b3fffff3bb39b9b3b33b3bf3f3b33f3b3f93b33b3b3bb33b33b3b3b3333393b3b3b33b39bffb3b332333b333dd3b3333233332333333333333333333333333333444444444444a4444444444444344444444444444444444444444444444444444444444",Ja="0001000000010010000000100000000000000000000000000001000000010014000100000001001000010101100101100000000000000000000100000001111000010000000110101001110111111111000100000021001000010000000100100001000000011010000100000001111000013000000100140001000000010010";var Qa=65535,bi=40960,un=126976,rl=new Uint8Array(12288),tl=new Uint8Array(3072),nl=new Uint8Array(2816),sl,il;{let e=(a,r,s,o,l)=>{let c=r+a.length-1;for(let u=s<r?r:s,p=o>c?c:o;u<=p;u++)a[u-r]=l},t=new Uint32Array(320),n=new Uint32Array(320),i=0;for(let[a,r,s]of Xa(Ha,Ka))e(rl,0,a,r,s),e(tl,bi,a,r,s),e(nl,un,a,r,s),r>=65040&&!(a>=un&&r<=129791)&&(t[i]=a,n[i++]=r<<5|s);sl=t.slice(0,i),il=n.slice(0,i)}function Za(e){return e<12288?rl[e]:e<bi?e<12336?e>=12330?3:0:e<12443?e===12336||e===12349?4:e>=12441?3:0:e===12951||e===12953?4:0:e<44032?tl[e-bi]:e<55204?(e-44032)%28?8:7:e<57344?e<=55238?e>=55216?13:0:e>=55243&&e<=55291?12:0:e<65024?e===64286?3:0:e<65040?3:e>=un&&e<129792?nl[e-un]:e>=917504?e>921599?0:e>=917536&&e<917632||e>=917760&&e<918e3?3:2:Wa(e,sl,il)}var ol=Uint8Array.from(Ja,Number);function Bm(e){return e===2381||e===2509||e===2637||e===2765||e===2893||e===3149||e===3405||e===4153||e===6098||e===6752||e===6980||e===7083||e===43456||e===43766||e===68159||e===69939||e===70608||e===71998||e===72263||e===72345||e===73538}function el(e,t,n){switch(t){case 3:return e&24?n===8204?e&6:(e&24)===16||Bm(n)?e&6|16:e&6|8:e&6;case 4:return 2;case 10:return e&1^1;case 14:return(e&2)<<1|e&24;default:return 8}}function*al(e){let t=e.length;if(t===0)return;let n=e.codePointAt(0),i=n>Qa?2:1,a=Za(n),r=50200>>a&1?el(0,a,n):0,s=0,o=n,l=a;for(;i<t;){n=e.codePointAt(i);let c=n>Qa?2:1,u=Za(n),p=ol[a<<4|u],m;p===0?m=!0:p===1?m=!1:p===2?m=!(r&1):p===3?m=!(r&4):m=(r&24)!==16,r=50200>>u&1&&(r!==0||u!==3)?el(r,u,n):0,m&&(yield{segment:e.slice(s,i),index:s,input:e,_hd:o,_catBegin:l===15?0:l,_catEnd:a===15?0:a},s=i,o=n,l=u),i+=c,a=u}yield{segment:e.slice(s),index:s,input:e,_hd:o,_catBegin:l===15?0:l,_catEnd:a===15?0:a}}function*ll(e){for(let t of al(e))yield t.segment}{let e=al("_");ol._keep=[e,e.next()]}var cl=1e3,dl=50,Ym=0,ul=100,pl=50,zm=60,Gm=3,Xm=.5,Wm=2e4,Hm=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,Km=/^\s+$/u,fl,Jm=e=>{let t=`${e??""}`.normalize("NFC"),n=globalThis.Intl?.Segmenter;return typeof n!="function"?Array.from(ll(t)):(fl??=new n(void 0,{granularity:"grapheme"}),Array.from(fl.segment(t),({segment:i})=>i))},Qm=e=>Jm(e).reduce((t,n)=>Km.test(n)?t+Xm:Hm.test(n)?t+Gm:t+1,0),Zm=e=>2**(((Number.isFinite(e)?Math.min(ul,Math.max(Ym,e)):dl)-pl)/(ul-pl)),ml=({text:e="",baseDelay:t=cl,speed:n=dl}={})=>{let i=Number.isFinite(t)?Math.max(0,t):cl,a=Zm(n),r=Qm(e)*zm/a,s=Math.max(i,Wm);return Math.min(i+r,s)};var pn={manual:{enabled:!0,requireLineCompleted:!1},auto:{enabled:!1},applyMode:"persistent"},vl=1,Ai=1,Br="choice",lr="form",vt=()=>({manual:{...pn.manual},auto:{...pn.auto},applyMode:pn.applyMode}),ki=()=>({groupId:null,variantId:null,pageIndex:0}),ey="music-room:player",ry=new Set(["asset-unavailable","decode-failed","invalid-segment","invalid-position","playback-failed"]),mn=({bgmPlayback:e={commandId:0,operation:"resume"}}={})=>({trackId:null,pageIndex:0,status:"stopped",readiness:"idle",positionMs:0,durationMs:null,playback:null,seekFallback:null,bgmPlayback:e}),Pi=new Set,ty=new Set(["groupId","variantId"]),ny=new Set(["pageIndex"]),Yr=new Set,sy=new Set(["trackId"]),iy=new Set(["positionMs"]),oy=new Set(["pageIndex"]),xi=new Set,ay=new Set(["replayId"]),ly=new Set(["pageIndex"]),Ei=()=>({pageIndex:0}),Si=e=>{if((e.global.nextLineConfig?.applyMode??"persistent")!=="singleLine")return;let n=e.global.nextLineConfig?.auto?.enabled===!0;e.global.nextLineConfig={...vt()},n&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"})},D=e=>{let t=ye(e)?er(e):e;return structuredClone(t)},F=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),yn=e=>{let t=e.global.audioCommandId;if(!Number.isSafeInteger(t)||t<0)throw new Error("Internal audio command counter is invalid");if(t===Number.MAX_SAFE_INTEGER)throw new Error("Audio command counter is exhausted");return e.global.audioCommandId=t+1,e.global.audioCommandId},Al=e=>{let t=e.global.sceneReplayEntryId;if(!Number.isSafeInteger(t)||t<0)throw new Error("Internal scene replay entry counter is invalid");if(t===Number.MAX_SAFE_INTEGER)throw new Error("Scene replay entry counter is exhausted");return e.global.sceneReplayEntryId=t+1,e.global.sceneReplayEntryId},At=(e,t,n)=>({commandId:yn(e),operation:t,...n===void 0?{}:{positionMs:n}}),Oi=e=>{if(!Object.prototype.hasOwnProperty.call(e.global??{},"musicRoomPlayer"))return;let t=e.global.musicRoomPlayer,n=t.bgmPlayback;t.trackId!==null&&(n={commandId:yn(e),operation:"resume"}),e.global.musicRoomPlayer=mn({bgmPlayback:n})},kl=(e,t)=>{if(typeof t!="string"||t.length===0)throw new Error("Achievement action requires a non-empty resourceId");let n=e.projectData.resources?.achievements?.[t];if(!n)throw new Error(`Achievement resource "${t}" not found`);if(n.type!=="boolean"&&n.type!=="number")throw new Error(`Achievement resource "${t}" has invalid type "${n.type}"`);return n},kt=e=>String(e),Pl=()=>({sections:[],resources:[]}),cy=e=>F(e)?(Array.isArray(e.sections)||(e.sections=[]),Array.isArray(e.resources)||(e.resources=[]),e):Pl(),uy=e=>Array.isArray(e)?e.map(t=>t?.text??"").join(""):"",py=({sectionId:e,lineId:t,content:n,dialogueState:i,characterName:a})=>({sectionId:e,lineId:t,content:n,text:uy(n),characterId:i.characterId,character:{...i.character||{},name:a},characterName:a}),fy=()=>({resourceId:void 0}),dy=e=>{if(!F(e))return e;let t={...e};return Object.prototype.hasOwnProperty.call(t,"requireComplete")&&!Object.prototype.hasOwnProperty.call(t,"requireLineCompleted")&&(t.requireLineCompleted=t.requireComplete),delete t.requireComplete,t},Er=(e,t)=>{let n=e?.story?.scenes??{};for(let[i,a]of Object.entries(n))if(a?.sections?.[t])return{sceneId:i,section:a.sections[t]};return{sceneId:void 0,section:void 0}},xl=e=>{let t=e?.story?.scenes??{},n=new Map;for(let[i,a]of Object.entries(t)){let r=a?.sections??{};for(let s of Object.keys(r)){let o=n.get(s);if(o!==void 0)throw new Error(`Duplicate sectionId "${s}" found in scenes "${o}" and "${i}". Section IDs must be globally unique.`);n.set(s,i)}}},El=e=>{if(typeof e=="number"||typeof e!="string")return e;let t=Number(e);return Number.isFinite(t)?t:e},Sl=e=>{if(!Number.isInteger(e)||e<1)throw new Error("Malformed save slot formatVersion.");if(e!==vl)throw new Error(`Unsupported save slot formatVersion "${e}".`);return e},my=(e,t={})=>{let n;try{n=Sl(t.formatVersion)}catch(a){throw new Error(`Hydrated save slot "${e}" failed validation: ${a.message}`)}let i={...t,formatVersion:n,slotId:El(t.slotId??t.slotKey??e),savedAt:typeof t.savedAt=="number"?t.savedAt:t.date};return delete i.slotKey,delete i.date,i},yy=(e={})=>Object.fromEntries(Object.entries(e).map(([t,n])=>[t,my(t,n)])),Ol=e=>{if(!Array.isArray(e))return;let t=e.filter(({type:n})=>rb(n));return t.length>0?t:void 0},hy=e=>{!F(e)||!Array.isArray(e.timeline)||(e.returnabilityVersion=Ai,e.timeline.forEach(t=>{if(!F(t))return;typeof t.returnable!="boolean"&&delete t.returnable;let n=Ol(t.executedActions);if(n){t.executedActions=n;return}delete t.executedActions}))},yl=(e,t,n,i="viewedRegistry")=>{let a=t==="sections"?"sectionId":"resourceId";if(typeof e=="string"||typeof e=="number")return{[a]:String(e)};if(!F(e))throw new Error(`Malformed ${i}.${t}[${n}] entry.`);if(typeof e[a]!="string"||e[a].length===0)throw new Error(`Malformed ${i}.${t}[${n}] entry: missing ${a}.`);if(t==="sections"){let r={sectionId:e.sectionId};if(e.lastLineId!==void 0&&e.lastLineId!==null&&typeof e.lastLineId!="string")throw new Error(`Malformed ${i}.sections[${n}] entry: invalid lastLineId.`);return typeof e.lastLineId=="string"&&e.lastLineId.length>0&&(r.lastLineId=e.lastLineId),r}return{resourceId:e.resourceId}},gy=(e,t="viewedRegistry")=>{if(e===void 0)return Pl();if(!F(e))throw new Error(`Malformed ${t}.`);if(e.sections!==void 0&&!Array.isArray(e.sections))throw new Error(`Malformed ${t}.sections.`);if(e.resources!==void 0&&!Array.isArray(e.resources))throw new Error(`Malformed ${t}.resources.`);let n=e.sections??[],i=e.resources??[];return{sections:Object.values(Object.fromEntries(n.map((a,r)=>{let s=yl(a,"sections",r,t);return[s.sectionId,s]}))),resources:Object.values(Object.fromEntries(i.map((a,r)=>{let s=yl(a,"resources",r,t);return[s.resourceId,s]})))}},Rl=(e,t,n)=>{if(!F(e))throw new Error(`Malformed save slot ${n}.`);let{sectionId:i,lineId:a}=e;if(typeof i!="string"||i.length===0)throw new Error(`Malformed save slot ${n}: missing sectionId.`);if(typeof a!="string"||a.length===0)throw new Error(`Malformed save slot ${n}: missing lineId.`);let{sceneId:r,section:s}=Er(t,i);if(!s)throw new Error(`Malformed save slot ${n}: section "${i}" does not exist in projectData.`);if(!s.lines?.some(l=>l.id===a))throw new Error(`Malformed save slot ${n}: line "${a}" does not exist in section "${i}".`);return{sceneId:r,sectionId:i,lineId:a}},Cl=(e,t)=>e?.sectionId===t?.sectionId&&e?.lineId===t?.lineId,by=(e,t)=>{let{section:n}=Er(e,t?.sectionId);return n?.lines?.find(i=>i.id===t?.lineId)},wy=(e,t)=>{let{section:n}=Er(e,t?.sectionId),i=n?.lines?.findIndex(r=>r.id===t?.lineId);if(typeof i!="number"||i<0)return null;let a=n.lines[i+1];return a?{sectionId:t.sectionId,lineId:a.id}:null},_l=(e,t,n)=>{if(typeof t?.sectionId!="string")return!1;let{section:i}=Er(e,t.sectionId);return Cl({sectionId:t.sectionId,lineId:i?.lines?.[0]?.id},n)},Iy=new Set(["jumpToLine","rollbackByOffset","rollbackToLine","sectionTransition","resetStoryAtSection"]),Ur={always:"always",maybe:"maybe",never:"never"},vy=e=>{if(!Object.prototype.hasOwnProperty.call(e??{},"when"))return Ur.always;let t=e.when,n;if(t===null||typeof t=="boolean"||typeof t=="number")n=t;else if(F(t)&&Object.keys(t).length===1&&Object.prototype.hasOwnProperty.call(t,"literal"))n=t.literal;else return Ur.maybe;return n?Ur.always:Ur.never},$l=(e,t)=>{if(!Array.isArray(e?.branches))return!1;for(let n of e.branches){let i=vy(n);if(i!==Ur.never){if(t(n))return!0;if(i===Ur.always)return!1}}return!1},jl=e=>$l(e,t=>Object.entries(t?.actions??{}).some(([n,i])=>n==="conditional"?jl(i):Iy.has(n))),Nl=(e,t,n)=>$l(t,i=>Object.entries(i?.actions??{}).some(([a,r])=>a==="sectionTransition"?_l(e,r,n):a==="conditional"?Nl(e,r,n):!1)),Ay=(e,t,n)=>{if(!t)return!0;let i=by(n,e)?.actions;if(!F(i))return!0;if(_l(n,i.sectionTransition,t))return!1;let a=i.conditional;return a?!(Nl(n,a,t)||!(i.choice?.resourceId||i.form?.resourceId)&&!jl(a)&&Cl(wy(n,e),t)):!0},ky=(e,t,n)=>{if(!F(e)||!Array.isArray(e.timeline))return It({pointer:t,replayStartIndex:1});let i=new WeakSet,a=e.timeline.flatMap((c,u)=>{if(!F(c))return[];try{let p=Rl(c,n,`rollback.timeline[${u}]`),m=dn({sectionId:p.sectionId,lineId:p.lineId,rollbackPolicy:c.rollbackPolicy,returnable:c.returnable});typeof c.returnable=="boolean"&&i.add(m);let d=Ol(D(c.executedActions));return d&&(m.executedActions=d),[m]}catch{return[]}});if(a.length===0)return It({pointer:t,replayStartIndex:1});e.returnabilityVersion!==Ai&&a.forEach((c,u)=>{!i.has(c)&&!Ay(c,a[u+1],n)&&(c.returnable=!1)});let s=typeof e.currentIndex=="number"?Math.trunc(e.currentIndex):a.length-1;(s<0||s>=a.length)&&(s=a.length-1);let o=a[s];if(o?.sectionId!==t.sectionId||o?.lineId!==t.lineId){let c=a.findLastIndex(u=>u.sectionId===t.sectionId&&u.lineId===t.lineId);c>=0?s=c:(a.push(dn({sectionId:t.sectionId,lineId:t.lineId})),s=a.length-1)}let l=typeof e.replayStartIndex=="number"?Math.min(Math.max(Math.trunc(e.replayStartIndex),0),s):0;return{currentIndex:s,isRestoring:!1,replayStartIndex:l,timeline:a}},Py=(e,t,n)=>{if(!F(e))throw new Error(`Malformed save slot contexts[${n}] entry.`);let i=_i(t),a=Rl(e.pointers?.read,t,`contexts[${n}].pointers.read`);if(e.variables!==void 0&&!F(e.variables))throw new Error(`Malformed save slot contexts[${n}].variables entry.`);if(e.runtime!==void 0&&!F(e.runtime))throw new Error(`Malformed save slot contexts[${n}].runtime entry.`);let r=e.variables?Tr(D(e.variables),t.resources?.variables??{}):{},s=Ly({loadedContextRuntime:F(e.runtime)?D(e.runtime):{}}),o={currentPointerMode:"read",pointers:{read:a},configuration:F(e.configuration)?D(e.configuration):{},views:Array.isArray(e.views)?D(e.views):[],bgm:F(e.bgm)?D(e.bgm):{resourceId:void 0},variables:{...i,...r},rollback:ky(e.rollback,a,t)};return s&&(o.runtime=s),o},xy=(e,t)=>{if(!F(e))throw new Error("Malformed save slot state.");if(!Array.isArray(e.contexts)||e.contexts.length===0)throw new Error("Malformed save slot state: contexts must be a non-empty array.");return{contexts:e.contexts.map((n,i)=>Py(n,t,i))}},Ey=(e,t)=>{if(!F(e))throw new Error("Malformed save slot.");let n=Sl(e.formatVersion);return{...e,formatVersion:n,state:xy(e.state,t)}},hl=(e,t,{required:n=!1}={})=>{if(e===void 0){if(n)throw new Error(`showConfirmDialog requires ${t}`);return{hideConfirmDialog:{}}}if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`showConfirmDialog ${t} must be an action object`);let i=D(e),a=i.hideConfirmDialog??{};return delete i.hideConfirmDialog,{hideConfirmDialog:a,...i}},Sy=(e={})=>{if(!e?.resourceId)throw new Error("showConfirmDialog requires resourceId");return{resourceId:e.resourceId,confirmActions:hl(e.confirmActions,"confirmActions",{required:!0}),cancelActions:hl(e.cancelActions,"cancelActions")}},zr=e=>{Object.prototype.hasOwnProperty.call(e.global,"confirmDialog")&&(e.global.confirmDialog=null)},Oy=e=>(F(e.global.formDrafts)||(e.global.formDrafts={}),e.global.formDrafts),Gr=e=>{Object.prototype.hasOwnProperty.call(e.global,"formDrafts")&&(e.global.formDrafts={})},Dl=e=>{if(!(!F(e)||!e.animations))return{animations:D(e.animations)}},Ry=(e,t)=>{let n=Dl(t);if(n){e.global.pendingScreenTransition=n;return}delete e.global.pendingScreenTransition},Cy=e=>{let t=e?.id??e?.resourceId;return typeof t=="string"&&t.length>0?t:void 0},_y=(e,t)=>{let n=e?.sectionId,i=e?.lineId;if(!(!n||!i||!t))return`${n}:${i}:${t}`},fn=e=>String(e??""),Tl=(e,t)=>{let n=fn(t);return e?.trim===!0?n.trim():n},$y=e=>F(e?.fields)?Object.fromEntries(Object.entries(e.fields).filter(([,t])=>F(t)).map(([t,n])=>[t,{id:t,...D(n)}])):{},jy=(e,t)=>{if(!t||!F(e.global.formDrafts))return;let n=e.global.formDrafts[t];return F(n)?n:void 0},Ll=(e,t)=>{let n=Oy(e);F(n[t])||(n[t]={values:{},touched:{},errors:{},submitted:!1});let i=n[t];return F(i.values)||(i.values={}),F(i.touched)||(i.touched={}),F(i.errors)||(i.errors={}),typeof i.submitted!="boolean"&&(i.submitted=!1),i},Ri=(e,t)=>{let n=Tl(e,t);return e?.required===!0&&n.length===0?"required":null},Ny=({state:e,pointer:t})=>{if(!t?.sectionId||!t?.lineId)return{};let i=we({state:e},{sectionId:t.sectionId})?.lines||[],a=i.findIndex(r=>r.id===t.lineId);return a<0?{}:br(i.slice(0,a+1).map(r=>r.actions||{}))},Dy=({state:e,form:t,pointer:n})=>{if(!t?.resourceId)return null;let i=Cy(t),a=_y(n,i);if(!i||!a)return null;let r=jy(e,a),s=$y(t),o=hn({state:e}),l={},c=[],u={},p=!0;return Object.entries(s).forEach(([m,d])=>{let f=fn(o?.[d.variableId]),y=Object.prototype.hasOwnProperty.call(r?.values??{},m)?fn(r.values[m]):f,g=r?.touched?.[m]===!0,h=Ri(d,y),w=r?.submitted||g?h:null,b=typeof d.maxLength=="number"?Math.max(0,Math.round(d.maxLength)):void 0,E={id:m,variableId:d.variableId,value:y,initialValue:f,valid:!h,error:w,touched:g,required:d.required===!0,trim:d.trim===!0,placeholder:d.placeholder===void 0?"":String(d.placeholder),multiline:d.multiline===!0,...b!==void 0?{maxLength:b}:{}};h&&(p=!1),l[m]=E,c.push(E),u[m]=y}),{id:i,key:a,resourceId:t.resourceId,animations:t.animations,valid:p,submitted:r?.submitted===!0,fields:l,fieldList:c,values:u,submitActions:{submitForm:{formKey:a,actions:D(t.submitActions??{})}},cancelActions:{cancelForm:{formKey:a,actions:D(t.cancelActions??{})}}}},Pr=[],gl="line",Ci="interaction",dn=({sectionId:e,lineId:t,rollbackPolicy:n,returnable:i})=>({sectionId:e,lineId:t,rollbackPolicy:n??"free",...typeof i=="boolean"?{returnable:i}:{}}),_i=e=>{let t=ye(e)?er(e):e,{contextVariableDefaultValues:n}=Kt(t??{});return D(n)},Ml=()=>({...D(ft)}),ql=({loadedRuntime:e,runtimeIds:t,defaults:n={},path:i})=>{if(e===void 0)return{runtimeState:D(n),hasLoadedValues:!1};if(!F(e))throw new Error(`Malformed ${i}.`);let a=D(n),r=!1;return t.forEach(s=>{e[s]!==void 0&&(a[s]=Ul(s,D(e[s])),r=!0)}),{runtimeState:a,hasLoadedValues:r}},Ty=({loadedGlobalRuntime:e={}})=>ql({loadedRuntime:e,runtimeIds:Xs,defaults:wr,path:"global.runtime"}).runtimeState,Ly=({loadedContextRuntime:e={}})=>{let{runtimeState:t,hasLoadedValues:n}=ql({loadedRuntime:e,runtimeIds:Ws,defaults:Ml(),path:"context.runtime"});return n?t:void 0},Pt=e=>{let t=Array.isArray(e?.contexts)?e.contexts:[];return t[t.length-1]},te=e=>{let t=Pt(e);return t?.kind==="sceneReplay"&&F(t.sceneReplay)?t:null},Vl=(e,t)=>{let n=t?.sceneReplay?.replayId,i=e.projectData?.resources?.sceneReplay?.replays?.find(a=>a.id===n);Object.entries(i?.initialVariables??{}).forEach(([a,r])=>{t.variables[a]=D(r)})},My=e=>({autoMode:e.global.autoMode,skipMode:e.global.skipMode,dialogueUIHidden:e.global.dialogueUIHidden,nextLineConfig:D(e.global.nextLineConfig),overlayStack:D(e.global.overlayStack),confirmDialog:D(e.global.confirmDialog),formDrafts:D(e.global.formDrafts),isLineCompleted:e.global.isLineCompleted,...e.global.isDialogueHistoryShowing===void 0?{}:{isDialogueHistoryShowing:e.global.isDialogueHistoryShowing},...e.global.pendingScreenTransition===void 0?{}:{pendingScreenTransition:D(e.global.pendingScreenTransition)}}),qy=e=>{e.global.autoMode=!1,e.global.skipMode=!1,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,delete e.global.pendingScreenTransition,e.global.nextLineConfig=vt(),e.global.overlayStack=[],e.global.confirmDialog=null,e.global.formDrafts={},e.global.isLineCompleted=!0,e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"})},Vy=(e,t)=>{e.global.autoMode=t.autoMode,e.global.skipMode=t.skipMode,e.global.dialogueUIHidden=t.dialogueUIHidden,e.global.nextLineConfig=D(t.nextLineConfig),e.global.overlayStack=D(t.overlayStack),e.global.confirmDialog=D(t.confirmDialog),e.global.formDrafts=D(t.formDrafts),e.global.isLineCompleted=t.isLineCompleted,t.isDialogueHistoryShowing===void 0?delete e.global.isDialogueHistoryShowing:e.global.isDialogueHistoryShowing=t.isDialogueHistoryShowing,t.pendingScreenTransition===void 0?delete e.global.pendingScreenTransition:e.global.pendingScreenTransition=D(t.pendingScreenTransition),e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"});let n=Pe({state:e});e.global.autoMode&&e.global.isLineCompleted&&!n&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:Wr({state:e})}}),e.global.skipMode&&!n&&e.global.pendingEffects.push({name:"startSkipNextTimer"}),e.global.nextLineConfig.auto?.enabled&&!n&&(e.global.nextLineConfig.auto.trigger==="fromStart"||e.global.isLineCompleted)&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:e.global.nextLineConfig.auto.delay}})},Fy=e=>e.runtime?(Ws.forEach(t=>{e.runtime[t]===void 0&&(e.runtime[t]=D(ft[t]))}),e.runtime):(e.runtime=Ml(),e.runtime),Uy=e=>ya(e.global),Fl=e=>{e.global.pendingEffects.push({name:"saveGlobalRuntime",payload:{globalRuntime:Uy(e)}})},By=e=>ma[e],Yy=(e,t)=>{let n=By(e);if(n==="number"){if(typeof t!="number"||!Number.isFinite(t))throw new Error(`${e} requires a finite numeric value`);return}if(n==="boolean"){if(typeof t!="boolean")throw new Error(`${e} requires a boolean value`);return}if(n==="string"){if(typeof t!="string")throw new Error(`${e} requires a string value`);return}if(n==="nullableString"){if(t!==null&&typeof t!="string")throw new Error(`${e} requires a string or null value`);return}throw new Error(`Unsupported runtime field "${e}"`)},Ul=(e,t)=>{if(Yy(e,t),e==="autoForwardSpeed"&&(t<0||t>100))throw new Error("autoForwardSpeed requires a value between 0 and 100");return e==="saveLoadPagination"?Math.max(1,Math.trunc(t)):t},$i=(e,t,n)=>{let i=Ul(t,n);if(t in ft){let a=Pt(e);if(!a)return i;let r=Fy(a);return r[t]=i,i}return e.global[t]=i,i},ji=({pointer:e,projectData:t,kind:n,sceneReplay:i})=>({...n===void 0?{}:{kind:n},...i===void 0?{}:{sceneReplay:D(i)},currentPointerMode:"read",pointers:{read:D(e)},configuration:{},views:[],bgm:fy(),variables:_i(t),rollback:It({pointer:e})}),Xr=e=>e?(e.currentPointerMode="read",F(e.pointers)||(e.pointers={}),Object.prototype.hasOwnProperty.call(e.pointers,"history")&&delete e.pointers.history,e.pointers):null,zy=(e,{queueRender:t=!0}={})=>{let n=e.contexts?.[e.contexts.length-1],i=n?.pointers?.read;if(!n||!i?.sectionId||!i?.lineId)return null;let a=ji({pointer:i,projectData:e.projectData});return e.contexts[e.contexts.length-1]=a,Gy(e,{queueRender:t}),a},Gy=(e,{queueRender:t=!0}={})=>{e.global.autoMode=!1,e.global.skipMode=!1,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,zr(e),Gr(e),e.global.nextLineConfig=vt(),e.global.overlayStack=[],e.global.isLineCompleted=!0,Oi(e),e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"}),t&&e.global.pendingEffects.push({name:"render"})},Bl=e=>{!e||!("baselineVariables"in e)||delete e.baselineVariables},It=({pointer:e,replayStartIndex:t=0})=>{let n=e?.sectionId&&e?.lineId;return{currentIndex:n?0:-1,isRestoring:!1,replayStartIndex:t,timeline:n?[dn({sectionId:e.sectionId,lineId:e.lineId})]:[]}},Sr=(e,t={})=>{if(e?.rollback)return Bl(e.rollback),Array.isArray(e.rollback.timeline)||(e.rollback.timeline=[]),typeof e.rollback.currentIndex!="number"&&(e.rollback.currentIndex=e.rollback.timeline.length>0?e.rollback.timeline.length-1:-1),typeof e.rollback.isRestoring!="boolean"&&(e.rollback.isRestoring=!1),typeof e.rollback.replayStartIndex!="number"&&(e.rollback.replayStartIndex=0),e.rollback;let n=e?.pointers?.read;return e.rollback=It({pointer:n,replayStartIndex:t.compatibilityAnchor?1:0}),e.rollback},Ni=(e,t)=>{let n=e.contexts?.[e.contexts.length-1];if(!n)return;let i=Sr(n);i.isRestoring||(i.currentIndex<i.timeline.length-1&&(i.timeline=i.timeline.slice(0,i.currentIndex+1)),i.timeline.push(dn(t)),i.currentIndex=i.timeline.length-1)},Xy=({state:e})=>{let n=e.contexts?.[e.contexts.length-1]?.rollback;return!Array.isArray(n?.timeline)||typeof n.currentIndex!="number"?null:{checkpointIndex:n.currentIndex,checkpoint:n.timeline[n.currentIndex]??null}},Wy=({state:e},t={})=>{let{checkpointIndex:n,checkpointIdentity:i,sectionId:a,lineId:r}=t,o=e.contexts?.[e.contexts.length-1]?.rollback;if(!Number.isInteger(n)||!Array.isArray(o?.timeline)||typeof o.currentIndex!="number")return e;let l=o.timeline[n];return(ye(l)?vs(l):l)!==i||l?.sectionId!==a||l?.lineId!==r||(l.returnable=!1),e},Hy=({state:e},t={})=>{let{slotId:n,saveSlotIdentity:i,checkpointIndex:a,sectionId:r,lineId:s}=t,o=kt(n),l=e.global.saveSlots?.[o],c=ye(l)?vs(l):l;if(!l||c!==i)return e;let u=l.state?.contexts,p=Array.isArray(u)?u.at(-1):null,m=p?.rollback,d=m?.timeline?.[a];return!Number.isInteger(a)||m?.currentIndex!==a||p?.pointers?.read?.sectionId!==r||p?.pointers?.read?.lineId!==s||d?.sectionId!==r||d?.lineId!==s||(d.returnable=!1,m.returnabilityVersion=Ai,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}})),e},Ky=e=>{let n=e.contexts?.[e.contexts.length-1]?.rollback;if(!n||n.isRestoring||!Array.isArray(n.timeline)||typeof n.currentIndex!="number")return null;let i=Pr[Pr.length-1],a=typeof i?.checkpointIndex=="number"?i.checkpointIndex:n.currentIndex;return a<0||a>=n.timeline.length?null:(typeof i?.checkpointIndex!="number"&&a<n.timeline.length-1&&(n.timeline=n.timeline.slice(0,a+1)),n.timeline[a]??null)},Jy=({state:e},t={})=>{let n=t?.source===gl?gl:Ci,a=e.contexts?.[e.contexts.length-1]?.rollback;return!a||a.isRestoring||!Array.isArray(a.timeline)||typeof a.currentIndex!="number"||a.currentIndex<0||a.currentIndex>=a.timeline.length?(Pr.push({checkpointIndex:null,source:n}),e):(a.currentIndex<a.timeline.length-1&&(a.timeline=a.timeline.slice(0,a.currentIndex+1)),Pr.push({checkpointIndex:a.currentIndex,source:n}),e)},Qy=({state:e})=>(Pr.pop(),e),Be=(e,t,n)=>{let a=Pr[Pr.length-1]?.source??Ci;if(!tb(t,a))return;let r=Ky(e);r&&(Array.isArray(r.executedActions)||(r.executedActions=[]),r.executedActions.push({type:t,payload:D(n)}))},bl=(e,t)=>{let n=e.contexts?.[e.contexts.length-1];if(!n)return;let i=t?.operations??[];for(let{variableId:a,op:r,value:s,roundTo:o}of i){let l=e.projectData.resources?.variables?.[a],c=l?.scope,u=l?.type;if(Ne(l))throw new Error(`Cannot update computed variable: ${a}`);if(l?.readonly===!0)throw new Error(`Cannot update readonly variable: ${a}`);ut(c,a),Jt(u,r,a),Fs(u,r,s,a,{roundTo:o}),c==="context"&&(n.variables[a]=Qt(n.variables[a],r,s,{roundTo:o}))}},Zy=(e,t)=>{Array.isArray(t?.executedActions)&&t.executedActions.forEach(({type:n,payload:i})=>{nb(e,n,i)})},eh=(e,t)=>{let{sectionId:n,lineId:i}=t,s=we({state:e},{sectionId:n})?.lines?.find(o=>o.id===i)?.actions;s&&Object.entries(s).forEach(([o,l])=>{Ac(e,o,l)})},Yl=(e,t)=>{let n=e.contexts?.[e.contexts.length-1];if(!n)return e;let i=Sr(n),a=i.timeline[t];if(!a)return e;e.global.autoMode&&St({state:e}),e.global.skipMode&&cr({state:e}),e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),i.isRestoring=!0,i.currentIndex=t;try{n.variables=_i(e.projectData),n.kind==="sceneReplay"&&(Vl(e,n),n.sceneReplay.finishOnNextAdvance=!1,n.sceneReplay.exitOnLineCompleted=!1),delete n.runtime,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,e.global.nextLineConfig=D(pn),e.global.overlayStack=[],zr(e),Gr(e),e.global.isLineCompleted=!0;let r=i.replayStartIndex??0;for(let o=r;o<=t;o++)o>r&&Si(e),eh(e,i.timeline[o]),Zy(e,i.timeline[o]);let s=Xr(n);s.read={sectionId:a.sectionId,lineId:a.lineId},n.kind==="sceneReplay"&&(n.sceneReplay.entryId=Al(e)),e.global.pendingEffects=e.global.pendingEffects.filter(o=>o?.name!=="render"),e.global.pendingEffects.push({name:"render"})}finally{i.isRestoring=!1}return e},rh=e=>{let{projectData:t}=e,n=e.global??{},{saveSlots:i={},variables:a={},runtime:r={},accountViewedRegistry:s={},localizationPackages:o=[{l10nId:null,language:null}]}=n;xl(t),ot(t),at(t),lt(t),gr(t?.resources?.variables??{});let l=t.story.initialSceneId,c=t.story.scenes[l],u=c.initialSectionId,p=c.sections[u],m={sceneId:l,sectionId:u,lineId:p.initialLineId??p.lines[0].id},{globalVariablesDefaultValues:d}=Kt(t),f={...d,...Tr(a,t.resources?.variables??{})};return{projectData:t,global:{pendingEffects:[],confirmDialog:null,formDrafts:{},accountViewedRegistry:gy(s,"accountViewedRegistry"),nextLineConfig:vt(),imageGalleryNavigation:ki(),sceneReplayNavigation:Ei(),sceneReplayEntryId:0,audioCommandId:0,musicRoomPlayer:mn(),saveSlots:yy(i),localizationPackages:D(o),overlayStack:[],variables:f,...Ty({loadedGlobalRuntime:r})},contexts:[ji({pointer:m,projectData:t})]}},th=({state:e})=>e.global.overlayStack||[],nh=({state:e})=>e.global.pendingEffects,zl=({state:e})=>e.global.skipMode,sh=({state:e})=>e.global.autoMode,Gl=({state:e})=>e.global.dialogueUIHidden,Xl=({state:e})=>{let t=Array.isArray(e.contexts)?e.contexts:[],n=t[t.length-1];if(!n)return[];let{sectionId:i,lineId:a}=n.pointers.read,r=we({state:e},{sectionId:i});if(!r?.lines||!Array.isArray(r.lines))return[];let s=r.lines.findIndex(p=>p.id===a),o=r.lines.slice(0,s+1),l=[],c={},u=ct({variables:{...e.global?.variables??{},...Pt(e)?.variables??{}},runtime:Ir(e),variableConfigs:e.projectData.resources?.variables??{},eager:!1});for(let p of o){let m=p.actions||{};if(c=br([c,m]),!m.dialogue)continue;let d=c.dialogue||{},f=Ht({characterId:d.characterId,character:d.character,characters:e.projectData.resources?.characters??{},variables:u}),y=py({sectionId:i,lineId:p.id,content:m.dialogue.append===!0?d.content:m.dialogue.content,dialogueState:d,characterName:f});if(m.dialogue.append===!0&&l.length>0){l[l.length-1]={...l[l.length-1],content:y.content,text:y.text,characterId:y.characterId,character:y.character,characterName:y.characterName};continue}l.push(y)}return l},ih=({state:e})=>e.global.confirmDialog??null,xt=({state:e},{pointer:t}={})=>{let n=t??Te({state:e})?.pointer,i=Ny({state:e,pointer:n});return Dy({state:e,form:i.form,pointer:n})},oh=({state:e},{pointer:t}={})=>!!xt({state:e},{pointer:t}),Pe=({state:e},{pointer:t}={})=>{let n=xt({state:e},{pointer:t});if(n)return{source:lr,formId:n.id,formKey:n.key};let i=Ql({state:e,pointer:t});return i?{source:Br,resourceId:i}:null},ah=({state:e,registry:t},n)=>{let{sectionId:i,lineId:a}=n,s=(Array.isArray(t?.sections)?t.sections:[]).find(u=>u.sectionId===i);if(!s)return!1;if(s.lastLineId===void 0||a===void 0)return!0;let o=we({state:e},{sectionId:i});if(!o||!o.lines||!Array.isArray(o.lines))return s.lastLineId===a;let l=o.lines.findIndex(u=>u.id===s.lastLineId),c=o.lines.findIndex(u=>u.id===a);return l===-1||c===-1?s.lastLineId===a:c<=l},Di=({registry:e},t)=>{let{resourceId:n}=t;return!!(Array.isArray(e?.resources)?e.resources:[]).find(r=>r.resourceId===n)},Ti=({state:e},t)=>ah({state:e,registry:e.global.accountViewedRegistry},t),lh=({state:e},t)=>Di({registry:e.global.accountViewedRegistry},t),wt=(e,t)=>!Di({registry:e.global.accountViewedRegistry},{resourceId:t.imageId}),Li=e=>e.groups.length===0?0:Math.ceil(e.groups.length/e.pageSize),Mi=(e,t)=>{let n=Li(e);if(n===0)return 0;let i=Number.isInteger(t?.pageIndex)?t.pageIndex:0;return Math.min(Math.max(i,0),n-1)},wi=(e,t,n,i)=>{for(let a=n+i;a>=0&&a<t.length;a+=i)if(!wt(e,t[a]))return t[a]},ch=({state:e})=>{let t=e.projectData?.resources?.imageGallery;return t===void 0?void 0:D(t)},Wl=({state:e})=>{let t=e.projectData?.resources?.imageGallery;if(t===void 0)return null;let n=e.global.imageGalleryNavigation??ki(),i=Li(t),a=Mi(t,n),r=a*t.pageSize,s=t.groups.slice(r,r+t.pageSize).map(l=>({groupId:l.id,locked:wt(e,l.variants[0]),variants:l.variants.map(c=>({variantId:c.id,imageId:c.imageId,locked:wt(e,c)}))})),o=null;if(typeof n.groupId=="string"&&typeof n.variantId=="string"){let l=t.groups.findIndex(d=>d.id===n.groupId),c=t.groups[l],u=c?.variants.findIndex(d=>d.id===n.variantId),p=u===void 0||u<0?void 0:c.variants[u],m=l<0?-1:Math.floor(l/t.pageSize);p&&m===a&&!wt(e,p)&&(o={groupId:c.id,variantId:p.id,imageId:p.imageId,canMoveToPreviousVariant:wi(e,c.variants,u,-1)!==void 0,canMoveToNextVariant:wi(e,c.variants,u,1)!==void 0})}return{pageGroups:s,selection:o,pagination:{pageIndex:a,pageCount:i,canMoveToPreviousPage:a>0,canMoveToNextPage:a+1<i}}},qi=(e,t)=>!Di({registry:e.global.accountViewedRegistry},{resourceId:t.soundId}),Vi=e=>e.tracks.length===0?0:Math.ceil(e.tracks.length/e.pageSize),Fi=(e,t)=>{let n=Vi(e);if(n===0)return 0;let i=Number.isInteger(t?.pageIndex)?t.pageIndex:0;return Math.min(Math.max(i,0),n-1)},Ii=(e,t,n,i)=>{for(let a=n+i;a>=0&&a<t.length;a+=i)if(!qi(e,t[a]))return t[a]},Hl=e=>({trackId:e.id,soundId:e.soundId,title:e.title,artist:e.artist??null,album:e.album??null,description:e.description??null,coverImageId:e.coverImageId??null}),uh=(e,t)=>({...Hl(t),locked:qi(e,t)}),wl=e=>{let t=Math.floor(e/1e3),n=t%60,i=Math.floor(t/60);if(i<60)return`${i}:${String(n).padStart(2,"0")}`;let a=Math.floor(i/60),r=i%60;return`${a}:${String(r).padStart(2,"0")}:${String(n).padStart(2,"0")}`},ph=({state:e})=>{let t=e.projectData?.resources?.musicRoom;return t===void 0?void 0:D(t)},Kl=({state:e})=>{let t=e.projectData?.resources?.musicRoom;if(t===void 0)return null;let n=e.global.musicRoomPlayer??mn(),i=Vi(t),a=Fi(t,n),r=a*t.pageSize,s=t.tracks.slice(r,r+t.pageSize).map(u=>uh(e,u)),o=t.tracks.findIndex(u=>u.id===n.trackId),l=t.tracks[o],c=l?{...Hl(l),canPlayPreviousTrack:Ii(e,t.tracks,o,-1)!==void 0,canPlayNextTrack:Ii(e,t.tracks,o,1)!==void 0}:null;return{pageTracks:s,selection:c,playback:c?{status:n.status,readiness:n.readiness,positionMs:n.positionMs,durationMs:n.durationMs,positionText:wl(n.positionMs),durationText:n.durationMs===null?null:wl(n.durationMs),canPlay:n.status!=="playing",canPause:n.status==="playing",canSeek:n.readiness==="ready"&&n.durationMs!==null}:null,pagination:{pageIndex:a,pageCount:i,canMoveToPreviousPage:a>0,canMoveToNextPage:a+1<i}}},Ui=e=>e.replays.length===0?0:Math.ceil(e.replays.length/e.pageSize),Bi=(e,t)=>{let n=Ui(e);if(n===0)return 0;let i=Number.isInteger(t?.pageIndex)?t.pageIndex:0;return Math.min(Math.max(i,0),n-1)},fh=({state:e})=>{let t=e.projectData?.resources?.sceneReplay;return t===void 0?void 0:D(t)},dh=({state:e})=>te(e)!==null,mh=({state:e})=>{let t=te(e);return t?{replayId:t.sceneReplay.replayId,entryId:t.sceneReplay.entryId}:null},Jl=({state:e})=>{let t=e.projectData?.resources?.sceneReplay;if(t===void 0)return null;let n=e.global.sceneReplayNavigation??Ei(),i=Ui(t),a=Bi(t,n),r=a*t.pageSize,s=t.replays.slice(r,r+t.pageSize).map(l=>({replayId:l.id,title:l.title,thumbnailImageId:l.thumbnailImageId})),o=te(e);return{isActive:o!==null,activeReplayId:o?.sceneReplay.replayId??null,pageReplays:s,pagination:{pageIndex:a,pageCount:i,canMoveToPreviousPage:a>0,canMoveToNextPage:a+1<i}}},yh=({state:e})=>e.global.nextLineConfig,Ql=({state:e,pointer:t}={})=>{let n=t??Te({state:e})?.pointer;if(!n)return;let i=n?.sectionId,a=n?.lineId,s=we({state:e},{sectionId:i})?.lines||[],o=s.findIndex(c=>c.id===a);if(o<0)return;let l;for(let c of s.slice(0,o+1)){let u=c?.actions;if(u?.cleanAll&&(l=void 0),!u||!Object.prototype.hasOwnProperty.call(u,"choice")){l=void 0;continue}let p=u.choice;if(p?.resourceId){l=p.resourceId;continue}p?.animations||(l=void 0)}return l},Zl=({state:e})=>!!Ql({state:e}),hh=({state:e})=>structuredClone(e),gh=({state:e})=>D(e.projectData.resources?.achievements??{}),bh=({state:e},t)=>{let n=e.projectData.resources?.achievements?.[t?.resourceId];return n===void 0?void 0:D(n)},ec=({state:e})=>e.global.saveSlots,wh=({state:e},t)=>{let n=t?.slotId,i=kt(n);return e.global.saveSlots[i]},rc=({state:e})=>D(e.global.localizationPackages),Yi=({state:e})=>Ir(e),Ih=({state:e},t)=>ir(e,t?.runtimeId),hn=({state:e})=>{let t={...e.global?.variables??{},...Pt(e)?.variables??{}};return ct({variables:t,runtime:Ir(e),variableConfigs:e.projectData.resources?.variables??{}})},Te=({state:e})=>{let t=Array.isArray(e.contexts)?e.contexts:[],n=t[t.length-1];if(n)return{currentPointerMode:"read",pointer:n.pointers?.read}},we=({state:e},t)=>{let{sectionId:n}=t;return Er(e.projectData,n).section},gn=({state:e})=>{let t=Te({state:e});if(!t?.pointer)return;let{sectionId:n,lineId:i}=t.pointer,a=we({state:e},{sectionId:n});if(!(!a?.lines||!Array.isArray(a.lines)))return a.lines.find(r=>r.id===i)},tc=({state:e})=>{let{sectionId:t,lineId:n}=Te({state:e}).pointer,a=we({state:e},{sectionId:t})?.lines||[],r=a.findIndex(c=>c.id===n),o=a.slice(0,r+1).map(c=>{let u=c.actions||{},p={};return Object.keys(u).forEach(m=>{p[m]=u[m]}),p});return br(o)},vh=e=>{let t=gn({state:e})?.actions?.dialogue;if(t?.clear===!0||!Array.isArray(t?.content))return"";let n=hn({state:e});return t.content.map(i=>`${Lr(i?.text,{variables:n})??""}`).join("")},Wr=({state:e})=>ml({text:vh(e),baseDelay:ir(e,"autoForwardDelay"),speed:ir(e,"autoForwardSpeed")}),Ah=({state:e})=>{let t=nc({state:e}),i=gn({state:e})?.actions??{},a=br([t??{},i]);return Bs(t??{},a??{})},kh=({state:e},{sectionId:t})=>{let n=we({state:e},{sectionId:t});if(!n?.lines)return[];let i=[],a={};for(let r of n.lines){let s=r.actions||{},o=br([a,s]),l=Bs(a,o);i.push({id:r.id,changes:l,presentationState:o}),a=Ys(o)}return i},Ph=({state:e},{sectionId:t,includePresentationState:n=!1})=>{let i=kh({state:e},{sectionId:t});return n?{lines:i}:{lines:i.map(({presentationState:a,...r})=>r)}},nc=({state:e})=>{let{sectionId:t,lineId:n}=Te({state:e}).pointer,a=we({state:e},{sectionId:t})?.lines||[],r=a.findIndex(l=>l.id===n);if(r<=0)return null;let o=a.slice(0,r).map(l=>{let c=l.actions||{},u={};return Object.keys(c).forEach(p=>{u[p]=c[p]}),u});return Ys(br(o))},zi=({state:e},{slotsPerPage:t=6}={})=>{let a=((Yi({state:e}).saveLoadPagination??1)-1)*t+1,r=[];for(let s=0;s<t;s++){let o=a+s,l=e.global.saveSlots&&e.global.saveSlots[kt(o)]||{};r.push({...l,slotId:o})}return{saveSlots:r}},xh=ec,Eh=zi,Sh=e=>{let n=e.contexts?.[e.contexts.length-1]?.rollback;return!n||!Array.isArray(n.timeline)||typeof n.currentIndex!="number"?!1:n.currentIndex>=0&&n.currentIndex<n.timeline.length-1},Oh=({state:e},t={})=>{let n=tc({state:e}),i=nc({state:e}),a=gn({state:e})?.actions??{},r=e.global.pendingScreenTransition,s=r?.animations?{...a,screen:D(r)}:a,o=r?.animations&&i===null?{}:i,{sectionId:l}=Te({state:e}).pointer,{sceneId:c}=Er(e.projectData,l),u={...Yi({state:e}),localizationPackages:rc({state:e})},p=t?.activePersistentAnimations??[],m=t?.restoredPersistentAnimations??[],d=xt({state:e}),f=Zl({state:e}),y=Wl({state:e}),g=Kl({state:e}),h=Jl({state:e}),w=hn({state:e}),{saveSlots:b}=zi({state:e}),E=Sh(e);return Ga({presentationState:n,previousPresentationState:o,currentLineActions:s,resources:e.projectData.resources,currentSceneId:c,screen:e.projectData.screen,dialogueUIHidden:u.dialogueUIHidden,autoMode:u.autoMode,skipMode:u.skipMode,isChoiceVisible:f,isFormVisible:!!d,canRollback:xc({state:e}),skipOnlyViewedLines:!u.skipUnseenText,isLineCompleted:u.isLineCompleted,skipTransitionsAndAnimations:!!u.skipTransitionsAndAnimations||E,overlayStack:e.global.overlayStack,confirmDialog:e.global.confirmDialog,form:d,dialogueHistory:Xl({state:e}),saveSlots:b,variables:w,runtime:u,activePersistentAnimations:p,restoredPersistentAnimations:m,imageGallery:y,musicRoom:g,sceneReplay:h,musicRoomPlayer:D(e.global.musicRoomPlayer)})},Rh=({state:e},t)=>(e.global.confirmDialog=Sy(t),e.global.pendingEffects.push({name:"render"}),e),Ch=({state:e})=>(e.global.confirmDialog&&(zr(e),e.global.pendingEffects.push({name:"render"})),e),_h=({state:e},t)=>(e.global.overlayStack.push(t),e.global.pendingEffects.push({name:"render"}),Be(e,"pushOverlay",t),e),$h=({state:e})=>(e.global.overlayStack.pop(),e.global.pendingEffects.push({name:"render"}),Be(e,"popOverlay",void 0),e),jh=({state:e},t)=>(e.global.overlayStack.length>0&&(e.global.overlayStack[e.global.overlayStack.length-1]=t),e.global.pendingEffects.push({name:"render"}),Be(e,"replaceLastOverlay",t),e),Nh=({state:e})=>(e.global.overlayStack=[],zr(e),Gr(e),e.global.pendingEffects.push({name:"render"}),Be(e,"clearOverlays",void 0),e),Dh=(e,{activeInteraction:t})=>{e.global.autoMode&&e.global.pendingEffects.push({name:"clearAutoNextTimer"}),t&&e.global.skipMode&&e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.nextLineConfig?.auto?.enabled&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"})},Et=(e,t,{screenTransition:n}={})=>{e.global.isLineCompleted=!1,Ry(e,n),Gr(e);let i=Pe({state:e},{pointer:t}),a=i?.source===Br,r=i?.source===lr;Dh(e,{activeInteraction:i});let s=te(e),o={name:"handleLineActions"};if(typeof s?.sceneReplay?.replayId=="string"){let l=Al(e);s.sceneReplay.entryId=l,o.payload={sceneReplayId:s.sceneReplay.replayId,entryId:l}}return e.global.pendingEffects.push(o),{isChoiceVisible:a,isFormVisible:r,activeInteraction:i}},bn=(e,t,n)=>{!(t?.source===Br||t?.source===lr)||n||!e.global.skipMode||e.global.pendingEffects.push({name:"startSkipNextTimer"})},sc=({state:e})=>(Pe({state:e})||(e.global.skipMode&&(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"})),e.global.autoMode=!0,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.isLineCompleted&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:Wr({state:e})}}),e.global.pendingEffects.push({name:"render"})),e),St=({state:e})=>(e.global.autoMode=!1,e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Th=({state:e})=>{let t=e.global.autoMode;return Pe({state:e})&&!t||(t?St({state:e}):sc({state:e})),e},ic=({state:e})=>(Pe({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),cr=({state:e})=>(e.global.skipMode=!1,e.global.pendingEffects.push({name:"clearSkipNextTimer"}),e.global.pendingEffects.push({name:"render"}),e),Lh=({state:e})=>{let t=zl({state:e});return Pe({state:e})&&!t||(t?cr({state:e}):ic({state:e})),e},wn=({state:e})=>(e.global.dialogueUIHidden=!1,e.global.pendingEffects.push({name:"render"}),Be(e,"showDialogueUI",void 0),e),oc=({state:e})=>(e.global.dialogueUIHidden=!0,e.global.pendingEffects.push({name:"render"}),Be(e,"hideDialogueUI",void 0),e),Mh=({state:e})=>(Gl({state:e})?wn({state:e}):oc({state:e}),e),ur=(e,t,n)=>($i(e,t,n),Fl(e),e.global.pendingEffects.push({name:"render"}),e),Ot=(e,t,n,i)=>{let a=$i(e,t,n);return e.global.pendingEffects.push({name:"render"}),Be(e,i,{value:a}),e},qh=({state:e},t)=>ur(e,"dialogueTextSpeed",t?.value),Vh=({state:e},t)=>ur(e,"autoForwardDelay",t?.value),Fh=({state:e},t)=>ur(e,"autoForwardSpeed",t?.value),Uh=({state:e},t)=>ur(e,"skipUnseenText",t?.value),Bh=({state:e},t)=>ur(e,"skipTransitionsAndAnimations",t?.value),Yh=({state:e},t)=>ur(e,"soundVolume",t?.value),zh=({state:e},t)=>ur(e,"musicVolume",t?.value),Gh=({state:e},t)=>ur(e,"muteAll",t?.value),Xh=({state:e},t)=>Ot(e,"saveLoadPagination",t?.value,"setSaveLoadPagination"),Wh=({state:e})=>{let t=ir(e,"saveLoadPagination")+1;return Ot(e,"saveLoadPagination",t,"incrementSaveLoadPagination"),e},Hh=({state:e})=>{let t=ir(e,"saveLoadPagination")-1;return Ot(e,"saveLoadPagination",t,"decrementSaveLoadPagination"),e},Kh=({state:e},t)=>Ot(e,"menuPage",t?.value,"setMenuPage"),Jh=({state:e},t)=>Ot(e,"menuEntryPoint",t?.value,"setMenuEntryPoint"),Qh=({state:e})=>(e.global.pendingEffects=[],e),Zh=({state:e},t)=>(e.global.pendingEffects.push(t),e),eg=({state:e},t)=>{if(te(e))return e;let n=t?.resourceId;return kl(e,n),e.global.pendingEffects.push({name:"completeAchievement",payload:{resourceId:n}}),e},rg=({state:e},t)=>{if(te(e))return e;let n=t?.resourceId,i=kl(e,n);if(i.type!=="number")throw new Error(`Achievement resource "${n}" does not support numeric progress`);let a=t?.current;if(!Number.isInteger(a)||a<0)throw new Error(`Achievement progress for "${n}" must be a non-negative integer`);if(!Number.isInteger(i.target)||i.target<1)throw new Error(`Achievement resource "${n}" must have a positive integer target`);let r=Math.min(a,i.target);return e.global.pendingEffects.push({name:"setAchievementProgress",payload:{resourceId:n,current:r,target:i.target,completed:r>=i.target}}),e},ac=(e,{sectionId:t,resetStoryState:n=!1,screen:i})=>{let a=!!Dl(i),r=we({state:e},{sectionId:t});if(!r)return console.warn(`Section not found: ${t}`),e;let s=r.lines?.[0];if(!s)return console.warn(`Section ${t} has no lines`),e;if(n&&!zy(e,{queueRender:!a}))return e;let o=Pe({state:e});n&&e.global.skipMode&&cr({state:e});let l=e.contexts?.[e.contexts.length-1];if(l){let u=Xr(l),p=u.read;n||xr(e,{sectionId:p?.sectionId,lineId:p?.lineId}),l.rollback||Sr(l,{compatibilityAnchor:!0}),u.read={sectionId:t,lineId:s.id},n?l.rollback=It({pointer:u.read}):Ni(e,{sectionId:t,lineId:s.id})}let{activeInteraction:c}=Et(e,l?.pointers?.read,{screenTransition:i});return bn(e,o,c),e},tg=({state:e},t)=>{if(te(e))throw new Error("Cannot reset the story while a scene replay is active");return ac(e,{sectionId:t?.sectionId,resetStoryState:!0,screen:t?.screen})},lc=e=>(e.global.accountViewedRegistry=cy(e.global.accountViewedRegistry),e.global.accountViewedRegistry),Gi=(e,t)=>{!Array.isArray(t)||t.length===0||e.global.pendingEffects.push({name:"applyScopedDataUpdates",payload:{updates:t.map(n=>({scope:n.scope,path:n.path,op:n.op,value:D(n.value)}))}})},cc=(e,t)=>{Gi(e,[{scope:"account",path:"viewedRegistry",op:"markViewed",value:{sections:(Array.isArray(t?.sections)?t.sections:[]).map(n=>({sectionId:n.sectionId,...n.lastLineId===void 0?{}:{lineId:n.lastLineId}})),resources:Array.isArray(t?.resources)?t.resources:[]}}])},ng=(e,t,{sectionId:n,lineId:i})=>{if(!n||!i)return!1;let a=F(t)?t:{};Array.isArray(a.sections)||(a.sections=[]);let r=a.sections.find(s=>s.sectionId===n);if(r){if(r.lastLineId===void 0)return!1;let s=we({state:e},{sectionId:n});if(s?.lines){let o=s.lines.findIndex(c=>c.id===r.lastLineId),l=s.lines.findIndex(c=>c.id===i);if(o===-1||l>o)return r.lastLineId===i?!1:(r.lastLineId=i,!0)}else return r.lastLineId===i?!1:(r.lastLineId=i,!0);return!1}else return a.sections.push({sectionId:n,lastLineId:i}),!0},xr=(e,t)=>{if(te(e)||e.global.accountViewedRegistry===void 0)return;ng(e,lc(e),t)&&cc(e,{sections:[{sectionId:t.sectionId,lastLineId:t.lineId}],resources:[]})},sg=({state:e},t)=>(xr(e,t),e.global.pendingEffects.push({name:"render"}),e),ig=({state:e},t)=>{if(te(e))return e;let{resourceId:n}=t;if(e.global.accountViewedRegistry!==void 0){let i=lc(e);i.resources.find(r=>r.resourceId===n)||(i.resources.push({resourceId:n}),cc(e,{sections:[],resources:[{resourceId:n}]}))}return e.global.pendingEffects.push({name:"render"}),e},Ye=(e,t,n)=>{if(!F(t))throw new Error(`${e} payload must be an object`);Object.keys(t).forEach(i=>{if(!n.has(i))throw new Error(`${e} payload contains unsupported property "${i}"`)})},vi=(e,t,n)=>{if(typeof n!="string"||n.length===0)throw new Error(`${e} requires a non-empty ${t}`)},In=(e,t)=>{let n=e.global.imageGalleryNavigation;n.groupId===t.groupId&&n.variantId===t.variantId&&n.pageIndex===t.pageIndex||(e.global.imageGalleryNavigation=t,e.global.pendingEffects.push({name:"render"}))},og=({state:e},t)=>{let n="showImageGalleryVariant";Ye(n,t,ty),vi(n,"groupId",t.groupId),Object.prototype.hasOwnProperty.call(t,"variantId")&&vi(n,"variantId",t.variantId);let i=e.projectData?.resources?.imageGallery;if(i===void 0)return e;let a=i.groups.findIndex(o=>o.id===t.groupId),r=i.groups[a];if(!r)return e;let s=t.variantId===void 0?r.variants[0]:r.variants.find(o=>o.id===t.variantId);return!s||wt(e,s)||In(e,{groupId:r.id,variantId:s.id,pageIndex:Math.floor(a/i.pageSize)}),e},uc=(e,t,n,i)=>{Ye(i,t,Pi);let a=e.projectData?.resources?.imageGallery;if(a===void 0)return e;let r=e.global.imageGalleryNavigation;if(typeof r.groupId!="string"||typeof r.variantId!="string")return e;let s=a.groups.find(c=>c.id===r.groupId),o=s?.variants.findIndex(c=>c.id===r.variantId);if(!s||o===void 0||o<0)return e;let l=wi(e,s.variants,o,n);return l&&In(e,{...r,variantId:l.id}),e},ag=({state:e},t)=>uc(e,t,-1,"moveToPreviousImageGalleryVariant"),lg=({state:e},t)=>uc(e,t,1,"moveToNextImageGalleryVariant"),cg=({state:e},t)=>{if(Ye("clearImageGallerySelection",t,Pi),e.projectData?.resources?.imageGallery===void 0)return e;let i=e.global.imageGalleryNavigation;return In(e,{groupId:null,variantId:null,pageIndex:i.pageIndex}),e},pc=(e,t)=>{let n=e.projectData?.resources?.imageGallery;if(n===void 0)return e;let i=Li(n);if(t>=i)return e;let a=e.global.imageGalleryNavigation,r=Mi(n,a);return t===r||In(e,{groupId:null,variantId:null,pageIndex:t}),e},ug=({state:e},t)=>{if(Ye("moveToImageGalleryPage",t,ny),!Number.isInteger(t.pageIndex)||t.pageIndex<0)throw new Error("moveToImageGalleryPage requires a non-negative integer pageIndex");return pc(e,t.pageIndex)},fc=(e,t,n,i)=>{Ye(i,t,Pi);let a=e.projectData?.resources?.imageGallery;if(a===void 0)return e;let s=Mi(a,e.global.imageGalleryNavigation)+n;return s<0?e:pc(e,s)},pg=({state:e},t)=>fc(e,t,1,"moveToNextImageGalleryPage"),fg=({state:e},t)=>fc(e,t,-1,"moveToPreviousImageGalleryPage"),Qe=(e,t,n)=>{if(!F(t))throw new Error(`${e} payload must be an object`);Object.keys(t).forEach(i=>{if(!n.has(i))throw new Error(`${e} payload contains unsupported property "${i}"`)})},dg=(e,t)=>{if(typeof t!="string"||t.length===0)throw new Error(`${e} requires a non-empty trackId`)},Ve=e=>{e.global.pendingEffects.push({name:"render"})},dc=(e,t)=>{let n=e.projectData.resources.musicRoom,i=e.global.musicRoomPlayer,a=i.trackId!==null,r=i.trackId===t.id,s=i.bgmPlayback;a||(s={commandId:yn(e),operation:"pause"});let o=At(e,"play",0),l=n.tracks.indexOf(t),c=r?i.durationMs:null;e.global.musicRoomPlayer={trackId:t.id,pageIndex:Math.floor(l/n.pageSize),status:"playing",readiness:c===null?"loading":"ready",positionMs:0,durationMs:c,playback:o,seekFallback:null,bgmPlayback:s},Ve(e)},mg=({state:e},t)=>{let n="playMusicRoomTrack";Qe(n,t,sy),dg(n,t.trackId);let a=e.projectData?.resources?.musicRoom?.tracks.find(r=>r.id===t.trackId);return!a||qi(e,a)||dc(e,a),e},yg=({state:e},t)=>{Qe("playMusicRoom",t,Yr);let i=e.global.musicRoomPlayer;if(i.trackId===null||i.status==="playing")return e;let a=i.status==="ended",r=i.readiness==="error",s=i.status==="paused"&&!r?"resume":"play",o=a?0:i.positionMs;return i.playback=At(e,s,s==="play"?o:void 0),i.seekFallback=null,i.status="playing",i.positionMs=o,r&&(i.readiness=i.durationMs===null?"loading":"ready"),Ve(e),e},hg=({state:e},t)=>{Qe("pauseMusicRoom",t,Yr);let i=e.global.musicRoomPlayer;return i.trackId===null||i.status!=="playing"||(i.playback=At(e,"pause"),i.seekFallback=null,i.status="paused",Ve(e)),e},gg=({state:e},t)=>{Qe("stopMusicRoom",t,Yr);let i=e.global.musicRoomPlayer;return i.trackId===null||i.status==="stopped"&&i.positionMs===0||(i.playback=At(e,"stop"),i.seekFallback=null,i.status="stopped",i.positionMs=0,Ve(e)),e},bg=({state:e},t)=>{if(Qe("seekMusicRoom",t,iy),typeof t.positionMs!="number"||!Number.isFinite(t.positionMs)||t.positionMs<0)throw new Error("seekMusicRoom requires a finite non-negative positionMs");let i=e.global.musicRoomPlayer;if(i.trackId===null||i.readiness!=="ready"||i.durationMs===null||t.positionMs>i.durationMs)return e;let a=At(e,"seek",t.positionMs);return i.seekFallback={commandId:a.commandId,status:i.status,positionMs:i.positionMs},i.playback=a,i.positionMs=t.positionMs,t.positionMs===i.durationMs?i.status="ended":i.status==="ended"&&(i.status="stopped"),Ve(e),e},mc=(e,t,n,i)=>{Qe(i,t,Yr);let a=e.projectData?.resources?.musicRoom,r=e.global.musicRoomPlayer;if(!a||r.trackId===null)return e;let s=a.tracks.findIndex(l=>l.id===r.trackId);if(s<0)return e;let o=Ii(e,a.tracks,s,n);return o&&dc(e,o),e},wg=({state:e},t)=>mc(e,t,-1,"playPreviousMusicRoomTrack"),Ig=({state:e},t)=>mc(e,t,1,"playNextMusicRoomTrack"),vg=({state:e},t)=>{Qe("clearMusicRoomSelection",t,Yr);let i=e.global.musicRoomPlayer;if(i.trackId===null)return e;let a=i.pageIndex,r={commandId:yn(e),operation:"resume"};return e.global.musicRoomPlayer={...mn({bgmPlayback:r}),pageIndex:a},Ve(e),e},yc=(e,t)=>{let n=e.projectData?.resources?.musicRoom;if(!n||t>=Vi(n))return e;let i=e.global.musicRoomPlayer,a=Fi(n,i);return t===a||(i.pageIndex=t,Ve(e)),e},Ag=({state:e},t)=>{if(Qe("moveToMusicRoomPage",t,oy),!Number.isInteger(t.pageIndex)||t.pageIndex<0)throw new Error("moveToMusicRoomPage requires a non-negative integer pageIndex");return yc(e,t.pageIndex)},hc=(e,t,n,i)=>{Qe(i,t,Yr);let a=e.projectData?.resources?.musicRoom;if(!a)return e;let r=Fi(a,e.global.musicRoomPlayer)+n;return r<0?e:yc(e,r)},kg=({state:e},t)=>hc(e,t,1,"moveToNextMusicRoomPage"),Pg=({state:e},t)=>hc(e,t,-1,"moveToPreviousMusicRoomPage"),kr=e=>{let t=te(e);if(!t)return!1;if(e.contexts.length<2)throw new Error("Scene replay context has no caller context to restore");let n=D(t.sceneReplay.returnState),i=t.sceneReplay.replayId;return e.global.pendingEffects=e.global.pendingEffects.filter(a=>a?.name!=="handleLineActions"||a?.payload?.sceneReplayId!==i),e.contexts.pop(),Vy(e,n),e.global.pendingEffects.push({name:"render"}),!0},xg=({state:e},t)=>{let n="startSceneReplay";if(Ye(n,t,ay),vi(n,"replayId",t.replayId),te(e))throw new Error("Cannot start a scene replay while another replay is active");let a=e.projectData?.resources?.sceneReplay?.replays.find(u=>u.id===t.replayId);if(!a)return e;let{sceneId:r,section:s}=Er(e.projectData,a.startSectionId),o=s?.initialLineId??s?.lines?.[0]?.id;if(!s||!o||!s.lines.some(u=>u.id===o))throw new Error(`Scene replay "${a.id}" has an invalid start section`);let l=My(e);qy(e);let c=ji({pointer:{sceneId:r,sectionId:a.startSectionId,lineId:o},projectData:e.projectData,kind:"sceneReplay",sceneReplay:{replayId:a.id,entryId:0,finishOnNextAdvance:!1,exitOnLineCompleted:!1,returnState:l}});return Vl(e,c),e.contexts.push(c),Et(e,c.pointers.read),e},gc=({state:e},t)=>{Ye("finishSceneReplay",t,xi);let i=te(e);return i&&(i.sceneReplay.finishOnNextAdvance=!0),e},Eg=({state:e},t)=>(Ye("exitSceneReplay",t,xi),kr(e),e),bc=(e,t)=>{let n=e.projectData?.resources?.sceneReplay;if(!n||t>=Ui(n))return e;let i=Bi(n,e.global.sceneReplayNavigation);return t===i||(e.global.sceneReplayNavigation.pageIndex=t,e.global.pendingEffects.push({name:"render"})),e},Sg=({state:e},t)=>{if(Ye("moveToSceneReplayPage",t,ly),!Number.isInteger(t.pageIndex)||t.pageIndex<0)throw new Error("moveToSceneReplayPage requires a non-negative integer pageIndex");return bc(e,t.pageIndex)},wc=(e,t,n,i)=>{Ye(i,t,xi);let a=e.projectData?.resources?.sceneReplay;if(!a)return e;let r=Bi(a,e.global.sceneReplayNavigation)+n;return r<0?e:bc(e,r)},Og=({state:e},t)=>wc(e,t,1,"moveToNextSceneReplayPage"),Rg=({state:e},t)=>wc(e,t,-1,"moveToPreviousSceneReplayPage"),vn=(e,t)=>{let n=e.global.musicRoomPlayer;return!F(t)||t.id!==ey||n.trackId===null||!n.playback||t.commandId!==n.playback.commandId?null:n},Xi=e=>typeof e.positionMs=="number"&&Number.isFinite(e.positionMs)&&e.positionMs>=0&&typeof e.durationMs=="number"&&Number.isFinite(e.durationMs)&&e.durationMs>0&&e.positionMs<=e.durationMs,Ic=(e,t,n,{readiness:i=t.readiness}={})=>((t.readiness!==i||t.positionMs!==n.positionMs||t.durationMs!==n.durationMs||t.seekFallback!==null)&&(t.readiness=i,t.positionMs=n.positionMs,t.durationMs=n.durationMs,t.seekFallback=null,Ve(e)),e),Cg=({state:e},t)=>{let n=vn(e,t);return!n||n.readiness!=="loading"||!Xi(t)?e:Ic(e,n,t,{readiness:"ready"})},_g=({state:e},t)=>{let n=vn(e,t);return!n||n.readiness!=="ready"||!Xi(t)||n.status==="stopped"&&t.positionMs!==0||n.status==="ended"&&t.positionMs!==t.durationMs?e:Ic(e,n,t)},$g=({state:e},t)=>{let n=vn(e,t);return!n||n.readiness!=="ready"||n.status!=="playing"||!Xi(t)||t.positionMs!==t.durationMs||(n.status="ended",n.positionMs=t.positionMs,n.durationMs=t.durationMs,n.seekFallback=null,Ve(e)),e},jg=({state:e},t)=>{let n=vn(e,t);if(!n||typeof t.errorCode!="string"||!ry.has(t.errorCode)||n.readiness==="error"&&n.status==="stopped")return e;if(t.errorCode==="invalid-position"){let i=n.seekFallback;if(n.playback.operation!=="seek"||i?.commandId!==t.commandId)return e;let a=n.status!==i.status||n.positionMs!==i.positionMs;return n.status=i.status,n.positionMs=i.positionMs,n.seekFallback=null,a&&Ve(e),e}return n.readiness="error",n.status="stopped",n.positionMs=0,n.seekFallback=null,Ve(e),e},vc=({state:e},t)=>{let n=dy(t.manual),{auto:i,applyMode:a}=t,r=e.global.nextLineConfig.auto?.enabled,s=e.global.nextLineConfig?.applyMode,o=e.contexts?.[e.contexts.length-1]?.rollback?.isRestoring===!0;n&&i?(e.global.nextLineConfig={manual:n,auto:i},a!==void 0?e.global.nextLineConfig.applyMode=a:s!==void 0&&(e.global.nextLineConfig.applyMode=s)):(n&&(e.global.nextLineConfig.manual=n),i&&(e.global.nextLineConfig.auto=i),a!==void 0&&(e.global.nextLineConfig.applyMode=a));let l=e.global.nextLineConfig.auto?.enabled,c=Pe({state:e});return!o&&!c&&l===!0&&!r?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}}):!o&&l===!1&&r&&e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.pendingEffects.push({name:"render"}),Be(e,"setNextLineConfig",t),e},Ng=({state:e},t)=>{if(te(e))throw new Error("Cannot save while a scene replay is active");let n=t?.slotId;if(n==null||n==="")throw new Error("saveSlot requires slotId");let{thumbnailImage:i}=t,a=t?.savedAt,r=kt(n),s=D(e.contexts);s?.forEach(c=>{Xr(c),Bl(c.rollback),hy(c.rollback)});let o={contexts:s},l={formatVersion:vl,slotId:El(n),savedAt:typeof a=="number"?a:Date.now(),image:i,state:o};return e.global.saveSlots[r]=l,e.global.pendingEffects.push({name:"saveSlots",payload:{saveSlots:{...e.global.saveSlots}}},{name:"render"}),e},Dg=({state:e},t)=>{if(te(e))throw new Error("Cannot load while a scene replay is active");let n=t?.slotId;if(n==null||n==="")throw new Error("loadSlot requires slotId");let i=kt(n),a=e.global.saveSlots[i];if(a){let r=Ey(a,e.projectData);e.contexts=r.state.contexts,e.global.autoMode=!1,e.global.skipMode=!1,e.global.dialogueUIHidden=!1,delete e.global.isDialogueHistoryShowing,e.global.nextLineConfig=vt(),e.global.overlayStack=[],e.global.isLineCompleted=!0,zr(e),Gr(e),Oi(e),e.global.pendingEffects.push({name:"clearAutoNextTimer"},{name:"clearSkipNextTimer"},{name:"clearNextLineConfigTimer"},{name:"render"})}return e},Tg=({state:e},t)=>{if(te(e))throw new Error("Cannot update project data while a scene replay is active");let{projectData:n}=t;xl(n),ot(n),at(n),lt(n),gr(n?.resources?.variables??{}),e.projectData=n,e.global.imageGalleryNavigation=ki(),e.global.sceneReplayNavigation=Ei(),Oi(e);let i=n?.resources?.variables??{},{contextVariableDefaultValues:a,globalVariablesDefaultValues:r}=Kt(n??{});return Object.prototype.hasOwnProperty.call(e.global??{},"variables")&&(e.global.variables={...r,...Tr(e.global.variables,i)}),e.contexts?.forEach(s=>{Object.prototype.hasOwnProperty.call(s??{},"variables")&&(s.variables={...a,...Tr(s.variables,i)})}),zr(e),Gr(e),e.global.pendingEffects.push({name:"render"}),e},Lg=({state:e},t)=>{let{l10nId:n,projectData:i}=t??{};if(n!==null&&(typeof n!="string"||n.length===0))throw new Error("updateLocalizationPackage requires l10nId or null");if(!F(i))throw new Error("updateLocalizationPackage requires resolved projectData internally");return e.projectData=i,$i(e,"localizationPackageId",n),Fl(e),e.global.pendingEffects.push({name:"clearAutoNextTimer"}),e.global.autoMode&&e.global.isLineCompleted&&!Pe({state:e})&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:Wr({state:e})}}),e.global.pendingEffects.push({name:"render"}),e},Mg=({state:e},t)=>{let{sectionId:n,lineId:i}=t;if(!i)return console.warn("jumpToLine requires lineId parameter"),e;let a=e.contexts[e.contexts.length-1];if(!a)return console.warn("No context available for jumpToLine"),e;let r=n||a.pointers.read?.sectionId;if(n&&!we({state:e},{sectionId:n}))return console.warn(`Section not found: ${n}`),e;let s=we({state:e},{sectionId:r});if(!s?.lines||!Array.isArray(s.lines))return console.warn(`Section ${r} has no lines`),e;if(!s.lines.find(p=>p.id===i))return console.warn(`Line not found: ${i} in section ${r}`),e;let l=Pe({state:e}),c=Xr(a);c.read={sectionId:r,lineId:i};let{activeInteraction:u}=Et(e,c.read);return bn(e,l,u),e},qg=({state:e},t)=>{if(!e.global.nextLineConfig.manual.enabled)return e;if(e.global.dialogueUIHidden)return wn({state:e}),e;let n=Pe({state:e});if(n?.source===Br&&t?.bypassChoice!==!0||n?.source===lr&&t?._interactionSource!==lr)return e;if(!e.global.isLineCompleted){if(e.global.isLineCompleted=!0,delete e.global.pendingScreenTransition,te(e)?.sceneReplay.exitOnLineCompleted)return kr(e),e;let m=Te({state:e})?.pointer,d=m?.sectionId,f=m?.lineId;d&&f&&xr(e,{sectionId:d,lineId:f}),e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}),e.global.autoMode&&!n&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:Wr({state:e})}});let y=e.global.nextLineConfig;return y?.auto?.enabled&&!n&&y.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:y.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e}if(te(e)?.sceneReplay.finishOnNextAdvance)return kr(e),e;let a=Te({state:e})?.pointer,r=a?.sectionId,s=we({state:e},{sectionId:r}),o=e.contexts[e.contexts.length-1],l=s?.lines||[],u=l.findIndex(p=>p.id===a?.lineId)+1;if(u<l.length){let p=l[u],m=!ir(e,"skipUnseenText");if(e.global.skipMode&&m&&!Ti({state:e},{sectionId:r,lineId:p.id}))return cr({state:e}),e;if(o&&!o.rollback&&Sr(o,{compatibilityAnchor:!0}),o){let f=Xr(o),y=f.read?.lineId;y&&r&&xr(e,{sectionId:r,lineId:y}),f.read={sectionId:r,lineId:p.id}}Ni(e,{sectionId:r,lineId:p.id}),Si(e);let{activeInteraction:d}=Et(e,{sectionId:r,lineId:p.id});bn(e,n,d)}else{if(te(e))return console.warn("Scene replay reached the end of a section without finishSceneReplay; exiting replay."),kr(e),e;e.global.autoMode&&St({state:e}),e.global.skipMode&&cr({state:e})}return e},Vg=({state:e})=>{if(e.global.isLineCompleted)return e;if(e.global.isLineCompleted=!0,delete e.global.pendingScreenTransition,te(e)?.sceneReplay.exitOnLineCompleted)return kr(e),e;let n=Pe({state:e});e.global.autoMode&&!n&&e.global.pendingEffects.push({name:"startAutoNextTimer",payload:{delay:Wr({state:e})}});let i=Te({state:e})?.pointer,a=i?.sectionId,r=i?.lineId;a&&r&&xr(e,{sectionId:a,lineId:r});let s=e.global.nextLineConfig;return s?.auto?.enabled&&!n&&s.auto.trigger!=="fromStart"&&e.global.pendingEffects.push({name:"nextLineConfigTimer",payload:{delay:s.auto.delay}}),e.global.pendingEffects.push({name:"render"}),e},Fg=({state:e},t)=>ac(e,{sectionId:t?.sectionId,screen:t?.screen}),Ug=({state:e},t)=>{let n=t?._conditionalContinuation===!0;if(e.global.dialogueUIHidden&&!n)return wn({state:e}),e;let i=Pe({state:e});if(i?.source===Br&&t?.bypassChoice!==!0||i?.source===lr&&t?._interactionSource!==lr||i&&i.source!==Br&&i.source!==lr)return e;let a=te(e);if(a?.sceneReplay.finishOnNextAdvance)return e.global.isLineCompleted?(kr(e),e):(a.sceneReplay.exitOnLineCompleted=!0,e);let r=Te({state:e})?.pointer,s=r?.sectionId,o=we({state:e},{sectionId:s}),l=e.contexts[e.contexts.length-1],c=o?.lines||[],p=c.findIndex(m=>m.id===r?.lineId)+1;if(p<c.length){let m=c[p],d=!ir(e,"skipUnseenText");if(e.global.skipMode&&d&&!Ti({state:e},{sectionId:s,lineId:m.id})&&(cr({state:e}),!n))return e;if(l&&!l.rollback&&Sr(l,{compatibilityAnchor:!0}),l){let y=Xr(l),g=y.read?.lineId;g&&s&&xr(e,{sectionId:s,lineId:g}),y.read={sectionId:s,lineId:m.id}}Ni(e,{sectionId:s,lineId:m.id}),Si(e);let{activeInteraction:f}=Et(e,{sectionId:s,lineId:m.id});bn(e,i,f)}else{if(te(e))return console.warn("Scene replay reached the end of a section without finishSceneReplay; exiting replay."),kr(e),e;e.global.autoMode&&St({state:e}),e.global.skipMode&&cr({state:e}),e.global.nextLineConfig.auto?.enabled&&(e.global.nextLineConfig.auto.enabled=!1,e.global.pendingEffects.push({name:"clearNextLineConfigTimer"}))}return e},Wi=(e,t={})=>{let n=xt({state:e});return!n||t.formKey&&t.formKey!==n.key||t.formId&&t.formId!==n.id?null:n},Bg=(e,t)=>{if(!t.variableId)throw new Error(`form field "${t.id}" requires variableId`);let n=e.projectData.resources?.variables?.[t.variableId],i=n?.scope,a=n?.type;if(Ne(n))throw new Error(`Cannot update computed variable: ${t.variableId}`);if(n?.readonly===!0)throw new Error(`Cannot update readonly variable: ${t.variableId}`);if(ut(i,t.variableId),Jt(a,"set",t.variableId),te(e)&&i!=="context")throw new Error(`Cannot update ${i}-scoped variable "${t.variableId}" while a scene replay is active`);return{variableConfig:n,scope:i}},Yg=(e,t)=>({id:e.id,key:e.key,valid:!0,values:D(t),fields:D(e.fields),fieldList:D(e.fieldList)}),zg=e=>{if(e.global.isLineCompleted)return;e.global.isLineCompleted=!0,delete e.global.pendingScreenTransition;let t=Te({state:e})?.pointer,n=t?.sectionId,i=t?.lineId;n&&i&&xr(e,{sectionId:n,lineId:i})},Gg=({state:e},t={})=>{let n=Wi(e,t),i=t.field;if(!n?.fields?.[i])return e;let a=Ll(e,n.key),r=fn(t.value),s=n.fields[i],o=Ri(s,r);return a.values[i]=r,a.touched[i]=!0,o?a.errors[i]=o:delete a.errors[i],e.global.pendingEffects.push({name:"render"}),e},Xg=({state:e},t={})=>{let n=Wi(e,t);if(!n)return{submitted:!1,valid:!1,reason:"inactive"};let i=Ll(e,n.key);i.submitted=!0;let a={},r={};if(Object.entries(n.fields).forEach(([p,m])=>{let d=Object.prototype.hasOwnProperty.call(i.values,p)?i.values[p]:m.value,f=Ri(m,d);i.touched[p]=!0,f&&(r[p]=f),a[p]=Tl(m,d)}),i.errors=r,Object.keys(r).length>0)return e.global.pendingEffects.push({name:"render"}),{submitted:!0,valid:!1,errors:D(r),form:{id:n.id,key:n.key,values:D(a)}};let s=e.contexts[e.contexts.length-1];if(s?.rollback?.isRestoring)return{submitted:!1,valid:!1,reason:"restoring"};let o=!1,l=[],c=[];Object.entries(n.fields).forEach(([p,m])=>{let{scope:d}=Bg(e,m),f=d==="context"?s.variables:e.global.variables,y=a[p];f[m.variableId]=Qt(f[m.variableId],"set",y),d==="context"&&(o=!0,c.push({variableId:m.variableId,op:"set",value:y})),(d==="device"||d==="account")&&l.push({scope:d,path:`variables.${m.variableId}`,op:"set",value:D(f[m.variableId])})}),o&&Be(e,"updateVariable",{id:"submitForm",operations:c}),Gi(e,l);let u=Yg(n,a);return zg(e),delete e.global.formDrafts[n.key],e.global.pendingEffects.push({name:"render"}),{submitted:!0,valid:!0,form:u}},Wg=({state:e},t={})=>{let n=Wi(e,t);return n?(delete e.global.formDrafts?.[n.key],e.global.pendingEffects.push({name:"render"}),{cancelled:!0,form:{id:n.id,key:n.key,values:D(n.values),fields:D(n.fields),fieldList:D(n.fieldList)}}):{cancelled:!1,reason:"inactive"}},Hg=({state:e},t)=>{let{id:n,operations:i=[]}=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 a=e.contexts[e.contexts.length-1];if(a?.rollback?.isRestoring)return e;let r=!1,s=[],o=[];return i.forEach(({variableId:l,op:c,value:u,roundTo:p})=>{let m=e.projectData.resources?.variables?.[l],d=m?.scope,f=m?.type;if(Ne(m))throw new Error(`Cannot update computed variable: ${l}`);if(m?.readonly===!0)throw new Error(`Cannot update readonly variable: ${l}`);if(ut(d,l),Jt(f,c,l),Fs(f,c,u,l,{roundTo:p}),te(e)&&d!=="context")throw new Error(`Cannot update ${d}-scoped variable "${l}" while a scene replay is active`);let y=d==="context"?a.variables:e.global.variables;if(d==="context"){r=!0;let g={variableId:l,op:c,value:u};p!==void 0&&(g.roundTo=p),o.push(g)}y[l]=Qt(y[l],c,u,{roundTo:p}),(d==="device"||d==="account")&&s.push({scope:d,path:`variables.${l}`,op:"set",value:D(y[l])})}),r&&Be(e,"updateVariable",{id:n,operations:o}),Gi(e,s),e.global.pendingEffects.push({name:"render"}),e},Il=e=>(t,n)=>e({state:t},n),Kg=e=>({variables:ct({variables:{...e.global?.variables??{},...Pt(e)?.variables??{}},runtime:Ir(e),variableConfigs:e.projectData.resources?.variables??{},eager:!1}),runtime:Ir(e)}),Jg=e=>{if(!F(e))throw new Error("conditional action payload must be an object");if(!Array.isArray(e.branches))throw new Error("conditional action requires branches array");if(e.branches.length===0)throw new Error("conditional action requires at least one branch")},Qg=(e,t,n)=>{if(!F(e))throw new Error(`conditional branch at index ${t} must be an object`);if(!F(e.actions))throw new Error(`conditional branch at index ${t} requires actions object`);if(!Object.prototype.hasOwnProperty.call(e,"when")&&t!==n-1)throw new Error("conditional else branch must be the last branch")},Zg=(e,t)=>{Jg(t);for(let n=0;n<t.branches.length;n+=1){let i=t.branches[n];if(Qg(i,n,t.branches.length),!(Object.prototype.hasOwnProperty.call(i,"when")&&!it(i.when,Kg(e)))){Object.entries(i.actions).forEach(([r,s])=>{Ac(e,r,s)});return}}},eb={conditional:{replayLine:Zg},updateVariable:{recordSources:[Ci],replayLine:bl,replayRecorded:bl,persistInSaveSlot:!0},setNextLineConfig:{replayLine:Il(vc)},finishSceneReplay:{replayLine:Il(gc)}},An=e=>eb[e]??null,rb=e=>An(e)?.persistInSaveSlot===!0,tb=(e,t)=>{let n=An(e)?.recordSources;return Array.isArray(n)&&n.includes(t)},nb=(e,t,n)=>{An(t)?.replayRecorded?.(e,n)},Ac=(e,t,n)=>{An(t)?.replayLine?.(e,n)},sb=e=>e?.returnable!==!1,kc=(e,t)=>{if(t>=0)return e.currentIndex+t;let n=Math.abs(t);for(let i=e.currentIndex-1;i>=0;i-=1)if(sb(e.timeline[i])&&(n-=1,n===0))return i;return-1},Pc=({state:e},t)=>{let{offset:n}=t;if(n===void 0||typeof n!="number")return console.warn("selectLineIdByOffset requires a numeric offset"),null;let i=e.contexts[e.contexts.length-1];if(!i)return null;let a=i.rollback;if(!Array.isArray(a?.timeline)||typeof a?.currentIndex!="number")return null;let r=kc(a,n);if(r<0||r>=a.timeline.length)return null;let s=a.timeline[r];return{sectionId:s.sectionId,lineId:s.lineId}},xc=({state:e})=>Pc({state:e},{offset:-1})!==null,ib=({state:e},t)=>{let{offset:n=-1}=t;if(n>=0)throw new Error("rollbackByOffset requires a negative offset");let i=e.contexts?.[e.contexts.length-1];if(!i)return e;let a=Sr(i,{compatibilityAnchor:!i.rollback}),r=kc(a,n);return r<0||r>=a.timeline.length?e:Yl(e,r)},ob=({state:e},t)=>{let{sectionId:n,lineId:i}=t,a=e.contexts[e.contexts.length-1];if(!a)throw new Error("No context available for rollbackToLine");let r=Sr(a,{compatibilityAnchor:!a.rollback}),o=r.timeline.slice(0,r.currentIndex+1).findLastIndex(l=>l.sectionId===n&&l.lineId===i);if(o===-1)throw new Error(`Line ${i} not found in section ${n} rollback timeline`);return o===r.currentIndex?e:Yl(e,o)},Ec=e=>{let t=rh(e);return Yo(t,{selectPendingEffects:nh,selectSkipMode:zl,selectAutoMode:sh,selectIsChoiceVisible:Zl,selectIsFormVisible:oh,selectActiveInteraction:Pe,selectActiveForm:xt,selectDialogueUIHidden:Gl,selectDialogueHistory:Xl,selectConfirmDialog:ih,selectIsLineAccountViewed:Ti,selectIsResourceAccountViewed:lh,selectImageGalleryConfig:ch,selectImageGallery:Wl,selectMusicRoomConfig:ph,selectMusicRoom:Kl,selectSceneReplayConfig:fh,selectSceneReplay:Jl,selectIsSceneReplayActive:dh,selectActiveSceneReplayEntry:mh,selectNextLineConfig:yh,selectSystemState:hh,selectAchievements:gh,selectAchievement:bh,selectSaveSlotMap:ec,selectSaveSlots:xh,selectSaveSlot:wh,selectLocalizationPackages:rc,selectRuntime:Yi,selectRuntimeValue:Ih,selectAllVariables:hn,selectCurrentPointer:Te,selectSection:we,selectCurrentLine:gn,selectPresentationState:tc,selectAutoForwardTimerDelay:Wr,selectPresentationChanges:Ah,selectSectionLineChanges:Ph,selectSaveSlotPage:zi,selectCurrentPageSlots:Eh,selectRenderState:Oh,selectOverlayStack:th,selectLineIdByOffset:Pc,selectCanRollback:xc,selectRollbackCursor:Xy,startAutoMode:sc,stopAutoMode:St,toggleAutoMode:Th,startSkipMode:ic,stopSkipMode:cr,toggleSkipMode:Lh,showDialogueUI:wn,hideDialogueUI:oc,toggleDialogueUI:Mh,setDialogueTextSpeed:qh,setAutoForwardDelay:Vh,setAutoForwardSpeed:Fh,setSkipUnseenText:Uh,setSkipTransitionsAndAnimations:Bh,setSoundVolume:Yh,setMusicVolume:zh,setMuteAll:Gh,setSaveLoadPagination:Xh,incrementSaveLoadPagination:Wh,decrementSaveLoadPagination:Hh,setMenuPage:Kh,setMenuEntryPoint:Jh,showConfirmDialog:Rh,hideConfirmDialog:Ch,resetStoryAtSection:tg,clearPendingEffects:Qh,appendPendingEffect:Zh,completeAchievement:eg,setAchievementProgress:rg,beginRollbackActionBatch:Jy,endRollbackActionBatch:Qy,markRollbackCheckpointTransient:Wy,markSavedRollbackCheckpointTransient:Hy,addViewedLine:sg,addViewedResource:ig,showImageGalleryVariant:og,moveToPreviousImageGalleryVariant:ag,moveToNextImageGalleryVariant:lg,clearImageGallerySelection:cg,moveToImageGalleryPage:ug,moveToNextImageGalleryPage:pg,moveToPreviousImageGalleryPage:fg,playMusicRoomTrack:mg,playMusicRoom:yg,pauseMusicRoom:hg,stopMusicRoom:gg,seekMusicRoom:bg,playPreviousMusicRoomTrack:wg,playNextMusicRoomTrack:Ig,clearMusicRoomSelection:vg,moveToMusicRoomPage:Ag,moveToNextMusicRoomPage:kg,moveToPreviousMusicRoomPage:Pg,musicRoomSoundReady:Cg,musicRoomSoundProgress:_g,musicRoomSoundComplete:$g,musicRoomSoundError:jg,startSceneReplay:xg,finishSceneReplay:gc,exitSceneReplay:Eg,moveToSceneReplayPage:Sg,moveToNextSceneReplayPage:Og,moveToPreviousSceneReplayPage:Rg,setNextLineConfig:vc,saveSlot:Ng,loadSlot:Dg,updateProjectData:Tg,updateLocalizationPackage:Lg,sectionTransition:Fg,jumpToLine:Mg,nextLine:qg,markLineCompleted:Vg,rollbackToLine:ob,rollbackByOffset:ib,pushOverlay:_h,popOverlay:$h,replaceLastOverlay:jh,clearOverlays:Nh,updateFormField:Gg,submitForm:Xg,cancelForm:Wg,updateVariable:Hg,nextLineFromSystem:Ug},{transformActionFirstArgument:i=>({state:i}),transformSelectorFirstArgument:i=>({state:i})})};var ab="route-engine",lb="projectPersistence";var Oc=()=>({saveSlots:{},globalDeviceVariables:{},globalAccountVariables:{},globalRuntime:{},accountViewedRegistry:{}}),he=e=>Object.prototype.toString.call(e)==="[object Object]",Sc="variables.",cb=(e={})=>{let t=he(e)?e:{};return{sections:(Array.isArray(t.sections)?t.sections:[]).map(n=>typeof n=="string"||typeof n=="number"?{sectionId:String(n)}:!he(n)||typeof n.sectionId!="string"||n.sectionId.length===0?null:{sectionId:n.sectionId,...typeof n.lineId=="string"?{lineId:n.lineId}:{}}).filter(Boolean),resources:(Array.isArray(t.resources)?t.resources:[]).map(n=>typeof n=="string"||typeof n=="number"?{resourceId:String(n)}:!he(n)||typeof n.resourceId!="string"||n.resourceId.length===0?null:{resourceId:n.resourceId}).filter(Boolean)}},ub=(e={})=>{let t=he(e)?e:{};return{sections:(Array.isArray(t.sections)?t.sections:[]).map(n=>typeof n=="string"||typeof n=="number"?{sectionId:String(n)}:!he(n)||typeof n.sectionId!="string"||n.sectionId.length===0?null:{sectionId:n.sectionId,...typeof n.lastLineId=="string"?{lastLineId:n.lastLineId}:{}}).filter(Boolean),resources:(Array.isArray(t.resources)?t.resources:[]).map(n=>typeof n=="string"||typeof n=="number"?{resourceId:String(n)}:!he(n)||typeof n.resourceId!="string"||n.resourceId.length===0?null:{resourceId:n.resourceId}).filter(Boolean)}},pb=(e,t)=>{let n=ub(e),i=cb(t),a=n.sections.map(s=>({...s})),r=n.resources.map(s=>({...s}));return i.sections.forEach(s=>{let o=a.find(l=>l.sectionId===s.sectionId);if(!o){a.push({sectionId:s.sectionId,...s.lineId===void 0?{}:{lastLineId:s.lineId}});return}if(o.lastLineId!==void 0){if(s.lineId===void 0){delete o.lastLineId;return}o.lastLineId=s.lineId}}),i.resources.forEach(s=>{r.find(l=>l.resourceId===s.resourceId)||r.push({...s})}),{sections:a,resources:r}},Rc=(e={})=>{let t=he(e)?e:{};return{saveSlots:he(t.saveSlots)?t.saveSlots:{},globalDeviceVariables:he(t.globalDeviceVariables)?t.globalDeviceVariables:{},globalAccountVariables:he(t.globalAccountVariables)?t.globalAccountVariables:{},globalRuntime:he(t.globalRuntime)?t.globalRuntime:{},accountViewedRegistry:he(t.accountViewedRegistry)?t.accountViewedRegistry:{}}},fb=(e=[])=>{if(e===void 0)return[];if(!Array.isArray(e))throw new Error("applyScopedDataUpdates requires an updates array.");return e.map((t,n)=>{if(!he(t))throw new Error(`Malformed applyScopedDataUpdates.updates[${n}] entry.`);let i=t.path?.startsWith(Sc)?t.path.slice(Sc.length):null;if(i!==null){if(!["device","account"].includes(t.scope))throw new Error(`Unsupported applyScopedDataUpdates scope "${t.scope}" at updates[${n}].`);if(i.length===0)throw new Error(`Malformed applyScopedDataUpdates path "${t.path}" at updates[${n}].`);if(t.op!=="set")throw new Error(`Unsupported applyScopedDataUpdates operation "${t.op}" at updates[${n}].`);return{scope:t.scope,path:t.path,op:t.op,value:t.value,variableId:i}}if(t.path==="viewedRegistry"){if(t.scope!=="account")throw new Error(`Unsupported applyScopedDataUpdates scope "${t.scope}" at updates[${n}].`);if(t.op!=="markViewed")throw new Error(`Unsupported applyScopedDataUpdates operation "${t.op}" at updates[${n}].`);return t}throw typeof t.path!="string"?new Error(`Malformed applyScopedDataUpdates path at updates[${n}].`):new Error(`Unsupported applyScopedDataUpdates path "${t.path}" at updates[${n}].`)})},db=(e,t)=>{let n={};return fb(t).forEach(i=>{if(i.path==="viewedRegistry"){n.accountViewedRegistry=pb(n.accountViewedRegistry??e.accountViewedRegistry,i.value);return}let a=i.scope==="device"?"globalDeviceVariables":"globalAccountVariables";n[a]={...e[a],...n[a],[i.variableId]:i.value}}),n},Hi=e=>{if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null},mb=e=>{let t=Hi(e);if(!t)throw new Error("createIndexedDbPersistence requires a non-empty namespace.");return t},yb=e=>{let t=e??globalThis.indexedDB;if(!t)throw new Error("IndexedDB is not available in this environment.");return t},hb=({indexedDB:e,databaseName:t,objectStoreName:n})=>new Promise((i,a)=>{let r=e.open(t,1);r.onupgradeneeded=()=>{let s=r.result;s.objectStoreNames.contains(n)||s.createObjectStore(n,{keyPath:"namespace"})},r.onsuccess=()=>{i(r.result)},r.onerror=()=>{a(r.error??new Error(`Failed to open IndexedDB database "${t}".`))}}),gb=async({databasePromise:e,objectStoreName:t,namespace:n})=>{let i=await e;return new Promise((a,r)=>{let l=i.transaction(t,"readonly").objectStore(t).get(n);l.onsuccess=()=>{a(l.result??null)},l.onerror=()=>{r(l.error??new Error(`Failed to read persisted namespace "${n}" from IndexedDB.`))}})},Rt=async({databasePromise:e,objectStoreName:t,namespace:n,patch:i})=>{let a=await e;return new Promise((r,s)=>{let o=a.transaction(t,"readwrite"),l=o.objectStore(t),c=l.get(n),u=!1,p=d=>{u||(u=!0,s(d))},m=()=>{u||(u=!0,r())};c.onerror=()=>{p(c.error??new Error(`Failed to read persisted namespace "${n}" before updating IndexedDB.`))},c.onsuccess=()=>{let d=Rc(c.result),f=typeof i=="function"?i(d):i,y={namespace:n,version:1,...Oc(),...d,...f},g=l.put(y);g.onerror=()=>{p(g.error??new Error(`Failed to persist namespace "${n}" to IndexedDB.`))}},o.oncomplete=()=>{m()},o.onerror=()=>{p(o.error??new Error(`IndexedDB transaction failed while updating namespace "${n}".`))},o.onabort=()=>{p(o.error??new Error(`IndexedDB transaction aborted while updating namespace "${n}".`))}})},bb=async({databasePromise:e,objectStoreName:t,namespace:n})=>{let i=await e;return new Promise((a,r)=>{let s=i.transaction(t,"readwrite"),l=s.objectStore(t).delete(n),c=!1,u=m=>{c||(c=!0,r(m))},p=()=>{c||(c=!0,a())};l.onerror=()=>{u(l.error??new Error(`Failed to clear persisted namespace "${n}" from IndexedDB.`))},s.oncomplete=()=>{p()},s.onerror=()=>{u(s.error??new Error(`IndexedDB transaction failed while clearing namespace "${n}".`))},s.onabort=()=>{u(s.error??new Error(`IndexedDB transaction aborted while clearing namespace "${n}".`))}})},Ki=(e={})=>{let{indexedDB:t,databaseName:n=ab,objectStoreName:i=lb,namespace:a}=e,r=yb(t),s=mb(a),o=hb({indexedDB:r,databaseName:n,objectStoreName:i});return{namespace:s,load:async()=>{let l=await gb({databasePromise:o,objectStoreName:i,namespace:s});return{...Oc(),...Rc(l)}},clear:async()=>bb({databasePromise:o,objectStoreName:i,namespace:s}),saveSlots:async l=>Rt({databasePromise:o,objectStoreName:i,namespace:s,patch:{saveSlots:he(l)?l:{}}}),saveGlobalDeviceVariables:async l=>Rt({databasePromise:o,objectStoreName:i,namespace:s,patch:{globalDeviceVariables:he(l)?l:{}}}),saveGlobalAccountVariables:async l=>Rt({databasePromise:o,objectStoreName:i,namespace:s,patch:{globalAccountVariables:he(l)?l:{}}}),saveGlobalRuntime:async l=>Rt({databasePromise:o,objectStoreName:i,namespace:s,patch:{globalRuntime:he(l)?l:{}}}),applyScopedDataUpdates:async l=>Rt({databasePromise:o,objectStoreName:i,namespace:s,patch:c=>db(c,l)})}},wb=Ki;var Lc=Mc;var Ib={type:"object",properties:{resourceId:{type:"string"},animationName:{type:"string"},animationSpeed:{type:"number"},loop:{type:"boolean"},colorId:{type:"string"},transformId:{type:"string"},x:{type:"number"},y:{type:"number"},anchorX:{type:"number"},anchorY:{type:"number"},scaleX:{type:"number"},scaleY:{type:"number"},rotation:{type:"number"},originX:{type:"number"},originY:{type:"number"},opacity:{type:"number",minimum:0,maximum:1},blur:{$ref:"#/definitions/backgroundBlur"},animations:{$ref:"#/definitions/animationSelection"}},additionalProperties:!1},Ze=Object.prototype.hasOwnProperty,vb={anyOf:[{type:"null"},{type:"object",properties:{x:{type:"number",minimum:0},y:{type:"number",minimum:0},quality:{type:"number",minimum:1},kernelSize:{type:"integer",enum:[5,7,9,11,13,15]},repeatEdgePixels:{type:"boolean"}},required:["x","y"],additionalProperties:!1}]};function Ce(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=!1,c=s;if(e!==null){let p={instancePath:t,schemaPath:"#/anyOf/0/type",keyword:"type",params:{type:"null"},message:"must be null"};r===null?r=[p]:r.push(p),s++}var u=c===s;if(l=l||u,!l){let p=s;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.x===void 0){let d={instancePath:t,schemaPath:"#/anyOf/1/required",keyword:"required",params:{missingProperty:"x"},message:"must have required property 'x'"};r===null?r=[d]:r.push(d),s++}if(e.y===void 0){let d={instancePath:t,schemaPath:"#/anyOf/1/required",keyword:"required",params:{missingProperty:"y"},message:"must have required property 'y'"};r===null?r=[d]:r.push(d),s++}for(let d in e)if(!(d==="x"||d==="y"||d==="quality"||d==="kernelSize"||d==="repeatEdgePixels")){let f={instancePath:t,schemaPath:"#/anyOf/1/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:d},message:"must NOT have additional properties"};r===null?r=[f]:r.push(f),s++}if(e.x!==void 0){let d=e.x;if(typeof d=="number"){if(d<0||isNaN(d)){let f={instancePath:t+"/x",schemaPath:"#/anyOf/1/properties/x/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[f]:r.push(f),s++}}else{let f={instancePath:t+"/x",schemaPath:"#/anyOf/1/properties/x/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}}if(e.y!==void 0){let d=e.y;if(typeof d=="number"){if(d<0||isNaN(d)){let f={instancePath:t+"/y",schemaPath:"#/anyOf/1/properties/y/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[f]:r.push(f),s++}}else{let f={instancePath:t+"/y",schemaPath:"#/anyOf/1/properties/y/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}}if(e.quality!==void 0){let d=e.quality;if(typeof d=="number"){if(d<1||isNaN(d)){let f={instancePath:t+"/quality",schemaPath:"#/anyOf/1/properties/quality/minimum",keyword:"minimum",params:{comparison:">=",limit:1},message:"must be >= 1"};r===null?r=[f]:r.push(f),s++}}else{let f={instancePath:t+"/quality",schemaPath:"#/anyOf/1/properties/quality/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}}if(e.kernelSize!==void 0){let d=e.kernelSize;if(!(typeof d=="number"&&!(d%1)&&!isNaN(d))){let f={instancePath:t+"/kernelSize",schemaPath:"#/anyOf/1/properties/kernelSize/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[f]:r.push(f),s++}if(!(d===5||d===7||d===9||d===11||d===13||d===15)){let f={instancePath:t+"/kernelSize",schemaPath:"#/anyOf/1/properties/kernelSize/enum",keyword:"enum",params:{allowedValues:vb.anyOf[1].properties.kernelSize.enum},message:"must be equal to one of the allowed values"};r===null?r=[f]:r.push(f),s++}}if(e.repeatEdgePixels!==void 0&&typeof e.repeatEdgePixels!="boolean"){let d={instancePath:t+"/repeatEdgePixels",schemaPath:"#/anyOf/1/properties/repeatEdgePixels/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[d]:r.push(d),s++}}else{let d={instancePath:t,schemaPath:"#/anyOf/1/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[d]:r.push(d),s++}var u=p===s;l=l||u}if(l)s=o,r!==null&&(o?r.length=o:r=null);else{let p={instancePath:t,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};r===null?r=[p]:r.push(p),s++}return Ce.errors=r,s===0}var Ab={type:"object",properties:{continuity:{type:"string",enum:["render","persistent"]},speed:{type:"number",exclusiveMinimum:0},loop:{type:"boolean"}},additionalProperties:!1};function Pn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!(o==="continuity"||o==="speed"||o==="loop")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.continuity!==void 0){let o=e.continuity;if(typeof o!="string"){let l={instancePath:t+"/continuity",schemaPath:"#/properties/continuity/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(!(o==="render"||o==="persistent")){let l={instancePath:t+"/continuity",schemaPath:"#/properties/continuity/enum",keyword:"enum",params:{allowedValues:Ab.properties.continuity.enum},message:"must be equal to one of the allowed values"};r===null?r=[l]:r.push(l),s++}}if(e.speed!==void 0){let o=e.speed;if(typeof o=="number"){if(o<=0||isNaN(o)){let l={instancePath:t+"/speed",schemaPath:"#/properties/speed/exclusiveMinimum",keyword:"exclusiveMinimum",params:{comparison:">",limit:0},message:"must be > 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/speed",schemaPath:"#/properties/speed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.loop!==void 0&&typeof e.loop!="boolean"){let o={instancePath:t+"/loop",schemaPath:"#/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Pn.errors=r,s===0}function J(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.resourceId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"resourceId"},message:"must have required property 'resourceId'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="resourceId"||o==="playback")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let o={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}e.playback!==void 0&&(Pn(e.playback,{instancePath:t+"/playback",parentData:e,parentDataProperty:"playback",rootData:a})||(r=r===null?Pn.errors:r.concat(Pn.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return J.errors=r,s===0}function xn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!Ze.call(Ib.properties,o)){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let o={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.animationName!==void 0&&typeof e.animationName!="string"){let o={instancePath:t+"/animationName",schemaPath:"#/properties/animationName/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.animationSpeed!==void 0&&typeof e.animationSpeed!="number"){let o={instancePath:t+"/animationSpeed",schemaPath:"#/properties/animationSpeed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.loop!==void 0&&typeof e.loop!="boolean"){let o={instancePath:t+"/loop",schemaPath:"#/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.colorId!==void 0&&typeof e.colorId!="string"){let o={instancePath:t+"/colorId",schemaPath:"#/properties/colorId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.transformId!==void 0&&typeof e.transformId!="string"){let o={instancePath:t+"/transformId",schemaPath:"#/properties/transformId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.x!==void 0&&typeof e.x!="number"){let o={instancePath:t+"/x",schemaPath:"#/properties/x/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.y!==void 0&&typeof e.y!="number"){let o={instancePath:t+"/y",schemaPath:"#/properties/y/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.anchorX!==void 0&&typeof e.anchorX!="number"){let o={instancePath:t+"/anchorX",schemaPath:"#/properties/anchorX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.anchorY!==void 0&&typeof e.anchorY!="number"){let o={instancePath:t+"/anchorY",schemaPath:"#/properties/anchorY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.scaleX!==void 0&&typeof e.scaleX!="number"){let o={instancePath:t+"/scaleX",schemaPath:"#/properties/scaleX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.scaleY!==void 0&&typeof e.scaleY!="number"){let o={instancePath:t+"/scaleY",schemaPath:"#/properties/scaleY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.rotation!==void 0&&typeof e.rotation!="number"){let o={instancePath:t+"/rotation",schemaPath:"#/properties/rotation/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.originX!==void 0&&typeof e.originX!="number"){let o={instancePath:t+"/originX",schemaPath:"#/properties/originX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.originY!==void 0&&typeof e.originY!="number"){let o={instancePath:t+"/originY",schemaPath:"#/properties/originY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.opacity!==void 0){let o=e.opacity;if(typeof o=="number"){if(o>1||isNaN(o)){let l={instancePath:t+"/opacity",schemaPath:"#/properties/opacity/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[l]:r.push(l),s++}if(o<0||isNaN(o)){let l={instancePath:t+"/opacity",schemaPath:"#/properties/opacity/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/opacity",schemaPath:"#/properties/opacity/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}e.blur!==void 0&&(Ce(e.blur,{instancePath:t+"/blur",parentData:e,parentDataProperty:"blur",rootData:a})||(r=r===null?Ce.errors:r.concat(Ce.errors),s=r.length)),e.animations!==void 0&&(J(e.animations,{instancePath:t+"/animations",parentData:e,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return xn.errors=r,s===0}function Mc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return xn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?xn.errors:r.concat(xn.errors),s=r.length),Mc.errors=r,s===0}var qc=Vc;var kb={type:"object",properties:{sounds:{type:"array",items:{$ref:"#/definitions/audioSound"}},resourceId:{type:"string"},loop:{type:"boolean"},interruption:{type:"string",enum:["immediate","loopEnd"]},volume:{type:"number",minimum:0,maximum:100},muted:{type:"boolean"},pan:{type:"number",minimum:-1,maximum:1},startDelayMs:{type:"number",minimum:0}},allOf:[{not:{required:["resourceId","sounds"]}},{not:{required:["startDelayMs","sounds"]}}],additionalProperties:!1},$c={type:"object",properties:{id:{type:"string",minLength:1},resourceId:{type:"string",minLength:1},loop:{type:"boolean"},volume:{type:"number",minimum:0,maximum:100},muted:{type:"boolean"},pan:{type:"number",minimum:-1,maximum:1},startDelayMs:{type:"number",minimum:0},playbackRate:{type:"number",minimum:0},startAt:{type:"number",minimum:0},endAt:{type:["number","null"],minimum:0}},required:["id","resourceId"],additionalProperties:!1},Re=_c().default;function Oe(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.id===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"id"},message:"must have required property 'id'"};r===null?r=[o]:r.push(o),s++}if(e.resourceId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"resourceId"},message:"must have required property 'resourceId'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!Ze.call($c.properties,o)){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.id!==void 0){let o=e.id;if(typeof o=="string"){if(Re(o)<1){let l={instancePath:t+"/id",schemaPath:"#/properties/id/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}}if(e.resourceId!==void 0){let o=e.resourceId;if(typeof o=="string"){if(Re(o)<1){let l={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}}if(e.loop!==void 0&&typeof e.loop!="boolean"){let o={instancePath:t+"/loop",schemaPath:"#/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.volume!==void 0){let o=e.volume;if(typeof o=="number"){if(o>100||isNaN(o)){let l={instancePath:t+"/volume",schemaPath:"#/properties/volume/maximum",keyword:"maximum",params:{comparison:"<=",limit:100},message:"must be <= 100"};r===null?r=[l]:r.push(l),s++}if(o<0||isNaN(o)){let l={instancePath:t+"/volume",schemaPath:"#/properties/volume/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/volume",schemaPath:"#/properties/volume/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.muted!==void 0&&typeof e.muted!="boolean"){let o={instancePath:t+"/muted",schemaPath:"#/properties/muted/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.pan!==void 0){let o=e.pan;if(typeof o=="number"){if(o>1||isNaN(o)){let l={instancePath:t+"/pan",schemaPath:"#/properties/pan/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[l]:r.push(l),s++}if(o<-1||isNaN(o)){let l={instancePath:t+"/pan",schemaPath:"#/properties/pan/minimum",keyword:"minimum",params:{comparison:">=",limit:-1},message:"must be >= -1"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/pan",schemaPath:"#/properties/pan/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.startDelayMs!==void 0){let o=e.startDelayMs;if(typeof o=="number"){if(o<0||isNaN(o)){let l={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.playbackRate!==void 0){let o=e.playbackRate;if(typeof o=="number"){if(o<0||isNaN(o)){let l={instancePath:t+"/playbackRate",schemaPath:"#/properties/playbackRate/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/playbackRate",schemaPath:"#/properties/playbackRate/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.startAt!==void 0){let o=e.startAt;if(typeof o=="number"){if(o<0||isNaN(o)){let l={instancePath:t+"/startAt",schemaPath:"#/properties/startAt/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/startAt",schemaPath:"#/properties/startAt/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.endAt!==void 0){let o=e.endAt;if(typeof o!="number"&&o!==null){let l={instancePath:t+"/endAt",schemaPath:"#/properties/endAt/type",keyword:"type",params:{type:$c.properties.endAt.type},message:"must be number,null"};r===null?r=[l]:r.push(l),s++}if(typeof o=="number"&&(o<0||isNaN(o))){let l={instancePath:t+"/endAt",schemaPath:"#/properties/endAt/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Oe.errors=r,s===0}function En(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let d;if(e.resourceId===void 0&&(d="resourceId")||e.sounds===void 0&&(d="sounds")){let f={};r===null?r=[f]:r.push(f),s++}}var c=l===s;if(c){let d={instancePath:t,schemaPath:"#/allOf/0/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[d]:r.push(d),s++}else s=o,r!==null&&(o?r.length=o:r=null);let u=s,p=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let d;if(e.startDelayMs===void 0&&(d="startDelayMs")||e.sounds===void 0&&(d="sounds")){let f={};r===null?r=[f]:r.push(f),s++}}var m=p===s;if(m){let d={instancePath:t,schemaPath:"#/allOf/1/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[d]:r.push(d),s++}else s=u,r!==null&&(u?r.length=u:r=null);if(e&&typeof e=="object"&&!Array.isArray(e)){for(let d in e)if(!(d==="sounds"||d==="resourceId"||d==="loop"||d==="interruption"||d==="volume"||d==="muted"||d==="pan"||d==="startDelayMs")){let f={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:d},message:"must NOT have additional properties"};r===null?r=[f]:r.push(f),s++}if(e.sounds!==void 0){let d=e.sounds;if(Array.isArray(d)){let f=d.length;for(let y=0;y<f;y++)Oe(d[y],{instancePath:t+"/sounds/"+y,parentData:d,parentDataProperty:y,rootData:a})||(r=r===null?Oe.errors:r.concat(Oe.errors),s=r.length)}else{let f={instancePath:t+"/sounds",schemaPath:"#/properties/sounds/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[f]:r.push(f),s++}}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let d={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[d]:r.push(d),s++}if(e.loop!==void 0&&typeof e.loop!="boolean"){let d={instancePath:t+"/loop",schemaPath:"#/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[d]:r.push(d),s++}if(e.interruption!==void 0){let d=e.interruption;if(typeof d!="string"){let f={instancePath:t+"/interruption",schemaPath:"#/properties/interruption/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[f]:r.push(f),s++}if(!(d==="immediate"||d==="loopEnd")){let f={instancePath:t+"/interruption",schemaPath:"#/properties/interruption/enum",keyword:"enum",params:{allowedValues:kb.properties.interruption.enum},message:"must be equal to one of the allowed values"};r===null?r=[f]:r.push(f),s++}}if(e.volume!==void 0){let d=e.volume;if(typeof d=="number"){if(d>100||isNaN(d)){let f={instancePath:t+"/volume",schemaPath:"#/properties/volume/maximum",keyword:"maximum",params:{comparison:"<=",limit:100},message:"must be <= 100"};r===null?r=[f]:r.push(f),s++}if(d<0||isNaN(d)){let f={instancePath:t+"/volume",schemaPath:"#/properties/volume/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[f]:r.push(f),s++}}else{let f={instancePath:t+"/volume",schemaPath:"#/properties/volume/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}}if(e.muted!==void 0&&typeof e.muted!="boolean"){let d={instancePath:t+"/muted",schemaPath:"#/properties/muted/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[d]:r.push(d),s++}if(e.pan!==void 0){let d=e.pan;if(typeof d=="number"){if(d>1||isNaN(d)){let f={instancePath:t+"/pan",schemaPath:"#/properties/pan/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[f]:r.push(f),s++}if(d<-1||isNaN(d)){let f={instancePath:t+"/pan",schemaPath:"#/properties/pan/minimum",keyword:"minimum",params:{comparison:">=",limit:-1},message:"must be >= -1"};r===null?r=[f]:r.push(f),s++}}else{let f={instancePath:t+"/pan",schemaPath:"#/properties/pan/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}}if(e.startDelayMs!==void 0){let d=e.startDelayMs;if(typeof d=="number"){if(d<0||isNaN(d)){let f={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[f]:r.push(f),s++}}else{let f={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}}}else{let d={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[d]:r.push(d),s++}return En.errors=r,s===0}function Vc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return En(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?En.errors:r.concat(En.errors),s=r.length),Vc.errors=r,s===0}var Fc=Uc;var Pb={type:"object",properties:{items:{type:"array",items:{type:"object",properties:{id:{type:"string"},transformId:{type:"string"},x:{type:"number"},y:{type:"number"},anchorX:{type:"number"},anchorY:{type:"number"},scaleX:{type:"number"},scaleY:{type:"number"},rotation:{type:"number"},originX:{type:"number"},originY:{type:"number"},opacity:{type:"number",minimum:0,maximum:1},blur:{$ref:"#/definitions/backgroundBlur"},sprites:{type:"array",items:{type:"object",properties:{id:{type:"string"},resourceId:{type:"string"},animationName:{type:"string"},animationSpeed:{type:"number"},loop:{type:"boolean"}},additionalProperties:!1}},animations:{$ref:"#/definitions/animationSelection"}},required:["id"],allOf:[{if:{required:["sprites"]},then:{required:["transformId"]}}],additionalProperties:!1}}},additionalProperties:!1};function Sn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let l in e)if(l!=="items"){let c={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:l},message:"must NOT have additional properties"};r===null?r=[c]:r.push(c),s++}if(e.items!==void 0){let l=e.items;if(Array.isArray(l)){let c=l.length;for(let u=0;u<c;u++){let p=l[u],m=s,d=!0,f=s;if(p&&typeof p=="object"&&!Array.isArray(p)){let y;if(p.sprites===void 0&&(y="sprites")){let g={};r===null?r=[g]:r.push(g),s++}}var o=f===s;if(s=m,r!==null&&(m?r.length=m:r=null),o){let y=s;if(p&&typeof p=="object"&&!Array.isArray(p)&&p.transformId===void 0){let h={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/allOf/0/then/required",keyword:"required",params:{missingProperty:"transformId"},message:"must have required property 'transformId'"};r===null?r=[h]:r.push(h),s++}var o=y===s;d=o}if(!d){let y={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/allOf/0/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[y]:r.push(y),s++}if(p&&typeof p=="object"&&!Array.isArray(p)){if(p.id===void 0){let y={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/required",keyword:"required",params:{missingProperty:"id"},message:"must have required property 'id'"};r===null?r=[y]:r.push(y),s++}for(let y in p)if(!Ze.call(Pb.properties.items.items.properties,y)){let g={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:y},message:"must NOT have additional properties"};r===null?r=[g]:r.push(g),s++}if(p.id!==void 0&&typeof p.id!="string"){let y={instancePath:t+"/items/"+u+"/id",schemaPath:"#/properties/items/items/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[y]:r.push(y),s++}if(p.transformId!==void 0&&typeof p.transformId!="string"){let y={instancePath:t+"/items/"+u+"/transformId",schemaPath:"#/properties/items/items/properties/transformId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[y]:r.push(y),s++}if(p.x!==void 0&&typeof p.x!="number"){let y={instancePath:t+"/items/"+u+"/x",schemaPath:"#/properties/items/items/properties/x/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.y!==void 0&&typeof p.y!="number"){let y={instancePath:t+"/items/"+u+"/y",schemaPath:"#/properties/items/items/properties/y/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.anchorX!==void 0&&typeof p.anchorX!="number"){let y={instancePath:t+"/items/"+u+"/anchorX",schemaPath:"#/properties/items/items/properties/anchorX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.anchorY!==void 0&&typeof p.anchorY!="number"){let y={instancePath:t+"/items/"+u+"/anchorY",schemaPath:"#/properties/items/items/properties/anchorY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.scaleX!==void 0&&typeof p.scaleX!="number"){let y={instancePath:t+"/items/"+u+"/scaleX",schemaPath:"#/properties/items/items/properties/scaleX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.scaleY!==void 0&&typeof p.scaleY!="number"){let y={instancePath:t+"/items/"+u+"/scaleY",schemaPath:"#/properties/items/items/properties/scaleY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.rotation!==void 0&&typeof p.rotation!="number"){let y={instancePath:t+"/items/"+u+"/rotation",schemaPath:"#/properties/items/items/properties/rotation/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.originX!==void 0&&typeof p.originX!="number"){let y={instancePath:t+"/items/"+u+"/originX",schemaPath:"#/properties/items/items/properties/originX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.originY!==void 0&&typeof p.originY!="number"){let y={instancePath:t+"/items/"+u+"/originY",schemaPath:"#/properties/items/items/properties/originY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(p.opacity!==void 0){let y=p.opacity;if(typeof y=="number"){if(y>1||isNaN(y)){let g={instancePath:t+"/items/"+u+"/opacity",schemaPath:"#/properties/items/items/properties/opacity/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[g]:r.push(g),s++}if(y<0||isNaN(y)){let g={instancePath:t+"/items/"+u+"/opacity",schemaPath:"#/properties/items/items/properties/opacity/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[g]:r.push(g),s++}}else{let g={instancePath:t+"/items/"+u+"/opacity",schemaPath:"#/properties/items/items/properties/opacity/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[g]:r.push(g),s++}}if(p.blur!==void 0&&(Ce(p.blur,{instancePath:t+"/items/"+u+"/blur",parentData:p,parentDataProperty:"blur",rootData:a})||(r=r===null?Ce.errors:r.concat(Ce.errors),s=r.length)),p.sprites!==void 0){let y=p.sprites;if(Array.isArray(y)){let g=y.length;for(let h=0;h<g;h++){let w=y[h];if(w&&typeof w=="object"&&!Array.isArray(w)){for(let b in w)if(!(b==="id"||b==="resourceId"||b==="animationName"||b==="animationSpeed"||b==="loop")){let E={instancePath:t+"/items/"+u+"/sprites/"+h,schemaPath:"#/properties/items/items/properties/sprites/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:b},message:"must NOT have additional properties"};r===null?r=[E]:r.push(E),s++}if(w.id!==void 0&&typeof w.id!="string"){let b={instancePath:t+"/items/"+u+"/sprites/"+h+"/id",schemaPath:"#/properties/items/items/properties/sprites/items/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[b]:r.push(b),s++}if(w.resourceId!==void 0&&typeof w.resourceId!="string"){let b={instancePath:t+"/items/"+u+"/sprites/"+h+"/resourceId",schemaPath:"#/properties/items/items/properties/sprites/items/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[b]:r.push(b),s++}if(w.animationName!==void 0&&typeof w.animationName!="string"){let b={instancePath:t+"/items/"+u+"/sprites/"+h+"/animationName",schemaPath:"#/properties/items/items/properties/sprites/items/properties/animationName/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[b]:r.push(b),s++}if(w.animationSpeed!==void 0&&typeof w.animationSpeed!="number"){let b={instancePath:t+"/items/"+u+"/sprites/"+h+"/animationSpeed",schemaPath:"#/properties/items/items/properties/sprites/items/properties/animationSpeed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[b]:r.push(b),s++}if(w.loop!==void 0&&typeof w.loop!="boolean"){let b={instancePath:t+"/items/"+u+"/sprites/"+h+"/loop",schemaPath:"#/properties/items/items/properties/sprites/items/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[b]:r.push(b),s++}}else{let b={instancePath:t+"/items/"+u+"/sprites/"+h,schemaPath:"#/properties/items/items/properties/sprites/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[b]:r.push(b),s++}}}else{let g={instancePath:t+"/items/"+u+"/sprites",schemaPath:"#/properties/items/items/properties/sprites/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[g]:r.push(g),s++}}p.animations!==void 0&&(J(p.animations,{instancePath:t+"/items/"+u+"/animations",parentData:p,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let y={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[y]:r.push(y),s++}}}else{let c={instancePath:t+"/items",schemaPath:"#/properties/items/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[c]:r.push(c),s++}}}else{let l={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}return Sn.errors=r,s===0}function Uc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Sn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Sn.errors:r.concat(Sn.errors),s=r.length),Uc.errors=r,s===0}var Bc=Yc;function On(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!(o==="resourceId"||o==="items"||o==="animations")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let o={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.items!==void 0){let o=e.items;if(Array.isArray(o)){let l=o.length;for(let c=0;c<l;c++){let u=o[c];if(u&&typeof u=="object"&&!Array.isArray(u)){for(let p in u)if(!(p==="id"||p==="content"||p==="events")){let m={instancePath:t+"/items/"+c,schemaPath:"#/properties/items/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:p},message:"must NOT have additional properties"};r===null?r=[m]:r.push(m),s++}if(u.id!==void 0&&typeof u.id!="string"){let p={instancePath:t+"/items/"+c+"/id",schemaPath:"#/properties/items/items/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[p]:r.push(p),s++}if(u.content!==void 0&&typeof u.content!="string"){let p={instancePath:t+"/items/"+c+"/content",schemaPath:"#/properties/items/items/properties/content/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[p]:r.push(p),s++}if(u.events!==void 0){let p=u.events;if(p&&typeof p=="object"&&!Array.isArray(p)){if(p.click!==void 0){let m=p.click;if(!(m&&typeof m=="object"&&!Array.isArray(m))){let d={instancePath:t+"/items/"+c+"/events/click",schemaPath:"#/properties/items/items/properties/events/properties/click/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[d]:r.push(d),s++}}}else{let m={instancePath:t+"/items/"+c+"/events",schemaPath:"#/properties/items/items/properties/events/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[m]:r.push(m),s++}}}else{let p={instancePath:t+"/items/"+c,schemaPath:"#/properties/items/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}}else{let l={instancePath:t+"/items",schemaPath:"#/properties/items/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[l]:r.push(l),s++}}e.animations!==void 0&&(J(e.animations,{instancePath:t+"/animations",parentData:e,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return On.errors=r,s===0}function Yc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return On(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?On.errors:r.concat(On.errors),s=r.length),Yc.errors=r,s===0}var zc=Gc;function Rn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(o!=="mode"){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.mode!==void 0&&typeof e.mode!="string"){let o={instancePath:t+"/mode",schemaPath:"#/properties/mode/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Rn.errors=r,s===0}function Gc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Rn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Rn.errors:r.concat(Rn.errors),s=r.length),Gc.errors=r,s===0}var Xc=Wc;function Cn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.resourceId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"resourceId"},message:"must have required property 'resourceId'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(o!=="resourceId"){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let o={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Cn.errors=r,s===0}function Wc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Cn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Cn.errors:r.concat(Cn.errors),s=r.length),Wc.errors=r,s===0}var Hc=Kc;var jc={type:"object",properties:{ui:{type:"object",properties:{resourceId:{type:"string"},animations:{$ref:"#/definitions/animationSelection"}},additionalProperties:!1},mode:{type:"string",enum:["adv","nvl"]},content:{type:"array",items:{type:"object",properties:{text:{type:"string"}}}},textSpeed:{type:"number"},append:{type:"boolean"},characterId:{type:"string"},characterName:{type:"string"},persistCharacter:{type:"boolean"},persistSprite:{type:"boolean"},character:{type:"object",properties:{name:{type:"string"},sprite:{type:"object",properties:{transformId:{type:"string"},items:{type:"array",items:{type:"object",properties:{id:{type:"string"},resourceId:{type:"string"},animationName:{type:"string"},animationSpeed:{type:"number"},loop:{type:"boolean"}},required:["id","resourceId"],additionalProperties:!1}},animations:{$ref:"#/definitions/animationSelection"}},additionalProperties:!1}},additionalProperties:!1},clear:{type:"boolean"},clearPage:{type:"boolean"}},additionalProperties:!1};function _n(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!Ze.call(jc.properties,o)){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.ui!==void 0){let o=e.ui;if(o&&typeof o=="object"&&!Array.isArray(o)){for(let l in o)if(!(l==="resourceId"||l==="animations")){let c={instancePath:t+"/ui",schemaPath:"#/properties/ui/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:l},message:"must NOT have additional properties"};r===null?r=[c]:r.push(c),s++}if(o.resourceId!==void 0&&typeof o.resourceId!="string"){let l={instancePath:t+"/ui/resourceId",schemaPath:"#/properties/ui/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}o.animations!==void 0&&(J(o.animations,{instancePath:t+"/ui/animations",parentData:o,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let l={instancePath:t+"/ui",schemaPath:"#/properties/ui/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}if(e.mode!==void 0){let o=e.mode;if(typeof o!="string"){let l={instancePath:t+"/mode",schemaPath:"#/properties/mode/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(!(o==="adv"||o==="nvl")){let l={instancePath:t+"/mode",schemaPath:"#/properties/mode/enum",keyword:"enum",params:{allowedValues:jc.properties.mode.enum},message:"must be equal to one of the allowed values"};r===null?r=[l]:r.push(l),s++}}if(e.content!==void 0){let o=e.content;if(Array.isArray(o)){let l=o.length;for(let c=0;c<l;c++){let u=o[c];if(u&&typeof u=="object"&&!Array.isArray(u)){if(u.text!==void 0&&typeof u.text!="string"){let p={instancePath:t+"/content/"+c+"/text",schemaPath:"#/properties/content/items/properties/text/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[p]:r.push(p),s++}}else{let p={instancePath:t+"/content/"+c,schemaPath:"#/properties/content/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}}else{let l={instancePath:t+"/content",schemaPath:"#/properties/content/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[l]:r.push(l),s++}}if(e.textSpeed!==void 0&&typeof e.textSpeed!="number"){let o={instancePath:t+"/textSpeed",schemaPath:"#/properties/textSpeed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.append!==void 0&&typeof e.append!="boolean"){let o={instancePath:t+"/append",schemaPath:"#/properties/append/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.characterId!==void 0&&typeof e.characterId!="string"){let o={instancePath:t+"/characterId",schemaPath:"#/properties/characterId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.characterName!==void 0&&typeof e.characterName!="string"){let o={instancePath:t+"/characterName",schemaPath:"#/properties/characterName/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.persistCharacter!==void 0&&typeof e.persistCharacter!="boolean"){let o={instancePath:t+"/persistCharacter",schemaPath:"#/properties/persistCharacter/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.persistSprite!==void 0&&typeof e.persistSprite!="boolean"){let o={instancePath:t+"/persistSprite",schemaPath:"#/properties/persistSprite/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.character!==void 0){let o=e.character;if(o&&typeof o=="object"&&!Array.isArray(o)){for(let l in o)if(!(l==="name"||l==="sprite")){let c={instancePath:t+"/character",schemaPath:"#/properties/character/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:l},message:"must NOT have additional properties"};r===null?r=[c]:r.push(c),s++}if(o.name!==void 0&&typeof o.name!="string"){let l={instancePath:t+"/character/name",schemaPath:"#/properties/character/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(o.sprite!==void 0){let l=o.sprite;if(l&&typeof l=="object"&&!Array.isArray(l)){for(let c in l)if(!(c==="transformId"||c==="items"||c==="animations")){let u={instancePath:t+"/character/sprite",schemaPath:"#/properties/character/properties/sprite/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:c},message:"must NOT have additional properties"};r===null?r=[u]:r.push(u),s++}if(l.transformId!==void 0&&typeof l.transformId!="string"){let c={instancePath:t+"/character/sprite/transformId",schemaPath:"#/properties/character/properties/sprite/properties/transformId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[c]:r.push(c),s++}if(l.items!==void 0){let c=l.items;if(Array.isArray(c)){let u=c.length;for(let p=0;p<u;p++){let m=c[p];if(m&&typeof m=="object"&&!Array.isArray(m)){if(m.id===void 0){let d={instancePath:t+"/character/sprite/items/"+p,schemaPath:"#/properties/character/properties/sprite/properties/items/items/required",keyword:"required",params:{missingProperty:"id"},message:"must have required property 'id'"};r===null?r=[d]:r.push(d),s++}if(m.resourceId===void 0){let d={instancePath:t+"/character/sprite/items/"+p,schemaPath:"#/properties/character/properties/sprite/properties/items/items/required",keyword:"required",params:{missingProperty:"resourceId"},message:"must have required property 'resourceId'"};r===null?r=[d]:r.push(d),s++}for(let d in m)if(!(d==="id"||d==="resourceId"||d==="animationName"||d==="animationSpeed"||d==="loop")){let f={instancePath:t+"/character/sprite/items/"+p,schemaPath:"#/properties/character/properties/sprite/properties/items/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:d},message:"must NOT have additional properties"};r===null?r=[f]:r.push(f),s++}if(m.id!==void 0&&typeof m.id!="string"){let d={instancePath:t+"/character/sprite/items/"+p+"/id",schemaPath:"#/properties/character/properties/sprite/properties/items/items/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[d]:r.push(d),s++}if(m.resourceId!==void 0&&typeof m.resourceId!="string"){let d={instancePath:t+"/character/sprite/items/"+p+"/resourceId",schemaPath:"#/properties/character/properties/sprite/properties/items/items/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[d]:r.push(d),s++}if(m.animationName!==void 0&&typeof m.animationName!="string"){let d={instancePath:t+"/character/sprite/items/"+p+"/animationName",schemaPath:"#/properties/character/properties/sprite/properties/items/items/properties/animationName/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[d]:r.push(d),s++}if(m.animationSpeed!==void 0&&typeof m.animationSpeed!="number"){let d={instancePath:t+"/character/sprite/items/"+p+"/animationSpeed",schemaPath:"#/properties/character/properties/sprite/properties/items/items/properties/animationSpeed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[d]:r.push(d),s++}if(m.loop!==void 0&&typeof m.loop!="boolean"){let d={instancePath:t+"/character/sprite/items/"+p+"/loop",schemaPath:"#/properties/character/properties/sprite/properties/items/items/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[d]:r.push(d),s++}}else{let d={instancePath:t+"/character/sprite/items/"+p,schemaPath:"#/properties/character/properties/sprite/properties/items/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[d]:r.push(d),s++}}}else{let u={instancePath:t+"/character/sprite/items",schemaPath:"#/properties/character/properties/sprite/properties/items/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[u]:r.push(u),s++}}l.animations!==void 0&&(J(l.animations,{instancePath:t+"/character/sprite/animations",parentData:l,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let c={instancePath:t+"/character/sprite",schemaPath:"#/properties/character/properties/sprite/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[c]:r.push(c),s++}}}else{let l={instancePath:t+"/character",schemaPath:"#/properties/character/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}if(e.clear!==void 0&&typeof e.clear!="boolean"){let o={instancePath:t+"/clear",schemaPath:"#/properties/clear/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.clearPage!==void 0&&typeof e.clearPage!="boolean"){let o={instancePath:t+"/clearPage",schemaPath:"#/properties/clearPage/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return _n.errors=r,s===0}function Kc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return _n(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?_n.errors:r.concat(_n.errors),s=r.length),Kc.errors=r,s===0}var Jc=Qc;function $n(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!(o==="id"||o==="resourceId"||o==="fields"||o==="submitActions"||o==="cancelActions"||o==="animations")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.id!==void 0&&typeof e.id!="string"){let o={instancePath:t+"/id",schemaPath:"#/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let o={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.fields!==void 0){let o=e.fields;if(o&&typeof o=="object"&&!Array.isArray(o))for(let l in o){let c=o[l];if(c&&typeof c=="object"&&!Array.isArray(c)){if(c.variableId===void 0){let u={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/fields/additionalProperties/required",keyword:"required",params:{missingProperty:"variableId"},message:"must have required property 'variableId'"};r===null?r=[u]:r.push(u),s++}for(let u in c)if(!(u==="variableId"||u==="required"||u==="trim"||u==="placeholder"||u==="multiline"||u==="maxLength")){let p={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/fields/additionalProperties/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:u},message:"must NOT have additional properties"};r===null?r=[p]:r.push(p),s++}if(c.variableId!==void 0&&typeof c.variableId!="string"){let u={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/variableId",schemaPath:"#/properties/fields/additionalProperties/properties/variableId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[u]:r.push(u),s++}if(c.required!==void 0&&typeof c.required!="boolean"){let u={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/required",schemaPath:"#/properties/fields/additionalProperties/properties/required/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[u]:r.push(u),s++}if(c.trim!==void 0&&typeof c.trim!="boolean"){let u={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/trim",schemaPath:"#/properties/fields/additionalProperties/properties/trim/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[u]:r.push(u),s++}if(c.placeholder!==void 0&&typeof c.placeholder!="string"){let u={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/placeholder",schemaPath:"#/properties/fields/additionalProperties/properties/placeholder/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[u]:r.push(u),s++}if(c.multiline!==void 0&&typeof c.multiline!="boolean"){let u={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/multiline",schemaPath:"#/properties/fields/additionalProperties/properties/multiline/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[u]:r.push(u),s++}if(c.maxLength!==void 0){let u=c.maxLength;if(!(typeof u=="number"&&!(u%1)&&!isNaN(u))){let p={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/maxLength",schemaPath:"#/properties/fields/additionalProperties/properties/maxLength/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[p]:r.push(p),s++}if(typeof u=="number"&&(u<0||isNaN(u))){let p={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/maxLength",schemaPath:"#/properties/fields/additionalProperties/properties/maxLength/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[p]:r.push(p),s++}}}else{let u={instancePath:t+"/fields/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/fields/additionalProperties/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[u]:r.push(u),s++}}else{let l={instancePath:t+"/fields",schemaPath:"#/properties/fields/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}if(e.submitActions!==void 0){let o=e.submitActions;if(!(o&&typeof o=="object"&&!Array.isArray(o))){let l={instancePath:t+"/submitActions",schemaPath:"#/properties/submitActions/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}if(e.cancelActions!==void 0){let o=e.cancelActions;if(!(o&&typeof o=="object"&&!Array.isArray(o))){let l={instancePath:t+"/cancelActions",schemaPath:"#/properties/cancelActions/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}e.animations!==void 0&&(J(e.animations,{instancePath:t+"/animations",parentData:e,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return $n.errors=r,s===0}function Qc(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return $n(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?$n.errors:r.concat($n.errors),s=r.length),Qc.errors=r,s===0}var Zc=eu;function jn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!(o==="resourceId"||o==="animations")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let o={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}e.animations!==void 0&&(J(e.animations,{instancePath:t+"/animations",parentData:e,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return jn.errors=r,s===0}function eu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return jn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?jn.errors:r.concat(jn.errors),s=r.length),eu.errors=r,s===0}var ru=tu;function Nn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!(o==="opacity"||o==="blur"||o==="animations")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.opacity!==void 0){let o=e.opacity;if(typeof o=="number"){if(o>1||isNaN(o)){let l={instancePath:t+"/opacity",schemaPath:"#/properties/opacity/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[l]:r.push(l),s++}if(o<0||isNaN(o)){let l={instancePath:t+"/opacity",schemaPath:"#/properties/opacity/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/opacity",schemaPath:"#/properties/opacity/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}e.blur!==void 0&&(Ce(e.blur,{instancePath:t+"/blur",parentData:e,parentDataProperty:"blur",rootData:a})||(r=r===null?Ce.errors:r.concat(Ce.errors),s=r.length)),e.animations!==void 0&&(J(e.animations,{instancePath:t+"/animations",parentData:e,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Nn.errors=r,s===0}function tu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Nn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Nn.errors:r.concat(Nn.errors),s=r.length),tu.errors=r,s===0}var nu=su;var xb={type:"object",properties:{items:{type:"array",items:{$ref:"#/definitions/audioSound"}},channels:{type:"array",items:{type:"object",properties:{id:{type:"string",minLength:1},volume:{type:"number",minimum:0,maximum:100},muted:{type:"boolean"},pan:{type:"number",minimum:-1,maximum:1},loop:{type:"boolean"},interruption:{type:"string",enum:["immediate","loopEnd"]},sounds:{type:"array",items:{$ref:"#/definitions/audioSound"}}},required:["id","sounds"],additionalProperties:!1}}},allOf:[{not:{required:["items","channels"]}}],additionalProperties:!1};function Dn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let u;if(e.items===void 0&&(u="items")||e.channels===void 0&&(u="channels")){let p={};r===null?r=[p]:r.push(p),s++}}var c=l===s;if(c){let u={instancePath:t,schemaPath:"#/allOf/0/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[u]:r.push(u),s++}else s=o,r!==null&&(o?r.length=o:r=null);if(e&&typeof e=="object"&&!Array.isArray(e)){for(let u in e)if(!(u==="items"||u==="channels")){let p={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:u},message:"must NOT have additional properties"};r===null?r=[p]:r.push(p),s++}if(e.items!==void 0){let u=e.items;if(Array.isArray(u)){let p=u.length;for(let m=0;m<p;m++)Oe(u[m],{instancePath:t+"/items/"+m,parentData:u,parentDataProperty:m,rootData:a})||(r=r===null?Oe.errors:r.concat(Oe.errors),s=r.length)}else{let p={instancePath:t+"/items",schemaPath:"#/properties/items/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[p]:r.push(p),s++}}if(e.channels!==void 0){let u=e.channels;if(Array.isArray(u)){let p=u.length;for(let m=0;m<p;m++){let d=u[m];if(d&&typeof d=="object"&&!Array.isArray(d)){if(d.id===void 0){let f={instancePath:t+"/channels/"+m,schemaPath:"#/properties/channels/items/required",keyword:"required",params:{missingProperty:"id"},message:"must have required property 'id'"};r===null?r=[f]:r.push(f),s++}if(d.sounds===void 0){let f={instancePath:t+"/channels/"+m,schemaPath:"#/properties/channels/items/required",keyword:"required",params:{missingProperty:"sounds"},message:"must have required property 'sounds'"};r===null?r=[f]:r.push(f),s++}for(let f in d)if(!(f==="id"||f==="volume"||f==="muted"||f==="pan"||f==="loop"||f==="interruption"||f==="sounds")){let y={instancePath:t+"/channels/"+m,schemaPath:"#/properties/channels/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:f},message:"must NOT have additional properties"};r===null?r=[y]:r.push(y),s++}if(d.id!==void 0){let f=d.id;if(typeof f=="string"){if(Re(f)<1){let y={instancePath:t+"/channels/"+m+"/id",schemaPath:"#/properties/channels/items/properties/id/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[y]:r.push(y),s++}}else{let y={instancePath:t+"/channels/"+m+"/id",schemaPath:"#/properties/channels/items/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[y]:r.push(y),s++}}if(d.volume!==void 0){let f=d.volume;if(typeof f=="number"){if(f>100||isNaN(f)){let y={instancePath:t+"/channels/"+m+"/volume",schemaPath:"#/properties/channels/items/properties/volume/maximum",keyword:"maximum",params:{comparison:"<=",limit:100},message:"must be <= 100"};r===null?r=[y]:r.push(y),s++}if(f<0||isNaN(f)){let y={instancePath:t+"/channels/"+m+"/volume",schemaPath:"#/properties/channels/items/properties/volume/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[y]:r.push(y),s++}}else{let y={instancePath:t+"/channels/"+m+"/volume",schemaPath:"#/properties/channels/items/properties/volume/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}}if(d.muted!==void 0&&typeof d.muted!="boolean"){let f={instancePath:t+"/channels/"+m+"/muted",schemaPath:"#/properties/channels/items/properties/muted/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[f]:r.push(f),s++}if(d.pan!==void 0){let f=d.pan;if(typeof f=="number"){if(f>1||isNaN(f)){let y={instancePath:t+"/channels/"+m+"/pan",schemaPath:"#/properties/channels/items/properties/pan/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[y]:r.push(y),s++}if(f<-1||isNaN(f)){let y={instancePath:t+"/channels/"+m+"/pan",schemaPath:"#/properties/channels/items/properties/pan/minimum",keyword:"minimum",params:{comparison:">=",limit:-1},message:"must be >= -1"};r===null?r=[y]:r.push(y),s++}}else{let y={instancePath:t+"/channels/"+m+"/pan",schemaPath:"#/properties/channels/items/properties/pan/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}}if(d.loop!==void 0&&typeof d.loop!="boolean"){let f={instancePath:t+"/channels/"+m+"/loop",schemaPath:"#/properties/channels/items/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[f]:r.push(f),s++}if(d.interruption!==void 0){let f=d.interruption;if(typeof f!="string"){let y={instancePath:t+"/channels/"+m+"/interruption",schemaPath:"#/properties/channels/items/properties/interruption/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[y]:r.push(y),s++}if(!(f==="immediate"||f==="loopEnd")){let y={instancePath:t+"/channels/"+m+"/interruption",schemaPath:"#/properties/channels/items/properties/interruption/enum",keyword:"enum",params:{allowedValues:xb.properties.channels.items.properties.interruption.enum},message:"must be equal to one of the allowed values"};r===null?r=[y]:r.push(y),s++}}if(d.sounds!==void 0){let f=d.sounds;if(Array.isArray(f)){let y=f.length;for(let g=0;g<y;g++)Oe(f[g],{instancePath:t+"/channels/"+m+"/sounds/"+g,parentData:f,parentDataProperty:g,rootData:a})||(r=r===null?Oe.errors:r.concat(Oe.errors),s=r.length)}else{let y={instancePath:t+"/channels/"+m+"/sounds",schemaPath:"#/properties/channels/items/properties/sounds/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[y]:r.push(y),s++}}}else{let f={instancePath:t+"/channels/"+m,schemaPath:"#/properties/channels/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[f]:r.push(f),s++}}}else{let p={instancePath:t+"/channels",schemaPath:"#/properties/channels/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[p]:r.push(p),s++}}}else{let u={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[u]:r.push(u),s++}return Dn.errors=r,s===0}function su(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Dn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Dn.errors:r.concat(Dn.errors),s=r.length),su.errors=r,s===0}var iu=ou;var Nc={type:"object",properties:{items:{type:"array",items:{type:"object",properties:{id:{type:"string"},animationName:{type:"string"},animationSpeed:{type:"number"},resourceId:{type:"string"},text:{$ref:"#/definitions/visualText"},transformId:{type:"string"},x:{type:"number"},y:{type:"number"},anchorX:{type:"number"},anchorY:{type:"number"},scaleX:{type:"number"},scaleY:{type:"number"},rotation:{type:"number"},originX:{type:"number"},originY:{type:"number"},layer:{type:"number",enum:[10,30,50,70,90]},opacity:{type:"number",minimum:0,maximum:1},blur:{$ref:"#/definitions/backgroundBlur"},animations:{$ref:"#/definitions/animationSelection"}},required:["id"],allOf:[{not:{required:["resourceId","text"]}}],additionalProperties:!1}}},additionalProperties:!1};function Tn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=!1,c=s;if(typeof e!="string"){let p={instancePath:t,schemaPath:"#/anyOf/0/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[p]:r.push(p),s++}var u=c===s;if(l=l||u,!l){let p=s;if(Array.isArray(e)){let d=e.length;for(let f=0;f<d;f++){let y=e[f];if(y&&typeof y=="object"&&!Array.isArray(y)){if(y.text!==void 0&&typeof y.text!="string"){let g={instancePath:t+"/"+f+"/text",schemaPath:"#/anyOf/1/items/properties/text/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[g]:r.push(g),s++}if(y.textStyleId!==void 0&&typeof y.textStyleId!="string"){let g={instancePath:t+"/"+f+"/textStyleId",schemaPath:"#/anyOf/1/items/properties/textStyleId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[g]:r.push(g),s++}if(y.furigana!==void 0){let g=y.furigana;if(g&&typeof g=="object"&&!Array.isArray(g)){if(g.text!==void 0&&typeof g.text!="string"){let h={instancePath:t+"/"+f+"/furigana/text",schemaPath:"#/anyOf/1/items/properties/furigana/properties/text/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}if(g.textStyleId!==void 0&&typeof g.textStyleId!="string"){let h={instancePath:t+"/"+f+"/furigana/textStyleId",schemaPath:"#/anyOf/1/items/properties/furigana/properties/textStyleId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}}else{let h={instancePath:t+"/"+f+"/furigana",schemaPath:"#/anyOf/1/items/properties/furigana/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[h]:r.push(h),s++}}}else{let g={instancePath:t+"/"+f,schemaPath:"#/anyOf/1/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[g]:r.push(g),s++}}}else{let d={instancePath:t,schemaPath:"#/anyOf/1/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[d]:r.push(d),s++}var u=p===s;l=l||u}if(l)s=o,r!==null&&(o?r.length=o:r=null);else{let p={instancePath:t,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};r===null?r=[p]:r.push(p),s++}return Tn.errors=r,s===0}function Ln(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=s,c=s,u=!1,p=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let w;if(e.id===void 0&&(w="id")){let b={};r===null?r=[b]:r.push(b),s++}}var m=p===s;if(u=u||m,!u){let w=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let E;if(e.type===void 0&&(E="type")){let v={};r===null?r=[v]:r.push(v),s++}}var m=w===s;if(u=u||m,!u){let E=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let k;if(e.resourceId===void 0&&(k="resourceId")){let x={};r===null?r=[x]:r.push(x),s++}}var m=E===s;if(u=u||m,!u){let k=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let C;if(e.transformId===void 0&&(C="transformId")){let N={};r===null?r=[N]:r.push(N),s++}}var m=k===s;if(u=u||m,!u){let C=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let P;if(e.x===void 0&&(P="x")){let T={};r===null?r=[T]:r.push(T),s++}}var m=C===s;if(u=u||m,!u){let P=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let q;if(e.y===void 0&&(q="y")){let ae={};r===null?r=[ae]:r.push(ae),s++}}var m=P===s;if(u=u||m,!u){let q=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let B;if(e.anchorX===void 0&&(B="anchorX")){let ne={};r===null?r=[ne]:r.push(ne),s++}}var m=q===s;if(u=u||m,!u){let B=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let ie;if(e.anchorY===void 0&&(ie="anchorY")){let fe={};r===null?r=[fe]:r.push(fe),s++}}var m=B===s;if(u=u||m,!u){let ie=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let ve;if(e.scaleX===void 0&&(ve="scaleX")){let le={};r===null?r=[le]:r.push(le),s++}}var m=ie===s;if(u=u||m,!u){let ve=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let se;if(e.scaleY===void 0&&(se="scaleY")){let ce={};r===null?r=[ce]:r.push(ce),s++}}var m=ve===s;if(u=u||m,!u){let se=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let oe;if(e.rotation===void 0&&(oe="rotation")){let R={};r===null?r=[R]:r.push(R),s++}}var m=se===s;if(u=u||m,!u){let oe=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let j;if(e.originX===void 0&&(j="originX")){let M={};r===null?r=[M]:r.push(M),s++}}var m=oe===s;if(u=u||m,!u){let j=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let Z;if(e.originY===void 0&&(Z="originY")){let ge={};r===null?r=[ge]:r.push(ge),s++}}var m=j===s;if(u=u||m,!u){let Z=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let K;if(e.layer===void 0&&(K="layer")){let xe={};r===null?r=[xe]:r.push(xe),s++}}var m=Z===s;if(u=u||m,!u){let K=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let me;if(e.opacity===void 0&&(me="opacity")){let Jr={};r===null?r=[Jr]:r.push(Jr),s++}}var m=K===s;if(u=u||m,!u){let me=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let Qr;if(e.blur===void 0&&(Qr="blur")){let Zr={};r===null?r=[Zr]:r.push(Zr),s++}}var m=me===s;if(u=u||m,!u){let Qr=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let cs;if(e.animations===void 0&&(cs="animations")){let jt={};r===null?r=[jt]:r.push(jt),s++}}var m=Qr===s;u=u||m}}}}}}}}}}}}}}}}if(u)s=c,r!==null&&(c?r.length=c:r=null);else{let w={};r===null?r=[w]:r.push(w),s++}var d=l===s;if(d){let w={instancePath:t,schemaPath:"#/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[w]:r.push(w),s++}else s=o,r!==null&&(o?r.length=o:r=null);let f=s,y=!1,g=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.content===void 0){let w={instancePath:t,schemaPath:"#/anyOf/0/required",keyword:"required",params:{missingProperty:"content"},message:"must have required property 'content'"};r===null?r=[w]:r.push(w),s++}var h=g===s;if(y=y||h,!y){let w=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.textStyleId===void 0){let E={instancePath:t,schemaPath:"#/anyOf/1/required",keyword:"required",params:{missingProperty:"textStyleId"},message:"must have required property 'textStyleId'"};r===null?r=[E]:r.push(E),s++}var h=w===s;y=y||h}if(y)s=f,r!==null&&(f?r.length=f:r=null);else{let w={instancePath:t,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};r===null?r=[w]:r.push(w),s++}if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.content!==void 0&&(Tn(e.content,{instancePath:t+"/content",parentData:e,parentDataProperty:"content",rootData:a})||(r=r===null?Tn.errors:r.concat(Tn.errors),s=r.length)),e.textStyleId!==void 0&&typeof e.textStyleId!="string"){let w={instancePath:t+"/textStyleId",schemaPath:"#/properties/textStyleId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[w]:r.push(w),s++}if(e.width!==void 0&&typeof e.width!="number"){let w={instancePath:t+"/width",schemaPath:"#/properties/width/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[w]:r.push(w),s++}if(e.height!==void 0&&typeof e.height!="number"){let w={instancePath:t+"/height",schemaPath:"#/properties/height/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[w]:r.push(w),s++}}else{let w={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[w]:r.push(w),s++}return Ln.errors=r,s===0}function Mn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let l in e)if(l!=="items"){let c={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:l},message:"must NOT have additional properties"};r===null?r=[c]:r.push(c),s++}if(e.items!==void 0){let l=e.items;if(Array.isArray(l)){let c=l.length;for(let u=0;u<c;u++){let p=l[u],m=s,d=s;if(p&&typeof p=="object"&&!Array.isArray(p)){let f;if(p.resourceId===void 0&&(f="resourceId")||p.text===void 0&&(f="text")){let y={};r===null?r=[y]:r.push(y),s++}}var o=d===s;if(o){let f={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/allOf/0/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[f]:r.push(f),s++}else s=m,r!==null&&(m?r.length=m:r=null);if(p&&typeof p=="object"&&!Array.isArray(p)){if(p.id===void 0){let f={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/required",keyword:"required",params:{missingProperty:"id"},message:"must have required property 'id'"};r===null?r=[f]:r.push(f),s++}for(let f in p)if(!Ze.call(Nc.properties.items.items.properties,f)){let y={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:f},message:"must NOT have additional properties"};r===null?r=[y]:r.push(y),s++}if(p.id!==void 0&&typeof p.id!="string"){let f={instancePath:t+"/items/"+u+"/id",schemaPath:"#/properties/items/items/properties/id/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[f]:r.push(f),s++}if(p.animationName!==void 0&&typeof p.animationName!="string"){let f={instancePath:t+"/items/"+u+"/animationName",schemaPath:"#/properties/items/items/properties/animationName/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[f]:r.push(f),s++}if(p.animationSpeed!==void 0&&typeof p.animationSpeed!="number"){let f={instancePath:t+"/items/"+u+"/animationSpeed",schemaPath:"#/properties/items/items/properties/animationSpeed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.resourceId!==void 0&&typeof p.resourceId!="string"){let f={instancePath:t+"/items/"+u+"/resourceId",schemaPath:"#/properties/items/items/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[f]:r.push(f),s++}if(p.text!==void 0&&(Ln(p.text,{instancePath:t+"/items/"+u+"/text",parentData:p,parentDataProperty:"text",rootData:a})||(r=r===null?Ln.errors:r.concat(Ln.errors),s=r.length)),p.transformId!==void 0&&typeof p.transformId!="string"){let f={instancePath:t+"/items/"+u+"/transformId",schemaPath:"#/properties/items/items/properties/transformId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[f]:r.push(f),s++}if(p.x!==void 0&&typeof p.x!="number"){let f={instancePath:t+"/items/"+u+"/x",schemaPath:"#/properties/items/items/properties/x/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.y!==void 0&&typeof p.y!="number"){let f={instancePath:t+"/items/"+u+"/y",schemaPath:"#/properties/items/items/properties/y/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.anchorX!==void 0&&typeof p.anchorX!="number"){let f={instancePath:t+"/items/"+u+"/anchorX",schemaPath:"#/properties/items/items/properties/anchorX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.anchorY!==void 0&&typeof p.anchorY!="number"){let f={instancePath:t+"/items/"+u+"/anchorY",schemaPath:"#/properties/items/items/properties/anchorY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.scaleX!==void 0&&typeof p.scaleX!="number"){let f={instancePath:t+"/items/"+u+"/scaleX",schemaPath:"#/properties/items/items/properties/scaleX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.scaleY!==void 0&&typeof p.scaleY!="number"){let f={instancePath:t+"/items/"+u+"/scaleY",schemaPath:"#/properties/items/items/properties/scaleY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.rotation!==void 0&&typeof p.rotation!="number"){let f={instancePath:t+"/items/"+u+"/rotation",schemaPath:"#/properties/items/items/properties/rotation/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.originX!==void 0&&typeof p.originX!="number"){let f={instancePath:t+"/items/"+u+"/originX",schemaPath:"#/properties/items/items/properties/originX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.originY!==void 0&&typeof p.originY!="number"){let f={instancePath:t+"/items/"+u+"/originY",schemaPath:"#/properties/items/items/properties/originY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[f]:r.push(f),s++}if(p.layer!==void 0){let f=p.layer;if(typeof f!="number"){let y={instancePath:t+"/items/"+u+"/layer",schemaPath:"#/properties/items/items/properties/layer/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}if(!(f===10||f===30||f===50||f===70||f===90)){let y={instancePath:t+"/items/"+u+"/layer",schemaPath:"#/properties/items/items/properties/layer/enum",keyword:"enum",params:{allowedValues:Nc.properties.items.items.properties.layer.enum},message:"must be equal to one of the allowed values"};r===null?r=[y]:r.push(y),s++}}if(p.opacity!==void 0){let f=p.opacity;if(typeof f=="number"){if(f>1||isNaN(f)){let y={instancePath:t+"/items/"+u+"/opacity",schemaPath:"#/properties/items/items/properties/opacity/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[y]:r.push(y),s++}if(f<0||isNaN(f)){let y={instancePath:t+"/items/"+u+"/opacity",schemaPath:"#/properties/items/items/properties/opacity/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[y]:r.push(y),s++}}else{let y={instancePath:t+"/items/"+u+"/opacity",schemaPath:"#/properties/items/items/properties/opacity/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[y]:r.push(y),s++}}p.blur!==void 0&&(Ce(p.blur,{instancePath:t+"/items/"+u+"/blur",parentData:p,parentDataProperty:"blur",rootData:a})||(r=r===null?Ce.errors:r.concat(Ce.errors),s=r.length)),p.animations!==void 0&&(J(p.animations,{instancePath:t+"/items/"+u+"/animations",parentData:p,parentDataProperty:"animations",rootData:a})||(r=r===null?J.errors:r.concat(J.errors),s=r.length))}else{let f={instancePath:t+"/items/"+u,schemaPath:"#/properties/items/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[f]:r.push(f),s++}}}else{let c={instancePath:t+"/items",schemaPath:"#/properties/items/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[c]:r.push(c),s++}}}else{let l={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}return Mn.errors=r,s===0}function ou(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Mn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Mn.errors:r.concat(Mn.errors),s=r.length),ou.errors=r,s===0}var au=lu;var Eb={type:"object",properties:{sounds:{type:"array",items:{$ref:"#/definitions/audioSound"}},resourceId:{type:"string"},volume:{type:"number",minimum:0,maximum:100},muted:{type:"boolean"},pan:{type:"number",minimum:-1,maximum:1},loop:{type:"boolean"},interruption:{type:"string",enum:["immediate","loopEnd"]},startDelayMs:{type:"number",minimum:0}},anyOf:[{required:["resourceId"]},{required:["sounds"]}],allOf:[{not:{required:["resourceId","sounds"]}},{not:{required:["startDelayMs","sounds"]}}],additionalProperties:!1};function qn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=!1,c=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.resourceId===void 0){let h={instancePath:t,schemaPath:"#/anyOf/0/required",keyword:"required",params:{missingProperty:"resourceId"},message:"must have required property 'resourceId'"};r===null?r=[h]:r.push(h),s++}var u=c===s;if(l=l||u,!l){let h=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.sounds===void 0){let b={instancePath:t,schemaPath:"#/anyOf/1/required",keyword:"required",params:{missingProperty:"sounds"},message:"must have required property 'sounds'"};r===null?r=[b]:r.push(b),s++}var u=h===s;l=l||u}if(l)s=o,r!==null&&(o?r.length=o:r=null);else{let h={instancePath:t,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};r===null?r=[h]:r.push(h),s++}let p=s,m=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let h;if(e.resourceId===void 0&&(h="resourceId")||e.sounds===void 0&&(h="sounds")){let w={};r===null?r=[w]:r.push(w),s++}}var d=m===s;if(d){let h={instancePath:t,schemaPath:"#/allOf/0/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[h]:r.push(h),s++}else s=p,r!==null&&(p?r.length=p:r=null);let f=s,y=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let h;if(e.startDelayMs===void 0&&(h="startDelayMs")||e.sounds===void 0&&(h="sounds")){let w={};r===null?r=[w]:r.push(w),s++}}var g=y===s;if(g){let h={instancePath:t,schemaPath:"#/allOf/1/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[h]:r.push(h),s++}else s=f,r!==null&&(f?r.length=f:r=null);if(e&&typeof e=="object"&&!Array.isArray(e)){for(let h in e)if(!(h==="sounds"||h==="resourceId"||h==="volume"||h==="muted"||h==="pan"||h==="loop"||h==="interruption"||h==="startDelayMs")){let w={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:h},message:"must NOT have additional properties"};r===null?r=[w]:r.push(w),s++}if(e.sounds!==void 0){let h=e.sounds;if(Array.isArray(h)){let w=h.length;for(let b=0;b<w;b++)Oe(h[b],{instancePath:t+"/sounds/"+b,parentData:h,parentDataProperty:b,rootData:a})||(r=r===null?Oe.errors:r.concat(Oe.errors),s=r.length)}else{let w={instancePath:t+"/sounds",schemaPath:"#/properties/sounds/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[w]:r.push(w),s++}}if(e.resourceId!==void 0&&typeof e.resourceId!="string"){let h={instancePath:t+"/resourceId",schemaPath:"#/properties/resourceId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}if(e.volume!==void 0){let h=e.volume;if(typeof h=="number"){if(h>100||isNaN(h)){let w={instancePath:t+"/volume",schemaPath:"#/properties/volume/maximum",keyword:"maximum",params:{comparison:"<=",limit:100},message:"must be <= 100"};r===null?r=[w]:r.push(w),s++}if(h<0||isNaN(h)){let w={instancePath:t+"/volume",schemaPath:"#/properties/volume/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[w]:r.push(w),s++}}else{let w={instancePath:t+"/volume",schemaPath:"#/properties/volume/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[w]:r.push(w),s++}}if(e.muted!==void 0&&typeof e.muted!="boolean"){let h={instancePath:t+"/muted",schemaPath:"#/properties/muted/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[h]:r.push(h),s++}if(e.pan!==void 0){let h=e.pan;if(typeof h=="number"){if(h>1||isNaN(h)){let w={instancePath:t+"/pan",schemaPath:"#/properties/pan/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[w]:r.push(w),s++}if(h<-1||isNaN(h)){let w={instancePath:t+"/pan",schemaPath:"#/properties/pan/minimum",keyword:"minimum",params:{comparison:">=",limit:-1},message:"must be >= -1"};r===null?r=[w]:r.push(w),s++}}else{let w={instancePath:t+"/pan",schemaPath:"#/properties/pan/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[w]:r.push(w),s++}}if(e.loop!==void 0&&typeof e.loop!="boolean"){let h={instancePath:t+"/loop",schemaPath:"#/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[h]:r.push(h),s++}if(e.interruption!==void 0){let h=e.interruption;if(typeof h!="string"){let w={instancePath:t+"/interruption",schemaPath:"#/properties/interruption/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[w]:r.push(w),s++}if(!(h==="immediate"||h==="loopEnd")){let w={instancePath:t+"/interruption",schemaPath:"#/properties/interruption/enum",keyword:"enum",params:{allowedValues:Eb.properties.interruption.enum},message:"must be equal to one of the allowed values"};r===null?r=[w]:r.push(w),s++}}if(e.startDelayMs!==void 0){let h=e.startDelayMs;if(typeof h=="number"){if(h<0||isNaN(h)){let w={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[w]:r.push(w),s++}}else{let w={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[w]:r.push(w),s++}}}else{let h={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[h]:r.push(h),s++}return qn.errors=r,s===0}function lu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return qn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?qn.errors:r.concat(qn.errors),s=r.length),lu.errors=r,s===0}var cu=uu;var Sb={type:"object",properties:{type:{type:"string",enum:["boolean","number"]},target:{type:"integer",minimum:1},name:{type:"string",minLength:1},description:{type:"string",minLength:1},lockedName:{type:"string",minLength:1},lockedDescription:{type:"string",minLength:1},hidden:{type:"boolean"}},required:["type","name","description"],allOf:[{if:{properties:{type:{const:"number"}}},then:{required:["target"]}},{if:{properties:{type:{const:"boolean"}}},then:{not:{required:["target"]}}}],additionalProperties:!1};function Vn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=!0,c=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.type!==void 0&&e.type!=="number"){let g={};r===null?r=[g]:r.push(g),s++}var u=c===s;if(s=o,r!==null&&(o?r.length=o:r=null),u){let g=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.target===void 0){let w={instancePath:t,schemaPath:"#/allOf/0/then/required",keyword:"required",params:{missingProperty:"target"},message:"must have required property 'target'"};r===null?r=[w]:r.push(w),s++}var u=g===s;l=u}if(!l){let g={instancePath:t,schemaPath:"#/allOf/0/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[g]:r.push(g),s++}let p=s,m=!0,d=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.type!==void 0&&e.type!=="boolean"){let g={};r===null?r=[g]:r.push(g),s++}var f=d===s;if(s=p,r!==null&&(p?r.length=p:r=null),f){let g=s,h=s,w=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let E;if(e.target===void 0&&(E="target")){let v={};r===null?r=[v]:r.push(v),s++}}var y=w===s;if(y){let E={instancePath:t,schemaPath:"#/allOf/1/then/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[E]:r.push(E),s++}else s=h,r!==null&&(h?r.length=h:r=null);var f=g===s;m=f}if(!m){let g={instancePath:t,schemaPath:"#/allOf/1/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[g]:r.push(g),s++}if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.type===void 0){let g={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"type"},message:"must have required property 'type'"};r===null?r=[g]:r.push(g),s++}if(e.name===void 0){let g={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"name"},message:"must have required property 'name'"};r===null?r=[g]:r.push(g),s++}if(e.description===void 0){let g={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"description"},message:"must have required property 'description'"};r===null?r=[g]:r.push(g),s++}for(let g in e)if(!(g==="type"||g==="target"||g==="name"||g==="description"||g==="lockedName"||g==="lockedDescription"||g==="hidden")){let h={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:g},message:"must NOT have additional properties"};r===null?r=[h]:r.push(h),s++}if(e.type!==void 0){let g=e.type;if(typeof g!="string"){let h={instancePath:t+"/type",schemaPath:"#/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}if(!(g==="boolean"||g==="number")){let h={instancePath:t+"/type",schemaPath:"#/properties/type/enum",keyword:"enum",params:{allowedValues:Sb.properties.type.enum},message:"must be equal to one of the allowed values"};r===null?r=[h]:r.push(h),s++}}if(e.target!==void 0){let g=e.target;if(!(typeof g=="number"&&!(g%1)&&!isNaN(g))){let h={instancePath:t+"/target",schemaPath:"#/properties/target/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[h]:r.push(h),s++}if(typeof g=="number"&&(g<1||isNaN(g))){let h={instancePath:t+"/target",schemaPath:"#/properties/target/minimum",keyword:"minimum",params:{comparison:">=",limit:1},message:"must be >= 1"};r===null?r=[h]:r.push(h),s++}}if(e.name!==void 0){let g=e.name;if(typeof g=="string"){if(Re(g)<1){let h={instancePath:t+"/name",schemaPath:"#/properties/name/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[h]:r.push(h),s++}}else{let h={instancePath:t+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}}if(e.description!==void 0){let g=e.description;if(typeof g=="string"){if(Re(g)<1){let h={instancePath:t+"/description",schemaPath:"#/properties/description/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[h]:r.push(h),s++}}else{let h={instancePath:t+"/description",schemaPath:"#/properties/description/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}}if(e.lockedName!==void 0){let g=e.lockedName;if(typeof g=="string"){if(Re(g)<1){let h={instancePath:t+"/lockedName",schemaPath:"#/properties/lockedName/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[h]:r.push(h),s++}}else{let h={instancePath:t+"/lockedName",schemaPath:"#/properties/lockedName/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}}if(e.lockedDescription!==void 0){let g=e.lockedDescription;if(typeof g=="string"){if(Re(g)<1){let h={instancePath:t+"/lockedDescription",schemaPath:"#/properties/lockedDescription/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[h]:r.push(h),s++}}else{let h={instancePath:t+"/lockedDescription",schemaPath:"#/properties/lockedDescription/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[h]:r.push(h),s++}}if(e.hidden!==void 0&&typeof e.hidden!="boolean"){let g={instancePath:t+"/hidden",schemaPath:"#/properties/hidden/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[g]:r.push(g),s++}}else{let g={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[g]:r.push(g),s++}return Vn.errors=r,s===0}function uu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Vn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Vn.errors:r.concat(Vn.errors),s=r.length),uu.errors=r,s===0}var pu=fu;var Ob={type:"object",required:["type"],$defs:{keyframe:{type:"object",required:["value","duration"],properties:{value:{type:"number"},duration:{type:"number"},easing:{type:"string",enum:["linear","easeInQuad","easeOutQuad","easeInOutQuad","easeInCubic","easeOutCubic","easeInOutCubic","easeInQuart","easeOutQuart","easeInOutQuart","easeInQuint","easeOutQuint","easeInOutQuint","easeInSine","easeOutSine","easeInOutSine","easeInExpo","easeOutExpo","easeInOutExpo","easeInCirc","easeOutCirc","easeInOutCirc","easeInBack","easeOutBack","easeInOutBack","easeInBounce","easeOutBounce","easeInOutBounce","easeInElastic","easeOutElastic","easeInOutElastic"]},relative:{type:"boolean"}},additionalProperties:!1},tweenProperty:{type:"object",properties:{initialValue:{type:"number"},keyframes:{type:"array",minItems:1,items:{$ref:"#/$defs/keyframe"}}},required:["keyframes"],additionalProperties:!1},updateTween:{type:"object",properties:{alpha:{$ref:"#/$defs/tweenProperty"},x:{$ref:"#/$defs/tweenProperty"},y:{$ref:"#/$defs/tweenProperty"},scaleX:{$ref:"#/$defs/tweenProperty"},scaleY:{$ref:"#/$defs/tweenProperty"},rotation:{$ref:"#/$defs/tweenProperty"}},additionalProperties:!1,minProperties:1},transitionTween:{type:"object",properties:{translateX:{$ref:"#/$defs/tweenProperty"},translateY:{$ref:"#/$defs/tweenProperty"},alpha:{$ref:"#/$defs/tweenProperty"},scaleX:{$ref:"#/$defs/tweenProperty"},scaleY:{$ref:"#/$defs/tweenProperty"},rotation:{$ref:"#/$defs/tweenProperty"}},additionalProperties:!1,minProperties:1},transitionSide:{type:"object",required:["tween"],properties:{tween:{$ref:"#/$defs/transitionTween"}},additionalProperties:!1},maskProgress:{$ref:"#/$defs/tweenProperty"},compositeMaskItem:{type:"object",required:["texture"],properties:{texture:{type:"string"},channel:{type:"string",enum:["red","green","blue","alpha"]},invert:{type:"boolean"}},additionalProperties:!1},mask:{type:"object",required:["kind"],properties:{kind:{type:"string",enum:["single","sequence","composite"]},texture:{type:"string"},textures:{type:"array",minItems:1,items:{type:"string"}},items:{type:"array",minItems:1,items:{$ref:"#/$defs/compositeMaskItem"}},combine:{type:"string",enum:["max","min","multiply","add"]},channel:{type:"string",enum:["red","green","blue","alpha"]},softness:{type:"number"},invert:{type:"boolean"},sample:{type:"string"},progress:{$ref:"#/$defs/maskProgress"}},additionalProperties:!1,allOf:[{if:{properties:{kind:{const:"single"}}},then:{required:["texture"]}},{if:{properties:{kind:{const:"sequence"}}},then:{required:["textures"]}},{if:{properties:{kind:{const:"composite"}}},then:{required:["items"]}}]}},properties:{name:{type:"string"},type:{type:"string",enum:["update","transition"]},complete:{type:"object",properties:{payload:{type:"object"}},additionalProperties:!0},tween:{$ref:"#/$defs/updateTween"},prev:{$ref:"#/$defs/transitionSide"},next:{$ref:"#/$defs/transitionSide"},mask:{$ref:"#/$defs/mask"}},allOf:[{if:{properties:{type:{const:"update"}}},then:{required:["tween"],not:{anyOf:[{required:["prev"]},{required:["next"]},{required:["mask"]}]}}},{if:{properties:{type:{const:"transition"}}},then:{not:{required:["tween"]},anyOf:[{required:["prev"]},{required:["next"]},{required:["mask"]}]}}],additionalProperties:!1,$id:"https://route-engine.runtime/schemas/projectData/animationResource.yaml"};var Rb={type:"object",required:["value","duration"],properties:{value:{type:"number"},duration:{type:"number"},easing:{type:"string",enum:["linear","easeInQuad","easeOutQuad","easeInOutQuad","easeInCubic","easeOutCubic","easeInOutCubic","easeInQuart","easeOutQuart","easeInOutQuart","easeInQuint","easeOutQuint","easeInOutQuint","easeInSine","easeOutSine","easeInOutSine","easeInExpo","easeOutExpo","easeInOutExpo","easeInCirc","easeOutCirc","easeInOutCirc","easeInBack","easeOutBack","easeInOutBack","easeInBounce","easeOutBounce","easeInOutBounce","easeInElastic","easeOutElastic","easeInOutElastic"]},relative:{type:"boolean"}},additionalProperties:!1};function Rr(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.value===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"value"},message:"must have required property 'value'"};r===null?r=[o]:r.push(o),s++}if(e.duration===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"duration"},message:"must have required property 'duration'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="value"||o==="duration"||o==="easing"||o==="relative")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.value!==void 0&&typeof e.value!="number"){let o={instancePath:t+"/value",schemaPath:"#/properties/value/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.duration!==void 0&&typeof e.duration!="number"){let o={instancePath:t+"/duration",schemaPath:"#/properties/duration/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.easing!==void 0){let o=e.easing;if(typeof o!="string"){let l={instancePath:t+"/easing",schemaPath:"#/properties/easing/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(!(o==="linear"||o==="easeInQuad"||o==="easeOutQuad"||o==="easeInOutQuad"||o==="easeInCubic"||o==="easeOutCubic"||o==="easeInOutCubic"||o==="easeInQuart"||o==="easeOutQuart"||o==="easeInOutQuart"||o==="easeInQuint"||o==="easeOutQuint"||o==="easeInOutQuint"||o==="easeInSine"||o==="easeOutSine"||o==="easeInOutSine"||o==="easeInExpo"||o==="easeOutExpo"||o==="easeInOutExpo"||o==="easeInCirc"||o==="easeOutCirc"||o==="easeInOutCirc"||o==="easeInBack"||o==="easeOutBack"||o==="easeInOutBack"||o==="easeInBounce"||o==="easeOutBounce"||o==="easeInOutBounce"||o==="easeInElastic"||o==="easeOutElastic"||o==="easeInOutElastic")){let l={instancePath:t+"/easing",schemaPath:"#/properties/easing/enum",keyword:"enum",params:{allowedValues:Rb.properties.easing.enum},message:"must be equal to one of the allowed values"};r===null?r=[l]:r.push(l),s++}}if(e.relative!==void 0&&typeof e.relative!="boolean"){let o={instancePath:t+"/relative",schemaPath:"#/properties/relative/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Rr.errors=r,s===0}function G(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.keyframes===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"keyframes"},message:"must have required property 'keyframes'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="initialValue"||o==="keyframes")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.initialValue!==void 0&&typeof e.initialValue!="number"){let o={instancePath:t+"/initialValue",schemaPath:"#/properties/initialValue/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.keyframes!==void 0){let o=e.keyframes;if(Array.isArray(o)){if(o.length<1){let c={instancePath:t+"/keyframes",schemaPath:"#/properties/keyframes/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};r===null?r=[c]:r.push(c),s++}let l=o.length;for(let c=0;c<l;c++)Rr(o[c],{instancePath:t+"/keyframes/"+c,parentData:o,parentDataProperty:c,rootData:a})||(r=r===null?Rr.errors:r.concat(Rr.errors),s=r.length)}else{let l={instancePath:t+"/keyframes",schemaPath:"#/properties/keyframes/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return G.errors=r,s===0}function Fn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(Object.keys(e).length<1){let o={instancePath:t,schemaPath:"#/minProperties",keyword:"minProperties",params:{limit:1},message:"must NOT have fewer than 1 properties"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="alpha"||o==="x"||o==="y"||o==="scaleX"||o==="scaleY"||o==="rotation")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}e.alpha!==void 0&&(G(e.alpha,{instancePath:t+"/alpha",parentData:e,parentDataProperty:"alpha",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.x!==void 0&&(G(e.x,{instancePath:t+"/x",parentData:e,parentDataProperty:"x",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.y!==void 0&&(G(e.y,{instancePath:t+"/y",parentData:e,parentDataProperty:"y",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.scaleX!==void 0&&(G(e.scaleX,{instancePath:t+"/scaleX",parentData:e,parentDataProperty:"scaleX",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.scaleY!==void 0&&(G(e.scaleY,{instancePath:t+"/scaleY",parentData:e,parentDataProperty:"scaleY",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.rotation!==void 0&&(G(e.rotation,{instancePath:t+"/rotation",parentData:e,parentDataProperty:"rotation",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Fn.errors=r,s===0}function Un(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(Object.keys(e).length<1){let o={instancePath:t,schemaPath:"#/minProperties",keyword:"minProperties",params:{limit:1},message:"must NOT have fewer than 1 properties"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="translateX"||o==="translateY"||o==="alpha"||o==="scaleX"||o==="scaleY"||o==="rotation")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}e.translateX!==void 0&&(G(e.translateX,{instancePath:t+"/translateX",parentData:e,parentDataProperty:"translateX",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.translateY!==void 0&&(G(e.translateY,{instancePath:t+"/translateY",parentData:e,parentDataProperty:"translateY",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.alpha!==void 0&&(G(e.alpha,{instancePath:t+"/alpha",parentData:e,parentDataProperty:"alpha",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.scaleX!==void 0&&(G(e.scaleX,{instancePath:t+"/scaleX",parentData:e,parentDataProperty:"scaleX",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.scaleY!==void 0&&(G(e.scaleY,{instancePath:t+"/scaleY",parentData:e,parentDataProperty:"scaleY",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length)),e.rotation!==void 0&&(G(e.rotation,{instancePath:t+"/rotation",parentData:e,parentDataProperty:"rotation",rootData:a})||(r=r===null?G.errors:r.concat(G.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Un.errors=r,s===0}function Or(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.tween===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"tween"},message:"must have required property 'tween'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(o!=="tween"){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}e.tween!==void 0&&(Un(e.tween,{instancePath:t+"/tween",parentData:e,parentDataProperty:"tween",rootData:a})||(r=r===null?Un.errors:r.concat(Un.errors),s=r.length))}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Or.errors=r,s===0}var kn={type:"object",required:["kind"],properties:{kind:{type:"string",enum:["single","sequence","composite"]},texture:{type:"string"},textures:{type:"array",minItems:1,items:{type:"string"}},items:{type:"array",minItems:1,items:{$ref:"#/$defs/compositeMaskItem"}},combine:{type:"string",enum:["max","min","multiply","add"]},channel:{type:"string",enum:["red","green","blue","alpha"]},softness:{type:"number"},invert:{type:"boolean"},sample:{type:"string"},progress:{$ref:"#/$defs/maskProgress"}},additionalProperties:!1,allOf:[{if:{properties:{kind:{const:"single"}}},then:{required:["texture"]}},{if:{properties:{kind:{const:"sequence"}}},then:{required:["textures"]}},{if:{properties:{kind:{const:"composite"}}},then:{required:["items"]}}]},Cb={type:"object",required:["texture"],properties:{texture:{type:"string"},channel:{type:"string",enum:["red","green","blue","alpha"]},invert:{type:"boolean"}},additionalProperties:!1};function Bn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.texture===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"texture"},message:"must have required property 'texture'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="texture"||o==="channel"||o==="invert")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.texture!==void 0&&typeof e.texture!="string"){let o={instancePath:t+"/texture",schemaPath:"#/properties/texture/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.channel!==void 0){let o=e.channel;if(typeof o!="string"){let l={instancePath:t+"/channel",schemaPath:"#/properties/channel/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(!(o==="red"||o==="green"||o==="blue"||o==="alpha")){let l={instancePath:t+"/channel",schemaPath:"#/properties/channel/enum",keyword:"enum",params:{allowedValues:Cb.properties.channel.enum},message:"must be equal to one of the allowed values"};r===null?r=[l]:r.push(l),s++}}if(e.invert!==void 0&&typeof e.invert!="boolean"){let o={instancePath:t+"/invert",schemaPath:"#/properties/invert/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Bn.errors=r,s===0}function Yn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.keyframes===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"keyframes"},message:"must have required property 'keyframes'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="initialValue"||o==="keyframes")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.initialValue!==void 0&&typeof e.initialValue!="number"){let o={instancePath:t+"/initialValue",schemaPath:"#/properties/initialValue/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.keyframes!==void 0){let o=e.keyframes;if(Array.isArray(o)){if(o.length<1){let c={instancePath:t+"/keyframes",schemaPath:"#/properties/keyframes/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};r===null?r=[c]:r.push(c),s++}let l=o.length;for(let c=0;c<l;c++)Rr(o[c],{instancePath:t+"/keyframes/"+c,parentData:o,parentDataProperty:c,rootData:a})||(r=r===null?Rr.errors:r.concat(Rr.errors),s=r.length)}else{let l={instancePath:t+"/keyframes",schemaPath:"#/properties/keyframes/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Yn.errors=r,s===0}function zn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=!0,c=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.kind!==void 0&&e.kind!=="single"){let b={};r===null?r=[b]:r.push(b),s++}var u=c===s;if(s=o,r!==null&&(o?r.length=o:r=null),u){let b=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.texture===void 0){let v={instancePath:t,schemaPath:"#/allOf/0/then/required",keyword:"required",params:{missingProperty:"texture"},message:"must have required property 'texture'"};r===null?r=[v]:r.push(v),s++}var u=b===s;l=u}if(!l){let b={instancePath:t,schemaPath:"#/allOf/0/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[b]:r.push(b),s++}let p=s,m=!0,d=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.kind!==void 0&&e.kind!=="sequence"){let b={};r===null?r=[b]:r.push(b),s++}var f=d===s;if(s=p,r!==null&&(p?r.length=p:r=null),f){let b=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.textures===void 0){let v={instancePath:t,schemaPath:"#/allOf/1/then/required",keyword:"required",params:{missingProperty:"textures"},message:"must have required property 'textures'"};r===null?r=[v]:r.push(v),s++}var f=b===s;m=f}if(!m){let b={instancePath:t,schemaPath:"#/allOf/1/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[b]:r.push(b),s++}let y=s,g=!0,h=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.kind!==void 0&&e.kind!=="composite"){let b={};r===null?r=[b]:r.push(b),s++}var w=h===s;if(s=y,r!==null&&(y?r.length=y:r=null),w){let b=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.items===void 0){let v={instancePath:t,schemaPath:"#/allOf/2/then/required",keyword:"required",params:{missingProperty:"items"},message:"must have required property 'items'"};r===null?r=[v]:r.push(v),s++}var w=b===s;g=w}if(!g){let b={instancePath:t,schemaPath:"#/allOf/2/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[b]:r.push(b),s++}if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.kind===void 0){let b={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"kind"},message:"must have required property 'kind'"};r===null?r=[b]:r.push(b),s++}for(let b in e)if(!Ze.call(kn.properties,b)){let E={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:b},message:"must NOT have additional properties"};r===null?r=[E]:r.push(E),s++}if(e.kind!==void 0){let b=e.kind;if(typeof b!="string"){let E={instancePath:t+"/kind",schemaPath:"#/properties/kind/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[E]:r.push(E),s++}if(!(b==="single"||b==="sequence"||b==="composite")){let E={instancePath:t+"/kind",schemaPath:"#/properties/kind/enum",keyword:"enum",params:{allowedValues:kn.properties.kind.enum},message:"must be equal to one of the allowed values"};r===null?r=[E]:r.push(E),s++}}if(e.texture!==void 0&&typeof e.texture!="string"){let b={instancePath:t+"/texture",schemaPath:"#/properties/texture/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[b]:r.push(b),s++}if(e.textures!==void 0){let b=e.textures;if(Array.isArray(b)){if(b.length<1){let v={instancePath:t+"/textures",schemaPath:"#/properties/textures/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};r===null?r=[v]:r.push(v),s++}let E=b.length;for(let v=0;v<E;v++)if(typeof b[v]!="string"){let k={instancePath:t+"/textures/"+v,schemaPath:"#/properties/textures/items/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[k]:r.push(k),s++}}else{let E={instancePath:t+"/textures",schemaPath:"#/properties/textures/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[E]:r.push(E),s++}}if(e.items!==void 0){let b=e.items;if(Array.isArray(b)){if(b.length<1){let v={instancePath:t+"/items",schemaPath:"#/properties/items/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};r===null?r=[v]:r.push(v),s++}let E=b.length;for(let v=0;v<E;v++)Bn(b[v],{instancePath:t+"/items/"+v,parentData:b,parentDataProperty:v,rootData:a})||(r=r===null?Bn.errors:r.concat(Bn.errors),s=r.length)}else{let E={instancePath:t+"/items",schemaPath:"#/properties/items/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[E]:r.push(E),s++}}if(e.combine!==void 0){let b=e.combine;if(typeof b!="string"){let E={instancePath:t+"/combine",schemaPath:"#/properties/combine/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[E]:r.push(E),s++}if(!(b==="max"||b==="min"||b==="multiply"||b==="add")){let E={instancePath:t+"/combine",schemaPath:"#/properties/combine/enum",keyword:"enum",params:{allowedValues:kn.properties.combine.enum},message:"must be equal to one of the allowed values"};r===null?r=[E]:r.push(E),s++}}if(e.channel!==void 0){let b=e.channel;if(typeof b!="string"){let E={instancePath:t+"/channel",schemaPath:"#/properties/channel/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[E]:r.push(E),s++}if(!(b==="red"||b==="green"||b==="blue"||b==="alpha")){let E={instancePath:t+"/channel",schemaPath:"#/properties/channel/enum",keyword:"enum",params:{allowedValues:kn.properties.channel.enum},message:"must be equal to one of the allowed values"};r===null?r=[E]:r.push(E),s++}}if(e.softness!==void 0&&typeof e.softness!="number"){let b={instancePath:t+"/softness",schemaPath:"#/properties/softness/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[b]:r.push(b),s++}if(e.invert!==void 0&&typeof e.invert!="boolean"){let b={instancePath:t+"/invert",schemaPath:"#/properties/invert/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[b]:r.push(b),s++}if(e.sample!==void 0&&typeof e.sample!="string"){let b={instancePath:t+"/sample",schemaPath:"#/properties/sample/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[b]:r.push(b),s++}e.progress!==void 0&&(Yn(e.progress,{instancePath:t+"/progress",parentData:e,parentDataProperty:"progress",rootData:a})||(r=r===null?Yn.errors:r.concat(Yn.errors),s=r.length))}else{let b={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[b]:r.push(b),s++}return zn.errors=r,s===0}function Gn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=!0,c=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.type!==void 0&&e.type!=="update"){let b={};r===null?r=[b]:r.push(b),s++}var u=c===s;if(s=o,r!==null&&(o?r.length=o:r=null),u){let b=s,E=s,v=s,k=s,x=!1,C=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let P;if(e.prev===void 0&&(P="prev")){let T={};r===null?r=[T]:r.push(T),s++}}var p=C===s;if(x=x||p,!x){let P=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let q;if(e.next===void 0&&(q="next")){let ae={};r===null?r=[ae]:r.push(ae),s++}}var p=P===s;if(x=x||p,!x){let q=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let B;if(e.mask===void 0&&(B="mask")){let ne={};r===null?r=[ne]:r.push(ne),s++}}var p=q===s;x=x||p}}if(x)s=k,r!==null&&(k?r.length=k:r=null);else{let P={};r===null?r=[P]:r.push(P),s++}var m=v===s;if(m){let P={instancePath:t,schemaPath:"#/allOf/0/then/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[P]:r.push(P),s++}else s=E,r!==null&&(E?r.length=E:r=null);if(e&&typeof e=="object"&&!Array.isArray(e)&&e.tween===void 0){let P={instancePath:t,schemaPath:"#/allOf/0/then/required",keyword:"required",params:{missingProperty:"tween"},message:"must have required property 'tween'"};r===null?r=[P]:r.push(P),s++}var u=b===s;l=u}if(!l){let b={instancePath:t,schemaPath:"#/allOf/0/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[b]:r.push(b),s++}let d=s,f=!0,y=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.type!==void 0&&e.type!=="transition"){let b={};r===null?r=[b]:r.push(b),s++}var g=y===s;if(s=d,r!==null&&(d?r.length=d:r=null),g){let b=s,E=s,v=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let P;if(e.tween===void 0&&(P="tween")){let T={};r===null?r=[T]:r.push(T),s++}}var h=v===s;if(h){let P={instancePath:t,schemaPath:"#/allOf/1/then/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[P]:r.push(P),s++}else s=E,r!==null&&(E?r.length=E:r=null);let k=s,x=!1,C=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.prev===void 0){let P={instancePath:t,schemaPath:"#/allOf/1/then/anyOf/0/required",keyword:"required",params:{missingProperty:"prev"},message:"must have required property 'prev'"};r===null?r=[P]:r.push(P),s++}var w=C===s;if(x=x||w,!x){let P=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.next===void 0){let q={instancePath:t,schemaPath:"#/allOf/1/then/anyOf/1/required",keyword:"required",params:{missingProperty:"next"},message:"must have required property 'next'"};r===null?r=[q]:r.push(q),s++}var w=P===s;if(x=x||w,!x){let q=s;if(e&&typeof e=="object"&&!Array.isArray(e)&&e.mask===void 0){let B={instancePath:t,schemaPath:"#/allOf/1/then/anyOf/2/required",keyword:"required",params:{missingProperty:"mask"},message:"must have required property 'mask'"};r===null?r=[B]:r.push(B),s++}var w=q===s;x=x||w}}if(x)s=k,r!==null&&(k?r.length=k:r=null);else{let P={instancePath:t,schemaPath:"#/allOf/1/then/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};r===null?r=[P]:r.push(P),s++}var g=b===s;f=g}if(!f){let b={instancePath:t,schemaPath:"#/allOf/1/if",keyword:"if",params:{failingKeyword:"then"},message:'must match "then" schema'};r===null?r=[b]:r.push(b),s++}if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.type===void 0){let b={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"type"},message:"must have required property 'type'"};r===null?r=[b]:r.push(b),s++}for(let b in e)if(!(b==="name"||b==="type"||b==="complete"||b==="tween"||b==="prev"||b==="next"||b==="mask")){let E={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:b},message:"must NOT have additional properties"};r===null?r=[E]:r.push(E),s++}if(e.name!==void 0&&typeof e.name!="string"){let b={instancePath:t+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[b]:r.push(b),s++}if(e.type!==void 0){let b=e.type;if(typeof b!="string"){let E={instancePath:t+"/type",schemaPath:"#/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[E]:r.push(E),s++}if(!(b==="update"||b==="transition")){let E={instancePath:t+"/type",schemaPath:"#/properties/type/enum",keyword:"enum",params:{allowedValues:Ob.properties.type.enum},message:"must be equal to one of the allowed values"};r===null?r=[E]:r.push(E),s++}}if(e.complete!==void 0){let b=e.complete;if(b&&typeof b=="object"&&!Array.isArray(b)){if(b.payload!==void 0){let E=b.payload;if(!(E&&typeof E=="object"&&!Array.isArray(E))){let v={instancePath:t+"/complete/payload",schemaPath:"#/properties/complete/properties/payload/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[v]:r.push(v),s++}}}else{let E={instancePath:t+"/complete",schemaPath:"#/properties/complete/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[E]:r.push(E),s++}}e.tween!==void 0&&(Fn(e.tween,{instancePath:t+"/tween",parentData:e,parentDataProperty:"tween",rootData:a})||(r=r===null?Fn.errors:r.concat(Fn.errors),s=r.length)),e.prev!==void 0&&(Or(e.prev,{instancePath:t+"/prev",parentData:e,parentDataProperty:"prev",rootData:a})||(r=r===null?Or.errors:r.concat(Or.errors),s=r.length)),e.next!==void 0&&(Or(e.next,{instancePath:t+"/next",parentData:e,parentDataProperty:"next",rootData:a})||(r=r===null?Or.errors:r.concat(Or.errors),s=r.length)),e.mask!==void 0&&(zn(e.mask,{instancePath:t+"/mask",parentData:e,parentDataProperty:"mask",rootData:a})||(r=r===null?zn.errors:r.concat(zn.errors),s=r.length))}else{let b={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[b]:r.push(b),s++}return Gn.errors=r,s===0}function fu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Gn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Gn.errors:r.concat(Gn.errors),s=r.length),fu.errors=r,s===0}var du=mu;function Xn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!(o==="name"||o==="nameVariableId")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.name!==void 0&&typeof e.name!="string"){let o={instancePath:t+"/name",schemaPath:"#/properties/name/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.nameVariableId!==void 0){let o=e.nameVariableId;if(typeof o=="string"){if(Re(o)<1){let l={instancePath:t+"/nameVariableId",schemaPath:"#/properties/nameVariableId/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/nameVariableId",schemaPath:"#/properties/nameVariableId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Xn.errors=r,s===0}function mu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Xn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Xn.errors:r.concat(Xn.errors),s=r.length),mu.errors=r,s===0}var yu=hu;var _b=new RegExp("^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$","u");function Wn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.hex===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"hex"},message:"must have required property 'hex'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(o!=="hex"){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.hex!==void 0){let o=e.hex;if(typeof o=="string"){if(!_b.test(o)){let l={instancePath:t+"/hex",schemaPath:"#/properties/hex/pattern",keyword:"pattern",params:{pattern:"^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"},message:'must match pattern "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"'};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/hex",schemaPath:"#/properties/hex/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Wn.errors=r,s===0}function hu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Wn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Wn.errors:r.concat(Wn.errors),s=r.length),hu.errors=r,s===0}var gu=bu;function Hn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.keyboard!==void 0){let o=e.keyboard;if(o&&typeof o=="object"&&!Array.isArray(o))for(let l in o){let c=o[l];if(c&&typeof c=="object"&&!Array.isArray(c)){if(c.actions!==void 0){let u=c.actions;if(!(u&&typeof u=="object"&&!Array.isArray(u))){let p={instancePath:t+"/keyboard/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/actions",schemaPath:"#/properties/keyboard/additionalProperties/properties/actions/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}if(c.payload!==void 0){let u=c.payload;if(!(u&&typeof u=="object"&&!Array.isArray(u))){let p={instancePath:t+"/keyboard/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/payload",schemaPath:"#/properties/keyboard/additionalProperties/properties/payload/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}if(c.keydown!==void 0){let u=c.keydown;if(u&&typeof u=="object"&&!Array.isArray(u)){if(u.payload!==void 0){let p=u.payload;if(!(p&&typeof p=="object"&&!Array.isArray(p))){let m={instancePath:t+"/keyboard/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/keydown/payload",schemaPath:"#/properties/keyboard/additionalProperties/properties/keydown/properties/payload/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[m]:r.push(m),s++}}}else{let p={instancePath:t+"/keyboard/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/keydown",schemaPath:"#/properties/keyboard/additionalProperties/properties/keydown/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}if(c.keyup!==void 0){let u=c.keyup;if(u&&typeof u=="object"&&!Array.isArray(u)){if(u.payload!==void 0){let p=u.payload;if(!(p&&typeof p=="object"&&!Array.isArray(p))){let m={instancePath:t+"/keyboard/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/keyup/payload",schemaPath:"#/properties/keyboard/additionalProperties/properties/keyup/properties/payload/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[m]:r.push(m),s++}}}else{let p={instancePath:t+"/keyboard/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/keyup",schemaPath:"#/properties/keyboard/additionalProperties/properties/keyup/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}}else{let u={instancePath:t+"/keyboard/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/keyboard/additionalProperties/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[u]:r.push(u),s++}}else{let l={instancePath:t+"/keyboard",schemaPath:"#/properties/keyboard/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}if(e.keyup!==void 0){let o=e.keyup;if(o&&typeof o=="object"&&!Array.isArray(o))for(let l in o){let c=o[l];if(c&&typeof c=="object"&&!Array.isArray(c)){if(c.actions!==void 0){let u=c.actions;if(!(u&&typeof u=="object"&&!Array.isArray(u))){let p={instancePath:t+"/keyup/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/actions",schemaPath:"#/properties/keyup/additionalProperties/properties/actions/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}if(c.payload!==void 0){let u=c.payload;if(!(u&&typeof u=="object"&&!Array.isArray(u))){let p={instancePath:t+"/keyup/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/payload",schemaPath:"#/properties/keyup/additionalProperties/properties/payload/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}}else{let u={instancePath:t+"/keyup/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/keyup/additionalProperties/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[u]:r.push(u),s++}}else{let l={instancePath:t+"/keyup",schemaPath:"#/properties/keyup/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}if(e.elements!==void 0){let o=e.elements;if(Array.isArray(o)){let l=o.length;for(let c=0;c<l;c++){let u=o[c];if(!(u&&typeof u=="object"&&!Array.isArray(u))){let p={instancePath:t+"/elements/"+c,schemaPath:"#/properties/elements/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}}else{let l={instancePath:t+"/elements",schemaPath:"#/properties/elements/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Hn.errors=r,s===0}function bu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Hn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Hn.errors:r.concat(Hn.errors),s=r.length),bu.errors=r,s===0}var wu=Iu;function Kn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fileId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fileId"},message:"must have required property 'fileId'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="fileId"||o==="fileType")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.fileId!==void 0&&typeof e.fileId!="string"){let o={instancePath:t+"/fileId",schemaPath:"#/properties/fileId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.fileType!==void 0&&typeof e.fileType!="string"){let o={instancePath:t+"/fileType",schemaPath:"#/properties/fileType/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Kn.errors=r,s===0}function Iu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Kn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Kn.errors:r.concat(Kn.errors),s=r.length),Iu.errors=r,s===0}var vu=Au;function Jn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fileId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fileId"},message:"must have required property 'fileId'"};r===null?r=[o]:r.push(o),s++}if(e.width===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"width"},message:"must have required property 'width'"};r===null?r=[o]:r.push(o),s++}if(e.height===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"height"},message:"must have required property 'height'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="fileId"||o==="fileType"||o==="width"||o==="height")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.fileId!==void 0&&typeof e.fileId!="string"){let o={instancePath:t+"/fileId",schemaPath:"#/properties/fileId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.fileType!==void 0&&typeof e.fileType!="string"){let o={instancePath:t+"/fileType",schemaPath:"#/properties/fileType/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.width!==void 0){let o=e.width;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/width",schemaPath:"#/properties/width/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}if(e.height!==void 0){let o=e.height;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/height",schemaPath:"#/properties/height/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Jn.errors=r,s===0}function Au(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Jn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Jn.errors:r.concat(Jn.errors),s=r.length),Au.errors=r,s===0}var ku=Pu;function Qn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.elements!==void 0){let o=e.elements;if(Array.isArray(o)){let l=o.length;for(let c=0;c<l;c++){let u=o[c];if(!(u&&typeof u=="object"&&!Array.isArray(u))){let p={instancePath:t+"/elements/"+c,schemaPath:"#/properties/elements/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[p]:r.push(p),s++}}}else{let l={instancePath:t+"/elements",schemaPath:"#/properties/elements/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return Qn.errors=r,s===0}function Pu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Qn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Qn.errors:r.concat(Qn.errors),s=r.length),Pu.errors=r,s===0}var xu=Eu;function Zn(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0,o=s,l=!1,c=null,u=s,p=s,m=s,d=s,f=!1,y=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let v;if(e.count===void 0&&(v="count")){let k={};r===null?r=[k]:r.push(k),s++}}var g=y===s;if(f=f||g,!f){let v=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let x;if(e.texture===void 0&&(x="texture")){let C={};r===null?r=[C]:r.push(C),s++}}var g=v===s;if(f=f||g,!f){let x=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let N;if(e.behaviors===void 0&&(N="behaviors")){let P={};r===null?r=[P]:r.push(P),s++}}var g=x===s;if(f=f||g,!f){let N=s;if(e&&typeof e=="object"&&!Array.isArray(e)){let T;if(e.emitter===void 0&&(T="emitter")){let q={};r===null?r=[q]:r.push(q),s++}}var g=N===s;f=f||g}}}if(f)s=d,r!==null&&(d?r.length=d:r=null);else{let v={};r===null?r=[v]:r.push(v),s++}var h=m===s;if(h){let v={instancePath:t,schemaPath:"#/oneOf/0/not",keyword:"not",params:{},message:"must NOT be valid"};r===null?r=[v]:r.push(v),s++}else s=p,r!==null&&(p?r.length=p:r=null);if(e&&typeof e=="object"&&!Array.isArray(e)&&e.modules===void 0){let v={instancePath:t,schemaPath:"#/oneOf/0/required",keyword:"required",params:{missingProperty:"modules"},message:"must have required property 'modules'"};r===null?r=[v]:r.push(v),s++}var b=u===s;b&&(l=!0,c=0);let w=s;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.texture===void 0){let v={instancePath:t,schemaPath:"#/oneOf/1/required",keyword:"required",params:{missingProperty:"texture"},message:"must have required property 'texture'"};r===null?r=[v]:r.push(v),s++}if(e.behaviors===void 0){let v={instancePath:t,schemaPath:"#/oneOf/1/required",keyword:"required",params:{missingProperty:"behaviors"},message:"must have required property 'behaviors'"};r===null?r=[v]:r.push(v),s++}if(e.emitter===void 0){let v={instancePath:t,schemaPath:"#/oneOf/1/required",keyword:"required",params:{missingProperty:"emitter"},message:"must have required property 'emitter'"};r===null?r=[v]:r.push(v),s++}}var b=w===s;if(b&&l?(l=!1,c=[c,1]):b&&(l=!0,c=1),l)s=o,r!==null&&(o?r.length=o:r=null);else{let v={instancePath:t,schemaPath:"#/oneOf",keyword:"oneOf",params:{passingSchemas:c},message:"must match exactly one schema in oneOf"};r===null?r=[v]:r.push(v),s++}if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.width===void 0){let v={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"width"},message:"must have required property 'width'"};r===null?r=[v]:r.push(v),s++}if(e.height===void 0){let v={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"height"},message:"must have required property 'height'"};r===null?r=[v]:r.push(v),s++}for(let v in e)if(!(v==="width"||v==="height"||v==="seed"||v==="modules"||v==="count"||v==="texture"||v==="behaviors"||v==="emitter")){let k={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:v},message:"must NOT have additional properties"};r===null?r=[k]:r.push(k),s++}if(e.width!==void 0){let v=e.width;if(typeof v=="number"){if(v<=0||isNaN(v)){let k={instancePath:t+"/width",schemaPath:"#/properties/width/exclusiveMinimum",keyword:"exclusiveMinimum",params:{comparison:">",limit:0},message:"must be > 0"};r===null?r=[k]:r.push(k),s++}}else{let k={instancePath:t+"/width",schemaPath:"#/properties/width/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[k]:r.push(k),s++}}if(e.height!==void 0){let v=e.height;if(typeof v=="number"){if(v<=0||isNaN(v)){let k={instancePath:t+"/height",schemaPath:"#/properties/height/exclusiveMinimum",keyword:"exclusiveMinimum",params:{comparison:">",limit:0},message:"must be > 0"};r===null?r=[k]:r.push(k),s++}}else{let k={instancePath:t+"/height",schemaPath:"#/properties/height/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[k]:r.push(k),s++}}if(e.seed!==void 0&&typeof e.seed!="number"){let v={instancePath:t+"/seed",schemaPath:"#/properties/seed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[v]:r.push(v),s++}if(e.modules!==void 0){let v=e.modules;if(v&&typeof v=="object"&&!Array.isArray(v)){if(v.emission===void 0){let k={instancePath:t+"/modules",schemaPath:"#/properties/modules/required",keyword:"required",params:{missingProperty:"emission"},message:"must have required property 'emission'"};r===null?r=[k]:r.push(k),s++}if(v.appearance===void 0){let k={instancePath:t+"/modules",schemaPath:"#/properties/modules/required",keyword:"required",params:{missingProperty:"appearance"},message:"must have required property 'appearance'"};r===null?r=[k]:r.push(k),s++}for(let k in v)if(!(k==="emission"||k==="movement"||k==="appearance"||k==="bounds")){let x={instancePath:t+"/modules",schemaPath:"#/properties/modules/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:k},message:"must NOT have additional properties"};r===null?r=[x]:r.push(x),s++}if(v.emission!==void 0){let k=v.emission;if(!(k&&typeof k=="object"&&!Array.isArray(k))){let x={instancePath:t+"/modules/emission",schemaPath:"#/properties/modules/properties/emission/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[x]:r.push(x),s++}}if(v.movement!==void 0){let k=v.movement;if(!(k&&typeof k=="object"&&!Array.isArray(k))){let x={instancePath:t+"/modules/movement",schemaPath:"#/properties/modules/properties/movement/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[x]:r.push(x),s++}}if(v.appearance!==void 0){let k=v.appearance;if(!(k&&typeof k=="object"&&!Array.isArray(k))){let x={instancePath:t+"/modules/appearance",schemaPath:"#/properties/modules/properties/appearance/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[x]:r.push(x),s++}}if(v.bounds!==void 0){let k=v.bounds;if(!(k&&typeof k=="object"&&!Array.isArray(k))){let x={instancePath:t+"/modules/bounds",schemaPath:"#/properties/modules/properties/bounds/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[x]:r.push(x),s++}}}else{let k={instancePath:t+"/modules",schemaPath:"#/properties/modules/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[k]:r.push(k),s++}}if(e.count!==void 0){let v=e.count;if(!(typeof v=="number"&&!(v%1)&&!isNaN(v))){let k={instancePath:t+"/count",schemaPath:"#/properties/count/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[k]:r.push(k),s++}if(typeof v=="number"&&(v<1||isNaN(v))){let k={instancePath:t+"/count",schemaPath:"#/properties/count/minimum",keyword:"minimum",params:{comparison:">=",limit:1},message:"must be >= 1"};r===null?r=[k]:r.push(k),s++}}if(e.texture!==void 0){let v=e.texture,k=s,x=!1,C=null,N=s;if(typeof v=="string"){if(Re(v)<1){let T={instancePath:t+"/texture",schemaPath:"#/properties/texture/oneOf/0/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[T]:r.push(T),s++}}else{let T={instancePath:t+"/texture",schemaPath:"#/properties/texture/oneOf/0/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[T]:r.push(T),s++}var E=N===s;E&&(x=!0,C=0);let P=s;if(!(v&&typeof v=="object"&&!Array.isArray(v))){let T={instancePath:t+"/texture",schemaPath:"#/properties/texture/oneOf/1/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[T]:r.push(T),s++}var E=P===s;if(E&&x?(x=!1,C=[C,1]):E&&(x=!0,C=1),x)s=k,r!==null&&(k?r.length=k:r=null);else{let T={instancePath:t+"/texture",schemaPath:"#/properties/texture/oneOf",keyword:"oneOf",params:{passingSchemas:C},message:"must match exactly one schema in oneOf"};r===null?r=[T]:r.push(T),s++}}if(e.behaviors!==void 0){let v=e.behaviors;if(Array.isArray(v)){if(v.length<1){let x={instancePath:t+"/behaviors",schemaPath:"#/properties/behaviors/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};r===null?r=[x]:r.push(x),s++}let k=v.length;for(let x=0;x<k;x++){let C=v[x];if(C&&typeof C=="object"&&!Array.isArray(C)){if(C.type===void 0){let N={instancePath:t+"/behaviors/"+x,schemaPath:"#/properties/behaviors/items/required",keyword:"required",params:{missingProperty:"type"},message:"must have required property 'type'"};r===null?r=[N]:r.push(N),s++}for(let N in C)if(!(N==="type"||N==="config")){let P={instancePath:t+"/behaviors/"+x,schemaPath:"#/properties/behaviors/items/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:N},message:"must NOT have additional properties"};r===null?r=[P]:r.push(P),s++}if(C.type!==void 0){let N=C.type;if(typeof N=="string"){if(Re(N)<1){let P={instancePath:t+"/behaviors/"+x+"/type",schemaPath:"#/properties/behaviors/items/properties/type/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[P]:r.push(P),s++}}else{let P={instancePath:t+"/behaviors/"+x+"/type",schemaPath:"#/properties/behaviors/items/properties/type/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[P]:r.push(P),s++}}if(C.config!==void 0){let N=C.config;if(!(N&&typeof N=="object"&&!Array.isArray(N))){let P={instancePath:t+"/behaviors/"+x+"/config",schemaPath:"#/properties/behaviors/items/properties/config/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[P]:r.push(P),s++}}}else{let N={instancePath:t+"/behaviors/"+x,schemaPath:"#/properties/behaviors/items/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[N]:r.push(N),s++}}}else{let k={instancePath:t+"/behaviors",schemaPath:"#/properties/behaviors/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[k]:r.push(k),s++}}if(e.emitter!==void 0){let v=e.emitter;if(v&&typeof v=="object"&&!Array.isArray(v)){if(v.lifetime===void 0){let k={instancePath:t+"/emitter",schemaPath:"#/properties/emitter/required",keyword:"required",params:{missingProperty:"lifetime"},message:"must have required property 'lifetime'"};r===null?r=[k]:r.push(k),s++}if(v.lifetime!==void 0){let k=v.lifetime;if(k&&typeof k=="object"&&!Array.isArray(k)){if(k.min===void 0){let x={instancePath:t+"/emitter/lifetime",schemaPath:"#/properties/emitter/properties/lifetime/required",keyword:"required",params:{missingProperty:"min"},message:"must have required property 'min'"};r===null?r=[x]:r.push(x),s++}if(k.max===void 0){let x={instancePath:t+"/emitter/lifetime",schemaPath:"#/properties/emitter/properties/lifetime/required",keyword:"required",params:{missingProperty:"max"},message:"must have required property 'max'"};r===null?r=[x]:r.push(x),s++}if(k.min!==void 0){let x=k.min;if(typeof x=="number"){if(x<0||isNaN(x)){let C={instancePath:t+"/emitter/lifetime/min",schemaPath:"#/properties/emitter/properties/lifetime/properties/min/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[C]:r.push(C),s++}}else{let C={instancePath:t+"/emitter/lifetime/min",schemaPath:"#/properties/emitter/properties/lifetime/properties/min/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[C]:r.push(C),s++}}if(k.max!==void 0){let x=k.max;if(typeof x=="number"){if(x<0||isNaN(x)){let C={instancePath:t+"/emitter/lifetime/max",schemaPath:"#/properties/emitter/properties/lifetime/properties/max/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[C]:r.push(C),s++}}else{let C={instancePath:t+"/emitter/lifetime/max",schemaPath:"#/properties/emitter/properties/lifetime/properties/max/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[C]:r.push(C),s++}}}else{let x={instancePath:t+"/emitter/lifetime",schemaPath:"#/properties/emitter/properties/lifetime/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[x]:r.push(x),s++}}}else{let k={instancePath:t+"/emitter",schemaPath:"#/properties/emitter/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[k]:r.push(k),s++}}}else{let v={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[v]:r.push(v),s++}return Zn.errors=r,s===0}function Eu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return Zn(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?Zn.errors:r.concat(Zn.errors),s=r.length),Eu.errors=r,s===0}var Su=Ou;var Dc={type:"object",properties:{fileId:{type:"string"},fileType:{type:"string"},loop:{type:"boolean"},volume:{type:"number",minimum:0,maximum:100},muted:{type:"boolean"},pan:{type:"number",minimum:-1,maximum:1},startDelayMs:{type:"number",minimum:0},playbackRate:{type:"number",minimum:0},startAt:{type:"number",minimum:0},endAt:{type:["number","null"],minimum:0}},required:["fileId"],additionalProperties:!1};function es(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fileId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fileId"},message:"must have required property 'fileId'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!Ze.call(Dc.properties,o)){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.fileId!==void 0&&typeof e.fileId!="string"){let o={instancePath:t+"/fileId",schemaPath:"#/properties/fileId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.fileType!==void 0&&typeof e.fileType!="string"){let o={instancePath:t+"/fileType",schemaPath:"#/properties/fileType/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.loop!==void 0&&typeof e.loop!="boolean"){let o={instancePath:t+"/loop",schemaPath:"#/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.volume!==void 0){let o=e.volume;if(typeof o=="number"){if(o>100||isNaN(o)){let l={instancePath:t+"/volume",schemaPath:"#/properties/volume/maximum",keyword:"maximum",params:{comparison:"<=",limit:100},message:"must be <= 100"};r===null?r=[l]:r.push(l),s++}if(o<0||isNaN(o)){let l={instancePath:t+"/volume",schemaPath:"#/properties/volume/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/volume",schemaPath:"#/properties/volume/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.muted!==void 0&&typeof e.muted!="boolean"){let o={instancePath:t+"/muted",schemaPath:"#/properties/muted/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[o]:r.push(o),s++}if(e.pan!==void 0){let o=e.pan;if(typeof o=="number"){if(o>1||isNaN(o)){let l={instancePath:t+"/pan",schemaPath:"#/properties/pan/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[l]:r.push(l),s++}if(o<-1||isNaN(o)){let l={instancePath:t+"/pan",schemaPath:"#/properties/pan/minimum",keyword:"minimum",params:{comparison:">=",limit:-1},message:"must be >= -1"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/pan",schemaPath:"#/properties/pan/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.startDelayMs!==void 0){let o=e.startDelayMs;if(typeof o=="number"){if(o<0||isNaN(o)){let l={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/startDelayMs",schemaPath:"#/properties/startDelayMs/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.playbackRate!==void 0){let o=e.playbackRate;if(typeof o=="number"){if(o<0||isNaN(o)){let l={instancePath:t+"/playbackRate",schemaPath:"#/properties/playbackRate/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/playbackRate",schemaPath:"#/properties/playbackRate/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.startAt!==void 0){let o=e.startAt;if(typeof o=="number"){if(o<0||isNaN(o)){let l={instancePath:t+"/startAt",schemaPath:"#/properties/startAt/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}else{let l={instancePath:t+"/startAt",schemaPath:"#/properties/startAt/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}}if(e.endAt!==void 0){let o=e.endAt;if(typeof o!="number"&&o!==null){let l={instancePath:t+"/endAt",schemaPath:"#/properties/endAt/type",keyword:"type",params:{type:Dc.properties.endAt.type},message:"must be number,null"};r===null?r=[l]:r.push(l),s++}if(typeof o=="number"&&(o<0||isNaN(o))){let l={instancePath:t+"/endAt",schemaPath:"#/properties/endAt/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return es.errors=r,s===0}function Ou(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return es(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?es.errors:r.concat(es.errors),s=r.length),Ou.errors=r,s===0}var Ru=Cu;var $b=new RegExp("^.+$","u");function rs(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fileId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fileId"},message:"must have required property 'fileId'"};r===null?r=[o]:r.push(o),s++}if(e.jsonData===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"jsonData"},message:"must have required property 'jsonData'"};r===null?r=[o]:r.push(o),s++}if(e.width===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"width"},message:"must have required property 'width'"};r===null?r=[o]:r.push(o),s++}if(e.height===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"height"},message:"must have required property 'height'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="fileId"||o==="jsonData"||o==="width"||o==="height"||o==="animations")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.fileId!==void 0&&typeof e.fileId!="string"){let o={instancePath:t+"/fileId",schemaPath:"#/properties/fileId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.jsonData!==void 0){let o=e.jsonData;if(!(o&&typeof o=="object"&&!Array.isArray(o))){let l={instancePath:t+"/jsonData",schemaPath:"#/properties/jsonData/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}if(e.width!==void 0){let o=e.width;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/width",schemaPath:"#/properties/width/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}if(e.height!==void 0){let o=e.height;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/height",schemaPath:"#/properties/height/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}if(e.animations!==void 0){let o=e.animations;if(o&&typeof o=="object"&&!Array.isArray(o)){for(let l in o)if($b.test(l)){let c=o[l];if(c&&typeof c=="object"&&!Array.isArray(c)){if(c.frames===void 0){let u={instancePath:t+"/animations/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/animations/patternProperties/%5E.%2B%24/required",keyword:"required",params:{missingProperty:"frames"},message:"must have required property 'frames'"};r===null?r=[u]:r.push(u),s++}for(let u in c)if(!(u==="frames"||u==="animationSpeed"||u==="loop")){let p={instancePath:t+"/animations/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/animations/patternProperties/%5E.%2B%24/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:u},message:"must NOT have additional properties"};r===null?r=[p]:r.push(p),s++}if(c.frames!==void 0){let u=c.frames;if(Array.isArray(u)){let p=u.length;for(let m=0;m<p;m++)if(typeof u[m]!="number"){let d={instancePath:t+"/animations/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/frames/"+m,schemaPath:"#/properties/animations/patternProperties/%5E.%2B%24/properties/frames/items/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[d]:r.push(d),s++}}else{let p={instancePath:t+"/animations/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/frames",schemaPath:"#/properties/animations/patternProperties/%5E.%2B%24/properties/frames/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[p]:r.push(p),s++}}if(c.animationSpeed!==void 0&&typeof c.animationSpeed!="number"){let u={instancePath:t+"/animations/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/animationSpeed",schemaPath:"#/properties/animations/patternProperties/%5E.%2B%24/properties/animationSpeed/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[u]:r.push(u),s++}if(c.loop!==void 0&&typeof c.loop!="boolean"){let u={instancePath:t+"/animations/"+l.replace(/~/g,"~0").replace(/\//g,"~1")+"/loop",schemaPath:"#/properties/animations/patternProperties/%5E.%2B%24/properties/loop/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[u]:r.push(u),s++}}else{let u={instancePath:t+"/animations/"+l.replace(/~/g,"~0").replace(/\//g,"~1"),schemaPath:"#/properties/animations/patternProperties/%5E.%2B%24/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[u]:r.push(u),s++}}}else{let l={instancePath:t+"/animations",schemaPath:"#/properties/animations/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return rs.errors=r,s===0}function Cu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return rs(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?rs.errors:r.concat(rs.errors),s=r.length),Cu.errors=r,s===0}var _u=$u;var Tc={type:"object",properties:{fontId:{oneOf:[{type:"string",minLength:1},{type:"array",minItems:1,uniqueItems:!0,items:{type:"string",minLength:1}}]},colorId:{type:"string"},colorAlpha:{type:"number"},fontSize:{type:"number"},fontWeight:{type:"string"},fontStyle:{type:"string",enum:["normal","italic","oblique"]},lineHeight:{type:"number"},align:{type:"string"},wordWrap:{type:"boolean"},breakWords:{type:"boolean"},wordWrapWidth:{type:"number"},strokeColorId:{type:"string"},strokeAlpha:{type:"number"},strokeWidth:{type:"number"},shadow:{type:"object",properties:{colorId:{type:"string",minLength:1},alpha:{type:"number",minimum:0,maximum:1},blur:{type:"number",minimum:0},offsetX:{type:"number"},offsetY:{type:"number"}},required:["colorId"],additionalProperties:!1}},required:["fontId","fontSize","fontWeight","fontStyle","lineHeight","colorId"],additionalProperties:!1};function ts(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fontId===void 0){let l={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fontId"},message:"must have required property 'fontId'"};r===null?r=[l]:r.push(l),s++}if(e.fontSize===void 0){let l={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fontSize"},message:"must have required property 'fontSize'"};r===null?r=[l]:r.push(l),s++}if(e.fontWeight===void 0){let l={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fontWeight"},message:"must have required property 'fontWeight'"};r===null?r=[l]:r.push(l),s++}if(e.fontStyle===void 0){let l={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fontStyle"},message:"must have required property 'fontStyle'"};r===null?r=[l]:r.push(l),s++}if(e.lineHeight===void 0){let l={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"lineHeight"},message:"must have required property 'lineHeight'"};r===null?r=[l]:r.push(l),s++}if(e.colorId===void 0){let l={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"colorId"},message:"must have required property 'colorId'"};r===null?r=[l]:r.push(l),s++}for(let l in e)if(!Ze.call(Tc.properties,l)){let c={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:l},message:"must NOT have additional properties"};r===null?r=[c]:r.push(c),s++}if(e.fontId!==void 0){let l=e.fontId,c=s,u=!1,p=null,m=s;if(typeof l=="string"){if(Re(l)<1){let f={instancePath:t+"/fontId",schemaPath:"#/properties/fontId/oneOf/0/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[f]:r.push(f),s++}}else{let f={instancePath:t+"/fontId",schemaPath:"#/properties/fontId/oneOf/0/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[f]:r.push(f),s++}var o=m===s;o&&(u=!0,p=0);let d=s;if(Array.isArray(l)){if(l.length<1){let h={instancePath:t+"/fontId",schemaPath:"#/properties/fontId/oneOf/1/minItems",keyword:"minItems",params:{limit:1},message:"must NOT have fewer than 1 items"};r===null?r=[h]:r.push(h),s++}let f=l.length;for(let h=0;h<f;h++){let w=l[h];if(typeof w=="string"){if(Re(w)<1){let b={instancePath:t+"/fontId/"+h,schemaPath:"#/properties/fontId/oneOf/1/items/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[b]:r.push(b),s++}}else{let b={instancePath:t+"/fontId/"+h,schemaPath:"#/properties/fontId/oneOf/1/items/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[b]:r.push(b),s++}}let y=l.length,g;if(y>1){let h={};for(;y--;){let w=l[y];if(typeof w=="string"){if(typeof h[w]=="number"){g=h[w];let b={instancePath:t+"/fontId",schemaPath:"#/properties/fontId/oneOf/1/uniqueItems",keyword:"uniqueItems",params:{i:y,j:g},message:"must NOT have duplicate items (items ## "+g+" and "+y+" are identical)"};r===null?r=[b]:r.push(b),s++;break}h[w]=y}}}}else{let f={instancePath:t+"/fontId",schemaPath:"#/properties/fontId/oneOf/1/type",keyword:"type",params:{type:"array"},message:"must be array"};r===null?r=[f]:r.push(f),s++}var o=d===s;if(o&&u?(u=!1,p=[p,1]):o&&(u=!0,p=1),u)s=c,r!==null&&(c?r.length=c:r=null);else{let f={instancePath:t+"/fontId",schemaPath:"#/properties/fontId/oneOf",keyword:"oneOf",params:{passingSchemas:p},message:"must match exactly one schema in oneOf"};r===null?r=[f]:r.push(f),s++}}if(e.colorId!==void 0&&typeof e.colorId!="string"){let l={instancePath:t+"/colorId",schemaPath:"#/properties/colorId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(e.colorAlpha!==void 0&&typeof e.colorAlpha!="number"){let l={instancePath:t+"/colorAlpha",schemaPath:"#/properties/colorAlpha/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}if(e.fontSize!==void 0&&typeof e.fontSize!="number"){let l={instancePath:t+"/fontSize",schemaPath:"#/properties/fontSize/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}if(e.fontWeight!==void 0&&typeof e.fontWeight!="string"){let l={instancePath:t+"/fontWeight",schemaPath:"#/properties/fontWeight/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(e.fontStyle!==void 0){let l=e.fontStyle;if(typeof l!="string"){let c={instancePath:t+"/fontStyle",schemaPath:"#/properties/fontStyle/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[c]:r.push(c),s++}if(!(l==="normal"||l==="italic"||l==="oblique")){let c={instancePath:t+"/fontStyle",schemaPath:"#/properties/fontStyle/enum",keyword:"enum",params:{allowedValues:Tc.properties.fontStyle.enum},message:"must be equal to one of the allowed values"};r===null?r=[c]:r.push(c),s++}}if(e.lineHeight!==void 0&&typeof e.lineHeight!="number"){let l={instancePath:t+"/lineHeight",schemaPath:"#/properties/lineHeight/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}if(e.align!==void 0&&typeof e.align!="string"){let l={instancePath:t+"/align",schemaPath:"#/properties/align/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(e.wordWrap!==void 0&&typeof e.wordWrap!="boolean"){let l={instancePath:t+"/wordWrap",schemaPath:"#/properties/wordWrap/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[l]:r.push(l),s++}if(e.breakWords!==void 0&&typeof e.breakWords!="boolean"){let l={instancePath:t+"/breakWords",schemaPath:"#/properties/breakWords/type",keyword:"type",params:{type:"boolean"},message:"must be boolean"};r===null?r=[l]:r.push(l),s++}if(e.wordWrapWidth!==void 0&&typeof e.wordWrapWidth!="number"){let l={instancePath:t+"/wordWrapWidth",schemaPath:"#/properties/wordWrapWidth/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}if(e.strokeColorId!==void 0&&typeof e.strokeColorId!="string"){let l={instancePath:t+"/strokeColorId",schemaPath:"#/properties/strokeColorId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[l]:r.push(l),s++}if(e.strokeAlpha!==void 0&&typeof e.strokeAlpha!="number"){let l={instancePath:t+"/strokeAlpha",schemaPath:"#/properties/strokeAlpha/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}if(e.strokeWidth!==void 0&&typeof e.strokeWidth!="number"){let l={instancePath:t+"/strokeWidth",schemaPath:"#/properties/strokeWidth/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[l]:r.push(l),s++}if(e.shadow!==void 0){let l=e.shadow;if(l&&typeof l=="object"&&!Array.isArray(l)){if(l.colorId===void 0){let c={instancePath:t+"/shadow",schemaPath:"#/properties/shadow/required",keyword:"required",params:{missingProperty:"colorId"},message:"must have required property 'colorId'"};r===null?r=[c]:r.push(c),s++}for(let c in l)if(!(c==="colorId"||c==="alpha"||c==="blur"||c==="offsetX"||c==="offsetY")){let u={instancePath:t+"/shadow",schemaPath:"#/properties/shadow/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:c},message:"must NOT have additional properties"};r===null?r=[u]:r.push(u),s++}if(l.colorId!==void 0){let c=l.colorId;if(typeof c=="string"){if(Re(c)<1){let u={instancePath:t+"/shadow/colorId",schemaPath:"#/properties/shadow/properties/colorId/minLength",keyword:"minLength",params:{limit:1},message:"must NOT have fewer than 1 characters"};r===null?r=[u]:r.push(u),s++}}else{let u={instancePath:t+"/shadow/colorId",schemaPath:"#/properties/shadow/properties/colorId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[u]:r.push(u),s++}}if(l.alpha!==void 0){let c=l.alpha;if(typeof c=="number"){if(c>1||isNaN(c)){let u={instancePath:t+"/shadow/alpha",schemaPath:"#/properties/shadow/properties/alpha/maximum",keyword:"maximum",params:{comparison:"<=",limit:1},message:"must be <= 1"};r===null?r=[u]:r.push(u),s++}if(c<0||isNaN(c)){let u={instancePath:t+"/shadow/alpha",schemaPath:"#/properties/shadow/properties/alpha/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[u]:r.push(u),s++}}else{let u={instancePath:t+"/shadow/alpha",schemaPath:"#/properties/shadow/properties/alpha/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[u]:r.push(u),s++}}if(l.blur!==void 0){let c=l.blur;if(typeof c=="number"){if(c<0||isNaN(c)){let u={instancePath:t+"/shadow/blur",schemaPath:"#/properties/shadow/properties/blur/minimum",keyword:"minimum",params:{comparison:">=",limit:0},message:"must be >= 0"};r===null?r=[u]:r.push(u),s++}}else{let u={instancePath:t+"/shadow/blur",schemaPath:"#/properties/shadow/properties/blur/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[u]:r.push(u),s++}}if(l.offsetX!==void 0&&typeof l.offsetX!="number"){let c={instancePath:t+"/shadow/offsetX",schemaPath:"#/properties/shadow/properties/offsetX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[c]:r.push(c),s++}if(l.offsetY!==void 0&&typeof l.offsetY!="number"){let c={instancePath:t+"/shadow/offsetY",schemaPath:"#/properties/shadow/properties/offsetY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[c]:r.push(c),s++}}else{let c={instancePath:t+"/shadow",schemaPath:"#/properties/shadow/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[c]:r.push(c),s++}}}else{let l={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[l]:r.push(l),s++}return ts.errors=r,s===0}function $u(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return ts(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?ts.errors:r.concat(ts.errors),s=r.length),$u.errors=r,s===0}var ju=Nu;var jb={type:"object",properties:{x:{type:"integer"},y:{type:"integer"},anchorX:{type:"number"},anchorY:{type:"number"},scaleX:{type:"number"},scaleY:{type:"number"},rotation:{type:"number"},originX:{type:"number"},originY:{type:"number"}},additionalProperties:!1};function ns(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){for(let o in e)if(!Ze.call(jb.properties,o)){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.x!==void 0){let o=e.x;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/x",schemaPath:"#/properties/x/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}if(e.y!==void 0){let o=e.y;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/y",schemaPath:"#/properties/y/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}if(e.anchorX!==void 0&&typeof e.anchorX!="number"){let o={instancePath:t+"/anchorX",schemaPath:"#/properties/anchorX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.anchorY!==void 0&&typeof e.anchorY!="number"){let o={instancePath:t+"/anchorY",schemaPath:"#/properties/anchorY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.scaleX!==void 0&&typeof e.scaleX!="number"){let o={instancePath:t+"/scaleX",schemaPath:"#/properties/scaleX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.scaleY!==void 0&&typeof e.scaleY!="number"){let o={instancePath:t+"/scaleY",schemaPath:"#/properties/scaleY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.rotation!==void 0&&typeof e.rotation!="number"){let o={instancePath:t+"/rotation",schemaPath:"#/properties/rotation/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.originX!==void 0&&typeof e.originX!="number"){let o={instancePath:t+"/originX",schemaPath:"#/properties/originX/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}if(e.originY!==void 0&&typeof e.originY!="number"){let o={instancePath:t+"/originY",schemaPath:"#/properties/originY/type",keyword:"type",params:{type:"number"},message:"must be number"};r===null?r=[o]:r.push(o),s++}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return ns.errors=r,s===0}function Nu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return ns(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?ns.errors:r.concat(ns.errors),s=r.length),Nu.errors=r,s===0}var Du=Tu;function ss(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;if(e&&typeof e=="object"&&!Array.isArray(e)){if(e.fileId===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"fileId"},message:"must have required property 'fileId'"};r===null?r=[o]:r.push(o),s++}if(e.width===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"width"},message:"must have required property 'width'"};r===null?r=[o]:r.push(o),s++}if(e.height===void 0){let o={instancePath:t,schemaPath:"#/required",keyword:"required",params:{missingProperty:"height"},message:"must have required property 'height'"};r===null?r=[o]:r.push(o),s++}for(let o in e)if(!(o==="fileId"||o==="fileType"||o==="width"||o==="height")){let l={instancePath:t,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty:o},message:"must NOT have additional properties"};r===null?r=[l]:r.push(l),s++}if(e.fileId!==void 0&&typeof e.fileId!="string"){let o={instancePath:t+"/fileId",schemaPath:"#/properties/fileId/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.fileType!==void 0&&typeof e.fileType!="string"){let o={instancePath:t+"/fileType",schemaPath:"#/properties/fileType/type",keyword:"type",params:{type:"string"},message:"must be string"};r===null?r=[o]:r.push(o),s++}if(e.width!==void 0){let o=e.width;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/width",schemaPath:"#/properties/width/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}if(e.height!==void 0){let o=e.height;if(!(typeof o=="number"&&!(o%1)&&!isNaN(o))){let l={instancePath:t+"/height",schemaPath:"#/properties/height/type",keyword:"type",params:{type:"integer"},message:"must be integer"};r===null?r=[l]:r.push(l),s++}}}else{let o={instancePath:t,schemaPath:"#/type",keyword:"type",params:{type:"object"},message:"must be object"};r===null?r=[o]:r.push(o),s++}return ss.errors=r,s===0}function Tu(e,{instancePath:t="",parentData:n,parentDataProperty:i,rootData:a=e}={}){let r=null,s=0;return ss(e,{instancePath:t,parentData:n,parentDataProperty:i,rootData:a})||(r=r===null?ss.errors:r.concat(ss.errors),s=r.length),Tu.errors=r,s===0}var os=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),_t=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Cr=e=>e===void 0?void 0:structuredClone(e),Nb=Object.freeze({achievement:"achievements",animation:"animations",character:"characters",color:"colors",control:"controls",font:"fonts",image:"images",layout:"layouts",particle:"particles",sound:"sounds",spritesheet:"spritesheets",textStyle:"textStyles",transform:"transforms",video:"videos"}),Db=new Set(["background","bgm","character","choice","cleanAll","control","dialogue","form","layout","screen","sfx","visual","voice"]),Tb=Object.freeze({background:Lc,bgm:qc,character:Fc,choice:Bc,cleanAll:zc,control:Xc,dialogue:Hc,form:Jc,layout:Zc,screen:ru,sfx:nu,visual:iu,voice:au}),Lb=Object.freeze({achievement:cu,animation:pu,character:du,color:yu,control:gu,font:wu,image:vu,layout:ku,particle:xu,sound:Su,spritesheet:Ru,textStyle:_u,transform:ju,video:Du}),Mb=new Set(["files","language","patches"]),qb=new Set(["actionType","ignoreFields","lineId","mode","payload","type"]),Vb=new Set(["lineId","mode","payload","type"]),Fb=new Set(["mode","payload","sceneId","type"]),Ub=new Set(["mode","operation","payload","resourceId","type"]),Bb=new Set(["fileId","mimeType"]),V=(e,t)=>{throw new Error(`Invalid l10nData at ${e}: ${t}`)},Fe=(e,t)=>{_t(e)||V(t,"expected an object")},Qi=(e,t)=>{Array.isArray(e)||V(t,"expected an array")},Hr=(e,t)=>{(typeof e!="string"||e.length===0)&&V(t,"expected a non-empty string")},qu=(e,t)=>{typeof e!="string"&&V(t,"expected a string")},ze=(e,t,n)=>{for(let i of Object.keys(e))t.has(i)||V(`${n}.${i}`,"unknown field")},Ge=(e,t,n)=>{for(let i of t)os(e,i)||V(n,`missing required field "${i}"`)},Yb=e=>e.replaceAll("~1","/").replaceAll("~0","~"),zb=(e,t)=>{let n=(t?.instancePath??"").split("/").slice(1).map(Yb);return t?.keyword==="required"?n.push(t.params.missingProperty):t?.keyword==="additionalProperties"&&n.push(t.params.additionalProperty),n.reduce((i,a)=>/^\d+$/.test(a)?`${i}[${a}]`:`${i}.${a}`,e)},Gb=(e=[])=>e.filter(t=>!["anyOf","if","not","oneOf"].includes(t.keyword)).reduce((t,n)=>{if(t===void 0)return n;let i=n.instancePath.split("/").length,a=t.instancePath.split("/").length;return i>a?n:t},void 0)??e[0],Vu=({value:e,validator:t,path:n,contract:i})=>{if(t(e))return;let a=Gb(t.errors);V(zb(n,a),`does not match ${i}: ${a?.message??"schema validation failed"}`)},Kr=(e,t)=>{Hr(e,t),(e==="__proto__"||e==="constructor"||e==="prototype")&&V(t,`"${e}" is not a safe ID`)},Xb=(e,t)=>{Hr(e,t),(e==="."||e===".."||e.includes("/")||e.includes("\\")||e.includes("\0"))&&V(t,"must be a safe single filename")},Ct=(e,t)=>{if(Object.is(e,t))return!0;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)?!1:e.length===t.length&&e.every((a,r)=>Ct(a,t[r]));if(!_t(e)||!_t(t))return!1;let n=Object.keys(e).sort(),i=Object.keys(t).sort();return Ct(n,i)&&n.every(a=>Ct(e[a],t[a]))},is=(e,t=new Set,n=new WeakSet)=>{if(Array.isArray(e))return e.forEach(i=>is(i,t,n)),t;if(!_t(e)||n.has(e))return t;n.add(e);for(let[i,a]of Object.entries(e))i==="fileId"&&typeof a=="string"&&t.add(a),is(a,t,n);return t},Wb=e=>{let t=new Map;for(let[n,i]of Object.entries(e?.story?.scenes??{}))for(let[a,r]of Object.entries(i?.sections??{}))for(let[s,o]of(r?.lines??[]).entries()){if(typeof o?.id!="string")continue;let l=t.get(o.id)??[];l.push({sceneId:n,sectionId:a,lineIndex:s,line:o}),t.set(o.id,l)}return t},Fu=(e,t,n)=>{let i=e.get(t)??[];return i.length===0&&V(n,`lineId "${t}" does not exist in projectData`),i.length>1&&V(n,`lineId "${t}" is not globally unique in projectData`),i[0]},Uu=(e,t)=>e.story.scenes[t.sceneId].sections[t.sectionId].lines[t.lineIndex],Lu=e=>({items:(e?.items??[]).map(t=>({id:t?.id,events:t?.events}))}),Mu=e=>{let t=Cr(e??{});delete t.resourceId,delete t.animations;for(let n of Object.values(t.fields??{}))_t(n)&&delete n.placeholder;return t},Hb=(e,t,n,i)=>{e==="choice"&&!Ct(Lu(t),Lu(n))&&V(i,"choice item IDs and events must remain identical to the source action"),e==="form"&&!Ct(Mu(t),Mu(n))&&V(i,"form behavior must remain identical; only presentation fields and placeholders may change")},Kb=({patch:e,path:t,lineIndex:n})=>{ze(e,qb,t),Ge(e,["type","lineId","actionType","payload"],t),Kr(e.lineId,`${t}.lineId`),Hr(e.actionType,`${t}.actionType`),Fe(e.payload,`${t}.payload`),e.mode!==void 0&&e.mode!=="replace"&&V(`${t}.mode`,'line.action supports only "replace"'),Db.has(e.actionType)||V(`${t}.actionType`,`"${e.actionType}" is not a localizable presentation action`);let i=Fu(n,e.lineId,`${t}.lineId`),a=i.line?.actions?.[e.actionType];return a===void 0&&V(`${t}.actionType`,`source line "${e.lineId}" does not contain action "${e.actionType}"`),e.actionType==="dialogue"?((!Array.isArray(e.ignoreFields)||e.ignoreFields.length!==1||e.ignoreFields[0]!=="content")&&V(`${t}.ignoreFields`,'dialogue action replacement requires exactly ["content"]'),os(e.payload,"content")&&V(`${t}.payload.content`,"dialogue content must use a separate line.dialogue patch")):e.ignoreFields!==void 0&&V(`${t}.ignoreFields`,"ignoreFields is supported only for dialogue actions"),Hb(e.actionType,a,e.payload,`${t}.payload`),Vu({value:e.payload,validator:Tb[e.actionType],path:`${t}.payload`,contract:`the ${e.actionType} presentation-action schema`}),{kind:"line.action",key:`line.action:${e.lineId}:${e.actionType}`,location:i,patch:e}},Jb=(e,t)=>{Qi(e,t),e.forEach((n,i)=>{Fe(n,`${t}[${i}]`),ze(n,new Set(["text"]),`${t}[${i}]`),Ge(n,["text"],`${t}[${i}]`),qu(n.text,`${t}[${i}].text`)})},Qb=({patch:e,path:t,lineIndex:n})=>{ze(e,Vb,t),Ge(e,["type","lineId","payload"],t),Kr(e.lineId,`${t}.lineId`),Fe(e.payload,`${t}.payload`),ze(e.payload,new Set(["content"]),`${t}.payload`),Ge(e.payload,["content"],`${t}.payload`),Jb(e.payload.content,`${t}.payload.content`),e.mode!==void 0&&e.mode!=="replace"&&V(`${t}.mode`,'line.dialogue supports only "replace"');let i=Fu(n,e.lineId,`${t}.lineId`);return i.line?.actions?.dialogue===void 0&&V(`${t}.lineId`,`source line "${e.lineId}" does not contain a dialogue action`),{kind:"line.dialogue",key:`line.dialogue:${e.lineId}`,location:i,patch:e}},Zb=({patch:e,path:t,projectData:n})=>(ze(e,Fb,t),Ge(e,["type","mode","sceneId","payload"],t),Kr(e.sceneId,`${t}.sceneId`),Fe(e.payload,`${t}.payload`),ze(e.payload,new Set(["name"]),`${t}.payload`),Ge(e.payload,["name"],`${t}.payload`),qu(e.payload.name,`${t}.payload.name`),e.mode!=="patch"&&V(`${t}.mode`,'story.scene requires "patch"'),os(n?.story?.scenes??{},e.sceneId)||V(`${t}.sceneId`,`sceneId "${e.sceneId}" does not exist`),{kind:"story.scene",key:`story.scene:${e.sceneId}`,patch:e}),e0=(e,t,n)=>{Fe(t,n),["font","image","sound","spritesheet","video"].includes(e)&&Hr(t.fileId,`${n}.fileId`),["image","video"].includes(e)&&(Number.isInteger(t.width)||V(`${n}.width`,"expected an integer"),Number.isInteger(t.height)||V(`${n}.height`,"expected an integer")),e==="spritesheet"&&(Fe(t.jsonData,`${n}.jsonData`),Number.isInteger(t.width)||V(`${n}.width`,"expected an integer"),Number.isInteger(t.height)||V(`${n}.height`,"expected an integer")),e==="color"&&(typeof t.hex!="string"||!/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(t.hex))&&V(`${n}.hex`,"expected an opaque #RGB or #RRGGBB color"),Vu({value:t,validator:Lb[e],path:n,contract:`the resource.${e} schema`})},r0=({patch:e,path:t,projectData:n,packageFileIds:i,canonicalFileIds:a})=>{ze(e,Ub,t),Ge(e,["type","resourceId","payload"],t),Kr(e.resourceId,`${t}.resourceId`);let r=e.type.slice(9),s=Nb[r];s||V(`${t}.type`,`unsupported resource patch type "${e.type}"`),e.mode!==void 0&&e.mode!=="replace"&&V(`${t}.mode`,'resource patches support only "replace"'),e.operation!==void 0&&e.operation!=="add"&&V(`${t}.operation`,'the only resource operation is "add"'),e0(r,e.payload,`${t}.payload`);let o=n?.resources?.[s]??{},l=os(o,e.resourceId);e.operation==="add"&&l&&V(`${t}.resourceId`,`cannot add existing ${r} resource "${e.resourceId}"`),e.operation!=="add"&&!l&&V(`${t}.resourceId`,`cannot replace missing ${r} resource "${e.resourceId}"`);for(let c of is(e.payload))!i.has(c)&&!a.has(c)&&V(`${t}.payload`,`fileId "${c}" is not declared by this package or the canonical project`);return{kind:"resource",key:`${e.type}:${e.resourceId}`,collectionName:s,patch:e}},t0=({patch:e,path:t,projectData:n,lineIndex:i,packageFileIds:a,canonicalFileIds:r})=>{if(Fe(e,t),Hr(e.type,`${t}.type`),e.type==="line.action")return Kb({patch:e,path:t,lineIndex:i});if(e.type==="line.dialogue")return Qb({patch:e,path:t,lineIndex:i});if(e.type==="story.scene")return Zb({patch:e,path:t,projectData:n});if(e.type.startsWith("resource."))return r0({patch:e,path:t,projectData:n,packageFileIds:a,canonicalFileIds:r});V(`${t}.type`,`unsupported patch type "${e.type}"`)},n0=(e,t)=>{Qi(e,t);let n=new Set;return e.forEach((i,a)=>{let r=`${t}[${a}]`;Fe(i,r),ze(i,Bb,r),Ge(i,["fileId"],r),Xb(i.fileId,`${r}.fileId`),i.mimeType!==void 0&&(typeof i.mimeType!="string"||i.mimeType.length===0)&&V(`${r}.mimeType`,"expected a non-empty string"),n.has(i.fileId)&&V(`${r}.fileId`,`duplicate fileId "${i.fileId}"`),n.add(i.fileId)}),n},s0=({packageId:e,packageData:t,path:n,projectData:i,lineIndex:a,canonicalFileIds:r})=>{Fe(t,n),ze(t,Mb,n),Ge(t,["language","files","patches"],n),Hr(t.language,`${n}.language`);let s=n0(t.files,`${n}.files`);Qi(t.patches,`${n}.patches`);let o=new Set,l=t.patches.map((c,u)=>{let p=t0({patch:c,path:`${n}.patches[${u}]`,projectData:i,lineIndex:a,packageFileIds:s,canonicalFileIds:r});return o.has(p.key)&&V(`${n}.patches[${u}]`,`duplicate patch target "${p.key}"`),o.add(p.key),p});return{id:e,data:t,fileIds:s,patches:l}},Bu=({projectData:e,l10nData:t})=>{if(t===void 0)return{packages:new Map};Fe(t,"l10nData"),ze(t,new Set(["packages"]),"l10nData"),Ge(t,["packages"],"l10nData"),Fe(t.packages,"l10nData.packages");let n=Wb(e),i=is(e?.resources??{}),a=new Map,r=new Map;for(let[s,o]of Object.entries(t.packages)){Kr(s,`l10nData.packages.${s}`);let l=s0({packageId:s,packageData:o,path:`l10nData.packages.${s}`,projectData:e,lineIndex:n,canonicalFileIds:i});for(let c of l.fileIds){i.has(c)&&V(`l10nData.packages.${s}.files`,`fileId "${c}" conflicts with a canonical project file`);let u=r.get(c);u!==void 0&&V(`l10nData.packages.${s}.files`,`fileId "${c}" is already declared by package "${u}"`),r.set(c,s)}a.set(s,l)}return{packages:a}},i0=(e,t)=>{let{collectionName:n,patch:i}=t;e.resources[n]??={},e.resources[n][i.resourceId]=Cr(i.payload)},o0=(e,t)=>{let{patch:n}=t,i=e.story.scenes[n.sceneId];i.name=n.payload.name},a0=(e,t)=>{let{location:n,patch:i}=t,a=Uu(e,n);if(i.actionType!=="dialogue"){a.actions[i.actionType]=Cr(i.payload);return}let r=Cr(n.line.actions.dialogue.content);a.actions.dialogue=Cr(i.payload),r!==void 0&&(a.actions.dialogue.content=r)},l0=(e,t)=>{let{location:n,patch:i}=t,a=Uu(e,n);a.actions.dialogue.content=Cr(i.payload.content)},Yu=({projectData:e,l10nData:t})=>{let n=Bu({projectData:e,l10nData:t});return[{l10nId:null,language:null},...Array.from(n.packages.values(),i=>({l10nId:i.id,language:i.data.language}))]},as=({projectData:e,l10nData:t,l10nId:n=null})=>{let i=Bu({projectData:e,l10nData:t});if(n!==null&&(Kr(n,"l10nId"),i.packages.has(n)||V("l10nId",`package "${n}" was not imported`)),n===null)return e;let a=Cr(e),r=i.packages.get(n).patches;return r.filter(s=>s.kind==="resource").forEach(s=>i0(a,s)),r.filter(s=>s.kind==="story.scene").forEach(s=>o0(a,s)),r.filter(s=>s.kind==="line.action").forEach(s=>a0(a,s)),r.filter(s=>s.kind==="line.dialogue").forEach(s=>l0(a,s)),a};var c0=new Set(["loadSlot","resetStoryAtSection","rollbackByOffset","rollbackToLine","updateLocalizationPackage","updateProjectData"]),u0=new Set(["loadSlot","rollbackByOffset","rollbackToLine"]),zu="conditional",ro=Symbol("conditionalAutoContinue"),p0=new Set(["sectionTransition","resetStoryAtSection"]),f0=new Set(["nextLine","nextLineFromSystem","resetStoryAtSection","sectionTransition"]),d0=new Set(["loadSlot","rollbackByOffset","rollbackToLine"]),Zi="form",m0=new Set(["submitForm","cancelForm"]),y0="showImageGalleryVariant",h0="playMusicRoomTrack",g0="startSceneReplay",Ue=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),ls=e=>e?.type===ro,eo=(e,t)=>e?.sectionId===t?.sectionId&&e?.lineId===t?.lineId;function to(e){let t,n=0,i=null,a=0,r=!1,s=0,o=[],l=null,c=new Map,u=new Map,p=new Map,m,d,f=null,{handlePendingEffects:y}=e,g=(I=new Map,S=Date.now())=>new Map(Array.from(I.entries()).filter(([,O])=>S<O.expiresAt).map(([O,_])=>[O,{animation:structuredClone(_.animation),startedAt:_.startedAt,expiresAt:_.expiresAt}])),h=(I=new Map)=>Array.from(I.values()).map(S=>structuredClone(S.animation)),w=(I=Date.now())=>{c=new Map(Array.from(c.entries()).filter(([,S])=>I<S.expiresAt))},b=()=>{if(!(a>0||r)){r=!0;try{for(;t.selectPendingEffects().length>0;){let I=[...t.selectPendingEffects()];t.clearPendingEffects();try{y(I)}catch(S){throw t.clearPendingEffects(),I.forEach(O=>{t.appendPendingEffect(O)}),S}}}finally{r=!1}}},E=I=>{a+=1;let S=!1;try{let O=I();return S=!0,O}finally{a-=1,S&&b()}},v=({initialState:I,namespace:S})=>{let{l10nData:O,..._}=I,L=O===void 0?void 0:structuredClone(O),Y=structuredClone(I.projectData),Q=Yu({projectData:Y,l10nData:L}),ee=_.global??{};if(!Ue(ee))throw new Error("Malformed global state.");let Ee=ee.runtime??{};if(!Ue(Ee))throw new Error("Malformed global.runtime.");let Le=Ee.localizationPackageId;if(Le!=null&&typeof Le!="string")throw new Error("localizationPackageId requires a string or null value");let _r=new Set(Q.map(({l10nId:fs})=>fs).filter(fs=>fs!==null)),$r=typeof Le=="string"&&_r.has(Le)?Le:null,dp=as({projectData:Y,l10nData:L,l10nId:$r});t=Ec({..._,global:{...ee,localizationPackages:Q,runtime:{...Ee,localizationPackageId:$r}},projectData:dp}),n=0,i=Hi(S),a=0,r=!1,s=0,o=[],l=null,c=new Map,u=new Map,p=new Map,m=Y,d=L,f=$r,t.appendPendingEffect({name:"handleLineActions"}),b()},k=()=>i,x=()=>t.selectPresentationState(),C=()=>t.selectPresentationChanges(),N=I=>t.selectSectionLineChanges(I),P=(I={})=>{n+=1;let S=Date.now();w(S);let O=u.size>0,_=g(c,S),L=O?g(u,S):new Map,Q={...t.selectRenderState({activePersistentAnimations:h(_),restoredPersistentAnimations:h(L)}),id:`render-${n}`};return p.set(Q.id,{builtAt:S,persistentAnimationSessions:new Map([...L.entries(),..._.entries()]),usedRestoredPersistentAnimationSessions:O}),Q},T=(I={})=>P(I),q=(I={})=>P(I),ae=I=>{let S=typeof I?.id=="string"&&I.id.length>0?I.id:null,O=S?p.get(S):null;S&&p.delete(S);let _=new Map;Ra(I?.animations).forEach(L=>{let Y=tn(L);if(!Y)return;let Q=O?.persistentAnimationSessions?.get(Y)??c.get(Y),ee=Math.max(0,$a(L)),Ee=Q?.startedAt??O?.builtAt??Date.now();_.set(Y,{animation:structuredClone(L),startedAt:Ee,expiresAt:Ee+ee})}),c=_,O?.usedRestoredPersistentAnimationSessions&&(u=new Map)},B=()=>t.selectSystemState(),ne=()=>t.selectAchievements(),ie=I=>t.selectAchievement(I),fe=()=>t.selectSaveSlotMap(),ve=I=>t.selectSaveSlot(I),le=I=>t.selectSaveSlotPage(I),se=()=>t.selectImageGallery(),ce=()=>t.selectMusicRoom(),oe=()=>t.selectSceneReplay(),R=()=>t.selectIsSceneReplayActive(),j=()=>t.selectSkipMode(),M=()=>t.selectAutoMode(),Z=()=>t.selectRuntime(),ge=()=>t.selectIsChoiceVisible(),K=()=>t.selectIsFormVisible(),xe=()=>t.selectActiveInteraction(),me=()=>t.selectPendingEffects().some(I=>I?.name==="handleLineActions"||I?.name==="render"),Jr=(I,S,O={})=>!Ue(S)||I!=="nextLine"?S:O.bypassChoice===!0?{...S,bypassChoice:!0}:O.interactionSource===Zi?{...S,_interactionSource:Zi}:S,Qr=(I={})=>({type:ro,payload:Jr("nextLine",{_conditionalContinuation:!0},I)}),Zr=(I,S)=>ls(I)?{type:ro,payload:{...I.payload,...S.payload}}:S,cs=I=>{I.savedCheckpointOccurrences.forEach(S=>{t.markSavedRollbackCheckpointTransient(S)}),I.savedCheckpointOccurrences=[]},jt=(I,S)=>{let O=l;return l=null,!O||!eo(O.pointer,I)||O.checkpointIndex!==S?.checkpointIndex||O.checkpointIdentity!==S?.checkpoint?[]:O.savedCheckpointOccurrences},so=I=>{I.markCurrentCheckpointTransient&&(t.markRollbackCheckpointTransient({checkpointIndex:I.rollbackCursor?.checkpointIndex,checkpointIdentity:I.rollbackCursor?.checkpoint,sectionId:I.pointer?.sectionId,lineId:I.pointer?.lineId}),cs(I))},Ku=(I,S,O)=>f0.has(I)?I==="resetStoryAtSection"?O?.checkpoint!==S?.checkpoint:O?.checkpoint!==S?.checkpoint&&O?.checkpointIndex>S?.checkpointIndex:!1,Ju=I=>{let S=o.at(-1);if(!S?.markCurrentCheckpointTransient)return;let O=t.selectSaveSlot({slotId:I?.slotId});O&&S.savedCheckpointOccurrences.push({slotId:I.slotId,saveSlotIdentity:O,checkpointIndex:S.rollbackCursor?.checkpointIndex,sectionId:S.pointer?.sectionId,lineId:S.pointer?.lineId})},Qu=(I,S,O)=>{let _=o.at(-1);if(!_)return;let L=t.selectCurrentPointer()?.pointer,Y=Ku(I,S,O);if(eo(_.pointer,L)){let Q=O?.checkpoint!==S?.checkpoint||O?.checkpointIndex!==S?.checkpointIndex;(Y||Q&&d0.has(I))&&(so(_),_.pointer=L,_.rollbackCursor=O,_.markCurrentCheckpointTransient=Y,_.savedCheckpointOccurrences=[]);return}so(_),_.pointer=L,_.rollbackCursor=t.selectRollbackCursor?.()??null,_.markCurrentCheckpointTransient=Y,_.savedCheckpointOccurrences=[]},Nt=(I,S)=>{if(!t[I])return;let O=S,_,L;if(I==="updateProjectData")io(S),_=structuredClone(S.projectData),O={...S,projectData:as({projectData:_,l10nData:d,l10nId:f})},io(O);else if(I==="updateLocalizationPackage"){if(L=Zu(S),L===f)return;O={l10nId:L,projectData:as({projectData:m,l10nData:d,l10nId:L})}}p0.has(I)&&(s+=1);let Y=t.selectIsSceneReplayActive?.()===!0,Q=u0.has(I)?g(c):null,ee=t.selectRollbackCursor?.()??null,Ee=t[I](O);_!==void 0&&(m=_),L!==void 0&&(f=L),c0.has(I)&&(u=Q??new Map,c=new Map);let Le=t.selectIsSceneReplayActive?.()===!0;Y!==Le&&(c=new Map,u=new Map);let _r=t.selectRollbackCursor?.()??null;return I==="saveSlot"&&Ju(S),Qu(I,ee,_r),b(),Ee},io=I=>{if(!Object.prototype.hasOwnProperty.call(I??{},"projectData"))throw new Error("updateProjectData requires projectData");gr(I?.projectData?.resources?.variables??{}),ot(I.projectData),at(I.projectData),lt(I.projectData)},Zu=I=>{if(!Ue(I))throw new Error("updateLocalizationPackage requires an object payload");let S=Object.keys(I);if(S.length!==1||S[0]!=="l10nId")throw new Error("updateLocalizationPackage only accepts l10nId");if(I.l10nId!==null&&(typeof I.l10nId!="string"||I.l10nId.length===0))throw new Error("updateLocalizationPackage requires a non-empty l10nId or null");return I.l10nId},ep=(I,S,O)=>{let _=t.selectCurrentPointer()?.pointer;S!==_||O!==s||(t.appendPendingEffect({name:"clearAutoNextTimer"}),t.appendPendingEffect({name:"clearNextLineConfigTimer"}),Nt("nextLineFromSystem",I.payload))},rp=()=>({renderSequence:n,conditionalRoutingSequence:s,rollbackNavigationContexts:o.slice(),pendingRollbackLineEntrySaveHandoff:l,persistentAnimationSessions:new Map(c),restoredPersistentAnimationSessions:new Map(u),renderPersistentAnimationMetadata:new Map(p),canonicalProjectData:m,localizationPackageId:f}),tp=I=>{n=I.renderSequence,s=I.conditionalRoutingSequence,o=I.rollbackNavigationContexts.slice(),l=I.pendingRollbackLineEntrySaveHandoff,c=new Map(I.persistentAnimationSessions),u=new Map(I.restoredPersistentAnimationSessions),p=new Map(I.renderPersistentAnimationMetadata),m=I.canonicalProjectData,f=I.localizationPackageId},oo=(I,S={})=>E(()=>{let O=rp();try{return t[Vs](()=>{let _,L=t.selectCurrentPointer()?.pointer??null,Y=t.selectRollbackCursor?.()??null,Q=s,ee={pointer:L,rollbackCursor:Y,markCurrentCheckpointTransient:S.rollbackSource==="line",savedCheckpointOccurrences:S.savedCheckpointOccurrences?.slice()??[]};o.push(ee);try{t.beginRollbackActionBatch({source:S.rollbackSource});try{_=I()}finally{t.endRollbackActionBatch({})}ls(_)&&ep(_,L,Q)}finally{o.pop(),(!eo(L,ee.pointer)||Y?.checkpoint!==ee.rollbackCursor?.checkpoint)&&ee.markCurrentCheckpointTransient&&ee.savedCheckpointOccurrences.length>0&&(l={pointer:ee.pointer,checkpointIndex:ee.rollbackCursor?.checkpointIndex,checkpointIdentity:ee.rollbackCursor?.checkpoint,savedCheckpointOccurrences:ee.savedCheckpointOccurrences})}})}catch(_){throw tp(O),_}}),ao=(I,S,O,_={})=>{if(I===zu)return oo(()=>{let L=us(O),Y=zs({[I]:S},L);return lo(Y[I],O,_)},_);Nt(I,S)},np=(I,S)=>{ao(I,S)},us=I=>{if(!I)return{variables:t.selectAllVariables?t.selectAllVariables():void 0,runtime:t.selectRuntime?t.selectRuntime():{}};if(Object.prototype.hasOwnProperty.call(I,"event"))throw new Error('eventContext key "event" is no longer supported. Use "_event".');let{_event:S,...O}=I,_=t.selectAllVariables?t.selectAllVariables():void 0;return{...O,_event:S,variables:_,runtime:t.selectRuntime?t.selectRuntime():{}}},sp=I=>{if(!Ue(I))return{templatePayload:I,literalTargetIds:null};let S=t.selectImageGalleryConfig();if(!Array.isArray(S?.groups))return{templatePayload:I,literalTargetIds:null};let O=typeof I.groupId=="string"?S.groups.find(L=>L.id===I.groupId):void 0;if(!O)return{templatePayload:I,literalTargetIds:null};let _=typeof I.variantId=="string"&&O.variants.some(L=>L.id===I.variantId);return{templatePayload:{...I,groupId:null,..._?{variantId:null}:{}},literalTargetIds:{groupId:I.groupId,..._?{variantId:I.variantId}:{}}}},ip=I=>!Ue(I)||typeof I.trackId!="string"?{templatePayload:I,literalTargetIds:null}:t.selectMusicRoomConfig()?.tracks?.some(_=>_.id===I.trackId)?{templatePayload:{...I,trackId:null},literalTargetIds:{trackId:I.trackId}}:{templatePayload:I,literalTargetIds:null},op=I=>!Ue(I)||typeof I.replayId!="string"?{templatePayload:I,literalTargetIds:null}:t.selectSceneReplayConfig()?.replays?.some(_=>_.id===I.replayId)?{templatePayload:{...I,replayId:null},literalTargetIds:{replayId:I.replayId}}:{templatePayload:I,literalTargetIds:null},ap=I=>{if(!Ue(I))throw new Error("conditional action payload must be an object");if(!Array.isArray(I.branches))throw new Error("conditional action requires branches array");if(I.branches.length===0)throw new Error("conditional action requires at least one branch")},lp=(I,S,O)=>{if(!Ue(I))throw new Error(`conditional branch at index ${S} must be an object`);if(!Ue(I.actions))throw new Error(`conditional branch at index ${S} requires actions object`);if(!Object.prototype.hasOwnProperty.call(I,"when")&&S!==O-1)throw new Error("conditional else branch must be the last branch")},lo=(I,S,O)=>{ap(I);let _=Qr(O);for(let L=0;L<I.branches.length;L+=1){let Y=I.branches[L];lp(Y,L,I.branches.length);let Q=us(S);if(Object.prototype.hasOwnProperty.call(Y,"when")&&!it(Y.when,Q))continue;let Ee=ps(Y.actions,S,O);return ls(Ee)?Zr(_,Ee):_}return _},cp=(I,S)=>({...I??{},_form:S}),up=(I,S,O,_)=>{let L=Nt(I,S),Y=L?.submitted===!0&&L.valid===!0,Q=L?.cancelled===!0;if(!(!Y&&!Q)&&Ue(S.actions))return ps(S.actions,cp(O,L.form),{..._,interactionSource:Zi})},pp=(I,S,O,_)=>{let L=us(O),Y={templatePayload:S,literalTargetIds:null};I===y0?Y=sp(S):I===h0?Y=ip(S):I===g0&&(Y=op(S));let{templatePayload:Q,literalTargetIds:ee}=Y,Le=zs({[I]:Q},L)[I],_r=ee?{...Le,...ee}:Le;if(I===zu)return lo(_r,O,_);let $r=Jr(I,_r,_);if(m0.has(I))return up(I,$r,O,_);Nt(I,$r)},ps=(I,S,O)=>{let _;return Object.entries(I).forEach(([L,Y])=>{let Q=pp(L,Y,S,O);ls(Q)&&(_=Zr(_,Q))}),_},co=(I,S,O={})=>oo(()=>ps(I,S,O),O),fp=I=>{let S=t.selectCurrentPointer()?.pointer;if(I!==S||t.selectActiveInteraction())return;let O=t.selectNextLineConfig();O?.auto?.enabled&&O.auto.trigger==="fromStart"&&t.appendPendingEffect({name:"nextLineConfigTimer",payload:{delay:O.auto.delay}})};return{init:v,handleAction:ao,handleInternalAction:np,handleActions:co,selectRenderState:T,prepareRenderState:q,commitRenderState:ae,selectPresentationState:x,selectPresentationChanges:C,selectSectionLineChanges:N,selectSystemState:B,selectAchievements:ne,selectAchievement:ie,selectSaveSlotMap:fe,selectSaveSlot:ve,selectSaveSlotPage:le,selectSaveSlots:fe,selectImageGallery:se,selectMusicRoom:ce,selectSceneReplay:oe,selectIsSceneReplayActive:R,selectRuntime:Z,selectIsChoiceVisible:ge,selectIsFormVisible:K,selectActiveInteraction:xe,selectHasPendingRenderWork:me,handleLineActions:I=>{if(typeof I?.sceneReplayId=="string"){let S=t.selectActiveSceneReplayEntry?.();if(S?.replayId!==I.sceneReplayId||S?.entryId!==I.entryId)return!1}return E(()=>{let S=t.selectCurrentPointer()?.pointer,O=t.selectRollbackCursor?.()??null,_=l,L=jt(S,O),Y=t.selectCurrentLine(),Q=!1;if(Y?.actions){try{co(Y.actions,void 0,{rollbackSource:"line",savedCheckpointOccurrences:L})}catch(ee){throw l=_,ee}Q=!0}return fp(S),Q})},getNamespace:k}}var no=()=>{let e=0,t=null;return{getElapsed:()=>e,setElapsed:n=>{e=n},addElapsed:n=>{e+=n},getCallback:()=>t,setCallback:n=>{t=n}}},b0=80,w0="music-room:player",Wu=new Map([["soundReady","musicRoomSoundReady"],["soundProgress","musicRoomSoundProgress"],["soundComplete","musicRoomSoundComplete"],["soundError","musicRoomSoundError"]]),Gu=(e,t)=>Wu.has(e)&&t?._event?.id===w0,Hu=({engine:e,routeGraphics:t,trackRenderDispatch:n},i)=>{if(e.selectHasPendingRenderWork?.())return;let a=e.prepareRenderState?.(i)??e.selectRenderState(i);n?.(a),t.render(a),e.commitRenderState?.(a)},I0=({engine:e,routeGraphics:t,trackRenderDispatch:n,getRenderDispatchCount:i},a)=>{let r=i?.()??0,s=e.handleLineActions(a);(i?.()??0)===r&&Hu({engine:e,routeGraphics:t,trackRenderDispatch:n},a)},v0=({engine:e,ticker:t,autoTimer:n},i)=>{let a=n.getCallback();a&&t.remove(a),n.setElapsed(0);let r=s=>{n.addElapsed(s.deltaMS);let o=i.delay??1e3;n.getElapsed()>=o&&(t.remove(r),n.setCallback(null),n.setElapsed(0),$t(e,"nextLineFromSystem",{}))};n.setCallback(r),t.add(r)},A0=({ticker:e,autoTimer:t},n)=>{let i=t.getCallback();i&&(e.remove(i),t.setCallback(null)),t.setElapsed(0)},k0=({engine:e,ticker:t,skipTimer:n},i)=>{let a=n.getCallback();a&&t.remove(a),n.setElapsed(0);let r=s=>{n.addElapsed(s.deltaMS);let o=i?.delay??b0;n.getElapsed()>=o&&(n.setElapsed(0),$t(e,"nextLineFromSystem",{}))};n.setCallback(r),t.add(r)},P0=({ticker:e,skipTimer:t},n)=>{let i=t.getCallback();i&&(e.remove(i),t.setCallback(null)),t.setElapsed(0)},x0=({engine:e,ticker:t,nextLineConfigTimerState:n},i)=>{let a=n.getCallback();a&&t.remove(a),n.setElapsed(0);let r=s=>{n.addElapsed(s.deltaMS);let o=i.delay??1e3;n.getElapsed()>=o&&(n.setElapsed(0),$t(e,"nextLineFromSystem",{}),t.remove(r),n.getCallback()===r&&n.setCallback(null))};n.setCallback(r),t.add(r)},E0=({ticker:e,nextLineConfigTimerState:t},n)=>{let i=t.getCallback();i&&(e.remove(i),t.setCallback(null)),t.setElapsed(0)},S0=({enqueuePersistenceWrite:e},t)=>{e(n=>n.saveSlots(t?.saveSlots))},O0=({enqueuePersistenceWrite:e},t)=>{e(n=>n.saveGlobalDeviceVariables(t?.globalDeviceVariables))},R0=({enqueuePersistenceWrite:e},t)=>{e(n=>n.saveGlobalAccountVariables(t?.globalAccountVariables))},C0=({enqueuePersistenceWrite:e},t)=>{e(n=>n.saveGlobalRuntime(t?.globalRuntime))},_0=({enqueuePersistenceWrite:e},t)=>{e(n=>{if(typeof n.applyScopedDataUpdates!="function")throw new Error("RouteEngine persistence adapter must implement applyScopedDataUpdates.");return n.applyScopedDataUpdates(t?.updates)})},Xu={render:Hu,saveSlots:S0,saveGlobalDeviceVariables:O0,saveGlobalAccountVariables:R0,saveGlobalRuntime:C0,applyScopedDataUpdates:_0,handleLineActions:I0,startAutoNextTimer:v0,clearAutoNextTimer:A0,startSkipNextTimer:k0,clearSkipNextTimer:P0,nextLineConfigTimer:x0,clearNextLineConfigTimer:E0},$0=new Set(["render","handleLineActions","saveSlots","saveGlobalDeviceVariables","saveGlobalAccountVariables","saveGlobalRuntime","startAutoNextTimer","clearAutoNextTimer","startSkipNextTimer","clearSkipNextTimer","nextLineConfigTimer","clearNextLineConfigTimer"]),$t=(e,t,n)=>{(e.handleInternalAction??e.handleAction?.bind(e))?.(t,n)},j0=(e=[])=>{let t=new Set,n=[];for(let i=e.length-1;i>=0;i-=1){let a=e[i];if(typeof a?.name!="string"||a.name.length===0)throw new Error("Pending effect is missing a valid name.");if(!$0.has(a.name)){n.unshift(a);continue}t.has(a.name)||(t.add(a.name),n.unshift(a))}return n},N0=({getEngine:e,routeGraphics:t,ticker:n,handleUnhandledEffect:i,handlePersistenceError:a,indexedDB:r,persistence:s,namespace:o})=>{let l=no(),c=no(),u=no(),p=s??null,m=Promise.resolve(),d=null,f=null,y=!1,g=0,h=R=>{if(a){a(R);return}console.error("RouteEngine persistence write failed.",R)},w=()=>{if(p)return p;let R=e();return p=Ki({indexedDB:r,namespace:o??R?.getNamespace?.()}),p},b=R=>{m=m.catch(()=>{}).then(()=>{let j=w();return R(j)}).catch(j=>{h(j)})},E=R=>{let j=typeof R?.id=="string"&&R.id.length>0?R.id:null;g+=1,d=j,y=!1},v=()=>g,k=(R={})=>{if(R?.aborted===!0)return!1;let j=typeof R?.id=="string"&&R.id.length>0?R.id:null;return j?j!==d||j===f?!1:(f=j,!0):d!==null||y?!1:(y=!0,!0)},x=(R,j={})=>{if(Gu(R,j)){let Z=Wu.get(R),ge=e();return $t(ge,Z,j?._event),!0}if(R!=="renderComplete"||!k(j))return!1;let M=e();return $t(M,"markLineCompleted",{}),!0},C=new Set(["updateFormField","submitForm","cancelForm"]),N=new Set(["updateVariable"]),P=R=>typeof R?.selectActiveInteraction=="function"?R.selectActiveInteraction():typeof R?.selectIsChoiceVisible=="function"&&R.selectIsChoiceVisible()?{source:"choice"}:null,T=R=>R?._formKey??R?.formKey,q=(R,j)=>T(R)===j?.formKey,ae=(R,j)=>!R||typeof R!="object"||Array.isArray(R)?!1:R._interactionSource===j?.source,B=(R,j)=>ae(R,j)?j.source==="form"?q(R,j):!0:!1,ne=(R,j)=>!R||typeof R!="object"||Array.isArray(R)||j?.source!=="form"?!1:q(R,j),ie=(R={})=>Object.keys(R).some(j=>C.has(j)),fe=(R={},j)=>Object.entries(R).some(([M,Z])=>C.has(M)&&ne(Z,j)),ve=(R={})=>Object.keys(R).length>0&&Object.keys(R).every(j=>N.has(j)),le=(R={},j)=>{let M=R?.actions;return j?.source==="form"?!M||typeof M!="object"||Array.isArray(M)?!1:fe(M,j)?!0:ie(M)?!1:ve(M):B(R,j)?!0:!M||typeof M!="object"||Array.isArray(M)?!1:Object.values(M).some(Z=>B(Z,j))},se=(R,j={})=>{if(!j?.actions)return!1;let M=P(R);return!M||M.source==="choice"?!1:!le(j,M)},ce=({preprocessPayload:R,onEvent:j}={})=>async(M,Z={})=>{if(Gu(M,Z))return x(M,Z),j?.(M,Z);let ge=e();if(se(ge,Z))return j?.(M,Z);let K=await R?.(M,Z)??Z;if(se(ge,K))return j?.(M,K);if(x(M,K),K?.actions){let xe=K?._event?{_event:K._event}:K?.event?{_event:K.event}:void 0,me;K?.bypassChoice===!0?me={bypassChoice:!0}:K?._interactionSource&&(me={interactionSource:K._interactionSource}),me?ge.handleActions(K.actions,xe,me):ge.handleActions(K.actions,xe)}return j?.(M,K)},oe=R=>{let j=e(),M=j0(R),Z=M.some(K=>K.name==="handleLineActions");M.forEach(K=>{if(!Xu[K.name]&&!i)throw new Error(`Unhandled pending effect "${K.name}".`)});let ge={engine:j,routeGraphics:t,ticker:n,autoTimer:l,skipTimer:c,nextLineConfigTimerState:u,trackRenderDispatch:E,getRenderDispatchCount:v,enqueuePersistenceWrite:b};for(let K of M){if(Z&&K.name==="render")continue;let xe=Xu[K.name];if(xe){xe(ge,K.payload);continue}i(K,ge)}};return oe.handleRouteGraphicsEvent=x,oe.createRouteGraphicsEventHandler=ce,oe},D0=N0;var T0=(e,t={})=>{let{resources:n={}}=t;return hi(e,n)};var wI=to;export{Hs as DEFAULT_VISUAL_LAYER,Mr as RENDER_LAYER,Xe as VISUAL_LAYER,D0 as createEffectsHandler,wb as createIndexedDbPersistence,wI as default,Us as formatDate,qf as resolveComputedVariables,T0 as resolveLayoutReferences};