smbls 0.8.26 → 0.8.29
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 +2 -2
- package/src/Block/index.js +3 -3
- package/src/Box/index.js +3 -1
- package/src/Media.js +92 -0
- package/src/Shape/index.js +6 -2
- package/src/Shape/style.js +4 -4
- package/src/Media/index.js +0 -71
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"description": "UI Library built on Scratch and DOMQL",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "symbo.ls",
|
|
6
|
-
"version": "0.8.
|
|
7
|
-
"repository": "https://github.com/
|
|
6
|
+
"version": "0.8.29",
|
|
7
|
+
"repository": "https://github.com/symbo-ls/smbls",
|
|
8
8
|
"main": "src/index.js",
|
|
9
9
|
"files": [
|
|
10
10
|
"src"
|
package/src/Block/index.js
CHANGED
|
@@ -38,10 +38,10 @@ export const Block = {
|
|
|
38
38
|
height: ({ props }) => props.height && mapBasedOnRatio(props, 'height'),
|
|
39
39
|
boxSize: ({ props }) => {
|
|
40
40
|
if (typeof props.boxSize !== 'string') return
|
|
41
|
-
const [
|
|
41
|
+
const [height, width] = props.boxSize.split(' ')
|
|
42
42
|
return {
|
|
43
|
-
...mapSpacing(
|
|
44
|
-
...mapSpacing(
|
|
43
|
+
...mapSpacing(height, 'height'),
|
|
44
|
+
...mapSpacing(width, 'width')
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
|
package/src/Box/index.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
import { Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive } from '..'
|
|
4
4
|
|
|
5
5
|
const PropsCSS = {
|
|
6
|
-
class: {
|
|
6
|
+
class: {
|
|
7
|
+
propsCSS: ({ props }) => props && props.css
|
|
8
|
+
}
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export const Box = {
|
package/src/Media.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { merge } from '@domql/utils'
|
|
4
|
+
import { CASES as CONFIG_CASES, MEDIA as CONFIG_MEDIA, getTheme } from '@symbo.ls/scratch'
|
|
5
|
+
|
|
6
|
+
const convertToClass = (subProps, element) => {
|
|
7
|
+
const { class: className } = element
|
|
8
|
+
const subPropsClassname = {}
|
|
9
|
+
for (const prop in subProps) {
|
|
10
|
+
const classnameExec = className[prop]
|
|
11
|
+
if (typeof classnameExec !== 'function') continue
|
|
12
|
+
|
|
13
|
+
const contertedToClass = classnameExec({ props: subProps })
|
|
14
|
+
for (const finalProp in contertedToClass) subPropsClassname[finalProp] = contertedToClass[finalProp]
|
|
15
|
+
}
|
|
16
|
+
return subPropsClassname
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const init = (el, s) => {
|
|
20
|
+
const { props, class: className } = el
|
|
21
|
+
|
|
22
|
+
for (const screen in props) {
|
|
23
|
+
if (screen.slice(0, 1) === '@') {
|
|
24
|
+
const mediaName = CONFIG_MEDIA[screen.slice(1)]
|
|
25
|
+
const mediaKey = `@media screen and ${mediaName}`
|
|
26
|
+
const screenProps = props[screen]
|
|
27
|
+
|
|
28
|
+
const { MEDIA } = className
|
|
29
|
+
if (!MEDIA) className.MEDIA = {}
|
|
30
|
+
className.MEDIA[mediaKey] = convertToClass(screenProps, el)
|
|
31
|
+
} else if (screen.slice(0, 1) === ':') {
|
|
32
|
+
const selectorProps = props[screen]
|
|
33
|
+
const selectorKey = `&${screen}`
|
|
34
|
+
|
|
35
|
+
const { SELECTORS } = className
|
|
36
|
+
if (!SELECTORS) className.SELECTORS = {}
|
|
37
|
+
className.SELECTORS[selectorKey] = convertToClass(selectorProps, el)
|
|
38
|
+
} else if (screen.slice(0, 1) === '$') {
|
|
39
|
+
const caseKey = screen.slice(1)
|
|
40
|
+
if (!CONFIG_CASES[caseKey]) continue
|
|
41
|
+
|
|
42
|
+
const caseProps = props[screen]
|
|
43
|
+
const execCaseProps = convertToClass(caseProps, el)
|
|
44
|
+
|
|
45
|
+
const { CASE } = className
|
|
46
|
+
if (!CASE) className.CASE = {}
|
|
47
|
+
merge(className.CASE, execCaseProps)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const Responsive = {
|
|
53
|
+
on: {
|
|
54
|
+
init,
|
|
55
|
+
initUpdate: el => {
|
|
56
|
+
const { props, class: className } = el
|
|
57
|
+
const rootState = el.__root ? el.__root.state : el.state
|
|
58
|
+
// console.log(props)
|
|
59
|
+
|
|
60
|
+
if (props.theme) {
|
|
61
|
+
// console.group(props.theme)
|
|
62
|
+
const { theme } = props
|
|
63
|
+
|
|
64
|
+
for (const key in theme) {
|
|
65
|
+
if (key.includes('dark') || key.includes('light')) {
|
|
66
|
+
const parse = key.split(': ')[1].split(')')[0]
|
|
67
|
+
if (rootState.globalTheme === parse) {
|
|
68
|
+
props.theme = getTheme(theme[key])
|
|
69
|
+
} else props.theme = theme
|
|
70
|
+
className.MEDIA_FORCED_BY_STATE = props.theme
|
|
71
|
+
props.generatedTheme = true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// console.groupEnd(props.theme)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (const screen in props) {
|
|
78
|
+
if (screen.slice(0, 1) === '@') {
|
|
79
|
+
const mediaName = screen.slice(1)
|
|
80
|
+
const mediaKey = `@media screen and ${CONFIG_MEDIA[mediaName]}`
|
|
81
|
+
if (mediaName === 'dark' || mediaName === 'light') {
|
|
82
|
+
const { MEDIA_FORCE } = className
|
|
83
|
+
if (!MEDIA_FORCE) className.media = {}
|
|
84
|
+
if (rootState.globalTheme === mediaName) {
|
|
85
|
+
className.MEDIA_FORCED = className.MEDIA[mediaKey]
|
|
86
|
+
} else className.MEDIA_FORCED = {}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/Shape/index.js
CHANGED
|
@@ -45,10 +45,14 @@ export const Shape = {
|
|
|
45
45
|
depth: ({ props }) => depth[props.depth],
|
|
46
46
|
round: ({ props, key, ...el }) => props.round ? (mapSpacing(props.round, 'borderRadius') || ({ borderRadius: props.round })) : null,
|
|
47
47
|
borderRadius: ({ props, key, ...el }) => props.borderRadius ? (mapSpacing(props.borderRadius, 'borderRadius') || ({ borderRadius: props.borderRadius })) : null,
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
theme: ({ props }) => {
|
|
50
|
+
if (!props.theme) return
|
|
51
|
+
return getTheme(props.theme)
|
|
52
|
+
},
|
|
53
|
+
|
|
49
54
|
color: ({ props }) => props.color ? ({ color: getColor(props.color) }) : null,
|
|
50
55
|
background: ({ props }) => props.background ? ({ backgroundColor: getColor(props.background) }) : null,
|
|
51
|
-
// border: ({ props }) => props.border ? ({ borderColor: getColor(props.border) }) : null,
|
|
52
56
|
|
|
53
57
|
textStroke: ({ props }) => props.textStroke ? diffStroke(props.textStroke) : null,
|
|
54
58
|
|
package/src/Shape/style.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { UNIT, getColor } from '@symbo.ls/scratch'
|
|
3
|
+
import { UNIT, getColor, getTheme } from '@symbo.ls/scratch'
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
boxSizing: 'border-box'
|
|
@@ -27,7 +27,7 @@ export const SHAPES = {
|
|
|
27
27
|
display: 'block',
|
|
28
28
|
width: '0px',
|
|
29
29
|
height: '0px',
|
|
30
|
-
border: `6px solid ${getColor(props.background)}`,
|
|
30
|
+
border: `6px solid ${getColor(props.background) || (props.theme && getTheme(props.theme).backgroundColor)}`,
|
|
31
31
|
position: 'absolute',
|
|
32
32
|
borderRadius: '2px'
|
|
33
33
|
}
|
|
@@ -71,10 +71,10 @@ export const SHAPES = {
|
|
|
71
71
|
display: 'block',
|
|
72
72
|
width: '0',
|
|
73
73
|
height: '0',
|
|
74
|
-
border: `16px solid ${getColor(props.background)}`,
|
|
74
|
+
border: `16px solid ${getColor(props.background) || (props.theme && getTheme(props.theme).backgroundColor)}`,
|
|
75
75
|
borderRadius: '6px',
|
|
76
76
|
position: 'absolute'
|
|
77
|
-
}
|
|
77
|
+
}
|
|
78
78
|
}),
|
|
79
79
|
|
|
80
80
|
tagDirection: {
|
package/src/Media/index.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { MEDIA as BREAKPOINTS } from '@symbo.ls/scratch'
|
|
4
|
-
|
|
5
|
-
export const Responsive = {
|
|
6
|
-
on: {
|
|
7
|
-
init: (el, s) => {
|
|
8
|
-
const { props } = el
|
|
9
|
-
|
|
10
|
-
for (const screen in props) {
|
|
11
|
-
if (screen.slice(0, 1) === '@') {
|
|
12
|
-
const mediaName = screen.slice(1)
|
|
13
|
-
const responsiveKey = `@media screen and ${BREAKPOINTS[mediaName]}`
|
|
14
|
-
const screenProps = props[screen]
|
|
15
|
-
const calculatedScreenProps = {}
|
|
16
|
-
|
|
17
|
-
for (const prop in screenProps) {
|
|
18
|
-
// if (!el.class || !el.class[prop]) return
|
|
19
|
-
// const classProp = el.class[prop]
|
|
20
|
-
const classProp = el.class[prop]
|
|
21
|
-
if (typeof classProp !== 'function') continue
|
|
22
|
-
let calculatedProp = classProp({ props: screenProps })
|
|
23
|
-
|
|
24
|
-
if (Array.isArray(calculatedProp)) {
|
|
25
|
-
calculatedProp = Object.assign({}, ...calculatedProp)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (const finalProp in calculatedProp) {
|
|
29
|
-
calculatedScreenProps[finalProp] = calculatedProp[finalProp]
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const { MEDIA } = el.class
|
|
34
|
-
if (MEDIA) MEDIA[responsiveKey] = calculatedScreenProps
|
|
35
|
-
else {
|
|
36
|
-
el.class.MEDIA = {
|
|
37
|
-
[responsiveKey]: calculatedScreenProps
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
} else if (screen.slice(0, 1) === ':') {
|
|
41
|
-
const selectorProps = {}
|
|
42
|
-
// const selectorName = screen.slice(1)
|
|
43
|
-
const underSelectorProps = props[screen]
|
|
44
|
-
const selectorKey = `&${screen}`
|
|
45
|
-
|
|
46
|
-
for (const prop in underSelectorProps) {
|
|
47
|
-
const classProp = el.class[prop]
|
|
48
|
-
if (typeof classProp !== 'function') continue
|
|
49
|
-
let calculatedProp = classProp({ props: underSelectorProps })
|
|
50
|
-
|
|
51
|
-
if (Array.isArray(calculatedProp)) {
|
|
52
|
-
calculatedProp = Object.assign({}, ...calculatedProp)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
for (const finalProp in calculatedProp) {
|
|
56
|
-
selectorProps[finalProp] = calculatedProp[finalProp]
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const { SELECTORS } = el.class
|
|
61
|
-
if (SELECTORS) SELECTORS[selectorKey] = selectorProps
|
|
62
|
-
else {
|
|
63
|
-
el.class.SELECTORS = {
|
|
64
|
-
[selectorKey]: selectorProps
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|