smbls 0.8.30 → 0.8.33
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/Block.js +4 -2
- package/src/Box.js +2 -2
- package/src/Link.js +1 -1
- package/src/Media.js +119 -74
- package/src/Shape/index.js +3 -74
- package/src/Shape/style.js +0 -4
- package/src/Theme.js +58 -0
- package/src/index.js +1 -0
package/package.json
CHANGED
package/src/Block.js
CHANGED
|
@@ -27,9 +27,11 @@ export const mapBasedOnRatio = (props, prop, unit) => {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const Block = {
|
|
30
|
-
props: {},
|
|
31
|
-
|
|
32
30
|
class: {
|
|
31
|
+
boxSizing: ({ props }) => props.boxSizing ? ({ display: props.boxSizing }) : {
|
|
32
|
+
boxSizing: 'border-box'
|
|
33
|
+
},
|
|
34
|
+
|
|
33
35
|
display: ({ props }) => props.display && ({ display: props.display }),
|
|
34
36
|
|
|
35
37
|
hide: ({ props }) => props.hide && ({ display: 'none' }),
|
package/src/Box.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive } from '.'
|
|
3
|
+
import { Shape, Position, Theme, Block, Text, Overflow, Transition, Transform, Responsive } from '.'
|
|
4
4
|
|
|
5
5
|
const PropsCSS = {
|
|
6
6
|
class: {
|
|
@@ -9,5 +9,5 @@ const PropsCSS = {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const Box = {
|
|
12
|
-
proto: [Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive, PropsCSS]
|
|
12
|
+
proto: [Shape, Position, Theme, Block, Text, Overflow, Transition, Transform, Responsive, PropsCSS]
|
|
13
13
|
}
|
package/src/Link.js
CHANGED
package/src/Media.js
CHANGED
|
@@ -3,93 +3,138 @@
|
|
|
3
3
|
import { merge, isArray } from '@domql/utils'
|
|
4
4
|
import { CASES as CONFIG_CASES, MEDIA as CONFIG_MEDIA, getTheme } from '@symbo.ls/scratch'
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
// const keySetters = {
|
|
7
|
+
// '@': (props, result, element, isSubtree) => {
|
|
8
|
+
// if (isSubtree) result.media = {}
|
|
9
|
+
// return applyMediaProps(props, result.media, element)
|
|
10
|
+
// },
|
|
11
|
+
// ':': (props, result, element, isSubtree) => {
|
|
12
|
+
// if (isSubtree) result.selector = {}
|
|
13
|
+
// return applySelectorProps(props, result.selector, element)
|
|
14
|
+
// },
|
|
15
|
+
// $: (props, result, element, isSubtree) => {
|
|
16
|
+
// if (isSubtree) result.case = {}
|
|
17
|
+
// return applyCaseProps(props, result.case, element)
|
|
18
|
+
// }
|
|
19
|
+
// }
|
|
20
|
+
|
|
21
|
+
// const keySetters = {
|
|
22
|
+
// '@': (props, result, element) => applyMediaProps(props, result.media, element),
|
|
23
|
+
// ':': (props, result, element) => applySelectorProps(props, result.selector, element),
|
|
24
|
+
// $: (props, result, element) => applyCaseProps(props, result.case, element)
|
|
25
|
+
// }
|
|
26
|
+
|
|
27
|
+
const keySetters = {
|
|
28
|
+
'@': (key, props, result, element, isSubtree) => applyMediaProps(key, props, isSubtree ? result : result.media, element),
|
|
29
|
+
':': (key, props, result, element, isSubtree) => applySelectorProps(key, props, isSubtree ? result : result.selector, element),
|
|
30
|
+
$: (key, props, result, element, isSubtree) => applyCaseProps(key, props, isSubtree ? result : result.case, element),
|
|
31
|
+
'.': (key, props, result, element, isSubtree) => applyCaseProps(key, props, isSubtree ? result : result.case, element)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const execClass = (key, props, result, element) => {
|
|
7
35
|
const { class: className } = element
|
|
8
|
-
const
|
|
9
|
-
for (const prop in subProps) {
|
|
10
|
-
const classnameExec = className[prop]
|
|
11
|
-
if (typeof classnameExec !== 'function') continue
|
|
12
|
-
|
|
13
|
-
let contertedToClass = classnameExec({ props: subProps })
|
|
14
|
-
if (isArray(contertedToClass)) {
|
|
15
|
-
contertedToClass = contertedToClass.reduce((a, c) => merge(a, c), {})
|
|
16
|
-
}
|
|
36
|
+
const classnameExec = className[key]
|
|
17
37
|
|
|
18
|
-
|
|
38
|
+
if (typeof classnameExec !== 'function') return
|
|
39
|
+
|
|
40
|
+
let classExec = classnameExec({ props })
|
|
41
|
+
if (isArray(classExec)) {
|
|
42
|
+
classExec = classExec.reduce((a, c) => merge(a, c), {})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const finalProp in classExec) {
|
|
46
|
+
result[finalProp] = classExec[finalProp]
|
|
19
47
|
}
|
|
20
|
-
return subPropsClassname
|
|
21
48
|
}
|
|
22
49
|
|
|
23
|
-
const
|
|
24
|
-
const
|
|
50
|
+
const convertPropsToClass = (props, result, element) => {
|
|
51
|
+
const propsClassObj = {}
|
|
25
52
|
|
|
26
|
-
for (const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!MEDIA) className.MEDIA = {}
|
|
34
|
-
className.MEDIA[mediaKey] = convertToClass(screenProps, el)
|
|
35
|
-
} else if (screen.slice(0, 1) === ':') {
|
|
36
|
-
const selectorProps = props[screen]
|
|
37
|
-
const selectorKey = `&${screen}`
|
|
38
|
-
|
|
39
|
-
const { SELECTORS } = className
|
|
40
|
-
if (!SELECTORS) className.SELECTORS = {}
|
|
41
|
-
className.SELECTORS[selectorKey] = convertToClass(selectorProps, el)
|
|
42
|
-
} else if (screen.slice(0, 1) === '$') {
|
|
43
|
-
const caseKey = screen.slice(1)
|
|
44
|
-
if (!CONFIG_CASES[caseKey]) continue
|
|
45
|
-
const caseProps = props[screen]
|
|
46
|
-
const { CASE } = className
|
|
47
|
-
if (!CASE) className.CASE = {}
|
|
48
|
-
merge(className.CASE, convertToClass(caseProps, el))
|
|
53
|
+
for (const key in props) {
|
|
54
|
+
const setter = keySetters[key.slice(0, 1)]
|
|
55
|
+
if (setter) {
|
|
56
|
+
setter(key, props[key], propsClassObj, element, true)
|
|
57
|
+
continue
|
|
58
|
+
} else {
|
|
59
|
+
execClass(key, props, propsClassObj, element)
|
|
49
60
|
}
|
|
50
61
|
}
|
|
62
|
+
|
|
63
|
+
return propsClassObj
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const applyMediaProps = (key, props, result, element) => {
|
|
67
|
+
const mediaName = CONFIG_MEDIA[key.slice(1)]
|
|
68
|
+
const mediaKey = `@media screen and ${mediaName}`
|
|
69
|
+
result[mediaKey] = convertPropsToClass(props, result, element)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const applySelectorProps = (key, props, result, element) => {
|
|
73
|
+
const selectorKey = `&${key}`
|
|
74
|
+
result[selectorKey] = convertPropsToClass(props, result, element)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const applyCaseProps = (key, props, result, element) => {
|
|
78
|
+
const caseKey = key.slice(1)
|
|
79
|
+
if (!(CONFIG_CASES[caseKey] || element.props[caseKey])) return
|
|
80
|
+
merge(result, convertPropsToClass(props, result, element))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const init = (element, s) => {
|
|
84
|
+
const { props, class: className } = element
|
|
85
|
+
|
|
86
|
+
const CLASS_NAMES = {
|
|
87
|
+
media: {},
|
|
88
|
+
selector: {},
|
|
89
|
+
case: {}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (const key in props) {
|
|
93
|
+
const setter = keySetters[key.slice(0, 1)]
|
|
94
|
+
if (setter) setter(key, props[key], CLASS_NAMES, element)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
merge(className, CLASS_NAMES)
|
|
51
98
|
}
|
|
52
99
|
|
|
53
100
|
export const Responsive = {
|
|
54
|
-
on: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// console.groupEnd(props.theme)
|
|
101
|
+
on: { init }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const initUpdate = el => {
|
|
105
|
+
// FORCE STATE UPDATE:
|
|
106
|
+
const { props, class: className } = el
|
|
107
|
+
const rootState = el.__root ? el.__root.state : el.state
|
|
108
|
+
if (el.key !== 'app') return
|
|
109
|
+
|
|
110
|
+
if (props.theme) {
|
|
111
|
+
const { theme } = props
|
|
112
|
+
// console.group(props.theme)
|
|
113
|
+
|
|
114
|
+
const convertTheme = getTheme(theme)
|
|
115
|
+
|
|
116
|
+
for (const key in convertTheme) {
|
|
117
|
+
if (key.includes('dark') || key.includes('light')) {
|
|
118
|
+
const parse = key.split(': ')[1].split(')')[0]
|
|
119
|
+
if (rootState.globalTheme === parse) {
|
|
120
|
+
props.theme = getTheme(theme[key])
|
|
121
|
+
} else props.theme = theme
|
|
122
|
+
className.MEDIA_FORCED_BY_STATE = props.theme
|
|
79
123
|
}
|
|
124
|
+
}
|
|
125
|
+
// console.groupEnd(props.theme)
|
|
126
|
+
}
|
|
80
127
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
}
|
|
128
|
+
for (const screen in props) {
|
|
129
|
+
if (screen.slice(0, 1) === '@') {
|
|
130
|
+
const mediaName = screen.slice(1)
|
|
131
|
+
const mediaKey = `@media screen and ${CONFIG_MEDIA[mediaName]}`
|
|
132
|
+
if (mediaName === 'dark' || mediaName === 'light') {
|
|
133
|
+
const { MEDIA_FORCE } = className
|
|
134
|
+
if (!MEDIA_FORCE) className.media = {}
|
|
135
|
+
if (rootState.globalTheme === mediaName) {
|
|
136
|
+
className.MEDIA_FORCED = className.MEDIA[mediaKey]
|
|
137
|
+
} else className.MEDIA_FORCED = {}
|
|
93
138
|
}
|
|
94
139
|
}
|
|
95
140
|
}
|
package/src/Shape/index.js
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import style, { SHAPES, depth } from './style'
|
|
7
|
-
|
|
8
|
-
const isBorderStyle = str =>
|
|
9
|
-
['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset', 'initial'].some(v => str.includes(v))
|
|
10
|
-
|
|
11
|
-
const diffBorder = (border, key = 'border') => {
|
|
12
|
-
const obj = {}
|
|
13
|
-
const arr = isObject(border) ? Object.values(border) : isArray(border) ? border : border.split(', ')
|
|
14
|
-
arr.map(v => {
|
|
15
|
-
if (v.includes('px')) obj[`${key}Width`] = v
|
|
16
|
-
else if (isBorderStyle(v)) obj[`${key}Style`] = v || 'solid'
|
|
17
|
-
else if (getColor(v)) obj[`${key}Color`] = getColor(v)
|
|
18
|
-
})
|
|
19
|
-
return obj
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const diffStroke = stroke => {
|
|
23
|
-
const WebkitTextStroke = stroke.split(', ').map(v => {
|
|
24
|
-
if (v.includes('px')) return v
|
|
25
|
-
else if (getColor(v)) return getColor(v)
|
|
26
|
-
}).join(' ')
|
|
27
|
-
return { WebkitTextStroke }
|
|
28
|
-
}
|
|
3
|
+
import { exec } from '@domql/utils'
|
|
4
|
+
import { SHAPES } from './style'
|
|
29
5
|
|
|
30
6
|
export const Shape = {
|
|
31
7
|
class: {
|
|
32
|
-
default: style,
|
|
33
8
|
shape: (element) => {
|
|
34
9
|
const { props } = element
|
|
35
10
|
const { shape } = props
|
|
@@ -41,54 +16,8 @@ export const Shape = {
|
|
|
41
16
|
const shapeDir = SHAPES[shape + 'Direction']
|
|
42
17
|
return shape ? shapeDir[shapeDirection || 'top'] : null
|
|
43
18
|
},
|
|
44
|
-
shapeDirectionColor: ({ props, ...el }) => props.shapeDirection ? { '&:before': { borderColor: el.class.backgroundColor } } : null
|
|
45
|
-
depth: ({ props }) => depth[props.depth],
|
|
46
|
-
round: ({ props, key, ...el }) => props.round ? (mapSpacing(props.round, 'borderRadius') || ({ borderRadius: props.round })) : null,
|
|
47
|
-
borderRadius: ({ props, key, ...el }) => props.borderRadius ? (mapSpacing(props.borderRadius, 'borderRadius') || ({ borderRadius: props.borderRadius })) : null,
|
|
48
|
-
|
|
49
|
-
theme: ({ props }) => {
|
|
50
|
-
if (!props.theme) return
|
|
51
|
-
return getTheme(props.theme)
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
color: ({ props }) => props.color ? ({ color: getColor(props.color) }) : null,
|
|
55
|
-
background: ({ props }) => props.background ? ({ backgroundColor: getColor(props.background) }) : null,
|
|
56
|
-
|
|
57
|
-
textStroke: ({ props }) => props.textStroke ? diffStroke(props.textStroke) : null,
|
|
58
|
-
|
|
59
|
-
border: ({ props }) => props.border ? diffBorder(props.border) : null,
|
|
60
|
-
borderColor: ({ props }) => props.borderColor ? ({ borderColor: getColor(props.borderColor) }) : null,
|
|
61
|
-
borderStyle: ({ props }) => props.borderStyle && ({ borderStyle: props.borderStyle }),
|
|
62
|
-
|
|
63
|
-
borderLeft: ({ props }) => props.borderLeft ? diffBorder(props.borderLeft, 'borderLeft') : null,
|
|
64
|
-
borderTop: ({ props }) => props.borderTop ? diffBorder(props.borderTop, 'borderTop') : null,
|
|
65
|
-
borderRight: ({ props }) => props.borderRight ? diffBorder(props.borderRight, 'borderRight') : null,
|
|
66
|
-
borderBottom: ({ props }) => props.borderBottom ? diffBorder(props.borderBottom, 'borderBottom') : null,
|
|
67
|
-
|
|
68
|
-
opacity: ({ props }) => props.opacity && ({ opacity: props.opacity }),
|
|
69
|
-
visibility: ({ props }) => props.visibility && ({ visibility: props.visibility })
|
|
19
|
+
shapeDirectionColor: ({ props, ...el }) => props.shapeDirection ? { '&:before': { borderColor: el.class.backgroundColor } } : null
|
|
70
20
|
}
|
|
71
|
-
|
|
72
|
-
// mode: {
|
|
73
|
-
// dark: {
|
|
74
|
-
// theme: 'white'
|
|
75
|
-
// }
|
|
76
|
-
// }
|
|
77
|
-
|
|
78
|
-
// theme: {
|
|
79
|
-
// default: 'primary',
|
|
80
|
-
// dark: 'whiteish'
|
|
81
|
-
// }
|
|
82
|
-
|
|
83
|
-
// size: {
|
|
84
|
-
// default: 'auto',
|
|
85
|
-
// mobile: 'fit'
|
|
86
|
-
// }
|
|
87
|
-
|
|
88
|
-
// padding: {
|
|
89
|
-
// default: ratio.phi,
|
|
90
|
-
// mobile: ratio.perfect
|
|
91
|
-
// }
|
|
92
21
|
}
|
|
93
22
|
|
|
94
23
|
export default Shape
|
package/src/Shape/style.js
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import { UNIT, getColor, getTheme } from '@symbo.ls/scratch'
|
|
4
4
|
|
|
5
|
-
export default {
|
|
6
|
-
boxSizing: 'border-box'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
export const depth = {
|
|
10
6
|
4: { boxShadow: `rgba(0,0,0,.10) 0 2${UNIT.default} 4${UNIT.default}` },
|
|
11
7
|
6: { boxShadow: `rgba(0,0,0,.10) 0 3${UNIT.default} 6${UNIT.default}` },
|
package/src/Theme.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isArray, isObject } from '@domql/utils'
|
|
4
|
+
import { mapSpacing, getTheme, getColor } from '@symbo.ls/scratch'
|
|
5
|
+
|
|
6
|
+
import { depth } from './Shape/style'
|
|
7
|
+
|
|
8
|
+
const isBorderStyle = str =>
|
|
9
|
+
['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset', 'initial'].some(v => str.includes(v))
|
|
10
|
+
|
|
11
|
+
const diffBorder = (border, key = 'border') => {
|
|
12
|
+
const obj = {}
|
|
13
|
+
const arr = isObject(border) ? Object.values(border) : isArray(border) ? border : border.split(', ')
|
|
14
|
+
arr.map(v => {
|
|
15
|
+
if (v.includes('px')) obj[`${key}Width`] = v // TODO: add map spacing
|
|
16
|
+
else if (isBorderStyle(v)) obj[`${key}Style`] = v || 'solid'
|
|
17
|
+
else if (getColor(v)) obj[`${key}Color`] = getColor(v)
|
|
18
|
+
})
|
|
19
|
+
return obj
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const diffStroke = stroke => {
|
|
23
|
+
const WebkitTextStroke = stroke.split(', ').map(v => {
|
|
24
|
+
if (v.includes('px')) return v
|
|
25
|
+
else if (getColor(v)) return getColor(v)
|
|
26
|
+
}).join(' ')
|
|
27
|
+
return { WebkitTextStroke }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const Theme = {
|
|
31
|
+
class: {
|
|
32
|
+
depth: ({ props }) => depth[props.depth],
|
|
33
|
+
round: ({ props, key, ...el }) => props.round ? (mapSpacing(props.round, 'borderRadius') || ({ borderRadius: props.round })) : null,
|
|
34
|
+
borderRadius: ({ props, key, ...el }) => props.borderRadius ? (mapSpacing(props.borderRadius, 'borderRadius') || ({ borderRadius: props.borderRadius })) : null,
|
|
35
|
+
|
|
36
|
+
theme: ({ props }) => {
|
|
37
|
+
if (!props.theme) return
|
|
38
|
+
return getTheme(props.theme)
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
color: ({ props }) => props.color ? ({ color: getColor(props.color) }) : null,
|
|
42
|
+
background: ({ props }) => props.background ? ({ backgroundColor: getColor(props.background) }) : null,
|
|
43
|
+
|
|
44
|
+
textStroke: ({ props }) => props.textStroke ? diffStroke(props.textStroke) : null,
|
|
45
|
+
|
|
46
|
+
border: ({ props }) => props.border ? diffBorder(props.border) : null,
|
|
47
|
+
borderColor: ({ props }) => props.borderColor ? ({ borderColor: getColor(props.borderColor) }) : null,
|
|
48
|
+
borderStyle: ({ props }) => props.borderStyle && ({ borderStyle: props.borderStyle }),
|
|
49
|
+
|
|
50
|
+
borderLeft: ({ props }) => props.borderLeft ? diffBorder(props.borderLeft, 'borderLeft') : null,
|
|
51
|
+
borderTop: ({ props }) => props.borderTop ? diffBorder(props.borderTop, 'borderTop') : null,
|
|
52
|
+
borderRight: ({ props }) => props.borderRight ? diffBorder(props.borderRight, 'borderRight') : null,
|
|
53
|
+
borderBottom: ({ props }) => props.borderBottom ? diffBorder(props.borderBottom, 'borderBottom') : null,
|
|
54
|
+
|
|
55
|
+
opacity: ({ props }) => props.opacity && ({ opacity: props.opacity }),
|
|
56
|
+
visibility: ({ props }) => props.visibility && ({ visibility: props.visibility })
|
|
57
|
+
}
|
|
58
|
+
}
|