@linxin666/dsh-remote-bridge 0.0.0-stage → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +202 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +277 -2
  4. package/README.zh.md +276 -0
  5. package/cordis.patch.yml +17 -0
  6. package/icon.svg +3 -0
  7. package/lib/client.js +1830 -0
  8. package/lib/client.js.map +1 -0
  9. package/lib/index.js +5789 -0
  10. package/lib/types/client/PairEntry.d.ts +16 -0
  11. package/lib/types/client/PairPanel.d.ts +55 -0
  12. package/lib/types/client/icons.d.ts +18 -0
  13. package/lib/types/client/index.d.ts +35 -0
  14. package/lib/types/client/locales.d.ts +42 -0
  15. package/lib/types/client/pair-token.d.ts +73 -0
  16. package/lib/types/client/semantic.d.ts +28 -0
  17. package/lib/types/core/approvals.d.ts +99 -0
  18. package/lib/types/core/connection.d.ts +170 -0
  19. package/lib/types/core/crypto.d.ts +48 -0
  20. package/lib/types/core/delta.d.ts +101 -0
  21. package/lib/types/core/devices.d.ts +72 -0
  22. package/lib/types/core/dsh-frames.d.ts +332 -0
  23. package/lib/types/core/envelope.d.ts +132 -0
  24. package/lib/types/core/extension.d.ts +144 -0
  25. package/lib/types/core/gateway-errors.d.ts +49 -0
  26. package/lib/types/core/hub.d.ts +127 -0
  27. package/lib/types/core/jobs.d.ts +204 -0
  28. package/lib/types/core/loopback.d.ts +35 -0
  29. package/lib/types/core/owner-peer.d.ts +49 -0
  30. package/lib/types/core/pairing.d.ts +61 -0
  31. package/lib/types/core/protocol.d.ts +319 -0
  32. package/lib/types/core/questions.d.ts +294 -0
  33. package/lib/types/core/session-meta.d.ts +105 -0
  34. package/lib/types/core/session-permissions.d.ts +134 -0
  35. package/lib/types/core/wire.d.ts +115 -0
  36. package/lib/types/core/ws-frames.d.ts +72 -0
  37. package/lib/types/host/dsh-home.d.ts +16 -0
  38. package/lib/types/host/pair-origin.d.ts +44 -0
  39. package/lib/types/host/routes.d.ts +27 -0
  40. package/lib/types/host/websocket.d.ts +111 -0
  41. package/lib/types/index.d.ts +55 -0
  42. package/lib/types/mount-once.d.ts +55 -0
  43. package/locale/en.json +6 -0
  44. package/locale/ru.json +6 -0
  45. package/locale/zh.json +6 -0
  46. package/package.json +93 -3
  47. package/src/client/PairEntry.tsx +151 -0
  48. package/src/client/PairPanel.tsx +183 -0
  49. package/src/client/icons.tsx +72 -0
  50. package/src/client/index.ts +81 -0
  51. package/src/client/locales.ts +72 -0
  52. package/src/client/pair-token.ts +104 -0
  53. package/src/client/panel.module.css +344 -0
  54. package/src/client/semantic.ts +37 -0
  55. package/src/core/approvals.ts +173 -0
  56. package/src/core/connection.ts +1906 -0
  57. package/src/core/crypto.ts +113 -0
  58. package/src/core/delta.ts +204 -0
  59. package/src/core/devices.ts +209 -0
  60. package/src/core/dsh-frames.ts +843 -0
  61. package/src/core/envelope.ts +219 -0
  62. package/src/core/extension.ts +197 -0
  63. package/src/core/gateway-errors.ts +92 -0
  64. package/src/core/hub.ts +310 -0
  65. package/src/core/jobs.ts +372 -0
  66. package/src/core/loopback.ts +60 -0
  67. package/src/core/owner-peer.ts +70 -0
  68. package/src/core/pairing.ts +113 -0
  69. package/src/core/protocol.ts +381 -0
  70. package/src/core/questions.ts +630 -0
  71. package/src/core/session-meta.ts +176 -0
  72. package/src/core/session-permissions.ts +266 -0
  73. package/src/core/wire.ts +159 -0
  74. package/src/core/ws-frames.ts +139 -0
  75. package/src/css-modules.d.ts +6 -0
  76. package/src/host/dsh-home.ts +42 -0
  77. package/src/host/pair-origin.ts +77 -0
  78. package/src/host/routes.ts +85 -0
  79. package/src/host/websocket.ts +359 -0
  80. package/src/index.ts +257 -0
  81. package/src/mount-once.ts +142 -0
