@mirage-engine/core 0.3.20 → 0.3.21
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/CHANGELOG.md +8 -0
- package/dist/mirage-engine.js +653 -649
- package/dist/mirage-engine.umd.js +16 -16
- package/package.json +2 -2
- package/src/dom/Extractor.ts +45 -37
- package/src/renderer/Renderer.ts +2 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
(function(b,
|
|
2
|
-
`),c=[];return i.forEach(s=>{const a=s.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(a.length===0){c.push("");return}let l=a[0];for(let n=1;n<a.length;n++){const u=a[n];this.ctx.measureText(l+u).width<=r+2?l+=u:(l&&c.push(l),l=u.trimStart())}l&&c.push(l)}),c}updateText(t,r,i,c,s){s!==void 0&&(this.qualityFactor=s);const l=(window.devicePixelRatio||1)*this.qualityFactor,n=i*l,u=c*l;this.canvas.width!==n||this.canvas.height!==u?(this.canvas.width=n,this.canvas.height=u):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(l,0,0,l,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),d=r.lineHeight,
|
|
1
|
+
(function(b,M){typeof exports=="object"&&typeof module!="undefined"?M(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],M):(b=typeof globalThis!="undefined"?globalThis:b||self,M(b.MirageEngine={},b.THREE))})(this,function(b,M){"use strict";var gt=Object.defineProperty,pt=Object.defineProperties;var mt=Object.getOwnPropertyDescriptors;var Pe=Object.getOwnPropertySymbols;var vt=Object.prototype.hasOwnProperty,wt=Object.prototype.propertyIsEnumerable;var De=(b,M,k)=>M in b?gt(b,M,{enumerable:!0,configurable:!0,writable:!0,value:k}):b[M]=k,ae=(b,M)=>{for(var k in M||(M={}))vt.call(M,k)&&De(b,k,M[k]);if(Pe)for(var k of Pe(M))wt.call(M,k)&&De(b,k,M[k]);return b},We=(b,M)=>pt(b,mt(M));var p=(b,M,k)=>(De(b,typeof M!="symbol"?M+"":M,k),k);var He=(b,M,k)=>new Promise((w,ge)=>{var Z=U=>{try{F(k.next(U))}catch(P){ge(P)}},pe=U=>{try{F(k.throw(U))}catch(P){ge(P)}},F=U=>U.done?w(U.value):Promise.resolve(U.value).then(Z,pe);F((k=k.apply(b,M)).next())});function k(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const w=k(M),ge={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},Z={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},pe={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"},F={NAME:"data-mirage-travel",KEY:"mirageTravel",VALUES:pe,MAX_LAYERS:Object.keys(pe).length-1},U={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:ge},P={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:ge},Ae={NAME:"data-mirage-shader",KEY:"mirageShader"},Ge={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},me=0,ee=1,le=2,Ie=4,ve=8,Se=16;function qe(o){const e=o.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);return e?{r:parseInt(e[1])/255,g:parseInt(e[2])/255,b:parseInt(e[3])/255,a:e[4]!==void 0?parseFloat(e[4]):1}:{r:1,g:1,b:1,a:1}}function ke(o){const e={};if(o.opacity&&(e.opacity=parseFloat(o.opacity)),o.backgroundColor){const t=qe(o.backgroundColor);e.backgroundColor=[t.r,t.g,t.b,t.a]}if(o.backgroundImage?e.backgroundImage=o.backgroundImage:o.background&&(e.backgroundImage=o.background),o.boxShadow&&(e.boxShadow=o.boxShadow),o.borderRadius&&(e.borderRadius=parseFloat(o.borderRadius)),o.width&&(e.width=parseFloat(o.width)),o.height&&(e.height=parseFloat(o.height)),o.transform&&o.transform!=="none"){const t=new DOMMatrix(o.transform);e.x=t.m41,e.y=t.m42,e.z=t.m43}return e}class Ue{constructor(e,t){p(this,"target");p(this,"observer");p(this,"pendingDeletions",new Set);p(this,"pendingStyles",new Map);p(this,"isDomDirty",!1);p(this,"isRunning",!1);p(this,"pendingMask",me);p(this,"mutationTimer",null);p(this,"cssTimer",null);p(this,"resizeConfig");p(this,"resizeTimer",null);p(this,"isResizing",!1);p(this,"lastScrollX",0);p(this,"lastScrollY",0);p(this,"scrollTimer",null);p(this,"onBeforeRender",new Set);p(this,"onLayoutChange",new Set);p(this,"onStyleChange",new Set);p(this,"onScrollChange",new Set);p(this,"onRender",new Set);p(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=ee|le,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});p(this,"onWindowResize",()=>{if(!this.resizeConfig.enabled){this.isDomDirty=!0;return}this.isResizing||(this.isResizing=!0,this.resizeConfig.onStart&&this.resizeConfig.onStart()),this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.resizeConfig.onEnd&&this.resizeConfig.onEnd(),this.isResizing=!1,this.resizeTimer=null},this.resizeConfig.delay)});p(this,"renderLoop",()=>{if(!this.isRunning)return;this.onBeforeRender.forEach(r=>r()),this.isDomDirty&&(this.isDomDirty=!1,this.onLayoutChange.forEach(r=>r(this.pendingMask,this.pendingDeletions)),this.pendingDeletions.clear(),this.pendingMask=me);const e=window.scrollX,t=window.scrollY;(e!==this.lastScrollX||t!==this.lastScrollY)&&(this.onScrollChange.forEach(r=>r(e,t)),this.lastScrollX=e,this.lastScrollY=t,this.scrollTimer&&clearTimeout(this.scrollTimer),this.scrollTimer=window.setTimeout(()=>{this.pendingMask|=ee,this.isDomDirty=!0,this.scrollTimer=null},150)),this.pendingStyles.size>0&&(this.onStyleChange.forEach(r=>r(this.pendingStyles)),this.pendingStyles.clear()),this.onRender.forEach(r=>r()),requestAnimationFrame(this.renderLoop)});var i,c;this.target=e;const r=(i=t.resizeDebounce)!=null?i:!0;r===!1?this.resizeConfig={enabled:!1,delay:0}:r===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(c=r.delay)!=null?c:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(s=>{let a=me;for(const l of s)if(l.type==="childList")a|=ve,l.removedNodes.length>0&&l.removedNodes.forEach(n=>{n instanceof HTMLElement&&this.pendingDeletions.add(n)});else if(l.type==="attributes")if(l.attributeName==="style"){a|=ee|le;const n=l.target,u=ke(n.style);this.pendingStyles.set(n,u)}else l.attributeName==="class"?a|=ee|le:l.attributeName&&l.attributeName.startsWith("data-")&&(a|=ee|le,l.attributeName.startsWith("data-mirage")&&(a|=ve));else l.type==="characterData"&&(a|=Se|ee);if(a!==me){if(this.pendingMask|=a,a&ve){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 q=1,ne=2,$e=0,X={BASE:0,SELECTED:1,getCaptureLayer:o=>31-o,HIDDEN:31},xe=Object.values(U.VALUES);class _e{static getBaseline(e){if(this.cache.has(e))return this.cache.get(e);const t=this.calculateBaselineFromDOM(e);return this.cache.set(e,t),t}static calculateBaselineFromDOM(e){if(typeof document=="undefined")return 0;const t=document.createElement("div"),r=document.createElement("span"),i=document.createElement("img");t.style.visibility="hidden",t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.font=e,t.style.margin="0",t.style.padding="0",t.style.border="none",r.style.margin="0",r.style.padding="0",r.style.border="none",r.style.lineHeight="normal",i.width=1,i.height=1,i.style.verticalAlign="baseline",r.appendChild(document.createTextNode("Hidden Text")),t.appendChild(r),t.appendChild(i),document.body.appendChild(t);const c=i.offsetTop-r.offsetTop;return document.body.removeChild(t),c}}p(_e,"cache",new Map);class je extends w.MeshBasicMaterial{constructor(t,r,i,c,s=2){super({transparent:!0,side:w.FrontSide,color:16777215});p(this,"canvas");p(this,"ctx");p(this,"qualityFactor");if(this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("[Mirage] Failed to create canvas context");this.qualityFactor=s,this.map=new w.CanvasTexture(this.canvas),this.map.colorSpace=w.LinearSRGBColorSpace,this.map.minFilter=w.LinearFilter,this.map.magFilter=w.LinearFilter,this.updateText(t,r,i,c)}wrapText(t,r){const i=t.split(`
|
|
2
|
+
`),c=[];return i.forEach(s=>{const a=s.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(a.length===0){c.push("");return}let l=a[0];for(let n=1;n<a.length;n++){const u=a[n];this.ctx.measureText(l+u).width<=r+2?l+=u:(l&&c.push(l),l=u.trimStart())}l&&c.push(l)}),c}updateText(t,r,i,c,s){s!==void 0&&(this.qualityFactor=s);const l=(window.devicePixelRatio||1)*this.qualityFactor,n=i*l,u=c*l;this.canvas.width!==n||this.canvas.height!==u?(this.canvas.width=n,this.canvas.height=u):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(l,0,0,l,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),d=r.lineHeight,m=_e.getBaseline(r.font);h.forEach((g,L)=>{const v=L*d+m;let S=0;r.textAlign==="center"?S=i/2:r.textAlign==="right"&&(S=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(g,S,v)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function ce(o,e=0){if(typeof o=="number")return o;const t=parseFloat(o)||0;return typeof o=="string"&&o.includes("%")?t/100*e:t}function he(o){if(!o||o==="transparent")return{color:new w.Color(16777215),alpha:0};const e=o.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),c=e[4]!==void 0?parseFloat(e[4]):1;return{color:new w.Color(`rgb(${t}, ${r}, ${i})`),alpha:c}}return{color:new w.Color(o),alpha:1}}function Oe(o){const e=[];let t="",r=0;for(let i=0;i<o.length;i++){const c=o[i];if(c==="(")r++;else if(c===")")r--;else if(c===","&&r===0){e.push(t.trim()),t="";continue}t+=c}return t&&e.push(t.trim()),e}function Ke(o){if(!o||typeof o!="string"||!o.includes("linear-gradient"))return null;const e=o.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=Oe(t);let i=Math.PI,c=0;const s=r[0].trim();if(s.startsWith("to "))s==="to top"?i=0:s==="to right"?i=Math.PI/2:s==="to bottom"?i=Math.PI:s==="to left"?i=Math.PI*1.5:s==="to top right"||s==="to right top"?i=Math.PI/4:s==="to bottom right"||s==="to right bottom"?i=Math.PI*.75:s==="to bottom left"||s==="to left bottom"?i=Math.PI*1.25:(s==="to top left"||s==="to left top")&&(i=Math.PI*1.75),c=1;else if(s.endsWith("deg")||s.endsWith("rad")||s.endsWith("turn")){const l=parseFloat(s);s.endsWith("deg")?i=l*(Math.PI/180):s.endsWith("rad")?i=l:s.endsWith("turn")&&(i=l*Math.PI*2),c=1}const a=[];for(let l=c;l<r.length&&!(a.length>=8);l++){const n=r[l].trim(),u=n.lastIndexOf(" ");let h=n,d=null;if(u!==-1&&!n.endsWith(")")){const g=n.substring(u+1);(g.endsWith("%")||g.endsWith("px")||!isNaN(parseFloat(g)))&&(h=n.substring(0,u).trim(),d=g)}const m=he(h);a.push({color:m.color,alpha:m.alpha,rawStop:d,stop:0})}if(a.length>0){for(let n=0;n<a.length;n++)a[n].rawStop!==null&&(a[n].stop=parseFloat(a[n].rawStop)/100);a[0].rawStop===null&&(a[0].stop=0),a.length>1&&a[a.length-1].rawStop===null&&(a[a.length-1].stop=1);let l=0;for(let n=1;n<a.length;n++)if(a[n].rawStop!==null||n===a.length-1){const u=n-l;if(u>1){const h=a[l].stop,m=(a[n].stop-h)/u;for(let g=1;g<u;g++)a[l+g].stop=h+m*g}l=n}}return{angle:i,stops:a}}function Je(o){if(!o||o==="none")return null;const e=Oe(o);if(e.length===0)return null;const t=e[0].trim(),r=/(rgba?\([^)]+\)|#[0-9a-fA-F]+|[a-zA-Z]+)/,i=t.match(r);let c="transparent",s=t;if(i&&i[1]!=="inset"){const m=i[1];(m.startsWith("rgb")||m.startsWith("#")||m==="black"||m==="white"||m==="transparent")&&(c=m,s=t.replace(m,"").trim())}s=s.replace("inset","").trim();const a=s.split(/\s+/).map(m=>parseFloat(m)||0),l=a[0]||0,n=a[1]||0,u=a[2]||0,h=a[3]||0,d=he(c);return{offsetX:l,offsetY:n,blurRadius:u,spreadRadius:h,color:d.color,alpha:d.alpha}}const Ze=`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
|
-
}`,
|
|
8
|
+
}`,Qe=`varying vec2 vUv;
|
|
9
9
|
uniform vec2 uSize;
|
|
10
10
|
uniform vec2 uMeshSize;
|
|
11
11
|
uniform vec4 uShadowColor;
|
|
@@ -164,26 +164,26 @@ void main() {
|
|
|
164
164
|
|
|
165
165
|
// #include <colorspace_fragment>
|
|
166
166
|
}
|
|
167
|
-
`,
|
|
167
|
+
`,et=`uniform sampler2D uTexture;
|
|
168
168
|
varying vec4 vScreenPos;
|
|
169
169
|
uniform vec2 uTextureRepeat;
|
|
170
|
-
uniform vec2 uTextureOffset;`,
|
|
170
|
+
uniform vec2 uTextureOffset;`,tt=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
|
|
171
171
|
vec2 resultUv = screenUv;
|
|
172
172
|
|
|
173
|
-
`,
|
|
174
|
-
baseColor = blendSrcOver(baseColor, texColor);`,
|
|
175
|
-
`,a[y]={value:
|
|
176
|
-
`,a[y]={value:new
|
|
177
|
-
`,a[y]={value:new
|
|
178
|
-
`,a[y]={value:new
|
|
179
|
-
`,a[y]=
|
|
180
|
-
`,a[y]={value:
|
|
173
|
+
`,rt=`vec4 texColor = texture2D(uTexture, resultUv);
|
|
174
|
+
baseColor = blendSrcOver(baseColor, texColor);`,Be={vertexShader:Ze,fragmentShader:Qe},Fe={declChunk:et,uvChunk:tt,baseColorChunk:rt};function it(o,e,t,r=null,i){var C;const c=r!==null||!!o.imageSrc;let s="";const a={};if(i!=null&&i.uniforms)for(const[y,E]of Object.entries(i.uniforms))typeof E=="number"?(s+=`uniform float ${y};
|
|
175
|
+
`,a[y]={value:E}):Array.isArray(E)?E.length===2?(s+=`uniform vec2 ${y};
|
|
176
|
+
`,a[y]={value:new w.Vector2(...E)}):E.length===3?(s+=`uniform vec3 ${y};
|
|
177
|
+
`,a[y]={value:new w.Vector3(...E)}):E.length===4&&(s+=`uniform vec4 ${y};
|
|
178
|
+
`,a[y]={value:new w.Vector4(...E)}):E&&typeof E=="object"&&E.type?(s+=`uniform ${E.type} ${y};
|
|
179
|
+
`,a[y]=E):(s+=`uniform float ${y};
|
|
180
|
+
`,a[y]={value:E});const l=i!==void 0,n=(c||l?Fe.declChunk:"")+`
|
|
181
181
|
`+s,u=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
|
|
182
182
|
`,h=o.isTraveler?`vec2 resultUv = screenUv;
|
|
183
183
|
`:`vec2 localUv = (p / uSize) + 0.5;
|
|
184
184
|
vec2 resultUv = localUv * uTextureRepeat + uTextureOffset;
|
|
185
|
-
`,d=c||l?u+h+((i==null?void 0:i.uvModifier)||""):"",p=c||l?Oe.baseColorChunk:"",f=(i==null?void 0:i.colorModifier)||"",A=_e.fragmentShader.replace("#INJECT_DECLARATIONS",n).replace("#INJECT_UV_MODIFIER",d).replace("#INJECT_BASE_COLOR",p).replace("#INJECT_COLOR_MODIFIER",f),m=ce(o.backgroundColor),S=ce(o.borderColor),T={uSize:{value:new v.Vector2(e,t)},uMeshSize:{value:new v.Vector2(e,t)},uShadowColor:{value:new v.Vector4(0,0,0,0)},uShadowOffset:{value:new v.Vector2(0,0)},uShadowBlur:{value:0},uShadowSpread:{value:0},uBgColor:{value:new v.Vector4(m.color.r,m.color.g,m.color.b,m.alpha)},uBorderColor:{value:new v.Vector4(S.color.r,S.color.g,S.color.b,S.alpha)},uBorderRadius:{value:new v.Vector4(0,0,0,0)},uBorderWidth:{value:le(o.borderWidth)},uOpacity:{value:(C=o.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)}};Be(T.uBorderRadius.value,o.borderRadius,Math.min(e,t)),c&&(T.uTexture.value=r);const k=new v.ShaderMaterial({uniforms:ne(ne({},T),a),vertexShader:_e.vertexShader,fragmentShader:A,transparent:!0,side:v.FrontSide});return o.backgroundImage&&xe(k,{backgroundImage:o.backgroundImage}),k}function tt(o,e,t,r,i){const c=le(e.borderWidth);xe(o,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:c,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage,boxShadow:e.boxShadow})}function xe(o,e){var r,i,c;if(e.boxShadow!==void 0){const s=$e(e.boxShadow);s?(o.uniforms.uShadowColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha),o.uniforms.uShadowOffset.value.set(s.offsetX,s.offsetY),o.uniforms.uShadowBlur.value=s.blurRadius,o.uniforms.uShadowSpread.value=s.spreadRadius,o.userData.shadowPadding=s.blurRadius+s.spreadRadius+Math.max(Math.abs(s.offsetX),Math.abs(s.offsetY))):(o.uniforms.uShadowColor.value.w=0,o.userData.shadowPadding=0)}if(e.width!==void 0&&e.height!==void 0&&o.uniforms.uSize.value.set(e.width,e.height),o.uniforms.uMeshSize){const s=o.userData.shadowPadding||0,a=e.width!==void 0?e.width:o.uniforms.uSize.value.x,l=e.height!==void 0?e.height:o.uniforms.uSize.value.y;o.uniforms.uMeshSize.value.set(a+s*2,l+s*2)}if(e.borderRadius!==void 0){const s=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(o.uniforms.uSize.value.x,o.uniforms.uSize.value.y);Be(o.uniforms.uBorderRadius.value,e.borderRadius,s)}if(e.borderWidth!==void 0&&(o.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const s=e.backgroundColor[3]!==void 0?e.backgroundColor[3]:o.uniforms.uBgColor.value.w;o.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],s)}else if(typeof e.backgroundColor=="string"){const s=ce(e.backgroundColor);o.uniforms.uBgColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=o.uniforms.uBgColor.value.w;o.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,s)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const s=o.uniforms.uBorderColor.value.w;o.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],s)}else if(typeof e.borderColor=="string"){const s=ce(e.borderColor);o.uniforms.uBorderColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=o.uniforms.uBorderColor.value.w;o.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,s)}e.opacity!==void 0&&(o.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(o.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(o.uniforms.uBorderColor.value.w=e.borderOpacity),o.uniforms.uTexture&&e.texture!==void 0&&(o.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=o.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const s=t.image.naturalWidth||t.image.videoWidth||t.image.width,a=t.image.naturalHeight||t.image.videoHeight||t.image.height,l=(i=e.width)!=null?i:o.uniforms.uSize.value.x,n=(c=e.height)!=null?c:o.uniforms.uSize.value.y;if(s&&a&&l&&n){const u=s/a,h=l/n;if(u>h){const d=h/u;o.uniforms.uTextureRepeat.value.set(d,1),o.uniforms.uTextureOffset.value.set((1-d)/2,0)}else{const d=u/h;o.uniforms.uTextureRepeat.value.set(1,d),o.uniforms.uTextureOffset.value.set(0,(1-d)/2)}}}else o.uniforms.uTextureRepeat&&(o.uniforms.uTextureRepeat.value.set(1,1),o.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const s=qe(e.backgroundImage);if(s){o.uniforms.uGradientCount.value=s.stops.length,o.uniforms.uGradientAngle.value=s.angle;for(let a=0;a<8;a++)if(a<s.stops.length){const l=s.stops[a];o.uniforms.uGradientColors.value[a].set(l.color.r,l.color.g,l.color.b,l.alpha),o.uniforms.uGradientStops.value[a]=l.stop}else o.uniforms.uGradientColors.value[a].set(0,0,0,0),o.uniforms.uGradientStops.value[a]=1}else o.uniforms.uGradientCount.value=0}for(const s of Object.keys(e))s!=="width"&&s!=="height"&&s!=="borderRadius"&&s!=="borderWidth"&&s!=="backgroundColor"&&s!=="borderColor"&&s!=="opacity"&&s!=="bgOpacity"&&s!=="borderOpacity"&&s!=="texture"&&s!=="backgroundImage"&&s!=="boxShadow"&&o.uniforms[s]!==void 0&&(o.uniforms[s].value!==void 0&&o.uniforms[s].value!==null&&typeof o.uniforms[s].value.set=="function"?Array.isArray(e[s])?o.uniforms[s].value.set(...e[s]):e[s]!==void 0&&(e[s].copy?o.uniforms[s].value.copy(e[s]):o.uniforms[s].value=e[s]):o.uniforms[s].value=e[s])}function Be(o,e,t=0){var l,n,u,h;if(e==null){o.set(0,0,0,0);return}if(typeof e=="number"){o.set(e,e,e,e);return}if(Array.isArray(e)){o.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=le(r[0],t),c=le((l=r[1])!=null?l:r[0],t),s=le((n=r[2])!=null?n:r[0],t),a=le((h=(u=r[3])!=null?u:r[1])!=null?h:r[0],t);o.set(i,c,s,a)}const G={create(o,e,t,r,i,c=2,s=null,a){return o==="BOX"?et(e,r,i,s,a):o==="TEXT"?new Ge(t||"",e,r,i,c):new v.MeshBasicMaterial({visible:!1})},update(o,e,t,r,i,c,s=2,a){e==="BOX"?tt(o,t,i,c,a):e==="TEXT"&&o.updateText(r||"",t,i,c,s)},forceUpdateUniforms(o,e){xe(o,e)}};class rt{constructor(e,t=!0){g(this,"observer");g(this,"textures",new WeakMap);g(this,"loadStatus",new WeakMap);g(this,"elementUrls",new WeakMap);g(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const c=i.target;i.isIntersecting?this.loadTexture(c):this.disposeTexture(c)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return Ve(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((c,s)=>{const a=new Image;a.onload=()=>c(a),a.onerror=s,a.src=t});else{const s=yield(yield fetch(t)).blob();r=yield createImageBitmap(s,{imageOrientation:"flipY"})}if(this.elementUrls.get(e)!==t){"close"in r&&r.close();return}const i=new v.Texture(r);r instanceof HTMLImageElement||(i.flipY=!1),i.colorSpace=v.LinearSRGBColorSpace,i.needsUpdate=!0,this.textures.set(e,i),this.onUpdate(e,i)}catch(r){console.warn("[MirageEngine] Failed to load texture:",t,r)}finally{this.elementUrls.has(e)&&this.loadStatus.set(e,!1)}}})}disposeTexture(e){const t=this.textures.get(e);t&&(t.dispose(),this.textures.delete(e),this.onUpdate(e,null)),this.loadStatus.set(e,!1)}get(e){return this.textures.get(e)}disposeAll(){this.observer&&this.observer.disconnect()}}class it{constructor(e,t,r,i){g(this,"canvas");g(this,"scene");g(this,"camera");g(this,"renderer");g(this,"renderTargets",[]);g(this,"renderOrder",0);g(this,"qualityFactor",2);g(this,"mode","overlay");g(this,"canvasSize","viewport");g(this,"clipArea",1);g(this,"targetLayer","base");g(this,"overscan",200);g(this,"target");g(this,"mountContainer");g(this,"registry");g(this,"targetRect");g(this,"travelersByLayer",Array.from({length:F.MAX_LAYERS},()=>new Set));g(this,"textureManager");g(this,"fixedMeshes",new Set);var a,l,n,u,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(a=t.mode)!=null?a:"overlay",this.canvasSize=(l=t.canvasSize)!=null?l:"viewport",this.clipArea=(n=t.travelerClipArea)!=null?n:1,this.targetLayer=(u=t.layer)!=null?u:"base",this.textureManager=new rt((d,p)=>{const f=this.registry.get(d);f&&f.material instanceof v.ShaderMaterial&&G.forceUpdateUniforms(f.material,{texture:p})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new v.Scene,this.targetRect=this.target.getBoundingClientRect();const c=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,s=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.camera=new v.OrthographicCamera(c/-2,c/2,s/2,s/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(this.getSceneLayer()),this.renderer=new v.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),v.ColorManagement.enabled=!1,this.renderer.outputColorSpace=v.LinearSRGBColorSpace,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(c,s),this.applyTextQuality((h=t.quality)!=null?h:"medium")}get isViewport(){return this.mode==="overlay"&&this.canvasSize==="viewport"}getSceneLayer(){return typeof this.targetLayer=="number"?this.targetLayer:this.targetLayer==="selected"?N.SELECTED:N.BASE}createRenderTarget(){for(let e=0;e<F.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&&G.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&G.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,c=this.isViewport?window.innerHeight+this.overscan*2:r.height,s=this.isViewport?this.canvas.clientWidth:this.targetRect.width,a=this.isViewport?this.canvas.clientHeight:this.targetRect.height,l=Math.abs(i-s)>.1||Math.abs(c-a)>.1,n=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);l?(this.targetRect=r,this.setSize(i,c),this.updateCanvasLayout()):n?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(u=>{const h=this.registry.get(u);if(h){this.scene.remove(h);for(const d of this.travelersByLayer)d.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(d=>d.dispose()):h.userData.nativeMesh.material.dispose(),h.userData.nativeMesh.geometry.dispose()),h.traverse(d=>{d instanceof v.Mesh&&(d.geometry&&d.geometry.dispose(),d.material&&(Array.isArray(d.material)?d.material.forEach(p=>p.dispose()):d.material.dispose()))}),this.registry.remove(u),this.textureManager.unregister(u)}})}reconcileNode(e){var i,c;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof v.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const s=new v.PlaneGeometry(1,1),a=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),l=G.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,a,e.shaderHooks);t=new v.Mesh(s,l),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=l,t.userData.domElement=e.element,t.userData.shaderHash=r}if(t.userData.clipElements=e.clipElements,(c=e.nativeStyles)!=null&&c.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let s=0;s<F.MAX_LAYERS;s++)s===e.captureLayer-2?this.travelersByLayer[s].add(t):this.travelersByLayer[s].delete(t);else for(const s of this.travelersByLayer)s.delete(t);if(e.isFixed?this.fixedMeshes.add(t):this.fixedMeshes.delete(t),e.styles.imageSrc?this.textureManager.register(e.element,e.styles.imageSrc):this.textureManager.unregister(e.element),e.type==="BOX")for(const s of e.children)this.reconcileNode(s);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var n;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],c=r?t.nativeStyles:t.textStyles,s=JSON.stringify(c)+t.textContent+i.map(u=>u.text).join("|"),a=(n=e.userData)==null?void 0:n.textChildStyleHash;if(t.dirtyMask&ye||s!==a){e.children.filter(f=>f.name.startsWith("TEXT_CHILD")).forEach(f=>{var m;const A=f;(m=A.material.map)==null||m.dispose(),A.geometry.dispose(),e.remove(A)});const h=t.rect,d=h.x+h.width/2,p=h.y+h.height/2;i.forEach((f,A)=>{const m=G.create("TEXT",c,f.text,f.rect.width,f.rect.height,this.qualityFactor),S=new v.PlaneGeometry(1,1),T=new v.Mesh(S,m);T.name=`TEXT_CHILD_${A}`;const k=t.rect.width===0?1:f.rect.width/t.rect.width,C=t.rect.height===0?1:f.rect.height/t.rect.height;T.scale.set(k,C,1);const y=f.rect.x+f.rect.width/2,x=f.rect.y+f.rect.height/2,W=y-d,q=-(x-p);T.position.set(t.rect.width===0?0:W/t.rect.width,t.rect.height===0?0:q/t.rect.height,.005),e.add(T)}),e.userData.textChildStyleHash=s}e.children.forEach(u=>{if(!u.name.startsWith("TEXT_CHILD"))return;const h=u;if(r&&t.nativeLayer!==void 0)h.layers.set(N.HIDDEN),t.visibility&H&&h.layers.enable(N.getCaptureLayer(t.nativeLayer));else{const d=t.visibility&H?N.BASE:N.HIDDEN;if(h.layers.set(d),t.visibility&oe&&h.layers.enable(N.SELECTED),t.visibility&H)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let p=t.captureLayer;p<=F.MAX_LAYERS+1;p++)p!==t.nativeLayer&&h.layers.enable(N.getCaptureLayer(p));else for(let p=t.captureLayer;p<=F.MAX_LAYERS+1;p++)h.layers.enable(N.getCaptureLayer(p))}})}updateMeshProperties(e,t){var C,y,x,W,q;const{rect:r,styles:i}=t,c=this.renderer.getPixelRatio(),s=this.renderer.domElement.width/c,a=this.renderer.domElement.height/c;e.material=e.userData.baseMaterial;let l=((C=e.material.userData)==null?void 0:C.shadowPadding)||0;e.scale.set(r.width+l*2,r.height+l*2,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const n=.001;this.renderOrder++;const u=this.targetRect.left+window.scrollX,h=this.targetRect.top+window.scrollY;let d,p;if(this.isViewport)d=r.x-window.innerWidth/2+r.width/2,p=-r.y+window.innerHeight/2-r.height/2;else{const X=r.x-u,U=r.y-h;d=X-s/2+r.width/2,p=-U+a/2-r.height/2}e.position.set(d,p,i.zIndex+this.renderOrder*n);const f=r.x,A=r.y;e.userData.basePosition={x:d,y:p},e.userData.originalBasePosition={x:d,y:p},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:f,y:A},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,S=window.getComputedStyle(m);let T=0,k=0;if(S.transform&&S.transform!=="none"){const X=new DOMMatrix(S.transform);T=X.m41,k=X.m42}if(e.userData.baseTransform={x:T,y:k},delete e.userData.originRatioX,delete e.userData.originRatioY,G.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(y=this.renderTargets[t.captureLayer-2])==null?void 0:y.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const Y=G.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(x=this.renderTargets[t.captureLayer-2])==null?void 0:x.texture:this.textureManager.get(t.element),t.shaderHooks),$=new v.Mesh(e.geometry,Y);t.type==="TEXT"&&($.name="BG_MESH"),this.scene.add($),e.userData.nativeMesh=$}const X=e.userData.nativeMesh;let U,Q;if(this.isViewport)U=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,Q=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const Y=t.nativeRect.x-u,$=t.nativeRect.y-h;U=Y-s/2+t.nativeRect.width/2,Q=-$+a/2-t.nativeRect.height/2}let re=t.nativeRect.width,ie=t.nativeRect.height,L=U,z=Q;if(t.nativeStyles.transform){const Y=t.nativeStyles.transform,$=Y.match(/scale\(([\d.]+%?)\)/);if($){let E=parseFloat($[1]);$[1].includes("%")&&(E/=100),re*=E,ie*=E}const he=Y.match(/scaleX\(([\d.]+%?)\)/);if(he){let E=parseFloat(he[1]);he[1].includes("%")&&(E/=100),re*=E}const de=Y.match(/scaleY\(([\d.]+%?)\)/);if(de){let E=parseFloat(de[1]);de[1].includes("%")&&(E/=100),ie*=E}const ue=Y.match(/translate\(([^,]+),\s*([^)]+)\)/);if(ue){const E=ue[1].trim(),R=ue[2].trim();let P=parseFloat(E);E.includes("%")&&(P=P/100*t.nativeRect.width);let I=parseFloat(R);R.includes("%")&&(I=I/100*t.nativeRect.height),L+=P,z-=I}const we=Y.match(/translateX\(([^)]+)\)/);if(we){const E=we[1].trim();let R=parseFloat(E);E.includes("%")&&(R=R/100*t.nativeRect.width),L+=R}const w=Y.match(/translateY\(([^)]+)\)/);if(w){const E=w[1].trim();let R=parseFloat(E);E.includes("%")&&(R=R/100*t.nativeRect.height),z-=R}}let ee=((W=X.material.userData)==null?void 0:W.shadowPadding)||0;X.scale.set(re+ee*2,ie+ee*2,1),X.position.set(L,z,t.nativeStyles.zIndex+this.renderOrder*n),G.update(X.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(q=this.renderTargets[t.captureLayer-2])==null?void 0:q.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&H?N.BASE:N.HIDDEN;if(e.layers.set(r),t.visibility&oe&&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&H){i.layers.enable(N.getCaptureLayer(t.nativeLayer));for(let c=t.captureLayer;c<=F.MAX_LAYERS+1;c++)c!==t.nativeLayer&&e.layers.enable(N.getCaptureLayer(c))}}else if(t.visibility&H)for(let i=t.captureLayer;i<=F.MAX_LAYERS+1;i++)e.layers.enable(N.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new v.Color,c=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const s=new v.Vector3,a=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,l=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,n=this.renderer.getPixelRatio();for(const u of e){s.setFromMatrixPosition(u.matrixWorld),s.project(this.camera);const h=(s.x+1)/2*a,d=(s.y+1)/2*l;let p=0,f=1;typeof this.clipArea=="number"?f=this.clipArea:this.clipArea.endsWith("%")?f=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(p=parseFloat(this.clipArea));const A=u.scale.x*f+.5,m=u.scale.y*f+.5,S=h-A/2,T=d-m/2,k=(S*this.qualityFactor-p)/n,C=(T*this.qualityFactor-p)/n,y=(A*this.qualityFactor+p*2)/n,x=(m*this.qualityFactor+p*2)/n;this.renderer.setScissor(k,C,y,x),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,c)}render(){for(let l=0;l<F.MAX_LAYERS;l++){const n=l+1;this.captureRenderTarget(this.travelersByLayer[l],N.getCaptureLayer(n),this.renderTargets[l])}const e=this.renderer.getContext(),t=this.renderer.getPixelRatio(),r=this.renderer.domElement.height/t,i=this.renderer.domElement,c=i.getBoundingClientRect().top,s=i.getBoundingClientRect().left,a=(l,n)=>{if(n&&n.width>0&&n.height>0){const u=Math.floor((n.x-s)*t),h=Math.floor((r-(n.y-c+n.height))*t),d=Math.ceil(n.width*t),p=Math.ceil(n.height*t);l.onBeforeRender=()=>{e.enable(e.SCISSOR_TEST),e.scissor(u,h,d,p)},l.onAfterRender=()=>{e.disable(e.SCISSOR_TEST)},l.__hasScissorHook=!0}else l.__hasScissorHook&&(l.onBeforeRender=()=>{},l.onAfterRender=()=>{},l.__hasScissorHook=!1)};this.scene.children.forEach(l=>{var h;const n=l,u=(h=n.userData)==null?void 0:h.scissorRect;a(n,u),n.children.forEach(d=>{d.name.startsWith("TEXT_CHILD")&&a(d,u)})}),this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,c=this.renderer.domElement.height/r;this.scene.children.forEach(s=>{var h,d;const a=s;if(!a.userData||!a.userData.domElement)return;const l=a.userData.domElement;if(!l.isConnected)return;let n;if(l.nodeType===Node.TEXT_NODE){const p=document.createRange();p.selectNode(l),n=p.getBoundingClientRect()}else n=l.getBoundingClientRect();const u=a.userData.domRect;if(!u||Math.abs(n.x-u.x)>.5||Math.abs(n.y-u.y)>.5||Math.abs(n.width-u.width)>.5||Math.abs(n.height-u.height)>.5){a.userData.domRect={x:n.x,y:n.y,width:n.width,height:n.height};const p=a.userData.clipElements;if(p&&p.length>0){let S=-1/0,T=-1/0,k=1/0,C=1/0;for(const y of p){const x=y.getBoundingClientRect();S=Math.max(S,x.left),T=Math.max(T,x.top),k=Math.min(k,x.right),C=Math.min(C,x.bottom)}a.userData.scissorRect={x:S,y:T,width:Math.max(0,k-S),height:Math.max(0,C-T)}}else a.userData.scissorRect=void 0;let f,A;if(this.isViewport)f=n.x-window.innerWidth/2+n.width/2,A=-n.y+window.innerHeight/2-n.height/2;else{const S=n.x-e,T=n.y-t;f=S-i/2+n.width/2,A=-T+c/2-n.height/2}a.position.setX(f),a.position.setY(A);let m=((h=a.material.userData)==null?void 0:h.shadowPadding)||0;if(a.scale.set(n.width+m*2,n.height+m*2,1),a.updateMatrixWorld(),a.material instanceof v.ShaderMaterial&&G.forceUpdateUniforms(a.material,{width:n.width,height:n.height}),a.userData.nativeMesh){const S=a.userData.nativeMesh;let T=n.width,k=n.height,C=f,y=A;if(a.userData.nativeTransform){const W=a.userData.nativeTransform,q=W.match(/scale\(([\d.]+%?)\)/);if(q){let L=parseFloat(q[1]);q[1].includes("%")&&(L/=100),T*=L,k*=L}const X=W.match(/scaleX\(([\d.]+%?)\)/);if(X){let L=parseFloat(X[1]);X[1].includes("%")&&(L/=100),T*=L}const U=W.match(/scaleY\(([\d.]+%?)\)/);if(U){let L=parseFloat(U[1]);U[1].includes("%")&&(L/=100),k*=L}const Q=W.match(/translate\(([^,]+),\s*([^)]+)\)/);if(Q){const L=Q[1].trim(),z=Q[2].trim();let ee=parseFloat(L);L.includes("%")&&(ee=ee/100*n.width);let Y=parseFloat(z);z.includes("%")&&(Y=Y/100*n.height),C+=ee,y-=Y}const re=W.match(/translateX\(([^)]+)\)/);if(re){const L=re[1].trim();let z=parseFloat(L);L.includes("%")&&(z=z/100*n.width),C+=z}const ie=W.match(/translateY\(([^)]+)\)/);if(ie){const L=ie[1].trim();let z=parseFloat(L);L.includes("%")&&(z=z/100*n.height),y-=z}}let x=((d=S.material.userData)==null?void 0:d.shadowPadding)||0;S.position.setX(C),S.position.setY(y),S.scale.set(T+x*2,k+x*2,1),S.updateMatrixWorld(),S.material instanceof v.ShaderMaterial&&G.forceUpdateUniforms(S.material,{width:T,height:k})}}})}}function st(o){const e=o.textContent||"",t=[];let r="",i=null,c=-1;const s=(n,u)=>{for(let h=0;h<n.length;h++){const d=n[h],p=document.createRange();p.setStart(o,u+h),p.setEnd(o,u+h+1);const f=p.getBoundingClientRect();if(f.width===0&&f.height===0){r+=d;continue}c===-1||Math.abs(f.top-c)>f.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=d,i={left:f.left,top:f.top,right:f.right,bottom:f.bottom},c=f.top):(r+=d,i&&(i.left=Math.min(i.left,f.left),i.top=Math.min(i.top,f.top),i.right=Math.max(i.right,f.right),i.bottom=Math.max(i.bottom,f.bottom)))}},a=e.match(/[^\s\-]+\-?|\-|\s+/g)||[];let l=0;for(const n of a){const u=document.createRange();u.setStart(o,l),u.setEnd(o,l+n.length);const h=u.getClientRects();if(h.length>1)s(n,l);else{const d=h.length===1?h[0]:u.getBoundingClientRect();if(d.width===0&&d.height===0){r+=n,l+=n.length;continue}c===-1||Math.abs(d.top-c)>d.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=n,i={left:d.left,top:d.top,right:d.right,bottom:d.bottom},c=d.top):(r+=n,i&&(i.left=Math.min(i.left,d.left),i.top=Math.min(i.top,d.top),i.right=Math.max(i.right,d.right),i.bottom=Math.max(i.bottom,d.bottom)))}l+=n.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(n=>n.text.trim().length>0&&n.rect.width>0&&n.rect.height>0)}function Fe(o){const e=parseFloat(o.fontSize);let t=parseFloat(o.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(o.letterSpacing);return isNaN(r)&&(r=0),{font:`${o.fontStyle} ${o.fontWeight} ${o.fontSize} ${o.fontFamily}`,fontSize:o.fontSize,color:o.color,textAlign:o.textAlign||"start",textBaseline:"alphabetic",direction:o.direction||"inherit",lineHeight:t,letterSpacing:r}}function Ne(o,e=te|ae|De|ye|ve,t,r=1,i=0,c=2,s,a,l){var ee,Y,$,he,de,ue,we;if(o.nodeType===Node.TEXT_NODE){const w=o;if(!w.textContent||!w.textContent.trim())return null;const E=w.textContent.replace(/\s+/g," ");if(E.length===0)return null;const R=st(w);if(R.length===0)return null;const P=w.parentElement,I=P?window.getComputedStyle(P):null;if(!I)return null;const Z=Math.min(...R.map(M=>M.rect.left)),j=Math.min(...R.map(M=>M.rect.top)),se=Math.max(...R.map(M=>M.rect.left+M.rect.width)),_=Math.max(...R.map(M=>M.rect.top+M.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:w,rect:{x:Z+window.scrollX,y:j+window.scrollY,width:se-Z,height:_-j},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:P&&P.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(I.opacity),zIndex:(isNaN(parseInt(I.zIndex))?0:parseInt(I.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:E,textLines:R.map(M=>({text:M.text.trim(),rect:{x:M.rect.left+window.scrollX,y:M.rect.top+window.scrollY,width:M.rect.width,height:M.rect.height}})),textStyles:Fe(I),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:I.position==="fixed",nativeLayer:s,nativeStyles:a?ne(ne({backgroundColor:"transparent",backgroundImage:"",opacity:P&&P.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(I.opacity),zIndex:(isNaN(parseInt(I.zIndex))?0:parseInt(I.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Fe(I)),a):void 0,nativeRect:a?{x:Z+window.scrollX,y:j+window.scrollY,width:se-Z,height:_-j}:void 0,clipElements:l,children:[]}}if(o.nodeType!==Node.ELEMENT_NODE)return null;const n=o,u=n.dataset[B.KEY];let h=t,d=t;if(u){const w=new Set(u.split(/\s+/));for(const E of w)if(!Ee.includes(E))throw new Error(`[MirageEngine] Invalid filter token: '${E}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(w.has(B.VALUES.END))return null;if(w.has(B.VALUES.INCLUDE_TREE)&&w.has(B.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(w.has(B.VALUES.INCLUDE_SELF)&&w.has(B.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");w.has(B.VALUES.INCLUDE_TREE)?h=h|H:w.has(B.VALUES.EXCLUDE_TREE)&&(h=h&~H),d=h,w.has(B.VALUES.INCLUDE_SELF)?d=d|H:w.has(B.VALUES.EXCLUDE_SELF)&&(d=d&~H)}const p=n.dataset[V.KEY];if(p){const w=new Set(p.split(/\s+/));for(const E of w)if(!Ee.includes(E))throw new Error(`[MirageEngine] Invalid select token: '${E}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(w.has(V.VALUES.END))return null;if(w.has(V.VALUES.INCLUDE_TREE)&&w.has(V.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(w.has(V.VALUES.INCLUDE_SELF)&&w.has(V.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");w.has(V.VALUES.INCLUDE_TREE)?h=h|oe:w.has(V.VALUES.EXCLUDE_TREE)&&(h=h&~oe),d=h,w.has(V.VALUES.INCLUDE_SELF)?d=d|oe:w.has(V.VALUES.EXCLUDE_SELF)&&(d=d&~oe)}const f=n.dataset[F.KEY];let A=!1,m=a?ne({},a):{},S=s;if(f){let w=1;const E=f.indexOf("{"),R=f.lastIndexOf("}");let P=f;if(E!==-1&&R!==-1&&R>E){P=f.substring(0,E).trim();const _=f.substring(E,R+1);try{m=new Function("return "+_)()}catch(M){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${_}`)}}const I=P.split(/\s+/);let Z=!1;const j=I.indexOf(F.VALUES.TRAVELER);if(j!==-1){A=!0,Z=!0;const _=I[j+1];if(_&&!isNaN(parseInt(_,10)))w=parseInt(_,10);else{const M=I.find(fe=>!isNaN(parseInt(fe,10)));M&&(w=parseInt(M,10))}}const se=I.indexOf(F.VALUES.NATIVE);if(se!==-1){const _=I[se+1];if(_&&!isNaN(parseInt(_,10)))S=parseInt(_,10);else if(!A){const M=I.find(fe=>!isNaN(parseInt(fe,10)));M&&(S=parseInt(M,10))}}if(Z){const _=w+1;if(_<r)throw new Error(`[MirageEngine] Traveler layer (${w}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(_,F.MAX_LAYERS+1)}}const T=n.dataset[Le.KEY];let k;T&&(k=JSON.parse(T));const C=n.getBoundingClientRect(),y=window.getComputedStyle(n);if(C.width===0||C.height===0||y.display==="none")return null;let x=n.getAttribute("data-mid");x||(x=Math.random().toString(36).substring(2,11),n.setAttribute("data-mid",x));const W=parseInt(y.zIndex),q=(isNaN(W)?0:W)+i;let X;if(n.tagName==="IMG")X=n.src;else if(n.tagName.toLowerCase()==="svg"){const w=n.cloneNode(!0),E=m==null?void 0:m.color,R=m==null?void 0:m.fill,P=m==null?void 0:m.stroke,I=m==null?void 0:m.opacity,Z=(M,fe)=>{const J=window.getComputedStyle(M),be=fe,ct=J.fill===J.color,ht=J.stroke===J.color,Te=R||(ct?E:void 0)||J.fill;Te&&Te!=="none"&&(be.style.fill=Te);const Ce=P||(ht?E:void 0)||J.stroke;Ce&&Ce!=="none"&&(be.style.stroke=Ce),J.strokeWidth&&J.strokeWidth!=="0px"&&(be.style.strokeWidth=J.strokeWidth);const Xe=E||J.color;Xe&&(be.style.color=Xe);const Re=I||J.opacity;Re&&Re!=="1"&&(be.style.opacity=Re);for(let Se=0;Se<M.children.length;Se++)Z(M.children[Se],fe.children[Se])};Z(n,w);const j=n.getBoundingClientRect(),se=window.devicePixelRatio*c;w.hasAttribute("viewBox")||w.setAttribute("viewBox",`0 0 ${j.width} ${j.height}`),w.setAttribute("width",(j.width*se).toString()),w.setAttribute("height",(j.height*se).toString());let _=new XMLSerializer().serializeToString(w);_.includes("xmlns=")||(_=_.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),X=`data:image/svg+xml;utf8,${encodeURIComponent(_)}`}else if(y.backgroundImage&&y.backgroundImage!=="none"){const w=y.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);w&&(X=w[1])}const U={backgroundColor:y.backgroundColor,backgroundImage:y.backgroundImage,opacity:n.dataset[K.KEY]===K.VALUES.HIDE?1:parseFloat(y.opacity),zIndex:q,borderRadius:y.borderRadius,borderColor:y.borderColor,borderWidth:y.borderWidth,boxShadow:y.boxShadow,imageSrc:X,isTraveler:A},Q=U;let re,ie;const L=[],z=y.overflow==="hidden"?[...l||[],n]:l;return n.tagName.toLowerCase()!=="svg"&&Array.from(n.childNodes).forEach(w=>{const E=w.nodeType===Node.TEXT_NODE?d:h,R=Ne(w,e,E,r,q,c,w.nodeType===Node.TEXT_NODE?S:void 0,w.nodeType===Node.TEXT_NODE&&Object.keys(m).length>0?m:void 0,z);R&&L.push(R)}),{id:x,type:"BOX",element:n,rect:{x:C.left+window.scrollX,y:C.top+window.scrollY,width:C.width,height:C.height},styles:Q,textContent:re,textStyles:ie,dirtyMask:e,visibility:d,isTraveler:A,captureLayer:r,nativeLayer:S,nativeStyles:S!==void 0?ze(ne({},U),{backgroundColor:(ee=m.backgroundColor)!=null?ee:U.backgroundColor,backgroundImage:(Y=m.backgroundImage)!=null?Y:U.backgroundImage,opacity:($=m.opacity)!=null?$:U.opacity,zIndex:m.zIndex!==void 0?m.zIndex+q:U.zIndex,borderRadius:(he=m.borderRadius)!=null?he:U.borderRadius,borderColor:(de=m.borderColor)!=null?de:U.borderColor,borderWidth:(ue=m.borderWidth)!=null?ue:U.borderWidth,boxShadow:(we=m.boxShadow)!=null?we:U.boxShadow,isTraveler:U.isTraveler,transform:m.transform}):void 0,nativeRect:S!==void 0?{x:m.x!==void 0?parseFloat(m.x):C.left+window.scrollX,y:m.y!==void 0?parseFloat(m.y):C.top+window.scrollY,width:m.width!==void 0?parseFloat(m.width):C.width,height:m.height!==void 0?parseFloat(m.height):C.height}:void 0,isFixed:y.position==="fixed",clipElements:l,children:L,shaderHooks:k}}function ot(o,e){e.size!==0&&e.forEach((t,r)=>{var c,s,a,l;const i=o.get(r);!i||!i.userData.basePosition||(G.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(s=t.borderRadius)!=null?s:(c=i.userData.baseStyles)==null?void 0:c.borderRadius}),i.userData.nativeMesh&&G.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(l=t.borderRadius)!=null?l:(a=i.userData.baseStyles)==null?void 0:a.borderRadius}))})}class nt{constructor(e,t,r,i){g(this,"target");g(this,"renderer");g(this,"registry");g(this,"isTravelEnabled",!1);g(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new Ie(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((c,s)=>{document.querySelector(`[${F.NAME}~='${F.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const l=Ne(this.target,c,H,1,0,this.renderer.qualityFactor);l&&this.renderer.syncScene(l,s)}),this.tracker.onStyleChange.add(c=>{ot(this.registry,c)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class at{constructor(){g(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 lt{constructor(e,t){g(this,"renderer");g(this,"syncer");g(this,"target");g(this,"registry");var i,c,s;if(this.target=e,this.registry=new at,!document.getElementById("mirage-engine-styles")){const a=document.createElement("style");a.id="mirage-engine-styles",a.textContent=`
|
|
186
|
-
[${
|
|
185
|
+
`,d=c||l?u+h+((i==null?void 0:i.uvModifier)||""):"",m=c||l?Fe.baseColorChunk:"",g=(i==null?void 0:i.colorModifier)||"",L=Be.fragmentShader.replace("#INJECT_DECLARATIONS",n).replace("#INJECT_UV_MODIFIER",d).replace("#INJECT_BASE_COLOR",m).replace("#INJECT_COLOR_MODIFIER",g),v=he(o.backgroundColor),S=he(o.borderColor),T={uSize:{value:new w.Vector2(e,t)},uMeshSize:{value:new w.Vector2(e,t)},uShadowColor:{value:new w.Vector4(0,0,0,0)},uShadowOffset:{value:new w.Vector2(0,0)},uShadowBlur:{value:0},uShadowSpread:{value:0},uBgColor:{value:new w.Vector4(v.color.r,v.color.g,v.color.b,v.alpha)},uBorderColor:{value:new w.Vector4(S.color.r,S.color.g,S.color.b,S.alpha)},uBorderRadius:{value:new w.Vector4(0,0,0,0)},uBorderWidth:{value:ce(o.borderWidth)},uOpacity:{value:(C=o.opacity)!=null?C:1},uTexture:{value:null},uTextureRepeat:{value:new w.Vector2(1,1)},uTextureOffset:{value:new w.Vector2(0,0)},uGradientCount:{value:0},uGradientAngle:{value:0},uGradientColors:{value:Array.from({length:8},()=>new w.Vector4(0,0,0,0))},uGradientStops:{value:new Float32Array(8)}};Ne(T.uBorderRadius.value,o.borderRadius,Math.min(e,t)),c&&(T.uTexture.value=r);const A=new w.ShaderMaterial({uniforms:ae(ae({},T),a),vertexShader:Be.vertexShader,fragmentShader:L,transparent:!0,side:w.FrontSide});return o.backgroundImage&&Te(A,{backgroundImage:o.backgroundImage}),A}function st(o,e,t,r,i){const c=ce(e.borderWidth);Te(o,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:c,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage,boxShadow:e.boxShadow})}function Te(o,e){var r,i,c;if(e.boxShadow!==void 0){const s=Je(e.boxShadow);s?(o.uniforms.uShadowColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha),o.uniforms.uShadowOffset.value.set(s.offsetX,s.offsetY),o.uniforms.uShadowBlur.value=s.blurRadius,o.uniforms.uShadowSpread.value=s.spreadRadius,o.userData.shadowPadding=s.blurRadius+s.spreadRadius+Math.max(Math.abs(s.offsetX),Math.abs(s.offsetY))):(o.uniforms.uShadowColor.value.w=0,o.userData.shadowPadding=0)}if(e.width!==void 0&&e.height!==void 0&&o.uniforms.uSize.value.set(e.width,e.height),o.uniforms.uMeshSize){const s=o.userData.shadowPadding||0,a=e.width!==void 0?e.width:o.uniforms.uSize.value.x,l=e.height!==void 0?e.height:o.uniforms.uSize.value.y;o.uniforms.uMeshSize.value.set(a+s*2,l+s*2)}if(e.borderRadius!==void 0){const s=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(o.uniforms.uSize.value.x,o.uniforms.uSize.value.y);Ne(o.uniforms.uBorderRadius.value,e.borderRadius,s)}if(e.borderWidth!==void 0&&(o.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const s=e.backgroundColor[3]!==void 0?e.backgroundColor[3]:o.uniforms.uBgColor.value.w;o.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],s)}else if(typeof e.backgroundColor=="string"){const s=he(e.backgroundColor);o.uniforms.uBgColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=o.uniforms.uBgColor.value.w;o.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,s)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const s=o.uniforms.uBorderColor.value.w;o.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],s)}else if(typeof e.borderColor=="string"){const s=he(e.borderColor);o.uniforms.uBorderColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=o.uniforms.uBorderColor.value.w;o.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,s)}e.opacity!==void 0&&(o.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(o.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(o.uniforms.uBorderColor.value.w=e.borderOpacity),o.uniforms.uTexture&&e.texture!==void 0&&(o.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=o.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const s=t.image.naturalWidth||t.image.videoWidth||t.image.width,a=t.image.naturalHeight||t.image.videoHeight||t.image.height,l=(i=e.width)!=null?i:o.uniforms.uSize.value.x,n=(c=e.height)!=null?c:o.uniforms.uSize.value.y;if(s&&a&&l&&n){const u=s/a,h=l/n;if(u>h){const d=h/u;o.uniforms.uTextureRepeat.value.set(d,1),o.uniforms.uTextureOffset.value.set((1-d)/2,0)}else{const d=u/h;o.uniforms.uTextureRepeat.value.set(1,d),o.uniforms.uTextureOffset.value.set(0,(1-d)/2)}}}else o.uniforms.uTextureRepeat&&(o.uniforms.uTextureRepeat.value.set(1,1),o.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const s=Ke(e.backgroundImage);if(s){o.uniforms.uGradientCount.value=s.stops.length,o.uniforms.uGradientAngle.value=s.angle;for(let a=0;a<8;a++)if(a<s.stops.length){const l=s.stops[a];o.uniforms.uGradientColors.value[a].set(l.color.r,l.color.g,l.color.b,l.alpha),o.uniforms.uGradientStops.value[a]=l.stop}else o.uniforms.uGradientColors.value[a].set(0,0,0,0),o.uniforms.uGradientStops.value[a]=1}else o.uniforms.uGradientCount.value=0}for(const s of Object.keys(e))s!=="width"&&s!=="height"&&s!=="borderRadius"&&s!=="borderWidth"&&s!=="backgroundColor"&&s!=="borderColor"&&s!=="opacity"&&s!=="bgOpacity"&&s!=="borderOpacity"&&s!=="texture"&&s!=="backgroundImage"&&s!=="boxShadow"&&o.uniforms[s]!==void 0&&(o.uniforms[s].value!==void 0&&o.uniforms[s].value!==null&&typeof o.uniforms[s].value.set=="function"?Array.isArray(e[s])?o.uniforms[s].value.set(...e[s]):e[s]!==void 0&&(e[s].copy?o.uniforms[s].value.copy(e[s]):o.uniforms[s].value=e[s]):o.uniforms[s].value=e[s])}function Ne(o,e,t=0){var l,n,u,h;if(e==null){o.set(0,0,0,0);return}if(typeof e=="number"){o.set(e,e,e,e);return}if(Array.isArray(e)){o.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=ce(r[0],t),c=ce((l=r[1])!=null?l:r[0],t),s=ce((n=r[2])!=null?n:r[0],t),a=ce((h=(u=r[3])!=null?u:r[1])!=null?h:r[0],t);o.set(i,c,s,a)}const $={create(o,e,t,r,i,c=2,s=null,a){return o==="BOX"?it(e,r,i,s,a):o==="TEXT"?new je(t||"",e,r,i,c):new w.MeshBasicMaterial({visible:!1})},update(o,e,t,r,i,c,s=2,a){e==="BOX"?st(o,t,i,c,a):e==="TEXT"&&o.updateText(r||"",t,i,c,s)},forceUpdateUniforms(o,e){Te(o,e)}};class ot{constructor(e,t=!0){p(this,"observer");p(this,"textures",new WeakMap);p(this,"loadStatus",new WeakMap);p(this,"elementUrls",new WeakMap);p(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const c=i.target;i.isIntersecting?this.loadTexture(c):this.disposeTexture(c)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return He(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((c,s)=>{const a=new Image;a.onload=()=>c(a),a.onerror=s,a.src=t});else{const s=yield(yield fetch(t)).blob();r=yield createImageBitmap(s,{imageOrientation:"flipY"})}if(this.elementUrls.get(e)!==t){"close"in r&&r.close();return}const i=new w.Texture(r);r instanceof HTMLImageElement||(i.flipY=!1),i.colorSpace=w.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 nt{constructor(e,t,r,i){p(this,"canvas");p(this,"scene");p(this,"camera");p(this,"renderer");p(this,"renderTargets",[]);p(this,"renderOrder",0);p(this,"qualityFactor",2);p(this,"mode","overlay");p(this,"canvasSize","viewport");p(this,"clipArea",1);p(this,"targetLayer","base");p(this,"overscan",200);p(this,"target");p(this,"mountContainer");p(this,"registry");p(this,"targetRect");p(this,"travelersByLayer",Array.from({length:F.MAX_LAYERS},()=>new Set));p(this,"textureManager");p(this,"fixedMeshes",new Set);var a,l,n,u,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(a=t.mode)!=null?a:"overlay",this.canvasSize=(l=t.canvasSize)!=null?l:"viewport",this.clipArea=(n=t.travelerClipArea)!=null?n:1,this.targetLayer=(u=t.layer)!=null?u:"base",this.textureManager=new ot((d,m)=>{const g=this.registry.get(d);g&&g.material instanceof w.ShaderMaterial&&$.forceUpdateUniforms(g.material,{texture:m})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new w.Scene,this.targetRect=this.target.getBoundingClientRect();const c=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,s=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.camera=new w.OrthographicCamera(c/-2,c/2,s/2,s/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(this.getSceneLayer()),this.renderer=new w.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),w.ColorManagement.enabled=!1,this.renderer.outputColorSpace=w.LinearSRGBColorSpace,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(c,s),this.applyTextQuality((h=t.quality)!=null?h:"medium")}get isViewport(){return this.mode==="overlay"&&this.canvasSize==="viewport"}getSceneLayer(){return typeof this.targetLayer=="number"?this.targetLayer:this.targetLayer==="selected"?X.SELECTED:X.BASE}createRenderTarget(){for(let e=0;e<F.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 w.WebGLRenderTarget(t*this.qualityFactor,r*this.qualityFactor,{minFilter:w.LinearFilter,magFilter:w.LinearFilter,format:w.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&&$.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&$.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,c=this.isViewport?window.innerHeight+this.overscan*2:r.height,s=this.isViewport?this.canvas.clientWidth:this.targetRect.width,a=this.isViewport?this.canvas.clientHeight:this.targetRect.height,l=Math.abs(i-s)>.1||Math.abs(c-a)>.1,n=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);l?(this.targetRect=r,this.setSize(i,c),this.updateCanvasLayout()):n?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(u=>{const h=this.registry.get(u);if(h){this.scene.remove(h);for(const d of this.travelersByLayer)d.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(d=>d.dispose()):h.userData.nativeMesh.material.dispose(),h.userData.nativeMesh.geometry.dispose()),h.traverse(d=>{d instanceof w.Mesh&&(d.geometry&&d.geometry.dispose(),d.material&&(Array.isArray(d.material)?d.material.forEach(m=>m.dispose()):d.material.dispose()))}),this.registry.remove(u),this.textureManager.unregister(u)}})}reconcileNode(e){var i,c;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof w.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const s=new w.PlaneGeometry(1,1),a=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),l=$.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,a,e.shaderHooks);t=new w.Mesh(s,l),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=l,t.userData.domElement=e.element,t.userData.shaderHash=r}if(t.userData.clipElements=e.clipElements,(c=e.nativeStyles)!=null&&c.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let s=0;s<F.MAX_LAYERS;s++)s===e.captureLayer-2?this.travelersByLayer[s].add(t):this.travelersByLayer[s].delete(t);else for(const s of this.travelersByLayer)s.delete(t);if(e.isFixed?this.fixedMeshes.add(t):this.fixedMeshes.delete(t),e.styles.imageSrc?this.textureManager.register(e.element,e.styles.imageSrc):this.textureManager.unregister(e.element),e.type==="BOX")for(const s of e.children)this.reconcileNode(s);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var n;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],c=r?t.nativeStyles:t.textStyles,s=JSON.stringify(c)+t.textContent+i.map(u=>u.text).join("|"),a=(n=e.userData)==null?void 0:n.textChildStyleHash;if(t.dirtyMask&Se||s!==a){e.children.filter(g=>g.name.startsWith("TEXT_CHILD")).forEach(g=>{var v;const L=g;(v=L.material.map)==null||v.dispose(),L.geometry.dispose(),e.remove(L)});const h=t.rect,d=h.x+h.width/2,m=h.y+h.height/2;i.forEach((g,L)=>{const v=$.create("TEXT",c,g.text,g.rect.width,g.rect.height,this.qualityFactor),S=new w.PlaneGeometry(1,1),T=new w.Mesh(S,v);T.name=`TEXT_CHILD_${L}`;const A=t.rect.width===0?1:g.rect.width/t.rect.width,C=t.rect.height===0?1:g.rect.height/t.rect.height;T.scale.set(A,C,1);const y=g.rect.x+g.rect.width/2,E=g.rect.y+g.rect.height/2,W=y-d,j=-(E-m);T.position.set(t.rect.width===0?0:W/t.rect.width,t.rect.height===0?0:j/t.rect.height,.005),e.add(T)}),e.userData.textChildStyleHash=s}e.children.forEach(u=>{if(!u.name.startsWith("TEXT_CHILD"))return;const h=u;if(r&&t.nativeLayer!==void 0)h.layers.set(X.HIDDEN),t.visibility&q&&h.layers.enable(X.getCaptureLayer(t.nativeLayer));else{const d=t.visibility&q?X.BASE:X.HIDDEN;if(h.layers.set(d),t.visibility&ne&&h.layers.enable(X.SELECTED),t.visibility&q)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let m=t.captureLayer;m<=F.MAX_LAYERS+1;m++)m!==t.nativeLayer&&h.layers.enable(X.getCaptureLayer(m));else for(let m=t.captureLayer;m<=F.MAX_LAYERS+1;m++)h.layers.enable(X.getCaptureLayer(m))}})}updateMeshProperties(e,t){var C,y,E,W,j;const{rect:r,styles:i}=t,c=this.renderer.getPixelRatio(),s=this.renderer.domElement.width/c,a=this.renderer.domElement.height/c;e.material=e.userData.baseMaterial;let l=((C=e.material.userData)==null?void 0:C.shadowPadding)||0;e.scale.set(r.width+l*2,r.height+l*2,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const n=.001;this.renderOrder++;const u=this.targetRect.left+window.scrollX,h=this.targetRect.top+window.scrollY;let d,m;if(this.isViewport)d=r.x-window.innerWidth/2+r.width/2,m=-r.y+window.innerHeight/2-r.height/2;else{const _=r.x-u,H=r.y-h;d=_-s/2+r.width/2,m=-H+a/2-r.height/2}e.position.set(d,m,i.zIndex+this.renderOrder*n);const g=r.x,L=r.y;e.userData.basePosition={x:d,y:m},e.userData.originalBasePosition={x:d,y:m},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:g,y:L},e.userData.isFixed=t.isFixed,e.userData.initialScroll={x:window.scrollX,y:window.scrollY};const v=t.element.nodeType===Node.TEXT_NODE?t.element.parentElement:t.element,S=window.getComputedStyle(v);let T=0,A=0;if(S.transform&&S.transform!=="none"){const _=new DOMMatrix(S.transform);T=_.m41,A=_.m42}if(e.userData.baseTransform={x:T,y:A},delete e.userData.originRatioX,delete e.userData.originRatioY,$.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(y=this.renderTargets[t.captureLayer-2])==null?void 0:y.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const z=$.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(E=this.renderTargets[t.captureLayer-2])==null?void 0:E.texture:t.nativeStyles.imageSrc&&t.nativeStyles.imageSrc!==t.styles.imageSrc?new w.TextureLoader().load(t.nativeStyles.imageSrc):this.textureManager.get(t.element),t.shaderHooks),K=new w.Mesh(e.geometry,z);t.type==="TEXT"&&(K.name="BG_MESH"),this.scene.add(K),e.userData.nativeMesh=K}const _=e.userData.nativeMesh;let H,N;if(this.isViewport)H=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,N=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const z=t.nativeRect.x-u,K=t.nativeRect.y-h;H=z-s/2+t.nativeRect.width/2,N=-K+a/2-t.nativeRect.height/2}let te=t.nativeRect.width,re=t.nativeRect.height,D=H,Y=N;if(t.nativeStyles.transform){const z=t.nativeStyles.transform,K=z.match(/scale\(([\d.]+%?)\)/);if(K){let f=parseFloat(K[1]);K[1].includes("%")&&(f/=100),te*=f,re*=f}const de=z.match(/scaleX\(([\d.]+%?)\)/);if(de){let f=parseFloat(de[1]);de[1].includes("%")&&(f/=100),te*=f}const ue=z.match(/scaleY\(([\d.]+%?)\)/);if(ue){let f=parseFloat(ue[1]);ue[1].includes("%")&&(f/=100),re*=f}const fe=z.match(/translate\(([^,]+),\s*([^)]+)\)/);if(fe){const f=fe[1].trim(),x=fe[2].trim();let O=parseFloat(f);f.includes("%")&&(O=O/100*t.nativeRect.width);let V=parseFloat(x);x.includes("%")&&(V=V/100*t.nativeRect.height),D+=O,Y-=V}const we=z.match(/translateX\(([^)]+)\)/);if(we){const f=we[1].trim();let x=parseFloat(f);f.includes("%")&&(x=x/100*t.nativeRect.width),D+=x}const be=z.match(/translateY\(([^)]+)\)/);if(be){const f=be[1].trim();let x=parseFloat(f);f.includes("%")&&(x=x/100*t.nativeRect.height),Y-=x}}let ie=((W=_.material.userData)==null?void 0:W.shadowPadding)||0;_.scale.set(te+ie*2,re+ie*2,1),_.position.set(D,Y,t.nativeStyles.zIndex+this.renderOrder*n),$.update(_.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(j=this.renderTargets[t.captureLayer-2])==null?void 0:j.texture:_.material.uniforms.uTexture.value||this.textureManager.get(t.element))}else e.userData.nativeMesh&&(this.scene.remove(e.userData.nativeMesh),e.userData.nativeMesh.material instanceof w.Material&&e.userData.nativeMesh.material.dispose(),delete e.userData.nativeMesh)}updateMeshLayers(e,t){const r=t.visibility&q?X.BASE:X.HIDDEN;if(e.layers.set(r),t.visibility&ne&&e.layers.enable(X.SELECTED),e.userData.nativeMesh&&t.nativeLayer!==void 0){const i=e.userData.nativeMesh;if(i.layers.set(X.HIDDEN),t.visibility&q){i.layers.enable(X.getCaptureLayer(t.nativeLayer));for(let c=t.captureLayer;c<=F.MAX_LAYERS+1;c++)c!==t.nativeLayer&&e.layers.enable(X.getCaptureLayer(c))}}else if(t.visibility&q)for(let i=t.captureLayer;i<=F.MAX_LAYERS+1;i++)e.layers.enable(X.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new w.Color,c=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const s=new w.Vector3,a=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,l=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,n=this.renderer.getPixelRatio();for(const u of e){s.setFromMatrixPosition(u.matrixWorld),s.project(this.camera);const h=(s.x+1)/2*a,d=(s.y+1)/2*l;let m=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(m=parseFloat(this.clipArea));const L=u.scale.x*g+.5,v=u.scale.y*g+.5,S=h-L/2,T=d-v/2,A=(S*this.qualityFactor-m)/n,C=(T*this.qualityFactor-m)/n,y=(L*this.qualityFactor+m*2)/n,E=(v*this.qualityFactor+m*2)/n;this.renderer.setScissor(A,C,y,E),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,c)}render(){for(let l=0;l<F.MAX_LAYERS;l++){const n=l+1;this.captureRenderTarget(this.travelersByLayer[l],X.getCaptureLayer(n),this.renderTargets[l])}const e=this.renderer.getContext(),t=this.renderer.getPixelRatio(),r=this.renderer.domElement.height/t,i=this.renderer.domElement,c=i.getBoundingClientRect().top,s=i.getBoundingClientRect().left,a=(l,n)=>{if(n&&n.width>0&&n.height>0){const u=Math.floor((n.x-s)*t),h=Math.floor((r-(n.y-c+n.height))*t),d=Math.ceil(n.width*t),m=Math.ceil(n.height*t);l.onBeforeRender=()=>{e.enable(e.SCISSOR_TEST),e.scissor(u,h,d,m)},l.onAfterRender=()=>{e.disable(e.SCISSOR_TEST)},l.__hasScissorHook=!0}else l.__hasScissorHook&&(l.onBeforeRender=()=>{},l.onAfterRender=()=>{},l.__hasScissorHook=!1)};this.scene.children.forEach(l=>{var h;const n=l,u=(h=n.userData)==null?void 0:h.scissorRect;a(n,u),n.children.forEach(d=>{d.name.startsWith("TEXT_CHILD")&&a(d,u)})}),this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,c=this.renderer.domElement.height/r;this.scene.children.forEach(s=>{var h,d;const a=s;if(!a.userData||!a.userData.domElement)return;const l=a.userData.domElement;if(!l.isConnected)return;let n;if(l.nodeType===Node.TEXT_NODE){const m=document.createRange();m.selectNode(l),n=m.getBoundingClientRect()}else n=l.getBoundingClientRect();const u=a.userData.domRect;if(!u||Math.abs(n.x-u.x)>.5||Math.abs(n.y-u.y)>.5||Math.abs(n.width-u.width)>.5||Math.abs(n.height-u.height)>.5){a.userData.domRect={x:n.x,y:n.y,width:n.width,height:n.height};const m=a.userData.clipElements;if(m&&m.length>0){let S=-1/0,T=-1/0,A=1/0,C=1/0;for(const y of m){const E=y.getBoundingClientRect();S=Math.max(S,E.left),T=Math.max(T,E.top),A=Math.min(A,E.right),C=Math.min(C,E.bottom)}a.userData.scissorRect={x:S,y:T,width:Math.max(0,A-S),height:Math.max(0,C-T)}}else a.userData.scissorRect=void 0;let g,L;if(this.isViewport)g=n.x-window.innerWidth/2+n.width/2,L=-n.y+window.innerHeight/2-n.height/2;else{const S=n.x-e,T=n.y-t;g=S-i/2+n.width/2,L=-T+c/2-n.height/2}a.position.setX(g),a.position.setY(L);let v=((h=a.material.userData)==null?void 0:h.shadowPadding)||0;if(a.scale.set(n.width+v*2,n.height+v*2,1),a.updateMatrixWorld(),a.material instanceof w.ShaderMaterial&&$.forceUpdateUniforms(a.material,{width:n.width,height:n.height}),a.userData.nativeMesh){const S=a.userData.nativeMesh;let T=n.width,A=n.height,C=g,y=L;if(a.userData.nativeTransform){const W=a.userData.nativeTransform,j=W.match(/scale\(([\d.]+%?)\)/);if(j){let D=parseFloat(j[1]);j[1].includes("%")&&(D/=100),T*=D,A*=D}const _=W.match(/scaleX\(([\d.]+%?)\)/);if(_){let D=parseFloat(_[1]);_[1].includes("%")&&(D/=100),T*=D}const H=W.match(/scaleY\(([\d.]+%?)\)/);if(H){let D=parseFloat(H[1]);H[1].includes("%")&&(D/=100),A*=D}const N=W.match(/translate\(([^,]+),\s*([^)]+)\)/);if(N){const D=N[1].trim(),Y=N[2].trim();let ie=parseFloat(D);D.includes("%")&&(ie=ie/100*n.width);let z=parseFloat(Y);Y.includes("%")&&(z=z/100*n.height),C+=ie,y-=z}const te=W.match(/translateX\(([^)]+)\)/);if(te){const D=te[1].trim();let Y=parseFloat(D);D.includes("%")&&(Y=Y/100*n.width),C+=Y}const re=W.match(/translateY\(([^)]+)\)/);if(re){const D=re[1].trim();let Y=parseFloat(D);D.includes("%")&&(Y=Y/100*n.height),y-=Y}}let E=((d=S.material.userData)==null?void 0:d.shadowPadding)||0;S.position.setX(C),S.position.setY(y),S.scale.set(T+E*2,A+E*2,1),S.updateMatrixWorld(),S.material instanceof w.ShaderMaterial&&$.forceUpdateUniforms(S.material,{width:T,height:A})}}})}}function at(o){const e=o.textContent||"",t=[];let r="",i=null,c=-1;const s=(n,u)=>{for(let h=0;h<n.length;h++){const d=n[h],m=document.createRange();m.setStart(o,u+h),m.setEnd(o,u+h+1);const g=m.getBoundingClientRect();if(g.width===0&&g.height===0){r+=d;continue}c===-1||Math.abs(g.top-c)>g.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=d,i={left:g.left,top:g.top,right:g.right,bottom:g.bottom},c=g.top):(r+=d,i&&(i.left=Math.min(i.left,g.left),i.top=Math.min(i.top,g.top),i.right=Math.max(i.right,g.right),i.bottom=Math.max(i.bottom,g.bottom)))}},a=e.match(/[^\s\-]+\-?|\-|\s+/g)||[];let l=0;for(const n of a){const u=document.createRange();u.setStart(o,l),u.setEnd(o,l+n.length);const h=u.getClientRects();if(h.length>1)s(n,l);else{const d=h.length===1?h[0]:u.getBoundingClientRect();if(d.width===0&&d.height===0){r+=n,l+=n.length;continue}c===-1||Math.abs(d.top-c)>d.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=n,i={left:d.left,top:d.top,right:d.right,bottom:d.bottom},c=d.top):(r+=n,i&&(i.left=Math.min(i.left,d.left),i.top=Math.min(i.top,d.top),i.right=Math.max(i.right,d.right),i.bottom=Math.max(i.bottom,d.bottom)))}l+=n.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(n=>n.text.trim().length>0&&n.rect.width>0&&n.rect.height>0)}function Xe(o){const e=parseFloat(o.fontSize);let t=parseFloat(o.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(o.letterSpacing);return isNaN(r)&&(r=0),{font:`${o.fontStyle} ${o.fontWeight} ${o.fontSize} ${o.fontFamily}`,fontSize:o.fontSize,color:o.color,textAlign:o.textAlign||"start",textBaseline:"alphabetic",direction:o.direction||"inherit",lineHeight:t,letterSpacing:r}}function Ye(o,e=ee|le|Ie|Se|ve,t,r=1,i=0,c=2,s,a,l){var z,K,de,ue,fe,we,be;if(o.nodeType===Node.TEXT_NODE){const f=o;if(!f.textContent||!f.textContent.trim())return null;const x=f.textContent.replace(/\s+/g," ");if(x.length===0)return null;const O=at(f);if(O.length===0)return null;const V=f.parentElement,B=V?window.getComputedStyle(V):null;if(!B)return null;const J=Math.min(...O.map(R=>R.rect.left)),G=Math.min(...O.map(R=>R.rect.top)),se=Math.max(...O.map(R=>R.rect.left+R.rect.width)),I=Math.max(...O.map(R=>R.rect.top+R.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:f,rect:{x:J+window.scrollX,y:G+window.scrollY,width:se-J,height:I-G},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:V&&V.dataset[Z.KEY]===Z.VALUES.HIDE?1:parseFloat(B.opacity),zIndex:(isNaN(parseInt(B.zIndex))?0:parseInt(B.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:x,textLines:O.map(R=>({text:R.text.trim(),rect:{x:R.rect.left+window.scrollX,y:R.rect.top+window.scrollY,width:R.rect.width,height:R.rect.height}})),textStyles:Xe(B),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:B.position==="fixed",nativeLayer:s,nativeStyles:a?ae(ae({backgroundColor:"transparent",backgroundImage:"",opacity:V&&V.dataset[Z.KEY]===Z.VALUES.HIDE?1:parseFloat(B.opacity),zIndex:(isNaN(parseInt(B.zIndex))?0:parseInt(B.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Xe(B)),a):void 0,nativeRect:a?{x:J+window.scrollX,y:G+window.scrollY,width:se-J,height:I-G}:void 0,clipElements:l,children:[]}}if(o.nodeType!==Node.ELEMENT_NODE)return null;const n=o,u=n.dataset[U.KEY];let h=t,d=t;if(u){const f=new Set(u.split(/\s+/));for(const x of f)if(!xe.includes(x))throw new Error(`[MirageEngine] Invalid filter token: '${x}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(f.has(U.VALUES.END))return null;if(f.has(U.VALUES.INCLUDE_TREE)&&f.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(f.has(U.VALUES.INCLUDE_SELF)&&f.has(U.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");f.has(U.VALUES.INCLUDE_TREE)?h=h|q:f.has(U.VALUES.EXCLUDE_TREE)&&(h=h&~q),d=h,f.has(U.VALUES.INCLUDE_SELF)?d=d|q:f.has(U.VALUES.EXCLUDE_SELF)&&(d=d&~q)}const m=n.dataset[P.KEY];if(m){const f=new Set(m.split(/\s+/));for(const x of f)if(!xe.includes(x))throw new Error(`[MirageEngine] Invalid select token: '${x}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(f.has(P.VALUES.END))return null;if(f.has(P.VALUES.INCLUDE_TREE)&&f.has(P.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(f.has(P.VALUES.INCLUDE_SELF)&&f.has(P.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");f.has(P.VALUES.INCLUDE_TREE)?h=h|ne:f.has(P.VALUES.EXCLUDE_TREE)&&(h=h&~ne),d=h,f.has(P.VALUES.INCLUDE_SELF)?d=d|ne:f.has(P.VALUES.EXCLUDE_SELF)&&(d=d&~ne)}const g=n.dataset[F.KEY];let L=!1,v=a?ae({},a):{},S=s;if(g){let f=1;const x=g.indexOf("{"),O=g.lastIndexOf("}");let V=g;if(x!==-1&&O!==-1&&O>x){V=g.substring(0,x).trim();const I=g.substring(x,O+1);try{v=new Function("return "+I)()}catch(R){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${I}`)}}const B=V.split(/\s+/);let J=!1;const G=B.indexOf(F.VALUES.TRAVELER);if(G!==-1){L=!0,J=!0;const I=B[G+1];if(I&&!isNaN(parseInt(I,10)))f=parseInt(I,10);else{const R=B.find(oe=>!isNaN(parseInt(oe,10)));R&&(f=parseInt(R,10))}}const se=B.indexOf(F.VALUES.NATIVE);if(se!==-1){const I=B[se+1];if(I&&!isNaN(parseInt(I,10)))S=parseInt(I,10);else if(!L){const R=B.find(oe=>!isNaN(parseInt(oe,10)));R&&(S=parseInt(R,10))}}if(J){const I=f+1;if(I<r)throw new Error(`[MirageEngine] Traveler layer (${f}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(I,F.MAX_LAYERS+1)}}const T=n.dataset[Ae.KEY];let A;T&&(A=JSON.parse(T));const C=n.getBoundingClientRect(),y=window.getComputedStyle(n);if(C.width===0||C.height===0||y.display==="none")return null;let E=n.getAttribute("data-mid");E||(E=Math.random().toString(36).substring(2,11),n.setAttribute("data-mid",E));const W=parseInt(y.zIndex),j=(isNaN(W)?0:W)+i;let _,H;if(n.tagName==="IMG")_=n.src;else if(n.tagName.toLowerCase()==="svg"){const f=v==null?void 0:v.color,x=v==null?void 0:v.fill,O=v==null?void 0:v.stroke,V=v==null?void 0:v.opacity,B=J=>{const G=n.cloneNode(!0),se=(Ce,ze)=>{const Q=window.getComputedStyle(Ce),ye=ze,ut=Q.fill===Q.color,ft=Q.stroke===Q.color,Re=(J?x||(ut?f:void 0):void 0)||Q.fill;Re&&Re!=="none"&&(ye.style.fill=Re);const Me=(J?O||(ft?f:void 0):void 0)||Q.stroke;Me&&Me!=="none"&&(ye.style.stroke=Me),Q.strokeWidth&&Q.strokeWidth!=="0px"&&(ye.style.strokeWidth=Q.strokeWidth);const Ve=(J?f:void 0)||Q.color;Ve&&(ye.style.color=Ve);const Le=(J?V:void 0)||Q.opacity;Le&&Le!=="1"&&(ye.style.opacity=Le);for(let Ee=0;Ee<Ce.children.length;Ee++)se(Ce.children[Ee],ze.children[Ee])};se(n,G);const I=n.getBoundingClientRect(),R=window.devicePixelRatio*c;G.hasAttribute("viewBox")||G.setAttribute("viewBox",`0 0 ${I.width} ${I.height}`),G.setAttribute("width",(I.width*R).toString()),G.setAttribute("height",(I.height*R).toString());let oe=new XMLSerializer().serializeToString(G);return oe.includes("xmlns=")||(oe=oe.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),`data:image/svg+xml;utf8,${encodeURIComponent(oe)}`};_=B(!1),S!==void 0&&(f||x||O||V)&&(H=B(!0))}else if(y.backgroundImage&&y.backgroundImage!=="none"){const f=y.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);f&&(_=f[1])}const N={backgroundColor:y.backgroundColor,backgroundImage:y.backgroundImage,opacity:n.dataset[Z.KEY]===Z.VALUES.HIDE?1:parseFloat(y.opacity),zIndex:j,borderRadius:y.borderRadius,borderColor:y.borderColor,borderWidth:y.borderWidth,boxShadow:y.boxShadow,imageSrc:_,isTraveler:L},te=N;let re,D;const Y=[],ie=y.overflow==="hidden"?[...l||[],n]:l;return n.tagName.toLowerCase()!=="svg"&&Array.from(n.childNodes).forEach(f=>{const x=f.nodeType===Node.TEXT_NODE?d:h,O=Ye(f,e,x,r,j,c,f.nodeType===Node.TEXT_NODE?S:void 0,f.nodeType===Node.TEXT_NODE&&Object.keys(v).length>0?v:void 0,ie);O&&Y.push(O)}),{id:E,type:"BOX",element:n,rect:{x:C.left+window.scrollX,y:C.top+window.scrollY,width:C.width,height:C.height},styles:te,textContent:re,textStyles:D,dirtyMask:e,visibility:d,isTraveler:L,captureLayer:r,nativeLayer:S,nativeStyles:S!==void 0?We(ae({},N),{backgroundColor:(z=v.backgroundColor)!=null?z:N.backgroundColor,backgroundImage:(K=v.backgroundImage)!=null?K:N.backgroundImage,opacity:(de=v.opacity)!=null?de:N.opacity,zIndex:v.zIndex!==void 0?v.zIndex+j:N.zIndex,borderRadius:(ue=v.borderRadius)!=null?ue:N.borderRadius,borderColor:(fe=v.borderColor)!=null?fe:N.borderColor,borderWidth:(we=v.borderWidth)!=null?we:N.borderWidth,boxShadow:(be=v.boxShadow)!=null?be:N.boxShadow,isTraveler:N.isTraveler,transform:v.transform,imageSrc:H!=null?H:_}):void 0,nativeRect:S!==void 0?{x:v.x!==void 0?parseFloat(v.x):C.left+window.scrollX,y:v.y!==void 0?parseFloat(v.y):C.top+window.scrollY,width:v.width!==void 0?parseFloat(v.width):C.width,height:v.height!==void 0?parseFloat(v.height):C.height}:void 0,isFixed:y.position==="fixed",clipElements:l,children:Y,shaderHooks:A}}function lt(o,e){e.size!==0&&e.forEach((t,r)=>{var c,s,a,l;const i=o.get(r);!i||!i.userData.basePosition||($.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(s=t.borderRadius)!=null?s:(c=i.userData.baseStyles)==null?void 0:c.borderRadius}),i.userData.nativeMesh&&$.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(l=t.borderRadius)!=null?l:(a=i.userData.baseStyles)==null?void 0:a.borderRadius}))})}class ct{constructor(e,t,r,i){p(this,"target");p(this,"renderer");p(this,"registry");p(this,"isTravelEnabled",!1);p(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new Ue(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((c,s)=>{document.querySelector(`[${F.NAME}~='${F.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const l=Ye(this.target,c,q,1,0,this.renderer.qualityFactor);l&&this.renderer.syncScene(l,s)}),this.tracker.onStyleChange.add(c=>{lt(this.registry,c)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class ht{constructor(){p(this,"store");this.store=new WeakMap}register(e,t){this.store.set(e,t)}get(e){return this.store.get(e)}has(e){return this.store.has(e)}remove(e){this.store.delete(e)}}class dt{constructor(e,t){p(this,"renderer");p(this,"syncer");p(this,"target");p(this,"registry");var i,c,s;if(this.target=e,this.registry=new ht,!document.getElementById("mirage-engine-styles")){const a=document.createElement("style");a.id="mirage-engine-styles",a.textContent=`
|
|
186
|
+
[${Z.NAME}="${Z.VALUES.HIDE}"] {
|
|
187
187
|
opacity: 0 !important;
|
|
188
188
|
}
|
|
189
|
-
`,document.head.appendChild(a)}let r;if(t.mode==="duplicate"?r=(c=(i=t.container)!=null?i:this.target.parentElement)!=null?c:void 0:r=(s=this.target.parentElement)!=null?s:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new
|
|
189
|
+
`,document.head.appendChild(a)}let r;if(t.mode==="duplicate"?r=(c=(i=t.container)!=null?i:this.target.parentElement)!=null?c:void 0:r=(s=this.target.parentElement)!=null?s:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new nt(this.target,t,r,this.registry),this.renderer.mount(),this.syncer=new ct(this.target,this.renderer,this.registry,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}getTracker(){return this.syncer.tracker}updateUniforms(e,t){this.renderer.updateUniforms(e,t)}getCanvas(){return this.renderer.canvas}test(){const e=this.registry.get(document.querySelector("#box2"));if(!e)return;const t={ArrowRight:!1,ArrowLeft:!1,ArrowUp:!1,ArrowDown:!1};window.addEventListener("keydown",c=>{t[c.key]!==void 0&&(t[c.key]=!0)}),window.addEventListener("keyup",c=>{t[c.key]!==void 0&&(t[c.key]=!1)});const r=2,i=()=>{requestAnimationFrame(i),t.ArrowRight&&e.position.setX(e.position.x+r),t.ArrowLeft&&e.position.setX(e.position.x-r),t.ArrowUp&&e.position.setY(e.position.y+r),t.ArrowDown&&e.position.setY(e.position.y-r)};i()}}b.ALLOWED_FILTERS=xe,b.ATTR_DOM=Z,b.ATTR_FILTER=U,b.ATTR_SANDWICH=Ge,b.ATTR_SELECT=P,b.ATTR_SHADER=Ae,b.ATTR_TRAVEL=F,b.DIRTY_CONTENT=Se,b.DIRTY_NONE=me,b.DIRTY_RECT=ee,b.DIRTY_STRUCTURE=ve,b.DIRTY_STYLE=le,b.DIRTY_ZINDEX=Ie,b.EXCLUDED=$e,b.Engine=dt,b.SELECT_LAYER=ne,b.THREE_LAYERS=X,b.TRAVEL_VALUES=pe,b.Tracker=Ue,b.USER_LAYER=q,b.extractFromStyle=ke,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirage-engine/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"types": "src/index.ts",
|
|
6
6
|
"peerDependencies": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@types/three": "^0.181.0",
|
|
16
|
-
"@mirage-engine/painter": "1.0.
|
|
16
|
+
"@mirage-engine/painter": "1.0.11",
|
|
17
17
|
"@mirage-engine/dom-tracker": "0.3.10"
|
|
18
18
|
},
|
|
19
19
|
"private": false,
|
package/src/dom/Extractor.ts
CHANGED
|
@@ -511,64 +511,71 @@ export function extractSceneGraph(
|
|
|
511
511
|
// console.log(`${element.id}: ${computed.background}`);
|
|
512
512
|
// console.log(computed.backgroundImage);
|
|
513
513
|
let imageSrc: string | undefined;
|
|
514
|
+
let nativeImageSrc: string | undefined;
|
|
514
515
|
if (element.tagName === "IMG") {
|
|
515
516
|
imageSrc = (element as HTMLImageElement).src;
|
|
516
517
|
} else if (element.tagName.toLowerCase() === "svg") {
|
|
517
|
-
const clone = element.cloneNode(true) as SVGSVGElement;
|
|
518
|
-
|
|
519
518
|
const overrideColor = nativeParsedStyles?.color;
|
|
520
519
|
const overrideFill = nativeParsedStyles?.fill;
|
|
521
520
|
const overrideStroke = nativeParsedStyles?.stroke;
|
|
522
521
|
const overrideOpacity = nativeParsedStyles?.opacity;
|
|
523
522
|
|
|
524
|
-
const
|
|
525
|
-
const
|
|
526
|
-
|
|
523
|
+
const getSvgImageSrc = (useOverrides: boolean) => {
|
|
524
|
+
const clone = element.cloneNode(true) as SVGSVGElement;
|
|
525
|
+
|
|
526
|
+
const inlineSVGStyles = (orig: Element, cloned: Element) => {
|
|
527
|
+
const computed = window.getComputedStyle(orig);
|
|
528
|
+
const clonedHtml = cloned as HTMLElement;
|
|
527
529
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
+
const isCurrentColorFill = computed.fill === computed.color;
|
|
531
|
+
const isCurrentColorStroke = computed.stroke === computed.color;
|
|
530
532
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
+
const fill = (useOverrides ? (overrideFill || (isCurrentColorFill ? overrideColor : undefined)) : undefined) || computed.fill;
|
|
534
|
+
if (fill && fill !== "none") clonedHtml.style.fill = fill;
|
|
533
535
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
+
const stroke = (useOverrides ? (overrideStroke || (isCurrentColorStroke ? overrideColor : undefined)) : undefined) || computed.stroke;
|
|
537
|
+
if (stroke && stroke !== "none") clonedHtml.style.stroke = stroke;
|
|
536
538
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
+
if (computed.strokeWidth && computed.strokeWidth !== "0px")
|
|
540
|
+
clonedHtml.style.strokeWidth = computed.strokeWidth;
|
|
539
541
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
+
const color = (useOverrides ? overrideColor : undefined) || computed.color;
|
|
543
|
+
if (color) clonedHtml.style.color = color;
|
|
542
544
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
+
const opacity = (useOverrides ? overrideOpacity : undefined) || computed.opacity;
|
|
546
|
+
if (opacity && opacity !== "1") clonedHtml.style.opacity = opacity;
|
|
545
547
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
548
|
+
for (let i = 0; i < orig.children.length; i++) {
|
|
549
|
+
inlineSVGStyles(orig.children[i], cloned.children[i]);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
550
552
|
|
|
551
|
-
|
|
553
|
+
inlineSVGStyles(element, clone);
|
|
552
554
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
+
const svgRect = element.getBoundingClientRect();
|
|
556
|
+
const scale = window.devicePixelRatio * qualityFactor;
|
|
555
557
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
558
|
+
if (!clone.hasAttribute("viewBox")) {
|
|
559
|
+
clone.setAttribute("viewBox", `0 0 ${svgRect.width} ${svgRect.height}`);
|
|
560
|
+
}
|
|
559
561
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
+
clone.setAttribute("width", (svgRect.width * scale).toString());
|
|
563
|
+
clone.setAttribute("height", (svgRect.height * scale).toString());
|
|
562
564
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
565
|
+
let svgString = new XMLSerializer().serializeToString(clone);
|
|
566
|
+
if (!svgString.includes("xmlns=")) {
|
|
567
|
+
svgString = svgString.replace(
|
|
568
|
+
"<svg",
|
|
569
|
+
'<svg xmlns="http://www.w3.org/2000/svg"',
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
return `data:image/svg+xml;utf8,${encodeURIComponent(svgString)}`;
|
|
573
|
+
};
|
|
570
574
|
|
|
571
|
-
imageSrc =
|
|
575
|
+
imageSrc = getSvgImageSrc(false);
|
|
576
|
+
if (nativeLayer !== undefined && (overrideColor || overrideFill || overrideStroke || overrideOpacity)) {
|
|
577
|
+
nativeImageSrc = getSvgImageSrc(true);
|
|
578
|
+
}
|
|
572
579
|
} else if (computed.backgroundImage && computed.backgroundImage !== "none") {
|
|
573
580
|
const match = computed.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
|
|
574
581
|
if (match) {
|
|
@@ -668,6 +675,7 @@ export function extractSceneGraph(
|
|
|
668
675
|
nativeParsedStyles.boxShadow ?? baseStyles.boxShadow,
|
|
669
676
|
isTraveler: baseStyles.isTraveler,
|
|
670
677
|
transform: nativeParsedStyles.transform,
|
|
678
|
+
imageSrc: nativeImageSrc ?? imageSrc,
|
|
671
679
|
}
|
|
672
680
|
: undefined,
|
|
673
681
|
nativeRect:
|
package/src/renderer/Renderer.ts
CHANGED
|
@@ -652,7 +652,7 @@ export class Renderer {
|
|
|
652
652
|
this.qualityFactor,
|
|
653
653
|
node.isTraveler
|
|
654
654
|
? this.renderTargets[node.captureLayer - 2]?.texture
|
|
655
|
-
: this.textureManager.get(node.element),
|
|
655
|
+
: ((node.nativeStyles as any).imageSrc && (node.nativeStyles as any).imageSrc !== (node.styles as any).imageSrc) ? new THREE.TextureLoader().load((node.nativeStyles as any).imageSrc) : this.textureManager.get(node.element),
|
|
656
656
|
node.shaderHooks,
|
|
657
657
|
);
|
|
658
658
|
const nativeMesh = new THREE.Mesh(mesh.geometry, nativeMaterial);
|
|
@@ -757,7 +757,7 @@ export class Renderer {
|
|
|
757
757
|
this.qualityFactor,
|
|
758
758
|
node.isTraveler
|
|
759
759
|
? this.renderTargets[node.captureLayer - 2]?.texture
|
|
760
|
-
: this.textureManager.get(node.element),
|
|
760
|
+
: ((nativeMesh.material as THREE.ShaderMaterial).uniforms.uTexture.value) || this.textureManager.get(node.element),
|
|
761
761
|
);
|
|
762
762
|
} else {
|
|
763
763
|
if (mesh.userData.nativeMesh) {
|