{"version":3,"sources":["node_modules/@sydle/ui-utils/dist/index.mjs","src/global/setup.ts"],"names":["getConfig","packageIdentifier","window","sydleApp","config","setGlobalTokens","sydleUiConfig","primaryColor","accentColor","secondaryColor","globalCSSTokens","customTokens","style","--sy-primary","variants","ColorHelper","getColorVariations","forEach","variant","[object Object]","name","value","--sy-accent","element","token","styleElement","document","createElement","innerHTML","JSON","stringify","replace","head","appendChild"],"mappings":"oCAGA,SAASA,EAAUC,GACjB,IAAKC,OAAOC,UAAUC,SAASH,GAAoB,CACjD,OAAO,KAET,OAAOC,OAAOC,UAAUC,SAASH,GCAnC,SAAAI,IACE,MAAMC,EAAgBN,EAAA,YAEtB,IAAKM,EAAe,CAClB,OAGF,MAAAC,EAAAD,EAAAC,aACA,MAAMC,EAAcF,EAAcG,eAClC,MAAMC,EAAkBJ,EAAcK,aAEtC,IAAIC,EAAmC,GAEvC,GAAIL,EAAA,CACFK,EAAQ,IAAKA,EAAAC,eAAAN,GACb,MAAMO,EAAWC,EAAYC,mBAAmBT,GAChDO,EAASG,SAASC,IAChBN,EAAQ,IAAKA,EAAOO,CAAC,gBAAAD,EAAAE,QAAAF,EAAAG,UAIzB,GAAAb,EAAA,CACEI,EAAQ,IAAKA,EAAAU,cAAAd,GACb,MAAMM,EAAWC,EAAYC,mBAAmBR,GAChDM,EAASG,SAASC,IAChBN,EAAQ,IAAKA,EAAOO,CAAC,eAAAD,EAAAE,QAAAF,EAAAG,UAIzBX,GAAAO,SAAAM,IACEX,EAAQ,IAAKA,EAAOO,CAACI,EAAQC,OAAQD,EAAAF,UAGvC,MAAAI,EAAAC,SAAAC,cAAA,SACAF,EAAaG,UAAY,QAAQC,KAAKC,UAAUlB,IAAKmB,QAAA,KAAA,IAAAA,QAAA,KAAA,OACrDL,SAASM,KAAKC,YAAYR,GAG5BpB","sourcesContent":["import { h } from '@stencil/core';\n\n// src/lib/app-utils.ts\nfunction getConfig(packageIdentifier) {\n if (!window.sydleApp?.config?.[packageIdentifier]) {\n return null;\n }\n return window.sydleApp?.config?.[packageIdentifier];\n}\nfunction createTranslator(bundleIdentifier) {\n return (key, defaultValue, language) => {\n const bundle = window?.sydleApp?.translationBundles?.[bundleIdentifier];\n const currentLanguage = language ?? window.sydleApp?.api?.[\"userAPI\"]?.getCurrentLanguage();\n if (!currentLanguage || !bundle) {\n return defaultValue;\n }\n return bundle?.[key]?.[currentLanguage] ?? defaultValue;\n };\n}\n\n// src/lib/context-utils.ts\nfunction createConsumer(element, contextKey, timeout = 4e3) {\n const targetElement = element;\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n console.error(`Provider not found: '${contextKey}'`);\n reject();\n }, timeout);\n targetElement?.dispatchEvent(\n new CustomEvent(\"syContextConsumerDidSubscribe\", {\n bubbles: true,\n composed: true,\n detail: {\n context: contextKey,\n el: targetElement,\n changeValue: (newValue) => {\n targetElement[contextKey] = newValue;\n clearTimeout(timeoutId);\n resolve?.(newValue);\n }\n }\n })\n );\n });\n}\nfunction createProvider(element, contextKey, value) {\n const targetElement = element;\n targetElement.__provides = targetElement.__provides ?? {};\n const oldProvider = targetElement.__provides[contextKey];\n targetElement.__provides[contextKey] = {\n value,\n consumers: oldProvider ? oldProvider.consumers : /* @__PURE__ */ new Set()\n };\n oldProvider?.consumers?.forEach((consumer) => {\n consumer.changeValue(value);\n });\n if (targetElement.__wrapped)\n return;\n targetElement.__wrapped = true;\n const subscribeConsumerEventListener = (event) => {\n const { context, changeValue, el } = event.detail;\n if (!targetElement.__provides) {\n return;\n }\n if (!(context in targetElement.__provides)) {\n return;\n }\n const consumer = { el, changeValue };\n const currentProvider = targetElement.__provides[context];\n if (currentProvider) {\n currentProvider.consumers.add(consumer);\n consumer.changeValue(currentProvider.value);\n const previousDisconnectConsumer = consumer.el.disconnectConsumer;\n el.disconnectConsumer = () => {\n previousDisconnectConsumer?.();\n currentProvider.consumers.delete(consumer);\n };\n event.stopPropagation();\n }\n };\n targetElement.updateProvider = (contextKey2, value2) => {\n if (!targetElement.__provides) {\n return;\n }\n const currentProvider = targetElement.__provides[contextKey2];\n if (!currentProvider) {\n console.warn(\"Provider not found. Use CreateProvider before.\");\n return;\n }\n currentProvider.value = value2;\n currentProvider.consumers?.forEach((el) => {\n el.changeValue(value2);\n });\n };\n targetElement.disconnectProvider = () => {\n targetElement.__provides = void 0;\n targetElement.__wrapped = void 0;\n targetElement.updateProvider = void 0;\n targetElement.removeEventListener(\"syContextConsumerDidSubscribe\", subscribeConsumerEventListener);\n targetElement.disconnectProvider = void 0;\n };\n targetElement.addEventListener(\"syContextConsumerDidSubscribe\", subscribeConsumerEventListener);\n}\n\n// src/lib/debounce-decorator.ts\nvar Debounce = (duration, keyFn) => {\n return (_target, key, descriptor) => {\n const originalMethod = descriptor.value;\n if (keyFn && keyFn.length > originalMethod.length) {\n console.error(`Debounce decorator keyFn argument list must match the decorated function (${key}). `);\n }\n descriptor.value = function(...args) {\n this.__debounce = this.__debounce ?? {};\n const debounceKey = keyFn ? `${key}.${keyFn(...args)}` : key;\n clearTimeout(this.__debounce[debounceKey]);\n this.__debounce[debounceKey] = setTimeout(() => {\n originalMethod.call(this, ...args);\n }, duration);\n };\n };\n};\n\n// src/lib/throttle-decorator.ts\nfunction Throttle(delay) {\n return function(_target, key, descriptor) {\n const originalMethod = descriptor.value;\n descriptor.value = function(...args) {\n this.__shouldWait = this.__shouldWait ?? {};\n this.__waitingArgs = this.__waitingArgs ?? {};\n const setTimeoutFn = () => {\n if (this.__waitingArgs?.[key]) {\n originalMethod.call(this, ...this.__waitingArgs[key]);\n this.__waitingArgs[key] = null;\n setTimeout(setTimeoutFn, delay);\n } else {\n if (!this.__shouldWait) {\n this.__shouldWait = {};\n }\n this.__shouldWait[key] = false;\n }\n };\n if (this.__shouldWait[key]) {\n this.__waitingArgs[key] = args;\n return;\n }\n this.__shouldWait[key] = true;\n originalMethod.call(this, ...args);\n setTimeout(setTimeoutFn, delay);\n };\n };\n}\nfunction renderComponent(componentContent) {\n return h(componentContent.tag, componentContent.node, parseChildren(componentContent.children));\n}\nfunction parseChildren(children) {\n if (children.length < 1) {\n return [null];\n }\n return children.map((child) => {\n if (typeof child === \"string\") {\n return child;\n }\n return h(child.tag, child.node, parseChildren(child.children));\n });\n}\nfunction reloadPageContent(element) {\n const reloadEvent = new CustomEvent(\"syAppCustomPageReloadElements\", { bubbles: true });\n if (element) {\n return element.dispatchEvent(reloadEvent);\n }\n return document.body.dispatchEvent(reloadEvent);\n}\n\n// src/lib/router-utils.ts\nfunction getRouteByIdentifier(identifier) {\n return getConfig(\"ui-app\")?.routes.find((route) => route.name === identifier);\n}\nfunction getRouteById(id, routes) {\n routes = routes ?? getConfig(\"ui-app\")?.routes;\n for (const route of routes || []) {\n if (route._id === id) {\n return route;\n }\n if (route.children) {\n const foundRoute = getRouteById(id, route.children);\n if (foundRoute) {\n return foundRoute;\n }\n }\n }\n return null;\n}\nvar getAbsoluteUrl = function() {\n let a;\n return function(url = \"\") {\n if (!a)\n a = document.createElement(\"a\");\n a.href = url;\n return a.href;\n };\n}();\nfunction getRouter() {\n if (!window.sydleApp?.router?.instance) {\n return null;\n }\n return window.sydleApp.router.instance;\n}\nfunction getAction(routeIdentifier) {\n if (!routeIdentifier || !window?.sydleApp?.router?.actions) {\n return null;\n }\n return window.sydleApp.router.actions[routeIdentifier] ?? null;\n}\nfunction setAction(routeIdentifier, actionFunction) {\n if (!window.sydleApp) {\n window.sydleApp = {};\n }\n if (!window.sydleApp?.router) {\n window.sydleApp.router = {};\n }\n if (!window.sydleApp.router.actions) {\n window.sydleApp.router.actions = {};\n }\n let previousAction;\n if (window.sydleApp.router.actions[routeIdentifier]) {\n previousAction = window.sydleApp.router.actions[routeIdentifier];\n }\n window.sydleApp.router.actions[routeIdentifier] = async (context, commands) => {\n const previousActionReturnValue = await previousAction?.(context, commands);\n if (previousActionReturnValue) {\n return previousActionReturnValue;\n }\n return actionFunction(context, commands);\n };\n}\nfunction setActionAll(actionFunction, options) {\n const routes = getConfig(\"ui-app\")?.routes?.map((route) => route.name)?.filter((route) => route && !options?.except?.includes(route));\n routes?.forEach((route) => route && setAction(route, actionFunction));\n}\nfunction urlFor(name, params, router = getRouter()) {\n let path;\n try {\n path = router?.urlForName(name, params) ?? \"\";\n } catch (error) {\n console.error(error);\n path = router?.urlForName(\"home\") ?? \"\";\n }\n return removeBaseUrl(path);\n}\nfunction navigate(name, params, router = getRouter()) {\n const path = urlFor(name, params, router);\n return navigateToPath(path);\n}\nfunction navigateToPath(path) {\n window.history.pushState(null, document.title, path);\n return window.dispatchEvent(new PopStateEvent(\"popstate\"));\n}\nfunction removeBaseUrl(path) {\n return path.replace(getRouter()?.baseUrl ?? \"\", \"\");\n}\n\n// src/lib/seo-utils.ts\nfunction setHTMLTitle(title, sufix = \"\") {\n const titleElement = document.head.querySelector(\"title\");\n if (titleElement && (title || sufix)) {\n const isFullTitle = title && sufix;\n titleElement.innerHTML = isFullTitle ? `${title} | ${sufix}` : title || sufix;\n }\n}\nfunction getHTMLTitle() {\n const titleElement = document.head.querySelector(\"title\");\n return titleElement?.innerHTML;\n}\n\n// src/lib/url-utils.ts\nfunction setURLParam(param, value, href = window.location.href) {\n const url = new URL(href);\n url.searchParams.set(param, value);\n window.history.replaceState(null, \"\", url.href);\n return url.href;\n}\nfunction getURLParam(param, href = window.location.href) {\n const url = new URL(href);\n return url.searchParams.get(param);\n}\nfunction getRelativeURL(href) {\n const currentLocation = window.location;\n const currentHref = currentLocation.href.endsWith(\"/\") ? currentLocation.href : `${currentLocation.href}/`;\n const url = new URL(href, currentHref);\n return url.pathname;\n}\nfunction deleteURLParam(param, href = window.location.href) {\n const url = new URL(href);\n url.searchParams.delete(param);\n window.history.replaceState(null, \"\", url.href);\n return url.href;\n}\n\nexport { Debounce, Throttle, createConsumer, createProvider, createTranslator, deleteURLParam, getAbsoluteUrl, getAction, getConfig, getHTMLTitle, getRelativeURL, getRouteById, getRouteByIdentifier, getRouter, getURLParam, navigate, navigateToPath, reloadPageContent, renderComponent, setAction, setActionAll, setHTMLTitle, setURLParam, urlFor };\n//# sourceMappingURL=out.js.map\n//# sourceMappingURL=index.mjs.map","import { ColorHelper } from '../utils/color-helpers';\nimport { getConfig } from '@sydle/ui-utils';\nimport { SydleUIConfig } from '../utils/types/sydle-ui-config.types';\n\n/**\n * Insert style tokens into html body using package definitions\n */\nfunction setGlobalTokens(): void {\n const sydleUiConfig = getConfig('sydle-ui');\n\n if (!sydleUiConfig) {\n return;\n }\n\n const primaryColor = sydleUiConfig.primaryColor;\n const accentColor = sydleUiConfig.secondaryColor;\n const globalCSSTokens = sydleUiConfig.customTokens;\n\n let style: { [key: string]: string } = {};\n\n if (primaryColor) {\n style = { ...style, '--sy-primary': primaryColor };\n const variants = ColorHelper.getColorVariations(primaryColor);\n variants.forEach((variant: { name: string; value: string }) => {\n style = { ...style, [`--sy-primary-${variant.name}`]: variant.value };\n });\n }\n\n if (accentColor) {\n style = { ...style, '--sy-accent': accentColor };\n const variants = ColorHelper.getColorVariations(accentColor);\n variants.forEach((variant: { name: string; value: string }) => {\n style = { ...style, [`--sy-accent-${variant.name}`]: variant.value };\n });\n }\n\n globalCSSTokens?.forEach((element: { token: string; value: string }) => {\n style = { ...style, [element.token]: element.value };\n });\n\n const styleElement = document.createElement('style');\n styleElement.innerHTML = `body ${JSON.stringify(style)?.replace(/\"/g, '').replace(/,/g, ';')}`;\n document.head.appendChild(styleElement);\n}\n\nsetGlobalTokens();\n"]}