@olenbetong/synergi-react 4.2.1 → 4.2.4

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 (56) hide show
  1. package/package.json +8 -8
  2. package/src/chrome/AppShell/index.tsx +29 -29
  3. package/src/chrome/openReport.ts +34 -34
  4. package/src/colorScheme.ts +81 -81
  5. package/src/components/DateNavigator/index.tsx +186 -186
  6. package/src/components/FilePond.tsx +312 -312
  7. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  8. package/src/components/ImageEditor/index.ts +9 -9
  9. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  10. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  11. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  12. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  13. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  14. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  15. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  16. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  17. package/src/components/ImageEditor/useImageHistory.ts +197 -197
  18. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  19. package/src/components/LinkedCardList/index.scss +95 -95
  20. package/src/components/MergeProgressDialog/index.tsx +249 -249
  21. package/src/components/PageBanner/index.tsx +80 -80
  22. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  23. package/src/components/ProgressBar/index.scss +96 -96
  24. package/src/components/SplitContainer/index.tsx +333 -333
  25. package/src/components/Toolbar/index.tsx +232 -232
  26. package/src/designsystemet-web-types.d.ts +24 -24
  27. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  28. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  29. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  30. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  31. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  32. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  33. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  34. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  35. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  36. package/src/elements/ElementLookup.tsx +123 -123
  37. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -32
  38. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
  39. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
  40. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
  41. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
  42. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
  43. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
  44. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
  45. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  46. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  47. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  48. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  49. package/src/elements/ProjectSelect.tsx +130 -130
  50. package/src/elements/index.ts +15 -15
  51. package/src/filter/index.ts +34 -34
  52. package/src/i18n.ts +13 -13
  53. package/src/index.ts +77 -77
  54. package/src/mui/MuiThemeProvider.tsx +174 -174
  55. package/src/mui/index.ts +1 -1
  56. package/src/test/setup.ts +8 -8
