@taprootio/site-authoring 0.36.1 → 0.37.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.
@@ -1,4 +1,5 @@
1
1
  import { SiteAuthoringError } from "../errors.js";
2
+ import { readBlockquoteMetadata, validateBlockquoteMetadata } from "./blockquote-metadata.js";
2
3
  import {
3
4
  canonicalizeComponentData,
4
5
  expandComponentAuthoringShorthand,
@@ -25,6 +26,7 @@ import {
25
26
  LINK_REL_TOKENS,
26
27
  LINK_TARGETS,
27
28
  MARK_TYPES,
29
+ pointerSegment,
28
30
  } from "./vocabulary.js";
29
31
 
30
32
  /**
@@ -32,7 +34,8 @@ import {
32
34
  * dependencies.
33
35
  *
34
36
  * The subset is exactly the renderer's vocabulary: paragraphs, ATX headings
35
- * 1-4, hard breaks, bullet and ordered lists, blockquotes, fenced code with a
37
+ * 1-4, hard breaks, bullet and ordered lists, blockquotes (including the
38
+ * metadata envelope), fenced code with a
36
39
  * language, thematic breaks, images, bounded GFM pipe tables,
37
40
  * `component:<type>` fences, and `inline-facts` JSON-array fences; and the
38
41
  * bold, italic, strike, code, and link marks. **Anything outside it is a hard
@@ -75,6 +78,12 @@ const TABLE_CONTRACT = FREE_FORM_SECTION_REGISTRY.table;
75
78
  const TABLE_NODE_TYPES = TABLE_CONTRACT.nodeTypes;
76
79
  const TABLE_CAPTION_STEM = TABLE_CONTRACT.markdown.captionPrefix.trimEnd();
77
80
  const INLINE_FACTS_CONTRACT = FREE_FORM_SECTION_REGISTRY.inlineFacts;
81
+ const BLOCKQUOTE_CONTRACT = FREE_FORM_SECTION_REGISTRY.blockquote;
82
+ const BLOCKQUOTE_HEADER_RE = new RegExp(`^${BLOCKQUOTE_CONTRACT.markdown.open} (\\{.*\\})$`, "u");
83
+ const BLOCKQUOTE_DIRECTIVE_LIKE_RE = new RegExp(
84
+ `^ *(?:${BLOCKQUOTE_CONTRACT.markdown.open}|${BLOCKQUOTE_CONTRACT.markdown.close})(?=\\s|\\{|$)`,
85
+ "u",
86
+ );
78
87
  const TABLE_DELIMITER_TOKEN_RE = new RegExp(
79
88
  `^:?-{${TABLE_CONTRACT.markdown.delimiterMinHyphens},}:?$`,
80
89
  "u",
@@ -256,7 +265,8 @@ function isBlockStart(text) {
256
265
  || REFERENCE_DEFINITION_RE.test(text)
257
266
  || SECTION_HEADER_LIKE_RE.test(text)
258
267
  || SECTION_CLOSE_RE.test(text)
259
- || COLUMNS_DIRECTIVE_LIKE_RE.test(text);
268
+ || COLUMNS_DIRECTIVE_LIKE_RE.test(text)
269
+ || BLOCKQUOTE_DIRECTIVE_LIKE_RE.test(text);
260
270
  }
261
271
 
262
272
  function guardBlockConstructs(text, line, nextText) {
@@ -333,6 +343,13 @@ async function parseBlocks(lines, context, depth) {
333
343
  continue;
334
344
  }
335
345
 
346
+ if (BLOCKQUOTE_DIRECTIVE_LIKE_RE.test(text)) {
347
+ const consumed = await consumeBlockquoteEnvelope(lines, index, context, depth);
348
+ nodes.push(consumed.node);
349
+ index = consumed.next;
350
+ continue;
351
+ }
352
+
336
353
  if (COLUMNS_DIRECTIVE_LIKE_RE.test(text)) {
337
354
  if (context.blockPlacement !== "section" || !text.startsWith(":::columns ")) {
338
355
  throw fail(CODES.markdownColumns, "columns layout", "A columns layout belongs directly inside a section; its headers and closing markers must match.", line.number);
@@ -1009,6 +1026,68 @@ async function componentNode(componentType, body, line, context) {
1009
1026
  // Blockquotes
1010
1027
  // ---------------------------------------------------------------------------
1011
1028
 
1029
+ async function consumeBlockquoteEnvelope(lines, start, context, depth) {
1030
+ const line = lines[start];
1031
+ const header = expandLeadingTabs(line.text);
1032
+ const match = BLOCKQUOTE_HEADER_RE.exec(header);
1033
+ if (!match) {
1034
+ throw fail(
1035
+ CODES.markdownBlockquote,
1036
+ "blockquote",
1037
+ `Use '${BLOCKQUOTE_CONTRACT.markdown.open} {JSON object}' and a matching '${BLOCKQUOTE_CONTRACT.markdown.close}' without indentation or trailing text. A closing marker needs an open blockquote.`,
1038
+ line.number,
1039
+ );
1040
+ }
1041
+ let parsed;
1042
+ try { parsed = JSON.parse(match[1]); } catch (error) {
1043
+ throw fail(CODES.markdownBlockquote, "blockquote", "A blockquote header needs a valid JSON object.", line.number, error);
1044
+ }
1045
+ const [issue] = validateBlockquoteMetadata(parsed);
1046
+ if (issue) {
1047
+ throw fail(issue.code, issue.code === "blockquote.attrs" ? "/attrs" : `/attrs/${pointerSegment(issue.field)}`, issue.message, line.number);
1048
+ }
1049
+ const attrs = readBlockquoteMetadata(parsed);
1050
+ const body = [];
1051
+ let nested = 0;
1052
+ let activeFence;
1053
+ for (let index = start + 1; index < lines.length; index += 1) {
1054
+ const bodyLine = lines[index];
1055
+ const text = expandLeadingTabs(bodyLine.text);
1056
+ if (activeFence) {
1057
+ body.push(bodyLine);
1058
+ if (activeFence.test(text)) activeFence = undefined;
1059
+ continue;
1060
+ }
1061
+ const fence = FENCE_RE.exec(text);
1062
+ if (fence) {
1063
+ activeFence = fenceClosing(fence[2]);
1064
+ body.push(bodyLine);
1065
+ continue;
1066
+ }
1067
+ if (BLOCKQUOTE_HEADER_RE.test(text)) {
1068
+ nested += 1;
1069
+ if (depth + nested > CONTENT_LIMITS.markdownNesting) {
1070
+ throw fail(CODES.markdownNesting, "nesting", `Markdown may not nest more than ${CONTENT_LIMITS.markdownNesting} levels deep.`, bodyLine.number);
1071
+ }
1072
+ }
1073
+ if (text === BLOCKQUOTE_CONTRACT.markdown.close) {
1074
+ if (nested === 0) {
1075
+ const content = await parseBlocks(body, { ...context, blockPlacement: "nested" }, depth + 1);
1076
+ if (content.length === 0) {
1077
+ throw fail(CODES.markdownEmpty, "blockquote", "A blockquote must contain content.", line.number);
1078
+ }
1079
+ return {
1080
+ node: { type: BLOCKQUOTE_CONTRACT.nodeType, ...(Object.keys(attrs).length > 0 ? { attrs } : {}), content },
1081
+ next: index + 1,
1082
+ };
1083
+ }
1084
+ nested -= 1;
1085
+ }
1086
+ body.push(bodyLine);
1087
+ }
1088
+ throw fail(CODES.markdownBlockquote, "blockquote", `A blockquote was opened but never closed with '${BLOCKQUOTE_CONTRACT.markdown.close}'.`, line.number);
1089
+ }
1090
+
1012
1091
  async function consumeBlockquote(lines, start, context, depth) {
1013
1092
  const inner = [];
1014
1093
  let index = start;
@@ -7,6 +7,7 @@
7
7
  * Keep those publishing copies in sync and covered by parity tests.
8
8
  */
9
9
 
10
+ import { blockquoteCaptionParts, readBlockquoteMetadata } from "./blockquote-metadata.js";
10
11
  import { columnsAttributes, isColumnEligibleBlock } from "./free-form-columns.js";
11
12
  import freeFormSectionRegistry from "./free-form-section-registry.json" with { type: "json" };
12
13
  import { imageDescriptionIssues } from "./image-description-validation.js";
@@ -292,11 +293,7 @@ function renderNode(
292
293
  case "listItem":
293
294
  return renderElement("li", {}, renderNodes(node.content ?? [], options, "nested"));
294
295
  case "blockquote":
295
- return renderElement(
296
- "blockquote",
297
- withProseMeasure({}, node.type, options),
298
- renderNodes(node.content ?? [], options, "nested"),
299
- );
296
+ return renderBlockquote(node, options);
300
297
  case "codeBlock":
301
298
  return renderCodeBlock(node, options);
302
299
  case "horizontalRule":
@@ -400,6 +397,27 @@ function renderHeading(node: ProseMirrorNode, options: RenderProseMirrorOptions)
400
397
  );
401
398
  }
