@adea-ai/themes 0.9.9 → 0.10.0
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/accents.d.ts +95 -11
- package/dist/accents.d.ts.map +1 -1
- package/dist/accents.js +179 -9
- package/dist/accents.js.map +1 -1
- package/dist/adapters/shadcn.d.ts +4 -2
- package/dist/adapters/shadcn.d.ts.map +1 -1
- package/dist/adapters/shadcn.js +14 -5
- package/dist/adapters/shadcn.js.map +1 -1
- package/dist/generated/themes/ayu-light.js +2 -2
- package/dist/generated/themes/one-dark.js +2 -2
- package/dist/generated/themes/rosepine-dawn.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/normalize.d.ts +2 -65
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.js +73 -74
- package/dist/normalize.js.map +1 -1
- package/dist/policy.d.ts +76 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +81 -0
- package/dist/policy.js.map +1 -0
- package/dist/validate.d.ts +5 -4
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +9 -4
- package/dist/validate.js.map +1 -1
- package/package.json +1 -1
- package/src/accents.ts +220 -16
- package/src/adapters/shadcn.ts +40 -27
- package/src/generated/themes/ayu-light.ts +2 -2
- package/src/generated/themes/one-dark.ts +2 -2
- package/src/generated/themes/rosepine-dawn.ts +1 -1
- package/src/index.ts +3 -0
- package/src/normalize.ts +103 -77
- package/src/policy.ts +86 -0
- package/src/validate.ts +9 -4
package/dist/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;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
|
* A uniform step needs a resolved value, which is why {@link primaryHover} returns
|
|
43
43
|
* one and why the tint below can stay an expression. `shiftLightness` is what keeps
|
|
44
44
|
* the step uniform *and* the hue intact — a mix toward a neutral cannot do both.
|
|
45
|
+
*
|
|
46
|
+
* ## The tint rule
|
|
47
|
+
*
|
|
48
|
+
* The tint is the selected state across the component library — `bg-primary-subtle
|
|
49
|
+
* text-foreground` on an active nav row, a pressed toggle, the highlighted command
|
|
50
|
+
* row, a selected tab — so body text on it is held to the body floor, on every
|
|
51
|
+
* surface body text is held to it on, for every accent the theme offers.
|
|
52
|
+
*
|
|
53
|
+
* It stays a translucent `color-mix()` rather than becoming an opaque value, and
|
|
54
|
+
* that is a measured choice rather than a habit. An opaque tint mixed into the
|
|
55
|
+
* canvas is legible everywhere by construction — the status `-subtle` fills work
|
|
56
|
+
* that way — but it is a wash *of the canvas*: on a dark theme's popover, which is
|
|
57
|
+
* already lighter than the canvas, a selected command row resolved that way lands
|
|
58
|
+
* within ΔE 0.01 of the popover and disappears. A translucent tint is a wash of
|
|
59
|
+
* whatever it sits on, so it reads as selected on every rung.
|
|
60
|
+
*
|
|
61
|
+
* What moves instead is the **strength**, per theme. {@link ACCENT_SUBTLE_ALPHA} is
|
|
62
|
+
* the ceiling, and {@link primarySubtleAlpha} lowers it — only as far as a theme
|
|
63
|
+
* needs — until the composite clears the floor everywhere. The palettes whose body
|
|
64
|
+
* text sits closest to the floor get a lighter wash, and the colour, the
|
|
65
|
+
* foreground and the surfaces stay exactly as their authors wrote them.
|
|
45
66
|
*/
|
|
46
67
|
|
|
47
|
-
import type { AdeaTheme, AnsiKey, ThemeAppearance } from './schema.js'
|
|
68
|
+
import type { AdeaTheme, AnsiKey, ShadcnThemeProjection, ThemeAppearance } from './schema.js'
|
|
48
69
|
import type { Oklch } from './oklch.js'
|
|
49
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
contrastRatio,
|
|
72
|
+
formatOklch,
|
|
73
|
+
hexToOklch,
|
|
74
|
+
oklchToHex,
|
|
75
|
+
parseColor,
|
|
76
|
+
shiftLightness,
|
|
77
|
+
} from './oklch.js'
|
|
50
78
|
import {
|
|
51
79
|
ACCENT_PREFERENCE,
|
|
52
80
|
CONTRAST_FLOORS,
|
|
53
81
|
MINIMUM_ACCENT_CHROMA,
|
|
54
82
|
REPAIR_BUDGET,
|
|
55
|
-
} from './
|
|
83
|
+
} from './policy.js'
|
|
56
84
|
|
|
57
85
|
/** One accent preset: a named primary, per appearance. */
|
|
58
86
|
export type AccentPreset = {
|
|
@@ -195,12 +223,16 @@ export function primaryHover(primary: string, appearance: ThemeAppearance): stri
|
|
|
195
223
|
}
|
|
196
224
|
|
|
197
225
|
/**
|
|
198
|
-
* How much of the primary a tint carries, per appearance.
|
|
226
|
+
* How much of the primary a tint carries at most, per appearance.
|
|
199
227
|
*
|
|
200
228
|
* Not one value, because a tint's visibility depends on what it is tinted onto: the
|
|
201
229
|
* same alpha over a near-black surface reads as nothing, and over a near-white one
|
|
202
230
|
* reads as a wash. The dark value is the larger for exactly that reason.
|
|
203
231
|
*
|
|
232
|
+
* A **ceiling**, not the value every theme gets: {@link primarySubtleAlpha} lowers
|
|
233
|
+
* it for a theme whose body text cannot hold the floor on a tint this strong. Most
|
|
234
|
+
* themes keep it.
|
|
235
|
+
*
|
|
204
236
|
* This one *is* a `color-mix()`, because a tint is a share of the primary by nature
|
|
205
237
|
* and follows `--primary` correctly at runtime.
|
|
206
238
|
*/
|
|
@@ -209,17 +241,180 @@ export const ACCENT_SUBTLE_ALPHA: Readonly<Record<ThemeAppearance, number>> = Ob
|
|
|
209
241
|
dark: 16,
|
|
210
242
|
})
|
|
211
243
|
|
|
244
|
+
/** A theme, with the presentation surfaces the shadcn bridge may substitute. */
|
|
245
|
+
type TintedTheme = Pick<AdeaTheme, 'appearance' | 'colors' | 'ansi'> & {
|
|
246
|
+
shadcn?: ShadcnThemeProjection
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The weakest tint the catalogue will ship, as a whole percentage.
|
|
251
|
+
*
|
|
252
|
+
* {@link primarySubtleAlpha} lowers a theme's strength for legibility, and this is
|
|
253
|
+
* how far it may go: below it the selected state stops reading as a state at all.
|
|
254
|
+
* The normalizer reserves it — it fits a theme's hover rung so body text still
|
|
255
|
+
* clears the floor under a tint this strong — so every theme in the catalogue can
|
|
256
|
+
* carry at least this much. At 4% the tint over One Dark's popover measures ΔE 0.018
|
|
257
|
+
* against the popover, about the same as its hover rung's feedback there.
|
|
258
|
+
*/
|
|
259
|
+
export const ACCENT_SUBTLE_MINIMUM_ALPHA = 4
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Every surface the tint is guaranteed on: every surface body text is guaranteed
|
|
263
|
+
* on.
|
|
264
|
+
*
|
|
265
|
+
* The canvas, the two raised rungs and the hover rung, plus whatever a source
|
|
266
|
+
* substitutes for them in the shadcn bridge — `--card`, `--popover`, `--muted` and
|
|
267
|
+
* `--secondary`; `--sidebar` is the first rung and `--accent` the hover rung. The
|
|
268
|
+
* hover rung is here because a selected item that is also hovered paints the tint
|
|
269
|
+
* over it in some components. The active rung is not: it is the pressed state of an
|
|
270
|
+
* item, not a surface an item sits on.
|
|
271
|
+
*/
|
|
272
|
+
function tintSurfaces(theme: TintedTheme): string[] {
|
|
273
|
+
const shadcn = theme.shadcn ?? {}
|
|
274
|
+
return [
|
|
275
|
+
...new Set([
|
|
276
|
+
theme.colors.background,
|
|
277
|
+
theme.colors.surface,
|
|
278
|
+
theme.colors.surfaceElevated,
|
|
279
|
+
theme.colors.surfaceHover,
|
|
280
|
+
...[shadcn.card, shadcn.popover, shadcn.muted, shadcn.secondary].filter(
|
|
281
|
+
(value): value is string => value !== undefined
|
|
282
|
+
),
|
|
283
|
+
]),
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* The primaries a theme offers: its own accent, the {@link ACCENTS} presets in its
|
|
289
|
+
* appearance, and every palette slot {@link themeAccentPresets} could offer from it
|
|
290
|
+
* whatever theme it is paired with.
|
|
291
|
+
*/
|
|
292
|
+
function offeredPrimaries(theme: TintedTheme): string[] {
|
|
293
|
+
const slots = ACCENT_PREFERENCE.map((slot) => offeredSlotValue(theme, slot)).filter(
|
|
294
|
+
(value): value is string => value !== undefined
|
|
295
|
+
)
|
|
296
|
+
return [
|
|
297
|
+
...new Set([
|
|
298
|
+
theme.colors.accent,
|
|
299
|
+
...ACCENTS.map((preset) => accentValue(preset, theme.appearance)),
|
|
300
|
+
...slots,
|
|
301
|
+
]),
|
|
302
|
+
]
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** A colour as the screen draws it: through eight-bit sRGB. */
|
|
306
|
+
function rendered(value: string): Oklch | undefined {
|
|
307
|
+
const parsed = parseColor(value)
|
|
308
|
+
return parsed ? hexToOklch(oklchToHex(parsed)) : undefined
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* A translucent fill painted over an opaque one, the way a browser paints
|
|
313
|
+
* `color-mix(in oklch, <tint> N%, transparent)`: the mix keeps the tint's colour and
|
|
314
|
+
* takes the share as alpha, and the alpha is composited in gamma-encoded sRGB.
|
|
315
|
+
* Rounded to the eight-bit value that reaches the screen, which is the colour an
|
|
316
|
+
* accessibility audit samples.
|
|
317
|
+
*/
|
|
318
|
+
function compositeTint(tint: string, surface: string, alpha: number): Oklch | undefined {
|
|
319
|
+
const tintColor = parseColor(tint)
|
|
320
|
+
const surfaceColor = parseColor(surface)
|
|
321
|
+
if (!tintColor || !surfaceColor) return undefined
|
|
322
|
+
const front = oklchToHex(tintColor)
|
|
323
|
+
const back = oklchToHex(surfaceColor)
|
|
324
|
+
const channels = [1, 3, 5].map((offset) => {
|
|
325
|
+
const top = Number.parseInt(front.slice(offset, offset + 2), 16)
|
|
326
|
+
const bottom = Number.parseInt(back.slice(offset, offset + 2), 16)
|
|
327
|
+
return Math.round(top * alpha + bottom * (1 - alpha))
|
|
328
|
+
.toString(16)
|
|
329
|
+
.padStart(2, '0')
|
|
330
|
+
})
|
|
331
|
+
return hexToOklch(`#${channels.join('')}`)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Whether body text holds the floor on a surface under the primary tint.
|
|
336
|
+
*
|
|
337
|
+
* True when `text` and `foreground` both clear `CONTRAST_FLOORS.text` on the tint
|
|
338
|
+
* at `alpha` percent composited over `surface`, for every primary the theme offers
|
|
339
|
+
* and every one in `primaries`. At `alpha` 0 it is the bare surface. The
|
|
340
|
+
* normalizer calls this to fit the hover rung, and {@link primarySubtleAlpha} to
|
|
341
|
+
* fit the strength, so the two are measured by one rule.
|
|
342
|
+
*/
|
|
343
|
+
export function primaryTintClears(
|
|
344
|
+
theme: TintedTheme,
|
|
345
|
+
surface: string,
|
|
346
|
+
alpha: number,
|
|
347
|
+
primaries: readonly string[] = []
|
|
348
|
+
): boolean {
|
|
349
|
+
const foregrounds = [...new Set([theme.colors.text, theme.colors.foreground])].map(rendered)
|
|
350
|
+
if (foregrounds.some((value) => value === undefined)) return false
|
|
351
|
+
const tints = alpha === 0 ? [surface] : [...new Set([...offeredPrimaries(theme), ...primaries])]
|
|
352
|
+
return tints.every((tint) => {
|
|
353
|
+
const fill = compositeTint(tint, surface, alpha / 100)
|
|
354
|
+
return (
|
|
355
|
+
fill !== undefined &&
|
|
356
|
+
foregrounds.every((foreground) => contrastRatio(foreground!, fill) >= CONTRAST_FLOORS.text)
|
|
357
|
+
)
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const subtleAlphaCache = new WeakMap<object, number>()
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The tint strength a theme can carry, as a whole percentage.
|
|
365
|
+
*
|
|
366
|
+
* The appearance's {@link ACCENT_SUBTLE_ALPHA} ceiling, lowered one point at a time
|
|
367
|
+
* until body text clears `CONTRAST_FLOORS.text` on the tint over every floored
|
|
368
|
+
* surface, hover rung included, for every primary the theme offers. One value per
|
|
369
|
+
* theme rather than one per accent, so switching between offered accents at runtime
|
|
370
|
+
* needs no new tint: the expression follows `--primary` and the strength already
|
|
371
|
+
* holds for all of them. Every catalogue theme lands at or above
|
|
372
|
+
* {@link ACCENT_SUBTLE_MINIMUM_ALPHA}, because the normalizer fits its hover rung to
|
|
373
|
+
* leave room for it.
|
|
374
|
+
*
|
|
375
|
+
* Pass `primaries` to hold the strength for colours outside the offered set too —
|
|
376
|
+
* a product's own brand primary, say. The offered set is always included.
|
|
377
|
+
*/
|
|
378
|
+
export function primarySubtleAlpha(theme: TintedTheme, primaries: readonly string[] = []): number {
|
|
379
|
+
const cached = primaries.length === 0 ? subtleAlphaCache.get(theme) : undefined
|
|
380
|
+
if (cached !== undefined) return cached
|
|
381
|
+
|
|
382
|
+
const surfaces = tintSurfaces(theme)
|
|
383
|
+
const clears = (alpha: number): boolean =>
|
|
384
|
+
surfaces.every((surface) => primaryTintClears(theme, surface, alpha, primaries))
|
|
385
|
+
|
|
386
|
+
let alpha = ACCENT_SUBTLE_ALPHA[theme.appearance]
|
|
387
|
+
while (alpha > 0 && !clears(alpha)) alpha -= 1
|
|
388
|
+
|
|
389
|
+
if (primaries.length === 0) subtleAlphaCache.set(theme, alpha)
|
|
390
|
+
return alpha
|
|
391
|
+
}
|
|
392
|
+
|
|
212
393
|
/**
|
|
213
394
|
* The tint expression, for any primary.
|
|
214
395
|
*
|
|
215
|
-
*
|
|
216
|
-
* {@link
|
|
396
|
+
* Pass the **theme**: the expression then carries that theme's measured strength
|
|
397
|
+
* ({@link primarySubtleAlpha}) and body text on it is held to the floor for every
|
|
398
|
+
* accent the theme offers. It still reads `var(--primary)`, so it follows a runtime
|
|
399
|
+
* accent switch — but the strength is the theme's, so a consumer that applies
|
|
400
|
+
* themes at runtime has to write this token per theme, as it already does for
|
|
401
|
+
* {@link primaryHover}. A consumer whose primary is not one the theme offers passes
|
|
402
|
+
* it as `primaries` to have the strength measured for it as well.
|
|
403
|
+
*
|
|
404
|
+
* Passing only an **appearance** gives the {@link ACCENT_SUBTLE_ALPHA} ceiling for
|
|
405
|
+
* that appearance, unmeasured. That is the old behaviour and it is not legible on
|
|
406
|
+
* every theme — One Dark's body text on its own primary's tint over a card measures
|
|
407
|
+
* 4.34:1 at the dark ceiling — so it is kept for a consumer without a theme object
|
|
408
|
+
* in hand, not as the default to reach for.
|
|
217
409
|
*/
|
|
218
410
|
export function primarySubtleCss(
|
|
219
|
-
|
|
220
|
-
primaryVariable = '--primary'
|
|
411
|
+
target: ThemeAppearance | TintedTheme,
|
|
412
|
+
primaryVariable = '--primary',
|
|
413
|
+
primaries: readonly string[] = []
|
|
221
414
|
): string {
|
|
222
|
-
|
|
415
|
+
const alpha =
|
|
416
|
+
typeof target === 'string' ? ACCENT_SUBTLE_ALPHA[target] : primarySubtleAlpha(target, primaries)
|
|
417
|
+
return `color-mix(in oklch, var(${primaryVariable}) ${alpha}%, transparent)`
|
|
223
418
|
}
|
|
224
419
|
|
|
225
420
|
/**
|
|
@@ -256,7 +451,10 @@ const REPAIR_STEP = 0.002
|
|
|
256
451
|
* with a legible label. `undefined` when even the budget cannot get there, which
|
|
257
452
|
* is the one case where the theme honestly cannot offer the slot.
|
|
258
453
|
*/
|
|
259
|
-
function offeredSlotValue(
|
|
454
|
+
function offeredSlotValue(
|
|
455
|
+
theme: Pick<AdeaTheme, 'colors' | 'ansi'>,
|
|
456
|
+
slot: ThemeAccentSlot
|
|
457
|
+
): string | undefined {
|
|
260
458
|
const original = theme.ansi[slot as AnsiKey]
|
|
261
459
|
const value = parseColor(original)
|
|
262
460
|
const background = parseColor(theme.colors.background)
|
|
@@ -311,10 +509,10 @@ export function themeAccentPresets(light: AdeaTheme, dark: AdeaTheme): AccentPre
|
|
|
311
509
|
/**
|
|
312
510
|
* The five declarations an accent sets, as CSS values.
|
|
313
511
|
*
|
|
314
|
-
* `primary`, `primaryForeground` and `ring` are resolved colours;
|
|
315
|
-
* `primarySubtle`
|
|
316
|
-
* writes them as custom properties and the rules hold for every theme and
|
|
317
|
-
* accent at once.
|
|
512
|
+
* `primary`, `primaryForeground`, `primaryHover` and `ring` are resolved colours;
|
|
513
|
+
* `primarySubtle` is an expression, for the reason in the module comment. A
|
|
514
|
+
* consumer writes them as custom properties and the rules hold for every theme and
|
|
515
|
+
* every accent at once.
|
|
318
516
|
*/
|
|
319
517
|
export type AccentRoles = {
|
|
320
518
|
primary: string
|
|
@@ -326,10 +524,16 @@ export type AccentRoles = {
|
|
|
326
524
|
|
|
327
525
|
export function accentRoles(
|
|
328
526
|
preset: AccentPreset,
|
|
329
|
-
|
|
527
|
+
/**
|
|
528
|
+
* The theme the accent is applied to, or only its appearance. A theme gives the
|
|
529
|
+
* tint that theme's measured strength — see {@link primarySubtleCss}; an
|
|
530
|
+
* appearance gives the unmeasured ceiling.
|
|
531
|
+
*/
|
|
532
|
+
target: ThemeAppearance | TintedTheme,
|
|
330
533
|
/** The property the subtle tint is built from. A consumer may pass its own alias. */
|
|
331
534
|
primaryVariable = '--primary'
|
|
332
535
|
): AccentRoles {
|
|
536
|
+
const appearance = typeof target === 'string' ? target : target.appearance
|
|
333
537
|
const value = accentValue(preset, appearance)
|
|
334
538
|
const parsed = parseColor(value)
|
|
335
539
|
const primary = parsed ? formatOklch(parsed) : value
|
|
@@ -338,7 +542,7 @@ export function accentRoles(
|
|
|
338
542
|
primary,
|
|
339
543
|
primaryForeground: accentForeground(value),
|
|
340
544
|
primaryHover: primaryHover(value, appearance),
|
|
341
|
-
primarySubtle: primarySubtleCss(
|
|
545
|
+
primarySubtle: primarySubtleCss(target, primaryVariable),
|
|
342
546
|
ring: primary,
|
|
343
547
|
}
|
|
344
548
|
}
|
package/src/adapters/shadcn.ts
CHANGED
|
@@ -144,31 +144,39 @@ export function shadcnDestructiveProjection(theme: ShadcnTheme): ShadcnDestructi
|
|
|
144
144
|
* Canonical role → shadcn custom-property name.
|
|
145
145
|
*
|
|
146
146
|
* Every entry is a deliberate correspondence, and the ones that are not a plain
|
|
147
|
-
* rename carry the reason here rather than in the output.
|
|
147
|
+
* rename carry the reason here rather than in the output. A `null` destination
|
|
148
|
+
* is a deliberate "not emitted": the role has no shadcn consumer, and the
|
|
149
|
+
* compiler still refuses a new role until it makes that choice.
|
|
148
150
|
*/
|
|
149
|
-
export const SHADCN_MAPPING: Readonly<Record<keyof AdeaThemeColors, string>> = Object.freeze(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
151
|
+
export const SHADCN_MAPPING: Readonly<Record<keyof AdeaThemeColors, string | null>> = Object.freeze(
|
|
152
|
+
{
|
|
153
|
+
background: 'background',
|
|
154
|
+
foreground: 'foreground',
|
|
155
|
+
// The first two rungs are the two surfaces shadcn names.
|
|
156
|
+
surface: 'card',
|
|
157
|
+
surfaceElevated: 'popover',
|
|
158
|
+
surfaceHover: 'surface-hover',
|
|
159
|
+
surfaceActive: 'surface-active',
|
|
160
|
+
border: 'border',
|
|
161
|
+
// Nothing reads `--border-muted`. A consumer that wants the quieter rule
|
|
162
|
+
// reads the record's `borderMuted` or the CSS adapter's `--adea-border-muted`.
|
|
163
|
+
borderMuted: null,
|
|
164
|
+
// `text` is `foreground` in shadcn; `--foreground` is what body text reads.
|
|
165
|
+
text: 'foreground',
|
|
166
|
+
textMuted: 'muted-foreground',
|
|
167
|
+
// shadcn has no tertiary text slot and nothing reads `--subtle-foreground`;
|
|
168
|
+
// `textSubtle` stays a canonical role (the shiki adapter's indent guides).
|
|
169
|
+
textSubtle: null,
|
|
170
|
+
// See the header: the interactive colour is shadcn's `primary`.
|
|
171
|
+
accent: 'primary',
|
|
172
|
+
accentForeground: 'primary-foreground',
|
|
173
|
+
success: 'success',
|
|
174
|
+
warning: 'warning',
|
|
175
|
+
// shadcn's destructive slot is in the same position as Adea's error.
|
|
176
|
+
error: 'destructive',
|
|
177
|
+
info: 'info',
|
|
178
|
+
}
|
|
179
|
+
)
|
|
172
180
|
|
|
173
181
|
/**
|
|
174
182
|
* The shadcn roles as an object, keyed by role name without the `--` prefix.
|
|
@@ -195,15 +203,20 @@ export function shadcnVariables(theme: ShadcnTheme): Record<string, string> {
|
|
|
195
203
|
const variables: Record<string, string> = {}
|
|
196
204
|
const destructive = shadcnDestructiveProjection(theme)
|
|
197
205
|
|
|
198
|
-
for (const [role, name] of Object.entries(SHADCN_MAPPING) as [
|
|
206
|
+
for (const [role, name] of Object.entries(SHADCN_MAPPING) as [
|
|
207
|
+
keyof AdeaThemeColors,
|
|
208
|
+
string | null,
|
|
209
|
+
][]) {
|
|
210
|
+
if (name === null) continue
|
|
199
211
|
variables[`--${name}`] = role === 'error' ? destructive.fill : theme.colors[role]
|
|
200
212
|
}
|
|
201
213
|
|
|
202
214
|
// Keep primary states on the shared appearance-aware accent derivation. Hover is
|
|
203
215
|
// resolved because its uniform lightness step cannot be expressed as a mix; the
|
|
204
|
-
// subtle tint stays tied to --primary so it follows runtime primary overrides
|
|
216
|
+
// subtle tint stays tied to --primary so it follows runtime primary overrides, at
|
|
217
|
+
// the strength measured for this theme so body text stays legible on it.
|
|
205
218
|
variables['--primary-hover'] = primaryHover(theme.colors.accent, theme.appearance)
|
|
206
|
-
variables['--primary-subtle'] = primarySubtleCss(theme
|
|
219
|
+
variables['--primary-subtle'] = primarySubtleCss(theme)
|
|
207
220
|
|
|
208
221
|
variables['--accent'] = theme.colors.surfaceHover
|
|
209
222
|
variables['--accent-foreground'] = theme.colors.text
|
|
@@ -17,8 +17,8 @@ const theme: AdeaThemeRecord = {
|
|
|
17
17
|
"foreground": "oklch(0.4899 0.0102 248.04)",
|
|
18
18
|
"surface": "oklch(0.9466 0.0008 247.84)",
|
|
19
19
|
"surfaceElevated": "oklch(0.9166 0.0011 247.84)",
|
|
20
|
-
"surfaceHover": "oklch(0.
|
|
21
|
-
"surfaceActive": "oklch(0.
|
|
20
|
+
"surfaceHover": "oklch(0.9086 0.0017 247.84)",
|
|
21
|
+
"surfaceActive": "oklch(0.8896 0.0021 247.84)",
|
|
22
22
|
"border": "oklch(0.8316 0.0015 247.84)",
|
|
23
23
|
"borderMuted": "oklch(0.8866 0.001 247.84)",
|
|
24
24
|
"text": "oklch(0.4899 0.0102 248.04)",
|
|
@@ -17,8 +17,8 @@ const theme: AdeaThemeRecord = {
|
|
|
17
17
|
"foreground": "oklch(0.7621 0.0202 262.99)",
|
|
18
18
|
"surface": "oklch(0.3275 0.019 264.3)",
|
|
19
19
|
"surfaceElevated": "oklch(0.3575 0.0218 264.3)",
|
|
20
|
-
"surfaceHover": "oklch(0.
|
|
21
|
-
"surfaceActive": "oklch(0.
|
|
20
|
+
"surfaceHover": "oklch(0.3725 0.0251 264.3)",
|
|
21
|
+
"surfaceActive": "oklch(0.3915 0.0251 264.3)",
|
|
22
22
|
"border": "oklch(0.4425 0.0141 264.3)",
|
|
23
23
|
"borderMuted": "oklch(0.3875 0.0094 264.3)",
|
|
24
24
|
"text": "oklch(0.7621 0.0202 262.99)",
|
|
@@ -18,7 +18,7 @@ const theme: AdeaThemeRecord = {
|
|
|
18
18
|
"surface": "oklch(0.9349 0.0056 71.9)",
|
|
19
19
|
"surfaceElevated": "oklch(0.9049 0.0083 71.9)",
|
|
20
20
|
"surfaceHover": "oklch(0.8699 0.0121 71.9)",
|
|
21
|
-
"surfaceActive": "oklch(0.
|
|
21
|
+
"surfaceActive": "oklch(0.8449 0.0147 71.9)",
|
|
22
22
|
"border": "oklch(0.8199 0.0102 71.9)",
|
|
23
23
|
"borderMuted": "oklch(0.8749 0.0068 71.9)",
|
|
24
24
|
"text": "oklch(0.4597 0.0629 289.56)",
|
package/src/index.ts
CHANGED
|
@@ -65,13 +65,16 @@ export {
|
|
|
65
65
|
ACCENT_HOVER_STEP,
|
|
66
66
|
ACCENT_IDS,
|
|
67
67
|
ACCENT_SUBTLE_ALPHA,
|
|
68
|
+
ACCENT_SUBTLE_MINIMUM_ALPHA,
|
|
68
69
|
accentForeground,
|
|
69
70
|
accentForegroundContrast,
|
|
70
71
|
accentRoles,
|
|
71
72
|
accentValue,
|
|
72
73
|
getAccent,
|
|
73
74
|
primaryHover,
|
|
75
|
+
primarySubtleAlpha,
|
|
74
76
|
primarySubtleCss,
|
|
77
|
+
primaryTintClears,
|
|
75
78
|
themeAccentPresets,
|
|
76
79
|
} from './accents.js'
|
|
77
80
|
|