@perkyzz/emvb 0.6.0 → 0.7.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 (183) hide show
  1. package/package.json +1 -1
  2. package/src/admin/access/RequireEditor.tsx +7 -7
  3. package/src/admin/access/role.ts +5 -2
  4. package/src/admin/content-api.ts +10 -3
  5. package/src/admin/content-item.ts +1 -1
  6. package/src/admin/editor/A11yCopilot.tsx +104 -56
  7. package/src/admin/editor/CommandPalette.tsx +29 -13
  8. package/src/admin/editor/Editor.tsx +82 -20
  9. package/src/admin/editor/EditorToasts.tsx +26 -0
  10. package/src/admin/editor/PerfMeter.tsx +97 -72
  11. package/src/admin/editor/ShareLink.tsx +107 -72
  12. package/src/admin/editor/ShortcutsDialog.tsx +27 -16
  13. package/src/admin/editor/Timeline.tsx +255 -160
  14. package/src/admin/editor/TopBar.tsx +71 -14
  15. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  16. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  17. package/src/admin/editor/canvas/drop-line.ts +11 -3
  18. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  19. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  20. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  21. package/src/admin/editor/collection-previews.ts +10 -0
  22. package/src/admin/editor/dialogs.tsx +38 -14
  23. package/src/admin/editor/dnd/drop-target.ts +26 -1
  24. package/src/admin/editor/edited-noun.ts +15 -0
  25. package/src/admin/editor/editor-chrome.tsx +59 -7
  26. package/src/admin/editor/editor-commands.ts +2 -1
  27. package/src/admin/editor/editor-css.ts +72 -22
  28. package/src/admin/editor/element-chrome.ts +21 -11
  29. package/src/admin/editor/feature-css.ts +45 -13
  30. package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
  31. package/src/admin/editor/icons/library.ts +1 -1
  32. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  33. package/src/admin/editor/ime.ts +29 -0
  34. package/src/admin/editor/palette-items.ts +10 -3
  35. package/src/admin/editor/panels/AddPanel.tsx +35 -10
  36. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  37. package/src/admin/editor/panels/ColorControl.tsx +130 -23
  38. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  39. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  40. package/src/admin/editor/panels/LayersPanel.tsx +55 -19
  41. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  42. package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
  43. package/src/admin/editor/panels/TokenScales.tsx +76 -36
  44. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  45. package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
  46. package/src/admin/editor/panels/VariableSection.tsx +48 -18
  47. package/src/admin/editor/panels/color-space.ts +9 -3
  48. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  49. package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
  50. package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
  51. package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
  52. package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
  53. package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
  54. package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
  55. package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
  56. package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
  57. package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
  58. package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
  59. package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
  60. package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
  61. package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
  62. package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
  63. package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
  64. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
  65. package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
  66. package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
  67. package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
  68. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  69. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  70. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  71. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  72. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
  73. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  74. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  75. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  76. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  77. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  78. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  79. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  80. package/src/admin/editor/panels/site-list.tsx +20 -6
  81. package/src/admin/editor/panels/variable-values.ts +11 -4
  82. package/src/admin/editor/restore-deleted.ts +21 -2
  83. package/src/admin/editor/section-templates.ts +81 -12
  84. package/src/admin/editor/shortcuts.ts +17 -2
  85. package/src/admin/editor/store.ts +7 -0
  86. package/src/admin/editor/useEditorCommands.ts +61 -15
  87. package/src/admin/editor/useEditorData.ts +4 -2
  88. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  89. package/src/admin/editor/useNodeActions.ts +61 -6
  90. package/src/admin/editor/useSave.ts +22 -7
  91. package/src/admin/forms-api.ts +2 -0
  92. package/src/admin/image-editor/CurvesPanel.tsx +2 -1
  93. package/src/admin/image-editor/ExportDialog.tsx +48 -18
  94. package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
  95. package/src/admin/image-editor/MetadataPanel.tsx +15 -4
  96. package/src/admin/image-editor/crop-geometry.ts +3 -2
  97. package/src/admin/image-editor/image-editor-css.ts +4 -2
  98. package/src/admin/image-editor/load.ts +9 -2
  99. package/src/admin/image-editor/parts.tsx +51 -2
  100. package/src/admin/image-editor/save.ts +23 -7
  101. package/src/admin/media-api.ts +2 -1
  102. package/src/admin/pages/AgentsPage.tsx +138 -27
  103. package/src/admin/pages/CreateDialog.tsx +97 -30
  104. package/src/admin/pages/NewPageDialog.tsx +21 -3
  105. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  106. package/src/admin/pages/PageList.tsx +14 -6
  107. package/src/admin/pages/SetupShell.tsx +28 -12
  108. package/src/admin/pages/ThemePartList.tsx +27 -7
  109. package/src/admin/pages/list-kit.tsx +106 -24
  110. package/src/admin/search.ts +15 -0
  111. package/src/admin/setup/useSetupStatus.ts +1 -1
  112. package/src/admin/theme-api.ts +13 -3
  113. package/src/admin/ui.ts +73 -22
  114. package/src/astro/floats/runtime.ts +21 -0
  115. package/src/astro/menu/runtime.ts +34 -1
  116. package/src/astro/popups/runtime.ts +33 -3
  117. package/src/astro/render.ts +3 -0
  118. package/src/astro/resolve-theme.ts +53 -11
  119. package/src/astro/resolve.ts +9 -1
  120. package/src/astro/tabs/runtime.ts +12 -0
  121. package/src/astro/theme-posts.ts +2 -2
  122. package/src/astro/visitor.ts +2 -0
  123. package/src/constants.ts +1 -1
  124. package/src/core/a11y/audit.ts +171 -24
  125. package/src/core/arrange.ts +27 -6
  126. package/src/core/audience/rules.ts +5 -1
  127. package/src/core/audience/variants.ts +29 -3
  128. package/src/core/clipboard.ts +7 -0
  129. package/src/core/css/generate.ts +31 -6
  130. package/src/core/data/bindings.ts +8 -1
  131. package/src/core/design/classes.ts +16 -7
  132. package/src/core/design/diff.ts +6 -0
  133. package/src/core/design/merge.ts +90 -2
  134. package/src/core/design/tokens.ts +16 -2
  135. package/src/core/design/transfer.ts +33 -6
  136. package/src/core/design/variables.ts +30 -9
  137. package/src/core/elements/dynamic-elements.ts +44 -5
  138. package/src/core/elements/form-elements.ts +55 -16
  139. package/src/core/elements/index.ts +83 -38
  140. package/src/core/elements/menu.ts +37 -19
  141. package/src/core/elements/select-prompt.ts +3 -0
  142. package/src/core/elements/svg-ids.ts +39 -0
  143. package/src/core/forms/binding.ts +57 -16
  144. package/src/core/forms/definition.ts +72 -0
  145. package/src/core/history/diff.ts +18 -1
  146. package/src/core/icons/catalog.ts +3 -2
  147. package/src/core/image-edit/schema.ts +11 -1
  148. package/src/core/image-edit/summary.ts +6 -3
  149. package/src/core/index.ts +15 -1
  150. package/src/core/limits.ts +12 -1
  151. package/src/core/perf/meter.ts +42 -7
  152. package/src/core/recipes/index.ts +5 -4
  153. package/src/core/render/context.ts +8 -0
  154. package/src/core/render/dynamic-post.ts +69 -12
  155. package/src/core/render/extras.ts +77 -4
  156. package/src/core/render/form.ts +140 -6
  157. package/src/core/render/index.ts +156 -20
  158. package/src/core/render/loop.ts +43 -7
  159. package/src/core/render/pagination.ts +18 -4
  160. package/src/core/render/section.ts +27 -0
  161. package/src/core/render/tabs.ts +12 -3
  162. package/src/core/render/vnode.ts +1 -1
  163. package/src/core/sanitize/css.ts +15 -2
  164. package/src/core/sanitize/embed-url.ts +42 -5
  165. package/src/core/sanitize/url.ts +2 -1
  166. package/src/core/schema/layout.ts +15 -6
  167. package/src/core/stats.ts +2 -1
  168. package/src/core/theme/conditions.ts +3 -1
  169. package/src/core/theme/dynamic.ts +36 -5
  170. package/src/core/theme/float.ts +9 -2
  171. package/src/core/theme/pagination.ts +31 -11
  172. package/src/core/theme/popup-markup.ts +23 -5
  173. package/src/core/theme/popup-rules.ts +1 -0
  174. package/src/core/theme/triggers.ts +3 -2
  175. package/src/core/tree-ops.ts +27 -0
  176. package/src/mcp/rate-limit.ts +2 -1
  177. package/src/mcp/read.ts +14 -2
  178. package/src/mcp/refs.ts +18 -0
  179. package/src/mcp/write.ts +174 -10
  180. package/src/server/agent-settings.ts +1 -1
  181. package/src/server/hooks.ts +5 -3
  182. package/src/server/icon-routes.ts +30 -9
  183. package/src/server/mcp-routes.ts +6 -1
