handler-playable-sdk 0.3.32 → 0.3.34

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.
@@ -44,7 +44,7 @@
44
44
  <button class="debug-btn primary" data-modal-apply>Apply</button>
45
45
  </div>
46
46
  </div>
47
- `,this.modal=i}attachModalListeners(){if(!this.modal)return;this.modal.querySelectorAll("[data-modal-close]").forEach(s=>{s.addEventListener("click",()=>this.close())}),this.modal.querySelectorAll("[data-tab]").forEach(s=>{s.addEventListener("click",o=>{let l=o.target.dataset.tab;l&&this.switchTab(l)})});let i=this.modal.querySelector("[data-ai-generate]");i==null||i.addEventListener("click",()=>{this.openAiEditor("generate")});let r=this.modal.querySelector("[data-ai-edit]");r==null||r.addEventListener("click",()=>{this.openAiEditor("edit")});let a=this.modal.querySelector("[data-modal-apply]");a==null||a.addEventListener("click",()=>{this.apply()}),this.modal.addEventListener("click",s=>{s.target===this.modal&&this.close()})}switchTab(t){if(!this.modal)return;this.modal.querySelectorAll("[data-tab]").forEach(r=>{r.classList.toggle("active",r.getAttribute("data-tab")===t)}),this.modal.querySelectorAll("[data-tab-panel]").forEach(r=>{r.classList.toggle("active",r.getAttribute("data-tab-panel")===t)})}openAiEditor(t){let n=window.__openAiEditor;if(typeof n!="function"){alert("AI Editor not available. Please check your setup.");return}let i="";t==="edit"&&this.currentAsset?i=`Edit this image: ${this.currentObjectId}`:i=`Create an image for: ${this.currentObjectId}`,n(this.currentObjectId||"unknown",i,this.currentAsset,{path:this.currentPath,onApply:r=>{this.onApplyCallback&&this.onApplyCallback(r),this.close()}})}apply(){this.onApplyCallback&&this.onApplyCallback("library/placeholder.png"),this.close()}close(){this.modal&&this.modal.parentNode&&this.modal.parentNode.removeChild(this.modal),this.modal=null,this.currentObjectId=null,this.currentPath=null,this.onApplyCallback=null}}});var V0={};hc(V0,{AspectClass:()=>$o,GameObject:()=>Di,GameObjectManager:()=>na,Renderer:()=>ji,ResponsiveUISystem:()=>zn,Transform:()=>Pi,animateHandClick:()=>Hh,animatePanelEntrance:()=>Nh,createBrushTexture:()=>Vh,createEndGamePanel:()=>Bh,createHandTutorial:()=>$h,createThreeBase:()=>Dh,createTutorialLabel:()=>Uh,getAspectClass:()=>ta,getRegisteredFontIds:()=>Fh,loadAsset:()=>Go,loadCharacterFrames:()=>Yh,registerFont:()=>zh,resolveFont:()=>Fe,resolveFontWeight:()=>Be,updateHandAnimation:()=>qh});module.exports=Hg(V0);var Te=Ge(require("three"),1);var dt={};function qi(e,t,n=!1){dt[e]||(dt[e]=[]),dt[e].push({fn:t,once:n})}function ga(e,t){if(dt[e]){if(!t){delete dt[e];return}dt[e]=dt[e].filter(n=>n.fn!==t)}}function Gi(e,...t){let n=dt[e];if(n)for(let i of[...n])i.fn(...t),i.once&&ga(e,i.fn)}function fe(e,t){qi(e,t,!0)}var q=null,we=[],Zt=null;function yc(e){q=e,we=[],Zt!==null&&(clearTimeout(Zt),Zt=null)}function vc(){var e,t,n;return{endpoint:(q==null?void 0:q.endpoint)||"",transport:(q==null?void 0:q.transport)||"beacon",batchSize:(e=q==null?void 0:q.batchSize)!=null?e:10,flushIntervalMs:(t=q==null?void 0:q.flushIntervalMs)!=null?t:300,maxQueue:(n=q==null?void 0:q.maxQueue)!=null?n:200,debug:!!(q!=null&&q.debug)}}async function mc(e,t,n,i){let r=JSON.stringify(t);if(n==="beacon"&&typeof navigator!="undefined"&&typeof navigator.sendBeacon=="function")try{let a=navigator.sendBeacon(e,new Blob([r],{type:"application/json"}));i&&console.log("[handler.telemetry] beacon",a,t);return}catch(a){i&&console.warn("[handler.telemetry] beacon failed, fallback to fetch",a)}try{await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:r,keepalive:!0}),i&&console.log("[handler.telemetry] fetch",t)}catch(a){i&&console.warn("[handler.telemetry] fetch failed",a)}}function ma(e,t){let n=vc();if(t&&n.endpoint){if(we.push(e),we.length>n.maxQueue&&(we=we.slice(we.length-n.maxQueue)),we.length>=n.batchSize){bc();return}Zt===null&&(Zt=window.setTimeout(()=>{Zt=null,bc()},n.flushIntervalMs))}}async function bc(){let e=vc();if(!e.endpoint||we.length===0)return;let t=we.splice(0,e.batchSize);await mc(e.endpoint,{events:t},e.transport,e.debug),we.length>0&&await mc(e.endpoint,{events:we.splice(0,e.batchSize)},e.transport,e.debug)}function xc(e){return Math.max(0,Math.min(1,e))}function $g(e){let t=String(e!=null?e:"power2.out");if(t==="linear")return n=>n;if(t==="sine.inOut")return n=>.5-Math.cos(Math.PI*n)/2;if(t==="power2.out"||t==="easeOutQuad")return n=>1-(1-n)*(1-n);if(t.startsWith("back.out")){let n=t.match(/back\.out\(([\d.]+)\)/),i=n?Number(n[1]):1.8;return r=>1+(i+1)*Math.pow(r-1,3)+i*Math.pow(r-1,2)}return n=>1-(1-n)*(1-n)}function Hn(){return typeof performance!="undefined"&&performance.now?performance.now():Date.now()}function Ug(e,t){let n=e==null?void 0:e[t];return typeof n=="number"?n:0}function wc(e,t,n){try{e[t]=n}catch{}}function qg(e){let t=e==null?void 0:e.scale;if(!t)return null;let n=typeof t.x=="number"?t.x:1,i=typeof t.y=="number"?t.y:1;return{x:n,y:i}}function _c(e,t){let n=e==null?void 0:e.scale;if(n)try{typeof n.set=="function"?n.set(t.x,t.y):(typeof n.x=="number"&&(n.x=t.x),typeof n.y=="number"&&(n.y=t.y))}catch{}}function Ec(e,t){let n=qg(e);if(!n)return{from:null,to:null};let i=null,r=null;return typeof t.scale=="number"?(i=t.scale,r=t.scale):t.scale&&typeof t.scale=="object"&&(typeof t.scale.x=="number"&&(i=t.scale.x),typeof t.scale.y=="number"&&(r=t.scale.y)),typeof t.scaleX=="number"&&(i=t.scaleX),typeof t.scaleY=="number"&&(r=t.scaleY),i===null&&r===null?{from:null,to:null}:{from:{x:n.x,y:n.y},to:{x:i!=null?i:n.x,y:r!=null?r:n.y}}}function Sc(){let e=new Set,t=new WeakMap,n=null,i=()=>{if(n!=null)return;n=requestAnimationFrame(()=>{n=null,o(),e.size>0&&i()})},r=c=>{var p;e.add(c);let f=(p=t.get(c.target))!=null?p:new Set;f.add(c),t.set(c.target,f),i()},a=c=>{e.delete(c);let f=t.get(c.target);f&&(f.delete(c),f.size===0&&t.delete(c.target))},s=c=>{c.killed||(c.killed=!0,a(c))},o=()=>{var f,p;let c=Hn();for(let u of Array.from(e)){if(u.killed||u.paused)continue;let v=c-u.startMs-u.delayMs;if(v<0)continue;let h=u.durationMs>0?v/u.durationMs:1,w=xc(h),y=u.repeat>=0?u.repeat+1:1,m=u.repeat>0?Math.min(Math.floor(h),y-1):0;if(u.repeat>0&&h>=1){let x=h-m;w=xc(x)}let b=u.ease(w);u.yoyo&&m%2===1&&(b=1-b);for(let x of u.props)wc(u.target,x.key,x.from+(x.to-x.from)*b);u.scaleFrom&&u.scaleTo&&_c(u.target,{x:u.scaleFrom.x+(u.scaleTo.x-u.scaleFrom.x)*b,y:u.scaleFrom.y+(u.scaleTo.y-u.scaleFrom.y)*b});try{(f=u.onUpdate)==null||f.call(u)}catch{}if(h>=y){s(u);try{(p=u.onComplete)==null||p.call(u)}catch{}}}},d=(c,f,p)=>{var x;let u=Math.max(0,(typeof f.duration=="number"?f.duration:.5)*1e3),v=Math.max(0,(typeof f.delay=="number"?f.delay:0)*1e3+((x=p==null?void 0:p.delayMsOverride)!=null?x:0)),h=$g(f.ease),w=typeof f.repeat=="number"?Math.max(0,f.repeat|0):0,y=f.yoyo===!0,m=new Set(["duration","delay","ease","repeat","yoyo","onUpdate","onComplete","scale","scaleX","scaleY"]),b=[];for(let E of Object.keys(f)){if(m.has(E))continue;let A=f[E];typeof A=="number"&&b.push({key:E,from:Ug(c,E),to:A})}let g=Ec(c,f);return{target:c,startMs:Hn(),delayMs:v,durationMs:u,ease:h,props:b,scaleFrom:g.from,scaleTo:g.to,repeat:w,yoyo:y,onUpdate:typeof f.onUpdate=="function"?f.onUpdate:void 0,onComplete:typeof f.onComplete=="function"?f.onComplete:void 0,killed:!1,paused:!1,pauseAtMs:null}},l={to(c,f){let p=d(c,f);return r(p),{kill:()=>s(p),pause:()=>{p.paused||(p.paused=!0,p.pauseAtMs=Hn())},resume:()=>{var h;if(!p.paused)return;let u=(h=p.pauseAtMs)!=null?h:Hn(),v=Hn()-u;p.startMs+=v,p.paused=!1,p.pauseAtMs=null},isActive:()=>!p.killed&&!p.paused}},fromTo(c,f,p){return l.set(c,f),l.to(c,p)},set(c,f){if(!c||!f)return;for(let u of Object.keys(f)){let v=f[u];u==="scale"||u==="scaleX"||u==="scaleY"||typeof v=="number"&&wc(c,u,v)}let p=Ec(c,f);p.to&&_c(c,p.to)},killTweensOf(c){let f=t.get(c);if(f)for(let p of Array.from(f))s(p)},timeline(c={}){let f=[],p=0,u=!1,v=[],h=m=>{if(typeof m=="number")return Math.max(0,m*1e3);let b=typeof m=="string"?m.trim():"";return b.startsWith("+=")?p+Math.max(0,Number(b.slice(2))*1e3||0):b?Math.max(0,Number(b)*1e3||0):p},w=m=>{f.push(m);let b=Math.max(0,(typeof m.vars.duration=="number"?m.vars.duration:.5)*1e3);p=Math.max(p,m.atMs+b)},y={to(m,b,g){return w({kind:"to",target:m,vars:b,atMs:h(g)}),y},fromTo(m,b,g,x){return w({kind:"fromTo",target:m,vars:g,from:b,atMs:h(x)}),y},play(){var m,b;if(u)return y;u=!0,v=[];for(let g of f)g.kind==="fromTo"&&l.set(g.target,(m=g.from)!=null?m:{}),v.push(l.to(g.target,{...g.vars,delay:g.atMs/1e3+((b=g.vars.delay)!=null?b:0)}));return y},pause(){for(let m of v)m.pause();return y},kill(){for(let m of v)m.kill();v=[],u=!1}};return c.paused||y.play(),y}};return l}function Ac(){if(typeof window=="undefined")return;let e=window;if(!e.gsap)try{e.gsap=Sc()}catch{}}var Cc={name:"handler-playable-sdk",version:"0.3.32",type:"module",description:"Handler Playable SDK v0.1 with contract-aligned surface (root sandbox, canonical event envelope).",main:"dist/index.cjs",module:"dist/index.js",types:"dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"},"./pixi":{types:"./dist/pixi/index.d.ts",import:"./dist/pixi/index.js",require:"./dist/pixi/index.cjs"},"./pixi/index.css":{import:"./dist/pixi/index.css",require:"./dist/pixi/index.css"},"./three":{types:"./dist/three/index.d.ts",import:"./dist/three/index.js",require:"./dist/three/index.cjs"},"./cli":{types:"./dist/cli/index.d.ts",import:"./dist/cli/index.js",require:"./dist/cli/index.cjs"}},bin:{"handler-student-helper":"./bin/student-helper.mjs","handler-validate":"./bin/validate.mjs","handler-sync-screens":"./bin/sync-screens.mjs","handler-brand-dna":"./bin/brand-dna.mjs","handler-setup-library":"./bin/setup-library.mjs","handler-screen-helper":"./bin/screen-helper.mjs"},scripts:{prebuild:"python3 src/preview/build-css.py",build:"tsup src/index.ts src/pixi/index.ts src/three/index.ts src/cli/index.ts --format cjs,esm --dts --clean --minify --external lottie-web && npm run create-mjs-symlinks && npm run postbuild-cli && npm run obfuscate && npm run postbuild",postbuild:"python3 src/preview/copy-css-to-dist.py","postbuild-cli":"cp src/cli/*.mjs dist/cli/ && chmod +x dist/cli/*.mjs && chmod +x bin/*.mjs","create-mjs-symlinks":"cd dist && ln -sf index.js index.mjs && cd pixi && ln -sf index.js index.mjs && cd ../three && ln -sf index.js index.mjs","build:dev":"tsup src/index.ts src/pixi/index.ts src/three/index.ts src/cli/index.ts --format cjs,esm --dts --clean --external lottie-web && npm run create-mjs-symlinks && npm run postbuild-cli",obfuscate:"javascript-obfuscator dist/pixi/index.js --output dist/pixi/index.js --config obfuscator.config.json && javascript-obfuscator dist/three/index.js --output dist/three/index.js --config obfuscator.config.json && javascript-obfuscator dist/cli/index.js --output dist/cli/index.js --config obfuscator.config.json && npm run obfuscate-cli","obfuscate-cli":'for file in dist/cli/*.mjs; do javascript-obfuscator "$file" --output "$file" --config obfuscator.config.json; done',lint:"eslint 'src/**/*.{ts,tsx}'",typecheck:"tsc --noEmit",prepublishOnly:"npm run build","publish:update":"node scripts/publish-and-update.cjs patch","publish:update:minor":"node scripts/publish-and-update.cjs minor","publish:update:major":"node scripts/publish-and-update.cjs major"},author:"Handler",license:"MIT",publishConfig:{access:"public"},repository:{type:"git",url:"https://github.com/HandlerAIGames/handler-playable-sdk.git"},files:["dist","bin","LICENSE","README.md"],peerDependencies:{"lottie-web":"^5.0.0","pixi.js":"^8.0.0",three:"^0.182.0"},peerDependenciesMeta:{"pixi.js":{optional:!0},three:{optional:!0},"lottie-web":{optional:!0}},devDependencies:{"@types/three":"^0.182.0",eslint:"^9.39.2","javascript-obfuscator":"^5.1.0","pixi.js":"8.8.1",three:"^0.182.0","ts-node":"^10.9.2",tsup:"^8.4.0",typescript:"^5.7.2","typescript-eslint":"^8.53.0"},dependencies:{"@google/genai":"^1.35.0","@google/generative-ai":"^0.24.1",sharp:"^0.34.5"}};var he=0,Wg=he++,Tc=he++,kc=he++,Lc=he++,Rc=he++,Mc=he++,Oc=he++,Ic=he++,Pc=he++,jc=he++,Dc=he++,zc=he++,N=Wg;function Fc(){return N===Tc}function Bc(){return N===kc}function Nc(){return N===Lc}function Hc(){return N===Rc}function Jt(){return N===Mc}function Qt(){return N===Oc}function $c(){return N===Ic}function Uc(){return N===Pc}function qc(){return N===jc}function ba(){return N===Dc}function ya(){return N===zc}function Gc(){let e=typeof AD_PROTOCOL!="undefined"?AD_PROTOCOL:"none",t=typeof AD_NETWORK!="undefined"?AD_NETWORK:"web_embed";if(e==="mraid")try{mraid.getState(),N=Tc;return}catch{}else if(e==="dapi")try{dapi.isReady(),N=kc;return}catch{}if(t==="facebook")try{typeof FbPlayableAd!="undefined"&&(N=Lc)}catch{}else if(t==="google")try{typeof ExitApi!="undefined"&&(N=Rc)}catch{}else if(t==="mintegral")window.gameReady&&(N=Mc);else if(t==="tapjoy")window.TJ_API&&(N=Oc);else if(t==="tiktok")window.openAppStore&&(N=Ic);else if(t==="smadex")try{window.smxTracking&&(N=Pc)}catch{}else if(t==="snapchat")try{window.ScPlayableAd&&(N=jc)}catch{}else t==="vungle"?N=Dc:(e==="nucleo"||t==="nucleo")&&(N=zc)}var Wi=Ge(require("lottie-web"),1),Wc=Wi.default;typeof window!="undefined"&&(window.lottie=Wi.default,window.__baseLottie=Wi.default);var Yg=require("pixi.js");var va=require("pixi.js");var Vg=null;function xa(e){Vg=e}Yi();wa();var $n=require("pixi.js");Yi();var em=typeof __BUILD_MODE__!="undefined"?__BUILD_MODE__:"undefined",Aa=em;if(typeof window!="undefined")try{let e=new XMLHttpRequest;if(e.open("GET","./build-settings.json",!1),e.send(),e.status===200&&e.responseText){let t=JSON.parse(e.responseText);t!=null&&t.buildMode&&(Aa=t.buildMode,console.log(`[ObjectFactory] Build mode overridden by settings: ${Aa}`))}}catch{}var Mt=class{static async create(t,n,i){var d,l,c,f,p,u,v;console.log(`[ObjectFactory] create() called for: ${t}, __BUILD_MODE__: ${Aa}`);let r=(d=n==null?void 0:n.render)==null?void 0:d.asset;if(!r){console.log(`[ObjectFactory] No asset definition for: ${t}, returning empty container`);let h=new $n.Container;return this.applyTransform(h,n==null?void 0:n.transform),h}let a=(l=n==null?void 0:n.identity)==null?void 0:l.id;console.log(`[ObjectFactory] Calling AssetLoader.load() for: ${t}, configId: ${a}, type: ${r.type}, path: ${r.path}`);let s=await Rt.load(t,r,i,a);console.log(`[ObjectFactory] AssetLoader.load() completed for: ${t}, rawAsset type: ${(c=s==null?void 0:s.constructor)==null?void 0:c.name}`);let o;if(r.type==="image")console.log("[ObjectFactory] Creating Sprite from texture:",s,"for object:",t),o=new $n.Sprite(s),console.log("[ObjectFactory] Created object:",o,"type:",(f=o==null?void 0:o.constructor)==null?void 0:f.name),this.applyTransform(o,n==null?void 0:n.transform);else if(r.type==="json")if(console.log("[ObjectFactory] JSON asset for",t,"rawAsset type:",(p=s==null?void 0:s.constructor)==null?void 0:p.name,s),s&&(((u=s.constructor)==null?void 0:u.name)==="Container"||s instanceof $n.Container)){console.warn("[ObjectFactory] JSON asset is Container (from cache), reloading JSON directly");let h=[r.path,`/assets/${r.path}`,`assets/${r.path}`,`../assets/${r.path}`],w=!1;for(let y of h)try{let m=await fetch(y);if(m.ok){o=await m.json(),console.log("[ObjectFactory] Reloaded JSON directly from:",y,"type:",(v=o==null?void 0:o.constructor)==null?void 0:v.name),w=!0;break}}catch{continue}w||(console.error("[ObjectFactory] Failed to reload JSON from any path"),o=s)}else o=s;else o=s,o&&typeof o=="object"&&("x"in o||"position"in o)&&this.applyTransform(o,n==null?void 0:n.transform);return o}static applyTransform(t,n){var i,r,a,s;!n||!t||(n.position&&("x"in t&&"y"in t?(t.x=(i=n.position.x)!=null?i:0,t.y=(r=n.position.y)!=null?r:0):"position"in t&&t.position&&t.position.set((a=n.position.x)!=null?a:0,(s=n.position.y)!=null?s:0)),n.scale!==void 0&&"scale"in t&&t.scale&&(typeof t.scale=="object"&&"set"in t.scale?t.scale.set(n.scale):t.scale=n.scale),n.rotation!==void 0&&"rotation"in t&&(t.rotation=n.rotation),n.anchor&&"anchor"in t&&t.anchor&&Array.isArray(n.anchor)&&("set"in t.anchor?t.anchor.set(n.anchor[0],n.anchor[1]):(t.anchor.x=n.anchor[0],t.anchor.y=n.anchor[1])))}};var Un=class{constructor(){this.config=null}init(t){this.config=t}get(t){if(!this.config)throw new Error("RuntimeObjectRegistry not initialized. Call init() first.");return this.config.objects.get(t)}getAllIds(){if(!this.config)throw new Error("RuntimeObjectRegistry not initialized. Call init() first.");return Array.from(this.config.objects.keys())}has(t){return this.config?this.config.objects.has(t):!1}};var im=Ge(require("pixi.js"),1);typeof window!="undefined"&&(window.__basePixi=im);qn();var Xi=require("pixi.js");qn();var Ta=class{constructor(){this.instanceCache=new Map;this.readyPromise=null;this.app=null;this.registry=new Un}init(t,n){this.registry.init(t),this.app=n}updateConfig(t){this.registry.init(t),this.instanceCache.clear(),this.readyPromise=null}async ready(){this.readyPromise&&await this.readyPromise;let n=this.registry.getAllIds().filter(r=>!this.instanceCache.has(r));if(n.length===0)return;let i=async r=>{r.length&&(console.log("[Assets] Loading objects:",r),await Promise.all(r.map(async a=>{var o;let s=this.registry.get(a);if(!s){console.warn("[Assets] No config found for object:",a);return}try{let d=await Mt.create(a,s,this.app);this.instanceCache.set(a,d),console.log("[Assets] Loaded object:",a,(o=d==null?void 0:d.constructor)==null?void 0:o.name)}catch(d){console.error("[Assets] Failed to load object:",a,d)}})))};return this.readyPromise=(async()=>{await i(n);let r=this.registry.getAllIds().filter(a=>!this.instanceCache.has(a));r.length>0&&(console.warn("[Assets] Retrying missing assets:",r),await i(r)),console.log("[Assets] Ready. Cached objects:",Array.from(this.instanceCache.keys()))})(),this.readyPromise}resetScene(){this.instanceCache.clear(),this.readyPromise=null}async reloadObject(t){let n=this.registry.get(t);if(n){let i=await Mt.create(t,n,this.app);this.instanceCache.set(t,i)}}get(t){return this.instanceCache.get(t)}},am=new Ta,sm=new Proxy(am,{get(e,t){if(t in e&&typeof e[t]=="function")return e[t].bind(e);if(e.get(t))return e.get(t)}});qn();var Kc=require("pixi.js"),Xe={width:400,height:600,designWidth:400,scaleFactor:1},Zi={scale:1,position:1},La=[];function cm(e,t,n,i,r,a,s){La.push({element:e,originalScale:a,positionHelper:t,heightPercent:r}),t(e,n,i,r,a,s,!1)}function dm(){La.forEach(({element:e,originalScale:t,positionHelper:n,heightPercent:i})=>{let r=t*Xe.scaleFactor;n(e,Xe.width,Xe.height,i,r,!0,!1)})}function ka(e,t){console.log(`[SCREEN] updateScreenState called: ${e}x${t}`),Xe.width=e,Xe.height=t,Xe.scaleFactor=Math.min(e/Xe.designWidth,1.15),Zi.scale=Xe.scaleFactor,Zi.position=1,console.log(`[SCREEN] Global multipliers - scale: ${Zi.scale.toFixed(3)}`),dm()}var Wn={layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:1,screen_scale_y:1},engine:{scale:1,background_scale:1.05,background_offset_y:0,background_alpha:.98,label_pulse_speed:3,label_pulse_intensity:.03}};function um(e,t,n){let i=Wn[e];i&&i[t]!==void 0&&(i[t]=n,console.log(`Updated ${e}.${t} = ${n}`))}function pm(){return Wn}var fm={center:{x:.5,y:.5},"center-center":{x:.5,y:.5},middle:{x:.5,y:.5},"middle-center":{x:.5,y:.5},"top-left":{x:0,y:0},"top-center":{x:.5,y:0},"top-right":{x:1,y:0},"bottom-left":{x:0,y:1},"bottom-center":{x:.5,y:1},"bottom-right":{x:1,y:1},"left-center":{x:0,y:.5},"right-center":{x:1,y:.5},"center-left":{x:0,y:.5},"center-right":{x:1,y:.5},left:{x:0,y:.5},right:{x:1,y:.5},top:{x:.5,y:0},bottom:{x:.5,y:1}};function Ki(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function Ji(e,t={x:.5,y:.5}){var n;if(Array.isArray(e))return{x:Ki(e[0],t.x),y:Ki(e[1],t.y)};if(e&&typeof e=="object"){let i=e;return{x:Ki(i.x,t.x),y:Ki(i.y,t.y)}}if(typeof e=="string"){let i=e.trim().toLowerCase();return(n=fm[i])!=null?n:t}return t}function Zc(e,t,n,i={}){var u,v,h,w,y,m;let r=Ji(n),a=(u=i.inset)!=null?u:{},s=(v=i.padding)!=null?v:{x:0,y:0},o=((h=a.left)!=null?h:0)+s.x,d=((w=a.right)!=null?w:0)+s.x,l=((y=a.top)!=null?y:0)+s.y,c=((m=a.bottom)!=null?m:0)+s.y,f=Math.max(0,e-o-d),p=Math.max(0,t-l-c);return{x:o+f*r.x,y:l+p*r.y}}function Jc(e,t,n,i={}){var h,w,y,m,b,g;let r=(h=i.inset)!=null?h:{},a=(w=i.padding)!=null?w:{x:0,y:0},s=((y=r.left)!=null?y:0)+a.x,o=((m=r.right)!=null?m:0)+a.x,d=((b=r.top)!=null?b:0)+a.y,l=((g=r.bottom)!=null?g:0)+a.y,c=Math.max(0,e-s-o),f=Math.max(0,t-d-l),p=Ji(n,{x:.5,y:.5}),u=Math.min(Math.max(p.x,0),1),v=Math.min(Math.max(p.y,0),1);return{x:s+c*u,y:d+f*v}}if(typeof window!="undefined"){let e=window.innerWidth,t=window.innerHeight,n=()=>{let i=window.innerWidth,r=window.innerHeight;(i!==e||r!==t)&&(e=i,t=r,ka(i,r))};window.addEventListener("resize",n),window.addEventListener("orientationchange",()=>{setTimeout(n,100)}),window.mraid&&(window.mraid.addEventListener("viewableChange",n),window.mraid.addEventListener("sizeChange",n)),ka(window.innerWidth,window.innerHeight),window.updateDebugConfig=um,window.getDebugConfig=pm,window.copyConfig=Sm,window.applyConfig=Gn,window.applyConfigForRatio=Am,window.positionAtBottom=Qc,window.positionAtTop=mm,window.positionAtCenter=bm,window.positionAtLeft=ym,window.positionAtRight=vm,window.positionAtBottomLeft=xm,window.positionAtBottomRight=wm,window.positionAtTopLeft=_m,window.positionAtTopRight=Em,window.applyPositionContract=gm,console.log("\u{1F3AE} Debug Config Functions Available:"),console.log("\u2022 updateDebugConfig(category, key, value)"),console.log("\u2022 getDebugConfig()"),console.log("\u2022 copyConfig(presetName)"),console.log("\u2022 applyConfig(config)"),console.log("\u2022 applyConfigForRatio(width, height)"),console.log("\u{1F4CD} Positioning Helpers Available (with scale):"),console.log("\u2022 positionAtBottom(element, w, h, percent, scale)"),console.log("\u2022 positionAtTop(element, w, h, percent, scale)"),console.log("\u2022 positionAtCenter(element, w, h, offsetX, offsetY, scale)"),console.log("\u2022 positionAtLeft/Right(element, w, h, percent, scale)"),console.log("\u2022 Corner positions: BottomLeft/Right, TopLeft/Right (all with scale)"),console.log("\u2022 applyPositionContract(element, w, h, contract)"),console.log("Example: positionAtCenter(mySprite, 400, 600, 0, -50, 1.2)")}function Qi(e,t,n=0){return e*t+n}function er(e,t,n=0){return e*(1-t)+n}function tr(e,t,n=0){return e*t+n}function nr(e,t,n=0){return e*(1-t)+n}function ge(e,t=0){return e/2+t}function hm(e,t){return e*t}function gm(e,t,n,i){var s,o,d,l,c,f,p,u,v,h,w,y,m,b,g,x,E,A,C,T;let r=0,a=0;switch(i.type){case"top":r=ge(t,(o=(s=i.offset)==null?void 0:s.x)!=null?o:0),a=Qi(n,i.percent,(l=(d=i.offset)==null?void 0:d.y)!=null?l:0);break;case"bottom":r=ge(t,(f=(c=i.offset)==null?void 0:c.x)!=null?f:0),a=er(n,i.percent,(u=(p=i.offset)==null?void 0:p.y)!=null?u:0);break;case"left":r=tr(t,i.percent,(h=(v=i.offset)==null?void 0:v.x)!=null?h:0),a=ge(n,(y=(w=i.offset)==null?void 0:w.y)!=null?y:0);break;case"right":r=nr(t,i.percent,(b=(m=i.offset)==null?void 0:m.x)!=null?b:0),a=ge(n,(x=(g=i.offset)==null?void 0:g.y)!=null?x:0);break;case"center":r=ge(t,(A=(E=i.offset)==null?void 0:E.x)!=null?A:0),a=ge(n,(T=(C=i.offset)==null?void 0:C.y)!=null?T:0);break}e.position?e.position.set(r,a):(e.x=r,e.y=a),i.scale!==void 0&&i.scale!==1&&e.scale&&(typeof e.scale.set=="function"?e.scale.set(i.scale,i.scale):(e.scale.x=i.scale,e.scale.y=i.scale))}function Qc(e,t,n,i=.2,r=1,a=!0,s=!1){let o=hm(n,i),d=er(n,i/2);Ke(e,ge(t),d);let l=a?r*Xe.scaleFactor:r;Ze(e,l),s&&!La.find(c=>c.element===e)&&cm(e,Qc,t,n,i,r,a)}function mm(e,t,n,i=.1,r=1){Ke(e,ge(t),Qi(n,i)),Ze(e,r)}function bm(e,t,n,i=0,r=0,a=1){Ke(e,ge(t,i),ge(n,r)),Ze(e,a)}function ym(e,t,n,i=.1,r=1){Ke(e,tr(t,i),ge(n)),Ze(e,r)}function vm(e,t,n,i=.1,r=1){Ke(e,nr(t,i),ge(n)),Ze(e,r)}function xm(e,t,n,i=.05,r=.05,a=1){Ke(e,tr(t,r),er(n,i)),Ze(e,a)}function wm(e,t,n,i=.05,r=.05,a=1){Ke(e,nr(t,r),er(n,i)),Ze(e,a)}function _m(e,t,n,i=.05,r=.05,a=1){Ke(e,tr(t,r),Qi(n,i)),Ze(e,a)}function Em(e,t,n,i=.05,r=.05,a=1){Ke(e,nr(t,r),Qi(n,i)),Ze(e,a)}function Ke(e,t,n){e&&e.position?typeof e.position.set=="function"?e.position.set(t,n):(e.position.x=t,e.position.y=n):e&&(e.x=t,e.y=n)}function Ze(e,t){t!==1&&e&&e.scale&&(typeof e.scale.set=="function"?e.scale.set(t,t):e.scale.x!==void 0&&e.scale.y!==void 0&&(e.scale.x=t,e.scale.y=t))}var Ot={default:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:1,screen_scale_y:1},engine:{scale:1,background_scale:1.05,background_offset_y:0,background_alpha:.98,label_pulse_speed:3,label_pulse_intensity:.03}},wide:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:.9,screen_scale_y:1.1},engine:{scale:1,background_scale:1.1,background_offset_y:0,background_alpha:.95,label_pulse_speed:3,label_pulse_intensity:.03}},square:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:.85,screen_scale_y:.85},engine:{scale:1,background_scale:1,background_offset_y:0,background_alpha:1,label_pulse_speed:3,label_pulse_intensity:.03}},tall:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:1.1,screen_scale_y:.9},engine:{scale:1,background_scale:.95,background_offset_y:0,background_alpha:1,label_pulse_speed:3,label_pulse_intensity:.03}}};function Sm(e){return e&&Ot[e]?JSON.parse(JSON.stringify(Ot[e])):JSON.parse(JSON.stringify(Wn))}function Gn(e){Object.keys(e).forEach(t=>{let n=t;Wn[n]&&e[n]&&Object.assign(Wn[n],e[n])}),console.log("Config applied:",e)}function Am(e,t){let n=e/t;n>1.6?(Gn(Ot.wide),console.log("Applied WIDE config for ratio:",n)):n<.7?(Gn(Ot.tall),console.log("Applied TALL config for ratio:",n)):n>.8&&n<1.2?(Gn(Ot.square),console.log("Applied SQUARE config for ratio:",n)):(Gn(Ot.default),console.log("Applied DEFAULT config for ratio:",n))}if(typeof window!="undefined"){let e=window;e.configPresets=Ot,e.resolveAnchorVec2=e.resolveAnchorVec2||Ji,e.resolveScreenAnchorPoint=e.resolveScreenAnchorPoint||Zc,e.resolveScreenRatioPoint=e.resolveScreenRatioPoint||Jc}Oa();function G(e,t){let n=(r,a)=>a===0?r:n(a,r%a),i=n(e,t);return`${e/i}:${t/i}`}var N_=[{id:"iphone-15-pro-max",label:"iPhone 15 Pro Max",width:430,height:932,category:"iphone",ratio:G(430,932)},{id:"iphone-15-pro",label:"iPhone 15 Pro",width:393,height:852,category:"iphone",ratio:G(393,852)},{id:"iphone-15",label:"iPhone 15",width:393,height:852,category:"iphone",ratio:G(393,852)},{id:"iphone-14",label:"iPhone 14",width:390,height:844,category:"iphone",ratio:G(390,844)},{id:"iphone-se",label:"iPhone SE",width:375,height:667,category:"iphone",ratio:G(375,667)},{id:"iphone-12-mini",label:"iPhone 12 Mini",width:360,height:780,category:"iphone",ratio:G(360,780)}],H_=[{id:"pixel-8-pro",label:"Pixel 8 Pro",width:448,height:998,category:"android",ratio:G(448,998)},{id:"pixel-8",label:"Pixel 8",width:412,height:915,category:"android",ratio:G(412,915)},{id:"samsung-s24-ultra",label:"Samsung S24 Ultra",width:412,height:915,category:"android",ratio:G(412,915)},{id:"samsung-s24",label:"Samsung S24",width:360,height:780,category:"android",ratio:G(360,780)},{id:"samsung-a54",label:"Samsung A54",width:412,height:915,category:"android",ratio:G(412,915)},{id:"oneplus-12",label:"OnePlus 12",width:412,height:915,category:"android",ratio:G(412,915)}],$_=[{id:"ipad-pro-12",label:'iPad Pro 12.9"',width:1024,height:1366,category:"tablet",ratio:G(1024,1366)},{id:"ipad-pro-11",label:'iPad Pro 11"',width:834,height:1194,category:"tablet",ratio:G(834,1194)},{id:"ipad-air",label:"iPad Air",width:820,height:1180,category:"tablet",ratio:G(820,1180)},{id:"ipad-mini",label:"iPad Mini",width:768,height:1024,category:"tablet",ratio:G(768,1024)},{id:"samsung-tab-s9",label:"Samsung Tab S9",width:800,height:1280,category:"tablet",ratio:G(800,1280)}],id=[{id:"playable-portrait",label:"Playable Portrait",width:320,height:480,category:"playable",ratio:"2:3",mraidScale:1},{id:"mraid-320x480",label:"MRAID 320\xD7480",width:320,height:480,category:"playable",ratio:"2:3",mraidScale:1},{id:"iphone-14",label:"iPhone 14",width:390,height:844,category:"playable",ratio:G(390,844),mraidScale:.7},{id:"ipad-mini",label:"iPad Mini",width:768,height:1024,category:"playable",ratio:G(768,1024),mraidScale:.7}];var U_=[...id];var Im=id[0];pt();var y0=Ge(mh(),1);function g0(e){return new Promise((t,n)=>{let i=new FileReader;i.onerror=()=>n(new Error("FileReader failed")),i.onload=()=>t(String(i.result||"")),i.readAsDataURL(e)})}function m0(e){var r;let[t,n]=e.split(","),i=t==null?void 0:t.match(/data:(.*?);base64/);return{base64:n!=null?n:"",mimeType:(r=i==null?void 0:i[1])!=null?r:"image/png"}}async function b0(e){return await new Promise(t=>{let n=new Image;n.onload=()=>t({width:n.naturalWidth||n.width,height:n.naturalHeight||n.height}),n.onerror=()=>t(null),n.src=e})}async function Eo(e){var t,n;try{console.log("[ImageUtils] Fetching image data from URL:",e);let i=await fetch(e);if(!i.ok)return console.warn("[ImageUtils] Fetch failed with status:",i.status,e),null;let r=await i.blob();console.log("[ImageUtils] Blob received, size:",r.size,"type:",r.type);let a=await g0(r),s=await b0(a),o=m0(a);return console.log("[ImageUtils] Success resolution:",s==null?void 0:s.width,"x",s==null?void 0:s.height,"mime:",o.mimeType),{base64:o.base64,mimeType:o.mimeType,dataUrl:a,width:(t=s==null?void 0:s.width)!=null?t:0,height:(n=s==null?void 0:s.height)!=null?n:0}}catch(i){return console.error("[ImageUtils] Error fetching image data:",i),null}}async function Vr(e,t=30){try{console.log("[ImageUtils] Removing background color...");let n=await new Promise((f,p)=>{let u=new Image;u.onload=()=>f(u),u.onerror=()=>p(new Error("Failed to load image")),u.src=e}),i=document.createElement("canvas");i.width=n.width,i.height=n.height;let r=i.getContext("2d");if(!r)return console.error("[ImageUtils] Failed to get canvas context"),e;r.drawImage(n,0,0);let a=r.getImageData(0,0,i.width,i.height),s=a.data,d=[{name:"top-left",offset:0},{name:"top-right",offset:(i.width-1)*4},{name:"bottom-left",offset:(i.height-1)*i.width*4},{name:"bottom-right",offset:((i.height-1)*i.width+(i.width-1))*4}].map(f=>({r:s[f.offset],g:s[f.offset+1],b:s[f.offset+2]})),l=0;for(let f=0;f<s.length;f+=4){let p=s[f],u=s[f+1],v=s[f+2],h=!1;for(let w of d)if(Math.sqrt(Math.pow(p-w.r,2)+Math.pow(u-w.g,2)+Math.pow(v-w.b,2))<t){h=!0;break}h&&(s[f+3]=0,l++)}return console.log(`[ImageUtils] Removed background from ${l} pixels (4-corner sampling, tolerance: ${t})`),r.putImageData(a,0,0),i.toDataURL("image/png")}catch(n){return console.error("[ImageUtils] Error removing background:",n),e}}var bh=require("@google/genai");async function So(e,t,n=[],i={}){var r,a,s,o,d,l,c;try{if(!(e!=null&&e.trim()))throw new Error("Gemini API key is required");if(!(t!=null&&t.trim()))throw new Error("Prompt is required");for(let y=0;y<n.length;y++){let m=n[y];if(!m.base64||!m.mimeType)throw new Error(`Image ${y+1} is missing required data`);if(m.base64.length<1e3&&console.warn(`Image ${y+1} data appears very small, may be corrupted`),!m.mimeType.startsWith("image/"))throw new Error(`Image ${y+1} has invalid MIME type: ${m.mimeType}`)}let f=new bh.GoogleGenAI({apiKey:e}),p="gemini-2.5-flash",u=[t];n.length>0&&n.forEach((y,m)=>{u.push({inlineData:{data:y.base64,mimeType:y.mimeType}}),console.log(`[Gemini] Added image ${m+1}: ${y.mimeType}, size: ${Math.round(y.base64.length/1024)}KB`)}),console.log(`[Gemini] Making request with ${n.length} images and prompt length: ${t.length}`);let v=await f.models.generateContent({model:p,contents:u}),h="",w=(s=(a=(r=v.candidates)==null?void 0:r[0])==null?void 0:a.content)==null?void 0:s.parts;if(w)for(let y of w)y.text&&(h+=y.text);if(!h.trim())throw new Error("Empty response from Gemini API");return console.log(`[Gemini] Response received, length: ${h.length}`),h}catch(f){throw console.error("[Gemini] API error:",f),(o=f.message)!=null&&o.includes("Unable to process input image")?new Error("Unable to process the uploaded image. Please ensure it's a valid PNG, JPG, or JPEG file under 10MB and not corrupted."):(d=f.message)!=null&&d.includes("API_KEY_INVALID")?new Error("Invalid Gemini API key. Please check your API key configuration."):(l=f.message)!=null&&l.includes("QUOTA_EXCEEDED")?new Error("Gemini API quota exceeded. Please try again later or check your billing."):(c=f.message)!=null&&c.includes("SAFETY")?new Error("Content was flagged by Gemini safety filters. Please try with different images."):f}}var yh=require("@google/genai");async function Xr(e,t,n=[],i={}){try{console.info("[GEMINI-REAL-SDK] Initializing GoogleGenAI...");let r=new yh.GoogleGenAI({apiKey:e}),a=[{text:t}];n.length>0&&n.forEach((o,d)=>{console.info(`[GEMINI-REAL-SDK] Adding image part ${d}`),a.push({inlineData:{mimeType:o.mimeType,data:o.base64}})}),console.info("[GEMINI-REAL-SDK] Calling generateContent with model: gemini-2.5-flash-image");let s=await r.models.generateContent({model:"gemini-2.5-flash-image",contents:a});if(console.info("[GEMINI-REAL-SDK] Received response from model"),!s.candidates||!s.candidates[0]||!s.candidates[0].content||!s.candidates[0].content.parts)throw new Error("Gemini 2.5 Flash Image returned invalid response structure.");for(let o of s.candidates[0].content.parts)if(o.text)console.log(o.text);else if(o.inlineData){let d=o.inlineData.data,l=o.inlineData.mimeType||"image/png";return console.info("[GEMINI-REAL-SDK] Found inline image data in response"),`data:${l};base64,${d}`}throw new Error("Gemini 2.5 Flash Image returned no image data.")}catch(r){throw console.error("[GEMINI-REAL-SDK] Error in generateImageWithGemini25Flash:",JSON.stringify(r,Object.getOwnPropertyNames(r),2)),r}}var v0=require("pixi.js");qn();pt();var xh=require("pixi.js");var x0=require("pixi.js");pt();function T0(e){return new Promise((t,n)=>{let i=new FileReader;i.onerror=()=>n(new Error("FileReader failed")),i.onload=()=>t(String(i.result||"")),i.readAsDataURL(e)})}function k0(e){var r;let[t,n]=e.split(","),i=t==null?void 0:t.match(/data:(.*?);base64/);return{base64:n!=null?n:"",mimeType:(r=i==null?void 0:i[1])!=null?r:"image/png"}}function L0(e){return`
47
+ `,this.modal=i}attachModalListeners(){if(!this.modal)return;this.modal.querySelectorAll("[data-modal-close]").forEach(s=>{s.addEventListener("click",()=>this.close())}),this.modal.querySelectorAll("[data-tab]").forEach(s=>{s.addEventListener("click",o=>{let l=o.target.dataset.tab;l&&this.switchTab(l)})});let i=this.modal.querySelector("[data-ai-generate]");i==null||i.addEventListener("click",()=>{this.openAiEditor("generate")});let r=this.modal.querySelector("[data-ai-edit]");r==null||r.addEventListener("click",()=>{this.openAiEditor("edit")});let a=this.modal.querySelector("[data-modal-apply]");a==null||a.addEventListener("click",()=>{this.apply()}),this.modal.addEventListener("click",s=>{s.target===this.modal&&this.close()})}switchTab(t){if(!this.modal)return;this.modal.querySelectorAll("[data-tab]").forEach(r=>{r.classList.toggle("active",r.getAttribute("data-tab")===t)}),this.modal.querySelectorAll("[data-tab-panel]").forEach(r=>{r.classList.toggle("active",r.getAttribute("data-tab-panel")===t)})}openAiEditor(t){let n=window.__openAiEditor;if(typeof n!="function"){alert("AI Editor not available. Please check your setup.");return}let i="";t==="edit"&&this.currentAsset?i=`Edit this image: ${this.currentObjectId}`:i=`Create an image for: ${this.currentObjectId}`,n(this.currentObjectId||"unknown",i,this.currentAsset,{path:this.currentPath,onApply:r=>{this.onApplyCallback&&this.onApplyCallback(r),this.close()}})}apply(){this.onApplyCallback&&this.onApplyCallback("library/placeholder.png"),this.close()}close(){this.modal&&this.modal.parentNode&&this.modal.parentNode.removeChild(this.modal),this.modal=null,this.currentObjectId=null,this.currentPath=null,this.onApplyCallback=null}}});var V0={};hc(V0,{AspectClass:()=>$o,GameObject:()=>Di,GameObjectManager:()=>na,Renderer:()=>ji,ResponsiveUISystem:()=>zn,Transform:()=>Pi,animateHandClick:()=>Hh,animatePanelEntrance:()=>Nh,createBrushTexture:()=>Vh,createEndGamePanel:()=>Bh,createHandTutorial:()=>$h,createThreeBase:()=>Dh,createTutorialLabel:()=>Uh,getAspectClass:()=>ta,getRegisteredFontIds:()=>Fh,loadAsset:()=>Go,loadCharacterFrames:()=>Yh,registerFont:()=>zh,resolveFont:()=>Fe,resolveFontWeight:()=>Be,updateHandAnimation:()=>qh});module.exports=Hg(V0);var Te=Ge(require("three"),1);var dt={};function qi(e,t,n=!1){dt[e]||(dt[e]=[]),dt[e].push({fn:t,once:n})}function ga(e,t){if(dt[e]){if(!t){delete dt[e];return}dt[e]=dt[e].filter(n=>n.fn!==t)}}function Gi(e,...t){let n=dt[e];if(n)for(let i of[...n])i.fn(...t),i.once&&ga(e,i.fn)}function fe(e,t){qi(e,t,!0)}var q=null,we=[],Zt=null;function yc(e){q=e,we=[],Zt!==null&&(clearTimeout(Zt),Zt=null)}function vc(){var e,t,n;return{endpoint:(q==null?void 0:q.endpoint)||"",transport:(q==null?void 0:q.transport)||"beacon",batchSize:(e=q==null?void 0:q.batchSize)!=null?e:10,flushIntervalMs:(t=q==null?void 0:q.flushIntervalMs)!=null?t:300,maxQueue:(n=q==null?void 0:q.maxQueue)!=null?n:200,debug:!!(q!=null&&q.debug)}}async function mc(e,t,n,i){let r=JSON.stringify(t);if(n==="beacon"&&typeof navigator!="undefined"&&typeof navigator.sendBeacon=="function")try{let a=navigator.sendBeacon(e,new Blob([r],{type:"application/json"}));i&&console.log("[handler.telemetry] beacon",a,t);return}catch(a){i&&console.warn("[handler.telemetry] beacon failed, fallback to fetch",a)}try{await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:r,keepalive:!0}),i&&console.log("[handler.telemetry] fetch",t)}catch(a){i&&console.warn("[handler.telemetry] fetch failed",a)}}function ma(e,t){let n=vc();if(t&&n.endpoint){if(we.push(e),we.length>n.maxQueue&&(we=we.slice(we.length-n.maxQueue)),we.length>=n.batchSize){bc();return}Zt===null&&(Zt=window.setTimeout(()=>{Zt=null,bc()},n.flushIntervalMs))}}async function bc(){let e=vc();if(!e.endpoint||we.length===0)return;let t=we.splice(0,e.batchSize);await mc(e.endpoint,{events:t},e.transport,e.debug),we.length>0&&await mc(e.endpoint,{events:we.splice(0,e.batchSize)},e.transport,e.debug)}function xc(e){return Math.max(0,Math.min(1,e))}function $g(e){let t=String(e!=null?e:"power2.out");if(t==="linear")return n=>n;if(t==="sine.inOut")return n=>.5-Math.cos(Math.PI*n)/2;if(t==="power2.out"||t==="easeOutQuad")return n=>1-(1-n)*(1-n);if(t.startsWith("back.out")){let n=t.match(/back\.out\(([\d.]+)\)/),i=n?Number(n[1]):1.8;return r=>1+(i+1)*Math.pow(r-1,3)+i*Math.pow(r-1,2)}return n=>1-(1-n)*(1-n)}function Hn(){return typeof performance!="undefined"&&performance.now?performance.now():Date.now()}function Ug(e,t){let n=e==null?void 0:e[t];return typeof n=="number"?n:0}function wc(e,t,n){try{e[t]=n}catch{}}function qg(e){let t=e==null?void 0:e.scale;if(!t)return null;let n=typeof t.x=="number"?t.x:1,i=typeof t.y=="number"?t.y:1;return{x:n,y:i}}function _c(e,t){let n=e==null?void 0:e.scale;if(n)try{typeof n.set=="function"?n.set(t.x,t.y):(typeof n.x=="number"&&(n.x=t.x),typeof n.y=="number"&&(n.y=t.y))}catch{}}function Ec(e,t){let n=qg(e);if(!n)return{from:null,to:null};let i=null,r=null;return typeof t.scale=="number"?(i=t.scale,r=t.scale):t.scale&&typeof t.scale=="object"&&(typeof t.scale.x=="number"&&(i=t.scale.x),typeof t.scale.y=="number"&&(r=t.scale.y)),typeof t.scaleX=="number"&&(i=t.scaleX),typeof t.scaleY=="number"&&(r=t.scaleY),i===null&&r===null?{from:null,to:null}:{from:{x:n.x,y:n.y},to:{x:i!=null?i:n.x,y:r!=null?r:n.y}}}function Sc(){let e=new Set,t=new WeakMap,n=null,i=()=>{if(n!=null)return;n=requestAnimationFrame(()=>{n=null,o(),e.size>0&&i()})},r=c=>{var p;e.add(c);let f=(p=t.get(c.target))!=null?p:new Set;f.add(c),t.set(c.target,f),i()},a=c=>{e.delete(c);let f=t.get(c.target);f&&(f.delete(c),f.size===0&&t.delete(c.target))},s=c=>{c.killed||(c.killed=!0,a(c))},o=()=>{var f,p;let c=Hn();for(let u of Array.from(e)){if(u.killed||u.paused)continue;let v=c-u.startMs-u.delayMs;if(v<0)continue;let h=u.durationMs>0?v/u.durationMs:1,w=xc(h),y=u.repeat>=0?u.repeat+1:1,m=u.repeat>0?Math.min(Math.floor(h),y-1):0;if(u.repeat>0&&h>=1){let x=h-m;w=xc(x)}let b=u.ease(w);u.yoyo&&m%2===1&&(b=1-b);for(let x of u.props)wc(u.target,x.key,x.from+(x.to-x.from)*b);u.scaleFrom&&u.scaleTo&&_c(u.target,{x:u.scaleFrom.x+(u.scaleTo.x-u.scaleFrom.x)*b,y:u.scaleFrom.y+(u.scaleTo.y-u.scaleFrom.y)*b});try{(f=u.onUpdate)==null||f.call(u)}catch{}if(h>=y){s(u);try{(p=u.onComplete)==null||p.call(u)}catch{}}}},d=(c,f,p)=>{var x;let u=Math.max(0,(typeof f.duration=="number"?f.duration:.5)*1e3),v=Math.max(0,(typeof f.delay=="number"?f.delay:0)*1e3+((x=p==null?void 0:p.delayMsOverride)!=null?x:0)),h=$g(f.ease),w=typeof f.repeat=="number"?Math.max(0,f.repeat|0):0,y=f.yoyo===!0,m=new Set(["duration","delay","ease","repeat","yoyo","onUpdate","onComplete","scale","scaleX","scaleY"]),b=[];for(let E of Object.keys(f)){if(m.has(E))continue;let A=f[E];typeof A=="number"&&b.push({key:E,from:Ug(c,E),to:A})}let g=Ec(c,f);return{target:c,startMs:Hn(),delayMs:v,durationMs:u,ease:h,props:b,scaleFrom:g.from,scaleTo:g.to,repeat:w,yoyo:y,onUpdate:typeof f.onUpdate=="function"?f.onUpdate:void 0,onComplete:typeof f.onComplete=="function"?f.onComplete:void 0,killed:!1,paused:!1,pauseAtMs:null}},l={to(c,f){let p=d(c,f);return r(p),{kill:()=>s(p),pause:()=>{p.paused||(p.paused=!0,p.pauseAtMs=Hn())},resume:()=>{var h;if(!p.paused)return;let u=(h=p.pauseAtMs)!=null?h:Hn(),v=Hn()-u;p.startMs+=v,p.paused=!1,p.pauseAtMs=null},isActive:()=>!p.killed&&!p.paused}},fromTo(c,f,p){return l.set(c,f),l.to(c,p)},set(c,f){if(!c||!f)return;for(let u of Object.keys(f)){let v=f[u];u==="scale"||u==="scaleX"||u==="scaleY"||typeof v=="number"&&wc(c,u,v)}let p=Ec(c,f);p.to&&_c(c,p.to)},killTweensOf(c){let f=t.get(c);if(f)for(let p of Array.from(f))s(p)},timeline(c={}){let f=[],p=0,u=!1,v=[],h=m=>{if(typeof m=="number")return Math.max(0,m*1e3);let b=typeof m=="string"?m.trim():"";return b.startsWith("+=")?p+Math.max(0,Number(b.slice(2))*1e3||0):b?Math.max(0,Number(b)*1e3||0):p},w=m=>{f.push(m);let b=Math.max(0,(typeof m.vars.duration=="number"?m.vars.duration:.5)*1e3);p=Math.max(p,m.atMs+b)},y={to(m,b,g){return w({kind:"to",target:m,vars:b,atMs:h(g)}),y},fromTo(m,b,g,x){return w({kind:"fromTo",target:m,vars:g,from:b,atMs:h(x)}),y},play(){var m,b;if(u)return y;u=!0,v=[];for(let g of f)g.kind==="fromTo"&&l.set(g.target,(m=g.from)!=null?m:{}),v.push(l.to(g.target,{...g.vars,delay:g.atMs/1e3+((b=g.vars.delay)!=null?b:0)}));return y},pause(){for(let m of v)m.pause();return y},kill(){for(let m of v)m.kill();v=[],u=!1}};return c.paused||y.play(),y}};return l}function Ac(){if(typeof window=="undefined")return;let e=window;if(!e.gsap)try{e.gsap=Sc()}catch{}}var Cc={name:"handler-playable-sdk",version:"0.3.34",type:"module",description:"Handler Playable SDK v0.1 with contract-aligned surface (root sandbox, canonical event envelope).",main:"dist/index.cjs",module:"dist/index.js",types:"dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"},"./pixi":{types:"./dist/pixi/index.d.ts",import:"./dist/pixi/index.js",require:"./dist/pixi/index.cjs"},"./pixi/index.css":{import:"./dist/pixi/index.css",require:"./dist/pixi/index.css"},"./three":{types:"./dist/three/index.d.ts",import:"./dist/three/index.js",require:"./dist/three/index.cjs"},"./cli":{types:"./dist/cli/index.d.ts",import:"./dist/cli/index.js",require:"./dist/cli/index.cjs"}},bin:{"handler-student-helper":"./bin/student-helper.mjs","handler-validate":"./bin/validate.mjs","handler-sync-screens":"./bin/sync-screens.mjs","handler-brand-dna":"./bin/brand-dna.mjs","handler-setup-library":"./bin/setup-library.mjs","handler-screen-helper":"./bin/screen-helper.mjs"},scripts:{prebuild:"python3 src/preview/build-css.py",build:"tsup src/index.ts src/pixi/index.ts src/three/index.ts src/cli/index.ts --format cjs,esm --dts --clean --minify --external lottie-web && npm run create-mjs-symlinks && npm run postbuild-cli && npm run obfuscate && npm run postbuild",postbuild:"python3 src/preview/copy-css-to-dist.py","postbuild-cli":"cp src/cli/*.mjs dist/cli/ && chmod +x dist/cli/*.mjs && chmod +x bin/*.mjs","create-mjs-symlinks":"cd dist && ln -sf index.js index.mjs && cd pixi && ln -sf index.js index.mjs && cd ../three && ln -sf index.js index.mjs","build:dev":"tsup src/index.ts src/pixi/index.ts src/three/index.ts src/cli/index.ts --format cjs,esm --dts --clean --external lottie-web && npm run create-mjs-symlinks && npm run postbuild-cli",obfuscate:"javascript-obfuscator dist/pixi/index.js --output dist/pixi/index.js --config obfuscator.config.json && javascript-obfuscator dist/three/index.js --output dist/three/index.js --config obfuscator.config.json && javascript-obfuscator dist/cli/index.js --output dist/cli/index.js --config obfuscator.config.json && npm run obfuscate-cli","obfuscate-cli":'for file in dist/cli/*.mjs; do javascript-obfuscator "$file" --output "$file" --config obfuscator.config.json; done',lint:"eslint 'src/**/*.{ts,tsx}'",typecheck:"tsc --noEmit",prepublishOnly:"npm run build","publish:update":"node scripts/publish-and-update.cjs patch","publish:update:minor":"node scripts/publish-and-update.cjs minor","publish:update:major":"node scripts/publish-and-update.cjs major"},author:"Handler",license:"MIT",publishConfig:{access:"public"},repository:{type:"git",url:"https://github.com/HandlerAIGames/handler-playable-sdk.git"},files:["dist","bin","LICENSE","README.md"],peerDependencies:{"lottie-web":"^5.0.0","pixi.js":"^8.0.0",three:"^0.182.0"},peerDependenciesMeta:{"pixi.js":{optional:!0},three:{optional:!0},"lottie-web":{optional:!0}},devDependencies:{"@types/three":"^0.182.0",eslint:"^9.39.2","javascript-obfuscator":"^5.1.0","pixi.js":"8.8.1",three:"^0.182.0","ts-node":"^10.9.2",tsup:"^8.4.0",typescript:"^5.7.2","typescript-eslint":"^8.53.0"},dependencies:{"@google/genai":"^1.35.0","@google/generative-ai":"^0.24.1",sharp:"^0.34.5"}};var he=0,Wg=he++,Tc=he++,kc=he++,Lc=he++,Rc=he++,Mc=he++,Oc=he++,Ic=he++,Pc=he++,jc=he++,Dc=he++,zc=he++,N=Wg;function Fc(){return N===Tc}function Bc(){return N===kc}function Nc(){return N===Lc}function Hc(){return N===Rc}function Jt(){return N===Mc}function Qt(){return N===Oc}function $c(){return N===Ic}function Uc(){return N===Pc}function qc(){return N===jc}function ba(){return N===Dc}function ya(){return N===zc}function Gc(){let e=typeof AD_PROTOCOL!="undefined"?AD_PROTOCOL:"none",t=typeof AD_NETWORK!="undefined"?AD_NETWORK:"web_embed";if(e==="mraid")try{mraid.getState(),N=Tc;return}catch{}else if(e==="dapi")try{dapi.isReady(),N=kc;return}catch{}if(t==="facebook")try{typeof FbPlayableAd!="undefined"&&(N=Lc)}catch{}else if(t==="google")try{typeof ExitApi!="undefined"&&(N=Rc)}catch{}else if(t==="mintegral")window.gameReady&&(N=Mc);else if(t==="tapjoy")window.TJ_API&&(N=Oc);else if(t==="tiktok")window.openAppStore&&(N=Ic);else if(t==="smadex")try{window.smxTracking&&(N=Pc)}catch{}else if(t==="snapchat")try{window.ScPlayableAd&&(N=jc)}catch{}else t==="vungle"?N=Dc:(e==="nucleo"||t==="nucleo")&&(N=zc)}var Wi=Ge(require("lottie-web"),1),Wc=Wi.default;typeof window!="undefined"&&(window.lottie=Wi.default,window.__baseLottie=Wi.default);var Yg=require("pixi.js");var va=require("pixi.js");var Vg=null;function xa(e){Vg=e}Yi();wa();var $n=require("pixi.js");Yi();var em=typeof __BUILD_MODE__!="undefined"?__BUILD_MODE__:"undefined",Aa=em;if(typeof window!="undefined")try{let e=new XMLHttpRequest;if(e.open("GET","./build-settings.json",!1),e.send(),e.status===200&&e.responseText){let t=JSON.parse(e.responseText);t!=null&&t.buildMode&&(Aa=t.buildMode,console.log(`[ObjectFactory] Build mode overridden by settings: ${Aa}`))}}catch{}var Mt=class{static async create(t,n,i){var d,l,c,f,p,u,v;console.log(`[ObjectFactory] create() called for: ${t}, __BUILD_MODE__: ${Aa}`);let r=(d=n==null?void 0:n.render)==null?void 0:d.asset;if(!r){console.log(`[ObjectFactory] No asset definition for: ${t}, returning empty container`);let h=new $n.Container;return this.applyTransform(h,n==null?void 0:n.transform),h}let a=(l=n==null?void 0:n.identity)==null?void 0:l.id;console.log(`[ObjectFactory] Calling AssetLoader.load() for: ${t}, configId: ${a}, type: ${r.type}, path: ${r.path}`);let s=await Rt.load(t,r,i,a);console.log(`[ObjectFactory] AssetLoader.load() completed for: ${t}, rawAsset type: ${(c=s==null?void 0:s.constructor)==null?void 0:c.name}`);let o;if(r.type==="image")console.log("[ObjectFactory] Creating Sprite from texture:",s,"for object:",t),o=new $n.Sprite(s),console.log("[ObjectFactory] Created object:",o,"type:",(f=o==null?void 0:o.constructor)==null?void 0:f.name),this.applyTransform(o,n==null?void 0:n.transform);else if(r.type==="json")if(console.log("[ObjectFactory] JSON asset for",t,"rawAsset type:",(p=s==null?void 0:s.constructor)==null?void 0:p.name,s),s&&(((u=s.constructor)==null?void 0:u.name)==="Container"||s instanceof $n.Container)){console.warn("[ObjectFactory] JSON asset is Container (from cache), reloading JSON directly");let h=[r.path,`/assets/${r.path}`,`assets/${r.path}`,`../assets/${r.path}`],w=!1;for(let y of h)try{let m=await fetch(y);if(m.ok){o=await m.json(),console.log("[ObjectFactory] Reloaded JSON directly from:",y,"type:",(v=o==null?void 0:o.constructor)==null?void 0:v.name),w=!0;break}}catch{continue}w||(console.error("[ObjectFactory] Failed to reload JSON from any path"),o=s)}else o=s;else o=s,o&&typeof o=="object"&&("x"in o||"position"in o)&&this.applyTransform(o,n==null?void 0:n.transform);return o}static applyTransform(t,n){var i,r,a,s;!n||!t||(n.position&&("x"in t&&"y"in t?(t.x=(i=n.position.x)!=null?i:0,t.y=(r=n.position.y)!=null?r:0):"position"in t&&t.position&&t.position.set((a=n.position.x)!=null?a:0,(s=n.position.y)!=null?s:0)),n.scale!==void 0&&"scale"in t&&t.scale&&(typeof t.scale=="object"&&"set"in t.scale?t.scale.set(n.scale):t.scale=n.scale),n.rotation!==void 0&&"rotation"in t&&(t.rotation=n.rotation),n.anchor&&"anchor"in t&&t.anchor&&Array.isArray(n.anchor)&&("set"in t.anchor?t.anchor.set(n.anchor[0],n.anchor[1]):(t.anchor.x=n.anchor[0],t.anchor.y=n.anchor[1])))}};var Un=class{constructor(){this.config=null}init(t){this.config=t}get(t){if(!this.config)throw new Error("RuntimeObjectRegistry not initialized. Call init() first.");return this.config.objects.get(t)}getAllIds(){if(!this.config)throw new Error("RuntimeObjectRegistry not initialized. Call init() first.");return Array.from(this.config.objects.keys())}has(t){return this.config?this.config.objects.has(t):!1}};var im=Ge(require("pixi.js"),1);typeof window!="undefined"&&(window.__basePixi=im);qn();var Xi=require("pixi.js");qn();var Ta=class{constructor(){this.instanceCache=new Map;this.readyPromise=null;this.app=null;this.registry=new Un}init(t,n){this.registry.init(t),this.app=n}updateConfig(t){this.registry.init(t),this.instanceCache.clear(),this.readyPromise=null}async ready(){this.readyPromise&&await this.readyPromise;let n=this.registry.getAllIds().filter(r=>!this.instanceCache.has(r));if(n.length===0)return;let i=async r=>{r.length&&(console.log("[Assets] Loading objects:",r),await Promise.all(r.map(async a=>{var o;let s=this.registry.get(a);if(!s){console.warn("[Assets] No config found for object:",a);return}try{let d=await Mt.create(a,s,this.app);this.instanceCache.set(a,d),console.log("[Assets] Loaded object:",a,(o=d==null?void 0:d.constructor)==null?void 0:o.name)}catch(d){console.error("[Assets] Failed to load object:",a,d)}})))};return this.readyPromise=(async()=>{await i(n);let r=this.registry.getAllIds().filter(a=>!this.instanceCache.has(a));r.length>0&&(console.warn("[Assets] Retrying missing assets:",r),await i(r)),console.log("[Assets] Ready. Cached objects:",Array.from(this.instanceCache.keys()))})(),this.readyPromise}resetScene(){this.instanceCache.clear(),this.readyPromise=null}async reloadObject(t){let n=this.registry.get(t);if(n){let i=await Mt.create(t,n,this.app);this.instanceCache.set(t,i)}}get(t){return this.instanceCache.get(t)}},am=new Ta,sm=new Proxy(am,{get(e,t){if(t in e&&typeof e[t]=="function")return e[t].bind(e);if(e.get(t))return e.get(t)}});qn();var Kc=require("pixi.js"),Xe={width:400,height:600,designWidth:400,scaleFactor:1},Zi={scale:1,position:1},La=[];function cm(e,t,n,i,r,a,s){La.push({element:e,originalScale:a,positionHelper:t,heightPercent:r}),t(e,n,i,r,a,s,!1)}function dm(){La.forEach(({element:e,originalScale:t,positionHelper:n,heightPercent:i})=>{let r=t*Xe.scaleFactor;n(e,Xe.width,Xe.height,i,r,!0,!1)})}function ka(e,t){console.log(`[SCREEN] updateScreenState called: ${e}x${t}`),Xe.width=e,Xe.height=t,Xe.scaleFactor=Math.min(e/Xe.designWidth,1.15),Zi.scale=Xe.scaleFactor,Zi.position=1,console.log(`[SCREEN] Global multipliers - scale: ${Zi.scale.toFixed(3)}`),dm()}var Wn={layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:1,screen_scale_y:1},engine:{scale:1,background_scale:1.05,background_offset_y:0,background_alpha:.98,label_pulse_speed:3,label_pulse_intensity:.03}};function um(e,t,n){let i=Wn[e];i&&i[t]!==void 0&&(i[t]=n,console.log(`Updated ${e}.${t} = ${n}`))}function pm(){return Wn}var fm={center:{x:.5,y:.5},"center-center":{x:.5,y:.5},middle:{x:.5,y:.5},"middle-center":{x:.5,y:.5},"top-left":{x:0,y:0},"top-center":{x:.5,y:0},"top-right":{x:1,y:0},"bottom-left":{x:0,y:1},"bottom-center":{x:.5,y:1},"bottom-right":{x:1,y:1},"left-center":{x:0,y:.5},"right-center":{x:1,y:.5},"center-left":{x:0,y:.5},"center-right":{x:1,y:.5},left:{x:0,y:.5},right:{x:1,y:.5},top:{x:.5,y:0},bottom:{x:.5,y:1}};function Ki(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function Ji(e,t={x:.5,y:.5}){var n;if(Array.isArray(e))return{x:Ki(e[0],t.x),y:Ki(e[1],t.y)};if(e&&typeof e=="object"){let i=e;return{x:Ki(i.x,t.x),y:Ki(i.y,t.y)}}if(typeof e=="string"){let i=e.trim().toLowerCase();return(n=fm[i])!=null?n:t}return t}function Zc(e,t,n,i={}){var u,v,h,w,y,m;let r=Ji(n),a=(u=i.inset)!=null?u:{},s=(v=i.padding)!=null?v:{x:0,y:0},o=((h=a.left)!=null?h:0)+s.x,d=((w=a.right)!=null?w:0)+s.x,l=((y=a.top)!=null?y:0)+s.y,c=((m=a.bottom)!=null?m:0)+s.y,f=Math.max(0,e-o-d),p=Math.max(0,t-l-c);return{x:o+f*r.x,y:l+p*r.y}}function Jc(e,t,n,i={}){var h,w,y,m,b,g;let r=(h=i.inset)!=null?h:{},a=(w=i.padding)!=null?w:{x:0,y:0},s=((y=r.left)!=null?y:0)+a.x,o=((m=r.right)!=null?m:0)+a.x,d=((b=r.top)!=null?b:0)+a.y,l=((g=r.bottom)!=null?g:0)+a.y,c=Math.max(0,e-s-o),f=Math.max(0,t-d-l),p=Ji(n,{x:.5,y:.5}),u=Math.min(Math.max(p.x,0),1),v=Math.min(Math.max(p.y,0),1);return{x:s+c*u,y:d+f*v}}if(typeof window!="undefined"){let e=window.innerWidth,t=window.innerHeight,n=()=>{let i=window.innerWidth,r=window.innerHeight;(i!==e||r!==t)&&(e=i,t=r,ka(i,r))};window.addEventListener("resize",n),window.addEventListener("orientationchange",()=>{setTimeout(n,100)}),window.mraid&&(window.mraid.addEventListener("viewableChange",n),window.mraid.addEventListener("sizeChange",n)),ka(window.innerWidth,window.innerHeight),window.updateDebugConfig=um,window.getDebugConfig=pm,window.copyConfig=Sm,window.applyConfig=Gn,window.applyConfigForRatio=Am,window.positionAtBottom=Qc,window.positionAtTop=mm,window.positionAtCenter=bm,window.positionAtLeft=ym,window.positionAtRight=vm,window.positionAtBottomLeft=xm,window.positionAtBottomRight=wm,window.positionAtTopLeft=_m,window.positionAtTopRight=Em,window.applyPositionContract=gm,console.log("\u{1F3AE} Debug Config Functions Available:"),console.log("\u2022 updateDebugConfig(category, key, value)"),console.log("\u2022 getDebugConfig()"),console.log("\u2022 copyConfig(presetName)"),console.log("\u2022 applyConfig(config)"),console.log("\u2022 applyConfigForRatio(width, height)"),console.log("\u{1F4CD} Positioning Helpers Available (with scale):"),console.log("\u2022 positionAtBottom(element, w, h, percent, scale)"),console.log("\u2022 positionAtTop(element, w, h, percent, scale)"),console.log("\u2022 positionAtCenter(element, w, h, offsetX, offsetY, scale)"),console.log("\u2022 positionAtLeft/Right(element, w, h, percent, scale)"),console.log("\u2022 Corner positions: BottomLeft/Right, TopLeft/Right (all with scale)"),console.log("\u2022 applyPositionContract(element, w, h, contract)"),console.log("Example: positionAtCenter(mySprite, 400, 600, 0, -50, 1.2)")}function Qi(e,t,n=0){return e*t+n}function er(e,t,n=0){return e*(1-t)+n}function tr(e,t,n=0){return e*t+n}function nr(e,t,n=0){return e*(1-t)+n}function ge(e,t=0){return e/2+t}function hm(e,t){return e*t}function gm(e,t,n,i){var s,o,d,l,c,f,p,u,v,h,w,y,m,b,g,x,E,A,C,T;let r=0,a=0;switch(i.type){case"top":r=ge(t,(o=(s=i.offset)==null?void 0:s.x)!=null?o:0),a=Qi(n,i.percent,(l=(d=i.offset)==null?void 0:d.y)!=null?l:0);break;case"bottom":r=ge(t,(f=(c=i.offset)==null?void 0:c.x)!=null?f:0),a=er(n,i.percent,(u=(p=i.offset)==null?void 0:p.y)!=null?u:0);break;case"left":r=tr(t,i.percent,(h=(v=i.offset)==null?void 0:v.x)!=null?h:0),a=ge(n,(y=(w=i.offset)==null?void 0:w.y)!=null?y:0);break;case"right":r=nr(t,i.percent,(b=(m=i.offset)==null?void 0:m.x)!=null?b:0),a=ge(n,(x=(g=i.offset)==null?void 0:g.y)!=null?x:0);break;case"center":r=ge(t,(A=(E=i.offset)==null?void 0:E.x)!=null?A:0),a=ge(n,(T=(C=i.offset)==null?void 0:C.y)!=null?T:0);break}e.position?e.position.set(r,a):(e.x=r,e.y=a),i.scale!==void 0&&i.scale!==1&&e.scale&&(typeof e.scale.set=="function"?e.scale.set(i.scale,i.scale):(e.scale.x=i.scale,e.scale.y=i.scale))}function Qc(e,t,n,i=.2,r=1,a=!0,s=!1){let o=hm(n,i),d=er(n,i/2);Ke(e,ge(t),d);let l=a?r*Xe.scaleFactor:r;Ze(e,l),s&&!La.find(c=>c.element===e)&&cm(e,Qc,t,n,i,r,a)}function mm(e,t,n,i=.1,r=1){Ke(e,ge(t),Qi(n,i)),Ze(e,r)}function bm(e,t,n,i=0,r=0,a=1){Ke(e,ge(t,i),ge(n,r)),Ze(e,a)}function ym(e,t,n,i=.1,r=1){Ke(e,tr(t,i),ge(n)),Ze(e,r)}function vm(e,t,n,i=.1,r=1){Ke(e,nr(t,i),ge(n)),Ze(e,r)}function xm(e,t,n,i=.05,r=.05,a=1){Ke(e,tr(t,r),er(n,i)),Ze(e,a)}function wm(e,t,n,i=.05,r=.05,a=1){Ke(e,nr(t,r),er(n,i)),Ze(e,a)}function _m(e,t,n,i=.05,r=.05,a=1){Ke(e,tr(t,r),Qi(n,i)),Ze(e,a)}function Em(e,t,n,i=.05,r=.05,a=1){Ke(e,nr(t,r),Qi(n,i)),Ze(e,a)}function Ke(e,t,n){e&&e.position?typeof e.position.set=="function"?e.position.set(t,n):(e.position.x=t,e.position.y=n):e&&(e.x=t,e.y=n)}function Ze(e,t){t!==1&&e&&e.scale&&(typeof e.scale.set=="function"?e.scale.set(t,t):e.scale.x!==void 0&&e.scale.y!==void 0&&(e.scale.x=t,e.scale.y=t))}var Ot={default:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:1,screen_scale_y:1},engine:{scale:1,background_scale:1.05,background_offset_y:0,background_alpha:.98,label_pulse_speed:3,label_pulse_intensity:.03}},wide:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:.9,screen_scale_y:1.1},engine:{scale:1,background_scale:1.1,background_offset_y:0,background_alpha:.95,label_pulse_speed:3,label_pulse_intensity:.03}},square:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:.85,screen_scale_y:.85},engine:{scale:1,background_scale:1,background_offset_y:0,background_alpha:1,label_pulse_speed:3,label_pulse_intensity:.03}},tall:{layout:{scale_multiplier:1,position_offset:{x:0,y:0},debug_rect_visible:!0,debug_rect_color:16711680,debug_rect_thickness:4,debug_rect_scale_x:1,debug_rect_scale_y:1,screen_scale_x:1.1,screen_scale_y:.9},engine:{scale:1,background_scale:.95,background_offset_y:0,background_alpha:1,label_pulse_speed:3,label_pulse_intensity:.03}}};function Sm(e){return e&&Ot[e]?JSON.parse(JSON.stringify(Ot[e])):JSON.parse(JSON.stringify(Wn))}function Gn(e){Object.keys(e).forEach(t=>{let n=t;Wn[n]&&e[n]&&Object.assign(Wn[n],e[n])}),console.log("Config applied:",e)}function Am(e,t){let n=e/t;n>1.6?(Gn(Ot.wide),console.log("Applied WIDE config for ratio:",n)):n<.7?(Gn(Ot.tall),console.log("Applied TALL config for ratio:",n)):n>.8&&n<1.2?(Gn(Ot.square),console.log("Applied SQUARE config for ratio:",n)):(Gn(Ot.default),console.log("Applied DEFAULT config for ratio:",n))}if(typeof window!="undefined"){let e=window;e.configPresets=Ot,e.resolveAnchorVec2=e.resolveAnchorVec2||Ji,e.resolveScreenAnchorPoint=e.resolveScreenAnchorPoint||Zc,e.resolveScreenRatioPoint=e.resolveScreenRatioPoint||Jc}Oa();function G(e,t){let n=(r,a)=>a===0?r:n(a,r%a),i=n(e,t);return`${e/i}:${t/i}`}var N_=[{id:"iphone-15-pro-max",label:"iPhone 15 Pro Max",width:430,height:932,category:"iphone",ratio:G(430,932)},{id:"iphone-15-pro",label:"iPhone 15 Pro",width:393,height:852,category:"iphone",ratio:G(393,852)},{id:"iphone-15",label:"iPhone 15",width:393,height:852,category:"iphone",ratio:G(393,852)},{id:"iphone-14",label:"iPhone 14",width:390,height:844,category:"iphone",ratio:G(390,844)},{id:"iphone-se",label:"iPhone SE",width:375,height:667,category:"iphone",ratio:G(375,667)},{id:"iphone-12-mini",label:"iPhone 12 Mini",width:360,height:780,category:"iphone",ratio:G(360,780)}],H_=[{id:"pixel-8-pro",label:"Pixel 8 Pro",width:448,height:998,category:"android",ratio:G(448,998)},{id:"pixel-8",label:"Pixel 8",width:412,height:915,category:"android",ratio:G(412,915)},{id:"samsung-s24-ultra",label:"Samsung S24 Ultra",width:412,height:915,category:"android",ratio:G(412,915)},{id:"samsung-s24",label:"Samsung S24",width:360,height:780,category:"android",ratio:G(360,780)},{id:"samsung-a54",label:"Samsung A54",width:412,height:915,category:"android",ratio:G(412,915)},{id:"oneplus-12",label:"OnePlus 12",width:412,height:915,category:"android",ratio:G(412,915)}],$_=[{id:"ipad-pro-12",label:'iPad Pro 12.9"',width:1024,height:1366,category:"tablet",ratio:G(1024,1366)},{id:"ipad-pro-11",label:'iPad Pro 11"',width:834,height:1194,category:"tablet",ratio:G(834,1194)},{id:"ipad-air",label:"iPad Air",width:820,height:1180,category:"tablet",ratio:G(820,1180)},{id:"ipad-mini",label:"iPad Mini",width:768,height:1024,category:"tablet",ratio:G(768,1024)},{id:"samsung-tab-s9",label:"Samsung Tab S9",width:800,height:1280,category:"tablet",ratio:G(800,1280)}],id=[{id:"playable-portrait",label:"Playable Portrait",width:320,height:480,category:"playable",ratio:"2:3",mraidScale:1},{id:"mraid-320x480",label:"MRAID 320\xD7480",width:320,height:480,category:"playable",ratio:"2:3",mraidScale:1},{id:"iphone-14",label:"iPhone 14",width:390,height:844,category:"playable",ratio:G(390,844),mraidScale:.7},{id:"ipad-mini",label:"iPad Mini",width:768,height:1024,category:"playable",ratio:G(768,1024),mraidScale:.7}];var U_=[...id];var Im=id[0];pt();var y0=Ge(mh(),1);function g0(e){return new Promise((t,n)=>{let i=new FileReader;i.onerror=()=>n(new Error("FileReader failed")),i.onload=()=>t(String(i.result||"")),i.readAsDataURL(e)})}function m0(e){var r;let[t,n]=e.split(","),i=t==null?void 0:t.match(/data:(.*?);base64/);return{base64:n!=null?n:"",mimeType:(r=i==null?void 0:i[1])!=null?r:"image/png"}}async function b0(e){return await new Promise(t=>{let n=new Image;n.onload=()=>t({width:n.naturalWidth||n.width,height:n.naturalHeight||n.height}),n.onerror=()=>t(null),n.src=e})}async function Eo(e){var t,n;try{console.log("[ImageUtils] Fetching image data from URL:",e);let i=await fetch(e);if(!i.ok)return console.warn("[ImageUtils] Fetch failed with status:",i.status,e),null;let r=await i.blob();console.log("[ImageUtils] Blob received, size:",r.size,"type:",r.type);let a=await g0(r),s=await b0(a),o=m0(a);return console.log("[ImageUtils] Success resolution:",s==null?void 0:s.width,"x",s==null?void 0:s.height,"mime:",o.mimeType),{base64:o.base64,mimeType:o.mimeType,dataUrl:a,width:(t=s==null?void 0:s.width)!=null?t:0,height:(n=s==null?void 0:s.height)!=null?n:0}}catch(i){return console.error("[ImageUtils] Error fetching image data:",i),null}}async function Vr(e,t=30){try{console.log("[ImageUtils] Removing background color...");let n=await new Promise((f,p)=>{let u=new Image;u.onload=()=>f(u),u.onerror=()=>p(new Error("Failed to load image")),u.src=e}),i=document.createElement("canvas");i.width=n.width,i.height=n.height;let r=i.getContext("2d");if(!r)return console.error("[ImageUtils] Failed to get canvas context"),e;r.drawImage(n,0,0);let a=r.getImageData(0,0,i.width,i.height),s=a.data,d=[{name:"top-left",offset:0},{name:"top-right",offset:(i.width-1)*4},{name:"bottom-left",offset:(i.height-1)*i.width*4},{name:"bottom-right",offset:((i.height-1)*i.width+(i.width-1))*4}].map(f=>({r:s[f.offset],g:s[f.offset+1],b:s[f.offset+2]})),l=0;for(let f=0;f<s.length;f+=4){let p=s[f],u=s[f+1],v=s[f+2],h=!1;for(let w of d)if(Math.sqrt(Math.pow(p-w.r,2)+Math.pow(u-w.g,2)+Math.pow(v-w.b,2))<t){h=!0;break}h&&(s[f+3]=0,l++)}return console.log(`[ImageUtils] Removed background from ${l} pixels (4-corner sampling, tolerance: ${t})`),r.putImageData(a,0,0),i.toDataURL("image/png")}catch(n){return console.error("[ImageUtils] Error removing background:",n),e}}var bh=require("@google/genai");async function So(e,t,n=[],i={}){var r,a,s,o,d,l,c;try{if(!(e!=null&&e.trim()))throw new Error("Gemini API key is required");if(!(t!=null&&t.trim()))throw new Error("Prompt is required");for(let y=0;y<n.length;y++){let m=n[y];if(!m.base64||!m.mimeType)throw new Error(`Image ${y+1} is missing required data`);if(m.base64.length<1e3&&console.warn(`Image ${y+1} data appears very small, may be corrupted`),!m.mimeType.startsWith("image/"))throw new Error(`Image ${y+1} has invalid MIME type: ${m.mimeType}`)}let f=new bh.GoogleGenAI({apiKey:e}),p="gemini-2.5-flash",u=[t];n.length>0&&n.forEach((y,m)=>{u.push({inlineData:{data:y.base64,mimeType:y.mimeType}}),console.log(`[Gemini] Added image ${m+1}: ${y.mimeType}, size: ${Math.round(y.base64.length/1024)}KB`)}),console.log(`[Gemini] Making request with ${n.length} images and prompt length: ${t.length}`);let v=await f.models.generateContent({model:p,contents:u}),h="",w=(s=(a=(r=v.candidates)==null?void 0:r[0])==null?void 0:a.content)==null?void 0:s.parts;if(w)for(let y of w)y.text&&(h+=y.text);if(!h.trim())throw new Error("Empty response from Gemini API");return console.log(`[Gemini] Response received, length: ${h.length}`),h}catch(f){throw console.error("[Gemini] API error:",f),(o=f.message)!=null&&o.includes("Unable to process input image")?new Error("Unable to process the uploaded image. Please ensure it's a valid PNG, JPG, or JPEG file under 10MB and not corrupted."):(d=f.message)!=null&&d.includes("API_KEY_INVALID")?new Error("Invalid Gemini API key. Please check your API key configuration."):(l=f.message)!=null&&l.includes("QUOTA_EXCEEDED")?new Error("Gemini API quota exceeded. Please try again later or check your billing."):(c=f.message)!=null&&c.includes("SAFETY")?new Error("Content was flagged by Gemini safety filters. Please try with different images."):f}}var yh=require("@google/genai");async function Xr(e,t,n=[],i={}){try{console.info("[GEMINI-REAL-SDK] Initializing GoogleGenAI...");let r=new yh.GoogleGenAI({apiKey:e}),a=[{text:t}];n.length>0&&n.forEach((o,d)=>{console.info(`[GEMINI-REAL-SDK] Adding image part ${d}`),a.push({inlineData:{mimeType:o.mimeType,data:o.base64}})}),console.info("[GEMINI-REAL-SDK] Calling generateContent with model: gemini-2.5-flash-image");let s=await r.models.generateContent({model:"gemini-2.5-flash-image",contents:a});if(console.info("[GEMINI-REAL-SDK] Received response from model"),!s.candidates||!s.candidates[0]||!s.candidates[0].content||!s.candidates[0].content.parts)throw new Error("Gemini 2.5 Flash Image returned invalid response structure.");for(let o of s.candidates[0].content.parts)if(o.text)console.log(o.text);else if(o.inlineData){let d=o.inlineData.data,l=o.inlineData.mimeType||"image/png";return console.info("[GEMINI-REAL-SDK] Found inline image data in response"),`data:${l};base64,${d}`}throw new Error("Gemini 2.5 Flash Image returned no image data.")}catch(r){throw console.error("[GEMINI-REAL-SDK] Error in generateImageWithGemini25Flash:",JSON.stringify(r,Object.getOwnPropertyNames(r),2)),r}}var v0=require("pixi.js");qn();pt();var xh=require("pixi.js");var x0=require("pixi.js");pt();function T0(e){return new Promise((t,n)=>{let i=new FileReader;i.onerror=()=>n(new Error("FileReader failed")),i.onload=()=>t(String(i.result||"")),i.readAsDataURL(e)})}function k0(e){var r;let[t,n]=e.split(","),i=t==null?void 0:t.match(/data:(.*?);base64/);return{base64:n!=null?n:"",mimeType:(r=i==null?void 0:i[1])!=null?r:"image/png"}}function L0(e){return`
48
48
  Analyze these screenshots of a brand or game and extract its "Brand DNA".
