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