@perkyzz/emvb 0.4.0 → 0.6.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 (127) hide show
  1. package/README.md +23 -3
  2. package/THIRD_PARTY_NOTICES.md +23 -1
  3. package/licenses/exif-js.LICENSE +21 -0
  4. package/licenses/fflate.LICENSE +21 -0
  5. package/licenses/glfx.js.LICENSE +19 -0
  6. package/licenses/mini-photo-editor.LICENSE +21 -0
  7. package/licenses/photocn.LICENSE +21 -0
  8. package/package.json +5 -3
  9. package/src/admin/agents-api.ts +39 -0
  10. package/src/admin/editor/CommandPalette.tsx +43 -2
  11. package/src/admin/editor/Editor.tsx +33 -0
  12. package/src/admin/editor/Timeline.tsx +108 -6
  13. package/src/admin/editor/collection-previews.ts +6 -1
  14. package/src/admin/editor/editor-chrome.tsx +49 -0
  15. package/src/admin/editor/editor-commands.ts +13 -0
  16. package/src/admin/editor/editor-css.ts +7 -0
  17. package/src/admin/editor/feature-css.ts +22 -3
  18. package/src/admin/editor/palette.ts +6 -2
  19. package/src/admin/editor/panels/ColorControl.tsx +24 -12
  20. package/src/admin/editor/panels/ElementPanel.tsx +1 -1
  21. package/src/admin/editor/panels/LayersPanel.tsx +13 -3
  22. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  23. package/src/admin/editor/panels/VariableSection.tsx +5 -3
  24. package/src/admin/editor/panels/color-space.ts +12 -1
  25. package/src/admin/editor/panels/settings/AdvancedFields.tsx +84 -28
  26. package/src/admin/editor/panels/settings/AudienceEditor.tsx +42 -4
  27. package/src/admin/editor/panels/settings/DraftTextField.tsx +38 -9
  28. package/src/admin/editor/panels/settings/FieldControl.tsx +24 -7
  29. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  30. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  31. package/src/admin/editor/panels/settings/MediaPicker.tsx +156 -7
  32. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  33. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +76 -0
  34. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  35. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  36. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  37. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  38. package/src/admin/editor/panels/variable-values.ts +18 -2
  39. package/src/admin/editor/remote-change.ts +67 -0
  40. package/src/admin/editor/store.ts +7 -3
  41. package/src/admin/image-editor/BlurFocus.tsx +112 -0
  42. package/src/admin/image-editor/Canvas.tsx +261 -0
  43. package/src/admin/image-editor/CropOverlay.tsx +390 -0
  44. package/src/admin/image-editor/CurvesPanel.tsx +394 -0
  45. package/src/admin/image-editor/ExportDialog.tsx +354 -0
  46. package/src/admin/image-editor/ImageEditButton.tsx +83 -0
  47. package/src/admin/image-editor/ImageEditorDialog.tsx +786 -0
  48. package/src/admin/image-editor/MetadataPanel.tsx +183 -0
  49. package/src/admin/image-editor/announce.tsx +65 -0
  50. package/src/admin/image-editor/crop-geometry.ts +161 -0
  51. package/src/admin/image-editor/curve-math.ts +177 -0
  52. package/src/admin/image-editor/data-url-fetch.ts +59 -0
  53. package/src/admin/image-editor/engine.ts +55 -0
  54. package/src/admin/image-editor/exif.ts +82 -0
  55. package/src/admin/image-editor/flatten.ts +54 -0
  56. package/src/admin/image-editor/gpu-fit.ts +81 -0
  57. package/src/admin/image-editor/image-editor-css.ts +398 -0
  58. package/src/admin/image-editor/load.ts +109 -0
  59. package/src/admin/image-editor/panels.tsx +287 -0
  60. package/src/admin/image-editor/parts.tsx +565 -0
  61. package/src/admin/image-editor/save.ts +125 -0
  62. package/src/admin/image-editor/tone-panels.tsx +338 -0
  63. package/src/admin/image-editor/tools.ts +59 -0
  64. package/src/admin/image-editor/worker.ts +111 -0
  65. package/src/admin/index.tsx +3 -1
  66. package/src/admin/media-api.ts +132 -2
  67. package/src/admin/pages/AgentsPage.tsx +274 -0
  68. package/src/admin/ui.ts +33 -0
  69. package/src/astro/EmVBPage.astro +11 -2
  70. package/src/astro/floats/runtime.ts +10 -0
  71. package/src/astro/popups/runtime.ts +15 -0
  72. package/src/astro/render.ts +3 -0
  73. package/src/astro/resolve-theme.ts +15 -4
  74. package/src/astro/tabs/runtime.ts +60 -1
  75. package/src/astro/visitor.ts +4 -3
  76. package/src/constants.ts +1 -1
  77. package/src/core/a11y/audit.ts +202 -26
  78. package/src/core/arrange.ts +13 -3
  79. package/src/core/css/generate.ts +9 -1
  80. package/src/core/data/bindings.ts +12 -6
  81. package/src/core/design/classes.ts +5 -3
  82. package/src/core/design/diff.ts +3 -1
  83. package/src/core/design/merge.ts +3 -1
  84. package/src/core/design/transfer.ts +13 -2
  85. package/src/core/design/variables.ts +2 -1
  86. package/src/core/elements/dynamic-elements.ts +9 -1
  87. package/src/core/elements/form-elements.ts +18 -3
  88. package/src/core/elements/index.ts +39 -11
  89. package/src/core/elements/plain-text.ts +2 -2
  90. package/src/core/forms/binding.ts +148 -1
  91. package/src/core/history/diff.ts +32 -4
  92. package/src/core/image-edit/schema.ts +145 -0
  93. package/src/core/image-edit/summary.ts +58 -0
  94. package/src/core/index.ts +14 -0
  95. package/src/core/limits.ts +10 -0
  96. package/src/core/migrate/index.ts +3 -1
  97. package/src/core/perf/meter.ts +9 -1
  98. package/src/core/render/dynamic-post.ts +23 -6
  99. package/src/core/render/form.ts +36 -11
  100. package/src/core/render/index.ts +75 -15
  101. package/src/core/render/pagination.ts +21 -2
  102. package/src/core/sanitize/embed-url.ts +7 -1
  103. package/src/core/sanitize/href.ts +13 -1
  104. package/src/core/schema/descriptors.ts +4 -1
  105. package/src/core/schema/layout.ts +21 -4
  106. package/src/core/share/link.ts +9 -3
  107. package/src/core/stable-json.ts +15 -0
  108. package/src/core/theme/dynamic.ts +32 -24
  109. package/src/core/theme/pagination.ts +30 -3
  110. package/src/core/theme/popup-rules.ts +10 -5
  111. package/src/mcp/errors.ts +44 -0
  112. package/src/mcp/index.ts +4 -0
  113. package/src/mcp/ports.ts +85 -0
  114. package/src/mcp/prompts.ts +76 -0
  115. package/src/mcp/publish.ts +60 -0
  116. package/src/mcp/queue.ts +19 -0
  117. package/src/mcp/rate-limit.ts +80 -0
  118. package/src/mcp/read.ts +486 -0
  119. package/src/mcp/refs.ts +84 -0
  120. package/src/mcp/settings.ts +18 -0
  121. package/src/mcp/tools.ts +265 -0
  122. package/src/mcp/write.ts +664 -0
  123. package/src/server/agent-settings.ts +159 -0
  124. package/src/server/design-routes.ts +71 -17
  125. package/src/server/icon-routes.ts +13 -6
  126. package/src/server/mcp-routes.ts +323 -0
  127. package/src/server/plugin.ts +32 -2
