@chayns-components/scanner 5.0.0-beta.1265
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/LICENSE +21 -0
- package/README.md +34 -0
- package/lib/cjs/components/code-scanner/CodeScanner.js +227 -0
- package/lib/cjs/components/code-scanner/CodeScanner.js.map +1 -0
- package/lib/cjs/components/code-scanner/CodeScanner.styles.js +34 -0
- package/lib/cjs/components/code-scanner/CodeScanner.styles.js.map +1 -0
- package/lib/cjs/components/code-scanner/scanner-toolbar/ScannerToolbar.js +149 -0
- package/lib/cjs/components/code-scanner/scanner-toolbar/ScannerToolbar.js.map +1 -0
- package/lib/cjs/components/code-scanner/scanner-toolbar/ScannerToolbar.styles.js +50 -0
- package/lib/cjs/components/code-scanner/scanner-toolbar/ScannerToolbar.styles.js.map +1 -0
- package/lib/cjs/constants/codeScanner.js +20 -0
- package/lib/cjs/constants/codeScanner.js.map +1 -0
- package/lib/cjs/hooks/codeScanner.js +16 -0
- package/lib/cjs/hooks/codeScanner.js.map +1 -0
- package/lib/cjs/hooks/loadscript.js +44 -0
- package/lib/cjs/hooks/loadscript.js.map +1 -0
- package/lib/cjs/index.js +33 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/types/barcode.d.js +6 -0
- package/lib/cjs/types/barcode.d.js.map +1 -0
- package/lib/cjs/types/codeScanner.js +14 -0
- package/lib/cjs/types/codeScanner.js.map +1 -0
- package/lib/cjs/types/global.d.js +2 -0
- package/lib/cjs/types/global.d.js.map +1 -0
- package/lib/cjs/utils/animate.js +25 -0
- package/lib/cjs/utils/animate.js.map +1 -0
- package/lib/cjs/utils/errorDialog.js +13 -0
- package/lib/cjs/utils/errorDialog.js.map +1 -0
- package/lib/cjs/utils/loadScript.js +15 -0
- package/lib/cjs/utils/loadScript.js.map +1 -0
- package/lib/cjs/utils/support.js +11 -0
- package/lib/cjs/utils/support.js.map +1 -0
- package/lib/esm/components/code-scanner/CodeScanner.js +218 -0
- package/lib/esm/components/code-scanner/CodeScanner.js.map +1 -0
- package/lib/esm/components/code-scanner/CodeScanner.styles.js +27 -0
- package/lib/esm/components/code-scanner/CodeScanner.styles.js.map +1 -0
- package/lib/esm/components/code-scanner/scanner-toolbar/ScannerToolbar.js +141 -0
- package/lib/esm/components/code-scanner/scanner-toolbar/ScannerToolbar.js.map +1 -0
- package/lib/esm/components/code-scanner/scanner-toolbar/ScannerToolbar.styles.js +43 -0
- package/lib/esm/components/code-scanner/scanner-toolbar/ScannerToolbar.styles.js.map +1 -0
- package/lib/esm/constants/codeScanner.js +14 -0
- package/lib/esm/constants/codeScanner.js.map +1 -0
- package/lib/esm/hooks/codeScanner.js +10 -0
- package/lib/esm/hooks/codeScanner.js.map +1 -0
- package/lib/esm/hooks/loadscript.js +37 -0
- package/lib/esm/hooks/loadscript.js.map +1 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/types/barcode.d.js +4 -0
- package/lib/esm/types/barcode.d.js.map +1 -0
- package/lib/esm/types/codeScanner.js +8 -0
- package/lib/esm/types/codeScanner.js.map +1 -0
- package/lib/esm/types/global.d.js +2 -0
- package/lib/esm/types/global.d.js.map +1 -0
- package/lib/esm/utils/animate.js +18 -0
- package/lib/esm/utils/animate.js.map +1 -0
- package/lib/esm/utils/errorDialog.js +6 -0
- package/lib/esm/utils/errorDialog.js.map +1 -0
- package/lib/esm/utils/loadScript.js +8 -0
- package/lib/esm/utils/loadScript.js.map +1 -0
- package/lib/esm/utils/support.js +3 -0
- package/lib/esm/utils/support.js.map +1 -0
- package/lib/types/components/code-scanner/CodeScanner.d.ts +54 -0
- package/lib/types/components/code-scanner/CodeScanner.styles.d.ts +7 -0
- package/lib/types/components/code-scanner/scanner-toolbar/ScannerToolbar.d.ts +45 -0
- package/lib/types/components/code-scanner/scanner-toolbar/ScannerToolbar.styles.d.ts +7 -0
- package/lib/types/constants/codeScanner.d.ts +3 -0
- package/lib/types/hooks/codeScanner.d.ts +2 -0
- package/lib/types/hooks/loadscript.d.ts +4 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/types/codeScanner.d.ts +16 -0
- package/lib/types/utils/animate.d.ts +1 -0
- package/lib/types/utils/errorDialog.d.ts +1 -0
- package/lib/types/utils/loadScript.d.ts +1 -0
- package/lib/types/utils/support.d.ts +2 -0
- package/package.json +87 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Icon, selectFiles } from '@chayns-components/core';
|
|
3
|
+
import { StyledScannerToolbar, StyledScannerToolbarButton } from './ScannerToolbar.styles';
|
|
4
|
+
import { checkTrackSupport } from '../../../utils/support';
|
|
5
|
+
import { animateNumericValue } from '../../../utils/animate';
|
|
6
|
+
import usePrevious from '../../../hooks/codeScanner';
|
|
7
|
+
const ScannerToolbar = ({
|
|
8
|
+
videoConstraints,
|
|
9
|
+
onFileSelect,
|
|
10
|
+
isScanningFile,
|
|
11
|
+
hasScannerError = false,
|
|
12
|
+
stream,
|
|
13
|
+
minZoom: minZoomProp = 1,
|
|
14
|
+
maxZoom: maxZoomProp = 3,
|
|
15
|
+
isZoomDisabled = false,
|
|
16
|
+
isTorchDisabled = false,
|
|
17
|
+
isFileSelectDisabled = false
|
|
18
|
+
}) => {
|
|
19
|
+
const [tracks, setTrack] = useState();
|
|
20
|
+
const [isZoomed, setIsZoomed] = useState();
|
|
21
|
+
const previousIsZoomed = usePrevious(isZoomed);
|
|
22
|
+
const [isZoomSupported, setIsZoomSupported] = useState(false);
|
|
23
|
+
const [isTorchActive, setIsTorchActive] = useState(false);
|
|
24
|
+
const [isTorchSupported, setIsTorchSupported] = useState(false);
|
|
25
|
+
const [isImageSelectActive, setIsImageSelectActive] = useState(false);
|
|
26
|
+
const minZoom = useRef(minZoomProp);
|
|
27
|
+
const maxZoom = useRef(maxZoomProp);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (hasScannerError) {
|
|
30
|
+
setIsTorchSupported(false);
|
|
31
|
+
setIsZoomSupported(false);
|
|
32
|
+
setIsZoomed(false);
|
|
33
|
+
setTrack(undefined);
|
|
34
|
+
} else if (stream) {
|
|
35
|
+
const videoTracks = stream.getVideoTracks();
|
|
36
|
+
let canZoom = false;
|
|
37
|
+
let canTorch = false;
|
|
38
|
+
videoTracks.forEach(track => {
|
|
39
|
+
if (checkTrackSupport(track, 'zoom')) {
|
|
40
|
+
canZoom = true;
|
|
41
|
+
const capabilities = track.getCapabilities();
|
|
42
|
+
if (capabilities.zoom.min > minZoomProp) {
|
|
43
|
+
minZoom.current = capabilities.zoom.min;
|
|
44
|
+
}
|
|
45
|
+
if (capabilities.zoom.max < maxZoomProp) {
|
|
46
|
+
maxZoom.current = capabilities.zoom.max;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (checkTrackSupport(track, 'torch')) {
|
|
50
|
+
canTorch = true;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (canZoom && !isZoomDisabled) {
|
|
54
|
+
setIsZoomSupported(true);
|
|
55
|
+
setIsZoomed(false);
|
|
56
|
+
}
|
|
57
|
+
setIsTorchSupported(canTorch && !isTorchDisabled);
|
|
58
|
+
setTrack(videoTracks);
|
|
59
|
+
}
|
|
60
|
+
}, [videoConstraints, hasScannerError, stream, minZoomProp, maxZoomProp, isZoomDisabled, isTorchDisabled]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (tracks?.length && isZoomSupported) {
|
|
63
|
+
if (typeof previousIsZoomed === 'undefined') {
|
|
64
|
+
tracks.forEach(track => {
|
|
65
|
+
if (checkTrackSupport(track, 'zoom')) {
|
|
66
|
+
void track.applyConstraints({
|
|
67
|
+
advanced: [{
|
|
68
|
+
zoom: isZoomed ? maxZoom.current : minZoom.current
|
|
69
|
+
}]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
} else if (previousIsZoomed !== isZoomed) {
|
|
74
|
+
animateNumericValue(previousIsZoomed ? maxZoom.current : minZoom.current, isZoomed ? maxZoom.current : minZoom.current, 500, value => {
|
|
75
|
+
tracks.forEach(track => {
|
|
76
|
+
if (checkTrackSupport(track, 'zoom')) {
|
|
77
|
+
void track.applyConstraints({
|
|
78
|
+
advanced: [{
|
|
79
|
+
zoom: value
|
|
80
|
+
}]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, [isZoomSupported, isZoomed, previousIsZoomed, tracks]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (tracks?.length && isTorchSupported) {
|
|
90
|
+
tracks.forEach(track => {
|
|
91
|
+
if (checkTrackSupport(track, 'torch')) {
|
|
92
|
+
void track.applyConstraints({
|
|
93
|
+
advanced: [{
|
|
94
|
+
torch: isTorchActive
|
|
95
|
+
}]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}, [isTorchActive, isTorchSupported, tracks]);
|
|
101
|
+
return /*#__PURE__*/React.createElement(StyledScannerToolbar, null, /*#__PURE__*/React.createElement(StyledScannerToolbarButton, {
|
|
102
|
+
$isAvailable: isTorchSupported,
|
|
103
|
+
$isActive: isTorchActive,
|
|
104
|
+
onClick: () => {
|
|
105
|
+
setIsTorchActive(prev => !prev);
|
|
106
|
+
}
|
|
107
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
108
|
+
icons: ['far fa-lightbulb'],
|
|
109
|
+
size: 25
|
|
110
|
+
})), /*#__PURE__*/React.createElement(StyledScannerToolbarButton, {
|
|
111
|
+
$isAvailable: isZoomSupported,
|
|
112
|
+
$isActive: isZoomed,
|
|
113
|
+
onClick: () => {
|
|
114
|
+
setIsZoomed(prev => !prev);
|
|
115
|
+
}
|
|
116
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
117
|
+
icons: ['far fa-search-plus'],
|
|
118
|
+
size: 25
|
|
119
|
+
})), /*#__PURE__*/React.createElement(StyledScannerToolbarButton, {
|
|
120
|
+
$isAvailable: !isFileSelectDisabled,
|
|
121
|
+
$isActive: isImageSelectActive || isScanningFile,
|
|
122
|
+
onClick: () => {
|
|
123
|
+
setIsImageSelectActive(true);
|
|
124
|
+
selectFiles({
|
|
125
|
+
multiple: false,
|
|
126
|
+
type: 'image/*'
|
|
127
|
+
}).then(files => {
|
|
128
|
+
if (files && files[0]) {
|
|
129
|
+
onFileSelect(files[0]);
|
|
130
|
+
}
|
|
131
|
+
}).catch(console.error).finally(() => {
|
|
132
|
+
setIsImageSelectActive(false);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
136
|
+
icons: ['far fa-folder-image'],
|
|
137
|
+
size: 25
|
|
138
|
+
})));
|
|
139
|
+
};
|
|
140
|
+
export default ScannerToolbar;
|
|
141
|
+
//# sourceMappingURL=ScannerToolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScannerToolbar.js","names":["React","useEffect","useRef","useState","Icon","selectFiles","StyledScannerToolbar","StyledScannerToolbarButton","checkTrackSupport","animateNumericValue","usePrevious","ScannerToolbar","videoConstraints","onFileSelect","isScanningFile","hasScannerError","stream","minZoom","minZoomProp","maxZoom","maxZoomProp","isZoomDisabled","isTorchDisabled","isFileSelectDisabled","tracks","setTrack","isZoomed","setIsZoomed","previousIsZoomed","isZoomSupported","setIsZoomSupported","isTorchActive","setIsTorchActive","isTorchSupported","setIsTorchSupported","isImageSelectActive","setIsImageSelectActive","undefined","videoTracks","getVideoTracks","canZoom","canTorch","forEach","track","capabilities","getCapabilities","zoom","min","current","max","length","applyConstraints","advanced","value","torch","createElement","$isAvailable","$isActive","onClick","prev","icons","size","multiple","type","then","files","catch","console","error","finally"],"sources":["../../../../../src/components/code-scanner/scanner-toolbar/ScannerToolbar.tsx"],"sourcesContent":["import React, { FC, useEffect, useRef, useState } from 'react';\nimport { Icon, selectFiles } from '@chayns-components/core';\nimport { StyledScannerToolbar, StyledScannerToolbarButton } from './ScannerToolbar.styles';\nimport { checkTrackSupport } from '../../../utils/support';\nimport { animateNumericValue } from '../../../utils/animate';\nimport usePrevious from '../../../hooks/codeScanner';\n\ntype ScannerToolbarProps = {\n /**\n * Indicates whether the scanner currently has an active error.\n */\n hasScannerError?: boolean;\n /**\n * Disables the file select option if set to true.\n */\n isFileSelectDisabled?: boolean;\n /**\n * Disables the torch (flashlight) button if set to true.\n */\n isTorchDisabled?: boolean;\n /**\n * Indicates if a file is currently being scanned.\n */\n isScanningFile: boolean;\n /**\n * Disables the zoom slider if set to true.\n */\n isZoomDisabled?: boolean;\n /**\n * Maximum allowed zoom level for the camera.\n */\n maxZoom?: number;\n /**\n * Minimum allowed zoom level for the camera.\n */\n minZoom?: number;\n /**\n * Callback triggered when a file is selected for scanning.\n */\n onFileSelect: (file: File) => void;\n /**\n * The active media stream used by the scanner.\n */\n stream?: MediaStream;\n /**\n * Defines constraints for the video element, e.g., resolution or facing mode.\n */\n videoConstraints: MediaTrackConstraints;\n};\n\nconst ScannerToolbar: FC<ScannerToolbarProps> = ({\n videoConstraints,\n onFileSelect,\n isScanningFile,\n hasScannerError = false,\n stream,\n minZoom: minZoomProp = 1,\n maxZoom: maxZoomProp = 3,\n isZoomDisabled = false,\n isTorchDisabled = false,\n isFileSelectDisabled = false,\n}) => {\n const [tracks, setTrack] = useState<MediaStreamTrack[]>();\n const [isZoomed, setIsZoomed] = useState<boolean>();\n const previousIsZoomed = usePrevious(isZoomed);\n const [isZoomSupported, setIsZoomSupported] = useState(false);\n const [isTorchActive, setIsTorchActive] = useState(false);\n const [isTorchSupported, setIsTorchSupported] = useState(false);\n const [isImageSelectActive, setIsImageSelectActive] = useState(false);\n\n const minZoom = useRef(minZoomProp);\n const maxZoom = useRef(maxZoomProp);\n\n useEffect(() => {\n if (hasScannerError) {\n setIsTorchSupported(false);\n setIsZoomSupported(false);\n setIsZoomed(false);\n setTrack(undefined);\n } else if (stream) {\n const videoTracks = stream.getVideoTracks();\n\n let canZoom = false;\n let canTorch = false;\n\n videoTracks.forEach((track) => {\n if (checkTrackSupport(track, 'zoom')) {\n canZoom = true;\n\n const capabilities = track.getCapabilities();\n\n if (capabilities.zoom.min > minZoomProp) {\n minZoom.current = capabilities.zoom.min;\n }\n if (capabilities.zoom.max < maxZoomProp) {\n maxZoom.current = capabilities.zoom.max;\n }\n }\n if (checkTrackSupport(track, 'torch')) {\n canTorch = true;\n }\n });\n\n if (canZoom && !isZoomDisabled) {\n setIsZoomSupported(true);\n setIsZoomed(false);\n }\n\n setIsTorchSupported(canTorch && !isTorchDisabled);\n setTrack(videoTracks);\n }\n }, [\n videoConstraints,\n hasScannerError,\n stream,\n minZoomProp,\n maxZoomProp,\n isZoomDisabled,\n isTorchDisabled,\n ]);\n\n useEffect(() => {\n if (tracks?.length && isZoomSupported) {\n if (typeof previousIsZoomed === 'undefined') {\n tracks.forEach((track) => {\n if (checkTrackSupport(track, 'zoom')) {\n void track.applyConstraints({\n advanced: [{ zoom: isZoomed ? maxZoom.current : minZoom.current }],\n });\n }\n });\n } else if (previousIsZoomed !== isZoomed) {\n animateNumericValue(\n previousIsZoomed ? maxZoom.current : minZoom.current,\n isZoomed ? maxZoom.current : minZoom.current,\n 500,\n (value) => {\n tracks.forEach((track) => {\n if (checkTrackSupport(track, 'zoom')) {\n void track.applyConstraints({\n advanced: [{ zoom: value }],\n });\n }\n });\n },\n );\n }\n }\n }, [isZoomSupported, isZoomed, previousIsZoomed, tracks]);\n\n useEffect(() => {\n if (tracks?.length && isTorchSupported) {\n tracks.forEach((track) => {\n if (checkTrackSupport(track, 'torch')) {\n void track.applyConstraints({\n advanced: [{ torch: isTorchActive }],\n });\n }\n });\n }\n }, [isTorchActive, isTorchSupported, tracks]);\n\n return (\n <StyledScannerToolbar>\n <StyledScannerToolbarButton\n $isAvailable={isTorchSupported}\n $isActive={isTorchActive}\n onClick={() => {\n setIsTorchActive((prev) => !prev);\n }}\n >\n <Icon icons={['far fa-lightbulb']} size={25} />\n </StyledScannerToolbarButton>\n <StyledScannerToolbarButton\n $isAvailable={isZoomSupported}\n $isActive={isZoomed}\n onClick={() => {\n setIsZoomed((prev) => !prev);\n }}\n >\n <Icon icons={['far fa-search-plus']} size={25} />\n </StyledScannerToolbarButton>\n <StyledScannerToolbarButton\n $isAvailable={!isFileSelectDisabled}\n $isActive={isImageSelectActive || isScanningFile}\n onClick={() => {\n setIsImageSelectActive(true);\n selectFiles({\n multiple: false,\n type: 'image/*',\n })\n .then((files) => {\n if (files && files[0]) {\n onFileSelect(files[0]);\n }\n })\n .catch(console.error)\n .finally(() => {\n setIsImageSelectActive(false);\n });\n }}\n >\n <Icon icons={['far fa-folder-image']} size={25} />\n </StyledScannerToolbarButton>\n </StyledScannerToolbar>\n );\n};\n\nexport default ScannerToolbar;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC9D,SAASC,IAAI,EAAEC,WAAW,QAAQ,yBAAyB;AAC3D,SAASC,oBAAoB,EAAEC,0BAA0B,QAAQ,yBAAyB;AAC1F,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,OAAOC,WAAW,MAAM,4BAA4B;AA6CpD,MAAMC,cAAuC,GAAGA,CAAC;EAC7CC,gBAAgB;EAChBC,YAAY;EACZC,cAAc;EACdC,eAAe,GAAG,KAAK;EACvBC,MAAM;EACNC,OAAO,EAAEC,WAAW,GAAG,CAAC;EACxBC,OAAO,EAAEC,WAAW,GAAG,CAAC;EACxBC,cAAc,GAAG,KAAK;EACtBC,eAAe,GAAG,KAAK;EACvBC,oBAAoB,GAAG;AAC3B,CAAC,KAAK;EACF,MAAM,CAACC,MAAM,EAAEC,QAAQ,CAAC,GAAGtB,QAAQ,CAAqB,CAAC;EACzD,MAAM,CAACuB,QAAQ,EAAEC,WAAW,CAAC,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B,SAAS,EAAE/B,QAAS;IACpBgC,OAAO,EAAEA,CAAA,KAAM;MACX/B,WAAW,CAAEgC,IAAI,IAAK,CAACA,IAAI,CAAC;IAChC;EAAE,gBAEF3D,KAAA,CAAAuD,aAAA,CAACnD,IAAI;IAACwD,KAAK,EAAE,CAAC,oBAAoB,CAAE;IAACC,IAAI,EAAE;EAAG,CAAE,CACxB,CAAC,eAC7B7D,KAAA,CAAAuD,aAAA,CAAChD,0BAA0B;IACvBiD,YAAY,EAAE,CAACjC,oBAAqB;IACpCkC,SAAS,EAAEtB,mBAAmB,IAAIrB,cAAe;IACjD4C,OAAO,EAAEA,CAAA,KAAM;MACXtB,sBAAsB,CAAC,IAAI,CAAC;MAC5B/B,WAAW,CAAC;QACRyD,QAAQ,EAAE,KAAK;QACfC,IAAI,EAAE;MACV,CAAC,CAAC,CACGC,IAAI,CAAEC,KAAK,IAAK;QACb,IAAIA,KAAK,IAAIA,KAAK,CAAC,CAAC,CAAC,EAAE;UACnBpD,YAAY,CAACoD,KAAK,CAAC,CAAC,CAAC,CAAC;QAC1B;MACJ,CAAC,CAAC,CACDC,KAAK,CAACC,OAAO,CAACC,KAAK,CAAC,CACpBC,OAAO,CAAC,MAAM;QACXjC,sBAAsB,CAAC,KAAK,CAAC;MACjC,CAAC,CAAC;IACV;EAAE,gBAEFpC,KAAA,CAAAuD,aAAA,CAACnD,IAAI;IAACwD,KAAK,EAAE,CAAC,qBAAqB,CAAE;IAACC,IAAI,EAAE;EAAG,CAAE,CACzB,CACV,CAAC;AAE/B,CAAC;AAED,eAAelD,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
export const StyledScannerToolbar = styled.div`
|
|
3
|
+
position: absolute;
|
|
4
|
+
bottom: 0;
|
|
5
|
+
left: 0;
|
|
6
|
+
right: 0;
|
|
7
|
+
height: 85px;
|
|
8
|
+
padding: 20px;
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
|
|
12
|
+
color: white;
|
|
13
|
+
`;
|
|
14
|
+
export const StyledScannerToolbarButton = styled.div`
|
|
15
|
+
display: flex;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
align-items: center;
|
|
18
|
+
height: 45px;
|
|
19
|
+
width: 45px;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
border-radius: 50%;
|
|
22
|
+
|
|
23
|
+
${({
|
|
24
|
+
$isAvailable = false
|
|
25
|
+
}) => !$isAvailable && css`
|
|
26
|
+
cursor: default;
|
|
27
|
+
opacity: 0;
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
`};
|
|
30
|
+
|
|
31
|
+
${({
|
|
32
|
+
$isActive = false
|
|
33
|
+
}) => $isActive && css`
|
|
34
|
+
background-color: rgba(255, 255, 255, 0.2);
|
|
35
|
+
`};
|
|
36
|
+
|
|
37
|
+
text-shadow: 0 0 10px black;
|
|
38
|
+
|
|
39
|
+
i {
|
|
40
|
+
color: white;
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
//# sourceMappingURL=ScannerToolbar.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScannerToolbar.styles.js","names":["styled","css","StyledScannerToolbar","div","StyledScannerToolbarButton","$isAvailable","$isActive"],"sources":["../../../../../src/components/code-scanner/scanner-toolbar/ScannerToolbar.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\n\nexport const StyledScannerToolbar = styled.div`\n position: absolute;\n bottom: 0;\n left: 0;\n right: 0;\n height: 85px;\n padding: 20px;\n display: flex;\n justify-content: space-between;\n\n color: white;\n`;\n\ntype ScannerToolbarButtonProps = {\n $isAvailable?: boolean;\n $isActive?: boolean;\n};\n\nexport const StyledScannerToolbarButton = styled.div<ScannerToolbarButtonProps>`\n display: flex;\n justify-content: center;\n align-items: center;\n height: 45px;\n width: 45px;\n cursor: pointer;\n border-radius: 50%;\n\n ${({ $isAvailable = false }) =>\n !$isAvailable &&\n css`\n cursor: default;\n opacity: 0;\n pointer-events: none;\n `};\n\n ${({ $isActive = false }) =>\n $isActive &&\n css`\n background-color: rgba(255, 255, 255, 0.2);\n `};\n\n text-shadow: 0 0 10px black;\n\n i {\n color: white;\n }\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAE/C,OAAO,MAAMC,oBAAoB,GAAGF,MAAM,CAACG,GAAG;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAOD,OAAO,MAAMC,0BAA0B,GAAGJ,MAAM,CAACG,GAA8B;AAC/E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,CAAC;EAAEE,YAAY,GAAG;AAAM,CAAC,KACvB,CAACA,YAAY,IACbJ,GAAG;AACX;AACA;AACA;AACA,SAAS;AACT;AACA,MAAM,CAAC;EAAEK,SAAS,GAAG;AAAM,CAAC,KACpBA,SAAS,IACTL,GAAG;AACX;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const ALL_FORMATS = ['code_128', 'code_39', 'code_93', 'codabar', 'ean_13', 'ean_8', 'itf', 'qr_code', 'upc_a', 'upc_e'];
|
|
2
|
+
export const DEFAULT_VIDEO_CONSTRAINTS = {
|
|
3
|
+
facingMode: {
|
|
4
|
+
ideal: 'environment'
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
export const DEFAULT_TRACK_CONSTRAINTS = {
|
|
8
|
+
width: 640,
|
|
9
|
+
height: 480,
|
|
10
|
+
frameRate: 25,
|
|
11
|
+
noiseSuppression: false,
|
|
12
|
+
facingMode: 'environment'
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=codeScanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeScanner.js","names":["ALL_FORMATS","DEFAULT_VIDEO_CONSTRAINTS","facingMode","ideal","DEFAULT_TRACK_CONSTRAINTS","width","height","frameRate","noiseSuppression"],"sources":["../../../src/constants/codeScanner.ts"],"sourcesContent":["export const ALL_FORMATS: Array<BarcodeFormat> = [\n 'code_128',\n 'code_39',\n 'code_93',\n 'codabar',\n 'ean_13',\n 'ean_8',\n 'itf',\n 'qr_code',\n 'upc_a',\n 'upc_e',\n];\n\nexport const DEFAULT_VIDEO_CONSTRAINTS: MediaTrackConstraints = {\n facingMode: {\n ideal: 'environment',\n },\n};\n\nexport const DEFAULT_TRACK_CONSTRAINTS: MediaTrackConstraints = {\n width: 640,\n height: 480,\n frameRate: 25,\n noiseSuppression: false,\n facingMode: 'environment',\n};\n"],"mappings":"AAAA,OAAO,MAAMA,WAAiC,GAAG,CAC7C,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,OAAO,EACP,KAAK,EACL,SAAS,EACT,OAAO,EACP,OAAO,CACV;AAED,OAAO,MAAMC,yBAAgD,GAAG;EAC5DC,UAAU,EAAE;IACRC,KAAK,EAAE;EACX;AACJ,CAAC;AAED,OAAO,MAAMC,yBAAgD,GAAG;EAC5DC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE,GAAG;EACXC,SAAS,EAAE,EAAE;EACbC,gBAAgB,EAAE,KAAK;EACvBN,UAAU,EAAE;AAChB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeScanner.js","names":["useEffect","useRef","usePrevious","value","ref","current"],"sources":["../../../src/hooks/codeScanner.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nconst usePrevious = <T>(value: T): T | undefined => {\n const ref = useRef<T>();\n useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n};\n\nexport default usePrevious;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAEzC,MAAMC,WAAW,GAAOC,KAAQ,IAAoB;EAChD,MAAMC,GAAG,GAAGH,MAAM,CAAI,CAAC;EACvBD,SAAS,CAAC,MAAM;IACZI,GAAG,CAACC,OAAO,GAAGF,KAAK;EACvB,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EACX,OAAOC,GAAG,CAACC,OAAO;AACtB,CAAC;AAED,eAAeH,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { loadScript } from '../utils/loadScript';
|
|
3
|
+
const VERSION = 1;
|
|
4
|
+
let scannerPolyfillPromise;
|
|
5
|
+
let scannerWasmPromise;
|
|
6
|
+
const loadPolyfillScript = () => {
|
|
7
|
+
if (!scannerPolyfillPromise) {
|
|
8
|
+
scannerPolyfillPromise = loadScript(`https://api.chayns-static.space/polyfill/CodeScanner/v${VERSION}/barcode-detector-polyfill.js`);
|
|
9
|
+
}
|
|
10
|
+
return scannerPolyfillPromise;
|
|
11
|
+
};
|
|
12
|
+
const loadWasmScript = () => {
|
|
13
|
+
if (!scannerWasmPromise) {
|
|
14
|
+
scannerWasmPromise = loadScript(`https://api.chayns-static.space/polyfill/CodeScanner/v${VERSION}/zbar-wasm.js`);
|
|
15
|
+
}
|
|
16
|
+
return scannerWasmPromise;
|
|
17
|
+
};
|
|
18
|
+
export const useScannerPolyfill = () => {
|
|
19
|
+
const [wasmLoaded, setWasmLoaded] = useState(false);
|
|
20
|
+
const [polyfillLoaded, setPolyfillLoaded] = useState(false);
|
|
21
|
+
const loadQrCodeDetector = useCallback(async () => {
|
|
22
|
+
try {
|
|
23
|
+
await BarcodeDetector.getSupportedFormats();
|
|
24
|
+
} catch {
|
|
25
|
+
await loadWasmScript().then(() => setWasmLoaded(true));
|
|
26
|
+
await loadPolyfillScript().then(() => setPolyfillLoaded(true));
|
|
27
|
+
// @ts-expect-error polyfill is not defined in window
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
|
|
29
|
+
window.BarcodeDetector = barcodeDetectorPolyfill.BarcodeDetectorPolyfill;
|
|
30
|
+
}
|
|
31
|
+
}, []);
|
|
32
|
+
return {
|
|
33
|
+
loadQrCodeDetector,
|
|
34
|
+
loaded: polyfillLoaded && wasmLoaded
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=loadscript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadscript.js","names":["useCallback","useState","loadScript","VERSION","scannerPolyfillPromise","scannerWasmPromise","loadPolyfillScript","loadWasmScript","useScannerPolyfill","wasmLoaded","setWasmLoaded","polyfillLoaded","setPolyfillLoaded","loadQrCodeDetector","BarcodeDetector","getSupportedFormats","then","window","barcodeDetectorPolyfill","BarcodeDetectorPolyfill","loaded"],"sources":["../../../src/hooks/loadscript.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { loadScript } from '../utils/loadScript';\n\nconst VERSION = 1;\n\nlet scannerPolyfillPromise: Promise<Event | UIEvent> | undefined;\nlet scannerWasmPromise: Promise<Event | UIEvent> | undefined;\n\nconst loadPolyfillScript = () => {\n if (!scannerPolyfillPromise) {\n scannerPolyfillPromise = loadScript(\n `https://api.chayns-static.space/polyfill/CodeScanner/v${VERSION}/barcode-detector-polyfill.js`,\n );\n }\n\n return scannerPolyfillPromise;\n};\n\nconst loadWasmScript = () => {\n if (!scannerWasmPromise) {\n scannerWasmPromise = loadScript(\n `https://api.chayns-static.space/polyfill/CodeScanner/v${VERSION}/zbar-wasm.js`,\n );\n }\n\n return scannerWasmPromise;\n};\n\nexport const useScannerPolyfill = () => {\n const [wasmLoaded, setWasmLoaded] = useState(false);\n const [polyfillLoaded, setPolyfillLoaded] = useState(false);\n\n const loadQrCodeDetector = useCallback(async () => {\n try {\n await BarcodeDetector.getSupportedFormats();\n } catch {\n await loadWasmScript().then(() => setWasmLoaded(true));\n await loadPolyfillScript().then(() => setPolyfillLoaded(true));\n // @ts-expect-error polyfill is not defined in window\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access\n window.BarcodeDetector = barcodeDetectorPolyfill.BarcodeDetectorPolyfill;\n }\n }, []);\n\n return { loadQrCodeDetector, loaded: polyfillLoaded && wasmLoaded };\n};\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,OAAO;AAC7C,SAASC,UAAU,QAAQ,qBAAqB;AAEhD,MAAMC,OAAO,GAAG,CAAC;AAEjB,IAAIC,sBAA4D;AAChE,IAAIC,kBAAwD;AAE5D,MAAMC,kBAAkB,GAAGA,CAAA,KAAM;EAC7B,IAAI,CAACF,sBAAsB,EAAE;IACzBA,sBAAsB,GAAGF,UAAU,CAC/B,yDAAyDC,OAAO,+BACpE,CAAC;EACL;EAEA,OAAOC,sBAAsB;AACjC,CAAC;AAED,MAAMG,cAAc,GAAGA,CAAA,KAAM;EACzB,IAAI,CAACF,kBAAkB,EAAE;IACrBA,kBAAkB,GAAGH,UAAU,CAC3B,yDAAyDC,OAAO,eACpE,CAAC;EACL;EAEA,OAAOE,kBAAkB;AAC7B,CAAC;AAED,OAAO,MAAMG,kBAAkB,GAAGA,CAAA,KAAM;EACpC,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGT,QAAQ,CAAC,KAAK,CAAC;EACnD,MAAM,CAACU,cAAc,EAAEC,iBAAiB,CAAC,GAAGX,QAAQ,CAAC,KAAK,CAAC;EAE3D,MAAMY,kBAAkB,GAAGb,WAAW,CAAC,YAAY;IAC/C,IAAI;MACA,MAAMc,eAAe,CAACC,mBAAmB,CAAC,CAAC;IAC/C,CAAC,CAAC,MAAM;MACJ,MAAMR,cAAc,CAAC,CAAC,CAACS,IAAI,CAAC,MAAMN,aAAa,CAAC,IAAI,CAAC,CAAC;MACtD,MAAMJ,kBAAkB,CAAC,CAAC,CAACU,IAAI,CAAC,MAAMJ,iBAAiB,CAAC,IAAI,CAAC,CAAC;MAC9D;MACA;MACAK,MAAM,CAACH,eAAe,GAAGI,uBAAuB,CAACC,uBAAuB;IAC5E;EACJ,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IAAEN,kBAAkB;IAAEO,MAAM,EAAET,cAAc,IAAIF;EAAW,CAAC;AACvE,CAAC","ignoreList":[]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","CodeScanner","ALL_FORMATS","DEFAULT_TRACK_CONSTRAINTS","DEFAULT_VIDEO_CONSTRAINTS"],"sources":["../../src/index.ts"],"sourcesContent":["export { default as CodeScanner } from './components/code-scanner/CodeScanner';\nexport {\n ALL_FORMATS,\n DEFAULT_TRACK_CONSTRAINTS,\n DEFAULT_VIDEO_CONSTRAINTS,\n} from './constants/codeScanner';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,uCAAuC;AAC9E,SACIC,WAAW,EACXC,yBAAyB,EACzBC,yBAAyB,QACtB,yBAAyB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcode.d.js","names":[],"sources":["../../../src/types/barcode.d.ts"],"sourcesContent":["// This is necessary because Typescript refuses to import the file unless it has\n// an export, apparently. 🥲\nexport {};\n\ndeclare global {\n /**\n * The possible types of barcode format that can be detected using the\n * Barcode Detection API. This list may change in the future.\n * Adapted from: https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API\n */\n type BarcodeFormat =\n | 'code_128'\n | 'code_39'\n | 'code_93'\n | 'codabar'\n | 'ean_13'\n | 'ean_8'\n | 'itf'\n | 'qr_code'\n | 'upc_a'\n | 'upc_e'\n | 'unknown';\n\n /**\n * The return type of the Barcode Detect API `detect` function that\n * describes a barcode that has been recognized by the API.\n */\n interface DetectedBarcode {\n /**\n * A DOMRectReadOnly, which returns the dimensions of a rectangle\n * representing the extent of a detected barcode, aligned with the\n * image\n */\n boundingBox: DOMRectReadOnly;\n /**\n * The x and y co-ordinates of the four corner points of the detected\n * barcode relative to the image, starting with the top left and working\n * clockwise. This may not be square due to perspective distortions\n * within the image.\n */\n cornerPoints: {\n x: number;\n y: number;\n }[];\n /**\n * The detected barcode format\n */\n format: BarcodeFormat;\n\n /**\n * A string decoded from the barcode data\n */\n rawValue: string;\n }\n\n /**\n * Options for describing how a BarcodeDetector should be initialised\n */\n interface BarcodeDetectorOptions {\n /**\n * Which formats the barcode detector should detect\n */\n formats: BarcodeFormat[];\n }\n\n /**\n * The BarcodeDetector interface of the Barcode Detection API allows\n * detection of linear and two-dimensional barcodes in images.\n */\n class BarcodeDetector {\n /**\n * Initialize a Barcode Detector instance\n */\n constructor(options?: BarcodeDetectorOptions);\n\n /**\n * Retrieve the formats that are supported by the detector\n */\n static getSupportedFormats(): Promise<BarcodeFormat[]>;\n\n /**\n * Attempt to detect barcodes from an image source\n */\n public detect(source: ImageBitmapSource): Promise<DetectedBarcode[]>;\n }\n}\n"],"mappings":"AAAA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export let ScannerErrorType = /*#__PURE__*/function (ScannerErrorType) {
|
|
2
|
+
ScannerErrorType[ScannerErrorType["NO_CAMERA_ACCESS"] = 0] = "NO_CAMERA_ACCESS";
|
|
3
|
+
ScannerErrorType[ScannerErrorType["CAMERA_ALREADY_IN_USE"] = 1] = "CAMERA_ALREADY_IN_USE";
|
|
4
|
+
ScannerErrorType[ScannerErrorType["DEVICE_NOT_FOUND"] = 2] = "DEVICE_NOT_FOUND";
|
|
5
|
+
ScannerErrorType[ScannerErrorType["UNKNOWN"] = 3] = "UNKNOWN";
|
|
6
|
+
return ScannerErrorType;
|
|
7
|
+
}({});
|
|
8
|
+
//# sourceMappingURL=codeScanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeScanner.js","names":["ScannerErrorType"],"sources":["../../../src/types/codeScanner.ts"],"sourcesContent":["export type CodeReaderOnScanCallback = (code: {\n format: BarcodeFormat;\n value: string;\n}) => void | Promise<void>;\n\nexport enum ScannerErrorType {\n NO_CAMERA_ACCESS,\n CAMERA_ALREADY_IN_USE,\n DEVICE_NOT_FOUND,\n UNKNOWN,\n}\n\nexport interface ScannerErrorMessages {\n noPermission: string;\n alreadyInUse: string;\n cameraNotAvailable: string;\n noCodeFound: string;\n}\n"],"mappings":"AAKA,WAAYA,gBAAgB,0BAAhBA,gBAAgB;EAAhBA,gBAAgB,CAAhBA,gBAAgB;EAAhBA,gBAAgB,CAAhBA,gBAAgB;EAAhBA,gBAAgB,CAAhBA,gBAAgB;EAAhBA,gBAAgB,CAAhBA,gBAAgB;EAAA,OAAhBA,gBAAgB;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.js","names":[],"sources":["../../../src/types/global.d.ts"],"sourcesContent":["interface Window {\n BarcodeDetector: BarcodeDetector;\n}\n\ninterface MediaTrackCapabilities {\n zoom: {\n min: number;\n max: number;\n step?: number;\n };\n}\n\ninterface MediaTrackConstraintSet {\n zoom?: number;\n torch?: boolean;\n}\n\ninterface MediaTrackSettings {\n zoom: number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const animateNumericValue = (start, end, duration, callback) => {
|
|
2
|
+
if (start === end) {
|
|
3
|
+
callback(end);
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const startTime = performance.now();
|
|
7
|
+
const animate = () => {
|
|
8
|
+
const currentTime = performance.now();
|
|
9
|
+
const progress = Math.min((currentTime - startTime) / duration, 1);
|
|
10
|
+
const value = start + (end - start) * progress;
|
|
11
|
+
callback(value);
|
|
12
|
+
if (progress < 1) {
|
|
13
|
+
requestAnimationFrame(animate);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
animate();
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=animate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animate.js","names":["animateNumericValue","start","end","duration","callback","startTime","performance","now","animate","currentTime","progress","Math","min","value","requestAnimationFrame"],"sources":["../../../src/utils/animate.ts"],"sourcesContent":["export const animateNumericValue = (\n start: number,\n end: number,\n duration: number,\n callback: (value: number) => void,\n) => {\n if (start === end) {\n callback(end);\n return;\n }\n\n const startTime = performance.now();\n const animate = () => {\n const currentTime = performance.now();\n const progress = Math.min((currentTime - startTime) / duration, 1);\n const value = start + (end - start) * progress;\n callback(value);\n if (progress < 1) {\n requestAnimationFrame(animate);\n }\n };\n animate();\n};\n"],"mappings":"AAAA,OAAO,MAAMA,mBAAmB,GAAGA,CAC/BC,KAAa,EACbC,GAAW,EACXC,QAAgB,EAChBC,QAAiC,KAChC;EACD,IAAIH,KAAK,KAAKC,GAAG,EAAE;IACfE,QAAQ,CAACF,GAAG,CAAC;IACb;EACJ;EAEA,MAAMG,SAAS,GAAGC,WAAW,CAACC,GAAG,CAAC,CAAC;EACnC,MAAMC,OAAO,GAAGA,CAAA,KAAM;IAClB,MAAMC,WAAW,GAAGH,WAAW,CAACC,GAAG,CAAC,CAAC;IACrC,MAAMG,QAAQ,GAAGC,IAAI,CAACC,GAAG,CAAC,CAACH,WAAW,GAAGJ,SAAS,IAAIF,QAAQ,EAAE,CAAC,CAAC;IAClE,MAAMU,KAAK,GAAGZ,KAAK,GAAG,CAACC,GAAG,GAAGD,KAAK,IAAIS,QAAQ;IAC9CN,QAAQ,CAACS,KAAK,CAAC;IACf,IAAIH,QAAQ,GAAG,CAAC,EAAE;MACdI,qBAAqB,CAACN,OAAO,CAAC;IAClC;EACJ,CAAC;EACDA,OAAO,CAAC,CAAC;AACb,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createDialog, DialogType } from 'chayns-api';
|
|
2
|
+
export const createErrorAlertDialog = text => createDialog({
|
|
3
|
+
type: DialogType.ALERT,
|
|
4
|
+
text: `<p style="text-align: center;">%%DialogErrorIcon%%</p><p>${text}</p>`
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=errorDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorDialog.js","names":["createDialog","DialogType","createErrorAlertDialog","text","type","ALERT"],"sources":["../../../src/utils/errorDialog.ts"],"sourcesContent":["import { createDialog, DialogType } from 'chayns-api';\n\nexport const createErrorAlertDialog = (text: string) =>\n createDialog({\n type: DialogType.ALERT,\n text: `<p style=\"text-align: center;\">%%DialogErrorIcon%%</p><p>${text}</p>`,\n });\n"],"mappings":"AAAA,SAASA,YAAY,EAAEC,UAAU,QAAQ,YAAY;AAErD,OAAO,MAAMC,sBAAsB,GAAIC,IAAY,IAC/CH,YAAY,CAAC;EACTI,IAAI,EAAEH,UAAU,CAACI,KAAK;EACtBF,IAAI,EAAE,4DAA4DA,IAAI;AAC1E,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const loadScript = src => new Promise((resolve, reject) => {
|
|
2
|
+
const script = document.createElement('script');
|
|
3
|
+
script.src = src;
|
|
4
|
+
script.onload = resolve;
|
|
5
|
+
script.onabort = reject;
|
|
6
|
+
document.head.appendChild(script);
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=loadScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadScript.js","names":["loadScript","src","Promise","resolve","reject","script","document","createElement","onload","onabort","head","appendChild"],"sources":["../../../src/utils/loadScript.ts"],"sourcesContent":["export const loadScript = (src: string): Promise<Event | UIEvent> =>\n new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = src;\n script.onload = resolve;\n script.onabort = reject;\n document.head.appendChild(script);\n });\n"],"mappings":"AAAA,OAAO,MAAMA,UAAU,GAAIC,GAAW,IAClC,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;EAC7B,MAAMC,MAAM,GAAGC,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC;EAC/CF,MAAM,CAACJ,GAAG,GAAGA,GAAG;EAChBI,MAAM,CAACG,MAAM,GAAGL,OAAO;EACvBE,MAAM,CAACI,OAAO,GAAGL,MAAM;EACvBE,QAAQ,CAACI,IAAI,CAACC,WAAW,CAACN,MAAM,CAAC;AACrC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const hasBrowserSupport = constraint => constraint in navigator.mediaDevices.getSupportedConstraints();
|
|
2
|
+
export const checkTrackSupport = (track, capability) => hasBrowserSupport(capability) && capability in track.getCapabilities();
|
|
3
|
+
//# sourceMappingURL=support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"support.js","names":["hasBrowserSupport","constraint","navigator","mediaDevices","getSupportedConstraints","checkTrackSupport","track","capability","getCapabilities"],"sources":["../../../src/utils/support.ts"],"sourcesContent":["export const hasBrowserSupport = (constraint: string): boolean =>\n constraint in navigator.mediaDevices.getSupportedConstraints();\n\nexport const checkTrackSupport = (track: MediaStreamTrack, capability: string): boolean =>\n hasBrowserSupport(capability) && capability in track.getCapabilities();\n"],"mappings":"AAAA,OAAO,MAAMA,iBAAiB,GAAIC,UAAkB,IAChDA,UAAU,IAAIC,SAAS,CAACC,YAAY,CAACC,uBAAuB,CAAC,CAAC;AAElE,OAAO,MAAMC,iBAAiB,GAAGA,CAACC,KAAuB,EAAEC,UAAkB,KACzEP,iBAAiB,CAACO,UAAU,CAAC,IAAIA,UAAU,IAAID,KAAK,CAACE,eAAe,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { CodeReaderOnScanCallback, ScannerErrorMessages } from '../../types/codeScanner';
|
|
3
|
+
type CodeScannerProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Defines which barcode formats are allowed to be detected.
|
|
6
|
+
*/
|
|
7
|
+
allowedFormats?: Array<BarcodeFormat>;
|
|
8
|
+
/**
|
|
9
|
+
* The interval of the scans.
|
|
10
|
+
*/
|
|
11
|
+
scanInterval?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Custom error messages for various scanner states or failures.
|
|
14
|
+
*/
|
|
15
|
+
errorMessages: ScannerErrorMessages;
|
|
16
|
+
/**
|
|
17
|
+
* Disables the file select feature if set to true.
|
|
18
|
+
*/
|
|
19
|
+
isFileSelectDisabled?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Disables the torch (flashlight) feature if set to true.
|
|
22
|
+
*/
|
|
23
|
+
isTorchDisabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Disables the zoom control if set to true.
|
|
26
|
+
*/
|
|
27
|
+
isZoomDisabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum allowed zoom level for the camera.
|
|
30
|
+
*/
|
|
31
|
+
maxZoom?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Minimum allowed zoom level for the camera.
|
|
34
|
+
*/
|
|
35
|
+
minZoom?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Callback function triggered when a code is successfully scanned.
|
|
38
|
+
*/
|
|
39
|
+
onScan?: CodeReaderOnScanCallback;
|
|
40
|
+
/**
|
|
41
|
+
* If true, allows scanning the same code multiple times in a row.
|
|
42
|
+
*/
|
|
43
|
+
shouldTriggerForSameCode?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Custom media track constraints for controlling the video input.
|
|
46
|
+
*/
|
|
47
|
+
trackConstraints?: MediaTrackConstraints;
|
|
48
|
+
/**
|
|
49
|
+
* Additional video constraints for the camera feed.
|
|
50
|
+
*/
|
|
51
|
+
videoConstraints?: MediaTrackConstraints;
|
|
52
|
+
};
|
|
53
|
+
declare const CodeScanner: FC<CodeScannerProps>;
|
|
54
|
+
export default CodeScanner;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const StyledCodeScanner: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
2
|
+
type StyledCodeScannerPreviewProps = {
|
|
3
|
+
$isVisible: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const StyledCodeScannerTextWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
6
|
+
export declare const StyledCodeScannerPreview: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").VideoHTMLAttributes<HTMLVideoElement>, HTMLVideoElement>, StyledCodeScannerPreviewProps>> & string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
type ScannerToolbarProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Indicates whether the scanner currently has an active error.
|
|
5
|
+
*/
|
|
6
|
+
hasScannerError?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Disables the file select option if set to true.
|
|
9
|
+
*/
|
|
10
|
+
isFileSelectDisabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Disables the torch (flashlight) button if set to true.
|
|
13
|
+
*/
|
|
14
|
+
isTorchDisabled?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Indicates if a file is currently being scanned.
|
|
17
|
+
*/
|
|
18
|
+
isScanningFile: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Disables the zoom slider if set to true.
|
|
21
|
+
*/
|
|
22
|
+
isZoomDisabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum allowed zoom level for the camera.
|
|
25
|
+
*/
|
|
26
|
+
maxZoom?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Minimum allowed zoom level for the camera.
|
|
29
|
+
*/
|
|
30
|
+
minZoom?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Callback triggered when a file is selected for scanning.
|
|
33
|
+
*/
|
|
34
|
+
onFileSelect: (file: File) => void;
|
|
35
|
+
/**
|
|
36
|
+
* The active media stream used by the scanner.
|
|
37
|
+
*/
|
|
38
|
+
stream?: MediaStream;
|
|
39
|
+
/**
|
|
40
|
+
* Defines constraints for the video element, e.g., resolution or facing mode.
|
|
41
|
+
*/
|
|
42
|
+
videoConstraints: MediaTrackConstraints;
|
|
43
|
+
};
|
|
44
|
+
declare const ScannerToolbar: FC<ScannerToolbarProps>;
|
|
45
|
+
export default ScannerToolbar;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const StyledScannerToolbar: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
2
|
+
type ScannerToolbarButtonProps = {
|
|
3
|
+
$isAvailable?: boolean;
|
|
4
|
+
$isActive?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const StyledScannerToolbarButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, ScannerToolbarButtonProps>> & string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type CodeReaderOnScanCallback = (code: {
|
|
2
|
+
format: BarcodeFormat;
|
|
3
|
+
value: string;
|
|
4
|
+
}) => void | Promise<void>;
|
|
5
|
+
export declare enum ScannerErrorType {
|
|
6
|
+
NO_CAMERA_ACCESS = 0,
|
|
7
|
+
CAMERA_ALREADY_IN_USE = 1,
|
|
8
|
+
DEVICE_NOT_FOUND = 2,
|
|
9
|
+
UNKNOWN = 3
|
|
10
|
+
}
|
|
11
|
+
export interface ScannerErrorMessages {
|
|
12
|
+
noPermission: string;
|
|
13
|
+
alreadyInUse: string;
|
|
14
|
+
cameraNotAvailable: string;
|
|
15
|
+
noCodeFound: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const animateNumericValue: (start: number, end: number, duration: number, callback: (value: number) => void) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createErrorAlertDialog: (text: string) => import("chayns-api").DialogHandler<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loadScript: (src: string) => Promise<Event | UIEvent>;
|