css-in-props 2.10.72 → 2.10.77

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
@@ -2,7 +2,7 @@
2
2
  "name": "css-in-props",
3
3
  "description": "Utilize props as CSS methods",
4
4
  "author": "symbo.ls",
5
- "version": "2.10.72",
5
+ "version": "2.10.77",
6
6
  "repository": "https://github.com/symbo-ls/smbls",
7
7
  "main": "src/index.js",
8
8
  "files": [
@@ -10,8 +10,9 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@domql/utils": "latest",
13
+ "@symbo.ls/atoms": "latest",
13
14
  "@symbo.ls/emotion": "latest",
14
15
  "@symbo.ls/scratch": "latest"
15
16
  },
16
- "gitHead": "a85e1214d361a34282504ca033755e7c854cc00f"
17
+ "gitHead": "02998a848941e15bc0cdbeab9cbf0d74247f226e"
17
18
  }
package/src/registry.js CHANGED
@@ -1,216 +1,34 @@
1
1
  'use strict'
2
2
 
3
- import { isArray, isObject } from '@domql/utils'
4
- import { getColor, getSpacingByKey, getTheme, SPACING, getFontSizeByKey, getFontFamily, FONT_FAMILY } from '@symbo.ls/scratch'
5
-
6
- export const mapBasedOnRatio = (props, prop, unit) => {
7
- const { spacingRatio } = props
8
- const val = props[prop]
9
- // TODO: move this to getSpacingByKey
10
- if (spacingRatio) {
11
- const params = SPACING[spacingRatio]
12
-
13
- if (!params) {
14
- SPACING[spacingRatio] = {
15
- base: SPACING.base,
16
- type: 'spacing',
17
- ratio: spacingRatio,
18
- range: [-5, +7],
19
- subSequence: true,
20
- sequence: {},
21
- scales: {}
22
- }
23
- }
24
-
25
- return getSpacingByKey(val, prop, params, unit)
26
- }
27
- return getSpacingByKey(val, prop, null, unit)
28
- }
29
-
30
- const isBorderStyle = str =>
31
- ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset', 'initial'].some(v => str.includes(v))
32
-
33
- const diffBorder = (border, key = 'border') => {
34
- const obj = {}
35
- const arr = isObject(border) ? Object.values(border) : isArray(border) ? border : border.split(', ')
36
- arr.map(v => {
37
- if (v.includes('px')) obj[`${key}Width`] = v // TODO: add map spacing
38
- else if (isBorderStyle(v)) obj[`${key}Style`] = v || 'solid'
39
- else if (getColor(v)) obj[`${key}Color`] = getColor(v)
40
- })
41
- return obj
42
- }
43
-
44
- const diffStroke = stroke => {
45
- const WebkitTextStroke = stroke.split(', ').map(v => {
46
- if (v.includes('px')) return v
47
- else if (getColor(v)) return getColor(v)
48
- }).join(' ')
49
- return { WebkitTextStroke }
50
- }
51
-
52
- export const grid = {
53
- columns: props => props.columns ? ({ gridTemplateColumns: props.columns }) : null,
54
- rows: props => props.rows ? ({ gridTemplateRows: props.rows }) : null,
55
- area: props => props.area ? ({ gridArea: props.area }) : null,
56
- template: props => props.template ? ({ gridTemplate: props.template }) : null,
57
- templateAreas: props => props.templateAreas ? ({ gridTemplateAreas: props.templateAreas }) : null,
58
- gap: props => props.gap ? mapBasedOnRatio(props, 'gap') : null,
59
- columnGap: props => props.template ? mapBasedOnRatio(props, 'columnGap') : null,
60
- rowGap: props => props.template ? mapBasedOnRatio(props, 'rowGap') : null
61
- }
62
-
63
- export const theme = {
64
- theme: props => props.theme ? getTheme(props.theme) : null,
65
-
66
- color: props => props.color ? ({ color: getColor(props.color) }) : null,
67
- background: props => props.background ? ({ background: getColor(props.background) }) : null,
68
-
69
- textStroke: props => props.textStroke ? diffStroke(props.textStroke) : null,
70
-
71
- border: props => props.border ? diffBorder(props.border) : null,
72
- borderColor: props => props.borderColor ? ({ borderColor: getColor(props.borderColor) }) : null,
73
- borderStyle: props => props.borderStyle && ({ borderStyle: props.borderStyle }),
74
-
75
- borderLeft: props => props.borderLeft ? diffBorder(props.borderLeft, 'borderLeft') : null,
76
- borderTop: props => props.borderTop ? diffBorder(props.borderTop, 'borderTop') : null,
77
- borderRight: props => props.borderRight ? diffBorder(props.borderRight, 'borderRight') : null,
78
- borderBottom: props => props.borderBottom ? diffBorder(props.borderBottom, 'borderBottom') : null,
79
-
80
- opacity: props => props.opacity && ({ opacity: props.opacity }),
81
- visibility: props => ({ visibility: props.visibility })
82
- }
83
-
84
- export const block = {
85
- round: props => props.round ? (mapBasedOnRatio(props, 'borderRadius') || ({ borderRadius: props.round })) : null,
86
- borderRadius: props => props.borderRadius ? (mapBasedOnRatio(props, 'borderRadius') || ({ borderRadius: props.borderRadius })) : null,
87
-
88
- transition: props => props.transition && ({ transition: props.transition }),
89
- transitionProperty: props => props.transitionProperty && ({
90
- transitionProperty: props.transitionProperty,
91
- willChange: props.transitionProperty
92
- }),
93
-
94
- boxSizing: props => props.boxSizing ? ({ display: props.boxSizing }) : {
95
- boxSizing: 'border-box'
96
- },
97
-
98
- display: props => props.display && ({ display: props.display }),
99
-
100
- hide: props => props.hide && ({ display: 'none' }),
101
-
102
- width: props => props.width && mapBasedOnRatio(props, 'width'),
103
- height: props => props.height && mapBasedOnRatio(props, 'height'),
104
- boxSize: props => {
105
- if (typeof props.boxSize !== 'string') return
106
- const [height, width] = props.boxSize.split(' ')
107
- return {
108
- ...mapBasedOnRatio({ height, spacingRatio: props.spacingRatio }, 'height'),
109
- ...mapBasedOnRatio({ width, spacingRatio: props.spacingRatio }, 'width')
110
- }
111
- },
112
-
113
- maxWidth: props => props.maxWidth && mapBasedOnRatio(props, 'maxWidth'),
114
- minWidth: props => props.minWidth && mapBasedOnRatio(props, 'minWidth'),
115
- widthRange: props => {
116
- if (typeof props.widthRange !== 'string') return
117
- const [minWidth, maxWidth] = props.widthRange.split(' ')
118
- return {
119
- ...mapBasedOnRatio({ minWidth, spacingRatio: props.spacingRatio }, 'minWidth'),
120
- ...mapBasedOnRatio({ maxWidth, spacingRatio: props.spacingRatio }, 'maxWidth')
121
- }
122
- },
123
-
124
- maxHeight: props => props.maxHeight && mapBasedOnRatio(props, 'maxHeight'),
125
- minHeight: props => props.minHeight && mapBasedOnRatio(props, 'minHeight'),
126
- heightRange: props => {
127
- if (typeof props.heightRange !== 'string') return
128
- const [minHeight, maxHeight] = props.heightRange.split(' ')
129
- return {
130
- ...mapBasedOnRatio({ minHeight, spacingRatio: props.spacingRatio }, 'minHeight'),
131
- ...mapBasedOnRatio({ maxHeight, spacingRatio: props.spacingRatio }, 'maxHeight')
132
- }
133
- },
134
-
135
- aspectRatio: props => props.aspectRatio && ({ aspectRatio: props.aspectRatio }),
136
-
137
- borderWidth: props => props.borderWidth ? mapBasedOnRatio(props, 'borderWidth') : null,
138
-
139
- padding: props => props.padding ? mapBasedOnRatio(props, 'padding') : null,
140
- margin: props => props.margin ? mapBasedOnRatio(props, 'margin') : null,
141
-
142
- gap: props => props.gap ? mapBasedOnRatio(props, 'gap') : null,
143
- gridArea: props => props.gridArea && ({ gridArea: props.gridArea })
144
- }
145
-
146
- export const flex = {
147
- flexFlow: props => props.flexFlow && ({
148
- display: 'flex',
149
- flexFlow: props.flexFlow
150
- }),
151
- flexAlign: props => {
152
- if (typeof props.flexAlign !== 'string') return
153
- const [alignItems, justifyContent] = props.flexAlign.split(' ')
154
- return {
155
- display: 'flex',
156
- alignItems: alignItems,
157
- justifyContent: justifyContent
158
- }
159
- },
160
-
161
- flex: props => props.flex && ({ flex: props.flex }),
162
- alignItems: props => props.alignItems && ({ alignItems: props.alignItems }),
163
- alignContent: props => props.alignContent && ({ alignContent: props.alignContent }),
164
- justifyContent: props => props.justifyContent && ({ justifyContent: props.justifyContent })
165
- }
166
-
167
- export const position = {
168
- position: props => props.position && ({ position: props.position }),
169
- inset: props => {
170
- const { inset } = props
171
- if (typeof inset !== 'string') return
172
- return { inset: inset.split(' ').map(v => mapBasedOnRatio(v, 'k').k).join(' ') }
173
- },
174
-
175
- left: props => mapBasedOnRatio(props, 'left'),
176
- top: props => mapBasedOnRatio(props, 'top'),
177
- right: props => mapBasedOnRatio(props, 'right'),
178
- bottom: props => mapBasedOnRatio(props, 'bottom')
179
- }
180
-
181
- export const text = {
182
- fontSize: props => props.fontSize ? getFontSizeByKey(props.fontSize) : null,
183
- fontFamily: props => props.fontFamily && ({ fontFamily: getFontFamily(FONT_FAMILY, props.fontFamily) || props.fontFamily }),
184
- lineHeight: props => props.lineHeight && ({ lineHeight: props.lineHeight }),
185
- // lineHeight: props => props.lineHeight && mapBasedOnRatio(props, 'lineHeight', null, ''),
186
- textDecoration: props => props.textDecoration && ({ textDecoration: props.textDecoration }),
187
- textTransform: props => props.textTransform && ({ textTransform: props.textTransform }),
188
- textAlign: props => props.textAlign && ({ textAlign: props.textAlign }),
189
- fontWeight: props => props.fontWeight && ({ fontWeight: props.fontWeight })
190
- }
191
-
192
- export const registry = {
193
- style: props => props.style,
194
-
195
- ...theme,
196
- ...block,
197
- ...flex,
198
- ...position,
199
- ...text,
200
-
201
- gridColumn: props => props.gridColumn && ({ gridColumn: props.gridColumn }),
202
- gridRow: props => props.gridRow && ({ gridRow: props.gridRow }),
203
-
204
- size: props => {
205
- if (typeof props.heightRange !== 'string') return
206
- const [minHeight, maxHeight] = props.heightRange.split(' ')
207
- return {
208
- ...getSpacingByKey(minHeight, 'minHeight'),
209
- ...getSpacingByKey(maxHeight, 'maxHeight')
210
- }
211
- },
212
-
213
- overflow: props => props.overflow && ({ overflow: props.overflow }),
214
-
215
- transform: props => props.transform && ({ transform: props.transform })
216
- }
3
+ import { mergeArray } from '@domql/utils'
4
+
5
+ import {
6
+ Shape,
7
+ Position,
8
+ Theme,
9
+ Block,
10
+ Text,
11
+ Overflow,
12
+ Timing,
13
+ Transform,
14
+ Media,
15
+ Interaction,
16
+ XYZ,
17
+ Animation
18
+ } from '@symbo.ls/atoms'
19
+
20
+
21
+ export const registry = mergeArray([
22
+ Shape,
23
+ Position,
24
+ Theme,
25
+ Block,
26
+ Text,
27
+ Overflow,
28
+ Timing,
29
+ Transform,
30
+ Media,
31
+ Interaction,
32
+ XYZ,
33
+ Animation
34
+ ])
package/src/_fromClass.js DELETED
@@ -1,45 +0,0 @@
1
- 'use strict'
2
-
3
- const methods = {
4
- shape: (element) => {
5
- const { props } = element
6
- const { shape } = props
7
- return shape ? exec(SHAPES[shape], element) : null
8
- },
9
- shapeDirection: ({ props }) => {
10
- const { shape, shapeDirection } = props
11
- if (!shape || !shapeDirection) return
12
- const shapeDir = SHAPES[shape + 'Direction']
13
- return shape ? shapeDir[shapeDirection || 'top'] : null
14
- },
15
- shapeDirectionColor: ({ props, ...el }) => props.shapeDirection ? { '&:before': { borderColor: el.class.backgroundColor } } : null,
16
- depth: ({ props }) => depth[props.depth],
17
- round: ({ props, key, ...el }) => props.round ? (mapSpacing(props.round, 'borderRadius') || ({ borderRadius: props.round })) : null,
18
- borderRadius: ({ props, key, ...el }) => props.borderRadius ? (mapSpacing(props.borderRadius, 'borderRadius') || ({ borderRadius: props.borderRadius })) : null,
19
-
20
- theme: ({ props }) => {
21
- if (!props.theme) return
22
- return getTheme(props.theme)
23
- },
24
-
25
- color: ({ props }) => props.color ? ({ color: getColor(props.color) }) : null,
26
- background: ({ props }) => props.background ? ({ backgroundColor: getColor(props.background) }) : null,
27
-
28
- textStroke: ({ props }) => props.textStroke ? diffStroke(props.textStroke) : null,
29
-
30
- border: ({ props }) => props.border ? diffBorder(props.border) : null,
31
- borderColor: ({ props }) => props.borderColor ? ({ borderColor: getColor(props.borderColor) }) : null,
32
- borderStyle: ({ props }) => props.borderStyle && ({ borderStyle: props.borderStyle }),
33
-
34
- borderLeft: ({ props }) => props.borderLeft ? diffBorder(props.borderLeft, 'borderLeft') : null,
35
- borderTop: ({ props }) => props.borderTop ? diffBorder(props.borderTop, 'borderTop') : null,
36
- borderRight: ({ props }) => props.borderRight ? diffBorder(props.borderRight, 'borderRight') : null,
37
- borderBottom: ({ props }) => props.borderBottom ? diffBorder(props.borderBottom, 'borderBottom') : null,
38
-
39
- opacity: ({ props }) => props.opacity && ({ opacity: props.opacity }),
40
- visibility: ({ props }) => execClass({ visibility: props.visibility })
41
- }
42
- const execClass = (prop, element, state) => {
43
- const { props } = element
44
- if (props[prop]) return { prop }
45
- }