@perkyzz/emvb 1.0.0 → 1.2.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 (142) hide show
  1. package/README.md +9 -0
  2. package/THIRD_PARTY_NOTICES.md +1 -0
  3. package/package.json +10 -9
  4. package/src/admin/agents-api.ts +5 -1
  5. package/src/admin/bulk-api.ts +67 -0
  6. package/src/admin/content-api.ts +39 -6
  7. package/src/admin/copy-rich-text.ts +119 -0
  8. package/src/admin/dialog-tab-wrap.ts +78 -0
  9. package/src/admin/editor/A11yCopilot.tsx +2 -0
  10. package/src/admin/editor/Editor.tsx +24 -7
  11. package/src/admin/editor/ScheduleDialog.tsx +167 -0
  12. package/src/admin/editor/Timeline.tsx +6 -2
  13. package/src/admin/editor/TopBar.tsx +60 -8
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  15. package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
  16. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  17. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  18. package/src/admin/editor/dnd/new-element.ts +68 -0
  19. package/src/admin/editor/editor-chrome.tsx +16 -5
  20. package/src/admin/editor/editor-commands.ts +10 -4
  21. package/src/admin/editor/editor-css.ts +2 -1
  22. package/src/admin/editor/element-chrome.ts +22 -0
  23. package/src/admin/editor/panels/ElementPanel.tsx +34 -17
  24. package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
  25. package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
  26. package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
  27. package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
  28. package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
  29. package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
  30. package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
  31. package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
  32. package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
  33. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
  34. package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
  35. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  36. package/src/admin/editor/panels/settings/length-units.ts +15 -3
  37. package/src/admin/editor/panels/settings/style-sections.ts +1 -0
  38. package/src/admin/editor/panels/style-target.ts +17 -4
  39. package/src/admin/editor/section-templates.ts +26 -4
  40. package/src/admin/editor/store.ts +15 -3
  41. package/src/admin/editor/useEditorCommands.ts +7 -5
  42. package/src/admin/editor/useEditorData.ts +4 -0
  43. package/src/admin/editor/useNodeActions.ts +4 -2
  44. package/src/admin/editor/useSave.ts +47 -3
  45. package/src/admin/export-api.ts +238 -0
  46. package/src/admin/index.tsx +6 -1
  47. package/src/admin/menus-api.ts +113 -0
  48. package/src/admin/pages/ExportDialog.tsx +395 -0
  49. package/src/admin/pages/ImportElementorDialog.tsx +25 -1
  50. package/src/admin/pages/PageList.tsx +67 -2
  51. package/src/admin/pages/ThemePartList.tsx +37 -1
  52. package/src/admin/pages/bulk.tsx +303 -0
  53. package/src/admin/search.ts +20 -0
  54. package/src/admin/theme-api.ts +4 -0
  55. package/src/admin/ui.ts +11 -2
  56. package/src/admin/widgets/CanvasField.tsx +8 -0
  57. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  58. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  59. package/src/admin/widgets/convert-body.ts +73 -2
  60. package/src/astro/EmVBPage.astro +3 -0
  61. package/src/astro/render.ts +47 -22
  62. package/src/astro/request-data.ts +3 -0
  63. package/src/astro/resolve-theme.ts +88 -51
  64. package/src/astro/tabs/runtime.ts +16 -6
  65. package/src/astro/visitor.ts +23 -4
  66. package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
  67. package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
  68. package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
  69. package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
  70. package/src/astro/widgets/alerts.ts +37 -0
  71. package/src/astro/widgets/carousel.ts +167 -0
  72. package/src/astro/widgets/index.ts +1 -0
  73. package/src/astro/widgets/lightbox.ts +123 -0
  74. package/src/constants.ts +1 -1
  75. package/src/core/a11y/audit.ts +103 -3
  76. package/src/core/arrange.ts +57 -1
  77. package/src/core/bounded-array.ts +16 -13
  78. package/src/core/contract.ts +26 -3
  79. package/src/core/css/generate.ts +83 -21
  80. package/src/core/css/scope.ts +10 -2
  81. package/src/core/css/trace.ts +33 -8
  82. package/src/core/design/classes.ts +25 -5
  83. package/src/core/design/devices.ts +78 -2
  84. package/src/core/design/variables.ts +14 -1
  85. package/src/core/elements/icon-svg.ts +135 -0
  86. package/src/core/elements/index.ts +33 -127
  87. package/src/core/elements/widgets.ts +907 -0
  88. package/src/core/export/runtimes.generated.ts +12 -0
  89. package/src/core/export/site.ts +579 -0
  90. package/src/core/export/zip.ts +95 -0
  91. package/src/core/extensions/schema.ts +2 -1
  92. package/src/core/geo-trust.ts +18 -0
  93. package/src/core/history/diff.ts +25 -0
  94. package/src/core/icons/social.generated.ts +29 -0
  95. package/src/core/image-edit/schema.ts +2 -1
  96. package/src/core/import/elementor/atomic.ts +22 -9
  97. package/src/core/import/elementor/context.ts +18 -0
  98. package/src/core/import/elementor/index.ts +72 -11
  99. package/src/core/import/elementor/style.ts +21 -1
  100. package/src/core/import/elementor/widgets.ts +394 -133
  101. package/src/core/index.ts +14 -0
  102. package/src/core/issue-cap.ts +19 -0
  103. package/src/core/json-schema.ts +8 -1
  104. package/src/core/limits.ts +6 -0
  105. package/src/core/loop-collections.ts +33 -0
  106. package/src/core/perf/meter.ts +37 -19
  107. package/src/core/portable-text-export.ts +243 -0
  108. package/src/core/proposals.ts +8 -2
  109. package/src/core/public-attributes.ts +30 -0
  110. package/src/core/render/index.ts +115 -13
  111. package/src/core/render/tabs.ts +18 -11
  112. package/src/core/render/vnode.ts +44 -6
  113. package/src/core/sanitize/css.ts +26 -0
  114. package/src/core/sanitize/svg-upload.ts +276 -23
  115. package/src/core/sanitize/svg.ts +3 -3
  116. package/src/core/schema/descriptors.ts +4 -0
  117. package/src/core/schema/design.ts +8 -7
  118. package/src/core/schema/layout.ts +406 -18
  119. package/src/core/schema/style.ts +49 -1
  120. package/src/core/search-text.ts +70 -0
  121. package/src/core/shadowing-ids.ts +41 -0
  122. package/src/core/theme/conditions.ts +2 -1
  123. package/src/core/theme/float.ts +1 -0
  124. package/src/core/theme/parse-doc.ts +10 -5
  125. package/src/core/theme/popup-rules.ts +16 -0
  126. package/src/core/theme/triggers.ts +3 -2
  127. package/src/core/validate.ts +3 -2
  128. package/src/index.ts +23 -2
  129. package/src/mcp/ports.ts +18 -7
  130. package/src/mcp/proposals.ts +36 -11
  131. package/src/mcp/read.ts +2 -3
  132. package/src/mcp/tools.ts +1 -1
  133. package/src/server/agent-settings.ts +12 -1
  134. package/src/server/hooks.ts +41 -6
  135. package/src/server/icon-routes.ts +52 -12
  136. package/src/server/mcp-routes.ts +11 -5
  137. package/src/server/plugin.ts +27 -2
  138. package/src/server/presence.ts +5 -1
  139. package/src/server/proposals.ts +16 -4
  140. package/src/server/requests.ts +60 -11
  141. package/src/server/site-origin.ts +13 -0
  142. package/src/server/targets.ts +26 -0
