@symbo.ls/scratch 0.4.4 → 0.5.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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symbo.ls/scratch",
3
3
  "description": "Φ / CSS framework and methodology.",
4
4
  "author": "symbo.ls",
5
- "version": "0.4.4",
5
+ "version": "0.5.0",
6
6
  "files": [
7
7
  "src"
8
8
  ],
@@ -1,13 +1,3 @@
1
1
  'use strict'
2
2
 
3
- import { FONT_FAMILY, THEME, TYPOGRAPHY } from '.'
4
- import { getDefaultOrFirstKey, merge } from '../utils'
5
-
6
3
  export const DOCUMENT = {}
7
-
8
- export const applyDocument = () => merge(DOCUMENT, {
9
- theme: THEME.document,
10
- fontFamily: getDefaultOrFirstKey(FONT_FAMILY),
11
- fontSize: TYPOGRAPHY.base,
12
- lineHeight: TYPOGRAPHY.lineHeight
13
- })
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { CSS_VARS } from '../factory'
3
+ import { CSS_VARS } from '../factory' // eslint-disable-line
4
4
 
5
5
  export * from './sequence'
6
6
  export * from './unit'
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  import { SEQUENCE, TYPOGRAPHY } from '.'
4
- import { Arrayize, getSequenceValue, generateSequence, applySequenceVars, merge } from '../utils'
5
4
 
6
5
  const defaultProps = {
7
6
  base: TYPOGRAPHY.base,
@@ -15,93 +14,4 @@ const defaultProps = {
15
14
  vars: {}
16
15
  }
17
16
 
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
- }
44
- }
45
-
46
- export const applySpacingSequence = () => {
47
- generateSequence(defaultProps)
48
- applySequenceVars(defaultProps)
49
- runThroughMedia(defaultProps)
50
- }
51
-
52
- const getSequence = (props) => {
53
- if (!props) return
54
- const hasGenerated = Object.keys(props.sequence).length > 0
55
- return hasGenerated ? props : generateSequence(props)
56
- }
57
-
58
- export const getSpacingByKey = (val, property = 'padding', props, unit) => {
59
- const prefix = '--spacing-'
60
-
61
- const generatedSequence = getSequence(props)
62
- const type = (generatedSequence || defaultProps).sequence
63
-
64
- const stack = Arrayize(val)
65
- if (!stack) return
66
-
67
- const length = stack.length
68
-
69
- const wrapSequenceItem = (prop, i) => getSequenceValue({
70
- type,
71
- prop,
72
- val: stack[i],
73
- prefix,
74
- unit
75
- })
76
-
77
- let suffix = ''
78
- if (property === 'borderWidth') {
79
- property = 'border'
80
- suffix = 'Width'
81
- }
82
-
83
- if (length === 2) {
84
- return [
85
- wrapSequenceItem(property + 'Block' + suffix, 0),
86
- wrapSequenceItem(property + 'Inline' + suffix, 1)
87
- ]
88
- }
89
- if (length === 3) {
90
- return [
91
- wrapSequenceItem(property + 'BlockStart' + suffix, 0),
92
- wrapSequenceItem(property + 'Inline' + suffix, 1),
93
- wrapSequenceItem(property + 'BlockEnd' + suffix, 2)
94
- ]
95
- } else if (length === 4) {
96
- return [
97
- wrapSequenceItem(property + 'BlockStart' + suffix, 0),
98
- wrapSequenceItem(property + 'InlineStart' + suffix, 3),
99
- wrapSequenceItem(property + 'BlockEnd' + suffix, 2),
100
- wrapSequenceItem(property + 'InlineEnd' + suffix, 1)
101
- ]
102
- }
103
-
104
- return getSequenceValue({ type, prop: property, val, prefix, unit })
105
- }
106
-
107
17
  export const SPACING = defaultProps
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  import { SEQUENCE } from '.'
4
- import { applySequenceVars, generateSequence, getSequenceValue } from '../utils'
5
4
 
