@symbo.ls/scratch 2.11.225 → 2.11.227
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/defaultConfig/index.js +3 -0
- package/dist/cjs/defaultConfig/spacing.js +2 -0
- package/dist/cjs/defaultConfig/timing.js +1 -0
- package/dist/cjs/defaultConfig/typography.js +1 -0
- package/dist/cjs/factory.js +3 -0
- package/dist/cjs/index.js +210 -87
- package/dist/cjs/set.js +181 -82
- package/dist/cjs/system/color.js +3 -0
- package/dist/cjs/system/document.js +3 -0
- package/dist/cjs/system/font.js +3 -0
- package/dist/cjs/system/index.js +182 -83
- package/dist/cjs/system/reset.js +3 -0
- package/dist/cjs/system/shadow.js +47 -13
- package/dist/cjs/system/spacing.js +143 -58
- package/dist/cjs/system/svg.js +3 -0
- package/dist/cjs/system/theme.js +3 -0
- package/dist/cjs/system/timing.js +82 -35
- package/dist/cjs/system/typography.js +151 -60
- package/dist/cjs/transforms/index.js +63 -17
- package/dist/cjs/utils/index.js +118 -35
- package/dist/cjs/utils/sequence.js +55 -14
- package/dist/cjs/utils/sprite.js +3 -0
- package/dist/cjs/utils/var.js +101 -34
- package/package.json +2 -2
- package/src/defaultConfig/spacing.js +1 -0
- package/src/defaultConfig/timing.js +1 -0
- package/src/defaultConfig/typography.js +1 -0
- package/src/system/spacing.js +35 -26
- package/src/system/typography.js +42 -25
- package/src/transforms/index.js +12 -4
- package/src/utils/sequence.js +54 -14
- package/src/utils/var.js +84 -21
package/src/system/spacing.js
CHANGED
|
@@ -5,36 +5,45 @@ import { isString, merge } from '@domql/utils'
|
|
|
5
5
|
|
|
6
6
|
import { getActiveConfig } from '../factory.js'
|
|
7
7
|
import {
|
|
8
|
+
applyMediaSequenceVars,
|
|
8
9
|
applySequenceVars,
|
|
9
10
|
generateSequence,
|
|
10
11
|
getSequenceValuePropertyPair
|
|
11
12
|
} from '../utils'
|
|
12
13
|
|
|
13
|
-
const runThroughMedia =
|
|
14
|
-
for (const prop in
|
|
15
|
-
const mediaProps =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
const runThroughMedia = FACTORY => {
|
|
15
|
+
for (const prop in FACTORY) {
|
|
16
|
+
const mediaProps = FACTORY[prop]
|
|
17
|
+
|
|
18
|
+
const isMediaName = prop.slice(0, 1) === '@'
|
|
19
|
+
if (!isMediaName) continue
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
type,
|
|
23
|
+
base,
|
|
24
|
+
ratio,
|
|
25
|
+
range,
|
|
26
|
+
subSequence,
|
|
27
|
+
h1Matches,
|
|
28
|
+
unit
|
|
29
|
+
} = FACTORY
|
|
30
|
+
|
|
31
|
+
merge(mediaProps, {
|
|
32
|
+
type,
|
|
33
|
+
base,
|
|
34
|
+
ratio,
|
|
35
|
+
range,
|
|
36
|
+
subSequence,
|
|
37
|
+
h1Matches,
|
|
38
|
+
unit,
|
|
39
|
+
sequence: {},
|
|
40
|
+
scales: {},
|
|
41
|
+
templates: {},
|
|
42
|
+
vars: {}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
generateSequence(mediaProps)
|
|
46
|
+
applyMediaSequenceVars(FACTORY, prop)
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
|
|
@@ -127,7 +136,7 @@ export const getSpacingBasedOnRatio = (props, propertyName, val) => {
|
|
|
127
136
|
})
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
applySequenceVars(sequenceProps,
|
|
139
|
+
applySequenceVars(sequenceProps, { useDefault: false })
|
|
131
140
|
|
|
132
141
|
return getSpacingByKey(value, propertyName, sequenceProps)
|
|
133
142
|
}
|
package/src/system/typography.js
CHANGED
|
@@ -4,45 +4,62 @@ import { merge } from '@domql/utils'
|
|
|
4
4
|
import { getActiveConfig } from '../factory.js'
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
+
applyMediaSequenceVars,
|
|
7
8
|
applySequenceVars,
|
|
8
9
|
findHeadings,
|
|
9
10
|
generateSequence,
|
|
10
11
|
getSequenceValuePropertyPair
|
|
11
12
|
} from '../utils'
|
|
12
13
|
|
|
13
|
-
export const runThroughMedia =
|
|
14
|
+
export const runThroughMedia = FACTORY => {
|
|
14
15
|
const CONFIG = getActiveConfig()
|
|
15
16
|
const { TYPOGRAPHY, MEDIA } = CONFIG
|
|
16
17
|
|
|
17
|
-
for (const prop in
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
for (const prop in FACTORY) {
|
|
19
|
+
const isPropMedia = prop.slice(0, 1) === '@'
|
|
20
|
+
const mediaValue = FACTORY[prop]
|
|
21
|
+
if (!isPropMedia) continue
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
base,
|
|
25
|
-
ratio,
|
|
26
|
-
range,
|
|
27
|
-
subSequence,
|
|
28
|
-
h1Matches,
|
|
29
|
-
unit,
|
|
30
|
-
sequence: {},
|
|
31
|
-
scales: {},
|
|
32
|
-
templates: {},
|
|
33
|
-
vars: {}
|
|
34
|
-
})
|
|
23
|
+
const { mediaRegenerate } = FACTORY
|
|
24
|
+
const mediaName = prop.slice(1)
|
|
35
25
|
|
|
36
|
-
|
|
26
|
+
const {
|
|
27
|
+
type,
|
|
28
|
+
base,
|
|
29
|
+
ratio,
|
|
30
|
+
range,
|
|
31
|
+
subSequence,
|
|
32
|
+
h1Matches,
|
|
33
|
+
unit
|
|
34
|
+
} = FACTORY
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
merge(mediaValue, {
|
|
37
|
+
type,
|
|
38
|
+
base,
|
|
39
|
+
ratio,
|
|
40
|
+
range,
|
|
41
|
+
subSequence,
|
|
42
|
+
h1Matches,
|
|
43
|
+
unit,
|
|
44
|
+
sequence: {},
|
|
45
|
+
scales: {},
|
|
46
|
+
templates: {},
|
|
47
|
+
vars: {}
|
|
48
|
+
})
|
|
40
49
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
const query = MEDIA[mediaName]
|
|
51
|
+
TYPOGRAPHY.templates[`@media screen and ${query}`] = {
|
|
52
|
+
fontSize: mediaValue.base / TYPOGRAPHY.browserDefault + unit
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!mediaRegenerate) {
|
|
56
|
+
applyMediaSequenceVars(FACTORY, prop)
|
|
57
|
+
continue
|
|
45
58
|
}
|
|
59
|
+
|
|
60
|
+
generateSequence(mediaValue)
|
|
61
|
+
|
|
62
|
+
applyMediaSequenceVars(FACTORY, prop)
|
|
46
63
|
}
|
|
47
64
|
}
|
|
48
65
|
|
package/src/transforms/index.js
CHANGED
|
@@ -46,11 +46,19 @@ export const transformTextStroke = stroke => {
|
|
|
46
46
|
}).join(' ')
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export const transformShadow = (sh, globalTheme) =>
|
|
50
|
-
return sh.split(',').map(shadow => getShadow(shadow, globalTheme)).join(',')
|
|
51
|
-
}
|
|
49
|
+
export const transformShadow = (sh, globalTheme) => getShadow(sh, globalTheme)
|
|
52
50
|
|
|
53
|
-
export const transformBoxShadow = (
|
|
51
|
+
export const transformBoxShadow = shadows => shadows.split('|').map(shadow => {
|
|
52
|
+
return shadow.split(', ').map(v => {
|
|
53
|
+
v = v.trim()
|
|
54
|
+
if (v.slice(0, 2) === '--') return `var(${v})`
|
|
55
|
+
if (getColor(v).length > 2) return getColor(v)
|
|
56
|
+
if (v.includes('px') || v.slice(-2) === 'em') return v
|
|
57
|
+
const arr = v.split(' ')
|
|
58
|
+
if (!arr.length) return v
|
|
59
|
+
return arr.map(v => getSpacingByKey(v, 'shadow').shadow).join(' ')
|
|
60
|
+
}).join(' ')
|
|
61
|
+
}).join(',')
|
|
54
62
|
|
|
55
63
|
export const transformBackgroundImage = (backgroundImage, globalTheme) => {
|
|
56
64
|
const CONFIG = getActiveConfig()
|
package/src/utils/sequence.js
CHANGED
|
@@ -34,50 +34,88 @@ export const numToLetterMap = {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const setSequenceValue = (props, sequenceProps) => {
|
|
37
|
-
const { key, variable, value, scaling, index } = props
|
|
37
|
+
const { key, variable, value, scaling, index, scalingVariable } = props
|
|
38
38
|
sequenceProps.sequence[key] = {
|
|
39
39
|
key,
|
|
40
40
|
decimal: ~~(value * 100) / 100,
|
|
41
41
|
val: ~~(value),
|
|
42
42
|
scaling,
|
|
43
43
|
index,
|
|
44
|
+
scalingVariable,
|
|
44
45
|
variable
|
|
45
46
|
}
|
|
46
47
|
sequenceProps.scales[key] = scaling
|
|
47
48
|
sequenceProps.vars[variable] = scaling + sequenceProps.unit
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
export const setScalingVar = (key, sequenceProps) => {
|
|
52
|
+
const { type } = sequenceProps
|
|
53
|
+
if (key === 0) return '1em'
|
|
54
|
+
|
|
55
|
+
const prefix = '--' + (type && type.replace('.', '-'))
|
|
56
|
+
const ratioVar = `${prefix}-ratio`
|
|
57
|
+
|
|
58
|
+
if (key > 0) {
|
|
59
|
+
const prevLetterKey = numToLetterMap[key - 1]
|
|
60
|
+
return `calc(var(${prefix}-${prevLetterKey}) * var(${ratioVar}))`
|
|
61
|
+
}
|
|
62
|
+
if (key < 0) {
|
|
63
|
+
const nextLetterKey = numToLetterMap[key + 1]
|
|
64
|
+
return `calc(var(${prefix}-${nextLetterKey}) / var(${ratioVar}))`
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const setSubScalingVar = (index, arr, variable, sequenceProps) => {
|
|
69
|
+
const { type } = sequenceProps
|
|
70
|
+
const skipMiddle = index === 2 && arr.length === 2
|
|
71
|
+
const indexMapWithLength = skipMiddle ? index + 1 : index
|
|
72
|
+
|
|
73
|
+
const prefix = '--' + (type && type.replace('.', '-'))
|
|
74
|
+
const subRatioVarPrefix = `${prefix}-sub-ratio-`
|
|
75
|
+
|
|
76
|
+
return `calc(var(${variable}) * var(${subRatioVarPrefix + indexMapWithLength}))`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const getSubratioDifference = (base, ratio) => {
|
|
80
|
+
const diff = (base * ratio - base)
|
|
81
|
+
const subRatio = diff / 1.618
|
|
82
|
+
const first = (base * ratio - subRatio)
|
|
83
|
+
const second = base + subRatio
|
|
84
|
+
const middle = (first + second) / 2
|
|
85
|
+
return [first, middle, second]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const getSubratio = (base, ratio) => {
|
|
89
|
+
return getSubratioDifference(base, ratio).map(v => v / base)
|
|
90
|
+
}
|
|
91
|
+
|
|
50
92
|
export const generateSubSequence = (props, sequenceProps) => {
|
|
51
93
|
const { key, base, value, ratio, variable, index } = props
|
|
52
94
|
|
|
53
95
|
const next = value * ratio
|
|
54
|
-
const
|
|
55
|
-
const smallscale = diff / 1.618
|
|
56
|
-
|
|
57
|
-
const valueRounded = ~~(value)
|
|
58
|
-
const nextRounded = ~~(next)
|
|
59
|
-
const diffRounded = nextRounded - valueRounded
|
|
96
|
+
const diffRounded = ~~next - ~~value
|
|
60
97
|
|
|
61
|
-
let arr
|
|
62
|
-
const first =
|
|
63
|
-
const second = value + smallscale
|
|
64
|
-
const middle = (first + second) / 2
|
|
98
|
+
let arr
|
|
99
|
+
const [first, middle, second] = getSubratioDifference(value, ratio)
|
|
65
100
|
if (diffRounded > 16) arr = [first, middle, second]
|
|
66
101
|
else arr = [first, second]
|
|
67
102
|
|
|
68
|
-
arr.
|
|
103
|
+
arr.forEach((v, k) => {
|
|
69
104
|
const scaling = ~~(v / base * 1000) / 1000
|
|
70
105
|
const newVar = variable + (k + 1)
|
|
106
|
+
const newIndex = index + (k + 1) / 10
|
|
107
|
+
const scalingVariable = setSubScalingVar(k + 1, arr, variable, sequenceProps)
|
|
71
108
|
|
|
72
109
|
const props = {
|
|
73
110
|
key: key + (k + 1),
|
|
74
111
|
variable: newVar,
|
|
75
112
|
value: v,
|
|
76
113
|
scaling,
|
|
77
|
-
|
|
114
|
+
scalingVariable,
|
|
115
|
+
index: newIndex
|
|
78
116
|
}
|
|
79
117
|
|
|
80
|
-
|
|
118
|
+
setSequenceValue(props, sequenceProps)
|
|
81
119
|
})
|
|
82
120
|
}
|
|
83
121
|
|
|
@@ -106,6 +144,7 @@ export const generateSequence = (sequenceProps) => {
|
|
|
106
144
|
const value = switchSequenceOnNegative(key, base, ratio)
|
|
107
145
|
const scaling = ~~(value / base * 100) / 100
|
|
108
146
|
const variable = prefix + letterKey
|
|
147
|
+
const scalingVariable = setScalingVar(key, sequenceProps)
|
|
109
148
|
|
|
110
149
|
const props = {
|
|
111
150
|
key: letterKey,
|
|
@@ -113,6 +152,7 @@ export const generateSequence = (sequenceProps) => {
|
|
|
113
152
|
value,
|
|
114
153
|
base,
|
|
115
154
|
scaling,
|
|
155
|
+
scalingVariable,
|
|
116
156
|
ratio,
|
|
117
157
|
index: key
|
|
118
158
|
}
|
package/src/utils/var.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { isObjectLike } from '@domql/utils'
|
|
4
4
|
import { getActiveConfig } from '../factory.js'
|
|
5
|
+
import { getSubratio } from './sequence.js'
|
|
5
6
|
|
|
6
7
|
export const setVariables = (result, key) => {
|
|
7
8
|
const CONFIG = getActiveConfig()
|
|
@@ -14,33 +15,95 @@ export const setVariables = (result, key) => {
|
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export const
|
|
18
|
+
export const applyGlobalVars = (vars, obj, options) => {
|
|
18
19
|
const CONFIG = getActiveConfig()
|
|
19
|
-
const { UNIT
|
|
20
|
+
const { UNIT } = CONFIG
|
|
21
|
+
const unit = obj.unit || UNIT.default
|
|
22
|
+
const { base, ratio, type } = obj
|
|
23
|
+
const prefix = '--' + (type && type.replace('.', '-'))
|
|
24
|
+
vars[`${prefix}-base`] = base
|
|
25
|
+
vars[`${prefix}-unit`] = unit
|
|
26
|
+
const ratioVar = `${prefix}-ratio`
|
|
27
|
+
vars[ratioVar] = ratio
|
|
28
|
+
|
|
29
|
+
const [first, middle, second] = getSubratio(base, ratio)
|
|
30
|
+
vars[`${prefix}-sub-ratio-1`] = first
|
|
31
|
+
vars[`${prefix}-sub-ratio-2`] = middle
|
|
32
|
+
vars[`${prefix}-sub-ratio-3`] = second
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const applySequenceVars = (FACTORY, options = {}) => {
|
|
36
|
+
const CONFIG = getActiveConfig()
|
|
37
|
+
const { UNIT, TIMING, CSS_VARS } = CONFIG
|
|
38
|
+
|
|
39
|
+
const unit = FACTORY.unit || UNIT.default
|
|
40
|
+
const { mediaRegenerate, sequence, scales } = FACTORY
|
|
20
41
|
|
|
21
|
-
|
|
22
|
-
|
|
42
|
+
if (!mediaRegenerate) {
|
|
43
|
+
applyGlobalVars(CSS_VARS, FACTORY, options)
|
|
44
|
+
}
|
|
23
45
|
|
|
24
46
|
for (const key in sequence) {
|
|
25
47
|
const item = sequence[key]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
|
|
49
|
+
const value = (FACTORY.type === TIMING.type
|
|
50
|
+
? sequence[key].val
|
|
51
|
+
: scales[key]
|
|
52
|
+
) + unit
|
|
53
|
+
|
|
54
|
+
if (!mediaRegenerate) {
|
|
55
|
+
CSS_VARS[item.variable + '_default'] = value
|
|
56
|
+
CSS_VARS[item.variable] = item.scalingVariable
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (options.useDefault === false) {
|
|
61
|
+
CSS_VARS[item.variable] = value
|
|
37
62
|
} else {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} else {
|
|
41
|
-
CSS_VARS[item.variable + '_default'] = value
|
|
42
|
-
CSS_VARS[item.variable] = `var(${item.variable + '_default'})`
|
|
43
|
-
}
|
|
63
|
+
CSS_VARS[item.variable + '_default'] = value
|
|
64
|
+
CSS_VARS[item.variable] = `var(${item.variable + '_default'})`
|
|
44
65
|
}
|
|
45
66
|
}
|
|
46
67
|
}
|
|
68
|
+
|
|
69
|
+
export const applyMediaSequenceVars = (FACTORY, media, options = {}) => {
|
|
70
|
+
const CONFIG = getActiveConfig()
|
|
71
|
+
const { UNIT, MEDIA, TIMING, CSS_VARS } = CONFIG
|
|
72
|
+
|
|
73
|
+
const mediaName = media.slice(1)
|
|
74
|
+
|
|
75
|
+
const unit = FACTORY.unit || UNIT.default
|
|
76
|
+
const { mediaRegenerate } = FACTORY
|
|
77
|
+
const { sequence, scales } = FACTORY[media]
|
|
78
|
+
|
|
79
|
+
const query = MEDIA[mediaName]
|
|
80
|
+
if (!query && CONFIG.verbose) console.warn('Can\'t find media query ', query)
|
|
81
|
+
|
|
82
|
+
// if mediaRegenerate is not applied ratio and and sequence sizes
|
|
83
|
+
// will be applied using CSS vars
|
|
84
|
+
if (!mediaRegenerate) {
|
|
85
|
+
let underMediaQuery = CSS_VARS[`@media ${query}`]
|
|
86
|
+
if (!underMediaQuery) underMediaQuery = CSS_VARS[`@media ${query}`] = {}
|
|
87
|
+
applyGlobalVars(underMediaQuery, FACTORY[media], options)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const key in sequence) {
|
|
92
|
+
const item = sequence[key]
|
|
93
|
+
|
|
94
|
+
const value = (FACTORY.type === TIMING.type
|
|
95
|
+
? sequence[key].val
|
|
96
|
+
: scales[key]
|
|
97
|
+
) + unit
|
|
98
|
+
|
|
99
|
+
if (!query && CONFIG.verbose) console.warn('Can\'t find query ', query)
|
|
100
|
+
|
|
101
|
+
let underMediaQuery = CSS_VARS[`@media ${query}`]
|
|
102
|
+
if (!underMediaQuery) underMediaQuery = CSS_VARS[`@media ${query}`] = {}
|
|
103
|
+
|
|
104
|
+
underMediaQuery[item.variable] = `var(${item.variable + '_' + mediaName})`
|
|
105
|
+
CSS_VARS[item.variable + '_' + mediaName] = value
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(CSS_VARS)
|
|
109
|
+
}
|