@perkyzz/emvb 0.7.0 → 0.9.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 (97) hide show
  1. package/README.md +3 -3
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  5. package/src/admin/editor/Editor.tsx +71 -1
  6. package/src/admin/editor/FieldPreview.tsx +164 -0
  7. package/src/admin/editor/PerfMeter.tsx +3 -9
  8. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  9. package/src/admin/editor/ShareLink.tsx +2 -7
  10. package/src/admin/editor/ShortcutsDialog.tsx +19 -11
  11. package/src/admin/editor/Timeline.tsx +2 -7
  12. package/src/admin/editor/TopBar.tsx +32 -1
  13. package/src/admin/editor/dialogs.tsx +3 -14
  14. package/src/admin/editor/editor-chrome.tsx +8 -24
  15. package/src/admin/editor/editor-commands.ts +15 -1
  16. package/src/admin/editor/editor-css.ts +6 -2
  17. package/src/admin/editor/feature-css.ts +11 -1
  18. package/src/admin/editor/focus-when-lost.ts +23 -0
  19. package/src/admin/editor/host.ts +6 -0
  20. package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
  21. package/src/admin/editor/palette-items.ts +17 -0
  22. package/src/admin/editor/panels/AddPanel.tsx +9 -1
  23. package/src/admin/editor/panels/ElementPanel.tsx +4 -1
  24. package/src/admin/editor/panels/LayersPanel.tsx +6 -1
  25. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  26. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  27. package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
  28. package/src/admin/editor/panels/TokenScales.tsx +16 -16
  29. package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
  30. package/src/admin/editor/panels/color-space.ts +14 -26
  31. package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
  32. package/src/admin/editor/panels/settings/BackgroundControls.tsx +4 -5
  33. package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
  34. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  35. package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
  36. package/src/admin/editor/panels/settings/length-units.ts +2 -1
  37. package/src/admin/editor/shortcuts.ts +14 -0
  38. package/src/admin/editor/useSavedSections.ts +197 -0
  39. package/src/admin/image-editor/Canvas.tsx +61 -17
  40. package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
  41. package/src/admin/image-editor/image-editor-css.ts +11 -8
  42. package/src/admin/image-editor/parts.tsx +18 -17
  43. package/src/admin/image-editor/save.ts +31 -1
  44. package/src/admin/index.tsx +5 -1
  45. package/src/admin/media-api.ts +27 -0
  46. package/src/admin/pages/AgentsPage.tsx +3 -3
  47. package/src/admin/pages/CollectionsPage.tsx +215 -0
  48. package/src/admin/pages/ThemePartList.tsx +32 -4
  49. package/src/admin/saved-sections-api.ts +51 -0
  50. package/src/admin/setup/host-collections.ts +100 -0
  51. package/src/admin/theme-api.ts +3 -2
  52. package/src/admin/ui.ts +9 -0
  53. package/src/admin/widgets/CanvasField.tsx +202 -0
  54. package/src/admin/widgets/convert-body.ts +54 -0
  55. package/src/admin/widgets/field-fetcher.ts +79 -0
  56. package/src/astro/index.ts +2 -0
  57. package/src/astro/page-count.ts +77 -0
  58. package/src/astro/popups/runtime.ts +8 -6
  59. package/src/astro/resolve-theme.ts +44 -2
  60. package/src/astro/resolve.ts +40 -4
  61. package/src/astro/responsive-images.ts +99 -0
  62. package/src/constants.ts +1 -1
  63. package/src/core/a11y/audit.ts +32 -7
  64. package/src/core/arrange.ts +21 -6
  65. package/src/core/canvas-collections.ts +20 -0
  66. package/src/core/css/print.ts +5 -0
  67. package/src/core/design/classes.ts +23 -9
  68. package/src/core/design/devices.ts +7 -13
  69. package/src/core/design/states.ts +7 -13
  70. package/src/core/elements/dynamic-elements.ts +27 -12
  71. package/src/core/elements/index.ts +1 -1
  72. package/src/core/elements/menu.ts +3 -0
  73. package/src/core/icons/animation-runs.ts +11 -0
  74. package/src/core/index.ts +22 -0
  75. package/src/core/migrate/index.ts +3 -0
  76. package/src/core/portable-text.ts +127 -0
  77. package/src/core/render/loop.ts +1 -1
  78. package/src/core/render/pagination.ts +20 -1
  79. package/src/core/sanitize/css.ts +14 -6
  80. package/src/core/saved-sections.ts +318 -0
  81. package/src/core/schema/design.ts +1 -1
  82. package/src/core/schema/layout.ts +6 -1
  83. package/src/core/schema/style.ts +4 -2
  84. package/src/core/theme/float.ts +3 -0
  85. package/src/core/theme/pagination.ts +34 -24
  86. package/src/core/theme/part-types.ts +4 -4
  87. package/src/index.ts +11 -1
  88. package/src/mcp/ports.ts +22 -1
  89. package/src/mcp/read.ts +1 -1
  90. package/src/mcp/sections.ts +183 -0
  91. package/src/mcp/tools.ts +44 -0
  92. package/src/mcp/write.ts +4 -4
  93. package/src/server/agent-settings.ts +16 -1
  94. package/src/server/hooks.ts +81 -0
  95. package/src/server/mcp-routes.ts +2 -0
  96. package/src/server/plugin.ts +34 -5
  97. package/src/server/saved-sections.ts +163 -0
