@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.
- package/README.md +50 -0
- package/examples/riverbend-wellness/settings/site-publishing-preferences.json +3 -0
- package/examples/riverbend-wellness/settings/taproot-styles.json +11 -0
- package/package.json +4 -3
- package/src/api.js +170 -11
- package/src/appearance-contract.js +278 -8
- package/src/authored-tag-names.js +88 -0
- package/src/block-flow.js +103 -1
- package/src/brand-color.js +39 -4
- package/src/breadcrumb-artwork.js +234 -0
- package/src/breadcrumb-separators.js +11 -0
- package/src/changelog.json +154 -0
- package/src/chrome-features.js +152 -0
- package/src/chrome-input.js +147 -0
- package/src/chrome-output.js +92 -0
- package/src/chrome-paint-catalog-taproot.json +52 -0
- package/src/chrome-report.js +173 -0
- package/src/cli.js +48 -17
- package/src/content/components.js +27 -4
- package/src/content/external-link.js +2 -1
- package/src/content/markdown.js +271 -101
- package/src/content/tiptap-prosemirror.ts +125 -43
- package/src/content/validate-document.js +4 -1
- package/src/content-inset.js +48 -0
- package/src/errors.js +1 -0
- package/src/espalier-shared.js +26 -0
- package/src/field-suggestions.js +40 -0
- package/src/fixture-init.js +22 -5
- package/src/font-catalog.js +11 -1
- package/src/footer-brand-inputs.js +25 -2
- package/src/footer-content.js +38 -0
- package/src/footer-contract.js +11 -0
- package/src/footer-cta-styles.js +6 -0
- package/src/footer-draft-hash.js +4 -2
- package/src/footer-fit.js +62 -15
- package/src/footer-workspace.js +60 -16
- package/src/header-presentation.js +16 -0
- package/src/latest-posts-tags.js +57 -0
- package/src/page-structure-checks.js +5 -0
- package/src/page-tag-badge-modes.js +6 -0
- package/src/page-tag-writes.js +158 -0
- package/src/page-type-tags.js +16 -0
- package/src/presentation-reference.js +312 -86
- package/src/recipe-page-options.js +22 -0
- package/src/recipe-step-contract.js +164 -0
- package/src/recipe-step-contract.json +65 -0
- package/src/reference-help.js +164 -78
- package/src/session.js +39 -24
- package/src/setting-reference.js +239 -48
- package/src/settings-catalog.js +63 -0
- package/src/site-check-findings.js +25 -5
- package/src/site-check-rules.json +3 -1
- package/src/site-health-findings.js +13 -13
- package/src/site-navigation-groups.js +70 -0
- package/src/styling-fixed-values.js +71 -0
- package/src/tag-destination-warnings.js +35 -0
- package/src/template-token-reach.json +242 -0
- package/src/theme-proposals.js +18 -27
- package/src/theme-resolve.js +305 -51
- package/src/theme-validation.js +126 -6
- package/src/token-reach.js +222 -0
- package/src/typed-page-reference.js +72 -15
- package/src/typed-pages.js +171 -71
- package/src/verbs/deploy.js +6 -0
- package/src/verbs/footer-push.js +30 -5
- package/src/verbs/forms-push.js +11 -3
- package/src/verbs/pages-delete.js +19 -10
- package/src/verbs/pages-push.js +125 -36
- package/src/verbs/plan.js +10 -4
- package/src/verbs/pull.js +277 -67
- package/src/verbs/staging-review.js +27 -1
- package/src/verbs/status.js +22 -0
- package/src/verbs/theme-push.js +249 -120
- package/src/verbs/theme-resolve.js +310 -47
- package/src/verbs/validate.js +71 -17
- package/src/workspace-check.js +37 -4
- package/src/workspace.js +37 -1
- package/test/fixtures/default-site-theme.json +516 -0
|
@@ -89,9 +89,10 @@ export interface RenderProseMirrorOptions {
|
|
|
89
89
|
/** The page shell emits this default once so rich-text formats inherit it. */
|
|
90
90
|
maxHeightVh?: TiptapImageMaxHeightVh | number | null;
|
|
91
91
|
};
|
|
92
|
+
headingSpacing?: { imagePlacement: unknown };
|
|
92
93
|
/** Generator-only render hooks for structured nodes that need page context. */
|
|
93
94
|
nodeRenderers?: {
|
|
94
|
-
componentBlock?: (node: ProseMirrorNode) => string | undefined;
|
|
95
|
+
componentBlock?: (node: ProseMirrorNode, headingFlow: boolean) => string | undefined;
|
|
95
96
|
taprootImage?: (
|
|
96
97
|
node: ProseMirrorNode,
|
|
97
98
|
context: { groupColumns?: number; fullWidth: boolean },
|
|
@@ -111,6 +112,8 @@ export interface RenderProseMirrorOptions {
|
|
|
111
112
|
* previews and PDFs render as before.
|
|
112
113
|
*/
|
|
113
114
|
siteHosts?: ReadonlySet<string>;
|
|
115
|
+
/** Recipe step links carry their stored, validated title. */
|
|
116
|
+
linkTitles?: boolean;
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
export function createEmptyProseMirrorDocument(): ProseMirrorDocument {
|
|
@@ -131,9 +134,12 @@ export function renderProseMirrorDocumentToHtml(
|
|
|
131
134
|
options: RenderProseMirrorOptions = {},
|
|
132
135
|
): string {
|
|
133
136
|
if (!document?.content?.length) return "";
|
|
137
|
+
const layout = options.headingSpacing
|
|
138
|
+
? { ...options, headingSpacingAllowed: headingSpacingEligibility(document, options.headingSpacing.imagePlacement) }
|
|
139
|
+
: options;
|
|
134
140
|
return options.freeFormSections
|
|
135
|
-
? renderFreeFormRootNodes(document.content,
|
|
136
|
-
: renderNodes(document.content,
|
|
141
|
+
? renderFreeFormRootNodes(document.content, layout)
|
|
142
|
+
: renderNodes(document.content, layout, "root");
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
export function renderRichTextBodyToHtml(
|
|
@@ -181,13 +187,68 @@ function isTextBlock(type: string): boolean {
|
|
|
181
187
|
}
|
|
182
188
|
|
|
183
189
|
type RenderPlacement = "root" | "section" | "column" | "nested";
|
|
184
|
-
type RenderOptionsWithLayout = RenderProseMirrorOptions & {
|
|
190
|
+
type RenderOptionsWithLayout = RenderProseMirrorOptions & {
|
|
191
|
+
fullWidthImages?: boolean;
|
|
192
|
+
headingSpacingAllowed?: (nodes: readonly ProseMirrorNode[]) => boolean;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
function anyNode(
|
|
196
|
+
nodes: readonly ProseMirrorNode[],
|
|
197
|
+
matches: (node: ProseMirrorNode) => boolean,
|
|
198
|
+
skipDescendants?: (node: ProseMirrorNode) => boolean,
|
|
199
|
+
): boolean {
|
|
200
|
+
return nodes.some(node =>
|
|
201
|
+
matches(node)
|
|
202
|
+
|| (!skipDescendants?.(node) && anyNode(node.content ?? [], matches, skipDescendants))
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function headingSpacingEligibility(
|
|
207
|
+
document: ProseMirrorDocument,
|
|
208
|
+
effectivePlacement: unknown,
|
|
209
|
+
): (nodes: readonly ProseMirrorNode[]) => boolean {
|
|
210
|
+
if (
|
|
211
|
+
anyNode(document.content ?? [], node => node.type === "integrationFragment" || node.type === "integrationPlacement")
|
|
212
|
+
) {
|
|
213
|
+
return () => false;
|
|
214
|
+
}
|
|
215
|
+
return nodes =>
|
|
216
|
+
!anyNode(nodes, node => {
|
|
217
|
+
if (node.type !== "taprootImage") return false;
|
|
218
|
+
const attrs = node.attrs ?? {};
|
|
219
|
+
if (effectivePlacement === undefined && inheritsImagePlacement(attrs)) return true;
|
|
220
|
+
const placement = resolvePlacement(attrs, effectivePlacement);
|
|
221
|
+
return placement === "left-text-right" || placement === "right-text-left";
|
|
222
|
+
}, node => node.type === "columns" || node.type === "section");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function textHasLineBox(node: ProseMirrorNode): boolean {
|
|
226
|
+
return anyNode(node.content ?? [], child =>
|
|
227
|
+
child.type === "hardBreak"
|
|
228
|
+
|| (child.type === "text" && (
|
|
229
|
+
/[^ \t\n\r\f]/u.test(child.text ?? "")
|
|
230
|
+
|| (Boolean(child.text) && child.marks?.some(mark => mark.type === "code") === true)
|
|
231
|
+
)));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function headingFlowAttrs(
|
|
235
|
+
node: ProseMirrorNode,
|
|
236
|
+
kind: "heading" | "paragraph",
|
|
237
|
+
allowed: boolean,
|
|
238
|
+
): Record<string, string> {
|
|
239
|
+
return allowed ? { "data-heading-flow": textHasLineBox(node) ? kind : "empty" } : {};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function headingNeighborAttrs(kind: string, allowed: boolean): Record<string, string> {
|
|
243
|
+
return allowed ? { "data-heading-flow-neighbor": kind } : {};
|
|
244
|
+
}
|
|
185
245
|
|
|
186
246
|
function renderNodes(
|
|
187
247
|
nodes: readonly ProseMirrorNode[],
|
|
188
248
|
options: RenderOptionsWithLayout,
|
|
189
249
|
placement: RenderPlacement,
|
|
190
250
|
): string {
|
|
251
|
+
const headingFlow = placement !== "nested" && options.headingSpacingAllowed?.(nodes) === true;
|
|
191
252
|
let imageRunEnd = 0;
|
|
192
253
|
let groupColumns: number | undefined;
|
|
193
254
|
return nodes.map((node, index) => {
|
|
@@ -200,7 +261,7 @@ function renderNodes(
|
|
|
200
261
|
? Math.min(count, normalizeTiptapImageMaxImagesPerRow(options.imageDefaults?.maxImagesPerRow))
|
|
201
262
|
: undefined;
|
|
202
263
|
}
|
|
203
|
-
const html = renderNode(node, options, placement, false, isImage ? groupColumns : undefined);
|
|
264
|
+
const html = renderNode(node, options, placement, false, isImage ? groupColumns : undefined, headingFlow);
|
|
204
265
|
options.onRenderedNode?.(node, html);
|
|
205
266
|
return html;
|
|
206
267
|
}).join("");
|
|
@@ -208,7 +269,7 @@ function renderNodes(
|
|
|
208
269
|
|
|
209
270
|
function renderFreeFormRootNodes(
|
|
210
271
|
nodes: readonly ProseMirrorNode[],
|
|
211
|
-
options:
|
|
272
|
+
options: RenderOptionsWithLayout,
|
|
212
273
|
): string {
|
|
213
274
|
const rendered: string[] = [];
|
|
214
275
|
let flow: ProseMirrorNode[] = [];
|
|
@@ -263,6 +324,7 @@ function renderNode(
|
|
|
263
324
|
placement: RenderPlacement,
|
|
264
325
|
compactFollowing = false,
|
|
265
326
|
groupColumns?: number,
|
|
327
|
+
headingFlow = false,
|
|
266
328
|
): string {
|
|
267
329
|
switch (node.type) {
|
|
268
330
|
case "doc":
|
|
@@ -270,7 +332,11 @@ function renderNode(
|
|
|
270
332
|
case "paragraph":
|
|
271
333
|
return renderElement(
|
|
272
334
|
"p",
|
|
273
|
-
withProseMeasure(
|
|
335
|
+
withProseMeasure(
|
|
336
|
+
{ ...textBlockAttrs(node.attrs), ...headingFlowAttrs(node, "paragraph", headingFlow) },
|
|
337
|
+
node.type,
|
|
338
|
+
options,
|
|
339
|
+
),
|
|
274
340
|
renderNodes(node.content ?? [], options, "nested"),
|
|
275
341
|
);
|
|
276
342
|
case "text":
|
|
@@ -278,27 +344,27 @@ function renderNode(
|
|
|
278
344
|
case "hardBreak":
|
|
279
345
|
return "<br>";
|
|
280
346
|
case "heading":
|
|
281
|
-
return renderHeading(node, options);
|
|
347
|
+
return renderHeading(node, options, headingFlow);
|
|
282
348
|
case "bulletList":
|
|
283
349
|
return renderElement(
|
|
284
350
|
"ul",
|
|
285
|
-
withProseMeasure(
|
|
351
|
+
withProseMeasure(headingNeighborAttrs("list", headingFlow), node.type, options),
|
|
286
352
|
renderNodes(node.content ?? [], options, "nested"),
|
|
287
353
|
);
|
|
288
354
|
case "orderedList":
|
|
289
355
|
return renderElement(
|
|
290
356
|
"ol",
|
|
291
|
-
withProseMeasure(
|
|
357
|
+
withProseMeasure(headingNeighborAttrs("list", headingFlow), node.type, options),
|
|
292
358
|
renderNodes(node.content ?? [], options, "nested"),
|
|
293
359
|
);
|
|
294
360
|
case "listItem":
|
|
295
361
|
return renderElement("li", {}, renderNodes(node.content ?? [], options, "nested"));
|
|
296
362
|
case "blockquote":
|
|
297
|
-
return renderBlockquote(node, options);
|
|
363
|
+
return renderBlockquote(node, options, headingFlow);
|
|
298
364
|
case "codeBlock":
|
|
299
|
-
return renderCodeBlock(node, options);
|
|
365
|
+
return renderCodeBlock(node, options, headingFlow);
|
|
300
366
|
case "horizontalRule":
|
|
301
|
-
return
|
|
367
|
+
return `<hr${serializeAttributes(headingNeighborAttrs("rule", headingFlow))}>`;
|
|
302
368
|
case "table":
|
|
303
369
|
return placement === "root" || placement === "section" || placement === "column"
|
|
304
370
|
? renderTable(node, options)
|
|
@@ -309,7 +375,7 @@ function renderNode(
|
|
|
309
375
|
case "inlineFacts":
|
|
310
376
|
return renderInlineFacts(node, options, placement);
|
|
311
377
|
case "componentBlock":
|
|
312
|
-
return options.nodeRenderers?.componentBlock?.(node) ?? renderComponentBlock(node);
|
|
378
|
+
return options.nodeRenderers?.componentBlock?.(node, headingFlow) ?? renderComponentBlock(node, headingFlow);
|
|
313
379
|
case "integrationPlacement":
|
|
314
380
|
return renderIntegrationPlacement(node, options);
|
|
315
381
|
case "columns":
|
|
@@ -387,22 +453,33 @@ function wrapMark(html: string, mark: ProseMirrorMark, options: RenderProseMirro
|
|
|
387
453
|
}
|
|
388
454
|
}
|
|
389
455
|
|
|
390
|
-
function renderHeading(node: ProseMirrorNode, options:
|
|
456
|
+
function renderHeading(node: ProseMirrorNode, options: RenderOptionsWithLayout, headingFlow: boolean): string {
|
|
391
457
|
const rawLevel = numberAttr(node.attrs?.level) ?? 1;
|
|
392
458
|
const authored = Math.min(4, Math.max(1, Math.trunc(rawLevel)));
|
|
393
459
|
const level = Math.min(6, Math.max(1, options.headingLevel?.(authored) ?? authored));
|
|
394
460
|
return renderElement(
|
|
395
461
|
`h${level}`,
|
|
396
|
-
withProseMeasure(
|
|
462
|
+
withProseMeasure(
|
|
463
|
+
{ ...textBlockAttrs(node.attrs), ...headingFlowAttrs(node, "heading", headingFlow) },
|
|
464
|
+
node.type,
|
|
465
|
+
options,
|
|
466
|
+
),
|
|
397
467
|
renderNodes(node.content ?? [], options, "nested"),
|
|
398
468
|
);
|
|
399
469
|
}
|
|
400
470
|
|
|
401
|
-
function renderBlockquote(node: ProseMirrorNode, options:
|
|
471
|
+
function renderBlockquote(node: ProseMirrorNode, options: RenderOptionsWithLayout, headingFlow: boolean): string {
|
|
402
472
|
const metadata = readBlockquoteMetadata(node.attrs) ?? {};
|
|
403
473
|
const quote = renderElement(
|
|
404
474
|
"blockquote",
|
|
405
|
-
withProseMeasure(
|
|
475
|
+
withProseMeasure(
|
|
476
|
+
{
|
|
477
|
+
...(metadata.cite ? { cite: metadata.cite } : {}),
|
|
478
|
+
...headingNeighborAttrs("quote", headingFlow),
|
|
479
|
+
},
|
|
480
|
+
node.type,
|
|
481
|
+
options,
|
|
482
|
+
),
|
|
406
483
|
renderNodes(node.content ?? [], { ...options, freeFormSections: false }, "nested"),
|
|
407
484
|
);
|
|
408
485
|
const parts = blockquoteCaptionParts(metadata);
|
|
@@ -419,15 +496,15 @@ function renderBlockquote(node: ProseMirrorNode, options: RenderProseMirrorOptio
|
|
|
419
496
|
}, quote + renderElement("figcaption", {}, caption));
|
|
420
497
|
}
|
|
421
498
|
|
|
422
|
-
function renderCodeBlock(node: ProseMirrorNode, options: RenderProseMirrorOptions): string {
|
|
499
|
+
function renderCodeBlock(node: ProseMirrorNode, options: RenderProseMirrorOptions, headingFlow: boolean): string {
|
|
423
500
|
const language = stringAttr(node.attrs?.language);
|
|
424
501
|
const attrs = language ? { class: `language-${language}` } : {};
|
|
425
502
|
const text = (node.content ?? [])
|
|
426
503
|
.map((child) => child.text ?? "")
|
|
427
504
|
.join("");
|
|
428
|
-
return `<pre${
|
|
429
|
-
|
|
430
|
-
}</code></pre>`;
|
|
505
|
+
return `<pre${
|
|
506
|
+
serializeAttributes(withProseMeasure(headingNeighborAttrs("code", headingFlow), node.type, options))
|
|
507
|
+
}><code${serializeAttributes(attrs)}>${escapeHtml(text)}</code></pre>`;
|
|
431
508
|
}
|
|
432
509
|
|
|
433
510
|
type NormalizedTable = {
|
|
@@ -805,14 +882,8 @@ function renderSection(
|
|
|
805
882
|
"--esp-section-padding-block: 0",
|
|
806
883
|
);
|
|
807
884
|
} else {
|
|
808
|
-
//
|
|
809
|
-
|
|
810
|
-
// here, in the one place that renders it, so the published page, the editor's live preview and the
|
|
811
|
-
// CLI all get the same padding (TR01258: the page shell used to add it, and the preview has no shell).
|
|
812
|
-
sectionStyleParts.push(
|
|
813
|
-
"--esp-section-padding-inline: var(--esp-size-padding)",
|
|
814
|
-
"--esp-section-padding-block: var(--esp-size-padding)",
|
|
815
|
-
);
|
|
885
|
+
// The inset sits inside the well while the band retains its block padding (TR01395).
|
|
886
|
+
sectionStyleParts.push("--esp-section-padding-inline: 0", "--esp-section-padding-block: var(--esp-size-padding)");
|
|
816
887
|
}
|
|
817
888
|
|
|
818
889
|
// Espalier paints the decoration plane only on a section carrying the
|
|
@@ -833,9 +904,13 @@ function renderSection(
|
|
|
833
904
|
sectionStyleParts.push("--esp-section-background: transparent");
|
|
834
905
|
}
|
|
835
906
|
const sectionStyle = sectionStyleParts.length > 0 ? sectionStyleParts.join("; ") : undefined;
|
|
907
|
+
const inset = "var(--taproot-content-inset, var(--esp-size-small-to-normal))";
|
|
836
908
|
const content = renderElement(
|
|
837
909
|
"div",
|
|
838
|
-
{
|
|
910
|
+
{
|
|
911
|
+
"data-section-content": true,
|
|
912
|
+
style: contentPadding !== "none" && surface === "none" ? `padding-inline: ${inset}` : undefined,
|
|
913
|
+
},
|
|
839
914
|
renderNodes(nodes, { ...options, fullWidthImages: contentPadding === "none" }, contentPlacement),
|
|
840
915
|
);
|
|
841
916
|
const surfaced = surface === "none"
|
|
@@ -844,9 +919,12 @@ function renderSection(
|
|
|
844
919
|
"esp-box",
|
|
845
920
|
{
|
|
846
921
|
"data-surface": surface,
|
|
847
|
-
style:
|
|
848
|
-
?
|
|
849
|
-
|
|
922
|
+
style: [
|
|
923
|
+
contentPadding !== "none" ? `margin-inline: ${inset}` : undefined,
|
|
924
|
+
surface === "elevated"
|
|
925
|
+
? "--esp-color-box-background: var(--esp-color-layer-2); --esp-box-shadow: var(--esp-shadow-2)"
|
|
926
|
+
: undefined,
|
|
927
|
+
].filter(Boolean).join("; ") || undefined,
|
|
850
928
|
},
|
|
851
929
|
content,
|
|
852
930
|
);
|
|
@@ -1215,13 +1293,14 @@ function isBoundedNumber(value: unknown, minimum: number, maximum: number): valu
|
|
|
1215
1293
|
return typeof value === "number" && Number.isFinite(value) && value >= minimum && value <= maximum;
|
|
1216
1294
|
}
|
|
1217
1295
|
|
|
1218
|
-
function renderComponentBlock(node: ProseMirrorNode): string {
|
|
1296
|
+
function renderComponentBlock(node: ProseMirrorNode, headingFlow: boolean): string {
|
|
1219
1297
|
const componentType = stringAttr(node.attrs?.componentType) || "placeholder";
|
|
1220
1298
|
const componentData = stringAttr(node.attrs?.componentData) || "{}";
|
|
1221
1299
|
return renderElement(
|
|
1222
1300
|
"div",
|
|
1223
1301
|
{
|
|
1224
1302
|
"data-component-block": "",
|
|
1303
|
+
"data-heading-flow-component": headingFlow || undefined,
|
|
1225
1304
|
"data-component-type": componentType,
|
|
1226
1305
|
"data-component-data": componentData,
|
|
1227
1306
|
class: "component-block",
|
|
@@ -1324,16 +1403,18 @@ function resolvePlacement(
|
|
|
1324
1403
|
// choice. The node's own alignment attributes still win — mirroring the
|
|
1325
1404
|
// editor's node view — and the site default applies only when those are
|
|
1326
1405
|
// absent too.
|
|
1327
|
-
if (
|
|
1328
|
-
isAbsentPresentationValue(attrs.imageAlign)
|
|
1329
|
-
&& isAbsentPresentationValue(attrs.imagePlacement)
|
|
1330
|
-
&& isAbsentPresentationValue(attrs.textAlign)
|
|
1331
|
-
) {
|
|
1332
|
-
return normalizeImagePresentationPlacement(defaultValue);
|
|
1333
|
-
}
|
|
1406
|
+
if (inheritsImagePlacement(attrs)) return normalizeImagePresentationPlacement(defaultValue);
|
|
1334
1407
|
return imagePresentationPlacementForAttrs(attrs);
|
|
1335
1408
|
}
|
|
1336
1409
|
|
|
1410
|
+
function inheritsImagePlacement(attrs: Record<string, JsonValue | undefined>): boolean {
|
|
1411
|
+
const explicit = attrs.presentationPlacement;
|
|
1412
|
+
return (typeof explicit !== "string" || explicit === TIPTAP_SITE_DEFAULT)
|
|
1413
|
+
&& isAbsentPresentationValue(attrs.imageAlign)
|
|
1414
|
+
&& isAbsentPresentationValue(attrs.imagePlacement)
|
|
1415
|
+
&& isAbsentPresentationValue(attrs.textAlign);
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1337
1418
|
function isAbsentPresentationValue(value: unknown): boolean {
|
|
1338
1419
|
return value === undefined || value === null;
|
|
1339
1420
|
}
|
|
@@ -1551,7 +1632,8 @@ function renderLink(
|
|
|
1551
1632
|
): string {
|
|
1552
1633
|
const linkAttributes = linkRelAttributes(attrs, href, options.siteHosts);
|
|
1553
1634
|
const cue = options.siteHosts !== undefined && linkAttributes.target === "_blank" ? NEW_TAB_CUE_HTML : "";
|
|
1554
|
-
|
|
1635
|
+
const title = options.linkTitles ? stringAttr(attrs?.title) : undefined;
|
|
1636
|
+
return renderElement("a", { href, title, ...linkAttributes }, `${html}${cue}`);
|
|
1555
1637
|
}
|
|
1556
1638
|
|
|
1557
1639
|
function jsonAttr(value: unknown): string | null {
|
|
@@ -798,6 +798,8 @@ function checkMarkAttrs(mark, markPath, state) {
|
|
|
798
798
|
);
|
|
799
799
|
continue;
|
|
800
800
|
}
|
|
801
|
+
// The recipe step policy has already checked these values.
|
|
802
|
+
if (!state.checkLinkValues && mark.type === "link" && ["href", "target", "rel"].includes(key)) continue;
|
|
801
803
|
const detail = attrSpec.check(attrs[key]);
|
|
802
804
|
if (detail) {
|
|
803
805
|
report(
|
|
@@ -1100,10 +1102,11 @@ function validateNode(node, path, parentRule, index, state, depth) {
|
|
|
1100
1102
|
* component finding continues *through* the `componentData` JSON string into
|
|
1101
1103
|
* the parsed data). `code` is one of `CONTENT_ERROR_CODES`.
|
|
1102
1104
|
*/
|
|
1103
|
-
export function validateDocument(document) {
|
|
1105
|
+
export function validateDocument(document, { checkLinkValues = true } = {}) {
|
|
1104
1106
|
const state = {
|
|
1105
1107
|
errors: [],
|
|
1106
1108
|
truncated: false,
|
|
1109
|
+
checkLinkValues,
|
|
1107
1110
|
};
|
|
1108
1111
|
|
|
1109
1112
|
if (!isPlainObject(document) || document.type !== "doc") {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Generated from shared/content-inset.ts by scripts/sync-field-validation.mjs. Do not edit.
|
|
2
|
+
import { buildTaprootLightTheme, DEFAULT_LIGHT_THEME, mergeTheme, parseTheme } from "@taprootio/espalier/shared/theme";
|
|
3
|
+
import { computeThemeProperties } from "@taprootio/espalier/shared/theme-properties";
|
|
4
|
+
export const CONTENT_INSET_OPTIONS = ["small", "small-to-normal", "normal", "normal-to-medium", "medium"];
|
|
5
|
+
export const DEFAULT_CONTENT_INSET = CONTENT_INSET_OPTIONS[1];
|
|
6
|
+
export const CONTENT_WELL_MAX_REM = 72;
|
|
7
|
+
export function normalizeContentInset(value) {
|
|
8
|
+
return CONTENT_INSET_OPTIONS.find(option => option === value) ?? DEFAULT_CONTENT_INSET;
|
|
9
|
+
}
|
|
10
|
+
const builtInLight = mergeTheme(DEFAULT_LIGHT_THEME, parseTheme(buildTaprootLightTheme("")) ?? {});
|
|
11
|
+
const cachedScales = new Map();
|
|
12
|
+
function contentScales(lightTheme, viewportWidth) {
|
|
13
|
+
const key = `${viewportWidth ?? ""}\0${lightTheme}`;
|
|
14
|
+
const cached = cachedScales.get(key);
|
|
15
|
+
if (cached)
|
|
16
|
+
return cached;
|
|
17
|
+
const resolved = lightTheme ? mergeTheme(DEFAULT_LIGHT_THEME, parseTheme(lightTheme) ?? {}) : builtInLight;
|
|
18
|
+
const options = { viewportWidth };
|
|
19
|
+
const properties = computeThemeProperties(resolved, "light", options);
|
|
20
|
+
const effective = properties[`--esp-size-${DEFAULT_CONTENT_INSET}`]
|
|
21
|
+
? properties
|
|
22
|
+
: computeThemeProperties(builtInLight, "light", options);
|
|
23
|
+
const result = Object.fromEntries(CONTENT_INSET_OPTIONS.map(inset => [inset, effective[`--esp-size-${inset}`]]));
|
|
24
|
+
if (cachedScales.size === 12) {
|
|
25
|
+
const oldest = cachedScales.keys().next().value;
|
|
26
|
+
if (oldest !== undefined)
|
|
27
|
+
cachedScales.delete(oldest);
|
|
28
|
+
}
|
|
29
|
+
cachedScales.set(key, result);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
export function resolveContentInset(lightTheme, value, viewportWidth) {
|
|
33
|
+
return contentScales(lightTheme, viewportWidth)[normalizeContentInset(value)];
|
|
34
|
+
}
|
|
35
|
+
const number = "[+-]?(?:[0-9]+(?:\\.[0-9]+)?|\\.[0-9]+)";
|
|
36
|
+
const atFixedWidth = new RegExp(`^clamp\\((${number})rem,\\s*(${number})rem\\s*\\+\\s*(${number})px,\\s*(${number})rem\\)$`, "u");
|
|
37
|
+
const remLength = new RegExp(`^(${number})rem$`, "u");
|
|
38
|
+
export function contentInsetPixels(lightTheme, value, viewportWidth) {
|
|
39
|
+
const css = resolveContentInset(lightTheme, value, viewportWidth);
|
|
40
|
+
const fixed = remLength.exec(css);
|
|
41
|
+
if (fixed)
|
|
42
|
+
return 16 * Number(fixed[1]);
|
|
43
|
+
const clamp = atFixedWidth.exec(css);
|
|
44
|
+
if (!clamp)
|
|
45
|
+
throw new Error(`Unsupported Espalier inset length: ${css}`);
|
|
46
|
+
const [minimum, intercept, pixels, maximum] = clamp.slice(1).map(Number);
|
|
47
|
+
return Math.max(16 * minimum, Math.min(16 * maximum, 16 * intercept + pixels));
|
|
48
|
+
}
|
package/src/errors.js
CHANGED
|
@@ -193,6 +193,7 @@ export class SiteAuthoringError extends Error {
|
|
|
193
193
|
...(typeof problem.file === "string" ? { file: sanitizeDiagnostic(problem.file, "") } : {}),
|
|
194
194
|
code: /^[a-z0-9_.-]+$/u.test(problem.code) ? problem.code : "site.failed",
|
|
195
195
|
...(typeof problem.field === "string" ? { field: sanitizeDiagnostic(problem.field, "") } : {}),
|
|
196
|
+
...(Number.isSafeInteger(problem.line) && problem.line > 0 ? { line: problem.line } : {}),
|
|
196
197
|
...(typeof problem.rule === "string" && /^[a-z0-9_.]+$/u.test(problem.rule) ? { rule: problem.rule } : {}),
|
|
197
198
|
message: sanitizeDiagnostic(problem.message),
|
|
198
199
|
}));
|
package/src/espalier-shared.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
let tokenManifest;
|
|
4
|
+
let settableComponentProperties;
|
|
5
|
+
|
|
6
|
+
export function getEspalierTokenManifest() {
|
|
7
|
+
if (tokenManifest === undefined) {
|
|
8
|
+
const manifestUrl = new URL(import.meta.resolve("@taprootio/espalier/espalier.token-manifest.json"));
|
|
9
|
+
tokenManifest = JSON.parse(readFileSync(manifestUrl, "utf8"));
|
|
10
|
+
}
|
|
11
|
+
return tokenManifest;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getSettableComponentProperties() {
|
|
15
|
+
if (settableComponentProperties === undefined) {
|
|
16
|
+
settableComponentProperties = Object.freeze(getEspalierTokenManifest().tokens.filter((entry) => entry.settable === true));
|
|
17
|
+
}
|
|
18
|
+
return settableComponentProperties;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const BADGE_FOCUS_RING = "--esp-badge-link-focus-ring-color";
|
|
22
|
+
|
|
23
|
+
export function supportsBadgeFocusRing() {
|
|
24
|
+
return getSettableComponentProperties().some(({ name }) => name === BADGE_FOCUS_RING);
|
|
25
|
+
}
|
|
26
|
+
|
|
1
27
|
/**
|
|
2
28
|
* An Espalier module that sits beside the exported theme module but is not
|
|
3
29
|
* exported itself (the fit report, the color engine). Its package root
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function fieldEditDistance(field, candidate) {
|
|
2
|
+
let beforePrevious = [];
|
|
3
|
+
let previous = Array.from({ length: candidate.length + 1 }, (_, index) => index);
|
|
4
|
+
for (let i = 1; i <= field.length; i += 1) {
|
|
5
|
+
const current = [i];
|
|
6
|
+
for (let j = 1; j <= candidate.length; j += 1) {
|
|
7
|
+
current[j] = Math.min(
|
|
8
|
+
previous[j] + 1,
|
|
9
|
+
current[j - 1] + 1,
|
|
10
|
+
previous[j - 1] + Number(field[i - 1] !== candidate[j - 1]),
|
|
11
|
+
);
|
|
12
|
+
if (i > 1 && j > 1 && field[i - 1] === candidate[j - 2] && field[i - 2] === candidate[j - 1]) {
|
|
13
|
+
current[j] = Math.min(current[j], beforePrevious[j - 2] + 1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
beforePrevious = previous;
|
|
17
|
+
previous = current;
|
|
18
|
+
}
|
|
19
|
+
return previous[candidate.length];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function closeFieldMatch(key, names) {
|
|
23
|
+
let nearest;
|
|
24
|
+
let bestDistance = key.length < 8 ? 2 : 3;
|
|
25
|
+
for (const name of names) {
|
|
26
|
+
if (Math.abs(key.length - name.length) > bestDistance) continue;
|
|
27
|
+
const distance = fieldEditDistance(key, name);
|
|
28
|
+
if (distance === bestDistance) nearest = undefined;
|
|
29
|
+
if (distance >= bestDistance) continue;
|
|
30
|
+
nearest = name;
|
|
31
|
+
bestDistance = distance;
|
|
32
|
+
}
|
|
33
|
+
return nearest;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function unknownFieldHint(nearest, helpTopic = "theme") {
|
|
37
|
+
return nearest === undefined
|
|
38
|
+
? ` See 'taproot-site help ${helpTopic}' for the supported fields.`
|
|
39
|
+
: ` Did you mean '${nearest}'?`;
|
|
40
|
+
}
|
package/src/fixture-init.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { lstat, mkdir, realpath, rm } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
+
import { authoredTagSlug } from "./authored-tag-names.js";
|
|
5
6
|
import { loadSiteConfig } from "./config.js";
|
|
6
7
|
import { isCanonicalUuid, SiteAuthoringError } from "./errors.js";
|
|
7
8
|
import { FIXTURE_CONTRACT_VERSION, FIXTURE_MANIFEST_FILE_NAME } from "./fixture-contract.js";
|
|
@@ -9,6 +10,7 @@ import { appearanceManifestEntry, footerManifestEntry } from "./footer-workspace
|
|
|
9
10
|
import { formFileName } from "./forms-contract.js";
|
|
10
11
|
import { formsManifestEntry, readWorkspaceForms } from "./forms-workspace.js";
|
|
11
12
|
import { SETTINGS_GROUPS, SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES } from "./settings-catalog.js";
|
|
13
|
+
import { tagDestinationEntries } from "./tag-destination-warnings.js";
|
|
12
14
|
import { validateWorkspacePageSource } from "./verbs/pages-push.js";
|
|
13
15
|
import { validateThemeWorkspace } from "./verbs/theme-push.js";
|
|
14
16
|
import {
|
|
@@ -182,6 +184,8 @@ export async function initializeFixture(invocation, validate) {
|
|
|
182
184
|
new Set(
|
|
183
185
|
[...identities].filter(([, mapped]) => imageIds.has(mapped)).map(([original]) => original),
|
|
184
186
|
),
|
|
187
|
+
undefined,
|
|
188
|
+
{ fixtureExport: true },
|
|
185
189
|
);
|
|
186
190
|
for (
|
|
187
191
|
const [file, limit] of [["nav.json", WORKSPACE_LIMITS.navigationBytes], [
|
|
@@ -200,11 +204,11 @@ export async function initializeFixture(invocation, validate) {
|
|
|
200
204
|
),
|
|
201
205
|
);
|
|
202
206
|
}
|
|
203
|
-
// Navigation and
|
|
204
|
-
//
|
|
205
|
-
// so the fixture validates as the site does (TR01198).
|
|
207
|
+
// Navigation, footer and badges can link a page whose source the fixture
|
|
208
|
+
// does not have. Keep its remapped metadata so the links still resolve.
|
|
206
209
|
const editablePageCount = pages.length;
|
|
207
|
-
const
|
|
210
|
+
const publishing = appearanceDocuments[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES];
|
|
211
|
+
const linkedResourceIds = new Set(tagDestinationEntries(publishing).map(({ resourceId }) => resourceId));
|
|
208
212
|
(function collect(value) {
|
|
209
213
|
if (Array.isArray(value)) value.forEach(collect);
|
|
210
214
|
else if (value && typeof value === "object") {
|
|
@@ -238,6 +242,19 @@ export async function initializeFixture(invocation, validate) {
|
|
|
238
242
|
workspaceMode: PAGE_WORKSPACE_MODE_METADATA_ONLY,
|
|
239
243
|
}));
|
|
240
244
|
}
|
|
245
|
+
const exportedPageIds = new Set(pages.map(page => page.resourceId));
|
|
246
|
+
let omittedDestinations = 0;
|
|
247
|
+
for (const { setting, name, resourceId } of tagDestinationEntries(publishing)) {
|
|
248
|
+
if (exportedPageIds.has(resourceId)) continue;
|
|
249
|
+
const saved = source.presentation?.[setting]?.[authoredTagSlug(name)];
|
|
250
|
+
if (isCanonicalUuid(saved) && identity(saved) === resourceId) {
|
|
251
|
+
delete publishing[setting][name];
|
|
252
|
+
omittedDestinations += 1;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (omittedDestinations > 0) {
|
|
256
|
+
invocation.onProgress?.(`Fixture export omitted ${omittedDestinations} saved badge destination(s) whose pages are absent.`);
|
|
257
|
+
}
|
|
241
258
|
const redirects = documents.get("redirects.json");
|
|
242
259
|
// A fixture hash is a local placeholder, not authority to mutate the original site.
|
|
243
260
|
const revision = createHash("sha256").update(JSON.stringify(redirects.entries)).digest("hex");
|
|
@@ -254,7 +271,7 @@ export async function initializeFixture(invocation, validate) {
|
|
|
254
271
|
id: identity(source.forms.items[form.key].id),
|
|
255
272
|
version: source.forms.items[form.key].version,
|
|
256
273
|
}]));
|
|
257
|
-
const footer = footerManifestEntry(
|
|
274
|
+
const footer = footerManifestEntry(publishing.footerSettings);
|
|
258
275
|
const appearance = appearanceManifestEntry(appearanceDocuments);
|
|
259
276
|
for (const id of [...footer.imageIds, ...appearance.imageIds]) imageIds.add(id);
|
|
260
277
|
add(FIXTURE_MANIFEST_FILE_NAME, {
|
package/src/font-catalog.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import definitions from "@taprootio/espalier/css/fonts/font-definitions.json" with { type: "json" };
|
|
2
2
|
|
|
3
3
|
import { CLI_BINARY_NAME } from "./constants.js";
|
|
4
|
+
import { formatFixedValues } from "./styling-fixed-values.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* `help fonts` (TR01188): the font families a published site can load, read
|
|
@@ -42,6 +43,14 @@ const DETAILS = Object.freeze([
|
|
|
42
43
|
+ "cannot be used.",
|
|
43
44
|
]);
|
|
44
45
|
|
|
46
|
+
const FIXED_VALUES = Object.freeze([Object.freeze({
|
|
47
|
+
name: "fonts.requestedAxes",
|
|
48
|
+
value: "ital,wght@0,<weight>",
|
|
49
|
+
where: "Publish requests only ital (at 0, the upright face) and wght (at the font field's configured weight). "
|
|
50
|
+
+ "Publish never requests opsz, SOFT or WONK.",
|
|
51
|
+
source: "Taproot publish font requests",
|
|
52
|
+
})]);
|
|
53
|
+
|
|
45
54
|
/** The catalog's categories, or one category's families. */
|
|
46
55
|
export function getFontCatalogReference(category) {
|
|
47
56
|
const base = {
|
|
@@ -49,6 +58,7 @@ export function getFontCatalogReference(category) {
|
|
|
49
58
|
summary: "The font families a published site can load, by category, with the weights each offers.",
|
|
50
59
|
usage: `${CLI_BINARY_NAME} help fonts [category] [--json]`,
|
|
51
60
|
details: DETAILS,
|
|
61
|
+
fixedValues: FIXED_VALUES,
|
|
52
62
|
};
|
|
53
63
|
if (category === undefined) {
|
|
54
64
|
return Object.freeze({
|
|
@@ -70,7 +80,7 @@ export function getFontCatalogReference(category) {
|
|
|
70
80
|
export function formatFontCatalog(reference) {
|
|
71
81
|
const header = `${reference.title}\n${reference.summary}\n\nUsage: ${reference.usage}\n\n${
|
|
72
82
|
reference.details.map((detail) => `- ${detail}`).join("\n")
|
|
73
|
-
}\n
|
|
83
|
+
}${formatFixedValues(reference.fixedValues)}\n`;
|
|
74
84
|
if (reference.families === undefined) {
|
|
75
85
|
return `${header}${reference.familyCount} families:\n${
|
|
76
86
|
reference.categories.map((entry) =>
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { encodeTheme } from "@taprootio/espalier/shared/theme";
|
|
2
|
+
|
|
1
3
|
import { APPEARANCE_FILES } from "./appearance-contract.js";
|
|
4
|
+
import { normalizeContentInset } from "./content-inset.js";
|
|
2
5
|
import { resolveFooterLogoPairs } from "./footer-branding.js";
|
|
3
|
-
import { footerLogoAspectRatio } from "./footer-fit.js";
|
|
6
|
+
import { buildFooterFitInput, footerLogoAspectRatio } from "./footer-fit.js";
|
|
4
7
|
import { logoInputsFromSettings } from "./logo-inputs.js";
|
|
5
8
|
import { SETTINGS_TYPE_SITE_HEADER, SETTINGS_TYPE_TAPROOT_STYLES } from "./settings-catalog.js";
|
|
6
9
|
import { MEDIA_MANIFEST_FILE_NAME, readWorkspaceJson, WORKSPACE_LIMITS } from "./workspace.js";
|
|
@@ -16,11 +19,31 @@ async function optionalSettings(workspaceDir, settingsType) {
|
|
|
16
19
|
|
|
17
20
|
/** Optional files are independent: losing the header must not discard a known logo, or the reverse. */
|
|
18
21
|
export async function readFooterBrandInputs(workspaceDir, footerSettings) {
|
|
19
|
-
const [header, styles, media] = await
|
|
22
|
+
const [header, styles, media] = await readFooterAppearance(workspaceDir);
|
|
23
|
+
return footerBrandInputsFromSettings(header, styles, media, footerSettings);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function readFooterFitInput(workspaceDir, footerSettings) {
|
|
27
|
+
const [header, styles, media] = await readFooterAppearance(workspaceDir);
|
|
28
|
+
return footerFitInputFromSettings(header, styles, media, footerSettings);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function readFooterAppearance(workspaceDir) {
|
|
32
|
+
return Promise.all([
|
|
20
33
|
optionalSettings(workspaceDir, SETTINGS_TYPE_SITE_HEADER),
|
|
21
34
|
optionalSettings(workspaceDir, SETTINGS_TYPE_TAPROOT_STYLES),
|
|
22
35
|
readWorkspaceJson(workspaceDir, MEDIA_MANIFEST_FILE_NAME, WORKSPACE_LIMITS.manifestBytes).then(value => value?.media ?? {}).catch(() => ({})),
|
|
23
36
|
]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function footerFitInputFromSettings(header, styles, media, footerSettings) {
|
|
40
|
+
const light = styles?.lightTheme;
|
|
41
|
+
const lightTheme = light && typeof light === "object" ? encodeTheme(light) : "";
|
|
42
|
+
return buildFooterFitInput(footerSettings, footerBrandInputsFromSettings(header, styles, media, footerSettings),
|
|
43
|
+
undefined, { contentInset: normalizeContentInset(styles?.contentInset), lightTheme });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function footerBrandInputsFromSettings(header, styles, media, footerSettings) {
|
|
24
47
|
const pair = resolveFooterLogoPairs({ ...logoInputsFromSettings(styles, footerSettings, media), logoVariant: footerSettings?.logoVariant });
|
|
25
48
|
const visible = [pair.light, pair.dark].filter(value => value.url !== "");
|
|
26
49
|
const ratios = visible.map(value => Number(value.aspectRatio));
|