6
5
  const defaultProps = {
7
6
  default: 150,
@@ -15,17 +14,4 @@ const defaultProps = {
15
14
  vars: {}
16
15
  }
17
16
 
18
- export const applyTimingSequence = () => {
19
- generateSequence(defaultProps)
20
- applySequenceVars(defaultProps)
21
- }
22
-
23
- export const getTimingByKey = val => getSequenceValue({
24
- type: defaultProps.sequence,
25
- prop: 'duration',
26
- val,
27
- unit: 'ms',
28
- prefix: '--duration-'
29
- })
30
-
31
17
  export const TIMING = defaultProps
@@ -1,8 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { CONFIG } from '../factory'
4
- import { SEQUENCE, MEDIA } from '.'
5
- import { getSequenceValue, generateSequence, findHeadings, merge, applySequenceVars } from '../utils'
3
+ import { SEQUENCE } from './sequence'
6
4
 
7
5
  const defaultProps = {
8
6
  browserDefault: 16,
@@ -19,65 +17,4 @@ const defaultProps = {
19
17
  vars: {}
20
18
  }
21
19
 
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
- }
54
-
55
- const applyHeadings = (props) => {
56
- if (props.h1Matches) {
57
- const unit = props.unit
58
- const HEADINGS = findHeadings(props)
59
- const { styles } = props
60
- for (const k in HEADINGS) {
61
- styles[`h${parseInt(k) + 1}`] = {
62
- fontSize: CONFIG.useVariable ? `var(${HEADINGS[k].variable})` : `${HEADINGS[k].scaling}${unit}`
63
- }
64
- }
65
- }
66
- }
67
-
68
- export const applyTypographySequence = () => {
69
- generateSequence(defaultProps)
70
- applyHeadings(defaultProps)
71
- applySequenceVars(defaultProps)
72
- runThroughMedia(defaultProps)
73
- }
74
-
75
- export const getFontSizeByKey = val => getSequenceValue({
76
- type: defaultProps.sequence,
77
- prop: 'fontSize',
78
- val,
79
- unit: defaultProps.unit,
80
- prefix: '--font-size-'
81
- })
82
-
83
20
  export const TYPOGRAPHY = defaultProps
package/src/index.js CHANGED
@@ -4,4 +4,3 @@ export * from './factory'
4
4
  export * from './utils'
5
5
  export * from './set'
6
6
  export * from './config'
7
- export * from './reset'
package/src/set.js CHANGED
@@ -1,13 +1,20 @@
1
1
  'use strict'
2
2
 
3
- import { applyDocument, applySpacingSequence, applyTimingSequence, applyTypographySequence } from './config'
4
3
  import { CONFIG, CSS_VARS } from './factory' // eslint-disable-line no-unused-vars
5
- import { applyReset } from './reset'
6
- import { setColor, setGradient, setFont, setFontFamily, setTheme } from './system'
7
4
  import {
8
- setVariables,
9
- isFunction
10
- } from './utils'
5
+ setColor,
6
+ setGradient,
7
+ setFont,
8
+ setFontFamily,
9
+ setTheme,
10
+ applyTypographySequence,
11
+ applySpacingSequence,
12
+ applyReset,
13
+ applyTimingSequence,
14
+ applyDocument
15
+ } from './system'
16
+
17
+ import { isFunction } from './utils'
11
18
 
12
19
  const ENV = process.env.NODE_ENV
13
20
 
@@ -52,7 +59,7 @@ export const setValue = (FACTORY_NAME, value, key) => {
52
59
  }
53
60
 
54
61
  FACTORY[key] = result
55
- setVariables(result, key)
62
+ // setVariables(result, key)
56
63
 
57
64
  return FACTORY
58
65
  }
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ import { MEDIA } from '../config'
3
4
  import { CONFIG, CSS_VARS } from '../factory' // eslint-disable-line
4
5
 
