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.
- package/dist/components/layershift.js +28 -28
- package/dist/npm/layershift.es.js +895 -851
- package/dist/types/components/layershift/layershift-element.d.ts +8 -7
- package/dist/types/components/layershift/layershift-element.d.ts.map +1 -1
- package/dist/types/components/layershift/lifecycle.d.ts +77 -0
- package/dist/types/components/layershift/lifecycle.d.ts.map +1 -0
- package/dist/types/components/layershift/portal-element.d.ts +8 -7
- package/dist/types/components/layershift/portal-element.d.ts.map +1 -1
- package/dist/types/parallax-renderer.d.ts.map +1 -1
- package/dist/types/portal-renderer.d.ts +1 -0
- package/dist/types/portal-renderer.d.ts.map +1 -1
- package/package.json +15 -1
|
@@ -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
|
|
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
|
-
),
|
|
26
|
-
const l = new Uint8Array(
|
|
27
|
-
return l.set(
|
|
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((
|
|
29
|
+
return await new Promise((a, l) => {
|
|
30
30
|
const u = setTimeout(() => l(new Error("Worker init timeout")), 1e4);
|
|
31
|
-
|
|
32
|
-
f.data.type === "ready" && (clearTimeout(u),
|
|
33
|
-
},
|
|
31
|
+
o.onmessage = (f) => {
|
|
32
|
+
f.data.type === "ready" && (clearTimeout(u), a());
|
|
33
|
+
}, o.onerror = (f) => {
|
|
34
34
|
clearTimeout(u), l(f);
|
|
35
|
-
},
|
|
35
|
+
}, o.postMessage(
|
|
36
36
|
{
|
|
37
37
|
type: "init",
|
|
38
|
-
frames:
|
|
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
|
-
|
|
48
|
+
h
|
|
49
49
|
// Transfer list
|
|
50
50
|
);
|
|
51
|
-
}),
|
|
52
|
-
if (
|
|
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
|
|
89
|
-
this.interpolatedDepth = new Float32Array(
|
|
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),
|
|
104
|
-
if (!s && !
|
|
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 =
|
|
107
|
-
const
|
|
108
|
-
for (let
|
|
109
|
-
this.interpolatedDepth[
|
|
110
|
-
|
|
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 &&
|
|
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
|
|
127
|
-
this.uint8Output[
|
|
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
|
|
132
|
-
const [i,
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
async function yt(r, t, e) {
|
|
132
|
+
const [i, o] = await Promise.all([
|
|
133
|
+
Mt(t),
|
|
134
|
+
_t(r)
|
|
135
135
|
]);
|
|
136
|
-
return
|
|
136
|
+
return It(o, i);
|
|
137
137
|
}
|
|
138
|
-
async function
|
|
139
|
-
const t = await fetch(
|
|
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
|
|
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
|
|
152
|
-
const e = await fetch(
|
|
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
|
|
160
|
-
let
|
|
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 && (
|
|
166
|
+
u && (o.push(u), n += u.byteLength);
|
|
167
167
|
}
|
|
168
|
-
const
|
|
169
|
-
let
|
|
170
|
-
for (const l of
|
|
171
|
-
|
|
172
|
-
return
|
|
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
|
|
175
|
-
if (
|
|
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(
|
|
178
|
-
if (
|
|
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 ${
|
|
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 =
|
|
187
|
-
for (let
|
|
188
|
-
const l =
|
|
189
|
-
a
|
|
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:
|
|
191
|
+
return { meta: t, frames: h };
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
if (!
|
|
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(
|
|
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
|
|
200
|
-
const s = t / i,
|
|
201
|
-
for (let
|
|
202
|
-
const l = (
|
|
203
|
-
for (let
|
|
204
|
-
const
|
|
205
|
-
|
|
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
|
|
209
|
+
function kt(r, t, e, i) {
|
|
210
210
|
for (let s = 0; s < e; s += 1)
|
|
211
|
-
for (let
|
|
212
|
-
const
|
|
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
|
|
216
|
-
if (!(
|
|
217
|
-
for (let
|
|
218
|
-
if (
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
221
|
-
const U =
|
|
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[
|
|
225
|
+
i[a] = f / u;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
function Z(
|
|
229
|
-
return Math.min(e, Math.max(t,
|
|
228
|
+
function Z(r, t, e) {
|
|
229
|
+
return Math.min(e, Math.max(t, r));
|
|
230
230
|
}
|
|
231
|
-
const
|
|
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(
|
|
241
|
+
function Ht(r, t, e) {
|
|
242
242
|
const i = new Float32Array(256);
|
|
243
|
-
if (
|
|
243
|
+
if (r.length === 0 || t <= 0 || e <= 0)
|
|
244
244
|
return pt(i);
|
|
245
|
-
const
|
|
245
|
+
const o = Nt(r.length), n = t * e;
|
|
246
246
|
let s = 0;
|
|
247
|
-
const
|
|
248
|
-
for (const T of
|
|
249
|
-
const x =
|
|
250
|
-
for (let S = 0; S <
|
|
251
|
-
|
|
252
|
-
s +=
|
|
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
|
|
256
|
+
const a = 1 / s;
|
|
257
257
|
for (let T = 0; T < 256; T += 1)
|
|
258
|
-
i[T] =
|
|
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),
|
|
264
|
-
let
|
|
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
|
-
|
|
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 -
|
|
269
|
+
const x = T / 255 - m;
|
|
270
270
|
U += i[T] * x * x;
|
|
271
271
|
}
|
|
272
|
-
const b = Math.sqrt(U), E =
|
|
272
|
+
const b = Math.sqrt(U), E = d - u, p = g - f, v = zt(i);
|
|
273
273
|
return {
|
|
274
|
-
mean:
|
|
274
|
+
mean: m,
|
|
275
275
|
stdDev: b,
|
|
276
276
|
p5: u,
|
|
277
277
|
p25: f,
|
|
278
278
|
median: c,
|
|
279
|
-
p75:
|
|
280
|
-
p95:
|
|
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
|
|
288
|
-
if (
|
|
289
|
-
return { ...
|
|
290
|
-
const t =
|
|
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
|
-
),
|
|
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:
|
|
298
|
-
contrastHigh:
|
|
299
|
-
verticalReduction:
|
|
300
|
-
dofStart:
|
|
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
|
|
307
|
-
if (
|
|
308
|
-
if (
|
|
309
|
-
const t =
|
|
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(
|
|
312
|
-
Math.floor(
|
|
313
|
-
Math.floor(3 *
|
|
311
|
+
Math.floor(r / 4),
|
|
312
|
+
Math.floor(r / 2),
|
|
313
|
+
Math.floor(3 * r / 4),
|
|
314
314
|
t
|
|
315
|
-
], i = /* @__PURE__ */ new Set(),
|
|
316
|
-
for (const
|
|
317
|
-
i.has(
|
|
318
|
-
return
|
|
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(
|
|
320
|
+
function Y(r, t) {
|
|
321
321
|
for (let e = 0; e < 256; e += 1)
|
|
322
|
-
if (
|
|
322
|
+
if (r[e] >= t)
|
|
323
323
|
return e / 255;
|
|
324
324
|
return 1;
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function zt(r) {
|
|
327
327
|
const t = new Float32Array(256);
|
|
328
328
|
for (let c = 0; c < 256; c += 1) {
|
|
329
|
-
let
|
|
330
|
-
for (let
|
|
331
|
-
|
|
332
|
-
t[c] =
|
|
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,
|
|
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 &&
|
|
341
|
-
if (t[0] > t[1] && t[0] >= i &&
|
|
342
|
-
const s =
|
|
343
|
-
let
|
|
344
|
-
for (let c = 1; c <
|
|
345
|
-
if (Math.abs(
|
|
346
|
-
|
|
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 (!
|
|
350
|
-
const
|
|
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 =
|
|
352
|
+
for (let c = a; c <= l; c += 1)
|
|
353
353
|
t[c] < u && (u = t[c]);
|
|
354
|
-
const f = Math.min(s.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(
|
|
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:
|
|
369
|
+
histogram: r
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
|
-
function O(
|
|
373
|
-
return Math.min(e, Math.max(t,
|
|
372
|
+
function O(r, t, e) {
|
|
373
|
+
return Math.min(e, Math.max(t, r));
|
|
374
374
|
}
|
|
375
|
-
const
|
|
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
|
-
),
|
|
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(
|
|
578
|
-
const i =
|
|
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 (
|
|
581
|
-
const
|
|
582
|
-
throw
|
|
583
|
-
${
|
|
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
|
|
588
|
-
const i =
|
|
587
|
+
function jt(r, t, e) {
|
|
588
|
+
const i = r.createProgram();
|
|
589
589
|
if (!i) throw new Error("Failed to create program.");
|
|
590
|
-
if (
|
|
591
|
-
const
|
|
592
|
-
throw
|
|
593
|
-
${
|
|
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
|
|
595
|
+
return r.detachShader(i, t), r.detachShader(i, e), r.deleteShader(t), r.deleteShader(e), i;
|
|
596
596
|
}
|
|
597
|
-
function
|
|
597
|
+
function Yt(r, t) {
|
|
598
598
|
return {
|
|
599
|
-
uImage:
|
|
600
|
-
uDepth:
|
|
601
|
-
uOffset:
|
|
602
|
-
uStrength:
|
|
603
|
-
uPomEnabled:
|
|
604
|
-
uPomSteps:
|
|
605
|
-
uContrastLow:
|
|
606
|
-
uContrastHigh:
|
|
607
|
-
uVerticalReduction:
|
|
608
|
-
uDofStart:
|
|
609
|
-
uDofStrength:
|
|
610
|
-
uImageTexelSize:
|
|
611
|
-
uUvOffset:
|
|
612
|
-
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
|
|
698
|
-
|
|
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,
|
|
711
|
-
this.stop(), this.playbackVideo = t, this.readDepth = e, this.readInput = i, this.onVideoFrame =
|
|
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 =
|
|
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,
|
|
733
|
-
this.program =
|
|
734
|
-
const
|
|
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,
|
|
751
|
-
const
|
|
752
|
-
t.enableVertexAttribArray(
|
|
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
|
|
775
|
-
this.updateDepthTexture(
|
|
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(),
|
|
848
|
-
(this.canvas.width !==
|
|
849
|
-
const
|
|
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
|
-
|
|
852
|
-
const f = 1 +
|
|
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
|
-
|
|
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
|
|
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,
|
|
919
|
-
this.pointerTarget.x = z(i, -1, 1), this.pointerTarget.y = z(
|
|
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,
|
|
932
|
-
this.pointerTarget.x = z(i /
|
|
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
|
|
987
|
-
return Number.isFinite(
|
|
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",
|
|
1042
|
+
return this.getAttrFloat("parallax-x", H.parallaxX);
|
|
996
1043
|
}
|
|
997
1044
|
get parallaxY() {
|
|
998
|
-
return this.getAttrFloat("parallax-y",
|
|
1045
|
+
return this.getAttrFloat("parallax-y", H.parallaxY);
|
|
999
1046
|
}
|
|
1000
1047
|
get parallaxMax() {
|
|
1001
|
-
return this.getAttrFloat("parallax-max",
|
|
1048
|
+
return this.getAttrFloat("parallax-max", H.parallaxMax);
|
|
1002
1049
|
}
|
|
1003
1050
|
get overscan() {
|
|
1004
|
-
return this.getAttrFloat("overscan",
|
|
1051
|
+
return this.getAttrFloat("overscan", H.overscan);
|
|
1005
1052
|
}
|
|
1006
1053
|
get shouldAutoplay() {
|
|
1007
|
-
return this.getAttrBool("autoplay",
|
|
1054
|
+
return this.getAttrBool("autoplay", H.autoplay);
|
|
1008
1055
|
}
|
|
1009
1056
|
get shouldLoop() {
|
|
1010
|
-
return this.getAttrBool("loop",
|
|
1057
|
+
return this.getAttrBool("loop", H.loop);
|
|
1011
1058
|
}
|
|
1012
1059
|
get shouldMute() {
|
|
1013
|
-
return this.getAttrBool("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.
|
|
1098
|
+
this.lifecycle.onConnected();
|
|
1052
1099
|
}
|
|
1053
1100
|
disconnectedCallback() {
|
|
1054
|
-
this.
|
|
1101
|
+
this.lifecycle.onDisconnected();
|
|
1055
1102
|
}
|
|
1056
1103
|
attributeChangedCallback(t, e, i) {
|
|
1057
|
-
|
|
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
|
|
1087
|
-
const
|
|
1088
|
-
if (
|
|
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 [
|
|
1097
|
-
this.createVideoElement(
|
|
1098
|
-
|
|
1137
|
+
const [n, s] = await Promise.all([
|
|
1138
|
+
this.createVideoElement(e),
|
|
1139
|
+
yt(i, o)
|
|
1099
1140
|
]);
|
|
1100
|
-
if (
|
|
1101
|
-
|
|
1141
|
+
if (t.aborted) {
|
|
1142
|
+
n.remove();
|
|
1102
1143
|
return;
|
|
1103
1144
|
}
|
|
1104
|
-
this.video =
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
), a =
|
|
1110
|
-
let
|
|
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
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1154
|
+
s,
|
|
1155
|
+
s.meta.width,
|
|
1156
|
+
s.meta.height
|
|
1116
1157
|
);
|
|
1117
|
-
this.depthWorker = d,
|
|
1158
|
+
this.depthWorker = d, f = (m) => d.sample(m);
|
|
1118
1159
|
} catch {
|
|
1119
1160
|
const d = new bt(
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1161
|
+
s,
|
|
1162
|
+
s.meta.width,
|
|
1163
|
+
s.meta.height
|
|
1123
1164
|
);
|
|
1124
|
-
|
|
1165
|
+
f = (m) => d.sample(m);
|
|
1125
1166
|
}
|
|
1126
|
-
if (
|
|
1127
|
-
|
|
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:
|
|
1172
|
+
parallaxStrength: l,
|
|
1132
1173
|
pomEnabled: !0,
|
|
1133
1174
|
pomSteps: a.pomSteps,
|
|
1134
|
-
overscanPadding:
|
|
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(
|
|
1141
|
-
const
|
|
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
|
-
|
|
1144
|
-
|
|
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 *
|
|
1149
|
-
y: d.y *
|
|
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
|
-
|
|
1202
|
+
n.currentTime = 0;
|
|
1161
1203
|
try {
|
|
1162
|
-
await
|
|
1204
|
+
await n.play();
|
|
1163
1205
|
} catch {
|
|
1164
1206
|
}
|
|
1165
1207
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
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 (
|
|
1174
|
-
const
|
|
1175
|
-
console.error("<layershift-parallax>: Failed to initialize.",
|
|
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,
|
|
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
|
|
1188
|
-
|
|
1229
|
+
const n = () => {
|
|
1230
|
+
h(), i();
|
|
1189
1231
|
}, s = () => {
|
|
1190
|
-
|
|
1191
|
-
},
|
|
1192
|
-
e.removeEventListener("loadedmetadata",
|
|
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",
|
|
1236
|
+
e.addEventListener("loadedmetadata", n), e.addEventListener("error", s), e.load();
|
|
1195
1237
|
}), e;
|
|
1196
1238
|
}
|
|
1197
1239
|
// --- Cleanup ---
|
|
1198
|
-
|
|
1199
|
-
this.
|
|
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(
|
|
1203
|
-
return Math.min(e, Math.max(t,
|
|
1244
|
+
function z(r, t, e) {
|
|
1245
|
+
return Math.min(e, Math.max(t, r));
|
|
1204
1246
|
}
|
|
1205
|
-
function it(
|
|
1206
|
-
return
|
|
1247
|
+
function it(r, t, e) {
|
|
1248
|
+
return r + (t - r) * e;
|
|
1207
1249
|
}
|
|
1208
|
-
const
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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
|
-
),
|
|
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(
|
|
1772
|
-
const i =
|
|
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 (
|
|
1775
|
-
const
|
|
1776
|
-
throw
|
|
1777
|
-
${
|
|
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(
|
|
1782
|
-
const i =
|
|
1823
|
+
function V(r, t, e) {
|
|
1824
|
+
const i = r.createProgram();
|
|
1783
1825
|
if (!i) throw new Error("Failed to create program.");
|
|
1784
|
-
if (
|
|
1785
|
-
const
|
|
1786
|
-
throw
|
|
1787
|
-
${
|
|
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
|
|
1831
|
+
return r.detachShader(i, t), r.detachShader(i, e), r.deleteShader(t), r.deleteShader(e), i;
|
|
1790
1832
|
}
|
|
1791
|
-
function
|
|
1833
|
+
function de(r) {
|
|
1792
1834
|
const t = [];
|
|
1793
1835
|
let e = 0;
|
|
1794
|
-
for (let i = 0; i <
|
|
1795
|
-
const
|
|
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 =
|
|
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
|
-
|
|
1850
|
+
h,
|
|
1809
1851
|
f,
|
|
1810
1852
|
c,
|
|
1811
1853
|
s,
|
|
1812
|
-
|
|
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
|
-
|
|
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
|
|
1872
|
+
function me(r, t, e, i, o) {
|
|
1831
1873
|
if (i <= 0)
|
|
1832
1874
|
return { vertices: new Float32Array(0), count: 0 };
|
|
1833
|
-
const
|
|
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],
|
|
1837
|
-
if (
|
|
1838
|
-
const
|
|
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 <
|
|
1841
|
-
const
|
|
1842
|
-
U += S * _ - P *
|
|
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 <
|
|
1846
|
-
const
|
|
1847
|
-
P < 1e-8 ? (E.push(x > 0 ? E[x - 1] : 0), p.push(x > 0 ? p[x - 1] : 0)) : (E.push(-
|
|
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 <
|
|
1851
|
-
const
|
|
1852
|
-
let S = E[
|
|
1853
|
-
const P = Math.sqrt(S * S +
|
|
1854
|
-
P > 1e-8 ? (S /= P,
|
|
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 <
|
|
1857
|
-
const
|
|
1858
|
-
|
|
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(
|
|
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
|
|
1952
|
-
|
|
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,
|
|
1965
|
-
const
|
|
1966
|
-
|
|
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
|
|
1978
|
-
e.enableVertexAttribArray(
|
|
1979
|
-
const
|
|
1980
|
-
e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,
|
|
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
|
|
1989
|
-
e.enableVertexAttribArray(
|
|
1990
|
-
const
|
|
1991
|
-
e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,
|
|
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 =
|
|
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
|
|
2000
|
-
e.bindBuffer(e.ARRAY_BUFFER,
|
|
2001
|
-
const
|
|
2002
|
-
e.enableVertexAttribArray(s), e.vertexAttribPointer(s, 2, e.FLOAT, !1,
|
|
2003
|
-
const
|
|
2004
|
-
|
|
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 =
|
|
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
|
|
2019
|
-
e.bindBuffer(e.ARRAY_BUFFER,
|
|
2020
|
-
const
|
|
2021
|
-
e.enableVertexAttribArray(s), e.vertexAttribPointer(s, 2, e.FLOAT, !1,
|
|
2022
|
-
const
|
|
2023
|
-
|
|
2024
|
-
const
|
|
2025
|
-
|
|
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
|
|
2039
|
-
|
|
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
|
|
2049
|
-
this.jfaWidth =
|
|
2050
|
-
const s = (a,
|
|
2051
|
-
const
|
|
2052
|
-
return i.bindFramebuffer(i.FRAMEBUFFER,
|
|
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,
|
|
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
|
|
2063
|
-
let s = Math.ceil(
|
|
2107
|
+
const o = Math.max(e, i), n = [];
|
|
2108
|
+
let s = Math.ceil(o / 2);
|
|
2064
2109
|
for (; s >= 1; )
|
|
2065
|
-
|
|
2110
|
+
n.push(s), s = Math.floor(s / 2);
|
|
2066
2111
|
t.useProgram(this.jfaFloodProgram);
|
|
2067
|
-
let
|
|
2068
|
-
for (let f = 0; f <
|
|
2069
|
-
const c =
|
|
2070
|
-
t.bindFramebuffer(t.FRAMEBUFFER,
|
|
2071
|
-
const
|
|
2072
|
-
|
|
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,
|
|
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,
|
|
2082
|
-
this.stop(), this.playbackVideo = t, this.readDepth = e, this.readInput = i, this.onVideoFrame =
|
|
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,
|
|
2099
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2105
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2111
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2115
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2119
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2123
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2148
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2157
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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,
|
|
2178
|
-
L(t, t.FRAGMENT_SHADER,
|
|
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
|
|
2194
|
-
t.enableVertexAttribArray(
|
|
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,
|
|
2198
|
-
for (const
|
|
2199
|
-
|
|
2200
|
-
return
|
|
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
|
|
2210
|
-
this.updateDepthTexture(
|
|
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,
|
|
2265
|
+
let i = 0, o = 0;
|
|
2221
2266
|
if (this.readInput) {
|
|
2222
|
-
const
|
|
2223
|
-
i = -
|
|
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.
|
|
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(),
|
|
2260
|
-
(this.canvas.width !==
|
|
2261
|
-
const
|
|
2262
|
-
(this.jfaWidth !==
|
|
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
|
|
2267
|
-
f /=
|
|
2268
|
-
const
|
|
2269
|
-
this.meshScaleX =
|
|
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
|
|
2318
|
-
const t = await fetch(
|
|
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
|
|
2371
|
+
return ge(e);
|
|
2323
2372
|
}
|
|
2324
|
-
function
|
|
2325
|
-
const i = new DOMParser().parseFromString(
|
|
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
|
|
2329
|
-
if (
|
|
2377
|
+
const o = ve(i);
|
|
2378
|
+
if (o.length === 0)
|
|
2330
2379
|
throw new Error("No path data found in SVG.");
|
|
2331
|
-
let
|
|
2332
|
-
for (const
|
|
2333
|
-
for (let R = 0; R <
|
|
2334
|
-
|
|
2335
|
-
const l =
|
|
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 <
|
|
2338
|
-
R.push((
|
|
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 =
|
|
2341
|
-
for (const
|
|
2342
|
-
const { flatCoords: R, holeIndices: C } =
|
|
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 +
|
|
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 = [],
|
|
2349
|
-
for (let
|
|
2350
|
-
const R =
|
|
2351
|
-
x.push(T.length),
|
|
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
|
|
2357
|
-
for (let
|
|
2358
|
-
|
|
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:
|
|
2365
|
-
bounds: { minX:
|
|
2366
|
-
aspect:
|
|
2413
|
+
contourIsHole: A,
|
|
2414
|
+
bounds: { minX: D, maxX: _, minY: P, maxY: k },
|
|
2415
|
+
aspect: d
|
|
2367
2416
|
};
|
|
2368
2417
|
}
|
|
2369
|
-
function
|
|
2418
|
+
function ve(r) {
|
|
2370
2419
|
const t = [];
|
|
2371
|
-
return
|
|
2372
|
-
const l =
|
|
2420
|
+
return r.querySelectorAll("path").forEach((a) => {
|
|
2421
|
+
const l = a.getAttribute("d");
|
|
2373
2422
|
if (!l) return;
|
|
2374
|
-
const u =
|
|
2423
|
+
const u = Ee(l);
|
|
2375
2424
|
t.push(...u);
|
|
2376
|
-
}),
|
|
2377
|
-
const l =
|
|
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
|
-
}),
|
|
2382
|
-
const l =
|
|
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
|
-
}),
|
|
2387
|
-
const l = parseFloat(
|
|
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
|
-
}),
|
|
2390
|
-
const l = parseFloat(
|
|
2391
|
-
f > 0 && t.push(
|
|
2392
|
-
}),
|
|
2393
|
-
const l = parseFloat(
|
|
2394
|
-
f > 0 && c > 0 && t.push(
|
|
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(
|
|
2398
|
-
const t = [], e =
|
|
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
|
|
2401
|
-
Number.isFinite(
|
|
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
|
|
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
|
|
2416
|
-
const
|
|
2417
|
-
o.push(
|
|
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(
|
|
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,
|
|
2424
|
-
const u =
|
|
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
|
|
2431
|
-
let
|
|
2432
|
-
/^[a-zA-Z]$/.test(
|
|
2433
|
-
const
|
|
2434
|
-
switch (
|
|
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() + (
|
|
2438
|
-
i = b,
|
|
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() + (
|
|
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() + (
|
|
2495
|
+
i = c() + (m ? i : 0), e.push(i, o), h = i, a = o;
|
|
2447
2496
|
break;
|
|
2448
2497
|
}
|
|
2449
2498
|
case "V": {
|
|
2450
|
-
|
|
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() + (
|
|
2455
|
-
J(e, i,
|
|
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 -
|
|
2460
|
-
J(e, i,
|
|
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() + (
|
|
2465
|
-
xt(e, i,
|
|
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 -
|
|
2470
|
-
xt(e, i,
|
|
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() + (
|
|
2475
|
-
Ae(e, i,
|
|
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 =
|
|
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 =
|
|
2535
|
+
l = d;
|
|
2487
2536
|
}
|
|
2488
2537
|
return e.length >= 6 && t.push(e), t;
|
|
2489
2538
|
}
|
|
2490
|
-
function
|
|
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(
|
|
2542
|
+
for (; (i = e.exec(r)) !== null; )
|
|
2494
2543
|
t.push(i[0]);
|
|
2495
2544
|
return t;
|
|
2496
2545
|
}
|
|
2497
|
-
const
|
|
2498
|
-
function J(
|
|
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
|
-
|
|
2549
|
+
r.push(h, a);
|
|
2501
2550
|
return;
|
|
2502
2551
|
}
|
|
2503
|
-
const u =
|
|
2552
|
+
const u = h - t, f = a - e, c = Math.sqrt(u * u + f * f);
|
|
2504
2553
|
if (c < 1e-6) {
|
|
2505
|
-
|
|
2554
|
+
r.push(h, a);
|
|
2506
2555
|
return;
|
|
2507
2556
|
}
|
|
2508
|
-
const
|
|
2509
|
-
if (
|
|
2510
|
-
|
|
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
|
|
2514
|
-
J(
|
|
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(
|
|
2517
|
-
const
|
|
2518
|
-
J(
|
|
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(
|
|
2521
|
-
if (i === 0 ||
|
|
2522
|
-
|
|
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(
|
|
2526
|
-
const c =
|
|
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,
|
|
2533
|
-
let S = Math.max(0, (v * T - v *
|
|
2534
|
-
S = Math.sqrt(S), s ===
|
|
2535
|
-
const
|
|
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 -
|
|
2586
|
+
(b - D) / u,
|
|
2538
2587
|
(E - P) / f,
|
|
2539
|
-
(-b -
|
|
2588
|
+
(-b - D) / u,
|
|
2540
2589
|
(-E - P) / f
|
|
2541
2590
|
);
|
|
2542
|
-
!
|
|
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
|
|
2546
|
-
|
|
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(
|
|
2550
|
-
const
|
|
2551
|
-
return
|
|
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
|
|
2602
|
+
function Se(r) {
|
|
2554
2603
|
const t = [], e = [];
|
|
2555
|
-
for (let i = 0; i <
|
|
2604
|
+
for (let i = 0; i < r.length; i++) {
|
|
2556
2605
|
i > 0 && e.push(t.length / 2);
|
|
2557
|
-
for (const
|
|
2558
|
-
t.push(
|
|
2606
|
+
for (const o of r[i])
|
|
2607
|
+
t.push(o);
|
|
2559
2608
|
}
|
|
2560
2609
|
return { flatCoords: t, holeIndices: e };
|
|
2561
2610
|
}
|
|
2562
|
-
function
|
|
2563
|
-
const t =
|
|
2564
|
-
for (let
|
|
2565
|
-
let
|
|
2566
|
-
const s =
|
|
2567
|
-
for (let
|
|
2568
|
-
|
|
2569
|
-
i[
|
|
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
|
|
2574
|
-
if (
|
|
2575
|
-
return [
|
|
2576
|
-
const t =
|
|
2577
|
-
const
|
|
2578
|
-
return { index:
|
|
2579
|
-
}), i = 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
|
|
2582
|
-
const
|
|
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
|
|
2587
|
-
const
|
|
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(
|
|
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 ?
|
|
2643
|
+
l >= 0 ? n[l].holes.push(s.contour) : n.push({ outer: s.contour, holes: [] });
|
|
2595
2644
|
}
|
|
2596
|
-
return
|
|
2645
|
+
return n.map((s) => [s.outer, ...s.holes]);
|
|
2597
2646
|
}
|
|
2598
|
-
function
|
|
2647
|
+
function Ft(r) {
|
|
2599
2648
|
let t = 0;
|
|
2600
|
-
const e =
|
|
2649
|
+
const e = r.length;
|
|
2601
2650
|
for (let i = 0; i < e; i += 2) {
|
|
2602
|
-
const
|
|
2603
|
-
t +=
|
|
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(
|
|
2656
|
+
function Dt(r, t, e) {
|
|
2608
2657
|
let i = !1;
|
|
2609
|
-
const
|
|
2610
|
-
for (let
|
|
2611
|
-
const
|
|
2612
|
-
|
|
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
|
|
2617
|
-
const i = t && t.length > 0,
|
|
2618
|
-
let
|
|
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 (!
|
|
2621
|
-
i && (
|
|
2622
|
-
let
|
|
2623
|
-
if (
|
|
2624
|
-
for (let c = 0; c <
|
|
2625
|
-
const
|
|
2626
|
-
|
|
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 -
|
|
2677
|
+
f = Math.max(l - h, u - a), f = f !== 0 ? 32767 / f : 0;
|
|
2629
2678
|
}
|
|
2630
|
-
return K(
|
|
2679
|
+
return K(n, s, e, h, a, f, 0), s;
|
|
2631
2680
|
}
|
|
2632
|
-
function
|
|
2633
|
-
let
|
|
2634
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
2640
|
-
return
|
|
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(
|
|
2643
|
-
t || (t =
|
|
2644
|
-
let e =
|
|
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(
|
|
2655
|
-
if (!
|
|
2656
|
-
!s &&
|
|
2657
|
-
let
|
|
2658
|
-
for (;
|
|
2659
|
-
if (
|
|
2660
|
-
t.push(
|
|
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 (
|
|
2664
|
-
s ? s === 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(
|
|
2670
|
-
const t =
|
|
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
|
|
2673
|
-
let
|
|
2674
|
-
for (;
|
|
2675
|
-
if (
|
|
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
|
-
|
|
2726
|
+
d = d.next;
|
|
2678
2727
|
}
|
|
2679
2728
|
return !0;
|
|
2680
2729
|
}
|
|
2681
|
-
function
|
|
2682
|
-
const
|
|
2683
|
-
if (w(
|
|
2684
|
-
const
|
|
2685
|
-
let p =
|
|
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 >=
|
|
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 >=
|
|
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 >=
|
|
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
|
|
2701
|
-
let i =
|
|
2749
|
+
function Pe(r, t, e) {
|
|
2750
|
+
let i = r;
|
|
2702
2751
|
do {
|
|
2703
|
-
const
|
|
2704
|
-
!at(
|
|
2705
|
-
} while (i !==
|
|
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
|
|
2709
|
-
let s =
|
|
2757
|
+
function we(r, t, e, i, o, n) {
|
|
2758
|
+
let s = r;
|
|
2710
2759
|
do {
|
|
2711
|
-
let
|
|
2712
|
-
for (;
|
|
2713
|
-
if (s.i !==
|
|
2714
|
-
let
|
|
2715
|
-
s = X(s, s.next),
|
|
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
|
-
|
|
2767
|
+
h = h.next;
|
|
2719
2768
|
}
|
|
2720
2769
|
s = s.next;
|
|
2721
|
-
} while (s !==
|
|
2770
|
+
} while (s !== r);
|
|
2722
2771
|
}
|
|
2723
|
-
function
|
|
2724
|
-
const
|
|
2725
|
-
for (let
|
|
2726
|
-
const s = t[
|
|
2727
|
-
|
|
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
|
-
|
|
2730
|
-
for (const
|
|
2731
|
-
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
|
|
2735
|
-
const e =
|
|
2783
|
+
function Ce(r, t) {
|
|
2784
|
+
const e = Me(r, t);
|
|
2736
2785
|
if (!e) return t;
|
|
2737
|
-
const i =
|
|
2786
|
+
const i = wt(e, r);
|
|
2738
2787
|
return X(i, i.next), X(e, e.next);
|
|
2739
2788
|
}
|
|
2740
|
-
function
|
|
2789
|
+
function Me(r, t) {
|
|
2741
2790
|
let e = t;
|
|
2742
|
-
const i =
|
|
2743
|
-
let
|
|
2791
|
+
const i = r.x, o = r.y;
|
|
2792
|
+
let n = -1 / 0, s = null;
|
|
2744
2793
|
do {
|
|
2745
|
-
if (
|
|
2746
|
-
const f = e.x + (
|
|
2747
|
-
if (f <= i && f >
|
|
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
|
|
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 >=
|
|
2758
|
-
const f = Math.abs(
|
|
2759
|
-
Q(e,
|
|
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 !==
|
|
2811
|
+
} while (e !== h);
|
|
2763
2812
|
return s;
|
|
2764
2813
|
}
|
|
2765
|
-
function
|
|
2766
|
-
return w(
|
|
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
|
|
2769
|
-
let
|
|
2817
|
+
function Ie(r, t, e, i) {
|
|
2818
|
+
let o = r;
|
|
2770
2819
|
do
|
|
2771
|
-
|
|
2772
|
-
while (
|
|
2773
|
-
|
|
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
|
|
2824
|
+
function Ve(r) {
|
|
2776
2825
|
let t = 1, e;
|
|
2777
2826
|
do {
|
|
2778
|
-
let i =
|
|
2779
|
-
|
|
2780
|
-
let
|
|
2827
|
+
let i = r;
|
|
2828
|
+
r = null;
|
|
2829
|
+
let o = null;
|
|
2781
2830
|
for (e = 0; i; ) {
|
|
2782
2831
|
e++;
|
|
2783
|
-
let
|
|
2784
|
-
for (let
|
|
2832
|
+
let n = i, s = 0;
|
|
2833
|
+
for (let a = 0; a < t && (s++, n = n.nextZ, !!n); a++)
|
|
2785
2834
|
;
|
|
2786
|
-
let
|
|
2787
|
-
for (; s > 0 ||
|
|
2788
|
-
let
|
|
2789
|
-
s !== 0 && (
|
|
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 =
|
|
2840
|
+
i = n;
|
|
2792
2841
|
}
|
|
2793
|
-
|
|
2842
|
+
o.nextZ = null, t *= 2;
|
|
2794
2843
|
} while (e > 1);
|
|
2795
|
-
return
|
|
2844
|
+
return r;
|
|
2796
2845
|
}
|
|
2797
|
-
function ct(
|
|
2798
|
-
let
|
|
2799
|
-
return
|
|
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
|
|
2802
|
-
let t =
|
|
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 !==
|
|
2854
|
+
while (t !== r);
|
|
2806
2855
|
return e;
|
|
2807
2856
|
}
|
|
2808
|
-
function G(
|
|
2809
|
-
return (
|
|
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
|
|
2812
|
-
return
|
|
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(
|
|
2815
|
-
return (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(
|
|
2818
|
-
return
|
|
2866
|
+
function at(r, t) {
|
|
2867
|
+
return r.x === t.x && r.y === t.y;
|
|
2819
2868
|
}
|
|
2820
|
-
function
|
|
2821
|
-
const
|
|
2822
|
-
return !!(
|
|
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(
|
|
2825
|
-
return t.x <= Math.max(
|
|
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(
|
|
2828
|
-
return
|
|
2876
|
+
function ot(r) {
|
|
2877
|
+
return r > 0 ? 1 : r < 0 ? -1 : 0;
|
|
2829
2878
|
}
|
|
2830
|
-
function
|
|
2831
|
-
let e =
|
|
2879
|
+
function Be(r, t) {
|
|
2880
|
+
let e = r;
|
|
2832
2881
|
do {
|
|
2833
|
-
if (e.i !==
|
|
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 !==
|
|
2884
|
+
} while (e !== r);
|
|
2836
2885
|
return !1;
|
|
2837
2886
|
}
|
|
2838
|
-
function Q(
|
|
2839
|
-
return w(
|
|
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(
|
|
2842
|
-
let e =
|
|
2843
|
-
const
|
|
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 >
|
|
2846
|
-
while (e !==
|
|
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
|
|
2850
|
-
const e = ut(
|
|
2851
|
-
return
|
|
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(
|
|
2854
|
-
const
|
|
2855
|
-
return i ? (
|
|
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(
|
|
2858
|
-
|
|
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(
|
|
2909
|
+
function ut(r, t, e) {
|
|
2861
2910
|
return {
|
|
2862
|
-
i:
|
|
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
|
|
2874
|
-
let
|
|
2875
|
-
for (let
|
|
2876
|
-
|
|
2877
|
-
return
|
|
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
|
|
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,
|
|
2960
|
-
this.pointerTarget.x = W(i, -1, 1), this.pointerTarget.y = W(
|
|
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,
|
|
2973
|
-
this.pointerTarget.x = W(i /
|
|
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
|
|
3065
|
-
return Number.isFinite(
|
|
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
|
|
3123
|
+
return Ne(i);
|
|
3075
3124
|
}
|
|
3076
3125
|
getAttrVec3(t, e) {
|
|
3077
|
-
const
|
|
3078
|
-
if (
|
|
3079
|
-
return [
|
|
3080
|
-
const
|
|
3081
|
-
return [
|
|
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",
|
|
3133
|
+
return this.getAttrFloat("parallax-x", y.parallaxX);
|
|
3085
3134
|
}
|
|
3086
3135
|
get parallaxY() {
|
|
3087
|
-
return this.getAttrFloat("parallax-y",
|
|
3136
|
+
return this.getAttrFloat("parallax-y", y.parallaxY);
|
|
3088
3137
|
}
|
|
3089
3138
|
get parallaxMax() {
|
|
3090
|
-
return this.getAttrFloat("parallax-max",
|
|
3139
|
+
return this.getAttrFloat("parallax-max", y.parallaxMax);
|
|
3091
3140
|
}
|
|
3092
3141
|
get overscan() {
|
|
3093
|
-
return this.getAttrFloat("overscan",
|
|
3142
|
+
return this.getAttrFloat("overscan", y.overscan);
|
|
3094
3143
|
}
|
|
3095
3144
|
get pomSteps() {
|
|
3096
|
-
return this.getAttrFloat("pom-steps",
|
|
3145
|
+
return this.getAttrFloat("pom-steps", y.pomSteps);
|
|
3097
3146
|
}
|
|
3098
3147
|
// Boundary
|
|
3099
3148
|
get rimIntensity() {
|
|
3100
|
-
return this.getAttrFloat("rim-intensity",
|
|
3149
|
+
return this.getAttrFloat("rim-intensity", y.rimIntensity);
|
|
3101
3150
|
}
|
|
3102
3151
|
get rimWidth() {
|
|
3103
|
-
return this.getAttrFloat("rim-width",
|
|
3152
|
+
return this.getAttrFloat("rim-width", y.rimWidth);
|
|
3104
3153
|
}
|
|
3105
3154
|
get rimColor() {
|
|
3106
|
-
return this.getAttrColor("rim-color",
|
|
3155
|
+
return this.getAttrColor("rim-color", y.rimColor);
|
|
3107
3156
|
}
|
|
3108
3157
|
get refractionStrength() {
|
|
3109
|
-
return this.getAttrFloat("refraction-strength",
|
|
3158
|
+
return this.getAttrFloat("refraction-strength", y.refractionStrength);
|
|
3110
3159
|
}
|
|
3111
3160
|
get chromaticStrength() {
|
|
3112
|
-
return this.getAttrFloat("chromatic-strength",
|
|
3161
|
+
return this.getAttrFloat("chromatic-strength", y.chromaticStrength);
|
|
3113
3162
|
}
|
|
3114
3163
|
get occlusionIntensity() {
|
|
3115
|
-
return this.getAttrFloat("occlusion-intensity",
|
|
3164
|
+
return this.getAttrFloat("occlusion-intensity", y.occlusionIntensity);
|
|
3116
3165
|
}
|
|
3117
3166
|
// Lens transform
|
|
3118
3167
|
get depthPower() {
|
|
3119
|
-
return this.getAttrFloat("depth-power",
|
|
3168
|
+
return this.getAttrFloat("depth-power", y.depthPower);
|
|
3120
3169
|
}
|
|
3121
3170
|
get depthScale() {
|
|
3122
|
-
return this.getAttrFloat("depth-scale",
|
|
3171
|
+
return this.getAttrFloat("depth-scale", y.depthScale);
|
|
3123
3172
|
}
|
|
3124
3173
|
get depthBias() {
|
|
3125
|
-
return this.getAttrFloat("depth-bias",
|
|
3174
|
+
return this.getAttrFloat("depth-bias", y.depthBias);
|
|
3126
3175
|
}
|
|
3127
3176
|
// Interior mood
|
|
3128
3177
|
get fogDensity() {
|
|
3129
|
-
return this.getAttrFloat("fog-density",
|
|
3178
|
+
return this.getAttrFloat("fog-density", y.fogDensity);
|
|
3130
3179
|
}
|
|
3131
3180
|
get fogColor() {
|
|
3132
|
-
return this.getAttrColor("fog-color",
|
|
3181
|
+
return this.getAttrColor("fog-color", y.fogColor);
|
|
3133
3182
|
}
|
|
3134
3183
|
get colorShift() {
|
|
3135
|
-
return this.getAttrFloat("color-shift",
|
|
3184
|
+
return this.getAttrFloat("color-shift", y.colorShift);
|
|
3136
3185
|
}
|
|
3137
3186
|
get brightnessBias() {
|
|
3138
|
-
return this.getAttrFloat("brightness-bias",
|
|
3187
|
+
return this.getAttrFloat("brightness-bias", y.brightnessBias);
|
|
3139
3188
|
}
|
|
3140
3189
|
// Depth-adaptive
|
|
3141
3190
|
get contrastLow() {
|
|
3142
|
-
return this.getAttrFloat("contrast-low",
|
|
3191
|
+
return this.getAttrFloat("contrast-low", y.contrastLow);
|
|
3143
3192
|
}
|
|
3144
3193
|
get contrastHigh() {
|
|
3145
|
-
return this.getAttrFloat("contrast-high",
|
|
3194
|
+
return this.getAttrFloat("contrast-high", y.contrastHigh);
|
|
3146
3195
|
}
|
|
3147
3196
|
get verticalReduction() {
|
|
3148
|
-
return this.getAttrFloat("vertical-reduction",
|
|
3197
|
+
return this.getAttrFloat("vertical-reduction", y.verticalReduction);
|
|
3149
3198
|
}
|
|
3150
3199
|
get dofStart() {
|
|
3151
|
-
return this.getAttrFloat("dof-start",
|
|
3200
|
+
return this.getAttrFloat("dof-start", y.dofStart);
|
|
3152
3201
|
}
|
|
3153
3202
|
get dofStrength() {
|
|
3154
|
-
return this.getAttrFloat("dof-strength",
|
|
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",
|
|
3207
|
+
return this.getAttrFloat("bevel-intensity", y.bevelIntensity);
|
|
3159
3208
|
}
|
|
3160
3209
|
get bevelWidth() {
|
|
3161
|
-
return this.getAttrFloat("bevel-width",
|
|
3210
|
+
return this.getAttrFloat("bevel-width", y.bevelWidth);
|
|
3162
3211
|
}
|
|
3163
3212
|
get bevelDarkening() {
|
|
3164
|
-
return this.getAttrFloat("bevel-darkening",
|
|
3213
|
+
return this.getAttrFloat("bevel-darkening", y.bevelDarkening);
|
|
3165
3214
|
}
|
|
3166
3215
|
get bevelDesaturation() {
|
|
3167
|
-
return this.getAttrFloat("bevel-desaturation",
|
|
3216
|
+
return this.getAttrFloat("bevel-desaturation", y.bevelDesaturation);
|
|
3168
3217
|
}
|
|
3169
3218
|
get bevelLightAngle() {
|
|
3170
|
-
return this.getAttrFloat("bevel-light-angle",
|
|
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",
|
|
3223
|
+
return this.getAttrFloat("edge-thickness", y.edgeThickness);
|
|
3175
3224
|
}
|
|
3176
3225
|
get edgeSpecular() {
|
|
3177
|
-
return this.getAttrFloat("edge-specular",
|
|
3226
|
+
return this.getAttrFloat("edge-specular", y.edgeSpecular);
|
|
3178
3227
|
}
|
|
3179
3228
|
get edgeColor() {
|
|
3180
|
-
return this.getAttrColor("edge-color",
|
|
3229
|
+
return this.getAttrColor("edge-color", y.edgeColor);
|
|
3181
3230
|
}
|
|
3182
3231
|
// Chamfer geometry
|
|
3183
3232
|
get chamferWidth() {
|
|
3184
|
-
return this.getAttrFloat("chamfer-width",
|
|
3233
|
+
return this.getAttrFloat("chamfer-width", y.chamferWidth);
|
|
3185
3234
|
}
|
|
3186
3235
|
get chamferAngle() {
|
|
3187
|
-
return this.getAttrFloat("chamfer-angle",
|
|
3236
|
+
return this.getAttrFloat("chamfer-angle", y.chamferAngle);
|
|
3188
3237
|
}
|
|
3189
3238
|
get chamferColor() {
|
|
3190
|
-
return this.getAttrColor("chamfer-color",
|
|
3239
|
+
return this.getAttrColor("chamfer-color", y.chamferColor);
|
|
3191
3240
|
}
|
|
3192
3241
|
get chamferAmbient() {
|
|
3193
|
-
return this.getAttrFloat("chamfer-ambient",
|
|
3242
|
+
return this.getAttrFloat("chamfer-ambient", y.chamferAmbient);
|
|
3194
3243
|
}
|
|
3195
3244
|
get chamferSpecular() {
|
|
3196
|
-
return this.getAttrFloat("chamfer-specular",
|
|
3245
|
+
return this.getAttrFloat("chamfer-specular", y.chamferSpecular);
|
|
3197
3246
|
}
|
|
3198
3247
|
get chamferShininess() {
|
|
3199
|
-
return this.getAttrFloat("chamfer-shininess",
|
|
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",
|
|
3252
|
+
return this.getAttrFloat("edge-occlusion-width", y.edgeOcclusionWidth);
|
|
3204
3253
|
}
|
|
3205
3254
|
get edgeOcclusionStrength() {
|
|
3206
|
-
return this.getAttrFloat("edge-occlusion-strength",
|
|
3255
|
+
return this.getAttrFloat("edge-occlusion-strength", y.edgeOcclusionStrength);
|
|
3207
3256
|
}
|
|
3208
3257
|
get lightDirection3() {
|
|
3209
|
-
return this.getAttrVec3("light-direction",
|
|
3258
|
+
return this.getAttrVec3("light-direction", y.lightDirection);
|
|
3210
3259
|
}
|
|
3211
3260
|
get shouldAutoplay() {
|
|
3212
|
-
return this.getAttrBool("autoplay",
|
|
3261
|
+
return this.getAttrBool("autoplay", y.autoplay);
|
|
3213
3262
|
}
|
|
3214
3263
|
get shouldLoop() {
|
|
3215
|
-
return this.getAttrBool("loop",
|
|
3264
|
+
return this.getAttrBool("loop", y.loop);
|
|
3216
3265
|
}
|
|
3217
3266
|
get shouldMute() {
|
|
3218
|
-
return this.getAttrBool("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.
|
|
3296
|
+
this.lifecycle.onConnected();
|
|
3248
3297
|
}
|
|
3249
3298
|
disconnectedCallback() {
|
|
3250
|
-
this.
|
|
3299
|
+
this.lifecycle.onDisconnected();
|
|
3251
3300
|
}
|
|
3252
3301
|
attributeChangedCallback(t, e, i) {
|
|
3253
|
-
|
|
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
|
|
3283
|
-
const
|
|
3284
|
-
if (
|
|
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 [
|
|
3293
|
-
this.createVideoElement(
|
|
3294
|
-
|
|
3295
|
-
|
|
3335
|
+
const [s, h, a] = await Promise.all([
|
|
3336
|
+
this.createVideoElement(e),
|
|
3337
|
+
yt(i, o),
|
|
3338
|
+
pe(n)
|
|
3296
3339
|
]);
|
|
3297
|
-
if (
|
|
3298
|
-
|
|
3340
|
+
if (t.aborted) {
|
|
3341
|
+
s.remove();
|
|
3299
3342
|
return;
|
|
3300
3343
|
}
|
|
3301
|
-
this.video =
|
|
3302
|
-
const
|
|
3303
|
-
let
|
|
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
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3349
|
+
h,
|
|
3350
|
+
h.meta.width,
|
|
3351
|
+
h.meta.height
|
|
3309
3352
|
);
|
|
3310
|
-
this.depthWorker = d,
|
|
3353
|
+
this.depthWorker = d, u = (m) => d.sample(m);
|
|
3311
3354
|
} catch {
|
|
3312
3355
|
const d = new bt(
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3356
|
+
h,
|
|
3357
|
+
h.meta.width,
|
|
3358
|
+
h.meta.height
|
|
3316
3359
|
);
|
|
3317
|
-
|
|
3360
|
+
u = (m) => d.sample(m);
|
|
3318
3361
|
}
|
|
3319
|
-
if (
|
|
3320
|
-
|
|
3362
|
+
if (t.aborted) {
|
|
3363
|
+
s.remove(), this.depthWorker?.dispose(), this.depthWorker = null;
|
|
3321
3364
|
return;
|
|
3322
3365
|
}
|
|
3323
|
-
const
|
|
3324
|
-
parallaxStrength:
|
|
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,
|
|
3372
|
-
const
|
|
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
|
-
|
|
3375
|
-
|
|
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 *
|
|
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
|
-
|
|
3431
|
+
s.currentTime = 0;
|
|
3388
3432
|
try {
|
|
3389
|
-
await
|
|
3433
|
+
await s.play();
|
|
3390
3434
|
} catch {
|
|
3391
3435
|
}
|
|
3392
3436
|
}
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
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 (
|
|
3399
|
-
const
|
|
3400
|
-
console.error("<layershift-portal>: Failed to initialize.",
|
|
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,
|
|
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
|
|
3413
|
-
|
|
3456
|
+
const n = () => {
|
|
3457
|
+
h(), i();
|
|
3414
3458
|
}, s = () => {
|
|
3415
|
-
|
|
3416
|
-
},
|
|
3417
|
-
e.removeEventListener("loadedmetadata",
|
|
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",
|
|
3463
|
+
e.addEventListener("loadedmetadata", n), e.addEventListener("error", s), e.load();
|
|
3420
3464
|
}), e;
|
|
3421
3465
|
}
|
|
3422
3466
|
// --- Cleanup ---
|
|
3423
|
-
|
|
3424
|
-
this.
|
|
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(
|
|
3428
|
-
return Math.min(e, Math.max(t,
|
|
3471
|
+
function W(r, t, e) {
|
|
3472
|
+
return Math.min(e, Math.max(t, r));
|
|
3429
3473
|
}
|
|
3430
|
-
function nt(
|
|
3431
|
-
return
|
|
3474
|
+
function nt(r, t, e) {
|
|
3475
|
+
return r + (t - r) * e;
|
|
3432
3476
|
}
|
|
3433
|
-
function
|
|
3434
|
-
const t =
|
|
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,
|
|
3437
|
-
return [e, i,
|
|
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,
|
|
3441
|
-
return [e, i,
|
|
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
|
}
|