smbls 0.8.29 → 0.8.32

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.29",
6
+ "version": "0.8.32",
7
7
  "repository": "https://github.com/symbo-ls/smbls",
8
8
  "main": "src/index.js",
9
9
  "files": [
@@ -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 ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict'
2
+
3
+ import { Shape, Position, Theme, Block, Text, Overflow, Transition, Transform, Responsive } from '.'
4
+
5
+ const PropsCSS = {
6
+ class: {
7
+ propsCSS: ({ props }) => props && props.css
8
+ }
9
+ }
10
+
11
+ export const Box = {
12
+ proto: [Shape, Position, Theme, Block, Text, Overflow, Transition, Transform, Responsive, PropsCSS]
13
+ }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { IconText } from '../'
3
+ import { IconText } from '.'
4
4
 
5
5
  const css = {
6
6
  appearance: 'none',
@@ -0,0 +1,10 @@
1
+ 'use strict'
2
+
3
+ import { SquareButton } from './Button'
4
+ import { Flex } from './Flex'
5
+
6
+ export const ButtonSet = {
7
+ tag: 'nav',
8
+ proto: Flex,
9
+ childProto: SquareButton
10
+ }
@@ -3,13 +3,10 @@
3
3
  import style from './style'
4
4
 
5
5
  import Icon from '../Icon'
6
- import Shape from '../Shape'
7
- import { Block } from '../Block'
8
6
 
9
7
  export const DatePicker = {
10
8
  style,
11
9
 
12
- proto: [Shape, Block],
13
10
  props: {
14
11
  theme: 'lightDark',
15
12
  padding: 'A',
File without changes
@@ -1,12 +1,10 @@
1
1
  'use strict'
2
2
 
3
- import style from './style'
4
- import { mapBasedOnRatio } from '../Block'
3
+ import { mapBasedOnRatio } from './Block'
5
4
 
6
5
  export const Flex = {
7
- style,
8
-
9
6
  props: {
7
+ display: 'flex',
10
8
  flow: 'row'
11
9
  },
12
10
 
@@ -1,12 +1,9 @@
1
1
  'use strict'
2
2
 
3
- import style from './style'
4
- import { mapBasedOnRatio } from '../Block'
3
+ import { mapBasedOnRatio } from './Block'
5
4
 
6
5
  export const Grid = {
7
- style,
8
-
9
- props: {},
6
+ props: { display: 'grid' },
10
7
 
11
8
  class: {
12
9
  columns: ({ props }) => props.columns ? ({ gridTemplateColumns: props.columns }) : null,
File without changes
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
- import { Block } from '../Block'
3
- import { Shape } from '../Shape'
4
- import { Text } from '../Text'
2
+ import { Block } from './Block'
3
+ import { Shape } from './Shape'
4
+ import { Text } from './Text'
5
5
 
6
6
  export const Label = {
7
7
  proto: [Shape, Block, Text],
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { exec } from '@domql/utils'
4
- import { Shape, Text } from '..'
4
+ import { Shape, Text } from '.'
5
5
 
6
6
  export const Link = {
7
7
  proto: [Shape, Text],
package/src/Media.js CHANGED
@@ -1,91 +1,125 @@
1
1
  'use strict'
2
2
 
3
- import { merge } from '@domql/utils'
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
10
  for (const prop in subProps) {
11
+ // if (prop.slice(0, 1) === ':') {
12
+ // applySelectorProps(prop, lib, element)
13
+ // continue
14
+ // }
15
+
10
16
  const classnameExec = className[prop]
11
17
  if (typeof classnameExec !== 'function') continue
12
18
 
13
- const contertedToClass = classnameExec({ props: subProps })
14
- for (const finalProp in contertedToClass) subPropsClassname[finalProp] = contertedToClass[finalProp]
19
+ let classExec = classnameExec({ props: subProps })
20
+ if (isArray(classExec)) {
21
+ classExec = classExec.reduce((a, c) => merge(a, c), {})
22
+ }
23
+
24
+ for (const finalProp in classExec) {
25
+ subPropsClassname[finalProp] = classExec[finalProp]
26
+ }
15
27
  }
28
+
29
+ // console.group(subProps)
30
+ // console.log(subPropsClassname)
31
+ // console.log(lib)
32
+ // console.log(className)
33
+ // console.groupEnd(subProps)
34
+
16
35
  return subPropsClassname
17
36
  }
18
37
 
38
+ const applyMediaProps = (key, lib, element) => {
39
+ const { props } = element
40
+ const mediaName = CONFIG_MEDIA[key.slice(1)]
41
+ const mediaKey = `@media screen and ${mediaName}`
42
+ const mediaProps = props[key]
43
+ lib.media[mediaKey] = convertPropsToClass(mediaProps, lib, element)
44
+ }
45
+
46
+ const applySelectorProps = (key, lib, element) => {
47
+ const { props } = element
48
+ const selectorKey = `&${key}`
49
+ const selectorProps = props[key]
50
+ lib.selector[selectorKey] = convertPropsToClass(selectorProps, lib, element)
51
+ }
52
+
53
+ const applyCaseProps = (key, lib, element) => {
54
+ const { props } = element
55
+ const caseKey = key.slice(1)
56
+ if (!CONFIG_CASES[caseKey]) return
57
+ const caseProps = props[key]
58
+ merge(lib.case, convertPropsToClass(caseProps, lib, element))
59
+ }
60
+
61
+ const keySetters = {
62
+ '@': applyMediaProps,
63
+ ':': applySelectorProps,
64
+ $: applyCaseProps
65
+ }
66
+
19
67
  const init = (el, s) => {
20
68
  const { props, class: className } = el
21
69
 
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
- }
70
+ const CLASS_NAMES = {
71
+ media: {},
72
+ selector: {},
73
+ case: {}
74
+ }
75
+
76
+ for (const key in props) {
77
+ const setter = keySetters[key.slice(0, 1)]
78
+ if (setter) setter(key, CLASS_NAMES, el)
49
79
  }
80
+
81
+ merge(className, CLASS_NAMES)
50
82
  }
51
83
 
52
84
  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)
85
+ on: { init }
86
+ }
87
+
88
+ export const initUpdate = el => {
89
+ // FORCE STATE UPDATE:
90
+ const { props, class: className } = el
91
+ const rootState = el.__root ? el.__root.state : el.state
92
+ console.log(props)
93
+ if (el.key !== 'app') return
94
+
95
+ if (props.theme) {
96
+ const { theme } = props
97
+ // console.group(props.theme)
98
+
99
+ const convertTheme = getTheme(theme)
100
+
101
+ for (const key in convertTheme) {
102
+ if (key.includes('dark') || key.includes('light')) {
103
+ const parse = key.split(': ')[1].split(')')[0]
104
+ if (rootState.globalTheme === parse) {
105
+ props.theme = getTheme(theme[key])
106
+ } else props.theme = theme
107
+ className.MEDIA_FORCED_BY_STATE = props.theme
75
108
  }
109
+ }
110
+ // console.groupEnd(props.theme)
111
+ }
76
112
 
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
- }
113
+ for (const screen in props) {
114
+ if (screen.slice(0, 1) === '@') {
115
+ const mediaName = screen.slice(1)
116
+ const mediaKey = `@media screen and ${CONFIG_MEDIA[mediaName]}`
117
+ if (mediaName === 'dark' || mediaName === 'light') {
118
+ const { MEDIA_FORCE } = className
119
+ if (!MEDIA_FORCE) className.media = {}
120
+ if (rootState.globalTheme === mediaName) {
121
+ className.MEDIA_FORCED = className.MEDIA[mediaKey]
122
+ } else className.MEDIA_FORCED = {}
89
123
  }
90
124
  }
91
125
  }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { Shape, Block, IconText, Direction, Flex, Text } from '../'
3
+ import { Shape, Block, IconText, Direction, Flex, Text } from '.'
4
4
 
5
5
  export const Notification = {
6
6
  style: { cursor: 'pointer' },
@@ -2,6 +2,6 @@
2
2
 
3
3
  export const Overflow = {
4
4
  class: {
5
- overflow: ({ props }) => props.overflow && ({ overflow: props.overflow }),
5
+ overflow: ({ props }) => props.overflow && ({ overflow: props.overflow })
6
6
  }
7
7
  }
@@ -1,5 +1,4 @@
1
1
  'use strict'
2
- import Shape from '../Shape'
3
2
 
4
3
  export const Pills = {
5
4
  style: {
@@ -18,13 +17,10 @@ export const Pills = {
18
17
  },
19
18
  childProto: {
20
19
  tag: 'div',
21
- proto: Shape,
22
20
  props: {
23
21
  round: 42,
24
22
  theme: 'White'
25
23
  }
26
24
  },
27
- ...[
28
- {}, {}, {}
29
- ]
25
+ ...[{}, {}, {}]
30
26
  }
File without changes
File without changes
@@ -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}` },
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
- import { Icon, Link } from '../'
2
+
3
+ import { Icon, Link } from '.'
3
4
 
4
5
  const MenuItem = {
5
6
  proto: Link,
File without changes
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
+ }
@@ -4,6 +4,6 @@ export const Transform = {
4
4
  class: {
5
5
  transform: ({ props }) => props.transform && ({
6
6
  transform: props.transform
7
- }),
7
+ })
8
8
  }
9
9
  }
File without changes
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'
@@ -1 +0,0 @@
1
- 'use strict'
package/src/Box/index.js DELETED
@@ -1,13 +0,0 @@
1
- 'use strict'
2
-
3
- import { Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive } from '..'
4
-
5
- const PropsCSS = {
6
- class: {
7
- propsCSS: ({ props }) => props && props.css
8
- }
9
- }
10
-
11
- export const Box = {
12
- proto: [Shape, Position, Block, Text, Overflow, Transition, Transform, Responsive, PropsCSS]
13
- }
@@ -1,4 +0,0 @@
1
- 'use strict'
2
-
3
- export default {
4
- }
@@ -1,14 +0,0 @@
1
- 'use strict'
2
-
3
- import { SquareButton } from '../Button'
4
- import { Shape } from '../Shape'
5
- import { Flex } from '../Flex'
6
- import { Block } from '../Block'
7
-
8
- export const ButtonSet = {
9
- tag: 'nav',
10
- proto: [Shape, Flex, Block],
11
- childProto: {
12
- proto: [SquareButton]
13
- }
14
- }
package/src/Flex/style.js DELETED
@@ -1,5 +0,0 @@
1
- 'use strict'
2
-
3
- export default {
4
- display: 'flex'
5
- }
package/src/Grid/style.js DELETED
@@ -1,5 +0,0 @@
1
- 'use strict'
2
-
3
- export default {
4
- display: 'grid'
5
- }
package/src/Text/style.js DELETED
@@ -1,2 +0,0 @@
1
- 'use strict'
2
-
@@ -1,2 +0,0 @@
1
- 'use strict'
2
-