smbls 0.8.28 → 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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "UI Library built on Scratch and DOMQL",
4
4
  "private": false,
5
5
  "author": "symbo.ls",
6
- "version": "0.8.28",
6
+ "version": "0.8.29",
7
7
  "repository": "https://github.com/symbo-ls/smbls",
8
8
  "main": "src/index.js",
9
9
  "files": [
@@ -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 [width, height] = props.boxSize.split(' ')
41
+ const [height, width] = props.boxSize.split(' ')
42
42
  return {
43
- ...mapSpacing(width, 'width'),
44
- ...mapSpacing(height, 'height')
43
+ ...mapSpacing(height, 'height'),
44
+ ...mapSpacing(width, 'width')
45
45
  }
46
46
  },
47
47
 
package/src/Media.js CHANGED
@@ -1,91 +1,50 @@
1
1
  'use strict'
2
2
 
3
- import { getTheme, CASES, MEDIA as BREAKPOINTS } from '@symbo.ls/scratch'
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
+ }
4
18
 
5
19
  const init = (el, s) => {
6
20
  const { props, class: className } = el
7
21
 
8
22
  for (const screen in props) {
9
23
  if (screen.slice(0, 1) === '@') {
10
- const mediaName = screen.slice(1)
11
- const responsiveKey = `@media screen and ${BREAKPOINTS[mediaName]}`
24
+ const mediaName = CONFIG_MEDIA[screen.slice(1)]
25
+ const mediaKey = `@media screen and ${mediaName}`
12
26
  const screenProps = props[screen]
13
- const calculatedScreenProps = {}
14
-
15
- for (const prop in screenProps) {
16
- // if (!className || !className[prop]) return
17
- // const classProp = className[prop]
18
- const classProp = className[prop]
19
- if (typeof classProp !== 'function') continue
20
- let calculatedProp = classProp({ props: screenProps })
21
-
22
- if (Array.isArray(calculatedProp)) {
23
- calculatedProp = Object.assign({}, ...calculatedProp)
24
- }
25
-
26
- for (const finalProp in calculatedProp) {
27
- calculatedScreenProps[finalProp] = calculatedProp[finalProp]
28
- }
29
- }
30
27
 
31
28
  const { MEDIA } = className
32
29
  if (!MEDIA) className.MEDIA = {}
33
- className.MEDIA[responsiveKey] = calculatedScreenProps
30
+ className.MEDIA[mediaKey] = convertToClass(screenProps, el)
34
31
  } else if (screen.slice(0, 1) === ':') {
35
- const selectorProps = {}
36
- // const selectorName = screen.slice(1)
37
- const underSelectorProps = props[screen]
32
+ const selectorProps = props[screen]
38
33
  const selectorKey = `&${screen}`
39
34
 
40
- for (const prop in underSelectorProps) {
41
- const classProp = className[prop]
42
- if (typeof classProp !== 'function') continue
43
- let calculatedProp = classProp({ props: underSelectorProps })
44
-
45
- if (Array.isArray(calculatedProp)) {
46
- calculatedProp = Object.assign({}, ...calculatedProp)
47
- }
48
-
49
- for (const finalProp in calculatedProp) {
50
- selectorProps[finalProp] = calculatedProp[finalProp]
51
- }
52
- }
53
-
54
35
  const { SELECTORS } = className
55
- if (SELECTORS) SELECTORS[selectorKey] = selectorProps
56
- else {
57
- className.SELECTORS = {
58
- [selectorKey]: selectorProps
59
- }
60
- }
36
+ if (!SELECTORS) className.SELECTORS = {}
37
+ className.SELECTORS[selectorKey] = convertToClass(selectorProps, el)
61
38
  } else if (screen.slice(0, 1) === '$') {
62
39
  const caseKey = screen.slice(1)
63
- const caseProps = props[screen]
64
- const calculatedCaseProps = {}
65
-
66
- if (!CASES[caseKey]) return
40
+ if (!CONFIG_CASES[caseKey]) continue
67
41
 
68
- for (const prop in caseProps) {
69
- // if (!className || !className[prop]) return
70
- // const classProp = className[prop]
71
- const classProp = className[prop]
72
- if (typeof classProp !== 'function') continue
73
- let calculatedProp = classProp({ props: caseProps })
74
-
75
- if (Array.isArray(calculatedProp)) {
76
- calculatedProp = Object.assign({}, ...calculatedProp)
77
- }
78
-
79
- for (const finalProp in calculatedProp) {
80
- calculatedCaseProps[finalProp] = calculatedProp[finalProp]
81
- }
82
- }
42
+ const caseProps = props[screen]
43
+ const execCaseProps = convertToClass(caseProps, el)
83
44
 
84
45
  const { CASE } = className
85
46
  if (!CASE) className.CASE = {}
86
- className.CASE[caseKey] = calculatedCaseProps
87
- // Object.assign(className.CASE[caseKey], calculatedCaseProps)
88
- // console.log(className.CASE)
47
+ merge(className.CASE, execCaseProps)
89
48
  }
90
49
  }
91
50
  }
