layershift 0.2.1 → 0.2.2

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.
@@ -15,27 +15,27 @@ class st {
15
15
  * and should not be accessed.
16
16
  */
17
17
  static async create(t, e, i) {
18
- const r = new Worker(
18
+ const o = new Worker(
19
19
  new URL(
20
20
  /* @vite-ignore */
21
21
  "/assets/depth-worker-CMcEa805.js",
22
22
  import.meta.url
23
23
  ),
24
24
  { type: "module" }
25
- ), o = e * i, s = new st(r, o), a = t.frames.map((h) => {
26
- const l = new Uint8Array(h.length);
27
- return l.set(h), l.buffer;
25
+ ), n = e * i, s = new st(o, n), h = t.frames.map((a) => {
26
+ const l = new Uint8Array(a.length);
27
+ return l.set(a), l.buffer;
28
28
  });
29
- return await new Promise((h, l) => {
29
+ return await new Promise((a, l) => {
30
30
  const u = setTimeout(() => l(new Error("Worker init timeout")), 1e4);
31
- r.onmessage = (f) => {
32
- f.data.type === "ready" && (clearTimeout(u), h());
33
- }, r.onerror = (f) => {
31
+ o.onmessage = (f) => {
32
+ f.data.type === "ready" && (clearTimeout(u), a());
33
+ }, o.onerror = (f) => {
34
34
  clearTimeout(u), l(f);
35
- }, r.postMessage(
35
+ }, o.postMessage(
36
36
  {
37
37
  type: "init",
38
- frames: a,
38
+ frames: h,
39
39
  meta: {
40
40
  frameCount: t.meta.frameCount,
41
41
  fps: t.meta.fps,
@@ -45,11 +45,11 @@ class st {
45
45
  targetWidth: e,
46
46
  targetHeight: i
47
47
  },
48
- a
48
+ h
49
49
  // Transfer list
50
50
  );
51
- }), r.onmessage = (h) => {
52
- if (h.data.type === "result" && (s.currentBuffer = h.data.data, s.workerBusy = !1, s.pendingTimeSec !== null)) {
51
+ }), o.onmessage = (a) => {
52
+ if (a.data.type === "result" && (s.currentBuffer = a.data.data, s.workerBusy = !1, s.pendingTimeSec !== null)) {
53
53
  const l = s.pendingTimeSec;
54
54
  s.pendingTimeSec = null, s.requestSample(l);
55
55
  }
@@ -85,8 +85,8 @@ class st {
85
85
  class bt {
86
86
  constructor(t, e, i) {
87
87
  this.depthData = t, this.targetWidth = e, this.targetHeight = i;
88
- const r = t.meta.width * t.meta.height, o = e * i;
89
- this.interpolatedDepth = new Float32Array(r), this.bilateralOutput = new Float32Array(r), this.resizedDepth = new Float32Array(o), this.uint8Output = new Uint8Array(o);
88
+ const o = t.meta.width * t.meta.height, n = e * i;
89
+ this.interpolatedDepth = new Float32Array(o), this.bilateralOutput = new Float32Array(o), this.resizedDepth = new Float32Array(n), this.uint8Output = new Uint8Array(n);
90
90
  }
91
91
  interpolatedDepth;
92
92
  resizedDepth;
@@ -100,21 +100,21 @@ class bt {
100
100
  lastNextFrameIndex = -1;
101
101
  lastLerpFactor = -1;
102
102
  sample(t) {
103
- const e = Z(t * this.depthData.meta.fps, 0, this.depthData.meta.frameCount - 1), i = Math.floor(e), r = Math.min(i + 1, this.depthData.meta.frameCount - 1), o = e - i, s = i !== this.lastFrameIndex || r !== this.lastNextFrameIndex, a = Math.abs(o - this.lastLerpFactor) > 1e-3;
104
- if (!s && !a)
103
+ const e = Z(t * this.depthData.meta.fps, 0, this.depthData.meta.frameCount - 1), i = Math.floor(e), o = Math.min(i + 1, this.depthData.meta.frameCount - 1), n = e - i, s = i !== this.lastFrameIndex || o !== this.lastNextFrameIndex, h = Math.abs(n - this.lastLerpFactor) > 1e-3;
104
+ if (!s && !h)
105
105
  return this.uint8Output;
106
- this.lastFrameIndex = i, this.lastNextFrameIndex = r, this.lastLerpFactor = o;
107
- const h = 1 - o, l = this.depthData.frames[i], u = this.depthData.frames[r];
108
- for (let d = 0; d < this.interpolatedDepth.length; d += 1)
109
- this.interpolatedDepth[d] = (l[d] * h + u[d] * o) / 255;
110
- Ot(
106
+ this.lastFrameIndex = i, this.lastNextFrameIndex = o, this.lastLerpFactor = n;
107
+ const a = 1 - n, l = this.depthData.frames[i], u = this.depthData.frames[o];
108
+ for (let g = 0; g < this.interpolatedDepth.length; g += 1)
109
+ this.interpolatedDepth[g] = (l[g] * a + u[g] * n) / 255;
110
+ kt(
111
111
  this.interpolatedDepth,
112
112
  this.depthData.meta.width,
113
113
  this.depthData.meta.height,
114
114
  this.bilateralOutput
115
115
  );
116
116
  const f = this.targetWidth !== this.depthData.meta.width || this.targetHeight !== this.depthData.meta.height;
117
- f && Vt(
117
+ f && Ot(
118
118
  this.bilateralOutput,
119
119
  this.depthData.meta.width,
120
120
  this.depthData.meta.height,
@@ -123,24 +123,24 @@ class bt {
123
123
  this.resizedDepth
124
124
  );
125
125
  const c = f ? this.resizedDepth : this.bilateralOutput;
126
- for (let d = 0; d < this.uint8Output.length; d += 1)
127
- this.uint8Output[d] = c[d] * 255 + 0.5 | 0;
126
+ for (let g = 0; g < this.uint8Output.length; g += 1)
127
+ this.uint8Output[g] = c[g] * 255 + 0.5 | 0;
128
128
  return this.uint8Output;
129
129
  }
130
130
  }
131
- async function At(n, t, e) {
132
- const [i, r] = await Promise.all([
133
- Ct(t),
134
- Mt(n)
131
+ async function yt(r, t, e) {
132
+ const [i, o] = await Promise.all([
133
+ Mt(t),
134
+ _t(r)
135
135
  ]);
136
- return _t(r, i);
136
+ return It(o, i);
137
137
  }
138
- async function Ct(n) {
139
- const t = await fetch(n);
138
+ async function Mt(r) {
139
+ const t = await fetch(r);
140
140
  if (!t.ok)
141
141
  throw new Error(`Failed to fetch depth metadata (${t.status} ${t.statusText}).`);
142
142
  const e = await t.json();
143
- return It(e), {
143
+ return Vt(e), {
144
144
  frameCount: e.frameCount,
145
145
  fps: e.fps,
146
146
  width: e.width,
@@ -148,87 +148,87 @@ async function Ct(n) {
148
148
  sourceFps: e.sourceFps
149
149
  };
150
150
  }
151
- async function Mt(n, t) {
152
- const e = await fetch(n);
151
+ async function _t(r, t) {
152
+ const e = await fetch(r);
153
153
  if (!e.ok)
154
154
  throw new Error(`Failed to fetch depth data (${e.status} ${e.statusText}).`);
155
155
  e.headers.get("content-length");
156
156
  const i = e.body;
157
157
  if (!i)
158
158
  return new Uint8Array(await e.arrayBuffer());
159
- const r = [];
160
- let o = 0;
159
+ const o = [];
160
+ let n = 0;
161
161
  const s = i.getReader();
162
162
  for (; ; ) {
163
163
  const { done: l, value: u } = await s.read();
164
164
  if (l)
165
165
  break;
166
- u && (r.push(u), o += u.byteLength);
166
+ u && (o.push(u), n += u.byteLength);
167
167
  }
168
- const a = new Uint8Array(o);
169
- let h = 0;
170
- for (const l of r)
171
- a.set(l, h), h += l.byteLength;
172
- return a;
168
+ const h = new Uint8Array(n);
169
+ let a = 0;
170
+ for (const l of o)
171
+ h.set(l, a), a += l.byteLength;
172
+ return h;
173
173
  }
174
- function _t(n, t) {
175
- if (n.byteLength < 4)
174
+ function It(r, t) {
175
+ if (r.byteLength < 4)
176
176
  throw new Error("Depth data binary is missing the frame-count header.");
177
- const i = new DataView(n.buffer, n.byteOffset, n.byteLength).getUint32(0, !0), r = t.width * t.height, o = 4 + i * r;
178
- if (n.byteLength !== o)
177
+ const i = new DataView(r.buffer, r.byteOffset, r.byteLength).getUint32(0, !0), o = t.width * t.height, n = 4 + i * o;
178
+ if (r.byteLength !== n)
179
179
  throw new Error(
180
- `Depth data byte length mismatch. Expected ${o} bytes, received ${n.byteLength}.`
180
+ `Depth data byte length mismatch. Expected ${n} bytes, received ${r.byteLength}.`
181
181
  );
182
182
  if (i !== t.frameCount)
183
183
  throw new Error(
184
184
  `Depth frame count mismatch between metadata (${t.frameCount}) and binary header (${i}).`
185
185
  );
186
- const s = n.subarray(4), a = new Array(i);
187
- for (let h = 0; h < i; h += 1) {
188
- const l = h * r;
189
- a[h] = s.subarray(l, l + r);
186
+ const s = r.subarray(4), h = new Array(i);
187
+ for (let a = 0; a < i; a += 1) {
188
+ const l = a * o;
189
+ h[a] = s.subarray(l, l + o);
190
190
  }
191
- return { meta: t, frames: a };
191
+ return { meta: t, frames: h };
192
192
  }
193
- function It(n) {
194
- if (!n || typeof n.frameCount != "number" || typeof n.fps != "number" || typeof n.width != "number" || typeof n.height != "number" || typeof n.sourceFps != "number")
193
+ function Vt(r) {
194
+ if (!r || typeof r.frameCount != "number" || typeof r.fps != "number" || typeof r.width != "number" || typeof r.height != "number" || typeof r.sourceFps != "number")
195
195
  throw new Error("Depth metadata is malformed.");
196
- if (!Number.isFinite(n.frameCount) || !Number.isFinite(n.fps) || !Number.isFinite(n.width) || !Number.isFinite(n.height) || !Number.isFinite(n.sourceFps) || n.frameCount <= 0 || n.fps <= 0 || n.width <= 0 || n.height <= 0 || n.sourceFps <= 0)
196
+ if (!Number.isFinite(r.frameCount) || !Number.isFinite(r.fps) || !Number.isFinite(r.width) || !Number.isFinite(r.height) || !Number.isFinite(r.sourceFps) || r.frameCount <= 0 || r.fps <= 0 || r.width <= 0 || r.height <= 0 || r.sourceFps <= 0)
197
197
  throw new Error("Depth metadata contains invalid numeric values.");
198
198
  }
199
- function Vt(n, t, e, i, r, o) {
200
- const s = t / i, a = e / r;
201
- for (let h = 0; h < r; h += 1) {
202
- const l = (h + 0.5) * a - 0.5, u = Z(Math.floor(l), 0, e - 1), f = Z(u + 1, 0, e - 1), c = l - u;
203
- for (let d = 0; d < i; d += 1) {
204
- const m = (d + 0.5) * s - 0.5, g = Z(Math.floor(m), 0, t - 1), U = Z(g + 1, 0, t - 1), b = m - g, E = n[u * t + g], p = n[u * t + U], v = n[f * t + g], T = n[f * t + U], x = E + (p - E) * b, y = v + (T - v) * b;
205
- o[h * i + d] = x + (y - x) * c;
199
+ function Ot(r, t, e, i, o, n) {
200
+ const s = t / i, h = e / o;
201
+ for (let a = 0; a < o; a += 1) {
202
+ const l = (a + 0.5) * h - 0.5, u = Z(Math.floor(l), 0, e - 1), f = Z(u + 1, 0, e - 1), c = l - u;
203
+ for (let g = 0; g < i; g += 1) {
204
+ const d = (g + 0.5) * s - 0.5, m = Z(Math.floor(d), 0, t - 1), U = Z(m + 1, 0, t - 1), b = d - m, E = r[u * t + m], p = r[u * t + U], v = r[f * t + m], T = r[f * t + U], x = E + (p - E) * b, A = v + (T - v) * b;
205
+ n[a * i + g] = x + (A - x) * c;
206
206
  }
207
207
  }
208
208
  }
209
- function Ot(n, t, e, i) {
209
+ function kt(r, t, e, i) {
210
210
  for (let s = 0; s < e; s += 1)
211
- for (let a = 0; a < t; a += 1) {
212
- const h = s * t + a, l = n[h];
211
+ for (let h = 0; h < t; h += 1) {
212
+ const a = s * t + h, l = r[a];
213
213
  let u = 1, f = l;
214
214
  for (let c = -2; c <= 2; c += 1) {
215
- const d = s + c;
216
- if (!(d < 0 || d >= e))
217
- for (let m = -2; m <= 2; m += 1) {
218
- if (m === 0 && c === 0) continue;
219
- const g = a + m;
220
- if (g < 0 || g >= t) continue;
221
- const U = n[d * t + g], b = m * m + c * c, E = U - l, p = Math.exp(-b / 2.25 - E * E / 0.01);
215
+ const g = s + c;
216
+ if (!(g < 0 || g >= e))
217
+ for (let d = -2; d <= 2; d += 1) {
218
+ if (d === 0 && c === 0) continue;
219
+ const m = h + d;
220
+ if (m < 0 || m >= t) continue;
221
+ const U = r[g * t + m], b = d * d + c * c, E = U - l, p = Math.exp(-b / 2.25 - E * E / 0.01);
222
222
  u += p, f += U * p;
223
223
  }
224
224
  }
225
- i[h] = f / u;
225
+ i[a] = f / u;
226
226
  }
227
227
  }
228
- function Z(n, t, e) {
229
- return Math.min(e, Math.max(t, n));
228
+ function Z(r, t, e) {
229
+ return Math.min(e, Math.max(t, r));
230
230
  }
231
- const kt = {
231
+ const Bt = {
232
232
  parallaxStrength: 0.05,
233
233
  contrastLow: 0.05,
234
234
  contrastHigh: 0.95,
@@ -238,123 +238,123 @@ const kt = {
238
238
  pomSteps: 16,
239
239
  overscanPadding: 0.08
240
240
  };
241
- function Ht(n, t, e) {
241
+ function Ht(r, t, e) {
242
242
  const i = new Float32Array(256);
243
- if (n.length === 0 || t <= 0 || e <= 0)
243
+ if (r.length === 0 || t <= 0 || e <= 0)
244
244
  return pt(i);
245
- const r = Xt(n.length), o = t * e;
245
+ const o = Nt(r.length), n = t * e;
246
246
  let s = 0;
247
- const a = new Uint32Array(256);
248
- for (const T of r) {
249
- const x = n[T], y = Math.min(x.length, o);
250
- for (let S = 0; S < y; S += 1)
251
- a[x[S]] += 1;
252
- s += y;
247
+ const h = new Uint32Array(256);
248
+ for (const T of o) {
249
+ const x = r[T], A = Math.min(x.length, n);
250
+ for (let S = 0; S < A; S += 1)
251
+ h[x[S]] += 1;
252
+ s += A;
253
253
  }
254
254
  if (s === 0)
255
255
  return pt(i);
256
- const h = 1 / s;
256
+ const a = 1 / s;
257
257
  for (let T = 0; T < 256; T += 1)
258
- i[T] = a[T] * h;
258
+ i[T] = h[T] * a;
259
259
  const l = new Float32Array(256);
260
260
  l[0] = i[0];
261
261
  for (let T = 1; T < 256; T += 1)
262
262
  l[T] = l[T - 1] + i[T];
263
- const u = Y(l, 0.05), f = Y(l, 0.25), c = Y(l, 0.5), d = Y(l, 0.75), m = Y(l, 0.95);
264
- let g = 0;
263
+ const u = Y(l, 0.05), f = Y(l, 0.25), c = Y(l, 0.5), g = Y(l, 0.75), d = Y(l, 0.95);
264
+ let m = 0;
265
265
  for (let T = 0; T < 256; T += 1)
266
- g += T / 255 * i[T];
266
+ m += T / 255 * i[T];
267
267
  let U = 0;
268
268
  for (let T = 0; T < 256; T += 1) {
269
- const x = T / 255 - g;
269
+ const x = T / 255 - m;
270
270
  U += i[T] * x * x;
271
271
  }
272
- const b = Math.sqrt(U), E = m - u, p = d - f, v = Nt(i);
272
+ const b = Math.sqrt(U), E = d - u, p = g - f, v = zt(i);
273
273
  return {
274
- mean: g,
274
+ mean: m,
275
275
  stdDev: b,
276
276
  p5: u,
277
277
  p25: f,
278
278
  median: c,
279
- p75: d,
280
- p95: m,
279
+ p75: g,
280
+ p95: d,
281
281
  effectiveRange: E,
282
282
  iqr: p,
283
283
  bimodality: v,
284
284
  histogram: i
285
285
  };
286
286
  }
287
- function Bt(n) {
288
- if (n.effectiveRange < 0.05 || n.stdDev < 0.02)
289
- return { ...kt };
290
- const t = n.effectiveRange - 0.5, e = n.bimodality - 0.4, i = O(
287
+ function Xt(r) {
288
+ if (r.effectiveRange < 0.05 || r.stdDev < 0.02)
289
+ return { ...Bt };
290
+ const t = r.effectiveRange - 0.5, e = r.bimodality - 0.4, i = O(
291
291
  0.05 - t * 0.03 + e * 0.01,
292
292
  0.035,
293
293
  0.065
294
- ), r = O(n.p5 - 0.03, 0, 0.25), o = O(n.p95 + 0.03, 0.75, 1), s = O((i - 0.03) / 0.05, 0, 1), a = O(0.6 - s * 0.25, 0.35, 0.6), h = O(0.6 - t * 0.2, 0.5, 0.7), l = O(0.4 + t * 0.2, 0.25, 0.5), u = 16, f = O(i + 0.03, 0.06, 0.1);
294
+ ), o = O(r.p5 - 0.03, 0, 0.25), n = O(r.p95 + 0.03, 0.75, 1), s = O((i - 0.03) / 0.05, 0, 1), h = O(0.6 - s * 0.25, 0.35, 0.6), a = O(0.6 - t * 0.2, 0.5, 0.7), l = O(0.4 + t * 0.2, 0.25, 0.5), u = 16, f = O(i + 0.03, 0.06, 0.1);
295
295
  return {
296
296
  parallaxStrength: i,
297
- contrastLow: r,
298
- contrastHigh: o,
299
- verticalReduction: a,
300
- dofStart: h,
297
+ contrastLow: o,
298
+ contrastHigh: n,
299
+ verticalReduction: h,
300
+ dofStart: a,
301
301
  dofStrength: l,
302
302
  pomSteps: u,
303
303
  overscanPadding: f
304
304
  };
305
305
  }
306
- function Xt(n) {
307
- if (n <= 0) return [];
308
- if (n === 1) return [0];
309
- const t = n - 1, e = [
306
+ function Nt(r) {
307
+ if (r <= 0) return [];
308
+ if (r === 1) return [0];
309
+ const t = r - 1, e = [
310
310
  0,
311
- Math.floor(n / 4),
312
- Math.floor(n / 2),
313
- Math.floor(3 * n / 4),
311
+ Math.floor(r / 4),
312
+ Math.floor(r / 2),
313
+ Math.floor(3 * r / 4),
314
314
  t
315
- ], i = /* @__PURE__ */ new Set(), r = [];
316
- for (const o of e)
317
- i.has(o) || (i.add(o), r.push(o));
318
- return r;
315
+ ], i = /* @__PURE__ */ new Set(), o = [];
316
+ for (const n of e)
317
+ i.has(n) || (i.add(n), o.push(n));
318
+ return o;
319
319
  }
320
- function Y(n, t) {
320
+ function Y(r, t) {
321
321
  for (let e = 0; e < 256; e += 1)
322
- if (n[e] >= t)
322
+ if (r[e] >= t)
323
323
  return e / 255;
324
324
  return 1;
325
325
  }
326
- function Nt(n) {
326
+ function zt(r) {
327
327
  const t = new Float32Array(256);
328
328
  for (let c = 0; c < 256; c += 1) {
329
- let d = 0, m = 0;
330
- for (let g = c - 2; g <= c + 2; g += 1)
331
- g >= 0 && g < 256 && (d += n[g], m += 1);
332
- t[c] = d / m;
329
+ let g = 0, d = 0;
330
+ for (let m = c - 2; m <= c + 2; m += 1)
331
+ m >= 0 && m < 256 && (g += r[m], d += 1);
332
+ t[c] = g / d;
333
333
  }
334
334
  let e = 0;
335
335
  for (let c = 0; c < 256; c += 1)
336
336
  e += t[c];
337
337
  e /= 256;
338
- const i = e * 2, r = 25, o = [];
338
+ const i = e * 2, o = 25, n = [];
339
339
  for (let c = 1; c < 255; c += 1)
340
- t[c] > t[c - 1] && t[c] > t[c + 1] && t[c] >= i && o.push({ bin: c, height: t[c] });
341
- if (t[0] > t[1] && t[0] >= i && o.push({ bin: 0, height: t[0] }), t[255] > t[254] && t[255] >= i && o.push({ bin: 255, height: t[255] }), o.sort((c, d) => d.height - c.height), o.length < 2) return 0;
342
- const s = o[0];
343
- let a = null;
344
- for (let c = 1; c < o.length; c += 1)
345
- if (Math.abs(o[c].bin - s.bin) >= r) {
346
- a = o[c];
340
+ t[c] > t[c - 1] && t[c] > t[c + 1] && t[c] >= i && n.push({ bin: c, height: t[c] });
341
+ if (t[0] > t[1] && t[0] >= i && n.push({ bin: 0, height: t[0] }), t[255] > t[254] && t[255] >= i && n.push({ bin: 255, height: t[255] }), n.sort((c, g) => g.height - c.height), n.length < 2) return 0;
342
+ const s = n[0];
343
+ let h = null;
344
+ for (let c = 1; c < n.length; c += 1)
345
+ if (Math.abs(n[c].bin - s.bin) >= o) {
346
+ h = n[c];
347
347
  break;
348
348
  }
349
- if (!a) return 0;
350
- const h = Math.min(s.bin, a.bin), l = Math.max(s.bin, a.bin);
349
+ if (!h) return 0;
350
+ const a = Math.min(s.bin, h.bin), l = Math.max(s.bin, h.bin);
351
351
  let u = 1 / 0;
352
- for (let c = h; c <= l; c += 1)
352
+ for (let c = a; c <= l; c += 1)
353
353
  t[c] < u && (u = t[c]);
354
- const f = Math.min(s.height, a.height);
354
+ const f = Math.min(s.height, h.height);
355
355
  return f <= 0 ? 0 : O(1 - u / f, 0, 1);
356
356
  }
357
- function pt(n) {
357
+ function pt(r) {
358
358
  return {
359
359
  mean: 0,
360
360
  stdDev: 0,
@@ -366,13 +366,13 @@ function pt(n) {
366
366
  effectiveRange: 0,
367
367
  iqr: 0,
368
368
  bimodality: 0,
369
- histogram: n
369
+ histogram: r
370
370
  };
371
371
  }
372
- function O(n, t, e) {
373
- return Math.min(e, Math.max(t, n));
372
+ function O(r, t, e) {
373
+ return Math.min(e, Math.max(t, r));
374
374
  }
375
- const zt = (
375
+ const Wt = (
376
376
  /* glsl */
377
377
  `#version 300 es
378
378
  in vec2 aPosition;
@@ -396,7 +396,7 @@ const zt = (
396
396
  gl_Position = vec4(aPosition, 0.0, 1.0);
397
397
  }
398
398
  `
399
- ), Wt = (
399
+ ), Gt = (
400
400
  /* glsl */
401
401
  `#version 300 es
402
402
  precision highp float;
@@ -574,42 +574,42 @@ const zt = (
574
574
  dofStart: 0.6,
575
575
  dofStrength: 0.4
576
576
  };
577
- function gt(n, t, e) {
578
- const i = n.createShader(t);
577
+ function gt(r, t, e) {
578
+ const i = r.createShader(t);
579
579
  if (!i) throw new Error("Failed to create shader.");
580
- if (n.shaderSource(i, e), n.compileShader(i), !n.getShaderParameter(i, n.COMPILE_STATUS)) {
581
- const r = n.getShaderInfoLog(i) ?? "";
582
- throw n.deleteShader(i), new Error(`Shader compilation failed:
583
- ${r}`);
580
+ if (r.shaderSource(i, e), r.compileShader(i), !r.getShaderParameter(i, r.COMPILE_STATUS)) {
581
+ const o = r.getShaderInfoLog(i) ?? "";
582
+ throw r.deleteShader(i), new Error(`Shader compilation failed:
583
+ ${o}`);
584
584
  }
585
585
  return i;
586
586
  }
587
- function Gt(n, t, e) {
588
- const i = n.createProgram();
587
+ function jt(r, t, e) {
588
+ const i = r.createProgram();
589
589
  if (!i) throw new Error("Failed to create program.");
590
- if (n.attachShader(i, t), n.attachShader(i, e), n.linkProgram(i), !n.getProgramParameter(i, n.LINK_STATUS)) {
591
- const r = n.getProgramInfoLog(i) ?? "";
592
- throw n.deleteProgram(i), new Error(`Program linking failed:
593
- ${r}`);
590
+ if (r.attachShader(i, t), r.attachShader(i, e), r.linkProgram(i), !r.getProgramParameter(i, r.LINK_STATUS)) {
591
+ const o = r.getProgramInfoLog(i) ?? "";
592
+ throw r.deleteProgram(i), new Error(`Program linking failed:
593
+ ${o}`);
594
594
  }
595
- return n.detachShader(i, t), n.detachShader(i, e), n.deleteShader(t), n.deleteShader(e), i;
595
+ return r.detachShader(i, t), r.detachShader(i, e), r.deleteShader(t), r.deleteShader(e), i;
596
596
  }
597
- function jt(n, t) {
597
+ function Yt(r, t) {
598
598
  return {
599
- uImage: n.getUniformLocation(t, "uImage"),
600
- uDepth: n.getUniformLocation(t, "uDepth"),
601
- uOffset: n.getUniformLocation(t, "uOffset"),
602
- uStrength: n.getUniformLocation(t, "uStrength"),
603
- uPomEnabled: n.getUniformLocation(t, "uPomEnabled"),
604
- uPomSteps: n.getUniformLocation(t, "uPomSteps"),
605
- uContrastLow: n.getUniformLocation(t, "uContrastLow"),
606
- uContrastHigh: n.getUniformLocation(t, "uContrastHigh"),
607
- uVerticalReduction: n.getUniformLocation(t, "uVerticalReduction"),
608
- uDofStart: n.getUniformLocation(t, "uDofStart"),
609
- uDofStrength: n.getUniformLocation(t, "uDofStrength"),
610
- uImageTexelSize: n.getUniformLocation(t, "uImageTexelSize"),
611
- uUvOffset: n.getUniformLocation(t, "uUvOffset"),
612
- uUvScale: n.getUniformLocation(t, "uUvScale")
599
+ uImage: r.getUniformLocation(t, "uImage"),
600
+ uDepth: r.getUniformLocation(t, "uDepth"),
601
+ uOffset: r.getUniformLocation(t, "uOffset"),
602
+ uStrength: r.getUniformLocation(t, "uStrength"),
603
+ uPomEnabled: r.getUniformLocation(t, "uPomEnabled"),
604
+ uPomSteps: r.getUniformLocation(t, "uPomSteps"),
605
+ uContrastLow: r.getUniformLocation(t, "uContrastLow"),
606
+ uContrastHigh: r.getUniformLocation(t, "uContrastHigh"),
607
+ uVerticalReduction: r.getUniformLocation(t, "uVerticalReduction"),
608
+ uDofStart: r.getUniformLocation(t, "uDofStart"),
609
+ uDofStrength: r.getUniformLocation(t, "uDofStrength"),
610
+ uImageTexelSize: r.getUniformLocation(t, "uImageTexelSize"),
611
+ uUvOffset: r.getUniformLocation(t, "uUvOffset"),
612
+ uUvScale: r.getUniformLocation(t, "uUvScale")
613
613
  };
614
614
  }
615
615
  class $ {
@@ -694,8 +694,8 @@ class $ {
694
694
  * @param depthHeight - Height of the precomputed depth map (e.g. 512).
695
695
  */
696
696
  initialize(t, e, i) {
697
- const r = this.gl;
698
- r && (this.disposeTextures(), this.videoAspect = t.videoWidth / t.videoHeight, this.depthWidth = e, this.depthHeight = i, this.videoTexture = r.createTexture(), r.activeTexture(r.TEXTURE0), r.bindTexture(r.TEXTURE_2D, this.videoTexture), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), this.depthTexture = r.createTexture(), r.activeTexture(r.TEXTURE1), r.bindTexture(r.TEXTURE_2D, this.depthTexture), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.texStorage2D(r.TEXTURE_2D, 1, r.R8, e, i), this.program && this.uniforms && (r.useProgram(this.program), r.uniform1i(this.uniforms.uImage, 0), r.uniform1i(this.uniforms.uDepth, 1), r.uniform1f(this.uniforms.uStrength, this.config.parallaxStrength), r.uniform1i(this.uniforms.uPomEnabled, this.config.pomEnabled ? 1 : 0), r.uniform1i(this.uniforms.uPomSteps, this.config.pomSteps), r.uniform1f(this.uniforms.uContrastLow, this.config.contrastLow), r.uniform1f(this.uniforms.uContrastHigh, this.config.contrastHigh), r.uniform1f(this.uniforms.uVerticalReduction, this.config.verticalReduction), r.uniform1f(this.uniforms.uDofStart, this.config.dofStart), r.uniform1f(this.uniforms.uDofStrength, this.config.dofStrength), r.uniform2f(this.uniforms.uImageTexelSize, 1 / t.videoWidth, 1 / t.videoHeight)), this.recalculateViewportLayout());
697
+ const o = this.gl;
698
+ o && (this.disposeTextures(), this.videoAspect = t.videoWidth / t.videoHeight, this.depthWidth = e, this.depthHeight = i, this.videoTexture = o.createTexture(), o.activeTexture(o.TEXTURE0), o.bindTexture(o.TEXTURE_2D, this.videoTexture), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), this.depthTexture = o.createTexture(), o.activeTexture(o.TEXTURE1), o.bindTexture(o.TEXTURE_2D, this.depthTexture), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), o.texStorage2D(o.TEXTURE_2D, 1, o.R8, e, i), this.program && this.uniforms && (o.useProgram(this.program), o.uniform1i(this.uniforms.uImage, 0), o.uniform1i(this.uniforms.uDepth, 1), o.uniform1f(this.uniforms.uStrength, this.config.parallaxStrength), o.uniform1i(this.uniforms.uPomEnabled, this.config.pomEnabled ? 1 : 0), o.uniform1i(this.uniforms.uPomSteps, this.config.pomSteps), o.uniform1f(this.uniforms.uContrastLow, this.config.contrastLow), o.uniform1f(this.uniforms.uContrastHigh, this.config.contrastHigh), o.uniform1f(this.uniforms.uVerticalReduction, this.config.verticalReduction), o.uniform1f(this.uniforms.uDofStart, this.config.dofStart), o.uniform1f(this.uniforms.uDofStrength, this.config.dofStrength), o.uniform2f(this.uniforms.uImageTexelSize, 1 / t.videoWidth, 1 / t.videoHeight)), this.recalculateViewportLayout());
699
699
  }
700
700
  /**
701
701
  * Begin the render loop.
@@ -707,8 +707,8 @@ class $ {
707
707
  * When RVFC is not available, falls back to a single RAF loop that
708
708
  * does everything (the pre-RVFC behavior).
709
709
  */
710
- start(t, e, i, r) {
711
- this.stop(), this.playbackVideo = t, this.readDepth = e, this.readInput = i, this.onVideoFrame = r ?? null, this.rvfcSupported = $.isRVFCSupported(), this.rvfcSupported && (this.rvfcHandle = t.requestVideoFrameCallback(this.videoFrameLoop)), this.animationFrameHandle = window.requestAnimationFrame(this.renderLoop);
710
+ start(t, e, i, o) {
711
+ this.stop(), this.playbackVideo = t, this.readDepth = e, this.readInput = i, this.onVideoFrame = o ?? null, this.rvfcSupported = $.isRVFCSupported(), this.rvfcSupported && (this.rvfcHandle = t.requestVideoFrameCallback(this.videoFrameLoop)), this.animationFrameHandle = window.requestAnimationFrame(this.renderLoop);
712
712
  }
713
713
  /** Stop both render loops and release callbacks. */
714
714
  stop() {
@@ -716,7 +716,7 @@ class $ {
716
716
  }
717
717
  /** Stop rendering and release all GPU resources. */
718
718
  dispose() {
719
- this.stop(), this.disposeTextures(), this.disposeGPUResources(), this.canvas.removeEventListener("webglcontextlost", this.handleContextLost), this.canvas.removeEventListener("webglcontextrestored", this.handleContextRestored), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), window.removeEventListener("resize", this.scheduleResizeRecalculate), this.resizeTimer !== null && (window.clearTimeout(this.resizeTimer), this.resizeTimer = null);
719
+ this.stop(), this.disposeTextures(), this.disposeGPUResources(), this.canvas.removeEventListener("webglcontextlost", this.handleContextLost), this.canvas.removeEventListener("webglcontextrestored", this.handleContextRestored), this.gl && (this.gl.getExtension("WEBGL_lose_context")?.loseContext(), this.gl = null), this.canvas.remove(), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), window.removeEventListener("resize", this.scheduleResizeRecalculate), this.resizeTimer !== null && (window.clearTimeout(this.resizeTimer), this.resizeTimer = null);
720
720
  }
721
721
  // -----------------------------------------------------------------------
722
722
  // GPU resource initialization
@@ -725,13 +725,13 @@ class $ {
725
725
  initGPUResources() {
726
726
  const t = this.gl;
727
727
  if (!t) return;
728
- const e = Wt.replace(
728
+ const e = Gt.replace(
729
729
  "#version 300 es",
730
730
  `#version 300 es
731
731
  #define MAX_POM_STEPS ${$.MAX_POM_STEPS}`
732
- ), i = gt(t, t.VERTEX_SHADER, zt), r = gt(t, t.FRAGMENT_SHADER, e);
733
- this.program = Gt(t, i, r), this.uniforms = jt(t, this.program);
734
- const o = new Float32Array([
732
+ ), i = gt(t, t.VERTEX_SHADER, Wt), o = gt(t, t.FRAGMENT_SHADER, e);
733
+ this.program = jt(t, i, o), this.uniforms = Yt(t, this.program);
734
+ const n = new Float32Array([
735
735
  -1,
736
736
  -1,
737
737
  // bottom-left
@@ -747,9 +747,9 @@ class $ {
747
747
  ]);
748
748
  this.vao = t.createVertexArray(), t.bindVertexArray(this.vao);
749
749
  const s = t.createBuffer();
750
- t.bindBuffer(t.ARRAY_BUFFER, s), t.bufferData(t.ARRAY_BUFFER, o, t.STATIC_DRAW);
751
- const a = t.getAttribLocation(this.program, "aPosition");
752
- t.enableVertexAttribArray(a), t.vertexAttribPointer(a, 2, t.FLOAT, !1, 0, 0), t.bindVertexArray(null), t.disable(t.DEPTH_TEST);
750
+ t.bindBuffer(t.ARRAY_BUFFER, s), t.bufferData(t.ARRAY_BUFFER, n, t.STATIC_DRAW);
751
+ const h = t.getAttribLocation(this.program, "aPosition");
752
+ t.enableVertexAttribArray(h), t.vertexAttribPointer(h, 2, t.FLOAT, !1, 0, 0), t.bindVertexArray(null), t.disable(t.DEPTH_TEST);
753
753
  }
754
754
  // -----------------------------------------------------------------------
755
755
  // RVFC feature detection
@@ -771,8 +771,8 @@ class $ {
771
771
  const i = this.playbackVideo;
772
772
  if (!i) return;
773
773
  this.rvfcHandle = i.requestVideoFrameCallback(this.videoFrameLoop);
774
- const r = e.mediaTime ?? i.currentTime;
775
- this.updateDepthTexture(r), this.onVideoFrame && this.onVideoFrame(r, e.presentedFrames ?? 0);
774
+ const o = e.mediaTime ?? i.currentTime;
775
+ this.updateDepthTexture(o), this.onVideoFrame && this.onVideoFrame(o, e.presentedFrames ?? 0);
776
776
  };
777
777
  // -----------------------------------------------------------------------
778
778
  // Render loop (RAF) — input + render at display refresh rate
@@ -844,12 +844,12 @@ class $ {
844
844
  recalculateViewportLayout() {
845
845
  const t = this.gl;
846
846
  if (!t) return;
847
- const { width: e, height: i } = this.getViewportSize(), r = Math.min(window.devicePixelRatio, 2), o = Math.round(e * r), s = Math.round(i * r);
848
- (this.canvas.width !== o || this.canvas.height !== s) && (this.canvas.width = o, this.canvas.height = s, t.viewport(0, 0, o, s));
849
- const a = e / i, h = this.config.parallaxStrength + this.config.overscanPadding;
847
+ const { width: e, height: i } = this.getViewportSize(), o = Math.min(window.devicePixelRatio, 2), n = Math.round(e * o), s = Math.round(i * o);
848
+ (this.canvas.width !== n || this.canvas.height !== s) && (this.canvas.width = n, this.canvas.height = s, t.viewport(0, 0, n, s));
849
+ const h = e / i, a = this.config.parallaxStrength + this.config.overscanPadding;
850
850
  let l = 1, u = 1;
851
- a > this.videoAspect ? u = this.videoAspect / a : l = a / this.videoAspect;
852
- const f = 1 + h * 2;
851
+ h > this.videoAspect ? u = this.videoAspect / h : l = h / this.videoAspect;
852
+ const f = 1 + a * 2;
853
853
  l /= f, u /= f, this.uvOffset = [(1 - l) / 2, (1 - u) / 2], this.uvScale = [l, u], this.program && this.uniforms && (t.useProgram(this.program), t.uniform2f(this.uniforms.uUvOffset, this.uvOffset[0], this.uvOffset[1]), t.uniform2f(this.uniforms.uUvScale, this.uvScale[0], this.uvScale[1]));
854
854
  }
855
855
  /** Read the container's pixel dimensions, with a minimum of 1x1. */
@@ -881,7 +881,54 @@ class $ {
881
881
  t && (this.program && (t.deleteProgram(this.program), this.program = null), this.vao && (t.deleteVertexArray(this.vao), this.vao = null), this.uniforms = null);
882
882
  }
883
883
  }
884
- const B = {
884
+ class At {
885
+ abortController = null;
886
+ initialized = !1;
887
+ initializing = !1;
888
+ element;
889
+ constructor(t) {
890
+ this.element = t;
891
+ }
892
+ // --- Public API (called from lifecycle callbacks) ---
893
+ onConnected() {
894
+ this.element.setupShadowDOM(), this.tryInit();
895
+ }
896
+ onDisconnected() {
897
+ this.cancelInit(), this.element.doDispose(), this.initialized = !1;
898
+ }
899
+ onAttributeChanged(t, e, i) {
900
+ this.element.reinitAttributes.includes(t) && e !== i && (this.initialized ? (this.cancelInit(), this.element.doDispose(), this.initialized = !1, this.element.setupShadowDOM(), this.tryInit()) : this.initializing || this.tryInit());
901
+ }
902
+ get isInitialized() {
903
+ return this.initialized;
904
+ }
905
+ markInitialized() {
906
+ this.initialized = !0, this.initializing = !1;
907
+ }
908
+ // --- Internal ---
909
+ async tryInit() {
910
+ if (this.initializing) return;
911
+ const t = this.element;
912
+ if (!t.isConnected) return;
913
+ for (const i of t.reinitAttributes)
914
+ if (!t.getAttribute(i)) return;
915
+ this.cancelInit();
916
+ const e = new AbortController();
917
+ this.abortController = e, this.initializing = !0;
918
+ try {
919
+ if (await t.doInit(e.signal), e.signal.aborted) {
920
+ this.initializing = !1;
921
+ return;
922
+ }
923
+ } catch {
924
+ this.initializing = !1;
925
+ }
926
+ }
927
+ cancelInit() {
928
+ this.abortController?.abort(), this.abortController = null, this.initializing = !1;
929
+ }
930
+ }
931
+ const H = {
885
932
  parallaxX: 0.4,
886
933
  parallaxY: 1,
887
934
  parallaxMax: 30,
@@ -890,7 +937,7 @@ const B = {
890
937
  loop: !0,
891
938
  muted: !0
892
939
  };
893
- let Yt = class yt {
940
+ let qt = class St {
894
941
  constructor(t, e = 0.08, i = 0.06) {
895
942
  this.host = t, this.lerpFactor = e, this.motionLerpFactor = i, this.host.addEventListener("mousemove", this.handleMouseMove), this.host.addEventListener("mouseleave", this.resetPointerTarget), this.host.addEventListener("touchstart", this.handleTouchStart, { passive: !0 }), this.host.addEventListener("touchmove", this.handleTouchMove, { passive: !0 }), this.host.addEventListener("touchend", this.handleTouchEnd, { passive: !0 }), this.host.addEventListener("touchcancel", this.handleTouchEnd, { passive: !0 });
896
943
  }
@@ -915,8 +962,8 @@ let Yt = class yt {
915
962
  this.host.removeEventListener("mousemove", this.handleMouseMove), this.host.removeEventListener("mouseleave", this.resetPointerTarget), this.host.removeEventListener("touchstart", this.handleTouchStart), this.host.removeEventListener("touchmove", this.handleTouchMove), this.host.removeEventListener("touchend", this.handleTouchEnd), this.host.removeEventListener("touchcancel", this.handleTouchEnd), this.motionListenerAttached && (window.removeEventListener("deviceorientation", this.handleDeviceOrientation), this.motionListenerAttached = !1);
916
963
  }
917
964
  handleMouseMove = (t) => {
918
- const e = this.host.getBoundingClientRect(), i = (t.clientX - e.left) / e.width * 2 - 1, r = (t.clientY - e.top) / e.height * 2 - 1;
919
- this.pointerTarget.x = z(i, -1, 1), this.pointerTarget.y = z(r, -1, 1);
965
+ const e = this.host.getBoundingClientRect(), i = (t.clientX - e.left) / e.width * 2 - 1, o = (t.clientY - e.top) / e.height * 2 - 1;
966
+ this.pointerTarget.x = z(i, -1, 1), this.pointerTarget.y = z(o, -1, 1);
920
967
  };
921
968
  resetPointerTarget = () => {
922
969
  this.pointerTarget.x = 0, this.pointerTarget.y = 0;
@@ -928,8 +975,8 @@ let Yt = class yt {
928
975
  handleTouchMove = (t) => {
929
976
  const e = t.touches[0];
930
977
  if (!e) return;
931
- const i = e.clientX - this.touchAnchorX, r = e.clientY - this.touchAnchorY, o = yt.TOUCH_DRAG_RANGE;
932
- this.pointerTarget.x = z(i / o, -1, 1), this.pointerTarget.y = z(r / o, -1, 1);
978
+ const i = e.clientX - this.touchAnchorX, o = e.clientY - this.touchAnchorY, n = St.TOUCH_DRAG_RANGE;
979
+ this.pointerTarget.x = z(i / n, -1, 1), this.pointerTarget.y = z(o / n, -1, 1);
933
980
  };
934
981
  handleTouchEnd = () => {
935
982
  this.touchActive = !1, this.pointerTarget.x = 0, this.pointerTarget.y = 0;
@@ -967,24 +1014,24 @@ class ht extends HTMLElement {
967
1014
  "muted"
968
1015
  ];
969
1016
  }
1017
+ reinitAttributes = ["src", "depth-src", "depth-meta"];
970
1018
  shadow;
971
1019
  container = null;
972
1020
  renderer = null;
973
1021
  inputHandler = null;
974
1022
  depthWorker = null;
975
1023
  video = null;
976
- initialized = !1;
977
- abortController = null;
978
1024
  loopCount = 0;
1025
+ lifecycle;
979
1026
  constructor() {
980
- super(), this.shadow = this.attachShadow({ mode: "open" });
1027
+ super(), this.shadow = this.attachShadow({ mode: "open" }), this.lifecycle = new At(this);
981
1028
  }
982
1029
  // --- Attribute helpers ---
983
1030
  getAttrFloat(t, e) {
984
1031
  const i = this.getAttribute(t);
985
1032
  if (i === null) return e;
986
- const r = parseFloat(i);
987
- return Number.isFinite(r) ? r : e;
1033
+ const o = parseFloat(i);
1034
+ return Number.isFinite(o) ? o : e;
988
1035
  }
989
1036
  getAttrBool(t, e) {
990
1037
  if (!this.hasAttribute(t)) return e;
@@ -992,25 +1039,25 @@ class ht extends HTMLElement {
992
1039
  return !(i === "false" || i === "0");
993
1040
  }
994
1041
  get parallaxX() {
995
- return this.getAttrFloat("parallax-x", B.parallaxX);
1042
+ return this.getAttrFloat("parallax-x", H.parallaxX);
996
1043
  }
997
1044
  get parallaxY() {
998
- return this.getAttrFloat("parallax-y", B.parallaxY);
1045
+ return this.getAttrFloat("parallax-y", H.parallaxY);
999
1046
  }
1000
1047
  get parallaxMax() {
1001
- return this.getAttrFloat("parallax-max", B.parallaxMax);
1048
+ return this.getAttrFloat("parallax-max", H.parallaxMax);
1002
1049
  }
1003
1050
  get overscan() {
1004
- return this.getAttrFloat("overscan", B.overscan);
1051
+ return this.getAttrFloat("overscan", H.overscan);
1005
1052
  }
1006
1053
  get shouldAutoplay() {
1007
- return this.getAttrBool("autoplay", B.autoplay);
1054
+ return this.getAttrBool("autoplay", H.autoplay);
1008
1055
  }
1009
1056
  get shouldLoop() {
1010
- return this.getAttrBool("loop", B.loop);
1057
+ return this.getAttrBool("loop", H.loop);
1011
1058
  }
1012
1059
  get shouldMute() {
1013
- return this.getAttrBool("muted", B.muted);
1060
+ return this.getAttrBool("muted", H.muted);
1014
1061
  }
1015
1062
  // --- Event dispatching ---
1016
1063
  /**
@@ -1048,13 +1095,13 @@ class ht extends HTMLElement {
1048
1095
  }
1049
1096
  // --- Lifecycle ---
1050
1097
  connectedCallback() {
1051
- this.setupShadowDOM(), this.init();
1098
+ this.lifecycle.onConnected();
1052
1099
  }
1053
1100
  disconnectedCallback() {
1054
- this.dispose();
1101
+ this.lifecycle.onDisconnected();
1055
1102
  }
1056
1103
  attributeChangedCallback(t, e, i) {
1057
- ["src", "depth-src", "depth-meta"].includes(t) && (this.initialized ? (this.dispose(), this.setupShadowDOM(), this.init()) : this.isConnected && this.getAttribute("src") && this.getAttribute("depth-src") && this.getAttribute("depth-meta") && this.init());
1104
+ this.lifecycle.onAttributeChanged(t, e, i);
1058
1105
  }
1059
1106
  // --- Shadow DOM setup ---
1060
1107
  setupShadowDOM() {
@@ -1083,70 +1130,65 @@ class ht extends HTMLElement {
1083
1130
  `, this.shadow.appendChild(t), this.container = document.createElement("div"), this.container.className = "container", this.shadow.appendChild(this.container);
1084
1131
  }
1085
1132
  // --- Initialization ---
1086
- async init() {
1087
- const t = this.getAttribute("src"), e = this.getAttribute("depth-src"), i = this.getAttribute("depth-meta");
1088
- if (!t || !e || !i) {
1089
- const r = "src, depth-src, and depth-meta attributes are required.";
1090
- console.warn(`<layershift-parallax>: ${r}`), this.emit("layershift-parallax:error", { message: r });
1091
- return;
1092
- }
1093
- if (this.container) {
1094
- this.abortController = new AbortController();
1133
+ async doInit(t) {
1134
+ const e = this.getAttribute("src"), i = this.getAttribute("depth-src"), o = this.getAttribute("depth-meta");
1135
+ if (this.container)
1095
1136
  try {
1096
- const [r, o] = await Promise.all([
1097
- this.createVideoElement(t),
1098
- At(e, i)
1137
+ const [n, s] = await Promise.all([
1138
+ this.createVideoElement(e),
1139
+ yt(i, o)
1099
1140
  ]);
1100
- if (this.abortController.signal.aborted) {
1101
- r.remove();
1141
+ if (t.aborted) {
1142
+ n.remove();
1102
1143
  return;
1103
1144
  }
1104
- this.video = r, this.loopCount = 0, this.attachVideoEventListeners(r);
1105
- const s = Ht(
1106
- o.frames,
1107
- o.meta.width,
1108
- o.meta.height
1109
- ), a = Bt(s), h = this.hasAttribute("parallax-max") ? this.parallaxMax / Math.max(r.videoWidth, 1) : a.parallaxStrength, l = this.hasAttribute("overscan") ? this.overscan : a.overscanPadding;
1110
- let u;
1145
+ this.video = n, this.loopCount = 0, this.attachVideoEventListeners(n);
1146
+ const h = Ht(
1147
+ s.frames,
1148
+ s.meta.width,
1149
+ s.meta.height
1150
+ ), a = Xt(h), l = this.hasAttribute("parallax-max") ? this.parallaxMax / Math.max(n.videoWidth, 1) : a.parallaxStrength, u = this.hasAttribute("overscan") ? this.overscan : a.overscanPadding;
1151
+ let f;
1111
1152
  try {
1112
1153
  const d = await st.create(
1113
- o,
1114
- o.meta.width,
1115
- o.meta.height
1154
+ s,
1155
+ s.meta.width,
1156
+ s.meta.height
1116
1157
  );
1117
- this.depthWorker = d, u = (m) => d.sample(m);
1158
+ this.depthWorker = d, f = (m) => d.sample(m);
1118
1159
  } catch {
1119
1160
  const d = new bt(
1120
- o,
1121
- o.meta.width,
1122
- o.meta.height
1161
+ s,
1162
+ s.meta.width,
1163
+ s.meta.height
1123
1164
  );
1124
- u = (m) => d.sample(m);
1165
+ f = (m) => d.sample(m);
1125
1166
  }
1126
- if (this.abortController.signal.aborted) {
1127
- r.remove(), this.depthWorker?.dispose(), this.depthWorker = null;
1167
+ if (t.aborted) {
1168
+ n.remove(), this.depthWorker?.dispose(), this.depthWorker = null;
1128
1169
  return;
1129
1170
  }
1130
1171
  this.renderer = new $(this.container, {
1131
- parallaxStrength: h,
1172
+ parallaxStrength: l,
1132
1173
  pomEnabled: !0,
1133
1174
  pomSteps: a.pomSteps,
1134
- overscanPadding: l,
1175
+ overscanPadding: u,
1135
1176
  contrastLow: a.contrastLow,
1136
1177
  contrastHigh: a.contrastHigh,
1137
1178
  verticalReduction: a.verticalReduction,
1138
1179
  dofStart: a.dofStart,
1139
1180
  dofStrength: a.dofStrength
1140
- }), this.renderer.initialize(r, o.meta.width, o.meta.height), this.inputHandler = new Yt(this);
1141
- const f = this.parallaxX, c = this.parallaxY;
1181
+ }), this.renderer.initialize(n, s.meta.width, s.meta.height), this.inputHandler = new qt(this);
1182
+ const c = this.parallaxX, g = this.parallaxY;
1142
1183
  if (this.renderer.start(
1143
- r,
1144
- u,
1184
+ n,
1185
+ f,
1145
1186
  () => {
1187
+ if (!this.inputHandler) return { x: 0, y: 0 };
1146
1188
  const d = this.inputHandler.update();
1147
1189
  return {
1148
- x: d.x * f,
1149
- y: d.y * c
1190
+ x: d.x * c,
1191
+ y: d.y * g
1150
1192
  };
1151
1193
  },
1152
1194
  // RVFC callback: dispatch 'frame' event on each new video frame
@@ -1157,55 +1199,55 @@ class ht extends HTMLElement {
1157
1199
  });
1158
1200
  }
1159
1201
  ), this.shouldAutoplay) {
1160
- r.currentTime = 0;
1202
+ n.currentTime = 0;
1161
1203
  try {
1162
- await r.play();
1204
+ await n.play();
1163
1205
  } catch {
1164
1206
  }
1165
1207
  }
1166
- this.initialized = !0, this.emit("layershift-parallax:ready", {
1167
- videoWidth: r.videoWidth,
1168
- videoHeight: r.videoHeight,
1169
- duration: r.duration,
1170
- depthProfile: s,
1208
+ if (t.aborted) return;
1209
+ this.lifecycle.markInitialized(), this.emit("layershift-parallax:ready", {
1210
+ videoWidth: n.videoWidth,
1211
+ videoHeight: n.videoHeight,
1212
+ duration: n.duration,
1213
+ depthProfile: h,
1171
1214
  derivedParams: a
1172
1215
  });
1173
- } catch (r) {
1174
- const o = r instanceof Error ? r.message : "Failed to initialize.";
1175
- console.error("<layershift-parallax>: Failed to initialize.", r), this.emit("layershift-parallax:error", { message: o });
1216
+ } catch (n) {
1217
+ const s = n instanceof Error ? n.message : "Failed to initialize.";
1218
+ console.error("<layershift-parallax>: Failed to initialize.", n), this.emit("layershift-parallax:error", { message: s });
1176
1219
  }
1177
- }
1178
1220
  }
1179
1221
  // --- Video element ---
1180
1222
  async createVideoElement(t) {
1181
1223
  const e = document.createElement("video");
1182
- return e.crossOrigin = "anonymous", e.setAttribute("crossorigin", "anonymous"), e.playsInline = !0, e.setAttribute("playsinline", ""), e.setAttribute("webkit-playsinline", "true"), e.muted = this.shouldMute, e.defaultMuted = this.shouldMute, this.shouldMute && e.setAttribute("muted", ""), e.loop = this.shouldLoop, e.preload = "auto", e.style.display = "none", e.src = t, this.shadow.appendChild(e), await new Promise((i, r) => {
1224
+ return e.crossOrigin = "anonymous", e.setAttribute("crossorigin", "anonymous"), e.playsInline = !0, e.setAttribute("playsinline", ""), e.setAttribute("webkit-playsinline", "true"), e.muted = this.shouldMute, e.defaultMuted = this.shouldMute, this.shouldMute && e.setAttribute("muted", ""), e.loop = this.shouldLoop, e.preload = "auto", e.style.display = "none", e.src = t, this.shadow.appendChild(e), await new Promise((i, o) => {
1183
1225
  if (e.readyState >= HTMLMediaElement.HAVE_METADATA) {
1184
1226
  i();
1185
1227
  return;
1186
1228
  }
1187
- const o = () => {
1188
- a(), i();
1229
+ const n = () => {
1230
+ h(), i();
1189
1231
  }, s = () => {
1190
- a(), r(new Error("Failed to load video metadata."));
1191
- }, a = () => {
1192
- e.removeEventListener("loadedmetadata", o), e.removeEventListener("error", s);
1232
+ h(), o(new Error("Failed to load video metadata."));
1233
+ }, h = () => {
1234
+ e.removeEventListener("loadedmetadata", n), e.removeEventListener("error", s);
1193
1235
  };
1194
- e.addEventListener("loadedmetadata", o), e.addEventListener("error", s), e.load();
1236
+ e.addEventListener("loadedmetadata", n), e.addEventListener("error", s), e.load();
1195
1237
  }), e;
1196
1238
  }
1197
1239
  // --- Cleanup ---
1198
- dispose() {
1199
- this.abortController?.abort(), this.abortController = null, this.renderer?.dispose(), this.renderer = null, this.inputHandler?.dispose(), this.inputHandler = null, this.depthWorker?.dispose(), this.depthWorker = null, this.video && (this.video.pause(), this.video.removeAttribute("src"), this.video.load(), this.video.remove(), this.video = null), this.initialized = !1, this.loopCount = 0, this.container = null;
1240
+ doDispose() {
1241
+ this.renderer?.dispose(), this.renderer = null, this.inputHandler?.dispose(), this.inputHandler = null, this.depthWorker?.dispose(), this.depthWorker = null, this.video && (this.video.pause(), this.video.removeAttribute("src"), this.video.load(), this.video.remove(), this.video = null), this.loopCount = 0, this.container = null;
1200
1242
  }
1201
1243
  }
1202
- function z(n, t, e) {
1203
- return Math.min(e, Math.max(t, n));
1244
+ function z(r, t, e) {
1245
+ return Math.min(e, Math.max(t, r));
1204
1246
  }
1205
- function it(n, t, e) {
1206
- return n + (t - n) * e;
1247
+ function it(r, t, e) {
1248
+ return r + (t - r) * e;
1207
1249
  }
1208
- const qt = (
1250
+ const Zt = (
1209
1251
  /* glsl */
1210
1252
  `#version 300 es
1211
1253
  in vec2 aPosition;
@@ -1214,14 +1256,14 @@ const qt = (
1214
1256
  gl_Position = vec4(aPosition * uMeshScale, 0.0, 1.0);
1215
1257
  }
1216
1258
  `
1217
- ), Zt = (
1259
+ ), $t = (
1218
1260
  /* glsl */
1219
1261
  `#version 300 es
1220
1262
  precision lowp float;
1221
1263
  out vec4 fragColor;
1222
1264
  void main() { fragColor = vec4(0.0); }
1223
1265
  `
1224
- ), $t = (
1266
+ ), Jt = (
1225
1267
  /* glsl */
1226
1268
  `#version 300 es
1227
1269
  in vec2 aPosition;
@@ -1230,14 +1272,14 @@ const qt = (
1230
1272
  gl_Position = vec4(aPosition * uMeshScale, 0.0, 1.0);
1231
1273
  }
1232
1274
  `
1233
- ), Jt = (
1275
+ ), Kt = (
1234
1276
  /* glsl */
1235
1277
  `#version 300 es
1236
1278
  precision lowp float;
1237
1279
  out vec4 fragColor;
1238
1280
  void main() { fragColor = vec4(1.0); }
1239
1281
  `
1240
- ), Kt = (
1282
+ ), Qt = (
1241
1283
  /* glsl */
1242
1284
  `#version 300 es
1243
1285
  in vec2 aPosition;
@@ -1247,7 +1289,7 @@ const qt = (
1247
1289
  gl_Position = vec4(aPosition, 0.0, 1.0);
1248
1290
  }
1249
1291
  `
1250
- ), Qt = (
1292
+ ), te = (
1251
1293
  /* glsl */
1252
1294
  `#version 300 es
1253
1295
  precision highp float;
@@ -1275,7 +1317,7 @@ const qt = (
1275
1317
  }
1276
1318
  }
1277
1319
  `
1278
- ), te = (
1320
+ ), ee = (
1279
1321
  /* glsl */
1280
1322
  `#version 300 es
1281
1323
  in vec2 aPosition;
@@ -1285,7 +1327,7 @@ const qt = (
1285
1327
  gl_Position = vec4(aPosition, 0.0, 1.0);
1286
1328
  }
1287
1329
  `
1288
- ), ee = (
1330
+ ), ie = (
1289
1331
  /* glsl */
1290
1332
  `#version 300 es
1291
1333
  precision highp float;
@@ -1317,7 +1359,7 @@ const qt = (
1317
1359
  fragSeed = bestSeed;
1318
1360
  }
1319
1361
  `
1320
- ), ie = (
1362
+ ), re = (
1321
1363
  /* glsl */
1322
1364
  `#version 300 es
1323
1365
  in vec2 aPosition;
@@ -1327,7 +1369,7 @@ const qt = (
1327
1369
  gl_Position = vec4(aPosition, 0.0, 1.0);
1328
1370
  }
1329
1371
  `
1330
- ), re = (
1372
+ ), oe = (
1331
1373
  /* glsl */
1332
1374
  `#version 300 es
1333
1375
  precision highp float;
@@ -1355,7 +1397,7 @@ const qt = (
1355
1397
  fragDist = vec4(normalized, 0.0, 0.0, 1.0);
1356
1398
  }
1357
1399
  `
1358
- ), oe = (
1400
+ ), ne = (
1359
1401
  /* glsl */
1360
1402
  `#version 300 es
1361
1403
  in vec2 aPosition;
@@ -1370,7 +1412,7 @@ const qt = (
1370
1412
  gl_Position = vec4(aPosition, 0.0, 1.0);
1371
1413
  }
1372
1414
  `
1373
- ), ne = (
1415
+ ), se = (
1374
1416
  /* glsl */
1375
1417
  `#version 300 es
1376
1418
  precision highp float;
@@ -1504,7 +1546,7 @@ const qt = (
1504
1546
  fragDepth = vec4(lensD, 0.0, 0.0, 1.0);
1505
1547
  }
1506
1548
  `
1507
- ), se = (
1549
+ ), ae = (
1508
1550
  /* glsl */
1509
1551
  `#version 300 es
1510
1552
  in vec2 aPosition;
@@ -1514,7 +1556,7 @@ const qt = (
1514
1556
  gl_Position = vec4(aPosition, 0.0, 1.0);
1515
1557
  }
1516
1558
  `
1517
- ), ae = (
1559
+ ), he = (
1518
1560
  /* glsl */
1519
1561
  `#version 300 es
1520
1562
  precision highp float;
@@ -1547,7 +1589,7 @@ const qt = (
1547
1589
  fragColor = vec4(toSRGB(linear), color.a);
1548
1590
  }
1549
1591
  `
1550
- ), he = (
1592
+ ), le = (
1551
1593
  /* glsl */
1552
1594
  `#version 300 es
1553
1595
  in vec2 aPosition;
@@ -1573,7 +1615,7 @@ const qt = (
1573
1615
  gl_Position = vec4(pos, 0.0, 1.0);
1574
1616
  }
1575
1617
  `
1576
- ), le = (
1618
+ ), ce = (
1577
1619
  /* glsl */
1578
1620
  `#version 300 es
1579
1621
  precision highp float;
@@ -1678,7 +1720,7 @@ const qt = (
1678
1720
  fragColor = vec4(color * alpha, alpha);
1679
1721
  }
1680
1722
  `
1681
- ), ce = (
1723
+ ), ue = (
1682
1724
  /* glsl */
1683
1725
  `#version 300 es
1684
1726
  in vec2 aPosition;
@@ -1697,7 +1739,7 @@ const qt = (
1697
1739
  gl_Position = vec4(sp, 0.0, 1.0);
1698
1740
  }
1699
1741
  `
1700
- ), ue = (
1742
+ ), fe = (
1701
1743
  /* glsl */
1702
1744
  `#version 300 es
1703
1745
  precision highp float;
@@ -1768,56 +1810,56 @@ const qt = (
1768
1810
  }
1769
1811
  `
1770
1812
  );
1771
- function L(n, t, e) {
1772
- const i = n.createShader(t);
1813
+ function L(r, t, e) {
1814
+ const i = r.createShader(t);
1773
1815
  if (!i) throw new Error("Failed to create shader.");
1774
- if (n.shaderSource(i, e), n.compileShader(i), !n.getShaderParameter(i, n.COMPILE_STATUS)) {
1775
- const r = n.getShaderInfoLog(i) ?? "";
1776
- throw n.deleteShader(i), new Error(`Shader compilation failed:
1777
- ${r}`);
1816
+ if (r.shaderSource(i, e), r.compileShader(i), !r.getShaderParameter(i, r.COMPILE_STATUS)) {
1817
+ const o = r.getShaderInfoLog(i) ?? "";
1818
+ throw r.deleteShader(i), new Error(`Shader compilation failed:
1819
+ ${o}`);
1778
1820
  }
1779
1821
  return i;
1780
1822
  }
1781
- function V(n, t, e) {
1782
- const i = n.createProgram();
1823
+ function V(r, t, e) {
1824
+ const i = r.createProgram();
1783
1825
  if (!i) throw new Error("Failed to create program.");
1784
- if (n.attachShader(i, t), n.attachShader(i, e), n.linkProgram(i), !n.getProgramParameter(i, n.LINK_STATUS)) {
1785
- const r = n.getProgramInfoLog(i) ?? "";
1786
- throw n.deleteProgram(i), new Error(`Program linking failed:
1787
- ${r}`);
1826
+ if (r.attachShader(i, t), r.attachShader(i, e), r.linkProgram(i), !r.getProgramParameter(i, r.LINK_STATUS)) {
1827
+ const o = r.getProgramInfoLog(i) ?? "";
1828
+ throw r.deleteProgram(i), new Error(`Program linking failed:
1829
+ ${o}`);
1788
1830
  }
1789
- return n.detachShader(i, t), n.detachShader(i, e), n.deleteShader(t), n.deleteShader(e), i;
1831
+ return r.detachShader(i, t), r.detachShader(i, e), r.deleteShader(t), r.deleteShader(e), i;
1790
1832
  }
1791
- function fe(n) {
1833
+ function de(r) {
1792
1834
  const t = [];
1793
1835
  let e = 0;
1794
- for (let i = 0; i < n.length - 2; i += 2) {
1795
- const r = n[i], o = n[i + 1], s = n[i + 2], a = n[i + 3], h = s - r, l = a - o, u = Math.sqrt(h * h + l * l);
1836
+ for (let i = 0; i < r.length - 2; i += 2) {
1837
+ const o = r[i], n = r[i + 1], s = r[i + 2], h = r[i + 3], a = s - o, l = h - n, u = Math.sqrt(a * a + l * l);
1796
1838
  if (u < 1e-6) continue;
1797
- const f = -l / u, c = h / u;
1839
+ const f = -l / u, c = a / u;
1798
1840
  t.push(
1799
- r,
1800
1841
  o,
1842
+ n,
1801
1843
  f,
1802
1844
  c,
1803
- r,
1804
1845
  o,
1846
+ n,
1805
1847
  -f,
1806
1848
  -c,
1807
1849
  s,
1808
- a,
1850
+ h,
1809
1851
  f,
1810
1852
  c,
1811
1853
  s,
1812
- a,
1854
+ h,
1813
1855
  f,
1814
1856
  c,
1815
- r,
1816
1857
  o,
1858
+ n,
1817
1859
  -f,
1818
1860
  -c,
1819
1861
  s,
1820
- a,
1862
+ h,
1821
1863
  -f,
1822
1864
  -c
1823
1865
  ), e += 6;
@@ -1827,39 +1869,39 @@ function fe(n) {
1827
1869
  count: e
1828
1870
  };
1829
1871
  }
1830
- function de(n, t, e, i, r) {
1872
+ function me(r, t, e, i, o) {
1831
1873
  if (i <= 0)
1832
1874
  return { vertices: new Float32Array(0), count: 0 };
1833
- const o = r * Math.PI / 180, s = -Math.cos(o), a = Math.sin(o), h = [];
1875
+ const n = o * Math.PI / 180, s = -Math.cos(n), h = Math.sin(n), a = [];
1834
1876
  let l = 0;
1835
1877
  for (let u = 0; u < t.length; u++) {
1836
- const f = t[u], m = ((u + 1 < t.length ? t[u + 1] : n.length) - f) / 2;
1837
- if (m < 3) continue;
1838
- const g = m - 1;
1878
+ const f = t[u], d = ((u + 1 < t.length ? t[u + 1] : r.length) - f) / 2;
1879
+ if (d < 3) continue;
1880
+ const m = d - 1;
1839
1881
  let U = 0;
1840
- for (let x = 0; x < g; x++) {
1841
- const y = f + x * 2, S = n[y], F = n[y + 1], P = n[y + 2], _ = n[y + 3];
1842
- U += S * _ - P * F;
1882
+ for (let x = 0; x < m; x++) {
1883
+ const A = f + x * 2, S = r[A], D = r[A + 1], P = r[A + 2], _ = r[A + 3];
1884
+ U += S * _ - P * D;
1843
1885
  }
1844
1886
  const b = U >= 0 ? 1 : -1, E = [], p = [];
1845
- for (let x = 0; x < g; x++) {
1846
- const y = f + x * 2, S = n[y + 2] - n[y], F = n[y + 3] - n[y + 1], P = Math.sqrt(S * S + F * F);
1847
- P < 1e-8 ? (E.push(x > 0 ? E[x - 1] : 0), p.push(x > 0 ? p[x - 1] : 0)) : (E.push(-F / P * b), p.push(S / P * b));
1887
+ for (let x = 0; x < m; x++) {
1888
+ const A = f + x * 2, S = r[A + 2] - r[A], D = r[A + 3] - r[A + 1], P = Math.sqrt(S * S + D * D);
1889
+ P < 1e-8 ? (E.push(x > 0 ? E[x - 1] : 0), p.push(x > 0 ? p[x - 1] : 0)) : (E.push(-D / P * b), p.push(S / P * b));
1848
1890
  }
1849
1891
  const v = [], T = [];
1850
- for (let x = 0; x < g; x++) {
1851
- const y = (x - 1 + g) % g;
1852
- let S = E[y] + E[x], F = p[y] + p[x];
1853
- const P = Math.sqrt(S * S + F * F);
1854
- P > 1e-8 ? (S /= P, F /= P) : (S = E[x], F = p[x]), v.push(S), T.push(F);
1892
+ for (let x = 0; x < m; x++) {
1893
+ const A = (x - 1 + m) % m;
1894
+ let S = E[A] + E[x], D = p[A] + p[x];
1895
+ const P = Math.sqrt(S * S + D * D);
1896
+ P > 1e-8 ? (S /= P, D /= P) : (S = E[x], D = p[x]), v.push(S), T.push(D);
1855
1897
  }
1856
- for (let x = 0; x < g; x++) {
1857
- const y = x, S = (x + 1) % g, F = f + x * 2, P = f + (x + 1) % g * 2, _ = n[F], k = n[F + 1], D = n[P], R = n[P + 1], C = v[y] * a, M = T[y] * a, H = s, I = v[S] * a, N = T[S] * a, j = s, et = _ + v[y] * i, mt = k + T[y] * i, wt = D + v[S] * i, Lt = R + T[S] * i;
1858
- h.push(_, k, C, M, H, 0), h.push(et, mt, C, M, H, 1), h.push(D, R, I, N, j, 0), h.push(D, R, I, N, j, 0), h.push(et, mt, C, M, H, 1), h.push(wt, Lt, I, N, j, 1), l += 6;
1898
+ for (let x = 0; x < m; x++) {
1899
+ const A = x, S = (x + 1) % m, D = f + x * 2, P = f + (x + 1) % m * 2, _ = r[D], k = r[D + 1], F = r[P], R = r[P + 1], C = v[A] * h, M = T[A] * h, B = s, I = v[S] * h, N = T[S] * h, j = s, et = _ + v[A] * i, mt = k + T[A] * i, Lt = F + v[S] * i, Ct = R + T[S] * i;
1900
+ a.push(_, k, C, M, B, 0), a.push(et, mt, C, M, B, 1), a.push(F, R, I, N, j, 0), a.push(F, R, I, N, j, 0), a.push(et, mt, C, M, B, 1), a.push(Lt, Ct, I, N, j, 1), l += 6;
1859
1901
  }
1860
1902
  }
1861
1903
  return {
1862
- vertices: new Float32Array(h),
1904
+ vertices: new Float32Array(a),
1863
1905
  count: l
1864
1906
  };
1865
1907
  }
@@ -1918,6 +1960,7 @@ class ft {
1918
1960
  jfaWidth = 0;
1919
1961
  jfaHeight = 0;
1920
1962
  distFieldDirty = !0;
1963
+ hasColorBufferFloat = !1;
1921
1964
  // Dimensions
1922
1965
  depthWidth = 0;
1923
1966
  depthHeight = 0;
@@ -1948,8 +1991,8 @@ class ft {
1948
1991
  this.container = t, this.config = { ...e };
1949
1992
  const i = this.config.bevelLightAngle * Math.PI / 180;
1950
1993
  this.lightDirX = Math.cos(i), this.lightDirY = Math.sin(i);
1951
- const r = this.config.lightDirection, o = Math.sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]);
1952
- o > 1e-6 && (this.lightDir3 = [r[0] / o, r[1] / o, r[2] / o]), this.canvas = document.createElement("canvas");
1994
+ const o = this.config.lightDirection, n = Math.sqrt(o[0] * o[0] + o[1] * o[1] + o[2] * o[2]);
1995
+ n > 1e-6 && (this.lightDir3 = [o[0] / n, o[1] / n, o[2] / n]), this.canvas = document.createElement("canvas");
1953
1996
  const s = this.canvas.getContext("webgl2", {
1954
1997
  antialias: !0,
1955
1998
  alpha: !0,
@@ -1959,11 +2002,11 @@ class ft {
1959
2002
  powerPreference: "high-performance"
1960
2003
  });
1961
2004
  if (!s) throw new Error("WebGL 2 is not supported.");
1962
- this.gl = s, "drawingBufferColorSpace" in s && (s.drawingBufferColorSpace = "srgb"), s.clearColor(0, 0, 0, 0), s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL, !0), this.container.appendChild(this.canvas), this.initGPUResources(), this.setupResizeHandling(), this.canvas.addEventListener("webglcontextlost", this.handleContextLost), this.canvas.addEventListener("webglcontextrestored", this.handleContextRestored);
2005
+ this.gl = s, "drawingBufferColorSpace" in s && (s.drawingBufferColorSpace = "srgb"), this.hasColorBufferFloat = !!s.getExtension("EXT_color_buffer_float"), s.clearColor(0, 0, 0, 0), s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL, !0), this.container.appendChild(this.canvas), this.initGPUResources(), this.setupResizeHandling(), this.canvas.addEventListener("webglcontextlost", this.handleContextLost), this.canvas.addEventListener("webglcontextrestored", this.handleContextRestored);
1963
2006
  }
1964
- initialize(t, e, i, r) {
1965
- const o = this.gl;
1966
- o && (this.disposeTextures(), this.disposeFBO(), this.disposeJFA(), this.disposeStencilGeometry(), this.disposeBoundaryGeometry(), this.disposeChamferGeometry(), this.videoAspect = t.videoWidth / t.videoHeight, this.meshAspect = r.aspect, this.depthWidth = e, this.depthHeight = i, this.videoTexture = o.createTexture(), o.activeTexture(o.TEXTURE0), o.bindTexture(o.TEXTURE_2D, this.videoTexture), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), this.depthTexture = o.createTexture(), o.activeTexture(o.TEXTURE1), o.bindTexture(o.TEXTURE_2D, this.depthTexture), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), o.texStorage2D(o.TEXTURE_2D, 1, o.R8, e, i), this.uploadStencilMesh(r), this.uploadMaskMesh(r), this.uploadBoundaryMesh(r), this.uploadChamferMesh(r), this.interiorProgram && (o.useProgram(this.interiorProgram), o.uniform1i(this.interiorUniforms.uImage, 0), o.uniform1i(this.interiorUniforms.uDepth, 1), o.uniform1f(this.interiorUniforms.uStrength, this.config.parallaxStrength), o.uniform1i(this.interiorUniforms.uPomSteps, this.config.pomSteps), o.uniform1f(this.interiorUniforms.uDepthPower, this.config.depthPower), o.uniform1f(this.interiorUniforms.uDepthScale, this.config.depthScale), o.uniform1f(this.interiorUniforms.uDepthBias, this.config.depthBias), o.uniform1f(this.interiorUniforms.uContrastLow, this.config.contrastLow), o.uniform1f(this.interiorUniforms.uContrastHigh, this.config.contrastHigh), o.uniform1f(this.interiorUniforms.uVerticalReduction, this.config.verticalReduction), o.uniform1f(this.interiorUniforms.uDofStart, this.config.dofStart), o.uniform1f(this.interiorUniforms.uDofStrength, this.config.dofStrength), o.uniform2f(this.interiorUniforms.uImageTexelSize, 1 / t.videoWidth, 1 / t.videoHeight), o.uniform1f(this.interiorUniforms.uFogDensity, this.config.fogDensity), o.uniform3f(this.interiorUniforms.uFogColor, ...this.config.fogColor), o.uniform1f(this.interiorUniforms.uColorShift, this.config.colorShift), o.uniform1f(this.interiorUniforms.uBrightnessBias, this.config.brightnessBias)), this.compositeProgram && (o.useProgram(this.compositeProgram), o.uniform1i(this.compositeUniforms.uInteriorColor, 2), o.uniform1i(this.compositeUniforms.uDistField, 4), o.uniform1f(this.compositeUniforms.uEdgeOcclusionWidth, this.config.edgeOcclusionWidth), o.uniform1f(this.compositeUniforms.uEdgeOcclusionStrength, this.config.edgeOcclusionStrength)), this.chamferProgram && (o.useProgram(this.chamferProgram), o.uniform3f(this.chamferUniforms.uLightDir3, ...this.lightDir3), o.uniform3f(this.chamferUniforms.uChamferColor, ...this.config.chamferColor), o.uniform1f(this.chamferUniforms.uChamferAmbient, this.config.chamferAmbient), o.uniform1f(this.chamferUniforms.uChamferSpecular, this.config.chamferSpecular), o.uniform1f(this.chamferUniforms.uChamferShininess, this.config.chamferShininess), o.uniform1i(this.chamferUniforms.uInteriorColor, 2)), this.boundaryProgram && (o.useProgram(this.boundaryProgram), o.uniform1i(this.boundaryUniforms.uInteriorColor, 2), o.uniform1i(this.boundaryUniforms.uInteriorDepth, 3), o.uniform1i(this.boundaryUniforms.uDistField, 4), o.uniform1f(this.boundaryUniforms.uRimIntensity, this.config.rimLightIntensity), o.uniform3f(this.boundaryUniforms.uRimColor, ...this.config.rimLightColor), o.uniform1f(this.boundaryUniforms.uRefractionStrength, this.config.refractionStrength), o.uniform1f(this.boundaryUniforms.uChromaticStrength, this.config.chromaticStrength), o.uniform1f(this.boundaryUniforms.uOcclusionIntensity, this.config.occlusionIntensity), o.uniform1f(this.boundaryUniforms.uEdgeThickness, this.config.edgeThickness), o.uniform1f(this.boundaryUniforms.uEdgeSpecular, this.config.edgeSpecular), o.uniform3f(this.boundaryUniforms.uEdgeColor, ...this.config.edgeColor), o.uniform2f(this.boundaryUniforms.uLightDir, this.lightDirX, this.lightDirY), o.uniform1f(this.boundaryUniforms.uBevelIntensity, this.config.bevelIntensity)), this.recalculateViewportLayout());
2007
+ initialize(t, e, i, o) {
2008
+ const n = this.gl;
2009
+ n && (this.disposeTextures(), this.disposeFBO(), this.disposeJFA(), this.disposeStencilGeometry(), this.disposeBoundaryGeometry(), this.disposeChamferGeometry(), this.videoAspect = t.videoWidth / t.videoHeight, this.meshAspect = o.aspect, this.depthWidth = e, this.depthHeight = i, this.videoTexture = n.createTexture(), n.activeTexture(n.TEXTURE0), n.bindTexture(n.TEXTURE_2D, this.videoTexture), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE), this.depthTexture = n.createTexture(), n.activeTexture(n.TEXTURE1), n.bindTexture(n.TEXTURE_2D, this.depthTexture), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, n.LINEAR), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE), n.texStorage2D(n.TEXTURE_2D, 1, n.R8, e, i), this.uploadStencilMesh(o), this.uploadMaskMesh(o), this.uploadBoundaryMesh(o), this.uploadChamferMesh(o), this.interiorProgram && (n.useProgram(this.interiorProgram), n.uniform1i(this.interiorUniforms.uImage, 0), n.uniform1i(this.interiorUniforms.uDepth, 1), n.uniform1f(this.interiorUniforms.uStrength, this.config.parallaxStrength), n.uniform1i(this.interiorUniforms.uPomSteps, this.config.pomSteps), n.uniform1f(this.interiorUniforms.uDepthPower, this.config.depthPower), n.uniform1f(this.interiorUniforms.uDepthScale, this.config.depthScale), n.uniform1f(this.interiorUniforms.uDepthBias, this.config.depthBias), n.uniform1f(this.interiorUniforms.uContrastLow, this.config.contrastLow), n.uniform1f(this.interiorUniforms.uContrastHigh, this.config.contrastHigh), n.uniform1f(this.interiorUniforms.uVerticalReduction, this.config.verticalReduction), n.uniform1f(this.interiorUniforms.uDofStart, this.config.dofStart), n.uniform1f(this.interiorUniforms.uDofStrength, this.config.dofStrength), n.uniform2f(this.interiorUniforms.uImageTexelSize, 1 / t.videoWidth, 1 / t.videoHeight), n.uniform1f(this.interiorUniforms.uFogDensity, this.config.fogDensity), n.uniform3f(this.interiorUniforms.uFogColor, ...this.config.fogColor), n.uniform1f(this.interiorUniforms.uColorShift, this.config.colorShift), n.uniform1f(this.interiorUniforms.uBrightnessBias, this.config.brightnessBias)), this.compositeProgram && (n.useProgram(this.compositeProgram), n.uniform1i(this.compositeUniforms.uInteriorColor, 2), n.uniform1i(this.compositeUniforms.uDistField, 4), n.uniform1f(this.compositeUniforms.uEdgeOcclusionWidth, this.config.edgeOcclusionWidth), n.uniform1f(this.compositeUniforms.uEdgeOcclusionStrength, this.config.edgeOcclusionStrength)), this.chamferProgram && (n.useProgram(this.chamferProgram), n.uniform3f(this.chamferUniforms.uLightDir3, ...this.lightDir3), n.uniform3f(this.chamferUniforms.uChamferColor, ...this.config.chamferColor), n.uniform1f(this.chamferUniforms.uChamferAmbient, this.config.chamferAmbient), n.uniform1f(this.chamferUniforms.uChamferSpecular, this.config.chamferSpecular), n.uniform1f(this.chamferUniforms.uChamferShininess, this.config.chamferShininess), n.uniform1i(this.chamferUniforms.uInteriorColor, 2)), this.boundaryProgram && (n.useProgram(this.boundaryProgram), n.uniform1i(this.boundaryUniforms.uInteriorColor, 2), n.uniform1i(this.boundaryUniforms.uInteriorDepth, 3), n.uniform1i(this.boundaryUniforms.uDistField, 4), n.uniform1f(this.boundaryUniforms.uRimIntensity, this.config.rimLightIntensity), n.uniform3f(this.boundaryUniforms.uRimColor, ...this.config.rimLightColor), n.uniform1f(this.boundaryUniforms.uRefractionStrength, this.config.refractionStrength), n.uniform1f(this.boundaryUniforms.uChromaticStrength, this.config.chromaticStrength), n.uniform1f(this.boundaryUniforms.uOcclusionIntensity, this.config.occlusionIntensity), n.uniform1f(this.boundaryUniforms.uEdgeThickness, this.config.edgeThickness), n.uniform1f(this.boundaryUniforms.uEdgeSpecular, this.config.edgeSpecular), n.uniform3f(this.boundaryUniforms.uEdgeColor, ...this.config.edgeColor), n.uniform2f(this.boundaryUniforms.uLightDir, this.lightDirX, this.lightDirY), n.uniform1f(this.boundaryUniforms.uBevelIntensity, this.config.bevelIntensity)), this.recalculateViewportLayout());
1967
2010
  }
1968
2011
  // -----------------------------------------------------------------------
1969
2012
  // Geometry upload
@@ -1974,10 +2017,10 @@ class ft {
1974
2017
  this.stencilVao = e.createVertexArray(), e.bindVertexArray(this.stencilVao);
1975
2018
  const i = e.createBuffer();
1976
2019
  e.bindBuffer(e.ARRAY_BUFFER, i), e.bufferData(e.ARRAY_BUFFER, t.vertices, e.STATIC_DRAW);
1977
- const r = e.getAttribLocation(this.stencilProgram, "aPosition");
1978
- e.enableVertexAttribArray(r), e.vertexAttribPointer(r, 2, e.FLOAT, !1, 0, 0);
1979
- const o = e.createBuffer();
1980
- e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, o), e.bufferData(e.ELEMENT_ARRAY_BUFFER, t.indices, e.STATIC_DRAW), this.stencilIndexCount = t.indices.length, e.bindVertexArray(null);
2020
+ const o = e.getAttribLocation(this.stencilProgram, "aPosition");
2021
+ e.enableVertexAttribArray(o), e.vertexAttribPointer(o, 2, e.FLOAT, !1, 0, 0);
2022
+ const n = e.createBuffer();
2023
+ e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n), e.bufferData(e.ELEMENT_ARRAY_BUFFER, t.indices, e.STATIC_DRAW), this.stencilIndexCount = t.indices.length, e.bindVertexArray(null);
1981
2024
  }
1982
2025
  uploadMaskMesh(t) {
1983
2026
  const e = this.gl;
@@ -1985,28 +2028,28 @@ class ft {
1985
2028
  this.maskVao = e.createVertexArray(), e.bindVertexArray(this.maskVao);
1986
2029
  const i = e.createBuffer();
1987
2030
  e.bindBuffer(e.ARRAY_BUFFER, i), e.bufferData(e.ARRAY_BUFFER, t.vertices, e.STATIC_DRAW);
1988
- const r = e.getAttribLocation(this.maskProgram, "aPosition");
1989
- e.enableVertexAttribArray(r), e.vertexAttribPointer(r, 2, e.FLOAT, !1, 0, 0);
1990
- const o = e.createBuffer();
1991
- e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, o), e.bufferData(e.ELEMENT_ARRAY_BUFFER, t.indices, e.STATIC_DRAW), e.bindVertexArray(null);
2031
+ const o = e.getAttribLocation(this.maskProgram, "aPosition");
2032
+ e.enableVertexAttribArray(o), e.vertexAttribPointer(o, 2, e.FLOAT, !1, 0, 0);
2033
+ const n = e.createBuffer();
2034
+ e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n), e.bufferData(e.ELEMENT_ARRAY_BUFFER, t.indices, e.STATIC_DRAW), e.bindVertexArray(null);
1992
2035
  }
1993
2036
  uploadBoundaryMesh(t) {
1994
2037
  const e = this.gl;
1995
2038
  if (!e || !this.boundaryProgram) return;
1996
- const i = fe(t.edgeVertices);
2039
+ const i = de(t.edgeVertices);
1997
2040
  if (i.count === 0) return;
1998
2041
  this.boundaryVao = e.createVertexArray(), e.bindVertexArray(this.boundaryVao);
1999
- const r = e.createBuffer();
2000
- e.bindBuffer(e.ARRAY_BUFFER, r), e.bufferData(e.ARRAY_BUFFER, i.vertices, e.STATIC_DRAW);
2001
- const o = 16, s = e.getAttribLocation(this.boundaryProgram, "aPosition");
2002
- e.enableVertexAttribArray(s), e.vertexAttribPointer(s, 2, e.FLOAT, !1, o, 0);
2003
- const a = e.getAttribLocation(this.boundaryProgram, "aNormal");
2004
- a >= 0 && (e.enableVertexAttribArray(a), e.vertexAttribPointer(a, 2, e.FLOAT, !1, o, 8)), this.boundaryVertexCount = i.count, e.bindVertexArray(null);
2042
+ const o = e.createBuffer();
2043
+ e.bindBuffer(e.ARRAY_BUFFER, o), e.bufferData(e.ARRAY_BUFFER, i.vertices, e.STATIC_DRAW);
2044
+ const n = 16, s = e.getAttribLocation(this.boundaryProgram, "aPosition");
2045
+ e.enableVertexAttribArray(s), e.vertexAttribPointer(s, 2, e.FLOAT, !1, n, 0);
2046
+ const h = e.getAttribLocation(this.boundaryProgram, "aNormal");
2047
+ h >= 0 && (e.enableVertexAttribArray(h), e.vertexAttribPointer(h, 2, e.FLOAT, !1, n, 8)), this.boundaryVertexCount = i.count, e.bindVertexArray(null);
2005
2048
  }
2006
2049
  uploadChamferMesh(t) {
2007
2050
  const e = this.gl;
2008
2051
  if (!e || !this.chamferProgram || this.config.chamferWidth <= 0) return;
2009
- const i = de(
2052
+ const i = me(
2010
2053
  t.edgeVertices,
2011
2054
  t.contourOffsets,
2012
2055
  t.contourIsHole,
@@ -2015,14 +2058,14 @@ class ft {
2015
2058
  );
2016
2059
  if (i.count === 0) return;
2017
2060
  this.chamferVao = e.createVertexArray(), e.bindVertexArray(this.chamferVao);
2018
- const r = e.createBuffer();
2019
- e.bindBuffer(e.ARRAY_BUFFER, r), e.bufferData(e.ARRAY_BUFFER, i.vertices, e.STATIC_DRAW);
2020
- const o = 24, s = e.getAttribLocation(this.chamferProgram, "aPosition");
2021
- e.enableVertexAttribArray(s), e.vertexAttribPointer(s, 2, e.FLOAT, !1, o, 0);
2022
- const a = e.getAttribLocation(this.chamferProgram, "aNormal3");
2023
- a >= 0 && (e.enableVertexAttribArray(a), e.vertexAttribPointer(a, 3, e.FLOAT, !1, o, 8));
2024
- const h = e.getAttribLocation(this.chamferProgram, "aLerpT");
2025
- h >= 0 && (e.enableVertexAttribArray(h), e.vertexAttribPointer(h, 1, e.FLOAT, !1, o, 20)), this.chamferVertexCount = i.count, e.bindVertexArray(null);
2061
+ const o = e.createBuffer();
2062
+ e.bindBuffer(e.ARRAY_BUFFER, o), e.bufferData(e.ARRAY_BUFFER, i.vertices, e.STATIC_DRAW);
2063
+ const n = 24, s = e.getAttribLocation(this.chamferProgram, "aPosition");
2064
+ e.enableVertexAttribArray(s), e.vertexAttribPointer(s, 2, e.FLOAT, !1, n, 0);
2065
+ const h = e.getAttribLocation(this.chamferProgram, "aNormal3");
2066
+ h >= 0 && (e.enableVertexAttribArray(h), e.vertexAttribPointer(h, 3, e.FLOAT, !1, n, 8));
2067
+ const a = e.getAttribLocation(this.chamferProgram, "aLerpT");
2068
+ a >= 0 && (e.enableVertexAttribArray(a), e.vertexAttribPointer(a, 1, e.FLOAT, !1, n, 20)), this.chamferVertexCount = i.count, e.bindVertexArray(null);
2026
2069
  }
2027
2070
  disposeChamferGeometry() {
2028
2071
  const t = this.gl;
@@ -2035,8 +2078,8 @@ class ft {
2035
2078
  const i = this.gl;
2036
2079
  if (!i) return;
2037
2080
  this.disposeFBO(), this.fboWidth = t, this.fboHeight = e, this.interiorFbo = i.createFramebuffer(), i.bindFramebuffer(i.FRAMEBUFFER, this.interiorFbo), this.interiorColorTex = i.createTexture(), i.activeTexture(i.TEXTURE2), i.bindTexture(i.TEXTURE_2D, this.interiorColorTex), i.texStorage2D(i.TEXTURE_2D, 1, i.RGBA8, t, e), 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, this.interiorColorTex, 0), this.interiorDepthTex = i.createTexture(), i.activeTexture(i.TEXTURE3), i.bindTexture(i.TEXTURE_2D, this.interiorDepthTex), i.texStorage2D(i.TEXTURE_2D, 1, i.RGBA8, t, e), 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_ATTACHMENT1, i.TEXTURE_2D, this.interiorDepthTex, 0), i.drawBuffers([i.COLOR_ATTACHMENT0, i.COLOR_ATTACHMENT1]);
2038
- const r = i.checkFramebufferStatus(i.FRAMEBUFFER);
2039
- r !== i.FRAMEBUFFER_COMPLETE && console.error("Interior FBO incomplete:", r), i.bindFramebuffer(i.FRAMEBUFFER, null);
2081
+ const o = i.checkFramebufferStatus(i.FRAMEBUFFER);
2082
+ o !== i.FRAMEBUFFER_COMPLETE && console.error("Interior FBO incomplete:", o), i.bindFramebuffer(i.FRAMEBUFFER, null);
2040
2083
  }
2041
2084
  // -----------------------------------------------------------------------
2042
2085
  // JFA Distance Field
@@ -2045,13 +2088,15 @@ class ft {
2045
2088
  const i = this.gl;
2046
2089
  if (!i) return;
2047
2090
  this.disposeJFA();
2048
- const r = Math.max(1, Math.round(t / 2)), o = Math.max(1, Math.round(e / 2));
2049
- this.jfaWidth = r, this.jfaHeight = o;
2050
- const s = (a, h, l, u) => {
2051
- const f = i.createFramebuffer();
2052
- return i.bindFramebuffer(i.FRAMEBUFFER, f), i.bindTexture(i.TEXTURE_2D, a), i.texStorage2D(i.TEXTURE_2D, 1, h, l, 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, a, 0), i.bindFramebuffer(i.FRAMEBUFFER, null), f;
2091
+ const o = Math.max(1, Math.round(t / 2)), n = Math.max(1, Math.round(e / 2));
2092
+ this.jfaWidth = o, this.jfaHeight = n;
2093
+ const s = (a, l, u, f) => {
2094
+ const c = i.createFramebuffer();
2095
+ return i.bindFramebuffer(i.FRAMEBUFFER, c), i.bindTexture(i.TEXTURE_2D, a), i.texStorage2D(i.TEXTURE_2D, 1, l, u, f), 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, a, 0), i.bindFramebuffer(i.FRAMEBUFFER, null), c;
2053
2096
  };
2054
- this.maskTex = i.createTexture(), this.maskFbo = s(this.maskTex, i.R8, r, o), this.jfaPingTex = i.createTexture(), this.jfaPingFbo = s(this.jfaPingTex, i.RG16F, r, o), this.jfaPongTex = i.createTexture(), this.jfaPongFbo = s(this.jfaPongTex, i.RG16F, r, o), this.distTex = i.createTexture(), this.distFbo = s(this.distTex, i.RGBA8, r, o), this.distFieldDirty = !0;
2097
+ this.maskTex = i.createTexture(), this.maskFbo = s(this.maskTex, i.R8, o, n);
2098
+ const h = this.hasColorBufferFloat ? i.RG16F : i.RGBA8;
2099
+ this.jfaPingTex = i.createTexture(), this.jfaPingFbo = s(this.jfaPingTex, h, o, n), this.jfaPongTex = i.createTexture(), this.jfaPongFbo = s(this.jfaPongTex, h, o, n), this.distTex = i.createTexture(), this.distFbo = s(this.distTex, i.RGBA8, o, n), this.distFieldDirty = !0;
2055
2100
  }
2056
2101
  computeDistanceField() {
2057
2102
  const t = this.gl;
@@ -2059,33 +2104,33 @@ class ft {
2059
2104
  const e = this.jfaWidth, i = this.jfaHeight;
2060
2105
  if (e === 0 || i === 0) return;
2061
2106
  t.viewport(0, 0, e, i), t.disable(t.STENCIL_TEST), t.disable(t.BLEND), t.bindFramebuffer(t.FRAMEBUFFER, this.maskFbo), t.clearColor(0, 0, 0, 1), t.clear(t.COLOR_BUFFER_BIT), t.useProgram(this.maskProgram), t.uniform2f(this.maskUniforms.uMeshScale, this.meshScaleX, this.meshScaleY), t.bindVertexArray(this.maskVao), t.drawElements(t.TRIANGLES, this.stencilIndexCount, t.UNSIGNED_SHORT, 0), t.bindFramebuffer(t.FRAMEBUFFER, this.jfaPingFbo), t.clearColor(-1, -1, 0, 0), t.clear(t.COLOR_BUFFER_BIT), t.useProgram(this.jfaSeedProgram), t.activeTexture(t.TEXTURE5), t.bindTexture(t.TEXTURE_2D, this.maskTex), t.uniform1i(this.jfaSeedUniforms.uMask, 5), t.uniform2f(this.jfaSeedUniforms.uTexelSize, 1 / e, 1 / i), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4);
2062
- const r = Math.max(e, i), o = [];
2063
- let s = Math.ceil(r / 2);
2107
+ const o = Math.max(e, i), n = [];
2108
+ let s = Math.ceil(o / 2);
2064
2109
  for (; s >= 1; )
2065
- o.push(s), s = Math.floor(s / 2);
2110
+ n.push(s), s = Math.floor(s / 2);
2066
2111
  t.useProgram(this.jfaFloodProgram);
2067
- let a = this.jfaPingTex, h = this.jfaPongFbo, l = this.jfaPongTex;
2068
- for (let f = 0; f < o.length; f++) {
2069
- const c = o[f] / Math.max(e, i);
2070
- t.bindFramebuffer(t.FRAMEBUFFER, h), t.activeTexture(t.TEXTURE5), t.bindTexture(t.TEXTURE_2D, a), t.uniform1i(this.jfaFloodUniforms.uSeedTex, 5), t.uniform1f(this.jfaFloodUniforms.uStepSize, c), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4);
2071
- const d = a, m = h;
2072
- a = l, h = m === this.jfaPongFbo ? this.jfaPingFbo : this.jfaPongFbo, l = d;
2112
+ let h = this.jfaPingTex, a = this.jfaPongFbo, l = this.jfaPongTex;
2113
+ for (let f = 0; f < n.length; f++) {
2114
+ const c = n[f] / Math.max(e, i);
2115
+ t.bindFramebuffer(t.FRAMEBUFFER, a), t.activeTexture(t.TEXTURE5), t.bindTexture(t.TEXTURE_2D, h), t.uniform1i(this.jfaFloodUniforms.uSeedTex, 5), t.uniform1f(this.jfaFloodUniforms.uStepSize, c), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4);
2116
+ const g = h, d = a;
2117
+ h = l, a = d === this.jfaPongFbo ? this.jfaPingFbo : this.jfaPongFbo, l = g;
2073
2118
  }
2074
- t.bindFramebuffer(t.FRAMEBUFFER, this.distFbo), t.clearColor(0, 0, 0, 1), t.clear(t.COLOR_BUFFER_BIT), t.useProgram(this.jfaDistProgram), t.activeTexture(t.TEXTURE5), t.bindTexture(t.TEXTURE_2D, a), t.uniform1i(this.jfaDistUniforms.uSeedTex, 5), t.activeTexture(t.TEXTURE6), t.bindTexture(t.TEXTURE_2D, this.maskTex), t.uniform1i(this.jfaDistUniforms.uMask, 6);
2119
+ t.bindFramebuffer(t.FRAMEBUFFER, this.distFbo), t.clearColor(0, 0, 0, 1), t.clear(t.COLOR_BUFFER_BIT), t.useProgram(this.jfaDistProgram), t.activeTexture(t.TEXTURE5), t.bindTexture(t.TEXTURE_2D, h), t.uniform1i(this.jfaDistUniforms.uSeedTex, 5), t.activeTexture(t.TEXTURE6), t.bindTexture(t.TEXTURE_2D, this.maskTex), t.uniform1i(this.jfaDistUniforms.uMask, 6);
2075
2120
  const u = Math.max(this.config.bevelWidth, this.config.edgeOcclusionWidth);
2076
2121
  t.uniform1f(this.jfaDistUniforms.uBevelWidth, u), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4), t.activeTexture(t.TEXTURE4), t.bindTexture(t.TEXTURE_2D, this.distTex), t.bindFramebuffer(t.FRAMEBUFFER, null), this.distFieldDirty = !1;
2077
2122
  }
2078
2123
  // -----------------------------------------------------------------------
2079
2124
  // Render loop control
2080
2125
  // -----------------------------------------------------------------------
2081
- start(t, e, i, r) {
2082
- this.stop(), this.playbackVideo = t, this.readDepth = e, this.readInput = i, this.onVideoFrame = r ?? null, this.rvfcSupported = "requestVideoFrameCallback" in HTMLVideoElement.prototype, this.rvfcSupported && (this.rvfcHandle = t.requestVideoFrameCallback(this.videoFrameLoop)), this.animationFrameHandle = window.requestAnimationFrame(this.renderLoop);
2126
+ start(t, e, i, o) {
2127
+ this.stop(), this.playbackVideo = t, this.readDepth = e, this.readInput = i, this.onVideoFrame = o ?? null, this.rvfcSupported = "requestVideoFrameCallback" in HTMLVideoElement.prototype, this.rvfcSupported && (this.rvfcHandle = t.requestVideoFrameCallback(this.videoFrameLoop)), this.animationFrameHandle = window.requestAnimationFrame(this.renderLoop);
2083
2128
  }
2084
2129
  stop() {
2085
2130
  this.animationFrameHandle && (window.cancelAnimationFrame(this.animationFrameHandle), this.animationFrameHandle = 0), this.rvfcHandle && this.playbackVideo && (this.playbackVideo.cancelVideoFrameCallback(this.rvfcHandle), this.rvfcHandle = 0), this.playbackVideo = null, this.readDepth = null, this.readInput = null, this.onVideoFrame = null, this.rvfcSupported = !1;
2086
2131
  }
2087
2132
  dispose() {
2088
- this.stop(), this.disposeTextures(), this.disposeFBO(), this.disposeJFA(), this.disposeStencilGeometry(), this.disposeBoundaryGeometry(), this.disposeChamferGeometry(), this.disposeGPUResources(), this.canvas.removeEventListener("webglcontextlost", this.handleContextLost), this.canvas.removeEventListener("webglcontextrestored", this.handleContextRestored), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), window.removeEventListener("resize", this.scheduleResizeRecalculate), this.resizeTimer !== null && (window.clearTimeout(this.resizeTimer), this.resizeTimer = null);
2133
+ this.stop(), this.disposeTextures(), this.disposeFBO(), this.disposeJFA(), this.disposeStencilGeometry(), this.disposeBoundaryGeometry(), this.disposeChamferGeometry(), this.disposeGPUResources(), this.canvas.removeEventListener("webglcontextlost", this.handleContextLost), this.canvas.removeEventListener("webglcontextrestored", this.handleContextRestored), this.gl && (this.gl.getExtension("WEBGL_lose_context")?.loseContext(), this.gl = null), this.canvas.remove(), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), window.removeEventListener("resize", this.scheduleResizeRecalculate), this.resizeTimer !== null && (window.clearTimeout(this.resizeTimer), this.resizeTimer = null);
2089
2134
  }
2090
2135
  // -----------------------------------------------------------------------
2091
2136
  // GPU resource initialization
@@ -2095,32 +2140,32 @@ class ft {
2095
2140
  if (!t) return;
2096
2141
  this.stencilProgram = V(
2097
2142
  t,
2098
- L(t, t.VERTEX_SHADER, qt),
2099
- L(t, t.FRAGMENT_SHADER, Zt)
2143
+ L(t, t.VERTEX_SHADER, Zt),
2144
+ L(t, t.FRAGMENT_SHADER, $t)
2100
2145
  ), this.stencilUniforms = {
2101
2146
  uMeshScale: t.getUniformLocation(this.stencilProgram, "uMeshScale")
2102
2147
  }, this.maskProgram = V(
2103
2148
  t,
2104
- L(t, t.VERTEX_SHADER, $t),
2105
- L(t, t.FRAGMENT_SHADER, Jt)
2149
+ L(t, t.VERTEX_SHADER, Jt),
2150
+ L(t, t.FRAGMENT_SHADER, Kt)
2106
2151
  ), this.maskUniforms = {
2107
2152
  uMeshScale: t.getUniformLocation(this.maskProgram, "uMeshScale")
2108
2153
  }, this.jfaSeedProgram = V(
2109
2154
  t,
2110
- L(t, t.VERTEX_SHADER, Kt),
2111
- L(t, t.FRAGMENT_SHADER, Qt)
2155
+ L(t, t.VERTEX_SHADER, Qt),
2156
+ L(t, t.FRAGMENT_SHADER, te)
2112
2157
  ), this.jfaSeedUniforms = this.getUniforms(this.jfaSeedProgram, ["uMask", "uTexelSize"]), this.jfaFloodProgram = V(
2113
2158
  t,
2114
- L(t, t.VERTEX_SHADER, te),
2115
- L(t, t.FRAGMENT_SHADER, ee)
2159
+ L(t, t.VERTEX_SHADER, ee),
2160
+ L(t, t.FRAGMENT_SHADER, ie)
2116
2161
  ), this.jfaFloodUniforms = this.getUniforms(this.jfaFloodProgram, ["uSeedTex", "uStepSize"]), this.jfaDistProgram = V(
2117
2162
  t,
2118
- L(t, t.VERTEX_SHADER, ie),
2119
- L(t, t.FRAGMENT_SHADER, re)
2163
+ L(t, t.VERTEX_SHADER, re),
2164
+ L(t, t.FRAGMENT_SHADER, oe)
2120
2165
  ), this.jfaDistUniforms = this.getUniforms(this.jfaDistProgram, ["uSeedTex", "uMask", "uBevelWidth"]), this.interiorProgram = V(
2121
2166
  t,
2122
- L(t, t.VERTEX_SHADER, oe),
2123
- L(t, t.FRAGMENT_SHADER, ne)
2167
+ L(t, t.VERTEX_SHADER, ne),
2168
+ L(t, t.FRAGMENT_SHADER, se)
2124
2169
  ), this.interiorUniforms = this.getUniforms(this.interiorProgram, [
2125
2170
  "uImage",
2126
2171
  "uDepth",
@@ -2144,8 +2189,8 @@ class ft {
2144
2189
  "uUvScale"
2145
2190
  ]), this.compositeProgram = V(
2146
2191
  t,
2147
- L(t, t.VERTEX_SHADER, se),
2148
- L(t, t.FRAGMENT_SHADER, ae)
2192
+ L(t, t.VERTEX_SHADER, ae),
2193
+ L(t, t.FRAGMENT_SHADER, he)
2149
2194
  ), this.compositeUniforms = this.getUniforms(this.compositeProgram, [
2150
2195
  "uInteriorColor",
2151
2196
  "uDistField",
@@ -2153,8 +2198,8 @@ class ft {
2153
2198
  "uEdgeOcclusionStrength"
2154
2199
  ]), this.boundaryProgram = V(
2155
2200
  t,
2156
- L(t, t.VERTEX_SHADER, he),
2157
- L(t, t.FRAGMENT_SHADER, le)
2201
+ L(t, t.VERTEX_SHADER, le),
2202
+ L(t, t.FRAGMENT_SHADER, ce)
2158
2203
  ), this.boundaryUniforms = this.getUniforms(this.boundaryProgram, [
2159
2204
  "uInteriorColor",
2160
2205
  "uInteriorDepth",
@@ -2174,8 +2219,8 @@ class ft {
2174
2219
  "uBevelIntensity"
2175
2220
  ]), this.chamferProgram = V(
2176
2221
  t,
2177
- L(t, t.VERTEX_SHADER, ce),
2178
- L(t, t.FRAGMENT_SHADER, ue)
2222
+ L(t, t.VERTEX_SHADER, ue),
2223
+ L(t, t.FRAGMENT_SHADER, fe)
2179
2224
  ), this.chamferUniforms = this.getUniforms(this.chamferProgram, [
2180
2225
  "uMeshScale",
2181
2226
  "uLightDir3",
@@ -2190,14 +2235,14 @@ class ft {
2190
2235
  this.quadVao = t.createVertexArray(), t.bindVertexArray(this.quadVao);
2191
2236
  const i = t.createBuffer();
2192
2237
  t.bindBuffer(t.ARRAY_BUFFER, i), t.bufferData(t.ARRAY_BUFFER, e, t.STATIC_DRAW);
2193
- const r = t.getAttribLocation(this.interiorProgram, "aPosition");
2194
- t.enableVertexAttribArray(r), t.vertexAttribPointer(r, 2, t.FLOAT, !1, 0, 0), t.bindVertexArray(null), t.disable(t.DEPTH_TEST);
2238
+ const o = t.getAttribLocation(this.interiorProgram, "aPosition");
2239
+ t.enableVertexAttribArray(o), t.vertexAttribPointer(o, 2, t.FLOAT, !1, 0, 0), t.bindVertexArray(null), t.disable(t.DEPTH_TEST);
2195
2240
  }
2196
2241
  getUniforms(t, e) {
2197
- const i = this.gl, r = {};
2198
- for (const o of e)
2199
- r[o] = i.getUniformLocation(t, o);
2200
- return r;
2242
+ const i = this.gl, o = {};
2243
+ for (const n of e)
2244
+ o[n] = i.getUniformLocation(t, n);
2245
+ return o;
2201
2246
  }
2202
2247
  // -----------------------------------------------------------------------
2203
2248
  // RVFC loop
@@ -2206,8 +2251,8 @@ class ft {
2206
2251
  const i = this.playbackVideo;
2207
2252
  if (!i) return;
2208
2253
  this.rvfcHandle = i.requestVideoFrameCallback(this.videoFrameLoop);
2209
- const r = e.mediaTime ?? i.currentTime;
2210
- this.updateDepthTexture(r), this.onVideoFrame && this.onVideoFrame(r, e.presentedFrames ?? 0);
2254
+ const o = e.mediaTime ?? i.currentTime;
2255
+ this.updateDepthTexture(o), this.onVideoFrame && this.onVideoFrame(o, e.presentedFrames ?? 0);
2211
2256
  };
2212
2257
  // -----------------------------------------------------------------------
2213
2258
  // Main render loop
@@ -2217,12 +2262,16 @@ class ft {
2217
2262
  const t = this.gl, e = this.playbackVideo;
2218
2263
  if (!t || !this.interiorProgram || !this.quadVao || !e || e.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || !this.interiorFbo || !this.interiorColorTex || !this.interiorDepthTex) return;
2219
2264
  this.distFieldDirty && this.maskVao && this.distFbo && (this.computeDistanceField(), t.viewport(0, 0, this.canvas.width, this.canvas.height)), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.videoTexture), t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.rvfcSupported || this.updateDepthTexture(e.currentTime);
2220
- let i = 0, r = 0;
2265
+ let i = 0, o = 0;
2221
2266
  if (this.readInput) {
2222
- const o = this.readInput();
2223
- i = -o.x, r = o.y;
2267
+ const n = this.readInput();
2268
+ i = -n.x, o = n.y;
2269
+ }
2270
+ if (t.bindFramebuffer(t.FRAMEBUFFER, this.interiorFbo), t.checkFramebufferStatus(t.FRAMEBUFFER) !== t.FRAMEBUFFER_COMPLETE) {
2271
+ t.bindFramebuffer(t.FRAMEBUFFER, null);
2272
+ return;
2224
2273
  }
2225
- t.bindFramebuffer(t.FRAMEBUFFER, this.interiorFbo), t.viewport(0, 0, this.fboWidth, this.fboHeight), t.clearColor(0, 0, 0, 1), t.clear(t.COLOR_BUFFER_BIT), t.useProgram(this.interiorProgram), t.uniform2f(this.interiorUniforms.uOffset, i, r), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.videoTexture), t.activeTexture(t.TEXTURE1), t.bindTexture(t.TEXTURE_2D, this.depthTexture), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4), t.bindFramebuffer(t.FRAMEBUFFER, null), t.clearColor(0, 0, 0, 0), t.viewport(0, 0, this.canvas.width, this.canvas.height), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT), this.stencilVao && this.stencilProgram && this.stencilIndexCount > 0 && (t.enable(t.STENCIL_TEST), t.stencilFunc(t.ALWAYS, 1, 255), t.stencilOp(t.KEEP, t.KEEP, t.REPLACE), t.stencilMask(255), t.colorMask(!1, !1, !1, !1), t.useProgram(this.stencilProgram), t.bindVertexArray(this.stencilVao), t.drawElements(t.TRIANGLES, this.stencilIndexCount, t.UNSIGNED_SHORT, 0), t.colorMask(!0, !0, !0, !0)), t.stencilFunc(t.EQUAL, 1, 255), t.stencilMask(0), t.activeTexture(t.TEXTURE2), t.bindTexture(t.TEXTURE_2D, this.interiorColorTex), t.activeTexture(t.TEXTURE3), t.bindTexture(t.TEXTURE_2D, this.interiorDepthTex), t.activeTexture(t.TEXTURE4), t.bindTexture(t.TEXTURE_2D, this.distTex), t.useProgram(this.compositeProgram), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4), t.disable(t.STENCIL_TEST), this.chamferVao && this.chamferProgram && this.chamferVertexCount > 0 && (t.useProgram(this.chamferProgram), t.uniform2f(this.chamferUniforms.uMeshScale, this.meshScaleX, this.meshScaleY), t.uniform2f(this.chamferUniforms.uTexelSize, 1 / this.canvas.width, 1 / this.canvas.height), t.bindVertexArray(this.chamferVao), t.drawArrays(t.TRIANGLES, 0, this.chamferVertexCount)), this.boundaryVao && this.boundaryProgram && this.boundaryVertexCount > 0 && this.config.rimLightIntensity > 0 && (t.enable(t.BLEND), t.blendFunc(t.SRC_ALPHA, t.ONE_MINUS_SRC_ALPHA), t.useProgram(this.boundaryProgram), t.bindVertexArray(this.boundaryVao), t.drawArrays(t.TRIANGLES, 0, this.boundaryVertexCount), t.disable(t.BLEND));
2274
+ t.viewport(0, 0, this.fboWidth, this.fboHeight), t.clearColor(0, 0, 0, 1), t.clear(t.COLOR_BUFFER_BIT), t.useProgram(this.interiorProgram), t.uniform2f(this.interiorUniforms.uOffset, i, o), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.videoTexture), t.activeTexture(t.TEXTURE1), t.bindTexture(t.TEXTURE_2D, this.depthTexture), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4), t.bindFramebuffer(t.FRAMEBUFFER, null), t.clearColor(0, 0, 0, 0), t.viewport(0, 0, this.canvas.width, this.canvas.height), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT), this.stencilVao && this.stencilProgram && this.stencilIndexCount > 0 && (t.enable(t.STENCIL_TEST), t.stencilFunc(t.ALWAYS, 1, 255), t.stencilOp(t.KEEP, t.KEEP, t.REPLACE), t.stencilMask(255), t.colorMask(!1, !1, !1, !1), t.useProgram(this.stencilProgram), t.bindVertexArray(this.stencilVao), t.drawElements(t.TRIANGLES, this.stencilIndexCount, t.UNSIGNED_SHORT, 0), t.colorMask(!0, !0, !0, !0)), t.stencilFunc(t.EQUAL, 1, 255), t.stencilMask(0), t.activeTexture(t.TEXTURE2), t.bindTexture(t.TEXTURE_2D, this.interiorColorTex), t.activeTexture(t.TEXTURE3), t.bindTexture(t.TEXTURE_2D, this.interiorDepthTex), t.activeTexture(t.TEXTURE4), t.bindTexture(t.TEXTURE_2D, this.distTex), t.useProgram(this.compositeProgram), t.bindVertexArray(this.quadVao), t.drawArrays(t.TRIANGLE_STRIP, 0, 4), t.disable(t.STENCIL_TEST), this.chamferVao && this.chamferProgram && this.chamferVertexCount > 0 && (t.useProgram(this.chamferProgram), t.uniform2f(this.chamferUniforms.uMeshScale, this.meshScaleX, this.meshScaleY), t.uniform2f(this.chamferUniforms.uTexelSize, 1 / this.canvas.width, 1 / this.canvas.height), t.bindVertexArray(this.chamferVao), t.drawArrays(t.TRIANGLES, 0, this.chamferVertexCount)), this.boundaryVao && this.boundaryProgram && this.boundaryVertexCount > 0 && this.config.rimLightIntensity > 0 && (t.enable(t.BLEND), t.blendFunc(t.SRC_ALPHA, t.ONE_MINUS_SRC_ALPHA), t.useProgram(this.boundaryProgram), t.bindVertexArray(this.boundaryVao), t.drawArrays(t.TRIANGLES, 0, this.boundaryVertexCount), t.disable(t.BLEND));
2226
2275
  };
2227
2276
  updateDepthTexture(t) {
2228
2277
  const e = this.gl;
@@ -2256,17 +2305,17 @@ class ft {
2256
2305
  recalculateViewportLayout() {
2257
2306
  const t = this.gl;
2258
2307
  if (!t) return;
2259
- const { width: e, height: i } = this.getViewportSize(), r = Math.min(window.devicePixelRatio, 2), o = Math.round(e * r), s = Math.round(i * r);
2260
- (this.canvas.width !== o || this.canvas.height !== s) && (this.canvas.width = o, this.canvas.height = s, t.viewport(0, 0, o, s)), (this.fboWidth !== o || this.fboHeight !== s) && this.createFBO(o, s);
2261
- const a = Math.max(1, Math.round(o / 2)), h = Math.max(1, Math.round(s / 2));
2262
- (this.jfaWidth !== a || this.jfaHeight !== h) && this.createJFAResources(o, s);
2308
+ const { width: e, height: i } = this.getViewportSize(), o = Math.min(window.devicePixelRatio, 2), n = Math.round(e * o), s = Math.round(i * o);
2309
+ (this.canvas.width !== n || this.canvas.height !== s) && (this.canvas.width = n, this.canvas.height = s, t.viewport(0, 0, n, s)), (this.fboWidth !== n || this.fboHeight !== s) && this.createFBO(n, s);
2310
+ const h = Math.max(1, Math.round(n / 2)), a = Math.max(1, Math.round(s / 2));
2311
+ (this.jfaWidth !== h || this.jfaHeight !== a) && this.createJFAResources(n, s);
2263
2312
  const l = e / i, u = this.config.parallaxStrength + this.config.overscanPadding;
2264
2313
  let f = 1, c = 1;
2265
2314
  l > this.videoAspect ? c = this.videoAspect / l : f = l / this.videoAspect;
2266
- const d = 1 + u * 2;
2267
- f /= d, c /= d, this.uvOffset = [(1 - f) / 2, (1 - c) / 2], this.uvScale = [f, c], this.interiorProgram && (t.useProgram(this.interiorProgram), t.uniform2f(this.interiorUniforms.uUvOffset, this.uvOffset[0], this.uvOffset[1]), t.uniform2f(this.interiorUniforms.uUvScale, this.uvScale[0], this.uvScale[1]));
2268
- const m = 0.65;
2269
- this.meshScaleX = m, this.meshScaleY = m, l > this.meshAspect ? this.meshScaleX = m * (this.meshAspect / l) : this.meshScaleY = m * (l / this.meshAspect), this.stencilProgram && (t.useProgram(this.stencilProgram), t.uniform2f(this.stencilUniforms.uMeshScale, this.meshScaleX, this.meshScaleY)), this.boundaryProgram && (t.useProgram(this.boundaryProgram), t.uniform2f(this.boundaryUniforms.uMeshScale, this.meshScaleX, this.meshScaleY), t.uniform1f(this.boundaryUniforms.uRimWidth, this.config.rimLightWidth), t.uniform2f(this.boundaryUniforms.uTexelSize, 1 / o, 1 / s)), this.chamferProgram && (t.useProgram(this.chamferProgram), t.uniform2f(this.chamferUniforms.uMeshScale, this.meshScaleX, this.meshScaleY)), this.distFieldDirty = !0;
2315
+ const g = 1 + u * 2;
2316
+ f /= g, c /= g, this.uvOffset = [(1 - f) / 2, (1 - c) / 2], this.uvScale = [f, c], this.interiorProgram && (t.useProgram(this.interiorProgram), t.uniform2f(this.interiorUniforms.uUvOffset, this.uvOffset[0], this.uvOffset[1]), t.uniform2f(this.interiorUniforms.uUvScale, this.uvScale[0], this.uvScale[1]));
2317
+ const d = 0.65;
2318
+ this.meshScaleX = d, this.meshScaleY = d, l > this.meshAspect ? this.meshScaleX = d * (this.meshAspect / l) : this.meshScaleY = d * (l / this.meshAspect), this.stencilProgram && (t.useProgram(this.stencilProgram), t.uniform2f(this.stencilUniforms.uMeshScale, this.meshScaleX, this.meshScaleY)), this.boundaryProgram && (t.useProgram(this.boundaryProgram), t.uniform2f(this.boundaryUniforms.uMeshScale, this.meshScaleX, this.meshScaleY), t.uniform1f(this.boundaryUniforms.uRimWidth, this.config.rimLightWidth), t.uniform2f(this.boundaryUniforms.uTexelSize, 1 / n, 1 / s)), this.chamferProgram && (t.useProgram(this.chamferProgram), t.uniform2f(this.chamferUniforms.uMeshScale, this.meshScaleX, this.meshScaleY)), this.distFieldDirty = !0;
2270
2319
  }
2271
2320
  getViewportSize() {
2272
2321
  const t = Math.max(1, Math.round(this.container.clientWidth || window.innerWidth)), e = Math.max(1, Math.round(this.container.clientHeight || window.innerHeight));
@@ -2284,7 +2333,7 @@ class ft {
2284
2333
  premultipliedAlpha: !0,
2285
2334
  stencil: !0
2286
2335
  });
2287
- t && (this.gl = t, t.clearColor(0, 0, 0, 0), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, !0), this.initGPUResources(), this.playbackVideo && (this.animationFrameHandle = window.requestAnimationFrame(this.renderLoop)));
2336
+ t && (this.gl = t, this.hasColorBufferFloat = !!t.getExtension("EXT_color_buffer_float"), t.clearColor(0, 0, 0, 0), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, !0), this.initGPUResources(), this.recalculateViewportLayout(), this.playbackVideo && (this.animationFrameHandle = window.requestAnimationFrame(this.renderLoop)));
2288
2337
  };
2289
2338
  // -----------------------------------------------------------------------
2290
2339
  // Cleanup
@@ -2314,334 +2363,334 @@ class ft {
2314
2363
  t && (this.stencilProgram && (t.deleteProgram(this.stencilProgram), this.stencilProgram = null), this.maskProgram && (t.deleteProgram(this.maskProgram), this.maskProgram = null), this.jfaSeedProgram && (t.deleteProgram(this.jfaSeedProgram), this.jfaSeedProgram = null), this.jfaFloodProgram && (t.deleteProgram(this.jfaFloodProgram), this.jfaFloodProgram = null), this.jfaDistProgram && (t.deleteProgram(this.jfaDistProgram), this.jfaDistProgram = null), this.interiorProgram && (t.deleteProgram(this.interiorProgram), this.interiorProgram = null), this.compositeProgram && (t.deleteProgram(this.compositeProgram), this.compositeProgram = null), this.boundaryProgram && (t.deleteProgram(this.boundaryProgram), this.boundaryProgram = null), this.chamferProgram && (t.deleteProgram(this.chamferProgram), this.chamferProgram = null), this.quadVao && (t.deleteVertexArray(this.quadVao), this.quadVao = null), this.stencilUniforms = {}, this.maskUniforms = {}, this.jfaSeedUniforms = {}, this.jfaFloodUniforms = {}, this.jfaDistUniforms = {}, this.interiorUniforms = {}, this.compositeUniforms = {}, this.boundaryUniforms = {}, this.chamferUniforms = {});
2315
2364
  }
2316
2365
  }
2317
- async function me(n) {
2318
- const t = await fetch(n);
2366
+ async function pe(r) {
2367
+ const t = await fetch(r);
2319
2368
  if (!t.ok)
2320
2369
  throw new Error(`Failed to fetch SVG: ${t.status} ${t.statusText}`);
2321
2370
  const e = await t.text();
2322
- return pe(e);
2371
+ return ge(e);
2323
2372
  }
2324
- function pe(n) {
2325
- const i = new DOMParser().parseFromString(n, "image/svg+xml").querySelector("svg");
2373
+ function ge(r) {
2374
+ const i = new DOMParser().parseFromString(r, "image/svg+xml").querySelector("svg");
2326
2375
  if (!i)
2327
2376
  throw new Error("No <svg> element found in document.");
2328
- const r = ge(i);
2329
- if (r.length === 0)
2377
+ const o = ve(i);
2378
+ if (o.length === 0)
2330
2379
  throw new Error("No path data found in SVG.");
2331
- let o = 1 / 0, s = 1 / 0, a = -1 / 0, h = -1 / 0;
2332
- for (const D of r)
2333
- for (let R = 0; R < D.length; R += 2)
2334
- o = Math.min(o, D[R]), a = Math.max(a, D[R]), s = Math.min(s, D[R + 1]), h = Math.max(h, D[R + 1]);
2335
- const l = a - o, u = h - s, f = (o + a) / 2, c = (s + h) / 2, d = 2 / Math.max(l, u), m = l / u, g = r.map((D) => {
2380
+ let n = 1 / 0, s = 1 / 0, h = -1 / 0, a = -1 / 0;
2381
+ for (const F of o)
2382
+ for (let R = 0; R < F.length; R += 2)
2383
+ n = Math.min(n, F[R]), h = Math.max(h, F[R]), s = Math.min(s, F[R + 1]), a = Math.max(a, F[R + 1]);
2384
+ const l = h - n, u = a - s, f = (n + h) / 2, c = (s + a) / 2, g = 2 / Math.max(l, u), d = l / u, m = o.map((F) => {
2336
2385
  const R = [];
2337
- for (let C = 0; C < D.length; C += 2)
2338
- R.push((D[C] - f) * d), R.push(-((D[C + 1] - c) * d));
2386
+ for (let C = 0; C < F.length; C += 2)
2387
+ R.push((F[C] - f) * g), R.push(-((F[C + 1] - c) * g));
2339
2388
  return R;
2340
- }), U = Se(g), b = [], E = [];
2341
- for (const D of U) {
2342
- const { flatCoords: R, holeIndices: C } = ye(D), M = Re(R, C), H = b.length / 2;
2389
+ }), U = Re(m), b = [], E = [];
2390
+ for (const F of U) {
2391
+ const { flatCoords: R, holeIndices: C } = Se(F), M = Fe(R, C), B = b.length / 2;
2343
2392
  for (const I of M)
2344
- E.push(I + H);
2393
+ E.push(I + B);
2345
2394
  for (const I of R)
2346
2395
  b.push(I);
2347
2396
  }
2348
- const p = b, v = E, T = [], x = [], y = [], S = St(g);
2349
- for (let D = 0; D < g.length; D++) {
2350
- const R = g[D];
2351
- x.push(T.length), y.push(S[D]);
2397
+ const p = b, v = E, T = [], x = [], A = [], S = Rt(m);
2398
+ for (let F = 0; F < m.length; F++) {
2399
+ const R = m[F];
2400
+ x.push(T.length), A.push(S[F]);
2352
2401
  for (let C = 0; C < R.length; C++)
2353
2402
  T.push(R[C]);
2354
2403
  R.length >= 2 && T.push(R[0], R[1]);
2355
2404
  }
2356
- let F = 1 / 0, P = 1 / 0, _ = -1 / 0, k = -1 / 0;
2357
- for (let D = 0; D < p.length; D += 2)
2358
- F = Math.min(F, p[D]), _ = Math.max(_, p[D]), P = Math.min(P, p[D + 1]), k = Math.max(k, p[D + 1]);
2405
+ let D = 1 / 0, P = 1 / 0, _ = -1 / 0, k = -1 / 0;
2406
+ for (let F = 0; F < p.length; F += 2)
2407
+ D = Math.min(D, p[F]), _ = Math.max(_, p[F]), P = Math.min(P, p[F + 1]), k = Math.max(k, p[F + 1]);
2359
2408
  return {
2360
2409
  vertices: new Float32Array(p),
2361
2410
  indices: new Uint16Array(v),
2362
2411
  edgeVertices: new Float32Array(T),
2363
2412
  contourOffsets: x,
2364
- contourIsHole: y,
2365
- bounds: { minX: F, maxX: _, minY: P, maxY: k },
2366
- aspect: m
2413
+ contourIsHole: A,
2414
+ bounds: { minX: D, maxX: _, minY: P, maxY: k },
2415
+ aspect: d
2367
2416
  };
2368
2417
  }
2369
- function ge(n) {
2418
+ function ve(r) {
2370
2419
  const t = [];
2371
- return n.querySelectorAll("path").forEach((h) => {
2372
- const l = h.getAttribute("d");
2420
+ return r.querySelectorAll("path").forEach((a) => {
2421
+ const l = a.getAttribute("d");
2373
2422
  if (!l) return;
2374
- const u = Te(l);
2423
+ const u = Ee(l);
2375
2424
  t.push(...u);
2376
- }), n.querySelectorAll("polygon").forEach((h) => {
2377
- const l = h.getAttribute("points");
2425
+ }), r.querySelectorAll("polygon").forEach((a) => {
2426
+ const l = a.getAttribute("points");
2378
2427
  if (!l) return;
2379
2428
  const u = vt(l);
2380
2429
  u.length >= 6 && t.push(u);
2381
- }), n.querySelectorAll("polyline").forEach((h) => {
2382
- const l = h.getAttribute("points");
2430
+ }), r.querySelectorAll("polyline").forEach((a) => {
2431
+ const l = a.getAttribute("points");
2383
2432
  if (!l) return;
2384
2433
  const u = vt(l);
2385
2434
  u.length >= 6 && t.push(u);
2386
- }), n.querySelectorAll("rect").forEach((h) => {
2387
- const l = parseFloat(h.getAttribute("x") || "0"), u = parseFloat(h.getAttribute("y") || "0"), f = parseFloat(h.getAttribute("width") || "0"), c = parseFloat(h.getAttribute("height") || "0");
2435
+ }), r.querySelectorAll("rect").forEach((a) => {
2436
+ const l = parseFloat(a.getAttribute("x") || "0"), u = parseFloat(a.getAttribute("y") || "0"), f = parseFloat(a.getAttribute("width") || "0"), c = parseFloat(a.getAttribute("height") || "0");
2388
2437
  f > 0 && c > 0 && t.push([l, u, l + f, u, l + f, u + c, l, u + c]);
2389
- }), n.querySelectorAll("circle").forEach((h) => {
2390
- const l = parseFloat(h.getAttribute("cx") || "0"), u = parseFloat(h.getAttribute("cy") || "0"), f = parseFloat(h.getAttribute("r") || "0");
2391
- f > 0 && t.push(ve(l, u, f));
2392
- }), n.querySelectorAll("ellipse").forEach((h) => {
2393
- const l = parseFloat(h.getAttribute("cx") || "0"), u = parseFloat(h.getAttribute("cy") || "0"), f = parseFloat(h.getAttribute("rx") || "0"), c = parseFloat(h.getAttribute("ry") || "0");
2394
- f > 0 && c > 0 && t.push(xe(l, u, f, c));
2438
+ }), r.querySelectorAll("circle").forEach((a) => {
2439
+ const l = parseFloat(a.getAttribute("cx") || "0"), u = parseFloat(a.getAttribute("cy") || "0"), f = parseFloat(a.getAttribute("r") || "0");
2440
+ f > 0 && t.push(xe(l, u, f));
2441
+ }), r.querySelectorAll("ellipse").forEach((a) => {
2442
+ const l = parseFloat(a.getAttribute("cx") || "0"), u = parseFloat(a.getAttribute("cy") || "0"), f = parseFloat(a.getAttribute("rx") || "0"), c = parseFloat(a.getAttribute("ry") || "0");
2443
+ f > 0 && c > 0 && t.push(Te(l, u, f, c));
2395
2444
  }), t;
2396
2445
  }
2397
- function vt(n) {
2398
- const t = [], e = n.trim().split(/[\s,]+/);
2446
+ function vt(r) {
2447
+ const t = [], e = r.trim().split(/[\s,]+/);
2399
2448
  for (let i = 0; i < e.length - 1; i += 2) {
2400
- const r = parseFloat(e[i]), o = parseFloat(e[i + 1]);
2401
- Number.isFinite(r) && Number.isFinite(o) && t.push(r, o);
2449
+ const o = parseFloat(e[i]), n = parseFloat(e[i + 1]);
2450
+ Number.isFinite(o) && Number.isFinite(n) && t.push(o, n);
2402
2451
  }
2403
2452
  return t;
2404
2453
  }
2405
- function ve(n, t, e, i = 64) {
2406
- const r = [];
2407
- for (let o = 0; o < i; o++) {
2408
- const s = 2 * Math.PI * o / i;
2409
- r.push(n + e * Math.cos(s), t + e * Math.sin(s));
2410
- }
2411
- return r;
2412
- }
2413
- function xe(n, t, e, i, r = 64) {
2454
+ function xe(r, t, e, i = 64) {
2414
2455
  const o = [];
2415
- for (let s = 0; s < r; s++) {
2416
- const a = 2 * Math.PI * s / r;
2417
- o.push(n + e * Math.cos(a), t + i * Math.sin(a));
2456
+ for (let n = 0; n < i; n++) {
2457
+ const s = 2 * Math.PI * n / i;
2458
+ o.push(r + e * Math.cos(s), t + e * Math.sin(s));
2418
2459
  }
2419
2460
  return o;
2420
2461
  }
2421
- function Te(n) {
2462
+ function Te(r, t, e, i, o = 64) {
2463
+ const n = [];
2464
+ for (let s = 0; s < o; s++) {
2465
+ const h = 2 * Math.PI * s / o;
2466
+ n.push(r + e * Math.cos(h), t + i * Math.sin(h));
2467
+ }
2468
+ return n;
2469
+ }
2470
+ function Ee(r) {
2422
2471
  const t = [];
2423
- let e = [], i = 0, r = 0, o = 0, s = 0, a = 0, h = 0, l = "";
2424
- const u = Ee(n);
2472
+ let e = [], i = 0, o = 0, n = 0, s = 0, h = 0, a = 0, l = "";
2473
+ const u = be(r);
2425
2474
  let f = 0;
2426
2475
  function c() {
2427
2476
  return f >= u.length ? 0 : parseFloat(u[f++]);
2428
2477
  }
2429
2478
  for (; f < u.length; ) {
2430
- const d = u[f];
2431
- let m;
2432
- /^[a-zA-Z]$/.test(d) ? (m = d, f++) : m = l === "M" ? "L" : l === "m" ? "l" : l;
2433
- const g = m === m.toLowerCase();
2434
- switch (m.toUpperCase()) {
2479
+ const g = u[f];
2480
+ let d;
2481
+ /^[a-zA-Z]$/.test(g) ? (d = g, f++) : d = l === "M" ? "L" : l === "m" ? "l" : l;
2482
+ const m = d === d.toLowerCase();
2483
+ switch (d.toUpperCase()) {
2435
2484
  case "M": {
2436
2485
  e.length > 0 && t.push(e), e = [];
2437
- const b = c() + (g ? i : 0), E = c() + (g ? r : 0);
2438
- i = b, r = E, o = b, s = E, e.push(i, r), a = i, h = r;
2486
+ const b = c() + (m ? i : 0), E = c() + (m ? o : 0);
2487
+ i = b, o = E, n = b, s = E, e.push(i, o), h = i, a = o;
2439
2488
  break;
2440
2489
  }
2441
2490
  case "L": {
2442
- i = c() + (g ? i : 0), r = c() + (g ? r : 0), e.push(i, r), a = i, h = r;
2491
+ i = c() + (m ? i : 0), o = c() + (m ? o : 0), e.push(i, o), h = i, a = o;
2443
2492
  break;
2444
2493
  }
2445
2494
  case "H": {
2446
- i = c() + (g ? i : 0), e.push(i, r), a = i, h = r;
2495
+ i = c() + (m ? i : 0), e.push(i, o), h = i, a = o;
2447
2496
  break;
2448
2497
  }
2449
2498
  case "V": {
2450
- r = c() + (g ? r : 0), e.push(i, r), a = i, h = r;
2499
+ o = c() + (m ? o : 0), e.push(i, o), h = i, a = o;
2451
2500
  break;
2452
2501
  }
2453
2502
  case "C": {
2454
- const b = c() + (g ? i : 0), E = c() + (g ? r : 0), p = c() + (g ? i : 0), v = c() + (g ? r : 0), T = c() + (g ? i : 0), x = c() + (g ? r : 0);
2455
- J(e, i, r, b, E, p, v, T, x), i = T, r = x, a = p, h = v;
2503
+ const b = c() + (m ? i : 0), E = c() + (m ? o : 0), p = c() + (m ? i : 0), v = c() + (m ? o : 0), T = c() + (m ? i : 0), x = c() + (m ? o : 0);
2504
+ J(e, i, o, b, E, p, v, T, x), i = T, o = x, h = p, a = v;
2456
2505
  break;
2457
2506
  }
2458
2507
  case "S": {
2459
- const b = 2 * i - a, E = 2 * r - h, p = c() + (g ? i : 0), v = c() + (g ? r : 0), T = c() + (g ? i : 0), x = c() + (g ? r : 0);
2460
- J(e, i, r, b, E, p, v, T, x), i = T, r = x, a = p, h = v;
2508
+ const b = 2 * i - h, E = 2 * o - a, p = c() + (m ? i : 0), v = c() + (m ? o : 0), T = c() + (m ? i : 0), x = c() + (m ? o : 0);
2509
+ J(e, i, o, b, E, p, v, T, x), i = T, o = x, h = p, a = v;
2461
2510
  break;
2462
2511
  }
2463
2512
  case "Q": {
2464
- const b = c() + (g ? i : 0), E = c() + (g ? r : 0), p = c() + (g ? i : 0), v = c() + (g ? r : 0);
2465
- xt(e, i, r, b, E, p, v), i = p, r = v, a = b, h = E;
2513
+ const b = c() + (m ? i : 0), E = c() + (m ? o : 0), p = c() + (m ? i : 0), v = c() + (m ? o : 0);
2514
+ xt(e, i, o, b, E, p, v), i = p, o = v, h = b, a = E;
2466
2515
  break;
2467
2516
  }
2468
2517
  case "T": {
2469
- const b = 2 * i - a, E = 2 * r - h, p = c() + (g ? i : 0), v = c() + (g ? r : 0);
2470
- xt(e, i, r, b, E, p, v), i = p, r = v, a = b, h = E;
2518
+ const b = 2 * i - h, E = 2 * o - a, p = c() + (m ? i : 0), v = c() + (m ? o : 0);
2519
+ xt(e, i, o, b, E, p, v), i = p, o = v, h = b, a = E;
2471
2520
  break;
2472
2521
  }
2473
2522
  case "A": {
2474
- const b = c(), E = c(), p = c(), v = c(), T = c(), x = c() + (g ? i : 0), y = c() + (g ? r : 0);
2475
- Ae(e, i, r, b, E, p, !!v, !!T, x, y), i = x, r = y, a = i, h = r;
2523
+ const b = c(), E = c(), p = c(), v = c(), T = c(), x = c() + (m ? i : 0), A = c() + (m ? o : 0);
2524
+ Ae(e, i, o, b, E, p, !!v, !!T, x, A), i = x, o = A, h = i, a = o;
2476
2525
  break;
2477
2526
  }
2478
2527
  case "Z": {
2479
- i = o, r = s, e.length > 0 && t.push(e), e = [], a = i, h = r;
2528
+ i = n, o = s, e.length > 0 && t.push(e), e = [], h = i, a = o;
2480
2529
  break;
2481
2530
  }
2482
2531
  default:
2483
2532
  f++;
2484
2533
  break;
2485
2534
  }
2486
- l = m;
2535
+ l = d;
2487
2536
  }
2488
2537
  return e.length >= 6 && t.push(e), t;
2489
2538
  }
2490
- function Ee(n) {
2539
+ function be(r) {
2491
2540
  const t = [], e = /([a-zA-Z])|([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/g;
2492
2541
  let i;
2493
- for (; (i = e.exec(n)) !== null; )
2542
+ for (; (i = e.exec(r)) !== null; )
2494
2543
  t.push(i[0]);
2495
2544
  return t;
2496
2545
  }
2497
- const be = 0.5;
2498
- function J(n, t, e, i, r, o, s, a, h, l = 0) {
2546
+ const ye = 0.5;
2547
+ function J(r, t, e, i, o, n, s, h, a, l = 0) {
2499
2548
  if (l > 12) {
2500
- n.push(a, h);
2549
+ r.push(h, a);
2501
2550
  return;
2502
2551
  }
2503
- const u = a - t, f = h - e, c = Math.sqrt(u * u + f * f);
2552
+ const u = h - t, f = a - e, c = Math.sqrt(u * u + f * f);
2504
2553
  if (c < 1e-6) {
2505
- n.push(a, h);
2554
+ r.push(h, a);
2506
2555
  return;
2507
2556
  }
2508
- const d = Math.abs((i - a) * f - (r - h) * u) / c, m = Math.abs((o - a) * f - (s - h) * u) / c;
2509
- if (d + m < be) {
2510
- n.push(a, h);
2557
+ const g = Math.abs((i - h) * f - (o - a) * u) / c, d = Math.abs((n - h) * f - (s - a) * u) / c;
2558
+ if (g + d < ye) {
2559
+ r.push(h, a);
2511
2560
  return;
2512
2561
  }
2513
- const g = (t + i) / 2, U = (e + r) / 2, b = (i + o) / 2, E = (r + s) / 2, p = (o + a) / 2, v = (s + h) / 2, T = (g + b) / 2, x = (U + E) / 2, y = (b + p) / 2, S = (E + v) / 2, F = (T + y) / 2, P = (x + S) / 2;
2514
- J(n, t, e, g, U, T, x, F, P, l + 1), J(n, F, P, y, S, p, v, a, h, l + 1);
2562
+ const m = (t + i) / 2, U = (e + o) / 2, b = (i + n) / 2, E = (o + s) / 2, p = (n + h) / 2, v = (s + a) / 2, T = (m + b) / 2, x = (U + E) / 2, A = (b + p) / 2, S = (E + v) / 2, D = (T + A) / 2, P = (x + S) / 2;
2563
+ J(r, t, e, m, U, T, x, D, P, l + 1), J(r, D, P, A, S, p, v, h, a, l + 1);
2515
2564
  }
2516
- function xt(n, t, e, i, r, o, s) {
2517
- const a = t + 0.6666666666666666 * (i - t), h = e + 2 / 3 * (r - e), l = o + 2 / 3 * (i - o), u = s + 2 / 3 * (r - s);
2518
- J(n, t, e, a, h, l, u, o, s);
2565
+ function xt(r, t, e, i, o, n, s) {
2566
+ const h = t + 0.6666666666666666 * (i - t), a = e + 2 / 3 * (o - e), l = n + 2 / 3 * (i - n), u = s + 2 / 3 * (o - s);
2567
+ J(r, t, e, h, a, l, u, n, s);
2519
2568
  }
2520
- function Ae(n, t, e, i, r, o, s, a, h, l) {
2521
- if (i === 0 || r === 0) {
2522
- n.push(h, l);
2569
+ function Ae(r, t, e, i, o, n, s, h, a, l) {
2570
+ if (i === 0 || o === 0) {
2571
+ r.push(a, l);
2523
2572
  return;
2524
2573
  }
2525
- let u = Math.abs(i), f = Math.abs(r);
2526
- const c = o * Math.PI / 180, d = Math.cos(c), m = Math.sin(c), g = (t - h) / 2, U = (e - l) / 2, b = d * g + m * U, E = -m * g + d * U;
2574
+ let u = Math.abs(i), f = Math.abs(o);
2575
+ const c = n * Math.PI / 180, g = Math.cos(c), d = Math.sin(c), m = (t - a) / 2, U = (e - l) / 2, b = g * m + d * U, E = -d * m + g * U;
2527
2576
  let p = b * b / (u * u) + E * E / (f * f);
2528
2577
  if (p > 1) {
2529
2578
  const M = Math.sqrt(p);
2530
2579
  u *= M, f *= M, p = 1;
2531
2580
  }
2532
- const v = u * u, T = f * f, x = b * b, y = E * E;
2533
- let S = Math.max(0, (v * T - v * y - T * x) / (v * y + T * x));
2534
- S = Math.sqrt(S), s === a && (S = -S);
2535
- const F = S * (u * E) / f, P = S * -(f * b) / u, _ = d * F - m * P + (t + h) / 2, k = m * F + d * P + (e + l) / 2, D = Tt(1, 0, (b - F) / u, (E - P) / f);
2581
+ const v = u * u, T = f * f, x = b * b, A = E * E;
2582
+ let S = Math.max(0, (v * T - v * A - T * x) / (v * A + T * x));
2583
+ S = Math.sqrt(S), s === h && (S = -S);
2584
+ const D = S * (u * E) / f, P = S * -(f * b) / u, _ = g * D - d * P + (t + a) / 2, k = d * D + g * P + (e + l) / 2, F = Tt(1, 0, (b - D) / u, (E - P) / f);
2536
2585
  let R = Tt(
2537
- (b - F) / u,
2586
+ (b - D) / u,
2538
2587
  (E - P) / f,
2539
- (-b - F) / u,
2588
+ (-b - D) / u,
2540
2589
  (-E - P) / f
2541
2590
  );
2542
- !a && R > 0 && (R -= 2 * Math.PI), a && R < 0 && (R += 2 * Math.PI);
2591
+ !h && R > 0 && (R -= 2 * Math.PI), h && R < 0 && (R += 2 * Math.PI);
2543
2592
  const C = Math.max(4, Math.ceil(Math.abs(R) / (Math.PI / 16)));
2544
2593
  for (let M = 1; M <= C; M++) {
2545
- const H = D + M / C * R, I = Math.cos(H), N = Math.sin(H), j = d * u * I - m * f * N + _, et = m * u * I + d * f * N + k;
2546
- n.push(j, et);
2594
+ const B = F + M / C * R, I = Math.cos(B), N = Math.sin(B), j = g * u * I - d * f * N + _, et = d * u * I + g * f * N + k;
2595
+ r.push(j, et);
2547
2596
  }
2548
2597
  }
2549
- function Tt(n, t, e, i) {
2550
- const r = n * i - t * e < 0 ? -1 : 1, o = n * e + t * i, s = Math.sqrt(n * n + t * t), a = Math.sqrt(e * e + i * i), h = o / (s * a);
2551
- return r * Math.acos(Math.max(-1, Math.min(1, h)));
2598
+ function Tt(r, t, e, i) {
2599
+ const o = r * i - t * e < 0 ? -1 : 1, n = r * e + t * i, s = Math.sqrt(r * r + t * t), h = Math.sqrt(e * e + i * i), a = n / (s * h);
2600
+ return o * Math.acos(Math.max(-1, Math.min(1, a)));
2552
2601
  }
2553
- function ye(n) {
2602
+ function Se(r) {
2554
2603
  const t = [], e = [];
2555
- for (let i = 0; i < n.length; i++) {
2604
+ for (let i = 0; i < r.length; i++) {
2556
2605
  i > 0 && e.push(t.length / 2);
2557
- for (const r of n[i])
2558
- t.push(r);
2606
+ for (const o of r[i])
2607
+ t.push(o);
2559
2608
  }
2560
2609
  return { flatCoords: t, holeIndices: e };
2561
2610
  }
2562
- function St(n) {
2563
- const t = n.length, e = n.map((r) => Math.abs(Rt(r))), i = new Array(t).fill(!1);
2564
- for (let r = 0; r < t; r++) {
2565
- let o = 0;
2566
- const s = n[r][0], a = n[r][1];
2567
- for (let h = 0; h < t; h++)
2568
- r !== h && e[h] > e[r] && Dt(s, a, n[h]) && o++;
2569
- i[r] = o % 2 === 1;
2611
+ function Rt(r) {
2612
+ const t = r.length, e = r.map((o) => Math.abs(Ft(o))), i = new Array(t).fill(!1);
2613
+ for (let o = 0; o < t; o++) {
2614
+ let n = 0;
2615
+ const s = r[o][0], h = r[o][1];
2616
+ for (let a = 0; a < t; a++)
2617
+ o !== a && e[a] > e[o] && Dt(s, h, r[a]) && n++;
2618
+ i[o] = n % 2 === 1;
2570
2619
  }
2571
2620
  return i;
2572
2621
  }
2573
- function Se(n) {
2574
- if (n.length <= 1)
2575
- return [n];
2576
- const t = St(n), e = n.map((s, a) => {
2577
- const h = Rt(s);
2578
- return { index: a, contour: s, area: h, isOuter: !t[a] };
2579
- }), i = e.filter((s) => s.isOuter), r = e.filter((s) => !s.isOuter);
2622
+ function Re(r) {
2623
+ if (r.length <= 1)
2624
+ return [r];
2625
+ const t = Rt(r), e = r.map((s, h) => {
2626
+ const a = Ft(s);
2627
+ return { index: h, contour: s, area: a, isOuter: !t[h] };
2628
+ }), i = e.filter((s) => s.isOuter), o = e.filter((s) => !s.isOuter);
2580
2629
  if (i.length === 0)
2581
- return n.map((s) => [s]);
2582
- const o = i.map((s) => ({
2630
+ return r.map((s) => [s]);
2631
+ const n = i.map((s) => ({
2583
2632
  outer: s.contour,
2584
2633
  holes: []
2585
2634
  }));
2586
- for (const s of r) {
2587
- const a = s.contour[0], h = s.contour[1];
2635
+ for (const s of o) {
2636
+ const h = s.contour[0], a = s.contour[1];
2588
2637
  let l = -1, u = 1 / 0;
2589
2638
  for (let f = 0; f < i.length; f++)
2590
- if (Dt(a, h, i[f].contour)) {
2639
+ if (Dt(h, a, i[f].contour)) {
2591
2640
  const c = Math.abs(i[f].area);
2592
2641
  c < u && (u = c, l = f);
2593
2642
  }
2594
- l >= 0 ? o[l].holes.push(s.contour) : o.push({ outer: s.contour, holes: [] });
2643
+ l >= 0 ? n[l].holes.push(s.contour) : n.push({ outer: s.contour, holes: [] });
2595
2644
  }
2596
- return o.map((s) => [s.outer, ...s.holes]);
2645
+ return n.map((s) => [s.outer, ...s.holes]);
2597
2646
  }
2598
- function Rt(n) {
2647
+ function Ft(r) {
2599
2648
  let t = 0;
2600
- const e = n.length;
2649
+ const e = r.length;
2601
2650
  for (let i = 0; i < e; i += 2) {
2602
- const r = n[i], o = n[i + 1], s = n[(i + 2) % e], a = n[(i + 3) % e];
2603
- t += r * a - s * o;
2651
+ const o = r[i], n = r[i + 1], s = r[(i + 2) % e], h = r[(i + 3) % e];
2652
+ t += o * h - s * n;
2604
2653
  }
2605
2654
  return t / 2;
2606
2655
  }
2607
- function Dt(n, t, e) {
2656
+ function Dt(r, t, e) {
2608
2657
  let i = !1;
2609
- const r = e.length;
2610
- for (let o = 0, s = r - 2; o < r; s = o, o += 2) {
2611
- const a = e[o], h = e[o + 1], l = e[s], u = e[s + 1];
2612
- h > t != u > t && n < (l - a) * (t - h) / (u - h) + a && (i = !i);
2658
+ const o = e.length;
2659
+ for (let n = 0, s = o - 2; n < o; s = n, n += 2) {
2660
+ const h = e[n], a = e[n + 1], l = e[s], u = e[s + 1];
2661
+ a > t != u > t && r < (l - h) * (t - a) / (u - a) + h && (i = !i);
2613
2662
  }
2614
2663
  return i;
2615
2664
  }
2616
- function Re(n, t, e = 2) {
2617
- const i = t && t.length > 0, r = i ? t[0] * e : n.length;
2618
- let o = Ft(n, 0, r, e, !0);
2665
+ function Fe(r, t, e = 2) {
2666
+ const i = t && t.length > 0, o = i ? t[0] * e : r.length;
2667
+ let n = Ut(r, 0, o, e, !0);
2619
2668
  const s = [];
2620
- if (!o || o.next === o.prev) return s;
2621
- i && (o = we(n, t, o, e));
2622
- let a = 1 / 0, h = 1 / 0, l = -1 / 0, u = -1 / 0, f = 0;
2623
- if (n.length > 80 * e) {
2624
- for (let c = 0; c < r; c += e) {
2625
- const d = n[c], m = n[c + 1];
2626
- d < a && (a = d), m < h && (h = m), d > l && (l = d), m > u && (u = m);
2669
+ if (!n || n.next === n.prev) return s;
2670
+ i && (n = Le(r, t, n, e));
2671
+ let h = 1 / 0, a = 1 / 0, l = -1 / 0, u = -1 / 0, f = 0;
2672
+ if (r.length > 80 * e) {
2673
+ for (let c = 0; c < o; c += e) {
2674
+ const g = r[c], d = r[c + 1];
2675
+ g < h && (h = g), d < a && (a = d), g > l && (l = g), d > u && (u = d);
2627
2676
  }
2628
- f = Math.max(l - a, u - h), f = f !== 0 ? 32767 / f : 0;
2677
+ f = Math.max(l - h, u - a), f = f !== 0 ? 32767 / f : 0;
2629
2678
  }
2630
- return K(o, s, e, a, h, f, 0), s;
2679
+ return K(n, s, e, h, a, f, 0), s;
2631
2680
  }
2632
- function Ft(n, t, e, i, r) {
2633
- let o = null;
2634
- if (r === Be(n, t, e, i) > 0)
2681
+ function Ut(r, t, e, i, o) {
2682
+ let n = null;
2683
+ if (o === Xe(r, t, e, i) > 0)
2635
2684
  for (let s = t; s < e; s += i)
2636
- o = Et(s, n[s], n[s + 1], o);
2685
+ n = Et(s, r[s], r[s + 1], n);
2637
2686
  else
2638
2687
  for (let s = e - i; s >= t; s -= i)
2639
- o = Et(s, n[s], n[s + 1], o);
2640
- return o && at(o, o.next) && (tt(o), o = o.next), o ? (o.next.prev = o, o.prev.next = o, o.next) : null;
2688
+ n = Et(s, r[s], r[s + 1], n);
2689
+ return n && at(n, n.next) && (tt(n), n = n.next), n ? (n.next.prev = n, n.prev.next = n, n.next) : null;
2641
2690
  }
2642
- function X(n, t) {
2643
- t || (t = n);
2644
- let e = n, i;
2691
+ function X(r, t) {
2692
+ t || (t = r);
2693
+ let e = r, i;
2645
2694
  do
2646
2695
  if (i = !1, !e.steiner && (at(e, e.next) || w(e.prev, e, e.next) === 0)) {
2647
2696
  if (tt(e), e = t = e.prev, e === e.next) break;
@@ -2651,215 +2700,215 @@ function X(n, t) {
2651
2700
  while (i || e !== t);
2652
2701
  return t;
2653
2702
  }
2654
- function K(n, t, e, i, r, o, s) {
2655
- if (!n) return;
2656
- !s && o && _e(n, i, r, o);
2657
- let a = n, h, l;
2658
- for (; n.prev !== n.next; ) {
2659
- if (h = n.prev, l = n.next, o ? Fe(n, i, r, o) : De(n)) {
2660
- t.push(h.i / e, n.i / e, l.i / e), tt(n), n = l.next, a = l.next;
2703
+ function K(r, t, e, i, o, n, s) {
2704
+ if (!r) return;
2705
+ !s && n && Ie(r, i, o, n);
2706
+ let h = r, a, l;
2707
+ for (; r.prev !== r.next; ) {
2708
+ if (a = r.prev, l = r.next, n ? Ue(r, i, o, n) : De(r)) {
2709
+ t.push(a.i / e, r.i / e, l.i / e), tt(r), r = l.next, h = l.next;
2661
2710
  continue;
2662
2711
  }
2663
- if (n = l, n === a) {
2664
- s ? s === 1 ? (n = Ue(X(n), t, e), K(n, t, e, i, r, o, 2)) : s === 2 && Pe(n, t, e, i, r, o) : K(X(n), t, e, i, r, o, 1);
2712
+ if (r = l, r === h) {
2713
+ s ? s === 1 ? (r = Pe(X(r), t, e), K(r, t, e, i, o, n, 2)) : s === 2 && we(r, t, e, i, o, n) : K(X(r), t, e, i, o, n, 1);
2665
2714
  break;
2666
2715
  }
2667
2716
  }
2668
2717
  }
2669
- function De(n) {
2670
- const t = n.prev, e = n, i = n.next;
2718
+ function De(r) {
2719
+ const t = r.prev, e = r, i = r.next;
2671
2720
  if (w(t, e, i) >= 0) return !1;
2672
- const r = t.x, o = e.x, s = i.x, a = t.y, h = e.y, l = i.y, u = r < o ? r < s ? r : s : o < s ? o : s, f = a < h ? a < l ? a : l : h < l ? h : l, c = r > o ? r > s ? r : s : o > s ? o : s, d = a > h ? a > l ? a : l : h > l ? h : l;
2673
- let m = i.next;
2674
- for (; m !== t; ) {
2675
- if (m.x >= u && m.x <= c && m.y >= f && m.y <= d && G(r, a, o, h, s, l, m.x, m.y) && w(m.prev, m, m.next) >= 0)
2721
+ const o = t.x, n = e.x, s = i.x, h = t.y, a = e.y, l = i.y, u = o < n ? o < s ? o : s : n < s ? n : s, f = h < a ? h < l ? h : l : a < l ? a : l, c = o > n ? o > s ? o : s : n > s ? n : s, g = h > a ? h > l ? h : l : a > l ? a : l;
2722
+ let d = i.next;
2723
+ for (; d !== t; ) {
2724
+ if (d.x >= u && d.x <= c && d.y >= f && d.y <= g && G(o, h, n, a, s, l, d.x, d.y) && w(d.prev, d, d.next) >= 0)
2676
2725
  return !1;
2677
- m = m.next;
2726
+ d = d.next;
2678
2727
  }
2679
2728
  return !0;
2680
2729
  }
2681
- function Fe(n, t, e, i) {
2682
- const r = n.prev, o = n, s = n.next;
2683
- if (w(r, o, s) >= 0) return !1;
2684
- const a = r.x, h = o.x, l = s.x, u = r.y, f = o.y, c = s.y, d = a < h ? a < l ? a : l : h < l ? h : l, m = u < f ? u < c ? u : c : f < c ? f : c, g = a > h ? a > l ? a : l : h > l ? h : l, U = u > f ? u > c ? u : c : f > c ? f : c, b = ct(d, m, t, e, i), E = ct(g, U, t, e, i);
2685
- let p = n.prevZ, v = n.nextZ;
2730
+ function Ue(r, t, e, i) {
2731
+ const o = r.prev, n = r, s = r.next;
2732
+ if (w(o, n, s) >= 0) return !1;
2733
+ const h = o.x, a = n.x, l = s.x, u = o.y, f = n.y, c = s.y, g = h < a ? h < l ? h : l : a < l ? a : l, d = u < f ? u < c ? u : c : f < c ? f : c, m = h > a ? h > l ? h : l : a > l ? a : l, U = u > f ? u > c ? u : c : f > c ? f : c, b = ct(g, d, t, e, i), E = ct(m, U, t, e, i);
2734
+ let p = r.prevZ, v = r.nextZ;
2686
2735
  for (; p && p.z >= b && v && v.z <= E; ) {
2687
- if (p.x >= d && p.x <= g && p.y >= m && p.y <= U && p !== r && p !== s && G(a, u, h, f, l, c, p.x, p.y) && w(p.prev, p, p.next) >= 0 || (p = p.prevZ, v.x >= d && v.x <= g && v.y >= m && v.y <= U && v !== r && v !== s && G(a, u, h, f, l, c, v.x, v.y) && w(v.prev, v, v.next) >= 0)) return !1;
2736
+ if (p.x >= g && p.x <= m && p.y >= d && p.y <= U && p !== o && p !== s && G(h, u, a, f, l, c, p.x, p.y) && w(p.prev, p, p.next) >= 0 || (p = p.prevZ, v.x >= g && v.x <= m && v.y >= d && v.y <= U && v !== o && v !== s && G(h, u, a, f, l, c, v.x, v.y) && w(v.prev, v, v.next) >= 0)) return !1;
2688
2737
  v = v.nextZ;
2689
2738
  }
2690
2739
  for (; p && p.z >= b; ) {
2691
- if (p.x >= d && p.x <= g && p.y >= m && p.y <= U && p !== r && p !== s && G(a, u, h, f, l, c, p.x, p.y) && w(p.prev, p, p.next) >= 0) return !1;
2740
+ if (p.x >= g && p.x <= m && p.y >= d && p.y <= U && p !== o && p !== s && G(h, u, a, f, l, c, p.x, p.y) && w(p.prev, p, p.next) >= 0) return !1;
2692
2741
  p = p.prevZ;
2693
2742
  }
2694
2743
  for (; v && v.z <= E; ) {
2695
- if (v.x >= d && v.x <= g && v.y >= m && v.y <= U && v !== r && v !== s && G(a, u, h, f, l, c, v.x, v.y) && w(v.prev, v, v.next) >= 0) return !1;
2744
+ if (v.x >= g && v.x <= m && v.y >= d && v.y <= U && v !== o && v !== s && G(h, u, a, f, l, c, v.x, v.y) && w(v.prev, v, v.next) >= 0) return !1;
2696
2745
  v = v.nextZ;
2697
2746
  }
2698
2747
  return !0;
2699
2748
  }
2700
- function Ue(n, t, e) {
2701
- let i = n;
2749
+ function Pe(r, t, e) {
2750
+ let i = r;
2702
2751
  do {
2703
- const r = i.prev, o = i.next.next;
2704
- !at(r, o) && Ut(r, i, i.next, o) && Q(r, o) && Q(o, r) && (t.push(r.i / e, i.i / e, o.i / e), tt(i), tt(i.next), i = n = o), i = i.next;
2705
- } while (i !== n);
2752
+ const o = i.prev, n = i.next.next;
2753
+ !at(o, n) && Pt(o, i, i.next, n) && Q(o, n) && Q(n, o) && (t.push(o.i / e, i.i / e, n.i / e), tt(i), tt(i.next), i = r = n), i = i.next;
2754
+ } while (i !== r);
2706
2755
  return X(i);
2707
2756
  }
2708
- function Pe(n, t, e, i, r, o) {
2709
- let s = n;
2757
+ function we(r, t, e, i, o, n) {
2758
+ let s = r;
2710
2759
  do {
2711
- let a = s.next.next;
2712
- for (; a !== s.prev; ) {
2713
- if (s.i !== a.i && Oe(s, a)) {
2714
- let h = Pt(s, a);
2715
- s = X(s, s.next), h = X(h, h.next), K(s, t, e, i, r, o, 0), K(h, t, e, i, r, o, 0);
2760
+ let h = s.next.next;
2761
+ for (; h !== s.prev; ) {
2762
+ if (s.i !== h.i && ke(s, h)) {
2763
+ let a = wt(s, h);
2764
+ s = X(s, s.next), a = X(a, a.next), K(s, t, e, i, o, n, 0), K(a, t, e, i, o, n, 0);
2716
2765
  return;
2717
2766
  }
2718
- a = a.next;
2767
+ h = h.next;
2719
2768
  }
2720
2769
  s = s.next;
2721
- } while (s !== n);
2770
+ } while (s !== r);
2722
2771
  }
2723
- function we(n, t, e, i) {
2724
- const r = [];
2725
- for (let o = 0; o < t.length; o++) {
2726
- const s = t[o] * i, a = o < t.length - 1 ? t[o + 1] * i : n.length, h = Ft(n, s, a, i, !1);
2727
- h && (h === h.next && (h.steiner = !0), r.push(Ve(h)));
2772
+ function Le(r, t, e, i) {
2773
+ const o = [];
2774
+ for (let n = 0; n < t.length; n++) {
2775
+ const s = t[n] * i, h = n < t.length - 1 ? t[n + 1] * i : r.length, a = Ut(r, s, h, i, !1);
2776
+ a && (a === a.next && (a.steiner = !0), o.push(Oe(a)));
2728
2777
  }
2729
- r.sort((o, s) => o.x - s.x);
2730
- for (const o of r)
2731
- e = Le(o, e);
2778
+ o.sort((n, s) => n.x - s.x);
2779
+ for (const n of o)
2780
+ e = Ce(n, e);
2732
2781
  return e;
2733
2782
  }
2734
- function Le(n, t) {
2735
- const e = Ce(n, t);
2783
+ function Ce(r, t) {
2784
+ const e = Me(r, t);
2736
2785
  if (!e) return t;
2737
- const i = Pt(e, n);
2786
+ const i = wt(e, r);
2738
2787
  return X(i, i.next), X(e, e.next);
2739
2788
  }
2740
- function Ce(n, t) {
2789
+ function Me(r, t) {
2741
2790
  let e = t;
2742
- const i = n.x, r = n.y;
2743
- let o = -1 / 0, s = null;
2791
+ const i = r.x, o = r.y;
2792
+ let n = -1 / 0, s = null;
2744
2793
  do {
2745
- if (r <= e.y && r >= e.next.y && e.next.y !== e.y) {
2746
- const f = e.x + (r - e.y) / (e.next.y - e.y) * (e.next.x - e.x);
2747
- if (f <= i && f > o && (o = f, s = e.x < e.next.x ? e : e.next, f === i))
2794
+ if (o <= e.y && o >= e.next.y && e.next.y !== e.y) {
2795
+ const f = e.x + (o - e.y) / (e.next.y - e.y) * (e.next.x - e.x);
2796
+ if (f <= i && f > n && (n = f, s = e.x < e.next.x ? e : e.next, f === i))
2748
2797
  return s;
2749
2798
  }
2750
2799
  e = e.next;
2751
2800
  } while (e !== t);
2752
2801
  if (!s) return null;
2753
- const a = s, h = s.x, l = s.y;
2802
+ const h = s, a = s.x, l = s.y;
2754
2803
  let u = 1 / 0;
2755
2804
  e = s;
2756
2805
  do {
2757
- if (i >= e.x && e.x >= h && i !== e.x && G(r < l ? i : o, r, h, l, r < l ? o : i, r, e.x, e.y)) {
2758
- const f = Math.abs(r - e.y) / (i - e.x);
2759
- Q(e, n) && (f < u || f === u && (e.x > s.x || Me(s, e))) && (s = e, u = f);
2806
+ if (i >= e.x && e.x >= a && i !== e.x && G(o < l ? i : n, o, a, l, o < l ? n : i, o, e.x, e.y)) {
2807
+ const f = Math.abs(o - e.y) / (i - e.x);
2808
+ Q(e, r) && (f < u || f === u && (e.x > s.x || _e(s, e))) && (s = e, u = f);
2760
2809
  }
2761
2810
  e = e.next;
2762
- } while (e !== a);
2811
+ } while (e !== h);
2763
2812
  return s;
2764
2813
  }
2765
- function Me(n, t) {
2766
- return w(n.prev, n, t.prev) < 0 && w(t.next, n, n.next) < 0;
2814
+ function _e(r, t) {
2815
+ return w(r.prev, r, t.prev) < 0 && w(t.next, r, r.next) < 0;
2767
2816
  }
2768
- function _e(n, t, e, i) {
2769
- let r = n;
2817
+ function Ie(r, t, e, i) {
2818
+ let o = r;
2770
2819
  do
2771
- r.z === 0 && (r.z = ct(r.x, r.y, t, e, i)), r.prevZ = r.prev, r.nextZ = r.next, r = r.next;
2772
- while (r !== n);
2773
- r.prevZ.nextZ = null, r.prevZ = null, Ie(r);
2820
+ o.z === 0 && (o.z = ct(o.x, o.y, t, e, i)), o.prevZ = o.prev, o.nextZ = o.next, o = o.next;
2821
+ while (o !== r);
2822
+ o.prevZ.nextZ = null, o.prevZ = null, Ve(o);
2774
2823
  }
2775
- function Ie(n) {
2824
+ function Ve(r) {
2776
2825
  let t = 1, e;
2777
2826
  do {
2778
- let i = n;
2779
- n = null;
2780
- let r = null;
2827
+ let i = r;
2828
+ r = null;
2829
+ let o = null;
2781
2830
  for (e = 0; i; ) {
2782
2831
  e++;
2783
- let o = i, s = 0;
2784
- for (let h = 0; h < t && (s++, o = o.nextZ, !!o); h++)
2832
+ let n = i, s = 0;
2833
+ for (let a = 0; a < t && (s++, n = n.nextZ, !!n); a++)
2785
2834
  ;
2786
- let a = t;
2787
- for (; s > 0 || a > 0 && o; ) {
2788
- let h;
2789
- s !== 0 && (a === 0 || !o || i.z <= o.z) ? (h = i, i = i.nextZ, s--) : (h = o, o = o.nextZ, a--), r ? r.nextZ = h : n = h, h.prevZ = r, r = h;
2835
+ let h = t;
2836
+ for (; s > 0 || h > 0 && n; ) {
2837
+ let a;
2838
+ s !== 0 && (h === 0 || !n || i.z <= n.z) ? (a = i, i = i.nextZ, s--) : (a = n, n = n.nextZ, h--), o ? o.nextZ = a : r = a, a.prevZ = o, o = a;
2790
2839
  }
2791
- i = o;
2840
+ i = n;
2792
2841
  }
2793
- r.nextZ = null, t *= 2;
2842
+ o.nextZ = null, t *= 2;
2794
2843
  } while (e > 1);
2795
- return n;
2844
+ return r;
2796
2845
  }
2797
- function ct(n, t, e, i, r) {
2798
- let o = (n - e) * r | 0, s = (t - i) * r | 0;
2799
- return o = (o | o << 8) & 16711935, o = (o | o << 4) & 252645135, o = (o | o << 2) & 858993459, o = (o | o << 1) & 1431655765, s = (s | s << 8) & 16711935, s = (s | s << 4) & 252645135, s = (s | s << 2) & 858993459, s = (s | s << 1) & 1431655765, o | s << 1;
2846
+ function ct(r, t, e, i, o) {
2847
+ let n = (r - e) * o | 0, s = (t - i) * o | 0;
2848
+ return n = (n | n << 8) & 16711935, n = (n | n << 4) & 252645135, n = (n | n << 2) & 858993459, n = (n | n << 1) & 1431655765, s = (s | s << 8) & 16711935, s = (s | s << 4) & 252645135, s = (s | s << 2) & 858993459, s = (s | s << 1) & 1431655765, n | s << 1;
2800
2849
  }
2801
- function Ve(n) {
2802
- let t = n, e = n;
2850
+ function Oe(r) {
2851
+ let t = r, e = r;
2803
2852
  do
2804
2853
  (t.x < e.x || t.x === e.x && t.y < e.y) && (e = t), t = t.next;
2805
- while (t !== n);
2854
+ while (t !== r);
2806
2855
  return e;
2807
2856
  }
2808
- function G(n, t, e, i, r, o, s, a) {
2809
- return (r - s) * (t - a) - (n - s) * (o - a) >= 0 && (n - s) * (i - a) - (e - s) * (t - a) >= 0 && (e - s) * (o - a) - (r - s) * (i - a) >= 0;
2857
+ function G(r, t, e, i, o, n, s, h) {
2858
+ return (o - s) * (t - h) - (r - s) * (n - h) >= 0 && (r - s) * (i - h) - (e - s) * (t - h) >= 0 && (e - s) * (n - h) - (o - s) * (i - h) >= 0;
2810
2859
  }
2811
- function Oe(n, t) {
2812
- return n.next.i !== t.i && n.prev.i !== t.i && !ke(n, t) && (Q(n, t) && Q(t, n) && He(n, t) && (w(n.prev, n, t.prev) !== 0 || w(n, t.prev, t) !== 0) || at(n, t) && w(n.prev, n, n.next) > 0 && w(t.prev, t, t.next) > 0);
2860
+ function ke(r, t) {
2861
+ return r.next.i !== t.i && r.prev.i !== t.i && !Be(r, t) && (Q(r, t) && Q(t, r) && He(r, t) && (w(r.prev, r, t.prev) !== 0 || w(r, t.prev, t) !== 0) || at(r, t) && w(r.prev, r, r.next) > 0 && w(t.prev, t, t.next) > 0);
2813
2862
  }
2814
- function w(n, t, e) {
2815
- return (t.y - n.y) * (e.x - t.x) - (t.x - n.x) * (e.y - t.y);
2863
+ function w(r, t, e) {
2864
+ return (t.y - r.y) * (e.x - t.x) - (t.x - r.x) * (e.y - t.y);
2816
2865
  }
2817
- function at(n, t) {
2818
- return n.x === t.x && n.y === t.y;
2866
+ function at(r, t) {
2867
+ return r.x === t.x && r.y === t.y;
2819
2868
  }
2820
- function Ut(n, t, e, i) {
2821
- const r = ot(w(n, t, e)), o = ot(w(n, t, i)), s = ot(w(e, i, n)), a = ot(w(e, i, t));
2822
- return !!(r !== o && s !== a || r === 0 && rt(n, e, t) || o === 0 && rt(n, i, t) || s === 0 && rt(e, n, i) || a === 0 && rt(e, t, i));
2869
+ function Pt(r, t, e, i) {
2870
+ const o = ot(w(r, t, e)), n = ot(w(r, t, i)), s = ot(w(e, i, r)), h = ot(w(e, i, t));
2871
+ return !!(o !== n && s !== h || o === 0 && rt(r, e, t) || n === 0 && rt(r, i, t) || s === 0 && rt(e, r, i) || h === 0 && rt(e, t, i));
2823
2872
  }
2824
- function rt(n, t, e) {
2825
- return t.x <= Math.max(n.x, e.x) && t.x >= Math.min(n.x, e.x) && t.y <= Math.max(n.y, e.y) && t.y >= Math.min(n.y, e.y);
2873
+ function rt(r, t, e) {
2874
+ return t.x <= Math.max(r.x, e.x) && t.x >= Math.min(r.x, e.x) && t.y <= Math.max(r.y, e.y) && t.y >= Math.min(r.y, e.y);
2826
2875
  }
2827
- function ot(n) {
2828
- return n > 0 ? 1 : n < 0 ? -1 : 0;
2876
+ function ot(r) {
2877
+ return r > 0 ? 1 : r < 0 ? -1 : 0;
2829
2878
  }
2830
- function ke(n, t) {
2831
- let e = n;
2879
+ function Be(r, t) {
2880
+ let e = r;
2832
2881
  do {
2833
- if (e.i !== n.i && e.next.i !== n.i && e.i !== t.i && e.next.i !== t.i && Ut(e, e.next, n, t)) return !0;
2882
+ if (e.i !== r.i && e.next.i !== r.i && e.i !== t.i && e.next.i !== t.i && Pt(e, e.next, r, t)) return !0;
2834
2883
  e = e.next;
2835
- } while (e !== n);
2884
+ } while (e !== r);
2836
2885
  return !1;
2837
2886
  }
2838
- function Q(n, t) {
2839
- return w(n.prev, n, n.next) < 0 ? w(n, t, n.next) >= 0 && w(n, n.prev, t) >= 0 : w(n, t, n.prev) < 0 || w(n, n.next, t) < 0;
2887
+ function Q(r, t) {
2888
+ return w(r.prev, r, r.next) < 0 ? w(r, t, r.next) >= 0 && w(r, r.prev, t) >= 0 : w(r, t, r.prev) < 0 || w(r, r.next, t) < 0;
2840
2889
  }
2841
- function He(n, t) {
2842
- let e = n, i = !1;
2843
- const r = (n.x + t.x) / 2, o = (n.y + t.y) / 2;
2890
+ function He(r, t) {
2891
+ let e = r, i = !1;
2892
+ const o = (r.x + t.x) / 2, n = (r.y + t.y) / 2;
2844
2893
  do
2845
- e.y > o != e.next.y > o && e.next.y !== e.y && r < (e.next.x - e.x) * (o - e.y) / (e.next.y - e.y) + e.x && (i = !i), e = e.next;
2846
- while (e !== n);
2894
+ e.y > n != e.next.y > n && e.next.y !== e.y && o < (e.next.x - e.x) * (n - e.y) / (e.next.y - e.y) + e.x && (i = !i), e = e.next;
2895
+ while (e !== r);
2847
2896
  return i;
2848
2897
  }
2849
- function Pt(n, t) {
2850
- const e = ut(n.i, n.x, n.y), i = ut(t.i, t.x, t.y), r = n.next, o = t.prev;
2851
- return n.next = t, t.prev = n, e.next = r, r.prev = e, i.next = e, e.prev = i, o.next = i, i.prev = o, i;
2898
+ function wt(r, t) {
2899
+ const e = ut(r.i, r.x, r.y), i = ut(t.i, t.x, t.y), o = r.next, n = t.prev;
2900
+ return r.next = t, t.prev = r, e.next = o, o.prev = e, i.next = e, e.prev = i, n.next = i, i.prev = n, i;
2852
2901
  }
2853
- function Et(n, t, e, i) {
2854
- const r = ut(n, t, e);
2855
- return i ? (r.next = i.next, r.prev = i, i.next.prev = r, i.next = r) : (r.prev = r, r.next = r), r;
2902
+ function Et(r, t, e, i) {
2903
+ const o = ut(r, t, e);
2904
+ return i ? (o.next = i.next, o.prev = i, i.next.prev = o, i.next = o) : (o.prev = o, o.next = o), o;
2856
2905
  }
2857
- function tt(n) {
2858
- n.next.prev = n.prev, n.prev.next = n.next, n.prevZ && (n.prevZ.nextZ = n.nextZ), n.nextZ && (n.nextZ.prevZ = n.prevZ);
2906
+ function tt(r) {
2907
+ r.next.prev = r.prev, r.prev.next = r.next, r.prevZ && (r.prevZ.nextZ = r.nextZ), r.nextZ && (r.nextZ.prevZ = r.prevZ);
2859
2908
  }
2860
- function ut(n, t, e) {
2909
+ function ut(r, t, e) {
2861
2910
  return {
2862
- i: n,
2911
+ i: r,
2863
2912
  x: t,
2864
2913
  y: e,
2865
2914
  prev: null,
@@ -2870,13 +2919,13 @@ function ut(n, t, e) {
2870
2919
  steiner: !1
2871
2920
  };
2872
2921
  }
2873
- function Be(n, t, e, i) {
2874
- let r = 0;
2875
- for (let o = t, s = e - i; o < e; o += i)
2876
- r += (n[s] - n[o]) * (n[o + 1] + n[s + 1]), s = o;
2877
- return r;
2922
+ function Xe(r, t, e, i) {
2923
+ let o = 0;
2924
+ for (let n = t, s = e - i; n < e; n += i)
2925
+ o += (r[s] - r[n]) * (r[n + 1] + r[s + 1]), s = n;
2926
+ return o;
2878
2927
  }
2879
- const A = {
2928
+ const y = {
2880
2929
  parallaxX: 0.4,
2881
2930
  parallaxY: 0.8,
2882
2931
  parallaxMax: 30,
@@ -2956,8 +3005,8 @@ class dt {
2956
3005
  this.host.removeEventListener("mousemove", this.handleMouseMove), this.host.removeEventListener("mouseleave", this.resetPointerTarget), this.host.removeEventListener("touchstart", this.handleTouchStart), this.host.removeEventListener("touchmove", this.handleTouchMove), this.host.removeEventListener("touchend", this.handleTouchEnd), this.host.removeEventListener("touchcancel", this.handleTouchEnd), this.motionListenerAttached && (window.removeEventListener("deviceorientation", this.handleDeviceOrientation), this.motionListenerAttached = !1);
2957
3006
  }
2958
3007
  handleMouseMove = (t) => {
2959
- const e = this.host.getBoundingClientRect(), i = (t.clientX - e.left) / e.width * 2 - 1, r = (t.clientY - e.top) / e.height * 2 - 1;
2960
- this.pointerTarget.x = W(i, -1, 1), this.pointerTarget.y = W(r, -1, 1);
3008
+ const e = this.host.getBoundingClientRect(), i = (t.clientX - e.left) / e.width * 2 - 1, o = (t.clientY - e.top) / e.height * 2 - 1;
3009
+ this.pointerTarget.x = W(i, -1, 1), this.pointerTarget.y = W(o, -1, 1);
2961
3010
  };
2962
3011
  resetPointerTarget = () => {
2963
3012
  this.pointerTarget.x = 0, this.pointerTarget.y = 0;
@@ -2969,8 +3018,8 @@ class dt {
2969
3018
  handleTouchMove = (t) => {
2970
3019
  const e = t.touches[0];
2971
3020
  if (!e) return;
2972
- const i = e.clientX - this.touchAnchorX, r = e.clientY - this.touchAnchorY, o = dt.TOUCH_DRAG_RANGE;
2973
- this.pointerTarget.x = W(i / o, -1, 1), this.pointerTarget.y = W(r / o, -1, 1);
3021
+ const i = e.clientX - this.touchAnchorX, o = e.clientY - this.touchAnchorY, n = dt.TOUCH_DRAG_RANGE;
3022
+ this.pointerTarget.x = W(i / n, -1, 1), this.pointerTarget.y = W(o / n, -1, 1);
2974
3023
  };
2975
3024
  handleTouchEnd = () => {
2976
3025
  this.touchActive = !1, this.pointerTarget.x = 0, this.pointerTarget.y = 0;
@@ -3044,6 +3093,7 @@ class lt extends HTMLElement {
3044
3093
  "muted"
3045
3094
  ];
3046
3095
  }
3096
+ reinitAttributes = ["src", "depth-src", "depth-meta", "logo-src"];
3047
3097
  shadow;
3048
3098
  container = null;
3049
3099
  renderer = null;
@@ -3051,18 +3101,17 @@ class lt extends HTMLElement {
3051
3101
  depthWorker = null;
3052
3102
  video = null;
3053
3103
  mesh = null;
3054
- initialized = !1;
3055
- abortController = null;
3056
3104
  loopCount = 0;
3105
+ lifecycle;
3057
3106
  constructor() {
3058
- super(), this.shadow = this.attachShadow({ mode: "open" });
3107
+ super(), this.shadow = this.attachShadow({ mode: "open" }), this.lifecycle = new At(this);
3059
3108
  }
3060
3109
  // --- Attribute helpers ---
3061
3110
  getAttrFloat(t, e) {
3062
3111
  const i = this.getAttribute(t);
3063
3112
  if (i === null) return e;
3064
- const r = parseFloat(i);
3065
- return Number.isFinite(r) ? r : e;
3113
+ const o = parseFloat(i);
3114
+ return Number.isFinite(o) ? o : e;
3066
3115
  }
3067
3116
  getAttrBool(t, e) {
3068
3117
  if (!this.hasAttribute(t)) return e;
@@ -3071,151 +3120,151 @@ class lt extends HTMLElement {
3071
3120
  }
3072
3121
  getAttrColor(t, e) {
3073
3122
  const i = this.getAttribute(t) ?? e;
3074
- return Xe(i);
3123
+ return Ne(i);
3075
3124
  }
3076
3125
  getAttrVec3(t, e) {
3077
- const r = (this.getAttribute(t) ?? e).split(",").map((s) => parseFloat(s.trim()));
3078
- if (r.length >= 3 && r.every(Number.isFinite))
3079
- return [r[0], r[1], r[2]];
3080
- const o = e.split(",").map((s) => parseFloat(s.trim()));
3081
- return [o[0], o[1], o[2]];
3126
+ const o = (this.getAttribute(t) ?? e).split(",").map((s) => parseFloat(s.trim()));
3127
+ if (o.length >= 3 && o.every(Number.isFinite))
3128
+ return [o[0], o[1], o[2]];
3129
+ const n = e.split(",").map((s) => parseFloat(s.trim()));
3130
+ return [n[0], n[1], n[2]];
3082
3131
  }
3083
3132
  get parallaxX() {
3084
- return this.getAttrFloat("parallax-x", A.parallaxX);
3133
+ return this.getAttrFloat("parallax-x", y.parallaxX);
3085
3134
  }
3086
3135
  get parallaxY() {
3087
- return this.getAttrFloat("parallax-y", A.parallaxY);
3136
+ return this.getAttrFloat("parallax-y", y.parallaxY);
3088
3137
  }
3089
3138
  get parallaxMax() {
3090
- return this.getAttrFloat("parallax-max", A.parallaxMax);
3139
+ return this.getAttrFloat("parallax-max", y.parallaxMax);
3091
3140
  }
3092
3141
  get overscan() {
3093
- return this.getAttrFloat("overscan", A.overscan);
3142
+ return this.getAttrFloat("overscan", y.overscan);
3094
3143
  }
3095
3144
  get pomSteps() {
3096
- return this.getAttrFloat("pom-steps", A.pomSteps);
3145
+ return this.getAttrFloat("pom-steps", y.pomSteps);
3097
3146
  }
3098
3147
  // Boundary
3099
3148
  get rimIntensity() {
3100
- return this.getAttrFloat("rim-intensity", A.rimIntensity);
3149
+ return this.getAttrFloat("rim-intensity", y.rimIntensity);
3101
3150
  }
3102
3151
  get rimWidth() {
3103
- return this.getAttrFloat("rim-width", A.rimWidth);
3152
+ return this.getAttrFloat("rim-width", y.rimWidth);
3104
3153
  }
3105
3154
  get rimColor() {
3106
- return this.getAttrColor("rim-color", A.rimColor);
3155
+ return this.getAttrColor("rim-color", y.rimColor);
3107
3156
  }
3108
3157
  get refractionStrength() {
3109
- return this.getAttrFloat("refraction-strength", A.refractionStrength);
3158
+ return this.getAttrFloat("refraction-strength", y.refractionStrength);
3110
3159
  }
3111
3160
  get chromaticStrength() {
3112
- return this.getAttrFloat("chromatic-strength", A.chromaticStrength);
3161
+ return this.getAttrFloat("chromatic-strength", y.chromaticStrength);
3113
3162
  }
3114
3163
  get occlusionIntensity() {
3115
- return this.getAttrFloat("occlusion-intensity", A.occlusionIntensity);
3164
+ return this.getAttrFloat("occlusion-intensity", y.occlusionIntensity);
3116
3165
  }
3117
3166
  // Lens transform
3118
3167
  get depthPower() {
3119
- return this.getAttrFloat("depth-power", A.depthPower);
3168
+ return this.getAttrFloat("depth-power", y.depthPower);
3120
3169
  }
3121
3170
  get depthScale() {
3122
- return this.getAttrFloat("depth-scale", A.depthScale);
3171
+ return this.getAttrFloat("depth-scale", y.depthScale);
3123
3172
  }
3124
3173
  get depthBias() {
3125
- return this.getAttrFloat("depth-bias", A.depthBias);
3174
+ return this.getAttrFloat("depth-bias", y.depthBias);
3126
3175
  }
3127
3176
  // Interior mood
3128
3177
  get fogDensity() {
3129
- return this.getAttrFloat("fog-density", A.fogDensity);
3178
+ return this.getAttrFloat("fog-density", y.fogDensity);
3130
3179
  }
3131
3180
  get fogColor() {
3132
- return this.getAttrColor("fog-color", A.fogColor);
3181
+ return this.getAttrColor("fog-color", y.fogColor);
3133
3182
  }
3134
3183
  get colorShift() {
3135
- return this.getAttrFloat("color-shift", A.colorShift);
3184
+ return this.getAttrFloat("color-shift", y.colorShift);
3136
3185
  }
3137
3186
  get brightnessBias() {
3138
- return this.getAttrFloat("brightness-bias", A.brightnessBias);
3187
+ return this.getAttrFloat("brightness-bias", y.brightnessBias);
3139
3188
  }
3140
3189
  // Depth-adaptive
3141
3190
  get contrastLow() {
3142
- return this.getAttrFloat("contrast-low", A.contrastLow);
3191
+ return this.getAttrFloat("contrast-low", y.contrastLow);
3143
3192
  }
3144
3193
  get contrastHigh() {
3145
- return this.getAttrFloat("contrast-high", A.contrastHigh);
3194
+ return this.getAttrFloat("contrast-high", y.contrastHigh);
3146
3195
  }
3147
3196
  get verticalReduction() {
3148
- return this.getAttrFloat("vertical-reduction", A.verticalReduction);
3197
+ return this.getAttrFloat("vertical-reduction", y.verticalReduction);
3149
3198
  }
3150
3199
  get dofStart() {
3151
- return this.getAttrFloat("dof-start", A.dofStart);
3200
+ return this.getAttrFloat("dof-start", y.dofStart);
3152
3201
  }
3153
3202
  get dofStrength() {
3154
- return this.getAttrFloat("dof-strength", A.dofStrength);
3203
+ return this.getAttrFloat("dof-strength", y.dofStrength);
3155
3204
  }
3156
3205
  // Bevel / dimensional typography
3157
3206
  get bevelIntensity() {
3158
- return this.getAttrFloat("bevel-intensity", A.bevelIntensity);
3207
+ return this.getAttrFloat("bevel-intensity", y.bevelIntensity);
3159
3208
  }
3160
3209
  get bevelWidth() {
3161
- return this.getAttrFloat("bevel-width", A.bevelWidth);
3210
+ return this.getAttrFloat("bevel-width", y.bevelWidth);
3162
3211
  }
3163
3212
  get bevelDarkening() {
3164
- return this.getAttrFloat("bevel-darkening", A.bevelDarkening);
3213
+ return this.getAttrFloat("bevel-darkening", y.bevelDarkening);
3165
3214
  }
3166
3215
  get bevelDesaturation() {
3167
- return this.getAttrFloat("bevel-desaturation", A.bevelDesaturation);
3216
+ return this.getAttrFloat("bevel-desaturation", y.bevelDesaturation);
3168
3217
  }
3169
3218
  get bevelLightAngle() {
3170
- return this.getAttrFloat("bevel-light-angle", A.bevelLightAngle);
3219
+ return this.getAttrFloat("bevel-light-angle", y.bevelLightAngle);
3171
3220
  }
3172
3221
  // Volumetric edge wall
3173
3222
  get edgeThickness() {
3174
- return this.getAttrFloat("edge-thickness", A.edgeThickness);
3223
+ return this.getAttrFloat("edge-thickness", y.edgeThickness);
3175
3224
  }
3176
3225
  get edgeSpecular() {
3177
- return this.getAttrFloat("edge-specular", A.edgeSpecular);
3226
+ return this.getAttrFloat("edge-specular", y.edgeSpecular);
3178
3227
  }
3179
3228
  get edgeColor() {
3180
- return this.getAttrColor("edge-color", A.edgeColor);
3229
+ return this.getAttrColor("edge-color", y.edgeColor);
3181
3230
  }
3182
3231
  // Chamfer geometry
3183
3232
  get chamferWidth() {
3184
- return this.getAttrFloat("chamfer-width", A.chamferWidth);
3233
+ return this.getAttrFloat("chamfer-width", y.chamferWidth);
3185
3234
  }
3186
3235
  get chamferAngle() {
3187
- return this.getAttrFloat("chamfer-angle", A.chamferAngle);
3236
+ return this.getAttrFloat("chamfer-angle", y.chamferAngle);
3188
3237
  }
3189
3238
  get chamferColor() {
3190
- return this.getAttrColor("chamfer-color", A.chamferColor);
3239
+ return this.getAttrColor("chamfer-color", y.chamferColor);
3191
3240
  }
3192
3241
  get chamferAmbient() {
3193
- return this.getAttrFloat("chamfer-ambient", A.chamferAmbient);
3242
+ return this.getAttrFloat("chamfer-ambient", y.chamferAmbient);
3194
3243
  }
3195
3244
  get chamferSpecular() {
3196
- return this.getAttrFloat("chamfer-specular", A.chamferSpecular);
3245
+ return this.getAttrFloat("chamfer-specular", y.chamferSpecular);
3197
3246
  }
3198
3247
  get chamferShininess() {
3199
- return this.getAttrFloat("chamfer-shininess", A.chamferShininess);
3248
+ return this.getAttrFloat("chamfer-shininess", y.chamferShininess);
3200
3249
  }
3201
3250
  // Edge occlusion
3202
3251
  get edgeOcclusionWidth() {
3203
- return this.getAttrFloat("edge-occlusion-width", A.edgeOcclusionWidth);
3252
+ return this.getAttrFloat("edge-occlusion-width", y.edgeOcclusionWidth);
3204
3253
  }
3205
3254
  get edgeOcclusionStrength() {
3206
- return this.getAttrFloat("edge-occlusion-strength", A.edgeOcclusionStrength);
3255
+ return this.getAttrFloat("edge-occlusion-strength", y.edgeOcclusionStrength);
3207
3256
  }
3208
3257
  get lightDirection3() {
3209
- return this.getAttrVec3("light-direction", A.lightDirection);
3258
+ return this.getAttrVec3("light-direction", y.lightDirection);
3210
3259
  }
3211
3260
  get shouldAutoplay() {
3212
- return this.getAttrBool("autoplay", A.autoplay);
3261
+ return this.getAttrBool("autoplay", y.autoplay);
3213
3262
  }
3214
3263
  get shouldLoop() {
3215
- return this.getAttrBool("loop", A.loop);
3264
+ return this.getAttrBool("loop", y.loop);
3216
3265
  }
3217
3266
  get shouldMute() {
3218
- return this.getAttrBool("muted", A.muted);
3267
+ return this.getAttrBool("muted", y.muted);
3219
3268
  }
3220
3269
  // --- Event dispatching ---
3221
3270
  emit(t, e) {
@@ -3242,17 +3291,17 @@ class lt extends HTMLElement {
3242
3291
  }));
3243
3292
  });
3244
3293
  }
3245
- // --- Lifecycle ---
3294
+ // --- Lifecycle (delegated to LifecycleManager) ---
3246
3295
  connectedCallback() {
3247
- this.setupShadowDOM(), this.init();
3296
+ this.lifecycle.onConnected();
3248
3297
  }
3249
3298
  disconnectedCallback() {
3250
- this.dispose();
3299
+ this.lifecycle.onDisconnected();
3251
3300
  }
3252
3301
  attributeChangedCallback(t, e, i) {
3253
- ["src", "depth-src", "depth-meta", "logo-src"].includes(t) && (this.initialized ? (this.dispose(), this.setupShadowDOM(), this.init()) : this.isConnected && this.getAttribute("src") && this.getAttribute("depth-src") && this.getAttribute("depth-meta") && this.getAttribute("logo-src") && this.init());
3302
+ this.lifecycle.onAttributeChanged(t, e, i);
3254
3303
  }
3255
- // --- Shadow DOM ---
3304
+ // --- Shadow DOM setup ---
3256
3305
  setupShadowDOM() {
3257
3306
  this.shadow.innerHTML = "";
3258
3307
  const t = document.createElement("style");
@@ -3279,49 +3328,43 @@ class lt extends HTMLElement {
3279
3328
  `, this.shadow.appendChild(t), this.container = document.createElement("div"), this.container.className = "container", this.shadow.appendChild(this.container);
3280
3329
  }
3281
3330
  // --- Initialization ---
3282
- async init() {
3283
- const t = this.getAttribute("src"), e = this.getAttribute("depth-src"), i = this.getAttribute("depth-meta"), r = this.getAttribute("logo-src");
3284
- if (!t || !e || !i || !r) {
3285
- const o = "src, depth-src, depth-meta, and logo-src attributes are required.";
3286
- console.warn(`<layershift-portal>: ${o}`), this.emit("layershift-portal:error", { message: o });
3287
- return;
3288
- }
3289
- if (this.container) {
3290
- this.abortController = new AbortController();
3331
+ async doInit(t) {
3332
+ const e = this.getAttribute("src"), i = this.getAttribute("depth-src"), o = this.getAttribute("depth-meta"), n = this.getAttribute("logo-src");
3333
+ if (this.container)
3291
3334
  try {
3292
- const [o, s, a] = await Promise.all([
3293
- this.createVideoElement(t),
3294
- At(e, i),
3295
- me(r)
3335
+ const [s, h, a] = await Promise.all([
3336
+ this.createVideoElement(e),
3337
+ yt(i, o),
3338
+ pe(n)
3296
3339
  ]);
3297
- if (this.abortController.signal.aborted) {
3298
- o.remove();
3340
+ if (t.aborted) {
3341
+ s.remove();
3299
3342
  return;
3300
3343
  }
3301
- this.video = o, this.mesh = a, this.loopCount = 0, this.attachVideoEventListeners(o);
3302
- const h = this.parallaxMax / Math.max(o.videoWidth, 1);
3303
- let l;
3344
+ this.video = s, this.mesh = a, this.loopCount = 0, this.attachVideoEventListeners(s);
3345
+ const l = this.parallaxMax / Math.max(s.videoWidth, 1);
3346
+ let u;
3304
3347
  try {
3305
3348
  const d = await st.create(
3306
- s,
3307
- s.meta.width,
3308
- s.meta.height
3349
+ h,
3350
+ h.meta.width,
3351
+ h.meta.height
3309
3352
  );
3310
- this.depthWorker = d, l = (m) => d.sample(m);
3353
+ this.depthWorker = d, u = (m) => d.sample(m);
3311
3354
  } catch {
3312
3355
  const d = new bt(
3313
- s,
3314
- s.meta.width,
3315
- s.meta.height
3356
+ h,
3357
+ h.meta.width,
3358
+ h.meta.height
3316
3359
  );
3317
- l = (m) => d.sample(m);
3360
+ u = (m) => d.sample(m);
3318
3361
  }
3319
- if (this.abortController.signal.aborted) {
3320
- o.remove(), this.depthWorker?.dispose(), this.depthWorker = null;
3362
+ if (t.aborted) {
3363
+ s.remove(), this.depthWorker?.dispose(), this.depthWorker = null;
3321
3364
  return;
3322
3365
  }
3323
- const u = {
3324
- parallaxStrength: h,
3366
+ const f = {
3367
+ parallaxStrength: l,
3325
3368
  overscanPadding: this.overscan,
3326
3369
  pomSteps: this.pomSteps,
3327
3370
  // Boundary
@@ -3368,14 +3411,15 @@ class lt extends HTMLElement {
3368
3411
  edgeOcclusionStrength: this.edgeOcclusionStrength,
3369
3412
  lightDirection: this.lightDirection3
3370
3413
  };
3371
- this.renderer = new ft(this.container, u), this.renderer.initialize(o, s.meta.width, s.meta.height, a), this.inputHandler = new dt(this);
3372
- const f = this.parallaxX, c = this.parallaxY;
3414
+ this.renderer = new ft(this.container, f), this.renderer.initialize(s, h.meta.width, h.meta.height, a), this.inputHandler = new dt(this);
3415
+ const c = this.parallaxX, g = this.parallaxY;
3373
3416
  if (this.renderer.start(
3374
- o,
3375
- l,
3417
+ s,
3418
+ u,
3376
3419
  () => {
3420
+ if (!this.inputHandler) return { x: 0, y: 0 };
3377
3421
  const d = this.inputHandler.update();
3378
- return { x: d.x * f, y: d.y * c };
3422
+ return { x: d.x * c, y: d.y * g };
3379
3423
  },
3380
3424
  (d, m) => {
3381
3425
  this.emit("layershift-portal:frame", {
@@ -3384,61 +3428,61 @@ class lt extends HTMLElement {
3384
3428
  });
3385
3429
  }
3386
3430
  ), this.shouldAutoplay) {
3387
- o.currentTime = 0;
3431
+ s.currentTime = 0;
3388
3432
  try {
3389
- await o.play();
3433
+ await s.play();
3390
3434
  } catch {
3391
3435
  }
3392
3436
  }
3393
- this.initialized = !0, this.emit("layershift-portal:ready", {
3394
- videoWidth: o.videoWidth,
3395
- videoHeight: o.videoHeight,
3396
- duration: o.duration
3437
+ if (t.aborted) return;
3438
+ this.lifecycle.markInitialized(), this.emit("layershift-portal:ready", {
3439
+ videoWidth: s.videoWidth,
3440
+ videoHeight: s.videoHeight,
3441
+ duration: s.duration
3397
3442
  });
3398
- } catch (o) {
3399
- const s = o instanceof Error ? o.message : "Failed to initialize.";
3400
- console.error("<layershift-portal>: Failed to initialize.", o), this.emit("layershift-portal:error", { message: s });
3443
+ } catch (s) {
3444
+ const h = s instanceof Error ? s.message : "Failed to initialize.";
3445
+ console.error("<layershift-portal>: Failed to initialize.", s), this.emit("layershift-portal:error", { message: h });
3401
3446
  }
3402
- }
3403
3447
  }
3404
3448
  // --- Video element ---
3405
3449
  async createVideoElement(t) {
3406
3450
  const e = document.createElement("video");
3407
- return e.crossOrigin = "anonymous", e.setAttribute("crossorigin", "anonymous"), e.playsInline = !0, e.setAttribute("playsinline", ""), e.setAttribute("webkit-playsinline", "true"), e.muted = this.shouldMute, e.defaultMuted = this.shouldMute, this.shouldMute && e.setAttribute("muted", ""), e.loop = this.shouldLoop, e.preload = "auto", e.style.display = "none", e.src = t, this.shadow.appendChild(e), await new Promise((i, r) => {
3451
+ return e.crossOrigin = "anonymous", e.setAttribute("crossorigin", "anonymous"), e.playsInline = !0, e.setAttribute("playsinline", ""), e.setAttribute("webkit-playsinline", "true"), e.muted = this.shouldMute, e.defaultMuted = this.shouldMute, this.shouldMute && e.setAttribute("muted", ""), e.loop = this.shouldLoop, e.preload = "auto", e.style.display = "none", e.src = t, this.shadow.appendChild(e), await new Promise((i, o) => {
3408
3452
  if (e.readyState >= HTMLMediaElement.HAVE_METADATA) {
3409
3453
  i();
3410
3454
  return;
3411
3455
  }
3412
- const o = () => {
3413
- a(), i();
3456
+ const n = () => {
3457
+ h(), i();
3414
3458
  }, s = () => {
3415
- a(), r(new Error("Failed to load video metadata."));
3416
- }, a = () => {
3417
- e.removeEventListener("loadedmetadata", o), e.removeEventListener("error", s);
3459
+ h(), o(new Error("Failed to load video metadata."));
3460
+ }, h = () => {
3461
+ e.removeEventListener("loadedmetadata", n), e.removeEventListener("error", s);
3418
3462
  };
3419
- e.addEventListener("loadedmetadata", o), e.addEventListener("error", s), e.load();
3463
+ e.addEventListener("loadedmetadata", n), e.addEventListener("error", s), e.load();
3420
3464
  }), e;
3421
3465
  }
3422
3466
  // --- Cleanup ---
3423
- dispose() {
3424
- this.abortController?.abort(), this.abortController = null, this.renderer?.dispose(), this.renderer = null, this.inputHandler?.dispose(), this.inputHandler = null, this.depthWorker?.dispose(), this.depthWorker = null, this.video && (this.video.pause(), this.video.removeAttribute("src"), this.video.load(), this.video.remove(), this.video = null), this.mesh = null, this.initialized = !1, this.loopCount = 0, this.container = null;
3467
+ doDispose() {
3468
+ this.renderer?.dispose(), this.renderer = null, this.inputHandler?.dispose(), this.inputHandler = null, this.depthWorker?.dispose(), this.depthWorker = null, this.video && (this.video.pause(), this.video.removeAttribute("src"), this.video.load(), this.video.remove(), this.video = null), this.mesh = null, this.loopCount = 0, this.container = null;
3425
3469
  }
3426
3470
  }
3427
- function W(n, t, e) {
3428
- return Math.min(e, Math.max(t, n));
3471
+ function W(r, t, e) {
3472
+ return Math.min(e, Math.max(t, r));
3429
3473
  }
3430
- function nt(n, t, e) {
3431
- return n + (t - n) * e;
3474
+ function nt(r, t, e) {
3475
+ return r + (t - r) * e;
3432
3476
  }
3433
- function Xe(n) {
3434
- const t = n.replace("#", "");
3477
+ function Ne(r) {
3478
+ const t = r.replace("#", "");
3435
3479
  if (t.length === 3) {
3436
- const e = parseInt(t[0] + t[0], 16) / 255, i = parseInt(t[1] + t[1], 16) / 255, r = parseInt(t[2] + t[2], 16) / 255;
3437
- return [e, i, r];
3480
+ const e = parseInt(t[0] + t[0], 16) / 255, i = parseInt(t[1] + t[1], 16) / 255, o = parseInt(t[2] + t[2], 16) / 255;
3481
+ return [e, i, o];
3438
3482
  }
3439
3483
  if (t.length === 6) {
3440
- const e = parseInt(t.substring(0, 2), 16) / 255, i = parseInt(t.substring(2, 4), 16) / 255, r = parseInt(t.substring(4, 6), 16) / 255;
3441
- return [e, i, r];
3484
+ const e = parseInt(t.substring(0, 2), 16) / 255, i = parseInt(t.substring(2, 4), 16) / 255, o = parseInt(t.substring(4, 6), 16) / 255;
3485
+ return [e, i, o];
3442
3486
  }
3443
3487
  return [0, 0, 0];
3444
3488
  }