mirage-engine 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,46 +1,47 @@
1
- var _e = Object.defineProperty, ze = Object.defineProperties;
2
- var Xe = Object.getOwnPropertyDescriptors;
3
- var Ee = Object.getOwnPropertySymbols;
4
- var Ne = Object.prototype.hasOwnProperty, Ye = Object.prototype.propertyIsEnumerable;
5
- var ge = (s, e, t) => e in s ? _e(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, G = (s, e) => {
1
+ var _e = Object.defineProperty, Fe = Object.defineProperties;
2
+ var Ne = Object.getOwnPropertyDescriptors;
3
+ var be = Object.getOwnPropertySymbols;
4
+ var ze = Object.prototype.hasOwnProperty, Xe = Object.prototype.propertyIsEnumerable;
5
+ var oe = (s, e, t) => e in s ? _e(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, $ = (s, e) => {
6
6
  for (var t in e || (e = {}))
7
- Ne.call(e, t) && ge(s, t, e[t]);
8
- if (Ee)
9
- for (var t of Ee(e))
10
- Ye.call(e, t) && ge(s, t, e[t]);
7
+ ze.call(e, t) && oe(s, t, e[t]);
8
+ if (be)
9
+ for (var t of be(e))
10
+ Xe.call(e, t) && oe(s, t, e[t]);
11
11
  return s;
12
- }, pe = (s, e) => ze(s, Xe(e));
13
- var d = (s, e, t) => (ge(s, typeof e != "symbol" ? e + "" : e, t), t);
14
- var Ce = (s, e, t) => new Promise((i, r) => {
15
- var o = (a) => {
12
+ }, we = (s, e) => Fe(s, Ne(e));
13
+ var u = (s, e, t) => (oe(s, typeof e != "symbol" ? e + "" : e, t), t);
14
+ var Ee = (s, e, t) => new Promise((i, r) => {
15
+ var o = (c) => {
16
16
  try {
17
- c(t.next(a));
17
+ a(t.next(c));
18
18
  } catch (l) {
19
19
  r(l);
20
20
  }
21
- }, n = (a) => {
21
+ }, n = (c) => {
22
22
  try {
23
- c(t.throw(a));
23
+ a(t.throw(c));
24
24
  } catch (l) {
25
25
  r(l);
26
26
  }
27
- }, c = (a) => a.done ? i(a.value) : Promise.resolve(a.value).then(o, n);
28
- c((t = t.apply(s, e)).next());
27
+ }, a = (c) => c.done ? i(c.value) : Promise.resolve(c.value).then(o, n);
28
+ a((t = t.apply(s, e)).next());
29
29
  });
30
30
  import * as y from "three";
31
- const Ae = {
31
+ const Re = {
32
32
  INCLUDE_TREE: "include-tree",
33
33
  EXCLUDE_TREE: "exclude-tree",
34
34
  INCLUDE_SELF: "include-self",
35
35
  EXCLUDE_SELF: "exclude-self",
36
36
  END: "end"
37
- }, $ = {
37
+ }, H = {
38
38
  NAME: "data-mirage-dom",
39
39
  KEY: "mirageDom",
40
40
  VALUES: {
41
- HIDE: "hide"
41
+ HIDE: "hide",
42
+ SHOW: "show"
42
43
  }
43
- }, Te = {
44
+ }, xe = {
44
45
  TRAVELER: "traveler",
45
46
  NATIVE: "native",
46
47
  CAPTURE_1: "1",
@@ -48,30 +49,30 @@ const Ae = {
48
49
  CAPTURE_3: "3",
49
50
  CAPTURE_4: "4",
50
51
  CAPTURE_5: "5"
51
- }, F = {
52
+ }, I = {
52
53
  NAME: "data-mirage-travel",
53
54
  KEY: "mirageTravel",
54
- VALUES: Te,
55
- MAX_LAYERS: Object.keys(Te).length - 1
56
- }, N = {
55
+ VALUES: xe,
56
+ MAX_LAYERS: Object.keys(xe).length - 1
57
+ }, F = {
57
58
  NAME: "data-mirage-filter",
58
59
  KEY: "mirageFilter",
59
- VALUES: Ae
60
+ VALUES: Re
60
61
  }, V = {
61
62
  NAME: "data-mirage-select",
62
63
  KEY: "mirageSelect",
63
- VALUES: Ae
64
+ VALUES: Re
64
65
  }, Ve = {
65
66
  NAME: "data-mirage-shader",
66
67
  KEY: "mirageShader"
67
- }, Se = {
68
+ }, Ce = {
68
69
  NAME: "data-mirage-sandwich",
69
70
  KEY: "mirageSandwich",
70
71
  VALUES: {
71
72
  FRONT: "front"
72
73
  }
73
- }, he = 0, q = 1, ne = 2, We = 4, ve = 8, ye = 16;
74
- function Pe(s) {
74
+ }, te = 0, q = 1, Q = 2, Ye = 4, re = 8, ce = 16;
75
+ function We(s) {
75
76
  const e = s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
76
77
  return e ? {
77
78
  r: parseInt(e[1]) / 255,
@@ -82,7 +83,7 @@ function Pe(s) {
82
83
  function He(s) {
83
84
  const e = {};
84
85
  if (s.opacity && (e.opacity = parseFloat(s.opacity)), s.backgroundColor && s.backgroundColor !== "rgba(0, 0, 0, 0)") {
85
- const t = Pe(s.backgroundColor);
86
+ const t = We(s.backgroundColor);
86
87
  e.backgroundColor = [t.r, t.g, t.b];
87
88
  }
88
89
  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") {
@@ -91,34 +92,34 @@ function He(s) {
91
92
  }
92
93
  return e;
93
94
  }
94
- class ke {
95
+ class Me {
95
96
  constructor(e, t) {
96
- d(this, "target");
97
- d(this, "observer");
98
- d(this, "pendingDeletions", /* @__PURE__ */ new Set());
99
- d(this, "pendingStyles", /* @__PURE__ */ new Map());
100
- d(this, "isDomDirty", !1);
101
- d(this, "isRunning", !1);
102
- d(this, "pendingMask", he);
103
- d(this, "mutationTimer", null);
104
- d(this, "cssTimer", null);
105
- d(this, "resizeConfig");
106
- d(this, "resizeTimer", null);
107
- d(this, "isResizing", !1);
108
- d(this, "lastScrollX", 0);
109
- d(this, "lastScrollY", 0);
110
- d(this, "scrollTimer", null);
111
- d(this, "onBeforeRender", /* @__PURE__ */ new Set());
112
- d(this, "onLayoutChange", /* @__PURE__ */ new Set());
113
- d(this, "onStyleChange", /* @__PURE__ */ new Set());
114
- d(this, "onScrollChange", /* @__PURE__ */ new Set());
115
- d(this, "onRender", /* @__PURE__ */ new Set());
116
- d(this, "onTransitionFinished", (e) => {
117
- this.target.contains(e.target) && this.mutationTimer === null && (this.cssTimer && clearTimeout(this.cssTimer), this.pendingStyles.size == 0 && (this.pendingMask |= q | ne, this.cssTimer = window.setTimeout(() => {
97
+ u(this, "target");
98
+ u(this, "observer");
99
+ u(this, "pendingDeletions", /* @__PURE__ */ new Set());
100
+ u(this, "pendingStyles", /* @__PURE__ */ new Map());
101
+ u(this, "isDomDirty", !1);
102
+ u(this, "isRunning", !1);
103
+ u(this, "pendingMask", te);
104
+ u(this, "mutationTimer", null);
105
+ u(this, "cssTimer", null);
106
+ u(this, "resizeConfig");
107
+ u(this, "resizeTimer", null);
108
+ u(this, "isResizing", !1);
109
+ u(this, "lastScrollX", 0);
110
+ u(this, "lastScrollY", 0);
111
+ u(this, "scrollTimer", null);
112
+ u(this, "onBeforeRender", /* @__PURE__ */ new Set());
113
+ u(this, "onLayoutChange", /* @__PURE__ */ new Set());
114
+ u(this, "onStyleChange", /* @__PURE__ */ new Set());
115
+ u(this, "onScrollChange", /* @__PURE__ */ new Set());
116
+ u(this, "onRender", /* @__PURE__ */ new Set());
117
+ u(this, "onTransitionFinished", (e) => {
118
+ this.target.contains(e.target) && this.mutationTimer === null && (this.cssTimer && clearTimeout(this.cssTimer), this.pendingStyles.size == 0 && (this.pendingMask |= q | Q, this.cssTimer = window.setTimeout(() => {
118
119
  this.isDomDirty = !0, this.cssTimer = null;
119
120
  }, 50)));
120
121
  });
121
- d(this, "onWindowResize", () => {
122
+ u(this, "onWindowResize", () => {
122
123
  if (!this.resizeConfig.enabled) {
123
124
  this.isDomDirty = !0;
124
125
  return;
@@ -127,10 +128,10 @@ class ke {
127
128
  this.isDomDirty = !0, this.resizeConfig.onEnd && this.resizeConfig.onEnd(), this.isResizing = !1, this.resizeTimer = null;
128
129
  }, this.resizeConfig.delay);
129
130
  });
130
- d(this, "renderLoop", () => {
131
+ u(this, "renderLoop", () => {
131
132
  if (!this.isRunning)
132
133
  return;
133
- this.onBeforeRender.forEach((i) => i()), this.isDomDirty && (this.isDomDirty = !1, this.onLayoutChange.forEach((i) => i(this.pendingMask, this.pendingDeletions)), this.pendingDeletions.clear(), this.pendingMask = he);
134
+ this.onBeforeRender.forEach((i) => i()), this.isDomDirty && (this.isDomDirty = !1, this.onLayoutChange.forEach((i) => i(this.pendingMask, this.pendingDeletions)), this.pendingDeletions.clear(), this.pendingMask = te);
134
135
  const e = window.scrollX, t = window.scrollY;
135
136
  (e !== this.lastScrollX || t !== this.lastScrollY) && (this.onScrollChange.forEach((i) => i(e, t)), this.lastScrollX = e, this.lastScrollY = t, this.scrollTimer && clearTimeout(this.scrollTimer), this.scrollTimer = window.setTimeout(() => {
136
137
  this.pendingMask |= q, this.isDomDirty = !0, this.scrollTimer = null;
@@ -145,23 +146,23 @@ class ke {
145
146
  onStart: i.onStart,
146
147
  onEnd: i.onEnd
147
148
  }, this.observer = new MutationObserver((n) => {
148
- let c = he;
149
- for (const a of n)
150
- if (a.type === "childList")
151
- c |= ve, a.removedNodes.length > 0 && a.removedNodes.forEach((l) => {
149
+ let a = te;
150
+ for (const c of n)
151
+ if (c.type === "childList")
152
+ a |= re, c.removedNodes.length > 0 && c.removedNodes.forEach((l) => {
152
153
  l instanceof HTMLElement && this.pendingDeletions.add(l);
153
154
  });
154
- else if (a.type === "attributes")
155
- if (a.attributeName === "style") {
156
- c |= q | ne;
157
- const l = a.target, u = He(l.style);
158
- this.pendingStyles.set(l, u);
155
+ else if (c.type === "attributes")
156
+ if (c.attributeName === "style") {
157
+ a |= q | Q;
158
+ const l = c.target, d = He(l.style);
159
+ this.pendingStyles.set(l, d);
159
160
  } else
160
- (a.attributeName === "class" || a.attributeName && a.attributeName.startsWith("data-")) && (c |= q | ne);
161
+ c.attributeName === "class" ? a |= q | Q : c.attributeName && c.attributeName.startsWith("data-") && (a |= q | Q, c.attributeName.startsWith("data-mirage") && (a |= re));
161
162
  else
162
- a.type === "characterData" && (c |= ye | q);
163
- if (c !== he) {
164
- if (this.pendingMask |= c, c & ve) {
163
+ c.type === "characterData" && (a |= ce | q);
164
+ if (a !== te) {
165
+ if (this.pendingMask |= a, a & re) {
165
166
  this.clearTimers(), this.isDomDirty = !0;
166
167
  return;
167
168
  }
@@ -186,13 +187,13 @@ class ke {
186
187
  this.mutationTimer && (clearTimeout(this.mutationTimer), this.mutationTimer = null), this.cssTimer && (clearTimeout(this.cssTimer), this.cssTimer = null), this.scrollTimer && (clearTimeout(this.scrollTimer), this.scrollTimer = null);
187
188
  }
188
189
  }
189
- const W = 1, j = 2, k = {
190
+ const W = 1, j = 2, R = {
190
191
  BASE: 0,
191
192
  SELECTED: 1,
192
193
  getCaptureLayer: (s) => 31 - s,
193
194
  HIDDEN: 31
194
- }, Le = Object.values(N.VALUES);
195
- class Ie {
195
+ }, Te = Object.values(F.VALUES);
196
+ class Ae {
196
197
  /**
197
198
  * Calculates or retrieves the exact alphabetic baseline (in pixels) for the given font.
198
199
  * @param font CSS font shorthand string (e.g., "400 16px Inter")
@@ -213,17 +214,17 @@ class Ie {
213
214
  return document.body.removeChild(t), o;
214
215
  }
215
216
  }
216
- d(Ie, "cache", /* @__PURE__ */ new Map());
217
- class Ge extends y.MeshBasicMaterial {
217
+ u(Ae, "cache", /* @__PURE__ */ new Map());
218
+ class Pe extends y.MeshBasicMaterial {
218
219
  constructor(t, i, r, o, n = 2) {
219
220
  super({
220
221
  transparent: !0,
221
222
  side: y.FrontSide,
222
223
  color: 16777215
223
224
  });
224
- d(this, "canvas");
225
- d(this, "ctx");
226
- d(this, "qualityFactor");
225
+ u(this, "canvas");
226
+ u(this, "ctx");
227
+ u(this, "qualityFactor");
227
228
  if (this.canvas = document.createElement("canvas"), this.ctx = this.canvas.getContext("2d"), !this.ctx)
228
229
  throw new Error("[Mirage] Failed to create canvas context");
229
230
  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, i, r, o);
@@ -232,26 +233,26 @@ class Ge extends y.MeshBasicMaterial {
232
233
  const r = t.split(`
233
234
  `), o = [];
234
235
  return r.forEach((n) => {
235
- const c = n.match(/[^\s\-]+\-?|\-|\s+/g) || [];
236
- if (c.length === 0) {
236
+ const a = n.match(/[^\s\-]+\-?|\-|\s+/g) || [];
237
+ if (a.length === 0) {
237
238
  o.push("");
238
239
  return;
239
240
  }
240
- let a = c[0];
241
- for (let l = 1; l < c.length; l++) {
242
- const u = c[l];
243
- this.ctx.measureText(a + u).width <= i + 2 ? a += u : (a && o.push(a), a = u.trimStart());
241
+ let c = a[0];
242
+ for (let l = 1; l < a.length; l++) {
243
+ const d = a[l];
244
+ this.ctx.measureText(c + d).width <= i + 2 ? c += d : (c && o.push(c), c = d.trimStart());
244
245
  }
245
- a && o.push(a);
246
+ c && o.push(c);
246
247
  }), o;
247
248
  }
248
249
  updateText(t, i, r, o, n) {
249
250
  n !== void 0 && (this.qualityFactor = n);
250
- const a = (window.devicePixelRatio || 1) * this.qualityFactor, l = r * a, u = o * a;
251
- this.canvas.width !== l || this.canvas.height !== u ? (this.canvas.width = l, this.canvas.height = u) : this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height), this.ctx.setTransform(a, 0, 0, a, 0, 0), this.ctx.font = i.font, this.ctx.fillStyle = i.color, this.ctx.textBaseline = "alphabetic", this.ctx.globalAlpha = 1;
252
- const h = this.wrapText(t, r), f = i.lineHeight, v = Ie.getBaseline(i.font);
253
- h.forEach((g, p) => {
254
- const E = p * f + v;
251
+ const c = (window.devicePixelRatio || 1) * this.qualityFactor, l = r * c, d = o * c;
252
+ this.canvas.width !== l || this.canvas.height !== d ? (this.canvas.width = l, this.canvas.height = d) : this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height), this.ctx.setTransform(c, 0, 0, c, 0, 0), this.ctx.font = i.font, this.ctx.fillStyle = i.color, this.ctx.textBaseline = "alphabetic", this.ctx.globalAlpha = 1;
253
+ const h = this.wrapText(t, r), f = i.lineHeight, p = Ae.getBaseline(i.font);
254
+ h.forEach((g, m) => {
255
+ const E = m * f + p;
255
256
  let L = 0;
256
257
  i.textAlign === "center" ? L = r / 2 : i.textAlign === "right" && (L = r), this.ctx.textAlign = i.textAlign, this.ctx.fillText(g, L, E);
257
258
  }), this.map && (this.map.needsUpdate = !0);
@@ -263,7 +264,7 @@ class Ge extends y.MeshBasicMaterial {
263
264
  function K(s) {
264
265
  return typeof s == "number" ? s : parseFloat(s) || 0;
265
266
  }
266
- function oe(s) {
267
+ function Z(s) {
267
268
  if (!s || s === "transparent")
268
269
  return { color: new y.Color(16777215), alpha: 0 };
269
270
  const e = s.match(
@@ -275,7 +276,7 @@ function oe(s) {
275
276
  }
276
277
  return { color: new y.Color(s), alpha: 1 };
277
278
  }
278
- function $e(s) {
279
+ function Ge(s) {
279
280
  const e = [];
280
281
  let t = "", i = 0;
281
282
  for (let r = 0; r < s.length; r++) {
@@ -292,62 +293,62 @@ function $e(s) {
292
293
  }
293
294
  return t && e.push(t.trim()), e;
294
295
  }
295
- function qe(s) {
296
+ function $e(s) {
296
297
  if (!s || typeof s != "string" || !s.includes("linear-gradient"))
297
298
  return null;
298
299
  const e = s.match(/linear-gradient\((.*)\)/);
299
300
  if (!e)
300
301
  return null;
301
- const t = e[1], i = $e(t);
302
+ const t = e[1], i = Ge(t);
302
303
  let r = Math.PI, o = 0;
303
304
  const n = i[0].trim();
304
305
  if (n.startsWith("to "))
305
306
  n === "to top" ? r = 0 : n === "to right" ? r = Math.PI / 2 : n === "to bottom" ? r = Math.PI : n === "to left" ? r = Math.PI * 1.5 : n === "to top right" || n === "to right top" ? r = Math.PI / 4 : n === "to bottom right" || n === "to right bottom" ? r = Math.PI * 0.75 : n === "to bottom left" || n === "to left bottom" ? r = Math.PI * 1.25 : (n === "to top left" || n === "to left top") && (r = Math.PI * 1.75), o = 1;
306
307
  else if (n.endsWith("deg") || n.endsWith("rad") || n.endsWith("turn")) {
307
- const a = parseFloat(n);
308
- n.endsWith("deg") ? r = a * (Math.PI / 180) : n.endsWith("rad") ? r = a : n.endsWith("turn") && (r = a * Math.PI * 2), o = 1;
308
+ const c = parseFloat(n);
309
+ n.endsWith("deg") ? r = c * (Math.PI / 180) : n.endsWith("rad") ? r = c : n.endsWith("turn") && (r = c * Math.PI * 2), o = 1;
309
310
  }
310
- const c = [];
311
- for (let a = o; a < i.length && !(c.length >= 8); a++) {
312
- const l = i[a].trim(), u = l.lastIndexOf(" ");
311
+ const a = [];
312
+ for (let c = o; c < i.length && !(a.length >= 8); c++) {
313
+ const l = i[c].trim(), d = l.lastIndexOf(" ");
313
314
  let h = l, f = null;
314
- if (u !== -1 && !l.endsWith(")")) {
315
- const g = l.substring(u + 1);
316
- (g.endsWith("%") || g.endsWith("px") || !isNaN(parseFloat(g))) && (h = l.substring(0, u).trim(), f = g);
315
+ if (d !== -1 && !l.endsWith(")")) {
316
+ const g = l.substring(d + 1);
317
+ (g.endsWith("%") || g.endsWith("px") || !isNaN(parseFloat(g))) && (h = l.substring(0, d).trim(), f = g);
317
318
  }
318
- const v = oe(h);
319
- c.push({
320
- color: v.color,
321
- alpha: v.alpha,
319
+ const p = Z(h);
320
+ a.push({
321
+ color: p.color,
322
+ alpha: p.alpha,
322
323
  rawStop: f,
323
324
  stop: 0
324
325
  });
325
326
  }
326
- if (c.length > 0) {
327
- for (let l = 0; l < c.length; l++)
328
- c[l].rawStop !== null && (c[l].stop = parseFloat(c[l].rawStop) / 100);
329
- c[0].rawStop === null && (c[0].stop = 0), c.length > 1 && c[c.length - 1].rawStop === null && (c[c.length - 1].stop = 1);
330
- let a = 0;
331
- for (let l = 1; l < c.length; l++)
332
- if (c[l].rawStop !== null || l === c.length - 1) {
333
- const u = l - a;
334
- if (u > 1) {
335
- const h = c[a].stop, v = (c[l].stop - h) / u;
336
- for (let g = 1; g < u; g++)
337
- c[a + g].stop = h + v * g;
327
+ if (a.length > 0) {
328
+ for (let l = 0; l < a.length; l++)
329
+ a[l].rawStop !== null && (a[l].stop = parseFloat(a[l].rawStop) / 100);
330
+ a[0].rawStop === null && (a[0].stop = 0), a.length > 1 && a[a.length - 1].rawStop === null && (a[a.length - 1].stop = 1);
331
+ let c = 0;
332
+ for (let l = 1; l < a.length; l++)
333
+ if (a[l].rawStop !== null || l === a.length - 1) {
334
+ const d = l - c;
335
+ if (d > 1) {
336
+ const h = a[c].stop, p = (a[l].stop - h) / d;
337
+ for (let g = 1; g < d; g++)
338
+ a[c + g].stop = h + p * g;
338
339
  }
339
- a = l;
340
+ c = l;
340
341
  }
341
342
  }
342
- return { angle: r, stops: c };
343
+ return { angle: r, stops: a };
343
344
  }
344
- const je = `varying vec2 vUv;
345
+ const qe = `varying vec2 vUv;
345
346
  varying vec4 vScreenPos;
346
347
  void main() {
347
348
  vUv = uv;
348
349
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
349
350
  vScreenPos = gl_Position;
350
- }`, Ke = `varying vec2 vUv;
351
+ }`, je = `varying vec2 vUv;
351
352
  uniform vec2 uSize;
352
353
  uniform vec4 uBorderRadius;
353
354
  uniform float uBorderWidth;
@@ -476,37 +477,37 @@ void main() {
476
477
 
477
478
  // #include <colorspace_fragment>
478
479
  }
479
- `, Je = `uniform sampler2D uTexture;
480
+ `, Ke = `uniform sampler2D uTexture;
480
481
  varying vec4 vScreenPos;
481
482
  uniform vec2 uTextureRepeat;
482
- uniform vec2 uTextureOffset;`, Qe = `vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
483
+ uniform vec2 uTextureOffset;`, Je = `vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
483
484
  vec2 resultUv = screenUv;
484
485
 
485
- `, Ze = `vec4 texColor = texture2D(uTexture, resultUv);
486
- baseColor = blendSrcOver(baseColor, texColor);`, Re = {
487
- vertexShader: je,
488
- fragmentShader: Ke
489
- }, me = {
490
- declChunk: Je,
491
- uvChunk: Qe,
492
- baseColorChunk: Ze
486
+ `, Qe = `vec4 texColor = texture2D(uTexture, resultUv);
487
+ baseColor = blendSrcOver(baseColor, texColor);`, Se = {
488
+ vertexShader: qe,
489
+ fragmentShader: je
490
+ }, ae = {
491
+ declChunk: Ke,
492
+ uvChunk: Je,
493
+ baseColorChunk: Qe
493
494
  };
494
- function et(s, e, t, i = null, r) {
495
- var R;
495
+ function Ze(s, e, t, i = null, r) {
496
+ var M;
496
497
  const o = i !== null || !!s.imageSrc;
497
498
  let n = "";
498
- const c = {};
499
+ const a = {};
499
500
  if (r != null && r.uniforms)
500
- for (const [x, w] of Object.entries(r.uniforms))
501
- typeof w == "number" ? (n += `uniform float ${x};
502
- `, c[x] = { value: w }) : Array.isArray(w) ? w.length === 2 ? (n += `uniform vec2 ${x};
503
- `, c[x] = { value: new y.Vector2(...w) }) : w.length === 3 ? (n += `uniform vec3 ${x};
504
- `, c[x] = { value: new y.Vector3(...w) }) : w.length === 4 && (n += `uniform vec4 ${x};
505
- `, c[x] = { value: new y.Vector4(...w) }) : (n += `uniform float ${x};
506
- `, c[x] = { value: w });
507
- const a = (o ? me.declChunk : "") + `
508
- ` + n, l = s.isTraveler ? me.uvChunk : `vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
509
- `, u = o ? l + ((r == null ? void 0 : r.uvModifier) || "") : "", h = o ? me.baseColorChunk : "", f = (r == null ? void 0 : r.colorModifier) || "", v = Re.fragmentShader.replace("#INJECT_DECLARATIONS", a).replace("#INJECT_UV_MODIFIER", u).replace("#INJECT_BASE_COLOR", h).replace("#INJECT_COLOR_MODIFIER", f), g = oe(s.backgroundColor), p = oe(s.borderColor), E = {
501
+ for (const [w, b] of Object.entries(r.uniforms))
502
+ typeof b == "number" ? (n += `uniform float ${w};
503
+ `, a[w] = { value: b }) : Array.isArray(b) ? b.length === 2 ? (n += `uniform vec2 ${w};
504
+ `, a[w] = { value: new y.Vector2(...b) }) : b.length === 3 ? (n += `uniform vec3 ${w};
505
+ `, a[w] = { value: new y.Vector3(...b) }) : b.length === 4 && (n += `uniform vec4 ${w};
506
+ `, a[w] = { value: new y.Vector4(...b) }) : (n += `uniform float ${w};
507
+ `, a[w] = { value: b });
508
+ const c = (o ? ae.declChunk : "") + `
509
+ ` + n, l = s.isTraveler ? ae.uvChunk : `vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
510
+ `, d = o ? l + ((r == null ? void 0 : r.uvModifier) || "") : "", h = o ? ae.baseColorChunk : "", f = (r == null ? void 0 : r.colorModifier) || "", p = Se.fragmentShader.replace("#INJECT_DECLARATIONS", c).replace("#INJECT_UV_MODIFIER", d).replace("#INJECT_BASE_COLOR", h).replace("#INJECT_COLOR_MODIFIER", f), g = Z(s.backgroundColor), m = Z(s.borderColor), E = {
510
511
  uSize: { value: new y.Vector2(e, t) },
511
512
  uBgColor: {
512
513
  value: new y.Vector4(
@@ -518,15 +519,15 @@ function et(s, e, t, i = null, r) {
518
519
  },
519
520
  uBorderColor: {
520
521
  value: new y.Vector4(
521
- p.color.r,
522
- p.color.g,
523
- p.color.b,
524
- p.alpha
522
+ m.color.r,
523
+ m.color.g,
524
+ m.color.b,
525
+ m.alpha
525
526
  )
526
527
  },
527
528
  uBorderRadius: { value: new y.Vector4(0, 0, 0, 0) },
528
529
  uBorderWidth: { value: K(s.borderWidth) },
529
- uOpacity: { value: (R = s.opacity) != null ? R : 1 },
530
+ uOpacity: { value: (M = s.opacity) != null ? M : 1 },
530
531
  uTexture: { value: null },
531
532
  uTextureRepeat: { value: new y.Vector2(1, 1) },
532
533
  uTextureOffset: { value: new y.Vector2(0, 0) },
@@ -537,20 +538,20 @@ function et(s, e, t, i = null, r) {
537
538
  },
538
539
  uGradientStops: { value: new Float32Array(8) }
539
540
  };
540
- Be(E.uBorderRadius.value, s.borderRadius), o && (E.uTexture.value = i);
541
+ De(E.uBorderRadius.value, s.borderRadius), o && (E.uTexture.value = i);
541
542
  const L = new y.ShaderMaterial({
542
- uniforms: G(G({}, E), c),
543
- vertexShader: Re.vertexShader,
544
- fragmentShader: v,
543
+ uniforms: $($({}, E), a),
544
+ vertexShader: Se.vertexShader,
545
+ fragmentShader: p,
545
546
  transparent: !0,
546
547
  side: y.FrontSide
547
548
  // for better performance
548
549
  });
549
- return s.backgroundImage && be(L, { backgroundImage: s.backgroundImage }), L;
550
+ return s.backgroundImage && le(L, { backgroundImage: s.backgroundImage }), L;
550
551
  }
551
- function tt(s, e, t, i, r) {
552
+ function et(s, e, t, i, r) {
552
553
  const o = K(e.borderWidth);
553
- be(s, {
554
+ le(s, {
554
555
  width: t,
555
556
  height: i,
556
557
  borderRadius: e.borderRadius,
@@ -562,9 +563,9 @@ function tt(s, e, t, i, r) {
562
563
  backgroundImage: e.backgroundImage
563
564
  });
564
565
  }
565
- function be(s, e) {
566
+ function le(s, e) {
566
567
  var i, r, o;
567
- if (e.width !== void 0 && e.height !== void 0 && s.uniforms.uSize.value.set(e.width, e.height), e.borderRadius !== void 0 && Be(s.uniforms.uBorderRadius.value, e.borderRadius), e.borderWidth !== void 0 && (s.uniforms.uBorderWidth.value = e.borderWidth), e.backgroundColor !== void 0)
568
+ if (e.width !== void 0 && e.height !== void 0 && s.uniforms.uSize.value.set(e.width, e.height), e.borderRadius !== void 0 && De(s.uniforms.uBorderRadius.value, e.borderRadius), e.borderWidth !== void 0 && (s.uniforms.uBorderWidth.value = e.borderWidth), e.backgroundColor !== void 0)
568
569
  if (Array.isArray(e.backgroundColor)) {
569
570
  const n = s.uniforms.uBgColor.value.w;
570
571
  s.uniforms.uBgColor.value.set(
@@ -574,7 +575,7 @@ function be(s, e) {
574
575
  n
575
576
  );
576
577
  } else if (typeof e.backgroundColor == "string") {
577
- const n = oe(e.backgroundColor);
578
+ const n = Z(e.backgroundColor);
578
579
  s.uniforms.uBgColor.value.set(
579
580
  n.color.r,
580
581
  n.color.g,
@@ -600,7 +601,7 @@ function be(s, e) {
600
601
  n
601
602
  );
602
603
  } else if (typeof e.borderColor == "string") {
603
- const n = oe(e.borderColor);
604
+ const n = Z(e.borderColor);
604
605
  s.uniforms.uBorderColor.value.set(
605
606
  n.color.r,
606
607
  n.color.g,
@@ -619,42 +620,42 @@ function be(s, e) {
619
620
  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);
620
621
  const t = e.texture !== void 0 ? e.texture : (i = s.uniforms.uTexture) == null ? void 0 : i.value;
621
622
  if (t && (t.image instanceof ImageBitmap || t.image instanceof HTMLImageElement || t.image instanceof HTMLCanvasElement)) {
622
- const n = t.image.width, c = t.image.height, a = (r = e.width) != null ? r : s.uniforms.uSize.value.x, l = (o = e.height) != null ? o : s.uniforms.uSize.value.y;
623
- if (n && c && a && l) {
624
- const u = n / c, h = a / l;
625
- if (u > h) {
626
- const f = h / u;
623
+ const n = t.image.naturalWidth || t.image.videoWidth || t.image.width, a = t.image.naturalHeight || t.image.videoHeight || t.image.height, c = (r = e.width) != null ? r : s.uniforms.uSize.value.x, l = (o = e.height) != null ? o : s.uniforms.uSize.value.y;
624
+ if (n && a && c && l) {
625
+ const d = n / a, h = c / l;
626
+ if (d > h) {
627
+ const f = h / d;
627
628
  s.uniforms.uTextureRepeat.value.set(f, 1), s.uniforms.uTextureOffset.value.set((1 - f) / 2, 0);
628
629
  } else {
629
- const f = u / h;
630
+ const f = d / h;
630
631
  s.uniforms.uTextureRepeat.value.set(1, f), s.uniforms.uTextureOffset.value.set(0, (1 - f) / 2);
631
632
  }
632
633
  }
633
634
  } else
634
635
  s.uniforms.uTextureRepeat && (s.uniforms.uTextureRepeat.value.set(1, 1), s.uniforms.uTextureOffset.value.set(0, 0));
635
636
  if (e.backgroundImage !== void 0) {
636
- const n = qe(e.backgroundImage);
637
+ const n = $e(e.backgroundImage);
637
638
  if (n) {
638
639
  s.uniforms.uGradientCount.value = n.stops.length, s.uniforms.uGradientAngle.value = n.angle;
639
- for (let c = 0; c < 8; c++)
640
- if (c < n.stops.length) {
641
- const a = n.stops[c];
642
- s.uniforms.uGradientColors.value[c].set(
643
- a.color.r,
644
- a.color.g,
645
- a.color.b,
646
- a.alpha
647
- ), s.uniforms.uGradientStops.value[c] = a.stop;
640
+ for (let a = 0; a < 8; a++)
641
+ if (a < n.stops.length) {
642
+ const c = n.stops[a];
643
+ s.uniforms.uGradientColors.value[a].set(
644
+ c.color.r,
645
+ c.color.g,
646
+ c.color.b,
647
+ c.alpha
648
+ ), s.uniforms.uGradientStops.value[a] = c.stop;
648
649
  } else
649
- s.uniforms.uGradientColors.value[c].set(0, 0, 0, 0), s.uniforms.uGradientStops.value[c] = 1;
650
+ s.uniforms.uGradientColors.value[a].set(0, 0, 0, 0), s.uniforms.uGradientStops.value[a] = 1;
650
651
  } else
651
652
  s.uniforms.uGradientCount.value = 0;
652
653
  }
653
654
  for (const n of Object.keys(e))
654
655
  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]);
655
656
  }
656
- function Be(s, e) {
657
- var c, a, l, u;
657
+ function De(s, e) {
658
+ var a, c, l, d;
658
659
  if (e == null) {
659
660
  s.set(0, 0, 0, 0);
660
661
  return;
@@ -667,18 +668,18 @@ function Be(s, e) {
667
668
  s.set(e[0], e[1], e[2], e[3]);
668
669
  return;
669
670
  }
670
- const t = e.split("/")[0].trim().split(/\s+/), i = K(t[0]), r = K((c = t[1]) != null ? c : t[0]), o = K((a = t[2]) != null ? a : t[0]), n = K((u = (l = t[3]) != null ? l : t[1]) != null ? u : t[0]);
671
+ const t = e.split("/")[0].trim().split(/\s+/), i = K(t[0]), r = K((a = t[1]) != null ? a : t[0]), o = K((c = t[2]) != null ? c : t[0]), n = K((d = (l = t[3]) != null ? l : t[1]) != null ? d : t[0]);
671
672
  s.set(i, r, o, n);
672
673
  }
673
- const H = {
674
- create(s, e, t, i, r, o = 2, n = null, c) {
675
- return s === "BOX" ? et(
674
+ const Y = {
675
+ create(s, e, t, i, r, o = 2, n = null, a) {
676
+ return s === "BOX" ? Ze(
676
677
  e,
677
678
  i,
678
679
  r,
679
680
  n,
680
- c
681
- ) : s === "TEXT" ? new Ge(
681
+ a
682
+ ) : s === "TEXT" ? new Pe(
682
683
  t || "",
683
684
  e,
684
685
  i,
@@ -686,13 +687,13 @@ const H = {
686
687
  o
687
688
  ) : new y.MeshBasicMaterial({ visible: !1 });
688
689
  },
689
- update(s, e, t, i, r, o, n = 2, c) {
690
- e === "BOX" ? tt(
690
+ update(s, e, t, i, r, o, n = 2, a) {
691
+ e === "BOX" ? et(
691
692
  s,
692
693
  t,
693
694
  r,
694
695
  o,
695
- c
696
+ a
696
697
  ) : e === "TEXT" && s.updateText(
697
698
  i || "",
698
699
  t,
@@ -702,16 +703,16 @@ const H = {
702
703
  );
703
704
  },
704
705
  forceUpdateUniforms(s, e) {
705
- be(s, e);
706
+ le(s, e);
706
707
  }
707
708
  };
708
- class rt {
709
+ class tt {
709
710
  constructor(e, t = !0) {
710
- d(this, "observer");
711
- d(this, "textures", /* @__PURE__ */ new WeakMap());
712
- d(this, "loadStatus", /* @__PURE__ */ new WeakMap());
713
- d(this, "elementUrls", /* @__PURE__ */ new WeakMap());
714
- d(this, "onUpdate");
711
+ u(this, "observer");
712
+ u(this, "textures", /* @__PURE__ */ new WeakMap());
713
+ u(this, "loadStatus", /* @__PURE__ */ new WeakMap());
714
+ u(this, "elementUrls", /* @__PURE__ */ new WeakMap());
715
+ u(this, "onUpdate");
715
716
  this.onUpdate = e, t && (this.observer = new IntersectionObserver(
716
717
  (i) => {
717
718
  for (const r of i) {
@@ -731,7 +732,7 @@ class rt {
731
732
  e.nodeType === Node.ELEMENT_NODE && this.observer && this.observer.unobserve(e), this.disposeTexture(e), this.elementUrls.delete(e), this.loadStatus.delete(e);
732
733
  }
733
734
  loadTexture(e) {
734
- return Ce(this, null, function* () {
735
+ return Ee(this, null, function* () {
735
736
  if (this.loadStatus.get(e) || this.textures.has(e))
736
737
  return;
737
738
  const t = this.elementUrls.get(e);
@@ -741,8 +742,8 @@ class rt {
741
742
  let i;
742
743
  if (t.startsWith("data:image/svg+xml"))
743
744
  i = yield new Promise((o, n) => {
744
- const c = new Image();
745
- c.onload = () => o(c), c.onerror = n, c.src = t;
745
+ const a = new Image();
746
+ a.onload = () => o(a), a.onerror = n, a.src = t;
746
747
  });
747
748
  else {
748
749
  const n = yield (yield fetch(t)).blob();
@@ -773,35 +774,35 @@ class rt {
773
774
  this.observer && this.observer.disconnect();
774
775
  }
775
776
  }
776
- class it {
777
+ class rt {
777
778
  constructor(e, t, i, r) {
778
- d(this, "canvas");
779
- d(this, "scene");
780
- d(this, "camera");
781
- d(this, "renderer");
782
- d(this, "renderTargets", []);
783
- d(this, "renderOrder", 0);
784
- d(this, "qualityFactor", 2);
785
- d(this, "mode", "overlay");
786
- d(this, "canvasSize", "viewport");
787
- d(this, "clipArea", 1);
788
- d(this, "targetLayer", "base");
789
- d(this, "overscan", 200);
790
- d(this, "target");
791
- d(this, "mountContainer");
792
- d(this, "registry");
793
- d(this, "targetRect");
794
- d(this, "travelersByLayer", Array.from(
795
- { length: F.MAX_LAYERS },
779
+ u(this, "canvas");
780
+ u(this, "scene");
781
+ u(this, "camera");
782
+ u(this, "renderer");
783
+ u(this, "renderTargets", []);
784
+ u(this, "renderOrder", 0);
785
+ u(this, "qualityFactor", 2);
786
+ u(this, "mode", "overlay");
787
+ u(this, "canvasSize", "viewport");
788
+ u(this, "clipArea", 1);
789
+ u(this, "targetLayer", "base");
790
+ u(this, "overscan", 200);
791
+ u(this, "target");
792
+ u(this, "mountContainer");
793
+ u(this, "registry");
794
+ u(this, "targetRect");
795
+ u(this, "travelersByLayer", Array.from(
796
+ { length: I.MAX_LAYERS },
796
797
  () => /* @__PURE__ */ new Set()
797
798
  ));
798
- d(this, "textureManager");
799
+ u(this, "textureManager");
799
800
  // private meshMap: Map<HTMLElement, THREE.Mesh> = new Map();
800
- d(this, "fixedMeshes", /* @__PURE__ */ new Set());
801
- var c, a, l, u, h;
802
- this.target = e, this.mountContainer = i, this.registry = r, this.mode = (c = t.mode) != null ? c : "overlay", this.canvasSize = (a = t.canvasSize) != null ? a : "viewport", this.clipArea = (l = t.travelerClipArea) != null ? l : 1, this.targetLayer = (u = t.layer) != null ? u : "base", this.textureManager = new rt((f, v) => {
801
+ u(this, "fixedMeshes", /* @__PURE__ */ new Set());
802
+ var a, c, l, d, h;
803
+ this.target = e, this.mountContainer = i, this.registry = r, this.mode = (a = t.mode) != null ? a : "overlay", this.canvasSize = (c = t.canvasSize) != null ? c : "viewport", this.clipArea = (l = t.travelerClipArea) != null ? l : 1, this.targetLayer = (d = t.layer) != null ? d : "base", this.textureManager = new tt((f, p) => {
803
804
  const g = this.registry.get(f);
804
- g && g.material instanceof y.ShaderMaterial && H.forceUpdateUniforms(g.material, { texture: v });
805
+ g && g.material instanceof y.ShaderMaterial && Y.forceUpdateUniforms(g.material, { texture: p });
805
806
  }, this.isViewport), this.canvas = document.createElement("canvas"), this.scene = new y.Scene(), this.targetRect = this.target.getBoundingClientRect();
806
807
  const o = this.isViewport ? window.innerWidth + this.overscan * 2 : this.targetRect.width, n = this.isViewport ? window.innerHeight + this.overscan * 2 : this.targetRect.height;
807
808
  this.camera = new y.OrthographicCamera(
@@ -823,10 +824,10 @@ class it {
823
824
  return this.mode === "overlay" && this.canvasSize === "viewport";
824
825
  }
825
826
  getSceneLayer() {
826
- return typeof this.targetLayer == "number" ? this.targetLayer : this.targetLayer === "selected" ? k.SELECTED : k.BASE;
827
+ return typeof this.targetLayer == "number" ? this.targetLayer : this.targetLayer === "selected" ? R.SELECTED : R.BASE;
827
828
  }
828
829
  createRenderTarget() {
829
- for (let e = 0; e < F.MAX_LAYERS; e++) {
830
+ for (let e = 0; e < I.MAX_LAYERS; e++) {
830
831
  const t = this.isViewport ? window.innerWidth + this.overscan * 2 : this.targetRect.width, i = this.isViewport ? window.innerHeight + this.overscan * 2 : this.targetRect.height;
831
832
  this.renderTargets.push(
832
833
  new y.WebGLRenderTarget(
@@ -873,12 +874,12 @@ class it {
873
874
  updateUniforms(e, t) {
874
875
  const i = this.registry.get(e);
875
876
  i && (i.traverse((r) => {
876
- r.isMesh && r.material && H.forceUpdateUniforms(
877
+ r.isMesh && r.material && Y.forceUpdateUniforms(
877
878
  r.material,
878
879
  t
879
880
  );
880
881
  }), i.userData.nativeMesh && i.userData.nativeMesh.traverse((r) => {
881
- r.isMesh && r.material && H.forceUpdateUniforms(
882
+ r.isMesh && r.material && Y.forceUpdateUniforms(
882
883
  r.material,
883
884
  t
884
885
  );
@@ -894,16 +895,16 @@ class it {
894
895
  this.camera.left = e / -2, this.camera.right = e / 2, this.camera.top = t / 2, this.camera.bottom = t / -2, this.camera.updateProjectionMatrix();
895
896
  }
896
897
  syncScene(e, t) {
897
- const i = this.target.getBoundingClientRect(), r = this.isViewport ? window.innerWidth + this.overscan * 2 : i.width, o = this.isViewport ? window.innerHeight + this.overscan * 2 : i.height, n = this.isViewport ? this.canvas.clientWidth : this.targetRect.width, c = this.isViewport ? this.canvas.clientHeight : this.targetRect.height, a = Math.abs(r - n) > 0.1 || Math.abs(o - c) > 0.1, l = this.mode === "overlay" && (Math.abs(i.top - this.targetRect.top) > 0.1 || Math.abs(i.left - this.targetRect.left) > 0.1);
898
- a ? (this.targetRect = i, this.setSize(r, o), this.updateCanvasLayout()) : l ? (this.targetRect = i, this.updateCanvasLayout()) : this.targetRect = i, this.renderOrder = 0, this.reconcileNode(e), t.size > 0 && t.forEach((u) => {
899
- const h = this.registry.get(u);
898
+ const i = this.target.getBoundingClientRect(), r = this.isViewport ? window.innerWidth + this.overscan * 2 : i.width, o = this.isViewport ? window.innerHeight + this.overscan * 2 : i.height, n = this.isViewport ? this.canvas.clientWidth : this.targetRect.width, a = this.isViewport ? this.canvas.clientHeight : this.targetRect.height, c = Math.abs(r - n) > 0.1 || Math.abs(o - a) > 0.1, l = this.mode === "overlay" && (Math.abs(i.top - this.targetRect.top) > 0.1 || Math.abs(i.left - this.targetRect.left) > 0.1);
899
+ c ? (this.targetRect = i, this.setSize(r, o), this.updateCanvasLayout()) : l ? (this.targetRect = i, this.updateCanvasLayout()) : this.targetRect = i, this.renderOrder = 0, this.reconcileNode(e), t.size > 0 && t.forEach((d) => {
900
+ const h = this.registry.get(d);
900
901
  if (h) {
901
902
  this.scene.remove(h);
902
903
  for (const f of this.travelersByLayer)
903
904
  f.delete(h);
904
905
  this.fixedMeshes.delete(h), h.geometry.dispose(), h.userData.nativeMesh && (this.scene.remove(h.userData.nativeMesh), Array.isArray(h.userData.nativeMesh.material) ? h.userData.nativeMesh.material.forEach((f) => f.dispose()) : h.userData.nativeMesh.material.dispose(), h.userData.nativeMesh.geometry.dispose()), h.traverse((f) => {
905
- f instanceof y.Mesh && (f.geometry && f.geometry.dispose(), f.material && (Array.isArray(f.material) ? f.material.forEach((v) => v.dispose()) : f.material.dispose()));
906
- }), this.registry.remove(u), this.textureManager.unregister(u);
906
+ f instanceof y.Mesh && (f.geometry && f.geometry.dispose(), f.material && (Array.isArray(f.material) ? f.material.forEach((p) => p.dispose()) : f.material.dispose()));
907
+ }), this.registry.remove(d), this.textureManager.unregister(d);
907
908
  }
908
909
  });
909
910
  }
@@ -912,30 +913,31 @@ class it {
912
913
  // => 이후 activeElements를 이용하여 mesh를 정리!!!+ map에서도 삭제
913
914
  // private reconcileNode(node: SceneNode, activeElements: Set<HTMLElement>) {
914
915
  reconcileNode(e) {
915
- var i;
916
+ var r;
916
917
  let t = this.registry.get(e.element);
917
- if (!t) {
918
- const r = new y.PlaneGeometry(1, 1), o = e.isTraveler ? (i = this.renderTargets[e.captureLayer - 2]) == null ? void 0 : i.texture : this.textureManager.get(e.element), n = H.create(
918
+ const i = JSON.stringify(e.shaderHooks || null);
919
+ if (t && t.userData.shaderHash !== i && (this.scene.remove(t), t.geometry.dispose(), t.material instanceof y.Material && t.material.dispose(), this.registry.remove(e.element), t = void 0), !t) {
920
+ const o = new y.PlaneGeometry(1, 1), n = e.isTraveler ? (r = this.renderTargets[e.captureLayer - 2]) == null ? void 0 : r.texture : this.textureManager.get(e.element), a = Y.create(
919
921
  "BOX",
920
922
  e.styles,
921
923
  "",
922
924
  e.rect.width,
923
925
  e.rect.height,
924
926
  this.qualityFactor,
925
- o,
927
+ n,
926
928
  e.shaderHooks
927
929
  );
928
- t = new y.Mesh(r, n), e.type === "TEXT" && (t.name = "BG_MESH"), this.scene.add(t), this.registry.register(e.element, t), t.userData.baseMaterial = n;
930
+ t = new y.Mesh(o, a), e.type === "TEXT" && (t.name = "BG_MESH"), this.scene.add(t), this.registry.register(e.element, t), t.userData.baseMaterial = a, t.userData.domElement = e.element, t.userData.shaderHash = i;
929
931
  }
930
932
  if (this.updateMeshProperties(t, e), this.updateMeshLayers(t, e), e.isTraveler)
931
- for (let r = 0; r < F.MAX_LAYERS; r++)
932
- r === e.captureLayer - 2 ? this.travelersByLayer[r].add(t) : this.travelersByLayer[r].delete(t);
933
+ for (let o = 0; o < I.MAX_LAYERS; o++)
934
+ o === e.captureLayer - 2 ? this.travelersByLayer[o].add(t) : this.travelersByLayer[o].delete(t);
933
935
  else
934
- for (const r of this.travelersByLayer)
935
- r.delete(t);
936
+ for (const o of this.travelersByLayer)
937
+ o.delete(t);
936
938
  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")
937
- for (const r of e.children)
938
- this.reconcileNode(r);
939
+ for (const o of e.children)
940
+ this.reconcileNode(o);
939
941
  else
940
942
  e.type === "TEXT" && (this.reconcileTextChild(t, e, !1), t.userData.nativeMesh && e.nativeStyles && this.reconcileTextChild(t.userData.nativeMesh, e, !0));
941
943
  }
@@ -943,83 +945,85 @@ class it {
943
945
  var l;
944
946
  const r = t.textLines || [
945
947
  { text: t.textContent || "", rect: t.rect }
946
- ], o = i ? t.nativeStyles : t.textStyles, n = JSON.stringify(o) + t.textContent + r.map((u) => u.text).join("|"), c = (l = e.userData) == null ? void 0 : l.textChildStyleHash;
947
- if (t.dirtyMask & ye || n !== c) {
948
+ ], o = i ? t.nativeStyles : t.textStyles, n = JSON.stringify(o) + t.textContent + r.map((d) => d.text).join("|"), a = (l = e.userData) == null ? void 0 : l.textChildStyleHash;
949
+ if (t.dirtyMask & ce || n !== a) {
948
950
  e.children.filter(
949
951
  (g) => g.name.startsWith("TEXT_CHILD")
950
952
  ).forEach((g) => {
951
953
  var E;
952
- const p = g;
953
- (E = p.material.map) == null || E.dispose(), p.geometry.dispose(), e.remove(p);
954
+ const m = g;
955
+ (E = m.material.map) == null || E.dispose(), m.geometry.dispose(), e.remove(m);
954
956
  });
955
- const h = t.rect, f = h.x + h.width / 2, v = h.y + h.height / 2;
956
- r.forEach((g, p) => {
957
- const E = H.create(
957
+ const h = t.rect, f = h.x + h.width / 2, p = h.y + h.height / 2;
958
+ r.forEach((g, m) => {
959
+ const E = Y.create(
958
960
  "TEXT",
959
961
  o,
960
962
  g.text,
961
963
  g.rect.width,
962
964
  g.rect.height,
963
965
  this.qualityFactor
964
- ), L = new y.PlaneGeometry(1, 1), R = new y.Mesh(L, E);
965
- R.name = `TEXT_CHILD_${p}`;
966
- const x = t.rect.width === 0 ? 1 : g.rect.width / t.rect.width, w = t.rect.height === 0 ? 1 : g.rect.height / t.rect.height;
967
- R.scale.set(x, w, 1);
968
- const B = g.rect.x + g.rect.width / 2, M = g.rect.y + g.rect.height / 2, O = B - f, _ = -(M - v);
969
- R.position.set(
966
+ ), L = new y.PlaneGeometry(1, 1), M = new y.Mesh(L, E);
967
+ M.name = `TEXT_CHILD_${m}`;
968
+ const w = t.rect.width === 0 ? 1 : g.rect.width / t.rect.width, b = t.rect.height === 0 ? 1 : g.rect.height / t.rect.height;
969
+ M.scale.set(w, b, 1);
970
+ const U = g.rect.x + g.rect.width / 2, A = g.rect.y + g.rect.height / 2, O = U - f, N = -(A - p);
971
+ M.position.set(
970
972
  t.rect.width === 0 ? 0 : O / t.rect.width,
971
- t.rect.height === 0 ? 0 : _ / t.rect.height,
973
+ t.rect.height === 0 ? 0 : N / t.rect.height,
972
974
  5e-3
973
- ), e.add(R);
975
+ ), e.add(M);
974
976
  }), e.userData.textChildStyleHash = n;
975
977
  }
976
- e.children.forEach((u) => {
977
- if (!u.name.startsWith("TEXT_CHILD"))
978
+ e.children.forEach((d) => {
979
+ if (!d.name.startsWith("TEXT_CHILD"))
978
980
  return;
979
- const h = u, f = t.visibility & W ? k.BASE : k.HIDDEN;
980
- if (h.layers.set(f), t.visibility & j && h.layers.enable(k.SELECTED), t.visibility & W)
981
+ const h = d, f = t.visibility & W ? R.BASE : R.HIDDEN;
982
+ if (h.layers.set(f), t.visibility & j && h.layers.enable(R.SELECTED), t.visibility & W)
981
983
  if (!i && t.nativeLayer !== void 0 && t.nativeStyles !== void 0)
982
- for (let v = t.captureLayer; v < t.nativeLayer; v++)
983
- h.layers.enable(k.getCaptureLayer(v));
984
+ for (let p = t.captureLayer; p < t.nativeLayer; p++)
985
+ h.layers.enable(R.getCaptureLayer(p));
984
986
  else if (i && t.nativeLayer !== void 0)
985
- for (let v = Math.max(t.captureLayer, t.nativeLayer); v <= F.MAX_LAYERS + 1; v++)
986
- h.layers.enable(k.getCaptureLayer(v));
987
+ for (let p = Math.max(t.captureLayer, t.nativeLayer); p <= I.MAX_LAYERS + 1; p++)
988
+ h.layers.enable(R.getCaptureLayer(p));
987
989
  else
988
- for (let v = t.captureLayer; v <= F.MAX_LAYERS + 1; v++)
989
- h.layers.enable(k.getCaptureLayer(v));
990
+ for (let p = t.captureLayer; p <= I.MAX_LAYERS + 1; p++)
991
+ h.layers.enable(R.getCaptureLayer(p));
990
992
  });
991
993
  }
992
994
  updateMeshProperties(e, t) {
993
- var x, w, B;
994
- const { rect: i, styles: r } = t, o = this.renderer.getPixelRatio(), n = this.renderer.domElement.width / o, c = this.renderer.domElement.height / o;
995
- e.material = e.userData.baseMaterial, e.scale.set(i.width, i.height, 1), e.userData.domRect = pe(G({}, i), {
995
+ var w, b, U;
996
+ const { rect: i, styles: r } = t, o = this.renderer.getPixelRatio(), n = this.renderer.domElement.width / o, a = this.renderer.domElement.height / o;
997
+ e.material = e.userData.baseMaterial, e.scale.set(i.width, i.height, 1), e.userData.domRect = {
998
+ x: i.x,
999
+ y: i.y,
996
1000
  width: i.width,
997
1001
  height: i.height
998
- });
999
- const a = 1e-3;
1002
+ };
1003
+ const c = 1e-3;
1000
1004
  this.renderOrder++;
1001
- const l = this.targetRect.left + window.scrollX, u = this.targetRect.top + window.scrollY;
1005
+ const l = this.targetRect.left + window.scrollX, d = this.targetRect.top + window.scrollY;
1002
1006
  let h, f;
1003
1007
  if (this.isViewport)
1004
1008
  h = i.x - window.innerWidth / 2 + i.width / 2, f = -i.y + window.innerHeight / 2 - i.height / 2;
1005
1009
  else {
1006
- const M = i.x - l, O = i.y - u;
1007
- h = M - n / 2 + i.width / 2, f = -O + c / 2 - i.height / 2;
1010
+ const A = i.x - l, O = i.y - d;
1011
+ h = A - n / 2 + i.width / 2, f = -O + a / 2 - i.height / 2;
1008
1012
  }
1009
1013
  e.position.set(
1010
1014
  h,
1011
1015
  f,
1012
- r.zIndex + this.renderOrder * a
1016
+ r.zIndex + this.renderOrder * c
1013
1017
  );
1014
- const v = i.x, g = i.y;
1015
- e.userData.basePosition = { x: h, y: f }, e.userData.originalBasePosition = { x: h, y: f }, e.userData.baseSize = { width: i.width, height: i.height }, e.userData.baseDOM = { x: v, y: g }, e.userData.isFixed = t.isFixed, e.userData.initialScroll = { x: window.scrollX, y: window.scrollY };
1016
- const p = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, E = window.getComputedStyle(p);
1017
- let L = 0, R = 0;
1018
+ const p = i.x, g = i.y;
1019
+ e.userData.basePosition = { x: h, y: f }, e.userData.originalBasePosition = { x: h, y: f }, e.userData.baseSize = { width: i.width, height: i.height }, e.userData.baseDOM = { x: p, y: g }, e.userData.isFixed = t.isFixed, e.userData.initialScroll = { x: window.scrollX, y: window.scrollY };
1020
+ const m = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, E = window.getComputedStyle(m);
1021
+ let L = 0, M = 0;
1018
1022
  if (E.transform && E.transform !== "none") {
1019
- const M = new DOMMatrix(E.transform);
1020
- L = M.m41, R = M.m42;
1023
+ const A = new DOMMatrix(E.transform);
1024
+ L = A.m41, M = A.m42;
1021
1025
  }
1022
- if (e.userData.baseTransform = { x: L, y: R }, delete e.userData.originRatioX, delete e.userData.originRatioY, H.update(
1026
+ if (e.userData.baseTransform = { x: L, y: M }, delete e.userData.originRatioX, delete e.userData.originRatioY, Y.update(
1023
1027
  e.userData.baseMaterial,
1024
1028
  "BOX",
1025
1029
  r,
@@ -1027,99 +1031,129 @@ class it {
1027
1031
  i.width,
1028
1032
  i.height,
1029
1033
  this.qualityFactor,
1030
- t.isTraveler ? (x = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : x.texture : this.textureManager.get(t.element)
1034
+ t.isTraveler ? (w = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : w.texture : this.textureManager.get(t.element)
1031
1035
  ), t.nativeStyles && t.nativeRect) {
1032
1036
  if (!e.userData.nativeMesh) {
1033
- const A = H.create(
1037
+ const k = Y.create(
1034
1038
  "BOX",
1035
1039
  t.nativeStyles,
1036
1040
  "",
1037
1041
  t.nativeRect.width,
1038
1042
  t.nativeRect.height,
1039
1043
  this.qualityFactor,
1040
- t.isTraveler ? (w = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : w.texture : this.textureManager.get(t.element),
1044
+ t.isTraveler ? (b = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : b.texture : this.textureManager.get(t.element),
1041
1045
  t.shaderHooks
1042
- ), Y = new y.Mesh(e.geometry, A);
1043
- t.type === "TEXT" && (Y.name = "BG_MESH"), this.scene.add(Y), e.userData.nativeMesh = Y;
1046
+ ), P = new y.Mesh(e.geometry, k);
1047
+ t.type === "TEXT" && (P.name = "BG_MESH"), this.scene.add(P), e.userData.nativeMesh = P;
1044
1048
  }
1045
- const M = e.userData.nativeMesh;
1046
- let O, _;
1049
+ const A = e.userData.nativeMesh;
1050
+ let O, N;
1047
1051
  if (this.isViewport)
1048
- O = t.nativeRect.x - window.innerWidth / 2 + t.nativeRect.width / 2, _ = -t.nativeRect.y + window.innerHeight / 2 - t.nativeRect.height / 2;
1052
+ O = t.nativeRect.x - window.innerWidth / 2 + t.nativeRect.width / 2, N = -t.nativeRect.y + window.innerHeight / 2 - t.nativeRect.height / 2;
1049
1053
  else {
1050
- const A = t.nativeRect.x - l, Y = t.nativeRect.y - u;
1051
- O = A - n / 2 + t.nativeRect.width / 2, _ = -Y + c / 2 - t.nativeRect.height / 2;
1054
+ const k = t.nativeRect.x - l, P = t.nativeRect.y - d;
1055
+ O = k - n / 2 + t.nativeRect.width / 2, N = -P + a / 2 - t.nativeRect.height / 2;
1052
1056
  }
1053
- M.scale.set(t.nativeRect.width, t.nativeRect.height, 1), M.position.set(
1057
+ A.scale.set(t.nativeRect.width, t.nativeRect.height, 1), A.position.set(
1054
1058
  O,
1055
- _,
1056
- t.nativeStyles.zIndex + this.renderOrder * a
1057
- ), H.update(
1058
- M.material,
1059
+ N,
1060
+ t.nativeStyles.zIndex + this.renderOrder * c
1061
+ ), Y.update(
1062
+ A.material,
1059
1063
  "BOX",
1060
1064
  t.nativeStyles,
1061
1065
  "",
1062
1066
  t.nativeRect.width,
1063
1067
  t.nativeRect.height,
1064
1068
  this.qualityFactor,
1065
- t.isTraveler ? (B = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : B.texture : this.textureManager.get(t.element)
1069
+ t.isTraveler ? (U = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : U.texture : this.textureManager.get(t.element)
1066
1070
  );
1067
1071
  } else
1068
1072
  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);
1069
1073
  }
1070
1074
  updateMeshLayers(e, t) {
1071
- const i = t.visibility & W ? k.BASE : k.HIDDEN;
1072
- if (e.layers.set(i), t.visibility & j && e.layers.enable(k.SELECTED), e.userData.nativeMesh && t.nativeLayer !== void 0) {
1075
+ const i = t.visibility & W ? R.BASE : R.HIDDEN;
1076
+ if (e.layers.set(i), t.visibility & j && e.layers.enable(R.SELECTED), e.userData.nativeMesh && t.nativeLayer !== void 0) {
1073
1077
  const r = e.userData.nativeMesh;
1074
- if (r.layers.set(k.HIDDEN), t.visibility & W) {
1078
+ if (r.layers.set(R.HIDDEN), t.visibility & W) {
1075
1079
  for (let o = t.captureLayer; o < t.nativeLayer; o++)
1076
- e.layers.enable(k.getCaptureLayer(o));
1077
- for (let o = Math.max(t.captureLayer, t.nativeLayer); o <= F.MAX_LAYERS + 1; o++)
1078
- r.layers.enable(k.getCaptureLayer(o));
1080
+ e.layers.enable(R.getCaptureLayer(o));
1081
+ for (let o = Math.max(t.captureLayer, t.nativeLayer); o <= I.MAX_LAYERS + 1; o++)
1082
+ r.layers.enable(R.getCaptureLayer(o));
1079
1083
  }
1080
1084
  } else if (t.visibility & W)
1081
- for (let r = t.captureLayer; r <= F.MAX_LAYERS + 1; r++)
1082
- e.layers.enable(k.getCaptureLayer(r));
1085
+ for (let r = t.captureLayer; r <= I.MAX_LAYERS + 1; r++)
1086
+ e.layers.enable(R.getCaptureLayer(r));
1083
1087
  }
1084
1088
  captureRenderTarget(e, t, i) {
1085
1089
  if (e.size === 0 || !i)
1086
1090
  return;
1087
1091
  const r = new y.Color(), o = this.renderer.getClearAlpha();
1088
1092
  this.renderer.getClearColor(r), this.renderer.setClearColor(0, 0), this.renderer.setRenderTarget(i), this.renderer.clear(), this.renderer.autoClear = !1, this.renderer.setScissorTest(!0), this.camera.layers.set(t);
1089
- const n = new y.Vector3(), c = 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();
1090
- for (const u of e) {
1091
- n.setFromMatrixPosition(u.matrixWorld), n.project(this.camera);
1092
- const h = (n.x + 1) / 2 * c, f = (n.y + 1) / 2 * a;
1093
- let v = 0, g = 1;
1094
- typeof this.clipArea == "number" ? g = this.clipArea : this.clipArea.endsWith("%") ? g = parseFloat(this.clipArea) / 100 : this.clipArea.endsWith("px") && (v = parseFloat(this.clipArea));
1095
- const p = u.scale.x * g + 0.5, E = u.scale.y * g + 0.5, L = h - p / 2, R = f - E / 2, x = (L * this.qualityFactor - v) / l, w = (R * this.qualityFactor - v) / l, B = (p * this.qualityFactor + v * 2) / l, M = (E * this.qualityFactor + v * 2) / l;
1096
- this.renderer.setScissor(x, w, B, M), this.renderer.render(this.scene, this.camera);
1093
+ const n = new y.Vector3(), a = this.isViewport ? window.innerWidth + this.overscan * 2 : this.targetRect.width, c = this.isViewport ? window.innerHeight + this.overscan * 2 : this.targetRect.height, l = this.renderer.getPixelRatio();
1094
+ for (const d of e) {
1095
+ n.setFromMatrixPosition(d.matrixWorld), n.project(this.camera);
1096
+ const h = (n.x + 1) / 2 * a, f = (n.y + 1) / 2 * c;
1097
+ let p = 0, g = 1;
1098
+ typeof this.clipArea == "number" ? g = this.clipArea : this.clipArea.endsWith("%") ? g = parseFloat(this.clipArea) / 100 : this.clipArea.endsWith("px") && (p = parseFloat(this.clipArea));
1099
+ const m = d.scale.x * g + 0.5, E = d.scale.y * g + 0.5, L = h - m / 2, M = f - E / 2, w = (L * this.qualityFactor - p) / l, b = (M * this.qualityFactor - p) / l, U = (m * this.qualityFactor + p * 2) / l, A = (E * this.qualityFactor + p * 2) / l;
1100
+ this.renderer.setScissor(w, b, U, A), this.renderer.render(this.scene, this.camera);
1097
1101
  }
1098
1102
  this.renderer.setScissorTest(!1), this.renderer.autoClear = !0, this.renderer.setRenderTarget(null), this.camera.layers.set(this.getSceneLayer()), this.renderer.setClearColor(r, o);
1099
1103
  }
1100
1104
  render() {
1101
- for (let e = 0; e < F.MAX_LAYERS; e++) {
1105
+ for (let e = 0; e < I.MAX_LAYERS; e++) {
1102
1106
  const t = e + 1;
1103
1107
  this.captureRenderTarget(
1104
1108
  this.travelersByLayer[e],
1105
- k.getCaptureLayer(t),
1109
+ R.getCaptureLayer(t),
1106
1110
  this.renderTargets[e]
1107
1111
  );
1108
1112
  }
1109
1113
  this.renderer.render(this.scene, this.camera);
1110
1114
  }
1111
- updateCameraScroll(e, t) {
1112
- this.isViewport && (this.camera.position.x = e, this.camera.position.y = -t, this.camera.updateMatrixWorld());
1115
+ syncMeshesByDOM() {
1116
+ const e = this.targetRect.left + window.scrollX, t = this.targetRect.top + window.scrollY, i = this.renderer.getPixelRatio(), r = this.renderer.domElement.width / i, o = this.renderer.domElement.height / i;
1117
+ this.scene.children.forEach((n) => {
1118
+ const a = n;
1119
+ if (!a.userData || !a.userData.domElement)
1120
+ return;
1121
+ const c = a.userData.domElement;
1122
+ let l;
1123
+ if (c.nodeType === Node.TEXT_NODE) {
1124
+ const h = document.createRange();
1125
+ h.selectNode(c), l = h.getBoundingClientRect();
1126
+ } else
1127
+ l = c.getBoundingClientRect();
1128
+ const d = a.userData.domRect;
1129
+ if (!d || Math.abs(l.x - d.x) > 0.5 || Math.abs(l.y - d.y) > 0.5 || Math.abs(l.width - d.width) > 0.5 || Math.abs(l.height - d.height) > 0.5) {
1130
+ a.userData.domRect = { x: l.x, y: l.y, width: l.width, height: l.height };
1131
+ let h, f;
1132
+ if (this.isViewport)
1133
+ h = l.x - window.innerWidth / 2 + l.width / 2, f = -l.y + window.innerHeight / 2 - l.height / 2;
1134
+ else {
1135
+ const p = l.x - e, g = l.y - t;
1136
+ h = p - r / 2 + l.width / 2, f = -g + o / 2 - l.height / 2;
1137
+ }
1138
+ if (a.position.setX(h), a.position.setY(f), a.scale.set(l.width, l.height, 1), a.material instanceof y.ShaderMaterial && Y.forceUpdateUniforms(a.material, {
1139
+ width: l.width,
1140
+ height: l.height
1141
+ }), a.userData.nativeMesh) {
1142
+ const p = a.userData.nativeMesh;
1143
+ p.position.setX(h), p.position.setY(f), p.scale.set(l.width, l.height, 1);
1144
+ }
1145
+ }
1146
+ });
1113
1147
  }
1114
1148
  }
1115
- function st(s) {
1149
+ function it(s) {
1116
1150
  const e = s.textContent || "", t = [];
1117
1151
  let i = "", r = null, o = -1;
1118
- const n = (l, u) => {
1152
+ const n = (l, d) => {
1119
1153
  for (let h = 0; h < l.length; h++) {
1120
- const f = l[h], v = document.createRange();
1121
- v.setStart(s, u + h), v.setEnd(s, u + h + 1);
1122
- const g = v.getBoundingClientRect();
1154
+ const f = l[h], p = document.createRange();
1155
+ p.setStart(s, d + h), p.setEnd(s, d + h + 1);
1156
+ const g = p.getBoundingClientRect();
1123
1157
  if (g.width === 0 && g.height === 0) {
1124
1158
  i += f;
1125
1159
  continue;
@@ -1142,18 +1176,18 @@ function st(s) {
1142
1176
  g.bottom
1143
1177
  )));
1144
1178
  }
1145
- }, c = e.match(/[^\s\-]+\-?|\-|\s+/g) || [];
1146
- let a = 0;
1147
- for (const l of c) {
1148
- const u = document.createRange();
1149
- u.setStart(s, a), u.setEnd(s, a + l.length);
1150
- const h = u.getClientRects();
1179
+ }, a = e.match(/[^\s\-]+\-?|\-|\s+/g) || [];
1180
+ let c = 0;
1181
+ for (const l of a) {
1182
+ const d = document.createRange();
1183
+ d.setStart(s, c), d.setEnd(s, c + l.length);
1184
+ const h = d.getClientRects();
1151
1185
  if (h.length > 1)
1152
- n(l, a);
1186
+ n(l, c);
1153
1187
  else {
1154
- const f = h.length === 1 ? h[0] : u.getBoundingClientRect();
1188
+ const f = h.length === 1 ? h[0] : d.getBoundingClientRect();
1155
1189
  if (f.width === 0 && f.height === 0) {
1156
- i += l, a += l.length;
1190
+ i += l, c += l.length;
1157
1191
  continue;
1158
1192
  }
1159
1193
  o === -1 || Math.abs(f.top - o) > f.height / 2 ? (i && r && t.push({
@@ -1174,7 +1208,7 @@ function st(s) {
1174
1208
  f.bottom
1175
1209
  )));
1176
1210
  }
1177
- a += l.length;
1211
+ c += l.length;
1178
1212
  }
1179
1213
  return i && r && t.push({
1180
1214
  text: i,
@@ -1188,7 +1222,7 @@ function st(s) {
1188
1222
  (l) => l.text.trim().length > 0 && l.rect.width > 0 && l.rect.height > 0
1189
1223
  );
1190
1224
  }
1191
- function Me(s) {
1225
+ function Le(s) {
1192
1226
  const e = parseFloat(s.fontSize);
1193
1227
  let t = parseFloat(s.lineHeight);
1194
1228
  isNaN(t) && (t = e * 1.2);
@@ -1204,308 +1238,284 @@ function Me(s) {
1204
1238
  letterSpacing: i
1205
1239
  };
1206
1240
  }
1207
- function Oe(s, e = q | ne | We | ye | ve, t, i = 1, r = 0, o = 2, n, c) {
1208
- var Q, Z, ee, te, re, ie;
1241
+ function ke(s, e = q | Q | Ye | ce | re, t, i = 1, r = 0, o = 2, n, a) {
1242
+ var de, ue, fe, ge, pe, me;
1209
1243
  if (s.nodeType === Node.TEXT_NODE) {
1210
- const m = s;
1211
- if (!m.textContent || !m.textContent.trim())
1244
+ const v = s;
1245
+ if (!v.textContent || !v.textContent.trim())
1212
1246
  return null;
1213
- const T = m.textContent.replace(/\s+/g, " ");
1214
- if (T.length === 0)
1247
+ const C = v.textContent.replace(/\s+/g, " ");
1248
+ if (C.length === 0)
1215
1249
  return null;
1216
- const D = st(m);
1250
+ const D = it(v);
1217
1251
  if (D.length === 0)
1218
1252
  return null;
1219
- const I = m.parentElement, S = I ? window.getComputedStyle(I) : null;
1253
+ const B = v.parentElement, S = B ? window.getComputedStyle(B) : null;
1220
1254
  if (!S)
1221
1255
  return null;
1222
- const U = Math.min(...D.map((b) => b.rect.left)), C = Math.min(...D.map((b) => b.rect.top)), z = Math.max(...D.map((b) => b.rect.left + b.rect.width)), P = Math.max(...D.map((b) => b.rect.top + b.rect.height));
1256
+ const z = Math.min(...D.map((T) => T.rect.left)), x = Math.min(...D.map((T) => T.rect.top)), X = Math.max(...D.map((T) => T.rect.left + T.rect.width)), G = Math.max(...D.map((T) => T.rect.top + T.rect.height));
1223
1257
  return {
1224
1258
  id: Math.random().toString(36).substring(2, 9),
1225
1259
  type: "TEXT",
1226
- element: m,
1260
+ element: v,
1227
1261
  rect: {
1228
- x: U + window.scrollX,
1229
- y: C + window.scrollY,
1230
- width: z - U,
1231
- height: P - C
1262
+ x: z + window.scrollX,
1263
+ y: x + window.scrollY,
1264
+ width: X - z,
1265
+ height: G - x
1232
1266
  },
1233
1267
  styles: {
1234
1268
  backgroundColor: "transparent",
1235
1269
  backgroundImage: "",
1236
- opacity: I && I.dataset[$.KEY] === $.VALUES.HIDE ? 1 : parseFloat(S.opacity),
1270
+ opacity: B && B.dataset[H.KEY] === H.VALUES.HIDE ? 1 : parseFloat(S.opacity),
1237
1271
  zIndex: (isNaN(parseInt(S.zIndex)) ? 0 : parseInt(S.zIndex)) + r,
1238
1272
  borderRadius: "0px",
1239
1273
  borderColor: "transparent",
1240
1274
  borderWidth: "0px",
1241
1275
  isTraveler: !1
1242
1276
  },
1243
- textContent: T,
1244
- textLines: D.map((b) => ({
1245
- text: b.text.trim(),
1277
+ textContent: C,
1278
+ textLines: D.map((T) => ({
1279
+ text: T.text.trim(),
1246
1280
  rect: {
1247
- x: b.rect.left + window.scrollX,
1248
- y: b.rect.top + window.scrollY,
1249
- width: b.rect.width,
1250
- height: b.rect.height
1281
+ x: T.rect.left + window.scrollX,
1282
+ y: T.rect.top + window.scrollY,
1283
+ width: T.rect.width,
1284
+ height: T.rect.height
1251
1285
  }
1252
1286
  })),
1253
- textStyles: Me(S),
1287
+ textStyles: Le(S),
1254
1288
  dirtyMask: e,
1255
1289
  visibility: t,
1256
1290
  isTraveler: !1,
1257
1291
  captureLayer: i,
1258
1292
  isFixed: S.position === "fixed",
1259
1293
  nativeLayer: n,
1260
- nativeStyles: c ? G(G({
1294
+ nativeStyles: a ? $($({
1261
1295
  backgroundColor: "transparent",
1262
1296
  backgroundImage: "",
1263
- opacity: I && I.dataset[$.KEY] === $.VALUES.HIDE ? 1 : parseFloat(S.opacity),
1297
+ opacity: B && B.dataset[H.KEY] === H.VALUES.HIDE ? 1 : parseFloat(S.opacity),
1264
1298
  zIndex: (isNaN(parseInt(S.zIndex)) ? 0 : parseInt(S.zIndex)) + r,
1265
1299
  borderRadius: "0px",
1266
1300
  borderColor: "transparent",
1267
1301
  borderWidth: "0px",
1268
1302
  isTraveler: !1
1269
- }, Me(S)), c) : void 0,
1270
- nativeRect: c ? {
1271
- x: U + window.scrollX,
1272
- y: C + window.scrollY,
1273
- width: z - U,
1274
- height: P - C
1303
+ }, Le(S)), a) : void 0,
1304
+ nativeRect: a ? {
1305
+ x: z + window.scrollX,
1306
+ y: x + window.scrollY,
1307
+ width: X - z,
1308
+ height: G - x
1275
1309
  } : void 0,
1276
1310
  children: []
1277
1311
  };
1278
1312
  }
1279
1313
  if (s.nodeType !== Node.ELEMENT_NODE)
1280
1314
  return null;
1281
- const a = s, l = a.dataset[N.KEY];
1282
- let u = t, h = t;
1315
+ const c = s, l = c.dataset[F.KEY];
1316
+ let d = t, h = t;
1283
1317
  if (l) {
1284
- const m = new Set(l.split(/\s+/));
1285
- for (const T of m)
1286
- if (!Le.includes(T))
1318
+ const v = new Set(l.split(/\s+/));
1319
+ for (const C of v)
1320
+ if (!Te.includes(C))
1287
1321
  throw new Error(
1288
- `[MirageEngine] Invalid filter token: '${T}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1322
+ `[MirageEngine] Invalid filter token: '${C}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1289
1323
  );
1290
- if (m.has(N.VALUES.END))
1324
+ if (v.has(F.VALUES.END))
1291
1325
  return null;
1292
- if (m.has(N.VALUES.INCLUDE_TREE) && m.has(N.VALUES.EXCLUDE_TREE))
1326
+ if (v.has(F.VALUES.INCLUDE_TREE) && v.has(F.VALUES.EXCLUDE_TREE))
1293
1327
  throw new Error(
1294
1328
  "[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element."
1295
1329
  );
1296
- if (m.has(N.VALUES.INCLUDE_SELF) && m.has(N.VALUES.EXCLUDE_SELF))
1330
+ if (v.has(F.VALUES.INCLUDE_SELF) && v.has(F.VALUES.EXCLUDE_SELF))
1297
1331
  throw new Error(
1298
1332
  "[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element."
1299
1333
  );
1300
- m.has(N.VALUES.INCLUDE_TREE) ? u = u | W : m.has(N.VALUES.EXCLUDE_TREE) && (u = u & ~W), h = u, m.has(N.VALUES.INCLUDE_SELF) ? h = h | W : m.has(N.VALUES.EXCLUDE_SELF) && (h = h & ~W);
1334
+ v.has(F.VALUES.INCLUDE_TREE) ? d = d | W : v.has(F.VALUES.EXCLUDE_TREE) && (d = d & ~W), h = d, v.has(F.VALUES.INCLUDE_SELF) ? h = h | W : v.has(F.VALUES.EXCLUDE_SELF) && (h = h & ~W);
1301
1335
  }
1302
- const f = a.dataset[V.KEY];
1336
+ const f = c.dataset[V.KEY];
1303
1337
  if (f) {
1304
- const m = new Set(f.split(/\s+/));
1305
- for (const T of m)
1306
- if (!Le.includes(T))
1338
+ const v = new Set(f.split(/\s+/));
1339
+ for (const C of v)
1340
+ if (!Te.includes(C))
1307
1341
  throw new Error(
1308
- `[MirageEngine] Invalid select token: '${T}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1342
+ `[MirageEngine] Invalid select token: '${C}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1309
1343
  );
1310
- if (m.has(V.VALUES.END))
1344
+ if (v.has(V.VALUES.END))
1311
1345
  return null;
1312
- if (m.has(V.VALUES.INCLUDE_TREE) && m.has(V.VALUES.EXCLUDE_TREE))
1346
+ if (v.has(V.VALUES.INCLUDE_TREE) && v.has(V.VALUES.EXCLUDE_TREE))
1313
1347
  throw new Error(
1314
1348
  "[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element."
1315
1349
  );
1316
- if (m.has(V.VALUES.INCLUDE_SELF) && m.has(V.VALUES.EXCLUDE_SELF))
1350
+ if (v.has(V.VALUES.INCLUDE_SELF) && v.has(V.VALUES.EXCLUDE_SELF))
1317
1351
  throw new Error(
1318
1352
  "[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element."
1319
1353
  );
1320
- m.has(V.VALUES.INCLUDE_TREE) ? u = u | j : m.has(V.VALUES.EXCLUDE_TREE) && (u = u & ~j), h = u, m.has(V.VALUES.INCLUDE_SELF) ? h = h | j : m.has(V.VALUES.EXCLUDE_SELF) && (h = h & ~j);
1321
- }
1322
- const v = a.dataset[F.KEY];
1323
- let g = !1, p = c ? G({}, c) : {}, E = n;
1324
- if (v) {
1325
- let m = 1;
1326
- const T = v.indexOf("{"), D = v.lastIndexOf("}");
1327
- let I = v;
1328
- if (T !== -1 && D !== -1 && D > T) {
1329
- I = v.substring(0, T).trim();
1330
- const C = v.substring(T, D + 1);
1354
+ v.has(V.VALUES.INCLUDE_TREE) ? d = d | j : v.has(V.VALUES.EXCLUDE_TREE) && (d = d & ~j), h = d, v.has(V.VALUES.INCLUDE_SELF) ? h = h | j : v.has(V.VALUES.EXCLUDE_SELF) && (h = h & ~j);
1355
+ }
1356
+ const p = c.dataset[I.KEY];
1357
+ let g = !1, m = a ? $({}, a) : {}, E = n;
1358
+ if (p) {
1359
+ let v = 1;
1360
+ const C = p.indexOf("{"), D = p.lastIndexOf("}");
1361
+ let B = p;
1362
+ if (C !== -1 && D !== -1 && D > C) {
1363
+ B = p.substring(0, C).trim();
1364
+ const x = p.substring(C, D + 1);
1331
1365
  try {
1332
- p = new Function("return " + C)();
1333
- } catch (z) {
1366
+ m = new Function("return " + x)();
1367
+ } catch (X) {
1334
1368
  console.warn(
1335
- `[MirageEngine] Failed to parse travel styles JSON: ${C}`
1369
+ `[MirageEngine] Failed to parse travel styles JSON: ${x}`
1336
1370
  );
1337
1371
  }
1338
1372
  }
1339
- const S = I.split(/\s+/);
1340
- let U = !1;
1341
- if (S.includes(F.VALUES.TRAVELER)) {
1342
- g = !0, U = !0;
1343
- const C = S.find((z) => !isNaN(parseInt(z, 10)));
1344
- C && (m = parseInt(C, 10));
1345
- } else if (S.includes(F.VALUES.NATIVE)) {
1373
+ const S = B.split(/\s+/);
1374
+ let z = !1;
1375
+ if (S.includes(I.VALUES.TRAVELER)) {
1376
+ g = !0, z = !0;
1377
+ const x = S.find((X) => !isNaN(parseInt(X, 10)));
1378
+ x && (v = parseInt(x, 10));
1379
+ } else if (S.includes(I.VALUES.NATIVE)) {
1346
1380
  g = !1;
1347
- const C = S.find((z) => !isNaN(parseInt(z, 10)));
1348
- C && (E = parseInt(C, 10));
1381
+ const x = S.find((X) => !isNaN(parseInt(X, 10)));
1382
+ x && (E = parseInt(x, 10));
1349
1383
  }
1350
- if (U) {
1351
- const C = m + 1;
1352
- if (C < i)
1384
+ if (z) {
1385
+ const x = v + 1;
1386
+ if (x < i)
1353
1387
  throw new Error(
1354
- `[MirageEngine] Traveler layer (${m}) cannot be smaller than inherited capture layer (${i - 1}).`
1388
+ `[MirageEngine] Traveler layer (${v}) cannot be smaller than inherited capture layer (${i - 1}).`
1355
1389
  );
1356
- i = Math.min(C, F.MAX_LAYERS + 1);
1390
+ i = Math.min(x, I.MAX_LAYERS + 1);
1357
1391
  }
1358
1392
  }
1359
- const L = a.dataset[Ve.KEY];
1360
- let R;
1361
- L && (R = JSON.parse(L));
1362
- const x = a.getBoundingClientRect(), w = window.getComputedStyle(a);
1363
- if (x.width === 0 || x.height === 0 || w.display === "none")
1393
+ const L = c.dataset[Ve.KEY];
1394
+ let M;
1395
+ L && (M = JSON.parse(L));
1396
+ const w = c.getBoundingClientRect(), b = window.getComputedStyle(c);
1397
+ if (w.width === 0 || w.height === 0 || b.display === "none")
1364
1398
  return null;
1365
- let B = a.getAttribute("data-mid");
1366
- B || (B = Math.random().toString(36).substring(2, 11), a.setAttribute("data-mid", B));
1367
- const M = parseInt(w.zIndex), O = (isNaN(M) ? 0 : M) + r;
1368
- let _;
1369
- if (a.tagName === "IMG")
1370
- _ = a.src;
1371
- else if (a.tagName.toLowerCase() === "svg") {
1372
- const m = a.cloneNode(!0), T = p == null ? void 0 : p.color, D = p == null ? void 0 : p.fill, I = p == null ? void 0 : p.stroke, S = p == null ? void 0 : p.opacity, U = (b, we) => {
1373
- const X = window.getComputedStyle(b), se = we, Ue = X.fill === X.color, Fe = X.stroke === X.color, de = D || (Ue ? T : void 0) || X.fill;
1374
- de && de !== "none" && (se.style.fill = de);
1375
- const ue = I || (Fe ? T : void 0) || X.stroke;
1376
- ue && ue !== "none" && (se.style.stroke = ue), X.strokeWidth && X.strokeWidth !== "0px" && (se.style.strokeWidth = X.strokeWidth);
1377
- const xe = T || X.color;
1378
- xe && (se.style.color = xe);
1379
- const fe = S || X.opacity;
1380
- fe && fe !== "1" && (se.style.opacity = fe);
1381
- for (let le = 0; le < b.children.length; le++)
1382
- U(b.children[le], we.children[le]);
1399
+ let U = c.getAttribute("data-mid");
1400
+ U || (U = Math.random().toString(36).substring(2, 11), c.setAttribute("data-mid", U));
1401
+ const A = parseInt(b.zIndex), O = (isNaN(A) ? 0 : A) + r;
1402
+ let N;
1403
+ if (c.tagName === "IMG")
1404
+ N = c.src;
1405
+ else if (c.tagName.toLowerCase() === "svg") {
1406
+ const v = c.cloneNode(!0), C = m == null ? void 0 : m.color, D = m == null ? void 0 : m.fill, B = m == null ? void 0 : m.stroke, S = m == null ? void 0 : m.opacity, z = (T, ve) => {
1407
+ const _ = window.getComputedStyle(T), J = ve, Oe = _.fill === _.color, Be = _.stroke === _.color, ie = D || (Oe ? C : void 0) || _.fill;
1408
+ ie && ie !== "none" && (J.style.fill = ie);
1409
+ const se = B || (Be ? C : void 0) || _.stroke;
1410
+ se && se !== "none" && (J.style.stroke = se), _.strokeWidth && _.strokeWidth !== "0px" && (J.style.strokeWidth = _.strokeWidth);
1411
+ const ye = C || _.color;
1412
+ ye && (J.style.color = ye);
1413
+ const ne = S || _.opacity;
1414
+ ne && ne !== "1" && (J.style.opacity = ne);
1415
+ for (let ee = 0; ee < T.children.length; ee++)
1416
+ z(T.children[ee], ve.children[ee]);
1383
1417
  };
1384
- U(a, m);
1385
- const C = a.getBoundingClientRect(), z = window.devicePixelRatio * o;
1386
- m.hasAttribute("viewBox") || m.setAttribute("viewBox", `0 0 ${C.width} ${C.height}`), m.setAttribute("width", (C.width * z).toString()), m.setAttribute("height", (C.height * z).toString());
1387
- let P = new XMLSerializer().serializeToString(m);
1388
- P.includes("xmlns=") || (P = P.replace(
1418
+ z(c, v);
1419
+ const x = c.getBoundingClientRect(), X = window.devicePixelRatio * o;
1420
+ v.hasAttribute("viewBox") || v.setAttribute("viewBox", `0 0 ${x.width} ${x.height}`), v.setAttribute("width", (x.width * X).toString()), v.setAttribute("height", (x.height * X).toString());
1421
+ let G = new XMLSerializer().serializeToString(v);
1422
+ G.includes("xmlns=") || (G = G.replace(
1389
1423
  "<svg",
1390
1424
  '<svg xmlns="http://www.w3.org/2000/svg"'
1391
- )), _ = `data:image/svg+xml;utf8,${encodeURIComponent(P)}`;
1392
- } else if (w.backgroundImage && w.backgroundImage !== "none") {
1393
- const m = w.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
1394
- m && (_ = m[1]);
1395
- }
1396
- const A = {
1397
- backgroundColor: w.backgroundColor,
1398
- backgroundImage: w.backgroundImage,
1399
- opacity: a.dataset[$.KEY] === $.VALUES.HIDE ? 1 : parseFloat(w.opacity),
1425
+ )), N = `data:image/svg+xml;utf8,${encodeURIComponent(G)}`;
1426
+ } else if (b.backgroundImage && b.backgroundImage !== "none") {
1427
+ const v = b.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
1428
+ v && (N = v[1]);
1429
+ }
1430
+ const k = {
1431
+ backgroundColor: b.backgroundColor,
1432
+ backgroundImage: b.backgroundImage,
1433
+ opacity: c.dataset[H.KEY] === H.VALUES.HIDE ? 1 : parseFloat(b.opacity),
1400
1434
  zIndex: O,
1401
- borderRadius: w.borderRadius,
1402
- borderColor: w.borderColor,
1403
- borderWidth: w.borderWidth,
1404
- imageSrc: _,
1435
+ borderRadius: b.borderRadius,
1436
+ borderColor: b.borderColor,
1437
+ borderWidth: b.borderWidth,
1438
+ imageSrc: N,
1405
1439
  isTraveler: g
1406
- }, Y = A;
1407
- let ae, ce;
1408
- const J = [];
1409
- return a.tagName.toLowerCase() !== "svg" && Array.from(a.childNodes).forEach((m) => {
1410
- const T = m.nodeType === Node.TEXT_NODE ? h : u, D = Oe(
1411
- m,
1440
+ }, P = k;
1441
+ let Ie, Ue;
1442
+ const he = [];
1443
+ return c.tagName.toLowerCase() !== "svg" && Array.from(c.childNodes).forEach((v) => {
1444
+ const C = v.nodeType === Node.TEXT_NODE ? h : d, D = ke(
1445
+ v,
1412
1446
  e,
1413
- T,
1447
+ C,
1414
1448
  i,
1415
1449
  O,
1416
1450
  o,
1417
1451
  E,
1418
- m.nodeType === Node.TEXT_NODE && Object.keys(p).length > 0 ? p : void 0
1452
+ v.nodeType === Node.TEXT_NODE && Object.keys(m).length > 0 ? m : void 0
1419
1453
  );
1420
- D && J.push(D);
1454
+ D && he.push(D);
1421
1455
  }), {
1422
- id: B,
1456
+ id: U,
1423
1457
  type: "BOX",
1424
- element: a,
1458
+ element: c,
1425
1459
  rect: {
1426
- x: x.left + window.scrollX,
1427
- y: x.top + window.scrollY,
1428
- width: x.width,
1429
- height: x.height
1460
+ x: w.left + window.scrollX,
1461
+ y: w.top + window.scrollY,
1462
+ width: w.width,
1463
+ height: w.height
1430
1464
  },
1431
- styles: Y,
1432
- textContent: ae,
1433
- textStyles: ce,
1465
+ styles: P,
1466
+ textContent: Ie,
1467
+ textStyles: Ue,
1434
1468
  dirtyMask: e,
1435
1469
  visibility: h,
1436
1470
  isTraveler: g,
1437
1471
  captureLayer: i,
1438
1472
  nativeLayer: E,
1439
- nativeStyles: E !== void 0 ? pe(G({}, A), {
1440
- backgroundColor: (Q = p.backgroundColor) != null ? Q : A.backgroundColor,
1441
- backgroundImage: (Z = p.backgroundImage) != null ? Z : A.backgroundImage,
1442
- opacity: (ee = p.opacity) != null ? ee : A.opacity,
1443
- zIndex: p.zIndex !== void 0 ? p.zIndex + O : A.zIndex,
1444
- borderRadius: (te = p.borderRadius) != null ? te : A.borderRadius,
1445
- borderColor: (re = p.borderColor) != null ? re : A.borderColor,
1446
- borderWidth: (ie = p.borderWidth) != null ? ie : A.borderWidth,
1447
- isTraveler: A.isTraveler
1473
+ nativeStyles: E !== void 0 ? we($({}, k), {
1474
+ backgroundColor: (de = m.backgroundColor) != null ? de : k.backgroundColor,
1475
+ backgroundImage: (ue = m.backgroundImage) != null ? ue : k.backgroundImage,
1476
+ opacity: (fe = m.opacity) != null ? fe : k.opacity,
1477
+ zIndex: m.zIndex !== void 0 ? m.zIndex + O : k.zIndex,
1478
+ borderRadius: (ge = m.borderRadius) != null ? ge : k.borderRadius,
1479
+ borderColor: (pe = m.borderColor) != null ? pe : k.borderColor,
1480
+ borderWidth: (me = m.borderWidth) != null ? me : k.borderWidth,
1481
+ isTraveler: k.isTraveler
1448
1482
  }) : void 0,
1449
1483
  nativeRect: E !== void 0 ? {
1450
- x: p.x !== void 0 ? parseFloat(p.x) : x.left + window.scrollX,
1451
- y: p.y !== void 0 ? parseFloat(p.y) : x.top + window.scrollY,
1452
- width: p.width !== void 0 ? parseFloat(p.width) : x.width,
1453
- height: p.height !== void 0 ? parseFloat(p.height) : x.height
1484
+ x: m.x !== void 0 ? parseFloat(m.x) : w.left + window.scrollX,
1485
+ y: m.y !== void 0 ? parseFloat(m.y) : w.top + window.scrollY,
1486
+ width: m.width !== void 0 ? parseFloat(m.width) : w.width,
1487
+ height: m.height !== void 0 ? parseFloat(m.height) : w.height
1454
1488
  } : void 0,
1455
- isFixed: w.position === "fixed",
1456
- children: J,
1457
- shaderHooks: R
1489
+ isFixed: b.position === "fixed",
1490
+ children: he,
1491
+ shaderHooks: M
1458
1492
  };
1459
1493
  }
1460
- function nt(s, e) {
1494
+ function st(s, e) {
1461
1495
  e.size !== 0 && e.forEach((t, i) => {
1462
- var B, M, O, _, A, Y, ae, ce, J, Q, Z, ee, te, re, ie, m, T, D;
1496
+ var o, n;
1463
1497
  const r = s.get(i);
1464
- if (!r || !r.userData.basePosition)
1465
- return;
1466
- let { x: o, y: n } = r.userData.basePosition;
1467
- const { width: c, height: a } = r.userData.baseSize, l = (B = t.width) != null ? B : c, u = (M = t.height) != null ? M : a, h = l - c, f = u - a;
1468
- if (t.width !== void 0 && r.userData.originRatioX === void 0 && Math.abs(h) > 0.1) {
1469
- const I = i.getBoundingClientRect(), S = (O = t.x) != null ? O : 0, U = (A = (_ = r.userData.baseTransform) == null ? void 0 : _.x) != null ? A : 0, C = r.userData.isFixed ? 0 : window.scrollX;
1470
- let b = -(I.left + C - S + U - r.userData.baseDOM.x) / h;
1471
- Math.abs(b) < 0.05 ? b = 0 : Math.abs(b - 1) < 0.05 ? b = 1 : Math.abs(b - 0.5) < 0.05 && (b = 0.5), r.userData.originRatioX = b;
1472
- }
1473
- if (t.height !== void 0 && r.userData.originRatioY === void 0 && Math.abs(f) > 0.1) {
1474
- const I = i.getBoundingClientRect(), S = (Y = t.y) != null ? Y : 0, U = (ce = (ae = r.userData.baseTransform) == null ? void 0 : ae.y) != null ? ce : 0, C = r.userData.isFixed ? 0 : window.scrollY;
1475
- let b = -(I.top + C - S + U - r.userData.baseDOM.y) / f;
1476
- Math.abs(b) < 0.05 ? b = 0 : Math.abs(b - 1) < 0.05 ? b = 1 : Math.abs(b - 0.5) < 0.05 && (b = 0.5), r.userData.originRatioY = b;
1477
- }
1478
- const v = (J = r.userData.originRatioX) != null ? J : 0.5, g = (Q = r.userData.originRatioY) != null ? Q : 0.5, p = h * (0.5 - v), E = f * (0.5 - g), L = (ee = (Z = r.userData.baseTransform) == null ? void 0 : Z.x) != null ? ee : 0, R = (re = (te = r.userData.baseTransform) == null ? void 0 : te.y) != null ? re : 0, x = ((ie = t.x) != null ? ie : L) - L, w = ((m = t.y) != null ? m : R) - R;
1479
- r.position.setX(o + p + x), r.position.setY(n - (E + w)), r.scale.set(l, u, 1), H.forceUpdateUniforms(r.material, {
1498
+ !r || !r.userData.basePosition || Y.forceUpdateUniforms(r.material, {
1480
1499
  backgroundColor: t.backgroundColor,
1481
1500
  backgroundImage: t.backgroundImage,
1482
1501
  opacity: t.opacity,
1483
- borderRadius: (D = t.borderRadius) != null ? D : (T = r.userData.baseStyles) == null ? void 0 : T.borderRadius,
1484
- width: l,
1485
- height: u
1502
+ borderRadius: (n = t.borderRadius) != null ? n : (o = r.userData.baseStyles) == null ? void 0 : o.borderRadius
1503
+ // width and height are no longer updated here, they are updated in syncMeshesByDOM
1486
1504
  });
1487
1505
  });
1488
1506
  }
1489
- function De(s, e, t) {
1490
- s.forEach((i) => {
1491
- if (i.userData.isFixed && i.userData.initialScroll && i.userData.originalBasePosition) {
1492
- const r = e - i.userData.initialScroll.x, o = t - i.userData.initialScroll.y;
1493
- i.userData.basePosition.x = i.userData.originalBasePosition.x + r, i.userData.basePosition.y = i.userData.originalBasePosition.y - o, i.position.x = i.userData.basePosition.x, i.position.y = i.userData.basePosition.y;
1494
- }
1495
- });
1496
- }
1497
- class ot {
1507
+ class nt {
1498
1508
  constructor(e, t, i, r) {
1499
- d(this, "target");
1500
- d(this, "renderer");
1501
- d(this, "registry");
1502
- d(this, "isTravelEnabled", !1);
1503
- d(this, "tracker");
1504
- this.target = e, this.renderer = t, this.registry = i, this.tracker = new ke(e, {
1509
+ u(this, "target");
1510
+ u(this, "renderer");
1511
+ u(this, "registry");
1512
+ u(this, "isTravelEnabled", !1);
1513
+ u(this, "tracker");
1514
+ this.target = e, this.renderer = t, this.registry = i, this.tracker = new Me(e, {
1505
1515
  resizeDebounce: r.resizeDebounce
1506
1516
  }), this.tracker.onLayoutChange.add((o, n) => {
1507
- document.querySelector(`[${F.NAME}~='${F.VALUES.TRAVELER}']`) !== null && !this.isTravelEnabled && (this.isTravelEnabled = !0, this.renderer.createRenderTarget());
1508
- const a = Oe(
1517
+ document.querySelector(`[${I.NAME}~='${I.VALUES.TRAVELER}']`) !== null && !this.isTravelEnabled && (this.isTravelEnabled = !0, this.renderer.createRenderTarget());
1518
+ const c = ke(
1509
1519
  this.target,
1510
1520
  o,
1511
1521
  W,
@@ -1513,25 +1523,23 @@ class ot {
1513
1523
  0,
1514
1524
  this.renderer.qualityFactor
1515
1525
  );
1516
- a && this.renderer.syncScene(a, n);
1517
- }), this.tracker.onScrollChange.add((o, n) => {
1518
- De(this.renderer.fixedMeshes, o, n), this.renderer.updateCameraScroll(o, n);
1526
+ c && this.renderer.syncScene(c, n);
1519
1527
  }), this.tracker.onStyleChange.add((o) => {
1520
- nt(this.registry, o);
1528
+ st(this.registry, o);
1521
1529
  }), this.tracker.onRender.add(() => {
1522
- this.renderer.render();
1530
+ this.renderer.syncMeshesByDOM(), this.renderer.render();
1523
1531
  });
1524
1532
  }
1525
1533
  start() {
1526
- this.tracker.start(), De(this.renderer.fixedMeshes, window.scrollX, window.scrollY), this.renderer.updateCameraScroll(window.scrollX, window.scrollY);
1534
+ this.tracker.start();
1527
1535
  }
1528
1536
  stop() {
1529
1537
  this.tracker.stop();
1530
1538
  }
1531
1539
  }
1532
- class at {
1540
+ class ot {
1533
1541
  constructor() {
1534
- d(this, "store");
1542
+ u(this, "store");
1535
1543
  this.store = /* @__PURE__ */ new WeakMap();
1536
1544
  }
1537
1545
  register(e, t) {
@@ -1554,30 +1562,30 @@ class at {
1554
1562
  this.store.delete(e);
1555
1563
  }
1556
1564
  }
1557
- class ct {
1565
+ class at {
1558
1566
  constructor(e, t) {
1559
- d(this, "renderer");
1560
- d(this, "syncer");
1561
- d(this, "target");
1562
- d(this, "registry");
1567
+ u(this, "renderer");
1568
+ u(this, "syncer");
1569
+ u(this, "target");
1570
+ u(this, "registry");
1563
1571
  var r, o, n;
1564
- if (this.target = e, this.registry = new at(), !document.getElementById("mirage-engine-styles")) {
1565
- const c = document.createElement("style");
1566
- c.id = "mirage-engine-styles", c.textContent = `
1567
- [${$.NAME}="${$.VALUES.HIDE}"] {
1572
+ if (this.target = e, this.registry = new ot(), !document.getElementById("mirage-engine-styles")) {
1573
+ const a = document.createElement("style");
1574
+ a.id = "mirage-engine-styles", a.textContent = `
1575
+ [${H.NAME}="${H.VALUES.HIDE}"] {
1568
1576
  opacity: 0 !important;
1569
1577
  }
1570
- `, document.head.appendChild(c);
1578
+ `, document.head.appendChild(a);
1571
1579
  }
1572
1580
  let i;
1573
1581
  if (t.mode === "duplicate" ? i = (o = (r = t.container) != null ? r : this.target.parentElement) != null ? o : void 0 : i = (n = this.target.parentElement) != null ? n : void 0, !i)
1574
1582
  throw new Error("[Mirage] Cannot find a container (parent or option).");
1575
- this.renderer = new it(
1583
+ this.renderer = new rt(
1576
1584
  this.target,
1577
1585
  t,
1578
1586
  i,
1579
1587
  this.registry
1580
- ), this.renderer.mount(), this.syncer = new ot(this.target, this.renderer, this.registry, t);
1588
+ ), this.renderer.mount(), this.syncer = new nt(this.target, this.renderer, this.registry, t);
1581
1589
  }
1582
1590
  start() {
1583
1591
  this.syncer.start();
@@ -1620,16 +1628,16 @@ class ct {
1620
1628
  r();
1621
1629
  }
1622
1630
  }
1623
- class lt {
1631
+ class ct {
1624
1632
  constructor(e = {}) {
1625
- d(this, "frontSelector");
1626
- d(this, "midLayerElement");
1627
- d(this, "items", []);
1628
- d(this, "isInitialized", !1);
1629
- d(this, "midLayer", null);
1630
- d(this, "frontLayer", null);
1631
- d(this, "tracker", null);
1632
- this.frontSelector = e.frontSelector || ".front", this.midLayerElement = e.midLayerElement || null, this.items = [], this.isInitialized = !1, this.tracker = new ke(document.body, e.trackerConfig || { resizeDebounce: !0 });
1633
+ u(this, "frontSelector");
1634
+ u(this, "midLayerElement");
1635
+ u(this, "items", []);
1636
+ u(this, "isInitialized", !1);
1637
+ u(this, "midLayer", null);
1638
+ u(this, "frontLayer", null);
1639
+ u(this, "tracker", null);
1640
+ this.frontSelector = e.frontSelector || ".front", this.midLayerElement = e.midLayerElement || null, this.items = [], this.isInitialized = !1, this.tracker = new Me(document.body, e.trackerConfig || { resizeDebounce: !0 });
1633
1641
  }
1634
1642
  init() {
1635
1643
  var e;
@@ -1691,16 +1699,16 @@ class lt {
1691
1699
  });
1692
1700
  }
1693
1701
  }
1694
- class dt {
1702
+ class ht {
1695
1703
  constructor(e, t) {
1696
- d(this, "_engine");
1697
- d(this, "_sandwich");
1704
+ u(this, "_engine");
1705
+ u(this, "_sandwich");
1698
1706
  if (!e)
1699
1707
  throw new Error("[Mirage] Target element is required.");
1700
- if (this._engine = new ct(e, t), t.sandwich !== !1) {
1708
+ if (this._engine = new at(e, t), t.sandwich !== !1) {
1701
1709
  const i = typeof t.sandwich == "object" ? t.sandwich : {};
1702
- this._sandwich = new lt({
1703
- frontSelector: i.frontSelector || `[${Se.NAME}='${Se.VALUES.FRONT}']`
1710
+ this._sandwich = new ct({
1711
+ frontSelector: i.frontSelector || `[${Ce.NAME}='${Ce.VALUES.FRONT}']`
1704
1712
  }), this._sandwich.useTracker(this._engine.getTracker());
1705
1713
  }
1706
1714
  }
@@ -1727,5 +1735,5 @@ class dt {
1727
1735
  }
1728
1736
  }
1729
1737
  export {
1730
- dt as Mirage
1738
+ ht as Mirage
1731
1739
  };