@symbo.ls/scratch 3.2.3 → 3.2.7
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/factory.js +23 -494
- package/dist/cjs/index.js +11 -2742
- package/dist/cjs/set.js +66 -2060
- package/dist/esm/factory.js +43 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/set.js +148 -0
- package/dist/iife/index.js +2580 -0
- package/package.json +25 -15
- package/src/set.js +22 -7
- package/src/system/color.js +48 -11
- package/src/system/font.js +19 -5
- package/src/system/reset.js +12 -3
- package/src/system/shadow.js +20 -13
- package/src/system/spacing.js +63 -56
- package/src/system/theme.js +4 -3
- package/src/system/timing.js +1 -1
- package/src/transforms/index.js +212 -95
- package/src/utils/color.js +79 -0
- package/src/utils/font.js +54 -14
- package/src/utils/sequence.js +94 -39
- package/src/utils/sprite.js +2 -2
- package/src/utils/unit.js +69 -2
- package/src/utils/var.js +1 -2
- package/dist/cjs/defaultConfig/animation.js +0 -26
- package/dist/cjs/defaultConfig/cases.js +0 -26
- package/dist/cjs/defaultConfig/class.js +0 -27
- package/dist/cjs/defaultConfig/color.js +0 -28
- package/dist/cjs/defaultConfig/document.js +0 -26
- package/dist/cjs/defaultConfig/font-family.js +0 -34
- package/dist/cjs/defaultConfig/font.js +0 -26
- package/dist/cjs/defaultConfig/grid.js +0 -27
- package/dist/cjs/defaultConfig/icons.js +0 -28
- package/dist/cjs/defaultConfig/index.js +0 -222
- package/dist/cjs/defaultConfig/media.js +0 -31
- package/dist/cjs/defaultConfig/responsive.js +0 -52
- package/dist/cjs/defaultConfig/sequence.js +0 -51
- package/dist/cjs/defaultConfig/shadow.js +0 -26
- package/dist/cjs/defaultConfig/spacing.js +0 -87
- package/dist/cjs/defaultConfig/svg.js +0 -28
- package/dist/cjs/defaultConfig/templates.js +0 -26
- package/dist/cjs/defaultConfig/theme.js +0 -26
- package/dist/cjs/defaultConfig/timing.js +0 -68
- package/dist/cjs/defaultConfig/typography.js +0 -72
- package/dist/cjs/defaultConfig/unit.js +0 -28
- package/dist/cjs/package.json +0 -4
- package/dist/cjs/system/color.js +0 -1175
- package/dist/cjs/system/document.js +0 -987
- package/dist/cjs/system/font.js +0 -1009
- package/dist/cjs/system/index.js +0 -2227
- package/dist/cjs/system/reset.js +0 -1099
- package/dist/cjs/system/shadow.js +0 -1384
- package/dist/cjs/system/spacing.js +0 -1338
- package/dist/cjs/system/svg.js +0 -1086
- package/dist/cjs/system/theme.js +0 -1276
- package/dist/cjs/system/timing.js +0 -1213
- package/dist/cjs/system/typography.js +0 -1311
- package/dist/cjs/tests/index.js +0 -30
- package/dist/cjs/transforms/index.js +0 -1613
- package/dist/cjs/utils/color.js +0 -333
- package/dist/cjs/utils/font.js +0 -69
- package/dist/cjs/utils/index.js +0 -1548
- package/dist/cjs/utils/sequence.js +0 -1198
- package/dist/cjs/utils/sprite.js +0 -579
- package/dist/cjs/utils/theme.js +0 -31
- package/dist/cjs/utils/unit.js +0 -28
- package/dist/cjs/utils/var.js +0 -1040
package/package.json
CHANGED
|
@@ -2,32 +2,42 @@
|
|
|
2
2
|
"name": "@symbo.ls/scratch",
|
|
3
3
|
"description": "Φ / CSS framework and methodology.",
|
|
4
4
|
"author": "symbo.ls",
|
|
5
|
-
"version": "3.2.
|
|
5
|
+
"version": "3.2.7",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"dist",
|
|
8
|
+
"*.js",
|
|
9
|
+
"src"
|
|
9
10
|
],
|
|
10
11
|
"repository": "https://github.com/symbo-ls/smbls",
|
|
11
12
|
"type": "module",
|
|
12
|
-
"module": "
|
|
13
|
-
"unpkg": "dist/iife/index.js",
|
|
14
|
-
"jsdelivr": "dist/iife/index.js",
|
|
15
|
-
"main": "
|
|
16
|
-
"exports":
|
|
13
|
+
"module": "./dist/esm/index.js",
|
|
14
|
+
"unpkg": "./dist/iife/index.js",
|
|
15
|
+
"jsdelivr": "./dist/iife/index.js",
|
|
16
|
+
"main": "./dist/cjs/index.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/esm/index.js",
|
|
20
|
+
"require": "./dist/cjs/index.js",
|
|
21
|
+
"browser": "./dist/iife/index.js",
|
|
22
|
+
"default": "./dist/esm/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
17
25
|
"source": "src/index.js",
|
|
18
26
|
"publishConfig": {},
|
|
19
27
|
"scripts": {
|
|
20
28
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
21
|
-
"build:esm": "
|
|
22
|
-
"build:cjs": "
|
|
23
|
-
"build:iife": "
|
|
24
|
-
"build": "
|
|
25
|
-
"prepublish": "
|
|
29
|
+
"build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild src/*.js --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
30
|
+
"build:cjs": "cross-env NODE_ENV=$NODE_ENV esbuild src/*.js --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
31
|
+
"build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild src/index.js --bundle --target=es2020 --format=iife --global-name=SmblsScratch --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
32
|
+
"build": "node ../../build/build.js",
|
|
33
|
+
"prepublish": "npm run build && npm run copy:package:cjs"
|
|
26
34
|
},
|
|
27
35
|
"dependencies": {
|
|
28
36
|
"@domql/utils": "^3.2.3",
|
|
29
|
-
"@symbo.ls/utils": "^3.2.3",
|
|
37
|
+
"@symbo.ls/smbls-utils": "^3.2.3",
|
|
30
38
|
"color-contrast-checker": "^1.5.0"
|
|
31
39
|
},
|
|
32
|
-
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681"
|
|
40
|
+
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
41
|
+
"browser": "./dist/iife/index.js",
|
|
42
|
+
"sideEffects": false
|
|
33
43
|
}
|
package/src/set.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
setShadow
|
|
18
18
|
} from './system'
|
|
19
19
|
|
|
20
|
-
import { isFunction } from '@domql/utils'
|
|
20
|
+
import { isFunction, deepMerge } from '@domql/utils'
|
|
21
21
|
|
|
22
22
|
const setCases = (val, key) => {
|
|
23
23
|
if (isFunction(val)) return val()
|
|
@@ -129,22 +129,37 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
|
|
|
129
129
|
if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {}
|
|
130
130
|
|
|
131
131
|
const keys = Object.keys(config)
|
|
132
|
-
|
|
132
|
+
const keySet = new Set(keys)
|
|
133
|
+
|
|
134
|
+
// Pre-merge: fold UPPERCASE default keys into lowercase project keys
|
|
135
|
+
keys.forEach(key => {
|
|
136
|
+
const lower = key.toLowerCase()
|
|
137
|
+
if (lower !== key && keySet.has(lower)) {
|
|
138
|
+
deepMerge(config[lower], config[key])
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
// Process only lowercase keys (skip UPPERCASE when lowercase equivalent exists)
|
|
143
|
+
keys.map(key => {
|
|
144
|
+
const lower = key.toLowerCase()
|
|
145
|
+
if (lower !== key && keySet.has(lower)) return
|
|
146
|
+
return setEach(key, config[key])
|
|
147
|
+
})
|
|
133
148
|
|
|
134
149
|
// apply generic configs
|
|
135
|
-
if (config.TYPOGRAPHY) {
|
|
150
|
+
if (config.TYPOGRAPHY || config.typography) {
|
|
136
151
|
try { applyTypographySequence() } catch (e) {
|
|
137
152
|
if (CONFIG.verbose) console.warn('Error applying typography sequence', e)
|
|
138
153
|
}
|
|
139
154
|
}
|
|
140
|
-
if (config.SPACING) {
|
|
155
|
+
if (config.SPACING || config.spacing) {
|
|
141
156
|
try { applySpacingSequence() } catch (e) {
|
|
142
|
-
if (CONFIG.verbose) console.warn('Error applying
|
|
157
|
+
if (CONFIG.verbose) console.warn('Error applying spacing sequence', e)
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
|
-
if (config.TIMING) {
|
|
160
|
+
if (config.TIMING || config.timing) {
|
|
146
161
|
try { applyTimingSequence() } catch (e) {
|
|
147
|
-
if (CONFIG.verbose) console.warn('Error applying
|
|
162
|
+
if (CONFIG.verbose) console.warn('Error applying timing sequence', e)
|
|
148
163
|
}
|
|
149
164
|
}
|
|
150
165
|
applyDocument()
|
package/src/system/color.js
CHANGED
|
@@ -5,7 +5,9 @@ import { getActiveConfig } from '../factory.js'
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
colorStringToRgbaArray,
|
|
8
|
-
getRgbTone
|
|
8
|
+
getRgbTone,
|
|
9
|
+
isCSSVar,
|
|
10
|
+
parseColorToken
|
|
9
11
|
} from '../utils'
|
|
10
12
|
|
|
11
13
|
export const getColor = (value, key, config) => {
|
|
@@ -15,10 +17,23 @@ export const getColor = (value, key, config) => {
|
|
|
15
17
|
return
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
if (value
|
|
20
|
+
if (isCSSVar(value)) return `var(${value})`
|
|
19
21
|
|
|
20
22
|
if (key && value[key]) value = value[key]
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
let name, alpha, tone
|
|
25
|
+
if (isArray(value)) {
|
|
26
|
+
[name, alpha, tone] = value
|
|
27
|
+
} else {
|
|
28
|
+
const parsed = parseColorToken(value)
|
|
29
|
+
if (!parsed) return value
|
|
30
|
+
if (parsed.passthrough) return parsed.passthrough
|
|
31
|
+
if (parsed.cssVar) return `var(${parsed.cssVar})`
|
|
32
|
+
name = parsed.name
|
|
33
|
+
alpha = parsed.alpha
|
|
34
|
+
tone = parsed.tone
|
|
35
|
+
}
|
|
36
|
+
|
|
22
37
|
const { COLOR, GRADIENT } = CONFIG
|
|
23
38
|
|
|
24
39
|
let val = (COLOR[name] || GRADIENT[name])
|
|
@@ -47,20 +62,30 @@ export const getColor = (value, key, config) => {
|
|
|
47
62
|
if (val[tone]) rgb = val[tone].rgb
|
|
48
63
|
|
|
49
64
|
if (alpha) return `rgba(${rgb}, ${alpha})`
|
|
65
|
+
if (tone) return `rgba(${rgb}, 1)`
|
|
50
66
|
return CONFIG.useVariable ? `var(${val.var})` : `rgb(${rgb})`
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
export const getMediaColor = (value, globalTheme, config) => {
|
|
54
70
|
const CONFIG = config || getActiveConfig()
|
|
55
|
-
if (!globalTheme) globalTheme = CONFIG.globalTheme
|
|
71
|
+
if (!globalTheme) globalTheme = CONFIG.globalTheme === 'auto' ? null : CONFIG.globalTheme
|
|
56
72
|
if (!isString(value)) {
|
|
57
73
|
if (CONFIG.verbose) console.warn(value, '- type for color is not valid')
|
|
58
74
|
return
|
|
59
75
|
}
|
|
60
76
|
|
|
61
|
-
if (value
|
|
77
|
+
if (isCSSVar(value)) return `var(${value})`
|
|
62
78
|
|
|
63
|
-
|
|
79
|
+
let name
|
|
80
|
+
if (isArray(value)) {
|
|
81
|
+
name = value[0]
|
|
82
|
+
} else {
|
|
83
|
+
const parsed = parseColorToken(value)
|
|
84
|
+
if (!parsed) return value
|
|
85
|
+
if (parsed.passthrough) return parsed.passthrough
|
|
86
|
+
if (parsed.cssVar) return `var(${parsed.cssVar})`
|
|
87
|
+
name = parsed.name
|
|
88
|
+
}
|
|
64
89
|
|
|
65
90
|
const { COLOR, GRADIENT } = CONFIG
|
|
66
91
|
const val = COLOR[name] || GRADIENT[name]
|
|
@@ -87,15 +112,27 @@ export const getMediaColor = (value, globalTheme, config) => {
|
|
|
87
112
|
export const setColor = (val, key, suffix) => {
|
|
88
113
|
const CONFIG = getActiveConfig()
|
|
89
114
|
|
|
90
|
-
if (isString(val) && val
|
|
91
|
-
|
|
115
|
+
if (isString(val) && isCSSVar(val)) {
|
|
116
|
+
const rawRef = val.slice(2)
|
|
117
|
+
val = getColor(rawRef)
|
|
92
118
|
if (!(
|
|
93
119
|
val.includes('rgb') ||
|
|
94
120
|
val.includes('var') ||
|
|
95
121
|
val.includes('#')
|
|
96
122
|
)) {
|
|
97
|
-
|
|
98
|
-
|
|
123
|
+
// Handle space-separated format: '--colorName alpha' (e.g. '--gray1 1')
|
|
124
|
+
const parts = rawRef.split(' ')
|
|
125
|
+
const refColor = CONFIG.COLOR[parts[0]]
|
|
126
|
+
if (refColor && refColor.value) {
|
|
127
|
+
if (parts[1] !== undefined) {
|
|
128
|
+
val = `rgba(${refColor.rgb}, ${parts[1]})`
|
|
129
|
+
} else {
|
|
130
|
+
val = refColor.value
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
if (CONFIG.verbose) console.warn(val, '- referred but does not exist')
|
|
134
|
+
val = parts[0]
|
|
135
|
+
}
|
|
99
136
|
}
|
|
100
137
|
}
|
|
101
138
|
|
|
@@ -137,7 +174,7 @@ export const setColor = (val, key, suffix) => {
|
|
|
137
174
|
|
|
138
175
|
export const setGradient = (val, key, suffix) => {
|
|
139
176
|
const CONFIG = getActiveConfig()
|
|
140
|
-
if (isString(val) && val
|
|
177
|
+
if (isString(val) && isCSSVar(val)) val = getColor(val.slice(2))
|
|
141
178
|
|
|
142
179
|
if (isArray(val)) {
|
|
143
180
|
return {
|
package/src/system/font.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { isObject, isArray } from '@domql/utils'
|
|
4
|
-
import { arrayzeValue } from '@symbo.ls/utils'
|
|
4
|
+
import { arrayzeValue } from '@symbo.ls/smbls-utils'
|
|
5
5
|
import { getActiveConfig } from '../factory.js'
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
getDefaultOrFirstKey,
|
|
9
9
|
getFontFaceEach,
|
|
10
|
-
|
|
10
|
+
isGoogleFontsUrl,
|
|
11
|
+
setCustomFontMedia,
|
|
12
|
+
setFontImport
|
|
11
13
|
} from '../utils'
|
|
12
14
|
|
|
13
15
|
export const setFont = (val, key) => {
|
|
@@ -15,9 +17,21 @@ export const setFont = (val, key) => {
|
|
|
15
17
|
|
|
16
18
|
if (!val || (isArray(val) && !val[0])) return
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
let fontFace
|
|
21
|
+
if (val.isVariable) {
|
|
22
|
+
if (isGoogleFontsUrl(val.url)) {
|
|
23
|
+
fontFace = setFontImport(val.url)
|
|
24
|
+
} else {
|
|
25
|
+
fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
|
|
26
|
+
fontStretch: val.fontStretch,
|
|
27
|
+
fontDisplay: val.fontDisplay || 'swap'
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
} else if (val[0]) {
|
|
31
|
+
fontFace = getFontFaceEach(key, val)
|
|
32
|
+
} else {
|
|
33
|
+
fontFace = setCustomFontMedia(key, val.url)
|
|
34
|
+
}
|
|
21
35
|
|
|
22
36
|
return { var: CSSvar, value: val, fontFace }
|
|
23
37
|
}
|
package/src/system/reset.js
CHANGED
|
@@ -15,7 +15,9 @@ export const applyReset = (reset = {}) => {
|
|
|
15
15
|
const configTemplates = TYPOGRAPHY.templates
|
|
16
16
|
|
|
17
17
|
configReset.body = {
|
|
18
|
-
...(CONFIG.useDocumentTheme
|
|
18
|
+
...(CONFIG.useDocumentTheme
|
|
19
|
+
? getMediaTheme('document', `@${CONFIG.globalTheme}`)
|
|
20
|
+
: {}),
|
|
19
21
|
...configTemplates.body
|
|
20
22
|
}
|
|
21
23
|
configReset.h1 = configTemplates.h1
|
|
@@ -27,7 +29,9 @@ export const applyReset = (reset = {}) => {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const { body, ...templates } = TYPOGRAPHY.templates
|
|
30
|
-
const globalTheme =
|
|
32
|
+
const globalTheme = CONFIG.useDocumentTheme
|
|
33
|
+
? getMediaTheme('document', `@${CONFIG.globalTheme}`)
|
|
34
|
+
: {}
|
|
31
35
|
if (RESET.html) overwriteDeep(RESET.html, globalTheme)
|
|
32
36
|
|
|
33
37
|
return deepMerge(merge(RESET, reset), {
|
|
@@ -56,12 +60,17 @@ export const applyReset = (reset = {}) => {
|
|
|
56
60
|
margin: 0,
|
|
57
61
|
fontFamily: DOCUMENT.fontFamily,
|
|
58
62
|
|
|
59
|
-
fontSize:
|
|
63
|
+
fontSize:
|
|
64
|
+
TYPOGRAPHY.base / TYPOGRAPHY.browserDefault + CONFIG.UNIT.default,
|
|
60
65
|
|
|
61
66
|
...templates,
|
|
62
67
|
...body
|
|
63
68
|
},
|
|
64
69
|
|
|
70
|
+
a: {
|
|
71
|
+
color: 'currentColor'
|
|
72
|
+
},
|
|
73
|
+
|
|
65
74
|
// form elements
|
|
66
75
|
fieldset: {
|
|
67
76
|
border: 0,
|
package/src/system/shadow.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { getActiveConfig } from '../factory.js'
|
|
4
4
|
import { getColor } from './color.js'
|
|
5
5
|
import { getSpacingByKey } from './spacing.js'
|
|
6
|
+
import { isResolvedColor, isCSSVar, splitTopLevelCommas, CSS_NATIVE_COLOR_REGEX } from '../utils/color.js'
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
isObject,
|
|
@@ -12,8 +13,6 @@ import {
|
|
|
12
13
|
|
|
13
14
|
export const setShadow = (value, key, suffix, prefers) => {
|
|
14
15
|
const CONFIG = getActiveConfig()
|
|
15
|
-
// const { CSS_VARS } = CONFIG
|
|
16
|
-
// const theme = { valueue: value }
|
|
17
16
|
|
|
18
17
|
if (isArray(value)) {
|
|
19
18
|
return {
|
|
@@ -34,16 +33,24 @@ export const setShadow = (value, key, suffix, prefers) => {
|
|
|
34
33
|
return obj
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
if (isString(value) &&
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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(', ')
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
const CSSVar = `--shadow-${key}` + (suffix ? `-${suffix}` : '')
|
|
@@ -64,7 +71,7 @@ export const getShadow = (value, globalTheme) => {
|
|
|
64
71
|
return
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
if (value
|
|
74
|
+
if (isCSSVar(value)) return `var(${value})`
|
|
68
75
|
|
|
69
76
|
const [name] = isArray(value) ? value : value.split(' ')
|
|
70
77
|
|
package/src/system/spacing.js
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { arrayzeValue } from '@symbo.ls/utils'
|
|
3
|
+
import { arrayzeValue } from '@symbo.ls/smbls-utils'
|
|
4
4
|
import { isArray, isString, merge } from '@domql/utils'
|
|
5
5
|
|
|
6
6
|
import { getActiveConfig } from '../factory.js'
|
|
7
7
|
import {
|
|
8
|
+
CSS_UNITS,
|
|
8
9
|
applyMediaSequenceVars,
|
|
9
10
|
applySequenceVars,
|
|
10
11
|
generateSequence,
|
|
12
|
+
getFnPrefixAndValue,
|
|
11
13
|
getSequenceValuePropertyPair
|
|
12
14
|
} from '../utils'
|
|
13
15
|
|
|
14
|
-
const runThroughMedia = FACTORY => {
|
|
16
|
+
const runThroughMedia = (FACTORY) => {
|
|
15
17
|
for (const prop in FACTORY) {
|
|
16
18
|
const mediaProps = FACTORY[prop]
|
|
17
19
|
|
|
18
20
|
const isMediaName = prop.slice(0, 1) === '@'
|
|
19
21
|
if (!isMediaName) continue
|
|
20
22
|
|
|
21
|
-
const {
|
|
22
|
-
type,
|
|
23
|
-
base,
|
|
24
|
-
ratio,
|
|
25
|
-
range,
|
|
26
|
-
subSequence,
|
|
27
|
-
h1Matches,
|
|
28
|
-
unit
|
|
29
|
-
} = FACTORY
|
|
23
|
+
const { type, base, ratio, range, subSequence, h1Matches, unit } = FACTORY
|
|
30
24
|
|
|
31
25
|
merge(mediaProps, {
|
|
32
26
|
type,
|
|
@@ -47,6 +41,13 @@ const runThroughMedia = FACTORY => {
|
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
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
|
+
|
|
50
51
|
export const applySpacingSequence = () => {
|
|
51
52
|
const CONFIG = getActiveConfig()
|
|
52
53
|
const { SPACING } = CONFIG
|
|
@@ -58,7 +59,7 @@ export const applySpacingSequence = () => {
|
|
|
58
59
|
const getSequence = (sequenceProps) => {
|
|
59
60
|
const CONFIG = getActiveConfig()
|
|
60
61
|
const { SPACING } = CONFIG
|
|
61
|
-
if (!sequenceProps) return SPACING
|
|
62
|
+
if (!sequenceProps || !sequenceProps.sequence) return SPACING
|
|
62
63
|
const hasGenerated = Object.keys(sequenceProps.sequence).length > 0
|
|
63
64
|
return hasGenerated ? sequenceProps : generateSequence(sequenceProps)
|
|
64
65
|
}
|
|
@@ -66,15 +67,20 @@ const getSequence = (sequenceProps) => {
|
|
|
66
67
|
export const getSpacingByKey = (
|
|
67
68
|
value,
|
|
68
69
|
propertyName = 'padding',
|
|
69
|
-
sequenceProps
|
|
70
|
+
sequenceProps,
|
|
71
|
+
fnPrefix
|
|
70
72
|
) => {
|
|
71
73
|
const sequence = getSequence(sequenceProps)
|
|
72
74
|
|
|
73
|
-
if (isString(value)
|
|
74
|
-
|
|
75
|
+
if (isString(value)) {
|
|
76
|
+
if (!fnPrefix && value.includes('(')) {
|
|
77
|
+
const fnArray = getFnPrefixAndValue(value)
|
|
78
|
+
fnPrefix = fnArray[0]
|
|
79
|
+
value = fnArray[1]
|
|
80
|
+
}
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
const stack = arrayzeValue(value)
|
|
83
|
+
const stack = fnPrefix ? [value] : arrayzeValue(value)
|
|
78
84
|
if (!isArray(stack)) return
|
|
79
85
|
|
|
80
86
|
if (stack.length > 1) {
|
|
@@ -90,56 +96,57 @@ export const getSpacingByKey = (
|
|
|
90
96
|
4: ['BlockStart', 'InlineEnd', 'BlockEnd', 'InlineStart']
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
const wrapSequenceValueByDirection = (direction, i) =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
const wrapSequenceValueByDirection = (direction, i) =>
|
|
100
|
+
getSequenceValuePropertyPair(
|
|
101
|
+
stack[i],
|
|
102
|
+
propertyName + direction + suffix,
|
|
103
|
+
sequence,
|
|
104
|
+
fnPrefix
|
|
105
|
+
)
|
|
98
106
|
|
|
99
|
-
return directions[stack.length].map((dir, key) =>
|
|
107
|
+
return directions[stack.length].map((dir, key) =>
|
|
108
|
+
wrapSequenceValueByDirection(dir, key)
|
|
109
|
+
)
|
|
100
110
|
}
|
|
101
111
|
|
|
102
|
-
return getSequenceValuePropertyPair(
|
|
103
|
-
value,
|
|
104
|
-
propertyName,
|
|
105
|
-
sequence
|
|
106
|
-
)
|
|
112
|
+
return getSequenceValuePropertyPair(value, propertyName, sequence, fnPrefix)
|
|
107
113
|
}
|
|
108
114
|
|
|
109
|
-
export const getSpacingBasedOnRatio = (props, propertyName, val) => {
|
|
115
|
+
export const getSpacingBasedOnRatio = (props, propertyName, val, fnPrefix) => {
|
|
110
116
|
const CONFIG = getActiveConfig()
|
|
111
117
|
const { SPACING } = CONFIG
|
|
112
118
|
|
|
113
|
-
|
|
114
|
-
const value = val || props[propertyName]
|
|
115
|
-
|
|
116
|
-
if (spacingRatio) {
|
|
117
|
-
let sequenceProps = SPACING[spacingRatio]
|
|
118
|
-
|
|
119
|
-
if (!sequenceProps) {
|
|
120
|
-
const { type, base, range, subSequence } = SPACING
|
|
121
|
-
|
|
122
|
-
sequenceProps = SPACING[spacingRatio] = merge({
|
|
123
|
-
ratio: spacingRatio,
|
|
124
|
-
type: type + '-' + spacingRatio,
|
|
125
|
-
unit,
|
|
126
|
-
sequence: {},
|
|
127
|
-
scales: {},
|
|
128
|
-
templates: {},
|
|
129
|
-
vars: {}
|
|
130
|
-
}, {
|
|
131
|
-
base,
|
|
132
|
-
range,
|
|
133
|
-
subSequence,
|
|
134
|
-
ratio: SPACING.ratio,
|
|
135
|
-
unit: SPACING.unit
|
|
136
|
-
})
|
|
137
|
-
}
|
|
119
|
+
let value = val || props[propertyName]
|
|
138
120
|
|
|
139
|
-
|
|
121
|
+
if (!fnPrefix && isString(value) && value.includes('(')) {
|
|
122
|
+
const fnArr = getFnPrefixAndValue(value)
|
|
123
|
+
fnPrefix = fnArr[0]
|
|
124
|
+
value = fnArr[1]
|
|
125
|
+
}
|
|
140
126
|
|
|
141
|
-
|
|
127
|
+
if (props.spacingRatio) {
|
|
128
|
+
const sequenceProps = applyCustomSequence(props)
|
|
129
|
+
return getSpacingByKey(value, propertyName, sequenceProps, fnPrefix)
|
|
142
130
|
}
|
|
143
131
|
|
|
144
|
-
return getSpacingByKey(value, propertyName)
|
|
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(' ')
|
|
145
152
|
}
|
package/src/system/theme.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { getColor } from './color'
|
|
4
4
|
import { getActiveConfig } from '../factory.js'
|
|
5
|
+
import { isCSSVar } from '../utils/color.js'
|
|
5
6
|
|
|
6
7
|
import {
|
|
7
8
|
isObject,
|
|
@@ -174,7 +175,7 @@ export const setMediaTheme = (val, key, suffix, prefers) => {
|
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
if (isString(val) && val
|
|
178
|
+
if (isString(val) && isCSSVar(val)) {
|
|
178
179
|
const { THEME } = CONFIG
|
|
179
180
|
const value = THEME[val.slice(2)]
|
|
180
181
|
const getReferenced = getMediaTheme(value, prefers)
|
|
@@ -215,7 +216,7 @@ const findModifier = (val, modifier) => {
|
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
const checkForReference = (val, callback) => {
|
|
218
|
-
if (isString(val) && val
|
|
219
|
+
if (isString(val) && isCSSVar(val)) return getMediaTheme(val.slice(2))
|
|
219
220
|
return val
|
|
220
221
|
}
|
|
221
222
|
|
|
@@ -224,7 +225,7 @@ const checkThemeReference = (val) => checkForReference(val, checkThemeReference)
|
|
|
224
225
|
export const getMediaTheme = (value, modifier) => {
|
|
225
226
|
const activeConfig = getActiveConfig()
|
|
226
227
|
|
|
227
|
-
if (isString(value) && value
|
|
228
|
+
if (isString(value) && isCSSVar(value)) {
|
|
228
229
|
value = getMediaTheme(value.slice(2))
|
|
229
230
|
}
|
|
230
231
|
|