@descope/web-components-ui 1.0.94 → 1.0.95

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/web-components-ui",
3
- "version": "1.0.94",
3
+ "version": "1.0.95",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -13,4 +13,14 @@ export const compose = (...fns) =>
13
13
 
14
14
  export const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)
15
15
 
16
- export const isFunction = (maybeFunc) => typeof maybeFunc === 'function'
16
+ export const isFunction = (maybeFunc) => typeof maybeFunc === 'function';
17
+
18
+ export const isUrl = (maybeUrl) => {
19
+ try {
20
+ new URL(maybeUrl)
21
+
22
+ return true;
23
+ } catch (e) {
24
+ return false;
25
+ }
26
+ }
@@ -1,7 +1,7 @@
1
1
  import merge from 'lodash.merge';
2
2
  import set from 'lodash.set';
3
3
  import { BASE_THEME_SECTION, DESCOPE_PREFIX, PORTAL_THEME_PREFIX } from '../../constants';
4
- import { kebabCase } from '..';
4
+ import { isUrl, kebabCase } from '..';
5
5
  import { getComponentName, getCssVarName } from '../componentHelpers';
6
6
 
7
7
  const getVarName = (path) => getCssVarName(DESCOPE_PREFIX, ...path);
@@ -19,9 +19,20 @@ const transformTheme = (theme, path, getTransformation) => {
19
19
  const stringifyArray = (strArr) =>
20
20
  strArr.map((str) => (str.includes(' ') ? `"${str}"` : str)).join(', ');
21
21
 
22
+ const getCssVarValue = (val) => {
23
+ switch (true) {
24
+ case Array.isArray(val):
25
+ return stringifyArray(val)
26
+ case isUrl(val):
27
+ return `url(${val})`
28
+ default:
29
+ return val
30
+ }
31
+ }
32
+
22
33
  export const themeToCSSVarsObj = (theme) =>
23
34
  transformTheme(theme, [], (path, val) => ({
24
- [getVarName(path)]: Array.isArray(val) ? stringifyArray(val) : val
35
+ [getVarName(path)]: getCssVarValue(val)
25
36
  }));
26
37
 
27
38
  export const getThemeRefs = (theme, prefix) =>