@taprootio/site-authoring 0.41.1 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +50 -0
  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 +170 -11
  6. package/src/appearance-contract.js +278 -8
  7. package/src/authored-tag-names.js +88 -0
  8. package/src/block-flow.js +103 -1
  9. package/src/brand-color.js +39 -4
  10. package/src/breadcrumb-artwork.js +234 -0
  11. package/src/breadcrumb-separators.js +11 -0
  12. package/src/changelog.json +154 -0
  13. package/src/chrome-features.js +152 -0
  14. package/src/chrome-input.js +147 -0
  15. package/src/chrome-output.js +92 -0
  16. package/src/chrome-paint-catalog-taproot.json +52 -0
  17. package/src/chrome-report.js +173 -0
  18. package/src/cli.js +48 -17
  19. package/src/content/components.js +27 -4
  20. package/src/content/external-link.js +2 -1
  21. package/src/content/markdown.js +271 -101
  22. package/src/content/tiptap-prosemirror.ts +125 -43
  23. package/src/content/validate-document.js +4 -1
  24. package/src/content-inset.js +48 -0
  25. package/src/errors.js +1 -0
  26. package/src/espalier-shared.js +26 -0
  27. package/src/field-suggestions.js +40 -0
  28. package/src/fixture-init.js +22 -5
  29. package/src/font-catalog.js +11 -1
  30. package/src/footer-brand-inputs.js +25 -2
  31. package/src/footer-content.js +38 -0
  32. package/src/footer-contract.js +11 -0
  33. package/src/footer-cta-styles.js +6 -0
  34. package/src/footer-draft-hash.js +4 -2
  35. package/src/footer-fit.js +62 -15
  36. package/src/footer-workspace.js +60 -16
  37. package/src/header-presentation.js +16 -0
  38. package/src/latest-posts-tags.js +57 -0
  39. package/src/page-structure-checks.js +5 -0
  40. package/src/page-tag-badge-modes.js +6 -0
  41. package/src/page-tag-writes.js +158 -0
  42. package/src/page-type-tags.js +16 -0
  43. package/src/presentation-reference.js +312 -86
  44. package/src/recipe-page-options.js +22 -0
  45. package/src/recipe-step-contract.js +164 -0
  46. package/src/recipe-step-contract.json +65 -0
  47. package/src/reference-help.js +164 -78
  48. package/src/session.js +39 -24
  49. package/src/setting-reference.js +239 -48
  50. package/src/settings-catalog.js +63 -0
  51. package/src/site-check-findings.js +25 -5
  52. package/src/site-check-rules.json +3 -1
  53. package/src/site-health-findings.js +13 -13
  54. package/src/site-navigation-groups.js +70 -0
  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 +305 -51
  60. package/src/theme-validation.js +126 -6
  61. package/src/token-reach.js +222 -0
  62. package/src/typed-page-reference.js +72 -15
  63. package/src/typed-pages.js +171 -71
  64. package/src/verbs/deploy.js +6 -0
  65. package/src/verbs/footer-push.js +30 -5
  66. package/src/verbs/forms-push.js +11 -3
  67. package/src/verbs/pages-delete.js +19 -10
  68. package/src/verbs/pages-push.js +125 -36
  69. package/src/verbs/plan.js +10 -4
  70. package/src/verbs/pull.js +277 -67
  71. package/src/verbs/staging-review.js +27 -1
  72. package/src/verbs/status.js +22 -0
  73. package/src/verbs/theme-push.js +249 -120
  74. package/src/verbs/theme-resolve.js +310 -47
  75. package/src/verbs/validate.js +71 -17
  76. package/src/workspace-check.js +37 -4
  77. package/src/workspace.js +37 -1
  78. package/test/fixtures/default-site-theme.json +516 -0
@@ -1,8 +1,35 @@
1
- import { BLOCK_SPACINGS, DEFAULT_BLOCK_SPACING } from "./block-flow.js";
1
+ import {
2
+ BLOCK_SPACINGS,
3
+ DEFAULT_BLOCK_SPACING,
4
+ HEADING_SPACING_FIELDS,
5
+ HEADING_SPACING_MAX,
6
+ HEADING_SPACING_MIN,
7
+ HEADING_SPACING_STEP,
8
+ isHeadingSpacing,
9
+ } from "./block-flow.js";
10
+ import {
11
+ BREADCRUMB_SEPARATOR_DEFAULT,
12
+ BREADCRUMB_SEPARATOR_STYLES,
13
+ BREADCRUMB_TRAIL_END_DEFAULT,
14
+ BREADCRUMB_TRAIL_ENDS,
15
+ } from "./breadcrumb-separators.js";
16
+ import { BREADCRUMB_ARTWORK_FIELDS, BREADCRUMB_ARTWORK_MAX_BYTES, importBreadcrumbSvg, parseBreadcrumbArtwork } from "./breadcrumb-artwork.js";
17
+ import { RECIPE_TAGS_BAR_COLOR_TOKENS } from "./brand-color.js";
18
+ import { AUTHORED_TAG_SLUG, authoredTagSlug, validateAuthoredTagNames } from "./authored-tag-names.js";
19
+ import { CONTENT_INSET_OPTIONS, DEFAULT_CONTENT_INSET } from "./content-inset.js";
2
20
  import { hasControlCharacter, isCanonicalUuid, SiteAuthoringError } from "./errors.js";
