@aidenlx/player
Version:
Headless web components that make integrating media on the a web a breeze.
31 lines (27 loc) • 1.41 kB
JavaScript
import{a as s}from"./chunk.KCC3AAG2.js";import{T as h,W as i,a as r,b as o,ia as m,ja as p,w as a}from"./chunk.PWTX2M5C.js";var l=m`
:host {
display: block;
height: 0;
padding-bottom: min(
max(var(--vds-min-height), var(--vds-aspect-ratio-percent)),
var(--vds-max-height)
);
position: relative;
width: 100%;
}
:host([hidden]) {
display: none;
}
slot {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
::slotted(*) {
width: 100%;
height: 100%;
}
`;var e=class extends p{constructor(){super(...arguments);this.minHeight="150px";this.maxHeight="100vh";this.ratio="2/1"}static get styles(){return[l]}get isValidRatio(){return a(this.ratio)?/\d{1,2}\s*?(?:\/|:)\s*?\d{1,2}/.test(this.ratio):!1}update(t){super.update(t),t.has("ratio")&&this.Ji(),t.has("minHeight")&&i(this,"min-height",this.minHeight),t.has("maxHeight")&&i(this,"max-height",this.maxHeight)}render(){return o`<slot></slot>`}Ji(){if(this.isValidRatio){let[t,n]=this.Xi();i(this,"aspect-ratio-percent",`${n/t*100}%`)}else i(this,"aspect-ratio-percent","50%")}Xi(){return this.ratio.split(/\s*?(?:\/|:)\s*?/).map(Number)}};r([s({attribute:"min-height",reflect:!0})],e.prototype,"minHeight",2),r([s({attribute:"max-height",reflect:!0})],e.prototype,"maxHeight",2),r([s({reflect:!0})],e.prototype,"ratio",2);h("vds-aspect-ratio",e);