@rokkit/core 1.0.0-next.125 → 1.0.0-next.129

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.
@@ -1,22 +0,0 @@
1
- import { colors } from '@unocss/preset-mini/colors'
2
- // import defaultTailwindColors from './tailwind.json' with { type: 'json' }
3
- import syntaxColorPalette from './syntax.json' with { type: 'json' }
4
- import extraColors from './extra.json' with { type: 'json' }
5
-
6
- export const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
7
- export const defaultPalette = [
8
- 'surface',
9
- 'primary',
10
- 'secondary',
11
- 'accent',
12
- 'success',
13
- 'warning',
14
- 'danger',
15
- 'info'
16
- ]
17
-
18
- export const syntaxColors = syntaxColorPalette
19
- export const defaultColors = {
20
- ...colors,
21
- ...extraColors
22
- }
package/src/theme.js DELETED
@@ -1,174 +0,0 @@
1
- import { defaultThemeMapping, defaultColors, TONE_MAP } from './constants.js'
2
- import { shades } from './colors/index.js'
3
- import { hex2rgb } from './utils'
4
-
5
- const modifiers = {
6
- hsl: (value) => `hsl(${value} / <alpha-value>)`,
7
- rgb: (value) => `rgb(${value} / <alpha-value>)`,
8
- none: (value) => value
9
- }
10
-
11
- /**
12
- * Generate shades for a color using css varuable
13
- *
14
- * @param {string} name
15
- * @param {string} modifier
16
- * @returns
17
- */
18
- export function shadesOf(name, modifier = 'none') {
19
- const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
20
-
21
- return shades.reduce(
22
- (result, shade) => ({
23
- ...result,
24
- [shade]: fn(`var(--color-${name}-${shade})`)
25
- }),
26
- {
27
- DEFAULT: fn(`var(--color-${name}-500)`)
28
- }
29
- )
30
- }
31
-
32
- /**
33
- * Generates color rules for a specific theme variant, for both light and dark modes.
34
- *
35
- * @param {string} variant - The name of the variant to generate rules for.
36
- * @param {Object} colors - The object containing color definitions.
37
- * @param {Object} mapping - An object that maps variant names to color property names.
38
- * @returns {import('./types').ShadeMappings} An array containing the color rules for both light and dark modes.
39
- */
40
- function generateColorRules(variant, colors, mapping) {
41
- return ['DEFAULT', ...shades].flatMap((shade) => [
42
- {
43
- key: shade === 'DEFAULT' ? `--color-${variant}` : `--color-${variant}-${shade}`,
44
- value: hex2rgb(colors[mapping[variant]][`${shade}`])
45
- }
46
- ])
47
- }
48
-
49
- /**
50
- * Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
51
- *
52
- * @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
53
- * @param {Object} [colors=defaultColors] - The object containing default color definitions.
54
- * @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
55
- */
56
- export function themeRules(mapping = defaultThemeMapping, colors = defaultColors) {
57
- mapping = { ...defaultThemeMapping, ...mapping }
58
- colors = { ...defaultColors, ...colors }
59
- const variants = Object.keys(mapping)
60
- const rules = variants
61
- .flatMap((variant) => generateColorRules(variant, colors, mapping))
62
- .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
63
-
64
- return rules
65
- }
66
-
67
- /**
68
- * Generates UnoCSS shortcut definitions for semantic tones with bg, border, text.
69
- * @param {string} name - Color name (e.g., 'primary')
70
- * @returns {Array} Array of shortcut definitions
71
- */
72
- export function semanticShortcuts(name) {
73
- const prefixes = ['bg', 'border', 'text', 'ring', 'outline', 'from', 'to', 'divide']
74
- const shortcuts = []
75
-
76
- for (const [toneName, lightValue] of Object.entries(TONE_MAP)) {
77
- const darkValue = 1000 - lightValue
78
-
79
- for (const prefix of prefixes) {
80
- // Variant-prefixed regex (e.g., hover:bg-primary-base)
81
- const variantPattern = new RegExp(`^(.+):${prefix}-${name}-${toneName}(\/\\d+)?$`)
82
- shortcuts.push([
83
- variantPattern,
84
- ([, variant, end]) =>
85
- `${variant}:${prefix}-${name}-${lightValue}${end || ''} ${variant}:dark:${prefix}-${name}-${darkValue}${end || ''}`
86
- ])
87
-
88
- const opacityPattern = new RegExp(`${prefix}-${name}-${toneName}(\/\\d+)?$`)
89
- shortcuts.push([
90
- opacityPattern,
91
- ([, end]) =>
92
- `${prefix}-${name}-${lightValue}${end || ''} dark:${prefix}-${name}-${darkValue}${end || ''}`
93
- ])
94
-
95
- // Exact static shortcut (e.g., bg-primary-base)
96
- const exactPattern = `${prefix}-${name}-${toneName}`
97
- shortcuts.push([
98
- exactPattern,
99
- `${prefix}-${name}-${lightValue} dark:${prefix}-${name}-${darkValue}`
100
- ])
101
- }
102
- }
103
-
104
- return shortcuts
105
- }
106
-
107
- /**
108
- * Theme class for managing color palettes, mappings, and semantic shortcuts.
109
- */
110
- export class Theme {
111
- #colors
112
- #mapping
113
-
114
- /**
115
- *
116
- * @param {import('./types.js').ColorTheme} param0
117
- */
118
- constructor({ colors = defaultColors, mapping = defaultThemeMapping } = {}) {
119
- this.#colors = { ...defaultColors, ...colors }
120
- this.#mapping = { ...defaultThemeMapping, ...mapping }
121
- }
122
-
123
- get colors() {
124
- return this.#colors
125
- }
126
- set colors(colors) {
127
- this.#colors = { ...colors }
128
- }
129
-
130
- get mapping() {
131
- return this.#mapping
132
- }
133
- set mapping(mapping) {
134
- this.#mapping = { ...mapping }
135
- }
136
-
137
- mapVariant(color, variant) {
138
- return Object.keys(color).reduce(
139
- (acc, key) => ({
140
- ...acc,
141
- [key]:
142
- key === 'DEFAULT'
143
- ? `rgba(var(--color-${variant}),<alpha-value>)`
144
- : `rgba(var(--color-${variant}-${key}),<alpha-value>)`
145
- }),
146
- {}
147
- )
148
- }
149
-
150
- getColorRules(mapping = null) {
151
- const variants = Object.entries({ ...this.#mapping, ...mapping })
152
- return variants.reduce(
153
- (acc, [variant, key]) => ({
154
- ...acc,
155
- [variant]: this.mapVariant(this.#colors[key], variant)
156
- }),
157
- {}
158
- )
159
- }
160
-
161
- getPalette(mapping = null) {
162
- const useMapping = { ...this.#mapping, ...mapping }
163
- const useColors = { ...defaultColors, ...this.#colors }
164
- const variants = Object.keys(useMapping)
165
- const rules = variants
166
- .flatMap((variant) => generateColorRules(variant, useColors, useMapping))
167
- .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
168
- return rules
169
- }
170
-
171
- getShortcuts(name) {
172
- return semanticShortcuts(name)
173
- }
174
- }