@rokkit/core 1.0.0-next.147 → 1.0.0-next.149
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/dist/utils.d.ts +11 -0
- package/package.json +1 -1
- package/src/theme.ts +5 -3
- package/src/utils.js +17 -0
package/dist/utils.d.ts
CHANGED
|
@@ -84,6 +84,17 @@ export function resolveSnippet(snippets: any, proxy: any, fallback?: string): Fu
|
|
|
84
84
|
* @return {string}
|
|
85
85
|
*/
|
|
86
86
|
export function hex2rgb(hex: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Convert a CSS color value to r,g,b for use in CSS variables.
|
|
89
|
+
* Hex values (#rrggbb) are converted to "r,g,b" for rgba() support.
|
|
90
|
+
* All other CSS color formats (oklch, hsl, named) are returned as-is.
|
|
91
|
+
* Non-string values are returned unchanged.
|
|
92
|
+
* Note: non-hex values will NOT work with UnoCSS opacity utilities like bg-primary/50.
|
|
93
|
+
*
|
|
94
|
+
* @param {unknown} value
|
|
95
|
+
* @returns {unknown}
|
|
96
|
+
*/
|
|
97
|
+
export function colorToRgb(value: unknown): unknown;
|
|
87
98
|
/**
|
|
88
99
|
* A utility function that detects if a string is an image URL or image data (base64)
|
|
89
100
|
*
|
package/package.json
CHANGED
package/src/theme.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
import { DEFAULT_THEME_MAPPING, defaultColors, TONE_MAP } from './constants'
|
|
4
4
|
import { shades } from './colors/index'
|
|
5
|
-
import {
|
|
5
|
+
import { colorToRgb } from './utils'
|
|
6
6
|
|
|
7
7
|
const modifiers = {
|
|
8
8
|
hsl: (value) => `hsl(${value} / <alpha-value>)`,
|
|
@@ -43,7 +43,7 @@ function generateColorRules(variant, colors, mapping) {
|
|
|
43
43
|
return ['DEFAULT', ...shades].flatMap((shade) => [
|
|
44
44
|
{
|
|
45
45
|
key: shade === 'DEFAULT' ? `--color-${variant}` : `--color-${variant}-${shade}`,
|
|
46
|
-
value:
|
|
46
|
+
value: colorToRgb(colors[mapping[variant]][`${shade}`])
|
|
47
47
|
}
|
|
48
48
|
])
|
|
49
49
|
}
|
|
@@ -78,7 +78,9 @@ const SEMANTIC_PREFIXES = [
|
|
|
78
78
|
'outline',
|
|
79
79
|
'from',
|
|
80
80
|
'to',
|
|
81
|
-
'divide'
|
|
81
|
+
'divide',
|
|
82
|
+
'stroke',
|
|
83
|
+
'fill'
|
|
82
84
|
]
|
|
83
85
|
|
|
84
86
|
/**
|
package/src/utils.js
CHANGED
|
@@ -204,6 +204,23 @@ export function hex2rgb(hex) {
|
|
|
204
204
|
return `${r},${g},${b}`
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Convert a CSS color value to r,g,b for use in CSS variables.
|
|
209
|
+
* Hex values (#rrggbb) are converted to "r,g,b" for rgba() support.
|
|
210
|
+
* All other CSS color formats (oklch, hsl, named) are returned as-is.
|
|
211
|
+
* Non-string values are returned unchanged.
|
|
212
|
+
* Note: non-hex values will NOT work with UnoCSS opacity utilities like bg-primary/50.
|
|
213
|
+
*
|
|
214
|
+
* @param {unknown} value
|
|
215
|
+
* @returns {unknown}
|
|
216
|
+
*/
|
|
217
|
+
export function colorToRgb(value) {
|
|
218
|
+
if (typeof value === 'string' && /^#[0-9a-fA-F]{6}$/.test(value)) {
|
|
219
|
+
return hex2rgb(value)
|
|
220
|
+
}
|
|
221
|
+
return value
|
|
222
|
+
}
|
|
223
|
+
|
|
207
224
|
/**
|
|
208
225
|
* Checks if a string is a valid image URL
|
|
209
226
|
*
|