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