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
package/dist/demo.html CHANGED
@@ -1,8 +1 @@
1
- <meta charset="utf-8">
2
- <title>QrcodeReaderVue3 demo</title>
3
- <script src="./QrcodeReaderVue3.umd.js"></script>
4
-
5
-
6
- <script>
7
- console.log(QrcodeReaderVue3)
8
- </script>
1
+ <!doctype html><meta charset="utf-8"><title>QrcodeReaderVue3 demo</title><script src="./QrcodeReaderVue3.umd.js"></script><script>console.log(QrcodeReaderVue3)</script>
@@ -1,54 +1,54 @@
1
- <template>
2
- <component :is="currentDemo" />
3
- </template>
4
-
5
- <script>
6
- import CustomTracking from './demos/CustomTracking.vue'
7
- import DecodeAll from './demos/DecodeAll.vue'
8
- import SwitchCamera from './demos/SwitchCamera.vue'
9
- import DragDrop from './demos/DragDrop.vue'
10
- import Upload from './demos/Upload.vue'
11
- import Fullscreen from './demos/Fullscreen.vue'
12
- import LoadingIndicator from './demos/LoadingIndicator.vue'
13
- import Torch from './demos/Torch.vue'
14
- import Validate from './demos/Validate.vue'
15
- import ScanSameQrcodeMoreThanOnce from './demos/ScanSameQrcodeMoreThanOnce.vue'
16
-
17
- export default {
18
- components: {
19
- DecodeAll,
20
- CustomTracking,
21
- SwitchCamera,
22
- DragDrop,
23
- Upload,
24
- Fullscreen,
25
- LoadingIndicator,
26
- Torch,
27
- Validate,
28
- ScanSameQrcodeMoreThanOnce
29
- },
30
-
31
- props: {
32
- component: String
33
- },
34
-
35
- data () {
36
- return {
37
- currentDemo: null
38
- }
39
- },
40
-
41
- mounted () {
42
- this.currentDemo = this.component
43
- }
44
-
45
- }
46
- </script>
47
-
48
- <style>
49
- .decode-result {
50
- overflow: hidden;
51
- text-overflow: ellipsis;
52
- white-space: nowrap;
53
- }
54
- </style>
1
+ <template>
2
+ <component :is="currentDemo" />
3
+ </template>
4
+
5
+ <script>
6
+ import CustomTracking from './demos/CustomTracking.vue'
7
+ import DecodeAll from './demos/DecodeAll.vue'
8
+ import SwitchCamera from './demos/SwitchCamera.vue'
9
+ import DragDrop from './demos/DragDrop.vue'
10
+ import Upload from './demos/Upload.vue'
11
+ import Fullscreen from './demos/Fullscreen.vue'
12
+ import LoadingIndicator from './demos/LoadingIndicator.vue'
13
+ import Torch from './demos/Torch.vue'
14
+ import Validate from './demos/Validate.vue'
15
+ import ScanSameQrcodeMoreThanOnce from './demos/ScanSameQrcodeMoreThanOnce.vue'
16
+
17
+ export default {
18
+ components: {
19
+ DecodeAll,
20
+ CustomTracking,
21
+ SwitchCamera,
22
+ DragDrop,
23
+ Upload,
24
+ Fullscreen,
25
+ LoadingIndicator,
26
+ Torch,
27
+ Validate,
28
+ ScanSameQrcodeMoreThanOnce
29
+ },
30
+
31
+ props: {
32
+ component: String
33
+ },
34
+
35
+ data () {
36
+ return {
37
+ currentDemo: null
38
+ }
39
+ },
40
+
41
+ mounted () {
42
+ this.currentDemo = this.component
43
+ }
44
+
45
+ }
46
+ </script>
47
+
48
+ <style>
49
+ .decode-result {
50
+ overflow: hidden;
51
+ text-overflow: ellipsis;
52
+ white-space: nowrap;
53
+ }
54
+ </style>
@@ -3,8 +3,9 @@
3
3
  <p>
