@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
@@ -8,12 +8,37 @@ export type AbTest = { test: string; split: number };
8
8
  /** The cookie that keeps a visitor on one arm of a test (W-312). */
9
9
  export const abCookieName = (test: string) => `emvb_ab_${test.replaceAll("-", "_")}`;
10
10
 
11
- /** Every A/B test in the layout, at most 10, with B's split (default 50 %). */
11
+ /**
12
+ * Tests in the layout that have only one arm (W-625): the other was deleted, cut or moved away.
13
+ * Such a test isn't run and its remaining elements show to every visitor, so nobody sees a gap.
14
+ */
15
+ export function loneAbTests(layout: Layout): Set<string> {
16
+ const arms = new Map<string, Set<AbArm>>();
17
+ const walk = (node: LayoutNode): void => {
18
+ const v = node.variant;
19
+ if (v) {
20
+ const seen = arms.get(v.test) ?? new Set<AbArm>();
21
+ seen.add(v.arm);
22
+ arms.set(v.test, seen);
23
+ }
24
+ if (isParentNode(node)) for (const child of node.children) walk(child);
25
+ };
26
+ walk(layout.root);
27
+ return new Set([...arms].filter(([, seen]) => seen.size < 2).map(([test]) => test));
28
+ }
29
+
30
+ /** Every A/B test in the layout with both arms, at most 10, with B's split (default 50 %). */
12
31
  export function collectAbTests(layout: Layout): AbTest[] {
32
+ const lone = loneAbTests(layout);
13
33
  const tests = new Map<string, number>();
14
34
  const walk = (node: LayoutNode): void => {
15
35
  const v = node.variant;
16
- if (v && AB_TEST_NAME.test(v.test) && (tests.has(v.test) || tests.size < 10)) {
36
+ if (
37
+ v &&
38
+ !lone.has(v.test) &&
39
+ AB_TEST_NAME.test(v.test) &&
40
+ (tests.has(v.test) || tests.size < 10)
41
+ ) {
17
42
  const known = tests.get(v.test);
18
43
  if (v.arm === "b" && v.split !== undefined) tests.set(v.test, v.split);
19
44
  else if (known === undefined) tests.set(v.test, 50);
@@ -44,8 +69,9 @@ export function pickArm(
44
69
  export function variantShows(
45
70
  node: LayoutNode,
46
71
  arms: Readonly<Record<string, AbArm>> | undefined,
72
+ lone?: ReadonlySet<string>,
47
73
  ): boolean {
48
74
  const v = node.variant;
49
- if (!v) return true;
75
+ if (!v || lone?.has(v.test)) return true;
50
76
  return (arms?.[v.test] ?? "a") === v.arm;
51
77
  }
@@ -205,6 +205,8 @@ const refsOf = (owner: CopiedStyle): Ref[] => [
205
205
  ...STYLE_STATES.flatMap((state) => refsInStyle(owner.states?.[state])),
206
206
  ...refsInStyle(owner.devices?.tablet),
207
207
  ...refsInStyle(owner.devices?.mobile),
208
+ // W-643: a container-query override (W-346) can use a variable too.
209
+ ...refsInStyle((owner as { query?: { style?: StyleProps } }).query?.style),
208
210
  ];
209
211
 
210
212
  const hasVariable = (design: DesignSystem, ref: Ref) =>
@@ -311,6 +313,11 @@ function cleanNode(
311
313
  next = { ...next };
312
314
  delete next.htmlId;
313
315
  }
316
+ if (next.variant) {
317
+ // A pasted copy is never part of an A/B test, like a duplicate (W-632).
318
+ next = { ...next };
319
+ delete next.variant;
320
+ }
314
321
  const kids = nodeChildren(next);
315
322
  if (kids.length === 0) return next;
316
323
  return {
@@ -75,15 +75,20 @@ const block = (selector: string, declarations: Declaration[]) =>
75
75
  : `${selector}{${declarations.map((d) => `${d.property}:${d.value}`).join(";")}}`;
76
76
 
77
77
  /** Tag defaults sit under `:where` so a class (0,1,0) still beats the tag (0,0,1). */
78
- function tagDefaultCss(design: DesignSystem): string {
78
+ function tagDefaultCss(
79
+ design: DesignSystem,
80
+ track: (selector: string, declarations: Declaration[]) => Declaration[],
81
+ ): string {
79
82
  const defaults = design.defaults;
80
83
  if (!defaults) return "";
81
84
  let css = "";
82
85
  for (const tag of DEFAULT_STYLE_TAGS) {
83
86
  const style = defaults[tag];
84
87
  if (!style) continue;
85
- const { declarations } = styleDeclarations(style);
86
- css += block(`:where(.emvb-root) ${tag}`, declarations);
88
+ // W-670: tracked like classes, so a tag default's entrance gets its keyframes and turns off
89
+ // for reduced motion.
90
+ const selector = `:where(.emvb-root) ${tag}`;
91
+ css += block(selector, track(selector, styleDeclarations(style).declarations));
87
92
  }
88
93
  return css;
89
94
  }
@@ -189,6 +194,8 @@ export function generateCss({
189
194
  withInheritedLayers(cls.devices?.mobile, { ...cls.style, ...cls.devices?.tablet }),
190
195
  ).declarations,
191
196
  hiddenOn: cls.hiddenOn,
197
+ // W-571: the page root is never hidden (W-567), not even by a class.
198
+ hideSelector: `.${className}:not(.emvb-root)`,
192
199
  },
193
200
  ]
194
201
  : [];
@@ -220,7 +227,7 @@ export function generateCss({
220
227
  .flatMap((rule) =>
221
228
  "figure" in rule && rule.figure
222
229
  ? [rule.selector, `.emvb-figure:has(>${rule.selector},>a>${rule.selector})`]
223
- : [rule.selector],
230
+ : ["hideSelector" in rule && rule.hideSelector ? rule.hideSelector : rule.selector],
224
231
  );
225
232
  return forDevices(
226
233
  [device],
@@ -237,15 +244,33 @@ export function generateCss({
237
244
  entrances.push(rule.selector);
238
245
  }
239
246
  }
247
+ const defaultsCss = tagDefaultCss(design, track);
248
+ // W-670: an entrance or scroll motion set only in a container query override pointed at
249
+ // keyframes that were never sent (no animation at all) and ignored reduced motion.
250
+ for (const rule of localRules) {
251
+ const query = rule.query ?? [];
252
+ const selector = `.emvb-e-${rule.id}`;
253
+ if (usesMotion(query)) motion = true;
254
+ if (!entrances.includes(selector) && query.some((d) => d.property === "animation")) {
255
+ entrances.push(selector);
256
+ }
257
+ if (!animated.includes(selector) && query.some((d) => d.property === "transition")) {
258
+ animated.push(selector);
259
+ }
260
+ }
240
261
  return [
241
262
  entrances.length > 0
242
263
  ? "@keyframes emvb-fade{from{opacity:0}to{opacity:1}}@keyframes emvb-fade-up{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}@keyframes emvb-fade-down{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:none}}@keyframes emvb-slide-up{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:none}}@keyframes emvb-slide-down{from{opacity:0;transform:translateY(-16px)}to{opacity:1;transform:none}}@keyframes emvb-scale{from{opacity:0;transform:scale(0.96)}to{opacity:1;transform:none}}"
243
264
  : "",
244
265
  entrances.length > 0 && motion ? MOTION_KEYFRAMES : "",
245
266
  block(".emvb-root", variables),
246
- tagDefaultCss(design),
267
+ defaultsCss,
247
268
  backgroundVideo
248
- ? ".emvb-has-bg-video{position:relative;overflow:hidden}.emvb-bg-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:0;pointer-events:none}.emvb-has-bg-video>:not(.emvb-bg-video){position:relative;z-index:1}"
269
+ ? ".emvb-has-bg-video{position:relative;overflow:hidden}.emvb-bg-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:0;pointer-events:none}.emvb-has-bg-video>:not(.emvb-bg-video){position:relative;z-index:1}" +
270
+ // W-802: the overlay above the video, under the content; reset so a nested box's own wins.
271
+ '.emvb-has-bg-video{--emvb-bg-overlay:none}.emvb-has-bg-video::after{content:"";position:absolute;inset:0;z-index:0;pointer-events:none;background:var(--emvb-bg-overlay)}' +
272
+ // W-801: a looping video kept playing for visitors who ask for reduced motion.
273
+ "@media (prefers-reduced-motion: reduce){.emvb-bg-video{display:none}}"
249
274
  : "",
250
275
  ...[...usedTypes].toSorted().map((type) => baseCss.get(type) ?? ""),
251
276
  ...classes,
@@ -100,7 +100,14 @@ function clean(value: string): string {
100
100
  let out = "";
101
101
  for (const char of value) {
102
102
  const code = char.codePointAt(0) ?? 0;
103
- const kept = code === 9 ? " " : code === 10 || (code >= 32 && code !== 127) ? char : "";
103
+ // W-677: C1 controls and bidi overrides, embeddings and isolates too: a URL parameter
104
+ // could make a bound heading or link read backwards ("exe.jpg" shown as "gpj.exe").
105
+ const dropped =
106
+ code === 127 ||
107
+ (code >= 0x80 && code <= 0x9f) ||
108
+ (code >= 0x202a && code <= 0x202e) ||
109
+ (code >= 0x2066 && code <= 0x2069);
110
+ const kept = code === 9 ? " " : code === 10 || (code >= 32 && !dropped) ? char : "";
104
111
  // W-502: cutting at a UTF-16 length split an emoji at the limit into a broken half.
105
112
  if (out.length + kept.length > MAX_BOUND_LENGTH) break;
106
113
  out += kept;
@@ -96,10 +96,14 @@ export const MAX_CLASSES = 100;
96
96
 
97
97
  /** A class name as saved: control characters gone, trimmed, at most 60 characters (W-218). */
98
98
  export function cleanClassName(name: string): string {
99
- const spaced = Array.from(name, (ch) => {
99
+ // W-568: one form for accents, C1 controls spaced like C0, and invisible marks (zero-width
100
+ // space, word joiner, BOM, bidi overrides) dropped so two names that look alike compare alike.
101
+ const spaced = Array.from(name.normalize("NFC"), (ch) => {
100
102
  const code = ch.charCodeAt(0);
101
- return code < 32 || code === 127 ? " " : ch;
102
- }).join("");
103
+ return code < 32 || (code >= 127 && code <= 159) ? " " : ch;
104
+ })
105
+ .join("")
106
+ .replace(/[\u200B\u2060\uFEFF\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "");
103
107
  const spacedTrim = spaced.replace(/ {2,}/g, " ").trim();
104
108
  return clipText(spacedTrim, 60).trim();
105
109
  }
@@ -122,10 +126,10 @@ export function localStylesToClass(
122
126
  node: LayoutNode,
123
127
  name: string,
124
128
  ): { design: DesignSystem; node: LayoutNode; classId: string } | null {
125
- const trimmed = clipText(name.trim(), 60);
129
+ const trimmed = cleanClassName(name);
126
130
  if (!trimmed || localToClassRefusal(design, node)) return null;
127
131
  const classes = design.classes ?? [];
128
- const base = slugify(trimmed).slice(0, 34) || "class";
132
+ const base = slugify(trimmed).slice(0, 34).replace(/-+$/, "") || "class";
129
133
  const taken = new Set(classes.map((c) => c.id));
130
134
  let id = base;
131
135
  for (let n = 2; taken.has(id); n++) id = `${base}-${n}`;
@@ -161,7 +165,7 @@ export function duplicateClass(
161
165
  for (let n = 2; n <= MAX_CLASSES && classNameTaken(design, baseName); n++) {
162
166
  baseName = `${stem} ${n}`;
163
167
  }
164
- const base = slugify(baseName).slice(0, 34) || "class";
168
+ const base = slugify(baseName).slice(0, 34).replace(/-+$/, "") || "class";
165
169
  const taken = new Set(classes.map((c) => c.id));
166
170
  let id = randomSuffix ? `${base}-${randomSuffix}`.slice(0, 40) : base;
167
171
  for (let n = 2; taken.has(id); n++) id = `${base}-${n}`.slice(0, 40);
@@ -174,9 +178,14 @@ export function duplicateClass(
174
178
  * W-277: whether another class already has this name (case-insensitive). Two classes with one
175
179
  * name can't be told apart in the class picker or the Site styles list.
176
180
  */
181
+ /** W-570: the form two class or variable names are compared in (cleaned, any case). */
182
+ export const nameKey = (name: string) => cleanClassName(name).toLowerCase();
183
+
177
184
  export function classNameTaken(design: DesignSystem, name: string, exceptId?: string): boolean {
178
185
  const wanted = cleanClassName(name).toLowerCase();
179
- return (design.classes ?? []).some((c) => c.id !== exceptId && c.name.toLowerCase() === wanted);
186
+ return (design.classes ?? []).some(
187
+ (c) => c.id !== exceptId && cleanClassName(c.name).toLowerCase() === wanted,
188
+ );
180
189
  }
181
190
 
182
191
  /** The message shown when a new or renamed class would take another class's name (W-277). */
@@ -18,6 +18,12 @@ export function designChanges(published: DesignSystem, draft: DesignSystem): Des
18
18
  listChanges(published.variables.fontSizes, draft.variables.fontSizes, "variable", changes);
19
19
  listChanges(published.variables.spacings, draft.variables.spacings, "variable", changes);
20
20
  listChanges(published.classes, draft.classes, "class", changes);
21
+ // W-641: class order is the cascade order, so a reorder alone changes how the page looks.
22
+ const kept = new Set((draft.classes ?? []).map((c) => c.id));
23
+ const before = (published.classes ?? []).map((c) => c.id).filter((id) => kept.has(id));
24
+ const had = new Set(before);
25
+ const after = (draft.classes ?? []).map((c) => c.id).filter((id) => had.has(id));
26
+ if (!same(before, after)) changes.push({ kind: "changed", what: "setting", name: "Class order" });
21
27
  if (!same(published.direction, draft.direction)) {
22
28
  changes.push({ kind: "changed", what: "setting", name: "Direction" });
23
29
  }
@@ -1,4 +1,5 @@
1
1
  import { sameJson } from "../stable-json.ts";
2
+ import { nameKey } from "./classes.ts";
2
3
  import { emptyDesign, type DesignSystem } from "../schema/design.ts";
3
4
 
4
5
  export type DesignConflict = { kind: "variable" | "class" | "setting"; name: string };
@@ -30,6 +31,7 @@ export function mergeDesign(
30
31
  theirs.variables.colors,
31
32
  conflicts,
32
33
  "variable",
34
+ 200,
33
35
  ),
34
36
  fonts: mergeList(
35
37
  from.variables.fonts,
@@ -37,6 +39,7 @@ export function mergeDesign(
37
39
  theirs.variables.fonts,
38
40
  conflicts,
39
41
  "variable",
42
+ 50,
40
43
  ),
41
44
  fontSizes: mergeList(
42
45
  from.variables.fontSizes,
@@ -44,6 +47,7 @@ export function mergeDesign(
44
47
  theirs.variables.fontSizes,
45
48
  conflicts,
46
49
  "variable",
50
+ 50,
47
51
  ),
48
52
  spacings: mergeList(
49
53
  from.variables.spacings,
@@ -51,9 +55,10 @@ export function mergeDesign(
51
55
  theirs.variables.spacings,
52
56
  conflicts,
53
57
  "variable",
58
+ 100,
54
59
  ),
55
60
  },
56
- classes: mergeList(from.classes, ours.classes, theirs.classes, conflicts, "class"),
61
+ classes: mergeList(from.classes, ours.classes, theirs.classes, conflicts, "class", 100),
57
62
  fluidRange: pickSetting(
58
63
  from.fluidRange,
59
64
  ours.fluidRange,
@@ -79,6 +84,32 @@ function mergeList<T extends Named>(
79
84
  theirs: T[] | undefined,
80
85
  conflicts: DesignConflict[],
81
86
  kind: "variable" | "class",
87
+ /** The list's limit in schema/design.ts. */
88
+ max: number,
89
+ ): T[] {
90
+ const merged = mergeListUncapped(base, ours, theirs, conflicts, kind);
91
+ if (merged.length <= max) return merged;
92
+ // W-647: both tabs added items and together they pass the limit, so the save would be refused.
93
+ // The server's items stay; this tab's new ones past the limit are reported as conflicts.
94
+ const theirIds = new Set((theirs ?? []).map((item) => item.id));
95
+ let over = merged.length - max;
96
+ const dropped = new Set<string>();
97
+ for (const item of merged.toReversed()) {
98
+ if (over === 0) break;
99
+ if (theirIds.has(item.id)) continue;
100
+ dropped.add(item.id);
101
+ conflicts.push({ kind, name: item.name });
102
+ over--;
103
+ }
104
+ return merged.filter((item) => !dropped.has(item.id));
105
+ }
106
+
107
+ function mergeListUncapped<T extends Named>(
108
+ base: T[] | undefined,
109
+ ours: T[] | undefined,
110
+ theirs: T[] | undefined,
111
+ conflicts: DesignConflict[],
112
+ kind: "variable" | "class",
82
113
  ): T[] {
83
114
  const baseItems = base ?? [];
84
115
  const ourItems = ours ?? [];
@@ -89,6 +120,8 @@ function mergeList<T extends Named>(
89
120
  const theirsBy = by(theirItems);
90
121
  const result: T[] = [];
91
122
  const seen = new Set<string>();
123
+ /** Ids whose kept copy is this tab's change (W-620). */
124
+ const fromUs = new Set<string>();
92
125
  const take = (id: string) => {
93
126
  if (seen.has(id)) return;
94
127
  seen.add(id);
@@ -102,6 +135,7 @@ function mergeList<T extends Named>(
102
135
  return;
103
136
  }
104
137
  if (!theyChanged || same(ourItem, theirItem)) {
138
+ if (ourItem && !same(ourItem, theirItem)) fromUs.add(ourItem.id);
105
139
  if (ourItem) result.push(ourItem);
106
140
  return;
107
141
  }
@@ -110,7 +144,26 @@ function mergeList<T extends Named>(
110
144
  };
111
145
  for (const item of theirItems) take(item.id);
112
146
  for (const item of ourItems) take(item.id);
113
- return result;
147
+ // W-620: this tab and the other one each named a different class (or variable) the same, so the
148
+ // merge would keep two with one name; names must stay unique, so it's a conflict.
149
+ const theirNames = new Map(
150
+ result.filter((item) => !fromUs.has(item.id)).map((item) => [nameKey(item.name), item.id]),
151
+ );
152
+ const clashes = result.filter((item) => {
153
+ if (!fromUs.has(item.id)) return false;
154
+ const other = theirNames.get(nameKey(item.name));
155
+ return other !== undefined && other !== item.id;
156
+ });
157
+ if (clashes.length === 0)
158
+ return inOurOrder(baseItems, ourItems, theirItems, result, conflicts, kind);
159
+ for (const item of clashes) conflicts.push({ kind, name: item.name });
160
+ // The server copy stays, as in any conflict: their version of a renamed item, nothing for a new one.
161
+ const clashed = new Set(clashes.map((item) => item.id));
162
+ return result.flatMap((item) => {
163
+ if (!clashed.has(item.id)) return [item];
164
+ const theirItem = theirsBy.get(item.id);
165
+ return theirItem ? [theirItem] : [];
166
+ });
114
167
  }
115
168
 
116
169
  function pickSetting<T>(
@@ -127,3 +180,38 @@ function pickSetting<T>(
127
180
  conflicts.push({ kind: "setting", name });
128
181
  return theirs;
129
182
  }
183
+
184
+ /** The ids both lists share, in `list`'s order. */
185
+ const sharedOrder = (list: Named[], other: Set<string>) =>
186
+ list.filter((item) => other.has(item.id)).map((item) => item.id);
187
+
188
+ /**
189
+ * W-621: class order is the cascade order, so a reorder here was lost when the other tab
190
+ * changed anything. Our order wins when only we reordered; both reordering is a conflict.
191
+ */
192
+ function inOurOrder<T extends Named>(
193
+ base: T[],
194
+ ours: T[],
195
+ theirs: T[],
196
+ result: T[],
197
+ conflicts: DesignConflict[],
198
+ kind: "variable" | "class",
199
+ ): T[] {
200
+ const baseIds = new Set(base.map((item) => item.id));
201
+ const ourIds = new Set(ours.map((item) => item.id));
202
+ const theirIds = new Set(theirs.map((item) => item.id));
203
+ const inAll = new Set([...baseIds].filter((id) => ourIds.has(id) && theirIds.has(id)));
204
+ const baseOrder = sharedOrder(base, inAll).join("\n");
205
+ const ourOrder = sharedOrder(ours, inAll).join("\n");
206
+ const theirOrder = sharedOrder(theirs, inAll).join("\n");
207
+ if (ourOrder === baseOrder || ourOrder === theirOrder) return result;
208
+ if (theirOrder !== baseOrder) {
209
+ conflicts.push({ kind: "setting", name: kind === "class" ? "Class order" : "Variable order" });
210
+ return result;
211
+ }
212
+ const rank = new Map(ours.map((item, index) => [item.id, index]));
213
+ const keptOurs = result.filter((item) => rank.has(item.id));
214
+ keptOurs.sort((a, b) => (rank.get(a.id) as number) - (rank.get(b.id) as number));
215
+ let next = 0;
216
+ return result.map((item) => (rank.has(item.id) ? (keptOurs[next++] as T) : item));
217
+ }
@@ -119,9 +119,23 @@ export function applyTokens(
119
119
  ): DesignSystem {
120
120
  const current = design.variables[list] ?? [];
121
121
  const byId = new Map(tokens.map((t) => [t.id, t]));
122
- const replaced = current.map((v) => byId.get(v.id) ?? v);
122
+ // W-640: an updated token keeps the name the site gave it.
123
+ const replaced = current.map((v) => {
124
+ const t = byId.get(v.id);
125
+ return t ? Object.assign({}, t, { name: v.name }) : v;
126
+ });
123
127
  const have = new Set(current.map((v) => v.id));
124
128
  const limit = list === "fontSizes" ? 50 : 100;
125
- const added = tokens.filter((t) => !have.has(t.id)).slice(0, Math.max(0, limit - current.length));
129
+ // W-640: a new token whose name another variable has gets "Display 2", so pickers can tell them apart.
130
+ const taken = new Set(current.map((v) => v.name.trim().toLowerCase()));
131
+ const added = tokens
132
+ .filter((t) => !have.has(t.id))
133
+ .slice(0, Math.max(0, limit - current.length))
134
+ .map((t) => {
135
+ let name = t.name;
136
+ for (let n = 2; taken.has(name.toLowerCase()); n++) name = `${t.name} ${n}`;
137
+ taken.add(name.toLowerCase());
138
+ return name === t.name ? t : Object.assign({}, t, { name });
139
+ });
126
140
  return { ...design, variables: { ...design.variables, [list]: [...replaced, ...added] } };
127
141
  }
@@ -3,7 +3,7 @@ import { DesignSystem as DesignSystemSchema, DESIGN_SCHEMA_VERSION } from "../sc
3
3
  import type { DesignSystem } from "../schema/design.ts";
4
4
  import { DESIGN_MIGRATIONS, upgradeLayout } from "../migrate/index.ts";
5
5
  import type { Layout } from "../schema/layout.ts";
6
- import { findClassUsages } from "./classes.ts";
6
+ import { findClassUsages, nameKey } from "./classes.ts";
7
7
  import { findVariableUsages } from "./variables.ts";
8
8
 
9
9
  /** The design document as JSON. This file is the backup: there is no revision history. */
@@ -23,22 +23,22 @@ function freeName(name: string, taken: Set<string>): string {
23
23
  for (let n = 2; ; n++) {
24
24
  const suffix = ` ${n}`;
25
25
  const next = `${clipText(name, 60 - suffix.length).trim()}${suffix}`;
26
- if (!taken.has(next.toLowerCase())) return next;
26
+ if (!taken.has(nameKey(next))) return next;
27
27
  }
28
28
  }
29
29
 
30
30
  function dedupe<T extends { name: string }>(items: T[], renamed: ImportRename[]): T[] {
31
- const taken = new Set(items.map((item) => item.name.toLowerCase()));
31
+ const taken = new Set(items.map((item) => nameKey(item.name)));
32
32
  const seen = new Set<string>();
33
33
  return items.map((item) => {
34
- const key = item.name.toLowerCase();
34
+ const key = nameKey(item.name);
35
35
  if (!seen.has(key)) {
36
36
  seen.add(key);
37
37
  return item;
38
38
  }
39
39
  const to = freeName(item.name, taken);
40
- taken.add(to.toLowerCase());
41
- seen.add(to.toLowerCase());
40
+ taken.add(nameKey(to));
41
+ seen.add(nameKey(to));
42
42
  renamed.push({ from: item.name, to });
43
43
  return { ...item, name: to };
44
44
  });
@@ -64,6 +64,24 @@ export function uniqueImportNames(design: DesignSystem): {
64
64
  return { design: { ...design, variables, ...(classes ? { classes } : {}) }, renamed };
65
65
  }
66
66
 
67
+ function repeatedId(design: DesignSystem): { what: string; id: string } | null {
68
+ const lists: [string, { id: string }[] | undefined][] = [
69
+ ["classes", design.classes],
70
+ ...VARIABLE_GROUPS.map(([group]): [string, { id: string }[] | undefined] => [
71
+ "variables",
72
+ design.variables[group],
73
+ ]),
74
+ ];
75
+ for (const [what, list] of lists) {
76
+ const seen = new Set<string>();
77
+ for (const item of list ?? []) {
78
+ if (seen.has(item.id)) return { what, id: item.id };
79
+ seen.add(item.id);
80
+ }
81
+ }
82
+ return null;
83
+ }
84
+
67
85
  /** Parse an exported design. Older schema versions are upgraded. A newer file is refused. */
68
86
  export function designFromJson(text: string): DesignImport {
69
87
  let parsed: unknown;
@@ -84,6 +102,15 @@ export function designFromJson(text: string): DesignImport {
84
102
  }
85
103
  const result = DesignSystemSchema.safeParse(upgraded.doc);
86
104
  if (!result.success) return { ok: false, message: "That file is not an EmVB design document." };
105
+ // W-619: every reference points at an id, so two classes (or two variables of one kind) with
106
+ // the same id can't both be kept; the editor never writes such a file.
107
+ const repeated = repeatedId(result.data);
108
+ if (repeated) {
109
+ return {
110
+ ok: false,
111
+ message: `That file has two ${repeated.what} with the id "${clipText(repeated.id, 40)}". Give one of them a different id, then import it again.`,
112
+ };
113
+ }
87
114
  const imported = uniqueImportNames(result.data);
88
115
  // W-516: the file cap is 1 MB, but the saved design is capped lower; a design over that cap
89
116
  // replaced the site styles in the editor and then every save of them was refused.
@@ -68,7 +68,12 @@ const RESPONSIVE = ["tablet", "mobile"] as const;
68
68
 
69
69
  /** Style, state styles and device overrides. A nested usage is `<state|device>.<prop>`. */
70
70
  function collectAllUsages(
71
- owner: { style?: StyleProps; states?: StyleStates; devices?: DeviceStyles },
71
+ owner: {
72
+ style?: StyleProps;
73
+ states?: StyleStates;
74
+ devices?: DeviceStyles;
75
+ query?: { style: StyleProps };
76
+ },
72
77
  id: string,
73
78
  kind: VariableKind | undefined,
74
79
  hit: (prop: string) => void,
@@ -80,6 +85,8 @@ function collectAllUsages(
80
85
  for (const device of RESPONSIVE) {
81
86
  collectStyleUsages(owner.devices?.[device], id, kind, (prop) => hit(`${device}.${prop}`));
82
87
  }
88
+ // W-643: a container-query override (W-346) can use a variable too.
89
+ collectStyleUsages(owner.query?.style, id, kind, (prop) => hit(`query.${prop}`));
83
90
  }
84
91
 
85
92
  /** Find every style property on `layout` that references variable `id` (optionally of `kind`). */
@@ -191,19 +198,33 @@ function stripRefsFromDevices(
191
198
  }
192
199
 
193
200
  /** Style, states and device overrides with the refs removed. Same object when nothing changed. */
194
- function stripOwner<T extends { style?: StyleProps; states?: StyleStates; devices?: DeviceStyles }>(
195
- owner: T,
196
- id: string,
197
- kind: VariableKind | undefined,
198
- ): T {
201
+ function stripOwner<
202
+ T extends {
203
+ style?: StyleProps;
204
+ states?: StyleStates;
205
+ devices?: DeviceStyles;
206
+ query?: { min: number; style: StyleProps };
207
+ },
208
+ >(owner: T, id: string, kind: VariableKind | undefined): T {
199
209
  const style = stripRefsFromStyle(owner.style, id, kind);
200
210
  const states = stripRefsFromStates(owner.states, id, kind);
201
211
  const devices = stripRefsFromDevices(owner.devices, id, kind);
202
- if (style === owner.style && states === owner.states && devices === owner.devices) return owner;
212
+ const queryStyle = owner.query ? stripRefsFromStyle(owner.query.style, id, kind) : undefined;
213
+ const queryChanged = owner.query !== undefined && queryStyle !== owner.query.style;
214
+ if (
215
+ style === owner.style &&
216
+ states === owner.states &&
217
+ devices === owner.devices &&
218
+ !queryChanged
219
+ ) {
220
+ return owner;
221
+ }
203
222
  const next: T = { ...owner, style, states, devices };
204
223
  if (style === undefined) delete next.style;
205
224
  if (states === undefined) delete next.states;
206
225
  if (devices === undefined) delete next.devices;
226
+ // W-643: the container-query override keeps its width; an emptied one keeps `{}`.
227
+ if (queryChanged && owner.query) next.query = { ...owner.query, style: queryStyle ?? {} };
207
228
  return next;
208
229
  }
209
230
 
@@ -285,7 +306,7 @@ export function duplicateVariable(
285
306
  for (let n = 2; n <= MAX_VARIABLES[kind] && variableNameTaken(design, kind, name); n++) {
286
307
  name = `${stem} ${n}`;
287
308
  }
288
- const base = slugify(name).slice(0, 34) || kind;
309
+ const base = slugify(name).slice(0, 34).replace(/-+$/, "") || kind;
289
310
  const taken = new Set(list.map((entry) => entry.id));
290
311
  let nextId = base;
291
312
  for (let n = 2; taken.has(nextId); n++) nextId = `${base}-${n}`.slice(0, 40);
@@ -312,7 +333,7 @@ export function variableNameTaken(
312
333
  ): boolean {
313
334
  const wanted = cleanClassName(name).toLowerCase();
314
335
  return (design.variables[KIND_TO_LIST[kind]] ?? []).some(
315
- (v) => v.id !== exceptId && v.name.toLowerCase() === wanted,
336
+ (v) => v.id !== exceptId && cleanClassName(v.name).toLowerCase() === wanted,
316
337
  );
317
338
  }
318
339
 
@@ -146,7 +146,7 @@ export const postLink: ElementDefinition<PostLinkNode> = {
146
146
  optional: true,
147
147
  message: "Leave blank to use the post title.",
148
148
  },
149
- { key: "newTab", kind: "boolean", label: "Open in new tab", optional: true },
149
+ { key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
150
150
  ],
151
151
  },
152
152
  build: (_node, attrs) => ({ tag: "a", attrs: { ...attrs, href: "#" }, children: ["Post link"] }),
@@ -222,21 +222,22 @@ export const loop: ElementDefinition<LoopNode> = {
222
222
  label: "Link pattern",
223
223
  optional: true,
224
224
  message:
225
- "Where each entry links, e.g. /team/{slug}; {slug} and {id} are filled in. Leave it empty for /collection/{slug}.",
225
+ "Where each entry links, such as /team/{slug}; {slug} and {id} are filled in. Leave it empty for /collection/{slug}.",
226
226
  },
227
227
  {
228
228
  key: "imageField",
229
229
  kind: "text",
230
230
  label: "Image field",
231
231
  optional: true,
232
- message: "The field Post Image shows, e.g. photo. Leave it empty for the featured image.",
232
+ message:
233
+ "The field Post Image shows, such as photo. Leave it empty for the featured image.",
233
234
  },
234
235
  {
235
236
  key: "excerptField",
236
237
  kind: "text",
237
238
  label: "Excerpt field",
238
239
  optional: true,
239
- message: "The field Post Excerpt shows, e.g. role. Leave it empty for the excerpt.",
240
+ message: "The field Post Excerpt shows, such as role. Leave it empty for the excerpt.",
240
241
  },
241
242
  {
242
243
  key: "filter",
@@ -244,7 +245,7 @@ export const loop: ElementDefinition<LoopNode> = {
244
245
  label: "Only entries where",
245
246
  optional: true,
246
247
  message:
247
- "field=value pairs separated by ;, e.g. category=news; team=design. A taxonomy works too. The same field twice matches either value.",
248
+ "field=value pairs separated by semicolons, such as category=news; team=design. A taxonomy works too. The same field twice matches either value.",
248
249
  },
249
250
  {
250
251
  key: "itemPartId",
@@ -318,6 +319,44 @@ export const pagination: ElementDefinition<PaginationNode> = {
318
319
  message:
319
320
  'The browser title of page 2 onward. {title} and {page} are filled in; unset is "{title} – page {page}".',
320
321
  },
322
+ {
323
+ key: "archiveTitle",
324
+ kind: "text",
325
+ label: "Posts archive title",
326
+ optional: true,
327
+ message:
328
+ "Replaces \"Posts\" as the posts archive's title, in the site's language. Category and tag archives use the term's name.",
329
+ },
330
+ {
331
+ key: "navLabel",
332
+ kind: "text",
333
+ label: "Screen reader name",
334
+ optional: true,
335
+ message:
336
+ 'What screen readers call the links, in the site\'s language. Unset is "Pagination".',
337
+ },
338
+ {
339
+ key: "pageLabel",
340
+ kind: "text",
341
+ label: "Page number name",
342
+ optional: true,
343
+ message:
344
+ 'What screen readers call each number. {page} is filled in; unset is "Page {page}".',
345
+ },
346
+ {
347
+ key: "prevLabel",
348
+ kind: "text",
349
+ label: "Previous name",
350
+ optional: true,
351
+ message: 'Read out when Previous text is only an arrow. Unset is "Previous page".',
352
+ },
353
+ {
354
+ key: "nextLabel",
355
+ kind: "text",
356
+ label: "Next name",
357
+ optional: true,
358
+ message: 'Read out when Next text is only an arrow. Unset is "Next page".',
359
+ },
321
360
  ],
322
361
  },
323
362
  // Rendered by core/render/pagination.ts from the archive's page data (W-222).