@symbo.ls/scratch 3.14.2 → 3.14.3

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.
Files changed (140) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/index.cjs +1 -0
  3. package/dist/cjs/src/defaultConfig/animation.cjs +1 -0
  4. package/dist/cjs/src/defaultConfig/cases.cjs +1 -0
  5. package/dist/cjs/src/defaultConfig/class.cjs +1 -0
  6. package/dist/cjs/src/defaultConfig/color.cjs +1 -0
  7. package/dist/cjs/src/defaultConfig/document.cjs +1 -0
  8. package/dist/cjs/src/defaultConfig/font-family.cjs +1 -0
  9. package/dist/cjs/src/defaultConfig/font.cjs +1 -0
  10. package/dist/cjs/src/defaultConfig/grid.cjs +1 -0
  11. package/dist/cjs/src/defaultConfig/icons.cjs +1 -0
  12. package/dist/cjs/src/defaultConfig/index.cjs +1 -0
  13. package/dist/cjs/src/defaultConfig/media.cjs +1 -0
  14. package/dist/cjs/src/defaultConfig/responsive.cjs +1 -0
  15. package/dist/cjs/src/defaultConfig/sequence.cjs +1 -0
  16. package/dist/cjs/src/defaultConfig/shadow.cjs +1 -0
  17. package/dist/cjs/src/defaultConfig/spacing.cjs +1 -0
  18. package/dist/cjs/src/defaultConfig/svg.cjs +1 -0
  19. package/dist/cjs/src/defaultConfig/templates.cjs +1 -0
  20. package/dist/cjs/src/defaultConfig/theme.cjs +1 -0
  21. package/dist/cjs/src/defaultConfig/timing.cjs +1 -0
  22. package/dist/cjs/src/defaultConfig/typography.cjs +1 -0
  23. package/dist/cjs/src/defaultConfig/unit.cjs +1 -0
  24. package/dist/cjs/src/factory.cjs +1 -0
  25. package/dist/cjs/src/index.cjs +1 -0
  26. package/dist/cjs/src/set.cjs +1 -0
  27. package/dist/cjs/src/system/color.cjs +1 -0
  28. package/dist/cjs/src/system/document.cjs +1 -0
  29. package/dist/cjs/src/system/font.cjs +1 -0
  30. package/dist/cjs/src/system/index.cjs +1 -0
  31. package/dist/cjs/src/system/reset.cjs +1 -0
  32. package/dist/cjs/src/system/shadow.cjs +1 -0
  33. package/dist/cjs/src/system/spacing.cjs +1 -0
  34. package/dist/cjs/src/system/svg.cjs +1 -0
  35. package/dist/cjs/src/system/theme.cjs +1 -0
  36. package/dist/cjs/src/system/timing.cjs +1 -0
  37. package/dist/cjs/src/system/typography.cjs +1 -0
  38. package/dist/cjs/src/tests/index.cjs +1 -0
  39. package/dist/cjs/src/transforms/index.cjs +1 -0
  40. package/dist/cjs/src/utils/color.cjs +1 -0
  41. package/dist/cjs/src/utils/font.cjs +9 -0
  42. package/dist/cjs/src/utils/index.cjs +1 -0
  43. package/dist/cjs/src/utils/sequence.cjs +1 -0
  44. package/dist/cjs/src/utils/sprite.cjs +1 -0
  45. package/dist/cjs/src/utils/theme.cjs +1 -0
  46. package/dist/cjs/src/utils/unit.cjs +1 -0
  47. package/dist/cjs/src/utils/var.cjs +1 -0
  48. package/dist/esm/index.js +1 -0
  49. package/dist/esm/src/defaultConfig/animation.js +1 -0
  50. package/dist/esm/src/defaultConfig/cases.js +1 -0
  51. package/dist/esm/src/defaultConfig/class.js +1 -0
  52. package/dist/esm/src/defaultConfig/color.js +1 -0
  53. package/dist/esm/src/defaultConfig/document.js +1 -0
  54. package/dist/esm/src/defaultConfig/font-family.js +1 -0
  55. package/dist/esm/src/defaultConfig/font.js +1 -0
  56. package/dist/esm/src/defaultConfig/grid.js +1 -0
  57. package/dist/esm/src/defaultConfig/icons.js +1 -0
  58. package/dist/esm/src/defaultConfig/index.js +1 -0
  59. package/dist/esm/src/defaultConfig/media.js +1 -0
  60. package/dist/esm/src/defaultConfig/responsive.js +1 -0
  61. package/dist/esm/src/defaultConfig/sequence.js +1 -0
  62. package/dist/esm/src/defaultConfig/shadow.js +1 -0
  63. package/dist/esm/src/defaultConfig/spacing.js +1 -0
  64. package/dist/esm/src/defaultConfig/svg.js +1 -0
  65. package/dist/esm/src/defaultConfig/templates.js +1 -0
  66. package/dist/esm/src/defaultConfig/theme.js +1 -0
  67. package/dist/esm/src/defaultConfig/timing.js +1 -0
  68. package/dist/esm/src/defaultConfig/typography.js +1 -0
  69. package/dist/esm/src/defaultConfig/unit.js +1 -0
  70. package/dist/esm/src/factory.js +1 -0
  71. package/dist/esm/src/index.js +1 -0
  72. package/dist/esm/src/set.js +1 -0
  73. package/dist/esm/src/system/color.js +1 -0
  74. package/dist/esm/src/system/document.js +1 -0
  75. package/dist/esm/src/system/font.js +1 -0
  76. package/dist/esm/src/system/index.js +1 -0
  77. package/dist/esm/src/system/reset.js +1 -0
  78. package/dist/esm/src/system/shadow.js +1 -0
  79. package/dist/esm/src/system/spacing.js +1 -0
  80. package/dist/esm/src/system/svg.js +1 -0
  81. package/dist/esm/src/system/theme.js +1 -0
  82. package/dist/esm/src/system/timing.js +1 -0
  83. package/dist/esm/src/system/typography.js +1 -0
  84. package/dist/esm/src/tests/index.js +1 -0
  85. package/dist/esm/src/transforms/index.js +1 -0
  86. package/dist/esm/src/utils/color.js +1 -0
  87. package/dist/esm/src/utils/font.js +9 -0
  88. package/dist/esm/src/utils/index.js +1 -0
  89. package/dist/esm/src/utils/sequence.js +1 -0
  90. package/dist/esm/src/utils/sprite.js +1 -0
  91. package/dist/esm/src/utils/theme.js +1 -0
  92. package/dist/esm/src/utils/unit.js +1 -0
  93. package/dist/esm/src/utils/var.js +1 -0
  94. package/package.json +16 -15
  95. package/index.js +0 -1
  96. package/src/defaultConfig/animation.js +0 -3
  97. package/src/defaultConfig/cases.js +0 -3
  98. package/src/defaultConfig/class.js +0 -6
  99. package/src/defaultConfig/color.js +0 -9
  100. package/src/defaultConfig/document.js +0 -3
  101. package/src/defaultConfig/font-family.js +0 -15
  102. package/src/defaultConfig/font.js +0 -12
  103. package/src/defaultConfig/grid.js +0 -5
  104. package/src/defaultConfig/icons.js +0 -4
  105. package/src/defaultConfig/index.js +0 -24
  106. package/src/defaultConfig/media.js +0 -10
  107. package/src/defaultConfig/responsive.js +0 -29
  108. package/src/defaultConfig/sequence.js +0 -24
  109. package/src/defaultConfig/shadow.js +0 -3
  110. package/src/defaultConfig/spacing.js +0 -19
  111. package/src/defaultConfig/svg.js +0 -4
  112. package/src/defaultConfig/templates.js +0 -3
  113. package/src/defaultConfig/theme.js +0 -13
  114. package/src/defaultConfig/timing.js +0 -18
  115. package/src/defaultConfig/typography.js +0 -22
  116. package/src/defaultConfig/unit.js +0 -5
  117. package/src/factory.js +0 -135
  118. package/src/index.js +0 -24
  119. package/src/set.js +0 -353
  120. package/src/system/color.js +0 -327
  121. package/src/system/document.js +0 -16
  122. package/src/system/font.js +0 -66
  123. package/src/system/index.js +0 -12
  124. package/src/system/reset.js +0 -119
  125. package/src/system/shadow.js +0 -107
  126. package/src/system/spacing.js +0 -152
  127. package/src/system/svg.js +0 -132
  128. package/src/system/theme.js +0 -454
  129. package/src/system/timing.js +0 -32
  130. package/src/system/typography.js +0 -110
  131. package/src/tests/index.js +0 -4
  132. package/src/transforms/index.js +0 -270
  133. package/src/utils/color.js +0 -269
  134. package/src/utils/font.js +0 -116
  135. package/src/utils/index.js +0 -9
  136. package/src/utils/sequence.js +0 -386
  137. package/src/utils/sprite.js +0 -107
  138. package/src/utils/theme.js +0 -8
  139. package/src/utils/unit.js +0 -72
  140. package/src/utils/var.js +0 -129
