@rokkit/core 1.0.0-next.99 → 1.0.2
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 +121 -1
- package/package.json +26 -34
- package/src/colors/extra.json +16 -0
- package/src/colors/index.ts +24 -0
- package/src/colors/syntax.json +4 -4
- package/src/colors/tailwind.json +0 -14
- package/src/connector.js +28 -23
- package/src/constants.js +113 -24
- package/src/events.js +32 -0
- package/src/field-mapper.js +147 -0
- package/src/index.js +13 -11
- package/src/key-event-map.js +35 -0
- package/src/mapped-items.js +22 -0
- package/src/mapping.js +5 -122
- package/src/nested.js +3 -31
- package/src/string.js +11 -11
- package/src/theme.ts +243 -0
- package/src/types.js +45 -0
- package/src/utils.js +203 -3
- package/src/vite/icon-collections.js +73 -0
- package/src/vite/index.js +1 -0
- package/LICENSE +0 -21
- package/src/colors/index.js +0 -19
- package/src/mapped-list.js +0 -233
- package/src/theme.js +0 -197
package/src/theme.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { defaultThemeMapping, defaultColors, syntaxColors } from './constants'
|
|
2
|
-
import { shades, defaultPalette } from './colors'
|
|
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
|
-
}
|