UNPKG

@aidenlx/player

Version:

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

40 lines (39 loc) 1.22 kB
import "../../chunks/chunk.LNH2V2XS.js"; import { camelToKebabCase, DisposalBin } from "@vidstack/foundation"; import { mediaStoreContext } from "../store"; class MediaStyleController { constructor(_host, _mediaProps) { this._host = _host; this._mediaProps = _mediaProps; this._disposal = new DisposalBin(); this._consumer = mediaStoreContext.consume(_host); _host.addController({ hostConnected: this._hostConnected.bind(this), hostDisconnected: this._hostDisconnected.bind(this) }); } _hostConnected() { for (const propName of this._mediaProps) { const store = this._consumer.value[propName]; if (store) { const attrName = this._getMediaAttrName(propName); const unsub = store.subscribe(($v) => { this._handleValueChange(propName, attrName, $v); }); this._disposal.add(unsub); } } } _hostDisconnected() { for (const propName of this._mediaProps) { this._handleDisconnect(propName, this._getMediaAttrName(propName)); } this._disposal.empty(); } _getMediaAttrName(propName) { return `media-${camelToKebabCase(propName.replace("media", ""))}`; } } export { MediaStyleController };