@@ -96,31 +55,34 @@ export const Responsive = {
96
55
  initUpdate: el => {
97
56
  const { props, class: className } = el
98
57
  const rootState = el.__root ? el.__root.state : el.state
58
+ // console.log(props)
99
59
 
100
60
  if (props.theme) {
101
- props.returnGeneratedTheme = getTheme(props.theme)
102
- const { returnGeneratedTheme } = props
61
+ // console.group(props.theme)
62
+ const { theme } = props
103
63
 
104
- for (const key in returnGeneratedTheme) {
64
+ for (const key in theme) {
105
65
  if (key.includes('dark') || key.includes('light')) {
106
66
  const parse = key.split(': ')[1].split(')')[0]
107
67
  if (rootState.globalTheme === parse) {
108
- props.returnGeneratedTheme = getTheme(returnGeneratedTheme[key])
109
- } else props.returnGeneratedTheme = returnGeneratedTheme
110
- className.MEDIA_FORCED_BY_STATE = props.returnGeneratedTheme
68
+ props.theme = getTheme(theme[key])
69
+ } else props.theme = theme
70
+ className.MEDIA_FORCED_BY_STATE = props.theme
71
+ props.generatedTheme = true
111
72
  }
112
73
  }
74
+ // console.groupEnd(props.theme)
113
75
  }
114
76
 
115
77
  for (const screen in props) {
116
78
  if (screen.slice(0, 1) === '@') {
117
79
  const mediaName = screen.slice(1)
118
- const responsiveKey = `@media screen and ${BREAKPOINTS[mediaName]}`
80
+ const mediaKey = `@media screen and ${CONFIG_MEDIA[mediaName]}`
119
81
  if (mediaName === 'dark' || mediaName === 'light') {
120
82
  const { MEDIA_FORCE } = className
121
83
  if (!MEDIA_FORCE) className.media = {}
122
84
  if (rootState.globalTheme === mediaName) {
123
- className.MEDIA_FORCED = className.MEDIA[responsiveKey]
85
+ className.MEDIA_FORCED = className.MEDIA[mediaKey]
124
86
  } else className.MEDIA_FORCED = {}
125
87
  }
126
88
  }
@@ -48,12 +48,11 @@ export const Shape = {
48
48
 
49
49
  theme: ({ props }) => {
50
50
  if (!props.theme) return
51
- return props.returnGeneratedTheme || getTheme(props.theme)
51
+ return getTheme(props.theme)
52
52
  },
53
53
 
54
54
  color: ({ props }) => props.color ? ({ color: getColor(props.color) }) : null,
55
55
  background: ({ props }) => props.background ? ({ backgroundColor: getColor(props.background) }) : null,
56
- // border: ({ props }) => props.border ? ({ borderColor: getColor(props.border) }) : null,
57
56
 
58
57
  textStroke: ({ props }) => props.textStroke ? diffStroke(props.textStroke) : null,
59
58
 
@@ -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: {