@perkyzz/emvb 0.4.0 → 0.6.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 (127) hide show
  1. package/README.md +23 -3
  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 +5 -3
  9. package/src/admin/agents-api.ts +39 -0
  10. package/src/admin/editor/CommandPalette.tsx +43 -2
  11. package/src/admin/editor/Editor.tsx +33 -0
  12. package/src/admin/editor/Timeline.tsx +108 -6
  13. package/src/admin/editor/collection-previews.ts +6 -1
  14. package/src/admin/editor/editor-chrome.tsx +49 -0
  15. package/src/admin/editor/editor-commands.ts +13 -0
  16. package/src/admin/editor/editor-css.ts +7 -0
  17. package/src/admin/editor/feature-css.ts +22 -3
  18. package/src/admin/editor/palette.ts +6 -2
  19. package/src/admin/editor/panels/ColorControl.tsx +24 -12
  20. package/src/admin/editor/panels/ElementPanel.tsx +1 -1
  21. package/src/admin/editor/panels/LayersPanel.tsx +13 -3
  22. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  23. package/src/admin/editor/panels/VariableSection.tsx +5 -3
  24. package/src/admin/editor/panels/color-space.ts +12 -1
  25. package/src/admin/editor/panels/settings/AdvancedFields.tsx +84 -28
  26. package/src/admin/editor/panels/settings/AudienceEditor.tsx +42 -4
  27. package/src/admin/editor/panels/settings/DraftTextField.tsx +38 -9
  28. package/src/admin/editor/panels/settings/FieldControl.tsx +24 -7
  29. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  30. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  31. package/src/admin/editor/panels/settings/MediaPicker.tsx +156 -7
  32. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  33. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +76 -0
  34. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  35. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  36. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  37. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  38. package/src/admin/editor/panels/variable-values.ts +18 -2
  39. package/src/admin/editor/remote-change.ts +67 -0
  40. package/src/admin/editor/store.ts +7 -3
  41. package/src/admin/image-editor/BlurFocus.tsx +112 -0
  42. package/src/admin/image-editor/Canvas.tsx +261 -0
  43. package/src/admin/image-editor/CropOverlay.tsx +390 -0
  44. package/src/admin/image-editor/CurvesPanel.tsx +394 -0
  45. package/src/admin/image-editor/ExportDialog.tsx +354 -0
  46. package/src/admin/image-editor/ImageEditButton.tsx +83 -0
  47. package/src/admin/image-editor/ImageEditorDialog.tsx +786 -0
  48. package/src/admin/image-editor/MetadataPanel.tsx +183 -0
  49. package/src/admin/image-editor/announce.tsx +65 -0
  50. package/src/admin/image-editor/crop-geometry.ts +161 -0
  51. package/src/admin/image-editor/curve-math.ts +177 -0
  52. package/src/admin/image-editor/data-url-fetch.ts +59 -0
  53. package/src/admin/image-editor/engine.ts +55 -0
  54. package/src/admin/image-editor/exif.ts +82 -0
  55. package/src/admin/image-editor/flatten.ts +54 -0
  56. package/src/admin/image-editor/gpu-fit.ts +81 -0
  57. package/src/admin/image-editor/image-editor-css.ts +398 -0
  58. package/src/admin/image-editor/load.ts +109 -0
  59. package/src/admin/image-editor/panels.tsx +287 -0
  60. package/src/admin/image-editor/parts.tsx +565 -0
  61. package/src/admin/image-editor/save.ts +125 -0
  62. package/src/admin/image-editor/tone-panels.tsx +338 -0
  63. package/src/admin/image-editor/tools.ts +59 -0
  64. package/src/admin/image-editor/worker.ts +111 -0
  65. package/src/admin/index.tsx +3 -1
  66. package/src/admin/media-api.ts +132 -2
  67. package/src/admin/pages/AgentsPage.tsx +274 -0
  68. package/src/admin/ui.ts +33 -0
  69. package/src/astro/EmVBPage.astro +11 -2
  70. package/src/astro/floats/runtime.ts +10 -0
  71. package/src/astro/popups/runtime.ts +15 -0
  72. package/src/astro/render.ts +3 -0
  73. package/src/astro/resolve-theme.ts +15 -4
  74. package/src/astro/tabs/runtime.ts +60 -1
  75. package/src/astro/visitor.ts +4 -3
  76. package/src/constants.ts +1 -1
  77. package/src/core/a11y/audit.ts +202 -26
  78. package/src/core/arrange.ts +13 -3
  79. package/src/core/css/generate.ts +9 -1
  80. package/src/core/data/bindings.ts +12 -6
  81. package/src/core/design/classes.ts +5 -3
  82. package/src/core/design/diff.ts +3 -1
  83. package/src/core/design/merge.ts +3 -1
  84. package/src/core/design/transfer.ts +13 -2
  85. package/src/core/design/variables.ts +2 -1
  86. package/src/core/elements/dynamic-elements.ts +9 -1
  87. package/src/core/elements/form-elements.ts +18 -3
  88. package/src/core/elements/index.ts +39 -11
  89. package/src/core/elements/plain-text.ts +2 -2
  90. package/src/core/forms/binding.ts +148 -1
  91. package/src/core/history/diff.ts +32 -4
  92. package/src/core/image-edit/schema.ts +145 -0
  93. package/src/core/image-edit/summary.ts +58 -0
  94. package/src/core/index.ts +14 -0
  95. package/src/core/limits.ts +10 -0
  96. package/src/core/migrate/index.ts +3 -1
  97. package/src/core/perf/meter.ts +9 -1
  98. package/src/core/render/dynamic-post.ts +23 -6
  99. package/src/core/render/form.ts +36 -11
  100. package/src/core/render/index.ts +75 -15
  101. package/src/core/render/pagination.ts +21 -2
  102. package/src/core/sanitize/embed-url.ts +7 -1
  103. package/src/core/sanitize/href.ts +13 -1
  104. package/src/core/schema/descriptors.ts +4 -1
  105. package/src/core/schema/layout.ts +21 -4
  106. package/src/core/share/link.ts +9 -3
  107. package/src/core/stable-json.ts +15 -0
  108. package/src/core/theme/dynamic.ts +32 -24
  109. package/src/core/theme/pagination.ts +30 -3
  110. package/src/core/theme/popup-rules.ts +10 -5
  111. package/src/mcp/errors.ts +44 -0
  112. package/src/mcp/index.ts +4 -0
  113. package/src/mcp/ports.ts +85 -0
  114. package/src/mcp/prompts.ts +76 -0
  115. package/src/mcp/publish.ts +60 -0
  116. package/src/mcp/queue.ts +19 -0
  117. package/src/mcp/rate-limit.ts +80 -0
  118. package/src/mcp/read.ts +486 -0
  119. package/src/mcp/refs.ts +84 -0
  120. package/src/mcp/settings.ts +18 -0
  121. package/src/mcp/tools.ts +265 -0
  122. package/src/mcp/write.ts +664 -0
  123. package/src/server/agent-settings.ts +159 -0
  124. package/src/server/design-routes.ts +71 -17
  125. package/src/server/icon-routes.ts +13 -6
  126. package/src/server/mcp-routes.ts +323 -0
  127. package/src/server/plugin.ts +32 -2