@@ -1,66 +0,0 @@
1
- 'use strict'
2
-
3
- import { isObject, isArray } from '@symbo.ls/utils'
4
- import { arrayzeValue } from '@symbo.ls/utils'
5
- import { getActiveConfig } from '../factory.js'
6
-
7
- import {
8
- getDefaultOrFirstKey,
9
- getFontFaceEach,
10
- isGoogleFontsUrl,
11
- setCustomFontMedia,
12
- setFontImport,
13
- resolveFileUrl
14
- } from '../utils/index.js'
15
-
16
- export const setFont = (val, key) => {
17
- const CONFIG = getActiveConfig()
18
- const CSSvar = `--font-${key}`
19
-
20
- if (!val || (isArray(val) && !val[0])) return
21
-
22
- let fontFace
23
- if (val.isVariable) {
24
- const url = resolveFileUrl(val.url, CONFIG.files) || val.url
25
- if (isGoogleFontsUrl(url)) {
26
- fontFace = setFontImport(url)
27
- } else {
28
- fontFace = setCustomFontMedia(key, url, val.fontWeight, {
29
- fontStretch: val.fontStretch,
30
- fontDisplay: val.fontDisplay || 'swap'
31
- })
32
- }
33
- } else if (val[0]) {
34
- fontFace = getFontFaceEach(key, val, CONFIG.files)
35
- } else {
36
- const url = Array.isArray(val.url)
37
- ? val.url.map((u) => resolveFileUrl(u, CONFIG.files) || u)
38
- : resolveFileUrl(val.url, CONFIG.files) || val.url
39
- fontFace = setCustomFontMedia(key, url, val.fontWeight, {
40
- fontStyle: val.fontStyle,
41
- fontDisplay: val.fontDisplay,
42
- fontStretch: val.fontStretch
43
- })
44
- }
45
-
46
- return { var: CSSvar, value: val, fontFace }
47
- }
48
-
49
- export const getFontFamily = (key, factory) => {
50
- const CONFIG = getActiveConfig()
51
- const { fontFamily: FONT_FAMILY } = CONFIG
52
- return getDefaultOrFirstKey(factory || FONT_FAMILY, key)
53
- }
54
-
55
- export const setFontFamily = (val, key) => {
56
- const CONFIG = getActiveConfig()
57
- const { fontFamily: FONT_FAMILY, fontFamilyTypes: FONT_FAMILY_TYPES } = CONFIG
58
- let { value, type } = val
59
- if (val.isDefault) FONT_FAMILY.default = key
60
-
61
- if (isObject(value)) value = arrayzeValue(value)
62
-
63
- const CSSvar = `--font-family-${key}`
64
- const str = `${value.join(', ')}, ${FONT_FAMILY_TYPES[type]}`
65
- return { var: CSSvar, value: str, arr: value, type }
66
- }
@@ -1,12 +0,0 @@
1
- 'use strict'
2
-
3
- export * from './color.js'
4
- export * from './theme.js'
5
- export * from './font.js'
6
- export * from './typography.js'
7
- export * from './spacing.js'
8
- export * from './shadow.js'
9
- export * from './timing.js'
10
- export * from './document.js'
11
- export * from './svg.js'
12
- export * from './reset.js'
@@ -1,119 +0,0 @@
1
- 'use strict'
2
-
3
- import { deepMerge, merge, overwriteDeep } from '@symbo.ls/utils'
4
- import { getActiveConfig } from '../factory.js'
5
- import { getMediaTheme } from './theme.js'
6
-
7
- export const applyReset = (reset = {}) => {
8
- const CONFIG = getActiveConfig()
9
-
10
- const { reset: RESET, typography: TYPOGRAPHY, document: DOCUMENT } = CONFIG
11
-
12
- if (RESET) {
13
- if (RESET[':root']) {
14
- const configReset = RESET
15
- const configTemplates = TYPOGRAPHY.templates
16
-
17
- configReset.body = {
18
- ...(CONFIG.useDocumentTheme
19
- ? getMediaTheme('document')
20
- : {}),
21
- ...configTemplates.body
22
- }
23
- configReset.h1 = configTemplates.h1
24
- configReset.h2 = configTemplates.h2
25
- configReset.h3 = configTemplates.h3
26
- configReset.h4 = configTemplates.h4
27
- configReset.h5 = configTemplates.h5
28
- configReset.h6 = configTemplates.h6
29
- }
30
-
31
- const { body, ...templates } = TYPOGRAPHY.templates
32
- const globalTheme = CONFIG.useDocumentTheme
33
- ? getMediaTheme('document')
34
- : {}
35
- if (RESET.html) overwriteDeep(RESET.html, globalTheme)
36
-
37
- // Generate html fontSize overrides for typography media breakpoints
38
- if (TYPOGRAPHY.unit) {
39
- const { media: MEDIA } = CONFIG
40
- for (const key in TYPOGRAPHY) {
41
- if (key.charAt(0) !== '@') continue
42
- const mediaTypo = TYPOGRAPHY[key]
43
- if (!mediaTypo) continue
44
- // Only override html fontSize if this media explicitly changes the unit
45
- if (mediaTypo.unit === TYPOGRAPHY.unit || !mediaTypo.unit) continue
46
- const mediaUnit = mediaTypo.unit
47
- const mediaBase = mediaTypo.base || TYPOGRAPHY.base
48
- const mediaBrowserDefault = mediaTypo.browserDefault || TYPOGRAPHY.browserDefault
49
- const mediaName = key.slice(1)
50
- const query = MEDIA[mediaName]
51
- if (!query) continue
52
- const mediaKey = '@media ' + (query === 'print' ? query : 'screen and ' + query)
53
- if (!RESET[mediaKey]) RESET[mediaKey] = {}
54
- if (!RESET[mediaKey].html) RESET[mediaKey].html = {}
55
- RESET[mediaKey].html.fontSize = (mediaBase / mediaBrowserDefault) + mediaUnit
56
- }
57
- }
58
-
59
- return deepMerge(merge(RESET, reset), {
60
- html: {
61
- position: 'absolute',
62
- width: '100%',
63
- height: '100%',
64
- top: '0',
65
- left: '0',
66
- margin: '0',
67
- WebkitFontSmoothing: 'subpixel-antialiased',
68
- scrollBehavior: 'smooth',
69
-
70
- ...globalTheme,
71
-
72
- fontSize: TYPOGRAPHY.unit
73
- ? (TYPOGRAPHY.base / TYPOGRAPHY.browserDefault) + TYPOGRAPHY.unit
74
- : TYPOGRAPHY.browserDefault + 'px',
75
-
76
- fontFamily: DOCUMENT.fontFamily,
77
- lineHeight: DOCUMENT.lineHeight
78
- },
79
-
80
- body: {
81
- boxSizing: 'border-box',
82
- height: '100%',
83
- margin: 0,
84
- fontFamily: DOCUMENT.fontFamily,
85
-
86
- fontSize:
87
- TYPOGRAPHY.base / TYPOGRAPHY.browserDefault + CONFIG.unit.default,
88
-
89
- ...templates,
90
- ...body
91
- },
92
-
93
- a: {
94
- color: 'currentColor'
95
- },
96
-
97
- button: {
98
- color: 'inherit',
99
- font: 'inherit',
100
- background: 'transparent',
101
- border: 'none',
102
- cursor: 'pointer',
103
- appearance: 'none',
104
- WebkitAppearance: 'none'
105
- },
106
-
107
- 'input, select, textarea': {
108
- color: 'inherit',
109
- font: 'inherit'
110
- },
111
-
112
- fieldset: {
113
- border: 0,
114
- padding: 0,
115
- margin: 0
116
- }
117
- })
118
- }
119
- }
@@ -1,107 +0,0 @@
1
- 'use strict'
2
-
3
- import { getActiveConfig } from '../factory.js'
4
- import { getColor } from './color.js'
5
- import { getSpacingByKey } from './spacing.js'
6
- import { isResolvedColor, isCSSVar, splitTopLevelCommas, CSS_NATIVE_COLOR_REGEX } from '../utils/color.js'
7
-
8
- import {
9
- isObject,
10
- isString,
11
- isArray
12
- } from '@symbo.ls/utils'
13
-
14
- export const setShadow = (value, key, suffix, prefers) => {
15
- const CONFIG = getActiveConfig()
16
-
17
- if (isArray(value)) {
18
- return {
19
- '@light': setShadow(value[0], key, 'light'),
20
- '@dark': setShadow(value[1], key, 'dark')
21
- }
22
- }
23
-
24
- if (isObject(value)) {
25
- const obj = {}
26
- for (const variant in value) {
27
- obj[variant] = setShadow(
28
- value[variant],
29
- key,
30
- variant.startsWith('@') ? variant.slice(1) : variant
31
- )
32
- }
33
- return obj
34
- }
35
-
36
- if (isString(value) && !CSS_NATIVE_COLOR_REGEX.test(value)) {
37
- // Split multiple shadows by commas (CSS standard), respecting parentheses
38
- value = splitTopLevelCommas(value).map(shadow => {
39
- shadow = shadow.trim()
40
- // Each shadow: space-separated tokens
41
- return shadow.split(/\s+/).map(v => {
42
- v = v.trim()
43
- if (!v) return ''
44
- if (v.startsWith('--')) return `var(${v})`
45
- const color = getColor(v)
46
- if (isResolvedColor(color)) return color
47
- if (/^\d/.test(v) || v === '0' || v.includes('px') || v.slice(-2) === 'em') return v
48
- if (v === 'inset' || v === 'none') return v
49
- const spacing = getSpacingByKey(v, 'shadow')
50
- if (spacing && spacing.shadow) return spacing.shadow
51
- return v
52
- }).join(' ')
53
- }).join(', ')
54
- }
55
-
56
- const vp = CONFIG.varPrefix ? CONFIG.varPrefix + '-' : ''
57
- const CSSVar = `--${vp}shadow-${key}` + (suffix ? `-${suffix}` : '')
58
-
59
- if (CONFIG.useVariable) { CONFIG.cssVars[CSSVar] = value }
60
-
61
- return {
62
- var: CSSVar,
63
- value
64
- }
65
- }
66
-
67
- export const getShadow = (value, globalTheme) => {
68
- const CONFIG = getActiveConfig()
69
- if (!globalTheme) globalTheme = CONFIG.globalTheme
70
- if (!isString(value)) {
71
- if (CONFIG.verbose) console.warn(value, '- type for color is not valid')
72
- return
73
- }
74
-
75
- if (isCSSVar(value)) return `var(${value})`
76
-
77
- const [name] = isArray(value) ? value : value.split(' ')
78
-
79
- const SHADOW = CONFIG.shadow
80
- const val = SHADOW[name]
81
- const isObj = isObject(val)
82
-
83
- if (!val) {
84
- if (CONFIG.verbose) console.warn('Can\'t find color ', name)
85
- return value
86
- }
87
-
88
- if (globalTheme) {
89
- if (val[globalTheme]) return val[globalTheme].value
90
- else if (CONFIG.verbose) console.warn(value, ' - does not have ', globalTheme)
91
- }
92
-
93
- if (isObj && val.value) return val.value
94
-
95
- if (isObj) {
96
- const obj = {}
97
- for (const mediaName in val) {
98
- const query = CONFIG.media[mediaName.slice(1)]
99
- const media = '@media ' + (query === 'print' ? `${query}` : `screen and ${query}`)
100
- obj[media] = val.value
101
- }
102
- return obj
103
- }
104
-
105
- if (CONFIG.verbose) console.warn('Can\'t find color', value)
106
- return value
107
- }
@@ -1,152 +0,0 @@
1
- 'use strict'
2
-
3
- import { arrayzeValue } from '@symbo.ls/utils'
4
- import { isArray, isString, merge } from '@symbo.ls/utils'
5
-
6
- import { getActiveConfig } from '../factory.js'
7
- import {
8
- CSS_UNITS,
9
- applyMediaSequenceVars,
10
- applySequenceVars,
11
- generateSequence,
12
- getFnPrefixAndValue,
13
- getSequenceValuePropertyPair
14
- } from '../utils/index.js'
15
-
16
- const runThroughMedia = (FACTORY) => {
17
- for (const prop in FACTORY) {
18
- const mediaProps = FACTORY[prop]
19
-
20
- const isMediaName = prop.slice(0, 1) === '@'
21
- if (!isMediaName) continue
22
-
23
- const { type, base, ratio, range, subSequence, h1Matches, unit } = FACTORY
24
-
25
- merge(mediaProps, {
26
- type,
27
- base,
28
- ratio,
29
- range,
30
- subSequence,
31
- h1Matches,
32
- unit,
33
- sequence: {},
34
- scales: {},
35
- templates: {},
36
- vars: {}
37
- })
38
-
39
- generateSequence(mediaProps)
40
- applyMediaSequenceVars(FACTORY, prop)
41
- }
42
- }
43
-
44
- export const checkIfBoxSize = (propertyName) => {
45
- const prop = propertyName.toLowerCase()
46
- const includesWidth = prop.includes('width') || prop.includes('height')
47
- const includesBorder = prop.includes('border') || prop.includes('outline')
48
- return includesWidth && !includesBorder
49
- }
50
-
51
- export const applySpacingSequence = () => {
52
- const CONFIG = getActiveConfig()
53
- const { spacing: SPACING } = CONFIG
54
- generateSequence(SPACING)
55
- applySequenceVars(SPACING)
56
- runThroughMedia(SPACING)
57
- }
58
-
59
- const getSequence = (sequenceProps) => {
60
- const CONFIG = getActiveConfig()
61
- const { spacing: SPACING } = CONFIG
62
- if (!sequenceProps || !sequenceProps.sequence) return SPACING
63
- const hasGenerated = Object.keys(sequenceProps.sequence).length > 0
64
- return hasGenerated ? sequenceProps : generateSequence(sequenceProps)
65
- }
66
-
67
- export const getSpacingByKey = (
68
- value,
69
- propertyName = 'padding',
70
- sequenceProps,
71
- fnPrefix
72
- ) => {
73
- const sequence = getSequence(sequenceProps)
74
-
75
- if (isString(value)) {
76
- if (!fnPrefix && value.includes('(')) {
77
- const fnArray = getFnPrefixAndValue(value)
78
- fnPrefix = fnArray[0]
79
- value = fnArray[1]
80
- }
81
- }
82
-
83
- const stack = fnPrefix ? [value] : arrayzeValue(value)
84
- if (!isArray(stack)) return
85
-
86
- if (stack.length > 1) {
87
- let suffix = ''
88
- if (propertyName === 'borderWidth') {
89
- propertyName = 'border'
90
- suffix = 'Width'
91
- }
92
-
93
- const directions = {
94
- 2: ['Block', 'Inline'],
95
- 3: ['BlockStart', 'Inline', 'BlockEnd'],
96
- 4: ['BlockStart', 'InlineEnd', 'BlockEnd', 'InlineStart']
97
- }
98
-
99
- const wrapSequenceValueByDirection = (direction, i) =>
100
- getSequenceValuePropertyPair(
101
- stack[i],
102
- propertyName + direction + suffix,
103
- sequence,
104
- fnPrefix
105
- )
106
-
107
- return directions[stack.length].map((dir, key) =>
108
- wrapSequenceValueByDirection(dir, key)
109
- )
110
- }
111
-
112
- return getSequenceValuePropertyPair(value, propertyName, sequence, fnPrefix)
113
- }
114
-
115
- export const getSpacingBasedOnRatio = (props, propertyName, val, fnPrefix) => {
116
- const CONFIG = getActiveConfig()
117
- const { spacing: SPACING } = CONFIG
118
-
119
- let value = val || props[propertyName]
120
-
121
- if (!fnPrefix && isString(value) && value.includes('(')) {
122
- const fnArr = getFnPrefixAndValue(value)
123
- fnPrefix = fnArr[0]
124
- value = fnArr[1]
125
- }
126
-
127
- if (props.spacingRatio) {
128
- const sequenceProps = applyCustomSequence(props)
129
- return getSpacingByKey(value, propertyName, sequenceProps, fnPrefix)
130
- }
131
-
132
- return getSpacingByKey(value, propertyName, SPACING, fnPrefix)
133
- }
134
-
135
- export const splitSpacedValue = (val) => {
136
- const addDefault = (v) => {
137
- const isSymbol = ['+', '-', '*', '/'].includes(v)
138
- const hasUnits = CSS_UNITS.some((unit) => val.includes(unit))
139
- if (isSymbol || hasUnits) return v
140
- const isSingleLetter = v.length < 3 && /[A-Z]/.test(v)
141
- if (isSingleLetter) return v + '_default'
142
- return v
143
- }
144
- return val
145
- .split(',')
146
- .map((v) => v.trim())
147
- .map(addDefault)
148
- .join(',')
149
- .split(' ')
150
- .map(addDefault)
151
- .join(' ')
152
- }
package/src/system/svg.js DELETED
@@ -1,132 +0,0 @@
1
- 'use strict'
2
-
3
- import { document } from '@symbo.ls/utils'
4
- import { generateSprite, convertSvgToSymbol } from '../utils/index.js'
5
- import { getActiveConfig } from '../factory.js'
6
-
7
- const DEF_OPTIONS = {
8
- document
9
- }
10
-
11
- export const setSVG = (val, key) => {
12
- const CONFIG = getActiveConfig()
13
- if (!val) {
14
- if (CONFIG.verbose) console.warn('setSVG: val is not defined', key)
15
- return
16
- }
17
- if (CONFIG.useSvgSprite) {
18
- return convertSvgToSymbol(key, val)
19
- } return val
20
- }
21
-
22
- export const appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
23
- const CONFIG = getActiveConfig()
24
-
25
- const lib = Object.keys(LIBRARY).length ? {} : CONFIG.svg
26
- for (const key in LIBRARY) lib[key] = LIBRARY[key]
27
-
28
- appendSVG(lib, options)
29
- }
30
-
31
- export const setSvgIcon = (val, key) => {
32
- const CONFIG = getActiveConfig()
33
- if (CONFIG.useIconSprite && !CONFIG.semanticIcons?.[key]) {
34
- return setSVG(val, key)
35
- } return val
36
- }
37
-
38
- export const appendSvgIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
39
- const CONFIG = getActiveConfig()
40
-
41
- const lib = Object.keys(LIBRARY).length ? {} : CONFIG.icons
42
- for (const key in LIBRARY) lib[key] = LIBRARY[key]
43
-
44
- appendSVG(lib, options)
45
- }
46
-
47
- const createSVGSpriteElement = (doc, options = { isRoot: true }) => {
48
- if (!doc || !doc.createElementNS) return
49
- const svgElem = doc.createElementNS('http://www.w3.org/2000/svg', 'svg')
50
- if (options.isRoot) {
51
- svgElem.setAttribute('aria-hidden', 'true')
52
- svgElem.setAttribute('width', '0')
53
- svgElem.setAttribute('height', '0')
54
- svgElem.setAttribute('style', 'position:absolute')
55
- svgElem.setAttribute('id', 'svgSprite')
56
- }
57
- return svgElem
58
- }
59
-
60
- // Parse SVG sprite string using XML parser to correctly handle self-closing tags.
61
- // HTML parser treats <line .../> as <line ...> (ignores /), nesting siblings.
62
- const parseSVGSprite = (doc, svgString) => {
63
- const DOMParserCtor = (typeof DOMParser !== 'undefined') ? DOMParser : null
64
- if (DOMParserCtor) {
65
- const wrapped = `<svg xmlns="http://www.w3.org/2000/svg">${svgString}</svg>`
66
- const parser = new DOMParserCtor()
67
- const parsed = parser.parseFromString(wrapped, 'image/svg+xml')
68
- // Check for parse errors — if the SVG is malformed, fall back to innerHTML
69
- if (parsed.querySelector('parsererror')) return null
70
- return parsed.documentElement
71
- }
72
- return null
73
- }
74
-
75
- // Move all children from a parsed SVG element into a target element.
76
- // Uses importNode to cross document boundaries, then removes the source child
77
- // so the loop terminates.
78
- const moveChildren = (doc, from, to) => {
79
- while (from.firstChild) {
80
- const child = from.firstChild
81
- to.appendChild(doc.importNode(child, true))
82
- child.remove()
83
- }
84
- }
85
-
86
- const appendSVG = (lib, options = DEF_OPTIONS) => {
87
- const CONFIG = getActiveConfig()
88
- const doc = options.document || document
89
-
90
- if (!doc || !doc.documentElement) {
91
- if (CONFIG.verbose) {
92
- console.warn('To append SVG sprites it should be run in browser environment')
93
- }
94
- return generateSprite(lib)
95
- }
96
-
97
- const exists = doc.querySelector('#svgSprite')
98
- const SVGsprite = generateSprite(lib)
99
-
100
- const spriteHtml = `<svg aria-hidden="true" width="0" height="0" style="position:absolute" id="svgSprite">${SVGsprite}</svg>`
101
-
102
- const parsed = parseSVGSprite(doc, SVGsprite)
103
-
104
- if (exists) {
105
- if (parsed) {
106
- moveChildren(doc, parsed, exists)
107
- } else if (doc.body.insertAdjacentHTML) {
108
- exists.insertAdjacentHTML('beforeend', SVGsprite)
109
- } else {
110
- const tempSVG = createSVGSpriteElement(doc, { isRoot: false })
111
- tempSVG.innerHTML = SVGsprite
112
- exists.append(...tempSVG.children)
113
- }
114
- } else {
115
- if (parsed) {
116
- const svgSpriteDOM = createSVGSpriteElement(doc)
117
- if (svgSpriteDOM && svgSpriteDOM.nodeType) {
118
- moveChildren(doc, parsed, svgSpriteDOM)
119
- doc.body.prepend(svgSpriteDOM)
120
- }
121
- } else if (doc.body.insertAdjacentHTML) {
122
- doc.body.insertAdjacentHTML('afterbegin', spriteHtml)
123
- } else {
124
- const svgSpriteDOM = createSVGSpriteElement(doc)
125
- if (svgSpriteDOM && svgSpriteDOM.nodeType) {
126
- svgSpriteDOM.innerHTML = SVGsprite
127
- doc.body.prepend(svgSpriteDOM)
128
- }
129
- }
130
- }
131
-
132
- }