49
49
 
50
50
  Provide a concise summary (2-3 sentences) covering:
@@ -3384,6 +3384,128 @@
3384
3384
  filter: grayscale(1);
3385
3385
  opacity: 0.5;
3386
3386
  }
3387
+ /* Version Management Section */
3388
+ .version-management-section {
3389
+ margin-top: 16px;
3390
+ padding: 12px;
3391
+ background: rgba(30, 35, 45, 0.5);
3392
+ border: 1px solid var(--ui-border);
3393
+ border-radius: 10px;
3394
+ }
3395
+
3396
+ .version-header {
3397
+ margin-bottom: 12px;
3398
+ }
3399
+
3400
+ .version-label {
3401
+ font-size: 11px;
3402
+ font-weight: 700;
3403
+ text-transform: uppercase;
3404
+ letter-spacing: 0.05em;
3405
+ color: var(--ui-accent);
3406
+ }
3407
+
3408
+ .version-controls {
3409
+ display: flex;
3410
+ flex-direction: column;
3411
+ gap: 12px;
3412
+ }
3413
+
3414
+ .version-current {
3415
+ display: flex;
3416
+ align-items: center;
3417
+ gap: 8px;
3418
+ }
3419
+
3420
+ .version-current label {
3421
+ font-size: 12px;
3422
+ color: var(--ui-text);
3423
+ min-width: 110px;
3424
+ font-weight: 600;
3425
+ }
3426
+
3427
+ .version-dropdown {
3428
+ flex: 1;
3429
+ padding: 8px 10px;
3430
+ border: 1px solid var(--ui-border);
3431
+ border-radius: 6px;
3432
+ background: var(--ui-surface);
3433
+ color: var(--ui-text);
3434
+ font-size: 12px;
3435
+ cursor: pointer;
3436
+ transition: border-color var(--ui-duration-fast);
3437
+ }
3438
+
3439
+ .version-dropdown:hover {
3440
+ border-color: var(--ui-accent);
3441
+ }
3442
+
3443
+ .version-dropdown:focus {
3444
+ outline: none;
3445
+ border-color: var(--ui-accent);
3446
+ box-shadow: 0 0 0 2px rgba(61, 214, 198, 0.2);
3447
+ }
3448
+
3449
+ .persistence-btn {
3450
+ padding: 10px 16px;
3451
+ background: var(--ui-surface);
3452
+ color: var(--ui-text);
3453
+ border: 1px solid var(--ui-border);
3454
+ border-radius: 8px;
3455
+ font-size: 11px;
3456
+ font-weight: 700;
3457
+ cursor: pointer;
3458
+ transition: all var(--ui-duration-fast);
3459
+ }
3460
+
3461
+ .persistence-btn:hover:not(:disabled) {
3462
+ background: rgba(61, 214, 198, 0.1);
3463
+ border-color: var(--ui-accent);
3464
+ }
3465
+
3466
+ .persistence-btn:disabled {
3467
+ opacity: 0.5;
3468
+ cursor: not-allowed;
3469
+ }
3470
+
3471
+ /* Developer-Only Section */
3472
+ .dev-only-section {
3473
+ margin-top: 16px;
3474
+ padding: 12px;
3475
+ background: rgba(255, 165, 0, 0.08);
3476
+ border: 1px solid rgba(255, 165, 0, 0.3);
3477
+ border-radius: 8px;
3478
+ }
3479
+
3480
+ .dev-warning {
3481
+ font-size: 11px;
3482
+ color: #ff8c00;
3483
+ font-weight: 700;
3484
+ margin-bottom: 8px;
3485
+ text-transform: uppercase;
3486
+ letter-spacing: 0.05em;
3487
+ }
3488
+
3489
+ .persistence-btn.danger-action {
3490
+ background: #dc3545;
3491
+ border-color: #dc3545;
3492
+ color: white;
3493
+ width: 100%;
3494
+ }
3495
+
3496
+ .persistence-btn.danger-action:hover:not(:disabled) {
3497
+ background: #c82333;
3498
+ border-color: #c82333;
3499
+ box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
3500
+ }
3501
+
3502
+ .dev-hint {
3503
+ margin-top: 8px;
3504
+ font-size: 10px;
3505
+ color: var(--ui-muted);
3506
+ font-style: italic;
3507
+ line-height: 1.4;
3508
+ }
3387
3509
 
3388
3510
 
3389
3511
  /* ========== 08-inspector.css ========== */