@@ -18,7 +18,7 @@ export function LoopItemBindControl({
18
18
  fetcher,
19
19
  onChange,
20
20
  partType = "loop_item",
21
- label = "Loop Item",
21
+ label = "Loop item",
22
22
  emptyLabel = "Use nested elements",
23
23
  marker = "loop-item",
24
24
  }: {
@@ -103,10 +103,6 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
103
103
  }
104
104
  }, [fetcher, setBusy]);
105
105
 
106
- React.useEffect(() => {
107
- if (open) void loadLibrary();
108
- }, [open, loadLibrary]);
109
-
110
106
  /** Focus Choose from library, or the URL field while the picker is busy (W-741). */
111
107
  const focusOpener = () => {
112
108
  const opener = libraryOpenerRef.current;
@@ -256,7 +252,11 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image", editable
256
252
  type="button"
257
253
  className={BUTTON}
258
254
  onClick={() => {
259
- if (!busyRef.current) setOpen(true);
255
+ if (busyRef.current) return;
256
+ // W-906: load in the same update that opens it; loading from an effect painted the
257
+ // last result ("No images yet.") first, and closing then raced the real load.
258
+ setOpen(true);
259
+ void loadLibrary();
260
260
  }}
261
261
  aria-disabled={busy}
262
262
  ref={libraryOpenerRef}
@@ -20,7 +20,8 @@ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
20
20
  right: BOX_AUTO,
21
21
  bottom: BOX_AUTO,
22
22
  left: BOX_AUTO,
23
- fontSize: ["px", "rem", "em", "%", "vw"],
23
+ // vh since W-910, for hero headings sized to the screen height.
24
+ fontSize: ["px", "rem", "em", "%", "vw", "vh"],
24
25
  // em first, so a typed 1.5 means 1.5 times the font size, not 1.5 px (W-125).
25
26
  lineHeight: ["em", "px", "rem", "%", "x"],
26
27
  letterSpacing: ["px", "rem", "em"],
@@ -19,6 +19,20 @@ export const SHORTCUTS: readonly { action: string; keys: string }[] = [
19
19
  { action: "Save draft", keys: "Ctrl/Cmd+S" },
20
20
  ];
21
21
 
22
+ /** One alternative in a shortcut ("Ctrl/Cmd+Shift+Z"), with the separator before it. */
23
+ export type KeyCombo = { before: string; keys: string[] };
24
+
25
+ /** W-864: "Ctrl/Cmd+Z / Ctrl/Cmd+Y" as combos of single keys, for key boxes. */
26
+ export function keyCombos(keys: string): KeyCombo[] {
27
+ const parts = keys.split(/( \/ | or )/);
28
+ const combos: KeyCombo[] = [];
29
+ for (let i = 0; i < parts.length; i += 2) {
30
+ const combo = parts[i] ?? "";
31
+ combos.push({ before: i === 0 ? "" : (parts[i - 1] ?? ""), keys: combo.split(/\+(?=.)/) });
32
+ }
33
+ return combos;
34
+ }
35
+
22
36
  /**
23
37
  * W-565: the letter of a Ctrl/Cmd shortcut on any keyboard layout. A Russian, Greek, Hebrew or
24
38
  * Arabic layout reports its own letter (Ctrl+Z is "я"), so the key's position stands in when the
@@ -0,0 +1,197 @@
1
+ import * as React from "react";
2
+ import type { createKumoToastManager } from "@cloudflare/kumo";
3
+ import {
4
+ classMergeNotice,
5
+ droppedNotice,
6
+ insertSavedSection,
7
+ LAYOUT_SCHEMA_VERSION,
8
+ newNodeId,
9
+ pageSlug,
10
+ snapshotSection,
11
+ syncedPartLayout,
12
+ wrapInThemeSection,
13
+ type DesignSystem,
14
+ type Layout,
15
+ } from "../../core/index.ts";
16
+ import type { Fetcher } from "../api.ts";
17
+ import {
18
+ deleteSavedSection,
19
+ getSavedSection,
20
+ listSavedSections,
21
+ renameSavedSection,
22
+ saveSavedSection,
23
+ type SavedSectionSummary,
24
+ } from "../saved-sections-api.ts";
25
+ import { createThemePart } from "../theme-api.ts";
26
+ import type { EditorAction, EditorState } from "./store.ts";
27
+
28
+ export type SaveMode = "copy" | "synced";
29
+
30
+ /** What the Add panel, the palette and the Save as section dialog use (W-876). */
31
+ export type SavedSectionActions = {
32
+ list: SavedSectionSummary[];
33
+ /** Null until the first list arrives; a message when it couldn't be read. */
34
+ loadError: string | null;
35
+ loaded: boolean;
36
+ refresh: () => void;
37
+ /** Resolves to null when saved, or the reason it wasn't. */
38
+ save: (nodeId: string, name: string, mode: SaveMode) => Promise<string | null>;
39
+ insert: (id: string) => Promise<void>;
40
+ rename: (id: string, name: string) => Promise<string | null>;
41
+ remove: (id: string) => Promise<string | null>;
42
+ };
43
+
44
+ const NOTICE_MS = 5000;
45
+ const messageOf = (error: unknown, fallback: string) =>
46
+ error instanceof Error && error.message ? error.message : fallback;
47
+
48
+ /**
49
+ * Saved sections in the editor (W-876, D-060). Copies go to `emvb_saved_sections`; Synced makes a
50
+ * Section theme part (W-098) from the element and puts the element inside a Theme section that
51
+ * embeds it. Inserting brings the section's classes into Site styles first, never overwriting one.
52
+ */
53
+ export function useSavedSections({
54
+ fetcher,
55
+ latest,
56
+ dispatch,
57
+ changeDesign,
58
+ announce,
59
+ toasts,
60
+ }: {
61
+ fetcher: Fetcher;
62
+ latest: React.RefObject<EditorState>;
63
+ dispatch: React.Dispatch<EditorAction>;
64
+ changeDesign: (next: DesignSystem) => Promise<unknown>;
65
+ announce: (message: string) => void;
66
+ toasts: ReturnType<typeof createKumoToastManager>;
67
+ }): SavedSectionActions {
68
+ const [list, setList] = React.useState<SavedSectionSummary[]>([]);
69
+ const [loaded, setLoaded] = React.useState(false);
70
+ const [loadError, setLoadError] = React.useState<string | null>(null);
71
+ const tell = React.useCallback(
72
+ (title: string, description?: string) => {
73
+ announce(description ? `${title}. ${description}` : title);
74
+ toasts.add({ title, ...(description ? { description } : {}), timeout: NOTICE_MS });
75
+ },
76
+ [announce, toasts],
77
+ );
78
+
79
+ const refresh = React.useCallback(() => {
80
+ listSavedSections(fetcher).then(
81
+ (items) => {
82
+ setList(items);
83
+ setLoadError(null);
84
+ setLoaded(true);
85
+ },
86
+ (error: unknown) => {
87
+ setLoadError(messageOf(error, "Couldn't load My sections."));
88
+ setLoaded(true);
89
+ },
90
+ );
91
+ }, [fetcher]);
92
+ React.useEffect(refresh, [refresh]);
93
+
94
+ const saveCopy = async (layout: Layout, nodeId: string, name: string) => {
95
+ const snap = snapshotSection(
96
+ layout,
97
+ nodeId,
98
+ latest.current.design,
99
+ name,
100
+ new Date().toISOString(),
101
+ );
102
+ if (!snap.ok) return snap.reason;
103
+ await saveSavedSection(fetcher, snap.record);
104
+ refresh();
105
+ tell(`Saved "${snap.record.name}" to My sections`);
106
+ return null;
107
+ };
108
+
109
+ const saveSynced = async (layout: Layout, nodeId: string, name: string) => {
110
+ const partLayout = syncedPartLayout(layout, nodeId);
111
+ const title = name.trim();
112
+ if (!title) return "Give the section a name.";
113
+ if (!partLayout) return "Choose an element inside the page.";
114
+ // Try the wrap first: a refused one (a tab panel, a menu item) used to leave a stray part (W-880).
115
+ const fits = wrapInThemeSection(layout, nodeId, "check");
116
+ if (!fits.ok) return fits.reason;
117
+ // The slug only tells theme parts apart; a short random tail keeps two "Hero"s apart.
118
+ const slug = `${pageSlug(`section-${title}`).slice(0, 60)}-${newNodeId().slice(0, 4)}`;
119
+ const partId = await createThemePart(fetcher, {
120
+ title,
121
+ slug,
122
+ partType: "section",
123
+ layout: partLayout,
124
+ });
125
+ const now = latest.current.page.layout;
126
+ const wrapped = now ? wrapInThemeSection(now, nodeId, partId) : null;
127
+ if (!wrapped?.ok) {
128
+ return `The theme section "${title}" was made, but this element couldn't be linked to it. ${wrapped?.reason ?? ""}`.trim();
129
+ }
130
+ dispatch({ type: "apply-arranged", layout: wrapped.layout, selected: wrapped.selected });
131
+ tell(
132
+ `Made the synced section "${title}"`,
133
+ "Edit it in Theme Builder; publish it there to use it on the site.",
134
+ );
135
+ return null;
136
+ };
137
+
138
+ const save: SavedSectionActions["save"] = async (nodeId, name, mode) => {
139
+ const layout = latest.current.page.layout;
140
+ if (!layout) return "This page has no elements yet.";
141
+ try {
142
+ return await (mode === "synced" ? saveSynced : saveCopy)(layout, nodeId, name);
143
+ } catch (error) {
144
+ return messageOf(error, "Couldn't save the section.");
145
+ }
146
+ };
147
+
148
+ const insert: SavedSectionActions["insert"] = async (id) => {
149
+ try {
150
+ const section = await getSavedSection(fetcher, id);
151
+ const state = latest.current;
152
+ const layout = state.page.layout ?? {
153
+ schemaVersion: LAYOUT_SCHEMA_VERSION,
154
+ root: { id: newNodeId(), type: "container" as const, props: {}, children: [] },
155
+ };
156
+ const result = insertSavedSection(section, layout, state.design, state.selectedId);
157
+ if (!result.ok) {
158
+ tell(result.reason);
159
+ return;
160
+ }
161
+ const classes = classMergeNotice(result.merge);
162
+ // Classes first: an inserted copy never points at a class Site styles failed to save.
163
+ if (classes) await changeDesign(result.design);
164
+ dispatch({ type: "apply-arranged", layout: result.layout, selected: result.selected });
165
+ const left = droppedNotice(result.dropped);
166
+ const extra = [classes, left].filter(Boolean).join(" ");
167
+ if (extra) tell(`Inserted "${section.name}"`, extra);
168
+ else announce(`Inserted "${section.name}"`);
169
+ } catch (error) {
170
+ tell(messageOf(error, "Couldn't insert the section."));
171
+ }
172
+ };
173
+
174
+ const rename: SavedSectionActions["rename"] = async (id, name) => {
175
+ try {
176
+ const item = await renameSavedSection(fetcher, id, name);
177
+ setList((items) => items.map((entry) => (entry.id === id ? item : entry)));
178
+ announce(`Renamed to "${item.name}"`);
179
+ return null;
180
+ } catch (error) {
181
+ return messageOf(error, "Couldn't rename the section.");
182
+ }
183
+ };
184
+
185
+ const remove: SavedSectionActions["remove"] = async (id) => {
186
+ try {
187
+ await deleteSavedSection(fetcher, id);
188
+ setList((items) => items.filter((entry) => entry.id !== id));
189
+ announce("Section deleted. Pages that use a copy keep it.");
190
+ return null;
191
+ } catch (error) {
192
+ return messageOf(error, "Couldn't delete the section.");
193
+ }
194
+ };
195
+
196
+ return { list, loaded, loadError, refresh, save, insert, rename, remove };
197
+ }
@@ -7,8 +7,13 @@
7
7
  * apps/www/src/registry/image-editor), MIT License, Copyright (c) 2026 rbbydotdev. Dropping and
