@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
@@ -100,11 +100,19 @@ 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
- if (code === 10 || code === 9) out += char === "\t" ? " " : char;
104
- else if (code >= 32 && code !== 127) out += char;
105
- if (out.length >= MAX_BOUND_LENGTH) break;
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 : "";
111
+ // W-502: cutting at a UTF-16 length split an emoji at the limit into a broken half.
112
+ if (out.length + kept.length > MAX_BOUND_LENGTH) break;
113
+ out += kept;
106
114
  }
107
- return out.slice(0, MAX_BOUND_LENGTH).trim();
115
+ return out.trim();
108
116
  }
109
117
 
110
118
  /** The live value of one binding, or undefined when its source has nothing for this key. */
@@ -189,8 +197,13 @@ export function applyBindings(node: LayoutNode, data: BindingData): LayoutNode {
189
197
  if (value === undefined) continue;
190
198
  props ??= { ...(node.props as Record<string, unknown>) };
191
199
  props[field.key] = value;
192
- // A bound image is no longer the media library item it was picked from.
193
- if (field.kind === "image") delete props["mediaId"];
200
+ // A bound image is no longer the media library item it was picked from. W-501: nor are the
201
+ // typed picture's extra sizes; with `w` descriptors the browser picks only from srcset, so
202
+ // they hid the bound image on most screens.
203
+ if (field.kind === "image") {
204
+ delete props["mediaId"];
205
+ delete props["sources"];
206
+ }
194
207
  }
195
208
  return props ? ({ ...node, props } as LayoutNode) : node;
196
209
  }
@@ -1,3 +1,4 @@
1
+ import { clipText } from "../limits.ts";
1
2
  import type { DesignSystem } from "../schema/design.ts";
2
3
  import type { Layout, LayoutNode } from "../schema/layout.ts";
3
4
  import type { StyleProps } from "../schema/style.ts";
@@ -95,11 +96,16 @@ export const MAX_CLASSES = 100;
95
96
 
96
97
  /** A class name as saved: control characters gone, trimmed, at most 60 characters (W-218). */
97
98
  export function cleanClassName(name: string): string {
98
- 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) => {
99
102
  const code = ch.charCodeAt(0);
100
- return code < 32 || code === 127 ? " " : ch;
101
- }).join("");
102
- return spaced.replace(/ {2,}/g, " ").trim().slice(0, 60).trim();
103
+ return code < 32 || (code >= 127 && code <= 159) ? " " : ch;
104
+ })
105
+ .join("")
106
+ .replace(/[\u200B\u2060\uFEFF\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "");
107
+ const spacedTrim = spaced.replace(/ {2,}/g, " ").trim();
108
+ return clipText(spacedTrim, 60).trim();
103
109
  }
104
110
 
