layershift 0.6.0 → 0.8.0

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,4 +1,130 @@
1
- class Vt {
1
+ const lt = new Uint8Array([76, 83, 70, 84]), At = 4, ie = 22, re = At + ie, se = 1, oe = 0, ae = 1, le = 3;
2
+ function ue(s) {
3
+ return s.byteLength < At ? !1 : s[0] === lt[0] && s[1] === lt[1] && s[2] === lt[2] && s[3] === lt[3];
4
+ }
5
+ function ce(s) {
6
+ let t = At;
7
+ const e = s.getUint16(t, !0);
8
+ t += 2;
9
+ const n = s.getUint32(t, !0);
10
+ t += 4;
11
+ const i = s.getFloat32(t, !0);
12
+ t += 4;
13
+ const r = s.getUint16(t, !0);
14
+ t += 2;
15
+ const o = s.getUint16(t, !0);
16
+ t += 2;
17
+ const l = s.getUint16(t, !0);
18
+ return { version: e, frameCount: n, fps: i, width: r, height: o, signalsPresent: l };
19
+ }
20
+ function he(s) {
21
+ let t = 0, e = s;
22
+ for (; e; )
23
+ t += e & 1, e >>>= 1;
24
+ return t;
25
+ }
26
+ function fe(s, t) {
27
+ const e = [];
28
+ let n = re;
29
+ for (let i = 0; i < t; i++) {
30
+ const r = s.getUint16(n, !0);
31
+ n += 2;
32
+ const o = s.getUint32(n, !0);
33
+ n += 4;
34
+ const l = s.getUint32(n, !0);
35
+ n += 4;
36
+ const a = o + l * 4294967296, h = s.getUint32(n, !0);
37
+ n += 4;
38
+ const c = s.getUint32(n, !0);
39
+ n += 4;
40
+ const f = h + c * 4294967296, u = s.getUint32(n, !0);
41
+ n += 4;
42
+ const v = s.getUint8(n);
43
+ n += 1;
44
+ const p = s.getUint8(n);
45
+ n += 1, n += 6, e.push({ signalId: r, dataOffset: a, dataLength: f, frameStride: u, encoding: v, channels: p });
46
+ }
47
+ return e;
48
+ }
49
+ function de(s) {
50
+ const t = s >>> 15 & 1, e = s >>> 10 & 31, n = s & 1023;
51
+ if (e === 31)
52
+ return n === 0 ? t ? -1 / 0 : 1 / 0 : NaN;
53
+ if (e === 0) {
54
+ const r = n / 1024 * 6103515625e-14;
55
+ return t ? -r : r;
56
+ }
57
+ const i = (1 + n / 1024) * Math.pow(2, e - 15);
58
+ return t ? -i : i;
59
+ }
60
+ function me(s) {
61
+ const t = de(s);
62
+ return Number.isNaN(t) || t <= 0 ? 0 : t >= 1 ? 255 : t * 255 + 0.5 | 0;
63
+ }
64
+ function pe(s, t, e) {
65
+ const n = new Uint8Array(e);
66
+ for (let i = 0; i < e; i++) {
67
+ const r = s.getUint16(t + i * 2, !0);
68
+ n[i] = me(r);
69
+ }
70
+ return n;
71
+ }
72
+ async function ge(s) {
73
+ const t = new DecompressionStream("deflate-raw"), e = t.writable.getWriter();
74
+ e.write(s), e.close();
75
+ const n = t.readable.getReader(), i = [];
76
+ for (; ; ) {
77
+ const { done: a, value: h } = await n.read();
78
+ if (a) break;
79
+ i.push(h);
80
+ }
81
+ const r = i.reduce((a, h) => a + h.byteLength, 0), o = new Uint8Array(r);
82
+ let l = 0;
83
+ for (const a of i)
84
+ o.set(a, l), l += a.byteLength;
85
+ return o;
86
+ }
87
+ async function ve(s, t, e, n) {
88
+ const i = new DataView(s.buffer, s.byteOffset, s.byteLength), r = ce(i), o = he(r.signalsPresent), a = fe(i, o).find((p) => p.signalId === se);
89
+ if (!a)
90
+ throw new Error(
91
+ `LSFT file does not contain a depth signal (signals_present: 0x${r.signalsPresent.toString(16).padStart(4, "0")})`
92
+ );
93
+ const h = t ?? r.width, c = e ?? r.height, f = n ?? r.fps, u = h * c, v = [];
94
+ if (a.encoding === le) {
95
+ const p = s.subarray(
96
+ a.dataOffset,
97
+ a.dataOffset + a.dataLength
98
+ ), d = await ge(p);
99
+ for (let S = 0; S < r.frameCount; S++) {
100
+ const E = S * a.frameStride;
101
+ v.push(d.slice(E, E + a.frameStride));
102
+ }
103
+ } else if (a.encoding === oe)
104
+ for (let p = 0; p < r.frameCount; p++) {
105
+ const d = a.dataOffset + p * a.frameStride;
106
+ v.push(s.slice(d, d + a.frameStride));
107
+ }
108
+ else if (a.encoding === ae)
109
+ for (let p = 0; p < r.frameCount; p++) {
110
+ const d = a.dataOffset + p * a.frameStride;
111
+ v.push(pe(i, d, u));
112
+ }
113
+ else
114
+ throw new Error(`Unsupported depth encoding: ${a.encoding}`);
115
+ return {
116
+ width: h,
117
+ height: c,
118
+ fps: f,
119
+ frameCount: r.frameCount,
120
+ frames: v,
121
+ metadata: {
122
+ version: r.version,
123
+ signalsPresent: r.signalsPresent
124
+ }
125
+ };
126
+ }
127
+ class Ht {
2
128
  constructor(t) {
3
129
  this.depthData = t;
4
130
  const e = t.width * t.height;
@@ -10,7 +136,7 @@ class Vt {
10
136
  lastNextFrameIndex = -1;
11
137
  lastLerpFactor = -1;
12
138
  sample(t) {
13
- const e = ne(t * this.depthData.fps, 0, this.depthData.frameCount - 1), n = Math.floor(e), i = Math.min(n + 1, this.depthData.frameCount - 1), r = e - n, o = n !== this.lastFrameIndex || i !== this.lastNextFrameIndex, l = Math.abs(r - this.lastLerpFactor) > 1e-3;
139
+ const e = Te(t * this.depthData.fps, 0, this.depthData.frameCount - 1), n = Math.floor(e), i = Math.min(n + 1, this.depthData.frameCount - 1), r = e - n, o = n !== this.lastFrameIndex || i !== this.lastNextFrameIndex, l = Math.abs(r - this.lastLerpFactor) > 1e-3;
14
140
  if (!o && !l)
15
141
  return this.uint8Output;
16
142
  this.lastFrameIndex = n, this.lastNextFrameIndex = i, this.lastLerpFactor = r;
@@ -20,49 +146,42 @@ class Vt {
20
146
  return this.uint8Output;
21
147
  }
22
148
  }
23
- async function kt(s, t = 512, e = 512, n = 5, i) {
24
- const r = await te(s);
25
- return ee(r, t, e, n);
149
+ async function Nt(s, t = 512, e = 512, n = 5, i) {
150
+ const r = await xe(s);
151
+ if (!ue(r))
152
+ throw new Error(
153
+ "Unsupported depth data format. Expected LSFT (.lsb) file. Use the layershift precompute CLI to produce LSFT-format files."
154
+ );
155
+ return await ve(r, t !== 512 ? t : void 0, e !== 512 ? e : void 0, n !== 5 ? n : void 0);
26
156
  }
27
- async function te(s, t) {
157
+ async function xe(s, t) {
28
158
  const e = await fetch(s);
29
159
  if (!e.ok)
30
160
  throw new Error(`Failed to fetch depth data (${e.status} ${e.statusText}).`);
161
+ if ((e.headers.get("content-type") ?? "").includes("text/html"))
162
+ throw new Error(
163
+ `Depth data URL returned HTML instead of binary data. The file may not exist at "${s}". Check the URL and server configuration.`
164
+ );
31
165
  e.headers.get("content-length");
32
- const n = e.body;
33
- if (!n)
166
+ const i = e.body;
167
+ if (!i)
34
168
  return new Uint8Array(await e.arrayBuffer());
35
- const i = [];
36
- let r = 0;
37
- const o = n.getReader();
169
+ const r = [];
170
+ let o = 0;
171
+ const l = i.getReader();
38
172
  for (; ; ) {
39
- const { done: h, value: c } = await o.read();
40
- if (h)
173
+ const { done: c, value: f } = await l.read();
174
+ if (c)
41
175
  break;
42
- c && (i.push(c), r += c.byteLength);
43
- }
44
- const l = new Uint8Array(r);
45
- let a = 0;
46
- for (const h of i)
47
- l.set(h, a), a += h.byteLength;
48
- return l;
49
- }
50
- function ee(s, t, e, n) {
51
- const i = t * e;
52
- if (i === 0)
53
- throw new Error("Depth frame dimensions must be non-zero.");
54
- if (s.byteLength % i !== 0)
55
- throw new Error(
56
- `Depth data byte length (${s.byteLength}) is not evenly divisible by frame size (${i} = ${t}×${e}).`
57
- );
58
- const r = s.byteLength / i, o = new Array(r);
59
- for (let l = 0; l < r; l += 1) {
60
- const a = l * i;
61
- o[l] = s.subarray(a, a + i);
176
+ f && (r.push(f), o += f.byteLength);
62
177
  }
63
- return { width: t, height: e, fps: n, frameCount: r, frames: o };
178
+ const a = new Uint8Array(o);
179
+ let h = 0;
180
+ for (const c of r)
181
+ a.set(c, h), h += c.byteLength;
182
+ return a;
64
183
  }
65
- function X(s, t) {
184
+ function N(s, t) {
66
185
  const e = new Uint8Array(s * t);
67
186
  return e.fill(128), {
68
187
  width: s,
@@ -72,10 +191,10 @@ function X(s, t) {
72
191
  frames: [e]
73
192
  };
74
193
  }
75
- function ne(s, t, e) {
194
+ function Te(s, t, e) {
76
195
  return Math.min(e, Math.max(t, s));
77
196
  }
78
- const ie = {
197
+ const Ee = {
79
198
  parallaxStrength: 0.05,
80
199
  contrastLow: 0.05,
81
200
  contrastHigh: 0.95,
@@ -85,11 +204,11 @@ const ie = {
85
204
  pomSteps: 16,
86
205
  overscanPadding: 0.08
87
206
  };
88
- function re(s, t, e) {
207
+ function be(s, t, e) {
89
208
  const n = new Float32Array(256);
90
209
  if (s.length === 0 || t <= 0 || e <= 0)
91
- return Pt(n);
92
- const i = oe(s.length), r = t * e;
210
+ return Ft(n);
211
+ const i = ye(s.length), r = t * e;
93
212
  let o = 0;
94
213
  const l = new Uint32Array(256);
95
214
  for (const m of i) {
@@ -99,7 +218,7 @@ function re(s, t, e) {
99
218
  o += w;
100
219
  }
101
220
  if (o === 0)
102
- return Pt(n);
221
+ return Ft(n);
103
222
  const a = 1 / o;
104
223
  for (let m = 0; m < 256; m += 1)
105
224
  n[m] = l[m] * a;
@@ -107,33 +226,33 @@ function re(s, t, e) {
107
226
  h[0] = n[0];
108
227
  for (let m = 1; m < 256; m += 1)
109
228
  h[m] = h[m - 1] + n[m];
110
- const c = nt(h, 0.05), f = nt(h, 0.25), u = nt(h, 0.5), x = nt(h, 0.75), p = nt(h, 0.95);
229
+ const c = nt(h, 0.05), f = nt(h, 0.25), u = nt(h, 0.5), v = nt(h, 0.75), p = nt(h, 0.95);
111
230
  let d = 0;
112
231
  for (let m = 0; m < 256; m += 1)
113
232
  d += m / 255 * n[m];
114
- let y = 0;
233
+ let S = 0;
115
234
  for (let m = 0; m < 256; m += 1) {
116
235
  const T = m / 255 - d;
117
- y += n[m] * T * T;
236
+ S += n[m] * T * T;
118
237
  }
119
- const b = Math.sqrt(y), E = p - c, g = x - f, v = ae(n);
238
+ const E = Math.sqrt(S), b = p - c, g = v - f, x = we(n);
120
239
  return {
121
240
  mean: d,
122
- stdDev: b,
241
+ stdDev: E,
123
242
  p5: c,
124
243
  p25: f,
125
244
  median: u,
126
- p75: x,
245
+ p75: v,
127
246
  p95: p,
128
- effectiveRange: E,
247
+ effectiveRange: b,
129
248
  iqr: g,
130
- bimodality: v,
249
+ bimodality: x,
131
250
  histogram: n
132
251
  };
133
252
  }
134
- function se(s) {
253
+ function Se(s) {
135
254
  if (s.effectiveRange < 0.05 || s.stdDev < 0.02)
136
- return { ...ie };
255
+ return { ...Ee };
137
256
  const t = s.effectiveRange - 0.5, e = s.bimodality - 0.4, n = H(
138
257
  0.05 - t * 0.03 + e * 0.01,
139
258
  0.035,
@@ -150,7 +269,7 @@ function se(s) {
150
269
  overscanPadding: f
151
270
  };
152
271
  }
153
- function oe(s) {
272
+ function ye(s) {
154
273
  if (s <= 0) return [];
155
274
  if (s === 1) return [0];
156
275
  const t = s - 1, e = [
@@ -170,13 +289,13 @@ function nt(s, t) {
170
289
  return e / 255;
171
290
  return 1;
172
291
  }
173
- function ae(s) {
292
+ function we(s) {
174
293
  const t = new Float32Array(256);
175
294
  for (let u = 0; u < 256; u += 1) {
176
- let x = 0, p = 0;
295
+ let v = 0, p = 0;
177
296
  for (let d = u - 2; d <= u + 2; d += 1)
178
- d >= 0 && d < 256 && (x += s[d], p += 1);
179
- t[u] = x / p;
297
+ d >= 0 && d < 256 && (v += s[d], p += 1);
298
+ t[u] = v / p;
180
299
  }
181
300
  let e = 0;
182
301
  for (let u = 0; u < 256; u += 1)
@@ -185,7 +304,7 @@ function ae(s) {
185
304
  const n = e * 2, i = 25, r = [];
186
305
  for (let u = 1; u < 255; u += 1)
187
306
  t[u] > t[u - 1] && t[u] > t[u + 1] && t[u] >= n && r.push({ bin: u, height: t[u] });
188
- if (t[0] > t[1] && t[0] >= n && r.push({ bin: 0, height: t[0] }), t[255] > t[254] && t[255] >= n && r.push({ bin: 255, height: t[255] }), r.sort((u, x) => x.height - u.height), r.length < 2) return 0;
307
+ if (t[0] > t[1] && t[0] >= n && r.push({ bin: 0, height: t[0] }), t[255] > t[254] && t[255] >= n && r.push({ bin: 255, height: t[255] }), r.sort((u, v) => v.height - u.height), r.length < 2) return 0;
189
308
  const o = r[0];
190
309
  let l = null;
191
310
  for (let u = 1; u < r.length; u += 1)
@@ -201,7 +320,7 @@ function ae(s) {
201
320
  const f = Math.min(o.height, l.height);
202
321
  return f <= 0 ? 0 : H(1 - c / f, 0, 1);
203
322
  }
204
- function Pt(s) {
323
+ function Ft(s) {
205
324
  return {
206
325
  mean: 0,
207
326
  stdDev: 0,
@@ -229,7 +348,7 @@ ${i}`);
229
348
  }
230
349
  return n;
231
350
  }
232
- function mt(s, t, e) {
351
+ function pt(s, t, e) {
233
352
  const n = s.createProgram();
234
353
  if (!n) throw new Error("Failed to create program.");
235
354
  if (s.attachShader(n, t), s.attachShader(n, e), s.linkProgram(n), !s.getProgramParameter(n, s.LINK_STATUS)) {
@@ -239,13 +358,13 @@ ${i}`);
239
358
  }
240
359
  return s.detachShader(n, t), s.detachShader(n, e), s.deleteShader(t), s.deleteShader(e), n;
241
360
  }
242
- function pt(s, t, e) {
361
+ function gt(s, t, e) {
243
362
  const n = {};
244
363
  for (const i of e)
245
364
  n[i] = s.getUniformLocation(t, i);
246
365
  return n;
247
366
  }
248
- const le = new Float32Array([
367
+ const Re = new Float32Array([
249
368
  -1,
250
369
  -1,
251
370
  1,
@@ -255,16 +374,16 @@ const le = new Float32Array([
255
374
  1,
256
375
  1
257
376
  ]);
258
- function Ot(s, t) {
377
+ function Xt(s, t) {
259
378
  const e = s.createVertexArray();
260
379
  if (!e) throw new Error("Failed to create VAO.");
261
380
  s.bindVertexArray(e);
262
381
  const n = s.createBuffer();
263
- s.bindBuffer(s.ARRAY_BUFFER, n), s.bufferData(s.ARRAY_BUFFER, le, s.STATIC_DRAW);
382
+ s.bindBuffer(s.ARRAY_BUFFER, n), s.bufferData(s.ARRAY_BUFFER, Re, s.STATIC_DRAW);
264
383
  const i = s.getAttribLocation(t, "aPosition");
265
384
  return s.enableVertexAttribArray(i), s.vertexAttribPointer(i, 2, s.FLOAT, !1, 0, 0), s.bindVertexArray(null), e;
266
385
  }
267
- class Ht {
386
+ class Gt {
268
387
  slots = /* @__PURE__ */ new Map();
269
388
  nextUnit = 0;
270
389
  /**
@@ -300,8 +419,8 @@ class Ht {
300
419
  return this.slots.size;
301
420
  }
302
421
  }
303
- function O(s, t, e, n, i) {
304
- const r = G(s, s.VERTEX_SHADER, e), o = G(s, s.FRAGMENT_SHADER, n), l = mt(s, r, o), a = pt(s, l, i);
422
+ function k(s, t, e, n, i) {
423
+ const r = G(s, s.VERTEX_SHADER, e), o = G(s, s.FRAGMENT_SHADER, n), l = pt(s, r, o), a = gt(s, l, i);
305
424
  return {
306
425
  name: t,
307
426
  program: l,
@@ -311,8 +430,8 @@ function O(s, t, e, n, i) {
311
430
  }
312
431
  };
313
432
  }
314
- function Dt(s, t, e, n, i, r) {
315
- const o = G(s, s.VERTEX_SHADER, e), l = G(s, s.FRAGMENT_SHADER, n), a = mt(s, o, l), h = pt(s, a, i), c = {
433
+ function Ct(s, t, e, n, i, r) {
434
+ const o = G(s, s.VERTEX_SHADER, e), l = G(s, s.FRAGMENT_SHADER, n), a = pt(s, o, l), h = gt(s, a, i), c = {
316
435
  texture: null,
317
436
  unit: r.textureUnit,
318
437
  attachment: s.COLOR_ATTACHMENT0
@@ -324,12 +443,12 @@ function Dt(s, t, e, n, i, r) {
324
443
  outputs: [c],
325
444
  width: 0,
326
445
  height: 0,
327
- resize(u, x, p) {
328
- f.fbo && u.deleteFramebuffer(f.fbo), c.texture && u.deleteTexture(c.texture), f.width = x, f.height = p, c.texture = u.createTexture(), u.activeTexture(u.TEXTURE0 + c.unit), u.bindTexture(u.TEXTURE_2D, c.texture), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MIN_FILTER, u.LINEAR), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MAG_FILTER, u.LINEAR), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_S, u.CLAMP_TO_EDGE), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_T, u.CLAMP_TO_EDGE), u.texImage2D(
446
+ resize(u, v, p) {
447
+ f.fbo && u.deleteFramebuffer(f.fbo), c.texture && u.deleteTexture(c.texture), f.width = v, f.height = p, c.texture = u.createTexture(), u.activeTexture(u.TEXTURE0 + c.unit), u.bindTexture(u.TEXTURE_2D, c.texture), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MIN_FILTER, u.LINEAR), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MAG_FILTER, u.LINEAR), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_S, u.CLAMP_TO_EDGE), u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_T, u.CLAMP_TO_EDGE), u.texImage2D(
329
448
  u.TEXTURE_2D,
330
449
  0,
331
450
  r.internalFormat,
332
- x,
451
+ v,
333
452
  p,
334
453
  0,
335
454
  r.format,
@@ -349,7 +468,7 @@ function Dt(s, t, e, n, i, r) {
349
468
  };
350
469
  return r.width > 0 && r.height > 0 && f.resize(s, r.width, r.height), f;
351
470
  }
352
- const ue = {
471
+ const Ae = {
353
472
  high: {
354
473
  dprCap: 2,
355
474
  depthMaxDim: 512,
@@ -372,7 +491,7 @@ const ue = {
372
491
  jfaDivisor: 4
373
492
  }
374
493
  };
375
- function ce(s) {
494
+ function Pe(s) {
376
495
  let t = "unknown";
377
496
  const e = s.getExtension("WEBGL_debug_renderer_info");
378
497
  e && (t = s.getParameter(e.UNMASKED_RENDERER_WEBGL) || "unknown");
@@ -387,7 +506,7 @@ function ce(s) {
387
506
  isMobile: a && h
388
507
  };
389
508
  }
390
- const he = [
509
+ const De = [
391
510
  "mali-4",
392
511
  "mali-t",
393
512
  "adreno 3",
@@ -400,7 +519,7 @@ const he = [
400
519
  "llvmpipe",
401
520
  "swiftshader",
402
521
  "software"
403
- ], fe = [
522
+ ], Fe = [
404
523
  "nvidia",
405
524
  "geforce",
406
525
  "radeon rx",
@@ -412,16 +531,16 @@ const he = [
412
531
  "mali-g7",
413
532
  "mali-g6"
414
533
  ];
415
- function de(s) {
534
+ function Ce(s) {
416
535
  let t = 0;
417
- const e = s.gpuRenderer.toLowerCase(), n = he.some((r) => e.includes(r)), i = fe.some((r) => e.includes(r));
536
+ const e = s.gpuRenderer.toLowerCase(), n = De.some((r) => e.includes(r)), i = Fe.some((r) => e.includes(r));
418
537
  return n && (t -= 30), i && (t += 20), s.maxTextureSize >= 16384 ? t += 10 : s.maxTextureSize >= 8192 ? t += 5 : s.maxTextureSize <= 4096 && (t -= 15), s.hardwareConcurrency >= 8 ? t += 5 : s.hardwareConcurrency >= 4 ? t += 0 : s.hardwareConcurrency > 0 && s.hardwareConcurrency < 4 && (t -= 10), s.deviceMemory >= 8 ? t += 5 : s.deviceMemory >= 4 ? t += 0 : s.deviceMemory > 0 && s.deviceMemory < 4 && (t -= 15), s.isMobile && (t -= 10), t >= 0 ? "high" : t >= -25 ? "medium" : "low";
419
538
  }
420
- function Xt(s, t) {
421
- const e = t && t !== "auto" ? t : de(ce(s));
422
- return { tier: e, ...ue[e] };
539
+ function Wt(s, t) {
540
+ const e = t && t !== "auto" ? t : Ce(Pe(s));
541
+ return { tier: e, ...Ae[e] };
423
542
  }
424
- class gt {
543
+ class vt {
425
544
  static RESIZE_DEBOUNCE_MS = 100;
426
545
  // ---- Canvas + container ----
427
546
  canvas;
@@ -452,6 +571,11 @@ class gt {
452
571
  * The Web Component uses this to dispatch frame events.
453
572
  */
454
573
  onVideoFrame = null;
574
+ /**
575
+ * Optional callback invoked when a render loop error causes the loop to stop.
576
+ * The Web Component uses this to dispatch error events.
577
+ */
578
+ onError = null;
455
579
  // ---- Animation & resize ----
456
580
  animationFrameHandle = 0;
457
581
  /** requestVideoFrameCallback handle (0 = inactive). */
@@ -487,7 +611,26 @@ class gt {
487
611
  }
488
612
  /** Stop both render loops and release callbacks. */
489
613
  stop() {
490
- this.animationFrameHandle && (window.cancelAnimationFrame(this.animationFrameHandle), this.animationFrameHandle = 0), this.rvfcHandle && this.mediaSource?.cancelVideoFrameCallback && (this.mediaSource.cancelVideoFrameCallback(this.rvfcHandle), this.rvfcHandle = 0), this.mediaSource = null, this.readDepth = null, this.readInput = null, this.onVideoFrame = null, this.rvfcSupported = !1;
614
+ this.stopLoops(), this.mediaSource = null, this.readDepth = null, this.readInput = null, this.onVideoFrame = null, this.rvfcSupported = !1;
615
+ }
616
+ /**
617
+ * Pause the render loops without releasing callbacks.
618
+ * The loops can be resumed with `resume()`.
619
+ */
620
+ pause() {
621
+ this.stopLoops();
622
+ }
623
+ /** Resume render loops previously paused with `pause()`. */
624
+ resume() {
625
+ this.readInput && (this.animationFrameHandle || (this.rvfcSupported && this.mediaSource?.requestVideoFrameCallback && (this.rvfcHandle = this.mediaSource.requestVideoFrameCallback(this._videoFrameLoop)), this.animationFrameHandle = window.requestAnimationFrame(this._rafLoop)));
626
+ }
627
+ /** Whether the render loops are currently paused. */
628
+ get isPaused() {
629
+ return this.animationFrameHandle === 0 && this.readInput !== null;
630
+ }
631
+ /** Cancel animation loops without clearing callbacks. */
632
+ stopLoops() {
633
+ this.animationFrameHandle && (window.cancelAnimationFrame(this.animationFrameHandle), this.animationFrameHandle = 0), this.rvfcHandle && this.mediaSource?.cancelVideoFrameCallback && (this.mediaSource.cancelVideoFrameCallback(this.rvfcHandle), this.rvfcHandle = 0);
491
634
  }
492
635
  /** Stop rendering and release all GPU resources. */
493
636
  dispose() {
@@ -508,7 +651,14 @@ class gt {
508
651
  * Delegates to subclass `onRenderFrame()` for the actual render work.
509
652
  */
510
653
  _rafLoop = () => {
511
- this.animationFrameHandle = window.requestAnimationFrame(this._rafLoop), this.onRenderFrame();
654
+ this.animationFrameHandle = window.requestAnimationFrame(this._rafLoop);
655
+ try {
656
+ this.onRenderFrame();
657
+ } catch (t) {
658
+ this.stopLoops();
659
+ const e = t instanceof Error ? t : new Error(String(t));
660
+ console.error("Layershift: render loop stopped due to error.", e), this.onError && this.onError(e);
661
+ }
512
662
  };
513
663
  /**
514
664
  * RVFC callback — fires only when the browser presents a new video frame.
@@ -516,10 +666,17 @@ class gt {
516
666
  */
517
667
  _videoFrameLoop = (t, e) => {
518
668
  const n = this.mediaSource;
519
- if (!n || !n.requestVideoFrameCallback) return;
520
- this.rvfcHandle = n.requestVideoFrameCallback(this._videoFrameLoop);
521
- const i = e.mediaTime ?? n.currentTime;
522
- this.onDepthUpdate(i), this.onVideoFrame && this.onVideoFrame(i, e.presentedFrames ?? 0);
669
+ if (!(!n || !n.requestVideoFrameCallback)) {
670
+ this.rvfcHandle = n.requestVideoFrameCallback(this._videoFrameLoop);
671
+ try {
672
+ const i = e.mediaTime ?? n.currentTime;
673
+ this.onDepthUpdate(i), this.onVideoFrame && this.onVideoFrame(i, e.presentedFrames ?? 0);
674
+ } catch (i) {
675
+ this.stopLoops();
676
+ const r = i instanceof Error ? i : new Error(String(i));
677
+ console.error("Layershift: video frame loop stopped due to error.", r), this.onError && this.onError(r);
678
+ }
679
+ }
523
680
  };
524
681
  // -----------------------------------------------------------------------
525
682
  // Context loss handling
@@ -546,7 +703,7 @@ class gt {
546
703
  scheduleResizeRecalculate = () => {
547
704
  this.resizeTimer !== null && window.clearTimeout(this.resizeTimer), this.resizeTimer = window.setTimeout(() => {
548
705
  this.resizeTimer = null, this.recalculateViewportLayout();
549
- }, gt.RESIZE_DEBOUNCE_MS);
706
+ }, vt.RESIZE_DEBOUNCE_MS);
550
707
  };
551
708
  /** Read the container's pixel dimensions, with a minimum of 1x1. */
552
709
  getViewportSize() {
@@ -605,7 +762,7 @@ class gt {
605
762
  l /= h, a /= h, this.uvOffset = [(1 - l) / 2, (1 - a) / 2], this.uvScale = [l, a], this.isCameraSource && (this.uvOffset[0] += this.uvScale[0], this.uvScale[0] = -this.uvScale[0]);
606
763
  }
607
764
  }
608
- const me = `#version 300 es
765
+ const Ue = `#version 300 es
609
766
  in vec2 aPosition;
610
767
 
611
768
  // UV coordinates for cover-fit + overscan.
@@ -626,7 +783,7 @@ void main() {
626
783
  vScreenUv = baseUv;
627
784
  gl_Position = vec4(aPosition, 0.0, 1.0);
628
785
  }
629
- `, bt = `#version 300 es
786
+ `, St = `#version 300 es
630
787
  in vec2 aPosition;
631
788
  out vec2 vUv;
632
789
 
@@ -634,7 +791,7 @@ void main() {
634
791
  vUv = aPosition * 0.5 + 0.5;
635
792
  gl_Position = vec4(aPosition, 0.0, 1.0);
636
793
  }
637
- `, pe = `#version 300 es
794
+ `, Le = `#version 300 es
638
795
  precision highp float;
639
796
 
640
797
  // BILATERAL_RADIUS is injected as a #define at compile time.
@@ -672,7 +829,7 @@ void main() {
672
829
 
673
830
  fragColor = vec4(totalDepth / totalWeight, 0.0, 0.0, 1.0);
674
831
  }
675
- `, ge = `#version 300 es
832
+ `, _e = `#version 300 es
676
833
  precision highp float;
677
834
 
678
835
  // ---- Uniforms ----
@@ -1059,7 +1216,7 @@ void main() {
1059
1216
 
1060
1217
  fragColor = color;
1061
1218
  }
1062
- `, Ft = `#version 300 es
1219
+ `, Ut = `#version 300 es
1063
1220
  precision highp float;
1064
1221
 
1065
1222
  // Separable glow blur — 7-tap box filter.
@@ -1124,18 +1281,18 @@ void main() {
1124
1281
  tiltHalfTanFov: Math.tan(50 * Math.PI / 360),
1125
1282
  tiltTransitionWidth: 0.3 * 4.5,
1126
1283
  tiltPeakIntensity: 0.8
1127
- }, ve = ["uRawDepth", "uTexelSize", "uSpatialSigma2"], xe = {
1284
+ }, Ie = ["uRawDepth", "uTexelSize", "uSpatialSigma2"], Me = {
1128
1285
  2: 2.25,
1129
1286
  // 1.5²
1130
1287
  1: 0.5625
1131
1288
  // 0.75²
1132
1289
  };
1133
- function Te(s, t) {
1134
- const e = pe.replace(
1290
+ function Be(s, t) {
1291
+ const e = Le.replace(
1135
1292
  "#version 300 es",
1136
1293
  `#version 300 es
1137
1294
  #define BILATERAL_RADIUS ${t}`
1138
- ), n = G(s, s.VERTEX_SHADER, bt), i = G(s, s.FRAGMENT_SHADER, e), r = mt(s, n, i), o = pt(s, r, ve), l = xe[t] ?? 2.25;
1295
+ ), n = G(s, s.VERTEX_SHADER, St), i = G(s, s.FRAGMENT_SHADER, e), r = pt(s, n, i), o = gt(s, r, Ie), l = Me[t] ?? 2.25;
1139
1296
  let a = null;
1140
1297
  const h = {
1141
1298
  name: "bilateral-filter",
@@ -1147,16 +1304,16 @@ function Te(s, t) {
1147
1304
  height: 0,
1148
1305
  resize(c, f, u) {
1149
1306
  },
1150
- initFBO(c, f, u, x) {
1151
- a && c.deleteFramebuffer(a), h.width = u, h.height = x, a = c.createFramebuffer(), h.fbo = a, c.bindFramebuffer(c.FRAMEBUFFER, a), c.framebufferTexture2D(
1307
+ initFBO(c, f, u, v) {
1308
+ a && c.deleteFramebuffer(a), h.width = u, h.height = v, a = c.createFramebuffer(), h.fbo = a, c.bindFramebuffer(c.FRAMEBUFFER, a), c.framebufferTexture2D(
1152
1309
  c.FRAMEBUFFER,
1153
1310
  c.COLOR_ATTACHMENT0,
1154
1311
  c.TEXTURE_2D,
1155
1312
  f,
1156
1313
  0
1157
- ), c.bindFramebuffer(c.FRAMEBUFFER, null), c.useProgram(r), c.uniform1i(o.uRawDepth, 2), c.uniform2f(o.uTexelSize, 1 / u, 1 / x), c.uniform1f(o.uSpatialSigma2, l);
1314
+ ), c.bindFramebuffer(c.FRAMEBUFFER, null), c.useProgram(r), c.uniform1i(o.uRawDepth, 2), c.uniform2f(o.uTexelSize, 1 / u, 1 / v), c.uniform1f(o.uSpatialSigma2, l);
1158
1315
  },
1159
- execute(c, f, u, x, p, d, y, b) {
1316
+ execute(c, f, u, v, p, d, S, E) {
1160
1317
  a && (c.activeTexture(c.TEXTURE2), c.bindTexture(c.TEXTURE_2D, u), c.texSubImage2D(
1161
1318
  c.TEXTURE_2D,
1162
1319
  0,
@@ -1166,8 +1323,8 @@ function Te(s, t) {
1166
1323
  d,
1167
1324
  c.RED,
1168
1325
  c.UNSIGNED_BYTE,
1169
- x
1170
- ), c.bindFramebuffer(c.FRAMEBUFFER, a), c.viewport(0, 0, p, d), c.useProgram(r), c.bindVertexArray(f), c.drawArrays(c.TRIANGLE_STRIP, 0, 4), c.bindFramebuffer(c.FRAMEBUFFER, null), c.viewport(0, 0, y, b));
1326
+ v
1327
+ ), c.bindFramebuffer(c.FRAMEBUFFER, a), c.viewport(0, 0, p, d), c.useProgram(r), c.bindVertexArray(f), c.drawArrays(c.TRIANGLE_STRIP, 0, 4), c.bindFramebuffer(c.FRAMEBUFFER, null), c.viewport(0, 0, S, E));
1171
1328
  },
1172
1329
  dispose(c) {
1173
1330
  a && (c.deleteFramebuffer(a), a = null, h.fbo = null), c.deleteProgram(r);
@@ -1175,7 +1332,7 @@ function Te(s, t) {
1175
1332
  };
1176
1333
  return h;
1177
1334
  }
1178
- const Ee = [
1335
+ const Ve = [
1179
1336
  "uImage",
1180
1337
  "uDepth",
1181
1338
  "uOffset",
@@ -1214,13 +1371,13 @@ const Ee = [
1214
1371
  "uTiltPeakIntensity",
1215
1372
  "uTiltPlaneNormal",
1216
1373
  "uTiltPlaneD"
1217
- ], be = 64;
1218
- function Se(s) {
1219
- const t = ge.replace(
1374
+ ], Oe = 64;
1375
+ function ke(s) {
1376
+ const t = _e.replace(
1220
1377
  "#version 300 es",
1221
1378
  `#version 300 es
1222
- #define MAX_POM_STEPS ${be}`
1223
- ), e = G(s, s.VERTEX_SHADER, me), n = G(s, s.FRAGMENT_SHADER, t), i = mt(s, e, n), r = pt(s, i, Ee);
1379
+ #define MAX_POM_STEPS ${Oe}`
1380
+ ), e = G(s, s.VERTEX_SHADER, Ue), n = G(s, s.FRAGMENT_SHADER, t), i = pt(s, e, n), r = gt(s, i, Ve);
1224
1381
  return {
1225
1382
  name: "depth-effect",
1226
1383
  program: i,
@@ -1236,7 +1393,7 @@ function Se(s) {
1236
1393
  }
1237
1394
  };
1238
1395
  }
1239
- class ye extends gt {
1396
+ class He extends vt {
1240
1397
  // ---- Shared GPU resources ----
1241
1398
  gl = null;
1242
1399
  quadVao = null;
@@ -1244,7 +1401,7 @@ class ye extends gt {
1244
1401
  bilateralPass = null;
1245
1402
  effectPass = null;
1246
1403
  // ---- Texture registry (init-time allocation, zero per-frame overhead) ----
1247
- textures = new Ht();
1404
+ textures = new Gt();
1248
1405
  videoSlot;
1249
1406
  filteredDepthSlot;
1250
1407
  rawDepthSlot;
@@ -1295,7 +1452,7 @@ class ye extends gt {
1295
1452
  powerPreference: "high-performance"
1296
1453
  });
1297
1454
  if (!n) throw new Error("WebGL 2 is not supported.");
1298
- this.gl = n, this.qualityParams = Xt(n, e.quality), "drawingBufferColorSpace" in n && (n.drawingBufferColorSpace = "srgb"), n.clearColor(0, 0, 0, 1), n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL, !0), this.initGPUResources(), this.setupResizeHandling();
1455
+ this.gl = n, this.qualityParams = Wt(n, e.quality), "drawingBufferColorSpace" in n && (n.drawingBufferColorSpace = "srgb"), n.clearColor(0, 0, 0, 1), n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL, !0), this.initGPUResources(), this.setupResizeHandling();
1299
1456
  }
1300
1457
  /**
1301
1458
  * Set up the scene: create video texture, depth textures + FBO, and
@@ -1374,8 +1531,8 @@ class ye extends gt {
1374
1531
  initGPUResources() {
1375
1532
  const t = this.gl;
1376
1533
  if (!t) return;
1377
- this.bilateralPass = Te(t, this.qualityParams.bilateralRadius), this.effectPass = Se(t);
1378
- const e = Ft.replace(
1534
+ this.bilateralPass = Be(t, this.qualityParams.bilateralRadius), this.effectPass = ke(t);
1535
+ const e = Ut.replace(
1379
1536
  "#version 300 es",
1380
1537
  `#version 300 es
1381
1538
  #define PASS_HORIZONTAL`
@@ -1387,10 +1544,10 @@ class ye extends gt {
1387
1544
  "uGlowRadius",
1388
1545
  "uBlurDir"
1389
1546
  ];
1390
- this.glowBlurHPass = Dt(
1547
+ this.glowBlurHPass = Ct(
1391
1548
  t,
1392
1549
  "glow-blur-h",
1393
- bt,
1550
+ St,
1394
1551
  e,
1395
1552
  n,
1396
1553
  {
@@ -1401,11 +1558,11 @@ class ye extends gt {
1401
1558
  width: 0,
1402
1559
  height: 0
1403
1560
  }
1404
- ), this.glowBlurVPass = Dt(
1561
+ ), this.glowBlurVPass = Ct(
1405
1562
  t,
1406
1563
  "glow-blur-v",
1407
- bt,
1408
- Ft,
1564
+ St,
1565
+ Ut,
1409
1566
  n,
1410
1567
  {
1411
1568
  internalFormat: t.R8,
@@ -1415,7 +1572,7 @@ class ye extends gt {
1415
1572
  width: 0,
1416
1573
  height: 0
1417
1574
  }
1418
- ), this.quadVao = Ot(t, this.effectPass.program), t.disable(t.DEPTH_TEST);
1575
+ ), this.quadVao = Xt(t, this.effectPass.program), t.disable(t.DEPTH_TEST);
1419
1576
  }
1420
1577
  // -----------------------------------------------------------------------
1421
1578
  // Curve LUT texture management
@@ -1536,15 +1693,15 @@ class ye extends gt {
1536
1693
  t && (this.bilateralPass && (this.bilateralPass.dispose(t), this.bilateralPass = null), this.effectPass && (this.effectPass.dispose(t), this.effectPass = null), this.glowBlurHPass && (this.glowBlurHPass.dispose(t), this.glowBlurHPass = null), this.glowBlurVPass && (this.glowBlurVPass.dispose(t), this.glowBlurVPass = null), this.quadVao && (t.deleteVertexArray(this.quadVao), this.quadVao = null));
1537
1694
  }
1538
1695
  }
1539
- async function ht(s, t = {}) {
1696
+ async function ft(s, t = {}) {
1540
1697
  const {
1541
1698
  parent: e = document.body,
1542
1699
  loop: n = !0,
1543
1700
  muted: i = !0
1544
1701
  } = t, r = document.createElement("video");
1545
- return r.crossOrigin = "anonymous", r.setAttribute("crossorigin", "anonymous"), r.playsInline = !0, r.setAttribute("playsinline", ""), r.setAttribute("webkit-playsinline", "true"), r.muted = i, r.defaultMuted = i, i && r.setAttribute("muted", ""), r.loop = n, r.preload = "auto", r.style.display = "none", r.src = s, e.appendChild(r), await Gt(r), new we(r);
1702
+ return r.crossOrigin = "anonymous", r.setAttribute("crossorigin", "anonymous"), r.playsInline = !0, r.setAttribute("playsinline", ""), r.setAttribute("webkit-playsinline", "true"), r.muted = i, r.defaultMuted = i, i && r.setAttribute("muted", ""), r.loop = n, r.preload = "auto", r.style.display = "none", r.src = s, e.appendChild(r), await qt(r), new Ne(r);
1546
1703
  }
1547
- class we {
1704
+ class Ne {
1548
1705
  constructor(t) {
1549
1706
  this.video = t;
1550
1707
  }
@@ -1590,7 +1747,7 @@ class we {
1590
1747
  this.video.pause(), this.video.removeAttribute("src"), this.video.load(), this.video.remove();
1591
1748
  }
1592
1749
  }
1593
- async function ft(s, t = {}) {
1750
+ async function dt(s, t = {}) {
1594
1751
  const e = new Image();
1595
1752
  return e.crossOrigin = "anonymous", e.src = s, await new Promise((n, i) => {
1596
1753
  if (e.complete && e.naturalWidth > 0) {
@@ -1598,9 +1755,9 @@ async function ft(s, t = {}) {
1598
1755
  return;
1599
1756
  }
1600
1757
  e.addEventListener("load", () => n(), { once: !0 }), e.addEventListener("error", () => i(new Error(`Failed to load image: ${s}`)), { once: !0 });
1601
- }), new Re(e);
1758
+ }), new Xe(e);
1602
1759
  }
1603
- class Re {
1760
+ class Xe {
1604
1761
  constructor(t) {
1605
1762
  this.img = t;
1606
1763
  }
@@ -1622,11 +1779,11 @@ class Re {
1622
1779
  this.img.removeAttribute("src");
1623
1780
  }
1624
1781
  }
1625
- async function Nt(s = { video: !0 }, t = {}) {
1782
+ async function zt(s = { video: !0 }, t = {}) {
1626
1783
  const { parent: e = document.body } = t, n = await navigator.mediaDevices.getUserMedia(s), i = document.createElement("video");
1627
- return i.playsInline = !0, i.setAttribute("playsinline", ""), i.muted = !0, i.defaultMuted = !0, i.style.display = "none", i.srcObject = n, e.appendChild(i), await Gt(i), await i.play(), new Ae(i, n);
1784
+ return i.playsInline = !0, i.setAttribute("playsinline", ""), i.muted = !0, i.defaultMuted = !0, i.style.display = "none", i.srcObject = n, e.appendChild(i), await qt(i), await i.play(), new Ge(i, n);
1628
1785
  }
1629
- class Ae {
1786
+ class Ge {
1630
1787
  constructor(t, e) {
1631
1788
  this.video = t, this.stream = e;
1632
1789
  }
@@ -1672,7 +1829,7 @@ class Ae {
1672
1829
  t.stop();
1673
1830
  }
1674
1831
  }
1675
- async function Gt(s) {
1832
+ async function qt(s) {
1676
1833
  s.readyState >= HTMLMediaElement.HAVE_METADATA || await new Promise((t, e) => {
1677
1834
  const n = () => {
1678
1835
  r(), t();
@@ -1684,11 +1841,17 @@ async function Gt(s) {
1684
1841
  s.addEventListener("loadedmetadata", n), s.addEventListener("error", i), s.load();
1685
1842
  });
1686
1843
  }
1844
+ async function Lt(s, t, e) {
1845
+ return s.create(t, {
1846
+ executionProviders: e,
1847
+ graphOptimizationLevel: "disabled"
1848
+ });
1849
+ }
1687
1850
  const Z = 518;
1688
- async function Pe() {
1851
+ async function We() {
1689
1852
  return await import("onnxruntime-web/webgpu");
1690
1853
  }
1691
- class De {
1854
+ class ze {
1692
1855
  constructor(t, e) {
1693
1856
  this.depthWidth = t, this.depthHeight = e;
1694
1857
  const n = t * e;
@@ -1727,23 +1890,19 @@ class De {
1727
1890
  * (GPU-accelerated on main thread), falls back to WASM EP.
1728
1891
  */
1729
1892
  async init(t, e) {
1730
- const n = await Pe();
1893
+ const n = await We();
1731
1894
  if (this.ort = n, this.captureCanvas = document.createElement("canvas"), this.captureCanvas.width = Z, this.captureCanvas.height = Z, this.captureCtx = this.captureCanvas.getContext("2d", {
1732
1895
  willReadFrequently: !0
1733
1896
  }), !this.captureCtx)
1734
1897
  throw new Error("[DepthEstimator] Failed to create 2D canvas context.");
1735
1898
  e?.({ receivedBytes: 0, totalBytes: null, fraction: 0, label: "Downloading depth model…" });
1736
- const i = await Fe(t, e);
1899
+ const i = await qe(t, e);
1737
1900
  e?.({ receivedBytes: i.byteLength, totalBytes: i.byteLength, fraction: 1, label: "Initialising depth model…" });
1738
1901
  let r;
1739
1902
  try {
1740
- r = await n.InferenceSession.create(i, {
1741
- executionProviders: ["webgpu"]
1742
- }), console.log("[DepthEstimator] Using WebGPU execution provider");
1903
+ r = await Lt(n.InferenceSession, i, ["webgpu"]), console.log("[DepthEstimator] Using WebGPU execution provider");
1743
1904
  } catch (o) {
1744
- console.warn("[DepthEstimator] WebGPU EP unavailable, falling back to WASM:", o), n.env.wasm.proxy = !0, r = await n.InferenceSession.create(i, {
1745
- executionProviders: ["wasm"]
1746
- }), console.log("[DepthEstimator] Using WASM execution provider (proxy worker)");
1905
+ console.warn("[DepthEstimator] WebGPU EP unavailable, falling back to WASM:", o), n.env.wasm.proxy = !0, r = await Lt(n.InferenceSession, i, ["wasm"]), console.log("[DepthEstimator] Using WASM execution provider (proxy worker)");
1747
1906
  }
1748
1907
  this.session = r, this.inputName = r.inputNames[0], this.outputName = r.outputNames[0], this.preprocessWorker = new Worker(
1749
1908
  new URL(
@@ -1855,11 +2014,11 @@ class De {
1855
2014
  });
1856
2015
  }
1857
2016
  }
1858
- async function dt(s, t, e, n) {
1859
- const i = new De(t, e);
2017
+ async function mt(s, t, e, n) {
2018
+ const i = new ze(t, e);
1860
2019
  return await i.init(s, n), i;
1861
2020
  }
1862
- async function Fe(s, t) {
2021
+ async function qe(s, t) {
1863
2022
  const e = await fetch(s);
1864
2023
  if (!e.ok)
1865
2024
  throw new Error(`[DepthEstimator] Failed to fetch model (${e.status} ${e.statusText}).`);
@@ -1892,12 +2051,12 @@ async function Fe(s, t) {
1892
2051
  h.set(f, c), c += f.byteLength;
1893
2052
  return h.buffer;
1894
2053
  }
1895
- const Ct = {
2054
+ const _t = {
1896
2055
  sensitivityX: 0.4,
1897
2056
  sensitivityY: 1,
1898
2057
  lerpFactor: 0.08
1899
2058
  };
1900
- function St(s, t) {
2059
+ function yt(s, t) {
1901
2060
  const e = s.points;
1902
2061
  if (e.length === 0) return 0;
1903
2062
  if (e.length === 1 || t <= e[0].x) return e[0].y;
@@ -1918,28 +2077,28 @@ function St(s, t) {
1918
2077
  return i.y + (r.y - i.y) * o;
1919
2078
  }
1920
2079
  }
1921
- function lt(s, t = 256) {
2080
+ function ut(s, t = 256) {
1922
2081
  const e = new Uint8Array(t);
1923
2082
  for (let n = 0; n < t; n++) {
1924
2083
  const i = n / (t - 1);
1925
- e[n] = Math.round(St(s, i) * 255);
2084
+ e[n] = Math.round(yt(s, i) * 255);
1926
2085
  }
1927
2086
  return e;
1928
2087
  }
1929
2088
  function q(s, t) {
1930
2089
  return s.find((e) => e.channel === t && e.enabled);
1931
2090
  }
1932
- function Ut(s, t) {
2091
+ function It(s, t) {
1933
2092
  const e = q(s, "displacement"), n = q(s, "blur"), i = q(s, "glow"), r = e?.params;
1934
2093
  let o = 0.6, l = 0;
1935
2094
  if (n) {
1936
2095
  const a = n.curve;
1937
2096
  for (let h = 0; h <= 1; h += 0.01)
1938
- if (St(a, h) > 0.01) {
2097
+ if (yt(a, h) > 0.01) {
1939
2098
  o = h;
1940
2099
  break;
1941
2100
  }
1942
- l = St(a, 1);
2101
+ l = yt(a, 1);
1943
2102
  }
1944
2103
  return {
1945
2104
  parallaxStrength: r?.strength ?? 0.05,
@@ -1960,13 +2119,13 @@ function Ut(s, t) {
1960
2119
  tiltPeakIntensity: n?.params?.peakIntensity ?? 0.8
1961
2120
  };
1962
2121
  }
1963
- function Lt(s) {
2122
+ function Mt(s) {
1964
2123
  const t = q(s, "displacement"), e = q(s, "blur"), n = q(s, "glow"), i = q(s, "color-shift"), r = i?.params;
1965
2124
  return {
1966
- displacementLUT: t ? lt(t.curve) : null,
1967
- blurLUT: e ? lt(e.curve) : null,
1968
- glowLUT: n ? lt(n.curve) : null,
1969
- colorShiftLUT: i ? lt(i.curve) : null,
2125
+ displacementLUT: t ? ut(t.curve) : null,
2126
+ blurLUT: e ? ut(e.curve) : null,
2127
+ glowLUT: n ? ut(n.curve) : null,
2128
+ colorShiftLUT: i ? ut(i.curve) : null,
1970
2129
  colorShiftParams: r ? {
1971
2130
  hueShift: r.hueShift ?? 0,
1972
2131
  saturation: r.saturation ?? 1,
@@ -1976,7 +2135,7 @@ function Lt(s) {
1976
2135
  } : null
1977
2136
  };
1978
2137
  }
1979
- class Wt {
2138
+ class Yt {
1980
2139
  abortController = null;
1981
2140
  initialized = !1;
1982
2141
  initializing = !1;
@@ -1986,7 +2145,7 @@ class Wt {
1986
2145
  }
1987
2146
  // --- Public API (called from lifecycle callbacks) ---
1988
2147
  onConnected() {
1989
- this.element.setupShadowDOM(), this.tryInit();
2148
+ this.cancelInit(), this.element.setupShadowDOM(), this.tryInit();
1990
2149
  }
1991
2150
  onDisconnected() {
1992
2151
  this.cancelInit(), this.element.doDispose(), this.initialized = !1;
@@ -2014,12 +2173,10 @@ class Wt {
2014
2173
  const e = new AbortController();
2015
2174
  this.abortController = e, this.initializing = !0;
2016
2175
  try {
2017
- if (await t.doInit(e.signal), e.signal.aborted) {
2018
- this.initializing = !1;
2019
- return;
2020
- }
2176
+ await t.doInit(e.signal);
2021
2177
  } catch {
2022
- this.initializing = !1;
2178
+ } finally {
2179
+ this.initialized || (this.initializing = !1);
2023
2180
  }
2024
2181
  }
2025
2182
  cancelInit() {
@@ -2035,15 +2192,15 @@ const z = {
2035
2192
  loop: !0,
2036
2193
  muted: !0
2037
2194
  }, $ = 512, K = 512;
2038
- class xt extends HTMLElement {
2195
+ class Tt extends HTMLElement {
2039
2196
  static TAG_NAME = "layershift-effect";
2040
2197
  static get observedAttributes() {
2041
2198
  return [
2042
2199
  "src",
2043
- "depth-src",
2044
- "depth-width",
2045
- "depth-height",
2046
- "depth-fps",
2200
+ "map-src",
2201
+ "map-width",
2202
+ "map-height",
2203
+ "map-fps",
2047
2204
  "depth-model",
2048
2205
  "source-type",
2049
2206
  "config",
@@ -2059,10 +2216,10 @@ class xt extends HTMLElement {
2059
2216
  "muted"
2060
2217
  ];
2061
2218
  }
2062
- reinitAttributes = ["src", "depth-src", "depth-width", "depth-height", "depth-fps", "depth-model", "source-type", "config"];
2219
+ reinitAttributes = ["src", "map-src", "map-width", "map-height", "map-fps", "depth-model", "source-type", "config"];
2063
2220
  canInit() {
2064
2221
  if (this.sourceType === "camera") return !0;
2065
- const t = !!this.getAttribute("src"), e = !!this.getAttribute("depth-src"), n = !!this.getAttribute("depth-model");
2222
+ const t = !!this.getAttribute("src"), e = !!this.getAttribute("map-src"), n = !!this.getAttribute("depth-model");
2066
2223
  return t && (e || n);
2067
2224
  }
2068
2225
  shadow;
@@ -2080,7 +2237,7 @@ class xt extends HTMLElement {
2080
2237
  */
2081
2238
  depthFallback = null;
2082
2239
  constructor() {
2083
- super(), this.shadow = this.attachShadow({ mode: "open" }), this.lifecycle = new Wt(this);
2240
+ super(), this.shadow = this.attachShadow({ mode: "open" }), this.lifecycle = new Yt(this);
2084
2241
  }
2085
2242
  /** The current input offset. Set this externally to drive the effect. */
2086
2243
  get input() {
@@ -2222,7 +2379,7 @@ class xt extends HTMLElement {
2222
2379
  const i = await n.json();
2223
2380
  return {
2224
2381
  channels: i.channels ?? [],
2225
- motion: i.motion ?? Ct,
2382
+ motion: i.motion ?? _t,
2226
2383
  overscanPadding: i.overscanPadding ?? 0.05,
2227
2384
  quality: i.quality ?? "auto"
2228
2385
  };
@@ -2258,7 +2415,7 @@ class xt extends HTMLElement {
2258
2415
  this.emit("layershift-effect:model-progress", m);
2259
2416
  };
2260
2417
  if (e) {
2261
- if (i = await Nt(
2418
+ if (i = await zt(
2262
2419
  { video: { facingMode: "user" } },
2263
2420
  { parent: this.shadow }
2264
2421
  ), t.aborted) {
@@ -2266,27 +2423,27 @@ class xt extends HTMLElement {
2266
2423
  return;
2267
2424
  }
2268
2425
  if (n) {
2269
- if (o = await dt(n, $, K, l), t.aborted) {
2426
+ if (o = await mt(n, $, K, l), t.aborted) {
2270
2427
  o.dispose(), i.dispose();
2271
2428
  return;
2272
2429
  }
2273
- r = X($, K);
2430
+ r = N($, K);
2274
2431
  } else
2275
- r = X(i.width, i.height);
2432
+ r = N(i.width, i.height);
2276
2433
  } else {
2277
- const m = this.getAttribute("src"), T = this.getAttribute("depth-src"), w = !!T, A = this.sourceType === "image" || /\.(jpe?g|png|webp|gif|avif|bmp)(\?|$)/i.test(m);
2434
+ const m = this.getAttribute("src"), T = this.getAttribute("map-src"), w = !!T, A = this.sourceType === "image" || /\.(jpe?g|png|webp|gif|avif|bmp)(\?|$)/i.test(m);
2278
2435
  if (w) {
2279
2436
  const [P, F] = await Promise.all([
2280
- A ? ft(m) : ht(m, {
2437
+ A ? dt(m) : ft(m, {
2281
2438
  parent: this.shadow,
2282
2439
  loop: this.shouldLoop,
2283
2440
  muted: this.shouldMute
2284
2441
  }),
2285
- kt(
2442
+ Nt(
2286
2443
  T,
2287
- this.getAttrFloat("depth-width", 512),
2288
- this.getAttrFloat("depth-height", 512),
2289
- this.getAttrFloat("depth-fps", 5)
2444
+ this.getAttrFloat("map-width", 512),
2445
+ this.getAttrFloat("map-height", 512),
2446
+ this.getAttrFloat("map-fps", 5)
2290
2447
  )
2291
2448
  ]);
2292
2449
  if (t.aborted) {
@@ -2296,12 +2453,12 @@ class xt extends HTMLElement {
2296
2453
  i = P, r = F;
2297
2454
  } else if (n) {
2298
2455
  const [P, F] = await Promise.all([
2299
- A ? ft(m) : ht(m, {
2456
+ A ? dt(m) : ft(m, {
2300
2457
  parent: this.shadow,
2301
2458
  loop: this.shouldLoop,
2302
2459
  muted: this.shouldMute
2303
2460
  }),
2304
- dt(n, $, K, l)
2461
+ mt(n, $, K, l)
2305
2462
  ]);
2306
2463
  if (t.aborted) {
2307
2464
  P.dispose(), F.dispose();
@@ -2319,18 +2476,18 @@ class xt extends HTMLElement {
2319
2476
  frames: [I]
2320
2477
  };
2321
2478
  } else
2322
- r = X($, K);
2479
+ r = N($, K);
2323
2480
  } else
2324
- r = X($, K);
2481
+ r = N($, K);
2325
2482
  } else
2326
- throw new Error("Either depth-src or depth-model must be provided.");
2483
+ throw new Error("Either map-src or depth-model must be provided.");
2327
2484
  }
2328
2485
  this.source = i, this.depthEstimator = o, this.loopCount = 0, this.attachSourceEventListeners(i);
2329
- const a = re(
2486
+ const a = be(
2330
2487
  r.frames,
2331
2488
  r.width,
2332
2489
  r.height
2333
- ), h = se(a);
2490
+ ), h = Se(a);
2334
2491
  this.depthFallback = {
2335
2492
  contrastLow: h.contrastLow,
2336
2493
  contrastHigh: h.contrastHigh,
@@ -2340,15 +2497,15 @@ class xt extends HTMLElement {
2340
2497
  if (o)
2341
2498
  c = () => o.getLatestDepth();
2342
2499
  else {
2343
- const m = new Vt(r);
2500
+ const m = new Ht(r);
2344
2501
  c = (T) => m.sample(T);
2345
2502
  }
2346
2503
  if (t.aborted) return;
2347
- let f, u = null, x = Ct;
2504
+ let f, u = null, v = _t;
2348
2505
  const p = await this.fetchFilterConfig(t);
2349
2506
  if (t.aborted) return;
2350
2507
  if (p && p.channels.length > 0) {
2351
- const m = Ut(p.channels, {
2508
+ const m = It(p.channels, {
2352
2509
  contrastLow: h.contrastLow,
2353
2510
  contrastHigh: h.contrastHigh,
2354
2511
  verticalReduction: h.verticalReduction
@@ -2372,37 +2529,39 @@ class xt extends HTMLElement {
2372
2529
  tiltHalfTanFov: m.tiltHalfTanFov,
2373
2530
  tiltTransitionWidth: m.tiltTransitionWidth,
2374
2531
  tiltPeakIntensity: m.tiltPeakIntensity
2375
- }, u = Lt(p.channels), x = p.motion;
2532
+ }, u = Mt(p.channels), v = p.motion;
2376
2533
  } else
2377
2534
  f = this.buildLegacyConfig(h, i.width);
2378
- this.renderer = new ye(this.container, f), this.renderer.initialize(i, r.width, r.height), u && this.renderer.updateCurveLUTs(
2535
+ this.renderer = new He(this.container, f), this.renderer.onError = (m) => {
2536
+ this.emit("layershift-effect:error", { message: m.message });
2537
+ }, this.renderer.initialize(i, r.width, r.height), u && this.renderer.updateCurveLUTs(
2379
2538
  u.displacementLUT,
2380
2539
  u.blurLUT,
2381
2540
  u.glowLUT,
2382
2541
  u.colorShiftLUT,
2383
2542
  u.colorShiftParams ?? void 0
2384
2543
  );
2385
- const d = x.tiltPlaneInput ?? !1, y = x.tiltPitchSensitivity ?? 0.35, b = x.tiltYawSensitivity ?? 0.15, g = p?.channels.find((m) => m.channel === "blur" && m.enabled)?.params?.focalCenter ?? 0.5, v = o;
2544
+ const d = v.tiltPlaneInput ?? !1, S = v.tiltPitchSensitivity ?? 0.35, E = v.tiltYawSensitivity ?? 0.15, g = p?.channels.find((m) => m.channel === "blur" && m.enabled)?.params?.focalCenter ?? 0.5, x = o;
2386
2545
  if (this.renderer.start(
2387
2546
  i,
2388
2547
  c,
2389
2548
  () => {
2390
2549
  const m = this._input;
2391
2550
  if (d) {
2392
- const A = m.y * y, P = m.x * b, F = Math.cos(A), _ = Math.sin(A), I = Math.cos(P), S = Math.sin(P) * F, D = -_, U = I * F, M = 0.5 + g * (5 - 0.5);
2551
+ const A = m.y * S, P = m.x * E, F = Math.cos(A), _ = Math.sin(A), I = Math.cos(P), y = Math.sin(P) * F, D = -_, U = I * F, M = 0.5 + g * (5 - 0.5);
2393
2552
  return {
2394
2553
  x: m.x * 0.3,
2395
2554
  y: m.y * 0.3,
2396
- tiltPlaneNormal: [S, D, U],
2555
+ tiltPlaneNormal: [y, D, U],
2397
2556
  tiltPlaneD: U * M
2398
2557
  };
2399
2558
  }
2400
2559
  return { x: m.x, y: m.y };
2401
2560
  },
2402
2561
  (m, T) => {
2403
- if (v) {
2562
+ if (x) {
2404
2563
  const w = i.getImageSource();
2405
- w && v.submitFrame(w);
2564
+ w && x.submitFrame(w);
2406
2565
  }
2407
2566
  this.emit("layershift-effect:frame", {
2408
2567
  currentTime: m,
@@ -2421,13 +2580,43 @@ class xt extends HTMLElement {
2421
2580
  duration: i.duration,
2422
2581
  depthProfile: a,
2423
2582
  derivedParams: h,
2424
- motionConfig: x
2583
+ motionConfig: v
2425
2584
  });
2426
2585
  } catch (i) {
2427
2586
  const r = i instanceof Error ? i.message : "Failed to initialize.";
2428
2587
  console.error("<layershift-effect>: Failed to initialize.", i), this.emit("layershift-effect:error", { message: r });
2429
2588
  }
2430
2589
  }
2590
+ // --- Playback control ---
2591
+ /** Whether the effect is currently paused. */
2592
+ get paused() {
2593
+ return this.renderer ? this.renderer.isPaused : this.source?.paused ?? !0;
2594
+ }
2595
+ /**
2596
+ * Pause the effect: stops the renderer animation loop and pauses the
2597
+ * underlying media source. Dispatches a `layershift-effect:pause` event.
2598
+ */
2599
+ pause() {
2600
+ !this.renderer || this.paused || (this.renderer.pause(), this.source?.pause?.(), this.emit("layershift-effect:pause", {
2601
+ currentTime: this.source?.currentTime ?? 0
2602
+ }));
2603
+ }
2604
+ /**
2605
+ * Resume the effect: restarts the renderer animation loop and plays the
2606
+ * underlying media source. Dispatches a `layershift-effect:play` event.
2607
+ */
2608
+ async play() {
2609
+ if (!(!this.renderer || !this.paused)) {
2610
+ if (this.renderer.resume(), this.source?.play)
2611
+ try {
2612
+ await this.source.play();
2613
+ } catch {
2614
+ }
2615
+ this.emit("layershift-effect:play", {
2616
+ currentTime: this.source?.currentTime ?? 0
2617
+ });
2618
+ }
2619
+ }
2431
2620
  // --- Live config updates ---
2432
2621
  /**
2433
2622
  * Push new channel parameters to the renderer at runtime.
@@ -2444,9 +2633,9 @@ class xt extends HTMLElement {
2444
2633
  contrastLow: 0.05,
2445
2634
  contrastHigh: 0.95,
2446
2635
  verticalReduction: 0.5
2447
- }, n = Ut(t, e);
2636
+ }, n = It(t, e);
2448
2637
  this.renderer.updateConfig(n);
2449
- const i = Lt(t);
2638
+ const i = Mt(t);
2450
2639
  this.renderer.updateCurveLUTs(
2451
2640
  i.displacementLUT,
2452
2641
  i.blurLUT,
@@ -2460,7 +2649,7 @@ class xt extends HTMLElement {
2460
2649
  this.renderer?.dispose(), this.renderer = null, this.depthEstimator?.dispose(), this.depthEstimator = null, this.source?.dispose(), this.source = null, this.depthFallback = null, this.loopCount = 0, this.container = null;
2461
2650
  }
2462
2651
  }
2463
- class Rt {
2652
+ class Pt {
2464
2653
  gl;
2465
2654
  hasColorBufferFloat;
2466
2655
  // FBO / texture resources
@@ -2511,8 +2700,8 @@ class Rt {
2511
2700
  const r = Math.max(1, Math.round(t / n)), o = Math.max(1, Math.round(e / n));
2512
2701
  this._width = r, this._height = o;
2513
2702
  const l = (h, c, f, u) => {
2514
- const x = i.createFramebuffer();
2515
- return i.bindFramebuffer(i.FRAMEBUFFER, x), i.bindTexture(i.TEXTURE_2D, h), i.texStorage2D(i.TEXTURE_2D, 1, c, f, u), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_MIN_FILTER, i.LINEAR), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_MAG_FILTER, i.LINEAR), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_WRAP_S, i.CLAMP_TO_EDGE), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_WRAP_T, i.CLAMP_TO_EDGE), i.framebufferTexture2D(i.FRAMEBUFFER, i.COLOR_ATTACHMENT0, i.TEXTURE_2D, h, 0), i.bindFramebuffer(i.FRAMEBUFFER, null), x;
2703
+ const v = i.createFramebuffer();
2704
+ return i.bindFramebuffer(i.FRAMEBUFFER, v), i.bindTexture(i.TEXTURE_2D, h), i.texStorage2D(i.TEXTURE_2D, 1, c, f, u), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_MIN_FILTER, i.LINEAR), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_MAG_FILTER, i.LINEAR), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_WRAP_S, i.CLAMP_TO_EDGE), i.texParameteri(i.TEXTURE_2D, i.TEXTURE_WRAP_T, i.CLAMP_TO_EDGE), i.framebufferTexture2D(i.FRAMEBUFFER, i.COLOR_ATTACHMENT0, i.TEXTURE_2D, h, 0), i.bindFramebuffer(i.FRAMEBUFFER, null), v;
2516
2705
  };
2517
2706
  this.maskTex = i.createTexture(), this.maskFbo = l(this.maskTex, i.R8, r, o);
2518
2707
  const a = this.hasColorBufferFloat ? i.RG16F : i.RGBA8;
@@ -2535,7 +2724,7 @@ class Rt {
2535
2724
  const n = this._width, i = this._height;
2536
2725
  if (n === 0 || i === 0) return;
2537
2726
  e.viewport(0, 0, n, i), e.disable(e.STENCIL_TEST), e.disable(e.BLEND), e.bindFramebuffer(e.FRAMEBUFFER, this.maskFbo), e.clearColor(0, 0, 0, 1), e.clear(e.COLOR_BUFFER_BIT), e.useProgram(t.maskPass.program), e.uniform2f(t.maskPass.uniforms.uMeshScale, t.meshScaleX, t.meshScaleY), e.bindVertexArray(t.maskVao), e.drawElements(e.TRIANGLES, t.stencilIndexCount, e.UNSIGNED_SHORT, 0), e.bindFramebuffer(e.FRAMEBUFFER, this.pingFbo), e.clearColor(-1, -1, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.useProgram(t.seedPass.program), e.activeTexture(e.TEXTURE5), e.bindTexture(e.TEXTURE_2D, this.maskTex), e.uniform1i(t.seedPass.uniforms.uMask, 5), e.uniform2f(t.seedPass.uniforms.uTexelSize, 1 / n, 1 / i), e.bindVertexArray(t.quadVao), e.drawArrays(e.TRIANGLE_STRIP, 0, 4);
2538
- const r = Rt.computeFloodIterations(n, i);
2727
+ const r = Pt.computeFloodIterations(n, i);
2539
2728
  e.useProgram(t.floodPass.program);
2540
2729
  let o = this.pingTex, l = this.pongFbo, a = this.pongTex;
2541
2730
  for (let h = 0; h < r.length; h++) {
@@ -2568,34 +2757,34 @@ class Rt {
2568
2757
  this.maskTex && (t.deleteTexture(this.maskTex), this.maskTex = null), this.maskFbo && (t.deleteFramebuffer(this.maskFbo), this.maskFbo = null), this.pingTex && (t.deleteTexture(this.pingTex), this.pingTex = null), this.pingFbo && (t.deleteFramebuffer(this.pingFbo), this.pingFbo = null), this.pongTex && (t.deleteTexture(this.pongTex), this.pongTex = null), this.pongFbo && (t.deleteFramebuffer(this.pongFbo), this.pongFbo = null), this.distTex && (t.deleteTexture(this.distTex), this.distTex = null), this.distFbo && (t.deleteFramebuffer(this.distFbo), this.distFbo = null), this._width = 0, this._height = 0, this._dirty = !0;
2569
2758
  }
2570
2759
  }
2571
- const Ce = `#version 300 es
2760
+ const Ye = `#version 300 es
2572
2761
  in vec2 aPosition;
2573
2762
  uniform vec2 uMeshScale;
2574
2763
  void main() {
2575
2764
  gl_Position = vec4(aPosition * uMeshScale, 0.0, 1.0);
2576
2765
  }
2577
- `, Ue = `#version 300 es
2766
+ `, je = `#version 300 es
2578
2767
  precision lowp float;
2579
2768
  out vec4 fragColor;
2580
2769
  void main() { fragColor = vec4(0.0); }
2581
- `, Le = `#version 300 es
2770
+ `, Ze = `#version 300 es
2582
2771
  in vec2 aPosition;
2583
2772
  uniform vec2 uMeshScale;
2584
2773
  void main() {
2585
2774
  gl_Position = vec4(aPosition * uMeshScale, 0.0, 1.0);
2586
2775
  }
2587
- `, _e = `#version 300 es
2776
+ `, $e = `#version 300 es
2588
2777
  precision lowp float;
2589
2778
  out vec4 fragColor;
2590
2779
  void main() { fragColor = vec4(1.0); }
2591
- `, Ie = `#version 300 es
2780
+ `, Ke = `#version 300 es
2592
2781
  in vec2 aPosition;
2593
2782
  out vec2 vUv;
2594
2783
  void main() {
2595
2784
  vUv = aPosition * 0.5 + 0.5;
2596
2785
  gl_Position = vec4(aPosition, 0.0, 1.0);
2597
2786
  }
2598
- `, Me = `#version 300 es
2787
+ `, Je = `#version 300 es
2599
2788
  precision highp float;
2600
2789
  uniform sampler2D uMask;
2601
2790
  uniform vec2 uTexelSize;
@@ -2620,14 +2809,14 @@ void main() {
2620
2809
  fragSeed = vec2(-1.0);
2621
2810
  }
2622
2811
  }
2623
- `, Be = `#version 300 es
2812
+ `, Qe = `#version 300 es
2624
2813
  in vec2 aPosition;
2625
2814
  out vec2 vUv;
2626
2815
  void main() {
2627
2816
  vUv = aPosition * 0.5 + 0.5;
2628
2817
  gl_Position = vec4(aPosition, 0.0, 1.0);
2629
2818
  }
2630
- `, Ve = `#version 300 es
2819
+ `, tn = `#version 300 es
2631
2820
  precision highp float;
2632
2821
  uniform sampler2D uSeedTex;
2633
2822
  uniform float uStepSize;
@@ -2656,14 +2845,14 @@ void main() {
2656
2845
 
2657
2846
  fragSeed = bestSeed;
2658
2847
  }
2659
- `, ke = `#version 300 es
2848
+ `, en = `#version 300 es
2660
2849
  in vec2 aPosition;
2661
2850
  out vec2 vUv;
2662
2851
  void main() {
2663
2852
  vUv = aPosition * 0.5 + 0.5;
2664
2853
  gl_Position = vec4(aPosition, 0.0, 1.0);
2665
2854
  }
2666
- `, Oe = `#version 300 es
2855
+ `, nn = `#version 300 es
2667
2856
  precision highp float;
2668
2857
  uniform sampler2D uSeedTex;
2669
2858
  uniform sampler2D uMask;
@@ -2688,7 +2877,7 @@ void main() {
2688
2877
  float normalized = clamp(d / max(uBevelWidth, 0.001), 0.0, 1.0);
2689
2878
  fragDist = vec4(normalized, 0.0, 0.0, 1.0);
2690
2879
  }
2691
- `, He = `#version 300 es
2880
+ `, rn = `#version 300 es
2692
2881
  in vec2 aPosition;
2693
2882
  uniform vec2 uUvOffset;
2694
2883
  uniform vec2 uUvScale;
@@ -2700,7 +2889,7 @@ void main() {
2700
2889
  vScreenUv = baseUv;
2701
2890
  gl_Position = vec4(aPosition, 0.0, 1.0);
2702
2891
  }
2703
- `, Xe = `#version 300 es
2892
+ `, sn = `#version 300 es
2704
2893
  precision highp float;
2705
2894
 
2706
2895
  #define MAX_POM_STEPS 32
@@ -2831,14 +3020,14 @@ void main() {
2831
3020
  // Write lens-transformed depth to second attachment for boundary effects
2832
3021
  fragDepth = vec4(lensD, 0.0, 0.0, 1.0);
2833
3022
  }
2834
- `, Ne = `#version 300 es
3023
+ `, on = `#version 300 es
2835
3024
  in vec2 aPosition;
2836
3025
  out vec2 vUv;
2837
3026
  void main() {
2838
3027
  vUv = aPosition * 0.5 + 0.5;
2839
3028
  gl_Position = vec4(aPosition, 0.0, 1.0);
2840
3029
  }
2841
- `, Ge = `#version 300 es
3030
+ `, an = `#version 300 es
2842
3031
  precision highp float;
2843
3032
  uniform sampler2D uInteriorColor;
2844
3033
  uniform sampler2D uDistField;
@@ -2868,7 +3057,7 @@ void main() {
2868
3057
 
2869
3058
  fragColor = vec4(toSRGB(linear), color.a);
2870
3059
  }
2871
- `, We = `#version 300 es
3060
+ `, ln = `#version 300 es
2872
3061
  in vec2 aPosition;
2873
3062
  in vec2 aNormal;
2874
3063
  uniform float uRimWidth;
@@ -2891,7 +3080,7 @@ void main() {
2891
3080
 
2892
3081
  gl_Position = vec4(pos, 0.0, 1.0);
2893
3082
  }
2894
- `, ze = `#version 300 es
3083
+ `, un = `#version 300 es
2895
3084
  precision highp float;
2896
3085
 
2897
3086
  uniform sampler2D uInteriorColor;
@@ -2993,7 +3182,7 @@ void main() {
2993
3182
 
2994
3183
  fragColor = vec4(color * alpha, alpha);
2995
3184
  }
2996
- `, qe = `#version 300 es
3185
+ `, cn = `#version 300 es
2997
3186
  in vec2 aPosition;
2998
3187
  in vec3 aNormal3;
2999
3188
  in float aLerpT; // 0 = inner (at silhouette), 1 = outer edge
@@ -3009,7 +3198,7 @@ void main() {
3009
3198
  vLerpT = aLerpT;
3010
3199
  gl_Position = vec4(sp, 0.0, 1.0);
3011
3200
  }
3012
- `, Ye = `#version 300 es
3201
+ `, hn = `#version 300 es
3013
3202
  precision highp float;
3014
3203
  uniform vec3 uLightDir3;
3015
3204
  uniform vec3 uChamferColor;
@@ -3077,7 +3266,7 @@ void main() {
3077
3266
  fragColor = vec4(toSRGB(lit), 1.0);
3078
3267
  }
3079
3268
  `;
3080
- function je(s) {
3269
+ function fn(s) {
3081
3270
  const t = [];
3082
3271
  let e = 0;
3083
3272
  for (let n = 0; n < s.length - 2; n += 2) {
@@ -3116,7 +3305,7 @@ function je(s) {
3116
3305
  count: e
3117
3306
  };
3118
3307
  }
3119
- function Ze(s, t, e, n, i) {
3308
+ function dn(s, t, e, n, i) {
3120
3309
  if (n <= 0)
3121
3310
  return { vertices: new Float32Array(0), count: 0 };
3122
3311
  const r = i * Math.PI / 180, o = -Math.cos(r), l = Math.sin(r), a = [];
@@ -3125,26 +3314,26 @@ function Ze(s, t, e, n, i) {
3125
3314
  const f = t[c], p = ((c + 1 < t.length ? t[c + 1] : s.length) - f) / 2;
3126
3315
  if (p < 3) continue;
3127
3316
  const d = p - 1;
3128
- let y = 0;
3317
+ let S = 0;
3129
3318
  for (let T = 0; T < d; T++) {
3130
3319
  const w = f + T * 2, A = s[w], P = s[w + 1], F = s[w + 2], _ = s[w + 3];
3131
- y += A * _ - F * P;
3320
+ S += A * _ - F * P;
3132
3321
  }
3133
- const b = y >= 0 ? 1 : -1, E = [], g = [];
3322
+ const E = S >= 0 ? 1 : -1, b = [], g = [];
3134
3323
  for (let T = 0; T < d; T++) {
3135
3324
  const w = f + T * 2, A = s[w + 2] - s[w], P = s[w + 3] - s[w + 1], F = Math.sqrt(A * A + P * P);
3136
- F < 1e-8 ? (E.push(T > 0 ? E[T - 1] : 0), g.push(T > 0 ? g[T - 1] : 0)) : (E.push(-P / F * b), g.push(A / F * b));
3325
+ F < 1e-8 ? (b.push(T > 0 ? b[T - 1] : 0), g.push(T > 0 ? g[T - 1] : 0)) : (b.push(-P / F * E), g.push(A / F * E));
3137
3326
  }
3138
- const v = [], m = [];
3327
+ const x = [], m = [];
3139
3328
  for (let T = 0; T < d; T++) {
3140
3329
  const w = (T - 1 + d) % d;
3141
- let A = E[w] + E[T], P = g[w] + g[T];
3330
+ let A = b[w] + b[T], P = g[w] + g[T];
3142
3331
  const F = Math.sqrt(A * A + P * P);
3143
- F > 1e-8 ? (A /= F, P /= F) : (A = E[T], P = g[T]), v.push(A), m.push(P);
3332
+ F > 1e-8 ? (A /= F, P /= F) : (A = b[T], P = g[T]), x.push(A), m.push(P);
3144
3333
  }
3145
3334
  for (let T = 0; T < d; T++) {
3146
- const w = T, A = (T + 1) % d, P = f + T * 2, F = f + (T + 1) % d * 2, _ = s[P], I = s[P + 1], C = s[F], S = s[F + 1], D = v[w] * l, U = m[w] * l, M = o, k = v[A] * l, j = m[A] * l, et = o, at = _ + v[w] * n, At = I + m[w] * n, Jt = C + v[A] * n, Qt = S + m[A] * n;
3147
- a.push(_, I, D, U, M, 0), a.push(at, At, D, U, M, 1), a.push(C, S, k, j, et, 0), a.push(C, S, k, j, et, 0), a.push(at, At, D, U, M, 1), a.push(Jt, Qt, k, j, et, 1), h += 6;
3335
+ const w = T, A = (T + 1) % d, P = f + T * 2, F = f + (T + 1) % d * 2, _ = s[P], I = s[P + 1], C = s[F], y = s[F + 1], D = x[w] * l, U = m[w] * l, M = o, O = x[A] * l, j = m[A] * l, et = o, at = _ + x[w] * n, Dt = I + m[w] * n, ee = C + x[A] * n, ne = y + m[A] * n;
3336
+ a.push(_, I, D, U, M, 0), a.push(at, Dt, D, U, M, 1), a.push(C, y, O, j, et, 0), a.push(C, y, O, j, et, 0), a.push(at, Dt, D, U, M, 1), a.push(ee, ne, O, j, et, 1), h += 6;
3148
3337
  }
3149
3338
  }
3150
3339
  return {
@@ -3152,7 +3341,7 @@ function Ze(s, t, e, n, i) {
3152
3341
  count: h
3153
3342
  };
3154
3343
  }
3155
- class $e extends gt {
3344
+ class mn extends vt {
3156
3345
  gl = null;
3157
3346
  // Render passes (each owns its program + cached uniforms)
3158
3347
  stencilPass = null;
@@ -3174,7 +3363,7 @@ class $e extends gt {
3174
3363
  chamferVao = null;
3175
3364
  chamferVertexCount = 0;
3176
3365
  // Source textures (via TextureRegistry — init-time allocation)
3177
- textures = new Ht();
3366
+ textures = new Gt();
3178
3367
  videoSlot;
3179
3368
  depthSlot;
3180
3369
  // Interior FBO (units 2, 3)
@@ -3210,7 +3399,7 @@ class $e extends gt {
3210
3399
  powerPreference: "high-performance"
3211
3400
  });
3212
3401
  if (!o) throw new Error("WebGL 2 is not supported.");
3213
- this.gl = o, this.qualityParams = Xt(o, e.quality), "drawingBufferColorSpace" in o && (o.drawingBufferColorSpace = "srgb"), this.hasColorBufferFloat = !!o.getExtension("EXT_color_buffer_float"), o.clearColor(0, 0, 0, 0), o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL, !0), this.initGPUResources(), this.setupResizeHandling();
3402
+ this.gl = o, this.qualityParams = Wt(o, e.quality), "drawingBufferColorSpace" in o && (o.drawingBufferColorSpace = "srgb"), this.hasColorBufferFloat = !!o.getExtension("EXT_color_buffer_float"), o.clearColor(0, 0, 0, 0), o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL, !0), this.initGPUResources(), this.setupResizeHandling();
3214
3403
  }
3215
3404
  initialize(t, e, n, i) {
3216
3405
  const r = this.gl;
@@ -3244,7 +3433,7 @@ class $e extends gt {
3244
3433
  uploadBoundaryMesh(t) {
3245
3434
  const e = this.gl;
3246
3435
  if (!e || !this.boundaryPass) return;
3247
- const n = je(t.edgeVertices);
3436
+ const n = fn(t.edgeVertices);
3248
3437
  if (n.count === 0) return;
3249
3438
  this.boundaryVao = e.createVertexArray(), e.bindVertexArray(this.boundaryVao);
3250
3439
  const i = e.createBuffer();
@@ -3257,7 +3446,7 @@ class $e extends gt {
3257
3446
  uploadChamferMesh(t) {
3258
3447
  const e = this.gl;
3259
3448
  if (!e || !this.chamferPass || this.config.chamferWidth <= 0) return;
3260
- const n = Ze(
3449
+ const n = dn(
3261
3450
  t.edgeVertices,
3262
3451
  t.contourOffsets,
3263
3452
  t.contourIsHole,
@@ -3294,7 +3483,7 @@ class $e extends gt {
3294
3483
  // -----------------------------------------------------------------------
3295
3484
  createJFAResources(t, e) {
3296
3485
  const n = this.gl;
3297
- n && (this.jfa || (this.jfa = new Rt(n, this.hasColorBufferFloat)), this.jfa.createResources(t, e, this.qualityParams.jfaDivisor));
3486
+ n && (this.jfa || (this.jfa = new Pt(n, this.hasColorBufferFloat)), this.jfa.createResources(t, e, this.qualityParams.jfaDivisor));
3298
3487
  }
3299
3488
  computeDistanceField() {
3300
3489
  !this.jfa || !this.maskPass || !this.jfaSeedPass || !this.jfaFloodPass || !this.jfaDistPass || !this.maskVao || !this.quadVao || this.jfa.compute({
@@ -3315,7 +3504,7 @@ class $e extends gt {
3315
3504
  // -----------------------------------------------------------------------
3316
3505
  initGPUResources() {
3317
3506
  const t = this.gl;
3318
- t && (this.stencilPass = O(t, "stencil", Ce, Ue, ["uMeshScale"]), this.maskPass = O(t, "mask", Le, _e, ["uMeshScale"]), this.jfaSeedPass = O(t, "jfa-seed", Ie, Me, ["uMask", "uTexelSize"]), this.jfaFloodPass = O(t, "jfa-flood", Be, Ve, ["uSeedTex", "uStepSize"]), this.jfaDistPass = O(t, "jfa-dist", ke, Oe, ["uSeedTex", "uMask", "uBevelWidth"]), this.interiorPass = O(t, "interior", He, Xe, [
3507
+ t && (this.stencilPass = k(t, "stencil", Ye, je, ["uMeshScale"]), this.maskPass = k(t, "mask", Ze, $e, ["uMeshScale"]), this.jfaSeedPass = k(t, "jfa-seed", Ke, Je, ["uMask", "uTexelSize"]), this.jfaFloodPass = k(t, "jfa-flood", Qe, tn, ["uSeedTex", "uStepSize"]), this.jfaDistPass = k(t, "jfa-dist", en, nn, ["uSeedTex", "uMask", "uBevelWidth"]), this.interiorPass = k(t, "interior", rn, sn, [
3319
3508
  "uImage",
3320
3509
  "uDepth",
3321
3510
  "uOffset",
@@ -3336,12 +3525,12 @@ class $e extends gt {
3336
3525
  "uBrightnessBias",
3337
3526
  "uUvOffset",
3338
3527
  "uUvScale"
3339
- ]), this.compositePass = O(t, "composite", Ne, Ge, [
3528
+ ]), this.compositePass = k(t, "composite", on, an, [
3340
3529
  "uInteriorColor",
3341
3530
  "uDistField",
3342
3531
  "uEdgeOcclusionWidth",
3343
3532
  "uEdgeOcclusionStrength"
3344
- ]), this.boundaryPass = O(t, "boundary", We, ze, [
3533
+ ]), this.boundaryPass = k(t, "boundary", ln, un, [
3345
3534
  "uInteriorColor",
3346
3535
  "uInteriorDepth",
3347
3536
  "uDistField",
@@ -3358,7 +3547,7 @@ class $e extends gt {
3358
3547
  "uEdgeColor",
3359
3548
  "uLightDir",
3360
3549
  "uBevelIntensity"
3361
- ]), this.chamferPass = O(t, "chamfer", qe, Ye, [
3550
+ ]), this.chamferPass = k(t, "chamfer", cn, hn, [
3362
3551
  "uMeshScale",
3363
3552
  "uLightDir3",
3364
3553
  "uChamferColor",
@@ -3367,7 +3556,7 @@ class $e extends gt {
3367
3556
  "uChamferShininess",
3368
3557
  "uInteriorColor",
3369
3558
  "uTexelSize"
3370
- ]), this.quadVao = Ot(t, this.interiorPass.program), t.disable(t.DEPTH_TEST));
3559
+ ]), this.quadVao = Xt(t, this.interiorPass.program), t.disable(t.DEPTH_TEST));
3371
3560
  }
3372
3561
  // -----------------------------------------------------------------------
3373
3562
  // Abstract method implementations (RendererBase)
@@ -3486,51 +3675,51 @@ class $e extends gt {
3486
3675
  this.stencilPass = null, this.maskPass = null, this.jfaSeedPass = null, this.jfaFloodPass = null, this.jfaDistPass = null, this.interiorPass = null, this.compositePass = null, this.boundaryPass = null, this.chamferPass = null, this.quadVao && (t.deleteVertexArray(this.quadVao), this.quadVao = null);
3487
3676
  }
3488
3677
  }
3489
- async function Tt(s) {
3678
+ async function Et(s) {
3490
3679
  const t = await fetch(s);
3491
3680
  if (!t.ok)
3492
3681
  throw new Error(`Failed to fetch SVG: ${t.status} ${t.statusText}`);
3493
3682
  const e = await t.text();
3494
- return Ke(e);
3683
+ return pn(e);
3495
3684
  }
3496
- function Ke(s) {
3685
+ function pn(s) {
3497
3686
  const n = new DOMParser().parseFromString(s, "image/svg+xml").querySelector("svg");
3498
3687
  if (!n)
3499
3688
  throw new Error("No <svg> element found in document.");
3500
- const i = Je(n);
3689
+ const i = gn(n);
3501
3690
  if (i.length === 0)
3502
3691
  throw new Error("No path data found in SVG.");
3503
3692
  let r = 1 / 0, o = 1 / 0, l = -1 / 0, a = -1 / 0;
3504
3693
  for (const C of i)
3505
- for (let S = 0; S < C.length; S += 2)
3506
- r = Math.min(r, C[S]), l = Math.max(l, C[S]), o = Math.min(o, C[S + 1]), a = Math.max(a, C[S + 1]);
3507
- const h = l - r, c = a - o, f = (r + l) / 2, u = (o + a) / 2, x = 2 / Math.max(h, c), p = h / c, d = i.map((C) => {
3508
- const S = [];
3694
+ for (let y = 0; y < C.length; y += 2)
3695
+ r = Math.min(r, C[y]), l = Math.max(l, C[y]), o = Math.min(o, C[y + 1]), a = Math.max(a, C[y + 1]);
3696
+ const h = l - r, c = a - o, f = (r + l) / 2, u = (o + a) / 2, v = 2 / Math.max(h, c), p = h / c, d = i.map((C) => {
3697
+ const y = [];
3509
3698
  for (let D = 0; D < C.length; D += 2)
3510
- S.push((C[D] - f) * x), S.push(-((C[D + 1] - u) * x));
3511
- return S;
3512
- }), y = an(d), b = [], E = [];
3513
- for (const C of y) {
3514
- const { flatCoords: S, holeIndices: D } = on(C), U = ln(S, D), M = b.length / 2;
3515
- for (const k of U)
3516
- E.push(k + M);
3517
- for (const k of S)
3518
- b.push(k);
3519
- }
3520
- const g = b, v = E, m = [], T = [], w = [], A = zt(d);
3699
+ y.push((C[D] - f) * v), y.push(-((C[D + 1] - u) * v));
3700
+ return y;
3701
+ }), S = wn(d), E = [], b = [];
3702
+ for (const C of S) {
3703
+ const { flatCoords: y, holeIndices: D } = yn(C), U = Rn(y, D), M = E.length / 2;
3704
+ for (const O of U)
3705
+ b.push(O + M);
3706
+ for (const O of y)
3707
+ E.push(O);
3708
+ }
3709
+ const g = E, x = b, m = [], T = [], w = [], A = jt(d);
3521
3710
  for (let C = 0; C < d.length; C++) {
3522
- const S = d[C];
3711
+ const y = d[C];
3523
3712
  T.push(m.length), w.push(A[C]);
3524
- for (let D = 0; D < S.length; D++)
3525
- m.push(S[D]);
3526
- S.length >= 2 && m.push(S[0], S[1]);
3713
+ for (let D = 0; D < y.length; D++)
3714
+ m.push(y[D]);
3715
+ y.length >= 2 && m.push(y[0], y[1]);
3527
3716
  }
3528
3717
  let P = 1 / 0, F = 1 / 0, _ = -1 / 0, I = -1 / 0;
3529
3718
  for (let C = 0; C < g.length; C += 2)
3530
3719
  P = Math.min(P, g[C]), _ = Math.max(_, g[C]), F = Math.min(F, g[C + 1]), I = Math.max(I, g[C + 1]);
3531
3720
  return {
3532
3721
  vertices: new Float32Array(g),
3533
- indices: new Uint16Array(v),
3722
+ indices: new Uint16Array(x),
3534
3723
  edgeVertices: new Float32Array(m),
3535
3724
  contourOffsets: T,
3536
3725
  contourIsHole: w,
@@ -3538,35 +3727,35 @@ function Ke(s) {
3538
3727
  aspect: p
3539
3728
  };
3540
3729
  }
3541
- function Je(s) {
3730
+ function gn(s) {
3542
3731
  const t = [];
3543
3732
  return s.querySelectorAll("path").forEach((a) => {
3544
3733
  const h = a.getAttribute("d");
3545
3734
  if (!h) return;
3546
- const c = en(h);
3735
+ const c = Tn(h);
3547
3736
  t.push(...c);
3548
3737
  }), s.querySelectorAll("polygon").forEach((a) => {
3549
3738
  const h = a.getAttribute("points");
3550
3739
  if (!h) return;
3551
- const c = _t(h);
3740
+ const c = Bt(h);
3552
3741
  c.length >= 6 && t.push(c);
3553
3742
  }), s.querySelectorAll("polyline").forEach((a) => {
3554
3743
  const h = a.getAttribute("points");
3555
3744
  if (!h) return;
3556
- const c = _t(h);
3745
+ const c = Bt(h);
3557
3746
  c.length >= 6 && t.push(c);
3558
3747
  }), s.querySelectorAll("rect").forEach((a) => {
3559
3748
  const h = parseFloat(a.getAttribute("x") || "0"), c = parseFloat(a.getAttribute("y") || "0"), f = parseFloat(a.getAttribute("width") || "0"), u = parseFloat(a.getAttribute("height") || "0");
3560
3749
  f > 0 && u > 0 && t.push([h, c, h + f, c, h + f, c + u, h, c + u]);
3561
3750
  }), s.querySelectorAll("circle").forEach((a) => {
3562
3751
  const h = parseFloat(a.getAttribute("cx") || "0"), c = parseFloat(a.getAttribute("cy") || "0"), f = parseFloat(a.getAttribute("r") || "0");
3563
- f > 0 && t.push(Qe(h, c, f));
3752
+ f > 0 && t.push(vn(h, c, f));
3564
3753
  }), s.querySelectorAll("ellipse").forEach((a) => {
3565
3754
  const h = parseFloat(a.getAttribute("cx") || "0"), c = parseFloat(a.getAttribute("cy") || "0"), f = parseFloat(a.getAttribute("rx") || "0"), u = parseFloat(a.getAttribute("ry") || "0");
3566
- f > 0 && u > 0 && t.push(tn(h, c, f, u));
3755
+ f > 0 && u > 0 && t.push(xn(h, c, f, u));
3567
3756
  }), t;
3568
3757
  }
3569
- function _t(s) {
3758
+ function Bt(s) {
3570
3759
  const t = [], e = s.trim().split(/[\s,]+/);
3571
3760
  for (let n = 0; n < e.length - 1; n += 2) {
3572
3761
  const i = parseFloat(e[n]), r = parseFloat(e[n + 1]);
@@ -3574,7 +3763,7 @@ function _t(s) {
3574
3763
  }
3575
3764
  return t;
3576
3765
  }
3577
- function Qe(s, t, e, n = 64) {
3766
+ function vn(s, t, e, n = 64) {
3578
3767
  const i = [];
3579
3768
  for (let r = 0; r < n; r++) {
3580
3769
  const o = 2 * Math.PI * r / n;
@@ -3582,7 +3771,7 @@ function Qe(s, t, e, n = 64) {
3582
3771
  }
3583
3772
  return i;
3584
3773
  }
3585
- function tn(s, t, e, n, i = 64) {
3774
+ function xn(s, t, e, n, i = 64) {
3586
3775
  const r = [];
3587
3776
  for (let o = 0; o < i; o++) {
3588
3777
  const l = 2 * Math.PI * o / i;
@@ -3590,24 +3779,24 @@ function tn(s, t, e, n, i = 64) {
3590
3779
  }
3591
3780
  return r;
3592
3781
  }
3593
- function en(s) {
3782
+ function Tn(s) {
3594
3783
  const t = [];
3595
3784
  let e = [], n = 0, i = 0, r = 0, o = 0, l = 0, a = 0, h = "";
3596
- const c = nn(s);
3785
+ const c = En(s);
3597
3786
  let f = 0;
3598
3787
  function u() {
3599
3788
  return f >= c.length ? 0 : parseFloat(c[f++]);
3600
3789
  }
3601
3790
  for (; f < c.length; ) {
3602
- const x = c[f];
3791
+ const v = c[f];
3603
3792
  let p;
3604
- /^[a-zA-Z]$/.test(x) ? (p = x, f++) : p = h === "M" ? "L" : h === "m" ? "l" : h;
3793
+ /^[a-zA-Z]$/.test(v) ? (p = v, f++) : p = h === "M" ? "L" : h === "m" ? "l" : h;
3605
3794
  const d = p === p.toLowerCase();
3606
3795
  switch (p.toUpperCase()) {
3607
3796
  case "M": {
3608
3797
  e.length > 0 && t.push(e), e = [];
3609
- const b = u() + (d ? n : 0), E = u() + (d ? i : 0);
3610
- n = b, i = E, r = b, o = E, e.push(n, i), l = n, a = i;
3798
+ const E = u() + (d ? n : 0), b = u() + (d ? i : 0);
3799
+ n = E, i = b, r = E, o = b, e.push(n, i), l = n, a = i;
3611
3800
  break;
3612
3801
  }
3613
3802
  case "L": {
@@ -3623,28 +3812,28 @@ function en(s) {
3623
3812
  break;
3624
3813
  }
3625
3814
  case "C": {
3626
- const b = u() + (d ? n : 0), E = u() + (d ? i : 0), g = u() + (d ? n : 0), v = u() + (d ? i : 0), m = u() + (d ? n : 0), T = u() + (d ? i : 0);
3627
- it(e, n, i, b, E, g, v, m, T), n = m, i = T, l = g, a = v;
3815
+ const E = u() + (d ? n : 0), b = u() + (d ? i : 0), g = u() + (d ? n : 0), x = u() + (d ? i : 0), m = u() + (d ? n : 0), T = u() + (d ? i : 0);
3816
+ it(e, n, i, E, b, g, x, m, T), n = m, i = T, l = g, a = x;
3628
3817
  break;
3629
3818
  }
3630
3819
  case "S": {
3631
- const b = 2 * n - l, E = 2 * i - a, g = u() + (d ? n : 0), v = u() + (d ? i : 0), m = u() + (d ? n : 0), T = u() + (d ? i : 0);
3632
- it(e, n, i, b, E, g, v, m, T), n = m, i = T, l = g, a = v;
3820
+ const E = 2 * n - l, b = 2 * i - a, g = u() + (d ? n : 0), x = u() + (d ? i : 0), m = u() + (d ? n : 0), T = u() + (d ? i : 0);
3821
+ it(e, n, i, E, b, g, x, m, T), n = m, i = T, l = g, a = x;
3633
3822
  break;
3634
3823
  }
3635
3824
  case "Q": {
3636
- const b = u() + (d ? n : 0), E = u() + (d ? i : 0), g = u() + (d ? n : 0), v = u() + (d ? i : 0);
3637
- It(e, n, i, b, E, g, v), n = g, i = v, l = b, a = E;
3825
+ const E = u() + (d ? n : 0), b = u() + (d ? i : 0), g = u() + (d ? n : 0), x = u() + (d ? i : 0);
3826
+ Vt(e, n, i, E, b, g, x), n = g, i = x, l = E, a = b;
3638
3827
  break;
3639
3828
  }
3640
3829
  case "T": {
3641
- const b = 2 * n - l, E = 2 * i - a, g = u() + (d ? n : 0), v = u() + (d ? i : 0);
3642
- It(e, n, i, b, E, g, v), n = g, i = v, l = b, a = E;
3830
+ const E = 2 * n - l, b = 2 * i - a, g = u() + (d ? n : 0), x = u() + (d ? i : 0);
3831
+ Vt(e, n, i, E, b, g, x), n = g, i = x, l = E, a = b;
3643
3832
  break;
3644
3833
  }
3645
3834
  case "A": {
3646
- const b = u(), E = u(), g = u(), v = u(), m = u(), T = u() + (d ? n : 0), w = u() + (d ? i : 0);
3647
- sn(e, n, i, b, E, g, !!v, !!m, T, w), n = T, i = w, l = n, a = i;
3835
+ const E = u(), b = u(), g = u(), x = u(), m = u(), T = u() + (d ? n : 0), w = u() + (d ? i : 0);
3836
+ Sn(e, n, i, E, b, g, !!x, !!m, T, w), n = T, i = w, l = n, a = i;
3648
3837
  break;
3649
3838
  }
3650
3839
  case "Z": {
@@ -3659,14 +3848,14 @@ function en(s) {
3659
3848
  }
3660
3849
  return e.length >= 6 && t.push(e), t;
3661
3850
  }
3662
- function nn(s) {
3851
+ function En(s) {
3663
3852
  const t = [], e = /([a-zA-Z])|([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/g;
3664
3853
  let n;
3665
3854
  for (; (n = e.exec(s)) !== null; )
3666
3855
  t.push(n[0]);
3667
3856
  return t;
3668
3857
  }
3669
- const rn = 0.5;
3858
+ const bn = 0.5;
3670
3859
  function it(s, t, e, n, i, r, o, l, a, h = 0) {
3671
3860
  if (h > 12) {
3672
3861
  s.push(l, a);
@@ -3677,52 +3866,52 @@ function it(s, t, e, n, i, r, o, l, a, h = 0) {
3677
3866
  s.push(l, a);
3678
3867
  return;
3679
3868
  }
3680
- const x = Math.abs((n - l) * f - (i - a) * c) / u, p = Math.abs((r - l) * f - (o - a) * c) / u;
3681
- if (x + p < rn) {
3869
+ const v = Math.abs((n - l) * f - (i - a) * c) / u, p = Math.abs((r - l) * f - (o - a) * c) / u;
3870
+ if (v + p < bn) {
3682
3871
  s.push(l, a);
3683
3872
  return;
3684
3873
  }
3685
- const d = (t + n) / 2, y = (e + i) / 2, b = (n + r) / 2, E = (i + o) / 2, g = (r + l) / 2, v = (o + a) / 2, m = (d + b) / 2, T = (y + E) / 2, w = (b + g) / 2, A = (E + v) / 2, P = (m + w) / 2, F = (T + A) / 2;
3686
- it(s, t, e, d, y, m, T, P, F, h + 1), it(s, P, F, w, A, g, v, l, a, h + 1);
3874
+ const d = (t + n) / 2, S = (e + i) / 2, E = (n + r) / 2, b = (i + o) / 2, g = (r + l) / 2, x = (o + a) / 2, m = (d + E) / 2, T = (S + b) / 2, w = (E + g) / 2, A = (b + x) / 2, P = (m + w) / 2, F = (T + A) / 2;
3875
+ it(s, t, e, d, S, m, T, P, F, h + 1), it(s, P, F, w, A, g, x, l, a, h + 1);
3687
3876
  }
3688
- function It(s, t, e, n, i, r, o) {
3877
+ function Vt(s, t, e, n, i, r, o) {
3689
3878
  const l = t + 0.6666666666666666 * (n - t), a = e + 2 / 3 * (i - e), h = r + 2 / 3 * (n - r), c = o + 2 / 3 * (i - o);
3690
3879
  it(s, t, e, l, a, h, c, r, o);
3691
3880
  }
3692
- function sn(s, t, e, n, i, r, o, l, a, h) {
3881
+ function Sn(s, t, e, n, i, r, o, l, a, h) {
3693
3882
  if (n === 0 || i === 0) {
3694
3883
  s.push(a, h);
3695
3884
  return;
3696
3885
  }
3697
3886
  let c = Math.abs(n), f = Math.abs(i);
3698
- const u = r * Math.PI / 180, x = Math.cos(u), p = Math.sin(u), d = (t - a) / 2, y = (e - h) / 2, b = x * d + p * y, E = -p * d + x * y;
3699
- let g = b * b / (c * c) + E * E / (f * f);
3887
+ const u = r * Math.PI / 180, v = Math.cos(u), p = Math.sin(u), d = (t - a) / 2, S = (e - h) / 2, E = v * d + p * S, b = -p * d + v * S;
3888
+ let g = E * E / (c * c) + b * b / (f * f);
3700
3889
  if (g > 1) {
3701
3890
  const U = Math.sqrt(g);
3702
3891
  c *= U, f *= U, g = 1;
3703
3892
  }
3704
- const v = c * c, m = f * f, T = b * b, w = E * E;
3705
- let A = Math.max(0, (v * m - v * w - m * T) / (v * w + m * T));
3893
+ const x = c * c, m = f * f, T = E * E, w = b * b;
3894
+ let A = Math.max(0, (x * m - x * w - m * T) / (x * w + m * T));
3706
3895
  A = Math.sqrt(A), o === l && (A = -A);
3707
- const P = A * (c * E) / f, F = A * -(f * b) / c, _ = x * P - p * F + (t + a) / 2, I = p * P + x * F + (e + h) / 2, C = Mt(1, 0, (b - P) / c, (E - F) / f);
3708
- let S = Mt(
3709
- (b - P) / c,
3710
- (E - F) / f,
3711
- (-b - P) / c,
3712
- (-E - F) / f
3896
+ const P = A * (c * b) / f, F = A * -(f * E) / c, _ = v * P - p * F + (t + a) / 2, I = p * P + v * F + (e + h) / 2, C = Ot(1, 0, (E - P) / c, (b - F) / f);
3897
+ let y = Ot(
3898
+ (E - P) / c,
3899
+ (b - F) / f,
3900
+ (-E - P) / c,
3901
+ (-b - F) / f
3713
3902
  );
3714
- !l && S > 0 && (S -= 2 * Math.PI), l && S < 0 && (S += 2 * Math.PI);
3715
- const D = Math.max(4, Math.ceil(Math.abs(S) / (Math.PI / 16)));
3903
+ !l && y > 0 && (y -= 2 * Math.PI), l && y < 0 && (y += 2 * Math.PI);
3904
+ const D = Math.max(4, Math.ceil(Math.abs(y) / (Math.PI / 16)));
3716
3905
  for (let U = 1; U <= D; U++) {
3717
- const M = C + U / D * S, k = Math.cos(M), j = Math.sin(M), et = x * c * k - p * f * j + _, at = p * c * k + x * f * j + I;
3906
+ const M = C + U / D * y, O = Math.cos(M), j = Math.sin(M), et = v * c * O - p * f * j + _, at = p * c * O + v * f * j + I;
3718
3907
  s.push(et, at);
3719
3908
  }
3720
3909
  }
3721
- function Mt(s, t, e, n) {
3910
+ function Ot(s, t, e, n) {
3722
3911
  const i = s * n - t * e < 0 ? -1 : 1, r = s * e + t * n, o = Math.sqrt(s * s + t * t), l = Math.sqrt(e * e + n * n), a = r / (o * l);
3723
3912
  return i * Math.acos(Math.max(-1, Math.min(1, a)));
3724
3913
  }
3725
- function on(s) {
3914
+ function yn(s) {
3726
3915
  const t = [], e = [];
3727
3916
  for (let n = 0; n < s.length; n++) {
3728
3917
  n > 0 && e.push(t.length / 2);
@@ -3731,22 +3920,22 @@ function on(s) {
3731
3920
  }
3732
3921
  return { flatCoords: t, holeIndices: e };
3733
3922
  }
3734
- function zt(s) {
3735
- const t = s.length, e = s.map((i) => Math.abs(qt(i))), n = new Array(t).fill(!1);
3923
+ function jt(s) {
3924
+ const t = s.length, e = s.map((i) => Math.abs(Zt(i))), n = new Array(t).fill(!1);
3736
3925
  for (let i = 0; i < t; i++) {
3737
3926
  let r = 0;
3738
3927
  const o = s[i][0], l = s[i][1];
3739
3928
  for (let a = 0; a < t; a++)
3740
- i !== a && e[a] > e[i] && Yt(o, l, s[a]) && r++;
3929
+ i !== a && e[a] > e[i] && $t(o, l, s[a]) && r++;
3741
3930
  n[i] = r % 2 === 1;
3742
3931
  }
3743
3932
  return n;
3744
3933
  }
3745
- function an(s) {
3934
+ function wn(s) {
3746
3935
  if (s.length <= 1)
3747
3936
  return [s];
3748
- const t = zt(s), e = s.map((o, l) => {
3749
- const a = qt(o);
3937
+ const t = jt(s), e = s.map((o, l) => {
3938
+ const a = Zt(o);
3750
3939
  return { index: l, contour: o, area: a, isOuter: !t[l] };
3751
3940
  }), n = e.filter((o) => o.isOuter), i = e.filter((o) => !o.isOuter);
3752
3941
  if (n.length === 0)
@@ -3759,7 +3948,7 @@ function an(s) {
3759
3948
  const l = o.contour[0], a = o.contour[1];
3760
3949
  let h = -1, c = 1 / 0;
3761
3950
  for (let f = 0; f < n.length; f++)
3762
- if (Yt(l, a, n[f].contour)) {
3951
+ if ($t(l, a, n[f].contour)) {
3763
3952
  const u = Math.abs(n[f].area);
3764
3953
  u < c && (c = u, h = f);
3765
3954
  }
@@ -3767,7 +3956,7 @@ function an(s) {
3767
3956
  }
3768
3957
  return r.map((o) => [o.outer, ...o.holes]);
3769
3958
  }
3770
- function qt(s) {
3959
+ function Zt(s) {
3771
3960
  let t = 0;
3772
3961
  const e = s.length;
3773
3962
  for (let n = 0; n < e; n += 2) {
@@ -3776,7 +3965,7 @@ function qt(s) {
3776
3965
  }
3777
3966
  return t / 2;
3778
3967
  }
3779
- function Yt(s, t, e) {
3968
+ function $t(s, t, e) {
3780
3969
  let n = !1;
3781
3970
  const i = e.length;
3782
3971
  for (let r = 0, o = i - 2; r < i; o = r, r += 2) {
@@ -3785,37 +3974,37 @@ function Yt(s, t, e) {
3785
3974
  }
3786
3975
  return n;
3787
3976
  }
3788
- function ln(s, t, e = 2) {
3977
+ function Rn(s, t, e = 2) {
3789
3978
  const n = t && t.length > 0, i = n ? t[0] * e : s.length;
3790
- let r = jt(s, 0, i, e, !0);
3979
+ let r = Kt(s, 0, i, e, !0);
3791
3980
  const o = [];
3792
3981
  if (!r || r.next === r.prev) return o;
3793
- n && (r = dn(s, t, r, e));
3982
+ n && (r = Cn(s, t, r, e));
3794
3983
  let l = 1 / 0, a = 1 / 0, h = -1 / 0, c = -1 / 0, f = 0;
3795
3984
  if (s.length > 80 * e) {
3796
3985
  for (let u = 0; u < i; u += e) {
3797
- const x = s[u], p = s[u + 1];
3798
- x < l && (l = x), p < a && (a = p), x > h && (h = x), p > c && (c = p);
3986
+ const v = s[u], p = s[u + 1];
3987
+ v < l && (l = v), p < a && (a = p), v > h && (h = v), p > c && (c = p);
3799
3988
  }
3800
3989
  f = Math.max(h - l, c - a), f = f !== 0 ? 32767 / f : 0;
3801
3990
  }
3802
3991
  return rt(r, o, e, l, a, f, 0), o;
3803
3992
  }
3804
- function jt(s, t, e, n, i) {
3993
+ function Kt(s, t, e, n, i) {
3805
3994
  let r = null;
3806
- if (i === yn(s, t, e, n) > 0)
3995
+ if (i === Hn(s, t, e, n) > 0)
3807
3996
  for (let o = t; o < e; o += n)
3808
- r = Bt(o, s[o], s[o + 1], r);
3997
+ r = kt(o, s[o], s[o + 1], r);
3809
3998
  else
3810
3999
  for (let o = e - n; o >= t; o -= n)
3811
- r = Bt(o, s[o], s[o + 1], r);
3812
- return r && vt(r, r.next) && (ot(r), r = r.next), r ? (r.next.prev = r, r.prev.next = r, r.next) : null;
4000
+ r = kt(o, s[o], s[o + 1], r);
4001
+ return r && xt(r, r.next) && (ot(r), r = r.next), r ? (r.next.prev = r, r.prev.next = r, r.next) : null;
3813
4002
  }
3814
4003
  function Y(s, t) {
3815
4004
  t || (t = s);
3816
4005
  let e = s, n;
3817
4006
  do
3818
- if (n = !1, !e.steiner && (vt(e, e.next) || L(e.prev, e, e.next) === 0)) {
4007
+ if (n = !1, !e.steiner && (xt(e, e.next) || L(e.prev, e, e.next) === 0)) {
3819
4008
  if (ot(e), e = t = e.prev, e === e.next) break;
3820
4009
  n = !0;
3821
4010
  } else
@@ -3825,65 +4014,65 @@ function Y(s, t) {
3825
4014
  }
3826
4015
  function rt(s, t, e, n, i, r, o) {
3827
4016
  if (!s) return;
3828
- !o && r && vn(s, n, i, r);
4017
+ !o && r && In(s, n, i, r);
3829
4018
  let l = s, a, h;
3830
4019
  for (; s.prev !== s.next; ) {
3831
- if (a = s.prev, h = s.next, r ? cn(s, n, i, r) : un(s)) {
4020
+ if (a = s.prev, h = s.next, r ? Pn(s, n, i, r) : An(s)) {
3832
4021
  t.push(a.i / e, s.i / e, h.i / e), ot(s), s = h.next, l = h.next;
3833
4022
  continue;
3834
4023
  }
3835
4024
  if (s = h, s === l) {
3836
- o ? o === 1 ? (s = hn(Y(s), t, e), rt(s, t, e, n, i, r, 2)) : o === 2 && fn(s, t, e, n, i, r) : rt(Y(s), t, e, n, i, r, 1);
4025
+ o ? o === 1 ? (s = Dn(Y(s), t, e), rt(s, t, e, n, i, r, 2)) : o === 2 && Fn(s, t, e, n, i, r) : rt(Y(s), t, e, n, i, r, 1);
3837
4026
  break;
3838
4027
  }
3839
4028
  }
3840
4029
  }
3841
- function un(s) {
4030
+ function An(s) {
3842
4031
  const t = s.prev, e = s, n = s.next;
3843
4032
  if (L(t, e, n) >= 0) return !1;
3844
- const i = t.x, r = e.x, o = n.x, l = t.y, a = e.y, h = n.y, c = i < r ? i < o ? i : o : r < o ? r : o, f = l < a ? l < h ? l : h : a < h ? a : h, u = i > r ? i > o ? i : o : r > o ? r : o, x = l > a ? l > h ? l : h : a > h ? a : h;
4033
+ const i = t.x, r = e.x, o = n.x, l = t.y, a = e.y, h = n.y, c = i < r ? i < o ? i : o : r < o ? r : o, f = l < a ? l < h ? l : h : a < h ? a : h, u = i > r ? i > o ? i : o : r > o ? r : o, v = l > a ? l > h ? l : h : a > h ? a : h;
3845
4034
  let p = n.next;
3846
4035
  for (; p !== t; ) {
3847
- if (p.x >= c && p.x <= u && p.y >= f && p.y <= x && tt(i, l, r, a, o, h, p.x, p.y) && L(p.prev, p, p.next) >= 0)
4036
+ if (p.x >= c && p.x <= u && p.y >= f && p.y <= v && tt(i, l, r, a, o, h, p.x, p.y) && L(p.prev, p, p.next) >= 0)
3848
4037
  return !1;
3849
4038
  p = p.next;
3850
4039
  }
3851
4040
  return !0;
3852
4041
  }
3853
- function cn(s, t, e, n) {
4042
+ function Pn(s, t, e, n) {
3854
4043
  const i = s.prev, r = s, o = s.next;
3855
4044
  if (L(i, r, o) >= 0) return !1;
3856
- const l = i.x, a = r.x, h = o.x, c = i.y, f = r.y, u = o.y, x = l < a ? l < h ? l : h : a < h ? a : h, p = c < f ? c < u ? c : u : f < u ? f : u, d = l > a ? l > h ? l : h : a > h ? a : h, y = c > f ? c > u ? c : u : f > u ? f : u, b = yt(x, p, t, e, n), E = yt(d, y, t, e, n);
3857
- let g = s.prevZ, v = s.nextZ;
3858
- for (; g && g.z >= b && v && v.z <= E; ) {
3859
- if (g.x >= x && g.x <= d && g.y >= p && g.y <= y && g !== i && g !== o && tt(l, c, a, f, h, u, g.x, g.y) && L(g.prev, g, g.next) >= 0 || (g = g.prevZ, v.x >= x && v.x <= d && v.y >= p && v.y <= y && v !== i && v !== o && tt(l, c, a, f, h, u, v.x, v.y) && L(v.prev, v, v.next) >= 0)) return !1;
3860
- v = v.nextZ;
3861
- }
3862
- for (; g && g.z >= b; ) {
3863
- if (g.x >= x && g.x <= d && g.y >= p && g.y <= y && g !== i && g !== o && tt(l, c, a, f, h, u, g.x, g.y) && L(g.prev, g, g.next) >= 0) return !1;
4045
+ const l = i.x, a = r.x, h = o.x, c = i.y, f = r.y, u = o.y, v = l < a ? l < h ? l : h : a < h ? a : h, p = c < f ? c < u ? c : u : f < u ? f : u, d = l > a ? l > h ? l : h : a > h ? a : h, S = c > f ? c > u ? c : u : f > u ? f : u, E = wt(v, p, t, e, n), b = wt(d, S, t, e, n);
4046
+ let g = s.prevZ, x = s.nextZ;
4047
+ for (; g && g.z >= E && x && x.z <= b; ) {
4048
+ if (g.x >= v && g.x <= d && g.y >= p && g.y <= S && g !== i && g !== o && tt(l, c, a, f, h, u, g.x, g.y) && L(g.prev, g, g.next) >= 0 || (g = g.prevZ, x.x >= v && x.x <= d && x.y >= p && x.y <= S && x !== i && x !== o && tt(l, c, a, f, h, u, x.x, x.y) && L(x.prev, x, x.next) >= 0)) return !1;
4049
+ x = x.nextZ;
4050
+ }
4051
+ for (; g && g.z >= E; ) {
4052
+ if (g.x >= v && g.x <= d && g.y >= p && g.y <= S && g !== i && g !== o && tt(l, c, a, f, h, u, g.x, g.y) && L(g.prev, g, g.next) >= 0) return !1;
3864
4053
  g = g.prevZ;
3865
4054
  }
3866
- for (; v && v.z <= E; ) {
3867
- if (v.x >= x && v.x <= d && v.y >= p && v.y <= y && v !== i && v !== o && tt(l, c, a, f, h, u, v.x, v.y) && L(v.prev, v, v.next) >= 0) return !1;
3868
- v = v.nextZ;
4055
+ for (; x && x.z <= b; ) {
4056
+ if (x.x >= v && x.x <= d && x.y >= p && x.y <= S && x !== i && x !== o && tt(l, c, a, f, h, u, x.x, x.y) && L(x.prev, x, x.next) >= 0) return !1;
4057
+ x = x.nextZ;
3869
4058
  }
3870
4059
  return !0;
3871
4060
  }
3872
- function hn(s, t, e) {
4061
+ function Dn(s, t, e) {
3873
4062
  let n = s;
3874
4063
  do {
3875
4064
  const i = n.prev, r = n.next.next;
3876
- !vt(i, r) && Zt(i, n, n.next, r) && st(i, r) && st(r, i) && (t.push(i.i / e, n.i / e, r.i / e), ot(n), ot(n.next), n = s = r), n = n.next;
4065
+ !xt(i, r) && Jt(i, n, n.next, r) && st(i, r) && st(r, i) && (t.push(i.i / e, n.i / e, r.i / e), ot(n), ot(n.next), n = s = r), n = n.next;
3877
4066
  } while (n !== s);
3878
4067
  return Y(n);
3879
4068
  }
3880
- function fn(s, t, e, n, i, r) {
4069
+ function Fn(s, t, e, n, i, r) {
3881
4070
  let o = s;
3882
4071
  do {
3883
4072
  let l = o.next.next;
3884
4073
  for (; l !== o.prev; ) {
3885
- if (o.i !== l.i && En(o, l)) {
3886
- let a = $t(o, l);
4074
+ if (o.i !== l.i && Vn(o, l)) {
4075
+ let a = Qt(o, l);
3887
4076
  o = Y(o, o.next), a = Y(a, a.next), rt(o, t, e, n, i, r, 0), rt(a, t, e, n, i, r, 0);
3888
4077
  return;
3889
4078
  }
@@ -3892,24 +4081,24 @@ function fn(s, t, e, n, i, r) {
3892
4081
  o = o.next;
3893
4082
  } while (o !== s);
3894
4083
  }
3895
- function dn(s, t, e, n) {
4084
+ function Cn(s, t, e, n) {
3896
4085
  const i = [];
3897
4086
  for (let r = 0; r < t.length; r++) {
3898
- const o = t[r] * n, l = r < t.length - 1 ? t[r + 1] * n : s.length, a = jt(s, o, l, n, !1);
3899
- a && (a === a.next && (a.steiner = !0), i.push(Tn(a)));
4087
+ const o = t[r] * n, l = r < t.length - 1 ? t[r + 1] * n : s.length, a = Kt(s, o, l, n, !1);
4088
+ a && (a === a.next && (a.steiner = !0), i.push(Bn(a)));
3900
4089
  }
3901
4090
  i.sort((r, o) => r.x - o.x);
3902
4091
  for (const r of i)
3903
- e = mn(r, e);
4092
+ e = Un(r, e);
3904
4093
  return e;
3905
4094
  }
3906
- function mn(s, t) {
3907
- const e = pn(s, t);
4095
+ function Un(s, t) {
4096
+ const e = Ln(s, t);
3908
4097
  if (!e) return t;
3909
- const n = $t(e, s);
4098
+ const n = Qt(e, s);
3910
4099
  return Y(n, n.next), Y(e, e.next);
3911
4100
  }
3912
- function pn(s, t) {
4101
+ function Ln(s, t) {
3913
4102
  let e = t;
3914
4103
  const n = s.x, i = s.y;
3915
4104
  let r = -1 / 0, o = null;
@@ -3928,23 +4117,23 @@ function pn(s, t) {
3928
4117
  do {
3929
4118
  if (n >= e.x && e.x >= a && n !== e.x && tt(i < h ? n : r, i, a, h, i < h ? r : n, i, e.x, e.y)) {
3930
4119
  const f = Math.abs(i - e.y) / (n - e.x);
3931
- st(e, s) && (f < c || f === c && (e.x > o.x || gn(o, e))) && (o = e, c = f);
4120
+ st(e, s) && (f < c || f === c && (e.x > o.x || _n(o, e))) && (o = e, c = f);
3932
4121
  }
3933
4122
  e = e.next;
3934
4123
  } while (e !== l);
3935
4124
  return o;
3936
4125
  }
3937
- function gn(s, t) {
4126
+ function _n(s, t) {
3938
4127
  return L(s.prev, s, t.prev) < 0 && L(t.next, s, s.next) < 0;
3939
4128
  }
3940
- function vn(s, t, e, n) {
4129
+ function In(s, t, e, n) {
3941
4130
  let i = s;
3942
4131
  do
3943
- i.z === 0 && (i.z = yt(i.x, i.y, t, e, n)), i.prevZ = i.prev, i.nextZ = i.next, i = i.next;
4132
+ i.z === 0 && (i.z = wt(i.x, i.y, t, e, n)), i.prevZ = i.prev, i.nextZ = i.next, i = i.next;
3944
4133
  while (i !== s);
3945
- i.prevZ.nextZ = null, i.prevZ = null, xn(i);
4134
+ i.prevZ.nextZ = null, i.prevZ = null, Mn(i);
3946
4135
  }
3947
- function xn(s) {
4136
+ function Mn(s) {
3948
4137
  let t = 1, e;
3949
4138
  do {
3950
4139
  let n = s;
@@ -3966,11 +4155,11 @@ function xn(s) {
3966
4155
  } while (e > 1);
3967
4156
  return s;
3968
4157
  }
3969
- function yt(s, t, e, n, i) {
4158
+ function wt(s, t, e, n, i) {
3970
4159
  let r = (s - e) * i | 0, o = (t - n) * i | 0;
3971
4160
  return r = (r | r << 8) & 16711935, r = (r | r << 4) & 252645135, r = (r | r << 2) & 858993459, r = (r | r << 1) & 1431655765, o = (o | o << 8) & 16711935, o = (o | o << 4) & 252645135, o = (o | o << 2) & 858993459, o = (o | o << 1) & 1431655765, r | o << 1;
3972
4161
  }
3973
- function Tn(s) {
4162
+ function Bn(s) {
3974
4163
  let t = s, e = s;
3975
4164
  do
3976
4165
  (t.x < e.x || t.x === e.x && t.y < e.y) && (e = t), t = t.next;
@@ -3980,29 +4169,29 @@ function Tn(s) {
3980
4169
  function tt(s, t, e, n, i, r, o, l) {
3981
4170
  return (i - o) * (t - l) - (s - o) * (r - l) >= 0 && (s - o) * (n - l) - (e - o) * (t - l) >= 0 && (e - o) * (r - l) - (i - o) * (n - l) >= 0;
3982
4171
  }
3983
- function En(s, t) {
3984
- return s.next.i !== t.i && s.prev.i !== t.i && !bn(s, t) && (st(s, t) && st(t, s) && Sn(s, t) && (L(s.prev, s, t.prev) !== 0 || L(s, t.prev, t) !== 0) || vt(s, t) && L(s.prev, s, s.next) > 0 && L(t.prev, t, t.next) > 0);
4172
+ function Vn(s, t) {
4173
+ return s.next.i !== t.i && s.prev.i !== t.i && !On(s, t) && (st(s, t) && st(t, s) && kn(s, t) && (L(s.prev, s, t.prev) !== 0 || L(s, t.prev, t) !== 0) || xt(s, t) && L(s.prev, s, s.next) > 0 && L(t.prev, t, t.next) > 0);
3985
4174
  }
3986
4175
  function L(s, t, e) {
3987
4176
  return (t.y - s.y) * (e.x - t.x) - (t.x - s.x) * (e.y - t.y);
3988
4177
  }
3989
- function vt(s, t) {
4178
+ function xt(s, t) {
3990
4179
  return s.x === t.x && s.y === t.y;
3991
4180
  }
3992
- function Zt(s, t, e, n) {
3993
- const i = ct(L(s, t, e)), r = ct(L(s, t, n)), o = ct(L(e, n, s)), l = ct(L(e, n, t));
3994
- return !!(i !== r && o !== l || i === 0 && ut(s, e, t) || r === 0 && ut(s, n, t) || o === 0 && ut(e, s, n) || l === 0 && ut(e, t, n));
4181
+ function Jt(s, t, e, n) {
4182
+ const i = ht(L(s, t, e)), r = ht(L(s, t, n)), o = ht(L(e, n, s)), l = ht(L(e, n, t));
4183
+ return !!(i !== r && o !== l || i === 0 && ct(s, e, t) || r === 0 && ct(s, n, t) || o === 0 && ct(e, s, n) || l === 0 && ct(e, t, n));
3995
4184
  }
3996
- function ut(s, t, e) {
4185
+ function ct(s, t, e) {
3997
4186
  return t.x <= Math.max(s.x, e.x) && t.x >= Math.min(s.x, e.x) && t.y <= Math.max(s.y, e.y) && t.y >= Math.min(s.y, e.y);
3998
4187
  }
3999
- function ct(s) {
4188
+ function ht(s) {
4000
4189
  return s > 0 ? 1 : s < 0 ? -1 : 0;
4001
4190
  }
4002
- function bn(s, t) {
4191
+ function On(s, t) {
4003
4192
  let e = s;
4004
4193
  do {
4005
- if (e.i !== s.i && e.next.i !== s.i && e.i !== t.i && e.next.i !== t.i && Zt(e, e.next, s, t)) return !0;
4194
+ if (e.i !== s.i && e.next.i !== s.i && e.i !== t.i && e.next.i !== t.i && Jt(e, e.next, s, t)) return !0;
4006
4195
  e = e.next;
4007
4196
  } while (e !== s);
4008
4197
  return !1;
@@ -4010,7 +4199,7 @@ function bn(s, t) {
4010
4199
  function st(s, t) {
4011
4200
  return L(s.prev, s, s.next) < 0 ? L(s, t, s.next) >= 0 && L(s, s.prev, t) >= 0 : L(s, t, s.prev) < 0 || L(s, s.next, t) < 0;
4012
4201
  }
4013
- function Sn(s, t) {
4202
+ function kn(s, t) {
4014
4203
  let e = s, n = !1;
4015
4204
  const i = (s.x + t.x) / 2, r = (s.y + t.y) / 2;
4016
4205
  do
@@ -4018,18 +4207,18 @@ function Sn(s, t) {
4018
4207
  while (e !== s);
4019
4208
  return n;
4020
4209
  }
4021
- function $t(s, t) {
4022
- const e = wt(s.i, s.x, s.y), n = wt(t.i, t.x, t.y), i = s.next, r = t.prev;
4210
+ function Qt(s, t) {
4211
+ const e = Rt(s.i, s.x, s.y), n = Rt(t.i, t.x, t.y), i = s.next, r = t.prev;
4023
4212
  return s.next = t, t.prev = s, e.next = i, i.prev = e, n.next = e, e.prev = n, r.next = n, n.prev = r, n;
4024
4213
  }
4025
- function Bt(s, t, e, n) {
4026
- const i = wt(s, t, e);
4214
+ function kt(s, t, e, n) {
4215
+ const i = Rt(s, t, e);
4027
4216
  return n ? (i.next = n.next, i.prev = n, n.next.prev = i, n.next = i) : (i.prev = i, i.next = i), i;
4028
4217
  }
4029
4218
  function ot(s) {
4030
4219
  s.next.prev = s.prev, s.prev.next = s.next, s.prevZ && (s.prevZ.nextZ = s.nextZ), s.nextZ && (s.nextZ.prevZ = s.prevZ);
4031
4220
  }
4032
- function wt(s, t, e) {
4221
+ function Rt(s, t, e) {
4033
4222
  return {
4034
4223
  i: s,
4035
4224
  x: t,
@@ -4042,7 +4231,7 @@ function wt(s, t, e) {
4042
4231
  steiner: !1
4043
4232
  };
4044
4233
  }
4045
- function yn(s, t, e, n) {
4234
+ function Hn(s, t, e, n) {
4046
4235
  let i = 0;
4047
4236
  for (let r = t, o = e - n; r < e; r += n)
4048
4237
  i += (s[o] - s[r]) * (s[r + 1] + s[o + 1]), o = r;
@@ -4104,15 +4293,15 @@ const R = {
4104
4293
  loop: !0,
4105
4294
  muted: !0
4106
4295
  }, J = 512, Q = 512;
4107
- class Et extends HTMLElement {
4296
+ class bt extends HTMLElement {
4108
4297
  static TAG_NAME = "layershift-portal";
4109
4298
  static get observedAttributes() {
4110
4299
  return [
4111
4300
  "src",
4112
- "depth-src",
4113
- "depth-width",
4114
- "depth-height",
4115
- "depth-fps",
4301
+ "map-src",
4302
+ "map-width",
4303
+ "map-height",
4304
+ "map-fps",
4116
4305
  "depth-model",
4117
4306
  "logo-src",
4118
4307
  "source-type",
@@ -4163,11 +4352,11 @@ class Et extends HTMLElement {
4163
4352
  "muted"
4164
4353
  ];
4165
4354
  }
4166
- reinitAttributes = ["src", "depth-src", "depth-width", "depth-height", "depth-fps", "depth-model", "logo-src", "source-type"];
4355
+ reinitAttributes = ["src", "map-src", "map-width", "map-height", "map-fps", "depth-model", "logo-src", "source-type"];
4167
4356
  canInit() {
4168
4357
  const t = !!this.getAttribute("logo-src");
4169
4358
  if (this.sourceType === "camera") return t;
4170
- const e = !!this.getAttribute("src"), n = !!this.getAttribute("depth-src"), i = !!this.getAttribute("depth-model");
4359
+ const e = !!this.getAttribute("src"), n = !!this.getAttribute("map-src"), i = !!this.getAttribute("depth-model");
4171
4360
  return e && t && (n || i);
4172
4361
  }
4173
4362
  _input = { x: 0, y: 0 };
@@ -4187,7 +4376,7 @@ class Et extends HTMLElement {
4187
4376
  loopCount = 0;
4188
4377
  lifecycle;
4189
4378
  constructor() {
4190
- super(), this.shadow = this.attachShadow({ mode: "open" }), this.lifecycle = new Wt(this);
4379
+ super(), this.shadow = this.attachShadow({ mode: "open" }), this.lifecycle = new Yt(this);
4191
4380
  }
4192
4381
  // --- Attribute helpers ---
4193
4382
  getAttrFloat(t, e) {
@@ -4203,7 +4392,7 @@ class Et extends HTMLElement {
4203
4392
  }
4204
4393
  getAttrColor(t, e) {
4205
4394
  const n = this.getAttribute(t) ?? e;
4206
- return wn(n);
4395
+ return Nn(n);
4207
4396
  }
4208
4397
  getAttrVec3(t, e) {
4209
4398
  const i = (this.getAttribute(t) ?? e).split(",").map((o) => parseFloat(o.trim()));
@@ -4438,62 +4627,62 @@ class Et extends HTMLElement {
4438
4627
  this.emit("layershift-portal:model-progress", d);
4439
4628
  };
4440
4629
  if (n) {
4441
- const [d, y] = await Promise.all([
4442
- Nt(
4630
+ const [d, S] = await Promise.all([
4631
+ zt(
4443
4632
  { video: { facingMode: "user" } },
4444
4633
  { parent: this.shadow }
4445
4634
  ),
4446
- Tt(e)
4635
+ Et(e)
4447
4636
  ]);
4448
4637
  if (t.aborted) {
4449
4638
  d.dispose();
4450
4639
  return;
4451
4640
  }
4452
- if (r = d, l = y, i) {
4453
- if (a = await dt(i, J, Q, h), t.aborted) {
4641
+ if (r = d, l = S, i) {
4642
+ if (a = await mt(i, J, Q, h), t.aborted) {
4454
4643
  a.dispose(), r.dispose();
4455
4644
  return;
4456
4645
  }
4457
- o = X(J, Q);
4646
+ o = N(J, Q);
4458
4647
  } else
4459
- o = X(r.width, r.height);
4648
+ o = N(r.width, r.height);
4460
4649
  } else {
4461
- const d = this.getAttribute("src"), y = this.getAttribute("depth-src"), b = !!y, E = this.sourceType === "image" || /\.(jpe?g|png|webp|gif|avif|bmp)(\?|$)/i.test(d);
4462
- if (b) {
4463
- const [g, v, m] = await Promise.all([
4464
- E ? ft(d) : ht(d, {
4650
+ const d = this.getAttribute("src"), S = this.getAttribute("map-src"), E = !!S, b = this.sourceType === "image" || /\.(jpe?g|png|webp|gif|avif|bmp)(\?|$)/i.test(d);
4651
+ if (E) {
4652
+ const [g, x, m] = await Promise.all([
4653
+ b ? dt(d) : ft(d, {
4465
4654
  parent: this.shadow,
4466
4655
  loop: this.shouldLoop,
4467
4656
  muted: this.shouldMute
4468
4657
  }),
4469
- kt(
4470
- y,
4471
- this.getAttrFloat("depth-width", 512),
4472
- this.getAttrFloat("depth-height", 512),
4473
- this.getAttrFloat("depth-fps", 5)
4658
+ Nt(
4659
+ S,
4660
+ this.getAttrFloat("map-width", 512),
4661
+ this.getAttrFloat("map-height", 512),
4662
+ this.getAttrFloat("map-fps", 5)
4474
4663
  ),
4475
- Tt(e)
4664
+ Et(e)
4476
4665
  ]);
4477
4666
  if (t.aborted) {
4478
4667
  g.dispose();
4479
4668
  return;
4480
4669
  }
4481
- r = g, o = v, l = m;
4670
+ r = g, o = x, l = m;
4482
4671
  } else if (i) {
4483
- const [g, v, m] = await Promise.all([
4484
- E ? ft(d) : ht(d, {
4672
+ const [g, x, m] = await Promise.all([
4673
+ b ? dt(d) : ft(d, {
4485
4674
  parent: this.shadow,
4486
4675
  loop: this.shouldLoop,
4487
4676
  muted: this.shouldMute
4488
4677
  }),
4489
- dt(i, J, Q, h),
4490
- Tt(e)
4678
+ mt(i, J, Q, h),
4679
+ Et(e)
4491
4680
  ]);
4492
4681
  if (t.aborted) {
4493
- g.dispose(), v.dispose();
4682
+ g.dispose(), x.dispose();
4494
4683
  return;
4495
4684
  }
4496
- if (r = g, a = v, l = m, E || !r.isLive) {
4685
+ if (r = g, a = x, l = m, b || !r.isLive) {
4497
4686
  const T = r.getImageSource();
4498
4687
  if (T) {
4499
4688
  const w = await a.submitFrameAndWait(T);
@@ -4505,11 +4694,11 @@ class Et extends HTMLElement {
4505
4694
  frames: [w]
4506
4695
  };
4507
4696
  } else
4508
- o = X(J, Q);
4697
+ o = N(J, Q);
4509
4698
  } else
4510
- o = X(J, Q);
4699
+ o = N(J, Q);
4511
4700
  } else
4512
- throw new Error("Either depth-src or depth-model must be provided.");
4701
+ throw new Error("Either map-src or depth-model must be provided.");
4513
4702
  }
4514
4703
  this.source = r, this.depthEstimator = a, this.mesh = l, this.loopCount = 0, this.attachSourceEventListeners(r);
4515
4704
  const c = this.container?.clientWidth || r.width, f = this.parallaxMax / Math.max(c, 1);
@@ -4517,10 +4706,10 @@ class Et extends HTMLElement {
4517
4706
  if (a)
4518
4707
  u = () => a.getLatestDepth();
4519
4708
  else {
4520
- const d = new Vt(o);
4521
- u = (y) => d.sample(y);
4709
+ const d = new Ht(o);
4710
+ u = (S) => d.sample(S);
4522
4711
  }
4523
- const x = {
4712
+ const v = {
4524
4713
  parallaxStrength: f,
4525
4714
  overscanPadding: this.overscan,
4526
4715
  pomSteps: this.pomSteps,
@@ -4562,20 +4751,22 @@ class Et extends HTMLElement {
4562
4751
  lightDirection: this.lightDirection3
4563
4752
  };
4564
4753
  if (t.aborted) return;
4565
- this.renderer = new $e(this.container, x), this.renderer.initialize(r, o.width, o.height, l);
4754
+ this.renderer = new mn(this.container, v), this.renderer.onError = (d) => {
4755
+ this.emit("layershift-portal:error", { message: d.message });
4756
+ }, this.renderer.initialize(r, o.width, o.height, l);
4566
4757
  const p = a;
4567
4758
  if (this.renderer.start(
4568
4759
  r,
4569
4760
  u,
4570
4761
  () => ({ x: this._input.x, y: this._input.y }),
4571
- (d, y) => {
4762
+ (d, S) => {
4572
4763
  if (p) {
4573
- const b = r.getImageSource();
4574
- b && p.submitFrame(b);
4764
+ const E = r.getImageSource();
4765
+ E && p.submitFrame(E);
4575
4766
  }
4576
4767
  this.emit("layershift-portal:frame", {
4577
4768
  currentTime: d,
4578
- frameNumber: y
4769
+ frameNumber: S
4579
4770
  });
4580
4771
  }
4581
4772
  ), !n && r.isLive && this.shouldAutoplay && r.play)
@@ -4599,7 +4790,7 @@ class Et extends HTMLElement {
4599
4790
  this.renderer?.dispose(), this.renderer = null, this.depthEstimator?.dispose(), this.depthEstimator = null, this.source?.dispose(), this.source = null, this.mesh = null, this.loopCount = 0, this.container = null;
4600
4791
  }
4601
4792
  }
4602
- function wn(s) {
4793
+ function Nn(s) {
4603
4794
  const t = s.replace("#", "");
4604
4795
  if (t.length === 3) {
4605
4796
  const e = parseInt(t[0] + t[0], 16) / 255, n = parseInt(t[1] + t[1], 16) / 255, i = parseInt(t[2] + t[2], 16) / 255;
@@ -4617,104 +4808,104 @@ function V(s, t, e) {
4617
4808
  function W(s, t, e) {
4618
4809
  return s + (t - s) * e;
4619
4810
  }
4620
- const N = 100, Kt = 0.06;
4621
- function Rn(s, t) {
4811
+ const X = 100, te = 0.06;
4812
+ function Xn(s, t) {
4622
4813
  const e = t?.sensitivityX ?? 1, n = t?.sensitivityY ?? 1, i = t?.lerpFactor ?? 0.08;
4623
4814
  let r = 0, o = 0, l = 0, a = 0, h = 0, c = !0;
4624
4815
  const f = (p) => {
4625
- const d = s.getBoundingClientRect(), y = (p.clientX - d.left) / d.width * 2 - 1, b = (p.clientY - d.top) / d.height * 2 - 1;
4626
- r = V(y, -1, 1), o = V(b, -1, 1);
4816
+ const d = s.getBoundingClientRect(), S = (p.clientX - d.left) / d.width * 2 - 1, E = (p.clientY - d.top) / d.height * 2 - 1;
4817
+ r = V(S, -1, 1), o = V(E, -1, 1);
4627
4818
  }, u = () => {
4628
4819
  r = 0, o = 0;
4629
- }, x = () => {
4630
- c && (l = W(l, r, i), a = W(a, o, i), s.input = { x: l * e, y: a * n }, h = requestAnimationFrame(x));
4820
+ }, v = () => {
4821
+ c && (l = W(l, r, i), a = W(a, o, i), s.input = { x: l * e, y: a * n }, h = requestAnimationFrame(v));
4631
4822
  };
4632
- return s.addEventListener("mousemove", f), s.addEventListener("mouseleave", u), h = requestAnimationFrame(x), () => {
4823
+ return s.addEventListener("mousemove", f), s.addEventListener("mouseleave", u), h = requestAnimationFrame(v), () => {
4633
4824
  c = !1, cancelAnimationFrame(h), s.removeEventListener("mousemove", f), s.removeEventListener("mouseleave", u);
4634
4825
  };
4635
4826
  }
4636
- function An(s, t) {
4827
+ function Gn(s, t) {
4637
4828
  const e = t?.sensitivityX ?? 1, n = t?.sensitivityY ?? 1, i = t?.lerpFactor ?? 0.08;
4638
4829
  let r = 0, o = 0, l = 0, a = 0, h = 0, c = 0, f = 0, u = !0;
4639
- const x = (b) => {
4640
- const E = b.touches[0];
4641
- E && (h = E.clientX - l * N, c = E.clientY - a * N, r = l, o = a);
4642
- }, p = (b) => {
4643
- const E = b.touches[0];
4644
- if (!E) return;
4645
- const g = E.clientX - h, v = E.clientY - c;
4646
- r = V(g / N, -1, 1), o = V(v / N, -1, 1);
4830
+ const v = (E) => {
4831
+ const b = E.touches[0];
4832
+ b && (h = b.clientX - l * X, c = b.clientY - a * X, r = l, o = a);
4833
+ }, p = (E) => {
4834
+ const b = E.touches[0];
4835
+ if (!b) return;
4836
+ const g = b.clientX - h, x = b.clientY - c;
4837
+ r = V(g / X, -1, 1), o = V(x / X, -1, 1);
4647
4838
  }, d = () => {
4648
4839
  r = 0, o = 0;
4649
- }, y = () => {
4650
- u && (l = W(l, r, i), a = W(a, o, i), s.input = { x: l * e, y: a * n }, f = requestAnimationFrame(y));
4840
+ }, S = () => {
4841
+ u && (l = W(l, r, i), a = W(a, o, i), s.input = { x: l * e, y: a * n }, f = requestAnimationFrame(S));
4651
4842
  };
4652
- return s.addEventListener("touchstart", x, { passive: !0 }), s.addEventListener("touchmove", p, { passive: !0 }), s.addEventListener("touchend", d, { passive: !0 }), s.addEventListener("touchcancel", d, { passive: !0 }), f = requestAnimationFrame(y), () => {
4653
- u = !1, cancelAnimationFrame(f), s.removeEventListener("touchstart", x), s.removeEventListener("touchmove", p), s.removeEventListener("touchend", d), s.removeEventListener("touchcancel", d);
4843
+ return s.addEventListener("touchstart", v, { passive: !0 }), s.addEventListener("touchmove", p, { passive: !0 }), s.addEventListener("touchend", d, { passive: !0 }), s.addEventListener("touchcancel", d, { passive: !0 }), f = requestAnimationFrame(S), () => {
4844
+ u = !1, cancelAnimationFrame(f), s.removeEventListener("touchstart", v), s.removeEventListener("touchmove", p), s.removeEventListener("touchend", d), s.removeEventListener("touchcancel", d);
4654
4845
  };
4655
4846
  }
4656
- function Pn(s, t) {
4657
- const e = t?.sensitivityX ?? 1, n = t?.sensitivityY ?? 1, i = t?.lerpFactor ?? Kt;
4847
+ function Wn(s, t) {
4848
+ const e = t?.sensitivityX ?? 1, n = t?.sensitivityY ?? 1, i = t?.lerpFactor ?? te;
4658
4849
  let r = 0, o = 0, l = 0, a = 0, h = 0, c = !0, f = !1;
4659
- const u = (y) => {
4660
- r = V((y.gamma ?? 0) / 45, -1, 1), o = V((y.beta ?? 0) / 45, -1, 1);
4661
- }, x = () => {
4662
- c && (l = W(l, r, i), a = W(a, o, i), s.input = { x: l * e, y: a * n }, h = requestAnimationFrame(x));
4850
+ const u = (S) => {
4851
+ r = V((S.gamma ?? 0) / 45, -1, 1), o = V((S.beta ?? 0) / 45, -1, 1);
4852
+ }, v = () => {
4853
+ c && (l = W(l, r, i), a = W(a, o, i), s.input = { x: l * e, y: a * n }, h = requestAnimationFrame(v));
4663
4854
  }, p = () => {
4664
4855
  c && !f && (window.addEventListener("deviceorientation", u), f = !0);
4665
4856
  }, d = DeviceOrientationEvent;
4666
- return typeof d.requestPermission == "function" ? d.requestPermission().then((y) => {
4667
- y === "granted" && p();
4857
+ return typeof d.requestPermission == "function" ? d.requestPermission().then((S) => {
4858
+ S === "granted" && p();
4668
4859
  }).catch(() => {
4669
- }) : p(), h = requestAnimationFrame(x), () => {
4860
+ }) : p(), h = requestAnimationFrame(v), () => {
4670
4861
  c = !1, cancelAnimationFrame(h), f && (window.removeEventListener("deviceorientation", u), f = !1);
4671
4862
  };
4672
4863
  }
4673
- function Dn(s, t) {
4674
- const e = t?.sensitivityX ?? 1, n = t?.sensitivityY ?? 1, i = t?.lerpFactor ?? 0.08, r = t?.lerpFactor ?? Kt;
4675
- let o = 0, l = 0, a = 0, h = 0, c = 0, f = 0, u = 0, x = 0, p = !1, d = !1, y = !1, b = 0, E = 0, g = 0, v = !0;
4676
- const m = (S) => {
4677
- const D = s.getBoundingClientRect(), U = (S.clientX - D.left) / D.width * 2 - 1, M = (S.clientY - D.top) / D.height * 2 - 1;
4864
+ function zn(s, t) {
4865
+ const e = t?.sensitivityX ?? 1, n = t?.sensitivityY ?? 1, i = t?.lerpFactor ?? 0.08, r = t?.lerpFactor ?? te;
4866
+ let o = 0, l = 0, a = 0, h = 0, c = 0, f = 0, u = 0, v = 0, p = !1, d = !1, S = !1, E = 0, b = 0, g = 0, x = !0;
4867
+ const m = (y) => {
4868
+ const D = s.getBoundingClientRect(), U = (y.clientX - D.left) / D.width * 2 - 1, M = (y.clientY - D.top) / D.height * 2 - 1;
4678
4869
  o = V(U, -1, 1), l = V(M, -1, 1);
4679
4870
  }, T = () => {
4680
4871
  o = 0, l = 0;
4681
- }, w = (S) => {
4682
- const D = S.touches[0];
4683
- D && (p = !0, b = D.clientX - u * N, E = D.clientY - x * N, a = u, h = x, !d && !y && I());
4684
- }, A = (S) => {
4685
- const D = S.touches[0];
4872
+ }, w = (y) => {
4873
+ const D = y.touches[0];
4874
+ D && (p = !0, E = D.clientX - u * X, b = D.clientY - v * X, a = u, h = v, !d && !S && I());
4875
+ }, A = (y) => {
4876
+ const D = y.touches[0];
4686
4877
  if (!D) return;
4687
- const U = D.clientX - b, M = D.clientY - E;
4688
- a = V(U / N, -1, 1), h = V(M / N, -1, 1);
4878
+ const U = D.clientX - E, M = D.clientY - b;
4879
+ a = V(U / X, -1, 1), h = V(M / X, -1, 1);
4689
4880
  }, P = () => {
4690
4881
  p = !1, a = 0, h = 0;
4691
- }, F = (S) => {
4692
- c = V((S.gamma ?? 0) / 45, -1, 1), f = V((S.beta ?? 0) / 45, -1, 1);
4882
+ }, F = (y) => {
4883
+ c = V((y.gamma ?? 0) / 45, -1, 1), f = V((y.beta ?? 0) / 45, -1, 1);
4693
4884
  }, _ = () => {
4694
- v && !y && (window.addEventListener("deviceorientation", F), y = !0, d = !0);
4885
+ x && !S && (window.addEventListener("deviceorientation", F), S = !0, d = !0);
4695
4886
  }, I = () => {
4696
4887
  if (typeof DeviceOrientationEvent > "u") return;
4697
- const S = DeviceOrientationEvent;
4698
- typeof S.requestPermission == "function" ? S.requestPermission().then((D) => {
4888
+ const y = DeviceOrientationEvent;
4889
+ typeof y.requestPermission == "function" ? y.requestPermission().then((D) => {
4699
4890
  D === "granted" && _();
4700
4891
  }).catch(() => {
4701
4892
  }) : _();
4702
4893
  }, C = () => {
4703
- if (!v) return;
4704
- let S, D, U;
4705
- p ? (S = a, D = h, U = i) : d ? (S = c, D = f, U = r) : (S = o, D = l, U = i), u = W(u, S, U), x = W(x, D, U), s.input = { x: u * e, y: x * n }, g = requestAnimationFrame(C);
4894
+ if (!x) return;
4895
+ let y, D, U;
4896
+ p ? (y = a, D = h, U = i) : d ? (y = c, D = f, U = r) : (y = o, D = l, U = i), u = W(u, y, U), v = W(v, D, U), s.input = { x: u * e, y: v * n }, g = requestAnimationFrame(C);
4706
4897
  };
4707
4898
  return s.addEventListener("mousemove", m), s.addEventListener("mouseleave", T), s.addEventListener("touchstart", w, { passive: !0 }), s.addEventListener("touchmove", A, { passive: !0 }), s.addEventListener("touchend", P, { passive: !0 }), s.addEventListener("touchcancel", P, { passive: !0 }), g = requestAnimationFrame(C), () => {
4708
- v = !1, cancelAnimationFrame(g), s.removeEventListener("mousemove", m), s.removeEventListener("mouseleave", T), s.removeEventListener("touchstart", w), s.removeEventListener("touchmove", A), s.removeEventListener("touchend", P), s.removeEventListener("touchcancel", P), y && (window.removeEventListener("deviceorientation", F), y = !1);
4899
+ x = !1, cancelAnimationFrame(g), s.removeEventListener("mousemove", m), s.removeEventListener("mouseleave", T), s.removeEventListener("touchstart", w), s.removeEventListener("touchmove", A), s.removeEventListener("touchend", P), s.removeEventListener("touchcancel", P), S && (window.removeEventListener("deviceorientation", F), S = !1);
4709
4900
  };
4710
4901
  }
4711
- customElements.get(xt.TAG_NAME) || customElements.define(xt.TAG_NAME, xt);
4712
- customElements.get(Et.TAG_NAME) || customElements.define(Et.TAG_NAME, Et);
4902
+ customElements.get(Tt.TAG_NAME) || customElements.define(Tt.TAG_NAME, Tt);
4903
+ customElements.get(bt.TAG_NAME) || customElements.define(bt.TAG_NAME, bt);
4713
4904
  export {
4714
- xt as LayershiftElement,
4715
- Et as LayershiftPortalElement,
4716
- Pn as connectGyro,
4717
- Rn as connectMouse,
4718
- Dn as connectPointer,
4719
- An as connectTouch
4905
+ Tt as LayershiftElement,
4906
+ bt as LayershiftPortalElement,
4907
+ Wn as connectGyro,
4908
+ Xn as connectMouse,
4909
+ zn as connectPointer,
4910
+ Gn as connectTouch
4720
4911
  };