@perkyzz/emvb 0.5.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 (212) hide show
  1. package/README.md +4 -0
  2. package/THIRD_PARTY_NOTICES.md +23 -1
  3. package/licenses/exif-js.LICENSE +21 -0
  4. package/licenses/fflate.LICENSE +21 -0
  5. package/licenses/glfx.js.LICENSE +19 -0
  6. package/licenses/mini-photo-editor.LICENSE +21 -0
  7. package/licenses/photocn.LICENSE +21 -0
  8. package/package.json +2 -1
  9. package/src/admin/access/RequireEditor.tsx +7 -7
  10. package/src/admin/access/role.ts +5 -2
  11. package/src/admin/content-api.ts +10 -3
  12. package/src/admin/content-item.ts +1 -1
  13. package/src/admin/editor/A11yCopilot.tsx +104 -56
  14. package/src/admin/editor/CommandPalette.tsx +29 -13
  15. package/src/admin/editor/Editor.tsx +88 -20
  16. package/src/admin/editor/EditorToasts.tsx +26 -0
  17. package/src/admin/editor/PerfMeter.tsx +97 -72
  18. package/src/admin/editor/ShareLink.tsx +107 -72
  19. package/src/admin/editor/ShortcutsDialog.tsx +27 -16
  20. package/src/admin/editor/Timeline.tsx +255 -160
  21. package/src/admin/editor/TopBar.tsx +71 -14
  22. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  23. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  24. package/src/admin/editor/canvas/drop-line.ts +11 -3
  25. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  26. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  27. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  28. package/src/admin/editor/collection-previews.ts +16 -1
  29. package/src/admin/editor/dialogs.tsx +38 -14
  30. package/src/admin/editor/dnd/drop-target.ts +26 -1
  31. package/src/admin/editor/edited-noun.ts +15 -0
  32. package/src/admin/editor/editor-chrome.tsx +108 -7
  33. package/src/admin/editor/editor-commands.ts +15 -1
  34. package/src/admin/editor/editor-css.ts +75 -22
  35. package/src/admin/editor/element-chrome.ts +21 -11
  36. package/src/admin/editor/feature-css.ts +45 -13
  37. package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
  38. package/src/admin/editor/icons/library.ts +1 -1
  39. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  40. package/src/admin/editor/ime.ts +29 -0
  41. package/src/admin/editor/palette-items.ts +10 -3
  42. package/src/admin/editor/panels/AddPanel.tsx +35 -10
  43. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  44. package/src/admin/editor/panels/ColorControl.tsx +135 -27
  45. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  46. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  47. package/src/admin/editor/panels/LayersPanel.tsx +68 -22
  48. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  49. package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
  50. package/src/admin/editor/panels/TokenScales.tsx +76 -36
  51. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  52. package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
  53. package/src/admin/editor/panels/VariableSection.tsx +53 -21
  54. package/src/admin/editor/panels/color-space.ts +9 -3
  55. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  56. package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
  57. package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
  58. package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
  59. package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
  60. package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
  61. package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
  62. package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
  63. package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
  64. package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
  65. package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
  66. package/src/admin/editor/panels/settings/FieldControl.tsx +38 -15
  67. package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
  68. package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
  69. package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
  70. package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
  71. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
  72. package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
  73. package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
  74. package/src/admin/editor/panels/settings/MediaPicker.tsx +274 -20
  75. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  76. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  77. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  78. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  79. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +141 -0
  80. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  81. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  82. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  83. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  84. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  85. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  86. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  87. package/src/admin/editor/panels/site-list.tsx +20 -6
  88. package/src/admin/editor/panels/variable-values.ts +25 -4
  89. package/src/admin/editor/restore-deleted.ts +21 -2
  90. package/src/admin/editor/section-templates.ts +81 -12
  91. package/src/admin/editor/shortcuts.ts +17 -2
  92. package/src/admin/editor/store.ts +14 -3
  93. package/src/admin/editor/useEditorCommands.ts +61 -15
  94. package/src/admin/editor/useEditorData.ts +4 -2
  95. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  96. package/src/admin/editor/useNodeActions.ts +61 -6
  97. package/src/admin/editor/useSave.ts +22 -7
  98. package/src/admin/forms-api.ts +2 -0
  99. package/src/admin/image-editor/BlurFocus.tsx +112 -0
  100. package/src/admin/image-editor/Canvas.tsx +261 -0
  101. package/src/admin/image-editor/CropOverlay.tsx +390 -0
  102. package/src/admin/image-editor/CurvesPanel.tsx +395 -0
  103. package/src/admin/image-editor/ExportDialog.tsx +384 -0
  104. package/src/admin/image-editor/ImageEditButton.tsx +83 -0
  105. package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
  106. package/src/admin/image-editor/MetadataPanel.tsx +194 -0
  107. package/src/admin/image-editor/announce.tsx +65 -0
  108. package/src/admin/image-editor/crop-geometry.ts +162 -0
  109. package/src/admin/image-editor/curve-math.ts +177 -0
  110. package/src/admin/image-editor/data-url-fetch.ts +59 -0
  111. package/src/admin/image-editor/engine.ts +55 -0
  112. package/src/admin/image-editor/exif.ts +82 -0
  113. package/src/admin/image-editor/flatten.ts +54 -0
  114. package/src/admin/image-editor/gpu-fit.ts +81 -0
  115. package/src/admin/image-editor/image-editor-css.ts +400 -0
  116. package/src/admin/image-editor/load.ts +116 -0
  117. package/src/admin/image-editor/panels.tsx +287 -0
  118. package/src/admin/image-editor/parts.tsx +614 -0
  119. package/src/admin/image-editor/save.ts +141 -0
  120. package/src/admin/image-editor/tone-panels.tsx +338 -0
  121. package/src/admin/image-editor/tools.ts +59 -0
  122. package/src/admin/image-editor/worker.ts +111 -0
  123. package/src/admin/media-api.ts +114 -3
  124. package/src/admin/pages/AgentsPage.tsx +138 -27
  125. package/src/admin/pages/CreateDialog.tsx +97 -30
  126. package/src/admin/pages/NewPageDialog.tsx +21 -3
  127. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  128. package/src/admin/pages/PageList.tsx +14 -6
  129. package/src/admin/pages/SetupShell.tsx +28 -12
  130. package/src/admin/pages/ThemePartList.tsx +27 -7
  131. package/src/admin/pages/list-kit.tsx +106 -24
  132. package/src/admin/search.ts +15 -0
  133. package/src/admin/setup/useSetupStatus.ts +1 -1
  134. package/src/admin/theme-api.ts +13 -3
  135. package/src/admin/ui.ts +78 -22
  136. package/src/astro/EmVBPage.astro +11 -2
  137. package/src/astro/floats/runtime.ts +21 -0
  138. package/src/astro/menu/runtime.ts +34 -1
  139. package/src/astro/popups/runtime.ts +33 -3
  140. package/src/astro/render.ts +6 -0
  141. package/src/astro/resolve-theme.ts +67 -14
  142. package/src/astro/resolve.ts +9 -1
  143. package/src/astro/tabs/runtime.ts +12 -0
  144. package/src/astro/theme-posts.ts +2 -2
  145. package/src/astro/visitor.ts +6 -3
  146. package/src/constants.ts +1 -1
  147. package/src/core/a11y/audit.ts +171 -24
  148. package/src/core/arrange.ts +29 -6
  149. package/src/core/audience/rules.ts +5 -1
  150. package/src/core/audience/variants.ts +29 -3
  151. package/src/core/clipboard.ts +7 -0
  152. package/src/core/css/generate.ts +31 -6
  153. package/src/core/data/bindings.ts +19 -6
  154. package/src/core/design/classes.ts +20 -9
  155. package/src/core/design/diff.ts +9 -1
  156. package/src/core/design/merge.ts +93 -3
  157. package/src/core/design/tokens.ts +16 -2
  158. package/src/core/design/transfer.ts +46 -8
  159. package/src/core/design/variables.ts +32 -10
  160. package/src/core/elements/dynamic-elements.ts +53 -6
  161. package/src/core/elements/form-elements.ts +68 -30
  162. package/src/core/elements/index.ts +83 -38
  163. package/src/core/elements/menu.ts +37 -19
  164. package/src/core/elements/plain-text.ts +2 -2
  165. package/src/core/elements/select-prompt.ts +3 -0
  166. package/src/core/elements/svg-ids.ts +39 -0
  167. package/src/core/forms/binding.ts +190 -2
  168. package/src/core/forms/definition.ts +72 -0
  169. package/src/core/history/diff.ts +49 -4
  170. package/src/core/icons/catalog.ts +3 -2
  171. package/src/core/image-edit/schema.ts +155 -0
  172. package/src/core/image-edit/summary.ts +61 -0
  173. package/src/core/index.ts +29 -1
  174. package/src/core/limits.ts +21 -0
  175. package/src/core/migrate/index.ts +3 -1
  176. package/src/core/perf/meter.ts +51 -8
  177. package/src/core/recipes/index.ts +5 -4
  178. package/src/core/render/context.ts +8 -0
  179. package/src/core/render/dynamic-post.ts +71 -13
  180. package/src/core/render/extras.ts +77 -4
  181. package/src/core/render/form.ts +164 -12
  182. package/src/core/render/index.ts +179 -22
  183. package/src/core/render/loop.ts +43 -7
  184. package/src/core/render/pagination.ts +18 -4
  185. package/src/core/render/section.ts +27 -0
  186. package/src/core/render/tabs.ts +12 -3
  187. package/src/core/render/vnode.ts +1 -1
  188. package/src/core/sanitize/css.ts +15 -2
  189. package/src/core/sanitize/embed-url.ts +42 -5
  190. package/src/core/sanitize/url.ts +2 -1
  191. package/src/core/schema/layout.ts +26 -7
  192. package/src/core/share/link.ts +5 -2
  193. package/src/core/stable-json.ts +15 -0
  194. package/src/core/stats.ts +2 -1
  195. package/src/core/theme/conditions.ts +3 -1
  196. package/src/core/theme/dynamic.ts +57 -23
  197. package/src/core/theme/float.ts +9 -2
  198. package/src/core/theme/pagination.ts +57 -10
  199. package/src/core/theme/popup-markup.ts +23 -5
  200. package/src/core/theme/popup-rules.ts +11 -5
  201. package/src/core/theme/triggers.ts +3 -2
  202. package/src/core/tree-ops.ts +27 -0
  203. package/src/mcp/ports.ts +8 -1
  204. package/src/mcp/rate-limit.ts +2 -1
  205. package/src/mcp/read.ts +82 -3
  206. package/src/mcp/refs.ts +18 -0
  207. package/src/mcp/tools.ts +1 -1
  208. package/src/mcp/write.ts +271 -25
  209. package/src/server/agent-settings.ts +29 -4
  210. package/src/server/hooks.ts +5 -3
  211. package/src/server/icon-routes.ts +33 -9
  212. package/src/server/mcp-routes.ts +74 -11
