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,118 +1,118 @@
1
- <template>
2
- <div>
3
- <p class="decode-result">Last result: <b>{{ result }}</b></p>
4
-
5
- <qrcode-stream :camera="camera" @decode="onDecode" @init="onInit">
6
- <div v-if="validationSuccess" class="validation-success">
7
- This is a URL
8
- </div>
9
-
10
- <div v-if="validationFailure" class="validation-failure">
11
- This is NOT a URL!
12
- </div>
13
-
14
- <div v-if="validationPending" class="validation-pending">
15
- Long validation in progress...
16
- </div>
17
- </qrcode-stream>
18
- </div>
19
- </template>
20
-
21
- <script>
22
- import { QrcodeStream } from '../../../../src'
23
-
24
- export default {
25
-
26
- components: { QrcodeStream },
27
-
28
- data () {
29
- return {
30
- isValid: undefined,
31
- camera: 'auto',
32
- result: null,
33
- }
34
- },
35
-
36
- computed: {
37
- validationPending () {
38
- return this.isValid === undefined
39
- && this.camera === 'off'
40
- },
41
-
42
- validationSuccess () {
43
- return this.isValid === true
44
- },
45
-
46
- validationFailure () {
47
- return this.isValid === false
48
- }
49
- },
50
-
51
- methods: {
52
-
53
- onInit (promise) {
54
- promise
55
- .catch(console.error)
56
- .then(this.resetValidationState)
57
- },
58
-
59
- resetValidationState () {
60
- this.isValid = undefined
61
- },
62
-
63
- async onDecode (content) {
64
- this.result = content
65
- this.turnCameraOff()
66
-
67
- // pretend it's taking really long
68
- await this.timeout(3000)
69
- this.isValid = content.startsWith('http')
70
-
71
- // some more delay, so users have time to read the message
72
- await this.timeout(2000)
73
-
74
- this.turnCameraOn()
75
- },
76
-
77
- turnCameraOn () {
78
- this.camera = 'auto'
79
- },
80
-
81
- turnCameraOff () {
82
- this.camera = 'off'
83
- },
84
-
85
- timeout (ms) {
86
- return new Promise(resolve => {
87
- window.setTimeout(resolve, ms)
88
- })
89
- }
90
- }
91
- }
92
- </script>
93
-
94
- <style scoped>
95
- .validation-success,
96
- .validation-failure,
97
- .validation-pending {
98
- position: absolute;
99
- width: 100%;
100
- height: 100%;
101
-
102
- background-color: rgba(255, 255, 255, .8);
103
- text-align: center;
104
- font-weight: bold;
105
- font-size: 1.4rem;
106
- padding: 10px;
107
-
108
- display: flex;
109
- flex-flow: column nowrap;
110
- justify-content: center;
111
- }
112
- .validation-success {
113
- color: green;
114
- }
115
- .validation-failure {
116
- color: red;
117
- }
118
- </style>
1
+ <template>
2
+ <div>
3
+ <p class="decode-result">Last result: <b>{{ result }}</b></p>
4
+
5
+ <qrcode-stream :camera="camera" @decode="onDecode" @init="onInit">
6
+ <div v-if="validationSuccess" class="validation-success">
7
+ This is a URL
8
+ </div>
9
+
10
+ <div v-if="validationFailure" class="validation-failure">
11
+ This is NOT a URL!
12
+ </div>
13
+
14
+ <div v-if="validationPending" class="validation-pending">
15
+ Long validation in progress...
16
+ </div>
17
+ </qrcode-stream>
18
+ </div>
19
+ </template>
20
+
21
+ <script>
22
+ import { QrcodeStream } from '../../../../src'
23
+
24
+ export default {
25
+
26
+ components: { QrcodeStream },
27
+
28
+ data () {
29
+ return {
30
+ isValid: undefined,
31
+ camera: 'auto',
32
+ result: null,
33
+ }
34
+ },
35
+
36
+ computed: {
37
+ validationPending () {
38
+ return this.isValid === undefined
39
+ && this.camera === 'off'
40
+ },
41
+
42
+ validationSuccess () {
43
+ return this.isValid === true
44
+ },
45
+
46
+ validationFailure () {
47
+ return this.isValid === false
48
+ }
49
+ },
50
+
51
+ methods: {
52
+
53
+ onInit (promise) {
54
+ promise
55
+ .catch(console.error)
56
+ .then(this.resetValidationState)
57
+ },
58
+
59
+ resetValidationState () {
60
+ this.isValid = undefined
61
+ },
62
+
63
+ async onDecode (content) {
64
+ this.result = content
65
+ this.turnCameraOff()
66
+
67
+ // pretend it's taking really long
68
+ await this.timeout(3000)
69
+ this.isValid = content.startsWith('http')
70
+
71
+ // some more delay, so users have time to read the message
72
+ await this.timeout(2000)
73
+
74
+ this.turnCameraOn()
75
+ },
76
+
77
+ turnCameraOn () {
78
+ this.camera = 'auto'
79
+ },
80
+
81
+ turnCameraOff () {
82
+ this.camera = 'off'
83
+ },
84
+
85
+ timeout (ms) {
86
+ return new Promise(resolve => {
87
+ window.setTimeout(resolve, ms)
88
+ })
89
+ }
90
+ }
91
+ }
92
+ </script>
93
+
94
+ <style scoped>
95
+ .validation-success,
96
+ .validation-failure,
97
+ .validation-pending {
98
+ position: absolute;
99
+ width: 100%;
100
+ height: 100%;
101
+
102
+ background-color: rgba(255, 255, 255, .8);
103
+ text-align: center;
104
+ font-weight: bold;
105
+ font-size: 1.4rem;
106
+ padding: 10px;
107
+
108
+ display: flex;
109
+ flex-flow: column nowrap;
110
+ justify-content: center;
111
+ }
112
+ .validation-success {
113
+ color: green;
114
+ }
115
+ .validation-failure {
116
+ color: red;
117
+ }
118
+ </style>
@@ -1,41 +1,41 @@
1
- module.exports = {
2
- title: 'Vue Qrcode Reader',
3
- description: 'A set of Vue.js components for detecting and decoding QR codes.',
4
-
5
- base: '/qrcode-reader-vue3/',
6
-
7
- extraWatchFiles: [
8
- '../src/'
9
- ],
10
-
11
- themeConfig: {
12
- repo: 'gruhn/qrcode-reader-vue3',
13
-
14
- sidebar: {
15
- '/demos/': [
16
- 'Simple',
17
- 'DecodeAll',
18
- 'CustomTracking',
19
- 'LoadingIndicator',
20
- 'ScanSameQrcodeMoreThanOnce',
21
- 'Validate',
22
- 'SwitchCamera',
23
- 'Fullscreen',
24
- 'Torch',
25
- 'DragDrop',
26
- 'Upload'
27
- ],
28
-
29
- '/api/': [
30
- 'QrcodeStream',
31
- 'QrcodeDropZone',
32
- 'QrcodeCapture'
33
- ],
34
- },
35
-
36
- nav: [
37
- { text: 'Live Demos', link: '/demos/CustomTracking' },
38
- { text: 'API Reference', link: '/api/QrcodeStream' }
39
- ]
40
- }
41
- }
1
+ module.exports = {
2
+ title: 'Vue Qrcode Reader',
3
+ description: 'A set of Vue.js components for detecting and decoding QR codes.',
4
+
5
+ base: '/qrcode-reader-vue3/',
6
+
7
+ extraWatchFiles: [
8
+ '../src/'
9
+ ],
10
+
11
+ themeConfig: {
12
+ repo: 'gruhn/qrcode-reader-vue3',
13
+
14
+ sidebar: {
15
+ '/demos/': [
16
+ 'Simple',
17
+ 'DecodeAll',
18
+ 'CustomTracking',
19
+ 'LoadingIndicator',
20
+ 'ScanSameQrcodeMoreThanOnce',
21
+ 'Validate',
22
+ 'SwitchCamera',
23
+ 'Fullscreen',
24
+ 'Torch',
25
+ 'DragDrop',
26
+ 'Upload'
27
+ ],
28
+
29
+ '/api/': [
30
+ 'QrcodeStream',
31
+ 'QrcodeDropZone',
32
+ 'QrcodeCapture'
33
+ ],
34
+ },
35
+
36
+ nav: [
37
+ { text: 'Live Demos', link: '/demos/CustomTracking' },
38
+ { text: 'API Reference', link: '/api/QrcodeStream' }
39
+ ]
40
+ }
41
+ }
@@ -1 +1 @@
1
- <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z" fill="#3eaf7c" /></svg>
1
+ <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z" fill="#3eaf7c" /></svg>
@@ -1,102 +1,102 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Document</title>
7
- </head>
8
- <body>
9
- <video id="video" autoplay muted playsinline></video>
10
- </body>
11
- <script type="module">
12
- import BarcodeDetector from "https://cdn.skypack.dev/barcode-detector@0.5.0";
13
-
14
- const adaptOldFormat = detectedCodes => {
15
- if (detectedCodes.length > 0) {
16
- const [ firstCode ] = detectedCodes;
17
-
18
- const [
19
- topLeftCorner,
20
- topRightCorner,
21
- bottomRightCorner,
22
- bottomLeftCorner
23
- ] = firstCode.cornerPoints
24
-
25
- return {
26
- content: firstCode.rawValue,
27
- location: {
28
- topLeftCorner,
29
- topRightCorner,
30
- bottomRightCorner,
31
- bottomLeftCorner,
32
-
33
- // not supported by native API:
34
- topLeftFinderPattern: {},
35
- topRightFinderPattern: {},
36
- bottomLeftFinderPattern: {}
37
- },
38
- imageData: null
39
- }
40
- } else {
41
- return {
42
- content: null,
43
- location: null,
44
- imageData: null
45
- }
46
- }
47
- }
48
-
49
- export const keepScanning = (videoElement, options) => {
50
- const barcodeDetector = new BarcodeDetector({ formats: ["qr_code"] });
51
-
52
- const { detectHandler, locateHandler, minDelay } = options;
53
-
54
- const processFrame = state => async timeNow => {
55
- if (videoElement.readyState > 1) {
56
- console.log("scan")
57
- const { lastScanned, contentBefore, locationBefore } = state
58
-
59
- if (timeNow - lastScanned >= minDelay) {
60
- const detectedCodes = await barcodeDetector.detect(videoElement);
61
- const { content, location, imageData } = adaptOldFormat(detectedCodes)
62
-
63
- if (content !== null && content !== contentBefore) {
64
- detectHandler({ content, location, imageData });
65
- }
66
-
67
- if (location !== null || locationBefore !== null) {
68
- locateHandler(detectedCodes);
69
- }
70
-
71
- window.requestAnimationFrame(processFrame({
72
- lastScanned: timeNow,
73
- contentBefore: content ?? contentBefore,
74
- locationBefore: location
75
- }))
76
- } else {
77
- window.requestAnimationFrame(processFrame(state))
78
- }
79
- }
80
- };
81
-
82
- processFrame({
83
- contentBefore: null,
84
- locationBefore: null,
85
- lastScanned: performance.now()
86
- })();
87
- };
88
-
89
- (async () => {
90
- const videoEl = document.querySelector('#video')
91
-
92
- const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: false })
93
-
94
- videoEl.srcObject = stream
95
-
96
- videoEl.addEventListener("loadeddata", () => {
97
- keepScanning(videoEl, { minDelay: 40, detectHandler: console.log, locateHandler: console.log })
98
- })
99
-
100
- })()
101
- </script>
102
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Document</title>
7
+ </head>
8
+ <body>
9
+ <video id="video" autoplay muted playsinline></video>
10
+ </body>
11
+ <script type="module">
12
+ import BarcodeDetector from "https://cdn.skypack.dev/barcode-detector@0.5.0";
13
+
14
+ const adaptOldFormat = detectedCodes => {
15
+ if (detectedCodes.length > 0) {
16
+ const [ firstCode ] = detectedCodes;
17
+
18
+ const [
19
+ topLeftCorner,
20
+ topRightCorner,
21
+ bottomRightCorner,
22
+ bottomLeftCorner
23
+ ] = firstCode.cornerPoints
24
+
25
+ return {
26
+ content: firstCode.rawValue,
27
+ location: {
28
+ topLeftCorner,
29
+ topRightCorner,
30
+ bottomRightCorner,
31
+ bottomLeftCorner,
32
+
33
+ // not supported by native API:
34
+ topLeftFinderPattern: {},
35
+ topRightFinderPattern: {},
36
+ bottomLeftFinderPattern: {}
37
+ },
38
+ imageData: null
39
+ }
40
+ } else {
41
+ return {
42
+ content: null,
43
+ location: null,
44
+ imageData: null
45
+ }
46
+ }
47
+ }
48
+
49
+ export const keepScanning = (videoElement, options) => {
50
+ const barcodeDetector = new BarcodeDetector({ formats: ["qr_code"] });
51
+
52
+ const { detectHandler, locateHandler, minDelay } = options;
53
+
54
+ const processFrame = state => async timeNow => {
55
+ if (videoElement.readyState > 1) {
56
+ console.log("scan")
57
+ const { lastScanned, contentBefore, locationBefore } = state
58
+
59
+ if (timeNow - lastScanned >= minDelay) {
60
+ const detectedCodes = await barcodeDetector.detect(videoElement);
61
+ const { content, location, imageData } = adaptOldFormat(detectedCodes)
62
+
63
+ if (content !== null && content !== contentBefore) {
64
+ detectHandler({ content, location, imageData });
65
+ }
66
+
67
+ if (location !== null || locationBefore !== null) {
68
+ locateHandler(detectedCodes);
69
+ }
70
+
71
+ window.requestAnimationFrame(processFrame({
72
+ lastScanned: timeNow,
73
+ contentBefore: content ?? contentBefore,
74
+ locationBefore: location
75
+ }))
76
+ } else {
77
+ window.requestAnimationFrame(processFrame(state))
78
+ }
79
+ }
80
+ };
81
+
82
+ processFrame({
83
+ contentBefore: null,
84
+ locationBefore: null,
85
+ lastScanned: performance.now()
86
+ })();
87
+ };
88
+
89
+ (async () => {
90
+ const videoEl = document.querySelector('#video')
91
+
92
+ const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: false })
93
+
94
+ videoEl.srcObject = stream
95
+
96
+ videoEl.addEventListener("loadeddata", () => {
97
+ keepScanning(videoEl, { minDelay: 40, detectHandler: console.log, locateHandler: console.log })
98
+ })
99
+
100
+ })()
101
+ </script>
102
+ </html>
package/docs/README.md CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- home: true
3
- heroImage: /logo.png
4
- actionText: See Demos →
5
- actionLink: /demos/CustomTracking
6
- footer: MIT Licensed | Copyright © 2017-present Niklas Gruhn
7
- ---
1
+ ---
2
+ home: true
3
+ heroImage: /logo.png
4
+ actionText: See Demos →
5
+ actionLink: /demos/CustomTracking
6
+ footer: MIT Licensed | Copyright © 2017-present Niklas Gruhn
7
+ ---