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,299 +1,299 @@
1
- # QrcodeStream
2
-
3
- ## Browser Support
4
-
5
- This component fundamentally depends on the [Stream API](https://caniuse.com/#feat=stream).
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
- | No | Yes | Yes | Yes¹ | Yes² |
10
-
11
- 1. Chrome requires [HTTPS or localhost](https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins) (see _Troubleshooting_ for help)
12
- 2. Safari also requires HTTPS **even** on localhost (see [#48](https://github.com/scholtz/qrcode-reader-vue3/issues/48)). It also won't work in:
13
- - _Chrome for iOS_, _Firefox for iOS_, ... (see [#29](https://github.com/scholtz/qrcode-reader-vue3/issues/29))
14
- - WkWebView component of native iOS apps
15
- - web apps added to home screen (PWA mode) **prior to iOS 13.4** (see [#76](https://github.com/scholtz/qrcode-reader-vue3/issues/76))
16
-
17
-
18
- ## Events
19
-
20
- ### `decode`
21
- * **Payload Type:** `String`
22
-
23
- Once a stream from the users camera is loaded, it's displayed and continuously scanned for QR codes. Results are indicated by the `decode` event.
24
-
25
- ```html
26
- <qrcode-stream @decode="onDecode"></qrcode-stream>
27
- ```
28
- ```javascript
29
- methods: {
30
- onDecode (decodedString) {
31
- // ...
32
- }
33
- }
34
- ```
35
-
36
- ::: tip
37
- If you scan the same QR code multiple times in a row, `decode` is still only emitted once. When you hold a QR code in the camera, frames are actually decoded multiple times a second but you don't want to be flooded with `decode` events that often. That's why the last decoded QR code is always cached and only new results are propagated. However changing the value of `camera` resets this internal cache.
38
- :::
39
-
40
- ### `detect`
41
- * **Payload Type:** `Promise<Object>`
42
-
43
- The `detect` event is basically a verbose version of `decode`. `decode` only gives you the string encoded by QR codes. `detect` on the other hand ...
44
-
45
- * is always emitted before `decode`
46
- * gives you the unprocessed raw image data
47
- * gives you the raw bytes of the QR code.
48
- * gives you the coordinates of the QR code in the camera frame
49
- * does NOT silently fail in case of errors
50
-
51
- ```html
52
- <qrcode-stream @detect="onDetect"></qrcode-stream>
53
- ```
54
- ```javascript
55
- methods: {
56
- async onDetect (promise) {
57
- try {
58
- const {
59
- imageData, // raw image data of image/frame
60
- content, // decoded String
61
- binaryData, // The raw bytes of the QR code
62
- location // QR code coordinates
63
- } = await promise
64
-
65
- // ...
66
- } catch (error) {
67
- // ...
68
- }
69
- }
70
- }
71
- ```
72
-
73
- ### `init`
74
- * **Payload Type:** `Promise<MediaTrackCapabilities>`
75
-
76
- It might take a while before the component is ready and the scanning process starts. The user has to be asked for camera access permission first and the camera stream has to be loaded.
77
-
78
- If you want to show a loading indicator, you can listen for the `init` event. It's emitted as soon as the component is mounted. It carries a promise which resolves with the cameras [MediaTrackCapabilities](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities) when everything is ready. The promise is rejected if initialization fails. This can have [a couple of reasons](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Exceptions).
79
-
80
- ::: warning
81
- In Chrome you can't prompt users for permissions a second time. Once denied, users can only manually grant them. Make sure your users understand why you need access to their camera **before** you mount this component. Otherwise they might panic and deny and then get frustrated because they don't know how to change their decision.
82
- :::
83
-
84
- ```html
85
- <qrcode-stream @init="onInit"></qrcode-stream>
86
- ```
87
- ```javascript
88
- methods: {
89
- async onInit (promise) {
90
- // show loading indicator
91
-
92
- try {
93
- const { capabilities } = await promise
94
-
95
- // successfully initialized
96
- } catch (error) {
97
- if (error.name === 'NotAllowedError') {
98
- // user denied camera access permisson
99
- } else if (error.name === 'NotFoundError') {
100
- // no suitable camera device installed
101
- } else if (error.name === 'NotSupportedError') {
102
- // page is not served over HTTPS (or localhost)
103
- } else if (error.name === 'NotReadableError') {
104
- // maybe camera is already in use
105
- } else if (error.name === 'OverconstrainedError') {
106
- // did you requested the front camera although there is none?
107
- } else if (error.name === 'StreamApiNotSupportedError') {
108
- // browser seems to be lacking features
109
- }
110
- } finally {
111
- // hide loading indicator
112
- }
113
- }
114
- }
115
- ```
116
-
117
- ## Props
118
-
119
- ### `track`
120
- * **Input Type:** `Boolean`, `Function`
121
- * **Default:** `true`
122
-
123
- By default detected QR codes are visually highlighted. A transparent canvas overlays the camera stream. When a QR code is detected, its location is painted to the canvas. You can enable/disable this feature by passing `true`/`false` via the `track` prop. If tracking is disabled the camera stream is scanned much less frequently. So if you encounter performance problems on your target device, this might help.
124
-
125
- You can also pass a function with `track` to customize the way the location is painted. This function is called to produce each frame. It receives the location object as the first argument and a `CanvasRenderingContext2D` instance as the second argument.
126
-
127
- ::: danger
128
- Avoid access to reactive properties in this function (like stuff in `data`, `computed` or your Vuex store). The function is called several times a second and might cause memory leaks. To be safe don't access `this` at all.
129
- :::
130
-
131
- Say you want to paint in a different color that better fits your overall page theme.
132
-
133
- ```html
134
- <qrcode-stream :track="repaint"></qrcode-stream>
135
- ```
136
- ```javascript
137
- methods: {
138
- repaint (location, ctx) {
139
- const {
140
- topLeftCorner,
141
- topRightCorner,
142
- bottomLeftCorner,
143
- bottomRightCorner,
144
- // topLeftFinderPattern,
145
- // topRightFinderPattern,
146
- // bottomLeftFinderPattern
147
- } = location
148
-
149
- ctx.strokeStyle = 'blue' // instead of red
150
-
151
- ctx.beginPath()
152
- ctx.moveTo(topLeftCorner.x, topLeftCorner.y)
153
- ctx.lineTo(bottomLeftCorner.x, bottomLeftCorner.y)
154
- ctx.lineTo(bottomRightCorner.x, bottomRightCorner.y)
155
- ctx.lineTo(topRightCorner.x, topRightCorner.y)
156
- ctx.lineTo(topLeftCorner.x, topLeftCorner.y)
157
- ctx.closePath()
158
-
159
- ctx.stroke()
160
- }
161
- }
162
- ```
163
-
164
- ### `camera`
165
- * **Input Type:** `String`
166
- * **Default:** `auto`
167
- * **Valid Inputs:** `auto`, `rear`, `front`, `off`
168
-
169
- With the `camera` prop you can control which camera to access on the users device.
170
-
171
- * Use `front` or `rear` to force request the front or rear camera respectively.
172
- * If you choose `auto` the rear camera is requested by default.
173
- But if a device like a laptop has only a front camera installed, `auto` will fallback to that.
174
- * Use `off` to not request a camera at all or in other words: turn the camera off.
175
-
176
- Every time the camera prop is modified, a new camera stream is requested so the `init` event is emitted again.
177
- That way you can catch errors.
178
- For example when the front camera is requested on a device that doesn't have one.
179
-
180
- ```html
181
- <qrcode-stream :camera="camera" @init="onCameraChange"></qrcode-stream>
182
- ```
183
- ```js
184
- data () {
185
- return {
186
- camera: 'auto'
187
- }
188
- },
189
-
190
- methods: {
191
- startFrontCamera () {
192
- this.camera = 'front'
193
- },
194
-
195
- onCameraChange (promise) {
196
- promise.catch(error => {
197
- const cameraMissingError = error.name === 'OverconstrainedError'
198
- const triedFrontCamera = this.camera === 'front'
199
-
200
- if (triedFrontCamera && cameraMissingError) {
201
- // no front camera on this device
202
- }
203
- })
204
- }
205
- }
206
- ```
207
-
208
- ### `torch`
209
- * **Input Type:** `Boolean`
210
- * **Default:** `false`
211
-
212
- With the `torch` prop you can turn a devices flashlight on/off.
213
- This is not consistently supported by all devices and browsers.
214
- Support can even vary on the same device with the same browser.
215
- For example the rear camera often has a flashlight but the front camera doesn't.
216
- We can only tell if flashlight control is supported once the camera is loaded and the `init` event has been emitted.
217
- At the moment, `torch` silently fails on unsupported devices.
218
- But from the `init` events payload you can access the [MediaTrackCapabilities](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities) object.
219
- This will tell you whether or not `torch` is supported.
220
-
221
- Due to API limitations the camera stream must be reloaded when turning the torch on/off.
222
- That means the `init` event will be emitted again.
223
-
224
-
225
- ```html
226
- <qrcode-stream :torch="true" @init="onInit"></qrcode-stream>
227
- ```
228
- ```js
229
- methods: {
230
- async onInit (promise) {
231
- const { capabilities } = await promise
232
-
233
- const TORCH_IS_SUPPORTED = !!capabilities.torch
234
- }
235
- }
236
- ```
237
-
238
- ### `worker` <Badge text="experimental" type="error" />
239
-
240
- ::: tip
241
- So far *qrcode-reader-vue3* could only process QR codes.
242
- However, many people requested support for different code types
243
- (bar codes, data matrix, color inverted QR codes, ...) though.
244
- With this prop we try to meet these demands.
245
-
246
- Please share your successful or unsuccessful implementation attempts at
247
- [#109](https://github.com/scholtz/qrcode-reader-vue3/issues/109).
248
- Your feedback is greatly appreciated.
249
- :::
250
-
251
- By default, *QrcodeStream* will only detect QR codes.
252
- Processing image data is expensive so a web worker is doing the heavy lifting.
253
- Because the worker is the only QR code specific part of the library though,
254
- you can replace the default worker and get a component that can scan whatever you want.
255
-
256
- First of all you need to create a custom worker class:
257
-
258
- ```js
259
- class MyWorkerClass extends Worker {
260
- constructor() {
261
- super("path/to/worker.js")
262
- }
263
- }
264
- ```
265
- (Internally, *qrcode-reader-vue3* leverages [worker-loader](https://github.com/webpack-contrib/worker-loader)
266
- to makes this slightly more convenient)
267
-
268
- To get your `worker.js` right, check out [the default implementation](https://github.com/scholtz/qrcode-reader-vue3/blob/91ee3fc8bf2f7fab96ac3f0a5d84d2d4c09b012f/src/worker/jsqr.js).
269
-
270
- Now, pass the worker class via the `worker` prop.
271
- Don't pass a class instance, we need the class itself!
272
-
273
- ```html
274
- <qrcode-stream :worker="Worker"></qrcode-stream>
275
- ```
276
- ```js
277
- data() {
278
- return {
279
- Worker: MyWorkerClass // Don't do: new MyWorkerClass()
280
- }
281
- }
282
- ```
283
-
284
- :::tip
285
- `QrcodeCapture` and `QrcodeDropZone` too expose the `worker` prop.
286
- Dedicated API documentation is missing so far but usage should be similar.
287
- :::
288
-
289
- ## Slots
290
-
291
- ### default
292
-
293
- Any distributed content overlays the camera stream, wrapped in a `position: absolute` container.
294
-
295
- ```html
296
- <qrcode-stream>
297
- <b>stuff here overlays the camera stream</b>
298
- </qrcode-stream>
1
+ # QrcodeStream
2
+
3
+ ## Browser Support
4
+
5
+ This component fundamentally depends on the [Stream API](https://caniuse.com/#feat=stream).
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
+ | No | Yes | Yes | Yes¹ | Yes² |
10
+
11
+ 1. Chrome requires [HTTPS or localhost](https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins) (see _Troubleshooting_ for help)
12
+ 2. Safari also requires HTTPS **even** on localhost (see [#48](https://github.com/scholtz/qrcode-reader-vue3/issues/48)). It also won't work in:
13
+ - _Chrome for iOS_, _Firefox for iOS_, ... (see [#29](https://github.com/scholtz/qrcode-reader-vue3/issues/29))
14
+ - WkWebView component of native iOS apps
15
+ - web apps added to home screen (PWA mode) **prior to iOS 13.4** (see [#76](https://github.com/scholtz/qrcode-reader-vue3/issues/76))
16
+
17
+
18
+ ## Events
19
+
20
+ ### `decode`
21
+ * **Payload Type:** `String`
22
+
23
+ Once a stream from the users camera is loaded, it's displayed and continuously scanned for QR codes. Results are indicated by the `decode` event.
24
+
25
+ ```html
26
+ <qrcode-stream @decode="onDecode"></qrcode-stream>
27
+ ```
28
+ ```javascript
29
+ methods: {
30
+ onDecode (decodedString) {
31
+ // ...
32
+ }
33
+ }
34
+ ```
35
+
36
+ ::: tip
37
+ If you scan the same QR code multiple times in a row, `decode` is still only emitted once. When you hold a QR code in the camera, frames are actually decoded multiple times a second but you don't want to be flooded with `decode` events that often. That's why the last decoded QR code is always cached and only new results are propagated. However changing the value of `camera` resets this internal cache.
38
+ :::
39
+
40
+ ### `detect`
41
+ * **Payload Type:** `Promise<Object>`
42
+
43
+ The `detect` event is basically a verbose version of `decode`. `decode` only gives you the string encoded by QR codes. `detect` on the other hand ...
44
+
45
+ * is always emitted before `decode`
46
+ * gives you the unprocessed raw image data
47
+ * gives you the raw bytes of the QR code.
48
+ * gives you the coordinates of the QR code in the camera frame
49
+ * does NOT silently fail in case of errors
50
+
51
+ ```html
52
+ <qrcode-stream @detect="onDetect"></qrcode-stream>
53
+ ```
54
+ ```javascript
55
+ methods: {
56
+ async onDetect (promise) {
57
+ try {
58
+ const {
59
+ imageData, // raw image data of image/frame
60
+ content, // decoded String
61
+ binaryData, // The raw bytes of the QR code
62
+ location // QR code coordinates
63
+ } = await promise
64
+
65
+ // ...
66
+ } catch (error) {
67
+ // ...
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ ### `init`
74
+ * **Payload Type:** `Promise<MediaTrackCapabilities>`
75
+
76
+ It might take a while before the component is ready and the scanning process starts. The user has to be asked for camera access permission first and the camera stream has to be loaded.
77
+
78
+ If you want to show a loading indicator, you can listen for the `init` event. It's emitted as soon as the component is mounted. It carries a promise which resolves with the cameras [MediaTrackCapabilities](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities) when everything is ready. The promise is rejected if initialization fails. This can have [a couple of reasons](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Exceptions).
79
+
80
+ ::: warning
81
+ In Chrome you can't prompt users for permissions a second time. Once denied, users can only manually grant them. Make sure your users understand why you need access to their camera **before** you mount this component. Otherwise they might panic and deny and then get frustrated because they don't know how to change their decision.
82
+ :::
83
+
84
+ ```html
85
+ <qrcode-stream @init="onInit"></qrcode-stream>
86
+ ```
87
+ ```javascript
88
+ methods: {
89
+ async onInit (promise) {
90
+ // show loading indicator
91
+
92
+ try {
93
+ const { capabilities } = await promise
94
+
95
+ // successfully initialized
96
+ } catch (error) {
97
+ if (error.name === 'NotAllowedError') {
98
+ // user denied camera access permisson
99
+ } else if (error.name === 'NotFoundError') {
100
+ // no suitable camera device installed
101
+ } else if (error.name === 'NotSupportedError') {
102
+ // page is not served over HTTPS (or localhost)
103
+ } else if (error.name === 'NotReadableError') {
104
+ // maybe camera is already in use
105
+ } else if (error.name === 'OverconstrainedError') {
106
+ // did you requested the front camera although there is none?
107
+ } else if (error.name === 'StreamApiNotSupportedError') {
108
+ // browser seems to be lacking features
109
+ }
110
+ } finally {
111
+ // hide loading indicator
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ ## Props
118
+
119
+ ### `track`
120
+ * **Input Type:** `Boolean`, `Function`
121
+ * **Default:** `true`
122
+
123
+ By default detected QR codes are visually highlighted. A transparent canvas overlays the camera stream. When a QR code is detected, its location is painted to the canvas. You can enable/disable this feature by passing `true`/`false` via the `track` prop. If tracking is disabled the camera stream is scanned much less frequently. So if you encounter performance problems on your target device, this might help.
124
+
125
+ You can also pass a function with `track` to customize the way the location is painted. This function is called to produce each frame. It receives the location object as the first argument and a `CanvasRenderingContext2D` instance as the second argument.
126
+
127
+ ::: danger
128
+ Avoid access to reactive properties in this function (like stuff in `data`, `computed` or your Vuex store). The function is called several times a second and might cause memory leaks. To be safe don't access `this` at all.
129
+ :::
130
+
131
+ Say you want to paint in a different color that better fits your overall page theme.
132
+
133
+ ```html
134
+ <qrcode-stream :track="repaint"></qrcode-stream>
135
+ ```
136
+ ```javascript
137
+ methods: {
138
+ repaint (location, ctx) {
139
+ const {
140
+ topLeftCorner,
141
+ topRightCorner,
142
+ bottomLeftCorner,
143
+ bottomRightCorner,
144
+ // topLeftFinderPattern,
145
+ // topRightFinderPattern,
146
+ // bottomLeftFinderPattern
147
+ } = location
148
+
149
+ ctx.strokeStyle = 'blue' // instead of red
150
+
151
+ ctx.beginPath()
152
+ ctx.moveTo(topLeftCorner.x, topLeftCorner.y)
153
+ ctx.lineTo(bottomLeftCorner.x, bottomLeftCorner.y)
154
+ ctx.lineTo(bottomRightCorner.x, bottomRightCorner.y)
155
+ ctx.lineTo(topRightCorner.x, topRightCorner.y)
156
+ ctx.lineTo(topLeftCorner.x, topLeftCorner.y)
157
+ ctx.closePath()
158
+
159
+ ctx.stroke()
160
+ }
161
+ }
162
+ ```
163
+
164
+ ### `camera`
165
+ * **Input Type:** `String`
166
+ * **Default:** `auto`
167
+ * **Valid Inputs:** `auto`, `rear`, `front`, `off`
168
+
169
+ With the `camera` prop you can control which camera to access on the users device.
170
+
171
+ * Use `front` or `rear` to force request the front or rear camera respectively.
172
+ * If you choose `auto` the rear camera is requested by default.
173
+ But if a device like a laptop has only a front camera installed, `auto` will fallback to that.
174
+ * Use `off` to not request a camera at all or in other words: turn the camera off.
175
+
176
+ Every time the camera prop is modified, a new camera stream is requested so the `init` event is emitted again.
177
+ That way you can catch errors.
178
+ For example when the front camera is requested on a device that doesn't have one.
179
+
180
+ ```html
181
+ <qrcode-stream :camera="camera" @init="onCameraChange"></qrcode-stream>
182
+ ```
183
+ ```js
184
+ data () {
185
+ return {
186
+ camera: 'auto'
187
+ }
188
+ },
189
+
190
+ methods: {
191
+ startFrontCamera () {
192
+ this.camera = 'front'
193
+ },
194
+
195
+ onCameraChange (promise) {
196
+ promise.catch(error => {
197
+ const cameraMissingError = error.name === 'OverconstrainedError'
198
+ const triedFrontCamera = this.camera === 'front'
199
+
200
+ if (triedFrontCamera && cameraMissingError) {
201
+ // no front camera on this device
202
+ }
203
+ })
204
+ }
205
+ }
206
+ ```
207
+
208
+ ### `torch`
209
+ * **Input Type:** `Boolean`
210
+ * **Default:** `false`
211
+
212
+ With the `torch` prop you can turn a devices flashlight on/off.
213
+ This is not consistently supported by all devices and browsers.
214
+ Support can even vary on the same device with the same browser.
215
+ For example the rear camera often has a flashlight but the front camera doesn't.
216
+ We can only tell if flashlight control is supported once the camera is loaded and the `init` event has been emitted.
217
+ At the moment, `torch` silently fails on unsupported devices.
218
+ But from the `init` events payload you can access the [MediaTrackCapabilities](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/getCapabilities) object.
219
+ This will tell you whether or not `torch` is supported.
220
+
221
+ Due to API limitations the camera stream must be reloaded when turning the torch on/off.
222
+ That means the `init` event will be emitted again.
223
+
224
+
225
+ ```html
226
+ <qrcode-stream :torch="true" @init="onInit"></qrcode-stream>
227
+ ```
228
+ ```js
229
+ methods: {
230
+ async onInit (promise) {
231
+ const { capabilities } = await promise
232
+
233
+ const TORCH_IS_SUPPORTED = !!capabilities.torch
234
+ }
235
+ }
236
+ ```
237
+
238
+ ### `worker` <Badge text="experimental" type="error" />
239
+
240
+ ::: tip
241
+ So far *qrcode-reader-vue3* could only process QR codes.
242
+ However, many people requested support for different code types
243
+ (bar codes, data matrix, color inverted QR codes, ...) though.
244
+ With this prop we try to meet these demands.
245
+
246
+ Please share your successful or unsuccessful implementation attempts at
247
+ [#109](https://github.com/scholtz/qrcode-reader-vue3/issues/109).
248
+ Your feedback is greatly appreciated.
249
+ :::
250
+
251
+ By default, *QrcodeStream* will only detect QR codes.
252
+ Processing image data is expensive so a web worker is doing the heavy lifting.
253
+ Because the worker is the only QR code specific part of the library though,
254
+ you can replace the default worker and get a component that can scan whatever you want.
255
+
256
+ First of all you need to create a custom worker class:
257
+
258
+ ```js
259
+ class MyWorkerClass extends Worker {
260
+ constructor() {
261
+ super("path/to/worker.js")
262
+ }
263
+ }
264
+ ```
265
+ (Internally, *qrcode-reader-vue3* leverages [worker-loader](https://github.com/webpack-contrib/worker-loader)
266
+ to makes this slightly more convenient)
267
+
268
+ To get your `worker.js` right, check out [the default implementation](https://github.com/scholtz/qrcode-reader-vue3/blob/91ee3fc8bf2f7fab96ac3f0a5d84d2d4c09b012f/src/worker/jsqr.js).
269
+
270
+ Now, pass the worker class via the `worker` prop.
271
+ Don't pass a class instance, we need the class itself!
272
+
273
+ ```html
274
+ <qrcode-stream :worker="Worker"></qrcode-stream>
275
+ ```
276
+ ```js
277
+ data() {
278
+ return {
279
+ Worker: MyWorkerClass // Don't do: new MyWorkerClass()
280
+ }
281
+ }
282
+ ```
283
+
284
+ :::tip
285
+ `QrcodeCapture` and `QrcodeDropZone` too expose the `worker` prop.
286
+ Dedicated API documentation is missing so far but usage should be similar.
287
+ :::
288
+
289
+ ## Slots
290
+
291
+ ### default
292
+
293
+ Any distributed content overlays the camera stream, wrapped in a `position: absolute` container.
294
+
295
+ ```html
296
+ <qrcode-stream>
297
+ <b>stuff here overlays the camera stream</b>
298
+ </qrcode-stream>
299
299
  ```
@@ -1,13 +1,13 @@
1
- # Visual Tracking
2
-
3
- Hold a QR code into view of the camera.
4
- It should be visually highlighted in real-time.
5
- Use the track function select below to change the flavor.
6
-
7
- <ClientOnly>
8
- <DemoWrapper component="CustomTracking" />
9
- </ClientOnly>
10
-
11
- ### Source
12
-
13
- <<< @/docs/.vuepress/components/demos/CustomTracking.vue
1
+ # Visual Tracking
2
+
3
+ Hold a QR code into view of the camera.
4
+ It should be visually highlighted in real-time.
5
+ Use the track function select below to change the flavor.
6
+
7
+ <ClientOnly>
8
+ <DemoWrapper component="CustomTracking" />
9
+ </ClientOnly>
10
+
11
+ ### Source
12
+
13
+ <<< @/docs/.vuepress/components/demos/CustomTracking.vue
@@ -1,12 +1,12 @@
1
- # Decode Continuously
2
-
3
- Hold a QR code in the camera and see what happens. Note, you can't scan the same
4
- QR code multiple time in a row.
5
-
6
- <ClientOnly>
7
- <DemoWrapper component="DecodeAll" />
8
- </ClientOnly>
9
-
10
- ### Source
11
-
12
- <<< @/docs/.vuepress/components/demos/DecodeAll.vue
1
+ # Decode Continuously
2
+
3
+ Hold a QR code in the camera and see what happens. Note, you can't scan the same
4
+ QR code multiple time in a row.
5
+
6
+ <ClientOnly>
7
+ <DemoWrapper component="DecodeAll" />
8
+ </ClientOnly>
9
+
10
+ ### Source
11
+
12
+ <<< @/docs/.vuepress/components/demos/DecodeAll.vue