@web-widget/web-widget
Version:
Web front-end application container
847 lines (837 loc) • 26.9 kB
JavaScript
import {
__privateAdd,
__privateGet,
__privateMethod,
__privateSet,
__spreadValues
} from "./chunk-EAUID5A7.js";
// src/element.ts
import { callSyncCacheProvider } from "@web-widget/lifecycle-cache/client";
// src/utils/idle.ts
var supportRequestIdleCallback = "requestIdleCallback" in window;
var createIdleObserver = (element, callback, options = {}) => {
let id;
if (supportRequestIdleCallback) {
id = requestIdleCallback(callback, options);
} else {
id = setTimeout(callback, 200);
}
const disconnect = () => {
if (supportRequestIdleCallback) {
cancelIdleCallback(id);
} else {
clearTimeout(id);
}
};
return disconnect;
};
// src/utils/lazy.ts
var placeholder = Symbol();
var isBox = (element) => ["contents", "none"].includes(getComputedStyle(element).display);
var createPlaceholderElement = () => Object.assign(document.createElement("span"), {
[placeholder]: true
});
var isPlaceholderElement = (element) => element[placeholder];
var createVisibleObserver = (element, callback, options = {}) => {
let observer = new IntersectionObserver(
(entries) => {
for (const { isIntersecting, target } of entries) {
if (!isIntersecting) {
continue;
}
disconnect();
if (isPlaceholderElement(target)) {
target.remove();
}
callback();
break;
}
},
__spreadValues({
rootMargin: "80%"
}, options)
);
const disconnect = () => {
if (observer) {
observer.disconnect();
observer = null;
}
};
if (isBox(element)) {
const children = Array.from(element.children).filter(
(node) => !isBox(node)
);
if (children.length) {
for (const child of children) {
observer.observe(child);
}
} else {
const placeholderElement = createPlaceholderElement();
element.firstChild ? element.insertBefore(placeholderElement, element.firstChild) : element.appendChild(placeholderElement);
observer.observe(placeholderElement);
}
} else {
observer.observe(element);
}
return disconnect;
};
// src/utils/module-preload.ts
function triggerModulePreload(href, { fetchPriority = "high", rel = "modulepreload" } = {}) {
const link = Array.from(
document.querySelectorAll(`link[rel="${rel}"]`)
).find((link2) => link2.href === href);
if (link) {
Object.assign(link, { fetchPriority });
} else {
document.head.appendChild(
Object.assign(document.createElement("link"), {
href,
rel,
fetchPriority
})
);
}
}
// src/utils/queue-microtask.ts
var promise;
var queueMicrotask = typeof window.queueMicrotask === "function" ? window.queueMicrotask.bind(window) : (callback) => (promise || (promise = Promise.resolve())).then(callback).catch(
(error) => setTimeout(() => {
throw error;
}, 0)
);
// src/utils/report-error.ts
var reportError = typeof window.reportError === "function" ? window.reportError.bind(window) : (error) => {
queueMicrotask(() => {
throw error;
});
};
// src/container.ts
var INITIAL = "initial";
var LOADING = "loading";
var LOADED = "loaded";
var BOOTSTRAPPING = "bootstrapping";
var BOOTSTRAPPED = "bootstrapped";
var MOUNTING = "mounting";
var MOUNTED = "mounted";
var UPDATING = "updating";
var UNMOUNTING = "unmounting";
var UNLOADING = "unloading";
var LOAD_ERROR = "load-error";
var BOOTSTRAP_ERROR = "bootstrap-error";
var MOUNT_ERROR = "mount-error";
var UPDATE_ERROR = "update-error";
var UNMOUNT_ERROR = "unmount-error";
var UNLOAD_ERROR = "unload-error";
var status = {
INITIAL,
LOADING,
LOADED,
BOOTSTRAPPING,
BOOTSTRAPPED,
MOUNTING,
MOUNTED,
UPDATING,
UNMOUNTING,
UNLOADING,
LOAD_ERROR,
BOOTSTRAP_ERROR,
MOUNT_ERROR,
UPDATE_ERROR,
UNMOUNT_ERROR,
UNLOAD_ERROR
};
var statusTransitions = {
[INITIAL]: [LOADING],
[LOADING]: [LOADED, LOAD_ERROR],
[LOADED]: [BOOTSTRAPPING, UNLOADING],
[BOOTSTRAPPING]: [BOOTSTRAPPED, BOOTSTRAP_ERROR],
[BOOTSTRAPPED]: [MOUNTING, UNLOADING],
[MOUNTING]: [MOUNTED, MOUNT_ERROR],
[MOUNTED]: [UPDATING, UNMOUNTING],
[UPDATING]: [MOUNTED, UPDATE_ERROR],
[UNMOUNTING]: [LOADED, UNMOUNT_ERROR],
[UNLOADING]: [INITIAL, UNLOAD_ERROR],
[LOAD_ERROR]: [LOADING],
[BOOTSTRAP_ERROR]: [BOOTSTRAPPING],
[MOUNT_ERROR]: [MOUNTING],
[UPDATE_ERROR]: [UPDATING],
[UNMOUNT_ERROR]: [UNMOUNTING],
[UNLOAD_ERROR]: [UNLOADING]
};
var _moduleLoader, _module, _data, _options, _lifecycle, _currentStatus, _statusListener, _timeouts, _ModuleContainer_instances, setStatus_fn, canTransitionTo_fn, safeExecute_fn, transition_fn;
var ModuleContainer = class {
constructor(moduleLoader, data, options) {
__privateAdd(this, _ModuleContainer_instances);
__privateAdd(this, _moduleLoader);
__privateAdd(this, _module, null);
__privateAdd(this, _data);
__privateAdd(this, _options);
__privateAdd(this, _lifecycle, {});
__privateAdd(this, _currentStatus, INITIAL);
__privateAdd(this, _statusListener, null);
__privateAdd(this, _timeouts, null);
__privateSet(this, _moduleLoader, moduleLoader);
__privateSet(this, _data, data);
__privateSet(this, _options, options);
}
get status() {
return __privateGet(this, _currentStatus);
}
set onStatusChange(listener) {
__privateSet(this, _statusListener, listener);
}
set timeouts(timeouts) {
__privateSet(this, _timeouts, timeouts);
}
/** Loads the widget module. */
async load() {
await __privateMethod(this, _ModuleContainer_instances, transition_fn).call(this, "load", LOADING, LOAD_ERROR, async () => {
var _a, _b;
const mod = await withTimeout(
__privateGet(this, _moduleLoader).call(this),
(_b = (_a = __privateGet(this, _timeouts)) == null ? void 0 : _a.load) != null ? _b : 0
);
if (!(mod == null ? void 0 : mod.render) || typeof mod.render !== "function") {
throw new Error("Invalid module: missing render() function.");
}
__privateSet(this, _module, mod);
});
__privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, LOADED);
}
/** Bootstraps the widget module. */
async bootstrap() {
await __privateMethod(this, _ModuleContainer_instances, transition_fn).call(this, "bootstrap", BOOTSTRAPPING, BOOTSTRAP_ERROR, async () => {
const renderResult = await __privateGet(this, _module).render(
__privateGet(this, _module).default,
__privateGet(this, _data),
__privateGet(this, _options)
);
__privateSet(this, _lifecycle, renderResult || {});
await __privateMethod(this, _ModuleContainer_instances, safeExecute_fn).call(this, "bootstrap", __privateGet(this, _lifecycle).bootstrap, BOOTSTRAP_ERROR);
});
__privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, BOOTSTRAPPED);
}
/** Mounts the widget module. */
async mount() {
await __privateMethod(this, _ModuleContainer_instances, transition_fn).call(this, "mount", MOUNTING, MOUNT_ERROR, __privateGet(this, _lifecycle).mount);
__privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, MOUNTED);
}
/** Updates the widget module with new data. */
async update(data) {
__privateSet(this, _data, data);
await __privateMethod(this, _ModuleContainer_instances, transition_fn).call(this, "update", UPDATING, UPDATE_ERROR, () => {
var _a, _b;
return (_b = (_a = __privateGet(this, _lifecycle)).update) == null ? void 0 : _b.call(_a, data);
});
__privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, MOUNTED);
}
/** Unmounts the widget module. */
async unmount() {
await __privateMethod(this, _ModuleContainer_instances, transition_fn).call(this, "unmount", UNMOUNTING, UNMOUNT_ERROR, __privateGet(this, _lifecycle).unmount);
__privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, BOOTSTRAPPED);
}
/** Unloads the widget module. */
async unload() {
await __privateMethod(this, _ModuleContainer_instances, transition_fn).call(this, "unload", UNLOADING, UNLOAD_ERROR, __privateGet(this, _lifecycle).unload);
__privateSet(this, _module, null);
__privateSet(this, _lifecycle, {});
__privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, INITIAL);
}
/**
* Retry the last failed operation based on the current error
* Throws an error if the current status is not an error state.
*/
// async retry() {
// switch (this.#currentStatus) {
// case LOAD_ERROR:
// await this.load();
// break;
// case BOOTSTRAP_ERROR:
// await this.bootstrap();
// break;
// case MOUNT_ERROR:
// await this.mount();
// break;
// case UPDATE_ERROR:
// await this.update(this.#data);
// break;
// case UNMOUNT_ERROR:
// await this.unmount();
// break;
// case UNLOAD_ERROR:
// await this.unload();
// break;
// default:
// throw new Error(
// `Cannot retry operation from the current status: "${this.#currentStatus}".`
// );
// }
// }
};
_moduleLoader = new WeakMap();
_module = new WeakMap();
_data = new WeakMap();
_options = new WeakMap();
_lifecycle = new WeakMap();
_currentStatus = new WeakMap();
_statusListener = new WeakMap();
_timeouts = new WeakMap();
_ModuleContainer_instances = new WeakSet();
setStatus_fn = function(next) {
var _a;
const prev = __privateGet(this, _currentStatus);
__privateSet(this, _currentStatus, next);
(_a = __privateGet(this, _statusListener)) == null ? void 0 : _a.call(this, next, prev);
};
canTransitionTo_fn = function(next) {
return statusTransitions[__privateGet(this, _currentStatus)].includes(next);
};
safeExecute_fn = async function(action, fn, errorStatus) {
var _a, _b;
if (!fn) return;
const timeout = (_b = (_a = __privateGet(this, _timeouts)) == null ? void 0 : _a[action]) != null ? _b : 0;
try {
await withTimeout(Promise.resolve(fn()), timeout);
} catch (err) {
if (errorStatus) __privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, errorStatus);
throw err;
}
};
transition_fn = async function(action, next, errorStatus, fn) {
if (!__privateMethod(this, _ModuleContainer_instances, canTransitionTo_fn).call(this, next)) {
throw new Error(
`Cannot perform "${action}" from "${__privateGet(this, _currentStatus)}" to "${next}".`
);
}
__privateMethod(this, _ModuleContainer_instances, setStatus_fn).call(this, next);
try {
await __privateMethod(this, _ModuleContainer_instances, safeExecute_fn).call(this, action, fn, errorStatus);
} catch (err) {
throw err;
}
};
function withTimeout(promise2, timeoutMs) {
if (!timeoutMs || timeoutMs <= 0) return promise2;
return Promise.race([
promise2,
new Promise(
(_, reject) => setTimeout(() => reject(new Error("Operation timed out.")), timeoutMs)
)
]);
}
// src/error.ts
var WebWidgetError = class extends Error {
constructor(moduleName, message, cause) {
super(`WebWidgetError: ${moduleName}: ${message}`, { cause });
this.name = "WebWidgetError";
}
};
// src/element.ts
var globalTimeouts = /* @__PURE__ */ Object.create(null);
var innerHTMLDescriptor = Object.getOwnPropertyDescriptor(
Element.prototype,
"innerHTML"
);
var innerHTMLSetter = innerHTMLDescriptor.set;
var INNER_HTML_PLACEHOLDER = `<!--web-widget:placeholder-->`;
var _loader, _moduleContainer, _data2, _disconnectObserver, _meta, _isFirstConnect, _timeouts2, _status, _internals, _autoMountPromise, _HTMLWebWidgetElement_instances, autoMount_fn, firstConnectedCallback_fn, call_fn, createModuleContainer_fn, statusChangeCallback_fn, updateStatus_fn, markPerformance_fn, dispatchStatusChangeEvent_fn, name_get, throwGlobalError_fn;
var _HTMLWebWidgetElement = class _HTMLWebWidgetElement extends HTMLElement {
constructor() {
super();
__privateAdd(this, _HTMLWebWidgetElement_instances);
__privateAdd(this, _loader, null);
__privateAdd(this, _moduleContainer, null);
__privateAdd(this, _data2, null);
__privateAdd(this, _disconnectObserver);
__privateAdd(this, _meta, null);
__privateAdd(this, _isFirstConnect, false);
__privateAdd(this, _timeouts2, null);
__privateAdd(this, _status, status.INITIAL);
__privateAdd(this, _internals);
__privateAdd(this, _autoMountPromise, null);
if (this.attachInternals) {
__privateSet(this, _internals, this.attachInternals());
}
}
/**
* WidgetModule loader.
* @default null
*/
get loader() {
return __privateGet(this, _loader) || null;
}
set loader(value) {
if (typeof value === "function") {
__privateSet(this, _loader, value);
if (this.loading === "eager") {
__privateMethod(this, _HTMLWebWidgetElement_instances, autoMount_fn).call(this);
}
}
}
/**
* WidgetModule base.
*/
get base() {
const value = this.getAttribute("base");
return value === null ? this.baseURI : new URL(value, this.baseURI).href;
}
set base(value) {
this.setAttribute("base", value);
}
/**
* WidgetModule data.
* @deprecated Use `contextData` instead.
*/
get data() {
console.warn("`data` is deprecated. Use `contextData` instead.");
return this.contextData;
}
set data(value) {
if (typeof value === "object") {
this.setAttribute("data", JSON.stringify(value));
}
}
/**
* WidgetModule data.
*/
get contextData() {
var _a;
if (!__privateGet(this, _data2)) {
const dataAttr = (_a = this.getAttribute("contextdata")) != null ? _a : (
// @deprecated
this.getAttribute("data")
);
if (dataAttr) {
try {
const parsedData = JSON.parse(dataAttr);
if (parsedData !== null) {
__privateSet(this, _data2, parsedData);
} else {
throw new Error("Invalid contextData format");
}
} catch (error) {
__privateMethod(this, _HTMLWebWidgetElement_instances, throwGlobalError_fn).call(this, error);
__privateSet(this, _data2, {});
}
} else if (Object.entries(this.dataset).length) {
__privateSet(this, _data2, __spreadValues({}, this.dataset));
}
}
return __privateGet(this, _data2);
}
set contextData(value) {
if (typeof value === "object") {
__privateSet(this, _data2, value);
}
}
/**
* WidgetModule meta.
*/
get contextMeta() {
if (!__privateGet(this, _meta)) {
const dataAttr = this.getAttribute("contextmeta");
if (dataAttr) {
try {
__privateSet(this, _meta, JSON.parse(dataAttr));
} catch (error) {
__privateMethod(this, _HTMLWebWidgetElement_instances, throwGlobalError_fn).call(this, error);
__privateSet(this, _meta, {});
}
}
}
return __privateGet(this, _meta);
}
set contextMeta(value) {
if (typeof value === "object") {
this.setAttribute("contextmeta", JSON.stringify(value));
}
}
/**
* Whether the module is inactive.
*/
get inactive() {
return this.hasAttribute("inactive");
}
set inactive(value) {
if (value) {
this.setAttribute("inactive", "");
} else {
this.removeAttribute("inactive");
}
}
/**
* Hydration mode.
* @default false
*/
get recovering() {
return this.hasAttribute("recovering");
}
set recovering(value) {
if (value) {
this.setAttribute("recovering", "");
} else {
this.removeAttribute("recovering");
}
}
/**
* Indicates how the browser should load the module.
* @default "eager"
*/
get loading() {
return this.getAttribute("loading") || "eager";
}
set loading(value) {
this.setAttribute("loading", value);
}
/**
* WidgetModule container status.
* @default "initial"
*/
get status() {
return __privateGet(this, _status);
}
/**
* WidgetModule module url.
* @default ""
*/
get import() {
let value = this.getAttribute("import");
const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/;
if (value && !bareImportRE.test(value)) {
value = new URL(value, this.base).href;
}
return value === null ? "" : value;
}
set import(value) {
this.setAttribute("import", value);
}
/**
* WidgetModule render target.
* @default "shadow"
*/
get renderTarget() {
return this.getAttribute("rendertarget") || "shadow";
}
set renderTarget(value) {
this.setAttribute("rendertarget", value);
}
/**
* WidgetModule timeouts.
*/
get timeouts() {
if (!__privateGet(this, _timeouts2)) {
__privateSet(this, _timeouts2, __spreadValues({}, _HTMLWebWidgetElement.timeouts));
}
return __privateGet(this, _timeouts2);
}
set timeouts(value) {
__privateSet(this, _timeouts2, value || null);
}
// NOTE: This is a temporary solution for React.
// NOTE: Prevent React components from clearing innerHTML when re-rendering on the client side.
set innerHTML(value) {
if (value === INNER_HTML_PLACEHOLDER) {
return;
} else {
innerHTMLSetter.call(this, value);
}
}
/**
* Hook: Create the module's render node.
*/
createContainer() {
var _a, _b;
let container = null;
if (this.renderTarget === "shadow") {
if (this.recovering) {
container = (_b = (_a = __privateGet(this, _internals)) == null ? void 0 : _a.shadowRoot) != null ? _b : null;
}
if (!container) {
container = this.attachShadow({ mode: "open" });
}
} else if (this.renderTarget === "light") {
container = this;
}
return container;
}
/**
* Hook: Create the module's loader.
*/
createLoader() {
const supportsImportMaps = HTMLScriptElement.supports && HTMLScriptElement.supports("importmap");
function importModule(target) {
if (!supportsImportMaps && typeof importShim === "function") {
return importShim(target);
}
return import(
/* @vite-ignore */
/* webpackIgnore: true */
target
);
}
return () => importModule(this.import);
}
/**
* Trigger the loading of the module.
*/
async load() {
await __privateMethod(this, _HTMLWebWidgetElement_instances, call_fn).call(this, "load");
}
/**
* Trigger the bootstrapping of the module.
*/
async bootstrap() {
await __privateMethod(this, _HTMLWebWidgetElement_instances, call_fn).call(this, "bootstrap");
}
/**
* Trigger the mounting of the module.
*/
async mount() {
await callSyncCacheProvider(() => __privateMethod(this, _HTMLWebWidgetElement_instances, call_fn).call(this, "mount"));
}
/**
* Trigger the updating of the module.
*/
async update(data) {
await __privateMethod(this, _HTMLWebWidgetElement_instances, call_fn).call(this, "update", data);
}
/**
* Trigger the unmounting of the module.
*/
async unmount() {
await __privateMethod(this, _HTMLWebWidgetElement_instances, call_fn).call(this, "unmount");
}
/**
* Trigger the unloading of the module.
*/
async unload() {
await __privateMethod(this, _HTMLWebWidgetElement_instances, call_fn).call(this, "unload");
}
connectedCallback() {
if (!__privateGet(this, _isFirstConnect)) {
__privateMethod(this, _HTMLWebWidgetElement_instances, firstConnectedCallback_fn).call(this);
__privateSet(this, _isFirstConnect, true);
}
}
disconnectedCallback() {
queueMicrotask(() => {
if (!this.isConnected) {
this.destroyedCallback();
}
});
}
attributeChangedCallback(name) {
const cacheClearingAttributes = ["contextdata", "data", "contextmeta"];
if (cacheClearingAttributes.includes(name)) {
__privateSet(this, _data2, null);
__privateSet(this, _meta, null);
}
if (this.loading === "eager") {
__privateMethod(this, _HTMLWebWidgetElement_instances, autoMount_fn).call(this);
}
}
destroyedCallback() {
if (__privateGet(this, _disconnectObserver)) {
__privateGet(this, _disconnectObserver).call(this);
}
if (!this.inactive) {
this.unmount().then(() => this.unload()).catch((error) => __privateMethod(this, _HTMLWebWidgetElement_instances, throwGlobalError_fn).call(this, error));
}
}
static get observedAttributes() {
return [
"data",
// @deprecated
"contextdata",
"inactive",
"loading",
"import",
"meta",
// @deprecated
"contextmeta"
];
}
static get timeouts() {
return globalTimeouts;
}
static set timeouts(value) {
globalTimeouts = value;
}
};
_loader = new WeakMap();
_moduleContainer = new WeakMap();
_data2 = new WeakMap();
_disconnectObserver = new WeakMap();
_meta = new WeakMap();
_isFirstConnect = new WeakMap();
_timeouts2 = new WeakMap();
_status = new WeakMap();
_internals = new WeakMap();
_autoMountPromise = new WeakMap();
_HTMLWebWidgetElement_instances = new WeakSet();
autoMount_fn = function() {
if (__privateGet(this, _autoMountPromise)) return;
if (!this.isConnected || this.inactive || !(this.import || this.loader)) {
return;
}
const canAutoMount = this.status === status.INITIAL || this.status === status.LOAD_ERROR;
if (!canAutoMount) {
return;
}
__privateSet(this, _autoMountPromise, Promise.resolve().then(async () => {
try {
await this.load();
await this.bootstrap();
await this.mount();
} catch (error) {
__privateMethod(this, _HTMLWebWidgetElement_instances, throwGlobalError_fn).call(this, error);
} finally {
__privateSet(this, _autoMountPromise, null);
}
}));
};
firstConnectedCallback_fn = function() {
var _a;
const preload = () => this.import && triggerModulePreload(this.import);
const options = { once: true, passive: true };
["mousemove", "touchstart"].forEach(
(type) => this.addEventListener(type, preload, options)
);
const loadingStrategies = {
eager: () => __privateMethod(this, _HTMLWebWidgetElement_instances, autoMount_fn).call(this),
lazy: () => __privateSet(this, _disconnectObserver, createVisibleObserver(
this,
() => __privateMethod(this, _HTMLWebWidgetElement_instances, autoMount_fn).call(this)
)),
idle: () => __privateSet(this, _disconnectObserver, createIdleObserver(
this,
() => __privateMethod(this, _HTMLWebWidgetElement_instances, autoMount_fn).call(this)
))
};
(_a = loadingStrategies[this.loading]) == null ? void 0 : _a.call(loadingStrategies);
};
call_fn = async function(lifecycle, data) {
if (!__privateGet(this, _moduleContainer)) {
__privateSet(this, _moduleContainer, __privateMethod(this, _HTMLWebWidgetElement_instances, createModuleContainer_fn).call(this));
}
return __privateGet(this, _moduleContainer)[lifecycle](data);
};
createModuleContainer_fn = function() {
const view = this;
let container;
const { recovering, contextData } = this;
const moduleContainer = new ModuleContainer(
() => {
if (!this.loader) {
this.loader = this.createLoader();
}
return this.loader();
},
contextData,
{
get container() {
if (!container) {
container = view.createContainer();
}
return container;
},
get recovering() {
return recovering;
}
}
);
moduleContainer.timeouts = __privateGet(this, _timeouts2);
moduleContainer.onStatusChange = (status2) => {
__privateMethod(this, _HTMLWebWidgetElement_instances, statusChangeCallback_fn).call(this, status2);
};
return moduleContainer;
};
statusChangeCallback_fn = function(value) {
__privateMethod(this, _HTMLWebWidgetElement_instances, updateStatus_fn).call(this, value);
__privateMethod(this, _HTMLWebWidgetElement_instances, markPerformance_fn).call(this, value);
__privateMethod(this, _HTMLWebWidgetElement_instances, dispatchStatusChangeEvent_fn).call(this);
};
updateStatus_fn = function(value) {
var _a;
__privateSet(this, _status, value);
if ((_a = __privateGet(this, _internals)) == null ? void 0 : _a.states) {
try {
__privateGet(this, _internals).states.clear();
__privateGet(this, _internals).states.add(value);
} catch (error) {
this.setAttribute("status", value);
}
} else {
this.setAttribute("status", value);
}
if (value === status.MOUNTED) {
this.removeAttribute("recovering");
}
};
markPerformance_fn = function(value) {
try {
const componentName = __privateGet(this, _HTMLWebWidgetElement_instances, name_get);
const markNameSpace = `${componentName}:statusChange`;
const detail = {
name: componentName,
import: this.import,
source: this.localName,
timestamp: Date.now()
};
performance.mark(`${markNameSpace}:${value}`, { detail });
switch (value) {
case status.LOADED:
const loadMeasure = performance.measure(`${componentName}:load`, {
start: `${markNameSpace}:${status.LOADING}`,
end: `${markNameSpace}:${status.LOADED}`,
detail
});
if (!this.performance) {
this.performance = {};
}
this.performance.loadTime = `${Math.round(loadMeasure.duration)}ms`;
break;
case status.MOUNTED:
const mountMeasure = performance.measure(`${componentName}:mount`, {
start: `${markNameSpace}:${status.MOUNTING}`,
end: `${markNameSpace}:${status.MOUNTED}`,
detail
});
if (!this.performance) {
this.performance = {};
}
this.performance.mountTime = `${Math.round(mountMeasure.duration)}ms`;
break;
}
} catch (e) {
}
};
dispatchStatusChangeEvent_fn = function() {
this.dispatchEvent(new Event("statuschange"));
};
name_get = function() {
const attr = this.id ? ["id", this.id] : this.getAttribute("name") ? ["name", this.getAttribute("name")] : this.import ? ["import", this.import] : null;
return attr ? `${this.localName}[${attr[0]}=${JSON.stringify(attr[1])}]` : this.localName;
};
throwGlobalError_fn = function(error) {
const moduleName = __privateGet(this, _HTMLWebWidgetElement_instances, name_get);
let err;
if (error instanceof WebWidgetError) {
err = error;
} else if (error instanceof Error) {
err = new WebWidgetError(moduleName, error.message, error);
} else if (typeof error === "string") {
err = new WebWidgetError(moduleName, error);
} else {
err = new WebWidgetError(moduleName, "Unknown error", error);
}
reportError(err);
};
var HTMLWebWidgetElement = _HTMLWebWidgetElement;
Object.assign(HTMLWebWidgetElement, status);
export {
queueMicrotask,
INNER_HTML_PLACEHOLDER,
HTMLWebWidgetElement
};
//# sourceMappingURL=chunk-TIHYKKQL.js.map