@@ -1,4 +1,5 @@
1
- import { variantShows } from "../audience/variants.ts";
1
+ import { MAX_NODES } from "../limits.ts";
2
+ import { loneAbTests, variantShows } from "../audience/variants.ts";
2
3
  import { audienceShows, audienceSummary } from "../audience/rules.ts";
3
4
  import { generateCss } from "../css/generate.ts";
4
5
  import { printCss } from "../css/print.ts";
@@ -25,7 +26,6 @@ import {
25
26
  stateDeclarations,
26
27
  styleClassName,
27
28
  styleDeclarations,
28
- withInheritedAnimation,
29
29
  withInheritedLayers,
30
30
  type Declaration,
31
31
  type StateDeclarations,
@@ -190,6 +190,9 @@ function renameIds(vnode: VNode, base: string, next: string): VNode {
190
190
  };
191
191
  }
192
192
 
193
+ /** Elements synced sections may add to one render, all copies together (W-653): 20 full pages. */
194
+ const MAX_SECTION_ELEMENTS = 20 * MAX_NODES;
195
+
193
196
  export function renderPage(
194
197
  layout: Layout,
195
198
  design: DesignSystem,
@@ -207,6 +210,8 @@ export function renderPage(
207
210
  * the page's field. Their generated ids get a suffix from `scope` (W-527).
208
211
  */
209
212
  partIds?: boolean;
213
+ /** The page's language, e.g. "fr-CA": Post Dates are written in it (W-688). */
214
+ lang?: string;
210
215
  } = {},
211
216
  ): RenderResult {
212
217
  const mode = opts.mode ?? "public";
@@ -224,12 +229,22 @@ export function renderPage(
224
229
  queryMin?: number;
225
230
  }[] = [];
226
231
  const layoutHasToc = treeHasType(layout.root, "toc");
232
+ // W-799: each grid child's grid, so a span or start line that doesn't fit a device's columns
233
+ // can be clamped there.
234
+ const gridOf = new Map<string, LayoutNode>();
235
+ someNode(layout.root, (current) => {
236
+ if (current.type === "grid")
237
+ for (const child of nodeChildren(current)) gridOf.set(child.id, current);
238
+ return false;
239
+ });
240
+ const loneTests = loneAbTests(layout);
227
241
  // W-384: a table of contents lists the page's headings that actually render, with their
228
242
  // rendered text, so a hidden A/B arm or audience heading is not a dead link.
229
243
  const pageHeadings = layoutHasToc
230
- ? new Set(headingAnchors(layout.root).map((h) => h.node))
244
+ ? new Map(headingAnchors(layout.root).map((h) => [h.node, h.hiddenOn]))
231
245
  : undefined;
232
- const renderedHeadings: { id: string; text: string }[] = [];
246
+ const renderedHeadings: { id: string; text: string; tocClass?: string }[] = [];
247
+ const emittedIds = new Set<string>();
233
248
  const tocNodes: { node: LayoutNode; vnode: VNode }[] = [];
234
249
  const knownVariables = new Set(design.variables.colors.map((c) => c.id));
235
250
  let backgroundVideo = false;
@@ -239,8 +254,15 @@ export function renderPage(
239
254
  // W-253: runtimes follow what renders, including synced section and loop item contents,
240
255
  // which the page's own layout doesn't hold.
241
256
  const rendered = { form: false, tabs: false, menuDropdown: false };
257
+ let sectionBudget = MAX_SECTION_ELEMENTS;
242
258
  const ctx: RenderContext = {
259
+ takeSectionBudget: (nodes) => {
260
+ if (nodes > sectionBudget) return false;
261
+ sectionBudget -= nodes;
262
+ return true;
263
+ },
243
264
  mode,
265
+ ...(opts.lang ? { lang: opts.lang } : {}),
244
266
  definitions: opts.formDefinitions ?? new Map(),
245
267
  children: (nodes, dynamic) =>
246
268
  nodes
@@ -280,12 +302,31 @@ export function renderPage(
280
302
  ...(fromClasses.entrance ? { entrance: fromClasses.entrance } : {}),
281
303
  ...(fromClasses.scrollMotion ? { scrollMotion: fromClasses.scrollMotion } : {}),
282
304
  };
305
+ // W-569: and an own image, gradient or overlay keeps the layers its classes draw, as they
306
+ // share one background-image stack and the local rule would otherwise replace them.
307
+ const classLayers = {
308
+ ...classAnimation,
309
+ ...Object.fromEntries(
310
+ (
311
+ [
312
+ "backgroundImage",
313
+ "gradient",
314
+ "overlay",
315
+ "backgroundSize",
316
+ "backgroundPosition",
317
+ "backgroundRepeat",
318
+ ] as const
319
+ )
320
+ .filter((key) => fromClasses[key] !== undefined)
321
+ .map((key) => [key, fromClasses[key]]),
322
+ ),
323
+ };
283
324
  const own = node.style
284
- ? (withInheritedAnimation(node.style, classAnimation) as typeof node.style)
325
+ ? (withInheritedLayers(node.style, classLayers) as typeof node.style)
285
326
  : undefined;
286
327
  const { declarations, rejected } = styleDeclarations(own);
287
328
  // W-210: a device that sets one background layer keeps the layers it inherits.
288
- const base = { ...classAnimation, ...own };
329
+ const base = { ...classLayers, ...own };
289
330
  const tabletStyle = node.devices?.tablet;
290
331
  const tablet = styleDeclarations(withInheritedLayers(tabletStyle, base));
291
332
  const mobile = styleDeclarations(
@@ -353,6 +394,26 @@ export function renderPage(
353
394
  mobile.declarations.unshift(...mobileColumns);
354
395
  }
355
396
  }
397
+ const grid = gridOf.get(node.id);
398
+ if (grid) {
399
+ const counts = gridColumnCounts(grid);
400
+ const tabletPlacement = { ...node.style, ...node.devices?.tablet };
401
+ const levels = [
402
+ node.style ?? {},
403
+ tabletPlacement,
404
+ { ...tabletPlacement, ...node.devices?.mobile },
405
+ ];
406
+ const fitted = levels.map((style, i) =>
407
+ fitGridColumn(style.gridColumnStart, style.gridColumnSpan, counts[i] ?? 1),
408
+ );
409
+ if (fitted.some((f) => f.changed)) {
410
+ const at = (i: number) => ({ property: "grid-column", value: fitted[i]?.value ?? "auto" });
411
+ const kept = declarations.filter((d) => d.property !== "grid-column");
412
+ declarations.splice(0, declarations.length, ...kept, at(0));
413
+ tablet.declarations.push(at(1));
414
+ mobile.declarations.push(at(2));
415
+ }
416
+ }
356
417
  const states = stateDeclarations(node.states);
357
418
  for (const key of states.rejected) {
358
419
  warnings.push({ nodeId, code: "rejected-style", detail: key });
@@ -362,7 +423,8 @@ export function renderPage(
362
423
  warnings.push({ nodeId, code: "unknown-variable", detail: color.var });
363
424
  }
364
425
  }
365
- const hiddenOn = node.hiddenOn;
426
+ // W-567: the root is the page itself; hiding it on a device blanked the whole page there.
427
+ const hiddenOn = isRoot ? undefined : node.hiddenOn;
366
428
  const responsive =
367
429
  tablet.declarations.length > 0 ||
368
430
  mobile.declarations.length > 0 ||
@@ -395,8 +457,18 @@ export function renderPage(
395
457
  }
396
458
  const attrs: Record<string, string> = { class: classes.join(" "), ...customAttributes(node) };
397
459
  if (mode === "editor" && id) attrs["data-emvb-id"] = id;
398
- if (node.htmlId && HTML_ID.test(node.htmlId)) attrs.id = node.htmlId;
399
- else if (node.type === "heading" && id && layoutHasToc) attrs.id = `emvb-h-${id}`;
460
+ const htmlId =
461
+ node.htmlId && HTML_ID.test(node.htmlId)
462
+ ? node.htmlId
463
+ : node.type === "heading" && id && layoutHasToc
464
+ ? `emvb-h-${id}`
465
+ : undefined;
466
+ // W-649: a Loop renders its item design once per entry; an id repeated on the page is invalid
467
+ // and every Table of contents link or label would point at the first copy only.
468
+ if (htmlId && !emittedIds.has(htmlId)) {
469
+ emittedIds.add(htmlId);
470
+ attrs.id = htmlId;
471
+ }
400
472
  // W-230: the site's text direction on the root, also a fallback when the host's <html> has none.
401
473
  if (node.dir === "ltr" || node.dir === "rtl" || node.dir === "auto") attrs.dir = node.dir;
402
474
  else if (isRoot && design.direction) attrs.dir = design.direction;
@@ -411,7 +483,7 @@ export function renderPage(
411
483
  // W-307: bound fields read their live value; the typed value is the fallback.
412
484
  const node = stored.bind ? applyBindings(stored, bindingData(dynamic)) : stored;
413
485
  // W-312: only the visitor's arm of an A/B test renders; the editor shows every arm.
414
- if (mode === "public" && !variantShows(stored, dynamic?.abArms)) return undefined;
486
+ if (mode === "public" && !variantShows(stored, dynamic?.abArms, loneTests)) return undefined;
415
487
  // W-313: visitor-aware elements render only for their audience; the editor shows them all.
416
488
  if (mode === "public" && !audienceShows(stored, dynamic?.visitor)) return undefined;
417
489
  const id = ID.test(node.id) ? node.id : undefined;
@@ -455,6 +527,7 @@ export function renderPage(
455
527
  resolvePostForRender(dynamic, mode),
456
528
  mode,
457
529
  dynamic?.inLoopItem === true,
530
+ ctx.lang,
458
531
  ),
459
532
  );
460
533
  }
@@ -472,7 +545,18 @@ export function renderPage(
472
545
  node.hiddenOn?.includes(device),
473
546
  );
474
547
  if (text && !hiddenEverywhere && !renderedHeadings.some((h) => h.id === attrs.id)) {
475
- renderedHeadings.push({ id: attrs.id, text });
548
+ // W-793: a heading hidden on some devices (itself or an ancestor) hides its contents
549
+ // entry there too, or the entry was a dead link on those devices.
550
+ const hiddenOn = pageHeadings.get(stored) ?? [];
551
+ const tocId = `toc-${node.id}`;
552
+ if (hiddenOn.length > 0) {
553
+ localRules.push({ id: tocId, declarations: [], states: {}, hiddenOn: [...hiddenOn] });
554
+ }
555
+ renderedHeadings.push({
556
+ id: attrs.id,
557
+ text,
558
+ ...(hiddenOn.length > 0 ? { tocClass: `emvb-e-${tocId}` } : {}),
559
+ });
476
560
  }
477
561
  }
478
562
  if (isParentNode(node)) {
@@ -574,22 +658,74 @@ function treeHasType(node: LayoutNode, type: string): boolean {
574
658
  * inside an element hidden on every device, which never show, so a contents link has nothing
575
659
  * to jump to (W-409 covered only the heading's own visibility).
576
660
  */
577
- function headingAnchors(root: LayoutNode): { node: LayoutNode }[] {
578
- const out: { node: LayoutNode }[] = [];
579
- const walk = (node: LayoutNode) => {
661
+ function headingAnchors(root: LayoutNode): { node: LayoutNode; hiddenOn: PopupDevice[] }[] {
662
+ const out: { node: LayoutNode; hiddenOn: PopupDevice[] }[] = [];
663
+ const walk = (node: LayoutNode, inherited: PopupDevice[]) => {
580
664
  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);
665
+ const own = node === root ? [] : (node.hiddenOn ?? []);
666
+ const hiddenOn = HIDDEN_DEVICES.filter((d) => inherited.includes(d) || own.includes(d));
667
+ if (hiddenOn.length === HIDDEN_DEVICES.length) return;
668
+ if (node.type === "heading") out.push({ node, hiddenOn });
669
+ for (const child of nodeChildren(node)) walk(child, hiddenOn);
583
670
  };
584
- walk(root);
671
+ walk(root, []);
585
672
  return out;
586
673
  }
587
674
 
588
675
  const HIDDEN_DEVICES = ["desktop", "tablet", "mobile"] as const;
589
676
 
677
+ /** Columns set by custom tracks or a count, or undefined when neither is set. */
678
+ const columnCount = (tracks: unknown, columns: unknown): number | undefined =>
679
+ Array.isArray(tracks) && tracks.length > 0
680
+ ? tracks.length
681
+ : Number.isInteger(columns) && (columns as number) >= 1
682
+ ? (columns as number)
683
+ : undefined;
684
+
685
+ /** A grid's column count on desktop, tablet and mobile; unset follows the next wider device. */
686
+ function gridColumnCounts(grid: LayoutNode): [number, number, number] {
687
+ const props = grid.props as Record<string, unknown>;
688
+ const desktop = columnCount(props["columnTracks"], props["columns"]) ?? 1;
689
+ const tablet = columnCount(props["columnTracksTablet"], props["columnsTablet"]) ?? desktop;
690
+ const mobile = columnCount(props["columnTracksMobile"], props["columnsMobile"]) ?? tablet;
691
+ return [desktop, tablet, mobile];
692
+ }
693
+
694
+ /**
695
+ * W-799: a span wider than the grid, or a start line past it, made the browser add columns, so on
696
+ * a phone grid of 1 column a "span 3" child squeezed its siblings to a few pixels. The span is
697
+ * capped at the count and a start line that no longer fits is dropped.
698
+ */
699
+ function fitGridColumn(
700
+ start: unknown,
701
+ span: unknown,
702
+ count: number,
703
+ ): { value?: string; changed: boolean } {
704
+ const across =
705
+ Number.isInteger(span) && (span as number) >= 1 && (span as number) <= 12
706
+ ? (span as number)
707
+ : undefined;
708
+ const line =
709
+ Number.isInteger(start) && (start as number) >= 1 && (start as number) <= 13
710
+ ? (start as number)
711
+ : undefined;
712
+ const width = Math.min(across ?? 1, count);
713
+ const fits = line !== undefined && line + width - 1 <= count ? line : undefined;
714
+ const changed = width !== (across ?? 1) || fits !== line;
715
+ const value =
716
+ fits !== undefined
717
+ ? across !== undefined
718
+ ? `${fits} / span ${width}`
719
+ : String(fits)
720
+ : across !== undefined
721
+ ? `span ${width}`
722
+ : undefined;
723
+ return { value, changed };
724
+ }
725
+
590
726
  function tocChildren(
591
727
  node: LayoutNode,
592
- items: { id: string; text: string }[],
728
+ items: { id: string; text: string; tocClass?: string }[],
593
729
  mode: RenderMode,
594
730
  ): (VNode | string)[] {
595
731
  const title =
@@ -611,9 +747,9 @@ function tocChildren(
611
747
  children.push({
612
748
  tag: "ol",
613
749
  attrs: {},
614
- children: items.map((item) => ({
750
+ children: items.map((item): VNode => ({
615
751
  tag: "li",
616
- attrs: {},
752
+ attrs: item.tocClass ? { class: item.tocClass } : {},
617
753
  children: [{ tag: "a", attrs: { href: `#${item.id}` }, children: [item.text] }],
618
754
  })),
619
755
  });
@@ -41,6 +41,21 @@ function entriesFor(
41
41
  * state child (W-308) is left out of the item design and shows when there are no entries; the
42
42
  * editor shows it under the items too, so it can be designed.
43
43
  */
44
+ /** Loops inside loop items, at most this deep (W-654). */
45
+ const MAX_LOOP_DEPTH = 4;
46
+
47
+ function countNodes(nodes: readonly LayoutNode[]): number {
48
+ let count = 0;
49
+ const stack: LayoutNode[] = [...nodes];
50
+ while (stack.length > 0) {
51
+ const node = stack.pop() as LayoutNode;
52
+ count++;
53
+ const kids = (node as { children?: LayoutNode[] }).children;
54
+ if (Array.isArray(kids)) for (const child of kids) stack.push(child);
55
+ }
56
+ return count;
57
+ }
58
+
44
59
  export function renderLoop(
45
60
  node: LoopNode,
46
61
  attrs: Record<string, string>,
@@ -49,6 +64,14 @@ export function renderLoop(
49
64
  ): VNode | undefined {
50
65
  const posts = entriesFor(node, dynamic, ctx.mode);
51
66
  const itemPartId = node.props.itemPartId?.trim() ?? "";
67
+ const loopStack = dynamic?.loopStack ?? [];
68
+ // W-654: a loop item part holding a Loop that uses the same part (or one that leads back to it)
69
+ // recursed until the stack overflowed and the page failed to render.
70
+ const cycle = itemPartId !== "" && loopStack.includes(itemPartId);
71
+ if (cycle || loopStack.length >= MAX_LOOP_DEPTH) {
72
+ if (ctx.mode === "public") return undefined;
73
+ return { tag: "div", attrs: { ...attrs, "data-emvb-loop-empty": "" }, children: ["Loop"] };
74
+ }
52
75
  const templateLayout =
53
76
  itemPartId && dynamic?.loopTemplates ? dynamic.loopTemplates[itemPartId] : undefined;
54
77
  const own = node.children.filter((child) => child.type !== "loop-empty");
@@ -62,7 +85,9 @@ export function renderLoop(
62
85
  if (designed.length > 0) return ELEMENTS.loop.build(node as never, attrs, designed);
63
86
  }
64
87
  // Editor mode always has a sample post, so an empty item template would paint a zero-height box.
65
- if (posts.length === 0 || (ctx.mode === "editor" && templateNodes.length === 0)) {
88
+ // W-602: on the page, no item design means nothing to list, not a row of blank items (empty
89
+ // bordered boxes with Cards).
90
+ if (posts.length === 0 || templateNodes.length === 0) {
66
91
  if (ctx.mode !== "editor") return undefined;
67
92
  return {
68
93
  tag: "div",
@@ -75,16 +100,27 @@ export function renderLoop(
75
100
  }
76
101
  const children: VNode[] = [];
77
102
  // A loop item part is another layout, so its ids may match the page's (W-250).
78
- const itemDynamic = templateLayout
79
- ? { ...rest, idOrigin: `${rest.idOrigin ?? ""}/l:${itemPartId}` }
80
- : rest;
103
+ const itemDynamic = {
104
+ ...(templateLayout ? { ...rest, idOrigin: `${rest.idOrigin ?? ""}/l:${itemPartId}` } : rest),
105
+ loopStack: [...loopStack, itemPartId || node.id],
106
+ };
107
+ const itemSize = countNodes(templateNodes);
81
108
  for (const post of posts) {
109
+ // W-654: nested Loops multiply like nested sections; they share the render's budget.
110
+ if (ctx.takeSectionBudget && !ctx.takeSectionBudget(itemSize)) break;
82
111
  children.push({
83
112
  tag: "div",
84
- attrs: { class: "emvb-loop-item", "data-emvb-loop-item": post.id },
113
+ attrs: { class: "emvb-loop-item", "data-emvb-loop-item": post.id, role: "listitem" },
85
114
  children: ctx.children(templateNodes, { ...itemDynamic, post, inLoopItem: true }),
86
115
  });
87
116
  }
88
- if (ctx.mode === "editor") children.push(...empty());
89
- return ELEMENTS.loop.build(node as never, attrs, children);
117
+ // W-789: entries were bare divs, so screen readers didn't hear "list, 4 items" and a repeated
118
+ // "Read more" had no list item to take its purpose from (WCAG 1.3.1, 2.4.4). The editor adds the
119
+ // Empty state under the items; a list may hold only its items, so the roles go only then.
120
+ const extras = ctx.mode === "editor" ? empty() : [];
121
+ if (extras.length > 0) {
122
+ for (const item of children) delete item.attrs.role;
123
+ return ELEMENTS.loop.build(node as never, attrs, [...children, ...extras]);
124
+ }
125
+ return ELEMENTS.loop.build(node as never, { ...attrs, role: "list" }, children);
90
126
  }
@@ -56,7 +56,10 @@ export function renderPagination(
56
56
  class: "emvb-pagination-prev",
57
57
  href: href(item.href),
58
58
  rel: "prev",
59
- ...nameIfSymbols(label(node.props.prevText, "Previous"), "Previous page"),
59
+ ...nameIfSymbols(
60
+ label(node.props.prevText, "Previous"),
61
+ label(node.props.prevLabel, "Previous page"),
62
+ ),
60
63
  },
61
64
  children: [label(node.props.prevText, "Previous")],
62
65
  };
@@ -67,7 +70,10 @@ export function renderPagination(
67
70
  class: "emvb-pagination-next",
68
71
  href: href(item.href),
69
72
  rel: "next",
70
- ...nameIfSymbols(label(node.props.nextText, "Next"), "Next page"),
73
+ ...nameIfSymbols(
74
+ label(node.props.nextText, "Next"),
75
+ label(node.props.nextLabel, "Next page"),
76
+ ),
71
77
  },
72
78
  children: [label(node.props.nextText, "Next")],
73
79
  };
@@ -84,7 +90,11 @@ export function renderPagination(
84
90
  class: "emvb-pagination-page",
85
91
  href: href(item.href),
86
92
  // W-426: a bare "2" says nothing out of context; screen readers hear "Page 2".
87
- "aria-label": `Page ${item.n}`,
93
+ // W-689: in the site's language when "Page number name" is set.
94
+ "aria-label": label(node.props.pageLabel, "Page {page}").replaceAll(
95
+ "{page}",
96
+ String(item.n),
97
+ ),
88
98
  ...(item.current ? { "aria-current": "page" } : {}),
89
99
  },
90
100
  children: [String(item.n)],
@@ -99,5 +109,9 @@ export function renderPagination(
99
109
  children: [pageCountText(data, node.props.countText)],
100
110
  });
101
111
  }
102
- return { tag: "nav", attrs: { ...attrs, "aria-label": "Pagination" }, children };
112
+ return {
113
+ tag: "nav",
114
+ attrs: { ...attrs, "aria-label": label(node.props.navLabel, "Pagination") },
115
+ children,
116
+ };
103
117
  }
@@ -6,6 +6,23 @@ import type { VNode } from "./vnode.ts";
6
6
 
7
7
  const MAX_SECTION_DEPTH = 8;
8
8
 
9
+ const sizes = new WeakMap<object, number>();
10
+ /** Elements in a part's layout, counted once per layout object. */
11
+ function partSize(nodes: readonly object[]): number {
12
+ const cached = sizes.get(nodes);
13
+ if (cached !== undefined) return cached;
14
+ let count = 0;
15
+ const stack: unknown[] = [...nodes];
16
+ while (stack.length > 0) {
17
+ const node = stack.pop() as { children?: unknown } | null;
18
+ if (!node || typeof node !== "object") continue;
19
+ count++;
20
+ if (Array.isArray(node.children)) for (const child of node.children) stack.push(child);
21
+ }
22
+ sizes.set(nodes, count);
23
+ return count;
24
+ }
25
+
9
26
  /**
10
27
  * A section with `partId` renders that theme part's children.
11
28
  * A missing part stays empty on the public site (local children would drift from the source).
@@ -27,6 +44,16 @@ export function renderSection(
27
44
  if (ctx.mode !== "editor") return ELEMENTS.section.build(node as never, attrs, []);
28
45
  return { tag: "div", attrs, children: ["Synced section"] };
29
46
  }
47
+ // W-653: past the render's budget a copy renders like a missing part. W-657: the editor
48
+ // says why, instead of the same placeholder a deleted part shows.
49
+ if (ctx.takeSectionBudget && !ctx.takeSectionBudget(partSize(template.root.children))) {
50
+ if (ctx.mode !== "editor") return ELEMENTS.section.build(node as never, attrs, []);
51
+ return {
52
+ tag: "div",
53
+ attrs,
54
+ children: ["Synced section not shown: this page already holds too many synced copies."],
55
+ };
56
+ }
30
57
  const templateNodes = template.root.children;
31
58
  const next: ThemeDynamicData = {
32
59
  ...dynamic,
@@ -40,10 +40,19 @@ export function renderTabs(
40
40
  "aria-controls": panelDomId,
41
41
  tabindex: i === 0 ? "0" : "-1",
42
42
  },
43
- children: [panel.props.label],
43
+ // W-664: a label of only spaces made a zero-width tab nobody could click or hear.
44
+ children: [panel.props.label.trim() || `Tab ${i + 1}`],
44
45
  });
46
+ // W-598: the panel renders like any element, so its own style, classes and device
47
+ // visibility reach the page; the tab wiring is added on top.
48
+ const built = ctx.children([panel], dynamic)[0];
49
+ const own = built?.attrs ?? {};
45
50
  const panelAttrs: Record<string, string> = {
46
- class: "emvb-tab-panel",
51
+ ...own,
52
+ class: `emvb-tab-panel ${own.class ?? ""}`
53
+ .split(/\s+/)
54
+ .filter((c, at, all) => c && all.indexOf(c) === at)
55
+ .join(" "),
47
56
  id: panelDomId,
48
57
  role: "tabpanel",
49
58
  "aria-labelledby": tabDomId,
@@ -52,7 +61,7 @@ export function renderTabs(
52
61
  panelNodes.push({
53
62
  tag: "div",
54
63
  attrs: panelAttrs,
55
- children: ctx.children(panel.children, dynamic),
64
+ children: built ? built.children : ctx.children(panel.children, dynamic),
56
65
  });
57
66
  });
58
67
  return {
@@ -78,7 +78,7 @@ const TAGS = new Set([
78
78
  const VOID = new Set(["hr", "img", "input", "br"]);
79
79
  // iframe/video are not void — they need closing tags.
80
80
  const ATTR_NAME =
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-]*)$/;
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|step|data-[a-z][a-z0-9-]*)$/;
82
82
 
83
83
  export const isAllowedTag = (tag: string) => TAGS.has(tag);
84
84
  export const isAllowedAttr = (name: string) => ATTR_NAME.test(name);
@@ -51,6 +51,15 @@ export function isSafeCssValue(value: string): boolean {
51
51
  const FAMILY = String.raw`(?:'[\p{L}\p{N} _.-]+'|"[\p{L}\p{N} _.-]+"|[\p{L}\p{N}_-]+(?: [\p{L}\p{N}_-]+)*)`;
52
52
  const FONT_STACK = new RegExp(String.raw`^${FAMILY}(?:\s*,\s*${FAMILY})*$`, "u");
53
53
 
54
+ /**
55
+ * A font stack that can be written as a `font-family` declaration (W-648): `!important` would let
56
+ * a class's font beat the element's own, and control characters aren't part of any family name.
57
+ * Checked on output only, so a layout saved with one still loads; the declaration is dropped.
58
+ */
59
+ function isEmittableFontStack(value: string): boolean {
60
+ return !/[!\p{Cc}]/u.test(value) && isSafeFontStack(value);
61
+ }
62
+
54
63
  /**
55
64
  * A comma-separated font stack whose family names may be quoted. Quoted names hold only letters,
56
65
  * digits, spaces, `_`, `.` and `-`, so a quote can never open or close anything else.
@@ -700,7 +709,7 @@ export function styleDeclarations(style: unknown): {
700
709
  const value = entry?.toValue(raw);
701
710
  const safe =
702
711
  value !== undefined &&
703
- (entry?.css === "font-family" ? isSafeFontStack(value) : isSafeCssValue(value));
712
+ (entry?.css === "font-family" ? isEmittableFontStack(value) : isSafeCssValue(value));
704
713
  if (entry && safe) {
705
714
  declarations.push({ property: entry.css, value });
706
715
  if (key === "entrance") {
@@ -719,6 +728,10 @@ export function styleDeclarations(style: unknown): {
719
728
  const background = composeBackground(record);
720
729
  declarations.push(...background.declarations);
721
730
  rejected.push(...background.rejected);
731
+ // W-802: a background video is drawn above the element's background, overlay included, so
732
+ // the overlay is also handed to the layer the video box paints above its video.
733
+ const overlayLayer = cssOverlay(record["overlay"]);
734
+ if (overlayLayer) declarations.push({ property: "--emvb-bg-overlay", value: overlayLayer });
722
735
  const column = gridPlacement(record["gridColumnStart"], record["gridColumnSpan"]);
723
736
  const row = gridPlacement(record["gridRowStart"], record["gridRowSpan"]);
724
737
  if (column.value) declarations.push({ property: "grid-column", value: column.value });
@@ -795,7 +808,7 @@ const ANIMATION_KEYS = ["entrance", "scrollMotion"] as const;
795
808
  * A style that sets an entrance or scroll motion keeps the other one it inherits from a wider
796
809
  * device or its classes (W-319): both are one `animation` list in CSS.
797
810
  */
798
- export function withInheritedAnimation(style: unknown, inherited: unknown): unknown {
811
+ function withInheritedAnimation(style: unknown, inherited: unknown): unknown {
799
812
  if (!isRecord(style) || !isRecord(inherited)) return style;
800
813
  if (!ANIMATION_KEYS.some((key) => style[key] !== undefined)) return style;
801
814
  const next: Record<string, unknown> = { ...style };
@@ -13,6 +13,8 @@ const YT_HOSTS = new Set([
13
13
  "youtube.com",
14
14
  "www.youtube.com",
15
15
  "m.youtube.com",
16
+ // W-546: YouTube Music links play the same video ids.
17
+ "music.youtube.com",
16
18
  "youtu.be",
17
19
  "www.youtu.be",
18
20
  "youtube-nocookie.com",
@@ -27,9 +29,26 @@ const YT_ID = /^[\w-]{6,}$/;
27
29
  const VIMEO_ID = /^\d{6,}$/;
28
30
  const firstSegment = (path: string) => path.split("/").find(Boolean);
29
31
 
32
+ /** A YouTube playlist id (PL…, UU…, OLAK5uy_…). */
33
+ const YT_LIST = /^[\w-]{10,64}$/;
34
+
35
+ /**
36
+ * W-691: a playlist (`/embed/videoseries?list=…`, `/playlist?list=…`) embeds as
37
+ * `videoseries?list=…`. "videoseries" was taken for a video id and the list dropped, so the
38
+ * player showed "Video unavailable".
39
+ */
40
+ function youtubePlaylist(parsed: URL): string | undefined | null {
41
+ const path = parsed.pathname.replace(/\/+$/, "");
42
+ if (path !== "/embed/videoseries" && path !== "/playlist") return null;
43
+ const list = matching(parsed.searchParams.get("list") ?? undefined, YT_LIST);
44
+ return list ? `videoseries?list=${list}` : undefined;
45
+ }
46
+
30
47
  function youtubeId(parsed: URL): string | undefined {
31
48
  const host = parsed.hostname.toLowerCase();
32
49
  const path = parsed.pathname;
50
+ const playlist = youtubePlaylist(parsed);
51
+ if (playlist !== null) return playlist;
33
52
  if (host === "youtu.be" || host === "www.youtu.be") return matching(firstSegment(path), YT_ID);
34
53
  // W-215: /live/ links (a stream or its replay) too.
35
54
  for (const prefix of ["/embed/", "/shorts/", "/live/"]) {
@@ -56,7 +75,9 @@ function vimeoId(parsed: URL): string | undefined {
56
75
  : 0
57
76
  : parts[0] === "channels"
58
77
  ? 2
59
- : parts[0] === "groups" && parts[2] === "videos"
78
+ : (parts[0] === "groups" && parts[2] === "videos") ||
79
+ // W-546: a video opened from a showcase.
80
+ (parts[0] === "showcase" && parts[2] === "video")
60
81
  ? 3
61
82
  : 0;
62
83
  const id = matching(parts[at], VIMEO_ID);
@@ -93,7 +114,7 @@ const withStart = (provider: "youtube" | "vimeo", src: string, start: number | u
93
114
  start === undefined
94
115
  ? src
95
116
  : provider === "youtube"
96
- ? `${src}?start=${start}`
117
+ ? `${src}${src.includes("?") ? "&" : "?"}start=${start}`
97
118
  : `${src}#t=${start}s`;
98
119
 
99
120
  /**
@@ -116,16 +137,32 @@ const PROVIDERS = [
116
137
  */
117
138
  // W-448: "youtube.com/watch?v=…" typed without https:// was taken for a video file path on this
118
139
  // 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;
140
+ // W-659: every host the providers accept, not a hand-kept subset (youtube-nocookie.com and
141
+ // www.youtu.be still became a broken file player).
142
+ function bareVideoHost(typed: string): boolean {
143
+ const slash = typed.indexOf("/");
144
+ if (slash <= 0) return false;
145
+ const host = typed.slice(0, slash).toLowerCase();
146
+ return YT_HOSTS.has(host) || VIMEO_HOSTS.has(host);
147
+ }
148
+
149
+ /** A site path (not `//host`) to a .mp4/.webm/.ogg file, or the media file route. */
150
+ function isVideoFilePath(value: string): boolean {
151
+ if (value.startsWith("//")) return false;
152
+ const path = value.split(/[?#]/)[0] ?? "";
153
+ return /\.(mp4|webm|ogg)$/i.test(path) || path.startsWith("/_emdash/api/media/file/");
154
+ }
121
155
 
122
156
  export function resolveEmbedUrl(value: string): EmbedTarget | undefined {
123
157
  const typed = value.trim();
124
- const trimmed = BARE_VIDEO_HOST.test(typed) ? `https://${typed}` : typed;
158
+ const trimmed = bareVideoHost(typed) ? `https://${typed}` : typed;
125
159
  if (trimmed.length === 0 || trimmed.length > 2000) return undefined;
126
160
 
127
161
  const hasScheme = /^[a-z][a-z0-9+.-]*:/i.test(trimmed);
128
162
  if (!hasScheme) {
163
+ // W-795: a bare word such as "nonsense" became a page-relative <video> (a black player).
164
+ // A relative value must name a video file or the media route, as absolute ones must.
165
+ if (!isVideoFilePath(trimmed)) return undefined;
129
166
  const media = sanitizeMediaUrl(trimmed);
130
167
  if (!media) return undefined;
131
168
  return { kind: "video", src: media };
@@ -20,7 +20,8 @@ export function sanitizeUrl(value: string, schemes: ReadonlySet<string>): string
20
20
  // second address hides in the same string.
21
21
  if (/[^\S ]|\\/.test(trimmed)) return undefined;
22
22
  // Relative: /path, ./path, ../path, ?query, #hash, or bare path segment
23
- if (/^(?:[/?#.]|[A-Za-z0-9._~-])/.test(trimmed)) return trimmed;
23
+ // W-683: or one that starts in another script ("über-uns", "контакты"), like page slugs (W-554).
24
+ if (/^(?:[/?#.]|[\p{L}\p{N}._~-])/u.test(trimmed)) return trimmed;
24
25
  return undefined;
25
26
  }
26
27