@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
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
|
-
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
1
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
-
import { AppErrorBoundary } from "@olenbetong/appframe-
|
|
5
|
-
import { type ReactNode, useCallback,
|
|
2
|
+
import { AppErrorBoundary } from "@olenbetong/appframe-ds";
|
|
3
|
+
import { type ReactNode, useCallback, useMemo, useState } from "react";
|
|
6
4
|
import { createPortal } from "react-dom";
|
|
7
5
|
|
|
8
6
|
import { AppMenu, type AppMenuArticle } from "../AppMenu/AppMenu.js";
|
|
@@ -89,141 +87,19 @@ const dsAppMenuUser = af.data.generateApiDataObject<AppMenuUser>({
|
|
|
89
87
|
},
|
|
90
88
|
});
|
|
91
89
|
|
|
92
|
-
function getColorScheme(): "light" | "dark" {
|
|
93
|
-
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
94
|
-
|
|
95
|
-
if (scheme === "auto") {
|
|
96
|
-
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return scheme === "dark" ? "dark" : "light";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
104
|
-
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
105
|
-
* OS preference (used when the scheme is `auto`).
|
|
106
|
-
*/
|
|
107
|
-
function useColorScheme() {
|
|
108
|
-
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
109
|
-
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
function update() {
|
|
112
|
-
setScheme(getColorScheme());
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
update();
|
|
116
|
-
|
|
117
|
-
let observer = new MutationObserver(update);
|
|
118
|
-
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
119
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
120
|
-
|
|
121
|
-
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
122
|
-
media?.addEventListener("change", update);
|
|
123
|
-
|
|
124
|
-
return () => {
|
|
125
|
-
observer.disconnect();
|
|
126
|
-
media?.removeEventListener("change", update);
|
|
127
|
-
};
|
|
128
|
-
}, []);
|
|
129
|
-
|
|
130
|
-
return scheme;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function buildMuiTheme(mode: "light" | "dark") {
|
|
134
|
-
const s = getComputedStyle(document.body);
|
|
135
|
-
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
136
|
-
const isDark = mode === "dark";
|
|
137
|
-
|
|
138
|
-
return muiCreateTheme({
|
|
139
|
-
palette: {
|
|
140
|
-
mode,
|
|
141
|
-
primary: {
|
|
142
|
-
main: get("--ds-color-brand-base-default") || "#116069",
|
|
143
|
-
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
144
|
-
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
145
|
-
},
|
|
146
|
-
secondary: {
|
|
147
|
-
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
148
|
-
},
|
|
149
|
-
background: {
|
|
150
|
-
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
151
|
-
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
152
|
-
},
|
|
153
|
-
text: {
|
|
154
|
-
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
155
|
-
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
156
|
-
},
|
|
157
|
-
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
158
|
-
},
|
|
159
|
-
typography: {
|
|
160
|
-
fontFamily: [
|
|
161
|
-
"-apple-system",
|
|
162
|
-
"BlinkMacSystemFont",
|
|
163
|
-
'"Segoe UI"',
|
|
164
|
-
"Roboto",
|
|
165
|
-
'"Helvetica Neue"',
|
|
166
|
-
"Arial",
|
|
167
|
-
"sans-serif",
|
|
168
|
-
'"Apple Color Emoji"',
|
|
169
|
-
'"Segoe UI Emoji"',
|
|
170
|
-
'"Segoe UI Symbol"',
|
|
171
|
-
].join(","),
|
|
172
|
-
},
|
|
173
|
-
components: {
|
|
174
|
-
MuiTypography: {
|
|
175
|
-
styleOverrides: {
|
|
176
|
-
h1: { fontSize: "2.488rem" },
|
|
177
|
-
h2: { fontSize: "2.074rem" },
|
|
178
|
-
h3: { fontSize: "1.728rem" },
|
|
179
|
-
h4: { fontSize: "1.44rem" },
|
|
180
|
-
h5: { fontSize: "1.2rem" },
|
|
181
|
-
h6: { fontSize: "1rem" },
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
MuiAppBar: {
|
|
185
|
-
styleOverrides: {
|
|
186
|
-
root: {
|
|
187
|
-
"& .MuiTypography-h1": {
|
|
188
|
-
fontSize: "1.25rem",
|
|
189
|
-
fontWeight: "500",
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
MuiButton: {
|
|
195
|
-
styleOverrides: {
|
|
196
|
-
root: { borderRadius: 2 },
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
MuiDialogTitle: {
|
|
200
|
-
styleOverrides: {
|
|
201
|
-
root: {
|
|
202
|
-
fontSize: "1.2rem",
|
|
203
|
-
fontWeight: 500,
|
|
204
|
-
paddingLeft: 16,
|
|
205
|
-
paddingRight: 16,
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
MuiFormLabel: {
|
|
210
|
-
styleOverrides: {
|
|
211
|
-
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
215
|
-
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
216
|
-
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
90
|
export type AppShellProps = {
|
|
222
91
|
children: ReactNode;
|
|
223
92
|
};
|
|
224
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Standard Synergi app chrome: error boundary, app menu and the toolbar toggle.
|
|
96
|
+
*
|
|
97
|
+
* This component is Designsystemet-only. Apps that still render MUI components
|
|
98
|
+
* should additionally wrap it in `MuiThemeProvider` from
|
|
99
|
+
* `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
|
|
100
|
+
* tokens into a MUI theme.
|
|
101
|
+
*/
|
|
225
102
|
export function AppShell({ children }: AppShellProps) {
|
|
226
|
-
const colorScheme = useColorScheme();
|
|
227
103
|
const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
|
|
228
104
|
const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
|
|
229
105
|
|
|
@@ -242,46 +118,33 @@ export function AppShell({ children }: AppShellProps) {
|
|
|
242
118
|
await procSetArticleFavorite.execute({ HostName: hostName, ArticleID: articleId, Favorite: favorite });
|
|
243
119
|
}, []);
|
|
244
120
|
|
|
245
|
-
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
246
|
-
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
247
|
-
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
248
|
-
// the CSS variables aren't necessarily resolved during the first render.
|
|
249
|
-
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
250
|
-
useEffect(() => {
|
|
251
|
-
setTheme(buildMuiTheme(colorScheme));
|
|
252
|
-
}, [colorScheme]);
|
|
253
|
-
|
|
254
121
|
const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
|
|
255
122
|
|
|
256
123
|
return (
|
|
257
|
-
<
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
createPortal(
|
|
262
|
-
<AppMenuToggle
|
|
263
|
-
open={isAppMenuOpen}
|
|
264
|
-
hasUpdate={isUpdateAvailable}
|
|
265
|
-
aria-controls="ob-app-menu"
|
|
266
|
-
onClick={() => setIsAppMenuOpen((open) => !open)}
|
|
267
|
-
/>,
|
|
268
|
-
appMenuSlot,
|
|
269
|
-
)}
|
|
270
|
-
<AppMenu
|
|
271
|
-
id="ob-app-menu"
|
|
272
|
-
dataObject={dsMenuArticles}
|
|
273
|
-
userDataObject={dsAppMenuUser}
|
|
274
|
-
categories={categories}
|
|
275
|
-
homeLink={homeLink}
|
|
276
|
-
onToggleFavorite={toggleFavorite}
|
|
277
|
-
hasUpdate={isUpdateAvailable}
|
|
278
|
-
onInstallUpdate={installUpdate}
|
|
124
|
+
<AppErrorBoundary>
|
|
125
|
+
{appMenuSlot &&
|
|
126
|
+
createPortal(
|
|
127
|
+
<AppMenuToggle
|
|
279
128
|
open={isAppMenuOpen}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
129
|
+
hasUpdate={isUpdateAvailable}
|
|
130
|
+
aria-controls="ob-app-menu"
|
|
131
|
+
onClick={() => setIsAppMenuOpen((open) => !open)}
|
|
132
|
+
/>,
|
|
133
|
+
appMenuSlot,
|
|
134
|
+
)}
|
|
135
|
+
<AppMenu
|
|
136
|
+
id="ob-app-menu"
|
|
137
|
+
dataObject={dsMenuArticles}
|
|
138
|
+
userDataObject={dsAppMenuUser}
|
|
139
|
+
categories={categories}
|
|
140
|
+
homeLink={homeLink}
|
|
141
|
+
onToggleFavorite={toggleFavorite}
|
|
142
|
+
hasUpdate={isUpdateAvailable}
|
|
143
|
+
onInstallUpdate={installUpdate}
|
|
144
|
+
open={isAppMenuOpen}
|
|
145
|
+
onClose={() => setIsAppMenuOpen(false)}
|
|
146
|
+
/>
|
|
147
|
+
{children}
|
|
148
|
+
</AppErrorBoundary>
|
|
286
149
|
);
|
|
287
150
|
}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
height: 100%;
|
|
3
3
|
display: flex;
|
|
4
4
|
flex-direction: column;
|
|
5
|
-
/*
|
|
6
|
-
so
|
|
7
|
-
|
|
8
|
-
background: var(--ds-color-neutral-background-default, #111);
|
|
5
|
+
/* Follow the page color scheme, but keep a neutral gray editor surface in light mode
|
|
6
|
+
so white scanned documents still stand out from the background. */
|
|
7
|
+
background: var(--ds-color-neutral-background-tinted, #f3f3f4);
|
|
9
8
|
color: var(--ds-color-neutral-text-default, white);
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -26,6 +25,7 @@
|
|
|
26
25
|
justify-content: center;
|
|
27
26
|
position: relative;
|
|
28
27
|
overflow: hidden;
|
|
28
|
+
background: var(--ds-color-neutral-background-tinted, #f3f3f4);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
.image-editor__replay-overlay {
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
so they're never clipped at the edges. */
|
|
158
158
|
padding: 16px;
|
|
159
159
|
box-sizing: border-box;
|
|
160
|
-
background: var(--ds-color-neutral-background-
|
|
160
|
+
background: var(--ds-color-neutral-background-tinted, #f3f3f4);
|
|
161
161
|
touch-action: none;
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -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 {
|
|
@@ -113,7 +113,7 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
|
|
|
113
113
|
let TopBarControls = viewPlugin?.TopBarControls;
|
|
114
114
|
|
|
115
115
|
let inner = (
|
|
116
|
-
<div className="image-editor"
|
|
116
|
+
<div className="image-editor">
|
|
117
117
|
{/* Top toolbar — always visible; undo/redo/reset disabled while a tool is active */}
|
|
118
118
|
<div className="image-editor__topbar">
|
|
119
119
|
<div className="image-editor__toolbar-group">
|
|
@@ -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";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Paragraph, Spinner } from "@digdir/designsystemet-react";
|
|
2
2
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
3
|
|
|
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
|
|
|
9
10
|
/** Canvas-area overlay for the crop tool. Reads all state from CropContext. */
|
|
@@ -11,6 +12,8 @@ export function CropOverlay() {
|
|
|
11
12
|
let {
|
|
12
13
|
imageUrl,
|
|
13
14
|
activeCorners,
|
|
15
|
+
mode,
|
|
16
|
+
hasSelection,
|
|
14
17
|
scale,
|
|
15
18
|
displaySize,
|
|
16
19
|
canvasRef,
|
|
@@ -20,14 +23,51 @@ export function CropOverlay() {
|
|
|
20
23
|
error,
|
|
21
24
|
handleCanvasReady,
|
|
22
25
|
updateCorner,
|
|
26
|
+
startRectDraw,
|
|
27
|
+
updateRectDraw,
|
|
28
|
+
finishRectDraw,
|
|
23
29
|
} = useCropContext();
|
|
24
30
|
|
|
31
|
+
let zoom = useZoomLevel();
|
|
32
|
+
let showHandles = mode === "corners" && displaySize.width > 0;
|
|
33
|
+
|
|
34
|
+
function pointerPosition(e: React.PointerEvent<HTMLDivElement>) {
|
|
35
|
+
// getBoundingClientRect() is screen-space (affected by the zoom transform),
|
|
36
|
+
// so divide by zoom to get back to the CSS-pixel space the tool expects.
|
|
37
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
38
|
+
return { x: (e.clientX - rect.left) / zoom, y: (e.clientY - rect.top) / zoom };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function onPointerDown(e: React.PointerEvent<HTMLDivElement>) {
|
|
42
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
43
|
+
let { x, y } = pointerPosition(e);
|
|
44
|
+
startRectDraw(x, y);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function onPointerMove(e: React.PointerEvent<HTMLDivElement>) {
|
|
48
|
+
if (!(e.buttons & 1)) return;
|
|
49
|
+
let { x, y } = pointerPosition(e);
|
|
50
|
+
updateRectDraw(x, y);
|
|
51
|
+
}
|
|
52
|
+
|
|
25
53
|
return (
|
|
26
54
|
<div className="crop-root">
|
|
27
55
|
<div className="crop-inner">
|
|
28
56
|
<CropCanvas ref={canvasRef} imageUrl={imageUrl} corners={activeCorners} onReady={handleCanvasReady} />
|
|
29
57
|
|
|
30
|
-
{displaySize.width > 0 &&
|
|
58
|
+
{mode === "rect" && displaySize.width > 0 && (
|
|
59
|
+
<div
|
|
60
|
+
role="application"
|
|
61
|
+
aria-label={getLocalizedString("Drag to draw a rectangle to crop to")}
|
|
62
|
+
className="crop-draw-surface"
|
|
63
|
+
onPointerDown={onPointerDown}
|
|
64
|
+
onPointerMove={onPointerMove}
|
|
65
|
+
onPointerUp={finishRectDraw}
|
|
66
|
+
onPointerCancel={finishRectDraw}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
|
|
70
|
+
{showHandles &&
|
|
31
71
|
activeCorners.map((corner, i) => (
|
|
32
72
|
<DragHandle
|
|
33
73
|
key={i}
|
|
@@ -39,7 +79,7 @@ export function CropOverlay() {
|
|
|
39
79
|
/>
|
|
40
80
|
))}
|
|
41
81
|
|
|
42
|
-
{
|
|
82
|
+
{showHandles &&
|
|
43
83
|
(() => {
|
|
44
84
|
let [tl, tr, br, bl] = activeCorners;
|
|
45
85
|
let s = scale;
|
|
@@ -90,30 +130,36 @@ export function CropOverlay() {
|
|
|
90
130
|
})()}
|
|
91
131
|
</div>
|
|
92
132
|
|
|
93
|
-
{
|
|
133
|
+
{/* Status line. OpenCV only powers the border suggestion, so a load failure is
|
|
134
|
+
informational — cropping stays available either way. */}
|
|
135
|
+
{cropping ? (
|
|
94
136
|
<div className="crop-loading">
|
|
95
137
|
<Spinner aria-hidden data-size="xs" />
|
|
96
|
-
<Paragraph data-size="sm">{getLocalizedString("Loading OpenCV…")}</Paragraph>
|
|
97
138
|
</div>
|
|
98
|
-
)
|
|
99
|
-
{cvError && (
|
|
139
|
+
) : error ? (
|
|
100
140
|
<div className="crop-loading">
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
141
|
+
<Paragraph data-size="sm">{error}</Paragraph>
|
|
142
|
+
</div>
|
|
143
|
+
) : mode === "rect" ? (
|
|
144
|
+
<div className="crop-loading">
|
|
145
|
+
<Paragraph data-size="sm">
|
|
146
|
+
{hasSelection
|
|
147
|
+
? getLocalizedString("Release to use this rectangle")
|
|
148
|
+
: getLocalizedString("Drag to draw a rectangle to crop to")}
|
|
149
|
+
</Paragraph>
|
|
150
|
+
</div>
|
|
151
|
+
) : !cvReady && !cvError ? (
|
|
152
|
+
<div className="crop-loading">
|
|
153
|
+
<Spinner aria-hidden data-size="xs" />
|
|
154
|
+
<Paragraph data-size="sm">{getLocalizedString("Detecting borders…")}</Paragraph>
|
|
104
155
|
</div>
|
|
105
|
-
)
|
|
106
|
-
{(error || cropping) && (
|
|
156
|
+
) : cvError ? (
|
|
107
157
|
<div className="crop-loading">
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
<Alert data-color="danger" data-size="sm">
|
|
112
|
-
{error}
|
|
113
|
-
</Alert>
|
|
114
|
-
)}
|
|
158
|
+
<Paragraph data-size="sm">
|
|
159
|
+
{getLocalizedString("Automatic border detection is unavailable. Adjust the selection manually.")}
|
|
160
|
+
</Paragraph>
|
|
115
161
|
</div>
|
|
116
|
-
)}
|
|
162
|
+
) : null}
|
|
117
163
|
</div>
|
|
118
164
|
);
|
|
119
165
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Button, Spinner } from "@digdir/designsystemet-react";
|
|
2
|
-
import { CheckmarkIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
2
|
+
import { CheckmarkIcon, ExpandIcon, SquareIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
3
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
4
|
|
|
5
5
|
import { useCropContext } from "./CropContext.js";
|
|
6
6
|
|
|
7
7
|
/** Toolbar shown while the crop tool is active. Reads state from CropContext. */
|
|
8
8
|
export function CropToolbar() {
|
|
9
|
-
let { applyCrop, cropping,
|
|
9
|
+
let { applyCrop, cropping, mode, hasSelection, startRectMode, cancelRectMode, onApply, onCancel } = useCropContext();
|
|
10
|
+
let inRectMode = mode === "rect";
|
|
10
11
|
|
|
11
12
|
async function handleApply() {
|
|
12
13
|
let result = await applyCrop();
|
|
@@ -22,7 +23,22 @@ export function CropToolbar() {
|
|
|
22
23
|
</Button>
|
|
23
24
|
</div>
|
|
24
25
|
<div className="image-editor__toolbar-group">
|
|
25
|
-
<Button
|
|
26
|
+
<Button
|
|
27
|
+
variant="tertiary"
|
|
28
|
+
data-size="sm"
|
|
29
|
+
aria-pressed={inRectMode}
|
|
30
|
+
onClick={inRectMode ? cancelRectMode : startRectMode}
|
|
31
|
+
disabled={cropping}
|
|
32
|
+
>
|
|
33
|
+
{inRectMode ? <ExpandIcon aria-hidden /> : <SquareIcon aria-hidden />}
|
|
34
|
+
{inRectMode ? getLocalizedString("Adjust corners") : getLocalizedString("Draw rectangle")}
|
|
35
|
+
</Button>
|
|
36
|
+
<Button
|
|
37
|
+
variant="primary"
|
|
38
|
+
data-size="sm"
|
|
39
|
+
onClick={handleApply}
|
|
40
|
+
disabled={cropping || inRectMode || !hasSelection}
|
|
41
|
+
>
|
|
26
42
|
{cropping ? <Spinner aria-hidden data-size="xs" /> : <CheckmarkIcon aria-hidden />}
|
|
27
43
|
{getLocalizedString("Apply crop")}
|
|
28
44
|
</Button>
|