var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var _mediaController, _delay;
import {
MediaUIAttributes,
MediaStateReceiverAttributes
} from "./constants.js";
import { nouns } from "./labels/labels.js";
import { globalThis, document } from "./utils/server-safe-globals.js";
import {
getBooleanAttr,
setBooleanAttr,
getOrInsertCSSRule
} from "./utils/element-utils.js";
const Attributes = {
LOADING_DELAY: "loadingdelay"
};
const DEFAULT_LOADING_DELAY = 500;
const template = document.createElement("template");
const loadingIndicatorIcon = `
`;
template.innerHTML = /*html*/
`
${loadingIndicatorIcon}
${nouns.MEDIA_LOADING()}
`;
class MediaLoadingIndicator extends globalThis.HTMLElement {
constructor() {
super();
__privateAdd(this, _mediaController, void 0);
__privateAdd(this, _delay, DEFAULT_LOADING_DELAY);
if (!this.shadowRoot) {
const shadow = this.attachShadow({ mode: "open" });
const indicatorHTML = template.content.cloneNode(true);
shadow.appendChild(indicatorHTML);
}
}
static get observedAttributes() {
return [
MediaStateReceiverAttributes.MEDIA_CONTROLLER,
MediaUIAttributes.MEDIA_PAUSED,
MediaUIAttributes.MEDIA_LOADING,
Attributes.LOADING_DELAY
];
}
attributeChangedCallback(attrName, oldValue, newValue) {
var _a, _b, _c, _d, _e;
if (attrName === Attributes.LOADING_DELAY && oldValue !== newValue) {
this.loadingDelay = Number(newValue);
} else if (attrName === MediaStateReceiverAttributes.MEDIA_CONTROLLER) {
if (oldValue) {
(_b = (_a = __privateGet(this, _mediaController)) == null ? void 0 : _a.unassociateElement) == null ? void 0 : _b.call(_a, this);
__privateSet(this, _mediaController, null);
}
if (newValue && this.isConnected) {
__privateSet(this, _mediaController, (_c = this.getRootNode()) == null ? void 0 : _c.getElementById(newValue));
(_e = (_d = __privateGet(this, _mediaController)) == null ? void 0 : _d.associateElement) == null ? void 0 : _e.call(_d, this);
}
}
}
connectedCallback() {
var _a, _b, _c;
const mediaControllerId = this.getAttribute(
MediaStateReceiverAttributes.MEDIA_CONTROLLER
);
if (mediaControllerId) {
__privateSet(this, _mediaController, (_a = this.getRootNode()) == null ? void 0 : _a.getElementById(
mediaControllerId
));
(_c = (_b = __privateGet(this, _mediaController)) == null ? void 0 : _b.associateElement) == null ? void 0 : _c.call(_b, this);
}
}
disconnectedCallback() {
var _a, _b;
(_b = (_a = __privateGet(this, _mediaController)) == null ? void 0 : _a.unassociateElement) == null ? void 0 : _b.call(_a, this);
__privateSet(this, _mediaController, null);
}
/**
* Delay in ms
*/
get loadingDelay() {
return __privateGet(this, _delay);
}
set loadingDelay(delay) {
__privateSet(this, _delay, delay);
const { style } = getOrInsertCSSRule(this.shadowRoot, ":host");
style.setProperty(
"--_loading-indicator-delay",
`var(--media-loading-indicator-transition-delay, ${delay}ms)`
);
}
/**
* Is the media paused
*/
get mediaPaused() {
return getBooleanAttr(this, MediaUIAttributes.MEDIA_PAUSED);
}
set mediaPaused(value) {
setBooleanAttr(this, MediaUIAttributes.MEDIA_PAUSED, value);
}
/**
* Is the media loading
*/
get mediaLoading() {
return getBooleanAttr(this, MediaUIAttributes.MEDIA_LOADING);
}
set mediaLoading(value) {
setBooleanAttr(this, MediaUIAttributes.MEDIA_LOADING, value);
}
}
_mediaController = new WeakMap();
_delay = new WeakMap();
if (!globalThis.customElements.get("media-loading-indicator")) {
globalThis.customElements.define(
"media-loading-indicator",
MediaLoadingIndicator
);
}
var media_loading_indicator_default = MediaLoadingIndicator;
export {
Attributes,
media_loading_indicator_default as default
};