@@ -1,123 +1,123 @@
1
- import SearchIcon from "@mui/icons-material/Search";
2
- import { IconButton, TextField } from "@mui/material";
3
- import { type ReactNode, type RefObject, useEffect, useImperativeHandle, useRef, useState } from "react";
4
- import { type AddElement, ElementLookupDialog } from "./ElementLookupDialog";
5
- import type { DecoderFactory } from "./ElementLookupDialog/BarcodeScanner";
6
- import { getLocalizedString } from "../i18n.js";
7
-
8
- export type Element = {
9
- Domain: string;
10
- PrimKey: string;
11
- ProjectID: string;
12
- ProjectName: string;
13
- ElementID: string | null;
14
- };
15
-
16
- export type ElementLookupHandle = {
17
- openDialog: () => void;
18
- closeDialog: () => void;
19
- };
20
-
21
- export type ElementLookupProps = {
22
- value?: Element | null;
23
- defaultValue?: Element | null;
24
- ref?: RefObject<ElementLookupHandle | null>;
25
- elementIDRequired?: boolean;
26
- openLookupDialogIcon?: boolean;
27
- onChange?: (value: Element | null) => void;
28
- onDialogChange?: (open: boolean) => void;
29
- /** Engine for the camera tab of the lookup dialog. Defaults to zxing-wasm. */
30
- decoder?: DecoderFactory;
31
- /** Extra controls in the camera tab footer, e.g. an engine picker. */
32
- scannerActions?: ReactNode;
33
- };
34
-
35
- export function ElementLookup({
36
- value,
37
- defaultValue,
38
- ref,
39
- elementIDRequired = false,
40
- openLookupDialogIcon,
41
- onChange,
42
- onDialogChange,
43
- decoder,
44
- scannerActions,
45
- }: ElementLookupProps) {
46
- let initializedRef = useRef<boolean>(false);
47
-
48
- let [openElementLookupDialog, setOpenElementLookupDialog] = useState<boolean>(false);
49
- let [element, setElement] = useState<Element | null>(defaultValue ?? null);
50
- let elementValue = value === undefined ? element : value;
51
-
52
- useEffect(() => {
53
- if (initializedRef.current) {
54
- return;
55
- }
56
-
57
- if (value === undefined && defaultValue) {
58
- setElement(defaultValue);
59
- initializedRef.current = true;
60
- }
61
- }, [defaultValue]); // oxlint-disable-line react-hooks/exhaustive-deps (intentionally skipping "value" dependency as this shouldn't run when "value" changes)
62
-
63
- useImperativeHandle(ref, () => ({
64
- openDialog: () => setOpenElementLookupDialog(true),
65
- closeDialog: () => setOpenElementLookupDialog(false),
66
- }));
67
-
68
- async function handleAddElement(addElement: AddElement) {
69
- onChange?.(addElement.element);
70
- setElement(addElement.element);
71
- }
72
-
73
- useEffect(() => {
74
- onDialogChange?.(openElementLookupDialog);
75
- }, [openElementLookupDialog]); // oxlint-disable-line react-hooks/exhaustive-deps (only run when openElementLookupDialog changes)
76
-
77
- return (
78
- <>
79
- <ElementLookupDialog
80
- open={openElementLookupDialog}
81
- mode="single"
82
- onClose={() => setOpenElementLookupDialog(false)}
83
- onAdd={handleAddElement}
84
- allowEmptyElement={!elementIDRequired}
85
- decoder={decoder}
86
- scannerActions={scannerActions}
87
- />
88
-
89
- <input type="hidden" name="ProjectID" value={elementValue?.ProjectID ?? ""} />
90
- <input type="hidden" name="ElementRef" value={elementValue?.PrimKey ?? ""} />
91
-
92
- <TextField
93
- id="NewElementDamge_Project"
94
- value={elementValue ? `${elementValue.ProjectID}: ${elementValue.ProjectName}` : ""}
95
- label={getLocalizedString("Project")}
96
- fullWidth
97
- required
98
- autoComplete="off"
99
- slotProps={{ htmlInput: { readOnly: true } }}
100
- />
101
- <TextField
102
- name="ElementID"
103
- id="NewElementDamage_ElementID"
104
- value={elementValue ? elementValue.ElementID : ""}
105
- label={getLocalizedString("Element ID")}
106
- fullWidth
107
- required={elementIDRequired}
108
- autoComplete="off"
109
- slotProps={{
110
- htmlInput: { readOnly: true },
111
- input: {
112
- endAdornment: openLookupDialogIcon ? (
113
- <IconButton onClick={() => setOpenElementLookupDialog(true)}>
114
- <SearchIcon />
115
- </IconButton>
116
- ) : undefined,
117
- },
118
- inputLabel: { shrink: !!elementValue?.ElementID },
119
- }}
120
- />
121
- </>
122
- );
123
- }
1
+ import SearchIcon from "@mui/icons-material/Search";
2
+ import { IconButton, TextField } from "@mui/material";
3
+ import { type ReactNode, type RefObject, useEffect, useImperativeHandle, useRef, useState } from "react";
4
+ import { type AddElement, ElementLookupDialog } from "./ElementLookupDialog";
5
+ import type { DecoderFactory } from "./ElementLookupDialog/BarcodeScanner";
6
+ import { getLocalizedString } from "../i18n.js";
7
+
8
+ export type Element = {
9
+ Domain: string;
10
+ PrimKey: string;
11
+ ProjectID: string;
12
+ ProjectName: string;
13
+ ElementID: string | null;
14
+ };
15
+
16
+ export type ElementLookupHandle = {
17
+ openDialog: () => void;
18
+ closeDialog: () => void;
19
+ };
20
+
21
+ export type ElementLookupProps = {
22
+ value?: Element | null;
23
+ defaultValue?: Element | null;
24
+ ref?: RefObject<ElementLookupHandle | null>;
25
+ elementIDRequired?: boolean;
26
+ openLookupDialogIcon?: boolean;
27
+ onChange?: (value: Element | null) => void;
28
+ onDialogChange?: (open: boolean) => void;
29
+ /** Engine for the camera tab of the lookup dialog. Defaults to zxing-wasm. */
30
+ decoder?: DecoderFactory;
31
+ /** Extra controls in the camera tab footer, e.g. an engine picker. */
32
+ scannerActions?: ReactNode;
33
+ };
34
+
35
+ export function ElementLookup({
36
+ value,
37
+ defaultValue,
38
+ ref,
39
+ elementIDRequired = false,
40
+ openLookupDialogIcon,
41
+ onChange,
42
+ onDialogChange,
43
+ decoder,
44
+ scannerActions,
45
+ }: ElementLookupProps) {
46
+ let initializedRef = useRef<boolean>(false);
47
+
48
+ let [openElementLookupDialog, setOpenElementLookupDialog] = useState<boolean>(false);
49
+ let [element, setElement] = useState<Element | null>(defaultValue ?? null);
50
+ let elementValue = value === undefined ? element : value;
51
+
52
+ useEffect(() => {
53
+ if (initializedRef.current) {
54
+ return;
55
+ }
56
+
57
+ if (value === undefined && defaultValue) {
58
+ setElement(defaultValue);
59
+ initializedRef.current = true;
60
+ }
61
+ }, [defaultValue]); // oxlint-disable-line react-hooks/exhaustive-deps (intentionally skipping "value" dependency as this shouldn't run when "value" changes)
62
+
63
+ useImperativeHandle(ref, () => ({
64
+ openDialog: () => setOpenElementLookupDialog(true),
65
+ closeDialog: () => setOpenElementLookupDialog(false),
66
+ }));
67
+
68
+ async function handleAddElement(addElement: AddElement) {
69
+ onChange?.(addElement.element);
70
+ setElement(addElement.element);
71
+ }
72
+
73
+ useEffect(() => {
74
+ onDialogChange?.(openElementLookupDialog);
75
+ }, [openElementLookupDialog]); // oxlint-disable-line react-hooks/exhaustive-deps (only run when openElementLookupDialog changes)
76
+
77
+ return (
78
+ <>
79
+ <ElementLookupDialog
80
+ open={openElementLookupDialog}
81
+ mode="single"
82
+ onClose={() => setOpenElementLookupDialog(false)}
83
+ onAdd={handleAddElement}
84
+ allowEmptyElement={!elementIDRequired}
85
+ decoder={decoder}
86
+ scannerActions={scannerActions}
87
+ />
88
+
89
+ <input type="hidden" name="ProjectID" value={elementValue?.ProjectID ?? ""} />
90
+ <input type="hidden" name="ElementRef" value={elementValue?.PrimKey ?? ""} />
91
+
92
+ <TextField
93
+ id="NewElementDamge_Project"
94
+ value={elementValue ? `${elementValue.ProjectID}: ${elementValue.ProjectName}` : ""}
95
+ label={getLocalizedString("Project")}
96
+ fullWidth
97
+ required
98
+ autoComplete="off"
99
+ slotProps={{ htmlInput: { readOnly: true } }}
100
+ />
101
+ <TextField
102
+ name="ElementID"
103
+ id="NewElementDamage_ElementID"
104
+ value={elementValue ? elementValue.ElementID : ""}
105
+ label={getLocalizedString("Element ID")}
106
+ fullWidth
107
+ required={elementIDRequired}
108
+ autoComplete="off"
109
+ slotProps={{
110
+ htmlInput: { readOnly: true },
111
+ input: {
112
+ endAdornment: openLookupDialogIcon ? (
113
+ <IconButton onClick={() => setOpenElementLookupDialog(true)}>
114
+ <SearchIcon />
115
+ </IconButton>
116
+ ) : undefined,
117
+ },
118
+ inputLabel: { shrink: !!elementValue?.ElementID },
119
+ }}
120
+ />
121
+ </>
122
+ );
123
+ }
@@ -1,32 +1,32 @@
1
- export type DecodedPoint = { x: number; y: number };
2
-
3
- export type DecodedBarcode = {
4
- /** Decoded text. GS1 DataMatrix keeps the FNC1 separators as U+001D. */
5
- text: string;
6
- /** Corners of the symbol in frame pixel coordinates: top-left, top-right, bottom-right, bottom-left. */
7
- corners: [DecodedPoint, DecodedPoint, DecodedPoint, DecodedPoint];
8
- /** Engine-specific format name, when reported. */
9
- format?: string;
10
- };
11
-
12
- /**
13
- * A barcode decoding engine. `BarcodeScanner` owns the camera and the frame loop and only hands
14
- * frames to the decoder, so any engine that can read a canvas or an image file can be plugged in.
15
- */
16
- export interface BarcodeDecoder {
17
- /** Short identifier shown in the scanner UI, e.g. "zxing", "native" or "dbr". */
18
- readonly name: string;
19
- /** Decode one camera frame drawn on a canvas. The scanner never has more than one call in flight. */
20
- decodeFrame(frame: HTMLCanvasElement): Promise<DecodedBarcode[]>;
21
- /** Decode a still image, such as a photo upload. May use slower, more thorough settings. */
22
- decodeImage(file: Blob): Promise<DecodedBarcode[]>;
23
- /** Release engine resources. Called when the scanner unmounts. */
24
- dispose?(): void;
25
- }
26
-
27
- /**
28
- * Creates a decoder. The heavy work — downloading a WebAssembly build or a vendor script — happens
29
- * here, not when the factory itself is created, so the factory is cheap to pass around and nothing
30
- * is loaded until the scanner mounts.
31
- */
32
- export type DecoderFactory = () => Promise<BarcodeDecoder>;
1
+ export type DecodedPoint = { x: number; y: number };
2
+
3
+ export type DecodedBarcode = {
4
+ /** Decoded text. GS1 DataMatrix keeps the FNC1 separators as U+001D. */
5
+ text: string;
6
+ /** Corners of the symbol in frame pixel coordinates: top-left, top-right, bottom-right, bottom-left. */
7
+ corners: [DecodedPoint, DecodedPoint, DecodedPoint, DecodedPoint];
8
+ /** Engine-specific format name, when reported. */
9
+ format?: string;
10
+ };
11
+
12
+ /**
13
+ * A barcode decoding engine. `BarcodeScanner` owns the camera and the frame loop and only hands
14
+ * frames to the decoder, so any engine that can read a canvas or an image file can be plugged in.
15
+ */
16
+ export interface BarcodeDecoder {
17
+ /** Short identifier shown in the scanner UI, e.g. "zxing", "native" or "dbr". */
18
+ readonly name: string;
19
+ /** Decode one camera frame drawn on a canvas. The scanner never has more than one call in flight. */
20
+ decodeFrame(frame: HTMLCanvasElement): Promise<DecodedBarcode[]>;
21
+ /** Decode a still image, such as a photo upload. May use slower, more thorough settings. */
22
+ decodeImage(file: Blob): Promise<DecodedBarcode[]>;
23
+ /** Release engine resources. Called when the scanner unmounts. */
24
+ dispose?(): void;
25
+ }
26
+
27
+ /**
28
+ * Creates a decoder. The heavy work — downloading a WebAssembly build or a vendor script — happens
29
+ * here, not when the factory itself is created, so the factory is cheap to pass around and nothing
30
+ * is loaded until the scanner mounts.
31
+ */
32
+ export type DecoderFactory = () => Promise<BarcodeDecoder>;
@@ -1,118 +1,118 @@
1
- import type BarcodeReaderType from "dynamsoft-javascript-barcode";
2
- import type { BarcodeDecoder, DecodedBarcode, DecoderFactory } from "../decoder";
3
-
4
- export type DbrDecoderOptions = {
5
- /** URL of the Dynamsoft Barcode Reader 6.x script, e.g. `/lib/dbr/dbr-6.5.1.min.js`. */
6
- scriptUrl: string;
7
- licenseKey: string;
8
- };
9
-
10
- type DbrGlobal = typeof BarcodeReaderType;
11
-
12
- /** The parts of a Dynamsoft `TextResult` the mapper reads, typed locally so the vendor types stay out of the public API. */
13
- export type DbrTextResult = {
14
- BarcodeText: string;
15
- BarcodeFormat: number;
16
- LocalizationResult: {
17
- X1: number;
18
- Y1: number;
19
- X2: number;
20
- Y2: number;
21
- X3: number;
22
- Y3: number;
23
- X4: number;
24
- Y4: number;
25
- };
26
- };
27
-
28
- let scriptLoading: Promise<DbrGlobal> | undefined;
29
-
30
- function getGlobal(): DbrGlobal | undefined {
31
- return (window as { BarcodeReader?: DbrGlobal }).BarcodeReader;
32
- }
33
-
34
- /** Loads the vendor script once, reusing `window.BarcodeReader` if the page already has it. */
35
- function loadBarcodeReader(scriptUrl: string): Promise<DbrGlobal> {
36
- let existing = getGlobal();
37
- if (existing) return Promise.resolve(existing);
38
-
39
- if (!scriptLoading) {
40
- scriptLoading = new Promise<DbrGlobal>((resolve, reject) => {
41
- let script = document.createElement("script");
42
- script.src = scriptUrl;
43
- script.async = true;
44
- script.onload = () => {
45
- let loaded = getGlobal();
46
- if (loaded) {
47
- resolve(loaded);
48
- } else {
49
- scriptLoading = undefined;
50
- reject(new Error(`${scriptUrl} did not define BarcodeReader`));
51
- }
52
- };
53
- script.onerror = () => {
54
- scriptLoading = undefined;
55
- script.remove();
56
- reject(new Error(`Failed to load ${scriptUrl}`));
57
- };
58
- document.head.append(script);
59
- });
60
- }
61
-
62
- return scriptLoading;
63
- }
64
-
65
- export function mapDbrResult(result: DbrTextResult): DecodedBarcode {
66
- let { X1, Y1, X2, Y2, X3, Y3, X4, Y4 } = result.LocalizationResult;
67
-
68
- return {
69
- text: result.BarcodeText,
70
- format: String(result.BarcodeFormat),
71
- corners: [
72
- { x: X1, y: Y1 },
73
- { x: X2, y: Y2 },
74
- { x: X3, y: Y3 },
75
- { x: X4, y: Y4 },
76
- ],
77
- };
78
- }
79
-
80
- /**
81
- * Decoder backed by the legacy Dynamsoft Barcode Reader JavaScript SDK (6.x). Kept for A/B
82
- * comparison against the free engines; the script is loaded on demand rather than by the article
83
- * so users who never scan do not pay for it.
84
- */
85
- export function createDbrDecoder({ scriptUrl, licenseKey }: DbrDecoderOptions): DecoderFactory {
86
- return async () => {
87
- if (typeof WebAssembly === "undefined") {
88
- throw new Error("WebAssembly is not supported");
89
- }
90
-
91
- let BarcodeReader = await loadBarcodeReader(scriptUrl);
92
- BarcodeReader.licenseKey = licenseKey;
93
-
94
- let reader = await BarcodeReader.createInstance();
95
- let settings = reader.getRuntimeSettings();
96
- settings.mBarcodeFormatIds = BarcodeReader.EnumBarcodeFormat.DATAMATRIX;
97
- settings.mAntiDamageLevel = 3;
98
- settings.mDeblurLevel = 0;
99
- await reader.updateRuntimeSettings(settings);
100
-
101
- return {
102
- name: "dbr",
103
- async decodeFrame(frame) {
104
- let results = await reader.decode(frame);
105
-
106
- return results.map(mapDbrResult);
107
- },
108
- async decodeImage(file) {
109
- let results = await reader.decode(file);
110
-
111
- return results.map(mapDbrResult);
112
- },
113
- dispose() {
114
- reader.deleteInstance();
115
- },
116
- } satisfies BarcodeDecoder;
117
- };
118
- }
1
+ import type BarcodeReaderType from "dynamsoft-javascript-barcode";
2
+ import type { BarcodeDecoder, DecodedBarcode, DecoderFactory } from "../decoder";
3
+
4
+ export type DbrDecoderOptions = {
5
+ /** URL of the Dynamsoft Barcode Reader 6.x script, e.g. `/lib/dbr/dbr-6.5.1.min.js`. */
6
+ scriptUrl: string;
7
+ licenseKey: string;
8
+ };
9
+
10
+ type DbrGlobal = typeof BarcodeReaderType;
11
+
12
+ /** The parts of a Dynamsoft `TextResult` the mapper reads, typed locally so the vendor types stay out of the public API. */
13
+ export type DbrTextResult = {
14
+ BarcodeText: string;
15
+ BarcodeFormat: number;
16
+ LocalizationResult: {
17
+ X1: number;
18
+ Y1: number;
19
+ X2: number;
20
+ Y2: number;
21
+ X3: number;
22
+ Y3: number;
23
+ X4: number;
24
+ Y4: number;
25
+ };
26
+ };
27
+
28
+ let scriptLoading: Promise<DbrGlobal> | undefined;
29
+
30
+ function getGlobal(): DbrGlobal | undefined {
31
+ return (window as { BarcodeReader?: DbrGlobal }).BarcodeReader;
32
+ }
33
+
34
+ /** Loads the vendor script once, reusing `window.BarcodeReader` if the page already has it. */
35
+ function loadBarcodeReader(scriptUrl: string): Promise<DbrGlobal> {
36
+ let existing = getGlobal();
37
+ if (existing) return Promise.resolve(existing);
38
+
39
+ if (!scriptLoading) {
40
+ scriptLoading = new Promise<DbrGlobal>((resolve, reject) => {
41
+ let script = document.createElement("script");
42
+ script.src = scriptUrl;
43
+ script.async = true;
44
+ script.onload = () => {
45
+ let loaded = getGlobal();
46
+ if (loaded) {
47
+ resolve(loaded);
48
+ } else {
49
+ scriptLoading = undefined;
50
+ reject(new Error(`${scriptUrl} did not define BarcodeReader`));
51
+ }
52
+ };
53
+ script.onerror = () => {
54
+ scriptLoading = undefined;
55
+ script.remove();
56
+ reject(new Error(`Failed to load ${scriptUrl}`));
57
+ };
58
+ document.head.append(script);
59
+ });
60
+ }
61
+
62
+ return scriptLoading;
63
+ }
64
+
65
+ export function mapDbrResult(result: DbrTextResult): DecodedBarcode {
66
+ let { X1, Y1, X2, Y2, X3, Y3, X4, Y4 } = result.LocalizationResult;
67
+
68
+ return {
69
+ text: result.BarcodeText,
70
+ format: String(result.BarcodeFormat),
71
+ corners: [
72
+ { x: X1, y: Y1 },
73
+ { x: X2, y: Y2 },
74
+ { x: X3, y: Y3 },
75
+ { x: X4, y: Y4 },
76
+ ],
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Decoder backed by the legacy Dynamsoft Barcode Reader JavaScript SDK (6.x). Kept for A/B
82
+ * comparison against the free engines; the script is loaded on demand rather than by the article
83
+ * so users who never scan do not pay for it.
84
+ */
85
+ export function createDbrDecoder({ scriptUrl, licenseKey }: DbrDecoderOptions): DecoderFactory {
86
+ return async () => {
87
+ if (typeof WebAssembly === "undefined") {
88
+ throw new Error("WebAssembly is not supported");
89
+ }
90
+
91
+ let BarcodeReader = await loadBarcodeReader(scriptUrl);
92
+ BarcodeReader.licenseKey = licenseKey;
93
+
94
+ let reader = await BarcodeReader.createInstance();
95
+ let settings = reader.getRuntimeSettings();
96
+ settings.mBarcodeFormatIds = BarcodeReader.EnumBarcodeFormat.DATAMATRIX;
97
+ settings.mAntiDamageLevel = 3;
98
+ settings.mDeblurLevel = 0;
99
+ await reader.updateRuntimeSettings(settings);
100
+
101
+ return {
102
+ name: "dbr",
103
+ async decodeFrame(frame) {
104
+ let results = await reader.decode(frame);
105
+
106
+ return results.map(mapDbrResult);
107
+ },
108
+ async decodeImage(file) {
109
+ let results = await reader.decode(file);
110
+
111
+ return results.map(mapDbrResult);
112
+ },
113
+ dispose() {
114
+ reader.deleteInstance();
115
+ },
116
+ } satisfies BarcodeDecoder;
117
+ };
118
+ }