mirage-engine 0.2.18 → 0.3.0

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