persagy-vant 0.0.51 → 0.0.52

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 (79) hide show
  1. package/THIRD_PARTY_NOTICES.txt +439 -0
  2. package/es/icon/assets/flashlight-off.svg +4 -0
  3. package/es/icon/assets/flashlight.svg +4 -0
  4. package/es/icon/config.mjs +1 -1
  5. package/es/icon/index.css +1 -1
  6. package/es/icon/latest-iconfont.css +1 -1
  7. package/es/icon/latest-iconfont.less +16 -1
  8. package/es/index.d.ts +2 -1
  9. package/es/index.mjs +4 -1
  10. package/es/location-select/LocationSelect.d.ts +15 -1
  11. package/es/location-select/LocationSelect.mjs +17 -5
  12. package/es/location-select/index.d.ts +11 -1
  13. package/es/object-select/ObjectSelect.d.ts +15 -1
  14. package/es/object-select/ObjectSelect.mjs +19 -7
  15. package/es/object-select/index.d.ts +11 -1
  16. package/es/qr-scanner/QrScanner.d.ts +226 -0
  17. package/es/qr-scanner/QrScanner.mjs +615 -0
  18. package/es/qr-scanner/decoder.d.ts +10 -0
  19. package/es/qr-scanner/decoder.mjs +101 -0
  20. package/es/qr-scanner/function-call.d.ts +164 -0
  21. package/es/qr-scanner/function-call.mjs +69 -0
  22. package/es/qr-scanner/index.css +1 -0
  23. package/es/qr-scanner/index.d.ts +10 -0
  24. package/es/qr-scanner/index.less +239 -0
  25. package/es/qr-scanner/index.mjs +6 -0
  26. package/es/qr-scanner/style/index.mjs +8 -0
  27. package/es/qr-scanner/style/less.mjs +8 -0
  28. package/es/qr-scanner/types.d.ts +54 -0
  29. package/es/qr-scanner/types.mjs +0 -0
  30. package/es/qr-scanner/var.css +0 -0
  31. package/es/qr-scanner/var.less +4 -0
  32. package/es/qr-scanner/wasm.d.ts +4 -0
  33. package/lib/decoder-8f5b00db.js +2215 -0
  34. package/lib/decoder-a36ba9ae.mjs +2215 -0
  35. package/lib/icon/assets/flashlight-off.svg +4 -0
  36. package/lib/icon/assets/flashlight.svg +4 -0
  37. package/lib/icon/config.js +1 -1
  38. package/lib/icon/index.css +1 -1
  39. package/lib/icon/latest-iconfont.css +1 -1
  40. package/lib/icon/latest-iconfont.less +16 -1
  41. package/lib/index.css +1 -1
  42. package/lib/index.d.ts +2 -1
  43. package/lib/index.js +4 -1
  44. package/lib/index.less +1 -0
  45. package/lib/location-select/LocationSelect.d.ts +15 -1
  46. package/lib/location-select/LocationSelect.js +16 -4
  47. package/lib/location-select/index.d.ts +11 -1
  48. package/lib/object-select/ObjectSelect.d.ts +15 -1
  49. package/lib/object-select/ObjectSelect.js +18 -6
  50. package/lib/object-select/index.d.ts +11 -1
  51. package/lib/qr-scanner/QrScanner.d.ts +226 -0
  52. package/lib/qr-scanner/QrScanner.js +644 -0
  53. package/lib/qr-scanner/decoder.d.ts +10 -0
  54. package/lib/qr-scanner/decoder.js +130 -0
  55. package/lib/qr-scanner/function-call.d.ts +164 -0
  56. package/lib/qr-scanner/function-call.js +98 -0
  57. package/lib/qr-scanner/index.css +1 -0
  58. package/lib/qr-scanner/index.d.ts +10 -0
  59. package/lib/qr-scanner/index.js +25 -0
  60. package/lib/qr-scanner/index.less +239 -0
  61. package/lib/qr-scanner/style/index.js +8 -0
  62. package/lib/qr-scanner/style/less.js +8 -0
  63. package/lib/qr-scanner/types.d.ts +54 -0
  64. package/lib/qr-scanner/types.js +15 -0
  65. package/lib/qr-scanner/var.css +0 -0
  66. package/lib/qr-scanner/var.less +4 -0
  67. package/lib/qr-scanner/wasm.d.ts +4 -0
  68. package/lib/vant.cjs.js +1805 -1114
  69. package/lib/vant.es.js +1805 -1114
  70. package/lib/vant.js +5251 -2339
  71. package/lib/vant.min.js +1 -1
  72. package/lib/web-types.json +1 -1
  73. package/lib/zxing_reader-075835e4.mjs +4 -0
  74. package/lib/zxing_reader-d6a2742e.js +4 -0
  75. package/package.json +6 -4
  76. package/skills/use-persagy-vant/references/component-catalog.md +1 -0
  77. package/skills/use-persagy-vant/references/component-documentation.md +4 -4
  78. package/skills/use-persagy-vant/references/component-variant-selection.md +2 -2
  79. package/skills/use-persagy-vant/references/reuse-policy.md +2 -2
