@olenbetong/synergi-react 2.9.0 → 3.0.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 (113) hide show
  1. package/es/chrome/AppShell/index.d.ts +8 -0
  2. package/es/chrome/AppShell/index.js +10 -130
  3. package/es/components/ImageEditor/ImageEditor.css +10 -0
  4. package/es/components/ImageEditor/index.d.ts +1 -0
  5. package/es/components/ImageEditor/index.js +1 -0
  6. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
  7. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
  8. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
  9. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
  10. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
  11. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
  12. package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
  13. package/es/components/ImageEditor/useEdgeDetection.js +11 -30
  14. package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
  15. package/es/components/ImageEditor/useOpenCV.js +108 -42
  16. package/es/components/SplitContainer/index.js +2 -4
  17. package/es/filter/ChipListInput.d.ts +13 -0
  18. package/es/filter/ChipListInput.js +34 -0
  19. package/es/filter/FilterBuilder.css +152 -0
  20. package/es/filter/FilterBuilder.d.ts +115 -0
  21. package/es/filter/FilterBuilder.js +146 -0
  22. package/es/filter/FilterBuilder.test.d.ts +1 -0
  23. package/es/filter/FilterBuilder.test.js +120 -0
  24. package/es/filter/FilterEditor.css +231 -0
  25. package/es/filter/FilterEditor.d.ts +17 -0
  26. package/es/filter/FilterEditor.js +38 -0
  27. package/es/filter/FilterEditor.test.d.ts +1 -0
  28. package/es/filter/FilterEditor.test.js +183 -0
  29. package/es/filter/FilterGroupEditor.d.ts +22 -0
  30. package/es/filter/FilterGroupEditor.js +34 -0
  31. package/es/filter/FilterNameDialog.css +22 -0
  32. package/es/filter/FilterNameDialog.d.ts +18 -0
  33. package/es/filter/FilterNameDialog.js +32 -0
  34. package/es/filter/FilterRow.d.ts +14 -0
  35. package/es/filter/FilterRow.js +32 -0
  36. package/es/filter/FilterShareDialog.css +28 -0
  37. package/es/filter/FilterShareDialog.d.ts +23 -0
  38. package/es/filter/FilterShareDialog.js +63 -0
  39. package/es/filter/FilterStringField.d.ts +15 -0
  40. package/es/filter/FilterStringField.js +37 -0
  41. package/es/filter/FilterValueEditor.d.ts +16 -0
  42. package/es/filter/FilterValueEditor.js +85 -0
  43. package/es/filter/SavedFilterTree.css +107 -0
  44. package/es/filter/SavedFilterTree.d.ts +45 -0
  45. package/es/filter/SavedFilterTree.js +44 -0
  46. package/es/filter/SavedFilterTree.test.d.ts +1 -0
  47. package/es/filter/SavedFilterTree.test.js +75 -0
  48. package/es/filter/index.d.ts +11 -0
  49. package/es/filter/index.js +10 -0
  50. package/es/filter/types.d.ts +34 -0
  51. package/es/filter/types.js +1 -0
  52. package/es/index.d.ts +2 -1
  53. package/es/index.js +6 -1
  54. package/es/mui/MuiThemeProvider.d.ts +24 -0
  55. package/es/mui/MuiThemeProvider.js +152 -0
  56. package/es/mui/index.d.ts +1 -0
  57. package/es/mui/index.js +1 -0
  58. package/es/report/ReportLauncher.css +147 -0
  59. package/es/report/ReportLauncher.d.ts +55 -0
  60. package/es/report/ReportLauncher.js +142 -0
  61. package/es/report/ReportLauncher.test.d.ts +1 -0
  62. package/es/report/ReportLauncher.test.js +231 -0
  63. package/es/report/ReportParameters.css +29 -0
  64. package/es/report/ReportParameters.d.ts +46 -0
  65. package/es/report/ReportParameters.js +65 -0
  66. package/es/report/ReportParameters.test.d.ts +1 -0
  67. package/es/report/ReportParameters.test.js +84 -0
  68. package/es/report/index.d.ts +2 -0
  69. package/es/report/index.js +2 -0
  70. package/es/test/setup.d.ts +1 -0
  71. package/es/test/setup.js +6 -0
  72. package/package.json +22 -7
  73. package/src/chrome/AppShell/index.tsx +34 -171
  74. package/src/components/ImageEditor/ImageEditor.css +10 -0
  75. package/src/components/ImageEditor/index.ts +1 -0
  76. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
  77. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
  78. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
  79. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
  80. package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
  81. package/src/components/ImageEditor/useOpenCV.ts +112 -62
  82. package/src/components/SplitContainer/index.tsx +3 -4
  83. package/src/filter/ChipListInput.tsx +79 -0
  84. package/src/filter/FilterBuilder.css +152 -0
  85. package/src/filter/FilterBuilder.test.tsx +153 -0
  86. package/src/filter/FilterBuilder.tsx +435 -0
  87. package/src/filter/FilterEditor.css +231 -0
  88. package/src/filter/FilterEditor.test.tsx +259 -0
  89. package/src/filter/FilterEditor.tsx +74 -0
  90. package/src/filter/FilterGroupEditor.tsx +160 -0
  91. package/src/filter/FilterNameDialog.css +22 -0
  92. package/src/filter/FilterNameDialog.tsx +81 -0
  93. package/src/filter/FilterRow.tsx +117 -0
  94. package/src/filter/FilterShareDialog.css +28 -0
  95. package/src/filter/FilterShareDialog.tsx +201 -0
  96. package/src/filter/FilterStringField.tsx +77 -0
  97. package/src/filter/FilterValueEditor.tsx +220 -0
  98. package/src/filter/SavedFilterTree.css +107 -0
  99. package/src/filter/SavedFilterTree.test.tsx +94 -0
  100. package/src/filter/SavedFilterTree.tsx +222 -0
  101. package/src/filter/index.ts +11 -0
  102. package/src/filter/types.ts +38 -0
  103. package/src/index.ts +39 -1
  104. package/src/mui/MuiThemeProvider.tsx +174 -0
  105. package/src/mui/index.ts +1 -0
  106. package/src/report/ReportLauncher.css +147 -0
  107. package/src/report/ReportLauncher.test.tsx +281 -0
  108. package/src/report/ReportLauncher.tsx +421 -0
  109. package/src/report/ReportParameters.css +29 -0
  110. package/src/report/ReportParameters.test.tsx +133 -0
  111. package/src/report/ReportParameters.tsx +198 -0
  112. package/src/report/index.ts +2 -0
  113. 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-mui";
