@perkyzz/emvb 0.3.0 → 0.4.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 (121) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +3 -1
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/api.ts +17 -7
  6. package/src/admin/content-api.ts +7 -51
  7. package/src/admin/content-item.ts +22 -0
  8. package/src/admin/design-api.ts +30 -0
  9. package/src/admin/editor/A11yCopilot.tsx +1 -1
  10. package/src/admin/editor/Editor.tsx +106 -332
  11. package/src/admin/editor/EditorOverlay.tsx +3 -1
  12. package/src/admin/editor/PerfMeter.tsx +1 -1
  13. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  14. package/src/admin/editor/Timeline.tsx +16 -3
  15. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  16. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  17. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  18. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  19. package/src/admin/editor/canvas/drop-line.ts +24 -0
  20. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  21. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  22. package/src/admin/editor/collection-previews.ts +28 -5
  23. package/src/admin/editor/editor-chrome.tsx +346 -0
  24. package/src/admin/editor/editor-commands.ts +360 -0
  25. package/src/admin/editor/element-chrome.ts +89 -0
  26. package/src/admin/editor/feature-css.ts +15 -15
  27. package/src/admin/editor/host.ts +33 -0
  28. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  29. package/src/admin/editor/icons/library.ts +29 -19
  30. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  31. package/src/admin/editor/palette-items.ts +36 -5
  32. package/src/admin/editor/palette.ts +3 -2
  33. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  34. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  35. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  36. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  37. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  38. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  39. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  40. package/src/admin/editor/panels/inline-error.tsx +11 -0
  41. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  42. package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
  43. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  44. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  45. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  46. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  47. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  48. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  49. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  50. package/src/admin/editor/panels/style-target.ts +105 -0
  51. package/src/admin/editor/section-templates.ts +43 -21
  52. package/src/admin/editor/shortcuts.ts +4 -0
  53. package/src/admin/editor/store.ts +10 -1
  54. package/src/admin/editor/useClipboardActions.ts +1 -1
  55. package/src/admin/editor/useEditorCommands.ts +61 -13
  56. package/src/admin/editor/useEditorData.ts +7 -1
  57. package/src/admin/editor/useEditorShortcuts.ts +23 -15
  58. package/src/admin/editor/useNodeActions.ts +6 -1
  59. package/src/admin/forms-api.ts +17 -6
  60. package/src/admin/icon-uploads-api.ts +18 -0
  61. package/src/admin/theme-api.ts +5 -18
  62. package/src/astro/content-port.ts +24 -0
  63. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  64. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  65. package/src/astro/forms/client.ts +1 -0
  66. package/src/astro/forms-definitions.ts +24 -11
  67. package/src/astro/index.ts +1 -0
  68. package/src/astro/render-session.ts +85 -0
  69. package/src/astro/request-data.ts +20 -8
  70. package/src/astro/resolve-theme.ts +166 -76
  71. package/src/astro/resolve.ts +57 -16
  72. package/src/astro/theme-posts.ts +16 -5
  73. package/src/astro/visitor.ts +67 -5
  74. package/src/constants.ts +1 -1
  75. package/src/core/arrange.ts +63 -38
  76. package/src/core/audience/rules.ts +22 -2
  77. package/src/core/canvas-styles.ts +24 -0
  78. package/src/core/clipboard.ts +11 -32
  79. package/src/core/css/generate.ts +9 -0
  80. package/src/core/css/print.ts +12 -0
  81. package/src/core/css/scope.ts +3 -3
  82. package/src/core/css-keywords.ts +83 -0
  83. package/src/core/data/bindings.ts +4 -6
  84. package/src/core/design/classes.ts +13 -15
  85. package/src/core/design/diff.ts +55 -0
  86. package/src/core/design/merge.ts +127 -0
  87. package/src/core/design/variables.ts +25 -21
  88. package/src/core/elements/dynamic-elements.ts +30 -0
  89. package/src/core/elements/form-elements.ts +1 -0
  90. package/src/core/elements/index.ts +183 -7
  91. package/src/core/forms/binding.ts +4 -13
  92. package/src/core/index.ts +10 -0
  93. package/src/core/local-style.ts +27 -0
  94. package/src/core/migrate/index.ts +9 -4
  95. package/src/core/nesting.ts +4 -23
  96. package/src/core/perf/scripts.ts +9 -6
  97. package/src/core/record.ts +3 -0
  98. package/src/core/render/context.ts +2 -0
  99. package/src/core/render/dynamic-post.ts +1 -2
  100. package/src/core/render/form.ts +133 -10
  101. package/src/core/render/index.ts +155 -13
  102. package/src/core/render/vnode.ts +12 -2
  103. package/src/core/sanitize/css.ts +90 -77
  104. package/src/core/sanitize/svg.ts +8 -3
  105. package/src/core/sanitize/url.ts +10 -1
  106. package/src/core/schema/design.ts +5 -7
  107. package/src/core/schema/layout.ts +153 -181
  108. package/src/core/schema/style.ts +53 -63
  109. package/src/core/share/link.ts +68 -28
  110. package/src/core/tabs/presence.ts +7 -17
  111. package/src/core/theme/dynamic.ts +200 -39
  112. package/src/core/theme/float.ts +1 -1
  113. package/src/core/tree-ops.ts +57 -0
  114. package/src/index.ts +14 -2
  115. package/src/server/design-routes.ts +4 -1
  116. package/src/server/icon-routes.ts +68 -16
  117. package/src/server/plugin.ts +8 -2
  118. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  119. package/src/admin/editor/icons/sets/lucide.json +0 -1
  120. package/src/admin/editor/icons/sets/remix.json +0 -1
  121. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -7,6 +7,9 @@ import type { VNode } from "./vnode.ts";
