@symbo.ls/scratch 0.6.4 → 0.7.0
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 -70
- 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,66 +43,17 @@ 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
58
|
const smallscale = (next - value) / ratio
|
|
106
59
|
|
|
@@ -109,23 +62,32 @@ export const generateSubSequence = ({ key, base, value, ratio, variable, state,
|
|
|
109
62
|
const diffRounded = nextRounded - valueRounded
|
|
110
63
|
|
|
111
64
|
let arr = []
|
|
112
|
-
const first =
|
|
113
|
-
const second =
|
|
65
|
+
const first = value + smallscale
|
|
66
|
+
const second = next - smallscale
|
|
114
67
|
const middle = (first + second) / 2
|
|
115
|
-
if (diffRounded >
|
|
68
|
+
if (diffRounded > 16) arr = [first, middle, second]
|
|
116
69
|
else arr = [first, second]
|
|
117
70
|
|
|
118
71
|
arr.map((v, k) => {
|
|
119
72
|
const scaling = Math.round(v / base * 1000) / 1000
|
|
120
73
|
const newVar = variable + (k + 1)
|
|
121
74
|
|
|
122
|
-
|
|
75
|
+
const props = {
|
|
76
|
+
key: key + (k + 1),
|
|
77
|
+
variable: newVar,
|
|
78
|
+
value: v,
|
|
79
|
+
scaling,
|
|
80
|
+
index: index + (k + 1) / 10
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return setSequenceValue(props, sequenceProps)
|
|
123
84
|
})
|
|
124
85
|
}
|
|
125
86
|
|
|
126
|
-
export const generateSequence = (
|
|
87
|
+
export const generateSequence = (sequenceProps) => {
|
|
88
|
+
const { type, base, ratio, range, subSequence } = sequenceProps
|
|
127
89
|
const n = Math.abs(range[0]) + Math.abs(range[1])
|
|
128
|
-
const prefix = '--' + type + '-'
|
|
90
|
+
const prefix = '--' + type.replace('.', '-') + '-'
|
|
129
91
|
|
|
130
92
|
for (let i = 0; i <= n; i++) {
|
|
131
93
|
const key = range[1] - i
|
|
@@ -134,15 +96,84 @@ export const generateSequence = ({ type, base, ratio, range, subSequence, ...sta
|
|
|
134
96
|
const scaling = Math.round(value / base * 1000) / 1000
|
|
135
97
|
const variable = prefix + letterKey
|
|
136
98
|
|
|
137
|
-
|
|
99
|
+
const props = {
|
|
100
|
+
key: letterKey,
|
|
101
|
+
variable,
|
|
102
|
+
value,
|
|
103
|
+
base,
|
|
104
|
+
scaling,
|
|
105
|
+
ratio,
|
|
106
|
+
index: key
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
setSequenceValue(props, sequenceProps)
|
|
110
|
+
|
|
111
|
+
if (subSequence) generateSubSequence(props, sequenceProps)
|
|
112
|
+
}
|
|
113
|
+
return sequenceProps
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const getSequenceValue = (value = 'A', sequenceProps) => {
|
|
117
|
+
const {
|
|
118
|
+
sequence,
|
|
119
|
+
unit = UNIT.default,
|
|
120
|
+
useVariable
|
|
121
|
+
} = sequenceProps
|
|
122
|
+
|
|
123
|
+
if (isString(value) && value.slice(0, 2) === '--') {
|
|
124
|
+
return `var(${value})`
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const prefix = `--${dashize(sequenceProps.type.replace('.', '-'))}-`
|
|
128
|
+
|
|
129
|
+
const startsWithDashOrLetterRegex = /^-?[a-zA-Z]/i
|
|
130
|
+
const startsWithDashOrLetter = startsWithDashOrLetterRegex.test(value)
|
|
131
|
+
|
|
132
|
+
if (
|
|
133
|
+
value === 'none' ||
|
|
134
|
+
value === 'auto' ||
|
|
135
|
+
value === 'fit-content' ||
|
|
136
|
+
value === 'min-content' ||
|
|
137
|
+
value === 'max-content' ||
|
|
138
|
+
!startsWithDashOrLetter
|
|
139
|
+
) return value
|
|
140
|
+
|
|
141
|
+
const letterVal = value.toUpperCase()
|
|
142
|
+
const isNegative = letterVal.slice(0, 1) === '-' ? '-' : ''
|
|
143
|
+
let absValue = isNegative ? letterVal.slice(1) : letterVal
|
|
144
|
+
|
|
145
|
+
let mediaName = ''
|
|
146
|
+
if (absValue.includes('-')) {
|
|
147
|
+
mediaName = '-' + absValue.split('-')[1].toLowerCase()
|
|
148
|
+
absValue = absValue.split('-')[0]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (useVariable || CONFIG.useVariable) {
|
|
152
|
+
const varValue = `var(${prefix}${absValue}${mediaName})`
|
|
153
|
+
return isNegative ? `calc(${varValue} * -1)` : varValue
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const sequenceItem = sequence ? sequence[absValue] : null
|
|
157
|
+
if (!sequenceItem) return console.warn('can\'t find', sequence, absValue)
|
|
158
|
+
|
|
159
|
+
if (unit === 'ms' || unit === 's') {
|
|
160
|
+
return isNegative + sequenceItem.value + unit
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return isNegative + sequenceItem.scaling + unit
|
|
164
|
+
}
|
|
138
165
|
|
|
139
|
-
|
|
166
|
+
export const getSequenceValuePropertyPair = (value, propertyName, sequenceProps) => {
|
|
167
|
+
if (typeof value !== 'string') {
|
|
168
|
+
console.warn(propertyName, value, 'is not a string')
|
|
169
|
+
return ({})
|
|
140
170
|
}
|
|
141
|
-
return
|
|
171
|
+
if (value === '-' || value === '') return ({})
|
|
172
|
+
return { [propertyName]: getSequenceValue(value, sequenceProps) }
|
|
142
173
|
}
|
|
143
174
|
|
|
144
|
-
export const findHeadings =
|
|
145
|
-
const { h1Matches, sequence } =
|
|
175
|
+
export const findHeadings = propertyNames => {
|
|
176
|
+
const { h1Matches, sequence } = propertyNames
|
|
146
177
|
return new Array(6).fill(null).map((_, i) => {
|
|
147
178
|
const findLetter = numToLetterMap[h1Matches - i]
|
|
148
179
|
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
|
}
|