@taprootio/site-authoring 0.39.0 → 0.41.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.
@@ -19,10 +19,25 @@ export const MANUAL_SOURCE = "manual";
19
19
  export const GOOGLE_REVIEWS_SOURCE = "google-reviews";
20
20
  /** How many reviews a Google-source component shows, as stored: a whole number from 1 to 12. */
21
21
  export const TESTIMONIAL_MAX_ITEMS = Object.freeze({ minimum: 1, maximum: 12, default: 6 });
22
+ /**
23
+ * Which Google reviews a component shows (TR01341): the `newest` ones, as many as `maxItems` says, or the ones the
24
+ * author picked by id, in the order picked. Stored `reviewIds` stay when the selection is `newest`, so switching back
25
+ * loses nothing.
26
+ */
27
+ export const TESTIMONIAL_REVIEW_SELECTIONS = ["newest", "chosen"];
28
+ export const NEWEST_SELECTION = "newest";
29
+ export const CHOSEN_SELECTION = "chosen";
30
+ /** The most reviews one component can choose; the C# `BusinessProfilePolicy.MaxChosenReviewsPerComponent` is the same number. */
31
+ export const TESTIMONIAL_MAX_CHOSEN_REVIEWS = 12;
32
+ /** A review id Taproot keeps: 1 to 256 letters, digits, `_` or `-`, as `BusinessProfilePolicy.IsValidReviewId` says. */
33
+ export const REVIEW_ID_PATTERN = /^[A-Za-z0-9_-]{1,256}$/u;
22
34
  /** What a creator reads on a published page. Each is one sentence, so a change is made here only. */
23
35
  export const GOOGLE_REVIEWS_ATTRIBUTION = "Selected reviews from Google";
24
36
  export const GOOGLE_REVIEWS_LINK_TEXT = "Read all reviews on Google";
25
37
  export const GOOGLE_REVIEW_LABEL = "Google review";
38
+ /** The label above the owner's reply on a listed review, and the link to write a review (TR01342). */
39
+ export const GOOGLE_REVIEWS_REPLY_LABEL = "Reply from the owner";
40
+ export const GOOGLE_REVIEWS_WRITE_LINK_TEXT = "Write a review";
26
41
  /** The reviewer shown when Google sent no name (the freeze stores an empty name, never these words). */
27
42
  export const GOOGLE_USER_NAME = "Google user";
28
43
  /** An unknown or mistyped source is the hand-written one, so older and foreign data renders as it always did. */
@@ -35,7 +50,22 @@ export function normalizeTestimonialMaxItems(value) {
35
50
  return TESTIMONIAL_MAX_ITEMS.default;
36
51
  return Math.min(TESTIMONIAL_MAX_ITEMS.maximum, Math.max(TESTIMONIAL_MAX_ITEMS.minimum, Math.trunc(value)));
37
52
  }
