@adea-ai/themes 0.11.7 → 0.11.12
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 +46 -0
- package/dist/accents.d.ts +19 -19
- package/dist/accents.d.ts.map +1 -1
- package/dist/accents.js +45 -93
- package/dist/accents.js.map +1 -1
- package/dist/adapters/base24.d.ts +21 -12
- package/dist/adapters/base24.d.ts.map +1 -1
- package/dist/adapters/base24.js +47 -72
- package/dist/adapters/base24.js.map +1 -1
- package/dist/adapters/css-variables.d.ts +29 -0
- package/dist/adapters/css-variables.d.ts.map +1 -0
- package/dist/adapters/css-variables.js +56 -0
- package/dist/adapters/css-variables.js.map +1 -0
- package/dist/adapters/css.d.ts +2 -4
- package/dist/adapters/css.d.ts.map +1 -1
- package/dist/adapters/css.js +7 -39
- package/dist/adapters/css.js.map +1 -1
- package/dist/adapters/shadcn.d.ts +8 -4
- package/dist/adapters/shadcn.d.ts.map +1 -1
- package/dist/adapters/shadcn.js +38 -57
- package/dist/adapters/shadcn.js.map +1 -1
- package/dist/adapters/shiki.d.ts +2 -10
- package/dist/adapters/shiki.d.ts.map +1 -1
- package/dist/adapters/shiki.js +16 -29
- package/dist/adapters/shiki.js.map +1 -1
- package/dist/adapters/tailwind.d.ts +3 -3
- package/dist/adapters/tailwind.d.ts.map +1 -1
- package/dist/adapters/tailwind.js +7 -28
- package/dist/adapters/tailwind.js.map +1 -1
- package/dist/adapters/xterm.d.ts.map +1 -1
- package/dist/adapters/xterm.js +9 -21
- package/dist/adapters/xterm.js.map +1 -1
- package/dist/base24-synthesis.d.ts +31 -0
- package/dist/base24-synthesis.d.ts.map +1 -0
- package/dist/base24-synthesis.js +25 -0
- package/dist/base24-synthesis.js.map +1 -0
- package/dist/derive.d.ts +1 -1
- package/dist/derive.d.ts.map +1 -1
- package/dist/derive.js +11 -26
- package/dist/derive.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/normalize.d.ts +0 -8
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.js +105 -232
- package/dist/normalize.js.map +1 -1
- package/dist/oklch.d.ts +1 -7
- package/dist/oklch.d.ts.map +1 -1
- package/dist/oklch.js +15 -35
- package/dist/oklch.js.map +1 -1
- package/dist/policy.d.ts +14 -4
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +16 -4
- package/dist/policy.js.map +1 -1
- package/dist/render.d.ts +30 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +74 -0
- package/dist/render.js.map +1 -0
- package/dist/sources.d.ts +26 -33
- package/dist/sources.d.ts.map +1 -1
- package/dist/sources.js +136 -305
- package/dist/sources.js.map +1 -1
- package/dist/step-search.d.ts +10 -0
- package/dist/step-search.d.ts.map +1 -0
- package/dist/step-search.js +21 -0
- package/dist/step-search.js.map +1 -0
- package/dist/theme-token-projection-script.d.ts +2 -0
- package/dist/theme-token-projection-script.js +2 -0
- package/dist/theme-token-projection.d.ts +35 -0
- package/dist/theme-token-projection.d.ts.map +1 -0
- package/dist/theme-token-projection.js +79 -0
- package/dist/theme-token-projection.js.map +1 -0
- package/dist/validate.d.ts +12 -17
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +17 -63
- package/dist/validate.js.map +1 -1
- package/package.json +13 -3
- package/src/accents.ts +57 -96
- package/src/adapters/base24.ts +53 -75
- package/src/adapters/css-variables.ts +67 -0
- package/src/adapters/css.ts +9 -54
- package/src/adapters/shadcn.ts +34 -60
- package/src/adapters/shiki.ts +17 -30
- package/src/adapters/tailwind.ts +7 -37
- package/src/adapters/xterm.ts +9 -21
- package/src/base24-synthesis.ts +29 -0
- package/src/derive.ts +12 -27
- package/src/index.ts +6 -5
- package/src/normalize.ts +140 -267
- package/src/oklch.ts +20 -35
- package/src/policy.ts +18 -4
- package/src/render.ts +82 -0
- package/src/sources.ts +160 -330
- package/src/step-search.ts +25 -0
- package/src/theme-token-projection.ts +126 -0
- package/src/validate.ts +31 -74
package/src/adapters/shadcn.ts
CHANGED
|
@@ -25,14 +25,9 @@
|
|
|
25
25
|
import type { AdeaTheme, AdeaThemeColors, ShadcnThemeProjection } from '../schema.js'
|
|
26
26
|
import { primaryHover, primarySubtleCss } from '../accents.js'
|
|
27
27
|
import { STATUS_ROLES, statusForeground, tint } from '../derive.js'
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
gamutMap,
|
|
32
|
-
hexToOklch,
|
|
33
|
-
oklchToHex,
|
|
34
|
-
parseColor,
|
|
35
|
-
} from '../oklch.js'
|
|
28
|
+
import { contrastRatio, formatOklch, gamutMap, parseColor } from '../oklch.js'
|
|
29
|
+
import { compositeOver, renderedColor } from '../render.js'
|
|
30
|
+
import { smallestOffset } from '../step-search.js'
|
|
36
31
|
|
|
37
32
|
/** A canonical theme with optional owner-authored shadcn presentation values. */
|
|
38
33
|
export type ShadcnTheme = AdeaTheme & { shadcn?: ShadcnThemeProjection }
|
|
@@ -49,33 +44,15 @@ const DESTRUCTIVE_PRESENTATION_FLOOR = 5
|
|
|
49
44
|
const DESTRUCTIVE_HOVER_OPACITY = 0.9
|
|
50
45
|
const DESTRUCTIVE_PRESENTATION_SURFACES = ['background', 'surface', 'surfaceElevated'] as const
|
|
51
46
|
|
|
52
|
-
function renderedColor(value: string) {
|
|
53
|
-
const color = parseColor(value)
|
|
54
|
-
return color ? hexToOklch(oklchToHex(color)) : undefined
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function compositeSrgb(foreground: string, background: string, alpha: number) {
|
|
58
|
-
const foregroundHex = oklchToHex(parseColor(foreground)!)
|
|
59
|
-
const backgroundHex = oklchToHex(parseColor(background)!)
|
|
60
|
-
const channels = [1, 3, 5].map((offset) => {
|
|
61
|
-
const front = Number.parseInt(foregroundHex.slice(offset, offset + 2), 16)
|
|
62
|
-
const back = Number.parseInt(backgroundHex.slice(offset, offset + 2), 16)
|
|
63
|
-
return Math.round(front * alpha + back * (1 - alpha))
|
|
64
|
-
.toString(16)
|
|
65
|
-
.padStart(2, '0')
|
|
66
|
-
})
|
|
67
|
-
return hexToOklch(`#${channels.join('')}`)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
47
|
/**
|
|
71
48
|
* The shared destructive solid fill and foreground as rendered by the UI.
|
|
72
49
|
*
|
|
73
50
|
* A filled destructive button uses `--destructive/90` on hover. A foreground that
|
|
74
51
|
* clears the original fill can fall below AA when that color is alpha-composited
|
|
75
|
-
* over a light or dark surface.
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* margin
|
|
52
|
+
* over a light or dark surface. The canonical error color is untouched; the fill
|
|
53
|
+
* differs from it only in lightness, and the foreground clears 5:1 against the fill
|
|
54
|
+
* and against its 90% composite over the canvas and both card surfaces, as eight-bit
|
|
55
|
+
* sRGB. The margin over 4.5:1 protects the AA floor from browser quantization.
|
|
79
56
|
*/
|
|
80
57
|
export function shadcnDestructiveProjection(theme: ShadcnTheme): ShadcnDestructiveProjection {
|
|
81
58
|
const sourceFill = parseColor(theme.colors.error)
|
|
@@ -87,7 +64,7 @@ export function shadcnDestructiveProjection(theme: ShadcnTheme): ShadcnDestructi
|
|
|
87
64
|
|
|
88
65
|
const preferredForeground = statusForeground(theme, 'error')
|
|
89
66
|
const alternateForeground =
|
|
90
|
-
|
|
67
|
+
preferredForeground === formatOklch(sourceForeground)
|
|
91
68
|
? theme.colors.background
|
|
92
69
|
: theme.colors.foreground
|
|
93
70
|
const foregrounds = [preferredForeground, alternateForeground]
|
|
@@ -109,40 +86,40 @@ export function shadcnDestructiveProjection(theme: ShadcnTheme): ShadcnDestructi
|
|
|
109
86
|
throw new Error(`theme ${theme.id} has an invalid destructive presentation surface`)
|
|
110
87
|
}
|
|
111
88
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (candidate.l < 0.02 || candidate.l > 0.98) continue
|
|
120
|
-
const fill = formatOklch(candidate)
|
|
121
|
-
const renderedFill = renderedColor(fill)
|
|
122
|
-
if (!renderedFill) continue
|
|
89
|
+
let found: ShadcnDestructiveProjection | undefined
|
|
90
|
+
const accepts = (offset: number): boolean => {
|
|
91
|
+
const candidate = gamutMap({ ...sourceFill, l: sourceFill.l + offset })
|
|
92
|
+
if (candidate.l < 0.02 || candidate.l > 0.98) return false
|
|
93
|
+
const fill = formatOklch(candidate)
|
|
94
|
+
const renderedFill = renderedColor(fill)
|
|
95
|
+
if (!renderedFill) return false
|
|
123
96
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const composite = compositeSrgb(fill, formatOklch(rendered), DESTRUCTIVE_HOVER_OPACITY)
|
|
97
|
+
const foreground = foregrounds.find(
|
|
98
|
+
({ rendered: text }) =>
|
|
99
|
+
contrastRatio(text, renderedFill) >= DESTRUCTIVE_PRESENTATION_FLOOR &&
|
|
100
|
+
surfaces.every(({ rendered: surface }) => {
|
|
101
|
+
const composite = compositeOver(fill, formatOklch(surface), DESTRUCTIVE_HOVER_OPACITY)
|
|
130
102
|
return (
|
|
131
103
|
composite !== undefined &&
|
|
132
|
-
contrastRatio(
|
|
104
|
+
contrastRatio(text, composite) >= DESTRUCTIVE_PRESENTATION_FLOOR
|
|
133
105
|
)
|
|
134
106
|
})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
107
|
+
)
|
|
108
|
+
if (foreground) found = { fill, foreground: foreground.value }
|
|
109
|
+
return foreground !== undefined
|
|
138
110
|
}
|
|
139
111
|
|
|
112
|
+
if (accepts(0) || smallestOffset(0.001, 250, [-1, 1], accepts) !== undefined) return found!
|
|
140
113
|
throw new Error(`theme ${theme.id} cannot meet the shared destructive presentation floor`)
|
|
141
114
|
}
|
|
142
115
|
|
|
143
116
|
/**
|
|
144
117
|
* Canonical role → shadcn custom-property name.
|
|
145
118
|
*
|
|
119
|
+
* The default source of each name: `shadcnVariables` replaces `--destructive` with
|
|
120
|
+
* the destructive projection, and `--card`, `--popover`, `--muted-foreground` and
|
|
121
|
+
* `--border` with a record's own `shadcn` values when it has them.
|
|
122
|
+
*
|
|
146
123
|
* Every entry is a deliberate correspondence, and the ones that are not a plain
|
|
147
124
|
* rename carry the reason here rather than in the output. A `null` destination
|
|
148
125
|
* is a deliberate "not emitted": the role has no shadcn consumer, and the
|
|
@@ -165,7 +142,7 @@ export const SHADCN_MAPPING: Readonly<Record<keyof AdeaThemeColors, string | nul
|
|
|
165
142
|
text: 'foreground',
|
|
166
143
|
textMuted: 'muted-foreground',
|
|
167
144
|
// shadcn has no tertiary text slot and nothing reads `--subtle-foreground`;
|
|
168
|
-
// `textSubtle` stays a canonical role (the shiki adapter's
|
|
145
|
+
// `textSubtle` stays a canonical role (the shiki adapter's line numbers).
|
|
169
146
|
textSubtle: null,
|
|
170
147
|
// See the header: the interactive colour is shadcn's `primary`.
|
|
171
148
|
accent: 'primary',
|
|
@@ -211,10 +188,9 @@ export function shadcnVariables(theme: ShadcnTheme): Record<string, string> {
|
|
|
211
188
|
variables[`--${name}`] = role === 'error' ? destructive.fill : theme.colors[role]
|
|
212
189
|
}
|
|
213
190
|
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
// the strength measured for this theme so body text stays legible on it.
|
|
191
|
+
// Hover is resolved because its uniform lightness step cannot be expressed as a
|
|
192
|
+
// mix; the subtle tint stays tied to --primary so it follows runtime primary
|
|
193
|
+
// overrides, at the strength measured for this theme so body text stays legible.
|
|
218
194
|
variables['--primary-hover'] = primaryHover(theme.colors.accent, theme.appearance)
|
|
219
195
|
variables['--primary-subtle'] = primarySubtleCss(theme)
|
|
220
196
|
|
|
@@ -249,9 +225,7 @@ export function shadcnVariables(theme: ShadcnTheme): Record<string, string> {
|
|
|
249
225
|
|
|
250
226
|
for (const role of STATUS_ROLES) {
|
|
251
227
|
// Status labels on a subtle fill use the theme's body foreground; this
|
|
252
|
-
// foreground is reserved for text on the role's solid colour.
|
|
253
|
-
// generated shadcn names aligned with SHADCN_MAPPING, especially error →
|
|
254
|
-
// destructive, and resolve the tint against a real canvas so it is opaque.
|
|
228
|
+
// foreground is reserved for text on the role's solid colour.
|
|
255
229
|
const shadcnRole = SHADCN_MAPPING[role]
|
|
256
230
|
variables[`--${shadcnRole}-foreground`] =
|
|
257
231
|
role === 'error' ? destructive.foreground : statusForeground(theme, role)
|
package/src/adapters/shiki.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* ## Why a registration and not a bundled theme
|
|
20
20
|
*
|
|
21
|
-
* `
|
|
21
|
+
* `toShikiTheme` returns the object; it does not call `loadTheme`, and it does
|
|
22
22
|
* not import Shiki. That keeps this package free of a dependency on a library that
|
|
23
23
|
* is an application's choice, and it means a consumer can register the result
|
|
24
24
|
* however it likes — synchronously, into a custom highlighter, or inside a worker.
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
import type { AdeaTheme } from '../schema.js'
|
|
28
28
|
import type { SyntaxRole } from '../derive.js'
|
|
29
29
|
import { syntaxRolesHex } from '../derive.js'
|
|
30
|
-
import {
|
|
30
|
+
import { toHex as hex } from '../render.js'
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* A Shiki theme registration.
|
|
@@ -53,7 +53,12 @@ export interface ShikiTokenSetting {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Syntax role → the TextMate scopes it colours.
|
|
56
|
+
* Syntax role → the TextMate scopes it colours, in the order they are emitted.
|
|
57
|
+
*
|
|
58
|
+
* Order matters in Shiki's `settings` list: later entries win, and the scopes here
|
|
59
|
+
* overlap by design (`keyword.operator` is claimed by both `keyword` and
|
|
60
|
+
* `operator`). `operator` is last so its narrower claim wins, which is what every
|
|
61
|
+
* editor does and what makes `+` and `=` read differently from `if` and `return`.
|
|
57
62
|
*
|
|
58
63
|
* The scope lists are the ones an editor grammar actually emits, and several roles
|
|
59
64
|
* claim more than one scope because grammars disagree: a type annotation may arrive
|
|
@@ -79,7 +84,6 @@ const SHIKI_SCOPES: Readonly<Record<SyntaxRole, readonly string[]>> = Object.fre
|
|
|
79
84
|
type: ['entity.name.type', 'entity.name.class', 'support.type', 'support.class'],
|
|
80
85
|
tag: ['entity.name.tag', 'meta.tag'],
|
|
81
86
|
attribute: ['entity.other.attribute-name'],
|
|
82
|
-
operator: ['keyword.operator'],
|
|
83
87
|
heading: ['markup.heading', 'entity.name.section'],
|
|
84
88
|
link: ['markup.underline.link', 'string.other.link'],
|
|
85
89
|
constant: ['constant', 'support.constant', 'variable.language'],
|
|
@@ -88,17 +92,15 @@ const SHIKI_SCOPES: Readonly<Record<SyntaxRole, readonly string[]>> = Object.fre
|
|
|
88
92
|
diffDelete: ['markup.deleted', 'meta.diff.header.from-file', 'punctuation.definition.deleted'],
|
|
89
93
|
diffHunk: ['meta.diff.range', 'meta.diff.index', 'punctuation.definition.range.diff'],
|
|
90
94
|
searchMatch: ['markup.highlight', 'markup.underline.match'],
|
|
95
|
+
operator: ['keyword.operator'],
|
|
91
96
|
})
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* every editor does and what makes `+` and `=` read differently from `if` and
|
|
100
|
-
* `return`.
|
|
101
|
-
*/
|
|
98
|
+
const FONT_STYLES: Readonly<Partial<Record<SyntaxRole, string>>> = Object.freeze({
|
|
99
|
+
comment: 'italic',
|
|
100
|
+
heading: 'bold',
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
/** Converts a theme to a Shiki registration. */
|
|
102
104
|
export function toShikiTheme(theme: AdeaTheme): ShikiThemeRegistration {
|
|
103
105
|
const roles = syntaxRolesHex(theme)
|
|
104
106
|
|
|
@@ -115,8 +117,6 @@ export function toShikiTheme(theme: AdeaTheme): ShikiThemeRegistration {
|
|
|
115
117
|
'editorWhitespace.foreground': hex(theme.colors.border),
|
|
116
118
|
'editorWidget.background': hex(theme.colors.surfaceElevated),
|
|
117
119
|
'editorWidget.border': hex(theme.colors.border),
|
|
118
|
-
// Diff surfaces read the semantic status roles rather than a separate scale,
|
|
119
|
-
// so a diff in the editor and a diff in the conversation use one palette.
|
|
120
120
|
'diffEditor.insertedTextBackground': hex(theme.colors.surface),
|
|
121
121
|
'diffEditor.removedTextBackground': hex(theme.colors.surface),
|
|
122
122
|
'terminal.ansiRed': hex(theme.ansi.red),
|
|
@@ -132,21 +132,14 @@ export function toShikiTheme(theme: AdeaTheme): ShikiThemeRegistration {
|
|
|
132
132
|
{ settings: { foreground: hex(theme.colors.text), background: hex(theme.colors.background) } },
|
|
133
133
|
]
|
|
134
134
|
|
|
135
|
-
// Everything except `operator`, which is emitted last and narrows the claim.
|
|
136
135
|
for (const [role, scopes] of Object.entries(SHIKI_SCOPES) as [SyntaxRole, readonly string[]][]) {
|
|
137
|
-
|
|
136
|
+
const fontStyle = FONT_STYLES[role]
|
|
138
137
|
settings.push({
|
|
139
138
|
scope: scopes,
|
|
140
|
-
settings: {
|
|
141
|
-
foreground: roles[role],
|
|
142
|
-
...(role === 'comment' ? { fontStyle: 'italic' } : {}),
|
|
143
|
-
...(role === 'heading' ? { fontStyle: 'bold' } : {}),
|
|
144
|
-
},
|
|
139
|
+
settings: { foreground: roles[role], ...(fontStyle ? { fontStyle } : {}) },
|
|
145
140
|
})
|
|
146
141
|
}
|
|
147
142
|
|
|
148
|
-
settings.push({ scope: SHIKI_SCOPES.operator, settings: { foreground: roles.operator } })
|
|
149
|
-
|
|
150
143
|
return {
|
|
151
144
|
name: `adea-${theme.id}`,
|
|
152
145
|
type: theme.appearance,
|
|
@@ -155,12 +148,6 @@ export function toShikiTheme(theme: AdeaTheme): ShikiThemeRegistration {
|
|
|
155
148
|
}
|
|
156
149
|
}
|
|
157
150
|
|
|
158
|
-
/** Formats a colour as hex, leaving it alone if it cannot be parsed. */
|
|
159
|
-
function hex(value: string): string {
|
|
160
|
-
const parsed = parseColor(value)
|
|
161
|
-
return parsed ? oklchToHex(parsed) : value
|
|
162
|
-
}
|
|
163
|
-
|
|
164
151
|
/** Every theme as a registration list, ready for `createHighlighter({ themes })`. */
|
|
165
152
|
export function toShikiThemes(themes: readonly AdeaTheme[]): ShikiThemeRegistration[] {
|
|
166
153
|
return themes.map(toShikiTheme)
|
package/src/adapters/tailwind.ts
CHANGED
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
* utility in every consumer, and a consumer cannot silently fall behind.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
import { STATUS_ROLES } from '../derive.js'
|
|
16
|
+
import { CANONICAL_VARIABLES, DERIVED_VARIABLES, variableName } from './css-variables.js'
|
|
18
17
|
|
|
19
18
|
export interface TailwindOptions {
|
|
20
19
|
/** The custom-property namespace the CSS adapter used. Defaults to `adea`. */
|
|
@@ -27,53 +26,24 @@ export interface TailwindOptions {
|
|
|
27
26
|
extra?: Readonly<Record<string, string>>
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
function kebab(name: string): string {
|
|
31
|
-
return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
29
|
/**
|
|
35
30
|
* The `--color-*` namespace, which is what makes `bg-surface` a valid utility.
|
|
36
31
|
*
|
|
37
32
|
* Takes no theme, and that is the point rather than an oversight. Every declaration
|
|
38
|
-
* this emits is a `var()` reference, so the block is identical for
|
|
39
|
-
*
|
|
40
|
-
*
|
|
33
|
+
* this emits is a `var()` reference, so the block is identical for every theme and
|
|
34
|
+
* one stylesheet serves all of them. Accepting a theme would imply the output
|
|
35
|
+
* depended on which theme was passed, and the first person to notice would
|
|
41
36
|
* reasonably conclude they needed one block per theme.
|
|
42
37
|
*/
|
|
43
38
|
export function toTailwindTheme(options: TailwindOptions = {}): string {
|
|
44
39
|
const prefix = options.prefix ?? 'adea'
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
// `inline` so the utility resolves the variable at use time rather than at build
|
|
49
|
-
// time. Without it, every theme would need its own stylesheet.
|
|
50
|
-
lines.push('@theme inline {')
|
|
51
|
-
|
|
52
|
-
for (const role of THEME_COLOR_KEYS) {
|
|
53
|
-
lines.push(` --color-${kebab(role)}: var(${property(kebab(role))});`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
lines.push(` --color-surface-sunken: var(${property('surface-sunken')});`)
|
|
57
|
-
lines.push(` --color-cursor: var(${property('cursor')});`)
|
|
58
|
-
lines.push(` --color-selection: var(${property('selection')});`)
|
|
59
|
-
|
|
60
|
-
for (const role of STATUS_ROLES) {
|
|
61
|
-
lines.push(` --color-${role}-subtle: var(${property(`${role}-subtle`)});`)
|
|
62
|
-
lines.push(` --color-${role}-foreground: var(${property(`${role}-foreground`)});`)
|
|
40
|
+
const lines = ['@theme inline {']
|
|
41
|
+
for (const { name } of [...CANONICAL_VARIABLES, ...DERIVED_VARIABLES]) {
|
|
42
|
+
lines.push(` --color-${name}: var(${variableName(name, prefix)});`)
|
|
63
43
|
}
|
|
64
|
-
|
|
65
|
-
for (let index = 1; index <= 6; index += 1) {
|
|
66
|
-
lines.push(` --color-chart-${index}: var(${property(`chart-${index}`)});`)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
for (const key of ANSI_KEYS) {
|
|
70
|
-
lines.push(` --color-ansi-${kebab(key)}: var(${property(`ansi-${kebab(key)}`)});`)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
44
|
for (const [name, value] of Object.entries(options.extra ?? {})) {
|
|
74
45
|
lines.push(` --color-${name}: ${value};`)
|
|
75
46
|
}
|
|
76
|
-
|
|
77
47
|
lines.push('}')
|
|
78
48
|
return lines.join('\n')
|
|
79
49
|
}
|
package/src/adapters/xterm.ts
CHANGED
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
import type { AdeaTheme } from '../schema.js'
|
|
18
18
|
import type { Oklch } from '../oklch.js'
|
|
19
|
-
import {
|
|
19
|
+
import { oklchToHex, parseColor, repairContrast } from '../oklch.js'
|
|
20
|
+
import { CONTRAST_FLOORS } from '../policy.js'
|
|
21
|
+
import { mostContrasting, toHex as hex } from '../render.js'
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* The shape xterm.js's `ITheme` requires.
|
|
@@ -49,12 +51,8 @@ export interface XtermTheme {
|
|
|
49
51
|
brightWhite: string
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
*
|
|
55
|
-
* Selected text is text, so it takes the body floor.
|
|
56
|
-
*/
|
|
57
|
-
const SELECTION_FLOOR = 4.5
|
|
54
|
+
/** Selected text is text, so it takes the body floor. */
|
|
55
|
+
const SELECTION_FLOOR = CONTRAST_FLOORS.text
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
58
|
* The floor for the glyph under the cursor.
|
|
@@ -127,12 +125,10 @@ export function toXtermTheme(theme: AdeaTheme): XtermTheme {
|
|
|
127
125
|
}
|
|
128
126
|
|
|
129
127
|
/**
|
|
130
|
-
* The
|
|
128
|
+
* The most contrasting candidate as a foreground for `surface`.
|
|
131
129
|
*
|
|
132
|
-
* Repaired if
|
|
133
|
-
* selection colour that sits exactly between its background and its text.
|
|
134
|
-
* repair is bounded so it cannot drift into a colour the palette does not contain
|
|
135
|
-
* by more than a perceptible step.
|
|
130
|
+
* Repaired if none clears the floor, which happens when a palette picks a
|
|
131
|
+
* selection colour that sits exactly between its background and its text.
|
|
136
132
|
*/
|
|
137
133
|
function pickForeground(
|
|
138
134
|
surface: Oklch | undefined,
|
|
@@ -142,18 +138,10 @@ function pickForeground(
|
|
|
142
138
|
if (!surface) return candidates[0] ? oklchToHex(candidates[0]) : '#000000'
|
|
143
139
|
if (candidates.length === 0) return '#000000'
|
|
144
140
|
|
|
145
|
-
|
|
146
|
-
for (const candidate of candidates.slice(1)) {
|
|
147
|
-
if (contrastRatio(candidate, surface) > contrastRatio(best, surface)) best = candidate
|
|
148
|
-
}
|
|
141
|
+
const best = mostContrasting(surface, candidates)
|
|
149
142
|
|
|
150
143
|
// A generous budget: the alternative to a large lightness move here is an
|
|
151
144
|
// invisible glyph, and the colour is already one of the palette's own.
|
|
152
145
|
const repaired = repairContrast(best, surface, floor, 0.9)
|
|
153
146
|
return oklchToHex(repaired.color)
|
|
154
147
|
}
|
|
155
|
-
|
|
156
|
-
function hex(value: string): string {
|
|
157
|
-
const parsed = parseColor(value)
|
|
158
|
-
return parsed ? oklchToHex(parsed) : value
|
|
159
|
-
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Oklch } from './oklch.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base24's orange (`base09`) and brown (`base0F`), which no ANSI set contains and
|
|
5
|
+
* Adea has no role for, as a fixed hue rotation off red and yellow.
|
|
6
|
+
*
|
|
7
|
+
* A rotation keeps the source's saturation while moving the hue far enough to read
|
|
8
|
+
* as a distinct token.
|
|
9
|
+
*/
|
|
10
|
+
export const SYNTHESISED_HUES = Object.freeze({
|
|
11
|
+
base09: { from: 'red', degrees: 26 },
|
|
12
|
+
base0F: { from: 'yellow', degrees: -34 },
|
|
13
|
+
} as const)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Base24's `base10` and `base11` as lightness steps past the canvas: below it on a
|
|
17
|
+
* dark scheme ("dark black", "darker than that"), beyond it on a light one, where the
|
|
18
|
+
* normalizer reads the two as the light end of the ANSI ramp.
|
|
19
|
+
*/
|
|
20
|
+
export const PAST_CANVAS_STEPS = Object.freeze({ base10: 0.03, base11: 0.06 } as const)
|
|
21
|
+
|
|
22
|
+
/** The direction `PAST_CANVAS_STEPS` move in for an appearance. */
|
|
23
|
+
export function pastCanvasDirection(appearance: 'dark' | 'light'): 1 | -1 {
|
|
24
|
+
return appearance === 'light' ? 1 : -1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function rotateHue(color: Oklch, degrees: number): Oklch {
|
|
28
|
+
return { ...color, h: (color.h + degrees + 360) % 360 }
|
|
29
|
+
}
|
package/src/derive.ts
CHANGED
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
import type { AdeaTheme } from './schema.js'
|
|
33
33
|
import type { Oklch } from './oklch.js'
|
|
34
34
|
import { contrastRatio, formatOklch, mix, oklchToHex, parseColor, repairContrast } from './oklch.js'
|
|
35
|
+
import { CONTRAST_FLOORS, clearsFloor } from './policy.js'
|
|
36
|
+
import { mostContrasting, repairToHex, toHex } from './render.js'
|
|
35
37
|
|
|
36
38
|
/** The syntax roles, matching the names Shiki's theme contract expects. */
|
|
37
39
|
export type SyntaxRole =
|
|
@@ -174,12 +176,8 @@ export function syntaxRoles(
|
|
|
174
176
|
|
|
175
177
|
/** The syntax palette as hex, for engines that cannot evaluate `oklch()`. */
|
|
176
178
|
export function syntaxRolesHex(theme: AdeaTheme): Record<SyntaxRole, string> {
|
|
177
|
-
const roles = syntaxRoles(theme)
|
|
178
179
|
return Object.fromEntries(
|
|
179
|
-
Object.entries(
|
|
180
|
-
const parsed = parseColor(value)
|
|
181
|
-
return [role, parsed ? oklchToHex(parsed) : value]
|
|
182
|
-
})
|
|
180
|
+
Object.entries(syntaxRoles(theme)).map(([role, value]) => [role, toHex(value)])
|
|
183
181
|
) as Record<SyntaxRole, string>
|
|
184
182
|
}
|
|
185
183
|
|
|
@@ -201,31 +199,21 @@ export function editorRolesHex(theme: AdeaTheme): Record<EditorRole, string> {
|
|
|
201
199
|
|
|
202
200
|
const initial = oklchToHex(source)
|
|
203
201
|
const renderedInitial = parseColor(initial)
|
|
204
|
-
if (
|
|
202
|
+
if (
|
|
203
|
+
renderedInitial &&
|
|
204
|
+
clearsFloor(contrastRatio(renderedInitial, background), CONTRAST_FLOORS.text)
|
|
205
|
+
) {
|
|
205
206
|
return [role, initial]
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
// Repair against the exact role the editor receives. A repair at precisely
|
|
209
|
-
// 4.5:1 in OKLCH can round to a hex value just below that floor, so advance
|
|
210
|
-
// the requested threshold by the smallest measured step until the encoded
|
|
211
|
-
// value itself clears 4.5:1. No source palette value or hue is rewritten.
|
|
212
|
-
//
|
|
213
209
|
// The projection runs with a wider lightness budget than the default repair,
|
|
214
210
|
// because a light theme's brightest ANSI slots start near the paper: a
|
|
215
211
|
// pastel yellow `number` has more lightness between it and 4.5:1 than the
|
|
216
212
|
// default budget allows, and this projection's contract is to hold the role
|
|
217
213
|
// to AA however far the lightness has to travel — darkening a chromatic
|
|
218
214
|
// colour keeps its hue, so the number stays yellow, just amber.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (!repaired.satisfied) continue
|
|
222
|
-
const candidate = oklchToHex(repaired.color)
|
|
223
|
-
const renderedCandidate = parseColor(candidate)
|
|
224
|
-
if (renderedCandidate && contrastRatio(renderedCandidate, background) >= 4.5 - 1e-9) {
|
|
225
|
-
return [role, candidate]
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
215
|
+
const repaired = repairToHex(source, background, CONTRAST_FLOORS.text, 0.55)
|
|
216
|
+
if (repaired) return [role, repaired]
|
|
229
217
|
throw new Error(`cannot encode editor.${role} for ${theme.id} above 4.5:1 contrast`)
|
|
230
218
|
})
|
|
231
219
|
) as Record<EditorRole, string>
|
|
@@ -278,7 +266,7 @@ export type StatusRole = (typeof STATUS_ROLES)[number]
|
|
|
278
266
|
* The text colour to draw on a **solid** fill of a status role.
|
|
279
267
|
*
|
|
280
268
|
* Not the appearance's `foreground`, which is the shortcut and is wrong half the
|
|
281
|
-
* time: a dark theme's foreground is near-white, and near-white on
|
|
269
|
+
* time: a dark theme's foreground is near-white, and near-white on Adea Dark's
|
|
282
270
|
* `success` at `#3fb950` measures 2.6:1 — illegible. The correct answer is
|
|
283
271
|
* whichever of the theme's two extremes measures better against the fill, which
|
|
284
272
|
* for a bright green is black and for a deep red is white.
|
|
@@ -293,13 +281,10 @@ export function statusForeground(theme: AdeaTheme, role: StatusRole): string {
|
|
|
293
281
|
const foreground = parseColor(theme.colors.foreground)
|
|
294
282
|
if (!fill || !background || !foreground) return theme.colors.foreground
|
|
295
283
|
|
|
296
|
-
|
|
297
|
-
contrastRatio(foreground, fill) >= contrastRatio(background, fill) ? foreground : background
|
|
298
|
-
return formatOklch(best)
|
|
284
|
+
return formatOklch(mostContrasting(fill, [foreground, background]))
|
|
299
285
|
}
|
|
300
286
|
|
|
301
287
|
/** {@link statusForeground} as hex, for engines that cannot evaluate `oklch()`. */
|
|
302
288
|
export function statusForegroundHex(theme: AdeaTheme, role: StatusRole): string {
|
|
303
|
-
|
|
304
|
-
return parsed ? oklchToHex(parsed) : theme.colors.foreground
|
|
289
|
+
return toHex(statusForeground(theme, role))
|
|
305
290
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
*
|
|
12
12
|
* **Adea owns the schema and the transformation.** The seventeen surface roles in
|
|
13
13
|
* `schema.ts` are the contract, and no upstream project is asked to satisfy it. The
|
|
14
|
-
* Base24 palettes in `palettes/` are reproduced from a pinned revision; the
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* Base24 palettes in `palettes/` are reproduced from a pinned revision; the Adea
|
|
15
|
+
* family is composed from GitHub's palettes. Normalizing inputs is this package's
|
|
16
|
+
* job and it happens once, here.
|
|
17
17
|
*
|
|
18
18
|
* **OKLCH is the representation.** Every role is an `oklch()` string. Lightness in
|
|
19
19
|
* OKLCH is perceptually uniform, which is what lets a surface ladder be built by
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* theme be re-hued without re-deriving its ramp by eye.
|
|
22
22
|
*
|
|
23
23
|
* **Contrast is measured, not assumed.** Nothing enters the catalogue without
|
|
24
|
-
* clearing the floors in `
|
|
24
|
+
* clearing the floors in `policy.ts`; a palette that cannot is repaired by the
|
|
25
25
|
* least move that works, and reported. Several famous palettes fail on their own
|
|
26
26
|
* background, and the catalogue says so rather than shipping them.
|
|
27
27
|
*
|
|
@@ -124,7 +124,8 @@ export {
|
|
|
124
124
|
|
|
125
125
|
/* --- Normalization, for a consumer bringing its own palette ------------- */
|
|
126
126
|
export type { NormalizationFinding, NormalizedTheme, ThemeSourceSpec } from './normalize.js'
|
|
127
|
-
export {
|
|
127
|
+
export { normalizeTheme } from './normalize.js'
|
|
128
|
+
export { CONTRAST_FLOORS } from './policy.js'
|
|
128
129
|
|
|
129
130
|
/* --- Derived colours --------------------------------------------------- */
|
|
130
131
|
export type { EditorRole, StatusRole, SyntaxRole } from './derive.js'
|