UNPKG

@aidenlx/player

Version:

Headless web components that make integrating media on the a web a breeze.

34 lines (31 loc) 2.25 kB
import{a as g}from"./chunk.M4FYSJAP.js";import{b as d}from"./chunk.IZOPTWJO.js";import{a as s,b as n}from"./chunk.KCC3AAG2.js";import{J as l,T as h,_ as m,a as r,b as c,e as o,ia as p,ja as u,t as a}from"./chunk.PWTX2M5C.js";var b=new Set,e=class extends u{constructor(){super();this.__canLoad=!1;this.si=new g(this);d(this,"currentPoster",t=>{window.requestAnimationFrame(()=>{!this.__canLoad&&!b.has(t)&&(m(t,"prefetch"),b.add(t))}),this.__src=t,this.__canLoad&&this.ii()}),d(this,"canLoad",t=>{a(this.loading)&&this.Qe(t)});let i=l(this,{threshold:0},t=>{if(this.loading!=="lazy"){i.hostDisconnected();return}t[0]?.isIntersecting&&(this.Qe(!0),i.hostDisconnected())})}static get styles(){return[p` :host { display: block; contain: content; pointer-events: none; object-fit: cover; box-sizing: border-box; } :host([hidden]) { display: none; } img { display: block; width: 100%; height: 100%; pointer-events: none; object-fit: inherit; object-position: inherit; user-select: none; -webkit-user-select: none; box-sizing: border-box; } `]}get src(){return this.__src}connectedCallback(){super.connectedCallback(),this.loading==="eager"&&this.Qe(!0),this.si.hidePoster()}disconnectedCallback(){this.si.showPoster(),super.disconnectedCallback(),this.__src=void 0,this.Qe(!1)}render(){return c` <img part="img" src=${o(this.__canLoad?this.src:null)} alt=${o(this.alt)} @load=${this.bs} @error=${this.Ss} /> `}ii(){this.removeAttribute("img-error"),this.removeAttribute("img-loaded"),this.__canLoad&&this.src&&this.setAttribute("img-loading","")}bs(){this.removeAttribute("img-loading"),this.setAttribute("img-loaded","")}Ss(){this.removeAttribute("img-loading"),this.setAttribute("img-error","")}Qe(i){i?this.ii():(this.removeAttribute("img-error"),this.removeAttribute("img-loaded"),this.removeAttribute("img-loading")),this.__canLoad=i}};r([n()],e.prototype,"__src",2),r([n()],e.prototype,"__canLoad",2),r([s()],e.prototype,"loading",2),r([s()],e.prototype,"alt",2);h("vds-poster",e);