@taprootio/site-authoring 0.61.0 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +97 -23
  2. package/package.json +2 -2
  3. package/src/api.js +149 -21
  4. package/src/appearance-contract.js +27 -0
  5. package/src/article-appearance.js +19 -0
  6. package/src/article-appearance.json +9 -0
  7. package/src/article-end-settings.js +295 -0
  8. package/src/changelog.json +49 -0
  9. package/src/chrome-input.js +1 -1
  10. package/src/cli.js +110 -26
  11. package/src/constants.js +7 -0
  12. package/src/content/components.js +130 -14
  13. package/src/content/cta-decoration-paint.js +321 -0
  14. package/src/content/form-placement-presentation.js +91 -0
  15. package/src/content/form-placement-presentation.json +6 -0
  16. package/src/content/free-form-section-registry.json +19 -1
  17. package/src/content/free-form-sections.js +64 -55
  18. package/src/content/markdown.js +13 -0
  19. package/src/content/tiptap-prosemirror.ts +72 -59
  20. package/src/content/validate-document.js +2 -0
  21. package/src/cta-artwork-warnings.js +164 -0
  22. package/src/errors.js +6 -0
  23. package/src/field-schema.json +6 -2
  24. package/src/field-validation.js +14 -5
  25. package/src/footer-workspace.js +7 -3
  26. package/src/form-references.js +71 -9
  27. package/src/forms-contract.js +3 -5
  28. package/src/heading-outline.js +7 -0
  29. package/src/output.js +2 -0
  30. package/src/page-article-end.js +66 -0
  31. package/src/page-block-catalog.js +54 -0
  32. package/src/page-form-presentation.js +104 -0
  33. package/src/page-structure-checks.js +7 -1
  34. package/src/placed-image-ids.js +15 -18
  35. package/src/presentation-reference.js +31 -53
  36. package/src/reference-help.js +97 -27
  37. package/src/reusable-blocks.js +429 -0
  38. package/src/reusable-placements.js +271 -0
  39. package/src/setting-reference.js +57 -1
  40. package/src/settings-catalog.js +3 -0
  41. package/src/site-check-findings.js +30 -2
  42. package/src/site-check-rules.json +1 -0
  43. package/src/site-checks.js +26 -2
  44. package/src/site-health-findings.js +25 -3
  45. package/src/site-health-image-checks.js +1 -1
  46. package/src/staging-check.js +108 -21
  47. package/src/staging-served.js +5 -49
  48. package/src/status-warning-paints.js +17 -0
  49. package/src/template-token-reach.json +20 -2
  50. package/src/theme-resolve.js +27 -0
  51. package/src/transport.js +41 -5
  52. package/src/typed-page-reference.js +55 -5
  53. package/src/typed-pages.js +27 -4
  54. package/src/verbs/approve.js +2 -1
  55. package/src/verbs/deploy.js +93 -15
  56. package/src/verbs/footer-push.js +4 -2
  57. package/src/verbs/forms-push.js +9 -0
  58. package/src/verbs/health.js +11 -6
  59. package/src/verbs/index.js +3 -0
  60. package/src/verbs/pages-blocks-pull.js +22 -0
  61. package/src/verbs/pages-push.js +89 -34
  62. package/src/verbs/plan.js +34 -5
  63. package/src/verbs/pull.js +213 -124
  64. package/src/verbs/status.js +20 -2
  65. package/src/verbs/theme-push.js +170 -20
  66. package/src/verbs/theme-resolve.js +114 -40
  67. package/src/verbs/validate.js +49 -18
  68. package/src/workspace-check.js +42 -5
  69. package/src/workspace-context-usage.js +54 -1
  70. package/src/workspace.js +37 -7
  71. package/test/fixtures/default-site-theme.json +1 -1
@@ -6,10 +6,12 @@
6
6
  import { BUILT_IN_IMAGE_TEXTURES } from "@taprootio/espalier/shared/image-texture-registry";
7
7
  import registry from "./free-form-section-registry.json" with { type: "json" };
8
8
  import { hasAsciiControl } from "../errors.js";
9
+ import { isFormKey } from "../forms-contract.js";
9
10
  import { validateAuthoredTagNames } from "../authored-tag-names.js";
10
11
  import { isSocialLinkUrl, SOCIAL_LINK_URL_MAX_LENGTH, trimSocialLinkInput } from "../social-link-url.js";
11
12
  import socialPlatforms from "../social-platforms.json" with { type: "json" };
12
13
  import { IMAGE_DESCRIPTION_MODES } from "./image-description-validation.js";
14
+ import { FORM_PLACEMENT_TEXT_LIMITS, formPlacementPresentationIssues, readFormPlacementPresentation } from "./form-placement-presentation.js";
13
15
  import { stripImageDescriptionHydration } from "./image-description-document.js";