8
8
  * opening files are left out: the editor opens the Image element's picture.
9
9
  */
10
- import { Button } from "@cloudflare/kumo";
11
- import { CircleNotchIcon, CornersOutIcon } from "@phosphor-icons/react";
10
+ import {
11
+ CircleNotchIcon,
12
+ CornersOutIcon,
13
+ MagnifyingGlassMinusIcon,
14
+ MagnifyingGlassPlusIcon,
15
+ } from "@phosphor-icons/react";
16
+ import { IconButton } from "./parts.tsx";
12
17
  import * as React from "react";
13
18
  import { BlurFocus } from "./BlurFocus.tsx";
14
19
  import { CornerHandlesOverlay, CropFrameOverlay } from "./CropOverlay.tsx";
@@ -23,6 +28,17 @@ import { useImageEditor } from "./engine.ts";
23
28
 
24
29
  type UserView = { scale: number; x: number; y: number };
25
30
  const IDENTITY_VIEW: UserView = { scale: 1, x: 0, y: 0 };
31
+ const MAX_ZOOM = 8;
32
+ /** W-861 (IE-6): one Zoom in or Zoom out press. */
33
+ const ZOOM_STEP = 1.5;
34
+
35
+ /** Zoom by `factor` keeping the stage point (cx, cy) still; back to 1 is the plain fit. */
36
+ function zoomAt(prev: UserView, factor: number, cx: number, cy: number): UserView {
37
+ const scale = Math.min(MAX_ZOOM, Math.max(1, prev.scale * factor));
38
+ if (scale === 1) return IDENTITY_VIEW;
39
+ const f = scale / prev.scale;
40
+ return { scale, x: cx - (cx - prev.x) * f, y: cy - (cy - prev.y) * f };
41
+ }
26
42
  const SETTLE_MS = 240;
