@symbo.ls/scratch 0.6.4 → 0.7.1
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/package.json +1 -1
- package/src/{config → defaultConfig}/cases.js +0 -0
- package/src/{config → defaultConfig}/color.js +0 -0
- package/src/{config → defaultConfig}/document.js +0 -0
- package/src/{config → defaultConfig}/font-family.js +0 -0
- package/src/{config → defaultConfig}/font.js +0 -0
- package/src/{config → defaultConfig}/icons.js +0 -0
- package/src/{config → defaultConfig}/index.js +0 -0
- package/src/{config → defaultConfig}/media.js +0 -0
- package/src/{config → defaultConfig}/responsive.js +0 -0
- package/src/{config → defaultConfig}/sequence.js +0 -0
- package/src/{config → defaultConfig}/spacing.js +0 -0
- package/src/{config → defaultConfig}/theme.js +0 -0
- package/src/{config → defaultConfig}/timing.js +0 -0
- package/src/{config → defaultConfig}/typography.js +0 -0
- package/src/{config → defaultConfig}/unit.js +0 -0
- package/src/factory.js +1 -1
- package/src/index.js +1 -1
- package/src/system/color.js +4 -2
- package/src/system/document.js +1 -1
- package/src/system/reset.js +1 -1
- package/src/system/spacing.js +71 -47
- package/src/system/theme.js +50 -6
- package/src/system/timing.js +7 -9
- package/src/system/typography.js +7 -9
- package/src/utils/object.js +1 -1
- package/src/utils/sequence.js +101 -69
- package/src/utils/var.js +14 -5
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/factory.js
CHANGED
package/src/index.js
CHANGED
package/src/system/color.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { MEDIA } from '../
|
|
3
|
+
import { MEDIA } from '../defaultConfig'
|
|
4
4
|
import { CONFIG, CSS_VARS } from '../factory' // eslint-disable-line
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -32,7 +32,7 @@ export const getColor = (value, key) => {
|
|
|
32
32
|
let val = (COLOR[name] || GRADIENT[name])
|
|
33
33
|
|
|
34
34
|
if (!val) {
|
|
35
|
-
if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn('Can\'t find color', name)
|
|
35
|
+
if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn('Can\'t find color ', name)
|
|
36
36
|
return value
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -72,6 +72,8 @@ export const getMediaColor = (value, param) => {
|
|
|
72
72
|
return
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
if (value.slice(0, 2) === '--') return { [param]: `var(${value})` }
|
|
76
|
+
|
|
75
77
|
const [name] = isArray(value) ? value : value.split(' ')
|
|
76
78
|
|
|
77
79
|
const { COLOR, GRADIENT } = CONFIG
|
package/src/system/document.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { DOCUMENT, FONT_FAMILY, THEME, TYPOGRAPHY } from '../
|
|
3
|
+
import { DOCUMENT, FONT_FAMILY, THEME, TYPOGRAPHY } from '../defaultConfig'
|
|
4
4
|
import { getDefaultOrFirstKey, merge } from '../utils'
|
|
5
5
|
|
|
6
6
|
export const applyDocument = () => merge(DOCUMENT, {
|
package/src/system/reset.js
CHANGED
package/src/system/spacing.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { SPACING } from '../
|
|
4
|
-
import { applySequenceVars,
|
|
3
|
+
import { SPACING } from '../defaultConfig'
|
|
4
|
+
import { applySequenceVars, arrayze, generateSequence, getSequenceValuePropertyPair, merge } from '../utils'
|
|
5
5
|
|
|
6
|
-
const runThroughMedia =
|
|
7
|
-
for (const prop in
|
|
8
|
-
const mediaProps =
|
|
6
|
+
const runThroughMedia = sequenceProps => {
|
|
7
|
+
for (const prop in sequenceProps) {
|
|
8
|
+
const mediaProps = sequenceProps[prop]
|
|
9
9
|
if (prop.slice(0, 1) === '@') {
|
|
10
|
-
const { type, base, ratio, range, subSequence, h1Matches, unit } =
|
|
10
|
+
const { type, base, ratio, range, subSequence, h1Matches, unit } = sequenceProps
|
|
11
11
|
|
|
12
12
|
merge(mediaProps, {
|
|
13
13
|
type,
|
|
@@ -37,57 +37,81 @@ export const applySpacingSequence = () => {
|
|
|
37
37
|
runThroughMedia(SPACING)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const getSequence = (
|
|
41
|
-
if (!
|
|
42
|
-
const hasGenerated = Object.keys(
|
|
43
|
-
return hasGenerated ?
|
|
40
|
+
const getSequence = (sequenceProps) => {
|
|
41
|
+
if (!sequenceProps) return SPACING
|
|
42
|
+
const hasGenerated = Object.keys(sequenceProps.sequence).length > 0
|
|
43
|
+
return hasGenerated ? sequenceProps : generateSequence(sequenceProps)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export const getSpacingByKey = (
|
|
47
|
-
|
|
46
|
+
export const getSpacingByKey = (
|
|
47
|
+
value,
|
|
48
|
+
propertyName = 'padding',
|
|
49
|
+
sequenceProps
|
|
50
|
+
) => {
|
|
51
|
+
const sequence = getSequence(sequenceProps)
|
|
48
52
|
|
|
49
|
-
const
|
|
50
|
-
const type = (generatedSequence || SPACING).sequence
|
|
51
|
-
|
|
52
|
-
const stack = Arrayize(val)
|
|
53
|
+
const stack = arrayze(value)
|
|
53
54
|
if (!stack) return
|
|
54
55
|
|
|
55
|
-
const length = stack.length
|
|
56
|
-
|
|
57
|
-
const wrapSequenceItem = (prop, i) => getSequenceValue({
|
|
58
|
-
type,
|
|
59
|
-
prop,
|
|
60
|
-
val: stack[i],
|
|
61
|
-
prefix,
|
|
62
|
-
unit
|
|
63
|
-
})
|
|
64
|
-
|
|
65
56
|
let suffix = ''
|
|
66
|
-
if (
|
|
67
|
-
|
|
57
|
+
if (propertyName === 'borderWidth') {
|
|
58
|
+
propertyName = 'border'
|
|
68
59
|
suffix = 'Width'
|
|
69
60
|
}
|
|
70
61
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
]
|
|
62
|
+
const directions = {
|
|
63
|
+
2: ['Block', 'Inline'],
|
|
64
|
+
3: ['BlockStart', 'Inline', 'BlockEnd'],
|
|
65
|
+
4: ['BlockStart', 'InlineEnd', 'BlockEnd', 'InlineStart']
|
|
76
66
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
wrapSequenceItem(property + 'InlineStart' + suffix, 3),
|
|
87
|
-
wrapSequenceItem(property + 'BlockEnd' + suffix, 2),
|
|
88
|
-
wrapSequenceItem(property + 'InlineEnd' + suffix, 1)
|
|
89
|
-
]
|
|
67
|
+
|
|
68
|
+
const wrapSequenceValueByDirection = (direction, i) => getSequenceValuePropertyPair(
|
|
69
|
+
stack[i],
|
|
70
|
+
propertyName + direction + suffix,
|
|
71
|
+
sequence
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
if (stack.length > 1) {
|
|
75
|
+
return directions[stack.length].map((dir, key) => wrapSequenceValueByDirection(dir, key))
|
|
90
76
|
}
|
|
91
77
|
|
|
92
|
-
return
|
|
78
|
+
return getSequenceValuePropertyPair(
|
|
79
|
+
value,
|
|
80
|
+
propertyName,
|
|
81
|
+
sequence
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const getSpacingBasedOnRatio = (props, propertyName, val) => {
|
|
86
|
+
const { spacingRatio, unit } = props
|
|
87
|
+
const value = val || props[propertyName]
|
|
88
|
+
|
|
89
|
+
if (spacingRatio) {
|
|
90
|
+
let sequenceProps = SPACING[spacingRatio]
|
|
91
|
+
|
|
92
|
+
if (!sequenceProps) {
|
|
93
|
+
const { type, base, range, subSequence } = SPACING
|
|
94
|
+
|
|
95
|
+
sequenceProps = SPACING[spacingRatio] = merge({
|
|
96
|
+
ratio: spacingRatio,
|
|
97
|
+
type: type + '-' + spacingRatio,
|
|
98
|
+
unit,
|
|
99
|
+
sequence: {},
|
|
100
|
+
scales: {},
|
|
101
|
+
styles: {},
|
|
102
|
+
vars: {}
|
|
103
|
+
}, {
|
|
104
|
+
base,
|
|
105
|
+
range,
|
|
106
|
+
subSequence,
|
|
107
|
+
ratio: SPACING.ratio,
|
|
108
|
+
unit: SPACING.unit
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
applySequenceVars(sequenceProps, null, { useDefault: false })
|
|
113
|
+
|
|
114
|
+
return getSpacingByKey(value, propertyName, sequenceProps)
|
|
115
|
+
}
|
|
116
|
+
return getSpacingByKey(value, propertyName)
|
|
93
117
|
}
|
package/src/system/theme.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
isArray
|
|
11
11
|
} from '../utils'
|
|
12
12
|
|
|
13
|
-
const ENV = process.env.NODE_ENV
|
|
13
|
+
const ENV = process.env.NODE_ENV // eslint-disable-line
|
|
14
14
|
|
|
15
15
|
const setThemeValue = theme => {
|
|
16
16
|
const value = {}
|
|
@@ -53,7 +53,7 @@ export const getTheme = (value, modifier) => {
|
|
|
53
53
|
if (state && state[subThemeName]) return getThemeValue(state[subThemeName])
|
|
54
54
|
} else if (isObject(value)) return setThemeValue(value)
|
|
55
55
|
|
|
56
|
-
if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn('Can\'t find theme', value)
|
|
56
|
+
// if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn('Can\'t find theme', value)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const setInverseTheme = (theme, variant, value) => {
|
|
@@ -161,8 +161,23 @@ export const setMediaTheme = (val, key, suffix, prefers) => {
|
|
|
161
161
|
} else {
|
|
162
162
|
theme[param] = color
|
|
163
163
|
}
|
|
164
|
+
theme[`.${param}`] = { [param]: theme[param] }
|
|
164
165
|
}
|
|
165
166
|
}
|
|
167
|
+
|
|
168
|
+
if (theme['background'] || theme['color'] || theme['backgroundColor']) {
|
|
169
|
+
theme['.inversed'] = {
|
|
170
|
+
color: theme['background'] || theme['backgroundColor'],
|
|
171
|
+
background: theme['color']
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (isString(val) && val.slice(0, 2) === '--') {
|
|
177
|
+
const { THEME } = CONFIG
|
|
178
|
+
const value = THEME[val.slice(2)]
|
|
179
|
+
const getReferenced = getMediaTheme(value)
|
|
180
|
+
return getReferenced
|
|
166
181
|
}
|
|
167
182
|
|
|
168
183
|
return theme
|
|
@@ -185,13 +200,42 @@ const recursiveTheme = val => {
|
|
|
185
200
|
return obj
|
|
186
201
|
}
|
|
187
202
|
|
|
188
|
-
|
|
203
|
+
const findModifierFromArray = (val, modifierArray) => {
|
|
204
|
+
const currentMod = modifierArray.shift()
|
|
205
|
+
if (val[currentMod]) return findModifierFromArray(val[currentMod], modifierArray)
|
|
206
|
+
return val
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const findModifier = (val, modifier) => {
|
|
210
|
+
// console.log(val)
|
|
211
|
+
// console.log(modifier)
|
|
212
|
+
if (isArray(modifier)) return findModifierFromArray(val, modifier)
|
|
213
|
+
else if (isString(modifier)) return val[modifier]
|
|
214
|
+
else return val
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const checkForReference = (val, callback) => {
|
|
218
|
+
if (isString(val) && val.slice(0, 2) === '--') return getMediaTheme(val.slice(2))
|
|
219
|
+
return val
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const checkThemeReference = (val) => checkForReference(val, checkThemeReference) // eslint-disable-line
|
|
223
|
+
|
|
224
|
+
export const getMediaTheme = (val, mod, themeObj) => {
|
|
225
|
+
if (isString(val) && val.slice(0, 2) === '--') val = getMediaTheme(val.slice(2))
|
|
226
|
+
|
|
189
227
|
if (!val || !isString(val)) {
|
|
190
|
-
if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn(val, '- type for color is not valid')
|
|
228
|
+
// if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn(val, '- type for color is not valid')
|
|
191
229
|
return
|
|
192
230
|
}
|
|
193
|
-
|
|
231
|
+
|
|
232
|
+
// console.group(val)
|
|
233
|
+
const [name, ...modifier] = isArray(val) ? val : val.split(' ')
|
|
194
234
|
let value = CONFIG.THEME[name]
|
|
195
|
-
if (value && modifier
|
|
235
|
+
if (value && (modifier || mod)) value = findModifier(value, modifier.length ? modifier : mod)
|
|
236
|
+
// console.log('finalval', value)
|
|
237
|
+
// console.groupEnd(val)
|
|
196
238
|
return recursiveTheme(value)
|
|
197
239
|
}
|
|
240
|
+
|
|
241
|
+
window.getMediaTheme = getMediaTheme
|
package/src/system/timing.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { TIMING } from '../
|
|
3
|
+
import { TIMING } from '../defaultConfig'
|
|
4
4
|
import {
|
|
5
5
|
applySequenceVars,
|
|
6
6
|
generateSequence,
|
|
7
|
-
|
|
7
|
+
getSequenceValuePropertyPair
|
|
8
8
|
} from '../utils'
|
|
9
9
|
|
|
10
10
|
export const applyTimingSequence = () => {
|
|
@@ -12,10 +12,8 @@ export const applyTimingSequence = () => {
|
|
|
12
12
|
applySequenceVars(TIMING)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const getTimingByKey =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
prefix: '--duration-'
|
|
21
|
-
})
|
|
15
|
+
export const getTimingByKey = value => getSequenceValuePropertyPair(
|
|
16
|
+
value,
|
|
17
|
+
'duration',
|
|
18
|
+
TIMING
|
|
19
|
+
)
|
package/src/system/typography.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { MEDIA, TYPOGRAPHY } from '../
|
|
3
|
+
import { MEDIA, TYPOGRAPHY } from '../defaultConfig'
|
|
4
4
|
import { CONFIG } from '../factory'
|
|
5
5
|
import {
|
|
6
6
|
applySequenceVars,
|
|
7
7
|
findHeadings,
|
|
8
8
|
generateSequence,
|
|
9
|
-
|
|
9
|
+
getSequenceValuePropertyPair,
|
|
10
10
|
merge
|
|
11
11
|
} from '../utils'
|
|
12
12
|
|
|
@@ -63,10 +63,8 @@ export const applyTypographySequence = () => {
|
|
|
63
63
|
runThroughMedia(TYPOGRAPHY)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export const getFontSizeByKey =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
prefix: '--font-size-'
|
|
72
|
-
})
|
|
66
|
+
export const getFontSizeByKey = value => getSequenceValuePropertyPair(
|
|
67
|
+
value,
|
|
68
|
+
'fontSize',
|
|
69
|
+
TYPOGRAPHY
|
|
70
|
+
)
|
package/src/utils/object.js
CHANGED
|
@@ -38,7 +38,7 @@ export const deepMerge = (obj, obj2) => {
|
|
|
38
38
|
return obj
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export const
|
|
41
|
+
export const arrayze = val => {
|
|
42
42
|
const isString = typeof val === 'string'
|
|
43
43
|
if (isString) return val.split(' ')
|
|
44
44
|
if (isObject(val)) return Object.keys(val).map(v => val[v])
|
package/src/utils/sequence.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { UNIT } from '../
|
|
3
|
+
import { UNIT } from '../defaultConfig'
|
|
4
4
|
import { CONFIG } from '../factory'
|
|
5
|
+
import { isString } from './object'
|
|
5
6
|
|
|
6
7
|
export const numToLetterMap = {
|
|
7
8
|
'-6': 'U',
|
|
@@ -32,8 +33,9 @@ export const numToLetterMap = {
|
|
|
32
33
|
19: 'T'
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
const setSequenceValue = (
|
|
36
|
-
|
|
36
|
+
const setSequenceValue = (props, sequenceProps) => {
|
|
37
|
+
const { key, variable, value, scaling, index } = props
|
|
38
|
+
sequenceProps.sequence[key] = {
|
|
37
39
|
key,
|
|
38
40
|
decimal: Math.round(value * 100) / 100,
|
|
39
41
|
val: Math.round(value),
|
|
@@ -41,68 +43,20 @@ const setSequenceValue = ({ key, variable, value, scaling, state, index }) => {
|
|
|
41
43
|
index,
|
|
42
44
|
variable
|
|
43
45
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
sequenceProps.scales[key] = scaling
|
|
47
|
+
sequenceProps.vars[variable] = scaling + sequenceProps.unit
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
val = 'A',
|
|
52
|
-
prefix = '--font-size-',
|
|
53
|
-
unit = UNIT.default,
|
|
54
|
-
useVariable
|
|
55
|
-
}) => {
|
|
56
|
-
if (typeof val !== 'string') console.warn(prop, val, 'is not a string')
|
|
57
|
-
|
|
58
|
-
if (val === '-' || val === '') return ({ })
|
|
59
|
-
if (
|
|
60
|
-
val === 'none' ||
|
|
61
|
-
val === 'auto' ||
|
|
62
|
-
val === 'fit-content' ||
|
|
63
|
-
val === 'min-content' ||
|
|
64
|
-
val === 'max-content'
|
|
65
|
-
) return ({ [prop]: val })
|
|
66
|
-
|
|
67
|
-
const startsWithLetterRegex = /^-?[a-zA-Z]/i
|
|
68
|
-
const startsWithLetter = startsWithLetterRegex.test(val)
|
|
69
|
-
if (!startsWithLetter) return ({ [prop]: val })
|
|
70
|
-
|
|
71
|
-
const letterVal = val.toUpperCase()
|
|
72
|
-
const isNegative = letterVal.slice(0, 1) === '-' ? '-' : ''
|
|
73
|
-
let pureVal = isNegative ? letterVal.slice(1) : letterVal
|
|
74
|
-
|
|
75
|
-
let mediaName = ''
|
|
76
|
-
if (pureVal.includes('-')) {
|
|
77
|
-
mediaName = '-' + pureVal.split('-')[1].toLowerCase()
|
|
78
|
-
pureVal = pureVal.split('-')[0]
|
|
79
|
-
}
|
|
50
|
+
const dashize = val => val
|
|
51
|
+
.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? '-' : '') + match.toLowerCase())
|
|
52
|
+
.replace('.', '-')
|
|
80
53
|
|
|
81
|
-
|
|
82
|
-
|
|
54
|
+
export const generateSubSequence = (props, sequenceProps) => {
|
|
55
|
+
const { key, base, value, ratio, variable, index } = props
|
|
83
56
|
|
|
84
|
-
if (useVariable || CONFIG.useVariable) {
|
|
85
|
-
const varVal = `var(${prefix}${pureVal}${mediaName})`
|
|
86
|
-
return isNegative ? {
|
|
87
|
-
[prop]: `calc(${varVal} * -1)`
|
|
88
|
-
} : {
|
|
89
|
-
[prop]: varVal
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (unit === 'ms' || unit === 's') {
|
|
94
|
-
return ({ [prop]: isNegative + value.val + unit })
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return ({
|
|
98
|
-
[prop]: isNegative + value.val + value.unit,
|
|
99
|
-
[prop]: isNegative + value.scaling + unit
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export const generateSubSequence = ({ key, base, value, ratio, variable, state, index }) => {
|
|
104
57
|
const next = value * ratio
|
|
105
|
-
const
|
|
58
|
+
const diff = next - value
|
|
59
|
+
const smallscale = diff / 1.618
|
|
106
60
|
|
|
107
61
|
const valueRounded = Math.round(value)
|
|
108
62
|
const nextRounded = Math.round(next)
|
|
@@ -112,20 +66,29 @@ export const generateSubSequence = ({ key, base, value, ratio, variable, state,
|
|
|
112
66
|
const first = next - smallscale
|
|
113
67
|
const second = value + smallscale
|
|
114
68
|
const middle = (first + second) / 2
|
|
115
|
-
if (diffRounded >
|
|
69
|
+
if (diffRounded > 16) arr = [first, middle, second]
|
|
116
70
|
else arr = [first, second]
|
|
117
71
|
|
|
118
72
|
arr.map((v, k) => {
|
|
119
73
|
const scaling = Math.round(v / base * 1000) / 1000
|
|
120
74
|
const newVar = variable + (k + 1)
|
|
121
75
|
|
|
122
|
-
|
|
76
|
+
const props = {
|
|
77
|
+
key: key + (k + 1),
|
|
78
|
+
variable: newVar,
|
|
79
|
+
value: v,
|
|
80
|
+
scaling,
|
|
81
|
+
index: index + (k + 1) / 10
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return setSequenceValue(props, sequenceProps)
|
|
123
85
|
})
|
|
124
86
|
}
|
|
125
87
|
|
|
126
|
-
export const generateSequence = (
|
|
88
|
+
export const generateSequence = (sequenceProps) => {
|
|
89
|
+
const { type, base, ratio, range, subSequence } = sequenceProps
|
|
127
90
|
const n = Math.abs(range[0]) + Math.abs(range[1])
|
|
128
|
-
const prefix = '--' + type + '-'
|
|
91
|
+
const prefix = '--' + type.replace('.', '-') + '-'
|
|
129
92
|
|
|
130
93
|
for (let i = 0; i <= n; i++) {
|
|
131
94
|
const key = range[1] - i
|
|
@@ -134,15 +97,84 @@ export const generateSequence = ({ type, base, ratio, range, subSequence, ...sta
|
|
|
134
97
|
const scaling = Math.round(value / base * 1000) / 1000
|
|
135
98
|
const variable = prefix + letterKey
|
|
136
99
|
|
|
137
|
-
|
|
100
|
+
const props = {
|
|
101
|
+
key: letterKey,
|
|
102
|
+
variable,
|
|
103
|
+
value,
|
|
104
|
+
base,
|
|
105
|
+
scaling,
|
|
106
|
+
ratio,
|
|
107
|
+
index: key
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
setSequenceValue(props, sequenceProps)
|
|
111
|
+
|
|
112
|
+
if (subSequence) generateSubSequence(props, sequenceProps)
|
|
113
|
+
}
|
|
114
|
+
return sequenceProps
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const getSequenceValue = (value = 'A', sequenceProps) => {
|
|
118
|
+
const {
|
|
119
|
+
sequence,
|
|
120
|
+
unit = UNIT.default,
|
|
121
|
+
useVariable
|
|
122
|
+
} = sequenceProps
|
|
123
|
+
|
|
124
|
+
if (isString(value) && value.slice(0, 2) === '--') {
|
|
125
|
+
return `var(${value})`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const prefix = `--${dashize(sequenceProps.type.replace('.', '-'))}-`
|
|
129
|
+
|
|
130
|
+
const startsWithDashOrLetterRegex = /^-?[a-zA-Z]/i
|
|
131
|
+
const startsWithDashOrLetter = startsWithDashOrLetterRegex.test(value)
|
|
132
|
+
|
|
133
|
+
if (
|
|
134
|
+
value === 'none' ||
|
|
135
|
+
value === 'auto' ||
|
|
136
|
+
value === 'fit-content' ||
|
|
137
|
+
value === 'min-content' ||
|
|
138
|
+
value === 'max-content' ||
|
|
139
|
+
!startsWithDashOrLetter
|
|
140
|
+
) return value
|
|
141
|
+
|
|
142
|
+
const letterVal = value.toUpperCase()
|
|
143
|
+
const isNegative = letterVal.slice(0, 1) === '-' ? '-' : ''
|
|
144
|
+
let absValue = isNegative ? letterVal.slice(1) : letterVal
|
|
145
|
+
|
|
146
|
+
let mediaName = ''
|
|
147
|
+
if (absValue.includes('-')) {
|
|
148
|
+
mediaName = '-' + absValue.split('-')[1].toLowerCase()
|
|
149
|
+
absValue = absValue.split('-')[0]
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (useVariable || CONFIG.useVariable) {
|
|
153
|
+
const varValue = `var(${prefix}${absValue}${mediaName})`
|
|
154
|
+
return isNegative ? `calc(${varValue} * -1)` : varValue
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const sequenceItem = sequence ? sequence[absValue] : null
|
|
158
|
+
if (!sequenceItem) return console.warn('can\'t find', sequence, absValue)
|
|
159
|
+
|
|
160
|
+
if (unit === 'ms' || unit === 's') {
|
|
161
|
+
return isNegative + sequenceItem.value + unit
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return isNegative + sequenceItem.scaling + unit
|
|
165
|
+
}
|
|
138
166
|
|
|
139
|
-
|
|
167
|
+
export const getSequenceValuePropertyPair = (value, propertyName, sequenceProps) => {
|
|
168
|
+
if (typeof value !== 'string') {
|
|
169
|
+
console.warn(propertyName, value, 'is not a string')
|
|
170
|
+
return ({})
|
|
140
171
|
}
|
|
141
|
-
return
|
|
172
|
+
if (value === '-' || value === '') return ({})
|
|
173
|
+
return { [propertyName]: getSequenceValue(value, sequenceProps) }
|
|
142
174
|
}
|
|
143
175
|
|
|
144
|
-
export const findHeadings =
|
|
145
|
-
const { h1Matches, sequence } =
|
|
176
|
+
export const findHeadings = propertyNames => {
|
|
177
|
+
const { h1Matches, sequence } = propertyNames
|
|
146
178
|
return new Array(6).fill(null).map((_, i) => {
|
|
147
179
|
const findLetter = numToLetterMap[h1Matches - i]
|
|
148
180
|
return sequence[findLetter]
|
package/src/utils/var.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { MEDIA } from '../
|
|
3
|
+
import { MEDIA } from '../defaultConfig'
|
|
4
4
|
import { CONFIG, CSS_VARS } from '../factory'
|
|
5
5
|
import { isObjectLike } from './object'
|
|
6
6
|
|
|
7
|
+
const ENV = process.env.NODE_ENV
|
|
8
|
+
|
|
7
9
|
export const setVariables = (result, key) => {
|
|
8
10
|
// CSS_VARS[result.var] =
|
|
9
11
|
if (isObjectLike(result.value)) {
|
|
@@ -18,23 +20,30 @@ export const setVariables = (result, key) => {
|
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
export const applySequenceVars = (props, mediaName) => {
|
|
23
|
+
export const applySequenceVars = (props, mediaName, options = {}) => {
|
|
22
24
|
const unit = props.unit || CONFIG.UNIT.default
|
|
23
25
|
const { sequence, scales } = props
|
|
24
26
|
|
|
25
27
|
for (const key in sequence) {
|
|
26
28
|
const item = sequence[key]
|
|
27
29
|
const value = (props.type === 'duration' ? sequence[key].val : scales[key]) + unit
|
|
28
|
-
const query = MEDIA[mediaName]
|
|
29
30
|
|
|
30
31
|
if (mediaName) {
|
|
32
|
+
const query = MEDIA[mediaName]
|
|
33
|
+
if (!query) {
|
|
34
|
+
if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn('Can\'t find query ', query)
|
|
35
|
+
}
|
|
31
36
|
let underMediaQuery = CSS_VARS[`@media ${query}`]
|
|
32
37
|
if (!underMediaQuery) underMediaQuery = CSS_VARS[`@media ${query}`] = {}
|
|
33
38
|
underMediaQuery[item.variable] = `var(${item.variable + '-' + mediaName})`
|
|
34
39
|
CSS_VARS[item.variable + '-' + mediaName] = value
|
|
35
40
|
} else {
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
if (options.useDefault === false) {
|
|
42
|
+
CSS_VARS[item.variable] = value
|
|
43
|
+
} else {
|
|
44
|
+
CSS_VARS[item.variable + '-default'] = value
|
|
45
|
+
CSS_VARS[item.variable] = `var(${item.variable + '-default'})`
|
|
46
|
+
}
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
}
|