smbls 0.8.30 → 0.8.31

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.30",
6
+ "version": "0.8.31",
7
7
  "repository": "https://github.com/symbo-ls/smbls",
8
8
  "main": "src/index.js",
9
9
  "files": [
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/Media.js CHANGED
@@ -3,51 +3,81 @@
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 convertToClass = (subProps, element) => {
6
+ const convertPropsToClass = (subProps, lib, element) => {
7
7
  const { class: className } = element
8
8
  const subPropsClassname = {}
9
9
  for (const prop in subProps) {
10
+ // if (prop.slice(0, 1) === ':') {
11
+ // applySelectorProps(prop, lib, element)
12
+ // continue
13
+ // }
14
+
10
15
  const classnameExec = className[prop]
11
16
  if (typeof classnameExec !== 'function') continue
12
17
 
13
- let contertedToClass = classnameExec({ props: subProps })
14
- if (isArray(contertedToClass)) {
15
- contertedToClass = contertedToClass.reduce((a, c) => merge(a, c), {})
18
+ let classExec = classnameExec({ props: subProps })
19
+ if (isArray(classExec)) {
20
+ classExec = classExec.reduce((a, c) => merge(a, c), {})
16
21
  }
17
22
 
18
- for (const finalProp in contertedToClass) subPropsClassname[finalProp] = contertedToClass[finalProp]
23
+ for (const finalProp in classExec) {
24
+ subPropsClassname[finalProp] = classExec[finalProp]
25
+ }
19
26
  }
20
27
  return subPropsClassname
21
28
  }
22
29
 
30
+ const applyMediaProps = (key, lib, element) => {
31
+ const { props } = element
32
+ const mediaName = CONFIG_MEDIA[key.slice(1)]
33
+ const mediaKey = `@media key and ${mediaName}`
34
+ const mediaProps = props[key]
35
+ lib.media[mediaKey] = convertPropsToClass(mediaProps, lib, element)
36
+ }
37
+
38
+ const applySelectorProps = (key, lib, element) => {
39
+ const { props } = element
40
+ const selectorKey = `&${key}`
41
+ const selectorProps = props[key]
42
+ lib.selector[selectorKey] = convertPropsToClass(selectorProps, lib, element)
43
+ }
44
+
45
+ const applyCaseProps = (key, lib, element) => {
46
+ const { props } = element
47
+ const caseKey = key.slice(1)
48
+ if (!CONFIG_CASES[caseKey]) return
49
+ const caseProps = props[key]
50
+ merge(lib.case, convertPropsToClass(caseProps, lib, element))
51
+ }
52
+
53
+ const keySetters = {
54
+ '@': applyMediaProps,
55
+ ':': applySelectorProps,
56
+ $: applyCaseProps
57
+ }
58
+
23
59
  const init = (el, s) => {
24
60
  const { props, class: className } = el
25
61
 
26
- for (const screen in props) {
27
- if (screen.slice(0, 1) === '@') {
28
- const mediaName = CONFIG_MEDIA[screen.slice(1)]
29
- const mediaKey = `@media screen and ${mediaName}`
30
- const screenProps = props[screen]
31
-
32
- const { MEDIA } = className
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))
49
- }
62
+ const CLASS_NAMES = {
63
+ media: {},
64
+ selector: {},
65
+ case: {}
50
66
  }
67
+
68
+ for (const key in props) {
69
+ const setter = keySetters[key.slice(0, 1)]
70
+ if (setter) setter(key, CLASS_NAMES, el)
71
+ // if (key.slice(0, 1) === '@') {
72
+ // applyMediaProps(key, CLASS_NAMES.media, el)
73
+ // } else if (key.slice(0, 1) === ':') {
74
+ // applySelectorProps(key, CLASS_NAMES.selector, el)
75
+ // } else if (key.slice(0, 1) === '$') {
76
+ // applyCaseProps(key, CLASS_NAMES.case, el)
77
+ // }
78
+ }
79
+
80
+ merge(className, CLASS_NAMES)
51
81
  }
52
82
 
53
83
  export const Responsive = {
@@ -1,35 +1,10 @@
1
1
  'use strict'
2
2
 
3
- import { isArray, isObject, exec } from '@domql/utils'
4
- import { mapSpacing, getTheme, getColor } from '@symbo.ls/scratch'
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
@@ -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
+ }
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './styles'
7
7
  export * from './Text'
8
8
  export * from './Block'
9
9
  export * from './Shape'
10
+ export * from './Theme'
10
11
  export * from './Flex'
11
12
  export * from './Grid'
12
13
  export * from './Direction'