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

148 lines (145 loc) 4.58 kB
import { INITIAL_DEFAULT_SETTINGS, defaultSettings } from "./chunk.6QJYD7WX.js"; // src/utilities/defaultSettings/functions.ts var SYNERGY_EXPERIMENTAL_SETTING_EMIT_EVENTS = false; var hasGlobalEventSetup = false; var elementPropertyCache = /* @__PURE__ */ new Map(); var globalEventNotificationMap = /* @__PURE__ */ new Set(); function defaultSettingsHandler(e) { const { detail } = e; Object.entries(detail).forEach(([componentName, changes]) => { globalEventNotificationMap.forEach((element) => { if (element.__originalDecoratedClassName !== "undefined" && element.__originalDecoratedClassName === componentName) { element.overrideGlobalSettings(changes); } }); }); } var enableExperimentalSettingEmitEvents = (enabled = true) => { SYNERGY_EXPERIMENTAL_SETTING_EMIT_EVENTS = enabled; if (!enabled) { globalEventNotificationMap.clear(); hasGlobalEventSetup = false; window.removeEventListener("syn-default-settings-changed", defaultSettingsHandler, { capture: true }); return; } if (enabled && !hasGlobalEventSetup) { hasGlobalEventSetup = true; window.addEventListener("syn-default-settings-changed", defaultSettingsHandler, { capture: true }); } }; var addGlobalEventNotification = (element) => { if (SYNERGY_EXPERIMENTAL_SETTING_EMIT_EVENTS && !globalEventNotificationMap.has(element)) { globalEventNotificationMap.add(element); } }; var removeGlobalEventNotification = (element) => { if (globalEventNotificationMap.has(element)) { globalEventNotificationMap.delete(element); } }; var extractDefaultSettingsForElement = (component, from = "default") => { const store = from === "default" ? defaultSettings : INITIAL_DEFAULT_SETTINGS; if (from === "default") { const cachedSettings = elementPropertyCache.get(component); if (typeof cachedSettings !== "undefined") { return cachedSettings; } } const allElementSettings = Object.entries(store).reduce( (acc, [key, value]) => { const elementSetting = value[component]; if (elementSetting) { acc[key] = elementSetting; } return acc; }, {} ); if (from === "default") { elementPropertyCache.set(component, allElementSettings); } return allElementSettings; }; var setDefaultSettingsForElement = (component, newValues) => { const detail = { [component]: [] }; Object.entries(newValues).forEach(([key, value]) => { if (defaultSettings[key] && typeof defaultSettings[key][component] !== "undefined") { detail[component].push({ attribute: key, newValue: value, oldValue: defaultSettings[key][component] }); defaultSettings[key][component] = value; } }); const cachedItem = elementPropertyCache.get(component); if (typeof cachedItem !== "undefined") { detail[component].forEach((change) => { cachedItem[change.attribute] = change.newValue; }); } if (SYNERGY_EXPERIMENTAL_SETTING_EMIT_EVENTS) { const event = new CustomEvent("syn-default-settings-changed", { bubbles: true, detail }); dispatchEvent(event); } return defaultSettings; }; var setGlobalDefaultSettings = (newSettings) => { const detail = {}; Object.entries(newSettings).forEach(([key, value]) => { if (defaultSettings[key]) { Object.entries(value).forEach(([component, newValue]) => { if (!detail[component]) { detail[component] = []; } detail[component].push({ attribute: key, newValue, oldValue: defaultSettings[key][component] }); defaultSettings[key][component] = newValue; }); } }); Object.entries(detail).forEach(([component, changes]) => { const cachedItem = elementPropertyCache.get(component); if (typeof cachedItem !== "undefined") { changes.forEach((change) => { cachedItem[change.attribute] = change.newValue; }); } }); if (SYNERGY_EXPERIMENTAL_SETTING_EMIT_EVENTS) { const event = new CustomEvent("syn-default-settings-changed", { bubbles: true, detail }); dispatchEvent(event); } return defaultSettings; }; var resetGlobalDefaultSettings = () => setGlobalDefaultSettings( INITIAL_DEFAULT_SETTINGS ); export { enableExperimentalSettingEmitEvents, addGlobalEventNotification, removeGlobalEventNotification, extractDefaultSettingsForElement, setDefaultSettingsForElement, setGlobalDefaultSettings, resetGlobalDefaultSettings }; //# sourceMappingURL=chunk.HC4N72MX.js.map