@alpha-video-kit/svg 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{canvas-component-ChQNZXEV.js → canvas-component-C3vC6FBw.js} +106 -101
- package/dist/canvas-component-CE05m0PN.cjs +24 -0
- package/dist/index.cjs +1 -30
- package/dist/index.d.ts +16 -31
- package/dist/index.js +28 -87
- package/dist/register.cjs +1 -1
- package/dist/register.js +1 -1
- package/package.json +1 -1
- package/react.d.ts +3 -22
- package/dist/canvas-component-B4CLR7ME.cjs +0 -35
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var Q = Object.defineProperty;
|
|
2
|
+
var U = (h) => {
|
|
3
|
+
throw TypeError(h);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var e = (
|
|
5
|
+
var X = (h, n, t) => n in h ? Q(h, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[n] = t;
|
|
6
|
+
var I = (h, n, t) => X(h, typeof n != "symbol" ? n + "" : n, t), F = (h, n, t) => n.has(h) || U("Cannot " + t);
|
|
7
|
+
var e = (h, n, t) => (F(h, n, "read from private field"), t ? t.call(h) : n.get(h)), u = (h, n, t) => n.has(h) ? U("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(h) : n.set(h, t), a = (h, n, t, r) => (F(h, n, "write to private field"), r ? r.call(h, t) : n.set(h, t), t), d = (h, n, t) => (F(h, n, "access private method"), t);
|
|
8
8
|
const j = [
|
|
9
9
|
"src",
|
|
10
10
|
"crossorigin",
|
|
@@ -16,7 +16,7 @@ const j = [
|
|
|
16
16
|
"poster",
|
|
17
17
|
"width",
|
|
18
18
|
"height"
|
|
19
|
-
],
|
|
19
|
+
], Z = /* @__PURE__ */ new Set(["autoplay", "loop", "muted", "playsinline"]), tt = [
|
|
20
20
|
"loadstart",
|
|
21
21
|
"progress",
|
|
22
22
|
"suspend",
|
|
@@ -41,53 +41,53 @@ const j = [
|
|
|
41
41
|
"resize",
|
|
42
42
|
"volumechange"
|
|
43
43
|
];
|
|
44
|
-
var s,
|
|
45
|
-
class
|
|
44
|
+
var s, L, w, E, x, y, O, c, V, _, D;
|
|
45
|
+
class et extends HTMLElement {
|
|
46
46
|
constructor() {
|
|
47
47
|
super();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
u(this, c);
|
|
49
|
+
u(this, s);
|
|
50
|
+
u(this, L);
|
|
51
|
+
u(this, w);
|
|
52
|
+
u(this, E);
|
|
53
|
+
u(this, x);
|
|
54
|
+
u(this, y, null);
|
|
55
|
+
u(this, O);
|
|
56
56
|
const t = this.attachShadow({ mode: "open" });
|
|
57
|
-
a(this,
|
|
57
|
+
a(this, O, `avk-${Math.random().toString(36).slice(2, 8)}`), t.innerHTML = `<style>
|
|
58
58
|
:host{display:inline-block;overflow:hidden}
|
|
59
59
|
svg{display:block;width:100%;height:auto}
|
|
60
60
|
video{display:block;width:100%;height:100%}
|
|
61
61
|
</style>
|
|
62
62
|
<svg viewBox="0 0 1 1" preserveAspectRatio="xMidYMid meet">
|
|
63
63
|
<defs>
|
|
64
|
-
<filter id="${e(this,
|
|
64
|
+
<filter id="${e(this, O)}" filterUnits="userSpaceOnUse" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
|
|
65
65
|
<feOffset in="SourceGraphic" dy="0" result="s"/>
|
|
66
66
|
<feColorMatrix in="s" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0" result="a"/>
|
|
67
67
|
<feComposite in="SourceGraphic" in2="a" operator="in"/>
|
|
68
68
|
</filter>
|
|
69
69
|
</defs>
|
|
70
|
-
<foreignObject width="1" height="1" filter="url(#${e(this,
|
|
70
|
+
<foreignObject width="1" height="1" filter="url(#${e(this, O)})">
|
|
71
71
|
<video></video>
|
|
72
72
|
</foreignObject>
|
|
73
|
-
</svg>`, a(this,
|
|
74
|
-
for (const r of
|
|
75
|
-
e(this, s).addEventListener(r, (
|
|
76
|
-
this.dispatchEvent(new Event(
|
|
73
|
+
</svg>`, a(this, L, t.querySelector("svg")), a(this, w, t.querySelector("foreignObject")), a(this, E, t.querySelector("filter")), a(this, x, t.querySelector("feOffset")), a(this, s, t.querySelector("video"));
|
|
74
|
+
for (const r of tt)
|
|
75
|
+
e(this, s).addEventListener(r, (l) => {
|
|
76
|
+
this.dispatchEvent(new Event(l.type, { bubbles: !1, cancelable: !1 }));
|
|
77
77
|
});
|
|
78
|
-
e(this, s).addEventListener("loadedmetadata", () =>
|
|
78
|
+
e(this, s).addEventListener("loadedmetadata", () => d(this, c, V).call(this)), e(this, s).addEventListener("resize", () => d(this, c, V).call(this));
|
|
79
79
|
}
|
|
80
80
|
connectedCallback() {
|
|
81
81
|
for (const t of j)
|
|
82
|
-
this.hasAttribute(t) &&
|
|
83
|
-
|
|
82
|
+
this.hasAttribute(t) && d(this, c, _).call(this, t, this.getAttribute(t));
|
|
83
|
+
d(this, c, D).call(this), a(this, y, new MutationObserver(() => d(this, c, D).call(this))), e(this, y).observe(this, { childList: !0 });
|
|
84
84
|
}
|
|
85
85
|
disconnectedCallback() {
|
|
86
86
|
var t;
|
|
87
87
|
(t = e(this, y)) == null || t.disconnect(), a(this, y, null);
|
|
88
88
|
}
|
|
89
|
-
attributeChangedCallback(t, r,
|
|
90
|
-
|
|
89
|
+
attributeChangedCallback(t, r, l) {
|
|
90
|
+
d(this, c, _).call(this, t, l);
|
|
91
91
|
}
|
|
92
92
|
// --- Proxied properties ---
|
|
93
93
|
get src() {
|
|
@@ -203,19 +203,19 @@ video{display:block;width:100%;height:100%}
|
|
|
203
203
|
return e(this, s).canPlayType(t);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
s = new WeakMap(),
|
|
206
|
+
s = new WeakMap(), L = new WeakMap(), w = new WeakMap(), E = new WeakMap(), x = new WeakMap(), y = new WeakMap(), O = new WeakMap(), c = new WeakSet(), V = function() {
|
|
207
207
|
const t = e(this, s).videoWidth, r = e(this, s).videoHeight;
|
|
208
208
|
if (!t || !r) return;
|
|
209
|
-
const
|
|
210
|
-
e(this,
|
|
211
|
-
},
|
|
212
|
-
|
|
213
|
-
},
|
|
209
|
+
const l = Math.floor(r / 2);
|
|
210
|
+
e(this, L).setAttribute("viewBox", `0 0 ${t} ${l}`), e(this, w).setAttribute("width", String(t)), e(this, w).setAttribute("height", String(r)), e(this, E).setAttribute("width", String(t)), e(this, E).setAttribute("height", String(r)), e(this, x).setAttribute("dy", String(-l));
|
|
211
|
+
}, _ = function(t, r) {
|
|
212
|
+
Z.has(t) ? e(this, s)[t] = r !== null : r === null ? e(this, s).removeAttribute(t) : e(this, s).setAttribute(t, r);
|
|
213
|
+
}, D = function() {
|
|
214
214
|
e(this, s).querySelectorAll("source").forEach((t) => t.remove()), this.querySelectorAll("source").forEach((t) => {
|
|
215
215
|
e(this, s).appendChild(t.cloneNode(!0));
|
|
216
216
|
}), e(this, s).querySelectorAll("source").length > 0 && !e(this, s).src && e(this, s).load();
|
|
217
|
-
},
|
|
218
|
-
const
|
|
217
|
+
}, I(et, "observedAttributes", [...j]);
|
|
218
|
+
const k = "http://www.w3.org/2000/svg", Y = [
|
|
219
219
|
"src",
|
|
220
220
|
"crossorigin",
|
|
221
221
|
"preload",
|
|
@@ -226,7 +226,7 @@ const D = [
|
|
|
226
226
|
"poster",
|
|
227
227
|
"width",
|
|
228
228
|
"height"
|
|
229
|
-
],
|
|
229
|
+
], it = /* @__PURE__ */ new Set(["autoplay", "loop", "muted", "playsinline"]), st = [
|
|
230
230
|
"loadstart",
|
|
231
231
|
"progress",
|
|
232
232
|
"suspend",
|
|
@@ -251,66 +251,56 @@ const D = [
|
|
|
251
251
|
"resize",
|
|
252
252
|
"volumechange"
|
|
253
253
|
];
|
|
254
|
-
var i,
|
|
255
|
-
class
|
|
254
|
+
var i, p, T, H, m, v, g, b, f, C, A, S, R, o, G, J, P, W, B, K, $, z;
|
|
255
|
+
class rt extends HTMLElement {
|
|
256
256
|
constructor() {
|
|
257
257
|
super();
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
258
|
+
u(this, o);
|
|
259
|
+
u(this, i);
|
|
260
|
+
u(this, p);
|
|
261
|
+
u(this, T);
|
|
262
|
+
u(this, H);
|
|
263
|
+
u(this, m, null);
|
|
264
|
+
u(this, v, null);
|
|
265
|
+
u(this, g, !1);
|
|
266
|
+
u(this, b, 0);
|
|
267
|
+
u(this, f, 0);
|
|
268
|
+
// SVG filter (lives in document.body so ctx.filter url() can resolve it)
|
|
269
|
+
u(this, C);
|
|
270
|
+
u(this, A, null);
|
|
271
|
+
u(this, S, null);
|
|
272
|
+
u(this, R, null);
|
|
272
273
|
const t = this.attachShadow({ mode: "open" });
|
|
273
|
-
a(this,
|
|
274
|
+
a(this, C, `avk-c-${Math.random().toString(36).slice(2, 8)}`), t.innerHTML = `<style>
|
|
274
275
|
:host{display:inline-block;overflow:hidden}
|
|
275
276
|
video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
|
|
276
|
-
|
|
277
|
-
canvas{display:block;width:100
|
|
277
|
+
.clip{overflow:hidden;width:100%}
|
|
278
|
+
canvas{display:block;width:100%}
|
|
278
279
|
</style>
|
|
279
280
|
<video></video>
|
|
280
|
-
<
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
<feColorMatrix in="s" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0" result="a"/>
|
|
285
|
-
<feComposite in="SourceGraphic" in2="a" operator="in"/>
|
|
286
|
-
</filter>
|
|
287
|
-
</defs>
|
|
288
|
-
<foreignObject width="1" height="1" filter="url(#${e(this, E)})">
|
|
289
|
-
<canvas xmlns="http://www.w3.org/1999/xhtml"></canvas>
|
|
290
|
-
</foreignObject>
|
|
291
|
-
</svg>`, a(this, i, t.querySelector("video")), a(this, C, t.querySelector("svg")), a(this, w, t.querySelector("foreignObject")), a(this, O, t.querySelector("filter")), a(this, M, t.querySelector("feOffset")), a(this, g, t.querySelector("canvas")), a(this, q, e(this, g).getContext("2d"));
|
|
292
|
-
for (const r of Q)
|
|
293
|
-
e(this, i).addEventListener(r, (d) => {
|
|
294
|
-
this.dispatchEvent(new Event(d.type, { bubbles: !1, cancelable: !1 }));
|
|
281
|
+
<div class="clip"><canvas></canvas></div>`, a(this, i, t.querySelector("video")), a(this, H, t.querySelector(".clip")), a(this, p, t.querySelector("canvas")), a(this, T, e(this, p).getContext("2d"));
|
|
282
|
+
for (const r of st)
|
|
283
|
+
e(this, i).addEventListener(r, (l) => {
|
|
284
|
+
this.dispatchEvent(new Event(l.type, { bubbles: !1, cancelable: !1 }));
|
|
295
285
|
});
|
|
296
|
-
e(this, i).addEventListener("loadedmetadata", () =>
|
|
286
|
+
e(this, i).addEventListener("loadedmetadata", () => d(this, o, P).call(this)), e(this, i).addEventListener("resize", () => d(this, o, P).call(this));
|
|
297
287
|
}
|
|
298
288
|
connectedCallback() {
|
|
299
|
-
for (const t of
|
|
300
|
-
this.hasAttribute(t) &&
|
|
301
|
-
|
|
289
|
+
for (const t of Y)
|
|
290
|
+
this.hasAttribute(t) && d(this, o, W).call(this, t, this.getAttribute(t));
|
|
291
|
+
d(this, o, B).call(this), a(this, v, new MutationObserver(() => d(this, o, B).call(this))), e(this, v).observe(this, { childList: !0 }), d(this, o, G).call(this), a(this, m, new IntersectionObserver(
|
|
302
292
|
([t]) => {
|
|
303
|
-
a(this,
|
|
293
|
+
a(this, g, t.isIntersecting), e(this, g) ? d(this, o, K).call(this) : d(this, o, $).call(this);
|
|
304
294
|
},
|
|
305
295
|
{ threshold: 0 }
|
|
306
|
-
)), e(this,
|
|
296
|
+
)), e(this, m).observe(this);
|
|
307
297
|
}
|
|
308
298
|
disconnectedCallback() {
|
|
309
299
|
var t, r;
|
|
310
|
-
|
|
300
|
+
d(this, o, $).call(this), (t = e(this, m)) == null || t.disconnect(), a(this, m, null), (r = e(this, v)) == null || r.disconnect(), a(this, v, null), d(this, o, J).call(this);
|
|
311
301
|
}
|
|
312
|
-
attributeChangedCallback(t, r,
|
|
313
|
-
|
|
302
|
+
attributeChangedCallback(t, r, l) {
|
|
303
|
+
d(this, o, W).call(this, t, l);
|
|
314
304
|
}
|
|
315
305
|
// --- Proxied properties ---
|
|
316
306
|
get src() {
|
|
@@ -426,39 +416,54 @@ canvas{display:block;width:100%;height:100%}
|
|
|
426
416
|
return e(this, i).canPlayType(t);
|
|
427
417
|
}
|
|
428
418
|
}
|
|
429
|
-
i = new WeakMap(),
|
|
419
|
+
i = new WeakMap(), p = new WeakMap(), T = new WeakMap(), H = new WeakMap(), m = new WeakMap(), v = new WeakMap(), g = new WeakMap(), b = new WeakMap(), f = new WeakMap(), C = new WeakMap(), A = new WeakMap(), S = new WeakMap(), R = new WeakMap(), o = new WeakSet(), G = function() {
|
|
420
|
+
if (e(this, A)) return;
|
|
421
|
+
const t = document.createElementNS(k, "svg");
|
|
422
|
+
t.setAttribute("width", "0"), t.setAttribute("height", "0"), t.style.cssText = "position:absolute;overflow:hidden";
|
|
423
|
+
const r = document.createElementNS(k, "defs"), l = document.createElementNS(k, "filter");
|
|
424
|
+
l.id = e(this, C), l.setAttribute("filterUnits", "userSpaceOnUse"), l.setAttribute("x", "0"), l.setAttribute("y", "0"), l.setAttribute("width", "1"), l.setAttribute("height", "1"), l.setAttribute("color-interpolation-filters", "sRGB");
|
|
425
|
+
const q = document.createElementNS(k, "feOffset");
|
|
426
|
+
q.setAttribute("in", "SourceGraphic"), q.setAttribute("dy", "0"), q.setAttribute("result", "s");
|
|
427
|
+
const M = document.createElementNS(k, "feColorMatrix");
|
|
428
|
+
M.setAttribute("in", "s"), M.setAttribute("type", "matrix"), M.setAttribute("values", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0"), M.setAttribute("result", "a");
|
|
429
|
+
const N = document.createElementNS(k, "feComposite");
|
|
430
|
+
N.setAttribute("in", "SourceGraphic"), N.setAttribute("in2", "a"), N.setAttribute("operator", "in"), l.append(q, M, N), r.appendChild(l), t.appendChild(r), document.body.appendChild(t), a(this, A, t), a(this, S, l), a(this, R, q);
|
|
431
|
+
}, J = function() {
|
|
432
|
+
var t;
|
|
433
|
+
(t = e(this, A)) == null || t.remove(), a(this, A, null), a(this, S, null), a(this, R, null);
|
|
434
|
+
}, P = function() {
|
|
430
435
|
const t = e(this, i).videoWidth, r = e(this, i).videoHeight;
|
|
431
436
|
if (!t || !r) return;
|
|
432
|
-
const
|
|
433
|
-
e(this,
|
|
434
|
-
},
|
|
435
|
-
|
|
436
|
-
},
|
|
437
|
+
const l = Math.floor(r / 2);
|
|
438
|
+
e(this, p).width = t, e(this, p).height = r, e(this, H).style.aspectRatio = `${t} / ${l}`, d(this, o, G).call(this), e(this, S).setAttribute("width", String(t)), e(this, S).setAttribute("height", String(r)), e(this, R).setAttribute("dy", String(-l));
|
|
439
|
+
}, W = function(t, r) {
|
|
440
|
+
it.has(t) ? e(this, i)[t] = r !== null : r === null ? e(this, i).removeAttribute(t) : e(this, i).setAttribute(t, r);
|
|
441
|
+
}, B = function() {
|
|
437
442
|
e(this, i).querySelectorAll("source").forEach((t) => t.remove()), this.querySelectorAll("source").forEach((t) => {
|
|
438
443
|
e(this, i).appendChild(t.cloneNode(!0));
|
|
439
444
|
}), e(this, i).querySelectorAll("source").length > 0 && !e(this, i).src && e(this, i).load();
|
|
440
|
-
},
|
|
441
|
-
if (e(this,
|
|
442
|
-
if (
|
|
445
|
+
}, K = function() {
|
|
446
|
+
if (e(this, g))
|
|
447
|
+
if (d(this, o, $).call(this), "requestVideoFrameCallback" in e(this, i)) {
|
|
443
448
|
const t = () => {
|
|
444
|
-
e(this,
|
|
449
|
+
e(this, g) && (d(this, o, z).call(this), a(this, f, e(this, i).requestVideoFrameCallback(t)));
|
|
445
450
|
};
|
|
446
|
-
a(this,
|
|
451
|
+
a(this, f, e(this, i).requestVideoFrameCallback(t));
|
|
447
452
|
} else {
|
|
448
453
|
const t = () => {
|
|
449
|
-
e(this,
|
|
454
|
+
e(this, g) && (d(this, o, z).call(this), a(this, b, requestAnimationFrame(t)));
|
|
450
455
|
};
|
|
451
|
-
a(this,
|
|
456
|
+
a(this, b, requestAnimationFrame(t));
|
|
452
457
|
}
|
|
453
|
-
},
|
|
458
|
+
}, $ = function() {
|
|
454
459
|
var t, r;
|
|
455
|
-
e(this,
|
|
456
|
-
},
|
|
460
|
+
e(this, f) && ((r = (t = e(this, i)).cancelVideoFrameCallback) == null || r.call(t, e(this, f)), a(this, f, 0)), e(this, b) && (cancelAnimationFrame(e(this, b)), a(this, b, 0));
|
|
461
|
+
}, z = function() {
|
|
457
462
|
if (e(this, i).readyState < 2) return;
|
|
458
463
|
const t = e(this, i).videoWidth, r = e(this, i).videoHeight;
|
|
459
|
-
!t || !r || ((e(this,
|
|
460
|
-
},
|
|
464
|
+
!t || !r || ((e(this, p).width !== t || e(this, p).height !== r) && d(this, o, P).call(this), e(this, T).filter = `url(#${e(this, C)})`, e(this, T).drawImage(e(this, i), 0, 0));
|
|
465
|
+
}, I(rt, "observedAttributes", [...Y]);
|
|
461
466
|
export {
|
|
462
|
-
|
|
463
|
-
|
|
467
|
+
rt as A,
|
|
468
|
+
et as a
|
|
464
469
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";var Z=Object.defineProperty;var U=h=>{throw TypeError(h)};var tt=(h,n,t)=>n in h?Z(h,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[n]=t;var $=(h,n,t)=>tt(h,typeof n!="symbol"?n+"":n,t),I=(h,n,t)=>n.has(h)||U("Cannot "+t);var e=(h,n,t)=>(I(h,n,"read from private field"),t?t.call(h):n.get(h)),u=(h,n,t)=>n.has(h)?U("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(h):n.set(h,t),a=(h,n,t,r)=>(I(h,n,"write to private field"),r?r.call(h,t):n.set(h,t),t),d=(h,n,t)=>(I(h,n,"access private method"),t);const j=["src","crossorigin","preload","autoplay","loop","muted","playsinline","poster","width","height"],et=new Set(["autoplay","loop","muted","playsinline"]),it=["loadstart","progress","suspend","abort","error","emptied","stalled","loadedmetadata","loadeddata","canplay","canplaythrough","playing","waiting","seeking","seeked","ended","durationchange","timeupdate","play","pause","ratechange","resize","volumechange"];var s,L,w,E,H,y,O,c,F,_,G;class Y extends HTMLElement{constructor(){super();u(this,c);u(this,s);u(this,L);u(this,w);u(this,E);u(this,H);u(this,y,null);u(this,O);const t=this.attachShadow({mode:"open"});a(this,O,`avk-${Math.random().toString(36).slice(2,8)}`),t.innerHTML=`<style>
|
|
2
|
+
:host{display:inline-block;overflow:hidden}
|
|
3
|
+
svg{display:block;width:100%;height:auto}
|
|
4
|
+
video{display:block;width:100%;height:100%}
|
|
5
|
+
</style>
|
|
6
|
+
<svg viewBox="0 0 1 1" preserveAspectRatio="xMidYMid meet">
|
|
7
|
+
<defs>
|
|
8
|
+
<filter id="${e(this,O)}" filterUnits="userSpaceOnUse" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
|
|
9
|
+
<feOffset in="SourceGraphic" dy="0" result="s"/>
|
|
10
|
+
<feColorMatrix in="s" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0" result="a"/>
|
|
11
|
+
<feComposite in="SourceGraphic" in2="a" operator="in"/>
|
|
12
|
+
</filter>
|
|
13
|
+
</defs>
|
|
14
|
+
<foreignObject width="1" height="1" filter="url(#${e(this,O)})">
|
|
15
|
+
<video></video>
|
|
16
|
+
</foreignObject>
|
|
17
|
+
</svg>`,a(this,L,t.querySelector("svg")),a(this,w,t.querySelector("foreignObject")),a(this,E,t.querySelector("filter")),a(this,H,t.querySelector("feOffset")),a(this,s,t.querySelector("video"));for(const r of it)e(this,s).addEventListener(r,l=>{this.dispatchEvent(new Event(l.type,{bubbles:!1,cancelable:!1}))});e(this,s).addEventListener("loadedmetadata",()=>d(this,c,F).call(this)),e(this,s).addEventListener("resize",()=>d(this,c,F).call(this))}connectedCallback(){for(const t of j)this.hasAttribute(t)&&d(this,c,_).call(this,t,this.getAttribute(t));d(this,c,G).call(this),a(this,y,new MutationObserver(()=>d(this,c,G).call(this))),e(this,y).observe(this,{childList:!0})}disconnectedCallback(){var t;(t=e(this,y))==null||t.disconnect(),a(this,y,null)}attributeChangedCallback(t,r,l){d(this,c,_).call(this,t,l)}get src(){return e(this,s).src}set src(t){this.setAttribute("src",t)}get currentSrc(){return e(this,s).currentSrc}get currentTime(){return e(this,s).currentTime}set currentTime(t){e(this,s).currentTime=t}get duration(){return e(this,s).duration}get paused(){return e(this,s).paused}get ended(){return e(this,s).ended}get readyState(){return e(this,s).readyState}get videoWidth(){return e(this,s).videoWidth}get videoHeight(){return Math.floor(e(this,s).videoHeight/2)}get volume(){return e(this,s).volume}set volume(t){e(this,s).volume=t}get playbackRate(){return e(this,s).playbackRate}set playbackRate(t){e(this,s).playbackRate=t}get defaultPlaybackRate(){return e(this,s).defaultPlaybackRate}set defaultPlaybackRate(t){e(this,s).defaultPlaybackRate=t}get muted(){return e(this,s).muted}set muted(t){e(this,s).muted=t,this.toggleAttribute("muted",t)}get loop(){return e(this,s).loop}set loop(t){e(this,s).loop=t,this.toggleAttribute("loop",t)}get autoplay(){return e(this,s).autoplay}set autoplay(t){e(this,s).autoplay=t,this.toggleAttribute("autoplay",t)}get preload(){return e(this,s).preload}set preload(t){this.setAttribute("preload",t)}get crossOrigin(){return e(this,s).crossOrigin}set crossOrigin(t){t===null?this.removeAttribute("crossorigin"):this.setAttribute("crossorigin",t)}get buffered(){return e(this,s).buffered}get seekable(){return e(this,s).seekable}get played(){return e(this,s).played}get networkState(){return e(this,s).networkState}get error(){return e(this,s).error}get seeking(){return e(this,s).seeking}play(){return e(this,s).play()}pause(){e(this,s).pause()}load(){e(this,s).load()}canPlayType(t){return e(this,s).canPlayType(t)}}s=new WeakMap,L=new WeakMap,w=new WeakMap,E=new WeakMap,H=new WeakMap,y=new WeakMap,O=new WeakMap,c=new WeakSet,F=function(){const t=e(this,s).videoWidth,r=e(this,s).videoHeight;if(!t||!r)return;const l=Math.floor(r/2);e(this,L).setAttribute("viewBox",`0 0 ${t} ${l}`),e(this,w).setAttribute("width",String(t)),e(this,w).setAttribute("height",String(r)),e(this,E).setAttribute("width",String(t)),e(this,E).setAttribute("height",String(r)),e(this,H).setAttribute("dy",String(-l))},_=function(t,r){et.has(t)?e(this,s)[t]=r!==null:r===null?e(this,s).removeAttribute(t):e(this,s).setAttribute(t,r)},G=function(){e(this,s).querySelectorAll("source").forEach(t=>t.remove()),this.querySelectorAll("source").forEach(t=>{e(this,s).appendChild(t.cloneNode(!0))}),e(this,s).querySelectorAll("source").length>0&&!e(this,s).src&&e(this,s).load()},$(Y,"observedAttributes",[...j]);const k="http://www.w3.org/2000/svg",K=["src","crossorigin","preload","autoplay","loop","muted","playsinline","poster","width","height"],st=new Set(["autoplay","loop","muted","playsinline"]),rt=["loadstart","progress","suspend","abort","error","emptied","stalled","loadedmetadata","loadeddata","canplay","canplaythrough","playing","waiting","seeking","seeked","ended","durationchange","timeupdate","play","pause","ratechange","resize","volumechange"];var i,p,T,x,m,v,g,b,f,C,A,S,R,o,D,Q,V,W,B,X,P,z;class J extends HTMLElement{constructor(){super();u(this,o);u(this,i);u(this,p);u(this,T);u(this,x);u(this,m,null);u(this,v,null);u(this,g,!1);u(this,b,0);u(this,f,0);u(this,C);u(this,A,null);u(this,S,null);u(this,R,null);const t=this.attachShadow({mode:"open"});a(this,C,`avk-c-${Math.random().toString(36).slice(2,8)}`),t.innerHTML=`<style>
|
|
18
|
+
:host{display:inline-block;overflow:hidden}
|
|
19
|
+
video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
|
|
20
|
+
.clip{overflow:hidden;width:100%}
|
|
21
|
+
canvas{display:block;width:100%}
|
|
22
|
+
</style>
|
|
23
|
+
<video></video>
|
|
24
|
+
<div class="clip"><canvas></canvas></div>`,a(this,i,t.querySelector("video")),a(this,x,t.querySelector(".clip")),a(this,p,t.querySelector("canvas")),a(this,T,e(this,p).getContext("2d"));for(const r of rt)e(this,i).addEventListener(r,l=>{this.dispatchEvent(new Event(l.type,{bubbles:!1,cancelable:!1}))});e(this,i).addEventListener("loadedmetadata",()=>d(this,o,V).call(this)),e(this,i).addEventListener("resize",()=>d(this,o,V).call(this))}connectedCallback(){for(const t of K)this.hasAttribute(t)&&d(this,o,W).call(this,t,this.getAttribute(t));d(this,o,B).call(this),a(this,v,new MutationObserver(()=>d(this,o,B).call(this))),e(this,v).observe(this,{childList:!0}),d(this,o,D).call(this),a(this,m,new IntersectionObserver(([t])=>{a(this,g,t.isIntersecting),e(this,g)?d(this,o,X).call(this):d(this,o,P).call(this)},{threshold:0})),e(this,m).observe(this)}disconnectedCallback(){var t,r;d(this,o,P).call(this),(t=e(this,m))==null||t.disconnect(),a(this,m,null),(r=e(this,v))==null||r.disconnect(),a(this,v,null),d(this,o,Q).call(this)}attributeChangedCallback(t,r,l){d(this,o,W).call(this,t,l)}get src(){return e(this,i).src}set src(t){this.setAttribute("src",t)}get currentSrc(){return e(this,i).currentSrc}get currentTime(){return e(this,i).currentTime}set currentTime(t){e(this,i).currentTime=t}get duration(){return e(this,i).duration}get paused(){return e(this,i).paused}get ended(){return e(this,i).ended}get readyState(){return e(this,i).readyState}get videoWidth(){return e(this,i).videoWidth}get videoHeight(){return Math.floor(e(this,i).videoHeight/2)}get volume(){return e(this,i).volume}set volume(t){e(this,i).volume=t}get playbackRate(){return e(this,i).playbackRate}set playbackRate(t){e(this,i).playbackRate=t}get defaultPlaybackRate(){return e(this,i).defaultPlaybackRate}set defaultPlaybackRate(t){e(this,i).defaultPlaybackRate=t}get muted(){return e(this,i).muted}set muted(t){e(this,i).muted=t,this.toggleAttribute("muted",t)}get loop(){return e(this,i).loop}set loop(t){e(this,i).loop=t,this.toggleAttribute("loop",t)}get autoplay(){return e(this,i).autoplay}set autoplay(t){e(this,i).autoplay=t,this.toggleAttribute("autoplay",t)}get preload(){return e(this,i).preload}set preload(t){this.setAttribute("preload",t)}get crossOrigin(){return e(this,i).crossOrigin}set crossOrigin(t){t===null?this.removeAttribute("crossorigin"):this.setAttribute("crossorigin",t)}get buffered(){return e(this,i).buffered}get seekable(){return e(this,i).seekable}get played(){return e(this,i).played}get networkState(){return e(this,i).networkState}get error(){return e(this,i).error}get seeking(){return e(this,i).seeking}play(){return e(this,i).play()}pause(){e(this,i).pause()}load(){e(this,i).load()}canPlayType(t){return e(this,i).canPlayType(t)}}i=new WeakMap,p=new WeakMap,T=new WeakMap,x=new WeakMap,m=new WeakMap,v=new WeakMap,g=new WeakMap,b=new WeakMap,f=new WeakMap,C=new WeakMap,A=new WeakMap,S=new WeakMap,R=new WeakMap,o=new WeakSet,D=function(){if(e(this,A))return;const t=document.createElementNS(k,"svg");t.setAttribute("width","0"),t.setAttribute("height","0"),t.style.cssText="position:absolute;overflow:hidden";const r=document.createElementNS(k,"defs"),l=document.createElementNS(k,"filter");l.id=e(this,C),l.setAttribute("filterUnits","userSpaceOnUse"),l.setAttribute("x","0"),l.setAttribute("y","0"),l.setAttribute("width","1"),l.setAttribute("height","1"),l.setAttribute("color-interpolation-filters","sRGB");const q=document.createElementNS(k,"feOffset");q.setAttribute("in","SourceGraphic"),q.setAttribute("dy","0"),q.setAttribute("result","s");const M=document.createElementNS(k,"feColorMatrix");M.setAttribute("in","s"),M.setAttribute("type","matrix"),M.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0"),M.setAttribute("result","a");const N=document.createElementNS(k,"feComposite");N.setAttribute("in","SourceGraphic"),N.setAttribute("in2","a"),N.setAttribute("operator","in"),l.append(q,M,N),r.appendChild(l),t.appendChild(r),document.body.appendChild(t),a(this,A,t),a(this,S,l),a(this,R,q)},Q=function(){var t;(t=e(this,A))==null||t.remove(),a(this,A,null),a(this,S,null),a(this,R,null)},V=function(){const t=e(this,i).videoWidth,r=e(this,i).videoHeight;if(!t||!r)return;const l=Math.floor(r/2);e(this,p).width=t,e(this,p).height=r,e(this,x).style.aspectRatio=`${t} / ${l}`,d(this,o,D).call(this),e(this,S).setAttribute("width",String(t)),e(this,S).setAttribute("height",String(r)),e(this,R).setAttribute("dy",String(-l))},W=function(t,r){st.has(t)?e(this,i)[t]=r!==null:r===null?e(this,i).removeAttribute(t):e(this,i).setAttribute(t,r)},B=function(){e(this,i).querySelectorAll("source").forEach(t=>t.remove()),this.querySelectorAll("source").forEach(t=>{e(this,i).appendChild(t.cloneNode(!0))}),e(this,i).querySelectorAll("source").length>0&&!e(this,i).src&&e(this,i).load()},X=function(){if(e(this,g))if(d(this,o,P).call(this),"requestVideoFrameCallback"in e(this,i)){const t=()=>{e(this,g)&&(d(this,o,z).call(this),a(this,f,e(this,i).requestVideoFrameCallback(t)))};a(this,f,e(this,i).requestVideoFrameCallback(t))}else{const t=()=>{e(this,g)&&(d(this,o,z).call(this),a(this,b,requestAnimationFrame(t)))};a(this,b,requestAnimationFrame(t))}},P=function(){var t,r;e(this,f)&&((r=(t=e(this,i)).cancelVideoFrameCallback)==null||r.call(t,e(this,f)),a(this,f,0)),e(this,b)&&(cancelAnimationFrame(e(this,b)),a(this,b,0))},z=function(){if(e(this,i).readyState<2)return;const t=e(this,i).videoWidth,r=e(this,i).videoHeight;!t||!r||((e(this,p).width!==t||e(this,p).height!==r)&&d(this,o,V).call(this),e(this,T).filter=`url(#${e(this,C)})`,e(this,T).drawImage(e(this,i),0,0))},$(J,"observedAttributes",[...K]);exports.AlphaVideoKitCanvas=J;exports.AlphaVideoKitSVG=Y;
|
package/dist/index.cjs
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
3
|
-
width="${e}" height="${t}"
|
|
4
|
-
viewBox="0 0 ${e} ${t}">
|
|
5
|
-
<defs>
|
|
6
|
-
<filter id="r2a" color-interpolation-filters="sRGB">
|
|
7
|
-
<feColorMatrix type="matrix"
|
|
8
|
-
values="0 0 0 0 1
|
|
9
|
-
0 0 0 0 1
|
|
10
|
-
0 0 0 0 1
|
|
11
|
-
1 0 0 0 0"/>
|
|
12
|
-
</filter>
|
|
13
|
-
<mask id="alphaMask">
|
|
14
|
-
<svg viewBox="0 ${t} ${e} ${t}"
|
|
15
|
-
width="${e}" height="${t}"
|
|
16
|
-
preserveAspectRatio="none">
|
|
17
|
-
<image href="${o}"
|
|
18
|
-
width="${e}" height="${n}"
|
|
19
|
-
filter="url(#r2a)"/>
|
|
20
|
-
</svg>
|
|
21
|
-
</mask>
|
|
22
|
-
</defs>
|
|
23
|
-
<svg viewBox="0 0 ${e} ${t}"
|
|
24
|
-
width="${e}" height="${t}"
|
|
25
|
-
preserveAspectRatio="none"
|
|
26
|
-
mask="url(#alphaMask)">
|
|
27
|
-
<image href="${o}"
|
|
28
|
-
width="${e}" height="${n}"/>
|
|
29
|
-
</svg>
|
|
30
|
-
</svg>`}return{drawFrame(o){if(s)return;const e=o.videoWidth,t=o.videoHeight,n=Math.floor(t/2);(r.width!==e||r.height!==n)&&(r.width=e,r.height=n),(l.width!==e||l.height!==t)&&(l.width=e,l.height=t),d.drawImage(o,0,0);const h=l.toDataURL("image/png"),f=g(h,e,n,t),m=new Blob([f],{type:"image/svg+xml"}),a=URL.createObjectURL(m),v=new Image;v.onload=()=>{if(s){URL.revokeObjectURL(a);return}c.clearRect(0,0,e,n),c.drawImage(v,0,0),URL.revokeObjectURL(a)},v.src=a},setPremultipliedAlpha(o){},destroy(){s||(s=!0)},get isDestroyed(){return s}}}function $(u){const{canvas:r,premultipliedAlpha:c=!1}=u,l=r.getContext("2d",{willReadFrequently:!0}),d=document.createElement("canvas"),s=d.getContext("2d",{willReadFrequently:!0});let g=!1,o=c;return{drawFrame(e){if(g)return;const t=e.videoWidth,n=e.videoHeight,h=Math.floor(n/2);(r.width!==t||r.height!==h)&&(r.width=t,r.height=h),(d.width!==t||d.height!==n)&&(d.width=t,d.height=n),s.drawImage(e,0,0);const f=s.getImageData(0,0,t,h),m=s.getImageData(0,h,t,h),a=f.data,v=m.data;for(let i=0;i<a.length;i+=4){const p=v[i];if(o)a[i+3]=p;else{const w=p/255;a[i]=Math.round(a[i]*w),a[i+1]=Math.round(a[i+1]*w),a[i+2]=Math.round(a[i+2]*w),a[i+3]=p}}l.putImageData(f,0,0)},setPremultipliedAlpha(e){o=e},destroy(){g||(g=!0)},get isDestroyed(){return g}}}function C(u){const{mode:r="canvas",...c}=u;return r==="svg-filter"?R(c):$(c)}exports.AlphaVideoKitCanvas=x.AlphaVideoKitCanvas;exports.AlphaVideoKitSVG=x.AlphaVideoKitSVG;exports.createCanvasFilterRenderer=$;exports.createRenderer=C;exports.createSvgFilterRenderer=R;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("./canvas-component-CE05m0PN.cjs"),s="http://www.w3.org/2000/svg";function b(d){const{canvas:o}=d,f=o.getContext("2d"),p=`avk-f-${Math.random().toString(36).slice(2,8)}`;let i=null,u=null,h=null,a=!1;function m(){if(i)return;const e=document.createElementNS(s,"svg");e.setAttribute("width","0"),e.setAttribute("height","0"),e.style.cssText="position:absolute;overflow:hidden";const n=document.createElementNS(s,"defs"),t=document.createElementNS(s,"filter");t.id=p,t.setAttribute("filterUnits","userSpaceOnUse"),t.setAttribute("x","0"),t.setAttribute("y","0"),t.setAttribute("width","1"),t.setAttribute("height","1"),t.setAttribute("color-interpolation-filters","sRGB");const r=document.createElementNS(s,"feOffset");r.setAttribute("in","SourceGraphic"),r.setAttribute("dy","0"),r.setAttribute("result","s");const l=document.createElementNS(s,"feColorMatrix");l.setAttribute("in","s"),l.setAttribute("type","matrix"),l.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0"),l.setAttribute("result","a");const c=document.createElementNS(s,"feComposite");c.setAttribute("in","SourceGraphic"),c.setAttribute("in2","a"),c.setAttribute("operator","in"),t.append(r,l,c),n.appendChild(t),e.appendChild(n),document.body.appendChild(e),i=e,u=t,h=r}return{drawFrame(e){if(a)return;const n=e.videoWidth,t=e.videoHeight,r=Math.floor(t/2);(o.width!==n||o.height!==r)&&(o.width=n,o.height=r),m(),u.setAttribute("width",String(n)),u.setAttribute("height",String(t)),h.setAttribute("dy",String(-r)),f.filter=`url(#${p})`,f.drawImage(e,0,0)},setPremultipliedAlpha(e){},destroy(){a||(a=!0,i==null||i.remove(),i=null,u=null,h=null)},get isDestroyed(){return a}}}function g(d){return b(d)}exports.AlphaVideoKitCanvas=A.AlphaVideoKitCanvas;exports.AlphaVideoKitSVG=A.AlphaVideoKitSVG;exports.createRenderer=g;exports.createSvgFilterRenderer=b;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `<alpha-video-kit-canvas>` — Canvas 2D
|
|
2
|
+
* `<alpha-video-kit-canvas>` — Canvas 2D with SVG filter via ctx.filter.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* <foreignObject W×H filter> ← full-height canvas with filter applied
|
|
9
|
-
* <canvas>
|
|
10
|
-
*
|
|
11
|
-
* A hidden <video> feeds frames to <canvas> via drawImage (full stacked frame).
|
|
12
|
-
* The SVG filter composites the stacked-alpha halves.
|
|
13
|
-
* SVG viewBox clips to the top (color) half.
|
|
4
|
+
* A hidden <video> feeds frames to <canvas> via drawImage.
|
|
5
|
+
* The SVG filter (injected into document.body) composites stacked-alpha halves.
|
|
6
|
+
* ctx.filter = 'url(#id)' applies the filter during drawImage.
|
|
7
|
+
* A wrapper div clips the canvas to the top (color) half.
|
|
14
8
|
*/
|
|
15
9
|
export declare class AlphaVideoKitCanvas extends HTMLElement {
|
|
16
10
|
#private;
|
|
17
|
-
static observedAttributes: ("
|
|
11
|
+
static observedAttributes: ("width" | "height" | "src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster")[];
|
|
18
12
|
constructor();
|
|
19
13
|
connectedCallback(): void;
|
|
20
14
|
disconnectedCallback(): void;
|
|
@@ -72,7 +66,7 @@ export declare class AlphaVideoKitCanvas extends HTMLElement {
|
|
|
72
66
|
*/
|
|
73
67
|
export declare class AlphaVideoKitSVG extends HTMLElement {
|
|
74
68
|
#private;
|
|
75
|
-
static observedAttributes: ("
|
|
69
|
+
static observedAttributes: ("width" | "height" | "src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster")[];
|
|
76
70
|
constructor();
|
|
77
71
|
connectedCallback(): void;
|
|
78
72
|
disconnectedCallback(): void;
|
|
@@ -116,20 +110,17 @@ export declare class AlphaVideoKitSVG extends HTMLElement {
|
|
|
116
110
|
canPlayType(type: string): CanPlayTypeResult;
|
|
117
111
|
}
|
|
118
112
|
|
|
119
|
-
|
|
120
|
-
* Canvas 2D renderer with pixel manipulation.
|
|
121
|
-
* Draws the video to an offscreen canvas, reads pixels from top and bottom halves,
|
|
122
|
-
* applies alpha from the bottom half to the top half's color data.
|
|
123
|
-
* No SVG filters used — pure Canvas 2D fallback for maximum compatibility.
|
|
124
|
-
*/
|
|
125
|
-
export declare function createCanvasFilterRenderer(options: StackedAlphaRendererOptions): StackedAlphaRenderer;
|
|
126
|
-
|
|
127
|
-
export declare function createRenderer(options: SvgRendererOptions): StackedAlphaRenderer;
|
|
113
|
+
export declare function createRenderer(options: StackedAlphaRendererOptions): StackedAlphaRenderer;
|
|
128
114
|
|
|
129
115
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
116
|
+
* SVG filter renderer using ctx.filter on Canvas 2D.
|
|
117
|
+
*
|
|
118
|
+
* Injects an SVG <filter> into document.body, then on each frame:
|
|
119
|
+
* ctx.filter = 'url(#id)';
|
|
120
|
+
* ctx.drawImage(video, 0, 0);
|
|
121
|
+
*
|
|
122
|
+
* The filter shifts the bottom (alpha) half up, extracts R→alpha,
|
|
123
|
+
* and composites it over the top (color) half.
|
|
133
124
|
*/
|
|
134
125
|
export declare function createSvgFilterRenderer(options: StackedAlphaRendererOptions): StackedAlphaRenderer;
|
|
135
126
|
|
|
@@ -145,10 +136,4 @@ export declare interface StackedAlphaRendererOptions {
|
|
|
145
136
|
premultipliedAlpha?: boolean;
|
|
146
137
|
}
|
|
147
138
|
|
|
148
|
-
export declare type SvgRendererMode = 'svg-filter' | 'canvas';
|
|
149
|
-
|
|
150
|
-
export declare interface SvgRendererOptions extends StackedAlphaRendererOptions {
|
|
151
|
-
mode?: SvgRendererMode;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
139
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,102 +1,43 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<mask id="alphaMask">
|
|
19
|
-
<svg viewBox="0 ${t} ${e} ${t}"
|
|
20
|
-
width="${e}" height="${t}"
|
|
21
|
-
preserveAspectRatio="none">
|
|
22
|
-
<image href="${s}"
|
|
23
|
-
width="${e}" height="${n}"
|
|
24
|
-
filter="url(#r2a)"/>
|
|
25
|
-
</svg>
|
|
26
|
-
</mask>
|
|
27
|
-
</defs>
|
|
28
|
-
<svg viewBox="0 0 ${e} ${t}"
|
|
29
|
-
width="${e}" height="${t}"
|
|
30
|
-
preserveAspectRatio="none"
|
|
31
|
-
mask="url(#alphaMask)">
|
|
32
|
-
<image href="${s}"
|
|
33
|
-
width="${e}" height="${n}"/>
|
|
34
|
-
</svg>
|
|
35
|
-
</svg>`;
|
|
1
|
+
import { A as w, a as v } from "./canvas-component-C3vC6FBw.js";
|
|
2
|
+
const s = "http://www.w3.org/2000/svg";
|
|
3
|
+
function b(d) {
|
|
4
|
+
const { canvas: o } = d, h = o.getContext("2d"), A = `avk-f-${Math.random().toString(36).slice(2, 8)}`;
|
|
5
|
+
let i = null, l = null, f = null, a = !1;
|
|
6
|
+
function p() {
|
|
7
|
+
if (i) return;
|
|
8
|
+
const e = document.createElementNS(s, "svg");
|
|
9
|
+
e.setAttribute("width", "0"), e.setAttribute("height", "0"), e.style.cssText = "position:absolute;overflow:hidden";
|
|
10
|
+
const n = document.createElementNS(s, "defs"), t = document.createElementNS(s, "filter");
|
|
11
|
+
t.id = A, t.setAttribute("filterUnits", "userSpaceOnUse"), t.setAttribute("x", "0"), t.setAttribute("y", "0"), t.setAttribute("width", "1"), t.setAttribute("height", "1"), t.setAttribute("color-interpolation-filters", "sRGB");
|
|
12
|
+
const r = document.createElementNS(s, "feOffset");
|
|
13
|
+
r.setAttribute("in", "SourceGraphic"), r.setAttribute("dy", "0"), r.setAttribute("result", "s");
|
|
14
|
+
const u = document.createElementNS(s, "feColorMatrix");
|
|
15
|
+
u.setAttribute("in", "s"), u.setAttribute("type", "matrix"), u.setAttribute("values", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0"), u.setAttribute("result", "a");
|
|
16
|
+
const c = document.createElementNS(s, "feComposite");
|
|
17
|
+
c.setAttribute("in", "SourceGraphic"), c.setAttribute("in2", "a"), c.setAttribute("operator", "in"), t.append(r, u, c), n.appendChild(t), e.appendChild(n), document.body.appendChild(e), i = e, l = t, f = r;
|
|
36
18
|
}
|
|
37
|
-
return {
|
|
38
|
-
drawFrame(s) {
|
|
39
|
-
if (i) return;
|
|
40
|
-
const e = s.videoWidth, t = s.videoHeight, n = Math.floor(t / 2);
|
|
41
|
-
(r.width !== e || r.height !== n) && (r.width = e, r.height = n), (l.width !== e || l.height !== t) && (l.width = e, l.height = t), d.drawImage(s, 0, 0);
|
|
42
|
-
const h = l.toDataURL("image/png"), m = g(h, e, n, t), p = new Blob([m], { type: "image/svg+xml" }), a = URL.createObjectURL(p), f = new Image();
|
|
43
|
-
f.onload = () => {
|
|
44
|
-
if (i) {
|
|
45
|
-
URL.revokeObjectURL(a);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
c.clearRect(0, 0, e, n), c.drawImage(f, 0, 0), URL.revokeObjectURL(a);
|
|
49
|
-
}, f.src = a;
|
|
50
|
-
},
|
|
51
|
-
setPremultipliedAlpha(s) {
|
|
52
|
-
},
|
|
53
|
-
destroy() {
|
|
54
|
-
i || (i = !0);
|
|
55
|
-
},
|
|
56
|
-
get isDestroyed() {
|
|
57
|
-
return i;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function $(u) {
|
|
62
|
-
const { canvas: r, premultipliedAlpha: c = !1 } = u, l = r.getContext("2d", { willReadFrequently: !0 }), d = document.createElement("canvas"), i = d.getContext("2d", { willReadFrequently: !0 });
|
|
63
|
-
let g = !1, s = c;
|
|
64
19
|
return {
|
|
65
20
|
drawFrame(e) {
|
|
66
|
-
if (
|
|
67
|
-
const
|
|
68
|
-
(
|
|
69
|
-
const m = i.getImageData(0, 0, t, h), p = i.getImageData(0, h, t, h), a = m.data, f = p.data;
|
|
70
|
-
for (let o = 0; o < a.length; o += 4) {
|
|
71
|
-
const v = f[o];
|
|
72
|
-
if (s)
|
|
73
|
-
a[o + 3] = v;
|
|
74
|
-
else {
|
|
75
|
-
const w = v / 255;
|
|
76
|
-
a[o] = Math.round(a[o] * w), a[o + 1] = Math.round(a[o + 1] * w), a[o + 2] = Math.round(a[o + 2] * w), a[o + 3] = v;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
l.putImageData(m, 0, 0);
|
|
21
|
+
if (a) return;
|
|
22
|
+
const n = e.videoWidth, t = e.videoHeight, r = Math.floor(t / 2);
|
|
23
|
+
(o.width !== n || o.height !== r) && (o.width = n, o.height = r), p(), l.setAttribute("width", String(n)), l.setAttribute("height", String(t)), f.setAttribute("dy", String(-r)), h.filter = `url(#${A})`, h.drawImage(e, 0, 0);
|
|
80
24
|
},
|
|
81
25
|
setPremultipliedAlpha(e) {
|
|
82
|
-
s = e;
|
|
83
26
|
},
|
|
84
27
|
destroy() {
|
|
85
|
-
|
|
28
|
+
a || (a = !0, i == null || i.remove(), i = null, l = null, f = null);
|
|
86
29
|
},
|
|
87
30
|
get isDestroyed() {
|
|
88
|
-
return
|
|
31
|
+
return a;
|
|
89
32
|
}
|
|
90
33
|
};
|
|
91
34
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
return r === "svg-filter" ? x(c) : $(c);
|
|
35
|
+
function m(d) {
|
|
36
|
+
return b(d);
|
|
95
37
|
}
|
|
96
38
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
x as createSvgFilterRenderer
|
|
39
|
+
w as AlphaVideoKitCanvas,
|
|
40
|
+
v as AlphaVideoKitSVG,
|
|
41
|
+
m as createRenderer,
|
|
42
|
+
b as createSvgFilterRenderer
|
|
102
43
|
};
|
package/dist/register.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("./canvas-component-
|
|
1
|
+
"use strict";const e=require("./canvas-component-CE05m0PN.cjs");customElements.get("alpha-video-kit-svg")||customElements.define("alpha-video-kit-svg",e.AlphaVideoKitSVG);customElements.get("alpha-video-kit-canvas")||customElements.define("alpha-video-kit-canvas",e.AlphaVideoKitCanvas);
|
package/dist/register.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as e, A as a } from "./canvas-component-
|
|
1
|
+
import { a as e, A as a } from "./canvas-component-C3vC6FBw.js";
|
|
2
2
|
customElements.get("alpha-video-kit-svg") || customElements.define("alpha-video-kit-svg", e);
|
|
3
3
|
customElements.get("alpha-video-kit-canvas") || customElements.define("alpha-video-kit-canvas", a);
|
package/package.json
CHANGED
package/react.d.ts
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
|
+
import type React from 'react';
|
|
1
2
|
import type { AlphaVideoKitSVG } from './dist/index.js';
|
|
2
3
|
import type { AlphaVideoKitCanvas } from './dist/index.js';
|
|
3
4
|
|
|
4
|
-
interface AlphaVideoKitSVGAttributes extends React.
|
|
5
|
+
interface AlphaVideoKitSVGAttributes extends React.VideoHTMLAttributes<AlphaVideoKitSVG> {
|
|
5
6
|
ref?: React.Ref<AlphaVideoKitSVG>;
|
|
6
|
-
src?: string;
|
|
7
|
-
crossOrigin?: string;
|
|
8
|
-
preload?: string;
|
|
9
|
-
autoPlay?: boolean;
|
|
10
|
-
loop?: boolean;
|
|
11
|
-
muted?: boolean;
|
|
12
|
-
playsInline?: boolean;
|
|
13
|
-
poster?: string;
|
|
14
|
-
width?: number | string;
|
|
15
|
-
height?: number | string;
|
|
16
7
|
}
|
|
17
8
|
|
|
18
|
-
interface AlphaVideoKitCanvasAttributes extends React.
|
|
9
|
+
interface AlphaVideoKitCanvasAttributes extends React.VideoHTMLAttributes<AlphaVideoKitCanvas> {
|
|
19
10
|
ref?: React.Ref<AlphaVideoKitCanvas>;
|
|
20
|
-
src?: string;
|
|
21
|
-
crossOrigin?: string;
|
|
22
|
-
preload?: string;
|
|
23
|
-
autoPlay?: boolean;
|
|
24
|
-
loop?: boolean;
|
|
25
|
-
muted?: boolean;
|
|
26
|
-
playsInline?: boolean;
|
|
27
|
-
poster?: string;
|
|
28
|
-
width?: number | string;
|
|
29
|
-
height?: number | string;
|
|
30
11
|
}
|
|
31
12
|
|
|
32
13
|
declare module 'react' {
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var G=o=>{throw TypeError(o)};var K=(o,h,t)=>h in o?U(o,h,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[h]=t;var H=(o,h,t)=>K(o,typeof h!="symbol"?h+"":h,t),$=(o,h,t)=>h.has(o)||G("Cannot "+t);var e=(o,h,t)=>($(o,h,"read from private field"),t?t.call(o):h.get(o)),l=(o,h,t)=>h.has(o)?G("Cannot add the same private member more than once"):h instanceof WeakSet?h.add(o):h.set(o,t),a=(o,h,t,r)=>($(o,h,"write to private field"),r?r.call(o,t):h.set(o,t),t),u=(o,h,t)=>($(o,h,"access private method"),t);const W=["src","crossorigin","preload","autoplay","loop","muted","playsinline","poster","width","height"],Y=new Set(["autoplay","loop","muted","playsinline"]),J=["loadstart","progress","suspend","abort","error","emptied","stalled","loadedmetadata","loadeddata","canplay","canplaythrough","playing","waiting","seeking","seeked","ended","durationchange","timeupdate","play","pause","ratechange","resize","volumechange"];var s,T,S,A,R,y,k,c,P,V,I;class D extends HTMLElement{constructor(){super();l(this,c);l(this,s);l(this,T);l(this,S);l(this,A);l(this,R);l(this,y,null);l(this,k);const t=this.attachShadow({mode:"open"});a(this,k,`avk-${Math.random().toString(36).slice(2,8)}`),t.innerHTML=`<style>
|
|
2
|
-
:host{display:inline-block;overflow:hidden}
|
|
3
|
-
svg{display:block;width:100%;height:auto}
|
|
4
|
-
video{display:block;width:100%;height:100%}
|
|
5
|
-
</style>
|
|
6
|
-
<svg viewBox="0 0 1 1" preserveAspectRatio="xMidYMid meet">
|
|
7
|
-
<defs>
|
|
8
|
-
<filter id="${e(this,k)}" filterUnits="userSpaceOnUse" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
|
|
9
|
-
<feOffset in="SourceGraphic" dy="0" result="s"/>
|
|
10
|
-
<feColorMatrix in="s" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0" result="a"/>
|
|
11
|
-
<feComposite in="SourceGraphic" in2="a" operator="in"/>
|
|
12
|
-
</filter>
|
|
13
|
-
</defs>
|
|
14
|
-
<foreignObject width="1" height="1" filter="url(#${e(this,k)})">
|
|
15
|
-
<video></video>
|
|
16
|
-
</foreignObject>
|
|
17
|
-
</svg>`,a(this,T,t.querySelector("svg")),a(this,S,t.querySelector("foreignObject")),a(this,A,t.querySelector("filter")),a(this,R,t.querySelector("feOffset")),a(this,s,t.querySelector("video"));for(const r of J)e(this,s).addEventListener(r,d=>{this.dispatchEvent(new Event(d.type,{bubbles:!1,cancelable:!1}))});e(this,s).addEventListener("loadedmetadata",()=>u(this,c,P).call(this)),e(this,s).addEventListener("resize",()=>u(this,c,P).call(this))}connectedCallback(){for(const t of W)this.hasAttribute(t)&&u(this,c,V).call(this,t,this.getAttribute(t));u(this,c,I).call(this),a(this,y,new MutationObserver(()=>u(this,c,I).call(this))),e(this,y).observe(this,{childList:!0})}disconnectedCallback(){var t;(t=e(this,y))==null||t.disconnect(),a(this,y,null)}attributeChangedCallback(t,r,d){u(this,c,V).call(this,t,d)}get src(){return e(this,s).src}set src(t){this.setAttribute("src",t)}get currentSrc(){return e(this,s).currentSrc}get currentTime(){return e(this,s).currentTime}set currentTime(t){e(this,s).currentTime=t}get duration(){return e(this,s).duration}get paused(){return e(this,s).paused}get ended(){return e(this,s).ended}get readyState(){return e(this,s).readyState}get videoWidth(){return e(this,s).videoWidth}get videoHeight(){return Math.floor(e(this,s).videoHeight/2)}get volume(){return e(this,s).volume}set volume(t){e(this,s).volume=t}get playbackRate(){return e(this,s).playbackRate}set playbackRate(t){e(this,s).playbackRate=t}get defaultPlaybackRate(){return e(this,s).defaultPlaybackRate}set defaultPlaybackRate(t){e(this,s).defaultPlaybackRate=t}get muted(){return e(this,s).muted}set muted(t){e(this,s).muted=t,this.toggleAttribute("muted",t)}get loop(){return e(this,s).loop}set loop(t){e(this,s).loop=t,this.toggleAttribute("loop",t)}get autoplay(){return e(this,s).autoplay}set autoplay(t){e(this,s).autoplay=t,this.toggleAttribute("autoplay",t)}get preload(){return e(this,s).preload}set preload(t){this.setAttribute("preload",t)}get crossOrigin(){return e(this,s).crossOrigin}set crossOrigin(t){t===null?this.removeAttribute("crossorigin"):this.setAttribute("crossorigin",t)}get buffered(){return e(this,s).buffered}get seekable(){return e(this,s).seekable}get played(){return e(this,s).played}get networkState(){return e(this,s).networkState}get error(){return e(this,s).error}get seeking(){return e(this,s).seeking}play(){return e(this,s).play()}pause(){e(this,s).pause()}load(){e(this,s).load()}canPlayType(t){return e(this,s).canPlayType(t)}}s=new WeakMap,T=new WeakMap,S=new WeakMap,A=new WeakMap,R=new WeakMap,y=new WeakMap,k=new WeakMap,c=new WeakSet,P=function(){const t=e(this,s).videoWidth,r=e(this,s).videoHeight;if(!t||!r)return;const d=Math.floor(r/2);e(this,T).setAttribute("viewBox",`0 0 ${t} ${d}`),e(this,S).setAttribute("width",String(t)),e(this,S).setAttribute("height",String(r)),e(this,A).setAttribute("width",String(t)),e(this,A).setAttribute("height",String(r)),e(this,R).setAttribute("dy",String(-d))},V=function(t,r){Y.has(t)?e(this,s)[t]=r!==null:r===null?e(this,s).removeAttribute(t):e(this,s).setAttribute(t,r)},I=function(){e(this,s).querySelectorAll("source").forEach(t=>t.remove()),this.querySelectorAll("source").forEach(t=>{e(this,s).appendChild(t.cloneNode(!0))}),e(this,s).querySelectorAll("source").length>0&&!e(this,s).src&&e(this,s).load()},H(D,"observedAttributes",[...W]);const j=["src","crossorigin","preload","autoplay","loop","muted","playsinline","poster","width","height"],Q=new Set(["autoplay","loop","muted","playsinline"]),X=["loadstart","progress","suspend","abort","error","emptied","stalled","loadedmetadata","loadeddata","canplay","canplaythrough","playing","waiting","seeking","seeked","ended","durationchange","timeupdate","play","pause","ratechange","resize","volumechange"];var i,g,q,C,w,O,M,v,m,p,f,b,E,n,x,B,F,z,L,_;class N extends HTMLElement{constructor(){super();l(this,n);l(this,i);l(this,g);l(this,q);l(this,C);l(this,w);l(this,O);l(this,M);l(this,v,null);l(this,m,null);l(this,p,!1);l(this,f,0);l(this,b,0);l(this,E);const t=this.attachShadow({mode:"open"});a(this,E,`avk-c-${Math.random().toString(36).slice(2,8)}`),t.innerHTML=`<style>
|
|
18
|
-
:host{display:inline-block;overflow:hidden}
|
|
19
|
-
video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
|
|
20
|
-
svg{display:block;width:100%;height:auto}
|
|
21
|
-
canvas{display:block;width:100%;height:100%}
|
|
22
|
-
</style>
|
|
23
|
-
<video></video>
|
|
24
|
-
<svg viewBox="0 0 1 1" preserveAspectRatio="xMidYMid meet">
|
|
25
|
-
<defs>
|
|
26
|
-
<filter id="${e(this,E)}" filterUnits="userSpaceOnUse" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
|
|
27
|
-
<feOffset in="SourceGraphic" dy="0" result="s"/>
|
|
28
|
-
<feColorMatrix in="s" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0" result="a"/>
|
|
29
|
-
<feComposite in="SourceGraphic" in2="a" operator="in"/>
|
|
30
|
-
</filter>
|
|
31
|
-
</defs>
|
|
32
|
-
<foreignObject width="1" height="1" filter="url(#${e(this,E)})">
|
|
33
|
-
<canvas xmlns="http://www.w3.org/1999/xhtml"></canvas>
|
|
34
|
-
</foreignObject>
|
|
35
|
-
</svg>`,a(this,i,t.querySelector("video")),a(this,C,t.querySelector("svg")),a(this,w,t.querySelector("foreignObject")),a(this,O,t.querySelector("filter")),a(this,M,t.querySelector("feOffset")),a(this,g,t.querySelector("canvas")),a(this,q,e(this,g).getContext("2d"));for(const r of X)e(this,i).addEventListener(r,d=>{this.dispatchEvent(new Event(d.type,{bubbles:!1,cancelable:!1}))});e(this,i).addEventListener("loadedmetadata",()=>u(this,n,x).call(this)),e(this,i).addEventListener("resize",()=>u(this,n,x).call(this))}connectedCallback(){for(const t of j)this.hasAttribute(t)&&u(this,n,B).call(this,t,this.getAttribute(t));u(this,n,F).call(this),a(this,m,new MutationObserver(()=>u(this,n,F).call(this))),e(this,m).observe(this,{childList:!0}),a(this,v,new IntersectionObserver(([t])=>{a(this,p,t.isIntersecting),e(this,p)?u(this,n,z).call(this):u(this,n,L).call(this)},{threshold:0})),e(this,v).observe(this)}disconnectedCallback(){var t,r;u(this,n,L).call(this),(t=e(this,v))==null||t.disconnect(),a(this,v,null),(r=e(this,m))==null||r.disconnect(),a(this,m,null)}attributeChangedCallback(t,r,d){u(this,n,B).call(this,t,d)}get src(){return e(this,i).src}set src(t){this.setAttribute("src",t)}get currentSrc(){return e(this,i).currentSrc}get currentTime(){return e(this,i).currentTime}set currentTime(t){e(this,i).currentTime=t}get duration(){return e(this,i).duration}get paused(){return e(this,i).paused}get ended(){return e(this,i).ended}get readyState(){return e(this,i).readyState}get videoWidth(){return e(this,i).videoWidth}get videoHeight(){return Math.floor(e(this,i).videoHeight/2)}get volume(){return e(this,i).volume}set volume(t){e(this,i).volume=t}get playbackRate(){return e(this,i).playbackRate}set playbackRate(t){e(this,i).playbackRate=t}get defaultPlaybackRate(){return e(this,i).defaultPlaybackRate}set defaultPlaybackRate(t){e(this,i).defaultPlaybackRate=t}get muted(){return e(this,i).muted}set muted(t){e(this,i).muted=t,this.toggleAttribute("muted",t)}get loop(){return e(this,i).loop}set loop(t){e(this,i).loop=t,this.toggleAttribute("loop",t)}get autoplay(){return e(this,i).autoplay}set autoplay(t){e(this,i).autoplay=t,this.toggleAttribute("autoplay",t)}get preload(){return e(this,i).preload}set preload(t){this.setAttribute("preload",t)}get crossOrigin(){return e(this,i).crossOrigin}set crossOrigin(t){t===null?this.removeAttribute("crossorigin"):this.setAttribute("crossorigin",t)}get buffered(){return e(this,i).buffered}get seekable(){return e(this,i).seekable}get played(){return e(this,i).played}get networkState(){return e(this,i).networkState}get error(){return e(this,i).error}get seeking(){return e(this,i).seeking}play(){return e(this,i).play()}pause(){e(this,i).pause()}load(){e(this,i).load()}canPlayType(t){return e(this,i).canPlayType(t)}}i=new WeakMap,g=new WeakMap,q=new WeakMap,C=new WeakMap,w=new WeakMap,O=new WeakMap,M=new WeakMap,v=new WeakMap,m=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,E=new WeakMap,n=new WeakSet,x=function(){const t=e(this,i).videoWidth,r=e(this,i).videoHeight;if(!t||!r)return;const d=Math.floor(r/2);e(this,C).setAttribute("viewBox",`0 0 ${t} ${d}`),e(this,w).setAttribute("width",String(t)),e(this,w).setAttribute("height",String(r)),e(this,O).setAttribute("width",String(t)),e(this,O).setAttribute("height",String(r)),e(this,M).setAttribute("dy",String(-d)),e(this,g).width=t,e(this,g).height=r},B=function(t,r){Q.has(t)?e(this,i)[t]=r!==null:r===null?e(this,i).removeAttribute(t):e(this,i).setAttribute(t,r)},F=function(){e(this,i).querySelectorAll("source").forEach(t=>t.remove()),this.querySelectorAll("source").forEach(t=>{e(this,i).appendChild(t.cloneNode(!0))}),e(this,i).querySelectorAll("source").length>0&&!e(this,i).src&&e(this,i).load()},z=function(){if(e(this,p))if(u(this,n,L).call(this),"requestVideoFrameCallback"in e(this,i)){const t=()=>{e(this,p)&&(u(this,n,_).call(this),a(this,b,e(this,i).requestVideoFrameCallback(t)))};a(this,b,e(this,i).requestVideoFrameCallback(t))}else{const t=()=>{e(this,p)&&(u(this,n,_).call(this),a(this,f,requestAnimationFrame(t)))};a(this,f,requestAnimationFrame(t))}},L=function(){var t,r;e(this,b)&&((r=(t=e(this,i)).cancelVideoFrameCallback)==null||r.call(t,e(this,b)),a(this,b,0)),e(this,f)&&(cancelAnimationFrame(e(this,f)),a(this,f,0))},_=function(){if(e(this,i).readyState<2)return;const t=e(this,i).videoWidth,r=e(this,i).videoHeight;!t||!r||((e(this,g).width!==t||e(this,g).height!==r)&&u(this,n,x).call(this),e(this,q).drawImage(e(this,i),0,0))},H(N,"observedAttributes",[...j]);exports.AlphaVideoKitCanvas=N;exports.AlphaVideoKitSVG=D;
|