@@ -0,0 +1,615 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { defineComponent, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch, createVNode as _createVNode, Fragment as _Fragment, createTextVNode as _createTextVNode } from "vue";
22
+ import { createNamespace, extend, makeArrayProp, makeNumericProp, makeStringProp, numericProp, truthProp } from "../utils/index.mjs";
23
+ import { useExpose } from "../composables/use-expose.mjs";
24
+ import { useId } from "../composables/use-id.mjs";
25
+ import { Button } from "../button/index.mjs";
26
+ import { Icon } from "../icon/index.mjs";
27
+ import { Loading } from "../loading/index.mjs";
28
+ import { Popup } from "../popup/index.mjs";
29
+ const [name, bem] = createNamespace("qr-scanner");
30
+ const qrScannerProps = {
31
+ show: Boolean,
32
+ title: makeStringProp("\u626B\u63CF\u8BBE\u5907\u4E8C\u7EF4\u7801"),
33
+ tip: makeStringProp("\u5C06\u8BBE\u5907\u4E8C\u7EF4\u7801\u7F6E\u4E8E\u53D6\u666F\u6846\u5185\uFF0C\u5373\u53EF\u81EA\u52A8\u8BC6\u522B"),
34
+ processingText: makeStringProp("\u6B63\u5728\u5904\u7406\u626B\u7801\u7ED3\u679C..."),
35
+ formats: extend(makeArrayProp(), {
36
+ default: () => ["QRCode"]
37
+ }),
38
+ facingMode: makeStringProp("environment"),
39
+ showAlbum: truthProp,
40
+ showTorch: truthProp,
41
+ showSwitchCamera: truthProp,
42
+ closeAfterScan: truthProp,
43
+ scanInterval: makeNumericProp(150),
44
+ duplicateInterval: makeNumericProp(2e3),
45
+ maxImageSize: makeNumericProp(20 * 1024 * 1024),
46
+ paused: Boolean,
47
+ wasmUrl: String,
48
+ beforeConfirm: Function,
49
+ nativeScan: Function,
50
+ teleport: {
51
+ type: [String, Object],
52
+ default: "body"
53
+ },
54
+ zIndex: numericProp,
55
+ closeOnPopstate: truthProp
56
+ };
57
+ var stdin_default = defineComponent({
58
+ name,
59
+ props: qrScannerProps,
60
+ emits: ["update:show", "scan", "error", "cancel", "close", "closed", "ready"],
61
+ setup(props, {
62
+ emit
63
+ }) {
64
+ const torchHintId = `${useId()}-torch-hint`;
65
+ const video = ref();
66
+ const frame = ref();
67
+ const fileInput = ref();
68
+ const phase = ref("idle");
69
+ const message = ref("");
70
+ const hasTorch = ref(false);
71
+ const torchOn = ref(false);
72
+ const torchChanging = ref(false);
73
+ const cameraCount = ref(0);
74
+ let cameras = [];
75
+ let deviceId;
76
+ let stream;
77
+ let canvas;
78
+ let timer;
79
+ let generation = 0;
80
+ let abortController;
81
+ let resumeWhenVisible = false;
82
+ const recentResults = /* @__PURE__ */ new Map();
83
+ const isCurrent = (id) => id === generation && props.show && !props.paused;
84
+ const release = () => {
85
+ generation += 1;
86
+ if (timer)
87
+ clearTimeout(timer);
88
+ timer = void 0;
89
+ abortController == null ? void 0 : abortController.abort();
90
+ abortController = void 0;
91
+ stream == null ? void 0 : stream.getTracks().forEach((track) => track.stop());
92
+ stream = void 0;
93
+ if (video.value)
94
+ video.value.srcObject = null;
95
+ hasTorch.value = false;
96
+ torchOn.value = false;
97
+ torchChanging.value = false;
98
+ };
99
+ const stop = () => {
100
+ release();
101
+ phase.value = "paused";
102
+ };
103
+ const close = (cancelled = false) => {
104
+ release();
105
+ phase.value = "idle";
106
+ if (cancelled)
107
+ emit("cancel");
108
+ emit("update:show", false);
109
+ };
110
+ const reportError = (code, text, cause) => {
111
+ release();
112
+ phase.value = "error";
113
+ message.value = text;
114
+ emit("error", {
115
+ code,
116
+ message: text,
117
+ cause
118
+ });
119
+ };
120
+ const cameraError = (error) => {
121
+ const errorName = error == null ? void 0 : error.name;
122
+ if (errorName === "NotAllowedError" || errorName === "PermissionDeniedError") {
123
+ reportError("CAMERA_PERMISSION_DENIED", "\u65E0\u6CD5\u4F7F\u7528\u6444\u50CF\u5934\uFF0C\u8BF7\u5141\u8BB8\u76F8\u673A\u6743\u9650\uFF1B\u4E5F\u53EF\u4EE5\u4ECE\u76F8\u518C\u8BC6\u522B", error);
124
+ } else if (errorName === "NotFoundError" || errorName === "DevicesNotFoundError") {
125
+ reportError("CAMERA_NOT_FOUND", "\u672A\u627E\u5230\u53EF\u7528\u6444\u50CF\u5934\uFF0C\u8BF7\u4ECE\u76F8\u518C\u8BC6\u522B", error);
126
+ } else {
127
+ reportError("CAMERA_UNAVAILABLE", "\u6444\u50CF\u5934\u542F\u52A8\u5931\u8D25\uFF0C\u8BF7\u5173\u95ED\u5176\u4ED6\u5360\u7528\u76F8\u673A\u7684\u5E94\u7528\u540E\u91CD\u8BD5", error);
128
+ }
129
+ };
130
+ const schedule = (id, decoder) => {
131
+ if (!isCurrent(id) || phase.value !== "scanning")
132
+ return;
133
+ timer = setTimeout(
134
+ // The frame reader schedules the next iteration of this loop.
135
+ // eslint-disable-next-line no-use-before-define
136
+ () => scanFrame(id, decoder),
137
+ Math.max(100, Number(props.scanInterval) || 150)
138
+ );
139
+ };
140
+ const acceptResult = (result, id) => __async(this, null, function* () {
141
+ var _a;
142
+ if (!isCurrent(id))
143
+ return;
144
+ const now = Date.now();
145
+ if (result.source === "camera" && now - (recentResults.get(result.text) || 0) < Number(props.duplicateInterval))
146
+ return;
147
+ recentResults.set(result.text, now);
148
+ if (recentResults.size > 100) {
149
+ recentResults.delete(recentResults.keys().next().value);
150
+ }
151
+ phase.value = "processing";
152
+ message.value = "";
153
+ try {
154
+ const accepted = yield (_a = props.beforeConfirm) == null ? void 0 : _a.call(props, result);
155
+ if (!isCurrent(id))
156
+ return;
157
+ if (accepted === false) {
158
+ stop();
159
+ message.value = "\u672C\u6B21\u626B\u7801\u7ED3\u679C\u672A\u786E\u8BA4\uFF0C\u8BF7\u7EE7\u7EED\u626B\u63CF";
160
+ return;
161
+ }
162
+ emit("scan", result);
163
+ if (!isCurrent(id))
164
+ return;
165
+ if (props.closeAfterScan) {
166
+ close();
167
+ } else if (result.source === "camera") {
168
+ phase.value = "scanning";
169
+ } else {
170
+ timer = setTimeout(
171
+ // Non-camera sources restart through the same acquisition path.
172
+ // eslint-disable-next-line no-use-before-define
173
+ start,
174
+ Math.max(100, Number(props.scanInterval) || 150)
175
+ );
176
+ }
177
+ } catch (error) {
178
+ if (isCurrent(id)) {
179
+ reportError("CONFIRM_FAILED", (error == null ? void 0 : error.message) || "\u8BBE\u5907\u4FE1\u606F\u67E5\u8BE2\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5", error);
180
+ }
181
+ }
182
+ });
183
+ function scanFrame(id, decoder) {
184
+ return __async(this, null, function* () {
185
+ var _a;
186
+ if (!isCurrent(id) || phase.value !== "scanning" || !video.value)
187
+ return;
188
+ try {
189
+ canvas || (canvas = document.createElement("canvas"));
190
+ const viewport = video.value.getBoundingClientRect();
191
+ const target = (_a = frame.value) == null ? void 0 : _a.getBoundingClientRect();
192
+ if (!viewport.width || !viewport.height || !(target == null ? void 0 : target.width)) {
193
+ schedule(id, decoder);
194
+ return;
195
+ }
196
+ const scale = Math.max(viewport.width / video.value.videoWidth, viewport.height / video.value.videoHeight);
197
+ const offsetX = (video.value.videoWidth * scale - viewport.width) / 2;
198
+ const offsetY = (video.value.videoHeight * scale - viewport.height) / 2;
199
+ const image = decoder.captureImage(video.value, canvas, 1280, {
200
+ x: (target.left - viewport.left + offsetX) / scale,
201
+ y: (target.top - viewport.top + offsetY) / scale,
202
+ width: target.width / scale,
203
+ height: target.height / scale
204
+ });
205
+ if (image) {
206
+ const result = yield decoder.decode(image, props.formats, props.wasmUrl);
207
+ if (!isCurrent(id))
208
+ return;
209
+ if (result)
210
+ yield acceptResult({
211
+ text: result.text,
212
+ format: result.format,
213
+ source: "camera"
214
+ }, id);
215
+ }
216
+ schedule(id, decoder);
217
+ } catch (error) {
218
+ if (isCurrent(id))
219
+ reportError("DECODE_FAILED", "\u8BC6\u522B\u670D\u52A1\u5F02\u5E38\uFF0C\u8BF7\u91CD\u8BD5\u6216\u4ECE\u76F8\u518C\u8BC6\u522B", error);
220
+ }
221
+ });
222
+ }
223
+ function start() {
224
+ return __async(this, null, function* () {
225
+ var _a, _b, _c, _d;
226
+ release();
227
+ if (!props.show || props.paused || document.hidden) {
228
+ phase.value = "paused";
229
+ return;
230
+ }
231
+ const id = generation;
232
+ phase.value = "starting";
233
+ message.value = "";
234
+ if (props.nativeScan) {
235
+ abortController = new AbortController();
236
+ try {
237
+ const result = yield props.nativeScan({
238
+ formats: props.formats,
239
+ signal: abortController.signal
240
+ });
241
+ if (!isCurrent(id))
242
+ return;
243
+ if (!result)
244
+ close(true);
245
+ else if (typeof result.text !== "string" || !result.text.length) {
246
+ reportError("NATIVE_SCAN_FAILED", "\u672A\u83B7\u53D6\u5230\u4E8C\u7EF4\u7801\u5185\u5BB9\uFF0C\u8BF7\u91CD\u65B0\u626B\u63CF");
247
+ } else
248
+ yield acceptResult({
249
+ text: result.text,
250
+ format: result.format || "QRCode",
251
+ source: "native"
252
+ }, id);
253
+ } catch (error) {
254
+ if (isCurrent(id))
255
+ reportError("NATIVE_SCAN_FAILED", (error == null ? void 0 : error.message) || "\u5BBF\u4E3B\u626B\u7801\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5", error);
256
+ }
257
+ return;
258
+ }
259
+ if (window.isSecureContext === false) {
260
+ reportError("INSECURE_CONTEXT", "\u5B9E\u65F6\u626B\u7801\u9700\u8981 HTTPS \u5B89\u5168\u9875\u9762\uFF0C\u8BF7\u6539\u7528 HTTPS \u6216\u4ECE\u76F8\u518C\u8BC6\u522B");
261
+ return;
262
+ }
263
+ if (!((_a = navigator.mediaDevices) == null ? void 0 : _a.getUserMedia)) {
264
+ reportError("CAMERA_UNSUPPORTED", "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u5B9E\u65F6\u626B\u7801\uFF0C\u8BF7\u4ECE\u76F8\u518C\u8BC6\u522B\u6216\u5728\u7CFB\u7EDF\u6D4F\u89C8\u5668\u6253\u5F00");
265
+ return;
266
+ }
267
+ try {
268
+ const acquiredStream = yield navigator.mediaDevices.getUserMedia({
269
+ audio: false,
270
+ video: extend(deviceId ? {
271
+ deviceId: {
272
+ exact: deviceId
273
+ }
274
+ } : {
275
+ facingMode: {
276
+ ideal: props.facingMode
277
+ }
278
+ }, {
279
+ width: {
280
+ ideal: 1280
281
+ },
282
+ height: {
283
+ ideal: 720
284
+ }
285
+ })
286
+ });
287
+ if (!isCurrent(id)) {
288
+ acquiredStream.getTracks().forEach((track2) => track2.stop());
289
+ return;
290
+ }
291
+ stream = acquiredStream;
292
+ yield nextTick();
293
+ if (!isCurrent(id))
294
+ return;
295
+ if (!video.value)
296
+ throw new Error("\u626B\u7801\u9884\u89C8\u5C1A\u672A\u5C31\u7EEA");
297
+ video.value.srcObject = stream;
298
+ yield video.value.play();
299
+ } catch (error) {
300
+ if (isCurrent(id))
301
+ cameraError(error);
302
+ return;
303
+ }
304
+ let decoder;
305
+ try {
306
+ decoder = yield import("./decoder");
307
+ yield decoder.prepareDecoder(props.wasmUrl);
308
+ } catch (error) {
309
+ if (isCurrent(id))
310
+ reportError("DECODER_LOAD_FAILED", "\u626B\u7801\u8D44\u6E90\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u8D44\u6E90\u90E8\u7F72\u540E\u91CD\u8BD5", error);
311
+ return;
312
+ }
313
+ if (!isCurrent(id))
314
+ return;
315
+ const track = stream == null ? void 0 : stream.getVideoTracks()[0];
316
+ try {
317
+ const capability = (_b = track == null ? void 0 : track.getCapabilities) == null ? void 0 : _b.call(track).torch;
318
+ hasTorch.value = Array.isArray(capability) ? capability.includes(true) : capability === true;
319
+ } catch (e) {
320
+ hasTorch.value = false;
321
+ }
322
+ track == null ? void 0 : track.addEventListener("ended", () => {
323
+ if (isCurrent(id))
324
+ reportError("CAMERA_UNAVAILABLE", "\u6444\u50CF\u5934\u5DF2\u4E2D\u65AD\uFF0C\u8BF7\u91CD\u65B0\u5C1D\u8BD5");
325
+ }, {
326
+ once: true
327
+ });
328
+ (_d = (_c = navigator.mediaDevices).enumerateDevices) == null ? void 0 : _d.call(_c).then((devices) => {
329
+ if (!isCurrent(id))
330
+ return;
331
+ cameras = devices.filter((device) => device.kind === "videoinput");
332
+ cameraCount.value = cameras.length;
333
+ }).catch(() => {
334
+ });
335
+ phase.value = "scanning";
336
+ emit("ready", {
337
+ torch: hasTorch.value
338
+ });
339
+ schedule(id, decoder);
340
+ });
341
+ }
342
+ const scanImage = (file) => __async(this, null, function* () {
343
+ if (!props.show || props.paused)
344
+ return;
345
+ if (file.size > Number(props.maxImageSize)) {
346
+ reportError("IMAGE_TOO_LARGE", "\u56FE\u7247\u8FC7\u5927\uFF0C\u8BF7\u9009\u62E9\u8F83\u5C0F\u7684\u56FE\u7247");
347
+ return;
348
+ }
349
+ release();
350
+ const id = generation;
351
+ phase.value = "processing";
352
+ message.value = "";
353
+ let imageCanvas;
354
+ try {
355
+ const decoder = yield import("./decoder");
356
+ const image = yield decoder.loadImage(file);
357
+ if (!isCurrent(id))
358
+ return;
359
+ imageCanvas = document.createElement("canvas");
360
+ const data = decoder.captureImage(image, imageCanvas, 1920);
361
+ if (!data)
362
+ throw new Error("\u65E0\u6CD5\u8BFB\u53D6\u56FE\u7247");
363
+ const result = yield decoder.decode(data, props.formats, props.wasmUrl);
364
+ if (!isCurrent(id))
365
+ return;
366
+ if (!result) {
367
+ reportError("IMAGE_NOT_FOUND", "\u56FE\u7247\u4E2D\u672A\u8BC6\u522B\u5230\u4E8C\u7EF4\u7801\uFF0C\u8BF7\u9009\u62E9\u6E05\u6670\u7684\u8BBE\u5907\u4E8C\u7EF4\u7801\u56FE\u7247");
368
+ return;
369
+ }
370
+ yield acceptResult({
371
+ text: result.text,
372
+ format: result.format,
373
+ source: "image"
374
+ }, id);
375
+ } catch (error) {
376
+ if (isCurrent(id))
377
+ reportError("DECODE_FAILED", (error == null ? void 0 : error.message) || "\u56FE\u7247\u8BC6\u522B\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5", error);
378
+ } finally {
379
+ if (imageCanvas) {
380
+ imageCanvas.width = 0;
381
+ imageCanvas.height = 0;
382
+ }
383
+ }
384
+ });
385
+ const toggleTorch = () => __async(this, null, function* () {
386
+ const id = generation;
387
+ const track = stream == null ? void 0 : stream.getVideoTracks()[0];
388
+ if (!track || !hasTorch.value || torchChanging.value || phase.value === "starting" || phase.value === "processing")
389
+ return;
390
+ const enabled = !torchOn.value;
391
+ torchChanging.value = true;
392
+ try {
393
+ yield track.applyConstraints({
394
+ advanced: [{
395
+ torch: enabled
396
+ }]
397
+ });
398
+ if (isCurrent(id))
399
+ torchOn.value = enabled;
400
+ } catch (error) {
401
+ if (isCurrent(id)) {
402
+ hasTorch.value = false;
403
+ emit("error", {
404
+ code: "TORCH_UNAVAILABLE",
405
+ message: "\u5F53\u524D\u6444\u50CF\u5934\u65E0\u6CD5\u5F00\u542F\u624B\u7535\u7B52",
406
+ cause: error
407
+ });
408
+ }
409
+ } finally {
410
+ if (isCurrent(id))
411
+ torchChanging.value = false;
412
+ }
413
+ });
414
+ const switchCamera = () => {
415
+ var _a, _b;
416
+ const current = (_a = stream == null ? void 0 : stream.getVideoTracks()[0]) == null ? void 0 : _a.getSettings().deviceId;
417
+ const index = cameras.findIndex((camera) => camera.deviceId === current);
418
+ deviceId = (_b = cameras[(index + 1) % cameras.length]) == null ? void 0 : _b.deviceId;
419
+ start();
420
+ };
421
+ const onVisibilityChange = () => {
422
+ if (props.nativeScan)
423
+ return;
424
+ if (document.hidden) {
425
+ resumeWhenVisible = props.show && (phase.value === "scanning" || phase.value === "starting");
426
+ stop();
427
+ } else if (resumeWhenVisible) {
428
+ resumeWhenVisible = false;
429
+ start();
430
+ }
431
+ };
432
+ watch(() => props.show, (show) => __async(this, null, function* () {
433
+ release();
434
+ recentResults.clear();
435
+ if (show) {
436
+ deviceId = void 0;
437
+ yield nextTick();
438
+ if (props.show)
439
+ start();
440
+ } else {
441
+ phase.value = "idle";
442
+ resumeWhenVisible = false;
443
+ }
444
+ }), {
445
+ immediate: true
446
+ });
447
+ watch(() => props.paused, (paused) => {
448
+ if (paused)
449
+ stop();
450
+ else if (props.show)
451
+ start();
452
+ });
453
+ watch(() => props.facingMode, () => {
454
+ deviceId = void 0;
455
+ if (props.show)
456
+ start();
457
+ });
458
+ onMounted(() => document.addEventListener("visibilitychange", onVisibilityChange));
459
+ onBeforeUnmount(() => {
460
+ release();
461
+ if (canvas) {
462
+ canvas.width = 0;
463
+ canvas.height = 0;
464
+ }
465
+ document.removeEventListener("visibilitychange", onVisibilityChange);
466
+ });
467
+ onDeactivated(stop);
468
+ onActivated(() => {
469
+ if (props.show && phase.value === "paused")
470
+ start();
471
+ });
472
+ useExpose({
473
+ start,
474
+ stop,
475
+ close: () => close(true),
476
+ scanImage
477
+ });
478
+ return () => {
479
+ const busy = phase.value === "starting" || phase.value === "processing";
480
+ const needsRetry = phase.value === "error" || phase.value === "paused";
481
+ let torchHint = "";
482
+ if (!hasTorch.value) {
483
+ if (props.nativeScan)
484
+ torchHint = "\u8865\u5149\u8BF7\u5728\u539F\u751F\u626B\u7801\u9875\u9762\u64CD\u4F5C";
485
+ else if (phase.value === "starting")
486
+ torchHint = "\u76F8\u673A\u5C31\u7EEA\u540E\u53EF\u5F00\u542F\u624B\u7535\u7B52";
487
+ else if (phase.value === "scanning")
488
+ torchHint = "\u5F53\u524D\u6444\u50CF\u5934\u6216\u6D4F\u89C8\u5668\u65E0\u6CD5\u4F7F\u7528\u624B\u7535\u7B52";
489
+ else
490
+ torchHint = "\u6444\u50CF\u5934\u672A\u5C31\u7EEA\uFF0C\u624B\u7535\u7B52\u6682\u4E0D\u53EF\u7528";
491
+ }
492
+ return _createVNode(Popup, {
493
+ "show": props.show,
494
+ "class": bem(),
495
+ "teleport": props.teleport,
496
+ "zIndex": props.zIndex,
497
+ "position": "bottom",
498
+ "overlay": false,
499
+ "closeOnPopstate": props.closeOnPopstate,
500
+ "onUpdate:show": (show) => {
501
+ if (!show)
502
+ close(true);
503
+ },
504
+ "onClose": () => emit("close"),
505
+ "onClosed": () => emit("closed")
506
+ }, {
507
+ default: () => [_createVNode("video", {
508
+ "ref": video,
509
+ "class": bem("video"),
510
+ "muted": true,
511
+ "playsinline": true,
512
+ "autoplay": true
513
+ }, null), _createVNode("div", {
514
+ "class": bem("shade")
515
+ }, null), _createVNode("header", {
516
+ "class": bem("header")
517
+ }, [_createVNode("button", {
518
+ "type": "button",
519
+ "class": bem("close"),
520
+ "aria-label": "\u5173\u95ED\u626B\u7801",
521
+ "onClick": () => close(true)
522
+ }, [_createVNode(Icon, {
523
+ "name": "cross",
524
+ "size": "24"
525
+ }, null)]), _createVNode("span", {
526
+ "class": bem("title")
527
+ }, [props.title])]), _createVNode("div", {
528
+ "class": bem("viewfinder")
529
+ }, [_createVNode("div", {
530
+ "ref": frame,
531
+ "class": bem("frame", {
532
+ scanning: phase.value === "scanning"
533
+ }),
534
+ "aria-hidden": "true"
535
+ }, [_createVNode("i", null, null), _createVNode("i", null, null), _createVNode("i", null, null), _createVNode("i", null, null)]), _createVNode("p", {
536
+ "class": bem("tip")
537
+ }, [props.tip])]), _createVNode("div", {
538
+ "class": bem("status"),
539
+ "role": "status",
540
+ "aria-live": "polite"
541
+ }, [busy && _createVNode(Loading, {
542
+ "color": "white",
543
+ "vertical": true
544
+ }, {
545
+ default: () => [phase.value === "starting" ? props.nativeScan ? "\u6B63\u5728\u6253\u5F00\u626B\u7801..." : "\u6B63\u5728\u542F\u52A8\u6444\u50CF\u5934..." : props.processingText]
546
+ }), needsRetry && _createVNode(_Fragment, null, [_createVNode("p", {
547
+ "class": bem("message")
548
+ }, [message.value || "\u626B\u63CF\u5DF2\u6682\u505C"]), _createVNode(Button, {
549
+ "type": "primary",
550
+ "size": "small",
551
+ "onClick": start
552
+ }, {
553
+ default: () => [phase.value === "paused" ? "\u7EE7\u7EED\u626B\u63CF" : "\u91CD\u65B0\u5C1D\u8BD5"]
554
+ })])]), _createVNode("div", {
555
+ "class": bem("actions")
556
+ }, [props.showTorch && _createVNode("button", {
557
+ "type": "button",
558
+ "class": bem("action", {
559
+ active: torchOn.value
560
+ }),
561
+ "disabled": !hasTorch.value || busy || torchChanging.value,
562
+ "aria-pressed": torchOn.value,
563
+ "aria-busy": torchChanging.value || void 0,
564
+ "aria-describedby": torchHint ? torchHintId : void 0,
565
+ "title": torchHint || void 0,
566
+ "onClick": toggleTorch
567
+ }, [_createVNode(Icon, {
568
+ "name": torchOn.value ? "flashlight" : "flashlight-off",
569
+ "size": "26"
570
+ }, null), _createVNode("span", null, [torchOn.value ? "\u5173\u95ED\u624B\u7535\u7B52" : "\u6253\u5F00\u624B\u7535\u7B52"])]), props.showAlbum && _createVNode("button", {
571
+ "type": "button",
572
+ "class": bem("action"),
573
+ "disabled": phase.value === "processing",
574
+ "onClick": () => {
575
+ var _a;
576
+ stop();
577
+ resumeWhenVisible = false;
578
+ (_a = fileInput.value) == null ? void 0 : _a.click();
579
+ }
580
+ }, [_createVNode(Icon, {
581
+ "name": "photo-o",
582
+ "size": "26"
583
+ }, null), _createVNode("span", null, [_createTextVNode("\u4ECE\u76F8\u518C\u8BC6\u522B")])]), props.showSwitchCamera && cameraCount.value > 1 && !props.nativeScan && _createVNode("button", {
584
+ "type": "button",
585
+ "class": bem("action"),
586
+ "disabled": busy,
587
+ "onClick": switchCamera
588
+ }, [_createVNode(Icon, {
589
+ "name": "exchange",
590
+ "size": "26"
591
+ }, null), _createVNode("span", null, [_createTextVNode("\u5207\u6362\u6444\u50CF\u5934")])]), props.showTorch && torchHint && _createVNode("p", {
592
+ "id": torchHintId,
593
+ "class": bem("torch-hint"),
594
+ "role": "status"
595
+ }, [torchHint])]), _createVNode("input", {
596
+ "ref": fileInput,
597
+ "class": bem("file-input"),
598
+ "type": "file",
599
+ "accept": "image/*",
600
+ "onChange": (event) => {
601
+ var _a;
602
+ const input = event.target;
603
+ const file = (_a = input.files) == null ? void 0 : _a[0];
604
+ input.value = "";
605
+ if (file)
606
+ scanImage(file);
607
+ }
608
+ }, null)]
609
+ });
610
+ };
611
+ }
612
+ });
613
+ export {
614
+ stdin_default as default
615
+ };
@@ -0,0 +1,10 @@
1
+ import type { QrScannerFormat } from './types';
2
+ export declare function prepareDecoder(wasmUrl?: string): Promise<void>;
3
+ export declare function decode(image: ImageData, formats: QrScannerFormat[], wasmUrl?: string): Promise<import("zxing-wasm/reader").ReadResult | undefined>;
4
+ export declare function loadImage(file: File): Promise<HTMLImageElement>;
5
+ export declare function captureImage(source: HTMLVideoElement | HTMLImageElement, canvas: HTMLCanvasElement, maxSize?: number, region?: {
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ }): ImageData | undefined;