@olenbetong/synergi-react 2.9.0 → 3.1.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/es/chrome/AppShell/index.d.ts +8 -0
- package/es/chrome/AppShell/index.js +10 -130
- package/es/components/ImageEditor/ImageEditor.css +10 -0
- package/es/components/ImageEditor/index.d.ts +1 -0
- package/es/components/ImageEditor/index.js +1 -0
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
- package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
- package/es/components/ImageEditor/useEdgeDetection.js +11 -30
- package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
- package/es/components/ImageEditor/useOpenCV.js +108 -42
- package/es/components/SplitContainer/index.js +2 -4
- package/es/filter/index.d.ts +8 -0
- package/es/filter/index.js +8 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +6 -1
- package/es/mui/MuiThemeProvider.d.ts +24 -0
- package/es/mui/MuiThemeProvider.js +152 -0
- package/es/mui/index.d.ts +1 -0
- package/es/mui/index.js +1 -0
- package/es/report/ReportLauncher.css +147 -0
- package/es/report/ReportLauncher.d.ts +55 -0
- package/es/report/ReportLauncher.js +142 -0
- package/es/report/ReportLauncher.test.d.ts +1 -0
- package/es/report/ReportLauncher.test.js +231 -0
- package/es/report/ReportParameters.css +29 -0
- package/es/report/ReportParameters.d.ts +46 -0
- package/es/report/ReportParameters.js +65 -0
- package/es/report/ReportParameters.test.d.ts +1 -0
- package/es/report/ReportParameters.test.js +84 -0
- package/es/report/index.d.ts +2 -0
- package/es/report/index.js +2 -0
- package/es/test/setup.d.ts +1 -0
- package/es/test/setup.js +6 -0
- package/package.json +22 -7
- package/src/chrome/AppShell/index.tsx +34 -171
- package/src/components/ImageEditor/ImageEditor.css +15 -5
- package/src/components/ImageEditor/ImageEditor.tsx +1 -1
- package/src/components/ImageEditor/index.ts +1 -0
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
- package/src/components/ImageEditor/useOpenCV.ts +112 -62
- package/src/components/SplitContainer/index.tsx +3 -4
- package/src/filter/index.ts +34 -0
- package/src/index.ts +39 -1
- package/src/mui/MuiThemeProvider.tsx +174 -0
- package/src/mui/index.ts +1 -0
- package/src/report/ReportLauncher.css +147 -0
- package/src/report/ReportLauncher.test.tsx +281 -0
- package/src/report/ReportLauncher.tsx +420 -0
- package/src/report/ReportParameters.css +29 -0
- package/src/report/ReportParameters.test.tsx +133 -0
- package/src/report/ReportParameters.tsx +198 -0
- package/src/report/index.ts +2 -0
- package/src/test/setup.ts +8 -0
|
@@ -2,4 +2,12 @@ import { type ReactNode } from "react";
|
|
|
2
2
|
export type AppShellProps = {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* Standard Synergi app chrome: error boundary, app menu and the toolbar toggle.
|
|
7
|
+
*
|
|
8
|
+
* This component is Designsystemet-only. Apps that still render MUI components
|
|
9
|
+
* should additionally wrap it in `MuiThemeProvider` from
|
|
10
|
+
* `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
|
|
11
|
+
* tokens into a MUI theme.
|
|
12
|
+
*/
|
|
5
13
|
export declare function AppShell({ children }: AppShellProps): import("react").JSX.Element;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
3
|
-
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
4
2
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
5
|
-
import { AppErrorBoundary } from "@olenbetong/appframe-
|
|
6
|
-
import { useCallback,
|
|
3
|
+
import { AppErrorBoundary } from "@olenbetong/appframe-ds";
|
|
4
|
+
import { useCallback, useMemo, useState } from "react";
|
|
7
5
|
import { createPortal } from "react-dom";
|
|
8
6
|
import { AppMenu } from "../AppMenu/AppMenu.js";
|
|
9
7
|
import { AppMenuToggle } from "../AppMenu/AppMenuToggle.js";
|
|
@@ -80,125 +78,15 @@ const dsAppMenuUser = af.data.generateApiDataObject({
|
|
|
80
78
|
whereClause: "PersonID = SUSER_SNAME()",
|
|
81
79
|
},
|
|
82
80
|
});
|
|
83
|
-
function getColorScheme() {
|
|
84
|
-
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
85
|
-
if (scheme === "auto") {
|
|
86
|
-
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
87
|
-
}
|
|
88
|
-
return scheme === "dark" ? "dark" : "light";
|
|
89
|
-
}
|
|
90
81
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
82
|
+
* Standard Synergi app chrome: error boundary, app menu and the toolbar toggle.
|
|
83
|
+
*
|
|
84
|
+
* This component is Designsystemet-only. Apps that still render MUI components
|
|
85
|
+
* should additionally wrap it in `MuiThemeProvider` from
|
|
86
|
+
* `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
|
|
87
|
+
* tokens into a MUI theme.
|
|
94
88
|
*/
|
|
95
|
-
function useColorScheme() {
|
|
96
|
-
let [scheme, setScheme] = useState(() => getColorScheme());
|
|
97
|
-
useEffect(() => {
|
|
98
|
-
function update() {
|
|
99
|
-
setScheme(getColorScheme());
|
|
100
|
-
}
|
|
101
|
-
update();
|
|
102
|
-
let observer = new MutationObserver(update);
|
|
103
|
-
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
104
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
105
|
-
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
106
|
-
media?.addEventListener("change", update);
|
|
107
|
-
return () => {
|
|
108
|
-
observer.disconnect();
|
|
109
|
-
media?.removeEventListener("change", update);
|
|
110
|
-
};
|
|
111
|
-
}, []);
|
|
112
|
-
return scheme;
|
|
113
|
-
}
|
|
114
|
-
function buildMuiTheme(mode) {
|
|
115
|
-
const s = getComputedStyle(document.body);
|
|
116
|
-
const get = (v) => s.getPropertyValue(v).trim();
|
|
117
|
-
const isDark = mode === "dark";
|
|
118
|
-
return muiCreateTheme({
|
|
119
|
-
palette: {
|
|
120
|
-
mode,
|
|
121
|
-
primary: {
|
|
122
|
-
main: get("--ds-color-brand-base-default") || "#116069",
|
|
123
|
-
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
124
|
-
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
125
|
-
},
|
|
126
|
-
secondary: {
|
|
127
|
-
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
128
|
-
},
|
|
129
|
-
background: {
|
|
130
|
-
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
131
|
-
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
132
|
-
},
|
|
133
|
-
text: {
|
|
134
|
-
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
135
|
-
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
136
|
-
},
|
|
137
|
-
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
138
|
-
},
|
|
139
|
-
typography: {
|
|
140
|
-
fontFamily: [
|
|
141
|
-
"-apple-system",
|
|
142
|
-
"BlinkMacSystemFont",
|
|
143
|
-
'"Segoe UI"',
|
|
144
|
-
"Roboto",
|
|
145
|
-
'"Helvetica Neue"',
|
|
146
|
-
"Arial",
|
|
147
|
-
"sans-serif",
|
|
148
|
-
'"Apple Color Emoji"',
|
|
149
|
-
'"Segoe UI Emoji"',
|
|
150
|
-
'"Segoe UI Symbol"',
|
|
151
|
-
].join(","),
|
|
152
|
-
},
|
|
153
|
-
components: {
|
|
154
|
-
MuiTypography: {
|
|
155
|
-
styleOverrides: {
|
|
156
|
-
h1: { fontSize: "2.488rem" },
|
|
157
|
-
h2: { fontSize: "2.074rem" },
|
|
158
|
-
h3: { fontSize: "1.728rem" },
|
|
159
|
-
h4: { fontSize: "1.44rem" },
|
|
160
|
-
h5: { fontSize: "1.2rem" },
|
|
161
|
-
h6: { fontSize: "1rem" },
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
MuiAppBar: {
|
|
165
|
-
styleOverrides: {
|
|
166
|
-
root: {
|
|
167
|
-
"& .MuiTypography-h1": {
|
|
168
|
-
fontSize: "1.25rem",
|
|
169
|
-
fontWeight: "500",
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
MuiButton: {
|
|
175
|
-
styleOverrides: {
|
|
176
|
-
root: { borderRadius: 2 },
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
MuiDialogTitle: {
|
|
180
|
-
styleOverrides: {
|
|
181
|
-
root: {
|
|
182
|
-
fontSize: "1.2rem",
|
|
183
|
-
fontWeight: 500,
|
|
184
|
-
paddingLeft: 16,
|
|
185
|
-
paddingRight: 16,
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
MuiFormLabel: {
|
|
190
|
-
styleOverrides: {
|
|
191
|
-
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
195
|
-
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
196
|
-
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
89
|
export function AppShell({ children }) {
|
|
201
|
-
const colorScheme = useColorScheme();
|
|
202
90
|
const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
|
|
203
91
|
const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
|
|
204
92
|
// The developer tools are only reachable for developers, so hide them for
|
|
@@ -213,15 +101,7 @@ export function AppShell({ children }) {
|
|
|
213
101
|
const toggleFavorite = useCallback(async (articleId, favorite) => {
|
|
214
102
|
await procSetArticleFavorite.execute({ HostName: hostName, ArticleID: articleId, Favorite: favorite });
|
|
215
103
|
}, []);
|
|
216
|
-
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
217
|
-
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
218
|
-
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
219
|
-
// the CSS variables aren't necessarily resolved during the first render.
|
|
220
|
-
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
221
|
-
useEffect(() => {
|
|
222
|
-
setTheme(buildMuiTheme(colorScheme));
|
|
223
|
-
}, [colorScheme]);
|
|
224
104
|
const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
|
|
225
|
-
return (
|
|
226
|
-
|
|
105
|
+
return (_jsxs(AppErrorBoundary, { children: [appMenuSlot &&
|
|
106
|
+
createPortal(_jsx(AppMenuToggle, { open: isAppMenuOpen, hasUpdate: isUpdateAvailable, "aria-controls": "ob-app-menu", onClick: () => setIsAppMenuOpen((open) => !open) }), appMenuSlot), _jsx(AppMenu, { id: "ob-app-menu", dataObject: dsMenuArticles, userDataObject: dsAppMenuUser, categories: categories, homeLink: homeLink, onToggleFavorite: toggleFavorite, hasUpdate: isUpdateAvailable, onInstallUpdate: installUpdate, open: isAppMenuOpen, onClose: () => setIsAppMenuOpen(false) }), children] }));
|
|
227
107
|
}
|
|
@@ -167,6 +167,16 @@
|
|
|
167
167
|
line-height: 0; /* remove gap under canvas */
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/* Transparent drawing surface for the rectangle crop mode. Sits above the canvas
|
|
171
|
+
but below the corner handles (which are hidden while this mode is active). */
|
|
172
|
+
.crop-draw-surface {
|
|
173
|
+
position: absolute;
|
|
174
|
+
inset: 0;
|
|
175
|
+
cursor: crosshair;
|
|
176
|
+
touch-action: none;
|
|
177
|
+
z-index: 8;
|
|
178
|
+
}
|
|
179
|
+
|
|
170
180
|
/* ── Redact plugin ───────────────────────────────────────────── */
|
|
171
181
|
|
|
172
182
|
.redact-root {
|
|
@@ -6,3 +6,4 @@ export { redactPlugin } from "./plugins/redactPlugin/index.js";
|
|
|
6
6
|
export { zoomPlugin } from "./plugins/zoomPlugin/index.js";
|
|
7
7
|
export { rotateCcwPlugin, rotateCwPlugin } from "./plugins/rotatePlugin.js";
|
|
8
8
|
export type { ActionPlugin, EditAction, Plugin, ToolPlugin, ViewPlugin } from "./types.js";
|
|
9
|
+
export { configureOpenCV, DEFAULT_OPENCV_URLS, loadOpenCV } from "./useOpenCV.js";
|
|
@@ -4,3 +4,4 @@ export { cropPlugin } from "./plugins/cropPlugin/index.js";
|
|
|
4
4
|
export { redactPlugin } from "./plugins/redactPlugin/index.js";
|
|
5
5
|
export { zoomPlugin } from "./plugins/zoomPlugin/index.js";
|
|
6
6
|
export { rotateCcwPlugin, rotateCwPlugin } from "./plugins/rotatePlugin.js";
|
|
7
|
+
export { configureOpenCV, DEFAULT_OPENCV_URLS, loadOpenCV } from "./useOpenCV.js";
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Paragraph, Spinner } from "@digdir/designsystemet-react";
|
|
3
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
4
|
import { CropCanvas } from "../../CropCanvas.js";
|
|
5
5
|
import { DragHandle } from "../../DragHandle.js";
|
|
6
6
|
import { EdgeHandle } from "../../EdgeHandle.js";
|
|
7
|
+
import { useZoomLevel } from "../zoomPlugin/ZoomContext.js";
|
|
7
8
|
import { useCropContext } from "./CropContext.js";
|
|
8
9
|
/** Canvas-area overlay for the crop tool. Reads all state from CropContext. */
|
|
9
10
|
export function CropOverlay() {
|
|
10
|
-
let { imageUrl, activeCorners, scale, displaySize, canvasRef, cvReady, cvError, cropping, error, handleCanvasReady, updateCorner, } = useCropContext();
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let { imageUrl, activeCorners, mode, hasSelection, scale, displaySize, canvasRef, cvReady, cvError, cropping, error, handleCanvasReady, updateCorner, startRectDraw, updateRectDraw, finishRectDraw, } = useCropContext();
|
|
12
|
+
let zoom = useZoomLevel();
|
|
13
|
+
let showHandles = mode === "corners" && displaySize.width > 0;
|
|
14
|
+
function pointerPosition(e) {
|
|
15
|
+
// getBoundingClientRect() is screen-space (affected by the zoom transform),
|
|
16
|
+
// so divide by zoom to get back to the CSS-pixel space the tool expects.
|
|
17
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
18
|
+
return { x: (e.clientX - rect.left) / zoom, y: (e.clientY - rect.top) / zoom };
|
|
19
|
+
}
|
|
20
|
+
function onPointerDown(e) {
|
|
21
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
22
|
+
let { x, y } = pointerPosition(e);
|
|
23
|
+
startRectDraw(x, y);
|
|
24
|
+
}
|
|
25
|
+
function onPointerMove(e) {
|
|
26
|
+
if (!(e.buttons & 1))
|
|
27
|
+
return;
|
|
28
|
+
let { x, y } = pointerPosition(e);
|
|
29
|
+
updateRectDraw(x, y);
|
|
30
|
+
}
|
|
31
|
+
return (_jsxs("div", { className: "crop-root", children: [_jsxs("div", { className: "crop-inner", children: [_jsx(CropCanvas, { ref: canvasRef, imageUrl: imageUrl, corners: activeCorners, onReady: handleCanvasReady }), mode === "rect" && displaySize.width > 0 && (_jsx("div", { role: "application", "aria-label": getLocalizedString("Drag to draw a rectangle to crop to"), className: "crop-draw-surface", onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: finishRectDraw, onPointerCancel: finishRectDraw })), showHandles &&
|
|
32
|
+
activeCorners.map((corner, i) => (_jsx(DragHandle, { x: corner.x * scale, y: corner.y * scale, onChange: (x, y) => updateCorner(i, x, y), containerWidth: displaySize.width, containerHeight: displaySize.height }, i))), showHandles &&
|
|
13
33
|
(() => {
|
|
14
34
|
let [tl, tr, br, bl] = activeCorners;
|
|
15
35
|
let s = scale;
|
|
@@ -26,5 +46,7 @@ export function CropOverlay() {
|
|
|
26
46
|
updateCorner(3, bl.x * s + dx, bl.y * s + dy);
|
|
27
47
|
updateCorner(0, tl.x * s + dx, tl.y * s + dy);
|
|
28
48
|
} })] }));
|
|
29
|
-
})()] }),
|
|
49
|
+
})()] }), cropping ? (_jsx("div", { className: "crop-loading", children: _jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }) })) : error ? (_jsx("div", { className: "crop-loading", children: _jsx(Paragraph, { "data-size": "sm", children: error }) })) : mode === "rect" ? (_jsx("div", { className: "crop-loading", children: _jsx(Paragraph, { "data-size": "sm", children: hasSelection
|
|
50
|
+
? getLocalizedString("Release to use this rectangle")
|
|
51
|
+
: getLocalizedString("Drag to draw a rectangle to crop to") }) })) : !cvReady && !cvError ? (_jsxs("div", { className: "crop-loading", children: [_jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }), _jsx(Paragraph, { "data-size": "sm", children: getLocalizedString("Detecting borders…") })] })) : cvError ? (_jsx("div", { className: "crop-loading", children: _jsx(Paragraph, { "data-size": "sm", children: getLocalizedString("Automatic border detection is unavailable. Adjust the selection manually.") }) })) : null] }));
|
|
30
52
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Button, Spinner } from "@digdir/designsystemet-react";
|
|
3
|
-
import { CheckmarkIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
3
|
+
import { CheckmarkIcon, ExpandIcon, SquareIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
4
4
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
5
5
|
import { useCropContext } from "./CropContext.js";
|
|
6
6
|
/** Toolbar shown while the crop tool is active. Reads state from CropContext. */
|
|
7
7
|
export function CropToolbar() {
|
|
8
|
-
let { applyCrop, cropping,
|
|
8
|
+
let { applyCrop, cropping, mode, hasSelection, startRectMode, cancelRectMode, onApply, onCancel } = useCropContext();
|
|
9
|
+
let inRectMode = mode === "rect";
|
|
9
10
|
async function handleApply() {
|
|
10
11
|
let result = await applyCrop();
|
|
11
12
|
if (result)
|
|
12
13
|
onApply(result.blob, result.actions);
|
|
13
14
|
}
|
|
14
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "image-editor__toolbar-group", children: _jsxs(Button, { variant: "tertiary", "data-size": "sm", onClick: onCancel, disabled: cropping, children: [_jsx(XMarkIcon, { "aria-hidden": true }), getLocalizedString("Cancel")] }) }),
|
|
15
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "image-editor__toolbar-group", children: _jsxs(Button, { variant: "tertiary", "data-size": "sm", onClick: onCancel, disabled: cropping, children: [_jsx(XMarkIcon, { "aria-hidden": true }), getLocalizedString("Cancel")] }) }), _jsxs("div", { className: "image-editor__toolbar-group", children: [_jsxs(Button, { variant: "tertiary", "data-size": "sm", "aria-pressed": inRectMode, onClick: inRectMode ? cancelRectMode : startRectMode, disabled: cropping, children: [inRectMode ? _jsx(ExpandIcon, { "aria-hidden": true }) : _jsx(SquareIcon, { "aria-hidden": true }), inRectMode ? getLocalizedString("Adjust corners") : getLocalizedString("Draw rectangle")] }), _jsxs(Button, { variant: "primary", "data-size": "sm", onClick: handleApply, disabled: cropping || inRectMode || !hasSelection, children: [cropping ? _jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }) : _jsx(CheckmarkIcon, { "aria-hidden": true }), getLocalizedString("Apply crop")] })] })] }));
|
|
15
16
|
}
|
|
@@ -5,8 +5,16 @@ export interface ApplyCropResult {
|
|
|
5
5
|
blob: Blob;
|
|
6
6
|
actions: EditAction[];
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* `corners` — drag the four corner/edge handles of the current selection.
|
|
10
|
+
* `rect` — drag out a brand new axis-aligned rectangle.
|
|
11
|
+
*/
|
|
12
|
+
export type CropMode = "corners" | "rect";
|
|
8
13
|
export interface CropToolState {
|
|
9
14
|
activeCorners: Quad;
|
|
15
|
+
mode: CropMode;
|
|
16
|
+
/** False while the user is in rect mode and has not drawn a rectangle yet. */
|
|
17
|
+
hasSelection: boolean;
|
|
10
18
|
scale: number;
|
|
11
19
|
displaySize: {
|
|
12
20
|
width: number;
|
|
@@ -17,18 +25,27 @@ export interface CropToolState {
|
|
|
17
25
|
cvError: Error | null;
|
|
18
26
|
cropping: boolean;
|
|
19
27
|
error: string | null;
|
|
20
|
-
debugImageUrl: string | null;
|
|
21
28
|
handleCanvasReady: (canvas: HTMLCanvasElement, w: number, h: number) => void;
|
|
22
29
|
updateCorner: (index: number, screenX: number, screenY: number) => void;
|
|
30
|
+
/** Enters rect mode, temporarily clearing (and remembering) the current selection. */
|
|
31
|
+
startRectMode: () => void;
|
|
32
|
+
/** Leaves rect mode without drawing, restoring the selection that was active before. */
|
|
33
|
+
cancelRectMode: () => void;
|
|
34
|
+
startRectDraw: (screenX: number, screenY: number) => void;
|
|
35
|
+
updateRectDraw: (screenX: number, screenY: number) => void;
|
|
36
|
+
finishRectDraw: () => void;
|
|
23
37
|
applyCrop: () => Promise<ApplyCropResult | null>;
|
|
24
38
|
}
|
|
25
39
|
/**
|
|
26
|
-
* Manages all state and logic for the
|
|
27
|
-
*
|
|
40
|
+
* Manages all state and logic for the crop tool.
|
|
41
|
+
* OpenCV is loaded lazily for corner suggestion and perspective warping, but is optional:
|
|
42
|
+
* when it fails to load the tool stays fully usable, only the suggested border is missing.
|
|
28
43
|
*/
|
|
29
44
|
export declare function useCropTool(imageUrl: string, enabled: boolean): CropToolState;
|
|
30
45
|
/**
|
|
31
46
|
* Standalone replay handler for the "crop" action type.
|
|
32
47
|
* Corners are stored as relative (0–1) values so they work at any resolution.
|
|
48
|
+
* Rectangular crops replay without OpenCV; older actions without a stored mode
|
|
49
|
+
* are treated as perspective crops.
|
|
33
50
|
*/
|
|
34
51
|
export declare function replayCrop(imageUrl: string, params: Record<string, unknown>): Promise<Blob>;
|