package/lib/client.js ADDED
@@ -0,0 +1,1830 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@linxin666/dsh-remote-bridge",
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$1 = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
16
+ key = keys[i];
17
+ if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$1(to, key, {
18
+ get: ((k) => from[k]).bind(null, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ //#endregion
29
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
30
+ let react = require("react");
31
+ react = __toESM(react, 1);
32
+ let react_dom = require("react-dom");
33
+ let react_jsx_runtime = require("react/jsx-runtime");
34
+ //#region ../../node_modules/.pnpm/qrcode.react@4.2.0_react@18.3.1/node_modules/qrcode.react/lib/esm/index.js
35
+ var __defProp = Object.defineProperty;
36
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
37
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
38
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
39
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value
44
+ }) : obj[key] = value;
45
+ var __spreadValues = (a, b) => {
46
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
47
+ if (__getOwnPropSymbols) {
48
+ for (var prop of __getOwnPropSymbols(b)) if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
49
+ }
50
+ return a;
51
+ };
52
+ var __objRest = (source, exclude) => {
53
+ var target = {};
54
+ for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
55
+ if (source != null && __getOwnPropSymbols) {
56
+ for (var prop of __getOwnPropSymbols(source)) if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop];
57
+ }
58
+ return target;
59
+ };
60
+ /**
61
+ * @license QR Code generator library (TypeScript)
62
+ * Copyright (c) Project Nayuki.
63
+ * SPDX-License-Identifier: MIT
64
+ */
65
+ var qrcodegen;
66
+ ((qrcodegen2) => {
67
+ const _QrCode = class _QrCode {
68
+ constructor(version, errorCorrectionLevel, dataCodewords, msk) {
69
+ this.version = version;
70
+ this.errorCorrectionLevel = errorCorrectionLevel;
71
+ this.modules = [];
72
+ this.isFunction = [];
73
+ if (version < _QrCode.MIN_VERSION || version > _QrCode.MAX_VERSION) throw new RangeError("Version value out of range");
74
+ if (msk < -1 || msk > 7) throw new RangeError("Mask value out of range");
75
+ this.size = version * 4 + 17;
76
+ let row = [];
77
+ for (let i = 0; i < this.size; i++) row.push(false);
78
+ for (let i = 0; i < this.size; i++) {
79
+ this.modules.push(row.slice());
80
+ this.isFunction.push(row.slice());
81
+ }
82
+ this.drawFunctionPatterns();
83
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
84
+ this.drawCodewords(allCodewords);
85
+ if (msk == -1) {
86
+ let minPenalty = 1e9;
87
+ for (let i = 0; i < 8; i++) {
88
+ this.applyMask(i);
89
+ this.drawFormatBits(i);
90
+ const penalty = this.getPenaltyScore();
91
+ if (penalty < minPenalty) {
92
+ msk = i;
93
+ minPenalty = penalty;
94
+ }
95
+ this.applyMask(i);
96
+ }
97
+ }
98
+ assert(0 <= msk && msk <= 7);
99
+ this.mask = msk;
100
+ this.applyMask(msk);
101
+ this.drawFormatBits(msk);
102
+ this.isFunction = [];
103
+ }
104
+ static encodeText(text, ecl) {
105
+ const segs = qrcodegen2.QrSegment.makeSegments(text);
106
+ return _QrCode.encodeSegments(segs, ecl);
107
+ }
108
+ static encodeBinary(data, ecl) {
109
+ const seg = qrcodegen2.QrSegment.makeBytes(data);
110
+ return _QrCode.encodeSegments([seg], ecl);
111
+ }
112
+ static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
113
+ if (!(_QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode.MAX_VERSION) || mask < -1 || mask > 7) throw new RangeError("Invalid value");
114
+ let version;
115
+ let dataUsedBits;
116
+ for (version = minVersion;; version++) {
117
+ const dataCapacityBits2 = _QrCode.getNumDataCodewords(version, ecl) * 8;
118
+ const usedBits = QrSegment.getTotalBits(segs, version);
119
+ if (usedBits <= dataCapacityBits2) {
120
+ dataUsedBits = usedBits;
121
+ break;
122
+ }
123
+ if (version >= maxVersion) throw new RangeError("Data too long");
124
+ }
125
+ for (const newEcl of [
126
+ _QrCode.Ecc.MEDIUM,
127
+ _QrCode.Ecc.QUARTILE,
128
+ _QrCode.Ecc.HIGH
129
+ ]) if (boostEcl && dataUsedBits <= _QrCode.getNumDataCodewords(version, newEcl) * 8) ecl = newEcl;
130
+ let bb = [];
131
+ for (const seg of segs) {
132
+ appendBits(seg.mode.modeBits, 4, bb);
133
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
134
+ for (const b of seg.getData()) bb.push(b);
135
+ }
136
+ assert(bb.length == dataUsedBits);
137
+ const dataCapacityBits = _QrCode.getNumDataCodewords(version, ecl) * 8;
138
+ assert(bb.length <= dataCapacityBits);
139
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
140
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
141
+ assert(bb.length % 8 == 0);
142
+ for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 253) appendBits(padByte, 8, bb);
143
+ let dataCodewords = [];
144
+ while (dataCodewords.length * 8 < bb.length) dataCodewords.push(0);
145
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
146
+ return new _QrCode(version, ecl, dataCodewords, mask);
147
+ }
148
+ getModule(x, y) {
149
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
150
+ }
151
+ getModules() {
152
+ return this.modules;
153
+ }
154
+ drawFunctionPatterns() {
155
+ for (let i = 0; i < this.size; i++) {
156
+ this.setFunctionModule(6, i, i % 2 == 0);
157
+ this.setFunctionModule(i, 6, i % 2 == 0);
158
+ }
159
+ this.drawFinderPattern(3, 3);
160
+ this.drawFinderPattern(this.size - 4, 3);
161
+ this.drawFinderPattern(3, this.size - 4);
162
+ const alignPatPos = this.getAlignmentPatternPositions();
163
+ const numAlign = alignPatPos.length;
164
+ for (let i = 0; i < numAlign; i++) for (let j = 0; j < numAlign; j++) if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0)) this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
165
+ this.drawFormatBits(0);
166
+ this.drawVersion();
167
+ }
168
+ drawFormatBits(mask) {
169
+ const data = this.errorCorrectionLevel.formatBits << 3 | mask;
170
+ let rem = data;
171
+ for (let i = 0; i < 10; i++) rem = rem << 1 ^ (rem >>> 9) * 1335;
172
+ const bits = (data << 10 | rem) ^ 21522;
173
+ assert(bits >>> 15 == 0);
174
+ for (let i = 0; i <= 5; i++) this.setFunctionModule(8, i, getBit(bits, i));
175
+ this.setFunctionModule(8, 7, getBit(bits, 6));
176
+ this.setFunctionModule(8, 8, getBit(bits, 7));
177
+ this.setFunctionModule(7, 8, getBit(bits, 8));
178
+ for (let i = 9; i < 15; i++) this.setFunctionModule(14 - i, 8, getBit(bits, i));
179
+ for (let i = 0; i < 8; i++) this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
180
+ for (let i = 8; i < 15; i++) this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
181
+ this.setFunctionModule(8, this.size - 8, true);
182
+ }
183
+ drawVersion() {
184
+ if (this.version < 7) return;
185
+ let rem = this.version;
186
+ for (let i = 0; i < 12; i++) rem = rem << 1 ^ (rem >>> 11) * 7973;
187
+ const bits = this.version << 12 | rem;
188
+ assert(bits >>> 18 == 0);
189
+ for (let i = 0; i < 18; i++) {
190
+ const color = getBit(bits, i);
191
+ const a = this.size - 11 + i % 3;
192
+ const b = Math.floor(i / 3);
193
+ this.setFunctionModule(a, b, color);
194
+ this.setFunctionModule(b, a, color);
195
+ }
196
+ }
197
+ drawFinderPattern(x, y) {
198
+ for (let dy = -4; dy <= 4; dy++) for (let dx = -4; dx <= 4; dx++) {
199
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
200
+ const xx = x + dx;
201
+ const yy = y + dy;
202
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size) this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
203
+ }
204
+ }
205
+ drawAlignmentPattern(x, y) {
206
+ for (let dy = -2; dy <= 2; dy++) for (let dx = -2; dx <= 2; dx++) this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
207
+ }
208
+ setFunctionModule(x, y, isDark) {
209
+ this.modules[y][x] = isDark;
210
+ this.isFunction[y][x] = true;
211
+ }
212
+ addEccAndInterleave(data) {
213
+ const ver = this.version;
214
+ const ecl = this.errorCorrectionLevel;
215
+ if (data.length != _QrCode.getNumDataCodewords(ver, ecl)) throw new RangeError("Invalid argument");
216
+ const numBlocks = _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
217
+ const blockEccLen = _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
218
+ const rawCodewords = Math.floor(_QrCode.getNumRawDataModules(ver) / 8);
219
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
220
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
221
+ let blocks = [];
222
+ const rsDiv = _QrCode.reedSolomonComputeDivisor(blockEccLen);
223
+ for (let i = 0, k = 0; i < numBlocks; i++) {
224
+ let dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
225
+ k += dat.length;
226
+ const ecc = _QrCode.reedSolomonComputeRemainder(dat, rsDiv);
227
+ if (i < numShortBlocks) dat.push(0);
228
+ blocks.push(dat.concat(ecc));
229
+ }
230
+ let result = [];
231
+ for (let i = 0; i < blocks[0].length; i++) blocks.forEach((block, j) => {
232
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks) result.push(block[i]);
233
+ });
234
+ assert(result.length == rawCodewords);
235
+ return result;
236
+ }
237
+ drawCodewords(data) {
238
+ if (data.length != Math.floor(_QrCode.getNumRawDataModules(this.version) / 8)) throw new RangeError("Invalid argument");
239
+ let i = 0;
240
+ for (let right = this.size - 1; right >= 1; right -= 2) {
241
+ if (right == 6) right = 5;
242
+ for (let vert = 0; vert < this.size; vert++) for (let j = 0; j < 2; j++) {
243
+ const x = right - j;
244
+ const y = (right + 1 & 2) == 0 ? this.size - 1 - vert : vert;
245
+ if (!this.isFunction[y][x] && i < data.length * 8) {
246
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
247
+ i++;
248
+ }
249
+ }
250
+ }
251
+ assert(i == data.length * 8);
252
+ }
253
+ applyMask(mask) {
254
+ if (mask < 0 || mask > 7) throw new RangeError("Mask value out of range");
255
+ for (let y = 0; y < this.size; y++) for (let x = 0; x < this.size; x++) {
256
+ let invert;
257
+ switch (mask) {
258
+ case 0:
259
+ invert = (x + y) % 2 == 0;
260
+ break;
261
+ case 1:
262
+ invert = y % 2 == 0;
263
+ break;
264
+ case 2:
265
+ invert = x % 3 == 0;
266
+ break;
267
+ case 3:
268
+ invert = (x + y) % 3 == 0;
269
+ break;
270
+ case 4:
271
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
272
+ break;
273
+ case 5:
274
+ invert = x * y % 2 + x * y % 3 == 0;
275
+ break;
276
+ case 6:
277
+ invert = (x * y % 2 + x * y % 3) % 2 == 0;
278
+ break;
279
+ case 7:
280
+ invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
281
+ break;
282
+ default: throw new Error("Unreachable");
283
+ }
284
+ if (!this.isFunction[y][x] && invert) this.modules[y][x] = !this.modules[y][x];
285
+ }
286
+ }
287
+ getPenaltyScore() {
288
+ let result = 0;
289
+ for (let y = 0; y < this.size; y++) {
290
+ let runColor = false;
291
+ let runX = 0;
292
+ let runHistory = [
293
+ 0,
294
+ 0,
295
+ 0,
296
+ 0,
297
+ 0,
298
+ 0,
299
+ 0
300
+ ];
301
+ for (let x = 0; x < this.size; x++) if (this.modules[y][x] == runColor) {
302
+ runX++;
303
+ if (runX == 5) result += _QrCode.PENALTY_N1;
304
+ else if (runX > 5) result++;
305
+ } else {
306
+ this.finderPenaltyAddHistory(runX, runHistory);
307
+ if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
308
+ runColor = this.modules[y][x];
309
+ runX = 1;
310
+ }
311
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode.PENALTY_N3;
312
+ }
313
+ for (let x = 0; x < this.size; x++) {
314
+ let runColor = false;
315
+ let runY = 0;
316
+ let runHistory = [
317
+ 0,
318
+ 0,
319
+ 0,
320
+ 0,
321
+ 0,
322
+ 0,
323
+ 0
324
+ ];
325
+ for (let y = 0; y < this.size; y++) if (this.modules[y][x] == runColor) {
326
+ runY++;
327
+ if (runY == 5) result += _QrCode.PENALTY_N1;
328
+ else if (runY > 5) result++;
329
+ } else {
330
+ this.finderPenaltyAddHistory(runY, runHistory);
331
+ if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
332
+ runColor = this.modules[y][x];
333
+ runY = 1;
334
+ }
335
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode.PENALTY_N3;
336
+ }
337
+ for (let y = 0; y < this.size - 1; y++) for (let x = 0; x < this.size - 1; x++) {
338
+ const color = this.modules[y][x];
339
+ if (color == this.modules[y][x + 1] && color == this.modules[y + 1][x] && color == this.modules[y + 1][x + 1]) result += _QrCode.PENALTY_N2;
340
+ }
341
+ let dark = 0;
342
+ for (const row of this.modules) dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
343
+ const total = this.size * this.size;
344
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
345
+ assert(0 <= k && k <= 9);
346
+ result += k * _QrCode.PENALTY_N4;
347
+ assert(0 <= result && result <= 2568888);
348
+ return result;
349
+ }
350
+ getAlignmentPatternPositions() {
351
+ if (this.version == 1) return [];
352
+ else {
353
+ const numAlign = Math.floor(this.version / 7) + 2;
354
+ const step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
355
+ let result = [6];
356
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step) result.splice(1, 0, pos);
357
+ return result;
358
+ }
359
+ }
360
+ static getNumRawDataModules(ver) {
361
+ if (ver < _QrCode.MIN_VERSION || ver > _QrCode.MAX_VERSION) throw new RangeError("Version number out of range");
362
+ let result = (16 * ver + 128) * ver + 64;
363
+ if (ver >= 2) {
364
+ const numAlign = Math.floor(ver / 7) + 2;
365
+ result -= (25 * numAlign - 10) * numAlign - 55;
366
+ if (ver >= 7) result -= 36;
367
+ }
368
+ assert(208 <= result && result <= 29648);
369
+ return result;
370
+ }
371
+ static getNumDataCodewords(ver, ecl) {
372
+ return Math.floor(_QrCode.getNumRawDataModules(ver) / 8) - _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
373
+ }
374
+ static reedSolomonComputeDivisor(degree) {
375
+ if (degree < 1 || degree > 255) throw new RangeError("Degree out of range");
376
+ let result = [];
377
+ for (let i = 0; i < degree - 1; i++) result.push(0);
378
+ result.push(1);
379
+ let root = 1;
380
+ for (let i = 0; i < degree; i++) {
381
+ for (let j = 0; j < result.length; j++) {
382
+ result[j] = _QrCode.reedSolomonMultiply(result[j], root);
383
+ if (j + 1 < result.length) result[j] ^= result[j + 1];
384
+ }
385
+ root = _QrCode.reedSolomonMultiply(root, 2);
386
+ }
387
+ return result;
388
+ }
389
+ static reedSolomonComputeRemainder(data, divisor) {
390
+ let result = divisor.map((_) => 0);
391
+ for (const b of data) {
392
+ const factor = b ^ result.shift();
393
+ result.push(0);
394
+ divisor.forEach((coef, i) => result[i] ^= _QrCode.reedSolomonMultiply(coef, factor));
395
+ }
396
+ return result;
397
+ }
398
+ static reedSolomonMultiply(x, y) {
399
+ if (x >>> 8 != 0 || y >>> 8 != 0) throw new RangeError("Byte out of range");
400
+ let z = 0;
401
+ for (let i = 7; i >= 0; i--) {
402
+ z = z << 1 ^ (z >>> 7) * 285;
403
+ z ^= (y >>> i & 1) * x;
404
+ }
405
+ assert(z >>> 8 == 0);
406
+ return z;
407
+ }
408
+ finderPenaltyCountPatterns(runHistory) {
409
+ const n = runHistory[1];
410
+ assert(n <= this.size * 3);
411
+ const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
412
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
413
+ }
414
+ finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
415
+ if (currentRunColor) {
416
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
417
+ currentRunLength = 0;
418
+ }
419
+ currentRunLength += this.size;
420
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
421
+ return this.finderPenaltyCountPatterns(runHistory);
422
+ }
423
+ finderPenaltyAddHistory(currentRunLength, runHistory) {
424
+ if (runHistory[0] == 0) currentRunLength += this.size;
425
+ runHistory.pop();
426
+ runHistory.unshift(currentRunLength);
427
+ }
428
+ };
429
+ _QrCode.MIN_VERSION = 1;
430
+ _QrCode.MAX_VERSION = 40;
431
+ _QrCode.PENALTY_N1 = 3;
432
+ _QrCode.PENALTY_N2 = 3;
433
+ _QrCode.PENALTY_N3 = 40;
434
+ _QrCode.PENALTY_N4 = 10;
435
+ _QrCode.ECC_CODEWORDS_PER_BLOCK = [
436
+ [
437
+ -1,
438
+ 7,
439
+ 10,
440
+ 15,
441
+ 20,
442
+ 26,
443
+ 18,
444
+ 20,
445
+ 24,
446
+ 30,
447
+ 18,
448
+ 20,
449
+ 24,
450
+ 26,
451
+ 30,
452
+ 22,
453
+ 24,
454
+ 28,
455
+ 30,
456
+ 28,
457
+ 28,
458
+ 28,
459
+ 28,
460
+ 30,
461
+ 30,
462
+ 26,
463
+ 28,
464
+ 30,
465
+ 30,
466
+ 30,
467
+ 30,
468
+ 30,
469
+ 30,
470
+ 30,
471
+ 30,
472
+ 30,
473
+ 30,
474
+ 30,
475
+ 30,
476
+ 30,
477
+ 30
478
+ ],
479
+ [
480
+ -1,
481
+ 10,
482
+ 16,
483
+ 26,
484
+ 18,
485
+ 24,
486
+ 16,
487
+ 18,
488
+ 22,
489
+ 22,
490
+ 26,
491
+ 30,
492
+ 22,
493
+ 22,
494
+ 24,
495
+ 24,
496
+ 28,
497
+ 28,
498
+ 26,
499
+ 26,
500
+ 26,
501
+ 26,
502
+ 28,
503
+ 28,
504
+ 28,
505
+ 28,
506
+ 28,
507
+ 28,
508
+ 28,
509
+ 28,
510
+ 28,
511
+ 28,
512
+ 28,
513
+ 28,
514
+ 28,
515
+ 28,
516
+ 28,
517
+ 28,
518
+ 28,
519
+ 28,
520
+ 28
521
+ ],
522
+ [
523
+ -1,
524
+ 13,
525
+ 22,
526
+ 18,
527
+ 26,
528
+ 18,
529
+ 24,
530
+ 18,
531
+ 22,
532
+ 20,
533
+ 24,
534
+ 28,
535
+ 26,
536
+ 24,
537
+ 20,
538
+ 30,
539
+ 24,
540
+ 28,
541
+ 28,
542
+ 26,
543
+ 30,
544
+ 28,
545
+ 30,
546
+ 30,
547
+ 30,
548
+ 30,
549
+ 28,
550
+ 30,
551
+ 30,
552
+ 30,
553
+ 30,
554
+ 30,
555
+ 30,
556
+ 30,
557
+ 30,
558
+ 30,
559
+ 30,
560
+ 30,
561
+ 30,
562
+ 30,
563
+ 30
564
+ ],
565
+ [
566
+ -1,
567
+ 17,
568
+ 28,
569
+ 22,
570
+ 16,
571
+ 22,
572
+ 28,
573
+ 26,
574
+ 26,
575
+ 24,
576
+ 28,
577
+ 24,
578
+ 28,
579
+ 22,
580
+ 24,
581
+ 24,
582
+ 30,
583
+ 28,
584
+ 28,
585
+ 26,
586
+ 28,
587
+ 30,
588
+ 24,
589
+ 30,
590
+ 30,
591
+ 30,
592
+ 30,
593
+ 30,
594
+ 30,
595
+ 30,
596
+ 30,
597
+ 30,
598
+ 30,
599
+ 30,
600
+ 30,
601
+ 30,
602
+ 30,
603
+ 30,
604
+ 30,
605
+ 30,
606
+ 30
607
+ ]
608
+ ];
609
+ _QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
610
+ [
611
+ -1,
612
+ 1,
613
+ 1,
614
+ 1,
615
+ 1,
616
+ 1,
617
+ 2,
618
+ 2,
619
+ 2,
620
+ 2,
621
+ 4,
622
+ 4,
623
+ 4,
624
+ 4,
625
+ 4,
626
+ 6,
627
+ 6,
628
+ 6,
629
+ 6,
630
+ 7,
631
+ 8,
632
+ 8,
633
+ 9,
634
+ 9,
635
+ 10,
636
+ 12,
637
+ 12,
638
+ 12,
639
+ 13,
640
+ 14,
641
+ 15,
642
+ 16,
643
+ 17,
644
+ 18,
645
+ 19,
646
+ 19,
647
+ 20,
648
+ 21,
649
+ 22,
650
+ 24,
651
+ 25
652
+ ],
653
+ [
654
+ -1,
655
+ 1,
656
+ 1,
657
+ 1,
658
+ 2,
659
+ 2,
660
+ 4,
661
+ 4,
662
+ 4,
663
+ 5,
664
+ 5,
665
+ 5,
666
+ 8,
667
+ 9,
668
+ 9,
669
+ 10,
670
+ 10,
671
+ 11,
672
+ 13,
673
+ 14,
674
+ 16,
675
+ 17,
676
+ 17,
677
+ 18,
678
+ 20,
679
+ 21,
680
+ 23,
681
+ 25,
682
+ 26,
683
+ 28,
684
+ 29,
685
+ 31,
686
+ 33,
687
+ 35,
688
+ 37,
689
+ 38,
690
+ 40,
691
+ 43,
692
+ 45,
693
+ 47,
694
+ 49
695
+ ],
696
+ [
697
+ -1,
698
+ 1,
699
+ 1,
700
+ 2,
701
+ 2,
702
+ 4,
703
+ 4,
704
+ 6,
705
+ 6,
706
+ 8,
707
+ 8,
708
+ 8,
709
+ 10,
710
+ 12,
711
+ 16,
712
+ 12,
713
+ 17,
714
+ 16,
715
+ 18,
716
+ 21,
717
+ 20,
718
+ 23,
719
+ 23,
720
+ 25,
721
+ 27,
722
+ 29,
723
+ 34,
724
+ 34,
725
+ 35,
726
+ 38,
727
+ 40,
728
+ 43,
729
+ 45,
730
+ 48,
731
+ 51,
732
+ 53,
733
+ 56,
734
+ 59,
735
+ 62,
736
+ 65,
737
+ 68
738
+ ],
739
+ [
740
+ -1,
741
+ 1,
742
+ 1,
743
+ 2,
744
+ 4,
745
+ 4,
746
+ 4,
747
+ 5,
748
+ 6,
749
+ 8,
750
+ 8,
751
+ 11,
752
+ 11,
753
+ 16,
754
+ 16,
755
+ 18,
756
+ 16,
757
+ 19,
758
+ 21,
759
+ 25,
760
+ 25,
761
+ 25,
762
+ 34,
763
+ 30,
764
+ 32,
765
+ 35,
766
+ 37,
767
+ 40,
768
+ 42,
769
+ 45,
770
+ 48,
771
+ 51,
772
+ 54,
773
+ 57,
774
+ 60,
775
+ 63,
776
+ 66,
777
+ 70,
778
+ 74,
779
+ 77,
780
+ 81
781
+ ]
782
+ ];
783
+ qrcodegen2.QrCode = _QrCode;
784
+ function appendBits(val, len, bb) {
785
+ if (len < 0 || len > 31 || val >>> len != 0) throw new RangeError("Value out of range");
786
+ for (let i = len - 1; i >= 0; i--) bb.push(val >>> i & 1);
787
+ }
788
+ function getBit(x, i) {
789
+ return (x >>> i & 1) != 0;
790
+ }
791
+ function assert(cond) {
792
+ if (!cond) throw new Error("Assertion error");
793
+ }
794
+ const _QrSegment = class _QrSegment {
795
+ constructor(mode, numChars, bitData) {
796
+ this.mode = mode;
797
+ this.numChars = numChars;
798
+ this.bitData = bitData;
799
+ if (numChars < 0) throw new RangeError("Invalid argument");
800
+ this.bitData = bitData.slice();
801
+ }
802
+ static makeBytes(data) {
803
+ let bb = [];
804
+ for (const b of data) appendBits(b, 8, bb);
805
+ return new _QrSegment(_QrSegment.Mode.BYTE, data.length, bb);
806
+ }
807
+ static makeNumeric(digits) {
808
+ if (!_QrSegment.isNumeric(digits)) throw new RangeError("String contains non-numeric characters");
809
+ let bb = [];
810
+ for (let i = 0; i < digits.length;) {
811
+ const n = Math.min(digits.length - i, 3);
812
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
813
+ i += n;
814
+ }
815
+ return new _QrSegment(_QrSegment.Mode.NUMERIC, digits.length, bb);
816
+ }
817
+ static makeAlphanumeric(text) {
818
+ if (!_QrSegment.isAlphanumeric(text)) throw new RangeError("String contains unencodable characters in alphanumeric mode");
819
+ let bb = [];
820
+ let i;
821
+ for (i = 0; i + 2 <= text.length; i += 2) {
822
+ let temp = _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
823
+ temp += _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
824
+ appendBits(temp, 11, bb);
825
+ }
826
+ if (i < text.length) appendBits(_QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
827
+ return new _QrSegment(_QrSegment.Mode.ALPHANUMERIC, text.length, bb);
828
+ }
829
+ static makeSegments(text) {
830
+ if (text == "") return [];
831
+ else if (_QrSegment.isNumeric(text)) return [_QrSegment.makeNumeric(text)];
832
+ else if (_QrSegment.isAlphanumeric(text)) return [_QrSegment.makeAlphanumeric(text)];
833
+ else return [_QrSegment.makeBytes(_QrSegment.toUtf8ByteArray(text))];
834
+ }
835
+ static makeEci(assignVal) {
836
+ let bb = [];
837
+ if (assignVal < 0) throw new RangeError("ECI assignment value out of range");
838
+ else if (assignVal < 128) appendBits(assignVal, 8, bb);
839
+ else if (assignVal < 16384) {
840
+ appendBits(2, 2, bb);
841
+ appendBits(assignVal, 14, bb);
842
+ } else if (assignVal < 1e6) {
843
+ appendBits(6, 3, bb);
844
+ appendBits(assignVal, 21, bb);
845
+ } else throw new RangeError("ECI assignment value out of range");
846
+ return new _QrSegment(_QrSegment.Mode.ECI, 0, bb);
847
+ }
848
+ static isNumeric(text) {
849
+ return _QrSegment.NUMERIC_REGEX.test(text);
850
+ }
851
+ static isAlphanumeric(text) {
852
+ return _QrSegment.ALPHANUMERIC_REGEX.test(text);
853
+ }
854
+ getData() {
855
+ return this.bitData.slice();
856
+ }
857
+ static getTotalBits(segs, version) {
858
+ let result = 0;
859
+ for (const seg of segs) {
860
+ const ccbits = seg.mode.numCharCountBits(version);
861
+ if (seg.numChars >= 1 << ccbits) return Infinity;
862
+ result += 4 + ccbits + seg.bitData.length;
863
+ }
864
+ return result;
865
+ }
866
+ static toUtf8ByteArray(str) {
867
+ str = encodeURI(str);
868
+ let result = [];
869
+ for (let i = 0; i < str.length; i++) if (str.charAt(i) != "%") result.push(str.charCodeAt(i));
870
+ else {
871
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
872
+ i += 2;
873
+ }
874
+ return result;
875
+ }
876
+ };
877
+ _QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
878
+ _QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
879
+ _QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
880
+ let QrSegment = _QrSegment;
881
+ qrcodegen2.QrSegment = _QrSegment;
882
+ })(qrcodegen || (qrcodegen = {}));
883
+ ((qrcodegen2) => {
884
+ ((QrCode2) => {
885
+ const _Ecc = class _Ecc {
886
+ constructor(ordinal, formatBits) {
887
+ this.ordinal = ordinal;
888
+ this.formatBits = formatBits;
889
+ }
890
+ };
891
+ _Ecc.LOW = new _Ecc(0, 1);
892
+ _Ecc.MEDIUM = new _Ecc(1, 0);
893
+ _Ecc.QUARTILE = new _Ecc(2, 3);
894
+ _Ecc.HIGH = new _Ecc(3, 2);
895
+ QrCode2.Ecc = _Ecc;
896
+ })(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
897
+ })(qrcodegen || (qrcodegen = {}));
898
+ ((qrcodegen2) => {
899
+ ((QrSegment2) => {
900
+ const _Mode = class _Mode {
901
+ constructor(modeBits, numBitsCharCount) {
902
+ this.modeBits = modeBits;
903
+ this.numBitsCharCount = numBitsCharCount;
904
+ }
905
+ numCharCountBits(ver) {
906
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
907
+ }
908
+ };
909
+ _Mode.NUMERIC = new _Mode(1, [
910
+ 10,
911
+ 12,
912
+ 14
913
+ ]);
914
+ _Mode.ALPHANUMERIC = new _Mode(2, [
915
+ 9,
916
+ 11,
917
+ 13
918
+ ]);
919
+ _Mode.BYTE = new _Mode(4, [
920
+ 8,
921
+ 16,
922
+ 16
923
+ ]);
924
+ _Mode.KANJI = new _Mode(8, [
925
+ 8,
926
+ 10,
927
+ 12
928
+ ]);
929
+ _Mode.ECI = new _Mode(7, [
930
+ 0,
931
+ 0,
932
+ 0
933
+ ]);
934
+ QrSegment2.Mode = _Mode;
935
+ })(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
936
+ })(qrcodegen || (qrcodegen = {}));
937
+ var qrcodegen_default = qrcodegen;
938
+ /**
939
+ * @license qrcode.react
940
+ * Copyright (c) Paul O'Shannessy
941
+ * SPDX-License-Identifier: ISC
942
+ */
943
+ var ERROR_LEVEL_MAP = {
944
+ L: qrcodegen_default.QrCode.Ecc.LOW,
945
+ M: qrcodegen_default.QrCode.Ecc.MEDIUM,
946
+ Q: qrcodegen_default.QrCode.Ecc.QUARTILE,
947
+ H: qrcodegen_default.QrCode.Ecc.HIGH
948
+ };
949
+ var DEFAULT_SIZE = 128;
950
+ var DEFAULT_LEVEL = "L";
951
+ var DEFAULT_BGCOLOR = "#FFFFFF";
952
+ var DEFAULT_FGCOLOR = "#000000";
953
+ var DEFAULT_INCLUDEMARGIN = false;
954
+ var DEFAULT_MINVERSION = 1;
955
+ var SPEC_MARGIN_SIZE = 4;
956
+ var DEFAULT_MARGIN_SIZE = 0;
957
+ var DEFAULT_IMG_SCALE = .1;
958
+ function generatePath(modules, margin = 0) {
959
+ const ops = [];
960
+ modules.forEach(function(row, y) {
961
+ let start = null;
962
+ row.forEach(function(cell, x) {
963
+ if (!cell && start !== null) {
964
+ ops.push(`M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`);
965
+ start = null;
966
+ return;
967
+ }
968
+ if (x === row.length - 1) {
969
+ if (!cell) return;
970
+ if (start === null) ops.push(`M${x + margin},${y + margin} h1v1H${x + margin}z`);
971
+ else ops.push(`M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`);
972
+ return;
973
+ }
974
+ if (cell && start === null) start = x;
975
+ });
976
+ });
977
+ return ops.join("");
978
+ }
979
+ function excavateModules(modules, excavation) {
980
+ return modules.slice().map((row, y) => {
981
+ if (y < excavation.y || y >= excavation.y + excavation.h) return row;
982
+ return row.map((cell, x) => {
983
+ if (x < excavation.x || x >= excavation.x + excavation.w) return cell;
984
+ return false;
985
+ });
986
+ });
987
+ }
988
+ function getImageSettings(cells, size, margin, imageSettings) {
989
+ if (imageSettings == null) return null;
990
+ const numCells = cells.length + margin * 2;
991
+ const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
992
+ const scale = numCells / size;
993
+ const w = (imageSettings.width || defaultSize) * scale;
994
+ const h = (imageSettings.height || defaultSize) * scale;
995
+ const x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
996
+ const y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
997
+ const opacity = imageSettings.opacity == null ? 1 : imageSettings.opacity;
998
+ let excavation = null;
999
+ if (imageSettings.excavate) {
1000
+ let floorX = Math.floor(x);
1001
+ let floorY = Math.floor(y);
1002
+ excavation = {
1003
+ x: floorX,
1004
+ y: floorY,
1005
+ w: Math.ceil(w + x - floorX),
1006
+ h: Math.ceil(h + y - floorY)
1007
+ };
1008
+ }
1009
+ const crossOrigin = imageSettings.crossOrigin;
1010
+ return {
1011
+ x,
1012
+ y,
1013
+ h,
1014
+ w,
1015
+ excavation,
1016
+ opacity,
1017
+ crossOrigin
1018
+ };
1019
+ }
1020
+ function getMarginSize(includeMargin, marginSize) {
1021
+ if (marginSize != null) return Math.max(Math.floor(marginSize), 0);
1022
+ return includeMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
1023
+ }
1024
+ function useQRCode({ value, level, minVersion, includeMargin, marginSize, imageSettings, size, boostLevel }) {
1025
+ let qrcode = react.default.useMemo(() => {
1026
+ const segments = (Array.isArray(value) ? value : [value]).reduce((accum, v) => {
1027
+ accum.push(...qrcodegen_default.QrSegment.makeSegments(v));
1028
+ return accum;
1029
+ }, []);
1030
+ return qrcodegen_default.QrCode.encodeSegments(segments, ERROR_LEVEL_MAP[level], minVersion, void 0, void 0, boostLevel);
1031
+ }, [
1032
+ value,
1033
+ level,
1034
+ minVersion,
1035
+ boostLevel
1036
+ ]);
1037
+ const { cells, margin, numCells, calculatedImageSettings } = react.default.useMemo(() => {
1038
+ let cells2 = qrcode.getModules();
1039
+ const margin2 = getMarginSize(includeMargin, marginSize);
1040
+ return {
1041
+ cells: cells2,
1042
+ margin: margin2,
1043
+ numCells: cells2.length + margin2 * 2,
1044
+ calculatedImageSettings: getImageSettings(cells2, size, margin2, imageSettings)
1045
+ };
1046
+ }, [
1047
+ qrcode,
1048
+ size,
1049
+ imageSettings,
1050
+ includeMargin,
1051
+ marginSize
1052
+ ]);
1053
+ return {
1054
+ qrcode,
1055
+ margin,
1056
+ cells,
1057
+ numCells,
1058
+ calculatedImageSettings
1059
+ };
1060
+ }
1061
+ var SUPPORTS_PATH2D = function() {
1062
+ try {
1063
+ new Path2D().addPath(new Path2D());
1064
+ } catch (e) {
1065
+ return false;
1066
+ }
1067
+ return true;
1068
+ }();
1069
+ var QRCodeCanvas = react.default.forwardRef(function QRCodeCanvas2(props, forwardedRef) {
1070
+ const _a = props, { value, size = DEFAULT_SIZE, level = DEFAULT_LEVEL, bgColor = DEFAULT_BGCOLOR, fgColor = DEFAULT_FGCOLOR, includeMargin = DEFAULT_INCLUDEMARGIN, minVersion = DEFAULT_MINVERSION, boostLevel, marginSize, imageSettings } = _a;
1071
+ const _b = __objRest(_a, [
1072
+ "value",
1073
+ "size",
1074
+ "level",
1075
+ "bgColor",
1076
+ "fgColor",
1077
+ "includeMargin",
1078
+ "minVersion",
1079
+ "boostLevel",
1080
+ "marginSize",
1081
+ "imageSettings"
1082
+ ]), { style } = _b, otherProps = __objRest(_b, ["style"]);
1083
+ const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
1084
+ const _canvas = react.default.useRef(null);
1085
+ const _image = react.default.useRef(null);
1086
+ const setCanvasRef = react.default.useCallback((node) => {
1087
+ _canvas.current = node;
1088
+ if (typeof forwardedRef === "function") forwardedRef(node);
1089
+ else if (forwardedRef) forwardedRef.current = node;
1090
+ }, [forwardedRef]);
1091
+ const [isImgLoaded, setIsImageLoaded] = react.default.useState(false);
1092
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
1093
+ value,
1094
+ level,
1095
+ minVersion,
1096
+ boostLevel,
1097
+ includeMargin,
1098
+ marginSize,
1099
+ imageSettings,
1100
+ size
1101
+ });
1102
+ react.default.useEffect(() => {
1103
+ if (_canvas.current != null) {
1104
+ const canvas = _canvas.current;
1105
+ const ctx = canvas.getContext("2d");
1106
+ if (!ctx) return;
1107
+ let cellsToDraw = cells;
1108
+ const image = _image.current;
1109
+ const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
1110
+ if (haveImageToRender) {
1111
+ if (calculatedImageSettings.excavation != null) cellsToDraw = excavateModules(cells, calculatedImageSettings.excavation);
1112
+ }
1113
+ const pixelRatio = window.devicePixelRatio || 1;
1114
+ canvas.height = canvas.width = size * pixelRatio;
1115
+ const scale = size / numCells * pixelRatio;
1116
+ ctx.scale(scale, scale);
1117
+ ctx.fillStyle = bgColor;
1118
+ ctx.fillRect(0, 0, numCells, numCells);
1119
+ ctx.fillStyle = fgColor;
1120
+ if (SUPPORTS_PATH2D) ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));
1121
+ else cells.forEach(function(row, rdx) {
1122
+ row.forEach(function(cell, cdx) {
1123
+ if (cell) ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
1124
+ });
1125
+ });
1126
+ if (calculatedImageSettings) ctx.globalAlpha = calculatedImageSettings.opacity;
1127
+ if (haveImageToRender) ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);
1128
+ }
1129
+ });
1130
+ react.default.useEffect(() => {
1131
+ setIsImageLoaded(false);
1132
+ }, [imgSrc]);
1133
+ const canvasStyle = __spreadValues({
1134
+ height: size,
1135
+ width: size
1136
+ }, style);
1137
+ let img = null;
1138
+ if (imgSrc != null) img = /* @__PURE__ */ react.default.createElement("img", {
1139
+ src: imgSrc,
1140
+ key: imgSrc,
1141
+ style: { display: "none" },
1142
+ onLoad: () => {
1143
+ setIsImageLoaded(true);
1144
+ },
1145
+ ref: _image,
1146
+ crossOrigin: calculatedImageSettings == null ? void 0 : calculatedImageSettings.crossOrigin
1147
+ });
1148
+ return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("canvas", __spreadValues({
1149
+ style: canvasStyle,
1150
+ height: size,
1151
+ width: size,
1152
+ ref: setCanvasRef,
1153
+ role: "img"
1154
+ }, otherProps)), img);
1155
+ });
1156
+ QRCodeCanvas.displayName = "QRCodeCanvas";
1157
+ var QRCodeSVG = react.default.forwardRef(function QRCodeSVG2(props, forwardedRef) {
1158
+ const _a = props, { value, size = DEFAULT_SIZE, level = DEFAULT_LEVEL, bgColor = DEFAULT_BGCOLOR, fgColor = DEFAULT_FGCOLOR, includeMargin = DEFAULT_INCLUDEMARGIN, minVersion = DEFAULT_MINVERSION, boostLevel, title, marginSize, imageSettings } = _a, otherProps = __objRest(_a, [
1159
+ "value",
1160
+ "size",
1161
+ "level",
1162
+ "bgColor",
1163
+ "fgColor",
1164
+ "includeMargin",
1165
+ "minVersion",
1166
+ "boostLevel",
1167
+ "title",
1168
+ "marginSize",
1169
+ "imageSettings"
1170
+ ]);
1171
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
1172
+ value,
1173
+ level,
1174
+ minVersion,
1175
+ boostLevel,
1176
+ includeMargin,
1177
+ marginSize,
1178
+ imageSettings,
1179
+ size
1180
+ });
1181
+ let cellsToDraw = cells;
1182
+ let image = null;
1183
+ if (imageSettings != null && calculatedImageSettings != null) {
1184
+ if (calculatedImageSettings.excavation != null) cellsToDraw = excavateModules(cells, calculatedImageSettings.excavation);
1185
+ image = /* @__PURE__ */ react.default.createElement("image", {
1186
+ href: imageSettings.src,
1187
+ height: calculatedImageSettings.h,
1188
+ width: calculatedImageSettings.w,
1189
+ x: calculatedImageSettings.x + margin,
1190
+ y: calculatedImageSettings.y + margin,
1191
+ preserveAspectRatio: "none",
1192
+ opacity: calculatedImageSettings.opacity,
1193
+ crossOrigin: calculatedImageSettings.crossOrigin
1194
+ });
1195
+ }
1196
+ const fgPath = generatePath(cellsToDraw, margin);
1197
+ return /* @__PURE__ */ react.default.createElement("svg", __spreadValues({
1198
+ height: size,
1199
+ width: size,
1200
+ viewBox: `0 0 ${numCells} ${numCells}`,
1201
+ ref: forwardedRef,
1202
+ role: "img"
1203
+ }, otherProps), !!title && /* @__PURE__ */ react.default.createElement("title", null, title), /* @__PURE__ */ react.default.createElement("path", {
1204
+ fill: bgColor,
1205
+ d: `M0,0 h${numCells}v${numCells}H0z`,
1206
+ shapeRendering: "crispEdges"
1207
+ }), /* @__PURE__ */ react.default.createElement("path", {
1208
+ fill: fgColor,
1209
+ d: fgPath,
1210
+ shapeRendering: "crispEdges"
1211
+ }), image);
1212
+ });
1213
+ QRCodeSVG.displayName = "QRCodeSVG";
1214
+ //#endregion
1215
+ //#region src/client/icons.tsx
1216
+ /** Shared svg attrs for the 16px stroke icon family. */
1217
+ function iconProps(props) {
1218
+ return {
1219
+ width: 16,
1220
+ height: 16,
1221
+ viewBox: "0 0 16 16",
1222
+ fill: "none",
1223
+ stroke: "currentColor",
1224
+ strokeWidth: 1.3,
1225
+ strokeLinecap: "round",
1226
+ strokeLinejoin: "round",
1227
+ "aria-hidden": true,
1228
+ ...props
1229
+ };
1230
+ }
1231
+ /** A QR-symbol glyph: three finder squares plus a payload dot. */
1232
+ function QrIcon(props) {
1233
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1234
+ ...iconProps(props),
1235
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M2.5 2.5h4v4h-4zM9.5 2.5h4v4h-4zM2.5 9.5h4v4h-4z" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M9.5 9.5h1.6v1.6H9.5zM12.4 9.5h1.1M9.5 12.4v1.1M12 13.5h1.5v-1.5h-1.5z" })]
1236
+ });
1237
+ }
1238
+ /** Copy glyph. */
1239
+ function CopyIcon(props) {
1240
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1241
+ ...iconProps(props),
1242
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
1243
+ x: "5.5",
1244
+ y: "5.5",
1245
+ width: "9",
1246
+ height: "9",
1247
+ rx: "1.5"
1248
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M2.5 10.5v-7A1.5 1.5 0 0 1 4 2h5.5" })]
1249
+ });
1250
+ }
1251
+ /** Check glyph for the transient copied state. */
1252
+ function CheckIcon(props) {
1253
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1254
+ ...iconProps(props),
1255
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M3 8.5 6.5 12l6.5-8" })
1256
+ });
1257
+ }
1258
+ /** Close glyph for the panel header. */
1259
+ function CloseIcon(props) {
1260
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1261
+ ...iconProps(props),
1262
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M4 4l8 8M12 4l-8 8" })
1263
+ });
1264
+ }
1265
+ /** Refresh glyph for the mint-again action. */
1266
+ function RefreshIcon(props) {
1267
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1268
+ ...iconProps(props),
1269
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M13 8a5 5 0 1 1-1.8-3.85" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M13.2 2.4V5.6H10" })]
1270
+ });
1271
+ }
1272
+ //#endregion
1273
+ //#region src/client/semantic.ts
1274
+ /**
1275
+ * Semantic attribute values for the protocol v1 pairing panel (contract:
1276
+ * skins/skin-center/contracts/semantic-attrs-v1.md). Root containers carry
1277
+ * `data-dsh-plugin`; parts carry bare `data-dsh-part` values owned by that
1278
+ * plugin attribute.
1279
+ */
1280
+ /** Plugin short name stamped on the footer trigger and the modal root. */
1281
+ const PLUGIN_ATTR = "remote-bridge";
1282
+ /** The sidebar footer seat trigger. */
1283
+ const PART_ENTRY = "entry";
1284
+ /** The modal panel root. */
1285
+ const PART_PANEL = "panel";
1286
+ /** A state notice: the origin warning, or a refusal the host raised. */
1287
+ const PART_NOTICE = "notice";
1288
+ //#endregion
1289
+ //#region \0dsh-css:packages/dsh-remote-bridge/src/client/panel.module.css.mjs
1290
+ const css = ".sd7VOG_trigger{width:36px;height:36px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:50%;flex:none;order:-1;justify-content:center;align-items:center;padding:0;transition:background-color .12s,color .12s,box-shadow .12s;display:inline-flex;position:relative}.sd7VOG_trigger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.sd7VOG_trigger:active:not(:disabled){background:var(--dsw-alias-interactive-bg-active)}.sd7VOG_trigger:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-bg-layer-2), 0 0 0 4px var(--dsw-alias-brand-primary);outline:none}[class*=footerActions]:has([data-dsh-plugin=remote-bridge][data-wide=rail]){flex-direction:column;align-items:center;gap:4px}.sd7VOG_overlay{z-index:1000;justify-content:center;align-items:center;display:flex;position:fixed;inset:0}.sd7VOG_mask{background:var(--dsw-alias-bg-mask-1);backdrop-filter:var(--dsw-mask-blur);position:absolute;inset:0}.sd7VOG_panel{z-index:1;box-sizing:border-box;background:var(--dsw-alias-bg-layer-2);width:460px;max-width:calc(100vw - 48px);max-height:calc(100vh - 48px);box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-primary);border-radius:24px;flex-direction:column;gap:14px;padding:24px;font-size:14px;line-height:22px;display:flex;position:relative;overflow:auto}.sd7VOG_header{align-items:flex-start;gap:12px;display:flex}.sd7VOG_heading{flex:1;min-width:0}.sd7VOG_title{margin:0;font-size:18px;font-weight:600;line-height:26px}.sd7VOG_subtitle{color:var(--dsw-alias-label-secondary);margin:4px 0 0;font-size:13px;line-height:20px}.sd7VOG_closeButton{width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:8px;flex:none;justify-content:center;align-items:center;padding:0;transition:background-color .12s,color .12s;display:inline-flex}.sd7VOG_closeButton:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.sd7VOG_closeButton:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-bg-layer-2), 0 0 0 4px var(--dsw-alias-brand-primary);outline:none}.sd7VOG_qrCard{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);border-radius:16px;flex-direction:column;align-items:center;gap:10px;padding:18px;display:flex}.sd7VOG_qrWrap{justify-content:center;align-items:center;display:flex}.sd7VOG_qr{width:184px;height:184px;display:block}.sd7VOG_countdown{flex-direction:column;align-items:center;gap:6px;width:100%;display:flex}.sd7VOG_countdownText{color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;font-size:13px;line-height:18px}.sd7VOG_bar{background:var(--dsw-alias-interactive-bg-hover);border-radius:999px;width:100%;height:4px;display:block;overflow:hidden}.sd7VOG_barFill{background:var(--dsw-alias-brand-primary);border-radius:999px;height:100%;transition:width 1s linear;display:block}.sd7VOG_tokenRow{flex-direction:column;gap:4px;min-width:0;display:flex}.sd7VOG_tokenLabel{color:var(--dsw-alias-label-secondary);font-size:13px;line-height:18px}.sd7VOG_token{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);word-break:break-all;user-select:all;border-radius:8px;padding:8px 10px;font-size:12px;line-height:18px;display:block}.sd7VOG_notice{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);border-radius:12px;padding:10px 12px}.sd7VOG_notice[data-tone=alert]{border-color:var(--dsw-alias-state-error-primary)}.sd7VOG_notice[data-tone=warning]{border-color:var(--dsw-alias-state-warn-primary)}.sd7VOG_noticeTitle{margin:0;font-weight:600;line-height:20px}.sd7VOG_noticeBody{color:var(--dsw-alias-label-secondary);margin:4px 0 0;font-size:13px;line-height:20px}.sd7VOG_hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:18px}.sd7VOG_actions{justify-content:flex-end;gap:8px;display:flex}.sd7VOG_refresh{background:var(--dsw-alias-button-primary-fill);height:32px;color:var(--dsw-alias-label-primary-foreground);cursor:pointer;border:none;border-radius:16px;align-items:center;gap:6px;padding:0 16px;font-size:14px;line-height:20px;transition:background-color .12s;display:inline-flex}.sd7VOG_refresh:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover)}.sd7VOG_refresh:disabled{opacity:.5;cursor:default}.sd7VOG_refresh:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-bg-layer-2), 0 0 0 4px var(--dsw-alias-brand-primary);outline:none}.sd7VOG_copyButton{height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:8px;justify-content:center;align-self:flex-start;align-items:center;gap:4px;padding:0 10px;font-size:12px;line-height:18px;transition:background-color .12s,color .12s;display:inline-flex}.sd7VOG_copyButton:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.sd7VOG_copyButton[data-copied=true]{color:var(--dsw-alias-brand-primary)}.sd7VOG_copyButton[data-failed=true]{color:var(--dsw-alias-state-error-primary)}.sd7VOG_copyButton:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-bg-layer-2), 0 0 0 4px var(--dsw-alias-brand-primary);outline:none}";
1291
+ const tagId = "@linxin666/dsh-remote-bridge/packages/dsh-remote-bridge/src/client/panel.module.css";
1292
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
1293
+ const tag = document.createElement("style");
1294
+ tag.dataset.plugin = "@linxin666/dsh-remote-bridge";
1295
+ tag.dataset.pluginCss = tagId;
1296
+ tag.textContent = css;
1297
+ document.head.appendChild(tag);
1298
+ }
1299
+ var panel_module_css_default = {
1300
+ "actions": "sd7VOG_actions",
1301
+ "bar": "sd7VOG_bar",
1302
+ "barFill": "sd7VOG_barFill",
1303
+ "closeButton": "sd7VOG_closeButton",
1304
+ "copyButton": "sd7VOG_copyButton",
1305
+ "countdown": "sd7VOG_countdown",
1306
+ "countdownText": "sd7VOG_countdownText",
1307
+ "header": "sd7VOG_header",
1308
+ "heading": "sd7VOG_heading",
1309
+ "hint": "sd7VOG_hint",
1310
+ "mask": "sd7VOG_mask",
1311
+ "notice": "sd7VOG_notice",
1312
+ "noticeBody": "sd7VOG_noticeBody",
1313
+ "noticeTitle": "sd7VOG_noticeTitle",
1314
+ "overlay": "sd7VOG_overlay",
1315
+ "panel": "sd7VOG_panel",
1316
+ "qr": "sd7VOG_qr",
1317
+ "qrCard": "sd7VOG_qrCard",
1318
+ "qrWrap": "sd7VOG_qrWrap",
1319
+ "refresh": "sd7VOG_refresh",
1320
+ "subtitle": "sd7VOG_subtitle",
1321
+ "title": "sd7VOG_title",
1322
+ "token": "sd7VOG_token",
1323
+ "tokenLabel": "sd7VOG_tokenLabel",
1324
+ "tokenRow": "sd7VOG_tokenRow",
1325
+ "trigger": "sd7VOG_trigger"
1326
+ };
1327
+ //#endregion
1328
+ //#region src/client/PairPanel.tsx
1329
+ /**
1330
+ * The protocol v1 pairing panel body: the QR symbol, the same secret in
1331
+ * plaintext, the 30 s countdown with its expiry state, the refresh action, and
1332
+ * the two facts the reader must not miss — the phone's origin is the public
1333
+ * relay (never this machine's loopback address), and the code is one-shot.
1334
+ *
1335
+ * Pure presentation: every state and action arrives through props, and the
1336
+ * clock is a prop, so the expiry flip is deterministic instead of read from
1337
+ * `Date.now()` here.
1338
+ */
1339
+ /**
1340
+ * The QR symbol, memoized on the secret: the countdown re-renders the panel
1341
+ * every second, and qrcode.react rebuilds the whole module path on each render.
1342
+ * The encoded value is the host's own `pairingUrl` verbatim when there is one —
1343
+ * a `{token, url}` document whose `url` names THIS instance's public relay, so
1344
+ * the phone adopts an origin that actually reaches this host. The bare-token
1345
+ * fallback means the phone keeps whatever origin it already has.
1346
+ */
1347
+ const PairQrCode = (0, react.memo)(function PairQrCode({ value, label }) {
1348
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QRCodeSVG, {
1349
+ value,
1350
+ size: 184,
1351
+ level: "M",
1352
+ marginSize: 1,
1353
+ "aria-label": label
1354
+ });
1355
+ });
1356
+ /** One state notice: a title and, when there is one, the sentence explaining it. */
1357
+ function Notice({ tone, title, body }) {
1358
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1359
+ className: panel_module_css_default.notice,
1360
+ "data-dsh-part": PART_NOTICE,
1361
+ "data-tone": tone,
1362
+ role: tone === "plain" ? "status" : "alert",
1363
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1364
+ className: panel_module_css_default.noticeTitle,
1365
+ children: title
1366
+ }), body !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1367
+ className: panel_module_css_default.noticeBody,
1368
+ children: body
1369
+ })]
1370
+ });
1371
+ }
1372
+ /**
1373
+ * Render the pairing panel.
1374
+ * @param props - locale seat, view state, clock, page host and actions.
1375
+ * @returns the panel element tree.
1376
+ */
1377
+ function PairPanel({ t, state, now, host, copy, onClose, onRefresh, onCopy }) {
1378
+ const remainingMs = state.kind === "ready" ? Math.max(0, state.expiresAt - now) : 0;
1379
+ const expired = state.kind === "ready" && remainingMs <= 0;
1380
+ const seconds = Math.ceil(remainingMs / 1e3);
1381
+ const windowMs = state.kind === "ready" ? Math.max(1, state.expiresAt - state.issuedAt) : 1;
1382
+ const percent = Math.min(100, Math.max(0, Math.round(remainingMs / windowMs * 100)));
1383
+ const payload = state.kind === "ready" ? state.pairingUrl ?? state.token : "";
1384
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1385
+ className: panel_module_css_default.overlay,
1386
+ role: "presentation",
1387
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1388
+ className: panel_module_css_default.mask,
1389
+ "aria-hidden": "true",
1390
+ onClick: onClose
1391
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1392
+ className: panel_module_css_default.panel,
1393
+ role: "dialog",
1394
+ "aria-modal": "true",
1395
+ "aria-label": t("title"),
1396
+ "data-dsh-plugin": PLUGIN_ATTR,
1397
+ "data-dsh-part": PART_PANEL,
1398
+ children: [
1399
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1400
+ className: panel_module_css_default.header,
1401
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1402
+ className: panel_module_css_default.heading,
1403
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1404
+ className: panel_module_css_default.title,
1405
+ children: t("title")
1406
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1407
+ className: panel_module_css_default.subtitle,
1408
+ children: t("subtitle")
1409
+ })]
1410
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1411
+ type: "button",
1412
+ className: panel_module_css_default.closeButton,
1413
+ "aria-label": t("action.close"),
1414
+ onClick: onClose,
1415
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CloseIcon, {})
1416
+ })]
1417
+ }),
1418
+ state.kind === "reading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Notice, {
1419
+ tone: "plain",
1420
+ title: t("state.reading")
1421
+ }),
1422
+ state.kind === "forbidden" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Notice, {
1423
+ tone: "alert",
1424
+ title: t("forbidden.title"),
1425
+ body: t("forbidden.body")
1426
+ }),
1427
+ state.kind === "failed" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Notice, {
1428
+ tone: "alert",
1429
+ title: t("failed.title"),
1430
+ body: t("failed.body", { status: String(state.status) })
1431
+ }),
1432
+ state.kind === "unreachable" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Notice, {
1433
+ tone: "alert",
1434
+ title: t("unreachable.title"),
1435
+ body: t("unreachable.body")
1436
+ }),
1437
+ state.kind === "ready" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1438
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1439
+ className: panel_module_css_default.qrCard,
1440
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1441
+ className: panel_module_css_default.qrWrap,
1442
+ "data-dsh-part": "qr",
1443
+ ["data-dsh-qr-value"]: payload,
1444
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PairQrCode, {
1445
+ value: payload,
1446
+ label: t("pair.qrLabel")
1447
+ })
1448
+ }), expired ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Notice, {
1449
+ tone: "alert",
1450
+ title: t("pair.expired"),
1451
+ body: t("pair.expiredHint")
1452
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1453
+ className: panel_module_css_default.countdown,
1454
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1455
+ className: panel_module_css_default.countdownText,
1456
+ children: t("pair.countdown", { s: String(seconds) })
1457
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1458
+ className: panel_module_css_default.bar,
1459
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1460
+ className: panel_module_css_default.barFill,
1461
+ style: { width: `${String(percent)}%` }
1462
+ })
1463
+ })]
1464
+ })]
1465
+ }),
1466
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1467
+ className: panel_module_css_default.tokenRow,
1468
+ "data-dsh-part": "token",
1469
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1470
+ className: panel_module_css_default.tokenLabel,
1471
+ children: t("pair.payloadLabel")
1472
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1473
+ className: panel_module_css_default.token,
1474
+ children: payload
1475
+ })]
1476
+ }),
1477
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1478
+ type: "button",
1479
+ className: panel_module_css_default.copyButton,
1480
+ "data-dsh-part": "copy",
1481
+ "data-copied": copy === "copied",
1482
+ "data-failed": copy === "failed",
1483
+ onClick: () => {
1484
+ onCopy(payload);
1485
+ },
1486
+ children: [copy === "copied" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckIcon, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyIcon, {}), copy === "copied" ? t("action.copied") : copy === "failed" ? t("action.copyFailed") : t("action.copy")]
1487
+ }),
1488
+ state.pairingUrl === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Notice, {
1489
+ tone: "warning",
1490
+ title: t("origin.title"),
1491
+ body: t("origin.body", { host })
1492
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Notice, {
1493
+ tone: "plain",
1494
+ title: t("origin.located.title"),
1495
+ body: t("origin.located.body", { origin: state.origin ?? "" })
1496
+ })
1497
+ ] }),
1498
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1499
+ className: panel_module_css_default.actions,
1500
+ children: state.kind !== "reading" && state.kind !== "forbidden" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1501
+ type: "button",
1502
+ className: panel_module_css_default.refresh,
1503
+ "data-dsh-part": "refresh",
1504
+ onClick: onRefresh,
1505
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RefreshIcon, {}), t("pair.refresh")]
1506
+ })
1507
+ })
1508
+ ]
1509
+ })]
1510
+ });
1511
+ }
1512
+ //#endregion
1513
+ //#region src/client/PairEntry.tsx
1514
+ /**
1515
+ * Sidebar footer entry for the protocol v1 pairing panel: the icon-only trigger
1516
+ * beside the sidebar settings seat (wide row / rail circle) that opens the
1517
+ * panel. Registered into the official `sidebar.footer.action` list slot
1518
+ * (declared by ui-sidebar — the same seat dsh-remote-web-ui and dsh-update
1519
+ * share).
1520
+ *
1521
+ * This component owns the panel's behavior: one read per open, one clock tick
1522
+ * while a live code is on screen, the mint-again action, and the copy action.
1523
+ * The wire call and the clipboard are injected (see the plugin entry), so the
1524
+ * rendered tree carries no closure-factory bundle import and both can be driven
1525
+ * by a test without patching a module.
1526
+ */
1527
+ /** How long the transient "copied" / "copy failed" label stays up. */
1528
+ const COPY_FEEDBACK_MS = 1500;
1529
+ /** The countdown's tick; one second is the resolution the panel shows. */
1530
+ const TICK_MS = 1e3;
1531
+ /** Map a read outcome onto the panel's view state. */
1532
+ function panelStateOf(outcome, issuedAt) {
1533
+ switch (outcome.kind) {
1534
+ case "ok": return {
1535
+ kind: "ready",
1536
+ token: outcome.token,
1537
+ issuedAt,
1538
+ expiresAt: outcome.expiresAt,
1539
+ origin: outcome.origin,
1540
+ pairingUrl: outcome.pairingUrl
1541
+ };
1542
+ case "forbidden": return { kind: "forbidden" };
1543
+ case "unreachable": return { kind: "unreachable" };
1544
+ case "failed": return {
1545
+ kind: "failed",
1546
+ status: outcome.status
1547
+ };
1548
+ }
1549
+ }
1550
+ /**
1551
+ * Render the pairing seat trigger and, when open, the panel.
1552
+ * @param props - the footer seat's column state, the injected actions and the locale seat.
1553
+ * @returns the trigger and the panel portal.
1554
+ */
1555
+ function PairEntry({ wide, read, copy, t }) {
1556
+ const [open, setOpen] = (0, react.useState)(false);
1557
+ const [state, setState] = (0, react.useState)({ kind: "reading" });
1558
+ const [copyState, setCopyState] = (0, react.useState)("idle");
1559
+ const [now, setNow] = (0, react.useState)(() => Date.now());
1560
+ const generation = (0, react.useRef)(0);
1561
+ const mint = (0, react.useCallback)(() => {
1562
+ const request = ++generation.current;
1563
+ setState({ kind: "reading" });
1564
+ read().then((outcome) => {
1565
+ if (request !== generation.current) return;
1566
+ const issuedAt = Date.now();
1567
+ setNow(issuedAt);
1568
+ setState(panelStateOf(outcome, issuedAt));
1569
+ });
1570
+ }, [read]);
1571
+ const openPanel = (0, react.useCallback)(() => {
1572
+ setOpen(true);
1573
+ setCopyState("idle");
1574
+ mint();
1575
+ }, [mint]);
1576
+ const closePanel = (0, react.useCallback)(() => {
1577
+ generation.current += 1;
1578
+ setOpen(false);
1579
+ }, []);
1580
+ (0, react.useEffect)(() => {
1581
+ if (!open || state.kind !== "ready") return;
1582
+ const deadline = state.expiresAt;
1583
+ const timer = window.setInterval(() => {
1584
+ const current = Date.now();
1585
+ setNow(current);
1586
+ if (current >= deadline) window.clearInterval(timer);
1587
+ }, TICK_MS);
1588
+ return () => {
1589
+ window.clearInterval(timer);
1590
+ };
1591
+ }, [open, state]);
1592
+ (0, react.useEffect)(() => {
1593
+ if (!open) return;
1594
+ const onKey = (event) => {
1595
+ if (event.key === "Escape") closePanel();
1596
+ };
1597
+ window.addEventListener("keydown", onKey);
1598
+ return () => {
1599
+ window.removeEventListener("keydown", onKey);
1600
+ };
1601
+ }, [open, closePanel]);
1602
+ const handleCopy = (0, react.useCallback)((token) => {
1603
+ copy(token).then((ok) => {
1604
+ setCopyState(ok ? "copied" : "failed");
1605
+ window.setTimeout(() => {
1606
+ setCopyState("idle");
1607
+ }, COPY_FEEDBACK_MS);
1608
+ });
1609
+ }, [copy]);
1610
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1611
+ type: "button",
1612
+ className: panel_module_css_default.trigger,
1613
+ "data-dsh-plugin": PLUGIN_ATTR,
1614
+ "data-dsh-part": PART_ENTRY,
1615
+ "data-wide": wide ? "wide" : "rail",
1616
+ "aria-label": t("entry.label"),
1617
+ "aria-expanded": open,
1618
+ title: t("entry.label"),
1619
+ onClick: openPanel,
1620
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QrIcon, {})
1621
+ }), open && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(PairPanel, {
1622
+ t,
1623
+ state,
1624
+ now,
1625
+ host: window.location.host,
1626
+ copy: copyState,
1627
+ onClose: closePanel,
1628
+ onRefresh: mint,
1629
+ onCopy: handleCopy
1630
+ }), document.body)] });
1631
+ }
1632
+ //#endregion
1633
+ //#region src/client/pair-token.ts
1634
+ /**
1635
+ * The panel's one wire call: read the one-shot bootstrap token from this
1636
+ * package's own Host route.
1637
+ *
1638
+ * The route is same-origin and document-relative (the GUI is served with
1639
+ * `<base href="./">`, so a sub-path deployment resolves it against its entry
1640
+ * directory instead of escaping to the origin root — the same rule
1641
+ * `dsh-remote-web-ui`'s pair API follows). It is NOT consumed here: the panel
1642
+ * only displays the secret, and the phone spends it in `pair.begin`, so a
1643
+ * mis-click on "new code" voids a token without ever pairing a device.
1644
+ *
1645
+ * `403` is a fact, not an error: the loopback gate in `core/loopback.ts`
1646
+ * refuses any page whose socket or `Host` is not this machine, which is exactly
1647
+ * the case the panel must name out loud.
1648
+ * @module dsh-remote-bridge/client/pair-token
1649
+ */
1650
+ /** Document-relative form of the Host route, for a page served under any base. */
1651
+ const PAIR_TOKEN_URL = "/remote-bridge/pair/token".replace(/^\/+/, "");
1652
+ /** Read a string field, treating a missing, mistyped or empty value as absent. */
1653
+ function stringOrNull(value) {
1654
+ return typeof value === "string" && value !== "" ? value : null;
1655
+ }
1656
+ /**
1657
+ * Read one bootstrap token.
1658
+ *
1659
+ * Never throws: every failure is one of the outcome arms, because the panel has
1660
+ * to render each of them. A `200` whose body is not `{token, expiresAt}` is
1661
+ * reported as a failure rather than shown as an empty QR.
1662
+ * @param options - injected transport and abort signal.
1663
+ * @returns the read outcome.
1664
+ */
1665
+ async function readPairToken(options = {}) {
1666
+ const send = options.fetchImpl ?? globalThis.fetch;
1667
+ if (send === void 0) return { kind: "unreachable" };
1668
+ let response;
1669
+ try {
1670
+ response = await send(PAIR_TOKEN_URL, {
1671
+ cache: "no-store",
1672
+ ...options.signal === void 0 ? {} : { signal: options.signal }
1673
+ });
1674
+ } catch {
1675
+ return { kind: "unreachable" };
1676
+ }
1677
+ if (response.status === 403) return { kind: "forbidden" };
1678
+ if (!response.ok) return {
1679
+ kind: "failed",
1680
+ status: response.status
1681
+ };
1682
+ let body;
1683
+ try {
1684
+ body = await response.json();
1685
+ } catch {
1686
+ return {
1687
+ kind: "failed",
1688
+ status: response.status
1689
+ };
1690
+ }
1691
+ if (typeof body !== "object" || body === null) return {
1692
+ kind: "failed",
1693
+ status: response.status
1694
+ };
1695
+ const token = body.token;
1696
+ const expiresAt = body.expiresAt;
1697
+ if (typeof token !== "string" || token === "") return {
1698
+ kind: "failed",
1699
+ status: response.status
1700
+ };
1701
+ if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt)) return {
1702
+ kind: "failed",
1703
+ status: response.status
1704
+ };
1705
+ const origin = stringOrNull(body.origin);
1706
+ const candidate = stringOrNull(body.pairingUrl);
1707
+ return {
1708
+ kind: "ok",
1709
+ token,
1710
+ expiresAt,
1711
+ origin,
1712
+ pairingUrl: candidate !== null && /^wss?:\/\/\S+$/.test(candidate) ? candidate : null
1713
+ };
1714
+ }
1715
+ //#endregion
1716
+ //#region src/client/locales.ts
1717
+ /**
1718
+ * `remote-bridge` namespace dictionaries: the protocol v1 pairing panel copy.
1719
+ *
1720
+ * The panel has one job — show the operator the one-shot bootstrap token as a
1721
+ * QR symbol plus its plaintext — so the copy is dominated by the two facts a
1722
+ * reader has to get right: where the phone's origin points (the public relay,
1723
+ * never this machine's loopback address) and why the token vanished (30 s, one
1724
+ * use, or a fresh mint).
1725
+ */
1726
+ /** Simplified Chinese dictionary (the key-set source of truth). */
1727
+ const zh = {
1728
+ "entry.label": "配对手机(协议 v1)",
1729
+ "title": "协议 v1 配对",
1730
+ "subtitle": "用手机 App 扫描下方二维码,即可以协议 v1 配对这台宿主。配对码由本机签发,仅在本机可读。",
1731
+ "state.reading": "正在取配对码…",
1732
+ "pair.qrLabel": "配对二维码",
1733
+ "pair.payloadLabel": "二维码内容(可复制后粘贴到手机)",
1734
+ "pair.countdown": "剩余 {s} 秒",
1735
+ "pair.expired": "配对码已过期(30 秒)",
1736
+ "pair.expiredHint": "过期的配对码不会被手机接受,请重新取码。",
1737
+ "pair.usedHint": "配对码一次性:手机调用 pair.begin 的瞬间即作废,重新取码也会作废上一张。",
1738
+ "pair.refresh": "重新取码",
1739
+ "origin.title": "没能自动定位公网地址,二维码只装裸配对码",
1740
+ "origin.body": "这台机器既没有 DSH_REMOTE_PUBLIC_BASE_URL,也没有中继注册表记录,因此无法把地址写进二维码。请先在手机 App 里把连接地址设成你的公网中继(形如 wss://<id>.dsh-market.com),再扫上面的码;本页所在的 {host} 只有本机能连,手机连不上。",
1741
+ "origin.located.title": "手机将直接连到公网中继(地址已写进二维码)",
1742
+ "origin.located.body": "二维码里已经带上 {origin}:手机扫一次就同时设好连接地址与配对码,不需要手填任何东西。",
1743
+ "forbidden.title": "这个页面不是从本机打开的",
1744
+ "forbidden.body": "配对码只能在本机 Web UI 上取。请在本机浏览器打开 http://127.0.0.1:<端口> 后重试。",
1745
+ "failed.title": "取配对码失败",
1746
+ "failed.body": "宿主返回了 HTTP {status},请刷新页面后重试。",
1747
+ "unreachable.title": "无法连接本机宿主",
1748
+ "unreachable.body": "请求没有到达宿主,请确认 dsh web 仍在运行后重试。",
1749
+ "action.close": "关闭",
1750
+ "action.copy": "复制配对码",
1751
+ "action.copied": "已复制",
1752
+ "action.copyFailed": "复制失败",
1753
+ "action.retry": "重试"
1754
+ };
1755
+ /** English dictionary, key-for-key with the zh source. */
1756
+ const en = {
1757
+ "entry.label": "Pair a phone (protocol v1)",
1758
+ "title": "Protocol v1 pairing",
1759
+ "subtitle": "Scan the QR code with the phone app to pair it with this host over protocol v1. The code is minted by this machine and only readable here.",
1760
+ "state.reading": "Requesting a pairing code…",
1761
+ "pair.qrLabel": "Pairing QR code",
1762
+ "pair.payloadLabel": "What the QR encodes (copy it to paste on the phone)",
1763
+ "pair.countdown": "{s} s left",
1764
+ "pair.expired": "The pairing code expired (30 s)",
1765
+ "pair.expiredHint": "An expired code is never accepted; request a new one.",
1766
+ "pair.usedHint": "The code is single-use: the phone spends it the moment it calls pair.begin, and requesting a new one voids the previous code.",
1767
+ "pair.refresh": "New code",
1768
+ "origin.title": "No public address could be located, so the QR carries the bare code",
1769
+ "origin.body": "This machine has neither DSH_REMOTE_PUBLIC_BASE_URL nor a relay registry row, so the address cannot go into the QR. Set the phone app to your public relay first (such as wss://<id>.dsh-market.com), then scan the code above; {host} (this page) is reachable only from this machine and never from the phone.",
1770
+ "origin.located.title": "The phone dials the public relay directly (address is in the QR)",
1771
+ "origin.located.body": "The QR carries {origin}: one scan sets both the connection address and the pairing code, with nothing to type.",
1772
+ "forbidden.title": "This page is not open on this machine",
1773
+ "forbidden.body": "Pairing codes can only be read from the machine itself. Open http://127.0.0.1:<port> in a browser on this machine and retry.",
1774
+ "failed.title": "Could not read a pairing code",
1775
+ "failed.body": "The host answered HTTP {status}. Reload the page and retry.",
1776
+ "unreachable.title": "Cannot reach the local host",
1777
+ "unreachable.body": "The request never reached the host. Check that dsh web is still running and retry.",
1778
+ "action.close": "Close",
1779
+ "action.copy": "Copy pairing code",
1780
+ "action.copied": "Copied",
1781
+ "action.copyFailed": "Copy failed",
1782
+ "action.retry": "Retry"
1783
+ };
1784
+ //#endregion
1785
+ //#region src/client/index.ts
1786
+ /** Dictionary namespace owned by this plugin. */
1787
+ const NS = "remote-bridge";
1788
+ /** Unique occupant id inside the shared footer.action list slot. */
1789
+ const ENTRY_ID = "remote-bridge";
1790
+ /** Services required by this plugin. */
1791
+ const inject = ["slots", "locale"];
1792
+ /**
1793
+ * Register the protocol v1 pairing surface.
1794
+ * @param ctx - client root context.
1795
+ */
1796
+ function apply(ctx) {
1797
+ ctx.effect(() => {
1798
+ try {
1799
+ return ctx.locale.register(NS, {
1800
+ zh,
1801
+ en
1802
+ });
1803
+ } catch {
1804
+ return () => {};
1805
+ }
1806
+ }, "remote-bridge: dictionaries");
1807
+ ctx.slots.inject("sidebar.footer.action", () => {
1808
+ try {
1809
+ return ctx.slots.register({
1810
+ name: "sidebar.footer.action",
1811
+ id: ENTRY_ID,
1812
+ locale: NS,
1813
+ inject: () => ({
1814
+ read: readPairToken,
1815
+ copy: _deepseek_ai_dsh_client_ui_primitives.writeClipboard
1816
+ })
1817
+ }, PairEntry);
1818
+ } catch {
1819
+ return () => {};
1820
+ }
1821
+ });
1822
+ }
1823
+ //#endregion
1824
+ exports.apply = apply;
1825
+ exports.inject = inject;
1826
+ return module.exports;
1827
+ }
1828
+ });
1829
+
1830
+ //# sourceMappingURL=client.js.map