@alpha-video-kit/svg 0.2.0 → 0.2.1

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.
@@ -0,0 +1,8 @@
1
+ "use strict";var x=Object.defineProperty;var M=r=>{throw TypeError(r)};var _=(r,o,t)=>o in r?x(r,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[o]=t;var w=(r,o,t)=>_(r,typeof o!="symbol"?o+"":o,t),T=(r,o,t)=>o.has(r)||M("Cannot "+t);var e=(r,o,t)=>(T(r,o,"read from private field"),t?t.call(r):o.get(r)),u=(r,o,t)=>o.has(r)?M("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(r):o.set(r,t),n=(r,o,t,a)=>(T(r,o,"write to private field"),a?a.call(r,t):o.set(r,t),t),h=(r,o,t)=>(T(r,o,"access private method"),t);const S="avk-stacked-alpha";let E=!1;function P(){if(E)return;if(document.getElementById(S)){E=!0;return}E=!0;const r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("style","position:absolute;width:0;height:0;overflow:hidden"),r.setAttribute("aria-hidden","true"),r.innerHTML=`<defs><filter id="${S}" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB"><feOffset in="SourceGraphic" dy="-0.5" result="s"/><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"/><feComposite in="SourceGraphic" in2="a" operator="in"/></filter></defs>`,document.body.prepend(r)}const H=["src","crossorigin","preload","autoplay","loop","muted","playsinline","poster","width","height"],B=new Set(["autoplay","loop","muted","playsinline"]),N=["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,f,b,R,C;class V extends HTMLElement{constructor(){super();u(this,b);u(this,s);u(this,f,null);const t=this.attachShadow({mode:"open"});t.innerHTML=`<style>
2
+ :host{display:inline-block;overflow:hidden}
3
+ video{display:block;width:100%;filter:url(#${S})}
4
+ </style><video></video>`,n(this,s,t.querySelector("video"));for(const a of N)e(this,s).addEventListener(a,y=>{this.dispatchEvent(new Event(y.type,{bubbles:!1,cancelable:!1}))});e(this,s).addEventListener("loadedmetadata",()=>{this.style.aspectRatio=`${e(this,s).videoWidth} / ${Math.floor(e(this,s).videoHeight/2)}`})}connectedCallback(){P();for(const t of H)this.hasAttribute(t)&&h(this,b,R).call(this,t,this.getAttribute(t));h(this,b,C).call(this),n(this,f,new MutationObserver(()=>h(this,b,C).call(this))),e(this,f).observe(this,{childList:!0})}disconnectedCallback(){var t;(t=e(this,f))==null||t.disconnect(),n(this,f,null)}attributeChangedCallback(t,a,y){h(this,b,R).call(this,t,y)}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,f=new WeakMap,b=new WeakSet,R=function(t,a){B.has(t)?e(this,s)[t]=a!==null:a===null?e(this,s).removeAttribute(t):e(this,s).setAttribute(t,a)},C=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()},w(V,"observedAttributes",[...H]);const I=["src","crossorigin","preload","autoplay","loop","muted","playsinline","poster","width","height"],W=new Set(["autoplay","loop","muted","playsinline"]),D=["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,d,k,m,v,c,p,g,l,O,L,$,A,q;class F extends HTMLElement{constructor(){super();u(this,l);u(this,i);u(this,d);u(this,k);u(this,m,null);u(this,v,null);u(this,c,!1);u(this,p,0);u(this,g,0);const t=this.attachShadow({mode:"open"});t.innerHTML=`<style>
5
+ :host{display:inline-block;overflow:hidden}
6
+ video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
7
+ canvas{display:block;width:100%;filter:url(#${S})}
8
+ </style><video></video><canvas></canvas>`,n(this,i,t.querySelector("video")),n(this,d,t.querySelector("canvas")),n(this,k,e(this,d).getContext("2d"));for(const a of D)e(this,i).addEventListener(a,y=>{this.dispatchEvent(new Event(y.type,{bubbles:!1,cancelable:!1}))});e(this,i).addEventListener("loadedmetadata",()=>{this.style.aspectRatio=`${e(this,i).videoWidth} / ${Math.floor(e(this,i).videoHeight/2)}`})}connectedCallback(){P();for(const t of I)this.hasAttribute(t)&&h(this,l,O).call(this,t,this.getAttribute(t));h(this,l,L).call(this),n(this,v,new MutationObserver(()=>h(this,l,L).call(this))),e(this,v).observe(this,{childList:!0}),n(this,m,new IntersectionObserver(([t])=>{n(this,c,t.isIntersecting),e(this,c)?h(this,l,$).call(this):h(this,l,A).call(this)},{threshold:0})),e(this,m).observe(this)}disconnectedCallback(){var t,a;h(this,l,A).call(this),(t=e(this,m))==null||t.disconnect(),n(this,m,null),(a=e(this,v))==null||a.disconnect(),n(this,v,null)}attributeChangedCallback(t,a,y){h(this,l,O).call(this,t,y)}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,d=new WeakMap,k=new WeakMap,m=new WeakMap,v=new WeakMap,c=new WeakMap,p=new WeakMap,g=new WeakMap,l=new WeakSet,O=function(t,a){W.has(t)?e(this,i)[t]=a!==null:a===null?e(this,i).removeAttribute(t):e(this,i).setAttribute(t,a)},L=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()},$=function(){if(e(this,c))if(h(this,l,A).call(this),"requestVideoFrameCallback"in e(this,i)){const t=()=>{e(this,c)&&(h(this,l,q).call(this),n(this,g,e(this,i).requestVideoFrameCallback(t)))};n(this,g,e(this,i).requestVideoFrameCallback(t))}else{const t=()=>{e(this,c)&&(h(this,l,q).call(this),n(this,p,requestAnimationFrame(t)))};n(this,p,requestAnimationFrame(t))}},A=function(){var t,a;e(this,g)&&((a=(t=e(this,i)).cancelVideoFrameCallback)==null||a.call(t,e(this,g)),n(this,g,0)),e(this,p)&&(cancelAnimationFrame(e(this,p)),n(this,p,0))},q=function(){if(e(this,i).readyState<2)return;const t=e(this,i).videoWidth,a=e(this,i).videoHeight;(e(this,d).width!==t||e(this,d).height!==a)&&(e(this,d).width=t,e(this,d).height=a),e(this,k).drawImage(e(this,i),0,0)},w(F,"observedAttributes",[...I]);exports.AlphaVideoKitCanvas=F;exports.AlphaVideoKitSVG=V;
@@ -0,0 +1,435 @@
1
+ var F = Object.defineProperty;
2
+ var M = (r) => {
3
+ throw TypeError(r);
4
+ };
5
+ var $ = (r, o, t) => o in r ? F(r, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[o] = t;
6
+ var w = (r, o, t) => $(r, typeof o != "symbol" ? o + "" : o, t), T = (r, o, t) => o.has(r) || M("Cannot " + t);
7
+ var e = (r, o, t) => (T(r, o, "read from private field"), t ? t.call(r) : o.get(r)), u = (r, o, t) => o.has(r) ? M("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(r) : o.set(r, t), n = (r, o, t, a) => (T(r, o, "write to private field"), a ? a.call(r, t) : o.set(r, t), t), h = (r, o, t) => (T(r, o, "access private method"), t);
8
+ const S = "avk-stacked-alpha";
9
+ let E = !1;
10
+ function P() {
11
+ if (E) return;
12
+ if (document.getElementById(S)) {
13
+ E = !0;
14
+ return;
15
+ }
16
+ E = !0;
17
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
18
+ r.setAttribute("style", "position:absolute;width:0;height:0;overflow:hidden"), r.setAttribute("aria-hidden", "true"), r.innerHTML = `<defs><filter id="${S}" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB"><feOffset in="SourceGraphic" dy="-0.5" result="s"/><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"/><feComposite in="SourceGraphic" in2="a" operator="in"/></filter></defs>`, document.body.prepend(r);
19
+ }
20
+ const H = [
21
+ "src",
22
+ "crossorigin",
23
+ "preload",
24
+ "autoplay",
25
+ "loop",
26
+ "muted",
27
+ "playsinline",
28
+ "poster",
29
+ "width",
30
+ "height"
31
+ ], V = /* @__PURE__ */ new Set(["autoplay", "loop", "muted", "playsinline"]), _ = [
32
+ "loadstart",
33
+ "progress",
34
+ "suspend",
35
+ "abort",
36
+ "error",
37
+ "emptied",
38
+ "stalled",
39
+ "loadedmetadata",
40
+ "loadeddata",
41
+ "canplay",
42
+ "canplaythrough",
43
+ "playing",
44
+ "waiting",
45
+ "seeking",
46
+ "seeked",
47
+ "ended",
48
+ "durationchange",
49
+ "timeupdate",
50
+ "play",
51
+ "pause",
52
+ "ratechange",
53
+ "resize",
54
+ "volumechange"
55
+ ];
56
+ var s, f, b, R, C;
57
+ class B extends HTMLElement {
58
+ constructor() {
59
+ super();
60
+ u(this, b);
61
+ u(this, s);
62
+ u(this, f, null);
63
+ const t = this.attachShadow({ mode: "open" });
64
+ t.innerHTML = `<style>
65
+ :host{display:inline-block;overflow:hidden}
66
+ video{display:block;width:100%;filter:url(#${S})}
67
+ </style><video></video>`, n(this, s, t.querySelector("video"));
68
+ for (const a of _)
69
+ e(this, s).addEventListener(a, (y) => {
70
+ this.dispatchEvent(new Event(y.type, { bubbles: !1, cancelable: !1 }));
71
+ });
72
+ e(this, s).addEventListener("loadedmetadata", () => {
73
+ this.style.aspectRatio = `${e(this, s).videoWidth} / ${Math.floor(e(this, s).videoHeight / 2)}`;
74
+ });
75
+ }
76
+ connectedCallback() {
77
+ P();
78
+ for (const t of H)
79
+ this.hasAttribute(t) && h(this, b, R).call(this, t, this.getAttribute(t));
80
+ h(this, b, C).call(this), n(this, f, new MutationObserver(() => h(this, b, C).call(this))), e(this, f).observe(this, { childList: !0 });
81
+ }
82
+ disconnectedCallback() {
83
+ var t;
84
+ (t = e(this, f)) == null || t.disconnect(), n(this, f, null);
85
+ }
86
+ attributeChangedCallback(t, a, y) {
87
+ h(this, b, R).call(this, t, y);
88
+ }
89
+ // --- Proxied properties ---
90
+ get src() {
91
+ return e(this, s).src;
92
+ }
93
+ set src(t) {
94
+ this.setAttribute("src", t);
95
+ }
96
+ get currentSrc() {
97
+ return e(this, s).currentSrc;
98
+ }
99
+ get currentTime() {
100
+ return e(this, s).currentTime;
101
+ }
102
+ set currentTime(t) {
103
+ e(this, s).currentTime = t;
104
+ }
105
+ get duration() {
106
+ return e(this, s).duration;
107
+ }
108
+ get paused() {
109
+ return e(this, s).paused;
110
+ }
111
+ get ended() {
112
+ return e(this, s).ended;
113
+ }
114
+ get readyState() {
115
+ return e(this, s).readyState;
116
+ }
117
+ get videoWidth() {
118
+ return e(this, s).videoWidth;
119
+ }
120
+ get videoHeight() {
121
+ return Math.floor(e(this, s).videoHeight / 2);
122
+ }
123
+ get volume() {
124
+ return e(this, s).volume;
125
+ }
126
+ set volume(t) {
127
+ e(this, s).volume = t;
128
+ }
129
+ get playbackRate() {
130
+ return e(this, s).playbackRate;
131
+ }
132
+ set playbackRate(t) {
133
+ e(this, s).playbackRate = t;
134
+ }
135
+ get defaultPlaybackRate() {
136
+ return e(this, s).defaultPlaybackRate;
137
+ }
138
+ set defaultPlaybackRate(t) {
139
+ e(this, s).defaultPlaybackRate = t;
140
+ }
141
+ get muted() {
142
+ return e(this, s).muted;
143
+ }
144
+ set muted(t) {
145
+ e(this, s).muted = t, this.toggleAttribute("muted", t);
146
+ }
147
+ get loop() {
148
+ return e(this, s).loop;
149
+ }
150
+ set loop(t) {
151
+ e(this, s).loop = t, this.toggleAttribute("loop", t);
152
+ }
153
+ get autoplay() {
154
+ return e(this, s).autoplay;
155
+ }
156
+ set autoplay(t) {
157
+ e(this, s).autoplay = t, this.toggleAttribute("autoplay", t);
158
+ }
159
+ get preload() {
160
+ return e(this, s).preload;
161
+ }
162
+ set preload(t) {
163
+ this.setAttribute("preload", t);
164
+ }
165
+ get crossOrigin() {
166
+ return e(this, s).crossOrigin;
167
+ }
168
+ set crossOrigin(t) {
169
+ t === null ? this.removeAttribute("crossorigin") : this.setAttribute("crossorigin", t);
170
+ }
171
+ get buffered() {
172
+ return e(this, s).buffered;
173
+ }
174
+ get seekable() {
175
+ return e(this, s).seekable;
176
+ }
177
+ get played() {
178
+ return e(this, s).played;
179
+ }
180
+ get networkState() {
181
+ return e(this, s).networkState;
182
+ }
183
+ get error() {
184
+ return e(this, s).error;
185
+ }
186
+ get seeking() {
187
+ return e(this, s).seeking;
188
+ }
189
+ // --- Proxied methods ---
190
+ play() {
191
+ return e(this, s).play();
192
+ }
193
+ pause() {
194
+ e(this, s).pause();
195
+ }
196
+ load() {
197
+ e(this, s).load();
198
+ }
199
+ canPlayType(t) {
200
+ return e(this, s).canPlayType(t);
201
+ }
202
+ }
203
+ s = new WeakMap(), f = new WeakMap(), b = new WeakSet(), R = function(t, a) {
204
+ V.has(t) ? e(this, s)[t] = a !== null : a === null ? e(this, s).removeAttribute(t) : e(this, s).setAttribute(t, a);
205
+ }, C = function() {
206
+ e(this, s).querySelectorAll("source").forEach((t) => t.remove()), this.querySelectorAll("source").forEach((t) => {
207
+ e(this, s).appendChild(t.cloneNode(!0));
208
+ }), e(this, s).querySelectorAll("source").length > 0 && !e(this, s).src && e(this, s).load();
209
+ }, w(B, "observedAttributes", [...H]);
210
+ const I = [
211
+ "src",
212
+ "crossorigin",
213
+ "preload",
214
+ "autoplay",
215
+ "loop",
216
+ "muted",
217
+ "playsinline",
218
+ "poster",
219
+ "width",
220
+ "height"
221
+ ], N = /* @__PURE__ */ new Set(["autoplay", "loop", "muted", "playsinline"]), W = [
222
+ "loadstart",
223
+ "progress",
224
+ "suspend",
225
+ "abort",
226
+ "error",
227
+ "emptied",
228
+ "stalled",
229
+ "loadedmetadata",
230
+ "loadeddata",
231
+ "canplay",
232
+ "canplaythrough",
233
+ "playing",
234
+ "waiting",
235
+ "seeking",
236
+ "seeked",
237
+ "ended",
238
+ "durationchange",
239
+ "timeupdate",
240
+ "play",
241
+ "pause",
242
+ "ratechange",
243
+ "resize",
244
+ "volumechange"
245
+ ];
246
+ var i, d, k, m, v, c, p, g, l, O, L, x, A, q;
247
+ class D extends HTMLElement {
248
+ constructor() {
249
+ super();
250
+ u(this, l);
251
+ u(this, i);
252
+ u(this, d);
253
+ u(this, k);
254
+ u(this, m, null);
255
+ u(this, v, null);
256
+ u(this, c, !1);
257
+ u(this, p, 0);
258
+ u(this, g, 0);
259
+ const t = this.attachShadow({ mode: "open" });
260
+ t.innerHTML = `<style>
261
+ :host{display:inline-block;overflow:hidden}
262
+ video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
263
+ canvas{display:block;width:100%;filter:url(#${S})}
264
+ </style><video></video><canvas></canvas>`, n(this, i, t.querySelector("video")), n(this, d, t.querySelector("canvas")), n(this, k, e(this, d).getContext("2d"));
265
+ for (const a of W)
266
+ e(this, i).addEventListener(a, (y) => {
267
+ this.dispatchEvent(new Event(y.type, { bubbles: !1, cancelable: !1 }));
268
+ });
269
+ e(this, i).addEventListener("loadedmetadata", () => {
270
+ this.style.aspectRatio = `${e(this, i).videoWidth} / ${Math.floor(e(this, i).videoHeight / 2)}`;
271
+ });
272
+ }
273
+ connectedCallback() {
274
+ P();
275
+ for (const t of I)
276
+ this.hasAttribute(t) && h(this, l, O).call(this, t, this.getAttribute(t));
277
+ h(this, l, L).call(this), n(this, v, new MutationObserver(() => h(this, l, L).call(this))), e(this, v).observe(this, { childList: !0 }), n(this, m, new IntersectionObserver(
278
+ ([t]) => {
279
+ n(this, c, t.isIntersecting), e(this, c) ? h(this, l, x).call(this) : h(this, l, A).call(this);
280
+ },
281
+ { threshold: 0 }
282
+ )), e(this, m).observe(this);
283
+ }
284
+ disconnectedCallback() {
285
+ var t, a;
286
+ h(this, l, A).call(this), (t = e(this, m)) == null || t.disconnect(), n(this, m, null), (a = e(this, v)) == null || a.disconnect(), n(this, v, null);
287
+ }
288
+ attributeChangedCallback(t, a, y) {
289
+ h(this, l, O).call(this, t, y);
290
+ }
291
+ // --- Proxied properties ---
292
+ get src() {
293
+ return e(this, i).src;
294
+ }
295
+ set src(t) {
296
+ this.setAttribute("src", t);
297
+ }
298
+ get currentSrc() {
299
+ return e(this, i).currentSrc;
300
+ }
301
+ get currentTime() {
302
+ return e(this, i).currentTime;
303
+ }
304
+ set currentTime(t) {
305
+ e(this, i).currentTime = t;
306
+ }
307
+ get duration() {
308
+ return e(this, i).duration;
309
+ }
310
+ get paused() {
311
+ return e(this, i).paused;
312
+ }
313
+ get ended() {
314
+ return e(this, i).ended;
315
+ }
316
+ get readyState() {
317
+ return e(this, i).readyState;
318
+ }
319
+ get videoWidth() {
320
+ return e(this, i).videoWidth;
321
+ }
322
+ get videoHeight() {
323
+ return Math.floor(e(this, i).videoHeight / 2);
324
+ }
325
+ get volume() {
326
+ return e(this, i).volume;
327
+ }
328
+ set volume(t) {
329
+ e(this, i).volume = t;
330
+ }
331
+ get playbackRate() {
332
+ return e(this, i).playbackRate;
333
+ }
334
+ set playbackRate(t) {
335
+ e(this, i).playbackRate = t;
336
+ }
337
+ get defaultPlaybackRate() {
338
+ return e(this, i).defaultPlaybackRate;
339
+ }
340
+ set defaultPlaybackRate(t) {
341
+ e(this, i).defaultPlaybackRate = t;
342
+ }
343
+ get muted() {
344
+ return e(this, i).muted;
345
+ }
346
+ set muted(t) {
347
+ e(this, i).muted = t, this.toggleAttribute("muted", t);
348
+ }
349
+ get loop() {
350
+ return e(this, i).loop;
351
+ }
352
+ set loop(t) {
353
+ e(this, i).loop = t, this.toggleAttribute("loop", t);
354
+ }
355
+ get autoplay() {
356
+ return e(this, i).autoplay;
357
+ }
358
+ set autoplay(t) {
359
+ e(this, i).autoplay = t, this.toggleAttribute("autoplay", t);
360
+ }
361
+ get preload() {
362
+ return e(this, i).preload;
363
+ }
364
+ set preload(t) {
365
+ this.setAttribute("preload", t);
366
+ }
367
+ get crossOrigin() {
368
+ return e(this, i).crossOrigin;
369
+ }
370
+ set crossOrigin(t) {
371
+ t === null ? this.removeAttribute("crossorigin") : this.setAttribute("crossorigin", t);
372
+ }
373
+ get buffered() {
374
+ return e(this, i).buffered;
375
+ }
376
+ get seekable() {
377
+ return e(this, i).seekable;
378
+ }
379
+ get played() {
380
+ return e(this, i).played;
381
+ }
382
+ get networkState() {
383
+ return e(this, i).networkState;
384
+ }
385
+ get error() {
386
+ return e(this, i).error;
387
+ }
388
+ get seeking() {
389
+ return e(this, i).seeking;
390
+ }
391
+ // --- Proxied methods ---
392
+ play() {
393
+ return e(this, i).play();
394
+ }
395
+ pause() {
396
+ e(this, i).pause();
397
+ }
398
+ load() {
399
+ e(this, i).load();
400
+ }
401
+ canPlayType(t) {
402
+ return e(this, i).canPlayType(t);
403
+ }
404
+ }
405
+ i = new WeakMap(), d = new WeakMap(), k = new WeakMap(), m = new WeakMap(), v = new WeakMap(), c = new WeakMap(), p = new WeakMap(), g = new WeakMap(), l = new WeakSet(), O = function(t, a) {
406
+ N.has(t) ? e(this, i)[t] = a !== null : a === null ? e(this, i).removeAttribute(t) : e(this, i).setAttribute(t, a);
407
+ }, L = function() {
408
+ e(this, i).querySelectorAll("source").forEach((t) => t.remove()), this.querySelectorAll("source").forEach((t) => {
409
+ e(this, i).appendChild(t.cloneNode(!0));
410
+ }), e(this, i).querySelectorAll("source").length > 0 && !e(this, i).src && e(this, i).load();
411
+ }, x = function() {
412
+ if (e(this, c))
413
+ if (h(this, l, A).call(this), "requestVideoFrameCallback" in e(this, i)) {
414
+ const t = () => {
415
+ e(this, c) && (h(this, l, q).call(this), n(this, g, e(this, i).requestVideoFrameCallback(t)));
416
+ };
417
+ n(this, g, e(this, i).requestVideoFrameCallback(t));
418
+ } else {
419
+ const t = () => {
420
+ e(this, c) && (h(this, l, q).call(this), n(this, p, requestAnimationFrame(t)));
421
+ };
422
+ n(this, p, requestAnimationFrame(t));
423
+ }
424
+ }, A = function() {
425
+ var t, a;
426
+ e(this, g) && ((a = (t = e(this, i)).cancelVideoFrameCallback) == null || a.call(t, e(this, g)), n(this, g, 0)), e(this, p) && (cancelAnimationFrame(e(this, p)), n(this, p, 0));
427
+ }, q = function() {
428
+ if (e(this, i).readyState < 2) return;
429
+ const t = e(this, i).videoWidth, a = e(this, i).videoHeight;
430
+ (e(this, d).width !== t || e(this, d).height !== a) && (e(this, d).width = t, e(this, d).height = a), e(this, k).drawImage(e(this, i), 0, 0);
431
+ }, w(D, "observedAttributes", [...I]);
432
+ export {
433
+ D as A,
434
+ B as a
435
+ };
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
- "use strict";var G=Object.defineProperty;var U=i=>{throw TypeError(i)};var z=(i,s,t)=>s in i?G(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t;var B=(i,s,t)=>z(i,typeof s!="symbol"?s+"":s,t),E=(i,s,t)=>s.has(i)||U("Cannot "+t);var e=(i,s,t)=>(E(i,s,"read from private field"),t?t.call(i):s.get(i)),y=(i,s,t)=>s.has(i)?U("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(i):s.set(i,t),h=(i,s,t,a)=>(E(i,s,"write to private field"),a?a.call(i,t):s.set(i,t),t),u=(i,s,t)=>(E(i,s,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function j(i){const{canvas:s}=i,t=s.getContext("2d"),a=document.createElement("canvas"),d=a.getContext("2d");let p=!1;function x(v,n,l,f){return`<svg xmlns="http://www.w3.org/2000/svg"
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("./canvas-component-CJM11n9O.cjs");function R(u){const{canvas:r}=u,c=r.getContext("2d"),l=document.createElement("canvas"),d=l.getContext("2d");let s=!1;function g(o,e,t,n){return`<svg xmlns="http://www.w3.org/2000/svg"
2
2
  xmlns:xlink="http://www.w3.org/1999/xlink"
3
- width="${n}" height="${l}"
4
- viewBox="0 0 ${n} ${l}">
3
+ width="${e}" height="${t}"
4
+ viewBox="0 0 ${e} ${t}">
5
5
  <defs>
6
6
  <filter id="r2a" color-interpolation-filters="sRGB">
7
7
  <feColorMatrix type="matrix"
@@ -11,24 +11,20 @@
11
11
  1 0 0 0 0"/>
12
12
  </filter>
13
13
  <mask id="alphaMask">
14
- <svg viewBox="0 ${l} ${n} ${l}"
15
- width="${n}" height="${l}"
14
+ <svg viewBox="0 ${t} ${e} ${t}"
15
+ width="${e}" height="${t}"
16
16
  preserveAspectRatio="none">
17
- <image href="${v}"
18
- width="${n}" height="${f}"
17
+ <image href="${o}"
18
+ width="${e}" height="${n}"
19
19
  filter="url(#r2a)"/>
20
20
  </svg>
21
21
  </mask>
22
22
  </defs>
23
- <svg viewBox="0 0 ${n} ${l}"
24
- width="${n}" height="${l}"
23
+ <svg viewBox="0 0 ${e} ${t}"
24
+ width="${e}" height="${t}"
25
25
  preserveAspectRatio="none"
26
26
  mask="url(#alphaMask)">
27
- <image href="${v}"
28
- width="${n}" height="${f}"/>
27
+ <image href="${o}"
28
+ width="${e}" height="${n}"/>
29
29
  </svg>
30
- </svg>`}return{drawFrame(v){if(p)return;const n=v.videoWidth,l=v.videoHeight,f=Math.floor(l/2);(s.width!==n||s.height!==f)&&(s.width=n,s.height=f),(a.width!==n||a.height!==l)&&(a.width=n,a.height=l),d.drawImage(v,0,0);const A=a.toDataURL("image/png"),F=x(A,n,f,l),L=new Blob([F],{type:"image/svg+xml"}),g=URL.createObjectURL(L),C=new Image;C.onload=()=>{if(p){URL.revokeObjectURL(g);return}t.clearRect(0,0,n,f),t.drawImage(C,0,0),URL.revokeObjectURL(g)},C.src=g},setPremultipliedAlpha(v){},destroy(){p||(p=!0)},get isDestroyed(){return p}}}function W(i){const{canvas:s,premultipliedAlpha:t=!1}=i,a=s.getContext("2d",{willReadFrequently:!0}),d=document.createElement("canvas"),p=d.getContext("2d",{willReadFrequently:!0});let x=!1,v=t;return{drawFrame(n){if(x)return;const l=n.videoWidth,f=n.videoHeight,A=Math.floor(f/2);(s.width!==l||s.height!==A)&&(s.width=l,s.height=A),(d.width!==l||d.height!==f)&&(d.width=l,d.height=f),p.drawImage(n,0,0);const F=p.getImageData(0,0,l,A),L=p.getImageData(0,A,l,A),g=F.data,C=L.data;for(let m=0;m<g.length;m+=4){const M=C[m];if(v)g[m+3]=M;else{const T=M/255;g[m]=Math.round(g[m]*T),g[m+1]=Math.round(g[m+1]*T),g[m+2]=Math.round(g[m+2]*T),g[m+3]=M}}a.putImageData(F,0,0)},setPremultipliedAlpha(n){v=n},destroy(){x||(x=!0)},get isDestroyed(){return x}}}function H(i){const{mode:s="canvas",...t}=i;return s==="svg-filter"?j(t):W(t)}const _=["src","crossorigin","preload","autoplay","loop","muted","playsinline","poster","width","height","mode"],K=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 r,$,c,R,S,b,w,k,o,I,q,D,P,O,V;class N extends HTMLElement{constructor(){super();y(this,o);y(this,r);y(this,$);y(this,c,null);y(this,R,null);y(this,S,null);y(this,b,!1);y(this,w,0);y(this,k,0);const t=this.attachShadow({mode:"open"});t.innerHTML=`<style>
31
- :host{display:inline-block;overflow:hidden}
32
- video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
33
- canvas{display:block;width:100%;height:100%}
34
- </style><video></video><canvas></canvas>`,h(this,r,t.querySelector("video")),h(this,$,t.querySelector("canvas"));for(const a of J)e(this,r).addEventListener(a,d=>{this.dispatchEvent(new Event(d.type,{bubbles:!1,cancelable:!1}))})}connectedCallback(){for(const t of _)t!=="mode"&&this.hasAttribute(t)&&u(this,o,I).call(this,t,this.getAttribute(t));u(this,o,q).call(this),h(this,S,new MutationObserver(()=>u(this,o,q).call(this))),e(this,S).observe(this,{childList:!0}),h(this,R,new IntersectionObserver(([t])=>{h(this,b,t.isIntersecting),e(this,b)?(u(this,o,D).call(this),u(this,o,P).call(this)):u(this,o,O).call(this)},{threshold:0})),e(this,R).observe(this)}disconnectedCallback(){var t,a,d;u(this,o,O).call(this),(t=e(this,R))==null||t.disconnect(),h(this,R,null),(a=e(this,S))==null||a.disconnect(),h(this,S,null),(d=e(this,c))==null||d.destroy(),h(this,c,null)}attributeChangedCallback(t,a,d){var p;if(t==="mode"){(p=e(this,c))==null||p.destroy(),h(this,c,null),e(this,b)&&(u(this,o,D).call(this),u(this,o,P).call(this));return}u(this,o,I).call(this,t,d)}get src(){return e(this,r).src}set src(t){this.setAttribute("src",t)}get currentSrc(){return e(this,r).currentSrc}get currentTime(){return e(this,r).currentTime}set currentTime(t){e(this,r).currentTime=t}get duration(){return e(this,r).duration}get paused(){return e(this,r).paused}get ended(){return e(this,r).ended}get readyState(){return e(this,r).readyState}get videoWidth(){return e(this,r).videoWidth}get videoHeight(){return Math.floor(e(this,r).videoHeight/2)}get volume(){return e(this,r).volume}set volume(t){e(this,r).volume=t}get playbackRate(){return e(this,r).playbackRate}set playbackRate(t){e(this,r).playbackRate=t}get defaultPlaybackRate(){return e(this,r).defaultPlaybackRate}set defaultPlaybackRate(t){e(this,r).defaultPlaybackRate=t}get muted(){return e(this,r).muted}set muted(t){e(this,r).muted=t,this.toggleAttribute("muted",t)}get loop(){return e(this,r).loop}set loop(t){e(this,r).loop=t,this.toggleAttribute("loop",t)}get autoplay(){return e(this,r).autoplay}set autoplay(t){e(this,r).autoplay=t,this.toggleAttribute("autoplay",t)}get preload(){return e(this,r).preload}set preload(t){this.setAttribute("preload",t)}get crossOrigin(){return e(this,r).crossOrigin}set crossOrigin(t){t===null?this.removeAttribute("crossorigin"):this.setAttribute("crossorigin",t)}get buffered(){return e(this,r).buffered}get seekable(){return e(this,r).seekable}get played(){return e(this,r).played}get networkState(){return e(this,r).networkState}get error(){return e(this,r).error}get seeking(){return e(this,r).seeking}play(){return e(this,r).play()}pause(){e(this,r).pause()}load(){e(this,r).load()}canPlayType(t){return e(this,r).canPlayType(t)}}r=new WeakMap,$=new WeakMap,c=new WeakMap,R=new WeakMap,S=new WeakMap,b=new WeakMap,w=new WeakMap,k=new WeakMap,o=new WeakSet,I=function(t,a){K.has(t)?e(this,r)[t]=a!==null:a===null?e(this,r).removeAttribute(t):e(this,r).setAttribute(t,a)},q=function(){e(this,r).querySelectorAll("source").forEach(t=>t.remove()),this.querySelectorAll("source").forEach(t=>{e(this,r).appendChild(t.cloneNode(!0))}),e(this,r).querySelectorAll("source").length>0&&!e(this,r).src&&e(this,r).load()},D=function(){if(!(e(this,c)&&!e(this,c).isDestroyed))try{const t=this.getAttribute("mode")||"canvas";h(this,c,H({canvas:e(this,$),mode:t}))}catch{}},P=function(){if(!(!e(this,b)||!e(this,c)))if(u(this,o,O).call(this),"requestVideoFrameCallback"in e(this,r)){const t=()=>{!e(this,b)||!e(this,c)||(u(this,o,V).call(this),h(this,k,e(this,r).requestVideoFrameCallback(t)))};h(this,k,e(this,r).requestVideoFrameCallback(t))}else{const t=()=>{!e(this,b)||!e(this,c)||(u(this,o,V).call(this),h(this,w,requestAnimationFrame(t)))};h(this,w,requestAnimationFrame(t))}},O=function(){var t,a;e(this,k)&&((a=(t=e(this,r)).cancelVideoFrameCallback)==null||a.call(t,e(this,k)),h(this,k,0)),e(this,w)&&(cancelAnimationFrame(e(this,w)),h(this,w,0))},V=function(){e(this,r).readyState<2||!e(this,c)||e(this,c).drawFrame(e(this,r))},B(N,"observedAttributes",[..._]);exports.AlphaVideoKitSVG=N;exports.createCanvasFilterRenderer=W;exports.createRenderer=H;exports.createSvgFilterRenderer=j;
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;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,66 @@
1
+ /**
2
+ * `<alpha-video-kit-canvas>` — Canvas 2D with the same SVG filter applied via CSS.
3
+ *
4
+ * A hidden <video> feeds a visible <canvas> via drawImage (full stacked frame).
5
+ * The CSS SVG filter composites the stacked-alpha halves.
6
+ * The host element clips to the top half via overflow:hidden + aspect-ratio.
7
+ */
8
+ export declare class AlphaVideoKitCanvas extends HTMLElement {
9
+ #private;
10
+ static observedAttributes: ("src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster" | "width" | "height")[];
11
+ constructor();
12
+ connectedCallback(): void;
13
+ disconnectedCallback(): void;
14
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
15
+ get src(): string;
16
+ set src(v: string);
17
+ get currentSrc(): string;
18
+ get currentTime(): number;
19
+ set currentTime(v: number);
20
+ get duration(): number;
21
+ get paused(): boolean;
22
+ get ended(): boolean;
23
+ get readyState(): number;
24
+ get videoWidth(): number;
25
+ get videoHeight(): number;
26
+ get volume(): number;
27
+ set volume(v: number);
28
+ get playbackRate(): number;
29
+ set playbackRate(v: number);
30
+ get defaultPlaybackRate(): number;
31
+ set defaultPlaybackRate(v: number);
32
+ get muted(): boolean;
33
+ set muted(v: boolean);
34
+ get loop(): boolean;
35
+ set loop(v: boolean);
36
+ get autoplay(): boolean;
37
+ set autoplay(v: boolean);
38
+ get preload(): string;
39
+ set preload(v: string);
40
+ get crossOrigin(): string | null;
41
+ set crossOrigin(v: string | null);
42
+ get buffered(): TimeRanges;
43
+ get seekable(): TimeRanges;
44
+ get played(): TimeRanges;
45
+ get networkState(): number;
46
+ get error(): MediaError | null;
47
+ get seeking(): boolean;
48
+ play(): Promise<void>;
49
+ pause(): void;
50
+ load(): void;
51
+ canPlayType(type: string): CanPlayTypeResult;
52
+ }
53
+
54
+ /**
55
+ * `<alpha-video-kit-svg>` — SVG filter applied directly to a `<video>` element.
56
+ *
57
+ * No canvas, no rendering loop. The browser applies the CSS SVG filter on every
58
+ * paint, compositing the stacked-alpha halves in real time.
59
+ * The host element clips to the top half via overflow:hidden + aspect-ratio.
60
+ */
1
61
  export declare class AlphaVideoKitSVG extends HTMLElement {
2
62
  #private;
3
- static observedAttributes: ("mode" | "src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster" | "width" | "height")[];
63
+ static observedAttributes: ("src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster" | "width" | "height")[];
4
64
  constructor();
5
65
  connectedCallback(): void;
6
66
  disconnectedCallback(): void;
package/dist/index.js CHANGED
@@ -1,18 +1,12 @@
1
- var W = Object.defineProperty;
2
- var V = (r) => {
3
- throw TypeError(r);
4
- };
5
- var j = (r, i, t) => i in r ? W(r, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[i] = t;
6
- var B = (r, i, t) => j(r, typeof i != "symbol" ? i + "" : i, t), M = (r, i, t) => i.has(r) || V("Cannot " + t);
7
- var e = (r, i, t) => (M(r, i, "read from private field"), t ? t.call(r) : i.get(r)), y = (r, i, t) => i.has(r) ? V("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(r) : i.set(r, t), l = (r, i, t, a) => (M(r, i, "write to private field"), a ? a.call(r, t) : i.set(r, t), t), d = (r, i, t) => (M(r, i, "access private method"), t);
8
- function H(r) {
9
- const { canvas: i } = r, t = i.getContext("2d"), a = document.createElement("canvas"), u = a.getContext("2d");
10
- let p = !1;
11
- function S(v, n, h, f) {
1
+ import { A as k, a as b } from "./canvas-component-DMsm7VdA.js";
2
+ function x(u) {
3
+ const { canvas: r } = u, c = r.getContext("2d"), l = document.createElement("canvas"), d = l.getContext("2d");
4
+ let i = !1;
5
+ function g(s, e, t, n) {
12
6
  return `<svg xmlns="http://www.w3.org/2000/svg"
13
7
  xmlns:xlink="http://www.w3.org/1999/xlink"
14
- width="${n}" height="${h}"
15
- viewBox="0 0 ${n} ${h}">
8
+ width="${e}" height="${t}"
9
+ viewBox="0 0 ${e} ${t}">
16
10
  <defs>
17
11
  <filter id="r2a" color-interpolation-filters="sRGB">
18
12
  <feColorMatrix type="matrix"
@@ -22,315 +16,87 @@ function H(r) {
22
16
  1 0 0 0 0"/>
23
17
  </filter>
24
18
  <mask id="alphaMask">
25
- <svg viewBox="0 ${h} ${n} ${h}"
26
- width="${n}" height="${h}"
19
+ <svg viewBox="0 ${t} ${e} ${t}"
20
+ width="${e}" height="${t}"
27
21
  preserveAspectRatio="none">
28
- <image href="${v}"
29
- width="${n}" height="${f}"
22
+ <image href="${s}"
23
+ width="${e}" height="${n}"
30
24
  filter="url(#r2a)"/>
31
25
  </svg>
32
26
  </mask>
33
27
  </defs>
34
- <svg viewBox="0 0 ${n} ${h}"
35
- width="${n}" height="${h}"
28
+ <svg viewBox="0 0 ${e} ${t}"
29
+ width="${e}" height="${t}"
36
30
  preserveAspectRatio="none"
37
31
  mask="url(#alphaMask)">
38
- <image href="${v}"
39
- width="${n}" height="${f}"/>
32
+ <image href="${s}"
33
+ width="${e}" height="${n}"/>
40
34
  </svg>
41
35
  </svg>`;
42
36
  }
43
37
  return {
44
- drawFrame(v) {
45
- if (p) return;
46
- const n = v.videoWidth, h = v.videoHeight, f = Math.floor(h / 2);
47
- (i.width !== n || i.height !== f) && (i.width = n, i.height = f), (a.width !== n || a.height !== h) && (a.width = n, a.height = h), u.drawImage(v, 0, 0);
48
- const A = a.toDataURL("image/png"), F = S(A, n, f, h), O = new Blob([F], { type: "image/svg+xml" }), g = URL.createObjectURL(O), C = new Image();
49
- C.onload = () => {
50
- if (p) {
51
- URL.revokeObjectURL(g);
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);
52
46
  return;
53
47
  }
54
- t.clearRect(0, 0, n, f), t.drawImage(C, 0, 0), URL.revokeObjectURL(g);
55
- }, C.src = g;
48
+ c.clearRect(0, 0, e, n), c.drawImage(f, 0, 0), URL.revokeObjectURL(a);
49
+ }, f.src = a;
56
50
  },
57
- setPremultipliedAlpha(v) {
51
+ setPremultipliedAlpha(s) {
58
52
  },
59
53
  destroy() {
60
- p || (p = !0);
54
+ i || (i = !0);
61
55
  },
62
56
  get isDestroyed() {
63
- return p;
57
+ return i;
64
58
  }
65
59
  };
66
60
  }
67
- function N(r) {
68
- const { canvas: i, premultipliedAlpha: t = !1 } = r, a = i.getContext("2d", { willReadFrequently: !0 }), u = document.createElement("canvas"), p = u.getContext("2d", { willReadFrequently: !0 });
69
- let S = !1, v = t;
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;
70
64
  return {
71
- drawFrame(n) {
72
- if (S) return;
73
- const h = n.videoWidth, f = n.videoHeight, A = Math.floor(f / 2);
74
- (i.width !== h || i.height !== A) && (i.width = h, i.height = A), (u.width !== h || u.height !== f) && (u.width = h, u.height = f), p.drawImage(n, 0, 0);
75
- const F = p.getImageData(0, 0, h, A), O = p.getImageData(0, A, h, A), g = F.data, C = O.data;
76
- for (let m = 0; m < g.length; m += 4) {
77
- const E = C[m];
78
- if (v)
79
- g[m + 3] = E;
65
+ drawFrame(e) {
66
+ if (g) return;
67
+ const t = e.videoWidth, n = e.videoHeight, h = Math.floor(n / 2);
68
+ (r.width !== t || r.height !== h) && (r.width = t, r.height = h), (d.width !== t || d.height !== n) && (d.width = t, d.height = n), i.drawImage(e, 0, 0);
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;
80
74
  else {
81
- const I = E / 255;
82
- g[m] = Math.round(g[m] * I), g[m + 1] = Math.round(g[m + 1] * I), g[m + 2] = Math.round(g[m + 2] * I), g[m + 3] = E;
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;
83
77
  }
84
78
  }
85
- a.putImageData(F, 0, 0);
79
+ l.putImageData(m, 0, 0);
86
80
  },
87
- setPremultipliedAlpha(n) {
88
- v = n;
81
+ setPremultipliedAlpha(e) {
82
+ s = e;
89
83
  },
90
84
  destroy() {
91
- S || (S = !0);
85
+ g || (g = !0);
92
86
  },
93
87
  get isDestroyed() {
94
- return S;
88
+ return g;
95
89
  }
96
90
  };
97
91
  }
98
- function z(r) {
99
- const { mode: i = "canvas", ...t } = r;
100
- return i === "svg-filter" ? H(t) : N(t);
101
- }
102
- const _ = [
103
- "src",
104
- "crossorigin",
105
- "preload",
106
- "autoplay",
107
- "loop",
108
- "muted",
109
- "playsinline",
110
- "poster",
111
- "width",
112
- "height",
113
- "mode"
114
- ], G = /* @__PURE__ */ new Set(["autoplay", "loop", "muted", "playsinline"]), J = [
115
- "loadstart",
116
- "progress",
117
- "suspend",
118
- "abort",
119
- "error",
120
- "emptied",
121
- "stalled",
122
- "loadedmetadata",
123
- "loadeddata",
124
- "canplay",
125
- "canplaythrough",
126
- "playing",
127
- "waiting",
128
- "seeking",
129
- "seeked",
130
- "ended",
131
- "durationchange",
132
- "timeupdate",
133
- "play",
134
- "pause",
135
- "ratechange",
136
- "resize",
137
- "volumechange"
138
- ];
139
- var s, $, c, R, x, b, w, k, o, T, q, D, P, L, U;
140
- class K extends HTMLElement {
141
- constructor() {
142
- super();
143
- y(this, o);
144
- y(this, s);
145
- y(this, $);
146
- y(this, c, null);
147
- y(this, R, null);
148
- y(this, x, null);
149
- y(this, b, !1);
150
- y(this, w, 0);
151
- y(this, k, 0);
152
- const t = this.attachShadow({ mode: "open" });
153
- t.innerHTML = `<style>
154
- :host{display:inline-block;overflow:hidden}
155
- video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
156
- canvas{display:block;width:100%;height:100%}
157
- </style><video></video><canvas></canvas>`, l(this, s, t.querySelector("video")), l(this, $, t.querySelector("canvas"));
158
- for (const a of J)
159
- e(this, s).addEventListener(a, (u) => {
160
- this.dispatchEvent(new Event(u.type, { bubbles: !1, cancelable: !1 }));
161
- });
162
- }
163
- connectedCallback() {
164
- for (const t of _)
165
- t !== "mode" && this.hasAttribute(t) && d(this, o, T).call(this, t, this.getAttribute(t));
166
- d(this, o, q).call(this), l(this, x, new MutationObserver(() => d(this, o, q).call(this))), e(this, x).observe(this, { childList: !0 }), l(this, R, new IntersectionObserver(
167
- ([t]) => {
168
- l(this, b, t.isIntersecting), e(this, b) ? (d(this, o, D).call(this), d(this, o, P).call(this)) : d(this, o, L).call(this);
169
- },
170
- { threshold: 0 }
171
- )), e(this, R).observe(this);
172
- }
173
- disconnectedCallback() {
174
- var t, a, u;
175
- d(this, o, L).call(this), (t = e(this, R)) == null || t.disconnect(), l(this, R, null), (a = e(this, x)) == null || a.disconnect(), l(this, x, null), (u = e(this, c)) == null || u.destroy(), l(this, c, null);
176
- }
177
- attributeChangedCallback(t, a, u) {
178
- var p;
179
- if (t === "mode") {
180
- (p = e(this, c)) == null || p.destroy(), l(this, c, null), e(this, b) && (d(this, o, D).call(this), d(this, o, P).call(this));
181
- return;
182
- }
183
- d(this, o, T).call(this, t, u);
184
- }
185
- // --- Proxied properties ---
186
- get src() {
187
- return e(this, s).src;
188
- }
189
- set src(t) {
190
- this.setAttribute("src", t);
191
- }
192
- get currentSrc() {
193
- return e(this, s).currentSrc;
194
- }
195
- get currentTime() {
196
- return e(this, s).currentTime;
197
- }
198
- set currentTime(t) {
199
- e(this, s).currentTime = t;
200
- }
201
- get duration() {
202
- return e(this, s).duration;
203
- }
204
- get paused() {
205
- return e(this, s).paused;
206
- }
207
- get ended() {
208
- return e(this, s).ended;
209
- }
210
- get readyState() {
211
- return e(this, s).readyState;
212
- }
213
- get videoWidth() {
214
- return e(this, s).videoWidth;
215
- }
216
- get videoHeight() {
217
- return Math.floor(e(this, s).videoHeight / 2);
218
- }
219
- get volume() {
220
- return e(this, s).volume;
221
- }
222
- set volume(t) {
223
- e(this, s).volume = t;
224
- }
225
- get playbackRate() {
226
- return e(this, s).playbackRate;
227
- }
228
- set playbackRate(t) {
229
- e(this, s).playbackRate = t;
230
- }
231
- get defaultPlaybackRate() {
232
- return e(this, s).defaultPlaybackRate;
233
- }
234
- set defaultPlaybackRate(t) {
235
- e(this, s).defaultPlaybackRate = t;
236
- }
237
- get muted() {
238
- return e(this, s).muted;
239
- }
240
- set muted(t) {
241
- e(this, s).muted = t, this.toggleAttribute("muted", t);
242
- }
243
- get loop() {
244
- return e(this, s).loop;
245
- }
246
- set loop(t) {
247
- e(this, s).loop = t, this.toggleAttribute("loop", t);
248
- }
249
- get autoplay() {
250
- return e(this, s).autoplay;
251
- }
252
- set autoplay(t) {
253
- e(this, s).autoplay = t, this.toggleAttribute("autoplay", t);
254
- }
255
- get preload() {
256
- return e(this, s).preload;
257
- }
258
- set preload(t) {
259
- this.setAttribute("preload", t);
260
- }
261
- get crossOrigin() {
262
- return e(this, s).crossOrigin;
263
- }
264
- set crossOrigin(t) {
265
- t === null ? this.removeAttribute("crossorigin") : this.setAttribute("crossorigin", t);
266
- }
267
- get buffered() {
268
- return e(this, s).buffered;
269
- }
270
- get seekable() {
271
- return e(this, s).seekable;
272
- }
273
- get played() {
274
- return e(this, s).played;
275
- }
276
- get networkState() {
277
- return e(this, s).networkState;
278
- }
279
- get error() {
280
- return e(this, s).error;
281
- }
282
- get seeking() {
283
- return e(this, s).seeking;
284
- }
285
- // --- Proxied methods ---
286
- play() {
287
- return e(this, s).play();
288
- }
289
- pause() {
290
- e(this, s).pause();
291
- }
292
- load() {
293
- e(this, s).load();
294
- }
295
- canPlayType(t) {
296
- return e(this, s).canPlayType(t);
297
- }
92
+ function R(u) {
93
+ const { mode: r = "canvas", ...c } = u;
94
+ return r === "svg-filter" ? x(c) : $(c);
298
95
  }
299
- s = new WeakMap(), $ = new WeakMap(), c = new WeakMap(), R = new WeakMap(), x = new WeakMap(), b = new WeakMap(), w = new WeakMap(), k = new WeakMap(), o = new WeakSet(), T = function(t, a) {
300
- G.has(t) ? e(this, s)[t] = a !== null : a === null ? e(this, s).removeAttribute(t) : e(this, s).setAttribute(t, a);
301
- }, q = function() {
302
- e(this, s).querySelectorAll("source").forEach((t) => t.remove()), this.querySelectorAll("source").forEach((t) => {
303
- e(this, s).appendChild(t.cloneNode(!0));
304
- }), e(this, s).querySelectorAll("source").length > 0 && !e(this, s).src && e(this, s).load();
305
- }, D = function() {
306
- if (!(e(this, c) && !e(this, c).isDestroyed))
307
- try {
308
- const t = this.getAttribute("mode") || "canvas";
309
- l(this, c, z({ canvas: e(this, $), mode: t }));
310
- } catch {
311
- }
312
- }, P = function() {
313
- if (!(!e(this, b) || !e(this, c)))
314
- if (d(this, o, L).call(this), "requestVideoFrameCallback" in e(this, s)) {
315
- const t = () => {
316
- !e(this, b) || !e(this, c) || (d(this, o, U).call(this), l(this, k, e(this, s).requestVideoFrameCallback(t)));
317
- };
318
- l(this, k, e(this, s).requestVideoFrameCallback(t));
319
- } else {
320
- const t = () => {
321
- !e(this, b) || !e(this, c) || (d(this, o, U).call(this), l(this, w, requestAnimationFrame(t)));
322
- };
323
- l(this, w, requestAnimationFrame(t));
324
- }
325
- }, L = function() {
326
- var t, a;
327
- e(this, k) && ((a = (t = e(this, s)).cancelVideoFrameCallback) == null || a.call(t, e(this, k)), l(this, k, 0)), e(this, w) && (cancelAnimationFrame(e(this, w)), l(this, w, 0));
328
- }, U = function() {
329
- e(this, s).readyState < 2 || !e(this, c) || e(this, c).drawFrame(e(this, s));
330
- }, B(K, "observedAttributes", [..._]);
331
96
  export {
332
- K as AlphaVideoKitSVG,
333
- N as createCanvasFilterRenderer,
334
- z as createRenderer,
335
- H as createSvgFilterRenderer
97
+ k as AlphaVideoKitCanvas,
98
+ b as AlphaVideoKitSVG,
99
+ $ as createCanvasFilterRenderer,
100
+ R as createRenderer,
101
+ x as createSvgFilterRenderer
336
102
  };
package/dist/register.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const e=require("./index.cjs");customElements.get("alpha-video-kit-svg")||customElements.define("alpha-video-kit-svg",e.AlphaVideoKitSVG);
1
+ "use strict";const e=require("./canvas-component-CJM11n9O.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,2 +1,3 @@
1
- import { AlphaVideoKitSVG as e } from "./index.js";
1
+ import { a as e, A as a } from "./canvas-component-DMsm7VdA.js";
2
2
  customElements.get("alpha-video-kit-svg") || customElements.define("alpha-video-kit-svg", e);
3
+ customElements.get("alpha-video-kit-canvas") || customElements.define("alpha-video-kit-canvas", a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpha-video-kit/svg",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "SVG filter-based renderer for stacked alpha videos",
5
5
  "type": "module",
6
6
  "files": ["dist", "react.d.ts"],
package/react.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { AlphaVideoKitSVG } from './dist/index.js';
2
+ import type { AlphaVideoKitCanvas } from './dist/index.js';
2
3
 
3
4
  interface AlphaVideoKitSVGAttributes extends React.HTMLAttributes<AlphaVideoKitSVG> {
4
5
  src?: string;
@@ -11,13 +12,26 @@ interface AlphaVideoKitSVGAttributes extends React.HTMLAttributes<AlphaVideoKitS
11
12
  poster?: string;
12
13
  width?: number | string;
13
14
  height?: number | string;
14
- mode?: 'canvas' | 'svg-filter';
15
+ }
16
+
17
+ interface AlphaVideoKitCanvasAttributes extends React.HTMLAttributes<AlphaVideoKitCanvas> {
18
+ src?: string;
19
+ crossOrigin?: string;
20
+ preload?: string;
21
+ autoPlay?: boolean;
22
+ loop?: boolean;
23
+ muted?: boolean;
24
+ playsInline?: boolean;
25
+ poster?: string;
26
+ width?: number | string;
27
+ height?: number | string;
15
28
  }
16
29
 
17
30
  declare global {
18
31
  namespace JSX {
19
32
  interface IntrinsicElements {
20
33
  'alpha-video-kit-svg': AlphaVideoKitSVGAttributes;
34
+ 'alpha-video-kit-canvas': AlphaVideoKitCanvasAttributes;
21
35
  }
22
36
  }
23
37
  }