mirage-engine 0.3.11 → 0.3.12

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,5 +1,5 @@
1
- (function(A,S){typeof exports=="object"&&typeof module!="undefined"?S(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],S):(A=typeof globalThis!="undefined"?globalThis:A||self,S(A.MirageEngine={},A.THREE))})(this,function(A,S){"use strict";var ct=Object.defineProperty,lt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var Ce=(A,S,U)=>S in A?ct(A,S,{enumerable:!0,configurable:!0,writable:!0,value:U}):A[S]=U,te=(A,S)=>{for(var U in S||(S={}))dt.call(S,U)&&Ce(A,U,S[U]);if(Oe)for(var U of Oe(S))ut.call(S,U)&&Ce(A,U,S[U]);return A},_e=(A,S)=>lt(A,ht(S));var u=(A,S,U)=>(Ce(A,typeof S!="symbol"?S+"":S,U),U);var Be=(A,S,U)=>new Promise((y,oe)=>{var j=O=>{try{B(U.next(O))}catch(V){oe(V)}},ge=O=>{try{B(U.throw(O))}catch(V){oe(V)}},B=O=>O.done?y(O.value):Promise.resolve(O.value).then(j,ge);B((U=U.apply(A,S)).next())});function U(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const y=U(S),oe={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},j={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},ge={TRAVELER:"traveler",NATIVE:"native",CAPTURE_1:"1",CAPTURE_2:"2",CAPTURE_3:"3",CAPTURE_4:"4",CAPTURE_5:"5",CAPTURE_6:"6",CAPTURE_7:"7",CAPTURE_8:"8",CAPTURE_9:"9",CAPTURE_10:"10"},B={NAME:"data-mirage-travel",KEY:"mirageTravel",VALUES:ge,MAX_LAYERS:Object.keys(ge).length-1},O={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:oe},V={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:oe},Fe={NAME:"data-mirage-shader",KEY:"mirageShader"},Se={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},pe=0,ee=1,ae=2,Ne=4,me=8,ye=16;function ze(s){const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return e?{r:parseInt(e[1])/255,g:parseInt(e[2])/255,b:parseInt(e[3])/255}:{r:1,g:1,b:1}}function Xe(s){const e={};if(s.opacity&&(e.opacity=parseFloat(s.opacity)),s.backgroundColor&&s.backgroundColor!=="rgba(0, 0, 0, 0)"){const t=ze(s.backgroundColor);e.backgroundColor=[t.r,t.g,t.b]}if(s.backgroundImage?e.backgroundImage=s.backgroundImage:s.background&&(e.backgroundImage=s.background),s.borderRadius&&(e.borderRadius=parseFloat(s.borderRadius)),s.width&&(e.width=parseFloat(s.width)),s.height&&(e.height=parseFloat(s.height)),s.transform&&s.transform!=="none"){const t=new DOMMatrix(s.transform);e.x=t.m41,e.y=t.m42,e.z=t.m43}return e}class Te{constructor(e,t){u(this,"target");u(this,"observer");u(this,"pendingDeletions",new Set);u(this,"pendingStyles",new Map);u(this,"isDomDirty",!1);u(this,"isRunning",!1);u(this,"pendingMask",pe);u(this,"mutationTimer",null);u(this,"cssTimer",null);u(this,"resizeConfig");u(this,"resizeTimer",null);u(this,"isResizing",!1);u(this,"lastScrollX",0);u(this,"lastScrollY",0);u(this,"scrollTimer",null);u(this,"onBeforeRender",new Set);u(this,"onLayoutChange",new Set);u(this,"onStyleChange",new Set);u(this,"onScrollChange",new Set);u(this,"onRender",new Set);u(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=ee|ae,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});u(this,"onWindowResize",()=>{if(!this.resizeConfig.enabled){this.isDomDirty=!0;return}this.isResizing||(this.isResizing=!0,this.resizeConfig.onStart&&this.resizeConfig.onStart()),this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.resizeConfig.onEnd&&this.resizeConfig.onEnd(),this.isResizing=!1,this.resizeTimer=null},this.resizeConfig.delay)});u(this,"renderLoop",()=>{if(!this.isRunning)return;this.onBeforeRender.forEach(r=>r()),this.isDomDirty&&(this.isDomDirty=!1,this.onLayoutChange.forEach(r=>r(this.pendingMask,this.pendingDeletions)),this.pendingDeletions.clear(),this.pendingMask=pe);const e=window.scrollX,t=window.scrollY;(e!==this.lastScrollX||t!==this.lastScrollY)&&(this.onScrollChange.forEach(r=>r(e,t)),this.lastScrollX=e,this.lastScrollY=t,this.scrollTimer&&clearTimeout(this.scrollTimer),this.scrollTimer=window.setTimeout(()=>{this.pendingMask|=ee,this.isDomDirty=!0,this.scrollTimer=null},150)),this.pendingStyles.size>0&&(this.onStyleChange.forEach(r=>r(this.pendingStyles)),this.pendingStyles.clear()),this.onRender.forEach(r=>r()),requestAnimationFrame(this.renderLoop)});var i,a;this.target=e;const r=(i=t.resizeDebounce)!=null?i:!0;r===!1?this.resizeConfig={enabled:!1,delay:0}:r===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(a=r.delay)!=null?a:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(n=>{let o=pe;for(const c of n)if(c.type==="childList")o|=me,c.removedNodes.length>0&&c.removedNodes.forEach(l=>{l instanceof HTMLElement&&this.pendingDeletions.add(l)});else if(c.type==="attributes")if(c.attributeName==="style"){o|=ee|ae;const l=c.target,d=Xe(l.style);this.pendingStyles.set(l,d)}else c.attributeName==="class"?o|=ee|ae:c.attributeName&&c.attributeName.startsWith("data-")&&(o|=ee|ae,c.attributeName.startsWith("data-mirage")&&(o|=me));else c.type==="characterData"&&(o|=ye|ee);if(o!==pe){if(this.pendingMask|=o,o&me){this.clearTimers(),this.isDomDirty=!0;return}this.mutationTimer&&clearTimeout(this.mutationTimer),this.mutationTimer=window.setTimeout(()=>{this.mutationTimer=null,this.isDomDirty=!0},200)}})}start(){this.isRunning||(this.isRunning=!0,this.observer.observe(this.target,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),this.target.addEventListener("transitionend",this.onTransitionFinished),this.target.addEventListener("animationend",this.onTransitionFinished),window.addEventListener("resize",this.onWindowResize),this.isDomDirty=!0,this.lastScrollX=window.scrollX,this.lastScrollY=window.scrollY,this.renderLoop())}stop(){this.isRunning=!1,this.observer.disconnect(),this.clearTimers(),this.target.removeEventListener("transitionend",this.onTransitionFinished),this.target.removeEventListener("animationend",this.onTransitionFinished),window.removeEventListener("resize",this.onWindowResize)}clearTimers(){this.mutationTimer&&(clearTimeout(this.mutationTimer),this.mutationTimer=null),this.cssTimer&&(clearTimeout(this.cssTimer),this.cssTimer=null),this.scrollTimer&&(clearTimeout(this.scrollTimer),this.scrollTimer=null)}}const K=1,re=2,N={BASE:0,SELECTED:1,getCaptureLayer:s=>31-s,HIDDEN:31},Re=Object.values(O.VALUES);class Le{static getBaseline(e){if(this.cache.has(e))return this.cache.get(e);const t=this.calculateBaselineFromDOM(e);return this.cache.set(e,t),t}static calculateBaselineFromDOM(e){if(typeof document=="undefined")return 0;const t=document.createElement("div"),r=document.createElement("span"),i=document.createElement("img");t.style.visibility="hidden",t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.font=e,t.style.margin="0",t.style.padding="0",t.style.border="none",r.style.margin="0",r.style.padding="0",r.style.border="none",r.style.lineHeight="normal",i.width=1,i.height=1,i.style.verticalAlign="baseline",r.appendChild(document.createTextNode("Hidden Text")),t.appendChild(r),t.appendChild(i),document.body.appendChild(t);const a=i.offsetTop-r.offsetTop;return document.body.removeChild(t),a}}u(Le,"cache",new Map);class Ve extends y.MeshBasicMaterial{constructor(t,r,i,a,n=2){super({transparent:!0,side:y.FrontSide,color:16777215});u(this,"canvas");u(this,"ctx");u(this,"qualityFactor");if(this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("[Mirage] Failed to create canvas context");this.qualityFactor=n,this.map=new y.CanvasTexture(this.canvas),this.map.colorSpace=y.LinearSRGBColorSpace,this.map.minFilter=y.LinearFilter,this.map.magFilter=y.LinearFilter,this.updateText(t,r,i,a)}wrapText(t,r){const i=t.split(`
2
- `),a=[];return i.forEach(n=>{const o=n.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(o.length===0){a.push("");return}let c=o[0];for(let l=1;l<o.length;l++){const d=o[l];this.ctx.measureText(c+d).width<=r+2?c+=d:(c&&a.push(c),c=d.trimStart())}c&&a.push(c)}),a}updateText(t,r,i,a,n){n!==void 0&&(this.qualityFactor=n);const c=(window.devicePixelRatio||1)*this.qualityFactor,l=i*c,d=a*c;this.canvas.width!==l||this.canvas.height!==d?(this.canvas.width=l,this.canvas.height=d):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(c,0,0,c,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),f=r.lineHeight,p=Le.getBaseline(r.font);h.forEach((g,v)=>{const b=v*f+p;let M=0;r.textAlign==="center"?M=i/2:r.textAlign==="right"&&(M=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(g,M,b)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function ie(s,e=0){if(typeof s=="number")return s;const t=parseFloat(s)||0;return typeof s=="string"&&s.includes("%")?t/100*e:t}function ce(s){if(!s||s==="transparent")return{color:new y.Color(16777215),alpha:0};const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),a=e[4]!==void 0?parseFloat(e[4]):1;return{color:new y.Color(`rgb(${t}, ${r}, ${i})`),alpha:a}}return{color:new y.Color(s),alpha:1}}function Ye(s){const e=[];let t="",r=0;for(let i=0;i<s.length;i++){const a=s[i];if(a==="(")r++;else if(a===")")r--;else if(a===","&&r===0){e.push(t.trim()),t="";continue}t+=a}return t&&e.push(t.trim()),e}function We(s){if(!s||typeof s!="string"||!s.includes("linear-gradient"))return null;const e=s.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=Ye(t);let i=Math.PI,a=0;const n=r[0].trim();if(n.startsWith("to "))n==="to top"?i=0:n==="to right"?i=Math.PI/2:n==="to bottom"?i=Math.PI:n==="to left"?i=Math.PI*1.5:n==="to top right"||n==="to right top"?i=Math.PI/4:n==="to bottom right"||n==="to right bottom"?i=Math.PI*.75:n==="to bottom left"||n==="to left bottom"?i=Math.PI*1.25:(n==="to top left"||n==="to left top")&&(i=Math.PI*1.75),a=1;else if(n.endsWith("deg")||n.endsWith("rad")||n.endsWith("turn")){const c=parseFloat(n);n.endsWith("deg")?i=c*(Math.PI/180):n.endsWith("rad")?i=c:n.endsWith("turn")&&(i=c*Math.PI*2),a=1}const o=[];for(let c=a;c<r.length&&!(o.length>=8);c++){const l=r[c].trim(),d=l.lastIndexOf(" ");let h=l,f=null;if(d!==-1&&!l.endsWith(")")){const g=l.substring(d+1);(g.endsWith("%")||g.endsWith("px")||!isNaN(parseFloat(g)))&&(h=l.substring(0,d).trim(),f=g)}const p=ce(h);o.push({color:p.color,alpha:p.alpha,rawStop:f,stop:0})}if(o.length>0){for(let l=0;l<o.length;l++)o[l].rawStop!==null&&(o[l].stop=parseFloat(o[l].rawStop)/100);o[0].rawStop===null&&(o[0].stop=0),o.length>1&&o[o.length-1].rawStop===null&&(o[o.length-1].stop=1);let c=0;for(let l=1;l<o.length;l++)if(o[l].rawStop!==null||l===o.length-1){const d=l-c;if(d>1){const h=o[c].stop,p=(o[l].stop-h)/d;for(let g=1;g<d;g++)o[c+g].stop=h+p*g}c=l}}return{angle:i,stops:o}}const He=`varying vec2 vUv;
1
+ (function(D,S){typeof exports=="object"&&typeof module!="undefined"?S(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],S):(D=typeof globalThis!="undefined"?globalThis:D||self,S(D.MirageEngine={},D.THREE))})(this,function(D,S){"use strict";var ct=Object.defineProperty,lt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var Ce=(D,S,U)=>S in D?ct(D,S,{enumerable:!0,configurable:!0,writable:!0,value:U}):D[S]=U,te=(D,S)=>{for(var U in S||(S={}))dt.call(S,U)&&Ce(D,U,S[U]);if(Oe)for(var U of Oe(S))ut.call(S,U)&&Ce(D,U,S[U]);return D},_e=(D,S)=>lt(D,ht(S));var u=(D,S,U)=>(Ce(D,typeof S!="symbol"?S+"":S,U),U);var Be=(D,S,U)=>new Promise((y,oe)=>{var K=O=>{try{B(U.next(O))}catch(V){oe(V)}},ge=O=>{try{B(U.throw(O))}catch(V){oe(V)}},B=O=>O.done?y(O.value):Promise.resolve(O.value).then(K,ge);B((U=U.apply(D,S)).next())});function U(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const y=U(S),oe={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},K={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},ge={TRAVELER:"traveler",NATIVE:"native",CAPTURE_1:"1",CAPTURE_2:"2",CAPTURE_3:"3",CAPTURE_4:"4",CAPTURE_5:"5",CAPTURE_6:"6",CAPTURE_7:"7",CAPTURE_8:"8",CAPTURE_9:"9",CAPTURE_10:"10"},B={NAME:"data-mirage-travel",KEY:"mirageTravel",VALUES:ge,MAX_LAYERS:Object.keys(ge).length-1},O={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:oe},V={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:oe},Fe={NAME:"data-mirage-shader",KEY:"mirageShader"},Se={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},pe=0,ee=1,ae=2,Ne=4,me=8,ye=16;function ze(s){const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return e?{r:parseInt(e[1])/255,g:parseInt(e[2])/255,b:parseInt(e[3])/255}:{r:1,g:1,b:1}}function Xe(s){const e={};if(s.opacity&&(e.opacity=parseFloat(s.opacity)),s.backgroundColor&&s.backgroundColor!=="rgba(0, 0, 0, 0)"){const t=ze(s.backgroundColor);e.backgroundColor=[t.r,t.g,t.b]}if(s.backgroundImage?e.backgroundImage=s.backgroundImage:s.background&&(e.backgroundImage=s.background),s.borderRadius&&(e.borderRadius=parseFloat(s.borderRadius)),s.width&&(e.width=parseFloat(s.width)),s.height&&(e.height=parseFloat(s.height)),s.transform&&s.transform!=="none"){const t=new DOMMatrix(s.transform);e.x=t.m41,e.y=t.m42,e.z=t.m43}return e}class Te{constructor(e,t){u(this,"target");u(this,"observer");u(this,"pendingDeletions",new Set);u(this,"pendingStyles",new Map);u(this,"isDomDirty",!1);u(this,"isRunning",!1);u(this,"pendingMask",pe);u(this,"mutationTimer",null);u(this,"cssTimer",null);u(this,"resizeConfig");u(this,"resizeTimer",null);u(this,"isResizing",!1);u(this,"lastScrollX",0);u(this,"lastScrollY",0);u(this,"scrollTimer",null);u(this,"onBeforeRender",new Set);u(this,"onLayoutChange",new Set);u(this,"onStyleChange",new Set);u(this,"onScrollChange",new Set);u(this,"onRender",new Set);u(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=ee|ae,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});u(this,"onWindowResize",()=>{if(!this.resizeConfig.enabled){this.isDomDirty=!0;return}this.isResizing||(this.isResizing=!0,this.resizeConfig.onStart&&this.resizeConfig.onStart()),this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.resizeConfig.onEnd&&this.resizeConfig.onEnd(),this.isResizing=!1,this.resizeTimer=null},this.resizeConfig.delay)});u(this,"renderLoop",()=>{if(!this.isRunning)return;this.onBeforeRender.forEach(r=>r()),this.isDomDirty&&(this.isDomDirty=!1,this.onLayoutChange.forEach(r=>r(this.pendingMask,this.pendingDeletions)),this.pendingDeletions.clear(),this.pendingMask=pe);const e=window.scrollX,t=window.scrollY;(e!==this.lastScrollX||t!==this.lastScrollY)&&(this.onScrollChange.forEach(r=>r(e,t)),this.lastScrollX=e,this.lastScrollY=t,this.scrollTimer&&clearTimeout(this.scrollTimer),this.scrollTimer=window.setTimeout(()=>{this.pendingMask|=ee,this.isDomDirty=!0,this.scrollTimer=null},150)),this.pendingStyles.size>0&&(this.onStyleChange.forEach(r=>r(this.pendingStyles)),this.pendingStyles.clear()),this.onRender.forEach(r=>r()),requestAnimationFrame(this.renderLoop)});var i,c;this.target=e;const r=(i=t.resizeDebounce)!=null?i:!0;r===!1?this.resizeConfig={enabled:!1,delay:0}:r===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(c=r.delay)!=null?c:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(n=>{let o=pe;for(const a of n)if(a.type==="childList")o|=me,a.removedNodes.length>0&&a.removedNodes.forEach(l=>{l instanceof HTMLElement&&this.pendingDeletions.add(l)});else if(a.type==="attributes")if(a.attributeName==="style"){o|=ee|ae;const l=a.target,d=Xe(l.style);this.pendingStyles.set(l,d)}else a.attributeName==="class"?o|=ee|ae:a.attributeName&&a.attributeName.startsWith("data-")&&(o|=ee|ae,a.attributeName.startsWith("data-mirage")&&(o|=me));else a.type==="characterData"&&(o|=ye|ee);if(o!==pe){if(this.pendingMask|=o,o&me){this.clearTimers(),this.isDomDirty=!0;return}this.mutationTimer&&clearTimeout(this.mutationTimer),this.mutationTimer=window.setTimeout(()=>{this.mutationTimer=null,this.isDomDirty=!0},200)}})}start(){this.isRunning||(this.isRunning=!0,this.observer.observe(this.target,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),this.target.addEventListener("transitionend",this.onTransitionFinished),this.target.addEventListener("animationend",this.onTransitionFinished),window.addEventListener("resize",this.onWindowResize),this.isDomDirty=!0,this.lastScrollX=window.scrollX,this.lastScrollY=window.scrollY,this.renderLoop())}stop(){this.isRunning=!1,this.observer.disconnect(),this.clearTimers(),this.target.removeEventListener("transitionend",this.onTransitionFinished),this.target.removeEventListener("animationend",this.onTransitionFinished),window.removeEventListener("resize",this.onWindowResize)}clearTimers(){this.mutationTimer&&(clearTimeout(this.mutationTimer),this.mutationTimer=null),this.cssTimer&&(clearTimeout(this.cssTimer),this.cssTimer=null),this.scrollTimer&&(clearTimeout(this.scrollTimer),this.scrollTimer=null)}}const P=1,re=2,F={BASE:0,SELECTED:1,getCaptureLayer:s=>31-s,HIDDEN:31},Re=Object.values(O.VALUES);class Le{static getBaseline(e){if(this.cache.has(e))return this.cache.get(e);const t=this.calculateBaselineFromDOM(e);return this.cache.set(e,t),t}static calculateBaselineFromDOM(e){if(typeof document=="undefined")return 0;const t=document.createElement("div"),r=document.createElement("span"),i=document.createElement("img");t.style.visibility="hidden",t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.font=e,t.style.margin="0",t.style.padding="0",t.style.border="none",r.style.margin="0",r.style.padding="0",r.style.border="none",r.style.lineHeight="normal",i.width=1,i.height=1,i.style.verticalAlign="baseline",r.appendChild(document.createTextNode("Hidden Text")),t.appendChild(r),t.appendChild(i),document.body.appendChild(t);const c=i.offsetTop-r.offsetTop;return document.body.removeChild(t),c}}u(Le,"cache",new Map);class Ve extends y.MeshBasicMaterial{constructor(t,r,i,c,n=2){super({transparent:!0,side:y.FrontSide,color:16777215});u(this,"canvas");u(this,"ctx");u(this,"qualityFactor");if(this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("[Mirage] Failed to create canvas context");this.qualityFactor=n,this.map=new y.CanvasTexture(this.canvas),this.map.colorSpace=y.LinearSRGBColorSpace,this.map.minFilter=y.LinearFilter,this.map.magFilter=y.LinearFilter,this.updateText(t,r,i,c)}wrapText(t,r){const i=t.split(`
2
+ `),c=[];return i.forEach(n=>{const o=n.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(o.length===0){c.push("");return}let a=o[0];for(let l=1;l<o.length;l++){const d=o[l];this.ctx.measureText(a+d).width<=r+2?a+=d:(a&&c.push(a),a=d.trimStart())}a&&c.push(a)}),c}updateText(t,r,i,c,n){n!==void 0&&(this.qualityFactor=n);const a=(window.devicePixelRatio||1)*this.qualityFactor,l=i*a,d=c*a;this.canvas.width!==l||this.canvas.height!==d?(this.canvas.width=l,this.canvas.height=d):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(a,0,0,a,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),f=r.lineHeight,v=Le.getBaseline(r.font);h.forEach((g,m)=>{const b=m*f+v;let M=0;r.textAlign==="center"?M=i/2:r.textAlign==="right"&&(M=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(g,M,b)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function ie(s,e=0){if(typeof s=="number")return s;const t=parseFloat(s)||0;return typeof s=="string"&&s.includes("%")?t/100*e:t}function ce(s){if(!s||s==="transparent")return{color:new y.Color(16777215),alpha:0};const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),c=e[4]!==void 0?parseFloat(e[4]):1;return{color:new y.Color(`rgb(${t}, ${r}, ${i})`),alpha:c}}return{color:new y.Color(s),alpha:1}}function Ye(s){const e=[];let t="",r=0;for(let i=0;i<s.length;i++){const c=s[i];if(c==="(")r++;else if(c===")")r--;else if(c===","&&r===0){e.push(t.trim()),t="";continue}t+=c}return t&&e.push(t.trim()),e}function We(s){if(!s||typeof s!="string"||!s.includes("linear-gradient"))return null;const e=s.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=Ye(t);let i=Math.PI,c=0;const n=r[0].trim();if(n.startsWith("to "))n==="to top"?i=0:n==="to right"?i=Math.PI/2:n==="to bottom"?i=Math.PI:n==="to left"?i=Math.PI*1.5:n==="to top right"||n==="to right top"?i=Math.PI/4:n==="to bottom right"||n==="to right bottom"?i=Math.PI*.75:n==="to bottom left"||n==="to left bottom"?i=Math.PI*1.25:(n==="to top left"||n==="to left top")&&(i=Math.PI*1.75),c=1;else if(n.endsWith("deg")||n.endsWith("rad")||n.endsWith("turn")){const a=parseFloat(n);n.endsWith("deg")?i=a*(Math.PI/180):n.endsWith("rad")?i=a:n.endsWith("turn")&&(i=a*Math.PI*2),c=1}const o=[];for(let a=c;a<r.length&&!(o.length>=8);a++){const l=r[a].trim(),d=l.lastIndexOf(" ");let h=l,f=null;if(d!==-1&&!l.endsWith(")")){const g=l.substring(d+1);(g.endsWith("%")||g.endsWith("px")||!isNaN(parseFloat(g)))&&(h=l.substring(0,d).trim(),f=g)}const v=ce(h);o.push({color:v.color,alpha:v.alpha,rawStop:f,stop:0})}if(o.length>0){for(let l=0;l<o.length;l++)o[l].rawStop!==null&&(o[l].stop=parseFloat(o[l].rawStop)/100);o[0].rawStop===null&&(o[0].stop=0),o.length>1&&o[o.length-1].rawStop===null&&(o[o.length-1].stop=1);let a=0;for(let l=1;l<o.length;l++)if(o[l].rawStop!==null||l===o.length-1){const d=l-a;if(d>1){const h=o[a].stop,v=(o[l].stop-h)/d;for(let g=1;g<d;g++)o[a+g].stop=h+v*g}a=l}}return{angle:i,stops:o}}const He=`varying vec2 vUv;
3
3
  varying vec4 vScreenPos;
4
4
  void main() {
5
5
  vUv = uv;
@@ -152,17 +152,17 @@ uniform vec2 uTextureOffset;`,$e=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w)
152
152
  vec2 resultUv = screenUv;
153
153
 
154
154
  `,qe=`vec4 texColor = texture2D(uTexture, resultUv);
155
- baseColor = blendSrcOver(baseColor, texColor);`,Me={vertexShader:He,fragmentShader:Pe},Ae={declChunk:Ge,uvChunk:$e,baseColorChunk:qe};function je(s,e,t,r=null,i){var x;const a=r!==null||!!s.imageSrc;let n="";const o={};if(i!=null&&i.uniforms)for(const[C,w]of Object.entries(i.uniforms))typeof w=="number"?(n+=`uniform float ${C};
155
+ baseColor = blendSrcOver(baseColor, texColor);`,Me={vertexShader:He,fragmentShader:Pe},De={declChunk:Ge,uvChunk:$e,baseColorChunk:qe};function je(s,e,t,r=null,i){var x;const c=r!==null||!!s.imageSrc;let n="";const o={};if(i!=null&&i.uniforms)for(const[C,w]of Object.entries(i.uniforms))typeof w=="number"?(n+=`uniform float ${C};
156
156
  `,o[C]={value:w}):Array.isArray(w)?w.length===2?(n+=`uniform vec2 ${C};
157
157
  `,o[C]={value:new y.Vector2(...w)}):w.length===3?(n+=`uniform vec3 ${C};
158
158
  `,o[C]={value:new y.Vector3(...w)}):w.length===4&&(n+=`uniform vec4 ${C};
159
159
  `,o[C]={value:new y.Vector4(...w)}):(n+=`uniform float ${C};
160
- `,o[C]={value:w});const c=i!==void 0,l=(a||c?Ae.declChunk:"")+`
160
+ `,o[C]={value:w});const a=i!==void 0,l=(c||a?De.declChunk:"")+`
161
161
  `+n,d=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
162
162
  `,h=s.isTraveler?`vec2 resultUv = screenUv;
163
163
  `:`vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
164
- `,f=a||c?d+h+((i==null?void 0:i.uvModifier)||""):"",p=a||c?Ae.baseColorChunk:"",g=(i==null?void 0:i.colorModifier)||"",v=Me.fragmentShader.replace("#INJECT_DECLARATIONS",l).replace("#INJECT_UV_MODIFIER",f).replace("#INJECT_BASE_COLOR",p).replace("#INJECT_COLOR_MODIFIER",g),b=ce(s.backgroundColor),M=ce(s.borderColor),D={uSize:{value:new y.Vector2(e,t)},uBgColor:{value:new y.Vector4(b.color.r,b.color.g,b.color.b,b.alpha)},uBorderColor:{value:new y.Vector4(M.color.r,M.color.g,M.color.b,M.alpha)},uBorderRadius:{value:new y.Vector4(0,0,0,0)},uBorderWidth:{value:ie(s.borderWidth)},uOpacity:{value:(x=s.opacity)!=null?x:1},uTexture:{value:null},uTextureRepeat:{value:new y.Vector2(1,1)},uTextureOffset:{value:new y.Vector2(0,0)},uGradientCount:{value:0},uGradientAngle:{value:0},uGradientColors:{value:Array.from({length:8},()=>new y.Vector4(0,0,0,0))},uGradientStops:{value:new Float32Array(8)}};De(D.uBorderRadius.value,s.borderRadius,Math.min(e,t)),a&&(D.uTexture.value=r);const T=new y.ShaderMaterial({uniforms:te(te({},D),o),vertexShader:Me.vertexShader,fragmentShader:v,transparent:!0,side:y.FrontSide});return s.backgroundImage&&be(T,{backgroundImage:s.backgroundImage}),T}function Ke(s,e,t,r,i){const a=ie(e.borderWidth);be(s,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:a,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage})}function be(s,e){var r,i,a;if(e.width!==void 0&&e.height!==void 0&&s.uniforms.uSize.value.set(e.width,e.height),e.borderRadius!==void 0){const n=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(s.uniforms.uSize.value.x,s.uniforms.uSize.value.y);De(s.uniforms.uBorderRadius.value,e.borderRadius,n)}if(e.borderWidth!==void 0&&(s.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],n)}else if(typeof e.backgroundColor=="string"){const n=ce(e.backgroundColor);s.uniforms.uBgColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,n)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],n)}else if(typeof e.borderColor=="string"){const n=ce(e.borderColor);s.uniforms.uBorderColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,n)}e.opacity!==void 0&&(s.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(s.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(s.uniforms.uBorderColor.value.w=e.borderOpacity),s.uniforms.uTexture&&e.texture!==void 0&&(s.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=s.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const n=t.image.naturalWidth||t.image.videoWidth||t.image.width,o=t.image.naturalHeight||t.image.videoHeight||t.image.height,c=(i=e.width)!=null?i:s.uniforms.uSize.value.x,l=(a=e.height)!=null?a:s.uniforms.uSize.value.y;if(n&&o&&c&&l){const d=n/o,h=c/l;if(d>h){const f=h/d;s.uniforms.uTextureRepeat.value.set(f,1),s.uniforms.uTextureOffset.value.set((1-f)/2,0)}else{const f=d/h;s.uniforms.uTextureRepeat.value.set(1,f),s.uniforms.uTextureOffset.value.set(0,(1-f)/2)}}}else s.uniforms.uTextureRepeat&&(s.uniforms.uTextureRepeat.value.set(1,1),s.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const n=We(e.backgroundImage);if(n){s.uniforms.uGradientCount.value=n.stops.length,s.uniforms.uGradientAngle.value=n.angle;for(let o=0;o<8;o++)if(o<n.stops.length){const c=n.stops[o];s.uniforms.uGradientColors.value[o].set(c.color.r,c.color.g,c.color.b,c.alpha),s.uniforms.uGradientStops.value[o]=c.stop}else s.uniforms.uGradientColors.value[o].set(0,0,0,0),s.uniforms.uGradientStops.value[o]=1}else s.uniforms.uGradientCount.value=0}for(const n of Object.keys(e))n!=="width"&&n!=="height"&&n!=="borderRadius"&&n!=="borderWidth"&&n!=="backgroundColor"&&n!=="borderColor"&&n!=="opacity"&&n!=="bgOpacity"&&n!=="borderOpacity"&&n!=="texture"&&n!=="backgroundImage"&&s.uniforms[n]!==void 0&&(s.uniforms[n].value!==void 0&&s.uniforms[n].value!==null&&typeof s.uniforms[n].value.set=="function"?Array.isArray(e[n])?s.uniforms[n].value.set(...e[n]):e[n]!==void 0&&(e[n].copy?s.uniforms[n].value.copy(e[n]):s.uniforms[n].value=e[n]):s.uniforms[n].value=e[n])}function De(s,e,t=0){var c,l,d,h;if(e==null){s.set(0,0,0,0);return}if(typeof e=="number"){s.set(e,e,e,e);return}if(Array.isArray(e)){s.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=ie(r[0],t),a=ie((c=r[1])!=null?c:r[0],t),n=ie((l=r[2])!=null?l:r[0],t),o=ie((h=(d=r[3])!=null?d:r[1])!=null?h:r[0],t);s.set(i,a,n,o)}const P={create(s,e,t,r,i,a=2,n=null,o){return s==="BOX"?je(e,r,i,n,o):s==="TEXT"?new Ve(t||"",e,r,i,a):new y.MeshBasicMaterial({visible:!1})},update(s,e,t,r,i,a,n=2,o){e==="BOX"?Ke(s,t,i,a,o):e==="TEXT"&&s.updateText(r||"",t,i,a,n)},forceUpdateUniforms(s,e){be(s,e)}};class Je{constructor(e,t=!0){u(this,"observer");u(this,"textures",new WeakMap);u(this,"loadStatus",new WeakMap);u(this,"elementUrls",new WeakMap);u(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const a=i.target;i.isIntersecting?this.loadTexture(a):this.disposeTexture(a)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return Be(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((a,n)=>{const o=new Image;o.onload=()=>a(o),o.onerror=n,o.src=t});else{const n=yield(yield fetch(t)).blob();r=yield createImageBitmap(n,{imageOrientation:"flipY"})}if(this.elementUrls.get(e)!==t){"close"in r&&r.close();return}const i=new y.Texture(r);r instanceof HTMLImageElement||(i.flipY=!1),i.colorSpace=y.LinearSRGBColorSpace,i.needsUpdate=!0,this.textures.set(e,i),this.onUpdate(e,i)}catch(r){console.warn("[MirageEngine] Failed to load texture:",t,r)}finally{this.elementUrls.has(e)&&this.loadStatus.set(e,!1)}}})}disposeTexture(e){const t=this.textures.get(e);t&&(t.dispose(),this.textures.delete(e),this.onUpdate(e,null)),this.loadStatus.set(e,!1)}get(e){return this.textures.get(e)}disposeAll(){this.observer&&this.observer.disconnect()}}class Qe{constructor(e,t,r,i){u(this,"canvas");u(this,"scene");u(this,"camera");u(this,"renderer");u(this,"renderTargets",[]);u(this,"renderOrder",0);u(this,"qualityFactor",2);u(this,"mode","overlay");u(this,"canvasSize","viewport");u(this,"clipArea",1);u(this,"targetLayer","base");u(this,"overscan",200);u(this,"target");u(this,"mountContainer");u(this,"registry");u(this,"targetRect");u(this,"travelersByLayer",Array.from({length:B.MAX_LAYERS},()=>new Set));u(this,"textureManager");u(this,"fixedMeshes",new Set);var o,c,l,d,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(o=t.mode)!=null?o:"overlay",this.canvasSize=(c=t.canvasSize)!=null?c:"viewport",this.clipArea=(l=t.travelerClipArea)!=null?l:1,this.targetLayer=(d=t.layer)!=null?d:"base",this.textureManager=new Je((f,p)=>{const g=this.registry.get(f);g&&g.material instanceof y.ShaderMaterial&&P.forceUpdateUniforms(g.material,{texture:p})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new y.Scene,this.targetRect=this.target.getBoundingClientRect();const a=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,n=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.camera=new y.OrthographicCamera(a/-2,a/2,n/2,n/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(this.getSceneLayer()),this.renderer=new y.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),y.ColorManagement.enabled=!1,this.renderer.outputColorSpace=y.LinearSRGBColorSpace,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(a,n),this.applyTextQuality((h=t.quality)!=null?h:"medium")}get isViewport(){return this.mode==="overlay"&&this.canvasSize==="viewport"}getSceneLayer(){return typeof this.targetLayer=="number"?this.targetLayer:this.targetLayer==="selected"?N.SELECTED:N.BASE}createRenderTarget(){for(let e=0;e<B.MAX_LAYERS;e++){const t=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,r=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.renderTargets.push(new y.WebGLRenderTarget(t*this.qualityFactor,r*this.qualityFactor,{minFilter:y.LinearFilter,magFilter:y.LinearFilter,format:y.RGBAFormat,stencilBuffer:!1,depthBuffer:!0}))}}applyTextQuality(e){if(typeof e=="number"){this.qualityFactor=Math.max(.1,e);return}switch(e){case"low":this.qualityFactor=1;break;case"high":this.qualityFactor=4;break;case"medium":this.qualityFactor=2;break;default:this.qualityFactor=2;break}}mount(){this.mountContainer.prepend(this.canvas),this.canvas.style.pointerEvents=this.mode==="overlay"?"none":"auto",this.updateCanvasLayout()}updateCanvasLayout(){const e=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,t=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.mode==="duplicate"?(this.canvas.style.position="",this.canvas.style.top="",this.canvas.style.left="",this.canvas.style.display="block"):(this.canvas.style.position=this.isViewport?"fixed":"absolute",this.canvas.style.top=this.isViewport?`-${this.overscan}px`:`${this.target.offsetTop}px`,this.canvas.style.left=this.isViewport?`-${this.overscan}px`:`${this.target.offsetLeft}px`,this.canvas.style.display="block")}updateUniforms(e,t){const r=this.registry.get(e);r&&(r.traverse(i=>{i.isMesh&&i.material&&P.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&P.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,a=this.isViewport?window.innerHeight+this.overscan*2:r.height,n=this.isViewport?this.canvas.clientWidth:this.targetRect.width,o=this.isViewport?this.canvas.clientHeight:this.targetRect.height,c=Math.abs(i-n)>.1||Math.abs(a-o)>.1,l=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);c?(this.targetRect=r,this.setSize(i,a),this.updateCanvasLayout()):l?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(d=>{const h=this.registry.get(d);if(h){this.scene.remove(h);for(const f of this.travelersByLayer)f.delete(h);this.fixedMeshes.delete(h),h.geometry.dispose(),h.userData.nativeMesh&&(this.scene.remove(h.userData.nativeMesh),Array.isArray(h.userData.nativeMesh.material)?h.userData.nativeMesh.material.forEach(f=>f.dispose()):h.userData.nativeMesh.material.dispose(),h.userData.nativeMesh.geometry.dispose()),h.traverse(f=>{f instanceof y.Mesh&&(f.geometry&&f.geometry.dispose(),f.material&&(Array.isArray(f.material)?f.material.forEach(p=>p.dispose()):f.material.dispose()))}),this.registry.remove(d),this.textureManager.unregister(d)}})}reconcileNode(e){var i,a;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof y.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const n=new y.PlaneGeometry(1,1),o=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),c=P.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,o,e.shaderHooks);t=new y.Mesh(n,c),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=c,t.userData.domElement=e.element,t.userData.shaderHash=r}if((a=e.nativeStyles)!=null&&a.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let n=0;n<B.MAX_LAYERS;n++)n===e.captureLayer-2?this.travelersByLayer[n].add(t):this.travelersByLayer[n].delete(t);else for(const n of this.travelersByLayer)n.delete(t);if(e.isFixed?this.fixedMeshes.add(t):this.fixedMeshes.delete(t),e.styles.imageSrc?this.textureManager.register(e.element,e.styles.imageSrc):this.textureManager.unregister(e.element),e.type==="BOX")for(const n of e.children)this.reconcileNode(n);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var l;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],a=r?t.nativeStyles:t.textStyles,n=JSON.stringify(a)+t.textContent+i.map(d=>d.text).join("|"),o=(l=e.userData)==null?void 0:l.textChildStyleHash;if(t.dirtyMask&ye||n!==o){e.children.filter(g=>g.name.startsWith("TEXT_CHILD")).forEach(g=>{var b;const v=g;(b=v.material.map)==null||b.dispose(),v.geometry.dispose(),e.remove(v)});const h=t.rect,f=h.x+h.width/2,p=h.y+h.height/2;i.forEach((g,v)=>{const b=P.create("TEXT",a,g.text,g.rect.width,g.rect.height,this.qualityFactor),M=new y.PlaneGeometry(1,1),D=new y.Mesh(M,b);D.name=`TEXT_CHILD_${v}`;const T=t.rect.width===0?1:g.rect.width/t.rect.width,x=t.rect.height===0?1:g.rect.height/t.rect.height;D.scale.set(T,x,1);const C=g.rect.x+g.rect.width/2,w=g.rect.y+g.rect.height/2,R=C-f,k=-(w-p);D.position.set(t.rect.width===0?0:R/t.rect.width,t.rect.height===0?0:k/t.rect.height,.005),e.add(D)}),e.userData.textChildStyleHash=n}e.children.forEach(d=>{if(!d.name.startsWith("TEXT_CHILD"))return;const h=d,f=t.visibility&K?N.BASE:N.HIDDEN;if(h.layers.set(f),t.visibility&re&&h.layers.enable(N.SELECTED),t.visibility&K)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let p=t.captureLayer;p<t.nativeLayer;p++)h.layers.enable(N.getCaptureLayer(p));else if(r&&t.nativeLayer!==void 0)for(let p=Math.max(t.captureLayer,t.nativeLayer);p<=B.MAX_LAYERS+1;p++)h.layers.enable(N.getCaptureLayer(p));else for(let p=t.captureLayer;p<=B.MAX_LAYERS+1;p++)h.layers.enable(N.getCaptureLayer(p))})}updateMeshProperties(e,t){var T,x,C;const{rect:r,styles:i}=t,a=this.renderer.getPixelRatio(),n=this.renderer.domElement.width/a,o=this.renderer.domElement.height/a;e.material=e.userData.baseMaterial,e.scale.set(r.width,r.height,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const c=.001;this.renderOrder++;const l=this.targetRect.left+window.scrollX,d=this.targetRect.top+window.scrollY;let h,f;if(this.isViewport)h=r.x-window.innerWidth/2+r.width/2,f=-r.y+window.innerHeight/2-r.height/2;else{const w=r.x-l,R=r.y-d;h=w-n/2+r.width/2,f=-R+o/2-r.height/2}e.position.set(h,f,i.zIndex+this.renderOrder*c);const p=r.x,g=r.y;e.userData.basePosition={x:h,y:f},e.userData.originalBasePosition={x:h,y:f},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:p,y:g},e.userData.isFixed=t.isFixed,e.userData.initialScroll={x:window.scrollX,y:window.scrollY};const v=t.element.nodeType===Node.TEXT_NODE?t.element.parentElement:t.element,b=window.getComputedStyle(v);let M=0,D=0;if(b.transform&&b.transform!=="none"){const w=new DOMMatrix(b.transform);M=w.m41,D=w.m42}if(e.userData.baseTransform={x:M,y:D},delete e.userData.originRatioX,delete e.userData.originRatioY,P.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(T=this.renderTargets[t.captureLayer-2])==null?void 0:T.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const G=P.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(x=this.renderTargets[t.captureLayer-2])==null?void 0:x.texture:this.textureManager.get(t.element),t.shaderHooks),W=new y.Mesh(e.geometry,G);t.type==="TEXT"&&(W.name="BG_MESH"),this.scene.add(W),e.userData.nativeMesh=W}const w=e.userData.nativeMesh;let R,k;if(this.isViewport)R=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,k=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const G=t.nativeRect.x-l,W=t.nativeRect.y-d;R=G-n/2+t.nativeRect.width/2,k=-W+o/2-t.nativeRect.height/2}let F=t.nativeRect.width,Q=t.nativeRect.height,le=R,he=k;if(t.nativeStyles.transform){const G=t.nativeStyles.transform,W=G.match(/scale\(([\d.]+%?)\)/);if(W){let z=parseFloat(W[1]);W[1].includes("%")&&(z/=100),F*=z,Q*=z}const se=G.match(/translate\(([^,]+),\s*([^)]+)\)/);if(se){const z=se[1].trim(),Y=se[2].trim();let m=parseFloat(z);z.includes("%")&&(m=m/100*t.nativeRect.width);let L=parseFloat(Y);Y.includes("%")&&(L=L/100*t.nativeRect.height),le+=m,he-=L}const de=G.match(/translateX\(([^)]+)\)/);if(de){const z=de[1].trim();let Y=parseFloat(z);z.includes("%")&&(Y=Y/100*t.nativeRect.width),le+=Y}const ue=G.match(/translateY\(([^)]+)\)/);if(ue){const z=ue[1].trim();let Y=parseFloat(z);z.includes("%")&&(Y=Y/100*t.nativeRect.height),he-=Y}}w.scale.set(F,Q,1),w.position.set(le,he,t.nativeStyles.zIndex+this.renderOrder*c),P.update(w.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(C=this.renderTargets[t.captureLayer-2])==null?void 0:C.texture:this.textureManager.get(t.element))}else e.userData.nativeMesh&&(this.scene.remove(e.userData.nativeMesh),e.userData.nativeMesh.material instanceof y.Material&&e.userData.nativeMesh.material.dispose(),delete e.userData.nativeMesh)}updateMeshLayers(e,t){const r=t.visibility&K?N.BASE:N.HIDDEN;if(e.layers.set(r),t.visibility&re&&e.layers.enable(N.SELECTED),e.userData.nativeMesh&&t.nativeLayer!==void 0){const i=e.userData.nativeMesh;if(i.layers.set(N.HIDDEN),t.visibility&K){for(let a=t.captureLayer;a<t.nativeLayer;a++)e.layers.enable(N.getCaptureLayer(a));for(let a=Math.max(t.captureLayer,t.nativeLayer);a<=B.MAX_LAYERS+1;a++)i.layers.enable(N.getCaptureLayer(a))}}else if(t.visibility&K)for(let i=t.captureLayer;i<=B.MAX_LAYERS+1;i++)e.layers.enable(N.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new y.Color,a=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const n=new y.Vector3,o=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,c=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,l=this.renderer.getPixelRatio();for(const d of e){n.setFromMatrixPosition(d.matrixWorld),n.project(this.camera);const h=(n.x+1)/2*o,f=(n.y+1)/2*c;let p=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(p=parseFloat(this.clipArea));const v=d.scale.x*g+.5,b=d.scale.y*g+.5,M=h-v/2,D=f-b/2,T=(M*this.qualityFactor-p)/l,x=(D*this.qualityFactor-p)/l,C=(v*this.qualityFactor+p*2)/l,w=(b*this.qualityFactor+p*2)/l;this.renderer.setScissor(T,x,C,w),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,a)}render(){for(let e=0;e<B.MAX_LAYERS;e++){const t=e+1;this.captureRenderTarget(this.travelersByLayer[e],N.getCaptureLayer(t),this.renderTargets[e])}this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,a=this.renderer.domElement.height/r;this.scene.children.forEach(n=>{const o=n;if(!o.userData||!o.userData.domElement)return;const c=o.userData.domElement;if(!c.isConnected)return;let l;if(c.nodeType===Node.TEXT_NODE){const h=document.createRange();h.selectNode(c),l=h.getBoundingClientRect()}else l=c.getBoundingClientRect();const d=o.userData.domRect;if(!d||Math.abs(l.x-d.x)>.5||Math.abs(l.y-d.y)>.5||Math.abs(l.width-d.width)>.5||Math.abs(l.height-d.height)>.5){o.userData.domRect={x:l.x,y:l.y,width:l.width,height:l.height};let h,f;if(this.isViewport)h=l.x-window.innerWidth/2+l.width/2,f=-l.y+window.innerHeight/2-l.height/2;else{const p=l.x-e,g=l.y-t;h=p-i/2+l.width/2,f=-g+a/2-l.height/2}if(o.position.setX(h),o.position.setY(f),o.scale.set(l.width,l.height,1),o.updateMatrixWorld(),o.material instanceof y.ShaderMaterial&&P.forceUpdateUniforms(o.material,{width:l.width,height:l.height}),o.userData.nativeMesh){const p=o.userData.nativeMesh;let g=l.width,v=l.height,b=h,M=f;if(o.userData.nativeTransform){const D=o.userData.nativeTransform,T=D.match(/scale\(([\d.]+%?)\)/);if(T){let R=parseFloat(T[1]);T[1].includes("%")&&(R/=100),g*=R,v*=R}const x=D.match(/translate\(([^,]+),\s*([^)]+)\)/);if(x){const R=x[1].trim(),k=x[2].trim();let F=parseFloat(R);R.includes("%")&&(F=F/100*l.width);let Q=parseFloat(k);k.includes("%")&&(Q=Q/100*l.height),b+=F,M-=Q}const C=D.match(/translateX\(([^)]+)\)/);if(C){const R=C[1].trim();let k=parseFloat(R);R.includes("%")&&(k=k/100*l.width),b+=k}const w=D.match(/translateY\(([^)]+)\)/);if(w){const R=w[1].trim();let k=parseFloat(R);R.includes("%")&&(k=k/100*l.height),M-=k}}p.position.setX(b),p.position.setY(M),p.scale.set(g,v,1),p.updateMatrixWorld()}}})}}function Ze(s){const e=s.textContent||"",t=[];let r="",i=null,a=-1;const n=(l,d)=>{for(let h=0;h<l.length;h++){const f=l[h],p=document.createRange();p.setStart(s,d+h),p.setEnd(s,d+h+1);const g=p.getBoundingClientRect();if(g.width===0&&g.height===0){r+=f;continue}a===-1||Math.abs(g.top-a)>g.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=f,i={left:g.left,top:g.top,right:g.right,bottom:g.bottom},a=g.top):(r+=f,i&&(i.left=Math.min(i.left,g.left),i.top=Math.min(i.top,g.top),i.right=Math.max(i.right,g.right),i.bottom=Math.max(i.bottom,g.bottom)))}},o=e.match(/[^\s\-]+\-?|\-|\s+/g)||[];let c=0;for(const l of o){const d=document.createRange();d.setStart(s,c),d.setEnd(s,c+l.length);const h=d.getClientRects();if(h.length>1)n(l,c);else{const f=h.length===1?h[0]:d.getBoundingClientRect();if(f.width===0&&f.height===0){r+=l,c+=l.length;continue}a===-1||Math.abs(f.top-a)>f.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=l,i={left:f.left,top:f.top,right:f.right,bottom:f.bottom},a=f.top):(r+=l,i&&(i.left=Math.min(i.left,f.left),i.top=Math.min(i.top,f.top),i.right=Math.max(i.right,f.right),i.bottom=Math.max(i.bottom,f.bottom)))}c+=l.length}return r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),t.filter(l=>l.text.trim().length>0&&l.rect.width>0&&l.rect.height>0)}function ke(s){const e=parseFloat(s.fontSize);let t=parseFloat(s.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(s.letterSpacing);return isNaN(r)&&(r=0),{font:`${s.fontStyle} ${s.fontWeight} ${s.fontSize} ${s.fontFamily}`,fontSize:s.fontSize,color:s.color,textAlign:s.textAlign||"start",textBaseline:"alphabetic",direction:s.direction||"inherit",lineHeight:t,letterSpacing:r}}function Ie(s,e=ee|ae|Ne|ye|me,t,r=1,i=0,a=2,n,o){var W,se,de,ue,z,Y;if(s.nodeType===Node.TEXT_NODE){const m=s;if(!m.textContent||!m.textContent.trim())return null;const L=m.textContent.replace(/\s+/g," ");if(L.length===0)return null;const X=Ze(m);if(X.length===0)return null;const $=m.parentElement,_=$?window.getComputedStyle($):null;if(!_)return null;const J=Math.min(...X.map(E=>E.rect.left)),H=Math.min(...X.map(E=>E.rect.top)),Z=Math.max(...X.map(E=>E.rect.left+E.rect.width)),I=Math.max(...X.map(E=>E.rect.top+E.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:m,rect:{x:J+window.scrollX,y:H+window.scrollY,width:Z-J,height:I-H},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:$&&$.dataset[j.KEY]===j.VALUES.HIDE?1:parseFloat(_.opacity),zIndex:(isNaN(parseInt(_.zIndex))?0:parseInt(_.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:L,textLines:X.map(E=>({text:E.text.trim(),rect:{x:E.rect.left+window.scrollX,y:E.rect.top+window.scrollY,width:E.rect.width,height:E.rect.height}})),textStyles:ke(_),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:_.position==="fixed",nativeLayer:n,nativeStyles:o?te(te({backgroundColor:"transparent",backgroundImage:"",opacity:$&&$.dataset[j.KEY]===j.VALUES.HIDE?1:parseFloat(_.opacity),zIndex:(isNaN(parseInt(_.zIndex))?0:parseInt(_.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},ke(_)),o):void 0,nativeRect:o?{x:J+window.scrollX,y:H+window.scrollY,width:Z-J,height:I-H}:void 0,children:[]}}if(s.nodeType!==Node.ELEMENT_NODE)return null;const c=s,l=c.dataset[O.KEY];let d=t,h=t;if(l){const m=new Set(l.split(/\s+/));for(const L of m)if(!Re.includes(L))throw new Error(`[MirageEngine] Invalid filter token: '${L}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(m.has(O.VALUES.END))return null;if(m.has(O.VALUES.INCLUDE_TREE)&&m.has(O.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(m.has(O.VALUES.INCLUDE_SELF)&&m.has(O.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");m.has(O.VALUES.INCLUDE_TREE)?d=d|K:m.has(O.VALUES.EXCLUDE_TREE)&&(d=d&~K),h=d,m.has(O.VALUES.INCLUDE_SELF)?h=h|K:m.has(O.VALUES.EXCLUDE_SELF)&&(h=h&~K)}const f=c.dataset[V.KEY];if(f){const m=new Set(f.split(/\s+/));for(const L of m)if(!Re.includes(L))throw new Error(`[MirageEngine] Invalid select token: '${L}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(m.has(V.VALUES.END))return null;if(m.has(V.VALUES.INCLUDE_TREE)&&m.has(V.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(m.has(V.VALUES.INCLUDE_SELF)&&m.has(V.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");m.has(V.VALUES.INCLUDE_TREE)?d=d|re:m.has(V.VALUES.EXCLUDE_TREE)&&(d=d&~re),h=d,m.has(V.VALUES.INCLUDE_SELF)?h=h|re:m.has(V.VALUES.EXCLUDE_SELF)&&(h=h&~re)}const p=c.dataset[B.KEY];let g=!1,v=o?te({},o):{},b=n;if(p){let m=1;const L=p.indexOf("{"),X=p.lastIndexOf("}");let $=p;if(L!==-1&&X!==-1&&X>L){$=p.substring(0,L).trim();const I=p.substring(L,X+1);try{v=new Function("return "+I)()}catch(E){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${I}`)}}const _=$.split(/\s+/);let J=!1;const H=_.indexOf(B.VALUES.TRAVELER);if(H!==-1){g=!0,J=!0;const I=_[H+1];if(I&&!isNaN(parseInt(I,10)))m=parseInt(I,10);else{const E=_.find(ne=>!isNaN(parseInt(ne,10)));E&&(m=parseInt(E,10))}}const Z=_.indexOf(B.VALUES.NATIVE);if(Z!==-1){const I=_[Z+1];if(I&&!isNaN(parseInt(I,10)))b=parseInt(I,10);else if(!g){const E=_.find(ne=>!isNaN(parseInt(ne,10)));E&&(b=parseInt(E,10))}}if(J){const I=m+1;if(I<r)throw new Error(`[MirageEngine] Traveler layer (${m}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(I,B.MAX_LAYERS+1)}}const M=c.dataset[Fe.KEY];let D;M&&(D=JSON.parse(M));const T=c.getBoundingClientRect(),x=window.getComputedStyle(c);if(T.width===0||T.height===0||x.display==="none")return null;let C=c.getAttribute("data-mid");C||(C=Math.random().toString(36).substring(2,11),c.setAttribute("data-mid",C));const w=parseInt(x.zIndex),R=(isNaN(w)?0:w)+i;let k;if(c.tagName==="IMG")k=c.src;else if(c.tagName.toLowerCase()==="svg"){const m=c.cloneNode(!0),L=v==null?void 0:v.color,X=v==null?void 0:v.fill,$=v==null?void 0:v.stroke,_=v==null?void 0:v.opacity,J=(E,ne)=>{const q=window.getComputedStyle(E),fe=ne,ot=q.fill===q.color,at=q.stroke===q.color,we=X||(ot?L:void 0)||q.fill;we&&we!=="none"&&(fe.style.fill=we);const xe=$||(at?L:void 0)||q.stroke;xe&&xe!=="none"&&(fe.style.stroke=xe),q.strokeWidth&&q.strokeWidth!=="0px"&&(fe.style.strokeWidth=q.strokeWidth);const Ue=L||q.color;Ue&&(fe.style.color=Ue);const Ee=_||q.opacity;Ee&&Ee!=="1"&&(fe.style.opacity=Ee);for(let ve=0;ve<E.children.length;ve++)J(E.children[ve],ne.children[ve])};J(c,m);const H=c.getBoundingClientRect(),Z=window.devicePixelRatio*a;m.hasAttribute("viewBox")||m.setAttribute("viewBox",`0 0 ${H.width} ${H.height}`),m.setAttribute("width",(H.width*Z).toString()),m.setAttribute("height",(H.height*Z).toString());let I=new XMLSerializer().serializeToString(m);I.includes("xmlns=")||(I=I.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),k=`data:image/svg+xml;utf8,${encodeURIComponent(I)}`}else if(x.backgroundImage&&x.backgroundImage!=="none"){const m=x.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);m&&(k=m[1])}const F={backgroundColor:x.backgroundColor,backgroundImage:x.backgroundImage,opacity:c.dataset[j.KEY]===j.VALUES.HIDE?1:parseFloat(x.opacity),zIndex:R,borderRadius:x.borderRadius,borderColor:x.borderColor,borderWidth:x.borderWidth,imageSrc:k,isTraveler:g},Q=F;let le,he;const G=[];return c.tagName.toLowerCase()!=="svg"&&Array.from(c.childNodes).forEach(m=>{const L=m.nodeType===Node.TEXT_NODE?h:d,X=Ie(m,e,L,r,R,a,m.nodeType===Node.TEXT_NODE?b:void 0,m.nodeType===Node.TEXT_NODE&&Object.keys(v).length>0?v:void 0);X&&G.push(X)}),{id:C,type:"BOX",element:c,rect:{x:T.left+window.scrollX,y:T.top+window.scrollY,width:T.width,height:T.height},styles:Q,textContent:le,textStyles:he,dirtyMask:e,visibility:h,isTraveler:g,captureLayer:r,nativeLayer:b,nativeStyles:b!==void 0?_e(te({},F),{backgroundColor:(W=v.backgroundColor)!=null?W:F.backgroundColor,backgroundImage:(se=v.backgroundImage)!=null?se:F.backgroundImage,opacity:(de=v.opacity)!=null?de:F.opacity,zIndex:v.zIndex!==void 0?v.zIndex+R:F.zIndex,borderRadius:(ue=v.borderRadius)!=null?ue:F.borderRadius,borderColor:(z=v.borderColor)!=null?z:F.borderColor,borderWidth:(Y=v.borderWidth)!=null?Y:F.borderWidth,isTraveler:F.isTraveler,transform:v.transform}):void 0,nativeRect:b!==void 0?{x:v.x!==void 0?parseFloat(v.x):T.left+window.scrollX,y:v.y!==void 0?parseFloat(v.y):T.top+window.scrollY,width:v.width!==void 0?parseFloat(v.width):T.width,height:v.height!==void 0?parseFloat(v.height):T.height}:void 0,isFixed:x.position==="fixed",children:G,shaderHooks:D}}function et(s,e){e.size!==0&&e.forEach((t,r)=>{var a,n,o,c;const i=s.get(r);!i||!i.userData.basePosition||(P.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(n=t.borderRadius)!=null?n:(a=i.userData.baseStyles)==null?void 0:a.borderRadius}),i.userData.nativeMesh&&P.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(c=t.borderRadius)!=null?c:(o=i.userData.baseStyles)==null?void 0:o.borderRadius}))})}class tt{constructor(e,t,r,i){u(this,"target");u(this,"renderer");u(this,"registry");u(this,"isTravelEnabled",!1);u(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new Te(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((a,n)=>{document.querySelector(`[${B.NAME}~='${B.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const c=Ie(this.target,a,K,1,0,this.renderer.qualityFactor);c&&this.renderer.syncScene(c,n)}),this.tracker.onStyleChange.add(a=>{et(this.registry,a)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class rt{constructor(){u(this,"store");this.store=new WeakMap}register(e,t){this.store.set(e,t)}get(e){return this.store.get(e)}has(e){return this.store.has(e)}remove(e){this.store.delete(e)}}class it{constructor(e,t){u(this,"renderer");u(this,"syncer");u(this,"target");u(this,"registry");var i,a,n;if(this.target=e,this.registry=new rt,!document.getElementById("mirage-engine-styles")){const o=document.createElement("style");o.id="mirage-engine-styles",o.textContent=`
165
- [${j.NAME}="${j.VALUES.HIDE}"] {
164
+ `,f=c||a?d+h+((i==null?void 0:i.uvModifier)||""):"",v=c||a?De.baseColorChunk:"",g=(i==null?void 0:i.colorModifier)||"",m=Me.fragmentShader.replace("#INJECT_DECLARATIONS",l).replace("#INJECT_UV_MODIFIER",f).replace("#INJECT_BASE_COLOR",v).replace("#INJECT_COLOR_MODIFIER",g),b=ce(s.backgroundColor),M=ce(s.borderColor),A={uSize:{value:new y.Vector2(e,t)},uBgColor:{value:new y.Vector4(b.color.r,b.color.g,b.color.b,b.alpha)},uBorderColor:{value:new y.Vector4(M.color.r,M.color.g,M.color.b,M.alpha)},uBorderRadius:{value:new y.Vector4(0,0,0,0)},uBorderWidth:{value:ie(s.borderWidth)},uOpacity:{value:(x=s.opacity)!=null?x:1},uTexture:{value:null},uTextureRepeat:{value:new y.Vector2(1,1)},uTextureOffset:{value:new y.Vector2(0,0)},uGradientCount:{value:0},uGradientAngle:{value:0},uGradientColors:{value:Array.from({length:8},()=>new y.Vector4(0,0,0,0))},uGradientStops:{value:new Float32Array(8)}};Ae(A.uBorderRadius.value,s.borderRadius,Math.min(e,t)),c&&(A.uTexture.value=r);const T=new y.ShaderMaterial({uniforms:te(te({},A),o),vertexShader:Me.vertexShader,fragmentShader:m,transparent:!0,side:y.FrontSide});return s.backgroundImage&&be(T,{backgroundImage:s.backgroundImage}),T}function Ke(s,e,t,r,i){const c=ie(e.borderWidth);be(s,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:c,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage})}function be(s,e){var r,i,c;if(e.width!==void 0&&e.height!==void 0&&s.uniforms.uSize.value.set(e.width,e.height),e.borderRadius!==void 0){const n=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(s.uniforms.uSize.value.x,s.uniforms.uSize.value.y);Ae(s.uniforms.uBorderRadius.value,e.borderRadius,n)}if(e.borderWidth!==void 0&&(s.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],n)}else if(typeof e.backgroundColor=="string"){const n=ce(e.backgroundColor);s.uniforms.uBgColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,n)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],n)}else if(typeof e.borderColor=="string"){const n=ce(e.borderColor);s.uniforms.uBorderColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,n)}e.opacity!==void 0&&(s.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(s.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(s.uniforms.uBorderColor.value.w=e.borderOpacity),s.uniforms.uTexture&&e.texture!==void 0&&(s.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=s.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const n=t.image.naturalWidth||t.image.videoWidth||t.image.width,o=t.image.naturalHeight||t.image.videoHeight||t.image.height,a=(i=e.width)!=null?i:s.uniforms.uSize.value.x,l=(c=e.height)!=null?c:s.uniforms.uSize.value.y;if(n&&o&&a&&l){const d=n/o,h=a/l;if(d>h){const f=h/d;s.uniforms.uTextureRepeat.value.set(f,1),s.uniforms.uTextureOffset.value.set((1-f)/2,0)}else{const f=d/h;s.uniforms.uTextureRepeat.value.set(1,f),s.uniforms.uTextureOffset.value.set(0,(1-f)/2)}}}else s.uniforms.uTextureRepeat&&(s.uniforms.uTextureRepeat.value.set(1,1),s.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const n=We(e.backgroundImage);if(n){s.uniforms.uGradientCount.value=n.stops.length,s.uniforms.uGradientAngle.value=n.angle;for(let o=0;o<8;o++)if(o<n.stops.length){const a=n.stops[o];s.uniforms.uGradientColors.value[o].set(a.color.r,a.color.g,a.color.b,a.alpha),s.uniforms.uGradientStops.value[o]=a.stop}else s.uniforms.uGradientColors.value[o].set(0,0,0,0),s.uniforms.uGradientStops.value[o]=1}else s.uniforms.uGradientCount.value=0}for(const n of Object.keys(e))n!=="width"&&n!=="height"&&n!=="borderRadius"&&n!=="borderWidth"&&n!=="backgroundColor"&&n!=="borderColor"&&n!=="opacity"&&n!=="bgOpacity"&&n!=="borderOpacity"&&n!=="texture"&&n!=="backgroundImage"&&s.uniforms[n]!==void 0&&(s.uniforms[n].value!==void 0&&s.uniforms[n].value!==null&&typeof s.uniforms[n].value.set=="function"?Array.isArray(e[n])?s.uniforms[n].value.set(...e[n]):e[n]!==void 0&&(e[n].copy?s.uniforms[n].value.copy(e[n]):s.uniforms[n].value=e[n]):s.uniforms[n].value=e[n])}function Ae(s,e,t=0){var a,l,d,h;if(e==null){s.set(0,0,0,0);return}if(typeof e=="number"){s.set(e,e,e,e);return}if(Array.isArray(e)){s.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=ie(r[0],t),c=ie((a=r[1])!=null?a:r[0],t),n=ie((l=r[2])!=null?l:r[0],t),o=ie((h=(d=r[3])!=null?d:r[1])!=null?h:r[0],t);s.set(i,c,n,o)}const G={create(s,e,t,r,i,c=2,n=null,o){return s==="BOX"?je(e,r,i,n,o):s==="TEXT"?new Ve(t||"",e,r,i,c):new y.MeshBasicMaterial({visible:!1})},update(s,e,t,r,i,c,n=2,o){e==="BOX"?Ke(s,t,i,c,o):e==="TEXT"&&s.updateText(r||"",t,i,c,n)},forceUpdateUniforms(s,e){be(s,e)}};class Je{constructor(e,t=!0){u(this,"observer");u(this,"textures",new WeakMap);u(this,"loadStatus",new WeakMap);u(this,"elementUrls",new WeakMap);u(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const c=i.target;i.isIntersecting?this.loadTexture(c):this.disposeTexture(c)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return Be(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((c,n)=>{const o=new Image;o.onload=()=>c(o),o.onerror=n,o.src=t});else{const n=yield(yield fetch(t)).blob();r=yield createImageBitmap(n,{imageOrientation:"flipY"})}if(this.elementUrls.get(e)!==t){"close"in r&&r.close();return}const i=new y.Texture(r);r instanceof HTMLImageElement||(i.flipY=!1),i.colorSpace=y.LinearSRGBColorSpace,i.needsUpdate=!0,this.textures.set(e,i),this.onUpdate(e,i)}catch(r){console.warn("[MirageEngine] Failed to load texture:",t,r)}finally{this.elementUrls.has(e)&&this.loadStatus.set(e,!1)}}})}disposeTexture(e){const t=this.textures.get(e);t&&(t.dispose(),this.textures.delete(e),this.onUpdate(e,null)),this.loadStatus.set(e,!1)}get(e){return this.textures.get(e)}disposeAll(){this.observer&&this.observer.disconnect()}}class Qe{constructor(e,t,r,i){u(this,"canvas");u(this,"scene");u(this,"camera");u(this,"renderer");u(this,"renderTargets",[]);u(this,"renderOrder",0);u(this,"qualityFactor",2);u(this,"mode","overlay");u(this,"canvasSize","viewport");u(this,"clipArea",1);u(this,"targetLayer","base");u(this,"overscan",200);u(this,"target");u(this,"mountContainer");u(this,"registry");u(this,"targetRect");u(this,"travelersByLayer",Array.from({length:B.MAX_LAYERS},()=>new Set));u(this,"textureManager");u(this,"fixedMeshes",new Set);var o,a,l,d,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(o=t.mode)!=null?o:"overlay",this.canvasSize=(a=t.canvasSize)!=null?a:"viewport",this.clipArea=(l=t.travelerClipArea)!=null?l:1,this.targetLayer=(d=t.layer)!=null?d:"base",this.textureManager=new Je((f,v)=>{const g=this.registry.get(f);g&&g.material instanceof y.ShaderMaterial&&G.forceUpdateUniforms(g.material,{texture:v})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new y.Scene,this.targetRect=this.target.getBoundingClientRect();const c=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,n=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.camera=new y.OrthographicCamera(c/-2,c/2,n/2,n/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(this.getSceneLayer()),this.renderer=new y.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),y.ColorManagement.enabled=!1,this.renderer.outputColorSpace=y.LinearSRGBColorSpace,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(c,n),this.applyTextQuality((h=t.quality)!=null?h:"medium")}get isViewport(){return this.mode==="overlay"&&this.canvasSize==="viewport"}getSceneLayer(){return typeof this.targetLayer=="number"?this.targetLayer:this.targetLayer==="selected"?F.SELECTED:F.BASE}createRenderTarget(){for(let e=0;e<B.MAX_LAYERS;e++){const t=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,r=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.renderTargets.push(new y.WebGLRenderTarget(t*this.qualityFactor,r*this.qualityFactor,{minFilter:y.LinearFilter,magFilter:y.LinearFilter,format:y.RGBAFormat,stencilBuffer:!1,depthBuffer:!0}))}}applyTextQuality(e){if(typeof e=="number"){this.qualityFactor=Math.max(.1,e);return}switch(e){case"low":this.qualityFactor=1;break;case"high":this.qualityFactor=4;break;case"medium":this.qualityFactor=2;break;default:this.qualityFactor=2;break}}mount(){this.mountContainer.prepend(this.canvas),this.canvas.style.pointerEvents=this.mode==="overlay"?"none":"auto",this.updateCanvasLayout()}updateCanvasLayout(){const e=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,t=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.mode==="duplicate"?(this.canvas.style.position="",this.canvas.style.top="",this.canvas.style.left="",this.canvas.style.display="block"):(this.canvas.style.position=this.isViewport?"fixed":"absolute",this.canvas.style.top=this.isViewport?`-${this.overscan}px`:`${this.target.offsetTop}px`,this.canvas.style.left=this.isViewport?`-${this.overscan}px`:`${this.target.offsetLeft}px`,this.canvas.style.display="block")}updateUniforms(e,t){const r=this.registry.get(e);r&&(r.traverse(i=>{i.isMesh&&i.material&&G.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&G.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,c=this.isViewport?window.innerHeight+this.overscan*2:r.height,n=this.isViewport?this.canvas.clientWidth:this.targetRect.width,o=this.isViewport?this.canvas.clientHeight:this.targetRect.height,a=Math.abs(i-n)>.1||Math.abs(c-o)>.1,l=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);a?(this.targetRect=r,this.setSize(i,c),this.updateCanvasLayout()):l?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(d=>{const h=this.registry.get(d);if(h){this.scene.remove(h);for(const f of this.travelersByLayer)f.delete(h);this.fixedMeshes.delete(h),h.geometry.dispose(),h.userData.nativeMesh&&(this.scene.remove(h.userData.nativeMesh),Array.isArray(h.userData.nativeMesh.material)?h.userData.nativeMesh.material.forEach(f=>f.dispose()):h.userData.nativeMesh.material.dispose(),h.userData.nativeMesh.geometry.dispose()),h.traverse(f=>{f instanceof y.Mesh&&(f.geometry&&f.geometry.dispose(),f.material&&(Array.isArray(f.material)?f.material.forEach(v=>v.dispose()):f.material.dispose()))}),this.registry.remove(d),this.textureManager.unregister(d)}})}reconcileNode(e){var i,c;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof y.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const n=new y.PlaneGeometry(1,1),o=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),a=G.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,o,e.shaderHooks);t=new y.Mesh(n,a),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=a,t.userData.domElement=e.element,t.userData.shaderHash=r}if((c=e.nativeStyles)!=null&&c.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let n=0;n<B.MAX_LAYERS;n++)n===e.captureLayer-2?this.travelersByLayer[n].add(t):this.travelersByLayer[n].delete(t);else for(const n of this.travelersByLayer)n.delete(t);if(e.isFixed?this.fixedMeshes.add(t):this.fixedMeshes.delete(t),e.styles.imageSrc?this.textureManager.register(e.element,e.styles.imageSrc):this.textureManager.unregister(e.element),e.type==="BOX")for(const n of e.children)this.reconcileNode(n);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var l;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],c=r?t.nativeStyles:t.textStyles,n=JSON.stringify(c)+t.textContent+i.map(d=>d.text).join("|"),o=(l=e.userData)==null?void 0:l.textChildStyleHash;if(t.dirtyMask&ye||n!==o){e.children.filter(g=>g.name.startsWith("TEXT_CHILD")).forEach(g=>{var b;const m=g;(b=m.material.map)==null||b.dispose(),m.geometry.dispose(),e.remove(m)});const h=t.rect,f=h.x+h.width/2,v=h.y+h.height/2;i.forEach((g,m)=>{const b=G.create("TEXT",c,g.text,g.rect.width,g.rect.height,this.qualityFactor),M=new y.PlaneGeometry(1,1),A=new y.Mesh(M,b);A.name=`TEXT_CHILD_${m}`;const T=t.rect.width===0?1:g.rect.width/t.rect.width,x=t.rect.height===0?1:g.rect.height/t.rect.height;A.scale.set(T,x,1);const C=g.rect.x+g.rect.width/2,w=g.rect.y+g.rect.height/2,R=C-f,k=-(w-v);A.position.set(t.rect.width===0?0:R/t.rect.width,t.rect.height===0?0:k/t.rect.height,.005),e.add(A)}),e.userData.textChildStyleHash=n}e.children.forEach(d=>{if(!d.name.startsWith("TEXT_CHILD"))return;const h=d;if(r&&t.nativeLayer!==void 0)h.layers.set(F.HIDDEN),t.visibility&P&&h.layers.enable(F.getCaptureLayer(t.nativeLayer));else{const f=t.visibility&P?F.BASE:F.HIDDEN;if(h.layers.set(f),t.visibility&re&&h.layers.enable(F.SELECTED),t.visibility&P)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let v=t.captureLayer;v<=B.MAX_LAYERS+1;v++)v!==t.nativeLayer&&h.layers.enable(F.getCaptureLayer(v));else for(let v=t.captureLayer;v<=B.MAX_LAYERS+1;v++)h.layers.enable(F.getCaptureLayer(v))}})}updateMeshProperties(e,t){var T,x,C;const{rect:r,styles:i}=t,c=this.renderer.getPixelRatio(),n=this.renderer.domElement.width/c,o=this.renderer.domElement.height/c;e.material=e.userData.baseMaterial,e.scale.set(r.width,r.height,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const a=.001;this.renderOrder++;const l=this.targetRect.left+window.scrollX,d=this.targetRect.top+window.scrollY;let h,f;if(this.isViewport)h=r.x-window.innerWidth/2+r.width/2,f=-r.y+window.innerHeight/2-r.height/2;else{const w=r.x-l,R=r.y-d;h=w-n/2+r.width/2,f=-R+o/2-r.height/2}e.position.set(h,f,i.zIndex+this.renderOrder*a);const v=r.x,g=r.y;e.userData.basePosition={x:h,y:f},e.userData.originalBasePosition={x:h,y:f},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:v,y:g},e.userData.isFixed=t.isFixed,e.userData.initialScroll={x:window.scrollX,y:window.scrollY};const m=t.element.nodeType===Node.TEXT_NODE?t.element.parentElement:t.element,b=window.getComputedStyle(m);let M=0,A=0;if(b.transform&&b.transform!=="none"){const w=new DOMMatrix(b.transform);M=w.m41,A=w.m42}if(e.userData.baseTransform={x:M,y:A},delete e.userData.originRatioX,delete e.userData.originRatioY,G.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(T=this.renderTargets[t.captureLayer-2])==null?void 0:T.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const $=G.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(x=this.renderTargets[t.captureLayer-2])==null?void 0:x.texture:this.textureManager.get(t.element),t.shaderHooks),W=new y.Mesh(e.geometry,$);t.type==="TEXT"&&(W.name="BG_MESH"),this.scene.add(W),e.userData.nativeMesh=W}const w=e.userData.nativeMesh;let R,k;if(this.isViewport)R=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,k=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const $=t.nativeRect.x-l,W=t.nativeRect.y-d;R=$-n/2+t.nativeRect.width/2,k=-W+o/2-t.nativeRect.height/2}let N=t.nativeRect.width,Q=t.nativeRect.height,le=R,he=k;if(t.nativeStyles.transform){const $=t.nativeStyles.transform,W=$.match(/scale\(([\d.]+%?)\)/);if(W){let z=parseFloat(W[1]);W[1].includes("%")&&(z/=100),N*=z,Q*=z}const se=$.match(/translate\(([^,]+),\s*([^)]+)\)/);if(se){const z=se[1].trim(),Y=se[2].trim();let p=parseFloat(z);z.includes("%")&&(p=p/100*t.nativeRect.width);let L=parseFloat(Y);Y.includes("%")&&(L=L/100*t.nativeRect.height),le+=p,he-=L}const de=$.match(/translateX\(([^)]+)\)/);if(de){const z=de[1].trim();let Y=parseFloat(z);z.includes("%")&&(Y=Y/100*t.nativeRect.width),le+=Y}const ue=$.match(/translateY\(([^)]+)\)/);if(ue){const z=ue[1].trim();let Y=parseFloat(z);z.includes("%")&&(Y=Y/100*t.nativeRect.height),he-=Y}}w.scale.set(N,Q,1),w.position.set(le,he,t.nativeStyles.zIndex+this.renderOrder*a),G.update(w.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(C=this.renderTargets[t.captureLayer-2])==null?void 0:C.texture:this.textureManager.get(t.element))}else e.userData.nativeMesh&&(this.scene.remove(e.userData.nativeMesh),e.userData.nativeMesh.material instanceof y.Material&&e.userData.nativeMesh.material.dispose(),delete e.userData.nativeMesh)}updateMeshLayers(e,t){const r=t.visibility&P?F.BASE:F.HIDDEN;if(e.layers.set(r),t.visibility&re&&e.layers.enable(F.SELECTED),e.userData.nativeMesh&&t.nativeLayer!==void 0){const i=e.userData.nativeMesh;if(i.layers.set(F.HIDDEN),t.visibility&P){i.layers.enable(F.getCaptureLayer(t.nativeLayer));for(let c=t.captureLayer;c<=B.MAX_LAYERS+1;c++)c!==t.nativeLayer&&e.layers.enable(F.getCaptureLayer(c))}}else if(t.visibility&P)for(let i=t.captureLayer;i<=B.MAX_LAYERS+1;i++)e.layers.enable(F.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new y.Color,c=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const n=new y.Vector3,o=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,a=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,l=this.renderer.getPixelRatio();for(const d of e){n.setFromMatrixPosition(d.matrixWorld),n.project(this.camera);const h=(n.x+1)/2*o,f=(n.y+1)/2*a;let v=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(v=parseFloat(this.clipArea));const m=d.scale.x*g+.5,b=d.scale.y*g+.5,M=h-m/2,A=f-b/2,T=(M*this.qualityFactor-v)/l,x=(A*this.qualityFactor-v)/l,C=(m*this.qualityFactor+v*2)/l,w=(b*this.qualityFactor+v*2)/l;this.renderer.setScissor(T,x,C,w),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,c)}render(){for(let e=0;e<B.MAX_LAYERS;e++){const t=e+1;this.captureRenderTarget(this.travelersByLayer[e],F.getCaptureLayer(t),this.renderTargets[e])}this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,c=this.renderer.domElement.height/r;this.scene.children.forEach(n=>{const o=n;if(!o.userData||!o.userData.domElement)return;const a=o.userData.domElement;if(!a.isConnected)return;let l;if(a.nodeType===Node.TEXT_NODE){const h=document.createRange();h.selectNode(a),l=h.getBoundingClientRect()}else l=a.getBoundingClientRect();const d=o.userData.domRect;if(!d||Math.abs(l.x-d.x)>.5||Math.abs(l.y-d.y)>.5||Math.abs(l.width-d.width)>.5||Math.abs(l.height-d.height)>.5){o.userData.domRect={x:l.x,y:l.y,width:l.width,height:l.height};let h,f;if(this.isViewport)h=l.x-window.innerWidth/2+l.width/2,f=-l.y+window.innerHeight/2-l.height/2;else{const v=l.x-e,g=l.y-t;h=v-i/2+l.width/2,f=-g+c/2-l.height/2}if(o.position.setX(h),o.position.setY(f),o.scale.set(l.width,l.height,1),o.updateMatrixWorld(),o.material instanceof y.ShaderMaterial&&G.forceUpdateUniforms(o.material,{width:l.width,height:l.height}),o.userData.nativeMesh){const v=o.userData.nativeMesh;let g=l.width,m=l.height,b=h,M=f;if(o.userData.nativeTransform){const A=o.userData.nativeTransform,T=A.match(/scale\(([\d.]+%?)\)/);if(T){let R=parseFloat(T[1]);T[1].includes("%")&&(R/=100),g*=R,m*=R}const x=A.match(/translate\(([^,]+),\s*([^)]+)\)/);if(x){const R=x[1].trim(),k=x[2].trim();let N=parseFloat(R);R.includes("%")&&(N=N/100*l.width);let Q=parseFloat(k);k.includes("%")&&(Q=Q/100*l.height),b+=N,M-=Q}const C=A.match(/translateX\(([^)]+)\)/);if(C){const R=C[1].trim();let k=parseFloat(R);R.includes("%")&&(k=k/100*l.width),b+=k}const w=A.match(/translateY\(([^)]+)\)/);if(w){const R=w[1].trim();let k=parseFloat(R);R.includes("%")&&(k=k/100*l.height),M-=k}}v.position.setX(b),v.position.setY(M),v.scale.set(g,m,1),v.updateMatrixWorld()}}})}}function Ze(s){const e=s.textContent||"",t=[];let r="",i=null,c=-1;const n=(l,d)=>{for(let h=0;h<l.length;h++){const f=l[h],v=document.createRange();v.setStart(s,d+h),v.setEnd(s,d+h+1);const g=v.getBoundingClientRect();if(g.width===0&&g.height===0){r+=f;continue}c===-1||Math.abs(g.top-c)>g.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=f,i={left:g.left,top:g.top,right:g.right,bottom:g.bottom},c=g.top):(r+=f,i&&(i.left=Math.min(i.left,g.left),i.top=Math.min(i.top,g.top),i.right=Math.max(i.right,g.right),i.bottom=Math.max(i.bottom,g.bottom)))}},o=e.match(/[^\s\-]+\-?|\-|\s+/g)||[];let a=0;for(const l of o){const d=document.createRange();d.setStart(s,a),d.setEnd(s,a+l.length);const h=d.getClientRects();if(h.length>1)n(l,a);else{const f=h.length===1?h[0]:d.getBoundingClientRect();if(f.width===0&&f.height===0){r+=l,a+=l.length;continue}c===-1||Math.abs(f.top-c)>f.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=l,i={left:f.left,top:f.top,right:f.right,bottom:f.bottom},c=f.top):(r+=l,i&&(i.left=Math.min(i.left,f.left),i.top=Math.min(i.top,f.top),i.right=Math.max(i.right,f.right),i.bottom=Math.max(i.bottom,f.bottom)))}a+=l.length}return r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),t.filter(l=>l.text.trim().length>0&&l.rect.width>0&&l.rect.height>0)}function ke(s){const e=parseFloat(s.fontSize);let t=parseFloat(s.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(s.letterSpacing);return isNaN(r)&&(r=0),{font:`${s.fontStyle} ${s.fontWeight} ${s.fontSize} ${s.fontFamily}`,fontSize:s.fontSize,color:s.color,textAlign:s.textAlign||"start",textBaseline:"alphabetic",direction:s.direction||"inherit",lineHeight:t,letterSpacing:r}}function Ie(s,e=ee|ae|Ne|ye|me,t,r=1,i=0,c=2,n,o){var W,se,de,ue,z,Y;if(s.nodeType===Node.TEXT_NODE){const p=s;if(!p.textContent||!p.textContent.trim())return null;const L=p.textContent.replace(/\s+/g," ");if(L.length===0)return null;const X=Ze(p);if(X.length===0)return null;const q=p.parentElement,_=q?window.getComputedStyle(q):null;if(!_)return null;const J=Math.min(...X.map(E=>E.rect.left)),H=Math.min(...X.map(E=>E.rect.top)),Z=Math.max(...X.map(E=>E.rect.left+E.rect.width)),I=Math.max(...X.map(E=>E.rect.top+E.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:p,rect:{x:J+window.scrollX,y:H+window.scrollY,width:Z-J,height:I-H},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:q&&q.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(_.opacity),zIndex:(isNaN(parseInt(_.zIndex))?0:parseInt(_.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:L,textLines:X.map(E=>({text:E.text.trim(),rect:{x:E.rect.left+window.scrollX,y:E.rect.top+window.scrollY,width:E.rect.width,height:E.rect.height}})),textStyles:ke(_),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:_.position==="fixed",nativeLayer:n,nativeStyles:o?te(te({backgroundColor:"transparent",backgroundImage:"",opacity:q&&q.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(_.opacity),zIndex:(isNaN(parseInt(_.zIndex))?0:parseInt(_.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},ke(_)),o):void 0,nativeRect:o?{x:J+window.scrollX,y:H+window.scrollY,width:Z-J,height:I-H}:void 0,children:[]}}if(s.nodeType!==Node.ELEMENT_NODE)return null;const a=s,l=a.dataset[O.KEY];let d=t,h=t;if(l){const p=new Set(l.split(/\s+/));for(const L of p)if(!Re.includes(L))throw new Error(`[MirageEngine] Invalid filter token: '${L}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(p.has(O.VALUES.END))return null;if(p.has(O.VALUES.INCLUDE_TREE)&&p.has(O.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(p.has(O.VALUES.INCLUDE_SELF)&&p.has(O.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");p.has(O.VALUES.INCLUDE_TREE)?d=d|P:p.has(O.VALUES.EXCLUDE_TREE)&&(d=d&~P),h=d,p.has(O.VALUES.INCLUDE_SELF)?h=h|P:p.has(O.VALUES.EXCLUDE_SELF)&&(h=h&~P)}const f=a.dataset[V.KEY];if(f){const p=new Set(f.split(/\s+/));for(const L of p)if(!Re.includes(L))throw new Error(`[MirageEngine] Invalid select token: '${L}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(p.has(V.VALUES.END))return null;if(p.has(V.VALUES.INCLUDE_TREE)&&p.has(V.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(p.has(V.VALUES.INCLUDE_SELF)&&p.has(V.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");p.has(V.VALUES.INCLUDE_TREE)?d=d|re:p.has(V.VALUES.EXCLUDE_TREE)&&(d=d&~re),h=d,p.has(V.VALUES.INCLUDE_SELF)?h=h|re:p.has(V.VALUES.EXCLUDE_SELF)&&(h=h&~re)}const v=a.dataset[B.KEY];let g=!1,m=o?te({},o):{},b=n;if(v){let p=1;const L=v.indexOf("{"),X=v.lastIndexOf("}");let q=v;if(L!==-1&&X!==-1&&X>L){q=v.substring(0,L).trim();const I=v.substring(L,X+1);try{m=new Function("return "+I)()}catch(E){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${I}`)}}const _=q.split(/\s+/);let J=!1;const H=_.indexOf(B.VALUES.TRAVELER);if(H!==-1){g=!0,J=!0;const I=_[H+1];if(I&&!isNaN(parseInt(I,10)))p=parseInt(I,10);else{const E=_.find(ne=>!isNaN(parseInt(ne,10)));E&&(p=parseInt(E,10))}}const Z=_.indexOf(B.VALUES.NATIVE);if(Z!==-1){const I=_[Z+1];if(I&&!isNaN(parseInt(I,10)))b=parseInt(I,10);else if(!g){const E=_.find(ne=>!isNaN(parseInt(ne,10)));E&&(b=parseInt(E,10))}}if(J){const I=p+1;if(I<r)throw new Error(`[MirageEngine] Traveler layer (${p}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(I,B.MAX_LAYERS+1)}}const M=a.dataset[Fe.KEY];let A;M&&(A=JSON.parse(M));const T=a.getBoundingClientRect(),x=window.getComputedStyle(a);if(T.width===0||T.height===0||x.display==="none")return null;let C=a.getAttribute("data-mid");C||(C=Math.random().toString(36).substring(2,11),a.setAttribute("data-mid",C));const w=parseInt(x.zIndex),R=(isNaN(w)?0:w)+i;let k;if(a.tagName==="IMG")k=a.src;else if(a.tagName.toLowerCase()==="svg"){const p=a.cloneNode(!0),L=m==null?void 0:m.color,X=m==null?void 0:m.fill,q=m==null?void 0:m.stroke,_=m==null?void 0:m.opacity,J=(E,ne)=>{const j=window.getComputedStyle(E),fe=ne,ot=j.fill===j.color,at=j.stroke===j.color,we=X||(ot?L:void 0)||j.fill;we&&we!=="none"&&(fe.style.fill=we);const xe=q||(at?L:void 0)||j.stroke;xe&&xe!=="none"&&(fe.style.stroke=xe),j.strokeWidth&&j.strokeWidth!=="0px"&&(fe.style.strokeWidth=j.strokeWidth);const Ue=L||j.color;Ue&&(fe.style.color=Ue);const Ee=_||j.opacity;Ee&&Ee!=="1"&&(fe.style.opacity=Ee);for(let ve=0;ve<E.children.length;ve++)J(E.children[ve],ne.children[ve])};J(a,p);const H=a.getBoundingClientRect(),Z=window.devicePixelRatio*c;p.hasAttribute("viewBox")||p.setAttribute("viewBox",`0 0 ${H.width} ${H.height}`),p.setAttribute("width",(H.width*Z).toString()),p.setAttribute("height",(H.height*Z).toString());let I=new XMLSerializer().serializeToString(p);I.includes("xmlns=")||(I=I.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),k=`data:image/svg+xml;utf8,${encodeURIComponent(I)}`}else if(x.backgroundImage&&x.backgroundImage!=="none"){const p=x.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);p&&(k=p[1])}const N={backgroundColor:x.backgroundColor,backgroundImage:x.backgroundImage,opacity:a.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(x.opacity),zIndex:R,borderRadius:x.borderRadius,borderColor:x.borderColor,borderWidth:x.borderWidth,imageSrc:k,isTraveler:g},Q=N;let le,he;const $=[];return a.tagName.toLowerCase()!=="svg"&&Array.from(a.childNodes).forEach(p=>{const L=p.nodeType===Node.TEXT_NODE?h:d,X=Ie(p,e,L,r,R,c,p.nodeType===Node.TEXT_NODE?b:void 0,p.nodeType===Node.TEXT_NODE&&Object.keys(m).length>0?m:void 0);X&&$.push(X)}),{id:C,type:"BOX",element:a,rect:{x:T.left+window.scrollX,y:T.top+window.scrollY,width:T.width,height:T.height},styles:Q,textContent:le,textStyles:he,dirtyMask:e,visibility:h,isTraveler:g,captureLayer:r,nativeLayer:b,nativeStyles:b!==void 0?_e(te({},N),{backgroundColor:(W=m.backgroundColor)!=null?W:N.backgroundColor,backgroundImage:(se=m.backgroundImage)!=null?se:N.backgroundImage,opacity:(de=m.opacity)!=null?de:N.opacity,zIndex:m.zIndex!==void 0?m.zIndex+R:N.zIndex,borderRadius:(ue=m.borderRadius)!=null?ue:N.borderRadius,borderColor:(z=m.borderColor)!=null?z:N.borderColor,borderWidth:(Y=m.borderWidth)!=null?Y:N.borderWidth,isTraveler:N.isTraveler,transform:m.transform}):void 0,nativeRect:b!==void 0?{x:m.x!==void 0?parseFloat(m.x):T.left+window.scrollX,y:m.y!==void 0?parseFloat(m.y):T.top+window.scrollY,width:m.width!==void 0?parseFloat(m.width):T.width,height:m.height!==void 0?parseFloat(m.height):T.height}:void 0,isFixed:x.position==="fixed",children:$,shaderHooks:A}}function et(s,e){e.size!==0&&e.forEach((t,r)=>{var c,n,o,a;const i=s.get(r);!i||!i.userData.basePosition||(G.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(n=t.borderRadius)!=null?n:(c=i.userData.baseStyles)==null?void 0:c.borderRadius}),i.userData.nativeMesh&&G.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(a=t.borderRadius)!=null?a:(o=i.userData.baseStyles)==null?void 0:o.borderRadius}))})}class tt{constructor(e,t,r,i){u(this,"target");u(this,"renderer");u(this,"registry");u(this,"isTravelEnabled",!1);u(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new Te(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((c,n)=>{document.querySelector(`[${B.NAME}~='${B.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const a=Ie(this.target,c,P,1,0,this.renderer.qualityFactor);a&&this.renderer.syncScene(a,n)}),this.tracker.onStyleChange.add(c=>{et(this.registry,c)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class rt{constructor(){u(this,"store");this.store=new WeakMap}register(e,t){this.store.set(e,t)}get(e){return this.store.get(e)}has(e){return this.store.has(e)}remove(e){this.store.delete(e)}}class it{constructor(e,t){u(this,"renderer");u(this,"syncer");u(this,"target");u(this,"registry");var i,c,n;if(this.target=e,this.registry=new rt,!document.getElementById("mirage-engine-styles")){const o=document.createElement("style");o.id="mirage-engine-styles",o.textContent=`
165
+ [${K.NAME}="${K.VALUES.HIDE}"] {
166
166
  opacity: 0 !important;
167
167
  }
168
- `,document.head.appendChild(o)}let r;if(t.mode==="duplicate"?r=(a=(i=t.container)!=null?i:this.target.parentElement)!=null?a:void 0:r=(n=this.target.parentElement)!=null?n:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new Qe(this.target,t,r,this.registry),this.renderer.mount(),this.syncer=new tt(this.target,this.renderer,this.registry,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}getTracker(){return this.syncer.tracker}updateUniforms(e,t){this.renderer.updateUniforms(e,t)}getCanvas(){return this.renderer.canvas}test(){const e=this.registry.get(document.querySelector("#box2"));if(!e)return;const t={ArrowRight:!1,ArrowLeft:!1,ArrowUp:!1,ArrowDown:!1};window.addEventListener("keydown",a=>{t[a.key]!==void 0&&(t[a.key]=!0)}),window.addEventListener("keyup",a=>{t[a.key]!==void 0&&(t[a.key]=!1)});const r=2,i=()=>{requestAnimationFrame(i),t.ArrowRight&&e.position.setX(e.position.x+r),t.ArrowLeft&&e.position.setX(e.position.x-r),t.ArrowUp&&e.position.setY(e.position.y+r),t.ArrowDown&&e.position.setY(e.position.y-r)};i()}}class st{constructor(e={}){u(this,"frontSelector");u(this,"midLayerElement");u(this,"items",[]);u(this,"isInitialized",!1);u(this,"midLayer",null);u(this,"frontLayer",null);u(this,"tracker",null);this.frontSelector=e.frontSelector||".front",this.midLayerElement=e.midLayerElement||null,this.items=[],this.isInitialized=!1,this.tracker=new Te(document.body,e.trackerConfig||{resizeDebounce:!0})}init(){var e;this.isInitialized||(this.createLayers(),this.setupMidLayer(),this.hijackFrontElements(),this.setupHooks(),(e=this.tracker)==null||e.start(),this.isInitialized=!0,console.log("🥪 sand-telepochi initialized!"))}useTracker(e){this.tracker=e,this.setupHooks()}createLayers(){this.midLayer=document.createElement("div"),this.midLayer.id="sand-layer-mid",Object.assign(this.midLayer.style,{position:"fixed",inset:"0",zIndex:"9998",pointerEvents:"none"}),this.frontLayer=document.createElement("div"),this.frontLayer.id="sand-layer-front",Object.assign(this.frontLayer.style,{position:"fixed",inset:"0",zIndex:"9999",pointerEvents:"none"}),document.body.appendChild(this.midLayer),document.body.appendChild(this.frontLayer)}setupMidLayer(){this.midLayerElement&&this.midLayer&&(this.midLayer.appendChild(this.midLayerElement),this.midLayerElement.style.pointerEvents="auto")}hijackFrontElements(){const e=document.querySelectorAll(this.frontSelector);this.frontLayer&&e.forEach(t=>{var n;const r=t.getBoundingClientRect(),i=window.getComputedStyle(t),a=document.createElement("div");a.className="sand-placeholder",Object.assign(a.style,{display:i.display==="inline"?"inline-block":i.display,width:`${r.width}px`,height:`${r.height}px`,boxSizing:"border-box",marginTop:i.marginTop,marginBottom:i.marginBottom,marginLeft:i.marginLeft,marginRight:i.marginRight,visibility:"hidden",pointerEvents:"none"}),(n=t.parentNode)==null||n.insertBefore(a,t),this.frontLayer.appendChild(t),Object.assign(t.style,{position:"fixed",margin:"0",boxSizing:"border-box",width:`${r.width}px`,height:`${r.height}px`,pointerEvents:"auto"}),this.items.push({placeholder:a,original:t})})}setupHooks(){this.tracker&&this.tracker.onBeforeRender.add(()=>{const e=this.items.map(({placeholder:t})=>t.getBoundingClientRect());this.items.forEach(({original:t},r)=>{const i=e[r];t.style.top=`${i.top}px`,t.style.left=`${i.left}px`,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`})})}}class nt{constructor(e,t){u(this,"_engine");u(this,"_sandwich");if(!e)throw new Error("[Mirage] Target element is required.");if(this._engine=new it(e,t),t.sandwich!==!1){const r=typeof t.sandwich=="object"?t.sandwich:{};this._sandwich=new st({frontSelector:r.frontSelector||`[${Se.NAME}='${Se.VALUES.FRONT}']`}),this._sandwich.useTracker(this._engine.getTracker())}}start(){this._engine.start(),this._sandwich&&this._sandwich.init()}stop(){this._engine.stop()}destroy(){this._engine.dispose()}getTracker(){return this._engine.getTracker()}getCanvas(){return this._engine.getCanvas()}updateUniforms(e,t){this._engine.updateUniforms(e,t)}test(){this._engine.test()}}A.Mirage=nt,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
168
+ `,document.head.appendChild(o)}let r;if(t.mode==="duplicate"?r=(c=(i=t.container)!=null?i:this.target.parentElement)!=null?c:void 0:r=(n=this.target.parentElement)!=null?n:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new Qe(this.target,t,r,this.registry),this.renderer.mount(),this.syncer=new tt(this.target,this.renderer,this.registry,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}getTracker(){return this.syncer.tracker}updateUniforms(e,t){this.renderer.updateUniforms(e,t)}getCanvas(){return this.renderer.canvas}test(){const e=this.registry.get(document.querySelector("#box2"));if(!e)return;const t={ArrowRight:!1,ArrowLeft:!1,ArrowUp:!1,ArrowDown:!1};window.addEventListener("keydown",c=>{t[c.key]!==void 0&&(t[c.key]=!0)}),window.addEventListener("keyup",c=>{t[c.key]!==void 0&&(t[c.key]=!1)});const r=2,i=()=>{requestAnimationFrame(i),t.ArrowRight&&e.position.setX(e.position.x+r),t.ArrowLeft&&e.position.setX(e.position.x-r),t.ArrowUp&&e.position.setY(e.position.y+r),t.ArrowDown&&e.position.setY(e.position.y-r)};i()}}class st{constructor(e={}){u(this,"frontSelector");u(this,"midLayerElement");u(this,"items",[]);u(this,"isInitialized",!1);u(this,"midLayer",null);u(this,"frontLayer",null);u(this,"tracker",null);this.frontSelector=e.frontSelector||".front",this.midLayerElement=e.midLayerElement||null,this.items=[],this.isInitialized=!1,this.tracker=new Te(document.body,e.trackerConfig||{resizeDebounce:!0})}init(){var e;this.isInitialized||(this.createLayers(),this.setupMidLayer(),this.hijackFrontElements(),this.setupHooks(),(e=this.tracker)==null||e.start(),this.isInitialized=!0,console.log("🥪 sand-telepochi initialized!"))}useTracker(e){this.tracker=e,this.setupHooks()}createLayers(){this.midLayer=document.createElement("div"),this.midLayer.id="sand-layer-mid",Object.assign(this.midLayer.style,{position:"fixed",inset:"0",zIndex:"9998",pointerEvents:"none"}),this.frontLayer=document.createElement("div"),this.frontLayer.id="sand-layer-front",Object.assign(this.frontLayer.style,{position:"fixed",inset:"0",zIndex:"9999",pointerEvents:"none"}),document.body.appendChild(this.midLayer),document.body.appendChild(this.frontLayer)}setupMidLayer(){this.midLayerElement&&this.midLayer&&(this.midLayer.appendChild(this.midLayerElement),this.midLayerElement.style.pointerEvents="auto")}hijackFrontElements(){const e=document.querySelectorAll(this.frontSelector);this.frontLayer&&e.forEach(t=>{var n;const r=t.getBoundingClientRect(),i=window.getComputedStyle(t),c=document.createElement("div");c.className="sand-placeholder",Object.assign(c.style,{display:i.display==="inline"?"inline-block":i.display,width:`${r.width}px`,height:`${r.height}px`,boxSizing:"border-box",marginTop:i.marginTop,marginBottom:i.marginBottom,marginLeft:i.marginLeft,marginRight:i.marginRight,visibility:"hidden",pointerEvents:"none"}),(n=t.parentNode)==null||n.insertBefore(c,t),this.frontLayer.appendChild(t),Object.assign(t.style,{position:"fixed",margin:"0",boxSizing:"border-box",width:`${r.width}px`,height:`${r.height}px`,pointerEvents:"auto"}),this.items.push({placeholder:c,original:t})})}setupHooks(){this.tracker&&this.tracker.onBeforeRender.add(()=>{const e=this.items.map(({placeholder:t})=>t.getBoundingClientRect());this.items.forEach(({original:t},r)=>{const i=e[r];t.style.top=`${i.top}px`,t.style.left=`${i.left}px`,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`})})}}class nt{constructor(e,t){u(this,"_engine");u(this,"_sandwich");if(!e)throw new Error("[Mirage] Target element is required.");if(this._engine=new it(e,t),t.sandwich!==!1){const r=typeof t.sandwich=="object"?t.sandwich:{};this._sandwich=new st({frontSelector:r.frontSelector||`[${Se.NAME}='${Se.VALUES.FRONT}']`}),this._sandwich.useTracker(this._engine.getTracker())}}start(){this._engine.start(),this._sandwich&&this._sandwich.init()}stop(){this._engine.stop()}destroy(){this._engine.dispose()}getTracker(){return this._engine.getTracker()}getCanvas(){return this._engine.getCanvas()}updateUniforms(e,t){this._engine.updateUniforms(e,t)}test(){this._engine.test()}}D.Mirage=nt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirage-engine",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "description": "An engine that mirrors HTML DOM elements to a WebGL scene in real-time.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@mirage-engine/painter": "1.0.4",
25
25
  "@mirage-engine/sandwich": "0.2.8",
26
- "@mirage-engine/core": "0.3.11"
26
+ "@mirage-engine/core": "0.3.12"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "three": "^0.160.0"