@taprootio/site-authoring 0.42.0 → 0.56.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.
Files changed (80) hide show
  1. package/README.md +110 -12
  2. package/examples/riverbend-wellness/settings/site-publishing-preferences.json +3 -0
  3. package/examples/riverbend-wellness/settings/taproot-styles.json +11 -0
  4. package/package.json +4 -3
  5. package/src/api.js +242 -23
  6. package/src/appearance-contract.js +264 -3
  7. package/src/authored-tag-names.js +88 -0
  8. package/src/authors-contract.js +71 -3
  9. package/src/block-flow.js +103 -1
  10. package/src/brand-color.js +22 -0
  11. package/src/breadcrumb-artwork.js +234 -0
  12. package/src/breadcrumb-separators.js +11 -0
  13. package/src/changelog.json +160 -0
  14. package/src/chrome-features.js +6 -2
  15. package/src/chrome-input.js +1 -0
  16. package/src/chrome-paint-catalog-taproot.json +3 -3
  17. package/src/chrome-report.js +91 -12
  18. package/src/cli.js +136 -38
  19. package/src/constants.js +1 -0
  20. package/src/content/components.js +27 -4
  21. package/src/content/external-link.js +2 -1
  22. package/src/content/markdown.js +271 -101
  23. package/src/content/tiptap-prosemirror.ts +125 -43
  24. package/src/content/validate-document.js +4 -1
  25. package/src/content-inset.js +48 -0
  26. package/src/errors.js +1 -0
  27. package/src/espalier-shared.js +26 -0
  28. package/src/field-suggestions.js +40 -0
  29. package/src/fixture-init.js +22 -5
  30. package/src/font-catalog.js +11 -1
  31. package/src/footer-brand-inputs.js +22 -3
  32. package/src/footer-content.js +1 -0
  33. package/src/footer-contract.js +11 -0
  34. package/src/footer-cta-styles.js +6 -0
  35. package/src/footer-draft-hash.js +4 -2
  36. package/src/footer-fit.js +62 -15
  37. package/src/footer-workspace.js +44 -7
  38. package/src/latest-posts-tags.js +57 -0
  39. package/src/page-metadata.js +15 -13
  40. package/src/page-structure-checks.js +5 -0
  41. package/src/page-tag-badge-modes.js +6 -0
  42. package/src/page-tag-writes.js +158 -0
  43. package/src/page-type-tags.js +16 -0
  44. package/src/presentation-reference.js +297 -86
  45. package/src/recipe-page-options.js +22 -0
  46. package/src/recipe-step-contract.js +164 -0
  47. package/src/recipe-step-contract.json +65 -0
  48. package/src/reference-help.js +182 -79
  49. package/src/session.js +39 -24
  50. package/src/setting-reference.js +239 -48
  51. package/src/settings-catalog.js +63 -0
  52. package/src/site-check-findings.js +23 -5
  53. package/src/site-check-rules.json +1 -0
  54. package/src/site-health-findings.js +13 -13
  55. package/src/styling-fixed-values.js +71 -0
  56. package/src/tag-destination-warnings.js +35 -0
  57. package/src/template-token-reach.json +242 -0
  58. package/src/theme-proposals.js +18 -27
  59. package/src/theme-resolve.js +265 -23
  60. package/src/theme-validation.js +118 -7
  61. package/src/token-reach.js +222 -0
  62. package/src/typed-page-reference.js +94 -16
  63. package/src/typed-pages.js +233 -74
  64. package/src/verbs/authors.js +198 -33
  65. package/src/verbs/deploy.js +6 -0
  66. package/src/verbs/footer-push.js +30 -5
  67. package/src/verbs/forms-push.js +11 -3
  68. package/src/verbs/index.js +4 -2
  69. package/src/verbs/pages-delete.js +19 -10
  70. package/src/verbs/pages-push.js +225 -71
  71. package/src/verbs/plan.js +10 -4
  72. package/src/verbs/pull.js +324 -69
  73. package/src/verbs/staging-review.js +27 -1
  74. package/src/verbs/status.js +22 -0
  75. package/src/verbs/theme-push.js +93 -25
  76. package/src/verbs/theme-resolve.js +189 -55
  77. package/src/verbs/validate.js +6 -5
  78. package/src/workspace-check.js +35 -3
  79. package/src/workspace.js +73 -2
  80. package/test/fixtures/default-site-theme.json +516 -0
@@ -3,10 +3,12 @@ import {
3
3
  getDeploySelection,
4
4
  getPublishingReadiness,
5
5
  getSiteHealth,
6
+ getStagingPreviewStatus,
6
7
  IMAGE_PROCESSING_STATE_COMPLETE,
7
8
  IMAGE_PROCESSING_STATE_FAILED,
8
9
  listDeployments,
9
10
  listSiteImages,
11
+ STAGING_HOSTING_SETUP_GUIDANCE,
10
12
  withRefusalGuidance,
11
13
  } from "../api.js";
12
14
  import { installedWhatsNew } from "../changelog.js";
@@ -162,6 +164,24 @@ async function summarizeStagedHealth(client, siteId, stagedDeploymentId, onProgr
162
164
  };
163
165
  }
164
166
 
