qrcode-reader-vue3 3.1.3 → 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.
Files changed (71) hide show
  1. package/.browserslistrc +3 -3
  2. package/.editorconfig +18 -18
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +28 -28
  4. package/.github/copilot-instructions.md +209 -0
  5. package/.github/workflows/npm-publish.yml +15 -15
  6. package/.releaserc.yml +4 -4
  7. package/.travis.yml +26 -26
  8. package/CONTRIBUTING.md +23 -23
  9. package/LICENSE +21 -21
  10. package/README.md +194 -194
  11. package/babel.config.js +3 -3
  12. package/dist/QrcodeReaderVue3.common.js +15988 -13327
  13. package/dist/QrcodeReaderVue3.common.js.map +1 -1
  14. package/dist/QrcodeReaderVue3.umd.js +16152 -13482
  15. package/dist/QrcodeReaderVue3.umd.js.map +1 -1
  16. package/dist/QrcodeReaderVue3.umd.min.js +3 -1
  17. package/dist/QrcodeReaderVue3.umd.min.js.map +1 -1
  18. package/dist/demo.html +1 -8
  19. package/docs/.vuepress/components/DemoWrapper.vue +54 -54
  20. package/docs/.vuepress/components/demos/CustomTracking.vue +3 -2
  21. package/docs/.vuepress/components/demos/DecodeAll.vue +58 -58
  22. package/docs/.vuepress/components/demos/DragDrop.vue +80 -80
  23. package/docs/.vuepress/components/demos/Fullscreen.vue +115 -115
  24. package/docs/.vuepress/components/demos/LoadingIndicator.vue +61 -61
  25. package/docs/.vuepress/components/demos/ScanSameQrcodeMoreThanOnce.vue +78 -78
  26. package/docs/.vuepress/components/demos/SwitchCamera.vue +82 -82
  27. package/docs/.vuepress/components/demos/Torch.vue +64 -64
  28. package/docs/.vuepress/components/demos/Upload.vue +28 -28
  29. package/docs/.vuepress/components/demos/Validate.vue +118 -118
  30. package/docs/.vuepress/config.js +41 -41
  31. package/docs/.vuepress/public/checkmark.svg +1 -1
  32. package/docs/.vuepress/public/debug-memory-leak.html +102 -102
  33. package/docs/README.md +7 -7
  34. package/docs/api/QrcodeCapture.md +95 -95
  35. package/docs/api/QrcodeDropZone.md +117 -117
  36. package/docs/api/QrcodeStream.md +298 -298
  37. package/docs/demos/CustomTracking.md +13 -13
  38. package/docs/demos/DecodeAll.md +12 -12
  39. package/docs/demos/DragDrop.md +13 -13
  40. package/docs/demos/Fullscreen.md +13 -13
  41. package/docs/demos/LoadingIndicator.md +14 -14
  42. package/docs/demos/ScanSameQrcodeMoreThanOnce.md +17 -17
  43. package/docs/demos/Simple.md +14 -14
  44. package/docs/demos/SwitchCamera.md +12 -12
  45. package/docs/demos/Torch.md +15 -15
  46. package/docs/demos/Upload.md +16 -16
  47. package/docs/demos/Validate.md +13 -13
  48. package/eslint.config.js +49 -0
  49. package/package.json +33 -23
  50. package/src/components/QrcodeCapture.vue +31 -30
  51. package/src/components/QrcodeDropZone.vue +42 -42
  52. package/src/components/QrcodeStream.vue +28 -31
  53. package/src/index.ts +44 -0
  54. package/src/misc/{camera.js → camera.ts} +79 -21
  55. package/src/misc/{errors.js → errors.ts} +25 -25
  56. package/src/misc/scanner.ts +149 -0
  57. package/src/misc/{shimGetUserMedia.js → shimGetUserMedia.ts} +28 -28
  58. package/src/misc/util.ts +35 -0
  59. package/src/mixins/CommonAPI.vue +9 -4
  60. package/src/shims-vue.d.ts +9 -0
  61. package/src/types/index.d.ts +43 -0
  62. package/src/types/vue-qrcode-reader.d.ts +32 -4
  63. package/src/types/webrtc-adapter.d.ts +25 -0
  64. package/tests/misc/util.test.ts +72 -0
  65. package/tsconfig.json +35 -0
  66. package/vitest.config.ts +10 -0
  67. package/vue.config.js +30 -7
  68. package/.eslintrc.js +0 -25
  69. package/src/index.js +0 -32
  70. package/src/misc/scanner.js +0 -112
  71. package/src/misc/util.js +0 -15