4
4
  Track function:
5
5
  <select v-model="selected">
6
- <option v-for="option in options" :key="option.text" :value="option">
7
- {{ option.text }}
6
+ <!-- eslint-disable-next-line vue/valid-v-for -->
7
+ <option v-for="(option, index) in options" :key="option.text ?? index" :value="option">
8
+ {{ option.text }}
8
9
  </option>
9
10
  </select>
10
11
  </p>
@@ -1,58 +1,58 @@
1
- <template>
2
- <div>
3
- <p class="error">{{ error }}</p>
4
-
5
- <p class="decode-result">Last result: <b>{{ result }}</b></p>
6
-
7
- <qrcode-stream @decode="onDecode" @init="onInit" />
8
- </div>
9
- </template>
10
-
11
- <script>
12
- import { QrcodeStream } from '../../../../src'
13
-
14
- export default {
15
-
16
- components: { QrcodeStream },
17
-
18
- data () {
19
- return {
20
- result: '',
21
- error: ''
22
- }
23
- },
24
-
25
- methods: {
26
- onDecode (result) {
27
- this.result = result
28
- },
29
-
30
- async onInit (promise) {
31
- try {
32
- await promise
33
- } catch (error) {
34
- if (error.name === 'NotAllowedError') {
35
- this.error = "ERROR: you need to grant camera access permisson"
36
- } else if (error.name === 'NotFoundError') {
37
- this.error = "ERROR: no camera on this device"
38
- } else if (error.name === 'NotSupportedError') {
39
- this.error = "ERROR: secure context required (HTTPS, localhost)"
40
- } else if (error.name === 'NotReadableError') {
41
- this.error = "ERROR: is the camera already in use?"
42
- } else if (error.name === 'OverconstrainedError') {
43
- this.error = "ERROR: installed cameras are not suitable"
44
- } else if (error.name === 'StreamApiNotSupportedError') {
45
- this.error = "ERROR: Stream API is not supported in this browser"
46
- }
47
- }
48
- }
49
- }
50
- }
51
- </script>
52
-
53
- <style scoped>
54
- .error {
55
- font-weight: bold;
56
- color: red;
57
- }
58
- </style>
1
+ <template>
2
+ <div>
3
+ <p class="error">{{ error }}</p>
4
+
5
+ <p class="decode-result">Last result: <b>{{ result }}</b></p>
6
+
7
+ <qrcode-stream @decode="onDecode" @init="onInit" />
8
+ </div>
9
+ </template>
10
+
11
+ <script>
12
+ import { QrcodeStream } from '../../../../src'
13
+
14
+ export default {
15
+
16
+ components: { QrcodeStream },
17
+
18
+ data () {
19
+ return {
20
+ result: '',
21
+ error: ''
22
+ }
23
+ },
24
+
25
+ methods: {
26
+ onDecode (result) {
27
+ this.result = result
28
+ },
29
+
30
+ async onInit (promise) {
31
+ try {
32
+ await promise
33
+ } catch (error) {
34
+ if (error.name === 'NotAllowedError') {
35
+ this.error = "ERROR: you need to grant camera access permisson"
36
+ } else if (error.name === 'NotFoundError') {
37
+ this.error = "ERROR: no camera on this device"
38
+ } else if (error.name === 'NotSupportedError') {
39
+ this.error = "ERROR: secure context required (HTTPS, localhost)"
40
+ } else if (error.name === 'NotReadableError') {
41
+ this.error = "ERROR: is the camera already in use?"
42
+ } else if (error.name === 'OverconstrainedError') {
43
+ this.error = "ERROR: installed cameras are not suitable"
44
+ } else if (error.name === 'StreamApiNotSupportedError') {
45
+ this.error = "ERROR: Stream API is not supported in this browser"
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ </script>
52
+
53
+ <style scoped>
54
+ .error {
55
+ font-weight: bold;
56
+ color: red;
57
+ }
58
+ </style>
@@ -1,80 +1,80 @@
1
- <template>
2
- <div>
3
- <p class="decode-result">Last result: <b>{{ result }}</b></p>
4
-
5
- <p v-if="error !== null" class="drop-error">
6
- {{ error }}
7
- </p>
8
-
9
- <qrcode-drop-zone @detect="onDetect" @dragover="onDragOver" @init="logErrors">
10
- <div class="drop-area" :class="{ 'dragover': dragover }">
11
- DROP SOME IMAGES HERE
12
- </div>
13
- </qrcode-drop-zone>
14
- </div>
15
- </template>
16
-
17
- <script>
18
- import { QrcodeDropZone } from '../../../../src'
19
-
20
- export default {
21
-
22
- components: { QrcodeDropZone },
23
-
24
- data () {
25
- return {
26
- result: null,
27
- error: null,
28
- dragover: false
29
- }
30
- },
31
-
32
- methods: {
33
- async onDetect (promise) {
34
- try {
35
- const { content } = await promise
36
-
37
- this.result = content
38
- this.error = null
39
- } catch (error) {
40
- if (error.name === 'DropImageFetchError') {
41
- this.error = 'Sorry, you can\'t load cross-origin images :/'
42
- } else if (error.name === 'DropImageDecodeError') {
43
- this.error = 'Ok, that\'s not an image. That can\'t be decoded.'
44
- } else {
45
- this.error = 'Ups, what kind of error is this?! ' + error.message
46
- }
47
- }
48
- },
49
-
50
- logErrors (promise) {
51
- promise.catch(console.error)
52
- },
53
-
54
- onDragOver (isDraggingOver) {
55
- this.dragover = isDraggingOver
56
- }
57
- }
58
- }
59
- </script>
60
-
61
- <style>
62
- .drop-area {
63
- height: 300px;
64
- color: #fff;
65
- text-align: center;
66
- font-weight: bold;
67
- padding: 10px;
68
-
69
- background-color: rgba(0,0,0,.5);
70
- }
71
-
72
- .dragover {
73
- background-color: rgba(0,0,0,.8);
74
- }
75
-
76
- .drop-error {
77
- color: red;
78
- font-weight: bold;
79
- }
80
- </style>
1
+ <template>
2
+ <div>
3
+ <p class="decode-result">Last result: <b>{{ result }}</b></p>
4
+
5
+ <p v-if="error !== null" class="drop-error">
6
+ {{ error }}
7
+ </p>
8
+
9
+ <qrcode-drop-zone @detect="onDetect" @dragover="onDragOver" @init="logErrors">
10
+ <div class="drop-area" :class="{ 'dragover': dragover }">
11
+ DROP SOME IMAGES HERE
12
+ </div>
13
+ </qrcode-drop-zone>
14
+ </div>
15
+ </template>
16
+
17
+ <script>
18
+ import { QrcodeDropZone } from '../../../../src'
19
+
20
+ export default {
21
+
22
+ components: { QrcodeDropZone },
23
+
24
+ data () {
25
+ return {
26
+ result: null,
27
+ error: null,
28
+ dragover: false
29
+ }
30
+ },
31
+
32
+ methods: {
33
+ async onDetect (promise) {
34
+ try {
35
+ const { content } = await promise
36
+
37
+ this.result = content
38
+ this.error = null
39
+ } catch (error) {
40
+ if (error.name === 'DropImageFetchError') {
41
+ this.error = 'Sorry, you can\'t load cross-origin images :/'
42
+ } else if (error.name === 'DropImageDecodeError') {
43
+ this.error = 'Ok, that\'s not an image. That can\'t be decoded.'
44
+ } else {
45
+ this.error = 'Ups, what kind of error is this?! ' + error.message
46
+ }
47
+ }
48
+ },
49
+
50
+ logErrors (promise) {
51
+ promise.catch(console.error)
52
+ },
53
+
54
+ onDragOver (isDraggingOver) {
55
+ this.dragover = isDraggingOver
56
+ }
57
+ }
58
+ }
59
+ </script>
60
+
61
+ <style>
62
+ .drop-area {
63
+ height: 300px;
64
+ color: #fff;
65
+ text-align: center;
66
+ font-weight: bold;
67
+ padding: 10px;
68
+
69
+ background-color: rgba(0,0,0,.5);
70
+ }
71
+
72
+ .dragover {
73
+ background-color: rgba(0,0,0,.8);
74
+ }
75
+
76
+ .drop-error {
77
+ color: red;
78
+ font-weight: bold;
79
+ }
80
+ </style>
@@ -1,115 +1,115 @@
1
- <template>
2
- <div :class="{ 'fullscreen': fullscreen }" ref="wrapper" @fullscreenchange="onFullscreenChange">
3
- <qrcode-stream @init="logErrors">
4
- <button @click="fullscreen = !fullscreen" class="fullscreen-button">
5
- <img :src="$withBase(fullscreenIcon)" alt="toggle fullscreen" />
6
- </button>
7
- </qrcode-stream>
8
- </div>
9
- </template>
10
-
11
- <script>
12
- import { QrcodeStream } from '../../../../src'
13
-
14
- // NOTE: calling `requestFullscreen` might prompt the user with another
15
- // permission dialog. You already asked for camera access permission so this is
16
- // a rather invasive move.
17
- //
18
- // Even without calling `requestFullscreen` the entire viewport is covered
19
- // by the camera stream. So consider skipping `requestFullscreen` in your
20
- // implementation.
21
-
22
- export default {
23
-
24
- components: { QrcodeStream },
25
-
26
- data () {
27
- return {
28
- fullscreen: false
29
- }
30
- },
31
-
32
- computed: {
33
- fullscreenIcon() {
34
- if (this.fullscreen) {
35
- return "/fullscreen-exit.svg"
36
- } else {
37
- return "/fullscreen.svg"
38
- }
39
- }
40
- },
41
-
42
- watch: {
43
- fullscreen(enterFullscreen) {
44
- if (enterFullscreen) {
45
- this.requestFullscreen()
46
- } else {
47
- this.exitFullscreen()
48
- }
49
- }
50
- },
51
-
52
- methods: {
53
- onFullscreenChange(event) {
54
- // This becomes important when the user doesn't use the button to exit
55
- // fullscreen but hits ESC on desktop, pushes a physical back button on
56
- // mobile etc.
57
-
58
- this.fullscreen = document.fullscreenElement !== null
59
- },
60
-
61
- requestFullscreen() {
62
- const elem = this.$refs.wrapper
63
-
64
- if (elem.requestFullscreen) {
65
- elem.requestFullscreen();
66
- } else if (elem.mozRequestFullScreen) { /* Firefox */
67
- elem.mozRequestFullScreen();
68
- } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
69
- elem.webkitRequestFullscreen();
70
- } else if (elem.msRequestFullscreen) { /* IE/Edge */
71
- elem.msRequestFullscreen();
72
- }
73
- },
74
-
75
- exitFullscreen() {
76
- if (document.exitFullscreen) {
77
- document.exitFullscreen();
78
- } else if (document.mozCancelFullScreen) { /* Firefox */
79
- document.mozCancelFullScreen();
80
- } else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
81
- document.webkitExitFullscreen();
82
- } else if (document.msExitFullscreen) { /* IE/Edge */
83
- document.msExitFullscreen();
84
- }
85
- },
86
-
87
- logErrors (promise) {
88
- promise.catch(console.error)
89
- }
90
- }
91
-
92
- }
93
- </script>
94
-
95
- <style scoped>
96
- .fullscreen {
97
- position: fixed;
98
- z-index: 1000;
99
- top: 0;
100
- bottom: 0;
101
- right: 0;
102
- left: 0;
103
- }
104
-
105
- .fullscreen-button {
106
- background-color: white;
107
- position: absolute;
108
- bottom: 0;
109
- right: 0;
110
- margin: 1rem;
111
- }
112
- .fullscreen-button img {
113
- width: 2rem;
114
- }
115
- </style>
1
+ <template>
2
+ <div :class="{ 'fullscreen': fullscreen }" ref="wrapper" @fullscreenchange="onFullscreenChange">
3
+ <qrcode-stream @init="logErrors">
4
+ <button @click="fullscreen = !fullscreen" class="fullscreen-button">
5
+ <img :src="$withBase(fullscreenIcon)" alt="toggle fullscreen" />
6
+ </button>
7
+ </qrcode-stream>
8
+ </div>
9
+ </template>
10
+
11
+ <script>
12
+ import { QrcodeStream } from '../../../../src'
13
+
14
+ // NOTE: calling `requestFullscreen` might prompt the user with another
15
+ // permission dialog. You already asked for camera access permission so this is
16
+ // a rather invasive move.
17
+ //
18
+ // Even without calling `requestFullscreen` the entire viewport is covered
19
+ // by the camera stream. So consider skipping `requestFullscreen` in your
20
+ // implementation.
21
+
22
+ export default {
23
+
24
+ components: { QrcodeStream },
25
+
26
+ data () {
27
+ return {
28
+ fullscreen: false
29
+ }
30
+ },
31
+
32
+ computed: {
33
+ fullscreenIcon() {
34
+ if (this.fullscreen) {
35
+ return "/fullscreen-exit.svg"
36
+ } else {
37
+ return "/fullscreen.svg"
38
+ }
39
+ }
40
+ },
41
+
42
+ watch: {
43
+ fullscreen(enterFullscreen) {
44
+ if (enterFullscreen) {
45
+ this.requestFullscreen()
46
+ } else {
47
+ this.exitFullscreen()
48
+ }
49
+ }
50
+ },
51
+
52
+ methods: {
53
+ onFullscreenChange(event) {
54
+ // This becomes important when the user doesn't use the button to exit
55
+ // fullscreen but hits ESC on desktop, pushes a physical back button on
56
+ // mobile etc.
57
+
58
+ this.fullscreen = document.fullscreenElement !== null
59
+ },
60
+
61
+ requestFullscreen() {
62
+ const elem = this.$refs.wrapper
63
+
64
+ if (elem.requestFullscreen) {
65
+ elem.requestFullscreen();
66
+ } else if (elem.mozRequestFullScreen) { /* Firefox */
67
+ elem.mozRequestFullScreen();
68
+ } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
69
+ elem.webkitRequestFullscreen();
70
+ } else if (elem.msRequestFullscreen) { /* IE/Edge */
71
+ elem.msRequestFullscreen();
72
+ }
73
+ },
74
+
75
+ exitFullscreen() {
76
+ if (document.exitFullscreen) {
77
+ document.exitFullscreen();
78
+ } else if (document.mozCancelFullScreen) { /* Firefox */
79
+ document.mozCancelFullScreen();
80
+ } else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
81
+ document.webkitExitFullscreen();
82
+ } else if (document.msExitFullscreen) { /* IE/Edge */
83
+ document.msExitFullscreen();
84
+ }
85
+ },
86
+
87
+ logErrors (promise) {
88
+ promise.catch(console.error)
89
+ }
90
+ }
91
+
92
+ }
93
+ </script>
94
+
95
+ <style scoped>
96
+ .fullscreen {
97
+ position: fixed;
98
+ z-index: 1000;
99
+ top: 0;
100
+ bottom: 0;
101
+ right: 0;
102
+ left: 0;
103
+ }
104
+
105
+ .fullscreen-button {
106
+ background-color: white;
107
+ position: absolute;
108
+ bottom: 0;
109
+ right: 0;
110
+ margin: 1rem;
111
+ }
112
+ .fullscreen-button img {
113
+ width: 2rem;
114
+ }
115
+ </style>