@vue-solana/vue 4.1.7 → 4.1.8

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/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ export { u as useSignAndSendTransactions } from './shared/vue.sPcsjyKU.mjs';
18
18
  export { u as useSignatureStatus } from './shared/vue.Bu2cQ690.mjs';
19
19
  export { u as useSignIn } from './shared/vue.SeuJipQ8.mjs';
20
20
  export { t as tryUseSolana, u as useSolana } from './shared/vue.CcOZ9858.mjs';
21
- export { u as useSolanaQrScanner } from './shared/vue.Btxdm--M.mjs';
21
+ export { u as useSolanaQrScanner } from './shared/vue.B7s1pOGD.mjs';
22
22
  export { u as useSolanaQrCode } from './shared/vue.Bo4nAja_.mjs';
23
23
  export { u as useSolanaPay } from './shared/vue.gvgOc5rc.mjs';
24
24
  export { u as useSolanaPayConfirmation } from './shared/vue.MN-kcudq.mjs';
@@ -1,6 +1,21 @@
1
1
  import { ref, shallowRef, onUnmounted } from 'vue';
2
2
  import { parseURL } from '@vue-solana/core/solana-pay';
3
3
 
4
+ async function createQrCodeDetector() {
5
+ const BarcodeDetectorCtor = globalThis.BarcodeDetector;
6
+ if (!BarcodeDetectorCtor) {
7
+ return null;
8
+ }
9
+ try {
10
+ const formats = await BarcodeDetectorCtor.getSupportedFormats?.();
11
+ if (formats && !formats.includes("qr_code")) {
12
+ return null;
13
+ }
14
+ return new BarcodeDetectorCtor({ formats: ["qr_code"] });
15
+ } catch {
16
+ return null;
17
+ }
18
+ }
4
19
  function useSolanaQrScanner() {
5
20
  const scanning = ref(false);
6
21
  const result = shallowRef(null);
@@ -8,7 +23,7 @@ function useSolanaQrScanner() {
8
23
  const error = ref(null);
9
24
  let mediaStream = null;
10
25
  let videoElement = null;
11
- let scanInterval = null;
26
+ let scanTimer = null;
12
27
  let barcodeDetector = null;
13
28
  let stopped = false;
14
29
  function stopTracks() {
@@ -23,9 +38,9 @@ function useSolanaQrScanner() {
23
38
  }
24
39
  }
25
40
  function clearTimer() {
26
- if (scanInterval) {
27
- clearInterval(scanInterval);
28
- scanInterval = null;
41
+ if (scanTimer) {
42
+ clearTimeout(scanTimer);
43
+ scanTimer = null;
29
44
  }
30
45
  }
31
46
  async function scanFromText(text) {
@@ -39,6 +54,23 @@ function useSolanaQrScanner() {
39
54
  throw e;
40
55
  }
41
56
  }
57
+ async function scanFrame() {
58
+ if (!barcodeDetector || !videoElement || videoElement.readyState < 2) {
59
+ return false;
60
+ }
61
+ try {
62
+ const codes = await barcodeDetector.detect(videoElement);
63
+ const text = codes[0]?.rawValue || codes[0]?.raw || codes[0]?.value;
64
+ if (!text) {
65
+ return false;
66
+ }
67
+ await scanFromText(text);
68
+ return true;
69
+ } catch (e) {
70
+ error.value = e;
71
+ return false;
72
+ }
73
+ }
42
74
  async function start(options = {}) {
43
75
  if (typeof window === "undefined") {
44
76
  const err = new Error("Scanner can only run in the browser");
@@ -51,21 +83,15 @@ function useSolanaQrScanner() {
51
83
  videoElement = options.video ?? null;
52
84
  const intervalMs = options.scanIntervalMs ?? 500;
53
85
  try {
54
- const BarcodeDetectorCtor = globalThis.BarcodeDetector;
55
- if (BarcodeDetectorCtor) {
56
- try {
57
- barcodeDetector = new BarcodeDetectorCtor({
58
- formats: ["qr_code"]
59
- });
60
- } catch {
61
- barcodeDetector = null;
62
- }
63
- }
64
86
  if (!navigator?.mediaDevices?.getUserMedia) {
65
87
  throw new Error("Camera not available");
66
88
  }
89
+ barcodeDetector = await createQrCodeDetector();
90
+ if (!barcodeDetector) {
91
+ throw new Error("This browser cannot detect QR codes. Paste the payment URL instead.");
92
+ }
67
93
  mediaStream = await navigator.mediaDevices.getUserMedia({
68
- video: { facingMode: "environment" }
94
+ video: { facingMode: "environment", width: { ideal: 1280 }, height: { ideal: 720 } }
69
95
  });
70
96
  if (videoElement) {
71
97
  videoElement.srcObject = mediaStream;
@@ -74,25 +100,19 @@ function useSolanaQrScanner() {
74
100
  }
75
101
  scanning.value = true;
76
102
  clearTimer();
77
- scanInterval = setInterval(async () => {
78
- if (stopped || !scanning.value) return;
79
- try {
80
- if (barcodeDetector && videoElement) {
81
- const codes = await barcodeDetector.detect(videoElement);
82
- if (codes && codes.length > 0) {
83
- const text = codes[0]?.rawValue || codes[0]?.raw || codes[0]?.value;
84
- if (text) {
85
- try {
86
- await scanFromText(text);
87
- } catch {
88
- }
89
- }
90
- }
103
+ const scheduleScan = () => {
104
+ scanTimer = setTimeout(async () => {
105
+ if (stopped || !scanning.value) return;
106
+ if (await scanFrame()) {
107
+ stop();
108
+ return;
91
109
  }
92
- } catch (e) {
93
- error.value = e;
94
- }
95
- }, intervalMs);
110
+ if (!stopped && scanning.value) {
111
+ scheduleScan();
112
+ }
113
+ }, intervalMs);
114
+ };
115
+ scheduleScan();
96
116
  } catch (e) {
97
117
  error.value = e;
98
118
  stopTracks();
@@ -6,7 +6,7 @@ declare function useSolanaPay(): {
6
6
  requestUrl: vue.ShallowRef<string | null, string | null>;
7
7
  parsedRequest: vue.ShallowRef<unknown, unknown>;
8
8
  reference: vue.ShallowRef<unknown, unknown>;
9
- status: vue.ShallowRef<"confirmed" | "finalized" | "error" | "idle" | "pending" | "found" | "expired", "confirmed" | "finalized" | "error" | "idle" | "pending" | "found" | "expired">;
9
+ status: vue.ShallowRef<"idle" | "error" | "confirmed" | "finalized" | "pending" | "found" | "expired", "idle" | "error" | "confirmed" | "finalized" | "pending" | "found" | "expired">;
10
10
  loading: vue.ShallowRef<boolean, boolean>;
11
11
  error: vue.ShallowRef<unknown, unknown>;
12
12
  createTransferRequest: (input: Record<string, unknown>) => Promise<string>;
@@ -1 +1 @@
1
- export { u as useSolanaQrScanner } from './shared/vue.Btxdm--M.mjs';
1
+ export { u as useSolanaQrScanner } from './shared/vue.B7s1pOGD.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-solana/vue",
3
- "version": "4.1.7",
3
+ "version": "4.1.8",
4
4
  "description": "Vue plugin and composables for Solana applications.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -194,7 +194,7 @@
194
194
  "access": "public"
195
195
  },
196
196
  "dependencies": {
197
- "@vue-solana/core": "4.1.7"
197
+ "@vue-solana/core": "4.1.8"
198
198
  },
199
199
  "peerDependencies": {
200
200
  "vue": "^3.5.0"