smbls 0.15.32 → 0.15.34

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.15.32",
6
+ "version": "0.15.34",
7
7
  "repository": "https://github.com/symbo-ls/smbls",
8
8
  "main": "src/index.js",
9
9
  "files": [
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { merge, isArray } from '@domql/utils'
4
+ import { getSystemTheme } from './Theme'
4
5
 
5
6
  const keySetters = {
6
7
  '@': (key, props, result, element, isSubtree) => applyMediaProps(key, props, isSubtree ? result : result.media, element),
@@ -16,7 +17,11 @@ const execClass = (key, props, result, element) => {
16
17
 
17
18
  if (typeof classnameExec !== 'function') return
18
19
 
19
- let classExec = classnameExec({ props })
20
+ let classExec = classnameExec({
21
+ props,
22
+ context: element.context,
23
+ state: element.state
24
+ })
20
25
  if (isArray(classExec)) {
21
26
  classExec = classExec.reduce((a, c) => merge(a, c), {})
22
27
  }
@@ -45,13 +50,13 @@ const convertPropsToClass = (props, result, element) => {
45
50
  }
46
51
 
47
52
  const applyMediaProps = (key, props, result, element) => {
48
- if (!element.context.SYSTEM || !element.context.SYSTEM.MEDIA) { return }
49
- const { MEDIA } = element.context.SYSTEM
53
+ const { context } = element
54
+ if (!context.SYSTEM || !context.SYSTEM.MEDIA) return
55
+ const globalTheme = getSystemTheme(element)
56
+ const { MEDIA } = context.SYSTEM
50
57
  const mediaName = MEDIA[key.slice(1)]
51
58
  const generatedClass = convertPropsToClass(props, result, element)
52
59
 
53
- const rootState = element.__root ? element.__root.state : element.state
54
- const { globalTheme } = rootState
55
60
  const name = key.slice(1)
56
61
  const isTheme = ['dark', 'light'].includes(name)
57
62
  const matchesGlobal = name === globalTheme
@@ -114,7 +119,7 @@ const beforeClassAssign = (element, s) => {
114
119
 
115
120
  export const initUpdate = element => {
116
121
  const { props, class: className } = element
117
- const rootState = element.__root ? element.__root.state : element.state
122
+ const globalTheme = getSystemTheme(element)
118
123
 
119
124
  const parentProps = element.parent.props
120
125
  if (parentProps && parentProps.spacingRatio && parentProps.inheritSpacingRatio) {
@@ -127,8 +132,6 @@ export const initUpdate = element => {
127
132
  })
128
133
  }
129
134
 
130
- const { globalTheme } = rootState
131
-
132
135
  if (globalTheme) {
133
136
  const CLASS_NAMES = {
134
137
  media: {},
@@ -36,29 +36,60 @@ const transformShadow = shadows => shadows.split('|').map(shadow => {
36
36
  }).join(' ')
37
37
  }).join(',')
38
38
 
39
- const transformBackgroundImage = (backgroundImage, ctx) => ({
39
+ const transformBackgroundImage = (backgroundImage, ctx, globalTheme) => ({
40
40
  backgroundImage: backgroundImage.split(', ').map(v => {
41
41
  if (v.includes('url') || v.includes('gradient')) return v
42
42
  else if (ctx.SYSTEM.GRADIENT[backgroundImage]) {
43
- return getMediaColor(backgroundImage, 'backgroundImage')
43
+ return getMediaColor(backgroundImage, 'backgroundImage', globalTheme)
44
44
  }
45
45
  return `url(${v})`
46
46
  }).join(' ')
47
47
  })
48
48
 
49
+ export const getSystemTheme = (element, state) => {
50
+ const { context } = element
51
+ const rootState = element.__root ? element.__root.state : element.state
52
+ return rootState.globalTheme || context.SYSTEM.globalTheme
53
+ }
54
+
49
55
  export const Theme = {
50
56
  class: {
51
57
  depth: ({ props }) => depth[props.depth],
52
58
 
53
- theme: ({ props, key }) => {
59
+ theme: (element) => {
60
+ const { props } = element
61
+ const globalTheme = getSystemTheme(element)
54
62
  if (!props.theme) return
55
- return getMediaTheme(props.theme, props.themeModifier)
63
+ return getMediaTheme(props.theme, props.themeModifier || globalTheme)
56
64
  },
57
65
 
58
- color: ({ props }) => (props.color) && getMediaColor(props.color, 'color'),
59
- background: ({ props }) => (props.background) && getMediaColor(props.background, 'background'),
60
- backgroundColor: ({ props }) => (props.backgroundColor) && getMediaColor(props.backgroundColor, 'backgroundColor'),
61
- backgroundImage: ({ props, context }) => (props.backgroundImage) && transformBackgroundImage(props.backgroundImage, context),
66
+ color: (element) => {
67
+ const { props } = element
68
+ const globalTheme = getSystemTheme(element)
69
+ if (!props.color) return
70
+ return getMediaColor(props.color, 'color', globalTheme)
71
+ },
72
+
73
+ background: (element) => {
74
+ const { props } = element
75
+ const globalTheme = getSystemTheme(element)
76
+ if (!props.background) return
77
+ return getMediaColor(props.background, 'background', globalTheme)
78
+ },
79
+
80
+ backgroundColor: (element) => {
81
+ const { props } = element
82
+ const globalTheme = getSystemTheme(element)
83
+ if (!props.backgroundColor) return
84
+ return getMediaColor(props.backgroundColor, 'backgroundColor', globalTheme)
85
+ },
86
+
87
+ backgroundImage: (element) => {
88
+ const { props, context } = element
89
+ const globalTheme = getSystemTheme(element)
90
+ if (!props.backgroundImage) return
91
+ return transformBackgroundImage(props.backgroundImage, context, globalTheme)
92
+ },
62
93
  backgroundSize: ({ props }) => props.backgroundSize ? ({ backgroundSize: props.backgroundSize }) : null,
63
94
  backgroundPosition: ({ props }) => props.backgroundPosition ? ({ backgroundPosition: props.backgroundPosition }) : null,
64
95