@symbo.ls/scratch 0.3.34 → 0.4.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/document.js +1 -1
- package/src/config/index.js +3 -0
- package/src/config/media.js +3 -1
- package/src/config/spacing.js +46 -14
- package/src/config/timing.js +6 -3
- package/src/config/typography.js +56 -14
- package/src/factory.js +1 -3
- package/src/reset.js +10 -4
- package/src/set.js +3 -2
- package/src/system/font.js +3 -2
- package/src/system/theme.js +0 -3
- package/src/utils/index.js +1 -1
- package/src/utils/sequence.js +51 -36
- package/src/utils/var.js +38 -0
- package/src/utils/setVariables.js +0 -18
package/package.json
CHANGED
package/src/config/document.js
CHANGED
package/src/config/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { CSS_VARS } from '../factory'
|
|
4
|
+
|
|
3
5
|
export * from './sequence'
|
|
4
6
|
export * from './unit'
|
|
5
7
|
export * from './typography'
|
|
@@ -13,4 +15,5 @@ export * from './icons'
|
|
|
13
15
|
export * from './timing'
|
|
14
16
|
export * from './document'
|
|
15
17
|
export * from './cases'
|
|
18
|
+
|
|
16
19
|
export const RESET = {}
|
package/src/config/media.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
export const MEDIA = {
|
|
4
|
+
tv: '(min-width: 2780px)',
|
|
5
|
+
|
|
4
6
|
screenL: '(max-width: 1920px)',
|
|
5
7
|
screenM: '(max-width: 1680px)',
|
|
6
8
|
screenS: '(max-width: 1440px)',
|
|
@@ -11,7 +13,7 @@ export const MEDIA = {
|
|
|
11
13
|
mobileM: '(max-width: 560px)',
|
|
12
14
|
mobileS: '(max-width: 480px)',
|
|
13
15
|
mobileXS: '(max-width: 375px)',
|
|
14
|
-
|
|
16
|
+
|
|
15
17
|
sL: '(max-width: 1920px)',
|
|
16
18
|
sM: '(max-width: 1680px)',
|
|
17
19
|
sS: '(max-width: 1440px)',
|
package/src/config/spacing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { SEQUENCE, TYPOGRAPHY } from '.'
|
|
4
|
-
import { Arrayize,
|
|
4
|
+
import { Arrayize, getSequenceValue, generateSequence, applySequenceVars, merge } from '../utils'
|
|
5
5
|
|
|
6
6
|
const defaultProps = {
|
|
7
7
|
base: TYPOGRAPHY.base,
|
|
@@ -9,12 +9,44 @@ const defaultProps = {
|
|
|
9
9
|
ratio: SEQUENCE.phi,
|
|
10
10
|
range: [-5, +15],
|
|
11
11
|
subSequence: true,
|
|
12
|
+
unit: 'em',
|
|
12
13
|
sequence: {},
|
|
13
|
-
scales: {}
|
|
14
|
+
scales: {},
|
|
15
|
+
vars: {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const runThroughMedia = props => {
|
|
19
|
+
for (const prop in props) {
|
|
20
|
+
const mediaProps = props[prop]
|
|
21
|
+
if (prop.slice(0, 1) === '@') {
|
|
22
|
+
const { type, base, ratio, range, subSequence, h1Matches, unit } = props
|
|
23
|
+
|
|
24
|
+
merge(mediaProps, {
|
|
25
|
+
type,
|
|
26
|
+
base,
|
|
27
|
+
ratio,
|
|
28
|
+
range,
|
|
29
|
+
subSequence,
|
|
30
|
+
h1Matches,
|
|
31
|
+
unit,
|
|
32
|
+
sequence: {},
|
|
33
|
+
scales: {},
|
|
34
|
+
styles: {},
|
|
35
|
+
vars: {}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
generateSequence(mediaProps)
|
|
39
|
+
|
|
40
|
+
const mediaName = prop.slice(1)
|
|
41
|
+
applySequenceVars(mediaProps, mediaName)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
14
44
|
}
|
|
15
45
|
|
|
16
46
|
export const applySpacingSequence = () => {
|
|
17
47
|
generateSequence(defaultProps)
|
|
48
|
+
applySequenceVars(defaultProps)
|
|
49
|
+
runThroughMedia(defaultProps)
|
|
18
50
|
}
|
|
19
51
|
|
|
20
52
|
const getSequence = (props) => {
|
|
@@ -23,7 +55,7 @@ const getSequence = (props) => {
|
|
|
23
55
|
return hasGenerated ? props : generateSequence(props)
|
|
24
56
|
}
|
|
25
57
|
|
|
26
|
-
export const
|
|
58
|
+
export const getSpacingByKey = (val, property = 'padding', props, unit) => {
|
|
27
59
|
const prefix = '--spacing-'
|
|
28
60
|
|
|
29
61
|
const generatedSequence = getSequence(props)
|
|
@@ -34,7 +66,7 @@ export const mapSpacing = (val, property = 'padding', props, unit) => {
|
|
|
34
66
|
|
|
35
67
|
const length = stack.length
|
|
36
68
|
|
|
37
|
-
const
|
|
69
|
+
const wrapSequenceItem = (prop, i) => getSequenceValue({
|
|
38
70
|
type,
|
|
39
71
|
prop,
|
|
40
72
|
val: stack[i],
|
|
@@ -50,26 +82,26 @@ export const mapSpacing = (val, property = 'padding', props, unit) => {
|
|
|
50
82
|
|
|
51
83
|
if (length === 2) {
|
|
52
84
|
return [
|
|
53
|
-
|
|
54
|
-
|
|
85
|
+
wrapSequenceItem(property + 'Block' + suffix, 0),
|
|
86
|
+
wrapSequenceItem(property + 'Inline' + suffix, 1)
|
|
55
87
|
]
|
|
56
88
|
}
|
|
57
89
|
if (length === 3) {
|
|
58
90
|
return [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
91
|
+
wrapSequenceItem(property + 'BlockStart' + suffix, 0),
|
|
92
|
+
wrapSequenceItem(property + 'Inline' + suffix, 1),
|
|
93
|
+
wrapSequenceItem(property + 'BlockEnd' + suffix, 2)
|
|
62
94
|
]
|
|
63
95
|
} else if (length === 4) {
|
|
64
96
|
return [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
97
|
+
wrapSequenceItem(property + 'BlockStart' + suffix, 0),
|
|
98
|
+
wrapSequenceItem(property + 'InlineStart' + suffix, 3),
|
|
99
|
+
wrapSequenceItem(property + 'BlockEnd' + suffix, 2),
|
|
100
|
+
wrapSequenceItem(property + 'InlineEnd' + suffix, 1)
|
|
69
101
|
]
|
|
70
102
|
}
|
|
71
103
|
|
|
72
|
-
return
|
|
104
|
+
return getSequenceValue({ type, prop: property, val, prefix, unit })
|
|
73
105
|
}
|
|
74
106
|
|
|
75
107
|
export const SPACING = defaultProps
|
package/src/config/timing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { SEQUENCE } from '.'
|
|
4
|
-
import {
|
|
4
|
+
import { applySequenceVars, generateSequence, getSequenceValue } from '../utils'
|
|
5
5
|
|
|
6
6
|
const defaultProps = {
|
|
7
7
|
default: 150,
|
|
@@ -9,15 +9,18 @@ const defaultProps = {
|
|
|
9
9
|
type: 'duration',
|
|
10
10
|
ratio: SEQUENCE['perfect-fourth'],
|
|
11
11
|
range: [-3, +12],
|
|
12
|
+
unit: 'ms',
|
|
12
13
|
sequence: {},
|
|
13
|
-
scales: {}
|
|
14
|
+
scales: {},
|
|
15
|
+
vars: {}
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export const applyTimingSequence = () => {
|
|
17
19
|
generateSequence(defaultProps)
|
|
20
|
+
applySequenceVars(defaultProps)
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
export const
|
|
23
|
+
export const getTimingByKey = val => getSequenceValue({
|
|
21
24
|
type: defaultProps.sequence,
|
|
22
25
|
prop: 'duration',
|
|
23
26
|
val,
|
package/src/config/typography.js
CHANGED
|
@@ -1,40 +1,82 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { CONFIG } from '../factory'
|
|
4
|
+
import { SEQUENCE, MEDIA } from '.'
|
|
5
|
+
import { getSequenceValue, generateSequence, findHeadings, merge, applySequenceVars } from '../utils'
|
|
5
6
|
|
|
6
7
|
const defaultProps = {
|
|
7
|
-
|
|
8
|
+
browserDefault: 16,
|
|
8
9
|
base: 16,
|
|
9
10
|
type: 'font-size',
|
|
10
11
|
ratio: SEQUENCE['minor-third'],
|
|
11
12
|
range: [-3, +12],
|
|
12
13
|
h1Matches: +6,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
14
|
+
lineHeight: 1.5,
|
|
15
|
+
unit: 'em',
|
|
16
|
+
styles: {},
|
|
16
17
|
sequence: {},
|
|
17
|
-
scales: {}
|
|
18
|
+
scales: {},
|
|
19
|
+
vars: {}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const runThroughMedia = props => {
|
|
23
|
+
for (const prop in props) {
|
|
24
|
+
const mediaProps = props[prop]
|
|
25
|
+
if (prop.slice(0, 1) === '@') {
|
|
26
|
+
const { type, base, ratio, range, subSequence, h1Matches, unit } = props
|
|
27
|
+
|
|
28
|
+
merge(mediaProps, {
|
|
29
|
+
type,
|
|
30
|
+
base,
|
|
31
|
+
ratio,
|
|
32
|
+
range,
|
|
33
|
+
subSequence,
|
|
34
|
+
h1Matches,
|
|
35
|
+
unit,
|
|
36
|
+
sequence: {},
|
|
37
|
+
scales: {},
|
|
38
|
+
styles: {},
|
|
39
|
+
vars: {}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
generateSequence(mediaProps)
|
|
43
|
+
|
|
44
|
+
const mediaName = prop.slice(1)
|
|
45
|
+
applySequenceVars(mediaProps, mediaName)
|
|
46
|
+
|
|
47
|
+
const query = MEDIA[mediaName]
|
|
48
|
+
defaultProps.styles[`@media screen and ${query}`] = {
|
|
49
|
+
fontSize: mediaProps.base / defaultProps.browserDefault + unit
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
22
54
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
55
|
+
const applyHeadings = (props) => {
|
|
56
|
+
if (props.h1Matches) {
|
|
57
|
+
const unit = props.unit
|
|
58
|
+
const HEADINGS = findHeadings(props)
|
|
59
|
+
const { styles } = props
|
|
26
60
|
for (const k in HEADINGS) {
|
|
27
61
|
styles[`h${parseInt(k) + 1}`] = {
|
|
28
|
-
fontSize: `${HEADINGS[k].scaling}
|
|
62
|
+
fontSize: CONFIG.useVariable ? `var(${HEADINGS[k].variable})` : `${HEADINGS[k].scaling}${unit}`
|
|
29
63
|
}
|
|
30
64
|
}
|
|
31
65
|
}
|
|
32
66
|
}
|
|
33
67
|
|
|
34
|
-
export const
|
|
68
|
+
export const applyTypographySequence = () => {
|
|
69
|
+
generateSequence(defaultProps)
|
|
70
|
+
applyHeadings(defaultProps)
|
|
71
|
+
applySequenceVars(defaultProps)
|
|
72
|
+
runThroughMedia(defaultProps)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const getFontSizeByKey = val => getSequenceValue({
|
|
35
76
|
type: defaultProps.sequence,
|
|
36
77
|
prop: 'fontSize',
|
|
37
78
|
val,
|
|
79
|
+
unit: defaultProps.unit,
|
|
38
80
|
prefix: '--font-size-'
|
|
39
81
|
})
|
|
40
82
|
|
package/src/factory.js
CHANGED
package/src/reset.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import * as CONFIG from './config'
|
|
4
|
+
import { CSS_VARS } from './factory'
|
|
4
5
|
import { getTheme } from './system'
|
|
5
6
|
import { deepMerge, merge } from './utils'
|
|
6
7
|
|
|
7
8
|
export const applyReset = (reset = {}) => {
|
|
8
9
|
return deepMerge(merge(CONFIG.RESET, reset), {
|
|
10
|
+
':root': CSS_VARS,
|
|
11
|
+
|
|
9
12
|
html: {
|
|
10
13
|
position: 'absolute',
|
|
11
14
|
overflow: 'hidden',
|
|
@@ -18,8 +21,9 @@ export const applyReset = (reset = {}) => {
|
|
|
18
21
|
transform: 'translate3d(0, 0, 1px)',
|
|
19
22
|
scrollBehavior: 'smooth',
|
|
20
23
|
|
|
24
|
+
fontSize: CONFIG.TYPOGRAPHY.browserDefault + 'px',
|
|
25
|
+
|
|
21
26
|
fontFamily: CONFIG.DOCUMENT.fontFamily,
|
|
22
|
-
fontSize: CONFIG.DOCUMENT.fontSize / CONFIG.TYPOGRAPHY.default + CONFIG.UNIT.default,
|
|
23
27
|
lineHeight: CONFIG.DOCUMENT.lineHeight
|
|
24
28
|
},
|
|
25
29
|
|
|
@@ -29,10 +33,12 @@ export const applyReset = (reset = {}) => {
|
|
|
29
33
|
margin: 0,
|
|
30
34
|
fontFamily: CONFIG.DOCUMENT.fontFamily,
|
|
31
35
|
|
|
32
|
-
...getTheme('document')
|
|
33
|
-
},
|
|
36
|
+
...getTheme('document'),
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
fontSize: CONFIG.TYPOGRAPHY.base / CONFIG.TYPOGRAPHY.browserDefault + CONFIG.UNIT.default,
|
|
39
|
+
|
|
40
|
+
...CONFIG.TYPOGRAPHY.styles
|
|
41
|
+
},
|
|
36
42
|
|
|
37
43
|
// form elements
|
|
38
44
|
fieldset: {
|
package/src/set.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { applyDocument, applySpacingSequence, applyTimingSequence, applyTypographySequence } from './config'
|
|
4
|
-
import { CONFIG, CSS_VARS } from './factory'
|
|
4
|
+
import { CONFIG, CSS_VARS } from './factory' // eslint-disable-line no-unused-vars
|
|
5
5
|
import { applyReset } from './reset'
|
|
6
6
|
import { setColor, setGradient, setFont, setFontFamily, setTheme } from './system'
|
|
7
7
|
import {
|
|
@@ -30,7 +30,8 @@ export const SETTERS = {
|
|
|
30
30
|
media: setSameValue,
|
|
31
31
|
timing: setSameValue,
|
|
32
32
|
icons: setSameValue,
|
|
33
|
-
reset: setSameValue
|
|
33
|
+
reset: setSameValue,
|
|
34
|
+
unit: setSameValue
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
package/src/system/font.js
CHANGED
|
@@ -15,8 +15,9 @@ export const setFont = (val, key) => {
|
|
|
15
15
|
return { var: CSSvar, value: val, fontFace }
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export const getFontFamily =
|
|
19
|
-
|
|
18
|
+
export const getFontFamily = key => {
|
|
19
|
+
const { FONT_FAMILY } = CONFIG
|
|
20
|
+
return getDefaultOrFirstKey(FONT_FAMILY, key)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export const setFontFamily = (val, key) => {
|
package/src/system/theme.js
CHANGED
|
@@ -88,7 +88,6 @@ const goThroughInteractiveStates = (theme, value) => {
|
|
|
88
88
|
|
|
89
89
|
const setPrefersScheme = (theme, key, variant, themeValue) => {
|
|
90
90
|
const result = getTheme(variant)
|
|
91
|
-
// console.log(variant)
|
|
92
91
|
themeValue[`@media (prefers-color-scheme: ${key})`] = result
|
|
93
92
|
if (isObject(variant) && !variant.value) variant.value = result
|
|
94
93
|
}
|
|
@@ -99,8 +98,6 @@ const goThroughVariants = (theme, value) => {
|
|
|
99
98
|
const keys = Object.keys(variants)
|
|
100
99
|
keys.map(key => {
|
|
101
100
|
const variant = variants[key]
|
|
102
|
-
// console.log('=========')
|
|
103
|
-
// console.log(theme, key, variant, value)
|
|
104
101
|
if (key === 'dark' || key === 'light') setPrefersScheme(theme, key, variant, value)
|
|
105
102
|
if (key === 'inverse') setInverseTheme(theme, variant, value)
|
|
106
103
|
return theme
|
package/src/utils/index.js
CHANGED
package/src/utils/sequence.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { UNIT } from '../config'
|
|
4
|
+
import { CONFIG } from '../factory'
|
|
4
5
|
|
|
5
6
|
export const numToLetterMap = {
|
|
6
7
|
'-6': 'U',
|
|
@@ -32,14 +33,57 @@ export const numToLetterMap = {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
const setSequenceValue = ({ key, variable, value, scaling, state, index }) => {
|
|
35
|
-
state.sequence[
|
|
36
|
+
state.sequence[key] = {
|
|
36
37
|
key,
|
|
37
38
|
decimal: Math.round(value * 100) / 100,
|
|
38
39
|
val: Math.round(value),
|
|
39
40
|
scaling,
|
|
40
|
-
index
|
|
41
|
+
index,
|
|
42
|
+
variable
|
|
41
43
|
}
|
|
42
|
-
state.scales[
|
|
44
|
+
state.scales[key] = scaling
|
|
45
|
+
state.vars[variable] = scaling + state.unit
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const getSequenceValue = ({ type, prop, val = 'A', prefix = '--font-size-', unit = UNIT.default }) => {
|
|
49
|
+
if (typeof val !== 'string') console.warn(prop, val, 'is not a string')
|
|
50
|
+
|
|
51
|
+
if (val === '-' || val === '') return ({ })
|
|
52
|
+
if (
|
|
53
|
+
val === 'none' ||
|
|
54
|
+
val === 'auto' ||
|
|
55
|
+
val === 'fit-content' ||
|
|
56
|
+
val === 'min-content' ||
|
|
57
|
+
val === 'max-content'
|
|
58
|
+
) return ({ [prop]: val })
|
|
59
|
+
|
|
60
|
+
const startsWithLetterRegex = /^-?[a-zA-Z]/i
|
|
61
|
+
const startsWithLetter = startsWithLetterRegex.test(val)
|
|
62
|
+
if (!startsWithLetter) return ({ [prop]: val })
|
|
63
|
+
|
|
64
|
+
const letterVal = val.toUpperCase()
|
|
65
|
+
const isNegative = letterVal.slice(0, 1) === '-' ? '-' : ''
|
|
66
|
+
const simplyLetterVal = isNegative ? letterVal.slice(1) : letterVal
|
|
67
|
+
|
|
68
|
+
const value = type ? type[simplyLetterVal] : null
|
|
69
|
+
if (!value) return console.warn('can\'t find', type, simplyLetterVal)
|
|
70
|
+
|
|
71
|
+
if (CONFIG.useVariable) {
|
|
72
|
+
return isNegative ? {
|
|
73
|
+
[prop]: `calc(var(${prefix}${simplyLetterVal}) * -1)`
|
|
74
|
+
} : {
|
|
75
|
+
[prop]: `var(${prefix}${simplyLetterVal})`
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (unit === 'ms' || unit === 's') {
|
|
80
|
+
return ({ [prop]: isNegative + value.val + unit })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return ({
|
|
84
|
+
[prop]: isNegative + value.val + value.unit,
|
|
85
|
+
[prop]: isNegative + value.scaling + unit
|
|
86
|
+
})
|
|
43
87
|
}
|
|
44
88
|
|
|
45
89
|
export const generateSubSequence = ({ key, base, value, ratio, variable, state, index }) => {
|
|
@@ -56,8 +100,6 @@ export const generateSubSequence = ({ key, base, value, ratio, variable, state,
|
|
|
56
100
|
const middle = (first + second) / 2
|
|
57
101
|
if (diffRounded > 100) arr = [first, middle, second]
|
|
58
102
|
else arr = [first, second]
|
|
59
|
-
// else if (diffRounded > 2) arr = [first, second]
|
|
60
|
-
// else if (diffRounded > 1) arr = [middle]
|
|
61
103
|
|
|
62
104
|
arr.map((v, k) => {
|
|
63
105
|
const scaling = Math.round(v / base * 1000) / 1000
|
|
@@ -70,6 +112,7 @@ export const generateSubSequence = ({ key, base, value, ratio, variable, state,
|
|
|
70
112
|
export const generateSequence = ({ type, base, ratio, range, subSequence, ...state }) => {
|
|
71
113
|
const n = Math.abs(range[0]) + Math.abs(range[1])
|
|
72
114
|
const prefix = '--' + type + '-'
|
|
115
|
+
|
|
73
116
|
for (let i = 0; i <= n; i++) {
|
|
74
117
|
const key = range[1] - i
|
|
75
118
|
const letterKey = numToLetterMap[key]
|
|
@@ -84,38 +127,10 @@ export const generateSequence = ({ type, base, ratio, range, subSequence, ...sta
|
|
|
84
127
|
return state
|
|
85
128
|
}
|
|
86
129
|
|
|
87
|
-
export const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (val === '-' || val === '') return ({ })
|
|
91
|
-
if (val === 'none' || val === 'auto' || val === 'fit-content' || val === 'min-content' || val === 'max-content') return ({ [prop]: val })
|
|
92
|
-
|
|
93
|
-
// const startsWithLetterRegex = /^[a-zA-Z]/i
|
|
94
|
-
const startsWithLetterRegex = /^-?[a-zA-Z]/i
|
|
95
|
-
// const hasLetter = /[A-Za-z]+/.test(val)
|
|
96
|
-
const startsWithLetter = startsWithLetterRegex.test(val)
|
|
97
|
-
if (!startsWithLetter) return ({ [prop]: val })
|
|
98
|
-
|
|
99
|
-
const letterVal = val.toUpperCase()
|
|
100
|
-
const isNegative = letterVal.slice(0, 1) === '-' ? '-' : ''
|
|
101
|
-
const simplyLetterVal = isNegative ? letterVal.slice(1) : letterVal
|
|
102
|
-
|
|
103
|
-
const value = type ? type[prefix + simplyLetterVal] : null
|
|
104
|
-
if (!value) return console.warn('can\'t find', type, prefix + simplyLetterVal, simplyLetterVal)
|
|
105
|
-
|
|
106
|
-
if (unit === 'ms' || unit === 's') {
|
|
107
|
-
return ({ [prop]: isNegative + value.val + unit })
|
|
108
|
-
}
|
|
109
|
-
return ({
|
|
110
|
-
[prop]: isNegative + value.val + value.unit,
|
|
111
|
-
[prop]: isNegative + value.scaling + 'em'
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export const findHeadings = (TYPOGRAPHY) => {
|
|
116
|
-
const { h1Matches, type, sequence } = TYPOGRAPHY
|
|
130
|
+
export const findHeadings = props => {
|
|
131
|
+
const { h1Matches, sequence } = props
|
|
117
132
|
return new Array(6).fill(null).map((_, i) => {
|
|
118
133
|
const findLetter = numToLetterMap[h1Matches - i]
|
|
119
|
-
return sequence[
|
|
134
|
+
return sequence[findLetter]
|
|
120
135
|
})
|
|
121
136
|
}
|
package/src/utils/var.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { MEDIA } from '../config'
|
|
4
|
+
import { CONFIG, CSS_VARS } from '../factory'
|
|
5
|
+
import { isObjectLike } from './object'
|
|
6
|
+
|
|
7
|
+
export const setVariables = (result, key) => {
|
|
8
|
+
// CSS_VARS[result.var] =
|
|
9
|
+
if (isObjectLike(result.value)) {
|
|
10
|
+
// console.group(key)
|
|
11
|
+
// for (const key in result.value) {
|
|
12
|
+
// console.log(key, result.value[key])
|
|
13
|
+
// }
|
|
14
|
+
// console.log(result)
|
|
15
|
+
// console.groupEnd(key)
|
|
16
|
+
} else {
|
|
17
|
+
CSS_VARS[result.var] = result.value
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const applySequenceVars = (props, mediaName) => {
|
|
22
|
+
const unit = props.unit || CONFIG.UNIT.default
|
|
23
|
+
const { sequence, scales } = props
|
|
24
|
+
|
|
25
|
+
for (const key in sequence) {
|
|
26
|
+
const item = sequence[key]
|
|
27
|
+
const value = (props.type === 'duration' ? sequence[key].val : scales[key]) + unit
|
|
28
|
+
const query = MEDIA[mediaName]
|
|
29
|
+
|
|
30
|
+
if (mediaName) {
|
|
31
|
+
let underMediaQuery = CSS_VARS[`@media ${query}`]
|
|
32
|
+
if (!underMediaQuery) underMediaQuery = CSS_VARS[`@media ${query}`] = {}
|
|
33
|
+
underMediaQuery[item.variable] = value
|
|
34
|
+
} else {
|
|
35
|
+
CSS_VARS[item.variable] = value
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { CSS_VARS } from '../factory'
|
|
4
|
-
import { isObjectLike } from './object'
|
|
5
|
-
|
|
6
|
-
export const setVariables = (result, key) => {
|
|
7
|
-
// CSS_VARS[result.var] =
|
|
8
|
-
if (isObjectLike(result.value)) {
|
|
9
|
-
// console.group(key)
|
|
10
|
-
// for (const key in result.value) {
|
|
11
|
-
// console.log(key, result.value[key])
|
|
12
|
-
// }
|
|
13
|
-
// console.log(result)
|
|
14
|
-
// console.groupEnd(key)
|
|
15
|
-
} else {
|
|
16
|
-
CSS_VARS[result.var] = result.value
|
|
17
|
-
}
|
|
18
|
-
}
|