@perkyzz/emvb 0.3.0 → 0.5.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 (163) hide show
  1. package/README.md +22 -4
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +5 -2
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/agents-api.ts +39 -0
  6. package/src/admin/api.ts +17 -7
  7. package/src/admin/content-api.ts +7 -51
  8. package/src/admin/content-item.ts +22 -0
  9. package/src/admin/design-api.ts +30 -0
  10. package/src/admin/editor/A11yCopilot.tsx +1 -1
  11. package/src/admin/editor/CommandPalette.tsx +43 -2
  12. package/src/admin/editor/Editor.tsx +133 -332
  13. package/src/admin/editor/EditorOverlay.tsx +3 -1
  14. package/src/admin/editor/PerfMeter.tsx +1 -1
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +124 -9
  17. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  18. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  19. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  20. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  21. package/src/admin/editor/canvas/drop-line.ts +24 -0
  22. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  23. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  24. package/src/admin/editor/collection-previews.ts +28 -5
  25. package/src/admin/editor/editor-chrome.tsx +346 -0
  26. package/src/admin/editor/editor-commands.ts +360 -0
  27. package/src/admin/editor/editor-css.ts +4 -0
  28. package/src/admin/editor/element-chrome.ts +89 -0
  29. package/src/admin/editor/feature-css.ts +37 -18
  30. package/src/admin/editor/host.ts +33 -0
  31. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  32. package/src/admin/editor/icons/library.ts +29 -19
  33. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  34. package/src/admin/editor/palette-items.ts +36 -5
  35. package/src/admin/editor/palette.ts +9 -4
  36. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  37. package/src/admin/editor/panels/ColorControl.tsx +21 -18
  38. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  39. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  40. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  41. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  42. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  43. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  44. package/src/admin/editor/panels/color-space.ts +12 -1
  45. package/src/admin/editor/panels/inline-error.tsx +11 -0
  46. package/src/admin/editor/panels/settings/AdvancedFields.tsx +143 -1
  47. package/src/admin/editor/panels/settings/AudienceEditor.tsx +115 -7
  48. package/src/admin/editor/panels/settings/DraftTextField.tsx +42 -9
  49. package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
  50. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  51. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  52. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  53. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  54. package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
  55. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  56. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  57. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  58. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  59. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  60. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  61. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  62. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  63. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  64. package/src/admin/editor/panels/style-target.ts +105 -0
  65. package/src/admin/editor/panels/variable-values.ts +4 -2
  66. package/src/admin/editor/remote-change.ts +67 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +4 -0
  69. package/src/admin/editor/store.ts +10 -1
  70. package/src/admin/editor/useClipboardActions.ts +1 -1
  71. package/src/admin/editor/useEditorCommands.ts +61 -13
  72. package/src/admin/editor/useEditorData.ts +7 -1
  73. package/src/admin/editor/useEditorShortcuts.ts +23 -15
  74. package/src/admin/editor/useNodeActions.ts +6 -1
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/index.tsx +3 -1
  78. package/src/admin/media-api.ts +20 -0
  79. package/src/admin/pages/AgentsPage.tsx +274 -0
  80. package/src/admin/theme-api.ts +5 -18
  81. package/src/admin/ui.ts +28 -0
  82. package/src/astro/content-port.ts +24 -0
  83. package/src/astro/floats/runtime.ts +10 -0
  84. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  85. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  86. package/src/astro/forms/client.ts +1 -0
  87. package/src/astro/forms-definitions.ts +24 -11
  88. package/src/astro/index.ts +1 -0
  89. package/src/astro/popups/runtime.ts +15 -0
  90. package/src/astro/render-session.ts +85 -0
  91. package/src/astro/request-data.ts +20 -8
  92. package/src/astro/resolve-theme.ts +166 -76
  93. package/src/astro/resolve.ts +57 -16
  94. package/src/astro/tabs/runtime.ts +60 -1
  95. package/src/astro/theme-posts.ts +16 -5
  96. package/src/astro/visitor.ts +67 -5
  97. package/src/constants.ts +1 -1
  98. package/src/core/a11y/audit.ts +202 -26
  99. package/src/core/arrange.ts +71 -38
  100. package/src/core/audience/rules.ts +22 -2
  101. package/src/core/canvas-styles.ts +24 -0
  102. package/src/core/clipboard.ts +11 -32
  103. package/src/core/css/generate.ts +18 -1
  104. package/src/core/css/print.ts +12 -0
  105. package/src/core/css/scope.ts +3 -3
  106. package/src/core/css-keywords.ts +83 -0
  107. package/src/core/data/bindings.ts +4 -6
  108. package/src/core/design/classes.ts +13 -15
  109. package/src/core/design/diff.ts +55 -0
  110. package/src/core/design/merge.ts +127 -0
  111. package/src/core/design/variables.ts +25 -21
  112. package/src/core/elements/dynamic-elements.ts +30 -0
  113. package/src/core/elements/form-elements.ts +20 -3
  114. package/src/core/elements/index.ts +211 -7
  115. package/src/core/forms/binding.ts +4 -13
  116. package/src/core/index.ts +10 -0
  117. package/src/core/local-style.ts +27 -0
  118. package/src/core/migrate/index.ts +9 -4
  119. package/src/core/nesting.ts +4 -23
  120. package/src/core/perf/scripts.ts +9 -6
  121. package/src/core/record.ts +3 -0
  122. package/src/core/render/context.ts +2 -0
  123. package/src/core/render/dynamic-post.ts +22 -7
  124. package/src/core/render/form.ts +145 -15
  125. package/src/core/render/index.ts +195 -14
  126. package/src/core/render/pagination.ts +21 -2
  127. package/src/core/render/vnode.ts +12 -2
  128. package/src/core/sanitize/css.ts +90 -77
  129. package/src/core/sanitize/embed-url.ts +7 -1
  130. package/src/core/sanitize/href.ts +13 -1
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/descriptors.ts +4 -1
  134. package/src/core/schema/design.ts +5 -7
  135. package/src/core/schema/layout.ts +160 -181
  136. package/src/core/schema/style.ts +53 -63
  137. package/src/core/share/link.ts +72 -29
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +205 -39
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/tree-ops.ts +57 -0
  142. package/src/index.ts +14 -2
  143. package/src/mcp/errors.ts +44 -0
  144. package/src/mcp/index.ts +4 -0
  145. package/src/mcp/ports.ts +78 -0
  146. package/src/mcp/prompts.ts +76 -0
  147. package/src/mcp/publish.ts +60 -0
  148. package/src/mcp/queue.ts +19 -0
  149. package/src/mcp/rate-limit.ts +80 -0
  150. package/src/mcp/read.ts +419 -0
  151. package/src/mcp/refs.ts +84 -0
  152. package/src/mcp/settings.ts +18 -0
  153. package/src/mcp/tools.ts +265 -0
  154. package/src/mcp/write.ts +582 -0
  155. package/src/server/agent-settings.ts +134 -0
  156. package/src/server/design-routes.ts +75 -18
  157. package/src/server/icon-routes.ts +72 -16
  158. package/src/server/mcp-routes.ts +265 -0
  159. package/src/server/plugin.ts +40 -4
  160. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  161. package/src/admin/editor/icons/sets/lucide.json +0 -1
  162. package/src/admin/editor/icons/sets/remix.json +0 -1
  163. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -1,13 +1,16 @@