@@ -1,3 +1,4 @@
1
+ import { isShadowingId } from "../shadowing-ids.ts";
1
2
  import { renderableDesign, renderableDynamic, renderableLayout } from "../contract.ts";
2
3
  import { markColors } from "../text-marks.ts";
3
4
  import type { TextMark } from "../schema/layout.ts";
@@ -5,10 +6,17 @@ import { LIST_MARKERS } from "../css-keywords.ts";
5
6
  import { MAX_NODES } from "../limits.ts";
6
7
  import { loneAbTests, variantShows } from "../audience/variants.ts";
7
8
  import { audienceShows, audienceSummary } from "../audience/rules.ts";
8
- import { generateCss } from "../css/generate.ts";
9
+ import { baseRulesFor, generateCss } from "../css/generate.ts";
9
10
  import { printCss } from "../css/print.ts";
10
- import { cssScopeToken, scopeClassName, scopeCss, scopeWrapperCss } from "../css/scope.ts";
11
+ import {
12
+ cssScopeToken,
13
+ scopeClassName,
14
+ scopeCss,
15
+ scopeCssAll,
16
+ scopeWrapperCss,
17
+ } from "../css/scope.ts";
11
18
  import { ELEMENTS } from "../elements/index.ts";
19
+ import { nodeRuntime, type WidgetRuntime } from "../elements/widgets.ts";
12
20
  import { controlId } from "../elements/field-id.ts";