105
111
  export function localToClassRefusal(design: DesignSystem, node: LayoutNode): string | null {
@@ -120,10 +126,10 @@ export function localStylesToClass(
120
126
  node: LayoutNode,
121
127
  name: string,
122
128
  ): { design: DesignSystem; node: LayoutNode; classId: string } | null {
123
- const trimmed = name.trim().slice(0, 60);
129
+ const trimmed = cleanClassName(name);
124
130
  if (!trimmed || localToClassRefusal(design, node)) return null;
125
131
  const classes = design.classes ?? [];
126
- const base = slugify(trimmed).slice(0, 34) || "class";
132
+ const base = slugify(trimmed).slice(0, 34).replace(/-+$/, "") || "class";
127
133
  const taken = new Set(classes.map((c) => c.id));
128
134
  let id = base;
129
135
  for (let n = 2; taken.has(id); n++) id = `${base}-${n}`;
@@ -154,12 +160,12 @@ export function duplicateClass(
154
160
  // At the cap the copy would make the design invalid and the save fail (W-218).
155
161
  if (!source || classes.length >= MAX_CLASSES) return design;
156
162
  // W-277: "Card copy", then "Card copy 2"…, so the copy's name is free too.
157
- const stem = `${source.name.slice(0, 52).trim()} copy`;
163
+ const stem = `${clipText(source.name, 52).trim()} copy`;
158
164
  let baseName = stem;
159
165
  for (let n = 2; n <= MAX_CLASSES && classNameTaken(design, baseName); n++) {
160
166
  baseName = `${stem} ${n}`;
161
167
  }
162
- const base = slugify(baseName).slice(0, 34) || "class";
168
+ const base = slugify(baseName).slice(0, 34).replace(/-+$/, "") || "class";
163
169
  const taken = new Set(classes.map((c) => c.id));
164
170
  let id = randomSuffix ? `${base}-${randomSuffix}`.slice(0, 40) : base;
165
171
  for (let n = 2; taken.has(id); n++) id = `${base}-${n}`.slice(0, 40);
@@ -172,9 +178,14 @@ export function duplicateClass(
172
178
  * W-277: whether another class already has this name (case-insensitive). Two classes with one
173
179
  * name can't be told apart in the class picker or the Site styles list.
174
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
+
175
184
  export function classNameTaken(design: DesignSystem, name: string, exceptId?: string): boolean {
176
185
  const wanted = cleanClassName(name).toLowerCase();
177
- 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
+ );
178
189
  }
179
190
 
180
191
  /** The message shown when a new or renamed class would take another class's name (W-277). */
@@ -1,3 +1,4 @@
1
+ import { sameJson } from "../stable-json.ts";
1
2
  import type { DesignSystem } from "../schema/design.ts";
2
3
 
3
4
  export type DesignChange = {
@@ -6,7 +7,8 @@ export type DesignChange = {
6
7
  name: string;
7
8
  };
8
9
 
9
- const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
10
+ /** Key order is ignored: an edit that removes and re-adds a value is no change (W-519). */
11
+ const same = sameJson;
10
12
 
11
13
  /** What Publish styles will write: draft compared with the published design (W-340). */
12
14
  export function designChanges(published: DesignSystem, draft: DesignSystem): DesignChange[] {
@@ -16,6 +18,12 @@ export function designChanges(published: DesignSystem, draft: DesignSystem): Des
16
18
  listChanges(published.variables.fontSizes, draft.variables.fontSizes, "variable", changes);
17
19
  listChanges(published.variables.spacings, draft.variables.spacings, "variable", changes);
18
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" });
19
27
  if (!same(published.direction, draft.direction)) {
20
28
  changes.push({ kind: "changed", what: "setting", name: "Direction" });
21
29
  }
@@ -1,8 +1,11 @@
1
+ import { sameJson } from "../stable-json.ts";
2
+ import { nameKey } from "./classes.ts";
1
3
  import { emptyDesign, type DesignSystem } from "../schema/design.ts";
2
4
 
3
5
  export type DesignConflict = { kind: "variable" | "class" | "setting"; name: string };
4
6
 
5
- const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
7
+ /** Key order is ignored: an edit that removes and re-adds a value is no change (W-519). */
8
+ const same = sameJson;
6
9
 
7
10
  type Named = { id: string; name: string };
8
11
 
@@ -28,6 +31,7 @@ export function mergeDesign(
28
31
  theirs.variables.colors,
29
32
  conflicts,
30
33
  "variable",
34
+ 200,
31
35
  ),
32
36
  fonts: mergeList(
33
37
  from.variables.fonts,
@@ -35,6 +39,7 @@ export function mergeDesign(
35
39
  theirs.variables.fonts,
36
40
  conflicts,
37
41
  "variable",
42
+ 50,
38
43
  ),
39
44
  fontSizes: mergeList(
40
45
  from.variables.fontSizes,
@@ -42,6 +47,7 @@ export function mergeDesign(
42
47
  theirs.variables.fontSizes,
43
48
  conflicts,
44
49
  "variable",
50
+ 50,
45
51
  ),
46
52
  spacings: mergeList(
47
53
  from.variables.spacings,
@@ -49,9 +55,10 @@ export function mergeDesign(
49
55
  theirs.variables.spacings,
50
56
  conflicts,
51
57
  "variable",
58
+ 100,
52
59
  ),
53
60
  },
54
- classes: mergeList(from.classes, ours.classes, theirs.classes, conflicts, "class"),
61
+ classes: mergeList(from.classes, ours.classes, theirs.classes, conflicts, "class", 100),
55
62
  fluidRange: pickSetting(
56
63
  from.fluidRange,
57
64
  ours.fluidRange,
@@ -77,6 +84,32 @@ function mergeList<T extends Named>(
77
84
  theirs: T[] | undefined,
78
85
  conflicts: DesignConflict[],
79
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",
80
113
  ): T[] {
81
114
  const baseItems = base ?? [];
82
115
  const ourItems = ours ?? [];
@@ -87,6 +120,8 @@ function mergeList<T extends Named>(
87
120
  const theirsBy = by(theirItems);
88
121
  const result: T[] = [];
89
122
  const seen = new Set<string>();
123
+ /** Ids whose kept copy is this tab's change (W-620). */
124
+ const fromUs = new Set<string>();
90
125
  const take = (id: string) => {
91
126
  if (seen.has(id)) return;
92
127
  seen.add(id);
@@ -100,6 +135,7 @@ function mergeList<T extends Named>(
100
135
  return;
101
136
  }
102
137
  if (!theyChanged || same(ourItem, theirItem)) {
138
+ if (ourItem && !same(ourItem, theirItem)) fromUs.add(ourItem.id);
103
139
  if (ourItem) result.push(ourItem);
104
140
  return;
105
141
  }
@@ -108,7 +144,26 @@ function mergeList<T extends Named>(
108
144
  };
109
145
  for (const item of theirItems) take(item.id);
110
146
  for (const item of ourItems) take(item.id);
111
- 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
+ });
112
167
  }
113
168
 
114
169
  function pickSetting<T>(
@@ -125,3 +180,38 @@ function pickSetting<T>(
125
180
  conflicts.push({ kind: "setting", name });
126
181
  return theirs;
127
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
  }
@@ -1,8 +1,9 @@
1
+ import { clipText, MAX_DESIGN_BYTES } from "../limits.ts";
1
2
  import { DesignSystem as DesignSystemSchema, DESIGN_SCHEMA_VERSION } from "../schema/design.ts";
2
3
  import type { DesignSystem } from "../schema/design.ts";
3
4
  import { DESIGN_MIGRATIONS, upgradeLayout } from "../migrate/index.ts";
4
5
  import type { Layout } from "../schema/layout.ts";
5
- import { findClassUsages } from "./classes.ts";
6
+ import { findClassUsages, nameKey } from "./classes.ts";
6
7
  import { findVariableUsages } from "./variables.ts";
7
8
 
8
9
  /** The design document as JSON. This file is the backup: there is no revision history. */
@@ -21,23 +22,23 @@ export type DesignImport =
21
22
  function freeName(name: string, taken: Set<string>): string {
22
23
  for (let n = 2; ; n++) {
23
24
  const suffix = ` ${n}`;
24
- const next = `${name.slice(0, 60 - suffix.length).trim()}${suffix}`;
25
- if (!taken.has(next.toLowerCase())) return next;
25
+ const next = `${clipText(name, 60 - suffix.length).trim()}${suffix}`;
26
+ if (!taken.has(nameKey(next))) return next;
26
27
  }
27
28
  }
28
29
 
29
30
  function dedupe<T extends { name: string }>(items: T[], renamed: ImportRename[]): T[] {
30
- const taken = new Set(items.map((item) => item.name.toLowerCase()));
31
+ const taken = new Set(items.map((item) => nameKey(item.name)));
31
32
  const seen = new Set<string>();
32
33
  return items.map((item) => {
33
- const key = item.name.toLowerCase();
34
+ const key = nameKey(item.name);
34
35
  if (!seen.has(key)) {
35
36
  seen.add(key);
36
37
  return item;
37
38
  }
38
39
  const to = freeName(item.name, taken);
39
- taken.add(to.toLowerCase());
40
- seen.add(to.toLowerCase());
40
+ taken.add(nameKey(to));
41
+ seen.add(nameKey(to));
41
42
  renamed.push({ from: item.name, to });
42
43
  return { ...item, name: to };
43
44
  });
@@ -63,6 +64,24 @@ export function uniqueImportNames(design: DesignSystem): {
63
64
  return { design: { ...design, variables, ...(classes ? { classes } : {}) }, renamed };
64
65
  }
65
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
+
66
85
  /** Parse an exported design. Older schema versions are upgraded. A newer file is refused. */
67
86
  export function designFromJson(text: string): DesignImport {
68
87
  let parsed: unknown;
@@ -83,7 +102,26 @@ export function designFromJson(text: string): DesignImport {
83
102
  }
84
103
  const result = DesignSystemSchema.safeParse(upgraded.doc);
85
104
  if (!result.success) return { ok: false, message: "That file is not an EmVB design document." };
86
- return { ok: true, ...uniqueImportNames(result.data) };
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
+ }
114
+ const imported = uniqueImportNames(result.data);
115
+ // W-516: the file cap is 1 MB, but the saved design is capped lower; a design over that cap
116
+ // replaced the site styles in the editor and then every save of them was refused.
117
+ const bytes = new TextEncoder().encode(JSON.stringify(imported.design)).length;
118
+ if (bytes > MAX_DESIGN_BYTES) {
119
+ return {
120
+ ok: false,
121
+ message: `That design is ${Math.ceil(bytes / 1024)} KB; site styles can be at most ${MAX_DESIGN_BYTES / 1024} KB. Remove some classes or variables from the file, then import it again.`,
122
+ };
123
+ }
124
+ return { ok: true, ...imported };
87
125
  }
88
126
 
89
127
  /** The largest design file Import reads (W-214); the saved design is capped far lower. */
@@ -1,3 +1,4 @@
1
+ import { clipText } from "../limits.ts";
1
2
  import type { DesignSystem } from "../schema/design.ts";
2
3
  import type { Layout } from "../schema/layout.ts";
3
4
  import { cleanClassName } from "./classes.ts";
@@ -67,7 +68,12 @@ const RESPONSIVE = ["tablet", "mobile"] as const;
67
68
 
68
69
  /** Style, state styles and device overrides. A nested usage is `<state|device>.<prop>`. */
69
70
  function collectAllUsages(
70
- owner: { style?: StyleProps; states?: StyleStates; devices?: DeviceStyles },
71
+ owner: {
72
+ style?: StyleProps;
73
+ states?: StyleStates;
74
+ devices?: DeviceStyles;
75
+ query?: { style: StyleProps };
76
+ },
71
77
  id: string,
72
78
  kind: VariableKind | undefined,
73
79
  hit: (prop: string) => void,
@@ -79,6 +85,8 @@ function collectAllUsages(
79
85
  for (const device of RESPONSIVE) {
80
86
  collectStyleUsages(owner.devices?.[device], id, kind, (prop) => hit(`${device}.${prop}`));
81
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}`));
82
90
  }
83
91
 
84
92
  /** Find every style property on `layout` that references variable `id` (optionally of `kind`). */
@@ -190,19 +198,33 @@ function stripRefsFromDevices(
190
198
  }
191
199
 
192
200
  /** Style, states and device overrides with the refs removed. Same object when nothing changed. */
193
- function stripOwner<T extends { style?: StyleProps; states?: StyleStates; devices?: DeviceStyles }>(
194
- owner: T,
195
- id: string,
196
- kind: VariableKind | undefined,
197
- ): 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 {
198
209
  const style = stripRefsFromStyle(owner.style, id, kind);
199
210
  const states = stripRefsFromStates(owner.states, id, kind);
200
211
  const devices = stripRefsFromDevices(owner.devices, id, kind);
201
- 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
+ }
202
222
  const next: T = { ...owner, style, states, devices };
203
223
  if (style === undefined) delete next.style;
204
224
  if (states === undefined) delete next.states;
205
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 ?? {} };
206
228
  return next;
207
229
  }
208
230
 
@@ -279,12 +301,12 @@ export function duplicateVariable(
279
301
  // A copy past the cap, or a name past 60 characters, would fail to save (W-219).
280
302
  if (!source || variableListFull(design, kind)) return design;
281
303
  // W-278: "Brand copy", then "Brand copy 2"…, so the copy's name is free too.
282
- const stem = `${source.name.slice(0, 52).trim()} copy`;
304
+ const stem = `${clipText(source.name, 52).trim()} copy`;
283
305
  let name = stem;
284
306
  for (let n = 2; n <= MAX_VARIABLES[kind] && variableNameTaken(design, kind, name); n++) {
285
307
  name = `${stem} ${n}`;
286
308
  }
287
- const base = slugify(name).slice(0, 34) || kind;
309
+ const base = slugify(name).slice(0, 34).replace(/-+$/, "") || kind;
288
310
  const taken = new Set(list.map((entry) => entry.id));
289
311
  let nextId = base;
290
312
  for (let n = 2; taken.has(nextId); n++) nextId = `${base}-${n}`.slice(0, 40);
@@ -311,7 +333,7 @@ export function variableNameTaken(
311
333
  ): boolean {
312
334
  const wanted = cleanClassName(name).toLowerCase();
313
335
  return (design.variables[KIND_TO_LIST[kind]] ?? []).some(
314
- (v) => v.id !== exceptId && v.name.toLowerCase() === wanted,
336
+ (v) => v.id !== exceptId && cleanClassName(v.name).toLowerCase() === wanted,
315
337
  );
316
338
  }
317
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"] }),
@@ -166,7 +166,7 @@ export const loop: ElementDefinition<LoopNode> = {
166
166
  ".emvb-loop-grid,.emvb-loop-cards{display:grid;grid-template-columns:repeat(var(--emvb-loop-columns,3),minmax(0,1fr))}" +
167
167
  ".emvb-loop-cards>.emvb-loop-item{padding:1rem;border:1px solid color-mix(in srgb,currentColor 15%,transparent);border-radius:12px;background:color-mix(in srgb,currentColor 3%,transparent)}" +
168
168
  ".emvb-loop-grid>.emvb-loop-empty,.emvb-loop-cards>.emvb-loop-empty{grid-column:1/-1}" +
169
- "@media (max-width: 767px){.emvb-loop-grid,.emvb-loop-cards{grid-template-columns:minmax(0,1fr)}}",
169
+ "@media (max-width: 767.98px){.emvb-loop-grid,.emvb-loop-cards{grid-template-columns:minmax(0,1fr)}}",
170
170
  defaults: () => ({ type: "loop", props: {}, children: [] }),
171
171
  descriptor: {
172
172
  type: "loop",
@@ -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",
@@ -310,6 +311,52 @@ export const pagination: ElementDefinition<PaginationNode> = {
310
311
  message:
311
312
  '{page} and {total} are filled in. EmDash 1.2 doesn\'t report a total, so the count shows "Page N" until it does.',
312
313
  },
314
+ {
315
+ key: "titleText",
316
+ kind: "text",
317
+ label: "Page title text",
318
+ optional: true,
319
+ message:
320
+ 'The browser title of page 2 onward. {title} and {page} are filled in; unset is "{title} – page {page}".',
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
+ },
313
360
  ],
314
361
  },
315
362
  // Rendered by core/render/pagination.ts from the archive's page data (W-222).