123 lines
5.0 KiB
JavaScript
123 lines
5.0 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var media_mute_button_exports = {};
|
|
__export(media_mute_button_exports, {
|
|
default: () => media_mute_button_default
|
|
});
|
|
module.exports = __toCommonJS(media_mute_button_exports);
|
|
var import_media_chrome_button = require("./media-chrome-button.js");
|
|
var import_server_safe_globals = require("./utils/server-safe-globals.js");
|
|
var import_constants = require("./constants.js");
|
|
var import_labels = require("./labels/labels.js");
|
|
var import_element_utils = require("./utils/element-utils.js");
|
|
const { MEDIA_VOLUME_LEVEL } = import_constants.MediaUIAttributes;
|
|
const offIcon = `<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
<path d="M16.5 12A4.5 4.5 0 0 0 14 8v2.18l2.45 2.45a4.22 4.22 0 0 0 .05-.63Zm2.5 0a6.84 6.84 0 0 1-.54 2.64L20 16.15A8.8 8.8 0 0 0 21 12a9 9 0 0 0-7-8.77v2.06A7 7 0 0 1 19 12ZM4.27 3 3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25A6.92 6.92 0 0 1 14 18.7v2.06A9 9 0 0 0 17.69 19l2 2.05L21 19.73l-9-9L4.27 3ZM12 4 9.91 6.09 12 8.18V4Z"/>
|
|
</svg>`;
|
|
const lowIcon = `<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
<path d="M3 9v6h4l5 5V4L7 9H3Zm13.5 3A4.5 4.5 0 0 0 14 8v8a4.47 4.47 0 0 0 2.5-4Z"/>
|
|
</svg>`;
|
|
const highIcon = `<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
<path d="M3 9v6h4l5 5V4L7 9H3Zm13.5 3A4.5 4.5 0 0 0 14 8v8a4.47 4.47 0 0 0 2.5-4ZM14 3.23v2.06a7 7 0 0 1 0 13.42v2.06a9 9 0 0 0 0-17.54Z"/>
|
|
</svg>`;
|
|
const slotTemplate = import_server_safe_globals.document.createElement("template");
|
|
slotTemplate.innerHTML = /*html*/
|
|
`
|
|
<style>
|
|
${/* Default to High slot/icon. */
|
|
""}
|
|
:host(:not([${MEDIA_VOLUME_LEVEL}])) slot[name=icon] slot:not([name=high]),
|
|
:host([${MEDIA_VOLUME_LEVEL}=high]) slot[name=icon] slot:not([name=high]) {
|
|
display: none !important;
|
|
}
|
|
|
|
:host([${MEDIA_VOLUME_LEVEL}=off]) slot[name=icon] slot:not([name=off]) {
|
|
display: none !important;
|
|
}
|
|
|
|
:host([${MEDIA_VOLUME_LEVEL}=low]) slot[name=icon] slot:not([name=low]) {
|
|
display: none !important;
|
|
}
|
|
|
|
:host([${MEDIA_VOLUME_LEVEL}=medium]) slot[name=icon] slot:not([name=medium]) {
|
|
display: none !important;
|
|
}
|
|
|
|
:host(:not([${MEDIA_VOLUME_LEVEL}=off])) slot[name=tooltip-unmute],
|
|
:host([${MEDIA_VOLUME_LEVEL}=off]) slot[name=tooltip-mute] {
|
|
display: none;
|
|
}
|
|
</style>
|
|
|
|
<slot name="icon">
|
|
<slot name="off">${offIcon}</slot>
|
|
<slot name="low">${lowIcon}</slot>
|
|
<slot name="medium">${lowIcon}</slot>
|
|
<slot name="high">${highIcon}</slot>
|
|
</slot>
|
|
`;
|
|
const tooltipContent = (
|
|
/*html*/
|
|
`
|
|
<slot name="tooltip-mute">${import_labels.tooltipLabels.MUTE}</slot>
|
|
<slot name="tooltip-unmute">${import_labels.tooltipLabels.UNMUTE}</slot>
|
|
`
|
|
);
|
|
const updateAriaLabel = (el) => {
|
|
const muted = el.mediaVolumeLevel === "off";
|
|
const label = muted ? import_labels.verbs.UNMUTE() : import_labels.verbs.MUTE();
|
|
el.setAttribute("aria-label", label);
|
|
};
|
|
class MediaMuteButton extends import_media_chrome_button.MediaChromeButton {
|
|
static get observedAttributes() {
|
|
return [...super.observedAttributes, import_constants.MediaUIAttributes.MEDIA_VOLUME_LEVEL];
|
|
}
|
|
constructor(options = {}) {
|
|
super({ slotTemplate, tooltipContent, ...options });
|
|
}
|
|
connectedCallback() {
|
|
updateAriaLabel(this);
|
|
super.connectedCallback();
|
|
}
|
|
attributeChangedCallback(attrName, oldValue, newValue) {
|
|
if (attrName === import_constants.MediaUIAttributes.MEDIA_VOLUME_LEVEL) {
|
|
updateAriaLabel(this);
|
|
}
|
|
super.attributeChangedCallback(attrName, oldValue, newValue);
|
|
}
|
|
/**
|
|
* @type {string | undefined}
|
|
*/
|
|
get mediaVolumeLevel() {
|
|
return (0, import_element_utils.getStringAttr)(this, import_constants.MediaUIAttributes.MEDIA_VOLUME_LEVEL);
|
|
}
|
|
set mediaVolumeLevel(value) {
|
|
(0, import_element_utils.setStringAttr)(this, import_constants.MediaUIAttributes.MEDIA_VOLUME_LEVEL, value);
|
|
}
|
|
handleClick() {
|
|
const eventName = this.mediaVolumeLevel === "off" ? import_constants.MediaUIEvents.MEDIA_UNMUTE_REQUEST : import_constants.MediaUIEvents.MEDIA_MUTE_REQUEST;
|
|
this.dispatchEvent(
|
|
new import_server_safe_globals.globalThis.CustomEvent(eventName, { composed: true, bubbles: true })
|
|
);
|
|
}
|
|
}
|
|
if (!import_server_safe_globals.globalThis.customElements.get("media-mute-button")) {
|
|
import_server_safe_globals.globalThis.customElements.define("media-mute-button", MediaMuteButton);
|
|
}
|
|
var media_mute_button_default = MediaMuteButton;
|