@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.
- package/README.md +4 -0
- package/THIRD_PARTY_NOTICES.md +23 -1
- package/licenses/exif-js.LICENSE +21 -0
- package/licenses/fflate.LICENSE +21 -0
- package/licenses/glfx.js.LICENSE +19 -0
- package/licenses/mini-photo-editor.LICENSE +21 -0
- package/licenses/photocn.LICENSE +21 -0
- package/package.json +2 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +88 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +16 -1
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +108 -7
- package/src/admin/editor/editor-commands.ts +15 -1
- package/src/admin/editor/editor-css.ts +75 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +135 -27
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +68 -22
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +53 -21
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +38 -15
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +274 -20
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +141 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +25 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +14 -3
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/BlurFocus.tsx +112 -0
- package/src/admin/image-editor/Canvas.tsx +261 -0
- package/src/admin/image-editor/CropOverlay.tsx +390 -0
- package/src/admin/image-editor/CurvesPanel.tsx +395 -0
- package/src/admin/image-editor/ExportDialog.tsx +384 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
- package/src/admin/image-editor/MetadataPanel.tsx +194 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +162 -0
- package/src/admin/image-editor/curve-math.ts +177 -0
- package/src/admin/image-editor/data-url-fetch.ts +59 -0
- package/src/admin/image-editor/engine.ts +55 -0
- package/src/admin/image-editor/exif.ts +82 -0
- package/src/admin/image-editor/flatten.ts +54 -0
- package/src/admin/image-editor/gpu-fit.ts +81 -0
- package/src/admin/image-editor/image-editor-css.ts +400 -0
- package/src/admin/image-editor/load.ts +116 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +614 -0
- package/src/admin/image-editor/save.ts +141 -0
- package/src/admin/image-editor/tone-panels.tsx +338 -0
- package/src/admin/image-editor/tools.ts +59 -0
- package/src/admin/image-editor/worker.ts +111 -0
- package/src/admin/media-api.ts +114 -3
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +78 -22
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +6 -0
- package/src/astro/resolve-theme.ts +67 -14
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +6 -3
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +29 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +19 -6
- package/src/core/design/classes.ts +20 -9
- package/src/core/design/diff.ts +9 -1
- package/src/core/design/merge.ts +93 -3
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +46 -8
- package/src/core/design/variables.ts +32 -10
- package/src/core/elements/dynamic-elements.ts +53 -6
- package/src/core/elements/form-elements.ts +68 -30
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +190 -2
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +49 -4
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +155 -0
- package/src/core/image-edit/summary.ts +61 -0
- package/src/core/index.ts +29 -1
- package/src/core/limits.ts +21 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +51 -8
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +71 -13
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +164 -12
- package/src/core/render/index.ts +179 -22
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +26 -7
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +57 -23
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +57 -10
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +11 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +82 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +271 -25
- package/src/server/agent-settings.ts +29 -4
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +33 -9
- package/src/server/mcp-routes.ts +74 -11
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared pieces of the image editor (W-483): icon buttons with tooltips, the panel header,
|
|
3
|
+
* centered sliders, the histogram strip and the tool pickers.
|
|
4
|
+
*
|
|
5
|
+
* Layout and behaviour follow photocn's editor components (https://github.com/rbbydotdev/photocn,
|
|
6
|
+
* apps/www/src/registry/image-editor: toolbar.tsx, panel-header.tsx, histogram.tsx, crop-panel.tsx,
|
|
7
|
+
* compact-layout.tsx, icon-skew.tsx), MIT License, Copyright (c) 2026 rbbydotdev. Rebuilt with
|
|
8
|
+
* Kumo components and EmVB tokens instead of shadcn/ui.
|
|
9
|
+
*/
|
|
10
|
+
import { Button, Tabs, Tooltip } from "@cloudflare/kumo";
|
|
11
|
+
import {
|
|
12
|
+
ArrowCounterClockwiseIcon,
|
|
13
|
+
ArrowUUpLeftIcon,
|
|
14
|
+
ArrowUUpRightIcon,
|
|
15
|
+
CropIcon,
|
|
16
|
+
DropIcon,
|
|
17
|
+
EyeIcon,
|
|
18
|
+
InfoIcon,
|
|
19
|
+
MagicWandIcon,
|
|
20
|
+
PulseIcon,
|
|
21
|
+
SlidersHorizontalIcon,
|
|
22
|
+
SparkleIcon,
|
|
23
|
+
StackIcon,
|
|
24
|
+
type Icon,
|
|
25
|
+
} from "@phosphor-icons/react";
|
|
26
|
+
import * as React from "react";
|
|
27
|
+
import { useImageEditor } from "./engine.ts";
|
|
28
|
+
import { IMAGE_EDITOR_TOOLS, type ImageEditorToolId } from "./tools.ts";
|
|
29
|
+
import { isCommitEnter } from "../editor/ime.ts";
|
|
30
|
+
|
|
31
|
+
export const TOOL_ICONS: Record<ImageEditorToolId, Icon> = {
|
|
32
|
+
adjust: SlidersHorizontalIcon,
|
|
33
|
+
compose: CropIcon,
|
|
34
|
+
curves: PulseIcon,
|
|
35
|
+
effects: SparkleIcon,
|
|
36
|
+
filters: MagicWandIcon,
|
|
37
|
+
blender: StackIcon,
|
|
38
|
+
blur: DropIcon,
|
|
39
|
+
metadata: InfoIcon,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type IconButtonProps = {
|
|
43
|
+
label: string;
|
|
44
|
+
icon: React.ReactNode;
|
|
45
|
+
onClick?: () => void;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
/** Show the label next to the icon (photocn's `showLabel`). */
|
|
48
|
+
showLabel?: boolean;
|
|
49
|
+
variant?: "ghost" | "outline";
|
|
50
|
+
className?: string;
|
|
51
|
+
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onClick" | "disabled" | "className">;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* W-839: Undo, Redo and Reset disable themselves when they run out (and an icon button loses its
|
|
55
|
+
* tooltip wrapper, so it remounts). Focus then fell to the dialog or the page body. Once the
|
|
56
|
+
* pressed button can no longer hold focus, move it to the nearest enabled button in the toolbar.
|
|
57
|
+
*/
|
|
58
|
+
/** Distance from the pressed button; on a tie the earlier button wins (Redo hands back to Undo). */
|
|
59
|
+
const near = (at: number, index: number) => Math.abs(index - at) + (index > at ? 0.5 : 0);
|
|
60
|
+
|
|
61
|
+
function keepToolbarFocus(from: HTMLButtonElement) {
|
|
62
|
+
const bar = from.closest<HTMLElement>('[data-slot="editor-toolbar"], .emvb-ie-compact-head');
|
|
63
|
+
const dialog = from.closest<HTMLElement>('[role="dialog"]');
|
|
64
|
+
if (!bar) return;
|
|
65
|
+
const at = [...bar.querySelectorAll<HTMLButtonElement>("button")].indexOf(from);
|
|
66
|
+
const started = Date.now();
|
|
67
|
+
const settle = () => {
|
|
68
|
+
const active = document.activeElement;
|
|
69
|
+
const lost =
|
|
70
|
+
active === document.body ||
|
|
71
|
+
active === dialog ||
|
|
72
|
+
active === null ||
|
|
73
|
+
(active instanceof HTMLButtonElement && active.disabled);
|
|
74
|
+
if (!lost) {
|
|
75
|
+
if (active === from && Date.now() - started < 600) window.setTimeout(settle, 30);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Positions, not elements: a button that gained or lost its tooltip is a new element.
|
|
79
|
+
const all = [...bar.querySelectorAll<HTMLButtonElement>("button")];
|
|
80
|
+
const open = all
|
|
81
|
+
.map((button, index) => ({ button, index }))
|
|
82
|
+
.filter(({ button }) => !button.disabled && button.getAttribute("aria-disabled") !== "true");
|
|
83
|
+
open.toSorted((a, b) => near(at, a.index) - near(at, b.index))[0]?.button.focus();
|
|
84
|
+
};
|
|
85
|
+
window.setTimeout(settle, 0);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A ghost or outline button; icon-only ones get a tooltip below (photocn EditorActionButton). */
|
|
89
|
+
export function IconButton({
|
|
90
|
+
label,
|
|
91
|
+
icon,
|
|
92
|
+
showLabel = false,
|
|
93
|
+
variant = "ghost",
|
|
94
|
+
className,
|
|
95
|
+
...rest
|
|
96
|
+
}: IconButtonProps) {
|
|
97
|
+
const { onClick } = rest;
|
|
98
|
+
const props = {
|
|
99
|
+
...rest,
|
|
100
|
+
onClick: onClick
|
|
101
|
+
? (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
102
|
+
const from = event.currentTarget;
|
|
103
|
+
onClick();
|
|
104
|
+
keepToolbarFocus(from);
|
|
105
|
+
}
|
|
106
|
+
: undefined,
|
|
107
|
+
};
|
|
108
|
+
const classes = `emvb-ie-btn${showLabel ? "" : " emvb-ie-btn-icon"}${className ? ` ${className}` : ""}`;
|
|
109
|
+
const button = showLabel ? (
|
|
110
|
+
<Button type="button" variant={variant} size="sm" className={classes} icon={icon} {...props}>
|
|
111
|
+
{label}
|
|
112
|
+
</Button>
|
|
113
|
+
) : (
|
|
114
|
+
<Button
|
|
115
|
+
type="button"
|
|
116
|
+
variant={variant}
|
|
117
|
+
size="sm"
|
|
118
|
+
shape="square"
|
|
119
|
+
aria-label={label}
|
|
120
|
+
className={classes}
|
|
121
|
+
icon={icon}
|
|
122
|
+
{...props}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
if (showLabel || props.disabled) return button;
|
|
126
|
+
return (
|
|
127
|
+
<Tooltip content={label} side="bottom" asChild>
|
|
128
|
+
{button}
|
|
129
|
+
</Tooltip>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function UndoButton(props: { className?: string }) {
|
|
134
|
+
const editor = useImageEditor();
|
|
135
|
+
return (
|
|
136
|
+
<IconButton
|
|
137
|
+
label="Undo"
|
|
138
|
+
icon={<ArrowUUpLeftIcon aria-hidden="true" />}
|
|
139
|
+
disabled={editor.disabled || !editor.history.canUndo}
|
|
140
|
+
onClick={() => editor.history.undo()}
|
|
141
|
+
data-emvb-image-undo=""
|
|
142
|
+
{...props}
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function RedoButton(props: { className?: string }) {
|
|
148
|
+
const editor = useImageEditor();
|
|
149
|
+
return (
|
|
150
|
+
<IconButton
|
|
151
|
+
label="Redo"
|
|
152
|
+
icon={<ArrowUUpRightIcon aria-hidden="true" />}
|
|
153
|
+
disabled={editor.disabled || !editor.history.canRedo}
|
|
154
|
+
onClick={() => editor.history.redo()}
|
|
155
|
+
data-emvb-image-redo=""
|
|
156
|
+
{...props}
|
|
157
|
+
/>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function ResetAllButton() {
|
|
162
|
+
const editor = useImageEditor();
|
|
163
|
+
return (
|
|
164
|
+
<IconButton
|
|
165
|
+
label="Reset"
|
|
166
|
+
showLabel
|
|
167
|
+
variant="outline"
|
|
168
|
+
icon={<ArrowCounterClockwiseIcon aria-hidden="true" />}
|
|
169
|
+
disabled={editor.disabled || !editor.hasImage || editor.recipes.current === null}
|
|
170
|
+
onClick={() => editor.resetAll()}
|
|
171
|
+
data-emvb-image-reset=""
|
|
172
|
+
/>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Press and hold to see the original (geometry is kept). */
|
|
177
|
+
export function CompareButton({ showLabel = true }: { showLabel?: boolean }) {
|
|
178
|
+
const editor = useImageEditor();
|
|
179
|
+
const release = () => editor.compare.setActive(false);
|
|
180
|
+
return (
|
|
181
|
+
<IconButton
|
|
182
|
+
label="Original"
|
|
183
|
+
showLabel={showLabel}
|
|
184
|
+
variant={showLabel ? "outline" : "ghost"}
|
|
185
|
+
icon={<EyeIcon aria-hidden="true" />}
|
|
186
|
+
aria-pressed={editor.compare.active}
|
|
187
|
+
disabled={editor.disabled || !editor.hasImage}
|
|
188
|
+
data-emvb-image-compare=""
|
|
189
|
+
onBlur={release}
|
|
190
|
+
onKeyDown={(event) => {
|
|
191
|
+
if (event.key === " " || event.key === "Enter") editor.compare.setActive(true);
|
|
192
|
+
}}
|
|
193
|
+
onKeyUp={release}
|
|
194
|
+
onPointerCancel={release}
|
|
195
|
+
onPointerDown={() => editor.compare.setActive(true)}
|
|
196
|
+
onPointerLeave={release}
|
|
197
|
+
onPointerUp={release}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The sidebar's tool switcher: one icon per tool, the active one filled (photocn ToggleGroup). */
|
|
203
|
+
export function ToolSwitcher() {
|
|
204
|
+
const editor = useImageEditor();
|
|
205
|
+
const disabled = editor.disabled || editor.isLoading;
|
|
206
|
+
const buttons = React.useRef<(HTMLButtonElement | null)[]>([]);
|
|
207
|
+
const index = IMAGE_EDITOR_TOOLS.findIndex((t) => t.id === editor.tool);
|
|
208
|
+
const onKeyDown = (event: React.KeyboardEvent) => {
|
|
209
|
+
// W-680: Alt+Left is the browser's Back; Ctrl/Cmd keys are shortcuts.
|
|
210
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
211
|
+
const count = IMAGE_EDITOR_TOOLS.length;
|
|
212
|
+
const next =
|
|
213
|
+
event.key === "ArrowRight"
|
|
214
|
+
? (index + 1) % count
|
|
215
|
+
: event.key === "ArrowLeft"
|
|
216
|
+
? (index - 1 + count) % count
|
|
217
|
+
: event.key === "Home"
|
|
218
|
+
? 0
|
|
219
|
+
: event.key === "End"
|
|
220
|
+
? count - 1
|
|
221
|
+
: -1;
|
|
222
|
+
if (next < 0) return;
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
const target = IMAGE_EDITOR_TOOLS[next];
|
|
225
|
+
if (target) editor.setTool(target.id);
|
|
226
|
+
buttons.current[next]?.focus();
|
|
227
|
+
};
|
|
228
|
+
return (
|
|
229
|
+
<div
|
|
230
|
+
className="emvb-ie-switcher"
|
|
231
|
+
role="toolbar"
|
|
232
|
+
aria-label="Editor tools"
|
|
233
|
+
onKeyDown={onKeyDown}
|
|
234
|
+
data-slot="editor-toolbar"
|
|
235
|
+
>
|
|
236
|
+
{IMAGE_EDITOR_TOOLS.map((tool, i) => {
|
|
237
|
+
const ToolIcon = TOOL_ICONS[tool.id];
|
|
238
|
+
const active = tool.id === editor.tool;
|
|
239
|
+
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>
|
|
257
|
+
);
|
|
258
|
+
})}
|
|
259
|
+
</div>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Phone tool bar: labelled, horizontally scrolling, 44 px targets (photocn CompactToolBar). */
|
|
264
|
+
export function CompactToolBar({
|
|
265
|
+
onSelect,
|
|
266
|
+
disabled,
|
|
267
|
+
className,
|
|
268
|
+
}: {
|
|
269
|
+
onSelect: (tool: ImageEditorToolId) => void;
|
|
270
|
+
disabled?: boolean;
|
|
271
|
+
className?: string;
|
|
272
|
+
}) {
|
|
273
|
+
const editor = useImageEditor();
|
|
274
|
+
return (
|
|
275
|
+
<nav
|
|
276
|
+
className={`emvb-ie-compact-tools${className ? ` ${className}` : ""}`}
|
|
277
|
+
aria-label="Editor tools"
|
|
278
|
+
>
|
|
279
|
+
{IMAGE_EDITOR_TOOLS.map((tool) => {
|
|
280
|
+
const ToolIcon = TOOL_ICONS[tool.id];
|
|
281
|
+
const active = tool.id === editor.tool;
|
|
282
|
+
return (
|
|
283
|
+
<button
|
|
284
|
+
key={tool.id}
|
|
285
|
+
type="button"
|
|
286
|
+
className="emvb-ie-compact-tool"
|
|
287
|
+
aria-pressed={active}
|
|
288
|
+
disabled={disabled}
|
|
289
|
+
data-emvb-image-tool={tool.id}
|
|
290
|
+
onClick={() => onSelect(tool.id)}
|
|
291
|
+
>
|
|
292
|
+
<ToolIcon aria-hidden="true" />
|
|
293
|
+
{tool.label}
|
|
294
|
+
</button>
|
|
295
|
+
);
|
|
296
|
+
})}
|
|
297
|
+
</nav>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Title and description on the left, Reset on the right, a rule below (photocn PanelResetHeader). */
|
|
302
|
+
export function PanelHeader({
|
|
303
|
+
title,
|
|
304
|
+
description,
|
|
305
|
+
onReset,
|
|
306
|
+
resetDisabled = false,
|
|
307
|
+
}: {
|
|
308
|
+
title: string;
|
|
309
|
+
description?: string;
|
|
310
|
+
onReset?: () => void;
|
|
311
|
+
resetDisabled?: boolean;
|
|
312
|
+
}) {
|
|
313
|
+
return (
|
|
314
|
+
<div className="emvb-ie-panel-head">
|
|
315
|
+
<div className="emvb-ie-panel-titles">
|
|
316
|
+
<h2>{title}</h2>
|
|
317
|
+
{description ? <p>{description}</p> : null}
|
|
318
|
+
</div>
|
|
319
|
+
<IconButton
|
|
320
|
+
label="Reset"
|
|
321
|
+
showLabel
|
|
322
|
+
variant="outline"
|
|
323
|
+
icon={<ArrowCounterClockwiseIcon aria-hidden="true" />}
|
|
324
|
+
disabled={resetDisabled || !onReset}
|
|
325
|
+
onClick={onReset}
|
|
326
|
+
data-emvb-image-panel-reset=""
|
|
327
|
+
/>
|
|
328
|
+
</div>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* A slider whose zero is the middle, with its value as a click-to-reset button (photocn
|
|
334
|
+
* CenteredSlider).
|
|
335
|
+
* A native range input styled with EmVB tokens: Kumo has no slider. `onCommit` fires on release.
|
|
336
|
+
*/
|
|
337
|
+
export function CenteredSlider({
|
|
338
|
+
label,
|
|
339
|
+
value,
|
|
340
|
+
min,
|
|
341
|
+
max,
|
|
342
|
+
step,
|
|
343
|
+
disabled,
|
|
344
|
+
format,
|
|
345
|
+
onChange,
|
|
346
|
+
onCommit,
|
|
347
|
+
name,
|
|
348
|
+
}: {
|
|
349
|
+
label: string;
|
|
350
|
+
value: number;
|
|
351
|
+
min: number;
|
|
352
|
+
max: number;
|
|
353
|
+
step: number;
|
|
354
|
+
disabled?: boolean;
|
|
355
|
+
format: (value: number) => string;
|
|
356
|
+
onChange: (value: number) => void;
|
|
357
|
+
onCommit?: () => void;
|
|
358
|
+
name: string;
|
|
359
|
+
}) {
|
|
360
|
+
const id = React.useId();
|
|
361
|
+
const fill = ((value - min) / (max - min)) * 100;
|
|
362
|
+
return (
|
|
363
|
+
<div className="emvb-ie-slider" data-disabled={disabled || undefined}>
|
|
364
|
+
<div className="emvb-ie-slider-head">
|
|
365
|
+
<label htmlFor={id}>{label}</label>
|
|
366
|
+
<button
|
|
367
|
+
type="button"
|
|
368
|
+
className="emvb-ie-slider-value"
|
|
369
|
+
disabled={disabled || value === 0}
|
|
370
|
+
title="Reset"
|
|
371
|
+
onClick={() => {
|
|
372
|
+
onChange(0);
|
|
373
|
+
onCommit?.();
|
|
374
|
+
}}
|
|
375
|
+
>
|
|
376
|
+
{format(value)}
|
|
377
|
+
</button>
|
|
378
|
+
</div>
|
|
379
|
+
<input
|
|
380
|
+
id={id}
|
|
381
|
+
type="range"
|
|
382
|
+
min={min}
|
|
383
|
+
max={max}
|
|
384
|
+
step={step}
|
|
385
|
+
value={value}
|
|
386
|
+
disabled={disabled}
|
|
387
|
+
data-emvb-image-slider={name}
|
|
388
|
+
style={
|
|
389
|
+
{
|
|
390
|
+
"--emvb-ie-from": "0%",
|
|
391
|
+
"--emvb-ie-to": `${fill}%`,
|
|
392
|
+
} as React.CSSProperties
|
|
393
|
+
}
|
|
394
|
+
onChange={(event) => onChange(Number(event.currentTarget.value))}
|
|
395
|
+
onPointerUp={() => onCommit?.()}
|
|
396
|
+
onKeyUp={() => onCommit?.()}
|
|
397
|
+
onBlur={() => onCommit?.()}
|
|
398
|
+
/>
|
|
399
|
+
</div>
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const roundTo = (v: number, step: number) => {
|
|
404
|
+
const places = Math.max(0, -Math.floor(Math.log10(step)));
|
|
405
|
+
return Number(v.toFixed(places));
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* A labelled slider with a typed value (W-484; photocn's adjustment, blur and filter sliders,
|
|
410
|
+
* whose value is a read-only output). The value field takes a number in the shown unit: Enter or
|
|
411
|
+
* leaving the field applies it, Escape puts the old one back, ↑/↓ step it. Values are in the
|
|
412
|
+
* units shown (−1 to 1, or 0 to 100 for percentages); `onCommit` ends one undo step.
|
|
413
|
+
*/
|
|
414
|
+
export function ValueSlider({
|
|
415
|
+
label,
|
|
416
|
+
name,
|
|
417
|
+
value,
|
|
418
|
+
min,
|
|
419
|
+
max,
|
|
420
|
+
step,
|
|
421
|
+
disabled,
|
|
422
|
+
format,
|
|
423
|
+
onChange,
|
|
424
|
+
onCommit,
|
|
425
|
+
}: {
|
|
426
|
+
label: string;
|
|
427
|
+
name: string;
|
|
428
|
+
value: number;
|
|
429
|
+
min: number;
|
|
430
|
+
max: number;
|
|
431
|
+
step: number;
|
|
432
|
+
disabled?: boolean;
|
|
433
|
+
format: (value: number) => string;
|
|
434
|
+
onChange: (value: number) => void;
|
|
435
|
+
onCommit?: () => void;
|
|
436
|
+
}) {
|
|
437
|
+
const id = React.useId();
|
|
438
|
+
const labelId = `${id}-label`;
|
|
439
|
+
const [draft, setDraft] = React.useState<string | null>(null);
|
|
440
|
+
const fill = ((value - min) / (max - min)) * 100;
|
|
441
|
+
const apply = (raw: string) => {
|
|
442
|
+
setDraft(null);
|
|
443
|
+
const parsed = Number.parseFloat(raw.replace(/[^\d.+-]/g, ""));
|
|
444
|
+
if (!Number.isFinite(parsed)) return;
|
|
445
|
+
const next = roundTo(Math.min(max, Math.max(min, parsed)), step);
|
|
446
|
+
if (next !== value) onChange(next);
|
|
447
|
+
onCommit?.();
|
|
448
|
+
};
|
|
449
|
+
return (
|
|
450
|
+
<div className="emvb-ie-slider" data-disabled={disabled || undefined}>
|
|
451
|
+
<div className="emvb-ie-slider-head">
|
|
452
|
+
<label id={labelId} htmlFor={id}>
|
|
453
|
+
{label}
|
|
454
|
+
</label>
|
|
455
|
+
<input
|
|
456
|
+
type="text"
|
|
457
|
+
inputMode="decimal"
|
|
458
|
+
className="emvb-ie-number"
|
|
459
|
+
aria-label={`${label} value`}
|
|
460
|
+
disabled={disabled}
|
|
461
|
+
data-emvb-image-number={name}
|
|
462
|
+
value={draft ?? format(value)}
|
|
463
|
+
onFocus={(event) => event.currentTarget.select()}
|
|
464
|
+
onChange={(event) => setDraft(event.currentTarget.value)}
|
|
465
|
+
onBlur={(event) => {
|
|
466
|
+
if (draft !== null) apply(event.currentTarget.value);
|
|
467
|
+
}}
|
|
468
|
+
onKeyDown={(event) => {
|
|
469
|
+
if (isCommitEnter(event)) {
|
|
470
|
+
event.preventDefault();
|
|
471
|
+
apply(event.currentTarget.value);
|
|
472
|
+
} else if (event.key === "Escape") {
|
|
473
|
+
// Put the old value back, and keep Esc from closing the editor.
|
|
474
|
+
event.preventDefault();
|
|
475
|
+
event.stopPropagation();
|
|
476
|
+
setDraft(null);
|
|
477
|
+
} else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
478
|
+
event.preventDefault();
|
|
479
|
+
const delta = (event.key === "ArrowUp" ? 1 : -1) * step * (event.shiftKey ? 10 : 1);
|
|
480
|
+
const next = roundTo(Math.min(max, Math.max(min, value + delta)), step);
|
|
481
|
+
setDraft(null);
|
|
482
|
+
onChange(next);
|
|
483
|
+
onCommit?.();
|
|
484
|
+
}
|
|
485
|
+
}}
|
|
486
|
+
/>
|
|
487
|
+
</div>
|
|
488
|
+
<input
|
|
489
|
+
id={id}
|
|
490
|
+
type="range"
|
|
491
|
+
min={min}
|
|
492
|
+
max={max}
|
|
493
|
+
step={step}
|
|
494
|
+
value={value}
|
|
495
|
+
disabled={disabled}
|
|
496
|
+
aria-labelledby={labelId}
|
|
497
|
+
aria-valuetext={format(value)}
|
|
498
|
+
data-emvb-image-slider={name}
|
|
499
|
+
style={{ "--emvb-ie-from": "0%", "--emvb-ie-to": `${fill}%` } as React.CSSProperties}
|
|
500
|
+
onChange={(event) => onChange(Number(event.currentTarget.value))}
|
|
501
|
+
onPointerUp={() => onCommit?.()}
|
|
502
|
+
onKeyUp={() => onCommit?.()}
|
|
503
|
+
onBlur={() => onCommit?.()}
|
|
504
|
+
/>
|
|
505
|
+
</div>
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** Underlined or segmented section tabs (photocn's TabsList, here Kumo Tabs). */
|
|
510
|
+
export function SectionTabs<T extends string>({
|
|
511
|
+
label,
|
|
512
|
+
value,
|
|
513
|
+
items,
|
|
514
|
+
onChange,
|
|
515
|
+
variant = "underline",
|
|
516
|
+
name,
|
|
517
|
+
}: {
|
|
518
|
+
label: string;
|
|
519
|
+
value: T;
|
|
520
|
+
items: readonly { value: T; label: React.ReactNode }[];
|
|
521
|
+
onChange: (value: T) => void;
|
|
522
|
+
variant?: "underline" | "segmented";
|
|
523
|
+
name: string;
|
|
524
|
+
}) {
|
|
525
|
+
return (
|
|
526
|
+
<div
|
|
527
|
+
className="emvb-ie-tabs"
|
|
528
|
+
data-variant={variant}
|
|
529
|
+
data-emvb-image-tabs={name}
|
|
530
|
+
role="group"
|
|
531
|
+
aria-label={label}
|
|
532
|
+
>
|
|
533
|
+
<Tabs
|
|
534
|
+
variant={variant}
|
|
535
|
+
size="sm"
|
|
536
|
+
value={value}
|
|
537
|
+
tabs={items.map((item) => ({ value: item.value, label: item.label }))}
|
|
538
|
+
onValueChange={(next) => {
|
|
539
|
+
const match = items.find((item) => item.value === next);
|
|
540
|
+
if (match) onChange(match.value);
|
|
541
|
+
}}
|
|
542
|
+
/>
|
|
543
|
+
</div>
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** Live RGB histogram of the rendered image (photocn ImageEditorHistogram). */
|
|
548
|
+
export function Histogram() {
|
|
549
|
+
const editor = useImageEditor();
|
|
550
|
+
const pixels = editor.histogram.data?.pixels;
|
|
551
|
+
return (
|
|
552
|
+
<div className="emvb-ie-histogram" data-slot="image-editor-histogram">
|
|
553
|
+
<div className="emvb-ie-histogram-head">
|
|
554
|
+
<span>Histogram</span>
|
|
555
|
+
<span className="emvb-ie-mono">{pixels ? pixels.toLocaleString() : "—"}</span>
|
|
556
|
+
</div>
|
|
557
|
+
<canvas aria-hidden="true" height={64} width={256} ref={editor.histogram.canvasRef} />
|
|
558
|
+
</div>
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** Perspective "adjust corners" icon (photocn icon-skew.tsx, from xdadda/mini-photo-editor). */
|
|
563
|
+
export function SkewIcon() {
|
|
564
|
+
return (
|
|
565
|
+
<svg
|
|
566
|
+
aria-hidden="true"
|
|
567
|
+
fill="none"
|
|
568
|
+
stroke="currentColor"
|
|
569
|
+
strokeLinecap="round"
|
|
570
|
+
strokeLinejoin="round"
|
|
571
|
+
strokeWidth="2"
|
|
572
|
+
viewBox="0 0 24 24"
|
|
573
|
+
width="1em"
|
|
574
|
+
height="1em"
|
|
575
|
+
>
|
|
576
|
+
<path d="M7 5 L21 8 L17 19 L3 16 Z" />
|
|
577
|
+
<circle cx="7" cy="5" r="0.7" fill="currentColor" />
|
|
578
|
+
<circle cx="21" cy="8" r="0.7" fill="currentColor" />
|
|
579
|
+
<circle cx="17" cy="19" r="0.7" fill="currentColor" />
|
|
580
|
+
<circle cx="3" cy="16" r="0.7" fill="currentColor" />
|
|
581
|
+
</svg>
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** Quarter-turn icons, as in photocn's crop panel (Lucide rotate-ccw/cw-square, ISC). */
|
|
586
|
+
export function RotateSquareIcon({ direction }: { direction: "left" | "right" }) {
|
|
587
|
+
return (
|
|
588
|
+
<svg
|
|
589
|
+
aria-hidden="true"
|
|
590
|
+
fill="none"
|
|
591
|
+
stroke="currentColor"
|
|
592
|
+
strokeLinecap="round"
|
|
593
|
+
strokeLinejoin="round"
|
|
594
|
+
strokeWidth="2"
|
|
595
|
+
viewBox="0 0 24 24"
|
|
596
|
+
width="1em"
|
|
597
|
+
height="1em"
|
|
598
|
+
>
|
|
599
|
+
{direction === "left" ? (
|
|
600
|
+
<>
|
|
601
|
+
<path d="M20 9V7a2 2 0 0 0-2-2h-6" />
|
|
602
|
+
<path d="m15 2-3 3 3 3" />
|
|
603
|
+
<path d="M20 13v5a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2" />
|
|
604
|
+
</>
|
|
605
|
+
) : (
|
|
606
|
+
<>
|
|
607
|
+
<path d="M12 5H6a2 2 0 0 0-2 2v3" />
|
|
608
|
+
<path d="m9 8 3-3-3-3" />
|
|
609
|
+
<path d="M4 14v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2" />
|
|
610
|
+
</>
|
|
611
|
+
)}
|
|
612
|
+
</svg>
|
|
613
|
+
);
|
|
614
|
+
}
|