@mirage-engine/core 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mirage-engine/core
2
2
 
3
+ ## 0.3.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 12fe09b: hot fix
8
+
3
9
  ## 0.3.9
4
10
 
5
11
  ### Patch Changes
@@ -34,7 +34,7 @@ const Re = {
34
34
  INCLUDE_SELF: "include-self",
35
35
  EXCLUDE_SELF: "exclude-self",
36
36
  END: "end"
37
- }, P = {
37
+ }, G = {
38
38
  NAME: "data-mirage-dom",
39
39
  KEY: "mirageDom",
40
40
  VALUES: {
@@ -59,11 +59,11 @@ const Re = {
59
59
  KEY: "mirageTravel",
60
60
  VALUES: xe,
61
61
  MAX_LAYERS: Object.keys(xe).length - 1
62
- }, X = {
62
+ }, z = {
63
63
  NAME: "data-mirage-filter",
64
64
  KEY: "mirageFilter",
65
65
  VALUES: Re
66
- }, Y = {
66
+ }, W = {
67
67
  NAME: "data-mirage-select",
68
68
  KEY: "mirageSelect",
69
69
  VALUES: Re
@@ -192,12 +192,12 @@ class We {
192
192
  this.mutationTimer && (clearTimeout(this.mutationTimer), this.mutationTimer = null), this.cssTimer && (clearTimeout(this.cssTimer), this.cssTimer = null), this.scrollTimer && (clearTimeout(this.scrollTimer), this.scrollTimer = null);
193
193
  }
194
194
  }
195
- const W = 1, K = 2, ct = 0, A = {
195
+ const H = 1, K = 2, ct = 0, U = {
196
196
  BASE: 0,
197
197
  SELECTED: 1,
198
198
  getCaptureLayer: (s) => 31 - s,
199
199
  HIDDEN: 31
200
- }, Ee = Object.values(X.VALUES);
200
+ }, Ee = Object.values(z.VALUES);
201
201
  class Le {
202
202
  /**
203
203
  * Calculates or retrieves the exact alphabetic baseline (in pixels) for the given font.
@@ -257,9 +257,9 @@ class He extends y.MeshBasicMaterial {
257
257
  this.canvas.width !== c || this.canvas.height !== d ? (this.canvas.width = c, this.canvas.height = d) : this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height), this.ctx.setTransform(a, 0, 0, a, 0, 0), this.ctx.font = r.font, this.ctx.fillStyle = r.color, this.ctx.textBaseline = "alphabetic", this.ctx.globalAlpha = 1;
258
258
  const h = this.wrapText(t, i), u = r.lineHeight, p = Le.getBaseline(r.font);
259
259
  h.forEach((f, m) => {
260
- const x = m * u + p;
261
- let S = 0;
262
- r.textAlign === "center" ? S = i / 2 : r.textAlign === "right" && (S = i), this.ctx.textAlign = r.textAlign, this.ctx.fillText(f, S, x);
260
+ const b = m * u + p;
261
+ let R = 0;
262
+ r.textAlign === "center" ? R = i / 2 : r.textAlign === "right" && (R = i), this.ctx.textAlign = r.textAlign, this.ctx.fillText(f, R, b);
263
263
  }), this.map && (this.map.needsUpdate = !0);
264
264
  }
265
265
  dispose() {
@@ -512,43 +512,43 @@ baseColor = blendSrcOver(baseColor, texColor);`, Ce = {
512
512
  baseColorChunk: Je
513
513
  };
514
514
  function Qe(s, e, t, r = null, i) {
515
- var E;
515
+ var x;
516
516
  const l = r !== null || !!s.imageSrc;
517
517
  let n = "";
518
518
  const o = {};
519
519
  if (i != null && i.uniforms)
520
- for (const [b, w] of Object.entries(i.uniforms))
521
- typeof w == "number" ? (n += `uniform float ${b};
522
- `, o[b] = { value: w }) : Array.isArray(w) ? w.length === 2 ? (n += `uniform vec2 ${b};
523
- `, o[b] = { value: new y.Vector2(...w) }) : w.length === 3 ? (n += `uniform vec3 ${b};
524
- `, o[b] = { value: new y.Vector3(...w) }) : w.length === 4 && (n += `uniform vec4 ${b};
525
- `, o[b] = { value: new y.Vector4(...w) }) : (n += `uniform float ${b};
526
- `, o[b] = { value: w });
520
+ for (const [C, w] of Object.entries(i.uniforms))
521
+ typeof w == "number" ? (n += `uniform float ${C};
522
+ `, o[C] = { value: w }) : Array.isArray(w) ? w.length === 2 ? (n += `uniform vec2 ${C};
523
+ `, o[C] = { value: new y.Vector2(...w) }) : w.length === 3 ? (n += `uniform vec3 ${C};
524
+ `, o[C] = { value: new y.Vector3(...w) }) : w.length === 4 && (n += `uniform vec4 ${C};
525
+ `, o[C] = { value: new y.Vector4(...w) }) : (n += `uniform float ${C};
526
+ `, o[C] = { value: w });
527
527
  const a = i !== void 0, c = (l || a ? Te.declChunk : "") + `
528
528
  ` + n, d = `vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
529
529
  `, h = s.isTraveler ? `vec2 resultUv = screenUv;
530
530
  ` : `vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
531
- `, u = l || a ? d + h + ((i == null ? void 0 : i.uvModifier) || "") : "", p = l || a ? Te.baseColorChunk : "", f = (i == null ? void 0 : i.colorModifier) || "", m = Ce.fragmentShader.replace("#INJECT_DECLARATIONS", c).replace("#INJECT_UV_MODIFIER", u).replace("#INJECT_BASE_COLOR", p).replace("#INJECT_COLOR_MODIFIER", f), x = ee(s.backgroundColor), S = ee(s.borderColor), L = {
531
+ `, u = l || a ? d + h + ((i == null ? void 0 : i.uvModifier) || "") : "", p = l || a ? Te.baseColorChunk : "", f = (i == null ? void 0 : i.colorModifier) || "", m = Ce.fragmentShader.replace("#INJECT_DECLARATIONS", c).replace("#INJECT_UV_MODIFIER", u).replace("#INJECT_BASE_COLOR", p).replace("#INJECT_COLOR_MODIFIER", f), b = ee(s.backgroundColor), R = ee(s.borderColor), L = {
532
532
  uSize: { value: new y.Vector2(e, t) },
533
533
  uBgColor: {
534
534
  value: new y.Vector4(
535
- x.color.r,
536
- x.color.g,
537
- x.color.b,
538
- x.alpha
535
+ b.color.r,
536
+ b.color.g,
537
+ b.color.b,
538
+ b.alpha
539
539
  )
540
540
  },
541
541
  uBorderColor: {
542
542
  value: new y.Vector4(
543
- S.color.r,
544
- S.color.g,
545
- S.color.b,
546
- S.alpha
543
+ R.color.r,
544
+ R.color.g,
545
+ R.color.b,
546
+ R.alpha
547
547
  )
548
548
  },
549
549
  uBorderRadius: { value: new y.Vector4(0, 0, 0, 0) },
550
550
  uBorderWidth: { value: J(s.borderWidth) },
551
- uOpacity: { value: (E = s.opacity) != null ? E : 1 },
551
+ uOpacity: { value: (x = s.opacity) != null ? x : 1 },
552
552
  uTexture: { value: null },
553
553
  uTextureRepeat: { value: new y.Vector2(1, 1) },
554
554
  uTextureOffset: { value: new y.Vector2(0, 0) },
@@ -696,7 +696,7 @@ function Me(s, e, t = 0) {
696
696
  const r = e.split("/")[0].trim().split(/\s+/), i = J(r[0], t), l = J((a = r[1]) != null ? a : r[0], t), n = J((c = r[2]) != null ? c : r[0], t), o = J((h = (d = r[3]) != null ? d : r[1]) != null ? h : r[0], t);
697
697
  s.set(i, l, n, o);
698
698
  }
699
- const z = {
699
+ const V = {
700
700
  create(s, e, t, r, i, l = 2, n = null, o) {
701
701
  return s === "BOX" ? Qe(
702
702
  e,
@@ -827,7 +827,7 @@ class tt {
827
827
  var o, a, c, d, h;
828
828
  this.target = e, this.mountContainer = r, this.registry = i, this.mode = (o = t.mode) != null ? o : "overlay", this.canvasSize = (a = t.canvasSize) != null ? a : "viewport", this.clipArea = (c = t.travelerClipArea) != null ? c : 1, this.targetLayer = (d = t.layer) != null ? d : "base", this.textureManager = new et((u, p) => {
829
829
  const f = this.registry.get(u);
830
- f && f.material instanceof y.ShaderMaterial && z.forceUpdateUniforms(f.material, { texture: p });
830
+ f && f.material instanceof y.ShaderMaterial && V.forceUpdateUniforms(f.material, { texture: p });
831
831
  }, this.isViewport), this.canvas = document.createElement("canvas"), this.scene = new y.Scene(), this.targetRect = this.target.getBoundingClientRect();
832
832
  const l = this.isViewport ? window.innerWidth + this.overscan * 2 : this.targetRect.width, n = this.isViewport ? window.innerHeight + this.overscan * 2 : this.targetRect.height;
833
833
  this.camera = new y.OrthographicCamera(
@@ -849,7 +849,7 @@ class tt {
849
849
  return this.mode === "overlay" && this.canvasSize === "viewport";
850
850
  }
851
851
  getSceneLayer() {
852
- return typeof this.targetLayer == "number" ? this.targetLayer : this.targetLayer === "selected" ? A.SELECTED : A.BASE;
852
+ return typeof this.targetLayer == "number" ? this.targetLayer : this.targetLayer === "selected" ? U.SELECTED : U.BASE;
853
853
  }
854
854
  createRenderTarget() {
855
855
  for (let e = 0; e < O.MAX_LAYERS; e++) {
@@ -899,12 +899,12 @@ class tt {
899
899
  updateUniforms(e, t) {
900
900
  const r = this.registry.get(e);
901
901
  r && (r.traverse((i) => {
902
- i.isMesh && i.material && z.forceUpdateUniforms(
902
+ i.isMesh && i.material && V.forceUpdateUniforms(
903
903
  i.material,
904
904
  t
905
905
  );
906
906
  }), r.userData.nativeMesh && r.userData.nativeMesh.traverse((i) => {
907
- i.isMesh && i.material && z.forceUpdateUniforms(
907
+ i.isMesh && i.material && V.forceUpdateUniforms(
908
908
  i.material,
909
909
  t
910
910
  );
@@ -944,7 +944,7 @@ class tt {
944
944
  let t = this.registry.get(e.element);
945
945
  const r = JSON.stringify(e.shaderHooks || null);
946
946
  if (t && t.userData.shaderHash !== r && (this.scene.remove(t), t.geometry.dispose(), t.material instanceof y.Material && t.material.dispose(), this.registry.remove(e.element), t = void 0), !t) {
947
- const n = new y.PlaneGeometry(1, 1), o = e.isTraveler ? (i = this.renderTargets[e.captureLayer - 2]) == null ? void 0 : i.texture : this.textureManager.get(e.element), a = z.create(
947
+ const n = new y.PlaneGeometry(1, 1), o = e.isTraveler ? (i = this.renderTargets[e.captureLayer - 2]) == null ? void 0 : i.texture : this.textureManager.get(e.element), a = V.create(
948
948
  "BOX",
949
949
  e.styles,
950
950
  "",
@@ -981,27 +981,27 @@ class tt {
981
981
  e.children.filter(
982
982
  (f) => f.name.startsWith("TEXT_CHILD")
983
983
  ).forEach((f) => {
984
- var x;
984
+ var b;
985
985
  const m = f;
986
- (x = m.material.map) == null || x.dispose(), m.geometry.dispose(), e.remove(m);
986
+ (b = m.material.map) == null || b.dispose(), m.geometry.dispose(), e.remove(m);
987
987
  });
988
988
  const h = t.rect, u = h.x + h.width / 2, p = h.y + h.height / 2;
989
989
  i.forEach((f, m) => {
990
- const x = z.create(
990
+ const b = V.create(
991
991
  "TEXT",
992
992
  l,
993
993
  f.text,
994
994
  f.rect.width,
995
995
  f.rect.height,
996
996
  this.qualityFactor
997
- ), S = new y.PlaneGeometry(1, 1), L = new y.Mesh(S, x);
997
+ ), R = new y.PlaneGeometry(1, 1), L = new y.Mesh(R, b);
998
998
  L.name = `TEXT_CHILD_${m}`;
999
- const T = t.rect.width === 0 ? 1 : f.rect.width / t.rect.width, E = t.rect.height === 0 ? 1 : f.rect.height / t.rect.height;
1000
- L.scale.set(T, E, 1);
1001
- const b = f.rect.x + f.rect.width / 2, w = f.rect.y + f.rect.height / 2, I = b - u, U = -(w - p);
999
+ const T = t.rect.width === 0 ? 1 : f.rect.width / t.rect.width, x = t.rect.height === 0 ? 1 : f.rect.height / t.rect.height;
1000
+ L.scale.set(T, x, 1);
1001
+ const C = f.rect.x + f.rect.width / 2, w = f.rect.y + f.rect.height / 2, S = C - u, M = -(w - p);
1002
1002
  L.position.set(
1003
- t.rect.width === 0 ? 0 : I / t.rect.width,
1004
- t.rect.height === 0 ? 0 : U / t.rect.height,
1003
+ t.rect.width === 0 ? 0 : S / t.rect.width,
1004
+ t.rect.height === 0 ? 0 : M / t.rect.height,
1005
1005
  5e-3
1006
1006
  ), e.add(L);
1007
1007
  }), e.userData.textChildStyleHash = n;
@@ -1009,21 +1009,21 @@ class tt {
1009
1009
  e.children.forEach((d) => {
1010
1010
  if (!d.name.startsWith("TEXT_CHILD"))
1011
1011
  return;
1012
- const h = d, u = t.visibility & W ? A.BASE : A.HIDDEN;
1013
- if (h.layers.set(u), t.visibility & K && h.layers.enable(A.SELECTED), t.visibility & W)
1012
+ const h = d, u = t.visibility & H ? U.BASE : U.HIDDEN;
1013
+ if (h.layers.set(u), t.visibility & K && h.layers.enable(U.SELECTED), t.visibility & H)
1014
1014
  if (!r && t.nativeLayer !== void 0 && t.nativeStyles !== void 0)
1015
1015
  for (let p = t.captureLayer; p < t.nativeLayer; p++)
1016
- h.layers.enable(A.getCaptureLayer(p));
1016
+ h.layers.enable(U.getCaptureLayer(p));
1017
1017
  else if (r && t.nativeLayer !== void 0)
1018
1018
  for (let p = Math.max(t.captureLayer, t.nativeLayer); p <= O.MAX_LAYERS + 1; p++)
1019
- h.layers.enable(A.getCaptureLayer(p));
1019
+ h.layers.enable(U.getCaptureLayer(p));
1020
1020
  else
1021
1021
  for (let p = t.captureLayer; p <= O.MAX_LAYERS + 1; p++)
1022
- h.layers.enable(A.getCaptureLayer(p));
1022
+ h.layers.enable(U.getCaptureLayer(p));
1023
1023
  });
1024
1024
  }
1025
1025
  updateMeshProperties(e, t) {
1026
- var T, E, b;
1026
+ var T, x, C;
1027
1027
  const { rect: r, styles: i } = t, l = this.renderer.getPixelRatio(), n = this.renderer.domElement.width / l, o = this.renderer.domElement.height / l;
1028
1028
  e.material = e.userData.baseMaterial, e.scale.set(r.width, r.height, 1), e.userData.domRect = {
1029
1029
  x: r.x,
@@ -1038,8 +1038,8 @@ class tt {
1038
1038
  if (this.isViewport)
1039
1039
  h = r.x - window.innerWidth / 2 + r.width / 2, u = -r.y + window.innerHeight / 2 - r.height / 2;
1040
1040
  else {
1041
- const w = r.x - c, I = r.y - d;
1042
- h = w - n / 2 + r.width / 2, u = -I + o / 2 - r.height / 2;
1041
+ const w = r.x - c, S = r.y - d;
1042
+ h = w - n / 2 + r.width / 2, u = -S + o / 2 - r.height / 2;
1043
1043
  }
1044
1044
  e.position.set(
1045
1045
  h,
@@ -1048,13 +1048,13 @@ class tt {
1048
1048
  );
1049
1049
  const p = r.x, f = r.y;
1050
1050
  e.userData.basePosition = { x: h, y: u }, e.userData.originalBasePosition = { x: h, y: u }, e.userData.baseSize = { width: r.width, height: r.height }, e.userData.baseDOM = { x: p, y: f }, e.userData.isFixed = t.isFixed, e.userData.initialScroll = { x: window.scrollX, y: window.scrollY };
1051
- const m = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, x = window.getComputedStyle(m);
1052
- let S = 0, L = 0;
1053
- if (x.transform && x.transform !== "none") {
1054
- const w = new DOMMatrix(x.transform);
1055
- S = w.m41, L = w.m42;
1051
+ const m = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, b = window.getComputedStyle(m);
1052
+ let R = 0, L = 0;
1053
+ if (b.transform && b.transform !== "none") {
1054
+ const w = new DOMMatrix(b.transform);
1055
+ R = w.m41, L = w.m42;
1056
1056
  }
1057
- if (e.userData.baseTransform = { x: S, y: L }, delete e.userData.originRatioX, delete e.userData.originRatioY, z.update(
1057
+ if (e.userData.baseTransform = { x: R, y: L }, delete e.userData.originRatioX, delete e.userData.originRatioY, V.update(
1058
1058
  e.userData.baseMaterial,
1059
1059
  "BOX",
1060
1060
  i,
@@ -1065,31 +1065,31 @@ class tt {
1065
1065
  t.isTraveler ? (T = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : T.texture : this.textureManager.get(t.element)
1066
1066
  ), t.nativeStyles && t.nativeRect) {
1067
1067
  if (!e.userData.nativeMesh) {
1068
- const B = z.create(
1068
+ const k = V.create(
1069
1069
  "BOX",
1070
1070
  t.nativeStyles,
1071
1071
  "",
1072
1072
  t.nativeRect.width,
1073
1073
  t.nativeRect.height,
1074
1074
  this.qualityFactor,
1075
- t.isTraveler ? (E = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : E.texture : this.textureManager.get(t.element),
1075
+ t.isTraveler ? (x = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : x.texture : this.textureManager.get(t.element),
1076
1076
  t.shaderHooks
1077
- ), G = new y.Mesh(e.geometry, B);
1078
- t.type === "TEXT" && (G.name = "BG_MESH"), this.scene.add(G), e.userData.nativeMesh = G;
1077
+ ), _ = new y.Mesh(e.geometry, k);
1078
+ t.type === "TEXT" && (_.name = "BG_MESH"), this.scene.add(_), e.userData.nativeMesh = _;
1079
1079
  }
1080
1080
  const w = e.userData.nativeMesh;
1081
- let I, U;
1081
+ let S, M;
1082
1082
  if (this.isViewport)
1083
- I = t.nativeRect.x - window.innerWidth / 2 + t.nativeRect.width / 2, U = -t.nativeRect.y + window.innerHeight / 2 - t.nativeRect.height / 2;
1083
+ S = t.nativeRect.x - window.innerWidth / 2 + t.nativeRect.width / 2, M = -t.nativeRect.y + window.innerHeight / 2 - t.nativeRect.height / 2;
1084
1084
  else {
1085
- const B = t.nativeRect.x - c, G = t.nativeRect.y - d;
1086
- I = B - n / 2 + t.nativeRect.width / 2, U = -G + o / 2 - t.nativeRect.height / 2;
1085
+ const k = t.nativeRect.x - c, _ = t.nativeRect.y - d;
1086
+ S = k - n / 2 + t.nativeRect.width / 2, M = -_ + o / 2 - t.nativeRect.height / 2;
1087
1087
  }
1088
1088
  w.scale.set(t.nativeRect.width, t.nativeRect.height, 1), w.position.set(
1089
- I,
1090
- U,
1089
+ S,
1090
+ M,
1091
1091
  t.nativeStyles.zIndex + this.renderOrder * a
1092
- ), z.update(
1092
+ ), V.update(
1093
1093
  w.material,
1094
1094
  "BOX",
1095
1095
  t.nativeStyles,
@@ -1097,24 +1097,24 @@ class tt {
1097
1097
  t.nativeRect.width,
1098
1098
  t.nativeRect.height,
1099
1099
  this.qualityFactor,
1100
- t.isTraveler ? (b = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : b.texture : this.textureManager.get(t.element)
1100
+ t.isTraveler ? (C = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : C.texture : this.textureManager.get(t.element)
1101
1101
  );
1102
1102
  } else
1103
1103
  e.userData.nativeMesh && (this.scene.remove(e.userData.nativeMesh), e.userData.nativeMesh.material instanceof y.Material && e.userData.nativeMesh.material.dispose(), delete e.userData.nativeMesh);
1104
1104
  }
1105
1105
  updateMeshLayers(e, t) {
1106
- const r = t.visibility & W ? A.BASE : A.HIDDEN;
1107
- if (e.layers.set(r), t.visibility & K && e.layers.enable(A.SELECTED), e.userData.nativeMesh && t.nativeLayer !== void 0) {
1106
+ const r = t.visibility & H ? U.BASE : U.HIDDEN;
1107
+ if (e.layers.set(r), t.visibility & K && e.layers.enable(U.SELECTED), e.userData.nativeMesh && t.nativeLayer !== void 0) {
1108
1108
  const i = e.userData.nativeMesh;
1109
- if (i.layers.set(A.HIDDEN), t.visibility & W) {
1109
+ if (i.layers.set(U.HIDDEN), t.visibility & H) {
1110
1110
  for (let l = t.captureLayer; l < t.nativeLayer; l++)
1111
- e.layers.enable(A.getCaptureLayer(l));
1111
+ e.layers.enable(U.getCaptureLayer(l));
1112
1112
  for (let l = Math.max(t.captureLayer, t.nativeLayer); l <= O.MAX_LAYERS + 1; l++)
1113
- i.layers.enable(A.getCaptureLayer(l));
1113
+ i.layers.enable(U.getCaptureLayer(l));
1114
1114
  }
1115
- } else if (t.visibility & W)
1115
+ } else if (t.visibility & H)
1116
1116
  for (let i = t.captureLayer; i <= O.MAX_LAYERS + 1; i++)
1117
- e.layers.enable(A.getCaptureLayer(i));
1117
+ e.layers.enable(U.getCaptureLayer(i));
1118
1118
  }
1119
1119
  captureRenderTarget(e, t, r) {
1120
1120
  if (e.size === 0 || !r)
@@ -1127,8 +1127,8 @@ class tt {
1127
1127
  const h = (n.x + 1) / 2 * o, u = (n.y + 1) / 2 * a;
1128
1128
  let p = 0, f = 1;
1129
1129
  typeof this.clipArea == "number" ? f = this.clipArea : this.clipArea.endsWith("%") ? f = parseFloat(this.clipArea) / 100 : this.clipArea.endsWith("px") && (p = parseFloat(this.clipArea));
1130
- const m = d.scale.x * f + 0.5, x = d.scale.y * f + 0.5, S = h - m / 2, L = u - x / 2, T = (S * this.qualityFactor - p) / c, E = (L * this.qualityFactor - p) / c, b = (m * this.qualityFactor + p * 2) / c, w = (x * this.qualityFactor + p * 2) / c;
1131
- this.renderer.setScissor(T, E, b, w), this.renderer.render(this.scene, this.camera);
1130
+ const m = d.scale.x * f + 0.5, b = d.scale.y * f + 0.5, R = h - m / 2, L = u - b / 2, T = (R * this.qualityFactor - p) / c, x = (L * this.qualityFactor - p) / c, C = (m * this.qualityFactor + p * 2) / c, w = (b * this.qualityFactor + p * 2) / c;
1131
+ this.renderer.setScissor(T, x, C, w), this.renderer.render(this.scene, this.camera);
1132
1132
  }
1133
1133
  this.renderer.setScissorTest(!1), this.renderer.autoClear = !0, this.renderer.setRenderTarget(null), this.camera.layers.set(this.getSceneLayer()), this.renderer.setClearColor(i, l);
1134
1134
  }
@@ -1137,7 +1137,7 @@ class tt {
1137
1137
  const t = e + 1;
1138
1138
  this.captureRenderTarget(
1139
1139
  this.travelersByLayer[e],
1140
- A.getCaptureLayer(t),
1140
+ U.getCaptureLayer(t),
1141
1141
  this.renderTargets[e]
1142
1142
  );
1143
1143
  }
@@ -1173,28 +1173,40 @@ class tt {
1173
1173
  const p = c.x - e, f = c.y - t;
1174
1174
  h = p - i / 2 + c.width / 2, u = -f + l / 2 - c.height / 2;
1175
1175
  }
1176
- if (o.position.setX(h), o.position.setY(u), o.scale.set(c.width, c.height, 1), o.updateMatrixWorld(), o.material instanceof y.ShaderMaterial && z.forceUpdateUniforms(o.material, {
1176
+ if (o.position.setX(h), o.position.setY(u), o.scale.set(c.width, c.height, 1), o.updateMatrixWorld(), o.material instanceof y.ShaderMaterial && V.forceUpdateUniforms(o.material, {
1177
1177
  width: c.width,
1178
1178
  height: c.height
1179
1179
  }), o.userData.nativeMesh) {
1180
1180
  const p = o.userData.nativeMesh;
1181
- let f = c.width, m = c.height, x = h, S = u;
1181
+ let f = c.width, m = c.height, b = h, R = u;
1182
1182
  if (o.userData.nativeTransform) {
1183
1183
  const L = o.userData.nativeTransform, T = L.match(/scale\(([\d.]+%?)\)/);
1184
1184
  if (T) {
1185
- let b = parseFloat(T[1]);
1186
- T[1].includes("%") && (b /= 100), f *= b, m *= b;
1185
+ let S = parseFloat(T[1]);
1186
+ T[1].includes("%") && (S /= 100), f *= S, m *= S;
1187
1187
  }
1188
- const E = L.match(/translate\(([^,]+),\s*([^)]+)\)/);
1189
- if (E) {
1190
- const b = E[1].trim(), w = E[2].trim();
1191
- let I = parseFloat(b);
1192
- b.includes("%") && (I = I / 100 * c.width);
1193
- let U = parseFloat(w);
1194
- w.includes("%") && (U = U / 100 * c.height), x += I, S -= U;
1188
+ const x = L.match(/translate\(([^,]+),\s*([^)]+)\)/);
1189
+ if (x) {
1190
+ const S = x[1].trim(), M = x[2].trim();
1191
+ let k = parseFloat(S);
1192
+ S.includes("%") && (k = k / 100 * c.width);
1193
+ let _ = parseFloat(M);
1194
+ M.includes("%") && (_ = _ / 100 * c.height), b += k, R -= _;
1195
+ }
1196
+ const C = L.match(/translateX\(([^)]+)\)/);
1197
+ if (C) {
1198
+ const S = C[1].trim();
1199
+ let M = parseFloat(S);
1200
+ S.includes("%") && (M = M / 100 * c.width), b += M;
1201
+ }
1202
+ const w = L.match(/translateY\(([^)]+)\)/);
1203
+ if (w) {
1204
+ const S = w[1].trim();
1205
+ let M = parseFloat(S);
1206
+ S.includes("%") && (M = M / 100 * c.height), R -= M;
1195
1207
  }
1196
1208
  }
1197
- p.position.setX(x), p.position.setY(S), p.scale.set(f, m, 1), p.updateMatrixWorld();
1209
+ p.position.setX(b), p.position.setY(R), p.scale.set(f, m, 1), p.updateMatrixWorld();
1198
1210
  }
1199
1211
  }
1200
1212
  });
@@ -1298,228 +1310,228 @@ function De(s, e = $ | Z | ze | ce | ie, t, r = 1, i = 0, l = 2, n, o) {
1298
1310
  const v = s;
1299
1311
  if (!v.textContent || !v.textContent.trim())
1300
1312
  return null;
1301
- const M = v.textContent.replace(/\s+/g, " ");
1302
- if (M.length === 0)
1313
+ const A = v.textContent.replace(/\s+/g, " ");
1314
+ if (A.length === 0)
1303
1315
  return null;
1304
- const k = rt(v);
1305
- if (k.length === 0)
1316
+ const B = rt(v);
1317
+ if (B.length === 0)
1306
1318
  return null;
1307
- const _ = v.parentElement, D = _ ? window.getComputedStyle(_) : null;
1308
- if (!D)
1319
+ const N = v.parentElement, I = N ? window.getComputedStyle(N) : null;
1320
+ if (!I)
1309
1321
  return null;
1310
- const V = Math.min(...k.map((C) => C.rect.left)), F = Math.min(...k.map((C) => C.rect.top)), H = Math.max(...k.map((C) => C.rect.left + C.rect.width)), R = Math.max(...k.map((C) => C.rect.top + C.rect.height));
1322
+ const Y = Math.min(...B.map((E) => E.rect.left)), F = Math.min(...B.map((E) => E.rect.top)), P = Math.max(...B.map((E) => E.rect.left + E.rect.width)), D = Math.max(...B.map((E) => E.rect.top + E.rect.height));
1311
1323
  return {
1312
1324
  id: Math.random().toString(36).substring(2, 9),
1313
1325
  type: "TEXT",
1314
1326
  element: v,
1315
1327
  rect: {
1316
- x: V + window.scrollX,
1328
+ x: Y + window.scrollX,
1317
1329
  y: F + window.scrollY,
1318
- width: H - V,
1319
- height: R - F
1330
+ width: P - Y,
1331
+ height: D - F
1320
1332
  },
1321
1333
  styles: {
1322
1334
  backgroundColor: "transparent",
1323
1335
  backgroundImage: "",
1324
- opacity: _ && _.dataset[P.KEY] === P.VALUES.HIDE ? 1 : parseFloat(D.opacity),
1325
- zIndex: (isNaN(parseInt(D.zIndex)) ? 0 : parseInt(D.zIndex)) + i,
1336
+ opacity: N && N.dataset[G.KEY] === G.VALUES.HIDE ? 1 : parseFloat(I.opacity),
1337
+ zIndex: (isNaN(parseInt(I.zIndex)) ? 0 : parseInt(I.zIndex)) + i,
1326
1338
  borderRadius: "0px",
1327
1339
  borderColor: "transparent",
1328
1340
  borderWidth: "0px",
1329
1341
  isTraveler: !1
1330
1342
  },
1331
- textContent: M,
1332
- textLines: k.map((C) => ({
1333
- text: C.text.trim(),
1343
+ textContent: A,
1344
+ textLines: B.map((E) => ({
1345
+ text: E.text.trim(),
1334
1346
  rect: {
1335
- x: C.rect.left + window.scrollX,
1336
- y: C.rect.top + window.scrollY,
1337
- width: C.rect.width,
1338
- height: C.rect.height
1347
+ x: E.rect.left + window.scrollX,
1348
+ y: E.rect.top + window.scrollY,
1349
+ width: E.rect.width,
1350
+ height: E.rect.height
1339
1351
  }
1340
1352
  })),
1341
- textStyles: Se(D),
1353
+ textStyles: Se(I),
1342
1354
  dirtyMask: e,
1343
1355
  visibility: t,
1344
1356
  isTraveler: !1,
1345
1357
  captureLayer: r,
1346
- isFixed: D.position === "fixed",
1358
+ isFixed: I.position === "fixed",
1347
1359
  nativeLayer: n,
1348
1360
  nativeStyles: o ? q(q({
1349
1361
  backgroundColor: "transparent",
1350
1362
  backgroundImage: "",
1351
- opacity: _ && _.dataset[P.KEY] === P.VALUES.HIDE ? 1 : parseFloat(D.opacity),
1352
- zIndex: (isNaN(parseInt(D.zIndex)) ? 0 : parseInt(D.zIndex)) + i,
1363
+ opacity: N && N.dataset[G.KEY] === G.VALUES.HIDE ? 1 : parseFloat(I.opacity),
1364
+ zIndex: (isNaN(parseInt(I.zIndex)) ? 0 : parseInt(I.zIndex)) + i,
1353
1365
  borderRadius: "0px",
1354
1366
  borderColor: "transparent",
1355
1367
  borderWidth: "0px",
1356
1368
  isTraveler: !1
1357
- }, Se(D)), o) : void 0,
1369
+ }, Se(I)), o) : void 0,
1358
1370
  nativeRect: o ? {
1359
- x: V + window.scrollX,
1371
+ x: Y + window.scrollX,
1360
1372
  y: F + window.scrollY,
1361
- width: H - V,
1362
- height: R - F
1373
+ width: P - Y,
1374
+ height: D - F
1363
1375
  } : void 0,
1364
1376
  children: []
1365
1377
  };
1366
1378
  }
1367
1379
  if (s.nodeType !== Node.ELEMENT_NODE)
1368
1380
  return null;
1369
- const a = s, c = a.dataset[X.KEY];
1381
+ const a = s, c = a.dataset[z.KEY];
1370
1382
  let d = t, h = t;
1371
1383
  if (c) {
1372
1384
  const v = new Set(c.split(/\s+/));
1373
- for (const M of v)
1374
- if (!Ee.includes(M))
1385
+ for (const A of v)
1386
+ if (!Ee.includes(A))
1375
1387
  throw new Error(
1376
- `[MirageEngine] Invalid filter token: '${M}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1388
+ `[MirageEngine] Invalid filter token: '${A}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1377
1389
  );
1378
- if (v.has(X.VALUES.END))
1390
+ if (v.has(z.VALUES.END))
1379
1391
  return null;
1380
- if (v.has(X.VALUES.INCLUDE_TREE) && v.has(X.VALUES.EXCLUDE_TREE))
1392
+ if (v.has(z.VALUES.INCLUDE_TREE) && v.has(z.VALUES.EXCLUDE_TREE))
1381
1393
  throw new Error(
1382
1394
  "[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element."
1383
1395
  );
1384
- if (v.has(X.VALUES.INCLUDE_SELF) && v.has(X.VALUES.EXCLUDE_SELF))
1396
+ if (v.has(z.VALUES.INCLUDE_SELF) && v.has(z.VALUES.EXCLUDE_SELF))
1385
1397
  throw new Error(
1386
1398
  "[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element."
1387
1399
  );
1388
- v.has(X.VALUES.INCLUDE_TREE) ? d = d | W : v.has(X.VALUES.EXCLUDE_TREE) && (d = d & ~W), h = d, v.has(X.VALUES.INCLUDE_SELF) ? h = h | W : v.has(X.VALUES.EXCLUDE_SELF) && (h = h & ~W);
1400
+ v.has(z.VALUES.INCLUDE_TREE) ? d = d | H : v.has(z.VALUES.EXCLUDE_TREE) && (d = d & ~H), h = d, v.has(z.VALUES.INCLUDE_SELF) ? h = h | H : v.has(z.VALUES.EXCLUDE_SELF) && (h = h & ~H);
1389
1401
  }
1390
- const u = a.dataset[Y.KEY];
1402
+ const u = a.dataset[W.KEY];
1391
1403
  if (u) {
1392
1404
  const v = new Set(u.split(/\s+/));
1393
- for (const M of v)
1394
- if (!Ee.includes(M))
1405
+ for (const A of v)
1406
+ if (!Ee.includes(A))
1395
1407
  throw new Error(
1396
- `[MirageEngine] Invalid select token: '${M}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1408
+ `[MirageEngine] Invalid select token: '${A}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1397
1409
  );
1398
- if (v.has(Y.VALUES.END))
1410
+ if (v.has(W.VALUES.END))
1399
1411
  return null;
1400
- if (v.has(Y.VALUES.INCLUDE_TREE) && v.has(Y.VALUES.EXCLUDE_TREE))
1412
+ if (v.has(W.VALUES.INCLUDE_TREE) && v.has(W.VALUES.EXCLUDE_TREE))
1401
1413
  throw new Error(
1402
1414
  "[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element."
1403
1415
  );
1404
- if (v.has(Y.VALUES.INCLUDE_SELF) && v.has(Y.VALUES.EXCLUDE_SELF))
1416
+ if (v.has(W.VALUES.INCLUDE_SELF) && v.has(W.VALUES.EXCLUDE_SELF))
1405
1417
  throw new Error(
1406
1418
  "[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element."
1407
1419
  );
1408
- v.has(Y.VALUES.INCLUDE_TREE) ? d = d | K : v.has(Y.VALUES.EXCLUDE_TREE) && (d = d & ~K), h = d, v.has(Y.VALUES.INCLUDE_SELF) ? h = h | K : v.has(Y.VALUES.EXCLUDE_SELF) && (h = h & ~K);
1420
+ v.has(W.VALUES.INCLUDE_TREE) ? d = d | K : v.has(W.VALUES.EXCLUDE_TREE) && (d = d & ~K), h = d, v.has(W.VALUES.INCLUDE_SELF) ? h = h | K : v.has(W.VALUES.EXCLUDE_SELF) && (h = h & ~K);
1409
1421
  }
1410
1422
  const p = a.dataset[O.KEY];
1411
- let f = !1, m = o ? q({}, o) : {}, x = n;
1423
+ let f = !1, m = o ? q({}, o) : {}, b = n;
1412
1424
  if (p) {
1413
1425
  let v = 1;
1414
- const M = p.indexOf("{"), k = p.lastIndexOf("}");
1415
- let _ = p;
1416
- if (M !== -1 && k !== -1 && k > M) {
1417
- _ = p.substring(0, M).trim();
1418
- const R = p.substring(M, k + 1);
1426
+ const A = p.indexOf("{"), B = p.lastIndexOf("}");
1427
+ let N = p;
1428
+ if (A !== -1 && B !== -1 && B > A) {
1429
+ N = p.substring(0, A).trim();
1430
+ const D = p.substring(A, B + 1);
1419
1431
  try {
1420
- m = new Function("return " + R)();
1421
- } catch (C) {
1432
+ m = new Function("return " + D)();
1433
+ } catch (E) {
1422
1434
  console.warn(
1423
- `[MirageEngine] Failed to parse travel styles JSON: ${R}`
1435
+ `[MirageEngine] Failed to parse travel styles JSON: ${D}`
1424
1436
  );
1425
1437
  }
1426
1438
  }
1427
- const D = _.split(/\s+/);
1428
- let V = !1;
1429
- const F = D.indexOf(O.VALUES.TRAVELER);
1439
+ const I = N.split(/\s+/);
1440
+ let Y = !1;
1441
+ const F = I.indexOf(O.VALUES.TRAVELER);
1430
1442
  if (F !== -1) {
1431
- f = !0, V = !0;
1432
- const R = D[F + 1];
1433
- if (R && !isNaN(parseInt(R, 10)))
1434
- v = parseInt(R, 10);
1443
+ f = !0, Y = !0;
1444
+ const D = I[F + 1];
1445
+ if (D && !isNaN(parseInt(D, 10)))
1446
+ v = parseInt(D, 10);
1435
1447
  else {
1436
- const C = D.find((j) => !isNaN(parseInt(j, 10)));
1437
- C && (v = parseInt(C, 10));
1448
+ const E = I.find((j) => !isNaN(parseInt(j, 10)));
1449
+ E && (v = parseInt(E, 10));
1438
1450
  }
1439
1451
  }
1440
- const H = D.indexOf(O.VALUES.NATIVE);
1441
- if (H !== -1) {
1442
- const R = D[H + 1];
1443
- if (R && !isNaN(parseInt(R, 10)))
1444
- x = parseInt(R, 10);
1452
+ const P = I.indexOf(O.VALUES.NATIVE);
1453
+ if (P !== -1) {
1454
+ const D = I[P + 1];
1455
+ if (D && !isNaN(parseInt(D, 10)))
1456
+ b = parseInt(D, 10);
1445
1457
  else if (!f) {
1446
- const C = D.find((j) => !isNaN(parseInt(j, 10)));
1447
- C && (x = parseInt(C, 10));
1458
+ const E = I.find((j) => !isNaN(parseInt(j, 10)));
1459
+ E && (b = parseInt(E, 10));
1448
1460
  }
1449
1461
  }
1450
- if (V) {
1451
- const R = v + 1;
1452
- if (R < r)
1462
+ if (Y) {
1463
+ const D = v + 1;
1464
+ if (D < r)
1453
1465
  throw new Error(
1454
1466
  `[MirageEngine] Traveler layer (${v}) cannot be smaller than inherited capture layer (${r - 1}).`
1455
1467
  );
1456
- r = Math.min(R, O.MAX_LAYERS + 1);
1468
+ r = Math.min(D, O.MAX_LAYERS + 1);
1457
1469
  }
1458
1470
  }
1459
- const S = a.dataset[Xe.KEY];
1471
+ const R = a.dataset[Xe.KEY];
1460
1472
  let L;
1461
- S && (L = JSON.parse(S));
1462
- const T = a.getBoundingClientRect(), E = window.getComputedStyle(a);
1463
- if (T.width === 0 || T.height === 0 || E.display === "none")
1473
+ R && (L = JSON.parse(R));
1474
+ const T = a.getBoundingClientRect(), x = window.getComputedStyle(a);
1475
+ if (T.width === 0 || T.height === 0 || x.display === "none")
1464
1476
  return null;
1465
- let b = a.getAttribute("data-mid");
1466
- b || (b = Math.random().toString(36).substring(2, 11), a.setAttribute("data-mid", b));
1467
- const w = parseInt(E.zIndex), I = (isNaN(w) ? 0 : w) + i;
1468
- let U;
1477
+ let C = a.getAttribute("data-mid");
1478
+ C || (C = Math.random().toString(36).substring(2, 11), a.setAttribute("data-mid", C));
1479
+ const w = parseInt(x.zIndex), S = (isNaN(w) ? 0 : w) + i;
1480
+ let M;
1469
1481
  if (a.tagName === "IMG")
1470
- U = a.src;
1482
+ M = a.src;
1471
1483
  else if (a.tagName.toLowerCase() === "svg") {
1472
- const v = a.cloneNode(!0), M = m == null ? void 0 : m.color, k = m == null ? void 0 : m.fill, _ = m == null ? void 0 : m.stroke, D = m == null ? void 0 : m.opacity, V = (C, j) => {
1473
- const N = window.getComputedStyle(C), Q = j, ke = N.fill === N.color, Ue = N.stroke === N.color, se = k || (ke ? M : void 0) || N.fill;
1484
+ const v = a.cloneNode(!0), A = m == null ? void 0 : m.color, B = m == null ? void 0 : m.fill, N = m == null ? void 0 : m.stroke, I = m == null ? void 0 : m.opacity, Y = (E, j) => {
1485
+ const X = window.getComputedStyle(E), Q = j, ke = X.fill === X.color, Ue = X.stroke === X.color, se = B || (ke ? A : void 0) || X.fill;
1474
1486
  se && se !== "none" && (Q.style.fill = se);
1475
- const ne = _ || (Ue ? M : void 0) || N.stroke;
1476
- ne && ne !== "none" && (Q.style.stroke = ne), N.strokeWidth && N.strokeWidth !== "0px" && (Q.style.strokeWidth = N.strokeWidth);
1477
- const ve = M || N.color;
1487
+ const ne = N || (Ue ? A : void 0) || X.stroke;
1488
+ ne && ne !== "none" && (Q.style.stroke = ne), X.strokeWidth && X.strokeWidth !== "0px" && (Q.style.strokeWidth = X.strokeWidth);
1489
+ const ve = A || X.color;
1478
1490
  ve && (Q.style.color = ve);
1479
- const oe = D || N.opacity;
1491
+ const oe = I || X.opacity;
1480
1492
  oe && oe !== "1" && (Q.style.opacity = oe);
1481
- for (let te = 0; te < C.children.length; te++)
1482
- V(C.children[te], j.children[te]);
1493
+ for (let te = 0; te < E.children.length; te++)
1494
+ Y(E.children[te], j.children[te]);
1483
1495
  };
1484
- V(a, v);
1485
- const F = a.getBoundingClientRect(), H = window.devicePixelRatio * l;
1486
- v.hasAttribute("viewBox") || v.setAttribute("viewBox", `0 0 ${F.width} ${F.height}`), v.setAttribute("width", (F.width * H).toString()), v.setAttribute("height", (F.height * H).toString());
1487
- let R = new XMLSerializer().serializeToString(v);
1488
- R.includes("xmlns=") || (R = R.replace(
1496
+ Y(a, v);
1497
+ const F = a.getBoundingClientRect(), P = window.devicePixelRatio * l;
1498
+ v.hasAttribute("viewBox") || v.setAttribute("viewBox", `0 0 ${F.width} ${F.height}`), v.setAttribute("width", (F.width * P).toString()), v.setAttribute("height", (F.height * P).toString());
1499
+ let D = new XMLSerializer().serializeToString(v);
1500
+ D.includes("xmlns=") || (D = D.replace(
1489
1501
  "<svg",
1490
1502
  '<svg xmlns="http://www.w3.org/2000/svg"'
1491
- )), U = `data:image/svg+xml;utf8,${encodeURIComponent(R)}`;
1492
- } else if (E.backgroundImage && E.backgroundImage !== "none") {
1493
- const v = E.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
1494
- v && (U = v[1]);
1495
- }
1496
- const B = {
1497
- backgroundColor: E.backgroundColor,
1498
- backgroundImage: E.backgroundImage,
1499
- opacity: a.dataset[P.KEY] === P.VALUES.HIDE ? 1 : parseFloat(E.opacity),
1500
- zIndex: I,
1501
- borderRadius: E.borderRadius,
1502
- borderColor: E.borderColor,
1503
- borderWidth: E.borderWidth,
1504
- imageSrc: U,
1503
+ )), M = `data:image/svg+xml;utf8,${encodeURIComponent(D)}`;
1504
+ } else if (x.backgroundImage && x.backgroundImage !== "none") {
1505
+ const v = x.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
1506
+ v && (M = v[1]);
1507
+ }
1508
+ const k = {
1509
+ backgroundColor: x.backgroundColor,
1510
+ backgroundImage: x.backgroundImage,
1511
+ opacity: a.dataset[G.KEY] === G.VALUES.HIDE ? 1 : parseFloat(x.opacity),
1512
+ zIndex: S,
1513
+ borderRadius: x.borderRadius,
1514
+ borderColor: x.borderColor,
1515
+ borderWidth: x.borderWidth,
1516
+ imageSrc: M,
1505
1517
  isTraveler: f
1506
- }, G = B;
1518
+ }, _ = k;
1507
1519
  let Ae, Ie;
1508
1520
  const he = [];
1509
1521
  return a.tagName.toLowerCase() !== "svg" && Array.from(a.childNodes).forEach((v) => {
1510
- const M = v.nodeType === Node.TEXT_NODE ? h : d, k = De(
1522
+ const A = v.nodeType === Node.TEXT_NODE ? h : d, B = De(
1511
1523
  v,
1512
1524
  e,
1513
- M,
1525
+ A,
1514
1526
  r,
1515
- I,
1527
+ S,
1516
1528
  l,
1517
- v.nodeType === Node.TEXT_NODE ? x : void 0,
1529
+ v.nodeType === Node.TEXT_NODE ? b : void 0,
1518
1530
  v.nodeType === Node.TEXT_NODE && Object.keys(m).length > 0 ? m : void 0
1519
1531
  );
1520
- k && he.push(k);
1532
+ B && he.push(B);
1521
1533
  }), {
1522
- id: b,
1534
+ id: C,
1523
1535
  type: "BOX",
1524
1536
  element: a,
1525
1537
  rect: {
@@ -1528,32 +1540,32 @@ function De(s, e = $ | Z | ze | ce | ie, t, r = 1, i = 0, l = 2, n, o) {
1528
1540
  width: T.width,
1529
1541
  height: T.height
1530
1542
  },
1531
- styles: G,
1543
+ styles: _,
1532
1544
  textContent: Ae,
1533
1545
  textStyles: Ie,
1534
1546
  dirtyMask: e,
1535
1547
  visibility: h,
1536
1548
  isTraveler: f,
1537
1549
  captureLayer: r,
1538
- nativeLayer: x,
1539
- nativeStyles: x !== void 0 ? be(q({}, B), {
1540
- backgroundColor: (de = m.backgroundColor) != null ? de : B.backgroundColor,
1541
- backgroundImage: (ue = m.backgroundImage) != null ? ue : B.backgroundImage,
1542
- opacity: (fe = m.opacity) != null ? fe : B.opacity,
1543
- zIndex: m.zIndex !== void 0 ? m.zIndex + I : B.zIndex,
1544
- borderRadius: (ge = m.borderRadius) != null ? ge : B.borderRadius,
1545
- borderColor: (pe = m.borderColor) != null ? pe : B.borderColor,
1546
- borderWidth: (me = m.borderWidth) != null ? me : B.borderWidth,
1547
- isTraveler: B.isTraveler,
1550
+ nativeLayer: b,
1551
+ nativeStyles: b !== void 0 ? be(q({}, k), {
1552
+ backgroundColor: (de = m.backgroundColor) != null ? de : k.backgroundColor,
1553
+ backgroundImage: (ue = m.backgroundImage) != null ? ue : k.backgroundImage,
1554
+ opacity: (fe = m.opacity) != null ? fe : k.opacity,
1555
+ zIndex: m.zIndex !== void 0 ? m.zIndex + S : k.zIndex,
1556
+ borderRadius: (ge = m.borderRadius) != null ? ge : k.borderRadius,
1557
+ borderColor: (pe = m.borderColor) != null ? pe : k.borderColor,
1558
+ borderWidth: (me = m.borderWidth) != null ? me : k.borderWidth,
1559
+ isTraveler: k.isTraveler,
1548
1560
  transform: m.transform
1549
1561
  }) : void 0,
1550
- nativeRect: x !== void 0 ? {
1562
+ nativeRect: b !== void 0 ? {
1551
1563
  x: m.x !== void 0 ? parseFloat(m.x) : T.left + window.scrollX,
1552
1564
  y: m.y !== void 0 ? parseFloat(m.y) : T.top + window.scrollY,
1553
1565
  width: m.width !== void 0 ? parseFloat(m.width) : T.width,
1554
1566
  height: m.height !== void 0 ? parseFloat(m.height) : T.height
1555
1567
  } : void 0,
1556
- isFixed: E.position === "fixed",
1568
+ isFixed: x.position === "fixed",
1557
1569
  children: he,
1558
1570
  shaderHooks: L
1559
1571
  };
@@ -1562,13 +1574,13 @@ function it(s, e) {
1562
1574
  e.size !== 0 && e.forEach((t, r) => {
1563
1575
  var l, n, o, a;
1564
1576
  const i = s.get(r);
1565
- !i || !i.userData.basePosition || (z.forceUpdateUniforms(i.material, {
1577
+ !i || !i.userData.basePosition || (V.forceUpdateUniforms(i.material, {
1566
1578
  backgroundColor: t.backgroundColor,
1567
1579
  backgroundImage: t.backgroundImage,
1568
1580
  opacity: t.opacity,
1569
1581
  borderRadius: (n = t.borderRadius) != null ? n : (l = i.userData.baseStyles) == null ? void 0 : l.borderRadius
1570
1582
  // width and height are no longer updated here, they are updated in syncMeshesByDOM
1571
- }), i.userData.nativeMesh && z.forceUpdateUniforms(i.userData.nativeMesh.material, {
1583
+ }), i.userData.nativeMesh && V.forceUpdateUniforms(i.userData.nativeMesh.material, {
1572
1584
  backgroundColor: t.backgroundColor,
1573
1585
  backgroundImage: t.backgroundImage,
1574
1586
  opacity: t.opacity,
@@ -1590,7 +1602,7 @@ class st {
1590
1602
  const a = De(
1591
1603
  this.target,
1592
1604
  l,
1593
- W,
1605
+ H,
1594
1606
  1,
1595
1607
  0,
1596
1608
  this.renderer.qualityFactor
@@ -1644,7 +1656,7 @@ class lt {
1644
1656
  if (this.target = e, this.registry = new nt(), !document.getElementById("mirage-engine-styles")) {
1645
1657
  const o = document.createElement("style");
1646
1658
  o.id = "mirage-engine-styles", o.textContent = `
1647
- [${P.NAME}="${P.VALUES.HIDE}"] {
1659
+ [${G.NAME}="${G.VALUES.HIDE}"] {
1648
1660
  opacity: 0 !important;
1649
1661
  }
1650
1662
  `, document.head.appendChild(o);
@@ -1702,10 +1714,10 @@ class lt {
1702
1714
  }
1703
1715
  export {
1704
1716
  Ee as ALLOWED_FILTERS,
1705
- P as ATTR_DOM,
1706
- X as ATTR_FILTER,
1717
+ G as ATTR_DOM,
1718
+ z as ATTR_FILTER,
1707
1719
  at as ATTR_SANDWICH,
1708
- Y as ATTR_SELECT,
1720
+ W as ATTR_SELECT,
1709
1721
  Xe as ATTR_SHADER,
1710
1722
  O as ATTR_TRAVEL,
1711
1723
  ce as DIRTY_CONTENT,
@@ -1717,9 +1729,9 @@ export {
1717
1729
  ct as EXCLUDED,
1718
1730
  lt as Engine,
1719
1731
  K as SELECT_LAYER,
1720
- A as THREE_LAYERS,
1732
+ U as THREE_LAYERS,
1721
1733
  xe as TRAVEL_VALUES,
1722
1734
  We as Tracker,
1723
- W as USER_LAYER,
1735
+ H as USER_LAYER,
1724
1736
  Ye as extractFromStyle
1725
1737
  };
@@ -1,5 +1,5 @@
1
- (function(b,S){typeof exports=="object"&&typeof module!="undefined"?S(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],S):(b=typeof globalThis!="undefined"?globalThis:b||self,S(b.MirageEngine={},b.THREE))})(this,function(b,S){"use strict";var at=Object.defineProperty,ct=Object.defineProperties;var lt=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var ht=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var pe=(b,S,D)=>S in b?at(b,S,{enumerable:!0,configurable:!0,writable:!0,value:D}):b[S]=D,Z=(b,S)=>{for(var D in S||(S={}))ht.call(S,D)&&pe(b,D,S[D]);if(Oe)for(var D of Oe(S))dt.call(S,D)&&pe(b,D,S[D]);return b},_e=(b,S)=>ct(b,lt(S));var g=(b,S,D)=>(pe(b,typeof S!="symbol"?S+"":S,D),D);var Be=(b,S,D)=>new Promise((y,re)=>{var V=A=>{try{I(D.next(A))}catch(B){re(B)}},ie=A=>{try{I(D.throw(A))}catch(B){re(B)}},I=A=>A.done?y(A.value):Promise.resolve(A.value).then(V,ie);I((D=D.apply(b,S)).next())});function D(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const y=D(S),re={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},V={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},ie={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"},I={NAME:"data-mirage-travel",KEY:"mirageTravel",VALUES:ie,MAX_LAYERS:Object.keys(ie).length-1},A={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:re},B={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:re},me={NAME:"data-mirage-shader",KEY:"mirageShader"},Fe={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},se=0,$=1,Q=2,ve=4,ne=8,ce=16;function Ne(s){const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return e?{r:parseInt(e[1])/255,g:parseInt(e[2])/255,b:parseInt(e[3])/255}:{r:1,g:1,b:1}}function ye(s){const e={};if(s.opacity&&(e.opacity=parseFloat(s.opacity)),s.backgroundColor&&s.backgroundColor!=="rgba(0, 0, 0, 0)"){const t=Ne(s.backgroundColor);e.backgroundColor=[t.r,t.g,t.b]}if(s.backgroundImage?e.backgroundImage=s.backgroundImage:s.background&&(e.backgroundImage=s.background),s.borderRadius&&(e.borderRadius=parseFloat(s.borderRadius)),s.width&&(e.width=parseFloat(s.width)),s.height&&(e.height=parseFloat(s.height)),s.transform&&s.transform!=="none"){const t=new DOMMatrix(s.transform);e.x=t.m41,e.y=t.m42,e.z=t.m43}return e}class be{constructor(e,t){g(this,"target");g(this,"observer");g(this,"pendingDeletions",new Set);g(this,"pendingStyles",new Map);g(this,"isDomDirty",!1);g(this,"isRunning",!1);g(this,"pendingMask",se);g(this,"mutationTimer",null);g(this,"cssTimer",null);g(this,"resizeConfig");g(this,"resizeTimer",null);g(this,"isResizing",!1);g(this,"lastScrollX",0);g(this,"lastScrollY",0);g(this,"scrollTimer",null);g(this,"onBeforeRender",new Set);g(this,"onLayoutChange",new Set);g(this,"onStyleChange",new Set);g(this,"onScrollChange",new Set);g(this,"onRender",new Set);g(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=$|Q,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});g(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)});g(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=se);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|=$,this.isDomDirty=!0,this.scrollTimer=null},150)),this.pendingStyles.size>0&&(this.onStyleChange.forEach(r=>r(this.pendingStyles)),this.pendingStyles.clear()),this.onRender.forEach(r=>r()),requestAnimationFrame(this.renderLoop)});var i,c;this.target=e;const r=(i=t.resizeDebounce)!=null?i:!0;r===!1?this.resizeConfig={enabled:!1,delay:0}:r===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(c=r.delay)!=null?c:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(n=>{let o=se;for(const a of n)if(a.type==="childList")o|=ne,a.removedNodes.length>0&&a.removedNodes.forEach(l=>{l instanceof HTMLElement&&this.pendingDeletions.add(l)});else if(a.type==="attributes")if(a.attributeName==="style"){o|=$|Q;const l=a.target,d=ye(l.style);this.pendingStyles.set(l,d)}else a.attributeName==="class"?o|=$|Q:a.attributeName&&a.attributeName.startsWith("data-")&&(o|=$|Q,a.attributeName.startsWith("data-mirage")&&(o|=ne));else a.type==="characterData"&&(o|=ce|$);if(o!==se){if(this.pendingMask|=o,o&ne){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 W=1,K=2,Xe=0,_={BASE:0,SELECTED:1,getCaptureLayer:s=>31-s,HIDDEN:31},he=Object.values(A.VALUES);class Ee{static getBaseline(e){if(this.cache.has(e))return this.cache.get(e);const t=this.calculateBaselineFromDOM(e);return this.cache.set(e,t),t}static calculateBaselineFromDOM(e){if(typeof document=="undefined")return 0;const t=document.createElement("div"),r=document.createElement("span"),i=document.createElement("img");t.style.visibility="hidden",t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.font=e,t.style.margin="0",t.style.padding="0",t.style.border="none",r.style.margin="0",r.style.padding="0",r.style.border="none",r.style.lineHeight="normal",i.width=1,i.height=1,i.style.verticalAlign="baseline",r.appendChild(document.createTextNode("Hidden Text")),t.appendChild(r),t.appendChild(i),document.body.appendChild(t);const c=i.offsetTop-r.offsetTop;return document.body.removeChild(t),c}}g(Ee,"cache",new Map);class ze extends y.MeshBasicMaterial{constructor(t,r,i,c,n=2){super({transparent:!0,side:y.FrontSide,color:16777215});g(this,"canvas");g(this,"ctx");g(this,"qualityFactor");if(this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("[Mirage] Failed to create canvas context");this.qualityFactor=n,this.map=new y.CanvasTexture(this.canvas),this.map.colorSpace=y.LinearSRGBColorSpace,this.map.minFilter=y.LinearFilter,this.map.magFilter=y.LinearFilter,this.updateText(t,r,i,c)}wrapText(t,r){const i=t.split(`
2
- `),c=[];return i.forEach(n=>{const o=n.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(o.length===0){c.push("");return}let a=o[0];for(let l=1;l<o.length;l++){const d=o[l];this.ctx.measureText(a+d).width<=r+2?a+=d:(a&&c.push(a),a=d.trimStart())}a&&c.push(a)}),c}updateText(t,r,i,c,n){n!==void 0&&(this.qualityFactor=n);const a=(window.devicePixelRatio||1)*this.qualityFactor,l=i*a,d=c*a;this.canvas.width!==l||this.canvas.height!==d?(this.canvas.width=l,this.canvas.height=d):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(a,0,0,a,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),u=r.lineHeight,p=Ee.getBaseline(r.font);h.forEach((f,m)=>{const T=m*u+p;let L=0;r.textAlign==="center"?L=i/2:r.textAlign==="right"&&(L=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(f,L,T)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function ee(s,e=0){if(typeof s=="number")return s;const t=parseFloat(s)||0;return typeof s=="string"&&s.includes("%")?t/100*e:t}function oe(s){if(!s||s==="transparent")return{color:new y.Color(16777215),alpha:0};const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),c=e[4]!==void 0?parseFloat(e[4]):1;return{color:new y.Color(`rgb(${t}, ${r}, ${i})`),alpha:c}}return{color:new y.Color(s),alpha:1}}function Ye(s){const e=[];let t="",r=0;for(let i=0;i<s.length;i++){const c=s[i];if(c==="(")r++;else if(c===")")r--;else if(c===","&&r===0){e.push(t.trim()),t="";continue}t+=c}return t&&e.push(t.trim()),e}function Ve(s){if(!s||typeof s!="string"||!s.includes("linear-gradient"))return null;const e=s.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=Ye(t);let i=Math.PI,c=0;const n=r[0].trim();if(n.startsWith("to "))n==="to top"?i=0:n==="to right"?i=Math.PI/2:n==="to bottom"?i=Math.PI:n==="to left"?i=Math.PI*1.5:n==="to top right"||n==="to right top"?i=Math.PI/4:n==="to bottom right"||n==="to right bottom"?i=Math.PI*.75:n==="to bottom left"||n==="to left bottom"?i=Math.PI*1.25:(n==="to top left"||n==="to left top")&&(i=Math.PI*1.75),c=1;else if(n.endsWith("deg")||n.endsWith("rad")||n.endsWith("turn")){const a=parseFloat(n);n.endsWith("deg")?i=a*(Math.PI/180):n.endsWith("rad")?i=a:n.endsWith("turn")&&(i=a*Math.PI*2),c=1}const o=[];for(let a=c;a<r.length&&!(o.length>=8);a++){const l=r[a].trim(),d=l.lastIndexOf(" ");let h=l,u=null;if(d!==-1&&!l.endsWith(")")){const f=l.substring(d+1);(f.endsWith("%")||f.endsWith("px")||!isNaN(parseFloat(f)))&&(h=l.substring(0,d).trim(),u=f)}const p=oe(h);o.push({color:p.color,alpha:p.alpha,rawStop:u,stop:0})}if(o.length>0){for(let l=0;l<o.length;l++)o[l].rawStop!==null&&(o[l].stop=parseFloat(o[l].rawStop)/100);o[0].rawStop===null&&(o[0].stop=0),o.length>1&&o[o.length-1].rawStop===null&&(o[o.length-1].stop=1);let a=0;for(let l=1;l<o.length;l++)if(o[l].rawStop!==null||l===o.length-1){const d=l-a;if(d>1){const h=o[a].stop,p=(o[l].stop-h)/d;for(let f=1;f<d;f++)o[a+f].stop=h+p*f}a=l}}return{angle:i,stops:o}}const We=`varying vec2 vUv;
1
+ (function(b,S){typeof exports=="object"&&typeof module!="undefined"?S(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],S):(b=typeof globalThis!="undefined"?globalThis:b||self,S(b.MirageEngine={},b.THREE))})(this,function(b,S){"use strict";var at=Object.defineProperty,ct=Object.defineProperties;var lt=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var ht=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var pe=(b,S,k)=>S in b?at(b,S,{enumerable:!0,configurable:!0,writable:!0,value:k}):b[S]=k,Z=(b,S)=>{for(var k in S||(S={}))ht.call(S,k)&&pe(b,k,S[k]);if(Oe)for(var k of Oe(S))dt.call(S,k)&&pe(b,k,S[k]);return b},_e=(b,S)=>ct(b,lt(S));var g=(b,S,k)=>(pe(b,typeof S!="symbol"?S+"":S,k),k);var Be=(b,S,k)=>new Promise((y,re)=>{var V=U=>{try{O(k.next(U))}catch(X){re(X)}},ie=U=>{try{O(k.throw(U))}catch(X){re(X)}},O=U=>U.done?y(U.value):Promise.resolve(U.value).then(V,ie);O((k=k.apply(b,S)).next())});function k(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const y=k(S),re={INCLUDE_TREE:"include-tree",EXCLUDE_TREE:"exclude-tree",INCLUDE_SELF:"include-self",EXCLUDE_SELF:"exclude-self",END:"end"},V={NAME:"data-mirage-dom",KEY:"mirageDom",VALUES:{HIDE:"hide",SHOW:"show"}},ie={TRAVELER:"traveler",NATIVE:"native",CAPTURE_1:"1",CAPTURE_2:"2",CAPTURE_3:"3",CAPTURE_4:"4",CAPTURE_5:"5",CAPTURE_6:"6",CAPTURE_7:"7",CAPTURE_8:"8",CAPTURE_9:"9",CAPTURE_10:"10"},O={NAME:"data-mirage-travel",KEY:"mirageTravel",VALUES:ie,MAX_LAYERS:Object.keys(ie).length-1},U={NAME:"data-mirage-filter",KEY:"mirageFilter",VALUES:re},X={NAME:"data-mirage-select",KEY:"mirageSelect",VALUES:re},me={NAME:"data-mirage-shader",KEY:"mirageShader"},Fe={NAME:"data-mirage-sandwich",KEY:"mirageSandwich",VALUES:{FRONT:"front"}},se=0,j=1,Q=2,ve=4,ne=8,ce=16;function Ne(s){const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return e?{r:parseInt(e[1])/255,g:parseInt(e[2])/255,b:parseInt(e[3])/255}:{r:1,g:1,b:1}}function ye(s){const e={};if(s.opacity&&(e.opacity=parseFloat(s.opacity)),s.backgroundColor&&s.backgroundColor!=="rgba(0, 0, 0, 0)"){const t=Ne(s.backgroundColor);e.backgroundColor=[t.r,t.g,t.b]}if(s.backgroundImage?e.backgroundImage=s.backgroundImage:s.background&&(e.backgroundImage=s.background),s.borderRadius&&(e.borderRadius=parseFloat(s.borderRadius)),s.width&&(e.width=parseFloat(s.width)),s.height&&(e.height=parseFloat(s.height)),s.transform&&s.transform!=="none"){const t=new DOMMatrix(s.transform);e.x=t.m41,e.y=t.m42,e.z=t.m43}return e}class be{constructor(e,t){g(this,"target");g(this,"observer");g(this,"pendingDeletions",new Set);g(this,"pendingStyles",new Map);g(this,"isDomDirty",!1);g(this,"isRunning",!1);g(this,"pendingMask",se);g(this,"mutationTimer",null);g(this,"cssTimer",null);g(this,"resizeConfig");g(this,"resizeTimer",null);g(this,"isResizing",!1);g(this,"lastScrollX",0);g(this,"lastScrollY",0);g(this,"scrollTimer",null);g(this,"onBeforeRender",new Set);g(this,"onLayoutChange",new Set);g(this,"onStyleChange",new Set);g(this,"onScrollChange",new Set);g(this,"onRender",new Set);g(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingStyles.size==0&&(this.pendingMask|=j|Q,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50)))});g(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)});g(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=se);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|=j,this.isDomDirty=!0,this.scrollTimer=null},150)),this.pendingStyles.size>0&&(this.onStyleChange.forEach(r=>r(this.pendingStyles)),this.pendingStyles.clear()),this.onRender.forEach(r=>r()),requestAnimationFrame(this.renderLoop)});var i,l;this.target=e;const r=(i=t.resizeDebounce)!=null?i:!0;r===!1?this.resizeConfig={enabled:!1,delay:0}:r===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(l=r.delay)!=null?l:150,onStart:r.onStart,onEnd:r.onEnd},this.observer=new MutationObserver(n=>{let o=se;for(const a of n)if(a.type==="childList")o|=ne,a.removedNodes.length>0&&a.removedNodes.forEach(c=>{c instanceof HTMLElement&&this.pendingDeletions.add(c)});else if(a.type==="attributes")if(a.attributeName==="style"){o|=j|Q;const c=a.target,d=ye(c.style);this.pendingStyles.set(c,d)}else a.attributeName==="class"?o|=j|Q:a.attributeName&&a.attributeName.startsWith("data-")&&(o|=j|Q,a.attributeName.startsWith("data-mirage")&&(o|=ne));else a.type==="characterData"&&(o|=ce|j);if(o!==se){if(this.pendingMask|=o,o&ne){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 W=1,J=2,Xe=0,N={BASE:0,SELECTED:1,getCaptureLayer:s=>31-s,HIDDEN:31},he=Object.values(U.VALUES);class Ee{static getBaseline(e){if(this.cache.has(e))return this.cache.get(e);const t=this.calculateBaselineFromDOM(e);return this.cache.set(e,t),t}static calculateBaselineFromDOM(e){if(typeof document=="undefined")return 0;const t=document.createElement("div"),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}}g(Ee,"cache",new Map);class Ye extends y.MeshBasicMaterial{constructor(t,r,i,l,n=2){super({transparent:!0,side:y.FrontSide,color:16777215});g(this,"canvas");g(this,"ctx");g(this,"qualityFactor");if(this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("[Mirage] Failed to create canvas context");this.qualityFactor=n,this.map=new y.CanvasTexture(this.canvas),this.map.colorSpace=y.LinearSRGBColorSpace,this.map.minFilter=y.LinearFilter,this.map.magFilter=y.LinearFilter,this.updateText(t,r,i,l)}wrapText(t,r){const i=t.split(`
2
+ `),l=[];return i.forEach(n=>{const o=n.match(/[^\s\-]+\-?|\-|\s+/g)||[];if(o.length===0){l.push("");return}let a=o[0];for(let c=1;c<o.length;c++){const d=o[c];this.ctx.measureText(a+d).width<=r+2?a+=d:(a&&l.push(a),a=d.trimStart())}a&&l.push(a)}),l}updateText(t,r,i,l,n){n!==void 0&&(this.qualityFactor=n);const a=(window.devicePixelRatio||1)*this.qualityFactor,c=i*a,d=l*a;this.canvas.width!==c||this.canvas.height!==d?(this.canvas.width=c,this.canvas.height=d):this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(a,0,0,a,0,0),this.ctx.font=r.font,this.ctx.fillStyle=r.color,this.ctx.textBaseline="alphabetic",this.ctx.globalAlpha=1;const h=this.wrapText(t,i),u=r.lineHeight,p=Ee.getBaseline(r.font);h.forEach((f,m)=>{const E=m*u+p;let M=0;r.textAlign==="center"?M=i/2:r.textAlign==="right"&&(M=i),this.ctx.textAlign=r.textAlign,this.ctx.fillText(f,M,E)}),this.map&&(this.map.needsUpdate=!0)}dispose(){this.map&&this.map.dispose(),super.dispose()}}function ee(s,e=0){if(typeof s=="number")return s;const t=parseFloat(s)||0;return typeof s=="string"&&s.includes("%")?t/100*e:t}function oe(s){if(!s||s==="transparent")return{color:new y.Color(16777215),alpha:0};const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),i=parseInt(e[3],10),l=e[4]!==void 0?parseFloat(e[4]):1;return{color:new y.Color(`rgb(${t}, ${r}, ${i})`),alpha:l}}return{color:new y.Color(s),alpha:1}}function ze(s){const e=[];let t="",r=0;for(let i=0;i<s.length;i++){const l=s[i];if(l==="(")r++;else if(l===")")r--;else if(l===","&&r===0){e.push(t.trim()),t="";continue}t+=l}return t&&e.push(t.trim()),e}function Ve(s){if(!s||typeof s!="string"||!s.includes("linear-gradient"))return null;const e=s.match(/linear-gradient\((.*)\)/);if(!e)return null;const t=e[1],r=ze(t);let i=Math.PI,l=0;const n=r[0].trim();if(n.startsWith("to "))n==="to top"?i=0:n==="to right"?i=Math.PI/2:n==="to bottom"?i=Math.PI:n==="to left"?i=Math.PI*1.5:n==="to top right"||n==="to right top"?i=Math.PI/4:n==="to bottom right"||n==="to right bottom"?i=Math.PI*.75:n==="to bottom left"||n==="to left bottom"?i=Math.PI*1.25:(n==="to top left"||n==="to left top")&&(i=Math.PI*1.75),l=1;else if(n.endsWith("deg")||n.endsWith("rad")||n.endsWith("turn")){const a=parseFloat(n);n.endsWith("deg")?i=a*(Math.PI/180):n.endsWith("rad")?i=a:n.endsWith("turn")&&(i=a*Math.PI*2),l=1}const o=[];for(let a=l;a<r.length&&!(o.length>=8);a++){const c=r[a].trim(),d=c.lastIndexOf(" ");let h=c,u=null;if(d!==-1&&!c.endsWith(")")){const f=c.substring(d+1);(f.endsWith("%")||f.endsWith("px")||!isNaN(parseFloat(f)))&&(h=c.substring(0,d).trim(),u=f)}const p=oe(h);o.push({color:p.color,alpha:p.alpha,rawStop:u,stop:0})}if(o.length>0){for(let c=0;c<o.length;c++)o[c].rawStop!==null&&(o[c].stop=parseFloat(o[c].rawStop)/100);o[0].rawStop===null&&(o[0].stop=0),o.length>1&&o[o.length-1].rawStop===null&&(o[o.length-1].stop=1);let a=0;for(let c=1;c<o.length;c++)if(o[c].rawStop!==null||c===o.length-1){const d=c-a;if(d>1){const h=o[a].stop,p=(o[c].stop-h)/d;for(let f=1;f<d;f++)o[a+f].stop=h+p*f}a=c}}return{angle:i,stops:o}}const We=`varying vec2 vUv;
3
3
  varying vec4 vScreenPos;
4
4
  void main() {
5
5
  vUv = uv;
@@ -152,17 +152,17 @@ uniform vec2 uTextureOffset;`,Ge=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w)
152
152
  vec2 resultUv = screenUv;
153
153
 
154
154
  `,qe=`vec4 texColor = texture2D(uTexture, resultUv);
155
- baseColor = blendSrcOver(baseColor, texColor);`,we={vertexShader:We,fragmentShader:He},Te={declChunk:Pe,uvChunk:Ge,baseColorChunk:qe};function $e(s,e,t,r=null,i){var x;const c=r!==null||!!s.imageSrc;let n="";const o={};if(i!=null&&i.uniforms)for(const[E,w]of Object.entries(i.uniforms))typeof w=="number"?(n+=`uniform float ${E};
156
- `,o[E]={value:w}):Array.isArray(w)?w.length===2?(n+=`uniform vec2 ${E};
157
- `,o[E]={value:new y.Vector2(...w)}):w.length===3?(n+=`uniform vec3 ${E};
158
- `,o[E]={value:new y.Vector3(...w)}):w.length===4&&(n+=`uniform vec4 ${E};
159
- `,o[E]={value:new y.Vector4(...w)}):(n+=`uniform float ${E};
160
- `,o[E]={value:w});const a=i!==void 0,l=(c||a?Te.declChunk:"")+`
155
+ baseColor = blendSrcOver(baseColor, texColor);`,we={vertexShader:We,fragmentShader:He},Te={declChunk:Pe,uvChunk:Ge,baseColorChunk:qe};function $e(s,e,t,r=null,i){var T;const l=r!==null||!!s.imageSrc;let n="";const o={};if(i!=null&&i.uniforms)for(const[C,w]of Object.entries(i.uniforms))typeof w=="number"?(n+=`uniform float ${C};
156
+ `,o[C]={value:w}):Array.isArray(w)?w.length===2?(n+=`uniform vec2 ${C};
157
+ `,o[C]={value:new y.Vector2(...w)}):w.length===3?(n+=`uniform vec3 ${C};
158
+ `,o[C]={value:new y.Vector3(...w)}):w.length===4&&(n+=`uniform vec4 ${C};
159
+ `,o[C]={value:new y.Vector4(...w)}):(n+=`uniform float ${C};
160
+ `,o[C]={value:w});const a=i!==void 0,c=(l||a?Te.declChunk:"")+`
161
161
  `+n,d=`vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
162
162
  `,h=s.isTraveler?`vec2 resultUv = screenUv;
163
163
  `:`vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
164
- `,u=c||a?d+h+((i==null?void 0:i.uvModifier)||""):"",p=c||a?Te.baseColorChunk:"",f=(i==null?void 0:i.colorModifier)||"",m=we.fragmentShader.replace("#INJECT_DECLARATIONS",l).replace("#INJECT_UV_MODIFIER",u).replace("#INJECT_BASE_COLOR",p).replace("#INJECT_COLOR_MODIFIER",f),T=oe(s.backgroundColor),L=oe(s.borderColor),k={uSize:{value:new y.Vector2(e,t)},uBgColor:{value:new y.Vector4(T.color.r,T.color.g,T.color.b,T.alpha)},uBorderColor:{value:new y.Vector4(L.color.r,L.color.g,L.color.b,L.alpha)},uBorderRadius:{value:new y.Vector4(0,0,0,0)},uBorderWidth:{value:ee(s.borderWidth)},uOpacity:{value:(x=s.opacity)!=null?x:1},uTexture:{value:null},uTextureRepeat:{value:new y.Vector2(1,1)},uTextureOffset:{value:new y.Vector2(0,0)},uGradientCount:{value:0},uGradientAngle:{value:0},uGradientColors:{value:Array.from({length:8},()=>new y.Vector4(0,0,0,0))},uGradientStops:{value:new Float32Array(8)}};xe(k.uBorderRadius.value,s.borderRadius,Math.min(e,t)),c&&(k.uTexture.value=r);const R=new y.ShaderMaterial({uniforms:Z(Z({},k),o),vertexShader:we.vertexShader,fragmentShader:m,transparent:!0,side:y.FrontSide});return s.backgroundImage&&de(R,{backgroundImage:s.backgroundImage}),R}function je(s,e,t,r,i){const c=ee(e.borderWidth);de(s,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:c,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage})}function de(s,e){var r,i,c;if(e.width!==void 0&&e.height!==void 0&&s.uniforms.uSize.value.set(e.width,e.height),e.borderRadius!==void 0){const n=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(s.uniforms.uSize.value.x,s.uniforms.uSize.value.y);xe(s.uniforms.uBorderRadius.value,e.borderRadius,n)}if(e.borderWidth!==void 0&&(s.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],n)}else if(typeof e.backgroundColor=="string"){const n=oe(e.backgroundColor);s.uniforms.uBgColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,n)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],n)}else if(typeof e.borderColor=="string"){const n=oe(e.borderColor);s.uniforms.uBorderColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,n)}e.opacity!==void 0&&(s.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(s.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(s.uniforms.uBorderColor.value.w=e.borderOpacity),s.uniforms.uTexture&&e.texture!==void 0&&(s.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=s.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const n=t.image.naturalWidth||t.image.videoWidth||t.image.width,o=t.image.naturalHeight||t.image.videoHeight||t.image.height,a=(i=e.width)!=null?i:s.uniforms.uSize.value.x,l=(c=e.height)!=null?c:s.uniforms.uSize.value.y;if(n&&o&&a&&l){const d=n/o,h=a/l;if(d>h){const u=h/d;s.uniforms.uTextureRepeat.value.set(u,1),s.uniforms.uTextureOffset.value.set((1-u)/2,0)}else{const u=d/h;s.uniforms.uTextureRepeat.value.set(1,u),s.uniforms.uTextureOffset.value.set(0,(1-u)/2)}}}else s.uniforms.uTextureRepeat&&(s.uniforms.uTextureRepeat.value.set(1,1),s.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const n=Ve(e.backgroundImage);if(n){s.uniforms.uGradientCount.value=n.stops.length,s.uniforms.uGradientAngle.value=n.angle;for(let o=0;o<8;o++)if(o<n.stops.length){const a=n.stops[o];s.uniforms.uGradientColors.value[o].set(a.color.r,a.color.g,a.color.b,a.alpha),s.uniforms.uGradientStops.value[o]=a.stop}else s.uniforms.uGradientColors.value[o].set(0,0,0,0),s.uniforms.uGradientStops.value[o]=1}else s.uniforms.uGradientCount.value=0}for(const n of Object.keys(e))n!=="width"&&n!=="height"&&n!=="borderRadius"&&n!=="borderWidth"&&n!=="backgroundColor"&&n!=="borderColor"&&n!=="opacity"&&n!=="bgOpacity"&&n!=="borderOpacity"&&n!=="texture"&&n!=="backgroundImage"&&s.uniforms[n]!==void 0&&(s.uniforms[n].value!==void 0&&s.uniforms[n].value!==null&&typeof s.uniforms[n].value.set=="function"?Array.isArray(e[n])?s.uniforms[n].value.set(...e[n]):e[n]!==void 0&&(e[n].copy?s.uniforms[n].value.copy(e[n]):s.uniforms[n].value=e[n]):s.uniforms[n].value=e[n])}function xe(s,e,t=0){var a,l,d,h;if(e==null){s.set(0,0,0,0);return}if(typeof e=="number"){s.set(e,e,e,e);return}if(Array.isArray(e)){s.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=ee(r[0],t),c=ee((a=r[1])!=null?a:r[0],t),n=ee((l=r[2])!=null?l:r[0],t),o=ee((h=(d=r[3])!=null?d:r[1])!=null?h:r[0],t);s.set(i,c,n,o)}const H={create(s,e,t,r,i,c=2,n=null,o){return s==="BOX"?$e(e,r,i,n,o):s==="TEXT"?new ze(t||"",e,r,i,c):new y.MeshBasicMaterial({visible:!1})},update(s,e,t,r,i,c,n=2,o){e==="BOX"?je(s,t,i,c,o):e==="TEXT"&&s.updateText(r||"",t,i,c,n)},forceUpdateUniforms(s,e){de(s,e)}};class Ke{constructor(e,t=!0){g(this,"observer");g(this,"textures",new WeakMap);g(this,"loadStatus",new WeakMap);g(this,"elementUrls",new WeakMap);g(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const c=i.target;i.isIntersecting?this.loadTexture(c):this.disposeTexture(c)}},{rootMargin:"300px"}))}register(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;this.elementUrls.get(e)!==t&&(this.elementUrls.set(e,t),this.observer?(this.observer.unobserve(e),this.observer.observe(e)):this.loadTexture(e))}unregister(e){e.nodeType===Node.ELEMENT_NODE&&this.observer&&this.observer.unobserve(e),this.disposeTexture(e),this.elementUrls.delete(e),this.loadStatus.delete(e)}loadTexture(e){return Be(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((c,n)=>{const o=new Image;o.onload=()=>c(o),o.onerror=n,o.src=t});else{const n=yield(yield fetch(t)).blob();r=yield createImageBitmap(n,{imageOrientation:"flipY"})}if(this.elementUrls.get(e)!==t){"close"in r&&r.close();return}const i=new y.Texture(r);r instanceof HTMLImageElement||(i.flipY=!1),i.colorSpace=y.LinearSRGBColorSpace,i.needsUpdate=!0,this.textures.set(e,i),this.onUpdate(e,i)}catch(r){console.warn("[MirageEngine] Failed to load texture:",t,r)}finally{this.elementUrls.has(e)&&this.loadStatus.set(e,!1)}}})}disposeTexture(e){const t=this.textures.get(e);t&&(t.dispose(),this.textures.delete(e),this.onUpdate(e,null)),this.loadStatus.set(e,!1)}get(e){return this.textures.get(e)}disposeAll(){this.observer&&this.observer.disconnect()}}class Je{constructor(e,t,r,i){g(this,"canvas");g(this,"scene");g(this,"camera");g(this,"renderer");g(this,"renderTargets",[]);g(this,"renderOrder",0);g(this,"qualityFactor",2);g(this,"mode","overlay");g(this,"canvasSize","viewport");g(this,"clipArea",1);g(this,"targetLayer","base");g(this,"overscan",200);g(this,"target");g(this,"mountContainer");g(this,"registry");g(this,"targetRect");g(this,"travelersByLayer",Array.from({length:I.MAX_LAYERS},()=>new Set));g(this,"textureManager");g(this,"fixedMeshes",new Set);var o,a,l,d,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(o=t.mode)!=null?o:"overlay",this.canvasSize=(a=t.canvasSize)!=null?a:"viewport",this.clipArea=(l=t.travelerClipArea)!=null?l:1,this.targetLayer=(d=t.layer)!=null?d:"base",this.textureManager=new Ke((u,p)=>{const f=this.registry.get(u);f&&f.material instanceof y.ShaderMaterial&&H.forceUpdateUniforms(f.material,{texture:p})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new y.Scene,this.targetRect=this.target.getBoundingClientRect();const c=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,n=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.camera=new y.OrthographicCamera(c/-2,c/2,n/2,n/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(this.getSceneLayer()),this.renderer=new y.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),y.ColorManagement.enabled=!1,this.renderer.outputColorSpace=y.LinearSRGBColorSpace,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(c,n),this.applyTextQuality((h=t.quality)!=null?h:"medium")}get isViewport(){return this.mode==="overlay"&&this.canvasSize==="viewport"}getSceneLayer(){return typeof this.targetLayer=="number"?this.targetLayer:this.targetLayer==="selected"?_.SELECTED:_.BASE}createRenderTarget(){for(let e=0;e<I.MAX_LAYERS;e++){const t=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,r=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.renderTargets.push(new y.WebGLRenderTarget(t*this.qualityFactor,r*this.qualityFactor,{minFilter:y.LinearFilter,magFilter:y.LinearFilter,format:y.RGBAFormat,stencilBuffer:!1,depthBuffer:!0}))}}applyTextQuality(e){if(typeof e=="number"){this.qualityFactor=Math.max(.1,e);return}switch(e){case"low":this.qualityFactor=1;break;case"high":this.qualityFactor=4;break;case"medium":this.qualityFactor=2;break;default:this.qualityFactor=2;break}}mount(){this.mountContainer.prepend(this.canvas),this.canvas.style.pointerEvents=this.mode==="overlay"?"none":"auto",this.updateCanvasLayout()}updateCanvasLayout(){const e=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,t=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.mode==="duplicate"?(this.canvas.style.position="",this.canvas.style.top="",this.canvas.style.left="",this.canvas.style.display="block"):(this.canvas.style.position=this.isViewport?"fixed":"absolute",this.canvas.style.top=this.isViewport?`-${this.overscan}px`:`${this.target.offsetTop}px`,this.canvas.style.left=this.isViewport?`-${this.overscan}px`:`${this.target.offsetLeft}px`,this.canvas.style.display="block")}updateUniforms(e,t){const r=this.registry.get(e);r&&(r.traverse(i=>{i.isMesh&&i.material&&H.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&H.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,c=this.isViewport?window.innerHeight+this.overscan*2:r.height,n=this.isViewport?this.canvas.clientWidth:this.targetRect.width,o=this.isViewport?this.canvas.clientHeight:this.targetRect.height,a=Math.abs(i-n)>.1||Math.abs(c-o)>.1,l=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);a?(this.targetRect=r,this.setSize(i,c),this.updateCanvasLayout()):l?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(d=>{const h=this.registry.get(d);if(h){this.scene.remove(h);for(const u of this.travelersByLayer)u.delete(h);this.fixedMeshes.delete(h),h.geometry.dispose(),h.userData.nativeMesh&&(this.scene.remove(h.userData.nativeMesh),Array.isArray(h.userData.nativeMesh.material)?h.userData.nativeMesh.material.forEach(u=>u.dispose()):h.userData.nativeMesh.material.dispose(),h.userData.nativeMesh.geometry.dispose()),h.traverse(u=>{u instanceof y.Mesh&&(u.geometry&&u.geometry.dispose(),u.material&&(Array.isArray(u.material)?u.material.forEach(p=>p.dispose()):u.material.dispose()))}),this.registry.remove(d),this.textureManager.unregister(d)}})}reconcileNode(e){var i,c;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof y.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const n=new y.PlaneGeometry(1,1),o=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),a=H.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,o,e.shaderHooks);t=new y.Mesh(n,a),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=a,t.userData.domElement=e.element,t.userData.shaderHash=r}if((c=e.nativeStyles)!=null&&c.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let n=0;n<I.MAX_LAYERS;n++)n===e.captureLayer-2?this.travelersByLayer[n].add(t):this.travelersByLayer[n].delete(t);else for(const n of this.travelersByLayer)n.delete(t);if(e.isFixed?this.fixedMeshes.add(t):this.fixedMeshes.delete(t),e.styles.imageSrc?this.textureManager.register(e.element,e.styles.imageSrc):this.textureManager.unregister(e.element),e.type==="BOX")for(const n of e.children)this.reconcileNode(n);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var l;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],c=r?t.nativeStyles:t.textStyles,n=JSON.stringify(c)+t.textContent+i.map(d=>d.text).join("|"),o=(l=e.userData)==null?void 0:l.textChildStyleHash;if(t.dirtyMask&ce||n!==o){e.children.filter(f=>f.name.startsWith("TEXT_CHILD")).forEach(f=>{var T;const m=f;(T=m.material.map)==null||T.dispose(),m.geometry.dispose(),e.remove(m)});const h=t.rect,u=h.x+h.width/2,p=h.y+h.height/2;i.forEach((f,m)=>{const T=H.create("TEXT",c,f.text,f.rect.width,f.rect.height,this.qualityFactor),L=new y.PlaneGeometry(1,1),k=new y.Mesh(L,T);k.name=`TEXT_CHILD_${m}`;const R=t.rect.width===0?1:f.rect.width/t.rect.width,x=t.rect.height===0?1:f.rect.height/t.rect.height;k.scale.set(R,x,1);const E=f.rect.x+f.rect.width/2,w=f.rect.y+f.rect.height/2,F=E-u,X=-(w-p);k.position.set(t.rect.width===0?0:F/t.rect.width,t.rect.height===0?0:X/t.rect.height,.005),e.add(k)}),e.userData.textChildStyleHash=n}e.children.forEach(d=>{if(!d.name.startsWith("TEXT_CHILD"))return;const h=d,u=t.visibility&W?_.BASE:_.HIDDEN;if(h.layers.set(u),t.visibility&K&&h.layers.enable(_.SELECTED),t.visibility&W)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let p=t.captureLayer;p<t.nativeLayer;p++)h.layers.enable(_.getCaptureLayer(p));else if(r&&t.nativeLayer!==void 0)for(let p=Math.max(t.captureLayer,t.nativeLayer);p<=I.MAX_LAYERS+1;p++)h.layers.enable(_.getCaptureLayer(p));else for(let p=t.captureLayer;p<=I.MAX_LAYERS+1;p++)h.layers.enable(_.getCaptureLayer(p))})}updateMeshProperties(e,t){var R,x,E;const{rect:r,styles:i}=t,c=this.renderer.getPixelRatio(),n=this.renderer.domElement.width/c,o=this.renderer.domElement.height/c;e.material=e.userData.baseMaterial,e.scale.set(r.width,r.height,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const a=.001;this.renderOrder++;const l=this.targetRect.left+window.scrollX,d=this.targetRect.top+window.scrollY;let h,u;if(this.isViewport)h=r.x-window.innerWidth/2+r.width/2,u=-r.y+window.innerHeight/2-r.height/2;else{const w=r.x-l,F=r.y-d;h=w-n/2+r.width/2,u=-F+o/2-r.height/2}e.position.set(h,u,i.zIndex+this.renderOrder*a);const p=r.x,f=r.y;e.userData.basePosition={x:h,y:u},e.userData.originalBasePosition={x:h,y:u},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:p,y:f},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,T=window.getComputedStyle(m);let L=0,k=0;if(T.transform&&T.transform!=="none"){const w=new DOMMatrix(T.transform);L=w.m41,k=w.m42}if(e.userData.baseTransform={x:L,y:k},delete e.userData.originRatioX,delete e.userData.originRatioY,H.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(R=this.renderTargets[t.captureLayer-2])==null?void 0:R.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const z=H.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(x=this.renderTargets[t.captureLayer-2])==null?void 0:x.texture:this.textureManager.get(t.element),t.shaderHooks),J=new y.Mesh(e.geometry,z);t.type==="TEXT"&&(J.name="BG_MESH"),this.scene.add(J),e.userData.nativeMesh=J}const w=e.userData.nativeMesh;let F,X;if(this.isViewport)F=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,X=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const z=t.nativeRect.x-l,J=t.nativeRect.y-d;F=z-n/2+t.nativeRect.width/2,X=-J+o/2-t.nativeRect.height/2}w.scale.set(t.nativeRect.width,t.nativeRect.height,1),w.position.set(F,X,t.nativeStyles.zIndex+this.renderOrder*a),H.update(w.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(E=this.renderTargets[t.captureLayer-2])==null?void 0:E.texture:this.textureManager.get(t.element))}else e.userData.nativeMesh&&(this.scene.remove(e.userData.nativeMesh),e.userData.nativeMesh.material instanceof y.Material&&e.userData.nativeMesh.material.dispose(),delete e.userData.nativeMesh)}updateMeshLayers(e,t){const r=t.visibility&W?_.BASE:_.HIDDEN;if(e.layers.set(r),t.visibility&K&&e.layers.enable(_.SELECTED),e.userData.nativeMesh&&t.nativeLayer!==void 0){const i=e.userData.nativeMesh;if(i.layers.set(_.HIDDEN),t.visibility&W){for(let c=t.captureLayer;c<t.nativeLayer;c++)e.layers.enable(_.getCaptureLayer(c));for(let c=Math.max(t.captureLayer,t.nativeLayer);c<=I.MAX_LAYERS+1;c++)i.layers.enable(_.getCaptureLayer(c))}}else if(t.visibility&W)for(let i=t.captureLayer;i<=I.MAX_LAYERS+1;i++)e.layers.enable(_.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new y.Color,c=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const n=new y.Vector3,o=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,a=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,l=this.renderer.getPixelRatio();for(const d of e){n.setFromMatrixPosition(d.matrixWorld),n.project(this.camera);const h=(n.x+1)/2*o,u=(n.y+1)/2*a;let p=0,f=1;typeof this.clipArea=="number"?f=this.clipArea:this.clipArea.endsWith("%")?f=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(p=parseFloat(this.clipArea));const m=d.scale.x*f+.5,T=d.scale.y*f+.5,L=h-m/2,k=u-T/2,R=(L*this.qualityFactor-p)/l,x=(k*this.qualityFactor-p)/l,E=(m*this.qualityFactor+p*2)/l,w=(T*this.qualityFactor+p*2)/l;this.renderer.setScissor(R,x,E,w),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,c)}render(){for(let e=0;e<I.MAX_LAYERS;e++){const t=e+1;this.captureRenderTarget(this.travelersByLayer[e],_.getCaptureLayer(t),this.renderTargets[e])}this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,c=this.renderer.domElement.height/r;this.scene.children.forEach(n=>{const o=n;if(!o.userData||!o.userData.domElement)return;const a=o.userData.domElement;if(!a.isConnected)return;let l;if(a.nodeType===Node.TEXT_NODE){const h=document.createRange();h.selectNode(a),l=h.getBoundingClientRect()}else l=a.getBoundingClientRect();const d=o.userData.domRect;if(!d||Math.abs(l.x-d.x)>.5||Math.abs(l.y-d.y)>.5||Math.abs(l.width-d.width)>.5||Math.abs(l.height-d.height)>.5){o.userData.domRect={x:l.x,y:l.y,width:l.width,height:l.height};let h,u;if(this.isViewport)h=l.x-window.innerWidth/2+l.width/2,u=-l.y+window.innerHeight/2-l.height/2;else{const p=l.x-e,f=l.y-t;h=p-i/2+l.width/2,u=-f+c/2-l.height/2}if(o.position.setX(h),o.position.setY(u),o.scale.set(l.width,l.height,1),o.updateMatrixWorld(),o.material instanceof y.ShaderMaterial&&H.forceUpdateUniforms(o.material,{width:l.width,height:l.height}),o.userData.nativeMesh){const p=o.userData.nativeMesh;let f=l.width,m=l.height,T=h,L=u;if(o.userData.nativeTransform){const k=o.userData.nativeTransform,R=k.match(/scale\(([\d.]+%?)\)/);if(R){let E=parseFloat(R[1]);R[1].includes("%")&&(E/=100),f*=E,m*=E}const x=k.match(/translate\(([^,]+),\s*([^)]+)\)/);if(x){const E=x[1].trim(),w=x[2].trim();let F=parseFloat(E);E.includes("%")&&(F=F/100*l.width);let X=parseFloat(w);w.includes("%")&&(X=X/100*l.height),T+=F,L-=X}}p.position.setX(T),p.position.setY(L),p.scale.set(f,m,1),p.updateMatrixWorld()}}})}}function Ze(s){const e=s.textContent||"",t=[];let r="",i=null,c=-1;const n=(l,d)=>{for(let h=0;h<l.length;h++){const u=l[h],p=document.createRange();p.setStart(s,d+h),p.setEnd(s,d+h+1);const f=p.getBoundingClientRect();if(f.width===0&&f.height===0){r+=u;continue}c===-1||Math.abs(f.top-c)>f.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=u,i={left:f.left,top:f.top,right:f.right,bottom:f.bottom},c=f.top):(r+=u,i&&(i.left=Math.min(i.left,f.left),i.top=Math.min(i.top,f.top),i.right=Math.max(i.right,f.right),i.bottom=Math.max(i.bottom,f.bottom)))}},o=e.match(/[^\s\-]+\-?|\-|\s+/g)||[];let a=0;for(const l of o){const d=document.createRange();d.setStart(s,a),d.setEnd(s,a+l.length);const h=d.getClientRects();if(h.length>1)n(l,a);else{const u=h.length===1?h[0]:d.getBoundingClientRect();if(u.width===0&&u.height===0){r+=l,a+=l.length;continue}c===-1||Math.abs(u.top-c)>u.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=l,i={left:u.left,top:u.top,right:u.right,bottom:u.bottom},c=u.top):(r+=l,i&&(i.left=Math.min(i.left,u.left),i.top=Math.min(i.top,u.top),i.right=Math.max(i.right,u.right),i.bottom=Math.max(i.bottom,u.bottom)))}a+=l.length}return r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),t.filter(l=>l.text.trim().length>0&&l.rect.width>0&&l.rect.height>0)}function Ce(s){const e=parseFloat(s.fontSize);let t=parseFloat(s.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(s.letterSpacing);return isNaN(r)&&(r=0),{font:`${s.fontStyle} ${s.fontWeight} ${s.fontSize} ${s.fontFamily}`,fontSize:s.fontSize,color:s.color,textAlign:s.textAlign||"start",textBaseline:"alphabetic",direction:s.direction||"inherit",lineHeight:t,letterSpacing:r}}function Se(s,e=$|Q|ve|ce|ne,t,r=1,i=0,c=2,n,o){var Le,Me,De,Ae,Ie,ke;if(s.nodeType===Node.TEXT_NODE){const v=s;if(!v.textContent||!v.textContent.trim())return null;const U=v.textContent.replace(/\s+/g," ");if(U.length===0)return null;const N=Ze(v);if(N.length===0)return null;const P=v.parentElement,O=P?window.getComputedStyle(P):null;if(!O)return null;const q=Math.min(...N.map(C=>C.rect.left)),Y=Math.min(...N.map(C=>C.rect.top)),j=Math.max(...N.map(C=>C.rect.left+C.rect.width)),M=Math.max(...N.map(C=>C.rect.top+C.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:v,rect:{x:q+window.scrollX,y:Y+window.scrollY,width:j-q,height:M-Y},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:P&&P.dataset[V.KEY]===V.VALUES.HIDE?1:parseFloat(O.opacity),zIndex:(isNaN(parseInt(O.zIndex))?0:parseInt(O.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:U,textLines:N.map(C=>({text:C.text.trim(),rect:{x:C.rect.left+window.scrollX,y:C.rect.top+window.scrollY,width:C.rect.width,height:C.rect.height}})),textStyles:Ce(O),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:O.position==="fixed",nativeLayer:n,nativeStyles:o?Z(Z({backgroundColor:"transparent",backgroundImage:"",opacity:P&&P.dataset[V.KEY]===V.VALUES.HIDE?1:parseFloat(O.opacity),zIndex:(isNaN(parseInt(O.zIndex))?0:parseInt(O.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Ce(O)),o):void 0,nativeRect:o?{x:q+window.scrollX,y:Y+window.scrollY,width:j-q,height:M-Y}:void 0,children:[]}}if(s.nodeType!==Node.ELEMENT_NODE)return null;const a=s,l=a.dataset[A.KEY];let d=t,h=t;if(l){const v=new Set(l.split(/\s+/));for(const U of v)if(!he.includes(U))throw new Error(`[MirageEngine] Invalid filter token: '${U}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(v.has(A.VALUES.END))return null;if(v.has(A.VALUES.INCLUDE_TREE)&&v.has(A.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(v.has(A.VALUES.INCLUDE_SELF)&&v.has(A.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");v.has(A.VALUES.INCLUDE_TREE)?d=d|W:v.has(A.VALUES.EXCLUDE_TREE)&&(d=d&~W),h=d,v.has(A.VALUES.INCLUDE_SELF)?h=h|W:v.has(A.VALUES.EXCLUDE_SELF)&&(h=h&~W)}const u=a.dataset[B.KEY];if(u){const v=new Set(u.split(/\s+/));for(const U of v)if(!he.includes(U))throw new Error(`[MirageEngine] Invalid select token: '${U}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(v.has(B.VALUES.END))return null;if(v.has(B.VALUES.INCLUDE_TREE)&&v.has(B.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(v.has(B.VALUES.INCLUDE_SELF)&&v.has(B.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");v.has(B.VALUES.INCLUDE_TREE)?d=d|K:v.has(B.VALUES.EXCLUDE_TREE)&&(d=d&~K),h=d,v.has(B.VALUES.INCLUDE_SELF)?h=h|K:v.has(B.VALUES.EXCLUDE_SELF)&&(h=h&~K)}const p=a.dataset[I.KEY];let f=!1,m=o?Z({},o):{},T=n;if(p){let v=1;const U=p.indexOf("{"),N=p.lastIndexOf("}");let P=p;if(U!==-1&&N!==-1&&N>U){P=p.substring(0,U).trim();const M=p.substring(U,N+1);try{m=new Function("return "+M)()}catch(C){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${M}`)}}const O=P.split(/\s+/);let q=!1;const Y=O.indexOf(I.VALUES.TRAVELER);if(Y!==-1){f=!0,q=!0;const M=O[Y+1];if(M&&!isNaN(parseInt(M,10)))v=parseInt(M,10);else{const C=O.find(te=>!isNaN(parseInt(te,10)));C&&(v=parseInt(C,10))}}const j=O.indexOf(I.VALUES.NATIVE);if(j!==-1){const M=O[j+1];if(M&&!isNaN(parseInt(M,10)))T=parseInt(M,10);else if(!f){const C=O.find(te=>!isNaN(parseInt(te,10)));C&&(T=parseInt(C,10))}}if(q){const M=v+1;if(M<r)throw new Error(`[MirageEngine] Traveler layer (${v}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(M,I.MAX_LAYERS+1)}}const L=a.dataset[me.KEY];let k;L&&(k=JSON.parse(L));const R=a.getBoundingClientRect(),x=window.getComputedStyle(a);if(R.width===0||R.height===0||x.display==="none")return null;let E=a.getAttribute("data-mid");E||(E=Math.random().toString(36).substring(2,11),a.setAttribute("data-mid",E));const w=parseInt(x.zIndex),F=(isNaN(w)?0:w)+i;let X;if(a.tagName==="IMG")X=a.src;else if(a.tagName.toLowerCase()==="svg"){const v=a.cloneNode(!0),U=m==null?void 0:m.color,N=m==null?void 0:m.fill,P=m==null?void 0:m.stroke,O=m==null?void 0:m.opacity,q=(C,te)=>{const G=window.getComputedStyle(C),ae=te,nt=G.fill===G.color,ot=G.stroke===G.color,ue=N||(nt?U:void 0)||G.fill;ue&&ue!=="none"&&(ae.style.fill=ue);const fe=P||(ot?U:void 0)||G.stroke;fe&&fe!=="none"&&(ae.style.stroke=fe),G.strokeWidth&&G.strokeWidth!=="0px"&&(ae.style.strokeWidth=G.strokeWidth);const Ue=U||G.color;Ue&&(ae.style.color=Ue);const ge=O||G.opacity;ge&&ge!=="1"&&(ae.style.opacity=ge);for(let le=0;le<C.children.length;le++)q(C.children[le],te.children[le])};q(a,v);const Y=a.getBoundingClientRect(),j=window.devicePixelRatio*c;v.hasAttribute("viewBox")||v.setAttribute("viewBox",`0 0 ${Y.width} ${Y.height}`),v.setAttribute("width",(Y.width*j).toString()),v.setAttribute("height",(Y.height*j).toString());let M=new XMLSerializer().serializeToString(v);M.includes("xmlns=")||(M=M.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),X=`data:image/svg+xml;utf8,${encodeURIComponent(M)}`}else if(x.backgroundImage&&x.backgroundImage!=="none"){const v=x.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);v&&(X=v[1])}const z={backgroundColor:x.backgroundColor,backgroundImage:x.backgroundImage,opacity:a.dataset[V.KEY]===V.VALUES.HIDE?1:parseFloat(x.opacity),zIndex:F,borderRadius:x.borderRadius,borderColor:x.borderColor,borderWidth:x.borderWidth,imageSrc:X,isTraveler:f},J=z;let it,st;const Re=[];return a.tagName.toLowerCase()!=="svg"&&Array.from(a.childNodes).forEach(v=>{const U=v.nodeType===Node.TEXT_NODE?h:d,N=Se(v,e,U,r,F,c,v.nodeType===Node.TEXT_NODE?T:void 0,v.nodeType===Node.TEXT_NODE&&Object.keys(m).length>0?m:void 0);N&&Re.push(N)}),{id:E,type:"BOX",element:a,rect:{x:R.left+window.scrollX,y:R.top+window.scrollY,width:R.width,height:R.height},styles:J,textContent:it,textStyles:st,dirtyMask:e,visibility:h,isTraveler:f,captureLayer:r,nativeLayer:T,nativeStyles:T!==void 0?_e(Z({},z),{backgroundColor:(Le=m.backgroundColor)!=null?Le:z.backgroundColor,backgroundImage:(Me=m.backgroundImage)!=null?Me:z.backgroundImage,opacity:(De=m.opacity)!=null?De:z.opacity,zIndex:m.zIndex!==void 0?m.zIndex+F:z.zIndex,borderRadius:(Ae=m.borderRadius)!=null?Ae:z.borderRadius,borderColor:(Ie=m.borderColor)!=null?Ie:z.borderColor,borderWidth:(ke=m.borderWidth)!=null?ke:z.borderWidth,isTraveler:z.isTraveler,transform:m.transform}):void 0,nativeRect:T!==void 0?{x:m.x!==void 0?parseFloat(m.x):R.left+window.scrollX,y:m.y!==void 0?parseFloat(m.y):R.top+window.scrollY,width:m.width!==void 0?parseFloat(m.width):R.width,height:m.height!==void 0?parseFloat(m.height):R.height}:void 0,isFixed:x.position==="fixed",children:Re,shaderHooks:k}}function Qe(s,e){e.size!==0&&e.forEach((t,r)=>{var c,n,o,a;const i=s.get(r);!i||!i.userData.basePosition||(H.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(n=t.borderRadius)!=null?n:(c=i.userData.baseStyles)==null?void 0:c.borderRadius}),i.userData.nativeMesh&&H.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(a=t.borderRadius)!=null?a:(o=i.userData.baseStyles)==null?void 0:o.borderRadius}))})}class et{constructor(e,t,r,i){g(this,"target");g(this,"renderer");g(this,"registry");g(this,"isTravelEnabled",!1);g(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new be(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((c,n)=>{document.querySelector(`[${I.NAME}~='${I.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const a=Se(this.target,c,W,1,0,this.renderer.qualityFactor);a&&this.renderer.syncScene(a,n)}),this.tracker.onStyleChange.add(c=>{Qe(this.registry,c)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class tt{constructor(){g(this,"store");this.store=new WeakMap}register(e,t){this.store.set(e,t)}get(e){return this.store.get(e)}has(e){return this.store.has(e)}remove(e){this.store.delete(e)}}class rt{constructor(e,t){g(this,"renderer");g(this,"syncer");g(this,"target");g(this,"registry");var i,c,n;if(this.target=e,this.registry=new tt,!document.getElementById("mirage-engine-styles")){const o=document.createElement("style");o.id="mirage-engine-styles",o.textContent=`
164
+ `,u=l||a?d+h+((i==null?void 0:i.uvModifier)||""):"",p=l||a?Te.baseColorChunk:"",f=(i==null?void 0:i.colorModifier)||"",m=we.fragmentShader.replace("#INJECT_DECLARATIONS",c).replace("#INJECT_UV_MODIFIER",u).replace("#INJECT_BASE_COLOR",p).replace("#INJECT_COLOR_MODIFIER",f),E=oe(s.backgroundColor),M=oe(s.borderColor),D={uSize:{value:new y.Vector2(e,t)},uBgColor:{value:new y.Vector4(E.color.r,E.color.g,E.color.b,E.alpha)},uBorderColor:{value:new y.Vector4(M.color.r,M.color.g,M.color.b,M.alpha)},uBorderRadius:{value:new y.Vector4(0,0,0,0)},uBorderWidth:{value:ee(s.borderWidth)},uOpacity:{value:(T=s.opacity)!=null?T:1},uTexture:{value:null},uTextureRepeat:{value:new y.Vector2(1,1)},uTextureOffset:{value:new y.Vector2(0,0)},uGradientCount:{value:0},uGradientAngle:{value:0},uGradientColors:{value:Array.from({length:8},()=>new y.Vector4(0,0,0,0))},uGradientStops:{value:new Float32Array(8)}};xe(D.uBorderRadius.value,s.borderRadius,Math.min(e,t)),l&&(D.uTexture.value=r);const R=new y.ShaderMaterial({uniforms:Z(Z({},D),o),vertexShader:we.vertexShader,fragmentShader:m,transparent:!0,side:y.FrontSide});return s.backgroundImage&&de(R,{backgroundImage:s.backgroundImage}),R}function je(s,e,t,r,i){const l=ee(e.borderWidth);de(s,{width:t,height:r,borderRadius:e.borderRadius,borderWidth:l,backgroundColor:e.backgroundColor,borderColor:e.borderColor,opacity:e.opacity,texture:i,backgroundImage:e.backgroundImage})}function de(s,e){var r,i,l;if(e.width!==void 0&&e.height!==void 0&&s.uniforms.uSize.value.set(e.width,e.height),e.borderRadius!==void 0){const n=e.width!==void 0&&e.height!==void 0?Math.min(e.width,e.height):Math.min(s.uniforms.uSize.value.x,s.uniforms.uSize.value.y);xe(s.uniforms.uBorderRadius.value,e.borderRadius,n)}if(e.borderWidth!==void 0&&(s.uniforms.uBorderWidth.value=e.borderWidth),e.backgroundColor!==void 0)if(Array.isArray(e.backgroundColor)){const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor[0],e.backgroundColor[1],e.backgroundColor[2],n)}else if(typeof e.backgroundColor=="string"){const n=oe(e.backgroundColor);s.uniforms.uBgColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBgColor.value.w;s.uniforms.uBgColor.value.set(e.backgroundColor.r,e.backgroundColor.g,e.backgroundColor.b,n)}if(e.borderColor!==void 0)if(Array.isArray(e.borderColor)){const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor[0],e.borderColor[1],e.borderColor[2],n)}else if(typeof e.borderColor=="string"){const n=oe(e.borderColor);s.uniforms.uBorderColor.value.set(n.color.r,n.color.g,n.color.b,n.alpha)}else{const n=s.uniforms.uBorderColor.value.w;s.uniforms.uBorderColor.value.set(e.borderColor.r,e.borderColor.g,e.borderColor.b,n)}e.opacity!==void 0&&(s.uniforms.uOpacity.value=e.opacity),e.bgOpacity!==void 0&&(s.uniforms.uBgColor.value.w=e.bgOpacity),e.borderOpacity!==void 0&&(s.uniforms.uBorderColor.value.w=e.borderOpacity),s.uniforms.uTexture&&e.texture!==void 0&&(s.uniforms.uTexture.value=e.texture);const t=e.texture!==void 0?e.texture:(r=s.uniforms.uTexture)==null?void 0:r.value;if(t&&(t.image instanceof ImageBitmap||t.image instanceof HTMLImageElement||t.image instanceof HTMLCanvasElement)){const n=t.image.naturalWidth||t.image.videoWidth||t.image.width,o=t.image.naturalHeight||t.image.videoHeight||t.image.height,a=(i=e.width)!=null?i:s.uniforms.uSize.value.x,c=(l=e.height)!=null?l:s.uniforms.uSize.value.y;if(n&&o&&a&&c){const d=n/o,h=a/c;if(d>h){const u=h/d;s.uniforms.uTextureRepeat.value.set(u,1),s.uniforms.uTextureOffset.value.set((1-u)/2,0)}else{const u=d/h;s.uniforms.uTextureRepeat.value.set(1,u),s.uniforms.uTextureOffset.value.set(0,(1-u)/2)}}}else s.uniforms.uTextureRepeat&&(s.uniforms.uTextureRepeat.value.set(1,1),s.uniforms.uTextureOffset.value.set(0,0));if(e.backgroundImage!==void 0){const n=Ve(e.backgroundImage);if(n){s.uniforms.uGradientCount.value=n.stops.length,s.uniforms.uGradientAngle.value=n.angle;for(let o=0;o<8;o++)if(o<n.stops.length){const a=n.stops[o];s.uniforms.uGradientColors.value[o].set(a.color.r,a.color.g,a.color.b,a.alpha),s.uniforms.uGradientStops.value[o]=a.stop}else s.uniforms.uGradientColors.value[o].set(0,0,0,0),s.uniforms.uGradientStops.value[o]=1}else s.uniforms.uGradientCount.value=0}for(const n of Object.keys(e))n!=="width"&&n!=="height"&&n!=="borderRadius"&&n!=="borderWidth"&&n!=="backgroundColor"&&n!=="borderColor"&&n!=="opacity"&&n!=="bgOpacity"&&n!=="borderOpacity"&&n!=="texture"&&n!=="backgroundImage"&&s.uniforms[n]!==void 0&&(s.uniforms[n].value!==void 0&&s.uniforms[n].value!==null&&typeof s.uniforms[n].value.set=="function"?Array.isArray(e[n])?s.uniforms[n].value.set(...e[n]):e[n]!==void 0&&(e[n].copy?s.uniforms[n].value.copy(e[n]):s.uniforms[n].value=e[n]):s.uniforms[n].value=e[n])}function xe(s,e,t=0){var a,c,d,h;if(e==null){s.set(0,0,0,0);return}if(typeof e=="number"){s.set(e,e,e,e);return}if(Array.isArray(e)){s.set(e[0],e[1],e[2],e[3]);return}const r=e.split("/")[0].trim().split(/\s+/),i=ee(r[0],t),l=ee((a=r[1])!=null?a:r[0],t),n=ee((c=r[2])!=null?c:r[0],t),o=ee((h=(d=r[3])!=null?d:r[1])!=null?h:r[0],t);s.set(i,l,n,o)}const H={create(s,e,t,r,i,l=2,n=null,o){return s==="BOX"?$e(e,r,i,n,o):s==="TEXT"?new Ye(t||"",e,r,i,l):new y.MeshBasicMaterial({visible:!1})},update(s,e,t,r,i,l,n=2,o){e==="BOX"?je(s,t,i,l,o):e==="TEXT"&&s.updateText(r||"",t,i,l,n)},forceUpdateUniforms(s,e){de(s,e)}};class Ke{constructor(e,t=!0){g(this,"observer");g(this,"textures",new WeakMap);g(this,"loadStatus",new WeakMap);g(this,"elementUrls",new WeakMap);g(this,"onUpdate");this.onUpdate=e,t&&(this.observer=new IntersectionObserver(r=>{for(const i of r){const 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 Be(this,null,function*(){if(this.loadStatus.get(e)||this.textures.has(e))return;const t=this.elementUrls.get(e);if(t){this.loadStatus.set(e,!0);try{let r;if(t.startsWith("data:image/svg+xml"))r=yield new Promise((l,n)=>{const o=new Image;o.onload=()=>l(o),o.onerror=n,o.src=t});else{const n=yield(yield fetch(t)).blob();r=yield createImageBitmap(n,{imageOrientation:"flipY"})}if(this.elementUrls.get(e)!==t){"close"in r&&r.close();return}const i=new y.Texture(r);r instanceof HTMLImageElement||(i.flipY=!1),i.colorSpace=y.LinearSRGBColorSpace,i.needsUpdate=!0,this.textures.set(e,i),this.onUpdate(e,i)}catch(r){console.warn("[MirageEngine] Failed to load texture:",t,r)}finally{this.elementUrls.has(e)&&this.loadStatus.set(e,!1)}}})}disposeTexture(e){const t=this.textures.get(e);t&&(t.dispose(),this.textures.delete(e),this.onUpdate(e,null)),this.loadStatus.set(e,!1)}get(e){return this.textures.get(e)}disposeAll(){this.observer&&this.observer.disconnect()}}class Je{constructor(e,t,r,i){g(this,"canvas");g(this,"scene");g(this,"camera");g(this,"renderer");g(this,"renderTargets",[]);g(this,"renderOrder",0);g(this,"qualityFactor",2);g(this,"mode","overlay");g(this,"canvasSize","viewport");g(this,"clipArea",1);g(this,"targetLayer","base");g(this,"overscan",200);g(this,"target");g(this,"mountContainer");g(this,"registry");g(this,"targetRect");g(this,"travelersByLayer",Array.from({length:O.MAX_LAYERS},()=>new Set));g(this,"textureManager");g(this,"fixedMeshes",new Set);var o,a,c,d,h;this.target=e,this.mountContainer=r,this.registry=i,this.mode=(o=t.mode)!=null?o:"overlay",this.canvasSize=(a=t.canvasSize)!=null?a:"viewport",this.clipArea=(c=t.travelerClipArea)!=null?c:1,this.targetLayer=(d=t.layer)!=null?d:"base",this.textureManager=new Ke((u,p)=>{const f=this.registry.get(u);f&&f.material instanceof y.ShaderMaterial&&H.forceUpdateUniforms(f.material,{texture:p})},this.isViewport),this.canvas=document.createElement("canvas"),this.scene=new y.Scene,this.targetRect=this.target.getBoundingClientRect();const l=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,n=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.camera=new y.OrthographicCamera(l/-2,l/2,n/2,n/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(this.getSceneLayer()),this.renderer=new y.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),y.ColorManagement.enabled=!1,this.renderer.outputColorSpace=y.LinearSRGBColorSpace,this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(l,n),this.applyTextQuality((h=t.quality)!=null?h:"medium")}get isViewport(){return this.mode==="overlay"&&this.canvasSize==="viewport"}getSceneLayer(){return typeof this.targetLayer=="number"?this.targetLayer:this.targetLayer==="selected"?N.SELECTED:N.BASE}createRenderTarget(){for(let e=0;e<O.MAX_LAYERS;e++){const t=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,r=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.renderTargets.push(new y.WebGLRenderTarget(t*this.qualityFactor,r*this.qualityFactor,{minFilter:y.LinearFilter,magFilter:y.LinearFilter,format:y.RGBAFormat,stencilBuffer:!1,depthBuffer:!0}))}}applyTextQuality(e){if(typeof e=="number"){this.qualityFactor=Math.max(.1,e);return}switch(e){case"low":this.qualityFactor=1;break;case"high":this.qualityFactor=4;break;case"medium":this.qualityFactor=2;break;default:this.qualityFactor=2;break}}mount(){this.mountContainer.prepend(this.canvas),this.canvas.style.pointerEvents=this.mode==="overlay"?"none":"auto",this.updateCanvasLayout()}updateCanvasLayout(){const e=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,t=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height;this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this.mode==="duplicate"?(this.canvas.style.position="",this.canvas.style.top="",this.canvas.style.left="",this.canvas.style.display="block"):(this.canvas.style.position=this.isViewport?"fixed":"absolute",this.canvas.style.top=this.isViewport?`-${this.overscan}px`:`${this.target.offsetTop}px`,this.canvas.style.left=this.isViewport?`-${this.overscan}px`:`${this.target.offsetLeft}px`,this.canvas.style.display="block")}updateUniforms(e,t){const r=this.registry.get(e);r&&(r.traverse(i=>{i.isMesh&&i.material&&H.forceUpdateUniforms(i.material,t)}),r.userData.nativeMesh&&r.userData.nativeMesh.traverse(i=>{i.isMesh&&i.material&&H.forceUpdateUniforms(i.material,t)}))}dispose(){this.renderer.dispose(),this.canvas.remove(),this.textureManager.disposeAll()}setSize(e,t){this.renderer.setSize(e,t);for(const r of this.renderTargets)r.setSize(e*this.qualityFactor,t*this.qualityFactor);this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e,t){const r=this.target.getBoundingClientRect(),i=this.isViewport?window.innerWidth+this.overscan*2:r.width,l=this.isViewport?window.innerHeight+this.overscan*2:r.height,n=this.isViewport?this.canvas.clientWidth:this.targetRect.width,o=this.isViewport?this.canvas.clientHeight:this.targetRect.height,a=Math.abs(i-n)>.1||Math.abs(l-o)>.1,c=this.mode==="overlay"&&(Math.abs(r.top-this.targetRect.top)>.1||Math.abs(r.left-this.targetRect.left)>.1);a?(this.targetRect=r,this.setSize(i,l),this.updateCanvasLayout()):c?(this.targetRect=r,this.updateCanvasLayout()):this.targetRect=r,this.renderOrder=0,this.reconcileNode(e),t.size>0&&t.forEach(d=>{const h=this.registry.get(d);if(h){this.scene.remove(h);for(const u of this.travelersByLayer)u.delete(h);this.fixedMeshes.delete(h),h.geometry.dispose(),h.userData.nativeMesh&&(this.scene.remove(h.userData.nativeMesh),Array.isArray(h.userData.nativeMesh.material)?h.userData.nativeMesh.material.forEach(u=>u.dispose()):h.userData.nativeMesh.material.dispose(),h.userData.nativeMesh.geometry.dispose()),h.traverse(u=>{u instanceof y.Mesh&&(u.geometry&&u.geometry.dispose(),u.material&&(Array.isArray(u.material)?u.material.forEach(p=>p.dispose()):u.material.dispose()))}),this.registry.remove(d),this.textureManager.unregister(d)}})}reconcileNode(e){var i,l;let t=this.registry.get(e.element);const r=JSON.stringify(e.shaderHooks||null);if(t&&t.userData.shaderHash!==r&&(this.scene.remove(t),t.geometry.dispose(),t.material instanceof y.Material&&t.material.dispose(),this.registry.remove(e.element),t=void 0),!t){const n=new y.PlaneGeometry(1,1),o=e.isTraveler?(i=this.renderTargets[e.captureLayer-2])==null?void 0:i.texture:this.textureManager.get(e.element),a=H.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,o,e.shaderHooks);t=new y.Mesh(n,a),e.type==="TEXT"&&(t.name="BG_MESH"),this.scene.add(t),this.registry.register(e.element,t),t.userData.baseMaterial=a,t.userData.domElement=e.element,t.userData.shaderHash=r}if((l=e.nativeStyles)!=null&&l.transform?t.userData.nativeTransform=e.nativeStyles.transform:t.userData.nativeTransform=void 0,this.updateMeshProperties(t,e),this.updateMeshLayers(t,e),e.isTraveler)for(let n=0;n<O.MAX_LAYERS;n++)n===e.captureLayer-2?this.travelersByLayer[n].add(t):this.travelersByLayer[n].delete(t);else for(const n of this.travelersByLayer)n.delete(t);if(e.isFixed?this.fixedMeshes.add(t):this.fixedMeshes.delete(t),e.styles.imageSrc?this.textureManager.register(e.element,e.styles.imageSrc):this.textureManager.unregister(e.element),e.type==="BOX")for(const n of e.children)this.reconcileNode(n);else e.type==="TEXT"&&(this.reconcileTextChild(t,e,!1),t.userData.nativeMesh&&e.nativeStyles&&this.reconcileTextChild(t.userData.nativeMesh,e,!0))}reconcileTextChild(e,t,r){var c;const i=t.textLines||[{text:t.textContent||"",rect:t.rect}],l=r?t.nativeStyles:t.textStyles,n=JSON.stringify(l)+t.textContent+i.map(d=>d.text).join("|"),o=(c=e.userData)==null?void 0:c.textChildStyleHash;if(t.dirtyMask&ce||n!==o){e.children.filter(f=>f.name.startsWith("TEXT_CHILD")).forEach(f=>{var E;const m=f;(E=m.material.map)==null||E.dispose(),m.geometry.dispose(),e.remove(m)});const h=t.rect,u=h.x+h.width/2,p=h.y+h.height/2;i.forEach((f,m)=>{const E=H.create("TEXT",l,f.text,f.rect.width,f.rect.height,this.qualityFactor),M=new y.PlaneGeometry(1,1),D=new y.Mesh(M,E);D.name=`TEXT_CHILD_${m}`;const R=t.rect.width===0?1:f.rect.width/t.rect.width,T=t.rect.height===0?1:f.rect.height/t.rect.height;D.scale.set(R,T,1);const C=f.rect.x+f.rect.width/2,w=f.rect.y+f.rect.height/2,L=C-u,A=-(w-p);D.position.set(t.rect.width===0?0:L/t.rect.width,t.rect.height===0?0:A/t.rect.height,.005),e.add(D)}),e.userData.textChildStyleHash=n}e.children.forEach(d=>{if(!d.name.startsWith("TEXT_CHILD"))return;const h=d,u=t.visibility&W?N.BASE:N.HIDDEN;if(h.layers.set(u),t.visibility&J&&h.layers.enable(N.SELECTED),t.visibility&W)if(!r&&t.nativeLayer!==void 0&&t.nativeStyles!==void 0)for(let p=t.captureLayer;p<t.nativeLayer;p++)h.layers.enable(N.getCaptureLayer(p));else if(r&&t.nativeLayer!==void 0)for(let p=Math.max(t.captureLayer,t.nativeLayer);p<=O.MAX_LAYERS+1;p++)h.layers.enable(N.getCaptureLayer(p));else for(let p=t.captureLayer;p<=O.MAX_LAYERS+1;p++)h.layers.enable(N.getCaptureLayer(p))})}updateMeshProperties(e,t){var R,T,C;const{rect:r,styles:i}=t,l=this.renderer.getPixelRatio(),n=this.renderer.domElement.width/l,o=this.renderer.domElement.height/l;e.material=e.userData.baseMaterial,e.scale.set(r.width,r.height,1),e.userData.domRect={x:r.x,y:r.y,width:r.width,height:r.height};const a=.001;this.renderOrder++;const c=this.targetRect.left+window.scrollX,d=this.targetRect.top+window.scrollY;let h,u;if(this.isViewport)h=r.x-window.innerWidth/2+r.width/2,u=-r.y+window.innerHeight/2-r.height/2;else{const w=r.x-c,L=r.y-d;h=w-n/2+r.width/2,u=-L+o/2-r.height/2}e.position.set(h,u,i.zIndex+this.renderOrder*a);const p=r.x,f=r.y;e.userData.basePosition={x:h,y:u},e.userData.originalBasePosition={x:h,y:u},e.userData.baseSize={width:r.width,height:r.height},e.userData.baseDOM={x:p,y:f},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,E=window.getComputedStyle(m);let M=0,D=0;if(E.transform&&E.transform!=="none"){const w=new DOMMatrix(E.transform);M=w.m41,D=w.m42}if(e.userData.baseTransform={x:M,y:D},delete e.userData.originRatioX,delete e.userData.originRatioY,H.update(e.userData.baseMaterial,"BOX",i,"",r.width,r.height,this.qualityFactor,t.isTraveler?(R=this.renderTargets[t.captureLayer-2])==null?void 0:R.texture:this.textureManager.get(t.element)),t.nativeStyles&&t.nativeRect){if(!e.userData.nativeMesh){const F=H.create("BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(T=this.renderTargets[t.captureLayer-2])==null?void 0:T.texture:this.textureManager.get(t.element),t.shaderHooks),P=new y.Mesh(e.geometry,F);t.type==="TEXT"&&(P.name="BG_MESH"),this.scene.add(P),e.userData.nativeMesh=P}const w=e.userData.nativeMesh;let L,A;if(this.isViewport)L=t.nativeRect.x-window.innerWidth/2+t.nativeRect.width/2,A=-t.nativeRect.y+window.innerHeight/2-t.nativeRect.height/2;else{const F=t.nativeRect.x-c,P=t.nativeRect.y-d;L=F-n/2+t.nativeRect.width/2,A=-P+o/2-t.nativeRect.height/2}w.scale.set(t.nativeRect.width,t.nativeRect.height,1),w.position.set(L,A,t.nativeStyles.zIndex+this.renderOrder*a),H.update(w.material,"BOX",t.nativeStyles,"",t.nativeRect.width,t.nativeRect.height,this.qualityFactor,t.isTraveler?(C=this.renderTargets[t.captureLayer-2])==null?void 0:C.texture:this.textureManager.get(t.element))}else e.userData.nativeMesh&&(this.scene.remove(e.userData.nativeMesh),e.userData.nativeMesh.material instanceof y.Material&&e.userData.nativeMesh.material.dispose(),delete e.userData.nativeMesh)}updateMeshLayers(e,t){const r=t.visibility&W?N.BASE:N.HIDDEN;if(e.layers.set(r),t.visibility&J&&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&W){for(let l=t.captureLayer;l<t.nativeLayer;l++)e.layers.enable(N.getCaptureLayer(l));for(let l=Math.max(t.captureLayer,t.nativeLayer);l<=O.MAX_LAYERS+1;l++)i.layers.enable(N.getCaptureLayer(l))}}else if(t.visibility&W)for(let i=t.captureLayer;i<=O.MAX_LAYERS+1;i++)e.layers.enable(N.getCaptureLayer(i))}captureRenderTarget(e,t,r){if(e.size===0||!r)return;const i=new y.Color,l=this.renderer.getClearAlpha();this.renderer.getClearColor(i),this.renderer.setClearColor(0,0),this.renderer.setRenderTarget(r),this.renderer.clear(),this.renderer.autoClear=!1,this.renderer.setScissorTest(!0),this.camera.layers.set(t);const n=new y.Vector3,o=this.isViewport?window.innerWidth+this.overscan*2:this.targetRect.width,a=this.isViewport?window.innerHeight+this.overscan*2:this.targetRect.height,c=this.renderer.getPixelRatio();for(const d of e){n.setFromMatrixPosition(d.matrixWorld),n.project(this.camera);const h=(n.x+1)/2*o,u=(n.y+1)/2*a;let p=0,f=1;typeof this.clipArea=="number"?f=this.clipArea:this.clipArea.endsWith("%")?f=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(p=parseFloat(this.clipArea));const m=d.scale.x*f+.5,E=d.scale.y*f+.5,M=h-m/2,D=u-E/2,R=(M*this.qualityFactor-p)/c,T=(D*this.qualityFactor-p)/c,C=(m*this.qualityFactor+p*2)/c,w=(E*this.qualityFactor+p*2)/c;this.renderer.setScissor(R,T,C,w),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(this.getSceneLayer()),this.renderer.setClearColor(i,l)}render(){for(let e=0;e<O.MAX_LAYERS;e++){const t=e+1;this.captureRenderTarget(this.travelersByLayer[e],N.getCaptureLayer(t),this.renderTargets[e])}this.renderer.render(this.scene,this.camera)}syncMeshesByDOM(){const e=this.targetRect.left+window.scrollX,t=this.targetRect.top+window.scrollY,r=this.renderer.getPixelRatio(),i=this.renderer.domElement.width/r,l=this.renderer.domElement.height/r;this.scene.children.forEach(n=>{const o=n;if(!o.userData||!o.userData.domElement)return;const a=o.userData.domElement;if(!a.isConnected)return;let c;if(a.nodeType===Node.TEXT_NODE){const h=document.createRange();h.selectNode(a),c=h.getBoundingClientRect()}else c=a.getBoundingClientRect();const d=o.userData.domRect;if(!d||Math.abs(c.x-d.x)>.5||Math.abs(c.y-d.y)>.5||Math.abs(c.width-d.width)>.5||Math.abs(c.height-d.height)>.5){o.userData.domRect={x:c.x,y:c.y,width:c.width,height:c.height};let h,u;if(this.isViewport)h=c.x-window.innerWidth/2+c.width/2,u=-c.y+window.innerHeight/2-c.height/2;else{const p=c.x-e,f=c.y-t;h=p-i/2+c.width/2,u=-f+l/2-c.height/2}if(o.position.setX(h),o.position.setY(u),o.scale.set(c.width,c.height,1),o.updateMatrixWorld(),o.material instanceof y.ShaderMaterial&&H.forceUpdateUniforms(o.material,{width:c.width,height:c.height}),o.userData.nativeMesh){const p=o.userData.nativeMesh;let f=c.width,m=c.height,E=h,M=u;if(o.userData.nativeTransform){const D=o.userData.nativeTransform,R=D.match(/scale\(([\d.]+%?)\)/);if(R){let L=parseFloat(R[1]);R[1].includes("%")&&(L/=100),f*=L,m*=L}const T=D.match(/translate\(([^,]+),\s*([^)]+)\)/);if(T){const L=T[1].trim(),A=T[2].trim();let F=parseFloat(L);L.includes("%")&&(F=F/100*c.width);let P=parseFloat(A);A.includes("%")&&(P=P/100*c.height),E+=F,M-=P}const C=D.match(/translateX\(([^)]+)\)/);if(C){const L=C[1].trim();let A=parseFloat(L);L.includes("%")&&(A=A/100*c.width),E+=A}const w=D.match(/translateY\(([^)]+)\)/);if(w){const L=w[1].trim();let A=parseFloat(L);L.includes("%")&&(A=A/100*c.height),M-=A}}p.position.setX(E),p.position.setY(M),p.scale.set(f,m,1),p.updateMatrixWorld()}}})}}function Ze(s){const e=s.textContent||"",t=[];let r="",i=null,l=-1;const n=(c,d)=>{for(let h=0;h<c.length;h++){const u=c[h],p=document.createRange();p.setStart(s,d+h),p.setEnd(s,d+h+1);const f=p.getBoundingClientRect();if(f.width===0&&f.height===0){r+=u;continue}l===-1||Math.abs(f.top-l)>f.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=u,i={left:f.left,top:f.top,right:f.right,bottom:f.bottom},l=f.top):(r+=u,i&&(i.left=Math.min(i.left,f.left),i.top=Math.min(i.top,f.top),i.right=Math.max(i.right,f.right),i.bottom=Math.max(i.bottom,f.bottom)))}},o=e.match(/[^\s\-]+\-?|\-|\s+/g)||[];let a=0;for(const c of o){const d=document.createRange();d.setStart(s,a),d.setEnd(s,a+c.length);const h=d.getClientRects();if(h.length>1)n(c,a);else{const u=h.length===1?h[0]:d.getBoundingClientRect();if(u.width===0&&u.height===0){r+=c,a+=c.length;continue}l===-1||Math.abs(u.top-l)>u.height/2?(r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),r=c,i={left:u.left,top:u.top,right:u.right,bottom:u.bottom},l=u.top):(r+=c,i&&(i.left=Math.min(i.left,u.left),i.top=Math.min(i.top,u.top),i.right=Math.max(i.right,u.right),i.bottom=Math.max(i.bottom,u.bottom)))}a+=c.length}return r&&i&&t.push({text:r,rect:{left:i.left,top:i.top,width:i.right-i.left,height:i.bottom-i.top}}),t.filter(c=>c.text.trim().length>0&&c.rect.width>0&&c.rect.height>0)}function Ce(s){const e=parseFloat(s.fontSize);let t=parseFloat(s.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(s.letterSpacing);return isNaN(r)&&(r=0),{font:`${s.fontStyle} ${s.fontWeight} ${s.fontSize} ${s.fontFamily}`,fontSize:s.fontSize,color:s.color,textAlign:s.textAlign||"start",textBaseline:"alphabetic",direction:s.direction||"inherit",lineHeight:t,letterSpacing:r}}function Se(s,e=j|Q|ve|ce|ne,t,r=1,i=0,l=2,n,o){var Le,Me,De,Ae,Ie,ke;if(s.nodeType===Node.TEXT_NODE){const v=s;if(!v.textContent||!v.textContent.trim())return null;const _=v.textContent.replace(/\s+/g," ");if(_.length===0)return null;const Y=Ze(v);if(Y.length===0)return null;const G=v.parentElement,B=G?window.getComputedStyle(G):null;if(!B)return null;const $=Math.min(...Y.map(x=>x.rect.left)),z=Math.min(...Y.map(x=>x.rect.top)),K=Math.max(...Y.map(x=>x.rect.left+x.rect.width)),I=Math.max(...Y.map(x=>x.rect.top+x.rect.height));return{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:v,rect:{x:$+window.scrollX,y:z+window.scrollY,width:K-$,height:I-z},styles:{backgroundColor:"transparent",backgroundImage:"",opacity:G&&G.dataset[V.KEY]===V.VALUES.HIDE?1:parseFloat(B.opacity),zIndex:(isNaN(parseInt(B.zIndex))?0:parseInt(B.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},textContent:_,textLines:Y.map(x=>({text:x.text.trim(),rect:{x:x.rect.left+window.scrollX,y:x.rect.top+window.scrollY,width:x.rect.width,height:x.rect.height}})),textStyles:Ce(B),dirtyMask:e,visibility:t,isTraveler:!1,captureLayer:r,isFixed:B.position==="fixed",nativeLayer:n,nativeStyles:o?Z(Z({backgroundColor:"transparent",backgroundImage:"",opacity:G&&G.dataset[V.KEY]===V.VALUES.HIDE?1:parseFloat(B.opacity),zIndex:(isNaN(parseInt(B.zIndex))?0:parseInt(B.zIndex))+i,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px",isTraveler:!1},Ce(B)),o):void 0,nativeRect:o?{x:$+window.scrollX,y:z+window.scrollY,width:K-$,height:I-z}:void 0,children:[]}}if(s.nodeType!==Node.ELEMENT_NODE)return null;const a=s,c=a.dataset[U.KEY];let d=t,h=t;if(c){const v=new Set(c.split(/\s+/));for(const _ of v)if(!he.includes(_))throw new Error(`[MirageEngine] Invalid filter token: '${_}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(v.has(U.VALUES.END))return null;if(v.has(U.VALUES.INCLUDE_TREE)&&v.has(U.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(v.has(U.VALUES.INCLUDE_SELF)&&v.has(U.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");v.has(U.VALUES.INCLUDE_TREE)?d=d|W:v.has(U.VALUES.EXCLUDE_TREE)&&(d=d&~W),h=d,v.has(U.VALUES.INCLUDE_SELF)?h=h|W:v.has(U.VALUES.EXCLUDE_SELF)&&(h=h&~W)}const u=a.dataset[X.KEY];if(u){const v=new Set(u.split(/\s+/));for(const _ of v)if(!he.includes(_))throw new Error(`[MirageEngine] Invalid select token: '${_}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(v.has(X.VALUES.END))return null;if(v.has(X.VALUES.INCLUDE_TREE)&&v.has(X.VALUES.EXCLUDE_TREE))throw new Error("[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(v.has(X.VALUES.INCLUDE_SELF)&&v.has(X.VALUES.EXCLUDE_SELF))throw new Error("[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element.");v.has(X.VALUES.INCLUDE_TREE)?d=d|J:v.has(X.VALUES.EXCLUDE_TREE)&&(d=d&~J),h=d,v.has(X.VALUES.INCLUDE_SELF)?h=h|J:v.has(X.VALUES.EXCLUDE_SELF)&&(h=h&~J)}const p=a.dataset[O.KEY];let f=!1,m=o?Z({},o):{},E=n;if(p){let v=1;const _=p.indexOf("{"),Y=p.lastIndexOf("}");let G=p;if(_!==-1&&Y!==-1&&Y>_){G=p.substring(0,_).trim();const I=p.substring(_,Y+1);try{m=new Function("return "+I)()}catch(x){console.warn(`[MirageEngine] Failed to parse travel styles JSON: ${I}`)}}const B=G.split(/\s+/);let $=!1;const z=B.indexOf(O.VALUES.TRAVELER);if(z!==-1){f=!0,$=!0;const I=B[z+1];if(I&&!isNaN(parseInt(I,10)))v=parseInt(I,10);else{const x=B.find(te=>!isNaN(parseInt(te,10)));x&&(v=parseInt(x,10))}}const K=B.indexOf(O.VALUES.NATIVE);if(K!==-1){const I=B[K+1];if(I&&!isNaN(parseInt(I,10)))E=parseInt(I,10);else if(!f){const x=B.find(te=>!isNaN(parseInt(te,10)));x&&(E=parseInt(x,10))}}if($){const I=v+1;if(I<r)throw new Error(`[MirageEngine] Traveler layer (${v}) cannot be smaller than inherited capture layer (${r-1}).`);r=Math.min(I,O.MAX_LAYERS+1)}}const M=a.dataset[me.KEY];let D;M&&(D=JSON.parse(M));const R=a.getBoundingClientRect(),T=window.getComputedStyle(a);if(R.width===0||R.height===0||T.display==="none")return null;let C=a.getAttribute("data-mid");C||(C=Math.random().toString(36).substring(2,11),a.setAttribute("data-mid",C));const w=parseInt(T.zIndex),L=(isNaN(w)?0:w)+i;let A;if(a.tagName==="IMG")A=a.src;else if(a.tagName.toLowerCase()==="svg"){const v=a.cloneNode(!0),_=m==null?void 0:m.color,Y=m==null?void 0:m.fill,G=m==null?void 0:m.stroke,B=m==null?void 0:m.opacity,$=(x,te)=>{const q=window.getComputedStyle(x),ae=te,nt=q.fill===q.color,ot=q.stroke===q.color,ue=Y||(nt?_:void 0)||q.fill;ue&&ue!=="none"&&(ae.style.fill=ue);const fe=G||(ot?_:void 0)||q.stroke;fe&&fe!=="none"&&(ae.style.stroke=fe),q.strokeWidth&&q.strokeWidth!=="0px"&&(ae.style.strokeWidth=q.strokeWidth);const Ue=_||q.color;Ue&&(ae.style.color=Ue);const ge=B||q.opacity;ge&&ge!=="1"&&(ae.style.opacity=ge);for(let le=0;le<x.children.length;le++)$(x.children[le],te.children[le])};$(a,v);const z=a.getBoundingClientRect(),K=window.devicePixelRatio*l;v.hasAttribute("viewBox")||v.setAttribute("viewBox",`0 0 ${z.width} ${z.height}`),v.setAttribute("width",(z.width*K).toString()),v.setAttribute("height",(z.height*K).toString());let I=new XMLSerializer().serializeToString(v);I.includes("xmlns=")||(I=I.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"')),A=`data:image/svg+xml;utf8,${encodeURIComponent(I)}`}else if(T.backgroundImage&&T.backgroundImage!=="none"){const v=T.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);v&&(A=v[1])}const F={backgroundColor:T.backgroundColor,backgroundImage:T.backgroundImage,opacity:a.dataset[V.KEY]===V.VALUES.HIDE?1:parseFloat(T.opacity),zIndex:L,borderRadius:T.borderRadius,borderColor:T.borderColor,borderWidth:T.borderWidth,imageSrc:A,isTraveler:f},P=F;let it,st;const Re=[];return a.tagName.toLowerCase()!=="svg"&&Array.from(a.childNodes).forEach(v=>{const _=v.nodeType===Node.TEXT_NODE?h:d,Y=Se(v,e,_,r,L,l,v.nodeType===Node.TEXT_NODE?E:void 0,v.nodeType===Node.TEXT_NODE&&Object.keys(m).length>0?m:void 0);Y&&Re.push(Y)}),{id:C,type:"BOX",element:a,rect:{x:R.left+window.scrollX,y:R.top+window.scrollY,width:R.width,height:R.height},styles:P,textContent:it,textStyles:st,dirtyMask:e,visibility:h,isTraveler:f,captureLayer:r,nativeLayer:E,nativeStyles:E!==void 0?_e(Z({},F),{backgroundColor:(Le=m.backgroundColor)!=null?Le:F.backgroundColor,backgroundImage:(Me=m.backgroundImage)!=null?Me:F.backgroundImage,opacity:(De=m.opacity)!=null?De:F.opacity,zIndex:m.zIndex!==void 0?m.zIndex+L:F.zIndex,borderRadius:(Ae=m.borderRadius)!=null?Ae:F.borderRadius,borderColor:(Ie=m.borderColor)!=null?Ie:F.borderColor,borderWidth:(ke=m.borderWidth)!=null?ke:F.borderWidth,isTraveler:F.isTraveler,transform:m.transform}):void 0,nativeRect:E!==void 0?{x:m.x!==void 0?parseFloat(m.x):R.left+window.scrollX,y:m.y!==void 0?parseFloat(m.y):R.top+window.scrollY,width:m.width!==void 0?parseFloat(m.width):R.width,height:m.height!==void 0?parseFloat(m.height):R.height}:void 0,isFixed:T.position==="fixed",children:Re,shaderHooks:D}}function Qe(s,e){e.size!==0&&e.forEach((t,r)=>{var l,n,o,a;const i=s.get(r);!i||!i.userData.basePosition||(H.forceUpdateUniforms(i.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(n=t.borderRadius)!=null?n:(l=i.userData.baseStyles)==null?void 0:l.borderRadius}),i.userData.nativeMesh&&H.forceUpdateUniforms(i.userData.nativeMesh.material,{backgroundColor:t.backgroundColor,backgroundImage:t.backgroundImage,opacity:t.opacity,borderRadius:(a=t.borderRadius)!=null?a:(o=i.userData.baseStyles)==null?void 0:o.borderRadius}))})}class et{constructor(e,t,r,i){g(this,"target");g(this,"renderer");g(this,"registry");g(this,"isTravelEnabled",!1);g(this,"tracker");this.target=e,this.renderer=t,this.registry=r,this.tracker=new be(e,{resizeDebounce:i.resizeDebounce}),this.tracker.onLayoutChange.add((l,n)=>{document.querySelector(`[${O.NAME}~='${O.VALUES.TRAVELER}']`)!==null&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const a=Se(this.target,l,W,1,0,this.renderer.qualityFactor);a&&this.renderer.syncScene(a,n)}),this.tracker.onStyleChange.add(l=>{Qe(this.registry,l)}),this.tracker.onRender.add(()=>{this.renderer.syncMeshesByDOM(),this.renderer.render()})}start(){this.tracker.start()}stop(){this.tracker.stop()}}class tt{constructor(){g(this,"store");this.store=new WeakMap}register(e,t){this.store.set(e,t)}get(e){return this.store.get(e)}has(e){return this.store.has(e)}remove(e){this.store.delete(e)}}class rt{constructor(e,t){g(this,"renderer");g(this,"syncer");g(this,"target");g(this,"registry");var i,l,n;if(this.target=e,this.registry=new tt,!document.getElementById("mirage-engine-styles")){const o=document.createElement("style");o.id="mirage-engine-styles",o.textContent=`
165
165
  [${V.NAME}="${V.VALUES.HIDE}"] {
166
166
  opacity: 0 !important;
167
167
  }
168
- `,document.head.appendChild(o)}let r;if(t.mode==="duplicate"?r=(c=(i=t.container)!=null?i:this.target.parentElement)!=null?c:void 0:r=(n=this.target.parentElement)!=null?n:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new Je(this.target,t,r,this.registry),this.renderer.mount(),this.syncer=new et(this.target,this.renderer,this.registry,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}getTracker(){return this.syncer.tracker}updateUniforms(e,t){this.renderer.updateUniforms(e,t)}getCanvas(){return this.renderer.canvas}test(){const e=this.registry.get(document.querySelector("#box2"));if(!e)return;const t={ArrowRight:!1,ArrowLeft:!1,ArrowUp:!1,ArrowDown:!1};window.addEventListener("keydown",c=>{t[c.key]!==void 0&&(t[c.key]=!0)}),window.addEventListener("keyup",c=>{t[c.key]!==void 0&&(t[c.key]=!1)});const r=2,i=()=>{requestAnimationFrame(i),t.ArrowRight&&e.position.setX(e.position.x+r),t.ArrowLeft&&e.position.setX(e.position.x-r),t.ArrowUp&&e.position.setY(e.position.y+r),t.ArrowDown&&e.position.setY(e.position.y-r)};i()}}b.ALLOWED_FILTERS=he,b.ATTR_DOM=V,b.ATTR_FILTER=A,b.ATTR_SANDWICH=Fe,b.ATTR_SELECT=B,b.ATTR_SHADER=me,b.ATTR_TRAVEL=I,b.DIRTY_CONTENT=ce,b.DIRTY_NONE=se,b.DIRTY_RECT=$,b.DIRTY_STRUCTURE=ne,b.DIRTY_STYLE=Q,b.DIRTY_ZINDEX=ve,b.EXCLUDED=Xe,b.Engine=rt,b.SELECT_LAYER=K,b.THREE_LAYERS=_,b.TRAVEL_VALUES=ie,b.Tracker=be,b.USER_LAYER=W,b.extractFromStyle=ye,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
168
+ `,document.head.appendChild(o)}let r;if(t.mode==="duplicate"?r=(l=(i=t.container)!=null?i:this.target.parentElement)!=null?l:void 0:r=(n=this.target.parentElement)!=null?n:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new Je(this.target,t,r,this.registry),this.renderer.mount(),this.syncer=new et(this.target,this.renderer,this.registry,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}getTracker(){return this.syncer.tracker}updateUniforms(e,t){this.renderer.updateUniforms(e,t)}getCanvas(){return this.renderer.canvas}test(){const e=this.registry.get(document.querySelector("#box2"));if(!e)return;const t={ArrowRight:!1,ArrowLeft:!1,ArrowUp:!1,ArrowDown:!1};window.addEventListener("keydown",l=>{t[l.key]!==void 0&&(t[l.key]=!0)}),window.addEventListener("keyup",l=>{t[l.key]!==void 0&&(t[l.key]=!1)});const r=2,i=()=>{requestAnimationFrame(i),t.ArrowRight&&e.position.setX(e.position.x+r),t.ArrowLeft&&e.position.setX(e.position.x-r),t.ArrowUp&&e.position.setY(e.position.y+r),t.ArrowDown&&e.position.setY(e.position.y-r)};i()}}b.ALLOWED_FILTERS=he,b.ATTR_DOM=V,b.ATTR_FILTER=U,b.ATTR_SANDWICH=Fe,b.ATTR_SELECT=X,b.ATTR_SHADER=me,b.ATTR_TRAVEL=O,b.DIRTY_CONTENT=ce,b.DIRTY_NONE=se,b.DIRTY_RECT=j,b.DIRTY_STRUCTURE=ne,b.DIRTY_STYLE=Q,b.DIRTY_ZINDEX=ve,b.EXCLUDED=Xe,b.Engine=rt,b.SELECT_LAYER=J,b.THREE_LAYERS=N,b.TRAVEL_VALUES=ie,b.Tracker=be,b.USER_LAYER=W,b.extractFromStyle=ye,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirage-engine/core",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "main": "src/index.ts",
5
5
  "types": "src/index.ts",
6
6
  "peerDependencies": {
@@ -923,7 +923,23 @@ export class Renderer {
923
923
  if (tyStr.includes("%")) ty = (ty / 100) * rect.height;
924
924
 
925
925
  nPosX += tx;
926
- nPosY -= ty; // Three.js Y is up, so subtract positive Y translation to move down
926
+ nPosY -= ty;
927
+ }
928
+
929
+ const translateXMatch = transformStr.match(/translateX\(([^)]+)\)/);
930
+ if (translateXMatch) {
931
+ const txStr = translateXMatch[1].trim();
932
+ let tx = parseFloat(txStr);
933
+ if (txStr.includes("%")) tx = (tx / 100) * rect.width;
934
+ nPosX += tx;
935
+ }
936
+
937
+ const translateYMatch = transformStr.match(/translateY\(([^)]+)\)/);
938
+ if (translateYMatch) {
939
+ const tyStr = translateYMatch[1].trim();
940
+ let ty = parseFloat(tyStr);
941
+ if (tyStr.includes("%")) ty = (ty / 100) * rect.height;
942
+ nPosY -= ty;
927
943
  }
928
944
  }
929
945