@codeleap/styles 4.3.2 → 4.3.5
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 +3 -2
- package/package.json.bak +2 -1
- package/src/lib/StyleRegistry.ts +19 -14
- package/src/lib/borderCreator.ts +4 -9
- package/src/types/theme.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/styles",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.5",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"directory": "packages/styles"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@codeleap/config": "4.3.
|
|
12
|
+
"@codeleap/config": "4.3.5",
|
|
13
13
|
"ts-node-dev": "1.1.8"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@fastify/deepmerge": "1.3.0",
|
|
29
29
|
"js-sha256": "0.11.0",
|
|
30
30
|
"lz-string": "^1.5.0",
|
|
31
|
+
"rfdc": "^1.4.1",
|
|
31
32
|
"zustand": "4.5.0"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/package.json.bak
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/styles",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.5",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@fastify/deepmerge": "1.3.0",
|
|
29
29
|
"js-sha256": "0.11.0",
|
|
30
30
|
"lz-string": "^1.5.0",
|
|
31
|
+
"rfdc": "^1.4.1",
|
|
31
32
|
"zustand": "4.5.0"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/src/lib/StyleRegistry.ts
CHANGED
|
@@ -5,10 +5,13 @@ import deepmerge from '@fastify/deepmerge'
|
|
|
5
5
|
import { MultiplierFunction } from './spacing'
|
|
6
6
|
import { defaultVariants } from './defaultVariants'
|
|
7
7
|
import { dynamicVariants } from './dynamicVariants'
|
|
8
|
-
import { ignoredStyleKeys, isSpacingKey } from './utils'
|
|
8
|
+
import { capitalize, ignoredStyleKeys, isSpacingKey } from './utils'
|
|
9
9
|
import { StyleCache } from './StyleCache'
|
|
10
10
|
import { minifier } from './minifier'
|
|
11
11
|
import { StateStorage } from 'zustand/middleware'
|
|
12
|
+
import rfdc from 'rfdc'
|
|
13
|
+
|
|
14
|
+
const deepClone = rfdc()
|
|
12
15
|
|
|
13
16
|
export class CodeleapStyleRegistry {
|
|
14
17
|
stylesheets: Record<string, VariantStyleSheet> = {}
|
|
@@ -369,8 +372,6 @@ export class CodeleapStyleRegistry {
|
|
|
369
372
|
return this.mergeStylesWithCache([defaultStyle], cache.key)
|
|
370
373
|
}
|
|
371
374
|
|
|
372
|
-
const isStyleObject = typeof style === 'object' && !isStyleArray
|
|
373
|
-
|
|
374
375
|
if (typeof style === 'string') {
|
|
375
376
|
const computedVariantStyle = this.computeVariantStyle(componentName, [style])
|
|
376
377
|
|
|
@@ -380,6 +381,8 @@ export class CodeleapStyleRegistry {
|
|
|
380
381
|
)
|
|
381
382
|
}
|
|
382
383
|
|
|
384
|
+
const isStyleObject = typeof style === 'object' && !isStyleArray
|
|
385
|
+
|
|
383
386
|
if (isStyleObject) {
|
|
384
387
|
const { isComposition, composition } = this.isCompositionStyle(registeredComponent, style)
|
|
385
388
|
|
|
@@ -521,17 +524,7 @@ export class CodeleapStyleRegistry {
|
|
|
521
524
|
}
|
|
522
525
|
|
|
523
526
|
private copyStyle(style: any) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (Array.isArray(style)) {
|
|
527
|
-
copiedStyle = [...style]
|
|
528
|
-
} else if (typeof style == 'object') {
|
|
529
|
-
copiedStyle = { ...style }
|
|
530
|
-
} else {
|
|
531
|
-
copiedStyle = style
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
return copiedStyle
|
|
527
|
+
return deepClone(style)
|
|
535
528
|
}
|
|
536
529
|
|
|
537
530
|
createStyles<K extends string = string>(styles: Record<K, StyleProp<AnyRecord, ''>> | ((theme: ITheme) => Record<K, StyleProp<AnyRecord, ''>>)): Record<K, ICSS> {
|
|
@@ -565,4 +558,16 @@ export class CodeleapStyleRegistry {
|
|
|
565
558
|
},
|
|
566
559
|
})
|
|
567
560
|
}
|
|
561
|
+
|
|
562
|
+
prefixStyle(prefix: string, style: any) {
|
|
563
|
+
const entries = Object.entries(style).map(e => {
|
|
564
|
+
const [key, value] = e
|
|
565
|
+
|
|
566
|
+
const elementKey = capitalize(key)
|
|
567
|
+
|
|
568
|
+
return [`${prefix}${elementKey}`, value]
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
return Object.fromEntries(entries)
|
|
572
|
+
}
|
|
568
573
|
}
|
package/src/lib/borderCreator.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IColors, ICSS } from '../types'
|
|
2
|
-
import { StyleConstants } from './constants'
|
|
1
|
+
import { AppTheme, IColors, ICSS, Theme } from '../types'
|
|
3
2
|
import { borderDirection } from './dynamicVariants'
|
|
4
3
|
import { themeStore } from './themeStore'
|
|
5
4
|
import { capitalize } from './utils'
|
|
@@ -22,22 +21,18 @@ export const borderCreator: BorderCreator = (args) => {
|
|
|
22
21
|
directions = ['left', 'top', 'bottom', 'right'],
|
|
23
22
|
} = args
|
|
24
23
|
|
|
25
|
-
const theme = themeStore.getState().current
|
|
24
|
+
const theme = themeStore.getState().current as AppTheme<Theme>
|
|
26
25
|
|
|
27
|
-
// @ts-expect-error
|
|
28
26
|
const color = theme?.colors?.[colorKey] ?? colorKey
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
let borderStyles: ICSS = {}
|
|
31
29
|
|
|
32
30
|
for (const direction of directions) {
|
|
33
31
|
const property = `border${capitalize(direction)}`
|
|
34
32
|
|
|
35
33
|
borderStyles[`${property}Color`] = color
|
|
36
34
|
borderStyles[`${property}Width`] = width
|
|
37
|
-
|
|
38
|
-
if (StyleConstants.IS_BROWSER) {
|
|
39
|
-
borderStyles[`${property}Style`] = style
|
|
40
|
-
}
|
|
35
|
+
if (theme?.isBrowser) borderStyles[`${property}Style`] = style
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
return borderStyles
|