UNPKG

@synergy-design-system/components

Version:

This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define

42 lines (40 loc) 1.52 kB
import { getBasePath } from "./chunks/chunk.234ERFCE.js"; import "./chunks/chunk.Z4XV3SMG.js"; // src/synergy-autoloader.ts var observer = new MutationObserver((mutations) => { for (const { addedNodes } of mutations) { for (const node of addedNodes) { if (node.nodeType === Node.ELEMENT_NODE) { discover(node); } } } }); async function discover(root) { const rootTagName = root instanceof Element ? root.tagName.toLowerCase() : ""; const rootIsSynergyElement = rootTagName == null ? void 0 : rootTagName.startsWith("syn-"); const tags = [...root.querySelectorAll(":not(:defined)")].map((el) => el.tagName.toLowerCase()).filter((tag) => tag.startsWith("syn-")); if (rootIsSynergyElement && !customElements.get(rootTagName)) { tags.push(rootTagName); } const tagsToRegister = [...new Set(tags)]; await Promise.allSettled(tagsToRegister.map((tagName) => register(tagName))); } function register(tagName) { if (customElements.get(tagName)) { return Promise.resolve(); } const tagWithoutPrefix = tagName.replace(/^syn-/i, ""); const path = getBasePath(`components/${tagWithoutPrefix}/${tagWithoutPrefix}.js`); return new Promise((resolve, reject) => { import(path).then(() => resolve()).catch(() => reject(new Error(`Unable to autoload <${tagName}> from ${path}`))); }); } discover(document.body); observer.observe(document.documentElement, { subtree: true, childList: true }); export { discover }; //# sourceMappingURL=synergy-autoloader.js.map