6
- import { useCallback, useEffect, useMemo, useState } from "react";
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
- * Tracks the color scheme Designsystemet is rendering with. The article template
92
- * sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
93
- * OS preference (used when the scheme is `auto`).
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 (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(ThemeProvider, { theme: theme, children: _jsxs(AppErrorBoundary, { children: [appMenuSlot &&
226
- 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] }) }) }));
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 { Alert, Paragraph, Spinner } from "@digdir/designsystemet-react";
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
- return (_jsxs("div", { className: "crop-root", children: [_jsxs("div", { className: "crop-inner", children: [_jsx(CropCanvas, { ref: canvasRef, imageUrl: imageUrl, corners: activeCorners, onReady: handleCanvasReady }), displaySize.width > 0 &&
12
- 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))), displaySize.width > 0 &&
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
- })()] }), !cvReady && !cvError && (_jsxs("div", { className: "crop-loading", children: [_jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }), _jsx(Paragraph, { "data-size": "sm", children: getLocalizedString("Loading OpenCV…") })] })), cvError && (_jsx("div", { className: "crop-loading", children: _jsx(Alert, { "data-color": "danger", "data-size": "sm", children: getLocalizedString("Crop tool failed to load") }) })), (error || cropping) && (_jsx("div", { className: "crop-loading", children: cropping ? (_jsx(Spinner, { "aria-hidden": true, "data-size": "xs" })) : (_jsx(Alert, { "data-color": "danger", "data-size": "sm", children: error })) }))] }));
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, cvReady, cvError, onApply, onCancel } = useCropContext();
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")] }) }), _jsx("div", { className: "image-editor__toolbar-group", children: _jsxs(Button, { variant: "primary", "data-size": "sm", onClick: handleApply, disabled: cropping || !cvReady || !!cvError, children: [cropping ? _jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }) : _jsx(CheckmarkIcon, { "aria-hidden": true }), getLocalizedString("Apply crop")] }) })] }));
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 perspective crop tool.
27
- * Loads OpenCV lazily, runs edge detection, and performs the warp.
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>;