@rokkit/core 1.2.0 → 1.3.1
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/constants.d.ts +0 -13
- package/dist/named-tokens.d.ts +0 -15
- package/dist/theme.d.ts +3 -37
- package/package.json +2 -2
- package/src/constants.js +0 -14
- package/src/named-tokens.ts +0 -43
- package/src/theme.ts +12 -162
- package/src/utils.js +6 -3
package/dist/constants.d.ts
CHANGED
|
@@ -65,19 +65,6 @@ export namespace DEFAULT_THEME_MAPPING {
|
|
|
65
65
|
let error: string;
|
|
66
66
|
let info: string;
|
|
67
67
|
}
|
|
68
|
-
export namespace TONE_MAP {
|
|
69
|
-
let z0: number;
|
|
70
|
-
let z1: number;
|
|
71
|
-
let z2: number;
|
|
72
|
-
let z3: number;
|
|
73
|
-
let z4: number;
|
|
74
|
-
let z5: number;
|
|
75
|
-
let z6: number;
|
|
76
|
-
let z7: number;
|
|
77
|
-
let z8: number;
|
|
78
|
-
let z9: number;
|
|
79
|
-
let z10: number;
|
|
80
|
-
}
|
|
81
68
|
export const INVERTED_ROLES: Set<string>;
|
|
82
69
|
export const DEFAULT_STATE_ICONS: any;
|
|
83
70
|
export { defaultColors, syntaxColors, shades, defaultPalette } from "./colors/index";
|
package/dist/named-tokens.d.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
export declare const NAMED_TOKENS: readonly ["paper", "paper-soft", "paper-mute", "paper-edge", "ink", "ink-mute", "ink-soft", "ink-faint", "primary", "on-primary", "accent", "accent-soft", "success", "success-soft", "warning", "warning-soft", "danger", "danger-soft", "error", "error-soft", "info", "info-soft", "focus-ring", "shadow-tint"];
|
|
6
6
|
export type NamedToken = (typeof NAMED_TOKENS)[number];
|
|
7
7
|
export type SkinRole = 'surface' | 'ink' | 'primary' | 'accent' | 'success' | 'warning' | 'danger' | 'error' | 'info';
|
|
8
|
-
export type ZSlot = 'z0' | 'z1' | 'z2' | 'z3' | 'z4' | 'z5' | 'z6' | 'z7' | 'z8' | 'z9' | 'z10';
|
|
9
|
-
export declare const Z_SLOTS: ZSlot[];
|
|
10
8
|
/**
|
|
11
9
|
* Maps each named token to the palette shade index that backs it.
|
|
12
10
|
* 'derived' indicates the token is computed (e.g., on-primary is the auto
|
|
@@ -32,19 +30,6 @@ export declare const NAMED_TOKEN_SHADE_MAP: Record<NamedToken, number | 'derived
|
|
|
32
30
|
* Maps each named token to the skin role whose palette it draws from.
|
|
33
31
|
*/
|
|
34
32
|
export declare const NAMED_TOKEN_ROLE_MAP: Record<NamedToken, SkinRole>;
|
|
35
|
-
/**
|
|
36
|
-
* Surface z-slot → named slot. Used to emit back-compat aliases like
|
|
37
|
-
* `--color-surface-z1: var(--paper-soft);` in core mode.
|
|
38
|
-
*
|
|
39
|
-
* z2/z3 collapse to paper-mute, z5/z6 to ink-soft, z7/z8 to ink-mute,
|
|
40
|
-
* z9/z10 to ink. This collapse is the contract: 4 surface tones in core mode.
|
|
41
|
-
*/
|
|
42
|
-
export declare const Z_COLLAPSE_MAP_SURFACE: Record<ZSlot, NamedToken>;
|
|
43
|
-
/**
|
|
44
|
-
* Ink role uses the inverted z-scale (z0 = darkest = primary text).
|
|
45
|
-
* In core mode, the same 4+4 named ladder is reused; this table just inverts.
|
|
46
|
-
*/
|
|
47
|
-
export declare const Z_COLLAPSE_MAP_INK: Record<ZSlot, NamedToken>;
|
|
48
33
|
/**
|
|
49
34
|
* Returns true when the role has a `-soft` companion in the named vocabulary.
|
|
50
35
|
* Used to decide whether the role's tinted-background slot collapses to
|
package/dist/theme.d.ts
CHANGED
|
@@ -29,12 +29,6 @@ export declare function themeRules(mapping: {
|
|
|
29
29
|
error: string;
|
|
30
30
|
info: string;
|
|
31
31
|
} | undefined, colors: any, colorSpace: any): {};
|
|
32
|
-
/**
|
|
33
|
-
* Generates UnoCSS shortcut definitions for semantic tones with bg, border, text.
|
|
34
|
-
* @param {string} name - Color name (e.g., 'primary')
|
|
35
|
-
* @returns {Array} Array of shortcut definitions
|
|
36
|
-
*/
|
|
37
|
-
export declare function semanticShortcuts(name: any): (string[] | (RegExp | (([, variant, end]: [any, any, any]) => string))[] | (RegExp | (([, end]: [any, any]) => string))[])[];
|
|
38
32
|
/**
|
|
39
33
|
* Generates "on-color" text shortcuts for readable text on colored backgrounds.
|
|
40
34
|
*
|
|
@@ -108,20 +102,8 @@ export declare class Theme {
|
|
|
108
102
|
* (and for the whole map when undefined).
|
|
109
103
|
*/
|
|
110
104
|
getNamedTokens(_mode?: string, perRoleModes?: Record<string, 'core' | 'extended'>): Record<string, string>;
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
* `--color-{role}-z{n}` → `var(--{namedSlot})`.
|
|
114
|
-
*
|
|
115
|
-
* - surface: uses Z_COLLAPSE_MAP_SURFACE (z2/z3 → paper-mute, z9/z10 → ink, etc.)
|
|
116
|
-
* - ink: uses Z_COLLAPSE_MAP_INK (inverted scale)
|
|
117
|
-
* - primary/accent/status: tint-vs-solid 2-state collapse.
|
|
118
|
-
* z0–z2 → role-soft (if it exists) else role; z3+ → role.
|
|
119
|
-
*
|
|
120
|
-
* This is the back-compat layer: existing `@apply bg-surface-z3` etc. resolves
|
|
121
|
-
* through these aliases until consumers migrate to the named vocabulary.
|
|
122
|
-
*/
|
|
123
|
-
/** Accepts SkinRole and any custom skin roles beyond the SkinRole literal union. */
|
|
124
|
-
getZAliasesForCore(role: string): Record<string, string>;
|
|
105
|
+
/** Bare `--color-{role}` alias backing preset-wind3 utilities (from-/to-/divide-) in core mode. */
|
|
106
|
+
getRoleBaseAlias(role: string): Record<string, string>;
|
|
125
107
|
/**
|
|
126
108
|
* Returns named tokens as CSS-var aliases pointing at the palette layer.
|
|
127
109
|
* Used in extended mode where the preset emits the full --color-{role}-{shade}
|
|
@@ -136,21 +118,5 @@ export declare class Theme {
|
|
|
136
118
|
* Mirrors what getPalette does for all roles, but scoped to one.
|
|
137
119
|
*/
|
|
138
120
|
getPaletteForRole(role: string): Record<string, string>;
|
|
139
|
-
|
|
140
|
-
* Emit z-aliases for one role in extended mode — they point at the palette vars,
|
|
141
|
-
* using TONE_MAP for surface/non-inverted roles and the inverted map for ink.
|
|
142
|
-
*/
|
|
143
|
-
getZAliasesForRoleExtended(role: string): Record<string, string>;
|
|
144
|
-
getShortcuts(name: any): (string[] | (RegExp | (([, variant, end]: [any, any, any]) => string))[] | (RegExp | (([, end]: [any, any]) => string))[])[];
|
|
145
|
-
/**
|
|
146
|
-
* Generates CSS custom property declarations for the semantic z0–z10 tone scale.
|
|
147
|
-
*
|
|
148
|
-
* Returns a CSS string with two blocks:
|
|
149
|
-
* - `:root` — light-mode aliases (z0=50 … z10=950)
|
|
150
|
-
* - `[data-mode="dark"]` — dark-mode aliases (z0=950 … z10=50)
|
|
151
|
-
*
|
|
152
|
-
* These let consumers write `var(--color-primary-z5)` instead of hardcoding
|
|
153
|
-
* numeric shades, and the value automatically adapts to the active mode.
|
|
154
|
-
*/
|
|
155
|
-
getZScaleCSS(): string;
|
|
121
|
+
getShortcuts(name: any): (RegExp | (([, end]: [any, any]) => string))[][];
|
|
156
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Contains core utility functions and classes that can be used in various components.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"ramda": "^0.32.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@rokkit/icons": "1.
|
|
49
|
+
"@rokkit/icons": "1.3.1"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/constants.js
CHANGED
|
@@ -183,20 +183,6 @@ export const DEFAULT_THEME_MAPPING = {
|
|
|
183
183
|
info: 'cyan'
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
export const TONE_MAP = {
|
|
187
|
-
z0: 50,
|
|
188
|
-
z1: 100,
|
|
189
|
-
z2: 200,
|
|
190
|
-
z3: 300,
|
|
191
|
-
z4: 400,
|
|
192
|
-
z5: 500,
|
|
193
|
-
z6: 600,
|
|
194
|
-
z7: 700,
|
|
195
|
-
z8: 800,
|
|
196
|
-
z9: 900,
|
|
197
|
-
z10: 950
|
|
198
|
-
}
|
|
199
|
-
|
|
200
186
|
export const INVERTED_ROLES = new Set(['ink'])
|
|
201
187
|
|
|
202
188
|
/**
|
package/src/named-tokens.ts
CHANGED
|
@@ -21,10 +21,6 @@ export type SkinRole =
|
|
|
21
21
|
| 'surface' | 'ink' | 'primary' | 'accent'
|
|
22
22
|
| 'success' | 'warning' | 'danger' | 'error' | 'info'
|
|
23
23
|
|
|
24
|
-
export type ZSlot = 'z0' | 'z1' | 'z2' | 'z3' | 'z4' | 'z5' | 'z6' | 'z7' | 'z8' | 'z9' | 'z10'
|
|
25
|
-
|
|
26
|
-
export const Z_SLOTS: ZSlot[] = ['z0', 'z1', 'z2', 'z3', 'z4', 'z5', 'z6', 'z7', 'z8', 'z9', 'z10']
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* Maps each named token to the palette shade index that backs it.
|
|
30
26
|
* 'derived' indicates the token is computed (e.g., on-primary is the auto
|
|
@@ -102,45 +98,6 @@ export const NAMED_TOKEN_ROLE_MAP: Record<NamedToken, SkinRole> = {
|
|
|
102
98
|
'shadow-tint': 'ink'
|
|
103
99
|
}
|
|
104
100
|
|
|
105
|
-
/**
|
|
106
|
-
* Surface z-slot → named slot. Used to emit back-compat aliases like
|
|
107
|
-
* `--color-surface-z1: var(--paper-soft);` in core mode.
|
|
108
|
-
*
|
|
109
|
-
* z2/z3 collapse to paper-mute, z5/z6 to ink-soft, z7/z8 to ink-mute,
|
|
110
|
-
* z9/z10 to ink. This collapse is the contract: 4 surface tones in core mode.
|
|
111
|
-
*/
|
|
112
|
-
export const Z_COLLAPSE_MAP_SURFACE: Record<ZSlot, NamedToken> = {
|
|
113
|
-
z0: 'paper',
|
|
114
|
-
z1: 'paper-soft',
|
|
115
|
-
z2: 'paper-mute',
|
|
116
|
-
z3: 'paper-mute',
|
|
117
|
-
z4: 'paper-edge',
|
|
118
|
-
z5: 'ink-soft',
|
|
119
|
-
z6: 'ink-soft',
|
|
120
|
-
z7: 'ink-mute',
|
|
121
|
-
z8: 'ink-mute',
|
|
122
|
-
z9: 'ink',
|
|
123
|
-
z10: 'ink'
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Ink role uses the inverted z-scale (z0 = darkest = primary text).
|
|
128
|
-
* In core mode, the same 4+4 named ladder is reused; this table just inverts.
|
|
129
|
-
*/
|
|
130
|
-
export const Z_COLLAPSE_MAP_INK: Record<ZSlot, NamedToken> = {
|
|
131
|
-
z0: 'ink',
|
|
132
|
-
z1: 'ink-mute',
|
|
133
|
-
z2: 'ink-mute',
|
|
134
|
-
z3: 'ink-soft',
|
|
135
|
-
z4: 'ink-soft',
|
|
136
|
-
z5: 'paper-edge',
|
|
137
|
-
z6: 'paper-edge',
|
|
138
|
-
z7: 'paper-mute',
|
|
139
|
-
z8: 'paper-mute',
|
|
140
|
-
z9: 'paper-soft',
|
|
141
|
-
z10: 'paper'
|
|
142
|
-
}
|
|
143
|
-
|
|
144
101
|
const SOFT_TOKENS: Set<string> = new Set(NAMED_TOKENS.filter((t) => t.endsWith('-soft')))
|
|
145
102
|
|
|
146
103
|
/**
|
package/src/theme.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
import { DEFAULT_THEME_MAPPING, defaultColors
|
|
3
|
+
import { DEFAULT_THEME_MAPPING, defaultColors } from './constants'
|
|
4
4
|
import { shades } from './colors/index'
|
|
5
5
|
import { ColorSpace, relativeLuminance } from './color-space'
|
|
6
6
|
import {
|
|
7
7
|
NAMED_TOKENS,
|
|
8
8
|
NAMED_TOKEN_SHADE_MAP,
|
|
9
|
-
NAMED_TOKEN_ROLE_MAP
|
|
10
|
-
Z_COLLAPSE_MAP_SURFACE,
|
|
11
|
-
Z_COLLAPSE_MAP_INK,
|
|
12
|
-
Z_SLOTS,
|
|
13
|
-
hasSoftCompanion
|
|
9
|
+
NAMED_TOKEN_ROLE_MAP
|
|
14
10
|
} from './named-tokens'
|
|
15
11
|
|
|
16
12
|
/**
|
|
@@ -72,64 +68,6 @@ export function themeRules(mapping = DEFAULT_THEME_MAPPING, colors = defaultColo
|
|
|
72
68
|
return rules
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
const SEMANTIC_PREFIXES = [
|
|
76
|
-
'bg',
|
|
77
|
-
'border',
|
|
78
|
-
'border-l',
|
|
79
|
-
'border-r',
|
|
80
|
-
'border-t',
|
|
81
|
-
'border-b',
|
|
82
|
-
'text',
|
|
83
|
-
'ring',
|
|
84
|
-
'outline',
|
|
85
|
-
'from',
|
|
86
|
-
'to',
|
|
87
|
-
'divide',
|
|
88
|
-
'stroke',
|
|
89
|
-
'fill'
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @param {{ prefix: string, name: string, toneName: string, lightValue: number, darkValue: number }} opts
|
|
94
|
-
* @returns {Array}
|
|
95
|
-
*/
|
|
96
|
-
function toneShortcuts({ prefix, name, toneName, lightValue, darkValue }) {
|
|
97
|
-
const variantPattern = new RegExp(`^(.+):${prefix}-${name}-${toneName}(\\/\\d+)?$`)
|
|
98
|
-
const opacityPattern = new RegExp(`^${prefix}-${name}-${toneName}(\\/\\d+)?$`)
|
|
99
|
-
const exactPattern = `${prefix}-${name}-${toneName}`
|
|
100
|
-
return [
|
|
101
|
-
[
|
|
102
|
-
variantPattern,
|
|
103
|
-
([, variant, end]) =>
|
|
104
|
-
`${variant}:${prefix}-${name}-${lightValue}${end || ''} ${variant}:dark:${prefix}-${name}-${darkValue}${end || ''}`
|
|
105
|
-
],
|
|
106
|
-
[
|
|
107
|
-
opacityPattern,
|
|
108
|
-
([, end]) =>
|
|
109
|
-
`${prefix}-${name}-${lightValue}${end || ''} dark:${prefix}-${name}-${darkValue}${end || ''}`
|
|
110
|
-
],
|
|
111
|
-
[exactPattern, `${prefix}-${name}-${lightValue} dark:${prefix}-${name}-${darkValue}`]
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Generates UnoCSS shortcut definitions for semantic tones with bg, border, text.
|
|
117
|
-
* @param {string} name - Color name (e.g., 'primary')
|
|
118
|
-
* @returns {Array} Array of shortcut definitions
|
|
119
|
-
*/
|
|
120
|
-
export function semanticShortcuts(name) {
|
|
121
|
-
const inverted = INVERTED_ROLES.has(name)
|
|
122
|
-
const shortcuts = []
|
|
123
|
-
for (const [toneName, toneValue] of Object.entries(TONE_MAP)) {
|
|
124
|
-
const lightValue = inverted ? 1000 - toneValue : toneValue
|
|
125
|
-
const darkValue = inverted ? toneValue : 1000 - toneValue
|
|
126
|
-
for (const prefix of SEMANTIC_PREFIXES) {
|
|
127
|
-
shortcuts.push(...toneShortcuts({ prefix, name, toneName, lightValue, darkValue }))
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return shortcuts
|
|
131
|
-
}
|
|
132
|
-
|
|
133
71
|
/**
|
|
134
72
|
* Generates "on-color" text shortcuts for readable text on colored backgrounds.
|
|
135
73
|
*
|
|
@@ -332,6 +270,7 @@ export class Theme {
|
|
|
332
270
|
if (name === 'on-primary') {
|
|
333
271
|
return this.#adapter.wrap(this.#onColorHex('primary', colors))
|
|
334
272
|
}
|
|
273
|
+
/* v8 ignore next -- on-primary is the only 'derived' token, so this default is unreachable */
|
|
335
274
|
return undefined
|
|
336
275
|
}
|
|
337
276
|
|
|
@@ -349,63 +288,18 @@ export class Theme {
|
|
|
349
288
|
return y >= ON_COLOR_Y_CROSSOVER ? ON_COLOR_DARK : ON_COLOR_LIGHT
|
|
350
289
|
}
|
|
351
290
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
*/
|
|
355
|
-
#getZAliasesFromMap(role: 'surface' | 'ink', map: Record<ZSlot, NamedToken>): Record<string, string> {
|
|
356
|
-
const result: Record<string, string> = {}
|
|
357
|
-
// Bare `--color-{role}` alias — points at the role's primary named
|
|
358
|
-
// slot. Lets preset-wind3 color utilities (bg-surface, from-surface,
|
|
359
|
-
// to-surface, etc.) resolve in core mode without forcing the full
|
|
360
|
-
// palette emit. Surface → paper, Ink → ink.
|
|
361
|
-
result[`--color-${role}`] = role === 'surface' ? 'var(--paper)' : 'var(--ink)'
|
|
362
|
-
for (const z of Z_SLOTS) {
|
|
363
|
-
result[`--color-${role}-${z}`] = `var(--${map[z]})`
|
|
364
|
-
}
|
|
365
|
-
return result
|
|
291
|
+
#surfaceInkAlias(role: 'surface' | 'ink'): Record<string, string> {
|
|
292
|
+
return { [`--color-${role}`]: role === 'surface' ? 'var(--paper)' : 'var(--ink)' }
|
|
366
293
|
}
|
|
367
294
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
*/
|
|
371
|
-
#getZAliasesOther(role: string): Record<string, string> {
|
|
372
|
-
const result: Record<string, string> = {}
|
|
373
|
-
const hasSoft = hasSoftCompanion(role)
|
|
374
|
-
const softTarget = hasSoft ? `${role}-soft` : role
|
|
375
|
-
// Bare `--color-{role}` alias points at the named token so
|
|
376
|
-
// preset-wind3 color utilities (from-{role}, to-{role}, divide-{role},
|
|
377
|
-
// etc.) resolve in core mode — they read `--color-{role}` and we'd
|
|
378
|
-
// otherwise leave it undefined since core mode skips the palette emit.
|
|
379
|
-
result[`--color-${role}`] = `var(--${role})`
|
|
380
|
-
for (const z of Z_SLOTS) {
|
|
381
|
-
const zNum = parseInt(z.slice(1), 10)
|
|
382
|
-
const target = zNum <= 2 ? softTarget : role
|
|
383
|
-
result[`--color-${role}-${z}`] = `var(--${target})`
|
|
384
|
-
}
|
|
385
|
-
return result
|
|
295
|
+
#otherRoleAlias(role: string): Record<string, string> {
|
|
296
|
+
return { [`--color-${role}`]: `var(--${role})` }
|
|
386
297
|
}
|
|
387
298
|
|
|
388
|
-
/**
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
* - surface: uses Z_COLLAPSE_MAP_SURFACE (z2/z3 → paper-mute, z9/z10 → ink, etc.)
|
|
393
|
-
* - ink: uses Z_COLLAPSE_MAP_INK (inverted scale)
|
|
394
|
-
* - primary/accent/status: tint-vs-solid 2-state collapse.
|
|
395
|
-
* z0–z2 → role-soft (if it exists) else role; z3+ → role.
|
|
396
|
-
*
|
|
397
|
-
* This is the back-compat layer: existing `@apply bg-surface-z3` etc. resolves
|
|
398
|
-
* through these aliases until consumers migrate to the named vocabulary.
|
|
399
|
-
*/
|
|
400
|
-
/** Accepts SkinRole and any custom skin roles beyond the SkinRole literal union. */
|
|
401
|
-
getZAliasesForCore(role: string): Record<string, string> {
|
|
402
|
-
if (role === 'surface') {
|
|
403
|
-
return this.#getZAliasesFromMap('surface', Z_COLLAPSE_MAP_SURFACE)
|
|
404
|
-
}
|
|
405
|
-
if (role === 'ink') {
|
|
406
|
-
return this.#getZAliasesFromMap('ink', Z_COLLAPSE_MAP_INK)
|
|
407
|
-
}
|
|
408
|
-
return this.#getZAliasesOther(role)
|
|
299
|
+
/** Bare `--color-{role}` alias backing preset-wind3 utilities (from-/to-/divide-) in core mode. */
|
|
300
|
+
getRoleBaseAlias(role: string): Record<string, string> {
|
|
301
|
+
if (role === 'surface' || role === 'ink') return this.#surfaceInkAlias(role)
|
|
302
|
+
return this.#otherRoleAlias(role)
|
|
409
303
|
}
|
|
410
304
|
|
|
411
305
|
/**
|
|
@@ -450,53 +344,9 @@ export class Theme {
|
|
|
450
344
|
return result
|
|
451
345
|
}
|
|
452
346
|
|
|
453
|
-
/**
|
|
454
|
-
* Emit z-aliases for one role in extended mode — they point at the palette vars,
|
|
455
|
-
* using TONE_MAP for surface/non-inverted roles and the inverted map for ink.
|
|
456
|
-
*/
|
|
457
|
-
getZAliasesForRoleExtended(role: string): Record<string, string> {
|
|
458
|
-
const result: Record<string, string> = {}
|
|
459
|
-
const isInverted = INVERTED_ROLES.has(role)
|
|
460
|
-
for (const [zone, light] of Object.entries(TONE_MAP)) {
|
|
461
|
-
const shade = isInverted ? 1000 - light : light
|
|
462
|
-
result[`--color-${role}-${zone}`] = `var(--color-${role}-${shade})`
|
|
463
|
-
}
|
|
464
|
-
return result
|
|
465
|
-
}
|
|
466
|
-
|
|
467
347
|
getShortcuts(name) {
|
|
468
348
|
const colors = { ...defaultColors, ...this.#colors }
|
|
469
|
-
return
|
|
349
|
+
return contrastShortcuts(name, this.#onColorHex(name, colors))
|
|
470
350
|
}
|
|
471
351
|
|
|
472
|
-
/**
|
|
473
|
-
* Generates CSS custom property declarations for the semantic z0–z10 tone scale.
|
|
474
|
-
*
|
|
475
|
-
* Returns a CSS string with two blocks:
|
|
476
|
-
* - `:root` — light-mode aliases (z0=50 … z10=950)
|
|
477
|
-
* - `[data-mode="dark"]` — dark-mode aliases (z0=950 … z10=50)
|
|
478
|
-
*
|
|
479
|
-
* These let consumers write `var(--color-primary-z5)` instead of hardcoding
|
|
480
|
-
* numeric shades, and the value automatically adapts to the active mode.
|
|
481
|
-
*/
|
|
482
|
-
getZScaleCSS() {
|
|
483
|
-
const names = Object.keys(this.#mapping)
|
|
484
|
-
|
|
485
|
-
const lightLines = names.flatMap((name) =>
|
|
486
|
-
Object.entries(TONE_MAP).map(([zone, light]) => {
|
|
487
|
-
const value = INVERTED_ROLES.has(name) ? 1000 - light : light
|
|
488
|
-
return ` --color-${name}-${zone}: var(--color-${name}-${value});`
|
|
489
|
-
})
|
|
490
|
-
)
|
|
491
|
-
|
|
492
|
-
const darkLines = names.flatMap((name) =>
|
|
493
|
-
Object.entries(TONE_MAP).map(([zone, light]) => {
|
|
494
|
-
const dark = 1000 - light
|
|
495
|
-
const value = INVERTED_ROLES.has(name) ? light : dark
|
|
496
|
-
return ` --color-${name}-${zone}: var(--color-${name}-${value});`
|
|
497
|
-
})
|
|
498
|
-
)
|
|
499
|
-
|
|
500
|
-
return `:root {\n${lightLines.join('\n')}\n}\n[data-mode="dark"] {\n${darkLines.join('\n')}\n}`
|
|
501
|
-
}
|
|
502
352
|
}
|
package/src/utils.js
CHANGED
|
@@ -172,12 +172,13 @@ export function getSnippet(obj, key, defaultSnippet = null) {
|
|
|
172
172
|
/**
|
|
173
173
|
* Resolve which snippet to render for a proxy item.
|
|
174
174
|
*
|
|
175
|
-
*
|
|
175
|
+
* Reads the proxy's `snippet` field (via proxy.get('snippet'), honoring fields.snippet)
|
|
176
|
+
* for a per-item named override first (e.g. item.snippet = 'highlighted').
|
|
176
177
|
* Falls back to the component-level fallback snippet name (e.g. 'itemContent' / 'groupContent').
|
|
177
178
|
* Returns null if neither is found.
|
|
178
179
|
*
|
|
179
180
|
* @param {Record<string, unknown>} snippets - snippets passed to the component
|
|
180
|
-
* @param {{
|
|
181
|
+
* @param {{ get: (key: string) => unknown }} proxy - a ProxyItem; its snippet field is read via proxy.get('snippet')
|
|
181
182
|
* @param {string} [fallback] - fallback snippet name; defaults to ITEM_SNIPPET ('itemContent')
|
|
182
183
|
* @returns {Function | null}
|
|
183
184
|
*/
|
|
@@ -190,7 +191,9 @@ function asSnippet(value) {
|
|
|
190
191
|
}
|
|
191
192
|
|
|
192
193
|
export function resolveSnippet(snippets, proxy, fallback = ITEM_SNIPPET) {
|
|
193
|
-
|
|
194
|
+
// `snippet` is a field-mapped prop like icon/href — read it via the proxy's
|
|
195
|
+
// field accessor (honors fields.snippet), not as a direct property.
|
|
196
|
+
const name = proxy?.get('snippet')
|
|
194
197
|
return asSnippet(name && snippets[name]) || asSnippet(snippets[fallback])
|
|
195
198
|
}
|
|
196
199
|
|