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 {
getBooleanAttr,
getStringAttr,
setBooleanAttr,
setStringAttr
} from "./utils/element-utils.js";
const pipIcon = ``;
const slotTemplate = document.createElement("template");
slotTemplate.innerHTML = /*html*/
`
${pipIcon}
${pipIcon}
`;
const tooltipContent = (
/*html*/
`
${tooltipLabels.ENTER_PIP}
${tooltipLabels.EXIT_PIP}
`
);
const updateAriaLabel = (el) => {
const label = el.mediaIsPip ? verbs.EXIT_PIP() : verbs.ENTER_PIP();
el.setAttribute("aria-label", label);
};
class MediaPipButton extends MediaChromeButton {
static get observedAttributes() {
return [
...super.observedAttributes,
MediaUIAttributes.MEDIA_IS_PIP,
MediaUIAttributes.MEDIA_PIP_UNAVAILABLE
];
}
constructor(options = {}) {
super({ slotTemplate, tooltipContent, ...options });
}
connectedCallback() {
updateAriaLabel(this);
super.connectedCallback();
}
attributeChangedCallback(attrName, oldValue, newValue) {
if (attrName === MediaUIAttributes.MEDIA_IS_PIP) {
updateAriaLabel(this);
}
super.attributeChangedCallback(attrName, oldValue, newValue);
}
/**
* @type {string | undefined} Pip unavailability state
*/
get mediaPipUnavailable() {
return getStringAttr(this, MediaUIAttributes.MEDIA_PIP_UNAVAILABLE);
}
set mediaPipUnavailable(value) {
setStringAttr(this, MediaUIAttributes.MEDIA_PIP_UNAVAILABLE, value);
}
/**
* @type {boolean} Is the media currently playing picture-in-picture
*/
get mediaIsPip() {
return getBooleanAttr(this, MediaUIAttributes.MEDIA_IS_PIP);
}
set mediaIsPip(value) {
setBooleanAttr(this, MediaUIAttributes.MEDIA_IS_PIP, value);
}
handleClick() {
const eventName = this.mediaIsPip ? MediaUIEvents.MEDIA_EXIT_PIP_REQUEST : MediaUIEvents.MEDIA_ENTER_PIP_REQUEST;
this.dispatchEvent(
new globalThis.CustomEvent(eventName, { composed: true, bubbles: true })
);
}
}
if (!globalThis.customElements.get("media-pip-button")) {
globalThis.customElements.define("media-pip-button", MediaPipButton);
}
var media_pip_button_default = MediaPipButton;
export {
media_pip_button_default as default
};