@taprootio/site-authoring 0.41.0 → 0.41.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taprootio/site-authoring",
3
- "version": "0.41.0",
3
+ "version": "0.41.1",
4
4
  "description": "Taproot site authoring CLI: sign in once in the browser, then pull, validate, push, preview, approve, and deploy a site from the terminal",
5
5
  "type": "module",
6
6
  "license": "ISC",
@@ -0,0 +1,46 @@
1
+ // Generated from shared/brand-color.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ /** Brand-color rules shared by the renderer and the site-authoring CLI. */
3
+ const COLOR_MAX_LENGTH = 128;
4
+ const HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
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
+ const HEADER_BRAND_SEMANTIC_COLOR_TOKENS = new Set([
7
+ "--esp-color-headings",
8
+ "--esp-color-link",
9
+ "--esp-color-primary",
10
+ "--esp-color-text",
11
+ ]);
12
+ /** A valid semantic token keeps its name; a supported custom color keeps its value. */
13
+ export function resolveBrandColorToken(value) {
14
+ const color = value?.trim() ?? "";
15
+ if (HEADER_BRAND_SEMANTIC_COLOR_TOKENS.has(color))
16
+ return color;
17
+ return color.length <= COLOR_MAX_LENGTH && isSupportedCustomColor(color) ? color : "";
18
+ }
19
+ export function resolveHeaderBrandColor(value) {
20
+ const color = resolveBrandColorToken(value);
21
+ return HEADER_BRAND_SEMANTIC_COLOR_TOKENS.has(color) ? `var(${color})` : color;
22
+ }
23
+ export function resolveBrandColors(input, resolve = resolveHeaderBrandColor) {
24
+ const configured = resolve(input?.brandColor);
25
+ const light = resolve(input?.lightBrandColor) || configured;
26
+ const dark = resolve(input?.darkBrandColor) || configured || light;
27
+ return { light, dark, generic: configured || light || dark };
28
+ }
29
+ /** The footer preserves the caller's colors without header validation. */
30
+ export function resolveFooterBrandColors({ light, dark }) {
31
+ return { light, dark, generic: light || dark };
32
+ }
33
+ function isSupportedCustomColor(color) {
34
+ if (HEX_COLOR_PATTERN.test(color))
35
+ return true;
36
+ const match = color.match(OKLCH_COLOR_PATTERN);
37
+ if (!match)
38
+ return false;
39
+ return isBoundedColorComponent(match[1], 0, 1)
40
+ && isBoundedColorComponent(match[2], 0, 0.25)
41
+ && isBoundedColorComponent(match[3], 0, 360);
42
+ }
43
+ function isBoundedColorComponent(value, minimum, maximum) {
44
+ const parsed = Number(value);
45
+ return Number.isFinite(parsed) && parsed >= minimum && parsed <= maximum;
46
+ }
@@ -1,5 +1,14 @@
1
1
  {
2
2
  "entries": [
3
+ {
4
+ "version": "0.41.1",
5
+ "note": "Share renderer URL, social platform and brand-color rules with the authoring CLI while preserving published output.",
6
+ "behavior": [
7
+ "Renderer URL safety, social platform helpers and brand-color rules now have shared owners used by their generated copies; rendering and content validation behavior are unchanged.",
8
+ "The help reference version is 62."
9
+ ],
10
+ "help": []
11
+ },
3
12
  {
4
13
  "version": "0.41.0",
5
14
  "note": "A Google Testimonial can show particular reviews (reviewSelection and reviewIds), list every review with showAll, and show Google's rating and links with showProfileSummary. A quotation's own line breaks are kept on the published page.",
@@ -11,6 +11,7 @@ import { blockquoteCaptionParts, readBlockquoteMetadata } from "./blockquote-met
11
11
  import { columnsAttributes, isColumnEligibleBlock } from "./free-form-columns.js";
12
12
  import freeFormSectionRegistry from "./free-form-section-registry.json" with { type: "json" };
13
13
  import { imageDescriptionIssues } from "./image-description-validation.js";
14
+ import { isSafeUrl } from "./url-safety.js";
14
15
  import { isExternalLink, NEW_TAB_CUE_HTML, relWithNewTabTokens } from "./external-link.js";
15
16
  import {
16
17
  explicitImageMaxHeight,
@@ -1553,22 +1554,6 @@ function renderLink(
1553
1554
  return renderElement("a", { href, ...linkAttributes }, `${html}${cue}`);
1554
1555
  }
1555
1556
 
1556
- function isSafeUrl(url: string): boolean {
1557
- if (/[\x00-\x1f\x7f\\]/u.test(url)) return false;
1558
- const cleaned = url.trim();
1559
- if (!cleaned) return false;
1560
- if (cleaned.startsWith("//")) return false;
1561
- if (cleaned.startsWith("/") || cleaned.startsWith("./")) return true;
1562
- if (cleaned.startsWith("#") || cleaned.startsWith("?")) return true;
1563
-
1564
- try {
1565
- const parsed = new URL(cleaned);
1566
- return ["http:", "https:", "mailto:", "tel:"].includes(parsed.protocol);
1567
- } catch {
1568
- return true;
1569
- }
1570
- }
1571
-
1572
1557
  function jsonAttr(value: unknown): string | null {
1573
1558
  if (value === undefined || value === null) return null;
1574
1559
  if (typeof value === "string") return value;
@@ -0,0 +1,39 @@
1
+ // Generated from shared/url-safety.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ /**
3
+ * The renderer's safe-link rule. The generator, editor and CLI copies are
4
+ * written by scripts/sync-field-validation.mjs; edit this source only.
5
+ */
6
+ /**
7
+ * Check whether a URL string is safe for use in an `href` attribute.
8
+ * Allows `http:`, `https:`, `mailto:`, `tel:`, and site-relative paths
9
+ * (starting with `/` or `./`). Rejects `javascript:`, `data:`, `vbscript:`,
10
+ * and every other executable or unknown scheme.
11
+ *
12
+ * ASCII controls, backslashes, and protocol-relative paths are rejected
13
+ * before scheme validation because browsers normalize them inconsistently.
14
+ *
15
+ * Returns `false` for empty/whitespace-only strings.
16
+ */
17
+ export function isSafeUrl(url) {
18
+ if (/[\x00-\x1f\x7f\\]/u.test(url))
19
+ return false;
20
+ const cleaned = url.trim();
21
+ if (!cleaned)
22
+ return false;
23
+ if (cleaned.startsWith("//"))
24
+ return false;
25
+ if (cleaned.startsWith("/") || cleaned.startsWith("./"))
26
+ return true;
27
+ // Fragment-only and query-only links are safe.
28
+ if (cleaned.startsWith("#") || cleaned.startsWith("?"))
29
+ return true;
30
+ // Try parsing as an absolute URL. If it parses, validate the protocol.
31
+ try {
32
+ const parsed = new URL(cleaned);
33
+ return ["http:", "https:", "mailto:", "tel:"].includes(parsed.protocol);
34
+ }
35
+ catch {
36
+ // Not a valid absolute URL — treat as a relative path (safe).
37
+ return true;
38
+ }
39
+ }
@@ -10,11 +10,25 @@
10
10
  * CLI, the generator, the editor and the API's own port in agreement, which
11
11
  * `shared/social-link-url-corpus.json` proves in each of them.
12
12
  *
13
- * It is pure and dependency-free. The generator and the site-authoring CLI
13
+ * It uses the shared platform vocabulary. The generator and site-authoring CLI
14
14
  * cannot import this file, so `node scripts/sync-field-validation.mjs` writes
15
15
  * their copies; edit only this file and re-run it. The editor imports it by
16
16
  * relative path.
17
17
  */
18
+ import socialPlatforms from "./social-platforms.json" with { type: "json" };
19
+ /** The vocabulary in its recorded order; `other` is last. */
20
+ export const SOCIAL_PLATFORMS = socialPlatforms.platforms;
21
+ /** The platform key a Website link stores. */
22
+ export const OTHER_SOCIAL_PLATFORM = "other";
23
+ export function findSocialPlatform(key) {
24
+ return typeof key === "string" ? SOCIAL_PLATFORMS.find((platform) => platform.key === key) : undefined;
25
+ }
26
+ /** Whether a stored link can be rendered: a known platform and an accepted address. */
27
+ export function isRenderableSocialLink(item) {
28
+ return item !== null && item !== undefined
29
+ && findSocialPlatform(item.platform) !== undefined
30
+ && isSocialLinkUrl(item.url);
31
+ }
18
32
  /** The longest address stored anywhere a social link lives. */
19
33
  export const SOCIAL_LINK_URL_MAX_LENGTH = 2048;
20
34
  /**
@@ -0,0 +1,39 @@
1
+ // Generated from shared/url-safety.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ /**
3
+ * The renderer's safe-link rule. The generator, editor and CLI copies are
4
+ * written by scripts/sync-field-validation.mjs; edit this source only.
5
+ */
6
+ /**
7
+ * Check whether a URL string is safe for use in an `href` attribute.
8
+ * Allows `http:`, `https:`, `mailto:`, `tel:`, and site-relative paths
9
+ * (starting with `/` or `./`). Rejects `javascript:`, `data:`, `vbscript:`,
10
+ * and every other executable or unknown scheme.
11
+ *
12
+ * ASCII controls, backslashes, and protocol-relative paths are rejected
13
+ * before scheme validation because browsers normalize them inconsistently.
14
+ *
15
+ * Returns `false` for empty/whitespace-only strings.
16
+ */
17
+ export function isSafeUrl(url) {
18
+ if (/[\x00-\x1f\x7f\\]/u.test(url))
19
+ return false;
20
+ const cleaned = url.trim();
21
+ if (!cleaned)
22
+ return false;
23
+ if (cleaned.startsWith("//"))
24
+ return false;
25
+ if (cleaned.startsWith("/") || cleaned.startsWith("./"))
26
+ return true;
27
+ // Fragment-only and query-only links are safe.
28
+ if (cleaned.startsWith("#") || cleaned.startsWith("?"))
29
+ return true;
30
+ // Try parsing as an absolute URL. If it parses, validate the protocol.
31
+ try {
32
+ const parsed = new URL(cleaned);
33
+ return ["http:", "https:", "mailto:", "tel:"].includes(parsed.protocol);
34
+ }
35
+ catch {
36
+ // Not a valid absolute URL — treat as a relative path (safe).
37
+ return true;
38
+ }
39
+ }