@alpha-video-kit/svg 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
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;
@@ -0,0 +1,464 @@
1
+ var N = Object.defineProperty;
2
+ var W = (o) => {
3
+ throw TypeError(o);
4
+ };
5
+ var z = (o, h, t) => h in o ? N(o, h, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[h] = t;
6
+ var H = (o, h, t) => z(o, typeof h != "symbol" ? h + "" : h, t), $ = (o, h, t) => h.has(o) || W("Cannot " + t);
7
+ 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) ? W("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);
8
+ const j = [
9
+ "src",
10
+ "crossorigin",
11
+ "preload",
12
+ "autoplay",
13
+ "loop",
14
+ "muted",
15
+ "playsinline",
16
+ "poster",
17
+ "width",
18
+ "height"
19
+ ], U = /* @__PURE__ */ new Set(["autoplay", "loop", "muted", "playsinline"]), Y = [
20
+ "loadstart",
21
+ "progress",
22
+ "suspend",
23
+ "abort",
24
+ "error",
25
+ "emptied",
26
+ "stalled",
27
+ "loadedmetadata",
28
+ "loadeddata",
29
+ "canplay",
30
+ "canplaythrough",
31
+ "playing",
32
+ "waiting",
33
+ "seeking",
34
+ "seeked",
35
+ "ended",
36
+ "durationchange",
37
+ "timeupdate",
38
+ "play",
39
+ "pause",
40
+ "ratechange",
41
+ "resize",
42
+ "volumechange"
43
+ ];
44
+ var s, T, S, A, R, y, k, c, P, I, V;
45
+ class J extends HTMLElement {
46
+ constructor() {
47
+ super();
48
+ l(this, c);
49
+ l(this, s);
50
+ l(this, T);
51
+ l(this, S);
52
+ l(this, A);
53
+ l(this, R);
54
+ l(this, y, null);
55
+ l(this, k);
56
+ const t = this.attachShadow({ mode: "open" });
57
+ a(this, k, `avk-${Math.random().toString(36).slice(2, 8)}`), t.innerHTML = `<style>
58
+ :host{display:inline-block;overflow:hidden}
59
+ svg{display:block;width:100%;height:auto}
60
+ video{display:block;width:100%;height:100%}
61
+ </style>
62
+ <svg viewBox="0 0 1 1" preserveAspectRatio="xMidYMid meet">
63
+ <defs>
64
+ <filter id="${e(this, k)}" filterUnits="userSpaceOnUse" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
65
+ <feOffset in="SourceGraphic" dy="0" result="s"/>
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
+ <feComposite in="SourceGraphic" in2="a" operator="in"/>
68
+ </filter>
69
+ </defs>
70
+ <foreignObject width="1" height="1" filter="url(#${e(this, k)})">
71
+ <video></video>
72
+ </foreignObject>
73
+ </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"));
74
+ for (const r of Y)
75
+ e(this, s).addEventListener(r, (d) => {
76
+ this.dispatchEvent(new Event(d.type, { bubbles: !1, cancelable: !1 }));
77
+ });
78
+ e(this, s).addEventListener("loadedmetadata", () => u(this, c, P).call(this)), e(this, s).addEventListener("resize", () => u(this, c, P).call(this));
79
+ }
80
+ connectedCallback() {
81
+ for (const t of j)
82
+ this.hasAttribute(t) && u(this, c, I).call(this, t, this.getAttribute(t));
83
+ u(this, c, V).call(this), a(this, y, new MutationObserver(() => u(this, c, V).call(this))), e(this, y).observe(this, { childList: !0 });
84
+ }
85
+ disconnectedCallback() {
86
+ var t;
87
+ (t = e(this, y)) == null || t.disconnect(), a(this, y, null);
88
+ }
89
+ attributeChangedCallback(t, r, d) {
90
+ u(this, c, I).call(this, t, d);
91
+ }
92
+ // --- Proxied properties ---
93
+ get src() {
94
+ return e(this, s).src;
95
+ }
96
+ set src(t) {
97
+ this.setAttribute("src", t);
98
+ }
99
+ get currentSrc() {
100
+ return e(this, s).currentSrc;
101
+ }
102
+ get currentTime() {
103
+ return e(this, s).currentTime;
104
+ }
105
+ set currentTime(t) {
106
+ e(this, s).currentTime = t;
107
+ }
108
+ get duration() {
109
+ return e(this, s).duration;
110
+ }
111
+ get paused() {
112
+ return e(this, s).paused;
113
+ }
114
+ get ended() {
115
+ return e(this, s).ended;
116
+ }
117
+ get readyState() {
118
+ return e(this, s).readyState;
119
+ }
120
+ get videoWidth() {
121
+ return e(this, s).videoWidth;
122
+ }
123
+ get videoHeight() {
124
+ return Math.floor(e(this, s).videoHeight / 2);
125
+ }
126
+ get volume() {
127
+ return e(this, s).volume;
128
+ }
129
+ set volume(t) {
130
+ e(this, s).volume = t;
131
+ }
132
+ get playbackRate() {
133
+ return e(this, s).playbackRate;
134
+ }
135
+ set playbackRate(t) {
136
+ e(this, s).playbackRate = t;
137
+ }
138
+ get defaultPlaybackRate() {
139
+ return e(this, s).defaultPlaybackRate;
140
+ }
141
+ set defaultPlaybackRate(t) {
142
+ e(this, s).defaultPlaybackRate = t;
143
+ }
144
+ get muted() {
145
+ return e(this, s).muted;
146
+ }
147
+ set muted(t) {
148
+ e(this, s).muted = t, this.toggleAttribute("muted", t);
149
+ }
150
+ get loop() {
151
+ return e(this, s).loop;
152
+ }
153
+ set loop(t) {
154
+ e(this, s).loop = t, this.toggleAttribute("loop", t);
155
+ }
156
+ get autoplay() {
157
+ return e(this, s).autoplay;
158
+ }
159
+ set autoplay(t) {
160
+ e(this, s).autoplay = t, this.toggleAttribute("autoplay", t);
161
+ }
162
+ get preload() {
163
+ return e(this, s).preload;
164
+ }
165
+ set preload(t) {
166
+ this.setAttribute("preload", t);
167
+ }
168
+ get crossOrigin() {
169
+ return e(this, s).crossOrigin;
170
+ }
171
+ set crossOrigin(t) {
172
+ t === null ? this.removeAttribute("crossorigin") : this.setAttribute("crossorigin", t);
173
+ }
174
+ get buffered() {
175
+ return e(this, s).buffered;
176
+ }
177
+ get seekable() {
178
+ return e(this, s).seekable;
179
+ }
180
+ get played() {
181
+ return e(this, s).played;
182
+ }
183
+ get networkState() {
184
+ return e(this, s).networkState;
185
+ }
186
+ get error() {
187
+ return e(this, s).error;
188
+ }
189
+ get seeking() {
190
+ return e(this, s).seeking;
191
+ }
192
+ // --- Proxied methods ---
193
+ play() {
194
+ return e(this, s).play();
195
+ }
196
+ pause() {
197
+ e(this, s).pause();
198
+ }
199
+ load() {
200
+ e(this, s).load();
201
+ }
202
+ canPlayType(t) {
203
+ return e(this, s).canPlayType(t);
204
+ }
205
+ }
206
+ 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() {
207
+ const t = e(this, s).videoWidth, r = e(this, s).videoHeight;
208
+ if (!t || !r) return;
209
+ const d = Math.floor(r / 2);
210
+ 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));
211
+ }, I = function(t, r) {
212
+ U.has(t) ? e(this, s)[t] = r !== null : r === null ? e(this, s).removeAttribute(t) : e(this, s).setAttribute(t, r);
213
+ }, V = function() {
214
+ e(this, s).querySelectorAll("source").forEach((t) => t.remove()), this.querySelectorAll("source").forEach((t) => {
215
+ e(this, s).appendChild(t.cloneNode(!0));
216
+ }), e(this, s).querySelectorAll("source").length > 0 && !e(this, s).src && e(this, s).load();
217
+ }, H(J, "observedAttributes", [...j]);
218
+ const D = [
219
+ "src",
220
+ "crossorigin",
221
+ "preload",
222
+ "autoplay",
223
+ "loop",
224
+ "muted",
225
+ "playsinline",
226
+ "poster",
227
+ "width",
228
+ "height"
229
+ ], K = /* @__PURE__ */ new Set(["autoplay", "loop", "muted", "playsinline"]), Q = [
230
+ "loadstart",
231
+ "progress",
232
+ "suspend",
233
+ "abort",
234
+ "error",
235
+ "emptied",
236
+ "stalled",
237
+ "loadedmetadata",
238
+ "loadeddata",
239
+ "canplay",
240
+ "canplaythrough",
241
+ "playing",
242
+ "waiting",
243
+ "seeking",
244
+ "seeked",
245
+ "ended",
246
+ "durationchange",
247
+ "timeupdate",
248
+ "play",
249
+ "pause",
250
+ "ratechange",
251
+ "resize",
252
+ "volumechange"
253
+ ];
254
+ var i, g, q, C, w, O, M, v, m, p, f, b, E, n, x, B, F, G, L, _;
255
+ class X extends HTMLElement {
256
+ constructor() {
257
+ super();
258
+ l(this, n);
259
+ l(this, i);
260
+ l(this, g);
261
+ l(this, q);
262
+ l(this, C);
263
+ l(this, w);
264
+ l(this, O);
265
+ l(this, M);
266
+ l(this, v, null);
267
+ l(this, m, null);
268
+ l(this, p, !1);
269
+ l(this, f, 0);
270
+ l(this, b, 0);
271
+ l(this, E);
272
+ const t = this.attachShadow({ mode: "open" });
273
+ a(this, E, `avk-c-${Math.random().toString(36).slice(2, 8)}`), t.innerHTML = `<style>
274
+ :host{display:inline-block;overflow:hidden}
275
+ video{position:absolute;opacity:0;pointer-events:none;width:0;height:0}
276
+ svg{display:block;width:100%;height:auto}
277
+ canvas{display:block;width:100%;height:100%}
278
+ </style>
279
+ <video></video>
280
+ <svg viewBox="0 0 1 1" preserveAspectRatio="xMidYMid meet">
281
+ <defs>
282
+ <filter id="${e(this, E)}" filterUnits="userSpaceOnUse" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
283
+ <feOffset in="SourceGraphic" dy="0" result="s"/>
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 }));
295
+ });
296
+ e(this, i).addEventListener("loadedmetadata", () => u(this, n, x).call(this)), e(this, i).addEventListener("resize", () => u(this, n, x).call(this));
297
+ }
298
+ connectedCallback() {
299
+ for (const t of D)
300
+ this.hasAttribute(t) && u(this, n, B).call(this, t, this.getAttribute(t));
301
+ 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(
302
+ ([t]) => {
303
+ a(this, p, t.isIntersecting), e(this, p) ? u(this, n, G).call(this) : u(this, n, L).call(this);
304
+ },
305
+ { threshold: 0 }
306
+ )), e(this, v).observe(this);
307
+ }
308
+ disconnectedCallback() {
309
+ var t, r;
310
+ 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);
311
+ }
312
+ attributeChangedCallback(t, r, d) {
313
+ u(this, n, B).call(this, t, d);
314
+ }
315
+ // --- Proxied properties ---
316
+ get src() {
317
+ return e(this, i).src;
318
+ }
319
+ set src(t) {
320
+ this.setAttribute("src", t);
321
+ }
322
+ get currentSrc() {
323
+ return e(this, i).currentSrc;
324
+ }
325
+ get currentTime() {
326
+ return e(this, i).currentTime;
327
+ }
328
+ set currentTime(t) {
329
+ e(this, i).currentTime = t;
330
+ }
331
+ get duration() {
332
+ return e(this, i).duration;
333
+ }
334
+ get paused() {
335
+ return e(this, i).paused;
336
+ }
337
+ get ended() {
338
+ return e(this, i).ended;
339
+ }
340
+ get readyState() {
341
+ return e(this, i).readyState;
342
+ }
343
+ get videoWidth() {
344
+ return e(this, i).videoWidth;
345
+ }
346
+ get videoHeight() {
347
+ return Math.floor(e(this, i).videoHeight / 2);
348
+ }
349
+ get volume() {
350
+ return e(this, i).volume;
351
+ }
352
+ set volume(t) {
353
+ e(this, i).volume = t;
354
+ }
355
+ get playbackRate() {
356
+ return e(this, i).playbackRate;
357
+ }
358
+ set playbackRate(t) {
359
+ e(this, i).playbackRate = t;
360
+ }
361
+ get defaultPlaybackRate() {
362
+ return e(this, i).defaultPlaybackRate;
363
+ }
364
+ set defaultPlaybackRate(t) {
365
+ e(this, i).defaultPlaybackRate = t;
366
+ }
367
+ get muted() {
368
+ return e(this, i).muted;
369
+ }
370
+ set muted(t) {
371
+ e(this, i).muted = t, this.toggleAttribute("muted", t);
372
+ }
373
+ get loop() {
374
+ return e(this, i).loop;
375
+ }
376
+ set loop(t) {
377
+ e(this, i).loop = t, this.toggleAttribute("loop", t);
378
+ }
379
+ get autoplay() {
380
+ return e(this, i).autoplay;
381
+ }
382
+ set autoplay(t) {
383
+ e(this, i).autoplay = t, this.toggleAttribute("autoplay", t);
384
+ }
385
+ get preload() {
386
+ return e(this, i).preload;
387
+ }
388
+ set preload(t) {
389
+ this.setAttribute("preload", t);
390
+ }
391
+ get crossOrigin() {
392
+ return e(this, i).crossOrigin;
393
+ }
394
+ set crossOrigin(t) {
395
+ t === null ? this.removeAttribute("crossorigin") : this.setAttribute("crossorigin", t);
396
+ }
397
+ get buffered() {
398
+ return e(this, i).buffered;
399
+ }
400
+ get seekable() {
401
+ return e(this, i).seekable;
402
+ }
403
+ get played() {
404
+ return e(this, i).played;
405
+ }
406
+ get networkState() {
407
+ return e(this, i).networkState;
408
+ }
409
+ get error() {
410
+ return e(this, i).error;
411
+ }
412
+ get seeking() {
413
+ return e(this, i).seeking;
414
+ }
415
+ // --- Proxied methods ---
416
+ play() {
417
+ return e(this, i).play();
418
+ }
419
+ pause() {
420
+ e(this, i).pause();
421
+ }
422
+ load() {
423
+ e(this, i).load();
424
+ }
425
+ canPlayType(t) {
426
+ return e(this, i).canPlayType(t);
427
+ }
428
+ }
429
+ 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() {
430
+ const t = e(this, i).videoWidth, r = e(this, i).videoHeight;
431
+ if (!t || !r) return;
432
+ const d = Math.floor(r / 2);
433
+ 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;
434
+ }, B = function(t, r) {
435
+ K.has(t) ? e(this, i)[t] = r !== null : r === null ? e(this, i).removeAttribute(t) : e(this, i).setAttribute(t, r);
436
+ }, F = function() {
437
+ e(this, i).querySelectorAll("source").forEach((t) => t.remove()), this.querySelectorAll("source").forEach((t) => {
438
+ e(this, i).appendChild(t.cloneNode(!0));
439
+ }), e(this, i).querySelectorAll("source").length > 0 && !e(this, i).src && e(this, i).load();
440
+ }, G = function() {
441
+ if (e(this, p))
442
+ if (u(this, n, L).call(this), "requestVideoFrameCallback" in e(this, i)) {
443
+ const t = () => {
444
+ e(this, p) && (u(this, n, _).call(this), a(this, b, e(this, i).requestVideoFrameCallback(t)));
445
+ };
446
+ a(this, b, e(this, i).requestVideoFrameCallback(t));
447
+ } else {
448
+ const t = () => {
449
+ e(this, p) && (u(this, n, _).call(this), a(this, f, requestAnimationFrame(t)));
450
+ };
451
+ a(this, f, requestAnimationFrame(t));
452
+ }
453
+ }, L = function() {
454
+ var t, r;
455
+ 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));
456
+ }, _ = function() {
457
+ if (e(this, i).readyState < 2) return;
458
+ const t = e(this, i).videoWidth, r = e(this, i).videoHeight;
459
+ !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));
460
+ }, H(X, "observedAttributes", [...D]);
461
+ export {
462
+ X as A,
463
+ J as a
464
+ };
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-B4CLR7ME.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,78 @@
1
+ /**
2
+ * `<alpha-video-kit-canvas>` — Canvas 2D wrapped in an SVG with an inline filter.
3
+ *
4
+ * Structure:
5
+ * <video hidden> ← source, not displayed
6
+ * <svg viewBox="0 0 W H/2"> ← clips to top half
7
+ * <filter> ← feOffset + feColorMatrix + feComposite
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.
14
+ */
15
+ export declare class AlphaVideoKitCanvas extends HTMLElement {
16
+ #private;
17
+ static observedAttributes: ("src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster" | "width" | "height")[];
18
+ constructor();
19
+ connectedCallback(): void;
20
+ disconnectedCallback(): void;
21
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
22
+ get src(): string;
23
+ set src(v: string);
24
+ get currentSrc(): string;
25
+ get currentTime(): number;
26
+ set currentTime(v: number);
27
+ get duration(): number;
28
+ get paused(): boolean;
29
+ get ended(): boolean;
30
+ get readyState(): number;
31
+ get videoWidth(): number;
32
+ get videoHeight(): number;
33
+ get volume(): number;
34
+ set volume(v: number);
35
+ get playbackRate(): number;
36
+ set playbackRate(v: number);
37
+ get defaultPlaybackRate(): number;
38
+ set defaultPlaybackRate(v: number);
39
+ get muted(): boolean;
40
+ set muted(v: boolean);
41
+ get loop(): boolean;
42
+ set loop(v: boolean);
43
+ get autoplay(): boolean;
44
+ set autoplay(v: boolean);
45
+ get preload(): string;
46
+ set preload(v: string);
47
+ get crossOrigin(): string | null;
48
+ set crossOrigin(v: string | null);
49
+ get buffered(): TimeRanges;
50
+ get seekable(): TimeRanges;
51
+ get played(): TimeRanges;
52
+ get networkState(): number;
53
+ get error(): MediaError | null;
54
+ get seeking(): boolean;
55
+ play(): Promise<void>;
56
+ pause(): void;
57
+ load(): void;
58
+ canPlayType(type: string): CanPlayTypeResult;
59
+ }
60
+
61
+ /**
62
+ * `<alpha-video-kit-svg>` — video wrapped in an SVG with an inline filter.
63
+ *
64
+ * Structure:
65
+ * <svg viewBox="0 0 W H/2"> ← clips to top half
66
+ * <filter> ← feOffset + feColorMatrix + feComposite
67
+ * <foreignObject W×H filter> ← full-height video with filter applied
68
+ * <video>
69
+ *
70
+ * No canvas, no render loop. The browser composites the stacked-alpha halves
71
+ * via the SVG filter pipeline on every paint.
72
+ */
1
73
  export declare class AlphaVideoKitSVG extends HTMLElement {
2
74
  #private;
3
- static observedAttributes: ("mode" | "src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster" | "width" | "height")[];
75
+ static observedAttributes: ("src" | "crossorigin" | "preload" | "autoplay" | "loop" | "muted" | "playsinline" | "poster" | "width" | "height")[];
4
76
  constructor();
5
77
  connectedCallback(): void;
6
78
  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-ChQNZXEV.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-B4CLR7ME.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-ChQNZXEV.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.2",
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
  }