handler-playable-sdk 0.5.34 → 0.5.38

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.
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q}from"./chunk-C4GAOSNW.js";import"./chunk-JXBG6UFL.js";export{c as applyConfigOverride,d as applyConfigOverrides,o as applyConfigsToDisk,e as clearConfigOverrides,f as clearConfigOverridesForObject,i as configOverrideManager,l as deepClone,m as exportConfigsAsJSON,h as getConfigOverrides,n as getConfigStateSummary,a as getOverrideMode,k as redoLastConfigChange,g as removeConfigOverride,p as resetToApplied,q as resetToOriginal,b as setOverrideMode,j as undoLastConfigChange};
@@ -0,0 +1 @@
1
+ function w(){return typeof window=="undefined"?null:window.__editableConfig||null}function _(){return typeof window=="undefined"?null:window.__editableConfigBaseline||null}function v(n,e){var o,r;if(!n)return null;try{if(n instanceof Map)return(o=n.get(e))!=null?o:null;if(typeof n=="object")return(r=n[e])!=null?r:null}catch{}return null}function A(n,e,o){if(n){if(n instanceof Map){n.set(e,o);return}typeof n=="object"&&(n[e]=o)}}function S(n,e){for(let o of e)l(n,o.path,o.value)}function p(n){var a;if(typeof window=="undefined")return;let e=w();if(!e)return;let o=_(),r=(a=o?v(o.objects,n):null)!=null?a:v(e.objects,n);if(!r)return;let t=f(r),i=g().filter(d=>d.objectId===n);try{S(t,i)}catch(d){console.error("[CONFIG] Failed to reapply overrides for object",n,d);return}A(e.objects,n,t);let s=window.applyEditableObjectConfig;if(typeof s=="function")try{s(n,t)}catch{}}function O(){var t;if(typeof window=="undefined")return;let n=w();if(!(n!=null&&n.engine))return;let e=_(),o=f(((t=e==null?void 0:e.engine)!=null?t:n.engine)||{}),r=g().filter(i=>!i.objectId&&!i.sceneId);try{S(o,r)}catch(i){console.error("[CONFIG] Failed to reapply engine overrides",i);return}try{let i=n.engine;for(let s of Object.keys(i))s in o||delete i[s];for(let[s,a]of Object.entries(o))i[s]=a}catch{n.engine=o}}function R(){if(typeof window=="undefined")return"unknown";let n=window;return typeof n.__HANDLER_PROJECT_ID=="string"?n.__HANDLER_PROJECT_ID:"handler-default"}function N(){return`handler_preview_config_overrides::${R()}`}var k="handler_preview_override_mode";if(typeof window!="undefined"){let n=window.localStorage.getItem(k);window.__enableConfigOverrides=n===null?!0:n==="true"}function F(){if(typeof window=="undefined")return[];try{let n=window.localStorage.getItem(N());if(!n)return[];let e=JSON.parse(n);return Array.isArray(e)?e:[]}catch{return[]}}function y(n){if(typeof window!="undefined")try{window.localStorage.setItem(N(),JSON.stringify(n))}catch{}}function D(){return typeof window=="undefined"?!1:window.__enableConfigOverrides===!0}var T=500;function M(n){if(typeof window!="undefined"){window.__enableConfigOverrides=n;try{window.localStorage.setItem(k,n?"true":"false")}catch{}}}function b(n,e={}){var u,m;let{objectId:o,path:r,value:t}=n,{silent:i=!1,persist:s=!0,emitEvent:a=!0}=e,d=w();if(!d){console.warn("[CONFIG] applyConfigOverride: No editable config found in window.__editableConfig");return}let h=o?(m=(u=d.objects)==null?void 0:u.get)==null?void 0:m.call(u,o):d.engine;if(!h){console.warn("[CONFIG] applyConfigOverride: Override target not found:",{objectId:o,path:r,hasObjects:!!d.objects});return}i||console.log("[CONFIG] applyConfigOverride: Target found, applying...",{objectId:o,path:r,value:t});let I;try{I=V(h,r),l(h,r,t)}catch(c){console.error("[CONFIG] applyConfigOverride failed:",{objectId:o,path:r,value:t},c);return}if(e.trackHistory!==!1){window.__configChanges=window.__configChanges||[];let c=window.__configChanges;c.push({objectId:o,path:r,oldValue:I,newValue:t,ts:Date.now()}),c.length>T&&c.shift(),window.__configChangeRedo=[]}if(s){let c=g(),E=c.findIndex(C=>C.objectId===o&&C.sceneId===n.sceneId&&C.path===r);E>=0?c[E].value=t:c.push(n),window.__configOverrides=c,y(c),D()||M(!0)}i||console.log("[CONFIG] Applied override:",n),a&&typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("config:changed",{detail:n}))}function $(n,e={}){let o=e.emitEvent!==!1,r=[];for(let t of n)t!=null&&t.objectId&&typeof t.objectId=="string"&&r.push(t.objectId),b(t,{...e,emitEvent:!1});if(o&&typeof window!="undefined"){let t=Array.from(new Set(r));window.dispatchEvent(new CustomEvent("config:changed",{detail:{action:"batch",objectIds:t,count:n.length}}))}}function j(){window.__configOverrides=[],window.__configChanges=[],window.__configChangeRedo=[],y([]),console.log("[CONFIG] Cleared all overrides")}function J(n){let e=g().filter(r=>r.objectId!==n);window.__configOverrides=e,y(e);let o=window.__configChanges||[];window.__configChanges=o.filter(r=>r.objectId!==n),p(n),window.dispatchEvent(new CustomEvent("config:changed",{detail:{action:"clear_object",objectId:n}}))}function P(n,e){let o=g().filter(t=>t.objectId!==n||t.path!==e);window.__configOverrides=o,y(o);let r=window.__configChanges||[];window.__configChanges=r.filter(t=>t.objectId!==n||t.path!==e),n?p(n):O(),window.dispatchEvent(new CustomEvent("config:changed",{detail:{action:"remove",objectId:n,path:e}}))}function g(){return typeof window=="undefined"?[]:(window.__configOverrides||(window.__configOverrides=F()),window.__configOverrides||[])}var B={getCurrentConfig(){return window.__editableConfig||null},getChanges(){return window.__configChanges||[]},clearChanges(){window.__configChanges=[],window.__configChangeRedo=[]}};function L(){if(typeof window=="undefined")return!1;let n=window.__configChanges||[];if(n.length===0)return!1;let e=n.pop();window.__configChangeRedo=window.__configChangeRedo||[],window.__configChangeRedo.push({objectId:e.objectId,path:e.path,oldValue:e.newValue,newValue:e.oldValue,ts:Date.now()});let r=_(),t=!1;if(r){let i=e.objectId?v(r.objects,e.objectId):r.engine;if(i){let s=V(i,e.path);JSON.stringify(s)===JSON.stringify(e.oldValue)&&(t=!0)}}return t?P(e.objectId,e.path):(b({objectId:e.objectId,path:e.path,value:e.oldValue},{trackHistory:!1,persist:!0,emitEvent:!0}),e.objectId?p(e.objectId):O()),console.log("[CONFIG] Undo:",e.path),!0}function U(){if(typeof window=="undefined")return!1;let n=window.__configChangeRedo||[];if(n.length===0)return!1;let e=n.pop();return window.__configChanges=window.__configChanges||[],window.__configChanges.push({objectId:e.objectId,path:e.path,oldValue:e.newValue,newValue:e.oldValue,ts:Date.now()}),b({objectId:e.objectId,path:e.path,value:e.oldValue},{trackHistory:!1,persist:!0,emitEvent:!0}),e.objectId?p(e.objectId):O(),console.log("[CONFIG] Redo:",e.path),!0}function l(n,e,o){var s;let r=e.split("."),t=r.pop(),i=n;for(let a of r){if(i[a]!==void 0&&typeof i[a]!="object")throw new Error(`Invalid override path: ${e} (hit primitive at ${a})`);i[a]=(s=i[a])!=null?s:{},i=i[a]}i[t]=o}function V(n,e){return e.split(".").reduce((o,r)=>o?o[r]:void 0,n)}function f(n){if(n===null||typeof n!="object")return n;if(n instanceof Date)return new Date(n.getTime());if(n instanceof Set)return new Set([...n].map(o=>f(o)));if(ArrayBuffer.isView(n))return n.slice();if(n instanceof Array)return n.map(o=>f(o));if(n instanceof Map){let o=new Map;return n.forEach((r,t)=>o.set(t,f(r))),o}let e={};for(let o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=f(n[o]));return e}function G(){let n=window.__editableConfigBaseline;if(!n){let e=window.__editableConfig;if(!e)throw new Error("Cannot export: no config loaded");return x(e)}return x(n)}function x(n){let e={objects:{},scenes:{},engine:f(n.engine||{})},o=n.objects;if(o instanceof Map)o.forEach((i,s)=>{e.objects[s]=f(i)});else if(o&&typeof o=="object")for(let i in o)e.objects[i]=f(o[i]);let r=n.scenes;if(r instanceof Map)r.forEach((i,s)=>{e.scenes[s]=f(i)});else if(r&&typeof r=="object")for(let i in r)e.scenes[i]=f(r[i]);let t=g();for(let i of t)i.objectId?(e.objects[i.objectId]||(e.objects[i.objectId]={}),l(e.objects[i.objectId],i.path,i.value)):i.sceneId?(e.scenes[i.sceneId]||(e.scenes[i.sceneId]={}),l(e.scenes[i.sceneId],i.path,i.value)):l(e.engine,i.path,i.value);return e}function K(){let n=g(),e=new Set;for(let o of n)o.objectId?e.add(o.objectId):e.add("__engine__");return{modifiedObjects:Array.from(e),overrideCount:n.length,hasChanges:n.length>0,overrides:n}}async function W(n){let e=G(),o={};for(let[t,i]of Object.entries(e.objects)){let s=i,a=t;/^(json\.|ui\.|effects\.|engine\.)/.test(a)||(a=`json.${t}`),s&&typeof s=="object"&&(s.identity||(s.identity={}),s.identity.id=a),o[`objects/${a}.json`]=s}e.engine&&(e.engine.runtime&&(o["engine/engine.runtime.json"]=e.engine.runtime),e.engine.assets&&(o["engine/engine.assets.json"]=e.engine.assets),e.engine.splash&&(o["engine/engine.splash.json"]=e.engine.splash),e.engine.loading&&(o["engine/engine.loading.json"]=e.engine.loading),e.engine.start&&(o["engine/engine.start.json"]=e.engine.start),e.engine.tutorial&&(o["engine/engine.tutorial.json"]=e.engine.tutorial),e.engine.endgame&&(o["engine/engine.endgame.json"]=e.engine.endgame),!e.engine.runtime&&!e.engine.assets&&(o["engine/engine.json"]=e.engine));for(let[t,i]of Object.entries(e.scenes)){let s=t.startsWith("scene.")?t:`scene.${t}`;o[`scenes/${s}.json`]=i}let r=await fetch("/api/apply",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({configs:o,assets:{},hadCacheAtApply:g().length>0,versionName:n})});if(!r.ok){let t=await r.json();throw new Error(`Apply failed: ${t.error||"Unknown error"}`)}j();try{let t=w();t&&(window.__editableConfigBaseline=f(t))}catch{}localStorage.setItem("handler_last_applied",Date.now().toString()),console.log("[Config Persistence] \u2705 Applied to disk successfully")}function q(){j(),window.location.reload()}async function X(){if(!confirm("This will restore all configs to their original state. All uncommitted changes in cache AND applied changes will be lost. Continue?"))return;let e=await fetch("/api/reset-to-original",{method:"POST"});if(!e.ok){let o=await e.json();throw new Error(`Reset failed: ${o.error||"Unknown error"}`)}j(),window.location.reload()}export{D as a,M as b,b as c,$ as d,j as e,J as f,P as g,g as h,B as i,L as j,U as k,f as l,G as m,K as n,W as o,q as p,X as q};