@symbo.ls/scratch 0.2.26 → 0.3.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/document.js +5 -2
- package/src/config/spacing.js +4 -2
- package/src/config/typography.js +9 -7
- package/src/methods/create.js +1 -1
- package/src/methods/generate.js +9 -9
- package/src/methods/inject.js +1 -1
- package/src/methods/set.js +17 -3
- package/src/reset.js +9 -5
- package/src/utils/index.js +2 -0
package/package.json
CHANGED
package/src/config/document.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { FONT_FAMILY, THEME, TYPOGRAPHY } from '.'
|
|
4
|
+
import { merge } from '../utils'
|
|
4
5
|
|
|
5
|
-
export const DOCUMENT = {
|
|
6
|
+
export const DOCUMENT = {}
|
|
7
|
+
|
|
8
|
+
export const applyDocument = () => merge(DOCUMENT, {
|
|
6
9
|
theme: THEME.document,
|
|
7
10
|
fontFamily: FONT_FAMILY[Object.keys(FONT_FAMILY)[0]],
|
|
8
11
|
fontSize: TYPOGRAPHY.base,
|
|
9
12
|
lineHeight: TYPOGRAPHY.styles.lineHeight
|
|
10
|
-
}
|
|
13
|
+
})
|
package/src/config/spacing.js
CHANGED
|
@@ -6,14 +6,16 @@ import { Arrayize, fallBack, generateSequence } from '../utils'
|
|
|
6
6
|
const defaultProps = {
|
|
7
7
|
base: TYPOGRAPHY.base,
|
|
8
8
|
type: 'spacing',
|
|
9
|
-
ratio: SEQUENCE
|
|
9
|
+
ratio: SEQUENCE.phi,
|
|
10
10
|
range: [-5, +7],
|
|
11
11
|
subSequence: true,
|
|
12
12
|
sequence: {},
|
|
13
13
|
scales: {}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
export const applySpacingSequence = () => {
|
|
17
|
+
generateSequence(defaultProps)
|
|
18
|
+
}
|
|
17
19
|
|
|
18
20
|
const getSequence = (props) => {
|
|
19
21
|
if (!props) return
|
package/src/config/typography.js
CHANGED
|
@@ -17,14 +17,16 @@ const defaultProps = {
|
|
|
17
17
|
scales: {}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
export const applyTypographySequence = () => {
|
|
21
|
+
generateSequence(defaultProps)
|
|
21
22
|
|
|
22
|
-
if (defaultProps.h1Matches) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (defaultProps.h1Matches) {
|
|
24
|
+
const HEADINGS = findHeadings(defaultProps)
|
|
25
|
+
const { styles } = defaultProps
|
|
26
|
+
for (const k in HEADINGS) {
|
|
27
|
+
styles[`h${parseInt(k) + 1}`] = {
|
|
28
|
+
fontSize: `${HEADINGS[k].scaling}em`
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
}
|
package/src/methods/create.js
CHANGED
package/src/methods/generate.js
CHANGED
|
@@ -4,11 +4,11 @@ import { themeMap } from '../config/theme'
|
|
|
4
4
|
|
|
5
5
|
// var pairAsInvert = (scheme, referenced) => cx(scheme, referenced)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const mapThemeCSS = scheme => {
|
|
8
|
+
let str = ''
|
|
9
9
|
for (const prop in scheme) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const mappedProp = themeMap[prop]
|
|
11
|
+
const value = scheme[prop]
|
|
12
12
|
if (mappedProp && value) {
|
|
13
13
|
str += `${mappedProp}: ${value}`
|
|
14
14
|
}
|
|
@@ -16,10 +16,10 @@ var mapThemeCSS = scheme => {
|
|
|
16
16
|
return str
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const generateTheme = scheme => {
|
|
20
|
+
const { helpers, inverse } = scheme
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
let rule = `
|
|
23
23
|
${mapThemeCSS(scheme)}
|
|
24
24
|
`
|
|
25
25
|
|
|
@@ -28,8 +28,8 @@ var generateTheme = scheme => {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (helpers) {
|
|
31
|
-
for (
|
|
32
|
-
|
|
31
|
+
for (const prop in helpers) {
|
|
32
|
+
const value = helpers[prop]
|
|
33
33
|
rule += `.${prop} { ${value} }`
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/methods/inject.js
CHANGED
package/src/methods/set.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { applyDocument, applySpacingSequence, applyTypographySequence } from '../config'
|
|
3
4
|
import CONFIG, { CSS_VARS } from '../factory'
|
|
4
|
-
// import { FONT, FONT_FAMILY_TYPES } from '../config'
|
|
5
5
|
import {
|
|
6
6
|
isArray,
|
|
7
7
|
colorStringToRgbaArray,
|
|
@@ -87,6 +87,7 @@ const getThemeValue = theme => {
|
|
|
87
87
|
|
|
88
88
|
export const getTheme = value => {
|
|
89
89
|
const { THEME } = CONFIG
|
|
90
|
+
// console.log('theme', THEME, CONFIG)
|
|
90
91
|
if (isObjectLike(value) && value[1]) {
|
|
91
92
|
const themeName = value[0]
|
|
92
93
|
const subThemeName = value[1]
|
|
@@ -195,12 +196,17 @@ const setFontFamily = (val, key) => {
|
|
|
195
196
|
return { var: CSSvar, value: str, arr: value, type }
|
|
196
197
|
}
|
|
197
198
|
|
|
199
|
+
const setTypography = (val, key) => {
|
|
200
|
+
return val
|
|
201
|
+
}
|
|
202
|
+
|
|
198
203
|
export const SETTERS = {
|
|
199
204
|
color: setColor,
|
|
200
205
|
gradient: setGradient,
|
|
201
206
|
font: setFont,
|
|
202
207
|
font_family: setFontFamily,
|
|
203
|
-
theme: setTheme
|
|
208
|
+
theme: setTheme,
|
|
209
|
+
typography: setTypography
|
|
204
210
|
}
|
|
205
211
|
|
|
206
212
|
/**
|
|
@@ -223,12 +229,20 @@ export const setEach = (factoryName, props) => {
|
|
|
223
229
|
const FACTORY_NAME = factoryName.toUpperCase()
|
|
224
230
|
const keys = Object.keys(props)
|
|
225
231
|
keys.map(key => setValue(FACTORY_NAME, props[key], key))
|
|
232
|
+
|
|
226
233
|
return CONFIG[FACTORY_NAME]
|
|
227
234
|
}
|
|
228
235
|
|
|
229
|
-
export const set =
|
|
236
|
+
export const set = recivedConfig => {
|
|
237
|
+
const { version, ...config } = recivedConfig
|
|
230
238
|
const keys = Object.keys(config)
|
|
231
239
|
keys.map(key => setEach(key, config[key]))
|
|
240
|
+
|
|
241
|
+
// apply generic configs
|
|
242
|
+
applyTypographySequence()
|
|
243
|
+
applySpacingSequence()
|
|
244
|
+
applyDocument()
|
|
245
|
+
|
|
232
246
|
return CONFIG
|
|
233
247
|
}
|
|
234
248
|
|
package/src/reset.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import * as CONFIG from './config'
|
|
4
|
+
import { merge } from './utils'
|
|
4
5
|
|
|
5
|
-
export const RESET = {
|
|
6
|
+
export const RESET = {}
|
|
7
|
+
|
|
8
|
+
export const applyReset = () => merge(RESET, {
|
|
6
9
|
html: {
|
|
7
|
-
position: '
|
|
10
|
+
position: 'absolute',
|
|
8
11
|
overflow: 'hidden',
|
|
9
12
|
width: '100%',
|
|
10
13
|
height: '100%',
|
|
@@ -15,13 +18,14 @@ export const RESET = {
|
|
|
15
18
|
|
|
16
19
|
fontFamily: CONFIG.DOCUMENT.fontFamily,
|
|
17
20
|
|
|
18
|
-
fontSize: CONFIG.
|
|
21
|
+
fontSize: CONFIG.DOCUMENT.fontSize / CONFIG.TYPOGRAPHY.default + CONFIG.UNIT.default,
|
|
19
22
|
lineHeight: CONFIG.DOCUMENT.lineHeight
|
|
20
23
|
},
|
|
21
24
|
|
|
22
25
|
body: {
|
|
23
26
|
boxSizing: 'border-box',
|
|
24
|
-
height: '100%'
|
|
27
|
+
height: '100%',
|
|
28
|
+
margin: 0
|
|
25
29
|
},
|
|
26
30
|
|
|
27
31
|
...CONFIG.TYPOGRAPHY.styles,
|
|
@@ -32,4 +36,4 @@ export const RESET = {
|
|
|
32
36
|
padding: 0,
|
|
33
37
|
margin: 0
|
|
34
38
|
}
|
|
35
|
-
}
|
|
39
|
+
})
|
package/src/utils/index.js
CHANGED
|
@@ -257,6 +257,8 @@ export const generateSequence = ({ type, base, ratio, range, subSequence, ...sta
|
|
|
257
257
|
export const fallBack = ({ type, prop, val = 'A', prefix = '--font-size-' }) => {
|
|
258
258
|
if (typeof val !== 'string') console.warn(prop, val, 'is not a string')
|
|
259
259
|
|
|
260
|
+
if (val === 'auto') return ({ [prop]: val })
|
|
261
|
+
|
|
260
262
|
// const startsWithLetterRegex = /^[a-zA-Z]/i
|
|
261
263
|
const startsWithLetterRegex = /^-?[a-zA-Z]/i
|
|
262
264
|
// const hasLetter = /[A-Za-z]+/.test(val)
|