@adea-ai/themes 0.11.6 → 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 +4 -10
- package/dist/oklch.d.ts.map +1 -1
- package/dist/oklch.js +18 -38
- 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/schema.d.ts +2 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -1
- package/dist/schema.js.map +1 -1
- 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 +33 -55
- package/dist/validate.js.map +1 -1
- package/package.json +14 -4
- 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 +23 -38
- package/src/policy.ts +18 -4
- package/src/render.ts +82 -0
- package/src/schema.ts +2 -1
- 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 +46 -66
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The smallest move along one axis that satisfies a predicate.
|
|
3
|
+
*
|
|
4
|
+
* Tries `step`, then `2 × step`, and so on up to `steps` increments, in each of
|
|
5
|
+
* `directions` at every size, and returns the first offset `accepts`.
|
|
6
|
+
*/
|
|
7
|
+
export function smallestOffset(
|
|
8
|
+
step: number,
|
|
9
|
+
steps: number,
|
|
10
|
+
directions: readonly number[],
|
|
11
|
+
accepts: (offset: number) => boolean
|
|
12
|
+
): number | undefined {
|
|
13
|
+
for (let index = 1; index <= steps; index += 1) {
|
|
14
|
+
for (const direction of directions) {
|
|
15
|
+
const offset = direction * step * index
|
|
16
|
+
if (accepts(offset)) return offset
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The size of an offset as a repair reports it: positive, at the catalogue's precision. */
|
|
23
|
+
export function offsetSize(offset: number): number {
|
|
24
|
+
return Number(Math.abs(offset).toFixed(4))
|
|
25
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializable projections for token maps that have stable roles but predate one
|
|
3
|
+
* of the design system's derived token families.
|
|
4
|
+
*
|
|
5
|
+
* The rules are data rather than a callback because the same projection can run
|
|
6
|
+
* against a provider's live variant and against a stored theme during the
|
|
7
|
+
* pre-paint script. Explicit destination tokens always win.
|
|
8
|
+
*/
|
|
9
|
+
import { contrastRatio, parseColor } from './oklch.js'
|
|
10
|
+
import { repairToHex } from './render.js'
|
|
11
|
+
|
|
12
|
+
export type ThemeTokenContrastRule = Readonly<{
|
|
13
|
+
/** The custom property the generated foreground must read against. */
|
|
14
|
+
against: string
|
|
15
|
+
/** Minimum WCAG 2.1 contrast ratio for the generated value. */
|
|
16
|
+
minimum: number
|
|
17
|
+
}>
|
|
18
|
+
|
|
19
|
+
export type ThemeTokenProjectionRule = Readonly<{
|
|
20
|
+
/** Destination custom property; an explicit value is never replaced. */
|
|
21
|
+
target: string
|
|
22
|
+
/** Existing custom property to project when `target` is absent. */
|
|
23
|
+
source: string
|
|
24
|
+
/** Repair a generated destination when both source and surface are colours. */
|
|
25
|
+
contrast?: ThemeTokenContrastRule
|
|
26
|
+
}>
|
|
27
|
+
|
|
28
|
+
export type ThemeTokenProjection = readonly ThemeTokenProjectionRule[]
|
|
29
|
+
|
|
30
|
+
export type ThemeTokenProjectionFailure = Readonly<{
|
|
31
|
+
target: string
|
|
32
|
+
source: string
|
|
33
|
+
against: string
|
|
34
|
+
minimum: number
|
|
35
|
+
reason: 'unsupported_color' | 'contrast_unreachable'
|
|
36
|
+
}>
|
|
37
|
+
|
|
38
|
+
export type ThemeTokenProjectionResult = Readonly<{
|
|
39
|
+
tokens: Record<string, string>
|
|
40
|
+
failures: readonly ThemeTokenProjectionFailure[]
|
|
41
|
+
}>
|
|
42
|
+
|
|
43
|
+
const CUSTOM_PROPERTY = /^--[A-Za-z0-9_-]+$/
|
|
44
|
+
|
|
45
|
+
function validRule(rule: ThemeTokenProjectionRule): boolean {
|
|
46
|
+
if (!rule || typeof rule !== 'object' || Array.isArray(rule)) return false
|
|
47
|
+
const contrast = rule.contrast
|
|
48
|
+
return (
|
|
49
|
+
CUSTOM_PROPERTY.test(rule.target) &&
|
|
50
|
+
CUSTOM_PROPERTY.test(rule.source) &&
|
|
51
|
+
(contrast === undefined ||
|
|
52
|
+
(!!contrast &&
|
|
53
|
+
typeof contrast === 'object' &&
|
|
54
|
+
CUSTOM_PROPERTY.test(contrast.against) &&
|
|
55
|
+
Number.isFinite(contrast.minimum) &&
|
|
56
|
+
contrast.minimum > 1 &&
|
|
57
|
+
contrast.minimum <= 21))
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function hasUnsupportedAlpha(value: string): boolean {
|
|
62
|
+
return /^oklch\([^)]*\/[^)]*\)$/i.test(value.trim())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function repairGeneratedValue(
|
|
66
|
+
value: string,
|
|
67
|
+
against: string,
|
|
68
|
+
minimum: number
|
|
69
|
+
): { value: string; failure?: ThemeTokenProjectionFailure['reason'] } {
|
|
70
|
+
if (hasUnsupportedAlpha(value) || hasUnsupportedAlpha(against)) {
|
|
71
|
+
return { value, failure: 'unsupported_color' }
|
|
72
|
+
}
|
|
73
|
+
const foreground = parseColor(value)
|
|
74
|
+
const background = parseColor(against)
|
|
75
|
+
if (!foreground || !background) return { value, failure: 'unsupported_color' }
|
|
76
|
+
if (contrastRatio(foreground, background) >= minimum) return { value }
|
|
77
|
+
|
|
78
|
+
const repaired = repairToHex(foreground, background, minimum, 0.6)
|
|
79
|
+
return repaired ? { value: repaired } : { value, failure: 'contrast_unreachable' }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Add projected values for absent custom properties, leaving explicit values byte
|
|
84
|
+
* for byte intact. Rules run in order so one generated surface can anchor its text.
|
|
85
|
+
* Unknown or malformed rules and unparseable colors fail closed by skipping repair.
|
|
86
|
+
*/
|
|
87
|
+
export function projectThemeTokensDetailed(
|
|
88
|
+
tokens: Readonly<Record<string, string>>,
|
|
89
|
+
projection: ThemeTokenProjection
|
|
90
|
+
): ThemeTokenProjectionResult {
|
|
91
|
+
const projected = { ...tokens }
|
|
92
|
+
const failures: ThemeTokenProjectionFailure[] = []
|
|
93
|
+
|
|
94
|
+
for (const rule of Array.isArray(projection) ? projection : []) {
|
|
95
|
+
if (!validRule(rule) || Object.hasOwn(projected, rule.target)) continue
|
|
96
|
+
const value = projected[rule.source]
|
|
97
|
+
if (typeof value !== 'string') continue
|
|
98
|
+
if (!rule.contrast) {
|
|
99
|
+
projected[rule.target] = value
|
|
100
|
+
continue
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const against = projected[rule.contrast.against] ?? ''
|
|
104
|
+
const result = repairGeneratedValue(value, against, rule.contrast.minimum)
|
|
105
|
+
projected[rule.target] = result.value
|
|
106
|
+
if (result.failure) {
|
|
107
|
+
failures.push({
|
|
108
|
+
target: rule.target,
|
|
109
|
+
source: rule.source,
|
|
110
|
+
against: rule.contrast.against,
|
|
111
|
+
minimum: rule.contrast.minimum,
|
|
112
|
+
reason: result.failure,
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { tokens: projected, failures }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Project tokens while discarding diagnostics for callers that only paint them. */
|
|
121
|
+
export function projectThemeTokens(
|
|
122
|
+
tokens: Readonly<Record<string, string>>,
|
|
123
|
+
projection: ThemeTokenProjection
|
|
124
|
+
): Record<string, string> {
|
|
125
|
+
return projectThemeTokensDetailed(tokens, projection).tokens
|
|
126
|
+
}
|
package/src/validate.ts
CHANGED
|
@@ -32,7 +32,7 @@ import type { AdeaTheme, AnsiKey, ThemeColorKey } from './schema.js'
|
|
|
32
32
|
import { ANSI_KEYS, THEME_COLOR_KEYS } from './schema.js'
|
|
33
33
|
import type { Oklch } from './oklch.js'
|
|
34
34
|
import { contrastRatio, deltaEok, parseColor } from './oklch.js'
|
|
35
|
-
import { CONTRAST_FLOORS } from './policy.js'
|
|
35
|
+
import { CONTRAST_FLOORS, clearsFloor } from './policy.js'
|
|
36
36
|
import { STATUS_ROLES, statusForeground } from './derive.js'
|
|
37
37
|
|
|
38
38
|
/** One measured pairing that failed. */
|
|
@@ -48,29 +48,26 @@ export interface ContrastFinding {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* Declared as data rather than as a sequence of assertions so that the set is
|
|
54
|
-
* reviewable in one place, and so a consumer can see exactly what is guaranteed.
|
|
55
|
-
* `background` appears as the counterpart almost everywhere because a component's
|
|
56
|
-
* default surface is the canvas; the two exceptions are the pairs drawn on a
|
|
57
|
-
* raised surface or on the accent.
|
|
51
|
+
* One guaranteed pairing: `role` clears `minimum` against each of `against`.
|
|
58
52
|
*/
|
|
59
53
|
export interface Pairing {
|
|
60
54
|
role: ThemeColorKey | AnsiKey | 'accentForeground' | 'border' | 'borderMuted' | 'selection'
|
|
61
55
|
against: readonly (ThemeColorKey | 'background' | 'accent')[]
|
|
62
56
|
minimum: number
|
|
63
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Marks a pairing as advisory. No built-in pairing sets it, and `validateTheme`
|
|
59
|
+
* reports its findings like any other.
|
|
60
|
+
*/
|
|
64
61
|
advisory?: boolean
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
/**
|
|
68
65
|
* Every pairing the catalogue guarantees.
|
|
69
66
|
*
|
|
70
|
-
* `textSubtle`
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
67
|
+
* `textSubtle` is held to 3:1 rather than 4.5:1 — see the schema's note on it.
|
|
68
|
+
* That is not a relaxation for convenience: at 4.5:1 there is no visible
|
|
69
|
+
* difference between tertiary and secondary text and the role stops earning its
|
|
70
|
+
* place in the schema.
|
|
74
71
|
*/
|
|
75
72
|
export const REQUIRED_PAIRINGS: readonly Pairing[] = Object.freeze([
|
|
76
73
|
{ role: 'text', against: ['background'], minimum: CONTRAST_FLOORS.text },
|
|
@@ -101,7 +98,7 @@ export const REQUIRED_PAIRINGS: readonly Pairing[] = Object.freeze([
|
|
|
101
98
|
*
|
|
102
99
|
* Two tiers, matching the normalizer: the body floor on the canvas, where a status
|
|
103
100
|
* colour is read as small text, and the indicator floor on a raised surface. The
|
|
104
|
-
* reasoning is in `
|
|
101
|
+
* reasoning is in `CONTRAST_FLOORS.statusRaised`.
|
|
105
102
|
*/
|
|
106
103
|
export const STATUS_PAIRINGS: readonly Pairing[] = Object.freeze([
|
|
107
104
|
...STATUS_ROLES.map((role) => ({
|
|
@@ -131,10 +128,8 @@ export const STATUS_PAIRINGS: readonly Pairing[] = Object.freeze([
|
|
|
131
128
|
*
|
|
132
129
|
* - **Collapse** — a ramp whose roles resolve to the same colour, which means the
|
|
133
130
|
* theme cannot express dim text at all.
|
|
134
|
-
* - **Inversion** — an ANSI black lighter than its
|
|
135
|
-
*
|
|
136
|
-
* normalizer's ramp logic was rewritten to avoid, and the one a palette with a
|
|
137
|
-
* degenerate `base05`/`base06`/`base07` produces.
|
|
131
|
+
* - **Inversion** — an ANSI bright black no lighter than its black, in either
|
|
132
|
+
* appearance.
|
|
138
133
|
*/
|
|
139
134
|
export interface AnsiInvariant {
|
|
140
135
|
themeId: string
|
|
@@ -147,8 +142,6 @@ export function checkAnsiRamp(theme: AdeaTheme): AnsiInvariant[] {
|
|
|
147
142
|
const findings: AnsiInvariant[] = []
|
|
148
143
|
const black = parseColor(theme.ansi.black)
|
|
149
144
|
const brightBlack = parseColor(theme.ansi.brightBlack)
|
|
150
|
-
const white = parseColor(theme.ansi.white)
|
|
151
|
-
const brightWhite = parseColor(theme.ansi.brightWhite)
|
|
152
145
|
|
|
153
146
|
if (black && brightBlack) {
|
|
154
147
|
if (deltaEok(black, brightBlack) < 0.02) {
|
|
@@ -175,15 +168,10 @@ export function checkAnsiRamp(theme: AdeaTheme): AnsiInvariant[] {
|
|
|
175
168
|
// own light theme uses, sets white to a mid grey and bright white darker still,
|
|
176
169
|
// and several palettes in the catalogue set the two to the same value. There is no
|
|
177
170
|
// invariant there — unlike ANSI 0/8, whose ordering holds in both appearances.
|
|
178
|
-
void white
|
|
179
|
-
void brightWhite
|
|
180
|
-
|
|
181
171
|
return findings
|
|
182
172
|
}
|
|
183
173
|
|
|
184
174
|
function resolve(theme: AdeaTheme, role: string): Oklch | undefined {
|
|
185
|
-
if (role === 'accent') return parseColor(theme.colors.accent)
|
|
186
|
-
if (role === 'background') return parseColor(theme.colors.background)
|
|
187
175
|
if ((THEME_COLOR_KEYS as readonly string[]).includes(role)) {
|
|
188
176
|
return parseColor(theme.colors[role as ThemeColorKey])
|
|
189
177
|
}
|
|
@@ -195,6 +183,11 @@ function resolve(theme: AdeaTheme, role: string): Oklch | undefined {
|
|
|
195
183
|
return undefined
|
|
196
184
|
}
|
|
197
185
|
|
|
186
|
+
/** A finding about a theme's shape rather than a measured pairing. */
|
|
187
|
+
function structural(themeId: string, role: string, message: string): ContrastFinding {
|
|
188
|
+
return { themeId, role, against: [], ratio: 0, minimum: 0, message }
|
|
189
|
+
}
|
|
190
|
+
|
|
198
191
|
/** Measures one pairing, returning a finding when it fails. */
|
|
199
192
|
function measure(theme: AdeaTheme, pairing: Pairing): ContrastFinding | undefined {
|
|
200
193
|
const subject = resolve(theme, pairing.role)
|
|
@@ -213,7 +206,7 @@ function measure(theme: AdeaTheme, pairing: Pairing): ContrastFinding | undefine
|
|
|
213
206
|
const counterpart = resolve(theme, counterpartName)
|
|
214
207
|
if (!counterpart) continue
|
|
215
208
|
const ratio = contrastRatio(subject, counterpart)
|
|
216
|
-
if (ratio
|
|
209
|
+
if (!clearsFloor(ratio, pairing.minimum)) {
|
|
217
210
|
return {
|
|
218
211
|
themeId: theme.id,
|
|
219
212
|
role: pairing.role,
|
|
@@ -244,42 +237,37 @@ export function validateTheme(theme: AdeaTheme): ContrastFinding[] {
|
|
|
244
237
|
if (finding) findings.push(finding)
|
|
245
238
|
}
|
|
246
239
|
|
|
247
|
-
// Some roles are not used in contrast pairings, but still leave the package
|
|
248
|
-
// through adapters and must be valid colours at this public validation boundary.
|
|
249
240
|
for (const role of [...THEME_COLOR_KEYS, ...ANSI_KEYS, 'cursor', 'selection']) {
|
|
250
241
|
if (resolve(theme, role) || findings.some((finding) => finding.role === role)) continue
|
|
251
|
-
findings.push({
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
242
|
+
findings.push(structural(theme.id, role, `${role} is missing or is not a colour`))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Canonical colours are measured as opaque, and adapters such as CSS emit the
|
|
246
|
+
// original value. A translucent value's contrast depends on its backdrop, so
|
|
247
|
+
// those measurements cannot guarantee the published floors. Source-specific
|
|
248
|
+
// shadcn projections are separate and may deliberately contain alpha.
|
|
249
|
+
for (const [role, value] of [
|
|
250
|
+
...THEME_COLOR_KEYS.map((key) => [key, theme.colors[key]] as const),
|
|
251
|
+
...ANSI_KEYS.map((key) => [key, theme.ansi[key]] as const),
|
|
252
|
+
['cursor', theme.cursor] as const,
|
|
253
|
+
['selection', theme.selection] as const,
|
|
254
|
+
]) {
|
|
255
|
+
if (typeof value !== 'string' || !parseColor(value)) continue
|
|
256
|
+
const alpha = /\/\s*([\d.]+)(%)?\s*\)$/i.exec(value.trim())
|
|
257
|
+
if (!alpha || Number(alpha[1]) >= (alpha[2] ? 100 : 1)) continue
|
|
258
|
+
findings.push(structural(theme.id, role, `${role} must be opaque for contrast validation`))
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
// The greyscale ramp's failures are structural rather than contrast-based, so
|
|
262
|
-
// they are reported as findings with no ratio.
|
|
263
261
|
for (const invariant of checkAnsiRamp(theme)) {
|
|
264
|
-
findings.push(
|
|
265
|
-
themeId: invariant.themeId,
|
|
266
|
-
role: invariant.role,
|
|
267
|
-
against: [],
|
|
268
|
-
ratio: 0,
|
|
269
|
-
minimum: 0,
|
|
270
|
-
message: invariant.message,
|
|
271
|
-
})
|
|
262
|
+
findings.push(structural(invariant.themeId, invariant.role, invariant.message))
|
|
272
263
|
}
|
|
273
264
|
|
|
274
|
-
// The status foreground pairing cannot be declared as a table entry because it
|
|
275
|
-
// depends on the theme: the correct colour is whichever extreme of the theme
|
|
276
|
-
// measures better, so it is derived and then measured rather than named.
|
|
277
265
|
for (const role of STATUS_ROLES) {
|
|
278
266
|
const fill = parseColor(theme.colors[role])
|
|
279
267
|
const chosen = parseColor(statusForeground(theme, role))
|
|
280
268
|
if (!fill || !chosen) continue
|
|
281
269
|
const ratio = contrastRatio(chosen, fill)
|
|
282
|
-
if (ratio
|
|
270
|
+
if (!clearsFloor(ratio, CONTRAST_FLOORS.accentForeground)) {
|
|
283
271
|
findings.push({
|
|
284
272
|
themeId: theme.id,
|
|
285
273
|
role: `${role}-foreground`,
|
|
@@ -308,14 +296,7 @@ export function validateCatalogue(themes: readonly AdeaTheme[]): ContrastFinding
|
|
|
308
296
|
const ids = new Set<string>()
|
|
309
297
|
for (const theme of themes) {
|
|
310
298
|
if (ids.has(theme.id)) {
|
|
311
|
-
findings.push({
|
|
312
|
-
themeId: theme.id,
|
|
313
|
-
role: 'id',
|
|
314
|
-
against: [],
|
|
315
|
-
ratio: 0,
|
|
316
|
-
minimum: 0,
|
|
317
|
-
message: `duplicate theme id: ${theme.id}`,
|
|
318
|
-
})
|
|
299
|
+
findings.push(structural(theme.id, 'id', `duplicate theme id: ${theme.id}`))
|
|
319
300
|
}
|
|
320
301
|
ids.add(theme.id)
|
|
321
302
|
findings.push(...validateTheme(theme))
|
|
@@ -324,14 +305,13 @@ export function validateCatalogue(themes: readonly AdeaTheme[]): ContrastFinding
|
|
|
324
305
|
const light = themes.filter((theme) => theme.appearance === 'light').length
|
|
325
306
|
const dark = themes.filter((theme) => theme.appearance === 'dark').length
|
|
326
307
|
if (light === 0 || dark === 0) {
|
|
327
|
-
findings.push(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
})
|
|
308
|
+
findings.push(
|
|
309
|
+
structural(
|
|
310
|
+
'catalogue',
|
|
311
|
+
'appearance',
|
|
312
|
+
`catalogue covers ${light} light and ${dark} dark themes; both appearances must be represented`
|
|
313
|
+
)
|
|
314
|
+
)
|
|
335
315
|
}
|
|
336
316
|
|
|
337
317
|
return findings
|