1
1
  import { variantShows } from "../audience/variants.ts";
2
2
  import { audienceShows, audienceSummary } from "../audience/rules.ts";
3
3
  import { generateCss } from "../css/generate.ts";
4
- import { cssScopeToken, scopeAttribute, scopeCss, scopeWrapperCss } from "../css/scope.ts";
4
+ import { printCss } from "../css/print.ts";
5
+ import { cssScopeToken, scopeClassName, scopeCss, scopeWrapperCss } from "../css/scope.ts";
5
6
  import { ELEMENTS } from "../elements/index.ts";
6
7
  import { controlId } from "../elements/field-id.ts";
7
8
  import { layoutHasForm } from "../forms/binding.ts";
9
+ import { forEachNode, someNode } from "../tree-ops.ts";
8
10
  import { layoutHasMenuDropdown, layoutHasTabs } from "../tabs/presence.ts";
9
11
  import type { DesignSystem } from "../schema/design.ts";
10
12
  import {
13
+ FORM_FIELD_TYPES,
11
14
  isFormNode,
12
15
  isLoopNode,
13
16
  isParentNode,
@@ -73,6 +76,32 @@ export type RenderResult = {
73
76
  const ID = /^[A-Za-z0-9_-]{4,24}$/;
74
77
  const HTML_ID = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
75
78
 
79
+ /** A focal-point percentage, or the fallback when that axis is unset. Anything else is dropped. */
80
+ function focalPercent(value: unknown, fallback: number): number | undefined {
81
+ if (value === undefined) return fallback;
82
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 100) {
83
+ return undefined;
84
+ }
85
+ return value;
86
+ }
87
+
88
+ /** `object-position` only when both axes are whole percentages. A string here would break the sheet. */
89
+ function objectPosition(x: unknown, y: unknown): string | undefined {
90
+ if (x === undefined && y === undefined) return undefined;
91
+ const px = focalPercent(x, 50);
92
+ const py = focalPercent(y, 50);
93
+ if (px === undefined || py === undefined) return undefined;
94
+ return `${px}% ${py}%`;
95
+ }
96
+
97
+ /** `@container (min-width)` only for a whole pixel width in the schema's range. */
98
+ function containerQueryMin(value: unknown): number | undefined {
99
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 3840) {
100
+ return undefined;
101
+ }
102
+ return value;
103
+ }
104
+
76
105
  // Canvas iframe has no allow-scripts (D-011): live YouTube/Vimeo players fail there.