@@ -1,96 +1,96 @@
1
- # QrcodeCapture
2
-
3
- ## Browser Support
4
-
5
- The newest API this component depend on is the [FileReader API](https://caniuse.com/#feat=filereader).
6
-
7
- | ![Internet Explorer](./ie_32x32.png) | ![Edge](./edge2019_32x32.png) | ![Firefox](./firefox_32x32.png) | ![Chrome](./chrome_32x32.png) | ![Safari](./safari_32x32.png) |
8
- | :---------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
9
- | 10+ | Yes | Yes | Yes | Yes¹ |
10
-
11
- 1. It doesn't work in web apps added to home screen (PWA mode) on iOS prior to 11.3 (see [this StackOverflow question](https://stackoverflow.com/questions/46228218/how-to-access-camera-on-ios11-home-screen-web-app))
12
-
13
- ## Events
14
-
15
- ### `decode`
16
- * **Payload Type:** `String`
17
-
18
- The component renders to a simple file picker `input` element. Clicking opens a file dialog. On supporting mobile devices the camera is started to take a picture. The selected images are directly scanned and positive results are indicated by the `decode` event. You can also select multiple images at the same time (still one event per image though).
19
-
20
- However, if no QR code is pictured or an error occurs, `decode` silently fails.
21
-
22
- ```html
23
- <qrcode-capture @decode="onDecode" />
24
- ```
25
- ```javascript
26
- methods: {
27
- onDecode (decodedString) {
28
- // ...
29
- }
30
- }
31
- ```
32
-
33
- ### `detect`
34
- * **Payload Type:** `Promise<Object>`
35
-
36
- The `detect` event is basically a verbose version of `decode`. `detect` is emitted as soon as you confirm your file selection or the foto you took with your camera. `detect` carries a Promise which resolves when scanning the images has finished. The Promise rejects in case of errors. Additionally, `detect` gives you the unprocessed raw image data, the raw bytes of the QR code and the coordinates of the QR code in the image.
37
-
38
- ```html
39
- <qrcode-capture @detect="onDetect" />
40
- ```
41
- ```javascript
42
- methods: {
43
- async onDetect (promise) {
44
- try {
45
- const {
46
- imageData, // raw image data of image/frame
47
- content, // decoded String or null
48
- binaryData, // The raw bytes of the QR code
49
- location // QR code coordinates or null
50
- } = await promise
51
-
52
- if (content === null) {
53
- // decoded nothing
54
- } else {
55
- // ...
56
- }
57
- } catch (error) {
58
- // ...
59
- }
60
- }
61
- }
62
- ```
63
-
64
- ## Props
65
-
66
- `QrcodeCapture` has no explicitly defined props.
67
- However, checkout the components template:
68
-
69
- ```html
70
- <template lang="html">
71
- <input
72
- @change="onChangeInput"
73
- type="file"
74
- name="image"
75
- accept="image/*"
76
- capture="environment"
77
- multiple
78
- />
79
- </template>
80
- ```
81
-
82
- Because the `input` element is the root element of the component and because Vue components accept [non-prop attributes](https://vuejs.org/v2/guide/components-props.html#Non-Prop-Attributes) you can make use of any valid `input` attribute:
83
-
84
- ```html
85
- <qrcode-capture disabled />
86
- ```
87
-
88
- You can even remove or replace already defined attributes:
89
-
90
- ```html
91
- <qrcode-capture :multiple="false" capture="user" />
92
- ```
93
-
94
- ## Slots
95
-
1
+ # QrcodeCapture
2
+
3
+ ## Browser Support
4
+
5
+ The newest API this component depend on is the [FileReader API](https://caniuse.com/#feat=filereader).
6
+
7
+ | ![Internet Explorer](./ie_32x32.png) | ![Edge](./edge2019_32x32.png) | ![Firefox](./firefox_32x32.png) | ![Chrome](./chrome_32x32.png) | ![Safari](./safari_32x32.png) |
8
+ | :---------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
9
+ | 10+ | Yes | Yes | Yes | Yes¹ |
10
+
11
+ 1. It doesn't work in web apps added to home screen (PWA mode) on iOS prior to 11.3 (see [this StackOverflow question](https://stackoverflow.com/questions/46228218/how-to-access-camera-on-ios11-home-screen-web-app))
12
+
13
+ ## Events
14
+
15
+ ### `decode`
16
+ * **Payload Type:** `String`
17
+
18
+ The component renders to a simple file picker `input` element. Clicking opens a file dialog. On supporting mobile devices the camera is started to take a picture. The selected images are directly scanned and positive results are indicated by the `decode` event. You can also select multiple images at the same time (still one event per image though).
19
+
20
+ However, if no QR code is pictured or an error occurs, `decode` silently fails.
21
+
22
+ ```html
23
+ <qrcode-capture @decode="onDecode" />
24
+ ```
25
+ ```javascript
26
+ methods: {
27
+ onDecode (decodedString) {
28
+ // ...
29
+ }
30
+ }
31
+ ```
32
+
33
+ ### `detect`
34
+ * **Payload Type:** `Promise<Object>`
35
+
36
+ The `detect` event is basically a verbose version of `decode`. `detect` is emitted as soon as you confirm your file selection or the foto you took with your camera. `detect` carries a Promise which resolves when scanning the images has finished. The Promise rejects in case of errors. Additionally, `detect` gives you the unprocessed raw image data, the raw bytes of the QR code and the coordinates of the QR code in the image.
37
+
38
+ ```html
39
+ <qrcode-capture @detect="onDetect" />
40
+ ```
41
+ ```javascript
42
+ methods: {
43
+ async onDetect (promise) {
44
+ try {
45
+ const {
46
+ imageData, // raw image data of image/frame
47
+ content, // decoded String or null
48
+ binaryData, // The raw bytes of the QR code
49
+ location // QR code coordinates or null
50
+ } = await promise
51
+
52
+ if (content === null) {
53
+ // decoded nothing
54
+ } else {
55
+ // ...
56
+ }
57
+ } catch (error) {
58
+ // ...
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## Props
65
+
66
+ `QrcodeCapture` has no explicitly defined props.
67
+ However, checkout the components template:
68
+
69
+ ```html
70
+ <template lang="html">
71
+ <input
72
+ @change="onChangeInput"
73
+ type="file"
74
+ name="image"
75
+ accept="image/*"
76
+ capture="environment"
77
+ multiple
78
+ />
79
+ </template>
80
+ ```
81
+
82
+ Because the `input` element is the root element of the component and because Vue components accept [non-prop attributes](https://vuejs.org/v2/guide/components-props.html#Non-Prop-Attributes) you can make use of any valid `input` attribute:
83
+
84
+ ```html
85
+ <qrcode-capture disabled />
86
+ ```
87
+
88
+ You can even remove or replace already defined attributes:
89
+
90
+ ```html
91
+ <qrcode-capture :multiple="false" capture="user" />
92
+ ```
93
+
94
+ ## Slots
95
+
96
96
  > no slots
@@ -1,118 +1,118 @@
1
- # QrcodeDropZone
2
-
3
- ## Browser Support
4
-
5
- The newest API this component depend on is the [FileReader API](https://caniuse.com/#feat=filereader).
6
-
7
- | ![Internet Explorer](./ie_32x32.png) | ![Edge](./edge2019_32x32.png) | ![Firefox](./firefox_32x32.png) | ![Chrome](./chrome_32x32.png) | ![Safari](./safari_32x32.png) |
8
- | :---------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
9
- | 10+ | Yes | Yes | Yes | Yes |
10
-
11
-
12
- ## Events
13
-
14
- ### `decode`
15
- * **Payload Type:** `String`
16
-
17
- You can drag-and-drop image files from your desktop or images embedded into other web pages anywhere in the area the component occupies. The images are directly scanned and positive results are indicated by the `decode` event. You can also drop multiple images at the same time (still one event per image though).
18
-
19
- However, if no QR code is pictured or an error occurs, `decode` silently fails.
20
-
21
- ```html
22
- <qrcode-drop-zone @decode="onDecode">
23
- <!-- ... -->
24
- </qrcode-drop-zone>
25
- ```
26
- ```javascript
27
- methods: {
28
- onDecode (decodedString) {
29
- // ...
30
- }
31
- }
32
- ```
33
-
34
- ### `detect`
35
- * **Payload Type:** `Promise<Object>`
36
-
37
- The `detect` event is basically a verbose version of `decode`. `detect` is emitted as soon as you drop an image. It carries a Promise which resolves when scanning the dropped image has finished. The Promise rejects in case of errors. Additionally, `detect` gives you the unprocessed raw image data, the raw bytes of the QR code and the coordinates of the QR code in the image.
38
-
39
- ```html
40
- <qrcode-drop-zone @detect="onDetect">
41
- <!-- ... -->
42
- </qrcode-drop-zone>
43
- ```
44
- ```javascript
45
- methods: {
46
- async onDetect (promise) {
47
- try {
48
- const {
49
- imageData, // raw image data of image/frame
50
- content, // decoded String or null
51
- binaryData, // The raw bytes of the QR code
52
- location // QR code coordinates or null
53
- } = await promise
54
-
55
- if (content === null) {
56
- // decoded nothing
57
- } else {
58
- // ...
59
- }
60
- } catch (error) {
61
- if (error.name === 'DropImageFetchError') {
62
- // drag-and-dropped URL (probably just an <img> element) from different
63
- // domain without CORS header caused same-origin-policy violation
64
- } else if (error.name === 'DropImageDecodeError') {
65
- // drag-and-dropped file is not of type image and can't be decoded
66
- } else {
67
- // idk, open an issue ¯\_(ツ)_/¯
68
- }
69
- }
70
- }
71
- }
72
- ```
73
-
74
- ### `dragover`
75
- * **Payload Type:** `Boolean`
76
-
77
- When the user is dragging something over the the component you might want to apply some emphasizing styling. Do that by reacting to the `dragover` event.
78
-
79
- ```html
80
- <qrcode-drop-zone @dragover="onDragOver">
81
- <div :class="{ highlight: draggingOver }">
82
- <!-- ... -->
83
- </div>
84
- </qrcode-drop-zone>
85
- ```
86
- ```javascript
87
- data () {
88
- return {
89
- draggingOver: false
90
- }
91
- },
92
-
93
- methods: {
94
- onDragOver (draggingOver) {
95
- this.draggingOver = draggingOver
96
- }
97
- }
98
- ```
99
-
100
- ::: warning
101
- This is a custom event not to be confused with [native `dragover`](https://developer.mozilla.org/en-US/docs/Web/Events/dragover). If you really need to listen for the DOM event instead, use [Vues `native` event modifier](https://vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components).
102
- :::
103
-
104
- ## Props
105
-
106
- > no props
107
-
108
- ## Slots
109
-
110
- ### default
111
-
112
- This component merely renders a wrapper `div`. Its height is defined by the content inside so it will have zero height if you don't provide any content.
113
-
114
- ```html
115
- <qrcode-drop-zone>
116
- <b>put anything here</b>
117
- </qrcode-drop-zone>
1
+ # QrcodeDropZone
2
+
3
+ ## Browser Support
4
+
5
+ The newest API this component depend on is the [FileReader API](https://caniuse.com/#feat=filereader).
6
+
7
+ | ![Internet Explorer](./ie_32x32.png) | ![Edge](./edge2019_32x32.png) | ![Firefox](./firefox_32x32.png) | ![Chrome](./chrome_32x32.png) | ![Safari](./safari_32x32.png) |
8
+ | :---------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
9
+ | 10+ | Yes | Yes | Yes | Yes |
10
+
11
+
12
+ ## Events
13
+
14
+ ### `decode`
15
+ * **Payload Type:** `String`
16
+
17
+ You can drag-and-drop image files from your desktop or images embedded into other web pages anywhere in the area the component occupies. The images are directly scanned and positive results are indicated by the `decode` event. You can also drop multiple images at the same time (still one event per image though).
18
+
19
+ However, if no QR code is pictured or an error occurs, `decode` silently fails.
20
+
21
+ ```html
22
+ <qrcode-drop-zone @decode="onDecode">
23
+ <!-- ... -->
24
+ </qrcode-drop-zone>
25
+ ```
26
+ ```javascript
27
+ methods: {
28
+ onDecode (decodedString) {
29
+ // ...
30
+ }
31
+ }
32
+ ```
33
+
34
+ ### `detect`
35
+ * **Payload Type:** `Promise<Object>`
36
+
37
+ The `detect` event is basically a verbose version of `decode`. `detect` is emitted as soon as you drop an image. It carries a Promise which resolves when scanning the dropped image has finished. The Promise rejects in case of errors. Additionally, `detect` gives you the unprocessed raw image data, the raw bytes of the QR code and the coordinates of the QR code in the image.
38
+
39
+ ```html
40
+ <qrcode-drop-zone @detect="onDetect">
41
+ <!-- ... -->
42
+ </qrcode-drop-zone>
43
+ ```
44
+ ```javascript
45
+ methods: {
46
+ async onDetect (promise) {
47
+ try {
48
+ const {
49
+ imageData, // raw image data of image/frame
50
+ content, // decoded String or null
51
+ binaryData, // The raw bytes of the QR code
52
+ location // QR code coordinates or null
53
+ } = await promise
54
+
55
+ if (content === null) {
56
+ // decoded nothing
57
+ } else {
58
+ // ...
59
+ }
60
+ } catch (error) {
61
+ if (error.name === 'DropImageFetchError') {
62
+ // drag-and-dropped URL (probably just an <img> element) from different
63
+ // domain without CORS header caused same-origin-policy violation
64
+ } else if (error.name === 'DropImageDecodeError') {
65
+ // drag-and-dropped file is not of type image and can't be decoded
66
+ } else {
67
+ // idk, open an issue ¯\_(ツ)_/¯
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### `dragover`
75
+ * **Payload Type:** `Boolean`
76
+
77
+ When the user is dragging something over the the component you might want to apply some emphasizing styling. Do that by reacting to the `dragover` event.
78
+
79
+ ```html
80
+ <qrcode-drop-zone @dragover="onDragOver">
81
+ <div :class="{ highlight: draggingOver }">
82
+ <!-- ... -->
83
+ </div>
84
+ </qrcode-drop-zone>
85
+ ```
86
+ ```javascript
87
+ data () {
88
+ return {
89
+ draggingOver: false
90
+ }
91
+ },
92
+
93
+ methods: {
94
+ onDragOver (draggingOver) {
95
+ this.draggingOver = draggingOver
96
+ }
97
+ }
98
+ ```
99
+
100
+ ::: warning
101
+ This is a custom event not to be confused with [native `dragover`](https://developer.mozilla.org/en-US/docs/Web/Events/dragover). If you really need to listen for the DOM event instead, use [Vues `native` event modifier](https://vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components).
102
+ :::
103
+
104
+ ## Props
105
+
106
+ > no props
107
+
108
+ ## Slots
109
+
110
+ ### default
111
+
112
+ This component merely renders a wrapper `div`. Its height is defined by the content inside so it will have zero height if you don't provide any content.
113
+
114
+ ```html
115
+ <qrcode-drop-zone>
116
+ <b>put anything here</b>
117
+ </qrcode-drop-zone>
118
118
  ```