@olenbetong/synergi-react 3.2.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/chrome/AppShell/index.d.ts +10 -2
- package/es/chrome/AppShell/index.js +13 -97
- package/es/chrome/openReport.d.ts +22 -0
- package/es/chrome/openReport.js +21 -0
- package/es/colorScheme.d.ts +4 -4
- package/es/components/DateNavigator/index.js +1 -1
- package/es/components/FilePond.js +1 -1
- package/es/components/ImageEditor/ImageEditor.js +1 -1
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +1 -1
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +1 -1
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +1 -1
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
- package/es/components/MergeProgressDialog/index.js +1 -1
- package/es/components/Toolbar/index.d.ts +20 -11
- package/es/components/Toolbar/index.js +47 -6
- package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
- package/es/elements/ElementDamage/DescriptionInput.js +1 -1
- package/es/elements/ElementDamage/DuplicateDamage/DesktopView.js +1 -1
- package/es/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.js +1 -1
- package/es/elements/ElementDamage/DuplicateDamage/PhoneView.js +1 -1
- package/es/elements/ElementDamage/ElementNumberTextField.js +1 -1
- package/es/elements/ElementDamage/RegisterFix.js +1 -1
- package/es/elements/ElementDamage/SubmitButtons.js +1 -1
- package/es/elements/ElementDamage/TransportElementSelect.js +1 -1
- package/es/elements/ElementLookup.d.ts +7 -2
- package/es/elements/ElementLookup.js +5 -7
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoder.d.ts +32 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.d.ts +28 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.js +81 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.d.ts +26 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.js +70 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.d.ts +20 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +69 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +103 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.d.ts +6 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.js +19 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +14 -7
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +11 -7
- package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.d.ts +14 -12
- package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.js +223 -117
- package/es/elements/ElementLookupDialog/HIDScanner/index.js +1 -1
- package/es/elements/ElementLookupDialog/Manual/ManualForm.js +1 -1
- package/es/elements/ElementLookupDialog/index.d.ts +6 -0
- package/es/elements/ElementLookupDialog/index.js +3 -3
- package/es/elements/ElementLookupDialog/utils/Giai.js +1 -1
- package/es/elements/ProjectSelect.js +1 -1
- package/es/i18n.d.ts +6 -0
- package/es/i18n.js +10 -0
- package/es/index.d.ts +3 -4
- package/es/index.js +5 -4
- package/package.json +9 -8
- package/src/chrome/AppShell/index.tsx +13 -134
- package/src/chrome/openReport.ts +34 -0
- package/src/colorScheme.ts +4 -4
- package/src/components/DateNavigator/index.tsx +1 -1
- package/src/components/FilePond.tsx +1 -1
- package/src/components/ImageEditor/ImageEditor.tsx +1 -1
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +1 -1
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +1 -1
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +1 -1
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +1 -1
- package/src/components/MergeProgressDialog/index.tsx +1 -1
- package/src/components/Toolbar/index.tsx +65 -14
- package/src/elements/ElementDamage/DamageFormButtons.tsx +1 -1
- package/src/elements/ElementDamage/DescriptionInput.tsx +1 -1
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +1 -1
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +1 -1
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +1 -1
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +1 -1
- package/src/elements/ElementDamage/RegisterFix.tsx +1 -1
- package/src/elements/ElementDamage/SubmitButtons.tsx +1 -1
- package/src/elements/ElementDamage/TransportElementSelect.tsx +1 -1
- package/src/elements/ElementLookup.tsx +13 -6
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +30 -15
- package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +247 -137
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +1 -1
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +1 -1
- package/src/elements/ElementLookupDialog/index.tsx +13 -5
- package/src/elements/ElementLookupDialog/utils/Giai.ts +1 -1
- package/src/elements/ProjectSelect.tsx +1 -1
- package/src/i18n.ts +13 -0
- package/src/index.ts +6 -37
- package/es/chrome/AppMenu/AppMenu.css +0 -648
- package/es/chrome/AppMenu/AppMenu.d.ts +0 -56
- package/es/chrome/AppMenu/AppMenu.js +0 -145
- package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +0 -2
- package/es/chrome/AppMenu/AppMenuColorScheme.js +0 -18
- package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +0 -18
- package/es/chrome/AppMenu/AppMenuFavoriteButton.js +0 -11
- package/es/chrome/AppMenu/AppMenuHeader.d.ts +0 -24
- package/es/chrome/AppMenu/AppMenuHeader.js +0 -18
- package/es/chrome/AppMenu/AppMenuList.d.ts +0 -18
- package/es/chrome/AppMenu/AppMenuList.js +0 -39
- package/es/chrome/AppMenu/AppMenuRail.d.ts +0 -26
- package/es/chrome/AppMenu/AppMenuRail.js +0 -30
- package/es/chrome/AppMenu/AppMenuToggle.d.ts +0 -15
- package/es/chrome/AppMenu/AppMenuToggle.js +0 -14
- package/es/chrome/AppMenu/AppMenuUserMenu.d.ts +0 -32
- package/es/chrome/AppMenu/AppMenuUserMenu.js +0 -110
- package/es/chrome/AppMenu/developerCategories.d.ts +0 -24
- package/es/chrome/AppMenu/developerCategories.js +0 -116
- package/es/chrome/AppMenu/icons.d.ts +0 -15
- package/es/chrome/AppMenu/icons.js +0 -13
- package/es/chrome/AppMenu/index.d.ts +0 -12
- package/es/chrome/AppMenu/index.js +0 -10
- package/es/chrome/AppMenu/menuEntries.d.ts +0 -51
- package/es/chrome/AppMenu/menuEntries.js +0 -93
- package/es/chrome/AppMenu/types.d.ts +0 -43
- package/es/chrome/AppMenu/useFavorites.d.ts +0 -13
- package/es/chrome/AppMenu/useFavorites.js +0 -28
- package/es/chrome/AppMenu/useRovingTabIndex.d.ts +0 -28
- package/es/chrome/AppMenu/useRovingTabIndex.js +0 -114
- package/es/chrome/AppMenu/useServiceWorkerUpdate.d.ts +0 -16
- package/es/chrome/AppMenu/useServiceWorkerUpdate.js +0 -62
- package/es/report/ReportLauncher.css +0 -147
- package/es/report/ReportLauncher.d.ts +0 -55
- package/es/report/ReportLauncher.js +0 -142
- package/es/report/ReportLauncher.test.js +0 -231
- package/es/report/ReportParameters.css +0 -29
- package/es/report/ReportParameters.d.ts +0 -46
- package/es/report/ReportParameters.js +0 -65
- package/es/report/ReportParameters.test.d.ts +0 -1
- package/es/report/ReportParameters.test.js +0 -84
- package/es/report/index.d.ts +0 -2
- package/es/report/index.js +0 -2
- package/src/chrome/AppMenu/AppMenu.css +0 -648
- package/src/chrome/AppMenu/AppMenu.tsx +0 -285
- package/src/chrome/AppMenu/AppMenuColorScheme.tsx +0 -41
- package/src/chrome/AppMenu/AppMenuFavoriteButton.tsx +0 -47
- package/src/chrome/AppMenu/AppMenuHeader.tsx +0 -79
- package/src/chrome/AppMenu/AppMenuList.tsx +0 -89
- package/src/chrome/AppMenu/AppMenuRail.tsx +0 -117
- package/src/chrome/AppMenu/AppMenuToggle.tsx +0 -51
- package/src/chrome/AppMenu/AppMenuUserMenu.tsx +0 -190
- package/src/chrome/AppMenu/developerCategories.ts +0 -142
- package/src/chrome/AppMenu/icons.tsx +0 -76
- package/src/chrome/AppMenu/index.ts +0 -17
- package/src/chrome/AppMenu/menuEntries.ts +0 -128
- package/src/chrome/AppMenu/types.ts +0 -45
- package/src/chrome/AppMenu/useFavorites.ts +0 -40
- package/src/chrome/AppMenu/useRovingTabIndex.ts +0 -130
- package/src/chrome/AppMenu/useServiceWorkerUpdate.ts +0 -68
- package/src/report/ReportLauncher.css +0 -147
- package/src/report/ReportLauncher.test.tsx +0 -281
- package/src/report/ReportLauncher.tsx +0 -420
- package/src/report/ReportParameters.css +0 -29
- package/src/report/ReportParameters.test.tsx +0 -133
- package/src/report/ReportParameters.tsx +0 -198
- package/src/report/index.ts +0 -2
- /package/es/{chrome/AppMenu/types.js → elements/ElementLookupDialog/BarcodeScanner/decoder.js} +0 -0
- /package/es/{report/ReportLauncher.test.d.ts → elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts} +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DecodedBarcode, DecoderFactory } from "../decoder";
|
|
2
|
+
export type DbrDecoderOptions = {
|
|
3
|
+
/** URL of the Dynamsoft Barcode Reader 6.x script, e.g. `/lib/dbr/dbr-6.5.1.min.js`. */
|
|
4
|
+
scriptUrl: string;
|
|
5
|
+
licenseKey: string;
|
|
6
|
+
};
|
|
7
|
+
/** The parts of a Dynamsoft `TextResult` the mapper reads, typed locally so the vendor types stay out of the public API. */
|
|
8
|
+
export type DbrTextResult = {
|
|
9
|
+
BarcodeText: string;
|
|
10
|
+
BarcodeFormat: number;
|
|
11
|
+
LocalizationResult: {
|
|
12
|
+
X1: number;
|
|
13
|
+
Y1: number;
|
|
14
|
+
X2: number;
|
|
15
|
+
Y2: number;
|
|
16
|
+
X3: number;
|
|
17
|
+
Y3: number;
|
|
18
|
+
X4: number;
|
|
19
|
+
Y4: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare function mapDbrResult(result: DbrTextResult): DecodedBarcode;
|
|
23
|
+
/**
|
|
24
|
+
* Decoder backed by the legacy Dynamsoft Barcode Reader JavaScript SDK (6.x). Kept for A/B
|
|
25
|
+
* comparison against the free engines; the script is loaded on demand rather than by the article
|
|
26
|
+
* so users who never scan do not pay for it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createDbrDecoder({ scriptUrl, licenseKey }: DbrDecoderOptions): DecoderFactory;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
let scriptLoading;
|
|
2
|
+
function getGlobal() {
|
|
3
|
+
return window.BarcodeReader;
|
|
4
|
+
}
|
|
5
|
+
/** Loads the vendor script once, reusing `window.BarcodeReader` if the page already has it. */
|
|
6
|
+
function loadBarcodeReader(scriptUrl) {
|
|
7
|
+
let existing = getGlobal();
|
|
8
|
+
if (existing)
|
|
9
|
+
return Promise.resolve(existing);
|
|
10
|
+
if (!scriptLoading) {
|
|
11
|
+
scriptLoading = new Promise((resolve, reject) => {
|
|
12
|
+
let script = document.createElement("script");
|
|
13
|
+
script.src = scriptUrl;
|
|
14
|
+
script.async = true;
|
|
15
|
+
script.onload = () => {
|
|
16
|
+
let loaded = getGlobal();
|
|
17
|
+
if (loaded) {
|
|
18
|
+
resolve(loaded);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
scriptLoading = undefined;
|
|
22
|
+
reject(new Error(`${scriptUrl} did not define BarcodeReader`));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
script.onerror = () => {
|
|
26
|
+
scriptLoading = undefined;
|
|
27
|
+
script.remove();
|
|
28
|
+
reject(new Error(`Failed to load ${scriptUrl}`));
|
|
29
|
+
};
|
|
30
|
+
document.head.append(script);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return scriptLoading;
|
|
34
|
+
}
|
|
35
|
+
export function mapDbrResult(result) {
|
|
36
|
+
let { X1, Y1, X2, Y2, X3, Y3, X4, Y4 } = result.LocalizationResult;
|
|
37
|
+
return {
|
|
38
|
+
text: result.BarcodeText,
|
|
39
|
+
format: String(result.BarcodeFormat),
|
|
40
|
+
corners: [
|
|
41
|
+
{ x: X1, y: Y1 },
|
|
42
|
+
{ x: X2, y: Y2 },
|
|
43
|
+
{ x: X3, y: Y3 },
|
|
44
|
+
{ x: X4, y: Y4 },
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Decoder backed by the legacy Dynamsoft Barcode Reader JavaScript SDK (6.x). Kept for A/B
|
|
50
|
+
* comparison against the free engines; the script is loaded on demand rather than by the article
|
|
51
|
+
* so users who never scan do not pay for it.
|
|
52
|
+
*/
|
|
53
|
+
export function createDbrDecoder({ scriptUrl, licenseKey }) {
|
|
54
|
+
return async () => {
|
|
55
|
+
if (typeof WebAssembly === "undefined") {
|
|
56
|
+
throw new Error("WebAssembly is not supported");
|
|
57
|
+
}
|
|
58
|
+
let BarcodeReader = await loadBarcodeReader(scriptUrl);
|
|
59
|
+
BarcodeReader.licenseKey = licenseKey;
|
|
60
|
+
let reader = await BarcodeReader.createInstance();
|
|
61
|
+
let settings = reader.getRuntimeSettings();
|
|
62
|
+
settings.mBarcodeFormatIds = BarcodeReader.EnumBarcodeFormat.DATAMATRIX;
|
|
63
|
+
settings.mAntiDamageLevel = 3;
|
|
64
|
+
settings.mDeblurLevel = 0;
|
|
65
|
+
await reader.updateRuntimeSettings(settings);
|
|
66
|
+
return {
|
|
67
|
+
name: "dbr",
|
|
68
|
+
async decodeFrame(frame) {
|
|
69
|
+
let results = await reader.decode(frame);
|
|
70
|
+
return results.map(mapDbrResult);
|
|
71
|
+
},
|
|
72
|
+
async decodeImage(file) {
|
|
73
|
+
let results = await reader.decode(file);
|
|
74
|
+
return results.map(mapDbrResult);
|
|
75
|
+
},
|
|
76
|
+
dispose() {
|
|
77
|
+
reader.deleteInstance();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DecodedBarcode, DecoderFactory } from "../decoder";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal typing of the Barcode Detection API. It is not part of the TypeScript DOM lib because
|
|
4
|
+
* only Chromium-based browsers implement it.
|
|
5
|
+
*/
|
|
6
|
+
export type NativeDetectedBarcode = {
|
|
7
|
+
rawValue: string;
|
|
8
|
+
format: string;
|
|
9
|
+
cornerPoints: Array<{
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}>;
|
|
13
|
+
boundingBox: DOMRectReadOnly;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Whether the browser can detect DataMatrix codes natively. Chrome on desktop exposes the
|
|
17
|
+
* `BarcodeDetector` class without any formats, so the class alone is not enough.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isNativeDecoderAvailable(): Promise<boolean>;
|
|
20
|
+
export declare function mapNativeResult(result: NativeDetectedBarcode): DecodedBarcode;
|
|
21
|
+
/**
|
|
22
|
+
* Decoder backed by the browser's own Barcode Detection API (ML Kit on Android). Nothing to
|
|
23
|
+
* download, but only available where the browser supports it — check `isNativeDecoderAvailable`
|
|
24
|
+
* first and fall back to another decoder when it returns false.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createNativeDecoder(): DecoderFactory;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getLocalizedString } from "../../../../i18n.js";
|
|
2
|
+
const DATA_MATRIX = "data_matrix";
|
|
3
|
+
function getNativeDetector() {
|
|
4
|
+
return globalThis.BarcodeDetector;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Whether the browser can detect DataMatrix codes natively. Chrome on desktop exposes the
|
|
8
|
+
* `BarcodeDetector` class without any formats, so the class alone is not enough.
|
|
9
|
+
*/
|
|
10
|
+
export async function isNativeDecoderAvailable() {
|
|
11
|
+
try {
|
|
12
|
+
let detector = getNativeDetector();
|
|
13
|
+
if (!detector)
|
|
14
|
+
return false;
|
|
15
|
+
let formats = await detector.getSupportedFormats();
|
|
16
|
+
return formats.includes(DATA_MATRIX);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function mapNativeResult(result) {
|
|
23
|
+
let points = result.cornerPoints;
|
|
24
|
+
let { left, top, right, bottom } = result.boundingBox;
|
|
25
|
+
let corners = points.length >= 4
|
|
26
|
+
? [
|
|
27
|
+
{ x: points[0].x, y: points[0].y },
|
|
28
|
+
{ x: points[1].x, y: points[1].y },
|
|
29
|
+
{ x: points[2].x, y: points[2].y },
|
|
30
|
+
{ x: points[3].x, y: points[3].y },
|
|
31
|
+
]
|
|
32
|
+
: [
|
|
33
|
+
{ x: left, y: top },
|
|
34
|
+
{ x: right, y: top },
|
|
35
|
+
{ x: right, y: bottom },
|
|
36
|
+
{ x: left, y: bottom },
|
|
37
|
+
];
|
|
38
|
+
return { text: result.rawValue, format: result.format, corners };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Decoder backed by the browser's own Barcode Detection API (ML Kit on Android). Nothing to
|
|
42
|
+
* download, but only available where the browser supports it — check `isNativeDecoderAvailable`
|
|
43
|
+
* first and fall back to another decoder when it returns false.
|
|
44
|
+
*/
|
|
45
|
+
export function createNativeDecoder() {
|
|
46
|
+
return async () => {
|
|
47
|
+
let Detector = getNativeDetector();
|
|
48
|
+
if (!Detector || !(await isNativeDecoderAvailable())) {
|
|
49
|
+
throw new Error(getLocalizedString("This browser cannot detect barcodes natively"));
|
|
50
|
+
}
|
|
51
|
+
let detector = new Detector({ formats: [DATA_MATRIX] });
|
|
52
|
+
return {
|
|
53
|
+
name: "native",
|
|
54
|
+
async decodeFrame(frame) {
|
|
55
|
+
let results = await detector.detect(frame);
|
|
56
|
+
return results.map(mapNativeResult);
|
|
57
|
+
},
|
|
58
|
+
async decodeImage(file) {
|
|
59
|
+
let bitmap = await createImageBitmap(file);
|
|
60
|
+
try {
|
|
61
|
+
let results = await detector.detect(bitmap);
|
|
62
|
+
return results.map(mapNativeResult);
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
bitmap.close();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReaderOptions, ReadResult } from "zxing-wasm/reader";
|
|
2
|
+
import type { DecodedBarcode, DecoderFactory } from "../decoder";
|
|
3
|
+
export type ZxingDecoderOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* URL of `zxing_reader.wasm`. When omitted, zxing-wasm fetches the binary matching its own version
|
|
6
|
+
* from the jsDelivr CDN.
|
|
7
|
+
*/
|
|
8
|
+
wasmUrl?: string;
|
|
9
|
+
/** Reader options for live camera frames. Merged over the defaults. */
|
|
10
|
+
frameOptions?: ReaderOptions;
|
|
11
|
+
/** Reader options for still images. Merged over the defaults. */
|
|
12
|
+
imageOptions?: ReaderOptions;
|
|
13
|
+
};
|
|
14
|
+
export declare function mapZxingResult(result: ReadResult): DecodedBarcode;
|
|
15
|
+
/**
|
|
16
|
+
* Decoder backed by zxing-cpp compiled to WebAssembly (`zxing-wasm`). Free, runs everywhere
|
|
17
|
+
* WebAssembly does, including iOS Safari. The module is imported when the factory runs, so apps
|
|
18
|
+
* that never open the scanner do not download it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createZxingDecoder(options?: ZxingDecoderOptions): DecoderFactory;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const defaultFrameOptions = {
|
|
2
|
+
formats: ["DataMatrix"],
|
|
3
|
+
tryHarder: false,
|
|
4
|
+
tryRotate: true,
|
|
5
|
+
tryInvert: false,
|
|
6
|
+
tryDownscale: true,
|
|
7
|
+
maxNumberOfSymbols: 4,
|
|
8
|
+
};
|
|
9
|
+
const defaultImageOptions = {
|
|
10
|
+
formats: ["DataMatrix"],
|
|
11
|
+
tryHarder: true,
|
|
12
|
+
tryRotate: true,
|
|
13
|
+
tryInvert: true,
|
|
14
|
+
tryDownscale: true,
|
|
15
|
+
maxNumberOfSymbols: 8,
|
|
16
|
+
};
|
|
17
|
+
export function mapZxingResult(result) {
|
|
18
|
+
let { topLeft, topRight, bottomRight, bottomLeft } = result.position;
|
|
19
|
+
return {
|
|
20
|
+
text: result.text,
|
|
21
|
+
format: result.format,
|
|
22
|
+
corners: [
|
|
23
|
+
{ x: topLeft.x, y: topLeft.y },
|
|
24
|
+
{ x: topRight.x, y: topRight.y },
|
|
25
|
+
{ x: bottomRight.x, y: bottomRight.y },
|
|
26
|
+
{ x: bottomLeft.x, y: bottomLeft.y },
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Decoder backed by zxing-cpp compiled to WebAssembly (`zxing-wasm`). Free, runs everywhere
|
|
32
|
+
* WebAssembly does, including iOS Safari. The module is imported when the factory runs, so apps
|
|
33
|
+
* that never open the scanner do not download it.
|
|
34
|
+
*/
|
|
35
|
+
export function createZxingDecoder(options = {}) {
|
|
36
|
+
let frameOptions = { ...defaultFrameOptions, ...options.frameOptions };
|
|
37
|
+
let imageOptions = { ...defaultImageOptions, ...options.imageOptions };
|
|
38
|
+
return async () => {
|
|
39
|
+
if (typeof WebAssembly === "undefined") {
|
|
40
|
+
throw new Error("WebAssembly is not supported");
|
|
41
|
+
}
|
|
42
|
+
let zxing = await import("zxing-wasm/reader");
|
|
43
|
+
let { wasmUrl } = options;
|
|
44
|
+
if (wasmUrl) {
|
|
45
|
+
zxing.prepareZXingModule({
|
|
46
|
+
overrides: {
|
|
47
|
+
locateFile: (path, prefix) => (path.endsWith(".wasm") ? wasmUrl : prefix + path),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// Instantiate up front so a broken download surfaces as a scanner error instead of on the first frame.
|
|
52
|
+
await zxing.prepareZXingModule({ fireImmediately: true });
|
|
53
|
+
return {
|
|
54
|
+
name: "zxing",
|
|
55
|
+
async decodeFrame(frame) {
|
|
56
|
+
let context = frame.getContext("2d", { willReadFrequently: true });
|
|
57
|
+
if (!context)
|
|
58
|
+
return [];
|
|
59
|
+
let imageData = context.getImageData(0, 0, frame.width, frame.height);
|
|
60
|
+
let results = await zxing.readBarcodes(imageData, frameOptions);
|
|
61
|
+
return results.filter((result) => result.isValid).map(mapZxingResult);
|
|
62
|
+
},
|
|
63
|
+
async decodeImage(file) {
|
|
64
|
+
let results = await zxing.readBarcodes(file, imageOptions);
|
|
65
|
+
return results.filter((result) => result.isValid).map(mapZxingResult);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { mapDbrResult } from "./decoders/dbr";
|
|
3
|
+
import { mapNativeResult } from "./decoders/native";
|
|
4
|
+
import { mapZxingResult } from "./decoders/zxing";
|
|
5
|
+
import { createDuplicateFilter } from "./duplicateFilter";
|
|
6
|
+
const GS = "";
|
|
7
|
+
const GIAI = `8004${"7043210"}${GS}${"12345"}`;
|
|
8
|
+
describe("result mapping", () => {
|
|
9
|
+
it("maps a zxing result to corners in reading order", () => {
|
|
10
|
+
let mapped = mapZxingResult({
|
|
11
|
+
text: GIAI,
|
|
12
|
+
format: "DataMatrix",
|
|
13
|
+
isValid: true,
|
|
14
|
+
position: {
|
|
15
|
+
topLeft: { x: 10, y: 20 },
|
|
16
|
+
topRight: { x: 110, y: 20 },
|
|
17
|
+
bottomRight: { x: 110, y: 120 },
|
|
18
|
+
bottomLeft: { x: 10, y: 120 },
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
expect(mapped.text).toBe(GIAI);
|
|
22
|
+
expect(mapped.format).toBe("DataMatrix");
|
|
23
|
+
expect(mapped.corners).toEqual([
|
|
24
|
+
{ x: 10, y: 20 },
|
|
25
|
+
{ x: 110, y: 20 },
|
|
26
|
+
{ x: 110, y: 120 },
|
|
27
|
+
{ x: 10, y: 120 },
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
it("maps a native result from its corner points", () => {
|
|
31
|
+
let result = {
|
|
32
|
+
rawValue: GIAI,
|
|
33
|
+
format: "data_matrix",
|
|
34
|
+
cornerPoints: [
|
|
35
|
+
{ x: 1, y: 2 },
|
|
36
|
+
{ x: 3, y: 2 },
|
|
37
|
+
{ x: 3, y: 4 },
|
|
38
|
+
{ x: 1, y: 4 },
|
|
39
|
+
],
|
|
40
|
+
boundingBox: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
41
|
+
};
|
|
42
|
+
expect(mapNativeResult(result)).toEqual({
|
|
43
|
+
text: GIAI,
|
|
44
|
+
format: "data_matrix",
|
|
45
|
+
corners: [
|
|
46
|
+
{ x: 1, y: 2 },
|
|
47
|
+
{ x: 3, y: 2 },
|
|
48
|
+
{ x: 3, y: 4 },
|
|
49
|
+
{ x: 1, y: 4 },
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it("falls back to the bounding box when a native result has no corner points", () => {
|
|
54
|
+
let result = {
|
|
55
|
+
rawValue: GIAI,
|
|
56
|
+
format: "data_matrix",
|
|
57
|
+
cornerPoints: [],
|
|
58
|
+
boundingBox: { left: 5, top: 6, right: 15, bottom: 16 },
|
|
59
|
+
};
|
|
60
|
+
expect(mapNativeResult(result).corners).toEqual([
|
|
61
|
+
{ x: 5, y: 6 },
|
|
62
|
+
{ x: 15, y: 6 },
|
|
63
|
+
{ x: 15, y: 16 },
|
|
64
|
+
{ x: 5, y: 16 },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
it("maps a Dynamsoft result from its localization result", () => {
|
|
68
|
+
let mapped = mapDbrResult({
|
|
69
|
+
BarcodeText: GIAI,
|
|
70
|
+
BarcodeFormat: 134217728,
|
|
71
|
+
LocalizationResult: { X1: 1, Y1: 2, X2: 3, Y2: 2, X3: 3, Y3: 4, X4: 1, Y4: 4 },
|
|
72
|
+
});
|
|
73
|
+
expect(mapped.text).toBe(GIAI);
|
|
74
|
+
expect(mapped.corners).toEqual([
|
|
75
|
+
{ x: 1, y: 2 },
|
|
76
|
+
{ x: 3, y: 2 },
|
|
77
|
+
{ x: 3, y: 4 },
|
|
78
|
+
{ x: 1, y: 4 },
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("createDuplicateFilter", () => {
|
|
83
|
+
it("reports a code once while it stays in view", () => {
|
|
84
|
+
let isNew = createDuplicateFilter(1000);
|
|
85
|
+
expect(isNew("a", 0)).toBe(true);
|
|
86
|
+
expect(isNew("a", 100)).toBe(false);
|
|
87
|
+
expect(isNew("a", 900)).toBe(false);
|
|
88
|
+
// Still in view: every sighting refreshes the timer.
|
|
89
|
+
expect(isNew("a", 1500)).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
it("reports a code again once it has been out of view for the forget time", () => {
|
|
92
|
+
let isNew = createDuplicateFilter(1000);
|
|
93
|
+
expect(isNew("a", 0)).toBe(true);
|
|
94
|
+
expect(isNew("a", 1001)).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
it("tracks codes independently", () => {
|
|
97
|
+
let isNew = createDuplicateFilter(1000);
|
|
98
|
+
expect(isNew("a", 0)).toBe(true);
|
|
99
|
+
expect(isNew("b", 0)).toBe(true);
|
|
100
|
+
expect(isNew("a", 10)).toBe(false);
|
|
101
|
+
expect(isNew("b", 10)).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suppresses repeated reads of a code that stays in view. A value is reported once, and again only
|
|
3
|
+
* after it has been out of view for `forgetTime` milliseconds — every sighting refreshes the timer,
|
|
4
|
+
* matching the `duplicateForgetTime` behaviour of the Dynamsoft scanner the apps were built around.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createDuplicateFilter(forgetTime: number): (text: string, now: number) => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suppresses repeated reads of a code that stays in view. A value is reported once, and again only
|
|
3
|
+
* after it has been out of view for `forgetTime` milliseconds — every sighting refreshes the timer,
|
|
4
|
+
* matching the `duplicateForgetTime` behaviour of the Dynamsoft scanner the apps were built around.
|
|
5
|
+
*/
|
|
6
|
+
export function createDuplicateFilter(forgetTime) {
|
|
7
|
+
let lastSeen = new Map();
|
|
8
|
+
return function isNew(text, now) {
|
|
9
|
+
let previous = lastSeen.get(text);
|
|
10
|
+
lastSeen.set(text, now);
|
|
11
|
+
if (lastSeen.size > 64) {
|
|
12
|
+
for (let [key, seen] of lastSeen) {
|
|
13
|
+
if (now - seen > forgetTime)
|
|
14
|
+
lastSeen.delete(key);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return previous === undefined || now - previous > forgetTime;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { DecoderFactory } from "./decoder";
|
|
3
|
+
export type { BarcodeDecoder, DecodedBarcode, DecodedPoint, DecoderFactory } from "./decoder";
|
|
4
|
+
export { createDbrDecoder, type DbrDecoderOptions } from "./decoders/dbr";
|
|
5
|
+
export { createNativeDecoder, isNativeDecoderAvailable } from "./decoders/native";
|
|
6
|
+
export { createZxingDecoder, type ZxingDecoderOptions } from "./decoders/zxing";
|
|
7
7
|
export type BarcodeScannerProps = {
|
|
8
8
|
onRead: (barcode: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Engine used to decode the camera frames. Defaults to zxing-wasm. Pass a stable reference and
|
|
11
|
+
* change it only to switch engine — the decoder is recreated whenever it changes.
|
|
12
|
+
*/
|
|
13
|
+
decoder?: DecoderFactory;
|
|
14
|
+
/** Extra controls rendered in the scanner footer, next to the engine name — e.g. an engine picker. */
|
|
15
|
+
actions?: ReactNode;
|
|
9
16
|
};
|
|
10
|
-
export declare function BarcodeScanner({ onRead }: BarcodeScannerProps): import("react").JSX.Element;
|
|
17
|
+
export declare function BarcodeScanner({ onRead, decoder, actions }: BarcodeScannerProps): import("react").JSX.Element;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import SwitchCameraOutlined from "@mui/icons-material/SwitchCameraOutlined";
|
|
3
|
-
import { Box, IconButton } from "@mui/material";
|
|
4
|
-
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
|
+
import { Box, IconButton, Typography } from "@mui/material";
|
|
5
4
|
import { useRef } from "react";
|
|
6
5
|
import { ErrorIcon } from "./Error";
|
|
7
6
|
import { useScanner } from "./useScanner";
|
|
7
|
+
import { getLocalizedString } from "../../../i18n.js";
|
|
8
|
+
export { createDbrDecoder } from "./decoders/dbr";
|
|
9
|
+
export { createNativeDecoder, isNativeDecoderAvailable } from "./decoders/native";
|
|
10
|
+
export { createZxingDecoder } from "./decoders/zxing";
|
|
8
11
|
const frameSx = {
|
|
9
12
|
position: "absolute",
|
|
10
13
|
bottom: 0,
|
|
@@ -13,16 +16,17 @@ const frameSx = {
|
|
|
13
16
|
top: 0,
|
|
14
17
|
height: "100%",
|
|
15
18
|
width: "100%",
|
|
19
|
+
objectFit: "contain",
|
|
16
20
|
};
|
|
17
|
-
export function BarcodeScanner({ onRead }) {
|
|
18
|
-
let
|
|
21
|
+
export function BarcodeScanner({ onRead, decoder, actions }) {
|
|
22
|
+
let video = useRef(null);
|
|
19
23
|
let canvas = useRef(null);
|
|
20
|
-
let { devices, error, setNextDevice } = useScanner(
|
|
24
|
+
let { devices, engine, error, setNextDevice } = useScanner(video, canvas, onRead, decoder);
|
|
21
25
|
return (_jsxs(Box, { sx: {
|
|
22
26
|
position: "relative",
|
|
23
27
|
bgcolor: "black",
|
|
24
28
|
height: "100%",
|
|
25
|
-
}, children: [_jsxs(Box, { sx: { height: "100%" },
|
|
29
|
+
}, children: [_jsxs(Box, { sx: { height: "100%" }, children: [_jsx(Box, { component: "video", playsInline: true, muted: true, autoPlay: true, sx: frameSx, ref: video }), _jsx(Box, { component: "canvas", sx: frameSx, ref: canvas }), error && _jsx(ErrorIcon, { ...error })] }), _jsxs(Box, { sx: {
|
|
26
30
|
display: "flex",
|
|
27
31
|
alignItems: "center",
|
|
28
32
|
justifyContent: "space-between",
|
|
@@ -33,5 +37,5 @@ export function BarcodeScanner({ onRead }) {
|
|
|
33
37
|
py: 1,
|
|
34
38
|
px: 3,
|
|
35
39
|
color: "white",
|
|
36
|
-
}, children: [devices.length <= 1 && _jsx("span", {}), devices.length > 1 && (_jsx(IconButton, { color: "inherit", "aria-label": getLocalizedString("Switch camera"), onClick: () => setNextDevice(), size: "large", children: _jsx(SwitchCameraOutlined, {}) }))] })] }));
|
|
40
|
+
}, children: [devices.length <= 1 && _jsx("span", {}), devices.length > 1 && (_jsx(IconButton, { color: "inherit", "aria-label": getLocalizedString("Switch camera"), onClick: () => setNextDevice(), size: "large", children: _jsx(SwitchCameraOutlined, {}) })), _jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [engine && (_jsx(Typography, { variant: "caption", sx: { opacity: 0.7 }, "data-testid": "barcode-engine", children: engine })), actions] })] })] }));
|
|
37
41
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import type BarcodeReaderType from "dynamsoft-javascript-barcode";
|
|
2
1
|
import { type RefObject } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import type { DecoderFactory } from "./decoder";
|
|
3
|
+
export type ScannerError = {
|
|
4
|
+
message: string;
|
|
5
|
+
icon: "unsupported" | "camera" | "generic";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Drives the camera and the decode loop behind `BarcodeScanner`. The decoder is created from the
|
|
9
|
+
* factory and replaced whenever a different factory is passed, so callers must pass a stable
|
|
10
|
+
* reference (a module-level constant or a memoised value) and change it only to switch engine.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useScanner(videoRef: RefObject<HTMLVideoElement | null>, canvasRef: RefObject<HTMLCanvasElement | null>, onRead: (barcode: string) => void, decoderFactory?: DecoderFactory): {
|
|
13
|
+
devices: MediaDeviceInfo[];
|
|
14
|
+
engine: string | null;
|
|
15
|
+
error: ScannerError | null;
|
|
14
16
|
isLoading: boolean;
|
|
15
17
|
setNextDevice: () => void;
|
|
16
18
|
};
|