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 enterFullscreenIcon = ``; const exitFullscreenIcon = ``; const slotTemplate = document.createElement("template"); slotTemplate.innerHTML = /*html*/ ` ${enterFullscreenIcon} ${exitFullscreenIcon} `; const tooltipContent = ( /*html*/ ` ${tooltipLabels.ENTER_FULLSCREEN} ${tooltipLabels.EXIT_FULLSCREEN} ` ); const updateAriaLabel = (el) => { const label = el.mediaIsFullscreen ? verbs.EXIT_FULLSCREEN() : verbs.ENTER_FULLSCREEN(); el.setAttribute("aria-label", label); }; class MediaFullscreenButton extends MediaChromeButton { static get observedAttributes() { return [ ...super.observedAttributes, MediaUIAttributes.MEDIA_IS_FULLSCREEN, MediaUIAttributes.MEDIA_FULLSCREEN_UNAVAILABLE ]; } constructor(options = {}) { super({ slotTemplate, tooltipContent, ...options }); } connectedCallback() { super.connectedCallback(); updateAriaLabel(this); } attributeChangedCallback(attrName, oldValue, newValue) { super.attributeChangedCallback(attrName, oldValue, newValue); if (attrName === MediaUIAttributes.MEDIA_IS_FULLSCREEN) { updateAriaLabel(this); } } /** * @type {string | undefined} Fullscreen unavailability state */ get mediaFullscreenUnavailable() { return getStringAttr(this, MediaUIAttributes.MEDIA_FULLSCREEN_UNAVAILABLE); } set mediaFullscreenUnavailable(value) { setStringAttr(this, MediaUIAttributes.MEDIA_FULLSCREEN_UNAVAILABLE, value); } /** * @type {boolean} Whether fullscreen is available */ get mediaIsFullscreen() { return getBooleanAttr(this, MediaUIAttributes.MEDIA_IS_FULLSCREEN); } set mediaIsFullscreen(value) { setBooleanAttr(this, MediaUIAttributes.MEDIA_IS_FULLSCREEN, value); } handleClick() { const eventName = this.mediaIsFullscreen ? MediaUIEvents.MEDIA_EXIT_FULLSCREEN_REQUEST : MediaUIEvents.MEDIA_ENTER_FULLSCREEN_REQUEST; this.dispatchEvent( new globalThis.CustomEvent(eventName, { composed: true, bubbles: true }) ); } } if (!globalThis.customElements.get("media-fullscreen-button")) { globalThis.customElements.define( "media-fullscreen-button", MediaFullscreenButton ); } var media_fullscreen_button_default = MediaFullscreenButton; export { media_fullscreen_button_default as default };