@rokkit/core 1.0.0-next.116 → 1.0.0-next.118
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 +6 -0
- package/package.json +1 -1
- package/src/theme.js +12 -11
- package/src/utils.js +10 -0
package/dist/utils.d.ts
CHANGED
|
@@ -67,4 +67,10 @@ export function getPathFromKey(key: string): string[];
|
|
|
67
67
|
* @returns {Function|undefined}
|
|
68
68
|
*/
|
|
69
69
|
export function getSnippet(obj: Object, key: string, defaultSnippet?: null | Function): Function | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* convert hex string to `{r} {g} {b}`
|
|
72
|
+
* @param {string} hex
|
|
73
|
+
* @return {string}
|
|
74
|
+
*/
|
|
75
|
+
export function hex2rgb(hex: string): string;
|
|
70
76
|
export function importIcons(icons: Object): Object;
|
package/package.json
CHANGED
package/src/theme.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { defaultThemeMapping, defaultColors, syntaxColors } from './constants.js'
|
|
2
2
|
import { shades, defaultPalette } from './colors/index.js'
|
|
3
|
+
import { hex2rgb } from './utils'
|
|
3
4
|
|
|
4
5
|
const modifiers = {
|
|
5
|
-
hsl: (value) => `hsl(${value})`,
|
|
6
|
-
rgb: (value) => `rgb(${value})
|
|
7
|
-
|
|
6
|
+
hsl: (value) => `hsl(${value} / <alpha-value>)`,
|
|
7
|
+
rgb: (value) => `rgb(${value} / <alpha-value>)`
|
|
8
|
+
// rgb: (value) => value
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -14,8 +15,8 @@ const modifiers = {
|
|
|
14
15
|
* @param {string} modifier
|
|
15
16
|
* @returns
|
|
16
17
|
*/
|
|
17
|
-
export function shadesOf(name, modifier = '
|
|
18
|
-
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.
|
|
18
|
+
export function shadesOf(name, modifier = 'rgb') {
|
|
19
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.rgb
|
|
19
20
|
|
|
20
21
|
return shades.reduce(
|
|
21
22
|
(result, shade) => ({
|
|
@@ -44,8 +45,8 @@ export function shadesOf(name, modifier = 'none') {
|
|
|
44
45
|
* @param {string} modifier
|
|
45
46
|
* @returns {object}
|
|
46
47
|
*/
|
|
47
|
-
export function stateColors(name, modifier = '
|
|
48
|
-
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.
|
|
48
|
+
export function stateColors(name, modifier = 'rgb') {
|
|
49
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.rgb
|
|
49
50
|
return {
|
|
50
51
|
DEFAULT: fn(`var(--${name}-500)`),
|
|
51
52
|
light: fn(`var(--${name}-200)`),
|
|
@@ -58,8 +59,8 @@ export function stateColors(name, modifier = 'none') {
|
|
|
58
59
|
* @param {string} modifier
|
|
59
60
|
* @returns
|
|
60
61
|
*/
|
|
61
|
-
export function themeColors(modifier = '
|
|
62
|
-
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.
|
|
62
|
+
export function themeColors(modifier = 'rgb') {
|
|
63
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.rgb
|
|
63
64
|
|
|
64
65
|
const states = ['info', 'danger', 'warning', 'success', 'error']
|
|
65
66
|
const variants = ['neutral', 'primary', 'secondary', 'accent']
|
|
@@ -129,12 +130,12 @@ function generateColorRules(variant, colors, mapping) {
|
|
|
129
130
|
return shades.flatMap((shade, index) => [
|
|
130
131
|
{
|
|
131
132
|
key: `--${variant}-${shade}`,
|
|
132
|
-
value: colors[mapping[variant]][shade],
|
|
133
|
+
value: hex2rgb(colors[mapping[variant]][shade]),
|
|
133
134
|
mode: 'light'
|
|
134
135
|
},
|
|
135
136
|
{
|
|
136
137
|
key: `--${variant}-${shade}`,
|
|
137
|
-
value: colors[mapping[variant]][shades[shades.length - index - 1]],
|
|
138
|
+
value: hex2rgb(colors[mapping[variant]][shades[shades.length - index - 1]]),
|
|
138
139
|
mode: 'dark'
|
|
139
140
|
}
|
|
140
141
|
])
|
package/src/utils.js
CHANGED
|
@@ -135,3 +135,13 @@ export const importIcons = (icons) => {
|
|
|
135
135
|
return acc
|
|
136
136
|
}, {})
|
|
137
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* convert hex string to `{r} {g} {b}`
|
|
141
|
+
* @param {string} hex
|
|
142
|
+
* @return {string}
|
|
143
|
+
*/
|
|
144
|
+
export function hex2rgb(hex) {
|
|
145
|
+
const [r, g, b] = hex.match(/\w\w/g).map((x) => parseInt(x, 16))
|
|
146
|
+
return `${r} ${g} ${b}`
|
|
147
|
+
}
|