UNPKG

@vime/core

Version:

Customizable, extensible, accessible and framework agnostic media player.

1 lines 3.56 kB
import{g as n}from"./p-aa8acb66.js";function t(n,t,e,o){return n.addEventListener(t,e,o),()=>n.removeEventListener(t,e,o)}const e=(n,t,e=0,o=0,s=0,i=0)=>{const a=n.getBoundingClientRect(),r=t.getBoundingClientRect();return a.left+e<r.right+s&&a.right+e>r.left+s&&a.top+o<r.bottom+i&&a.bottom+o>r.top+i},o=()=>{},s=n=>null===n,i=n=>void 0===n,a=n=>s(n)||i(n),r=n=>a(n)?void 0:n.constructor,l=n=>r(n)===Object,c=n=>r(n)===Number&&!Number.isNaN(n),u=n=>r(n)===String,m=n=>r(n)===Boolean,d=n=>r(n)===Function,v=n=>Array.isArray(n),f=(n,t)=>Boolean(n&&t&&n instanceof t),y=()=>{let n=o,t=o;return{promise:new Promise(((e,o)=>{n=e,t=o})),resolve:n,reject:t}};function b(n,t,e){const o=n[t];n[t]=function(){return e(),o?o.call(n):void 0}}function p(n,t,e){let o=!1;i(t)||(b(n,"componentWillLoad",(()=>{t(),o=!0})),b(n,"connectedCallback",(()=>{o&&t()}))),i(e)||b(n,"disconnectedCallback",(()=>{e()}))}function C(e){const o=n(e);let s;p(e,(()=>{s=t(o,"vmFindPlayer",(n=>{n.stopPropagation(),n.detail(o)}))}),(()=>{null==s||s()}))}const w=(t,e=300,o=10)=>{const s=f(t,HTMLElement)?t:n(t),i=y();let a;const r=new CustomEvent("vmFindPlayer",{bubbles:!0,composed:!0,detail:n=>{i.resolve(n),a()}});return a=function(n,t,e,o=300,s=10){let i,a=0,r=!1;return function l(){r||(i=setTimeout((()=>{a!==s?(n.dispatchEvent(t),a+=1,l()):null==e||e()}),o))}(),()=>{window.clearTimeout(i),r=!0}}(s,r,(()=>{i.reject(`Could not find player for ${s.nodeName}`)}),e,o),i.promise};class g{constructor(n=[]){this.dispose=n}add(n){this.dispose.push(n)}empty(){this.dispose.forEach((n=>n())),this.dispose=[]}}const h=Symbol("vmPlayerKey"),R=Symbol("vmNameKey"),E=Symbol("vmRegistryKey"),P=Symbol("vmRegistrationKey"),S=t=>f(t,HTMLElement)?t:n(t);function j(n,t){const e=Symbol("vmRegistryId"),o=S(n);o[R]=null!=t?t:o.nodeName.toLowerCase(),o[P]=e;const s=new CustomEvent("vmComponentRegister",{bubbles:!0,composed:!0,detail:o});p(n,(()=>{o.dispatchEvent(s)}))}function A(e){const o=n(e),s=new Map,i=new g;function a(n){const t=n.detail,e=S(t);e[h]=o,e[E]=s,s.set(e[P],e),o.dispatchEvent(new CustomEvent("vmComponentRegistered",{detail:e})),p(t,void 0,(()=>function(n){delete n[h],delete n[E],s.delete(n[P]),o.dispatchEvent(new CustomEvent("vmComponentDeregistered",{detail:n}))}(e)))}o[E]=s,p(e,(()=>{i.add(t(o,"vmComponentRegister",a))}),(()=>{s.clear(),i.empty(),delete e[E]}))}function K(n,t){var e;const o=S(n)[E];return Array.from(null!==(e=null==o?void 0:o.values())&&void 0!==e?e:[]).some((n=>n[R]===t))}function k(n){return S(n)[h]}function D(n,t){var e,o;const s=S(n);return Array.from(null!==(o=null===(e=s[E])||void 0===e?void 0:e.values())&&void 0!==o?o:[]).filter((n=>n[R]===t))}function F(n,e,o){var s,a,r,l,c;return a=this,r=void 0,c=function*(){const a=yield w(n),r=new g,l=S(n)[E];function c(n){n.detail[R]===e&&(null==o||o(D(a,e)))}return Array.from(null!==(s=null==l?void 0:l.values())&&void 0!==s?s:[]).forEach((n=>c(new CustomEvent("",{detail:n})))),i(a)||(r.add(t(a,"vmComponentRegistered",c)),r.add(t(a,"vmComponentDeregistered",c))),p(n,(()=>{}),(()=>{r.empty()})),()=>{r.empty()}},new((l=void 0)||(l=Promise))((function(n,t){function e(n){try{s(c.next(n))}catch(n){t(n)}}function o(n){try{s(c.throw(n))}catch(n){t(n)}}function s(t){var s;t.done?n(t.value):(s=t.value,s instanceof l?s:new l((function(n){n(s)}))).then(e,o)}s((c=c.apply(a,r||[])).next())}))}export{R as C,g as D,h as P,P as R,k as a,E as b,j as c,f as d,i as e,w as f,D as g,u as h,K as i,p as j,y as k,t as l,l as m,a as n,v as o,o as p,d as q,b as r,C as s,A as t,c as u,m as v,F as w,s as x,e as y}