@@ -10,6 +10,8 @@ import {
10
10
  } from "../../core/index.ts";
11
11
  import type { Fetcher } from "../api.ts";
12
12
  import { discardDraft } from "../content-api.ts";
13
+ import { ImageEditorLauncher } from "../image-editor/ImageEditButton.tsx";
14
+ import { saveEditedCopy } from "../media-api.ts";
13
15
  import { A11yDialog } from "./A11yCopilot.tsx";
14
16
  import { CommandPalette } from "./CommandPalette.tsx";
15
17
  import { ConflictDialog, DeleteSubtreeDialog, LeaveDialog, RevertDialog } from "./dialogs.tsx";
@@ -64,6 +66,7 @@ const CLOSED = {
64
66
  a11y: false,
65
67
  leave: false,
66
68
  revert: false,
69
+ imageEditor: false,
67
70
  };
68
71
 
69
72
  type ChromeKey = keyof typeof CLOSED;
@@ -222,6 +225,13 @@ export function EditorDialogs({
222
225
  count={deleteAsk?.count ?? 0}
223
226
  onConfirm={() => deleteAsk && finishDelete(deleteAsk.id)}
224
227
  />
228
+ <PaletteImageEditor
229
+ open={chrome.flags.imageEditor}
230
+ onOpenChange={chrome.setOpen("imageEditor")}
231
+ selectedNode={selectedNode}
232
+ fetcher={fetcher}
233
+ dispatch={dispatch}
234
+ />
225
235
  <ShortcutsDialog open={chrome.flags.shortcuts} onOpenChange={chrome.setOpen("shortcuts")} />
226
236
  <CommandPalette
227
237
  open={chrome.flags.palette}
@@ -344,3 +354,42 @@ export function EditorDialogs({
344
354
  </>
345
355
  );
346
356
  }
357
+
358
+ /**
359
+ * The image editor opened from the command palette's "Edit image" (W-486). It edits the Image
360
+ * element that was selected when it opened, and saves the copy onto that element.
361
+ */
362
+ function PaletteImageEditor({
363
+ open,
364
+ onOpenChange,
365
+ selectedNode,
366
+ fetcher,
367
+ dispatch,
368
+ }: {
369
+ open: boolean;
370
+ onOpenChange: (open: boolean) => void;
371
+ selectedNode: LayoutNode | null;
372
+ fetcher: Fetcher;
373
+ dispatch: React.Dispatch<EditorAction>;
374
+ }) {
375
+ const [target, setTarget] = React.useState<LayoutNode | null>(null);
376
+ if (open && !target && selectedNode?.type === "image") setTarget(selectedNode);
377
+ if (!target) return null;
378
+ const props = target.props as Record<string, unknown>;
379
+ return (
380
+ <ImageEditorLauncher
381
+ open={open}
382
+ onOpenChange={onOpenChange}
383
+ imageProps={props}
384
+ onSave={async (file, copy) => {
385
+ const next = await saveEditedCopy(fetcher, props, file, copy);
386
+ dispatch({
387
+ type: "update-node",
388
+ id: target.id,
389
+ update: (node) => ({ ...node, props: next }) as LayoutNode,
390
+ });
391
+ }}
392
+ onClosed={() => setTarget(null)}
393
+ />
394
+ );
395
+ }
@@ -42,6 +42,8 @@ export type CommandRunners = {
42
42
  setDevice?: (device: PopupDevice) => void;
43
43
  openShortcuts?: () => void;
44
44
  rename?: () => void;
45
+ /** Set when the selection is an Image element the image editor can open (W-486). */
46
+ editImage?: () => void;
45
47
  };
46
48
 
47
49
  export type CommandInput = {
@@ -177,6 +179,12 @@ const SPECS: readonly Spec[] = [
177
179
  { id: "device-desktop", labels: { palette: "View on desktop" }, surfaces: ["palette"] },
178
180
  { id: "device-tablet", labels: { palette: "View on tablet" }, surfaces: ["palette"] },
179
181
  { id: "device-mobile", labels: { palette: "View on mobile" }, surfaces: ["palette"] },
182
+ {
183
+ id: "edit-image",
184
+ labels: { palette: "Edit image" },
185
+ keywords: "photo picture crop rotate adjust filter curves blur",
186
+ surfaces: ["palette"],
187
+ },
180
188
  { id: "shortcuts", labels: { palette: "Keyboard shortcuts" }, surfaces: ["palette"] },
181
189
  { id: "hide-on-device", labels: {}, surfaces: ["device"] },
182
190
  ];
@@ -204,6 +212,7 @@ const ORDER: Record<CommandSurface, readonly string[]> = {
204
212
  "preview",
205
213
  "undo",
206
214
  "redo",
215
+ "edit-image",
207
216
  "duplicate",
208
217
  "delete",
209
218
  "deselect",
@@ -227,6 +236,7 @@ const MOVE_IDS = new Set(["move-up", "move-down", "delete"]);
227
236
  function shown(id: string, input: CommandInput): boolean {
228
237
  const clip = !!input.runners.copy;
229
238
  if (id === "rename") return !!input.runners.rename;
239
+ if (id === "edit-image") return !!input.runners.editImage;
230
240
  if (id === "paste-inside") return clip && input.isParent;
231
241
  if (id === "paste") return clip && (input.surface !== "layers" || !input.isRoot);
232
242
  if (CLIP_IDS.has(id)) return clip;
@@ -270,6 +280,9 @@ export function runCommand(runners: CommandRunners, id: string, targetId: string
270
280
  case "rename":
271
281
  runners.rename?.();
272
282
  return;
283
+ case "edit-image":
284
+ runners.editImage?.();
285
+ return;
273
286
  case "copy":
274
287
  if (targetId) runners.copy?.(targetId);
275
288
  return;
@@ -87,6 +87,10 @@ export const EDITOR_CSS = `${UI_CSS}
87
87
  .emvb-panel-title { margin: 0; font-size: 14px; line-height: 18px; font-weight: 600; }
88
88
  .emvb-panel-body, .emvb-field-group, .emvb-new-variable, .emvb-section-body { display: flex; flex-direction: column; gap: 10px; }
89
89
  .emvb-field-group, .emvb-new-variable { gap: 8px; }
90
+ .emvb-query-style, .emvb-query-add { display: flex; flex-direction: column; gap: 6px; }
91
+ .emvb-query-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
92
+ .emvb-query-row > label, .emvb-query-row > .emvb-helper { grid-column: 1 / -1; }
93
+ .emvb-query-style { border-left: 2px solid var(--emvb-border, #d4d4d8); padding-left: 8px; }
90
94
  .emvb-section-header { display: flex; align-items: center; justify-content: space-between; width: 100%; height: var(--emvb-control); margin-top: 4px; padding: 0; border: 0; border-top: 1px solid var(--color-kumo-hairline); background: none; color: var(--text-color-kumo-strong, var(--text-color-kumo-default)); font: inherit; font-size: 12px; font-weight: 600; letter-spacing: 0.01em; cursor: pointer; }
91
95
  .emvb-section-header:focus-visible, .emvb-layer-row:focus-visible, .emvb-empty-prompt:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; }
92
96
  .emvb-count { margin-left: 4px; font-size: 12px; line-height: 16px; font-weight: 400; color: var(--text-color-kumo-subtle); }
@@ -404,6 +408,9 @@ export const EDITOR_CSS = `${UI_CSS}
404
408
 
405
409
  .emvb-media-actions { display: flex; flex-wrap: wrap; gap: 8px; }
406
410
  .emvb-media-preview { display: flex; flex-direction: column; gap: 4px; }
411
+ .emvb-media-edited { align-self: flex-start; }
412
+ .emvb-media-cell { position: relative; }
413
+ .emvb-media-cell .emvb-media-card-menu { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; padding: 0; opacity: 0.92; }
407
414
  .emvb-media-thumb { display: block; max-width: 100%; max-height: 96px; border-radius: 6px; object-fit: contain; background: var(--color-kumo-canvas); }
408
415
  .emvb-media-dialog {
409
416
  display: flex;
@@ -53,10 +53,29 @@ export const FEATURE_CSS = `
53
53
  .emvb-palette-empty { padding: 12px; color: var(--text-color-kumo-subtle); font-size: 13px; }
54
54
  .emvb-palette-tips { margin: 0; padding: 6px 12px; border-top: 1px solid var(--color-kumo-line); font-size: 11px; color: var(--text-color-kumo-subtle); }
55
55
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
56
- .emvb-timeline-body { display: grid; grid-template-columns: 200px 1fr; gap: 16px; margin: 12px 0; min-height: 0; }
56
+ .emvb-timeline-body { display: grid; grid-template-columns: 220px 1fr; gap: 16px; margin: 12px 0; min-height: 0; }
57
57
  .emvb-timeline-list { margin: 0; padding: 0; list-style: none; max-height: 60vh; overflow-y: auto; }
58
- .emvb-timeline-version { width: 100%; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; font-size: 12px; text-align: start; cursor: pointer; }
59
- .emvb-timeline-version[aria-current="true"] { background: var(--color-kumo-tint); font-weight: 600; }
58
+ .emvb-timeline-list { display: grid; gap: 2px; padding-inline-end: 4px; }
59
+ .emvb-timeline-version { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 6px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text-color-kumo-default); font: inherit; font-size: 13px; line-height: 18px; text-align: start; cursor: pointer; }
60
+ .emvb-timeline-version:hover { background: var(--color-kumo-tint); }
61
+ .emvb-timeline-version:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: -2px; }
62
+ .emvb-timeline-when { display: grid; min-width: 0; }
63
+ .emvb-timeline-time { color: var(--text-color-kumo-subtle); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
64
+ .emvb-timeline-version[aria-current="true"] { background: var(--color-kumo-base); box-shadow: var(--shadow-sm); outline: 1px solid var(--color-kumo-line); font-weight: 600; }
65
+ .emvb-timeline-agent { display: inline-flex; flex: none; align-items: center; gap: 3px; padding: 1px 7px 1px 5px; border: 1px solid var(--color-kumo-line); border-radius: 999px; background: var(--color-kumo-base); color: var(--text-color-kumo-default); font-size: 11px; line-height: 16px; font-weight: 600; }
66
+ /* W-477: a themed card under the top bar, centred over the canvas so it never hides the inspector. */
67
+ .emvb-remote-change { position: fixed; inset-block-start: 96px; inset-inline-start: 50%; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px)); padding: 10px 10px 10px 12px; border: 1px solid var(--color-kumo-line); border-radius: 12px; background: var(--color-kumo-base); color: var(--text-color-kumo-default); box-shadow: var(--shadow-lg); font-size: 13px; line-height: 18px; }
68
+ .emvb-remote-change-icon { display: grid; flex: none; place-items: center; width: 32px; height: 32px; border-radius: 999px; background: var(--color-kumo-tint); color: var(--text-color-kumo-brand, var(--text-color-kumo-default)); }
69
+ .emvb-remote-change-text { display: grid; min-width: 0; }
70
+ .emvb-remote-change-text strong { font-weight: 600; }
71
+ .emvb-remote-change-text span { color: var(--text-color-kumo-subtle); }
72
+ /* W-477: All | People | Agents as the editor's segmented control (Kumo Tabs "segmented" look). */
73
+ .emvb-timeline-who { display: inline-flex; gap: 2px; margin-block: 12px 4px; padding: 2px; border-radius: 8px; background: var(--color-kumo-recessed); }
74
+ .emvb-timeline-who-option { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text-color-kumo-default); font: inherit; font-size: 13px; cursor: pointer; }
75
+ .emvb-timeline-who-option:hover { background: var(--color-kumo-tint); }
76
+ .emvb-timeline-who-option:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
77
+ .emvb-timeline-who-option[aria-pressed="true"] { background: var(--color-kumo-base); box-shadow: var(--shadow-sm); outline: 1px solid var(--color-kumo-line); font-weight: 500; }
78
+ .emvb-timeline-count { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--color-kumo-tint); color: var(--text-color-kumo-subtle); font-size: 11px; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums; }
60
79
  .emvb-timeline-frames { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
61
80
  .emvb-timeline-frames figure { margin: 0; }
62
81
  .emvb-timeline-frames figcaption { font-size: 12px; color: var(--text-color-kumo-subtle); margin-bottom: 4px; }
@@ -22,13 +22,17 @@ const PREFIXES: Record<string, PaletteGroup> = {
22
22
  ".": "Apply class",
23
23
  };
24
24
 
25
+ /** W-420: accents and case don't matter, so "cafe" finds "Café" and "strasse" finds "Straße". */
26
+ const fold = (value: string) =>
27
+ value.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/ß/g, "ss");
28
+
25
29
  /**
26
30
  * How well `query` matches `text` (W-314): null when its letters don't all appear in order.
27
31
  * Higher is better: a prefix beats a word start, which beats a scattered match.
28
32
  */
29
33
  export function fuzzyScore(query: string, text: string): number | null {
30
- const q = query.trim().toLowerCase();
31
- const t = text.toLowerCase();
34
+ const q = fold(query.trim());
35
+ const t = fold(text);
32
36
  if (!q) return 0;
33
37
  if (t.startsWith(q)) return 1000 - t.length;
34
38
  const at = t.indexOf(q);
@@ -15,13 +15,14 @@ import {
15
15
  formatOklch,
16
16
  formatRgb,
17
17
  oklchClipped,
18
+ hexInput,
18
19
  parseHex,
19
20
  parseOklch,
20
21
  parseRgb,
21
22
  toHex,
22
23
  } from "./color-space.ts";
23
24
  import { InlineError } from "./inline-error.tsx";
24
- import { pickerHex } from "./variable-values.ts";
25
+ import { pickerHex, withPreviousAlpha } from "./variable-values.ts";
25
26
 
26
27
  const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
27
28
  const NONE = "__none__";
@@ -225,15 +226,22 @@ function CustomColor({
225
226
  const [error, setError] = React.useState<{ field: Notation; message: string } | null>(null);
226
227
  const picker = React.useRef<HTMLInputElement | null>(null);
227
228
  const commit = (next: string) => {
228
- const hex = next.trim();
229
- if (hex === value || hex === "") {
229
+ const typed = next.trim();
230
+ if (typed === value || typed === "") {
230
231
  setError(null);
231
232
  return;
232
233
  }
233
- if (!HEX.test(hex)) {
234
+ const hex = hexInput(typed);
235
+ if (!hex) {
234
236
  setError({ field: "hex", message: BAD_HEX });
235
237
  return;
236
238
  }
239
+ if (hex === value) {
240
+ setError(null);
241
+ setDraft(hex);
242
+ return;
243
+ }
244
+ setDraft(hex);
237
245
  setError(null);
238
246
  onCommit(hex);
239
247
  };
@@ -242,8 +250,9 @@ function CustomColor({
242
250
  const el = picker.current;
243
251
  if (!el) return;
244
252
  const onPicked = () => {
245
- setDraft(el.value);
246
- commit(el.value);
253
+ const picked = withPreviousAlpha(el.value, value);
254
+ setDraft(picked);
255
+ commit(picked);
247
256
  };
248
257
  el.addEventListener("change", onPicked);
249
258
  return () => el.removeEventListener("change", onPicked);
@@ -270,7 +279,7 @@ function CustomColor({
270
279
  aria-label={`Pick ${label.toLowerCase()}`}
271
280
  ref={picker}
272
281
  value={pickerHex(HEX.test(draft) ? draft : value || "#000000")}
273
- onChange={(event) => setDraft(event.target.value)}
282
+ onChange={(event) => setDraft(withPreviousAlpha(event.target.value, value))}
274
283
  />
275
284
  </div>
276
285
  {error?.field === "hex" && <InlineError>{error.message}</InlineError>}
@@ -379,14 +388,16 @@ function VariableValue({
379
388
  const [draft, setDraft] = React.useState(value);
380
389
  const [error, setError] = React.useState<string | null>(null);
381
390
  const commit = async () => {
382
- if (draft === value) return;
383
- if (!HEX.test(draft)) {
391
+ const hex = hexInput(draft);
392
+ if (hex === value) return;
393
+ if (!hex) {
384
394
  setError(BAD_HEX);
385
395
  return;
386
396
  }
387
397
  setError(null);
398
+ setDraft(hex);
388
399
  try {
389
- await onCommit(draft);
400
+ await onCommit(hex);
390
401
  } catch (failure) {
391
402
  setError(errorText(failure));
392
403
  }
@@ -426,11 +437,12 @@ function NewVariable({
426
437
  const [busy, setBusy] = React.useState(false);
427
438
  const create = async () => {
428
439
  if (!name.trim()) return setError("Enter a name for the variable.");
429
- if (!HEX.test(hex)) return setError(BAD_HEX);
440
+ const typed = hexInput(hex);
441
+ if (!typed) return setError(BAD_HEX);
430
442
  setError(null);
431
443
  setBusy(true);
432
444
  try {
433
- await onCreate(name.trim(), hex);
445
+ await onCreate(name.trim(), typed);
434
446
  } catch (failure) {
435
447
  setError(errorText(failure));
436
448
  setBusy(false);
@@ -586,7 +586,7 @@ function KnownElementPanel({
586
586
  <>
587
587
  <HtmlIdField node={node} layout={layout} onChange={onChange} />
588
588
  <DirectionField node={node} onChange={onChange} />
589
- {"children" in node && <ContainerQueryFields node={node} onChange={onChange} />}
589
+ <ContainerQueryFields node={node} onChange={onChange} />
590
590
  <AttributesEditor
591
591
  attributes={node.attributes}
592
592
  onChange={(attributes) => onChange({ ...node, attributes })}
@@ -14,6 +14,7 @@ import {
14
14
  SCRIPT_LABELS,
15
15
  type PageScript,
16
16
  } from "../../../core/index.ts";
17
+ import { clipText } from "../../../core/limits.ts";
17
18
  import { indexLayout } from "../../../core/tree-ops.ts";
18
19
  import { EXISTING_ELEMENT_MIME } from "../dnd/drop-target.ts";
19
20
  import { ELEMENT_NAMES, elementIcon } from "../element-chrome.ts";
@@ -106,6 +107,14 @@ function menuItems(
106
107
  }));
107
108
  }
108
109
 
110
+ /** The row above or below `id` among the rows Layers shows, or `id` at either end. */
111
+ function visibleStep(layout: Layout, id: string, collapsed: Set<string>, by: 1 | -1): string {
112
+ const ids = rows(layout.root, 0, collapsed).map((row) => row.node.id);
113
+ const at = ids.indexOf(id);
114
+ if (at === -1) return by === 1 ? nextInOrder(layout, id) : previousInOrder(layout, id);
115
+ return ids[at + by] ?? id;
116
+ }
117
+
109
118
  /** What a key does in the tree: select another row, toggle the selected one, or nothing. */
110
119
  export function treeKey(
111
120
  event: { key: string; shiftKey: boolean; altKey?: boolean; ctrlKey?: boolean; metaKey?: boolean },
@@ -118,10 +127,11 @@ export function treeKey(
118
127
  // them. Selecting here first made the move act on the newly selected row instead.
119
128
  if (event.altKey || event.ctrlKey || event.metaKey) return null;
120
129
  switch (event.key) {
130
+ // W-520: rows inside a collapsed element are skipped; selecting one re-opened the branch.
121
131
  case "ArrowDown":
122
- return { select: nextInOrder(layout, id) };
132
+ return { select: visibleStep(layout, id, collapsed, 1) };
123
133
  case "ArrowUp":
124
- return { select: previousInOrder(layout, id) };
134
+ return { select: visibleStep(layout, id, collapsed, -1) };
125
135
  case "ArrowRight":
126
136
  return collapsed.has(id) ? { toggle: true } : { select: firstChild(layout, id) };
127
137
  case "ArrowLeft": {
@@ -394,7 +404,7 @@ const LayerRow = React.memo(function LayerRow({
394
404
  refocus.current = byKey;
395
405
  setRenaming(false);
396
406
  if (text === null || !actions.onRename) return;
397
- const next = text.trim().slice(0, 80) || undefined;
407
+ const next = clipText(text.trim(), 80).trim() || undefined;
398
408
  if (next !== node.label) actions.onRename(node.id, next);
399
409
  };
400
410
  return (
@@ -7,10 +7,12 @@ import {
7
7
  typeScale,
8
8
  type DesignSystem,
9
9
  } from "../../../core/index.ts";
10
+ import { fieldNumber } from "./settings/number-input.ts";
10
11
 
12
+ // W-436: the fields are labelled "(px)", so "18px" is 18.
11
13
  const num = (text: string): number | undefined => {
12
- const n = Number(text);
13
- return text.trim() !== "" && Number.isFinite(n) ? n : undefined;
14
+ const n = fieldNumber(text, "px");
15
+ return Number.isFinite(n) ? n : undefined;
14
16
  };
15
17
 
16
18
  /**
@@ -41,6 +41,7 @@ import {
41
41
  lengthPx,
42
42
  parseValue,
43
43
  pickerHex,
44
+ withPreviousAlpha,
44
45
  valueText,
45
46
  type Length,
46
47
  } from "./variable-values.ts";
@@ -162,8 +163,9 @@ function ValueEditor({
162
163
  const el = picker.current;
163
164
  if (!el) return;
164
165
  const onChange = () => {
165
- setText(el.value);
166
- commit(el.value);
166
+ const picked = withPreviousAlpha(el.value, committed.current);
167
+ setText(picked);
168
+ commit(picked);
167
169
  };
168
170
  el.addEventListener("change", onChange);
169
171
  return () => el.removeEventListener("change", onChange);
@@ -179,7 +181,7 @@ function ValueEditor({
179
181
  className="emvb-site-picker"
180
182
  aria-label={`Pick ${item.name}`}
181
183
  value={pickerHex(error ? current : text)}
182
- onChange={(event) => setText(event.target.value)}
184
+ onChange={(event) => setText(withPreviousAlpha(event.target.value, committed.current))}
183
185
  />
184
186
  )}
185
187
  <Input
@@ -30,6 +30,16 @@ export function parseHex(hex: string): Rgba | null {
30
30
  return { r, g, b, a };
31
31
  }
32
32
 
33
+ /**
34
+ * W-434: a typed or pasted hex as stored, or undefined. Spaces are trimmed and a missing "#" is
35
+ * added, since design tools (Figma among them) copy "1A2B3C" without it.
36
+ */
37
+ export function hexInput(text: string): string | undefined {
38
+ const trimmed = text.trim();
39
+ const hex = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
40
+ return HEX.test(hex) ? hex : undefined;
41
+ }
42
+
33
43
  /** 6 digits when opaque, 8 when not. */
34
44
  export function toHex({ r, g, b, a }: Rgba): string {
35
45
  const hex = [r, g, b].map((n) => channel(n).toString(16).padStart(2, "0")).join("");
@@ -52,7 +62,8 @@ export function parseRgb(text: string): Rgba | null {
52
62
  .trim()
53
63
  .replace(/^rgba?\(/i, "")
54
64
  .replace(/\)$/, "")
55
- .split(/[\s,]+/)
65
+ // W-435: CSS's own "rgb(0 0 0 / 50%)", as DevTools copies it, puts a slash before alpha.
66
+ .split(/[\s,/]+/)
56
67
  .filter(Boolean);
57
68
  if (parts.length !== 3 && parts.length !== 4) return null;
58
69
  const nums = parts.slice(0, 3).map((part) => Number(part));
@@ -9,6 +9,7 @@ import {
9
9
  savableAttributes,
10
10
  type AttributeRow,
11
11
  } from "./advanced-rules.ts";
12
+ import { QueryStyleRows } from "./QueryStyleRows.tsx";
12
13
 
13
14
  /**
14
15
  * CSS id: a value the page can't save (bad characters, or another element's id) stays in the
@@ -82,51 +83,106 @@ export function ContainerQueryFields({
82
83
  node: LayoutNode;
83
84
  onChange: (node: LayoutNode) => void;
84
85
  }) {
85
- const min = node.query?.min ?? "";
86
+ // W-401: a draft committed on blur or Enter. Clearing the field while retyping a width used to
87
+ // delete the query and every style in it on the first keystroke.
88
+ const stored = node.query ? String(node.query.min) : "";
89
+ const [draft, setDraft] = React.useState(stored);
90
+ const [error, setError] = React.useState<string | null>(null);
91
+ React.useEffect(() => {
92
+ setDraft(stored);
93
+ setError(null);
94
+ }, [node.id, stored]);
95
+ const [confirming, setConfirming] = React.useState(false);
96
+ React.useEffect(() => setConfirming(false), [node.id]);
97
+ const copyStyle = () => {
98
+ setConfirming(false);
99
+ onChange({ ...node, query: { min: node.query?.min ?? 480, style: node.style ?? {} } });
100
+ };
101
+ const commitMin = () => {
102
+ const next = draft.trim();
103
+ if (next === stored) {
104
+ setError(null);
105
+ return;
106
+ }
107
+ if (next === "") {
108
+ setError(null);
109
+ const { query: _query, ...rest } = node;
110
+ onChange(rest);
111
+ return;
112
+ }
113
+ const width = Number(next);
114
+ if (!/^\d+$/.test(next) || width < 1 || width > 3840) {
115
+ setError("Use a whole number of px from 1 to 3840.");
116
+ return;
117
+ }
118
+ setError(null);
119
+ onChange({ ...node, query: { min: width, style: node.query?.style ?? {} } });
120
+ };
86
121
  return (
87
122
  <div className="emvb-field-group" data-emvb-container="">
88
- <label className="emvb-check">
89
- <input
90
- type="checkbox"
91
- checked={node.container === true}
92
- onChange={(event) =>
93
- onChange({ ...node, container: event.target.checked ? true : undefined })
94
- }
95
- />
96
- Query container
97
- </label>
123
+ {/* W-398: any element can take container-query styles; only a box can be the container. */}
124
+ {"children" in node && (
125
+ <label className="emvb-check">
126
+ <input
127
+ type="checkbox"
128
+ checked={node.container === true}
129
+ onChange={(event) =>
130
+ onChange({ ...node, container: event.target.checked ? true : undefined })
131
+ }
132
+ />
133
+ Query container
134
+ </label>
135
+ )}
98
136
  <Input
99
137
  label="Styles from container width (px)"
100
138
  className={FIELD}
101
- type="number"
102
- min={1}
103
- max={3840}
104
- value={min === "" ? "" : String(min)}
105
- onChange={(event) => {
106
- const next = event.target.value.trim();
107
- if (next === "") {
108
- const { query: _query, ...rest } = node;
109
- onChange(rest);
110
- return;
111
- }
112
- const width = Number(next);
113
- if (!Number.isInteger(width) || width < 1 || width > 3840) return;
114
- onChange({ ...node, query: { min: width, style: node.query?.style ?? {} } });
139
+ inputMode="numeric"
140
+ value={draft}
141
+ error={error ?? undefined}
142
+ data-emvb-query-min=""
143
+ onChange={(event) => setDraft(event.target.value)}
144
+ onBlur={commitMin}
145
+ onKeyDown={(event) => {
146
+ if (event.key === "Enter") commitMin();
115
147
  }}
116
148
  />
117
149
  <Button
118
150
  type="button"
119
151
  variant="secondary"
120
152
  className={BUTTON}
153
+ data-emvb-query-copy=""
121
154
  onClick={() => {
122
- const width = node.query?.min ?? 480;
123
- onChange({ ...node, query: { min: width, style: node.style ?? {} } });
155
+ // W-402: ask before replacing container-query styles that differ from the style.
156
+ const own = Object.keys(node.query?.style ?? {}).length;
157
+ const same = JSON.stringify(node.query?.style ?? {}) === JSON.stringify(node.style ?? {});
158
+ if (own > 0 && !same) setConfirming(true);
159
+ else copyStyle();
124
160
  }}
125
161
  >
126
162
  Use current style at that width
127
163
  </Button>
164
+ {confirming && (
165
+ <div className="emvb-query-confirm" role="alert" data-emvb-query-confirm="">
166
+ <p className="emvb-helper">
167
+ Replace the {Object.keys(node.query?.style ?? {}).length} styles set for this width with
168
+ the current style?
169
+ </p>
170
+ <Button type="button" variant="destructive" className={BUTTON} onClick={copyStyle}>
171
+ Replace
172
+ </Button>
173
+ <Button
174
+ type="button"
175
+ variant="secondary"
176
+ className={BUTTON}
177
+ onClick={() => setConfirming(false)}
178
+ >
179
+ Keep them
180
+ </Button>
181
+ </div>
182
+ )}
183
+ <QueryStyleRows node={node} onChange={onChange} />
128
184
  <p className="emvb-helper">
129
- Query container makes this box the size children measure. The copied style is what applies
185
+ Query container makes this box the size children measure. The styles listed here apply
130
186
  inside @container once the container is at least that wide, not the viewport.
131
187
  </p>
132
188
  </div>
@@ -29,6 +29,25 @@ export function parseSegments(text: string): string[] {
29
29
  return [...new Set(names)].slice(0, 20);
30
30
  }
31
31
 
32
+ const ZONE = /^[A-Za-z][A-Za-z0-9_+-]*(\/[A-Za-z0-9_+-]+){0,2}$/;
33
+
34
+ /**
35
+ * W-438: the time zone as stored ("" for UTC), or null when it isn't a zone this server knows.
36
+ * "america/toronto" becomes "America/Toronto". An unknown zone used to be saved and silently
37
+ * read as UTC.
38
+ */
39
+ export function readTimeZone(text: string): string | null {
40
+ const value = text.trim();
41
+ if (value === "") return "";
42
+ if (!ZONE.test(value)) return null;
43
+ try {
44
+ const zone = new Intl.DateTimeFormat("en-US", { timeZone: value }).resolvedOptions().timeZone;
45
+ return ZONE.test(zone) ? zone : null;
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+
32
51
  /** Drops empty rules so the stored audience stays valid (W-313). */
33
52
  function tidy(audience: Audience): Audience | undefined {
34
53
  const next: Audience = { ...audience };
@@ -61,9 +80,14 @@ export function AudienceEditor({
61
80
  const [countryText, setCountryText] = React.useState(node.audience?.countries?.join(", ") ?? "");
62
81
  const [segmentText, setSegmentText] = React.useState(node.audience?.segments?.join(", ") ?? "");
63
82
  const [segmentError, setSegmentError] = React.useState<string | null>(null);
83
+ // W-438: the zone is typed in full before it's checked; checking each keystroke refused the "/".
84
+ const [zoneText, setZoneText] = React.useState(node.audience?.timeZone ?? "");
85
+ const [zoneError, setZoneError] = React.useState<string | null>(null);
64
86
  React.useEffect(() => {
65
87
  setCountryText(node.audience?.countries?.join(", ") ?? "");
66
88
  setSegmentText(node.audience?.segments?.join(", ") ?? "");
89
+ setZoneText(node.audience?.timeZone ?? "");
90
+ setZoneError(null);
67
91
  }, [node.id]);
68
92
  if (isRoot) return null;
69
93
  const audience = node.audience;
@@ -261,18 +285,32 @@ export function AudienceEditor({
261
285
  <span className="emvb-bind-label">Time zone</span>
262
286
  <input
263
287
  className="emvb-native-input"
264
- value={base.timeZone ?? ""}
288
+ value={zoneText}
265
289
  placeholder="UTC"
266
290
  data-emvb-audience-zone=""
291
+ aria-invalid={zoneError ? true : undefined}
292
+ aria-describedby={zoneError ? `${id}-zone-error` : undefined}
267
293
  onChange={(event) => {
268
- const value = event.currentTarget.value.trim();
269
- if (value && !/^[A-Za-z][A-Za-z0-9_+-]*(\/[A-Za-z0-9_+-]+){0,2}$/.test(value))
294
+ setZoneText(event.currentTarget.value);
295
+ setZoneError(null);
296
+ }}
297
+ onBlur={() => {
298
+ const zone = readTimeZone(zoneText);
299
+ if (zone === null) {
300
+ setZoneError("Unknown time zone. Use a name such as America/Toronto.");
270
301
  return;
271
- set({ ...base, timeZone: value });
302
+ }
303
+ setZoneText(zone);
304
+ if (zone !== (base.timeZone ?? "")) set({ ...base, timeZone: zone });
272
305
  }}
273
306
  />
274
307
  </label>
275
308
  )}
309
+ {(base.hours || base.days) && zoneError && (
310
+ <span className="emvb-helper" id={`${id}-zone-error`} data-emvb-audience-zone-error="">
311
+ {zoneError}
312
+ </span>
313
+ )}
276
314
  <p className="emvb-helper" data-emvb-audience-help="">
277
315
  {ruleCount(base) === 0
278
316
  ? "Add a rule: with none, every visitor matches."