@perkyzz/emvb 0.6.0 → 0.8.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 (208) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/access/RequireEditor.tsx +7 -7
  5. package/src/admin/access/role.ts +5 -2
  6. package/src/admin/content-api.ts +10 -3
  7. package/src/admin/content-item.ts +1 -1
  8. package/src/admin/editor/A11yCopilot.tsx +104 -56
  9. package/src/admin/editor/CommandPalette.tsx +29 -13
  10. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  11. package/src/admin/editor/Editor.tsx +115 -20
  12. package/src/admin/editor/EditorToasts.tsx +26 -0
  13. package/src/admin/editor/PerfMeter.tsx +92 -73
  14. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  15. package/src/admin/editor/ShareLink.tsx +102 -72
  16. package/src/admin/editor/ShortcutsDialog.tsx +37 -18
  17. package/src/admin/editor/Timeline.tsx +250 -160
  18. package/src/admin/editor/TopBar.tsx +71 -14
  19. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  20. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  21. package/src/admin/editor/canvas/drop-line.ts +11 -3
  22. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  24. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  25. package/src/admin/editor/collection-previews.ts +10 -0
  26. package/src/admin/editor/dialogs.tsx +41 -28
  27. package/src/admin/editor/dnd/drop-target.ts +26 -1
  28. package/src/admin/editor/edited-noun.ts +15 -0
  29. package/src/admin/editor/editor-chrome.tsx +43 -7
  30. package/src/admin/editor/editor-commands.ts +17 -2
  31. package/src/admin/editor/editor-css.ts +75 -24
  32. package/src/admin/editor/element-chrome.ts +21 -11
  33. package/src/admin/editor/feature-css.ts +56 -14
  34. package/src/admin/editor/focus-when-lost.ts +23 -0
  35. package/src/admin/editor/icons/IconLibraryDialog.tsx +54 -18
  36. package/src/admin/editor/icons/library.ts +1 -1
  37. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  38. package/src/admin/editor/ime.ts +29 -0
  39. package/src/admin/editor/palette-items.ts +27 -3
  40. package/src/admin/editor/panels/AddPanel.tsx +44 -11
  41. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  42. package/src/admin/editor/panels/ColorControl.tsx +130 -23
  43. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  44. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  45. package/src/admin/editor/panels/LayersPanel.tsx +61 -20
  46. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  47. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  48. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  49. package/src/admin/editor/panels/SiteStylesDrawer.tsx +224 -42
  50. package/src/admin/editor/panels/TokenScales.tsx +88 -48
  51. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  52. package/src/admin/editor/panels/TriggersEditor.tsx +3 -2
  53. package/src/admin/editor/panels/VariableSection.tsx +48 -18
  54. package/src/admin/editor/panels/color-space.ts +23 -29
  55. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  56. package/src/admin/editor/panels/settings/AudienceEditor.tsx +87 -74
  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 +20 -8
  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 +33 -13
  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/LoopItemBindControl.tsx +1 -1
  75. package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
  76. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  77. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  78. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  79. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  80. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
  81. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  82. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  83. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  84. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  85. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  86. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  87. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  88. package/src/admin/editor/panels/site-list.tsx +20 -6
  89. package/src/admin/editor/panels/variable-values.ts +11 -4
  90. package/src/admin/editor/restore-deleted.ts +21 -2
  91. package/src/admin/editor/section-templates.ts +81 -12
  92. package/src/admin/editor/shortcuts.ts +31 -2
  93. package/src/admin/editor/store.ts +7 -0
  94. package/src/admin/editor/useEditorCommands.ts +61 -15
  95. package/src/admin/editor/useEditorData.ts +4 -2
  96. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  97. package/src/admin/editor/useNodeActions.ts +61 -6
  98. package/src/admin/editor/useSave.ts +22 -7
  99. package/src/admin/editor/useSavedSections.ts +197 -0
  100. package/src/admin/forms-api.ts +2 -0
  101. package/src/admin/image-editor/Canvas.tsx +61 -17
  102. package/src/admin/image-editor/CurvesPanel.tsx +2 -1
  103. package/src/admin/image-editor/ExportDialog.tsx +48 -18
  104. package/src/admin/image-editor/ImageEditorDialog.tsx +179 -8
  105. package/src/admin/image-editor/MetadataPanel.tsx +15 -4
  106. package/src/admin/image-editor/crop-geometry.ts +3 -2
  107. package/src/admin/image-editor/image-editor-css.ts +15 -10
  108. package/src/admin/image-editor/load.ts +9 -2
  109. package/src/admin/image-editor/parts.tsx +69 -19
  110. package/src/admin/image-editor/save.ts +54 -8
  111. package/src/admin/media-api.ts +2 -1
  112. package/src/admin/pages/AgentsPage.tsx +138 -27
  113. package/src/admin/pages/CreateDialog.tsx +97 -30
  114. package/src/admin/pages/NewPageDialog.tsx +21 -3
  115. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  116. package/src/admin/pages/PageList.tsx +14 -6
  117. package/src/admin/pages/SetupShell.tsx +28 -12
  118. package/src/admin/pages/ThemePartList.tsx +59 -11
  119. package/src/admin/pages/list-kit.tsx +106 -24
  120. package/src/admin/saved-sections-api.ts +51 -0
  121. package/src/admin/search.ts +15 -0
  122. package/src/admin/setup/useSetupStatus.ts +1 -1
  123. package/src/admin/theme-api.ts +16 -5
  124. package/src/admin/ui.ts +82 -22
  125. package/src/astro/floats/runtime.ts +21 -0
  126. package/src/astro/menu/runtime.ts +34 -1
  127. package/src/astro/popups/runtime.ts +41 -9
  128. package/src/astro/render.ts +3 -0
  129. package/src/astro/resolve-theme.ts +53 -11
  130. package/src/astro/resolve.ts +9 -1
  131. package/src/astro/tabs/runtime.ts +12 -0
  132. package/src/astro/theme-posts.ts +2 -2
  133. package/src/astro/visitor.ts +2 -0
  134. package/src/constants.ts +1 -1
  135. package/src/core/a11y/audit.ts +196 -24
  136. package/src/core/arrange.ts +48 -12
  137. package/src/core/audience/rules.ts +5 -1
  138. package/src/core/audience/variants.ts +29 -3
  139. package/src/core/clipboard.ts +7 -0
  140. package/src/core/css/generate.ts +31 -6
  141. package/src/core/css/print.ts +5 -0
  142. package/src/core/data/bindings.ts +8 -1
  143. package/src/core/design/classes.ts +39 -16
  144. package/src/core/design/devices.ts +7 -13
  145. package/src/core/design/diff.ts +6 -0
  146. package/src/core/design/merge.ts +90 -2
  147. package/src/core/design/states.ts +7 -13
  148. package/src/core/design/tokens.ts +16 -2
  149. package/src/core/design/transfer.ts +33 -6
  150. package/src/core/design/variables.ts +30 -9
  151. package/src/core/elements/dynamic-elements.ts +53 -14
  152. package/src/core/elements/form-elements.ts +55 -16
  153. package/src/core/elements/index.ts +84 -39
  154. package/src/core/elements/menu.ts +40 -19
  155. package/src/core/elements/select-prompt.ts +3 -0
  156. package/src/core/elements/svg-ids.ts +39 -0
  157. package/src/core/forms/binding.ts +57 -16
  158. package/src/core/forms/definition.ts +72 -0
  159. package/src/core/history/diff.ts +18 -1
  160. package/src/core/icons/animation-runs.ts +11 -0
  161. package/src/core/icons/catalog.ts +3 -2
  162. package/src/core/image-edit/schema.ts +11 -1
  163. package/src/core/image-edit/summary.ts +6 -3
  164. package/src/core/index.ts +35 -1
  165. package/src/core/limits.ts +12 -1
  166. package/src/core/migrate/index.ts +3 -0
  167. package/src/core/perf/meter.ts +42 -7
  168. package/src/core/recipes/index.ts +5 -4
  169. package/src/core/render/context.ts +8 -0
  170. package/src/core/render/dynamic-post.ts +69 -12
  171. package/src/core/render/extras.ts +77 -4
  172. package/src/core/render/form.ts +140 -6
  173. package/src/core/render/index.ts +156 -20
  174. package/src/core/render/loop.ts +44 -8
  175. package/src/core/render/pagination.ts +18 -4
  176. package/src/core/render/section.ts +27 -0
  177. package/src/core/render/tabs.ts +12 -3
  178. package/src/core/render/vnode.ts +1 -1
  179. package/src/core/sanitize/css.ts +29 -8
  180. package/src/core/sanitize/embed-url.ts +42 -5
  181. package/src/core/sanitize/url.ts +2 -1
  182. package/src/core/saved-sections.ts +318 -0
  183. package/src/core/schema/design.ts +1 -1
  184. package/src/core/schema/layout.ts +16 -7
  185. package/src/core/schema/style.ts +4 -2
  186. package/src/core/stats.ts +2 -1
  187. package/src/core/theme/conditions.ts +3 -1
  188. package/src/core/theme/dynamic.ts +36 -5
  189. package/src/core/theme/float.ts +12 -2
  190. package/src/core/theme/pagination.ts +50 -29
  191. package/src/core/theme/part-types.ts +4 -4
  192. package/src/core/theme/popup-markup.ts +23 -5
  193. package/src/core/theme/popup-rules.ts +1 -0
  194. package/src/core/theme/triggers.ts +3 -2
  195. package/src/core/tree-ops.ts +27 -0
  196. package/src/mcp/ports.ts +22 -1
  197. package/src/mcp/rate-limit.ts +2 -1
  198. package/src/mcp/read.ts +15 -3
  199. package/src/mcp/refs.ts +18 -0
  200. package/src/mcp/sections.ts +183 -0
  201. package/src/mcp/tools.ts +44 -0
  202. package/src/mcp/write.ts +178 -14
  203. package/src/server/agent-settings.ts +1 -1
  204. package/src/server/hooks.ts +5 -3
  205. package/src/server/icon-routes.ts +30 -9
  206. package/src/server/mcp-routes.ts +8 -1
  207. package/src/server/plugin.ts +14 -0
  208. package/src/server/saved-sections.ts +163 -0
