@taprootio/site-authoring 0.41.0 → 0.42.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 +19 -0
- package/package.json +2 -2
- package/src/api.js +9 -3
- package/src/appearance-contract.js +14 -5
- package/src/brand-color.js +59 -0
- package/src/changelog.json +20 -0
- package/src/chrome-features.js +148 -0
- package/src/chrome-input.js +146 -0
- package/src/chrome-output.js +92 -0
- package/src/chrome-paint-catalog-taproot.json +52 -0
- package/src/chrome-report.js +94 -0
- package/src/cli.js +3 -1
- package/src/content/tiptap-prosemirror.ts +1 -16
- package/src/content/url-safety.js +39 -0
- package/src/footer-brand-inputs.js +4 -0
- package/src/footer-content.js +37 -0
- package/src/footer-workspace.js +16 -9
- package/src/header-presentation.js +16 -0
- package/src/presentation-reference.js +15 -0
- package/src/reference-help.js +1 -1
- package/src/site-check-findings.js +2 -0
- package/src/site-check-rules.json +2 -1
- package/src/site-navigation-groups.js +70 -0
- package/src/social-link-url.js +15 -1
- package/src/theme-resolve.js +44 -32
- package/src/theme-validation.js +11 -2
- package/src/url-safety.js +39 -0
- package/src/verbs/theme-push.js +169 -108
- package/src/verbs/theme-resolve.js +140 -11
- package/src/verbs/validate.js +68 -15
- package/src/workspace-check.js +2 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { parseTheme } from "@taprootio/espalier/shared/theme";
|
|
2
|
+
|
|
3
|
+
import { APPEARANCE_FILES } from "./appearance-contract.js";
|
|
4
|
+
import { standaloneFooterActionEntries } from "./chrome-features.js";
|
|
5
|
+
import { buildChromeInput } from "./chrome-input.js";
|
|
6
|
+
import { CHROME_UNAVAILABLE_MESSAGE, displayChromeRatio } from "./chrome-output.js";
|
|
7
|
+
import taprootCatalog from "./chrome-paint-catalog-taproot.json" with { type: "json" };
|
|
8
|
+
import { loadEspalierShared } from "./espalier-shared.js";
|
|
9
|
+
import { SETTINGS_TYPE_SITE_HEADER, SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES } from "./settings-catalog.js";
|
|
10
|
+
import { CONTRAST_TEXT_BELOW_AA, THEME_STYLES_FILE } from "./theme-resolve.js";
|
|
11
|
+
import { loadFitReport } from "./theme-validation.js";
|
|
12
|
+
|
|
13
|
+
export { CHROME_UNAVAILABLE_MESSAGE } from "./chrome-output.js";
|
|
14
|
+
|
|
15
|
+
const SCHEMES = ["light", "dark"];
|
|
16
|
+
|
|
17
|
+
function fieldFor(role, context, scheme, pair, brandColorSourceFields) {
|
|
18
|
+
const brandColorField = pair.foreground === "brand-color" ? brandColorSourceFields[scheme] : undefined;
|
|
19
|
+
if (brandColorField !== undefined) {
|
|
20
|
+
return { field: `site-header.${brandColorField}`, file: APPEARANCE_FILES[SETTINGS_TYPE_SITE_HEADER] };
|
|
21
|
+
}
|
|
22
|
+
if (context === null) return { field: `${scheme}Theme`, file: THEME_STYLES_FILE };
|
|
23
|
+
return role === "header"
|
|
24
|
+
? { field: "site-header.context", file: APPEARANCE_FILES[SETTINGS_TYPE_SITE_HEADER] }
|
|
25
|
+
: { field: "site-publishing-preferences.footerSettings.context", file: APPEARANCE_FILES[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES] };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function extraPaintEntries(nameReportEnabled) {
|
|
29
|
+
if (nameReportEnabled !== true) return taprootCatalog;
|
|
30
|
+
const { PAINT_CATALOG } = await loadEspalierShared("paint-catalog.js");
|
|
31
|
+
return { ...taprootCatalog, footer: [...taprootCatalog.footer, ...standaloneFooterActionEntries(PAINT_CATALOG.footer)] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Measure optional chrome without changing the command that accepted the appearance. */
|
|
35
|
+
export async function completeChromeReport(inputs, { loadFit = loadFitReport } = {}) {
|
|
36
|
+
let navigationUnavailable = true;
|
|
37
|
+
try {
|
|
38
|
+
const { themes, appearance, resources, nameReportEnabled } = inputs;
|
|
39
|
+
const input = buildChromeInput({ appearance, resources, nameReportEnabled });
|
|
40
|
+
({ navigationUnavailable } = input);
|
|
41
|
+
const light = parseTheme(themes.light);
|
|
42
|
+
const dark = parseTheme(themes.dark);
|
|
43
|
+
if (!light || !dark) throw new Error("Missing accepted theme pair.");
|
|
44
|
+
const fit = await loadFit();
|
|
45
|
+
const extraEntries = await extraPaintEntries(nameReportEnabled);
|
|
46
|
+
const { paint: entries } = fit.themeFitReportSuite(light, dark, { paintSurfaces: input.paintSurfaces, extraEntries });
|
|
47
|
+
const flags = [];
|
|
48
|
+
const warnings = [];
|
|
49
|
+
let pairs = 0;
|
|
50
|
+
for (const scheme of SCHEMES) {
|
|
51
|
+
for (const { role, context, pairs: measured } of entries[scheme]) {
|
|
52
|
+
pairs += measured.length;
|
|
53
|
+
for (const pair of measured) {
|
|
54
|
+
if (pair.ratio >= pair.required) continue;
|
|
55
|
+
const { element, foreground, background, state, kind, required } = pair;
|
|
56
|
+
const { field, file } = fieldFor(role, context, scheme, pair, input.brandColorSourceFields);
|
|
57
|
+
const ratio = displayChromeRatio(pair.ratio, required);
|
|
58
|
+
const shownRatio = ratio.toFixed(2);
|
|
59
|
+
const shownRequirement = required.toFixed(2);
|
|
60
|
+
flags.push({
|
|
61
|
+
code: CONTRAST_TEXT_BELOW_AA,
|
|
62
|
+
area: "presentation",
|
|
63
|
+
file,
|
|
64
|
+
field,
|
|
65
|
+
token: foreground,
|
|
66
|
+
background,
|
|
67
|
+
scheme,
|
|
68
|
+
context,
|
|
69
|
+
ratio,
|
|
70
|
+
required,
|
|
71
|
+
message: `${role} ${element}/${state} paints ${foreground} on ${background} at ${shownRatio}:1. It needs ${shownRequirement}:1.`,
|
|
72
|
+
role,
|
|
73
|
+
element,
|
|
74
|
+
state,
|
|
75
|
+
kind,
|
|
76
|
+
});
|
|
77
|
+
warnings.push(
|
|
78
|
+
`chrome: ${CONTRAST_TEXT_BELOW_AA}; ${field}; ${scheme} ${role} ${element}/${state}; ${shownRatio}:1 < ${shownRequirement}:1.`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { entries, flags, warnings, contrast: { pairs, belowAa: flags.length }, navigationUnavailable, unavailable: false };
|
|
84
|
+
} catch {
|
|
85
|
+
return {
|
|
86
|
+
entries: { light: [], dark: [] },
|
|
87
|
+
flags: [],
|
|
88
|
+
warnings: [CHROME_UNAVAILABLE_MESSAGE],
|
|
89
|
+
contrast: { pairs: 0, belowAa: 0 },
|
|
90
|
+
navigationUnavailable,
|
|
91
|
+
unavailable: true,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -1195,7 +1195,9 @@ function verbHelp(verb) {
|
|
|
1195
1195
|
const boundary = verb.name === VERB_THEME_RESOLVE
|
|
1196
1196
|
? "By default this verb reads the pulled workspace and uses no credential, makes no network request, and writes "
|
|
1197
1197
|
+ `nothing to the workspace or the site (GITHUB_OUTPUT, when set, receives the JSON result). With --site it reads the site's presentation with the site-scoped credential from ${PUBLISH_KEY_ENVIRONMENT_VARIABLE} `
|
|
1198
|
-
+ `or the sign-in '${CLI_BINARY_NAME} ${VERB_LOGIN}' stores
|
|
1198
|
+
+ `or the sign-in '${CLI_BINARY_NAME} ${VERB_LOGIN}' stores. Header and footer JSON rows are `
|
|
1199
|
+
+ "[identityIndex, ratio, required]. Resolve identityIndex through chromeCatalog.pairs and its elements, colors, "
|
|
1200
|
+
+ `states and kinds dictionaries.${upgradeGate}`
|
|
1199
1201
|
: verb.name === VERB_VALIDATE
|
|
1200
1202
|
? "Validation uses no credential, network or write unless --site is given; it reads the configuration only to find "
|
|
1201
1203
|
+ "the workspace when no directory is given. With --init it reads the pulled workspace or selected configuration "
|
|
@@ -11,6 +11,7 @@ import { blockquoteCaptionParts, readBlockquoteMetadata } from "./blockquote-met
|
|
|
11
11
|
import { columnsAttributes, isColumnEligibleBlock } from "./free-form-columns.js";
|
|
12
12
|
import freeFormSectionRegistry from "./free-form-section-registry.json" with { type: "json" };
|
|
13
13
|
import { imageDescriptionIssues } from "./image-description-validation.js";
|
|
14
|
+
import { isSafeUrl } from "./url-safety.js";
|
|
14
15
|
import { isExternalLink, NEW_TAB_CUE_HTML, relWithNewTabTokens } from "./external-link.js";
|
|
15
16
|
import {
|
|
16
17
|
explicitImageMaxHeight,
|
|
@@ -1553,22 +1554,6 @@ function renderLink(
|
|
|
1553
1554
|
return renderElement("a", { href, ...linkAttributes }, `${html}${cue}`);
|
|
1554
1555
|
}
|
|
1555
1556
|
|
|
1556
|
-
function isSafeUrl(url: string): boolean {
|
|
1557
|
-
if (/[\x00-\x1f\x7f\\]/u.test(url)) return false;
|
|
1558
|
-
const cleaned = url.trim();
|
|
1559
|
-
if (!cleaned) return false;
|
|
1560
|
-
if (cleaned.startsWith("//")) return false;
|
|
1561
|
-
if (cleaned.startsWith("/") || cleaned.startsWith("./")) return true;
|
|
1562
|
-
if (cleaned.startsWith("#") || cleaned.startsWith("?")) return true;
|
|
1563
|
-
|
|
1564
|
-
try {
|
|
1565
|
-
const parsed = new URL(cleaned);
|
|
1566
|
-
return ["http:", "https:", "mailto:", "tel:"].includes(parsed.protocol);
|
|
1567
|
-
} catch {
|
|
1568
|
-
return true;
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
1557
|
function jsonAttr(value: unknown): string | null {
|
|
1573
1558
|
if (value === undefined || value === null) return null;
|
|
1574
1559
|
if (typeof value === "string") return value;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Generated from shared/url-safety.ts by scripts/sync-field-validation.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* The renderer's safe-link rule. The generator, editor and CLI copies are
|
|
4
|
+
* written by scripts/sync-field-validation.mjs; edit this source only.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Check whether a URL string is safe for use in an `href` attribute.
|
|
8
|
+
* Allows `http:`, `https:`, `mailto:`, `tel:`, and site-relative paths
|
|
9
|
+
* (starting with `/` or `./`). Rejects `javascript:`, `data:`, `vbscript:`,
|
|
10
|
+
* and every other executable or unknown scheme.
|
|
11
|
+
*
|
|
12
|
+
* ASCII controls, backslashes, and protocol-relative paths are rejected
|
|
13
|
+
* before scheme validation because browsers normalize them inconsistently.
|
|
14
|
+
*
|
|
15
|
+
* Returns `false` for empty/whitespace-only strings.
|
|
16
|
+
*/
|
|
17
|
+
export function isSafeUrl(url) {
|
|
18
|
+
if (/[\x00-\x1f\x7f\\]/u.test(url))
|
|
19
|
+
return false;
|
|
20
|
+
const cleaned = url.trim();
|
|
21
|
+
if (!cleaned)
|
|
22
|
+
return false;
|
|
23
|
+
if (cleaned.startsWith("//"))
|
|
24
|
+
return false;
|
|
25
|
+
if (cleaned.startsWith("/") || cleaned.startsWith("./"))
|
|
26
|
+
return true;
|
|
27
|
+
// Fragment-only and query-only links are safe.
|
|
28
|
+
if (cleaned.startsWith("#") || cleaned.startsWith("?"))
|
|
29
|
+
return true;
|
|
30
|
+
// Try parsing as an absolute URL. If it parses, validate the protocol.
|
|
31
|
+
try {
|
|
32
|
+
const parsed = new URL(cleaned);
|
|
33
|
+
return ["http:", "https:", "mailto:", "tel:"].includes(parsed.protocol);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Not a valid absolute URL — treat as a relative path (safe).
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -21,6 +21,10 @@ export async function readFooterBrandInputs(workspaceDir, footerSettings) {
|
|
|
21
21
|
optionalSettings(workspaceDir, SETTINGS_TYPE_TAPROOT_STYLES),
|
|
22
22
|
readWorkspaceJson(workspaceDir, MEDIA_MANIFEST_FILE_NAME, WORKSPACE_LIMITS.manifestBytes).then(value => value?.media ?? {}).catch(() => ({})),
|
|
23
23
|
]);
|
|
24
|
+
return footerBrandInputsFromSettings(header, styles, media, footerSettings);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function footerBrandInputsFromSettings(header, styles, media, footerSettings) {
|
|
24
28
|
const pair = resolveFooterLogoPairs({ ...logoInputsFromSettings(styles, footerSettings, media), logoVariant: footerSettings?.logoVariant });
|
|
25
29
|
const visible = [pair.light, pair.dark].filter(value => value.url !== "");
|
|
26
30
|
const ratios = visible.map(value => Number(value.aspectRatio));
|
package/src/footer-content.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Generated from shared/footer-content.ts by scripts/sync-field-validation.mjs. Do not edit.
|
|
2
|
+
import { isSafeUrl } from "./url-safety.js";
|
|
2
3
|
/** These fields belong to presentation; footer content saves and dirty checks leave them alone. */
|
|
3
4
|
export const FOOTER_PRESENTATION_FIELDS = ["context", "logoVariant"];
|
|
4
5
|
/** Preserve raw content values; callers decide whether their document needs normalization. */
|
|
@@ -8,3 +9,39 @@ export function projectFooterContent(settings) {
|
|
|
8
9
|
delete content[field];
|
|
9
10
|
return content;
|
|
10
11
|
}
|
|
12
|
+
/** Live settings without a path inventory can only assume an authored page target exists. */
|
|
13
|
+
export function resolveFooterTarget(target, pathsByResourceId) {
|
|
14
|
+
const pageResourceId = target.pageResourceId?.trim() ?? "";
|
|
15
|
+
const externalUrl = target.externalUrl?.trim() ?? "";
|
|
16
|
+
if (Boolean(pageResourceId) === Boolean(externalUrl))
|
|
17
|
+
return null;
|
|
18
|
+
if (pageResourceId) {
|
|
19
|
+
if (pathsByResourceId === undefined)
|
|
20
|
+
return "/";
|
|
21
|
+
const path = pathsByResourceId.get(pageResourceId);
|
|
22
|
+
return path && isSafeUrl(path) ? path : null;
|
|
23
|
+
}
|
|
24
|
+
return normalizeExternalTargetUrl(externalUrl);
|
|
25
|
+
}
|
|
26
|
+
/** Preserve authored contact URLs. URL.toString() can re-encode phone or address punctuation. */
|
|
27
|
+
function normalizeExternalTargetUrl(candidate) {
|
|
28
|
+
// The generic safe-link rule also allows relative paths. An external footer
|
|
29
|
+
// target must be absolute, and the write paths also refuse C1 controls.
|
|
30
|
+
if (!candidate || !isSafeUrl(candidate) || /[\u0080-\u009f]/u.test(candidate))
|
|
31
|
+
return null;
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = new URL(candidate);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
40
|
+
return parsed.username || parsed.password || !parsed.hostname ? null : parsed.toString();
|
|
41
|
+
}
|
|
42
|
+
if (parsed.protocol !== "mailto:" && parsed.protocol !== "tel:")
|
|
43
|
+
return null;
|
|
44
|
+
if (candidate.slice(candidate.indexOf(":") + 1).startsWith("//"))
|
|
45
|
+
return null;
|
|
46
|
+
return parsed.pathname.length > 0 ? candidate : null;
|
|
47
|
+
}
|
package/src/footer-workspace.js
CHANGED
|
@@ -54,15 +54,22 @@ export async function readFooterWorkspaceContext(workspaceDir, siteId) {
|
|
|
54
54
|
const manifest = await readManifest(workspaceDir, siteId);
|
|
55
55
|
const footer = requireFooterMetadata(manifest);
|
|
56
56
|
const mediaManifest = await readMediaManifest(workspaceDir, siteId);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
requireAppearanceMetadata(manifest, { required: false, code: "footer.pull_required" });
|
|
58
|
+
return { manifest, mediaManifest, footer, ...appearanceResourceIds(manifest, mediaManifest) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Collect the identities present in the available, site-bound inventory. */
|
|
62
|
+
export function appearanceResourceIds(manifest, mediaManifest) {
|
|
63
|
+
const knownPageResourceIds = manifest === undefined
|
|
64
|
+
? undefined
|
|
65
|
+
: new Set(manifest.pages.map((page) => page?.resourceId).filter(isCanonicalUuid));
|
|
66
|
+
const imageIds = [manifest?.footer?.imageIds, manifest?.appearance?.imageIds]
|
|
67
|
+
.flatMap((ids) => Array.isArray(ids) ? ids : []);
|
|
68
|
+
const knownImageIds = new Set([
|
|
69
|
+
...imageIds,
|
|
70
|
+
...Object.values(mediaManifest?.media ?? {}).map((item) => item?.imageId),
|
|
71
|
+
].filter(isCanonicalUuid));
|
|
72
|
+
return { knownPageResourceIds, knownImageIds };
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
export async function readAppearanceWorkspaceContext(workspaceDir, siteId) {
|
|
@@ -28,6 +28,22 @@ export function canUseCompactHeaderLogo(position, multiplier, hasRegularLogo, mi
|
|
|
28
28
|
return position === "fixed" && hasRegularLogo && height !== null
|
|
29
29
|
&& height.tenths > resolveHeaderMinHeightMultiplier(minimum, multiplier).tenths;
|
|
30
30
|
}
|
|
31
|
+
/** Read the same header settings when building the page and when auditing its paint. */
|
|
32
|
+
export function resolveHeaderChromePresentation(settings) {
|
|
33
|
+
const layout = settings?.headerLayout;
|
|
34
|
+
return {
|
|
35
|
+
layout: layout === "centered-brand" || layout === "centered-menu" || layout === "minimal" ? layout : "standard",
|
|
36
|
+
heightMultiplier: resolveHeaderHeightMultiplier(settings?.headerHeightMultiplier).scale,
|
|
37
|
+
minHeightMultiplier: resolveHeaderMinHeightMultiplier(settings?.headerMinHeightMultiplier, settings?.headerHeightMultiplier).scale,
|
|
38
|
+
compactSizeStandard: settings?.headerPosition === "fixed",
|
|
39
|
+
compactOnScroll: canUseCompactHeaderLogo(settings?.headerPosition, settings?.headerHeightMultiplier, true, settings?.headerMinHeightMultiplier),
|
|
40
|
+
menuDisplay: settings?.navMenuDisplay === "drawer" ? "drawer" : "auto",
|
|
41
|
+
navDrawerStyle: settings?.navDrawerStyle === "panel" ? "panel" : "full-screen",
|
|
42
|
+
brandText: settings?.brandText ?? "",
|
|
43
|
+
showBrandText: settings?.showBrandText !== false,
|
|
44
|
+
showThemeToggle: settings?.showThemeToggle === true,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
31
47
|
/** Keep each scheme's selected source and reserved ratio together through fallback. */
|
|
32
48
|
export function resolveHeaderLogoPairs(input) {
|
|
33
49
|
const pair = (url = "", aspectRatio = "") => ({ url, aspectRatio: url ? aspectRatio : "" });
|
|
@@ -27,6 +27,11 @@ import {
|
|
|
27
27
|
APPEARANCE_READ_ONLY_FIELDS,
|
|
28
28
|
APPEARANCE_SCALAR_FIELDS,
|
|
29
29
|
} from "./appearance-contract.js";
|
|
30
|
+
import {
|
|
31
|
+
CHROME_NAVIGATION_UNAVAILABLE_MESSAGE,
|
|
32
|
+
CHROME_OFFLINE_PAGE_LIMITATION,
|
|
33
|
+
CHROME_REPORT_NAME_RULE,
|
|
34
|
+
} from "./chrome-input.js";
|
|
30
35
|
import { CLI_BINARY_NAME } from "./constants.js";
|
|
31
36
|
import { LOGO_VARIANTS } from "./header-presentation.js";
|
|
32
37
|
import { FOOTER_LOGO_BOX, FOOTER_LOGO_SCALE_LIMITS } from "./footer-branding.js";
|
|
@@ -522,6 +527,15 @@ export function getAppearanceReference() {
|
|
|
522
527
|
+ "header at desktop and compact/mobile widths. Transparent pixels provide no contrast: inspect the visible mark, "
|
|
523
528
|
+ "not its canvas bounds. When one asset does not remain distinct in both schemes, supply scheme-specific logo "
|
|
524
529
|
+ "assets rather than relying on a shadow, outline, or header color that has not been previewed.",
|
|
530
|
+
chromeContrastContract:
|
|
531
|
+
"Theme resolve, validate and theme push check registered header and footer text, icons and focus indicators against the "
|
|
532
|
+
+ "base colors they use in both schemes. Text needs 4.5:1. Icons and focus indicators need 3:1. Inspect "
|
|
533
|
+
+ "background artwork and states outside the audited interactions on staging. "
|
|
534
|
+
+ `Offline reports leave ${CHROME_OFFLINE_PAGE_LIMITATION} unchecked. `
|
|
535
|
+
+ "A staged edit to a live page or a truncated inventory can leave its production path unknown. "
|
|
536
|
+
+ "Settings-only Docs validation lacks the navigation and page inventory for navigation and footer page links. "
|
|
537
|
+
+ CHROME_NAVIGATION_UNAVAILABLE_MESSAGE + " When report-name display eligibility is unknown, only validate "
|
|
538
|
+
+ `lists ${CHROME_REPORT_NAME_RULE} in siteChecks.skipped.`,
|
|
525
539
|
headerWidthContract: "headerWidth 'contained' keeps the brand and the header buttons at the page content edges; "
|
|
526
540
|
+ "'wide' moves them to the viewport edges. Pages with root-band components (image-banner) span the viewport, "
|
|
527
541
|
+ "so full-bleed designs usually pair headerWidth 'wide' with headerLayout 'centered-menu', which keeps the "
|
|
@@ -912,6 +926,7 @@ export function formatPresentationReference(reference) {
|
|
|
912
926
|
+ "\n\nField map: " + reference.fieldMap
|
|
913
927
|
+ "\n\nImages: " + reference.imageReferences + "\nLogos: " + reference.logoContract
|
|
914
928
|
+ "\nLogo contrast: " + reference.logoContrastContract
|
|
929
|
+
+ "\nHeader and footer contrast\n " + reference.chromeContrastContract
|
|
915
930
|
+ "\nFavicon: " + reference.faviconContract
|
|
916
931
|
+ "\nHeader width: " + reference.headerWidthContract
|
|
917
932
|
+ "\nBlock spacing: " + reference.blockSpacingContract
|
package/src/reference-help.js
CHANGED
|
@@ -95,7 +95,7 @@ import {
|
|
|
95
95
|
|
|
96
96
|
export { getAppearanceReference, getFooterReference, getSettingsReference, getThemeReference };
|
|
97
97
|
|
|
98
|
-
export const REFERENCE_VERSION =
|
|
98
|
+
export const REFERENCE_VERSION = 63;
|
|
99
99
|
|
|
100
100
|
// The date-limit examples `help forms` prints; tests run them through the form validator.
|
|
101
101
|
export const FORM_DATE_WINDOW_FIELD = Object.freeze({
|
|
@@ -88,6 +88,8 @@ export const SITE_CHECK_WORDING = Object.freeze({
|
|
|
88
88
|
const artwork = third ?? second;
|
|
89
89
|
return `the ${finding.subject === "footer" ? "footer" : "header"} shows ${artwork === "dark" ? "dark" : "light"}-background ${second === "compact" ? "compact " : ""}artwork against the opposite surface brightness in the ${scheme === "dark" ? "dark" : "light"} scheme; choose its other Logo variant or adjust its Colors context`;
|
|
90
90
|
},
|
|
91
|
+
"theme.chrome_report_name": () =>
|
|
92
|
+
"could not check report-name action contrast because its display eligibility is unknown",
|
|
91
93
|
"seo.social_image_fallback": (finding) =>
|
|
92
94
|
finding.detail === "first_image"
|
|
93
95
|
? "has no cover image; link previews use the page's first image only when it is public and at least 1200 pixels wide"
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
{ "id": "seo.description_matches_title", "severity": "warning", "scope": "document", "runsAt": ["validate", "edit", "deploy", "health"], "subject": "none", "detail": "none" },
|
|
36
36
|
{ "id": "seo.social_image_fallback", "severity": "warning", "scope": "document", "appliesTo": ["free_form"], "runsAt": ["edit"], "subject": "none", "detail": "social_image_source" },
|
|
37
37
|
{ "id": "footer.word_breaks", "severity": "warning", "scope": "site", "runsAt": ["validate", "edit", "deploy", "health"], "subject": "footer_word", "detail": "width_and_region" },
|
|
38
|
-
{ "id": "brand.logo_on_surface", "severity": "warning", "scope": "site", "runsAt": ["validate"], "subject": "surface", "detail": "scheme_and_variant" }
|
|
38
|
+
{ "id": "brand.logo_on_surface", "severity": "warning", "scope": "site", "runsAt": ["validate"], "subject": "surface", "detail": "scheme_and_variant" },
|
|
39
|
+
{ "id": "theme.chrome_report_name", "severity": "warning", "scope": "site", "runsAt": ["validate"], "subject": "none", "detail": "none" }
|
|
39
40
|
]
|
|
40
41
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Generated from shared/site-navigation-groups.ts by scripts/sync-field-validation.mjs. Do not edit.
|
|
2
|
+
import { isSafeUrl } from "./url-safety.js";
|
|
3
|
+
// Published navigation depth stays aligned with the API command validation cap.
|
|
4
|
+
export const MAX_NAVIGATION_DEPTH = 3;
|
|
5
|
+
export const SITE_NAVIGATION_KINDS = {
|
|
6
|
+
page: "NAV_ITEM_KIND_PAGE",
|
|
7
|
+
externalUrl: "NAV_ITEM_KIND_EXTERNAL_URL",
|
|
8
|
+
groupHeader: "NAV_ITEM_KIND_GROUP_HEADER",
|
|
9
|
+
};
|
|
10
|
+
/** Whether a page or external link without children can use button appearance. */
|
|
11
|
+
export function canStyleNavigationAsButton(kind, hasChildren, kinds = SITE_NAVIGATION_KINDS) {
|
|
12
|
+
return !hasChildren && (kind === kinds.page || kind === kinds.externalUrl);
|
|
13
|
+
}
|
|
14
|
+
/** Only top-level destination leaves can sit beside the header controls. */
|
|
15
|
+
export function canPlaceNavigationAtHeaderEnd(kind, depth, hasChildren, kinds = SITE_NAVIGATION_KINDS) {
|
|
16
|
+
return depth === 1 && canStyleNavigationAsButton(kind, hasChildren, kinds);
|
|
17
|
+
}
|
|
18
|
+
/** Rendering treatment after the navigation tree has been prepared. */
|
|
19
|
+
export function describeHeaderNavigationItem(item, kinds, buttonAppearance) {
|
|
20
|
+
const group = item.kind === kinds.groupHeader || (item.children?.length ?? 0) > 0;
|
|
21
|
+
const url = !group && item.url && isSafeUrl(item.url) ? item.url : "";
|
|
22
|
+
const button = Boolean(url) && item.appearance === buttonAppearance
|
|
23
|
+
&& canStyleNavigationAsButton(item.kind, group, kinds);
|
|
24
|
+
return { group, url, button };
|
|
25
|
+
}
|
|
26
|
+
/** Adapt old trees for rendering without changing their stored manifest or identities. */
|
|
27
|
+
export function normalizeSiteNavigationGroups(items, kinds) {
|
|
28
|
+
const usedIds = new Set();
|
|
29
|
+
const collect = (nodes) => {
|
|
30
|
+
for (const node of nodes) {
|
|
31
|
+
usedIds.add(node.id);
|
|
32
|
+
collect(node.children ?? []);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
collect(items);
|
|
36
|
+
const normalize = (item) => {
|
|
37
|
+
const children = (item.children ?? []).map(normalize);
|
|
38
|
+
if (children.length === 0)
|
|
39
|
+
return item;
|
|
40
|
+
const hasDestination = item.kind === kinds.page
|
|
41
|
+
? Boolean(item.resourceId?.trim())
|
|
42
|
+
: item.kind === kinds.externalUrl && Boolean(item.externalUrl?.trim());
|
|
43
|
+
if (hasDestination) {
|
|
44
|
+
// These opaque IDs exist only while rendering; persisted children get UUIDs from the API.
|
|
45
|
+
const base = `${item.id}-link`;
|
|
46
|
+
let id = base;
|
|
47
|
+
for (let suffix = 1; usedIds.has(id); suffix++)
|
|
48
|
+
id = `${base}-${suffix}`;
|
|
49
|
+
usedIds.add(id);
|
|
50
|
+
children.unshift({ ...item, id, children: [] });
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...item,
|
|
54
|
+
kind: kinds.groupHeader,
|
|
55
|
+
resourceId: "",
|
|
56
|
+
externalUrl: "",
|
|
57
|
+
url: "",
|
|
58
|
+
children,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
return items.map(normalize);
|
|
62
|
+
}
|
|
63
|
+
/** Preserve the old depth boundary before adapting linked groups. */
|
|
64
|
+
export function prepareHeaderNavigation(items, kinds) {
|
|
65
|
+
const project = (nodes, depth) => nodes.map((item) => ({
|
|
66
|
+
...item,
|
|
67
|
+
children: depth < MAX_NAVIGATION_DEPTH ? project(item.children ?? [], depth + 1) : [],
|
|
68
|
+
}));
|
|
69
|
+
return normalizeSiteNavigationGroups(project(items, 1), kinds);
|
|
70
|
+
}
|
package/src/social-link-url.js
CHANGED
|
@@ -10,11 +10,25 @@
|
|
|
10
10
|
* CLI, the generator, the editor and the API's own port in agreement, which
|
|
11
11
|
* `shared/social-link-url-corpus.json` proves in each of them.
|
|
12
12
|
*
|
|
13
|
-
* It
|
|
13
|
+
* It uses the shared platform vocabulary. The generator and site-authoring CLI
|
|
14
14
|
* cannot import this file, so `node scripts/sync-field-validation.mjs` writes
|
|
15
15
|
* their copies; edit only this file and re-run it. The editor imports it by
|
|
16
16
|
* relative path.
|
|
17
17
|
*/
|
|
18
|
+
import socialPlatforms from "./social-platforms.json" with { type: "json" };
|
|
19
|
+
/** The vocabulary in its recorded order; `other` is last. */
|
|
20
|
+
export const SOCIAL_PLATFORMS = socialPlatforms.platforms;
|
|
21
|
+
/** The platform key a Website link stores. */
|
|
22
|
+
export const OTHER_SOCIAL_PLATFORM = "other";
|
|
23
|
+
export function findSocialPlatform(key) {
|
|
24
|
+
return typeof key === "string" ? SOCIAL_PLATFORMS.find((platform) => platform.key === key) : undefined;
|
|
25
|
+
}
|
|
26
|
+
/** Whether a stored link can be rendered: a known platform and an accepted address. */
|
|
27
|
+
export function isRenderableSocialLink(item) {
|
|
28
|
+
return item !== null && item !== undefined
|
|
29
|
+
&& findSocialPlatform(item.platform) !== undefined
|
|
30
|
+
&& isSocialLinkUrl(item.url);
|
|
31
|
+
}
|
|
18
32
|
/** The longest address stored anywhere a social link lives. */
|
|
19
33
|
export const SOCIAL_LINK_URL_MAX_LENGTH = 2048;
|
|
20
34
|
/**
|
package/src/theme-resolve.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AA_LARGE_RATIO,
|
|
3
|
+
AA_TEXT_RATIO,
|
|
4
|
+
parseTheme,
|
|
5
|
+
SEMANTIC_COLOR_NAMES,
|
|
6
|
+
TOKEN_PAIRINGS,
|
|
7
|
+
wcagRatio,
|
|
8
|
+
} from "@taprootio/espalier/shared/theme";
|
|
2
9
|
|
|
10
|
+
import { CHROME_NAVIGATION_UNAVAILABLE_MESSAGE } from "./chrome-input.js";
|
|
11
|
+
import { CHROME_UNAVAILABLE_MESSAGE, decodeChromePair, floorTo } from "./chrome-output.js";
|
|
3
12
|
import { SiteAuthoringError } from "./errors.js";
|
|
4
13
|
import { loadEspalierShared } from "./espalier-shared.js";
|
|
5
14
|
import { validateAndEncodeThemePair } from "./theme-validation.js";
|
|
@@ -20,8 +29,6 @@ export const THEME_STYLES_FILE = "settings/taproot-styles.json";
|
|
|
20
29
|
// WCAG 2.x AA. Espalier sizes its pairings by APCA target: Lc 90 and 75 are
|
|
21
30
|
// body and 16px+ text, Lc 60 is the 24px+ and UI tier, which is what AA calls
|
|
22
31
|
// large text and non-text contrast.
|
|
23
|
-
export const AA_TEXT_RATIO = 4.5;
|
|
24
|
-
export const AA_LARGE_RATIO = 3;
|
|
25
32
|
const LARGE_TEXT_LC = 60;
|
|
26
33
|
|
|
27
34
|
export const CONTRAST_TEXT_BELOW_AA = "theme.contrast_text_below_aa";
|
|
@@ -39,36 +46,17 @@ export function loadThemeEngines() {
|
|
|
39
46
|
return engines;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
function channelByte(color, value) {
|
|
43
|
-
return Math.round(color.clampChannel(value) * 255);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
49
|
/** The sRGB the engine gamut-maps a compiled color to, as channels in 0..1 and as #rrggbb. */
|
|
47
50
|
function toSrgb(color, value) {
|
|
48
51
|
const parsed = color.parseCssColor(value);
|
|
49
52
|
if (parsed === null) return undefined;
|
|
50
|
-
const
|
|
51
|
-
const
|
|
53
|
+
const mapped = color.oklchToSRGB(color.gamutMapToSRGB(parsed));
|
|
54
|
+
const srgb = { r: color.clampChannel(mapped.r), g: color.clampChannel(mapped.g), b: color.clampChannel(mapped.b) };
|
|
55
|
+
const hex = `#${[srgb.r, srgb.g, srgb.b].map((channel) => Math.round(channel * 255).toString(16).padStart(2, "0")).join("")}`;
|
|
52
56
|
return { parsed, srgb, hex };
|
|
53
57
|
}
|
|
54
58
|
|
|
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
|
-
}
|
|
59
|
+
export { floorTo } from "./chrome-output.js";
|
|
72
60
|
|
|
73
61
|
function origin(token) {
|
|
74
62
|
if (token.explicit === "declared") return "pinned";
|
|
@@ -126,7 +114,7 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
126
114
|
const background = resolved.get(pairing.bg);
|
|
127
115
|
if (foreground === undefined || background === undefined) continue;
|
|
128
116
|
const required = pairing.targetLc <= LARGE_TEXT_LC ? AA_LARGE_RATIO : AA_TEXT_RATIO;
|
|
129
|
-
const ratio = wcagRatio(
|
|
117
|
+
const ratio = wcagRatio(foreground.srgb, background.srgb);
|
|
130
118
|
const lc = Math.abs(color.apcaContrast(foreground.parsed, background.parsed));
|
|
131
119
|
pairs.push({
|
|
132
120
|
token: ink,
|
|
@@ -155,7 +143,8 @@ function describeSurface(color, report, scheme, rootSurface) {
|
|
|
155
143
|
* a `theme.context_unknown` refusal for a context the theme does not declare.
|
|
156
144
|
*/
|
|
157
145
|
export async function resolveThemePair(lightTheme, darkTheme, { scheme, context } = {}) {
|
|
158
|
-
const
|
|
146
|
+
const encoded = validateAndEncodeThemePair(lightTheme, darkTheme);
|
|
147
|
+
const { light, dark } = encoded;
|
|
159
148
|
const { fit, color } = await loadThemeEngines();
|
|
160
149
|
// The stored pair is encoded and parsed back, as theme push's fit lints do, so this is what the page resolves.
|
|
161
150
|
const suite = fit.themeFitReportSuite(parseTheme(light) ?? {}, parseTheme(dark) ?? {});
|
|
@@ -184,7 +173,7 @@ export async function resolveThemePair(lightTheme, darkTheme, { scheme, context
|
|
|
184
173
|
schemes.push({ scheme: name, surfaces });
|
|
185
174
|
}
|
|
186
175
|
const pairs = schemes.flatMap((entry) => entry.surfaces).flatMap((surface) => surface.pairs);
|
|
187
|
-
return {
|
|
176
|
+
return Object.defineProperty({
|
|
188
177
|
contexts,
|
|
189
178
|
schemes,
|
|
190
179
|
flags,
|
|
@@ -193,7 +182,7 @@ export async function resolveThemePair(lightTheme, darkTheme, { scheme, context
|
|
|
193
182
|
belowAa: pairs.filter((pair) => !pair.aa).length,
|
|
194
183
|
belowApca: pairs.filter((pair) => !pair.apcaMet).length,
|
|
195
184
|
},
|
|
196
|
-
};
|
|
185
|
+
}, "encoded", { value: encoded });
|
|
197
186
|
}
|
|
198
187
|
|
|
199
188
|
const TOKEN_ORDER = new Map(SEMANTIC_COLOR_NAMES.map((name, index) => [name, index]));
|
|
@@ -240,10 +229,33 @@ export function formatThemeResolve(result) {
|
|
|
240
229
|
]));
|
|
241
230
|
}
|
|
242
231
|
}
|
|
232
|
+
for (const [scheme, entries] of Object.entries(result.chrome ?? {})) {
|
|
233
|
+
for (const entry of entries) {
|
|
234
|
+
if (entry.pairs.length === 0) continue;
|
|
235
|
+
const location = entry.context === null ? "page (root)" : `context ${entry.context}${entry.contextTruncated ? "…" : ""}`;
|
|
236
|
+
lines.push("", `${scheme} · ${entry.role} · ${location}`);
|
|
237
|
+
lines.push(table([
|
|
238
|
+
["element/state", "ink", "on", "ratio", "needs", ""],
|
|
239
|
+
...entry.pairs.map((row) => {
|
|
240
|
+
const pair = decodeChromePair(result.chromeCatalog, row);
|
|
241
|
+
return [
|
|
242
|
+
`${pair.element}/${pair.state}`, pair.foreground, pair.background,
|
|
243
|
+
`${pair.ratio.toFixed(2)}:1`, `${pair.required.toFixed(2)}:1`,
|
|
244
|
+
pair.ratio < pair.required ? "BELOW AA" : "ok",
|
|
245
|
+
];
|
|
246
|
+
}),
|
|
247
|
+
]));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (result.chromeUnavailable) lines.push("", CHROME_UNAVAILABLE_MESSAGE);
|
|
251
|
+
if (result.chromeNavigationUnavailable) lines.push("", CHROME_NAVIGATION_UNAVAILABLE_MESSAGE);
|
|
243
252
|
const { belowAa, pairs } = result.contrast;
|
|
253
|
+
const measured = result.chromeUnavailable ? " measured" : "";
|
|
254
|
+
const codes = [...new Set(result.flags.items.map((flag) => flag.code))];
|
|
255
|
+
const flags = codes.length > 0 ? ` (flags: ${codes.join(", ")})` : "";
|
|
244
256
|
lines.push("", belowAa === 0
|
|
245
|
-
? `All ${pairs} pairs meet WCAG AA.`
|
|
246
|
-
: `${belowAa} of ${pairs} pairs are below WCAG AA
|
|
257
|
+
? `All ${pairs}${measured} pairs meet WCAG AA.`
|
|
258
|
+
: `${belowAa} of ${pairs}${measured} pairs are below WCAG AA${flags}.`);
|
|
247
259
|
if (result.omittedSurfaces !== undefined) {
|
|
248
260
|
const names = result.omittedSurfaces.items.map((entry) => `${entry.scheme}/${entry.context ?? "root"}`);
|
|
249
261
|
lines.push(`Not shown (result size): ${names.join(", ")}${result.omittedSurfaces.truncated ? ", and more" : ""}. Narrow with --scheme and --context.`);
|
package/src/theme-validation.js
CHANGED
|
@@ -422,7 +422,7 @@ let fitReport;
|
|
|
422
422
|
* actually checked. The exact Espalier pin and this package's tests catch a
|
|
423
423
|
* release that moves it.
|
|
424
424
|
*/
|
|
425
|
-
function loadFitReport() {
|
|
425
|
+
export function loadFitReport() {
|
|
426
426
|
fitReport ??= loadEspalierShared("theme-fit-report.js");
|
|
427
427
|
return fitReport;
|
|
428
428
|
}
|
|
@@ -515,7 +515,16 @@ export async function validateAndLintThemePair(lightTheme, darkTheme) {
|
|
|
515
515
|
fit,
|
|
516
516
|
});
|
|
517
517
|
const unbuilt = items.filter((item) => item.lint === undefined).map((item) => item.text);
|
|
518
|
-
|
|
518
|
+
const warningGroups = { validation: proposed.warnings, unbuilt, lints: proposed.lints, inert };
|
|
519
|
+
const themes = Object.defineProperty({ light, dark }, "warningGroups", { value: warningGroups });
|
|
520
|
+
return withChromeWarnings(themes, []);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** Finish warning publication from the complete groups, before the shared cap. */
|
|
524
|
+
export function withChromeWarnings(themes, chromeWarnings) {
|
|
525
|
+
const { validation, unbuilt, lints, inert } = themes.warningGroups;
|
|
526
|
+
const bounded = boundedThemeWarnings([...validation, ...unbuilt, ...lints, ...chromeWarnings, ...inert]);
|
|
527
|
+
return Object.defineProperty({ ...themes, ...bounded }, "warningGroups", { value: themes.warningGroups });
|
|
519
528
|
}
|
|
520
529
|
|
|
521
530
|
function checkThemePair(lightTheme, darkTheme) {
|