@taprootio/site-authoring 0.42.0 → 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 +32 -1
- 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 +161 -8
- package/src/appearance-contract.js +264 -3
- package/src/authored-tag-names.js +88 -0
- package/src/block-flow.js +103 -1
- package/src/brand-color.js +22 -0
- package/src/breadcrumb-artwork.js +234 -0
- package/src/breadcrumb-separators.js +11 -0
- package/src/changelog.json +143 -0
- package/src/chrome-features.js +6 -2
- package/src/chrome-input.js +1 -0
- package/src/chrome-paint-catalog-taproot.json +3 -3
- package/src/chrome-report.js +91 -12
- package/src/cli.js +45 -16
- 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 +22 -3
- package/src/footer-content.js +1 -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 +44 -7
- 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 +297 -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 +23 -5
- package/src/site-check-rules.json +1 -0
- package/src/site-health-findings.js +13 -13
- 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 +265 -23
- package/src/theme-validation.js +118 -7
- 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 +93 -25
- package/src/verbs/theme-resolve.js +189 -55
- package/src/verbs/validate.js +6 -5
- package/src/workspace-check.js +35 -3
- package/src/workspace.js +37 -1
- package/test/fixtures/default-site-theme.json +516 -0
package/src/theme-resolve.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AA_LARGE_RATIO,
|
|
3
3
|
AA_TEXT_RATIO,
|
|
4
|
+
DEFAULT_DARK_THEME,
|
|
5
|
+
DEFAULT_LIGHT_THEME,
|
|
6
|
+
LIGHTNESS_KEYS,
|
|
7
|
+
mergeTheme,
|
|
4
8
|
parseTheme,
|
|
9
|
+
resolveContextTheme,
|
|
5
10
|
SEMANTIC_COLOR_NAMES,
|
|
6
11
|
TOKEN_PAIRINGS,
|
|
7
12
|
wcagRatio,
|
|
@@ -11,17 +16,16 @@ import { CHROME_NAVIGATION_UNAVAILABLE_MESSAGE } from "./chrome-input.js";
|
|
|
11
16
|
import { CHROME_UNAVAILABLE_MESSAGE, decodeChromePair, floorTo } from "./chrome-output.js";
|
|
12
17
|
import { SiteAuthoringError } from "./errors.js";
|
|
13
18
|
import { loadEspalierShared } from "./espalier-shared.js";
|
|
19
|
+
import { pinnedTheme } from "./theme-proposals.js";
|
|
14
20
|
import { validateAndEncodeThemePair } from "./theme-validation.js";
|
|
21
|
+
import { formatTokenPaints, getTokenDerivation } from "./token-reach.js";
|
|
15
22
|
|
|
16
23
|
/**
|
|
17
24
|
* `theme resolve` (TR01228): the colors Espalier compiles from a stored theme,
|
|
18
25
|
* with the contrast of every ink-on-surface pairing it defines.
|
|
19
26
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and `resolveContextTheme` for each context), so a resolved value cannot
|
|
23
|
-
* disagree with the render. This module only reads that result and measures
|
|
24
|
-
* 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.
|
|
25
29
|
*/
|
|
26
30
|
|
|
27
31
|
export const THEME_STYLES_FILE = "settings/taproot-styles.json";
|
|
@@ -34,10 +38,11 @@ const LARGE_TEXT_LC = 60;
|
|
|
34
38
|
export const CONTRAST_TEXT_BELOW_AA = "theme.contrast_text_below_aa";
|
|
35
39
|
|
|
36
40
|
const THEME_SCHEMES = Object.freeze(["light", "dark"]);
|
|
41
|
+
const THEME_DEFAULTS = Object.freeze({ light: DEFAULT_LIGHT_THEME, dark: DEFAULT_DARK_THEME });
|
|
37
42
|
|
|
38
43
|
let engines;
|
|
44
|
+
let traceCompiler;
|
|
39
45
|
|
|
40
|
-
/** The fit report and color engine are Espalier modules beside the exported theme module (see espalier-shared.js). */
|
|
41
46
|
export function loadThemeEngines() {
|
|
42
47
|
engines ??= Promise.all([
|
|
43
48
|
loadEspalierShared("theme-fit-report.js"),
|
|
@@ -46,6 +51,13 @@ export function loadThemeEngines() {
|
|
|
46
51
|
return engines;
|
|
47
52
|
}
|
|
48
53
|
|
|
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;
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
/** The sRGB the engine gamut-maps a compiled color to, as channels in 0..1 and as #rrggbb. */
|
|
50
62
|
function toSrgb(color, value) {
|
|
51
63
|
const parsed = color.parseCssColor(value);
|
|
@@ -91,12 +103,73 @@ function contrastFlag(pair, scheme, context) {
|
|
|
91
103
|
};
|
|
92
104
|
}
|
|
93
105
|
|
|
94
|
-
function
|
|
95
|
-
|
|
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) {
|
|
96
168
|
const resolved = new Map();
|
|
97
169
|
const tokens = report.tokens.map((token) => {
|
|
98
170
|
const measured = toSrgb(color, token.resolved);
|
|
99
171
|
resolved.set(token.token, measured);
|
|
172
|
+
const derivation = getTokenDerivation(token.token);
|
|
100
173
|
return {
|
|
101
174
|
token: token.token,
|
|
102
175
|
value: token.resolved,
|
|
@@ -104,8 +177,11 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
104
177
|
origin: origin(token),
|
|
105
178
|
source: token.source,
|
|
106
179
|
lightness: token.lightness,
|
|
107
|
-
|
|
108
|
-
...(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
|
+
} : {}),
|
|
109
185
|
};
|
|
110
186
|
});
|
|
111
187
|
const pairs = [];
|
|
@@ -115,7 +191,7 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
115
191
|
if (foreground === undefined || background === undefined) continue;
|
|
116
192
|
const required = pairing.targetLc <= LARGE_TEXT_LC ? AA_LARGE_RATIO : AA_TEXT_RATIO;
|
|
117
193
|
const ratio = wcagRatio(foreground.srgb, background.srgb);
|
|
118
|
-
const lc =
|
|
194
|
+
const lc = measureLc(color, foreground.parsed, background.parsed);
|
|
119
195
|
pairs.push({
|
|
120
196
|
token: ink,
|
|
121
197
|
background: pairing.bg,
|
|
@@ -129,7 +205,13 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
129
205
|
}
|
|
130
206
|
const flags = pairs.filter((pair) => !pair.aa).map((pair) => contrastFlag(pair, scheme, context));
|
|
131
207
|
return {
|
|
132
|
-
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
|
+
},
|
|
133
215
|
flags,
|
|
134
216
|
};
|
|
135
217
|
}
|
|
@@ -142,12 +224,16 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
142
224
|
* Throws what `theme push` would throw for an incomplete or invalid theme, and
|
|
143
225
|
* a `theme.context_unknown` refusal for a context the theme does not declare.
|
|
144
226
|
*/
|
|
145
|
-
export async function resolveThemePair(lightTheme, darkTheme, {
|
|
227
|
+
export async function resolveThemePair(lightTheme, darkTheme, {
|
|
228
|
+
scheme, context, footerContext, deferPassingStops = false,
|
|
229
|
+
} = {}) {
|
|
146
230
|
const encoded = validateAndEncodeThemePair(lightTheme, darkTheme);
|
|
147
231
|
const { light, dark } = encoded;
|
|
148
|
-
const
|
|
232
|
+
const themeEngines = await loadThemeEngines();
|
|
233
|
+
const { fit, color } = themeEngines;
|
|
149
234
|
// The stored pair is encoded and parsed back, as theme push's fit lints do, so this is what the page resolves.
|
|
150
|
-
const
|
|
235
|
+
const themes = { light: parseTheme(light) ?? {}, dark: parseTheme(dark) ?? {} };
|
|
236
|
+
const suite = fit.themeFitReportSuite(themes.light, themes.dark);
|
|
151
237
|
const contexts = suite.surfaces.filter((surface) => surface !== fit.ROOT_SURFACE);
|
|
152
238
|
if (context !== undefined && !contexts.includes(context)) {
|
|
153
239
|
throw new SiteAuthoringError(
|
|
@@ -159,21 +245,79 @@ export async function resolveThemePair(lightTheme, darkTheme, { scheme, context
|
|
|
159
245
|
);
|
|
160
246
|
}
|
|
161
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
|
+
|
|
162
278
|
const schemes = [];
|
|
163
279
|
const flags = [];
|
|
280
|
+
let computeThemeProperties;
|
|
164
281
|
for (const name of THEME_SCHEMES) {
|
|
165
282
|
if (scheme !== undefined && scheme !== name) continue;
|
|
283
|
+
const root = mergeTheme(THEME_DEFAULTS[name], themes[name]);
|
|
166
284
|
const surfaces = [];
|
|
167
285
|
for (const report of suite[name]) {
|
|
168
286
|
if (context !== undefined && report.surface !== context) continue;
|
|
169
|
-
const
|
|
170
|
-
|
|
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));
|
|
171
315
|
flags.push(...described.flags);
|
|
172
316
|
}
|
|
173
317
|
schemes.push({ scheme: name, surfaces });
|
|
174
318
|
}
|
|
175
319
|
const pairs = schemes.flatMap((entry) => entry.surfaces).flatMap((surface) => surface.pairs);
|
|
176
|
-
return Object.
|
|
320
|
+
return Object.defineProperties({
|
|
177
321
|
contexts,
|
|
178
322
|
schemes,
|
|
179
323
|
flags,
|
|
@@ -182,7 +326,11 @@ export async function resolveThemePair(lightTheme, darkTheme, { scheme, context
|
|
|
182
326
|
belowAa: pairs.filter((pair) => !pair.aa).length,
|
|
183
327
|
belowApca: pairs.filter((pair) => !pair.apcaMet).length,
|
|
184
328
|
},
|
|
185
|
-
},
|
|
329
|
+
}, {
|
|
330
|
+
encoded: { value: encoded },
|
|
331
|
+
enrichSurface: { value: enrichSurface },
|
|
332
|
+
passingStopByteBound: { value: (surface) => details.get(surface)?.passingStopBytes ?? 0 },
|
|
333
|
+
});
|
|
186
334
|
}
|
|
187
335
|
|
|
188
336
|
const TOKEN_ORDER = new Map(SEMANTIC_COLOR_NAMES.map((name, index) => [name, index]));
|
|
@@ -196,6 +344,45 @@ function table(rows) {
|
|
|
196
344
|
return rows.map((row) => ` ${row.map((cell, column) => pad(cell, widths[column])).join(" ").trimEnd()}`).join("\n");
|
|
197
345
|
}
|
|
198
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
|
+
|
|
199
386
|
/**
|
|
200
387
|
* The human table for a result. Tokens keep Espalier's own order, so a
|
|
201
388
|
* background and its layers read together; a pinned or inherited value is
|
|
@@ -205,17 +392,27 @@ export function formatThemeResolve(result) {
|
|
|
205
392
|
const lines = [`Compiled colors from the ${result.source === "site" ? "site's" : "workspace"} theme.`];
|
|
206
393
|
for (const { scheme, surfaces } of result.schemes) {
|
|
207
394
|
for (const surface of surfaces) {
|
|
208
|
-
lines.push("", `${scheme} · ${surface.context
|
|
395
|
+
lines.push("", `${scheme} · ${surfaceName(surface.context)}`);
|
|
209
396
|
const tokens = [...surface.tokens].sort((left, right) => TOKEN_ORDER.get(left.token) - TOKEN_ORDER.get(right.token));
|
|
210
397
|
lines.push(table([
|
|
211
|
-
["token", "value", "hex", "from"],
|
|
398
|
+
["token", "value", "hex", "from", "static role plan"],
|
|
212
399
|
...tokens.map((token) => [
|
|
213
400
|
token.token,
|
|
214
401
|
token.value,
|
|
215
402
|
token.hex ?? "-",
|
|
216
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}` : "-",
|
|
217
405
|
]),
|
|
218
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
|
+
}
|
|
219
416
|
lines.push("", table([
|
|
220
417
|
["ink", "on", "ratio", "needs", "apca", ""],
|
|
221
418
|
...surface.pairs.map((pair) => [
|
|
@@ -227,6 +424,27 @@ export function formatThemeResolve(result) {
|
|
|
227
424
|
pair.aa ? "ok" : "BELOW AA",
|
|
228
425
|
]),
|
|
229
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
|
+
}
|
|
230
448
|
}
|
|
231
449
|
}
|
|
232
450
|
for (const [scheme, entries] of Object.entries(result.chrome ?? {})) {
|
|
@@ -256,9 +474,33 @@ export function formatThemeResolve(result) {
|
|
|
256
474
|
lines.push("", belowAa === 0
|
|
257
475
|
? `All ${pairs}${measured} pairs meet WCAG AA.`
|
|
258
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
|
+
}
|
|
259
483
|
if (result.omittedSurfaces !== undefined) {
|
|
260
|
-
const
|
|
261
|
-
|
|
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.");
|
|
262
504
|
}
|
|
263
505
|
return `${lines.join("\n")}\n`;
|
|
264
506
|
}
|
package/src/theme-validation.js
CHANGED
|
@@ -6,11 +6,15 @@ import {
|
|
|
6
6
|
mergeTheme,
|
|
7
7
|
parseTheme,
|
|
8
8
|
SEMANTIC_COLOR_NAMES,
|
|
9
|
+
validateComponentProperties,
|
|
9
10
|
validateThemePair,
|
|
10
11
|
} from "@taprootio/espalier/shared/theme";
|
|
11
12
|
|
|
13
|
+
import { LIMITS } from "./constants.js";
|
|
12
14
|
import { hasControlCharacter, sanitizeDiagnostic, SiteAuthoringError } from "./errors.js";
|
|
13
|
-
import { loadEspalierShared } from "./espalier-shared.js";
|
|
15
|
+
import { getSettableComponentProperties, loadEspalierShared } from "./espalier-shared.js";
|
|
16
|
+
import { closeFieldMatch, unknownFieldHint } from "./field-suggestions.js";
|
|
17
|
+
import { withinByteBudget } from "./problems.js";
|
|
14
18
|
import { sharedDeclaredThemeContextNames, sharedEncodedThemeContextNames } from "./theme-contexts.js";
|
|
15
19
|
import { proposePassingValues, refuseUnavailableFontWeights } from "./theme-proposals.js";
|
|
16
20
|
|
|
@@ -19,6 +23,8 @@ export const MAXIMUM_THEME_WARNINGS = 32;
|
|
|
19
23
|
// missed its floor before the remedy, and a surface that fails across the
|
|
20
24
|
// board runs past 900 scalars. Truncating it would cut the remedy off.
|
|
21
25
|
export const MAXIMUM_THEME_WARNING_SCALARS = 2048;
|
|
26
|
+
// Leave room for change paths and save evidence in the CLI result.
|
|
27
|
+
const MAXIMUM_THEME_WARNING_BYTES = LIMITS.githubOutputBytes / 2;
|
|
22
28
|
export const MAXIMUM_THEME_OPEN_MAP_ENTRIES = 128;
|
|
23
29
|
export const MAXIMUM_THEME_OPEN_MAP_KEY_SCALARS = 64;
|
|
24
30
|
|
|
@@ -62,6 +68,21 @@ export const REQUIRED_THEME_PROPERTIES = Object.freeze([
|
|
|
62
68
|
"fontWeightMenu",
|
|
63
69
|
]);
|
|
64
70
|
|
|
71
|
+
export const OPTIONAL_THEME_FIELDS = Object.freeze([
|
|
72
|
+
"explicitMappingTokens",
|
|
73
|
+
"boxBackgroundImage",
|
|
74
|
+
"boxBackgroundImageOpacity",
|
|
75
|
+
"vellumOpacity",
|
|
76
|
+
"vellumBackgroundImage",
|
|
77
|
+
"vellumBackgroundImageOpacity",
|
|
78
|
+
"componentProperties",
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
export const THEME_FIELD_NAMES = Object.freeze([
|
|
82
|
+
...REQUIRED_THEME_PROPERTIES,
|
|
83
|
+
...OPTIONAL_THEME_FIELDS,
|
|
84
|
+
]);
|
|
85
|
+
|
|
65
86
|
const REQUIRED_ANGLE_LEAVES = Object.freeze([
|
|
66
87
|
"analogous",
|
|
67
88
|
"complementary",
|
|
@@ -300,6 +321,19 @@ function requireCompleteTheme(theme, scheme) {
|
|
|
300
321
|
}
|
|
301
322
|
}
|
|
302
323
|
|
|
324
|
+
function requireKnownThemeFields(theme, scheme) {
|
|
325
|
+
const key = Object.keys(theme).find((name) => !THEME_FIELD_NAMES.includes(name));
|
|
326
|
+
if (key === undefined) return;
|
|
327
|
+
|
|
328
|
+
const nearest = closeFieldMatch(key, THEME_FIELD_NAMES);
|
|
329
|
+
const field = `${scheme}Theme.${key}`;
|
|
330
|
+
throw new SiteAuthoringError(
|
|
331
|
+
"theme.field_unknown",
|
|
332
|
+
`Unknown theme field '${field}'.${unknownFieldHint(nearest)}`,
|
|
333
|
+
{ field, alternatives: nearest === undefined ? undefined : [nearest] },
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
303
337
|
function refuseAgentStylesheets(theme, scheme) {
|
|
304
338
|
// Espalier keeps this array in its complete theme document, but an external
|
|
305
339
|
// stylesheet is mutable code outside the frozen authoring-preview inventory.
|
|
@@ -475,14 +509,63 @@ async function fitLints(light, dark) {
|
|
|
475
509
|
return { fit, items };
|
|
476
510
|
}
|
|
477
511
|
|
|
512
|
+
function effectiveComponentProperty(theme, context, { name, default: fallback }) {
|
|
513
|
+
return (context === null ? undefined : theme.contexts[context]?.componentProperties?.[name])
|
|
514
|
+
?? theme.componentProperties?.[name]
|
|
515
|
+
?? fallback;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function comparableComponentProperty(value, unit) {
|
|
519
|
+
if (unit === undefined) return value;
|
|
520
|
+
if (value === "0") return 0;
|
|
521
|
+
return value.endsWith(unit) ? Number(value.slice(0, -unit.length)) : value;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function displayComponentProperty(authored, comparable, unit) {
|
|
525
|
+
if (typeof comparable !== "number") return authored;
|
|
526
|
+
const compact = comparable === 0 ? "0" : `${comparable}${unit}`;
|
|
527
|
+
return compact.length < authored.length ? compact : authored;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function abbreviateThemeContext(context, maximumLength, position) {
|
|
531
|
+
if (context.length <= maximumLength) return context;
|
|
532
|
+
const ending = `…${context.slice(-40)} [context ${position}]`;
|
|
533
|
+
return context.slice(0, maximumLength - ending.length) + ending;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function componentPropertyReflowWarnings(lightTheme, darkTheme) {
|
|
537
|
+
const properties = getSettableComponentProperties().filter(({ syntax }) => syntax !== "color");
|
|
538
|
+
const contexts = sharedDeclaredThemeContextNames(lightTheme, darkTheme);
|
|
539
|
+
const prefix = "theme.component_property_scheme_differs: ";
|
|
540
|
+
const warnings = [];
|
|
541
|
+
for (const [position, context] of [null, ...contexts].entries()) {
|
|
542
|
+
for (const property of properties) {
|
|
543
|
+
const light = effectiveComponentProperty(lightTheme, context, property);
|
|
544
|
+
const dark = effectiveComponentProperty(darkTheme, context, property);
|
|
545
|
+
const lightComparable = comparableComponentProperty(light, property.unit);
|
|
546
|
+
const darkComparable = comparableComponentProperty(dark, property.unit);
|
|
547
|
+
if (lightComparable === darkComparable) continue;
|
|
548
|
+
const lightValue = displayComponentProperty(light, lightComparable, property.unit);
|
|
549
|
+
const darkValue = displayComponentProperty(dark, darkComparable, property.unit);
|
|
550
|
+
const details = ` ${property.name} is ${lightValue} in light and ${darkValue} in dark.`;
|
|
551
|
+
const nameBudget = Math.min(LIMITS.diagnosticScalars, MAXIMUM_THEME_WARNING_SCALARS)
|
|
552
|
+
- prefix.length - "contexts.".length - details.length;
|
|
553
|
+
const surface = context === null ? "root" : `contexts.${abbreviateThemeContext(context, nameBudget, position)}`;
|
|
554
|
+
warnings.push(prefix + surface + details);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return warnings;
|
|
558
|
+
}
|
|
559
|
+
|
|
478
560
|
function boundedThemeWarnings(allWarnings) {
|
|
479
|
-
const
|
|
561
|
+
const candidates = allWarnings
|
|
480
562
|
.slice(0, MAXIMUM_THEME_WARNINGS)
|
|
481
563
|
.map((warning) =>
|
|
482
564
|
[...sanitizeDiagnostic(warning, "Theme validation warning.")]
|
|
483
565
|
.slice(0, MAXIMUM_THEME_WARNING_SCALARS)
|
|
484
566
|
.join("")
|
|
485
567
|
);
|
|
568
|
+
const warnings = withinByteBudget(candidates, MAXIMUM_THEME_WARNING_BYTES);
|
|
486
569
|
return {
|
|
487
570
|
warnings,
|
|
488
571
|
warningCount: allWarnings.length,
|
|
@@ -515,21 +598,24 @@ export async function validateAndLintThemePair(lightTheme, darkTheme) {
|
|
|
515
598
|
fit,
|
|
516
599
|
});
|
|
517
600
|
const unbuilt = items.filter((item) => item.lint === undefined).map((item) => item.text);
|
|
518
|
-
const
|
|
601
|
+
const reflow = componentPropertyReflowWarnings(lightTheme, darkTheme);
|
|
602
|
+
const warningGroups = { validation: proposed.warnings, reflow, unbuilt, lints: proposed.lints, inert };
|
|
519
603
|
const themes = Object.defineProperty({ light, dark }, "warningGroups", { value: warningGroups });
|
|
520
604
|
return withChromeWarnings(themes, []);
|
|
521
605
|
}
|
|
522
606
|
|
|
523
607
|
/** Finish warning publication from the complete groups, before the shared cap. */
|
|
524
608
|
export function withChromeWarnings(themes, chromeWarnings) {
|
|
525
|
-
const { validation, unbuilt, lints, inert } = themes.warningGroups;
|
|
526
|
-
const bounded = boundedThemeWarnings([...validation, ...unbuilt, ...lints, ...chromeWarnings, ...inert]);
|
|
609
|
+
const { validation, reflow, unbuilt, lints, inert } = themes.warningGroups;
|
|
610
|
+
const bounded = boundedThemeWarnings([...validation, ...reflow, ...unbuilt, ...lints, ...chromeWarnings, ...inert]);
|
|
527
611
|
return Object.defineProperty({ ...themes, ...bounded }, "warningGroups", { value: themes.warningGroups });
|
|
528
612
|
}
|
|
529
613
|
|
|
530
614
|
function checkThemePair(lightTheme, darkTheme) {
|
|
531
615
|
requireCompleteTheme(lightTheme, "light");
|
|
532
616
|
requireCompleteTheme(darkTheme, "dark");
|
|
617
|
+
requireKnownThemeFields(lightTheme, "light");
|
|
618
|
+
requireKnownThemeFields(darkTheme, "dark");
|
|
533
619
|
|
|
534
620
|
let light;
|
|
535
621
|
let dark;
|
|
@@ -545,8 +631,11 @@ function checkThemePair(lightTheme, darkTheme) {
|
|
|
545
631
|
}
|
|
546
632
|
|
|
547
633
|
const result = validateThemePair(light, dark);
|
|
548
|
-
|
|
549
|
-
|
|
634
|
+
// Espalier appends one error per component finding after its ordinary errors.
|
|
635
|
+
const findings = result.valid ? [] : validateComponentProperties(light, dark);
|
|
636
|
+
const componentFinding = findings.length === result.errors.length ? findings[0] : undefined;
|
|
637
|
+
const first = result.errors[0] ?? "The theme pair is invalid.";
|
|
638
|
+
if (!result.valid && componentFinding === undefined) {
|
|
550
639
|
const field = /^\s*(?:light|dark):\s*Every entry in ([A-Za-z0-9_.-]+)/u.exec(first)?.[1]
|
|
551
640
|
?? /^\s*(?:light|dark):\s*([A-Za-z0-9_.-]+)/u.exec(first)?.[1]
|
|
552
641
|
?? (/^\s*contexts\b/u.test(first) ? "contexts" : undefined);
|
|
@@ -558,6 +647,28 @@ function checkThemePair(lightTheme, darkTheme) {
|
|
|
558
647
|
}
|
|
559
648
|
refuseAgentStylesheets(lightTheme, "light");
|
|
560
649
|
refuseAgentStylesheets(darkTheme, "dark");
|
|
650
|
+
if (componentFinding !== undefined) {
|
|
651
|
+
const { scheme, context, property, code } = componentFinding;
|
|
652
|
+
const field = [`${scheme}Theme`];
|
|
653
|
+
if (context !== null) field.push("contexts", context);
|
|
654
|
+
field.push("componentProperties");
|
|
655
|
+
if (property !== null) field.push(property);
|
|
656
|
+
// Espalier suggests the nearest settable name even for unrelated inputs.
|
|
657
|
+
const unknownProperty = code === "unknown" && property !== null;
|
|
658
|
+
const nearest = unknownProperty
|
|
659
|
+
? closeFieldMatch(property.slice("--esp-".length), getSettableComponentProperties().map(({ name }) =>
|
|
660
|
+
name.slice("--esp-".length)))
|
|
661
|
+
: undefined;
|
|
662
|
+
const fullName = nearest === undefined ? undefined : "--esp-" + nearest;
|
|
663
|
+
const message = unknownProperty
|
|
664
|
+
? `Unknown component property '${property}'.${unknownFieldHint(fullName)}`
|
|
665
|
+
: `Espalier rejected the theme: ${first}`;
|
|
666
|
+
throw new SiteAuthoringError(
|
|
667
|
+
"theme.validation_failed",
|
|
668
|
+
message,
|
|
669
|
+
{ field: field.join("."), alternatives: fullName === undefined ? undefined : [fullName] },
|
|
670
|
+
);
|
|
671
|
+
}
|
|
561
672
|
return {
|
|
562
673
|
light,
|
|
563
674
|
dark,
|