@@ -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
  }
@@ -88,12 +93,27 @@ export function loopPerPage(layout: Layout): number {
88
93
  return found ?? DEFAULT_PER_PAGE;
89
94
  }
90
95
 
96
+ /** The paged archive title wording when the host passes none (W-229). */
97
+ const PAGED_TITLE = "{title} – page {page}";
98
+
91
99
  /**
92
100
  * A paged archive's title for `<title>` and headings: "Posts – page 2"; page 1 is the bare
93
- * title (W-229).
101
+ * title (W-229). W-529: `template` sets the wording in the site's language, with `{title}` and
102
+ * `{page}` filled in like the Pagination element's "Page {page} of {total}"; one without
103
+ * `{page}` would give every page the same title, so it falls back to the default.
94
104
  */
95
- export function archivePageTitle(title: string, page: number | undefined): string {
96
- return page !== undefined && page > 1 ? `${title} – page ${page}` : title;
105
+ export function archivePageTitle(
106
+ title: string,
107
+ page: number | undefined,
108
+ template?: string,
109
+ ): string {
110
+ if (page === undefined || page <= 1) return title;
111
+ const wording = template?.trim().includes("{page}") ? template.trim() : PAGED_TITLE;
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
+ );
97
117
  }
98
118
 
99
119
  /** One entry of a Pagination bar: a page link, the current page, or a gap (W-222). */
