dsh-deeppilot 0.2.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 (53) hide show
  1. package/COMPATIBILITY.md +36 -0
  2. package/LICENSE +21 -0
  3. package/PRIVACY.md +64 -0
  4. package/README.md +97 -0
  5. package/README.zh-CN.md +91 -0
  6. package/SECURITY.md +44 -0
  7. package/THIRD_PARTY_NOTICES.md +20 -0
  8. package/bin/SHA256SUMS +1 -0
  9. package/bin/darwin-arm64/dsh-deeppilot-tunnel +0 -0
  10. package/cordis.patch.yml +20 -0
  11. package/lib/client.js +3398 -0
  12. package/lib/client.js.map +1 -0
  13. package/lib/index.d.ts +586 -0
  14. package/lib/index.js +3654 -0
  15. package/lib/index.js.map +1 -0
  16. package/package.json +102 -0
  17. package/third_party/licenses/filippo.io/edwards25519/LICENSE +27 -0
  18. package/third_party/licenses/github.com/Mars-Sea/dsh-deeppilot/helper/LICENSE +21 -0
  19. package/third_party/licenses/github.com/coder/websocket/LICENSE.txt +13 -0
  20. package/third_party/licenses/github.com/creachadair/msync/trigger/LICENSE +26 -0
  21. package/third_party/licenses/github.com/fxamacker/cbor/v2/LICENSE +21 -0
  22. package/third_party/licenses/github.com/gaissmai/bart/LICENSE +21 -0
  23. package/third_party/licenses/github.com/go-json-experiment/json/LICENSE +27 -0
  24. package/third_party/licenses/github.com/golang/groupcache/lru/LICENSE +191 -0
  25. package/third_party/licenses/github.com/google/btree/LICENSE +202 -0
  26. package/third_party/licenses/github.com/hdevalence/ed25519consensus/LICENSE +28 -0
  27. package/third_party/licenses/github.com/huin/goupnp/LICENSE +23 -0
  28. package/third_party/licenses/github.com/klauspost/compress/LICENSE +304 -0
  29. package/third_party/licenses/github.com/klauspost/compress/internal/snapref/LICENSE +27 -0
  30. package/third_party/licenses/github.com/klauspost/compress/zstd/internal/xxhash/LICENSE.txt +22 -0
  31. package/third_party/licenses/github.com/mitchellh/go-ps/LICENSE.md +21 -0
  32. package/third_party/licenses/github.com/pires/go-proxyproto/LICENSE +201 -0
  33. package/third_party/licenses/github.com/tailscale/certstore/LICENSE.md +21 -0
  34. package/third_party/licenses/github.com/tailscale/hujson/LICENSE +27 -0
  35. package/third_party/licenses/github.com/tailscale/peercred/LICENSE +29 -0
  36. package/third_party/licenses/github.com/tailscale/web-client-prebuilt/LICENSE +28 -0
  37. package/third_party/licenses/github.com/tailscale/wireguard-go/LICENSE +17 -0
  38. package/third_party/licenses/github.com/x448/float16/LICENSE +22 -0
  39. package/third_party/licenses/go4.org/mem/LICENSE +202 -0
  40. package/third_party/licenses/go4.org/netipx/LICENSE +27 -0
  41. package/third_party/licenses/golang.org/x/crypto/LICENSE +27 -0
  42. package/third_party/licenses/golang.org/x/exp/LICENSE +27 -0
  43. package/third_party/licenses/golang.org/x/net/LICENSE +27 -0
  44. package/third_party/licenses/golang.org/x/oauth2/LICENSE +27 -0
  45. package/third_party/licenses/golang.org/x/sync/errgroup/LICENSE +27 -0
  46. package/third_party/licenses/golang.org/x/sys/LICENSE +27 -0
  47. package/third_party/licenses/golang.org/x/term/LICENSE +27 -0
  48. package/third_party/licenses/golang.org/x/text/LICENSE +27 -0
  49. package/third_party/licenses/golang.org/x/time/rate/LICENSE +27 -0
  50. package/third_party/licenses/gvisor.dev/gvisor/pkg/LICENSE +254 -0
  51. package/third_party/licenses/npm/dijkstrajs/LICENSE +17 -0
  52. package/third_party/licenses/npm/qrcode/LICENSE +21 -0
  53. package/third_party/licenses/tailscale.com/LICENSE +28 -0
