mirage-engine 0.2.16 → 0.2.17

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,55 +1,55 @@
1
- var X = Object.defineProperty;
2
- var P = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var h = (i, e, t) => (P(i, typeof e != "symbol" ? e + "" : e, t), t);
1
+ var k = Object.defineProperty;
2
+ var q = (i, e, t) => e in i ? k(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var c = (i, e, t) => (q(i, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import * as d from "three";
5
- const E = 0, O = 1, z = 2, q = 4, D = 8, _ = 16, x = 1, R = 2, k = [
5
+ const S = 0, z = 1, L = 2, Y = 4, I = 8, N = 16, x = 1, R = 2, W = [
6
6
  "include-tree",
7
7
  "exclude-tree",
8
8
  "include-self",
9
9
  "exclude-self",
10
10
  "end"
11
11
  ];
12
- function Y(i, e, t) {
12
+ function U(i, e, t) {
13
13
  const r = e.split(`
14
14
  `), s = [];
15
- return r.forEach((n) => {
16
- const a = n.split(" ");
17
- let o = a[0];
18
- for (let l = 1; l < a.length; l++) {
19
- const c = a[l];
20
- i.measureText(o + " " + c).width < t ? o += " " + c : (s.push(o), o = c);
15
+ return r.forEach((a) => {
16
+ const n = a.split(" ");
17
+ let o = n[0];
18
+ for (let l = 1; l < n.length; l++) {
19
+ const h = n[l];
20
+ i.measureText(o + " " + h).width < t ? o += " " + h : (s.push(o), o = h);
21
21
  }
22
22
  s.push(o);
23
23
  }), s;
24
24
  }
25
- function I(i, e, t, r, s = 2) {
26
- const n = document.createElement("canvas"), a = n.getContext("2d");
27
- if (!a)
25
+ function A(i, e, t, r, s = 2) {
26
+ const a = document.createElement("canvas"), n = a.getContext("2d");
27
+ if (!n)
28
28
  throw new Error("[Mirage] Failed to create canvas context");
29
29
  const l = (window.devicePixelRatio || 1) * s;
30
- n.width = t * l, n.height = r * l, a.scale(l, l), a.font = e.font, a.fillStyle = e.color, a.textBaseline = "top", a.globalAlpha = 1;
31
- const c = Y(a, i, t), g = e.lineHeight;
32
- c.forEach((p, m) => {
33
- const T = m * g + 2;
30
+ a.width = t * l, a.height = r * l, n.scale(l, l), n.font = e.font, n.fillStyle = e.color, n.textBaseline = "top", n.globalAlpha = 1;
31
+ const h = U(n, i, t), m = e.lineHeight;
32
+ h.forEach((g, p) => {
33
+ const y = p * m + 2;
34
34
  let v = 0;
35
- e.textAlign === "center" ? v = t / 2 : e.textAlign === "right" && (v = t), a.textAlign = e.textAlign, a.fillText(p, v, T);
35
+ e.textAlign === "center" ? v = t / 2 : e.textAlign === "right" && (v = t), n.textAlign = e.textAlign, n.fillText(g, v, y);
36
36
  });
37
- const u = new d.CanvasTexture(n);
38
- return u.colorSpace = d.SRGBColorSpace, u.minFilter = d.LinearFilter, u.magFilter = d.LinearFilter, u.needsUpdate = !0, u;
37
+ const f = new d.CanvasTexture(a);
38
+ return f.colorSpace = d.SRGBColorSpace, f.minFilter = d.LinearFilter, f.magFilter = d.LinearFilter, f.needsUpdate = !0, f;
39
39
  }
40
40
  function w(i) {
41
41
  return typeof i == "number" ? i : parseFloat(i) || 0;
42
42
  }
43
- function N(i, e) {
44
- var o, l, c, g;
43
+ function X(i, e) {
44
+ var o, l, h, m;
45
45
  if (!e) {
46
46
  i.set(0, 0, 0, 0);
47
47
  return;
48
48
  }
49
- const t = e.split("/")[0].trim().split(/\s+/), r = w(t[0]), s = w((o = t[1]) != null ? o : t[0]), n = w((l = t[2]) != null ? l : t[0]), a = w((g = (c = t[3]) != null ? c : t[1]) != null ? g : t[0]);
50
- i.set(r, s, n, a);
49
+ const t = e.split("/")[0].trim().split(/\s+/), r = w(t[0]), s = w((o = t[1]) != null ? o : t[0]), a = w((l = t[2]) != null ? l : t[0]), n = w((m = (h = t[3]) != null ? h : t[1]) != null ? m : t[0]);
50
+ i.set(r, s, a, n);
51
51
  }
52
- const U = (
52
+ const H = (
53
53
  /* glsl */
54
54
  `
55
55
  varying vec2 vUv;
@@ -60,7 +60,7 @@ const U = (
60
60
  vScreenPos = gl_Position;
61
61
  }
62
62
  `
63
- ), W = (
63
+ ), $ = (
64
64
  /* glsl */
65
65
  `
66
66
 
@@ -130,77 +130,77 @@ const U = (
130
130
  }
131
131
  `
132
132
  );
133
- function S(i) {
133
+ function E(i) {
134
134
  if (!i || i === "transparent")
135
135
  return { color: new d.Color(16777215), alpha: 0 };
136
136
  const e = i.match(
137
137
  /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/
138
138
  );
139
139
  if (e) {
140
- const t = parseInt(e[1], 10), r = parseInt(e[2], 10), s = parseInt(e[3], 10), n = e[4] !== void 0 ? parseFloat(e[4]) : 1;
141
- return { color: new d.Color(`rgb(${t}, ${r}, ${s})`), alpha: n };
140
+ const t = parseInt(e[1], 10), r = parseInt(e[2], 10), s = parseInt(e[3], 10), a = e[4] !== void 0 ? parseFloat(e[4]) : 1;
141
+ return { color: new d.Color(`rgb(${t}, ${r}, ${s})`), alpha: a };
142
142
  }
143
143
  return { color: new d.Color(i), alpha: 1 };
144
144
  }
145
- function H(i, e, t, r = null, s) {
145
+ function G(i, e, t, r = null, s) {
146
146
  var v;
147
- const n = r !== null, a = n ? (
147
+ const a = r !== null, n = a ? (
148
148
  /* glsl */
149
149
  `
150
150
  uniform sampler2D uTexture;
151
151
  varying vec4 vScreenPos;
152
152
  `
153
- ) : "", o = n ? (
153
+ ) : "", o = a ? (
154
154
  /* glsl */
155
155
  `
156
156
  vec2 screenUv = (vScreenPos.xy / vScreenPos.w) * 0.5 + 0.5;
157
157
  vec2 resultUv = screenUv;
158
158
  ${(s == null ? void 0 : s.uvModifier) || ""}
159
159
  `
160
- ) : "", l = n ? (
160
+ ) : "", l = a ? (
161
161
  /* glsl */
162
162
  `
163
163
  baseColor = texture2D(uTexture, resultUv);
164
164
  `
165
- ) : "", c = (s == null ? void 0 : s.colorModifier) || "", g = W.replace("#INJECT_DECLARATIONS", a).replace("#INJECT_UV_MODIFIER", o).replace("#INJECT_BASE_COLOR", l).replace("#INJECT_COLOR_MODIFIER", c), u = S(i.backgroundColor), p = S(i.borderColor), m = {
165
+ ) : "", h = (s == null ? void 0 : s.colorModifier) || "", m = $.replace("#INJECT_DECLARATIONS", n).replace("#INJECT_UV_MODIFIER", o).replace("#INJECT_BASE_COLOR", l).replace("#INJECT_COLOR_MODIFIER", h), f = E(i.backgroundColor), g = E(i.borderColor), p = {
166
166
  uSize: { value: new d.Vector2(e, t) },
167
167
  uBorderRadius: { value: new d.Vector4(0, 0, 0, 0) },
168
168
  uBorderWidth: { value: w(i.borderWidth) },
169
- uBgColor: { value: u.color },
170
- uBorderColor: { value: p.color },
169
+ uBgColor: { value: f.color },
170
+ uBorderColor: { value: g.color },
171
171
  uOpacity: { value: (v = i.opacity) != null ? v : 1 },
172
- uBgOpacity: { value: u.alpha },
173
- uBorderOpacity: { value: p.alpha },
172
+ uBgOpacity: { value: f.alpha },
173
+ uBorderOpacity: { value: g.alpha },
174
174
  uTexture: { value: null }
175
175
  };
176
- return N(m.uBorderRadius.value, i.borderRadius), n && (m.uTexture.value = r), new d.ShaderMaterial({
177
- uniforms: m,
178
- vertexShader: U,
179
- fragmentShader: g,
176
+ return X(p.uBorderRadius.value, i.borderRadius), a && (p.uTexture.value = r), new d.ShaderMaterial({
177
+ uniforms: p,
178
+ vertexShader: H,
179
+ fragmentShader: m,
180
180
  transparent: !0,
181
181
  side: d.FrontSide
182
182
  // for better performance
183
183
  });
184
184
  }
185
- function $(i, e, t, r, s) {
185
+ function J(i, e, t, r, s) {
186
186
  var o;
187
- const n = S(e.backgroundColor), a = S(e.borderColor);
188
- i.uniforms.uSize.value.set(t, r), N(i.uniforms.uBorderRadius.value, e.borderRadius), i.uniforms.uBorderWidth.value = w(e.borderWidth), i.uniforms.uBgColor.value.copy(n.color), i.uniforms.uBorderColor.value.copy(a.color), i.uniforms.uOpacity.value = (o = e.opacity) != null ? o : 1, i.uniforms.uBgOpacity.value = n.alpha, i.uniforms.uBorderOpacity.value = a.alpha, i.uniforms.uTexture && s !== void 0 && (i.uniforms.uTexture.value = s);
187
+ const a = E(e.backgroundColor), n = E(e.borderColor);
188
+ i.uniforms.uSize.value.set(t, r), X(i.uniforms.uBorderRadius.value, e.borderRadius), i.uniforms.uBorderWidth.value = w(e.borderWidth), i.uniforms.uBgColor.value.copy(a.color), i.uniforms.uBorderColor.value.copy(n.color), i.uniforms.uOpacity.value = (o = e.opacity) != null ? o : 1, i.uniforms.uBgOpacity.value = a.alpha, i.uniforms.uBorderOpacity.value = n.alpha, i.uniforms.uTexture && s !== void 0 && (i.uniforms.uTexture.value = s);
189
189
  }
190
- const F = {
191
- create(i, e, t, r, s, n = 2, a = null) {
190
+ const D = {
191
+ create(i, e, t, r, s, a = 2, n = null, o) {
192
192
  if (i === "BOX")
193
- return H(e, r, s, a);
193
+ return G(e, r, s, n, o);
194
194
  if (i === "TEXT") {
195
- const o = I(
195
+ const l = A(
196
196
  t || "",
197
197
  e,
198
198
  r,
199
199
  s,
200
- n
200
+ a
201
201
  );
202
202
  return new d.MeshBasicMaterial({
203
- map: o,
203
+ map: l,
204
204
  transparent: !0,
205
205
  side: d.FrontSide,
206
206
  color: 16777215
@@ -208,51 +208,52 @@ const F = {
208
208
  }
209
209
  return new d.MeshBasicMaterial({ visible: !1 });
210
210
  },
211
- update(i, e, t, r, s, n, a = 2, o) {
211
+ update(i, e, t, r, s, a, n = 2, o) {
212
212
  if (e === "BOX")
213
- $(
213
+ J(
214
214
  i,
215
215
  t,
216
216
  s,
217
- n,
217
+ a,
218
218
  o
219
219
  );
220
220
  else if (e === "TEXT") {
221
221
  const l = i;
222
222
  l.map && l.map.dispose();
223
- const c = I(
223
+ const h = A(
224
224
  r || "",
225
225
  t,
226
226
  s,
227
- n,
228
- a
227
+ a,
228
+ n
229
229
  );
230
- l.map = c, l.needsUpdate = !0;
230
+ l.map = h, l.needsUpdate = !0;
231
231
  }
232
232
  }
233
233
  };
234
- class G {
234
+ class V {
235
235
  constructor(e, t, r) {
236
- h(this, "canvas");
237
- h(this, "scene");
238
- h(this, "camera");
239
- h(this, "renderer");
240
- h(this, "renderTarget", null);
241
- h(this, "renderOrder", 0);
242
- h(this, "qualityFactor", 2);
243
- h(this, "mode", "overlay");
244
- h(this, "target");
245
- h(this, "mountContainer");
246
- h(this, "targetRect");
247
- h(this, "meshMap", /* @__PURE__ */ new Map());
248
- var a, o;
249
- this.target = e, this.mountContainer = r, this.mode = (a = t.mode) != null ? a : "overlay", this.canvas = document.createElement("canvas"), this.scene = new d.Scene(), this.targetRect = this.target.getBoundingClientRect();
250
- const s = this.targetRect.width, n = this.targetRect.height;
236
+ c(this, "canvas");
237
+ c(this, "scene");
238
+ c(this, "camera");
239
+ c(this, "renderer");
240
+ c(this, "renderTarget", null);
241
+ c(this, "renderOrder", 0);
242
+ c(this, "qualityFactor", 2);
243
+ c(this, "mode", "overlay");
244
+ c(this, "clipArea", 1);
245
+ c(this, "target");
246
+ c(this, "mountContainer");
247
+ c(this, "targetRect");
248
+ c(this, "meshMap", /* @__PURE__ */ new Map());
249
+ var n, o, l;
250
+ this.target = e, this.mountContainer = r, this.mode = (n = t.mode) != null ? n : "overlay", this.clipArea = (o = t.travelerClipArea) != null ? o : 1, this.canvas = document.createElement("canvas"), this.scene = new d.Scene(), this.targetRect = this.target.getBoundingClientRect();
251
+ const s = this.targetRect.width, a = this.targetRect.height;
251
252
  this.camera = new d.OrthographicCamera(
252
253
  s / -2,
253
254
  s / 2,
254
- n / 2,
255
- n / -2,
255
+ a / 2,
256
+ a / -2,
256
257
  1,
257
258
  1e3
258
259
  ), this.camera.position.z = 100, this.camera.layers.set(0), this.renderer = new d.WebGLRenderer({
@@ -261,7 +262,7 @@ class G {
261
262
  antialias: !0
262
263
  // [new]
263
264
  // premultipliedAlpha: true
264
- }), this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setSize(s, n), this.applyTextQuality((o = t.quality) != null ? o : "medium");
265
+ }), this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setSize(s, a), this.applyTextQuality((l = t.quality) != null ? l : "medium");
265
266
  }
266
267
  createRenderTarget() {
267
268
  this.renderTarget = new d.WebGLRenderTarget(
@@ -313,69 +314,70 @@ class G {
313
314
  syncScene(e) {
314
315
  const t = this.target.getBoundingClientRect(), r = Math.abs(t.width - this.targetRect.width) > 0.1 || Math.abs(t.height - this.targetRect.height) > 0.1, s = this.mode === "overlay" && (Math.abs(t.top - this.targetRect.top) > 0.1 || Math.abs(t.left - this.targetRect.left) > 0.1);
315
316
  r ? (this.targetRect = t, this.setSize(this.targetRect.width, this.targetRect.height), this.updateCanvasLayout()) : s ? (this.targetRect = t, this.updateCanvasLayout()) : this.targetRect = t, this.renderOrder = 0;
316
- const n = /* @__PURE__ */ new Set();
317
- this.reconcileNode(e, n);
318
- for (const [a, o] of this.meshMap.entries())
319
- n.has(a) || (this.scene.remove(o), o.geometry.dispose(), o.material instanceof d.Material && o.material.dispose(), this.meshMap.delete(a));
317
+ const a = /* @__PURE__ */ new Set();
318
+ this.reconcileNode(e, a);
319
+ for (const [n, o] of this.meshMap.entries())
320
+ a.has(n) || (this.scene.remove(o), o.geometry.dispose(), o.material instanceof d.Material && o.material.dispose(), this.meshMap.delete(n));
320
321
  }
321
322
  reconcileNode(e, t) {
322
323
  var s;
323
324
  t.add(e.element);
324
325
  let r = this.meshMap.get(e.element);
325
326
  if (!r) {
326
- const n = new d.PlaneGeometry(1, 1);
327
- let a;
328
- a = F.create(
327
+ const a = new d.PlaneGeometry(1, 1);
328
+ let n;
329
+ n = D.create(
329
330
  "BOX",
330
331
  e.styles,
331
332
  "",
332
333
  e.rect.width,
333
334
  e.rect.height,
334
335
  this.qualityFactor,
335
- e.isTraveler ? (s = this.renderTarget) == null ? void 0 : s.texture : void 0
336
- ), r = new d.Mesh(n, a), e.type === "TEXT" && (r.name = "BG_MESH"), this.scene.add(r), this.meshMap.set(e.element, r);
336
+ e.isTraveler ? (s = this.renderTarget) == null ? void 0 : s.texture : void 0,
337
+ e.shaderHooks
338
+ ), r = new d.Mesh(a, n), e.type === "TEXT" && (r.name = "BG_MESH"), this.scene.add(r), this.meshMap.set(e.element, r);
337
339
  }
338
340
  if (r.userData.domRect = e.rect, this.updateMeshProperties(r, e), this.updateMeshLayers(r, e), e.isTraveler && r.layers.enable(28), e.type === "BOX")
339
- for (const n of e.children)
340
- this.reconcileNode(n, t);
341
+ for (const a of e.children)
342
+ this.reconcileNode(a, t);
341
343
  else
342
344
  e.type === "TEXT" && this.reconcileTextChild(r, e);
343
345
  }
344
346
  reconcileTextChild(e, t) {
345
347
  var o, l;
346
348
  let r = e.children.find(
347
- (c) => c.name === "TEXT_CHILD"
349
+ (h) => h.name === "TEXT_CHILD"
348
350
  );
349
- const s = JSON.stringify(t.textStyles), n = (o = r == null ? void 0 : r.userData) == null ? void 0 : o.styleHash;
350
- if (!r || t.dirtyMask & _ || s !== n) {
351
+ const s = JSON.stringify(t.textStyles), a = (o = r == null ? void 0 : r.userData) == null ? void 0 : o.styleHash;
352
+ if (!r || t.dirtyMask & N || s !== a) {
351
353
  r && ((l = r.material.map) == null || l.dispose(), r.geometry.dispose(), e.remove(r));
352
- const c = F.create(
354
+ const h = D.create(
353
355
  "TEXT",
354
356
  t.textStyles,
355
357
  t.textContent || "",
356
358
  t.rect.width,
357
359
  t.rect.height,
358
360
  this.qualityFactor
359
- ), g = new d.PlaneGeometry(1, 1);
360
- r = new d.Mesh(g, c), r.name = "TEXT_CHILD", r.userData = { styleHash: s }, this.updateMeshLayers(r, t), r.position.z = 5e-3, e.add(r);
361
+ ), m = new d.PlaneGeometry(1, 1);
362
+ r = new d.Mesh(m, h), r.name = "TEXT_CHILD", r.userData = { styleHash: s }, this.updateMeshLayers(r, t), r.position.z = 5e-3, e.add(r);
361
363
  }
362
364
  if (r) {
363
- const c = e.userData.domRect, g = c.x + c.width / 2, u = c.y + c.height / 2, p = t.rect.x + t.rect.width / 2, m = t.rect.y + t.rect.height / 2, T = p - g, v = -(m - u);
364
- r.position.set(T, v, 5e-3);
365
+ const h = e.userData.domRect, m = h.x + h.width / 2, f = h.y + h.height / 2, g = t.rect.x + t.rect.width / 2, p = t.rect.y + t.rect.height / 2, y = g - m, v = -(p - f);
366
+ r.position.set(y, v, 5e-3);
365
367
  }
366
368
  }
367
369
  updateMeshProperties(e, t) {
368
- var m;
369
- const { rect: r, styles: s } = t, n = this.renderer.getPixelRatio(), a = this.renderer.domElement.width / n, o = this.renderer.domElement.height / n;
370
+ var p;
371
+ const { rect: r, styles: s } = t, a = this.renderer.getPixelRatio(), n = this.renderer.domElement.width / a, o = this.renderer.domElement.height / a;
370
372
  e.scale.set(r.width, r.height, 1);
371
373
  const l = 1e-3;
372
374
  this.renderOrder++;
373
- const c = this.targetRect.left + window.scrollX, g = this.targetRect.top + window.scrollY, u = r.x - c, p = r.y - g;
375
+ const h = this.targetRect.left + window.scrollX, m = this.targetRect.top + window.scrollY, f = r.x - h, g = r.y - m;
374
376
  e.position.set(
375
- u - a / 2 + r.width / 2,
376
- -p + o / 2 - r.height / 2,
377
+ f - n / 2 + r.width / 2,
378
+ -g + o / 2 - r.height / 2,
377
379
  s.zIndex + this.renderOrder * l
378
- ), F.update(
380
+ ), D.update(
379
381
  e.material,
380
382
  "BOX",
381
383
  t.styles,
@@ -383,7 +385,7 @@ class G {
383
385
  t.rect.width,
384
386
  t.rect.height,
385
387
  this.qualityFactor,
386
- t.isTraveler ? (m = this.renderTarget) == null ? void 0 : m.texture : void 0
388
+ t.isTraveler ? (p = this.renderTarget) == null ? void 0 : p.texture : void 0
387
389
  );
388
390
  }
389
391
  updateMeshLayers(e, t) {
@@ -398,11 +400,14 @@ class G {
398
400
  return;
399
401
  const t = new d.Color(), r = this.renderer.getClearAlpha();
400
402
  this.renderer.getClearColor(t), 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);
401
- const s = new d.Vector3(), n = this.targetRect.width, a = this.targetRect.height, o = this.renderer.getPixelRatio();
403
+ const s = new d.Vector3(), a = this.targetRect.width, n = this.targetRect.height, o = this.renderer.getPixelRatio();
402
404
  for (const l of e) {
403
405
  s.setFromMatrixPosition(l.matrixWorld), s.project(this.camera);
404
- const c = (s.x + 1) / 2 * n, g = (s.y + 1) / 2 * a, u = l.scale.x, p = l.scale.y, m = c - u / 2, T = g - p / 2, v = m * this.qualityFactor / o, B = T * this.qualityFactor / o, b = u * this.qualityFactor / o, f = p * this.qualityFactor / o;
405
- this.renderer.setScissor(v, B, b, f), this.renderer.render(this.scene, this.camera);
406
+ const h = (s.x + 1) / 2 * a, m = (s.y + 1) / 2 * n;
407
+ let f = 0, g = 1;
408
+ typeof this.clipArea == "number" ? g = this.clipArea : this.clipArea.endsWith("%") ? g = parseFloat(this.clipArea) / 100 : this.clipArea.endsWith("px") && (f = parseFloat(this.clipArea));
409
+ const p = l.scale.x * g + 0.5, y = l.scale.y * g + 0.5, v = h - p / 2, B = m - y / 2, M = (v * this.qualityFactor - f) / o, F = (B * this.qualityFactor - f) / o, b = (p * this.qualityFactor + f * 2) / o, u = (y * this.qualityFactor + f * 2) / o;
410
+ this.renderer.setScissor(M, F, b, u), this.renderer.render(this.scene, this.camera);
406
411
  }
407
412
  this.renderer.setScissorTest(!1), this.renderer.autoClear = !0, this.renderer.setRenderTarget(null), this.camera.layers.set(28), this.renderer.setClearColor(t, r);
408
413
  }
@@ -418,11 +423,11 @@ class G {
418
423
  side: d.DoubleSide,
419
424
  transparent: !0,
420
425
  opacity: 0.8
421
- }), n = new d.Mesh(r, s);
422
- n.position.set(0, 0, 90), n.layers.set(28), this.scene.add(n);
426
+ }), a = new d.Mesh(r, s);
427
+ a.position.set(0, 0, 90), a.layers.set(28), this.scene.add(a);
423
428
  }
424
429
  }
425
- function J(i) {
430
+ function j(i) {
426
431
  const e = document.createRange();
427
432
  e.selectNodeContents(i);
428
433
  const t = e.getBoundingClientRect();
@@ -433,7 +438,7 @@ function J(i) {
433
438
  height: t.height
434
439
  };
435
440
  }
436
- function V(i) {
441
+ function Q(i) {
437
442
  const e = parseFloat(i.fontSize);
438
443
  let t = parseFloat(i.lineHeight);
439
444
  isNaN(t) && (t = e * 1.2);
@@ -448,93 +453,96 @@ function V(i) {
448
453
  letterSpacing: r
449
454
  };
450
455
  }
451
- function A(i, e = O | z | q | _ | D, t, r) {
456
+ function P(i, e = z | L | Y | N | I, t, r) {
452
457
  if (i.nodeType === Node.TEXT_NODE) {
453
- const f = i;
454
- if (!f.textContent || !f.textContent.trim())
458
+ const u = i;
459
+ if (!u.textContent || !u.textContent.trim())
455
460
  return null;
456
- const C = f.textContent.replace(/\s+/g, " ").trim();
461
+ const C = u.textContent.replace(/\s+/g, " ").trim();
457
462
  if (C.length === 0)
458
463
  return null;
459
- const y = J(f);
460
- if (y.width === 0 || y.height === 0)
464
+ const T = j(u);
465
+ if (T.width === 0 || T.height === 0)
461
466
  return null;
462
- const L = f.parentElement, M = L ? window.getComputedStyle(L) : null;
463
- return M ? {
467
+ const _ = u.parentElement, O = _ ? window.getComputedStyle(_) : null;
468
+ return O ? {
464
469
  id: Math.random().toString(36).substring(2, 9),
465
470
  type: "TEXT",
466
- element: f,
471
+ element: u,
467
472
  rect: {
468
- x: y.left + window.scrollX,
469
- y: y.top + window.scrollY,
470
- width: y.width,
471
- height: y.height
473
+ x: T.left + window.scrollX,
474
+ y: T.top + window.scrollY,
475
+ width: T.width,
476
+ height: T.height
472
477
  },
473
478
  styles: {
474
479
  backgroundColor: "transparent",
475
- opacity: parseFloat(M.opacity),
480
+ opacity: parseFloat(O.opacity),
476
481
  zIndex: 0,
477
482
  borderRadius: "0px",
478
483
  borderColor: "transparent",
479
484
  borderWidth: "0px"
480
485
  },
481
486
  textContent: C,
482
- textStyles: V(M),
487
+ textStyles: Q(O),
483
488
  dirtyMask: e,
484
489
  visibility: t,
485
490
  isTraveler: !1,
486
491
  children: []
487
492
  } : null;
488
493
  }
489
- const s = i, n = s.dataset.mirageFilter;
490
- let a = t, o = t;
491
- if (n) {
492
- const f = new Set(n.split(/\s+/));
493
- for (const C of f)
494
- if (!k.includes(C))
494
+ const s = i, a = s.dataset.mirageFilter;
495
+ let n = t, o = t;
496
+ if (a) {
497
+ const u = new Set(a.split(/\s+/));
498
+ for (const C of u)
499
+ if (!W.includes(C))
495
500
  throw new Error(
496
501
  `[MirageEngine] Invalid filter token: '${C}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`
497
502
  );
498
- if (f.has("end"))
503
+ if (u.has("end"))
499
504
  return null;
500
- if (f.has("include-tree") && f.has("exclude-tree"))
505
+ if (u.has("include-tree") && u.has("exclude-tree"))
501
506
  throw new Error(
502
507
  "[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element."
503
508
  );
504
- if (f.has("include-self") && f.has("exclude-self"))
509
+ if (u.has("include-self") && u.has("exclude-self"))
505
510
  throw new Error(
506
511
  "[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element."
507
512
  );
508
- f.has("include-tree") ? a = a | x : f.has("exclude-tree") && (a = a & ~x), o = a, f.has("include-self") ? o = o | x : f.has("exclude-self") && (o = o & ~x);
513
+ u.has("include-tree") ? n = n | x : u.has("exclude-tree") && (n = n & ~x), o = n, u.has("include-self") ? o = o | x : u.has("exclude-self") && (o = o & ~x);
509
514
  }
510
515
  o = o | t & R;
511
516
  const l = s.dataset.mirageTravel;
512
- let c = !1;
513
- l && new Set(l.split(/\s+/)).has("traveler") && (o = o & ~R, a = a & ~R, c = !0);
514
- const g = s.getBoundingClientRect(), u = window.getComputedStyle(s);
515
- if (g.width === 0 || g.height === 0 || u.display === "none")
517
+ let h = !1;
518
+ l && new Set(l.split(/\s+/)).has("traveler") && (o = o & ~R, n = n & ~R, h = !0);
519
+ const m = s.dataset.mirageShader;
520
+ let f;
521
+ m && (f = JSON.parse(m));
522
+ const g = s.getBoundingClientRect(), p = window.getComputedStyle(s);
523
+ if (g.width === 0 || g.height === 0 || p.display === "none")
516
524
  return null;
517
- let p = s.getAttribute("data-mid");
518
- p || (p = Math.random().toString(36).substring(2, 11), s.setAttribute("data-mid", p));
519
- const m = parseInt(u.zIndex), T = {
520
- backgroundColor: u.backgroundColor,
521
- opacity: parseFloat(u.opacity),
522
- zIndex: isNaN(m) ? 0 : m,
523
- borderRadius: u.borderRadius,
524
- borderColor: u.borderColor,
525
- borderWidth: u.borderWidth
525
+ let y = s.getAttribute("data-mid");
526
+ y || (y = Math.random().toString(36).substring(2, 11), s.setAttribute("data-mid", y));
527
+ const v = parseInt(p.zIndex), B = {
528
+ backgroundColor: p.backgroundColor,
529
+ opacity: parseFloat(p.opacity),
530
+ zIndex: isNaN(v) ? 0 : v,
531
+ borderRadius: p.borderRadius,
532
+ borderColor: p.borderColor,
533
+ borderWidth: p.borderWidth
526
534
  };
527
- let v, B;
535
+ let M, F;
528
536
  const b = [];
529
- return Array.from(s.childNodes).forEach((f) => {
530
- const C = f.nodeType === Node.TEXT_NODE ? o : a, y = A(
531
- f,
537
+ return Array.from(s.childNodes).forEach((u) => {
538
+ const C = u.nodeType === Node.TEXT_NODE ? o : n, T = P(
539
+ u,
532
540
  e,
533
541
  C
534
542
  );
535
- y && b.push(y);
543
+ T && b.push(T);
536
544
  }), {
537
- id: p,
545
+ id: y,
538
546
  type: "BOX",
539
547
  element: s,
540
548
  rect: {
@@ -543,36 +551,37 @@ function A(i, e = O | z | q | _ | D, t, r) {
543
551
  width: g.width,
544
552
  height: g.height
545
553
  },
546
- styles: T,
547
- textContent: v,
548
- textStyles: B,
554
+ styles: B,
555
+ textContent: M,
556
+ textStyles: F,
549
557
  dirtyMask: e,
550
558
  visibility: o,
551
- isTraveler: c,
552
- children: b
559
+ isTraveler: h,
560
+ children: b,
561
+ shaderHooks: f
553
562
  };
554
563
  }
555
- class j {
564
+ class Z {
556
565
  constructor(e, t, r) {
557
- h(this, "target");
558
- h(this, "renderer");
559
- h(this, "filter");
560
- h(this, "observer");
561
- h(this, "isDomDirty", !1);
562
- h(this, "isRunning", !1);
563
- h(this, "isTravelEnabled", !1);
564
- h(this, "pendingMask", E);
565
- h(this, "mutationTimer", null);
566
- h(this, "cssTimer", null);
567
- h(this, "resizeConfig");
568
- h(this, "resizeTimer", null);
569
- h(this, "isResizing", !1);
570
- h(this, "onTransitionFinished", (e) => {
571
- this.target.contains(e.target) && this.mutationTimer === null && (this.cssTimer && clearTimeout(this.cssTimer), this.pendingMask |= O | z, this.cssTimer = window.setTimeout(() => {
566
+ c(this, "target");
567
+ c(this, "renderer");
568
+ c(this, "filter");
569
+ c(this, "observer");
570
+ c(this, "isDomDirty", !1);
571
+ c(this, "isRunning", !1);
572
+ c(this, "isTravelEnabled", !1);
573
+ c(this, "pendingMask", S);
574
+ c(this, "mutationTimer", null);
575
+ c(this, "cssTimer", null);
576
+ c(this, "resizeConfig");
577
+ c(this, "resizeTimer", null);
578
+ c(this, "isResizing", !1);
579
+ c(this, "onTransitionFinished", (e) => {
580
+ this.target.contains(e.target) && this.mutationTimer === null && (this.cssTimer && clearTimeout(this.cssTimer), this.pendingMask |= z | L, this.cssTimer = window.setTimeout(() => {
572
581
  this.isDomDirty = !0, this.cssTimer = null;
573
582
  }, 50));
574
583
  });
575
- h(this, "onWindowResize", () => {
584
+ c(this, "onWindowResize", () => {
576
585
  if (!this.resizeConfig.enabled) {
577
586
  this.isDomDirty = !0;
578
587
  return;
@@ -581,23 +590,23 @@ class j {
581
590
  this.isDomDirty = !0, this.resizeConfig.onEnd && this.resizeConfig.onEnd(), this.isResizing = !1, this.resizeTimer = null;
582
591
  }, this.resizeConfig.delay);
583
592
  });
584
- h(this, "renderLoop", () => {
593
+ c(this, "renderLoop", () => {
585
594
  this.isRunning && (this.isDomDirty && this.forceUpdateScene(), this.renderer.render(), requestAnimationFrame(this.renderLoop));
586
595
  });
587
- var n, a;
596
+ var a, n;
588
597
  this.target = e, this.renderer = t, this.filter = r.filter;
589
- const s = (n = r.resizeDebounce) != null ? n : !0;
598
+ const s = (a = r.resizeDebounce) != null ? a : !0;
590
599
  s === !1 ? this.resizeConfig = { enabled: !1, delay: 0 } : s === !0 ? this.resizeConfig = { enabled: !0, delay: 150 } : this.resizeConfig = {
591
600
  enabled: !0,
592
- delay: (a = s.delay) != null ? a : 150,
601
+ delay: (n = s.delay) != null ? n : 150,
593
602
  onStart: s.onStart,
594
603
  onEnd: s.onEnd
595
604
  }, this.observer = new MutationObserver((o) => {
596
- let l = E;
597
- for (const c of o)
598
- c.type === "childList" ? l |= D : c.type === "attributes" && (c.attributeName === "style" || c.attributeName === "class") && (l |= O | z);
599
- if (l !== E) {
600
- if (this.pendingMask |= l, l & D) {
605
+ let l = S;
606
+ for (const h of o)
607
+ h.type === "childList" ? l |= I : h.type === "attributes" && (h.attributeName === "style" || h.attributeName === "class") && (l |= z | L);
608
+ if (l !== S) {
609
+ if (this.pendingMask |= l, l & I) {
601
610
  this.clearTimers(), console.log("Structural Change detected"), this.isDomDirty = !0;
602
611
  return;
603
612
  }
@@ -625,26 +634,26 @@ class j {
625
634
  this.isDomDirty = !1;
626
635
  const e = document.querySelector("[data-mirage-travel='traveler']") !== null;
627
636
  e && !this.isTravelEnabled && (this.isTravelEnabled = !0, this.renderer.createRenderTarget());
628
- const t = A(
637
+ const t = P(
629
638
  this.target,
630
639
  this.pendingMask,
631
640
  e ? x | R : x,
632
641
  this.filter
633
642
  );
634
- t && this.renderer.syncScene(t), this.pendingMask = E;
643
+ t && this.renderer.syncScene(t), this.pendingMask = S;
635
644
  }
636
645
  }
637
- class Q {
646
+ class K {
638
647
  constructor(e, t) {
639
- h(this, "renderer");
640
- h(this, "syncer");
641
- h(this, "target");
642
- var s, n, a;
648
+ c(this, "renderer");
649
+ c(this, "syncer");
650
+ c(this, "target");
651
+ var s, a, n;
643
652
  this.target = e;
644
653
  let r;
645
- if (t.mode === "duplicate" ? r = (n = (s = t.container) != null ? s : this.target.parentElement) != null ? n : void 0 : r = (a = this.target.parentElement) != null ? a : void 0, !r)
654
+ if (t.mode === "duplicate" ? r = (a = (s = t.container) != null ? s : this.target.parentElement) != null ? a : void 0 : r = (n = this.target.parentElement) != null ? n : void 0, !r)
646
655
  throw new Error("[Mirage] Cannot find a container (parent or option).");
647
- this.renderer = new G(this.target, t, r), this.renderer.mount(), this.syncer = new j(this.target, this.renderer, t);
656
+ this.renderer = new V(this.target, t, r), this.renderer.mount(), this.syncer = new Z(this.target, this.renderer, t);
648
657
  }
649
658
  start() {
650
659
  this.syncer.start();
@@ -656,12 +665,12 @@ class Q {
656
665
  this.syncer.stop(), this.renderer.dispose();
657
666
  }
658
667
  }
659
- class K {
668
+ class te {
660
669
  constructor(e, t) {
661
- h(this, "_engine");
670
+ c(this, "_engine");
662
671
  if (!e)
663
672
  throw new Error("[Mirage] Target element is required.");
664
- this._engine = new Q(e, t);
673
+ this._engine = new K(e, t);
665
674
  }
666
675
  start() {
667
676
  this._engine.start();
@@ -674,5 +683,5 @@ class K {
674
683
  }
675
684
  }
676
685
  export {
677
- K as Mirage
686
+ te as Mirage
678
687
  };
@@ -1,5 +1,5 @@
1
- (function(v,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],y):(v=typeof globalThis!="undefined"?globalThis:v||self,y(v.MirageEngine={},v.THREE))})(this,function(v,y){"use strict";var ee=Object.defineProperty;var te=(v,y,b)=>y in v?ee(v,y,{enumerable:!0,configurable:!0,writable:!0,value:b}):v[y]=b;var h=(v,y,b)=>(te(v,typeof y!="symbol"?y+"":y,b),b);function b(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const d=b(y),M=0,F=1,z=2,k=4,D=8,N=16,C=1,E=2,Y=["include-tree","exclude-tree","include-self","exclude-self","end"];function U(i,e,t){const r=e.split(`
2
- `),s=[];return r.forEach(n=>{const a=n.split(" ");let o=a[0];for(let l=1;l<a.length;l++){const c=a[l];i.measureText(o+" "+c).width<t?o+=" "+c:(s.push(o),o=c)}s.push(o)}),s}function A(i,e,t,r,s=2){const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)throw new Error("[Mirage] Failed to create canvas context");const l=(window.devicePixelRatio||1)*s;n.width=t*l,n.height=r*l,a.scale(l,l),a.font=e.font,a.fillStyle=e.color,a.textBaseline="top",a.globalAlpha=1;const c=U(a,i,t),g=e.lineHeight;c.forEach((p,m)=>{const w=m*g+2;let T=0;e.textAlign==="center"?T=t/2:e.textAlign==="right"&&(T=t),a.textAlign=e.textAlign,a.fillText(p,T,w)});const u=new d.CanvasTexture(n);return u.colorSpace=d.SRGBColorSpace,u.minFilter=d.LinearFilter,u.magFilter=d.LinearFilter,u.needsUpdate=!0,u}function S(i){return typeof i=="number"?i:parseFloat(i)||0}function X(i,e){var o,l,c,g;if(!e){i.set(0,0,0,0);return}const t=e.split("/")[0].trim().split(/\s+/),r=S(t[0]),s=S((o=t[1])!=null?o:t[0]),n=S((l=t[2])!=null?l:t[0]),a=S((g=(c=t[3])!=null?c:t[1])!=null?g:t[0]);i.set(r,s,n,a)}const W=`
1
+ (function(v,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],y):(v=typeof globalThis!="undefined"?globalThis:v||self,y(v.MirageEngine={},v.THREE))})(this,function(v,y){"use strict";var re=Object.defineProperty;var ie=(v,y,b)=>y in v?re(v,y,{enumerable:!0,configurable:!0,writable:!0,value:b}):v[y]=b;var c=(v,y,b)=>(ie(v,typeof y!="symbol"?y+"":y,b),b);function b(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const d=b(y),M=0,F=1,D=2,W=4,z=8,X=16,w=1,E=2,H=["include-tree","exclude-tree","include-self","exclude-self","end"];function U(i,e,t){const r=e.split(`
2
+ `),s=[];return r.forEach(n=>{const a=n.split(" ");let o=a[0];for(let l=1;l<a.length;l++){const h=a[l];i.measureText(o+" "+h).width<t?o+=" "+h:(s.push(o),o=h)}s.push(o)}),s}function P(i,e,t,r,s=2){const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)throw new Error("[Mirage] Failed to create canvas context");const l=(window.devicePixelRatio||1)*s;n.width=t*l,n.height=r*l,a.scale(l,l),a.font=e.font,a.fillStyle=e.color,a.textBaseline="top",a.globalAlpha=1;const h=U(a,i,t),m=e.lineHeight;h.forEach((g,p)=>{const x=p*m+2;let T=0;e.textAlign==="center"?T=t/2:e.textAlign==="right"&&(T=t),a.textAlign=e.textAlign,a.fillText(g,T,x)});const f=new d.CanvasTexture(n);return f.colorSpace=d.SRGBColorSpace,f.minFilter=d.LinearFilter,f.magFilter=d.LinearFilter,f.needsUpdate=!0,f}function S(i){return typeof i=="number"?i:parseFloat(i)||0}function k(i,e){var o,l,h,m;if(!e){i.set(0,0,0,0);return}const t=e.split("/")[0].trim().split(/\s+/),r=S(t[0]),s=S((o=t[1])!=null?o:t[0]),n=S((l=t[2])!=null?l:t[0]),a=S((m=(h=t[3])!=null?h:t[1])!=null?m:t[0]);i.set(r,s,n,a)}const $=`
3
3
  varying vec2 vUv;
4
4
  varying vec4 vScreenPos;
5
5
  void main() {
@@ -7,7 +7,7 @@
7
7
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
8
8
  vScreenPos = gl_Position;
9
9
  }
10
- `,H=`
10
+ `,G=`
11
11
 
12
12
  varying vec2 vUv;
13
13
 
@@ -73,7 +73,7 @@
73
73
 
74
74
  #include <colorspace_fragment>
75
75
  }
76
- `;function B(i){if(!i||i==="transparent")return{color:new d.Color(16777215),alpha:0};const e=i.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),s=parseInt(e[3],10),n=e[4]!==void 0?parseFloat(e[4]):1;return{color:new d.Color(`rgb(${t}, ${r}, ${s})`),alpha:n}}return{color:new d.Color(i),alpha:1}}function $(i,e,t,r=null,s){var T;const n=r!==null,a=n?`
76
+ `;function B(i){if(!i||i==="transparent")return{color:new d.Color(16777215),alpha:0};const e=i.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(e){const t=parseInt(e[1],10),r=parseInt(e[2],10),s=parseInt(e[3],10),n=e[4]!==void 0?parseFloat(e[4]):1;return{color:new d.Color(`rgb(${t}, ${r}, ${s})`),alpha:n}}return{color:new d.Color(i),alpha:1}}function J(i,e,t,r=null,s){var T;const n=r!==null,a=n?`
77
77
  uniform sampler2D uTexture;
78
78
  varying vec4 vScreenPos;
79
79
  `:"",o=n?`
@@ -82,4 +82,4 @@
82
82
  ${(s==null?void 0:s.uvModifier)||""}
83
83
  `:"",l=n?`
84
84
  baseColor = texture2D(uTexture, resultUv);
85
- `:"",c=(s==null?void 0:s.colorModifier)||"",g=H.replace("#INJECT_DECLARATIONS",a).replace("#INJECT_UV_MODIFIER",o).replace("#INJECT_BASE_COLOR",l).replace("#INJECT_COLOR_MODIFIER",c),u=B(i.backgroundColor),p=B(i.borderColor),m={uSize:{value:new d.Vector2(e,t)},uBorderRadius:{value:new d.Vector4(0,0,0,0)},uBorderWidth:{value:S(i.borderWidth)},uBgColor:{value:u.color},uBorderColor:{value:p.color},uOpacity:{value:(T=i.opacity)!=null?T:1},uBgOpacity:{value:u.alpha},uBorderOpacity:{value:p.alpha},uTexture:{value:null}};return X(m.uBorderRadius.value,i.borderRadius),n&&(m.uTexture.value=r),new d.ShaderMaterial({uniforms:m,vertexShader:W,fragmentShader:g,transparent:!0,side:d.FrontSide})}function G(i,e,t,r,s){var o;const n=B(e.backgroundColor),a=B(e.borderColor);i.uniforms.uSize.value.set(t,r),X(i.uniforms.uBorderRadius.value,e.borderRadius),i.uniforms.uBorderWidth.value=S(e.borderWidth),i.uniforms.uBgColor.value.copy(n.color),i.uniforms.uBorderColor.value.copy(a.color),i.uniforms.uOpacity.value=(o=e.opacity)!=null?o:1,i.uniforms.uBgOpacity.value=n.alpha,i.uniforms.uBorderOpacity.value=a.alpha,i.uniforms.uTexture&&s!==void 0&&(i.uniforms.uTexture.value=s)}const L={create(i,e,t,r,s,n=2,a=null){if(i==="BOX")return $(e,r,s,a);if(i==="TEXT"){const o=A(t||"",e,r,s,n);return new d.MeshBasicMaterial({map:o,transparent:!0,side:d.FrontSide,color:16777215})}return new d.MeshBasicMaterial({visible:!1})},update(i,e,t,r,s,n,a=2,o){if(e==="BOX")G(i,t,s,n,o);else if(e==="TEXT"){const l=i;l.map&&l.map.dispose();const c=A(r||"",t,s,n,a);l.map=c,l.needsUpdate=!0}}};class j{constructor(e,t,r){h(this,"canvas");h(this,"scene");h(this,"camera");h(this,"renderer");h(this,"renderTarget",null);h(this,"renderOrder",0);h(this,"qualityFactor",2);h(this,"mode","overlay");h(this,"target");h(this,"mountContainer");h(this,"targetRect");h(this,"meshMap",new Map);var a,o;this.target=e,this.mountContainer=r,this.mode=(a=t.mode)!=null?a:"overlay",this.canvas=document.createElement("canvas"),this.scene=new d.Scene,this.targetRect=this.target.getBoundingClientRect();const s=this.targetRect.width,n=this.targetRect.height;this.camera=new d.OrthographicCamera(s/-2,s/2,n/2,n/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(0),this.renderer=new d.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(s,n),this.applyTextQuality((o=t.quality)!=null?o:"medium")}createRenderTarget(){this.renderTarget=new d.WebGLRenderTarget(this.targetRect.width*this.qualityFactor,this.targetRect.height*this.qualityFactor,{minFilter:d.LinearFilter,magFilter:d.LinearFilter,format:d.RGBAFormat,stencilBuffer:!1,depthBuffer:!0,samples:4})}applyTextQuality(e){if(typeof e=="number"){this.qualityFactor=Math.max(.1,e);return}switch(e){case"low":this.qualityFactor=1;break;case"high":this.qualityFactor=4;break;case"medium":default:this.qualityFactor=2;break}}mount(){this.mountContainer.prepend(this.canvas),this.canvas.style.pointerEvents=this.mode==="overlay"?"none":"auto",this.updateCanvasLayout()}updateCanvasLayout(){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")}dispose(){this.renderer.dispose(),this.canvas.remove()}setSize(e,t){this.renderer.setSize(e,t),this.renderTarget&&this.renderTarget.setSize(e*this.qualityFactor,t*this.qualityFactor),this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e){const t=this.target.getBoundingClientRect(),r=Math.abs(t.width-this.targetRect.width)>.1||Math.abs(t.height-this.targetRect.height)>.1,s=this.mode==="overlay"&&(Math.abs(t.top-this.targetRect.top)>.1||Math.abs(t.left-this.targetRect.left)>.1);r?(this.targetRect=t,this.setSize(this.targetRect.width,this.targetRect.height),this.updateCanvasLayout()):s?(this.targetRect=t,this.updateCanvasLayout()):this.targetRect=t,this.renderOrder=0;const n=new Set;this.reconcileNode(e,n);for(const[a,o]of this.meshMap.entries())n.has(a)||(this.scene.remove(o),o.geometry.dispose(),o.material instanceof d.Material&&o.material.dispose(),this.meshMap.delete(a))}reconcileNode(e,t){var s;t.add(e.element);let r=this.meshMap.get(e.element);if(!r){const n=new d.PlaneGeometry(1,1);let a;a=L.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,e.isTraveler?(s=this.renderTarget)==null?void 0:s.texture:void 0),r=new d.Mesh(n,a),e.type==="TEXT"&&(r.name="BG_MESH"),this.scene.add(r),this.meshMap.set(e.element,r)}if(r.userData.domRect=e.rect,this.updateMeshProperties(r,e),this.updateMeshLayers(r,e),e.isTraveler&&r.layers.enable(28),e.type==="BOX")for(const n of e.children)this.reconcileNode(n,t);else e.type==="TEXT"&&this.reconcileTextChild(r,e)}reconcileTextChild(e,t){var o,l;let r=e.children.find(c=>c.name==="TEXT_CHILD");const s=JSON.stringify(t.textStyles),n=(o=r==null?void 0:r.userData)==null?void 0:o.styleHash;if(!r||t.dirtyMask&N||s!==n){r&&((l=r.material.map)==null||l.dispose(),r.geometry.dispose(),e.remove(r));const c=L.create("TEXT",t.textStyles,t.textContent||"",t.rect.width,t.rect.height,this.qualityFactor),g=new d.PlaneGeometry(1,1);r=new d.Mesh(g,c),r.name="TEXT_CHILD",r.userData={styleHash:s},this.updateMeshLayers(r,t),r.position.z=.005,e.add(r)}if(r){const c=e.userData.domRect,g=c.x+c.width/2,u=c.y+c.height/2,p=t.rect.x+t.rect.width/2,m=t.rect.y+t.rect.height/2,w=p-g,T=-(m-u);r.position.set(w,T,.005)}}updateMeshProperties(e,t){var m;const{rect:r,styles:s}=t,n=this.renderer.getPixelRatio(),a=this.renderer.domElement.width/n,o=this.renderer.domElement.height/n;e.scale.set(r.width,r.height,1);const l=.001;this.renderOrder++;const c=this.targetRect.left+window.scrollX,g=this.targetRect.top+window.scrollY,u=r.x-c,p=r.y-g;e.position.set(u-a/2+r.width/2,-p+o/2-r.height/2,s.zIndex+this.renderOrder*l),L.update(e.material,"BOX",t.styles,"",t.rect.width,t.rect.height,this.qualityFactor,t.isTraveler?(m=this.renderTarget)==null?void 0:m.texture:void 0)}updateMeshLayers(e,t){const r=(1-(t.visibility&C))*30;e.layers.set(r),t.visibility===(C|E)&&e.layers.enable(29)}captureRenderTarget(){const e=[];for(const l of this.meshMap.values())l.layers.mask&1<<28&&e.push(l);if(e.length===0)return;const t=new d.Color,r=this.renderer.getClearAlpha();this.renderer.getClearColor(t),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);const s=new d.Vector3,n=this.targetRect.width,a=this.targetRect.height,o=this.renderer.getPixelRatio();for(const l of e){s.setFromMatrixPosition(l.matrixWorld),s.project(this.camera);const c=(s.x+1)/2*n,g=(s.y+1)/2*a,u=l.scale.x,p=l.scale.y,m=c-u/2,w=g-p/2,T=m*this.qualityFactor/o,_=w*this.qualityFactor/o,O=u*this.qualityFactor/o,f=p*this.qualityFactor/o;this.renderer.setScissor(T,_,O,f),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(28),this.renderer.setClearColor(t,r)}render(){this.renderTarget&&this.captureRenderTarget(),this.renderer.render(this.scene,this.camera)}showScissoredRenderTarget(){if(!this.renderTarget)return;const e=this.targetRect.width,t=this.targetRect.height,r=new d.PlaneGeometry(e,t),s=new d.MeshBasicMaterial({map:this.renderTarget.texture,side:d.DoubleSide,transparent:!0,opacity:.8}),n=new d.Mesh(r,s);n.position.set(0,0,90),n.layers.set(28),this.scene.add(n)}}function J(i){const e=document.createRange();e.selectNodeContents(i);const t=e.getBoundingClientRect();return{left:t.left,top:t.top,width:t.width,height:t.height}}function V(i){const e=parseFloat(i.fontSize);let t=parseFloat(i.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(i.letterSpacing);return isNaN(r)&&(r=0),{font:`${i.fontStyle} ${i.fontWeight} ${i.fontSize} ${i.fontFamily}`,color:i.color,textAlign:i.textAlign||"start",textBaseline:"alphabetic",direction:i.direction||"inherit",lineHeight:t,letterSpacing:r}}function P(i,e=F|z|k|N|D,t,r){if(i.nodeType===Node.TEXT_NODE){const f=i;if(!f.textContent||!f.textContent.trim())return null;const R=f.textContent.replace(/\s+/g," ").trim();if(R.length===0)return null;const x=J(f);if(x.width===0||x.height===0)return null;const q=f.parentElement,I=q?window.getComputedStyle(q):null;return I?{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:f,rect:{x:x.left+window.scrollX,y:x.top+window.scrollY,width:x.width,height:x.height},styles:{backgroundColor:"transparent",opacity:parseFloat(I.opacity),zIndex:0,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px"},textContent:R,textStyles:V(I),dirtyMask:e,visibility:t,isTraveler:!1,children:[]}:null}const s=i,n=s.dataset.mirageFilter;let a=t,o=t;if(n){const f=new Set(n.split(/\s+/));for(const R of f)if(!Y.includes(R))throw new Error(`[MirageEngine] Invalid filter token: '${R}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(f.has("end"))return null;if(f.has("include-tree")&&f.has("exclude-tree"))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(f.has("include-self")&&f.has("exclude-self"))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");f.has("include-tree")?a=a|C:f.has("exclude-tree")&&(a=a&~C),o=a,f.has("include-self")?o=o|C:f.has("exclude-self")&&(o=o&~C)}o=o|t&E;const l=s.dataset.mirageTravel;let c=!1;l&&new Set(l.split(/\s+/)).has("traveler")&&(o=o&~E,a=a&~E,c=!0);const g=s.getBoundingClientRect(),u=window.getComputedStyle(s);if(g.width===0||g.height===0||u.display==="none")return null;let p=s.getAttribute("data-mid");p||(p=Math.random().toString(36).substring(2,11),s.setAttribute("data-mid",p));const m=parseInt(u.zIndex),w={backgroundColor:u.backgroundColor,opacity:parseFloat(u.opacity),zIndex:isNaN(m)?0:m,borderRadius:u.borderRadius,borderColor:u.borderColor,borderWidth:u.borderWidth};let T,_;const O=[];return Array.from(s.childNodes).forEach(f=>{const R=f.nodeType===Node.TEXT_NODE?o:a,x=P(f,e,R);x&&O.push(x)}),{id:p,type:"BOX",element:s,rect:{x:g.left+window.scrollX,y:g.top+window.scrollY,width:g.width,height:g.height},styles:w,textContent:T,textStyles:_,dirtyMask:e,visibility:o,isTraveler:c,children:O}}class Q{constructor(e,t,r){h(this,"target");h(this,"renderer");h(this,"filter");h(this,"observer");h(this,"isDomDirty",!1);h(this,"isRunning",!1);h(this,"isTravelEnabled",!1);h(this,"pendingMask",M);h(this,"mutationTimer",null);h(this,"cssTimer",null);h(this,"resizeConfig");h(this,"resizeTimer",null);h(this,"isResizing",!1);h(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingMask|=F|z,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50))});h(this,"onWindowResize",()=>{if(!this.resizeConfig.enabled){this.isDomDirty=!0;return}this.isResizing||(this.isResizing=!0,this.resizeConfig.onStart&&this.resizeConfig.onStart()),this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.resizeConfig.onEnd&&this.resizeConfig.onEnd(),this.isResizing=!1,this.resizeTimer=null},this.resizeConfig.delay)});h(this,"renderLoop",()=>{this.isRunning&&(this.isDomDirty&&this.forceUpdateScene(),this.renderer.render(),requestAnimationFrame(this.renderLoop))});var n,a;this.target=e,this.renderer=t,this.filter=r.filter;const s=(n=r.resizeDebounce)!=null?n:!0;s===!1?this.resizeConfig={enabled:!1,delay:0}:s===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(a=s.delay)!=null?a:150,onStart:s.onStart,onEnd:s.onEnd},this.observer=new MutationObserver(o=>{let l=M;for(const c of o)c.type==="childList"?l|=D:c.type==="attributes"&&(c.attributeName==="style"||c.attributeName==="class")&&(l|=F|z);if(l!==M){if(this.pendingMask|=l,l&D){this.clearTimers(),console.log("Structural Change detected"),this.isDomDirty=!0;return}this.mutationTimer&&clearTimeout(this.mutationTimer),this.mutationTimer=window.setTimeout(()=>{this.mutationTimer=null,this.isDomDirty=!0},200)}})}start(){this.isRunning||(this.isRunning=!0,this.observer.observe(this.target,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),this.target.addEventListener("transitionend",this.onTransitionFinished),this.target.addEventListener("animationend",this.onTransitionFinished),window.addEventListener("resize",this.onWindowResize),this.forceUpdateScene(),this.renderLoop())}stop(){this.isRunning=!1,this.observer.disconnect(),this.clearTimers(),this.target.removeEventListener("transitionend",this.onTransitionFinished),this.target.removeEventListener("animationend",this.onTransitionFinished),window.removeEventListener("resize",this.onWindowResize)}clearTimers(){this.mutationTimer&&(clearTimeout(this.mutationTimer),this.mutationTimer=null),this.cssTimer&&(clearTimeout(this.cssTimer),this.cssTimer=null)}forceUpdateScene(){this.isDomDirty=!1;const e=document.querySelector("[data-mirage-travel='traveler']")!==null;e&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const t=P(this.target,this.pendingMask,e?C|E:C,this.filter);t&&this.renderer.syncScene(t),this.pendingMask=M}}class Z{constructor(e,t){h(this,"renderer");h(this,"syncer");h(this,"target");var s,n,a;this.target=e;let r;if(t.mode==="duplicate"?r=(n=(s=t.container)!=null?s:this.target.parentElement)!=null?n:void 0:r=(a=this.target.parentElement)!=null?a:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new j(this.target,t,r),this.renderer.mount(),this.syncer=new Q(this.target,this.renderer,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}}class K{constructor(e,t){h(this,"_engine");if(!e)throw new Error("[Mirage] Target element is required.");this._engine=new Z(e,t)}start(){this._engine.start()}stop(){this._engine.stop()}destroy(){this._engine.dispose()}}v.Mirage=K,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
85
+ `:"",h=(s==null?void 0:s.colorModifier)||"",m=G.replace("#INJECT_DECLARATIONS",a).replace("#INJECT_UV_MODIFIER",o).replace("#INJECT_BASE_COLOR",l).replace("#INJECT_COLOR_MODIFIER",h),f=B(i.backgroundColor),g=B(i.borderColor),p={uSize:{value:new d.Vector2(e,t)},uBorderRadius:{value:new d.Vector4(0,0,0,0)},uBorderWidth:{value:S(i.borderWidth)},uBgColor:{value:f.color},uBorderColor:{value:g.color},uOpacity:{value:(T=i.opacity)!=null?T:1},uBgOpacity:{value:f.alpha},uBorderOpacity:{value:g.alpha},uTexture:{value:null}};return k(p.uBorderRadius.value,i.borderRadius),n&&(p.uTexture.value=r),new d.ShaderMaterial({uniforms:p,vertexShader:$,fragmentShader:m,transparent:!0,side:d.FrontSide})}function j(i,e,t,r,s){var o;const n=B(e.backgroundColor),a=B(e.borderColor);i.uniforms.uSize.value.set(t,r),k(i.uniforms.uBorderRadius.value,e.borderRadius),i.uniforms.uBorderWidth.value=S(e.borderWidth),i.uniforms.uBgColor.value.copy(n.color),i.uniforms.uBorderColor.value.copy(a.color),i.uniforms.uOpacity.value=(o=e.opacity)!=null?o:1,i.uniforms.uBgOpacity.value=n.alpha,i.uniforms.uBorderOpacity.value=a.alpha,i.uniforms.uTexture&&s!==void 0&&(i.uniforms.uTexture.value=s)}const L={create(i,e,t,r,s,n=2,a=null,o){if(i==="BOX")return J(e,r,s,a,o);if(i==="TEXT"){const l=P(t||"",e,r,s,n);return new d.MeshBasicMaterial({map:l,transparent:!0,side:d.FrontSide,color:16777215})}return new d.MeshBasicMaterial({visible:!1})},update(i,e,t,r,s,n,a=2,o){if(e==="BOX")j(i,t,s,n,o);else if(e==="TEXT"){const l=i;l.map&&l.map.dispose();const h=P(r||"",t,s,n,a);l.map=h,l.needsUpdate=!0}}};class V{constructor(e,t,r){c(this,"canvas");c(this,"scene");c(this,"camera");c(this,"renderer");c(this,"renderTarget",null);c(this,"renderOrder",0);c(this,"qualityFactor",2);c(this,"mode","overlay");c(this,"clipArea",1);c(this,"target");c(this,"mountContainer");c(this,"targetRect");c(this,"meshMap",new Map);var a,o,l;this.target=e,this.mountContainer=r,this.mode=(a=t.mode)!=null?a:"overlay",this.clipArea=(o=t.travelerClipArea)!=null?o:1,this.canvas=document.createElement("canvas"),this.scene=new d.Scene,this.targetRect=this.target.getBoundingClientRect();const s=this.targetRect.width,n=this.targetRect.height;this.camera=new d.OrthographicCamera(s/-2,s/2,n/2,n/-2,1,1e3),this.camera.position.z=100,this.camera.layers.set(0),this.renderer=new d.WebGLRenderer({canvas:this.canvas,alpha:!0,antialias:!0}),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(s,n),this.applyTextQuality((l=t.quality)!=null?l:"medium")}createRenderTarget(){this.renderTarget=new d.WebGLRenderTarget(this.targetRect.width*this.qualityFactor,this.targetRect.height*this.qualityFactor,{minFilter:d.LinearFilter,magFilter:d.LinearFilter,format:d.RGBAFormat,stencilBuffer:!1,depthBuffer:!0,samples:4})}applyTextQuality(e){if(typeof e=="number"){this.qualityFactor=Math.max(.1,e);return}switch(e){case"low":this.qualityFactor=1;break;case"high":this.qualityFactor=4;break;case"medium":default:this.qualityFactor=2;break}}mount(){this.mountContainer.prepend(this.canvas),this.canvas.style.pointerEvents=this.mode==="overlay"?"none":"auto",this.updateCanvasLayout()}updateCanvasLayout(){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")}dispose(){this.renderer.dispose(),this.canvas.remove()}setSize(e,t){this.renderer.setSize(e,t),this.renderTarget&&this.renderTarget.setSize(e*this.qualityFactor,t*this.qualityFactor),this.camera.left=e/-2,this.camera.right=e/2,this.camera.top=t/2,this.camera.bottom=t/-2,this.camera.updateProjectionMatrix()}syncScene(e){const t=this.target.getBoundingClientRect(),r=Math.abs(t.width-this.targetRect.width)>.1||Math.abs(t.height-this.targetRect.height)>.1,s=this.mode==="overlay"&&(Math.abs(t.top-this.targetRect.top)>.1||Math.abs(t.left-this.targetRect.left)>.1);r?(this.targetRect=t,this.setSize(this.targetRect.width,this.targetRect.height),this.updateCanvasLayout()):s?(this.targetRect=t,this.updateCanvasLayout()):this.targetRect=t,this.renderOrder=0;const n=new Set;this.reconcileNode(e,n);for(const[a,o]of this.meshMap.entries())n.has(a)||(this.scene.remove(o),o.geometry.dispose(),o.material instanceof d.Material&&o.material.dispose(),this.meshMap.delete(a))}reconcileNode(e,t){var s;t.add(e.element);let r=this.meshMap.get(e.element);if(!r){const n=new d.PlaneGeometry(1,1);let a;a=L.create("BOX",e.styles,"",e.rect.width,e.rect.height,this.qualityFactor,e.isTraveler?(s=this.renderTarget)==null?void 0:s.texture:void 0,e.shaderHooks),r=new d.Mesh(n,a),e.type==="TEXT"&&(r.name="BG_MESH"),this.scene.add(r),this.meshMap.set(e.element,r)}if(r.userData.domRect=e.rect,this.updateMeshProperties(r,e),this.updateMeshLayers(r,e),e.isTraveler&&r.layers.enable(28),e.type==="BOX")for(const n of e.children)this.reconcileNode(n,t);else e.type==="TEXT"&&this.reconcileTextChild(r,e)}reconcileTextChild(e,t){var o,l;let r=e.children.find(h=>h.name==="TEXT_CHILD");const s=JSON.stringify(t.textStyles),n=(o=r==null?void 0:r.userData)==null?void 0:o.styleHash;if(!r||t.dirtyMask&X||s!==n){r&&((l=r.material.map)==null||l.dispose(),r.geometry.dispose(),e.remove(r));const h=L.create("TEXT",t.textStyles,t.textContent||"",t.rect.width,t.rect.height,this.qualityFactor),m=new d.PlaneGeometry(1,1);r=new d.Mesh(m,h),r.name="TEXT_CHILD",r.userData={styleHash:s},this.updateMeshLayers(r,t),r.position.z=.005,e.add(r)}if(r){const h=e.userData.domRect,m=h.x+h.width/2,f=h.y+h.height/2,g=t.rect.x+t.rect.width/2,p=t.rect.y+t.rect.height/2,x=g-m,T=-(p-f);r.position.set(x,T,.005)}}updateMeshProperties(e,t){var p;const{rect:r,styles:s}=t,n=this.renderer.getPixelRatio(),a=this.renderer.domElement.width/n,o=this.renderer.domElement.height/n;e.scale.set(r.width,r.height,1);const l=.001;this.renderOrder++;const h=this.targetRect.left+window.scrollX,m=this.targetRect.top+window.scrollY,f=r.x-h,g=r.y-m;e.position.set(f-a/2+r.width/2,-g+o/2-r.height/2,s.zIndex+this.renderOrder*l),L.update(e.material,"BOX",t.styles,"",t.rect.width,t.rect.height,this.qualityFactor,t.isTraveler?(p=this.renderTarget)==null?void 0:p.texture:void 0)}updateMeshLayers(e,t){const r=(1-(t.visibility&w))*30;e.layers.set(r),t.visibility===(w|E)&&e.layers.enable(29)}captureRenderTarget(){const e=[];for(const l of this.meshMap.values())l.layers.mask&1<<28&&e.push(l);if(e.length===0)return;const t=new d.Color,r=this.renderer.getClearAlpha();this.renderer.getClearColor(t),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);const s=new d.Vector3,n=this.targetRect.width,a=this.targetRect.height,o=this.renderer.getPixelRatio();for(const l of e){s.setFromMatrixPosition(l.matrixWorld),s.project(this.camera);const h=(s.x+1)/2*n,m=(s.y+1)/2*a;let f=0,g=1;typeof this.clipArea=="number"?g=this.clipArea:this.clipArea.endsWith("%")?g=parseFloat(this.clipArea)/100:this.clipArea.endsWith("px")&&(f=parseFloat(this.clipArea));const p=l.scale.x*g+.5,x=l.scale.y*g+.5,T=h-p/2,_=m-x/2,I=(T*this.qualityFactor-f)/o,N=(_*this.qualityFactor-f)/o,O=(p*this.qualityFactor+f*2)/o,u=(x*this.qualityFactor+f*2)/o;this.renderer.setScissor(I,N,O,u),this.renderer.render(this.scene,this.camera)}this.renderer.setScissorTest(!1),this.renderer.autoClear=!0,this.renderer.setRenderTarget(null),this.camera.layers.set(28),this.renderer.setClearColor(t,r)}render(){this.renderTarget&&this.captureRenderTarget(),this.renderer.render(this.scene,this.camera)}showScissoredRenderTarget(){if(!this.renderTarget)return;const e=this.targetRect.width,t=this.targetRect.height,r=new d.PlaneGeometry(e,t),s=new d.MeshBasicMaterial({map:this.renderTarget.texture,side:d.DoubleSide,transparent:!0,opacity:.8}),n=new d.Mesh(r,s);n.position.set(0,0,90),n.layers.set(28),this.scene.add(n)}}function Q(i){const e=document.createRange();e.selectNodeContents(i);const t=e.getBoundingClientRect();return{left:t.left,top:t.top,width:t.width,height:t.height}}function Z(i){const e=parseFloat(i.fontSize);let t=parseFloat(i.lineHeight);isNaN(t)&&(t=e*1.2);let r=parseFloat(i.letterSpacing);return isNaN(r)&&(r=0),{font:`${i.fontStyle} ${i.fontWeight} ${i.fontSize} ${i.fontFamily}`,color:i.color,textAlign:i.textAlign||"start",textBaseline:"alphabetic",direction:i.direction||"inherit",lineHeight:t,letterSpacing:r}}function q(i,e=F|D|W|X|z,t,r){if(i.nodeType===Node.TEXT_NODE){const u=i;if(!u.textContent||!u.textContent.trim())return null;const R=u.textContent.replace(/\s+/g," ").trim();if(R.length===0)return null;const C=Q(u);if(C.width===0||C.height===0)return null;const Y=u.parentElement,A=Y?window.getComputedStyle(Y):null;return A?{id:Math.random().toString(36).substring(2,9),type:"TEXT",element:u,rect:{x:C.left+window.scrollX,y:C.top+window.scrollY,width:C.width,height:C.height},styles:{backgroundColor:"transparent",opacity:parseFloat(A.opacity),zIndex:0,borderRadius:"0px",borderColor:"transparent",borderWidth:"0px"},textContent:R,textStyles:Z(A),dirtyMask:e,visibility:t,isTraveler:!1,children:[]}:null}const s=i,n=s.dataset.mirageFilter;let a=t,o=t;if(n){const u=new Set(n.split(/\s+/));for(const R of u)if(!H.includes(R))throw new Error(`[MirageEngine] Invalid filter token: '${R}'. Expected one of: 'include-tree', 'exclude-tree', 'include-self', 'exclude-self', 'end'.`);if(u.has("end"))return null;if(u.has("include-tree")&&u.has("exclude-tree"))throw new Error("[MirageEngine] Conflicting filters: 'include-tree' and 'exclude-tree' cannot be used together on the same element.");if(u.has("include-self")&&u.has("exclude-self"))throw new Error("[MirageEngine] Conflicting filters: 'include-self' and 'exclude-self' cannot be used together on the same element.");u.has("include-tree")?a=a|w:u.has("exclude-tree")&&(a=a&~w),o=a,u.has("include-self")?o=o|w:u.has("exclude-self")&&(o=o&~w)}o=o|t&E;const l=s.dataset.mirageTravel;let h=!1;l&&new Set(l.split(/\s+/)).has("traveler")&&(o=o&~E,a=a&~E,h=!0);const m=s.dataset.mirageShader;let f;m&&(f=JSON.parse(m));const g=s.getBoundingClientRect(),p=window.getComputedStyle(s);if(g.width===0||g.height===0||p.display==="none")return null;let x=s.getAttribute("data-mid");x||(x=Math.random().toString(36).substring(2,11),s.setAttribute("data-mid",x));const T=parseInt(p.zIndex),_={backgroundColor:p.backgroundColor,opacity:parseFloat(p.opacity),zIndex:isNaN(T)?0:T,borderRadius:p.borderRadius,borderColor:p.borderColor,borderWidth:p.borderWidth};let I,N;const O=[];return Array.from(s.childNodes).forEach(u=>{const R=u.nodeType===Node.TEXT_NODE?o:a,C=q(u,e,R);C&&O.push(C)}),{id:x,type:"BOX",element:s,rect:{x:g.left+window.scrollX,y:g.top+window.scrollY,width:g.width,height:g.height},styles:_,textContent:I,textStyles:N,dirtyMask:e,visibility:o,isTraveler:h,children:O,shaderHooks:f}}class K{constructor(e,t,r){c(this,"target");c(this,"renderer");c(this,"filter");c(this,"observer");c(this,"isDomDirty",!1);c(this,"isRunning",!1);c(this,"isTravelEnabled",!1);c(this,"pendingMask",M);c(this,"mutationTimer",null);c(this,"cssTimer",null);c(this,"resizeConfig");c(this,"resizeTimer",null);c(this,"isResizing",!1);c(this,"onTransitionFinished",e=>{this.target.contains(e.target)&&this.mutationTimer===null&&(this.cssTimer&&clearTimeout(this.cssTimer),this.pendingMask|=F|D,this.cssTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.cssTimer=null},50))});c(this,"onWindowResize",()=>{if(!this.resizeConfig.enabled){this.isDomDirty=!0;return}this.isResizing||(this.isResizing=!0,this.resizeConfig.onStart&&this.resizeConfig.onStart()),this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=window.setTimeout(()=>{this.isDomDirty=!0,this.resizeConfig.onEnd&&this.resizeConfig.onEnd(),this.isResizing=!1,this.resizeTimer=null},this.resizeConfig.delay)});c(this,"renderLoop",()=>{this.isRunning&&(this.isDomDirty&&this.forceUpdateScene(),this.renderer.render(),requestAnimationFrame(this.renderLoop))});var n,a;this.target=e,this.renderer=t,this.filter=r.filter;const s=(n=r.resizeDebounce)!=null?n:!0;s===!1?this.resizeConfig={enabled:!1,delay:0}:s===!0?this.resizeConfig={enabled:!0,delay:150}:this.resizeConfig={enabled:!0,delay:(a=s.delay)!=null?a:150,onStart:s.onStart,onEnd:s.onEnd},this.observer=new MutationObserver(o=>{let l=M;for(const h of o)h.type==="childList"?l|=z:h.type==="attributes"&&(h.attributeName==="style"||h.attributeName==="class")&&(l|=F|D);if(l!==M){if(this.pendingMask|=l,l&z){this.clearTimers(),console.log("Structural Change detected"),this.isDomDirty=!0;return}this.mutationTimer&&clearTimeout(this.mutationTimer),this.mutationTimer=window.setTimeout(()=>{this.mutationTimer=null,this.isDomDirty=!0},200)}})}start(){this.isRunning||(this.isRunning=!0,this.observer.observe(this.target,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),this.target.addEventListener("transitionend",this.onTransitionFinished),this.target.addEventListener("animationend",this.onTransitionFinished),window.addEventListener("resize",this.onWindowResize),this.forceUpdateScene(),this.renderLoop())}stop(){this.isRunning=!1,this.observer.disconnect(),this.clearTimers(),this.target.removeEventListener("transitionend",this.onTransitionFinished),this.target.removeEventListener("animationend",this.onTransitionFinished),window.removeEventListener("resize",this.onWindowResize)}clearTimers(){this.mutationTimer&&(clearTimeout(this.mutationTimer),this.mutationTimer=null),this.cssTimer&&(clearTimeout(this.cssTimer),this.cssTimer=null)}forceUpdateScene(){this.isDomDirty=!1;const e=document.querySelector("[data-mirage-travel='traveler']")!==null;e&&!this.isTravelEnabled&&(this.isTravelEnabled=!0,this.renderer.createRenderTarget());const t=q(this.target,this.pendingMask,e?w|E:w,this.filter);t&&this.renderer.syncScene(t),this.pendingMask=M}}class ee{constructor(e,t){c(this,"renderer");c(this,"syncer");c(this,"target");var s,n,a;this.target=e;let r;if(t.mode==="duplicate"?r=(n=(s=t.container)!=null?s:this.target.parentElement)!=null?n:void 0:r=(a=this.target.parentElement)!=null?a:void 0,!r)throw new Error("[Mirage] Cannot find a container (parent or option).");this.renderer=new V(this.target,t,r),this.renderer.mount(),this.syncer=new K(this.target,this.renderer,t)}start(){this.syncer.start()}stop(){this.syncer.stop()}dispose(){this.syncer.stop(),this.renderer.dispose()}}class te{constructor(e,t){c(this,"_engine");if(!e)throw new Error("[Mirage] Target element is required.");this._engine=new ee(e,t)}start(){this._engine.start()}stop(){this._engine.stop()}destroy(){this._engine.dispose()}}v.Mirage=te,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirage-engine",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "An engine that mirrors HTML DOM elements to a WebGL scene in real-time.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "@mirage-engine/painter": "0.3.0",
25
- "@mirage-engine/core": "0.2.0"
24
+ "@mirage-engine/painter": "0.4.0",
25
+ "@mirage-engine/core": "0.2.1"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "three": "^0.150.0"