@mirage-engine/core 0.3.14 → 0.3.15

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,12 +1,17 @@
1
- (function(b,L){typeof exports=="object"&&typeof module!="undefined"?L(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],L):(b=typeof globalThis!="undefined"?globalThis:b||self,L(b.MirageEngine={},b.THREE))})(this,function(b,L){"use strict";var ot=Object.defineProperty,ct=Object.defineProperties;var lt=Object.getOwnPropertyDescriptors;var Fe=Object.getOwnPropertySymbols;var ht=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var Ce=(b,L,k)=>L in b?ot(b,L,{enumerable:!0,configurable:!0,writable:!0,value:k}):b[L]=k,re=(b,L)=>{for(var k in L||(L={}))ht.call(L,k)&&Ce(b,k,L[k]);if(Fe)for(var k of Fe(L))dt.call(L,k)&&Ce(b,k,L[k]);return b},Be=(b,L)=>ct(b,lt(L));var p=(b,L,k)=>(Ce(b,typeof L!="symbol"?L+"":L,k),k);var Ne=(b,L,k)=>new Promise((y,le)=>{var $=U=>{try{O(k.next(U))}catch(X){le(X)}},he=U=>{try{O(k.throw(U))}catch(X){le(X)}},O=U=>U.done?y(U.value):Promise.resolve(U.value).then($,he);O((k=k.apply(b,L)).next())});function k(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const y=k(L),le={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},$={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},he={TRAVELER:"traveler",NATIVE:"native",CAPTURE_1:"1",CAPTURE_2:"2",CAPTURE_3:"3",CAPTURE_4:"4",CAPTURE_5:"5",CAPTURE_6:"6",CAPTURE_7:"7",CAPTURE_8:"8",CAPTURE_9:"9",CAPTURE_10:"10"},O={NAME:"data-mirage-travel",KEY:"mirageTravel",VALUES:he,MAX_LAYERS:Object.keys(he).length-1},U={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:le},X={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:le},Se={NAME:"data-mirage-shader",KEY:"mirageShader"},Xe={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},de=0,Q=1,ie=2,Re=4,ue=8,ve=16;function Ye(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 Le(s){const e={};if(s.opacity&&(e.opacity=parseFloat(s.opacity)),s.backgroundColor&&s.backgroundColor!=="rgba(0, 0, 0, 0)"){const t=Ye(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){p(this,"target");p(this,"observer");p(this,"pendingDeletions",new Set);p(this,"pendingStyles",new Map);p(this,"isDomDirty",!1);p(this,"isRunning",!1);p(this,"pendingMask",de);p(this,"mutationTimer",null);p(this,"cssTimer",null);p(this,"resizeConfig");p(this,"resizeTimer",null);p(this,"isResizing",!1);p(this,"lastScrollX",0);p(this,"lastScrollY",0);p(this,"scrollTimer",null);p(this,"onBeforeRender",new Set);p(this,"onLayoutChange",new Set);p(this,"onStyleChange",new Set);p(this,"onScrollChange",new Set);p(this,"onRender",new Set);p(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=Q|ie,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});p(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)});p(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=de);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,l;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:(l=r.delay)!=null?l:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(n=>{let a=de;for(const o of n)if(o.type==="childList")a|=ue,o.removedNodes.length>0&&o.removedNodes.forEach(c=>{c instanceof HTMLElement&&this.pendingDeletions.add(c)});else if(o.type==="attributes")if(o.attributeName==="style"){a|=Q|ie;const c=o.target,d=Le(c.style);this.pendingStyles.set(c,d)}else o.attributeName==="class"?a|=Q|ie:o.attributeName&&o.attributeName.startsWith("data-")&&(a|=Q|ie,o.attributeName.startsWith("data-mirage")&&(a|=ue));else o.type==="characterData"&&(a|=ve|Q);if(a!==de){if(this.pendingMask|=a,a&ue){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 H=1,te=2,Ve=0,B={BASE:0,SELECTED:1,getCaptureLayer:s=>31-s,HIDDEN:31},be=Object.values(U.VALUES);class De{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 l=i.offsetTop-r.offsetTop;return document.body.removeChild(t),l}}p(De,"cache",new Map);class ze extends y.MeshBasicMaterial{constructor(t,r,i,l,n=2){super({transparent:!0,side:y.FrontSide,color:16777215});p(this,"canvas");p(this,"ctx");p(this,"qualityFactor");if(this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("[Mirage] Failed to create canvas context");this.qualityFactor=n,this.map=new y.CanvasTexture(this.canvas),this.map.colorSpace=y.LinearSRGBColorSpace,this.map.minFilter=y.LinearFilter,this.map.magFilter=y.LinearFilter,this.updateText(t,r,i,l)}wrapText(t,r){const i=t.split(`
2
- `),l=[];return i.forEach(n=>{const a=n.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(a.length===0){l.push("");return}let o=a[0];for(let c=1;c<a.length;c++){const d=a[c];this.ctx.measureText(o+d).width<=r+2?o+=d:(o&&l.push(o),o=d.trimStart())}o&&l.push(o)}),l}updateText(t,r,i,l,n){n!==void 0&&(this.qualityFactor=n);const o=(window.devicePixelRatio||1)*this.qualityFactor,c=i*o,d=l*o;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(o,0,0,o,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),f=r.lineHeight,v=De.getBaseline(r.font);h.forEach((g,m)=>{const x=m*f+v;let A=0;r.textAlign==="center"?A=i/2:r.textAlign==="right"&&(A=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(g,A,x)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function se(s,e=0){if(typeof s=="number")return s;const t=parseFloat(s)||0;return typeof s=="string"&&s.includes("%")?t/100*e:t}function fe(s){if(!s||s==="transparent")return{color:new y.Color(16777215),alpha:0};const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),l=e[4]!==void 0?parseFloat(e[4]):1;return{color:new y.Color(`rgb(${t}, ${r}, ${i})`),alpha:l}}return{color:new y.Color(s),alpha:1}}function We(s){const e=[];let t="",r=0;for(let i=0;i<s.length;i++){const l=s[i];if(l==="(")r++;else if(l===")")r--;else if(l===","&&r===0){e.push(t.trim()),t="";continue}t+=l}return t&&e.push(t.trim()),e}function He(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=We(t);let i=Math.PI,l=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),l=1;else if(n.endsWith("deg")||n.endsWith("rad")||n.endsWith("turn")){const o=parseFloat(n);n.endsWith("deg")?i=o*(Math.PI/180):n.endsWith("rad")?i=o:n.endsWith("turn")&&(i=o*Math.PI*2),l=1}const a=[];for(let o=l;o<r.length&&!(a.length>=8);o++){const c=r[o].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 v=fe(h);a.push({color:v.color,alpha:v.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 o=0;for(let c=1;c<a.length;c++)if(a[c].rawStop!==null||c===a.length-1){const d=c-o;if(d>1){const h=a[o].stop,v=(a[c].stop-h)/d;for(let g=1;g<d;g++)a[o+g].stop=h+v*g}o=c}}return{angle:i,stops:a}}const Pe=`varying vec2 vUv;
1
+ (function(b,A){typeof exports=="object"&&typeof module!="undefined"?A(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],A):(b=typeof globalThis!="undefined"?globalThis:b||self,A(b.MirageEngine={},b.THREE))})(this,function(b,A){"use strict";var ct=Object.defineProperty,ht=Object.defineProperties;var dt=Object.getOwnPropertyDescriptors;var Ne=Object.getOwnPropertySymbols;var ut=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var Te=(b,A,F)=>A in b?ct(b,A,{enumerable:!0,configurable:!0,writable:!0,value:F}):b[A]=F,ae=(b,A)=>{for(var F in A||(A={}))ut.call(A,F)&&Te(b,F,A[F]);if(Ne)for(var F of Ne(A))ft.call(A,F)&&Te(b,F,A[F]);return b},Xe=(b,A)=>ht(b,dt(A));var p=(b,A,F)=>(Te(b,typeof A!="symbol"?A+"":A,F),F);var Ye=(b,A,F)=>new Promise((v,fe)=>{var K=_=>{try{B(F.next(_))}catch(V){fe(V)}},ge=_=>{try{B(F.throw(_))}catch(V){fe(V)}},B=_=>_.done?v(_.value):Promise.resolve(_.value).then(K,ge);B((F=F.apply(b,A)).next())});function F(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const v=F(A),fe={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},K={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},ge={TRAVELER:"traveler",NATIVE:"native",CAPTURE_1:"1",CAPTURE_2:"2",CAPTURE_3:"3",CAPTURE_4:"4",CAPTURE_5:"5",CAPTURE_6:"6",CAPTURE_7:"7",CAPTURE_8:"8",CAPTURE_9:"9",CAPTURE_10:"10"},B={NAME:"data-mirage-travel",KEY:"mirageTravel",VALUES:ge,MAX_LAYERS:Object.keys(ge).length-1},_={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:fe},V={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:fe},Re={NAME:"data-mirage-shader",KEY:"mirageShader"},ze={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},pe=0,te=1,oe=2,Me=4,me=8,we=16;function Ve(n){const e=n.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 Le(n){const e={};if(n.opacity&&(e.opacity=parseFloat(n.opacity)),n.backgroundColor&&n.backgroundColor!=="rgba(0, 0, 0, 0)"){const t=Ve(n.backgroundColor);e.backgroundColor=[t.r,t.g,t.b]}if(n.backgroundImage?e.backgroundImage=n.backgroundImage:n.background&&(e.backgroundImage=n.background),n.borderRadius&&(e.borderRadius=parseFloat(n.borderRadius)),n.width&&(e.width=parseFloat(n.width)),n.height&&(e.height=parseFloat(n.height)),n.transform&&n.transform!=="none"){const t=new DOMMatrix(n.transform);e.x=t.m41,e.y=t.m42,e.z=t.m43}return e}class De{constructor(e,t){p(this,"target");p(this,"observer");p(this,"pendingDeletions",new Set);p(this,"pendingStyles",new Map);p(this,"isDomDirty",!1);p(this,"isRunning",!1);p(this,"pendingMask",pe);p(this,"mutationTimer",null);p(this,"cssTimer",null);p(this,"resizeConfig");p(this,"resizeTimer",null);p(this,"isResizing",!1);p(this,"lastScrollX",0);p(this,"lastScrollY",0);p(this,"scrollTimer",null);p(this,"onBeforeRender",new Set);p(this,"onLayoutChange",new Set);p(this,"onStyleChange",new Set);p(this,"onScrollChange",new Set);p(this,"onRender",new Set);p(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=te|oe,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});p(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)});p(this,"renderLoop",()=>{if(!this.isRunning)return;this.onBeforeRender.forEach(r=>r()),this.isDomDirty&&(this.isDomDirty=!1,this.onLayoutChange.forEach(r=>r(this.pendingMask,this.pendingDeletions)),this.pendingDeletions.clear(),this.pendingMask=pe);const e=window.scrollX,t=window.scrollY;(e!==this.lastScrollX||t!==this.lastScrollY)&&(this.onScrollChange.forEach(r=>r(e,t)),this.lastScrollX=e,this.lastScrollY=t,this.scrollTimer&&clearTimeout(this.scrollTimer),this.scrollTimer=window.setTimeout(()=>{this.pendingMask|=te,this.isDomDirty=!0,this.scrollTimer=null},150)),this.pendingStyles.size>0&&(this.onStyleChange.forEach(r=>r(this.pendingStyles)),this.pendingStyles.clear()),this.onRender.forEach(r=>r()),requestAnimationFrame(this.renderLoop)});var i,c;this.target=e;const r=(i=t.resizeDebounce)!=null?i:!0;r===!1?this.resizeConfig={enabled:!1,delay:0}:r===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(c=r.delay)!=null?c:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(s=>{let a=pe;for(const o of s)if(o.type==="childList")a|=me,o.removedNodes.length>0&&o.removedNodes.forEach(l=>{l instanceof HTMLElement&&this.pendingDeletions.add(l)});else if(o.type==="attributes")if(o.attributeName==="style"){a|=te|oe;const l=o.target,d=Le(l.style);this.pendingStyles.set(l,d)}else o.attributeName==="class"?a|=te|oe:o.attributeName&&o.attributeName.startsWith("data-")&&(a|=te|oe,o.attributeName.startsWith("data-mirage")&&(a|=me));else o.type==="characterData"&&(a|=we|te);if(a!==pe){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,ne=2,Pe=0,N={BASE:0,SELECTED:1,getCaptureLayer:n=>31-n,HIDDEN:31},ye=Object.values(_.VALUES);class Ae{static getBaseline(e){if(this.cache.has(e))return this.cache.get(e);const t=this.calculateBaselineFromDOM(e);return this.cache.set(e,t),t}static calculateBaselineFromDOM(e){if(typeof document=="undefined")return 0;const t=document.createElement("div"),r=document.createElement("span"),i=document.createElement("img");t.style.visibility="hidden",t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.font=e,t.style.margin="0",t.style.padding="0",t.style.border="none",r.style.margin="0",r.style.padding="0",r.style.border="none",r.style.lineHeight="normal",i.width=1,i.height=1,i.style.verticalAlign="baseline",r.appendChild(document.createTextNode("Hidden Text")),t.appendChild(r),t.appendChild(i),document.body.appendChild(t);const c=i.offsetTop-r.offsetTop;return document.body.removeChild(t),c}}p(Ae,"cache",new Map);class We extends v.MeshBasicMaterial{constructor(t,r,i,c,s=2){super({transparent:!0,side:v.FrontSide,color:16777215});p(this,"canvas");p(this,"ctx");p(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=s,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,c)}wrapText(t,r){const i=t.split(`
2
+ `),c=[];return i.forEach(s=>{const a=s.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(a.length===0){c.push("");return}let o=a[0];for(let l=1;l<a.length;l++){const d=a[l];this.ctx.measureText(o+d).width<=r+2?o+=d:(o&&c.push(o),o=d.trimStart())}o&&c.push(o)}),c}updateText(t,r,i,c,s){s!==void 0&&(this.qualityFactor=s);const o=(window.devicePixelRatio||1)*this.qualityFactor,l=i*o,d=c*o;this.canvas.width!==l||this.canvas.height!==d?(this.canvas.width=l,this.canvas.height=d):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(o,0,0,o,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),u=r.lineHeight,f=Ae.getBaseline(r.font);h.forEach((g,w)=>{const y=w*u+f;let T=0;r.textAlign==="center"?T=i/2:r.textAlign==="right"&&(T=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(g,T,y)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function le(n,e=0){if(typeof n=="number")return n;const t=parseFloat(n)||0;return typeof n=="string"&&n.includes("%")?t/100*e:t}function ce(n){if(!n||n==="transparent")return{color:new v.Color(16777215),alpha:0};const e=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),c=e[4]!==void 0?parseFloat(e[4]):1;return{color:new v.Color(`rgb(${t}, ${r}, ${i})`),alpha:c}}return{color:new v.Color(n),alpha:1}}function Ie(n){const e=[];let t="",r=0;for(let i=0;i<n.length;i++){const c=n[i];if(c==="(")r++;else if(c===")")r--;else if(c===","&&r===0){e.push(t.trim()),t="";continue}t+=c}return t&&e.push(t.trim()),e}function He(n){if(!n||typeof n!="string"||!n.includes("linear-gradient"))return null;const e=n.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=Ie(t);let i=Math.PI,c=0;const s=r[0].trim();if(s.startsWith("to "))s==="to top"?i=0:s==="to right"?i=Math.PI/2:s==="to bottom"?i=Math.PI:s==="to left"?i=Math.PI*1.5:s==="to top right"||s==="to right top"?i=Math.PI/4:s==="to bottom right"||s==="to right bottom"?i=Math.PI*.75:s==="to bottom left"||s==="to left bottom"?i=Math.PI*1.25:(s==="to top left"||s==="to left top")&&(i=Math.PI*1.75),c=1;else if(s.endsWith("deg")||s.endsWith("rad")||s.endsWith("turn")){const o=parseFloat(s);s.endsWith("deg")?i=o*(Math.PI/180):s.endsWith("rad")?i=o:s.endsWith("turn")&&(i=o*Math.PI*2),c=1}const a=[];for(let o=c;o<r.length&&!(a.length>=8);o++){const l=r[o].trim(),d=l.lastIndexOf(" ");let h=l,u=null;if(d!==-1&&!l.endsWith(")")){const g=l.substring(d+1);(g.endsWith("%")||g.endsWith("px")||!isNaN(parseFloat(g)))&&(h=l.substring(0,d).trim(),u=g)}const f=ce(h);a.push({color:f.color,alpha:f.alpha,rawStop:u,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 o=0;for(let l=1;l<a.length;l++)if(a[l].rawStop!==null||l===a.length-1){const d=l-o;if(d>1){const h=a[o].stop,f=(a[l].stop-h)/d;for(let g=1;g<d;g++)a[o+g].stop=h+f*g}o=l}}return{angle:i,stops:a}}function Ge(n){if(!n||n==="none")return null;const e=Ie(n);if(e.length===0)return null;const t=e[0].trim(),r=/(rgba?\([^)]+\)|#[0-9a-fA-F]+|[a-zA-Z]+)/,i=t.match(r);let c="transparent",s=t;if(i&&i[1]!=="inset"){const f=i[1];(f.startsWith("rgb")||f.startsWith("#")||f==="black"||f==="white"||f==="transparent")&&(c=f,s=t.replace(f,"").trim())}s=s.replace("inset","").trim();const a=s.split(/\s+/).map(f=>parseFloat(f)||0),o=a[0]||0,l=a[1]||0,d=a[2]||0,h=a[3]||0,u=ce(c);return{offsetX:o,offsetY:l,blurRadius:d,spreadRadius:h,color:u.color,alpha:u.alpha}}const qe=`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
+ }`,$e=`varying vec2 vUv;
9
9
  uniform vec2 uSize;
10
+ uniform vec2 uMeshSize;
11
+ uniform vec4 uShadowColor;
12
+ uniform vec2 uShadowOffset;
13
+ uniform float uShadowBlur;
14
+ uniform float uShadowSpread;
10
15
  uniform vec4 uBorderRadius;
11
16
  uniform float uBorderWidth;
12
17
  uniform vec4 uBgColor;
@@ -62,11 +67,10 @@ float sdVisualBox(vec2 p, vec2 b, float r) {
62
67
  return min(max(q.x, q.y), 0.0) + d;
63
68
  }
64
69
 
65
- vec4 calculateGradientLayer(vec2 uv) {
70
+ vec4 calculateGradientLayer(vec2 p) {
66
71
  if (uGradientCount < 2) return uGradientColors[0];
67
72
 
68
73
  vec2 dir = vec2(sin(uGradientAngle), cos(uGradientAngle));
69
- vec2 p = (uv - 0.5) * uSize;
70
74
  float proj = dot(p, dir);
71
75
  float L = abs(uSize.x * dir.x) + abs(uSize.y * dir.y);
72
76
  float t = clamp((proj / L) + 0.5, 0.0, 1.0);
@@ -85,7 +89,7 @@ vec4 calculateGradientLayer(vec2 uv) {
85
89
  }
86
90
 
87
91
  void main() {
88
- vec2 p = (vUv - 0.5) * uSize;
92
+ vec2 p = (vUv - 0.5) * uMeshSize;
89
93
  vec2 halfSize = uSize * 0.5;
90
94
 
91
95
  // CSS Proportional Border-Radius Clamping
@@ -106,7 +110,7 @@ void main() {
106
110
  vec4 baseColor = vec4(uBgColor.rgb, uBgColor.a);
107
111
 
108
112
  if (uGradientCount > 0) {
109
- vec4 gradColor = calculateGradientLayer(vUv);
113
+ vec4 gradColor = calculateGradientLayer(p);
110
114
  baseColor = blendSrcOver(gradColor, baseColor);
111
115
  }
112
116
 
@@ -133,11 +137,26 @@ void main() {
133
137
 
134
138
  // final blending (border + background) using blendSrcOver
135
139
  vec4 borderLayer = vec4(uBorderColor.rgb, borderAlpha);
136
- vec4 finalColor = blendSrcOver(borderLayer, baseColor);
140
+ vec4 mainColor = blendSrcOver(borderLayer, baseColor);
141
+ mainColor.a *= bgMask;
142
+
143
+ vec4 shadowLayer = vec4(0.0);
144
+ if (uShadowColor.a > 0.001) {
145
+ vec2 shadowP = p - vec2(uShadowOffset.x, -uShadowOffset.y);
146
+ float shadowRadius = max(r + uShadowSpread, 0.0);
147
+ vec2 shadowHalfSize = max(halfSize + vec2(uShadowSpread), vec2(0.0));
148
+ float shadowD = sdRoundedBox(shadowP, shadowHalfSize, shadowRadius);
149
+ float blur = max(uShadowBlur, 1.0);
150
+ float shadowMask = 1.0 - smoothstep(-blur * 0.5, blur * 0.5, shadowD);
151
+ shadowLayer = vec4(uShadowColor.rgb, uShadowColor.a * shadowMask);
152
+ }
153
+
154
+ vec4 finalColor = blendSrcOver(mainColor, shadowLayer);
155
+
137
156
  // final color control (Tint, Noise)
138
157
  #INJECT_COLOR_MODIFIER
139
158
 
140
- float finalOpacity = finalColor.a * bgMask * uOpacity;
159
+ float finalOpacity = finalColor.a * uOpacity;
141
160
  if (finalOpacity < 0.001) discard;
142
161
 
143
162
  gl_FragColor = vec4(finalColor.rgb, finalOpacity);
@@ -145,24 +164,25 @@ void main() {
145
164
 
146
165
  // #include <colorspace_fragment>
147
166
  }
148
- `,qe=`uniform sampler2D uTexture;
167
+ `,je=`uniform sampler2D uTexture;
149
168
  varying vec4 vScreenPos;
150
169
  uniform vec2 uTextureRepeat;
151
- uniform vec2 uTextureOffset;`,$e=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
170
+ uniform vec2 uTextureOffset;`,Ke=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
152
171
  vec2 resultUv = screenUv;
153
172
 
154
- `,je=`vec4 texColor = texture2D(uTexture, resultUv);
155
- baseColor = blendSrcOver(baseColor, texColor);`,Ae={vertexShader:Pe,fragmentShader:Ge},Ie={declChunk:qe,uvChunk:$e,baseColorChunk:je};function Ke(s,e,t,r=null,i){var C;const l=r!==null||!!s.imageSrc;let n="";const a={};if(i!=null&&i.uniforms)for(const[S,w]of Object.entries(i.uniforms))typeof w=="number"?(n+=`uniform float ${S};
156
- `,a[S]={value:w}):Array.isArray(w)?w.length===2?(n+=`uniform vec2 ${S};
157
- `,a[S]={value:new y.Vector2(...w)}):w.length===3?(n+=`uniform vec3 ${S};
158
- `,a[S]={value:new y.Vector3(...w)}):w.length===4&&(n+=`uniform vec4 ${S};
159
- `,a[S]={value:new y.Vector4(...w)}):(n+=`uniform float ${S};
160
- `,a[S]={value:w});const o=i!==void 0,c=(l||o?Ie.declChunk:"")+`
161
- `+n,d=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
162
- `,h=s.isTraveler?`vec2 resultUv = screenUv;
163
- `:`vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
164
- `,f=l||o?d+h+((i==null?void 0:i.uvModifier)||""):"",v=l||o?Ie.baseColorChunk:"",g=(i==null?void 0:i.colorModifier)||"",m=Ae.fragmentShader.replace("#INJECT_DECLARATIONS",c).replace("#INJECT_UV_MODIFIER",f).replace("#INJECT_BASE_COLOR",v).replace("#INJECT_COLOR_MODIFIER",g),x=fe(s.backgroundColor),A=fe(s.borderColor),D={uSize:{value:new y.Vector2(e,t)},uBgColor:{value:new y.Vector4(x.color.r,x.color.g,x.color.b,x.alpha)},uBorderColor:{value:new y.Vector4(A.color.r,A.color.g,A.color.b,A.alpha)},uBorderRadius:{value:new y.Vector4(0,0,0,0)},uBorderWidth:{value:se(s.borderWidth)},uOpacity:{value:(C=s.opacity)!=null?C: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)}};ke(D.uBorderRadius.value,s.borderRadius,Math.min(e,t)),l&&(D.uTexture.value=r);const M=new y.ShaderMaterial({uniforms:re(re({},D),a),vertexShader:Ae.vertexShader,fragmentShader:m,transparent:!0,side:y.FrontSide});return s.backgroundImage&&Ee(M,{backgroundImage:s.backgroundImage}),M}function Je(s,e,t,r,i){const l=se(e.borderWidth);Ee(s,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:l,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage})}function Ee(s,e){var r,i,l;if(e.width!==void 0&&e.height!==void 0&&s.uniforms.uSize.value.set(e.width,e.height),e.borderRadius!==void 0){const n=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(s.uniforms.uSize.value.x,s.uniforms.uSize.value.y);ke(s.uniforms.uBorderRadius.value,e.borderRadius,n)}if(e.borderWidth!==void 0&&(s.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],n)}else if(typeof e.backgroundColor=="string"){const n=fe(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=fe(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,o=(i=e.width)!=null?i:s.uniforms.uSize.value.x,c=(l=e.height)!=null?l:s.uniforms.uSize.value.y;if(n&&a&&o&&c){const d=n/a,h=o/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=He(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 o=n.stops[a];s.uniforms.uGradientColors.value[a].set(o.color.r,o.color.g,o.color.b,o.alpha),s.uniforms.uGradientStops.value[a]=o.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 ke(s,e,t=0){var o,c,d,h;if(e==null){s.set(0,0,0,0);return}if(typeof e=="number"){s.set(e,e,e,e);return}if(Array.isArray(e)){s.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=se(r[0],t),l=se((o=r[1])!=null?o:r[0],t),n=se((c=r[2])!=null?c:r[0],t),a=se((h=(d=r[3])!=null?d:r[1])!=null?h:r[0],t);s.set(i,l,n,a)}const P={create(s,e,t,r,i,l=2,n=null,a){return s==="BOX"?Ke(e,r,i,n,a):s==="TEXT"?new ze(t||"",e,r,i,l):new y.MeshBasicMaterial({visible:!1})},update(s,e,t,r,i,l,n=2,a){e==="BOX"?Je(s,t,i,l,a):e==="TEXT"&&s.updateText(r||"",t,i,l,n)},forceUpdateUniforms(s,e){Ee(s,e)}};class Ze{constructor(e,t=!0){p(this,"observer");p(this,"textures",new WeakMap);p(this,"loadStatus",new WeakMap);p(this,"elementUrls",new WeakMap);p(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const l=i.target;i.isIntersecting?this.loadTexture(l):this.disposeTexture(l)}},{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 Ne(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((l,n)=>{const a=new Image;a.onload=()=>l(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 y.Texture(r);r instanceof HTMLImageElement||(i.flipY=!1),i.colorSpace=y.LinearSRGBColorSpace,i.needsUpdate=!0,this.textures.set(e,i),this.onUpdate(e,i)}catch(r){console.warn("[MirageEngine] Failed to load texture:",t,r)}finally{this.elementUrls.has(e)&&this.loadStatus.set(e,!1)}}})}disposeTexture(e){const t=this.textures.get(e);t&&(t.dispose(),this.textures.delete(e),this.onUpdate(e,null)),this.loadStatus.set(e,!1)}get(e){return this.textures.get(e)}disposeAll(){this.observer&&this.observer.disconnect()}}class Qe{constructor(e,t,r,i){p(this,"canvas");p(this,"scene");p(this,"camera");p(this,"renderer");p(this,"renderTargets",[]);p(this,"renderOrder",0);p(this,"qualityFactor",2);p(this,"mode","overlay");p(this,"canvasSize","viewport");p(this,"clipArea",1);p(this,"targetLayer","base");p(this,"overscan",200);p(this,"target");p(this,"mountContainer");p(this,"registry");p(this,"targetRect");p(this,"travelersByLayer",Array.from({length:O.MAX_LAYERS},()=>new Set));p(this,"textureManager");p(this,"fixedMeshes",new Set);var a,o,c,d,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(a=t.mode)!=null?a:"overlay",this.canvasSize=(o=t.canvasSize)!=null?o:"viewport",this.clipArea=(c=t.travelerClipArea)!=null?c:1,this.targetLayer=(d=t.layer)!=null?d:"base",this.textureManager=new Ze((f,v)=>{const g=this.registry.get(f);g&&g.material instanceof y.ShaderMaterial&&P.forceUpdateUniforms(g.material,{texture:v})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new y.Scene,this.targetRect=this.target.getBoundingClientRect();const l=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(l/-2,l/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(l,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"?B.SELECTED:B.BASE}createRenderTarget(){for(let e=0;e<O.MAX_LAYERS;e++){const t=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,r=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.renderTargets.push(new y.WebGLRenderTarget(t*this.qualityFactor,r*this.qualityFactor,{minFilter:y.LinearFilter,magFilter:y.LinearFilter,format:y.RGBAFormat,stencilBuffer:!1,depthBuffer:!0}))}}applyTextQuality(e){if(typeof e=="number"){this.qualityFactor=Math.max(.1,e);return}switch(e){case"low":this.qualityFactor=1;break;case"high":this.qualityFactor=4;break;case"medium":this.qualityFactor=2;break;default:this.qualityFactor=2;break}}mount(){this.mountContainer.prepend(this.canvas),this.canvas.style.pointerEvents=this.mode==="overlay"?"none":"auto",this.updateCanvasLayout()}updateCanvasLayout(){const e=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,t=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.mode==="duplicate"?(this.canvas.style.position="",this.canvas.style.top="",this.canvas.style.left="",this.canvas.style.display="block"):(this.canvas.style.position=this.isViewport?"fixed":"absolute",this.canvas.style.top=this.isViewport?`-${this.overscan}px`:`${this.target.offsetTop}px`,this.canvas.style.left=this.isViewport?`-${this.overscan}px`:`${this.target.offsetLeft}px`,this.canvas.style.display="block")}updateUniforms(e,t){const r=this.registry.get(e);r&&(r.traverse(i=>{i.isMesh&&i.material&&P.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&P.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,l=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,o=Math.abs(i-n)>.1||Math.abs(l-a)>.1,c=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);o?(this.targetRect=r,this.setSize(i,l),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 y.Mesh&&(f.geometry&&f.geometry.dispose(),f.material&&(Array.isArray(f.material)?f.material.forEach(v=>v.dispose()):f.material.dispose()))}),this.registry.remove(d),this.textureManager.unregister(d)}})}reconcileNode(e){var i,l;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof y.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const n=new y.PlaneGeometry(1,1),a=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),o=P.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,a,e.shaderHooks);t=new y.Mesh(n,o),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=o,t.userData.domElement=e.element,t.userData.shaderHash=r}if((l=e.nativeStyles)!=null&&l.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let n=0;n<O.MAX_LAYERS;n++)n===e.captureLayer-2?this.travelersByLayer[n].add(t):this.travelersByLayer[n].delete(t);else for(const n of this.travelersByLayer)n.delete(t);if(e.isFixed?this.fixedMeshes.add(t):this.fixedMeshes.delete(t),e.styles.imageSrc?this.textureManager.register(e.element,e.styles.imageSrc):this.textureManager.unregister(e.element),e.type==="BOX")for(const n of e.children)this.reconcileNode(n);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var c;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],l=r?t.nativeStyles:t.textStyles,n=JSON.stringify(l)+t.textContent+i.map(d=>d.text).join("|"),a=(c=e.userData)==null?void 0:c.textChildStyleHash;if(t.dirtyMask&ve||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,v=h.y+h.height/2;i.forEach((g,m)=>{const x=P.create("TEXT",l,g.text,g.rect.width,g.rect.height,this.qualityFactor),A=new y.PlaneGeometry(1,1),D=new y.Mesh(A,x);D.name=`TEXT_CHILD_${m}`;const M=t.rect.width===0?1:g.rect.width/t.rect.width,C=t.rect.height===0?1:g.rect.height/t.rect.height;D.scale.set(M,C,1);const S=g.rect.x+g.rect.width/2,w=g.rect.y+g.rect.height/2,V=S-f,z=-(w-v);D.position.set(t.rect.width===0?0:V/t.rect.width,t.rect.height===0?0:z/t.rect.height,.005),e.add(D)}),e.userData.textChildStyleHash=n}e.children.forEach(d=>{if(!d.name.startsWith("TEXT_CHILD"))return;const h=d;if(r&&t.nativeLayer!==void 0)h.layers.set(B.HIDDEN),t.visibility&H&&h.layers.enable(B.getCaptureLayer(t.nativeLayer));else{const f=t.visibility&H?B.BASE:B.HIDDEN;if(h.layers.set(f),t.visibility&te&&h.layers.enable(B.SELECTED),t.visibility&H)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let v=t.captureLayer;v<=O.MAX_LAYERS+1;v++)v!==t.nativeLayer&&h.layers.enable(B.getCaptureLayer(v));else for(let v=t.captureLayer;v<=O.MAX_LAYERS+1;v++)h.layers.enable(B.getCaptureLayer(v))}})}updateMeshProperties(e,t){var M,C,S;const{rect:r,styles:i}=t,l=this.renderer.getPixelRatio(),n=this.renderer.domElement.width/l,a=this.renderer.domElement.height/l;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 o=.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 w=r.x-c,V=r.y-d;h=w-n/2+r.width/2,f=-V+a/2-r.height/2}e.position.set(h,f,i.zIndex+this.renderOrder*o);const v=r.x,g=r.y;e.userData.basePosition={x:h,y:f},e.userData.originalBasePosition={x:h,y:f},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:v,y:g},e.userData.isFixed=t.isFixed,e.userData.initialScroll={x:window.scrollX,y:window.scrollY};const m=t.element.nodeType===Node.TEXT_NODE?t.element.parentElement:t.element,x=window.getComputedStyle(m);let A=0,D=0;if(x.transform&&x.transform!=="none"){const w=new DOMMatrix(x.transform);A=w.m41,D=w.m42}if(e.userData.baseTransform={x:A,y:D},delete e.userData.originRatioX,delete e.userData.originRatioY,P.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(M=this.renderTargets[t.captureLayer-2])==null?void 0:M.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const W=P.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(C=this.renderTargets[t.captureLayer-2])==null?void 0:C.texture:this.textureManager.get(t.element),t.shaderHooks),G=new y.Mesh(e.geometry,W);t.type==="TEXT"&&(G.name="BG_MESH"),this.scene.add(G),e.userData.nativeMesh=G}const w=e.userData.nativeMesh;let V,z;if(this.isViewport)V=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,z=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const W=t.nativeRect.x-c,G=t.nativeRect.y-d;V=W-n/2+t.nativeRect.width/2,z=-G+a/2-t.nativeRect.height/2}let E=t.nativeRect.width,N=t.nativeRect.height,J=V,Z=z;if(t.nativeStyles.transform){const W=t.nativeStyles.transform,G=W.match(/scale\(([\d.]+%?)\)/);if(G){let u=parseFloat(G[1]);G[1].includes("%")&&(u/=100),E*=u,N*=u}const ne=W.match(/scaleX\(([\d.]+%?)\)/);if(ne){let u=parseFloat(ne[1]);ne[1].includes("%")&&(u/=100),E*=u}const ae=W.match(/scaleY\(([\d.]+%?)\)/);if(ae){let u=parseFloat(ae[1]);ae[1].includes("%")&&(u/=100),N*=u}const oe=W.match(/translate\(([^,]+),\s*([^)]+)\)/);if(oe){const u=oe[1].trim(),T=oe[2].trim();let _=parseFloat(u);u.includes("%")&&(_=_/100*t.nativeRect.width);let Y=parseFloat(T);T.includes("%")&&(Y=Y/100*t.nativeRect.height),J+=_,Z-=Y}const ge=W.match(/translateX\(([^)]+)\)/);if(ge){const u=ge[1].trim();let T=parseFloat(u);u.includes("%")&&(T=T/100*t.nativeRect.width),J+=T}const pe=W.match(/translateY\(([^)]+)\)/);if(pe){const u=pe[1].trim();let T=parseFloat(u);u.includes("%")&&(T=T/100*t.nativeRect.height),Z-=T}}w.scale.set(E,N,1),w.position.set(J,Z,t.nativeStyles.zIndex+this.renderOrder*o),P.update(w.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(S=this.renderTargets[t.captureLayer-2])==null?void 0:S.texture:this.textureManager.get(t.element))}else e.userData.nativeMesh&&(this.scene.remove(e.userData.nativeMesh),e.userData.nativeMesh.material instanceof y.Material&&e.userData.nativeMesh.material.dispose(),delete e.userData.nativeMesh)}updateMeshLayers(e,t){const r=t.visibility&H?B.BASE:B.HIDDEN;if(e.layers.set(r),t.visibility&te&&e.layers.enable(B.SELECTED),e.userData.nativeMesh&&t.nativeLayer!==void 0){const i=e.userData.nativeMesh;if(i.layers.set(B.HIDDEN),t.visibility&H){i.layers.enable(B.getCaptureLayer(t.nativeLayer));for(let l=t.captureLayer;l<=O.MAX_LAYERS+1;l++)l!==t.nativeLayer&&e.layers.enable(B.getCaptureLayer(l))}}else if(t.visibility&H)for(let i=t.captureLayer;i<=O.MAX_LAYERS+1;i++)e.layers.enable(B.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new y.Color,l=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const n=new y.Vector3,a=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,o=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*o;let v=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(v=parseFloat(this.clipArea));const m=d.scale.x*g+.5,x=d.scale.y*g+.5,A=h-m/2,D=f-x/2,M=(A*this.qualityFactor-v)/c,C=(D*this.qualityFactor-v)/c,S=(m*this.qualityFactor+v*2)/c,w=(x*this.qualityFactor+v*2)/c;this.renderer.setScissor(M,C,S,w),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,l)}render(){for(let e=0;e<O.MAX_LAYERS;e++){const t=e+1;this.captureRenderTarget(this.travelersByLayer[e],B.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,l=this.renderer.domElement.height/r;this.scene.children.forEach(n=>{const a=n;if(!a.userData||!a.userData.domElement)return;const o=a.userData.domElement;if(!o.isConnected)return;let c;if(o.nodeType===Node.TEXT_NODE){const h=document.createRange();h.selectNode(o),c=h.getBoundingClientRect()}else c=o.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 v=c.x-e,g=c.y-t;h=v-i/2+c.width/2,f=-g+l/2-c.height/2}if(a.position.setX(h),a.position.setY(f),a.scale.set(c.width,c.height,1),a.updateMatrixWorld(),a.material instanceof y.ShaderMaterial&&P.forceUpdateUniforms(a.material,{width:c.width,height:c.height}),a.userData.nativeMesh){const v=a.userData.nativeMesh;let g=c.width,m=c.height,x=h,A=f;if(a.userData.nativeTransform){const D=a.userData.nativeTransform,M=D.match(/scale\(([\d.]+%?)\)/);if(M){let E=parseFloat(M[1]);M[1].includes("%")&&(E/=100),g*=E,m*=E}const C=D.match(/scaleX\(([\d.]+%?)\)/);if(C){let E=parseFloat(C[1]);C[1].includes("%")&&(E/=100),g*=E}const S=D.match(/scaleY\(([\d.]+%?)\)/);if(S){let E=parseFloat(S[1]);S[1].includes("%")&&(E/=100),m*=E}const w=D.match(/translate\(([^,]+),\s*([^)]+)\)/);if(w){const E=w[1].trim(),N=w[2].trim();let J=parseFloat(E);E.includes("%")&&(J=J/100*c.width);let Z=parseFloat(N);N.includes("%")&&(Z=Z/100*c.height),x+=J,A-=Z}const V=D.match(/translateX\(([^)]+)\)/);if(V){const E=V[1].trim();let N=parseFloat(E);E.includes("%")&&(N=N/100*c.width),x+=N}const z=D.match(/translateY\(([^)]+)\)/);if(z){const E=z[1].trim();let N=parseFloat(E);E.includes("%")&&(N=N/100*c.height),A-=N}}v.position.setX(x),v.position.setY(A),v.scale.set(g,m,1),v.updateMatrixWorld(),v.material instanceof y.ShaderMaterial&&P.forceUpdateUniforms(v.material,{width:g,height:m})}}})}}function et(s){const e=s.textContent||"",t=[];let r="",i=null,l=-1;const n=(c,d)=>{for(let h=0;h<c.length;h++){const f=c[h],v=document.createRange();v.setStart(s,d+h),v.setEnd(s,d+h+1);const g=v.getBoundingClientRect();if(g.width===0&&g.height===0){r+=f;continue}l===-1||Math.abs(g.top-l)>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},l=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 o=0;for(const c of a){const d=document.createRange();d.setStart(s,o),d.setEnd(s,o+c.length);const h=d.getClientRects();if(h.length>1)n(c,o);else{const f=h.length===1?h[0]:d.getBoundingClientRect();if(f.width===0&&f.height===0){r+=c,o+=c.length;continue}l===-1||Math.abs(f.top-l)>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},l=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)))}o+=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 Ue(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 Oe(s,e=Q|ie|Re|ve|ue,t,r=1,i=0,l=2,n,a){var G,ne,ae,oe,ge,pe;if(s.nodeType===Node.TEXT_NODE){const u=s;if(!u.textContent||!u.textContent.trim())return null;const T=u.textContent.replace(/\s+/g," ");if(T.length===0)return null;const _=et(u);if(_.length===0)return null;const Y=u.parentElement,F=Y?window.getComputedStyle(Y):null;if(!F)return null;const K=Math.min(..._.map(R=>R.rect.left)),q=Math.min(..._.map(R=>R.rect.top)),ee=Math.max(..._.map(R=>R.rect.left+R.rect.width)),I=Math.max(..._.map(R=>R.rect.top+R.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:u,rect:{x:K+window.scrollX,y:q+window.scrollY,width:ee-K,height:I-q},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:Y&&Y.dataset[$.KEY]===$.VALUES.HIDE?1:parseFloat(F.opacity),zIndex:(isNaN(parseInt(F.zIndex))?0:parseInt(F.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:T,textLines:_.map(R=>({text:R.text.trim(),rect:{x:R.rect.left+window.scrollX,y:R.rect.top+window.scrollY,width:R.rect.width,height:R.rect.height}})),textStyles:Ue(F),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:F.position==="fixed",nativeLayer:n,nativeStyles:a?re(re({backgroundColor:"transparent",backgroundImage:"",opacity:Y&&Y.dataset[$.KEY]===$.VALUES.HIDE?1:parseFloat(F.opacity),zIndex:(isNaN(parseInt(F.zIndex))?0:parseInt(F.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Ue(F)),a):void 0,nativeRect:a?{x:K+window.scrollX,y:q+window.scrollY,width:ee-K,height:I-q}:void 0,children:[]}}if(s.nodeType!==Node.ELEMENT_NODE)return null;const o=s,c=o.dataset[U.KEY];let d=t,h=t;if(c){const u=new Set(c.split(/\s+/));for(const T of u)if(!be.includes(T))throw new Error(`[MirageEngine] Invalid filter token: '${T}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(u.has(U.VALUES.END))return null;if(u.has(U.VALUES.INCLUDE_TREE)&&u.has(U.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(u.has(U.VALUES.INCLUDE_SELF)&&u.has(U.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");u.has(U.VALUES.INCLUDE_TREE)?d=d|H:u.has(U.VALUES.EXCLUDE_TREE)&&(d=d&~H),h=d,u.has(U.VALUES.INCLUDE_SELF)?h=h|H:u.has(U.VALUES.EXCLUDE_SELF)&&(h=h&~H)}const f=o.dataset[X.KEY];if(f){const u=new Set(f.split(/\s+/));for(const T of u)if(!be.includes(T))throw new Error(`[MirageEngine] Invalid select token: '${T}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(u.has(X.VALUES.END))return null;if(u.has(X.VALUES.INCLUDE_TREE)&&u.has(X.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(u.has(X.VALUES.INCLUDE_SELF)&&u.has(X.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");u.has(X.VALUES.INCLUDE_TREE)?d=d|te:u.has(X.VALUES.EXCLUDE_TREE)&&(d=d&~te),h=d,u.has(X.VALUES.INCLUDE_SELF)?h=h|te:u.has(X.VALUES.EXCLUDE_SELF)&&(h=h&~te)}const v=o.dataset[O.KEY];let g=!1,m=a?re({},a):{},x=n;if(v){let u=1;const T=v.indexOf("{"),_=v.lastIndexOf("}");let Y=v;if(T!==-1&&_!==-1&&_>T){Y=v.substring(0,T).trim();const I=v.substring(T,_+1);try{m=new Function("return "+I)()}catch(R){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${I}`)}}const F=Y.split(/\s+/);let K=!1;const q=F.indexOf(O.VALUES.TRAVELER);if(q!==-1){g=!0,K=!0;const I=F[q+1];if(I&&!isNaN(parseInt(I,10)))u=parseInt(I,10);else{const R=F.find(ce=>!isNaN(parseInt(ce,10)));R&&(u=parseInt(R,10))}}const ee=F.indexOf(O.VALUES.NATIVE);if(ee!==-1){const I=F[ee+1];if(I&&!isNaN(parseInt(I,10)))x=parseInt(I,10);else if(!g){const R=F.find(ce=>!isNaN(parseInt(ce,10)));R&&(x=parseInt(R,10))}}if(K){const I=u+1;if(I<r)throw new Error(`[MirageEngine] Traveler layer (${u}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(I,O.MAX_LAYERS+1)}}const A=o.dataset[Se.KEY];let D;A&&(D=JSON.parse(A));const M=o.getBoundingClientRect(),C=window.getComputedStyle(o);if(M.width===0||M.height===0||C.display==="none")return null;let S=o.getAttribute("data-mid");S||(S=Math.random().toString(36).substring(2,11),o.setAttribute("data-mid",S));const w=parseInt(C.zIndex),V=(isNaN(w)?0:w)+i;let z;if(o.tagName==="IMG")z=o.src;else if(o.tagName.toLowerCase()==="svg"){const u=o.cloneNode(!0),T=m==null?void 0:m.color,_=m==null?void 0:m.fill,Y=m==null?void 0:m.stroke,F=m==null?void 0:m.opacity,K=(R,ce)=>{const j=window.getComputedStyle(R),me=ce,nt=j.fill===j.color,at=j.stroke===j.color,we=_||(nt?T:void 0)||j.fill;we&&we!=="none"&&(me.style.fill=we);const Te=Y||(at?T:void 0)||j.stroke;Te&&Te!=="none"&&(me.style.stroke=Te),j.strokeWidth&&j.strokeWidth!=="0px"&&(me.style.strokeWidth=j.strokeWidth);const _e=T||j.color;_e&&(me.style.color=_e);const xe=F||j.opacity;xe&&xe!=="1"&&(me.style.opacity=xe);for(let ye=0;ye<R.children.length;ye++)K(R.children[ye],ce.children[ye])};K(o,u);const q=o.getBoundingClientRect(),ee=window.devicePixelRatio*l;u.hasAttribute("viewBox")||u.setAttribute("viewBox",`0 0 ${q.width} ${q.height}`),u.setAttribute("width",(q.width*ee).toString()),u.setAttribute("height",(q.height*ee).toString());let I=new XMLSerializer().serializeToString(u);I.includes("xmlns=")||(I=I.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),z=`data:image/svg+xml;utf8,${encodeURIComponent(I)}`}else if(C.backgroundImage&&C.backgroundImage!=="none"){const u=C.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);u&&(z=u[1])}const E={backgroundColor:C.backgroundColor,backgroundImage:C.backgroundImage,opacity:o.dataset[$.KEY]===$.VALUES.HIDE?1:parseFloat(C.opacity),zIndex:V,borderRadius:C.borderRadius,borderColor:C.borderColor,borderWidth:C.borderWidth,imageSrc:z,isTraveler:g},N=E;let J,Z;const W=[];return o.tagName.toLowerCase()!=="svg"&&Array.from(o.childNodes).forEach(u=>{const T=u.nodeType===Node.TEXT_NODE?h:d,_=Oe(u,e,T,r,V,l,u.nodeType===Node.TEXT_NODE?x:void 0,u.nodeType===Node.TEXT_NODE&&Object.keys(m).length>0?m:void 0);_&&W.push(_)}),{id:S,type:"BOX",element:o,rect:{x:M.left+window.scrollX,y:M.top+window.scrollY,width:M.width,height:M.height},styles:N,textContent:J,textStyles:Z,dirtyMask:e,visibility:h,isTraveler:g,captureLayer:r,nativeLayer:x,nativeStyles:x!==void 0?Be(re({},E),{backgroundColor:(G=m.backgroundColor)!=null?G:E.backgroundColor,backgroundImage:(ne=m.backgroundImage)!=null?ne:E.backgroundImage,opacity:(ae=m.opacity)!=null?ae:E.opacity,zIndex:m.zIndex!==void 0?m.zIndex+V:E.zIndex,borderRadius:(oe=m.borderRadius)!=null?oe:E.borderRadius,borderColor:(ge=m.borderColor)!=null?ge:E.borderColor,borderWidth:(pe=m.borderWidth)!=null?pe:E.borderWidth,isTraveler:E.isTraveler,transform:m.transform}):void 0,nativeRect:x!==void 0?{x:m.x!==void 0?parseFloat(m.x):M.left+window.scrollX,y:m.y!==void 0?parseFloat(m.y):M.top+window.scrollY,width:m.width!==void 0?parseFloat(m.width):M.width,height:m.height!==void 0?parseFloat(m.height):M.height}:void 0,isFixed:C.position==="fixed",children:W,shaderHooks:D}}function tt(s,e){e.size!==0&&e.forEach((t,r)=>{var l,n,a,o;const i=s.get(r);!i||!i.userData.basePosition||(P.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(n=t.borderRadius)!=null?n:(l=i.userData.baseStyles)==null?void 0:l.borderRadius}),i.userData.nativeMesh&&P.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(o=t.borderRadius)!=null?o:(a=i.userData.baseStyles)==null?void 0:a.borderRadius}))})}class rt{constructor(e,t,r,i){p(this,"target");p(this,"renderer");p(this,"registry");p(this,"isTravelEnabled",!1);p(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new Me(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((l,n)=>{document.querySelector(`[${O.NAME}~='${O.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const o=Oe(this.target,l,H,1,0,this.renderer.qualityFactor);o&&this.renderer.syncScene(o,n)}),this.tracker.onStyleChange.add(l=>{tt(this.registry,l)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class it{constructor(){p(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){p(this,"renderer");p(this,"syncer");p(this,"target");p(this,"registry");var i,l,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=`
165
- [${$.NAME}="${$.VALUES.HIDE}"] {
173
+ `,Je=`vec4 texColor = texture2D(uTexture, resultUv);
174
+ baseColor = blendSrcOver(baseColor, texColor);`,ke={vertexShader:qe,fragmentShader:$e},Ue={declChunk:je,uvChunk:Ke,baseColorChunk:Je};function Ze(n,e,t,r=null,i){var x;const c=r!==null||!!n.imageSrc;let s="";const a={};if(i!=null&&i.uniforms)for(const[M,C]of Object.entries(i.uniforms))typeof C=="number"?(s+=`uniform float ${M};
175
+ `,a[M]={value:C}):Array.isArray(C)?C.length===2?(s+=`uniform vec2 ${M};
176
+ `,a[M]={value:new v.Vector2(...C)}):C.length===3?(s+=`uniform vec3 ${M};
177
+ `,a[M]={value:new v.Vector3(...C)}):C.length===4&&(s+=`uniform vec4 ${M};
178
+ `,a[M]={value:new v.Vector4(...C)}):(s+=`uniform float ${M};
179
+ `,a[M]={value:C});const o=i!==void 0,l=(c||o?Ue.declChunk:"")+`
180
+ `+s,d=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
181
+ `,h=n.isTraveler?`vec2 resultUv = screenUv;
182
+ `:`vec2 localUv = (p / uSize) + 0.5;
183
+ vec2 resultUv = localUv * uTextureRepeat + uTextureOffset;
184
+ `,u=c||o?d+h+((i==null?void 0:i.uvModifier)||""):"",f=c||o?Ue.baseColorChunk:"",g=(i==null?void 0:i.colorModifier)||"",w=ke.fragmentShader.replace("#INJECT_DECLARATIONS",l).replace("#INJECT_UV_MODIFIER",u).replace("#INJECT_BASE_COLOR",f).replace("#INJECT_COLOR_MODIFIER",g),y=ce(n.backgroundColor),T=ce(n.borderColor),U={uSize:{value:new v.Vector2(e,t)},uMeshSize:{value:new v.Vector2(e,t)},uShadowColor:{value:new v.Vector4(0,0,0,0)},uShadowOffset:{value:new v.Vector2(0,0)},uShadowBlur:{value:0},uShadowSpread:{value:0},uBgColor:{value:new v.Vector4(y.color.r,y.color.g,y.color.b,y.alpha)},uBorderColor:{value:new v.Vector4(T.color.r,T.color.g,T.color.b,T.alpha)},uBorderRadius:{value:new v.Vector4(0,0,0,0)},uBorderWidth:{value:le(n.borderWidth)},uOpacity:{value:(x=n.opacity)!=null?x: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)}};Oe(U.uBorderRadius.value,n.borderRadius,Math.min(e,t)),c&&(U.uTexture.value=r);const I=new v.ShaderMaterial({uniforms:ae(ae({},U),a),vertexShader:ke.vertexShader,fragmentShader:w,transparent:!0,side:v.FrontSide});return n.backgroundImage&&Ee(I,{backgroundImage:n.backgroundImage}),I}function Qe(n,e,t,r,i){const c=le(e.borderWidth);Ee(n,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:c,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage,boxShadow:e.boxShadow})}function Ee(n,e){var r,i,c;if(e.boxShadow!==void 0){const s=Ge(e.boxShadow);s?(n.uniforms.uShadowColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha),n.uniforms.uShadowOffset.value.set(s.offsetX,s.offsetY),n.uniforms.uShadowBlur.value=s.blurRadius,n.uniforms.uShadowSpread.value=s.spreadRadius,n.userData.shadowPadding=s.blurRadius+s.spreadRadius+Math.max(Math.abs(s.offsetX),Math.abs(s.offsetY))):(n.uniforms.uShadowColor.value.w=0,n.userData.shadowPadding=0)}if(e.width!==void 0&&e.height!==void 0&&n.uniforms.uSize.value.set(e.width,e.height),n.uniforms.uMeshSize){const s=n.userData.shadowPadding||0,a=e.width!==void 0?e.width:n.uniforms.uSize.value.x,o=e.height!==void 0?e.height:n.uniforms.uSize.value.y;n.uniforms.uMeshSize.value.set(a+s*2,o+s*2)}if(e.borderRadius!==void 0){const s=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(n.uniforms.uSize.value.x,n.uniforms.uSize.value.y);Oe(n.uniforms.uBorderRadius.value,e.borderRadius,s)}if(e.borderWidth!==void 0&&(n.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const s=n.uniforms.uBgColor.value.w;n.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],s)}else if(typeof e.backgroundColor=="string"){const s=ce(e.backgroundColor);n.uniforms.uBgColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=n.uniforms.uBgColor.value.w;n.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,s)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const s=n.uniforms.uBorderColor.value.w;n.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],s)}else if(typeof e.borderColor=="string"){const s=ce(e.borderColor);n.uniforms.uBorderColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=n.uniforms.uBorderColor.value.w;n.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,s)}e.opacity!==void 0&&(n.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(n.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(n.uniforms.uBorderColor.value.w=e.borderOpacity),n.uniforms.uTexture&&e.texture!==void 0&&(n.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=n.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const s=t.image.naturalWidth||t.image.videoWidth||t.image.width,a=t.image.naturalHeight||t.image.videoHeight||t.image.height,o=(i=e.width)!=null?i:n.uniforms.uSize.value.x,l=(c=e.height)!=null?c:n.uniforms.uSize.value.y;if(s&&a&&o&&l){const d=s/a,h=o/l;if(d>h){const u=h/d;n.uniforms.uTextureRepeat.value.set(u,1),n.uniforms.uTextureOffset.value.set((1-u)/2,0)}else{const u=d/h;n.uniforms.uTextureRepeat.value.set(1,u),n.uniforms.uTextureOffset.value.set(0,(1-u)/2)}}}else n.uniforms.uTextureRepeat&&(n.uniforms.uTextureRepeat.value.set(1,1),n.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const s=He(e.backgroundImage);if(s){n.uniforms.uGradientCount.value=s.stops.length,n.uniforms.uGradientAngle.value=s.angle;for(let a=0;a<8;a++)if(a<s.stops.length){const o=s.stops[a];n.uniforms.uGradientColors.value[a].set(o.color.r,o.color.g,o.color.b,o.alpha),n.uniforms.uGradientStops.value[a]=o.stop}else n.uniforms.uGradientColors.value[a].set(0,0,0,0),n.uniforms.uGradientStops.value[a]=1}else n.uniforms.uGradientCount.value=0}for(const s of Object.keys(e))s!=="width"&&s!=="height"&&s!=="borderRadius"&&s!=="borderWidth"&&s!=="backgroundColor"&&s!=="borderColor"&&s!=="opacity"&&s!=="bgOpacity"&&s!=="borderOpacity"&&s!=="texture"&&s!=="backgroundImage"&&s!=="boxShadow"&&n.uniforms[s]!==void 0&&(n.uniforms[s].value!==void 0&&n.uniforms[s].value!==null&&typeof n.uniforms[s].value.set=="function"?Array.isArray(e[s])?n.uniforms[s].value.set(...e[s]):e[s]!==void 0&&(e[s].copy?n.uniforms[s].value.copy(e[s]):n.uniforms[s].value=e[s]):n.uniforms[s].value=e[s])}function Oe(n,e,t=0){var o,l,d,h;if(e==null){n.set(0,0,0,0);return}if(typeof e=="number"){n.set(e,e,e,e);return}if(Array.isArray(e)){n.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=le(r[0],t),c=le((o=r[1])!=null?o:r[0],t),s=le((l=r[2])!=null?l:r[0],t),a=le((h=(d=r[3])!=null?d:r[1])!=null?h:r[0],t);n.set(i,c,s,a)}const q={create(n,e,t,r,i,c=2,s=null,a){return n==="BOX"?Ze(e,r,i,s,a):n==="TEXT"?new We(t||"",e,r,i,c):new v.MeshBasicMaterial({visible:!1})},update(n,e,t,r,i,c,s=2,a){e==="BOX"?Qe(n,t,i,c,a):e==="TEXT"&&n.updateText(r||"",t,i,c,s)},forceUpdateUniforms(n,e){Ee(n,e)}};class et{constructor(e,t=!0){p(this,"observer");p(this,"textures",new WeakMap);p(this,"loadStatus",new WeakMap);p(this,"elementUrls",new WeakMap);p(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const c=i.target;i.isIntersecting?this.loadTexture(c):this.disposeTexture(c)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return Ye(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((c,s)=>{const a=new Image;a.onload=()=>c(a),a.onerror=s,a.src=t});else{const s=yield(yield fetch(t)).blob();r=yield createImageBitmap(s,{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 tt{constructor(e,t,r,i){p(this,"canvas");p(this,"scene");p(this,"camera");p(this,"renderer");p(this,"renderTargets",[]);p(this,"renderOrder",0);p(this,"qualityFactor",2);p(this,"mode","overlay");p(this,"canvasSize","viewport");p(this,"clipArea",1);p(this,"targetLayer","base");p(this,"overscan",200);p(this,"target");p(this,"mountContainer");p(this,"registry");p(this,"targetRect");p(this,"travelersByLayer",Array.from({length:B.MAX_LAYERS},()=>new Set));p(this,"textureManager");p(this,"fixedMeshes",new Set);var a,o,l,d,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(a=t.mode)!=null?a:"overlay",this.canvasSize=(o=t.canvasSize)!=null?o:"viewport",this.clipArea=(l=t.travelerClipArea)!=null?l:1,this.targetLayer=(d=t.layer)!=null?d:"base",this.textureManager=new et((u,f)=>{const g=this.registry.get(u);g&&g.material instanceof v.ShaderMaterial&&q.forceUpdateUniforms(g.material,{texture:f})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new v.Scene,this.targetRect=this.target.getBoundingClientRect();const c=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,s=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.camera=new v.OrthographicCamera(c/-2,c/2,s/2,s/-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(c,s),this.applyTextQuality((h=t.quality)!=null?h:"medium")}get isViewport(){return this.mode==="overlay"&&this.canvasSize==="viewport"}getSceneLayer(){return typeof this.targetLayer=="number"?this.targetLayer:this.targetLayer==="selected"?N.SELECTED:N.BASE}createRenderTarget(){for(let e=0;e<B.MAX_LAYERS;e++){const t=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,r=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.renderTargets.push(new 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&&q.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&q.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,c=this.isViewport?window.innerHeight+this.overscan*2:r.height,s=this.isViewport?this.canvas.clientWidth:this.targetRect.width,a=this.isViewport?this.canvas.clientHeight:this.targetRect.height,o=Math.abs(i-s)>.1||Math.abs(c-a)>.1,l=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);o?(this.targetRect=r,this.setSize(i,c),this.updateCanvasLayout()):l?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(d=>{const h=this.registry.get(d);if(h){this.scene.remove(h);for(const u of this.travelersByLayer)u.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(u=>u.dispose()):h.userData.nativeMesh.material.dispose(),h.userData.nativeMesh.geometry.dispose()),h.traverse(u=>{u instanceof v.Mesh&&(u.geometry&&u.geometry.dispose(),u.material&&(Array.isArray(u.material)?u.material.forEach(f=>f.dispose()):u.material.dispose()))}),this.registry.remove(d),this.textureManager.unregister(d)}})}reconcileNode(e){var i,c;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof v.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const s=new v.PlaneGeometry(1,1),a=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),o=q.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,a,e.shaderHooks);t=new v.Mesh(s,o),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=o,t.userData.domElement=e.element,t.userData.shaderHash=r}if((c=e.nativeStyles)!=null&&c.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let s=0;s<B.MAX_LAYERS;s++)s===e.captureLayer-2?this.travelersByLayer[s].add(t):this.travelersByLayer[s].delete(t);else for(const s of this.travelersByLayer)s.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 s of e.children)this.reconcileNode(s);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var l;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],c=r?t.nativeStyles:t.textStyles,s=JSON.stringify(c)+t.textContent+i.map(d=>d.text).join("|"),a=(l=e.userData)==null?void 0:l.textChildStyleHash;if(t.dirtyMask&we||s!==a){e.children.filter(g=>g.name.startsWith("TEXT_CHILD")).forEach(g=>{var y;const w=g;(y=w.material.map)==null||y.dispose(),w.geometry.dispose(),e.remove(w)});const h=t.rect,u=h.x+h.width/2,f=h.y+h.height/2;i.forEach((g,w)=>{const y=q.create("TEXT",c,g.text,g.rect.width,g.rect.height,this.qualityFactor),T=new v.PlaneGeometry(1,1),U=new v.Mesh(T,y);U.name=`TEXT_CHILD_${w}`;const I=t.rect.width===0?1:g.rect.width/t.rect.width,x=t.rect.height===0?1:g.rect.height/t.rect.height;U.scale.set(I,x,1);const M=g.rect.x+g.rect.width/2,C=g.rect.y+g.rect.height/2,$=M-u,W=-(C-f);U.position.set(t.rect.width===0?0:$/t.rect.width,t.rect.height===0?0:W/t.rect.height,.005),e.add(U)}),e.userData.textChildStyleHash=s}e.children.forEach(d=>{if(!d.name.startsWith("TEXT_CHILD"))return;const h=d;if(r&&t.nativeLayer!==void 0)h.layers.set(N.HIDDEN),t.visibility&G&&h.layers.enable(N.getCaptureLayer(t.nativeLayer));else{const u=t.visibility&G?N.BASE:N.HIDDEN;if(h.layers.set(u),t.visibility&ne&&h.layers.enable(N.SELECTED),t.visibility&G)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let f=t.captureLayer;f<=B.MAX_LAYERS+1;f++)f!==t.nativeLayer&&h.layers.enable(N.getCaptureLayer(f));else for(let f=t.captureLayer;f<=B.MAX_LAYERS+1;f++)h.layers.enable(N.getCaptureLayer(f))}})}updateMeshProperties(e,t){var x,M,C,$,W;const{rect:r,styles:i}=t,c=this.renderer.getPixelRatio(),s=this.renderer.domElement.width/c,a=this.renderer.domElement.height/c;e.material=e.userData.baseMaterial;let o=((x=e.material.userData)==null?void 0:x.shadowPadding)||0;e.scale.set(r.width+o*2,r.height+o*2,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const l=.001;this.renderOrder++;const d=this.targetRect.left+window.scrollX,h=this.targetRect.top+window.scrollY;let u,f;if(this.isViewport)u=r.x-window.innerWidth/2+r.width/2,f=-r.y+window.innerHeight/2-r.height/2;else{const L=r.x-d,J=r.y-h;u=L-s/2+r.width/2,f=-J+a/2-r.height/2}e.position.set(u,f,i.zIndex+this.renderOrder*l);const g=r.x,w=r.y;e.userData.basePosition={x:u,y:f},e.userData.originalBasePosition={x:u,y:f},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:g,y:w},e.userData.isFixed=t.isFixed,e.userData.initialScroll={x:window.scrollX,y:window.scrollY};const y=t.element.nodeType===Node.TEXT_NODE?t.element.parentElement:t.element,T=window.getComputedStyle(y);let U=0,I=0;if(T.transform&&T.transform!=="none"){const L=new DOMMatrix(T.transform);U=L.m41,I=L.m42}if(e.userData.baseTransform={x:U,y:I},delete e.userData.originRatioX,delete e.userData.originRatioY,q.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(M=this.renderTargets[t.captureLayer-2])==null?void 0:M.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const H=q.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(C=this.renderTargets[t.captureLayer-2])==null?void 0:C.texture:this.textureManager.get(t.element),t.shaderHooks),j=new v.Mesh(e.geometry,H);t.type==="TEXT"&&(j.name="BG_MESH"),this.scene.add(j),e.userData.nativeMesh=j}const L=e.userData.nativeMesh;let J,re;if(this.isViewport)J=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,re=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const H=t.nativeRect.x-d,j=t.nativeRect.y-h;J=H-s/2+t.nativeRect.width/2,re=-j+a/2-t.nativeRect.height/2}let ie=t.nativeRect.width,D=t.nativeRect.height,Y=J,Q=re;if(t.nativeStyles.transform){const H=t.nativeStyles.transform,j=H.match(/scale\(([\d.]+%?)\)/);if(j){let E=parseFloat(j[1]);j[1].includes("%")&&(E/=100),ie*=E,D*=E}const he=H.match(/scaleX\(([\d.]+%?)\)/);if(he){let E=parseFloat(he[1]);he[1].includes("%")&&(E/=100),ie*=E}const de=H.match(/scaleY\(([\d.]+%?)\)/);if(de){let E=parseFloat(de[1]);de[1].includes("%")&&(E/=100),D*=E}const m=H.match(/translate\(([^,]+),\s*([^)]+)\)/);if(m){const E=m[1].trim(),S=m[2].trim();let P=parseFloat(E);E.includes("%")&&(P=P/100*t.nativeRect.width);let z=parseFloat(S);S.includes("%")&&(z=z/100*t.nativeRect.height),Y+=P,Q-=z}const k=H.match(/translateX\(([^)]+)\)/);if(k){const E=k[1].trim();let S=parseFloat(E);E.includes("%")&&(S=S/100*t.nativeRect.width),Y+=S}const X=H.match(/translateY\(([^)]+)\)/);if(X){const E=X[1].trim();let S=parseFloat(E);E.includes("%")&&(S=S/100*t.nativeRect.height),Q-=S}}let ee=(($=L.material.userData)==null?void 0:$.shadowPadding)||0;L.scale.set(ie+ee*2,D+ee*2,1),L.position.set(Y,Q,t.nativeStyles.zIndex+this.renderOrder*l),q.update(L.material,"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))}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&G?N.BASE:N.HIDDEN;if(e.layers.set(r),t.visibility&ne&&e.layers.enable(N.SELECTED),e.userData.nativeMesh&&t.nativeLayer!==void 0){const i=e.userData.nativeMesh;if(i.layers.set(N.HIDDEN),t.visibility&G){i.layers.enable(N.getCaptureLayer(t.nativeLayer));for(let c=t.captureLayer;c<=B.MAX_LAYERS+1;c++)c!==t.nativeLayer&&e.layers.enable(N.getCaptureLayer(c))}}else if(t.visibility&G)for(let i=t.captureLayer;i<=B.MAX_LAYERS+1;i++)e.layers.enable(N.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new v.Color,c=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const s=new v.Vector3,a=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,o=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,l=this.renderer.getPixelRatio();for(const d of e){s.setFromMatrixPosition(d.matrixWorld),s.project(this.camera);const h=(s.x+1)/2*a,u=(s.y+1)/2*o;let f=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(f=parseFloat(this.clipArea));const w=d.scale.x*g+.5,y=d.scale.y*g+.5,T=h-w/2,U=u-y/2,I=(T*this.qualityFactor-f)/l,x=(U*this.qualityFactor-f)/l,M=(w*this.qualityFactor+f*2)/l,C=(y*this.qualityFactor+f*2)/l;this.renderer.setScissor(I,x,M,C),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,c)}render(){for(let e=0;e<B.MAX_LAYERS;e++){const t=e+1;this.captureRenderTarget(this.travelersByLayer[e],N.getCaptureLayer(t),this.renderTargets[e])}this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,c=this.renderer.domElement.height/r;this.scene.children.forEach(s=>{var h,u;const a=s;if(!a.userData||!a.userData.domElement)return;const o=a.userData.domElement;if(!o.isConnected)return;let l;if(o.nodeType===Node.TEXT_NODE){const f=document.createRange();f.selectNode(o),l=f.getBoundingClientRect()}else l=o.getBoundingClientRect();const d=a.userData.domRect;if(!d||Math.abs(l.x-d.x)>.5||Math.abs(l.y-d.y)>.5||Math.abs(l.width-d.width)>.5||Math.abs(l.height-d.height)>.5){a.userData.domRect={x:l.x,y:l.y,width:l.width,height:l.height};let f,g;if(this.isViewport)f=l.x-window.innerWidth/2+l.width/2,g=-l.y+window.innerHeight/2-l.height/2;else{const y=l.x-e,T=l.y-t;f=y-i/2+l.width/2,g=-T+c/2-l.height/2}a.position.setX(f),a.position.setY(g);let w=((h=a.material.userData)==null?void 0:h.shadowPadding)||0;if(a.scale.set(l.width+w*2,l.height+w*2,1),a.updateMatrixWorld(),a.material instanceof v.ShaderMaterial&&q.forceUpdateUniforms(a.material,{width:l.width,height:l.height}),a.userData.nativeMesh){const y=a.userData.nativeMesh;let T=l.width,U=l.height,I=f,x=g;if(a.userData.nativeTransform){const C=a.userData.nativeTransform,$=C.match(/scale\(([\d.]+%?)\)/);if($){let D=parseFloat($[1]);$[1].includes("%")&&(D/=100),T*=D,U*=D}const W=C.match(/scaleX\(([\d.]+%?)\)/);if(W){let D=parseFloat(W[1]);W[1].includes("%")&&(D/=100),T*=D}const L=C.match(/scaleY\(([\d.]+%?)\)/);if(L){let D=parseFloat(L[1]);L[1].includes("%")&&(D/=100),U*=D}const J=C.match(/translate\(([^,]+),\s*([^)]+)\)/);if(J){const D=J[1].trim(),Y=J[2].trim();let Q=parseFloat(D);D.includes("%")&&(Q=Q/100*l.width);let ee=parseFloat(Y);Y.includes("%")&&(ee=ee/100*l.height),I+=Q,x-=ee}const re=C.match(/translateX\(([^)]+)\)/);if(re){const D=re[1].trim();let Y=parseFloat(D);D.includes("%")&&(Y=Y/100*l.width),I+=Y}const ie=C.match(/translateY\(([^)]+)\)/);if(ie){const D=ie[1].trim();let Y=parseFloat(D);D.includes("%")&&(Y=Y/100*l.height),x-=Y}}let M=((u=y.material.userData)==null?void 0:u.shadowPadding)||0;y.position.setX(I),y.position.setY(x),y.scale.set(T+M*2,U+M*2,1),y.updateMatrixWorld(),y.material instanceof v.ShaderMaterial&&q.forceUpdateUniforms(y.material,{width:T,height:U})}}})}}function rt(n){const e=n.textContent||"",t=[];let r="",i=null,c=-1;const s=(l,d)=>{for(let h=0;h<l.length;h++){const u=l[h],f=document.createRange();f.setStart(n,d+h),f.setEnd(n,d+h+1);const g=f.getBoundingClientRect();if(g.width===0&&g.height===0){r+=u;continue}c===-1||Math.abs(g.top-c)>g.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=u,i={left:g.left,top:g.top,right:g.right,bottom:g.bottom},c=g.top):(r+=u,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 o=0;for(const l of a){const d=document.createRange();d.setStart(n,o),d.setEnd(n,o+l.length);const h=d.getClientRects();if(h.length>1)s(l,o);else{const u=h.length===1?h[0]:d.getBoundingClientRect();if(u.width===0&&u.height===0){r+=l,o+=l.length;continue}c===-1||Math.abs(u.top-c)>u.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=l,i={left:u.left,top:u.top,right:u.right,bottom:u.bottom},c=u.top):(r+=l,i&&(i.left=Math.min(i.left,u.left),i.top=Math.min(i.top,u.top),i.right=Math.max(i.right,u.right),i.bottom=Math.max(i.bottom,u.bottom)))}o+=l.length}return r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),t.filter(l=>l.text.trim().length>0&&l.rect.width>0&&l.rect.height>0)}function Fe(n){const e=parseFloat(n.fontSize);let t=parseFloat(n.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(n.letterSpacing);return isNaN(r)&&(r=0),{font:`${n.fontStyle} ${n.fontWeight} ${n.fontSize} ${n.fontFamily}`,fontSize:n.fontSize,color:n.color,textAlign:n.textAlign||"start",textBaseline:"alphabetic",direction:n.direction||"inherit",lineHeight:t,letterSpacing:r}}function _e(n,e=te|oe|Me|we|me,t,r=1,i=0,c=2,s,a){var Y,Q,ee,H,j,he,de;if(n.nodeType===Node.TEXT_NODE){const m=n;if(!m.textContent||!m.textContent.trim())return null;const k=m.textContent.replace(/\s+/g," ");if(k.length===0)return null;const X=rt(m);if(X.length===0)return null;const E=m.parentElement,S=E?window.getComputedStyle(E):null;if(!S)return null;const P=Math.min(...X.map(R=>R.rect.left)),z=Math.min(...X.map(R=>R.rect.top)),se=Math.max(...X.map(R=>R.rect.left+R.rect.width)),O=Math.max(...X.map(R=>R.rect.top+R.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:m,rect:{x:P+window.scrollX,y:z+window.scrollY,width:se-P,height:O-z},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:E&&E.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(S.opacity),zIndex:(isNaN(parseInt(S.zIndex))?0:parseInt(S.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:k,textLines:X.map(R=>({text:R.text.trim(),rect:{x:R.rect.left+window.scrollX,y:R.rect.top+window.scrollY,width:R.rect.width,height:R.rect.height}})),textStyles:Fe(S),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:S.position==="fixed",nativeLayer:s,nativeStyles:a?ae(ae({backgroundColor:"transparent",backgroundImage:"",opacity:E&&E.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(S.opacity),zIndex:(isNaN(parseInt(S.zIndex))?0:parseInt(S.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Fe(S)),a):void 0,nativeRect:a?{x:P+window.scrollX,y:z+window.scrollY,width:se-P,height:O-z}:void 0,children:[]}}if(n.nodeType!==Node.ELEMENT_NODE)return null;const o=n,l=o.dataset[_.KEY];let d=t,h=t;if(l){const m=new Set(l.split(/\s+/));for(const k of m)if(!ye.includes(k))throw new Error(`[MirageEngine] Invalid filter token: '${k}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(m.has(_.VALUES.END))return null;if(m.has(_.VALUES.INCLUDE_TREE)&&m.has(_.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(_.VALUES.INCLUDE_SELF)&&m.has(_.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");m.has(_.VALUES.INCLUDE_TREE)?d=d|G:m.has(_.VALUES.EXCLUDE_TREE)&&(d=d&~G),h=d,m.has(_.VALUES.INCLUDE_SELF)?h=h|G:m.has(_.VALUES.EXCLUDE_SELF)&&(h=h&~G)}const u=o.dataset[V.KEY];if(u){const m=new Set(u.split(/\s+/));for(const k of m)if(!ye.includes(k))throw new Error(`[MirageEngine] Invalid select token: '${k}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(m.has(V.VALUES.END))return null;if(m.has(V.VALUES.INCLUDE_TREE)&&m.has(V.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(m.has(V.VALUES.INCLUDE_SELF)&&m.has(V.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");m.has(V.VALUES.INCLUDE_TREE)?d=d|ne:m.has(V.VALUES.EXCLUDE_TREE)&&(d=d&~ne),h=d,m.has(V.VALUES.INCLUDE_SELF)?h=h|ne:m.has(V.VALUES.EXCLUDE_SELF)&&(h=h&~ne)}const f=o.dataset[B.KEY];let g=!1,w=a?ae({},a):{},y=s;if(f){let m=1;const k=f.indexOf("{"),X=f.lastIndexOf("}");let E=f;if(k!==-1&&X!==-1&&X>k){E=f.substring(0,k).trim();const O=f.substring(k,X+1);try{w=new Function("return "+O)()}catch(R){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${O}`)}}const S=E.split(/\s+/);let P=!1;const z=S.indexOf(B.VALUES.TRAVELER);if(z!==-1){g=!0,P=!0;const O=S[z+1];if(O&&!isNaN(parseInt(O,10)))m=parseInt(O,10);else{const R=S.find(ue=>!isNaN(parseInt(ue,10)));R&&(m=parseInt(R,10))}}const se=S.indexOf(B.VALUES.NATIVE);if(se!==-1){const O=S[se+1];if(O&&!isNaN(parseInt(O,10)))y=parseInt(O,10);else if(!g){const R=S.find(ue=>!isNaN(parseInt(ue,10)));R&&(y=parseInt(R,10))}}if(P){const O=m+1;if(O<r)throw new Error(`[MirageEngine] Traveler layer (${m}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(O,B.MAX_LAYERS+1)}}const T=o.dataset[Re.KEY];let U;T&&(U=JSON.parse(T));const I=o.getBoundingClientRect(),x=window.getComputedStyle(o);if(I.width===0||I.height===0||x.display==="none")return null;let M=o.getAttribute("data-mid");M||(M=Math.random().toString(36).substring(2,11),o.setAttribute("data-mid",M));const C=parseInt(x.zIndex),$=(isNaN(C)?0:C)+i;let W;if(o.tagName==="IMG")W=o.src;else if(o.tagName.toLowerCase()==="svg"){const m=o.cloneNode(!0),k=w==null?void 0:w.color,X=w==null?void 0:w.fill,E=w==null?void 0:w.stroke,S=w==null?void 0:w.opacity,P=(R,ue)=>{const Z=window.getComputedStyle(R),ve=ue,ot=Z.fill===Z.color,lt=Z.stroke===Z.color,Se=X||(ot?k:void 0)||Z.fill;Se&&Se!=="none"&&(ve.style.fill=Se);const xe=E||(lt?k:void 0)||Z.stroke;xe&&xe!=="none"&&(ve.style.stroke=xe),Z.strokeWidth&&Z.strokeWidth!=="0px"&&(ve.style.strokeWidth=Z.strokeWidth);const Be=k||Z.color;Be&&(ve.style.color=Be);const Ce=S||Z.opacity;Ce&&Ce!=="1"&&(ve.style.opacity=Ce);for(let be=0;be<R.children.length;be++)P(R.children[be],ue.children[be])};P(o,m);const z=o.getBoundingClientRect(),se=window.devicePixelRatio*c;m.hasAttribute("viewBox")||m.setAttribute("viewBox",`0 0 ${z.width} ${z.height}`),m.setAttribute("width",(z.width*se).toString()),m.setAttribute("height",(z.height*se).toString());let O=new XMLSerializer().serializeToString(m);O.includes("xmlns=")||(O=O.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),W=`data:image/svg+xml;utf8,${encodeURIComponent(O)}`}else if(x.backgroundImage&&x.backgroundImage!=="none"){const m=x.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);m&&(W=m[1])}const L={backgroundColor:x.backgroundColor,backgroundImage:x.backgroundImage,opacity:o.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(x.opacity),zIndex:$,borderRadius:x.borderRadius,borderColor:x.borderColor,borderWidth:x.borderWidth,boxShadow:x.boxShadow,imageSrc:W,isTraveler:g},J=L;let re,ie;const D=[];return o.tagName.toLowerCase()!=="svg"&&Array.from(o.childNodes).forEach(m=>{const k=m.nodeType===Node.TEXT_NODE?h:d,X=_e(m,e,k,r,$,c,m.nodeType===Node.TEXT_NODE?y:void 0,m.nodeType===Node.TEXT_NODE&&Object.keys(w).length>0?w:void 0);X&&D.push(X)}),{id:M,type:"BOX",element:o,rect:{x:I.left+window.scrollX,y:I.top+window.scrollY,width:I.width,height:I.height},styles:J,textContent:re,textStyles:ie,dirtyMask:e,visibility:h,isTraveler:g,captureLayer:r,nativeLayer:y,nativeStyles:y!==void 0?Xe(ae({},L),{backgroundColor:(Y=w.backgroundColor)!=null?Y:L.backgroundColor,backgroundImage:(Q=w.backgroundImage)!=null?Q:L.backgroundImage,opacity:(ee=w.opacity)!=null?ee:L.opacity,zIndex:w.zIndex!==void 0?w.zIndex+$:L.zIndex,borderRadius:(H=w.borderRadius)!=null?H:L.borderRadius,borderColor:(j=w.borderColor)!=null?j:L.borderColor,borderWidth:(he=w.borderWidth)!=null?he:L.borderWidth,boxShadow:(de=w.boxShadow)!=null?de:L.boxShadow,isTraveler:L.isTraveler,transform:w.transform}):void 0,nativeRect:y!==void 0?{x:w.x!==void 0?parseFloat(w.x):I.left+window.scrollX,y:w.y!==void 0?parseFloat(w.y):I.top+window.scrollY,width:w.width!==void 0?parseFloat(w.width):I.width,height:w.height!==void 0?parseFloat(w.height):I.height}:void 0,isFixed:x.position==="fixed",children:D,shaderHooks:U}}function it(n,e){e.size!==0&&e.forEach((t,r)=>{var c,s,a,o;const i=n.get(r);!i||!i.userData.basePosition||(q.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(s=t.borderRadius)!=null?s:(c=i.userData.baseStyles)==null?void 0:c.borderRadius}),i.userData.nativeMesh&&q.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(o=t.borderRadius)!=null?o:(a=i.userData.baseStyles)==null?void 0:a.borderRadius}))})}class st{constructor(e,t,r,i){p(this,"target");p(this,"renderer");p(this,"registry");p(this,"isTravelEnabled",!1);p(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new De(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((c,s)=>{document.querySelector(`[${B.NAME}~='${B.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const o=_e(this.target,c,G,1,0,this.renderer.qualityFactor);o&&this.renderer.syncScene(o,s)}),this.tracker.onStyleChange.add(c=>{it(this.registry,c)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class nt{constructor(){p(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 at{constructor(e,t){p(this,"renderer");p(this,"syncer");p(this,"target");p(this,"registry");var i,c,s;if(this.target=e,this.registry=new nt,!document.getElementById("mirage-engine-styles")){const a=document.createElement("style");a.id="mirage-engine-styles",a.textContent=`
185
+ [${K.NAME}="${K.VALUES.HIDE}"] {
166
186
  opacity: 0 !important;
167
187
  }
168
- `,document.head.appendChild(a)}let r;if(t.mode==="duplicate"?r=(l=(i=t.container)!=null?i:this.target.parentElement)!=null?l:void 0:r=(n=this.target.parentElement)!=null?n:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new Qe(this.target,t,r,this.registry),this.renderer.mount(),this.syncer=new 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",l=>{t[l.key]!==void 0&&(t[l.key]=!0)}),window.addEventListener("keyup",l=>{t[l.key]!==void 0&&(t[l.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()}}b.ALLOWED_FILTERS=be,b.ATTR_DOM=$,b.ATTR_FILTER=U,b.ATTR_SANDWICH=Xe,b.ATTR_SELECT=X,b.ATTR_SHADER=Se,b.ATTR_TRAVEL=O,b.DIRTY_CONTENT=ve,b.DIRTY_NONE=de,b.DIRTY_RECT=Q,b.DIRTY_STRUCTURE=ue,b.DIRTY_STYLE=ie,b.DIRTY_ZINDEX=Re,b.EXCLUDED=Ve,b.Engine=st,b.SELECT_LAYER=te,b.THREE_LAYERS=B,b.TRAVEL_VALUES=he,b.Tracker=Me,b.USER_LAYER=H,b.extractFromStyle=Le,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
188
+ `,document.head.appendChild(a)}let r;if(t.mode==="duplicate"?r=(c=(i=t.container)!=null?i:this.target.parentElement)!=null?c:void 0:r=(s=this.target.parentElement)!=null?s:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new tt(this.target,t,r,this.registry),this.renderer.mount(),this.syncer=new st(this.target,this.renderer,this.registry,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}getTracker(){return this.syncer.tracker}updateUniforms(e,t){this.renderer.updateUniforms(e,t)}getCanvas(){return this.renderer.canvas}test(){const e=this.registry.get(document.querySelector("#box2"));if(!e)return;const t={ArrowRight:!1,ArrowLeft:!1,ArrowUp:!1,ArrowDown:!1};window.addEventListener("keydown",c=>{t[c.key]!==void 0&&(t[c.key]=!0)}),window.addEventListener("keyup",c=>{t[c.key]!==void 0&&(t[c.key]=!1)});const r=2,i=()=>{requestAnimationFrame(i),t.ArrowRight&&e.position.setX(e.position.x+r),t.ArrowLeft&&e.position.setX(e.position.x-r),t.ArrowUp&&e.position.setY(e.position.y+r),t.ArrowDown&&e.position.setY(e.position.y-r)};i()}}b.ALLOWED_FILTERS=ye,b.ATTR_DOM=K,b.ATTR_FILTER=_,b.ATTR_SANDWICH=ze,b.ATTR_SELECT=V,b.ATTR_SHADER=Re,b.ATTR_TRAVEL=B,b.DIRTY_CONTENT=we,b.DIRTY_NONE=pe,b.DIRTY_RECT=te,b.DIRTY_STRUCTURE=me,b.DIRTY_STYLE=oe,b.DIRTY_ZINDEX=Me,b.EXCLUDED=Pe,b.Engine=at,b.SELECT_LAYER=ne,b.THREE_LAYERS=N,b.TRAVEL_VALUES=ge,b.Tracker=De,b.USER_LAYER=G,b.extractFromStyle=Le,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirage-engine/core",
3
- "version": "0.3.14",
3
+ "version": "0.3.15",
4
4
  "main": "src/index.ts",
5
5
  "types": "src/index.ts",
6
6
  "peerDependencies": {
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@types/three": "^0.181.0",
16
- "@mirage-engine/painter": "1.0.4",
16
+ "@mirage-engine/painter": "1.0.5",
17
17
  "@mirage-engine/dom-tracker": "0.3.10"
18
18
  },
19
19
  "private": false,
@@ -586,6 +586,7 @@ export function extractSceneGraph(
586
586
  borderRadius: computed.borderRadius,
587
587
  borderColor: computed.borderColor,
588
588
  borderWidth: computed.borderWidth,
589
+ boxShadow: computed.boxShadow,
589
590
  imageSrc,
590
591
  isTraveler: isTraveler,
591
592
  };
@@ -655,6 +656,8 @@ export function extractSceneGraph(
655
656
  nativeParsedStyles.borderColor ?? baseStyles.borderColor,
656
657
  borderWidth:
657
658
  nativeParsedStyles.borderWidth ?? baseStyles.borderWidth,
659
+ boxShadow:
660
+ nativeParsedStyles.boxShadow ?? baseStyles.boxShadow,
658
661
  isTraveler: baseStyles.isTraveler,
659
662
  transform: nativeParsedStyles.transform,
660
663
  }
@@ -562,7 +562,8 @@ export class Renderer {
562
562
  const canvasHeight = this.renderer.domElement.height / pixelRatio;
563
563
 
564
564
  mesh.material = mesh.userData.baseMaterial as THREE.Material;
565
- mesh.scale.set(rect.width, rect.height, 1);
565
+ let pad = (mesh.material as THREE.ShaderMaterial).userData?.shadowPadding || 0;
566
+ mesh.scale.set(rect.width + pad * 2, rect.height + pad * 2, 1);
566
567
 
567
568
  mesh.userData.domRect = {
568
569
  x: rect.x,
@@ -735,7 +736,8 @@ export class Renderer {
735
736
  }
736
737
  }
737
738
 
738
- nativeMesh.scale.set(nScaleX, nScaleY, 1);
739
+ let nPad = (nativeMesh.material as THREE.ShaderMaterial).userData?.shadowPadding || 0;
740
+ nativeMesh.scale.set(nScaleX + nPad * 2, nScaleY + nPad * 2, 1);
739
741
  nativeMesh.position.set(
740
742
  nPosX,
741
743
  nPosY,
@@ -938,7 +940,8 @@ export class Renderer {
938
940
  // Apply new position and scale
939
941
  mesh.position.setX(baseX);
940
942
  mesh.position.setY(baseY);
941
- mesh.scale.set(rect.width, rect.height, 1);
943
+ let pad = (mesh.material as THREE.ShaderMaterial).userData?.shadowPadding || 0;
944
+ mesh.scale.set(rect.width + pad * 2, rect.height + pad * 2, 1);
942
945
  mesh.updateMatrixWorld();
943
946
 
944
947
  // Update uniforms so shader-based drawing (like border-radius) doesn't stretch
@@ -1014,9 +1017,10 @@ export class Renderer {
1014
1017
  }
1015
1018
  }
1016
1019
 
1020
+ let nPad = (nativeMesh.material as THREE.ShaderMaterial).userData?.shadowPadding || 0;
1017
1021
  nativeMesh.position.setX(nPosX);
1018
1022
  nativeMesh.position.setY(nPosY);
1019
- nativeMesh.scale.set(nScaleX, nScaleY, 1);
1023
+ nativeMesh.scale.set(nScaleX + nPad * 2, nScaleY + nPad * 2, 1);
1020
1024
  nativeMesh.updateMatrixWorld();
1021
1025
 
1022
1026
  // Update uniforms so native shader-based drawing doesn't stretch