@@ -1,3 +1,4 @@
1
+ import { clipText } from "../limits.ts";
1
2
  import { HEADING_TAGS } from "../elements/index.ts";
2
3
  import type { LayoutNode, POST_DATE_FORMATS } from "../schema/layout.ts";
3
4
  import { sanitizeHref } from "../sanitize/href.ts";
@@ -29,7 +30,12 @@ type PostField = {
29
30
  /** Whether the post has this field; the placeholder stands in when it doesn't. */
30
31
  has?: (post: ThemePostFields) => boolean;
31
32
  /** The field's markup, or nothing when the post's value is empty or unsafe. */
32
- render: (node: LayoutNode, attrs: Attrs, post: ThemePostFields) => VNode | undefined;
33
+ render: (
34
+ node: LayoutNode,
35
+ attrs: Attrs,
36
+ post: ThemePostFields,
37
+ inLoop: boolean,
38
+ ) => VNode | undefined;
33
39
  };
34
40
 
35
41
  type PostDateFormat = (typeof POST_DATE_FORMATS)[number];
@@ -91,13 +97,16 @@ const POST_FIELDS = new Map<string, PostField>([
91
97
  children: ["Featured image"],
92
98
  }),
93
99
  has: (post) => !!post.featuredImageUrl,
94
- render: (node, attrs, post) => {
100
+ render: (node, attrs, post, inLoop) => {
95
101
  const src = sanitizeMediaUrl(post.featuredImageUrl ?? "");
96
102
  if (!src) return undefined;
97
103
  const alt = props<{ decorative?: boolean }>(node).decorative
98
104
  ? ""
99
105
  : post.featuredImageAlt?.trim() || post.title || "Featured image";
100
- return { tag: "img", attrs: { ...attrs, src, alt }, children: [] };
106
+ // W-440: a Loop's images below the fold loaded all at once; like Image, they wait.
107
+ // A single post's featured image is usually the hero, so it isn't delayed.
108
+ const lazy: Attrs = inLoop ? { loading: "lazy", decoding: "async" } : {};
109
+ return { tag: "img", attrs: { ...attrs, src, alt, ...lazy }, children: [] };
101
110
  },
102
111
  },
103
112
  ],
@@ -118,10 +127,17 @@ const POST_FIELDS = new Map<string, PostField>([
118
127
  linkAttrs.target = "_blank";
119
128
  linkAttrs.rel = "noopener noreferrer";
120
129
  }
130
+ const label = text?.trim();
131
+ const title = post.title.trim();
132
+ // W-439: a Loop repeats the same "Read more" for every post; screen readers listing links
133
+ // heard it N times. The name keeps the visible text first and adds the post's title.
134
+ if (label && title && !label.toLowerCase().includes(title.toLowerCase())) {
135
+ linkAttrs["aria-label"] = `${label}: ${title}`;
136
+ }
121
137
  return {
122
138
  tag: "a",
123
139
  attrs: linkAttrs,
124
- children: [text?.trim() || post.title || post.permalink],
140
+ children: [label || title || post.permalink],
125
141
  };
126
142
  },
127
143
  },
@@ -150,7 +166,7 @@ const POST_FIELDS = new Map<string, PostField>([
150
166
  has: (post) => !!post.authorName?.trim(),
151
167
  render: (_node, attrs, post) => {
152
168
  const name = post.authorName?.trim();
153
- return name ? { tag: "span", attrs, children: [name.slice(0, 200)] } : undefined;
169
+ return name ? { tag: "span", attrs, children: [clipText(name, 200)] } : undefined;
154
170
  },
155
171
  },
156
172
  ],