13
21
  import { layoutHasForm } from "../forms/binding.ts";
14
22
  import { nodeChildren, someNode } from "../tree-ops.ts";
@@ -40,7 +48,8 @@ import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
40
48
  import { sanitizeHref } from "../sanitize/href.ts";
41
49
  import { resolvePostForRender, type ThemeDynamicData } from "../theme/dynamic.ts";
42
50
  import type { FormDefinitions } from "../forms/definition.ts";
43
- import { DEVICES, type Device } from "../theme/popup-rules.ts";
51
+ import { DEVICES, type Device, type EditorDevice } from "../theme/popup-rules.ts";
52
+ import { hiddenOnEveryDevice } from "../design/devices.ts";
44
53
  import type { RenderContext, RenderMode } from "./context.ts";
45
54
  import { isDynamicPostNode, renderDynamicPost } from "./dynamic-post.ts";
46
55
  import { renderForm, withFieldOptions } from "./form.ts";
@@ -68,7 +77,7 @@ export { FORMS_SUBMIT_PATH } from "./form.ts";
68
77
 
69
78
  export type RenderWarning = {
70
79
  nodeId: string;
71
- code: "unknown-type" | "rejected-style" | "unknown-variable";
80
+ code: "unknown-type" | "rejected-style" | "unknown-variable" | "refused-markup";
72
81
  detail: string;
73
82
  };