402
399
 
400
+ function renderBlockquote(node: ProseMirrorNode, options: RenderProseMirrorOptions): string {
401
+ const metadata = readBlockquoteMetadata(node.attrs) ?? {};
402
+ const quote = renderElement(
403
+ "blockquote",
404
+ withProseMeasure({ ...(metadata.cite ? { cite: metadata.cite } : {}) }, node.type, options),
405
+ renderNodes(node.content ?? [], { ...options, freeFormSections: false }, "nested"),
406
+ );
407
+ const parts = blockquoteCaptionParts(metadata);
408
+ if (parts.length === 0) return quote;
409
+ const caption = parts.map(part => {
410
+ const text = escapeHtml(part.text);
411
+ const content = part.href ? renderLink(part.href, undefined, text, options) : text;
412
+ return part.kind === "title" ? renderElement("cite", {}, content) : content;
413
+ }).join("");
414
+ return renderElement("figure", {
415
+ "data-taproot-quote": "",
416
+ "data-attribution": metadata.attribution,
417
+ "data-source-title": metadata.sourceTitle,
418
+ }, quote + renderElement("figcaption", {}, caption));
419
+ }
420
+
403
421
  function renderCodeBlock(node: ProseMirrorNode, options: RenderProseMirrorOptions): string {
404
422
  const language = stringAttr(node.attrs?.language);
405
423
  const attrs = language ? { class: `language-${language}` } : {};
@@ -1,4 +1,5 @@
1
1
  import { validateColumnsBody } from "./free-form-columns.js";
2
+ import { validateBlockquoteMetadata } from "./blockquote-metadata.js";
2
3
  import { IMAGE_DESCRIPTION_MODES } from "./image-description-validation.js";
3
4
  import { validateComponentBlock } from "./components.js";
4
5
  import {
@@ -378,7 +379,11 @@ const NODE_RULES = Object.freeze({
378
379
  }),
379
380
  // ListItem's content expression is `paragraph block*`.
380
381
  listItem: rule({ children: BLOCKS, minChildren: 1, firstChild: "paragraph" }),
381
- blockquote: rule({ children: BLOCKS, minChildren: 1 }),
382
+ blockquote: rule({
383
+ blockquote: true,
384
+ children: BLOCKS,
385
+ minChildren: 1,
386
+ }),
382
387
  codeBlock: rule({
383
388
  attrs: Object.freeze({
384
389
  language: spec((value) => {
@@ -599,6 +604,12 @@ function checkMarkKeys(mark, markPath, state) {
599
604
  function checkAttrs(node, path, nodeRule, state) {
600
605
  const attrsPath = `${path}/attrs`;
601
606
  const attrs = node.attrs;
607
+ if (nodeRule.blockquote) {
608
+ for (const issue of validateBlockquoteMetadata(attrs)) {
609
+ report(state, issue.code === "blockquote.attrs" ? attrsPath : `${attrsPath}/${pointerSegment(issue.field)}`, issue.code, issue.message);
610
+ }
611
+ return;
612
+ }
602
613
  const present = isPlainObject(attrs);
603
614
 
604
615
  if (!isAbsent(attrs) && !present) {
@@ -175,6 +175,7 @@ export const CONTENT_ERROR_CODES = Object.freeze({
175
175
  markdownUnclosedFence: "content.markdown_unclosed_fence",
176
176
  markdownCodeLanguage: "content.markdown_code_language",
177
177
  markdownColumns: "content.markdown_columns",
178
+ markdownBlockquote: "content.markdown_blockquote",
178
179
  markdownSectionHeader: "content.markdown_section_header",
179
180
  markdownSectionUnclosed: "content.markdown_section_unclosed",
180
181
  markdownSectionNested: "content.markdown_section_nested",
package/src/errors.js CHANGED
@@ -219,3 +219,18 @@ export function asSiteAuthoringError(error) {
219
219
  ? error
220
220
  : new SiteAuthoringError("site.failed", "The Taproot site authoring command failed.");
221
221
  }
222
+
223
+ // A send that ended this way may still have written the page.
224
+ const OUTCOME_UNKNOWN_CODES = new Set([
225
+ "transport.mutation_ambiguous",
226
+ "transport.response_read",
227
+ "transport.response_too_large",
228
+ "transport.invalid_json",
229
+ "api.page_contract",
230
+ ]);
231
+
232
+ export function outcomeUnknown(error) {
233
+ // A cancelled retry of a write, and a server error on a write the transport
234
+ // does not replay, leave the same question open.
235
+ return OUTCOME_UNKNOWN_CODES.has(error.code) || error.ambiguousMutation === true || error.httpStatus >= 500;
236
+ }
@@ -22,10 +22,17 @@ export function parseHeaderHeightMultiplier(value) {
22
22
  export function resolveHeaderHeightMultiplier(value) {
23
23
  return parseHeaderHeightMultiplier(value) ?? STANDARD_HEIGHT;
24
24
  }
25
+ /** Clamp only the rendered endpoint, retaining the author's saved minimum. */
26
+ export function resolveHeaderMinHeightMultiplier(minimum, expanded) {
27
+ const height = resolveHeaderHeightMultiplier(expanded);
28
+ const floor = resolveHeaderHeightMultiplier(minimum);
29
+ return floor.tenths < height.tenths ? floor : height;
30
+ }
25
31
  /** Stored compact assets are delivered only when an expanded brand already exists. */
26
- export function canUseCompactHeaderLogo(position, multiplier, hasRegularLogo) {
32
+ export function canUseCompactHeaderLogo(position, multiplier, hasRegularLogo, minimum) {
27
33
  const height = parseHeaderHeightMultiplier(multiplier);
28
- return position === "fixed" && hasRegularLogo && height !== null && height.tenths > 10;
34
+ return position === "fixed" && hasRegularLogo && height !== null
35
+ && height.tenths > resolveHeaderMinHeightMultiplier(minimum, multiplier).tenths;
29
36
  }
30
37
  /** Keep each scheme's selected source and reserved ratio together through fallback. */
31
38
  export function resolveHeaderLogoPairs(input) {
@@ -0,0 +1,243 @@
1
+ // Generated from shared/placed-image-ids.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ /**
3
+ * The images a page places (TR01364), read from the wire form the CLI holds.
4
+ *
5
+ * `PageImageReferenceExtractor.Extract` in the API decides which images a page places, over its stored
6
+ * `templateData`. The CLI holds the wire form (the proto-JSON data member of a page read or of
7
+ * `wireTemplate(document)`), so this mirrors `Extract` over that shape, and C# is authoritative.
8
+ * `shared/image-reference-corpus.json` holds the two together: the API test maps each case's wire twin to its stored
9
+ * twin and runs `Extract` over it, and the CLI test runs this over the wire twin.
10
+ *
11
+ * It does not validate, so it cannot reproduce `ColumnsBodyPolicy`: for a body `PageTemplateBodies.Read` would
12
+ * reject, it returns every id its walk reaches. It never throws. Known gaps, all outside this file's reach:
13
+ * - ids that are server-only and absent from the wire form (the freezer's integration placements, and an
14
+ * integration-managed page's own referenced ids), which the stored Site Health report still covers;
15
+ * - C# stops at `System.Text.Json`'s default depth of 64 where this walk is bounded at 256;
16
+ * - C# keeps duplicate property names in decoded component data where `JSON.parse` keeps the last one;
17
+ * - the `Guid.TryParse` X format (`{0x...}`), and the numeric entities .NET also decodes with a sign or
18
+ * whitespace (`&#+34;`, `&# 34;`).
19
+ *
20
+ * It is dependency-free so the published site-authoring package can carry a compiled copy. Only the CLI uses it,
21
+ * so `node scripts/sync-field-validation.mjs` writes just that copy; edit only this file and re-run it.
22
+ */
23
+ /** Matches the depth the link extractors use, so a hostile body cannot overflow the stack. */
24
+ const MAXIMUM_DEPTH = 256;
25
+ const DOTNET_WHITESPACE = "\\t-\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
26
+ const LEADING_WHITESPACE = new RegExp(`^[${DOTNET_WHITESPACE}]+`, "u");
27
+ const TRAILING_WHITESPACE = new RegExp(`[${DOTNET_WHITESPACE}]+$`, "u");
28
+ const GROUPED_GUID = "([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})";
29
+ const GUID_N = /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/iu;
30
+ const GUID_D = new RegExp(`^${GROUPED_GUID}$`, "iu");
31
+ const GUID_B = new RegExp(`^\\{${GROUPED_GUID}\\}$`, "iu");
32
+ const GUID_P = new RegExp(`^\\(${GROUPED_GUID}\\)$`, "iu");
33
+ /** The lowercase hyphenated form of a GUID `Guid.TryParse` accepts (formats N, D, B and P), else `undefined`. */
34
+ function parseGuid(value) {
35
+ if (typeof value !== "string")
36
+ return undefined;
37
+ const trimmed = value.replace(LEADING_WHITESPACE, "").replace(TRAILING_WHITESPACE, "");
38
+ const match = GUID_N.exec(trimmed) ?? GUID_D.exec(trimmed) ?? GUID_B.exec(trimmed) ?? GUID_P.exec(trimmed);
39
+ return match === null ? undefined : match.slice(1).join("-").toLowerCase();
40
+ }
41
+ const NAMED_ENTITIES = {
42
+ quot: "\"",
43
+ amp: "&",
44
+ lt: "<",
45
+ gt: ">",
46
+ apos: "'",
47
+ nbsp: "\u00a0",
48
+ ensp: "\u2002",
49
+ emsp: "\u2003",
50
+ thinsp: "\u2009",
51
+ };
52
+ const ENTITY = /&(?:#[xX]([0-9a-fA-F]+)|#([0-9]+)|(quot|amp|lt|gt|apos|nbsp|ensp|emsp|thinsp));/gu;
53
+ /** One decoded code point, or `undefined` when .NET leaves the entity as text (too large, or a surrogate). */
54
+ function numericEntity(digits, radix) {
55
+ const significant = digits.replace(/^0+/u, "");
56
+ // 0x10FFFF is six hex digits and 1114111 seven decimal ones; a longer run is above it, or overflows .NET's parse.
57
+ if (significant.length > (radix === 16 ? 6 : 7))
58
+ return undefined;
59
+ const codePoint = significant === "" ? 0 : Number.parseInt(significant, radix);
60
+ if (codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff))
61
+ return undefined;
62
+ return String.fromCodePoint(codePoint);
63
+ }
64
+ /**
65
+ * `PageTemplateBodies.HtmlDecodeRepeatedly`: exactly three rounds, each one left-to-right pass over the closed
66
+ * set of entities that can change JSON structure or a GUID read (the four whitespace ones are there because
67
+ * .NET decodes them to characters `Guid.TryParse` trims). An unknown or malformed entity stays text.
68
+ */
69
+ function decodeComponentData(text) {
70
+ let decoded = text;
71
+ for (let round = 0; round < 3; round += 1) {
72
+ decoded = decoded.replace(ENTITY, (entity, hex, decimal, name) => {
73
+ if (name !== undefined)
74
+ return NAMED_ENTITIES[name] ?? entity;
75
+ return numericEntity(hex ?? decimal ?? "", hex === undefined ? 10 : 16) ?? entity;
76
+ });
77
+ }
78
+ return decoded;
79
+ }
80
+ function isDictionary(value) {
81
+ return typeof value === "object" && value !== null && !Array.isArray(value);
82
+ }
83
+ function own(dictionary, key) {
84
+ return Object.hasOwn(dictionary, key) ? dictionary[key] : undefined;
85
+ }
86
+ function addGuid(ids, value) {
87
+ const guid = parseGuid(value);
88
+ if (guid !== undefined)
89
+ ids.add(guid);
90
+ }
91
+ /** The id in `parent[property].imageId`, when `parent[property]` is an object. */
92
+ function addProcessedImage(ids, parent, property) {
93
+ const image = own(parent, property);
94
+ if (isDictionary(image) && typeof own(image, "imageId") === "string")
95
+ addGuid(ids, own(image, "imageId"));
96
+ }
97
+ /** The nodes of one body that name an image: what `AddImageIdsFromProseMirrorJson` reads at each node. */
98
+ function addNodeImages(ids, node) {
99
+ const type = own(node, "type");
100
+ const attributes = own(node, "attrs");
101
+ if (!isDictionary(attributes))
102
+ return;
103
+ if (type === "section") {
104
+ const decoration = own(attributes, "decoration");
105
+ if (isDictionary(decoration))
106
+ addProcessedImage(ids, decoration, "image");
107
+ const background = own(attributes, "background");
108
+ if (isDictionary(background)) {
109
+ addProcessedImage(ids, background, "image");
110
+ addProcessedImage(ids, background, "portraitImage");
111
+ }
112
+ }
113
+ else if (type === "taprootImage") {
114
+ if (typeof own(attributes, "imageId") === "string")
115
+ addGuid(ids, own(attributes, "imageId"));
116
+ }
117
+ else if (type === "integrationFragment") {
118
+ const imageIds = own(attributes, "imageIds");
119
+ if (Array.isArray(imageIds))
120
+ for (const imageId of imageIds)
121
+ if (typeof imageId === "string")
122
+ addGuid(ids, imageId);
123
+ }
124
+ else if (type === "componentBlock" && Object.hasOwn(attributes, "componentData")) {
125
+ addComponentImages(ids, own(attributes, "componentData"));
126
+ }
127
+ }
128
+ /**
129
+ * `AddImageIdsFromJson`: every string-valued `imageId` property at any depth, and nothing else. It is iterative and
130
+ * bounded, like the body walk.
131
+ */
132
+ function addGenericImageIds(ids, root) {
133
+ const stack = [[root, 0]];
134
+ for (let next = stack.pop(); next !== undefined; next = stack.pop()) {
135
+ const [value, depth] = next;
136
+ if (depth > MAXIMUM_DEPTH)
137
+ continue;
138
+ if (Array.isArray(value)) {
139
+ for (const item of value)
140
+ stack.push([item, depth + 1]);
141
+ }
142
+ else if (isDictionary(value)) {
143
+ for (const [key, child] of Object.entries(value)) {
144
+ if (key === "imageId" && typeof child === "string")
145
+ addGuid(ids, child);
146
+ else
147
+ stack.push([child, depth + 1]);
148
+ }
149
+ }
150
+ }
151
+ }
152
+ /**
153
+ * A string `componentData` is decoded, parsed and searched by the generic rule only. An object or array gets the
154
+ * generic rule here too, and the body walk then also recurses into it, so a nested `integrationFragment` counts
155
+ * inside an object but not inside a decoded string. Malformed component JSON reads as no ids, as in C#.
156
+ */
157
+ function addComponentImages(ids, componentData) {
158
+ if (typeof componentData === "string") {
159
+ let parsed;
160
+ try {
161
+ parsed = JSON.parse(decodeComponentData(componentData));
162
+ }
163
+ catch {
164
+ return;
165
+ }
166
+ addGenericImageIds(ids, parsed);
167
+ }
168
+ else if (Array.isArray(componentData) || isDictionary(componentData)) {
169
+ addGenericImageIds(ids, componentData);
170
+ }
171
+ }
172
+ /** Every node of a rich-text body, to the depth bound, so each one is read by `addNodeImages`. */
173
+ function addBodyImageIds(ids, body) {
174
+ const stack = [[body, 0]];
175
+ for (let next = stack.pop(); next !== undefined; next = stack.pop()) {
176
+ const [value, depth] = next;
177
+ if (depth > MAXIMUM_DEPTH)
178
+ continue;
179
+ if (Array.isArray(value)) {
180
+ for (const item of value)
181
+ stack.push([item, depth + 1]);
182
+ }
183
+ else if (isDictionary(value)) {
184
+ addNodeImages(ids, value);
185
+ for (const child of Object.values(value))
186
+ stack.push([child, depth + 1]);
187
+ }
188
+ }
189
+ }
190
+ /** The wire keys of a template's rich-text bodies, as `PageTemplateBodies.Read` walks them. */
191
+ function templateBodies(templateType, data) {
192
+ switch (templateType) {
193
+ case "free-form":
194
+ case "article":
195
+ case "place-review":
196
+ case "legal":
197
+ return [own(data, "body")];
198
+ case "recipe": {
199
+ const sections = own(data, "instructionSections");
200
+ return [
201
+ own(data, "introductionBody"),
202
+ ...(Array.isArray(sections)
203
+ ? sections.flatMap((section) => {
204
+ const steps = isDictionary(section) ? own(section, "stepBodies") : undefined;
205
+ return Array.isArray(steps) ? steps : [];
206
+ })
207
+ : []),
208
+ ];
209
+ }
210
+ case "album":
211
+ case "generated":
212
+ return [own(data, "introductionBody")];
213
+ default:
214
+ return [];
215
+ }
216
+ }
217
+ /**
218
+ * The image ids a page places, as a sorted, de-duplicated array of lowercase hyphenated GUIDs. `templateType` is a
219
+ * workspace template name (`free-form`, `article`, `recipe`, `album`, `place-review`, `legal` or `generated`); any
220
+ * other value, including `integration-managed`, returns an empty list. `data` is the wire form's data member (the
221
+ * `[dataKey]` member of `wireTemplate(document)`), never the wrapper. The caller adds the cover image separately.
222
+ */
223
+ export function placedImageIds(templateType, data) {
224
+ const ids = new Set();
225
+ try {
226
+ if (isDictionary(data)) {
227
+ for (const body of templateBodies(templateType, data))
228
+ addBodyImageIds(ids, body);
229
+ if (templateType === "album") {
230
+ const images = own(data, "images");
231
+ if (Array.isArray(images)) {
232
+ for (const image of images)
233
+ if (isDictionary(image))
234
+ addGuid(ids, own(image, "imageId"));
235
+ }
236
+ }
237
+ }
238
+ }
239
+ catch {
240
+ // Never throw: an unreadable shape returns what the walk had reached.
241
+ }
242
+ return [...ids].sort();
243
+ }
@@ -502,7 +502,7 @@ export function getAppearanceReference() {
502
502
  "Use site-owned image ids retained from pull or returned by media upload. URLs are server projections, never authored inputs.",
503
503
  logoContract:
504
504
  "lightLogoId and darkLogoId are the expanded scheme logos; optional lightCompactLogoId and darkCompactLogoId "
505
- + "supply compact logos for Fixed headers above 1.0 when a regular logo resolves. Inactive choices are retained. "
505
+ + "supply compact logos for Fixed headers above 1.0 when a regular logo resolves. A ready compact logo appears when shrinking starts; pending or failed artwork keeps the regular logo. Inactive choices are retained. "
506
506
  + "Each takes one image id: upload the highest-resolution file you have and assign it. An @2x or @3x suffix is only "
507
507
  + "part of a filename, nothing pairs it with another file, and the platform generates the sizes. "
508
508
  + "Prefer transparent PNG or WebP artwork with genuine alpha so the header background shows through, including "