import { MediaChromeButton } from "./media-chrome-button.js"; import { globalThis, document } from "./utils/server-safe-globals.js"; import { MediaUIEvents, MediaUIAttributes } from "./constants.js"; import { tooltipLabels, verbs } from "./labels/labels.js"; import { getStringAttr, setStringAttr } from "./utils/element-utils.js"; const { MEDIA_VOLUME_LEVEL } = MediaUIAttributes; const offIcon = ``; const lowIcon = ``; const highIcon = ``; const slotTemplate = document.createElement("template"); slotTemplate.innerHTML = /*html*/ ` ${offIcon} ${lowIcon} ${lowIcon} ${highIcon} `; const tooltipContent = ( /*html*/ ` ${tooltipLabels.MUTE} ${tooltipLabels.UNMUTE} ` ); const updateAriaLabel = (el) => { const muted = el.mediaVolumeLevel === "off"; const label = muted ? verbs.UNMUTE() : verbs.MUTE(); el.setAttribute("aria-label", label); }; class MediaMuteButton extends MediaChromeButton { static get observedAttributes() { return [...super.observedAttributes, MediaUIAttributes.MEDIA_VOLUME_LEVEL]; } constructor(options = {}) { super({ slotTemplate, tooltipContent, ...options }); } connectedCallback() { updateAriaLabel(this); super.connectedCallback(); } attributeChangedCallback(attrName, oldValue, newValue) { if (attrName === MediaUIAttributes.MEDIA_VOLUME_LEVEL) { updateAriaLabel(this); } super.attributeChangedCallback(attrName, oldValue, newValue); } /** * @type {string | undefined} */ get mediaVolumeLevel() { return getStringAttr(this, MediaUIAttributes.MEDIA_VOLUME_LEVEL); } set mediaVolumeLevel(value) { setStringAttr(this, MediaUIAttributes.MEDIA_VOLUME_LEVEL, value); } handleClick() { const eventName = this.mediaVolumeLevel === "off" ? MediaUIEvents.MEDIA_UNMUTE_REQUEST : MediaUIEvents.MEDIA_MUTE_REQUEST; this.dispatchEvent( new globalThis.CustomEvent(eventName, { composed: true, bubbles: true }) ); } } if (!globalThis.customElements.get("media-mute-button")) { globalThis.customElements.define("media-mute-button", MediaMuteButton); } var media_mute_button_default = MediaMuteButton; export { media_mute_button_default as default };