@@ -164,11 +180,12 @@ export function renderDynamicPost(
164
180
  attrs: Attrs,
165
181
  post: ThemePostFields | undefined,
166
182
  mode: RenderMode,
183
+ inLoop = false,
167
184
  ): VNode | undefined {
168
185
  const field = POST_FIELDS.get(node.type);
169
186
  if (!field) return undefined;
170
187
  if (!post || field.has?.(post) === false) {
171
188
  return mode === "editor" ? field.placeholder(attrs) : undefined;
172
189
  }
173
- return field.render(node, attrs, post);
190
+ return field.render(node, attrs, post, inLoop);
174
191
  }
@@ -40,7 +40,9 @@ const honeypot = (inputId: string): VNode => ({
40
40
  /** The text of the form's first Submit button, as the page renders it. */
41
41
  function firstSubmitLabel(nodes: readonly LayoutNode[]): string | undefined {
42
42
  for (const child of nodes) {
43
- if (child.type === "submit") return (child.props as { label?: string }).label ?? "Submit";
43
+ if (child.type === "submit") {
44
+ return (child.props as { label?: string }).label?.trim() || "Submit";
45
+ }
44
46
  const found = firstSubmitLabel(nodeChildren(child));
45
47
  if (found !== undefined) return found;
46
48
  }
@@ -294,16 +296,21 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
294
296
  },
295
297
  };
296
298
  }
297
- if (!meta.required || child.tag !== "label") return child;
299
+ if (!meta.required || (child.tag !== "label" && child.tag !== "legend")) return child;
298
300
  if (child.attrs.class === "emvb-form-label") {
299
301
  return { ...child, children: [...child.children, mark] };
300
302
  }
301
303
  // The checkbox label wraps the input and the label text; the mark follows the text.
304
+ // W-441: the same hidden mark as other labels; a plain " *" was read out as "star".
302
305
  if (child.attrs.class === "emvb-form-checkbox-label") {
303
- return {
304
- ...child,
305
- children: child.children.map((part) => (typeof part === "string" ? `${part} *` : part)),
306
- };
306
+ let last = -1;
307
+ child.children.forEach((part, i) => {
308
+ if (typeof part === "string") last = i;
309
+ });
310
+ if (last === -1) return child;
311
+ const children = [...child.children];
312
+ children.splice(last + 1, 0, mark);
313
+ return { ...child, children };
307
314
  }
308
315
  return child;
309
316
  });
@@ -325,6 +332,10 @@ export function withFieldOptions(
325
332
  return withFieldMeta(withOptions(vnode, node, meta), node, meta);
326
333
  }
327
334
 
335
+ /** The fieldset that holds a radio group's options. */
336
+ const radioGroup = (child: VNode) =>
337
+ child.tag === "fieldset" && (child.attrs.class ?? "").includes("emvb-radio-group");
338
+
328
339
  /** A select or radio field filled with the definition's options. */
329
340
  function withOptions(vnode: VNode, node: LayoutNode, meta: PublicFormField): VNode {
330
341
  const field = meta.name;
@@ -339,10 +350,13 @@ function withOptions(vnode: VNode, node: LayoutNode, meta: PublicFormField): VNo
339
350
  })),
340
351
  ]);
341
352
  }
