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