@vue-solana/vue 4.1.8 → 4.1.10
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.
|
|
21
|
+
export { u as useSolanaQrScanner } from './shared/vue.D0MQeVy2.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,7 @@
|
|
|
1
1
|
import { ref, shallowRef, onUnmounted } from 'vue';
|
|
2
2
|
import { parseURL } from '@vue-solana/core/solana-pay';
|
|
3
3
|
|
|
4
|
+
const DECODE_SIZE = 720;
|
|
4
5
|
async function createQrCodeDetector() {
|
|
5
6
|
const BarcodeDetectorCtor = globalThis.BarcodeDetector;
|
|
6
7
|
if (!BarcodeDetectorCtor) {
|
|
@@ -16,6 +17,18 @@ async function createQrCodeDetector() {
|
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
20
|
+
async function loadQrDecoder() {
|
|
21
|
+
try {
|
|
22
|
+
const mod = await import('jsqr');
|
|
23
|
+
const jsQR = mod.default ?? mod;
|
|
24
|
+
if (typeof jsQR !== "function") {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return (data, width, height) => jsQR(data, width, height, { inversionAttempts: "dontInvert" })?.data || null;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
19
32
|
function useSolanaQrScanner() {
|
|
20
33
|
const scanning = ref(false);
|
|
21
34
|
const result = shallowRef(null);
|
|
@@ -25,6 +38,8 @@ function useSolanaQrScanner() {
|
|
|
25
38
|
let videoElement = null;
|
|
26
39
|
let scanTimer = null;
|
|
27
40
|
let barcodeDetector = null;
|
|
41
|
+
let qrDecoder = null;
|
|
42
|
+
let frameCanvas = null;
|
|
28
43
|
let stopped = false;
|
|
29
44
|
function stopTracks() {
|
|
30
45
|
if (mediaStream) {
|
|
@@ -54,20 +69,55 @@ function useSolanaQrScanner() {
|
|
|
54
69
|
throw e;
|
|
55
70
|
}
|
|
56
71
|
}
|
|
72
|
+
async function detectWithBrowser(video) {
|
|
73
|
+
if (!barcodeDetector) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const codes = await barcodeDetector.detect(video);
|
|
78
|
+
return codes[0]?.rawValue || codes[0]?.raw || codes[0]?.value || null;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function decodeFrame(video) {
|
|
84
|
+
const side = Math.min(video.videoWidth, video.videoHeight);
|
|
85
|
+
if (!qrDecoder || !side) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const size = Math.min(side, DECODE_SIZE);
|
|
89
|
+
frameCanvas ??= document.createElement("canvas");
|
|
90
|
+
frameCanvas.width = size;
|
|
91
|
+
frameCanvas.height = size;
|
|
92
|
+
const context = frameCanvas.getContext("2d", { willReadFrequently: true });
|
|
93
|
+
if (!context) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
context.drawImage(
|
|
97
|
+
video,
|
|
98
|
+
(video.videoWidth - side) / 2,
|
|
99
|
+
(video.videoHeight - side) / 2,
|
|
100
|
+
side,
|
|
101
|
+
side,
|
|
102
|
+
0,
|
|
103
|
+
0,
|
|
104
|
+
size,
|
|
105
|
+
size
|
|
106
|
+
);
|
|
107
|
+
return qrDecoder(context.getImageData(0, 0, size, size).data, size, size);
|
|
108
|
+
}
|
|
57
109
|
async function scanFrame() {
|
|
58
|
-
if (!
|
|
110
|
+
if (!videoElement || videoElement.readyState < 2) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const text = await detectWithBrowser(videoElement) ?? decodeFrame(videoElement);
|
|
114
|
+
if (!text) {
|
|
59
115
|
return false;
|
|
60
116
|
}
|
|
61
117
|
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
118
|
await scanFromText(text);
|
|
68
119
|
return true;
|
|
69
|
-
} catch
|
|
70
|
-
error.value = e;
|
|
120
|
+
} catch {
|
|
71
121
|
return false;
|
|
72
122
|
}
|
|
73
123
|
}
|
|
@@ -86,8 +136,8 @@ function useSolanaQrScanner() {
|
|
|
86
136
|
if (!navigator?.mediaDevices?.getUserMedia) {
|
|
87
137
|
throw new Error("Camera not available");
|
|
88
138
|
}
|
|
89
|
-
barcodeDetector = await createQrCodeDetector();
|
|
90
|
-
if (!barcodeDetector) {
|
|
139
|
+
[barcodeDetector, qrDecoder] = await Promise.all([createQrCodeDetector(), loadQrDecoder()]);
|
|
140
|
+
if (!barcodeDetector && !qrDecoder) {
|
|
91
141
|
throw new Error("This browser cannot detect QR codes. Paste the payment URL instead.");
|
|
92
142
|
}
|
|
93
143
|
mediaStream = await navigator.mediaDevices.getUserMedia({
|
package/dist/useSolanaPay.d.ts
CHANGED
|
@@ -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<"
|
|
9
|
+
status: vue.ShallowRef<"confirmed" | "finalized" | "error" | "idle" | "pending" | "found" | "expired", "confirmed" | "finalized" | "error" | "idle" | "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.
|
|
1
|
+
export { u as useSolanaQrScanner } from './shared/vue.D0MQeVy2.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-solana/vue",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.10",
|
|
4
4
|
"description": "Vue plugin and composables for Solana applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -194,7 +194,8 @@
|
|
|
194
194
|
"access": "public"
|
|
195
195
|
},
|
|
196
196
|
"dependencies": {
|
|
197
|
-
"
|
|
197
|
+
"jsqr": "^1.4.0",
|
|
198
|
+
"@vue-solana/core": "4.1.10"
|
|
198
199
|
},
|
|
199
200
|
"peerDependencies": {
|
|
200
201
|
"vue": "^3.5.0"
|