14
16
  import {
15
17
  CONTENT_ERROR_CODES as CODES,
@@ -28,6 +30,13 @@ import {
28
30
  HERO_SECONDARY_ACTION_STYLE_DEFAULT,
29
31
  } from "./button-styles.js";
30
32
  import { normalizeCssLengthOverride } from "./media-presentation.js";
33
+ import {
34
+ CTA_ART_COMPACT_MAX,
35
+ CTA_ART_GUIDANCE,
36
+ CTA_ART_OPACITY,
37
+ CTA_DECORATION_FIELDS,
38
+ normalizeCtaDecoration,
39
+ } from "./cta-decoration-paint.js";
31
40
  import { isVideoEmbedId, parseVideoEmbedUrl, VIDEO_EMBED_REFUSAL } from "./video-embed-url.js";
32
41
  import {
33
42
  REVIEW_ID_PATTERN,
@@ -43,10 +52,8 @@ import {
43
52
  * pre-adoption replacement owned here and by the published renderer.
44
53
  *
45
54
  * `componentBlock.attrs.componentData` is a JSON **string**, not an object.
46
- * Nothing on the server looks inside it: the renderer copies it verbatim into a
47
- * `data-component-data` attribute and the generator's component renderer reads
48
- * whatever fields it finds, defaulting anything missing and ignoring anything
49
- * unknown. A typo'd enum value therefore publishes as a component silently
55
+ * The generator's component renderer reads the known fields and applies the
56
+ * component defaults to omitted values. A typo'd enum value therefore publishes as a component silently
50
57
  * rendered with the wrong layout, and a typo'd field name publishes as a
51
58
  * component silently rendered with none of the author's content — which is why
52
59
  * these tables exist and why unknown fields are refused.
@@ -216,13 +223,29 @@ const HERO_SECTION = Object.freeze({
216
223
  * silently rewriting a value the author never touched; the fix is to set a
217
224
  * current value, which is also what the editor does on its next save.
218
225
  */
226
+ const CTA_ART_FIELDS = Object.freeze(Object.fromEntries(Object.entries(CTA_DECORATION_FIELDS).map(([name, field]) => {
227
+ if (field.type === "processed-image") {
228
+ return [name, image({ required: field.required, nonNullable: true, decorationImage: field })];
229
+ }
230
+ let spec = field.type === "enum" ? enumOf(...field.values)
231
+ : field.type === "boolean" ? bool()
232
+ : num({ minimum: field.minimum, maximum: field.maximum, integer: field.type === "integer" });
233
+ if (name === "opacity") {
234
+ spec = described(spec, `Defaults to ${CTA_ART_OPACITY.mask} for mask and ${CTA_ART_OPACITY.original} for original colors.`);
235
+ }
236
+ if (name === "hideAtCompact") {
237
+ spec = described(spec, `Hide the art and its scrim when the panel is at most ${CTA_ART_COMPACT_MAX} wide.`);
238
+ }
239
+ return [name, field.default === undefined ? spec : withOmission(spec, { kind: "value", value: field.default })];
240
+ })));
241
+
219
242
  const CTA = Object.freeze({
220
243
  context: str({
221
244
  maximumLength: registry.section.attrs.context.maximumLength,
222
245
  pattern: new RegExp(registry.section.attrs.context.pattern, "u"),
223
246
  patternDescription: "a theme context name: a letter, then letters, digits, hyphens or underscores, at most 64 characters",
224
247
  description:
225
- "A theme context declared by both the light and dark themes. It gives the panel that context's background and border, with its text and button colors; run 'theme resolve' to see the context's colors. Omit it to leave the panel unfilled.",
248
+ "A theme context declared by both the light and dark themes. It gives the panel that context's background and border, with its text and button colors. Run 'theme resolve' to see those colors. Without a context the panel uses the surrounding colors, filling its background when it has artwork.",
226
249
  }),
227
250
  heading: str(),
228
251
  description: str(),
@@ -238,6 +261,16 @@ const CTA = Object.freeze({
238
261
  imagePosition: enumOf("top", "left", "right"),
239
262
  mediaImage: image(),
240
263
  mediaBorderWidth: borderLength({ description: MEDIA_BORDER_HELP }),
264
+ decoration: Object.freeze({
265
+ kind: "cta-decoration",
266
+ fields: CTA_ART_FIELDS,
267
+ description: CTA_ART_GUIDANCE
268
+ + " Use owned Markdown media paths for image and darkImage. Omit darkImage to use image in both schemes."
269
+ + " Original keeps the artwork colors, and mask colors the silhouette with tint. Use repeat without a size for a natural-size tile."
270
+ + ` Otherwise set either inlineSizePercent or blockSizePercent. Set hideAtCompact to true to hide artwork at ${CTA_ART_COMPACT_MAX} or less.`
271
+ + " Set scrimEnabled false to show the artwork at its configured opacity or true to mute the full panel."
272
+ + ` Without scrimEnabled, legacy artScrim 0 is off and values above 0 keep their assigned strength. Explicit true uses ${CTA_DECORATION_FIELDS.artScrim.default} when artScrim is missing or zero.`,
273
+ }),
241
274
  });
242
275
 
243
276
  /** `FeatureGridData`. */
@@ -533,9 +566,19 @@ const SPACER = Object.freeze({
533
566
  * two (TR01216). The key is checked against the site's forms when the page is
534
567
  * pushed, not here: this table only knows the shape.
535
568
  */
569
+ const optionalFormText = (max) => str({ nullable: true, description: `Optional plain text limited to ${max} Unicode characters.` });
536
570
  const FORM = Object.freeze({
537
571
  // Required: a placement with no form chosen can never publish, so it is refused here, not at deploy.
538
572
  formKey: str({ required: true, nonWhitespace: true }),
573
+ layout: enumOf("compact"),
574
+ heading: optionalFormText(FORM_PLACEMENT_TEXT_LIMITS.headingMaxScalars),
575
+ introduction: optionalFormText(FORM_PLACEMENT_TEXT_LIMITS.introductionMaxScalars),
576
+ context: str({ nullable: true, description: "A name declared by both site themes. Omit it to inherit the surrounding context." }),
577
+ finePrint: shape({
578
+ text: optionalFormText(FORM_PLACEMENT_TEXT_LIMITS.finePrintTextMaxScalars),
579
+ linkLabel: optionalFormText(FORM_PLACEMENT_TEXT_LIMITS.finePrintLinkLabelMaxScalars),
580
+ linkUrl: str({ nullable: true, description: "An HTTPS URL or root-relative site path. Supply linkLabel with it." }),
581
+ }, { nullable: true }),
539
582
  });
540
583
 
541
584
  /**
@@ -739,7 +782,7 @@ const COMPONENT_DEFINITIONS = Object.freeze({
739
782
  "cta": component(
740
783
  CTA,
741
784
  "Call to Action",
742
- "Focused prompt with supporting copy, a button, and optional media.",
785
+ "Focused prompt with supporting copy, a button, and optional media and panel artwork.",
743
786
  {
744
787
  heading: "",
745
788
  description: "",
@@ -753,6 +796,7 @@ const COMPONENT_DEFINITIONS = Object.freeze({
753
796
  [
754
797
  "Button text must describe its action or destination.",
755
798
  "Give meaningful media a descriptive alt value and decorative media an empty alt value.",
799
+ CTA_ART_GUIDANCE,
756
800
  ],
757
801
  {
758
802
  heading: "Ready to begin?",
@@ -760,6 +804,17 @@ const COMPONENT_DEFINITIONS = Object.freeze({
760
804
  buttonText: "Reserve a class",
761
805
  buttonUrl: "/classes/intro",
762
806
  variant: "primary",
807
+ decoration: {
808
+ image: {
809
+ imageId: "80380269-2d94-4d2a-aabc-e21e18b9beb0",
810
+ src: "https://static.example.test/rocket.webp",
811
+ urls: [{ minWidth: 640, url: "https://static.example.test/rocket.webp" }],
812
+ },
813
+ paint: "original",
814
+ anchor: "bottom-end",
815
+ inlineSizePercent: 42,
816
+ hideAtCompact: true,
817
+ },
763
818
  },
764
819
  ),
765
820
  "testimonial": component(
@@ -995,9 +1050,12 @@ const COMPONENT_DEFINITIONS = Object.freeze({
995
1050
  [
996
1051
  "Set formKey to the key of an existing form ('forms push' creates it); 'pages push' refuses an unknown or archived key, and the site stores the form's id, not the key.",
997
1052
  "The button text and what happens after a response is sent belong to the form, not the page: set submit_label and after_submit in the form's file (see 'help forms').",
1053
+ "Use layout: compact inside an article for a required contact email and one consent checkbox, with no other fields. Omit layout for the standard arrangement. If the selected form version no longer fits, it uses the standard layout.",
998
1054
  "The form's field labels are its accessible names; write each so it makes sense out of context.",
1055
+ "Use heading and introduction for text above the form, and finePrint below Submit. Fine print can contain text, linkLabel with linkUrl, or both. Choose context from both site themes.",
1056
+ "To reuse the presentation, edit it in settings/reusable-blocks.json and place only reusableKey on each page. Pull an existing page before adding, editing or removing its inline form presentation.",
999
1057
  ],
1000
- { formKey: "contact" },
1058
+ { formKey: "newsletter", layout: "compact" },
1001
1059
  ),
1002
1060
  "video": component(
1003
1061
  VIDEO,
@@ -1178,7 +1236,9 @@ function mapImageFields(fields, value, path, mapImage) {
1178
1236
 
1179
1237
  function mapImageValue(spec, value, path, mapImage) {
1180
1238
  if (spec.kind === "image") return mapImage(value, path);
1181
- if (spec.kind === "object" && isPlainObject(value)) return mapImageFields(spec.fields, value, path, mapImage);
1239
+ if ((spec.kind === "object" || spec.kind === "cta-decoration") && isPlainObject(value)) {
1240
+ return mapImageFields(spec.fields, value, path, mapImage);
1241
+ }
1182
1242
  if (spec.kind === "array" && Array.isArray(value)) {
1183
1243
  return value.map((item, index) => mapImageValue(spec.item, item, `${path}/${index}`, mapImage));
1184
1244
  }
@@ -1236,7 +1296,7 @@ function referenceSchema(spec) {
1236
1296
  "Names outside the built-in list render with no texture until the application registers them with Espalier.",
1237
1297
  };
1238
1298
  case "boolean":
1239
- return { type: "boolean" };
1299
+ return { type: "boolean", ...(spec.description ? { description: spec.description } : {}) };
1240
1300
  case "uuid":
1241
1301
  return { type: "string", format: "lowercase-uuid" };
1242
1302
  case "enum":
@@ -1268,6 +1328,13 @@ function referenceSchema(spec) {
1268
1328
  maxItems: spec.maxItems ?? MAX_ITEMS,
1269
1329
  items: referenceSchema(spec.item),
1270
1330
  };
1331
+ case "cta-decoration":
1332
+ return {
1333
+ type: "object",
1334
+ additionalProperties: false,
1335
+ description: spec.description,
1336
+ properties: referenceProperties(spec.fields, {}),
1337
+ };
1271
1338
  case "object":
1272
1339
  return {
1273
1340
  type: spec.nullable ? ["object", "null"] : "object",
@@ -1277,16 +1344,23 @@ function referenceSchema(spec) {
1277
1344
  };
1278
1345
  case "image":
1279
1346
  return {
1280
- type: spec.required ? "object" : ["object", "null"],
1347
+ type: spec.required || spec.nonNullable ? "object" : ["object", "null"],
1281
1348
  // What a Markdown component fence takes instead (TR01187).
1282
- markdownType: spec.required ? "string" : ["string", "null"],
1349
+ markdownType: spec.required || spec.nonNullable ? "string" : ["string", "null"],
1283
1350
  description: `In Markdown, a media path recorded by media upload (such as "media/photo.webp")${
1284
- spec.required ? "" : ", or null"
1351
+ spec.required || spec.nonNullable ? "" : ", or null"
1285
1352
  }; pages push stores the image record. A .pm.json document carries that record: keep imageId, src, and urls keys so the server can rewrite delivery URLs.${
1286
1353
  spec.altRequired ? " Alt text is required unless descriptionMode is inherit; inherited text must resolve before deployment." : ""
1287
1354
  }${spec.dimensionsRequired ? " Width and height are required." : ""}`,
1288
1355
  additionalProperties: false,
1289
- properties: referenceProperties(imageFieldsFor(spec)),
1356
+ properties: referenceProperties(spec.decorationImage ? {
1357
+ ...COMPONENT_IMAGE_FIELDS,
1358
+ urls: list(shape({ minWidth: num({ integer: true, minimum: 1 }), url: str(), type: enumOf("image/webp") }), {
1359
+ required: true, minItems: spec.decorationImage.urls.minItems, maxItems: spec.decorationImage.urls.maxItems,
1360
+ }),
1361
+ width: num({ integer: true, minimum: 1 }),
1362
+ height: num({ integer: true, minimum: 1 }),
1363
+ } : imageFieldsFor(spec)),
1290
1364
  };
1291
1365
  default:
1292
1366
  throw new TypeError(`Unknown component schema kind '${spec.kind}'.`);
@@ -1478,6 +1552,16 @@ function validateValue(spec, value, path, errors) {
1478
1552
  validateFields(spec.fields, value, path, errors);
1479
1553
  return;
1480
1554
  }
1555
+ case "cta-decoration": {
1556
+ for (const issue of normalizeCtaDecoration(value, path).issues) {
1557
+ errors.push(contentError(
1558
+ issue.path,
1559
+ issue.kind === "imageKeys" ? CODES.imageKeys : CODES.componentData,
1560
+ `CTA artwork at '${issue.path}' must ${issue.expected}.`,
1561
+ ));
1562
+ }
1563
+ return;
1564
+ }
1481
1565
  case "image": {
1482
1566
  // `ComponentImageData | null` — null is the documented "no image" value
1483
1567
  // unless the component's images are its content.
@@ -1590,6 +1674,17 @@ function validateCardImageFit(parsed, dataPath, errors) {
1590
1674
  }
1591
1675
  }
1592
1676
 
1677
+ /** A page reference can carry its key in a JSON string or a structured ProseMirror value. */
1678
+ export function reusablePlacementKey(componentType, value) {
1679
+ if (componentType !== "cta" && componentType !== "form") return undefined;
1680
+ let data = value;
1681
+ if (typeof value === "string") {
1682
+ try { data = JSON.parse(value); } catch { return undefined; }
1683
+ }
1684
+ return isPlainObject(data) && Object.hasOwn(data, "reusableKey") && Object.keys(data).length === 1 && isFormKey(data.reusableKey)
1685
+ ? data.reusableKey : undefined;
1686
+ }
1687
+
1593
1688
  /**
1594
1689
  * Validates a `componentBlock`'s `componentType` and `componentData` pair.
1595
1690
  *
@@ -1608,6 +1703,7 @@ export function validateComponentBlock(componentType, componentData, basePath) {
1608
1703
  ));
1609
1704
  }
1610
1705
  if (typeof componentData !== "string") {
1706
+ if (reusablePlacementKey(componentType, componentData) !== undefined) return errors;
1611
1707
  errors.push(contentError(
1612
1708
  dataPath,
1613
1709
  CODES.componentData,
@@ -1640,7 +1736,19 @@ export function validateComponentBlock(componentType, componentData, basePath) {
1640
1736
  // `toString` this module does not control.
1641
1737
  const fields = isComponentType(componentType) ? COMPONENT_SHAPES[componentType] : undefined;
1642
1738
  if (!fields) return errors;
1739
+ if (Object.hasOwn(parsed, "reusableKey")) {
1740
+ if (reusablePlacementKey(componentType, parsed) === undefined) {
1741
+ errors.push(contentError(`${dataPath}/reusableKey`, CODES.componentData,
1742
+ "Use a reusable key defined under Footer settings as the only field of a CTA or Form reference."));
1743
+ }
1744
+ return errors;
1745
+ }
1643
1746
  validateFields(fields, parsed, dataPath, errors);
1747
+ if (componentType === "form" && errors.length === 0) {
1748
+ for (const issue of formPlacementPresentationIssues(parsed)) {
1749
+ errors.push(contentError(`${dataPath}/${issue.field.replaceAll(".", "/")}`, CODES.componentData, issue.message));
1750
+ }
1751
+ }
1644
1752
  if (componentType === "card-grid") validateCardImageFit(parsed, dataPath, errors);
1645
1753
  if (componentType === "card-grid" && Array.isArray(parsed.cards)) {
1646
1754
  for (const [index, card] of parsed.cards.entries()) {
@@ -1757,7 +1865,11 @@ export function canonicalizeComponentData(componentType, data) {
1757
1865
  const fields = isComponentType(componentType) ? COMPONENT_SHAPES[componentType] : undefined;
1758
1866
  if (!fields) throw new TypeError("canonicalizeComponentData requires a known component type.");
1759
1867
  if (!isPlainObject(data)) throw new TypeError("canonicalizeComponentData requires an object.");
1760
- const authored = stripImageDescriptionHydration(data);
1868
+ const reusableKey = reusablePlacementKey(componentType, data);
1869
+ if (reusableKey !== undefined) return JSON.stringify({ reusableKey });
1870
+ const authored = componentType === "form"
1871
+ ? { formKey: data.formKey, ...(data.layout === undefined ? {} : { layout: data.layout }), ...readFormPlacementPresentation(data) }
1872
+ : stripImageDescriptionHydration(data);
1761
1873
  const ordered = {};
1762
1874
  for (const key of Object.keys(fields)) {
1763
1875
  if (Object.hasOwn(authored, key)) ordered[key] = orderValue(fields[key], authored[key]);
@@ -1769,6 +1881,10 @@ export function canonicalizeComponentData(componentType, data) {
1769
1881
  }
1770
1882
 
1771
1883
  function orderValue(spec, value) {
1884
+ if (spec.kind === "cta-decoration" && isPlainObject(value)) {
1885
+ return Object.fromEntries(Object.keys(spec.fields).filter((key) => Object.hasOwn(value, key))
1886
+ .map((key) => [key, value[key]]));
1887
+ }
1772
1888
  if (spec.kind === "array" && Array.isArray(value)) {
1773
1889
  return value.map((entry) => orderValue(spec.item, entry));
1774
1890
  }
@@ -0,0 +1,321 @@
1
+ // Generated from shared/cta-decoration-paint.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ import registry from "./free-form-section-registry.json" with { type: "json" };
3
+ import { imageDescriptionIssues } from "./image-description-validation.js";
4
+ export const CTA_ART_IMAGE_KEYS = ["image", "darkImage"];
5
+ export const CTA_ART_COMPACT_MAX = "768px";
6
+ export const CTA_ART_LAYER_CLASS = "cta-art";
7
+ const sectionFields = registry.section.attrs.decoration.fields;
8
+ const { image, opacity, sizeMode: _sectionSizeMode, ...placementFields } = sectionFields;
9
+ export const CTA_DECORATION_FIELDS = {
10
+ image,
11
+ darkImage: { ...image, required: false },
12
+ ...placementFields,
13
+ opacity: { ...opacity, default: undefined },
14
+ paint: { type: "enum", values: ["mask", "original"], default: "mask" },
15
+ artScrim: { type: "number", minimum: 0, maximum: 1, default: 0.65 },
16
+ scrimEnabled: { type: "boolean" },
17
+ hideAtCompact: { type: "boolean", default: false },
18
+ };
19
+ export const CTA_ART_OPACITY = { mask: opacity.default, original: 0.55 };
20
+ export const CTA_ART_GUIDANCE = "Artwork is decorative and sits inside the border, under the copy and button. The scrim uses the panel's effective background to mute artwork evenly across the full panel. Turn it on or lower the artwork opacity if the copy or button is hard to read.";
21
+ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u;
22
+ function isRecord(value) {
23
+ if (value === null || typeof value !== "object")
24
+ return false;
25
+ const prototype = Object.getPrototypeOf(value);
26
+ return prototype === null || prototype === Object.prototype;
27
+ }
28
+ function hasOwn(value, key) {
29
+ return Object.prototype.hasOwnProperty.call(value, key);
30
+ }
31
+ function pointer(value) {
32
+ return value.replaceAll("~", "~0").replaceAll("/", "~1");
33
+ }
34
+ export function isSafeRootRelativeOrHttpsUrl(value) {
35
+ if (typeof value !== "string" || value === "" || /[\u0000-\u0020\u007f\\]/u.test(value))
36
+ return false;
37
+ if (value.startsWith("/"))
38
+ return !value.startsWith("//");
39
+ if (!/^https:\/\//iu.test(value))
40
+ return false;
41
+ try {
42
+ const url = new URL(value);
43
+ return url.protocol === "https:" && url.hostname !== "" && url.username === "" && url.password === "";
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ }
49
+ export { isSafeRootRelativeOrHttpsUrl as isSafeDecorationUrl };
50
+ function reportUnknown(value, keys, path, report) {
51
+ for (const key of Object.keys(value)) {
52
+ if (!keys.includes(key)) {
53
+ report({ path: `${path}/${pointer(key)}`, expected: "be a supported field", kind: "unknown" });
54
+ }
55
+ }
56
+ }
57
+ function validateImage(value, path, report, acceptDelivery) {
58
+ if (!isRecord(value)) {
59
+ report({ path, expected: "be a site-owned processed image", kind: "imageKeys" });
60
+ return;
61
+ }
62
+ reportUnknown(value, [...image.requiredKeys, ...image.optionalKeys], path, report);
63
+ for (const key of image.requiredKeys) {
64
+ if (!hasOwn(value, key)) {
65
+ report({ path: `${path}/${key}`, expected: "be included in the processed image", kind: "imageKeys" });
66
+ }
67
+ }
68
+ const imageId = value.imageId;
69
+ if (typeof imageId !== "string" || !uuid.test(imageId)) {
70
+ report({ path: `${path}/imageId`, expected: "be a canonical lowercase image UUID" });
71
+ }
72
+ const placeholder = !acceptDelivery && value.src === "" && Array.isArray(value.urls) && value.urls.length === 0;
73
+ const acceptedUrl = (url) => isSafeRootRelativeOrHttpsUrl(url)
74
+ && (!acceptDelivery || (typeof imageId === "string" && acceptDelivery(url, imageId)));
75
+ const expectedUrl = acceptDelivery
76
+ ? "be a rewritten, signed WebP delivery URL for this site and image"
77
+ : "be a safe HTTPS or root-relative delivery URL";
78
+ if (!placeholder && !acceptedUrl(value.src))
79
+ report({ path: `${path}/src`, expected: expectedUrl });
80
+ if (!placeholder) {
81
+ const { minItems, maxItems, fields } = image.urls;
82
+ if (!Array.isArray(value.urls) || value.urls.length < minItems || value.urls.length > maxItems) {
83
+ report({ path: `${path}/urls`, expected: `have ${minItems} through ${maxItems} responsive candidates` });
84
+ }
85
+ else {
86
+ for (const [index, candidate] of value.urls.entries()) {
87
+ const candidatePath = `${path}/urls/${index}`;
88
+ if (!isRecord(candidate)) {
89
+ report({ path: candidatePath, expected: "be a responsive image URL object" });
90
+ continue;
91
+ }
92
+ reportUnknown(candidate, Object.keys(fields), candidatePath, report);
93
+ if (typeof candidate.minWidth !== "number" || !Number.isInteger(candidate.minWidth)
94
+ || candidate.minWidth < fields.minWidth.minimum) {
95
+ report({ path: `${candidatePath}/minWidth`, expected: "be a positive integer" });
96
+ }
97
+ if (!acceptedUrl(candidate.url))
98
+ report({ path: `${candidatePath}/url`, expected: expectedUrl });
99
+ if (candidate.type !== undefined && candidate.type !== "image/webp") {
100
+ report({ path: `${candidatePath}/type`, expected: "be image/webp" });
101
+ }
102
+ }
103
+ if (image.srcMustMatchUrls && !value.urls.some((candidate) => isRecord(candidate) && candidate.url === value.src)) {
104
+ report({ path: `${path}/src`, expected: "match a responsive candidate URL" });
105
+ }
106
+ }
107
+ }
108
+ for (const field of ["width", "height"]) {
109
+ const dimension = value[field];
110
+ if (hasOwn(value, field) && (typeof dimension !== "number" || !Number.isInteger(dimension) || dimension < 1)) {
111
+ report({ path: `${path}/${field}`, expected: "be a positive integer" });
112
+ }
113
+ }
114
+ if (hasOwn(value, "alt") && typeof value.alt !== "string") {
115
+ report({ path: `${path}/alt`, expected: "be text" });
116
+ }
117
+ for (const issue of imageDescriptionIssues(value)) {
118
+ report({ path: `${path}/${issue.field}`, expected: issue.expected });
119
+ }
120
+ }
121
+ /** Without a delivery callback, authored empty URL placeholders and safe preview URLs are valid. */
122
+ export function normalizeCtaDecoration(value, path = "/decoration", acceptDelivery) {
123
+ const issues = [];
124
+ const report = (issue) => {
125
+ if (issues.length < 200)
126
+ issues.push(issue);
127
+ };
128
+ if (value === undefined)
129
+ return { issues };
130
+ if (!isRecord(value)) {
131
+ report({ path, expected: "be a CTA artwork object" });
132
+ return { issues };
133
+ }
134
+ reportUnknown(value, Object.keys(CTA_DECORATION_FIELDS), path, report);
135
+ validateImage(value.image, `${path}/image`, report, acceptDelivery);
136
+ if (hasOwn(value, "darkImage"))
137
+ validateImage(value.darkImage, `${path}/darkImage`, report, acceptDelivery);
138
+ const hasInlineSize = hasOwn(value, "inlineSizePercent");
139
+ const hasBlockSize = hasOwn(value, "blockSizePercent");
140
+ const tiling = value.repeat === "repeat";
141
+ if ((hasInlineSize && hasBlockSize) || (tiling && (hasInlineSize || hasBlockSize))) {
142
+ report({
143
+ path: `${path}/${hasBlockSize ? "blockSizePercent" : "inlineSizePercent"}`,
144
+ expected: tiling ? "be omitted for a natural-size repeat tile" : "be omitted when inlineSizePercent is set",
145
+ });
146
+ }
147
+ const paint = value.paint === "original" ? "original" : CTA_DECORATION_FIELDS.paint.default;
148
+ const normalized = { image: value.image };
149
+ if (hasOwn(value, "darkImage"))
150
+ normalized.darkImage = value.darkImage;
151
+ for (const [name, definition] of Object.entries(CTA_DECORATION_FIELDS)) {
152
+ if (name === "image" || name === "darkImage")
153
+ continue;
154
+ const sent = hasOwn(value, name);
155
+ const entry = value[name];
156
+ if (!sent) {
157
+ const fallback = name === "opacity"
158
+ ? CTA_ART_OPACITY[paint]
159
+ : name === "inlineSizePercent" && (tiling || hasBlockSize)
160
+ ? undefined
161
+ : "default" in definition
162
+ ? definition.default
163
+ : undefined;
164
+ if (fallback !== undefined)
165
+ normalized[name] = fallback;
166
+ continue;
167
+ }
168
+ const fieldPath = `${path}/${name}`;
169
+ if ("values" in definition && definition.type === "enum") {
170
+ if (typeof entry !== "string" || !definition.values.includes(entry)) {
171
+ report({ path: fieldPath, expected: `be one of ${definition.values.join(", ")}` });
172
+ }
173
+ }
174
+ else if (definition.type === "boolean") {
175
+ if (typeof entry !== "boolean")
176
+ report({ path: fieldPath, expected: "be true or false" });
177
+ }
178
+ else if ("minimum" in definition && "maximum" in definition) {
179
+ const integer = definition.type === "integer";
180
+ if (typeof entry !== "number" || !Number.isFinite(entry) || (integer && !Number.isInteger(entry))
181
+ || entry < definition.minimum || entry > definition.maximum) {
182
+ report({
183
+ path: fieldPath,
184
+ expected: `be ${integer ? "an integer" : "a finite number"} from ${definition.minimum} through ${definition.maximum}`,
185
+ });
186
+ }
187
+ }
188
+ normalized[name] = entry;
189
+ }
190
+ return issues.length > 0 ? { issues } : { decoration: normalized, issues };
191
+ }
192
+ export function decorationPosition(anchor, inlineOffset, blockOffset) {
193
+ const bases = {
194
+ "top-start": [0, 0],
195
+ "top-end": [100, 0],
196
+ "bottom-start": [0, 100],
197
+ "bottom-end": [100, 100],
198
+ };
199
+ const [inline, block] = bases[anchor] ?? [50, 50];
200
+ const axis = (base, offset) => offset === 0 ? `${base}%` : `calc(${base}% ${offset < 0 ? "-" : "+"} ${Math.abs(offset)}%)`;
201
+ return `${axis(inline, inlineOffset)} ${axis(block, blockOffset)}`;
202
+ }
203
+ export function escapeCssString(value) {
204
+ return value.replace(/(["\\])/gu, "\\$1").replace(/[\u0000-\u001f\u007f]/gu, (character) => `\\${character.codePointAt(0)?.toString(16)} `);
205
+ }
206
+ function largestUrl(image) {
207
+ return image.urls.reduce((largest, candidate) => !largest || candidate.minWidth > largest.minWidth ? candidate : largest, undefined)?.url ?? image.src;
208
+ }
209
+ /** Use the authored legacy strength when it is present. */
210
+ export function effectiveCtaArtScrim(decoration) {
211
+ if (decoration.scrimEnabled === false)
212
+ return 0;
213
+ const fallback = CTA_DECORATION_FIELDS.artScrim.default;
214
+ const strength = decoration.artScrim ?? fallback;
215
+ return decoration.scrimEnabled === true && strength === 0 ? fallback : strength;
216
+ }
217
+ /** Builds the shared inline style and host attributes used in SSR and editor preview. */
218
+ export function ctaDecorationPaint(value) {
219
+ const { decoration } = normalizeCtaDecoration(value);
220
+ if (!decoration?.image.src)
221
+ return undefined;
222
+ const { anchor, inlineOffsetPercent, blockOffsetPercent, repeat, blockSizePercent, inlineSizePercent } = decoration;
223
+ const light = largestUrl(decoration.image);
224
+ const dark = decoration.darkImage?.src ? largestUrl(decoration.darkImage) : undefined;
225
+ const scrim = effectiveCtaArtScrim(decoration);
226
+ return {
227
+ attributes: {
228
+ "data-cta-art": decoration.paint,
229
+ ...(scrim > 0 ? { "data-cta-art-scrim": "" } : {}),
230
+ ...(dark ? { "data-cta-art-dark": "" } : {}),
231
+ ...(decoration.hideAtCompact ? { "data-cta-art-hide-compact": "" } : {}),
232
+ },
233
+ styles: [
234
+ `--taproot-cta-art-light: url("${escapeCssString(light)}")`,
235
+ ...(dark ? [`--taproot-cta-art-dark: url("${escapeCssString(dark)}")`] : []),
236
+ `--taproot-cta-art-tint: var(${sectionFields.tint.tokenByValue[decoration.tint]})`,
237
+ `--taproot-cta-art-position: ${decorationPosition(anchor, inlineOffsetPercent, blockOffsetPercent)}`,
238
+ `--taproot-cta-art-size: ${repeat === "repeat"
239
+ ? "auto"
240
+ : blockSizePercent !== undefined
241
+ ? `auto ${blockSizePercent}%`
242
+ : `${inlineSizePercent}% auto`}`,
243
+ `--taproot-cta-art-repeat: ${repeat ?? "no-repeat"}`,
244
+ `--taproot-cta-art-opacity: ${decoration.opacity}`,
245
+ `--taproot-cta-art-scrim: ${scrim}`,
246
+ ],
247
+ };
248
+ }
249
+ /** Root scheme stays independent of the colors selected by a nested context. */
250
+ export function buildCtaArtworkSchemeCss() {
251
+ const light = "--taproot-cta-art-light-display:block;--taproot-cta-art-dark-display:none";
252
+ const dark = "--taproot-cta-art-light-display:none;--taproot-cta-art-dark-display:block";
253
+ return `esp-root{${light}}`
254
+ + `esp-root[scheme=dark],esp-root[default-scheme=dark]:not([scheme]){${dark}}`
255
+ + `@media(prefers-color-scheme:dark){esp-root[default-scheme=system]:not([scheme]){${dark}}}`;
256
+ }
257
+ export const CTA_ART_LAYERS = `<div class="${CTA_ART_LAYER_CLASS}" aria-hidden="true"><div class="cta-art__light"></div><div class="cta-art__dark"></div></div>`;
258
+ /** Paints the same clipped layers before and after the CTA upgrades. */
259
+ export function ctaArtworkLayerCss(host, panel = "") {
260
+ const layer = (attribute) => `${host(attribute)} ${panel}.${CTA_ART_LAYER_CLASS}`;
261
+ return `
262
+ ${layer("[data-cta-art]")} {
263
+ display: block;
264
+ position: absolute;
265
+ inset: 0;
266
+ border-radius: max(0px, calc(var(--esp-size-border-radius, 0px) - var(--taproot-cta-art-border, 0px)));
267
+ overflow: clip;
268
+ pointer-events: none;
269
+ }
270
+ ${layer("[data-cta-art]")} > * {
271
+ position: absolute;
272
+ inset: 0;
273
+ opacity: var(--taproot-cta-art-opacity);
274
+ background-position: var(--taproot-cta-art-position);
275
+ background-size: var(--taproot-cta-art-size);
276
+ background-repeat: var(--taproot-cta-art-repeat);
277
+ mask-position: var(--taproot-cta-art-position);
278
+ mask-size: var(--taproot-cta-art-size);
279
+ mask-repeat: var(--taproot-cta-art-repeat);
280
+ }
281
+ .cta-art::after {
282
+ position: absolute;
283
+ inset: 0;
284
+ background: var(--esp-color-background);
285
+ opacity: var(--taproot-cta-art-scrim);
286
+ }
287
+ ${layer("[data-cta-art-scrim]")}::after { content: ""; }
288
+ ${layer("[data-cta-art]")} > .cta-art__light { --_cta-art-image: var(--taproot-cta-art-light); }
289
+ ${layer("[data-cta-art]")} > .cta-art__dark { display: none; }
290
+ ${layer("[data-cta-art-dark]")} > .cta-art__light {
291
+ display: var(--taproot-cta-art-light-display, block);
292
+ }
293
+ ${layer("[data-cta-art-dark]")} > .cta-art__dark {
294
+ --_cta-art-image: var(--taproot-cta-art-dark);
295
+ display: var(--taproot-cta-art-dark-display, none);
296
+ }
297
+ ${layer("[data-cta-art=\"original\"]")} > * { background-image: var(--_cta-art-image); }
298
+ ${layer("[data-cta-art=\"mask\"]")} > * {
299
+ background-color: var(--taproot-cta-art-tint);
300
+ mask-image: var(--_cta-art-image);
301
+ }
302
+ @container taproot-cta (max-width: ${CTA_ART_COMPACT_MAX}) {
303
+ ${layer("[data-cta-art-hide-compact]")} { display: none; }
304
+ }
305
+ `;
306
+ }
307
+ export const CTA_ART_FALLBACK_CSS = `
308
+ taproot-cta:not(:defined)[data-cta-art] {
309
+ display: block;
310
+ position: relative;
311
+ container: taproot-cta / inline-size;
312
+ min-block-size: var(--esp-size-huge);
313
+ background: var(--esp-color-background);
314
+ border: var(--taproot-cta-art-border, 0) solid var(--esp-color-border);
315
+ border-radius: var(--esp-size-border-radius);
316
+ isolation: isolate;
317
+ }
318
+ taproot-cta:not(:defined) > .cta-art { z-index: -1; }
319
+ taproot-cta:defined > .cta-art { display: none; }
320
+ ${ctaArtworkLayerCss((attribute) => `taproot-cta:not(:defined)${attribute}`, "> ")}
321
+ `;