5
6
  import {
@@ -10,26 +11,34 @@ import {
10
11
  hexToRgbArray,
11
12
  rgbArrayToHex,
12
13
  hslToRgb,
13
- getColorShade
14
+ getColorShade,
15
+ isObject
14
16
  } from '../utils'
15
17
 
16
18
  const ENV = process.env.NODE_ENV
17
19
 
18
- export const getColor = value => {
20
+ export const getColor = (value, key) => {
19
21
  if (!isString(value)) {
20
22
  if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn(value, '- type for color is not valid')
21
23
  return
22
24
  }
23
25
 
26
+ if (key && value[key]) value = value[key]
24
27
  const [name, alpha, tone] = isArray(value) ? value : value.split(' ')
25
28
  const { COLOR, GRADIENT } = CONFIG
26
- const val = COLOR[name] || GRADIENT[name]
29
+
30
+ let val = (COLOR[name] || GRADIENT[name])
27
31
 
28
32
  if (!val) {
29
33
  if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn('Can\'t find color', name)
30
34
  return value
31
35
  }
32
36
 
37
+ if (key) {
38
+ if (val[key]) val = val[key]
39
+ else if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn(value, ' - does not have ', key)
40
+ }
41
+
33
42
  // TODO: support variables
34
43
  // if (alpha) return `rgba(var(${val[shade || ''].var}), ${modifier})`
35
44
 
@@ -52,18 +61,62 @@ export const getColor = value => {
52
61
  }
53
62
  if (alpha) return `rgba(${rgb}, ${alpha})`
54
63
  return `rgb(${rgb})`
55
- } else return val.value
64
+ } else return CONFIG.useVariable ? `var(${val.var})` : val.value
56
65
  }
57
66
 