27
43
  const easeOutCubic = (t: number) => 1 - (1 - t) ** 3;
28
44
 
@@ -135,10 +151,7 @@ export function EditorCanvas({ alt, padding = 24 }: { alt: string; padding?: num
135
151
  const cy = event.clientY - rect.top;
136
152
  setUserView((prev) => {
137
153
  if (!zooming) return { ...prev, x: prev.x - event.deltaX, y: prev.y - event.deltaY };
138
- const scale = Math.min(8, Math.max(1, prev.scale * Math.exp(-event.deltaY * 0.01)));
139
- const f = scale / prev.scale;
140
- if (scale === 1) return IDENTITY_VIEW;
141
- return { scale, x: cx - (cx - prev.x) * f, y: cy - (cy - prev.y) * f };
154
+ return zoomAt(prev, Math.exp(-event.deltaY * 0.01), cx, cy);
142
155
  });
143
156
  };
144
157
  React.useEffect(() => {
@@ -242,18 +255,49 @@ export function EditorCanvas({ alt, padding = 24 }: { alt: string; padding?: num
242
255
  />
243
256
  </div>
244
257
  ) : null}
245
- {!isCropView && userView !== IDENTITY_VIEW ? (
246
- <Button
247
- aria-label="Fit to screen"
248
- className="emvb-ie-fit"
249
- shape="square"
250
- size="sm"
251
- variant="secondary"
252
- icon={<CornersOutIcon aria-hidden="true" />}
253
- onClick={() => setUserView(IDENTITY_VIEW)}
258
+ {!isCropView ? (
259
+ // W-861 (IE-6): Zoom out, Zoom in and Fit, as photocn's toolbar actions; Ctrl/⌘-scroll
260
+ // and pinch still zoom too.
261
+ <div
262
+ className="emvb-ie-zoom"
263
+ role="group"
264
+ aria-label="Zoom"
265
+ data-emvb-image-zoom={Math.round(userView.scale * 100)}
254
266
  onPointerDown={(event) => event.stopPropagation()}
255
- type="button"
256
- />
267
+ >
268
+ <IconButton
269
+ label="Zoom out"
270
+ variant="outline"
271
+ icon={<MagnifyingGlassMinusIcon aria-hidden="true" />}
272
+ disabled={editor.disabled || userView.scale <= 1}
273
+ onClick={() =>
274
+ setUserView((prev) =>
275
+ zoomAt(prev, 1 / ZOOM_STEP, (stage?.width ?? 0) / 2, (stage?.height ?? 0) / 2),
276
+ )
277
+ }
278
+ data-emvb-image-zoom-out=""
279
+ />
280
+ <IconButton
281
+ label="Zoom in"
282
+ variant="outline"
283
+ icon={<MagnifyingGlassPlusIcon aria-hidden="true" />}
284
+ disabled={editor.disabled || !editor.isReady || userView.scale >= MAX_ZOOM}
285
+ onClick={() =>
286
+ setUserView((prev) =>
287
+ zoomAt(prev, ZOOM_STEP, (stage?.width ?? 0) / 2, (stage?.height ?? 0) / 2),
288
+ )
289
+ }
290
+ data-emvb-image-zoom-in=""
291
+ />
292
+ {userView !== IDENTITY_VIEW ? (
293
+ <IconButton
294
+ label="Fit to screen"
295
+ variant="outline"
296
+ icon={<CornersOutIcon aria-hidden="true" />}
297
+ onClick={() => setUserView(IDENTITY_VIEW)}
298
+ />
299
+ ) : null}
300
+ </div>
257
301
  ) : null}
258
302
  </div>
259
303
  </div>
@@ -14,6 +14,8 @@ import {
14
14
  ArrowCounterClockwiseIcon,
15
15
  DotsThreeIcon,
16
16
  DownloadSimpleIcon,
17
+ FileArrowUpIcon,
18
+ ScrollIcon,
17
19
  WarningCircleIcon,
18
20
  XIcon,
19
21
  } from "@phosphor-icons/react";
@@ -45,7 +47,16 @@ import {
45
47
  ToolSwitcher,
46
48
  UndoButton,
47
49
  } from "./parts.tsx";
48
- import { buildImageEdit, editedFileName, hasGps, outputFile, savedRecipe } from "./save.ts";
50
+ import {
51
+ buildImageEdit,
52
+ editedFileName,
53
+ hasGps,
54
+ outputFile,
55
+ parseRecipeFile,
56
+ RECIPE_FILE_MAX_BYTES,
57
+ recipeFileText,
58
+ savedRecipe,
59
+ } from "./save.ts";
49
60
  import { displayName, elementAspectOption, sizeLabel, type ImageEditorToolId } from "./tools.ts";
50
61
  import type { RenderMode } from "./worker.ts";
51
62
  import type { ImageEdit } from "../../core/index.ts";
@@ -115,6 +126,119 @@ function useWidth(ref: React.RefObject<HTMLElement | null>) {
115
126
  return width;
116
127
  }
117
128
 
129
+ /** W-862 (IE-2): download the current edits as a recipe file, or load one onto this picture. */
130
+ function useRecipeFile(name: string) {
131
+ const editor = useImageEditor();
132
+ const fileRef = React.useRef<HTMLInputElement>(null);
133
+ const [error, setError] = React.useState<string | null>(null);
134
+ const current = editor.recipes.current;
135
+ const download = () => {
136
+ if (!current) return;
137
+ const url = URL.createObjectURL(
138
+ new Blob([recipeFileText(current as Parameters<typeof recipeFileText>[0])], {
139
+ type: "application/json",
140
+ }),
141
+ );
142
+ const a = document.createElement("a");
143
+ a.href = url;
144
+ a.download = `${name.replace(/\.[^.]+$/, "") || "image"}.recipe.json`;
145
+ a.click();
146
+ setTimeout(() => URL.revokeObjectURL(url), 0);
147
+ };
148
+ const load = async (file: File | undefined) => {
149
+ if (!file) return;
150
+ // W-881: a huge file picked by mistake isn't read into memory, and a failed apply says so.
151
+ if (file.size > RECIPE_FILE_MAX_BYTES) {
152
+ setError("This file is too large to be an image edit recipe.");
153
+ return;
154
+ }
155
+ try {
156
+ const result = parseRecipeFile(await file.text());
157
+ if (!result.ok) {
158
+ setError(result.error);
159
+ return;
160
+ }
161
+ setError(null);
162
+ await editor.recipes.apply(result.recipe as Parameters<typeof editor.recipes.apply>[0]);
163
+ } catch {
164
+ setError("This recipe couldn't be applied to this picture.");
165
+ }
166
+ };
167
+ const pick = () => fileRef.current?.click();
168
+ // W-884: the phone layout's More menu offers the same two items, so both layouts render these.
169
+ const errorNote = error ? (
170
+ <span className="emvb-ie-recipe-error" role="alert" data-emvb-image-recipe-error="">
171
+ <WarningCircleIcon aria-hidden="true" />
172
+ {error}
173
+ </span>
174
+ ) : null;
175
+ const fileInput = (
176
+ <input
177
+ ref={fileRef}
178
+ type="file"
179
+ accept="application/json,.json"
180
+ hidden
181
+ aria-label="Load recipe file"
182
+ data-emvb-image-recipe-file=""
183
+ onChange={(event) => {
184
+ const input = event.currentTarget;
185
+ void load(input.files?.[0]).finally(() => {
186
+ input.value = "";
187
+ });
188
+ }}
189
+ />
190
+ );
191
+ return { current, download, pick, errorNote, fileInput };
192
+ }
193
+
194
+ function RecipeMenu({ name }: { name: string }) {
195
+ const editor = useImageEditor();
196
+ const recipe = useRecipeFile(name);
197
+ return (
198
+ <>
199
+ {recipe.errorNote}
200
+ <DropdownMenu>
201
+ <DropdownMenu.Trigger
202
+ render={
203
+ <Button
204
+ type="button"
205
+ variant="outline"
206
+ size="sm"
207
+ className="emvb-ie-btn"
208
+ icon={<ScrollIcon aria-hidden="true" />}
209
+ disabled={editor.disabled || !editor.hasImage}
210
+ data-emvb-image-recipe=""
211
+ >
212
+ Recipe
213
+ </Button>
214
+ }
215
+ />
216
+ <DropdownMenu.Content align="end">
217
+ <RecipeItems recipe={recipe} />
218
+ </DropdownMenu.Content>
219
+ </DropdownMenu>
220
+ {recipe.fileInput}
221
+ </>
222
+ );
223
+ }
224
+
225
+ function RecipeItems({ recipe }: { recipe: ReturnType<typeof useRecipeFile> }) {
226
+ return (
227
+ <>
228
+ <DropdownMenu.Item
229
+ icon={DownloadSimpleIcon}
230
+ disabled={!recipe.current}
231
+ onClick={recipe.download}
232
+ >
233
+ Download recipe
234
+ </DropdownMenu.Item>
235
+ <DropdownMenu.Item icon={FileArrowUpIcon} onClick={recipe.pick}>
236
+ Load recipe…
237
+ </DropdownMenu.Item>
238
+ </>
239
+ );
240
+ }
241
+
118
242
  function SaveCopyButton() {
119
243
  const save = React.useContext(SaveContext);
120
244
  const editor = useImageEditor();
@@ -237,6 +361,7 @@ function DesktopLayout({ ready, name }: { ready: Ready; name: string }) {
237
361
  </span>
238
362
  ) : null}
239
363
  <div className="emvb-ie-toolbar-end">
364
+ <RecipeMenu name={name} />
240
365
  <ResetAllButton />
241
366
  <CompareButton />
242
367
  <CancelButton />
@@ -402,6 +527,7 @@ function PanelSheet({
402
527
 
403
528
  function CompactLayout({ name }: { name: string }) {
404
529
  const editor = useImageEditor();
530
+ const recipe = useRecipeFile(name);
405
531
  const rootRef = React.useRef<HTMLDivElement | null>(null);
406
532
  const [rootHeight, setRootHeight] = React.useState<number | null>(null);
407
533
  React.useLayoutEffect(() => {
@@ -468,11 +594,14 @@ function CompactLayout({ name }: { name: string }) {
468
594
  >
469
595
  Reset all edits
470
596
  </DropdownMenu.Item>
597
+ <RecipeItems recipe={recipe} />
471
598
  </DropdownMenu.Content>
472
599
  </DropdownMenu>
600
+ {recipe.fileInput}
473
601
  <CancelButton compact />
474
602
  </div>
475
603
  </header>
604
+ {recipe.errorNote ? <div className="emvb-ie-compact-note">{recipe.errorNote}</div> : null}
476
605
  <div className="emvb-ie-compact-canvas" style={{ paddingBottom: inset }}>
477
606
  <EditorCanvas alt={name} padding={12} />
478
607
  </div>
@@ -71,7 +71,6 @@ export const IMAGE_EDITOR_CSS = `
71
71
  flex: 1 1 0; min-width: 0; max-width: 40px; height: 32px; display: grid; place-items: center;
72
72
  border: 1px solid var(--color-kumo-line); border-radius: 8px; background: var(--color-kumo-base);
73
73
  color: var(--text-color-kumo-default); cursor: pointer; padding: 0;
74
- transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
75
74
  }
76
75
  .emvb-ie-switch svg { width: 16px; height: 16px; transition: transform 120ms ease; }
77
76
  .emvb-ie-switch:hover { background: var(--color-kumo-tint); }
@@ -89,9 +88,9 @@ export const IMAGE_EDITOR_CSS = `
89
88
  }
90
89
  .emvb-ie-histogram-head {
91
90
  display: flex; justify-content: space-between; font-size: 10px; line-height: 14px;
92
- text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-color-kumo-subtle);
91
+ color: var(--text-color-kumo-subtle);
93
92
  }
94
- .emvb-ie-mono { font-family: var(--font-mono, ui-monospace, monospace); text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }
93
+ .emvb-ie-mono { font-family: var(--font-mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; }
95
94
  .emvb-ie-histogram canvas { display: block; width: 100%; height: 64px; border-radius: 4px; background: var(--color-kumo-base); }
96
95
 
97
96
  /* Panels (photocn panel-header.tsx, crop-panel.tsx). */
@@ -189,7 +188,9 @@ export const IMAGE_EDITOR_CSS = `
189
188
  border-top-color: var(--text-color-kumo-default); animation: emvb-ie-spin 0.9s linear infinite;
190
189
  }
191
190
  @keyframes emvb-ie-spin { to { transform: rotate(360deg); } }
192
- .emvb-ie .emvb-ie-fit { position: absolute; right: 8px; bottom: 8px; }
191
+ .emvb-ie .emvb-ie-compact-note { padding: 4px 12px; }
192
+ .emvb-ie .emvb-ie-recipe-error { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--color-kumo-danger); }
193
+ .emvb-ie .emvb-ie-zoom { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--color-kumo-base); box-shadow: 0 1px 3px var(--color-kumo-shadow-drop, rgb(0 0 0 / 0.15)); }
193
194
  .emvb-ie-error {
194
195
  display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 420px; margin: 24px;
195
196
  padding: 20px 24px; border-radius: 12px; text-align: center;
@@ -258,10 +259,10 @@ export const IMAGE_EDITOR_CSS = `
258
259
  display: flex; flex: none; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
259
260
  min-width: 56px; min-height: 44px; padding: 0 8px; border: 0; border-radius: 10px; background: none;
260
261
  color: var(--text-color-kumo-subtle); font-size: 11px; line-height: 14px; cursor: pointer;
261
- transition: background-color 120ms ease, color 120ms ease;
262
262
  }
263
263
  .emvb-ie-compact-tool svg { width: 20px; height: 20px; }
264
- .emvb-ie-compact-tool[aria-pressed="true"] { background: var(--color-kumo-brand); color: #fff; }
264
+ .emvb-ie-compact-tool[aria-pressed="true"] { background: var(--color-kumo-brand); color: #fff; box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.2); }
265
+ .emvb-ie-compact-tool[aria-pressed="true"] svg { transform: scale(1.1); }
265
266
  .emvb-ie-compact-tool:focus-visible { outline: 2px solid var(--color-kumo-focus, var(--color-kumo-brand)); }
266
267
  .emvb-ie-compact-tool:disabled { opacity: 0.5; }
267
268
  .emvb-ie-sheet {
@@ -280,7 +281,9 @@ export const IMAGE_EDITOR_CSS = `
280
281
  .emvb-ie-sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
281
282
  /* Tone panels (W-484; photocn adjustments-panel, filters-panel, curves-panel, blur-panel). */
282
283
  .emvb-ie-tabs-wrap { padding: 12px 16px; }
283
- .emvb-ie-tabs [role="tablist"] { width: 100%; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
284
+ /* W-872: Kumo's small tab list has a fixed 26px height, but an icon-and-text tab is taller, so the
285
+ underline (bottom: 0 of the list) cut through the label. The list now grows to its tabs. */
286
+ .emvb-ie-tabs [role="tablist"] { width: 100%; height: auto; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
284
287
  .emvb-ie-tabs [role="tab"] { justify-content: center; font-size: 13px; }
285
288
  .emvb-ie-tab-label { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
286
289
  .emvb-ie-tab-label svg { width: 16px; height: 16px; }
@@ -303,7 +306,7 @@ export const IMAGE_EDITOR_CSS = `
303
306
  .emvb-ie .emvb-ie-chip[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--color-kumo-line); }
304
307
  .emvb-ie-spin { animation: emvb-ie-spin 0.9s linear infinite; }
305
308
  .emvb-ie-subgroup { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; border: 0; min-width: 0; }
306
- .emvb-ie-caps { padding: 0; margin-bottom: 0; font-size: 12px; line-height: 16px; font-weight: 600; text-transform: uppercase; color: var(--text-color-kumo-subtle); }
309
+ .emvb-ie-caps { padding: 0; margin-bottom: 0; font-size: 12px; line-height: 16px; font-weight: 600; color: var(--text-color-kumo-subtle); }
307
310
  .emvb-ie-group-curves { gap: 12px; }
308
311
  .emvb-ie-curves { display: flex; flex-direction: column; align-items: center; gap: 8px; }
309
312
  .emvb-ie-curves-box {
@@ -236,24 +236,25 @@ export function ToolSwitcher() {
236
236
  {IMAGE_EDITOR_TOOLS.map((tool, i) => {
237
237
  const ToolIcon = TOOL_ICONS[tool.id];
238
238
  const active = tool.id === editor.tool;
239
+ // W-860 (IE-3): a Kumo tooltip names each tool, as photocn's ToggleGroup does.
239
240
  return (
240
- <button
241
- key={tool.id}
242
- ref={(el) => {
243
- buttons.current[i] = el;
244
- }}
245
- type="button"
246
- className="emvb-ie-switch"
247
- aria-label={tool.label}
248
- aria-pressed={active}
249
- title={tool.label}
250
- tabIndex={active || (index < 0 && i === 0) ? 0 : -1}
251
- disabled={disabled}
252
- data-emvb-image-tool={tool.id}
253
- onClick={() => editor.setTool(tool.id)}
254
- >
255
- <ToolIcon aria-hidden="true" weight={active ? "bold" : "regular"} />
256
- </button>
241
+ <Tooltip key={tool.id} content={tool.label} side="bottom" asChild>
242
+ <button
243
+ ref={(el) => {
244
+ buttons.current[i] = el;
245
+ }}
246
+ type="button"
247
+ className="emvb-ie-switch"
248
+ aria-label={tool.label}
249
+ aria-pressed={active}
250
+ tabIndex={active || (index < 0 && i === 0) ? 0 : -1}
251
+ disabled={disabled}
252
+ data-emvb-image-tool={tool.id}
253
+ onClick={() => editor.setTool(tool.id)}
254
+ >
255
+ <ToolIcon aria-hidden="true" weight={active ? "bold" : "regular"} />
256
+ </button>
257
+ </Tooltip>
257
258
  );
258
259
  })}
259
260
  </div>