38
- /** The two fields of component data that is not an object (or has neither) are the defaults. */
53
+ /** Anything but the exact word `chosen` is the newest reviews, so older and foreign data renders as it always did. */
54
+ export function normalizeReviewSelection(value) {
55
+ return value === CHOSEN_SELECTION ? CHOSEN_SELECTION : NEWEST_SELECTION;
56
+ }
57
+ /**
58
+ * The review ids a component stored: the strings that are valid review ids, later duplicates dropped, then the first
59
+ * twelve. Anything that is not a list is none. The C# page extractor applies the same rule, and the corpus holds them
60
+ * to the same answers.
61
+ */
62
+ export function normalizeReviewIds(value) {
63
+ if (!Array.isArray(value))
64
+ return [];
65
+ const valid = value.filter((id) => typeof id === "string" && REVIEW_ID_PATTERN.test(id));
66
+ return [...new Set(valid)].slice(0, TESTIMONIAL_MAX_CHOSEN_REVIEWS);
67
+ }
68
+ /** The fields of component data that is not an object (or has none of them) are the defaults. */
39
69
  export function normalizeTestimonialGoogleFields(data) {
40
70
  const record = data !== null && typeof data === "object" && !Array.isArray(data)
41
71
  ? data
@@ -43,8 +73,61 @@ export function normalizeTestimonialGoogleFields(data) {
43
73
  return {
44
74
  source: normalizeTestimonialSource(record.source),
45
75
  maxItems: normalizeTestimonialMaxItems(record.maxItems),
76
+ reviewSelection: normalizeReviewSelection(record.reviewSelection),
77
+ reviewIds: normalizeReviewIds(record.reviewIds),
78
+ // Only the boolean `true` turns a switch on, so a string or a number in older or foreign data is off.
79
+ showAll: record.showAll === true,
80
+ showProfileSummary: record.showProfileSummary === true,
46
81
  };
47
82
  }
83
+ /**
84
+ * The one answer to what a Testimonial shows (TR01342), computed once from the stored fields. The renderer, the editor
85
+ * preview, the editor and the page preview's reference walk all call it, and the C# page extractor's answers are held to
86
+ * it by the corpus. The editor passes its draft fields in the stored shape.
87
+ */
88
+ export function googleReviewsDisplay(data) {
89
+ const fields = normalizeTestimonialGoogleFields(data);
90
+ const record = data !== null && typeof data === "object" && !Array.isArray(data)
91
+ ? data
92
+ : {};
93
+ const google = fields.source === GOOGLE_REVIEWS_SOURCE;
94
+ const listAll = google && fields.reviewSelection === NEWEST_SELECTION && fields.showAll;
95
+ return { listAll, summary: google && fields.showProfileSummary, carousel: Boolean(record.carousel) && !listAll };
96
+ }
97
+ /**
98
+ * The review ids a component chooses: its stored ids when the source is Google and the selection is `chosen`, and none
99
+ * otherwise (a `newest` component ignores ids it still holds). The page preview, the editor, the chooser below and the
100
+ * C# extractor all mean this.
101
+ */
102
+ export function chosenGoogleReviewIds(data) {
103
+ const fields = normalizeTestimonialGoogleFields(data);
104
+ return fields.source === GOOGLE_REVIEWS_SOURCE && fields.reviewSelection === CHOSEN_SELECTION ? fields.reviewIds : [];
105
+ }
106
+ /** The one test of an address a page may link to: https, as the profile's Maps address and the address to write a review at both need (TR01342). */
107
+ function isHttpsAddress(value) {
108
+ return /^https:\/\//iu.test(value);
109
+ }
110
+ /** "1 star", "5 stars": the one place the rating is worded, for the published page, the editor and the review cards. */
111
+ export function googleRatingWords(stars) {
112
+ return stars === 1 ? "1 star" : `${stars} stars`;
113
+ }
114
+ const COUNT_FORMAT = new Intl.NumberFormat("en-US");
115
+ const AVERAGE_FORMAT = new Intl.NumberFormat("en-US", { minimumFractionDigits: 1, maximumFractionDigits: 1 });
116
+ /**
117
+ * The sentence above a listing (TR01342): "4.8 average from 212 reviews on Google", "1 review" for one, the count with a US
118
+ * thousands separator and the average to one decimal place. An average that is not a rating from 1 to 5 (Google's reader stores an
119
+ * absent one as 0) leaves the count alone ("212 reviews on Google"), and a total of zero or less, which Google reports for a
120
+ * profile it counts no reviews for, has no figures at all, so the sentence is null.
121
+ */
122
+ export function googleSummarySentence(averageRating, totalReviewCount) {
123
+ if (!Number.isFinite(totalReviewCount) || totalReviewCount < 1)
124
+ return null;
125
+ const total = Math.trunc(totalReviewCount);
126
+ const count = `${COUNT_FORMAT.format(total)} ${total === 1 ? "review" : "reviews"} on Google`;
127
+ return Number.isFinite(averageRating) && averageRating >= 1 && averageRating <= 5
128
+ ? `${AVERAGE_FORMAT.format(averageRating)} average from ${count}`
129
+ : count;
130
+ }
48
131
  /**
49
132
  * The month and year of a review in US English, in the given IANA time zone and in UTC when none is given or
50
133
  * the zone is not one the runtime knows. Empty when the date is not a date.
@@ -62,26 +145,73 @@ export function formatReviewMonthYear(value, timeZone) {
62
145
  }
63
146
  }
64
147
  /**
65
- * Which reviews a Testimonial component shows. With the Google source it is the first `maxItems` of the reviews
66
- * in the order given (a release freezes them newest first), each with its reviewer and its second line; with the
67
- * manual source, with no reviews, or without an https profile address it is null, and the component renders as an
68
- * empty or hand-written one does. The renderer and the editor preview both call this, and later stories extend it.
148
+ * Which reviews a Testimonial component shows, and every word around them. With the Google source and the `newest`
149
+ * selection it is the first `maxItems` of the showable reviews in the order given (a release freezes them newest first),
150
+ * or every one of them, never an older chosen one, while `googleReviewsDisplay(data).listAll` holds (TR01342); with `chosen`
151
+ * it is the reviews the component lists, in the listed order, each taken from the showable reviews or from the older chosen
152
+ * ones, and a listed review that is in neither is skipped (TR01341). Each item has its reviewer and its second line (with the
153
+ * rating written out when the list is in effect) and, for the list, the owner's reply. `summary` holds the words and links of
154
+ * Google's rating when the component shows it and the release froze the figures, and `attribution` the line after the
155
+ * reviews, which keeps its link to read all reviews unless the summary is returned and carries it. With the manual source,
156
+ * with nothing to show, or without an https profile address it is null, and the component renders as an empty or
157
+ * hand-written one does. The renderer and the editor preview both call this and only lay the result out.
69
158
  */
70
159
  export function chooseGoogleReviews(data, input, timeZone) {
71
160
  const fields = normalizeTestimonialGoogleFields(data);
72
- if (fields.source !== GOOGLE_REVIEWS_SOURCE || !input || input.reviews.length === 0)
161
+ if (fields.source !== GOOGLE_REVIEWS_SOURCE || !input)
73
162
  return null;
74
163
  // The profile link is the attribution every review needs, so an address that cannot be one shows no review.
75
- if (!/^https:\/\//iu.test(input.mapsUri))
164
+ if (!isHttpsAddress(input.mapsUri))
76
165
  return null;
77
- const items = input.reviews.slice(0, fields.maxItems).map((review) => {
166
+ const display = googleReviewsDisplay(data);
167
+ // A list shows every showable review whatever maxItems holds, and never the older ones another page chose (TR01342).
168
+ const selected = fields.reviewSelection === CHOSEN_SELECTION
169
+ ? listedReviews(chosenGoogleReviewIds(data), input)
170
+ : display.listAll
171
+ ? [...input.reviews]
172
+ : input.reviews.slice(0, fields.maxItems);
173
+ if (selected.length === 0)
174
+ return null;
175
+ const items = selected.map((review) => {
78
176
  const month = formatReviewMonthYear(review.createTime, timeZone);
177
+ const parts = [GOOGLE_REVIEW_LABEL, month, ...(display.listAll ? [googleRatingWords(review.starRating)] : [])];
79
178
  return {
80
179
  reviewId: review.reviewId,
81
180
  text: review.text,
82
181
  name: review.reviewerName.trim() === "" ? GOOGLE_USER_NAME : review.reviewerName,
83
- byline: month ? `${GOOGLE_REVIEW_LABEL}, ${month}` : GOOGLE_REVIEW_LABEL,
182
+ byline: parts.filter((part) => part !== "").join(", "),
183
+ reply: display.listAll && typeof review.replyText === "string" && review.replyText.trim() !== ""
184
+ ? review.replyText
185
+ : null,
84
186
  };
85
187
  });
86
- return { mapsUri: input.mapsUri, items };
188
+ const summary = display.summary && input.summary ? summaryWords(input.summary, input.mapsUri) : null;
189
+ return {
190
+ items,
191
+ summary,
192
+ // The summary carries the link to read all reviews, so the page keeps one link of each kind.
193
+ attribution: {
194
+ text: `${GOOGLE_REVIEWS_ATTRIBUTION}.`,
195
+ link: summary ? null : { label: GOOGLE_REVIEWS_LINK_TEXT, href: input.mapsUri },
196
+ },
197
+ };
198
+ }
199
+ /** The summary's words and links. The write link needs an https address, as the profile's own link does. */
200
+ function summaryWords(summary, mapsUri) {
201
+ return {
202
+ sentence: googleSummarySentence(summary.averageRating, summary.totalReviewCount),
203
+ readAll: { label: GOOGLE_REVIEWS_LINK_TEXT, href: mapsUri },
204
+ write: isHttpsAddress(summary.newReviewUri)
205
+ ? { label: GOOGLE_REVIEWS_WRITE_LINK_TEXT, href: summary.newReviewUri }
206
+ : null,
207
+ };
208
+ }
209
+ /** The listed reviews in the listed order; a showable review wins over an older copy of the same id. */
210
+ function listedReviews(ids, input) {
211
+ const known = new Map();
212
+ for (const review of input.olderChosenReviews ?? [])
213
+ known.set(review.reviewId, review);
214
+ for (const review of input.reviews)
215
+ known.set(review.reviewId, review);
216
+ return ids.flatMap((id) => known.get(id) ?? []);
87
217
  }
@@ -1,7 +1,9 @@
1
1
  import { APPEARANCE_FILES } from "./appearance-contract.js";
2
- import { isCanonicalUuid } from "./errors.js";
2
+ import { resolveFooterLogoPairs } from "./footer-branding.js";
3
+ import { footerLogoAspectRatio } from "./footer-fit.js";
4
+ import { logoInputsFromSettings } from "./logo-inputs.js";
3
5
  import { SETTINGS_TYPE_SITE_HEADER, SETTINGS_TYPE_TAPROOT_STYLES } from "./settings-catalog.js";
4
- import { readWorkspaceJson, WORKSPACE_LIMITS } from "./workspace.js";
6
+ import { MEDIA_MANIFEST_FILE_NAME, readWorkspaceJson, WORKSPACE_LIMITS } from "./workspace.js";
5
7
 
6
8
  async function optionalSettings(workspaceDir, settingsType) {
7
9
  try {
@@ -14,13 +16,18 @@ async function optionalSettings(workspaceDir, settingsType) {
14
16
 
15
17
  /** Optional files are independent: losing the header must not discard a known logo, or the reverse. */
16
18
  export async function readFooterBrandInputs(workspaceDir, footerSettings) {
17
- const [header, styles] = await Promise.all([
19
+ const [header, styles, media] = await Promise.all([
18
20
  optionalSettings(workspaceDir, SETTINGS_TYPE_SITE_HEADER),
19
21
  optionalSettings(workspaceDir, SETTINGS_TYPE_TAPROOT_STYLES),
22
+ readWorkspaceJson(workspaceDir, MEDIA_MANIFEST_FILE_NAME, WORKSPACE_LIMITS.manifestBytes).then(value => value?.media ?? {}).catch(() => ({})),
20
23
  ]);
24
+ const pair = resolveFooterLogoPairs({ ...logoInputsFromSettings(styles, footerSettings, media), logoVariant: footerSettings?.logoVariant });
25
+ const visible = [pair.light, pair.dark].filter(value => value.url !== "");
26
+ const ratios = visible.map(value => Number(value.aspectRatio));
27
+ const knownRatios = visible.length > 0 && ratios.every(value => Number.isFinite(value) && value > 0);
21
28
  return {
22
29
  brandText: typeof header?.brandText === "string" ? header.brandText : "",
23
- hasLogo: [styles?.lightLogoId, styles?.darkLogoId, footerSettings?.light?.logoId, footerSettings?.dark?.logoId]
24
- .some(isCanonicalUuid),
30
+ hasLogo: visible.length > 0,
31
+ ...(knownRatios ? { logoAspectRatio: footerLogoAspectRatio(ratios) } : {}),
25
32
  };
26
33
  }
@@ -1,6 +1,6 @@
1
1
  // Generated from shared/footer-branding.ts by scripts/sync-field-validation.mjs. Do not edit.
2
2
  import { DISPLAY_SCALE_LIMITS, parseDisplayScale } from "./display-scale.js";
3
- import { resolveHeaderLogoPairs } from "./header-presentation.js";
3
+ import { resolveHeaderLogoPairs, resolveLogoVariant, } from "./header-presentation.js";
4
4
  export const FOOTER_LOGO_SCALE_LIMITS = DISPLAY_SCALE_LIMITS;
5
5
  export const FOOTER_LOGO_BOX = Object.freeze({ heightRem: 3, maxWidthRem: 12 });
6
6
  /** TR01365's unpublished Large setting scaled both logo and text before separation. */
@@ -11,7 +11,7 @@ export function parseFooterLogoScale(value, brandSize) {
11
11
  export function resolveFooterLogoScale(value, brandSize) {
12
12
  return parseFooterLogoScale(value, brandSize) ?? parseDisplayScale("");
13
13
  }
14
- export function footerBrandSizeStyles(size, logoScale) {
14
+ export function footerBrandSizeStyleMap(size, logoScale) {
15
15
  const scale = resolveFooterLogoScale(logoScale, size).scale;
16
16
  const declarations = {};
17
17
  if (scale !== 1) {
@@ -25,14 +25,20 @@ export function footerBrandSizeStyles(size, logoScale) {
25
25
  declarations["--esp-footer-brand-text-size"] = "var(--esp-type-big)";
26
26
  declarations["--esp-footer-brand-text-size-compact"] = "var(--esp-type-large)";
27
27
  }
28
- return Object.entries(declarations).map(([key, value]) => `${key}: ${value};`).join(" ");
28
+ return declarations;
29
+ }
30
+ export function footerBrandSizeStyles(size, logoScale) {
31
+ return Object.entries(footerBrandSizeStyleMap(size, logoScale)).map(([key, value]) => `${key}: ${value};`).join(" ");
29
32
  }
30
33
  /** An unset footer scheme inherits its site scheme, never the other footer override. */
31
34
  export function resolveFooterLogoPairs(input) {
32
- const site = resolveHeaderLogoPairs(input);
35
+ // A footer inherits the site pair before either surface selects its artwork.
36
+ const site = resolveHeaderLogoPairs({ ...input, logoVariant: "" });
33
37
  const override = (id, url = "", aspectRatio = "", inherited) => id ? { url, aspectRatio: url ? aspectRatio : "" } : inherited;
34
- return {
38
+ const effective = {
35
39
  light: override(input.lightFooterLogoId, input.lightFooterLogoUrl, input.lightFooterLogoAspectRatio, site.light),
36
40
  dark: override(input.darkFooterLogoId, input.darkFooterLogoUrl, input.darkFooterLogoAspectRatio, site.dark),
37
41
  };
42
+ const variant = resolveLogoVariant(input.logoVariant);
43
+ return variant ? { light: effective[variant], dark: effective[variant] } : effective;
38
44
  }
@@ -0,0 +1,10 @@
1
+ // Generated from shared/footer-content.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ /** These fields belong to presentation; footer content saves and dirty checks leave them alone. */
3
+ export const FOOTER_PRESENTATION_FIELDS = ["context", "logoVariant"];
4
+ /** Preserve raw content values; callers decide whether their document needs normalization. */
5
+ export function projectFooterContent(settings) {
6
+ const content = { ...settings };
7
+ for (const field of FOOTER_PRESENTATION_FIELDS)
8
+ delete content[field];
9
+ return content;
10
+ }
@@ -4,6 +4,7 @@ import {
4
4
  isContactOrWebUrl,
5
5
  } from "./contact-url.js";
6
6
  import { hasControlCharacter, isCanonicalUuid, SiteAuthoringError } from "./errors.js";
7
+ import { LOGO_VARIANTS, resolveLogoVariant } from "./header-presentation.js";
7
8
  import { parseFooterLogoScale, resolveFooterLogoScale } from "./footer-branding.js";
8
9
  import {
9
10
  FOOTER_ALIGNMENT_LAYOUTS,
@@ -15,7 +16,6 @@ import {
15
16
  } from "./footer-alignment.js";
16
17
  import { isSocialLinkUrl, SOCIAL_LINK_URL_MAX_LENGTH, trimSocialLinkInput } from "./social-link-url.js";
17
18
  import socialPlatforms from "./social-platforms.json" with { type: "json" };
18
- import { FOOTER_COLOR_TOKENS, requireAppearanceColor } from "./theme-validation.js";
19
19
 
20
20
  export const FOOTER_LIMITS = Object.freeze({
21
21
  linkColumns: 6,
@@ -81,6 +81,8 @@ export const FOOTER_FIELD_INVENTORY = Object.freeze({
81
81
  "asideAlignment",
82
82
  "bottomAlignment",
83
83
  "logoBox",
84
+ "context",
85
+ "logoVariant",
84
86
  ]),
85
87
  FooterLinkColumn: Object.freeze(["id", "groups", "span", "alignment"]),
86
88
  FooterAlignment: Object.freeze(["horizontal", "vertical", "textAlign"]),
@@ -95,11 +97,6 @@ export const FOOTER_FIELD_INVENTORY = Object.freeze({
95
97
  FooterRichTextRun: Object.freeze(["text", "bold", "italic", "underline", "link"]),
96
98
  FooterInlineLink: Object.freeze(["pageResourceId", "externalUrl"]),
97
99
  FooterSchemeSettings: Object.freeze([
98
- "backgroundColor",
99
- "textColor",
100
- "headingColor",
101
- "linkColor",
102
- "linkHoverColor",
103
100
  "backgroundImageId",
104
101
  "backgroundImageUrl",
105
102
  "backgroundImageOpacity",
@@ -138,6 +135,23 @@ function fail(code, message, field) {
138
135
  throw new SiteAuthoringError(code, message, { field });
139
136
  }
140
137
 
138
+ /** Refuse the retired model before closed-object errors obscure the migration recipe. */
139
+ export function refuseRetiredFooterColors(footer) {
140
+ for (const schemeName of ["light", "dark"]) {
141
+ const scheme = footer?.[schemeName];
142
+ if (!isPlainObject(scheme)) continue;
143
+ for (const name of ["backgroundColor", "textColor", "headingColor", "linkColor", "linkHoverColor"]) {
144
+ if (!Object.hasOwn(scheme, name)) continue;
145
+ const field = `footerSettings.${schemeName}.${name}`;
146
+ fail(
147
+ "appearance.retired_footer_color",
148
+ `${field} is retired. Declare a context in both themes and set footerSettings.context; 'taproot-site help appearance' gives the color-to-context recipe.`,
149
+ field,
150
+ );
151
+ }
152
+ }
153
+ }
154
+
141
155
  function object(value, path, { nullable = false } = {}) {
142
156
  if (nullable && (value === null || value === undefined)) return null;
143
157
  if (!isPlainObject(value)) fail("footer.document_invalid", `${path} must be a JSON object.`, path);
@@ -471,23 +485,6 @@ function scheme(value, path, knownImageIds) {
471
485
  );
472
486
  }
473
487
  return {
474
- backgroundColor: requireAppearanceColor(
475
- value.backgroundColor ?? "",
476
- FOOTER_COLOR_TOKENS.backgroundColor,
477
- `${path}.backgroundColor`,
478
- ),
479
- textColor: requireAppearanceColor(value.textColor ?? "", FOOTER_COLOR_TOKENS.textColor, `${path}.textColor`),
480
- headingColor: requireAppearanceColor(
481
- value.headingColor ?? "",
482
- FOOTER_COLOR_TOKENS.headingColor,
483
- `${path}.headingColor`,
484
- ),
485
- linkColor: requireAppearanceColor(value.linkColor ?? "", FOOTER_COLOR_TOKENS.linkColor, `${path}.linkColor`),
486
- linkHoverColor: requireAppearanceColor(
487
- value.linkHoverColor ?? "",
488
- FOOTER_COLOR_TOKENS.linkHoverColor,
489
- `${path}.linkHoverColor`,
490
- ),
491
488
  logoId: imageId(value.logoId, `${path}.logoId`, knownImageIds),
492
489
  backgroundImageId: imageId(value.backgroundImageId, `${path}.backgroundImageId`, knownImageIds),
493
490
  backgroundImageOpacity: number(value.backgroundImageOpacity, 1, `${path}.backgroundImageOpacity`, 0, 1),
@@ -547,11 +544,6 @@ function featureImage(value, knownImageIds, tolerateStoredValues) {
547
544
 
548
545
  export function footerDefaults() {
549
546
  const defaults = () => ({
550
- backgroundColor: "",
551
- textColor: "",
552
- headingColor: "",
553
- linkColor: "",
554
- linkHoverColor: "",
555
547
  logoId: "",
556
548
  backgroundImageId: "",
557
549
  backgroundImageOpacity: 1,
@@ -587,6 +579,7 @@ function normalizeFooterDocument(
587
579
  { knownPageResourceIds, knownImageIds, tolerateStoredValues = false } = {},
588
580
  ) {
589
581
  value = object(value ?? {}, "footerSettings");
582
+ refuseRetiredFooterColors(value);
590
583
  closed(value, "FooterSettings", "footerSettings");
591
584
  const seenColumnIds = new Set();
592
585
  const seenGroupIds = new Set();
@@ -638,14 +631,36 @@ function normalizeFooterDocument(
638
631
  }
639
632
 
640
633
  const normalizedFeatureImage = featureImage(value.featureImage, knownImageIds, tolerateStoredValues);
641
- const brandSize = choice(value.brandSize === "" ? undefined : value.brandSize, "standard", ["standard", "large"], "footerSettings.brandSize");
634
+ const brandSize = choice(
635
+ value.brandSize === "" ? undefined : value.brandSize,
636
+ "standard",
637
+ ["standard", "large"],
638
+ "footerSettings.brandSize",
639
+ );
642
640
  const logoScale = tolerateStoredValues
643
641
  ? resolveFooterLogoScale(value.logoScale, brandSize)
644
642
  : parseFooterLogoScale(value.logoScale, brandSize);
645
643
  if (logoScale === null) {
646
- fail("footer.field_invalid", "footerSettings.logoScale must be a string from 1.0 through 5.0 in 0.1 steps.", "footerSettings.logoScale");
644
+ fail(
645
+ "footer.field_invalid",
646
+ "footerSettings.logoScale must be a string from 1.0 through 5.0 in 0.1 steps.",
647
+ "footerSettings.logoScale",
648
+ );
649
+ }
650
+ const context = value.context === undefined ? "" : value.context;
651
+ if (typeof context !== "string") {
652
+ fail(
653
+ "settings.context_unknown",
654
+ "footerSettings.context must name a shared theme context or be empty.",
655
+ "footerSettings.context",
656
+ );
647
657
  }
658
+ const logoVariant = tolerateStoredValues
659
+ ? resolveLogoVariant(value.logoVariant)
660
+ : choice(value.logoVariant, "", LOGO_VARIANTS, "footerSettings.logoVariant");
648
661
  return {
662
+ ...(context === "" ? {} : { context }),
663
+ ...(logoVariant === "" ? {} : { logoVariant }),
649
664
  enabled: boolean(value.enabled, false, "footerSettings.enabled"),
650
665
  showBrand: boolean(value.showBrand, true, "footerSettings.showBrand"),
651
666
  brandSpan: span(value.brandSpan, FOOTER_LIMITS.brandSpanMax, "footerSettings.brandSpan"),
@@ -653,7 +668,10 @@ function normalizeFooterDocument(
653
668
  logoScale: logoScale.canonical,
654
669
  logoBox: tolerateStoredValues
655
670
  ? normalizeFooterLogoBox(value.logoBox)
656
- : choice(value.logoBox === "" || value.logoBox === null ? undefined : value.logoBox, "fixed", ["fixed", "natural"], "footerSettings.logoBox"),
671
+ : choice(value.logoBox === "" || value.logoBox === null ? undefined : value.logoBox, "fixed", [
672
+ "fixed",
673
+ "natural",
674
+ ], "footerSettings.logoBox"),
657
675
  ...authoredAlignment(value, "alignment", "footerSettings", tolerateStoredValues),
658
676
  ...authoredAlignment(value, "brandAlignment", "footerSettings", tolerateStoredValues),
659
677
  ...authoredAlignment(value, "asideAlignment", "footerSettings", tolerateStoredValues),
@@ -708,7 +726,9 @@ function normalizeFooterDocument(
708
726
  ...(normalizedFeatureImage === undefined ? {} : { featureImage: normalizedFeatureImage }),
709
727
  showBrandText: boolean(value.showBrandText, true, "footerSettings.showBrandText"),
710
728
  socialLinks: array(value.socialLinks, "footerSettings.socialLinks", FOOTER_LIMITS.socialLinks)
711
- .map((link, index) => socialLink(link, `footerSettings.socialLinks[${index}]`, seenLinkIds, tolerateStoredValues)),
729
+ .map((link, index) =>
730
+ socialLink(link, `footerSettings.socialLinks[${index}]`, seenLinkIds, tolerateStoredValues)
731
+ ),
712
732
  };
713
733
  }
714
734
 
@@ -788,11 +808,6 @@ export const FOOTER_EXAMPLE = Object.freeze({
788
808
  }),
789
809
  ]),
790
810
  light: Object.freeze({
791
- backgroundColor: "--esp-color-layer-1",
792
- textColor: "--esp-color-text",
793
- headingColor: "--esp-color-headings",
794
- linkColor: "--esp-color-link",
795
- linkHoverColor: "--esp-color-link-hover",
796
811
  logoId: "",
797
812
  backgroundImageId: "d461035a-74b6-4528-a4f5-e5a96fb50037",
798
813
  backgroundImageOpacity: 0.18,
@@ -802,11 +817,6 @@ export const FOOTER_EXAMPLE = Object.freeze({
802
817
  additionalTopPaddingRem: 0,
803
818
  }),
804
819
  dark: Object.freeze({
805
- backgroundColor: "--esp-color-background",
806
- textColor: "--esp-color-text",
807
- headingColor: "--esp-color-headings",
808
- linkColor: "--esp-color-link",
809
- linkHoverColor: "--esp-color-link-hover",
810
820
  logoId: "",
811
821
  backgroundImageId: "",
812
822
  backgroundImageOpacity: 1,
@@ -3,12 +3,7 @@ import { createHash } from "node:crypto";
3
3
  import { SiteAuthoringError } from "./errors.js";
4
4
  import { resolveFooterLogoScale } from "./footer-branding.js";
5
5
  import { footerAlignmentProfileValues, normalizeFooterLogoBox } from "./footer-alignment.js";
6
- import { FOOTER_COLOR_TOKENS } from "./theme-validation.js";
7
-
8
- // The ten scheme colors theme push owns — light/dark times the color-token
9
- // registry — so a new footer color changes one executable registry, not a
10
- // hand-copied list. Every other footer field is footer-push content.
11
- const THEME_OWNED_SCHEME_COLORS = Object.freeze(Object.keys(FOOTER_COLOR_TOKENS));
6
+ import { projectFooterContent } from "./footer-content.js";
12
7
 
13
8
  // Matches the package's document-depth convention (CONTENT_LIMITS.documentDepth):
14
9
  // the baseline hashes raw hand-editable JSON, and unbounded nesting would
@@ -17,8 +12,8 @@ const MAXIMUM_CONTENT_DEPTH = 64;
17
12
 
18
13
  /**
19
14
  * The pull baseline over everything `footer push` owns: a stable, type- and
20
- * shape-preserving JSON hash of the raw footer document with exactly the ten
21
- * scheme colors `theme push` overlays removed. The draft hash's canonical
15
+ * shape-preserving JSON hash of the raw footer document with presentation
16
+ * fields removed. The draft hash's canonical
22
17
  * form deliberately normalizes types and shapes the way the server does, so
23
18
  * it cannot see a hand-edit such as `enabled: "true"` or `bottomLinks: {}`;
24
19
  * this baseline must, because `theme push` would otherwise silently discard
@@ -28,16 +23,8 @@ const MAXIMUM_CONTENT_DEPTH = 64;
28
23
  */
29
24
  export function computeFooterContentHash(settings = {}) {
30
25
  requireBoundedDepth(settings);
31
- let content = settings;
32
- if (isContentObject(settings)) {
33
- content = structuredClone(settings);
34
- for (const scheme of ["light", "dark"]) {
35
- if (isContentObject(content[scheme])) {
36
- for (const color of THEME_OWNED_SCHEME_COLORS) delete content[scheme][color];
37
- }
38
- }
39
- }
40
- return createHash("sha256").update(`footer-content-v2${stableJson(content)}`, "utf8").digest("hex");
26
+ const content = isContentObject(settings) ? projectFooterContent(settings) : settings;
27
+ return createHash("sha256").update(`footer-content-v3${stableJson(content)}`, "utf8").digest("hex");
41
28
  }
42
29
 
43
30
  function isContentObject(value) {
@@ -85,12 +72,11 @@ export function stableJson(value) {
85
72
  }
86
73
 
87
74
  // Byte-for-byte port of FooterDraftConcurrency.ComputeHash. The token protects
88
- // the whole footer document while theme push overlays only its ten scheme color
89
- // fields onto a fresh read. Response-only image URLs deliberately do not enter
90
- // the canonical form.
75
+ // footer content independently of theme-owned presentation fields.
76
+ // Response-only image URLs stay outside the canonical form.
91
77
  export function computeFooterDraftHash(settings = {}) {
92
78
  const canonical = [];
93
- append(canonical, "footer-draft-v7");
79
+ append(canonical, "footer-draft-v8");
94
80
  append(canonical, settings.enabled === true);
95
81
  append(canonical, settings.showBrand ?? true);
96
82
  append(canonical, settings.showBrandText ?? true);
@@ -198,11 +184,6 @@ function appendRichText(canonical, richText) {
198
184
 
199
185
  function appendScheme(canonical, rawScheme) {
200
186
  const scheme = rawScheme ?? {};
201
- append(canonical, scheme.backgroundColor ?? "");
202
- append(canonical, scheme.textColor ?? "");
203
- append(canonical, scheme.headingColor ?? "");
204
- append(canonical, scheme.linkColor ?? "");
205
- append(canonical, scheme.linkHoverColor ?? "");
206
187
  append(canonical, normalizeId(scheme.logoId));
207
188
  append(canonical, normalizeId(scheme.backgroundImageId));
208
189
  append(canonical, doubleBits(scheme.backgroundImageOpacity ?? 1));
@@ -98,10 +98,8 @@ export async function advanceFooterManifest(
98
98
  expectedContentHash: computeFooterContentHash(footerSettings),
99
99
  imageIds: [...new Set([...prior.imageIds, ...footerImageIds(footerSettings)])].sort(),
100
100
  };
101
- // The ten scheme colours are part of the presentation change set, so a
102
- // footer save that moved one moved the revision too; the server reports the
103
- // new one from the same transaction and it becomes the baseline the next
104
- // theme push must carry (TR00807). One manifest write for both baselines.
101
+ // Update both baselines in one manifest write. The caller only supplies a
102
+ // presentation revision when it is already safe for this workspace to own.
105
103
  if (presentationRevision !== undefined) {
106
104
  manifest.presentation = presentationManifestEntry(presentationRevision);
107
105
  }
@@ -203,8 +201,8 @@ export function footerManifestEntry(footerSettings) {
203
201
  * `theme push` begins with a fresh server read that replaces the workspace
204
202
  * footer document, so an unpushed footer-content edit would be silently lost.
205
203
  * Refuse while the workspace footer's content hash differs from the recorded
206
- * pull baseline. The ten scheme colors `theme push` overlays are excluded
207
- * from the comparison, so a colour-only edit passes. A manifest that predates
204
+ * pull baseline. The presentation fields `theme push` owns are excluded
205
+ * from the comparison, so a context- or logo-variant-only edit passes. A manifest that predates
208
206
  * the baseline cannot prove the workspace is clean and refuses toward pull:
209
207
  * assuming "unchanged" is exactly the data loss this guard exists to stop.
210
208
  */
@@ -1,6 +1,11 @@
1
1
  // Generated from shared/header-presentation.ts by scripts/sync-field-validation.mjs. Do not edit.
2
2
  import { DISPLAY_SCALE_LIMITS, parseDisplayScale } from "./display-scale.js";
3
3
  export const HEADER_HEIGHT_MULTIPLIER_LIMITS = DISPLAY_SCALE_LIMITS;
4
+ export const LOGO_VARIANTS = Object.freeze(["", "light", "dark"]);
5
+ /** Unknown stored values keep the existing scheme choice; writers validate the literal vocabulary. */
6
+ export function resolveLogoVariant(value) {
7
+ return value === "light" || value === "dark" ? value : "";
8
+ }
4
9
  const STANDARD_HEIGHT = Object.freeze({ tenths: 10, scale: 1, canonical: "" });
5
10
  /** Parse the authored string without floating-point remainder or whitespace normalization. */
6
11
  export function parseHeaderHeightMultiplier(value) {
@@ -34,6 +39,14 @@ export function resolveHeaderLogoPairs(input) {
34
39
  const first = (...pairs) => pairs.find(candidate => candidate.url !== "") ?? pairs[0];
35
40
  const resolvedLight = first(light, profile, dark);
36
41
  const resolvedDark = first(dark, light, profile);
42
+ const variant = resolveLogoVariant(input.logoVariant);
43
+ if (variant) {
44
+ const regular = variant === "light" ? resolvedLight : resolvedDark;
45
+ const compact = variant === "light"
46
+ ? first(compactLight, light, compactDark, regular)
47
+ : first(compactDark, dark, compactLight, regular);
48
+ return { light: regular, dark: regular, lightCompact: compact, darkCompact: compact };
49
+ }
37
50
  return {
38
51
  light: resolvedLight,
39
52
  dark: resolvedDark,
@@ -0,0 +1,38 @@
1
+ import { isCanonicalUuid } from "./errors.js";
2
+
3
+ const identity = value => isCanonicalUuid(value) ? value : "";
4
+ const record = value => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
5
+
6
+ /** Stable image identities can go through the URL resolver without copying its fallback rules. */
7
+ export function logoInputsFromSettings(styles = {}, footer = {}, media = {}) {
8
+ styles = record(styles);
9
+ footer = record(footer);
10
+ const dimensions = new Map(Object.values(record(media)).filter(value => isCanonicalUuid(value?.imageId)).map(value => [value.imageId, value]));
11
+ const ratio = id => {
12
+ const image = dimensions.get(id);
13
+ return Number.isFinite(image?.width) && image.width > 0 && Number.isFinite(image?.height) && image.height > 0
14
+ ? String(image.width / image.height) : "";
15
+ };
16
+ const input = {};
17
+ for (const name of ["light", "dark", "lightCompact", "darkCompact"]) {
18
+ const id = identity(styles[`${name}LogoId`]);
19
+ input[`${name}LogoUrl`] = id;
20
+ input[`${name}LogoAspectRatio`] = ratio(id);
21
+ }
22
+ for (const scheme of ["light", "dark"]) {
23
+ const id = identity(footer[scheme]?.logoId);
24
+ input[`${scheme}FooterLogoId`] = id;
25
+ input[`${scheme}FooterLogoUrl`] = id;
26
+ input[`${scheme}FooterLogoAspectRatio`] = ratio(id);
27
+ }
28
+ return input;
29
+ }
30
+
31
+ /** Shared artwork has no single intended brightness; classify the artifact that actually resolved. */
32
+ export function logoArtworkScheme(identity, input) {
33
+ if (!identity) return undefined;
34
+ const schemes = ["light", "dark"].filter(scheme => [
35
+ input[`${scheme}LogoUrl`], input[`${scheme}CompactLogoUrl`], input[`${scheme}FooterLogoUrl`],
36
+ ].includes(identity));
37
+ return schemes.length === 1 ? schemes[0] : undefined;
38
+ }