77
106
  function videoPreview(node: LayoutNode, attrs: Record<string, string>): VNode | undefined {
78
107
  const target = resolveEmbedUrl((node.props as { url: string }).url);
@@ -101,6 +130,23 @@ const gridTracks = (columns: unknown): Declaration[] =>
101
130
  ? [{ property: "grid-template-columns", value: `repeat(${columns}, minmax(0, 1fr))` }]
102
131
  : [];
103
132
 
133
+ const GRID_TRACK =
134
+ /^(?:1fr|2fr|3fr|auto|min-content|max-content|0|(?:\d+(?:\.\d+)?)(?:px|rem|em|%|vw|vh|ch))$/;
135
+
136
+ /** Custom tracks replace equal columns when every track is in the allowlist. */
137
+ const customTracks = (value: unknown): string | undefined => {
138
+ if (!Array.isArray(value) || value.length < 1 || value.length > 12) return undefined;
139
+ if (!value.every((track) => typeof track === "string" && GRID_TRACK.test(track)))
140
+ return undefined;
141
+ return value.join(" ");
142
+ };
143
+
144
+ const gridTemplate = (tracks: unknown, columns: unknown): Declaration[] => {
145
+ const custom = customTracks(tracks);
146
+ if (custom) return [{ property: "grid-template-columns", value: custom }];
147
+ return gridTracks(columns);
148
+ };
149
+
104
150
  /** A node with at least one child; tolerant of a malformed node without a children array. */
105
151
  const hasChildren = (node: LayoutNode): boolean => {
106
152
  const children: unknown = (node as { children?: unknown }).children;
@@ -118,7 +164,7 @@ function originHash(origin: string): string {
118
164
  }
119
165
 
120
166
  /** Form fields whose control carries an `emvb-field-<id>` HTML id (W-187). */
121
- const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
167
+ const FIELD_TYPES = new Set<string>(FORM_FIELD_TYPES.filter((type) => type !== "submit"));
122
168
 
123
169
  const ID_ATTRS = ["id", "for", "aria-controls", "aria-labelledby", "aria-describedby"] as const;
124
170
 
@@ -168,7 +214,17 @@ export function renderPage(
168
214
  tablet?: Declaration[];
169
215
  mobile?: Declaration[];
170
216
  hiddenOn?: LayoutNode["hiddenOn"];
217
+ query?: Declaration[];
218
+ queryMin?: number;
171
219
  }[] = [];
220
+ const layoutHasToc = treeHasType(layout.root, "toc");
221
+ // W-384: a table of contents lists the page's headings that actually render, with their
222
+ // rendered text, so a hidden A/B arm or audience heading is not a dead link.
223
+ const pageHeadings = layoutHasToc
224
+ ? new Set(headingAnchors(layout.root).map((h) => h.node))
225
+ : undefined;
226
+ const renderedHeadings: { id: string; text: string }[] = [];
227
+ const tocNodes: { node: LayoutNode; vnode: VNode }[] = [];
172
228
  const knownVariables = new Set(design.variables.colors.map((c) => c.id));
173
229
  let backgroundVideo = false;
174
230
 
@@ -253,12 +309,37 @@ export function renderPage(
253
309
  declarations.push({ property: "--emvb-loop-columns", value: String(columns) });
254
310
  }
255
311
  }
312
+ if (node.container) declarations.push({ property: "container-type", value: "inline-size" });
313
+ if (node.type === "image") {
314
+ const focal = node.props as { focalX?: unknown; focalY?: unknown };
315
+ const position = objectPosition(focal.focalX, focal.focalY);
316
+ if (position) {
317
+ declarations.push({ property: "object-position", value: position });
318
+ declarations.push({ property: "object-fit", value: "cover" });
319
+ }
320
+ }
321
+ if (node.type === "button") {
322
+ const gap = (node.props as { iconGap?: unknown }).iconGap;
323
+ if (typeof gap === "number" && Number.isInteger(gap) && gap >= 0 && gap <= 64) {
324
+ declarations.push({ property: "gap", value: `${gap}px` });
325
+ }
326
+ }
327
+ const queryStyle = node.query ? styleDeclarations(node.query.style) : undefined;
328
+ for (const key of queryStyle?.rejected ?? []) {
329
+ warnings.push({ nodeId, code: "rejected-style", detail: key });
330
+ }
256
331
  if (node.type === "grid") {
257
332
  const props = (node as { props: Record<string, unknown> }).props;
258
- declarations.push(...gridTracks(props["columns"]));
259
- // Tablet and mobile counts go in their media queries (W-139).
260
- tablet.declarations.unshift(...gridTracks(props["columnsTablet"]));
261
- mobile.declarations.unshift(...gridTracks(props["columnsMobile"]));
333
+ declarations.push(...gridTemplate(props["columnTracks"], props["columns"]));
334
+ // Tablet and mobile counts go in their media queries (W-139). Custom tracks replace them.
335
+ const tabletColumns = gridTemplate(props["columnTracksTablet"], props["columnsTablet"]);
336
+ const mobileColumns = gridTemplate(props["columnTracksMobile"], props["columnsMobile"]);
337
+ if (props["columnTracksTablet"] !== undefined || props["columnsTablet"] !== undefined) {
338
+ tablet.declarations.unshift(...tabletColumns);
339
+ }
340
+ if (props["columnTracksMobile"] !== undefined || props["columnsMobile"] !== undefined) {
341
+ mobile.declarations.unshift(...mobileColumns);
342
+ }
262
343
  }
263
344
  const states = stateDeclarations(node.states);
264
345
  for (const key of states.rejected) {
@@ -274,9 +355,14 @@ export function renderPage(
274
355
  tablet.declarations.length > 0 ||
275
356
  mobile.declarations.length > 0 ||
276
357
  (hiddenOn?.length ?? 0) > 0;
358
+ const queryDeclarations = queryStyle?.declarations ?? [];
359
+ const queryMin = containerQueryMin(node.query?.min);
277
360
  if (
278
361
  ruleId &&
279
- (declarations.length > 0 || Object.keys(states.states).length > 0 || responsive)
362
+ (declarations.length > 0 ||
363
+ Object.keys(states.states).length > 0 ||
364
+ responsive ||
365
+ (queryDeclarations.length > 0 && queryMin !== undefined))
280
366
  ) {
281
367
  classes.push(`emvb-e-${ruleId}`);
282
368
  localRules.push({
@@ -286,13 +372,22 @@ export function renderPage(
286
372
  tablet: tablet.declarations,
287
373
  mobile: mobile.declarations,
288
374
  hiddenOn,
375
+ ...(node.type === "image" &&
376
+ String((node.props as { caption?: unknown }).caption ?? "").trim() !== ""
377
+ ? { figure: true }
378
+ : {}),
379
+ ...(queryDeclarations.length > 0 && queryMin !== undefined
380
+ ? { query: queryDeclarations, queryMin }
381
+ : {}),
289
382
  });
290
383
  }
291
384
  const attrs: Record<string, string> = { class: classes.join(" "), ...customAttributes(node) };
292
385
  if (mode === "editor" && id) attrs["data-emvb-id"] = id;
293
386
  if (node.htmlId && HTML_ID.test(node.htmlId)) attrs.id = node.htmlId;
387
+ else if (node.type === "heading" && id && layoutHasToc) attrs.id = `emvb-h-${id}`;
294
388
  // W-230: the site's text direction on the root, also a fallback when the host's <html> has none.
295
- if (isRoot && design.direction) attrs.dir = design.direction;
389
+ if (node.dir === "ltr" || node.dir === "rtl" || node.dir === "auto") attrs.dir = node.dir;
390
+ else if (isRoot && design.direction) attrs.dir = design.direction;
296
391
  return attrs;
297
392
  };
298
393
 
@@ -342,10 +437,32 @@ export function renderPage(
342
437
  if (isDynamicPostNode(node)) {
343
438
  return finish(
344
439
  node,
345
- renderDynamicPost(node, attrs, resolvePostForRender(dynamic, mode), mode),
440
+ renderDynamicPost(
441
+ node,
442
+ attrs,
443
+ resolvePostForRender(dynamic, mode),
444
+ mode,
445
+ dynamic?.inLoopItem === true,
446
+ ),
346
447
  );
347
448
  }
348
449
  if (isTabsNode(node)) return finish(node, renderTabs(node, id, attrs, ctx, dynamic));
450
+ if (node.type === "toc") {
451
+ const built = def.build(node as never, attrs, []);
452
+ const vnode = { ...built, children: [] as (VNode | string)[] };
453
+ tocNodes.push({ node, vnode });
454
+ return finish(node, vnode);
455
+ }
456
+ if (node.type === "heading" && pageHeadings?.has(stored) && attrs.id) {
457
+ const text = String((node.props as { text?: unknown }).text ?? "").trim();
458
+ // W-409: a heading hidden on every device has nothing to jump to.
459
+ const hiddenEverywhere = (["desktop", "tablet", "mobile"] as const).every((device) =>
460
+ node.hiddenOn?.includes(device),
461
+ );
462
+ if (text && !hiddenEverywhere && !renderedHeadings.some((h) => h.id === attrs.id)) {
463
+ renderedHeadings.push({ id: attrs.id, text });
464
+ }
465
+ }
349
466
  if (isParentNode(node)) {
350
467
  return finish(node, def.build(node as never, attrs, ctx.children(node.children, dynamic)));
351
468
  }
@@ -353,7 +470,12 @@ export function renderPage(
353
470
  const preview = videoPreview(node, attrs);
354
471
  if (preview) return finish(node, preview);
355
472
  }
356
- const built = withFieldOptions(def.build(node as never, attrs, []), node, ctx.definitions);
473
+ const built = withFieldOptions(
474
+ def.build(node as never, attrs, []),
475
+ node,
476
+ ctx.definitions,
477
+ ctx.formId,
478
+ );
357
479
  return finish(node, FIELD_TYPES.has(type) && id ? uniqueField(built, controlId(id)) : built);
358
480
  }
359
481
 
@@ -389,13 +511,22 @@ export function renderPage(
389
511
  };
390
512
  }
391
513
 
392
- const vnode = visit(layout.root, true) ?? {
514
+ const page = visit(layout.root, true) ?? {
393
515
  tag: "div",
394
516
  attrs: { class: "emvb-root" },
395
517
  children: [],
396
518
  };
519
+ for (const toc of tocNodes) {
520
+ toc.vnode.children = tocChildren(toc.node, renderedHeadings, mode);
521
+ // W-430: with no headings the public page had an empty "Table of contents" navigation
522
+ // landmark (or just its title). It's left as a plain empty box instead.
523
+ if (mode !== "editor" && renderedHeadings.length === 0) {
524
+ toc.vnode.tag = "div";
525
+ delete toc.vnode.attrs["aria-label"];
526
+ toc.vnode.children = [];
527
+ }
528
+ }
397
529
  const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
398
- const html = serialize(vnode);
399
530
  const css = generateCss({
400
531
  design,
401
532
  usedTypes,
@@ -406,10 +537,14 @@ export function renderPage(
406
537
  ...(mode === "editor" && opts.previewDevice ? { previewDevice: opts.previewDevice } : {}),
407
538
  });
408
539
  const scope = opts.scope === undefined ? undefined : cssScopeToken(opts.scope);
540
+ const vnode = scope
541
+ ? { tag: "div", attrs: { class: scopeClassName(scope) }, children: [page] }
542
+ : page;
543
+ const html = serialize(vnode);
409
544
  return {
410
545
  vnode,
411
- html: scope ? `<div ${scopeAttribute(scope)}>${html}</div>` : html,
412
- css: scope ? scopeWrapperCss() + scopeCss(css, scope) : css,
546
+ html,
547
+ css: (scope ? scopeWrapperCss() + scopeCss(css, scope) : css) + printCss(),
413
548
  needsFormsRuntime: rendered.form || layoutHasForm(layout),
414
549
  needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
415
550
  needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
@@ -417,3 +552,49 @@ export function renderPage(
417
552
  warnings,
418
553
  };
419
554
  }
555
+
556
+ function treeHasType(node: LayoutNode, type: string): boolean {
557
+ return someNode(node, (current) => current.type === type);
558
+ }
559
+
560
+ /** The page's own heading nodes (not synced section or loop item contents). */
561
+ function headingAnchors(root: LayoutNode): { node: LayoutNode }[] {
562
+ const out: { node: LayoutNode }[] = [];
563
+ forEachNode(root, (node) => {
564
+ if (node.type === "heading") out.push({ node });
565
+ });
566
+ return out;
567
+ }
568
+
569
+ function tocChildren(
570
+ node: LayoutNode,
571
+ items: { id: string; text: string }[],
572
+ mode: RenderMode,
573
+ ): (VNode | string)[] {
574
+ const title =
575
+ node.type === "toc"
576
+ ? String((node.props as { title?: unknown }).title ?? "").trim() || undefined
577
+ : undefined;
578
+ const children: (VNode | string)[] = [];
579
+ if (title) children.push({ tag: "p", attrs: { class: "emvb-toc-title" }, children: [title] });
580
+ if (items.length === 0) {
581
+ if (mode === "editor") {
582
+ children.push({
583
+ tag: "p",
584
+ attrs: {},
585
+ children: ["Headings on this page appear here."],
586
+ });
587
+ }
588
+ return children;
589
+ }
590
+ children.push({
591
+ tag: "ol",
592
+ attrs: {},
593
+ children: items.map((item) => ({
594
+ tag: "li",
595
+ attrs: {},
596
+ children: [{ tag: "a", attrs: { href: `#${item.id}` }, children: [item.text] }],
597
+ })),
598
+ });
599
+ return children;
600
+ }
@@ -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)],
@@ -26,6 +26,8 @@ const TAGS = new Set([
26
26
  "li",
27
27
  "hr",
28
28
  "img",
29
+ "figure",
30
+ "figcaption",
29
31
  "iframe",
30
32
  "video",
31
33
  "form",
@@ -39,6 +41,14 @@ const TAGS = new Set([
39
41
  "details",
40
42
  "summary",
41
43
  "time",
44
+ // Post Content formatting (W-328)
45
+ "strong",
46
+ "em",
47
+ "code",
48
+ "u",
49
+ "s",
50
+ "br",
51
+ "blockquote",
42
52
  // Lucide icon primitives (W-025 / A-04)
43
53
  "svg",
44
54
  "path",
@@ -65,10 +75,10 @@ const TAGS = new Set([
65
75
  "text",
66
76
  "tspan",
67
77
  ]);
68
- const VOID = new Set(["hr", "img", "input"]);
78
+ const VOID = new Set(["hr", "img", "input", "br"]);
69
79
  // iframe/video are not void — they need closing tags.
70
80
  const ATTR_NAME =
71
- /^(?:class|id|href|src|alt|width|height|loading|decoding|fetchpriority|dir|role|type|checked|target|rel|aria-[a-z][a-z0-9-]*|title|allow|referrerpolicy|preload|controls|allowfullscreen|xmlns|viewBox|fill|stroke|stroke-width|stroke-linecap|stroke-linejoin|stroke-dasharray|stroke-opacity|fill-opacity|opacity|transform|focusable|d|cx|cy|r|x|y|x1|y1|x2|y2|points|rx|ry|xlink:href|preserveAspectRatio|gradientUnits|gradientTransform|offset|stop-color|stop-opacity|clipPathUnits|maskUnits|maskContentUnits|patternUnits|patternContentUnits|patternTransform|markerUnits|markerWidth|markerHeight|refX|refY|orient|font-size|font-family|font-weight|text-anchor|dominant-baseline|dx|dy|clip-path|method|action|name|value|placeholder|for|tabindex|autocomplete|open|datetime|muted|loop|playsinline|autoplay|required|novalidate|minlength|maxlength|min|max|pattern|data-[a-z][a-z0-9-]*)$/;
81
+ /^(?:class|id|href|src|srcset|sizes|alt|width|height|loading|decoding|fetchpriority|dir|role|type|checked|target|rel|aria-[a-z][a-z0-9-]*|title|allow|referrerpolicy|preload|controls|allowfullscreen|sandbox|xmlns|viewBox|fill|stroke|stroke-width|stroke-linecap|stroke-linejoin|stroke-dasharray|stroke-opacity|fill-opacity|opacity|transform|focusable|d|cx|cy|r|x|y|x1|y1|x2|y2|points|rx|ry|xlink:href|preserveAspectRatio|gradientUnits|gradientTransform|offset|stop-color|stop-opacity|clipPathUnits|maskUnits|maskContentUnits|patternUnits|patternContentUnits|patternTransform|markerUnits|markerWidth|markerHeight|refX|refY|orient|font-size|font-family|font-weight|text-anchor|dominant-baseline|dx|dy|clip-path|method|action|name|value|placeholder|for|tabindex|autocomplete|open|datetime|muted|loop|playsinline|autoplay|required|novalidate|minlength|maxlength|min|max|pattern|data-[a-z][a-z0-9-]*)$/;
72
82
 
73
83
  export const isAllowedTag = (tag: string) => TAGS.has(tag);
74
84
  export const isAllowedAttr = (name: string) => ATTR_NAME.test(name);
@@ -1,53 +1,46 @@
1
+ import {
2
+ ALIGN_ITEMS,
3
+ BACKGROUND_POSITIONS,
4
+ BACKGROUND_REPEATS,
5
+ BACKGROUND_SIZES,
6
+ BORDER_STYLES,
7
+ CURSORS,
8
+ FLEX_DIRECTIONS as FLEX_DIRECTION_VALUES,
9
+ FLEX_WRAPS as FLEX_WRAP_VALUES,
10
+ FONT_WEIGHTS,
11
+ HEX_COLOR,
12
+ JUSTIFY_CONTENT,
13
+ LENGTH_UNITS,
14
+ OBJECT_FITS,
15
+ OVERFLOWS,
16
+ POSITIONS,
17
+ TEXT_ALIGNS,
18
+ TEXT_DECORATIONS,
19
+ TEXT_TRANSFORMS,
20
+ TRANSITION_EASINGS as TRANSITION_EASING_VALUES,
21
+ } from "../css-keywords.ts";
1
22
  import { STYLE_STATES, type StyleStateName } from "../schema/state-names.ts";
2
23
  import type { StyleProps } from "../schema/style.ts";
3
24
  import { sanitizeMediaUrl } from "./media-url.ts";
4
25
  import { motionDeclarations, withMotion } from "./motion.ts";
26
+ import { isRecord } from "../record.ts";
5
27
 
6
- const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
28
+ const setOf = (values: readonly string[]) => new Set<string>(values);
7
29
  const VAR_ID = /^[a-z0-9-]{1,40}$/;
8
- const UNITS = new Set(["px", "rem", "em", "%", "vw", "vh"]);
9
- const FLEX_DIRECTIONS = new Set(["row", "column", "row-reverse", "column-reverse"]);
10
- const FLEX_WRAPS = new Set(["nowrap", "wrap", "wrap-reverse"]);
11
- const JUSTIFY = new Set([
12
- "flex-start",
13
- "flex-end",
14
- "center",
15
- "space-between",
16
- "space-around",
17
- "space-evenly",
18
- ]);
19
- const ALIGN = new Set(["stretch", "flex-start", "flex-end", "center", "baseline"]);
20
- const TEXT_TRANSFORM = new Set(["none", "uppercase", "lowercase", "capitalize"]);
21
- const TEXT_DECORATION = new Set(["none", "underline", "overline", "line-through"]);
22
- const BORDER_STYLE = new Set(["none", "solid", "dashed", "dotted"]);
23
- const OVERFLOW = new Set(["visible", "hidden", "clip", "scroll", "auto"]);
24
- const OBJECT_FIT = new Set(["fill", "contain", "cover", "none", "scale-down"]);
25
- const POSITION = new Set(["static", "relative", "absolute", "fixed", "sticky"]);
26
- const CURSOR = new Set([
27
- "default",
28
- "pointer",
29
- "text",
30
- "move",
31
- "grab",
32
- "not-allowed",
33
- "help",
34
- "crosshair",
35
- "zoom-in",
36
- ]);
30
+ const UNITS = setOf(LENGTH_UNITS);
31
+ const FLEX_DIRECTIONS = setOf(FLEX_DIRECTION_VALUES);
32
+ const FLEX_WRAPS = setOf(FLEX_WRAP_VALUES);
33
+ const JUSTIFY = setOf(JUSTIFY_CONTENT);
34
+ const ALIGN = setOf(ALIGN_ITEMS);
35
+ const TEXT_TRANSFORM = setOf(TEXT_TRANSFORMS);
36
+ const TEXT_DECORATION = setOf(TEXT_DECORATIONS);
37
+ const BORDER_STYLE = setOf(BORDER_STYLES);
38
+ const OVERFLOW = setOf(OVERFLOWS);
39
+ const OBJECT_FIT = setOf(OBJECT_FITS);
40
+ const POSITION = setOf(POSITIONS);
41
+ const CURSOR = setOf(CURSORS);
37
42
  const ASPECT_RATIO = /^([1-9]\d{0,3})\/([1-9]\d{0,3})$/;
38
- const FONT_WEIGHT = new Set([
39
- "normal",
40
- "bold",
41
- "100",
42
- "200",
43
- "300",
44
- "400",
45
- "500",
46
- "600",
47
- "700",
48
- "800",
49
- "900",
50
- ]);
43
+ const FONT_WEIGHT = setOf(FONT_WEIGHTS);
51
44
  const FORBIDDEN = /[{};<>\\"'`]|\/\*|url\(|expression\(|@import|javascript:/i;
52
45
 
53
46
  /** Last line of defence on every emitted value, even ones built by the typed validators below. */
@@ -192,11 +185,13 @@ function cssEntrance(value: unknown): string | undefined {
192
185
  return `emvb-${type} ${duration}ms ease-out${wait} both`;
193
186
  }
194
187
 
188
+ const TEXT_ALIGN = setOf(TEXT_ALIGNS);
189
+
195
190
  function cssTextAlign(value: unknown): string | undefined {
191
+ if (typeof value !== "string" || !TEXT_ALIGN.has(value)) return undefined;
196
192
  if (value === "left") return "start";
197
193
  if (value === "right") return "end";
198
- if (value === "center" || value === "justify") return value;
199
- return undefined;
194
+ return value;
200
195
  }
201
196
 
202
197
  const cssGridSpan = (value: unknown): string | undefined =>
@@ -204,6 +199,28 @@ const cssGridSpan = (value: unknown): string | undefined =>
204
199
  ? `span ${value}`
205
200
  : undefined;
206
201
 
202
+ const cssGridStart = (value: unknown): number | undefined =>
203
+ Number.isInteger(value) && (value as number) >= 1 && (value as number) <= 13
204
+ ? (value as number)
205
+ : undefined;
206
+
207
+ /** `span N`, a line number, or `start / span N` when both are set. */
208
+ function gridPlacement(
209
+ start: unknown,
210
+ span: unknown,
211
+ ): { value?: string; badStart: boolean; badSpan: boolean } {
212
+ const badStart = start !== undefined && cssGridStart(start) === undefined;
213
+ const badSpan = span !== undefined && cssGridSpan(span) === undefined;
214
+ const line = cssGridStart(start);
215
+ const across = cssGridSpan(span);
216
+ if (line !== undefined && across !== undefined) {
217
+ return { value: `${line} / ${across}`, badStart, badSpan };
218
+ }
219
+ if (line !== undefined) return { value: String(line), badStart, badSpan };
220
+ if (across !== undefined) return { value: across, badStart, badSpan };
221
+ return { badStart, badSpan };
222
+ }
223
+
207
224
  const inRange = (value: unknown, min: number, max: number): value is number =>
208
225
  typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
209
226
 
@@ -283,7 +300,7 @@ function cssFontWeight(value: unknown): string | undefined {
283
300
  return undefined;
284
301
  }
285
302
 
286
- const TRANSITION_EASINGS = new Set(["ease", "ease-in", "ease-out", "ease-in-out", "linear"]);
303
+ const TRANSITION_EASINGS = setOf(TRANSITION_EASING_VALUES);
287
304
  const TRANSITION_PROPERTIES: Readonly<Record<string, readonly string[]>> = {
288
305
  all: ["all"],
289
306
  colors: ["color", "background-color", "border-color"],
@@ -371,19 +388,9 @@ function cssIconAnimation(value: unknown): string | undefined {
371
388
 
372
389
  export type Declaration = { property: string; value: string };
373
390
 
374
- const BACKGROUND_SIZE = new Set(["auto", "cover", "contain"]);
375
- const BACKGROUND_POSITION = new Set([
376
- "center",
377
- "top",
378
- "bottom",
379
- "left",
380
- "right",
381
- "top left",
382
- "top right",
383
- "bottom left",
384
- "bottom right",
385
- ]);
386
- const BACKGROUND_REPEAT = new Set(["no-repeat", "repeat", "repeat-x", "repeat-y"]);
391
+ const BACKGROUND_SIZE = setOf(BACKGROUND_SIZES);
392
+ const BACKGROUND_POSITION = setOf(BACKGROUND_POSITIONS);
393
+ const BACKGROUND_REPEAT = setOf(BACKGROUND_REPEATS);
387
394
  const BACKGROUND_KEYS = new Set([
388
395
  "backgroundImage",
389
396
  "backgroundSize",
@@ -399,9 +406,6 @@ function isSafeBackground(value: string): boolean {
399
406
  return value.length > 0 && value.length <= 4096 && !/[{};<>\\`]|\/\*|\n|\r/.test(value);
400
407
  }
401
408
 
402
- const isRecord = (value: unknown): value is Record<string, unknown> =>
403
- typeof value === "object" && value !== null && !Array.isArray(value);
404
-
405
409
  /** A media URL wrapped for CSS. The schema already refuses quotes, spaces and parentheses. */
406
410
  function cssBackgroundImage(value: unknown): string | undefined {
407
411
  if (typeof value !== "string") return undefined;
@@ -410,17 +414,7 @@ function cssBackgroundImage(value: unknown): string | undefined {
410
414
  return isSafeBackground(css) ? css : undefined;
411
415
  }
412
416
 
413
- const GRADIENT_POSITION = new Set([
414
- "center",
415
- "top",
416
- "bottom",
417
- "left",
418
- "right",
419
- "top left",
420
- "top right",
421
- "bottom left",
422
- "bottom right",
423
- ]);
417
+ const GRADIENT_POSITION = setOf(BACKGROUND_POSITIONS);
424
418
 
425
419
  function cssAngle(value: unknown, fallback: number): number | undefined {
426
420
  const angle = value === undefined ? fallback : value;
@@ -588,6 +582,9 @@ const PROPERTY_MAP: {
588
582
  gap: { css: "gap", toValue: cssLength },
589
583
  gridColumnSpan: { css: "grid-column", toValue: cssGridSpan },
590
584
  gridRowSpan: { css: "grid-row", toValue: cssGridSpan },
585
+ // Composed with the span in `styleDeclarations` (`start / span n`).
586
+ gridColumnStart: { css: "grid-column", toValue: () => undefined },
587
+ gridRowStart: { css: "grid-row", toValue: () => undefined },
591
588
  width: { css: "width", toValue: cssLengthOrAuto },
592
589
  minWidth: { css: "min-width", toValue: cssLength },
593
590
  maxWidth: { css: "max-width", toValue: cssLength },
@@ -601,10 +598,10 @@ const PROPERTY_MAP: {
601
598
  paddingRight: { css: "padding-inline-end", toValue: cssLength },
602
599
  paddingBottom: { css: "padding-bottom", toValue: cssLength },
603
600
  paddingLeft: { css: "padding-inline-start", toValue: cssLength },
604
- marginTop: { css: "margin-top", toValue: cssLengthOrAuto },
605
- marginRight: { css: "margin-inline-end", toValue: cssLengthOrAuto },
606
- marginBottom: { css: "margin-bottom", toValue: cssLengthOrAuto },
607
- marginLeft: { css: "margin-inline-start", toValue: cssLengthOrAuto },
601
+ marginTop: { css: "margin-top", toValue: cssOffset },
602
+ marginRight: { css: "margin-inline-end", toValue: cssOffset },
603
+ marginBottom: { css: "margin-bottom", toValue: cssOffset },
604
+ marginLeft: { css: "margin-inline-start", toValue: cssOffset },
608
605
  position: { css: "position", toValue: keyword(POSITION) },
609
606
  top: { css: "top", toValue: cssOffset },
610
607
  right: { css: "inset-inline-end", toValue: cssOffset },
@@ -683,6 +680,14 @@ export function styleDeclarations(style: unknown): {
683
680
  let motion: Declaration[] = [];
684
681
  for (const [key, raw] of shorthandsFirst(record)) {
685
682
  if (BACKGROUND_KEYS.has(key)) continue;
683
+ if (
684
+ key === "gridColumnSpan" ||
685
+ key === "gridRowSpan" ||
686
+ key === "gridColumnStart" ||
687
+ key === "gridRowStart"
688
+ ) {
689
+ continue;
690
+ }
686
691
  if (key === "scrollMotion") {
687
692
  const found = motionDeclarations(raw);
688
693
  if (found && found.every((d) => isSafeCssValue(d.value))) motion = found;
@@ -714,6 +719,14 @@ export function styleDeclarations(style: unknown): {
714
719
  const background = composeBackground(record);
715
720
  declarations.push(...background.declarations);
716
721
  rejected.push(...background.rejected);
722
+ const column = gridPlacement(record["gridColumnStart"], record["gridColumnSpan"]);
723
+ const row = gridPlacement(record["gridRowStart"], record["gridRowSpan"]);
724
+ if (column.value) declarations.push({ property: "grid-column", value: column.value });
725
+ if (row.value) declarations.push({ property: "grid-row", value: row.value });
726
+ if (column.badStart) rejected.push("gridColumnStart");
727
+ if (column.badSpan) rejected.push("gridColumnSpan");
728
+ if (row.badStart) rejected.push("gridRowStart");
729
+ if (row.badSpan) rejected.push("gridRowSpan");
717
730
  return { declarations: withMotion(declarations, motion), rejected };
718
731
  }
719
732
 
@@ -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);