@mirage-engine/core 0.2.2 → 0.3.1

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,31 +1,198 @@
1
- var de = Object.defineProperty;
2
- var ue = (i, e, t) => e in i ? de(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var u = (i, e, t) => (ue(i, typeof e != "symbol" ? e + "" : e, t), t);
4
- var se = (i, e, t) => new Promise((s, r) => {
5
- var a = (c) => {
1
+ var Be = Object.defineProperty, Oe = Object.defineProperties;
2
+ var Fe = Object.getOwnPropertyDescriptors;
3
+ var Ce = Object.getOwnPropertySymbols;
4
+ var Xe = Object.prototype.hasOwnProperty, _e = Object.prototype.propertyIsEnumerable;
5
+ var ge = (s, e, t) => e in s ? Be(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, G = (s, e) => {
6
+ for (var t in e || (e = {}))
7
+ Xe.call(e, t) && ge(s, t, e[t]);
8
+ if (Ce)
9
+ for (var t of Ce(e))
10
+ _e.call(e, t) && ge(s, t, e[t]);
11
+ return s;
12
+ }, pe = (s, e) => Oe(s, Fe(e));
13
+ var u = (s, e, t) => (ge(s, typeof e != "symbol" ? e + "" : e, t), t);
14
+ var we = (s, e, t) => new Promise((i, r) => {
15
+ var l = (n) => {
6
16
  try {
7
- n(t.next(c));
8
- } catch (l) {
9
- r(l);
17
+ a(t.next(n));
18
+ } catch (c) {
19
+ r(c);
10
20
  }
11
- }, o = (c) => {
21
+ }, o = (n) => {
12
22
  try {
13
- n(t.throw(c));
14
- } catch (l) {
15
- r(l);
23
+ a(t.throw(n));
24
+ } catch (c) {
25
+ r(c);
16
26
  }
17
- }, n = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(a, o);
18
- n((t = t.apply(i, e)).next());
27
+ }, a = (n) => n.done ? i(n.value) : Promise.resolve(n.value).then(l, o);
28
+ a((t = t.apply(s, e)).next());
19
29
  });
20
- import * as m from "three";
21
- const N = 0, B = 1, _ = 2, fe = 4, V = 8, $ = 16, D = 1, X = 2, Ae = 0, ge = [
22
- "include-tree",
23
- "exclude-tree",
24
- "include-self",
25
- "exclude-self",
26
- "end"
27
- ];
28
- class ne {
30
+ import * as v from "three";
31
+ const Me = {
32
+ INCLUDE_TREE: "include-tree",
33
+ EXCLUDE_TREE: "exclude-tree",
34
+ INCLUDE_SELF: "include-self",
35
+ EXCLUDE_SELF: "exclude-self",
36
+ END: "end"
37
+ }, q = {
38
+ NAME: "data-mirage-dom",
39
+ KEY: "mirageDom",
40
+ VALUES: {
41
+ HIDE: "hide"
42
+ }
43
+ }, Te = {
44
+ TRAVELER: "traveler",
45
+ NATIVE: "native",
46
+ CAPTURE_1: "1",
47
+ CAPTURE_2: "2",
48
+ CAPTURE_3: "3",
49
+ CAPTURE_4: "4",
50
+ CAPTURE_5: "5"
51
+ }, O = {
52
+ NAME: "data-mirage-travel",
53
+ KEY: "mirageTravel",
54
+ VALUES: Te,
55
+ MAX_LAYERS: Object.keys(Te).length - 1
56
+ }, Y = {
57
+ NAME: "data-mirage-filter",
58
+ KEY: "mirageFilter",
59
+ VALUES: Me
60
+ }, z = {
61
+ NAME: "data-mirage-select",
62
+ KEY: "mirageSelect",
63
+ VALUES: Me
64
+ }, Ne = {
65
+ NAME: "data-mirage-shader",
66
+ KEY: "mirageShader"
67
+ }, lt = {
68
+ NAME: "data-mirage-sandwich",
69
+ KEY: "mirageSandwich",
70
+ VALUES: {
71
+ FRONT: "front"
72
+ }
73
+ }, he = 0, j = 1, ae = 2, Ye = 4, be = 8, ve = 16;
74
+ function ze(s) {
75
+ const e = s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
76
+ return e ? {
77
+ r: parseInt(e[1]) / 255,
78
+ g: parseInt(e[2]) / 255,
79
+ b: parseInt(e[3]) / 255
80
+ } : { r: 1, g: 1, b: 1 };
81
+ }
82
+ function Pe(s) {
83
+ const e = {};
84
+ if (s.opacity && (e.opacity = parseFloat(s.opacity)), s.backgroundColor && s.backgroundColor !== "rgba(0, 0, 0, 0)") {
85
+ const t = ze(s.backgroundColor);
86
+ e.backgroundColor = [t.r, t.g, t.b];
87
+ }
88
+ 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") {
89
+ const t = new DOMMatrix(s.transform);
90
+ e.x = t.m41, e.y = t.m42, e.z = t.m43;
91
+ }
92
+ return e;
93
+ }
94
+ class Ve {
95
+ constructor(e, t) {
96
+ u(this, "target");
97
+ u(this, "observer");
98
+ u(this, "pendingDeletions", /* @__PURE__ */ new Set());
99
+ u(this, "pendingStyles", /* @__PURE__ */ new Map());
100
+ u(this, "isDomDirty", !1);
101
+ u(this, "isRunning", !1);
102
+ u(this, "pendingMask", he);
103
+ u(this, "mutationTimer", null);
104
+ u(this, "cssTimer", null);
105
+ u(this, "resizeConfig");
106
+ u(this, "resizeTimer", null);
107
+ u(this, "isResizing", !1);
108
+ u(this, "lastScrollX", 0);
109
+ u(this, "lastScrollY", 0);
110
+ u(this, "scrollTimer", null);
111
+ u(this, "onBeforeRender", /* @__PURE__ */ new Set());
112
+ u(this, "onLayoutChange", /* @__PURE__ */ new Set());
113
+ u(this, "onStyleChange", /* @__PURE__ */ new Set());
114
+ u(this, "onScrollChange", /* @__PURE__ */ new Set());
115
+ u(this, "onRender", /* @__PURE__ */ new Set());
116
+ u(this, "onTransitionFinished", (e) => {
117
+ this.target.contains(e.target) && this.mutationTimer === null && (this.cssTimer && clearTimeout(this.cssTimer), this.pendingStyles.size == 0 && (this.pendingMask |= j | ae, this.cssTimer = window.setTimeout(() => {
118
+ this.isDomDirty = !0, this.cssTimer = null;
119
+ }, 50)));
120
+ });
121
+ u(this, "onWindowResize", () => {
122
+ if (!this.resizeConfig.enabled) {
123
+ this.isDomDirty = !0;
124
+ return;
125
+ }
126
+ this.isResizing || (this.isResizing = !0, this.resizeConfig.onStart && this.resizeConfig.onStart()), this.resizeTimer && clearTimeout(this.resizeTimer), this.resizeTimer = window.setTimeout(() => {
127
+ this.isDomDirty = !0, this.resizeConfig.onEnd && this.resizeConfig.onEnd(), this.isResizing = !1, this.resizeTimer = null;
128
+ }, this.resizeConfig.delay);
129
+ });
130
+ u(this, "renderLoop", () => {
131
+ if (!this.isRunning)
132
+ 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
+ const e = window.scrollX, t = window.scrollY;
135
+ (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
+ this.pendingMask |= j, this.isDomDirty = !0, this.scrollTimer = null;
137
+ }, 150)), this.pendingStyles.size > 0 && (this.onStyleChange.forEach((i) => i(this.pendingStyles)), this.pendingStyles.clear()), this.onRender.forEach((i) => i()), requestAnimationFrame(this.renderLoop);
138
+ });
139
+ var r, l;
140
+ this.target = e;
141
+ const i = (r = t.resizeDebounce) != null ? r : !0;
142
+ i === !1 ? this.resizeConfig = { enabled: !1, delay: 0 } : i === !0 ? this.resizeConfig = { enabled: !0, delay: 150 } : this.resizeConfig = {
143
+ enabled: !0,
144
+ delay: (l = i.delay) != null ? l : 150,
145
+ onStart: i.onStart,
146
+ onEnd: i.onEnd
147
+ }, this.observer = new MutationObserver((o) => {
148
+ let a = he;
149
+ for (const n of o)
150
+ if (n.type === "childList")
151
+ a |= be, n.removedNodes.length > 0 && n.removedNodes.forEach((c) => {
152
+ c instanceof HTMLElement && this.pendingDeletions.add(c);
153
+ });
154
+ else if (n.type === "attributes")
155
+ if (n.attributeName === "style") {
156
+ a |= j | ae;
157
+ const c = n.target, h = Pe(c.style);
158
+ this.pendingStyles.set(c, h);
159
+ } else
160
+ (n.attributeName === "class" || n.attributeName && n.attributeName.startsWith("data-")) && (a |= j | ae);
161
+ else
162
+ n.type === "characterData" && (a |= ve | j);
163
+ if (a !== he) {
164
+ if (this.pendingMask |= a, a & be) {
165
+ this.clearTimers(), this.isDomDirty = !0;
166
+ return;
167
+ }
168
+ this.mutationTimer && clearTimeout(this.mutationTimer), this.mutationTimer = window.setTimeout(() => {
169
+ this.mutationTimer = null, this.isDomDirty = !0;
170
+ }, 200);
171
+ }
172
+ });
173
+ }
174
+ start() {
175
+ this.isRunning || (this.isRunning = !0, this.observer.observe(this.target, {
176
+ childList: !0,
177
+ subtree: !0,
178
+ attributes: !0,
179
+ characterData: !0
180
+ }), 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());
181
+ }
182
+ stop() {
183
+ 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);
184
+ }
185
+ clearTimers() {
186
+ 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
+ }
189
+ const P = 1, Z = 2, ct = 0, A = {
190
+ BASE: 0,
191
+ SELECTED: 1,
192
+ getCaptureLayer: (s) => 31 - s,
193
+ HIDDEN: 31
194
+ }, Se = Object.values(Y.VALUES);
195
+ class De {
29
196
  /**
30
197
  * Calculates or retrieves the exact alphabetic baseline (in pixels) for the given font.
31
198
  * @param font CSS font shorthand string (e.g., "400 16px Inter")
@@ -40,18 +207,18 @@ class ne {
40
207
  static calculateBaselineFromDOM(e) {
41
208
  if (typeof document == "undefined")
42
209
  return 0;
43
- const t = document.createElement("div"), s = document.createElement("span"), r = document.createElement("img");
44
- 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", s.style.margin = "0", s.style.padding = "0", s.style.border = "none", s.style.lineHeight = "normal", r.width = 1, r.height = 1, r.style.verticalAlign = "baseline", s.appendChild(document.createTextNode("Hidden Text")), t.appendChild(s), t.appendChild(r), document.body.appendChild(t);
45
- const a = r.offsetTop - s.offsetTop;
46
- return document.body.removeChild(t), a;
210
+ const t = document.createElement("div"), i = document.createElement("span"), r = document.createElement("img");
211
+ 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", i.style.margin = "0", i.style.padding = "0", i.style.border = "none", i.style.lineHeight = "normal", r.width = 1, r.height = 1, r.style.verticalAlign = "baseline", i.appendChild(document.createTextNode("Hidden Text")), t.appendChild(i), t.appendChild(r), document.body.appendChild(t);
212
+ const l = r.offsetTop - i.offsetTop;
213
+ return document.body.removeChild(t), l;
47
214
  }
48
215
  }
49
- u(ne, "cache", /* @__PURE__ */ new Map());
50
- class pe extends m.MeshBasicMaterial {
51
- constructor(t, s, r, a, o = 2) {
216
+ u(De, "cache", /* @__PURE__ */ new Map());
217
+ class We extends v.MeshBasicMaterial {
218
+ constructor(t, i, r, l, o = 2) {
52
219
  super({
53
220
  transparent: !0,
54
- side: m.FrontSide,
221
+ side: v.FrontSide,
55
222
  color: 16777215
56
223
  });
57
224
  u(this, "canvas");
@@ -59,128 +226,128 @@ class pe extends m.MeshBasicMaterial {
59
226
  u(this, "qualityFactor");
60
227
  if (this.canvas = document.createElement("canvas"), this.ctx = this.canvas.getContext("2d"), !this.ctx)
61
228
  throw new Error("[Mirage] Failed to create canvas context");
62
- this.qualityFactor = o, this.map = new m.CanvasTexture(this.canvas), this.map.colorSpace = m.LinearSRGBColorSpace, this.map.minFilter = m.LinearFilter, this.map.magFilter = m.LinearFilter, this.updateText(t, s, r, a);
229
+ this.qualityFactor = o, this.map = new v.CanvasTexture(this.canvas), this.map.colorSpace = v.LinearSRGBColorSpace, this.map.minFilter = v.LinearFilter, this.map.magFilter = v.LinearFilter, this.updateText(t, i, r, l);
63
230
  }
64
- wrapText(t, s) {
231
+ wrapText(t, i) {
65
232
  const r = t.split(`
66
- `), a = [];
233
+ `), l = [];
67
234
  return r.forEach((o) => {
68
- const n = o.match(/[^\s\-]+\-?|\-|\s+/g) || [];
69
- if (n.length === 0) {
70
- a.push("");
235
+ const a = o.match(/[^\s\-]+\-?|\-|\s+/g) || [];
236
+ if (a.length === 0) {
237
+ l.push("");
71
238
  return;
72
239
  }
73
- let c = n[0];
74
- for (let l = 1; l < n.length; l++) {
75
- const d = n[l];
76
- this.ctx.measureText(c + d).width <= s + 2 ? c += d : (c && a.push(c), c = d.trimStart());
240
+ let n = a[0];
241
+ for (let c = 1; c < a.length; c++) {
242
+ const h = a[c];
243
+ this.ctx.measureText(n + h).width <= i + 2 ? n += h : (n && l.push(n), n = h.trimStart());
77
244
  }
78
- c && a.push(c);
79
- }), a;
245
+ n && l.push(n);
246
+ }), l;
80
247
  }
81
- updateText(t, s, r, a, o) {
248
+ updateText(t, i, r, l, o) {
82
249
  o !== void 0 && (this.qualityFactor = o);
83
- const c = (window.devicePixelRatio || 1) * this.qualityFactor, l = r * c, d = a * c;
84
- 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 = s.font, this.ctx.fillStyle = s.color, this.ctx.textBaseline = "alphabetic", this.ctx.globalAlpha = 1;
85
- const f = this.wrapText(t, r), h = s.lineHeight, p = ne.getBaseline(s.font);
86
- f.forEach((g, y) => {
87
- const x = y * h + p;
88
- let T = 0;
89
- s.textAlign === "center" ? T = r / 2 : s.textAlign === "right" && (T = r), this.ctx.textAlign = s.textAlign, this.ctx.fillText(g, T, x);
250
+ const n = (window.devicePixelRatio || 1) * this.qualityFactor, c = r * n, h = l * n;
251
+ this.canvas.width !== c || this.canvas.height !== h ? (this.canvas.width = c, this.canvas.height = h) : this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height), this.ctx.setTransform(n, 0, 0, n, 0, 0), this.ctx.font = i.font, this.ctx.fillStyle = i.color, this.ctx.textBaseline = "alphabetic", this.ctx.globalAlpha = 1;
252
+ const f = this.wrapText(t, r), b = i.lineHeight, p = De.getBaseline(i.font);
253
+ f.forEach((d, g) => {
254
+ const w = g * b + p;
255
+ let L = 0;
256
+ i.textAlign === "center" ? L = r / 2 : i.textAlign === "right" && (L = r), this.ctx.textAlign = i.textAlign, this.ctx.fillText(d, L, w);
90
257
  }), this.map && (this.map.needsUpdate = !0);
91
258
  }
92
259
  dispose() {
93
260
  this.map && this.map.dispose(), super.dispose();
94
261
  }
95
262
  }
96
- function F(i) {
97
- return typeof i == "number" ? i : parseFloat(i) || 0;
263
+ function ee(s) {
264
+ return typeof s == "number" ? s : parseFloat(s) || 0;
98
265
  }
99
- function I(i) {
100
- if (!i || i === "transparent")
101
- return { color: new m.Color(16777215), alpha: 0 };
102
- const e = i.match(
266
+ function le(s) {
267
+ if (!s || s === "transparent")
268
+ return { color: new v.Color(16777215), alpha: 0 };
269
+ const e = s.match(
103
270
  /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/
104
271
  );
105
272
  if (e) {
106
- const t = parseInt(e[1], 10), s = parseInt(e[2], 10), r = parseInt(e[3], 10), a = e[4] !== void 0 ? parseFloat(e[4]) : 1;
107
- return { color: new m.Color(`rgb(${t}, ${s}, ${r})`), alpha: a };
273
+ const t = parseInt(e[1], 10), i = parseInt(e[2], 10), r = parseInt(e[3], 10), l = e[4] !== void 0 ? parseFloat(e[4]) : 1;
274
+ return { color: new v.Color(`rgb(${t}, ${i}, ${r})`), alpha: l };
108
275
  }
109
- return { color: new m.Color(i), alpha: 1 };
276
+ return { color: new v.Color(s), alpha: 1 };
110
277
  }
111
- function me(i) {
278
+ function He(s) {
112
279
  const e = [];
113
- let t = "", s = 0;
114
- for (let r = 0; r < i.length; r++) {
115
- const a = i[r];
116
- if (a === "(")
117
- s++;
118
- else if (a === ")")
119
- s--;
120
- else if (a === "," && s === 0) {
280
+ let t = "", i = 0;
281
+ for (let r = 0; r < s.length; r++) {
282
+ const l = s[r];
283
+ if (l === "(")
284
+ i++;
285
+ else if (l === ")")
286
+ i--;
287
+ else if (l === "," && i === 0) {
121
288
  e.push(t.trim()), t = "";
122
289
  continue;
123
290
  }
124
- t += a;
291
+ t += l;
125
292
  }
126
293
  return t && e.push(t.trim()), e;
127
294
  }
128
- function be(i) {
129
- if (!i || typeof i != "string" || !i.includes("linear-gradient"))
295
+ function Ge(s) {
296
+ if (!s || typeof s != "string" || !s.includes("linear-gradient"))
130
297
  return null;
131
- const e = i.match(/linear-gradient\((.*)\)/);
298
+ const e = s.match(/linear-gradient\((.*)\)/);
132
299
  if (!e)
133
300
  return null;
134
- const t = e[1], s = me(t);
135
- let r = Math.PI, a = 0;
136
- const o = s[0].trim();
301
+ const t = e[1], i = He(t);
302
+ let r = Math.PI, l = 0;
303
+ const o = i[0].trim();
137
304
  if (o.startsWith("to "))
138
- o === "to top" ? r = 0 : o === "to right" ? r = Math.PI / 2 : o === "to bottom" ? r = Math.PI : o === "to left" ? r = Math.PI * 1.5 : o === "to top right" || o === "to right top" ? r = Math.PI / 4 : o === "to bottom right" || o === "to right bottom" ? r = Math.PI * 0.75 : o === "to bottom left" || o === "to left bottom" ? r = Math.PI * 1.25 : (o === "to top left" || o === "to left top") && (r = Math.PI * 1.75), a = 1;
305
+ o === "to top" ? r = 0 : o === "to right" ? r = Math.PI / 2 : o === "to bottom" ? r = Math.PI : o === "to left" ? r = Math.PI * 1.5 : o === "to top right" || o === "to right top" ? r = Math.PI / 4 : o === "to bottom right" || o === "to right bottom" ? r = Math.PI * 0.75 : o === "to bottom left" || o === "to left bottom" ? r = Math.PI * 1.25 : (o === "to top left" || o === "to left top") && (r = Math.PI * 1.75), l = 1;
139
306
  else if (o.endsWith("deg") || o.endsWith("rad") || o.endsWith("turn")) {
140
- const c = parseFloat(o);
141
- o.endsWith("deg") ? r = c * (Math.PI / 180) : o.endsWith("rad") ? r = c : o.endsWith("turn") && (r = c * Math.PI * 2), a = 1;
142
- }
143
- const n = [];
144
- for (let c = a; c < s.length && !(n.length >= 8); c++) {
145
- const l = s[c].trim(), d = l.lastIndexOf(" ");
146
- let f = l, h = null;
147
- if (d !== -1 && !l.endsWith(")")) {
148
- const g = l.substring(d + 1);
149
- (g.endsWith("%") || g.endsWith("px") || !isNaN(parseFloat(g))) && (f = l.substring(0, d).trim(), h = g);
307
+ const n = parseFloat(o);
308
+ o.endsWith("deg") ? r = n * (Math.PI / 180) : o.endsWith("rad") ? r = n : o.endsWith("turn") && (r = n * Math.PI * 2), l = 1;
309
+ }
310
+ const a = [];
311
+ for (let n = l; n < i.length && !(a.length >= 8); n++) {
312
+ const c = i[n].trim(), h = c.lastIndexOf(" ");
313
+ let f = c, b = null;
314
+ if (h !== -1 && !c.endsWith(")")) {
315
+ const d = c.substring(h + 1);
316
+ (d.endsWith("%") || d.endsWith("px") || !isNaN(parseFloat(d))) && (f = c.substring(0, h).trim(), b = d);
150
317
  }
151
- const p = I(f);
152
- n.push({
318
+ const p = le(f);
319
+ a.push({
153
320
  color: p.color,
154
321
  alpha: p.alpha,
155
- rawStop: h,
322
+ rawStop: b,
156
323
  stop: 0
157
324
  });
158
325
  }
159
- if (n.length > 0) {
160
- for (let l = 0; l < n.length; l++)
161
- n[l].rawStop !== null && (n[l].stop = parseFloat(n[l].rawStop) / 100);
162
- n[0].rawStop === null && (n[0].stop = 0), n.length > 1 && n[n.length - 1].rawStop === null && (n[n.length - 1].stop = 1);
163
- let c = 0;
164
- for (let l = 1; l < n.length; l++)
165
- if (n[l].rawStop !== null || l === n.length - 1) {
166
- const d = l - c;
167
- if (d > 1) {
168
- const f = n[c].stop, p = (n[l].stop - f) / d;
169
- for (let g = 1; g < d; g++)
170
- n[c + g].stop = f + p * g;
326
+ if (a.length > 0) {
327
+ for (let c = 0; c < a.length; c++)
328
+ a[c].rawStop !== null && (a[c].stop = parseFloat(a[c].rawStop) / 100);
329
+ a[0].rawStop === null && (a[0].stop = 0), a.length > 1 && a[a.length - 1].rawStop === null && (a[a.length - 1].stop = 1);
330
+ let n = 0;
331
+ for (let c = 1; c < a.length; c++)
332
+ if (a[c].rawStop !== null || c === a.length - 1) {
333
+ const h = c - n;
334
+ if (h > 1) {
335
+ const f = a[n].stop, p = (a[c].stop - f) / h;
336
+ for (let d = 1; d < h; d++)
337
+ a[n + d].stop = f + p * d;
171
338
  }
172
- c = l;
339
+ n = c;
173
340
  }
174
341
  }
175
- return { angle: r, stops: n };
342
+ return { angle: r, stops: a };
176
343
  }
177
- const xe = `varying vec2 vUv;
344
+ const qe = `varying vec2 vUv;
178
345
  varying vec4 vScreenPos;
179
346
  void main() {
180
347
  vUv = uv;
181
348
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
182
349
  vScreenPos = gl_Position;
183
- }`, ve = `varying vec2 vUv;
350
+ }`, $e = `varying vec2 vUv;
184
351
  uniform vec2 uSize;
185
352
  uniform vec4 uBorderRadius;
186
353
  uniform float uBorderWidth;
@@ -309,73 +476,85 @@ void main() {
309
476
 
310
477
  // #include <colorspace_fragment>
311
478
  }
312
- `, ye = `uniform sampler2D uTexture;
479
+ `, je = `uniform sampler2D uTexture;
313
480
  varying vec4 vScreenPos;
314
481
  uniform vec2 uTextureRepeat;
315
- uniform vec2 uTextureOffset;`, Ce = `vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
482
+ uniform vec2 uTextureOffset;`, Ke = `vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
316
483
  vec2 resultUv = screenUv;
317
484
 
318
- `, we = `vec4 texColor = texture2D(uTexture, resultUv);
319
- baseColor = blendSrcOver(baseColor, texColor);`, oe = {
320
- vertexShader: xe,
321
- fragmentShader: ve
322
- }, H = {
323
- declChunk: ye,
324
- uvChunk: Ce,
325
- baseColorChunk: we
485
+ `, Je = `vec4 texColor = texture2D(uTexture, resultUv);
486
+ baseColor = blendSrcOver(baseColor, texColor);`, Re = {
487
+ vertexShader: qe,
488
+ fragmentShader: $e
489
+ }, me = {
490
+ declChunk: je,
491
+ uvChunk: Ke,
492
+ baseColorChunk: Je
326
493
  };
327
- function Te(i, e, t, s = null, r) {
328
- var x;
329
- const a = s !== null || !!i.imageSrc, o = a ? H.declChunk : "", n = i.isTraveler ? H.uvChunk : `vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
330
- `, c = a ? n + ((r == null ? void 0 : r.uvModifier) || "") : "", l = a ? H.baseColorChunk : "", d = (r == null ? void 0 : r.colorModifier) || "", f = oe.fragmentShader.replace("#INJECT_DECLARATIONS", o).replace("#INJECT_UV_MODIFIER", c).replace("#INJECT_BASE_COLOR", l).replace("#INJECT_COLOR_MODIFIER", d), h = I(i.backgroundColor), p = I(i.borderColor), g = {
331
- uSize: { value: new m.Vector2(e, t) },
494
+ function Qe(s, e, t, i = null, r) {
495
+ var R;
496
+ const l = i !== null || !!s.imageSrc;
497
+ let o = "";
498
+ const a = {};
499
+ if (r != null && r.uniforms)
500
+ for (const [E, x] of Object.entries(r.uniforms))
501
+ typeof x == "number" ? (o += `uniform float ${E};
502
+ `, a[E] = { value: x }) : Array.isArray(x) ? x.length === 2 ? (o += `uniform vec2 ${E};
503
+ `, a[E] = { value: new v.Vector2(...x) }) : x.length === 3 ? (o += `uniform vec3 ${E};
504
+ `, a[E] = { value: new v.Vector3(...x) }) : x.length === 4 && (o += `uniform vec4 ${E};
505
+ `, a[E] = { value: new v.Vector4(...x) }) : (o += `uniform float ${E};
506
+ `, a[E] = { value: x });
507
+ const n = (l ? me.declChunk : "") + `
508
+ ` + o, c = s.isTraveler ? me.uvChunk : `vec2 resultUv = vUv * uTextureRepeat + uTextureOffset;
509
+ `, h = l ? c + ((r == null ? void 0 : r.uvModifier) || "") : "", f = l ? me.baseColorChunk : "", b = (r == null ? void 0 : r.colorModifier) || "", p = Re.fragmentShader.replace("#INJECT_DECLARATIONS", n).replace("#INJECT_UV_MODIFIER", h).replace("#INJECT_BASE_COLOR", f).replace("#INJECT_COLOR_MODIFIER", b), d = le(s.backgroundColor), g = le(s.borderColor), w = {
510
+ uSize: { value: new v.Vector2(e, t) },
332
511
  uBgColor: {
333
- value: new m.Vector4(
334
- h.color.r,
335
- h.color.g,
336
- h.color.b,
337
- h.alpha
512
+ value: new v.Vector4(
513
+ d.color.r,
514
+ d.color.g,
515
+ d.color.b,
516
+ d.alpha
338
517
  )
339
518
  },
340
519
  uBorderColor: {
341
- value: new m.Vector4(
342
- p.color.r,
343
- p.color.g,
344
- p.color.b,
345
- p.alpha
520
+ value: new v.Vector4(
521
+ g.color.r,
522
+ g.color.g,
523
+ g.color.b,
524
+ g.alpha
346
525
  )
347
526
  },
348
- uBorderRadius: { value: new m.Vector4(0, 0, 0, 0) },
349
- uBorderWidth: { value: F(i.borderWidth) },
350
- uOpacity: { value: (x = i.opacity) != null ? x : 1 },
527
+ uBorderRadius: { value: new v.Vector4(0, 0, 0, 0) },
528
+ uBorderWidth: { value: ee(s.borderWidth) },
529
+ uOpacity: { value: (R = s.opacity) != null ? R : 1 },
351
530
  uTexture: { value: null },
352
- uTextureRepeat: { value: new m.Vector2(1, 1) },
353
- uTextureOffset: { value: new m.Vector2(0, 0) },
531
+ uTextureRepeat: { value: new v.Vector2(1, 1) },
532
+ uTextureOffset: { value: new v.Vector2(0, 0) },
354
533
  uGradientCount: { value: 0 },
355
534
  uGradientAngle: { value: 0 },
356
535
  uGradientColors: {
357
- value: Array.from({ length: 8 }, () => new m.Vector4(0, 0, 0, 0))
536
+ value: Array.from({ length: 8 }, () => new v.Vector4(0, 0, 0, 0))
358
537
  },
359
538
  uGradientStops: { value: new Float32Array(8) }
360
539
  };
361
- ae(g.uBorderRadius.value, i.borderRadius), a && (g.uTexture.value = s);
362
- const y = new m.ShaderMaterial({
363
- uniforms: g,
364
- vertexShader: oe.vertexShader,
365
- fragmentShader: f,
540
+ Ae(w.uBorderRadius.value, s.borderRadius), l && (w.uTexture.value = i);
541
+ const L = new v.ShaderMaterial({
542
+ uniforms: G(G({}, w), a),
543
+ vertexShader: Re.vertexShader,
544
+ fragmentShader: p,
366
545
  transparent: !0,
367
- side: m.FrontSide
546
+ side: v.FrontSide
368
547
  // for better performance
369
548
  });
370
- return i.backgroundImage && J(y, { backgroundImage: i.backgroundImage }), y;
549
+ return s.backgroundImage && ye(L, { backgroundImage: s.backgroundImage }), L;
371
550
  }
372
- function Se(i, e, t, s, r) {
373
- const a = F(e.borderWidth);
374
- J(i, {
551
+ function Ze(s, e, t, i, r) {
552
+ const l = ee(e.borderWidth);
553
+ ye(s, {
375
554
  width: t,
376
- height: s,
555
+ height: i,
377
556
  borderRadius: e.borderRadius,
378
- borderWidth: a,
557
+ borderWidth: l,
379
558
  backgroundColor: e.backgroundColor,
380
559
  borderColor: e.borderColor,
381
560
  opacity: e.opacity,
@@ -383,28 +562,28 @@ function Se(i, e, t, s, r) {
383
562
  backgroundImage: e.backgroundImage
384
563
  });
385
564
  }
386
- function J(i, e) {
387
- var s, r, a;
388
- if (e.width !== void 0 && e.height !== void 0 && i.uniforms.uSize.value.set(e.width, e.height), e.borderRadius !== void 0 && ae(i.uniforms.uBorderRadius.value, e.borderRadius), e.borderWidth !== void 0 && (i.uniforms.uBorderWidth.value = e.borderWidth), e.backgroundColor !== void 0)
565
+ function ye(s, e) {
566
+ var i, r, l;
567
+ if (e.width !== void 0 && e.height !== void 0 && s.uniforms.uSize.value.set(e.width, e.height), e.borderRadius !== void 0 && Ae(s.uniforms.uBorderRadius.value, e.borderRadius), e.borderWidth !== void 0 && (s.uniforms.uBorderWidth.value = e.borderWidth), e.backgroundColor !== void 0)
389
568
  if (Array.isArray(e.backgroundColor)) {
390
- const o = i.uniforms.uBgColor.value.w;
391
- i.uniforms.uBgColor.value.set(
569
+ const o = s.uniforms.uBgColor.value.w;
570
+ s.uniforms.uBgColor.value.set(
392
571
  e.backgroundColor[0],
393
572
  e.backgroundColor[1],
394
573
  e.backgroundColor[2],
395
574
  o
396
575
  );
397
576
  } else if (typeof e.backgroundColor == "string") {
398
- const o = I(e.backgroundColor);
399
- i.uniforms.uBgColor.value.set(
577
+ const o = le(e.backgroundColor);
578
+ s.uniforms.uBgColor.value.set(
400
579
  o.color.r,
401
580
  o.color.g,
402
581
  o.color.b,
403
582
  o.alpha
404
583
  );
405
584
  } else {
406
- const o = i.uniforms.uBgColor.value.w;
407
- i.uniforms.uBgColor.value.set(
585
+ const o = s.uniforms.uBgColor.value.w;
586
+ s.uniforms.uBgColor.value.set(
408
587
  e.backgroundColor.r,
409
588
  e.backgroundColor.g,
410
589
  e.backgroundColor.b,
@@ -413,118 +592,120 @@ function J(i, e) {
413
592
  }
414
593
  if (e.borderColor !== void 0)
415
594
  if (Array.isArray(e.borderColor)) {
416
- const o = i.uniforms.uBorderColor.value.w;
417
- i.uniforms.uBorderColor.value.set(
595
+ const o = s.uniforms.uBorderColor.value.w;
596
+ s.uniforms.uBorderColor.value.set(
418
597
  e.borderColor[0],
419
598
  e.borderColor[1],
420
599
  e.borderColor[2],
421
600
  o
422
601
  );
423
602
  } else if (typeof e.borderColor == "string") {
424
- const o = I(e.borderColor);
425
- i.uniforms.uBorderColor.value.set(
603
+ const o = le(e.borderColor);
604
+ s.uniforms.uBorderColor.value.set(
426
605
  o.color.r,
427
606
  o.color.g,
428
607
  o.color.b,
429
608
  o.alpha
430
609
  );
431
610
  } else {
432
- const o = i.uniforms.uBorderColor.value.w;
433
- i.uniforms.uBorderColor.value.set(
611
+ const o = s.uniforms.uBorderColor.value.w;
612
+ s.uniforms.uBorderColor.value.set(
434
613
  e.borderColor.r,
435
614
  e.borderColor.g,
436
615
  e.borderColor.b,
437
616
  o
438
617
  );
439
618
  }
440
- e.opacity !== void 0 && (i.uniforms.uOpacity.value = e.opacity), e.bgOpacity !== void 0 && (i.uniforms.uBgColor.value.w = e.bgOpacity), e.borderOpacity !== void 0 && (i.uniforms.uBorderColor.value.w = e.borderOpacity), i.uniforms.uTexture && e.texture !== void 0 && (i.uniforms.uTexture.value = e.texture);
441
- const t = e.texture !== void 0 ? e.texture : (s = i.uniforms.uTexture) == null ? void 0 : s.value;
619
+ 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
+ const t = e.texture !== void 0 ? e.texture : (i = s.uniforms.uTexture) == null ? void 0 : i.value;
442
621
  if (t && (t.image instanceof ImageBitmap || t.image instanceof HTMLImageElement || t.image instanceof HTMLCanvasElement)) {
443
- const o = t.image.width, n = t.image.height, c = (r = e.width) != null ? r : i.uniforms.uSize.value.x, l = (a = e.height) != null ? a : i.uniforms.uSize.value.y;
444
- if (o && n && c && l) {
445
- const d = o / n, f = c / l;
446
- if (d > f) {
447
- const h = f / d;
448
- i.uniforms.uTextureRepeat.value.set(h, 1), i.uniforms.uTextureOffset.value.set((1 - h) / 2, 0);
622
+ const o = t.image.width, a = t.image.height, n = (r = e.width) != null ? r : s.uniforms.uSize.value.x, c = (l = e.height) != null ? l : s.uniforms.uSize.value.y;
623
+ if (o && a && n && c) {
624
+ const h = o / a, f = n / c;
625
+ if (h > f) {
626
+ const b = f / h;
627
+ s.uniforms.uTextureRepeat.value.set(b, 1), s.uniforms.uTextureOffset.value.set((1 - b) / 2, 0);
449
628
  } else {
450
- const h = d / f;
451
- i.uniforms.uTextureRepeat.value.set(1, h), i.uniforms.uTextureOffset.value.set(0, (1 - h) / 2);
629
+ const b = h / f;
630
+ s.uniforms.uTextureRepeat.value.set(1, b), s.uniforms.uTextureOffset.value.set(0, (1 - b) / 2);
452
631
  }
453
632
  }
454
633
  } else
455
- i.uniforms.uTextureRepeat && (i.uniforms.uTextureRepeat.value.set(1, 1), i.uniforms.uTextureOffset.value.set(0, 0));
634
+ s.uniforms.uTextureRepeat && (s.uniforms.uTextureRepeat.value.set(1, 1), s.uniforms.uTextureOffset.value.set(0, 0));
456
635
  if (e.backgroundImage !== void 0) {
457
- const o = be(e.backgroundImage);
636
+ const o = Ge(e.backgroundImage);
458
637
  if (o) {
459
- i.uniforms.uGradientCount.value = o.stops.length, i.uniforms.uGradientAngle.value = o.angle;
460
- for (let n = 0; n < 8; n++)
461
- if (n < o.stops.length) {
462
- const c = o.stops[n];
463
- i.uniforms.uGradientColors.value[n].set(
464
- c.color.r,
465
- c.color.g,
466
- c.color.b,
467
- c.alpha
468
- ), console.log(c.color.r, c.color.g, c.color.b), i.uniforms.uGradientStops.value[n] = c.stop;
638
+ s.uniforms.uGradientCount.value = o.stops.length, s.uniforms.uGradientAngle.value = o.angle;
639
+ for (let a = 0; a < 8; a++)
640
+ if (a < o.stops.length) {
641
+ const n = o.stops[a];
642
+ s.uniforms.uGradientColors.value[a].set(
643
+ n.color.r,
644
+ n.color.g,
645
+ n.color.b,
646
+ n.alpha
647
+ ), s.uniforms.uGradientStops.value[a] = n.stop;
469
648
  } else
470
- i.uniforms.uGradientColors.value[n].set(0, 0, 0, 0), i.uniforms.uGradientStops.value[n] = 1;
649
+ s.uniforms.uGradientColors.value[a].set(0, 0, 0, 0), s.uniforms.uGradientStops.value[a] = 1;
471
650
  } else
472
- i.uniforms.uGradientCount.value = 0;
651
+ s.uniforms.uGradientCount.value = 0;
473
652
  }
653
+ for (const o of Object.keys(e))
654
+ o !== "width" && o !== "height" && o !== "borderRadius" && o !== "borderWidth" && o !== "backgroundColor" && o !== "borderColor" && o !== "opacity" && o !== "bgOpacity" && o !== "borderOpacity" && o !== "texture" && o !== "backgroundImage" && s.uniforms[o] !== void 0 && (s.uniforms[o].value !== void 0 && s.uniforms[o].value !== null && typeof s.uniforms[o].value.set == "function" ? Array.isArray(e[o]) ? s.uniforms[o].value.set(...e[o]) : e[o] !== void 0 && (e[o].copy ? s.uniforms[o].value.copy(e[o]) : s.uniforms[o].value = e[o]) : s.uniforms[o].value = e[o]);
474
655
  }
475
- function ae(i, e) {
476
- var n, c, l, d;
656
+ function Ae(s, e) {
657
+ var a, n, c, h;
477
658
  if (e == null) {
478
- i.set(0, 0, 0, 0);
659
+ s.set(0, 0, 0, 0);
479
660
  return;
480
661
  }
481
662
  if (typeof e == "number") {
482
- i.set(e, e, e, e);
663
+ s.set(e, e, e, e);
483
664
  return;
484
665
  }
485
666
  if (Array.isArray(e)) {
486
- i.set(e[0], e[1], e[2], e[3]);
667
+ s.set(e[0], e[1], e[2], e[3]);
487
668
  return;
488
669
  }
489
- const t = e.split("/")[0].trim().split(/\s+/), s = F(t[0]), r = F((n = t[1]) != null ? n : t[0]), a = F((c = t[2]) != null ? c : t[0]), o = F((d = (l = t[3]) != null ? l : t[1]) != null ? d : t[0]);
490
- i.set(s, r, a, o);
670
+ const t = e.split("/")[0].trim().split(/\s+/), i = ee(t[0]), r = ee((a = t[1]) != null ? a : t[0]), l = ee((n = t[2]) != null ? n : t[0]), o = ee((h = (c = t[3]) != null ? c : t[1]) != null ? h : t[0]);
671
+ s.set(i, r, l, o);
491
672
  }
492
- const z = {
493
- create(i, e, t, s, r, a = 2, o = null, n) {
494
- return i === "BOX" ? Te(
673
+ const H = {
674
+ create(s, e, t, i, r, l = 2, o = null, a) {
675
+ return s === "BOX" ? Qe(
495
676
  e,
496
- s,
677
+ i,
497
678
  r,
498
679
  o,
499
- n
500
- ) : i === "TEXT" ? new pe(
680
+ a
681
+ ) : s === "TEXT" ? new We(
501
682
  t || "",
502
683
  e,
503
- s,
684
+ i,
504
685
  r,
505
- a
506
- ) : new m.MeshBasicMaterial({ visible: !1 });
686
+ l
687
+ ) : new v.MeshBasicMaterial({ visible: !1 });
507
688
  },
508
- update(i, e, t, s, r, a, o = 2, n) {
509
- e === "BOX" ? Se(
510
- i,
689
+ update(s, e, t, i, r, l, o = 2, a) {
690
+ e === "BOX" ? Ze(
691
+ s,
511
692
  t,
512
693
  r,
513
- a,
514
- n
515
- ) : e === "TEXT" && i.updateText(
516
- s || "",
694
+ l,
695
+ a
696
+ ) : e === "TEXT" && s.updateText(
697
+ i || "",
517
698
  t,
518
699
  r,
519
- a,
700
+ l,
520
701
  o
521
702
  );
522
703
  },
523
- forceUpdateUniforms(i, e) {
524
- J(i, e);
704
+ forceUpdateUniforms(s, e) {
705
+ ye(s, e);
525
706
  }
526
707
  };
527
- class Re {
708
+ class et {
528
709
  constructor(e) {
529
710
  u(this, "observer");
530
711
  u(this, "textures", /* @__PURE__ */ new WeakMap());
@@ -533,9 +714,9 @@ class Re {
533
714
  u(this, "onUpdate");
534
715
  this.onUpdate = e, this.observer = new IntersectionObserver(
535
716
  (t) => {
536
- for (const s of t) {
537
- const r = s.target;
538
- s.isIntersecting ? this.loadTexture(r) : this.disposeTexture(r);
717
+ for (const i of t) {
718
+ const r = i.target;
719
+ i.isIntersecting ? this.loadTexture(r) : this.disposeTexture(r);
539
720
  }
540
721
  },
541
722
  { rootMargin: "300px" }
@@ -550,22 +731,31 @@ class Re {
550
731
  e.nodeType === Node.ELEMENT_NODE && this.observer.unobserve(e), this.disposeTexture(e), this.elementUrls.delete(e), this.loadStatus.delete(e);
551
732
  }
552
733
  loadTexture(e) {
553
- return se(this, null, function* () {
734
+ return we(this, null, function* () {
554
735
  if (this.loadStatus.get(e) || this.textures.has(e))
555
736
  return;
556
737
  const t = this.elementUrls.get(e);
557
738
  if (t) {
558
739
  this.loadStatus.set(e, !0);
559
740
  try {
560
- const r = yield (yield fetch(t)).blob(), a = yield createImageBitmap(r, { imageOrientation: "flipY" });
741
+ let i;
742
+ if (t.startsWith("data:image/svg+xml"))
743
+ i = yield new Promise((l, o) => {
744
+ const a = new Image();
745
+ a.onload = () => l(a), a.onerror = o, a.src = t;
746
+ });
747
+ else {
748
+ const o = yield (yield fetch(t)).blob();
749
+ i = yield createImageBitmap(o, { imageOrientation: "flipY" });
750
+ }
561
751
  if (this.elementUrls.get(e) !== t) {
562
- a.close();
752
+ "close" in i && i.close();
563
753
  return;
564
754
  }
565
- const o = new m.CanvasTexture(a);
566
- o.needsUpdate = !0, this.textures.set(e, o), this.onUpdate(e, o);
567
- } catch (s) {
568
- console.warn("[MirageEngine] Failed to load texture:", t, s);
755
+ const r = new v.Texture(i);
756
+ i instanceof HTMLImageElement || (r.flipY = !1), r.colorSpace = v.LinearSRGBColorSpace, r.needsUpdate = !0, this.textures.set(e, r), this.onUpdate(e, r);
757
+ } catch (i) {
758
+ console.warn("[MirageEngine] Failed to load texture:", t, i);
569
759
  } finally {
570
760
  this.elementUrls.has(e) && this.loadStatus.set(e, !1);
571
761
  }
@@ -583,59 +773,68 @@ class Re {
583
773
  this.observer.disconnect();
584
774
  }
585
775
  }
586
- class Me {
587
- constructor(e, t, s, r) {
776
+ class tt {
777
+ constructor(e, t, i, r) {
588
778
  u(this, "canvas");
589
779
  u(this, "scene");
590
780
  u(this, "camera");
591
781
  u(this, "renderer");
592
- u(this, "renderTarget", null);
782
+ u(this, "renderTargets", []);
593
783
  u(this, "renderOrder", 0);
594
784
  u(this, "qualityFactor", 2);
595
785
  u(this, "mode", "overlay");
596
786
  u(this, "clipArea", 1);
787
+ u(this, "targetLayer", "base");
597
788
  u(this, "target");
598
789
  u(this, "mountContainer");
599
790
  u(this, "registry");
600
791
  u(this, "targetRect");
601
- u(this, "travelers", /* @__PURE__ */ new Set());
792
+ u(this, "travelersByLayer", Array.from(
793
+ { length: O.MAX_LAYERS },
794
+ () => /* @__PURE__ */ new Set()
795
+ ));
602
796
  u(this, "textureManager");
603
797
  // private meshMap: Map<HTMLElement, THREE.Mesh> = new Map();
604
798
  u(this, "fixedMeshes", /* @__PURE__ */ new Set());
605
- var n, c, l;
606
- this.target = e, this.mountContainer = s, this.registry = r, this.textureManager = new Re((d, f) => {
607
- const h = this.registry.get(d);
608
- h && h.material instanceof m.ShaderMaterial && z.forceUpdateUniforms(h.material, { texture: f });
609
- }), this.mode = (n = t.mode) != null ? n : "overlay", this.clipArea = (c = t.travelerClipArea) != null ? c : 1, this.canvas = document.createElement("canvas"), this.scene = new m.Scene(), this.targetRect = this.target.getBoundingClientRect();
610
- const a = this.targetRect.width, o = this.targetRect.height;
611
- this.camera = new m.OrthographicCamera(
612
- a / -2,
613
- a / 2,
799
+ var a, n, c, h;
800
+ this.target = e, this.mountContainer = i, this.registry = r, this.textureManager = new et((f, b) => {
801
+ const p = this.registry.get(f);
802
+ p && p.material instanceof v.ShaderMaterial && H.forceUpdateUniforms(p.material, { texture: b });
803
+ }), this.mode = (a = t.mode) != null ? a : "overlay", this.clipArea = (n = t.travelerClipArea) != null ? n : 1, this.targetLayer = (c = t.layer) != null ? c : "base", this.canvas = document.createElement("canvas"), this.scene = new v.Scene(), this.targetRect = this.target.getBoundingClientRect();
804
+ const l = this.targetRect.width, o = this.targetRect.height;
805
+ this.camera = new v.OrthographicCamera(
806
+ l / -2,
807
+ l / 2,
614
808
  o / 2,
615
809
  o / -2,
616
810
  1,
617
811
  1e3
618
- ), this.camera.position.z = 100, this.camera.layers.set(0), this.renderer = new m.WebGLRenderer({
812
+ ), this.camera.position.z = 100, this.camera.layers.set(this.getSceneLayer()), this.renderer = new v.WebGLRenderer({
619
813
  canvas: this.canvas,
620
814
  alpha: !0,
621
815
  antialias: !0
622
816
  // [new]
623
817
  // premultipliedAlpha: true
624
- }), m.ColorManagement.enabled = !1, this.renderer.outputColorSpace = m.LinearSRGBColorSpace, this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setSize(a, o), this.applyTextQuality((l = t.quality) != null ? l : "medium");
818
+ }), v.ColorManagement.enabled = !1, this.renderer.outputColorSpace = v.LinearSRGBColorSpace, this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setSize(l, o), this.applyTextQuality((h = t.quality) != null ? h : "medium");
819
+ }
820
+ getSceneLayer() {
821
+ return typeof this.targetLayer == "number" ? this.targetLayer : this.targetLayer === "selected" ? A.SELECTED : A.BASE;
625
822
  }
626
823
  createRenderTarget() {
627
- this.renderTarget = new m.WebGLRenderTarget(
628
- this.targetRect.width * this.qualityFactor,
629
- this.targetRect.height * this.qualityFactor,
630
- {
631
- minFilter: m.LinearFilter,
632
- magFilter: m.LinearFilter,
633
- format: m.RGBAFormat,
634
- stencilBuffer: !1,
635
- depthBuffer: !0
636
- // samples: 0.7,
637
- }
638
- );
824
+ for (let e = 0; e < O.MAX_LAYERS; e++)
825
+ this.renderTargets.push(
826
+ new v.WebGLRenderTarget(
827
+ this.targetRect.width * this.qualityFactor,
828
+ this.targetRect.height * this.qualityFactor,
829
+ {
830
+ minFilter: v.LinearFilter,
831
+ magFilter: v.LinearFilter,
832
+ format: v.RGBAFormat,
833
+ stencilBuffer: !1,
834
+ depthBuffer: !0
835
+ }
836
+ )
837
+ );
639
838
  }
640
839
  applyTextQuality(e) {
641
840
  if (typeof e == "number") {
@@ -650,6 +849,8 @@ class Me {
650
849
  this.qualityFactor = 4;
651
850
  break;
652
851
  case "medium":
852
+ this.qualityFactor = 2;
853
+ break;
653
854
  default:
654
855
  this.qualityFactor = 2;
655
856
  break;
@@ -661,22 +862,41 @@ class Me {
661
862
  updateCanvasLayout() {
662
863
  this.canvas.style.width = `${this.targetRect.width}px`, this.canvas.style.height = `${this.targetRect.height}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 = "absolute", this.canvas.style.top = `${this.target.offsetTop}px`, this.canvas.style.left = `${this.target.offsetLeft}px`, this.canvas.style.display = "block");
663
864
  }
865
+ updateUniforms(e, t) {
866
+ const i = this.registry.get(e);
867
+ i && (i.traverse((r) => {
868
+ r.isMesh && r.material && H.forceUpdateUniforms(
869
+ r.material,
870
+ t
871
+ );
872
+ }), i.userData.nativeMesh && i.userData.nativeMesh.traverse((r) => {
873
+ r.isMesh && r.material && H.forceUpdateUniforms(
874
+ r.material,
875
+ t
876
+ );
877
+ }));
878
+ }
664
879
  dispose() {
665
880
  this.renderer.dispose(), this.canvas.remove(), this.textureManager.disposeAll();
666
881
  }
667
882
  setSize(e, t) {
668
- this.renderer.setSize(e, t), this.renderTarget && this.renderTarget.setSize(
669
- e * this.qualityFactor,
670
- t * this.qualityFactor
671
- ), this.camera.left = e / -2, this.camera.right = e / 2, this.camera.top = t / 2, this.camera.bottom = t / -2, this.camera.updateProjectionMatrix();
883
+ this.renderer.setSize(e, t);
884
+ for (const i of this.renderTargets)
885
+ i.setSize(e * this.qualityFactor, t * this.qualityFactor);
886
+ this.camera.left = e / -2, this.camera.right = e / 2, this.camera.top = t / 2, this.camera.bottom = t / -2, this.camera.updateProjectionMatrix();
672
887
  }
673
888
  syncScene(e, t) {
674
- const s = this.target.getBoundingClientRect(), r = Math.abs(s.width - this.targetRect.width) > 0.1 || Math.abs(s.height - this.targetRect.height) > 0.1, a = this.mode === "overlay" && (Math.abs(s.top - this.targetRect.top) > 0.1 || Math.abs(s.left - this.targetRect.left) > 0.1);
675
- r ? (this.targetRect = s, this.setSize(this.targetRect.width, this.targetRect.height), this.updateCanvasLayout()) : a ? (this.targetRect = s, this.updateCanvasLayout()) : this.targetRect = s, this.renderOrder = 0, this.reconcileNode(e), t.size > 0 && t.forEach((o) => {
676
- const n = this.registry.get(o);
677
- n && (this.scene.remove(n), this.travelers.delete(n), this.fixedMeshes.delete(n), n.geometry.dispose(), n.traverse((c) => {
678
- c instanceof m.Mesh && (c.geometry && c.geometry.dispose(), c.material && (Array.isArray(c.material) ? c.material.forEach((l) => l.dispose()) : c.material.dispose()));
679
- }), this.registry.remove(o), this.textureManager.unregister(o));
889
+ const i = this.target.getBoundingClientRect(), r = Math.abs(i.width - this.targetRect.width) > 0.1 || Math.abs(i.height - this.targetRect.height) > 0.1, l = this.mode === "overlay" && (Math.abs(i.top - this.targetRect.top) > 0.1 || Math.abs(i.left - this.targetRect.left) > 0.1);
890
+ r ? (this.targetRect = i, this.setSize(this.targetRect.width, this.targetRect.height), this.updateCanvasLayout()) : l ? (this.targetRect = i, this.updateCanvasLayout()) : this.targetRect = i, this.renderOrder = 0, this.reconcileNode(e), t.size > 0 && t.forEach((o) => {
891
+ const a = this.registry.get(o);
892
+ if (a) {
893
+ this.scene.remove(a);
894
+ for (const n of this.travelersByLayer)
895
+ n.delete(a);
896
+ this.fixedMeshes.delete(a), a.geometry.dispose(), a.userData.nativeMesh && (this.scene.remove(a.userData.nativeMesh), Array.isArray(a.userData.nativeMesh.material) ? a.userData.nativeMesh.material.forEach((n) => n.dispose()) : a.userData.nativeMesh.material.dispose(), a.userData.nativeMesh.geometry.dispose()), a.traverse((n) => {
897
+ n instanceof v.Mesh && (n.geometry && n.geometry.dispose(), n.material && (Array.isArray(n.material) ? n.material.forEach((c) => c.dispose()) : n.material.dispose()));
898
+ }), this.registry.remove(o), this.textureManager.unregister(o);
899
+ }
680
900
  });
681
901
  }
682
902
  // 탐색 후 완성된 Scene node를 이용하여 mesh를 만들거나 조정
@@ -684,495 +904,607 @@ class Me {
684
904
  // => 이후 activeElements를 이용하여 mesh를 정리!!!+ map에서도 삭제
685
905
  // private reconcileNode(node: SceneNode, activeElements: Set<HTMLElement>) {
686
906
  reconcileNode(e) {
687
- var s;
907
+ var i;
688
908
  let t = this.registry.get(e.element);
689
909
  if (!t) {
690
- const r = new m.PlaneGeometry(1, 1);
691
- let a;
692
- const o = e.isTraveler ? (s = this.renderTarget) == null ? void 0 : s.texture : this.textureManager.get(e.element);
693
- a = z.create(
910
+ const r = new v.PlaneGeometry(1, 1), l = e.isTraveler ? (i = this.renderTargets[e.captureLayer - 2]) == null ? void 0 : i.texture : this.textureManager.get(e.element), o = H.create(
694
911
  "BOX",
695
912
  e.styles,
696
913
  "",
697
914
  e.rect.width,
698
915
  e.rect.height,
699
916
  this.qualityFactor,
700
- o,
917
+ l,
701
918
  e.shaderHooks
702
- ), t = new m.Mesh(r, a), e.type === "TEXT" && (t.name = "BG_MESH"), this.scene.add(t), this.registry.register(e.element, t);
919
+ );
920
+ t = new v.Mesh(r, o), e.type === "TEXT" && (t.name = "BG_MESH"), this.scene.add(t), this.registry.register(e.element, t), t.userData.baseMaterial = o;
703
921
  }
704
- if (t.userData.domRect = e.rect, this.updateMeshProperties(t, e), this.updateMeshLayers(t, e), e.isTraveler ? (t.layers.enable(28), this.travelers.add(t)) : (t.layers.disable(28), this.travelers.delete(t)), 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")
922
+ if (this.updateMeshProperties(t, e), this.updateMeshLayers(t, e), e.isTraveler)
923
+ for (let r = 0; r < O.MAX_LAYERS; r++)
924
+ r === e.captureLayer - 2 ? this.travelersByLayer[r].add(t) : this.travelersByLayer[r].delete(t);
925
+ else
926
+ for (const r of this.travelersByLayer)
927
+ r.delete(t);
928
+ 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")
705
929
  for (const r of e.children)
706
930
  this.reconcileNode(r);
707
931
  else
708
- e.type === "TEXT" && this.reconcileTextChild(t, e);
709
- }
710
- reconcileTextChild(e, t) {
711
- var n;
712
- const s = t.textLines || [{ text: t.textContent || "", rect: t.rect }], r = JSON.stringify(t.textStyles) + t.textContent + s.map((c) => c.text).join("|"), a = (n = e.userData) == null ? void 0 : n.textChildStyleHash;
713
- if (t.dirtyMask & $ || r !== a) {
714
- e.children.filter((h) => h.name.startsWith("TEXT_CHILD")).forEach((h) => {
715
- var g;
716
- const p = h;
717
- (g = p.material.map) == null || g.dispose(), p.geometry.dispose(), e.remove(p);
932
+ e.type === "TEXT" && (this.reconcileTextChild(t, e, !1), t.userData.nativeMesh && e.nativeStyles && this.reconcileTextChild(t.userData.nativeMesh, e, !0));
933
+ }
934
+ reconcileTextChild(e, t, i) {
935
+ var c;
936
+ const r = t.textLines || [
937
+ { text: t.textContent || "", rect: t.rect }
938
+ ], l = i ? t.nativeStyles : t.textStyles, o = JSON.stringify(l) + t.textContent + r.map((h) => h.text).join("|"), a = (c = e.userData) == null ? void 0 : c.textChildStyleHash;
939
+ if (t.dirtyMask & ve || o !== a) {
940
+ e.children.filter(
941
+ (d) => d.name.startsWith("TEXT_CHILD")
942
+ ).forEach((d) => {
943
+ var w;
944
+ const g = d;
945
+ (w = g.material.map) == null || w.dispose(), g.geometry.dispose(), e.remove(g);
718
946
  });
719
- const l = t.rect, d = l.x + l.width / 2, f = l.y + l.height / 2;
720
- s.forEach((h, p) => {
721
- const g = z.create(
947
+ const f = t.rect, b = f.x + f.width / 2, p = f.y + f.height / 2;
948
+ r.forEach((d, g) => {
949
+ const w = H.create(
722
950
  "TEXT",
723
- t.textStyles,
724
- h.text,
725
- h.rect.width,
726
- h.rect.height,
951
+ l,
952
+ d.text,
953
+ d.rect.width,
954
+ d.rect.height,
727
955
  this.qualityFactor
728
- ), y = new m.PlaneGeometry(1, 1), x = new m.Mesh(y, g);
729
- x.name = `TEXT_CHILD_${p}`, this.updateMeshLayers(x, t);
730
- const T = t.rect.width === 0 ? 1 : h.rect.width / t.rect.width, S = t.rect.height === 0 ? 1 : h.rect.height / t.rect.height;
731
- x.scale.set(T, S, 1);
732
- const M = h.rect.x + h.rect.width / 2, E = h.rect.y + h.rect.height / 2, b = M - d, C = -(E - f);
733
- x.position.set(
734
- t.rect.width === 0 ? 0 : b / t.rect.width,
735
- t.rect.height === 0 ? 0 : C / t.rect.height,
956
+ ), L = new v.PlaneGeometry(1, 1), R = new v.Mesh(L, w);
957
+ R.name = `TEXT_CHILD_${g}`;
958
+ const E = t.rect.width === 0 ? 1 : d.rect.width / t.rect.width, x = t.rect.height === 0 ? 1 : d.rect.height / t.rect.height;
959
+ R.scale.set(E, x, 1);
960
+ const U = d.rect.x + d.rect.width / 2, F = d.rect.y + d.rect.height / 2, _ = U - b, D = -(F - p);
961
+ R.position.set(
962
+ t.rect.width === 0 ? 0 : _ / t.rect.width,
963
+ t.rect.height === 0 ? 0 : D / t.rect.height,
736
964
  5e-3
737
- ), e.add(x);
738
- }), e.userData.textChildStyleHash = r;
965
+ ), e.add(R);
966
+ }), e.userData.textChildStyleHash = o;
739
967
  }
968
+ e.children.forEach((h) => {
969
+ if (!h.name.startsWith("TEXT_CHILD"))
970
+ return;
971
+ const f = h, b = t.visibility & P ? A.BASE : A.HIDDEN;
972
+ if (f.layers.set(b), t.visibility & Z && f.layers.enable(A.SELECTED), t.visibility & P)
973
+ if (!i && t.nativeLayer !== void 0 && t.nativeStyles !== void 0)
974
+ for (let p = t.captureLayer; p < t.nativeLayer; p++)
975
+ f.layers.enable(A.getCaptureLayer(p));
976
+ else if (i && t.nativeLayer !== void 0)
977
+ for (let p = Math.max(t.captureLayer, t.nativeLayer); p <= O.MAX_LAYERS + 1; p++)
978
+ f.layers.enable(A.getCaptureLayer(p));
979
+ else
980
+ for (let p = t.captureLayer; p <= O.MAX_LAYERS + 1; p++)
981
+ f.layers.enable(A.getCaptureLayer(p));
982
+ });
740
983
  }
741
984
  updateMeshProperties(e, t) {
742
- var b;
743
- const { rect: s, styles: r } = t, a = this.renderer.getPixelRatio(), o = this.renderer.domElement.width / a, n = this.renderer.domElement.height / a;
744
- e.scale.set(s.width, s.height, 1);
745
- const c = 1e-3;
985
+ var U, F, _;
986
+ const { rect: i, styles: r } = t, l = this.renderer.getPixelRatio(), o = this.renderer.domElement.width / l, a = this.renderer.domElement.height / l;
987
+ e.material = e.userData.baseMaterial, e.scale.set(i.width, i.height, 1), e.userData.domRect = pe(G({}, i), {
988
+ width: i.width,
989
+ height: i.height
990
+ });
991
+ const n = 1e-3;
746
992
  this.renderOrder++;
747
- const l = this.targetRect.left + window.scrollX, d = this.targetRect.top + window.scrollY, f = s.x - l, h = s.y - d, p = f - o / 2 + s.width / 2, g = -h + n / 2 - s.height / 2;
993
+ const c = this.targetRect.left + window.scrollX, h = this.targetRect.top + window.scrollY, f = i.x - c, b = i.y - h, p = f - o / 2 + i.width / 2, d = -b + a / 2 - i.height / 2;
748
994
  e.position.set(
749
995
  p,
750
- g,
751
- r.zIndex + this.renderOrder * c
996
+ d,
997
+ r.zIndex + this.renderOrder * n
752
998
  );
753
- const y = s.x, x = s.y;
754
- e.userData.basePosition = { x: p, y: g }, e.userData.originalBasePosition = { x: p, y: g }, e.userData.baseSize = { width: s.width, height: s.height }, e.userData.baseDOM = { x: y, y: x }, e.userData.isFixed = t.isFixed, e.userData.initialScroll = { x: window.scrollX, y: window.scrollY };
755
- const T = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, S = window.getComputedStyle(T);
756
- let M = 0, E = 0;
757
- if (S.transform && S.transform !== "none") {
758
- const C = new DOMMatrix(S.transform);
759
- M = C.m41, E = C.m42;
999
+ const g = i.x, w = i.y;
1000
+ e.userData.basePosition = { x: p, y: d }, e.userData.originalBasePosition = { x: p, y: d }, e.userData.baseSize = { width: i.width, height: i.height }, e.userData.baseDOM = { x: g, y: w }, e.userData.isFixed = t.isFixed, e.userData.initialScroll = { x: window.scrollX, y: window.scrollY };
1001
+ const L = t.element.nodeType === Node.TEXT_NODE ? t.element.parentElement : t.element, R = window.getComputedStyle(L);
1002
+ let E = 0, x = 0;
1003
+ if (R.transform && R.transform !== "none") {
1004
+ const D = new DOMMatrix(R.transform);
1005
+ E = D.m41, x = D.m42;
760
1006
  }
761
- e.userData.baseTransform = { x: M, y: E }, delete e.userData.originRatioX, delete e.userData.originRatioY, z.update(
762
- e.material,
1007
+ if (e.userData.baseTransform = { x: E, y: x }, delete e.userData.originRatioX, delete e.userData.originRatioY, H.update(
1008
+ e.userData.baseMaterial,
763
1009
  "BOX",
764
- t.styles,
1010
+ r,
765
1011
  "",
766
- t.rect.width,
767
- t.rect.height,
1012
+ i.width,
1013
+ i.height,
768
1014
  this.qualityFactor,
769
- t.isTraveler ? (b = this.renderTarget) == null ? void 0 : b.texture : this.textureManager.get(t.element)
770
- );
1015
+ t.isTraveler ? (U = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : U.texture : this.textureManager.get(t.element)
1016
+ ), t.nativeStyles && t.nativeRect) {
1017
+ if (!e.userData.nativeMesh) {
1018
+ const $ = H.create(
1019
+ "BOX",
1020
+ t.nativeStyles,
1021
+ "",
1022
+ t.nativeRect.width,
1023
+ t.nativeRect.height,
1024
+ this.qualityFactor,
1025
+ t.isTraveler ? (F = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : F.texture : this.textureManager.get(t.element),
1026
+ t.shaderHooks
1027
+ ), V = new v.Mesh(e.geometry, $);
1028
+ t.type === "TEXT" && (V.name = "BG_MESH"), this.scene.add(V), e.userData.nativeMesh = V;
1029
+ }
1030
+ const D = e.userData.nativeMesh, I = t.nativeRect.x - c, K = t.nativeRect.y - h, J = I - o / 2 + t.nativeRect.width / 2, Q = -K + a / 2 - t.nativeRect.height / 2;
1031
+ D.scale.set(t.nativeRect.width, t.nativeRect.height, 1), D.position.set(
1032
+ J,
1033
+ Q,
1034
+ t.nativeStyles.zIndex + this.renderOrder * n
1035
+ ), H.update(
1036
+ D.material,
1037
+ "BOX",
1038
+ t.nativeStyles,
1039
+ "",
1040
+ t.nativeRect.width,
1041
+ t.nativeRect.height,
1042
+ this.qualityFactor,
1043
+ t.isTraveler ? (_ = this.renderTargets[t.captureLayer - 2]) == null ? void 0 : _.texture : this.textureManager.get(t.element)
1044
+ );
1045
+ } else
1046
+ e.userData.nativeMesh && (this.scene.remove(e.userData.nativeMesh), e.userData.nativeMesh.material instanceof v.Material && e.userData.nativeMesh.material.dispose(), delete e.userData.nativeMesh);
771
1047
  }
772
1048
  updateMeshLayers(e, t) {
773
- const s = (1 - (t.visibility & D)) * 30;
774
- e.layers.set(s), t.visibility === (D | X) && e.layers.enable(29);
1049
+ const i = t.visibility & P ? A.BASE : A.HIDDEN;
1050
+ if (e.layers.set(i), t.visibility & Z && e.layers.enable(A.SELECTED), e.userData.nativeMesh && t.nativeLayer !== void 0) {
1051
+ const r = e.userData.nativeMesh;
1052
+ if (r.layers.set(A.HIDDEN), t.visibility & P) {
1053
+ for (let l = t.captureLayer; l < t.nativeLayer; l++)
1054
+ e.layers.enable(A.getCaptureLayer(l));
1055
+ for (let l = Math.max(t.captureLayer, t.nativeLayer); l <= O.MAX_LAYERS + 1; l++)
1056
+ r.layers.enable(A.getCaptureLayer(l));
1057
+ }
1058
+ } else if (t.visibility & P)
1059
+ for (let r = t.captureLayer; r <= O.MAX_LAYERS + 1; r++)
1060
+ e.layers.enable(A.getCaptureLayer(r));
775
1061
  }
776
- captureRenderTarget() {
777
- if (this.travelers.size === 0)
1062
+ captureRenderTarget(e, t, i) {
1063
+ if (e.size === 0 || !i)
778
1064
  return;
779
- const e = new m.Color(), t = this.renderer.getClearAlpha();
780
- this.renderer.getClearColor(e), this.renderer.setClearColor(0, 0), this.renderer.setRenderTarget(this.renderTarget), this.renderer.clear(), this.renderer.autoClear = !1, this.renderer.setScissorTest(!0), this.camera.layers.set(29);
781
- const s = new m.Vector3(), r = this.targetRect.width, a = this.targetRect.height, o = this.renderer.getPixelRatio();
782
- for (const n of this.travelers) {
783
- s.setFromMatrixPosition(n.matrixWorld), s.project(this.camera);
784
- const c = (s.x + 1) / 2 * r, l = (s.y + 1) / 2 * a;
785
- let d = 0, f = 1;
786
- typeof this.clipArea == "number" ? f = this.clipArea : this.clipArea.endsWith("%") ? f = parseFloat(this.clipArea) / 100 : this.clipArea.endsWith("px") && (d = parseFloat(this.clipArea));
787
- const h = n.scale.x * f + 0.5, p = n.scale.y * f + 0.5, g = c - h / 2, y = l - p / 2, x = (g * this.qualityFactor - d) / o, T = (y * this.qualityFactor - d) / o, S = (h * this.qualityFactor + d * 2) / o, M = (p * this.qualityFactor + d * 2) / o;
788
- this.renderer.setScissor(x, T, S, M), this.renderer.render(this.scene, this.camera);
1065
+ const r = new v.Color(), l = this.renderer.getClearAlpha();
1066
+ 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);
1067
+ const o = new v.Vector3(), a = this.targetRect.width, n = this.targetRect.height, c = this.renderer.getPixelRatio();
1068
+ for (const h of e) {
1069
+ o.setFromMatrixPosition(h.matrixWorld), o.project(this.camera);
1070
+ const f = (o.x + 1) / 2 * a, b = (o.y + 1) / 2 * n;
1071
+ let p = 0, d = 1;
1072
+ typeof this.clipArea == "number" ? d = this.clipArea : this.clipArea.endsWith("%") ? d = parseFloat(this.clipArea) / 100 : this.clipArea.endsWith("px") && (p = parseFloat(this.clipArea));
1073
+ const g = h.scale.x * d + 0.5, w = h.scale.y * d + 0.5, L = f - g / 2, R = b - w / 2, E = (L * this.qualityFactor - p) / c, x = (R * this.qualityFactor - p) / c, U = (g * this.qualityFactor + p * 2) / c, F = (w * this.qualityFactor + p * 2) / c;
1074
+ this.renderer.setScissor(E, x, U, F), this.renderer.render(this.scene, this.camera);
789
1075
  }
790
- this.renderer.setScissorTest(!1), this.renderer.autoClear = !0, this.renderer.setRenderTarget(null), this.camera.layers.set(0), this.renderer.setClearColor(e, t);
1076
+ this.renderer.setScissorTest(!1), this.renderer.autoClear = !0, this.renderer.setRenderTarget(null), this.camera.layers.set(this.getSceneLayer()), this.renderer.setClearColor(r, l);
791
1077
  }
792
1078
  render() {
793
- this.renderTarget && this.captureRenderTarget(), this.renderer.render(this.scene, this.camera);
794
- }
795
- // for debugging
796
- showScissoredRenderTarget() {
797
- if (!this.renderTarget)
798
- return;
799
- const e = this.targetRect.width, t = this.targetRect.height, s = new m.PlaneGeometry(e, t), r = new m.MeshBasicMaterial({
800
- map: this.renderTarget.texture,
801
- side: m.DoubleSide,
802
- transparent: !0,
803
- opacity: 0.8
804
- }), a = new m.Mesh(s, r);
805
- a.position.set(0, 0, 90), a.layers.set(28), this.scene.add(a);
1079
+ for (let e = 0; e < O.MAX_LAYERS; e++) {
1080
+ const t = e + 1;
1081
+ this.captureRenderTarget(
1082
+ this.travelersByLayer[e],
1083
+ A.getCaptureLayer(t),
1084
+ this.renderTargets[e]
1085
+ );
1086
+ }
1087
+ this.renderer.render(this.scene, this.camera);
806
1088
  }
807
1089
  }
808
- function Ee(i) {
809
- const e = i.textContent || "", t = [];
810
- let s = "", r = null, a = -1;
811
- const o = (l, d) => {
812
- for (let f = 0; f < l.length; f++) {
813
- const h = l[f], p = document.createRange();
814
- p.setStart(i, d + f), p.setEnd(i, d + f + 1);
815
- const g = p.getBoundingClientRect();
816
- if (g.width === 0 && g.height === 0) {
817
- s += h;
1090
+ function rt(s) {
1091
+ const e = s.textContent || "", t = [];
1092
+ let i = "", r = null, l = -1;
1093
+ const o = (c, h) => {
1094
+ for (let f = 0; f < c.length; f++) {
1095
+ const b = c[f], p = document.createRange();
1096
+ p.setStart(s, h + f), p.setEnd(s, h + f + 1);
1097
+ const d = p.getBoundingClientRect();
1098
+ if (d.width === 0 && d.height === 0) {
1099
+ i += b;
818
1100
  continue;
819
1101
  }
820
- a === -1 || Math.abs(g.top - a) > g.height / 2 ? (s && r && t.push({
821
- text: s,
1102
+ l === -1 || Math.abs(d.top - l) > d.height / 2 ? (i && r && t.push({
1103
+ text: i,
822
1104
  rect: {
823
1105
  left: r.left,
824
1106
  top: r.top,
825
1107
  width: r.right - r.left,
826
1108
  height: r.bottom - r.top
827
1109
  }
828
- }), s = h, r = { left: g.left, top: g.top, right: g.right, bottom: g.bottom }, a = g.top) : (s += h, r && (r.left = Math.min(r.left, g.left), r.top = Math.min(r.top, g.top), r.right = Math.max(r.right, g.right), r.bottom = Math.max(r.bottom, g.bottom)));
1110
+ }), i = b, r = {
1111
+ left: d.left,
1112
+ top: d.top,
1113
+ right: d.right,
1114
+ bottom: d.bottom
1115
+ }, l = d.top) : (i += b, r && (r.left = Math.min(r.left, d.left), r.top = Math.min(r.top, d.top), r.right = Math.max(r.right, d.right), r.bottom = Math.max(
1116
+ r.bottom,
1117
+ d.bottom
1118
+ )));
829
1119
  }
830
- }, n = e.match(/[^\s\-]+\-?|\-|\s+/g) || [];
831
- let c = 0;
832
- for (const l of n) {
833
- const d = document.createRange();
834
- d.setStart(i, c), d.setEnd(i, c + l.length);
835
- const f = d.getClientRects();
1120
+ }, a = e.match(/[^\s\-]+\-?|\-|\s+/g) || [];
1121
+ let n = 0;
1122
+ for (const c of a) {
1123
+ const h = document.createRange();
1124
+ h.setStart(s, n), h.setEnd(s, n + c.length);
1125
+ const f = h.getClientRects();
836
1126
  if (f.length > 1)
837
- o(l, c);
1127
+ o(c, n);
838
1128
  else {
839
- const h = f.length === 1 ? f[0] : d.getBoundingClientRect();
840
- if (h.width === 0 && h.height === 0) {
841
- s += l, c += l.length;
1129
+ const b = f.length === 1 ? f[0] : h.getBoundingClientRect();
1130
+ if (b.width === 0 && b.height === 0) {
1131
+ i += c, n += c.length;
842
1132
  continue;
843
1133
  }
844
- a === -1 || Math.abs(h.top - a) > h.height / 2 ? (s && r && t.push({
845
- text: s,
1134
+ l === -1 || Math.abs(b.top - l) > b.height / 2 ? (i && r && t.push({
1135
+ text: i,
846
1136
  rect: {
847
1137
  left: r.left,
848
1138
  top: r.top,
849
1139
  width: r.right - r.left,
850
1140
  height: r.bottom - r.top
851
1141
  }
852
- }), s = l, r = { left: h.left, top: h.top, right: h.right, bottom: h.bottom }, a = h.top) : (s += l, r && (r.left = Math.min(r.left, h.left), r.top = Math.min(r.top, h.top), r.right = Math.max(r.right, h.right), r.bottom = Math.max(r.bottom, h.bottom)));
1142
+ }), i = c, r = {
1143
+ left: b.left,
1144
+ top: b.top,
1145
+ right: b.right,
1146
+ bottom: b.bottom
1147
+ }, l = b.top) : (i += c, r && (r.left = Math.min(r.left, b.left), r.top = Math.min(r.top, b.top), r.right = Math.max(r.right, b.right), r.bottom = Math.max(
1148
+ r.bottom,
1149
+ b.bottom
1150
+ )));
853
1151
  }
854
- c += l.length;
1152
+ n += c.length;
855
1153
  }
856
- return s && r && t.push({
857
- text: s,
1154
+ return i && r && t.push({
1155
+ text: i,
858
1156
  rect: {
859
1157
  left: r.left,
860
1158
  top: r.top,
861
1159
  width: r.right - r.left,
862
1160
  height: r.bottom - r.top
863
1161
  }
864
- }), t.filter((l) => l.text.trim().length > 0 && l.rect.width > 0 && l.rect.height > 0);
1162
+ }), t.filter(
1163
+ (c) => c.text.trim().length > 0 && c.rect.width > 0 && c.rect.height > 0
1164
+ );
865
1165
  }
866
- function De(i) {
867
- const e = parseFloat(i.fontSize);
868
- let t = parseFloat(i.lineHeight);
1166
+ function Le(s) {
1167
+ const e = parseFloat(s.fontSize);
1168
+ let t = parseFloat(s.lineHeight);
869
1169
  isNaN(t) && (t = e * 1.2);
870
- let s = parseFloat(i.letterSpacing);
871
- return isNaN(s) && (s = 0), {
872
- font: `${i.fontStyle} ${i.fontWeight} ${i.fontSize} ${i.fontFamily}`,
873
- fontSize: i.fontSize,
874
- color: i.color,
875
- textAlign: i.textAlign || "start",
1170
+ let i = parseFloat(s.letterSpacing);
1171
+ return isNaN(i) && (i = 0), {
1172
+ font: `${s.fontStyle} ${s.fontWeight} ${s.fontSize} ${s.fontFamily}`,
1173
+ fontSize: s.fontSize,
1174
+ color: s.color,
1175
+ textAlign: s.textAlign || "start",
876
1176
  textBaseline: "alphabetic",
877
- direction: i.direction || "inherit",
1177
+ direction: s.direction || "inherit",
878
1178
  lineHeight: t,
879
- letterSpacing: s
1179
+ letterSpacing: i
880
1180
  };
881
1181
  }
882
- function ce(i, e = B | _ | fe | $ | V, t, s) {
883
- if (i.nodeType === Node.TEXT_NODE) {
884
- const b = i;
885
- if (!b.textContent || !b.textContent.trim())
1182
+ function Ie(s, e = j | ae | Ye | ve | be, t, i = 1, r = 0, l = 2, o, a) {
1183
+ var V, te, re, ie, se, oe;
1184
+ if (s.nodeType === Node.TEXT_NODE) {
1185
+ const m = s;
1186
+ if (!m.textContent || !m.textContent.trim())
886
1187
  return null;
887
- const C = b.textContent.replace(/\s+/g, " ");
888
- if (C.length === 0)
1188
+ const T = m.textContent.replace(/\s+/g, " ");
1189
+ if (T.length === 0)
889
1190
  return null;
890
- const R = Ee(b);
891
- if (R.length === 0)
1191
+ const M = rt(m);
1192
+ if (M.length === 0)
892
1193
  return null;
893
- const k = b.parentElement, O = k ? window.getComputedStyle(k) : null;
894
- if (!O)
1194
+ const k = m.parentElement, S = k ? window.getComputedStyle(k) : null;
1195
+ if (!S)
895
1196
  return null;
896
- const L = Math.min(...R.map((v) => v.rect.left)), A = Math.min(...R.map((v) => v.rect.top)), P = Math.max(...R.map((v) => v.rect.left + v.rect.width)), Y = Math.max(...R.map((v) => v.rect.top + v.rect.height));
1197
+ const B = Math.min(...M.map((y) => y.rect.left)), C = Math.min(...M.map((y) => y.rect.top)), X = Math.max(...M.map((y) => y.rect.left + y.rect.width)), W = Math.max(...M.map((y) => y.rect.top + y.rect.height));
897
1198
  return {
898
1199
  id: Math.random().toString(36).substring(2, 9),
899
1200
  type: "TEXT",
900
- element: b,
1201
+ element: m,
901
1202
  rect: {
902
- x: L + window.scrollX,
903
- y: A + window.scrollY,
904
- width: P - L,
905
- height: Y - A
1203
+ x: B + window.scrollX,
1204
+ y: C + window.scrollY,
1205
+ width: X - B,
1206
+ height: W - C
906
1207
  },
907
1208
  styles: {
908
1209
  backgroundColor: "transparent",
909
1210
  backgroundImage: "",
910
- opacity: k && k.dataset.mirageDom === "hide" ? 1 : parseFloat(O.opacity),
911
- zIndex: 0,
1211
+ opacity: k && k.dataset[q.KEY] === q.VALUES.HIDE ? 1 : parseFloat(S.opacity),
1212
+ zIndex: (isNaN(parseInt(S.zIndex)) ? 0 : parseInt(S.zIndex)) + r,
912
1213
  borderRadius: "0px",
913
1214
  borderColor: "transparent",
914
1215
  borderWidth: "0px",
915
1216
  isTraveler: !1
916
1217
  },
917
- textContent: C,
918
- textLines: R.map((v) => ({
919
- text: v.text.trim(),
1218
+ textContent: T,
1219
+ textLines: M.map((y) => ({
1220
+ text: y.text.trim(),
920
1221
  rect: {
921
- x: v.rect.left + window.scrollX,
922
- y: v.rect.top + window.scrollY,
923
- width: v.rect.width,
924
- height: v.rect.height
1222
+ x: y.rect.left + window.scrollX,
1223
+ y: y.rect.top + window.scrollY,
1224
+ width: y.rect.width,
1225
+ height: y.rect.height
925
1226
  }
926
1227
  })),
927
- textStyles: De(O),
1228
+ textStyles: Le(S),
928
1229
  dirtyMask: e,
929
1230
  visibility: t,
930
1231
  isTraveler: !1,
931
- isFixed: O.position === "fixed",
1232
+ captureLayer: i,
1233
+ isFixed: S.position === "fixed",
1234
+ nativeLayer: o,
1235
+ nativeStyles: a ? G(G({
1236
+ backgroundColor: "transparent",
1237
+ backgroundImage: "",
1238
+ opacity: k && k.dataset[q.KEY] === q.VALUES.HIDE ? 1 : parseFloat(S.opacity),
1239
+ zIndex: (isNaN(parseInt(S.zIndex)) ? 0 : parseInt(S.zIndex)) + r,
1240
+ borderRadius: "0px",
1241
+ borderColor: "transparent",
1242
+ borderWidth: "0px",
1243
+ isTraveler: !1
1244
+ }, Le(S)), a) : void 0,
1245
+ nativeRect: a ? {
1246
+ x: B + window.scrollX,
1247
+ y: C + window.scrollY,
1248
+ width: X - B,
1249
+ height: W - C
1250
+ } : void 0,
932
1251
  children: []
933
1252
  };
934
1253
  }
935
- if (i.nodeType !== Node.ELEMENT_NODE)
1254
+ if (s.nodeType !== Node.ELEMENT_NODE)
936
1255
  return null;
937
- const r = i, a = r.dataset.mirageFilter;
938
- let o = t, n = t;
939
- if (a) {
940
- const b = new Set(a.split(/\s+/));
941
- for (const C of b)
942
- if (!ge.includes(C))
1256
+ const n = s, c = n.dataset[Y.KEY];
1257
+ let h = t, f = t;
1258
+ if (c) {
1259
+ const m = new Set(c.split(/\s+/));
1260
+ for (const T of m)
1261
+ if (!Se.includes(T))
943
1262
  throw new Error(
944
- `[MirageEngine] Invalid filter token: '${C}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1263
+ `[MirageEngine] Invalid filter token: '${T}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
945
1264
  );
946
- if (b.has("end"))
1265
+ if (m.has(Y.VALUES.END))
947
1266
  return null;
948
- if (b.has("include-tree") && b.has("exclude-tree"))
1267
+ if (m.has(Y.VALUES.INCLUDE_TREE) && m.has(Y.VALUES.EXCLUDE_TREE))
949
1268
  throw new Error(
950
1269
  "[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element."
951
1270
  );
952
- if (b.has("include-self") && b.has("exclude-self"))
1271
+ if (m.has(Y.VALUES.INCLUDE_SELF) && m.has(Y.VALUES.EXCLUDE_SELF))
953
1272
  throw new Error(
954
1273
  "[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element."
955
1274
  );
956
- b.has("include-tree") ? o = o | D : b.has("exclude-tree") && (o = o & ~D), n = o, b.has("include-self") ? n = n | D : b.has("exclude-self") && (n = n & ~D);
957
- }
958
- n = n | t & X;
959
- const c = r.dataset.mirageTravel;
960
- let l = !1;
961
- c && new Set(c.split(/\s+/)).has("traveler") && (n = n & ~X, o = o & ~X, l = !0);
962
- const d = r.dataset.mirageShader;
963
- let f;
964
- d && (f = JSON.parse(d));
965
- const h = r.getBoundingClientRect(), p = window.getComputedStyle(r);
966
- if (h.width === 0 || h.height === 0 || p.display === "none")
1275
+ m.has(Y.VALUES.INCLUDE_TREE) ? h = h | P : m.has(Y.VALUES.EXCLUDE_TREE) && (h = h & ~P), f = h, m.has(Y.VALUES.INCLUDE_SELF) ? f = f | P : m.has(Y.VALUES.EXCLUDE_SELF) && (f = f & ~P);
1276
+ }
1277
+ const b = n.dataset[z.KEY];
1278
+ if (b) {
1279
+ const m = new Set(b.split(/\s+/));
1280
+ for (const T of m)
1281
+ if (!Se.includes(T))
1282
+ throw new Error(
1283
+ `[MirageEngine] Invalid select token: '${T}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
1284
+ );
1285
+ if (m.has(z.VALUES.END))
1286
+ return null;
1287
+ if (m.has(z.VALUES.INCLUDE_TREE) && m.has(z.VALUES.EXCLUDE_TREE))
1288
+ throw new Error(
1289
+ "[MirageEngine] Conflicting selects: 'include-tree' and 'exclude-tree' cannot be used together on the same element."
1290
+ );
1291
+ if (m.has(z.VALUES.INCLUDE_SELF) && m.has(z.VALUES.EXCLUDE_SELF))
1292
+ throw new Error(
1293
+ "[MirageEngine] Conflicting selects: 'include-self' and 'exclude-self' cannot be used together on the same element."
1294
+ );
1295
+ m.has(z.VALUES.INCLUDE_TREE) ? h = h | Z : m.has(z.VALUES.EXCLUDE_TREE) && (h = h & ~Z), f = h, m.has(z.VALUES.INCLUDE_SELF) ? f = f | Z : m.has(z.VALUES.EXCLUDE_SELF) && (f = f & ~Z);
1296
+ }
1297
+ const p = n.dataset[O.KEY];
1298
+ let d = !1, g = a ? G({}, a) : {}, w = o;
1299
+ if (p) {
1300
+ let m = 1;
1301
+ const T = p.indexOf("{"), M = p.lastIndexOf("}");
1302
+ let k = p;
1303
+ if (T !== -1 && M !== -1 && M > T) {
1304
+ k = p.substring(0, T).trim();
1305
+ const C = p.substring(T, M + 1);
1306
+ try {
1307
+ g = new Function("return " + C)();
1308
+ } catch (X) {
1309
+ console.warn(
1310
+ `[MirageEngine] Failed to parse travel styles JSON: ${C}`
1311
+ );
1312
+ }
1313
+ }
1314
+ const S = k.split(/\s+/);
1315
+ let B = !1;
1316
+ if (S.includes(O.VALUES.TRAVELER)) {
1317
+ d = !0, B = !0;
1318
+ const C = S.find((X) => !isNaN(parseInt(X, 10)));
1319
+ C && (m = parseInt(C, 10));
1320
+ } else if (S.includes(O.VALUES.NATIVE)) {
1321
+ d = !1;
1322
+ const C = S.find((X) => !isNaN(parseInt(X, 10)));
1323
+ C && (w = parseInt(C, 10));
1324
+ }
1325
+ if (B) {
1326
+ const C = m + 1;
1327
+ if (C < i)
1328
+ throw new Error(
1329
+ `[MirageEngine] Traveler layer (${m}) cannot be smaller than inherited capture layer (${i - 1}).`
1330
+ );
1331
+ i = Math.min(C, O.MAX_LAYERS + 1);
1332
+ }
1333
+ }
1334
+ const L = n.dataset[Ne.KEY];
1335
+ let R;
1336
+ L && (R = JSON.parse(L));
1337
+ const E = n.getBoundingClientRect(), x = window.getComputedStyle(n);
1338
+ if (E.width === 0 || E.height === 0 || x.display === "none")
967
1339
  return null;
968
- let g = r.getAttribute("data-mid");
969
- g || (g = Math.random().toString(36).substring(2, 11), r.setAttribute("data-mid", g));
970
- const y = parseInt(p.zIndex);
971
- let x;
972
- if (r.tagName === "IMG")
973
- x = r.src;
974
- else if (p.backgroundImage && p.backgroundImage !== "none") {
975
- const b = p.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
976
- b && (x = b[1]);
977
- }
978
- const T = {
979
- backgroundColor: p.backgroundColor,
980
- backgroundImage: p.backgroundImage,
981
- opacity: r.dataset.mirageDom === "hide" ? 1 : parseFloat(p.opacity),
982
- zIndex: isNaN(y) ? 0 : y,
983
- borderRadius: p.borderRadius,
984
- borderColor: p.borderColor,
985
- borderWidth: p.borderWidth,
986
- imageSrc: x,
987
- isTraveler: l
988
- };
989
- let S, M;
990
- const E = [];
991
- return Array.from(r.childNodes).forEach((b) => {
992
- const C = b.nodeType === Node.TEXT_NODE ? n : o, R = ce(
993
- b,
1340
+ let U = n.getAttribute("data-mid");
1341
+ U || (U = Math.random().toString(36).substring(2, 11), n.setAttribute("data-mid", U));
1342
+ const F = parseInt(x.zIndex), _ = (isNaN(F) ? 0 : F) + r;
1343
+ let D;
1344
+ if (n.tagName === "IMG")
1345
+ D = n.src;
1346
+ else if (n.tagName.toLowerCase() === "svg") {
1347
+ const m = n.cloneNode(!0), T = g == null ? void 0 : g.color, M = g == null ? void 0 : g.fill, k = g == null ? void 0 : g.stroke, S = g == null ? void 0 : g.opacity, B = (y, xe) => {
1348
+ const N = window.getComputedStyle(y), ne = xe, ke = N.fill === N.color, Ue = N.stroke === N.color, de = M || (ke ? T : void 0) || N.fill;
1349
+ de && de !== "none" && (ne.style.fill = de);
1350
+ const ue = k || (Ue ? T : void 0) || N.stroke;
1351
+ ue && ue !== "none" && (ne.style.stroke = ue), N.strokeWidth && N.strokeWidth !== "0px" && (ne.style.strokeWidth = N.strokeWidth);
1352
+ const Ee = T || N.color;
1353
+ Ee && (ne.style.color = Ee);
1354
+ const fe = S || N.opacity;
1355
+ fe && fe !== "1" && (ne.style.opacity = fe);
1356
+ for (let ce = 0; ce < y.children.length; ce++)
1357
+ B(y.children[ce], xe.children[ce]);
1358
+ };
1359
+ B(n, m);
1360
+ const C = n.getBoundingClientRect(), X = window.devicePixelRatio * l;
1361
+ m.hasAttribute("viewBox") || m.setAttribute("viewBox", `0 0 ${C.width} ${C.height}`), m.setAttribute("width", (C.width * X).toString()), m.setAttribute("height", (C.height * X).toString());
1362
+ let W = new XMLSerializer().serializeToString(m);
1363
+ W.includes("xmlns=") || (W = W.replace(
1364
+ "<svg",
1365
+ '<svg xmlns="http://www.w3.org/2000/svg"'
1366
+ )), D = `data:image/svg+xml;utf8,${encodeURIComponent(W)}`;
1367
+ } else if (x.backgroundImage && x.backgroundImage !== "none") {
1368
+ const m = x.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/);
1369
+ m && (D = m[1]);
1370
+ }
1371
+ const I = {
1372
+ backgroundColor: x.backgroundColor,
1373
+ backgroundImage: x.backgroundImage,
1374
+ opacity: n.dataset[q.KEY] === q.VALUES.HIDE ? 1 : parseFloat(x.opacity),
1375
+ zIndex: _,
1376
+ borderRadius: x.borderRadius,
1377
+ borderColor: x.borderColor,
1378
+ borderWidth: x.borderWidth,
1379
+ imageSrc: D,
1380
+ isTraveler: d
1381
+ }, K = I;
1382
+ let J, Q;
1383
+ const $ = [];
1384
+ return n.tagName.toLowerCase() !== "svg" && Array.from(n.childNodes).forEach((m) => {
1385
+ const T = m.nodeType === Node.TEXT_NODE ? f : h, M = Ie(
1386
+ m,
994
1387
  e,
995
- C
1388
+ T,
1389
+ i,
1390
+ _,
1391
+ l,
1392
+ w,
1393
+ m.nodeType === Node.TEXT_NODE && Object.keys(g).length > 0 ? g : void 0
996
1394
  );
997
- R && E.push(R);
1395
+ M && $.push(M);
998
1396
  }), {
999
- id: g,
1397
+ id: U,
1000
1398
  type: "BOX",
1001
- element: r,
1399
+ element: n,
1002
1400
  rect: {
1003
- x: h.left + window.scrollX,
1004
- y: h.top + window.scrollY,
1005
- width: h.width,
1006
- height: h.height
1401
+ x: E.left + window.scrollX,
1402
+ y: E.top + window.scrollY,
1403
+ width: E.width,
1404
+ height: E.height
1007
1405
  },
1008
- styles: T,
1009
- textContent: S,
1010
- textStyles: M,
1406
+ styles: K,
1407
+ textContent: J,
1408
+ textStyles: Q,
1011
1409
  dirtyMask: e,
1012
- visibility: n,
1013
- isTraveler: l,
1014
- isFixed: p.position === "fixed",
1015
- children: E,
1016
- shaderHooks: f
1410
+ visibility: f,
1411
+ isTraveler: d,
1412
+ captureLayer: i,
1413
+ nativeLayer: w,
1414
+ nativeStyles: w !== void 0 ? pe(G({}, I), {
1415
+ backgroundColor: (V = g.backgroundColor) != null ? V : I.backgroundColor,
1416
+ backgroundImage: (te = g.backgroundImage) != null ? te : I.backgroundImage,
1417
+ opacity: (re = g.opacity) != null ? re : I.opacity,
1418
+ zIndex: g.zIndex !== void 0 ? g.zIndex + _ : I.zIndex,
1419
+ borderRadius: (ie = g.borderRadius) != null ? ie : I.borderRadius,
1420
+ borderColor: (se = g.borderColor) != null ? se : I.borderColor,
1421
+ borderWidth: (oe = g.borderWidth) != null ? oe : I.borderWidth,
1422
+ isTraveler: I.isTraveler
1423
+ }) : void 0,
1424
+ nativeRect: w !== void 0 ? {
1425
+ x: g.x !== void 0 ? parseFloat(g.x) : E.left + window.scrollX,
1426
+ y: g.y !== void 0 ? parseFloat(g.y) : E.top + window.scrollY,
1427
+ width: g.width !== void 0 ? parseFloat(g.width) : E.width,
1428
+ height: g.height !== void 0 ? parseFloat(g.height) : E.height
1429
+ } : void 0,
1430
+ isFixed: x.position === "fixed",
1431
+ children: $,
1432
+ shaderHooks: R
1017
1433
  };
1018
1434
  }
1019
- function ke(i, e) {
1020
- e.size !== 0 && e.forEach((t, s) => {
1021
- var b, C, R, k, O, L, A, P, Y, v, j, Q, Z, K, ee, te, re, ie;
1022
- const r = i.get(s);
1435
+ function it(s, e) {
1436
+ e.size !== 0 && e.forEach((t, i) => {
1437
+ var U, F, _, D, I, K, J, Q, $, V, te, re, ie, se, oe, m, T, M;
1438
+ const r = s.get(i);
1023
1439
  if (!r || !r.userData.basePosition)
1024
1440
  return;
1025
- let { x: a, y: o } = r.userData.basePosition;
1026
- const { width: n, height: c } = r.userData.baseSize, l = (b = t.width) != null ? b : n, d = (C = t.height) != null ? C : c, f = l - n, h = d - c;
1441
+ let { x: l, y: o } = r.userData.basePosition;
1442
+ const { width: a, height: n } = r.userData.baseSize, c = (U = t.width) != null ? U : a, h = (F = t.height) != null ? F : n, f = c - a, b = h - n;
1027
1443
  if (t.width !== void 0 && r.userData.originRatioX === void 0 && Math.abs(f) > 0.1) {
1028
- const U = s.getBoundingClientRect(), W = (R = t.x) != null ? R : 0, G = (O = (k = r.userData.baseTransform) == null ? void 0 : k.x) != null ? O : 0, q = r.userData.isFixed ? 0 : window.scrollX;
1029
- let w = -(U.left + q - W + G - r.userData.baseDOM.x) / f;
1030
- Math.abs(w) < 0.05 ? w = 0 : Math.abs(w - 1) < 0.05 ? w = 1 : Math.abs(w - 0.5) < 0.05 && (w = 0.5), r.userData.originRatioX = w;
1444
+ const k = i.getBoundingClientRect(), S = (_ = t.x) != null ? _ : 0, B = (I = (D = r.userData.baseTransform) == null ? void 0 : D.x) != null ? I : 0, C = r.userData.isFixed ? 0 : window.scrollX;
1445
+ let y = -(k.left + C - S + B - r.userData.baseDOM.x) / f;
1446
+ Math.abs(y) < 0.05 ? y = 0 : Math.abs(y - 1) < 0.05 ? y = 1 : Math.abs(y - 0.5) < 0.05 && (y = 0.5), r.userData.originRatioX = y;
1031
1447
  }
1032
- if (t.height !== void 0 && r.userData.originRatioY === void 0 && Math.abs(h) > 0.1) {
1033
- const U = s.getBoundingClientRect(), W = (L = t.y) != null ? L : 0, G = (P = (A = r.userData.baseTransform) == null ? void 0 : A.y) != null ? P : 0, q = r.userData.isFixed ? 0 : window.scrollY;
1034
- let w = -(U.top + q - W + G - r.userData.baseDOM.y) / h;
1035
- Math.abs(w) < 0.05 ? w = 0 : Math.abs(w - 1) < 0.05 ? w = 1 : Math.abs(w - 0.5) < 0.05 && (w = 0.5), r.userData.originRatioY = w;
1448
+ if (t.height !== void 0 && r.userData.originRatioY === void 0 && Math.abs(b) > 0.1) {
1449
+ const k = i.getBoundingClientRect(), S = (K = t.y) != null ? K : 0, B = (Q = (J = r.userData.baseTransform) == null ? void 0 : J.y) != null ? Q : 0, C = r.userData.isFixed ? 0 : window.scrollY;
1450
+ let y = -(k.top + C - S + B - r.userData.baseDOM.y) / b;
1451
+ Math.abs(y) < 0.05 ? y = 0 : Math.abs(y - 1) < 0.05 ? y = 1 : Math.abs(y - 0.5) < 0.05 && (y = 0.5), r.userData.originRatioY = y;
1036
1452
  }
1037
- const p = (Y = r.userData.originRatioX) != null ? Y : 0.5, g = (v = r.userData.originRatioY) != null ? v : 0.5, y = f * (0.5 - p), x = h * (0.5 - g), T = (Q = (j = r.userData.baseTransform) == null ? void 0 : j.x) != null ? Q : 0, S = (K = (Z = r.userData.baseTransform) == null ? void 0 : Z.y) != null ? K : 0, M = ((ee = t.x) != null ? ee : T) - T, E = ((te = t.y) != null ? te : S) - S;
1038
- r.position.setX(a + y + M), r.position.setY(o - (x + E)), r.scale.set(l, d, 1), z.forceUpdateUniforms(r.material, {
1453
+ const p = ($ = r.userData.originRatioX) != null ? $ : 0.5, d = (V = r.userData.originRatioY) != null ? V : 0.5, g = f * (0.5 - p), w = b * (0.5 - d), L = (re = (te = r.userData.baseTransform) == null ? void 0 : te.x) != null ? re : 0, R = (se = (ie = r.userData.baseTransform) == null ? void 0 : ie.y) != null ? se : 0, E = ((oe = t.x) != null ? oe : L) - L, x = ((m = t.y) != null ? m : R) - R;
1454
+ r.position.setX(l + g + E), r.position.setY(o - (w + x)), r.scale.set(c, h, 1), H.forceUpdateUniforms(r.material, {
1039
1455
  backgroundColor: t.backgroundColor,
1040
1456
  backgroundImage: t.backgroundImage,
1041
1457
  opacity: t.opacity,
1042
- borderRadius: (ie = t.borderRadius) != null ? ie : (re = r.userData.baseStyles) == null ? void 0 : re.borderRadius,
1043
- width: l,
1044
- height: d
1458
+ borderRadius: (M = t.borderRadius) != null ? M : (T = r.userData.baseStyles) == null ? void 0 : T.borderRadius,
1459
+ width: c,
1460
+ height: h
1045
1461
  });
1046
1462
  });
1047
1463
  }
1048
- function Oe(i, e, t) {
1049
- i.forEach((s) => {
1050
- if (s.userData.isFixed && s.userData.initialScroll && s.userData.originalBasePosition) {
1051
- const r = e - s.userData.initialScroll.x, a = t - s.userData.initialScroll.y;
1052
- s.userData.basePosition.x = s.userData.originalBasePosition.x + r, s.userData.basePosition.y = s.userData.originalBasePosition.y - a, s.position.x = s.userData.basePosition.x, s.position.y = s.userData.basePosition.y;
1464
+ function st(s, e, t) {
1465
+ s.forEach((i) => {
1466
+ if (i.userData.isFixed && i.userData.initialScroll && i.userData.originalBasePosition) {
1467
+ const r = e - i.userData.initialScroll.x, l = t - i.userData.initialScroll.y;
1468
+ i.userData.basePosition.x = i.userData.originalBasePosition.x + r, i.userData.basePosition.y = i.userData.originalBasePosition.y - l, i.position.x = i.userData.basePosition.x, i.position.y = i.userData.basePosition.y;
1053
1469
  }
1054
1470
  });
1055
1471
  }
1056
- function Be(i) {
1057
- const e = {};
1058
- if (i.opacity && (e.opacity = parseFloat(i.opacity)), i.backgroundColor && i.backgroundColor !== "rgba(0, 0, 0, 0)") {
1059
- const t = I(i.backgroundColor);
1060
- e.backgroundColor = [t.color.r, t.color.g, t.color.b];
1061
- }
1062
- if (i.backgroundImage ? e.backgroundImage = i.backgroundImage : i.background && (e.backgroundImage = i.background), i.borderRadius && (e.borderRadius = parseFloat(i.borderRadius)), i.width && (e.width = parseFloat(i.width)), i.height && (e.height = parseFloat(i.height)), i.transform && i.transform !== "none") {
1063
- const t = new DOMMatrix(i.transform);
1064
- e.x = t.m41, e.y = t.m42, e.z = t.m43;
1065
- }
1066
- return e;
1067
- }
1068
- class Fe {
1069
- constructor(e, t, s, r) {
1472
+ class ot {
1473
+ constructor(e, t, i, r) {
1070
1474
  u(this, "target");
1071
1475
  u(this, "renderer");
1072
1476
  u(this, "registry");
1073
- u(this, "filter");
1074
- u(this, "observer");
1075
- u(this, "pendingDeletions", /* @__PURE__ */ new Set());
1076
- u(this, "pendingStyles", /* @__PURE__ */ new Map());
1077
- u(this, "isDomDirty", !1);
1078
- u(this, "isRunning", !1);
1079
1477
  u(this, "isTravelEnabled", !1);
1080
- u(this, "pendingMask", N);
1081
- u(this, "mutationTimer", null);
1082
- u(this, "cssTimer", null);
1083
- u(this, "resizeConfig");
1084
- u(this, "resizeTimer", null);
1085
- u(this, "isResizing", !1);
1086
- u(this, "lastScrollX", 0);
1087
- u(this, "lastScrollY", 0);
1088
- u(this, "scrollTimer", null);
1089
- u(this, "onTransitionFinished", (e) => {
1090
- this.target.contains(e.target) && this.mutationTimer === null && (this.cssTimer && clearTimeout(this.cssTimer), this.pendingStyles.size == 0 && (this.pendingMask |= B | _, this.cssTimer = window.setTimeout(() => {
1091
- this.isDomDirty = !0, this.cssTimer = null;
1092
- }, 50)));
1093
- });
1094
- u(this, "onWindowResize", () => {
1095
- if (!this.resizeConfig.enabled) {
1096
- this.isDomDirty = !0;
1097
- return;
1098
- }
1099
- this.isResizing || (this.isResizing = !0, this.resizeConfig.onStart && this.resizeConfig.onStart()), this.resizeTimer && clearTimeout(this.resizeTimer), this.resizeTimer = window.setTimeout(() => {
1100
- this.isDomDirty = !0, this.resizeConfig.onEnd && this.resizeConfig.onEnd(), this.isResizing = !1, this.resizeTimer = null;
1101
- }, this.resizeConfig.delay);
1102
- });
1103
- u(this, "renderLoop", () => {
1104
- if (!this.isRunning)
1105
- return;
1106
- this.isDomDirty && this.forceUpdateScene();
1107
- const e = window.scrollX, t = window.scrollY;
1108
- (e !== this.lastScrollX || t !== this.lastScrollY) && (Oe(this.renderer.fixedMeshes, e, t), this.lastScrollX = e, this.lastScrollY = t, this.scrollTimer && clearTimeout(this.scrollTimer), this.scrollTimer = window.setTimeout(() => {
1109
- this.pendingMask |= B, this.isDomDirty = !0, this.scrollTimer = null;
1110
- }, 150)), this.pendingStyles.size > 0 && (ke(this.registry, this.pendingStyles), this.pendingStyles.clear()), this.renderer.render(), requestAnimationFrame(this.renderLoop);
1111
- });
1112
- var o, n;
1113
- this.target = e, this.renderer = t, this.registry = s, this.filter = r.filter;
1114
- const a = (o = r.resizeDebounce) != null ? o : !0;
1115
- a === !1 ? this.resizeConfig = { enabled: !1, delay: 0 } : a === !0 ? this.resizeConfig = { enabled: !0, delay: 150 } : this.resizeConfig = {
1116
- enabled: !0,
1117
- delay: (n = a.delay) != null ? n : 150,
1118
- onStart: a.onStart,
1119
- onEnd: a.onEnd
1120
- }, this.observer = new MutationObserver((c) => {
1121
- let l = N;
1122
- for (const d of c)
1123
- if (d.type === "childList")
1124
- l |= V, d.removedNodes.length > 0 && d.removedNodes.forEach((f) => {
1125
- f instanceof HTMLElement && this.pendingDeletions.add(f);
1126
- });
1127
- else if (d.type === "attributes")
1128
- if (d.attributeName === "style") {
1129
- l |= B | _;
1130
- const f = d.target, h = Be(f.style);
1131
- this.pendingStyles.set(f, h);
1132
- } else
1133
- d.attributeName === "class" && (l |= B | _);
1134
- else
1135
- d.type === "characterData" && (l |= $ | B);
1136
- if (l !== N) {
1137
- if (this.pendingMask |= l, l & V) {
1138
- this.clearTimers(), this.isDomDirty = !0;
1139
- return;
1140
- }
1141
- this.mutationTimer && clearTimeout(this.mutationTimer), this.mutationTimer = window.setTimeout(() => {
1142
- this.mutationTimer = null, this.isDomDirty = !0;
1143
- }, 200);
1144
- }
1478
+ u(this, "tracker");
1479
+ this.target = e, this.renderer = t, this.registry = i, this.tracker = new Ve(e, {
1480
+ resizeDebounce: r.resizeDebounce
1481
+ }), this.tracker.onLayoutChange.add((l, o) => {
1482
+ document.querySelector(`[${O.NAME}~='${O.VALUES.TRAVELER}']`) !== null && !this.isTravelEnabled && (this.isTravelEnabled = !0, this.renderer.createRenderTarget());
1483
+ const n = Ie(
1484
+ this.target,
1485
+ l,
1486
+ P,
1487
+ 1,
1488
+ 0,
1489
+ this.renderer.qualityFactor
1490
+ );
1491
+ n && this.renderer.syncScene(n, o);
1492
+ }), this.tracker.onScrollChange.add((l, o) => {
1493
+ st(this.renderer.fixedMeshes, l, o);
1494
+ }), this.tracker.onStyleChange.add((l) => {
1495
+ it(this.registry, l);
1496
+ }), this.tracker.onRender.add(() => {
1497
+ this.renderer.render();
1145
1498
  });
1146
1499
  }
1147
1500
  start() {
1148
- this.isRunning || (this.isRunning = !0, this.observer.observe(this.target, {
1149
- childList: !0,
1150
- subtree: !0,
1151
- attributes: !0,
1152
- characterData: !0
1153
- }), this.target.addEventListener("transitionend", this.onTransitionFinished), this.target.addEventListener("animationend", this.onTransitionFinished), window.addEventListener("resize", this.onWindowResize), this.forceUpdateScene(), this.renderLoop());
1501
+ this.tracker.start();
1154
1502
  }
1155
1503
  stop() {
1156
- 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);
1157
- }
1158
- clearTimers() {
1159
- this.mutationTimer && (clearTimeout(this.mutationTimer), this.mutationTimer = null), this.cssTimer && (clearTimeout(this.cssTimer), this.cssTimer = null), this.scrollTimer && (clearTimeout(this.scrollTimer), this.scrollTimer = null);
1160
- }
1161
- forceUpdateScene() {
1162
- this.isDomDirty = !1, this.lastScrollX = window.scrollX, this.lastScrollY = window.scrollY;
1163
- const e = document.querySelector("[data-mirage-travel='traveler']") !== null;
1164
- e && !this.isTravelEnabled && (this.isTravelEnabled = !0, this.renderer.createRenderTarget());
1165
- const t = ce(
1166
- this.target,
1167
- this.pendingMask,
1168
- e ? D | X : D,
1169
- this.filter
1170
- );
1171
- t && (this.renderer.syncScene(t, this.pendingDeletions), this.pendingDeletions.clear()), this.pendingMask = N;
1504
+ this.tracker.stop();
1172
1505
  }
1173
- // [ThinkPoint] change call back pattern when after
1174
1506
  }
1175
- class Ie {
1507
+ class nt {
1176
1508
  constructor() {
1177
1509
  u(this, "store");
1178
1510
  this.store = /* @__PURE__ */ new WeakMap();
@@ -1197,30 +1529,30 @@ class Ie {
1197
1529
  this.store.delete(e);
1198
1530
  }
1199
1531
  }
1200
- class ze {
1532
+ class ht {
1201
1533
  constructor(e, t) {
1202
1534
  u(this, "renderer");
1203
1535
  u(this, "syncer");
1204
1536
  u(this, "target");
1205
1537
  u(this, "registry");
1206
- var r, a, o;
1207
- if (this.target = e, this.registry = new Ie(), !document.getElementById("mirage-engine-styles")) {
1208
- const n = document.createElement("style");
1209
- n.id = "mirage-engine-styles", n.textContent = `
1210
- [data-mirage-dom="hide"] {
1538
+ var r, l, o;
1539
+ if (this.target = e, this.registry = new nt(), !document.getElementById("mirage-engine-styles")) {
1540
+ const a = document.createElement("style");
1541
+ a.id = "mirage-engine-styles", a.textContent = `
1542
+ [${q.NAME}="${q.VALUES.HIDE}"] {
1211
1543
  opacity: 0 !important;
1212
1544
  }
1213
- `, document.head.appendChild(n);
1545
+ `, document.head.appendChild(a);
1214
1546
  }
1215
- let s;
1216
- if (t.mode === "duplicate" ? s = (a = (r = t.container) != null ? r : this.target.parentElement) != null ? a : void 0 : s = (o = this.target.parentElement) != null ? o : void 0, !s)
1547
+ let i;
1548
+ if (t.mode === "duplicate" ? i = (l = (r = t.container) != null ? r : this.target.parentElement) != null ? l : void 0 : i = (o = this.target.parentElement) != null ? o : void 0, !i)
1217
1549
  throw new Error("[Mirage] Cannot find a container (parent or option).");
1218
- this.renderer = new Me(
1550
+ this.renderer = new tt(
1219
1551
  this.target,
1220
1552
  t,
1221
- s,
1553
+ i,
1222
1554
  this.registry
1223
- ), this.renderer.mount(), this.syncer = new Fe(this.target, this.renderer, this.registry, t);
1555
+ ), this.renderer.mount(), this.syncer = new ot(this.target, this.renderer, this.registry, t);
1224
1556
  }
1225
1557
  start() {
1226
1558
  this.syncer.start();
@@ -1231,6 +1563,15 @@ class ze {
1231
1563
  dispose() {
1232
1564
  this.syncer.stop(), this.renderer.dispose();
1233
1565
  }
1566
+ getTracker() {
1567
+ return this.syncer.tracker;
1568
+ }
1569
+ updateUniforms(e, t) {
1570
+ this.renderer.updateUniforms(e, t);
1571
+ }
1572
+ getCanvas() {
1573
+ return this.renderer.canvas;
1574
+ }
1234
1575
  test() {
1235
1576
  const e = this.registry.get(
1236
1577
  document.querySelector("#box2")
@@ -1243,27 +1584,37 @@ class ze {
1243
1584
  ArrowUp: !1,
1244
1585
  ArrowDown: !1
1245
1586
  };
1246
- window.addEventListener("keydown", (a) => {
1247
- t[a.key] !== void 0 && (t[a.key] = !0);
1248
- }), window.addEventListener("keyup", (a) => {
1249
- t[a.key] !== void 0 && (t[a.key] = !1);
1587
+ window.addEventListener("keydown", (l) => {
1588
+ t[l.key] !== void 0 && (t[l.key] = !0);
1589
+ }), window.addEventListener("keyup", (l) => {
1590
+ t[l.key] !== void 0 && (t[l.key] = !1);
1250
1591
  });
1251
- const s = 2, r = () => {
1252
- requestAnimationFrame(r), t.ArrowRight && e.position.setX(e.position.x + s), t.ArrowLeft && e.position.setX(e.position.x - s), t.ArrowUp && e.position.setY(e.position.y + s), t.ArrowDown && e.position.setY(e.position.y - s);
1592
+ const i = 2, r = () => {
1593
+ requestAnimationFrame(r), t.ArrowRight && e.position.setX(e.position.x + i), t.ArrowLeft && e.position.setX(e.position.x - i), t.ArrowUp && e.position.setY(e.position.y + i), t.ArrowDown && e.position.setY(e.position.y - i);
1253
1594
  };
1254
1595
  r();
1255
1596
  }
1256
1597
  }
1257
1598
  export {
1258
- ge as ALLOWED_FILTERS,
1259
- $ as DIRTY_CONTENT,
1260
- N as DIRTY_NONE,
1261
- B as DIRTY_RECT,
1262
- V as DIRTY_STRUCTURE,
1263
- _ as DIRTY_STYLE,
1264
- fe as DIRTY_ZINDEX,
1265
- Ae as EXCLUDED,
1266
- ze as Engine,
1267
- X as SYSTEM_LAYER,
1268
- D as USER_LAYER
1599
+ Se as ALLOWED_FILTERS,
1600
+ q as ATTR_DOM,
1601
+ Y as ATTR_FILTER,
1602
+ lt as ATTR_SANDWICH,
1603
+ z as ATTR_SELECT,
1604
+ Ne as ATTR_SHADER,
1605
+ O as ATTR_TRAVEL,
1606
+ ve as DIRTY_CONTENT,
1607
+ he as DIRTY_NONE,
1608
+ j as DIRTY_RECT,
1609
+ be as DIRTY_STRUCTURE,
1610
+ ae as DIRTY_STYLE,
1611
+ Ye as DIRTY_ZINDEX,
1612
+ ct as EXCLUDED,
1613
+ ht as Engine,
1614
+ Z as SELECT_LAYER,
1615
+ A as THREE_LAYERS,
1616
+ Te as TRAVEL_VALUES,
1617
+ Ve as Tracker,
1618
+ P as USER_LAYER,
1619
+ Pe as extractFromStyle
1269
1620
  };