74
83
  export type RenderResult = {
@@ -79,9 +88,16 @@ export type RenderResult = {
79
88
  needsTabsRuntime: boolean;
80
89
  /** A Menu has a dropdown: hosts load `EmVBMenuRuntime` (W-197). */
81
90
  needsMenuRuntime: boolean;
91
+ /**
92
+ * W-1025: the opt-in widget scripts the page's elements asked for, sorted; empty for most
93
+ * pages. `EmVBPage` loads them; a theme part's go to `EmVBWidgetRuntimes`.
94
+ */
95
+ runtimes: WidgetRuntime[];
82
96
  /** The site's text direction when set in Site styles, for the host's `<html dir>` (W-230). */
83
97
  dir?: "ltr" | "rtl" | "auto";
84
98
  warnings: RenderWarning[];
99
+ /** W-971: the element types whose base rules this sheet holds (see `sharedPartCss`). */
100
+ baseTypes: string[];
85
101
  };
86
102
 
87
103
  const ID = /^[A-Za-z0-9_-]{4,24}$/;
@@ -206,6 +222,44 @@ function renameIds(vnode: VNode, base: string, next: string): VNode {
206
222
  /** Elements synced sections may add to one render, all copies together (W-653): 20 full pages. */
207
223
  const MAX_SECTION_ELEMENTS = 20 * MAX_NODES;
208
224
 
225
+ const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
226
+ // W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
227
+ baseCss.set("ext", EXTENSION_PLACEHOLDER_CSS);
228
+
229
+ /**
230
+ * W-971: theme parts on one page (header, footer, popups, floats) each repeated the scope wrapper
231
+ * rule, the print rules and the base rules of their element types. Given their sheets (each the
232
+ * `css` of a scoped `renderPage`), this writes the wrapper and the union of base rules once, scoped
233
+ * to every part, then each part's own rules, then the print rules once. Base rules have no
234
+ * specificity of their own beyond their element class and came before every class and local rule
235
+ * in each sheet, so writing them first keeps the cascade.
236
+ */
237
+ export function sharedPartCss(
238
+ sheets: readonly { css: string; scope: string; baseTypes: readonly string[] }[],
239
+ ): string {
240
+ const scopes = sheets.flatMap((s) => {
241
+ const token = cssScopeToken(s.scope);
242
+ return token ? [token] : [];
243
+ });
244
+ if (scopes.length !== sheets.length || sheets.length < 2)
245
+ return sheets.map((s) => s.css).join("\n");
246
+ const wrapper = scopeWrapperCss();
247
+ const print = printCss();
248
+ const own: string[] = [];
249
+ for (const sheet of sheets) {
250
+ const token = cssScopeToken(sheet.scope) as string;
251
+ const base = scopeCss(baseRulesFor(sheet.baseTypes, baseCss), token);
252
+ let css = sheet.css;
253
+ if (!css.startsWith(wrapper) || !css.endsWith(print) || (base && !css.includes(base)))
254
+ return sheets.map((s) => s.css).join("\n");
255
+ css = css.slice(wrapper.length, css.length - print.length);
256
+ own.push(base ? css.replace(base, "") : css);
257
+ }
258
+ const union = new Set(sheets.flatMap((s) => s.baseTypes));
259
+ const shared = scopeCssAll(baseRulesFor(union, baseCss), scopes);
260
+ return [wrapper + shared, ...own, print].filter(Boolean).join("\n");
261
+ }
262
+
209
263
  export function renderPage(
210
264
  storedLayout: Layout,
211
265
  storedDesign: DesignSystem,
@@ -216,7 +270,7 @@ export function renderPage(
216
270
  /** Public renders: wrap the markup and scope the CSS to it, so sheets can't override each other (W-112). */
217
271
  scope?: string;
218
272
  /** Editor canvas: device rules follow this device, not the frame width (W-116). */
219
- previewDevice?: Device;
273
+ previewDevice?: EditorDevice;
220
274
  /**
221
275
  * Theme parts (header, footer, popup, float) render apart from the page, so a synced section
222
276
  * on both gave form fields, honeypots and tab groups the same ids: a label in a popup focused
@@ -239,6 +293,8 @@ export function renderPage(
239
293
  id: string;
240
294
  declarations: Declaration[];
241
295
  states: StateDeclarations;
296
+ wide?: Declaration[];
297
+ wideHidden?: boolean;
242
298
  laptop?: Declaration[];
243
299
  tablet?: Declaration[];
244
300
  mobile?: Declaration[];
@@ -264,6 +320,8 @@ export function renderPage(
264
320
  const renderedHeadings: { id: string; text: string; tocClass?: string }[] = [];
265
321
  const emittedIds = new Set<string>();
266
322
  const tocNodes: { node: LayoutNode; vnode: VNode }[] = [];
323
+ // S-02: markup the serializer refuses empties its element instead of failing the whole page.
324
+ const elementIds = new WeakMap<VNode, string>();
267
325
  const knownVariables = new Set(design.variables.colors.map((c) => c.id));
268
326
  let backgroundVideo = false;
269
327
  /** W-952: any List drawn as numbered steps, so their rules are sent. */
@@ -274,6 +332,7 @@ export function renderPage(
274
332
  // W-253: runtimes follow what renders, including synced section and loop item contents,
275
333
  // which the page's own layout doesn't hold.
276
334
  const rendered = { form: false, tabs: false, menuDropdown: false };
335
+ const runtimes = new Set<WidgetRuntime>();
277
336
  let sectionBudget = MAX_SECTION_ELEMENTS;
278
337
  const ctx: RenderContext = {
279
338
  takeSectionBudget: (nodes) => {
@@ -355,7 +414,21 @@ export function renderPage(
355
414
  const mobile = styleDeclarations(
356
415
  withInheritedLayers(node.devices?.mobile, { ...base, ...laptopStyle, ...tabletStyle }),
357
416
  );
358
- for (const key of [...rejected, ...laptop.rejected, ...tablet.rejected, ...mobile.rejected]) {
417
+ // W-959: Wide screen (2400 px and up) builds on Desktop; `renderableNode` moved `style.wide`
418
+ // here. The narrower devices never overlap it, so they don't inherit it.
419
+ const { devices: wideDevices, wideHidden } = node as {
420
+ devices?: { wide?: unknown };
421
+ wideHidden?: boolean;
422
+ };
423
+ const wideStyle = wideDevices?.wide;
424
+ const wide = styleDeclarations(withInheritedLayers(wideStyle, base));
425
+ for (const key of [
426
+ ...rejected,
427
+ ...wide.rejected,
428
+ ...laptop.rejected,
429
+ ...tablet.rejected,
430
+ ...mobile.rejected,
431
+ ]) {
359
432
  warnings.push({ nodeId, code: "rejected-style", detail: key });
360
433
  }
361
434
  if (node.type === "spacer") {
@@ -461,6 +534,20 @@ export function renderPage(
461
534
  tablet.declarations.push(at(2));
462
535
  mobile.declarations.push(at(3));
463
536
  }
537
+ // W-959: a Wide screen placement of its own, on the Desktop column count.
538
+ const wideOwn = wideStyle as { gridColumnStart?: unknown; gridColumnSpan?: unknown };
539
+ if (
540
+ wideOwn &&
541
+ (wideOwn.gridColumnStart !== undefined || wideOwn.gridColumnSpan !== undefined)
542
+ ) {
543
+ const place = { ...node.style, ...wideOwn } as typeof node.style & object;
544
+ const fit = fitGridColumn(place.gridColumnStart, place.gridColumnSpan, desktopCount);
545
+ const others = wide.declarations.filter((d) => d.property !== "grid-column");
546
+ wide.declarations.splice(0, wide.declarations.length, ...others, {
547
+ property: "grid-column",
548
+ value: fit.value ?? "auto",
549
+ });
550
+ }
464
551
  }
465
552
  const states = stateDeclarations(node.states);
466
553
  for (const key of states.rejected) {
@@ -474,6 +561,8 @@ export function renderPage(
474
561
  // W-567: the root is the page itself; hiding it on a device blanked the whole page there.
475
562
  const hiddenOn = isRoot ? undefined : node.hiddenOn;
476
563
  const responsive =
564
+ wide.declarations.length > 0 ||
565
+ (!isRoot && wideHidden !== undefined) ||
477
566
  laptop.declarations.length > 0 ||
478
567
  tablet.declarations.length > 0 ||
479
568
  mobile.declarations.length > 0 ||
@@ -492,6 +581,8 @@ export function renderPage(
492
581
  id: ruleId,
493
582
  declarations,
494
583
  states: states.states,
584
+ ...(wide.declarations.length > 0 ? { wide: wide.declarations } : {}),
585
+ ...(!isRoot && wideHidden !== undefined ? { wideHidden } : {}),
495
586
  laptop: laptop.declarations,
496
587
  tablet: tablet.declarations,
497
588
  mobile: mobile.declarations,
@@ -508,7 +599,7 @@ export function renderPage(
508
599
  const attrs: Record<string, string> = { class: classes.join(" "), ...customAttributes(node) };
509
600
  if (mode === "editor" && id) attrs["data-emvb-id"] = id;
510
601
  const htmlId =
511
- node.htmlId && HTML_ID.test(node.htmlId)
602
+ node.htmlId && HTML_ID.test(node.htmlId) && !isShadowingId(node.htmlId)
512
603
  ? node.htmlId
513
604
  : node.type === "heading" && id && layoutHasToc
514
605
  ? `emvb-h-${id}`
@@ -561,6 +652,8 @@ export function renderPage(
561
652
  if (isFormNode(node) && node.props.formId.trim()) rendered.form = true;
562
653
  if (isTabsNode(node)) rendered.tabs = true;
563
654
  if (type === "menu-item" && hasChildren(node)) rendered.menuDropdown = true;
655
+ const runtime = nodeRuntime(node as LayoutNode);
656
+ if (runtime) runtimes.add(runtime);
564
657
  const ruleId = id === undefined ? undefined : ruleIdFor(id, dynamic?.idOrigin ?? "");
565
658
  const attrs = nodeAttrs(node, isRoot, id, nodeId, ruleId);
566
659
  if (mode === "editor" && hasBindings(stored)) attrs["data-emvb-bound"] = "";
@@ -606,7 +699,7 @@ export function renderPage(
606
699
  if (node.type === "heading" && pageHeadings?.has(stored) && attrs.id) {
607
700
  const text = String((node.props as { text?: unknown }).text ?? "").trim();
608
701
  // W-409: a heading hidden on every device has nothing to jump to.
609
- const hiddenEverywhere = DEVICES.every((device) => node.hiddenOn?.includes(device));
702
+ const hiddenEverywhere = hiddenOnEveryDevice(node);
610
703
  if (text && !hiddenEverywhere && !renderedHeadings.some((h) => h.id === attrs.id)) {
611
704
  // W-793: a heading hidden on some devices (itself or an ancestor) hides its contents
612
705
  // entry there too, or the entry was a dead link on those devices.
@@ -658,7 +751,9 @@ export function renderPage(
658
751
  if (!vnode) return undefined;
659
752
  const src = videoOf(node);
660
753
  if (src) backgroundVideo = true;
661
- return applyBackgroundVideo(applyBoxLink(node, vnode), src);
754
+ const out = applyBackgroundVideo(applyBoxLink(node, vnode), src);
755
+ elementIds.set(out, node.id);
756
+ return out;
662
757
  }
663
758
 
664
759
  function bindingData(dynamic: ThemeDynamicData | undefined): BindingData {
@@ -685,9 +780,6 @@ export function renderPage(
685
780
  toc.vnode.children = [];
686
781
  }
687
782
  }
688
- const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
689
- // W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
690
- baseCss.set("ext", EXTENSION_PLACEHOLDER_CSS);
691
783
  const css = generateCss({
692
784
  design,
693
785
  usedTypes,
@@ -702,7 +794,15 @@ export function renderPage(
702
794
  const vnode = scope
703
795
  ? { tag: "div", attrs: { class: scopeClassName(scope) }, children: [page] }
704
796
  : page;
705
- const html = serialize(vnode);
797
+ const html = serialize(vnode, {
798
+ isElement: (node) => elementIds.has(node),
799
+ onRefused: (element, error) =>
800
+ warnings.push({
801
+ nodeId: elementIds.get(element) ?? "(page)",
802
+ code: "refused-markup",
803
+ detail: error.message,
804
+ }),
805
+ });
706
806
  return {
707
807
  vnode,
708
808
  html,
@@ -710,8 +810,10 @@ export function renderPage(
710
810
  needsFormsRuntime: rendered.form || layoutHasForm(layout),
711
811
  needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
712
812
  needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
813
+ runtimes: [...runtimes].toSorted(),
713
814
  ...(design.direction ? { dir: design.direction } : {}),
714
815
  warnings,
816
+ baseTypes: [...usedTypes],
715
817
  };
716
818
  }
717
819
 
@@ -29,19 +29,26 @@ export function renderTabs(
29
29
  inputs.push({ tag: "input", attrs: inputAttrs, children: [] });
30
30
  const panelDomId = `${group}-panel-${i}`;
31
31
  const tabDomId = `${group}-tab-${i}`;
32
+ // W-975: ARIA allows no role on a <label>, so the tab is a span inside it; the label still
33
+ // switches the radio, which keeps the tabs working without the script.
32
34
  labels.push({
33
35
  tag: "label",
34
- attrs: {
35
- class: "emvb-tab-label",
36
- for: inputId,
37
- id: tabDomId,
38
- role: "tab",
39
- "aria-selected": i === 0 ? "true" : "false",
40
- "aria-controls": panelDomId,
41
- tabindex: i === 0 ? "0" : "-1",
42
- },
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}`],
36
+ attrs: { class: "emvb-tab-label", for: inputId },
37
+ children: [
38
+ {
39
+ tag: "span",
40
+ attrs: {
41
+ class: "emvb-tab",
42
+ id: tabDomId,
43
+ role: "tab",
44
+ "aria-selected": i === 0 ? "true" : "false",
45
+ "aria-controls": panelDomId,
46
+ tabindex: i === 0 ? "0" : "-1",
47
+ },
48
+ // W-664: a label of only spaces made a zero-width tab nobody could click or hear.
49
+ children: [panel.props.label.trim() || `Tab ${i + 1}`],
50
+ },
51
+ ],
45
52
  });
46
53
  // W-598: the panel renders like any element, so its own style, classes and device
47
54
  // visibility reach the page; the tab wiring is added on top.
@@ -78,20 +78,58 @@ 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|lang|hreflang|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|start|data-[a-z][a-z0-9-]*)$/;
81
+ /^(?:class|id|href|src|srcset|sizes|alt|width|height|loading|decoding|fetchpriority|dir|lang|hreflang|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|mask|method|action|name|value|placeholder|for|tabindex|autocomplete|open|datetime|muted|loop|playsinline|autoplay|required|novalidate|minlength|maxlength|min|max|pattern|step|start|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);
85
85
 
86
- /** Serializes a VNode tree. Text and attribute values are always escaped; tags and attribute names are allowlisted. */
87
- export function serialize(node: VNode | string): string {
86
+ /** A tag or attribute name outside the allowlist. */
87
+ class RefusedMarkup extends Error {}
88
+
89
+ /** How `serialize` handles refused markup inside a page instead of throwing (S-02). */
90
+ export type SoftSerialize = {
91
+ /** True for the root node of a layout element: refused markup empties the nearest one. */
92
+ isElement: (node: VNode) => boolean;
93
+ onRefused: (element: VNode, error: Error) => void;
94
+ };
95
+
96
+ function write(node: VNode | string, inner: (child: VNode | string) => string): string {
88
97
  if (typeof node === "string") return escapeText(node);
89
- if (!TAGS.has(node.tag)) throw new Error(`EmVB: tag "${node.tag}" is not allowed`);
98
+ if (!TAGS.has(node.tag)) throw new RefusedMarkup(`EmVB: tag "${node.tag}" is not allowed`);
90
99
  let attrs = "";
91
100
  for (const [name, value] of Object.entries(node.attrs)) {
92
- if (!ATTR_NAME.test(name)) throw new Error(`EmVB: attribute "${name}" is not allowed`);
101
+ if (!ATTR_NAME.test(name)) throw new RefusedMarkup(`EmVB: attribute "${name}" is not allowed`);
93
102
  attrs += ` ${name}="${escapeAttr(value)}"`;
94
103
  }
95
104
  if (VOID.has(node.tag)) return `<${node.tag}${attrs}>`;
96
- return `<${node.tag}${attrs}>${node.children.map(serialize).join("")}</${node.tag}>`;
105
+ return `<${node.tag}${attrs}>${node.children.map(inner).join("")}</${node.tag}>`;
106
+ }
107
+
108
+ const strict = (node: VNode | string): string => write(node, strict);
109
+
110
+ function softWrite(node: VNode | string, soft: SoftSerialize): string {
111
+ return write(node, (child) =>
112
+ typeof child !== "string" && soft.isElement(child)
113
+ ? guarded(child, soft)
114
+ : softWrite(child, soft),
115
+ );
116
+ }
117
+
118
+ function guarded(node: VNode, soft: SoftSerialize): string {
119
+ try {
120
+ return softWrite(node, soft);
121
+ } catch (error) {
122
+ if (!(error instanceof RefusedMarkup)) throw error;
123
+ soft.onRefused(node, error);
124
+ return "";
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Serializes a VNode tree. Text and attribute values are always escaped; tags and attribute names
130
+ * are allowlisted. A refused name throws, or with `soft` empties the element that holds it.
131
+ */
132
+ export function serialize(node: VNode | string, soft?: SoftSerialize): string {
133
+ if (!soft || typeof node === "string") return strict(node);
134
+ return guarded(node, soft);
97
135
  }
@@ -738,6 +738,8 @@ const PROPERTY_MAP: {
738
738
  iconScale: { css: "scale", toValue: cssIconScale },
739
739
  iconStrokeWidth: { css: "--emvb-icon-stroke", toValue: cssIconStroke },
740
740
  iconShadow: { css: "--emvb-icon-shadow", toValue: cssIconShadow },
741
+ // W-974: applied by `withViewportUnits` to the record's lengths; never a declaration of its own.
742
+ viewportUnits: { css: "--emvb-viewport-units", toValue: () => undefined },
741
743
  iconAnimation: { css: "--emvb-icon-animation", toValue: cssIconAnimation },
742
744
  };
743
745
 
@@ -787,6 +789,28 @@ function transformDeclarations(value: unknown): Declaration[] | undefined {
787
789
  return out;
788
790
  }
789
791
 
792
+ const VH_LENGTH = /^(-?\d+(?:\.\d+)?)vh$/;
793
+
794
+ /**
795
+ * W-974: a `vh` length the record marks as `dvh` or `svh` is written in that unit. Only a plain
796
+ * number with `vh` changes; a variable, `clamp()` or `auto` is left alone.
797
+ */
798
+ function withViewportUnits(declarations: Declaration[], units: unknown): void {
799
+ if (!isRecord(units)) return;
800
+ for (const [key, unit] of Object.entries(units)) {
801
+ if (unit !== "dvh" && unit !== "svh") continue;
802
+ const entry = Object.hasOwn(PROPERTY_MAP, key)
803
+ ? PROPERTY_MAP[key as keyof FlatStyleProps]
804
+ : undefined;
805
+ if (!entry) continue;
806
+ for (const declaration of declarations) {
807
+ if (declaration.property !== entry.css) continue;
808
+ const match = VH_LENGTH.exec(declaration.value);
809
+ if (match) declaration.value = `${match[1]}${unit}`;
810
+ }
811
+ }
812
+ }
813
+
790
814
  export function styleDeclarations(style: unknown): {
791
815
  declarations: Declaration[];
792
816
  rejected: string[];
@@ -807,6 +831,7 @@ export function styleDeclarations(style: unknown): {
807
831
  ) {
808
832
  continue;
809
833
  }
834
+ if (key === "viewportUnits") continue;
810
835
  if (key === "loopMotion") {
811
836
  const found = loopDeclarations(raw);
812
837
  if (found && found.every((d) => isSafeCssValue(d.value))) loop = found;
@@ -847,6 +872,7 @@ export function styleDeclarations(style: unknown): {
847
872
  rejected.push(key);
848
873
  }
849
874
  }
875
+ withViewportUnits(declarations, record["viewportUnits"]);
850
876
  const background = composeBackground(record);
851
877
  declarations.push(...background.declarations);
852
878
  rejected.push(...background.rejected);