mirage-engine 0.3.19 → 0.3.20

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.
@@ -76,8 +76,8 @@ const Ie = {
76
76
  VALUES: {
77
77
  FRONT: "front"
78
78
  }
79
- }, ge = 0, re = 1, ue = 2, Ge = 4, pe = 8, be = 16;
80
- function $e(s) {
79
+ }, ge = 0, re = 1, ue = 2, $e = 4, pe = 8, be = 16;
80
+ function Ge(s) {
81
81
  const e = s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
82
82
  return e ? {
83
83
  r: parseInt(e[1]) / 255,
@@ -89,7 +89,7 @@ function $e(s) {
89
89
  function qe(s) {
90
90
  const e = {};
91
91
  if (s.opacity && (e.opacity = parseFloat(s.opacity)), s.backgroundColor) {
92
- const t = $e(s.backgroundColor);
92
+ const t = Ge(s.backgroundColor);
93
93
  e.backgroundColor = [t.r, t.g, t.b, t.a];
94
94
  }
95
95
  if (s.backgroundImage ? e.backgroundImage = s.backgroundImage : s.background && (e.backgroundImage = s.background), s.boxShadow && (e.boxShadow = s.boxShadow), s.borderRadius && (e.borderRadius = parseFloat(s.borderRadius)), s.width && (e.width = parseFloat(s.width)), s.height && (e.height = parseFloat(s.height)), s.transform && s.transform !== "none") {
@@ -193,7 +193,7 @@ class Be {
193
193
  this.mutationTimer && (clearTimeout(this.mutationTimer), this.mutationTimer = null), this.cssTimer && (clearTimeout(this.cssTimer), this.cssTimer = null), this.scrollTimer && (clearTimeout(this.scrollTimer), this.scrollTimer = null);
194
194
  }
195
195
  }
196
- const G = 1, ae = 2, O = {
196
+ const $ = 1, ae = 2, O = {
197
197
  BASE: 0,
198
198
  SELECTED: 1,
199
199
  getCaptureLayer: (s) => 31 - s,
@@ -259,8 +259,8 @@ class je extends w.MeshBasicMaterial {
259
259
  const h = this.wrapText(t, r), d = i.lineHeight, p = Ue.getBaseline(i.font);
260
260
  h.forEach((g, M) => {
261
261
  const m = M * d + p;
262
- let y = 0;
263
- i.textAlign === "center" ? y = r / 2 : i.textAlign === "right" && (y = r), this.ctx.textAlign = i.textAlign, this.ctx.fillText(g, y, m);
262
+ let b = 0;
263
+ i.textAlign === "center" ? b = r / 2 : i.textAlign === "right" && (b = r), this.ctx.textAlign = i.textAlign, this.ctx.fillText(g, b, m);
264
264
  }), this.map && (this.map.needsUpdate = !0);
265
265
  }
266
266
  dispose() {
@@ -553,19 +553,20 @@ function it(s, e, t, i = null, r) {
553
553
  let n = "";
554
554
  const a = {};
555
555
  if (r != null && r.uniforms)
556
- for (const [b, S] of Object.entries(r.uniforms))
557
- typeof S == "number" ? (n += `uniform float ${b};
558
- `, a[b] = { value: S }) : Array.isArray(S) ? S.length === 2 ? (n += `uniform vec2 ${b};
559
- `, a[b] = { value: new w.Vector2(...S) }) : S.length === 3 ? (n += `uniform vec3 ${b};
560
- `, a[b] = { value: new w.Vector3(...S) }) : S.length === 4 && (n += `uniform vec4 ${b};
561
- `, a[b] = { value: new w.Vector4(...S) }) : (n += `uniform float ${b};
562
- `, a[b] = { value: S });
556
+ for (const [y, S] of Object.entries(r.uniforms))
557
+ typeof S == "number" ? (n += `uniform float ${y};
558
+ `, a[y] = { value: S }) : Array.isArray(S) ? S.length === 2 ? (n += `uniform vec2 ${y};
559
+ `, a[y] = { value: new w.Vector2(...S) }) : S.length === 3 ? (n += `uniform vec3 ${y};
560
+ `, a[y] = { value: new w.Vector3(...S) }) : S.length === 4 && (n += `uniform vec4 ${y};
561
+ `, a[y] = { value: new w.Vector4(...S) }) : S && typeof S == "object" && S.type ? (n += `uniform ${S.type} ${y};
562
+ `, a[y] = S) : (n += `uniform float ${y};
563
+ `, a[y] = { value: S });
563
564
  const l = r !== void 0, o = (c || l ? Ae.declChunk : "") + `
564
565
  ` + n, f = `vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
565
566
  `, h = s.isTraveler ? `vec2 resultUv = screenUv;
566
567
  ` : `vec2 localUv = (p / uSize) + 0.5;
567
568
  vec2 resultUv = localUv * uTextureRepeat + uTextureOffset;
568
- `, d = c || l ? f + h + ((r == null ? void 0 : r.uvModifier) || "") : "", p = c || l ? Ae.baseColorChunk : "", g = (r == null ? void 0 : r.colorModifier) || "", M = De.fragmentShader.replace("#INJECT_DECLARATIONS", o).replace("#INJECT_UV_MODIFIER", d).replace("#INJECT_BASE_COLOR", p).replace("#INJECT_COLOR_MODIFIER", g), m = ce(s.backgroundColor), y = ce(s.borderColor), E = {
569
+ `, d = c || l ? f + h + ((r == null ? void 0 : r.uvModifier) || "") : "", p = c || l ? Ae.baseColorChunk : "", g = (r == null ? void 0 : r.colorModifier) || "", M = De.fragmentShader.replace("#INJECT_DECLARATIONS", o).replace("#INJECT_UV_MODIFIER", d).replace("#INJECT_BASE_COLOR", p).replace("#INJECT_COLOR_MODIFIER", g), m = ce(s.backgroundColor), b = ce(s.borderColor), E = {
569
570
  uSize: { value: new w.Vector2(e, t) },
570
571
  uMeshSize: { value: new w.Vector2(e, t) },
571
572
  uShadowColor: { value: new w.Vector4(0, 0, 0, 0) },
@@ -582,10 +583,10 @@ vec2 resultUv = localUv * uTextureRepeat + uTextureOffset;
582
583
  },
583
584
  uBorderColor: {
584
585
  value: new w.Vector4(
585
- y.color.r,
586
- y.color.g,
587
- y.color.b,
588
- y.alpha
586
+ b.color.r,
587
+ b.color.g,
588
+ b.color.b,
589
+ b.alpha
589
590
  )
590
591
  },
591
592
  uBorderRadius: { value: new w.Vector4(0, 0, 0, 0) },
@@ -1045,11 +1046,11 @@ class ot {
1045
1046
  g.rect.width,
1046
1047
  g.rect.height,
1047
1048
  this.qualityFactor
1048
- ), y = new w.PlaneGeometry(1, 1), E = new w.Mesh(y, m);
1049
+ ), b = new w.PlaneGeometry(1, 1), E = new w.Mesh(b, m);
1049
1050
  E.name = `TEXT_CHILD_${M}`;
1050
1051
  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;
1051
1052
  E.scale.set(A, C, 1);
1052
- const b = g.rect.x + g.rect.width / 2, S = g.rect.y + g.rect.height / 2, z = b - d, X = -(S - p);
1053
+ const y = g.rect.x + g.rect.width / 2, S = g.rect.y + g.rect.height / 2, z = y - d, X = -(S - p);
1053
1054
  E.position.set(
1054
1055
  t.rect.width === 0 ? 0 : z / t.rect.width,
1055
1056
  t.rect.height === 0 ? 0 : X / t.rect.height,
@@ -1062,10 +1063,10 @@ class ot {
1062
1063
  return;
1063
1064
  const h = f;
1064
1065
  if (i && t.nativeLayer !== void 0)
1065
- h.layers.set(O.HIDDEN), t.visibility & G && h.layers.enable(O.getCaptureLayer(t.nativeLayer));
1066
+ h.layers.set(O.HIDDEN), t.visibility & $ && h.layers.enable(O.getCaptureLayer(t.nativeLayer));
1066
1067
  else {
1067
- const d = t.visibility & G ? O.BASE : O.HIDDEN;
1068
- if (h.layers.set(d), t.visibility & ae && h.layers.enable(O.SELECTED), t.visibility & G)
1068
+ const d = t.visibility & $ ? O.BASE : O.HIDDEN;
1069
+ if (h.layers.set(d), t.visibility & ae && h.layers.enable(O.SELECTED), t.visibility & $)
1069
1070
  if (!i && t.nativeLayer !== void 0 && t.nativeStyles !== void 0)
1070
1071
  for (let p = t.captureLayer; p <= N.MAX_LAYERS + 1; p++)
1071
1072
  p !== t.nativeLayer && h.layers.enable(O.getCaptureLayer(p));
@@ -1076,7 +1077,7 @@ class ot {
1076
1077
  });
1077
1078
  }
1078
1079
  updateMeshProperties(e, t) {
1079
- var C, b, S, z, X;
1080
+ var C, y, S, z, X;
1080
1081
  const { rect: i, styles: r } = t, c = this.renderer.getPixelRatio(), n = this.renderer.domElement.width / c, a = this.renderer.domElement.height / c;
1081
1082
  e.material = e.userData.baseMaterial;
1082
1083
  let l = ((C = e.material.userData) == null ? void 0 : C.shadowPadding) || 0;
@@ -1103,10 +1104,10 @@ class ot {
1103
1104
  );
1104
1105
  const g = i.x, M = i.y;
1105
1106
  e.userData.basePosition = { x: d, y: p }, e.userData.originalBasePosition = { x: d, y: p }, e.userData.baseSize = { width: i.width, height: i.height }, e.userData.baseDOM = { x: g, y: M }, e.userData.isFixed = t.isFixed, e.userData.initialScroll = { x: window.scrollX, y: window.scrollY };
1106
- const m = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, y = window.getComputedStyle(m);
1107
+ const m = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, b = window.getComputedStyle(m);
1107
1108
  let E = 0, A = 0;
1108
- if (y.transform && y.transform !== "none") {
1109
- const B = new DOMMatrix(y.transform);
1109
+ if (b.transform && b.transform !== "none") {
1110
+ const B = new DOMMatrix(b.transform);
1110
1111
  E = B.m41, A = B.m42;
1111
1112
  }
1112
1113
  if (e.userData.baseTransform = { x: E, y: A }, delete e.userData.originRatioX, delete e.userData.originRatioY, W.update(
@@ -1117,7 +1118,7 @@ class ot {
1117
1118
  i.width,
1118
1119
  i.height,
1119
1120
  this.qualityFactor,
1120
- t.isTraveler ? (b = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : b.texture : this.textureManager.get(t.element)
1121
+ t.isTraveler ? (y = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : y.texture : this.textureManager.get(t.element)
1121
1122
  ), t.nativeStyles && t.nativeRect) {
1122
1123
  if (!e.userData.nativeMesh) {
1123
1124
  const U = W.create(
@@ -1197,15 +1198,15 @@ class ot {
1197
1198
  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);
1198
1199
  }
1199
1200
  updateMeshLayers(e, t) {
1200
- const i = t.visibility & G ? O.BASE : O.HIDDEN;
1201
+ const i = t.visibility & $ ? O.BASE : O.HIDDEN;
1201
1202
  if (e.layers.set(i), t.visibility & ae && e.layers.enable(O.SELECTED), e.userData.nativeMesh && t.nativeLayer !== void 0) {
1202
1203
  const r = e.userData.nativeMesh;
1203
- if (r.layers.set(O.HIDDEN), t.visibility & G) {
1204
+ if (r.layers.set(O.HIDDEN), t.visibility & $) {
1204
1205
  r.layers.enable(O.getCaptureLayer(t.nativeLayer));
1205
1206
  for (let c = t.captureLayer; c <= N.MAX_LAYERS + 1; c++)
1206
1207
  c !== t.nativeLayer && e.layers.enable(O.getCaptureLayer(c));
1207
1208
  }
1208
- } else if (t.visibility & G)
1209
+ } else if (t.visibility & $)
1209
1210
  for (let r = t.captureLayer; r <= N.MAX_LAYERS + 1; r++)
1210
1211
  e.layers.enable(O.getCaptureLayer(r));
1211
1212
  }
@@ -1220,8 +1221,8 @@ class ot {
1220
1221
  const h = (n.x + 1) / 2 * a, d = (n.y + 1) / 2 * l;
1221
1222
  let p = 0, g = 1;
1222
1223
  typeof this.clipArea == "number" ? g = this.clipArea : this.clipArea.endsWith("%") ? g = parseFloat(this.clipArea) / 100 : this.clipArea.endsWith("px") && (p = parseFloat(this.clipArea));
1223
- const M = f.scale.x * g + 0.5, m = f.scale.y * g + 0.5, y = h - M / 2, E = d - m / 2, A = (y * this.qualityFactor - p) / o, C = (E * this.qualityFactor - p) / o, b = (M * this.qualityFactor + p * 2) / o, S = (m * this.qualityFactor + p * 2) / o;
1224
- this.renderer.setScissor(A, C, b, S), this.renderer.render(this.scene, this.camera);
1224
+ const M = f.scale.x * g + 0.5, m = f.scale.y * g + 0.5, b = h - M / 2, E = d - m / 2, A = (b * this.qualityFactor - p) / o, C = (E * this.qualityFactor - p) / o, y = (M * this.qualityFactor + p * 2) / o, S = (m * this.qualityFactor + p * 2) / o;
1225
+ this.renderer.setScissor(A, C, y, S), this.renderer.render(this.scene, this.camera);
1225
1226
  }
1226
1227
  this.renderer.setScissorTest(!1), this.renderer.autoClear = !0, this.renderer.setRenderTarget(null), this.camera.layers.set(this.getSceneLayer()), this.renderer.setClearColor(r, c);
1227
1228
  }
@@ -1283,15 +1284,15 @@ class ot {
1283
1284
  };
1284
1285
  const p = a.userData.clipElements;
1285
1286
  if (p && p.length > 0) {
1286
- let y = -1 / 0, E = -1 / 0, A = 1 / 0, C = 1 / 0;
1287
- for (const b of p) {
1288
- const S = b.getBoundingClientRect();
1289
- y = Math.max(y, S.left), E = Math.max(E, S.top), A = Math.min(A, S.right), C = Math.min(C, S.bottom);
1287
+ let b = -1 / 0, E = -1 / 0, A = 1 / 0, C = 1 / 0;
1288
+ for (const y of p) {
1289
+ const S = y.getBoundingClientRect();
1290
+ b = Math.max(b, S.left), E = Math.max(E, S.top), A = Math.min(A, S.right), C = Math.min(C, S.bottom);
1290
1291
  }
1291
1292
  a.userData.scissorRect = {
1292
- x: y,
1293
+ x: b,
1293
1294
  y: E,
1294
- width: Math.max(0, A - y),
1295
+ width: Math.max(0, A - b),
1295
1296
  height: Math.max(0, C - E)
1296
1297
  };
1297
1298
  } else
@@ -1300,8 +1301,8 @@ class ot {
1300
1301
  if (this.isViewport)
1301
1302
  g = o.x - window.innerWidth / 2 + o.width / 2, M = -o.y + window.innerHeight / 2 - o.height / 2;
1302
1303
  else {
1303
- const y = o.x - e, E = o.y - t;
1304
- g = y - r / 2 + o.width / 2, M = -E + c / 2 - o.height / 2;
1304
+ const b = o.x - e, E = o.y - t;
1305
+ g = b - r / 2 + o.width / 2, M = -E + c / 2 - o.height / 2;
1305
1306
  }
1306
1307
  a.position.setX(g), a.position.setY(M);
1307
1308
  let m = ((h = a.material.userData) == null ? void 0 : h.shadowPadding) || 0;
@@ -1309,8 +1310,8 @@ class ot {
1309
1310
  width: o.width,
1310
1311
  height: o.height
1311
1312
  }), a.userData.nativeMesh) {
1312
- const y = a.userData.nativeMesh;
1313
- let E = o.width, A = o.height, C = g, b = M;
1313
+ const b = a.userData.nativeMesh;
1314
+ let E = o.width, A = o.height, C = g, y = M;
1314
1315
  if (a.userData.nativeTransform) {
1315
1316
  const z = a.userData.nativeTransform, X = z.match(/scale\(([\d.]+%?)\)/);
1316
1317
  if (X) {
@@ -1333,7 +1334,7 @@ class ot {
1333
1334
  let K = parseFloat(L);
1334
1335
  L.includes("%") && (K = K / 100 * o.width);
1335
1336
  let U = parseFloat(_);
1336
- _.includes("%") && (U = U / 100 * o.height), C += K, b -= U;
1337
+ _.includes("%") && (U = U / 100 * o.height), C += K, y -= U;
1337
1338
  }
1338
1339
  const J = z.match(/translateX\(([^)]+)\)/);
1339
1340
  if (J) {
@@ -1345,11 +1346,11 @@ class ot {
1345
1346
  if (Z) {
1346
1347
  const L = Z[1].trim();
1347
1348
  let _ = parseFloat(L);
1348
- L.includes("%") && (_ = _ / 100 * o.height), b -= _;
1349
+ L.includes("%") && (_ = _ / 100 * o.height), y -= _;
1349
1350
  }
1350
1351
  }
1351
- let S = ((d = y.material.userData) == null ? void 0 : d.shadowPadding) || 0;
1352
- y.position.setX(C), y.position.setY(b), y.scale.set(E + S * 2, A + S * 2, 1), y.updateMatrixWorld(), y.material instanceof w.ShaderMaterial && W.forceUpdateUniforms(y.material, {
1352
+ let S = ((d = b.material.userData) == null ? void 0 : d.shadowPadding) || 0;
1353
+ b.position.setX(C), b.position.setY(y), b.scale.set(E + S * 2, A + S * 2, 1), b.updateMatrixWorld(), b.material instanceof w.ShaderMaterial && W.forceUpdateUniforms(b.material, {
1353
1354
  width: E,
1354
1355
  height: A
1355
1356
  });
@@ -1450,7 +1451,7 @@ function ke(s) {
1450
1451
  letterSpacing: i
1451
1452
  };
1452
1453
  }
1453
- function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1454
+ function Fe(s, e = re | ue | $e | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1454
1455
  var K, U, V, ie, se, ne, he;
1455
1456
  if (s.nodeType === Node.TEXT_NODE) {
1456
1457
  const v = s;
@@ -1465,15 +1466,15 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1465
1466
  const F = v.parentElement, D = F ? window.getComputedStyle(F) : null;
1466
1467
  if (!D)
1467
1468
  return null;
1468
- const $ = Math.min(...T.map((R) => R.rect.left)), Y = Math.min(...T.map((R) => R.rect.top)), Q = Math.max(...T.map((R) => R.rect.left + R.rect.width)), I = Math.max(...T.map((R) => R.rect.top + R.rect.height));
1469
+ const G = Math.min(...T.map((R) => R.rect.left)), Y = Math.min(...T.map((R) => R.rect.top)), Q = Math.max(...T.map((R) => R.rect.left + R.rect.width)), I = Math.max(...T.map((R) => R.rect.top + R.rect.height));
1469
1470
  return {
1470
1471
  id: Math.random().toString(36).substring(2, 9),
1471
1472
  type: "TEXT",
1472
1473
  element: v,
1473
1474
  rect: {
1474
- x: $ + window.scrollX,
1475
+ x: G + window.scrollX,
1475
1476
  y: Y + window.scrollY,
1476
- width: Q - $,
1477
+ width: Q - G,
1477
1478
  height: I - Y
1478
1479
  },
1479
1480
  styles: {
@@ -1514,9 +1515,9 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1514
1515
  isTraveler: !1
1515
1516
  }, ke(D)), a) : void 0,
1516
1517
  nativeRect: a ? {
1517
- x: $ + window.scrollX,
1518
+ x: G + window.scrollX,
1518
1519
  y: Y + window.scrollY,
1519
- width: Q - $,
1520
+ width: Q - G,
1520
1521
  height: I - Y
1521
1522
  } : void 0,
1522
1523
  clipElements: l,
@@ -1544,7 +1545,7 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1544
1545
  throw new Error(
1545
1546
  "[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element."
1546
1547
  );
1547
- v.has(P.VALUES.INCLUDE_TREE) ? h = h | G : v.has(P.VALUES.EXCLUDE_TREE) && (h = h & ~G), d = h, v.has(P.VALUES.INCLUDE_SELF) ? d = d | G : v.has(P.VALUES.EXCLUDE_SELF) && (d = d & ~G);
1548
+ v.has(P.VALUES.INCLUDE_TREE) ? h = h | $ : v.has(P.VALUES.EXCLUDE_TREE) && (h = h & ~$), d = h, v.has(P.VALUES.INCLUDE_SELF) ? d = d | $ : v.has(P.VALUES.EXCLUDE_SELF) && (d = d & ~$);
1548
1549
  }
1549
1550
  const p = o.dataset[q.KEY];
1550
1551
  if (p) {
@@ -1567,7 +1568,7 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1567
1568
  v.has(q.VALUES.INCLUDE_TREE) ? h = h | ae : v.has(q.VALUES.EXCLUDE_TREE) && (h = h & ~ae), d = h, v.has(q.VALUES.INCLUDE_SELF) ? d = d | ae : v.has(q.VALUES.EXCLUDE_SELF) && (d = d & ~ae);
1568
1569
  }
1569
1570
  const g = o.dataset[N.KEY];
1570
- let M = !1, m = a ? te({}, a) : {}, y = n;
1571
+ let M = !1, m = a ? te({}, a) : {}, b = n;
1571
1572
  if (g) {
1572
1573
  let v = 1;
1573
1574
  const x = g.indexOf("{"), T = g.lastIndexOf("}");
@@ -1584,10 +1585,10 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1584
1585
  }
1585
1586
  }
1586
1587
  const D = F.split(/\s+/);
1587
- let $ = !1;
1588
+ let G = !1;
1588
1589
  const Y = D.indexOf(N.VALUES.TRAVELER);
1589
1590
  if (Y !== -1) {
1590
- M = !0, $ = !0;
1591
+ M = !0, G = !0;
1591
1592
  const I = D[Y + 1];
1592
1593
  if (I && !isNaN(parseInt(I, 10)))
1593
1594
  v = parseInt(I, 10);
@@ -1600,13 +1601,13 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1600
1601
  if (Q !== -1) {
1601
1602
  const I = D[Q + 1];
1602
1603
  if (I && !isNaN(parseInt(I, 10)))
1603
- y = parseInt(I, 10);
1604
+ b = parseInt(I, 10);
1604
1605
  else if (!M) {
1605
1606
  const R = D.find((oe) => !isNaN(parseInt(oe, 10)));
1606
- R && (y = parseInt(R, 10));
1607
+ R && (b = parseInt(R, 10));
1607
1608
  }
1608
1609
  }
1609
- if ($) {
1610
+ if (G) {
1610
1611
  const I = v + 1;
1611
1612
  if (I < i)
1612
1613
  throw new Error(
@@ -1618,17 +1619,17 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1618
1619
  const E = o.dataset[Pe.KEY];
1619
1620
  let A;
1620
1621
  E && (A = JSON.parse(E));
1621
- const C = o.getBoundingClientRect(), b = window.getComputedStyle(o);
1622
- if (C.width === 0 || C.height === 0 || b.display === "none")
1622
+ const C = o.getBoundingClientRect(), y = window.getComputedStyle(o);
1623
+ if (C.width === 0 || C.height === 0 || y.display === "none")
1623
1624
  return null;
1624
1625
  let S = o.getAttribute("data-mid");
1625
1626
  S || (S = Math.random().toString(36).substring(2, 11), o.setAttribute("data-mid", S));
1626
- const z = parseInt(b.zIndex), X = (isNaN(z) ? 0 : z) + r;
1627
+ const z = parseInt(y.zIndex), X = (isNaN(z) ? 0 : z) + r;
1627
1628
  let B;
1628
1629
  if (o.tagName === "IMG")
1629
1630
  B = o.src;
1630
1631
  else if (o.tagName.toLowerCase() === "svg") {
1631
- const v = o.cloneNode(!0), x = m == null ? void 0 : m.color, T = m == null ? void 0 : m.fill, F = m == null ? void 0 : m.stroke, D = m == null ? void 0 : m.opacity, $ = (R, oe) => {
1632
+ const v = o.cloneNode(!0), x = m == null ? void 0 : m.color, T = m == null ? void 0 : m.fill, F = m == null ? void 0 : m.stroke, D = m == null ? void 0 : m.opacity, G = (R, oe) => {
1632
1633
  const H = window.getComputedStyle(R), de = oe, ze = H.fill === H.color, Ne = H.stroke === H.color, me = T || (ze ? x : void 0) || H.fill;
1633
1634
  me && me !== "none" && (de.style.fill = me);
1634
1635
  const ve = F || (Ne ? x : void 0) || H.stroke;
@@ -1638,9 +1639,9 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1638
1639
  const we = D || H.opacity;
1639
1640
  we && we !== "1" && (de.style.opacity = we);
1640
1641
  for (let fe = 0; fe < R.children.length; fe++)
1641
- $(R.children[fe], oe.children[fe]);
1642
+ G(R.children[fe], oe.children[fe]);
1642
1643
  };
1643
- $(o, v);
1644
+ G(o, v);
1644
1645
  const Y = o.getBoundingClientRect(), Q = window.devicePixelRatio * c;
1645
1646
  v.hasAttribute("viewBox") || v.setAttribute("viewBox", `0 0 ${Y.width} ${Y.height}`), v.setAttribute("width", (Y.width * Q).toString()), v.setAttribute("height", (Y.height * Q).toString());
1646
1647
  let I = new XMLSerializer().serializeToString(v);
@@ -1648,24 +1649,24 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1648
1649
  "<svg",
1649
1650
  '<svg xmlns="http://www.w3.org/2000/svg"'
1650
1651
  )), B = `data:image/svg+xml;utf8,${encodeURIComponent(I)}`;
1651
- } else if (b.backgroundImage && b.backgroundImage !== "none") {
1652
- const v = b.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
1652
+ } else if (y.backgroundImage && y.backgroundImage !== "none") {
1653
+ const v = y.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
1653
1654
  v && (B = v[1]);
1654
1655
  }
1655
1656
  const k = {
1656
- backgroundColor: b.backgroundColor,
1657
- backgroundImage: b.backgroundImage,
1658
- opacity: o.dataset[ee.KEY] === ee.VALUES.HIDE ? 1 : parseFloat(b.opacity),
1657
+ backgroundColor: y.backgroundColor,
1658
+ backgroundImage: y.backgroundImage,
1659
+ opacity: o.dataset[ee.KEY] === ee.VALUES.HIDE ? 1 : parseFloat(y.opacity),
1659
1660
  zIndex: X,
1660
- borderRadius: b.borderRadius,
1661
- borderColor: b.borderColor,
1662
- borderWidth: b.borderWidth,
1663
- boxShadow: b.boxShadow,
1661
+ borderRadius: y.borderRadius,
1662
+ borderColor: y.borderColor,
1663
+ borderWidth: y.borderWidth,
1664
+ boxShadow: y.boxShadow,
1664
1665
  imageSrc: B,
1665
1666
  isTraveler: M
1666
1667
  }, j = k;
1667
1668
  let J, Z;
1668
- const L = [], _ = b.overflow === "hidden" ? [...l || [], o] : l;
1669
+ const L = [], _ = y.overflow === "hidden" ? [...l || [], o] : l;
1669
1670
  return o.tagName.toLowerCase() !== "svg" && Array.from(o.childNodes).forEach((v) => {
1670
1671
  const x = v.nodeType === Node.TEXT_NODE ? d : h, T = Fe(
1671
1672
  v,
@@ -1674,7 +1675,7 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1674
1675
  i,
1675
1676
  X,
1676
1677
  c,
1677
- v.nodeType === Node.TEXT_NODE ? y : void 0,
1678
+ v.nodeType === Node.TEXT_NODE ? b : void 0,
1678
1679
  v.nodeType === Node.TEXT_NODE && Object.keys(m).length > 0 ? m : void 0,
1679
1680
  _
1680
1681
  );
@@ -1696,8 +1697,8 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1696
1697
  visibility: d,
1697
1698
  isTraveler: M,
1698
1699
  captureLayer: i,
1699
- nativeLayer: y,
1700
- nativeStyles: y !== void 0 ? Ce(te({}, k), {
1700
+ nativeLayer: b,
1701
+ nativeStyles: b !== void 0 ? Ce(te({}, k), {
1701
1702
  backgroundColor: (K = m.backgroundColor) != null ? K : k.backgroundColor,
1702
1703
  backgroundImage: (U = m.backgroundImage) != null ? U : k.backgroundImage,
1703
1704
  opacity: (V = m.opacity) != null ? V : k.opacity,
@@ -1709,13 +1710,13 @@ function Fe(s, e = re | ue | Ge | be | pe, t, i = 1, r = 0, c = 2, n, a, l) {
1709
1710
  isTraveler: k.isTraveler,
1710
1711
  transform: m.transform
1711
1712
  }) : void 0,
1712
- nativeRect: y !== void 0 ? {
1713
+ nativeRect: b !== void 0 ? {
1713
1714
  x: m.x !== void 0 ? parseFloat(m.x) : C.left + window.scrollX,
1714
1715
  y: m.y !== void 0 ? parseFloat(m.y) : C.top + window.scrollY,
1715
1716
  width: m.width !== void 0 ? parseFloat(m.width) : C.width,
1716
1717
  height: m.height !== void 0 ? parseFloat(m.height) : C.height
1717
1718
  } : void 0,
1718
- isFixed: b.position === "fixed",
1719
+ isFixed: y.position === "fixed",
1719
1720
  clipElements: l,
1720
1721
  children: L,
1721
1722
  shaderHooks: A
@@ -1755,7 +1756,7 @@ class ct {
1755
1756
  const l = Fe(
1756
1757
  this.target,
1757
1758
  c,
1758
- G,
1759
+ $,
1759
1760
  1,
1760
1761
  0,
1761
1762
  this.renderer.qualityFactor
@@ -1,5 +1,5 @@
1
1
  (function(k,L){typeof exports=="object"&&typeof module!="undefined"?L(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],L):(k=typeof globalThis!="undefined"?globalThis:k||self,L(k.MirageEngine={},k.THREE))})(this,function(k,L){"use strict";var ut=Object.defineProperty,ft=Object.defineProperties;var gt=Object.getOwnPropertyDescriptors;var ze=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable;var Re=(k,L,U)=>L in k?ut(k,L,{enumerable:!0,configurable:!0,writable:!0,value:U}):k[L]=U,ne=(k,L)=>{for(var U in L||(L={}))pt.call(L,U)&&Re(k,U,L[U]);if(ze)for(var U of ze(L))mt.call(L,U)&&Re(k,U,L[U]);return k},Ne=(k,L)=>ft(k,gt(L));var u=(k,L,U)=>(Re(k,typeof L!="symbol"?L+"":L,U),U);var Xe=(k,L,U)=>new Promise((v,fe)=>{var J=_=>{try{F(U.next(_))}catch(P){fe(P)}},ve=_=>{try{F(U.throw(_))}catch(P){fe(P)}},F=_=>_.done?v(_.value):Promise.resolve(_.value).then(J,ve);F((U=U.apply(k,L)).next())});function U(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const v=U(L),fe={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},J={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},ve={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:ve,MAX_LAYERS:Object.keys(ve).length-1},_={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:fe},P={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:fe},Ve={NAME:"data-mirage-shader",KEY:"mirageShader"},Me={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},ye=0,se=1,ge=2,Ye=4,we=8,xe=16;function Pe(n){const e=n.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 He(n){const e={};if(n.opacity&&(e.opacity=parseFloat(n.opacity)),n.backgroundColor){const t=Pe(n.backgroundColor);e.backgroundColor=[t.r,t.g,t.b,t.a]}if(n.backgroundImage?e.backgroundImage=n.backgroundImage:n.background&&(e.backgroundImage=n.background),n.boxShadow&&(e.boxShadow=n.boxShadow),n.borderRadius&&(e.borderRadius=parseFloat(n.borderRadius)),n.width&&(e.width=parseFloat(n.width)),n.height&&(e.height=parseFloat(n.height)),n.transform&&n.transform!=="none"){const t=new DOMMatrix(n.transform);e.x=t.m41,e.y=t.m42,e.z=t.m43}return e}class Le{constructor(e,t){u(this,"target");u(this,"observer");u(this,"pendingDeletions",new Set);u(this,"pendingStyles",new Map);u(this,"isDomDirty",!1);u(this,"isRunning",!1);u(this,"pendingMask",ye);u(this,"mutationTimer",null);u(this,"cssTimer",null);u(this,"resizeConfig");u(this,"resizeTimer",null);u(this,"isResizing",!1);u(this,"lastScrollX",0);u(this,"lastScrollY",0);u(this,"scrollTimer",null);u(this,"onBeforeRender",new Set);u(this,"onLayoutChange",new Set);u(this,"onStyleChange",new Set);u(this,"onScrollChange",new Set);u(this,"onRender",new Set);u(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=se|ge,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});u(this,"onWindowResize",()=>{if(!this.resizeConfig.enabled){this.isDomDirty=!0;return}this.isResizing||(this.isResizing=!0,this.resizeConfig.onStart&&this.resizeConfig.onStart()),this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.resizeConfig.onEnd&&this.resizeConfig.onEnd(),this.isResizing=!1,this.resizeTimer=null},this.resizeConfig.delay)});u(this,"renderLoop",()=>{if(!this.isRunning)return;this.onBeforeRender.forEach(r=>r()),this.isDomDirty&&(this.isDomDirty=!1,this.onLayoutChange.forEach(r=>r(this.pendingMask,this.pendingDeletions)),this.pendingDeletions.clear(),this.pendingMask=ye);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|=se,this.isDomDirty=!0,this.scrollTimer=null},150)),this.pendingStyles.size>0&&(this.onStyleChange.forEach(r=>r(this.pendingStyles)),this.pendingStyles.clear()),this.onRender.forEach(r=>r()),requestAnimationFrame(this.renderLoop)});var i,l;this.target=e;const r=(i=t.resizeDebounce)!=null?i:!0;r===!1?this.resizeConfig={enabled:!1,delay:0}:r===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(l=r.delay)!=null?l:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(s=>{let a=ye;for(const c of s)if(c.type==="childList")a|=we,c.removedNodes.length>0&&c.removedNodes.forEach(o=>{o instanceof HTMLElement&&this.pendingDeletions.add(o)});else if(c.type==="attributes")if(c.attributeName==="style"){a|=se|ge;const o=c.target,f=He(o.style);this.pendingStyles.set(o,f)}else c.attributeName==="class"?a|=se|ge:c.attributeName&&c.attributeName.startsWith("data-")&&(a|=se|ge,c.attributeName.startsWith("data-mirage")&&(a|=we));else c.type==="characterData"&&(a|=xe|se);if(a!==ye){if(this.pendingMask|=a,a&we){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 j=1,oe=2,N={BASE:0,SELECTED:1,getCaptureLayer:n=>31-n,HIDDEN:31},De=Object.values(_.VALUES);class Ae{static getBaseline(e){if(this.cache.has(e))return this.cache.get(e);const t=this.calculateBaselineFromDOM(e);return this.cache.set(e,t),t}static calculateBaselineFromDOM(e){if(typeof document=="undefined")return 0;const t=document.createElement("div"),r=document.createElement("span"),i=document.createElement("img");t.style.visibility="hidden",t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.font=e,t.style.margin="0",t.style.padding="0",t.style.border="none",r.style.margin="0",r.style.padding="0",r.style.border="none",r.style.lineHeight="normal",i.width=1,i.height=1,i.style.verticalAlign="baseline",r.appendChild(document.createTextNode("Hidden Text")),t.appendChild(r),t.appendChild(i),document.body.appendChild(t);const l=i.offsetTop-r.offsetTop;return document.body.removeChild(t),l}}u(Ae,"cache",new Map);class We extends v.MeshBasicMaterial{constructor(t,r,i,l,s=2){super({transparent:!0,side:v.FrontSide,color:16777215});u(this,"canvas");u(this,"ctx");u(this,"qualityFactor");if(this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("[Mirage] Failed to create canvas context");this.qualityFactor=s,this.map=new v.CanvasTexture(this.canvas),this.map.colorSpace=v.LinearSRGBColorSpace,this.map.minFilter=v.LinearFilter,this.map.magFilter=v.LinearFilter,this.updateText(t,r,i,l)}wrapText(t,r){const i=t.split(`
2
- `),l=[];return i.forEach(s=>{const a=s.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(a.length===0){l.push("");return}let c=a[0];for(let o=1;o<a.length;o++){const f=a[o];this.ctx.measureText(c+f).width<=r+2?c+=f:(c&&l.push(c),c=f.trimStart())}c&&l.push(c)}),l}updateText(t,r,i,l,s){s!==void 0&&(this.qualityFactor=s);const c=(window.devicePixelRatio||1)*this.qualityFactor,o=i*c,f=l*c;this.canvas.width!==o||this.canvas.height!==f?(this.canvas.width=o,this.canvas.height=f):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(c,0,0,c,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),d=r.lineHeight,p=Ae.getBaseline(r.font);h.forEach((g,D)=>{const m=D*d+p;let w=0;r.textAlign==="center"?w=i/2:r.textAlign==="right"&&(w=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(g,w,m)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function ae(n,e=0){if(typeof n=="number")return n;const t=parseFloat(n)||0;return typeof n=="string"&&n.includes("%")?t/100*e:t}function ce(n){if(!n||n==="transparent")return{color:new v.Color(16777215),alpha:0};const e=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),l=e[4]!==void 0?parseFloat(e[4]):1;return{color:new v.Color(`rgb(${t}, ${r}, ${i})`),alpha:l}}return{color:new v.Color(n),alpha:1}}function ke(n){const e=[];let t="",r=0;for(let i=0;i<n.length;i++){const l=n[i];if(l==="(")r++;else if(l===")")r--;else if(l===","&&r===0){e.push(t.trim()),t="";continue}t+=l}return t&&e.push(t.trim()),e}function Ge(n){if(!n||typeof n!="string"||!n.includes("linear-gradient"))return null;const e=n.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=ke(t);let i=Math.PI,l=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),l=1;else if(s.endsWith("deg")||s.endsWith("rad")||s.endsWith("turn")){const c=parseFloat(s);s.endsWith("deg")?i=c*(Math.PI/180):s.endsWith("rad")?i=c:s.endsWith("turn")&&(i=c*Math.PI*2),l=1}const a=[];for(let c=l;c<r.length&&!(a.length>=8);c++){const o=r[c].trim(),f=o.lastIndexOf(" ");let h=o,d=null;if(f!==-1&&!o.endsWith(")")){const g=o.substring(f+1);(g.endsWith("%")||g.endsWith("px")||!isNaN(parseFloat(g)))&&(h=o.substring(0,f).trim(),d=g)}const p=ce(h);a.push({color:p.color,alpha:p.alpha,rawStop:d,stop:0})}if(a.length>0){for(let o=0;o<a.length;o++)a[o].rawStop!==null&&(a[o].stop=parseFloat(a[o].rawStop)/100);a[0].rawStop===null&&(a[0].stop=0),a.length>1&&a[a.length-1].rawStop===null&&(a[a.length-1].stop=1);let c=0;for(let o=1;o<a.length;o++)if(a[o].rawStop!==null||o===a.length-1){const f=o-c;if(f>1){const h=a[c].stop,p=(a[o].stop-h)/f;for(let g=1;g<f;g++)a[c+g].stop=h+p*g}c=o}}return{angle:i,stops:a}}function $e(n){if(!n||n==="none")return null;const e=ke(n);if(e.length===0)return null;const t=e[0].trim(),r=/(rgba?\([^)]+\)|#[0-9a-fA-F]+|[a-zA-Z]+)/,i=t.match(r);let l="transparent",s=t;if(i&&i[1]!=="inset"){const p=i[1];(p.startsWith("rgb")||p.startsWith("#")||p==="black"||p==="white"||p==="transparent")&&(l=p,s=t.replace(p,"").trim())}s=s.replace("inset","").trim();const a=s.split(/\s+/).map(p=>parseFloat(p)||0),c=a[0]||0,o=a[1]||0,f=a[2]||0,h=a[3]||0,d=ce(l);return{offsetX:c,offsetY:o,blurRadius:f,spreadRadius:h,color:d.color,alpha:d.alpha}}const qe=`varying vec2 vUv;
2
+ `),l=[];return i.forEach(s=>{const a=s.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(a.length===0){l.push("");return}let c=a[0];for(let o=1;o<a.length;o++){const f=a[o];this.ctx.measureText(c+f).width<=r+2?c+=f:(c&&l.push(c),c=f.trimStart())}c&&l.push(c)}),l}updateText(t,r,i,l,s){s!==void 0&&(this.qualityFactor=s);const c=(window.devicePixelRatio||1)*this.qualityFactor,o=i*c,f=l*c;this.canvas.width!==o||this.canvas.height!==f?(this.canvas.width=o,this.canvas.height=f):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(c,0,0,c,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),d=r.lineHeight,p=Ae.getBaseline(r.font);h.forEach((g,D)=>{const m=D*d+p;let b=0;r.textAlign==="center"?b=i/2:r.textAlign==="right"&&(b=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(g,b,m)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function ae(n,e=0){if(typeof n=="number")return n;const t=parseFloat(n)||0;return typeof n=="string"&&n.includes("%")?t/100*e:t}function ce(n){if(!n||n==="transparent")return{color:new v.Color(16777215),alpha:0};const e=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),l=e[4]!==void 0?parseFloat(e[4]):1;return{color:new v.Color(`rgb(${t}, ${r}, ${i})`),alpha:l}}return{color:new v.Color(n),alpha:1}}function ke(n){const e=[];let t="",r=0;for(let i=0;i<n.length;i++){const l=n[i];if(l==="(")r++;else if(l===")")r--;else if(l===","&&r===0){e.push(t.trim()),t="";continue}t+=l}return t&&e.push(t.trim()),e}function $e(n){if(!n||typeof n!="string"||!n.includes("linear-gradient"))return null;const e=n.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=ke(t);let i=Math.PI,l=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),l=1;else if(s.endsWith("deg")||s.endsWith("rad")||s.endsWith("turn")){const c=parseFloat(s);s.endsWith("deg")?i=c*(Math.PI/180):s.endsWith("rad")?i=c:s.endsWith("turn")&&(i=c*Math.PI*2),l=1}const a=[];for(let c=l;c<r.length&&!(a.length>=8);c++){const o=r[c].trim(),f=o.lastIndexOf(" ");let h=o,d=null;if(f!==-1&&!o.endsWith(")")){const g=o.substring(f+1);(g.endsWith("%")||g.endsWith("px")||!isNaN(parseFloat(g)))&&(h=o.substring(0,f).trim(),d=g)}const p=ce(h);a.push({color:p.color,alpha:p.alpha,rawStop:d,stop:0})}if(a.length>0){for(let o=0;o<a.length;o++)a[o].rawStop!==null&&(a[o].stop=parseFloat(a[o].rawStop)/100);a[0].rawStop===null&&(a[0].stop=0),a.length>1&&a[a.length-1].rawStop===null&&(a[a.length-1].stop=1);let c=0;for(let o=1;o<a.length;o++)if(a[o].rawStop!==null||o===a.length-1){const f=o-c;if(f>1){const h=a[c].stop,p=(a[o].stop-h)/f;for(let g=1;g<f;g++)a[c+g].stop=h+p*g}c=o}}return{angle:i,stops:a}}function Ge(n){if(!n||n==="none")return null;const e=ke(n);if(e.length===0)return null;const t=e[0].trim(),r=/(rgba?\([^)]+\)|#[0-9a-fA-F]+|[a-zA-Z]+)/,i=t.match(r);let l="transparent",s=t;if(i&&i[1]!=="inset"){const p=i[1];(p.startsWith("rgb")||p.startsWith("#")||p==="black"||p==="white"||p==="transparent")&&(l=p,s=t.replace(p,"").trim())}s=s.replace("inset","").trim();const a=s.split(/\s+/).map(p=>parseFloat(p)||0),c=a[0]||0,o=a[1]||0,f=a[2]||0,h=a[3]||0,d=ce(l);return{offsetX:c,offsetY:o,blurRadius:f,spreadRadius:h,color:d.color,alpha:d.alpha}}const qe=`varying vec2 vUv;
3
3
  varying vec4 vScreenPos;
4
4
  void main() {
5
5
  vUv = uv;
@@ -171,17 +171,18 @@ uniform vec2 uTextureOffset;`,Je=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w)
171
171
  vec2 resultUv = screenUv;
172
172
 
173
173
  `,Ze=`vec4 texColor = texture2D(uTexture, resultUv);
174
- baseColor = blendSrcOver(baseColor, texColor);`,Ie={vertexShader:qe,fragmentShader:je},Oe={declChunk:Ke,uvChunk:Je,baseColorChunk:Ze};function Qe(n,e,t,r=null,i){var C;const l=r!==null||!!n.imageSrc;let s="";const a={};if(i!=null&&i.uniforms)for(const[b,S]of Object.entries(i.uniforms))typeof S=="number"?(s+=`uniform float ${b};
175
- `,a[b]={value:S}):Array.isArray(S)?S.length===2?(s+=`uniform vec2 ${b};
176
- `,a[b]={value:new v.Vector2(...S)}):S.length===3?(s+=`uniform vec3 ${b};
177
- `,a[b]={value:new v.Vector3(...S)}):S.length===4&&(s+=`uniform vec4 ${b};
178
- `,a[b]={value:new v.Vector4(...S)}):(s+=`uniform float ${b};
179
- `,a[b]={value:S});const c=i!==void 0,o=(l||c?Oe.declChunk:"")+`
174
+ baseColor = blendSrcOver(baseColor, texColor);`,Ie={vertexShader:qe,fragmentShader:je},Oe={declChunk:Ke,uvChunk:Je,baseColorChunk:Ze};function Qe(n,e,t,r=null,i){var C;const l=r!==null||!!n.imageSrc;let s="";const a={};if(i!=null&&i.uniforms)for(const[w,S]of Object.entries(i.uniforms))typeof S=="number"?(s+=`uniform float ${w};
175
+ `,a[w]={value:S}):Array.isArray(S)?S.length===2?(s+=`uniform vec2 ${w};
176
+ `,a[w]={value:new v.Vector2(...S)}):S.length===3?(s+=`uniform vec3 ${w};
177
+ `,a[w]={value:new v.Vector3(...S)}):S.length===4&&(s+=`uniform vec4 ${w};
178
+ `,a[w]={value:new v.Vector4(...S)}):S&&typeof S=="object"&&S.type?(s+=`uniform ${S.type} ${w};
179
+ `,a[w]=S):(s+=`uniform float ${w};
180
+ `,a[w]={value:S});const c=i!==void 0,o=(l||c?Oe.declChunk:"")+`
180
181
  `+s,f=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
181
182
  `,h=n.isTraveler?`vec2 resultUv = screenUv;
182
183
  `:`vec2 localUv = (p / uSize) + 0.5;
183
184
  vec2 resultUv = localUv * uTextureRepeat + uTextureOffset;
184
- `,d=l||c?f+h+((i==null?void 0:i.uvModifier)||""):"",p=l||c?Oe.baseColorChunk:"",g=(i==null?void 0:i.colorModifier)||"",D=Ie.fragmentShader.replace("#INJECT_DECLARATIONS",o).replace("#INJECT_UV_MODIFIER",d).replace("#INJECT_BASE_COLOR",p).replace("#INJECT_COLOR_MODIFIER",g),m=ce(n.backgroundColor),w=ce(n.borderColor),E={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(w.color.r,w.color.g,w.color.b,w.alpha)},uBorderRadius:{value:new v.Vector4(0,0,0,0)},uBorderWidth:{value:ae(n.borderWidth)},uOpacity:{value:(C=n.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(E.uBorderRadius.value,n.borderRadius,Math.min(e,t)),l&&(E.uTexture.value=r);const I=new v.ShaderMaterial({uniforms:ne(ne({},E),a),vertexShader:Ie.vertexShader,fragmentShader:D,transparent:!0,side:v.FrontSide});return n.backgroundImage&&Se(I,{backgroundImage:n.backgroundImage}),I}function et(n,e,t,r,i){const l=ae(e.borderWidth);Se(n,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:l,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage,boxShadow:e.boxShadow})}function Se(n,e){var r,i,l;if(e.boxShadow!==void 0){const s=$e(e.boxShadow);s?(n.uniforms.uShadowColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha),n.uniforms.uShadowOffset.value.set(s.offsetX,s.offsetY),n.uniforms.uShadowBlur.value=s.blurRadius,n.uniforms.uShadowSpread.value=s.spreadRadius,n.userData.shadowPadding=s.blurRadius+s.spreadRadius+Math.max(Math.abs(s.offsetX),Math.abs(s.offsetY))):(n.uniforms.uShadowColor.value.w=0,n.userData.shadowPadding=0)}if(e.width!==void 0&&e.height!==void 0&&n.uniforms.uSize.value.set(e.width,e.height),n.uniforms.uMeshSize){const s=n.userData.shadowPadding||0,a=e.width!==void 0?e.width:n.uniforms.uSize.value.x,c=e.height!==void 0?e.height:n.uniforms.uSize.value.y;n.uniforms.uMeshSize.value.set(a+s*2,c+s*2)}if(e.borderRadius!==void 0){const s=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(n.uniforms.uSize.value.x,n.uniforms.uSize.value.y);Be(n.uniforms.uBorderRadius.value,e.borderRadius,s)}if(e.borderWidth!==void 0&&(n.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const s=e.backgroundColor[3]!==void 0?e.backgroundColor[3]:n.uniforms.uBgColor.value.w;n.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],s)}else if(typeof e.backgroundColor=="string"){const s=ce(e.backgroundColor);n.uniforms.uBgColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=n.uniforms.uBgColor.value.w;n.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,s)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const s=n.uniforms.uBorderColor.value.w;n.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],s)}else if(typeof e.borderColor=="string"){const s=ce(e.borderColor);n.uniforms.uBorderColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=n.uniforms.uBorderColor.value.w;n.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,s)}e.opacity!==void 0&&(n.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(n.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(n.uniforms.uBorderColor.value.w=e.borderOpacity),n.uniforms.uTexture&&e.texture!==void 0&&(n.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=n.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const s=t.image.naturalWidth||t.image.videoWidth||t.image.width,a=t.image.naturalHeight||t.image.videoHeight||t.image.height,c=(i=e.width)!=null?i:n.uniforms.uSize.value.x,o=(l=e.height)!=null?l:n.uniforms.uSize.value.y;if(s&&a&&c&&o){const f=s/a,h=c/o;if(f>h){const d=h/f;n.uniforms.uTextureRepeat.value.set(d,1),n.uniforms.uTextureOffset.value.set((1-d)/2,0)}else{const d=f/h;n.uniforms.uTextureRepeat.value.set(1,d),n.uniforms.uTextureOffset.value.set(0,(1-d)/2)}}}else n.uniforms.uTextureRepeat&&(n.uniforms.uTextureRepeat.value.set(1,1),n.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const s=Ge(e.backgroundImage);if(s){n.uniforms.uGradientCount.value=s.stops.length,n.uniforms.uGradientAngle.value=s.angle;for(let a=0;a<8;a++)if(a<s.stops.length){const c=s.stops[a];n.uniforms.uGradientColors.value[a].set(c.color.r,c.color.g,c.color.b,c.alpha),n.uniforms.uGradientStops.value[a]=c.stop}else n.uniforms.uGradientColors.value[a].set(0,0,0,0),n.uniforms.uGradientStops.value[a]=1}else n.uniforms.uGradientCount.value=0}for(const s of Object.keys(e))s!=="width"&&s!=="height"&&s!=="borderRadius"&&s!=="borderWidth"&&s!=="backgroundColor"&&s!=="borderColor"&&s!=="opacity"&&s!=="bgOpacity"&&s!=="borderOpacity"&&s!=="texture"&&s!=="backgroundImage"&&s!=="boxShadow"&&n.uniforms[s]!==void 0&&(n.uniforms[s].value!==void 0&&n.uniforms[s].value!==null&&typeof n.uniforms[s].value.set=="function"?Array.isArray(e[s])?n.uniforms[s].value.set(...e[s]):e[s]!==void 0&&(e[s].copy?n.uniforms[s].value.copy(e[s]):n.uniforms[s].value=e[s]):n.uniforms[s].value=e[s])}function Be(n,e,t=0){var c,o,f,h;if(e==null){n.set(0,0,0,0);return}if(typeof e=="number"){n.set(e,e,e,e);return}if(Array.isArray(e)){n.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=ae(r[0],t),l=ae((c=r[1])!=null?c:r[0],t),s=ae((o=r[2])!=null?o:r[0],t),a=ae((h=(f=r[3])!=null?f:r[1])!=null?h:r[0],t);n.set(i,l,s,a)}const W={create(n,e,t,r,i,l=2,s=null,a){return n==="BOX"?Qe(e,r,i,s,a):n==="TEXT"?new We(t||"",e,r,i,l):new v.MeshBasicMaterial({visible:!1})},update(n,e,t,r,i,l,s=2,a){e==="BOX"?et(n,t,i,l,a):e==="TEXT"&&n.updateText(r||"",t,i,l,s)},forceUpdateUniforms(n,e){Se(n,e)}};class tt{constructor(e,t=!0){u(this,"observer");u(this,"textures",new WeakMap);u(this,"loadStatus",new WeakMap);u(this,"elementUrls",new WeakMap);u(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const l=i.target;i.isIntersecting?this.loadTexture(l):this.disposeTexture(l)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return Xe(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((l,s)=>{const a=new Image;a.onload=()=>l(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 rt{constructor(e,t,r,i){u(this,"canvas");u(this,"scene");u(this,"camera");u(this,"renderer");u(this,"renderTargets",[]);u(this,"renderOrder",0);u(this,"qualityFactor",2);u(this,"mode","overlay");u(this,"canvasSize","viewport");u(this,"clipArea",1);u(this,"targetLayer","base");u(this,"overscan",200);u(this,"target");u(this,"mountContainer");u(this,"registry");u(this,"targetRect");u(this,"travelersByLayer",Array.from({length:F.MAX_LAYERS},()=>new Set));u(this,"textureManager");u(this,"fixedMeshes",new Set);var a,c,o,f,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(a=t.mode)!=null?a:"overlay",this.canvasSize=(c=t.canvasSize)!=null?c:"viewport",this.clipArea=(o=t.travelerClipArea)!=null?o:1,this.targetLayer=(f=t.layer)!=null?f:"base",this.textureManager=new tt((d,p)=>{const g=this.registry.get(d);g&&g.material instanceof v.ShaderMaterial&&W.forceUpdateUniforms(g.material,{texture:p})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new v.Scene,this.targetRect=this.target.getBoundingClientRect();const l=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(l/-2,l/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(l,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&&W.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&W.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,l=this.isViewport?window.innerHeight+this.overscan*2:r.height,s=this.isViewport?this.canvas.clientWidth:this.targetRect.width,a=this.isViewport?this.canvas.clientHeight:this.targetRect.height,c=Math.abs(i-s)>.1||Math.abs(l-a)>.1,o=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);c?(this.targetRect=r,this.setSize(i,l),this.updateCanvasLayout()):o?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(f=>{const h=this.registry.get(f);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(f),this.textureManager.unregister(f)}})}reconcileNode(e){var i,l;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof 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),c=W.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,a,e.shaderHooks);t=new v.Mesh(s,c),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=c,t.userData.domElement=e.element,t.userData.shaderHash=r}if(t.userData.clipElements=e.clipElements,(l=e.nativeStyles)!=null&&l.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let 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 o;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],l=r?t.nativeStyles:t.textStyles,s=JSON.stringify(l)+t.textContent+i.map(f=>f.text).join("|"),a=(o=e.userData)==null?void 0:o.textChildStyleHash;if(t.dirtyMask&xe||s!==a){e.children.filter(g=>g.name.startsWith("TEXT_CHILD")).forEach(g=>{var m;const D=g;(m=D.material.map)==null||m.dispose(),D.geometry.dispose(),e.remove(D)});const h=t.rect,d=h.x+h.width/2,p=h.y+h.height/2;i.forEach((g,D)=>{const m=W.create("TEXT",l,g.text,g.rect.width,g.rect.height,this.qualityFactor),w=new v.PlaneGeometry(1,1),E=new v.Mesh(w,m);E.name=`TEXT_CHILD_${D}`;const I=t.rect.width===0?1:g.rect.width/t.rect.width,C=t.rect.height===0?1:g.rect.height/t.rect.height;E.scale.set(I,C,1);const b=g.rect.x+g.rect.width/2,S=g.rect.y+g.rect.height/2,H=b-d,G=-(S-p);E.position.set(t.rect.width===0?0:H/t.rect.width,t.rect.height===0?0:G/t.rect.height,.005),e.add(E)}),e.userData.textChildStyleHash=s}e.children.forEach(f=>{if(!f.name.startsWith("TEXT_CHILD"))return;const h=f;if(r&&t.nativeLayer!==void 0)h.layers.set(N.HIDDEN),t.visibility&j&&h.layers.enable(N.getCaptureLayer(t.nativeLayer));else{const d=t.visibility&j?N.BASE:N.HIDDEN;if(h.layers.set(d),t.visibility&oe&&h.layers.enable(N.SELECTED),t.visibility&j)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,b,S,H,G;const{rect:r,styles:i}=t,l=this.renderer.getPixelRatio(),s=this.renderer.domElement.width/l,a=this.renderer.domElement.height/l;e.material=e.userData.baseMaterial;let c=((C=e.material.userData)==null?void 0:C.shadowPadding)||0;e.scale.set(r.width+c*2,r.height+c*2,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const o=.001;this.renderOrder++;const f=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 z=r.x-f,O=r.y-h;d=z-s/2+r.width/2,p=-O+a/2-r.height/2}e.position.set(d,p,i.zIndex+this.renderOrder*o);const g=r.x,D=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:g,y:D},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,w=window.getComputedStyle(m);let E=0,I=0;if(w.transform&&w.transform!=="none"){const z=new DOMMatrix(w.transform);E=z.m41,I=z.m42}if(e.userData.baseTransform={x:E,y:I},delete e.userData.originRatioX,delete e.userData.originRatioY,W.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(b=this.renderTargets[t.captureLayer-2])==null?void 0:b.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const X=W.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(S=this.renderTargets[t.captureLayer-2])==null?void 0:S.texture:this.textureManager.get(t.element),t.shaderHooks),$=new v.Mesh(e.geometry,X);t.type==="TEXT"&&($.name="BG_MESH"),this.scene.add($),e.userData.nativeMesh=$}const z=e.userData.nativeMesh;let O,Q;if(this.isViewport)O=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,Q=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const X=t.nativeRect.x-f,$=t.nativeRect.y-h;O=X-s/2+t.nativeRect.width/2,Q=-$+a/2-t.nativeRect.height/2}let te=t.nativeRect.width,re=t.nativeRect.height,M=O,V=Q;if(t.nativeStyles.transform){const X=t.nativeStyles.transform,$=X.match(/scale\(([\d.]+%?)\)/);if($){let x=parseFloat($[1]);$[1].includes("%")&&(x/=100),te*=x,re*=x}const le=X.match(/scaleX\(([\d.]+%?)\)/);if(le){let x=parseFloat(le[1]);le[1].includes("%")&&(x/=100),te*=x}const he=X.match(/scaleY\(([\d.]+%?)\)/);if(he){let x=parseFloat(he[1]);he[1].includes("%")&&(x/=100),re*=x}const de=X.match(/translate\(([^,]+),\s*([^)]+)\)/);if(de){const x=de[1].trim(),T=de[2].trim();let Y=parseFloat(x);x.includes("%")&&(Y=Y/100*t.nativeRect.width);let A=parseFloat(T);T.includes("%")&&(A=A/100*t.nativeRect.height),M+=Y,V-=A}const pe=X.match(/translateX\(([^)]+)\)/);if(pe){const x=pe[1].trim();let T=parseFloat(x);x.includes("%")&&(T=T/100*t.nativeRect.width),M+=T}const y=X.match(/translateY\(([^)]+)\)/);if(y){const x=y[1].trim();let T=parseFloat(x);x.includes("%")&&(T=T/100*t.nativeRect.height),V-=T}}let ee=((H=z.material.userData)==null?void 0:H.shadowPadding)||0;z.scale.set(te+ee*2,re+ee*2,1),z.position.set(M,V,t.nativeStyles.zIndex+this.renderOrder*o),W.update(z.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(G=this.renderTargets[t.captureLayer-2])==null?void 0:G.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&j?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&j){i.layers.enable(N.getCaptureLayer(t.nativeLayer));for(let l=t.captureLayer;l<=F.MAX_LAYERS+1;l++)l!==t.nativeLayer&&e.layers.enable(N.getCaptureLayer(l))}}else if(t.visibility&j)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,l=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const s=new v.Vector3,a=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,c=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,o=this.renderer.getPixelRatio();for(const f of e){s.setFromMatrixPosition(f.matrixWorld),s.project(this.camera);const h=(s.x+1)/2*a,d=(s.y+1)/2*c;let p=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(p=parseFloat(this.clipArea));const D=f.scale.x*g+.5,m=f.scale.y*g+.5,w=h-D/2,E=d-m/2,I=(w*this.qualityFactor-p)/o,C=(E*this.qualityFactor-p)/o,b=(D*this.qualityFactor+p*2)/o,S=(m*this.qualityFactor+p*2)/o;this.renderer.setScissor(I,C,b,S),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,l)}render(){for(let c=0;c<F.MAX_LAYERS;c++){const o=c+1;this.captureRenderTarget(this.travelersByLayer[c],N.getCaptureLayer(o),this.renderTargets[c])}const e=this.renderer.getContext(),t=this.renderer.getPixelRatio(),r=this.renderer.domElement.height/t,i=this.renderer.domElement,l=i.getBoundingClientRect().top,s=i.getBoundingClientRect().left,a=(c,o)=>{if(o&&o.width>0&&o.height>0){const f=Math.floor((o.x-s)*t),h=Math.floor((r-(o.y-l+o.height))*t),d=Math.ceil(o.width*t),p=Math.ceil(o.height*t);c.onBeforeRender=()=>{e.enable(e.SCISSOR_TEST),e.scissor(f,h,d,p)},c.onAfterRender=()=>{e.disable(e.SCISSOR_TEST)},c.__hasScissorHook=!0}else c.__hasScissorHook&&(c.onBeforeRender=()=>{},c.onAfterRender=()=>{},c.__hasScissorHook=!1)};this.scene.children.forEach(c=>{var h;const o=c,f=(h=o.userData)==null?void 0:h.scissorRect;a(o,f),o.children.forEach(d=>{d.name.startsWith("TEXT_CHILD")&&a(d,f)})}),this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,l=this.renderer.domElement.height/r;this.scene.children.forEach(s=>{var h,d;const a=s;if(!a.userData||!a.userData.domElement)return;const c=a.userData.domElement;if(!c.isConnected)return;let o;if(c.nodeType===Node.TEXT_NODE){const p=document.createRange();p.selectNode(c),o=p.getBoundingClientRect()}else o=c.getBoundingClientRect();const f=a.userData.domRect;if(!f||Math.abs(o.x-f.x)>.5||Math.abs(o.y-f.y)>.5||Math.abs(o.width-f.width)>.5||Math.abs(o.height-f.height)>.5){a.userData.domRect={x:o.x,y:o.y,width:o.width,height:o.height};const p=a.userData.clipElements;if(p&&p.length>0){let w=-1/0,E=-1/0,I=1/0,C=1/0;for(const b of p){const S=b.getBoundingClientRect();w=Math.max(w,S.left),E=Math.max(E,S.top),I=Math.min(I,S.right),C=Math.min(C,S.bottom)}a.userData.scissorRect={x:w,y:E,width:Math.max(0,I-w),height:Math.max(0,C-E)}}else a.userData.scissorRect=void 0;let g,D;if(this.isViewport)g=o.x-window.innerWidth/2+o.width/2,D=-o.y+window.innerHeight/2-o.height/2;else{const w=o.x-e,E=o.y-t;g=w-i/2+o.width/2,D=-E+l/2-o.height/2}a.position.setX(g),a.position.setY(D);let m=((h=a.material.userData)==null?void 0:h.shadowPadding)||0;if(a.scale.set(o.width+m*2,o.height+m*2,1),a.updateMatrixWorld(),a.material instanceof v.ShaderMaterial&&W.forceUpdateUniforms(a.material,{width:o.width,height:o.height}),a.userData.nativeMesh){const w=a.userData.nativeMesh;let E=o.width,I=o.height,C=g,b=D;if(a.userData.nativeTransform){const H=a.userData.nativeTransform,G=H.match(/scale\(([\d.]+%?)\)/);if(G){let M=parseFloat(G[1]);G[1].includes("%")&&(M/=100),E*=M,I*=M}const z=H.match(/scaleX\(([\d.]+%?)\)/);if(z){let M=parseFloat(z[1]);z[1].includes("%")&&(M/=100),E*=M}const O=H.match(/scaleY\(([\d.]+%?)\)/);if(O){let M=parseFloat(O[1]);O[1].includes("%")&&(M/=100),I*=M}const Q=H.match(/translate\(([^,]+),\s*([^)]+)\)/);if(Q){const M=Q[1].trim(),V=Q[2].trim();let ee=parseFloat(M);M.includes("%")&&(ee=ee/100*o.width);let X=parseFloat(V);V.includes("%")&&(X=X/100*o.height),C+=ee,b-=X}const te=H.match(/translateX\(([^)]+)\)/);if(te){const M=te[1].trim();let V=parseFloat(M);M.includes("%")&&(V=V/100*o.width),C+=V}const re=H.match(/translateY\(([^)]+)\)/);if(re){const M=re[1].trim();let V=parseFloat(M);M.includes("%")&&(V=V/100*o.height),b-=V}}let S=((d=w.material.userData)==null?void 0:d.shadowPadding)||0;w.position.setX(C),w.position.setY(b),w.scale.set(E+S*2,I+S*2,1),w.updateMatrixWorld(),w.material instanceof v.ShaderMaterial&&W.forceUpdateUniforms(w.material,{width:E,height:I})}}})}}function it(n){const e=n.textContent||"",t=[];let r="",i=null,l=-1;const s=(o,f)=>{for(let h=0;h<o.length;h++){const d=o[h],p=document.createRange();p.setStart(n,f+h),p.setEnd(n,f+h+1);const g=p.getBoundingClientRect();if(g.width===0&&g.height===0){r+=d;continue}l===-1||Math.abs(g.top-l)>g.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=d,i={left:g.left,top:g.top,right:g.right,bottom:g.bottom},l=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 c=0;for(const o of a){const f=document.createRange();f.setStart(n,c),f.setEnd(n,c+o.length);const h=f.getClientRects();if(h.length>1)s(o,c);else{const d=h.length===1?h[0]:f.getBoundingClientRect();if(d.width===0&&d.height===0){r+=o,c+=o.length;continue}l===-1||Math.abs(d.top-l)>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=o,i={left:d.left,top:d.top,right:d.right,bottom:d.bottom},l=d.top):(r+=o,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)))}c+=o.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(o=>o.text.trim().length>0&&o.rect.width>0&&o.rect.height>0)}function Ue(n){const e=parseFloat(n.fontSize);let t=parseFloat(n.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(n.letterSpacing);return isNaN(r)&&(r=0),{font:`${n.fontStyle} ${n.fontWeight} ${n.fontSize} ${n.fontFamily}`,fontSize:n.fontSize,color:n.color,textAlign:n.textAlign||"start",textBaseline:"alphabetic",direction:n.direction||"inherit",lineHeight:t,letterSpacing:r}}function _e(n,e=se|ge|Ye|xe|we,t,r=1,i=0,l=2,s,a,c){var ee,X,$,le,he,de,pe;if(n.nodeType===Node.TEXT_NODE){const y=n;if(!y.textContent||!y.textContent.trim())return null;const x=y.textContent.replace(/\s+/g," ");if(x.length===0)return null;const T=it(y);if(T.length===0)return null;const Y=y.parentElement,A=Y?window.getComputedStyle(Y):null;if(!A)return null;const Z=Math.min(...T.map(R=>R.rect.left)),q=Math.min(...T.map(R=>R.rect.top)),ie=Math.max(...T.map(R=>R.rect.left+R.rect.width)),B=Math.max(...T.map(R=>R.rect.top+R.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:y,rect:{x:Z+window.scrollX,y:q+window.scrollY,width:ie-Z,height:B-q},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:Y&&Y.dataset[J.KEY]===J.VALUES.HIDE?1:parseFloat(A.opacity),zIndex:(isNaN(parseInt(A.zIndex))?0:parseInt(A.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:x,textLines:T.map(R=>({text:R.text.trim(),rect:{x:R.rect.left+window.scrollX,y:R.rect.top+window.scrollY,width:R.rect.width,height:R.rect.height}})),textStyles:Ue(A),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:A.position==="fixed",nativeLayer:s,nativeStyles:a?ne(ne({backgroundColor:"transparent",backgroundImage:"",opacity:Y&&Y.dataset[J.KEY]===J.VALUES.HIDE?1:parseFloat(A.opacity),zIndex:(isNaN(parseInt(A.zIndex))?0:parseInt(A.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Ue(A)),a):void 0,nativeRect:a?{x:Z+window.scrollX,y:q+window.scrollY,width:ie-Z,height:B-q}:void 0,clipElements:c,children:[]}}if(n.nodeType!==Node.ELEMENT_NODE)return null;const o=n,f=o.dataset[_.KEY];let h=t,d=t;if(f){const y=new Set(f.split(/\s+/));for(const x of y)if(!De.includes(x))throw new Error(`[MirageEngine] Invalid filter token: '${x}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(y.has(_.VALUES.END))return null;if(y.has(_.VALUES.INCLUDE_TREE)&&y.has(_.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(y.has(_.VALUES.INCLUDE_SELF)&&y.has(_.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");y.has(_.VALUES.INCLUDE_TREE)?h=h|j:y.has(_.VALUES.EXCLUDE_TREE)&&(h=h&~j),d=h,y.has(_.VALUES.INCLUDE_SELF)?d=d|j:y.has(_.VALUES.EXCLUDE_SELF)&&(d=d&~j)}const p=o.dataset[P.KEY];if(p){const y=new Set(p.split(/\s+/));for(const x of y)if(!De.includes(x))throw new Error(`[MirageEngine] Invalid select token: '${x}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(y.has(P.VALUES.END))return null;if(y.has(P.VALUES.INCLUDE_TREE)&&y.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(y.has(P.VALUES.INCLUDE_SELF)&&y.has(P.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");y.has(P.VALUES.INCLUDE_TREE)?h=h|oe:y.has(P.VALUES.EXCLUDE_TREE)&&(h=h&~oe),d=h,y.has(P.VALUES.INCLUDE_SELF)?d=d|oe:y.has(P.VALUES.EXCLUDE_SELF)&&(d=d&~oe)}const g=o.dataset[F.KEY];let D=!1,m=a?ne({},a):{},w=s;if(g){let y=1;const x=g.indexOf("{"),T=g.lastIndexOf("}");let Y=g;if(x!==-1&&T!==-1&&T>x){Y=g.substring(0,x).trim();const B=g.substring(x,T+1);try{m=new Function("return "+B)()}catch(R){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${B}`)}}const A=Y.split(/\s+/);let Z=!1;const q=A.indexOf(F.VALUES.TRAVELER);if(q!==-1){D=!0,Z=!0;const B=A[q+1];if(B&&!isNaN(parseInt(B,10)))y=parseInt(B,10);else{const R=A.find(ue=>!isNaN(parseInt(ue,10)));R&&(y=parseInt(R,10))}}const ie=A.indexOf(F.VALUES.NATIVE);if(ie!==-1){const B=A[ie+1];if(B&&!isNaN(parseInt(B,10)))w=parseInt(B,10);else if(!D){const R=A.find(ue=>!isNaN(parseInt(ue,10)));R&&(w=parseInt(R,10))}}if(Z){const B=y+1;if(B<r)throw new Error(`[MirageEngine] Traveler layer (${y}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(B,F.MAX_LAYERS+1)}}const E=o.dataset[Ve.KEY];let I;E&&(I=JSON.parse(E));const C=o.getBoundingClientRect(),b=window.getComputedStyle(o);if(C.width===0||C.height===0||b.display==="none")return null;let S=o.getAttribute("data-mid");S||(S=Math.random().toString(36).substring(2,11),o.setAttribute("data-mid",S));const H=parseInt(b.zIndex),G=(isNaN(H)?0:H)+i;let z;if(o.tagName==="IMG")z=o.src;else if(o.tagName.toLowerCase()==="svg"){const y=o.cloneNode(!0),x=m==null?void 0:m.color,T=m==null?void 0:m.fill,Y=m==null?void 0:m.stroke,A=m==null?void 0:m.opacity,Z=(R,ue)=>{const K=window.getComputedStyle(R),me=ue,ht=K.fill===K.color,dt=K.stroke===K.color,Ee=T||(ht?x:void 0)||K.fill;Ee&&Ee!=="none"&&(me.style.fill=Ee);const Ce=Y||(dt?x:void 0)||K.stroke;Ce&&Ce!=="none"&&(me.style.stroke=Ce),K.strokeWidth&&K.strokeWidth!=="0px"&&(me.style.strokeWidth=K.strokeWidth);const Fe=x||K.color;Fe&&(me.style.color=Fe);const Te=A||K.opacity;Te&&Te!=="1"&&(me.style.opacity=Te);for(let be=0;be<R.children.length;be++)Z(R.children[be],ue.children[be])};Z(o,y);const q=o.getBoundingClientRect(),ie=window.devicePixelRatio*l;y.hasAttribute("viewBox")||y.setAttribute("viewBox",`0 0 ${q.width} ${q.height}`),y.setAttribute("width",(q.width*ie).toString()),y.setAttribute("height",(q.height*ie).toString());let B=new XMLSerializer().serializeToString(y);B.includes("xmlns=")||(B=B.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),z=`data:image/svg+xml;utf8,${encodeURIComponent(B)}`}else if(b.backgroundImage&&b.backgroundImage!=="none"){const y=b.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);y&&(z=y[1])}const O={backgroundColor:b.backgroundColor,backgroundImage:b.backgroundImage,opacity:o.dataset[J.KEY]===J.VALUES.HIDE?1:parseFloat(b.opacity),zIndex:G,borderRadius:b.borderRadius,borderColor:b.borderColor,borderWidth:b.borderWidth,boxShadow:b.boxShadow,imageSrc:z,isTraveler:D},Q=O;let te,re;const M=[],V=b.overflow==="hidden"?[...c||[],o]:c;return o.tagName.toLowerCase()!=="svg"&&Array.from(o.childNodes).forEach(y=>{const x=y.nodeType===Node.TEXT_NODE?d:h,T=_e(y,e,x,r,G,l,y.nodeType===Node.TEXT_NODE?w:void 0,y.nodeType===Node.TEXT_NODE&&Object.keys(m).length>0?m:void 0,V);T&&M.push(T)}),{id:S,type:"BOX",element:o,rect:{x:C.left+window.scrollX,y:C.top+window.scrollY,width:C.width,height:C.height},styles:Q,textContent:te,textStyles:re,dirtyMask:e,visibility:d,isTraveler:D,captureLayer:r,nativeLayer:w,nativeStyles:w!==void 0?Ne(ne({},O),{backgroundColor:(ee=m.backgroundColor)!=null?ee:O.backgroundColor,backgroundImage:(X=m.backgroundImage)!=null?X:O.backgroundImage,opacity:($=m.opacity)!=null?$:O.opacity,zIndex:m.zIndex!==void 0?m.zIndex+G:O.zIndex,borderRadius:(le=m.borderRadius)!=null?le:O.borderRadius,borderColor:(he=m.borderColor)!=null?he:O.borderColor,borderWidth:(de=m.borderWidth)!=null?de:O.borderWidth,boxShadow:(pe=m.boxShadow)!=null?pe:O.boxShadow,isTraveler:O.isTraveler,transform:m.transform}):void 0,nativeRect:w!==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:b.position==="fixed",clipElements:c,children:M,shaderHooks:I}}function st(n,e){e.size!==0&&e.forEach((t,r)=>{var l,s,a,c;const i=n.get(r);!i||!i.userData.basePosition||(W.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(s=t.borderRadius)!=null?s:(l=i.userData.baseStyles)==null?void 0:l.borderRadius}),i.userData.nativeMesh&&W.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(c=t.borderRadius)!=null?c:(a=i.userData.baseStyles)==null?void 0:a.borderRadius}))})}class nt{constructor(e,t,r,i){u(this,"target");u(this,"renderer");u(this,"registry");u(this,"isTravelEnabled",!1);u(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new Le(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((l,s)=>{document.querySelector(`[${F.NAME}~='${F.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const c=_e(this.target,l,j,1,0,this.renderer.qualityFactor);c&&this.renderer.syncScene(c,s)}),this.tracker.onStyleChange.add(l=>{st(this.registry,l)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class ot{constructor(){u(this,"store");this.store=new WeakMap}register(e,t){this.store.set(e,t)}get(e){return this.store.get(e)}has(e){return this.store.has(e)}remove(e){this.store.delete(e)}}class at{constructor(e,t){u(this,"renderer");u(this,"syncer");u(this,"target");u(this,"registry");var i,l,s;if(this.target=e,this.registry=new ot,!document.getElementById("mirage-engine-styles")){const a=document.createElement("style");a.id="mirage-engine-styles",a.textContent=`
185
+ `,d=l||c?f+h+((i==null?void 0:i.uvModifier)||""):"",p=l||c?Oe.baseColorChunk:"",g=(i==null?void 0:i.colorModifier)||"",D=Ie.fragmentShader.replace("#INJECT_DECLARATIONS",o).replace("#INJECT_UV_MODIFIER",d).replace("#INJECT_BASE_COLOR",p).replace("#INJECT_COLOR_MODIFIER",g),m=ce(n.backgroundColor),b=ce(n.borderColor),E={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(b.color.r,b.color.g,b.color.b,b.alpha)},uBorderRadius:{value:new v.Vector4(0,0,0,0)},uBorderWidth:{value:ae(n.borderWidth)},uOpacity:{value:(C=n.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(E.uBorderRadius.value,n.borderRadius,Math.min(e,t)),l&&(E.uTexture.value=r);const I=new v.ShaderMaterial({uniforms:ne(ne({},E),a),vertexShader:Ie.vertexShader,fragmentShader:D,transparent:!0,side:v.FrontSide});return n.backgroundImage&&Se(I,{backgroundImage:n.backgroundImage}),I}function et(n,e,t,r,i){const l=ae(e.borderWidth);Se(n,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:l,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage,boxShadow:e.boxShadow})}function Se(n,e){var r,i,l;if(e.boxShadow!==void 0){const s=Ge(e.boxShadow);s?(n.uniforms.uShadowColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha),n.uniforms.uShadowOffset.value.set(s.offsetX,s.offsetY),n.uniforms.uShadowBlur.value=s.blurRadius,n.uniforms.uShadowSpread.value=s.spreadRadius,n.userData.shadowPadding=s.blurRadius+s.spreadRadius+Math.max(Math.abs(s.offsetX),Math.abs(s.offsetY))):(n.uniforms.uShadowColor.value.w=0,n.userData.shadowPadding=0)}if(e.width!==void 0&&e.height!==void 0&&n.uniforms.uSize.value.set(e.width,e.height),n.uniforms.uMeshSize){const s=n.userData.shadowPadding||0,a=e.width!==void 0?e.width:n.uniforms.uSize.value.x,c=e.height!==void 0?e.height:n.uniforms.uSize.value.y;n.uniforms.uMeshSize.value.set(a+s*2,c+s*2)}if(e.borderRadius!==void 0){const s=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(n.uniforms.uSize.value.x,n.uniforms.uSize.value.y);Be(n.uniforms.uBorderRadius.value,e.borderRadius,s)}if(e.borderWidth!==void 0&&(n.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const s=e.backgroundColor[3]!==void 0?e.backgroundColor[3]:n.uniforms.uBgColor.value.w;n.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],s)}else if(typeof e.backgroundColor=="string"){const s=ce(e.backgroundColor);n.uniforms.uBgColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=n.uniforms.uBgColor.value.w;n.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,s)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const s=n.uniforms.uBorderColor.value.w;n.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],s)}else if(typeof e.borderColor=="string"){const s=ce(e.borderColor);n.uniforms.uBorderColor.value.set(s.color.r,s.color.g,s.color.b,s.alpha)}else{const s=n.uniforms.uBorderColor.value.w;n.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,s)}e.opacity!==void 0&&(n.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(n.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(n.uniforms.uBorderColor.value.w=e.borderOpacity),n.uniforms.uTexture&&e.texture!==void 0&&(n.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=n.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const s=t.image.naturalWidth||t.image.videoWidth||t.image.width,a=t.image.naturalHeight||t.image.videoHeight||t.image.height,c=(i=e.width)!=null?i:n.uniforms.uSize.value.x,o=(l=e.height)!=null?l:n.uniforms.uSize.value.y;if(s&&a&&c&&o){const f=s/a,h=c/o;if(f>h){const d=h/f;n.uniforms.uTextureRepeat.value.set(d,1),n.uniforms.uTextureOffset.value.set((1-d)/2,0)}else{const d=f/h;n.uniforms.uTextureRepeat.value.set(1,d),n.uniforms.uTextureOffset.value.set(0,(1-d)/2)}}}else n.uniforms.uTextureRepeat&&(n.uniforms.uTextureRepeat.value.set(1,1),n.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const s=$e(e.backgroundImage);if(s){n.uniforms.uGradientCount.value=s.stops.length,n.uniforms.uGradientAngle.value=s.angle;for(let a=0;a<8;a++)if(a<s.stops.length){const c=s.stops[a];n.uniforms.uGradientColors.value[a].set(c.color.r,c.color.g,c.color.b,c.alpha),n.uniforms.uGradientStops.value[a]=c.stop}else n.uniforms.uGradientColors.value[a].set(0,0,0,0),n.uniforms.uGradientStops.value[a]=1}else n.uniforms.uGradientCount.value=0}for(const s of Object.keys(e))s!=="width"&&s!=="height"&&s!=="borderRadius"&&s!=="borderWidth"&&s!=="backgroundColor"&&s!=="borderColor"&&s!=="opacity"&&s!=="bgOpacity"&&s!=="borderOpacity"&&s!=="texture"&&s!=="backgroundImage"&&s!=="boxShadow"&&n.uniforms[s]!==void 0&&(n.uniforms[s].value!==void 0&&n.uniforms[s].value!==null&&typeof n.uniforms[s].value.set=="function"?Array.isArray(e[s])?n.uniforms[s].value.set(...e[s]):e[s]!==void 0&&(e[s].copy?n.uniforms[s].value.copy(e[s]):n.uniforms[s].value=e[s]):n.uniforms[s].value=e[s])}function Be(n,e,t=0){var c,o,f,h;if(e==null){n.set(0,0,0,0);return}if(typeof e=="number"){n.set(e,e,e,e);return}if(Array.isArray(e)){n.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=ae(r[0],t),l=ae((c=r[1])!=null?c:r[0],t),s=ae((o=r[2])!=null?o:r[0],t),a=ae((h=(f=r[3])!=null?f:r[1])!=null?h:r[0],t);n.set(i,l,s,a)}const W={create(n,e,t,r,i,l=2,s=null,a){return n==="BOX"?Qe(e,r,i,s,a):n==="TEXT"?new We(t||"",e,r,i,l):new v.MeshBasicMaterial({visible:!1})},update(n,e,t,r,i,l,s=2,a){e==="BOX"?et(n,t,i,l,a):e==="TEXT"&&n.updateText(r||"",t,i,l,s)},forceUpdateUniforms(n,e){Se(n,e)}};class tt{constructor(e,t=!0){u(this,"observer");u(this,"textures",new WeakMap);u(this,"loadStatus",new WeakMap);u(this,"elementUrls",new WeakMap);u(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const l=i.target;i.isIntersecting?this.loadTexture(l):this.disposeTexture(l)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return Xe(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((l,s)=>{const a=new Image;a.onload=()=>l(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 rt{constructor(e,t,r,i){u(this,"canvas");u(this,"scene");u(this,"camera");u(this,"renderer");u(this,"renderTargets",[]);u(this,"renderOrder",0);u(this,"qualityFactor",2);u(this,"mode","overlay");u(this,"canvasSize","viewport");u(this,"clipArea",1);u(this,"targetLayer","base");u(this,"overscan",200);u(this,"target");u(this,"mountContainer");u(this,"registry");u(this,"targetRect");u(this,"travelersByLayer",Array.from({length:F.MAX_LAYERS},()=>new Set));u(this,"textureManager");u(this,"fixedMeshes",new Set);var a,c,o,f,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(a=t.mode)!=null?a:"overlay",this.canvasSize=(c=t.canvasSize)!=null?c:"viewport",this.clipArea=(o=t.travelerClipArea)!=null?o:1,this.targetLayer=(f=t.layer)!=null?f:"base",this.textureManager=new tt((d,p)=>{const g=this.registry.get(d);g&&g.material instanceof v.ShaderMaterial&&W.forceUpdateUniforms(g.material,{texture:p})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new v.Scene,this.targetRect=this.target.getBoundingClientRect();const l=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(l/-2,l/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(l,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&&W.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&W.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,l=this.isViewport?window.innerHeight+this.overscan*2:r.height,s=this.isViewport?this.canvas.clientWidth:this.targetRect.width,a=this.isViewport?this.canvas.clientHeight:this.targetRect.height,c=Math.abs(i-s)>.1||Math.abs(l-a)>.1,o=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);c?(this.targetRect=r,this.setSize(i,l),this.updateCanvasLayout()):o?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(f=>{const h=this.registry.get(f);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(f),this.textureManager.unregister(f)}})}reconcileNode(e){var i,l;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof 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),c=W.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,a,e.shaderHooks);t=new v.Mesh(s,c),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=c,t.userData.domElement=e.element,t.userData.shaderHash=r}if(t.userData.clipElements=e.clipElements,(l=e.nativeStyles)!=null&&l.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let 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 o;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],l=r?t.nativeStyles:t.textStyles,s=JSON.stringify(l)+t.textContent+i.map(f=>f.text).join("|"),a=(o=e.userData)==null?void 0:o.textChildStyleHash;if(t.dirtyMask&xe||s!==a){e.children.filter(g=>g.name.startsWith("TEXT_CHILD")).forEach(g=>{var m;const D=g;(m=D.material.map)==null||m.dispose(),D.geometry.dispose(),e.remove(D)});const h=t.rect,d=h.x+h.width/2,p=h.y+h.height/2;i.forEach((g,D)=>{const m=W.create("TEXT",l,g.text,g.rect.width,g.rect.height,this.qualityFactor),b=new v.PlaneGeometry(1,1),E=new v.Mesh(b,m);E.name=`TEXT_CHILD_${D}`;const I=t.rect.width===0?1:g.rect.width/t.rect.width,C=t.rect.height===0?1:g.rect.height/t.rect.height;E.scale.set(I,C,1);const w=g.rect.x+g.rect.width/2,S=g.rect.y+g.rect.height/2,H=w-d,$=-(S-p);E.position.set(t.rect.width===0?0:H/t.rect.width,t.rect.height===0?0:$/t.rect.height,.005),e.add(E)}),e.userData.textChildStyleHash=s}e.children.forEach(f=>{if(!f.name.startsWith("TEXT_CHILD"))return;const h=f;if(r&&t.nativeLayer!==void 0)h.layers.set(N.HIDDEN),t.visibility&j&&h.layers.enable(N.getCaptureLayer(t.nativeLayer));else{const d=t.visibility&j?N.BASE:N.HIDDEN;if(h.layers.set(d),t.visibility&oe&&h.layers.enable(N.SELECTED),t.visibility&j)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,w,S,H,$;const{rect:r,styles:i}=t,l=this.renderer.getPixelRatio(),s=this.renderer.domElement.width/l,a=this.renderer.domElement.height/l;e.material=e.userData.baseMaterial;let c=((C=e.material.userData)==null?void 0:C.shadowPadding)||0;e.scale.set(r.width+c*2,r.height+c*2,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const o=.001;this.renderOrder++;const f=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 z=r.x-f,O=r.y-h;d=z-s/2+r.width/2,p=-O+a/2-r.height/2}e.position.set(d,p,i.zIndex+this.renderOrder*o);const g=r.x,D=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:g,y:D},e.userData.isFixed=t.isFixed,e.userData.initialScroll={x:window.scrollX,y:window.scrollY};const m=t.element.nodeType===Node.TEXT_NODE?t.element.parentElement:t.element,b=window.getComputedStyle(m);let E=0,I=0;if(b.transform&&b.transform!=="none"){const z=new DOMMatrix(b.transform);E=z.m41,I=z.m42}if(e.userData.baseTransform={x:E,y:I},delete e.userData.originRatioX,delete e.userData.originRatioY,W.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(w=this.renderTargets[t.captureLayer-2])==null?void 0:w.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const X=W.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(S=this.renderTargets[t.captureLayer-2])==null?void 0:S.texture:this.textureManager.get(t.element),t.shaderHooks),G=new v.Mesh(e.geometry,X);t.type==="TEXT"&&(G.name="BG_MESH"),this.scene.add(G),e.userData.nativeMesh=G}const z=e.userData.nativeMesh;let O,Q;if(this.isViewport)O=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,Q=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const X=t.nativeRect.x-f,G=t.nativeRect.y-h;O=X-s/2+t.nativeRect.width/2,Q=-G+a/2-t.nativeRect.height/2}let te=t.nativeRect.width,re=t.nativeRect.height,M=O,V=Q;if(t.nativeStyles.transform){const X=t.nativeStyles.transform,G=X.match(/scale\(([\d.]+%?)\)/);if(G){let x=parseFloat(G[1]);G[1].includes("%")&&(x/=100),te*=x,re*=x}const le=X.match(/scaleX\(([\d.]+%?)\)/);if(le){let x=parseFloat(le[1]);le[1].includes("%")&&(x/=100),te*=x}const he=X.match(/scaleY\(([\d.]+%?)\)/);if(he){let x=parseFloat(he[1]);he[1].includes("%")&&(x/=100),re*=x}const de=X.match(/translate\(([^,]+),\s*([^)]+)\)/);if(de){const x=de[1].trim(),T=de[2].trim();let Y=parseFloat(x);x.includes("%")&&(Y=Y/100*t.nativeRect.width);let A=parseFloat(T);T.includes("%")&&(A=A/100*t.nativeRect.height),M+=Y,V-=A}const pe=X.match(/translateX\(([^)]+)\)/);if(pe){const x=pe[1].trim();let T=parseFloat(x);x.includes("%")&&(T=T/100*t.nativeRect.width),M+=T}const y=X.match(/translateY\(([^)]+)\)/);if(y){const x=y[1].trim();let T=parseFloat(x);x.includes("%")&&(T=T/100*t.nativeRect.height),V-=T}}let ee=((H=z.material.userData)==null?void 0:H.shadowPadding)||0;z.scale.set(te+ee*2,re+ee*2,1),z.position.set(M,V,t.nativeStyles.zIndex+this.renderOrder*o),W.update(z.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?($=this.renderTargets[t.captureLayer-2])==null?void 0:$.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&j?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&j){i.layers.enable(N.getCaptureLayer(t.nativeLayer));for(let l=t.captureLayer;l<=F.MAX_LAYERS+1;l++)l!==t.nativeLayer&&e.layers.enable(N.getCaptureLayer(l))}}else if(t.visibility&j)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,l=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const s=new v.Vector3,a=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,c=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,o=this.renderer.getPixelRatio();for(const f of e){s.setFromMatrixPosition(f.matrixWorld),s.project(this.camera);const h=(s.x+1)/2*a,d=(s.y+1)/2*c;let p=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(p=parseFloat(this.clipArea));const D=f.scale.x*g+.5,m=f.scale.y*g+.5,b=h-D/2,E=d-m/2,I=(b*this.qualityFactor-p)/o,C=(E*this.qualityFactor-p)/o,w=(D*this.qualityFactor+p*2)/o,S=(m*this.qualityFactor+p*2)/o;this.renderer.setScissor(I,C,w,S),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,l)}render(){for(let c=0;c<F.MAX_LAYERS;c++){const o=c+1;this.captureRenderTarget(this.travelersByLayer[c],N.getCaptureLayer(o),this.renderTargets[c])}const e=this.renderer.getContext(),t=this.renderer.getPixelRatio(),r=this.renderer.domElement.height/t,i=this.renderer.domElement,l=i.getBoundingClientRect().top,s=i.getBoundingClientRect().left,a=(c,o)=>{if(o&&o.width>0&&o.height>0){const f=Math.floor((o.x-s)*t),h=Math.floor((r-(o.y-l+o.height))*t),d=Math.ceil(o.width*t),p=Math.ceil(o.height*t);c.onBeforeRender=()=>{e.enable(e.SCISSOR_TEST),e.scissor(f,h,d,p)},c.onAfterRender=()=>{e.disable(e.SCISSOR_TEST)},c.__hasScissorHook=!0}else c.__hasScissorHook&&(c.onBeforeRender=()=>{},c.onAfterRender=()=>{},c.__hasScissorHook=!1)};this.scene.children.forEach(c=>{var h;const o=c,f=(h=o.userData)==null?void 0:h.scissorRect;a(o,f),o.children.forEach(d=>{d.name.startsWith("TEXT_CHILD")&&a(d,f)})}),this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,l=this.renderer.domElement.height/r;this.scene.children.forEach(s=>{var h,d;const a=s;if(!a.userData||!a.userData.domElement)return;const c=a.userData.domElement;if(!c.isConnected)return;let o;if(c.nodeType===Node.TEXT_NODE){const p=document.createRange();p.selectNode(c),o=p.getBoundingClientRect()}else o=c.getBoundingClientRect();const f=a.userData.domRect;if(!f||Math.abs(o.x-f.x)>.5||Math.abs(o.y-f.y)>.5||Math.abs(o.width-f.width)>.5||Math.abs(o.height-f.height)>.5){a.userData.domRect={x:o.x,y:o.y,width:o.width,height:o.height};const p=a.userData.clipElements;if(p&&p.length>0){let b=-1/0,E=-1/0,I=1/0,C=1/0;for(const w of p){const S=w.getBoundingClientRect();b=Math.max(b,S.left),E=Math.max(E,S.top),I=Math.min(I,S.right),C=Math.min(C,S.bottom)}a.userData.scissorRect={x:b,y:E,width:Math.max(0,I-b),height:Math.max(0,C-E)}}else a.userData.scissorRect=void 0;let g,D;if(this.isViewport)g=o.x-window.innerWidth/2+o.width/2,D=-o.y+window.innerHeight/2-o.height/2;else{const b=o.x-e,E=o.y-t;g=b-i/2+o.width/2,D=-E+l/2-o.height/2}a.position.setX(g),a.position.setY(D);let m=((h=a.material.userData)==null?void 0:h.shadowPadding)||0;if(a.scale.set(o.width+m*2,o.height+m*2,1),a.updateMatrixWorld(),a.material instanceof v.ShaderMaterial&&W.forceUpdateUniforms(a.material,{width:o.width,height:o.height}),a.userData.nativeMesh){const b=a.userData.nativeMesh;let E=o.width,I=o.height,C=g,w=D;if(a.userData.nativeTransform){const H=a.userData.nativeTransform,$=H.match(/scale\(([\d.]+%?)\)/);if($){let M=parseFloat($[1]);$[1].includes("%")&&(M/=100),E*=M,I*=M}const z=H.match(/scaleX\(([\d.]+%?)\)/);if(z){let M=parseFloat(z[1]);z[1].includes("%")&&(M/=100),E*=M}const O=H.match(/scaleY\(([\d.]+%?)\)/);if(O){let M=parseFloat(O[1]);O[1].includes("%")&&(M/=100),I*=M}const Q=H.match(/translate\(([^,]+),\s*([^)]+)\)/);if(Q){const M=Q[1].trim(),V=Q[2].trim();let ee=parseFloat(M);M.includes("%")&&(ee=ee/100*o.width);let X=parseFloat(V);V.includes("%")&&(X=X/100*o.height),C+=ee,w-=X}const te=H.match(/translateX\(([^)]+)\)/);if(te){const M=te[1].trim();let V=parseFloat(M);M.includes("%")&&(V=V/100*o.width),C+=V}const re=H.match(/translateY\(([^)]+)\)/);if(re){const M=re[1].trim();let V=parseFloat(M);M.includes("%")&&(V=V/100*o.height),w-=V}}let S=((d=b.material.userData)==null?void 0:d.shadowPadding)||0;b.position.setX(C),b.position.setY(w),b.scale.set(E+S*2,I+S*2,1),b.updateMatrixWorld(),b.material instanceof v.ShaderMaterial&&W.forceUpdateUniforms(b.material,{width:E,height:I})}}})}}function it(n){const e=n.textContent||"",t=[];let r="",i=null,l=-1;const s=(o,f)=>{for(let h=0;h<o.length;h++){const d=o[h],p=document.createRange();p.setStart(n,f+h),p.setEnd(n,f+h+1);const g=p.getBoundingClientRect();if(g.width===0&&g.height===0){r+=d;continue}l===-1||Math.abs(g.top-l)>g.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=d,i={left:g.left,top:g.top,right:g.right,bottom:g.bottom},l=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 c=0;for(const o of a){const f=document.createRange();f.setStart(n,c),f.setEnd(n,c+o.length);const h=f.getClientRects();if(h.length>1)s(o,c);else{const d=h.length===1?h[0]:f.getBoundingClientRect();if(d.width===0&&d.height===0){r+=o,c+=o.length;continue}l===-1||Math.abs(d.top-l)>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=o,i={left:d.left,top:d.top,right:d.right,bottom:d.bottom},l=d.top):(r+=o,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)))}c+=o.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(o=>o.text.trim().length>0&&o.rect.width>0&&o.rect.height>0)}function Ue(n){const e=parseFloat(n.fontSize);let t=parseFloat(n.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(n.letterSpacing);return isNaN(r)&&(r=0),{font:`${n.fontStyle} ${n.fontWeight} ${n.fontSize} ${n.fontFamily}`,fontSize:n.fontSize,color:n.color,textAlign:n.textAlign||"start",textBaseline:"alphabetic",direction:n.direction||"inherit",lineHeight:t,letterSpacing:r}}function _e(n,e=se|ge|Ye|xe|we,t,r=1,i=0,l=2,s,a,c){var ee,X,G,le,he,de,pe;if(n.nodeType===Node.TEXT_NODE){const y=n;if(!y.textContent||!y.textContent.trim())return null;const x=y.textContent.replace(/\s+/g," ");if(x.length===0)return null;const T=it(y);if(T.length===0)return null;const Y=y.parentElement,A=Y?window.getComputedStyle(Y):null;if(!A)return null;const Z=Math.min(...T.map(R=>R.rect.left)),q=Math.min(...T.map(R=>R.rect.top)),ie=Math.max(...T.map(R=>R.rect.left+R.rect.width)),B=Math.max(...T.map(R=>R.rect.top+R.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:y,rect:{x:Z+window.scrollX,y:q+window.scrollY,width:ie-Z,height:B-q},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:Y&&Y.dataset[J.KEY]===J.VALUES.HIDE?1:parseFloat(A.opacity),zIndex:(isNaN(parseInt(A.zIndex))?0:parseInt(A.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:x,textLines:T.map(R=>({text:R.text.trim(),rect:{x:R.rect.left+window.scrollX,y:R.rect.top+window.scrollY,width:R.rect.width,height:R.rect.height}})),textStyles:Ue(A),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:A.position==="fixed",nativeLayer:s,nativeStyles:a?ne(ne({backgroundColor:"transparent",backgroundImage:"",opacity:Y&&Y.dataset[J.KEY]===J.VALUES.HIDE?1:parseFloat(A.opacity),zIndex:(isNaN(parseInt(A.zIndex))?0:parseInt(A.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Ue(A)),a):void 0,nativeRect:a?{x:Z+window.scrollX,y:q+window.scrollY,width:ie-Z,height:B-q}:void 0,clipElements:c,children:[]}}if(n.nodeType!==Node.ELEMENT_NODE)return null;const o=n,f=o.dataset[_.KEY];let h=t,d=t;if(f){const y=new Set(f.split(/\s+/));for(const x of y)if(!De.includes(x))throw new Error(`[MirageEngine] Invalid filter token: '${x}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(y.has(_.VALUES.END))return null;if(y.has(_.VALUES.INCLUDE_TREE)&&y.has(_.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(y.has(_.VALUES.INCLUDE_SELF)&&y.has(_.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");y.has(_.VALUES.INCLUDE_TREE)?h=h|j:y.has(_.VALUES.EXCLUDE_TREE)&&(h=h&~j),d=h,y.has(_.VALUES.INCLUDE_SELF)?d=d|j:y.has(_.VALUES.EXCLUDE_SELF)&&(d=d&~j)}const p=o.dataset[P.KEY];if(p){const y=new Set(p.split(/\s+/));for(const x of y)if(!De.includes(x))throw new Error(`[MirageEngine] Invalid select token: '${x}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(y.has(P.VALUES.END))return null;if(y.has(P.VALUES.INCLUDE_TREE)&&y.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(y.has(P.VALUES.INCLUDE_SELF)&&y.has(P.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");y.has(P.VALUES.INCLUDE_TREE)?h=h|oe:y.has(P.VALUES.EXCLUDE_TREE)&&(h=h&~oe),d=h,y.has(P.VALUES.INCLUDE_SELF)?d=d|oe:y.has(P.VALUES.EXCLUDE_SELF)&&(d=d&~oe)}const g=o.dataset[F.KEY];let D=!1,m=a?ne({},a):{},b=s;if(g){let y=1;const x=g.indexOf("{"),T=g.lastIndexOf("}");let Y=g;if(x!==-1&&T!==-1&&T>x){Y=g.substring(0,x).trim();const B=g.substring(x,T+1);try{m=new Function("return "+B)()}catch(R){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${B}`)}}const A=Y.split(/\s+/);let Z=!1;const q=A.indexOf(F.VALUES.TRAVELER);if(q!==-1){D=!0,Z=!0;const B=A[q+1];if(B&&!isNaN(parseInt(B,10)))y=parseInt(B,10);else{const R=A.find(ue=>!isNaN(parseInt(ue,10)));R&&(y=parseInt(R,10))}}const ie=A.indexOf(F.VALUES.NATIVE);if(ie!==-1){const B=A[ie+1];if(B&&!isNaN(parseInt(B,10)))b=parseInt(B,10);else if(!D){const R=A.find(ue=>!isNaN(parseInt(ue,10)));R&&(b=parseInt(R,10))}}if(Z){const B=y+1;if(B<r)throw new Error(`[MirageEngine] Traveler layer (${y}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(B,F.MAX_LAYERS+1)}}const E=o.dataset[Ve.KEY];let I;E&&(I=JSON.parse(E));const C=o.getBoundingClientRect(),w=window.getComputedStyle(o);if(C.width===0||C.height===0||w.display==="none")return null;let S=o.getAttribute("data-mid");S||(S=Math.random().toString(36).substring(2,11),o.setAttribute("data-mid",S));const H=parseInt(w.zIndex),$=(isNaN(H)?0:H)+i;let z;if(o.tagName==="IMG")z=o.src;else if(o.tagName.toLowerCase()==="svg"){const y=o.cloneNode(!0),x=m==null?void 0:m.color,T=m==null?void 0:m.fill,Y=m==null?void 0:m.stroke,A=m==null?void 0:m.opacity,Z=(R,ue)=>{const K=window.getComputedStyle(R),me=ue,ht=K.fill===K.color,dt=K.stroke===K.color,Ee=T||(ht?x:void 0)||K.fill;Ee&&Ee!=="none"&&(me.style.fill=Ee);const Ce=Y||(dt?x:void 0)||K.stroke;Ce&&Ce!=="none"&&(me.style.stroke=Ce),K.strokeWidth&&K.strokeWidth!=="0px"&&(me.style.strokeWidth=K.strokeWidth);const Fe=x||K.color;Fe&&(me.style.color=Fe);const Te=A||K.opacity;Te&&Te!=="1"&&(me.style.opacity=Te);for(let be=0;be<R.children.length;be++)Z(R.children[be],ue.children[be])};Z(o,y);const q=o.getBoundingClientRect(),ie=window.devicePixelRatio*l;y.hasAttribute("viewBox")||y.setAttribute("viewBox",`0 0 ${q.width} ${q.height}`),y.setAttribute("width",(q.width*ie).toString()),y.setAttribute("height",(q.height*ie).toString());let B=new XMLSerializer().serializeToString(y);B.includes("xmlns=")||(B=B.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),z=`data:image/svg+xml;utf8,${encodeURIComponent(B)}`}else if(w.backgroundImage&&w.backgroundImage!=="none"){const y=w.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);y&&(z=y[1])}const O={backgroundColor:w.backgroundColor,backgroundImage:w.backgroundImage,opacity:o.dataset[J.KEY]===J.VALUES.HIDE?1:parseFloat(w.opacity),zIndex:$,borderRadius:w.borderRadius,borderColor:w.borderColor,borderWidth:w.borderWidth,boxShadow:w.boxShadow,imageSrc:z,isTraveler:D},Q=O;let te,re;const M=[],V=w.overflow==="hidden"?[...c||[],o]:c;return o.tagName.toLowerCase()!=="svg"&&Array.from(o.childNodes).forEach(y=>{const x=y.nodeType===Node.TEXT_NODE?d:h,T=_e(y,e,x,r,$,l,y.nodeType===Node.TEXT_NODE?b:void 0,y.nodeType===Node.TEXT_NODE&&Object.keys(m).length>0?m:void 0,V);T&&M.push(T)}),{id:S,type:"BOX",element:o,rect:{x:C.left+window.scrollX,y:C.top+window.scrollY,width:C.width,height:C.height},styles:Q,textContent:te,textStyles:re,dirtyMask:e,visibility:d,isTraveler:D,captureLayer:r,nativeLayer:b,nativeStyles:b!==void 0?Ne(ne({},O),{backgroundColor:(ee=m.backgroundColor)!=null?ee:O.backgroundColor,backgroundImage:(X=m.backgroundImage)!=null?X:O.backgroundImage,opacity:(G=m.opacity)!=null?G:O.opacity,zIndex:m.zIndex!==void 0?m.zIndex+$:O.zIndex,borderRadius:(le=m.borderRadius)!=null?le:O.borderRadius,borderColor:(he=m.borderColor)!=null?he:O.borderColor,borderWidth:(de=m.borderWidth)!=null?de:O.borderWidth,boxShadow:(pe=m.boxShadow)!=null?pe:O.boxShadow,isTraveler:O.isTraveler,transform:m.transform}):void 0,nativeRect:b!==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:w.position==="fixed",clipElements:c,children:M,shaderHooks:I}}function st(n,e){e.size!==0&&e.forEach((t,r)=>{var l,s,a,c;const i=n.get(r);!i||!i.userData.basePosition||(W.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(s=t.borderRadius)!=null?s:(l=i.userData.baseStyles)==null?void 0:l.borderRadius}),i.userData.nativeMesh&&W.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,boxShadow:t.boxShadow,opacity:t.opacity,borderRadius:(c=t.borderRadius)!=null?c:(a=i.userData.baseStyles)==null?void 0:a.borderRadius}))})}class nt{constructor(e,t,r,i){u(this,"target");u(this,"renderer");u(this,"registry");u(this,"isTravelEnabled",!1);u(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new Le(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((l,s)=>{document.querySelector(`[${F.NAME}~='${F.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const c=_e(this.target,l,j,1,0,this.renderer.qualityFactor);c&&this.renderer.syncScene(c,s)}),this.tracker.onStyleChange.add(l=>{st(this.registry,l)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class ot{constructor(){u(this,"store");this.store=new WeakMap}register(e,t){this.store.set(e,t)}get(e){return this.store.get(e)}has(e){return this.store.has(e)}remove(e){this.store.delete(e)}}class at{constructor(e,t){u(this,"renderer");u(this,"syncer");u(this,"target");u(this,"registry");var i,l,s;if(this.target=e,this.registry=new ot,!document.getElementById("mirage-engine-styles")){const a=document.createElement("style");a.id="mirage-engine-styles",a.textContent=`
185
186
  [${J.NAME}="${J.VALUES.HIDE}"] {
186
187
  opacity: 0 !important;
187
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirage-engine",
3
- "version": "0.3.19",
3
+ "version": "0.3.20",
4
4
  "description": "An engine that mirrors HTML DOM elements to a WebGL scene in real-time.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -21,9 +21,9 @@
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "@mirage-engine/painter": "1.0.9",
25
- "@mirage-engine/core": "0.3.19",
26
- "@mirage-engine/sandwich": "0.2.8"
24
+ "@mirage-engine/sandwich": "0.2.8",
25
+ "@mirage-engine/painter": "1.0.10",
26
+ "@mirage-engine/core": "0.3.20"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "three": "^0.160.0"