@symbo.ls/scratch 2.11.5 → 2.11.17

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.
@@ -12,8 +12,8 @@ import {
12
12
  getColorShade
13
13
  } from '../utils'
14
14
 
15
- export const getColor = (value, key) => {
16
- const CONFIG = getActiveConfig()
15
+ export const getColor = (value, key, config) => {
16
+ const CONFIG = config || getActiveConfig()
17
17
  if (!isString(value)) {
18
18
  if (CONFIG.verbose) console.warn(value, '- type for color is not valid')
19
19
  return
@@ -41,33 +41,31 @@ export const getColor = (value, key) => {
41
41
  // if (alpha) return `rgba(var(${val[shade || ''].var}), ${modifier})`
42
42
 
43
43
  let rgb = val.rgb
44
- if (rgb) {
45
- if (tone) {
46
- if (!val[tone]) {
47
- const toHex = rgbArrayToHex(rgb.split(', ').map(v => parseFloat(v)))
48
- const abs = tone.slice(0, 1)
49
- if (abs === '-' || abs === '+') {
50
- rgb = hexToRgbArray(
51
- getColorShade(toHex, parseFloat(tone))
52
- ).join(', ')
53
- } else {
54
- const [r, g, b] = [...rgb.split(', ').map(v => parseInt(v))]
55
- const hsl = rgbToHSL(r, g, b)
56
- const [h, s, l] = hsl // eslint-disable-line
57
- const newRgb = hslToRgb(h, s, parseFloat(tone) / 100 * 255)
58
- rgb = newRgb
59
- }
60
- val[tone] = { rgb, var: `${val.var}-${tone}` }
61
- } else rgb = val[tone].rgb
44
+ if (!rgb) return CONFIG.useVariable ? `var(${val.var})` : val.value
45
+ if (tone && !val[tone]) {
46
+ const toHex = rgbArrayToHex(rgb.split(', ').map(v => parseFloat(v)))
47
+ const abs = tone.slice(0, 1)
48
+ if (abs === '-' || abs === '+') {
49
+ rgb = hexToRgbArray(
50
+ getColorShade(toHex, parseFloat(tone))
51
+ ).join(', ')
52
+ } else {
53
+ const [r, g, b] = [...rgb.split(', ').map(v => parseInt(v))]
54
+ const hsl = rgbToHSL(r, g, b)
55
+ const [h, s, l] = hsl // eslint-disable-line
56
+ const newRgb = hslToRgb(h, s, parseFloat(tone) / 100 * 255)
57
+ rgb = newRgb
62
58
  }
59
+ val[tone] = { rgb, var: `${val.var}-${tone}` }
60
+ }
61
+ if (val[tone]) rgb = val[tone].rgb
63
62
 
64
- if (alpha) return `rgba(${rgb}, ${alpha})`
65
- return CONFIG.useVariable ? `var(${val.var})` : `rgb(${rgb})`
66
- } else return CONFIG.useVariable ? `var(${val.var})` : val.value
63
+ if (alpha) return `rgba(${rgb}, ${alpha})`
64
+ return CONFIG.useVariable ? `var(${val.var})` : `rgb(${rgb})`
67
65
  }
68
66
 
69
- export const getMediaColor = (value, globalTheme) => {
70
- const CONFIG = getActiveConfig()
67
+ export const getMediaColor = (value, globalTheme, config) => {
68
+ const CONFIG = config || getActiveConfig()
71
69
  if (!globalTheme) globalTheme = CONFIG.globalTheme
72
70
  if (!isString(value)) {
73
71
  if (CONFIG.verbose) console.warn(value, '- type for color is not valid')
@@ -82,15 +80,15 @@ export const getMediaColor = (value, globalTheme) => {
82
80
  const val = COLOR[name] || GRADIENT[name]
83
81
  const isObj = isObject(val)
84
82
 
85
- if (isObj && val.value) return getColor(value, `@${globalTheme}`)
83
+ if (isObj && val.value) return getColor(value, `@${globalTheme}`, config)
86
84
  else if (isObj) {
87
- if (globalTheme) return getColor(value, `@${globalTheme}`)
85
+ if (globalTheme) return getColor(value, `@${globalTheme}`, config)
88
86
  else {
89
87
  const obj = {}
90
88
  for (const mediaName in val) {
91
89
  const query = CONFIG.MEDIA[mediaName.slice(1)]
92
90
  const media = `@media screen and ${query}`
93
- obj[media] = getColor(value, mediaName)
91
+ obj[media] = getColor(value, mediaName, config)
94
92
  }
95
93
  return obj
96
94
  }
@@ -35,7 +35,7 @@ export const applyReset = (reset = {}) => {
35
35
  top: '0',
36
36
  left: '0',
37
37
  margin: '0',
38
- WebkitFontSmoothing: 'antialiased',
38
+ WebkitFontSmoothing: 'subpixel-antialiased',
39
39
  scrollBehavior: 'smooth',
40
40
 
41
41
  fontSize: TYPOGRAPHY.browserDefault + 'px',
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { isString } from '@domql/utils'
3
+ import { isArray, isString } from '@domql/utils'
4
4
  import { getActiveConfig } from '../factory'
5
5
 
6
6
  export const generateSprite = (icons) => {
@@ -36,16 +36,35 @@ const parseRootAttributes = (htmlString) => {
36
36
  }, {})
37
37
  }
38
38
 
39
+ const replaceIdsAndUrls = (code, key) => {
40
+ const idRegex = /id="([^"]*)"/
41
+ const urlRegex = /url\(#([^)]*)\)/g
42
+ const matches = code.match(/id="([^"]*)"/g)
43
+ let replacedCode = code
44
+ if (isArray(matches)) {
45
+ matches.forEach(() => {
46
+ const randomKey = Math.floor(Math.random() * 100000)
47
+ replacedCode = code.replace(idRegex, `id="${key}-${randomKey}"`).replace(urlRegex, `url(#${key}-${randomKey})`)
48
+ })
49
+ }
50
+ return replacedCode
51
+ }
52
+
39
53
  export const convertSvgToSymbol = (key, code) => {
40
54
  const extractAttrs = parseRootAttributes(code)
41
55
  const { width, height } = extractAttrs
42
56
 
57
+ console.log(extractAttrs)
58
+
43
59
  const viewBox = extractAttrs.viewBox || `0 0 ${width || 24} ${height || 24}`
44
60
  const xmlns = 'http://www.w3.org/2000/svg'
45
61
 
46
- let symbol = code.replace('<svg',
62
+ const replacedCode = replaceIdsAndUrls(code, key)
63
+
64
+ let symbol = replacedCode.replace('<svg',
47
65
  `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
48
66
  )
67
+
49
68
  symbol = symbol.replace(/width="[^"]*"/, '')
50
69
  symbol = symbol.replace(/height="[^"]*"/, '')
51
70
  symbol = symbol.replace('</svg', '</symbol')