@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
@@ -107,7 +107,7 @@ export const AUDIENCE_DEVICES = ["mobile", "tablet", "desktop"] as const;
107
107
  /** A visitor segment name the host passes and a Visitors rule matches (W-329). */
108
108
  /** A host segment name: letters, digits, and `:` `_` `-`, up to 64 characters (`plan:pro`). */
109
109
  export const AUDIENCE_SEGMENT = /^[a-z0-9][a-z0-9:_-]{0,63}$/;
110
- const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, e.g. plan:pro";
110
+ const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, such as plan:pro";
111
111
 
112
112
  /**
113
113
  * Who sees an element (W-313): visitors from these countries, on these devices, new or
@@ -117,7 +117,7 @@ const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, e.g. pl
117
117
  */
118
118
  export const Audience = z.strictObject({
119
119
  countries: z
120
- .array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes, e.g. CA"))
120
+ .array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes, such as CA"))
121
121
  .min(1)
122
122
  .max(50)
123
123
  .optional(),
@@ -567,7 +567,7 @@ export const PostLinkNode = leafNode(
567
567
  export const LOOP_DISPLAYS = ["list", "grid", "cards"] as const;
568
568
  /** A collection field's slug, e.g. `photo` (W-330). */
569
569
  const FIELD_SLUG = /^[a-z][a-z0-9_]{0,63}$/;
570
- const FIELD_SLUG_HINT = "Use the field's slug, e.g. photo";
570
+ const FIELD_SLUG_HINT = "Use the field's slug, such as photo";
571
571
  /** A site path with `{slug}` or `{id}`, and no other placeholders (W-330). */
572
572
  export const LOOP_PERMALINK =
573
573
  /^(?=.*\{(?:slug|id)\})\/(?!\/)(?:[A-Za-z0-9._~/-]|\{slug\}|\{id\})*$/;
@@ -593,7 +593,7 @@ export const LoopNode = parentNode(
593
593
  */
594
594
  collection: z
595
595
  .string()
596
- .regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug, e.g. team")
596
+ .regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug, such as team")
597
597
  .optional(),
598
598
  /** How many entries a collection Loop shows, 1–50. Unset = 6. */
599
599
  limit: z.number().int().min(1).max(50).optional(),
@@ -608,7 +608,7 @@ export const LoopNode = parentNode(
608
608
  permalink: z
609
609
  .string()
610
610
  .max(200)
611
- .regex(LOOP_PERMALINK, "A site path with {slug} or {id}, e.g. /team/{slug}")
611
+ .regex(LOOP_PERMALINK, "A site path with {slug} or {id}, such as /team/{slug}")
612
612
  .optional(),
613
613
  /** The entry field holding the image Post Image shows (W-330). Unset = featured_image. */
614
614
  imageField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
@@ -650,6 +650,14 @@ export const PaginationNode = leafNode(
650
650
  * Unset = "{title} – page {page}". Hosts read it with `archivePageTitle`.
651
651
  */
652
652
  titleText: z.string().max(60).optional(),
653
+ archiveTitle: z.string().max(60).optional(),
654
+ /** W-689: screen reader names in the site's language. Unset = "Pagination". */
655
+ navLabel: z.string().max(60).optional(),
656
+ /** Each number's name; `{page}` is filled in. Unset = "Page {page}". */
657
+ pageLabel: z.string().max(60).optional(),
658
+ /** Previous / Next names when their text is only an arrow. Unset = "Previous page" / "Next page". */
659
+ prevLabel: z.string().max(60).optional(),
660
+ nextLabel: z.string().max(60).optional(),
653
661
  }),
654
662
  );
655
663
 
@@ -910,7 +918,8 @@ export type TabPanelNode = NodeEnvelope & {
910
918
 
911
919
  export type TabsNode = NodeEnvelope & {
912
920
  type: "tabs";
913
- props: { href?: string; newTab?: boolean };
921
+ /** W-790: read from TabsNodeSchema, so the type can't drift from what the schema accepts. */
922
+ props: z.infer<typeof TabsNodeSchema>["props"];
914
923
  children: LayoutNode[];
915
924
  };
916
925
 
package/src/core/stats.ts CHANGED
@@ -12,7 +12,8 @@ export function summarizeLayout(input: unknown): LayoutSummary | undefined {
12
12
  if (typeof node !== "object" || node === null) continue;
13
13
  nodes++;
14
14
  const children = (node as { children?: unknown }).children;
15
- if (Array.isArray(children)) stack.push(...children);
15
+ // No spread: a huge children list would overflow the call stack (W-646).
16
+ if (Array.isArray(children)) for (const child of children) stack.push(child);
16
17
  }
17
18
  return { nodes, schemaVersion };
18
19
  }
@@ -142,8 +142,10 @@ export function conditionSpecificity(rule: ConditionRule): number {
142
142
  if (
143
143
  rule.group === "archive" &&
144
144
  rule.name === "taxonomy" &&
145
- typeof rule.args["slug"] === "string"
145
+ typeof rule.args["slug"] === "string" &&
146
+ rule.args["slug"] !== ""
146
147
  ) {
148
+ // A blank slug matches every term (taxonomyMatches), so it is not more specific (W-584).
147
149
  score += 5;
148
150
  }
149
151
  return score;
@@ -41,6 +41,8 @@ export type ThemeDynamicData = {
41
41
  sectionTemplates?: Record<string, Layout>;
42
42
  /** Section part ids already being expanded, so a section cannot include itself. */
43
43
  sectionStack?: readonly string[];
44
+ /** Loop item parts being rendered, outermost first, so a part that lists itself stops (W-654). */
45
+ loopStack?: readonly string[];
44
46
  /**
45
47
  * Where the nodes being rendered come from (W-250): unset for the page itself, else the synced
46
48
  * section and loop item parts they were expanded from. Another layout can reuse an id.
@@ -170,8 +172,14 @@ const hasText = (nodes: readonly (VNode | string)[]): boolean =>
170
172
  */
171
173
  export function portableTextToVNodes(value: unknown): VNode[] {
172
174
  if (typeof value === "string") {
173
- const trimmed = value.trim();
174
- return trimmed ? [{ tag: "p", attrs: {}, children: [trimmed] }] : [];
175
+ // W-662: plain-text content kept its blank lines and line breaks as raw newlines, which
176
+ // the page collapses, so every paragraph ran together into one.
177
+ return value
178
+ .replaceAll("\r\n", "\n")
179
+ .split(/\n[ \t]*\n/)
180
+ .map((para) => para.trim())
181
+ .filter(Boolean)
182
+ .map((para) => ({ tag: "p", attrs: {}, children: withBreaks(para) }));
175
183
  }
176
184
  if (!Array.isArray(value)) return [];
177
185
  const out: VNode[] = [];
@@ -214,9 +222,32 @@ export function portableTextToVNodes(value: unknown): VNode[] {
214
222
  const tag = style === "normal" ? "p" : style;
215
223
  out.push({ tag, attrs: {}, children: inline });
216
224
  }
217
- return out.filter((node) =>
218
- node.tag !== "ul" && node.tag !== "ol" ? true : node.children.length > 0,
219
- );
225
+ return pruneEmptyLists(out);
226
+ }
227
+
228
+ /**
229
+ * Lists with no items dropped at every depth (W-585): a blank nested item used to leave an empty
230
+ * `<ul>` inside its parent item, or an `<li>` holding only that empty list.
231
+ */
232
+ const isList = (n: VNode): boolean => n.tag === "ul" || n.tag === "ol";
233
+
234
+ function pruneEmptyLists(nodes: VNode[]): VNode[] {
235
+ const keep: VNode[] = [];
236
+ for (const node of nodes) {
237
+ if (isList(node)) {
238
+ const items: VNode[] = [];
239
+ for (const li of node.children) {
240
+ if (typeof li === "string") continue;
241
+ li.children = li.children.flatMap((c) =>
242
+ typeof c !== "string" && isList(c) ? pruneEmptyLists([c]) : [c],
243
+ );
244
+ if (li.children.length > 0) items.push(li);
245
+ }
246
+ node.children = items;
247
+ if (items.length > 0) keep.push(node);
248
+ } else keep.push(node);
249
+ }
250
+ return keep;
220
251
  }
221
252
 
222
253
  /** Collect `loop.itemPartId` values so hosts can load Loop Item templates. */
@@ -1,3 +1,4 @@
1
+ import { chromeLabel } from "./popup-markup.ts";
1
2
  import { z } from "zod";
2
3
  import { escapeAttr } from "../sanitize/escape.ts";
3
4
  import type { DesignSystem } from "../schema/design.ts";
@@ -43,6 +44,8 @@ export function validateFloatSettings(raw: unknown): FloatValidation {
43
44
 
44
45
  /**
45
46
  * Chrome for pinned bars and corner floats. Loaded only when a float matches.
47
+ * W-759: a corner float keeps its 1rem gap on both sides and never grows past the screen; a long
48
+ * one scrolls inside (on a phone it ran off the top, taking its close button and heading with it).
46
49
  * Bars reserve their height through the two custom properties the runtime sets.
47
50
  */
48
51
  export const FLOAT_CHROME_CSS = `
@@ -57,9 +60,11 @@ export const FLOAT_CHROME_CSS = `
57
60
  :where(.emvb-float--surface){background:#fff;color:#0f172a;box-shadow:0 4px 16px -4px rgba(15,23,42,.25);padding:.5rem 1rem}
58
61
  :where(.emvb-float--surface:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom)){border-radius:.75rem;padding:.75rem 1rem}
59
62
  .emvb-float__body{min-width:0;flex:1}
63
+ .emvb-float:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom){max-width:calc(100% - 2rem)}
64
+ .emvb-float:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom) .emvb-float__body{max-height:calc(100vh - 3.5rem);max-height:calc(100dvh - 3.5rem);overflow:auto}
60
65
  .emvb-float__close{flex:none;width:2rem;height:2rem;border:0;border-radius:999px;background:transparent;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
61
66
  .emvb-float__close:focus-visible{outline:2px solid #2563eb;outline-offset:2px}
62
- html{--emvb-float-top:0px;--emvb-float-bottom:0px}
67
+ html{--emvb-float-top:0px;--emvb-float-bottom:0px;scroll-padding-top:var(--emvb-float-top);scroll-padding-bottom:var(--emvb-float-bottom)}
63
68
  body{padding-top:var(--emvb-float-top);padding-bottom:var(--emvb-float-bottom)}
64
69
  `
65
70
  .replace(/\n+/g, "")
@@ -97,12 +102,14 @@ export function wrapFloatMarkup(
97
102
  bodyHtml: string,
98
103
  settings: FloatSettings,
99
104
  surface = true,
105
+ /** W-690: the close button's name in the site's language. Unset is "Close". */
106
+ closeLabel?: string,
100
107
  ): string {
101
108
  const safeId = escapeAttr(id);
102
109
  const label = escapeAttr(title.trim() || "Notice");
103
110
  const edge = escapeAttr(settings.edge);
104
111
  const close = settings.dismiss
105
- ? `<button type="button" class="emvb-float__close" data-emvb-float-dismiss aria-label="Close"><span aria-hidden="true">×</span></button>`
112
+ ? `<button type="button" class="emvb-float__close" data-emvb-float-dismiss aria-label="${chromeLabel(closeLabel, "Close")}"><span aria-hidden="true">×</span></button>`
106
113
  : "";
107
114
  return [
108
115
  `<aside class="emvb-float emvb-float--${edge}${surface ? " emvb-float--surface" : ""}" id="emvb-float-${safeId}" data-emvb-float="${safeId}" data-emvb-float-edge="${edge}" role="region" aria-label="${label}">`,
@@ -28,6 +28,14 @@ function knownTotal(p: ArchivePagination): number | undefined {
28
28
  : undefined;
29
29
  }
30
30
 
31
+ /**
32
+ * What leads into the total, dropped with it while the total is unknown: "of", "/" and the like.
33
+ * W-702: more languages ("z", "av", "od", "共"…) and a separator before them ("2, of"); "Strona 2 z"
34
+ * and "第 2 页,共" were left dangling.
35
+ */
36
+ const TOTAL_LEAD_IN =
37
+ /\s*[,,、·|/–—-]?\s*(?:(?<!\p{L})(?:of|from|out of|sur|de|da|do|von|di|van|av|af|z|ze|od|iš|из|з)|共|中)?\s*[,,、·|/–—-]?\s*$/iu;
38
+
31
39
  /**
32
40
  * The "Page N of M" text (W-309). `{page}` and `{total}` are filled in; without a known total
33
41
  * the text stops before ` of {total}` (or drops `{total}`), so it never shows a wrong count.
@@ -39,10 +47,7 @@ export function pageCountText(p: ArchivePagination, template: string | undefined
39
47
  return text.replaceAll("{page}", String(p.page)).replaceAll("{total}", String(total));
40
48
  }
41
49
  const cut = text.indexOf("{total}");
42
- const before =
43
- cut === -1
44
- ? text
45
- : text.slice(0, cut).replace(/\s*(of|\/|from|sur|de|von|di|van|из)?\s*$/i, "");
50
+ const before = cut === -1 ? text : text.slice(0, cut).replace(TOTAL_LEAD_IN, "");
46
51
  // A template that starts with {total} ("{total} pages · page {page}") keeps at least the number.
47
52
  return before.replaceAll("{page}", String(p.page)).trim() || String(p.page);
48
53
  }
@@ -104,7 +109,11 @@ export function archivePageTitle(
104
109
  ): string {
105
110
  if (page === undefined || page <= 1) return title;
106
111
  const wording = template?.trim().includes("{page}") ? template.trim() : PAGED_TITLE;
107
- return wording.replaceAll("{title}", title).replaceAll("{page}", String(page));
112
+ // One pass with a function: `$&` in a title is not a replacement pattern, and a "{page}" in
113
+ // the title stays as written (W-552).
114
+ return wording.replace(/\{(title|page)\}/g, (_, key: string) =>
115
+ key === "title" ? title : String(page),
116
+ );
108
117
  }
109
118
 
110
119
  /** One entry of a Pagination bar: a page link, the current page, or a gap (W-222). */
@@ -132,7 +141,9 @@ export function paginationItems(p: ArchivePagination): PaginationItem[] {
132
141
  if (p.page > 1) items.push({ kind: "prev", href: archivePagePath(p.basePath, p.page - 1) });
133
142
  const from = Math.max(1, p.page - 2);
134
143
  if (from > 1) items.push(page(1));
135
- if (from > 2) items.push({ kind: "gap" });
144
+ // W-600: "1 … 3" hides just page 2; show it instead of a gap.
145
+ if (from === 3) items.push(page(2));
146
+ if (from > 3) items.push({ kind: "gap" });
136
147
  for (let n = from; n <= p.page; n++) items.push(page(n));
137
148
  if (p.hasMore) {
138
149
  items.push(page(p.page + 1));
@@ -155,21 +166,24 @@ function totalItems(p: ArchivePagination, total: number): PaginationItem[] {
155
166
  const from = Math.max(1, p.page - 2);
156
167
  const to = Math.min(total, p.page + 2);
157
168
  if (from > 1) items.push(page(1));
158
- if (from > 2) items.push({ kind: "gap" });
169
+ // W-600: "1 … 3" hides just page 2; show it instead of a gap.
170
+ if (from === 3) items.push(page(2));
171
+ if (from > 3) items.push({ kind: "gap" });
159
172
  for (let n = from; n <= to; n++) items.push(page(n));
160
- if (to < total - 1) items.push({ kind: "gap" });
173
+ if (to === total - 2) items.push(page(total - 1));
174
+ if (to < total - 2) items.push({ kind: "gap" });
161
175
  if (to < total) items.push(page(total));
162
176
  if (p.page < total) items.push({ kind: "next", href: archivePagePath(p.basePath, p.page + 1) });
163
177
  return items;
164
178
  }
165
179
 
166
- /** The first Pagination element's "Page title text" in an archive layout, if set (W-529). */
167
- export function paginationTitleText(layout: Layout): string | undefined {
180
+ /** A text prop of the first Pagination element in an archive layout, if set (W-529, W-532). */
181
+ function paginationText(layout: Layout, key: "titleText" | "archiveTitle"): string | undefined {
168
182
  let found: string | undefined;
169
183
  const walk = (node: LayoutNode): void => {
170
184
  if (found !== undefined) return;
171
185
  if (node.type === "pagination") {
172
- const text = (node.props as { titleText?: unknown }).titleText;
186
+ const text = (node.props as Record<string, unknown>)[key];
173
187
  found = typeof text === "string" && text.trim() ? text.trim() : "";
174
188
  return;
175
189
  }
@@ -178,3 +192,9 @@ export function paginationTitleText(layout: Layout): string | undefined {
178
192
  walk(layout.root);
179
193
  return found || undefined;
180
194
  }
195
+
196
+ /** The first Pagination element's "Page title text" in an archive layout, if set (W-529). */
197
+ export const paginationTitleText = (layout: Layout) => paginationText(layout, "titleText");
198
+
199
+ /** The first Pagination element's "Posts archive title" (replaces "Posts"), if set (W-532). */
200
+ export const paginationArchiveTitle = (layout: Layout) => paginationText(layout, "archiveTitle");
@@ -1,19 +1,31 @@
1
+ import { clipText } from "../limits.ts";
1
2
  import { escapeAttr } from "../sanitize/escape.ts";
2
3
  import type { TriggersDoc } from "./triggers.ts";
3
4
 
4
- /** Minimal chrome styles for public popups (loaded only when popups match). */
5
+ /**
6
+ * Minimal chrome styles for public popups (loaded only when popups match). W-758: the close
7
+ * button sticks to the top of a long popup (it scrolled away with the content on phones) and
8
+ * floats, so a long heading wraps beside it instead of running under it.
9
+ */
5
10
  export const POPUP_CHROME_CSS = `
6
11
  .emvb-popup{position:fixed;inset:0;z-index:10000;display:flex;align-items:center;justify-content:center;padding:1.5rem;box-sizing:border-box}
7
12
  .emvb-popup[hidden]{display:none!important}
8
13
  .emvb-popup__backdrop{position:absolute;inset:0;background:rgba(15,23,42,.55)}
9
14
  .emvb-popup__dialog{position:relative;z-index:1;max-width:min(36rem,100%);max-height:min(90vh,100%);overflow:auto;background:#fff;color:#0f172a;border-radius:.75rem;box-shadow:0 25px 50px -12px rgba(0,0,0,.35);padding:1.5rem 1.5rem 1.25rem}
10
- .emvb-popup__close{position:absolute;top:.5rem;right:.5rem;width:2rem;height:2rem;border:0;border-radius:999px;background:transparent;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
15
+ .emvb-popup__close{position:sticky;top:-1rem;z-index:1;float:right;margin:-1rem -1rem 0 .5rem;width:2rem;height:2rem;border:0;border-radius:999px;background:inherit;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
11
16
  .emvb-popup__close:focus-visible{outline:2px solid #2563eb;outline-offset:2px}
12
17
  .emvb-popup__content{min-width:12rem}
13
18
  `
14
19
  .replace(/\n+/g, "")
15
20
  .trim();
16
21
 
22
+ /** Screen reader names for popup and float chrome; unset are "Popup" and "Close" (W-690). */
23
+ export type ChromeLabels = { popup?: string; close?: string };
24
+
25
+ /** A label clipped to 80 characters and escaped for an attribute, or the English fallback. */
26
+ export const chromeLabel = (text: string | undefined, fallback: string) =>
27
+ escapeAttr(clipText(text?.trim() ?? "", 80) || fallback);
28
+
17
29
  export type PopupPublicConfig = {
18
30
  id: string;
19
31
  triggers: TriggersDoc;
@@ -23,7 +35,13 @@ export type PopupPublicConfig = {
23
35
  * Wrap rendered popup body HTML with dialog chrome and a JSON config attribute
24
36
  * for the optional public runtime (R-031: only loaded when popups are present).
25
37
  */
26
- export function wrapPopupMarkup(id: string, bodyHtml: string, triggers: TriggersDoc): string {
38
+ export function wrapPopupMarkup(
39
+ id: string,
40
+ bodyHtml: string,
41
+ triggers: TriggersDoc,
42
+ /** W-690: the dialog's fallback name and the close button's name, in the site's language. */
43
+ labels: ChromeLabels = {},
44
+ ): string {
27
45
  const config: PopupPublicConfig = { id, triggers };
28
46
  const configJson = escapeAttr(JSON.stringify(config));
29
47
  const safeId = escapeAttr(id);
@@ -33,8 +51,8 @@ export function wrapPopupMarkup(id: string, bodyHtml: string, triggers: Triggers
33
51
  `<div class="emvb-popup__backdrop" data-emvb-popup-dismiss tabindex="-1"></div>`,
34
52
  // W-282: named "Popup" until the runtime points the name at the content's first heading;
35
53
  // naming it after the whole content read every word as the dialog's name.
36
- `<div class="emvb-popup__dialog" role="dialog" aria-modal="true" aria-label="Popup" tabindex="-1">`,
37
- `<button type="button" class="emvb-popup__close" data-emvb-popup-dismiss aria-label="Close"><span aria-hidden="true">×</span></button>`,
54
+ `<div class="emvb-popup__dialog" role="dialog" aria-modal="true" aria-label="${chromeLabel(labels.popup, "Popup")}" tabindex="-1">`,
55
+ `<button type="button" class="emvb-popup__close" data-emvb-popup-dismiss aria-label="${chromeLabel(labels.close, "Close")}"><span aria-hidden="true">×</span></button>`,
38
56
  `<div class="emvb-popup__content" id="${titleId}">${bodyHtml}</div>`,
39
57
  `</div></div>`,
40
58
  ].join("");
@@ -6,6 +6,7 @@ export const TRIGGER_LIMITS = {
6
6
  maxDelayMs: 120_000,
7
7
  maxScrollPercent: 100,
8
8
  minIdleMs: 1_000,
9
+ maxClickSelectorLength: 200,
9
10
  } as const;
10
11
 
11
12
  export const POPUP_DEVICES = ["desktop", "tablet", "mobile"] as const;
@@ -4,7 +4,7 @@ import { POPUP_DEVICES, TRIGGER_LIMITS } from "./popup-rules.ts";
4
4
 
5
5
  export const TRIGGERS_SCHEMA_VERSION = 1;
6
6
  export const MAX_POPUP_TRIGGERS = 8;
7
- const MAX_CLICK_SELECTOR_LENGTH = 200;
7
+ const MAX_CLICK_SELECTOR_LENGTH = TRIGGER_LIMITS.maxClickSelectorLength;
8
8
  const MAX_SHOW_TIMES = 100;
9
9
 
10
10
  /** Open triggers (Elementor-inspired). URL rules / scheduling / A/B deferred (W-081). */
@@ -97,7 +97,8 @@ export function validateTriggers(raw: unknown): TriggersValidation {
97
97
  export function isSafeClickSelector(selector: string): boolean {
98
98
  const trimmed = selector.trim();
99
99
  if (!trimmed || trimmed.length > MAX_CLICK_SELECTOR_LENGTH) return false;
100
- if (/[<>`]/.test(trimmed)) return false;
100
+ // W-613: `>` is the child combinator; the config attribute escapes it, like every quote.
101
+ if (/[<`]/.test(trimmed)) return false;
101
102
  if (/javascript:/i.test(trimmed)) return false;
102
103
  // Allow common CSS selector chars only.
103
104
  return /^[a-zA-Z0-9\s\-_.#[\]=,:()>+~*"'|/]+$/.test(trimmed);
@@ -183,6 +183,33 @@ export function starterLayout(title: string, random?: () => number): Layout {
183
183
  };
184
184
  }
185
185
 
186
+ /**
187
+ * W-554: a page's URL slug from its title, made the way EmDash makes entry slugs: NFKC,
188
+ * lowercase, spaces and underscores to hyphens, and letters, digits and marks of any script
189
+ * kept, cut to 80 characters as people see them. Empty when nothing usable is left (EmDash
190
+ * would then name it `untitled-…`). Class and variable ids keep `slugify`'s ASCII.
191
+ */
192
+ export function pageSlug(text: string, max = 80): string {
193
+ const slug = text
194
+ .normalize("NFKC")
195
+ .toLowerCase()
196
+ .replace(/[\s_]+/gu, "-")
197
+ .replace(/[^\p{L}\p{N}\p{M}-]+/gu, "")
198
+ .replace(/-+/g, "-")
199
+ .replace(/^-+|-+$/g, "");
200
+ if (!/[\p{L}\p{N}]/u.test(slug)) return "";
201
+ let out = "";
202
+ let count = 0;
203
+ for (const { segment } of new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(
204
+ slug,
205
+ )) {
206
+ if (count >= max) break;
207
+ out += segment;
208
+ count++;
209
+ }
210
+ return out.replace(/-+$/g, "");
211
+ }
212
+
186
213
  /** A URL slug from a title: lowercase ASCII letters, digits and single hyphens. */
187
214
  export function slugify(text: string): string {
188
215
  return text
@@ -47,10 +47,11 @@ export async function hitRateLimit(
47
47
  const stored = await store.getVersioned<Window>(key);
48
48
  const current = stored && stored.value?.w === w ? stored.value.n : 0;
49
49
  if (current >= limit) {
50
+ // W-754: "1 second", not "1 seconds", in the last second of a window.
50
51
  const retryAfterSeconds = Math.max(1, Math.ceil((w + windowMs - at) / 1000));
51
52
  throw new McpToolError(
52
53
  "RATE_LIMITED",
53
- `Too many ${NOUNS[cls]}: this token may make ${limit} ${per}. Try again in ${retryAfterSeconds} seconds.`,
54
+ `Too many ${NOUNS[cls]}: this token may make ${limit} ${per}. Try again in ${retryAfterSeconds} ${retryAfterSeconds === 1 ? "second" : "seconds"}.`,
54
55
  { retryAfterSeconds, limit, per },
55
56
  );
56
57
  }
package/src/mcp/read.ts CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  type LayoutNode,
18
18
  } from "../core/index.ts";
19
19
  import { parentChildRefusal } from "../core/arrange.ts";
20
+ import { clipText } from "../core/limits.ts";
20
21
  import { KNOWN_NODE_SCHEMAS } from "../core/schema/layout.ts";
21
22
  import { requiredFieldIssues, requiredFieldIssueText } from "../core/forms/binding.ts";
22
23
  import { isFormNode } from "../core/schema/layout.ts";
@@ -63,7 +64,7 @@ function summaryText(node: LayoutNode): string | undefined {
63
64
  const props = (node as { props?: Record<string, unknown> }).props ?? {};
64
65
  const text = typeof props["text"] === "string" ? props["text"] : undefined;
65
66
  if (!text) return undefined;
66
- return text.length > 60 ? `${text.slice(0, 57)}…` : text;
67
+ return text.length > 60 ? `${clipText(text, 57)}…` : text;
67
68
  }
68
69
 
69
70
  function stats(layout: Layout) {
@@ -476,11 +477,22 @@ export const ListVersionsOutput = z.object({
476
477
  ),
477
478
  });
478
479
 
480
+ /**
481
+ * W-805: EmDash stores revision times as SQLite UTC text ("2026-10-21 03:17:01") with no zone, so
482
+ * an agent read them as local time. Hand them out as ISO 8601 UTC instead.
483
+ */
484
+ const utcIso = (at: string) =>
485
+ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?$/.test(at) ? `${at.replace(" ", "T")}Z` : at;
486
+
479
487
  export async function listVersions(ports: EmvbPorts, input: z.infer<typeof ListVersionsInput>) {
480
488
  const page = await ports.getPage(input.pageId);
481
489
  if (!page) throw new McpToolError("NOT_FOUND", `No EmVB page with id ${input.pageId}.`);
482
490
  const revisions = await ports.listRevisions(input.pageId, input.limit ?? 20);
483
491
  return {
484
- versions: revisions.map((r) => ({ revisionId: r.id, at: r.createdAt, authorId: r.authorId })),
492
+ versions: revisions.map((r) => ({
493
+ revisionId: r.id,
494
+ at: utcIso(r.createdAt),
495
+ authorId: r.authorId,
496
+ })),
485
497
  };
486
498
  }
package/src/mcp/refs.ts CHANGED
@@ -10,6 +10,21 @@ const KINDS: [keyof DesignSystem["variables"], From][] = [
10
10
  ["spacings", "spacing"],
11
11
  ];
12
12
 
13
+ /** True when `value` nests objects or arrays more than `max` levels, checked without recursion. */
14
+ export function nestsDeeperThan(value: unknown, max: number): boolean {
15
+ const stack: [unknown, number][] = [[value, 1]];
16
+ while (stack.length > 0) {
17
+ const [item, depth] = stack.pop() as [unknown, number];
18
+ if (typeof item !== "object" || item === null) continue;
19
+ if (depth > max) return true;
20
+ for (const child of Object.values(item)) stack.push([child, depth + 1]);
21
+ }
22
+ return false;
23
+ }
24
+
25
+ /** Deeper than any element spec or style the tools accept; refused before the walk below recurses (W-652). */
26
+ const MAX_INPUT_NESTING = 256;
27
+
13
28
  const isRecord = (v: unknown): v is Record<string, unknown> =>
14
29
  typeof v === "object" && v !== null && !Array.isArray(v);
15
30
 
@@ -23,6 +38,9 @@ const isRef = (v: Record<string, unknown>) =>
23
38
  * Class names in `classes` are checked the same way.
24
39
  */
25
40
  export function resolveDesignRefs<T>(value: T, design: DesignSystem): T {
41
+ if (nestsDeeperThan(value, MAX_INPUT_NESTING)) {
42
+ throw new McpToolError("INVALID_INPUT", "This input nests too deeply.");
43
+ }
26
44
  const kinds = new Map<string, From[]>();
27
45
  for (const [key, from] of KINDS) {
28
46
  for (const v of design.variables[key] ?? [])