342
- return replaceChildren(
343
- vnode,
344
- (child) => child.tag === "fieldset" && (child.attrs.class ?? "").includes("emvb-radio-group"),
345
- meta.options.map((option) => ({
353
+ // W-524: the group's <legend> stays; only the placeholder option is replaced.
354
+ const legend = findNode(vnode, radioGroup)?.children.filter(
355
+ (child): child is VNode => typeof child !== "string" && child.tag === "legend",
356
+ );
357
+ return replaceChildren(vnode, radioGroup, [
358
+ ...(legend ?? []),
359
+ ...meta.options.map((option): VNode => ({
346
360
  tag: "label",
347
361
  attrs: { class: "emvb-form-radio-label" },
348
362
  children: [
@@ -354,5 +368,16 @@ function withOptions(vnode: VNode, node: LayoutNode, meta: PublicFormField): VNo
354
368
  ` ${option.label}`,
355
369
  ],
356
370
  })),
357
- );
371
+ ]);
372
+ }
373
+
374
+ /** The first element node `match` accepts, depth first. */
375
+ function findNode(vnode: VNode, match: (node: VNode) => boolean): VNode | undefined {
376
+ if (match(vnode)) return vnode;
377
+ for (const child of vnode.children) {
378
+ if (typeof child === "string") continue;
379
+ const found = findNode(child, match);
380
+ if (found) return found;
381
+ }
382
+ return undefined;
358
383
  }
@@ -6,7 +6,7 @@ import { cssScopeToken, scopeClassName, scopeCss, scopeWrapperCss } from "../css
6
6
  import { ELEMENTS } from "../elements/index.ts";
7
7
  import { controlId } from "../elements/field-id.ts";
8
8
  import { layoutHasForm } from "../forms/binding.ts";
9
- import { forEachNode, someNode } from "../tree-ops.ts";
9
+ import { nodeChildren, someNode } from "../tree-ops.ts";
10
10
  import { layoutHasMenuDropdown, layoutHasTabs } from "../tabs/presence.ts";
11
11
  import type { DesignSystem } from "../schema/design.ts";
12
12
  import {
@@ -201,6 +201,12 @@ export function renderPage(
201
201
  scope?: string;
202
202
  /** Editor canvas: device rules follow this device, not the frame width (W-116). */
203
203
  previewDevice?: PopupDevice;
204
+ /**
205
+ * Theme parts (header, footer, popup, float) render apart from the page, so a synced section
206
+ * on both gave form fields, honeypots and tab groups the same ids: a label in a popup focused
207
+ * the page's field. Their generated ids get a suffix from `scope` (W-527).
208
+ */
209
+ partIds?: boolean;
204
210
  } = {},
205
211
  ): RenderResult {
206
212
  const mode = opts.mode ?? "public";
@@ -218,10 +224,18 @@ export function renderPage(
218
224
  queryMin?: number;
219
225
  }[] = [];
220
226
  const layoutHasToc = treeHasType(layout.root, "toc");
227
+ // W-384: a table of contents lists the page's headings that actually render, with their
228
+ // rendered text, so a hidden A/B arm or audience heading is not a dead link.
229
+ const pageHeadings = layoutHasToc
230
+ ? new Set(headingAnchors(layout.root).map((h) => h.node))
231
+ : undefined;
232
+ const renderedHeadings: { id: string; text: string }[] = [];
233
+ const tocNodes: { node: LayoutNode; vnode: VNode }[] = [];
221
234
  const knownVariables = new Set(design.variables.colors.map((c) => c.id));
222
235
  let backgroundVideo = false;
223
236
 
224
237
  const domIds = new Map<string, number>();
238
+ const idSuffix = opts.partIds && opts.scope ? `-t${originHash(opts.scope)}` : "";
225
239
  // W-253: runtimes follow what renders, including synced section and loop item contents,
226
240
  // which the page's own layout doesn't hold.
227
241
  const rendered = { form: false, tabs: false, menuDropdown: false };
@@ -235,7 +249,7 @@ export function renderPage(
235
249
  uniqueId: (base) => {
236
250
  const count = (domIds.get(base) ?? 0) + 1;
237
251
  domIds.set(base, count);
238
- return count === 1 ? base : `${base}-r${count}`;
252
+ return `${base}${count === 1 ? "" : `-r${count}`}${idSuffix}`;
239
253
  },
240
254
  };
241
255
 
@@ -303,6 +317,11 @@ export function renderPage(
303
317
  }
304
318
  }
305
319
  if (node.container) declarations.push({ property: "container-type", value: "inline-size" });
320
+ // W-523: a query container can't size to its content, so in a row (or with align-items other
321
+ // than stretch) it collapsed to 0 px and its content vanished. Full width unless a width is set.
322
+ if (node.container && node.style?.width === undefined && !node.classes?.length) {
323
+ declarations.push({ property: "width", value: "100%" });
324
+ }
306
325
  if (node.type === "image") {
307
326
  const focal = node.props as { focalX?: unknown; focalY?: unknown };
308
327
  const position = objectPosition(focal.focalX, focal.focalY);
@@ -365,6 +384,10 @@ export function renderPage(
365
384
  tablet: tablet.declarations,
366
385
  mobile: mobile.declarations,
367
386
  hiddenOn,
387
+ ...(node.type === "image" &&
388
+ String((node.props as { caption?: unknown }).caption ?? "").trim() !== ""
389
+ ? { figure: true }
390
+ : {}),
368
391
  ...(queryDeclarations.length > 0 && queryMin !== undefined
369
392
  ? { query: queryDeclarations, queryMin }
370
393
  : {}),
@@ -426,13 +449,31 @@ export function renderPage(
426
449
  if (isDynamicPostNode(node)) {
427
450
  return finish(
428
451
  node,
429
- renderDynamicPost(node, attrs, resolvePostForRender(dynamic, mode), mode),
452
+ renderDynamicPost(
453
+ node,
454
+ attrs,
455
+ resolvePostForRender(dynamic, mode),
456
+ mode,
457
+ dynamic?.inLoopItem === true,
458
+ ),
430
459
  );
431
460
  }
432
461
  if (isTabsNode(node)) return finish(node, renderTabs(node, id, attrs, ctx, dynamic));
433
462
  if (node.type === "toc") {
434
463
  const built = def.build(node as never, attrs, []);
435
- return finish(node, { ...built, children: tocChildren(layout, node, mode) });
464
+ const vnode = { ...built, children: [] as (VNode | string)[] };
465
+ tocNodes.push({ node, vnode });
466
+ return finish(node, vnode);
467
+ }
468
+ if (node.type === "heading" && pageHeadings?.has(stored) && attrs.id) {
469
+ const text = String((node.props as { text?: unknown }).text ?? "").trim();
470
+ // W-409: a heading hidden on every device has nothing to jump to.
471
+ const hiddenEverywhere = (["desktop", "tablet", "mobile"] as const).every((device) =>
472
+ node.hiddenOn?.includes(device),
473
+ );
474
+ if (text && !hiddenEverywhere && !renderedHeadings.some((h) => h.id === attrs.id)) {
475
+ renderedHeadings.push({ id: attrs.id, text });
476
+ }
436
477
  }
437
478
  if (isParentNode(node)) {
438
479
  return finish(node, def.build(node as never, attrs, ctx.children(node.children, dynamic)));
@@ -487,6 +528,16 @@ export function renderPage(
487
528
  attrs: { class: "emvb-root" },
488
529
  children: [],
489
530
  };
531
+ for (const toc of tocNodes) {
532
+ toc.vnode.children = tocChildren(toc.node, renderedHeadings, mode);
533
+ // W-430: with no headings the public page had an empty "Table of contents" navigation
534
+ // landmark (or just its title). It's left as a plain empty box instead.
535
+ if (mode !== "editor" && renderedHeadings.length === 0) {
536
+ toc.vnode.tag = "div";
537
+ delete toc.vnode.attrs["aria-label"];
538
+ toc.vnode.children = [];
539
+ }
540
+ }
490
541
  const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
491
542
  const css = generateCss({
492
543
  design,
@@ -518,24 +569,33 @@ function treeHasType(node: LayoutNode, type: string): boolean {
518
569
  return someNode(node, (current) => current.type === type);
519
570
  }
520
571
 
521
- function headingAnchors(root: LayoutNode): { id: string; text: string }[] {
522
- const out: { id: string; text: string }[] = [];
523
- forEachNode(root, (node) => {
524
- if (node.type !== "heading") return;
525
- const text = String((node.props as { text?: unknown }).text ?? "").trim();
526
- if (!text) return;
527
- const id = node.htmlId && HTML_ID.test(node.htmlId) ? node.htmlId : `emvb-h-${node.id}`;
528
- out.push({ id, text });
529
- });
572
+ /**
573
+ * The page's own heading nodes (not synced section or loop item contents). W-512: not those
574
+ * inside an element hidden on every device, which never show, so a contents link has nothing
575
+ * to jump to (W-409 covered only the heading's own visibility).
576
+ */
577
+ function headingAnchors(root: LayoutNode): { node: LayoutNode }[] {
578
+ const out: { node: LayoutNode }[] = [];
579
+ const walk = (node: LayoutNode) => {
580
+ if (node !== root && HIDDEN_DEVICES.every((device) => node.hiddenOn?.includes(device))) return;
581
+ if (node.type === "heading") out.push({ node });
582
+ for (const child of nodeChildren(node)) walk(child);
583
+ };
584
+ walk(root);
530
585
  return out;
531
586
  }
532
587
 
533
- function tocChildren(layout: Layout, node: LayoutNode, mode: RenderMode): (VNode | string)[] {
588
+ const HIDDEN_DEVICES = ["desktop", "tablet", "mobile"] as const;
589
+
590
+ function tocChildren(
591
+ node: LayoutNode,
592
+ items: { id: string; text: string }[],
593
+ mode: RenderMode,
594
+ ): (VNode | string)[] {
534
595
  const title =
535
596
  node.type === "toc"
536
597
  ? String((node.props as { title?: unknown }).title ?? "").trim() || undefined
537
598
  : undefined;
538
- const items = headingAnchors(layout.root);
539
599
  const children: (VNode | string)[] = [];
540
600
  if (title) children.push({ tag: "p", attrs: { class: "emvb-toc-title" }, children: [title] });
541
601
  if (items.length === 0) {
@@ -8,6 +8,13 @@ const EDITOR_SAMPLE: ArchivePagination = { page: 2, hasMore: true, basePath: "/p
8
8
 
9
9
  const label = (text: string | undefined, fallback: string) => text?.trim() || fallback;
10
10
 
11
+ /**
12
+ * W-433: Previous/Next set to just an arrow ("←", "»") was read as "left arrow" or nothing; such
13
+ * texts get the plain name as an aria-label.
14
+ */
15
+ const nameIfSymbols = (text: string, name: string): Record<string, string> =>
16
+ /[\p{L}\p{N}]/u.test(text) ? {} : { "aria-label": name };
17
+
11
18
  /**
12
19
  * Previous, page numbers and Next as plain links in a `nav` (W-222). No JS. Nothing on the page
13
20
  * when there is no archive page data or only one page; the editor shows a sample.
@@ -45,13 +52,23 @@ export function renderPagination(
45
52
  case "prev":
46
53
  return {
47
54
  tag: "a",
48
- attrs: { class: "emvb-pagination-prev", href: href(item.href), rel: "prev" },
55
+ attrs: {
56
+ class: "emvb-pagination-prev",
57
+ href: href(item.href),
58
+ rel: "prev",
59
+ ...nameIfSymbols(label(node.props.prevText, "Previous"), "Previous page"),
60
+ },
49
61
  children: [label(node.props.prevText, "Previous")],
50
62
  };
51
63
  case "next":
52
64
  return {
53
65
  tag: "a",
54
- attrs: { class: "emvb-pagination-next", href: href(item.href), rel: "next" },
66
+ attrs: {
67
+ class: "emvb-pagination-next",
68
+ href: href(item.href),
69
+ rel: "next",
70
+ ...nameIfSymbols(label(node.props.nextText, "Next"), "Next page"),
71
+ },
55
72
  children: [label(node.props.nextText, "Next")],
56
73
  };
57
74
  case "gap":
@@ -66,6 +83,8 @@ export function renderPagination(
66
83
  attrs: {
67
84
  class: "emvb-pagination-page",
68
85
  href: href(item.href),
86
+ // W-426: a bare "2" says nothing out of context; screen readers hear "Page 2".
87
+ "aria-label": `Page ${item.n}`,
69
88
  ...(item.current ? { "aria-current": "page" } : {}),
70
89
  },
71
90
  children: [String(item.n)],
@@ -114,8 +114,14 @@ const PROVIDERS = [
114
114
  * Resolves an editor-supplied URL to a safe embed target, or undefined if refused.
115
115
  * YouTube always becomes `youtube-nocookie.com`; Vimeo becomes `player.vimeo.com`.
116
116
  */
117
+ // W-448: "youtube.com/watch?v=…" typed without https:// was taken for a video file path on this
118
+ // site, so the page showed a broken player. Known video hosts get their scheme.
119
+ const BARE_VIDEO_HOST =
120
+ /^(?:(?:www\.|m\.)?youtube\.com|youtu\.be|(?:www\.|player\.)?vimeo\.com)\//i;
121
+
117
122
  export function resolveEmbedUrl(value: string): EmbedTarget | undefined {
118
- const trimmed = value.trim();
123
+ const typed = value.trim();
124
+ const trimmed = BARE_VIDEO_HOST.test(typed) ? `https://${typed}` : typed;
119
125
  if (trimmed.length === 0 || trimmed.length > 2000) return undefined;
120
126
 
121
127
  const hasScheme = /^[a-z][a-z0-9+.-]*:/i.test(trimmed);
@@ -3,4 +3,16 @@ import { sanitizeUrl } from "./url.ts";
3
3
  const HREF_SCHEMES: ReadonlySet<string> = new Set(["http:", "https:", "mailto:", "tel:"]);
4
4
 
5
5
  /** Allowed public hrefs (R-032): http(s), mailto, tel, and relative paths, queries and hashes. */
6
- export const sanitizeHref = (value: string): string | undefined => sanitizeUrl(value, HREF_SCHEMES);
6
+ export function sanitizeHref(value: string): string | undefined {
7
+ // W-417: phone numbers are usually written with spaces ("tel:+1 555 010 0199"); the spaces
8
+ // made the link fall back to "#". They're dropped, as phones ignore them anyway.
9
+ if (/^\s*tel:/i.test(value)) return sanitizeUrl(value.replace(/\s+/g, ""), HREF_SCHEMES);
10
+ // W-427: "www.example.com" is a site, not a page path next to the current one.
11
+ const trimmed = value.trim().replace(/^www\./i, (w) => `https://${w}`);
12
+ // W-428: a plain space in an email link ("mailto:me@x.com?subject=Hi there") is encoded, as a
13
+ // browser would; the link used to fall back to "#". Web addresses with spaces are still refused.
14
+ return sanitizeUrl(
15
+ /^mailto:/i.test(trimmed) ? trimmed.replaceAll(" ", "%20") : trimmed,
16
+ HREF_SCHEMES,
17
+ );
18
+ }
@@ -9,7 +9,8 @@ export type FieldKind =
9
9
  | "href"
10
10
  | "media"
11
11
  | "icon"
12
- | "list-items";
12
+ | "list-items"
13
+ | "image-sources";
13
14
 
14
15
  export type FieldOption = { value: string | number | boolean; label: string };
15
16
 
@@ -23,6 +24,8 @@ export type FieldDescriptor = {
23
24
  optional?: boolean;
24
25
  /** Highest value a whole-number field accepts, matching its schema (W-223). */
25
26
  max?: number;
27
+ /** Lowest value a whole-number field accepts; unset is 1 (W-388). */
28
+ min?: number;
26
29
  /** Props that hold this field's tablet and mobile values (W-139); unset follows the wider device. */
27
30
  devices?: { tablet: string; mobile: string };
28
31
  };
@@ -1,8 +1,11 @@
1
1
  import { z } from "zod";
2
2
  import { MAX_TEXT_LENGTH } from "../limits.ts";
3
+ import { ImageEdit } from "../image-edit/schema.ts";
3
4
  import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style.ts";
4
5
 
5
6
  /**
7
+ * 16 since W-481 (D-061): an optional editor-only `edit` record on images (image editor).
8
+ * Every other value is unchanged.
6
9
  * 15 since W-341: optional per-element `dir`, image link/caption/focal point/sources, button icons,
7
10
  * a table-of-contents element, and container queries. Every other value is unchanged.
8
11
  * 14 since W-329: optional visitor `segments` in an element's audience (the host names them);
@@ -14,7 +17,7 @@ import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style
14
17
  * (`{ angle, from, to }`) become a linear gradient on read.
15
18
  * 11 since W-156 and W-157 (D-045): the layout Section element and an editor-only node label.
16
19
  */
17
- export const LAYOUT_SCHEMA_VERSION = 15;
20
+ export const LAYOUT_SCHEMA_VERSION = 16;
18
21
 
19
22
  export const NodeId = z
20
23
  .string()
@@ -104,7 +107,7 @@ export const AUDIENCE_DEVICES = ["mobile", "tablet", "desktop"] as const;
104
107
  /** A visitor segment name the host passes and a Visitors rule matches (W-329). */
105
108
  /** A host segment name: letters, digits, and `:` `_` `-`, up to 64 characters (`plan:pro`). */
106
109
  export const AUDIENCE_SEGMENT = /^[a-z0-9][a-z0-9:_-]{0,63}$/;
107
- const SEGMENT_HINT = "Segments are lowercase letters, digits, - or _, e.g. member";
110
+ const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, e.g. plan:pro";
108
111
 
109
112
  /**
110
113
  * Who sees an element (W-313): visitors from these countries, on these devices, new or
@@ -339,6 +342,8 @@ export const ImageNode = leafNode(
339
342
  )
340
343
  .max(6)
341
344
  .optional(),
345
+ /** Editor-only record of an image-editor edit; never rendered (W-481). */
346
+ edit: ImageEdit.optional(),
342
347
  }),
343
348
  ).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
344
349
  message: "Alt text is required unless the image is marked decorative.",
@@ -566,9 +571,13 @@ const FIELD_SLUG_HINT = "Use the field's slug, e.g. photo";
566
571
  /** A site path with `{slug}` or `{id}`, and no other placeholders (W-330). */
567
572
  export const LOOP_PERMALINK =
568
573
  /^(?=.*\{(?:slug|id)\})\/(?!\/)(?:[A-Za-z0-9._~/-]|\{slug\}|\{id\})*$/;
569
- /** `field=value` pairs separated by `;` (W-330). Values have no `;`, `=` or angle brackets. */
574
+ /**
575
+ * `field=value` pairs separated by `;` (W-330). Values have no `;`, `=` or angle brackets.
576
+ * W-391: a value starts and ends with a non-space, so the spaces around it can only be matched
577
+ * one way; the earlier pattern let both sides take them and a 265-character filter took ~50 s.
578
+ */
570
579
  export const LOOP_FILTER =
571
- /^\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>]{1,100}?(?:\s*;\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>]{1,100}?)*\s*;?\s*$/;
580
+ /^\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>\s](?:[^;=<>]{0,98}[^;=<>\s])?(?:\s*;\s*[a-z][a-z0-9_]{0,63}\s*=\s*[^;=<>\s](?:[^;=<>]{0,98}[^;=<>\s])?)*\s*;?\s*$/;
572
581
  /** Which entries a collection Loop shows first (W-308). */
573
582
  export const LOOP_ORDERS = ["newest", "oldest", "title"] as const;
574
583
 
@@ -636,6 +645,11 @@ export const PaginationNode = leafNode(
636
645
  showCount: z.boolean().optional(),
637
646
  /** The count's text; `{page}` and `{total}` are filled in. Unset = "Page {page} of {total}". */
638
647
  countText: z.string().max(60).optional(),
648
+ /**
649
+ * The page title of archive page 2 onward (W-529); `{title}` and `{page}` are filled in.
650
+ * Unset = "{title} – page {page}". Hosts read it with `archivePageTitle`.
651
+ */
652
+ titleText: z.string().max(60).optional(),
639
653
  }),
640
654
  );
641
655
 
@@ -769,6 +783,9 @@ const KnownLayoutNode = z.discriminatedUnion("type", [
769
783
  MenuItemNode,
770
784
  ]);
771
785
 
786
+ /** One strict schema per known element type, for the MCP element catalogue (W-453). */
787
+ export const KNOWN_NODE_SCHEMAS = KnownLayoutNode.options;
788
+
772
789
  export type HeadingNode = z.infer<typeof HeadingNode>;
773
790
  export type TocNode = z.infer<typeof TocNode>;
774
791
  export type SpacerNode = z.infer<typeof SpacerNode>;
@@ -17,6 +17,9 @@ const MAX_TITLE = 120;
17
17
  /** Unpacked text: a layout and a design at their limits, plus a little JSON. */
18
18
  const MAX_UNPACKED_BYTES = MAX_LAYOUT_BYTES + MAX_DESIGN_BYTES + 4096;
19
19
 
20
+ /** W-507: the title cap counts whole characters, so an emoji at the limit isn't cut in half. */
21
+ const clipTitle = (title: string): string => Array.from(title).slice(0, MAX_TITLE).join("");
22
+
20
23
  export type SharedPage = { title: string; layout: Layout; design?: DesignSystem };
21
24
 
22
25
  export type ShareRead =
@@ -120,7 +123,7 @@ export async function pipeBytes(
120
123
  */
121
124
  export async function encodeSharedPage(page: SharedPage): Promise<string> {
122
125
  const json = JSON.stringify({
123
- t: page.title.slice(0, MAX_TITLE),
126
+ t: clipTitle(page.title),
124
127
  l: page.layout,
125
128
  ...(page.design ? { d: page.design } : {}),
126
129
  });
@@ -151,7 +154,10 @@ export async function decodeSharedPage(encoded: string): Promise<ShareRead> {
151
154
  const text = encoded.trim();
152
155
  if (!text) return { ok: false, reason: "empty" };
153
156
  if (text.length > MAX_LINK_CHARS) return { ok: false, reason: "too-long" };
154
- const [version, body] = text.split(".", 2);
157
+ const [version, raw] = text.split(".", 2);
158
+ // W-437: mail clients wrap long links and chat apps take a closing ")" or "." into them; none
159
+ // of those characters is base64url, so line breaks inside and trailing punctuation are dropped.
160
+ const body = raw?.replace(/\s+/g, "").replace(/[^A-Za-z0-9_-]+$/, "");
155
161
  if (version !== VERSION || !body || !/^[A-Za-z0-9_-]+$/.test(body)) {
156
162
  return { ok: false, reason: "unreadable" };
157
163
  }
@@ -173,7 +179,7 @@ export async function decodeSharedPage(encoded: string): Promise<ShareRead> {
173
179
  return { ok: false, reason: "invalid", detail: layout.issues[0]?.message ?? "Bad layout" };
174
180
  }
175
181
  const page: SharedPage = {
176
- title: typeof t === "string" && t.trim() ? t.trim().slice(0, MAX_TITLE) : "Shared page",
182
+ title: typeof t === "string" && t.trim() ? clipTitle(t.trim()) : "Shared page",
177
183
  layout: layout.layout,
178
184
  };
179
185
  if (d !== undefined) {
@@ -0,0 +1,15 @@
1
+ /** Keys sorted at every level: a saved copy comes back in schema order, not edit order. */
2
+ function sorted(value: unknown): unknown {
3
+ if (Array.isArray(value)) return value.map(sorted);
4
+ if (!value || typeof value !== "object") return value;
5
+ const entries = Object.entries(value as Record<string, unknown>).toSorted(([a], [b]) =>
6
+ a < b ? -1 : a > b ? 1 : 0,
7
+ );
8
+ return Object.fromEntries(entries.map(([k, v]) => [k, sorted(v)]));
9
+ }
10
+
11
+ /** JSON text that ignores key order, to compare a saved copy with an edited one (W-518, W-519). */
12
+ export const stableJson = (value: unknown): string => JSON.stringify(sorted(value));
13
+
14
+ /** Same content, whatever the key order (W-519). */
15
+ export const sameJson = (a: unknown, b: unknown): boolean => stableJson(a) === stableJson(b);
@@ -99,26 +99,37 @@ function linkDefs(block: Record<string, unknown>): Map<string, string> {
99
99
  return links;
100
100
  }
101
101
 
102
- /** A span's text wrapped in its marks; unknown marks and unsafe links leave plain text. */
103
- function spanNode(
104
- span: Record<string, unknown>,
105
- links: Map<string, string>,
106
- ): VNode | string | null {
102
+ /** Text with its line breaks as `<br>`. */
103
+ function withBreaks(text: string): (VNode | string)[] {
104
+ const out: (VNode | string)[] = [];
105
+ text.split("\n").forEach((part, i) => {
106
+ if (i > 0) out.push({ tag: "br", attrs: {}, children: [] });
107
+ if (part) out.push(part);
108
+ });
109
+ return out;
110
+ }
111
+
112
+ /**
113
+ * A span's text wrapped in its marks; unknown marks and unsafe links leave plain text. Line
114
+ * breaks become `<br>` inside the marks too: a bold or linked line break was lost (W-525).
115
+ */
116
+ function spanNodes(span: Record<string, unknown>, links: Map<string, string>): (VNode | string)[] {
107
117
  const text = typeof span["text"] === "string" ? span["text"] : "";
108
- if (!text) return null;
118
+ if (!text) return [];
109
119
  const marks = Array.isArray(span["marks"])
110
120
  ? span["marks"].filter((m) => typeof m === "string")
111
121
  : [];
112
- let node: VNode | string = text;
113
- for (const mark of marks.toReversed()) {
122
+ let nodes = withBreaks(text);
123
+ // W-392: a link can't hold a link, so only the span's first (outermost) link mark is kept.
124
+ const link = marks.find((mark) => !DECORATORS[mark] && links.has(mark));
125
+ for (const mark of new Set(marks.toReversed())) {
114
126
  const tag = DECORATORS[mark];
115
- if (tag) node = { tag, attrs: {}, children: [node] };
116
- else {
117
- const href = links.get(mark);
118
- if (href) node = { tag: "a", attrs: { href }, children: [node] };
127
+ if (tag) nodes = [{ tag, attrs: {}, children: nodes }];
128
+ else if (mark === link) {
129
+ nodes = [{ tag: "a", attrs: { href: links.get(mark) as string }, children: nodes }];
119
130
  }
120
131
  }
121
- return node;
132
+ return nodes;
122
133
  }
123
134
 
124
135
  /** A block's spans, with line breaks kept as `<br>`. */
@@ -128,14 +139,7 @@ function inlineNodes(block: Record<string, unknown>): (VNode | string)[] {
128
139
  const out: (VNode | string)[] = [];
129
140
  for (const child of children) {
130
141
  if (!isRecord(child) || (child["_type"] !== undefined && child["_type"] !== "span")) continue;
131
- const node = spanNode(child, links);
132
- if (node === null) continue;
133
- if (typeof node === "string" && node.includes("\n")) {
134
- node.split("\n").forEach((part, i) => {
135
- if (i > 0) out.push({ tag: "br", attrs: {}, children: [] });
136
- if (part) out.push(part);
137
- });
138
- } else out.push(node);
142
+ out.push(...spanNodes(child, links));
139
143
  }
140
144
  return out;
141
145
  }
@@ -254,7 +258,11 @@ const MAX_LOOP_FILTERS = 5;
254
258
  */
255
259
  export function parseLoopFilter(text: unknown): Record<string, string | string[]> | undefined {
256
260
  if (typeof text !== "string" || !LOOP_FILTER.test(text)) return undefined;
257
- const where: Record<string, string | string[]> = {};
261
+ // W-391: a field named like an Object method (`constructor`) starts empty too.
262
+ const where: Record<string, string | string[]> = Object.create(null) as Record<
263
+ string,
264
+ string | string[]
265
+ >;
258
266
  let count = 0;
259
267
  for (const pair of text.split(";")) {
260
268
  const at = pair.indexOf("=");
@@ -263,10 +271,10 @@ export function parseLoopFilter(text: unknown): Record<string, string | string[]
263
271
  const value = pair.slice(at + 1).trim();
264
272
  if (!field || !value || count >= MAX_LOOP_FILTERS) continue;
265
273
  count += 1;
266
- const had = where[field];
274
+ const had = Object.hasOwn(where, field) ? where[field] : undefined;
267
275
  where[field] = had === undefined ? value : [...(Array.isArray(had) ? had : [had]), value];
268
276
  }
269
- return count > 0 ? where : undefined;
277
+ return count > 0 ? Object.fromEntries(Object.entries(where)) : undefined;
270
278
  }
271
279
 
272
280
  /** An entry's link from a Loop's pattern (W-330): `{slug}` and `{id}` filled in, URL-encoded. */