@taprootio/site-authoring 0.41.1 → 0.55.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/README.md +50 -0
- package/examples/riverbend-wellness/settings/site-publishing-preferences.json +3 -0
- package/examples/riverbend-wellness/settings/taproot-styles.json +11 -0
- package/package.json +4 -3
- package/src/api.js +170 -11
- package/src/appearance-contract.js +278 -8
- package/src/authored-tag-names.js +88 -0
- package/src/block-flow.js +103 -1
- package/src/brand-color.js +39 -4
- package/src/breadcrumb-artwork.js +234 -0
- package/src/breadcrumb-separators.js +11 -0
- package/src/changelog.json +154 -0
- package/src/chrome-features.js +152 -0
- package/src/chrome-input.js +147 -0
- package/src/chrome-output.js +92 -0
- package/src/chrome-paint-catalog-taproot.json +52 -0
- package/src/chrome-report.js +173 -0
- package/src/cli.js +48 -17
- package/src/content/components.js +27 -4
- package/src/content/external-link.js +2 -1
- package/src/content/markdown.js +271 -101
- package/src/content/tiptap-prosemirror.ts +125 -43
- package/src/content/validate-document.js +4 -1
- package/src/content-inset.js +48 -0
- package/src/errors.js +1 -0
- package/src/espalier-shared.js +26 -0
- package/src/field-suggestions.js +40 -0
- package/src/fixture-init.js +22 -5
- package/src/font-catalog.js +11 -1
- package/src/footer-brand-inputs.js +25 -2
- package/src/footer-content.js +38 -0
- package/src/footer-contract.js +11 -0
- package/src/footer-cta-styles.js +6 -0
- package/src/footer-draft-hash.js +4 -2
- package/src/footer-fit.js +62 -15
- package/src/footer-workspace.js +60 -16
- package/src/header-presentation.js +16 -0
- package/src/latest-posts-tags.js +57 -0
- package/src/page-structure-checks.js +5 -0
- package/src/page-tag-badge-modes.js +6 -0
- package/src/page-tag-writes.js +158 -0
- package/src/page-type-tags.js +16 -0
- package/src/presentation-reference.js +312 -86
- package/src/recipe-page-options.js +22 -0
- package/src/recipe-step-contract.js +164 -0
- package/src/recipe-step-contract.json +65 -0
- package/src/reference-help.js +164 -78
- package/src/session.js +39 -24
- package/src/setting-reference.js +239 -48
- package/src/settings-catalog.js +63 -0
- package/src/site-check-findings.js +25 -5
- package/src/site-check-rules.json +3 -1
- package/src/site-health-findings.js +13 -13
- package/src/site-navigation-groups.js +70 -0
- package/src/styling-fixed-values.js +71 -0
- package/src/tag-destination-warnings.js +35 -0
- package/src/template-token-reach.json +242 -0
- package/src/theme-proposals.js +18 -27
- package/src/theme-resolve.js +305 -51
- package/src/theme-validation.js +126 -6
- package/src/token-reach.js +222 -0
- package/src/typed-page-reference.js +72 -15
- package/src/typed-pages.js +171 -71
- package/src/verbs/deploy.js +6 -0
- package/src/verbs/footer-push.js +30 -5
- package/src/verbs/forms-push.js +11 -3
- package/src/verbs/pages-delete.js +19 -10
- package/src/verbs/pages-push.js +125 -36
- package/src/verbs/plan.js +10 -4
- package/src/verbs/pull.js +277 -67
- package/src/verbs/staging-review.js +27 -1
- package/src/verbs/status.js +22 -0
- package/src/verbs/theme-push.js +249 -120
- package/src/verbs/theme-resolve.js +310 -47
- package/src/verbs/validate.js +71 -17
- package/src/workspace-check.js +37 -4
- package/src/workspace.js +37 -1
- package/test/fixtures/default-site-theme.json +516 -0
package/src/theme-resolve.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AA_LARGE_RATIO,
|
|
3
|
+
AA_TEXT_RATIO,
|
|
4
|
+
DEFAULT_DARK_THEME,
|
|
5
|
+
DEFAULT_LIGHT_THEME,
|
|
6
|
+
LIGHTNESS_KEYS,
|
|
7
|
+
mergeTheme,
|
|
8
|
+
parseTheme,
|
|
9
|
+
resolveContextTheme,
|
|
10
|
+
SEMANTIC_COLOR_NAMES,
|
|
11
|
+
TOKEN_PAIRINGS,
|
|
12
|
+
wcagRatio,
|
|
13
|
+
} from "@taprootio/espalier/shared/theme";
|
|
2
14
|
|
|
15
|
+
import { CHROME_NAVIGATION_UNAVAILABLE_MESSAGE } from "./chrome-input.js";
|
|
16
|
+
import { CHROME_UNAVAILABLE_MESSAGE, decodeChromePair, floorTo } from "./chrome-output.js";
|
|
3
17
|
import { SiteAuthoringError } from "./errors.js";
|
|
4
18
|
import { loadEspalierShared } from "./espalier-shared.js";
|
|
19
|
+
import { pinnedTheme } from "./theme-proposals.js";
|
|
5
20
|
import { validateAndEncodeThemePair } from "./theme-validation.js";
|
|
21
|
+
import { formatTokenPaints, getTokenDerivation } from "./token-reach.js";
|
|
6
22
|
|
|
7
23
|
/**
|
|
8
24
|
* `theme resolve` (TR01228): the colors Espalier compiles from a stored theme,
|
|
9
25
|
* with the contrast of every ink-on-surface pairing it defines.
|
|
10
26
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* and `resolveContextTheme` for each context), so a resolved value cannot
|
|
14
|
-
* disagree with the render. This module only reads that result and measures
|
|
15
|
-
* it.
|
|
27
|
+
* The fit report suite uses the same compiler as the page. The raw trace from
|
|
28
|
+
* that compiler gives the pre-fit APCA measurements and verifies passing stops.
|
|
16
29
|
*/
|
|
17
30
|
|
|
18
31
|
export const THEME_STYLES_FILE = "settings/taproot-styles.json";
|
|
@@ -20,17 +33,16 @@ export const THEME_STYLES_FILE = "settings/taproot-styles.json";
|
|
|
20
33
|
// WCAG 2.x AA. Espalier sizes its pairings by APCA target: Lc 90 and 75 are
|
|
21
34
|
// body and 16px+ text, Lc 60 is the 24px+ and UI tier, which is what AA calls
|
|
22
35
|
// large text and non-text contrast.
|
|
23
|
-
export const AA_TEXT_RATIO = 4.5;
|
|
24
|
-
export const AA_LARGE_RATIO = 3;
|
|
25
36
|
const LARGE_TEXT_LC = 60;
|
|
26
37
|
|
|
27
38
|
export const CONTRAST_TEXT_BELOW_AA = "theme.contrast_text_below_aa";
|
|
28
39
|
|
|
29
40
|
const THEME_SCHEMES = Object.freeze(["light", "dark"]);
|
|
41
|
+
const THEME_DEFAULTS = Object.freeze({ light: DEFAULT_LIGHT_THEME, dark: DEFAULT_DARK_THEME });
|
|
30
42
|
|
|
31
43
|
let engines;
|
|
44
|
+
let traceCompiler;
|
|
32
45
|
|
|
33
|
-
/** The fit report and color engine are Espalier modules beside the exported theme module (see espalier-shared.js). */
|
|
34
46
|
export function loadThemeEngines() {
|
|
35
47
|
engines ??= Promise.all([
|
|
36
48
|
loadEspalierShared("theme-fit-report.js"),
|
|
@@ -39,36 +51,24 @@ export function loadThemeEngines() {
|
|
|
39
51
|
return engines;
|
|
40
52
|
}
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
/** Only adjusted colors need the exact Espalier pin's raw compiler trace. */
|
|
55
|
+
export function loadThemeTraceCompiler() {
|
|
56
|
+
traceCompiler ??= loadEspalierShared("../root/helpers/compute-theme-properties.js")
|
|
57
|
+
.then(({ computeThemeProperties }) => computeThemeProperties);
|
|
58
|
+
return traceCompiler;
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
/** The sRGB the engine gamut-maps a compiled color to, as channels in 0..1 and as #rrggbb. */
|
|
47
62
|
function toSrgb(color, value) {
|
|
48
63
|
const parsed = color.parseCssColor(value);
|
|
49
64
|
if (parsed === null) return undefined;
|
|
50
|
-
const
|
|
51
|
-
const
|
|
65
|
+
const mapped = color.oklchToSRGB(color.gamutMapToSRGB(parsed));
|
|
66
|
+
const srgb = { r: color.clampChannel(mapped.r), g: color.clampChannel(mapped.g), b: color.clampChannel(mapped.b) };
|
|
67
|
+
const hex = `#${[srgb.r, srgb.g, srgb.b].map((channel) => Math.round(channel * 255).toString(16).padStart(2, "0")).join("")}`;
|
|
52
68
|
return { parsed, srgb, hex };
|
|
53
69
|
}
|
|
54
70
|
|
|
55
|
-
|
|
56
|
-
const linear = (channel) => color.gammaToLinear(color.clampChannel(channel));
|
|
57
|
-
return 0.2126 * linear(srgb.r) + 0.7152 * linear(srgb.g) + 0.0722 * linear(srgb.b);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** WCAG contrast ratio of two compiled colors, unrounded. */
|
|
61
|
-
function wcagRatio(color, first, second) {
|
|
62
|
-
const [lighter, darker] = [relativeLuminance(color, first.srgb), relativeLuminance(color, second.srgb)]
|
|
63
|
-
.sort((left, right) => right - left);
|
|
64
|
-
return (lighter + 0.05) / (darker + 0.05);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Shown ratios round down, so a pair 0.004 short of AA never displays as 4.50.
|
|
68
|
-
function floorTo(value, places) {
|
|
69
|
-
const scale = 10 ** places;
|
|
70
|
-
return Math.floor(value * scale + 1e-9) / scale;
|
|
71
|
-
}
|
|
71
|
+
export { floorTo } from "./chrome-output.js";
|
|
72
72
|
|
|
73
73
|
function origin(token) {
|
|
74
74
|
if (token.explicit === "declared") return "pinned";
|
|
@@ -103,12 +103,73 @@ function contrastFlag(pair, scheme, context) {
|
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function
|
|
107
|
-
|
|
106
|
+
function measureLc(color, foreground, background) {
|
|
107
|
+
return Math.abs(color.apcaContrast(foreground, background));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function emittedLc(color, foreground, background) {
|
|
111
|
+
return measureLc(color, color.parseOklch(foreground), color.parseOklch(background));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function describeTokenContrast(color, token, raw) {
|
|
115
|
+
const { requested, resolved, apca: { against, againstColor, targetLc }, anchor } = token;
|
|
116
|
+
return {
|
|
117
|
+
requested,
|
|
118
|
+
resolved,
|
|
119
|
+
against,
|
|
120
|
+
againstColor,
|
|
121
|
+
targetLc,
|
|
122
|
+
requestedLc: measureLc(color, raw.requested, raw.contrast.background),
|
|
123
|
+
resolvedLc: emittedLc(color, resolved, againstColor),
|
|
124
|
+
...(anchor === undefined ? {} : { reference: anchor.reference, deltaE: anchor.deltaE }),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function traceSurface(computeThemeProperties, theme, scheme, footerTrace) {
|
|
129
|
+
const trace = [];
|
|
130
|
+
computeThemeProperties(theme, scheme, trace, undefined, undefined, footerTrace);
|
|
131
|
+
return new Map(trace.map((entry) => [entry.token, entry]));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function effectiveSurface(theme, context) {
|
|
135
|
+
return context === null ? theme : resolveContextTheme(theme, context);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function candidateStops(effective) {
|
|
139
|
+
return LIGHTNESS_KEYS.map((stop) => ({ stop, lightness: effective.lightness[stop] }));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function passingStopFieldBytes(stop) {
|
|
143
|
+
// Adding a field takes one comma and all of its object body bytes.
|
|
144
|
+
return Buffer.byteLength(JSON.stringify({ passingStop: stop }), "utf8") - 1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function nearestPassingStop({ fit, color }, theme, effective, stops, scheme, context, token, trace, footer = false) {
|
|
148
|
+
const { base, requested: { l: requestedL }, contrast: { background, targetLc } } = trace;
|
|
149
|
+
const { min, max } = effective.chroma[token.token];
|
|
150
|
+
const emittedBackground = color.serializeOklch(background);
|
|
151
|
+
// Equal distances keep ramp order.
|
|
152
|
+
const ordered = [...stops].sort((left, right) => Math.abs(left.lightness - requestedL) - Math.abs(right.lightness - requestedL));
|
|
153
|
+
for (const candidate of ordered) {
|
|
154
|
+
const requested = color.deriveSemantic(base, candidate.lightness, min, max);
|
|
155
|
+
if (measureLc(color, requested, background) < targetLc) continue;
|
|
156
|
+
if (emittedLc(color, color.serializeOklch(requested), emittedBackground) < targetLc) continue;
|
|
157
|
+
const mapping = { source: token.source, lightness: candidate.stop };
|
|
158
|
+
const patched = mergeTheme(THEME_DEFAULTS[scheme], pinnedTheme(theme, context, token.token, mapping));
|
|
159
|
+
const report = fit.themeFitReport(patched, scheme, { context: context ?? undefined });
|
|
160
|
+
const fitted = (footer ? report.footerTokens : report.tokens).find((entry) => entry.token === token.token);
|
|
161
|
+
if (fitted.explicit !== "declared" || fitted.adjusted) continue;
|
|
162
|
+
if (emittedLc(color, fitted.resolved, fitted.apca.againstColor) >= fitted.apca.targetLc) return candidate;
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function describeSurface(color, report, scheme, context, trace) {
|
|
108
168
|
const resolved = new Map();
|
|
109
169
|
const tokens = report.tokens.map((token) => {
|
|
110
170
|
const measured = toSrgb(color, token.resolved);
|
|
111
171
|
resolved.set(token.token, measured);
|
|
172
|
+
const derivation = getTokenDerivation(token.token);
|
|
112
173
|
return {
|
|
113
174
|
token: token.token,
|
|
114
175
|
value: token.resolved,
|
|
@@ -116,8 +177,11 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
116
177
|
origin: origin(token),
|
|
117
178
|
source: token.source,
|
|
118
179
|
lightness: token.lightness,
|
|
119
|
-
|
|
120
|
-
...(token.adjusted ? {
|
|
180
|
+
derivesFrom: derivation === null ? null : { role: derivation.role, slot: derivation.slot },
|
|
181
|
+
...(token.adjusted ? {
|
|
182
|
+
adjusted: true,
|
|
183
|
+
contrast: describeTokenContrast(color, token, trace.get(token.token)),
|
|
184
|
+
} : {}),
|
|
121
185
|
};
|
|
122
186
|
});
|
|
123
187
|
const pairs = [];
|
|
@@ -126,8 +190,8 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
126
190
|
const background = resolved.get(pairing.bg);
|
|
127
191
|
if (foreground === undefined || background === undefined) continue;
|
|
128
192
|
const required = pairing.targetLc <= LARGE_TEXT_LC ? AA_LARGE_RATIO : AA_TEXT_RATIO;
|
|
129
|
-
const ratio = wcagRatio(
|
|
130
|
-
const lc =
|
|
193
|
+
const ratio = wcagRatio(foreground.srgb, background.srgb);
|
|
194
|
+
const lc = measureLc(color, foreground.parsed, background.parsed);
|
|
131
195
|
pairs.push({
|
|
132
196
|
token: ink,
|
|
133
197
|
background: pairing.bg,
|
|
@@ -141,7 +205,13 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
141
205
|
}
|
|
142
206
|
const flags = pairs.filter((pair) => !pair.aa).map((pair) => contrastFlag(pair, scheme, context));
|
|
143
207
|
return {
|
|
144
|
-
surface: {
|
|
208
|
+
surface: {
|
|
209
|
+
context,
|
|
210
|
+
tokens,
|
|
211
|
+
pairs,
|
|
212
|
+
pinned: tokens.filter((token) => token.origin !== "compiled").map((token) => token.token),
|
|
213
|
+
componentProperties: report.componentProperties,
|
|
214
|
+
},
|
|
145
215
|
flags,
|
|
146
216
|
};
|
|
147
217
|
}
|
|
@@ -154,11 +224,16 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
154
224
|
* Throws what `theme push` would throw for an incomplete or invalid theme, and
|
|
155
225
|
* a `theme.context_unknown` refusal for a context the theme does not declare.
|
|
156
226
|
*/
|
|
157
|
-
export async function resolveThemePair(lightTheme, darkTheme, {
|
|
158
|
-
|
|
159
|
-
|
|
227
|
+
export async function resolveThemePair(lightTheme, darkTheme, {
|
|
228
|
+
scheme, context, footerContext, deferPassingStops = false,
|
|
229
|
+
} = {}) {
|
|
230
|
+
const encoded = validateAndEncodeThemePair(lightTheme, darkTheme);
|
|
231
|
+
const { light, dark } = encoded;
|
|
232
|
+
const themeEngines = await loadThemeEngines();
|
|
233
|
+
const { fit, color } = themeEngines;
|
|
160
234
|
// The stored pair is encoded and parsed back, as theme push's fit lints do, so this is what the page resolves.
|
|
161
|
-
const
|
|
235
|
+
const themes = { light: parseTheme(light) ?? {}, dark: parseTheme(dark) ?? {} };
|
|
236
|
+
const suite = fit.themeFitReportSuite(themes.light, themes.dark);
|
|
162
237
|
const contexts = suite.surfaces.filter((surface) => surface !== fit.ROOT_SURFACE);
|
|
163
238
|
if (context !== undefined && !contexts.includes(context)) {
|
|
164
239
|
throw new SiteAuthoringError(
|
|
@@ -170,21 +245,79 @@ export async function resolveThemePair(lightTheme, darkTheme, { scheme, context
|
|
|
170
245
|
);
|
|
171
246
|
}
|
|
172
247
|
|
|
248
|
+
const details = new WeakMap();
|
|
249
|
+
// The verb checks the preliminary surface against its budget before fitting candidates.
|
|
250
|
+
function enrichSurface(name, surface) {
|
|
251
|
+
const detail = details.get(surface);
|
|
252
|
+
if (detail === undefined) return surface;
|
|
253
|
+
detail.complete ??= {
|
|
254
|
+
...surface,
|
|
255
|
+
tokens: surface.tokens.map((token) => token.adjusted ? {
|
|
256
|
+
...token,
|
|
257
|
+
contrast: {
|
|
258
|
+
...token.contrast,
|
|
259
|
+
passingStop: nearestPassingStop(
|
|
260
|
+
themeEngines, themes[name], detail.effective, detail.stops, name, surface.context, token,
|
|
261
|
+
detail.trace.get(token.token),
|
|
262
|
+
),
|
|
263
|
+
},
|
|
264
|
+
} : token),
|
|
265
|
+
...(surface.footerInks ? {
|
|
266
|
+
footerInks: surface.footerInks.map(ink => ink.adjusted ? {
|
|
267
|
+
...ink,
|
|
268
|
+
passingStop: nearestPassingStop(
|
|
269
|
+
themeEngines, themes[name], detail.effective, detail.stops, name, surface.context, ink,
|
|
270
|
+
detail.footerTrace.get(ink.token), true,
|
|
271
|
+
),
|
|
272
|
+
} : ink),
|
|
273
|
+
} : {}),
|
|
274
|
+
};
|
|
275
|
+
return detail.complete;
|
|
276
|
+
}
|
|
277
|
+
|
|
173
278
|
const schemes = [];
|
|
174
279
|
const flags = [];
|
|
280
|
+
let computeThemeProperties;
|
|
175
281
|
for (const name of THEME_SCHEMES) {
|
|
176
282
|
if (scheme !== undefined && scheme !== name) continue;
|
|
283
|
+
const root = mergeTheme(THEME_DEFAULTS[name], themes[name]);
|
|
177
284
|
const surfaces = [];
|
|
178
285
|
for (const report of suite[name]) {
|
|
179
286
|
if (context !== undefined && report.surface !== context) continue;
|
|
180
|
-
const
|
|
181
|
-
|
|
287
|
+
const contextName = report.surface === fit.ROOT_SURFACE ? null : report.surface;
|
|
288
|
+
const footerTokens = footerContext === contextName ? report.footerTokens : undefined;
|
|
289
|
+
const requiresTrace = report.adjustedTokens.length > 0 || footerTokens !== undefined;
|
|
290
|
+
const effective = requiresTrace ? effectiveSurface(root, contextName) : undefined;
|
|
291
|
+
const footerTrace = footerTokens === undefined ? undefined : [];
|
|
292
|
+
if (requiresTrace) computeThemeProperties ??= await loadThemeTraceCompiler();
|
|
293
|
+
const trace = requiresTrace ? traceSurface(computeThemeProperties, effective, name, footerTrace) : new Map();
|
|
294
|
+
const footers = new Map(footerTrace?.map(entry => [entry.token, entry]));
|
|
295
|
+
const described = describeSurface(color, report, name, contextName, trace);
|
|
296
|
+
if (footerTokens !== undefined) {
|
|
297
|
+
described.surface.footerInks = footerTokens.map(token => ({
|
|
298
|
+
token: token.token,
|
|
299
|
+
source: token.source,
|
|
300
|
+
lightness: token.lightness,
|
|
301
|
+
adjusted: token.adjusted,
|
|
302
|
+
...describeTokenContrast(color, token, footers.get(token.token)),
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
if (requiresTrace) {
|
|
306
|
+
const stops = candidateStops(effective);
|
|
307
|
+
const largestStop = Math.max(passingStopFieldBytes(null), ...stops.map(passingStopFieldBytes));
|
|
308
|
+
details.set(described.surface, {
|
|
309
|
+
effective, trace, stops, footerTrace: footers,
|
|
310
|
+
passingStopBytes: (report.adjustedTokens.length + (footerTokens?.filter(token => token.adjusted).length ?? 0))
|
|
311
|
+
* largestStop,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
surfaces.push(deferPassingStops ? described.surface : enrichSurface(name, described.surface));
|
|
182
315
|
flags.push(...described.flags);
|
|
183
316
|
}
|
|
184
317
|
schemes.push({ scheme: name, surfaces });
|
|
185
318
|
}
|
|
186
319
|
const pairs = schemes.flatMap((entry) => entry.surfaces).flatMap((surface) => surface.pairs);
|
|
187
|
-
return {
|
|
320
|
+
return Object.defineProperties({
|
|
188
321
|
contexts,
|
|
189
322
|
schemes,
|
|
190
323
|
flags,
|
|
@@ -193,7 +326,11 @@ export async function resolveThemePair(lightTheme, darkTheme, { scheme, context
|
|
|
193
326
|
belowAa: pairs.filter((pair) => !pair.aa).length,
|
|
194
327
|
belowApca: pairs.filter((pair) => !pair.apcaMet).length,
|
|
195
328
|
},
|
|
196
|
-
}
|
|
329
|
+
}, {
|
|
330
|
+
encoded: { value: encoded },
|
|
331
|
+
enrichSurface: { value: enrichSurface },
|
|
332
|
+
passingStopByteBound: { value: (surface) => details.get(surface)?.passingStopBytes ?? 0 },
|
|
333
|
+
});
|
|
197
334
|
}
|
|
198
335
|
|
|
199
336
|
const TOKEN_ORDER = new Map(SEMANTIC_COLOR_NAMES.map((name, index) => [name, index]));
|
|
@@ -207,6 +344,45 @@ function table(rows) {
|
|
|
207
344
|
return rows.map((row) => ` ${row.map((cell, column) => pad(cell, widths[column])).join(" ").trimEnd()}`).join("\n");
|
|
208
345
|
}
|
|
209
346
|
|
|
347
|
+
function formatComponentContrast({ apca, adjusted, targetLc }) {
|
|
348
|
+
if (apca === undefined) return "";
|
|
349
|
+
return `Lc ${floorTo(apca.fromLc, 1)} → ${floorTo(apca.toLc, 1)} (target ${targetLc}) on ${apca.against} `
|
|
350
|
+
+ `(${apca.againstColor}), ${adjusted ? "adjusted" : "unchanged"}`;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function displayLc(value, target) {
|
|
354
|
+
const shown = floorTo(value, 1);
|
|
355
|
+
return value < target && shown >= target ? target - 0.1 : shown;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function colorLightness(oklch) {
|
|
359
|
+
return oklch.slice("oklch(".length, oklch.indexOf(" "));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function formatTokenContrast({ token, contrast }, context) {
|
|
363
|
+
const { requested, resolved, against, targetLc, requestedLc, resolvedLc, passingStop } = contrast;
|
|
364
|
+
const ground = context === null ? against : `${context} ${against}`;
|
|
365
|
+
const renderedLightness = colorLightness(resolved);
|
|
366
|
+
const sentences = [
|
|
367
|
+
`${token} requested L ${colorLightness(requested)} reaches Lc ${displayLc(requestedLc, targetLc)} against ${ground}.`,
|
|
368
|
+
`Target Lc ${targetLc}.`,
|
|
369
|
+
`Renders at L ${renderedLightness}.`,
|
|
370
|
+
];
|
|
371
|
+
if (resolvedLc < targetLc) sentences.push(`Rendered contrast still falls short at Lc ${displayLc(resolvedLc, targetLc)}.`);
|
|
372
|
+
if (passingStop === null) {
|
|
373
|
+
if (resolvedLc >= targetLc) {
|
|
374
|
+
sentences.push(`Try a custom tone at L ${renderedLightness} and rerun theme resolve to verify the pin.`);
|
|
375
|
+
} else {
|
|
376
|
+
sentences.push("No named stop passes.");
|
|
377
|
+
}
|
|
378
|
+
} else if (passingStop !== undefined) sentences.push(`Pin lightness \`${passingStop.stop}\` to pass without a lift.`);
|
|
379
|
+
return sentences.join(" ");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function surfaceName(context) {
|
|
383
|
+
return context === null ? "page (root)" : `context ${context}`;
|
|
384
|
+
}
|
|
385
|
+
|
|
210
386
|
/**
|
|
211
387
|
* The human table for a result. Tokens keep Espalier's own order, so a
|
|
212
388
|
* background and its layers read together; a pinned or inherited value is
|
|
@@ -216,17 +392,27 @@ export function formatThemeResolve(result) {
|
|
|
216
392
|
const lines = [`Compiled colors from the ${result.source === "site" ? "site's" : "workspace"} theme.`];
|
|
217
393
|
for (const { scheme, surfaces } of result.schemes) {
|
|
218
394
|
for (const surface of surfaces) {
|
|
219
|
-
lines.push("", `${scheme} · ${surface.context
|
|
395
|
+
lines.push("", `${scheme} · ${surfaceName(surface.context)}`);
|
|
220
396
|
const tokens = [...surface.tokens].sort((left, right) => TOKEN_ORDER.get(left.token) - TOKEN_ORDER.get(right.token));
|
|
221
397
|
lines.push(table([
|
|
222
|
-
["token", "value", "hex", "from"],
|
|
398
|
+
["token", "value", "hex", "from", "static role plan"],
|
|
223
399
|
...tokens.map((token) => [
|
|
224
400
|
token.token,
|
|
225
401
|
token.value,
|
|
226
402
|
token.hex ?? "-",
|
|
227
403
|
`${token.origin === "compiled" ? "" : `${token.origin.replace("_", " ")}: `}${token.source} @ ${token.lightness}${token.adjusted ? " (adjusted for contrast)" : ""}`,
|
|
404
|
+
token.derivesFrom ? `${token.derivesFrom.role}.${token.derivesFrom.slot}` : "-",
|
|
228
405
|
]),
|
|
229
406
|
]));
|
|
407
|
+
const adjusted = tokens.filter((token) => token.contrast !== undefined);
|
|
408
|
+
for (const token of adjusted) lines.push(` ${formatTokenContrast(token, surface.context)}`);
|
|
409
|
+
for (const ink of surface.footerInks ?? []) {
|
|
410
|
+
lines.push(` ${formatTokenContrast({ token: "footer " + ink.token, contrast: ink }, surface.context)}`);
|
|
411
|
+
lines.push(` Requested ${ink.requested}. Rendered ${ink.resolved} at Lc ${displayLc(ink.resolvedLc, ink.targetLc)}.`);
|
|
412
|
+
}
|
|
413
|
+
if (surface.footerLinkOnLayer2) {
|
|
414
|
+
lines.push(" The site-chrome table shows resting footer links on layer2.");
|
|
415
|
+
}
|
|
230
416
|
lines.push("", table([
|
|
231
417
|
["ink", "on", "ratio", "needs", "apca", ""],
|
|
232
418
|
...surface.pairs.map((pair) => [
|
|
@@ -238,15 +424,83 @@ export function formatThemeResolve(result) {
|
|
|
238
424
|
pair.aa ? "ok" : "BELOW AA",
|
|
239
425
|
]),
|
|
240
426
|
]));
|
|
427
|
+
if (surface.badgePaint?.length) {
|
|
428
|
+
lines.push("", "Tag badges", table([
|
|
429
|
+
["element/state", "ink", "on", "ratio", "needs", ""],
|
|
430
|
+
...surface.badgePaint.map(pair => [
|
|
431
|
+
`${pair.element}/${pair.state}`, pair.foreground, pair.background,
|
|
432
|
+
`${pair.ratio.toFixed(2)}:1`, `${pair.required.toFixed(2)}:1`, pair.ratio < pair.required ? (pair.kind === "ring" ? "BELOW AA" : "LOW CONTRAST") : "ok",
|
|
433
|
+
]),
|
|
434
|
+
]));
|
|
435
|
+
}
|
|
436
|
+
if (surface.componentProperties.length > 0) {
|
|
437
|
+
lines.push("", "Component properties");
|
|
438
|
+
for (const property of surface.componentProperties) {
|
|
439
|
+
const override = property.overridesRoot ? "yes" : "no";
|
|
440
|
+
const contrast = formatComponentContrast(property);
|
|
441
|
+
lines.push(
|
|
442
|
+
` ${property.name}`,
|
|
443
|
+
` Authored ${JSON.stringify(property.authored)} → resolved ${property.resolved}. Root override ${override}.`,
|
|
444
|
+
);
|
|
445
|
+
if (contrast !== "") lines.push(` ${contrast}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
for (const [scheme, entries] of Object.entries(result.chrome ?? {})) {
|
|
451
|
+
for (const entry of entries) {
|
|
452
|
+
if (entry.pairs.length === 0) continue;
|
|
453
|
+
const location = entry.context === null ? "page (root)" : `context ${entry.context}${entry.contextTruncated ? "…" : ""}`;
|
|
454
|
+
lines.push("", `${scheme} · ${entry.role} · ${location}`);
|
|
455
|
+
lines.push(table([
|
|
456
|
+
["element/state", "ink", "on", "ratio", "needs", ""],
|
|
457
|
+
...entry.pairs.map((row) => {
|
|
458
|
+
const pair = decodeChromePair(result.chromeCatalog, row);
|
|
459
|
+
return [
|
|
460
|
+
`${pair.element}/${pair.state}`, pair.foreground, pair.background,
|
|
461
|
+
`${pair.ratio.toFixed(2)}:1`, `${pair.required.toFixed(2)}:1`,
|
|
462
|
+
pair.ratio < pair.required ? "BELOW AA" : "ok",
|
|
463
|
+
];
|
|
464
|
+
}),
|
|
465
|
+
]));
|
|
241
466
|
}
|
|
242
467
|
}
|
|
468
|
+
if (result.chromeUnavailable) lines.push("", CHROME_UNAVAILABLE_MESSAGE);
|
|
469
|
+
if (result.chromeNavigationUnavailable) lines.push("", CHROME_NAVIGATION_UNAVAILABLE_MESSAGE);
|
|
243
470
|
const { belowAa, pairs } = result.contrast;
|
|
471
|
+
const measured = result.chromeUnavailable ? " measured" : "";
|
|
472
|
+
const codes = [...new Set(result.flags.items.map((flag) => flag.code))];
|
|
473
|
+
const flags = codes.length > 0 ? ` (flags: ${codes.join(", ")})` : "";
|
|
244
474
|
lines.push("", belowAa === 0
|
|
245
|
-
? `All ${pairs} pairs meet WCAG AA.`
|
|
246
|
-
: `${belowAa} of ${pairs} pairs are below WCAG AA
|
|
475
|
+
? `All ${pairs}${measured} pairs meet WCAG AA.`
|
|
476
|
+
: `${belowAa} of ${pairs}${measured} pairs are below WCAG AA${flags}.`);
|
|
477
|
+
if (result.paintCatalog !== undefined) {
|
|
478
|
+
lines.push("", "What selected tokens paint", ...formatTokenPaints(result.tokens, result.paintCatalog));
|
|
479
|
+
}
|
|
480
|
+
if (result.omittedTokens?.length > 0) {
|
|
481
|
+
lines.push("", `Paint details omitted for ${result.omittedTokens.join(", ")}. See '${result.omittedTokensHelp}'.`);
|
|
482
|
+
}
|
|
247
483
|
if (result.omittedSurfaces !== undefined) {
|
|
248
|
-
const
|
|
249
|
-
|
|
484
|
+
const { items, count, oversizedCount = 0, retryRootSchemes = [], truncated } = result.omittedSurfaces;
|
|
485
|
+
const oversizedLabel = "too large under the narrowest selectors";
|
|
486
|
+
lines.push("", `Omitted surfaces (${count} total, ${oversizedCount} ${oversizedLabel})`);
|
|
487
|
+
for (const { scheme, context, reason } of items) {
|
|
488
|
+
const note = reason === "surface_too_large" ? ` [${oversizedLabel}]` : "";
|
|
489
|
+
lines.push(` ${scheme} · ${surfaceName(context)}${note}`);
|
|
490
|
+
}
|
|
491
|
+
if (truncated) lines.push(" Additional omitted surfaces exceed the name list budget.");
|
|
492
|
+
for (const scheme of retryRootSchemes) {
|
|
493
|
+
lines.push(`Use --scheme ${scheme} to view the omitted ${scheme} root page.`);
|
|
494
|
+
}
|
|
495
|
+
if (retryRootSchemes.length > 0) lines.push("A root retry keeps its scheme's named contexts and chrome.");
|
|
496
|
+
if (count > oversizedCount + retryRootSchemes.length) {
|
|
497
|
+
lines.push("Use --scheme and --context to view named contexts that fit when selected.");
|
|
498
|
+
lines.push("Read full names under lightTheme.contexts or darkTheme.contexts in settings/taproot-styles.json.");
|
|
499
|
+
if (result.source === "site") {
|
|
500
|
+
lines.push("Run taproot-site pull in a separate workspace for the same site to preserve local edits.");
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (oversizedCount > 0) lines.push("Shorten long component property values or context names to view oversized surfaces.");
|
|
250
504
|
}
|
|
251
505
|
return `${lines.join("\n")}\n`;
|
|
252
506
|
}
|