@descope/web-components-ui 1.0.94 → 1.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs.js +22 -1
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +22 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/index.js +11 -1
- package/src/helpers/themeHelpers/index.js +13 -2
package/dist/cjs/index.cjs.js
CHANGED
@@ -15,6 +15,16 @@ const kebabCase = (str) =>
|
|
15
15
|
|
16
16
|
const kebabCaseJoin = (...args) => kebabCase(args.filter((arg) => !!arg).join('-'));
|
17
17
|
|
18
|
+
const isUrl = (maybeUrl) => {
|
19
|
+
try {
|
20
|
+
new URL(maybeUrl);
|
21
|
+
|
22
|
+
return true;
|
23
|
+
} catch (e) {
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
18
28
|
const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);
|
19
29
|
|
20
30
|
const getCssVarName = (...args) =>
|
@@ -75,9 +85,20 @@ const transformTheme = (theme, path, getTransformation) => {
|
|
75
85
|
const stringifyArray = (strArr) =>
|
76
86
|
strArr.map((str) => (str.includes(' ') ? `"${str}"` : str)).join(', ');
|
77
87
|
|
88
|
+
const getCssVarValue = (val) => {
|
89
|
+
switch (true) {
|
90
|
+
case Array.isArray(val):
|
91
|
+
return stringifyArray(val)
|
92
|
+
case isUrl(val):
|
93
|
+
return `url(${val})`
|
94
|
+
default:
|
95
|
+
return val
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
78
99
|
const themeToCSSVarsObj = (theme) =>
|
79
100
|
transformTheme(theme, [], (path, val) => ({
|
80
|
-
[getVarName(path)]:
|
101
|
+
[getVarName(path)]: getCssVarValue(val)
|
81
102
|
}));
|
82
103
|
|
83
104
|
const getThemeRefs = (theme, prefix) =>
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/constants.js","../../src/helpers/index.js","../../src/helpers/componentHelpers.js","../../src/helpers/themeHelpers/componentsThemeManager.js","../../src/helpers/themeHelpers/index.js"],"sourcesContent":["export const DESCOPE_PREFIX = 'descope';\nexport const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3\nexport const BASE_THEME_SECTION = 'host'\nexport const PORTAL_THEME_PREFIX = '@'","\nexport const kebabCase = (str) =>\n\tstr\n\t\t.replace(/([a-z])([A-Z])/g, '$1-$2')\n\t\t.replace(/[\\s_.]+/g, '-')\n\t\t.toLowerCase();\n\nexport const kebabCaseJoin = (...args) => kebabCase(args.filter((arg) => !!arg).join('-'));\n\nexport const compose = (...fns) =>\n\t(val) =>\n\t\tfns.reduceRight((res, fn) => fn(res), val);\n\nexport const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)\n\nexport const isFunction = (maybeFunc) => typeof maybeFunc === 'function'","import { kebabCaseJoin } from '.';\nimport { DESCOPE_PREFIX } from '../constants';\n\nexport const observeAttributes = (\n\tele,\n\tcallback,\n\t{ excludeAttrs = [], includeAttrs = [] }\n) => {\n\t// sync all attrs on init\n\tconst filteredAttrs = Array.from(ele.attributes)\n\t\t.filter((attr) =>\n\t\t\t!excludeAttrs.includes(attr.name) &&\n\t\t\t(!includeAttrs.length || includeAttrs.includes(attr.name))\n\t\t)\n\t\t.map((attr) => attr.name)\n\n\tcallback(filteredAttrs);\n\n\tconst observer = new MutationObserver((mutationsList) => {\n\t\tfor (const mutation of mutationsList) {\n\t\t\tif (\n\t\t\t\tmutation.type === 'attributes' &&\n\t\t\t\t!excludeAttrs.includes(mutation.attributeName) &&\n\t\t\t\t(!includeAttrs.length || includeAttrs.includes(mutation.attributeName))\n\t\t\t) {\n\t\t\t\tcallback([mutation.attributeName]);\n\t\t\t}\n\t\t}\n\t});\n\n\tobserver.observe(ele, { attributes: true });\n};\n\n// calling the callback with this object: { addedNodes, removedNodes }\nexport const observeChildren = (\n\tele,\n\tcallback,\n) => {\n\tcallback({ addedNodes: Array.from(ele.children), removedNodes: [] });\n\n\tconst observer = new MutationObserver((mutationsList) => {\n\t\tfor (const mutation of mutationsList) {\n\t\t\tif (mutation.type === 'childList') {\n\t\t\t\tcallback(mutation);\n\t\t\t}\n\t\t}\n\t});\n\n\tobserver.observe(ele, { childList: true });\n};\n\nconst createSyncAttrsCb =\n\t(srcEle, targetEle, mapAttrs = {}) =>\n\t\t(attrNames) => {\n\t\t\tattrNames.forEach((attrName) => {\n\t\t\t\tconst targetAttrName = mapAttrs[attrName] || attrName;\n\t\t\t\tconst srcAttrVal = srcEle.getAttribute(attrName);\n\t\t\t\tif (srcAttrVal !== null) {\n\t\t\t\t\tif (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {\n\t\t\t\t\t\ttargetEle.setAttribute(targetAttrName, srcAttrVal);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttargetEle.removeAttribute(targetAttrName);\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\nexport const syncAttrs = (ele1, ele2, options) => {\n\tobserveAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);\n\tobserveAttributes(ele2, createSyncAttrsCb(ele2, ele1), options);\n};\n\nexport const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);\n\nexport const getCssVarName = (...args) =>\n\t`--${kebabCaseJoin(...args)}`;\n\nexport const forwardAttrs = (source, dest, options = {}) => {\n\tobserveAttributes(\n\t\tsource,\n\t\tcreateSyncAttrsCb(source, dest, options.mapAttrs),\n\t\toptions\n\t);\n};\n\nexport const forwardProps = (src, target, props = []) => {\n\tif (!props.length) return;\n\n\tconst config = props.reduce((acc, prop) => Object.assign(acc, {\n\t\t[prop]: {\n\t\t\tget() {\n\t\t\t\treturn src[prop]\n\t\t\t},\n\t\t\tset(v) {\n\t\t\t\tsrc[prop] = v\n\t\t\t}\n\t\t}\n\t}), {})\n\n\tObject.defineProperties(target, config)\n}\n","\nclass ComponentsThemeManager {\n static mountOnPropName = 'DescopeThemeManager';\n\n #themes = {};\n\n #currentThemeName = 'light';\n\n #callbacks = new Set();\n\n #notify() {\n this.#callbacks.forEach(cb => cb?.());\n };\n\n get currentThemeName() {\n return this.#currentThemeName;\n }\n\n set currentThemeName(themeName) {\n this.#currentThemeName = themeName;\n this.#notify();\n }\n\n get currentTheme() {\n return this.#themes[this.currentThemeName];\n }\n\n onCurrentThemeChange(cb) {\n this.#callbacks.add(cb);\n\n return () => { this.#callbacks.delete(cb); };\n };\n\n set themes(themes) {\n this.#themes = themes;\n this.#notify();\n }\n}\n\nexport const componentsThemeManager = new ComponentsThemeManager()\n","import merge from 'lodash.merge';\nimport set from 'lodash.set';\nimport { BASE_THEME_SECTION, DESCOPE_PREFIX, PORTAL_THEME_PREFIX } from '../../constants';\nimport { kebabCase } from '..';\nimport { getComponentName, getCssVarName } from '../componentHelpers';\n\nconst getVarName = (path) => getCssVarName(DESCOPE_PREFIX, ...path);\n\nconst transformTheme = (theme, path, getTransformation) => {\n\treturn Object.entries(theme).reduce((acc, [key, val]) => {\n\t\tif (val?.constructor !== Object) {\n\t\t\treturn merge(acc, getTransformation(path.concat(key), val));\n\t\t} else {\n\t\t\treturn merge(acc, transformTheme(val, [...path, key], getTransformation));\n\t\t}\n\t}, {});\n};\n\nconst stringifyArray = (strArr) =>\n\tstrArr.map((str) => (str.includes(' ') ? `\"${str}\"` : str)).join(', ');\n\nexport const themeToCSSVarsObj = (theme) =>\n\ttransformTheme(theme, [], (path, val) => ({\n\t\t[getVarName(path)]: Array.isArray(val) ? stringifyArray(val) : val\n\t}));\n\nexport const getThemeRefs = (theme, prefix) =>\n\ttransformTheme(theme, [], (path) =>\n\t\tset({}, path, `var(${getVarName(prefix ? [prefix, ...path] : path)})`)\n\t);\n\nexport const globalsThemeToStyle = (theme, themeName = '') => `\n*[data-theme=\"${themeName}\"] {\n\t${Object.entries(themeToCSSVarsObj(theme)).reduce(\n\t(acc, entry) => (acc += `${entry.join(':')};\\n`),\n\t''\n)}\n}\n`;\n\nconst componentsThemeToStyleObj = (componentsTheme) =>\n\ttransformTheme(componentsTheme, [], (path, val) => {\n\t\tconst [component, ...restPath] = path;\n\t\tconst property = restPath.pop();\n\t\tconst componentName = getComponentName(component);\n\n\t\t// we need a support for portal components theme (e.g. overlay)\n\t\t// this allows us to generate those themes under different sections\n\t\t// if the theme has root level attribute that starts with #\n\t\t// we are generating a new theme\n\t\tlet themeName = BASE_THEME_SECTION\n\n\t\tif (restPath[0] && restPath[0].startsWith(PORTAL_THEME_PREFIX)) {\n\t\t\tthemeName = restPath.shift();\n\t\t}\n\n\t\t// do not start with underscore -> key:value, must have 2 no underscore attrs in a row\n\t\t// starts with underscore -> attribute selector\n\t\tconst attrsSelector = restPath.reduce((acc, section, idx) => {\n\t\t\tif (section.startsWith('_'))\n\t\t\t\treturn (acc += `[${kebabCase(section.replace(/^_/, ''))}=\"true\"]`);\n\n\t\t\tconst nextSection = restPath[idx + 1];\n\n\t\t\tif (typeof nextSection !== 'string' || nextSection.startsWith('_')) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t'theme generator',\n\t\t\t\t\t`your theme structure is invalid, attribute \"${section}\" is followed by \"${nextSection}\" which is not allowed`\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}\n\n\t\t\treturn (acc += `[${kebabCase(section)}=\"${restPath\n\t\t\t\t.splice(idx + 1, 1)\n\t\t\t\t.join('')}\"]`);\n\t\t}, '');\n\n\t\tlet selector = `:host${attrsSelector ? `(${attrsSelector})` : ''}`;\n\n\t\treturn {\n\t\t\t[componentName]: {\n\t\t\t\t[themeName]: {\n\t\t\t\t\t[selector]: {\n\t\t\t\t\t\t[property]: val\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t});\n\n\nexport const createComponentsTheme = (componentsTheme) => {\n\tconst styleObj = componentsThemeToStyleObj(componentsTheme);\n\n\treturn Object.keys(styleObj).reduce(\n\t\t(acc, componentName) => {\n\t\t\tconst componentThemes = styleObj[componentName];\n\n\t\t\treturn Object.assign(acc, {\n\t\t\t\t[componentName]: Object.keys(componentThemes)\n\t\t\t\t\t.reduce((acc, theme) =>\n\t\t\t\t\t\tObject.assign(acc, { [theme]: componentsThemeToStyle(componentThemes[theme]) }),\n\t\t\t\t\t\t{})\n\t\t\t})\n\t\t},\n\t\t{}\n\t);\n}\n\nconst componentsThemeToStyle = (componentsTheme) =>\n\tObject.entries(componentsTheme).reduce(\n\t\t(acc, [selector, vars]) =>\n\t\t(acc += `${selector} { \\n${Object.entries(\n\t\t\tvars\n\t\t)\n\t\t\t.map(([key, val]) => `${key}: ${val}`)\n\t\t\t.join(';\\n')} \\n}\\n\\n`),\n\t\t''\n\t);\n\nexport const themeToStyle = ({ globals, components }, themeName) => ({\n\tglobals: globalsThemeToStyle(globals, themeName),\n\tcomponents: createComponentsTheme(components)\n});\n\nconst useVar = (varName) => `var(${varName})`;\n\nexport const createHelperVars = (theme, prefix) => {\n\tconst res = transformTheme(theme, [], (path, value) => {\n\t\tconst modifiedPath = [...path];\n\t\tconst property = modifiedPath.splice(-1);\n\t\tconst varName = getCssVarName(prefix, property);\n\n\t\tconst vars = { [property]: varName };\n\t\tconst theme = set({}, [...modifiedPath, varName], value);\n\t\tconst useVars = { [property]: useVar(varName) };\n\n\t\treturn { theme, useVars, vars };\n\t});\n\n\treturn [res.theme, res.useVars, res.vars];\n};\n\nexport { componentsThemeManager } from './componentsThemeManager'\n"],"names":[],"mappings":";;;;;AAAO,MAAM,cAAc,GAAG,SAAS,CAAC;AAEjC,MAAM,kBAAkB,GAAG,OAAM;AACjC,MAAM,mBAAmB,GAAG;;ACF5B,MAAM,SAAS,GAAG,CAAC,GAAG;AAC7B,CAAC,GAAG;AACJ,GAAG,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;AACtC,GAAG,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;AAC3B,GAAG,WAAW,EAAE,CAAC;AACjB;AACO,MAAM,aAAa,GAAG,CAA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AE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAClC,EAAE,CAAC,CAAC;AACJ;AACA,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3C;;;;;;;;;;"}
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/constants.js","../../src/helpers/index.js","../../src/helpers/componentHelpers.js","../../src/helpers/themeHelpers/componentsThemeManager.js","../../src/helpers/themeHelpers/index.js"],"sourcesContent":["export const DESCOPE_PREFIX = 'descope';\nexport const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3\nexport const BASE_THEME_SECTION = 'host'\nexport const PORTAL_THEME_PREFIX = '@'","\nexport const kebabCase = (str) =>\n\tstr\n\t\t.replace(/([a-z])([A-Z])/g, '$1-$2')\n\t\t.replace(/[\\s_.]+/g, '-')\n\t\t.toLowerCase();\n\nexport const kebabCaseJoin = (...args) => kebabCase(args.filter((arg) => !!arg).join('-'));\n\nexport const compose = (...fns) =>\n\t(val) =>\n\t\tfns.reduceRight((res, fn) => fn(res), val);\n\nexport const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)\n\nexport const isFunction = (maybeFunc) => typeof maybeFunc === 'function';\n\nexport const isUrl = (maybeUrl) => {\n\ttry {\n\t\tnew URL(maybeUrl)\n\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n}","import { kebabCaseJoin } from '.';\nimport { DESCOPE_PREFIX } from '../constants';\n\nexport const observeAttributes = (\n\tele,\n\tcallback,\n\t{ excludeAttrs = [], includeAttrs = [] }\n) => {\n\t// sync all attrs on init\n\tconst filteredAttrs = Array.from(ele.attributes)\n\t\t.filter((attr) =>\n\t\t\t!excludeAttrs.includes(attr.name) &&\n\t\t\t(!includeAttrs.length || includeAttrs.includes(attr.name))\n\t\t)\n\t\t.map((attr) => attr.name)\n\n\tcallback(filteredAttrs);\n\n\tconst observer = new MutationObserver((mutationsList) => {\n\t\tfor (const mutation of mutationsList) {\n\t\t\tif (\n\t\t\t\tmutation.type === 'attributes' &&\n\t\t\t\t!excludeAttrs.includes(mutation.attributeName) &&\n\t\t\t\t(!includeAttrs.length || includeAttrs.includes(mutation.attributeName))\n\t\t\t) {\n\t\t\t\tcallback([mutation.attributeName]);\n\t\t\t}\n\t\t}\n\t});\n\n\tobserver.observe(ele, { attributes: true });\n};\n\n// calling the callback with this object: { addedNodes, removedNodes }\nexport const observeChildren = (\n\tele,\n\tcallback,\n) => {\n\tcallback({ addedNodes: Array.from(ele.children), removedNodes: [] });\n\n\tconst observer = new MutationObserver((mutationsList) => {\n\t\tfor (const mutation of mutationsList) {\n\t\t\tif (mutation.type === 'childList') {\n\t\t\t\tcallback(mutation);\n\t\t\t}\n\t\t}\n\t});\n\n\tobserver.observe(ele, { childList: true });\n};\n\nconst createSyncAttrsCb =\n\t(srcEle, targetEle, mapAttrs = {}) =>\n\t\t(attrNames) => {\n\t\t\tattrNames.forEach((attrName) => {\n\t\t\t\tconst targetAttrName = mapAttrs[attrName] || attrName;\n\t\t\t\tconst srcAttrVal = srcEle.getAttribute(attrName);\n\t\t\t\tif (srcAttrVal !== null) {\n\t\t\t\t\tif (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {\n\t\t\t\t\t\ttargetEle.setAttribute(targetAttrName, srcAttrVal);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttargetEle.removeAttribute(targetAttrName);\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\nexport const syncAttrs = (ele1, ele2, options) => {\n\tobserveAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);\n\tobserveAttributes(ele2, createSyncAttrsCb(ele2, ele1), options);\n};\n\nexport const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);\n\nexport const getCssVarName = (...args) =>\n\t`--${kebabCaseJoin(...args)}`;\n\nexport const forwardAttrs = (source, dest, options = {}) => {\n\tobserveAttributes(\n\t\tsource,\n\t\tcreateSyncAttrsCb(source, dest, options.mapAttrs),\n\t\toptions\n\t);\n};\n\nexport const forwardProps = (src, target, props = []) => {\n\tif (!props.length) return;\n\n\tconst config = props.reduce((acc, prop) => Object.assign(acc, {\n\t\t[prop]: {\n\t\t\tget() {\n\t\t\t\treturn src[prop]\n\t\t\t},\n\t\t\tset(v) {\n\t\t\t\tsrc[prop] = v\n\t\t\t}\n\t\t}\n\t}), {})\n\n\tObject.defineProperties(target, config)\n}\n","\nclass ComponentsThemeManager {\n static mountOnPropName = 'DescopeThemeManager';\n\n #themes = {};\n\n #currentThemeName = 'light';\n\n #callbacks = new Set();\n\n #notify() {\n this.#callbacks.forEach(cb => cb?.());\n };\n\n get currentThemeName() {\n return this.#currentThemeName;\n }\n\n set currentThemeName(themeName) {\n this.#currentThemeName = themeName;\n this.#notify();\n }\n\n get currentTheme() {\n return this.#themes[this.currentThemeName];\n }\n\n onCurrentThemeChange(cb) {\n this.#callbacks.add(cb);\n\n return () => { this.#callbacks.delete(cb); };\n };\n\n set themes(themes) {\n this.#themes = themes;\n this.#notify();\n }\n}\n\nexport const componentsThemeManager = new ComponentsThemeManager()\n","import merge from 'lodash.merge';\nimport set from 'lodash.set';\nimport { BASE_THEME_SECTION, DESCOPE_PREFIX, PORTAL_THEME_PREFIX } from '../../constants';\nimport { isUrl, kebabCase } from '..';\nimport { getComponentName, getCssVarName } from '../componentHelpers';\n\nconst getVarName = (path) => getCssVarName(DESCOPE_PREFIX, ...path);\n\nconst transformTheme = (theme, path, getTransformation) => {\n\treturn Object.entries(theme).reduce((acc, [key, val]) => {\n\t\tif (val?.constructor !== Object) {\n\t\t\treturn merge(acc, getTransformation(path.concat(key), val));\n\t\t} else {\n\t\t\treturn merge(acc, transformTheme(val, [...path, key], getTransformation));\n\t\t}\n\t}, {});\n};\n\nconst stringifyArray = (strArr) =>\n\tstrArr.map((str) => (str.includes(' ') ? `\"${str}\"` : str)).join(', ');\n\nconst getCssVarValue = (val) => {\n\tswitch (true) {\n\t\tcase Array.isArray(val):\n\t\t\treturn stringifyArray(val)\n\t\tcase isUrl(val):\n\t\t\treturn `url(${val})`\n\t\tdefault:\n\t\t\treturn val\n\t}\n}\n\nexport const themeToCSSVarsObj = (theme) =>\n\ttransformTheme(theme, [], (path, val) => ({\n\t\t[getVarName(path)]: getCssVarValue(val)\n\t}));\n\nexport const getThemeRefs = (theme, prefix) =>\n\ttransformTheme(theme, [], (path) =>\n\t\tset({}, path, `var(${getVarName(prefix ? [prefix, ...path] : path)})`)\n\t);\n\nexport const globalsThemeToStyle = (theme, themeName = '') => `\n*[data-theme=\"${themeName}\"] {\n\t${Object.entries(themeToCSSVarsObj(theme)).reduce(\n\t(acc, entry) => (acc += `${entry.join(':')};\\n`),\n\t''\n)}\n}\n`;\n\nconst componentsThemeToStyleObj = (componentsTheme) =>\n\ttransformTheme(componentsTheme, [], (path, val) => {\n\t\tconst [component, ...restPath] = path;\n\t\tconst property = restPath.pop();\n\t\tconst componentName = getComponentName(component);\n\n\t\t// we need a support for portal components theme (e.g. overlay)\n\t\t// this allows us to generate those themes under different sections\n\t\t// if the theme has root level attribute that starts with #\n\t\t// we are generating a new theme\n\t\tlet themeName = BASE_THEME_SECTION\n\n\t\tif (restPath[0] && restPath[0].startsWith(PORTAL_THEME_PREFIX)) {\n\t\t\tthemeName = restPath.shift();\n\t\t}\n\n\t\t// do not start with underscore -> key:value, must have 2 no underscore attrs in a row\n\t\t// starts with underscore -> attribute selector\n\t\tconst attrsSelector = restPath.reduce((acc, section, idx) => {\n\t\t\tif (section.startsWith('_'))\n\t\t\t\treturn (acc += `[${kebabCase(section.replace(/^_/, ''))}=\"true\"]`);\n\n\t\t\tconst nextSection = restPath[idx + 1];\n\n\t\t\tif (typeof nextSection !== 'string' || nextSection.startsWith('_')) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t'theme generator',\n\t\t\t\t\t`your theme structure is invalid, attribute \"${section}\" is followed by \"${nextSection}\" which is not allowed`\n\t\t\t\t);\n\t\t\t\treturn acc;\n\t\t\t}\n\n\t\t\treturn (acc += `[${kebabCase(section)}=\"${restPath\n\t\t\t\t.splice(idx + 1, 1)\n\t\t\t\t.join('')}\"]`);\n\t\t}, '');\n\n\t\tlet selector = `:host${attrsSelector ? `(${attrsSelector})` : ''}`;\n\n\t\treturn {\n\t\t\t[componentName]: {\n\t\t\t\t[themeName]: {\n\t\t\t\t\t[selector]: {\n\t\t\t\t\t\t[property]: val\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t});\n\n\nexport const createComponentsTheme = (componentsTheme) => {\n\tconst styleObj = componentsThemeToStyleObj(componentsTheme);\n\n\treturn Object.keys(styleObj).reduce(\n\t\t(acc, componentName) => {\n\t\t\tconst componentThemes = styleObj[componentName];\n\n\t\t\treturn Object.assign(acc, {\n\t\t\t\t[componentName]: Object.keys(componentThemes)\n\t\t\t\t\t.reduce((acc, theme) =>\n\t\t\t\t\t\tObject.assign(acc, { [theme]: componentsThemeToStyle(componentThemes[theme]) }),\n\t\t\t\t\t\t{})\n\t\t\t})\n\t\t},\n\t\t{}\n\t);\n}\n\nconst componentsThemeToStyle = (componentsTheme) =>\n\tObject.entries(componentsTheme).reduce(\n\t\t(acc, [selector, vars]) =>\n\t\t(acc += `${selector} { \\n${Object.entries(\n\t\t\tvars\n\t\t)\n\t\t\t.map(([key, val]) => `${key}: ${val}`)\n\t\t\t.join(';\\n')} \\n}\\n\\n`),\n\t\t''\n\t);\n\nexport const themeToStyle = ({ globals, components }, themeName) => ({\n\tglobals: globalsThemeToStyle(globals, themeName),\n\tcomponents: createComponentsTheme(components)\n});\n\nconst useVar = (varName) => `var(${varName})`;\n\nexport const createHelperVars = (theme, prefix) => {\n\tconst res = transformTheme(theme, [], (path, value) => {\n\t\tconst modifiedPath = [...path];\n\t\tconst property = modifiedPath.splice(-1);\n\t\tconst varName = getCssVarName(prefix, property);\n\n\t\tconst vars = { [property]: varName };\n\t\tconst theme = set({}, [...modifiedPath, varName], value);\n\t\tconst useVars = { [property]: useVar(varName) };\n\n\t\treturn { theme, useVars, vars };\n\t});\n\n\treturn [res.theme, res.useVars, res.vars];\n};\n\nexport { componentsThemeManager } from './componentsThemeManager'\n"],"names":[],"mappings":";;;;;AAAO,MAAM,cAAc,GAAG,SAAS,CAAC;AAEjC,MAAM,kBAAkB,GAAG,OAAM;AACjC,MAAM,mBAAmB,GAAG;;ACF5B,MAAM,SAAS,GAAG,CAAC,GAAG;AAC7B,CAAC,GAAG;AACJ,GAAG,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;AACtC,GAAG,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;AAC3B,GAAG,WAAW,EAAE,CAAC;AACjB;AACO,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAS3F;AACO,MAAM,KAAK,GAAG,CAAC,QAAQ,KAAK;AACnC,CAAC,IAAI;AACL,EAAE,IAAI,GAAG,CAAC,QAAQ,EAAC;AACnB;AACA,EAAE,OAAO,IAAI,CAAC;AACd,EAAE,CAAC,OAAO,CAAC,EAAE;AACb,EAAE,OAAO,KAAK,CAAC;AACf,EAAE;AACF;;AC+CO,MAAM,gBAAgB,GAAG,CAAC,IAAI,KAAK,aAAa,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAC9E;AACO,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI;AACrC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;;AC1E9B,MAAM,sBAAsB,CAAC;AAC7B,EAAE,OAAO,eAAe,GAAG,qBAAqB,CAAC;AACjD;AACA,EAAE,OAAO,GAAG,EAAE,CAAC;AACf;AACA,EAAE,iBAAiB,GAAG,OAAO,CAAC;AAC9B;AACA,EAAE,UA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 const compose = (...fns) =>
|
|
25
25
|
|
26
26
|
const isFunction = (maybeFunc) => typeof maybeFunc === 'function';
|
27
27
|
|
28
|
+
const isUrl = (maybeUrl) => {
|
29
|
+
try {
|
30
|
+
new URL(maybeUrl);
|
31
|
+
|
32
|
+
return true;
|
33
|
+
} catch (e) {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
28
38
|
const DESCOPE_PREFIX = 'descope';
|
29
39
|
const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3;
|
30
40
|
const BASE_THEME_SECTION = 'host';
|
@@ -4834,9 +4844,20 @@ const transformTheme = (theme, path, getTransformation) => {
|
|
4834
4844
|
const stringifyArray = (strArr) =>
|
4835
4845
|
strArr.map((str) => (str.includes(' ') ? `"${str}"` : str)).join(', ');
|
4836
4846
|
|
4847
|
+
const getCssVarValue = (val) => {
|
4848
|
+
switch (true) {
|
4849
|
+
case Array.isArray(val):
|
4850
|
+
return stringifyArray(val)
|
4851
|
+
case isUrl(val):
|
4852
|
+
return `url(${val})`
|
4853
|
+
default:
|
4854
|
+
return val
|
4855
|
+
}
|
4856
|
+
};
|
4857
|
+
|
4837
4858
|
const themeToCSSVarsObj = (theme) =>
|
4838
4859
|
transformTheme(theme, [], (path, val) => ({
|
4839
|
-
[getVarName(path)]:
|
4860
|
+
[getVarName(path)]: getCssVarValue(val)
|
4840
4861
|
}));
|
4841
4862
|
|
4842
4863
|
const getThemeRefs = (theme, prefix) =>
|