167
+ async function reportStagingHosting(client, siteId, onProgress) {
168
+ let hosting;
169
+ try {
170
+ hosting = await getStagingPreviewStatus(client, siteId);
171
+ } catch (error) {
172
+ const reason = `Staging hosting status could not be read (${readFailureCode(error)}).`;
173
+ onProgress(reason);
174
+ return { readyKnown: false, reason };
175
+ }
176
+ const releaseStatus = hosting.hasStagedRelease === undefined ? {} : { hasStagedRelease: hosting.hasStagedRelease };
177
+ if (!hosting.ready) {
178
+ onProgress(`Staging hosting: no ready address. ${STAGING_HOSTING_SETUP_GUIDANCE}`);
179
+ return { ready: false, guidance: STAGING_HOSTING_SETUP_GUIDANCE, ...releaseStatus };
180
+ }
181
+ onProgress(`Staging hosting: ${hosting.stagingUrl}`);
182
+ return { ready: true, url: hosting.stagingUrl, ...releaseStatus };
183
+ }
184
+
165
185
  export async function status(invocation) {
166
186
  const { client, siteId, surface, platform, release, onProgress } = await openSession(invocation);
167
187
  const presentationOnly = surface === SURFACE_DOCS_PRESENTATION;
@@ -183,6 +203,7 @@ export async function status(invocation) {
183
203
  ? { ...reviewed, stagedPageIds: [], includeNavigation: false }
184
204
  : reviewed;
185
205
  const readiness = await getPublishingReadiness(client, siteId, selection);
206
+ const stagingHosting = await reportStagingHosting(client, siteId, onProgress);
186
207
  onProgress("Reading the deployment log.");
187
208
  const {
188
209
  deployments,
@@ -251,6 +272,7 @@ export async function status(invocation) {
251
272
  blockers: blockers.items,
252
273
  ...(blockers.truncated ? { blockersTruncated: true } : {}),
253
274
  },
275
+ stagingHosting,
254
276
  deployments: {
255
277
  // One page of the log, not the site's history. `listTruncated` says so
256
278
  // rather than letting `total` read as a count of every deployment the
@@ -4,27 +4,36 @@ import {
4
4
  APPEARANCE_SCALAR_FIELDS,
5
5
  appearanceScalarInput,
6
6
  buildAppearanceScalarOperations,
7
+ refuseRetiredScalarFonts,
8
+ checkTagDestinationTargets,
9
+ normalizeTagDestinations,
10
+ readBreadcrumbArtworkSettings,
11
+ tagDestinationCatalogSlugs,
7
12
  footerPresentationOverlay,
8
13
  } from "../appearance-contract.js";
9
14
  import { captureChromeResources, selectNameReportEligibility } from "../chrome-input.js";
10
15
  import { completeChromeReport } from "../chrome-report.js";
11
16
  import { REFUSAL_UNCLASSIFIED, VERB_THEME_PUSH } from "../constants.js";
12
17
  import { MISSING_SETTING_MESSAGE, SiteAuthoringError } from "../errors.js";
13
- import { projectFooterSettingsForWorkspace } from "../footer-contract.js";
18
+ import { projectFooterSettingsForWorkspace, validateFooterDocument } from "../footer-contract.js";
14
19
  import {
15
20
  advanceFooterManifest,
16
21
  clearPendingPresentationSave,
22
+ compareFooterContent,
17
23
  computePresentationChangeSetHash,
24
+ hasFooterContentEdits,
18
25
  readAppearanceWorkspaceContext,
19
26
  readPendingPresentationSave,
20
27
  readPresentationBaseline,
21
28
  recordPendingPresentationSave,
29
+ reportFooterPreview,
22
30
  requireFooterContentPushed,
23
31
  } from "../footer-workspace.js";
24
32
  import { describeJsonDifferences } from "../json-path-diff.js";
25
- import { boundedList, openSession, successResult, warnIfExternalWritesPaused } from "../session.js";
33
+ import { boundedList, resolveSiteSession, successResult, warnIfExternalWritesPaused } from "../session.js";
26
34
  import {
27
35
  projectSettingsGroup,
36
+ requireKnownAppearanceSettings,
28
37
  SETTINGS_GROUPS,
29
38
  SETTINGS_TYPE_BRAND,
30
39
  SETTINGS_TYPE_SITE_HEADER,
@@ -32,6 +41,7 @@ import {
32
41
  SETTINGS_TYPE_TAPROOT_STYLES,
33
42
  } from "../settings-catalog.js";
34
43
  import { missingThemeFields, requireSurfaceContexts, validateAndLintThemePair, withChromeWarnings } from "../theme-validation.js";
44
+ import { missingTagDestinations, reportTagDestinationWarnings } from "../tag-destination-warnings.js";
35
45
  import { ApiError } from "../transport.js";
36
46
  import {
37
47
  readWorkspaceJson,
@@ -64,7 +74,7 @@ function fail(code, message, field) {
64
74
  throw new SiteAuthoringError(code, message, { field });
65
75
  }
66
76
 
67
- async function readBoundSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId = siteId) {
77
+ export async function readBoundSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId = siteId) {
68
78
  const file = `${SETTINGS_DIRECTORY}/${SETTINGS_FILES[settingsType]}`;
69
79
  if (!await workspaceFileExists(workspaceDir, file)) {
70
80
  fail("theme.settings_missing", `Workspace file '${file}' is missing. Run 'taproot-site pull' first.`, file);
@@ -86,7 +96,10 @@ async function readBoundSettingsDocument(workspaceDir, siteId, settingsType, exp
86
96
  }
87
97
 
88
98
  export async function readSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId) {
89
- return (await readBoundSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId)).settings;
99
+ const { settings } = await readBoundSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId);
100
+ return settingsType === SETTINGS_TYPE_TAPROOT_STYLES
101
+ ? readBreadcrumbArtworkSettings(workspaceDir, settings)
102
+ : settings;
90
103
  }
91
104
 
92
105
  /** The theme paths the styles document lacks, both schemes, in the order theme push reports them. */
@@ -123,7 +136,7 @@ export async function validateThemeWorkspace(
123
136
  siteId,
124
137
  knownImageIds,
125
138
  expectedEntityIds,
126
- { deferContextValidation = false } = {},
139
+ { deferContextValidation = false, fixtureExport = false } = {},
127
140
  ) {
128
141
  const [style, brand, header, publishingDocument] = await Promise.all([
129
142
  readSettingsDocument(
@@ -152,11 +165,20 @@ export async function validateThemeWorkspace(
152
165
  ),
153
166
  ]);
154
167
  const { settings: publishing } = publishingDocument;
168
+ for (const name of ["tagDestinations", "recipeMetadataDestinations"]) {
169
+ if (Object.hasOwn(publishing, name)) {
170
+ publishing[name] = normalizeTagDestinations(publishing[name], `site-publishing-preferences.${name}`);
171
+ }
172
+ }
155
173
  const documents = {
156
174
  [SETTINGS_TYPE_TAPROOT_STYLES]: style,
157
175
  [SETTINGS_TYPE_BRAND]: brand,
158
176
  [SETTINGS_TYPE_SITE_HEADER]: header,
177
+ [SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]: publishing,
159
178
  };
179
+ refuseRetiredScalarFonts(style);
180
+ // Fixture export validates again after projecting the source onto the settings catalog.
181
+ if (!fixtureExport) requireKnownAppearanceSettings(documents);
160
182
  // Preflight the complete required-key inventory before any value validator
161
183
  // can stop at a malformed value in an earlier group. Optional presentation
162
184
  // fields retain their empty default.
@@ -269,10 +291,12 @@ function ownedDocuments(validated, projected) {
269
291
  remote: Object.fromEntries(names.map((name) => [name, valueOf(settingsType, remote, name)])),
270
292
  });
271
293
  const scalarNames = (settingsType) =>
272
- APPEARANCE_SCALAR_FIELDS.filter((field) => field.settingsType === settingsType).map((field) => field.name);
273
- const footerPresentation = footer => ({
294
+ APPEARANCE_SCALAR_FIELDS.filter((field) => field.settingsType === settingsType
295
+ && (!field.onlyIfPresent || Object.hasOwn(validated.publishing, field.name))).map((field) => field.name);
296
+ const publishingDocument = document => ({
297
+ ...document,
274
298
  footerSettings: Object.fromEntries(
275
- APPEARANCE_FOOTER_FIELDS.map(field => [field.name, footer?.[field.name] ?? field.default]),
299
+ APPEARANCE_FOOTER_FIELDS.map(field => [field.name, document.footerSettings?.[field.name] ?? field.default]),
276
300
  ),
277
301
  });
278
302
  return [
@@ -289,11 +313,12 @@ function ownedDocuments(validated, projected) {
289
313
  projected[SETTINGS_TYPE_SITE_HEADER],
290
314
  scalarNames(SETTINGS_TYPE_SITE_HEADER),
291
315
  ),
292
- {
293
- file: `${SETTINGS_DIRECTORY}/${SETTINGS_FILES[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]}`,
294
- local: footerPresentation(validated.publishing.footerSettings),
295
- remote: footerPresentation(projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].footerSettings),
296
- },
316
+ owned(
317
+ SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
318
+ publishingDocument(validated.publishing),
319
+ publishingDocument(projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]),
320
+ [...scalarNames(SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES), "footerSettings"],
321
+ ),
297
322
  ];
298
323
  }
299
324
 
@@ -369,6 +394,25 @@ export async function comparePresentation(client, siteId, validated, manifest) {
369
394
  const projected = Object.fromEntries(SETTINGS_GROUPS.map((group) => [
370
395
  group.settingsType, projectSettingsGroup(group, current),
371
396
  ]));
397
+ if (validated.publishing.tagDestinations !== undefined) {
398
+ checkTagDestinationTargets(
399
+ validated.publishing.tagDestinations,
400
+ projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].tagDestinations,
401
+ manifest,
402
+ undefined,
403
+ tagDestinationCatalogSlugs(current.tagDestinationCatalog),
404
+ );
405
+ }
406
+ if (validated.publishing.recipeMetadataDestinations !== undefined) {
407
+ checkTagDestinationTargets(
408
+ validated.publishing.recipeMetadataDestinations,
409
+ projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].recipeMetadataDestinations,
410
+ manifest,
411
+ undefined,
412
+ undefined,
413
+ true,
414
+ );
415
+ }
372
416
  const differences = describeDifferences(validated, projected);
373
417
  return {
374
418
  baseline,
@@ -485,29 +529,33 @@ async function adoptSavedFooter(workspaceDir, siteId, presentation, publishing)
485
529
  // a failure here leaves a stale baseline that refuses the next push rather
486
530
  // than one that overwrites the save.
487
531
  const projectedFooter = projectFooterSettingsForWorkspace(savedFooter);
532
+ const { tagDestinations, recipeMetadataDestinations } = presentation.sitePublishingPreferences ?? {};
533
+ const settings = { ...publishing, footerSettings: projectedFooter };
534
+ for (const [name, destinations] of Object.entries({ tagDestinations, recipeMetadataDestinations })) {
535
+ if (destinations !== undefined || settings[name] !== undefined) settings[name] = destinations ?? {};
536
+ }
488
537
  await writeWorkspaceJson(
489
538
  workspaceDir,
490
539
  `${SETTINGS_DIRECTORY}/${SETTINGS_FILES[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]}`,
491
540
  {
492
541
  entityId: siteId,
493
542
  settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
494
- settings: { ...publishing, footerSettings: projectedFooter },
543
+ settings,
495
544
  },
496
545
  );
497
546
  await advanceFooterManifest(workspaceDir, siteId, projectedFooter, undefined, {
498
547
  presentationRevision: presentation.revision,
548
+ tagDestinations,
549
+ recipeMetadataDestinations,
550
+ authoredTagSlugs: tagDestinationCatalogSlugs(presentation.tagDestinationCatalog),
499
551
  });
500
552
  return projectedFooter;
501
553
  }
502
554
 
503
555
  export async function themePush(invocation, chromeDependencies) {
504
- const session = await openSession(invocation);
505
- const { client, config, siteId, onProgress } = session;
556
+ const resolved = await resolveSiteSession(invocation);
557
+ const { config, siteId } = resolved;
506
558
  const dryRun = invocation.dryRun === true;
507
- // One advisory line before this verb does any work, and only when the
508
- // exchange said the platform is paused. It changes nothing else: the write
509
- // still runs and its refusal still classifies as platform_paused (TR00692).
510
- if (!dryRun) warnIfExternalWritesPaused(session, VERB_THEME_PUSH);
511
559
  const appearanceContext = await readAppearanceWorkspaceContext(config.workspaceDir, siteId);
512
560
  const validated = await validateThemeWorkspace(
513
561
  config.workspaceDir,
@@ -520,11 +568,17 @@ export async function themePush(invocation, chromeDependencies) {
520
568
  // The save's response replaces the workspace footer document, so refuse
521
569
  // while it still carries footer-content edits that footer push has not
522
570
  // saved. Context-only differences are theme push's own to write.
523
- requireFooterContentPushed(appearanceContext.footer, publishing.footerSettings);
571
+ if (!dryRun) requireFooterContentPushed(appearanceContext.footer, publishing.footerSettings);
572
+ const proposedFooter = dryRun && hasFooterContentEdits(appearanceContext.footer, publishing.footerSettings)
573
+ ? validateFooterDocument(publishing.footerSettings, appearanceContext)
574
+ : undefined;
524
575
  const baseline = readPresentationBaseline(appearanceContext.manifest);
525
576
  if (!dryRun && baseline === undefined) {
526
577
  throw presentationPullRequired();
527
578
  }
579
+ const session = await resolved.open();
580
+ const { client, onProgress } = session;
581
+ if (!dryRun) warnIfExternalWritesPaused(session, VERB_THEME_PUSH);
528
582
  onProgress(`Validated the complete light/dark theme pair and ${scalarOperations.length} appearance settings.`);
529
583
  let comparison;
530
584
  let resources;
@@ -559,11 +613,19 @@ export async function themePush(invocation, chromeDependencies) {
559
613
  const { manifest } = appearanceContext;
560
614
 
561
615
  if (dryRun) {
562
- // The save overlays the proposed context and variant on the site's
563
- // footer, and leaves publishing preferences and asset delivery in place.
616
+ const proposedPublishing = { ...current.sitePublishingPreferences, ...publishing };
617
+ const tagDestinationWarnings = reportTagDestinationWarnings(missingTagDestinations(proposedPublishing, manifest), onProgress);
618
+ const footerContent = proposedFooter === undefined
619
+ ? undefined
620
+ : compareFooterContent(appearanceContext.footer, comparison.currentFooter, proposedFooter);
564
621
  const warnings = await completePushWarnings(
565
622
  validated,
566
- { ...resources, footerSettings: comparison.currentFooter, presentation: current },
623
+ {
624
+ ...resources,
625
+ footerSettings: proposedFooter ?? comparison.currentFooter,
626
+ presentation: current,
627
+ badgeSettings: proposedPublishing,
628
+ },
567
629
  { current, manifest },
568
630
  onProgress,
569
631
  chromeDependencies,
@@ -572,7 +634,11 @@ export async function themePush(invocation, chromeDependencies) {
572
634
  if (entry.paths.length === 0 && entry.truncated !== true) continue;
573
635
  onProgress(`${entry.file} differs at: ${entry.paths.join(", ")}${entry.truncated ? ", and more" : ""}.`);
574
636
  }
575
- if (!changed) onProgress("The workspace's presentation matches the site; a push would change nothing.");
637
+ if (footerContent !== undefined) {
638
+ reportFooterPreview(footerContent, onProgress);
639
+ onProgress("Run footer push to save footer content before a live theme push.");
640
+ }
641
+ if (!changed) onProgress("The workspace's presentation matches the site; a theme push would change nothing.");
576
642
  if (baseline === undefined) {
577
643
  onProgress(
578
644
  "The pull manifest records no presentation baseline; a push would refuse until the workspace is re-pulled.",
@@ -605,6 +671,8 @@ export async function themePush(invocation, chromeDependencies) {
605
671
  }),
606
672
  changed,
607
673
  differences,
674
+ ...(footerContent === undefined ? {} : { footerContent }),
675
+ ...(tagDestinationWarnings === undefined ? {} : { tagDestinationWarnings }),
608
676
  warnings,
609
677
  });
610
678
  }
@@ -1,16 +1,17 @@
1
- import { AA_LARGE_RATIO, AA_TEXT_RATIO } from "@taprootio/espalier/shared/theme";
1
+ import { AA_LARGE_RATIO, AA_TEXT_RATIO, SEMANTIC_COLOR_NAMES } from "@taprootio/espalier/shared/theme";
2
2
 
3
3
  import { getNavigation, getSitePresentation, withRefusalGuidance } from "../api.js";
4
4
  import { appearanceImageIds, footerPresentationOverlay, validateAppearanceScalarGroup } from "../appearance-contract.js";
5
+ import { BREADCRUMB_ARTWORK_FIELDS } from "../breadcrumb-artwork.js";
5
6
  import { CAPABILITY_CONTENT } from "../capabilities.js";
6
7
  import { captureChromeResources } from "../chrome-input.js";
7
- import { displayChromeContext, indexChromePaint } from "../chrome-output.js";
8
- import { completeChromeReport } from "../chrome-report.js";
8
+ import { displayChromeContext, displayChromeRatio, indexChromePaint } from "../chrome-output.js";
9
+ import { completeChromeReport, RECIPE_TAG_ICON_CONTRAST } from "../chrome-report.js";
9
10
  import { LIMITS, SURFACE_DOCS_PRESENTATION, SURFACE_STANDARD, VERB_THEME_RESOLVE } from "../constants.js";
10
11
  import { SiteAuthoringError } from "../errors.js";
11
12
  import { footerImageIds, validateFooterDocument } from "../footer-contract.js";
12
13
  import { appearanceResourceIds } from "../footer-workspace.js";
13
- import { CHECK_AREA, collectProblems, refuseProblems, withinByteBudget } from "../problems.js";
14
+ import { CHECK_AREA, collectProblems, refuseProblems } from "../problems.js";
14
15
  import { boundedByBytes, openAnonymousSession, openSession, successResult } from "../session.js";
15
16
  import {
16
17
  projectSettingsGroup,
@@ -20,18 +21,18 @@ import {
20
21
  SETTINGS_TYPE_TAPROOT_STYLES,
21
22
  } from "../settings-catalog.js";
22
23
  import { resolveThemePair, THEME_STYLES_FILE } from "../theme-resolve.js";
24
+ import { abbreviateThemeContext } from "../theme-validation.js";
25
+ import { buildTokenPaintCatalog } from "../token-reach.js";
23
26
  import { readManifest, readMediaManifest } from "../workspace.js";
24
27
  import { validateNavigationWorkspaceDocument } from "./nav-push.js";
25
- import { missingThemeSettings, readSettingsDocument, requireNoMissingSettings } from "./theme-push.js";
28
+ import { missingThemeSettings, readBoundSettingsDocument, readSettingsDocument, requireNoMissingSettings } from "./theme-push.js";
26
29
 
27
- // A result must fit LIMITS.githubOutputBytes (64 KiB), and a theme may declare 128 contexts a scheme. The lists that
28
- // grow with the theme are bounded first, each by its own share; surfaces then take what is left, and the ones past
29
- // it are named in omittedSurfaces to be fetched with --scheme and --context.
30
- const RESULT_ENVELOPE_BYTES = 4 * 1024;
30
+ // Bound variable diagnostics before budgeting complete surfaces against the real result.
31
31
  const FLAG_BYTE_BUDGET = 10 * 1024;
32
32
  const NAME_LIST_BYTE_BUDGET = 6 * 1024;
33
- // The maximal indexed catalog and cards occupy 9,772 bytes. Adding 25% rounds up to 12 KiB.
34
- export const CHROME_BYTE_BUDGET = 12 * 1024;
33
+ // The chrome catalog contract keeps the maximal fixture within this ceiling.
34
+ // Resolve charges each command for the cards it actually returns.
35
+ export const CHROME_BYTE_BUDGET = 13 * 1024;
35
36
 
36
37
  const STYLES_GROUP = SETTINGS_GROUPS.find((group) => group.settingsType === SETTINGS_TYPE_TAPROOT_STYLES);
37
38
  const HEADER_GROUP = SETTINGS_GROUPS.find((group) => group.settingsType === SETTINGS_TYPE_SITE_HEADER);
@@ -59,7 +60,10 @@ async function readThemes(invocation) {
59
60
  "No site is selected. Run 'taproot-site use <site>' to choose one, or set siteId in taproot-site.json.",
60
61
  );
61
62
  }
62
- const style = await readSettingsDocument(config.workspaceDir, config.siteId, SETTINGS_TYPE_TAPROOT_STYLES);
63
+ const { settings } = await readBoundSettingsDocument(config.workspaceDir, config.siteId, SETTINGS_TYPE_TAPROOT_STYLES);
64
+ const style = { ...settings };
65
+ // Artwork does not affect the colors or chrome this report measures.
66
+ for (const field of BREADCRUMB_ARTWORK_FIELDS) delete style[field];
63
67
  // The same preflight push and validate run, so a stale workspace gets the same code and the full path list.
64
68
  requireNoMissingSettings(missingThemeSettings(style));
65
69
  return { siteId: config.siteId, source: "workspace", style, config };
@@ -152,15 +156,127 @@ function selectChrome(report, { themeScheme, themeContext }) {
152
156
  .filter(([scheme]) => themeScheme === undefined || themeScheme === scheme)
153
157
  .map(([scheme, surfaces]) => [scheme, surfaces.filter(matchesContext)]));
154
158
  const flags = report.flags.filter((flag) => Object.hasOwn(entries, flag.scheme) && matchesContext(flag));
159
+ const badgePairs = Object.keys(entries).flatMap(scheme => report.badges[scheme].filter(matchesContext).flatMap(({ pairs }) => pairs.filter(({ kind }) => kind === "ring")));
155
160
  return {
156
161
  ...indexChromePaint(entries),
157
162
  unavailable: report.unavailable,
158
163
  navigationUnavailable: report.navigationUnavailable,
159
164
  flags: flags.map((flag) => ({ ...flag, context: displayChromeContext(flag.context).context })),
160
- contrast: { pairs: Object.values(entries).flat().reduce((count, entry) => count + entry.pairs.length, 0), belowAa: flags.length },
165
+ contrast: { pairs: Object.values(entries).flat().reduce((count, entry) => count + entry.pairs.length, badgePairs.length), belowAa: flags.filter(({ code }) => code !== RECIPE_TAG_ICON_CONTRAST).length },
161
166
  };
162
167
  }
163
168
 
169
+ function footerLinkOnLayer2(report, scheme, surface) {
170
+ return surface.footerInks === undefined && surface.tokens.some(({ token, adjusted }) => token === "link" && adjusted)
171
+ && report.entries[scheme]?.some(({ role, context, pairs }) =>
172
+ role === "footer" && context === surface.context && pairs.some(({ element, state, foreground, background }) =>
173
+ element === "footer-link" && state === "rest" && foreground === "link" && background === "layer2"
174
+ )
175
+ );
176
+ }
177
+
178
+ function resultBytes(result) {
179
+ return Buffer.byteLength(JSON.stringify(result), "utf8");
180
+ }
181
+
182
+ function reportEnvelope(siteId, source, contexts, entries, semanticFlags, chrome) {
183
+ const allFlags = [...semanticFlags, ...chrome.flags];
184
+ const flags = { ...boundedByBytes(allFlags, FLAG_BYTE_BUDGET), count: allFlags.length };
185
+ const contrast = { pairs: chrome.contrast.pairs, belowAa: chrome.contrast.belowAa, belowApca: 0 };
186
+ for (const { surface } of entries) {
187
+ for (const pair of surface.pairs) {
188
+ contrast.pairs += 1;
189
+ contrast.belowAa += Number(!pair.aa);
190
+ contrast.belowApca += Number(!pair.apcaMet);
191
+ }
192
+ for (const ink of surface.footerInks ?? []) contrast.belowApca += Number(ink.resolvedLc < ink.targetLc);
193
+ }
194
+ return successResult(VERB_THEME_RESOLVE, siteId, {
195
+ source,
196
+ thresholds: { textRatio: AA_TEXT_RATIO, largeRatio: AA_LARGE_RATIO },
197
+ contexts,
198
+ chrome: chrome.chrome,
199
+ chromeCatalog: chrome.chromeCatalog,
200
+ ...(chrome.unavailable ? { chromeUnavailable: true } : {}),
201
+ ...(chrome.navigationUnavailable ? { chromeNavigationUnavailable: true } : {}),
202
+ contrast,
203
+ flags,
204
+ });
205
+ }
206
+
207
+ function tokenCandidates(entries) {
208
+ const selected = new Set();
209
+ for (const { surface } of entries) {
210
+ for (const { token, origin, adjusted } of surface.tokens) {
211
+ if (origin !== "compiled" || adjusted) selected.add(token);
212
+ }
213
+ }
214
+ return SEMANTIC_COLOR_NAMES.filter((name) => selected.has(name));
215
+ }
216
+
217
+ function paintsForReport(candidates, shown = []) {
218
+ const omittedTokens = candidates.filter((name) => !shown.includes(name));
219
+ return {
220
+ ...(shown.length > 0 ? buildTokenPaintCatalog(shown) : { tokens: {} }),
221
+ ...(omittedTokens.length > 0 ? { omittedTokens, omittedTokensHelp: "taproot-site help tokens" } : {}),
222
+ };
223
+ }
224
+
225
+ function assembleReport(envelope, entries, omissions, paints) {
226
+ const byScheme = new Map();
227
+ for (const { scheme, surface, footerLinkOnLayer2, badgePaint } of entries) {
228
+ if (!byScheme.has(scheme)) byScheme.set(scheme, []);
229
+ byScheme.get(scheme).push({
230
+ ...surface,
231
+ ...(footerLinkOnLayer2 ? { footerLinkOnLayer2 } : {}),
232
+ ...(badgePaint?.length ? { badgePaint } : {}),
233
+ });
234
+ }
235
+ const schemes = [...byScheme].map(([scheme, surfaces]) => ({ scheme, surfaces }));
236
+ const oversizedCount = omissions.filter(({ reason }) => reason === "surface_too_large").length;
237
+ const retryRootSchemes = omissions.filter(({ context, reason }) => context === null && reason === undefined)
238
+ .map(({ scheme }) => scheme);
239
+ return {
240
+ ...envelope,
241
+ schemes,
242
+ ...paints,
243
+ ...(omissions.length > 0 ? {
244
+ omittedSurfaces: {
245
+ ...boundedByBytes(omissions, NAME_LIST_BYTE_BUDGET),
246
+ count: omissions.length,
247
+ ...(oversizedCount > 0 ? { oversizedCount } : {}),
248
+ ...(retryRootSchemes.length > 0 ? { retryRootSchemes } : {}),
249
+ },
250
+ } : {}),
251
+ };
252
+ }
253
+
254
+ function omission(entry, contextPositions, tooLarge) {
255
+ const { scheme, surface: { context } } = entry;
256
+ const label = context === null ? null : abbreviateThemeContext(context, LIMITS.diagnosticScalars, contextPositions.get(context));
257
+ return { scheme, context: label, ...(tooLarge ? { reason: "surface_too_large" } : {}) };
258
+ }
259
+
260
+ function canShowAfterNarrowing(entry, { resolution, entries, contexts, chromeReport, contextPositions, siteId, source, oversized }) {
261
+ const { scheme, surface } = entry;
262
+ // Root retry keeps the named contexts and chrome in the same scheme.
263
+ const context = surface.context ?? undefined;
264
+ const matches = (row, rowContext) => row.scheme === scheme && (context === undefined || rowContext === context);
265
+ const narrowed = entries.filter((row) => matches(row, row.surface.context));
266
+ const flags = resolution.flags.filter((flag) => matches(flag, flag.context));
267
+ const chrome = selectChrome(chromeReport, { themeScheme: scheme, themeContext: context });
268
+ const envelope = reportEnvelope(siteId, source, contexts, narrowed, flags, chrome);
269
+ const paints = paintsForReport(tokenCandidates(narrowed));
270
+ const otherOmissions = narrowed.filter((row) => row !== entry)
271
+ .map((row) => omission(row, contextPositions, oversized.has(row)));
272
+ const bytes = (candidate) =>
273
+ resultBytes(assembleReport(envelope, [{ ...entry, surface: candidate }], otherOmissions, paints));
274
+ const unexpanded = bytes(surface);
275
+ if (unexpanded > LIMITS.githubOutputBytes) return false;
276
+ if (unexpanded + resolution.passingStopByteBound(surface) <= LIMITS.githubOutputBytes) return true;
277
+ return bytes(resolution.enrichSurface(scheme, surface)) <= LIMITS.githubOutputBytes;
278
+ }
279
+
164
280
  /**
165
281
  * `theme resolve` — what Espalier compiles from the stored light and dark
166
282
  * themes: every semantic color per scheme and context, and the contrast of
@@ -171,57 +287,75 @@ export async function themeResolve(invocation, chromeDependencies) {
171
287
  const input = await readThemes(invocation);
172
288
  const { siteId, source, style: { lightTheme, darkTheme } } = input;
173
289
  const problems = [];
290
+ const evidence = await readReportEvidence(input);
291
+ const footer = evidence.resources.footerSettings;
174
292
  const resolution = await collectProblems(
175
293
  problems,
176
294
  { area: CHECK_AREA.presentation, file: THEME_STYLES_FILE },
177
295
  async () => await resolveThemePair(lightTheme, darkTheme, {
178
296
  scheme: invocation.themeScheme,
179
297
  context: invocation.themeContext,
298
+ footerContext: footer?.enabled === true ? footer.context || null : undefined,
299
+ deferPassingStops: true,
180
300
  }),
181
301
  );
182
302
  refuseProblems(problems, "theme resolve");
183
303
 
184
- const evidence = await readReportEvidence(input);
185
- const chrome = selectChrome(await completeChromeReport({ ...evidence, themes: resolution.encoded }, chromeDependencies), invocation);
186
- const allFlags = [...resolution.flags, ...chrome.flags];
187
- const flags = { ...boundedByBytes(allFlags, FLAG_BYTE_BUDGET), count: allFlags.length };
304
+ const chromeReport = await completeChromeReport({ ...evidence, themes: resolution.encoded }, chromeDependencies);
305
+ const chrome = selectChrome(chromeReport, invocation);
188
306
  const contexts = { ...boundedByBytes(resolution.contexts, NAME_LIST_BYTE_BUDGET), count: resolution.contexts.length };
189
- const surfaceBudget = LIMITS.githubOutputBytes - RESULT_ENVELOPE_BYTES - NAME_LIST_BYTE_BUDGET - CHROME_BYTE_BUDGET
190
- - Buffer.byteLength(JSON.stringify({ flags, contexts }), "utf8");
191
- const entries = resolution.schemes.flatMap(({ scheme, surfaces }) => surfaces.map((surface) => ({ scheme, surface })));
192
- const shown = withinByteBudget(entries, surfaceBudget);
193
- const omitted = entries.slice(shown.length);
194
- const schemes = resolution.schemes
195
- .map(({ scheme }) => ({
196
- scheme,
197
- surfaces: shown.filter((entry) => entry.scheme === scheme).map((entry) => entry.surface),
198
- }))
199
- .filter((entry) => entry.surfaces.length > 0);
200
- return successResult(VERB_THEME_RESOLVE, siteId, {
201
- source,
202
- thresholds: { textRatio: AA_TEXT_RATIO, largeRatio: AA_LARGE_RATIO },
203
- contexts,
204
- schemes,
205
- chrome: chrome.chrome,
206
- chromeCatalog: chrome.chromeCatalog,
207
- ...(chrome.unavailable ? { chromeUnavailable: true } : {}),
208
- ...(chrome.navigationUnavailable ? { chromeNavigationUnavailable: true } : {}),
209
- contrast: {
210
- pairs: resolution.contrast.pairs + chrome.contrast.pairs,
211
- belowAa: resolution.contrast.belowAa + chrome.contrast.belowAa,
212
- belowApca: resolution.contrast.belowApca,
213
- },
214
- flags,
215
- ...(omitted.length === 0
216
- ? {}
217
- : {
218
- omittedSurfaces: {
219
- ...boundedByBytes(
220
- omitted.map((entry) => ({ scheme: entry.scheme, context: entry.surface.context })),
221
- NAME_LIST_BYTE_BUDGET,
222
- ),
223
- count: omitted.length,
224
- },
225
- }),
226
- });
307
+ const contextPositions = new Map(resolution.contexts.map((name, index) => [name, index + 1]));
308
+ const entries = resolution.schemes.flatMap(({ scheme, surfaces }) => surfaces.map((surface) => ({
309
+ scheme,
310
+ surface,
311
+ footerLinkOnLayer2: footerLinkOnLayer2(chromeReport, scheme, surface),
312
+ badgePaint: chromeReport.badges[scheme].find(entry => entry.context === surface.context)?.pairs
313
+ .map(({ ratio, required, ...pair }) => ({ ...pair, ratio: displayChromeRatio(ratio, required), required })),
314
+ })));
315
+ const candidates = tokenCandidates(entries);
316
+ const emptyPaints = paintsForReport(candidates);
317
+ const envelope = reportEnvelope(siteId, source, contexts, entries, resolution.flags, chrome);
318
+ const oversized = new Set();
319
+ const narrowingInputs = { resolution, entries, contexts, chromeReport, contextPositions, siteId, source, oversized };
320
+ // A scheme-only root retry includes omissions for that scheme's named contexts.
321
+ const named = entries.filter(({ surface }) => surface.context !== null);
322
+ const roots = entries.filter(({ surface }) => surface.context === null);
323
+ for (const entry of [...named, ...roots]) {
324
+ if (!canShowAfterNarrowing(entry, narrowingInputs)) oversized.add(entry);
325
+ }
326
+ const possibleOmissions = entries.map((entry) => omission(entry, contextPositions, oversized.has(entry)));
327
+ const shown = [];
328
+ const omitted = [];
329
+ for (const [index, entry] of entries.entries()) {
330
+ const labels = [...omitted, ...possibleOmissions.slice(index + 1)];
331
+ const bytes = (candidate) => resultBytes(assembleReport(envelope, [...shown, candidate], labels, emptyPaints));
332
+ if (bytes(entry) <= LIMITS.githubOutputBytes) {
333
+ const surface = resolution.enrichSurface(entry.scheme, entry.surface);
334
+ const expanded = { ...entry, surface };
335
+ if (bytes(expanded) <= LIMITS.githubOutputBytes) {
336
+ shown.push(expanded);
337
+ continue;
338
+ }
339
+ }
340
+ omitted.push(possibleOmissions[index]);
341
+ }
342
+ if (shown.length === 0 && omitted.length > 0 && omitted.every(({ reason }) => reason === "surface_too_large")) {
343
+ const [{ scheme, context }] = omitted;
344
+ const field = context === null ? `${scheme}Theme` : `${scheme}Theme.contexts.${context}`;
345
+ throw new SiteAuthoringError(
346
+ "theme.resolve_surface_too_large",
347
+ "The selected theme report exceeds the output budget. Shorten long component property values or context names for the affected surfaces, then run theme resolve again.",
348
+ { field },
349
+ );
350
+ }
351
+ let result = assembleReport(envelope, shown, omitted, emptyPaints);
352
+ const paintNames = [];
353
+ for (const name of candidates) {
354
+ const trial = assembleReport(envelope, shown, omitted, paintsForReport(candidates, [...paintNames, name]));
355
+ if (resultBytes(trial) <= LIMITS.githubOutputBytes) {
356
+ paintNames.push(name);
357
+ result = trial;
358
+ }
359
+ }
360
+ return result;
227
361
  }