persagy-vant 0.0.51 → 0.0.53

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