@@ -121,7 +141,9 @@ export function paginationItems(p: ArchivePagination): PaginationItem[] {
121
141
  if (p.page > 1) items.push({ kind: "prev", href: archivePagePath(p.basePath, p.page - 1) });
122
142
  const from = Math.max(1, p.page - 2);
123
143
  if (from > 1) items.push(page(1));
124
- 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" });
125
147
  for (let n = from; n <= p.page; n++) items.push(page(n));
126
148
  if (p.hasMore) {
127
149
  items.push(page(p.page + 1));
@@ -144,10 +166,35 @@ function totalItems(p: ArchivePagination, total: number): PaginationItem[] {
144
166
  const from = Math.max(1, p.page - 2);
145
167
  const to = Math.min(total, p.page + 2);
146
168
  if (from > 1) items.push(page(1));
147
- 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" });
148
172
  for (let n = from; n <= to; n++) items.push(page(n));
149
- 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" });
150
175
  if (to < total) items.push(page(total));
151
176
  if (p.page < total) items.push({ kind: "next", href: archivePagePath(p.basePath, p.page + 1) });
152
177
  return items;
153
178
  }
179
+
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 {
182
+ let found: string | undefined;
183
+ const walk = (node: LayoutNode): void => {
184
+ if (found !== undefined) return;
185
+ if (node.type === "pagination") {
186
+ const text = (node.props as Record<string, unknown>)[key];
187
+ found = typeof text === "string" && text.trim() ? text.trim() : "";
188
+ return;
189
+ }
190
+ if (isParentNode(node)) for (const child of node.children) walk(child);
191
+ };
192
+ walk(layout.root);
193
+ return found || undefined;
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;
@@ -18,13 +19,18 @@ export type PopupDevice = (typeof POPUP_DEVICES)[number];
18
19
  */
19
20
  export const DEVICE_PREVIEW_PX = { desktop: 1280, tablet: 768, mobile: 390 } as const;
20
21
 
21
- /** Public CSS queries. Bounds match `deviceForWidth`: 767 mobile, 1024 tablet, 1025 desktop. */
22
+ /**
23
+ * Public CSS queries. Bounds match `deviceForWidth`: below 768 mobile, below 1025 tablet.
24
+ * W-506: zoom and display scaling give fractional viewport widths; with whole-pixel bounds a
25
+ * width such as 1024.5 matched neither the tablet nor the desktop "hide" query, so an element
26
+ * hidden on both showed. The max bounds sit just under the next device's min (as Bootstrap does).
27
+ */
22
28
  export const DEVICE_MEDIA = {
23
- tablet: "(max-width: 1024px)",
24
- mobile: "(max-width: 767px)",
29
+ tablet: "(max-width: 1024.98px)",
30
+ mobile: "(max-width: 767.98px)",
25
31
  hideDesktop: "(min-width: 1025px)",
26
- hideTablet: "(min-width: 768px) and (max-width: 1024px)",
27
- hideMobile: "(max-width: 767px)",
32
+ hideTablet: "(min-width: 768px) and (max-width: 1024.98px)",
33
+ hideMobile: "(max-width: 767.98px)",
28
34
  } as const;
29
35
 
30
36
  /** A scroll percent as a number from 0 to 100; anything unreadable is 0. */
@@ -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
package/src/mcp/ports.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AgentSettings } from "./settings.ts";
2
2
  import type { RateClass } from "./rate-limit.ts";
3
- import type { DesignSystem, Layout } from "../core/index.ts";
3
+ import type { DesignSystem, Layout, RequiredFieldInfo } from "../core/index.ts";
4
4
 
5
5
  /** A page as the tool core sees it: the current draft (or published) data and its revision. */
6
6
  export type PageRecord = {
@@ -75,4 +75,11 @@ export interface EmvbPorts {
75
75
  publishPage(id: string, expectedRev: string): Promise<{ rev: string }>;
76
76
  /** Publishes the style draft when the published revision is still `expectedPublishedRevision`. */
77
77
  publishDesign(expectedPublishedRevision: string | null): Promise<{ revision: string }>;
78
+ /**
79
+ * W-511: each form's fields as the forms plugin defines them, for describe_page's required-field
80
+ * warnings. Forms it can't read are left out; without this port there are no such warnings.
81
+ */
82
+ formFields?(
83
+ formIds: readonly string[],
84
+ ): Promise<ReadonlyMap<string, readonly RequiredFieldInfo[]>>;
78
85
  }
@@ -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,8 +17,11 @@ 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
- import { nodeChildren } from "../core/tree-ops.ts";
22
+ import { requiredFieldIssues, requiredFieldIssueText } from "../core/forms/binding.ts";
23
+ import { isFormNode } from "../core/schema/layout.ts";
24
+ import { forEachNode, nodeChildren } from "../core/tree-ops.ts";
22
25
  import { McpToolError } from "./errors.ts";
23
26
  import type { EmvbPorts, PageRecord } from "./ports.ts";
24
27
 
@@ -61,7 +64,7 @@ function summaryText(node: LayoutNode): string | undefined {
61
64
  const props = (node as { props?: Record<string, unknown> }).props ?? {};
62
65
  const text = typeof props["text"] === "string" ? props["text"] : undefined;
63
66
  if (!text) return undefined;
64
- return text.length > 60 ? `${text.slice(0, 57)}…` : text;
67
+ return text.length > 60 ? `${clipText(text, 57)}…` : text;
65
68
  }
66
69
 
67
70
  function stats(layout: Layout) {
@@ -282,6 +285,8 @@ export const DescribePageOutput = z.object({
282
285
  }),
283
286
  ),
284
287
  headingOutline: z.array(z.string()),
288
+ /** W-500: things that make content vanish without an error, such as hidden on every device. */
289
+ warnings: z.array(z.object({ nodeId: z.string(), message: z.string() })).optional(),
285
290
  wordCount: z.number(),
286
291
  images: z
287
292
  .array(z.object({ id: z.string(), alt: z.string(), src: z.string(), decorative: z.boolean() }))
@@ -307,6 +312,64 @@ function imagesOf(root: LayoutNode) {
307
312
  return found;
308
313
  }
309
314
 
315
+ /** W-500: elements hidden on desktop, tablet and mobile never show; the agent should know. */
316
+ function hiddenEverywhere(root: LayoutNode) {
317
+ const warnings: { nodeId: string; message: string }[] = [];
318
+ const walk = (node: LayoutNode) => {
319
+ const hidden = new Set((node as { hiddenOn?: string[] }).hiddenOn ?? []);
320
+ if (hidden.has("desktop") && hidden.has("tablet") && hidden.has("mobile")) {
321
+ warnings.push({
322
+ nodeId: node.id,
323
+ message:
324
+ node.id === root.id
325
+ ? "The whole page is hidden on every device, so visitors see an empty page. Unset hiddenOn on the root."
326
+ : `${node.label ?? node.type} ${node.id} is hidden on every device, so it and everything inside it never show. Unset hiddenOn, or remove it.`,
327
+ });
328
+ return;
329
+ }
330
+ for (const child of nodeChildren(node)) walk(child);
331
+ };
332
+ walk(root);
333
+ return warnings.slice(0, 50);
334
+ }
335
+
336
+ /**
337
+ * W-511: required form fields visitors can't fill (missing from the form, or hidden on a device),
338
+ * so the form can't be sent there. Needs the forms plugin's definitions; none without them.
339
+ */
340
+ async function requiredFieldWarnings(ports: EmvbPorts, root: LayoutNode) {
341
+ const forms: LayoutNode[] = [];
342
+ forEachNode(root, (node) => {
343
+ if (isFormNode(node) && node.props.formId.trim() && forms.length < 20) forms.push(node);
344
+ });
345
+ if (forms.length === 0 || !ports.formFields) return [];
346
+ let fields: ReadonlyMap<string, readonly { name: string; label: string; required: boolean }[]>;
347
+ try {
348
+ fields = await ports.formFields([
349
+ ...new Set(forms.map((form) => (form.props as { formId: string }).formId.trim())),
350
+ ]);
351
+ } catch {
352
+ return [];
353
+ }
354
+ const warnings: { nodeId: string; message: string }[] = [];
355
+ for (const form of forms) {
356
+ const defined = fields.get((form.props as { formId: string }).formId.trim());
357
+ if (!defined) continue;
358
+ for (const issue of requiredFieldIssues(form, defined)) {
359
+ warnings.push({
360
+ nodeId: issue.kind === "missing" ? issue.formNodeId : issue.nodeId,
361
+ message:
362
+ issue.kind === "hidden"
363
+ ? `${requiredFieldIssueText(issue)} (Unset hiddenOn on ${issue.nodeId} or the box around it.)`
364
+ : issue.kind === "audience"
365
+ ? `${requiredFieldIssueText(issue)} (Unset audience or variant on ${issue.nodeId} or the box around it.)`
366
+ : `${requiredFieldIssueText(issue)} (Form ${issue.formNodeId}, field name ${issue.field}.)`,
367
+ });
368
+ }
369
+ }
370
+ return warnings;
371
+ }
372
+
310
373
  const clip = (text: string, max: number) =>
311
374
  text.length > max ? `${text.slice(0, max - 1)}…` : text;
312
375
 
@@ -336,6 +399,10 @@ export async function describePage(ports: EmvbPorts, input: z.infer<typeof Descr
336
399
  return section;
337
400
  });
338
401
  const wordCount = all.text.join(" ").split(/\s+/).filter(Boolean).length;
402
+ const warnings = [
403
+ ...hiddenEverywhere(layout.root),
404
+ ...(await requiredFieldWarnings(ports, layout.root)),
405
+ ].slice(0, 50);
339
406
  const summary = clip(
340
407
  `"${page.title}" (/${page.slug}, ${page.status}${page.hasDraft ? ", unpublished changes" : ""}): ` +
341
408
  `${sections.length} top-level section${sections.length === 1 ? "" : "s"}, ` +
@@ -351,6 +418,7 @@ export async function describePage(ports: EmvbPorts, input: z.infer<typeof Descr
351
418
  headingOutline: all.headings,
352
419
  wordCount,
353
420
  images: imagesOf(layout.root),
421
+ ...(warnings.length ? { warnings } : {}),
354
422
  };
355
423
  }
356
424
 
@@ -409,11 +477,22 @@ export const ListVersionsOutput = z.object({
409
477
  ),
410
478
  });
411
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
+
412
487
  export async function listVersions(ports: EmvbPorts, input: z.infer<typeof ListVersionsInput>) {
413
488
  const page = await ports.getPage(input.pageId);
414
489
  if (!page) throw new McpToolError("NOT_FOUND", `No EmVB page with id ${input.pageId}.`);
415
490
  const revisions = await ports.listRevisions(input.pageId, input.limit ?? 20);
416
491
  return {
417
- 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
+ })),
418
497
  };
419
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] ?? [])
package/src/mcp/tools.ts CHANGED
@@ -50,7 +50,7 @@ const READ_TOOLS: ToolDef[] = [
50
50
  name: "get_layout",
51
51
  title: "Get a page layout",
52
52
  description:
53
- "Returns a page's layout (schema 15) and its revision `rev`. Use format \"outline\" first for a cheap tree of ids, types and labels; pass nodeId for one element's subtree.",
53
+ "Returns a page's layout (schema 16) and its revision `rev`. Use format \"outline\" first for a cheap tree of ids, types and labels; pass nodeId for one element's subtree.",
54
54
  input: read.GetLayoutInput,
55
55
  output: read.GetLayoutOutput,
56
56
  readOnly: true,