3
21
  import { FOOTER_PRESENTATION_FIELDS } from "./footer-content.js";
22
+ import { DEFAULT_PAGE_TAG_BADGES, PAGE_TAG_BADGE_MODES } from "./page-tag-badge-modes.js";
4
23
  import { refuseRetiredFooterColors } from "./footer-contract.js";
5
24
  import { HEADER_HEIGHT_MULTIPLIER_LIMITS, LOGO_VARIANTS, parseHeaderHeightMultiplier } from "./header-presentation.js";
25
+ import {
26
+ DEFAULT_RECIPE_JUMP_CONTROL,
27
+ DEFAULT_RECIPE_TAGS_ICON,
28
+ DEFAULT_RECIPE_TAGS_CONTENT,
29
+ RECIPE_TAGS_CONTENT,
30
+ RECIPE_JUMP_CONTROLS,
31
+ RECIPE_TAGS_ICONS,
32
+ } from "./recipe-page-options.js";
6
33
  import {
7
34
  SETTINGS_TYPE_BRAND,
8
35
  SETTINGS_TYPE_SITE_HEADER,
@@ -11,6 +38,8 @@ import {
11
38
  } from "./settings-catalog.js";
12
39
  import { HEADER_BRAND_COLOR_TOKENS, requireAppearanceColor } from "./theme-validation.js";
13
40
 
41
+ import { readWorkspaceFile } from "./workspace.js";
42
+
14
43
  export const APPEARANCE_FILES = Object.freeze({
15
44
  [SETTINGS_TYPE_TAPROOT_STYLES]: "settings/taproot-styles.json",
16
45
  [SETTINGS_TYPE_BRAND]: "settings/brand.json",
@@ -40,6 +69,51 @@ export const APPEARANCE_SCALAR_FIELDS = Object.freeze([
40
69
  values: Object.freeze(Object.keys(BLOCK_SPACINGS)),
41
70
  default: DEFAULT_BLOCK_SPACING,
42
71
  }),
72
+ ...HEADING_SPACING_FIELDS.map((name) => Object.freeze({
73
+ settingsType: SETTINGS_TYPE_TAPROOT_STYLES,
74
+ name,
75
+ path: `taproot-styles.${name}`,
76
+ type: "heading-spacing",
77
+ minimum: HEADING_SPACING_MIN,
78
+ maximum: HEADING_SPACING_MAX,
79
+ step: HEADING_SPACING_STEP,
80
+ default: "",
81
+ })),
82
+ Object.freeze({
83
+ settingsType: SETTINGS_TYPE_TAPROOT_STYLES,
84
+ name: "contentInset",
85
+ path: "taproot-styles.contentInset",
86
+ type: "enum",
87
+ values: CONTENT_INSET_OPTIONS,
88
+ default: DEFAULT_CONTENT_INSET,
89
+ emptyIsDefault: true,
90
+ }),
91
+ Object.freeze({
92
+ settingsType: SETTINGS_TYPE_TAPROOT_STYLES,
93
+ name: "breadcrumbSeparator",
94
+ path: "taproot-styles.breadcrumbSeparator",
95
+ type: "enum",
96
+ values: BREADCRUMB_SEPARATOR_STYLES,
97
+ default: BREADCRUMB_SEPARATOR_DEFAULT,
98
+ emptyIsDefault: true,
99
+ }),
100
+ Object.freeze({
101
+ settingsType: SETTINGS_TYPE_TAPROOT_STYLES,
102
+ name: "breadcrumbTrailEnd",
103
+ path: "taproot-styles.breadcrumbTrailEnd",
104
+ type: "enum",
105
+ values: BREADCRUMB_TRAIL_ENDS,
106
+ default: BREADCRUMB_TRAIL_END_DEFAULT,
107
+ emptyIsDefault: true,
108
+ }),
109
+ ...BREADCRUMB_ARTWORK_FIELDS.map(name => Object.freeze({
110
+ settingsType: SETTINGS_TYPE_TAPROOT_STYLES,
111
+ name,
112
+ path: "taproot-styles." + name,
113
+ type: "breadcrumb-artwork",
114
+ optional: true,
115
+ default: "",
116
+ })),
43
117
  ...["lightLogoId", "darkLogoId", "lightCompactLogoId", "darkCompactLogoId", "lightCanvasImageId", "darkCanvasImageId"]
44
118
  .map((name) =>
45
119
  Object.freeze({
@@ -200,6 +274,74 @@ export const APPEARANCE_SCALAR_FIELDS = Object.freeze([
200
274
  default: "",
201
275
  })
202
276
  ),
277
+ Object.freeze({
278
+ settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
279
+ name: "recipeJumpControl",
280
+ path: "site-publishing-preferences.recipeJumpControl",
281
+ type: "enum",
282
+ values: RECIPE_JUMP_CONTROLS,
283
+ default: DEFAULT_RECIPE_JUMP_CONTROL,
284
+ emptyIsDefault: true,
285
+ }),
286
+ Object.freeze({
287
+ settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
288
+ name: "recipeTagsIcon",
289
+ path: "site-publishing-preferences.recipeTagsIcon",
290
+ type: "enum",
291
+ values: RECIPE_TAGS_ICONS,
292
+ default: DEFAULT_RECIPE_TAGS_ICON,
293
+ emptyIsDefault: true,
294
+ }),
295
+ Object.freeze({
296
+ settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
297
+ name: "recipeTagsContent",
298
+ path: "site-publishing-preferences.recipeTagsContent",
299
+ type: "enum",
300
+ values: RECIPE_TAGS_CONTENT,
301
+ default: DEFAULT_RECIPE_TAGS_CONTENT,
302
+ emptyIsDefault: true,
303
+ optional: true,
304
+ onlyIfPresent: true,
305
+ }),
306
+ ...["recipeTagsBarBackground", "recipeTagsBarBorderColor", "recipeTagsBarColor"].map(name =>
307
+ Object.freeze({
308
+ settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
309
+ name,
310
+ path: `site-publishing-preferences.${name}`,
311
+ type: "appearance-color",
312
+ allowedTokens: RECIPE_TAGS_BAR_COLOR_TOKENS,
313
+ default: "",
314
+ optional: true,
315
+ onlyIfPresent: true,
316
+ })
317
+ ),
318
+ Object.freeze({
319
+ settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
320
+ name: "recipeMetadataDestinations",
321
+ path: "site-publishing-preferences.recipeMetadataDestinations",
322
+ type: "tag-destinations",
323
+ onlyIfPresent: true,
324
+ optional: true,
325
+ default: Object.freeze({}),
326
+ }),
327
+ Object.freeze({
328
+ settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
329
+ name: "pageTagBadges",
330
+ path: "site-publishing-preferences.pageTagBadges",
331
+ type: "enum",
332
+ values: PAGE_TAG_BADGE_MODES,
333
+ default: DEFAULT_PAGE_TAG_BADGES,
334
+ emptyIsDefault: true,
335
+ }),
336
+ Object.freeze({
337
+ settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
338
+ name: "tagDestinations",
339
+ path: "site-publishing-preferences.tagDestinations",
340
+ type: "tag-destinations",
341
+ onlyIfPresent: true,
342
+ optional: true,
343
+ default: Object.freeze({}),
344
+ }),
203
345
  ]);
204
346
 
205
347
  // TR00728: these four scalars were retired in favor of per-scheme theme
@@ -215,7 +357,7 @@ const RETIRED_TAPROOT_STYLES_SCALARS = Object.freeze([
215
357
  "fontWeightMenu",
216
358
  ]);
217
359
 
218
- function refuseRetiredScalarFonts(stylesDocument) {
360
+ export function refuseRetiredScalarFonts(stylesDocument) {
219
361
  if (stylesDocument === null || typeof stylesDocument !== "object") return;
220
362
  for (const name of RETIRED_TAPROOT_STYLES_SCALARS) {
221
363
  if (Object.hasOwn(stylesDocument, name)) {
@@ -275,8 +417,85 @@ function requireString(value, field, maximum = 256 * 1024) {
275
417
  return value;
276
418
  }
277
419
 
420
+ const recipeMetadataDestinationPath = "site-publishing-preferences.recipeMetadataDestinations";
421
+
422
+ export function normalizeTagDestinations(value, path = "site-publishing-preferences.tagDestinations") {
423
+ if (value === undefined) return {};
424
+ const metadata = path === recipeMetadataDestinationPath;
425
+ const label = metadata ? "Recipe metadata value" : "Tag";
426
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
427
+ fail("theme.tag_destinations_invalid", path + " maps names to page resource IDs.", path);
428
+ }
429
+ const destinations = new Map();
430
+ for (const [name, resourceId] of Object.entries(value)) {
431
+ const field = path + "." + name;
432
+ if (!metadata) {
433
+ const names = validateAuthoredTagNames([name]);
434
+ if ("field" in names) fail("theme.tag_destinations_invalid", names.reason, field);
435
+ }
436
+ const slug = authoredTagSlug(name);
437
+ if (metadata && (!AUTHORED_TAG_SLUG.test(slug) || slug.length > 100 || /[\p{Cc}\p{Cs}]/u.test(name))) {
438
+ fail("theme.tag_destinations_invalid", "Use a metadata value that forms a slug of up to 100 characters.", field);
439
+ }
440
+ if (destinations.has(slug)) fail("theme.tag_destinations_invalid", label + " '" + name + "' is listed more than once.", field);
441
+ if (!isCanonicalUuid(resourceId) || resourceId === "00000000-0000-0000-0000-000000000000") {
442
+ fail("theme.tag_destination_page_invalid", label + " '" + name + "' needs a lowercase page resource ID from pull.", field);
443
+ }
444
+ destinations.set(slug, resourceId);
445
+ }
446
+ return Object.fromEntries([...destinations].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
447
+ }
448
+
449
+ /** Older servers omitted the catalog. A present empty message is an empty catalog. */
450
+ export function tagDestinationCatalogSlugs(catalog) {
451
+ return catalog && typeof catalog === "object" && !Array.isArray(catalog)
452
+ ? Array.isArray(catalog.authoredTagSlugs) ? catalog.authoredTagSlugs : []
453
+ : undefined;
454
+ }
455
+
456
+ export function checkTagDestinationTargets(proposed, existing, manifest, onProgress = () => {}, authoredTagSlugs, metadata = false) {
457
+ const knownSlugs = new Set(authoredTagSlugs ?? manifest.presentation?.authoredTagSlugs
458
+ ?? manifest.pages.flatMap(page => page.baseline?.authoredTagSlugs ?? []));
459
+ const knownPages = new Set(manifest.pages.map(page => page.resourceId));
460
+ for (const [slug, resourceId] of Object.entries(proposed)) {
461
+ if (resourceId === existing?.[slug]) {
462
+ if (!knownPages.has(resourceId)) {
463
+ onProgress("Tag '" + slug + "' has a destination absent from this pull. Published badges stay plain when the destination is unavailable.");
464
+ }
465
+ continue;
466
+ }
467
+ const field = (metadata ? recipeMetadataDestinationPath : "site-publishing-preferences.tagDestinations") + "." + slug;
468
+ if (!metadata && !knownSlugs.has(slug)) {
469
+ fail("theme.tag_destination_tag_unknown", "Unknown site tag '" + slug + "'. Correct the spelling or create the tag, then pull again.", field);
470
+ }
471
+ if (!knownPages.has(resourceId)) {
472
+ const label = metadata ? "Recipe metadata value" : "Tag";
473
+ fail("theme.tag_destination_page_unknown", label + " '" + slug + "' must target a page resource in this workspace. Pull the site to refresh the page inventory.", field);
474
+ }
475
+ }
476
+ }
477
+
278
478
  function validateScalar(definition, value, knownImageIds) {
279
479
  switch (definition.type) {
480
+ case "tag-destinations":
481
+ return JSON.stringify(normalizeTagDestinations(value, definition.path));
482
+ case "breadcrumb-artwork": {
483
+ if (value === "") return "";
484
+ const artwork = parseBreadcrumbArtwork(value);
485
+ if (artwork === undefined) {
486
+ fail("theme.breadcrumb_artwork_invalid", definition.path + " requires a supported SVG file or artwork from pull. See 'taproot-site help appearance'.", definition.path);
487
+ }
488
+ return JSON.stringify(artwork);
489
+ }
490
+ case "heading-spacing":
491
+ if (value !== "" && !isHeadingSpacing(value)) {
492
+ fail(
493
+ "theme.setting_invalid",
494
+ `${definition.path} must be empty or a canonical string from ${definition.minimum} through ${definition.maximum} in ${definition.step} rem steps.`,
495
+ definition.path,
496
+ );
497
+ }
498
+ return value;
280
499
  case "header-height-multiplier": {
281
500
  const height = parseHeaderHeightMultiplier(value);
282
501
  if (!height) {
@@ -359,24 +578,75 @@ function validateScalar(definition, value, knownImageIds) {
359
578
 
360
579
  /** Compare authored aliases and omitted optional fields with the same values sent to Taproot. */
361
580
  export function appearanceScalarInput(definition, value) {
581
+ if (value === "" && definition.emptyIsDefault) return definition.default;
362
582
  const input = value === undefined && definition.optional ? definition.default : value;
363
583
  if (definition.type === "header-height-multiplier") return parseHeaderHeightMultiplier(input)?.canonical ?? input;
364
584
  return input;
365
585
  }
366
586
 
587
+ /** Import local source files before comparing or saving the frozen presentation. */
588
+ export async function readBreadcrumbArtworkSettings(workspaceDir, settings) {
589
+ const result = { ...settings };
590
+ for (const name of BREADCRUMB_ARTWORK_FIELDS) {
591
+ const reference = settings[name];
592
+ if (reference === null || typeof reference !== "object" || !Object.hasOwn(reference, "file")) continue;
593
+ const { file, color = "theme" } = reference;
594
+ const field = "taproot-styles." + name;
595
+ if (typeof file !== "string" || hasControlCharacter(file)) {
596
+ fail("theme.breadcrumb_artwork_invalid", field + " requires a workspace-relative .svg file.", field);
597
+ }
598
+ if (!file.endsWith(".svg")) {
599
+ fail("theme.breadcrumb_artwork_invalid", "Artwork file '" + file + "' must have a .svg extension.", field);
600
+ }
601
+ const unknownKey = Object.keys(reference).find(key => key !== "file" && key !== "color");
602
+ if (unknownKey !== undefined) {
603
+ fail("theme.breadcrumb_artwork_invalid", "The reference to SVG file '" + file + "' has an unknown '" + unknownKey + "' field. Use 'file' and optionally 'color'.", field);
604
+ }
605
+ if (color !== "theme" && color !== "original") {
606
+ fail("theme.breadcrumb_artwork_invalid", "SVG file '" + file + "' must use color 'theme' or 'original'.", field);
607
+ }
608
+ let bytes;
609
+ try {
610
+ bytes = await readWorkspaceFile(workspaceDir, file, BREADCRUMB_ARTWORK_MAX_BYTES);
611
+ } catch (error) {
612
+ if (error instanceof SiteAuthoringError) {
613
+ fail("theme.breadcrumb_artwork_invalid", error.message, field);
614
+ }
615
+ throw error;
616
+ }
617
+ const imported = importBreadcrumbSvg(bytes.toString("utf8"), color === "theme");
618
+ if ("reason" in imported) {
619
+ fail("theme.breadcrumb_artwork_invalid", "SVG file '" + file + "' " + imported.reason + ". See 'taproot-site help appearance'.", field);
620
+ }
621
+ result[name] = imported.artwork;
622
+ }
623
+ return result;
624
+ }
625
+
626
+ function checkedScalar(definition, settings, knownImageIds) {
627
+ return validateScalar(definition, appearanceScalarInput(definition, settings?.[definition.name]), knownImageIds);
628
+ }
629
+
630
+ /** Optional report evidence can be checked independently of other settings groups. */
631
+ export function validateAppearanceScalarGroup(settingsType, settings, knownImageIds) {
632
+ if (settingsType === SETTINGS_TYPE_TAPROOT_STYLES) refuseRetiredScalarFonts(settings);
633
+ for (const definition of APPEARANCE_SCALAR_FIELDS) {
634
+ if (definition.settingsType === settingsType) checkedScalar(definition, settings, knownImageIds);
635
+ }
636
+ return settings;
637
+ }
638
+
367
639
  export function buildAppearanceScalarOperations(documents, knownImageIds) {
368
640
  if (!(knownImageIds instanceof Set)) {
369
641
  throw new TypeError("Appearance validation requires the known site-owned image identities.");
370
642
  }
371
643
  refuseRetiredScalarFonts(documents[SETTINGS_TYPE_TAPROOT_STYLES]);
372
- return APPEARANCE_SCALAR_FIELDS.map((definition) => ({
644
+ return APPEARANCE_SCALAR_FIELDS.filter((definition) =>
645
+ !definition.onlyIfPresent || Object.hasOwn(documents[definition.settingsType], definition.name)
646
+ ).map((definition) => ({
373
647
  settingsType: definition.settingsType,
374
648
  setting: definition.name,
375
- value: validateScalar(
376
- definition,
377
- appearanceScalarInput(definition, documents[definition.settingsType]?.[definition.name]),
378
- knownImageIds,
379
- ),
649
+ value: checkedScalar(definition, documents[definition.settingsType], knownImageIds),
380
650
  }));
381
651
  }
382
652
 
@@ -0,0 +1,88 @@
1
+ // Generated from shared/authored-tag-names.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ import { isSystemPageTypeTag } from "./page-type-tags.js";
3
+ export const MAX_AUTHORED_TAGS = 100;
4
+ export const MAX_AUTHORED_TAG_NAME_SCALARS = 100;
5
+ export const AUTHORED_TAG_SLUG = /^[a-z0-9-]+$/u;
6
+ // UrlHelpers.Slugify uses the ASCII output of .NET's ISO-8859-5 best-fit
7
+ // encoding. These are the non-ASCII inputs that survive its slug filter.
8
+ // The encoding drops some letters that Unicode decomposition would keep.
9
+ const asciiByBestFit = new Map(Object.entries({
10
+ " ": "\u2000\u2001\u2002\u2003\u2004\u2005\u2006",
11
+ "-": "‐‑–—-",
12
+ "0": "0",
13
+ "1": "¹1",
14
+ "2": "²2",
15
+ "3": "³3",
16
+ "4": "4",
17
+ "5": "5",
18
+ "6": "6",
19
+ "7": "7",
20
+ "8": "8",
21
+ "9": "9",
22
+ a: "ªÀÁÂÃÄÅÆàáâãäåæĀāĂ㥹ǍǎǞǟAa",
23
+ b: "ƀBb",
24
+ c: "¢©ÇçĆćĈĉĊċČčCc",
25
+ d: "ÐĎďĐđƉDd",
26
+ e: "ÈÉÊËèéêëĒēĔĕĖėĘęĚěEe",
27
+ f: "ƑƒFf",
28
+ g: "ĜĝĞğĠġĢģǤǥǦǧɡGg",
29
+ h: "ĤĥĦħHh",
30
+ i: "ÌÍÎÏìíîïĨĩĪīĬĭĮįİıƗǏǐIi",
31
+ j: "ĴĵǰJj",
32
+ k: "ĶķǨǩKk",
33
+ l: "ĹĺĻļĽľŁłƚLl",
34
+ m: "Mm",
35
+ n: "ÑñŃńŅņŇňNn",
36
+ o: "ºÒÓÔÕÖØòóôõöøŌōŎŏŐőŒœƟƠơǑǒǪǫǬǭOo",
37
+ p: "Pp",
38
+ q: "Qq",
39
+ r: "®ŔŕŖŗŘřRr",
40
+ s: "ŚśŜŝŞşŠšSs",
41
+ t: "ŢţŤťŦŧƫƮ™Tt",
42
+ u: "ÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųƯưǓǔǕǖǗǘǙǚǛǜUu",
43
+ v: "Vv",
44
+ w: "ŴŵWw",
45
+ x: "Xx",
46
+ y: "¥ÝýÿŶŷŸYy",
47
+ z: "ŹźŻżŽžƶZz",
48
+ }).flatMap(([ascii, characters]) => [...characters].map((character) => [character, ascii])));
49
+ export function authoredTagSlug(name) {
50
+ let ascii = "";
51
+ for (const character of name) {
52
+ ascii += character.charCodeAt(0) < 128 ? character : asciiByBestFit.get(character) ?? "";
53
+ }
54
+ return ascii.toLowerCase().replace(/[^a-z0-9\s-]/gu, "").trim().replace(/\s+/gu, "-");
55
+ }
56
+ // String.Trim() in .NET includes these whitespace characters and Unicode separators.
57
+ const NAME_PADDING = /^\p{White_Space}+|\p{White_Space}+$/gu;
58
+ const NAME_CONTROL_OR_SURROGATE = /[\p{Cc}\p{Cs}]/u;
59
+ /** Preserve label order and spelling for a write, and sort identities for comparisons. */
60
+ export function validateAuthoredTagNames(value) {
61
+ if (!Array.isArray(value) || value.length > MAX_AUTHORED_TAGS) {
62
+ return { field: "tags", reason: `Use a list of up to ${MAX_AUTHORED_TAGS} tag names.` };
63
+ }
64
+ const names = [];
65
+ const slugs = new Set();
66
+ for (const [index, rawName] of value.entries()) {
67
+ const field = `tags[${index}]`;
68
+ if (typeof rawName !== "string")
69
+ return { field, reason: "Use a string for each tag name." };
70
+ const name = rawName.replace(NAME_PADDING, "");
71
+ if (NAME_CONTROL_OR_SURROGATE.test(name)) {
72
+ return { field, reason: "Tag names cannot contain control characters or invalid Unicode." };
73
+ }
74
+ if ([...name].length > MAX_AUTHORED_TAG_NAME_SCALARS) {
75
+ return { field, reason: `Use at most ${MAX_AUTHORED_TAG_NAME_SCALARS} characters in each tag name.` };
76
+ }
77
+ const slug = authoredTagSlug(name);
78
+ if (slug === "")
79
+ return { field, reason: "Use a name that can form a tag slug." };
80
+ if (isSystemPageTypeTag(name, slug))
81
+ return { field, reason: "Taproot reserves this tag for a page type." };
82
+ if (slugs.has(slug))
83
+ return { field, reason: "That tag has the same slug as an earlier tag in this list." };
84
+ names.push(name);
85
+ slugs.add(slug);
86
+ }
87
+ return { names, slugs: [...slugs].sort() };
88
+ }
package/src/block-flow.js CHANGED
@@ -21,11 +21,36 @@ export const BLOCK_SPACINGS = {
21
21
  };
22
22
  /** What a site that never chose gets; it is also the value the page leaves unwritten. */
23
23
  export const DEFAULT_BLOCK_SPACING = "standard";
24
+ export const HEADING_SPACING_MIN = 0;
25
+ export const HEADING_SPACING_MAX = 6;
26
+ export const HEADING_SPACING_STEP = 0.25;
27
+ export const HEADING_SPACING_FIELDS = [
28
+ "headingH1SpaceBefore",
29
+ "headingH1SpaceAfter",
30
+ "headingH2SpaceBefore",
31
+ "headingH2SpaceAfter",
32
+ "headingH3SpaceBefore",
33
+ "headingH3SpaceAfter",
34
+ "headingH4SpaceBefore",
35
+ "headingH4SpaceAfter",
36
+ ];
37
+ const canonicalHeadingSpacing = /^(?:[0-5](?:\.(?:25|5|75))?|6)(?![\s\S])/u;
38
+ export function isHeadingSpacing(value) {
39
+ return typeof value === "string" && canonicalHeadingSpacing.test(value);
40
+ }
41
+ export function normalizeHeadingSpacing(value) {
42
+ return isHeadingSpacing(value) ? value : "";
43
+ }
44
+ export function readHeadingSpacing(settings) {
45
+ return Object.fromEntries(HEADING_SPACING_FIELDS.map(field => [
46
+ field, normalizeHeadingSpacing(settings?.[field]),
47
+ ]));
48
+ }
24
49
  // A flow container holds a page's blocks as direct children. This is the
25
50
  // shell's older list with `.taproot-free-form` swapped for the section
26
51
  // content: the free-form element's own children are sections and root bands,
27
52
  // which must not gain a margin.
28
- const FLOW_CONTAINERS = [
53
+ export const FLOW_CONTAINERS = [
29
54
  "[data-section-content]",
30
55
  "[data-taproot-column]",
31
56
  "[slot=\"body\"]",
@@ -123,3 +148,80 @@ esp-section[data-content-padding="standard"] [data-section-content] > :is(${TEXT
123
148
  margin-block-start: 0;
124
149
  }
125
150
  `.trim();
151
+ export function hasHeadingSpacing(settings) {
152
+ return HEADING_SPACING_FIELDS.some(field => isHeadingSpacing(settings?.[field]));
153
+ }
154
+ export const HEADING_FLOW_NEIGHBORS = [
155
+ { surface: "both", selector: '[data-heading-flow="paragraph"], [data-heading-flow="heading"]', edge: "line-box" },
156
+ { surface: "both", selector: '[data-heading-flow="empty"]', edge: "excluded" },
157
+ { surface: "both", selector: '[data-heading-flow-neighbor="list"], [data-heading-flow-neighbor="code"]', edge: "barrier" },
158
+ { surface: "both", selector: '[data-heading-flow-neighbor="quote"], [data-heading-flow-neighbor="rule"]', edge: "self-contained" },
159
+ { surface: "both", selector: "figure[data-taproot-quote]", edge: "barrier" },
160
+ { surface: "both", selector: ".taproot-table-scroll", edge: "self-contained" },
161
+ { surface: "published", selector: ".taproot-free-form ul.taproot-inline-facts", edge: "self-contained" },
162
+ { surface: "published", selector: "ul.taproot-inline-facts:not(.taproot-free-form *)", edge: "barrier" },
163
+ { surface: "preview", selector: "ul.taproot-inline-facts", edge: "barrier" },
164
+ { surface: "both", selector: "esp-columns[data-taproot-columns]", edge: "self-contained" },
165
+ { surface: "both", selector: "esp-section[data-taproot-section], taproot-integration-placement[data-placement-id]", edge: "excluded" },
166
+ { surface: "both", selector: "esp-image[data-tiptap-image]:not([banner])", edge: "self-contained" },
167
+ { surface: "both", selector: ":is(taproot-hero, taproot-cta)[data-heading-flow-component]:not([data-heading-flow-ready]):not(:empty)", edge: "barrier" },
168
+ { surface: "both", selector: ":is(taproot-hero, taproot-cta)[data-heading-flow-ready]", edge: "self-contained" },
169
+ { surface: "both", selector: ":is(taproot-hero, taproot-cta)[data-heading-flow-component]:not([data-heading-flow-ready]):empty", edge: "excluded" },
170
+ { surface: "both", selector: "taproot-feature-grid:not(:empty), taproot-card-grid:not(:empty), taproot-product-grid:not(:empty), taproot-testimonial:not(:empty)", edge: "barrier" },
171
+ { surface: "published", selector: "taproot-latest-posts:not(:empty)", edge: "barrier" },
172
+ { surface: "preview", selector: '[data-heading-flow-neighbor="latest-posts"]:not(:empty)', edge: "barrier" },
173
+ { surface: "published", selector: ".testimonial-summary:not(:empty)", edge: "barrier" },
174
+ { surface: "published", selector: "p.testimonial-attribution:not(:empty)", edge: "line-box" },
175
+ { surface: "preview", selector: "[data-testimonial-google]:not(:empty)", edge: "barrier" },
176
+ { surface: "published", selector: "taproot-form", edge: "self-contained" },
177
+ { surface: "published", selector: ".place-review-header, .place-review-rating", edge: "excluded" },
178
+ { surface: "preview", selector: "p[data-recipe-preview-summary], p.integration-fragment-placeholder", edge: "excluded" },
179
+ { surface: "preview", selector: "[data-form-preview]", edge: "self-contained" },
180
+ { surface: "published", selector: ".taproot-video, taproot-video-embed", edge: "self-contained" },
181
+ { surface: "preview", selector: ".component-preview--video, .component-preview--video-embed, .component-preview--default", edge: "self-contained" },
182
+ { surface: "both", selector: "taproot-image-row:not(:empty), .taproot-social-links:not(:empty)", edge: "self-contained" },
183
+ { surface: "both", selector: "taproot-image-banner, esp-image[banner], taproot-spacer", edge: "excluded" },
184
+ { surface: "preview", selector: "[data-component-block], .preview-empty, [data-testimonial-google]:empty", edge: "excluded" },
185
+ { surface: "preview", selector: "taproot-feature-grid:empty, taproot-card-grid:empty, taproot-product-grid:empty, taproot-testimonial:empty, taproot-image-row:empty, .taproot-social-links:empty", edge: "excluded" },
186
+ ];
187
+ export const HEADING_GROUP_END_PROPERTY = "--taproot-heading-group-gap-end";
188
+ export function buildHeadingSpacingCss(settings, surface = "published") {
189
+ if (!hasHeadingSpacing(settings))
190
+ return "";
191
+ const entries = HEADING_FLOW_NEIGHBORS.filter(entry => entry.surface === "both" || entry.surface === surface);
192
+ const matching = (selected) => `:where(${selected.map(entry => entry.selector).join(", ")})`;
193
+ const allowed = matching(entries.filter(entry => entry.edge !== "excluded"));
194
+ const barrier = matching(entries.filter(entry => entry.edge === "barrier"));
195
+ const from = `:is(${FLOW_CONTAINERS}):nth-child(n) > `;
196
+ const known = (selector) => `${selector}:not([data-heading-flow="empty"])`;
197
+ const neighbor = known(allowed);
198
+ const blocked = known(barrier);
199
+ const rules = [];
200
+ const pair = (selector, declaration) => rules.push(`${selector} { ${declaration} }`);
201
+ const contain = 'content: ""; display: table; block-size: 0;';
202
+ // Before wins for adjacent headings, including an explicit zero.
203
+ for (const edge of ["After", "Before"]) {
204
+ for (const [index, field] of HEADING_SPACING_FIELDS.entries()) {
205
+ const value = settings?.[field];
206
+ if (!field.endsWith(edge) || !isHeadingSpacing(value))
207
+ continue;
208
+ const heading = `:where(h${Math.floor(index / 2) + 1})[data-heading-flow="heading"]`;
209
+ if (edge === "After") {
210
+ pair(`${from}${heading}:has(+ ${neighbor})`, "margin-block-end: 0;");
211
+ pair(`${from}${heading} + ${neighbor}`, `margin-block-start: ${value}rem;`);
212
+ pair(`${from}${heading} + ${blocked}::before`, contain);
213
+ }
214
+ else {
215
+ pair(`${from}${neighbor}:has(+ ${heading})`, "margin-block-end: 0;");
216
+ pair(`${from}${neighbor} + ${heading}`, `margin-block-start: ${value}rem;`);
217
+ pair(`${from}${blocked}:has(+ ${heading})::after`, contain);
218
+ pair(`${from}esp-image[data-tiptap-image]:not([banner]):has(+ ${heading})`, `${HEADING_GROUP_END_PROPERTY}: ${value}rem;`);
219
+ pair(`${from}esp-image[data-tiptap-image-grouped]:not([banner]) + ${heading}`, "margin-block-start: 0;");
220
+ if (surface === "preview") {
221
+ pair(`${from}[data-testimonial-google]:has(+ ${heading}) .testimonial-attribution:last-child`, "margin-block-end: 0;");
222
+ }
223
+ }
224
+ }
225
+ }
226
+ return rules.join("\n");
227
+ }
@@ -3,6 +3,28 @@
3
3
  const COLOR_MAX_LENGTH = 128;
4
4
  const HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
5
5
  const OKLCH_COLOR_PATTERN = /^oklch\(\s*((?:0|[1-9]\d*)(?:\.\d+)?)\s+((?:0|[1-9]\d*)(?:\.\d+)?)\s+((?:0|[1-9]\d*)(?:\.\d+)?)\s*\)$/i;
6
+ export const RECIPE_TAGS_BAR_COLOR_TOKENS = new Set([
7
+ "--esp-color-background",
8
+ "--esp-color-border",
9
+ "--esp-color-headings",
10
+ "--esp-color-layer-1",
11
+ "--esp-color-layer-2",
12
+ "--esp-color-layer-3",
13
+ "--esp-color-layer-4",
14
+ "--esp-color-link",
15
+ "--esp-color-text",
16
+ ]);
17
+ export const RECIPE_TAGS_BAR_PAINT_DEFAULTS = {
18
+ background: "--esp-color-layer-3",
19
+ border: "--esp-color-border",
20
+ ink: "--esp-color-text",
21
+ };
22
+ export function resolveRecipeTagsBarColor(value, fallback) {
23
+ const color = value?.trim() ?? "";
24
+ if (RECIPE_TAGS_BAR_COLOR_TOKENS.has(color))
25
+ return `var(${color})`;
26
+ return color.length <= COLOR_MAX_LENGTH && isSupportedCustomColor(color) ? color : `var(${fallback})`;
27
+ }
6
28
  const HEADER_BRAND_SEMANTIC_COLOR_TOKENS = new Set([
7
29
  "--esp-color-headings",
8
30
  "--esp-color-link",
@@ -21,10 +43,23 @@ export function resolveHeaderBrandColor(value) {
21
43
  return HEADER_BRAND_SEMANTIC_COLOR_TOKENS.has(color) ? `var(${color})` : color;
22
44
  }
23
45
  export function resolveBrandColors(input, resolve = resolveHeaderBrandColor) {
24
- const configured = resolve(input?.brandColor);
25
- const light = resolve(input?.lightBrandColor) || configured;
26
- const dark = resolve(input?.darkBrandColor) || configured || light;
27
- return { light, dark, generic: configured || light || dark };
46
+ const { light, dark, generic } = selectBrandColors(input, resolve);
47
+ return { light: light?.color ?? "", dark: dark?.color ?? "", generic: generic?.color ?? "" };
48
+ }
49
+ /** The source of each scheme's final ink, including the component's generic fallback. */
50
+ export function resolveBrandColorSourceFields(input) {
51
+ const { light, dark, generic } = selectBrandColors(input, resolveBrandColorToken);
52
+ return { light: (light ?? generic)?.field, dark: (dark ?? generic)?.field };
53
+ }
54
+ function selectBrandColors(input, resolve) {
55
+ const select = (field) => {
56
+ const color = resolve(input?.[field]);
57
+ return color ? { field, color } : undefined;
58
+ };
59
+ const configured = select("brandColor");
60
+ const light = select("lightBrandColor") ?? configured;
61
+ const dark = select("darkBrandColor") ?? configured ?? light;
62
+ return { light, dark, generic: configured ?? light ?? dark };
28
63
  }
29
64
  /** The footer preserves the caller's colors without header validation. */
30
65
  export function resolveFooterBrandColors({ light, dark }) {