@olenbetong/synergi-react 4.1.1 → 4.1.2
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/components/ImageEditor/plugins/cropPlugin/useCropTool.js +3 -1
- package/es/components/ImageEditor/useEdgeDetection.d.ts +17 -2
- package/es/components/ImageEditor/useEdgeDetection.js +238 -61
- package/es/components/Toolbar/index.js +20 -1
- package/package.json +3 -3
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.ts +81 -81
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.tsx +312 -312
- package/src/components/ImageEditor/ImageEditor.tsx +343 -343
- package/src/components/ImageEditor/index.ts +9 -9
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -403
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/useEdgeDetection.ts +316 -127
- package/src/components/ImageEditor/useImageHistory.ts +197 -197
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/index.tsx +249 -249
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/ProgressBar/index.scss +96 -96
- package/src/components/SplitContainer/index.tsx +333 -333
- package/src/components/Toolbar/index.tsx +232 -212
- package/src/designsystemet-web-types.d.ts +24 -24
- package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
- package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
- package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
- package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
- package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
- package/src/elements/ElementLookup.tsx +123 -123
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -32
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
- package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
- package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
- package/src/elements/ProjectSelect.tsx +130 -130
- package/src/elements/index.ts +15 -15
- package/src/filter/index.ts +34 -34
- package/src/i18n.ts +13 -13
- package/src/index.ts +77 -77
- package/src/mui/MuiThemeProvider.tsx +174 -174
- package/src/mui/index.ts +1 -1
- package/src/test/setup.ts +8 -8
|
@@ -52,7 +52,9 @@ export function useCropTool(imageUrl, enabled) {
|
|
|
52
52
|
let activeCorners = draftQuad ?? corners ?? fullImageQuad(canvasPixelSize.width, canvasPixelSize.height);
|
|
53
53
|
let scale = displaySize.width > 0 ? displaySize.width / canvasPixelSize.width : 1;
|
|
54
54
|
let handleCanvasReady = useCallback((canvas, w, h) => {
|
|
55
|
-
|
|
55
|
+
// Detect on a bare copy: the displayed canvas carries the selection border, which
|
|
56
|
+
// starts out along the image edges and would be found as the document outline.
|
|
57
|
+
setCanvasEl(canvasRef.current?.getCleanCanvas() ?? null);
|
|
56
58
|
setCanvasPixelSize({ width: w, height: h });
|
|
57
59
|
setDisplaySize({ width: canvas.clientWidth, height: canvas.clientHeight });
|
|
58
60
|
}, []);
|
|
@@ -5,12 +5,27 @@ export interface Point {
|
|
|
5
5
|
/** TL, TR, BR, BL */
|
|
6
6
|
export type Quad = [Point, Point, Point, Point];
|
|
7
7
|
export declare function fullImageQuad(width: number, height: number): Quad;
|
|
8
|
+
/**
|
|
9
|
+
* Finds the most likely document outline in an RGBA image.
|
|
10
|
+
*
|
|
11
|
+
* Print is first removed with a morphological close, so text and table rules do not
|
|
12
|
+
* compete with the paper's outline. Straight segments from a Hough transform are merged
|
|
13
|
+
* into candidate lines, and every combination of two near-vertical and two near-horizontal
|
|
14
|
+
* lines (the image borders included, for receipts that run off the photo) is scored by how
|
|
15
|
+
* much of each side both lies on an edge and separates two differently coloured surfaces.
|
|
16
|
+
* Scoring by supported length, rather than by the share of each side, lets a long receipt
|
|
17
|
+
* whose edges bend at a fold beat a small, perfectly straight section of it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findDocumentQuad(cv: any, src: any): Quad | null;
|
|
8
20
|
interface UseEdgeDetectionResult {
|
|
9
21
|
corners: Quad | null;
|
|
10
22
|
}
|
|
11
23
|
/**
|
|
12
|
-
*
|
|
13
|
-
* Falls back to full-image corners if no
|
|
24
|
+
* Suggests document corners for the image on `canvas`.
|
|
25
|
+
* Falls back to full-image corners if no document outline is found.
|
|
26
|
+
*
|
|
27
|
+
* `canvas` must hold the bare image: anything drawn over it, such as the crop overlay's
|
|
28
|
+
* selection border, is detected as an edge like any other.
|
|
14
29
|
*/
|
|
15
30
|
export declare function useEdgeDetection(cv: any, canvas: HTMLCanvasElement | null, enabled: boolean): UseEdgeDetectionResult;
|
|
16
31
|
export {};
|
|
@@ -7,80 +7,257 @@ export function fullImageQuad(width, height) {
|
|
|
7
7
|
{ x: 0, y: height },
|
|
8
8
|
];
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
/** Longest side of the downscaled working image. Detection is scale-dependent, so it is fixed. */
|
|
11
|
+
const WORK_SIZE = 512;
|
|
12
|
+
/** Closing kernel that erases dark print (text, thin rules) so only surface boundaries remain. */
|
|
13
|
+
const CLOSE_KERNEL = 5;
|
|
14
|
+
/** Candidate lines kept per orientation family. The search is O(n⁴), so keep this small. */
|
|
15
|
+
const MAX_LINES_PER_FAMILY = 14;
|
|
16
|
+
/** Distances (working pixels) sampled on each side of a candidate edge. */
|
|
17
|
+
const SAMPLE_OFFSET_MIN = 3;
|
|
18
|
+
const SAMPLE_OFFSET_MAX = 9;
|
|
19
|
+
/** Minimum Lab colour difference between the two sides for an edge sample to count. */
|
|
20
|
+
const MIN_CONTRAST = 8;
|
|
21
|
+
/** Cost of an unsupported stretch of side, relative to the gain of a supported one. */
|
|
22
|
+
const UNSUPPORTED_COST = 0.5;
|
|
23
|
+
/** Cost per pixel of using the image border as a side (document running off the frame). */
|
|
24
|
+
const BORDER_COST = 0.1;
|
|
25
|
+
/** Minimum normalised score for a suggestion; below it the full image is used. */
|
|
26
|
+
const MIN_SCORE = 0.3;
|
|
27
|
+
const MIN_AREA_FRACTION = 0.1;
|
|
28
|
+
/**
|
|
29
|
+
* Finds the most likely document outline in an RGBA image.
|
|
30
|
+
*
|
|
31
|
+
* Print is first removed with a morphological close, so text and table rules do not
|
|
32
|
+
* compete with the paper's outline. Straight segments from a Hough transform are merged
|
|
33
|
+
* into candidate lines, and every combination of two near-vertical and two near-horizontal
|
|
34
|
+
* lines (the image borders included, for receipts that run off the photo) is scored by how
|
|
35
|
+
* much of each side both lies on an edge and separates two differently coloured surfaces.
|
|
36
|
+
* Scoring by supported length, rather than by the share of each side, lets a long receipt
|
|
37
|
+
* whose edges bend at a fold beat a small, perfectly straight section of it.
|
|
38
|
+
*/
|
|
39
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js has no bundled types
|
|
40
|
+
export function findDocumentQuad(cv, src) {
|
|
41
|
+
let scale = Math.min(1, WORK_SIZE / Math.max(src.cols, src.rows));
|
|
42
|
+
let small = new cv.Mat();
|
|
43
|
+
let rgb = new cv.Mat();
|
|
44
|
+
let colour = new cv.Mat();
|
|
45
|
+
let lab = new cv.Mat();
|
|
11
46
|
let gray = new cv.Mat();
|
|
12
|
-
let blurred = new cv.Mat();
|
|
13
47
|
let edges = new cv.Mat();
|
|
14
|
-
let
|
|
15
|
-
let
|
|
16
|
-
let hierarchy = new cv.Mat();
|
|
48
|
+
let support = new cv.Mat();
|
|
49
|
+
let segments = new cv.Mat();
|
|
17
50
|
try {
|
|
18
|
-
cv.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
cv.
|
|
25
|
-
|
|
26
|
-
cv.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
cv.resize(src, small, new cv.Size(Math.round(src.cols * scale), Math.round(src.rows * scale)), 0, 0, cv.INTER_AREA);
|
|
52
|
+
let w = small.cols;
|
|
53
|
+
let h = small.rows;
|
|
54
|
+
let minDim = Math.min(w, h);
|
|
55
|
+
cv.cvtColor(small, rgb, cv.COLOR_RGBA2RGB);
|
|
56
|
+
let closeKernel = cv.getStructuringElement(cv.MORPH_RECT, new cv.Size(CLOSE_KERNEL, CLOSE_KERNEL));
|
|
57
|
+
cv.morphologyEx(rgb, rgb, cv.MORPH_CLOSE, closeKernel);
|
|
58
|
+
closeKernel.delete();
|
|
59
|
+
cv.GaussianBlur(rgb, colour, new cv.Size(5, 5), 0);
|
|
60
|
+
cv.cvtColor(colour, lab, cv.COLOR_RGB2Lab);
|
|
61
|
+
// Blurred after the grey conversion, not taken from `colour`: the rounding differs,
|
|
62
|
+
// and the weaker receipt edges sit close enough to the Hough threshold to notice.
|
|
63
|
+
cv.cvtColor(rgb, gray, cv.COLOR_RGB2GRAY);
|
|
64
|
+
cv.GaussianBlur(gray, gray, new cv.Size(5, 5), 0);
|
|
65
|
+
// Low thresholds: a receipt on a white table has very little contrast.
|
|
66
|
+
cv.Canny(gray, edges, 20, 60);
|
|
67
|
+
// A tolerant copy for scoring, so a side a pixel or two off its edge still counts.
|
|
68
|
+
let supportKernel = cv.getStructuringElement(cv.MORPH_RECT, new cv.Size(5, 5));
|
|
69
|
+
cv.dilate(edges, support, supportKernel);
|
|
70
|
+
supportKernel.delete();
|
|
71
|
+
cv.HoughLinesP(edges, segments, 1, Math.PI / 180, 30, minDim * 0.12, 8);
|
|
72
|
+
let { vertical, horizontal } = groupLines(segments, minDim);
|
|
73
|
+
vertical.push({ theta: 0, rho: 0, weight: 0, border: true }, { theta: 0, rho: w - 1, weight: 0, border: true });
|
|
74
|
+
horizontal.push({ theta: Math.PI / 2, rho: 0, weight: 0, border: true }, { theta: Math.PI / 2, rho: h - 1, weight: 0, border: true });
|
|
75
|
+
let labData = lab.data;
|
|
76
|
+
let supportData = support.data;
|
|
77
|
+
let labAt = (x, y, channel) => {
|
|
78
|
+
let xi = Math.min(w - 1, Math.max(0, Math.round(x)));
|
|
79
|
+
let yi = Math.min(h - 1, Math.max(0, Math.round(y)));
|
|
80
|
+
return labData[(yi * w + xi) * 3 + channel];
|
|
81
|
+
};
|
|
82
|
+
/** Share of a side that lies on an edge with different surfaces on either side of it. */
|
|
83
|
+
let coverage = (a, b) => {
|
|
84
|
+
let len = distance(a, b);
|
|
85
|
+
let n = Math.max(8, Math.round(len / 3));
|
|
86
|
+
let nx = -(b.y - a.y) / len;
|
|
87
|
+
let ny = (b.x - a.x) / len;
|
|
88
|
+
let hits = 0;
|
|
89
|
+
for (let i = 1; i < n; i++) {
|
|
90
|
+
let px = a.x + ((b.x - a.x) * i) / n;
|
|
91
|
+
let py = a.y + ((b.y - a.y) * i) / n;
|
|
92
|
+
let x = Math.round(px);
|
|
93
|
+
let y = Math.round(py);
|
|
94
|
+
if (x < 0 || y < 0 || x >= w || y >= h || !supportData[y * w + x])
|
|
95
|
+
continue;
|
|
96
|
+
let diff = [0, 0, 0];
|
|
97
|
+
let count = 0;
|
|
98
|
+
for (let d = SAMPLE_OFFSET_MIN; d <= SAMPLE_OFFSET_MAX; d += 2) {
|
|
99
|
+
for (let c = 0; c < 3; c++) {
|
|
100
|
+
diff[c] += labAt(px + nx * d, py + ny * d, c) - labAt(px - nx * d, py - ny * d, c);
|
|
101
|
+
}
|
|
102
|
+
count++;
|
|
45
103
|
}
|
|
104
|
+
// Chroma weighs double: a cream receipt on a grey-white table differs mostly in tint.
|
|
105
|
+
if (Math.hypot(diff[0] / count, (2 * diff[1]) / count, (2 * diff[2]) / count) > MIN_CONTRAST)
|
|
106
|
+
hits++;
|
|
46
107
|
}
|
|
47
|
-
|
|
48
|
-
|
|
108
|
+
return hits / (n - 1);
|
|
109
|
+
};
|
|
110
|
+
let margin = minDim * 0.02;
|
|
111
|
+
let inBounds = (p) => p !== null && p.x >= -margin && p.y >= -margin && p.x <= w + margin && p.y <= h + margin;
|
|
112
|
+
let minGap = minDim * 0.1;
|
|
113
|
+
let best = null;
|
|
114
|
+
let bestScore = -Infinity;
|
|
115
|
+
for (let left of vertical) {
|
|
116
|
+
for (let right of vertical) {
|
|
117
|
+
if (xAt(left, h / 2) >= xAt(right, h / 2) - minGap)
|
|
118
|
+
continue;
|
|
119
|
+
for (let top of horizontal) {
|
|
120
|
+
for (let bottom of horizontal) {
|
|
121
|
+
if (yAt(top, w / 2) >= yAt(bottom, w / 2) - minGap)
|
|
122
|
+
continue;
|
|
123
|
+
let sides = [top, right, bottom, left];
|
|
124
|
+
if (sides.filter((l) => l.border).length > 2)
|
|
125
|
+
continue;
|
|
126
|
+
let corners = [
|
|
127
|
+
intersect(left, top),
|
|
128
|
+
intersect(right, top),
|
|
129
|
+
intersect(right, bottom),
|
|
130
|
+
intersect(left, bottom),
|
|
131
|
+
];
|
|
132
|
+
if (!corners.every(inBounds))
|
|
133
|
+
continue;
|
|
134
|
+
let quad = corners;
|
|
135
|
+
if (polygonArea(quad) < w * h * MIN_AREA_FRACTION || !isConvex(quad))
|
|
136
|
+
continue;
|
|
137
|
+
let score = 0;
|
|
138
|
+
for (let s = 0; s < 4; s++) {
|
|
139
|
+
let a = quad[s];
|
|
140
|
+
let b = quad[(s + 1) % 4];
|
|
141
|
+
let len = distance(a, b);
|
|
142
|
+
if (sides[s].border) {
|
|
143
|
+
score -= BORDER_COST * len;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
let cov = coverage(a, b);
|
|
147
|
+
score += len * (cov - UNSUPPORTED_COST * (1 - cov));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
score /= w + h;
|
|
151
|
+
if (score > bestScore) {
|
|
152
|
+
bestScore = score;
|
|
153
|
+
best = quad;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
49
157
|
}
|
|
50
|
-
contour.delete();
|
|
51
158
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
159
|
+
if (!best || bestScore < MIN_SCORE)
|
|
160
|
+
return null;
|
|
161
|
+
return best.map((p) => ({
|
|
162
|
+
x: Math.min(src.cols, Math.max(0, p.x / scale)),
|
|
163
|
+
y: Math.min(src.rows, Math.max(0, p.y / scale)),
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
for (let mat of [small, rgb, colour, lab, gray, edges, support, segments])
|
|
59
168
|
mat.delete();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Merges Hough segments that lie on the same line and splits the result into near-vertical
|
|
173
|
+
* and near-horizontal families, each ordered by total segment length.
|
|
174
|
+
*/
|
|
175
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js has no bundled types
|
|
176
|
+
function groupLines(segments, minDim) {
|
|
177
|
+
let lines = [];
|
|
178
|
+
let maxAngle = (3 * Math.PI) / 180;
|
|
179
|
+
let maxOffset = minDim * 0.015;
|
|
180
|
+
for (let i = 0; i < segments.rows; i++) {
|
|
181
|
+
let [x1, y1, x2, y2] = segments.data32S.slice(i * 4, i * 4 + 4);
|
|
182
|
+
let len = Math.hypot(x2 - x1, y2 - y1);
|
|
183
|
+
// Normal of the segment, folded into [0, π)
|
|
184
|
+
let theta = Math.atan2(x1 - x2, y2 - y1);
|
|
185
|
+
if (theta < 0)
|
|
186
|
+
theta += Math.PI;
|
|
187
|
+
if (theta >= Math.PI)
|
|
188
|
+
theta -= Math.PI;
|
|
189
|
+
let rho = x1 * Math.cos(theta) + y1 * Math.sin(theta);
|
|
190
|
+
let match = lines.find((l) => Math.abs(l.theta - theta) < maxAngle && Math.abs(l.rho - rho) < maxOffset);
|
|
191
|
+
if (match) {
|
|
192
|
+
let total = match.weight + len;
|
|
193
|
+
match.theta = (match.theta * match.weight + theta * len) / total;
|
|
194
|
+
match.rho = (match.rho * match.weight + rho * len) / total;
|
|
195
|
+
match.weight = total;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
lines.push({ theta, rho, weight: len });
|
|
68
199
|
}
|
|
69
|
-
return quad;
|
|
70
200
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
201
|
+
lines.sort((a, b) => b.weight - a.weight);
|
|
202
|
+
let isVertical = (l) => l.theta < Math.PI / 4 || l.theta > (3 * Math.PI) / 4;
|
|
203
|
+
return {
|
|
204
|
+
vertical: lines.filter(isVertical).slice(0, MAX_LINES_PER_FAMILY),
|
|
205
|
+
horizontal: lines.filter((l) => !isVertical(l)).slice(0, MAX_LINES_PER_FAMILY),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** x where a near-vertical line crosses the given y. */
|
|
209
|
+
function xAt(line, y) {
|
|
210
|
+
return (line.rho - y * Math.sin(line.theta)) / Math.cos(line.theta);
|
|
211
|
+
}
|
|
212
|
+
/** y where a near-horizontal line crosses the given x. */
|
|
213
|
+
function yAt(line, x) {
|
|
214
|
+
return (line.rho - x * Math.cos(line.theta)) / Math.sin(line.theta);
|
|
215
|
+
}
|
|
216
|
+
function intersect(a, b) {
|
|
217
|
+
let ca = Math.cos(a.theta);
|
|
218
|
+
let sa = Math.sin(a.theta);
|
|
219
|
+
let cb = Math.cos(b.theta);
|
|
220
|
+
let sb = Math.sin(b.theta);
|
|
221
|
+
let det = ca * sb - sa * cb;
|
|
222
|
+
if (Math.abs(det) < 1e-6)
|
|
223
|
+
return null;
|
|
224
|
+
return { x: (a.rho * sb - b.rho * sa) / det, y: (ca * b.rho - cb * a.rho) / det };
|
|
225
|
+
}
|
|
226
|
+
function distance(a, b) {
|
|
227
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
228
|
+
}
|
|
229
|
+
function polygonArea(points) {
|
|
230
|
+
let area = 0;
|
|
231
|
+
for (let i = 0; i < points.length; i++) {
|
|
232
|
+
let p = points[i];
|
|
233
|
+
let q = points[(i + 1) % points.length];
|
|
234
|
+
area += p.x * q.y - q.x * p.y;
|
|
235
|
+
}
|
|
236
|
+
return Math.abs(area) / 2;
|
|
237
|
+
}
|
|
238
|
+
function isConvex(points) {
|
|
239
|
+
let sign = 0;
|
|
240
|
+
for (let i = 0; i < points.length; i++) {
|
|
241
|
+
let a = points[i];
|
|
242
|
+
let b = points[(i + 1) % points.length];
|
|
243
|
+
let c = points[(i + 2) % points.length];
|
|
244
|
+
let s = Math.sign((b.x - a.x) * (c.y - b.y) - (b.y - a.y) * (c.x - b.x));
|
|
245
|
+
if (s === 0)
|
|
246
|
+
continue;
|
|
247
|
+
if (sign && s !== sign)
|
|
248
|
+
return false;
|
|
249
|
+
sign = s;
|
|
78
250
|
}
|
|
251
|
+
return true;
|
|
79
252
|
}
|
|
80
253
|
/**
|
|
81
|
-
*
|
|
82
|
-
* Falls back to full-image corners if no
|
|
254
|
+
* Suggests document corners for the image on `canvas`.
|
|
255
|
+
* Falls back to full-image corners if no document outline is found.
|
|
256
|
+
*
|
|
257
|
+
* `canvas` must hold the bare image: anything drawn over it, such as the crop overlay's
|
|
258
|
+
* selection border, is detected as an edge like any other.
|
|
83
259
|
*/
|
|
260
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js has no bundled types
|
|
84
261
|
export function useEdgeDetection(cv, canvas, enabled) {
|
|
85
262
|
let [corners, setCorners] = useState(null);
|
|
86
263
|
useEffect(() => {
|
|
@@ -90,7 +267,7 @@ export function useEdgeDetection(cv, canvas, enabled) {
|
|
|
90
267
|
let src = cv.imread(canvas);
|
|
91
268
|
let quad;
|
|
92
269
|
try {
|
|
93
|
-
quad =
|
|
270
|
+
quad = findDocumentQuad(cv, src);
|
|
94
271
|
}
|
|
95
272
|
finally {
|
|
96
273
|
src.delete();
|
|
@@ -30,6 +30,25 @@ function findTarget(ids) {
|
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* The 2026 template reserves the drawer slot only for articles whose deploy wrote the
|
|
35
|
+
* `ToolbarDrawer` block (the build detects `ToolbarDrawerToggle` in the app). An app with a
|
|
36
|
+
* drawer that has not been deployed since renders on a toolbar without the slot: create it in
|
|
37
|
+
* front of the app region and drop the no-drawer layout class, so the toggle still mounts. The
|
|
38
|
+
* toolbar shifts once when that happens, which the block avoids on the next deploy.
|
|
39
|
+
*/
|
|
40
|
+
function createDrawerSlot() {
|
|
41
|
+
let toolbar = document.querySelector(".ob-toolbar");
|
|
42
|
+
let lead = toolbar?.querySelector(".ob-toolbar__lead");
|
|
43
|
+
if (!toolbar || !lead)
|
|
44
|
+
return null;
|
|
45
|
+
let slot = document.createElement("div");
|
|
46
|
+
slot.id = DRAWER_SLOT_IDS[0];
|
|
47
|
+
slot.className = "ob-toolbar__drawer";
|
|
48
|
+
lead.prepend(slot);
|
|
49
|
+
toolbar.classList.remove("ob-toolbar--no-drawer");
|
|
50
|
+
return slot;
|
|
51
|
+
}
|
|
33
52
|
/**
|
|
34
53
|
* Renders its children into the toolbar's app region. Render `ToolbarBreadcrumbs` before any
|
|
35
54
|
* other `ToolbarPortal`, since the region lays its children out in mount order with the first
|
|
@@ -47,7 +66,7 @@ export function ToolbarPortal({ children }) {
|
|
|
47
66
|
* contrast colour on every brand. Renders nothing on a template without a toolbar.
|
|
48
67
|
*/
|
|
49
68
|
export function ToolbarDrawerToggle({ open, onToggle, label }) {
|
|
50
|
-
let target = findTarget(DRAWER_SLOT_IDS);
|
|
69
|
+
let target = findTarget(DRAWER_SLOT_IDS) ?? createDrawerSlot();
|
|
51
70
|
if (!target)
|
|
52
71
|
return null;
|
|
53
72
|
return createPortal(_jsx("button", { type: "button", className: "ob-toolbar__icon-button", "aria-label": label ?? getLocalizedString("Toggle menu"), "aria-expanded": open, onClick: onToggle, children: _jsx(MenuHamburgerIcon, { "aria-hidden": true, fontSize: "1.5rem" }) }), target);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/synergi-react",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "Standalone React component for SynergiWeb and Partner Portal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"react-dom": "19.3.0",
|
|
55
55
|
"react-pdf": "10.5.0",
|
|
56
56
|
"zxing-wasm": "3.1.4",
|
|
57
|
+
"@olenbetong/appframe-ds": "1.3.0",
|
|
57
58
|
"@olenbetong/appframe-core": "2.14.0",
|
|
58
|
-
"@olenbetong/appframe-react": "2.2.1",
|
|
59
59
|
"@olenbetong/appframe-data": "1.7.2",
|
|
60
60
|
"@olenbetong/appframe-mui": "7.0.3",
|
|
61
|
-
"@olenbetong/appframe-
|
|
61
|
+
"@olenbetong/appframe-react": "2.2.1"
|
|
62
62
|
},
|
|
63
63
|
"repository": {
|
|
64
64
|
"type": "git",
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { AppErrorBoundary } from "@olenbetong/appframe-ds";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
export type AppShellProps = {
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Standard Synergi app shell: the error boundary around the app.
|
|
10
|
-
*
|
|
11
|
-
* The site chrome (app menu, user menu, colour scheme, service worker update)
|
|
12
|
-
* is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
|
|
13
|
-
* bundle the `ob.2026.application` template loads, which marks the page with
|
|
14
|
-
* `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
|
|
15
|
-
* `ToolbarPortal` and `ToolbarBreadcrumbs`.
|
|
16
|
-
*
|
|
17
|
-
* This component is Designsystemet-only. Apps that still render MUI components
|
|
18
|
-
* should additionally wrap it in `MuiThemeProvider` from
|
|
19
|
-
* `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
|
|
20
|
-
* tokens into a MUI theme.
|
|
21
|
-
*/
|
|
22
|
-
export function AppShell({ children }: AppShellProps) {
|
|
23
|
-
return <AppErrorBoundary>{children}</AppErrorBoundary>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
|
|
27
|
-
export function hasSiteChrome() {
|
|
28
|
-
return typeof document !== "undefined" && document.documentElement.dataset.obChrome !== undefined;
|
|
29
|
-
}
|
|
1
|
+
import { AppErrorBoundary } from "@olenbetong/appframe-ds";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
export type AppShellProps = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Standard Synergi app shell: the error boundary around the app.
|
|
10
|
+
*
|
|
11
|
+
* The site chrome (app menu, user menu, colour scheme, service worker update)
|
|
12
|
+
* is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
|
|
13
|
+
* bundle the `ob.2026.application` template loads, which marks the page with
|
|
14
|
+
* `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
|
|
15
|
+
* `ToolbarPortal` and `ToolbarBreadcrumbs`.
|
|
16
|
+
*
|
|
17
|
+
* This component is Designsystemet-only. Apps that still render MUI components
|
|
18
|
+
* should additionally wrap it in `MuiThemeProvider` from
|
|
19
|
+
* `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
|
|
20
|
+
* tokens into a MUI theme.
|
|
21
|
+
*/
|
|
22
|
+
export function AppShell({ children }: AppShellProps) {
|
|
23
|
+
return <AppErrorBoundary>{children}</AppErrorBoundary>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
|
|
27
|
+
export function hasSiteChrome() {
|
|
28
|
+
return typeof document !== "undefined" && document.documentElement.dataset.obChrome !== undefined;
|
|
29
|
+
}
|
package/src/chrome/openReport.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
export type OpenReportOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* Overrides the filter the report was designed with, as a criteria string.
|
|
4
|
-
* An empty string starts the launcher with no filter at all.
|
|
5
|
-
*/
|
|
6
|
-
initialFilter?: string | null;
|
|
7
|
-
/** The tab shown first. */
|
|
8
|
-
defaultTab?: "parameters" | "filter";
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type ChromeWithReports = {
|
|
12
|
-
openReport?: (reportId: string, options?: OpenReportOptions) => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Opens a report in the site chrome's report launcher, the way the app menu does.
|
|
17
|
-
*
|
|
18
|
-
* The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
|
|
19
|
-
* so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
|
|
20
|
-
* On a page without the chrome (a legacy template) the call is logged and ignored.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function openReport(reportId: string, options?: OpenReportOptions) {
|
|
28
|
-
let chrome = (globalThis as { ob?: { chrome?: ChromeWithReports } }).ob?.chrome;
|
|
29
|
-
if (chrome?.openReport) {
|
|
30
|
-
chrome.openReport(reportId, options);
|
|
31
|
-
} else {
|
|
32
|
-
console.warn(`openReport(${reportId}): the site chrome is not on this page, so there is no report launcher.`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
export type OpenReportOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* Overrides the filter the report was designed with, as a criteria string.
|
|
4
|
+
* An empty string starts the launcher with no filter at all.
|
|
5
|
+
*/
|
|
6
|
+
initialFilter?: string | null;
|
|
7
|
+
/** The tab shown first. */
|
|
8
|
+
defaultTab?: "parameters" | "filter";
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type ChromeWithReports = {
|
|
12
|
+
openReport?: (reportId: string, options?: OpenReportOptions) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Opens a report in the site chrome's report launcher, the way the app menu does.
|
|
17
|
+
*
|
|
18
|
+
* The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
|
|
19
|
+
* so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
|
|
20
|
+
* On a page without the chrome (a legacy template) the call is logged and ignored.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function openReport(reportId: string, options?: OpenReportOptions) {
|
|
28
|
+
let chrome = (globalThis as { ob?: { chrome?: ChromeWithReports } }).ob?.chrome;
|
|
29
|
+
if (chrome?.openReport) {
|
|
30
|
+
chrome.openReport(reportId, options);
|
|
31
|
+
} else {
|
|
32
|
+
console.warn(`openReport(${reportId}): the site chrome is not on this page, so there is no report launcher.`);
|
|
33
|
+
}
|
|
34
|
+
}
|