@symbo.ls/scratch 2.11.226 → 2.11.228
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 +196 -83
- package/dist/cjs/set.js +183 -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 +184 -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 +153 -60
- package/dist/cjs/transforms/index.js +47 -13
- 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 +36 -26
- package/src/system/typography.js +49 -29
- package/src/utils/sequence.js +54 -14
- package/src/utils/var.js +84 -21
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
|
+
}
|