mirage-engine 0.3.3 → 0.3.4

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