css-in-props 3.8.9 → 3.14.0
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/README.md +6 -22
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/props/animation.js +28 -23
- package/dist/cjs/props/block.js +46 -58
- package/dist/cjs/props/flex.js +4 -5
- package/dist/cjs/props/index.js +18 -19
- package/dist/cjs/props/misc.js +10 -3
- package/dist/cjs/props/theme.js +10 -7
- package/dist/cjs/set.js +13 -6
- package/dist/cjs/transform/executors.js +54 -47
- package/dist/cjs/transform/index.js +2 -2
- package/dist/cjs/transform/transformers.js +69 -20
- package/dist/esm/index.js +4 -4
- package/dist/esm/props/animation.js +28 -23
- package/dist/esm/props/block.js +46 -58
- package/dist/esm/props/flex.js +4 -5
- package/dist/esm/props/index.js +18 -19
- package/dist/esm/props/misc.js +10 -3
- package/dist/esm/props/theme.js +10 -7
- package/dist/esm/set.js +12 -5
- package/dist/esm/transform/executors.js +54 -47
- package/dist/esm/transform/index.js +2 -2
- package/dist/esm/transform/transformers.js +69 -20
- package/dist/iife/index.js +230 -167
- package/index.js +1 -0
- package/package.json +13 -15
- package/src/index.js +4 -4
- package/src/props/animation.js +28 -23
- package/src/props/block.js +49 -57
- package/src/props/flex.js +4 -5
- package/src/props/index.js +18 -19
- package/src/props/misc.js +10 -3
- package/src/props/theme.js +10 -7
- package/src/set.js +11 -4
- package/src/transform/executors.js +60 -52
- package/src/transform/index.js +2 -2
- package/src/transform/transformers.js +85 -23
- package/dist/cjs/_transform.js +0 -30
- package/dist/cjs/emotion.js +0 -29
- package/dist/esm/_transform.js +0 -10
- package/dist/esm/emotion.js +0 -9
- package/src/_transform.js +0 -10
- package/src/emotion.js +0 -9
package/package.json
CHANGED
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
"name": "css-in-props",
|
|
3
3
|
"description": "Utilize props as CSS methods",
|
|
4
4
|
"author": "symbo.ls",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.14.0",
|
|
6
6
|
"repository": "https://github.com/symbo-ls/smbls",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"module": "./
|
|
8
|
+
"module": "./index.js",
|
|
9
9
|
"unpkg": "./dist/iife/index.js",
|
|
10
10
|
"jsdelivr": "./dist/iife/index.js",
|
|
11
|
-
"main": "./
|
|
11
|
+
"main": "./index.js",
|
|
12
12
|
"exports": {
|
|
13
|
-
".":
|
|
14
|
-
"import": "./dist/esm/index.js",
|
|
15
|
-
"require": "./dist/cjs/index.js"
|
|
16
|
-
},
|
|
13
|
+
".": "./index.js",
|
|
17
14
|
"./src/*": "./src/*.js",
|
|
18
|
-
"./src/props": "./src/props/index.js"
|
|
15
|
+
"./src/props": "./src/props/index.js",
|
|
16
|
+
"./package.json": "./package.json"
|
|
19
17
|
},
|
|
20
18
|
"source": "src/index.js",
|
|
21
19
|
"publishConfig": {
|
|
@@ -23,9 +21,9 @@
|
|
|
23
21
|
},
|
|
24
22
|
"scripts": {
|
|
25
23
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
26
|
-
"build:esm": "
|
|
27
|
-
"build:cjs": "
|
|
28
|
-
"build:iife": "
|
|
24
|
+
"build:esm": "NODE_ENV=$NODE_ENV esbuild $(find src -name '*.js') --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
25
|
+
"build:cjs": "NODE_ENV=$NODE_ENV esbuild $(find src -name '*.js') --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
26
|
+
"build:iife": "NODE_ENV=$NODE_ENV esbuild src/index.js --bundle --target=es2020 --format=iife --global-name=CssInProps --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV --external:@symbo.ls/* --external:@symbo.ls/* --external:smbls",
|
|
29
27
|
"build": "node ../../build/build.js",
|
|
30
28
|
"prepublish": "npm run build && npm run copy:package:cjs"
|
|
31
29
|
},
|
|
@@ -35,12 +33,12 @@
|
|
|
35
33
|
"src"
|
|
36
34
|
],
|
|
37
35
|
"dependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@symbo.ls/
|
|
40
|
-
"@symbo.ls/scratch": "^3.
|
|
36
|
+
"@symbo.ls/css": "^3.14.0",
|
|
37
|
+
"@symbo.ls/utils": "^3.14.0",
|
|
38
|
+
"@symbo.ls/scratch": "^3.14.0"
|
|
41
39
|
},
|
|
42
40
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
43
|
-
"browser": "./
|
|
41
|
+
"browser": "./index.js",
|
|
44
42
|
"sideEffects": false,
|
|
45
43
|
"devDependencies": {
|
|
46
44
|
"@babel/core": "^7.29.0"
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
export * from './transform'
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './props'
|
|
6
|
-
export * from './props/defaults'
|
|
3
|
+
export * from './transform/index.js'
|
|
4
|
+
export * from './set.js'
|
|
5
|
+
export * from './props/index.js'
|
|
6
|
+
export * from './props/defaults.js'
|
package/src/props/animation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isObject, isString } from '@
|
|
4
|
-
import {
|
|
3
|
+
import { isObject, isString } from '@symbo.ls/utils'
|
|
4
|
+
import { keyframes as cssKeyframes } from '@symbo.ls/css'
|
|
5
5
|
import { getTimingByKey, getTimingFunction } from '@symbo.ls/scratch'
|
|
6
6
|
|
|
7
7
|
const TIMING_FUNCTIONS = ['ease', 'linear', 'ease-in', 'ease-out', 'ease-in-out', 'step-start', 'step-end']
|
|
@@ -10,13 +10,18 @@ const DIRECTIONS = ['normal', 'reverse', 'alternate', 'alternate-reverse']
|
|
|
10
10
|
const PLAY_STATES = ['running', 'paused']
|
|
11
11
|
const isDuration = v => /^[\d.]+m?s$/.test(v)
|
|
12
12
|
|
|
13
|
+
let _animCounter = 0
|
|
13
14
|
const applyAnimationProps = (animation, element) => {
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const { animation: ANIMATION } = (element.context && element.context.designSystem) || {}
|
|
16
|
+
if (isObject(animation)) {
|
|
17
|
+
const name = `smbls-anim-${_animCounter++}`
|
|
18
|
+
return { animationName: cssKeyframes(name, animation) }
|
|
19
|
+
}
|
|
20
|
+
const record = ANIMATION && ANIMATION[animation]
|
|
21
|
+
if (isObject(record)) {
|
|
22
|
+
return cssKeyframes(animation, record)
|
|
23
|
+
}
|
|
24
|
+
return animation
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/**
|
|
@@ -25,7 +30,7 @@ const applyAnimationProps = (animation, element) => {
|
|
|
25
30
|
* Other tokens are classified by type: duration, timing-function, iteration-count, etc.
|
|
26
31
|
*/
|
|
27
32
|
const parseAnimationShorthand = (val, el) => {
|
|
28
|
-
const { ANIMATION } = el.context && el.context.designSystem || {}
|
|
33
|
+
const { animation: ANIMATION } = el.context && el.context.designSystem || {}
|
|
29
34
|
const tokens = val.split(/\s+/)
|
|
30
35
|
let name = null
|
|
31
36
|
const durations = []
|
|
@@ -66,25 +71,25 @@ export const ANIMATION_PROPS = {
|
|
|
66
71
|
const parsed = parseAnimationShorthand(val, el)
|
|
67
72
|
return {
|
|
68
73
|
animationName: applyAnimationProps(parsed.name || val, el),
|
|
69
|
-
animationDuration: parsed.durations[0] || getTimingByKey(el.
|
|
70
|
-
animationDelay: parsed.durations[1] || getTimingByKey(el.
|
|
71
|
-
animationTimingFunction: parsed.timingFunction || getTimingFunction(el.
|
|
72
|
-
animationFillMode: parsed.fillMode || el.
|
|
73
|
-
animationIterationCount: parsed.iterationCount != null ? parsed.iterationCount : (el.
|
|
74
|
-
animationPlayState: parsed.playState || el.
|
|
75
|
-
animationDirection: parsed.direction || el.
|
|
74
|
+
animationDuration: parsed.durations[0] || getTimingByKey(el.animationDuration || 'A').timing,
|
|
75
|
+
animationDelay: parsed.durations[1] || getTimingByKey(el.animationDelay || '0s').timing,
|
|
76
|
+
animationTimingFunction: parsed.timingFunction || getTimingFunction(el.animationTimingFunction || 'ease'),
|
|
77
|
+
animationFillMode: parsed.fillMode || el.animationFillMode || 'both',
|
|
78
|
+
animationIterationCount: parsed.iterationCount != null ? parsed.iterationCount : (el.animationIterationCount || 1),
|
|
79
|
+
animationPlayState: parsed.playState || el.animationPlayState,
|
|
80
|
+
animationDirection: parsed.direction || el.animationDirection
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
// Single name (no spaces) — original behavior
|
|
79
84
|
return {
|
|
80
85
|
animationName: applyAnimationProps(val, el),
|
|
81
|
-
animationDuration: getTimingByKey(el.
|
|
82
|
-
animationDelay: getTimingByKey(el.
|
|
83
|
-
animationTimingFunction: getTimingFunction(el.
|
|
84
|
-
animationFillMode: el.
|
|
85
|
-
animationIterationCount: el.
|
|
86
|
-
animationPlayState: el.
|
|
87
|
-
animationDirection: el.
|
|
86
|
+
animationDuration: getTimingByKey(el.animationDuration || 'A').timing,
|
|
87
|
+
animationDelay: getTimingByKey(el.animationDelay || '0s').timing,
|
|
88
|
+
animationTimingFunction: getTimingFunction(el.animationTimingFunction || 'ease'),
|
|
89
|
+
animationFillMode: el.animationFillMode || 'both',
|
|
90
|
+
animationIterationCount: el.animationIterationCount || 1,
|
|
91
|
+
animationPlayState: el.animationPlayState,
|
|
92
|
+
animationDirection: el.animationDirection
|
|
88
93
|
}
|
|
89
94
|
},
|
|
90
95
|
animationName: (val, el) => ({
|
package/src/props/block.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isUndefined, isString } from '@
|
|
3
|
+
import { isUndefined, isString } from '@symbo.ls/utils'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
getSpacingBasedOnRatio,
|
|
@@ -11,16 +11,12 @@ import {
|
|
|
11
11
|
} from '@symbo.ls/scratch'
|
|
12
12
|
|
|
13
13
|
export const BLOCK_PROPS = {
|
|
14
|
-
show: (val
|
|
15
|
-
display: 'none !important'
|
|
16
|
-
}),
|
|
14
|
+
show: (val) => !val ? ({ display: 'none !important' }) : undefined,
|
|
17
15
|
|
|
18
|
-
hide: (val
|
|
19
|
-
display: 'none !important'
|
|
20
|
-
}),
|
|
16
|
+
hide: (val) => val ? ({ display: 'none !important' }) : undefined,
|
|
21
17
|
|
|
22
|
-
height: (val,
|
|
23
|
-
width: (val,
|
|
18
|
+
height: (val, el) => transformSizeRatio('height', val, el),
|
|
19
|
+
width: (val, el) => transformSizeRatio('width', val, el),
|
|
24
20
|
|
|
25
21
|
boxSizing: (val) => !isUndefined(val)
|
|
26
22
|
? ({ boxSizing: val })
|
|
@@ -35,11 +31,11 @@ export const BLOCK_PROPS = {
|
|
|
35
31
|
}
|
|
36
32
|
},
|
|
37
33
|
|
|
38
|
-
inlineSize: (val,
|
|
39
|
-
blockSize: (val,
|
|
34
|
+
inlineSize: (val, el) => transformSizeRatio('inlineSize', val, el),
|
|
35
|
+
blockSize: (val, el) => transformSizeRatio('blockSize', val, el),
|
|
40
36
|
|
|
41
|
-
minWidth: (val,
|
|
42
|
-
maxWidth: (val,
|
|
37
|
+
minWidth: (val, el) => transformSizeRatio('minWidth', val, el),
|
|
38
|
+
maxWidth: (val, el) => transformSizeRatio('maxWidth', val, el),
|
|
43
39
|
widthRange: (val) => {
|
|
44
40
|
if (!isString(val)) return
|
|
45
41
|
const [minWidth, maxWidth] = val.split(' ')
|
|
@@ -49,8 +45,8 @@ export const BLOCK_PROPS = {
|
|
|
49
45
|
}
|
|
50
46
|
},
|
|
51
47
|
|
|
52
|
-
minHeight: (val,
|
|
53
|
-
maxHeight: (val,
|
|
48
|
+
minHeight: (val, el) => transformSizeRatio('minHeight', val, el),
|
|
49
|
+
maxHeight: (val, el) => transformSizeRatio('maxHeight', val, el),
|
|
54
50
|
heightRange: (val) => {
|
|
55
51
|
if (!isString(val)) return
|
|
56
52
|
const [minHeight, maxHeight] = val.split(' ')
|
|
@@ -69,11 +65,11 @@ export const BLOCK_PROPS = {
|
|
|
69
65
|
}
|
|
70
66
|
},
|
|
71
67
|
|
|
72
|
-
minBlockSize: (val,
|
|
73
|
-
minInlineSize: (val,
|
|
68
|
+
minBlockSize: (val, el) => transformSizeRatio('minBlockSize', val, el),
|
|
69
|
+
minInlineSize: (val, el) => transformSizeRatio('minInlineSize', val, el),
|
|
74
70
|
|
|
75
|
-
maxBlockSize: (val,
|
|
76
|
-
maxInlineSize: (val,
|
|
71
|
+
maxBlockSize: (val, el) => transformSizeRatio('maxBlockSize', val, el),
|
|
72
|
+
maxInlineSize: (val, el) => transformSizeRatio('maxInlineSize', val, el),
|
|
77
73
|
|
|
78
74
|
minSize: (val) => {
|
|
79
75
|
if (!isString(val)) return
|
|
@@ -93,10 +89,10 @@ export const BLOCK_PROPS = {
|
|
|
93
89
|
}
|
|
94
90
|
},
|
|
95
91
|
|
|
96
|
-
borderWidth: (val,
|
|
92
|
+
borderWidth: (val, el) => transformSizeRatio('borderWidth', val, el),
|
|
97
93
|
|
|
98
|
-
padding: (val,
|
|
99
|
-
scrollPadding: (val,
|
|
94
|
+
padding: (val, el) => transformSizeRatio('padding', val, el),
|
|
95
|
+
scrollPadding: (val, el) => transformSizeRatio('scrollPadding', val, el),
|
|
100
96
|
paddingInline: (val) => {
|
|
101
97
|
if (!isString(val)) return
|
|
102
98
|
const [paddingInlineStart, paddingInlineEnd] = val.split(' ')
|
|
@@ -113,19 +109,17 @@ export const BLOCK_PROPS = {
|
|
|
113
109
|
...transformSize('paddingBlockEnd', paddingBlockEnd || paddingBlockStart)
|
|
114
110
|
}
|
|
115
111
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
margin: (val, { props }) => transformSizeRatio('margin', val, props),
|
|
112
|
+
paddingTop: (val, el) => transformSizeRatio('paddingBlockStart', val, el),
|
|
113
|
+
paddingBottom: (val, el) => transformSizeRatio('paddingBlockEnd', val, el),
|
|
114
|
+
paddingLeft: (val, el) => transformSizeRatio('paddingInlineStart', val, el),
|
|
115
|
+
paddingRight: (val, el) => transformSizeRatio('paddingInlineEnd', val, el),
|
|
116
|
+
|
|
117
|
+
paddingBlockStart: (val, el) => transformSizeRatio('paddingBlockStart', val, el),
|
|
118
|
+
paddingBlockEnd: (val, el) => transformSizeRatio('paddingBlockEnd', val, el),
|
|
119
|
+
paddingInlineStart: (val, el) => transformSizeRatio('paddingInlineStart', val, el),
|
|
120
|
+
paddingInlineEnd: (val, el) => transformSizeRatio('paddingInlineEnd', val, el),
|
|
121
|
+
|
|
122
|
+
margin: (val, el) => transformSizeRatio('margin', val, el),
|
|
129
123
|
marginInline: (val) => {
|
|
130
124
|
if (!isString(val)) return
|
|
131
125
|
const [marginInlineStart, marginInlineEnd] = val.split(' ')
|
|
@@ -134,39 +128,37 @@ export const BLOCK_PROPS = {
|
|
|
134
128
|
...transformSize('marginInlineEnd', marginInlineEnd || marginInlineStart)
|
|
135
129
|
}
|
|
136
130
|
},
|
|
137
|
-
marginBlock: (val,
|
|
138
|
-
if (!isString(
|
|
139
|
-
const [marginBlockStart, marginBlockEnd] =
|
|
131
|
+
marginBlock: (val, el) => {
|
|
132
|
+
if (!isString(el.marginBlock)) return
|
|
133
|
+
const [marginBlockStart, marginBlockEnd] = el.marginBlock.split(' ')
|
|
140
134
|
return {
|
|
141
135
|
...transformSize('marginBlockStart', marginBlockStart),
|
|
142
136
|
...transformSize('marginBlockEnd', marginBlockEnd || marginBlockStart)
|
|
143
137
|
}
|
|
144
138
|
},
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
marginBlockStart: (val, { props }) => transformSizeRatio('marginBlockStart', val, props),
|
|
155
|
-
marginBlockEnd: (val, { props }) => transformSizeRatio('marginBlockEnd', val, props),
|
|
139
|
+
marginTop: (val, el) => transformSizeRatio('marginBlockStart', val, el),
|
|
140
|
+
marginBottom: (val, el) => transformSizeRatio('marginBlockEnd', val, el),
|
|
141
|
+
marginLeft: (val, el) => transformSizeRatio('marginInlineStart', val, el),
|
|
142
|
+
marginRight: (val, el) => transformSizeRatio('marginInlineEnd', val, el),
|
|
143
|
+
|
|
144
|
+
marginInlineStart: (val, el) => transformSizeRatio('marginInlineStart', val, el),
|
|
145
|
+
marginInlineEnd: (val, el) => transformSizeRatio('marginInlineEnd', val, el),
|
|
146
|
+
marginBlockStart: (val, el) => transformSizeRatio('marginBlockStart', val, el),
|
|
147
|
+
marginBlockEnd: (val, el) => transformSizeRatio('marginBlockEnd', val, el),
|
|
156
148
|
|
|
157
149
|
gap: (val) => ({
|
|
158
150
|
gap: transfromGap(val)
|
|
159
151
|
}),
|
|
160
152
|
|
|
161
|
-
columnGap: (val,
|
|
162
|
-
rowGap: (val,
|
|
153
|
+
columnGap: (val, el) => getSpacingBasedOnRatio(el, 'columnGap', val),
|
|
154
|
+
rowGap: (val, el) => getSpacingBasedOnRatio(el, 'rowGap', val),
|
|
163
155
|
|
|
164
|
-
flexWrap: (val
|
|
156
|
+
flexWrap: (val) => ({
|
|
165
157
|
display: 'flex',
|
|
166
|
-
|
|
158
|
+
flexWrap: val
|
|
167
159
|
}),
|
|
168
|
-
flexFlow: (val,
|
|
169
|
-
const
|
|
160
|
+
flexFlow: (val, el) => {
|
|
161
|
+
const reverse = el.reverse
|
|
170
162
|
if (!isString(val)) return
|
|
171
163
|
let [direction, wrap] = (val || 'row').split(' ')
|
|
172
164
|
if (val.startsWith('x') || val === 'row') direction = 'row'
|
|
@@ -186,6 +178,6 @@ export const BLOCK_PROPS = {
|
|
|
186
178
|
}
|
|
187
179
|
},
|
|
188
180
|
|
|
189
|
-
round: (val,
|
|
190
|
-
borderRadius: (val,
|
|
181
|
+
round: (val, el) => transformBorderRadius(val ?? el.borderRadius, el, 'round'),
|
|
182
|
+
borderRadius: (val, el) => transformBorderRadius(val ?? el.round, el, 'borderRadius')
|
|
191
183
|
}
|
package/src/props/flex.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isString } from '@
|
|
3
|
+
import { isString } from '@symbo.ls/utils'
|
|
4
4
|
|
|
5
5
|
export const FLEX_PROPS = {
|
|
6
6
|
flow: (value, el) => {
|
|
7
|
-
const
|
|
8
|
-
const { reverse } = props
|
|
7
|
+
const reverse = el.reverse
|
|
9
8
|
if (!isString(value)) return
|
|
10
9
|
let [direction, wrap] = (value || 'row').split(' ')
|
|
11
10
|
if (value.startsWith('x') || value === 'row') direction = 'row'
|
|
@@ -20,11 +19,11 @@ export const FLEX_PROPS = {
|
|
|
20
19
|
}
|
|
21
20
|
},
|
|
22
21
|
|
|
23
|
-
wrap: (value,
|
|
22
|
+
wrap: (value, el) => {
|
|
24
23
|
return { display: 'flex', flexWrap: value }
|
|
25
24
|
},
|
|
26
25
|
|
|
27
|
-
align: (value,
|
|
26
|
+
align: (value, el) => {
|
|
28
27
|
const [alignItems, justifyContent] = value.split(' ')
|
|
29
28
|
return { display: 'flex', alignItems, justifyContent }
|
|
30
29
|
}
|
package/src/props/index.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { ANIMATION_PROPS } from './animation'
|
|
4
|
-
import { BLOCK_PROPS } from './block'
|
|
5
|
-
import { FONT_PROPS } from './font'
|
|
6
|
-
import { MISC_PROPS } from './misc'
|
|
7
|
-
import { POSITION_PROPS } from './position'
|
|
8
|
-
import { THEME_PROPS } from './theme'
|
|
9
|
-
import { TIMING_PROPS } from './timing'
|
|
10
|
-
import { FLEX_PROPS } from './flex'
|
|
11
|
-
import { GRID_PROPS } from './grid'
|
|
3
|
+
import { ANIMATION_PROPS } from './animation.js'
|
|
4
|
+
import { BLOCK_PROPS } from './block.js'
|
|
5
|
+
import { FONT_PROPS } from './font.js'
|
|
6
|
+
import { MISC_PROPS } from './misc.js'
|
|
7
|
+
import { POSITION_PROPS } from './position.js'
|
|
8
|
+
import { THEME_PROPS } from './theme.js'
|
|
9
|
+
import { TIMING_PROPS } from './timing.js'
|
|
10
|
+
import { FLEX_PROPS } from './flex.js'
|
|
11
|
+
import { GRID_PROPS } from './grid.js'
|
|
12
12
|
|
|
13
|
-
export * from './animation'
|
|
14
|
-
export * from './block'
|
|
15
|
-
export * from './font'
|
|
16
|
-
export * from './misc'
|
|
17
|
-
export * from './position'
|
|
18
|
-
export * from './theme'
|
|
19
|
-
export * from './timing'
|
|
20
|
-
export * from './flex'
|
|
21
|
-
export * from './grid'
|
|
13
|
+
export * from './animation.js'
|
|
14
|
+
export * from './block.js'
|
|
15
|
+
export * from './font.js'
|
|
16
|
+
export * from './misc.js'
|
|
17
|
+
export * from './position.js'
|
|
18
|
+
export * from './theme.js'
|
|
19
|
+
export * from './timing.js'
|
|
20
|
+
export * from './flex.js'
|
|
21
|
+
export * from './grid.js'
|
|
22
22
|
|
|
23
23
|
export const CSS_PROPS_REGISTRY = {
|
|
24
24
|
...ANIMATION_PROPS,
|
|
25
25
|
...BLOCK_PROPS,
|
|
26
26
|
...FONT_PROPS,
|
|
27
27
|
...MISC_PROPS,
|
|
28
|
-
...MISC_PROPS,
|
|
29
28
|
...POSITION_PROPS,
|
|
30
29
|
...THEME_PROPS,
|
|
31
30
|
...TIMING_PROPS,
|
package/src/props/misc.js
CHANGED
|
@@ -8,9 +8,16 @@ export const MISC_PROPS = {
|
|
|
8
8
|
cursor: (value, el, s, ctx) => {
|
|
9
9
|
if (!value) return
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
11
|
+
const asset = ctx.assets && ctx.assets[value]
|
|
12
|
+
if (asset && asset.content) value = `url(${asset.content.src})`
|
|
13
|
+
else {
|
|
14
|
+
const file = ctx.files && ctx.files[value]
|
|
15
|
+
if (file && file.content) value = `url(${file.content.src})`
|
|
16
|
+
}
|
|
13
17
|
|
|
14
18
|
return ({ cursor: value })
|
|
15
|
-
}
|
|
19
|
+
},
|
|
20
|
+
opacity: (value) => value != null ? ({ opacity: String(value) }) : undefined,
|
|
21
|
+
visibility: (value) => value != null ? ({ visibility: value }) : undefined,
|
|
22
|
+
pointerEvents: (value) => value != null ? ({ pointerEvents: value }) : undefined
|
|
16
23
|
}
|
package/src/props/theme.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
transformSizeRatio
|
|
13
13
|
} from '@symbo.ls/scratch'
|
|
14
14
|
|
|
15
|
-
import { isDefined, isString } from '@
|
|
15
|
+
import { isDefined, isString } from '@symbo.ls/utils'
|
|
16
16
|
|
|
17
17
|
export const getSystemGlobalTheme = ({ context, state }) => {
|
|
18
18
|
const theme = state?.root?.globalTheme || context.designSystem?.globalTheme
|
|
@@ -21,12 +21,11 @@ export const getSystemGlobalTheme = ({ context, state }) => {
|
|
|
21
21
|
|
|
22
22
|
export const THEME_PROPS = {
|
|
23
23
|
theme: (val, element) => {
|
|
24
|
-
const { props } = element
|
|
25
24
|
if (!val) return
|
|
26
25
|
|
|
27
26
|
// themeModifier explicitly forces a scheme on this component
|
|
28
|
-
if (
|
|
29
|
-
return getMediaTheme(val, `@${
|
|
27
|
+
if (element.themeModifier) {
|
|
28
|
+
return getMediaTheme(val, `@${element.themeModifier}`)
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
// CSS vars handle dark/light switching — no modifier needed, no DOMQL re-render
|
|
@@ -63,8 +62,12 @@ export const THEME_PROPS = {
|
|
|
63
62
|
backgroundImage: (val, element, s, ctx) => {
|
|
64
63
|
const globalTheme = getSystemGlobalTheme(element)
|
|
65
64
|
if (!val) return
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
65
|
+
const asset = ctx.assets && ctx.assets[val]
|
|
66
|
+
if (asset && asset.content) val = asset.content.src
|
|
67
|
+
else {
|
|
68
|
+
const file = ctx.files && ctx.files[val]
|
|
69
|
+
if (file && file.content) val = file.content.src
|
|
70
|
+
}
|
|
68
71
|
return {
|
|
69
72
|
backgroundImage: transformBackgroundImage(val, globalTheme)
|
|
70
73
|
}
|
|
@@ -78,7 +81,7 @@ export const THEME_PROPS = {
|
|
|
78
81
|
outline: transformBorder(val)
|
|
79
82
|
}),
|
|
80
83
|
|
|
81
|
-
outlineOffset: (val,
|
|
84
|
+
outlineOffset: (val, el) => transformSizeRatio('outlineOffset', val, el),
|
|
82
85
|
|
|
83
86
|
border: (val) => ({
|
|
84
87
|
border: transformBorder(val)
|
package/src/set.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { isObject } from '@symbo.ls/utils'
|
|
4
|
+
import { useCssInProps } from './transform/index.js'
|
|
5
|
+
import { css } from '@symbo.ls/css'
|
|
5
6
|
|
|
6
|
-
export const
|
|
7
|
+
export const transformClassname = (element) => {
|
|
8
|
+
if (!isObject(element)) return
|
|
9
|
+
return useCssInProps(element, element)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const setClassname = (props, cssEngine) => {
|
|
7
13
|
const transform = transformClassname(props)
|
|
8
|
-
return
|
|
14
|
+
if (typeof cssEngine === 'function') return cssEngine(transform)
|
|
15
|
+
return css(transform)
|
|
9
16
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { exec, isArray, isFunction, isObject, isProduction, merge, overwrite, overwriteDeep } from '@
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { exec, isArray, isFunction, isObject, isProduction, merge, overwrite, overwriteDeep } from '@symbo.ls/utils'
|
|
4
|
+
import { pushConfig, popConfig } from '@symbo.ls/scratch'
|
|
5
|
+
import { CSS_PROPS_REGISTRY } from '../props/index.js'
|
|
6
|
+
import { DEFAULT_CSS_PROPERTIES_LIST } from '../props/defaults.js'
|
|
7
|
+
import { applyTrueProps, transformersByPrefix } from './transformers.js'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* CLASS ASSIGNMENT
|
|
@@ -14,60 +15,67 @@ const isProd = isProduction()
|
|
|
14
15
|
|
|
15
16
|
// Process non-setter properties and return remaining props
|
|
16
17
|
export const usePropsAsCSS = (sourceObj, element, opts) => {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const ds = element?.context?.designSystem
|
|
19
|
+
if (ds) pushConfig(ds)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
obj[key] = val
|
|
26
|
-
}
|
|
21
|
+
try {
|
|
22
|
+
let obj = {}
|
|
23
|
+
const rest = {}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (val.length) {
|
|
33
|
-
const CLASS = element.context.designSystem.class
|
|
34
|
-
const result = val
|
|
35
|
-
.reduce((acc, curr) => merge(acc, CLASS[curr]), {})
|
|
36
|
-
obj.designSystemClass = result
|
|
25
|
+
const setToObj = (key, val) => {
|
|
26
|
+
if (opts.unpack) {
|
|
27
|
+
obj = { ...obj, ...val }
|
|
28
|
+
return
|
|
37
29
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
obj[key] = val
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const key in sourceObj) {
|
|
34
|
+
const value = sourceObj[key]
|
|
35
|
+
if (key === 'class' && element.call('isString', sourceObj.class)) {
|
|
36
|
+
const val = value.split(' ')
|
|
37
|
+
if (val.length) {
|
|
38
|
+
const CLASS = element.context.designSystem.class
|
|
39
|
+
const result = val
|
|
40
|
+
.reduce((acc, curr) => merge(acc, CLASS[curr]), {})
|
|
41
|
+
obj.designSystemClass = result
|
|
42
|
+
}
|
|
43
|
+
} else if (key === 'true') {
|
|
44
|
+
const val = exec(value, element)
|
|
45
|
+
merge(obj, applyTrueProps(val, element))
|
|
46
|
+
} else if (element.classlist[key]) {
|
|
47
|
+
const originalFromClass = element.classlist[key]
|
|
48
|
+
const result = isFunction(originalFromClass)
|
|
49
|
+
? originalFromClass(element, element.state, element.context)
|
|
50
|
+
: originalFromClass
|
|
51
|
+
if (result) setToObj(key, result)
|
|
52
|
+
if (!isProd && isObject(obj[key])) obj[key].label = key
|
|
53
|
+
} else if (CSS_PROPS_REGISTRY[key]) {
|
|
54
|
+
let val = exec(value, element)
|
|
55
|
+
if (isArray(val)) {
|
|
56
|
+
val = val.reduce((a, c) => merge(a, c), {})
|
|
57
|
+
}
|
|
58
|
+
let result = CSS_PROPS_REGISTRY[key](val, element, element.state, element.context)
|
|
59
|
+
if (isArray(result)) result = result.reduce((a, c) => merge(a, c), {})
|
|
60
|
+
if (result) setToObj(key, result)
|
|
61
|
+
if (!isProd && isObject(obj[key])) obj[key].label = key
|
|
62
|
+
} else if (DEFAULT_CSS_PROPERTIES_LIST.has(key)) {
|
|
63
|
+
// they can be grouped
|
|
64
|
+
let result = exec(value, element)
|
|
65
|
+
if (typeof result === 'string' && result.charCodeAt(0) === 45 && result.charCodeAt(1) === 45) {
|
|
66
|
+
result = `var(${result})`
|
|
67
|
+
}
|
|
68
|
+
setToObj(key, { [key]: result })
|
|
69
|
+
if (!isProd && isObject(obj[key])) obj[key].label = key
|
|
70
|
+
} else {
|
|
71
|
+
rest[key] = value
|
|
62
72
|
}
|
|
63
|
-
setToObj(key, { [key]: result })
|
|
64
|
-
if (!isProd && isObject(obj[key])) obj[key].label = key
|
|
65
|
-
} else {
|
|
66
|
-
rest[key] = value
|
|
67
73
|
}
|
|
68
|
-
}
|
|
69
74
|
|
|
70
|
-
|
|
75
|
+
return [obj, rest]
|
|
76
|
+
} finally {
|
|
77
|
+
if (ds) popConfig()
|
|
78
|
+
}
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
export const useSelectorsAsCSS = (sourceObj, element) => {
|