@rokkit/core 1.0.0-next.104 → 1.0.0-next.105
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/index.d.ts +1 -0
- package/dist/theme.d.ts +47 -0
- package/package.json +7 -6
- package/src/index.js +2 -0
- package/src/theme.js +197 -0
- package/LICENSE +0 -21
package/dist/index.d.ts
CHANGED
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate shades for a color using css varuable
|
|
3
|
+
*
|
|
4
|
+
* @param {string} name
|
|
5
|
+
* @param {string} modifier
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function shadesOf(name: string, modifier?: string): {
|
|
9
|
+
DEFAULT: any;
|
|
10
|
+
base: any;
|
|
11
|
+
inset: any;
|
|
12
|
+
subtle: any;
|
|
13
|
+
muted: any;
|
|
14
|
+
raised: any;
|
|
15
|
+
elevated: any;
|
|
16
|
+
floating: any;
|
|
17
|
+
contrast: any;
|
|
18
|
+
overlay: any;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Generate shades for a color using css varuable
|
|
22
|
+
*
|
|
23
|
+
* @param {string} name
|
|
24
|
+
* @param {string} modifier
|
|
25
|
+
* @returns {object}
|
|
26
|
+
*/
|
|
27
|
+
export function stateColors(name: string, modifier?: string): object;
|
|
28
|
+
export function themeColors(modifier?: string): {};
|
|
29
|
+
/**
|
|
30
|
+
* Generates contrast colors for light and dark modes based on a given palette. Each color variant in the
|
|
31
|
+
* palette is mapped to either a light or dark contrast color depending on the shade's value.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} [light='#ffffff'] - The default light color used when the shade is >= 500 in light mode or <= 500 in dark mode.
|
|
34
|
+
* @param {string} [dark='#000000'] - The default dark color used when the shade is < 500 in light mode or > 500 in dark mode.
|
|
35
|
+
* @param {Array<string>} [palette=defaultPalette] - An array of color variant names to generate contrast colors for.
|
|
36
|
+
* @returns {Array<Object>} An array containing contrast color rules organized by light and dark modes for each variant in the palette.
|
|
37
|
+
*/
|
|
38
|
+
export function contrastColors(light?: string, dark?: string, palette?: Array<string>): Array<Object>;
|
|
39
|
+
/**
|
|
40
|
+
* Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} name - The base name for the theme, defaults to 'rokkit' if not provided.
|
|
43
|
+
* @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
|
|
44
|
+
* @param {Object} [colors=defaultColors] - The object containing default color definitions.
|
|
45
|
+
* @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
|
|
46
|
+
*/
|
|
47
|
+
export function themeRules(name?: string, mapping?: Object, colors?: Object): Array<any[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/core",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.105",
|
|
4
4
|
"description": "Contains core utility functions and classes that can be used in various components.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"prepublishOnly": "tsc --project tsconfig.build.json",
|
|
14
|
+
"clean": "rm -rf dist",
|
|
15
|
+
"build": "bun clean && bun prepublishOnly"
|
|
16
|
+
},
|
|
12
17
|
"files": [
|
|
13
18
|
"src/**/*.js",
|
|
14
19
|
"src/**/*.json",
|
|
@@ -24,9 +29,5 @@
|
|
|
24
29
|
},
|
|
25
30
|
"dependencies": {
|
|
26
31
|
"ramda": "^0.30.1"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"clean": "rm -rf dist",
|
|
30
|
-
"build": "pnpm clean && pnpm prepublishOnly"
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
}
|
package/src/index.js
CHANGED
package/src/theme.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { defaultThemeMapping, defaultColors, syntaxColors } from './constants.js'
|
|
2
|
+
import { shades, defaultPalette } from './colors/index.js'
|
|
3
|
+
|
|
4
|
+
const modifiers = {
|
|
5
|
+
hsl: (value) => `hsl(${value})`,
|
|
6
|
+
rgb: (value) => `rgb(${value})`,
|
|
7
|
+
none: (value) => value
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generate shades for a color using css varuable
|
|
12
|
+
*
|
|
13
|
+
* @param {string} name
|
|
14
|
+
* @param {string} modifier
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export function shadesOf(name, modifier = 'none') {
|
|
18
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
19
|
+
|
|
20
|
+
return shades.reduce(
|
|
21
|
+
(result, shade) => ({
|
|
22
|
+
...result,
|
|
23
|
+
[shade]: fn(`var(--${name}-${shade})`)
|
|
24
|
+
}),
|
|
25
|
+
{
|
|
26
|
+
DEFAULT: fn(`var(--${name}-500)`),
|
|
27
|
+
base: fn(`var(--${name}-50)`),
|
|
28
|
+
inset: fn(`var(--${name}-100)`),
|
|
29
|
+
subtle: fn(`var(--${name}-200)`),
|
|
30
|
+
muted: fn(`var(--${name}-300)`),
|
|
31
|
+
raised: fn(`var(--${name}-400)`),
|
|
32
|
+
elevated: fn(`var(--${name}-600)`),
|
|
33
|
+
floating: fn(`var(--${name}-700)`),
|
|
34
|
+
contrast: fn(`var(--${name}-800)`),
|
|
35
|
+
overlay: fn(`var(--${name}-900)`)
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Generate shades for a color using css varuable
|
|
42
|
+
*
|
|
43
|
+
* @param {string} name
|
|
44
|
+
* @param {string} modifier
|
|
45
|
+
* @returns {object}
|
|
46
|
+
*/
|
|
47
|
+
export function stateColors(name, modifier = 'none') {
|
|
48
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
49
|
+
return {
|
|
50
|
+
DEFAULT: fn(`var(--${name}-500)`),
|
|
51
|
+
light: fn(`var(--${name}-200)`),
|
|
52
|
+
dark: fn(`var(--${name}-700)`)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function themeColors(modifier = 'none') {
|
|
57
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
58
|
+
|
|
59
|
+
const states = ['info', 'danger', 'warning', 'success', 'error']
|
|
60
|
+
const variants = ['neutral', 'primary', 'secondary', 'accent']
|
|
61
|
+
let colors = states.reduce(
|
|
62
|
+
(acc, state) => ({ ...acc, [state]: stateColors(state, modifier) }),
|
|
63
|
+
{}
|
|
64
|
+
)
|
|
65
|
+
colors = variants.reduce(
|
|
66
|
+
(acc, variant) => ({ ...acc, [variant]: shadesOf(variant, modifier) }),
|
|
67
|
+
colors
|
|
68
|
+
)
|
|
69
|
+
colors.neutral = {
|
|
70
|
+
...colors.neutral,
|
|
71
|
+
// contrast: fn(`var(--neutral-800)`),
|
|
72
|
+
zebra: fn('var(--neutral-zebra)')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return colors
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Creates an array of shade mapping objects for a given theme variant and mode.
|
|
80
|
+
* Each object represents a CSS custom property (variable) with its value set based on a provided condition.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} variant - The name of the theme variant (e.g., 'primary', 'secondary').
|
|
83
|
+
* @param {'light' | 'dark'} mode - The theme mode for which the mappings are being created.
|
|
84
|
+
* @param {function(number): string} valueCondition - A function that takes a shade value and returns the color value
|
|
85
|
+
* based on the condition appropriate for light or dark mode.
|
|
86
|
+
* @returns {{import('./types'}.ShadeMapping[]>} An array of objects, where each object contains key, value, and mode
|
|
87
|
+
* properties corresponding to a CSS custom property definition.
|
|
88
|
+
*/
|
|
89
|
+
function createShadeMappings(variant, mode, valueCondition) {
|
|
90
|
+
return shades.map((shade) => ({
|
|
91
|
+
key: `--on-${variant}-${shade}`,
|
|
92
|
+
value: valueCondition(shade),
|
|
93
|
+
mode
|
|
94
|
+
}))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Generates contrast colors for light and dark modes based on a given palette. Each color variant in the
|
|
99
|
+
* palette is mapped to either a light or dark contrast color depending on the shade's value.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} [light='#ffffff'] - The default light color used when the shade is >= 500 in light mode or <= 500 in dark mode.
|
|
102
|
+
* @param {string} [dark='#000000'] - The default dark color used when the shade is < 500 in light mode or > 500 in dark mode.
|
|
103
|
+
* @param {Array<string>} [palette=defaultPalette] - An array of color variant names to generate contrast colors for.
|
|
104
|
+
* @returns {Array<Object>} An array containing contrast color rules organized by light and dark modes for each variant in the palette.
|
|
105
|
+
*/
|
|
106
|
+
export function contrastColors(light = '#ffffff', dark = '#000000', palette = defaultPalette) {
|
|
107
|
+
const colors = palette
|
|
108
|
+
.flatMap((variant) => [
|
|
109
|
+
createShadeMappings(variant, 'light', (shade) => (shade < 500 ? dark : light)),
|
|
110
|
+
createShadeMappings(variant, 'dark', (shade) => (shade > 500 ? dark : light))
|
|
111
|
+
])
|
|
112
|
+
.reduce((acc, item) => [...acc, ...item], [])
|
|
113
|
+
return colors
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Generates color rules for a specific theme variant, for both light and dark modes.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} variant - The name of the variant to generate rules for.
|
|
119
|
+
* @param {Object} colors - The object containing color definitions.
|
|
120
|
+
* @param {Object} mapping - An object that maps variant names to color property names.
|
|
121
|
+
* @returns {import('./types').ShadeMappings} An array containing the color rules for both light and dark modes.
|
|
122
|
+
*/
|
|
123
|
+
function generateColorRules(variant, colors, mapping) {
|
|
124
|
+
return shades.flatMap((shade, index) => [
|
|
125
|
+
{
|
|
126
|
+
key: `--${variant}-${shade}`,
|
|
127
|
+
value: colors[mapping[variant]][shade],
|
|
128
|
+
mode: 'light'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
key: `--${variant}-${shade}`,
|
|
132
|
+
value: colors[mapping[variant]][shades[shades.length - index - 1]],
|
|
133
|
+
mode: 'dark'
|
|
134
|
+
}
|
|
135
|
+
])
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Filters the rules for a specific mode and transforms them into an object mapping
|
|
140
|
+
* CSS variable names to their values.
|
|
141
|
+
*
|
|
142
|
+
* @param {Array<Object>} rules - The array of rules to filter and transform.
|
|
143
|
+
* @param {'light' | 'dark'} mode - The mode to filter by.
|
|
144
|
+
* @returns {Object} An object containing the rules specific to the provided mode.
|
|
145
|
+
*/
|
|
146
|
+
function filterRulesByMode(rules, mode) {
|
|
147
|
+
return rules
|
|
148
|
+
.filter((rule) => rule.mode === mode)
|
|
149
|
+
.reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Creates a theme variant object with a given mode, a collection of color rules, and additional colors.
|
|
154
|
+
*
|
|
155
|
+
* @param {string} name - The base name for the theme variant.
|
|
156
|
+
* @param {'light' | 'dark'} mode - The mode of the theme variant.
|
|
157
|
+
* @param {Object} colors - The object containing color rules for the theme.
|
|
158
|
+
* @param {Object} extraColors - Any additional color properties for the theme.
|
|
159
|
+
* @returns {Array} An array where the first element is the theme's name and the second element
|
|
160
|
+
* is an object containing all color rules and extra properties for the theme variant.
|
|
161
|
+
*/
|
|
162
|
+
function createThemeVariant(name, mode, colors, extraColors) {
|
|
163
|
+
return [
|
|
164
|
+
`${name}-mode-${mode}`,
|
|
165
|
+
{
|
|
166
|
+
...colors,
|
|
167
|
+
...extraColors,
|
|
168
|
+
'--plot-background': 'var(--neutral-200)'
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
|
|
175
|
+
*
|
|
176
|
+
* @param {string} name - The base name for the theme, defaults to 'rokkit' if not provided.
|
|
177
|
+
* @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
|
|
178
|
+
* @param {Object} [colors=defaultColors] - The object containing default color definitions.
|
|
179
|
+
* @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
|
|
180
|
+
*/
|
|
181
|
+
export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
|
|
182
|
+
mapping = { ...defaultThemeMapping, ...mapping }
|
|
183
|
+
const variants = Object.keys(mapping)
|
|
184
|
+
|
|
185
|
+
const rules = variants.reduce(
|
|
186
|
+
(acc, variant) => [...acc, ...generateColorRules(variant, colors, mapping)],
|
|
187
|
+
[]
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
const lightRules = filterRulesByMode(rules, 'light')
|
|
191
|
+
const darkRules = filterRulesByMode(rules, 'dark')
|
|
192
|
+
|
|
193
|
+
const lightTheme = createThemeVariant(name, 'light', lightRules, syntaxColors['one-dark'].light)
|
|
194
|
+
const darkTheme = createThemeVariant(name, 'dark', darkRules, syntaxColors['one-dark'].dark)
|
|
195
|
+
|
|
196
|
+
return [lightTheme, darkTheme]
|
|
197
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Jerry Thomas
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|