@olenbetong/synergi-react 5.1.0 → 5.3.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/dist/styles/styles.css +1 -1
- package/dist/styles/styles.css.map +1 -1
- package/es/components/Checkbox/index.css +1 -1
- package/es/components/ColorCard/index.css +17 -28
- package/es/components/DateNavigator/index.css +5 -7
- package/es/components/ImageEditor/ImageEditor.css +10 -10
- package/es/components/ImageEditor/ImageEditor.d.ts +18 -1
- package/es/components/ImageEditor/ImageEditor.js +30 -13
- package/es/components/ImageEditor/ResponsiveButton.js +2 -2
- package/es/components/ImageEditor/encodeImage.d.ts +33 -0
- package/es/components/ImageEditor/encodeImage.js +60 -0
- package/es/components/ImageEditor/index.d.ts +2 -0
- package/es/components/ImageEditor/index.js +1 -0
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +1 -1
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +3 -9
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +1 -1
- package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +3 -4
- package/es/components/ImageEditor/plugins/rotatePlugin.js +2 -1
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +3 -3
- package/es/components/PageBanner/index.css +1 -1
- package/es/components/PdfViewer/PdfViewer.js +1 -1
- package/es/components/Spinner/index.css +1 -1
- package/es/components/SplitContainer/index.css +1 -1
- package/es/components/ValueToggleGroup/index.css +2 -2
- package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +7 -7
- package/es/elements-ds/ElementLookupDialog.js +1 -1
- package/es/improve/ReportIssueAttachments.d.ts +6 -0
- package/es/improve/ReportIssueAttachments.js +45 -0
- package/es/improve/ReportIssueForm.css +133 -0
- package/es/improve/ReportIssueForm.d.ts +18 -0
- package/es/improve/ReportIssueForm.js +71 -0
- package/es/improve/data/dsReportIssueAreas.d.ts +8 -0
- package/es/improve/data/dsReportIssueAreas.js +37 -0
- package/es/improve/data/dsReportIssueFiles.d.ts +15 -0
- package/es/improve/data/dsReportIssueFiles.js +55 -0
- package/es/improve/data/index.d.ts +3 -0
- package/es/improve/data/index.js +3 -0
- package/es/improve/data/procReportIssue.d.ts +16 -0
- package/es/improve/data/procReportIssue.js +44 -0
- package/es/improve/index.d.ts +3 -0
- package/es/improve/index.js +3 -0
- package/es/index.css +1 -1
- package/package.json +7 -3
- package/src/components/Checkbox/index.scss +2 -2
- package/src/components/ColorCard/index.css +17 -28
- package/src/components/DateNavigator/index.css +5 -7
- package/src/components/ImageEditor/ImageEditor.browser.test.tsx +30 -5
- package/src/components/ImageEditor/ImageEditor.css +10 -10
- package/src/components/ImageEditor/ImageEditor.test.tsx +4 -3
- package/src/components/ImageEditor/ImageEditor.tsx +47 -14
- package/src/components/ImageEditor/ResponsiveButton.tsx +2 -2
- package/src/components/ImageEditor/encodeImage.browser.test.ts +88 -0
- package/src/components/ImageEditor/encodeImage.ts +80 -0
- package/src/components/ImageEditor/index.ts +2 -0
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +2 -8
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +3 -10
- package/src/components/ImageEditor/plugins/plugins.browser.test.ts +20 -2
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +3 -3
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +3 -4
- package/src/components/ImageEditor/plugins/rotatePlugin.ts +2 -1
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +3 -3
- package/src/components/PageBanner/index.scss +10 -10
- package/src/components/PdfViewer/PdfViewer.tsx +1 -1
- package/src/components/Spinner/index.css +1 -1
- package/src/components/SplitContainer/index.scss +5 -1
- package/src/components/ValueToggleGroup/index.css +2 -2
- package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +7 -7
- package/src/elements-ds/ElementLookupDialog.tsx +1 -3
- package/src/improve/ReportIssueAttachments.tsx +138 -0
- package/src/improve/ReportIssueForm.css +133 -0
- package/src/improve/ReportIssueForm.tsx +218 -0
- package/src/improve/data/dsReportIssueAreas.ts +45 -0
- package/src/improve/data/dsReportIssueFiles.ts +66 -0
- package/src/improve/data/index.ts +3 -0
- package/src/improve/data/procReportIssue.ts +58 -0
- package/src/improve/index.ts +3 -0
|
@@ -14,7 +14,7 @@ export function ResponsiveButton({ icon, label, onClick, disabled, isSmall }: Pr
|
|
|
14
14
|
if (isSmall) {
|
|
15
15
|
return (
|
|
16
16
|
<Tooltip content={label}>
|
|
17
|
-
<Button icon variant="tertiary"
|
|
17
|
+
<Button icon variant="tertiary" aria-label={label} onClick={onClick} disabled={disabled}>
|
|
18
18
|
{icon}
|
|
19
19
|
</Button>
|
|
20
20
|
</Tooltip>
|
|
@@ -22,7 +22,7 @@ export function ResponsiveButton({ icon, label, onClick, disabled, isSmall }: Pr
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
return (
|
|
25
|
-
<Button variant="tertiary"
|
|
25
|
+
<Button variant="tertiary" onClick={onClick} disabled={disabled}>
|
|
26
26
|
{icon}
|
|
27
27
|
{label}
|
|
28
28
|
</Button>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { encodeImage, scaledSize } from "./encodeImage";
|
|
4
|
+
|
|
5
|
+
/** A noisy image, so its encoded size depends on the quality and resolution the way a photo's does. */
|
|
6
|
+
async function photo(width: number, height: number, type = "image/png", quality?: number) {
|
|
7
|
+
let canvas = document.createElement("canvas");
|
|
8
|
+
canvas.width = width;
|
|
9
|
+
canvas.height = height;
|
|
10
|
+
let ctx = canvas.getContext("2d")!;
|
|
11
|
+
let pixels = ctx.createImageData(width, height);
|
|
12
|
+
for (let i = 0; i < pixels.data.length; i += 4) {
|
|
13
|
+
let shade = 128 + ((i * 7919) % 97) - 48;
|
|
14
|
+
pixels.data[i] = shade;
|
|
15
|
+
pixels.data[i + 1] = shade;
|
|
16
|
+
pixels.data[i + 2] = shade;
|
|
17
|
+
pixels.data[i + 3] = 255;
|
|
18
|
+
}
|
|
19
|
+
ctx.putImageData(pixels, 0, 0);
|
|
20
|
+
return new Promise<Blob>((resolve) => canvas.toBlob((b) => resolve(b!), type, quality));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function size(blob: Blob) {
|
|
24
|
+
let bitmap = await createImageBitmap(blob);
|
|
25
|
+
let result = { width: bitmap.width, height: bitmap.height };
|
|
26
|
+
bitmap.close();
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("scaledSize", () => {
|
|
31
|
+
it("leaves an image within the limit, or without one, as it is", () => {
|
|
32
|
+
expect(scaledSize(1600, 1200, 4_000_000)).toEqual({ width: 1600, height: 1200 });
|
|
33
|
+
expect(scaledSize(8000, 6000)).toEqual({ width: 8000, height: 6000 });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("scales by pixel count, so a long, narrow receipt stays narrow", () => {
|
|
37
|
+
let { width, height } = scaledSize(1000, 8000, 4_000_000);
|
|
38
|
+
expect(width * height).toBeLessThanOrEqual(4_000_000);
|
|
39
|
+
expect(height / width).toBeCloseTo(8, 1);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("encodeImage", () => {
|
|
44
|
+
it("scales an image down to the pixel limit and encodes it as asked", async () => {
|
|
45
|
+
let result = await encodeImage(await photo(400, 300), { type: "image/jpeg", maxPixels: 30_000 });
|
|
46
|
+
|
|
47
|
+
expect(result.type).toBe("image/jpeg");
|
|
48
|
+
let { width, height } = await size(result);
|
|
49
|
+
expect(width * height).toBeLessThanOrEqual(30_000);
|
|
50
|
+
expect(width / height).toBeCloseTo(4 / 3, 1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("hands back an image of the right type and size untouched", async () => {
|
|
54
|
+
let source = await photo(200, 100, "image/jpeg", 0.8);
|
|
55
|
+
|
|
56
|
+
expect(await encodeImage(source, { type: "image/jpeg", maxPixels: 30_000 })).toBe(source);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("re-encodes an image of the right type that is larger than maxBytes", async () => {
|
|
60
|
+
let source = await photo(200, 100, "image/jpeg", 1);
|
|
61
|
+
|
|
62
|
+
let result = await encodeImage(source, { type: "image/jpeg", quality: 0.5, maxBytes: 1000 });
|
|
63
|
+
|
|
64
|
+
expect(result).not.toBe(source);
|
|
65
|
+
expect(result.size).toBeLessThan(source.size);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("puts transparent areas on white when encoding JPEG", async () => {
|
|
69
|
+
let canvas = document.createElement("canvas");
|
|
70
|
+
canvas.width = 10;
|
|
71
|
+
canvas.height = 10;
|
|
72
|
+
let png = await new Promise<Blob>((resolve) => canvas.toBlob((b) => resolve(b!), "image/png"));
|
|
73
|
+
|
|
74
|
+
let result = await encodeImage(png, { type: "image/jpeg" });
|
|
75
|
+
|
|
76
|
+
let bitmap = await createImageBitmap(result);
|
|
77
|
+
let ctx = document.createElement("canvas").getContext("2d")!;
|
|
78
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
79
|
+
let [r, g, b] = ctx.getImageData(5, 5, 1, 1).data;
|
|
80
|
+
expect(Math.min(r, g, b)).toBeGreaterThan(245);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("hands back a file it cannot decode untouched", async () => {
|
|
84
|
+
let notAnImage = new Blob(["not an image"], { type: "image/heic" });
|
|
85
|
+
|
|
86
|
+
expect(await encodeImage(notAnImage, { type: "image/jpeg", maxPixels: 100 })).toBe(notAnImage);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Edits are kept lossless between steps; this is the type every tool and replay handler produces. */
|
|
2
|
+
export const INTERMEDIATE_TYPE = "image/png";
|
|
3
|
+
|
|
4
|
+
/** Encodes a canvas without loss, for the editor's intermediate images. */
|
|
5
|
+
export function canvasToIntermediateBlob(canvas: HTMLCanvasElement): Promise<Blob> {
|
|
6
|
+
return new Promise<Blob>((resolve, reject) => {
|
|
7
|
+
canvas.toBlob((b) => (b ? resolve(b) : reject(new Error("toBlob failed"))), INTERMEDIATE_TYPE);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ImageOutputOptions = {
|
|
12
|
+
/** The type to hand the image out in (default `"image/jpeg"`). */
|
|
13
|
+
type?: string;
|
|
14
|
+
/** Quality for a lossy type, 0-1 (default 0.92). */
|
|
15
|
+
quality?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Scales the image down to at most this many pixels, keeping its aspect ratio. A pixel count rather
|
|
18
|
+
* than a long edge, so a long, narrow receipt keeps the same text resolution as a square photo.
|
|
19
|
+
*/
|
|
20
|
+
maxPixels?: number;
|
|
21
|
+
/**
|
|
22
|
+
* An image already of `type` and within `maxPixels` is still re-encoded when its file is larger than
|
|
23
|
+
* this (a phone JPEG saved at quality 95+, say). The original is kept if that comes out no smaller.
|
|
24
|
+
*/
|
|
25
|
+
maxBytes?: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** The size to draw an image at so it holds at most `maxPixels`, keeping its aspect ratio. */
|
|
29
|
+
export function scaledSize(width: number, height: number, maxPixels?: number): { width: number; height: number } {
|
|
30
|
+
let pixels = width * height;
|
|
31
|
+
if (!maxPixels || pixels <= maxPixels) return { width, height };
|
|
32
|
+
let scale = Math.sqrt(maxPixels / pixels);
|
|
33
|
+
return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Encodes an image once, as the caller asked. Lossy formats are applied here and nowhere else, so a
|
|
38
|
+
* chain of edits (or an undo/redo replay) never stacks one JPEG generation on another.
|
|
39
|
+
*
|
|
40
|
+
* An image already of the requested type, within `maxPixels` and within `maxBytes` is returned untouched,
|
|
41
|
+
* as is one the browser cannot decode (HEIC outside Safari, for instance), so the caller never loses the file.
|
|
42
|
+
*/
|
|
43
|
+
export async function encodeImage(blob: Blob, options: ImageOutputOptions = {}): Promise<Blob> {
|
|
44
|
+
let { type = "image/jpeg", quality = 0.92, maxPixels, maxBytes } = options;
|
|
45
|
+
|
|
46
|
+
let bitmap: ImageBitmap;
|
|
47
|
+
try {
|
|
48
|
+
// Applies the EXIF orientation, which the encoded image then no longer needs.
|
|
49
|
+
bitmap = await createImageBitmap(blob, { imageOrientation: "from-image" });
|
|
50
|
+
} catch {
|
|
51
|
+
return blob;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
let size = scaledSize(bitmap.width, bitmap.height, maxPixels);
|
|
56
|
+
let resized = size.width !== bitmap.width || size.height !== bitmap.height;
|
|
57
|
+
let sameType = blob.type === type;
|
|
58
|
+
if (!resized && sameType && (maxBytes === undefined || blob.size <= maxBytes)) return blob;
|
|
59
|
+
|
|
60
|
+
let canvas = document.createElement("canvas");
|
|
61
|
+
canvas.width = size.width;
|
|
62
|
+
canvas.height = size.height;
|
|
63
|
+
let ctx = canvas.getContext("2d")!;
|
|
64
|
+
if (type === "image/jpeg") {
|
|
65
|
+
// JPEG has no transparency: put transparent areas on white instead of black.
|
|
66
|
+
ctx.fillStyle = "#fff";
|
|
67
|
+
ctx.fillRect(0, 0, size.width, size.height);
|
|
68
|
+
}
|
|
69
|
+
ctx.imageSmoothingQuality = "high";
|
|
70
|
+
ctx.drawImage(bitmap, 0, 0, size.width, size.height);
|
|
71
|
+
|
|
72
|
+
let encoded = await new Promise<Blob>((resolve, reject) => {
|
|
73
|
+
canvas.toBlob((b) => (b ? resolve(b) : reject(new Error("toBlob failed"))), type, quality);
|
|
74
|
+
});
|
|
75
|
+
// Re-encoded only for its size: no point handing out a file that did not shrink.
|
|
76
|
+
return !resized && sameType && encoded.size >= blob.size ? blob : encoded;
|
|
77
|
+
} finally {
|
|
78
|
+
bitmap.close();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { defaultPlugins, defaultViewPlugin } from "./defaultPlugins.js";
|
|
2
2
|
export type { ImageEditorRef } from "./ImageEditor.js";
|
|
3
3
|
export { ImageEditor } from "./ImageEditor.js";
|
|
4
|
+
export type { ImageOutputOptions } from "./encodeImage.js";
|
|
5
|
+
export { encodeImage, scaledSize } from "./encodeImage.js";
|
|
4
6
|
export { cropPlugin } from "./plugins/cropPlugin/index.js";
|
|
5
7
|
export { redactPlugin } from "./plugins/redactPlugin/index.js";
|
|
6
8
|
export { zoomPlugin } from "./plugins/zoomPlugin/index.js";
|
|
@@ -17,7 +17,7 @@ export function CropToolbar() {
|
|
|
17
17
|
return (
|
|
18
18
|
<>
|
|
19
19
|
<div className="image-editor__toolbar-group">
|
|
20
|
-
<Button variant="tertiary"
|
|
20
|
+
<Button variant="tertiary" onClick={onCancel} disabled={cropping}>
|
|
21
21
|
<XMarkIcon aria-hidden />
|
|
22
22
|
{getLocalizedString("Cancel")}
|
|
23
23
|
</Button>
|
|
@@ -25,7 +25,6 @@ export function CropToolbar() {
|
|
|
25
25
|
<div className="image-editor__toolbar-group">
|
|
26
26
|
<Button
|
|
27
27
|
variant="tertiary"
|
|
28
|
-
data-size="sm"
|
|
29
28
|
aria-pressed={inRectMode}
|
|
30
29
|
onClick={inRectMode ? cancelRectMode : startRectMode}
|
|
31
30
|
disabled={cropping}
|
|
@@ -33,12 +32,7 @@ export function CropToolbar() {
|
|
|
33
32
|
{inRectMode ? <ExpandIcon aria-hidden /> : <SquareIcon aria-hidden />}
|
|
34
33
|
{inRectMode ? getLocalizedString("Adjust corners") : getLocalizedString("Draw rectangle")}
|
|
35
34
|
</Button>
|
|
36
|
-
<Button
|
|
37
|
-
variant="primary"
|
|
38
|
-
data-size="sm"
|
|
39
|
-
onClick={handleApply}
|
|
40
|
-
disabled={cropping || inRectMode || !hasSelection}
|
|
41
|
-
>
|
|
35
|
+
<Button variant="primary" onClick={handleApply} disabled={cropping || inRectMode || !hasSelection}>
|
|
42
36
|
{cropping ? <Spinner aria-hidden data-size="xs" /> : <CheckmarkIcon aria-hidden />}
|
|
43
37
|
{getLocalizedString("Apply crop")}
|
|
44
38
|
</Button>
|
|
@@ -4,6 +4,7 @@ import type { CropCanvasHandle } from "../../CropCanvas.js";
|
|
|
4
4
|
import type { EditAction } from "../../types.js";
|
|
5
5
|
import { fullImageQuad, type Point, type Quad, useEdgeDetection } from "../../useEdgeDetection.js";
|
|
6
6
|
import { loadOpenCV, useOpenCV } from "../../useOpenCV.js";
|
|
7
|
+
import { canvasToIntermediateBlob } from "../../encodeImage.js";
|
|
7
8
|
|
|
8
9
|
export interface ApplyCropResult {
|
|
9
10
|
blob: Blob;
|
|
@@ -335,7 +336,7 @@ async function rectCropAtFullResolution(imageUrl: string, relCorners: Quad): Pro
|
|
|
335
336
|
canvas.height = height;
|
|
336
337
|
canvas.getContext("2d")!.drawImage(img, x, y, width, height, 0, 0, width, height);
|
|
337
338
|
|
|
338
|
-
return
|
|
339
|
+
return canvasToIntermediateBlob(canvas);
|
|
339
340
|
}
|
|
340
341
|
|
|
341
342
|
function loadImage(url: string): Promise<HTMLImageElement> {
|
|
@@ -347,14 +348,6 @@ function loadImage(url: string): Promise<HTMLImageElement> {
|
|
|
347
348
|
});
|
|
348
349
|
}
|
|
349
350
|
|
|
350
|
-
function canvasToPngBlob(canvas: HTMLCanvasElement): Promise<Blob> {
|
|
351
|
-
return new Promise<Blob>((resolve, reject) => {
|
|
352
|
-
// PNG is lossless — critical for receipts and screenshots where JPEG
|
|
353
|
-
// compression would make text unreadable.
|
|
354
|
-
canvas.toBlob((b) => (b ? resolve(b) : reject(new Error("toBlob failed"))), "image/png");
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
351
|
/** Loads the image at native resolution, maps relative corners, and warps. */
|
|
359
352
|
// oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js types
|
|
360
353
|
async function cropImageAtFullResolution(cv: any, imageUrl: string, relCorners: Quad): Promise<Blob> {
|
|
@@ -388,7 +381,7 @@ function perspectiveCrop(cv: any, srcCanvas: HTMLCanvasElement, corners: Quad):
|
|
|
388
381
|
cv.imshow(outCanvas, dst);
|
|
389
382
|
for (let m of [src, dst, srcPts, dstPts, M]) m.delete();
|
|
390
383
|
|
|
391
|
-
return
|
|
384
|
+
return canvasToIntermediateBlob(outCanvas);
|
|
392
385
|
}
|
|
393
386
|
|
|
394
387
|
/**
|
|
@@ -127,10 +127,28 @@ describe("rotate", () => {
|
|
|
127
127
|
expectColour(bl, RED);
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
-
it("
|
|
130
|
+
it("keeps its result lossless, as PNG", async () => {
|
|
131
131
|
let blob = await rotateCwPlugin.execute(await quadrantImage());
|
|
132
132
|
|
|
133
|
-
expect(blob.type).toBe("image/
|
|
133
|
+
expect(blob.type).toBe("image/png");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("gives back the original pixels after four quarter turns", async () => {
|
|
137
|
+
// The editor chains every edit on the previous result: a lossy step would compound here.
|
|
138
|
+
let source = await stripedImage(80, 40);
|
|
139
|
+
let url = source;
|
|
140
|
+
for (let i = 0; i < 4; i++) {
|
|
141
|
+
url = objectUrl(await rotateCwPlugin.execute(url));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let before = await read(await (await fetch(source)).blob());
|
|
145
|
+
let after = await read(await (await fetch(url)).blob());
|
|
146
|
+
expect([after.width, after.height]).toEqual([before.width, before.height]);
|
|
147
|
+
for (let y = 0; y < before.height; y++) {
|
|
148
|
+
for (let x = 0; x < before.width; x++) {
|
|
149
|
+
expect(after.pixel(x, y)).toEqual(before.pixel(x, y));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
134
152
|
});
|
|
135
153
|
|
|
136
154
|
it("rejects when the image cannot be loaded", async () => {
|
|
@@ -27,17 +27,17 @@ export function RedactToolbar() {
|
|
|
27
27
|
return (
|
|
28
28
|
<>
|
|
29
29
|
<div className="image-editor__toolbar-group">
|
|
30
|
-
<Button variant="tertiary"
|
|
30
|
+
<Button variant="tertiary" onClick={onCancel} disabled={applying}>
|
|
31
31
|
<XMarkIcon aria-hidden />
|
|
32
32
|
{getLocalizedString("Cancel")}
|
|
33
33
|
</Button>
|
|
34
|
-
<Button variant="tertiary"
|
|
34
|
+
<Button variant="tertiary" onClick={clearAll} disabled={applying || rects.length === 0}>
|
|
35
35
|
<EraserIcon aria-hidden />
|
|
36
36
|
{getLocalizedString("Clear all")}
|
|
37
37
|
</Button>
|
|
38
38
|
</div>
|
|
39
39
|
<div className="image-editor__toolbar-group">
|
|
40
|
-
<Button variant="primary"
|
|
40
|
+
<Button variant="primary" onClick={handleApply} disabled={applying}>
|
|
41
41
|
{applying ? <Spinner aria-hidden data-size="xs" /> : <CheckmarkIcon aria-hidden />}
|
|
42
42
|
{rects.length === 0 ? getLocalizedString("Done") : getLocalizedString("Apply redact")}
|
|
43
43
|
</Button>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useRef, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import type { EditAction } from "../../types.js";
|
|
4
|
+
import { canvasToIntermediateBlob } from "../../encodeImage.js";
|
|
4
5
|
|
|
5
6
|
export interface RedactRect {
|
|
6
7
|
x: number;
|
|
@@ -100,9 +101,7 @@ export function useRedactTool(imageUrl: string): RedactToolState {
|
|
|
100
101
|
blurRegionOnCanvas(ctx, img, nx, ny, nw, nh);
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
let blob = await
|
|
104
|
-
canvas.toBlob((b) => (b ? resolve(b) : reject(new Error("toBlob failed"))), "image/jpeg", 0.92);
|
|
105
|
-
});
|
|
104
|
+
let blob = await canvasToIntermediateBlob(canvas);
|
|
106
105
|
// Store natural-pixel coords so replay doesn't need display size.
|
|
107
106
|
let actions: EditAction[] = rects.map((r) => ({
|
|
108
107
|
type: "redact-blur",
|
|
@@ -152,7 +151,7 @@ export function replayRedactBlur(imageUrl: string, params: Record<string, unknow
|
|
|
152
151
|
let ctx = canvas.getContext("2d")!;
|
|
153
152
|
ctx.drawImage(img, 0, 0);
|
|
154
153
|
blurRegionOnCanvas(ctx, img, x, y, w, h);
|
|
155
|
-
canvas.
|
|
154
|
+
canvasToIntermediateBlob(canvas).then(resolve, reject);
|
|
156
155
|
};
|
|
157
156
|
img.onerror = () => reject(new Error("Failed to load image for redact replay"));
|
|
158
157
|
img.src = imageUrl;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RotateLeftIcon, RotateRightIcon } from "@navikt/aksel-icons";
|
|
2
2
|
|
|
3
|
+
import { canvasToIntermediateBlob } from "../encodeImage.js";
|
|
3
4
|
import type { ActionPlugin } from "../types.js";
|
|
4
5
|
|
|
5
6
|
function rotateBlob(imageUrl: string, direction: "cw" | "ccw"): Promise<Blob> {
|
|
@@ -18,7 +19,7 @@ function rotateBlob(imageUrl: string, direction: "cw" | "ccw"): Promise<Blob> {
|
|
|
18
19
|
ctx.rotate(-Math.PI / 2);
|
|
19
20
|
}
|
|
20
21
|
ctx.drawImage(img, 0, 0);
|
|
21
|
-
canvas.
|
|
22
|
+
canvasToIntermediateBlob(canvas).then(resolve, reject);
|
|
22
23
|
};
|
|
23
24
|
img.onerror = () => reject(new Error("Failed to load image"));
|
|
24
25
|
img.src = imageUrl;
|
|
@@ -27,7 +27,7 @@ export function MergeProgressDialogDs(props: MergeProgressDialogDsProps) {
|
|
|
27
27
|
{(phase.kind === "preparing" || phase.kind === "processing") && (
|
|
28
28
|
<LinearProgress
|
|
29
29
|
value={phase.kind === "processing" && phase.total > 0 ? pct : undefined}
|
|
30
|
-
style={{ marginBottom: "
|
|
30
|
+
style={{ marginBottom: "var(--ds-size-3)" }}
|
|
31
31
|
/>
|
|
32
32
|
)}
|
|
33
33
|
|
|
@@ -49,7 +49,7 @@ export function MergeProgressDialogDs(props: MergeProgressDialogDsProps) {
|
|
|
49
49
|
title={phase.currentFile}
|
|
50
50
|
style={{
|
|
51
51
|
...subtle,
|
|
52
|
-
marginTop: "
|
|
52
|
+
marginTop: "var(--ds-size-1)",
|
|
53
53
|
overflow: "hidden",
|
|
54
54
|
textOverflow: "ellipsis",
|
|
55
55
|
whiteSpace: "nowrap",
|
|
@@ -66,7 +66,7 @@ export function MergeProgressDialogDs(props: MergeProgressDialogDsProps) {
|
|
|
66
66
|
<Paragraph data-size="sm" style={{ color: "var(--ds-color-success-text-default)" }}>
|
|
67
67
|
{getLocalizedString("Download started. You can close this dialog.")}
|
|
68
68
|
</Paragraph>
|
|
69
|
-
<Paragraph data-size="sm" style={{ ...subtle, marginTop: "
|
|
69
|
+
<Paragraph data-size="sm" style={{ ...subtle, marginTop: "var(--ds-size-2)" }}>
|
|
70
70
|
{getLocalizedString("If the file did not open automatically, ")}{" "}
|
|
71
71
|
<Link href={`/api/ob/merger/download/${phase.jobId}`} target="_blank" rel="noopener noreferrer">
|
|
72
72
|
{getLocalizedString("click here to open it")}
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
.ObPageBanner-plantTitle {
|
|
26
|
-
font-size: 2rem;
|
|
26
|
+
font-size: var(--ds-font-size-7, 2rem);
|
|
27
27
|
|
|
28
28
|
@media screen and (min-width: variables.$screen-lg) {
|
|
29
|
-
font-size: 3rem;
|
|
29
|
+
font-size: var(--ds-font-size-9, 3rem);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
@media screen and (min-width: variables.$screen-sm) {
|
|
43
43
|
align-self: center;
|
|
44
44
|
margin: 0;
|
|
45
|
-
margin-right: 1rem;
|
|
45
|
+
margin-right: var(--ds-size-4, 1rem);
|
|
46
46
|
border: 0.4rem solid white;
|
|
47
47
|
border-radius: 50%;
|
|
48
48
|
height: 150px;
|
|
@@ -56,16 +56,16 @@
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
.ObPageBanner-bannerTitle {
|
|
59
|
-
margin-bottom: 1rem;
|
|
60
|
-
margin-top: 1rem;
|
|
61
|
-
font-size: 2rem;
|
|
59
|
+
margin-bottom: var(--ds-size-4, 1rem);
|
|
60
|
+
margin-top: var(--ds-size-4, 1rem);
|
|
61
|
+
font-size: var(--ds-font-size-7, 2rem);
|
|
62
62
|
|
|
63
63
|
@media screen and (min-width: variables.$screen-md) {
|
|
64
64
|
margin-top: 0;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
@media screen and (min-width: variables.$screen-lg) {
|
|
68
|
-
font-size: 3rem;
|
|
68
|
+
font-size: var(--ds-font-size-9, 3rem);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -87,9 +87,9 @@
|
|
|
87
87
|
.ObPageBanner-tab {
|
|
88
88
|
border-bottom: 0.25rem solid transparent;
|
|
89
89
|
display: inline-block;
|
|
90
|
-
margin-top: 0.5rem;
|
|
91
|
-
min-width:
|
|
92
|
-
padding: 0.5rem 1rem;
|
|
90
|
+
margin-top: var(--ds-size-2, 0.5rem);
|
|
91
|
+
min-width: calc(var(--ds-size-8, 2rem) * 4);
|
|
92
|
+
padding: var(--ds-size-2, 0.5rem) var(--ds-size-4, 1rem);
|
|
93
93
|
text-align: center;
|
|
94
94
|
text-transform: capitalize;
|
|
95
95
|
|
|
@@ -152,7 +152,7 @@ export function PdfViewer({ url, file }: PdfViewerProps) {
|
|
|
152
152
|
))}
|
|
153
153
|
</Document>
|
|
154
154
|
</div>
|
|
155
|
-
{error && <div style={{ color: "#b00020", padding:
|
|
155
|
+
{error && <div style={{ color: "#b00020", padding: "var(--ds-size-2, 8px)" }}>Error loading PDF: {error}</div>}
|
|
156
156
|
</div>
|
|
157
157
|
);
|
|
158
158
|
}
|
|
@@ -20,9 +20,13 @@ Hacky solution to sass output for some reason getting a zero-width space at the
|
|
|
20
20
|
overflow: hidden;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// Sized from the Designsystemet size mode, so the gap and the grip shrink with the panels around
|
|
24
|
+
// them in an xs or sm form.
|
|
23
25
|
.ObSplitContainer-divider {
|
|
24
|
-
flex: 0 0 0.5rem;
|
|
26
|
+
flex: 0 0 var(--ds-size-2, 0.5rem);
|
|
25
27
|
background-color: transparent;
|
|
28
|
+
color: var(--ds-color-neutral-text-subtle, currentColor);
|
|
29
|
+
font-size: var(--ds-font-size-2, 0.875rem);
|
|
26
30
|
line-height: 0.75;
|
|
27
31
|
cursor: ns-resize;
|
|
28
32
|
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
.ObValueToggleGroup {
|
|
20
|
-
padding: 0.25rem;
|
|
20
|
+
padding: var(--ds-size-1, 0.25rem);
|
|
21
21
|
border: 2px solid rgb(0 0 0 / 0.2);
|
|
22
22
|
border-radius: 4px;
|
|
23
23
|
|
|
24
24
|
display: flex;
|
|
25
|
-
gap: 0.25rem;
|
|
25
|
+
gap: var(--ds-size-1, 0.25rem);
|
|
26
26
|
flex-wrap: wrap;
|
|
27
27
|
|
|
28
28
|
&.vertical {
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
display: flex;
|
|
25
25
|
align-items: center;
|
|
26
26
|
justify-content: space-between;
|
|
27
|
-
padding: 0.5rem 1.5rem;
|
|
27
|
+
padding: var(--ds-size-2, 0.5rem) var(--ds-size-6, 1.5rem);
|
|
28
28
|
color: white;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
.ob-barcode-scanner__actions {
|
|
32
32
|
display: flex;
|
|
33
33
|
align-items: center;
|
|
34
|
-
gap: 0.5rem;
|
|
34
|
+
gap: var(--ds-size-2, 0.5rem);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
.ob-barcode-scanner__engine {
|
|
38
|
-
font-size: 0.75rem;
|
|
38
|
+
font-size: var(--ds-font-size-1, 0.75rem);
|
|
39
39
|
opacity: 0.7;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
display: inline-flex;
|
|
44
44
|
align-items: center;
|
|
45
45
|
justify-content: center;
|
|
46
|
-
padding: 0.75rem;
|
|
46
|
+
padding: var(--ds-size-3, 0.75rem);
|
|
47
47
|
border: 0;
|
|
48
48
|
border-radius: 50%;
|
|
49
49
|
background: transparent;
|
|
50
50
|
color: inherit;
|
|
51
|
-
font-size: 1.75rem;
|
|
51
|
+
font-size: var(--ds-font-size-7, 1.75rem);
|
|
52
52
|
cursor: pointer;
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
.ob-barcode-scanner__error-icon {
|
|
78
|
-
margin: 1rem 0;
|
|
78
|
+
margin: var(--ds-size-4, 1rem) 0;
|
|
79
79
|
color: #eee;
|
|
80
|
-
font-size: 3.5rem;
|
|
80
|
+
font-size: var(--ds-font-size-10, 3.5rem);
|
|
81
81
|
}
|
|
@@ -150,9 +150,7 @@ export function ElementLookupDialog(props: ElementLookupDialogProps) {
|
|
|
150
150
|
</div>
|
|
151
151
|
)}
|
|
152
152
|
<div className="ObElementsLookupDialog-list">
|
|
153
|
-
{props.mode === "multi" &&
|
|
154
|
-
<Alert data-color="info" data-size="sm">{localize`${elements.length} elements selected`}</Alert>
|
|
155
|
-
)}
|
|
153
|
+
{props.mode === "multi" && <Alert data-color="info">{localize`${elements.length} elements selected`}</Alert>}
|
|
156
154
|
<ItemList>
|
|
157
155
|
{elements.map(({ element }) => (
|
|
158
156
|
<ItemList.Item
|