@@ -27,14 +27,17 @@ function stampGroup(children: VNode["children"], name: string): VNode["children"
27
27
  }
28
28
 
29
29
  /** Runs of menu items become a list. Other elements stay in the panel beside that list. */
30
- function groupItems(children: VNode["children"]): VNode["children"] {
30
+ function groupItems(
31
+ children: VNode["children"],
32
+ listClass = "emvb-menu__list emvb-menu__list--sub",
33
+ ): VNode["children"] {
31
34
  const out: VNode["children"] = [];
32
35
  let batch: VNode[] = [];
33
36
  const flush = () => {
34
37
  if (batch.length === 0) return;
35
38
  out.push({
36
39
  tag: "ul",
37
- attrs: { class: "emvb-menu__list emvb-menu__list--sub" },
40
+ attrs: { class: listClass },
38
41
  children: batch,
39
42
  });
40
43
  batch = [];
@@ -63,17 +66,29 @@ const MENU_CSS = [
63
66
  ".emvb-menu-item__toggle{display:inline-flex;align-items:center;justify-content:center;width:1.75rem;height:1.75rem;padding:0;cursor:pointer;list-style:none}",
64
67
  ".emvb-menu-item__toggle::-webkit-details-marker{display:none}",
65
68
  ".emvb-menu-item__toggle::before{content:'';width:.4rem;height:.4rem;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;transform:rotate(45deg) translateY(-1px)}",
69
+ // W-614: the text toggle reads "Shop ⌄": text first, the chevron after it.
70
+ ".emvb-menu-item__toggle--label{width:auto;gap:.6rem;padding-inline-end:.35rem}",
71
+ ".emvb-menu-item__toggle--label::before{order:1}",
66
72
  ".emvb-menu-panel{display:none;position:absolute;z-index:30;top:100%;inset-inline-start:0;min-width:12rem;padding:.75rem;background:canvas;color:canvastext;border:1px solid #00000014;box-shadow:0 12px 32px #00000029}",
67
73
  ".emvb-menu-item__disclosure[open]>.emvb-menu-panel{display:block}",
68
- "@media (hover:hover) and (pointer:fine){.emvb-menu-item:hover>.emvb-menu-item__bar>.emvb-menu-item__disclosure>.emvb-menu-panel,.emvb-menu-item:focus-within>.emvb-menu-item__bar>.emvb-menu-item__disclosure>.emvb-menu-panel{display:block}}",
74
+ "@media (hover:hover) and (pointer:fine){.emvb-menu-item:not([data-emvb-menu-dismissed]):hover>.emvb-menu-item__bar>.emvb-menu-item__disclosure>.emvb-menu-panel,.emvb-menu-item:not([data-emvb-menu-dismissed]):focus-within>.emvb-menu-item__bar>.emvb-menu-item__disclosure>.emvb-menu-panel{display:block}}",
69
75
  // W-267: a closed <details> hides its content (::details-content is content-visibility:hidden),
70
76
  // so the hover rule above showed nothing until the details' content is made visible too. Its own
71
77
  // rule: a browser without ::details-content drops only this one. Hover only: keyboard users open
72
78
  // a dropdown with its toggle, and Tab doesn't walk through every closed dropdown's links.
73
- "@media (hover:hover) and (pointer:fine){.emvb-menu-item:hover>.emvb-menu-item__bar>.emvb-menu-item__disclosure::details-content{content-visibility:visible}}",
79
+ "@media (hover:hover) and (pointer:fine){.emvb-menu-item:not([data-emvb-menu-dismissed]):hover>.emvb-menu-item__bar>.emvb-menu-item__disclosure::details-content{content-visibility:visible}}",
80
+ // W-783: Escape marks the hovered item [data-emvb-menu-dismissed] (menu runtime) so a hover-shown
81
+ // panel can be dismissed without moving the pointer (WCAG 1.4.13).
74
82
  ".emvb-menu-panel--wide{inset-inline:0;min-width:0}",
83
+ // W-784: a column menu's items stretch to its width, so a flyout placed at the item's end
84
+ // opened far from its toggle (off the page in a full-width menu). Anchor it to the bar.
85
+ ".emvb-menu--column .emvb-menu-item{position:static}",
86
+ ".emvb-menu--column .emvb-menu-item__bar{position:relative;width:fit-content;max-width:100%}",
75
87
  ".emvb-menu--column .emvb-menu-panel{top:0;inset-inline-start:100%}",
76
88
  ".emvb-menu--column .emvb-menu-panel--wide{inset-inline:auto;inset-inline-start:100%;min-width:18rem}",
89
+ // W-847 (D-056): on a phone there is no room beside the item (the flyout overflowed by about
90
+ // 40-50 px), so a column flyout opens below its item instead, no wider than the screen.
91
+ "@media (max-width: 767.98px){.emvb-menu--column .emvb-menu-panel,.emvb-menu--column .emvb-menu-panel--wide{top:100%;inset-inline:auto;inset-inline-start:0;min-width:min(12rem,calc(100vw - 2rem));max-width:calc(100vw - 2rem)}}",
77
92
  ].join("");
78
93
 
79
94
  export const menu: ElementDefinition<MenuNode> = {
@@ -118,13 +133,9 @@ export const menu: ElementDefinition<MenuNode> = {
118
133
  return {
119
134
  tag: "nav",
120
135
  attrs: { ...attrs, class: classes, "aria-label": label },
121
- children: [
122
- {
123
- tag: "ul",
124
- attrs: { class: "emvb-menu__list" },
125
- children: stampGroup(children, `emvb-menu-${node.id}`),
126
- },
127
- ],
136
+ // W-601: an imported layout can put a non-item straight in the Menu; it sits beside the
137
+ // list, since a <ul> holds only <li>.
138
+ children: groupItems(stampGroup(children, `emvb-menu-${node.id}`), "emvb-menu__list"),
128
139
  };
129
140
  },
130
141
  };
@@ -138,11 +149,12 @@ export const menuItem: ElementDefinition<MenuItemNode> = {
138
149
  group: "content",
139
150
  defaultTab: "content",
140
151
  fields: [
141
- { key: "text", kind: "text", label: "Label" },
152
+ // UX-044: a menu item is a link, so its fields read like the Link and Button elements'.
153
+ { key: "text", kind: "text", label: "Text" },
142
154
  {
143
155
  key: "href",
144
156
  kind: "href",
145
- label: "Link",
157
+ label: "URL",
146
158
  optional: true,
147
159
  message: "Use a full URL such as https://example.com or a path such as /pricing.",
148
160
  },
@@ -161,18 +173,27 @@ export const menuItem: ElementDefinition<MenuItemNode> = {
161
173
  children: [node.props.text],
162
174
  }
163
175
  : { tag: "span", attrs: { class: "emvb-menu-item__label" }, children: [node.props.text] };
164
- const bar: VNode["children"] = [label];
176
+ // W-614: with no link, the item's text is the dropdown's toggle, so tapping "Shop" opens it
177
+ // (the chevron alone was a 28 px target, and the text did nothing on touch screens).
178
+ const textToggle = !href && children.length > 0;
179
+ const bar: VNode["children"] = textToggle ? [] : [label];
165
180
  if (children.length > 0) {
166
181
  const panelClass = wide ? "emvb-menu-panel emvb-menu-panel--wide" : "emvb-menu-panel";
167
182
  bar.push({
168
183
  tag: "details",
169
184
  attrs: { class: "emvb-menu-item__disclosure" },
170
185
  children: [
171
- {
172
- tag: "summary",
173
- attrs: { class: "emvb-menu-item__toggle", "aria-label": `Open ${node.props.text}` },
174
- children: [],
175
- },
186
+ textToggle
187
+ ? {
188
+ tag: "summary",
189
+ attrs: { class: "emvb-menu-item__toggle emvb-menu-item__toggle--label" },
190
+ children: [node.props.text],
191
+ }
192
+ : {
193
+ tag: "summary",
194
+ attrs: { class: "emvb-menu-item__toggle", "aria-label": `Open ${node.props.text}` },
195
+ children: [],
196
+ },
176
197
  {
177
198
  tag: "div",
178
199
  attrs: { class: panelClass },
@@ -0,0 +1,3 @@
1
+ /** The Select's empty first choice: its Placeholder, or "Choose…" (W-686). */
2
+ export const selectPrompt = (props: { placeholder?: string | undefined }): string =>
3
+ props.placeholder?.trim() || "Choose…";
@@ -0,0 +1,39 @@
1
+ import type { VNode } from "../render/vnode.ts";
2
+
3
+ const URL_REF = /url\(\s*(['"]?)#([^'")\s]+)\1\s*\)/g;
4
+ const ID_LIST_ATTRS = new Set(["aria-labelledby", "aria-describedby"]);
5
+
6
+ /**
7
+ * W-785: ids inside pasted SVG markup ("g", "a", "clip0") were rendered as-is, so two SVGs on
8
+ * a page using the same id resolved every url(#id) and href="#id" to the first one: a second
9
+ * gradient icon painted with the first one's colors. Prefix each internal id with the element's
10
+ * own id and rewrite the references to it. References to ids the SVG doesn't define are left.
11
+ */
12
+ export function scopeSvgIds(children: (VNode | string)[], prefix: string): (VNode | string)[] {
13
+ const ids = new Set<string>();
14
+ const collect = (node: VNode | string): void => {
15
+ if (typeof node === "string") return;
16
+ if (node.attrs.id) ids.add(node.attrs.id);
17
+ node.children.forEach(collect);
18
+ };
19
+ children.forEach(collect);
20
+ if (ids.size === 0) return children;
21
+ const scoped = (id: string) => (ids.has(id) ? `${prefix}-${id}` : id);
22
+ const rewrite = (node: VNode | string): VNode | string => {
23
+ if (typeof node === "string") return node;
24
+ const attrs: Record<string, string> = {};
25
+ for (const [name, value] of Object.entries(node.attrs)) {
26
+ if (name === "id") attrs[name] = scoped(value);
27
+ else if ((name === "href" || name === "xlink:href") && value.startsWith("#"))
28
+ attrs[name] = `#${scoped(value.slice(1))}`;
29
+ else if (ID_LIST_ATTRS.has(name)) attrs[name] = value.split(/\s+/).map(scoped).join(" ");
30
+ else
31
+ attrs[name] = value.replace(
32
+ URL_REF,
33
+ (_m, q: string, id: string) => `url(${q}#${scoped(id)}${q})`,
34
+ );
35
+ }
36
+ return { ...node, attrs, children: node.children.map(rewrite) };
37
+ };
38
+ return children.map(rewrite);
39
+ }
@@ -1,6 +1,13 @@
1
- import { isFormNode, type Layout, type LayoutNode } from "../schema/layout.ts";
1
+ import {
2
+ isFormNode,
3
+ LAYOUT_SCHEMA_VERSION,
4
+ type Layout,
5
+ type LayoutNode,
6
+ } from "../schema/layout.ts";
7
+ import { loneAbTests } from "../audience/variants.ts";
2
8
  import { audienceSummary } from "../audience/rules.ts";
3
9
  import { forEachNode, nodeChildren, someNode } from "../tree-ops.ts";
10
+ import { stableJson } from "../stable-json.ts";
4
11
  import { fieldsOf, type FormDefinitions } from "./definition.ts";
5
12
 
6
13
  export type MissingRequiredField = {
@@ -39,6 +46,8 @@ export function findMissingRequiredFields(
39
46
  const definition = definitions.get(node.props.formId);
40
47
  if (!definition) return;
41
48
  const bound = boundFields(node);
49
+ // W-595: a hidden field is sent by the form itself, with no control.
50
+ for (const field of fieldsOf(definition)) if (field.type === "hidden") bound.add(field.name);
42
51
  for (const field of fieldsOf(definition)) {
43
52
  if (field.required && !bound.has(field.name)) {
44
53
  missing.push({ formNodeId: node.id, formId: node.props.formId, field: field.name });
@@ -53,7 +62,7 @@ export function layoutHasForm(layout: Layout): boolean {
53
62
  }
54
63
 
55
64
  /** A field as the forms plugin defines it; only what the checks below read. */
56
- export type RequiredFieldInfo = { name: string; label: string; required: boolean };
65
+ export type RequiredFieldInfo = { name: string; label: string; required: boolean; type?: string };
57
66
 
58
67
  /**
59
68
  * A required field visitors can't fill (W-511): `missing` has no control in the form; `hidden`
@@ -85,13 +94,30 @@ const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "ra
85
94
  const DEVICE_ORDER = ["desktop", "tablet", "mobile"];
86
95
 
87
96
  /** Each bound field's controls, with the devices each is hidden on (itself or an ancestor). */
88
- type Control = { nodeId: string; hidden: Set<string>; who?: string };
97
+ type Control = { nodeId: string; hidden: Set<string>; who?: string; split?: string };
89
98
 
90
99
  /**
91
100
  * W-513: who an element is limited to, by a Visitors rule or as one arm of an A/B test, or
92
101
  * undefined when everyone sees it.
93
102
  */
94
- function restriction(node: LayoutNode): string | undefined {
103
+ /**
104
+ * W-550: the exact visitors split a node makes, e.g. "ab:hero:a" or "aud:1:{rules}". Two
105
+ * controls cover everyone when they are the two halves of one split; labels alone can't tell
106
+ * (they cut long country lists and leave out the time zone).
107
+ */
108
+ function splitKey(node: LayoutNode, lone: ReadonlySet<string>): string | undefined {
109
+ const audience = node.audience;
110
+ if (audience) {
111
+ const { hide, ...rules } = audience;
112
+ return `aud:${hide ? 1 : 0}:${stableJson(rules)}`;
113
+ }
114
+ if (node.variant && !lone.has(node.variant.test)) {
115
+ return `ab:${node.variant.test}:${node.variant.arm}`;
116
+ }
117
+ return undefined;
118
+ }
119
+
120
+ function restriction(node: LayoutNode, lone: ReadonlySet<string>): string | undefined {
95
121
  const audience = node.audience;
96
122
  if (audience) {
97
123
  const { hide, timeZone: _zone, ...rules } = audience;
@@ -99,27 +125,41 @@ function restriction(node: LayoutNode): string | undefined {
99
125
  return audienceSummary(audience);
100
126
  }
101
127
  }
102
- if (node.variant) {
128
+ // W-628: a test missing an arm isn't run, so its remaining arm reaches everyone.
129
+ if (node.variant && !lone.has(node.variant.test)) {
103
130
  return `Variant ${node.variant.arm.toUpperCase()} of A/B test ${node.variant.test}`;
104
131
  }
105
132
  return undefined;
106
133
  }
107
134
 
108
135
  function boundControls(form: LayoutNode): Map<string, Control[]> {
136
+ // A/B arms are siblings, so a test's arms inside a form are all inside it.
137
+ const lone = loneAbTests({ schemaVersion: LAYOUT_SCHEMA_VERSION, root: form } as Layout);
109
138
  const found = new Map<string, Control[]>();
110
- const walk = (node: LayoutNode, inherited: ReadonlySet<string>, limited: string | undefined) => {
139
+ const walk = (
140
+ node: LayoutNode,
141
+ inherited: ReadonlySet<string>,
142
+ limited: { who: string; split?: string } | undefined,
143
+ ) => {
111
144
  const own = (node as { hiddenOn?: readonly string[] }).hiddenOn ?? [];
112
145
  const hidden = own.length ? new Set([...inherited, ...own]) : inherited;
113
- const who = limited ?? restriction(node);
146
+ let scope = limited;
147
+ if (!scope) {
148
+ const who = restriction(node, lone);
149
+ if (who) scope = { who, split: splitKey(node, lone) };
150
+ }
114
151
  if (FIELD_TYPES.has(node.type)) {
115
152
  const field = (node.props as { field?: unknown }).field;
116
153
  if (typeof field === "string" && field) {
117
154
  const control: Control = { nodeId: node.id, hidden: new Set(hidden) };
118
- if (who) control.who = who;
155
+ if (scope) {
156
+ control.who = scope.who;
157
+ if (scope.split) control.split = scope.split;
158
+ }
119
159
  found.set(field, [...(found.get(field) ?? []), control]);
120
160
  }
121
161
  }
122
- for (const child of nodeChildren(node)) walk(child, hidden, who);
162
+ for (const child of nodeChildren(node)) walk(child, hidden, scope);
123
163
  };
124
164
  // The form's own hiddenOn or audience hides the whole form, which loses no answers: not counted.
125
165
  for (const child of nodeChildren(form)) walk(child, new Set(), undefined);
@@ -131,12 +171,12 @@ function boundControls(form: LayoutNode): Map<string, Control[]> {
131
171
  * "Hidden for X") still reach everyone.
132
172
  */
133
173
  function coversEveryone(controls: readonly Control[]): boolean {
134
- const who = new Set(controls.map((control) => control.who));
135
- for (const label of who) {
136
- if (!label) continue;
137
- const ab = /^Variant ([AB]) of (A\/B test .+)$/.exec(label);
138
- if (ab && who.has(`Variant ${ab[1] === "A" ? "B" : "A"} of ${ab[2]}`)) return true;
139
- if (label.startsWith("Only ") && who.has(`Hidden for ${label.slice(5)}`)) return true;
174
+ const splits = new Set(controls.map((control) => control.split));
175
+ for (const key of splits) {
176
+ if (!key) continue;
177
+ const ab = /^ab:(.*):([ab])$/.exec(key);
178
+ if (ab && splits.has(`ab:${ab[1]}:${ab[2] === "a" ? "b" : "a"}`)) return true;
179
+ if (key.startsWith("aud:0:") && splits.has(`aud:1:${key.slice(6)}`)) return true;
140
180
  }
141
181
  return false;
142
182
  }
@@ -149,7 +189,8 @@ export function requiredFieldIssues(
149
189
  const controls = boundControls(form);
150
190
  const issues: RequiredFieldIssue[] = [];
151
191
  for (const field of fields) {
152
- if (!field.required) continue;
192
+ // W-595: a hidden field is sent by the form itself, with no control.
193
+ if (!field.required || field.type === "hidden") continue;
153
194
  const label = field.label.trim() || field.name;
154
195
  const bound = controls.get(field.name);
155
196
  if (!bound?.length) {
@@ -43,3 +43,75 @@ export function fieldByName(
43
43
  if (!definition) return undefined;
44
44
  return fieldsOf(definition).find((field) => field.name === name);
45
45
  }
46
+
47
+ /** W-577: a field whose limits no answer can meet (min above max), so the form can't be sent. */
48
+ export type ImpossibleRangeField = {
49
+ name: string;
50
+ label: string;
51
+ kind: "length" | "value" | "both";
52
+ };
53
+
54
+ const above = (lo: unknown, hi: unknown) =>
55
+ typeof lo === "number" && typeof hi === "number" && lo > hi;
56
+
57
+ export function impossibleRangeFields(
58
+ fields: ReadonlyArray<{ name: string; label: string; validation?: unknown }>,
59
+ ): ImpossibleRangeField[] {
60
+ const found: ImpossibleRangeField[] = [];
61
+ for (const field of fields) {
62
+ const v = field.validation;
63
+ if (!v || typeof v !== "object") continue;
64
+ const { minLength, maxLength, min, max } = v as Record<string, unknown>;
65
+ const label = field.label.trim() || field.name;
66
+ const badLength = above(minLength, maxLength);
67
+ const badValue = above(min, max);
68
+ // W-589: report both problems together so fixing one doesn't reveal the other later.
69
+ if (badLength || badValue) {
70
+ const kind = badLength && badValue ? "both" : badLength ? "length" : "value";
71
+ found.push({ name: field.name, label, kind });
72
+ }
73
+ }
74
+ return found;
75
+ }
76
+
77
+ /**
78
+ * W-579: a control that can't send any answer its field accepts. A field with a fixed list of
79
+ * options (select, radio, checkbox group) is refused by the forms plugin unless the value is one
80
+ * of them, so a Text input, Textarea or Checkbox bound to it makes the form unsendable.
81
+ */
82
+ export type MismatchedControl = { nodeId: string; name: string; label: string; fieldType: string };
83
+
84
+ const OPTION_TYPES = new Set(["select", "radio", "checkbox-group"]);
85
+ const FREE_CONTROLS = new Set(["text-input", "textarea", "checkbox"]);
86
+
87
+ type ControlLike = { id: string; type: string; props: unknown; children?: readonly ControlLike[] };
88
+
89
+ export function mismatchedControls(
90
+ form: ControlLike,
91
+ fields: ReadonlyArray<{
92
+ name: string;
93
+ type: string;
94
+ label: string;
95
+ options?: readonly unknown[];
96
+ }>,
97
+ ): MismatchedControl[] {
98
+ const byName = new Map(fields.map((field) => [field.name, field]));
99
+ const found: MismatchedControl[] = [];
100
+ const visit = (node: ControlLike) => {
101
+ if (FREE_CONTROLS.has(node.type)) {
102
+ const name = (node.props as { field?: unknown }).field;
103
+ const field = typeof name === "string" ? byName.get(name) : undefined;
104
+ if (field && OPTION_TYPES.has(field.type) && (field.options?.length ?? 0) > 0) {
105
+ found.push({
106
+ nodeId: node.id,
107
+ name: field.name,
108
+ label: field.label.trim() || field.name,
109
+ fieldType: field.type,
110
+ });
111
+ }
112
+ }
113
+ for (const child of node.children ?? []) visit(child);
114
+ };
115
+ for (const child of form.children ?? []) visit(child);
116
+ return found;
117
+ }
@@ -129,6 +129,21 @@ const count = (node: LayoutNode): number =>
129
129
  * current section with the same id, or, if it was removed, goes back near its old place. Ids
130
130
  * already used elsewhere on the page are renewed, so the page stays valid.
131
131
  */
132
+ /** `node` with the A/B mark removed from every element whose id is in `live` (W-636). */
133
+ function withoutCopiedArms(node: LayoutNode, live: ReadonlySet<string>): LayoutNode {
134
+ let next = node;
135
+ if (node.variant && live.has(node.id)) {
136
+ next = { ...node };
137
+ delete next.variant;
138
+ }
139
+ const kids = nodeChildren(next);
140
+ if (kids.length === 0) return next;
141
+ return {
142
+ ...next,
143
+ children: kids.map((child) => withoutCopiedArms(child, live)),
144
+ } as LayoutNode;
145
+ }
146
+
132
147
  export function restoreSection(
133
148
  current: Layout,
134
149
  older: Layout,
@@ -143,7 +158,9 @@ export function restoreSection(
143
158
  const clashes = [...index(section).keys()].some((id) => elsewhere.has(id));
144
159
  // CSS ids another section took since then stay there: a repeat made the page fail to save (W-517).
145
160
  const takenHtml = htmlIdsOf(current.root, replacing);
146
- const fresh = clashes ? withFreshIds(current, section) : section;
161
+ // An element still on the page elsewhere comes back as a copy, and a copy is never part of an
162
+ // A/B test (W-629/W-632): it would add a second copy of a live arm (W-636).
163
+ const fresh = clashes ? withFreshIds(current, withoutCopiedArms(section, elsewhere)) : section;
147
164
  const incoming = withoutTakenHtmlIds(fresh, takenHtml);
148
165
  const size = count(current.root) - (replacing ? count(replacing) : 0) + count(incoming);
149
166
  if (size > MAX_NODES) return { ok: false, reason: "The page would have too many elements." };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * W-848 (D-057): a spin or pulse stops on its own after about 5 seconds (WCAG 2.2.2), so it repeats
3
+ * as many whole times as fit. A pulse alternates, so it runs an even number of times and ends at
4
+ * rest. One spin longer than 5 s, or one pulse there and back longer than 5 s, still runs once.
5
+ */
6
+ export const ICON_ANIMATION_LIMIT_MS = 5000;
7
+
8
+ export function iconAnimationRuns(type: "spin" | "pulse", durationMs: number): number {
9
+ if (type === "spin") return Math.max(1, Math.floor(ICON_ANIMATION_LIMIT_MS / durationMs));
10
+ return 2 * Math.max(1, Math.floor(ICON_ANIMATION_LIMIT_MS / (2 * durationMs)));
11
+ }
@@ -62,8 +62,9 @@ export const BUNDLED_ICONS: readonly BundledIcon[] = [
62
62
  label: "Circle Alert",
63
63
  children: [
64
64
  { tag: "circle", attrs: { cx: "12", cy: "12", r: "10" } },
65
- { tag: "line", attrs: {} },
66
- { tag: "line", attrs: {} },
65
+ // W-699: the mark's two lines had no coordinates, so the icon drew an empty circle.
66
+ { tag: "line", attrs: { x1: "12", x2: "12", y1: "8", y2: "12" } },
67
+ { tag: "line", attrs: { x1: "12", x2: "12.01", y1: "16", y2: "16" } },
67
68
  ],
68
69
  },
69
70
  {
@@ -82,6 +82,15 @@ const Geometry = z
82
82
  /** photocn filter labels are short names ("juno"); unknown ones are ignored by the renderer. */
83
83
  const FilterLabel = z.string().regex(/^[A-Za-z0-9 _-]{1,32}$/, "Filter names are short words");
84
84
 
85
+ /** Backslashes and control characters, which URL parsing rewrites or drops. */
86
+ function hasUnsafeUrlChar(s: string): boolean {
87
+ for (const ch of s) {
88
+ const code = ch.charCodeAt(0);
89
+ if (ch === "\\" || code < 0x20 || code === 0x7f) return true;
90
+ }
91
+ return false;
92
+ }
93
+
85
94
  /**
86
95
  * A blend image must be a same-site path or an https URL; `data:` blends (picked files) are
87
96
  * refused because they would put a whole image into the layout.
@@ -90,7 +99,8 @@ const BlendSrc = z
90
99
  .string()
91
100
  .max(2000)
92
101
  .refine(
93
- (s) => /^\/(?!\/)/.test(s) || /^https:\/\//i.test(s),
102
+ // A backslash or control character can turn "/\\host" into another host (W-534).
103
+ (s) => !hasUnsafeUrlChar(s) && (/^\/(?!\/)/.test(s) || /^https:\/\//i.test(s)),
94
104
  "Blend images must be a site path or an https URL",
95
105
  );
96
106
 
@@ -28,7 +28,7 @@ const title = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
28
28
  */
29
29
  export function summarizeImageEdit(recipe: ImageEditRecipe, max = 5): string {
30
30
  const parts: string[] = [];
31
- if (recipe.filters) {
31
+ if (recipe.filters && recipe.filters.strength !== 0) {
32
32
  const s = recipe.filters.strength;
33
33
  parts.push(
34
34
  s === undefined || s >= 1
@@ -45,12 +45,15 @@ export function summarizeImageEdit(recipe: ImageEditRecipe, max = 5): string {
45
45
  }
46
46
  for (const section of [recipe.lights, recipe.colors, recipe.effects]) {
47
47
  for (const [key, value] of Object.entries(section ?? {})) {
48
- if (typeof value === "number" && value !== 0)
48
+ // Shown as a whole percent: a nudge that rounds to 0 is no change (W-551).
49
+ if (typeof value === "number" && Math.round(value * 100) !== 0)
49
50
  parts.push(`${LABELS[key] ?? key} ${signed(value)}`);
50
51
  }
51
52
  }
52
53
  if (recipe.curves?.some((c) => c !== null)) parts.push("Curves");
53
- if (recipe.blur && Object.values(recipe.blur).some((v) => v)) parts.push("Blur");
54
+ // The centre alone blurs nothing (W-551).
55
+ const blur = recipe.blur;
56
+ if (blur && (blur.bokehstrength || blur.gaussianstrength)) parts.push("Blur");
54
57
  if (recipe.blend) parts.push("Blend");
55
58
  if (parts.length === 0) return "No changes";
56
59
  if (parts.length <= max) return parts.join(" · ");
package/src/core/index.ts CHANGED
@@ -159,6 +159,10 @@ export {
159
159
  export {
160
160
  fieldsOf,
161
161
  fieldByName,
162
+ impossibleRangeFields,
163
+ mismatchedControls,
164
+ type ImpossibleRangeField,
165
+ type MismatchedControl,
162
166
  type PublicFormDefinition,
163
167
  type PublicFormField,
164
168
  type FormDefinitions,
@@ -167,6 +171,7 @@ export { FORMS_SUBMIT_PATH } from "./render/index.ts";
167
171
 
168
172
  export {
169
173
  cleanClassName,
174
+ nameKey,
170
175
  MAX_CLASSES,
171
176
  moveClassId,
172
177
  addClassId,
@@ -255,6 +260,7 @@ export {
255
260
  nodeIdAtPath,
256
261
  newNodeId,
257
262
  starterLayout,
263
+ pageSlug,
258
264
  slugify,
259
265
  type Removed,
260
266
  } from "./tree-ops.ts";
@@ -266,6 +272,7 @@ export {
266
272
  canDrop,
267
273
  duplicateNode,
268
274
  wrapNode,
275
+ wrapInThemeSection,
269
276
  WRAP_TYPES,
270
277
  type WrapType,
271
278
  createVariantB,
@@ -361,7 +368,12 @@ export {
361
368
  type PopupDevice,
362
369
  } from "./theme/popup-rules.ts";
363
370
 
364
- export { POPUP_CHROME_CSS, wrapPopupMarkup, type PopupPublicConfig } from "./theme/popup-markup.ts";
371
+ export {
372
+ POPUP_CHROME_CSS,
373
+ wrapPopupMarkup,
374
+ type ChromeLabels,
375
+ type PopupPublicConfig,
376
+ } from "./theme/popup-markup.ts";
365
377
 
366
378
  export {
367
379
  FLOAT_EDGES,
@@ -394,6 +406,7 @@ export {
394
406
  archivePageTitle,
395
407
  DEFAULT_PER_PAGE,
396
408
  loopPerPage,
409
+ paginationArchiveTitle,
397
410
  paginationTitleText,
398
411
  MAX_ARCHIVE_PAGE,
399
412
  paginationItems,
@@ -445,6 +458,7 @@ export {
445
458
  export {
446
459
  abCookieName,
447
460
  collectAbTests,
461
+ loneAbTests,
448
462
  pickArm,
449
463
  variantShows,
450
464
  type AbArm,
@@ -513,3 +527,23 @@ export {
513
527
  ImageEditRecipe,
514
528
  } from "./image-edit/schema.ts";
515
529
  export { summarizeImageEdit } from "./image-edit/summary.ts";
530
+ export { boxLinkHeldBack } from "./render/extras.ts";
531
+ export {
532
+ classMergeNotice,
533
+ insertSavedSection,
534
+ MAX_SAVED_SECTIONS,
535
+ mergeSectionClasses,
536
+ prepareSavedSection,
537
+ readSavedSection,
538
+ SAVED_SECTION_NAME_MAX,
539
+ SAVED_SECTION_REASONS,
540
+ savedSectionName,
541
+ savedSectionRecord,
542
+ snapshotSection,
543
+ type ClassMerge,
544
+ type PreparedSection,
545
+ type SavedSection,
546
+ type SavedSectionRecord,
547
+ type SavedSectionSummary,
548
+ syncedPartLayout,
549
+ } from "./saved-sections.ts";
@@ -10,10 +10,21 @@ export const MAX_TABS = 12;
10
10
 
11
11
  /**
12
12
  * W-509: `text` cut to at most `max` UTF-16 units, as schema limits count, without leaving half
13
- * of an emoji (a lone surrogate) at the end.
13
+ * of an emoji (a lone surrogate), an accent's base letter or half a flag at the end.
14
14
  */
15
15
  export function clipText(text: string, max: number): string {
16
16
  if (text.length <= max) return text;
17
+ // W-543: whole characters as people see them, so an accent or half a flag isn't left behind.
18
+ if (typeof Intl !== "undefined" && "Segmenter" in Intl) {
19
+ let end = 0;
20
+ for (const { segment } of new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(
21
+ text.slice(0, max + 32),
22
+ )) {
23
+ if (end + segment.length > max) break;
24
+ end += segment.length;
25
+ }
26
+ return text.slice(0, end);
27
+ }
17
28
  const code = text.charCodeAt(max - 1);
18
29
  return text.slice(0, code >= 0xd800 && code <= 0xdbff ? max - 1 : max);
19
30
  }
@@ -59,6 +59,7 @@ function walkGradients(value: unknown): unknown {
59
59
 
60
60
  const gradients: Migration = (doc) => walkGradients(doc) as Record<string, unknown>;
61
61
 
62
+ /** 0.8.0 (W-885, D-031, D-059): layout 16 -> 17 and design 15 -> 16 add only the optional `loop`. */
62
63
  /** `LAYOUT_MIGRATIONS[n]` upgrades a version-n layout to version n + 1. Migrations must be pure. */
63
64
  export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
64
65
  1: unchanged,
@@ -76,6 +77,7 @@ export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
76
77
  13: unchanged,
77
78
  14: unchanged,
78
79
  15: unchanged,
80
+ 16: unchanged,
79
81
  };
80
82
 
81
83
  /** `DESIGN_MIGRATIONS[n]` upgrades a version-n design document to version n + 1. */
@@ -94,6 +96,7 @@ export const DESIGN_MIGRATIONS: Readonly<Record<number, Migration>> = {
94
96
  12: unchanged,
95
97
  13: unchanged,
96
98
  14: unchanged,
99
+ 15: unchanged,
97
100
  };
98
101
 
99
102
  export type UpgradeResult =