58
- export const setColor = (val, key) => {
67
+ export const getMediaColor = (value, param) => {
68
+ if (!isString(value)) {
69
+ if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn(value, '- type for color is not valid')
70
+ return
71
+ }
72
+
73
+ const [name] = isArray(value) ? value : value.split(' ')
74
+
75
+ const { COLOR, GRADIENT } = CONFIG
76
+ const val = COLOR[name] || GRADIENT[name]
77
+
78
+ const isObj = isObject(val)
79
+ if (isObj && val.value) return { [param]: getColor(value) }
80
+ else if (isObj) {
81
+ const obj = {}
82
+
83
+ for (const mediaName in val) {
84
+ const query = MEDIA[mediaName.slice(1)]
85
+ const media = `@media screen and ${query}`
86
+ obj[media] = { [param]: getColor(value, mediaName) }
87
+ }
88
+
89
+ return obj
90
+ } else {
91
+ if ((ENV === 'test' || ENV === 'development') && CONFIG.verbose) console.warn('Can\'t find color', value)
92
+ return { [param]: value }
93
+ }
94
+ }
95
+
96
+ export const setColor = (val, key, suffix) => {
59
97
  if (val.slice(0, 2) === '--') val = getColor(val.slice(2))
60
98
 
61
- const CSSVar = `--color-${key}`
99
+ if (isArray(val)) {
100
+ return {
101
+ '@light': setColor(val[0], key, 'light'),
102
+ '@dark': setColor(val[0], key, 'dark')
103
+ }
104
+ }
105
+
106
+ if (isObject(val)) {
107
+ const obj = {}
108
+ for (const variant in val) obj[variant] = setColor(val[variant], key, variant.slice(0, 1) === '@' ? variant.slice(1) : variant)
109
+ return obj
110
+ }
111
+
112
+ const CSSVar = `--color-${key}` + (suffix ? `-${suffix}` : '')
62
113
  const [r, g, b, a = 1] = colorStringToRgbaArray(val.value || val)
63
114
  const alpha = parseFloat(a.toFixed(2))
64
115
  const rgb = `${r}, ${g}, ${b}`
65
116
  const value = `rgba(${rgb}, ${alpha})`
66
117
 
118
+ if (CONFIG.useVariable) { CSS_VARS[CSSVar] = value }
119
+
67
120
  return {
68
121
  var: CSSVar,
69
122
  rgb,
@@ -72,8 +125,26 @@ export const setColor = (val, key) => {
72
125
  }
73
126
  }
74
127
 
75
- export const setGradient = (val, key) => {
76
- const CSSVar = `--gradient-${key}`
128
+ export const setGradient = (val, key, suffix) => {
129
+ if (isArray(val)) {
130
+ return {
131
+ '@light': setGradient(val[0], key, 'light'),
132
+ '@dark': setGradient(val[0], key, 'dark')
133
+ }
134
+ }
135
+
136
+ if (isObject(val)) {
137
+ const obj = {}
138
+ for (const variant in val) obj[variant] = setGradient(val[variant], key, variant.slice(0, 1) === '@' ? variant.slice(1) : variant)
139
+ return obj
140
+ }
141
+
142
+ const CSSVar = `--gradient-${key}` + (suffix ? `-${suffix}` : '')
143
+
144
+ if (CONFIG.useVariable) {
145
+ CSS_VARS[CSSVar] = val.value || val
146
+ }
147
+
77
148
  return {
78
149
  var: CSSVar,
79
150
  value: val.value || val
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ import { DOCUMENT, FONT_FAMILY, THEME, TYPOGRAPHY } from '../config'
4
+ import { getDefaultOrFirstKey, merge } from '../utils'
5
+
6
+ export const applyDocument = () => merge(DOCUMENT, {
7
+ theme: THEME.document,
8
+ fontFamily: getDefaultOrFirstKey(FONT_FAMILY),
9
+ fontSize: TYPOGRAPHY.base,
10
+ lineHeight: TYPOGRAPHY.lineHeight
11
+ })
@@ -3,3 +3,8 @@
3
3
  export * from './color'
4
4
  export * from './theme'
5
5
  export * from './font'
6
+ export * from './typography'
7
+ export * from './spacing'
8
+ export * from './timing'
9
+ export * from './document'
10
+ export * from './reset'
@@ -1,9 +1,9 @@
1
1
  'use strict'
2
2
 
3
- import * as CONFIG from './config'
4
- import { CSS_VARS } from './factory'
5
- import { getTheme } from './system'
6
- import { deepMerge, merge } from './utils'
3
+ import * as CONFIG from '../config'
4
+ import { CSS_VARS } from '../factory'
5
+ import { getTheme } from '.'
6
+ import { deepMerge, merge } from '../utils'
7
7
 
8
8
  export const applyReset = (reset = {}) => {
9
9
  return deepMerge(merge(CONFIG.RESET, reset), {
@@ -0,0 +1,93 @@
1
+ 'use strict'
2
+
3
+ import { SPACING } from '../config'
4
+ import { applySequenceVars, Arrayize, generateSequence, getSequenceValue, merge } from '../utils'
5
+
6
+ const runThroughMedia = props => {
7
+ for (const prop in props) {
8
+ const mediaProps = props[prop]
9
+ if (prop.slice(0, 1) === '@') {
10
+ const { type, base, ratio, range, subSequence, h1Matches, unit } = props
11
+
12
+ merge(mediaProps, {
13
+ type,
14
+ base,
15
+ ratio,
16
+ range,
17
+ subSequence,
18
+ h1Matches,
19
+ unit,
20
+ sequence: {},
21
+ scales: {},
22
+ styles: {},
23
+ vars: {}
24
+ })
25
+
26
+ generateSequence(mediaProps)
27
+
28
+ const mediaName = prop.slice(1)
29
+ applySequenceVars(mediaProps, mediaName)
30
+ }
31
+ }
32
+ }
33
+
34
+ export const applySpacingSequence = () => {
35
+ generateSequence(SPACING)
36
+ applySequenceVars(SPACING)
37
+ runThroughMedia(SPACING)
38
+ }
39
+
40
+ const getSequence = (props) => {
41
+ if (!props) return
42
+ const hasGenerated = Object.keys(props.sequence).length > 0
43
+ return hasGenerated ? props : generateSequence(props)
44
+ }
45
+
46
+ export const getSpacingByKey = (val, property = 'padding', props, unit) => {
47
+ const prefix = '--spacing-'
48
+
49
+ const generatedSequence = getSequence(props)
50
+ const type = (generatedSequence || SPACING).sequence
51
+
52
+ const stack = Arrayize(val)
53
+ if (!stack) return
54
+
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
+ let suffix = ''
66
+ if (property === 'borderWidth') {
67
+ property = 'border'
68
+ suffix = 'Width'
69
+ }
70
+
71
+ if (length === 2) {
72
+ return [
73
+ wrapSequenceItem(property + 'Block' + suffix, 0),
74
+ wrapSequenceItem(property + 'Inline' + suffix, 1)
75
+ ]
76
+ }
77
+ if (length === 3) {
78
+ return [
79
+ wrapSequenceItem(property + 'BlockStart' + suffix, 0),
80
+ wrapSequenceItem(property + 'Inline' + suffix, 1),
81
+ wrapSequenceItem(property + 'BlockEnd' + suffix, 2)
82
+ ]
83
+ } else if (length === 4) {
84
+ return [
85
+ wrapSequenceItem(property + 'BlockStart' + suffix, 0),
86
+ wrapSequenceItem(property + 'InlineStart' + suffix, 3),
87
+ wrapSequenceItem(property + 'BlockEnd' + suffix, 2),
88
+ wrapSequenceItem(property + 'InlineEnd' + suffix, 1)
89
+ ]
90
+ }
91
+
92
+ return getSequenceValue({ type, prop: property, val, prefix, unit })
93
+ }
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ import { TIMING } from '../config'
4
+ import {
5
+ applySequenceVars,
6
+ generateSequence,
7
+ getSequenceValue
8
+ } from '../utils'
9
+
10
+ export const applyTimingSequence = () => {
11
+ generateSequence(TIMING)
12
+ applySequenceVars(TIMING)
13
+ }
14
+
15
+ export const getTimingByKey = val => getSequenceValue({
16
+ type: TIMING.sequence,
17
+ prop: 'duration',
18
+ val,
19
+ unit: 'ms',
20
+ prefix: '--duration-'
21
+ })
@@ -0,0 +1,72 @@
1
+ 'use strict'
2
+
3
+ import { MEDIA, TYPOGRAPHY } from '../config'
4
+ import { CONFIG } from '../factory'
5
+ import {
6
+ applySequenceVars,
7
+ findHeadings,
8
+ generateSequence,
9
+ getSequenceValue,
10
+ merge
11
+ } from '../utils'
12
+
13
+ export const runThroughMedia = props => {
14
+ for (const prop in props) {
15
+ const mediaProps = props[prop]
16
+ if (prop.slice(0, 1) === '@') {
17
+ const { type, base, ratio, range, subSequence, h1Matches, unit } = props
18
+
19
+ merge(mediaProps, {
20
+ type,
21
+ base,
22
+ ratio,
23
+ range,
24
+ subSequence,
25
+ h1Matches,
26
+ unit,
27
+ sequence: {},
28
+ scales: {},
29
+ styles: {},
30
+ vars: {}
31
+ })
32
+
33
+ generateSequence(mediaProps)
34
+
35
+ const mediaName = prop.slice(1)
36
+ applySequenceVars(mediaProps, mediaName)
37
+
38
+ const query = MEDIA[mediaName]
39
+ TYPOGRAPHY.styles[`@media screen and ${query}`] = {
40
+ fontSize: mediaProps.base / TYPOGRAPHY.browserDefault + unit
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+ export const applyHeadings = (props) => {
47
+ if (props.h1Matches) {
48
+ const unit = props.unit
49
+ const HEADINGS = findHeadings(props)
50
+ const { styles } = props
51
+ for (const k in HEADINGS) {
52
+ styles[`h${parseInt(k) + 1}`] = {
53
+ fontSize: CONFIG.useVariable ? `var(${HEADINGS[k].variable})` : `${HEADINGS[k].scaling}${unit}`
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ export const applyTypographySequence = () => {
60
+ generateSequence(TYPOGRAPHY)
61
+ applyHeadings(TYPOGRAPHY)
62
+ applySequenceVars(TYPOGRAPHY)
63
+ runThroughMedia(TYPOGRAPHY)
64
+ }
65
+
66
+ export const getFontSizeByKey = val => getSequenceValue({
67
+ type: TYPOGRAPHY.sequence,
68
+ prop: 'fontSize',
69
+ val,
70
+ unit: TYPOGRAPHY.unit,
71
+ prefix: '--font-size-'
72
+ })