package/lib/client.js ADDED
@@ -0,0 +1,3398 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-deeppilot",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ //#region \0rolldown/runtime.js
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
17
+ key = keys[i];
18
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: ((k) => from[k]).bind(null, key),
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ //#endregion
30
+ let react = require("react");
31
+ let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
32
+ //#region node_modules/qrcode/lib/can-promise.js
33
+ var require_can_promise = /* @__PURE__ */ __commonJSMin(((exports, module) => {
34
+ module.exports = function() {
35
+ return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
36
+ };
37
+ }));
38
+ //#endregion
39
+ //#region node_modules/qrcode/lib/core/utils.js
40
+ var require_utils$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
41
+ let toSJISFunction;
42
+ const CODEWORDS_COUNT = [
43
+ 0,
44
+ 26,
45
+ 44,
46
+ 70,
47
+ 100,
48
+ 134,
49
+ 172,
50
+ 196,
51
+ 242,
52
+ 292,
53
+ 346,
54
+ 404,
55
+ 466,
56
+ 532,
57
+ 581,
58
+ 655,
59
+ 733,
60
+ 815,
61
+ 901,
62
+ 991,
63
+ 1085,
64
+ 1156,
65
+ 1258,
66
+ 1364,
67
+ 1474,
68
+ 1588,
69
+ 1706,
70
+ 1828,
71
+ 1921,
72
+ 2051,
73
+ 2185,
74
+ 2323,
75
+ 2465,
76
+ 2611,
77
+ 2761,
78
+ 2876,
79
+ 3034,
80
+ 3196,
81
+ 3362,
82
+ 3532,
83
+ 3706
84
+ ];
85
+ /**
86
+ * Returns the QR Code size for the specified version
87
+ *
88
+ * @param {Number} version QR Code version
89
+ * @return {Number} size of QR code
90
+ */
91
+ exports.getSymbolSize = function getSymbolSize(version) {
92
+ if (!version) throw new Error("\"version\" cannot be null or undefined");
93
+ if (version < 1 || version > 40) throw new Error("\"version\" should be in range from 1 to 40");
94
+ return version * 4 + 17;
95
+ };
96
+ /**
97
+ * Returns the total number of codewords used to store data and EC information.
98
+ *
99
+ * @param {Number} version QR Code version
100
+ * @return {Number} Data length in bits
101
+ */
102
+ exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
103
+ return CODEWORDS_COUNT[version];
104
+ };
105
+ /**
106
+ * Encode data with Bose-Chaudhuri-Hocquenghem
107
+ *
108
+ * @param {Number} data Value to encode
109
+ * @return {Number} Encoded value
110
+ */
111
+ exports.getBCHDigit = function(data) {
112
+ let digit = 0;
113
+ while (data !== 0) {
114
+ digit++;
115
+ data >>>= 1;
116
+ }
117
+ return digit;
118
+ };
119
+ exports.setToSJISFunction = function setToSJISFunction(f) {
120
+ if (typeof f !== "function") throw new Error("\"toSJISFunc\" is not a valid function.");
121
+ toSJISFunction = f;
122
+ };
123
+ exports.isKanjiModeEnabled = function() {
124
+ return typeof toSJISFunction !== "undefined";
125
+ };
126
+ exports.toSJIS = function toSJIS(kanji) {
127
+ return toSJISFunction(kanji);
128
+ };
129
+ }));
130
+ //#endregion
131
+ //#region node_modules/qrcode/lib/core/error-correction-level.js
132
+ var require_error_correction_level = /* @__PURE__ */ __commonJSMin(((exports) => {
133
+ exports.L = { bit: 1 };
134
+ exports.M = { bit: 0 };
135
+ exports.Q = { bit: 3 };
136
+ exports.H = { bit: 2 };
137
+ function fromString(string) {
138
+ if (typeof string !== "string") throw new Error("Param is not a string");
139
+ switch (string.toLowerCase()) {
140
+ case "l":
141
+ case "low": return exports.L;
142
+ case "m":
143
+ case "medium": return exports.M;
144
+ case "q":
145
+ case "quartile": return exports.Q;
146
+ case "h":
147
+ case "high": return exports.H;
148
+ default: throw new Error("Unknown EC Level: " + string);
149
+ }
150
+ }
151
+ exports.isValid = function isValid(level) {
152
+ return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
153
+ };
154
+ exports.from = function from(value, defaultValue) {
155
+ if (exports.isValid(value)) return value;
156
+ try {
157
+ return fromString(value);
158
+ } catch (e) {
159
+ return defaultValue;
160
+ }
161
+ };
162
+ }));
163
+ //#endregion
164
+ //#region node_modules/qrcode/lib/core/bit-buffer.js
165
+ var require_bit_buffer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
166
+ function BitBuffer() {
167
+ this.buffer = [];
168
+ this.length = 0;
169
+ }
170
+ BitBuffer.prototype = {
171
+ get: function(index) {
172
+ const bufIndex = Math.floor(index / 8);
173
+ return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
174
+ },
175
+ put: function(num, length) {
176
+ for (let i = 0; i < length; i++) this.putBit((num >>> length - i - 1 & 1) === 1);
177
+ },
178
+ getLengthInBits: function() {
179
+ return this.length;
180
+ },
181
+ putBit: function(bit) {
182
+ const bufIndex = Math.floor(this.length / 8);
183
+ if (this.buffer.length <= bufIndex) this.buffer.push(0);
184
+ if (bit) this.buffer[bufIndex] |= 128 >>> this.length % 8;
185
+ this.length++;
186
+ }
187
+ };
188
+ module.exports = BitBuffer;
189
+ }));
190
+ //#endregion
191
+ //#region node_modules/qrcode/lib/core/bit-matrix.js
192
+ var require_bit_matrix = /* @__PURE__ */ __commonJSMin(((exports, module) => {
193
+ /**
194
+ * Helper class to handle QR Code symbol modules
195
+ *
196
+ * @param {Number} size Symbol size
197
+ */
198
+ function BitMatrix(size) {
199
+ if (!size || size < 1) throw new Error("BitMatrix size must be defined and greater than 0");
200
+ this.size = size;
201
+ this.data = new Uint8Array(size * size);
202
+ this.reservedBit = new Uint8Array(size * size);
203
+ }
204
+ /**
205
+ * Set bit value at specified location
206
+ * If reserved flag is set, this bit will be ignored during masking process
207
+ *
208
+ * @param {Number} row
209
+ * @param {Number} col
210
+ * @param {Boolean} value
211
+ * @param {Boolean} reserved
212
+ */
213
+ BitMatrix.prototype.set = function(row, col, value, reserved) {
214
+ const index = row * this.size + col;
215
+ this.data[index] = value;
216
+ if (reserved) this.reservedBit[index] = true;
217
+ };
218
+ /**
219
+ * Returns bit value at specified location
220
+ *
221
+ * @param {Number} row
222
+ * @param {Number} col
223
+ * @return {Boolean}
224
+ */
225
+ BitMatrix.prototype.get = function(row, col) {
226
+ return this.data[row * this.size + col];
227
+ };
228
+ /**
229
+ * Applies xor operator at specified location
230
+ * (used during masking process)
231
+ *
232
+ * @param {Number} row
233
+ * @param {Number} col
234
+ * @param {Boolean} value
235
+ */
236
+ BitMatrix.prototype.xor = function(row, col, value) {
237
+ this.data[row * this.size + col] ^= value;
238
+ };
239
+ /**
240
+ * Check if bit at specified location is reserved
241
+ *
242
+ * @param {Number} row
243
+ * @param {Number} col
244
+ * @return {Boolean}
245
+ */
246
+ BitMatrix.prototype.isReserved = function(row, col) {
247
+ return this.reservedBit[row * this.size + col];
248
+ };
249
+ module.exports = BitMatrix;
250
+ }));
251
+ //#endregion
252
+ //#region node_modules/qrcode/lib/core/alignment-pattern.js
253
+ var require_alignment_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
254
+ /**
255
+ * Alignment pattern are fixed reference pattern in defined positions
256
+ * in a matrix symbology, which enables the decode software to re-synchronise
257
+ * the coordinate mapping of the image modules in the event of moderate amounts
258
+ * of distortion of the image.
259
+ *
260
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
261
+ * and their number depends on the symbol version.
262
+ */
263
+ const getSymbolSize = require_utils$1().getSymbolSize;
264
+ /**
265
+ * Calculate the row/column coordinates of the center module of each alignment pattern
266
+ * for the specified QR Code version.
267
+ *
268
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
269
+ * running from the top left corner of the symbol to the bottom right corner.
270
+ *
271
+ * Since positions are simmetrical only half of the coordinates are returned.
272
+ * Each item of the array will represent in turn the x and y coordinate.
273
+ * @see {@link getPositions}
274
+ *
275
+ * @param {Number} version QR Code version
276
+ * @return {Array} Array of coordinate
277
+ */
278
+ exports.getRowColCoords = function getRowColCoords(version) {
279
+ if (version === 1) return [];
280
+ const posCount = Math.floor(version / 7) + 2;
281
+ const size = getSymbolSize(version);
282
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
283
+ const positions = [size - 7];
284
+ for (let i = 1; i < posCount - 1; i++) positions[i] = positions[i - 1] - intervals;
285
+ positions.push(6);
286
+ return positions.reverse();
287
+ };
288
+ /**
289
+ * Returns an array containing the positions of each alignment pattern.
290
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
291
+ *
292
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
293
+ * and filtering out the items that overlaps with finder pattern
294
+ *
295
+ * @example
296
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
297
+ * The alignment patterns, therefore, are to be centered on (row, column)
298
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
299
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
300
+ * and are not therefore used for alignment patterns.
301
+ *
302
+ * let pos = getPositions(7)
303
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
304
+ *
305
+ * @param {Number} version QR Code version
306
+ * @return {Array} Array of coordinates
307
+ */
308
+ exports.getPositions = function getPositions(version) {
309
+ const coords = [];
310
+ const pos = exports.getRowColCoords(version);
311
+ const posLength = pos.length;
312
+ for (let i = 0; i < posLength; i++) for (let j = 0; j < posLength; j++) {
313
+ if (i === 0 && j === 0 || i === 0 && j === posLength - 1 || i === posLength - 1 && j === 0) continue;
314
+ coords.push([pos[i], pos[j]]);
315
+ }
316
+ return coords;
317
+ };
318
+ }));
319
+ //#endregion
320
+ //#region node_modules/qrcode/lib/core/finder-pattern.js
321
+ var require_finder_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
322
+ const getSymbolSize = require_utils$1().getSymbolSize;
323
+ const FINDER_PATTERN_SIZE = 7;
324
+ /**
325
+ * Returns an array containing the positions of each finder pattern.
326
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
327
+ *
328
+ * @param {Number} version QR Code version
329
+ * @return {Array} Array of coordinates
330
+ */
331
+ exports.getPositions = function getPositions(version) {
332
+ const size = getSymbolSize(version);
333
+ return [
334
+ [0, 0],
335
+ [size - FINDER_PATTERN_SIZE, 0],
336
+ [0, size - FINDER_PATTERN_SIZE]
337
+ ];
338
+ };
339
+ }));
340
+ //#endregion
341
+ //#region node_modules/qrcode/lib/core/mask-pattern.js
342
+ var require_mask_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
343
+ /**
344
+ * Data mask pattern reference
345
+ * @type {Object}
346
+ */
347
+ exports.Patterns = {
348
+ PATTERN000: 0,
349
+ PATTERN001: 1,
350
+ PATTERN010: 2,
351
+ PATTERN011: 3,
352
+ PATTERN100: 4,
353
+ PATTERN101: 5,
354
+ PATTERN110: 6,
355
+ PATTERN111: 7
356
+ };
357
+ /**
358
+ * Weighted penalty scores for the undesirable features
359
+ * @type {Object}
360
+ */
361
+ const PenaltyScores = {
362
+ N1: 3,
363
+ N2: 3,
364
+ N3: 40,
365
+ N4: 10
366
+ };
367
+ /**
368
+ * Check if mask pattern value is valid
369
+ *
370
+ * @param {Number} mask Mask pattern
371
+ * @return {Boolean} true if valid, false otherwise
372
+ */
373
+ exports.isValid = function isValid(mask) {
374
+ return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
375
+ };
376
+ /**
377
+ * Returns mask pattern from a value.
378
+ * If value is not valid, returns undefined
379
+ *
380
+ * @param {Number|String} value Mask pattern value
381
+ * @return {Number} Valid mask pattern or undefined
382
+ */
383
+ exports.from = function from(value) {
384
+ return exports.isValid(value) ? parseInt(value, 10) : void 0;
385
+ };
386
+ /**
387
+ * Find adjacent modules in row/column with the same color
388
+ * and assign a penalty value.
389
+ *
390
+ * Points: N1 + i
391
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
392
+ */
393
+ exports.getPenaltyN1 = function getPenaltyN1(data) {
394
+ const size = data.size;
395
+ let points = 0;
396
+ let sameCountCol = 0;
397
+ let sameCountRow = 0;
398
+ let lastCol = null;
399
+ let lastRow = null;
400
+ for (let row = 0; row < size; row++) {
401
+ sameCountCol = sameCountRow = 0;
402
+ lastCol = lastRow = null;
403
+ for (let col = 0; col < size; col++) {
404
+ let module$1 = data.get(row, col);
405
+ if (module$1 === lastCol) sameCountCol++;
406
+ else {
407
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
408
+ lastCol = module$1;
409
+ sameCountCol = 1;
410
+ }
411
+ module$1 = data.get(col, row);
412
+ if (module$1 === lastRow) sameCountRow++;
413
+ else {
414
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
415
+ lastRow = module$1;
416
+ sameCountRow = 1;
417
+ }
418
+ }
419
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
420
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
421
+ }
422
+ return points;
423
+ };
424
+ /**
425
+ * Find 2x2 blocks with the same color and assign a penalty value
426
+ *
427
+ * Points: N2 * (m - 1) * (n - 1)
428
+ */
429
+ exports.getPenaltyN2 = function getPenaltyN2(data) {
430
+ const size = data.size;
431
+ let points = 0;
432
+ for (let row = 0; row < size - 1; row++) for (let col = 0; col < size - 1; col++) {
433
+ const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
434
+ if (last === 4 || last === 0) points++;
435
+ }
436
+ return points * PenaltyScores.N2;
437
+ };
438
+ /**
439
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
440
+ * preceded or followed by light area 4 modules wide
441
+ *
442
+ * Points: N3 * number of pattern found
443
+ */
444
+ exports.getPenaltyN3 = function getPenaltyN3(data) {
445
+ const size = data.size;
446
+ let points = 0;
447
+ let bitsCol = 0;
448
+ let bitsRow = 0;
449
+ for (let row = 0; row < size; row++) {
450
+ bitsCol = bitsRow = 0;
451
+ for (let col = 0; col < size; col++) {
452
+ bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
453
+ if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
454
+ bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
455
+ if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
456
+ }
457
+ }
458
+ return points * PenaltyScores.N3;
459
+ };
460
+ /**
461
+ * Calculate proportion of dark modules in entire symbol
462
+ *
463
+ * Points: N4 * k
464
+ *
465
+ * k is the rating of the deviation of the proportion of dark modules
466
+ * in the symbol from 50% in steps of 5%
467
+ */
468
+ exports.getPenaltyN4 = function getPenaltyN4(data) {
469
+ let darkCount = 0;
470
+ const modulesCount = data.data.length;
471
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
472
+ return Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10) * PenaltyScores.N4;
473
+ };
474
+ /**
475
+ * Return mask value at given position
476
+ *
477
+ * @param {Number} maskPattern Pattern reference value
478
+ * @param {Number} i Row
479
+ * @param {Number} j Column
480
+ * @return {Boolean} Mask value
481
+ */
482
+ function getMaskAt(maskPattern, i, j) {
483
+ switch (maskPattern) {
484
+ case exports.Patterns.PATTERN000: return (i + j) % 2 === 0;
485
+ case exports.Patterns.PATTERN001: return i % 2 === 0;
486
+ case exports.Patterns.PATTERN010: return j % 3 === 0;
487
+ case exports.Patterns.PATTERN011: return (i + j) % 3 === 0;
488
+ case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
489
+ case exports.Patterns.PATTERN101: return i * j % 2 + i * j % 3 === 0;
490
+ case exports.Patterns.PATTERN110: return (i * j % 2 + i * j % 3) % 2 === 0;
491
+ case exports.Patterns.PATTERN111: return (i * j % 3 + (i + j) % 2) % 2 === 0;
492
+ default: throw new Error("bad maskPattern:" + maskPattern);
493
+ }
494
+ }
495
+ /**
496
+ * Apply a mask pattern to a BitMatrix
497
+ *
498
+ * @param {Number} pattern Pattern reference number
499
+ * @param {BitMatrix} data BitMatrix data
500
+ */
501
+ exports.applyMask = function applyMask(pattern, data) {
502
+ const size = data.size;
503
+ for (let col = 0; col < size; col++) for (let row = 0; row < size; row++) {
504
+ if (data.isReserved(row, col)) continue;
505
+ data.xor(row, col, getMaskAt(pattern, row, col));
506
+ }
507
+ };
508
+ /**
509
+ * Returns the best mask pattern for data
510
+ *
511
+ * @param {BitMatrix} data
512
+ * @return {Number} Mask pattern reference number
513
+ */
514
+ exports.getBestMask = function getBestMask(data, setupFormatFunc) {
515
+ const numPatterns = Object.keys(exports.Patterns).length;
516
+ let bestPattern = 0;
517
+ let lowerPenalty = Infinity;
518
+ for (let p = 0; p < numPatterns; p++) {
519
+ setupFormatFunc(p);
520
+ exports.applyMask(p, data);
521
+ const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
522
+ exports.applyMask(p, data);
523
+ if (penalty < lowerPenalty) {
524
+ lowerPenalty = penalty;
525
+ bestPattern = p;
526
+ }
527
+ }
528
+ return bestPattern;
529
+ };
530
+ }));
531
+ //#endregion
532
+ //#region node_modules/qrcode/lib/core/error-correction-code.js
533
+ var require_error_correction_code = /* @__PURE__ */ __commonJSMin(((exports) => {
534
+ const ECLevel = require_error_correction_level();
535
+ const EC_BLOCKS_TABLE = [
536
+ 1,
537
+ 1,
538
+ 1,
539
+ 1,
540
+ 1,
541
+ 1,
542
+ 1,
543
+ 1,
544
+ 1,
545
+ 1,
546
+ 2,
547
+ 2,
548
+ 1,
549
+ 2,
550
+ 2,
551
+ 4,
552
+ 1,
553
+ 2,
554
+ 4,
555
+ 4,
556
+ 2,
557
+ 4,
558
+ 4,
559
+ 4,
560
+ 2,
561
+ 4,
562
+ 6,
563
+ 5,
564
+ 2,
565
+ 4,
566
+ 6,
567
+ 6,
568
+ 2,
569
+ 5,
570
+ 8,
571
+ 8,
572
+ 4,
573
+ 5,
574
+ 8,
575
+ 8,
576
+ 4,
577
+ 5,
578
+ 8,
579
+ 11,
580
+ 4,
581
+ 8,
582
+ 10,
583
+ 11,
584
+ 4,
585
+ 9,
586
+ 12,
587
+ 16,
588
+ 4,
589
+ 9,
590
+ 16,
591
+ 16,
592
+ 6,
593
+ 10,
594
+ 12,
595
+ 18,
596
+ 6,
597
+ 10,
598
+ 17,
599
+ 16,
600
+ 6,
601
+ 11,
602
+ 16,
603
+ 19,
604
+ 6,
605
+ 13,
606
+ 18,
607
+ 21,
608
+ 7,
609
+ 14,
610
+ 21,
611
+ 25,
612
+ 8,
613
+ 16,
614
+ 20,
615
+ 25,
616
+ 8,
617
+ 17,
618
+ 23,
619
+ 25,
620
+ 9,
621
+ 17,
622
+ 23,
623
+ 34,
624
+ 9,
625
+ 18,
626
+ 25,
627
+ 30,
628
+ 10,
629
+ 20,
630
+ 27,
631
+ 32,
632
+ 12,
633
+ 21,
634
+ 29,
635
+ 35,
636
+ 12,
637
+ 23,
638
+ 34,
639
+ 37,
640
+ 12,
641
+ 25,
642
+ 34,
643
+ 40,
644
+ 13,
645
+ 26,
646
+ 35,
647
+ 42,
648
+ 14,
649
+ 28,
650
+ 38,
651
+ 45,
652
+ 15,
653
+ 29,
654
+ 40,
655
+ 48,
656
+ 16,
657
+ 31,
658
+ 43,
659
+ 51,
660
+ 17,
661
+ 33,
662
+ 45,
663
+ 54,
664
+ 18,
665
+ 35,
666
+ 48,
667
+ 57,
668
+ 19,
669
+ 37,
670
+ 51,
671
+ 60,
672
+ 19,
673
+ 38,
674
+ 53,
675
+ 63,
676
+ 20,
677
+ 40,
678
+ 56,
679
+ 66,
680
+ 21,
681
+ 43,
682
+ 59,
683
+ 70,
684
+ 22,
685
+ 45,
686
+ 62,
687
+ 74,
688
+ 24,
689
+ 47,
690
+ 65,
691
+ 77,
692
+ 25,
693
+ 49,
694
+ 68,
695
+ 81
696
+ ];
697
+ const EC_CODEWORDS_TABLE = [
698
+ 7,
699
+ 10,
700
+ 13,
701
+ 17,
702
+ 10,
703
+ 16,
704
+ 22,
705
+ 28,
706
+ 15,
707
+ 26,
708
+ 36,
709
+ 44,
710
+ 20,
711
+ 36,
712
+ 52,
713
+ 64,
714
+ 26,
715
+ 48,
716
+ 72,
717
+ 88,
718
+ 36,
719
+ 64,
720
+ 96,
721
+ 112,
722
+ 40,
723
+ 72,
724
+ 108,
725
+ 130,
726
+ 48,
727
+ 88,
728
+ 132,
729
+ 156,
730
+ 60,
731
+ 110,
732
+ 160,
733
+ 192,
734
+ 72,
735
+ 130,
736
+ 192,
737
+ 224,
738
+ 80,
739
+ 150,
740
+ 224,
741
+ 264,
742
+ 96,
743
+ 176,
744
+ 260,
745
+ 308,
746
+ 104,
747
+ 198,
748
+ 288,
749
+ 352,
750
+ 120,
751
+ 216,
752
+ 320,
753
+ 384,
754
+ 132,
755
+ 240,
756
+ 360,
757
+ 432,
758
+ 144,
759
+ 280,
760
+ 408,
761
+ 480,
762
+ 168,
763
+ 308,
764
+ 448,
765
+ 532,
766
+ 180,
767
+ 338,
768
+ 504,
769
+ 588,
770
+ 196,
771
+ 364,
772
+ 546,
773
+ 650,
774
+ 224,
775
+ 416,
776
+ 600,
777
+ 700,
778
+ 224,
779
+ 442,
780
+ 644,
781
+ 750,
782
+ 252,
783
+ 476,
784
+ 690,
785
+ 816,
786
+ 270,
787
+ 504,
788
+ 750,
789
+ 900,
790
+ 300,
791
+ 560,
792
+ 810,
793
+ 960,
794
+ 312,
795
+ 588,
796
+ 870,
797
+ 1050,
798
+ 336,
799
+ 644,
800
+ 952,
801
+ 1110,
802
+ 360,
803
+ 700,
804
+ 1020,
805
+ 1200,
806
+ 390,
807
+ 728,
808
+ 1050,
809
+ 1260,
810
+ 420,
811
+ 784,
812
+ 1140,
813
+ 1350,
814
+ 450,
815
+ 812,
816
+ 1200,
817
+ 1440,
818
+ 480,
819
+ 868,
820
+ 1290,
821
+ 1530,
822
+ 510,
823
+ 924,
824
+ 1350,
825
+ 1620,
826
+ 540,
827
+ 980,
828
+ 1440,
829
+ 1710,
830
+ 570,
831
+ 1036,
832
+ 1530,
833
+ 1800,
834
+ 570,
835
+ 1064,
836
+ 1590,
837
+ 1890,
838
+ 600,
839
+ 1120,
840
+ 1680,
841
+ 1980,
842
+ 630,
843
+ 1204,
844
+ 1770,
845
+ 2100,
846
+ 660,
847
+ 1260,
848
+ 1860,
849
+ 2220,
850
+ 720,
851
+ 1316,
852
+ 1950,
853
+ 2310,
854
+ 750,
855
+ 1372,
856
+ 2040,
857
+ 2430
858
+ ];
859
+ /**
860
+ * Returns the number of error correction block that the QR Code should contain
861
+ * for the specified version and error correction level.
862
+ *
863
+ * @param {Number} version QR Code version
864
+ * @param {Number} errorCorrectionLevel Error correction level
865
+ * @return {Number} Number of error correction blocks
866
+ */
867
+ exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
868
+ switch (errorCorrectionLevel) {
869
+ case ECLevel.L: return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
870
+ case ECLevel.M: return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
871
+ case ECLevel.Q: return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
872
+ case ECLevel.H: return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
873
+ default: return;
874
+ }
875
+ };
876
+ /**
877
+ * Returns the number of error correction codewords to use for the specified
878
+ * version and error correction level.
879
+ *
880
+ * @param {Number} version QR Code version
881
+ * @param {Number} errorCorrectionLevel Error correction level
882
+ * @return {Number} Number of error correction codewords
883
+ */
884
+ exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
885
+ switch (errorCorrectionLevel) {
886
+ case ECLevel.L: return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
887
+ case ECLevel.M: return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
888
+ case ECLevel.Q: return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
889
+ case ECLevel.H: return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
890
+ default: return;
891
+ }
892
+ };
893
+ }));
894
+ //#endregion
895
+ //#region node_modules/qrcode/lib/core/galois-field.js
896
+ var require_galois_field = /* @__PURE__ */ __commonJSMin(((exports) => {
897
+ const EXP_TABLE = /* @__PURE__ */ new Uint8Array(512);
898
+ const LOG_TABLE = /* @__PURE__ */ new Uint8Array(256);
899
+ (function initTables() {
900
+ let x = 1;
901
+ for (let i = 0; i < 255; i++) {
902
+ EXP_TABLE[i] = x;
903
+ LOG_TABLE[x] = i;
904
+ x <<= 1;
905
+ if (x & 256) x ^= 285;
906
+ }
907
+ for (let i = 255; i < 512; i++) EXP_TABLE[i] = EXP_TABLE[i - 255];
908
+ })();
909
+ /**
910
+ * Returns log value of n inside Galois Field
911
+ *
912
+ * @param {Number} n
913
+ * @return {Number}
914
+ */
915
+ exports.log = function log(n) {
916
+ if (n < 1) throw new Error("log(" + n + ")");
917
+ return LOG_TABLE[n];
918
+ };
919
+ /**
920
+ * Returns anti-log value of n inside Galois Field
921
+ *
922
+ * @param {Number} n
923
+ * @return {Number}
924
+ */
925
+ exports.exp = function exp(n) {
926
+ return EXP_TABLE[n];
927
+ };
928
+ /**
929
+ * Multiplies two number inside Galois Field
930
+ *
931
+ * @param {Number} x
932
+ * @param {Number} y
933
+ * @return {Number}
934
+ */
935
+ exports.mul = function mul(x, y) {
936
+ if (x === 0 || y === 0) return 0;
937
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
938
+ };
939
+ }));
940
+ //#endregion
941
+ //#region node_modules/qrcode/lib/core/polynomial.js
942
+ var require_polynomial = /* @__PURE__ */ __commonJSMin(((exports) => {
943
+ const GF = require_galois_field();
944
+ /**
945
+ * Multiplies two polynomials inside Galois Field
946
+ *
947
+ * @param {Uint8Array} p1 Polynomial
948
+ * @param {Uint8Array} p2 Polynomial
949
+ * @return {Uint8Array} Product of p1 and p2
950
+ */
951
+ exports.mul = function mul(p1, p2) {
952
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
953
+ for (let i = 0; i < p1.length; i++) for (let j = 0; j < p2.length; j++) coeff[i + j] ^= GF.mul(p1[i], p2[j]);
954
+ return coeff;
955
+ };
956
+ /**
957
+ * Calculate the remainder of polynomials division
958
+ *
959
+ * @param {Uint8Array} divident Polynomial
960
+ * @param {Uint8Array} divisor Polynomial
961
+ * @return {Uint8Array} Remainder
962
+ */
963
+ exports.mod = function mod(divident, divisor) {
964
+ let result = new Uint8Array(divident);
965
+ while (result.length - divisor.length >= 0) {
966
+ const coeff = result[0];
967
+ for (let i = 0; i < divisor.length; i++) result[i] ^= GF.mul(divisor[i], coeff);
968
+ let offset = 0;
969
+ while (offset < result.length && result[offset] === 0) offset++;
970
+ result = result.slice(offset);
971
+ }
972
+ return result;
973
+ };
974
+ /**
975
+ * Generate an irreducible generator polynomial of specified degree
976
+ * (used by Reed-Solomon encoder)
977
+ *
978
+ * @param {Number} degree Degree of the generator polynomial
979
+ * @return {Uint8Array} Buffer containing polynomial coefficients
980
+ */
981
+ exports.generateECPolynomial = function generateECPolynomial(degree) {
982
+ let poly = new Uint8Array([1]);
983
+ for (let i = 0; i < degree; i++) poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
984
+ return poly;
985
+ };
986
+ }));
987
+ //#endregion
988
+ //#region node_modules/qrcode/lib/core/reed-solomon-encoder.js
989
+ var require_reed_solomon_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
990
+ const Polynomial = require_polynomial();
991
+ function ReedSolomonEncoder(degree) {
992
+ this.genPoly = void 0;
993
+ this.degree = degree;
994
+ if (this.degree) this.initialize(this.degree);
995
+ }
996
+ /**
997
+ * Initialize the encoder.
998
+ * The input param should correspond to the number of error correction codewords.
999
+ *
1000
+ * @param {Number} degree
1001
+ */
1002
+ ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
1003
+ this.degree = degree;
1004
+ this.genPoly = Polynomial.generateECPolynomial(this.degree);
1005
+ };
1006
+ /**
1007
+ * Encodes a chunk of data
1008
+ *
1009
+ * @param {Uint8Array} data Buffer containing input data
1010
+ * @return {Uint8Array} Buffer containing encoded data
1011
+ */
1012
+ ReedSolomonEncoder.prototype.encode = function encode(data) {
1013
+ if (!this.genPoly) throw new Error("Encoder not initialized");
1014
+ const paddedData = new Uint8Array(data.length + this.degree);
1015
+ paddedData.set(data);
1016
+ const remainder = Polynomial.mod(paddedData, this.genPoly);
1017
+ const start = this.degree - remainder.length;
1018
+ if (start > 0) {
1019
+ const buff = new Uint8Array(this.degree);
1020
+ buff.set(remainder, start);
1021
+ return buff;
1022
+ }
1023
+ return remainder;
1024
+ };
1025
+ module.exports = ReedSolomonEncoder;
1026
+ }));
1027
+ //#endregion
1028
+ //#region node_modules/qrcode/lib/core/version-check.js
1029
+ var require_version_check = /* @__PURE__ */ __commonJSMin(((exports) => {
1030
+ /**
1031
+ * Check if QR Code version is valid
1032
+ *
1033
+ * @param {Number} version QR Code version
1034
+ * @return {Boolean} true if valid version, false otherwise
1035
+ */
1036
+ exports.isValid = function isValid(version) {
1037
+ return !isNaN(version) && version >= 1 && version <= 40;
1038
+ };
1039
+ }));
1040
+ //#endregion
1041
+ //#region node_modules/qrcode/lib/core/regex.js
1042
+ var require_regex = /* @__PURE__ */ __commonJSMin(((exports) => {
1043
+ const numeric = "[0-9]+";
1044
+ const alphanumeric = "[A-Z $%*+\\-./:]+";
1045
+ let kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
1046
+ kanji = kanji.replace(/u/g, "\\u");
1047
+ const byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + ")(?:.|[\r\n]))+";
1048
+ exports.KANJI = new RegExp(kanji, "g");
1049
+ exports.BYTE_KANJI = /* @__PURE__ */ new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
1050
+ exports.BYTE = new RegExp(byte, "g");
1051
+ exports.NUMERIC = new RegExp(numeric, "g");
1052
+ exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
1053
+ const TEST_KANJI = new RegExp("^" + kanji + "$");
1054
+ const TEST_NUMERIC = /* @__PURE__ */ new RegExp("^[0-9]+$");
1055
+ const TEST_ALPHANUMERIC = /* @__PURE__ */ new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
1056
+ exports.testKanji = function testKanji(str) {
1057
+ return TEST_KANJI.test(str);
1058
+ };
1059
+ exports.testNumeric = function testNumeric(str) {
1060
+ return TEST_NUMERIC.test(str);
1061
+ };
1062
+ exports.testAlphanumeric = function testAlphanumeric(str) {
1063
+ return TEST_ALPHANUMERIC.test(str);
1064
+ };
1065
+ }));
1066
+ //#endregion
1067
+ //#region node_modules/qrcode/lib/core/mode.js
1068
+ var require_mode = /* @__PURE__ */ __commonJSMin(((exports) => {
1069
+ const VersionCheck = require_version_check();
1070
+ const Regex = require_regex();
1071
+ /**
1072
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
1073
+ * (byte values 30HEX to 39HEX).
1074
+ * Normally, 3 data characters are represented by 10 bits.
1075
+ *
1076
+ * @type {Object}
1077
+ */
1078
+ exports.NUMERIC = {
1079
+ id: "Numeric",
1080
+ bit: 1,
1081
+ ccBits: [
1082
+ 10,
1083
+ 12,
1084
+ 14
1085
+ ]
1086
+ };
1087
+ /**
1088
+ * Alphanumeric mode encodes data from a set of 45 characters,
1089
+ * i.e. 10 numeric digits (0 - 9),
1090
+ * 26 alphabetic characters (A - Z),
1091
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1092
+ * Normally, two input characters are represented by 11 bits.
1093
+ *
1094
+ * @type {Object}
1095
+ */
1096
+ exports.ALPHANUMERIC = {
1097
+ id: "Alphanumeric",
1098
+ bit: 2,
1099
+ ccBits: [
1100
+ 9,
1101
+ 11,
1102
+ 13
1103
+ ]
1104
+ };
1105
+ /**
1106
+ * In byte mode, data is encoded at 8 bits per character.
1107
+ *
1108
+ * @type {Object}
1109
+ */
1110
+ exports.BYTE = {
1111
+ id: "Byte",
1112
+ bit: 4,
1113
+ ccBits: [
1114
+ 8,
1115
+ 16,
1116
+ 16
1117
+ ]
1118
+ };
1119
+ /**
1120
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
1121
+ * the Shift JIS system based on JIS X 0208.
1122
+ * The Shift JIS values are shifted from the JIS X 0208 values.
1123
+ * JIS X 0208 gives details of the shift coded representation.
1124
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
1125
+ *
1126
+ * @type {Object}
1127
+ */
1128
+ exports.KANJI = {
1129
+ id: "Kanji",
1130
+ bit: 8,
1131
+ ccBits: [
1132
+ 8,
1133
+ 10,
1134
+ 12
1135
+ ]
1136
+ };
1137
+ /**
1138
+ * Mixed mode will contain a sequences of data in a combination of any of
1139
+ * the modes described above
1140
+ *
1141
+ * @type {Object}
1142
+ */
1143
+ exports.MIXED = { bit: -1 };
1144
+ /**
1145
+ * Returns the number of bits needed to store the data length
1146
+ * according to QR Code specifications.
1147
+ *
1148
+ * @param {Mode} mode Data mode
1149
+ * @param {Number} version QR Code version
1150
+ * @return {Number} Number of bits
1151
+ */
1152
+ exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
1153
+ if (!mode.ccBits) throw new Error("Invalid mode: " + mode);
1154
+ if (!VersionCheck.isValid(version)) throw new Error("Invalid version: " + version);
1155
+ if (version >= 1 && version < 10) return mode.ccBits[0];
1156
+ else if (version < 27) return mode.ccBits[1];
1157
+ return mode.ccBits[2];
1158
+ };
1159
+ /**
1160
+ * Returns the most efficient mode to store the specified data
1161
+ *
1162
+ * @param {String} dataStr Input data string
1163
+ * @return {Mode} Best mode
1164
+ */
1165
+ exports.getBestModeForData = function getBestModeForData(dataStr) {
1166
+ if (Regex.testNumeric(dataStr)) return exports.NUMERIC;
1167
+ else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;
1168
+ else if (Regex.testKanji(dataStr)) return exports.KANJI;
1169
+ else return exports.BYTE;
1170
+ };
1171
+ /**
1172
+ * Return mode name as string
1173
+ *
1174
+ * @param {Mode} mode Mode object
1175
+ * @returns {String} Mode name
1176
+ */
1177
+ exports.toString = function toString(mode) {
1178
+ if (mode && mode.id) return mode.id;
1179
+ throw new Error("Invalid mode");
1180
+ };
1181
+ /**
1182
+ * Check if input param is a valid mode object
1183
+ *
1184
+ * @param {Mode} mode Mode object
1185
+ * @returns {Boolean} True if valid mode, false otherwise
1186
+ */
1187
+ exports.isValid = function isValid(mode) {
1188
+ return mode && mode.bit && mode.ccBits;
1189
+ };
1190
+ /**
1191
+ * Get mode object from its name
1192
+ *
1193
+ * @param {String} string Mode name
1194
+ * @returns {Mode} Mode object
1195
+ */
1196
+ function fromString(string) {
1197
+ if (typeof string !== "string") throw new Error("Param is not a string");
1198
+ switch (string.toLowerCase()) {
1199
+ case "numeric": return exports.NUMERIC;
1200
+ case "alphanumeric": return exports.ALPHANUMERIC;
1201
+ case "kanji": return exports.KANJI;
1202
+ case "byte": return exports.BYTE;
1203
+ default: throw new Error("Unknown mode: " + string);
1204
+ }
1205
+ }
1206
+ /**
1207
+ * Returns mode from a value.
1208
+ * If value is not a valid mode, returns defaultValue
1209
+ *
1210
+ * @param {Mode|String} value Encoding mode
1211
+ * @param {Mode} defaultValue Fallback value
1212
+ * @return {Mode} Encoding mode
1213
+ */
1214
+ exports.from = function from(value, defaultValue) {
1215
+ if (exports.isValid(value)) return value;
1216
+ try {
1217
+ return fromString(value);
1218
+ } catch (e) {
1219
+ return defaultValue;
1220
+ }
1221
+ };
1222
+ }));
1223
+ //#endregion
1224
+ //#region node_modules/qrcode/lib/core/version.js
1225
+ var require_version = /* @__PURE__ */ __commonJSMin(((exports) => {
1226
+ const Utils = require_utils$1();
1227
+ const ECCode = require_error_correction_code();
1228
+ const ECLevel = require_error_correction_level();
1229
+ const Mode = require_mode();
1230
+ const VersionCheck = require_version_check();
1231
+ const G18 = 7973;
1232
+ const G18_BCH = Utils.getBCHDigit(G18);
1233
+ function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
1234
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) return currentVersion;
1235
+ }
1236
+ function getReservedBitsCount(mode, version) {
1237
+ return Mode.getCharCountIndicator(mode, version) + 4;
1238
+ }
1239
+ function getTotalBitsFromDataArray(segments, version) {
1240
+ let totalBits = 0;
1241
+ segments.forEach(function(data) {
1242
+ const reservedBits = getReservedBitsCount(data.mode, version);
1243
+ totalBits += reservedBits + data.getBitsLength();
1244
+ });
1245
+ return totalBits;
1246
+ }
1247
+ function getBestVersionForMixedData(segments, errorCorrectionLevel) {
1248
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) if (getTotalBitsFromDataArray(segments, currentVersion) <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) return currentVersion;
1249
+ }
1250
+ /**
1251
+ * Returns version number from a value.
1252
+ * If value is not a valid version, returns defaultValue
1253
+ *
1254
+ * @param {Number|String} value QR Code version
1255
+ * @param {Number} defaultValue Fallback value
1256
+ * @return {Number} QR Code version number
1257
+ */
1258
+ exports.from = function from(value, defaultValue) {
1259
+ if (VersionCheck.isValid(value)) return parseInt(value, 10);
1260
+ return defaultValue;
1261
+ };
1262
+ /**
1263
+ * Returns how much data can be stored with the specified QR code version
1264
+ * and error correction level
1265
+ *
1266
+ * @param {Number} version QR Code version (1-40)
1267
+ * @param {Number} errorCorrectionLevel Error correction level
1268
+ * @param {Mode} mode Data mode
1269
+ * @return {Number} Quantity of storable data
1270
+ */
1271
+ exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
1272
+ if (!VersionCheck.isValid(version)) throw new Error("Invalid QR Code version");
1273
+ if (typeof mode === "undefined") mode = Mode.BYTE;
1274
+ const dataTotalCodewordsBits = (Utils.getSymbolTotalCodewords(version) - ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)) * 8;
1275
+ if (mode === Mode.MIXED) return dataTotalCodewordsBits;
1276
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
1277
+ switch (mode) {
1278
+ case Mode.NUMERIC: return Math.floor(usableBits / 10 * 3);
1279
+ case Mode.ALPHANUMERIC: return Math.floor(usableBits / 11 * 2);
1280
+ case Mode.KANJI: return Math.floor(usableBits / 13);
1281
+ case Mode.BYTE:
1282
+ default: return Math.floor(usableBits / 8);
1283
+ }
1284
+ };
1285
+ /**
1286
+ * Returns the minimum version needed to contain the amount of data
1287
+ *
1288
+ * @param {Segment} data Segment of data
1289
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
1290
+ * @param {Mode} mode Data mode
1291
+ * @return {Number} QR Code version
1292
+ */
1293
+ exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
1294
+ let seg;
1295
+ const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
1296
+ if (Array.isArray(data)) {
1297
+ if (data.length > 1) return getBestVersionForMixedData(data, ecl);
1298
+ if (data.length === 0) return 1;
1299
+ seg = data[0];
1300
+ } else seg = data;
1301
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
1302
+ };
1303
+ /**
1304
+ * Returns version information with relative error correction bits
1305
+ *
1306
+ * The version information is included in QR Code symbols of version 7 or larger.
1307
+ * It consists of an 18-bit sequence containing 6 data bits,
1308
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
1309
+ *
1310
+ * @param {Number} version QR Code version
1311
+ * @return {Number} Encoded version info bits
1312
+ */
1313
+ exports.getEncodedBits = function getEncodedBits(version) {
1314
+ if (!VersionCheck.isValid(version) || version < 7) throw new Error("Invalid QR Code version");
1315
+ let d = version << 12;
1316
+ while (Utils.getBCHDigit(d) - G18_BCH >= 0) d ^= G18 << Utils.getBCHDigit(d) - G18_BCH;
1317
+ return version << 12 | d;
1318
+ };
1319
+ }));
1320
+ //#endregion
1321
+ //#region node_modules/qrcode/lib/core/format-info.js
1322
+ var require_format_info = /* @__PURE__ */ __commonJSMin(((exports) => {
1323
+ const Utils = require_utils$1();
1324
+ const G15 = 1335;
1325
+ const G15_MASK = 21522;
1326
+ const G15_BCH = Utils.getBCHDigit(G15);
1327
+ /**
1328
+ * Returns format information with relative error correction bits
1329
+ *
1330
+ * The format information is a 15-bit sequence containing 5 data bits,
1331
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
1332
+ *
1333
+ * @param {Number} errorCorrectionLevel Error correction level
1334
+ * @param {Number} mask Mask pattern
1335
+ * @return {Number} Encoded format information bits
1336
+ */
1337
+ exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
1338
+ const data = errorCorrectionLevel.bit << 3 | mask;
1339
+ let d = data << 10;
1340
+ while (Utils.getBCHDigit(d) - G15_BCH >= 0) d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;
1341
+ return (data << 10 | d) ^ G15_MASK;
1342
+ };
1343
+ }));
1344
+ //#endregion
1345
+ //#region node_modules/qrcode/lib/core/numeric-data.js
1346
+ var require_numeric_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1347
+ const Mode = require_mode();
1348
+ function NumericData(data) {
1349
+ this.mode = Mode.NUMERIC;
1350
+ this.data = data.toString();
1351
+ }
1352
+ NumericData.getBitsLength = function getBitsLength(length) {
1353
+ return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
1354
+ };
1355
+ NumericData.prototype.getLength = function getLength() {
1356
+ return this.data.length;
1357
+ };
1358
+ NumericData.prototype.getBitsLength = function getBitsLength() {
1359
+ return NumericData.getBitsLength(this.data.length);
1360
+ };
1361
+ NumericData.prototype.write = function write(bitBuffer) {
1362
+ let i, group, value;
1363
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
1364
+ group = this.data.substr(i, 3);
1365
+ value = parseInt(group, 10);
1366
+ bitBuffer.put(value, 10);
1367
+ }
1368
+ const remainingNum = this.data.length - i;
1369
+ if (remainingNum > 0) {
1370
+ group = this.data.substr(i);
1371
+ value = parseInt(group, 10);
1372
+ bitBuffer.put(value, remainingNum * 3 + 1);
1373
+ }
1374
+ };
1375
+ module.exports = NumericData;
1376
+ }));
1377
+ //#endregion
1378
+ //#region node_modules/qrcode/lib/core/alphanumeric-data.js
1379
+ var require_alphanumeric_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1380
+ const Mode = require_mode();
1381
+ /**
1382
+ * Array of characters available in alphanumeric mode
1383
+ *
1384
+ * As per QR Code specification, to each character
1385
+ * is assigned a value from 0 to 44 which in this case coincides
1386
+ * with the array index
1387
+ *
1388
+ * @type {Array}
1389
+ */
1390
+ const ALPHA_NUM_CHARS = [
1391
+ "0",
1392
+ "1",
1393
+ "2",
1394
+ "3",
1395
+ "4",
1396
+ "5",
1397
+ "6",
1398
+ "7",
1399
+ "8",
1400
+ "9",
1401
+ "A",
1402
+ "B",
1403
+ "C",
1404
+ "D",
1405
+ "E",
1406
+ "F",
1407
+ "G",
1408
+ "H",
1409
+ "I",
1410
+ "J",
1411
+ "K",
1412
+ "L",
1413
+ "M",
1414
+ "N",
1415
+ "O",
1416
+ "P",
1417
+ "Q",
1418
+ "R",
1419
+ "S",
1420
+ "T",
1421
+ "U",
1422
+ "V",
1423
+ "W",
1424
+ "X",
1425
+ "Y",
1426
+ "Z",
1427
+ " ",
1428
+ "$",
1429
+ "%",
1430
+ "*",
1431
+ "+",
1432
+ "-",
1433
+ ".",
1434
+ "/",
1435
+ ":"
1436
+ ];
1437
+ function AlphanumericData(data) {
1438
+ this.mode = Mode.ALPHANUMERIC;
1439
+ this.data = data;
1440
+ }
1441
+ AlphanumericData.getBitsLength = function getBitsLength(length) {
1442
+ return 11 * Math.floor(length / 2) + 6 * (length % 2);
1443
+ };
1444
+ AlphanumericData.prototype.getLength = function getLength() {
1445
+ return this.data.length;
1446
+ };
1447
+ AlphanumericData.prototype.getBitsLength = function getBitsLength() {
1448
+ return AlphanumericData.getBitsLength(this.data.length);
1449
+ };
1450
+ AlphanumericData.prototype.write = function write(bitBuffer) {
1451
+ let i;
1452
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
1453
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
1454
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
1455
+ bitBuffer.put(value, 11);
1456
+ }
1457
+ if (this.data.length % 2) bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1458
+ };
1459
+ module.exports = AlphanumericData;
1460
+ }));
1461
+ //#endregion
1462
+ //#region node_modules/qrcode/lib/core/byte-data.js
1463
+ var require_byte_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1464
+ const Mode = require_mode();
1465
+ function ByteData(data) {
1466
+ this.mode = Mode.BYTE;
1467
+ if (typeof data === "string") this.data = new TextEncoder().encode(data);
1468
+ else this.data = new Uint8Array(data);
1469
+ }
1470
+ ByteData.getBitsLength = function getBitsLength(length) {
1471
+ return length * 8;
1472
+ };
1473
+ ByteData.prototype.getLength = function getLength() {
1474
+ return this.data.length;
1475
+ };
1476
+ ByteData.prototype.getBitsLength = function getBitsLength() {
1477
+ return ByteData.getBitsLength(this.data.length);
1478
+ };
1479
+ ByteData.prototype.write = function(bitBuffer) {
1480
+ for (let i = 0, l = this.data.length; i < l; i++) bitBuffer.put(this.data[i], 8);
1481
+ };
1482
+ module.exports = ByteData;
1483
+ }));
1484
+ //#endregion
1485
+ //#region node_modules/qrcode/lib/core/kanji-data.js
1486
+ var require_kanji_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1487
+ const Mode = require_mode();
1488
+ const Utils = require_utils$1();
1489
+ function KanjiData(data) {
1490
+ this.mode = Mode.KANJI;
1491
+ this.data = data;
1492
+ }
1493
+ KanjiData.getBitsLength = function getBitsLength(length) {
1494
+ return length * 13;
1495
+ };
1496
+ KanjiData.prototype.getLength = function getLength() {
1497
+ return this.data.length;
1498
+ };
1499
+ KanjiData.prototype.getBitsLength = function getBitsLength() {
1500
+ return KanjiData.getBitsLength(this.data.length);
1501
+ };
1502
+ KanjiData.prototype.write = function(bitBuffer) {
1503
+ let i;
1504
+ for (i = 0; i < this.data.length; i++) {
1505
+ let value = Utils.toSJIS(this.data[i]);
1506
+ if (value >= 33088 && value <= 40956) value -= 33088;
1507
+ else if (value >= 57408 && value <= 60351) value -= 49472;
1508
+ else throw new Error("Invalid SJIS character: " + this.data[i] + "\nMake sure your charset is UTF-8");
1509
+ value = (value >>> 8 & 255) * 192 + (value & 255);
1510
+ bitBuffer.put(value, 13);
1511
+ }
1512
+ };
1513
+ module.exports = KanjiData;
1514
+ }));
1515
+ //#endregion
1516
+ //#region node_modules/dijkstrajs/dijkstra.js
1517
+ var require_dijkstra = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1518
+ /******************************************************************************
1519
+ * Created 2008-08-19.
1520
+ *
1521
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
1522
+ *
1523
+ * Copyright (C) 2008
1524
+ * Wyatt Baldwin <self@wyattbaldwin.com>
1525
+ * All rights reserved
1526
+ *
1527
+ * Licensed under the MIT license.
1528
+ *
1529
+ * http://www.opensource.org/licenses/mit-license.php
1530
+ *
1531
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1532
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1533
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1534
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1535
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1536
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1537
+ * THE SOFTWARE.
1538
+ *****************************************************************************/
1539
+ var dijkstra = {
1540
+ single_source_shortest_paths: function(graph, s, d) {
1541
+ var predecessors = {};
1542
+ var costs = {};
1543
+ costs[s] = 0;
1544
+ var open = dijkstra.PriorityQueue.make();
1545
+ open.push(s, 0);
1546
+ var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit;
1547
+ while (!open.empty()) {
1548
+ closest = open.pop();
1549
+ u = closest.value;
1550
+ cost_of_s_to_u = closest.cost;
1551
+ adjacent_nodes = graph[u] || {};
1552
+ for (v in adjacent_nodes) if (adjacent_nodes.hasOwnProperty(v)) {
1553
+ cost_of_e = adjacent_nodes[v];
1554
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
1555
+ cost_of_s_to_v = costs[v];
1556
+ first_visit = typeof costs[v] === "undefined";
1557
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
1558
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
1559
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
1560
+ predecessors[v] = u;
1561
+ }
1562
+ }
1563
+ }
1564
+ if (typeof d !== "undefined" && typeof costs[d] === "undefined") {
1565
+ var msg = [
1566
+ "Could not find a path from ",
1567
+ s,
1568
+ " to ",
1569
+ d,
1570
+ "."
1571
+ ].join("");
1572
+ throw new Error(msg);
1573
+ }
1574
+ return predecessors;
1575
+ },
1576
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
1577
+ var nodes = [];
1578
+ var u = d;
1579
+ while (u) {
1580
+ nodes.push(u);
1581
+ predecessors[u];
1582
+ u = predecessors[u];
1583
+ }
1584
+ nodes.reverse();
1585
+ return nodes;
1586
+ },
1587
+ find_path: function(graph, s, d) {
1588
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
1589
+ return dijkstra.extract_shortest_path_from_predecessor_list(predecessors, d);
1590
+ },
1591
+ /**
1592
+ * A very naive priority queue implementation.
1593
+ */
1594
+ PriorityQueue: {
1595
+ make: function(opts) {
1596
+ var T = dijkstra.PriorityQueue, t = {}, key;
1597
+ opts = opts || {};
1598
+ for (key in T) if (T.hasOwnProperty(key)) t[key] = T[key];
1599
+ t.queue = [];
1600
+ t.sorter = opts.sorter || T.default_sorter;
1601
+ return t;
1602
+ },
1603
+ default_sorter: function(a, b) {
1604
+ return a.cost - b.cost;
1605
+ },
1606
+ /**
1607
+ * Add a new item to the queue and ensure the highest priority element
1608
+ * is at the front of the queue.
1609
+ */
1610
+ push: function(value, cost) {
1611
+ var item = {
1612
+ value,
1613
+ cost
1614
+ };
1615
+ this.queue.push(item);
1616
+ this.queue.sort(this.sorter);
1617
+ },
1618
+ /**
1619
+ * Return the highest priority element in the queue.
1620
+ */
1621
+ pop: function() {
1622
+ return this.queue.shift();
1623
+ },
1624
+ empty: function() {
1625
+ return this.queue.length === 0;
1626
+ }
1627
+ }
1628
+ };
1629
+ if (typeof module !== "undefined") module.exports = dijkstra;
1630
+ }));
1631
+ //#endregion
1632
+ //#region node_modules/qrcode/lib/core/segments.js
1633
+ var require_segments = /* @__PURE__ */ __commonJSMin(((exports) => {
1634
+ const Mode = require_mode();
1635
+ const NumericData = require_numeric_data();
1636
+ const AlphanumericData = require_alphanumeric_data();
1637
+ const ByteData = require_byte_data();
1638
+ const KanjiData = require_kanji_data();
1639
+ const Regex = require_regex();
1640
+ const Utils = require_utils$1();
1641
+ const dijkstra = require_dijkstra();
1642
+ /**
1643
+ * Returns UTF8 byte length
1644
+ *
1645
+ * @param {String} str Input string
1646
+ * @return {Number} Number of byte
1647
+ */
1648
+ function getStringByteLength(str) {
1649
+ return unescape(encodeURIComponent(str)).length;
1650
+ }
1651
+ /**
1652
+ * Get a list of segments of the specified mode
1653
+ * from a string
1654
+ *
1655
+ * @param {Mode} mode Segment mode
1656
+ * @param {String} str String to process
1657
+ * @return {Array} Array of object with segments data
1658
+ */
1659
+ function getSegments(regex, mode, str) {
1660
+ const segments = [];
1661
+ let result;
1662
+ while ((result = regex.exec(str)) !== null) segments.push({
1663
+ data: result[0],
1664
+ index: result.index,
1665
+ mode,
1666
+ length: result[0].length
1667
+ });
1668
+ return segments;
1669
+ }
1670
+ /**
1671
+ * Extracts a series of segments with the appropriate
1672
+ * modes from a string
1673
+ *
1674
+ * @param {String} dataStr Input string
1675
+ * @return {Array} Array of object with segments data
1676
+ */
1677
+ function getSegmentsFromString(dataStr) {
1678
+ const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
1679
+ const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
1680
+ let byteSegs;
1681
+ let kanjiSegs;
1682
+ if (Utils.isKanjiModeEnabled()) {
1683
+ byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
1684
+ kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
1685
+ } else {
1686
+ byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
1687
+ kanjiSegs = [];
1688
+ }
1689
+ return numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs).sort(function(s1, s2) {
1690
+ return s1.index - s2.index;
1691
+ }).map(function(obj) {
1692
+ return {
1693
+ data: obj.data,
1694
+ mode: obj.mode,
1695
+ length: obj.length
1696
+ };
1697
+ });
1698
+ }
1699
+ /**
1700
+ * Returns how many bits are needed to encode a string of
1701
+ * specified length with the specified mode
1702
+ *
1703
+ * @param {Number} length String length
1704
+ * @param {Mode} mode Segment mode
1705
+ * @return {Number} Bit length
1706
+ */
1707
+ function getSegmentBitsLength(length, mode) {
1708
+ switch (mode) {
1709
+ case Mode.NUMERIC: return NumericData.getBitsLength(length);
1710
+ case Mode.ALPHANUMERIC: return AlphanumericData.getBitsLength(length);
1711
+ case Mode.KANJI: return KanjiData.getBitsLength(length);
1712
+ case Mode.BYTE: return ByteData.getBitsLength(length);
1713
+ }
1714
+ }
1715
+ /**
1716
+ * Merges adjacent segments which have the same mode
1717
+ *
1718
+ * @param {Array} segs Array of object with segments data
1719
+ * @return {Array} Array of object with segments data
1720
+ */
1721
+ function mergeSegments(segs) {
1722
+ return segs.reduce(function(acc, curr) {
1723
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
1724
+ if (prevSeg && prevSeg.mode === curr.mode) {
1725
+ acc[acc.length - 1].data += curr.data;
1726
+ return acc;
1727
+ }
1728
+ acc.push(curr);
1729
+ return acc;
1730
+ }, []);
1731
+ }
1732
+ /**
1733
+ * Generates a list of all possible nodes combination which
1734
+ * will be used to build a segments graph.
1735
+ *
1736
+ * Nodes are divided by groups. Each group will contain a list of all the modes
1737
+ * in which is possible to encode the given text.
1738
+ *
1739
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
1740
+ * The group for '12345' will contain then 3 objects, one for each
1741
+ * possible encoding mode.
1742
+ *
1743
+ * Each node represents a possible segment.
1744
+ *
1745
+ * @param {Array} segs Array of object with segments data
1746
+ * @return {Array} Array of object with segments data
1747
+ */
1748
+ function buildNodes(segs) {
1749
+ const nodes = [];
1750
+ for (let i = 0; i < segs.length; i++) {
1751
+ const seg = segs[i];
1752
+ switch (seg.mode) {
1753
+ case Mode.NUMERIC:
1754
+ nodes.push([
1755
+ seg,
1756
+ {
1757
+ data: seg.data,
1758
+ mode: Mode.ALPHANUMERIC,
1759
+ length: seg.length
1760
+ },
1761
+ {
1762
+ data: seg.data,
1763
+ mode: Mode.BYTE,
1764
+ length: seg.length
1765
+ }
1766
+ ]);
1767
+ break;
1768
+ case Mode.ALPHANUMERIC:
1769
+ nodes.push([seg, {
1770
+ data: seg.data,
1771
+ mode: Mode.BYTE,
1772
+ length: seg.length
1773
+ }]);
1774
+ break;
1775
+ case Mode.KANJI:
1776
+ nodes.push([seg, {
1777
+ data: seg.data,
1778
+ mode: Mode.BYTE,
1779
+ length: getStringByteLength(seg.data)
1780
+ }]);
1781
+ break;
1782
+ case Mode.BYTE: nodes.push([{
1783
+ data: seg.data,
1784
+ mode: Mode.BYTE,
1785
+ length: getStringByteLength(seg.data)
1786
+ }]);
1787
+ }
1788
+ }
1789
+ return nodes;
1790
+ }
1791
+ /**
1792
+ * Builds a graph from a list of nodes.
1793
+ * All segments in each node group will be connected with all the segments of
1794
+ * the next group and so on.
1795
+ *
1796
+ * At each connection will be assigned a weight depending on the
1797
+ * segment's byte length.
1798
+ *
1799
+ * @param {Array} nodes Array of object with segments data
1800
+ * @param {Number} version QR Code version
1801
+ * @return {Object} Graph of all possible segments
1802
+ */
1803
+ function buildGraph(nodes, version) {
1804
+ const table = {};
1805
+ const graph = { start: {} };
1806
+ let prevNodeIds = ["start"];
1807
+ for (let i = 0; i < nodes.length; i++) {
1808
+ const nodeGroup = nodes[i];
1809
+ const currentNodeIds = [];
1810
+ for (let j = 0; j < nodeGroup.length; j++) {
1811
+ const node = nodeGroup[j];
1812
+ const key = "" + i + j;
1813
+ currentNodeIds.push(key);
1814
+ table[key] = {
1815
+ node,
1816
+ lastCount: 0
1817
+ };
1818
+ graph[key] = {};
1819
+ for (let n = 0; n < prevNodeIds.length; n++) {
1820
+ const prevNodeId = prevNodeIds[n];
1821
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
1822
+ graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
1823
+ table[prevNodeId].lastCount += node.length;
1824
+ } else {
1825
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
1826
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
1827
+ }
1828
+ }
1829
+ }
1830
+ prevNodeIds = currentNodeIds;
1831
+ }
1832
+ for (let n = 0; n < prevNodeIds.length; n++) graph[prevNodeIds[n]].end = 0;
1833
+ return {
1834
+ map: graph,
1835
+ table
1836
+ };
1837
+ }
1838
+ /**
1839
+ * Builds a segment from a specified data and mode.
1840
+ * If a mode is not specified, the more suitable will be used.
1841
+ *
1842
+ * @param {String} data Input data
1843
+ * @param {Mode | String} modesHint Data mode
1844
+ * @return {Segment} Segment
1845
+ */
1846
+ function buildSingleSegment(data, modesHint) {
1847
+ let mode;
1848
+ const bestMode = Mode.getBestModeForData(data);
1849
+ mode = Mode.from(modesHint, bestMode);
1850
+ if (mode !== Mode.BYTE && mode.bit < bestMode.bit) throw new Error("\"" + data + "\" cannot be encoded with mode " + Mode.toString(mode) + ".\n Suggested mode is: " + Mode.toString(bestMode));
1851
+ if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) mode = Mode.BYTE;
1852
+ switch (mode) {
1853
+ case Mode.NUMERIC: return new NumericData(data);
1854
+ case Mode.ALPHANUMERIC: return new AlphanumericData(data);
1855
+ case Mode.KANJI: return new KanjiData(data);
1856
+ case Mode.BYTE: return new ByteData(data);
1857
+ }
1858
+ }
1859
+ /**
1860
+ * Builds a list of segments from an array.
1861
+ * Array can contain Strings or Objects with segment's info.
1862
+ *
1863
+ * For each item which is a string, will be generated a segment with the given
1864
+ * string and the more appropriate encoding mode.
1865
+ *
1866
+ * For each item which is an object, will be generated a segment with the given
1867
+ * data and mode.
1868
+ * Objects must contain at least the property "data".
1869
+ * If property "mode" is not present, the more suitable mode will be used.
1870
+ *
1871
+ * @param {Array} array Array of objects with segments data
1872
+ * @return {Array} Array of Segments
1873
+ */
1874
+ exports.fromArray = function fromArray(array) {
1875
+ return array.reduce(function(acc, seg) {
1876
+ if (typeof seg === "string") acc.push(buildSingleSegment(seg, null));
1877
+ else if (seg.data) acc.push(buildSingleSegment(seg.data, seg.mode));
1878
+ return acc;
1879
+ }, []);
1880
+ };
1881
+ /**
1882
+ * Builds an optimized sequence of segments from a string,
1883
+ * which will produce the shortest possible bitstream.
1884
+ *
1885
+ * @param {String} data Input string
1886
+ * @param {Number} version QR Code version
1887
+ * @return {Array} Array of segments
1888
+ */
1889
+ exports.fromString = function fromString(data, version) {
1890
+ const graph = buildGraph(buildNodes(getSegmentsFromString(data, Utils.isKanjiModeEnabled())), version);
1891
+ const path = dijkstra.find_path(graph.map, "start", "end");
1892
+ const optimizedSegs = [];
1893
+ for (let i = 1; i < path.length - 1; i++) optimizedSegs.push(graph.table[path[i]].node);
1894
+ return exports.fromArray(mergeSegments(optimizedSegs));
1895
+ };
1896
+ /**
1897
+ * Splits a string in various segments with the modes which
1898
+ * best represent their content.
1899
+ * The produced segments are far from being optimized.
1900
+ * The output of this function is only used to estimate a QR Code version
1901
+ * which may contain the data.
1902
+ *
1903
+ * @param {string} data Input string
1904
+ * @return {Array} Array of segments
1905
+ */
1906
+ exports.rawSplit = function rawSplit(data) {
1907
+ return exports.fromArray(getSegmentsFromString(data, Utils.isKanjiModeEnabled()));
1908
+ };
1909
+ }));
1910
+ //#endregion
1911
+ //#region node_modules/qrcode/lib/core/qrcode.js
1912
+ var require_qrcode = /* @__PURE__ */ __commonJSMin(((exports) => {
1913
+ const Utils = require_utils$1();
1914
+ const ECLevel = require_error_correction_level();
1915
+ const BitBuffer = require_bit_buffer();
1916
+ const BitMatrix = require_bit_matrix();
1917
+ const AlignmentPattern = require_alignment_pattern();
1918
+ const FinderPattern = require_finder_pattern();
1919
+ const MaskPattern = require_mask_pattern();
1920
+ const ECCode = require_error_correction_code();
1921
+ const ReedSolomonEncoder = require_reed_solomon_encoder();
1922
+ const Version = require_version();
1923
+ const FormatInfo = require_format_info();
1924
+ const Mode = require_mode();
1925
+ const Segments = require_segments();
1926
+ /**
1927
+ * QRCode for JavaScript
1928
+ *
1929
+ * modified by Ryan Day for nodejs support
1930
+ * Copyright (c) 2011 Ryan Day
1931
+ *
1932
+ * Licensed under the MIT license:
1933
+ * http://www.opensource.org/licenses/mit-license.php
1934
+ *
1935
+ //---------------------------------------------------------------------
1936
+ // QRCode for JavaScript
1937
+ //
1938
+ // Copyright (c) 2009 Kazuhiko Arase
1939
+ //
1940
+ // URL: http://www.d-project.com/
1941
+ //
1942
+ // Licensed under the MIT license:
1943
+ // http://www.opensource.org/licenses/mit-license.php
1944
+ //
1945
+ // The word "QR Code" is registered trademark of
1946
+ // DENSO WAVE INCORPORATED
1947
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
1948
+ //
1949
+ //---------------------------------------------------------------------
1950
+ */
1951
+ /**
1952
+ * Add finder patterns bits to matrix
1953
+ *
1954
+ * @param {BitMatrix} matrix Modules matrix
1955
+ * @param {Number} version QR Code version
1956
+ */
1957
+ function setupFinderPattern(matrix, version) {
1958
+ const size = matrix.size;
1959
+ const pos = FinderPattern.getPositions(version);
1960
+ for (let i = 0; i < pos.length; i++) {
1961
+ const row = pos[i][0];
1962
+ const col = pos[i][1];
1963
+ for (let r = -1; r <= 7; r++) {
1964
+ if (row + r <= -1 || size <= row + r) continue;
1965
+ for (let c = -1; c <= 7; c++) {
1966
+ if (col + c <= -1 || size <= col + c) continue;
1967
+ if (r >= 0 && r <= 6 && (c === 0 || c === 6) || c >= 0 && c <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c >= 2 && c <= 4) matrix.set(row + r, col + c, true, true);
1968
+ else matrix.set(row + r, col + c, false, true);
1969
+ }
1970
+ }
1971
+ }
1972
+ }
1973
+ /**
1974
+ * Add timing pattern bits to matrix
1975
+ *
1976
+ * Note: this function must be called before {@link setupAlignmentPattern}
1977
+ *
1978
+ * @param {BitMatrix} matrix Modules matrix
1979
+ */
1980
+ function setupTimingPattern(matrix) {
1981
+ const size = matrix.size;
1982
+ for (let r = 8; r < size - 8; r++) {
1983
+ const value = r % 2 === 0;
1984
+ matrix.set(r, 6, value, true);
1985
+ matrix.set(6, r, value, true);
1986
+ }
1987
+ }
1988
+ /**
1989
+ * Add alignment patterns bits to matrix
1990
+ *
1991
+ * Note: this function must be called after {@link setupTimingPattern}
1992
+ *
1993
+ * @param {BitMatrix} matrix Modules matrix
1994
+ * @param {Number} version QR Code version
1995
+ */
1996
+ function setupAlignmentPattern(matrix, version) {
1997
+ const pos = AlignmentPattern.getPositions(version);
1998
+ for (let i = 0; i < pos.length; i++) {
1999
+ const row = pos[i][0];
2000
+ const col = pos[i][1];
2001
+ for (let r = -2; r <= 2; r++) for (let c = -2; c <= 2; c++) if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) matrix.set(row + r, col + c, true, true);
2002
+ else matrix.set(row + r, col + c, false, true);
2003
+ }
2004
+ }
2005
+ /**
2006
+ * Add version info bits to matrix
2007
+ *
2008
+ * @param {BitMatrix} matrix Modules matrix
2009
+ * @param {Number} version QR Code version
2010
+ */
2011
+ function setupVersionInfo(matrix, version) {
2012
+ const size = matrix.size;
2013
+ const bits = Version.getEncodedBits(version);
2014
+ let row, col, mod;
2015
+ for (let i = 0; i < 18; i++) {
2016
+ row = Math.floor(i / 3);
2017
+ col = i % 3 + size - 8 - 3;
2018
+ mod = (bits >> i & 1) === 1;
2019
+ matrix.set(row, col, mod, true);
2020
+ matrix.set(col, row, mod, true);
2021
+ }
2022
+ }
2023
+ /**
2024
+ * Add format info bits to matrix
2025
+ *
2026
+ * @param {BitMatrix} matrix Modules matrix
2027
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2028
+ * @param {Number} maskPattern Mask pattern reference value
2029
+ */
2030
+ function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
2031
+ const size = matrix.size;
2032
+ const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2033
+ let i, mod;
2034
+ for (i = 0; i < 15; i++) {
2035
+ mod = (bits >> i & 1) === 1;
2036
+ if (i < 6) matrix.set(i, 8, mod, true);
2037
+ else if (i < 8) matrix.set(i + 1, 8, mod, true);
2038
+ else matrix.set(size - 15 + i, 8, mod, true);
2039
+ if (i < 8) matrix.set(8, size - i - 1, mod, true);
2040
+ else if (i < 9) matrix.set(8, 15 - i - 1 + 1, mod, true);
2041
+ else matrix.set(8, 15 - i - 1, mod, true);
2042
+ }
2043
+ matrix.set(size - 8, 8, 1, true);
2044
+ }
2045
+ /**
2046
+ * Add encoded data bits to matrix
2047
+ *
2048
+ * @param {BitMatrix} matrix Modules matrix
2049
+ * @param {Uint8Array} data Data codewords
2050
+ */
2051
+ function setupData(matrix, data) {
2052
+ const size = matrix.size;
2053
+ let inc = -1;
2054
+ let row = size - 1;
2055
+ let bitIndex = 7;
2056
+ let byteIndex = 0;
2057
+ for (let col = size - 1; col > 0; col -= 2) {
2058
+ if (col === 6) col--;
2059
+ while (true) {
2060
+ for (let c = 0; c < 2; c++) if (!matrix.isReserved(row, col - c)) {
2061
+ let dark = false;
2062
+ if (byteIndex < data.length) dark = (data[byteIndex] >>> bitIndex & 1) === 1;
2063
+ matrix.set(row, col - c, dark);
2064
+ bitIndex--;
2065
+ if (bitIndex === -1) {
2066
+ byteIndex++;
2067
+ bitIndex = 7;
2068
+ }
2069
+ }
2070
+ row += inc;
2071
+ if (row < 0 || size <= row) {
2072
+ row -= inc;
2073
+ inc = -inc;
2074
+ break;
2075
+ }
2076
+ }
2077
+ }
2078
+ }
2079
+ /**
2080
+ * Create encoded codewords from data input
2081
+ *
2082
+ * @param {Number} version QR Code version
2083
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2084
+ * @param {ByteData} data Data input
2085
+ * @return {Uint8Array} Buffer containing encoded codewords
2086
+ */
2087
+ function createData(version, errorCorrectionLevel, segments) {
2088
+ const buffer = new BitBuffer();
2089
+ segments.forEach(function(data) {
2090
+ buffer.put(data.mode.bit, 4);
2091
+ buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
2092
+ data.write(buffer);
2093
+ });
2094
+ const dataTotalCodewordsBits = (Utils.getSymbolTotalCodewords(version) - ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)) * 8;
2095
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) buffer.put(0, 4);
2096
+ while (buffer.getLengthInBits() % 8 !== 0) buffer.putBit(0);
2097
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2098
+ for (let i = 0; i < remainingByte; i++) buffer.put(i % 2 ? 17 : 236, 8);
2099
+ return createCodewords(buffer, version, errorCorrectionLevel);
2100
+ }
2101
+ /**
2102
+ * Encode input data with Reed-Solomon and return codewords with
2103
+ * relative error correction bits
2104
+ *
2105
+ * @param {BitBuffer} bitBuffer Data to encode
2106
+ * @param {Number} version QR Code version
2107
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2108
+ * @return {Uint8Array} Buffer containing encoded codewords
2109
+ */
2110
+ function createCodewords(bitBuffer, version, errorCorrectionLevel) {
2111
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2112
+ const dataTotalCodewords = totalCodewords - ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2113
+ const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
2114
+ const blocksInGroup1 = ecTotalBlocks - totalCodewords % ecTotalBlocks;
2115
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2116
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2117
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
2118
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
2119
+ const rs = new ReedSolomonEncoder(ecCount);
2120
+ let offset = 0;
2121
+ const dcData = new Array(ecTotalBlocks);
2122
+ const ecData = new Array(ecTotalBlocks);
2123
+ let maxDataSize = 0;
2124
+ const buffer = new Uint8Array(bitBuffer.buffer);
2125
+ for (let b = 0; b < ecTotalBlocks; b++) {
2126
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
2127
+ dcData[b] = buffer.slice(offset, offset + dataSize);
2128
+ ecData[b] = rs.encode(dcData[b]);
2129
+ offset += dataSize;
2130
+ maxDataSize = Math.max(maxDataSize, dataSize);
2131
+ }
2132
+ const data = new Uint8Array(totalCodewords);
2133
+ let index = 0;
2134
+ let i, r;
2135
+ for (i = 0; i < maxDataSize; i++) for (r = 0; r < ecTotalBlocks; r++) if (i < dcData[r].length) data[index++] = dcData[r][i];
2136
+ for (i = 0; i < ecCount; i++) for (r = 0; r < ecTotalBlocks; r++) data[index++] = ecData[r][i];
2137
+ return data;
2138
+ }
2139
+ /**
2140
+ * Build QR Code symbol
2141
+ *
2142
+ * @param {String} data Input string
2143
+ * @param {Number} version QR Code version
2144
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
2145
+ * @param {MaskPattern} maskPattern Mask pattern
2146
+ * @return {Object} Object containing symbol data
2147
+ */
2148
+ function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
2149
+ let segments;
2150
+ if (Array.isArray(data)) segments = Segments.fromArray(data);
2151
+ else if (typeof data === "string") {
2152
+ let estimatedVersion = version;
2153
+ if (!estimatedVersion) {
2154
+ const rawSegments = Segments.rawSplit(data);
2155
+ estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2156
+ }
2157
+ segments = Segments.fromString(data, estimatedVersion || 40);
2158
+ } else throw new Error("Invalid data");
2159
+ const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
2160
+ if (!bestVersion) throw new Error("The amount of data is too big to be stored in a QR Code");
2161
+ if (!version) version = bestVersion;
2162
+ else if (version < bestVersion) throw new Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + bestVersion + ".\n");
2163
+ const dataBits = createData(version, errorCorrectionLevel, segments);
2164
+ const moduleCount = Utils.getSymbolSize(version);
2165
+ const modules = new BitMatrix(moduleCount);
2166
+ setupFinderPattern(modules, version);
2167
+ setupTimingPattern(modules);
2168
+ setupAlignmentPattern(modules, version);
2169
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
2170
+ if (version >= 7) setupVersionInfo(modules, version);
2171
+ setupData(modules, dataBits);
2172
+ if (isNaN(maskPattern)) maskPattern = MaskPattern.getBestMask(modules, setupFormatInfo.bind(null, modules, errorCorrectionLevel));
2173
+ MaskPattern.applyMask(maskPattern, modules);
2174
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
2175
+ return {
2176
+ modules,
2177
+ version,
2178
+ errorCorrectionLevel,
2179
+ maskPattern,
2180
+ segments
2181
+ };
2182
+ }
2183
+ /**
2184
+ * QR Code
2185
+ *
2186
+ * @param {String | Array} data Input data
2187
+ * @param {Object} options Optional configurations
2188
+ * @param {Number} options.version QR Code version
2189
+ * @param {String} options.errorCorrectionLevel Error correction level
2190
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
2191
+ */
2192
+ exports.create = function create(data, options) {
2193
+ if (typeof data === "undefined" || data === "") throw new Error("No input text");
2194
+ let errorCorrectionLevel = ECLevel.M;
2195
+ let version;
2196
+ let mask;
2197
+ if (typeof options !== "undefined") {
2198
+ errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
2199
+ version = Version.from(options.version);
2200
+ mask = MaskPattern.from(options.maskPattern);
2201
+ if (options.toSJISFunc) Utils.setToSJISFunction(options.toSJISFunc);
2202
+ }
2203
+ return createSymbol(data, version, errorCorrectionLevel, mask);
2204
+ };
2205
+ }));
2206
+ //#endregion
2207
+ //#region node_modules/qrcode/lib/renderer/utils.js
2208
+ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
2209
+ function hex2rgba(hex) {
2210
+ if (typeof hex === "number") hex = hex.toString();
2211
+ if (typeof hex !== "string") throw new Error("Color should be defined as hex string");
2212
+ let hexCode = hex.slice().replace("#", "").split("");
2213
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) throw new Error("Invalid hex color: " + hex);
2214
+ if (hexCode.length === 3 || hexCode.length === 4) hexCode = Array.prototype.concat.apply([], hexCode.map(function(c) {
2215
+ return [c, c];
2216
+ }));
2217
+ if (hexCode.length === 6) hexCode.push("F", "F");
2218
+ const hexValue = parseInt(hexCode.join(""), 16);
2219
+ return {
2220
+ r: hexValue >> 24 & 255,
2221
+ g: hexValue >> 16 & 255,
2222
+ b: hexValue >> 8 & 255,
2223
+ a: hexValue & 255,
2224
+ hex: "#" + hexCode.slice(0, 6).join("")
2225
+ };
2226
+ }
2227
+ exports.getOptions = function getOptions(options) {
2228
+ if (!options) options = {};
2229
+ if (!options.color) options.color = {};
2230
+ const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
2231
+ const width = options.width && options.width >= 21 ? options.width : void 0;
2232
+ const scale = options.scale || 4;
2233
+ return {
2234
+ width,
2235
+ scale: width ? 4 : scale,
2236
+ margin,
2237
+ color: {
2238
+ dark: hex2rgba(options.color.dark || "#000000ff"),
2239
+ light: hex2rgba(options.color.light || "#ffffffff")
2240
+ },
2241
+ type: options.type,
2242
+ rendererOpts: options.rendererOpts || {}
2243
+ };
2244
+ };
2245
+ exports.getScale = function getScale(qrSize, opts) {
2246
+ return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
2247
+ };
2248
+ exports.getImageWidth = function getImageWidth(qrSize, opts) {
2249
+ const scale = exports.getScale(qrSize, opts);
2250
+ return Math.floor((qrSize + opts.margin * 2) * scale);
2251
+ };
2252
+ exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
2253
+ const size = qr.modules.size;
2254
+ const data = qr.modules.data;
2255
+ const scale = exports.getScale(size, opts);
2256
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
2257
+ const scaledMargin = opts.margin * scale;
2258
+ const palette = [opts.color.light, opts.color.dark];
2259
+ for (let i = 0; i < symbolSize; i++) for (let j = 0; j < symbolSize; j++) {
2260
+ let posDst = (i * symbolSize + j) * 4;
2261
+ let pxColor = opts.color.light;
2262
+ if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2263
+ const iSrc = Math.floor((i - scaledMargin) / scale);
2264
+ const jSrc = Math.floor((j - scaledMargin) / scale);
2265
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
2266
+ }
2267
+ imgData[posDst++] = pxColor.r;
2268
+ imgData[posDst++] = pxColor.g;
2269
+ imgData[posDst++] = pxColor.b;
2270
+ imgData[posDst] = pxColor.a;
2271
+ }
2272
+ };
2273
+ }));
2274
+ //#endregion
2275
+ //#region node_modules/qrcode/lib/renderer/canvas.js
2276
+ var require_canvas = /* @__PURE__ */ __commonJSMin(((exports) => {
2277
+ const Utils = require_utils();
2278
+ function clearCanvas(ctx, canvas, size) {
2279
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
2280
+ if (!canvas.style) canvas.style = {};
2281
+ canvas.height = size;
2282
+ canvas.width = size;
2283
+ canvas.style.height = size + "px";
2284
+ canvas.style.width = size + "px";
2285
+ }
2286
+ function getCanvasElement() {
2287
+ try {
2288
+ return document.createElement("canvas");
2289
+ } catch (e) {
2290
+ throw new Error("You need to specify a canvas element");
2291
+ }
2292
+ }
2293
+ exports.render = function render(qrData, canvas, options) {
2294
+ let opts = options;
2295
+ let canvasEl = canvas;
2296
+ if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
2297
+ opts = canvas;
2298
+ canvas = void 0;
2299
+ }
2300
+ if (!canvas) canvasEl = getCanvasElement();
2301
+ opts = Utils.getOptions(opts);
2302
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
2303
+ const ctx = canvasEl.getContext("2d");
2304
+ const image = ctx.createImageData(size, size);
2305
+ Utils.qrToImageData(image.data, qrData, opts);
2306
+ clearCanvas(ctx, canvasEl, size);
2307
+ ctx.putImageData(image, 0, 0);
2308
+ return canvasEl;
2309
+ };
2310
+ exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
2311
+ let opts = options;
2312
+ if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
2313
+ opts = canvas;
2314
+ canvas = void 0;
2315
+ }
2316
+ if (!opts) opts = {};
2317
+ const canvasEl = exports.render(qrData, canvas, opts);
2318
+ const type = opts.type || "image/png";
2319
+ const rendererOpts = opts.rendererOpts || {};
2320
+ return canvasEl.toDataURL(type, rendererOpts.quality);
2321
+ };
2322
+ }));
2323
+ //#endregion
2324
+ //#region node_modules/qrcode/lib/renderer/svg-tag.js
2325
+ var require_svg_tag = /* @__PURE__ */ __commonJSMin(((exports) => {
2326
+ const Utils = require_utils();
2327
+ function getColorAttrib(color, attrib) {
2328
+ const alpha = color.a / 255;
2329
+ const str = attrib + "=\"" + color.hex + "\"";
2330
+ return alpha < 1 ? str + " " + attrib + "-opacity=\"" + alpha.toFixed(2).slice(1) + "\"" : str;
2331
+ }
2332
+ function svgCmd(cmd, x, y) {
2333
+ let str = cmd + x;
2334
+ if (typeof y !== "undefined") str += " " + y;
2335
+ return str;
2336
+ }
2337
+ function qrToPath(data, size, margin) {
2338
+ let path = "";
2339
+ let moveBy = 0;
2340
+ let newRow = false;
2341
+ let lineLength = 0;
2342
+ for (let i = 0; i < data.length; i++) {
2343
+ const col = Math.floor(i % size);
2344
+ const row = Math.floor(i / size);
2345
+ if (!col && !newRow) newRow = true;
2346
+ if (data[i]) {
2347
+ lineLength++;
2348
+ if (!(i > 0 && col > 0 && data[i - 1])) {
2349
+ path += newRow ? svgCmd("M", col + margin, .5 + row + margin) : svgCmd("m", moveBy, 0);
2350
+ moveBy = 0;
2351
+ newRow = false;
2352
+ }
2353
+ if (!(col + 1 < size && data[i + 1])) {
2354
+ path += svgCmd("h", lineLength);
2355
+ lineLength = 0;
2356
+ }
2357
+ } else moveBy++;
2358
+ }
2359
+ return path;
2360
+ }
2361
+ exports.render = function render(qrData, options, cb) {
2362
+ const opts = Utils.getOptions(options);
2363
+ const size = qrData.modules.size;
2364
+ const data = qrData.modules.data;
2365
+ const qrcodesize = size + opts.margin * 2;
2366
+ const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + " d=\"M0 0h" + qrcodesize + "v" + qrcodesize + "H0z\"/>";
2367
+ const path = "<path " + getColorAttrib(opts.color.dark, "stroke") + " d=\"" + qrToPath(data, size, opts.margin) + "\"/>";
2368
+ const viewBox = "viewBox=\"0 0 " + qrcodesize + " " + qrcodesize + "\"";
2369
+ const svgTag = "<svg xmlns=\"http://www.w3.org/2000/svg\" " + (!opts.width ? "" : "width=\"" + opts.width + "\" height=\"" + opts.width + "\" ") + viewBox + " shape-rendering=\"crispEdges\">" + bg + path + "</svg>\n";
2370
+ if (typeof cb === "function") cb(null, svgTag);
2371
+ return svgTag;
2372
+ };
2373
+ }));
2374
+ //#endregion
2375
+ //#region src/pairing-qr.ts
2376
+ var import_browser = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
2377
+ const canPromise = require_can_promise();
2378
+ const QRCode = require_qrcode();
2379
+ const CanvasRenderer = require_canvas();
2380
+ const SvgRenderer = require_svg_tag();
2381
+ function renderCanvas(renderFunc, canvas, text, opts, cb) {
2382
+ const args = [].slice.call(arguments, 1);
2383
+ const argsNum = args.length;
2384
+ const isLastArgCb = typeof args[argsNum - 1] === "function";
2385
+ if (!isLastArgCb && !canPromise()) throw new Error("Callback required as last argument");
2386
+ if (isLastArgCb) {
2387
+ if (argsNum < 2) throw new Error("Too few arguments provided");
2388
+ if (argsNum === 2) {
2389
+ cb = text;
2390
+ text = canvas;
2391
+ canvas = opts = void 0;
2392
+ } else if (argsNum === 3) {
2393
+ if (canvas.getContext && typeof cb === "undefined") {
2394
+ cb = opts;
2395
+ opts = void 0;
2396
+ } else {
2397
+ cb = opts;
2398
+ opts = text;
2399
+ text = canvas;
2400
+ canvas = void 0;
2401
+ }
2402
+ }
2403
+ } else {
2404
+ if (argsNum < 1) throw new Error("Too few arguments provided");
2405
+ if (argsNum === 1) {
2406
+ text = canvas;
2407
+ canvas = opts = void 0;
2408
+ } else if (argsNum === 2 && !canvas.getContext) {
2409
+ opts = text;
2410
+ text = canvas;
2411
+ canvas = void 0;
2412
+ }
2413
+ return new Promise(function(resolve, reject) {
2414
+ try {
2415
+ resolve(renderFunc(QRCode.create(text, opts), canvas, opts));
2416
+ } catch (e) {
2417
+ reject(e);
2418
+ }
2419
+ });
2420
+ }
2421
+ try {
2422
+ const data = QRCode.create(text, opts);
2423
+ cb(null, renderFunc(data, canvas, opts));
2424
+ } catch (e) {
2425
+ cb(e);
2426
+ }
2427
+ }
2428
+ exports.create = QRCode.create;
2429
+ exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
2430
+ exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
2431
+ exports.toString = renderCanvas.bind(null, function(data, _, opts) {
2432
+ return SvgRenderer.render(data, opts);
2433
+ });
2434
+ })))(), 1);
2435
+ /**
2436
+ * Protocol-v1 compatibility identifier used by the TestFlight build currently
2437
+ * under review. This is wire data, not the plugin or product display name.
2438
+ */
2439
+ const PAIRING_QR_TYPE = "dsh-pocket-pairing";
2440
+ function isLoopbackHostname(hostname) {
2441
+ const normalized = hostname.toLowerCase();
2442
+ return normalized === "localhost" || normalized.endsWith(".localhost") || normalized === "[::1]" || normalized === "::1" || normalized.startsWith("127.");
2443
+ }
2444
+ /** Prefer an online Funnel; otherwise turn the current web origin into a LAN target. */
2445
+ function selectPairingTarget(remote, lanAddresses, currentOrigin) {
2446
+ let origin;
2447
+ try {
2448
+ if (currentOrigin) origin = new URL(currentOrigin);
2449
+ } catch {}
2450
+ if (remote.publicURL && origin?.origin === remote.publicURL) return {
2451
+ host: remote.publicURL,
2452
+ kind: "public"
2453
+ };
2454
+ if (remote.phase === "online" && remote.publicURL) return {
2455
+ host: remote.publicURL,
2456
+ kind: "public"
2457
+ };
2458
+ if (origin && ["http:", "https:"].includes(origin.protocol) && !isLoopbackHostname(origin.hostname)) return {
2459
+ host: origin.origin,
2460
+ kind: "lan"
2461
+ };
2462
+ const address = lanAddresses[0];
2463
+ if (!address) return null;
2464
+ return {
2465
+ host: `${origin?.protocol === "https:" ? "https:" : "http:"}//${address}${origin?.port ? `:${origin.port}` : ""}`,
2466
+ kind: "lan"
2467
+ };
2468
+ }
2469
+ /** Encode an out-of-band pairing payload without putting the token in a URL. */
2470
+ function encodePairingQRPayload(host, token) {
2471
+ const normalizedHost = host.trim();
2472
+ const parsed = new URL(normalizedHost);
2473
+ if (![
2474
+ "http:",
2475
+ "https:",
2476
+ "ws:",
2477
+ "wss:"
2478
+ ].includes(parsed.protocol) || parsed.hostname === "" || parsed.username !== "" || parsed.password !== "") throw new TypeError("pairing QR requires a valid HTTP(S)/WS(S) host");
2479
+ if (token.trim().length < 32) throw new TypeError("pairing token is invalid");
2480
+ const payload = {
2481
+ v: 1,
2482
+ type: PAIRING_QR_TYPE,
2483
+ host: normalizedHost,
2484
+ token: token.trim()
2485
+ };
2486
+ return JSON.stringify(payload);
2487
+ }
2488
+ //#endregion
2489
+ //#region src/report-wire.ts
2490
+ /** The npm package identity both contribution registrations claim. */
2491
+ const REPORT_REMOTE_PACKAGE = "dsh-deeppilot";
2492
+ /** Canonical `<namespace>/<method>` endpoint of the report Remote. */
2493
+ const REPORT_ENDPOINT = "deeppilot/report";
2494
+ /** Explicit, user-triggered endpoint for revealing the pairing secret. */
2495
+ const REVEAL_TOKEN_ENDPOINT = "deeppilot/revealToken";
2496
+ /**
2497
+ * Explicit, user-triggered endpoint that replaces the pairing secret. The old
2498
+ * token stops working immediately; the fresh one is returned so the page can
2499
+ * show/QR it right away.
2500
+ */
2501
+ const ROTATE_TOKEN_ENDPOINT = "deeppilot/rotateToken";
2502
+ function reject(field) {
2503
+ throw new TypeError(`deeppilot/report result: invalid ${field}`);
2504
+ }
2505
+ function str(source, key, field) {
2506
+ const value = source[key];
2507
+ if (typeof value !== "string") reject(field);
2508
+ return value;
2509
+ }
2510
+ function num(source, key, field) {
2511
+ const value = source[key];
2512
+ if (typeof value !== "number" || !Number.isFinite(value)) reject(field);
2513
+ return value;
2514
+ }
2515
+ function bool(source, key, field) {
2516
+ const value = source[key];
2517
+ if (typeof value !== "boolean") reject(field);
2518
+ return value;
2519
+ }
2520
+ function rec(value, field) {
2521
+ if (typeof value !== "object" || value === null || Array.isArray(value)) reject(field);
2522
+ return value;
2523
+ }
2524
+ function parseDevice(value) {
2525
+ const s = rec(value, "device");
2526
+ let apns;
2527
+ if (s.apns !== void 0) {
2528
+ const a = rec(s.apns, "device.apns");
2529
+ const environment = str(a, "environment", "device.apns.environment");
2530
+ if (environment !== "development" && environment !== "production") reject("device.apns.environment");
2531
+ apns = {
2532
+ environment,
2533
+ updatedAt: num(a, "updatedAt", "device.apns.updatedAt")
2534
+ };
2535
+ }
2536
+ return {
2537
+ deviceId: str(s, "deviceId", "device.deviceId"),
2538
+ deviceName: str(s, "deviceName", "device.deviceName"),
2539
+ appVersion: str(s, "appVersion", "device.appVersion"),
2540
+ firstSeenTs: num(s, "firstSeenTs", "device.firstSeenTs"),
2541
+ lastSeenTs: num(s, "lastSeenTs", "device.lastSeenTs"),
2542
+ ...apns ? { apns } : {}
2543
+ };
2544
+ }
2545
+ function parseRemote(value) {
2546
+ const s = rec(value, "remote");
2547
+ const provider = str(s, "provider", "remote.provider");
2548
+ const phase = str(s, "phase", "remote.phase");
2549
+ if (provider !== "tailscale-funnel") reject("remote.provider");
2550
+ if (![
2551
+ "disabled",
2552
+ "starting",
2553
+ "login_required",
2554
+ "online",
2555
+ "error",
2556
+ "unavailable",
2557
+ "stopped"
2558
+ ].includes(phase)) reject("remote.phase");
2559
+ const publicURL = s.publicURL;
2560
+ const authURL = s.authURL;
2561
+ const message = s.message;
2562
+ if (publicURL !== void 0 && typeof publicURL !== "string") reject("remote.publicURL");
2563
+ if (authURL !== void 0 && typeof authURL !== "string") reject("remote.authURL");
2564
+ if (message !== void 0 && typeof message !== "string") reject("remote.message");
2565
+ return {
2566
+ provider,
2567
+ phase,
2568
+ ...typeof publicURL === "string" ? { publicURL } : {},
2569
+ ...typeof authURL === "string" ? { authURL } : {},
2570
+ ...typeof message === "string" ? { message } : {},
2571
+ updatedAt: num(s, "updatedAt", "remote.updatedAt")
2572
+ };
2573
+ }
2574
+ function parseRelayTestStep(value) {
2575
+ const st = rec(value, "step");
2576
+ const id = str(st, "id", "step.id");
2577
+ if (id !== "health" && id !== "enroll") reject("step.id");
2578
+ const latencyMs = st.latencyMs;
2579
+ if (latencyMs !== void 0 && typeof latencyMs !== "number") reject("step.latencyMs");
2580
+ return {
2581
+ id,
2582
+ ok: bool(st, "ok", "step.ok"),
2583
+ message: str(st, "message", "step.message"),
2584
+ ...typeof latencyMs === "number" ? { latencyMs } : {}
2585
+ };
2586
+ }
2587
+ function parseRelayTestResult(value) {
2588
+ const s = rec(value, "result");
2589
+ const overall = str(s, "overall", "overall");
2590
+ if (overall !== "ok" && overall !== "failed") reject("overall");
2591
+ const stepsRaw = s.steps;
2592
+ if (!Array.isArray(stepsRaw)) reject("steps");
2593
+ return {
2594
+ url: str(s, "url", "url"),
2595
+ overall,
2596
+ tokenIssued: bool(s, "tokenIssued", "tokenIssued"),
2597
+ steps: stepsRaw.map(parseRelayTestStep)
2598
+ };
2599
+ }
2600
+ function parsePushTestResult(value) {
2601
+ const s = rec(value, "result");
2602
+ const transport = str(s, "transport", "transport");
2603
+ if (transport !== "apns" && transport !== "relay" && transport !== "none") reject("transport");
2604
+ const overall = str(s, "overall", "overall");
2605
+ if (![
2606
+ "sent",
2607
+ "failed",
2608
+ "no-targets",
2609
+ "not-configured"
2610
+ ].includes(overall)) reject("overall");
2611
+ const resultsRaw = s.results;
2612
+ if (!Array.isArray(resultsRaw)) reject("results");
2613
+ const results = resultsRaw.map((value) => {
2614
+ const r = rec(value, "device result");
2615
+ const reason = r.reason;
2616
+ const tokenFingerprint = r.tokenFingerprint;
2617
+ return {
2618
+ name: str(r, "name", "result.name"),
2619
+ environment: str(r, "environment", "result.environment"),
2620
+ outcome: str(r, "outcome", "result.outcome"),
2621
+ ...typeof reason === "string" && reason.length > 0 ? { reason } : {},
2622
+ ...typeof tokenFingerprint === "string" && /^[0-9a-f]{1,32}$/.test(tokenFingerprint) ? { tokenFingerprint } : {}
2623
+ };
2624
+ });
2625
+ const message = s.message;
2626
+ return {
2627
+ transport,
2628
+ overall,
2629
+ ...typeof message === "string" && message.length > 0 ? { message } : {},
2630
+ results
2631
+ };
2632
+ }
2633
+ function parseReport(value) {
2634
+ const s = rec(value, "report");
2635
+ const devices = s.devices;
2636
+ const lanAddresses = s.lanAddresses;
2637
+ if (!Array.isArray(devices)) reject("devices");
2638
+ if (!Array.isArray(lanAddresses) || lanAddresses.some((value) => typeof value !== "string")) reject("lanAddresses");
2639
+ return {
2640
+ protocolVersion: num(s, "protocolVersion", "protocolVersion"),
2641
+ serverVersion: str(s, "serverVersion", "serverVersion"),
2642
+ enabled: bool(s, "enabled", "enabled"),
2643
+ tokenPath: str(s, "tokenPath", "tokenPath"),
2644
+ tokenReady: bool(s, "tokenReady", "tokenReady"),
2645
+ activeConnections: num(s, "activeConnections", "activeConnections"),
2646
+ historyBufferMax: num(s, "historyBufferMax", "historyBufferMax"),
2647
+ debug: bool(s, "debug", "debug"),
2648
+ lanAddresses,
2649
+ remote: parseRemote(s.remote),
2650
+ devices: devices.map(parseDevice)
2651
+ };
2652
+ }
2653
+ const reportSchema = { parse: parseReport };
2654
+ const relayTestSchema = { parse: parseRelayTestResult };
2655
+ const pushTestSchema = { parse: parsePushTestResult };
2656
+ const pairingTokenSchema = { parse(value) {
2657
+ if (typeof value !== "string" || value.length < 32) throw new TypeError("deeppilot/revealToken result: invalid token");
2658
+ return value;
2659
+ } };
2660
+ const REPORT_REMOTE_CONTRIBUTION = {
2661
+ package: REPORT_REMOTE_PACKAGE,
2662
+ descriptors: [
2663
+ {
2664
+ id: `${REPORT_REMOTE_PACKAGE}#${REPORT_ENDPOINT}`,
2665
+ service: "deeppilotReport",
2666
+ namespace: "deeppilot",
2667
+ method: "report",
2668
+ invocation: { kind: "direct" },
2669
+ parameters: [],
2670
+ result: {
2671
+ mode: "strict",
2672
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#DeepPilotReport`,
2673
+ schema: reportSchema
2674
+ }
2675
+ },
2676
+ {
2677
+ id: `${REPORT_REMOTE_PACKAGE}#${REVEAL_TOKEN_ENDPOINT}`,
2678
+ service: "deeppilotReport",
2679
+ namespace: "deeppilot",
2680
+ method: "revealToken",
2681
+ invocation: { kind: "direct" },
2682
+ parameters: [],
2683
+ result: {
2684
+ mode: "strict",
2685
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#PairingToken`,
2686
+ schema: pairingTokenSchema
2687
+ }
2688
+ },
2689
+ {
2690
+ id: `${REPORT_REMOTE_PACKAGE}#${ROTATE_TOKEN_ENDPOINT}`,
2691
+ service: "deeppilotReport",
2692
+ namespace: "deeppilot",
2693
+ method: "rotateToken",
2694
+ invocation: { kind: "direct" },
2695
+ parameters: [],
2696
+ result: {
2697
+ mode: "strict",
2698
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#PairingToken`,
2699
+ schema: pairingTokenSchema
2700
+ }
2701
+ },
2702
+ {
2703
+ id: `${REPORT_REMOTE_PACKAGE}#deeppilot/testRelay`,
2704
+ service: "deeppilotReport",
2705
+ namespace: "deeppilot",
2706
+ method: "testRelay",
2707
+ invocation: { kind: "direct" },
2708
+ parameters: [],
2709
+ result: {
2710
+ mode: "strict",
2711
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#RelayTestResult`,
2712
+ schema: relayTestSchema
2713
+ }
2714
+ },
2715
+ {
2716
+ id: `${REPORT_REMOTE_PACKAGE}#deeppilot/testPush`,
2717
+ service: "deeppilotReport",
2718
+ namespace: "deeppilot",
2719
+ method: "testPush",
2720
+ invocation: { kind: "direct" },
2721
+ parameters: [],
2722
+ result: {
2723
+ mode: "strict",
2724
+ typeSymbol: `${REPORT_REMOTE_PACKAGE}#PushTestResult`,
2725
+ schema: pushTestSchema
2726
+ }
2727
+ }
2728
+ ]
2729
+ };
2730
+ //#endregion
2731
+ //#region src/client/report-mount.ts
2732
+ /** Mount the contribution and resolve the namespace service it installs. */
2733
+ async function mountReportRemote(remote, resolveNamespace) {
2734
+ const dispose = await remote.$mount(REPORT_REMOTE_CONTRIBUTION);
2735
+ const namespace = resolveNamespace();
2736
+ if (namespace === void 0) {
2737
+ await dispose();
2738
+ throw new Error("remote.deeppilot 未注册");
2739
+ }
2740
+ return {
2741
+ namespace,
2742
+ dispose
2743
+ };
2744
+ }
2745
+ //#endregion
2746
+ //#region src/client/index.ts
2747
+ const CSS = [
2748
+ ".pbb-section{max-width:720px;color:var(--dsw-alias-label-primary);display:flex;flex-direction:column;gap:12px}",
2749
+ ".pbb-title{margin:0;font-size:18px;font-weight:600}",
2750
+ ".pbb-intro{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5;margin:0}",
2751
+ ".pbb-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;padding:4px 16px}",
2752
+ ".pbb-field{display:flex;flex-direction:column;gap:6px;padding:12px 0}",
2753
+ ".pbb-field+.pbb-field{border-top:1px solid var(--dsw-alias-border-l2)}",
2754
+ ".pbb-row{display:flex;align-items:center;gap:8px}",
2755
+ ".pbb-label{flex:1;font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary);min-width:0}",
2756
+ ".pbb-value{font-size:13px;color:var(--dsw-alias-label-secondary);word-break:break-all;text-align:right}",
2757
+ ".pbb-badge{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;white-space:nowrap}",
2758
+ ".pbb-ok{color:var(--dsw-alias-state-success-primary,var(--dsw-alias-label-secondary));font-weight:500}",
2759
+ ".pbb-bad{color:var(--dsw-alias-label-error);font-weight:500}",
2760
+ ".pbb-table{width:100%;border-collapse:collapse;font-size:12px}",
2761
+ ".pbb-table th{color:var(--dsw-alias-label-tertiary);text-align:left;font-weight:500;padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l2)}",
2762
+ ".pbb-table td{padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary)}",
2763
+ ".pbb-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:0}",
2764
+ ".pbb-diag{font-size:11px;color:var(--dsw-alias-label-tertiary);margin:0;line-height:1.5}",
2765
+ ".pbb-diagBad{color:var(--dsw-alias-label-error)}",
2766
+ ".pbb-refresh{font:inherit;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:none;border:none;padding:0}",
2767
+ ".pbb-refresh:hover:not(:disabled){color:var(--dsw-alias-label-primary)}",
2768
+ ".pbb-refresh:disabled{cursor:default;opacity:.5}",
2769
+ ".pbb-tokenRow{flex-wrap:wrap}",
2770
+ ".pbb-token{max-width:100%;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-secondary);word-break:break-all}",
2771
+ ".pbb-tokenActions{display:flex;align-items:center;gap:8px}",
2772
+ ".pbb-action{font:inherit;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:none;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;padding:3px 8px}",
2773
+ ".pbb-action:hover:not(:disabled){color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-module-platform)}",
2774
+ ".pbb-action:disabled{cursor:default;opacity:.5}",
2775
+ ".pbb-actionDanger:not(:disabled){color:#fff;background:var(--dsw-alias-label-error);border-color:var(--dsw-alias-label-error)}",
2776
+ ".pbb-qrPanel{display:flex;flex-direction:column;align-items:center;gap:9px;padding:12px 0 4px}",
2777
+ ".pbb-qrImage{width:240px;height:240px;max-width:100%;background:#fff;border-radius:10px;padding:8px;box-sizing:border-box}",
2778
+ ".pbb-qrHint{max-width:420px;text-align:center;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary);margin:0}",
2779
+ ".pbb-switchRow{padding:12px 0;display:flex;align-items:center;gap:12px}",
2780
+ ".pbb-switchRow+.pbb-field{border-top:1px solid var(--dsw-alias-border-l2)}",
2781
+ ".pbb-switchText{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}",
2782
+ ".pbb-switchTitle{font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary)}",
2783
+ ".pbb-dotRow{display:flex;align-items:center;gap:7px}",
2784
+ ".pbb-dot{width:8px;height:8px;border-radius:50%;background:var(--dsw-alias-label-tertiary);flex:none}",
2785
+ ".pbb-dotOk{background:var(--dsw-alias-state-success-primary,#22a06b)}",
2786
+ ".pbb-dotWarn{background:var(--dsw-alias-state-warning-primary,#e2b203)}",
2787
+ ".pbb-dotBad{background:var(--dsw-alias-label-error)}",
2788
+ ".pbb-rowAction{display:flex;gap:8px;margin-top:4px}",
2789
+ ".pbb-switchDesc{font-size:11px;color:var(--dsw-alias-label-tertiary);line-height:1.4}",
2790
+ ".pbb-switch{appearance:none;-webkit-appearance:none;width:38px;height:22px;border-radius:999px;background:var(--dsw-alias-bg-module-platform);border:1px solid var(--dsw-alias-border-l2);position:relative;cursor:pointer;padding:0;flex:none;transition:background .15s ease}",
2791
+ ".pbb-switch::after{content:\"\";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-secondary);transition:transform .15s ease,background .15s ease}",
2792
+ ".pbb-switchOn{background:var(--dsw-alias-state-success-primary,var(--dsw-alias-label-secondary))}",
2793
+ ".pbb-switchOn::after{transform:translateX(16px);background:#fff}",
2794
+ ".pbb-switch:disabled{opacity:.5;cursor:default}",
2795
+ ".pbb-help{border-top:1px solid var(--dsw-alias-border-l2);padding:12px 0}",
2796
+ ".pbb-help summary{cursor:pointer;color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;user-select:none}",
2797
+ ".pbb-help summary:hover{color:var(--dsw-alias-label-secondary)}",
2798
+ ".pbb-helpBody{display:flex;flex-direction:column;gap:14px;padding:12px 0 2px}",
2799
+ ".pbb-helpSection{display:flex;flex-direction:column;gap:6px}",
2800
+ ".pbb-helpHeading{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}",
2801
+ ".pbb-helpList{margin:0;padding-left:20px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.6}",
2802
+ ".pbb-helpList li+li{margin-top:4px}",
2803
+ ".pbb-helpText{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.6}",
2804
+ ".pbb-helpCode{display:block;margin:2px 0 0;padding:10px;overflow:auto;white-space:pre-wrap;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-primary);font:11px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}",
2805
+ ".pbb-helpLink{color:var(--dsw-alias-label-secondary);text-decoration:underline;text-underline-offset:2px}"
2806
+ ].join("\n");
2807
+ function injectCss() {
2808
+ if (typeof document === "undefined") return;
2809
+ if (document.querySelector("style[data-plugin-css=\"dsh-deeppilot/page.css\"]") !== null) return;
2810
+ const tag = document.createElement("style");
2811
+ tag.dataset.plugin = "dsh-deeppilot";
2812
+ tag.textContent = CSS;
2813
+ document.head.appendChild(tag);
2814
+ }
2815
+ async function writeClipboard(value) {
2816
+ try {
2817
+ await navigator.clipboard.writeText(value);
2818
+ return;
2819
+ } catch {}
2820
+ const textarea = document.createElement("textarea");
2821
+ textarea.value = value;
2822
+ textarea.style.position = "fixed";
2823
+ textarea.style.opacity = "0";
2824
+ document.body.appendChild(textarea);
2825
+ textarea.select();
2826
+ const copied = document.execCommand("copy");
2827
+ textarea.remove();
2828
+ if (!copied) throw new Error("浏览器拒绝了剪贴板写入");
2829
+ }
2830
+ /** Polls the report remote and owns the page state transitions. */
2831
+ var ReportController = class {
2832
+ fetchReport;
2833
+ listeners = /* @__PURE__ */ new Set();
2834
+ snap = {
2835
+ status: "loading",
2836
+ report: null,
2837
+ message: ""
2838
+ };
2839
+ constructor(fetchReport) {
2840
+ this.fetchReport = fetchReport;
2841
+ }
2842
+ state() {
2843
+ return this.snap;
2844
+ }
2845
+ subscribe(listener) {
2846
+ this.listeners.add(listener);
2847
+ return () => this.listeners.delete(listener);
2848
+ }
2849
+ dispose() {
2850
+ this.listeners.clear();
2851
+ }
2852
+ async refresh() {
2853
+ try {
2854
+ const report = await this.fetchReport();
2855
+ this.snap = report !== null ? {
2856
+ status: "ready",
2857
+ report,
2858
+ message: ""
2859
+ } : {
2860
+ status: "error",
2861
+ report: null,
2862
+ message: "报告远程未挂载(remote mount 失败)— 请确认宿主包含 typert 组合"
2863
+ };
2864
+ } catch (error) {
2865
+ this.snap = {
2866
+ status: "error",
2867
+ report: null,
2868
+ message: error instanceof Error ? error.message : String(error)
2869
+ };
2870
+ }
2871
+ this.emit();
2872
+ }
2873
+ emit() {
2874
+ for (const listener of [...this.listeners]) try {
2875
+ listener();
2876
+ } catch {}
2877
+ }
2878
+ };
2879
+ const inject = [
2880
+ "slots",
2881
+ "locale",
2882
+ "remote",
2883
+ "settingsScope"
2884
+ ];
2885
+ function apply(ctx) {
2886
+ if (typeof document !== "undefined") injectCss();
2887
+ const anyCtx = ctx;
2888
+ anyCtx.locale?.register("settings.deeppilot", {
2889
+ zh: { nav: "DeepPilot" },
2890
+ en: { nav: "DeepPilot" }
2891
+ });
2892
+ let namespace;
2893
+ let mountError;
2894
+ const fetchReport = async () => {
2895
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2896
+ const result = await namespace.report();
2897
+ if (!result.ok) throw new Error(result.error.message ?? "report remote 调用失败");
2898
+ return result.value;
2899
+ };
2900
+ const controller = new ReportController(fetchReport);
2901
+ ctx.effect(() => () => controller.dispose(), "dsh-deeppilot: report controller");
2902
+ const store = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)(controller.state());
2903
+ controller.subscribe(() => store.set(controller.state()));
2904
+ ctx.effect(() => {
2905
+ let cancelled = false;
2906
+ let unmount;
2907
+ if (anyCtx.remote === void 0) {
2908
+ mountError = "remote 服务不可用";
2909
+ controller.refresh();
2910
+ return () => {};
2911
+ }
2912
+ mountReportRemote(anyCtx.remote, () => ctx.get("remote.deeppilot")).then((mounted) => {
2913
+ if (cancelled) {
2914
+ mounted.dispose();
2915
+ return;
2916
+ }
2917
+ namespace = mounted.namespace;
2918
+ unmount = mounted.dispose;
2919
+ mountError = void 0;
2920
+ controller.refresh();
2921
+ }, (error) => {
2922
+ mountError = error instanceof Error ? error.message : String(error);
2923
+ controller.refresh();
2924
+ });
2925
+ return () => {
2926
+ cancelled = true;
2927
+ namespace = void 0;
2928
+ if (unmount !== void 0) unmount();
2929
+ };
2930
+ }, "dsh-deeppilot: report remote mount");
2931
+ const revealPairingToken = async () => {
2932
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2933
+ const result = await namespace.revealToken();
2934
+ if (!result.ok) throw new Error(result.error.message ?? "Token 读取失败");
2935
+ return result.value;
2936
+ };
2937
+ const sendTestPush = async () => {
2938
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2939
+ if (typeof namespace.testPush !== "function") throw new Error("宿主插件版本较旧,不支持推送测试 — 请更新 dsh-deeppilot");
2940
+ const result = await namespace.testPush();
2941
+ if (!result.ok) throw new Error(result.error.message ?? "推送测试失败");
2942
+ return result.value;
2943
+ };
2944
+ const testRelayConnection = async () => {
2945
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2946
+ if (typeof namespace.testRelay !== "function") throw new Error("宿主插件版本较旧,不支持中继测试 — 请更新 dsh-deeppilot");
2947
+ const result = await namespace.testRelay();
2948
+ if (!result.ok) throw new Error(result.error.message ?? "中继测试失败");
2949
+ return result.value;
2950
+ };
2951
+ const rotatePairingToken = async () => {
2952
+ if (namespace === void 0) throw new Error(mountError !== void 0 ? "remote mount 失败: " + mountError : "report remote 未挂载");
2953
+ const result = await namespace.rotateToken();
2954
+ if (!result.ok) throw new Error(result.error.message ?? "Token 更换失败");
2955
+ return result.value;
2956
+ };
2957
+ const enabledStore = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
2958
+ status: "loading",
2959
+ enabled: true
2960
+ });
2961
+ const scope = anyCtx.settingsScope?.bind({ namespace: "deeppilot" });
2962
+ const adoptEnabled = () => {
2963
+ if (scope === void 0) return;
2964
+ const snap = scope.getSnapshot();
2965
+ if (snap.status === "ready" && snap.value !== void 0) enabledStore.set({
2966
+ status: "ready",
2967
+ enabled: snap.value.enabled !== false
2968
+ });
2969
+ else if (snap.status === "unavailable") enabledStore.set({
2970
+ status: "unavailable",
2971
+ enabled: true
2972
+ });
2973
+ };
2974
+ if (scope !== void 0) {
2975
+ scope.subscribe(adoptEnabled);
2976
+ adoptEnabled();
2977
+ }
2978
+ const setDeepPilotEnabled = (value) => {
2979
+ enabledStore.set({
2980
+ status: "ready",
2981
+ enabled: value
2982
+ });
2983
+ if (scope !== void 0) scope.set("enabled", value);
2984
+ };
2985
+ const remoteEnabledStore = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
2986
+ status: "loading",
2987
+ enabled: false
2988
+ });
2989
+ const adoptRemoteEnabled = () => {
2990
+ if (scope === void 0) return;
2991
+ const snap = scope.getSnapshot();
2992
+ if (snap.status === "ready") remoteEnabledStore.set({
2993
+ status: "ready",
2994
+ enabled: snap.value?.remote?.enabled === true
2995
+ });
2996
+ else if (snap.status === "unavailable") remoteEnabledStore.set({
2997
+ status: "unavailable",
2998
+ enabled: false
2999
+ });
3000
+ };
3001
+ if (scope !== void 0) {
3002
+ scope.subscribe(adoptRemoteEnabled);
3003
+ adoptRemoteEnabled();
3004
+ }
3005
+ const setDeepPilotRemoteEnabled = (value) => {
3006
+ remoteEnabledStore.set({
3007
+ status: "ready",
3008
+ enabled: value
3009
+ });
3010
+ if (scope === void 0) return;
3011
+ const currentRemote = scope.getSnapshot().value?.remote ?? {};
3012
+ scope.set("remote", {
3013
+ ...currentRemote,
3014
+ enabled: value
3015
+ });
3016
+ };
3017
+ anyCtx.slots?.inject("settings.section", () => anyCtx.slots.register({
3018
+ name: "settings.section",
3019
+ id: "deeppilot",
3020
+ order: 13,
3021
+ label: () => {
3022
+ const bind = anyCtx.locale?.bind("settings.deeppilot");
3023
+ return bind ? bind("nav") : "DeepPilot";
3024
+ },
3025
+ locale: "settings.deeppilot",
3026
+ inject: () => ({
3027
+ hooks: {
3028
+ deepPilotReport: store,
3029
+ deepPilotEnabled: enabledStore,
3030
+ deepPilotRemoteEnabled: remoteEnabledStore
3031
+ },
3032
+ refresh: () => {
3033
+ controller.refresh();
3034
+ },
3035
+ revealPairingToken,
3036
+ rotatePairingToken,
3037
+ testRelay: testRelayConnection,
3038
+ testPush: sendTestPush,
3039
+ setDeepPilotEnabled,
3040
+ setDeepPilotRemoteEnabled
3041
+ })
3042
+ }, DeepPilotSettingsPage));
3043
+ }
3044
+ /** Visual state of the embedded Funnel: a colored dot plus its spoken label. */
3045
+ const REMOTE_PHASE_META = {
3046
+ disabled: {
3047
+ dot: "",
3048
+ label: "未启用"
3049
+ },
3050
+ starting: {
3051
+ dot: " pbb-dotWarn",
3052
+ label: "正在启动"
3053
+ },
3054
+ login_required: {
3055
+ dot: " pbb-dotWarn",
3056
+ label: "等待 Tailscale 授权"
3057
+ },
3058
+ online: {
3059
+ dot: " pbb-dotOk",
3060
+ label: "远程连接已就绪"
3061
+ },
3062
+ error: {
3063
+ dot: " pbb-dotBad",
3064
+ label: "远程连接失败"
3065
+ },
3066
+ unavailable: {
3067
+ dot: " pbb-dotBad",
3068
+ label: "远程 helper 不可用"
3069
+ },
3070
+ stopped: {
3071
+ dot: "",
3072
+ label: "已停止"
3073
+ }
3074
+ };
3075
+ /** Slot component: hooks come from the slot renderer, named use<Key>. */
3076
+ function DeepPilotSettingsPage(props) {
3077
+ const [revealedToken, setRevealedToken] = (0, react.useState)(null);
3078
+ const [tokenBusy, setTokenBusy] = (0, react.useState)(false);
3079
+ const [tokenMessage, setTokenMessage] = (0, react.useState)("");
3080
+ const [rotateArmed, setRotateArmed] = (0, react.useState)(false);
3081
+ const [remoteMessage, setRemoteMessage] = (0, react.useState)("");
3082
+ const [qrDataURL, setQRDataURL] = (0, react.useState)(null);
3083
+ const [qrBusy, setQRBusy] = (0, react.useState)(false);
3084
+ const [qrMessage, setQRMessage] = (0, react.useState)("");
3085
+ const [relayTestBusy, setRelayTestBusy] = (0, react.useState)(false);
3086
+ const [relayTestResult, setRelayTestResult] = (0, react.useState)(null);
3087
+ const [relayTestError, setRelayTestError] = (0, react.useState)("");
3088
+ const [pushTestBusy, setPushTestBusy] = (0, react.useState)(false);
3089
+ const [pushTestResult, setPushTestResult] = (0, react.useState)(null);
3090
+ const [pushTestError, setPushTestError] = (0, react.useState)("");
3091
+ (0, react.useEffect)(() => {
3092
+ if (typeof props.refresh !== "function") return;
3093
+ props.refresh();
3094
+ const timer = globalThis.setInterval(() => props.refresh(), 3e3);
3095
+ return () => globalThis.clearInterval(timer);
3096
+ }, [props.refresh]);
3097
+ const sendPushTest = () => {
3098
+ if (pushTestBusy) return;
3099
+ if (typeof props.testPush !== "function") {
3100
+ setPushTestError("宿主插件版本较旧,不支持推送测试");
3101
+ return;
3102
+ }
3103
+ setPushTestBusy(true);
3104
+ setPushTestError("");
3105
+ props.testPush().then((result) => {
3106
+ setPushTestResult(result);
3107
+ setPushTestBusy(false);
3108
+ }, (error) => {
3109
+ setPushTestError(error instanceof Error ? error.message : String(error));
3110
+ setPushTestBusy(false);
3111
+ });
3112
+ };
3113
+ const runRelayTest = () => {
3114
+ if (relayTestBusy) return;
3115
+ if (typeof props.testRelay !== "function") {
3116
+ setRelayTestError("宿主插件版本较旧,不支持中继测试");
3117
+ return;
3118
+ }
3119
+ setRelayTestBusy(true);
3120
+ setRelayTestError("");
3121
+ props.testRelay().then((result) => {
3122
+ setRelayTestResult(result);
3123
+ setRelayTestBusy(false);
3124
+ }, (error) => {
3125
+ setRelayTestError(error instanceof Error ? error.message : String(error));
3126
+ setRelayTestBusy(false);
3127
+ });
3128
+ };
3129
+ (0, react.useEffect)(() => {
3130
+ if (revealedToken === null) return;
3131
+ const timer = globalThis.setTimeout(() => {
3132
+ setRevealedToken(null);
3133
+ setTokenMessage("Token 已自动隐藏");
3134
+ }, 3e4);
3135
+ return () => globalThis.clearTimeout(timer);
3136
+ }, [revealedToken]);
3137
+ (0, react.useEffect)(() => {
3138
+ if (!tokenMessage) return;
3139
+ const timer = globalThis.setTimeout(() => setTokenMessage(""), 4e3);
3140
+ return () => globalThis.clearTimeout(timer);
3141
+ }, [tokenMessage]);
3142
+ (0, react.useEffect)(() => {
3143
+ if (!rotateArmed) return;
3144
+ const timer = globalThis.setTimeout(() => setRotateArmed(false), 5e3);
3145
+ return () => globalThis.clearTimeout(timer);
3146
+ }, [rotateArmed]);
3147
+ (0, react.useEffect)(() => {
3148
+ if (!remoteMessage) return;
3149
+ const timer = globalThis.setTimeout(() => setRemoteMessage(""), 2500);
3150
+ return () => globalThis.clearTimeout(timer);
3151
+ }, [remoteMessage]);
3152
+ (0, react.useEffect)(() => {
3153
+ if (qrDataURL === null) return;
3154
+ const timer = globalThis.setTimeout(() => {
3155
+ setQRDataURL(null);
3156
+ setQRMessage("配对二维码已自动隐藏");
3157
+ }, 6e4);
3158
+ return () => globalThis.clearTimeout(timer);
3159
+ }, [qrDataURL]);
3160
+ (0, react.useEffect)(() => {
3161
+ if (!qrMessage) return;
3162
+ const timer = globalThis.setTimeout(() => setQRMessage(""), 2500);
3163
+ return () => globalThis.clearTimeout(timer);
3164
+ }, [qrMessage]);
3165
+ const diag = [];
3166
+ let report = null;
3167
+ let enabled = true;
3168
+ let switchReady = false;
3169
+ let remoteEnabled = false;
3170
+ let remoteSwitchReady = false;
3171
+ let failed = false;
3172
+ try {
3173
+ if (typeof props.useDeepPilotReport !== "function") {
3174
+ diag.push("useDeepPilotReport hook 缺失");
3175
+ failed = true;
3176
+ } else {
3177
+ const state = props.useDeepPilotReport((s) => s);
3178
+ report = state.report;
3179
+ if (state.status === "error" && state.message) {
3180
+ diag.push(state.message);
3181
+ failed = true;
3182
+ }
3183
+ }
3184
+ if (typeof props.useDeepPilotEnabled === "function") {
3185
+ const state = props.useDeepPilotEnabled((s) => s);
3186
+ enabled = state.enabled;
3187
+ switchReady = state.status === "ready";
3188
+ if (state.status === "unavailable") diag.push("设置命名空间不可用(settingsScope 未提供)");
3189
+ } else diag.push("useDeepPilotEnabled hook 缺失");
3190
+ if (typeof props.refresh !== "function") diag.push("refresh 回调缺失");
3191
+ if (typeof props.revealPairingToken !== "function") diag.push("revealPairingToken 回调缺失");
3192
+ if (typeof props.rotatePairingToken !== "function") diag.push("rotatePairingToken 回调缺失");
3193
+ if (typeof props.testRelay !== "function") diag.push("testRelay 回调缺失");
3194
+ if (typeof props.testPush !== "function") diag.push("testPush 回调缺失");
3195
+ if (typeof props.setDeepPilotEnabled !== "function") diag.push("setDeepPilotEnabled 回调缺失");
3196
+ if (typeof props.useDeepPilotRemoteEnabled === "function") {
3197
+ const state = props.useDeepPilotRemoteEnabled((s) => s);
3198
+ remoteEnabled = state.enabled;
3199
+ remoteSwitchReady = state.status === "ready";
3200
+ } else diag.push("useDeepPilotRemoteEnabled hook 缺失");
3201
+ if (typeof props.setDeepPilotRemoteEnabled !== "function") diag.push("setDeepPilotRemoteEnabled 回调缺失");
3202
+ } catch (error) {
3203
+ diag.push("渲染异常: " + (error instanceof Error ? error.message : String(error)));
3204
+ failed = true;
3205
+ }
3206
+ const pairingTarget = report === null ? null : selectPairingTarget(report.remote, report.lanAddresses, typeof window === "undefined" ? void 0 : window.location.origin);
3207
+ (0, react.useEffect)(() => {
3208
+ setQRDataURL(null);
3209
+ }, [pairingTarget?.host]);
3210
+ const toggleToken = () => {
3211
+ if (revealedToken !== null) {
3212
+ setRevealedToken(null);
3213
+ setTokenMessage("");
3214
+ return;
3215
+ }
3216
+ if (typeof props.revealPairingToken !== "function") return;
3217
+ setTokenBusy(true);
3218
+ setTokenMessage("");
3219
+ props.revealPairingToken().then((token) => {
3220
+ setRevealedToken(token);
3221
+ }, (error) => {
3222
+ setTokenMessage("Token 读取失败:" + (error instanceof Error ? error.message : String(error)));
3223
+ }).finally(() => setTokenBusy(false));
3224
+ };
3225
+ const copyToken = () => {
3226
+ if (typeof props.revealPairingToken !== "function") return;
3227
+ setTokenBusy(true);
3228
+ setTokenMessage("");
3229
+ (revealedToken !== null ? Promise.resolve(revealedToken) : props.revealPairingToken()).then((value) => writeClipboard(value)).then(() => setTokenMessage("已复制到剪贴板"), (error) => {
3230
+ setTokenMessage("复制失败:" + (error instanceof Error ? error.message : String(error)));
3231
+ }).finally(() => setTokenBusy(false));
3232
+ };
3233
+ const rotateToken = () => {
3234
+ if (typeof props.rotatePairingToken !== "function") return;
3235
+ if (!rotateArmed) {
3236
+ setRotateArmed(true);
3237
+ setRevealedToken(null);
3238
+ setQRDataURL(null);
3239
+ setTokenMessage("更换会使当前 Token 立即失效、断开所有手机连接;5 秒内再次点击确认。");
3240
+ return;
3241
+ }
3242
+ setRotateArmed(false);
3243
+ setTokenBusy(true);
3244
+ setTokenMessage("");
3245
+ props.rotatePairingToken().then((token) => {
3246
+ setRevealedToken(token);
3247
+ setTokenMessage("新 Token 已生效,旧 Token 已失效;请重新配对所有设备。");
3248
+ }, (error) => {
3249
+ setTokenMessage("更换失败:" + (error instanceof Error ? error.message : String(error)));
3250
+ }).finally(() => setTokenBusy(false));
3251
+ };
3252
+ const copyRemoteURL = (url) => {
3253
+ setRemoteMessage("");
3254
+ writeClipboard(url).then(() => {
3255
+ setRemoteMessage("公网地址已复制");
3256
+ }, (error) => {
3257
+ setRemoteMessage("复制失败:" + (error instanceof Error ? error.message : String(error)));
3258
+ });
3259
+ };
3260
+ const showPairingQR = () => {
3261
+ if (typeof props.revealPairingToken !== "function" || pairingTarget === null) return;
3262
+ setQRBusy(true);
3263
+ setQRMessage("");
3264
+ setQRDataURL(null);
3265
+ props.revealPairingToken().then((pairingToken) => import_browser.toString(encodePairingQRPayload(pairingTarget.host, pairingToken), {
3266
+ type: "svg",
3267
+ errorCorrectionLevel: "M",
3268
+ margin: 2,
3269
+ width: 512
3270
+ })).then((svg) => setQRDataURL("data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg)), (error) => {
3271
+ setQRMessage("二维码生成失败:" + (error instanceof Error ? error.message : String(error)));
3272
+ }).finally(() => setQRBusy(false));
3273
+ };
3274
+ const primaryRows = [];
3275
+ const advancedRows = [];
3276
+ if (report !== null) {
3277
+ primaryRows.push((0, react.createElement)("div", {
3278
+ className: "pbb-field",
3279
+ key: "conn"
3280
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "当前连接"), (0, react.createElement)("span", { className: "pbb-value" }, String(report.activeConnections)))), (0, react.createElement)("div", {
3281
+ className: "pbb-field",
3282
+ key: "token"
3283
+ }, (0, react.createElement)("div", { className: "pbb-row pbb-tokenRow" }, (0, react.createElement)("span", { className: "pbb-label" }, "配对 Token"), (0, react.createElement)("code", { className: "pbb-token " + (report.tokenReady ? "pbb-ok" : "pbb-bad") }, report.tokenReady ? revealedToken ?? "••••••••••••" : "未生成"), report.tokenReady ? (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("button", {
3284
+ type: "button",
3285
+ className: "pbb-action",
3286
+ disabled: tokenBusy,
3287
+ onClick: toggleToken
3288
+ }, tokenBusy ? "读取中…" : revealedToken === null ? "显示" : "隐藏"), (0, react.createElement)("button", {
3289
+ type: "button",
3290
+ className: "pbb-action",
3291
+ disabled: tokenBusy,
3292
+ onClick: copyToken
3293
+ }, "复制"), (0, react.createElement)("button", {
3294
+ type: "button",
3295
+ className: "pbb-action" + (rotateArmed ? " pbb-actionDanger" : ""),
3296
+ disabled: tokenBusy,
3297
+ onClick: rotateToken
3298
+ }, rotateArmed ? "确认更换?" : tokenBusy ? "更换中…" : "更换")) : null), tokenMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, tokenMessage) : null));
3299
+ advancedRows.push((0, react.createElement)("div", {
3300
+ className: "pbb-field",
3301
+ key: "proto"
3302
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "协议版本"), (0, react.createElement)("span", { className: "pbb-value" }, "v" + String(report.protocolVersion)))), (0, react.createElement)("div", {
3303
+ className: "pbb-field",
3304
+ key: "server"
3305
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "服务器版本"), (0, react.createElement)("span", { className: "pbb-value" }, report.serverVersion))), (0, react.createElement)("div", {
3306
+ className: "pbb-field",
3307
+ key: "path"
3308
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "Token 路径"), (0, react.createElement)("span", { className: "pbb-value" }, report.tokenPath))), (0, react.createElement)("div", {
3309
+ className: "pbb-field",
3310
+ key: "buffer"
3311
+ }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "重放缓冲上限"), (0, react.createElement)("span", { className: "pbb-value" }, String(report.historyBufferMax) + " 帧"))));
3312
+ }
3313
+ const deviceTable = report !== null && report.devices.length > 0 ? (0, react.createElement)("table", { className: "pbb-table" }, (0, react.createElement)("thead", null, (0, react.createElement)("tr", null, (0, react.createElement)("th", null, "设备"), (0, react.createElement)("th", null, "App 版本"), (0, react.createElement)("th", null, "离线推送"), (0, react.createElement)("th", null, "最近在线"))), (0, react.createElement)("tbody", null, report.devices.map((d) => (0, react.createElement)("tr", { key: d.deviceId }, (0, react.createElement)("td", null, d.deviceName), (0, react.createElement)("td", null, d.appVersion), (0, react.createElement)("td", null, d.apns ? "已注册(" + (d.apns.environment === "production" ? "生产" : "开发") + ")" : "未注册"), (0, react.createElement)("td", null, new Date(d.lastSeenTs).toLocaleString()))))) : (0, react.createElement)("p", { className: "pbb-empty" }, "还没有设备配对过。在 iPhone 上的 DeepPilot App 中扫码或填入本机地址与 Token 即可配对。");
3314
+ const switchTitle = "DeepPilot 连接";
3315
+ const switchDesc = switchReady ? enabled ? "已开启:接受手机连接。" : "已关闭:不接受手机连接。" : "正在读取配置…";
3316
+ return (0, react.createElement)("div", { className: "pbb-section" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("h2", { className: "pbb-title" }, "DeepPilot"), (0, react.createElement)("button", {
3317
+ className: "pbb-refresh",
3318
+ onClick: () => {
3319
+ if (typeof props.refresh === "function") props.refresh();
3320
+ }
3321
+ }, "刷新")), (0, react.createElement)("p", { className: "pbb-intro" }, "把 iPhone 与这台电脑上的 DeepSeek Harness(DSH)连接起来(协议 v1)。"), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-switchRow" }, (0, react.createElement)("div", { className: "pbb-switchText" }, (0, react.createElement)("span", { className: "pbb-switchTitle" }, switchTitle), (0, react.createElement)("span", { className: "pbb-switchDesc" }, switchDesc)), (0, react.createElement)("button", {
3322
+ type: "button",
3323
+ role: "switch",
3324
+ "aria-checked": enabled,
3325
+ "aria-label": switchTitle,
3326
+ disabled: !switchReady,
3327
+ className: "pbb-switch" + (enabled ? " pbb-switchOn" : ""),
3328
+ onClick: () => {
3329
+ if (typeof props.setDeepPilotEnabled === "function") props.setDeepPilotEnabled(!enabled);
3330
+ }
3331
+ })), (0, react.createElement)("div", { className: "pbb-switchRow" }, (0, react.createElement)("div", { className: "pbb-switchText" }, (0, react.createElement)("span", { className: "pbb-switchTitle pbb-dotRow" }, (0, react.createElement)("span", {
3332
+ className: "pbb-dot" + (report !== null ? REMOTE_PHASE_META[report.remote.phase].dot : ""),
3333
+ role: "img",
3334
+ "aria-label": report !== null ? REMOTE_PHASE_META[report.remote.phase].label : "状态未知",
3335
+ title: report !== null ? REMOTE_PHASE_META[report.remote.phase].label : void 0
3336
+ }), "远程连接(Tailscale Funnel)"), (0, react.createElement)("span", { className: "pbb-switchDesc" }, remoteSwitchReady ? remoteEnabled ? "已配置:内嵌 Funnel 会自动启动并同步状态。" : "关闭:仅保留局域网连接。" : "正在读取配置…"), report !== null && report.remote.phase === "login_required" && typeof report.remote.authURL === "string" && report.remote.authURL.startsWith("https://") ? (0, react.createElement)("div", { className: "pbb-rowAction" }, (0, react.createElement)("a", {
3337
+ className: "pbb-action",
3338
+ href: report.remote.authURL,
3339
+ target: "_blank",
3340
+ rel: "noreferrer"
3341
+ }, "打开授权页面")) : null, report !== null && report.remote.message && (report.remote.phase === "error" || report.remote.phase === "unavailable") ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, report.remote.message) : null, remoteMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, remoteMessage) : null), (0, react.createElement)("button", {
3342
+ type: "button",
3343
+ role: "switch",
3344
+ "aria-checked": remoteEnabled,
3345
+ "aria-label": "远程连接",
3346
+ disabled: !remoteSwitchReady,
3347
+ className: "pbb-switch" + (remoteEnabled ? " pbb-switchOn" : ""),
3348
+ onClick: () => {
3349
+ if (typeof props.setDeepPilotRemoteEnabled === "function") props.setDeepPilotRemoteEnabled(!remoteEnabled);
3350
+ }
3351
+ })), (0, react.createElement)("details", { className: "pbb-help" }, (0, react.createElement)("summary", null, "远程连接帮助"), (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "推荐设置流程"), (0, react.createElement)("ol", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "先打开“DeepPilot 连接”,再打开“远程连接(Tailscale Funnel)”。"), (0, react.createElement)("li", null, "状态变为“等待 Tailscale 授权”后,点击“打开授权页面”。"), (0, react.createElement)("li", null, "使用有权管理此 Tailnet 的账号登录,并按授权页提示启用 Funnel。通常需要 Owner、Admin 或 Network admin 权限。"), (0, react.createElement)("li", null, "返回此页面并点击“刷新”。远程连接标题旁出现绿点后,即可扫描下方二维码添加手机。")), (0, react.createElement)("p", { className: "pbb-helpText" }, "插件已内嵌 Tailscale 网络组件,这台电脑和手机都不需要另外安装 Tailscale App;但首次启用仍需由 Tailnet 管理员授权。")), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "授权页未自动完成时:开启 HTTPS"), (0, react.createElement)("ol", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "打开 Tailscale 管理后台的 Network → DNS。"), (0, react.createElement)("li", null, "确认 MagicDNS 已开启。"), (0, react.createElement)("li", null, "在 HTTPS Certificates 中点击 Enable HTTPS。")), (0, react.createElement)("p", { className: "pbb-helpText" }, "启用 HTTPS 后,设备的完整域名会写入公开的证书透明度日志。如果设备名包含敏感信息,请先在 Tailscale 中重命名设备。")), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "授权页未自动完成时:允许 Funnel"), (0, react.createElement)("p", { className: "pbb-helpText" }, "打开 Access controls → Definitions,选择 Node attributes。在现有 nodeAttrs 数组中追加下面这一项;不要覆盖已有访问规则,也不要创建第二个 nodeAttrs 顶层字段。"), (0, react.createElement)("code", { className: "pbb-helpCode" }, "\"nodeAttrs\": [\n {\n \"target\": [\"autogroup:member\"],\n \"attr\": [\"funnel\"],\n },\n],"), (0, react.createElement)("p", { className: "pbb-helpText" }, "保存策略后回到本页刷新。公共 DNS 和权限变更可能需要几分钟生效。")), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "常见问题"), (0, react.createElement)("ul", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "提示“HTTPS must be enabled”:完成上面的 HTTPS Certificates 设置。"), (0, react.createElement)("li", null, "提示“Funnel not available”:确认 nodeAttrs 已保存,并且当前节点属于规则的 target。"), (0, react.createElement)("li", null, "已有公网地址但手机超时:等待几分钟后重试,同时确认这台电脑未休眠、DSH 正在运行,再重新扫描最新二维码。"), (0, react.createElement)("li", null, "没有公网地址:检查 Tailscale 授权是否完成,然后点击“刷新”或重启 DSH。"))), (0, react.createElement)("div", { className: "pbb-helpSection" }, (0, react.createElement)("div", { className: "pbb-helpHeading" }, "安全说明"), (0, react.createElement)("ul", { className: "pbb-helpList" }, (0, react.createElement)("li", null, "Funnel 公网地址可从互联网访问,但手机接口仍需要配对 Token。不要分享二维码、Token 或包含它们的截图。"), (0, react.createElement)("li", null, "怀疑 Token 泄露时,点击上方“更换”生成新 Token:旧 Token 立即失效,所有已连接设备会被断开并需要重新配对。"), (0, react.createElement)("li", null, "插件只通过 Funnel 转发 /phone 和 /phone/health,不会新增 3098 端口。"), (0, react.createElement)("li", null, "局域网连接沿用 DSH 的 3080 端口;仅在可信网络中使用,不建议直接把 3080 暴露到公网。"), (0, react.createElement)("li", null, "关闭远程连接开关会停止 Funnel,但不会影响可用的局域网连接。")), (0, react.createElement)("p", { className: "pbb-helpText" }, "更多信息:", (0, react.createElement)("a", {
3352
+ className: "pbb-helpLink",
3353
+ href: "https://tailscale.com/docs/features/tailscale-funnel",
3354
+ target: "_blank",
3355
+ rel: "noreferrer"
3356
+ }, "Tailscale Funnel 官方文档")))))), report === null ? null : (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "扫码添加当前手机"), pairingTarget === null ? (0, react.createElement)("span", { className: "pbb-value pbb-bad" }, "没有可用地址") : (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("span", { className: "pbb-badge" }, pairingTarget.kind === "public" ? "公网" : "内网"), (0, react.createElement)("button", {
3357
+ type: "button",
3358
+ className: "pbb-action",
3359
+ disabled: qrBusy || !report.tokenReady,
3360
+ onClick: () => {
3361
+ if (qrDataURL === null) showPairingQR();
3362
+ else setQRDataURL(null);
3363
+ }
3364
+ }, qrBusy ? "生成中…" : qrDataURL === null ? "显示二维码" : "隐藏二维码"))), pairingTarget === null ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, "未发现可供手机访问的局域网地址,请确认这台电脑已连接局域网。") : null, qrMessage ? (0, react.createElement)("p", { className: "pbb-diag" }, qrMessage) : null, pairingTarget === null || qrDataURL === null ? null : (0, react.createElement)("div", { className: "pbb-qrPanel" }, (0, react.createElement)("img", {
3365
+ className: "pbb-qrImage",
3366
+ src: qrDataURL,
3367
+ alt: "DeepPilot 配对二维码"
3368
+ }), (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("code", { className: "pbb-token" }, pairingTarget.host), (0, react.createElement)("button", {
3369
+ type: "button",
3370
+ className: "pbb-action",
3371
+ onClick: () => copyRemoteURL(pairingTarget.host)
3372
+ }, "复制")), (0, react.createElement)("p", { className: "pbb-qrHint" }, `二维码包含${pairingTarget.kind === "public" ? "公网" : "内网"}地址和配对 Token,将在 60 秒后自动隐藏。`)))), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, primaryRows, advancedRows.length > 0 ? (0, react.createElement)("details", { className: "pbb-help" }, (0, react.createElement)("summary", null, "高级信息"), (0, react.createElement)("div", { className: "pbb-helpBody" }, advancedRows)) : null)), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "离线推送中继"), (0, react.createElement)("span", { className: "pbb-tokenActions" }, (0, react.createElement)("button", {
3373
+ type: "button",
3374
+ className: "pbb-action",
3375
+ disabled: relayTestBusy,
3376
+ onClick: runRelayTest
3377
+ }, relayTestBusy ? "测试中…" : "测试访问与注册"), (0, react.createElement)("button", {
3378
+ type: "button",
3379
+ className: "pbb-action",
3380
+ disabled: pushTestBusy,
3381
+ onClick: sendPushTest
3382
+ }, pushTestBusy ? "发送中…" : "发送测试通知"))), relayTestError ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, relayTestError) : null, relayTestResult === null ? (0, react.createElement)("p", { className: "pbb-diag" }, "验证 Mac 到推送中继的连通性与自动注册是否正常。") : (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, relayTestResult.url || "(未启用)"), (0, react.createElement)("code", { className: "pbb-token " + (relayTestResult.overall === "ok" ? "pbb-ok" : "pbb-bad") }, relayTestResult.overall === "ok" ? "通过" : "存在问题")), relayTestResult.steps.map((step, index) => (0, react.createElement)("p", {
3383
+ className: "pbb-diag",
3384
+ key: String(index)
3385
+ }, (step.ok ? "✓ " : "✗ ") + (step.id === "health" ? "服务可达" : "自动注册") + (step.latencyMs !== void 0 ? ` (${String(step.latencyMs)}ms)` : "") + " — " + step.message))), pushTestError ? (0, react.createElement)("p", { className: "pbb-diag pbb-diagBad" }, pushTestError) : null, pushTestResult === null ? (0, react.createElement)("p", { className: "pbb-diag" }, "向所有已注册设备强制发送一条真实推送(不受在线状态与分类开关影响)。") : (0, react.createElement)("div", { className: "pbb-helpBody" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("code", { className: "pbb-token " + (pushTestResult.overall === "sent" ? "pbb-ok" : pushTestResult.overall === "failed" ? "pbb-bad" : "") }, pushTestResult.overall === "sent" ? "已送达" : pushTestResult.overall === "failed" ? "发送失败" : pushTestResult.overall === "no-targets" ? "无已注册设备" : "推送未启用")), pushTestResult.message ? (0, react.createElement)("p", { className: "pbb-diag" }, pushTestResult.message) : null, pushTestResult.results.map((r, index) => (0, react.createElement)("p", {
3386
+ className: "pbb-diag",
3387
+ key: String(index)
3388
+ }, (r.outcome === "sent" ? "✓ " : "✗ ") + r.name + " [" + r.environment + "] — " + r.outcome + (r.reason ? "(" + r.reason + ")" : "") + (r.tokenFingerprint ? " token:" + r.tokenFingerprint + "…" : "")))))), (0, react.createElement)("div", { className: "pbb-card" }, (0, react.createElement)("div", { className: "pbb-field" }, (0, react.createElement)("div", { className: "pbb-row" }, (0, react.createElement)("span", { className: "pbb-label" }, "已配对设备"), (0, react.createElement)("span", { className: "pbb-badge" }, String(report !== null ? report.devices.length : 0))), deviceTable)), diag.length > 0 ? (0, react.createElement)("p", { className: "pbb-diag" + (failed ? " pbb-diagBad" : "") }, "diag: " + diag.join(" | ")) : null);
3389
+ }
3390
+ //#endregion
3391
+ exports.DeepPilotSettingsPage = DeepPilotSettingsPage;
3392
+ exports.apply = apply;
3393
+ exports.inject = inject;
3394
+ return module.exports;
3395
+ }
3396
+ });
3397
+
3398
+ //# sourceMappingURL=client.js.map