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