7
7
 
8
8
  export const FORMS_SUBMIT_PATH = "/_emdash/api/plugins/emdash-forms/submit";
9
9
 
10
+ /** What a paused form shows on the page (W-326). */
11
+ export const FORM_PAUSED_TEXT = "This form isn't accepting responses right now.";
12
+
10
13
  const honeypot = (inputId: string): VNode => ({
11
14
  tag: "div",
12
15
  attrs: {
@@ -64,16 +67,34 @@ export function renderForm(
64
67
  children: ["Bind a form in settings to preview it here."],
65
68
  };
66
69
  }
70
+ // W-326: a paused form says so, in place of fields that can't be sent (the forms plugin refuses
71
+ // its submissions), with no form, inputs or Submit button.
72
+ if (ctx.definitions.get(formId)?.status === "paused") {
73
+ return {
74
+ tag: "div",
75
+ attrs: {
76
+ ...attrs,
77
+ class: `${attrs.class} emvb-form-paused`.trim(),
78
+ role: "status",
79
+ "data-emvb-form-paused": "",
80
+ },
81
+ children: [{ tag: "p", attrs: {}, children: [FORM_PAUSED_TEXT] }],
82
+ };
83
+ }
67
84
  // W-203: the forms client puts this label back on the button after each submit, so it must be
68
85
  // the label the page shows, not the form definition's.
69
86
  const submitLabel =
70
87
  firstSubmitLabel(node.children) ??
71
88
  ctx.definitions.get(formId)?.settings.submitLabel ??
72
89
  "Submit";
90
+ const previousForm = ctx.formId;
91
+ ctx.formId = formId;
92
+ const fieldNodes = ctx.children(node.children, dynamic);
93
+ ctx.formId = previousForm;
73
94
  const page: VNode = {
74
95
  tag: "div",
75
96
  attrs: { "data-page": "0" },
76
- children: ctx.children(node.children, dynamic),
97
+ children: fieldNodes,
77
98
  };
78
99
  return {
79
100
  tag: "form",
@@ -131,6 +152,107 @@ const LENGTH_TYPES = new Set(["text", "email", "tel", "url", "textarea"]);
131
152
  const isControl = (node: VNode) =>
132
153
  ["input", "select", "textarea"].includes(node.tag) && node.attrs.type !== "hidden";
133
154
 
155
+ /**
156
+ * A `pattern` the browser can compile. A group that can repeat and that itself contains `|` or
157
+ * another quantifier (`(a+)+`, `(a|aa)+`) is left off: it can hang the visitor's tab while they
158
+ * type. A pattern that does not compile is left off too.
159
+ */
160
+ function hasControlChar(value: string): boolean {
161
+ for (const char of value) {
162
+ const code = char.charCodeAt(0);
163
+ if (code < 32 || code === 127) return true;
164
+ }
165
+ return false;
166
+ }
167
+
168
+ /** How much of `pattern` at `index` is a quantifier, and whether it can repeat enough to hang. */
169
+ function quantifierAt(
170
+ pattern: string,
171
+ index: number,
172
+ ): { consumed: number; dangerous: boolean; repeats: boolean } {
173
+ const none = { consumed: 0, dangerous: false, repeats: false };
174
+ const ch = pattern[index];
175
+ if (ch === "+" || ch === "*") {
176
+ const lazy = pattern[index + 1] === "?" ? 1 : 0;
177
+ return { consumed: 1 + lazy, dangerous: true, repeats: true };
178
+ }
179
+ if (ch === "?") return { consumed: 1, dangerous: false, repeats: false };
180
+ if (ch !== "{") return none;
181
+ const match = /^\{(\d+)(?:\s*,\s*(\d+)?)?\}\??/.exec(pattern.slice(index));
182
+ if (!match) return none;
183
+ const min = Number(match[1]);
184
+ const hasComma = match[0].includes(",");
185
+ const max =
186
+ match[2] === undefined ? (hasComma ? Number.POSITIVE_INFINITY : min) : Number(match[2]);
187
+ if (max < min) return none;
188
+ return { consumed: match[0].length, dangerous: max > 20, repeats: max > 1 };
189
+ }
190
+
191
+ /**
192
+ * True when a group that contains `|` or a quantifier is itself repeated without a small bound.
193
+ * `(abc)+` and `(https?:\/\/)?` stay allowed.
194
+ */
195
+ function repeatsARiskyGroup(pattern: string): boolean {
196
+ const stack: { risky: boolean }[] = [];
197
+ let inClass = false;
198
+ const mark = () => {
199
+ const frame = stack[stack.length - 1];
200
+ if (frame) frame.risky = true;
201
+ };
202
+ for (let i = 0; i < pattern.length; i += 1) {
203
+ const ch = pattern[i];
204
+ if (ch === "\\") {
205
+ i += 1;
206
+ continue;
207
+ }
208
+ if (inClass) {
209
+ if (ch === "]") inClass = false;
210
+ continue;
211
+ }
212
+ if (ch === "[") {
213
+ inClass = true;
214
+ continue;
215
+ }
216
+ if (ch === "(") {
217
+ stack.push({ risky: false });
218
+ continue;
219
+ }
220
+ if (ch === ")") {
221
+ const frame = stack.pop();
222
+ if (!frame) return true;
223
+ const quantifier = quantifierAt(pattern, i + 1);
224
+ if (quantifier.dangerous && frame.risky) return true;
225
+ if (quantifier.repeats || frame.risky) mark();
226
+ i += quantifier.consumed;
227
+ continue;
228
+ }
229
+ if (ch === "|" || ch === "+" || ch === "*" || ch === "?") {
230
+ mark();
231
+ continue;
232
+ }
233
+ if (ch === "{") {
234
+ const quantifier = quantifierAt(pattern, i);
235
+ if (quantifier.consumed === 0) continue;
236
+ mark();
237
+ i += quantifier.consumed - 1;
238
+ }
239
+ }
240
+ return false;
241
+ }
242
+
243
+ function safeInputPattern(pattern: string): string | undefined {
244
+ const value = pattern.trim();
245
+ if (!value || value.length > 200 || hasControlChar(value)) return undefined;
246
+ if (repeatsARiskyGroup(value)) return undefined;
247
+ try {
248
+ const compiled = new RegExp(value);
249
+ compiled.test("");
250
+ } catch {
251
+ return undefined;
252
+ }
253
+ return value;
254
+ }
255
+
134
256
  /**
135
257
  * W-297: what the forms plugin's own embed puts on a control: the input type (so phones show the
136
258
  * right keyboard), `required`, and the length, range and pattern limits, plus a visible mark on
@@ -151,7 +273,8 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
151
273
  if (rules.max !== undefined) limits.max = String(rules.max);
152
274
  }
153
275
  if (node.type === "text-input" && kind !== "number" && kind !== "date" && rules.pattern) {
154
- limits.pattern = rules.pattern;
276
+ const pattern = safeInputPattern(rules.pattern);
277
+ if (pattern) limits.pattern = pattern;
155
278
  }
156
279
  }
157
280
  const mark: VNode = {
@@ -186,20 +309,20 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
186
309
  });
187
310
  }
188
311
 
189
- /** Fills a field from the first bound form definition that has it: options, type, limits. */
312
+ /** Fills a field from the form it sits in: options, type, limits. Other forms are left alone. */
190
313
  export function withFieldOptions(
191
314
  vnode: VNode,
192
315
  node: LayoutNode,
193
316
  definitions: FormDefinitions,
317
+ formId?: string,
194
318
  ): VNode {
195
319
  const field = (node.props as { field?: unknown }).field;
196
- if (typeof field !== "string") return vnode;
197
- for (const definition of definitions.values()) {
198
- const meta = fieldByName(definition, field);
199
- if (!meta) continue;
200
- return withFieldMeta(withOptions(vnode, node, meta), node, meta);
201
- }
202
- return vnode;
320
+ if (typeof field !== "string" || !formId) return vnode;
321
+ const definition = definitions.get(formId);
322
+ if (!definition) return vnode;
323
+ const meta = fieldByName(definition, field);
324
+ if (!meta) return vnode;
325
+ return withFieldMeta(withOptions(vnode, node, meta), node, meta);
203
326
  }
204
327
 
205
328
  /** A select or radio field filled with the definition's options. */
@@ -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,10 @@ 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");
172
221
  const knownVariables = new Set(design.variables.colors.map((c) => c.id));
173
222
  let backgroundVideo = false;
174
223
 
@@ -253,12 +302,37 @@ export function renderPage(
253
302
  declarations.push({ property: "--emvb-loop-columns", value: String(columns) });
254
303
  }
255
304
  }
305
+ if (node.container) declarations.push({ property: "container-type", value: "inline-size" });
306
+ if (node.type === "image") {
307
+ const focal = node.props as { focalX?: unknown; focalY?: unknown };
308
+ const position = objectPosition(focal.focalX, focal.focalY);
309
+ if (position) {
310
+ declarations.push({ property: "object-position", value: position });
311
+ declarations.push({ property: "object-fit", value: "cover" });
312
+ }
313
+ }
314
+ if (node.type === "button") {
315
+ const gap = (node.props as { iconGap?: unknown }).iconGap;
316
+ if (typeof gap === "number" && Number.isInteger(gap) && gap >= 0 && gap <= 64) {
317
+ declarations.push({ property: "gap", value: `${gap}px` });
318
+ }
319
+ }
320
+ const queryStyle = node.query ? styleDeclarations(node.query.style) : undefined;
321
+ for (const key of queryStyle?.rejected ?? []) {
322
+ warnings.push({ nodeId, code: "rejected-style", detail: key });
323
+ }
256
324
  if (node.type === "grid") {
257
325
  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"]));
326
+ declarations.push(...gridTemplate(props["columnTracks"], props["columns"]));
327
+ // Tablet and mobile counts go in their media queries (W-139). Custom tracks replace them.
328
+ const tabletColumns = gridTemplate(props["columnTracksTablet"], props["columnsTablet"]);
329
+ const mobileColumns = gridTemplate(props["columnTracksMobile"], props["columnsMobile"]);
330
+ if (props["columnTracksTablet"] !== undefined || props["columnsTablet"] !== undefined) {
331
+ tablet.declarations.unshift(...tabletColumns);
332
+ }
333
+ if (props["columnTracksMobile"] !== undefined || props["columnsMobile"] !== undefined) {
334
+ mobile.declarations.unshift(...mobileColumns);
335
+ }
262
336
  }
263
337
  const states = stateDeclarations(node.states);
264
338
  for (const key of states.rejected) {
@@ -274,9 +348,14 @@ export function renderPage(
274
348
  tablet.declarations.length > 0 ||
275
349
  mobile.declarations.length > 0 ||
276
350
  (hiddenOn?.length ?? 0) > 0;
351
+ const queryDeclarations = queryStyle?.declarations ?? [];
352
+ const queryMin = containerQueryMin(node.query?.min);
277
353
  if (
278
354
  ruleId &&
279
- (declarations.length > 0 || Object.keys(states.states).length > 0 || responsive)
355
+ (declarations.length > 0 ||
356
+ Object.keys(states.states).length > 0 ||
357
+ responsive ||
358
+ (queryDeclarations.length > 0 && queryMin !== undefined))
280
359
  ) {
281
360
  classes.push(`emvb-e-${ruleId}`);
282
361
  localRules.push({
@@ -286,13 +365,18 @@ export function renderPage(
286
365
  tablet: tablet.declarations,
287
366
  mobile: mobile.declarations,
288
367
  hiddenOn,
368
+ ...(queryDeclarations.length > 0 && queryMin !== undefined
369
+ ? { query: queryDeclarations, queryMin }
370
+ : {}),
289
371
  });
290
372
  }
291
373
  const attrs: Record<string, string> = { class: classes.join(" "), ...customAttributes(node) };
292
374
  if (mode === "editor" && id) attrs["data-emvb-id"] = id;
293
375
  if (node.htmlId && HTML_ID.test(node.htmlId)) attrs.id = node.htmlId;
376
+ else if (node.type === "heading" && id && layoutHasToc) attrs.id = `emvb-h-${id}`;
294
377
  // 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;
378
+ if (node.dir === "ltr" || node.dir === "rtl" || node.dir === "auto") attrs.dir = node.dir;
379
+ else if (isRoot && design.direction) attrs.dir = design.direction;
296
380
  return attrs;
297
381
  };
298
382
 
@@ -346,6 +430,10 @@ export function renderPage(
346
430
  );
347
431
  }
348
432
  if (isTabsNode(node)) return finish(node, renderTabs(node, id, attrs, ctx, dynamic));
433
+ if (node.type === "toc") {
434
+ const built = def.build(node as never, attrs, []);
435
+ return finish(node, { ...built, children: tocChildren(layout, node, mode) });
436
+ }
349
437
  if (isParentNode(node)) {
350
438
  return finish(node, def.build(node as never, attrs, ctx.children(node.children, dynamic)));
351
439
  }
@@ -353,7 +441,12 @@ export function renderPage(
353
441
  const preview = videoPreview(node, attrs);
354
442
  if (preview) return finish(node, preview);
355
443
  }
356
- const built = withFieldOptions(def.build(node as never, attrs, []), node, ctx.definitions);
444
+ const built = withFieldOptions(
445
+ def.build(node as never, attrs, []),
446
+ node,
447
+ ctx.definitions,
448
+ ctx.formId,
449
+ );
357
450
  return finish(node, FIELD_TYPES.has(type) && id ? uniqueField(built, controlId(id)) : built);
358
451
  }
359
452
 
@@ -389,13 +482,12 @@ export function renderPage(
389
482
  };
390
483
  }
391
484
 
392
- const vnode = visit(layout.root, true) ?? {
485
+ const page = visit(layout.root, true) ?? {
393
486
  tag: "div",
394
487
  attrs: { class: "emvb-root" },
395
488
  children: [],
396
489
  };
397
490
  const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
398
- const html = serialize(vnode);
399
491
  const css = generateCss({
400
492
  design,
401
493
  usedTypes,
@@ -406,10 +498,14 @@ export function renderPage(
406
498
  ...(mode === "editor" && opts.previewDevice ? { previewDevice: opts.previewDevice } : {}),
407
499
  });
408
500
  const scope = opts.scope === undefined ? undefined : cssScopeToken(opts.scope);
501
+ const vnode = scope
502
+ ? { tag: "div", attrs: { class: scopeClassName(scope) }, children: [page] }
503
+ : page;
504
+ const html = serialize(vnode);
409
505
  return {
410
506
  vnode,
411
- html: scope ? `<div ${scopeAttribute(scope)}>${html}</div>` : html,
412
- css: scope ? scopeWrapperCss() + scopeCss(css, scope) : css,
507
+ html,
508
+ css: (scope ? scopeWrapperCss() + scopeCss(css, scope) : css) + printCss(),
413
509
  needsFormsRuntime: rendered.form || layoutHasForm(layout),
414
510
  needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
415
511
  needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
@@ -417,3 +513,49 @@ export function renderPage(
417
513
  warnings,
418
514
  };
419
515
  }
516
+
517
+ function treeHasType(node: LayoutNode, type: string): boolean {
518
+ return someNode(node, (current) => current.type === type);
519
+ }
520
+
521
+ function headingAnchors(root: LayoutNode): { id: string; text: string }[] {
522
+ const out: { id: string; text: string }[] = [];
523
+ forEachNode(root, (node) => {
524
+ if (node.type !== "heading") return;
525
+ const text = String((node.props as { text?: unknown }).text ?? "").trim();
526
+ if (!text) return;
527
+ const id = node.htmlId && HTML_ID.test(node.htmlId) ? node.htmlId : `emvb-h-${node.id}`;
528
+ out.push({ id, text });
529
+ });
530
+ return out;
531
+ }
532
+
533
+ function tocChildren(layout: Layout, node: LayoutNode, mode: RenderMode): (VNode | string)[] {
534
+ const title =
535
+ node.type === "toc"
536
+ ? String((node.props as { title?: unknown }).title ?? "").trim() || undefined
537
+ : undefined;
538
+ const items = headingAnchors(layout.root);
539
+ const children: (VNode | string)[] = [];
540
+ if (title) children.push({ tag: "p", attrs: { class: "emvb-toc-title" }, children: [title] });
541
+ if (items.length === 0) {
542
+ if (mode === "editor") {
543
+ children.push({
544
+ tag: "p",
545
+ attrs: {},
546
+ children: ["Headings on this page appear here."],
547
+ });
548
+ }
549
+ return children;
550
+ }
551
+ children.push({
552
+ tag: "ol",
553
+ attrs: {},
554
+ children: items.map((item) => ({
555
+ tag: "li",
556
+ attrs: {},
557
+ children: [{ tag: "a", attrs: { href: `#${item.id}` }, children: [item.text] }],
558
+ })),
559
+ });
560
+ return children;
561
+ }
@@ -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);