@aiti-ai/aiti-msg-share 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +115 -2
- package/client/src/index.js +806 -0
- package/dist/aiti-msg-share-client.mjs +3346 -0
- package/docs/README.zh-CN.md +83 -0
- package/icon.svg +1 -0
- package/icons/share-2.svg +1 -0
- package/index.ts +602 -0
- package/lib/share-core.mjs +144 -0
- package/package.json +29 -4
- package/skills/configure-target/SKILL.md +56 -0
- package/skills/import-sxcu/SKILL.md +30 -0
- package/skills/index.json +1 -0
- package/skills/troubleshoot/SKILL.md +35 -0
- package/test/share-core.test.mjs +61 -0
- package/tools/build-client.mjs +10 -0
- package/tools/deploy.mjs +32 -0
|
@@ -0,0 +1,3346 @@
|
|
|
1
|
+
// aiti-msg-share client bundle — built by tools/build-client.mjs. Do not edit.
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/can-promise.js
|
|
29
|
+
var require_can_promise = __commonJS({
|
|
30
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/can-promise.js"(exports, module) {
|
|
31
|
+
module.exports = function() {
|
|
32
|
+
return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/utils.js
|
|
38
|
+
var require_utils = __commonJS({
|
|
39
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/utils.js"(exports) {
|
|
40
|
+
var toSJISFunction;
|
|
41
|
+
var CODEWORDS_COUNT = [
|
|
42
|
+
0,
|
|
43
|
+
// Not used
|
|
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
|
+
exports.getSymbolSize = function getSymbolSize(version) {
|
|
86
|
+
if (!version) throw new Error('"version" cannot be null or undefined');
|
|
87
|
+
if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
|
|
88
|
+
return version * 4 + 17;
|
|
89
|
+
};
|
|
90
|
+
exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
|
|
91
|
+
return CODEWORDS_COUNT[version];
|
|
92
|
+
};
|
|
93
|
+
exports.getBCHDigit = function(data) {
|
|
94
|
+
let digit = 0;
|
|
95
|
+
while (data !== 0) {
|
|
96
|
+
digit++;
|
|
97
|
+
data >>>= 1;
|
|
98
|
+
}
|
|
99
|
+
return digit;
|
|
100
|
+
};
|
|
101
|
+
exports.setToSJISFunction = function setToSJISFunction(f) {
|
|
102
|
+
if (typeof f !== "function") {
|
|
103
|
+
throw new Error('"toSJISFunc" is not a valid function.');
|
|
104
|
+
}
|
|
105
|
+
toSJISFunction = f;
|
|
106
|
+
};
|
|
107
|
+
exports.isKanjiModeEnabled = function() {
|
|
108
|
+
return typeof toSJISFunction !== "undefined";
|
|
109
|
+
};
|
|
110
|
+
exports.toSJIS = function toSJIS(kanji) {
|
|
111
|
+
return toSJISFunction(kanji);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/error-correction-level.js
|
|
117
|
+
var require_error_correction_level = __commonJS({
|
|
118
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/error-correction-level.js"(exports) {
|
|
119
|
+
exports.L = { bit: 1 };
|
|
120
|
+
exports.M = { bit: 0 };
|
|
121
|
+
exports.Q = { bit: 3 };
|
|
122
|
+
exports.H = { bit: 2 };
|
|
123
|
+
function fromString(string) {
|
|
124
|
+
if (typeof string !== "string") {
|
|
125
|
+
throw new Error("Param is not a string");
|
|
126
|
+
}
|
|
127
|
+
const lcStr = string.toLowerCase();
|
|
128
|
+
switch (lcStr) {
|
|
129
|
+
case "l":
|
|
130
|
+
case "low":
|
|
131
|
+
return exports.L;
|
|
132
|
+
case "m":
|
|
133
|
+
case "medium":
|
|
134
|
+
return exports.M;
|
|
135
|
+
case "q":
|
|
136
|
+
case "quartile":
|
|
137
|
+
return exports.Q;
|
|
138
|
+
case "h":
|
|
139
|
+
case "high":
|
|
140
|
+
return exports.H;
|
|
141
|
+
default:
|
|
142
|
+
throw new Error("Unknown EC Level: " + string);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.isValid = function isValid(level) {
|
|
146
|
+
return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
|
|
147
|
+
};
|
|
148
|
+
exports.from = function from(value, defaultValue) {
|
|
149
|
+
if (exports.isValid(value)) {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
return fromString(value);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
return defaultValue;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/bit-buffer.js
|
|
162
|
+
var require_bit_buffer = __commonJS({
|
|
163
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/bit-buffer.js"(exports, module) {
|
|
164
|
+
function BitBuffer() {
|
|
165
|
+
this.buffer = [];
|
|
166
|
+
this.length = 0;
|
|
167
|
+
}
|
|
168
|
+
BitBuffer.prototype = {
|
|
169
|
+
get: function(index) {
|
|
170
|
+
const bufIndex = Math.floor(index / 8);
|
|
171
|
+
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
|
|
172
|
+
},
|
|
173
|
+
put: function(num, length) {
|
|
174
|
+
for (let i = 0; i < length; i++) {
|
|
175
|
+
this.putBit((num >>> length - i - 1 & 1) === 1);
|
|
176
|
+
}
|
|
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) {
|
|
184
|
+
this.buffer.push(0);
|
|
185
|
+
}
|
|
186
|
+
if (bit) {
|
|
187
|
+
this.buffer[bufIndex] |= 128 >>> this.length % 8;
|
|
188
|
+
}
|
|
189
|
+
this.length++;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
module.exports = BitBuffer;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/bit-matrix.js
|
|
197
|
+
var require_bit_matrix = __commonJS({
|
|
198
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/bit-matrix.js"(exports, module) {
|
|
199
|
+
function BitMatrix(size) {
|
|
200
|
+
if (!size || size < 1) {
|
|
201
|
+
throw new Error("BitMatrix size must be defined and greater than 0");
|
|
202
|
+
}
|
|
203
|
+
this.size = size;
|
|
204
|
+
this.data = new Uint8Array(size * size);
|
|
205
|
+
this.reservedBit = new Uint8Array(size * size);
|
|
206
|
+
}
|
|
207
|
+
BitMatrix.prototype.set = function(row, col, value, reserved) {
|
|
208
|
+
const index = row * this.size + col;
|
|
209
|
+
this.data[index] = value;
|
|
210
|
+
if (reserved) this.reservedBit[index] = true;
|
|
211
|
+
};
|
|
212
|
+
BitMatrix.prototype.get = function(row, col) {
|
|
213
|
+
return this.data[row * this.size + col];
|
|
214
|
+
};
|
|
215
|
+
BitMatrix.prototype.xor = function(row, col, value) {
|
|
216
|
+
this.data[row * this.size + col] ^= value;
|
|
217
|
+
};
|
|
218
|
+
BitMatrix.prototype.isReserved = function(row, col) {
|
|
219
|
+
return this.reservedBit[row * this.size + col];
|
|
220
|
+
};
|
|
221
|
+
module.exports = BitMatrix;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/alignment-pattern.js
|
|
226
|
+
var require_alignment_pattern = __commonJS({
|
|
227
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/alignment-pattern.js"(exports) {
|
|
228
|
+
var getSymbolSize = require_utils().getSymbolSize;
|
|
229
|
+
exports.getRowColCoords = function getRowColCoords(version) {
|
|
230
|
+
if (version === 1) return [];
|
|
231
|
+
const posCount = Math.floor(version / 7) + 2;
|
|
232
|
+
const size = getSymbolSize(version);
|
|
233
|
+
const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
|
|
234
|
+
const positions = [size - 7];
|
|
235
|
+
for (let i = 1; i < posCount - 1; i++) {
|
|
236
|
+
positions[i] = positions[i - 1] - intervals;
|
|
237
|
+
}
|
|
238
|
+
positions.push(6);
|
|
239
|
+
return positions.reverse();
|
|
240
|
+
};
|
|
241
|
+
exports.getPositions = function getPositions(version) {
|
|
242
|
+
const coords = [];
|
|
243
|
+
const pos = exports.getRowColCoords(version);
|
|
244
|
+
const posLength = pos.length;
|
|
245
|
+
for (let i = 0; i < posLength; i++) {
|
|
246
|
+
for (let j = 0; j < posLength; j++) {
|
|
247
|
+
if (i === 0 && j === 0 || // top-left
|
|
248
|
+
i === 0 && j === posLength - 1 || // bottom-left
|
|
249
|
+
i === posLength - 1 && j === 0) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
coords.push([pos[i], pos[j]]);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return coords;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/finder-pattern.js
|
|
261
|
+
var require_finder_pattern = __commonJS({
|
|
262
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/finder-pattern.js"(exports) {
|
|
263
|
+
var getSymbolSize = require_utils().getSymbolSize;
|
|
264
|
+
var FINDER_PATTERN_SIZE = 7;
|
|
265
|
+
exports.getPositions = function getPositions(version) {
|
|
266
|
+
const size = getSymbolSize(version);
|
|
267
|
+
return [
|
|
268
|
+
// top-left
|
|
269
|
+
[0, 0],
|
|
270
|
+
// top-right
|
|
271
|
+
[size - FINDER_PATTERN_SIZE, 0],
|
|
272
|
+
// bottom-left
|
|
273
|
+
[0, size - FINDER_PATTERN_SIZE]
|
|
274
|
+
];
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/mask-pattern.js
|
|
280
|
+
var require_mask_pattern = __commonJS({
|
|
281
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/mask-pattern.js"(exports) {
|
|
282
|
+
exports.Patterns = {
|
|
283
|
+
PATTERN000: 0,
|
|
284
|
+
PATTERN001: 1,
|
|
285
|
+
PATTERN010: 2,
|
|
286
|
+
PATTERN011: 3,
|
|
287
|
+
PATTERN100: 4,
|
|
288
|
+
PATTERN101: 5,
|
|
289
|
+
PATTERN110: 6,
|
|
290
|
+
PATTERN111: 7
|
|
291
|
+
};
|
|
292
|
+
var PenaltyScores = {
|
|
293
|
+
N1: 3,
|
|
294
|
+
N2: 3,
|
|
295
|
+
N3: 40,
|
|
296
|
+
N4: 10
|
|
297
|
+
};
|
|
298
|
+
exports.isValid = function isValid(mask) {
|
|
299
|
+
return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
|
|
300
|
+
};
|
|
301
|
+
exports.from = function from(value) {
|
|
302
|
+
return exports.isValid(value) ? parseInt(value, 10) : void 0;
|
|
303
|
+
};
|
|
304
|
+
exports.getPenaltyN1 = function getPenaltyN1(data) {
|
|
305
|
+
const size = data.size;
|
|
306
|
+
let points = 0;
|
|
307
|
+
let sameCountCol = 0;
|
|
308
|
+
let sameCountRow = 0;
|
|
309
|
+
let lastCol = null;
|
|
310
|
+
let lastRow = null;
|
|
311
|
+
for (let row = 0; row < size; row++) {
|
|
312
|
+
sameCountCol = sameCountRow = 0;
|
|
313
|
+
lastCol = lastRow = null;
|
|
314
|
+
for (let col = 0; col < size; col++) {
|
|
315
|
+
let module2 = data.get(row, col);
|
|
316
|
+
if (module2 === lastCol) {
|
|
317
|
+
sameCountCol++;
|
|
318
|
+
} else {
|
|
319
|
+
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
320
|
+
lastCol = module2;
|
|
321
|
+
sameCountCol = 1;
|
|
322
|
+
}
|
|
323
|
+
module2 = data.get(col, row);
|
|
324
|
+
if (module2 === lastRow) {
|
|
325
|
+
sameCountRow++;
|
|
326
|
+
} else {
|
|
327
|
+
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
328
|
+
lastRow = module2;
|
|
329
|
+
sameCountRow = 1;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
333
|
+
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
334
|
+
}
|
|
335
|
+
return points;
|
|
336
|
+
};
|
|
337
|
+
exports.getPenaltyN2 = function getPenaltyN2(data) {
|
|
338
|
+
const size = data.size;
|
|
339
|
+
let points = 0;
|
|
340
|
+
for (let row = 0; row < size - 1; row++) {
|
|
341
|
+
for (let col = 0; col < size - 1; col++) {
|
|
342
|
+
const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
|
|
343
|
+
if (last === 4 || last === 0) points++;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return points * PenaltyScores.N2;
|
|
347
|
+
};
|
|
348
|
+
exports.getPenaltyN3 = function getPenaltyN3(data) {
|
|
349
|
+
const size = data.size;
|
|
350
|
+
let points = 0;
|
|
351
|
+
let bitsCol = 0;
|
|
352
|
+
let bitsRow = 0;
|
|
353
|
+
for (let row = 0; row < size; row++) {
|
|
354
|
+
bitsCol = bitsRow = 0;
|
|
355
|
+
for (let col = 0; col < size; col++) {
|
|
356
|
+
bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
|
|
357
|
+
if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
|
|
358
|
+
bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
|
|
359
|
+
if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return points * PenaltyScores.N3;
|
|
363
|
+
};
|
|
364
|
+
exports.getPenaltyN4 = function getPenaltyN4(data) {
|
|
365
|
+
let darkCount = 0;
|
|
366
|
+
const modulesCount = data.data.length;
|
|
367
|
+
for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
|
|
368
|
+
const k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
|
|
369
|
+
return k * PenaltyScores.N4;
|
|
370
|
+
};
|
|
371
|
+
function getMaskAt(maskPattern, i, j) {
|
|
372
|
+
switch (maskPattern) {
|
|
373
|
+
case exports.Patterns.PATTERN000:
|
|
374
|
+
return (i + j) % 2 === 0;
|
|
375
|
+
case exports.Patterns.PATTERN001:
|
|
376
|
+
return i % 2 === 0;
|
|
377
|
+
case exports.Patterns.PATTERN010:
|
|
378
|
+
return j % 3 === 0;
|
|
379
|
+
case exports.Patterns.PATTERN011:
|
|
380
|
+
return (i + j) % 3 === 0;
|
|
381
|
+
case exports.Patterns.PATTERN100:
|
|
382
|
+
return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
383
|
+
case exports.Patterns.PATTERN101:
|
|
384
|
+
return i * j % 2 + i * j % 3 === 0;
|
|
385
|
+
case exports.Patterns.PATTERN110:
|
|
386
|
+
return (i * j % 2 + i * j % 3) % 2 === 0;
|
|
387
|
+
case exports.Patterns.PATTERN111:
|
|
388
|
+
return (i * j % 3 + (i + j) % 2) % 2 === 0;
|
|
389
|
+
default:
|
|
390
|
+
throw new Error("bad maskPattern:" + maskPattern);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
exports.applyMask = function applyMask(pattern, data) {
|
|
394
|
+
const size = data.size;
|
|
395
|
+
for (let col = 0; col < size; col++) {
|
|
396
|
+
for (let row = 0; row < size; row++) {
|
|
397
|
+
if (data.isReserved(row, col)) continue;
|
|
398
|
+
data.xor(row, col, getMaskAt(pattern, row, col));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
exports.getBestMask = function getBestMask(data, setupFormatFunc) {
|
|
403
|
+
const numPatterns = Object.keys(exports.Patterns).length;
|
|
404
|
+
let bestPattern = 0;
|
|
405
|
+
let lowerPenalty = Infinity;
|
|
406
|
+
for (let p = 0; p < numPatterns; p++) {
|
|
407
|
+
setupFormatFunc(p);
|
|
408
|
+
exports.applyMask(p, data);
|
|
409
|
+
const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
|
|
410
|
+
exports.applyMask(p, data);
|
|
411
|
+
if (penalty < lowerPenalty) {
|
|
412
|
+
lowerPenalty = penalty;
|
|
413
|
+
bestPattern = p;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return bestPattern;
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/error-correction-code.js
|
|
422
|
+
var require_error_correction_code = __commonJS({
|
|
423
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/error-correction-code.js"(exports) {
|
|
424
|
+
var ECLevel = require_error_correction_level();
|
|
425
|
+
var EC_BLOCKS_TABLE = [
|
|
426
|
+
// L M Q H
|
|
427
|
+
1,
|
|
428
|
+
1,
|
|
429
|
+
1,
|
|
430
|
+
1,
|
|
431
|
+
1,
|
|
432
|
+
1,
|
|
433
|
+
1,
|
|
434
|
+
1,
|
|
435
|
+
1,
|
|
436
|
+
1,
|
|
437
|
+
2,
|
|
438
|
+
2,
|
|
439
|
+
1,
|
|
440
|
+
2,
|
|
441
|
+
2,
|
|
442
|
+
4,
|
|
443
|
+
1,
|
|
444
|
+
2,
|
|
445
|
+
4,
|
|
446
|
+
4,
|
|
447
|
+
2,
|
|
448
|
+
4,
|
|
449
|
+
4,
|
|
450
|
+
4,
|
|
451
|
+
2,
|
|
452
|
+
4,
|
|
453
|
+
6,
|
|
454
|
+
5,
|
|
455
|
+
2,
|
|
456
|
+
4,
|
|
457
|
+
6,
|
|
458
|
+
6,
|
|
459
|
+
2,
|
|
460
|
+
5,
|
|
461
|
+
8,
|
|
462
|
+
8,
|
|
463
|
+
4,
|
|
464
|
+
5,
|
|
465
|
+
8,
|
|
466
|
+
8,
|
|
467
|
+
4,
|
|
468
|
+
5,
|
|
469
|
+
8,
|
|
470
|
+
11,
|
|
471
|
+
4,
|
|
472
|
+
8,
|
|
473
|
+
10,
|
|
474
|
+
11,
|
|
475
|
+
4,
|
|
476
|
+
9,
|
|
477
|
+
12,
|
|
478
|
+
16,
|
|
479
|
+
4,
|
|
480
|
+
9,
|
|
481
|
+
16,
|
|
482
|
+
16,
|
|
483
|
+
6,
|
|
484
|
+
10,
|
|
485
|
+
12,
|
|
486
|
+
18,
|
|
487
|
+
6,
|
|
488
|
+
10,
|
|
489
|
+
17,
|
|
490
|
+
16,
|
|
491
|
+
6,
|
|
492
|
+
11,
|
|
493
|
+
16,
|
|
494
|
+
19,
|
|
495
|
+
6,
|
|
496
|
+
13,
|
|
497
|
+
18,
|
|
498
|
+
21,
|
|
499
|
+
7,
|
|
500
|
+
14,
|
|
501
|
+
21,
|
|
502
|
+
25,
|
|
503
|
+
8,
|
|
504
|
+
16,
|
|
505
|
+
20,
|
|
506
|
+
25,
|
|
507
|
+
8,
|
|
508
|
+
17,
|
|
509
|
+
23,
|
|
510
|
+
25,
|
|
511
|
+
9,
|
|
512
|
+
17,
|
|
513
|
+
23,
|
|
514
|
+
34,
|
|
515
|
+
9,
|
|
516
|
+
18,
|
|
517
|
+
25,
|
|
518
|
+
30,
|
|
519
|
+
10,
|
|
520
|
+
20,
|
|
521
|
+
27,
|
|
522
|
+
32,
|
|
523
|
+
12,
|
|
524
|
+
21,
|
|
525
|
+
29,
|
|
526
|
+
35,
|
|
527
|
+
12,
|
|
528
|
+
23,
|
|
529
|
+
34,
|
|
530
|
+
37,
|
|
531
|
+
12,
|
|
532
|
+
25,
|
|
533
|
+
34,
|
|
534
|
+
40,
|
|
535
|
+
13,
|
|
536
|
+
26,
|
|
537
|
+
35,
|
|
538
|
+
42,
|
|
539
|
+
14,
|
|
540
|
+
28,
|
|
541
|
+
38,
|
|
542
|
+
45,
|
|
543
|
+
15,
|
|
544
|
+
29,
|
|
545
|
+
40,
|
|
546
|
+
48,
|
|
547
|
+
16,
|
|
548
|
+
31,
|
|
549
|
+
43,
|
|
550
|
+
51,
|
|
551
|
+
17,
|
|
552
|
+
33,
|
|
553
|
+
45,
|
|
554
|
+
54,
|
|
555
|
+
18,
|
|
556
|
+
35,
|
|
557
|
+
48,
|
|
558
|
+
57,
|
|
559
|
+
19,
|
|
560
|
+
37,
|
|
561
|
+
51,
|
|
562
|
+
60,
|
|
563
|
+
19,
|
|
564
|
+
38,
|
|
565
|
+
53,
|
|
566
|
+
63,
|
|
567
|
+
20,
|
|
568
|
+
40,
|
|
569
|
+
56,
|
|
570
|
+
66,
|
|
571
|
+
21,
|
|
572
|
+
43,
|
|
573
|
+
59,
|
|
574
|
+
70,
|
|
575
|
+
22,
|
|
576
|
+
45,
|
|
577
|
+
62,
|
|
578
|
+
74,
|
|
579
|
+
24,
|
|
580
|
+
47,
|
|
581
|
+
65,
|
|
582
|
+
77,
|
|
583
|
+
25,
|
|
584
|
+
49,
|
|
585
|
+
68,
|
|
586
|
+
81
|
|
587
|
+
];
|
|
588
|
+
var EC_CODEWORDS_TABLE = [
|
|
589
|
+
// L M Q H
|
|
590
|
+
7,
|
|
591
|
+
10,
|
|
592
|
+
13,
|
|
593
|
+
17,
|
|
594
|
+
10,
|
|
595
|
+
16,
|
|
596
|
+
22,
|
|
597
|
+
28,
|
|
598
|
+
15,
|
|
599
|
+
26,
|
|
600
|
+
36,
|
|
601
|
+
44,
|
|
602
|
+
20,
|
|
603
|
+
36,
|
|
604
|
+
52,
|
|
605
|
+
64,
|
|
606
|
+
26,
|
|
607
|
+
48,
|
|
608
|
+
72,
|
|
609
|
+
88,
|
|
610
|
+
36,
|
|
611
|
+
64,
|
|
612
|
+
96,
|
|
613
|
+
112,
|
|
614
|
+
40,
|
|
615
|
+
72,
|
|
616
|
+
108,
|
|
617
|
+
130,
|
|
618
|
+
48,
|
|
619
|
+
88,
|
|
620
|
+
132,
|
|
621
|
+
156,
|
|
622
|
+
60,
|
|
623
|
+
110,
|
|
624
|
+
160,
|
|
625
|
+
192,
|
|
626
|
+
72,
|
|
627
|
+
130,
|
|
628
|
+
192,
|
|
629
|
+
224,
|
|
630
|
+
80,
|
|
631
|
+
150,
|
|
632
|
+
224,
|
|
633
|
+
264,
|
|
634
|
+
96,
|
|
635
|
+
176,
|
|
636
|
+
260,
|
|
637
|
+
308,
|
|
638
|
+
104,
|
|
639
|
+
198,
|
|
640
|
+
288,
|
|
641
|
+
352,
|
|
642
|
+
120,
|
|
643
|
+
216,
|
|
644
|
+
320,
|
|
645
|
+
384,
|
|
646
|
+
132,
|
|
647
|
+
240,
|
|
648
|
+
360,
|
|
649
|
+
432,
|
|
650
|
+
144,
|
|
651
|
+
280,
|
|
652
|
+
408,
|
|
653
|
+
480,
|
|
654
|
+
168,
|
|
655
|
+
308,
|
|
656
|
+
448,
|
|
657
|
+
532,
|
|
658
|
+
180,
|
|
659
|
+
338,
|
|
660
|
+
504,
|
|
661
|
+
588,
|
|
662
|
+
196,
|
|
663
|
+
364,
|
|
664
|
+
546,
|
|
665
|
+
650,
|
|
666
|
+
224,
|
|
667
|
+
416,
|
|
668
|
+
600,
|
|
669
|
+
700,
|
|
670
|
+
224,
|
|
671
|
+
442,
|
|
672
|
+
644,
|
|
673
|
+
750,
|
|
674
|
+
252,
|
|
675
|
+
476,
|
|
676
|
+
690,
|
|
677
|
+
816,
|
|
678
|
+
270,
|
|
679
|
+
504,
|
|
680
|
+
750,
|
|
681
|
+
900,
|
|
682
|
+
300,
|
|
683
|
+
560,
|
|
684
|
+
810,
|
|
685
|
+
960,
|
|
686
|
+
312,
|
|
687
|
+
588,
|
|
688
|
+
870,
|
|
689
|
+
1050,
|
|
690
|
+
336,
|
|
691
|
+
644,
|
|
692
|
+
952,
|
|
693
|
+
1110,
|
|
694
|
+
360,
|
|
695
|
+
700,
|
|
696
|
+
1020,
|
|
697
|
+
1200,
|
|
698
|
+
390,
|
|
699
|
+
728,
|
|
700
|
+
1050,
|
|
701
|
+
1260,
|
|
702
|
+
420,
|
|
703
|
+
784,
|
|
704
|
+
1140,
|
|
705
|
+
1350,
|
|
706
|
+
450,
|
|
707
|
+
812,
|
|
708
|
+
1200,
|
|
709
|
+
1440,
|
|
710
|
+
480,
|
|
711
|
+
868,
|
|
712
|
+
1290,
|
|
713
|
+
1530,
|
|
714
|
+
510,
|
|
715
|
+
924,
|
|
716
|
+
1350,
|
|
717
|
+
1620,
|
|
718
|
+
540,
|
|
719
|
+
980,
|
|
720
|
+
1440,
|
|
721
|
+
1710,
|
|
722
|
+
570,
|
|
723
|
+
1036,
|
|
724
|
+
1530,
|
|
725
|
+
1800,
|
|
726
|
+
570,
|
|
727
|
+
1064,
|
|
728
|
+
1590,
|
|
729
|
+
1890,
|
|
730
|
+
600,
|
|
731
|
+
1120,
|
|
732
|
+
1680,
|
|
733
|
+
1980,
|
|
734
|
+
630,
|
|
735
|
+
1204,
|
|
736
|
+
1770,
|
|
737
|
+
2100,
|
|
738
|
+
660,
|
|
739
|
+
1260,
|
|
740
|
+
1860,
|
|
741
|
+
2220,
|
|
742
|
+
720,
|
|
743
|
+
1316,
|
|
744
|
+
1950,
|
|
745
|
+
2310,
|
|
746
|
+
750,
|
|
747
|
+
1372,
|
|
748
|
+
2040,
|
|
749
|
+
2430
|
|
750
|
+
];
|
|
751
|
+
exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
|
|
752
|
+
switch (errorCorrectionLevel) {
|
|
753
|
+
case ECLevel.L:
|
|
754
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
|
|
755
|
+
case ECLevel.M:
|
|
756
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
|
|
757
|
+
case ECLevel.Q:
|
|
758
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
|
|
759
|
+
case ECLevel.H:
|
|
760
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
|
|
761
|
+
default:
|
|
762
|
+
return void 0;
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
|
|
766
|
+
switch (errorCorrectionLevel) {
|
|
767
|
+
case ECLevel.L:
|
|
768
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
|
|
769
|
+
case ECLevel.M:
|
|
770
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
|
|
771
|
+
case ECLevel.Q:
|
|
772
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
|
|
773
|
+
case ECLevel.H:
|
|
774
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
|
|
775
|
+
default:
|
|
776
|
+
return void 0;
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/galois-field.js
|
|
783
|
+
var require_galois_field = __commonJS({
|
|
784
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/galois-field.js"(exports) {
|
|
785
|
+
var EXP_TABLE = new Uint8Array(512);
|
|
786
|
+
var LOG_TABLE = new Uint8Array(256);
|
|
787
|
+
(function initTables() {
|
|
788
|
+
let x = 1;
|
|
789
|
+
for (let i = 0; i < 255; i++) {
|
|
790
|
+
EXP_TABLE[i] = x;
|
|
791
|
+
LOG_TABLE[x] = i;
|
|
792
|
+
x <<= 1;
|
|
793
|
+
if (x & 256) {
|
|
794
|
+
x ^= 285;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
for (let i = 255; i < 512; i++) {
|
|
798
|
+
EXP_TABLE[i] = EXP_TABLE[i - 255];
|
|
799
|
+
}
|
|
800
|
+
})();
|
|
801
|
+
exports.log = function log(n) {
|
|
802
|
+
if (n < 1) throw new Error("log(" + n + ")");
|
|
803
|
+
return LOG_TABLE[n];
|
|
804
|
+
};
|
|
805
|
+
exports.exp = function exp(n) {
|
|
806
|
+
return EXP_TABLE[n];
|
|
807
|
+
};
|
|
808
|
+
exports.mul = function mul(x, y) {
|
|
809
|
+
if (x === 0 || y === 0) return 0;
|
|
810
|
+
return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/polynomial.js
|
|
816
|
+
var require_polynomial = __commonJS({
|
|
817
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/polynomial.js"(exports) {
|
|
818
|
+
var GF = require_galois_field();
|
|
819
|
+
exports.mul = function mul(p1, p2) {
|
|
820
|
+
const coeff = new Uint8Array(p1.length + p2.length - 1);
|
|
821
|
+
for (let i = 0; i < p1.length; i++) {
|
|
822
|
+
for (let j = 0; j < p2.length; j++) {
|
|
823
|
+
coeff[i + j] ^= GF.mul(p1[i], p2[j]);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return coeff;
|
|
827
|
+
};
|
|
828
|
+
exports.mod = function mod(divident, divisor) {
|
|
829
|
+
let result = new Uint8Array(divident);
|
|
830
|
+
while (result.length - divisor.length >= 0) {
|
|
831
|
+
const coeff = result[0];
|
|
832
|
+
for (let i = 0; i < divisor.length; i++) {
|
|
833
|
+
result[i] ^= GF.mul(divisor[i], coeff);
|
|
834
|
+
}
|
|
835
|
+
let offset = 0;
|
|
836
|
+
while (offset < result.length && result[offset] === 0) offset++;
|
|
837
|
+
result = result.slice(offset);
|
|
838
|
+
}
|
|
839
|
+
return result;
|
|
840
|
+
};
|
|
841
|
+
exports.generateECPolynomial = function generateECPolynomial(degree) {
|
|
842
|
+
let poly = new Uint8Array([1]);
|
|
843
|
+
for (let i = 0; i < degree; i++) {
|
|
844
|
+
poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
|
|
845
|
+
}
|
|
846
|
+
return poly;
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/reed-solomon-encoder.js
|
|
852
|
+
var require_reed_solomon_encoder = __commonJS({
|
|
853
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/reed-solomon-encoder.js"(exports, module) {
|
|
854
|
+
var Polynomial = require_polynomial();
|
|
855
|
+
function ReedSolomonEncoder(degree) {
|
|
856
|
+
this.genPoly = void 0;
|
|
857
|
+
this.degree = degree;
|
|
858
|
+
if (this.degree) this.initialize(this.degree);
|
|
859
|
+
}
|
|
860
|
+
ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
|
|
861
|
+
this.degree = degree;
|
|
862
|
+
this.genPoly = Polynomial.generateECPolynomial(this.degree);
|
|
863
|
+
};
|
|
864
|
+
ReedSolomonEncoder.prototype.encode = function encode(data) {
|
|
865
|
+
if (!this.genPoly) {
|
|
866
|
+
throw new Error("Encoder not initialized");
|
|
867
|
+
}
|
|
868
|
+
const paddedData = new Uint8Array(data.length + this.degree);
|
|
869
|
+
paddedData.set(data);
|
|
870
|
+
const remainder = Polynomial.mod(paddedData, this.genPoly);
|
|
871
|
+
const start = this.degree - remainder.length;
|
|
872
|
+
if (start > 0) {
|
|
873
|
+
const buff = new Uint8Array(this.degree);
|
|
874
|
+
buff.set(remainder, start);
|
|
875
|
+
return buff;
|
|
876
|
+
}
|
|
877
|
+
return remainder;
|
|
878
|
+
};
|
|
879
|
+
module.exports = ReedSolomonEncoder;
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/version-check.js
|
|
884
|
+
var require_version_check = __commonJS({
|
|
885
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/version-check.js"(exports) {
|
|
886
|
+
exports.isValid = function isValid(version) {
|
|
887
|
+
return !isNaN(version) && version >= 1 && version <= 40;
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/regex.js
|
|
893
|
+
var require_regex = __commonJS({
|
|
894
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/regex.js"(exports) {
|
|
895
|
+
var numeric = "[0-9]+";
|
|
896
|
+
var alphanumeric = "[A-Z $%*+\\-./:]+";
|
|
897
|
+
var kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
|
|
898
|
+
kanji = kanji.replace(/u/g, "\\u");
|
|
899
|
+
var byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + ")(?:.|[\r\n]))+";
|
|
900
|
+
exports.KANJI = new RegExp(kanji, "g");
|
|
901
|
+
exports.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
|
|
902
|
+
exports.BYTE = new RegExp(byte, "g");
|
|
903
|
+
exports.NUMERIC = new RegExp(numeric, "g");
|
|
904
|
+
exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
|
|
905
|
+
var TEST_KANJI = new RegExp("^" + kanji + "$");
|
|
906
|
+
var TEST_NUMERIC = new RegExp("^" + numeric + "$");
|
|
907
|
+
var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
|
|
908
|
+
exports.testKanji = function testKanji(str) {
|
|
909
|
+
return TEST_KANJI.test(str);
|
|
910
|
+
};
|
|
911
|
+
exports.testNumeric = function testNumeric(str) {
|
|
912
|
+
return TEST_NUMERIC.test(str);
|
|
913
|
+
};
|
|
914
|
+
exports.testAlphanumeric = function testAlphanumeric(str) {
|
|
915
|
+
return TEST_ALPHANUMERIC.test(str);
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/mode.js
|
|
921
|
+
var require_mode = __commonJS({
|
|
922
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/mode.js"(exports) {
|
|
923
|
+
var VersionCheck = require_version_check();
|
|
924
|
+
var Regex = require_regex();
|
|
925
|
+
exports.NUMERIC = {
|
|
926
|
+
id: "Numeric",
|
|
927
|
+
bit: 1 << 0,
|
|
928
|
+
ccBits: [10, 12, 14]
|
|
929
|
+
};
|
|
930
|
+
exports.ALPHANUMERIC = {
|
|
931
|
+
id: "Alphanumeric",
|
|
932
|
+
bit: 1 << 1,
|
|
933
|
+
ccBits: [9, 11, 13]
|
|
934
|
+
};
|
|
935
|
+
exports.BYTE = {
|
|
936
|
+
id: "Byte",
|
|
937
|
+
bit: 1 << 2,
|
|
938
|
+
ccBits: [8, 16, 16]
|
|
939
|
+
};
|
|
940
|
+
exports.KANJI = {
|
|
941
|
+
id: "Kanji",
|
|
942
|
+
bit: 1 << 3,
|
|
943
|
+
ccBits: [8, 10, 12]
|
|
944
|
+
};
|
|
945
|
+
exports.MIXED = {
|
|
946
|
+
bit: -1
|
|
947
|
+
};
|
|
948
|
+
exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
|
|
949
|
+
if (!mode.ccBits) throw new Error("Invalid mode: " + mode);
|
|
950
|
+
if (!VersionCheck.isValid(version)) {
|
|
951
|
+
throw new Error("Invalid version: " + version);
|
|
952
|
+
}
|
|
953
|
+
if (version >= 1 && version < 10) return mode.ccBits[0];
|
|
954
|
+
else if (version < 27) return mode.ccBits[1];
|
|
955
|
+
return mode.ccBits[2];
|
|
956
|
+
};
|
|
957
|
+
exports.getBestModeForData = function getBestModeForData(dataStr) {
|
|
958
|
+
if (Regex.testNumeric(dataStr)) return exports.NUMERIC;
|
|
959
|
+
else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;
|
|
960
|
+
else if (Regex.testKanji(dataStr)) return exports.KANJI;
|
|
961
|
+
else return exports.BYTE;
|
|
962
|
+
};
|
|
963
|
+
exports.toString = function toString(mode) {
|
|
964
|
+
if (mode && mode.id) return mode.id;
|
|
965
|
+
throw new Error("Invalid mode");
|
|
966
|
+
};
|
|
967
|
+
exports.isValid = function isValid(mode) {
|
|
968
|
+
return mode && mode.bit && mode.ccBits;
|
|
969
|
+
};
|
|
970
|
+
function fromString(string) {
|
|
971
|
+
if (typeof string !== "string") {
|
|
972
|
+
throw new Error("Param is not a string");
|
|
973
|
+
}
|
|
974
|
+
const lcStr = string.toLowerCase();
|
|
975
|
+
switch (lcStr) {
|
|
976
|
+
case "numeric":
|
|
977
|
+
return exports.NUMERIC;
|
|
978
|
+
case "alphanumeric":
|
|
979
|
+
return exports.ALPHANUMERIC;
|
|
980
|
+
case "kanji":
|
|
981
|
+
return exports.KANJI;
|
|
982
|
+
case "byte":
|
|
983
|
+
return exports.BYTE;
|
|
984
|
+
default:
|
|
985
|
+
throw new Error("Unknown mode: " + string);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
exports.from = function from(value, defaultValue) {
|
|
989
|
+
if (exports.isValid(value)) {
|
|
990
|
+
return value;
|
|
991
|
+
}
|
|
992
|
+
try {
|
|
993
|
+
return fromString(value);
|
|
994
|
+
} catch (e) {
|
|
995
|
+
return defaultValue;
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/version.js
|
|
1002
|
+
var require_version = __commonJS({
|
|
1003
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/version.js"(exports) {
|
|
1004
|
+
var Utils = require_utils();
|
|
1005
|
+
var ECCode = require_error_correction_code();
|
|
1006
|
+
var ECLevel = require_error_correction_level();
|
|
1007
|
+
var Mode = require_mode();
|
|
1008
|
+
var VersionCheck = require_version_check();
|
|
1009
|
+
var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
|
|
1010
|
+
var G18_BCH = Utils.getBCHDigit(G18);
|
|
1011
|
+
function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
|
|
1012
|
+
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
1013
|
+
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
|
|
1014
|
+
return currentVersion;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return void 0;
|
|
1018
|
+
}
|
|
1019
|
+
function getReservedBitsCount(mode, version) {
|
|
1020
|
+
return Mode.getCharCountIndicator(mode, version) + 4;
|
|
1021
|
+
}
|
|
1022
|
+
function getTotalBitsFromDataArray(segments, version) {
|
|
1023
|
+
let totalBits = 0;
|
|
1024
|
+
segments.forEach(function(data) {
|
|
1025
|
+
const reservedBits = getReservedBitsCount(data.mode, version);
|
|
1026
|
+
totalBits += reservedBits + data.getBitsLength();
|
|
1027
|
+
});
|
|
1028
|
+
return totalBits;
|
|
1029
|
+
}
|
|
1030
|
+
function getBestVersionForMixedData(segments, errorCorrectionLevel) {
|
|
1031
|
+
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
1032
|
+
const length = getTotalBitsFromDataArray(segments, currentVersion);
|
|
1033
|
+
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
|
|
1034
|
+
return currentVersion;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return void 0;
|
|
1038
|
+
}
|
|
1039
|
+
exports.from = function from(value, defaultValue) {
|
|
1040
|
+
if (VersionCheck.isValid(value)) {
|
|
1041
|
+
return parseInt(value, 10);
|
|
1042
|
+
}
|
|
1043
|
+
return defaultValue;
|
|
1044
|
+
};
|
|
1045
|
+
exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
|
|
1046
|
+
if (!VersionCheck.isValid(version)) {
|
|
1047
|
+
throw new Error("Invalid QR Code version");
|
|
1048
|
+
}
|
|
1049
|
+
if (typeof mode === "undefined") mode = Mode.BYTE;
|
|
1050
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1051
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1052
|
+
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
1053
|
+
if (mode === Mode.MIXED) return dataTotalCodewordsBits;
|
|
1054
|
+
const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
|
|
1055
|
+
switch (mode) {
|
|
1056
|
+
case Mode.NUMERIC:
|
|
1057
|
+
return Math.floor(usableBits / 10 * 3);
|
|
1058
|
+
case Mode.ALPHANUMERIC:
|
|
1059
|
+
return Math.floor(usableBits / 11 * 2);
|
|
1060
|
+
case Mode.KANJI:
|
|
1061
|
+
return Math.floor(usableBits / 13);
|
|
1062
|
+
case Mode.BYTE:
|
|
1063
|
+
default:
|
|
1064
|
+
return Math.floor(usableBits / 8);
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
|
|
1068
|
+
let seg;
|
|
1069
|
+
const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
|
|
1070
|
+
if (Array.isArray(data)) {
|
|
1071
|
+
if (data.length > 1) {
|
|
1072
|
+
return getBestVersionForMixedData(data, ecl);
|
|
1073
|
+
}
|
|
1074
|
+
if (data.length === 0) {
|
|
1075
|
+
return 1;
|
|
1076
|
+
}
|
|
1077
|
+
seg = data[0];
|
|
1078
|
+
} else {
|
|
1079
|
+
seg = data;
|
|
1080
|
+
}
|
|
1081
|
+
return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
|
|
1082
|
+
};
|
|
1083
|
+
exports.getEncodedBits = function getEncodedBits(version) {
|
|
1084
|
+
if (!VersionCheck.isValid(version) || version < 7) {
|
|
1085
|
+
throw new Error("Invalid QR Code version");
|
|
1086
|
+
}
|
|
1087
|
+
let d = version << 12;
|
|
1088
|
+
while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
|
|
1089
|
+
d ^= G18 << Utils.getBCHDigit(d) - G18_BCH;
|
|
1090
|
+
}
|
|
1091
|
+
return version << 12 | d;
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/format-info.js
|
|
1097
|
+
var require_format_info = __commonJS({
|
|
1098
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/format-info.js"(exports) {
|
|
1099
|
+
var Utils = require_utils();
|
|
1100
|
+
var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
|
|
1101
|
+
var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
|
|
1102
|
+
var G15_BCH = Utils.getBCHDigit(G15);
|
|
1103
|
+
exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
|
|
1104
|
+
const data = errorCorrectionLevel.bit << 3 | mask;
|
|
1105
|
+
let d = data << 10;
|
|
1106
|
+
while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
|
|
1107
|
+
d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;
|
|
1108
|
+
}
|
|
1109
|
+
return (data << 10 | d) ^ G15_MASK;
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/numeric-data.js
|
|
1115
|
+
var require_numeric_data = __commonJS({
|
|
1116
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/numeric-data.js"(exports, module) {
|
|
1117
|
+
var Mode = require_mode();
|
|
1118
|
+
function NumericData(data) {
|
|
1119
|
+
this.mode = Mode.NUMERIC;
|
|
1120
|
+
this.data = data.toString();
|
|
1121
|
+
}
|
|
1122
|
+
NumericData.getBitsLength = function getBitsLength(length) {
|
|
1123
|
+
return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
|
|
1124
|
+
};
|
|
1125
|
+
NumericData.prototype.getLength = function getLength() {
|
|
1126
|
+
return this.data.length;
|
|
1127
|
+
};
|
|
1128
|
+
NumericData.prototype.getBitsLength = function getBitsLength() {
|
|
1129
|
+
return NumericData.getBitsLength(this.data.length);
|
|
1130
|
+
};
|
|
1131
|
+
NumericData.prototype.write = function write(bitBuffer) {
|
|
1132
|
+
let i, group, value;
|
|
1133
|
+
for (i = 0; i + 3 <= this.data.length; i += 3) {
|
|
1134
|
+
group = this.data.substr(i, 3);
|
|
1135
|
+
value = parseInt(group, 10);
|
|
1136
|
+
bitBuffer.put(value, 10);
|
|
1137
|
+
}
|
|
1138
|
+
const remainingNum = this.data.length - i;
|
|
1139
|
+
if (remainingNum > 0) {
|
|
1140
|
+
group = this.data.substr(i);
|
|
1141
|
+
value = parseInt(group, 10);
|
|
1142
|
+
bitBuffer.put(value, remainingNum * 3 + 1);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
module.exports = NumericData;
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/alphanumeric-data.js
|
|
1150
|
+
var require_alphanumeric_data = __commonJS({
|
|
1151
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/alphanumeric-data.js"(exports, module) {
|
|
1152
|
+
var Mode = require_mode();
|
|
1153
|
+
var ALPHA_NUM_CHARS = [
|
|
1154
|
+
"0",
|
|
1155
|
+
"1",
|
|
1156
|
+
"2",
|
|
1157
|
+
"3",
|
|
1158
|
+
"4",
|
|
1159
|
+
"5",
|
|
1160
|
+
"6",
|
|
1161
|
+
"7",
|
|
1162
|
+
"8",
|
|
1163
|
+
"9",
|
|
1164
|
+
"A",
|
|
1165
|
+
"B",
|
|
1166
|
+
"C",
|
|
1167
|
+
"D",
|
|
1168
|
+
"E",
|
|
1169
|
+
"F",
|
|
1170
|
+
"G",
|
|
1171
|
+
"H",
|
|
1172
|
+
"I",
|
|
1173
|
+
"J",
|
|
1174
|
+
"K",
|
|
1175
|
+
"L",
|
|
1176
|
+
"M",
|
|
1177
|
+
"N",
|
|
1178
|
+
"O",
|
|
1179
|
+
"P",
|
|
1180
|
+
"Q",
|
|
1181
|
+
"R",
|
|
1182
|
+
"S",
|
|
1183
|
+
"T",
|
|
1184
|
+
"U",
|
|
1185
|
+
"V",
|
|
1186
|
+
"W",
|
|
1187
|
+
"X",
|
|
1188
|
+
"Y",
|
|
1189
|
+
"Z",
|
|
1190
|
+
" ",
|
|
1191
|
+
"$",
|
|
1192
|
+
"%",
|
|
1193
|
+
"*",
|
|
1194
|
+
"+",
|
|
1195
|
+
"-",
|
|
1196
|
+
".",
|
|
1197
|
+
"/",
|
|
1198
|
+
":"
|
|
1199
|
+
];
|
|
1200
|
+
function AlphanumericData(data) {
|
|
1201
|
+
this.mode = Mode.ALPHANUMERIC;
|
|
1202
|
+
this.data = data;
|
|
1203
|
+
}
|
|
1204
|
+
AlphanumericData.getBitsLength = function getBitsLength(length) {
|
|
1205
|
+
return 11 * Math.floor(length / 2) + 6 * (length % 2);
|
|
1206
|
+
};
|
|
1207
|
+
AlphanumericData.prototype.getLength = function getLength() {
|
|
1208
|
+
return this.data.length;
|
|
1209
|
+
};
|
|
1210
|
+
AlphanumericData.prototype.getBitsLength = function getBitsLength() {
|
|
1211
|
+
return AlphanumericData.getBitsLength(this.data.length);
|
|
1212
|
+
};
|
|
1213
|
+
AlphanumericData.prototype.write = function write(bitBuffer) {
|
|
1214
|
+
let i;
|
|
1215
|
+
for (i = 0; i + 2 <= this.data.length; i += 2) {
|
|
1216
|
+
let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
|
|
1217
|
+
value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
|
|
1218
|
+
bitBuffer.put(value, 11);
|
|
1219
|
+
}
|
|
1220
|
+
if (this.data.length % 2) {
|
|
1221
|
+
bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
module.exports = AlphanumericData;
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/byte-data.js
|
|
1229
|
+
var require_byte_data = __commonJS({
|
|
1230
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/byte-data.js"(exports, module) {
|
|
1231
|
+
var Mode = require_mode();
|
|
1232
|
+
function ByteData(data) {
|
|
1233
|
+
this.mode = Mode.BYTE;
|
|
1234
|
+
if (typeof data === "string") {
|
|
1235
|
+
this.data = new TextEncoder().encode(data);
|
|
1236
|
+
} else {
|
|
1237
|
+
this.data = new Uint8Array(data);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
ByteData.getBitsLength = function getBitsLength(length) {
|
|
1241
|
+
return length * 8;
|
|
1242
|
+
};
|
|
1243
|
+
ByteData.prototype.getLength = function getLength() {
|
|
1244
|
+
return this.data.length;
|
|
1245
|
+
};
|
|
1246
|
+
ByteData.prototype.getBitsLength = function getBitsLength() {
|
|
1247
|
+
return ByteData.getBitsLength(this.data.length);
|
|
1248
|
+
};
|
|
1249
|
+
ByteData.prototype.write = function(bitBuffer) {
|
|
1250
|
+
for (let i = 0, l = this.data.length; i < l; i++) {
|
|
1251
|
+
bitBuffer.put(this.data[i], 8);
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
module.exports = ByteData;
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/kanji-data.js
|
|
1259
|
+
var require_kanji_data = __commonJS({
|
|
1260
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/kanji-data.js"(exports, module) {
|
|
1261
|
+
var Mode = require_mode();
|
|
1262
|
+
var Utils = require_utils();
|
|
1263
|
+
function KanjiData(data) {
|
|
1264
|
+
this.mode = Mode.KANJI;
|
|
1265
|
+
this.data = data;
|
|
1266
|
+
}
|
|
1267
|
+
KanjiData.getBitsLength = function getBitsLength(length) {
|
|
1268
|
+
return length * 13;
|
|
1269
|
+
};
|
|
1270
|
+
KanjiData.prototype.getLength = function getLength() {
|
|
1271
|
+
return this.data.length;
|
|
1272
|
+
};
|
|
1273
|
+
KanjiData.prototype.getBitsLength = function getBitsLength() {
|
|
1274
|
+
return KanjiData.getBitsLength(this.data.length);
|
|
1275
|
+
};
|
|
1276
|
+
KanjiData.prototype.write = function(bitBuffer) {
|
|
1277
|
+
let i;
|
|
1278
|
+
for (i = 0; i < this.data.length; i++) {
|
|
1279
|
+
let value = Utils.toSJIS(this.data[i]);
|
|
1280
|
+
if (value >= 33088 && value <= 40956) {
|
|
1281
|
+
value -= 33088;
|
|
1282
|
+
} else if (value >= 57408 && value <= 60351) {
|
|
1283
|
+
value -= 49472;
|
|
1284
|
+
} else {
|
|
1285
|
+
throw new Error(
|
|
1286
|
+
"Invalid SJIS character: " + this.data[i] + "\nMake sure your charset is UTF-8"
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
value = (value >>> 8 & 255) * 192 + (value & 255);
|
|
1290
|
+
bitBuffer.put(value, 13);
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
module.exports = KanjiData;
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
|
|
1297
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/dijkstrajs/dijkstra.js
|
|
1298
|
+
var require_dijkstra = __commonJS({
|
|
1299
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/dijkstrajs/dijkstra.js"(exports, module) {
|
|
1300
|
+
"use strict";
|
|
1301
|
+
var dijkstra = {
|
|
1302
|
+
single_source_shortest_paths: function(graph, s, d) {
|
|
1303
|
+
var predecessors = {};
|
|
1304
|
+
var costs = {};
|
|
1305
|
+
costs[s] = 0;
|
|
1306
|
+
var open = dijkstra.PriorityQueue.make();
|
|
1307
|
+
open.push(s, 0);
|
|
1308
|
+
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;
|
|
1309
|
+
while (!open.empty()) {
|
|
1310
|
+
closest = open.pop();
|
|
1311
|
+
u = closest.value;
|
|
1312
|
+
cost_of_s_to_u = closest.cost;
|
|
1313
|
+
adjacent_nodes = graph[u] || {};
|
|
1314
|
+
for (v in adjacent_nodes) {
|
|
1315
|
+
if (adjacent_nodes.hasOwnProperty(v)) {
|
|
1316
|
+
cost_of_e = adjacent_nodes[v];
|
|
1317
|
+
cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
|
|
1318
|
+
cost_of_s_to_v = costs[v];
|
|
1319
|
+
first_visit = typeof costs[v] === "undefined";
|
|
1320
|
+
if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
|
|
1321
|
+
costs[v] = cost_of_s_to_u_plus_cost_of_e;
|
|
1322
|
+
open.push(v, cost_of_s_to_u_plus_cost_of_e);
|
|
1323
|
+
predecessors[v] = u;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if (typeof d !== "undefined" && typeof costs[d] === "undefined") {
|
|
1329
|
+
var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
|
|
1330
|
+
throw new Error(msg);
|
|
1331
|
+
}
|
|
1332
|
+
return predecessors;
|
|
1333
|
+
},
|
|
1334
|
+
extract_shortest_path_from_predecessor_list: function(predecessors, d) {
|
|
1335
|
+
var nodes = [];
|
|
1336
|
+
var u = d;
|
|
1337
|
+
var predecessor;
|
|
1338
|
+
while (u) {
|
|
1339
|
+
nodes.push(u);
|
|
1340
|
+
predecessor = predecessors[u];
|
|
1341
|
+
u = predecessors[u];
|
|
1342
|
+
}
|
|
1343
|
+
nodes.reverse();
|
|
1344
|
+
return nodes;
|
|
1345
|
+
},
|
|
1346
|
+
find_path: function(graph, s, d) {
|
|
1347
|
+
var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
|
|
1348
|
+
return dijkstra.extract_shortest_path_from_predecessor_list(
|
|
1349
|
+
predecessors,
|
|
1350
|
+
d
|
|
1351
|
+
);
|
|
1352
|
+
},
|
|
1353
|
+
/**
|
|
1354
|
+
* A very naive priority queue implementation.
|
|
1355
|
+
*/
|
|
1356
|
+
PriorityQueue: {
|
|
1357
|
+
make: function(opts) {
|
|
1358
|
+
var T = dijkstra.PriorityQueue, t = {}, key;
|
|
1359
|
+
opts = opts || {};
|
|
1360
|
+
for (key in T) {
|
|
1361
|
+
if (T.hasOwnProperty(key)) {
|
|
1362
|
+
t[key] = T[key];
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
t.queue = [];
|
|
1366
|
+
t.sorter = opts.sorter || T.default_sorter;
|
|
1367
|
+
return t;
|
|
1368
|
+
},
|
|
1369
|
+
default_sorter: function(a, b) {
|
|
1370
|
+
return a.cost - b.cost;
|
|
1371
|
+
},
|
|
1372
|
+
/**
|
|
1373
|
+
* Add a new item to the queue and ensure the highest priority element
|
|
1374
|
+
* is at the front of the queue.
|
|
1375
|
+
*/
|
|
1376
|
+
push: function(value, cost) {
|
|
1377
|
+
var item = { value, cost };
|
|
1378
|
+
this.queue.push(item);
|
|
1379
|
+
this.queue.sort(this.sorter);
|
|
1380
|
+
},
|
|
1381
|
+
/**
|
|
1382
|
+
* Return the highest priority element in the queue.
|
|
1383
|
+
*/
|
|
1384
|
+
pop: function() {
|
|
1385
|
+
return this.queue.shift();
|
|
1386
|
+
},
|
|
1387
|
+
empty: function() {
|
|
1388
|
+
return this.queue.length === 0;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
if (typeof module !== "undefined") {
|
|
1393
|
+
module.exports = dijkstra;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/segments.js
|
|
1399
|
+
var require_segments = __commonJS({
|
|
1400
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/segments.js"(exports) {
|
|
1401
|
+
var Mode = require_mode();
|
|
1402
|
+
var NumericData = require_numeric_data();
|
|
1403
|
+
var AlphanumericData = require_alphanumeric_data();
|
|
1404
|
+
var ByteData = require_byte_data();
|
|
1405
|
+
var KanjiData = require_kanji_data();
|
|
1406
|
+
var Regex = require_regex();
|
|
1407
|
+
var Utils = require_utils();
|
|
1408
|
+
var dijkstra = require_dijkstra();
|
|
1409
|
+
function getStringByteLength(str) {
|
|
1410
|
+
return unescape(encodeURIComponent(str)).length;
|
|
1411
|
+
}
|
|
1412
|
+
function getSegments(regex, mode, str) {
|
|
1413
|
+
const segments = [];
|
|
1414
|
+
let result;
|
|
1415
|
+
while ((result = regex.exec(str)) !== null) {
|
|
1416
|
+
segments.push({
|
|
1417
|
+
data: result[0],
|
|
1418
|
+
index: result.index,
|
|
1419
|
+
mode,
|
|
1420
|
+
length: result[0].length
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
return segments;
|
|
1424
|
+
}
|
|
1425
|
+
function getSegmentsFromString(dataStr) {
|
|
1426
|
+
const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
|
|
1427
|
+
const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
|
|
1428
|
+
let byteSegs;
|
|
1429
|
+
let kanjiSegs;
|
|
1430
|
+
if (Utils.isKanjiModeEnabled()) {
|
|
1431
|
+
byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
|
|
1432
|
+
kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
|
|
1433
|
+
} else {
|
|
1434
|
+
byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
|
|
1435
|
+
kanjiSegs = [];
|
|
1436
|
+
}
|
|
1437
|
+
const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
|
|
1438
|
+
return segs.sort(function(s1, s2) {
|
|
1439
|
+
return s1.index - s2.index;
|
|
1440
|
+
}).map(function(obj) {
|
|
1441
|
+
return {
|
|
1442
|
+
data: obj.data,
|
|
1443
|
+
mode: obj.mode,
|
|
1444
|
+
length: obj.length
|
|
1445
|
+
};
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
function getSegmentBitsLength(length, mode) {
|
|
1449
|
+
switch (mode) {
|
|
1450
|
+
case Mode.NUMERIC:
|
|
1451
|
+
return NumericData.getBitsLength(length);
|
|
1452
|
+
case Mode.ALPHANUMERIC:
|
|
1453
|
+
return AlphanumericData.getBitsLength(length);
|
|
1454
|
+
case Mode.KANJI:
|
|
1455
|
+
return KanjiData.getBitsLength(length);
|
|
1456
|
+
case Mode.BYTE:
|
|
1457
|
+
return ByteData.getBitsLength(length);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
function mergeSegments(segs) {
|
|
1461
|
+
return segs.reduce(function(acc, curr) {
|
|
1462
|
+
const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
|
|
1463
|
+
if (prevSeg && prevSeg.mode === curr.mode) {
|
|
1464
|
+
acc[acc.length - 1].data += curr.data;
|
|
1465
|
+
return acc;
|
|
1466
|
+
}
|
|
1467
|
+
acc.push(curr);
|
|
1468
|
+
return acc;
|
|
1469
|
+
}, []);
|
|
1470
|
+
}
|
|
1471
|
+
function buildNodes(segs) {
|
|
1472
|
+
const nodes = [];
|
|
1473
|
+
for (let i = 0; i < segs.length; i++) {
|
|
1474
|
+
const seg = segs[i];
|
|
1475
|
+
switch (seg.mode) {
|
|
1476
|
+
case Mode.NUMERIC:
|
|
1477
|
+
nodes.push([
|
|
1478
|
+
seg,
|
|
1479
|
+
{ data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
|
|
1480
|
+
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
1481
|
+
]);
|
|
1482
|
+
break;
|
|
1483
|
+
case Mode.ALPHANUMERIC:
|
|
1484
|
+
nodes.push([
|
|
1485
|
+
seg,
|
|
1486
|
+
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
1487
|
+
]);
|
|
1488
|
+
break;
|
|
1489
|
+
case Mode.KANJI:
|
|
1490
|
+
nodes.push([
|
|
1491
|
+
seg,
|
|
1492
|
+
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
1493
|
+
]);
|
|
1494
|
+
break;
|
|
1495
|
+
case Mode.BYTE:
|
|
1496
|
+
nodes.push([
|
|
1497
|
+
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
1498
|
+
]);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return nodes;
|
|
1502
|
+
}
|
|
1503
|
+
function buildGraph(nodes, version) {
|
|
1504
|
+
const table = {};
|
|
1505
|
+
const graph = { start: {} };
|
|
1506
|
+
let prevNodeIds = ["start"];
|
|
1507
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1508
|
+
const nodeGroup = nodes[i];
|
|
1509
|
+
const currentNodeIds = [];
|
|
1510
|
+
for (let j = 0; j < nodeGroup.length; j++) {
|
|
1511
|
+
const node = nodeGroup[j];
|
|
1512
|
+
const key = "" + i + j;
|
|
1513
|
+
currentNodeIds.push(key);
|
|
1514
|
+
table[key] = { node, lastCount: 0 };
|
|
1515
|
+
graph[key] = {};
|
|
1516
|
+
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
1517
|
+
const prevNodeId = prevNodeIds[n];
|
|
1518
|
+
if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
|
|
1519
|
+
graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
|
|
1520
|
+
table[prevNodeId].lastCount += node.length;
|
|
1521
|
+
} else {
|
|
1522
|
+
if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
|
|
1523
|
+
graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
prevNodeIds = currentNodeIds;
|
|
1528
|
+
}
|
|
1529
|
+
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
1530
|
+
graph[prevNodeIds[n]].end = 0;
|
|
1531
|
+
}
|
|
1532
|
+
return { map: graph, table };
|
|
1533
|
+
}
|
|
1534
|
+
function buildSingleSegment(data, modesHint) {
|
|
1535
|
+
let mode;
|
|
1536
|
+
const bestMode = Mode.getBestModeForData(data);
|
|
1537
|
+
mode = Mode.from(modesHint, bestMode);
|
|
1538
|
+
if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
|
|
1539
|
+
throw new Error('"' + data + '" cannot be encoded with mode ' + Mode.toString(mode) + ".\n Suggested mode is: " + Mode.toString(bestMode));
|
|
1540
|
+
}
|
|
1541
|
+
if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
|
|
1542
|
+
mode = Mode.BYTE;
|
|
1543
|
+
}
|
|
1544
|
+
switch (mode) {
|
|
1545
|
+
case Mode.NUMERIC:
|
|
1546
|
+
return new NumericData(data);
|
|
1547
|
+
case Mode.ALPHANUMERIC:
|
|
1548
|
+
return new AlphanumericData(data);
|
|
1549
|
+
case Mode.KANJI:
|
|
1550
|
+
return new KanjiData(data);
|
|
1551
|
+
case Mode.BYTE:
|
|
1552
|
+
return new ByteData(data);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
exports.fromArray = function fromArray(array) {
|
|
1556
|
+
return array.reduce(function(acc, seg) {
|
|
1557
|
+
if (typeof seg === "string") {
|
|
1558
|
+
acc.push(buildSingleSegment(seg, null));
|
|
1559
|
+
} else if (seg.data) {
|
|
1560
|
+
acc.push(buildSingleSegment(seg.data, seg.mode));
|
|
1561
|
+
}
|
|
1562
|
+
return acc;
|
|
1563
|
+
}, []);
|
|
1564
|
+
};
|
|
1565
|
+
exports.fromString = function fromString(data, version) {
|
|
1566
|
+
const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
|
|
1567
|
+
const nodes = buildNodes(segs);
|
|
1568
|
+
const graph = buildGraph(nodes, version);
|
|
1569
|
+
const path = dijkstra.find_path(graph.map, "start", "end");
|
|
1570
|
+
const optimizedSegs = [];
|
|
1571
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
1572
|
+
optimizedSegs.push(graph.table[path[i]].node);
|
|
1573
|
+
}
|
|
1574
|
+
return exports.fromArray(mergeSegments(optimizedSegs));
|
|
1575
|
+
};
|
|
1576
|
+
exports.rawSplit = function rawSplit(data) {
|
|
1577
|
+
return exports.fromArray(
|
|
1578
|
+
getSegmentsFromString(data, Utils.isKanjiModeEnabled())
|
|
1579
|
+
);
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
});
|
|
1583
|
+
|
|
1584
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/qrcode.js
|
|
1585
|
+
var require_qrcode = __commonJS({
|
|
1586
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/core/qrcode.js"(exports) {
|
|
1587
|
+
var Utils = require_utils();
|
|
1588
|
+
var ECLevel = require_error_correction_level();
|
|
1589
|
+
var BitBuffer = require_bit_buffer();
|
|
1590
|
+
var BitMatrix = require_bit_matrix();
|
|
1591
|
+
var AlignmentPattern = require_alignment_pattern();
|
|
1592
|
+
var FinderPattern = require_finder_pattern();
|
|
1593
|
+
var MaskPattern = require_mask_pattern();
|
|
1594
|
+
var ECCode = require_error_correction_code();
|
|
1595
|
+
var ReedSolomonEncoder = require_reed_solomon_encoder();
|
|
1596
|
+
var Version = require_version();
|
|
1597
|
+
var FormatInfo = require_format_info();
|
|
1598
|
+
var Mode = require_mode();
|
|
1599
|
+
var Segments = require_segments();
|
|
1600
|
+
function setupFinderPattern(matrix, version) {
|
|
1601
|
+
const size = matrix.size;
|
|
1602
|
+
const pos = FinderPattern.getPositions(version);
|
|
1603
|
+
for (let i = 0; i < pos.length; i++) {
|
|
1604
|
+
const row = pos[i][0];
|
|
1605
|
+
const col = pos[i][1];
|
|
1606
|
+
for (let r = -1; r <= 7; r++) {
|
|
1607
|
+
if (row + r <= -1 || size <= row + r) continue;
|
|
1608
|
+
for (let c = -1; c <= 7; c++) {
|
|
1609
|
+
if (col + c <= -1 || size <= col + c) continue;
|
|
1610
|
+
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) {
|
|
1611
|
+
matrix.set(row + r, col + c, true, true);
|
|
1612
|
+
} else {
|
|
1613
|
+
matrix.set(row + r, col + c, false, true);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
function setupTimingPattern(matrix) {
|
|
1620
|
+
const size = matrix.size;
|
|
1621
|
+
for (let r = 8; r < size - 8; r++) {
|
|
1622
|
+
const value = r % 2 === 0;
|
|
1623
|
+
matrix.set(r, 6, value, true);
|
|
1624
|
+
matrix.set(6, r, value, true);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
function setupAlignmentPattern(matrix, version) {
|
|
1628
|
+
const pos = AlignmentPattern.getPositions(version);
|
|
1629
|
+
for (let i = 0; i < pos.length; i++) {
|
|
1630
|
+
const row = pos[i][0];
|
|
1631
|
+
const col = pos[i][1];
|
|
1632
|
+
for (let r = -2; r <= 2; r++) {
|
|
1633
|
+
for (let c = -2; c <= 2; c++) {
|
|
1634
|
+
if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
|
|
1635
|
+
matrix.set(row + r, col + c, true, true);
|
|
1636
|
+
} else {
|
|
1637
|
+
matrix.set(row + r, col + c, false, true);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
function setupVersionInfo(matrix, version) {
|
|
1644
|
+
const size = matrix.size;
|
|
1645
|
+
const bits = Version.getEncodedBits(version);
|
|
1646
|
+
let row, col, mod;
|
|
1647
|
+
for (let i = 0; i < 18; i++) {
|
|
1648
|
+
row = Math.floor(i / 3);
|
|
1649
|
+
col = i % 3 + size - 8 - 3;
|
|
1650
|
+
mod = (bits >> i & 1) === 1;
|
|
1651
|
+
matrix.set(row, col, mod, true);
|
|
1652
|
+
matrix.set(col, row, mod, true);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
|
|
1656
|
+
const size = matrix.size;
|
|
1657
|
+
const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
|
|
1658
|
+
let i, mod;
|
|
1659
|
+
for (i = 0; i < 15; i++) {
|
|
1660
|
+
mod = (bits >> i & 1) === 1;
|
|
1661
|
+
if (i < 6) {
|
|
1662
|
+
matrix.set(i, 8, mod, true);
|
|
1663
|
+
} else if (i < 8) {
|
|
1664
|
+
matrix.set(i + 1, 8, mod, true);
|
|
1665
|
+
} else {
|
|
1666
|
+
matrix.set(size - 15 + i, 8, mod, true);
|
|
1667
|
+
}
|
|
1668
|
+
if (i < 8) {
|
|
1669
|
+
matrix.set(8, size - i - 1, mod, true);
|
|
1670
|
+
} else if (i < 9) {
|
|
1671
|
+
matrix.set(8, 15 - i - 1 + 1, mod, true);
|
|
1672
|
+
} else {
|
|
1673
|
+
matrix.set(8, 15 - i - 1, mod, true);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
matrix.set(size - 8, 8, 1, true);
|
|
1677
|
+
}
|
|
1678
|
+
function setupData(matrix, data) {
|
|
1679
|
+
const size = matrix.size;
|
|
1680
|
+
let inc = -1;
|
|
1681
|
+
let row = size - 1;
|
|
1682
|
+
let bitIndex = 7;
|
|
1683
|
+
let byteIndex = 0;
|
|
1684
|
+
for (let col = size - 1; col > 0; col -= 2) {
|
|
1685
|
+
if (col === 6) col--;
|
|
1686
|
+
while (true) {
|
|
1687
|
+
for (let c = 0; c < 2; c++) {
|
|
1688
|
+
if (!matrix.isReserved(row, col - c)) {
|
|
1689
|
+
let dark = false;
|
|
1690
|
+
if (byteIndex < data.length) {
|
|
1691
|
+
dark = (data[byteIndex] >>> bitIndex & 1) === 1;
|
|
1692
|
+
}
|
|
1693
|
+
matrix.set(row, col - c, dark);
|
|
1694
|
+
bitIndex--;
|
|
1695
|
+
if (bitIndex === -1) {
|
|
1696
|
+
byteIndex++;
|
|
1697
|
+
bitIndex = 7;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
row += inc;
|
|
1702
|
+
if (row < 0 || size <= row) {
|
|
1703
|
+
row -= inc;
|
|
1704
|
+
inc = -inc;
|
|
1705
|
+
break;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
function createData(version, errorCorrectionLevel, segments) {
|
|
1711
|
+
const buffer = new BitBuffer();
|
|
1712
|
+
segments.forEach(function(data) {
|
|
1713
|
+
buffer.put(data.mode.bit, 4);
|
|
1714
|
+
buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
|
|
1715
|
+
data.write(buffer);
|
|
1716
|
+
});
|
|
1717
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1718
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1719
|
+
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
1720
|
+
if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
|
|
1721
|
+
buffer.put(0, 4);
|
|
1722
|
+
}
|
|
1723
|
+
while (buffer.getLengthInBits() % 8 !== 0) {
|
|
1724
|
+
buffer.putBit(0);
|
|
1725
|
+
}
|
|
1726
|
+
const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
|
|
1727
|
+
for (let i = 0; i < remainingByte; i++) {
|
|
1728
|
+
buffer.put(i % 2 ? 17 : 236, 8);
|
|
1729
|
+
}
|
|
1730
|
+
return createCodewords(buffer, version, errorCorrectionLevel);
|
|
1731
|
+
}
|
|
1732
|
+
function createCodewords(bitBuffer, version, errorCorrectionLevel) {
|
|
1733
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1734
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1735
|
+
const dataTotalCodewords = totalCodewords - ecTotalCodewords;
|
|
1736
|
+
const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
|
|
1737
|
+
const blocksInGroup2 = totalCodewords % ecTotalBlocks;
|
|
1738
|
+
const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
|
|
1739
|
+
const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
|
|
1740
|
+
const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
|
|
1741
|
+
const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
|
|
1742
|
+
const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
|
|
1743
|
+
const rs = new ReedSolomonEncoder(ecCount);
|
|
1744
|
+
let offset = 0;
|
|
1745
|
+
const dcData = new Array(ecTotalBlocks);
|
|
1746
|
+
const ecData = new Array(ecTotalBlocks);
|
|
1747
|
+
let maxDataSize = 0;
|
|
1748
|
+
const buffer = new Uint8Array(bitBuffer.buffer);
|
|
1749
|
+
for (let b = 0; b < ecTotalBlocks; b++) {
|
|
1750
|
+
const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
|
|
1751
|
+
dcData[b] = buffer.slice(offset, offset + dataSize);
|
|
1752
|
+
ecData[b] = rs.encode(dcData[b]);
|
|
1753
|
+
offset += dataSize;
|
|
1754
|
+
maxDataSize = Math.max(maxDataSize, dataSize);
|
|
1755
|
+
}
|
|
1756
|
+
const data = new Uint8Array(totalCodewords);
|
|
1757
|
+
let index = 0;
|
|
1758
|
+
let i, r;
|
|
1759
|
+
for (i = 0; i < maxDataSize; i++) {
|
|
1760
|
+
for (r = 0; r < ecTotalBlocks; r++) {
|
|
1761
|
+
if (i < dcData[r].length) {
|
|
1762
|
+
data[index++] = dcData[r][i];
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
for (i = 0; i < ecCount; i++) {
|
|
1767
|
+
for (r = 0; r < ecTotalBlocks; r++) {
|
|
1768
|
+
data[index++] = ecData[r][i];
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
return data;
|
|
1772
|
+
}
|
|
1773
|
+
function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
|
|
1774
|
+
let segments;
|
|
1775
|
+
if (Array.isArray(data)) {
|
|
1776
|
+
segments = Segments.fromArray(data);
|
|
1777
|
+
} else if (typeof data === "string") {
|
|
1778
|
+
let estimatedVersion = version;
|
|
1779
|
+
if (!estimatedVersion) {
|
|
1780
|
+
const rawSegments = Segments.rawSplit(data);
|
|
1781
|
+
estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
|
|
1782
|
+
}
|
|
1783
|
+
segments = Segments.fromString(data, estimatedVersion || 40);
|
|
1784
|
+
} else {
|
|
1785
|
+
throw new Error("Invalid data");
|
|
1786
|
+
}
|
|
1787
|
+
const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
|
|
1788
|
+
if (!bestVersion) {
|
|
1789
|
+
throw new Error("The amount of data is too big to be stored in a QR Code");
|
|
1790
|
+
}
|
|
1791
|
+
if (!version) {
|
|
1792
|
+
version = bestVersion;
|
|
1793
|
+
} else if (version < bestVersion) {
|
|
1794
|
+
throw new Error(
|
|
1795
|
+
"\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + bestVersion + ".\n"
|
|
1796
|
+
);
|
|
1797
|
+
}
|
|
1798
|
+
const dataBits = createData(version, errorCorrectionLevel, segments);
|
|
1799
|
+
const moduleCount = Utils.getSymbolSize(version);
|
|
1800
|
+
const modules = new BitMatrix(moduleCount);
|
|
1801
|
+
setupFinderPattern(modules, version);
|
|
1802
|
+
setupTimingPattern(modules);
|
|
1803
|
+
setupAlignmentPattern(modules, version);
|
|
1804
|
+
setupFormatInfo(modules, errorCorrectionLevel, 0);
|
|
1805
|
+
if (version >= 7) {
|
|
1806
|
+
setupVersionInfo(modules, version);
|
|
1807
|
+
}
|
|
1808
|
+
setupData(modules, dataBits);
|
|
1809
|
+
if (isNaN(maskPattern)) {
|
|
1810
|
+
maskPattern = MaskPattern.getBestMask(
|
|
1811
|
+
modules,
|
|
1812
|
+
setupFormatInfo.bind(null, modules, errorCorrectionLevel)
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
MaskPattern.applyMask(maskPattern, modules);
|
|
1816
|
+
setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
|
|
1817
|
+
return {
|
|
1818
|
+
modules,
|
|
1819
|
+
version,
|
|
1820
|
+
errorCorrectionLevel,
|
|
1821
|
+
maskPattern,
|
|
1822
|
+
segments
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
exports.create = function create(data, options) {
|
|
1826
|
+
if (typeof data === "undefined" || data === "") {
|
|
1827
|
+
throw new Error("No input text");
|
|
1828
|
+
}
|
|
1829
|
+
let errorCorrectionLevel = ECLevel.M;
|
|
1830
|
+
let version;
|
|
1831
|
+
let mask;
|
|
1832
|
+
if (typeof options !== "undefined") {
|
|
1833
|
+
errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
|
|
1834
|
+
version = Version.from(options.version);
|
|
1835
|
+
mask = MaskPattern.from(options.maskPattern);
|
|
1836
|
+
if (options.toSJISFunc) {
|
|
1837
|
+
Utils.setToSJISFunction(options.toSJISFunc);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
return createSymbol(data, version, errorCorrectionLevel, mask);
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
|
|
1845
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/renderer/utils.js
|
|
1846
|
+
var require_utils2 = __commonJS({
|
|
1847
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/renderer/utils.js"(exports) {
|
|
1848
|
+
function hex2rgba(hex) {
|
|
1849
|
+
if (typeof hex === "number") {
|
|
1850
|
+
hex = hex.toString();
|
|
1851
|
+
}
|
|
1852
|
+
if (typeof hex !== "string") {
|
|
1853
|
+
throw new Error("Color should be defined as hex string");
|
|
1854
|
+
}
|
|
1855
|
+
let hexCode = hex.slice().replace("#", "").split("");
|
|
1856
|
+
if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
|
|
1857
|
+
throw new Error("Invalid hex color: " + hex);
|
|
1858
|
+
}
|
|
1859
|
+
if (hexCode.length === 3 || hexCode.length === 4) {
|
|
1860
|
+
hexCode = Array.prototype.concat.apply([], hexCode.map(function(c) {
|
|
1861
|
+
return [c, c];
|
|
1862
|
+
}));
|
|
1863
|
+
}
|
|
1864
|
+
if (hexCode.length === 6) hexCode.push("F", "F");
|
|
1865
|
+
const hexValue = parseInt(hexCode.join(""), 16);
|
|
1866
|
+
return {
|
|
1867
|
+
r: hexValue >> 24 & 255,
|
|
1868
|
+
g: hexValue >> 16 & 255,
|
|
1869
|
+
b: hexValue >> 8 & 255,
|
|
1870
|
+
a: hexValue & 255,
|
|
1871
|
+
hex: "#" + hexCode.slice(0, 6).join("")
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
exports.getOptions = function getOptions(options) {
|
|
1875
|
+
if (!options) options = {};
|
|
1876
|
+
if (!options.color) options.color = {};
|
|
1877
|
+
const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
|
|
1878
|
+
const width = options.width && options.width >= 21 ? options.width : void 0;
|
|
1879
|
+
const scale = options.scale || 4;
|
|
1880
|
+
return {
|
|
1881
|
+
width,
|
|
1882
|
+
scale: width ? 4 : scale,
|
|
1883
|
+
margin,
|
|
1884
|
+
color: {
|
|
1885
|
+
dark: hex2rgba(options.color.dark || "#000000ff"),
|
|
1886
|
+
light: hex2rgba(options.color.light || "#ffffffff")
|
|
1887
|
+
},
|
|
1888
|
+
type: options.type,
|
|
1889
|
+
rendererOpts: options.rendererOpts || {}
|
|
1890
|
+
};
|
|
1891
|
+
};
|
|
1892
|
+
exports.getScale = function getScale(qrSize, opts) {
|
|
1893
|
+
return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
|
|
1894
|
+
};
|
|
1895
|
+
exports.getImageWidth = function getImageWidth(qrSize, opts) {
|
|
1896
|
+
const scale = exports.getScale(qrSize, opts);
|
|
1897
|
+
return Math.floor((qrSize + opts.margin * 2) * scale);
|
|
1898
|
+
};
|
|
1899
|
+
exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
|
|
1900
|
+
const size = qr.modules.size;
|
|
1901
|
+
const data = qr.modules.data;
|
|
1902
|
+
const scale = exports.getScale(size, opts);
|
|
1903
|
+
const symbolSize = Math.floor((size + opts.margin * 2) * scale);
|
|
1904
|
+
const scaledMargin = opts.margin * scale;
|
|
1905
|
+
const palette = [opts.color.light, opts.color.dark];
|
|
1906
|
+
for (let i = 0; i < symbolSize; i++) {
|
|
1907
|
+
for (let j = 0; j < symbolSize; j++) {
|
|
1908
|
+
let posDst = (i * symbolSize + j) * 4;
|
|
1909
|
+
let pxColor = opts.color.light;
|
|
1910
|
+
if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
|
|
1911
|
+
const iSrc = Math.floor((i - scaledMargin) / scale);
|
|
1912
|
+
const jSrc = Math.floor((j - scaledMargin) / scale);
|
|
1913
|
+
pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
|
|
1914
|
+
}
|
|
1915
|
+
imgData[posDst++] = pxColor.r;
|
|
1916
|
+
imgData[posDst++] = pxColor.g;
|
|
1917
|
+
imgData[posDst++] = pxColor.b;
|
|
1918
|
+
imgData[posDst] = pxColor.a;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
});
|
|
1924
|
+
|
|
1925
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/renderer/canvas.js
|
|
1926
|
+
var require_canvas = __commonJS({
|
|
1927
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/renderer/canvas.js"(exports) {
|
|
1928
|
+
var Utils = require_utils2();
|
|
1929
|
+
function clearCanvas(ctx, canvas, size) {
|
|
1930
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
1931
|
+
if (!canvas.style) canvas.style = {};
|
|
1932
|
+
canvas.height = size;
|
|
1933
|
+
canvas.width = size;
|
|
1934
|
+
canvas.style.height = size + "px";
|
|
1935
|
+
canvas.style.width = size + "px";
|
|
1936
|
+
}
|
|
1937
|
+
function getCanvasElement() {
|
|
1938
|
+
try {
|
|
1939
|
+
return document.createElement("canvas");
|
|
1940
|
+
} catch (e) {
|
|
1941
|
+
throw new Error("You need to specify a canvas element");
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
exports.render = function render(qrData, canvas, options) {
|
|
1945
|
+
let opts = options;
|
|
1946
|
+
let canvasEl = canvas;
|
|
1947
|
+
if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
|
|
1948
|
+
opts = canvas;
|
|
1949
|
+
canvas = void 0;
|
|
1950
|
+
}
|
|
1951
|
+
if (!canvas) {
|
|
1952
|
+
canvasEl = getCanvasElement();
|
|
1953
|
+
}
|
|
1954
|
+
opts = Utils.getOptions(opts);
|
|
1955
|
+
const size = Utils.getImageWidth(qrData.modules.size, opts);
|
|
1956
|
+
const ctx = canvasEl.getContext("2d");
|
|
1957
|
+
const image = ctx.createImageData(size, size);
|
|
1958
|
+
Utils.qrToImageData(image.data, qrData, opts);
|
|
1959
|
+
clearCanvas(ctx, canvasEl, size);
|
|
1960
|
+
ctx.putImageData(image, 0, 0);
|
|
1961
|
+
return canvasEl;
|
|
1962
|
+
};
|
|
1963
|
+
exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
|
|
1964
|
+
let opts = options;
|
|
1965
|
+
if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
|
|
1966
|
+
opts = canvas;
|
|
1967
|
+
canvas = void 0;
|
|
1968
|
+
}
|
|
1969
|
+
if (!opts) opts = {};
|
|
1970
|
+
const canvasEl = exports.render(qrData, canvas, opts);
|
|
1971
|
+
const type = opts.type || "image/png";
|
|
1972
|
+
const rendererOpts = opts.rendererOpts || {};
|
|
1973
|
+
return canvasEl.toDataURL(type, rendererOpts.quality);
|
|
1974
|
+
};
|
|
1975
|
+
}
|
|
1976
|
+
});
|
|
1977
|
+
|
|
1978
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/renderer/svg-tag.js
|
|
1979
|
+
var require_svg_tag = __commonJS({
|
|
1980
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/renderer/svg-tag.js"(exports) {
|
|
1981
|
+
var Utils = require_utils2();
|
|
1982
|
+
function getColorAttrib(color, attrib) {
|
|
1983
|
+
const alpha = color.a / 255;
|
|
1984
|
+
const str = attrib + '="' + color.hex + '"';
|
|
1985
|
+
return alpha < 1 ? str + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
|
|
1986
|
+
}
|
|
1987
|
+
function svgCmd(cmd, x, y) {
|
|
1988
|
+
let str = cmd + x;
|
|
1989
|
+
if (typeof y !== "undefined") str += " " + y;
|
|
1990
|
+
return str;
|
|
1991
|
+
}
|
|
1992
|
+
function qrToPath(data, size, margin) {
|
|
1993
|
+
let path = "";
|
|
1994
|
+
let moveBy = 0;
|
|
1995
|
+
let newRow = false;
|
|
1996
|
+
let lineLength = 0;
|
|
1997
|
+
for (let i = 0; i < data.length; i++) {
|
|
1998
|
+
const col = Math.floor(i % size);
|
|
1999
|
+
const row = Math.floor(i / size);
|
|
2000
|
+
if (!col && !newRow) newRow = true;
|
|
2001
|
+
if (data[i]) {
|
|
2002
|
+
lineLength++;
|
|
2003
|
+
if (!(i > 0 && col > 0 && data[i - 1])) {
|
|
2004
|
+
path += newRow ? svgCmd("M", col + margin, 0.5 + row + margin) : svgCmd("m", moveBy, 0);
|
|
2005
|
+
moveBy = 0;
|
|
2006
|
+
newRow = false;
|
|
2007
|
+
}
|
|
2008
|
+
if (!(col + 1 < size && data[i + 1])) {
|
|
2009
|
+
path += svgCmd("h", lineLength);
|
|
2010
|
+
lineLength = 0;
|
|
2011
|
+
}
|
|
2012
|
+
} else {
|
|
2013
|
+
moveBy++;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
return path;
|
|
2017
|
+
}
|
|
2018
|
+
exports.render = function render(qrData, options, cb) {
|
|
2019
|
+
const opts = Utils.getOptions(options);
|
|
2020
|
+
const size = qrData.modules.size;
|
|
2021
|
+
const data = qrData.modules.data;
|
|
2022
|
+
const qrcodesize = size + opts.margin * 2;
|
|
2023
|
+
const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + ' d="M0 0h' + qrcodesize + "v" + qrcodesize + 'H0z"/>';
|
|
2024
|
+
const path = "<path " + getColorAttrib(opts.color.dark, "stroke") + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
|
|
2025
|
+
const viewBox = 'viewBox="0 0 ' + qrcodesize + " " + qrcodesize + '"';
|
|
2026
|
+
const width = !opts.width ? "" : 'width="' + opts.width + '" height="' + opts.width + '" ';
|
|
2027
|
+
const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + "</svg>\n";
|
|
2028
|
+
if (typeof cb === "function") {
|
|
2029
|
+
cb(null, svgTag);
|
|
2030
|
+
}
|
|
2031
|
+
return svgTag;
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
|
|
2036
|
+
// ../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/browser.js
|
|
2037
|
+
var require_browser = __commonJS({
|
|
2038
|
+
"../../../../../../../tmp/aiti-build-root/node_modules/qrcode/lib/browser.js"(exports) {
|
|
2039
|
+
var canPromise = require_can_promise();
|
|
2040
|
+
var QRCode2 = require_qrcode();
|
|
2041
|
+
var CanvasRenderer = require_canvas();
|
|
2042
|
+
var SvgRenderer = require_svg_tag();
|
|
2043
|
+
function renderCanvas(renderFunc, canvas, text, opts, cb) {
|
|
2044
|
+
const args = [].slice.call(arguments, 1);
|
|
2045
|
+
const argsNum = args.length;
|
|
2046
|
+
const isLastArgCb = typeof args[argsNum - 1] === "function";
|
|
2047
|
+
if (!isLastArgCb && !canPromise()) {
|
|
2048
|
+
throw new Error("Callback required as last argument");
|
|
2049
|
+
}
|
|
2050
|
+
if (isLastArgCb) {
|
|
2051
|
+
if (argsNum < 2) {
|
|
2052
|
+
throw new Error("Too few arguments provided");
|
|
2053
|
+
}
|
|
2054
|
+
if (argsNum === 2) {
|
|
2055
|
+
cb = text;
|
|
2056
|
+
text = canvas;
|
|
2057
|
+
canvas = opts = void 0;
|
|
2058
|
+
} else if (argsNum === 3) {
|
|
2059
|
+
if (canvas.getContext && typeof cb === "undefined") {
|
|
2060
|
+
cb = opts;
|
|
2061
|
+
opts = void 0;
|
|
2062
|
+
} else {
|
|
2063
|
+
cb = opts;
|
|
2064
|
+
opts = text;
|
|
2065
|
+
text = canvas;
|
|
2066
|
+
canvas = void 0;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
} else {
|
|
2070
|
+
if (argsNum < 1) {
|
|
2071
|
+
throw new Error("Too few arguments provided");
|
|
2072
|
+
}
|
|
2073
|
+
if (argsNum === 1) {
|
|
2074
|
+
text = canvas;
|
|
2075
|
+
canvas = opts = void 0;
|
|
2076
|
+
} else if (argsNum === 2 && !canvas.getContext) {
|
|
2077
|
+
opts = text;
|
|
2078
|
+
text = canvas;
|
|
2079
|
+
canvas = void 0;
|
|
2080
|
+
}
|
|
2081
|
+
return new Promise(function(resolve, reject) {
|
|
2082
|
+
try {
|
|
2083
|
+
const data = QRCode2.create(text, opts);
|
|
2084
|
+
resolve(renderFunc(data, canvas, opts));
|
|
2085
|
+
} catch (e) {
|
|
2086
|
+
reject(e);
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
try {
|
|
2091
|
+
const data = QRCode2.create(text, opts);
|
|
2092
|
+
cb(null, renderFunc(data, canvas, opts));
|
|
2093
|
+
} catch (e) {
|
|
2094
|
+
cb(e);
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
exports.create = QRCode2.create;
|
|
2098
|
+
exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
|
|
2099
|
+
exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
|
|
2100
|
+
exports.toString = renderCanvas.bind(null, function(data, _, opts) {
|
|
2101
|
+
return SvgRenderer.render(data, opts);
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2105
|
+
|
|
2106
|
+
// client/src/index.js
|
|
2107
|
+
var import_qrcode = __toESM(require_browser(), 1);
|
|
2108
|
+
var RECENT_KEY = "pi-web:recent-share-targets";
|
|
2109
|
+
var API = (path) => `/api/extensions/aiti-msg-share/${path}`;
|
|
2110
|
+
var tFn = null;
|
|
2111
|
+
function kindLabel(k) {
|
|
2112
|
+
return shareT("share.kind." + k);
|
|
2113
|
+
}
|
|
2114
|
+
var IMG_EXT = /\.(png|jpe?g|gif|webp|bmp|svg|ico|avif)$/i;
|
|
2115
|
+
var BIN_EXT = /\.(pdf|zip|7z|rar|gz|tgz|tar|bz2|xz|mp3|wav|ogg|flac|mp4|mkv|webm|mov|avi|docx|doc|xlsx|xls|pptx|epub|bin|exe|dmg|iso|apk|psd|woff2?|ttf)$/i;
|
|
2116
|
+
function contentKind() {
|
|
2117
|
+
if (state.kind === "image") return "image";
|
|
2118
|
+
if (state.kind === "file" && state.payload?.filePath) {
|
|
2119
|
+
const f = state.payload.filePath;
|
|
2120
|
+
if (IMG_EXT.test(f)) return "image";
|
|
2121
|
+
if (BIN_EXT.test(f)) return "file";
|
|
2122
|
+
}
|
|
2123
|
+
return "text";
|
|
2124
|
+
}
|
|
2125
|
+
function supportsKind(t, kind) {
|
|
2126
|
+
return !(t.kinds || []).length || (t.kinds || []).includes(kind);
|
|
2127
|
+
}
|
|
2128
|
+
function shareT(key, params) {
|
|
2129
|
+
if (!tFn) return key;
|
|
2130
|
+
try {
|
|
2131
|
+
const raw = tFn(key, params);
|
|
2132
|
+
if (!params) return raw;
|
|
2133
|
+
return raw.replace(/\{(\w+)\}/g, (_m, k) => String(params[k] ?? ""));
|
|
2134
|
+
} catch {
|
|
2135
|
+
return key;
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
var h = null;
|
|
2139
|
+
var ctxRef = null;
|
|
2140
|
+
var apiUrlFn = null;
|
|
2141
|
+
var state = {
|
|
2142
|
+
open: false,
|
|
2143
|
+
manager: false,
|
|
2144
|
+
loading: true,
|
|
2145
|
+
targets: [],
|
|
2146
|
+
history: [],
|
|
2147
|
+
payload: null,
|
|
2148
|
+
kind: "message",
|
|
2149
|
+
text: "",
|
|
2150
|
+
rawText: "",
|
|
2151
|
+
baseText: "",
|
|
2152
|
+
title: "",
|
|
2153
|
+
tags: "",
|
|
2154
|
+
// Which page-context fields get prepended to the shared content (multi-select).
|
|
2155
|
+
stamp: { os: true, browser: true, url: false, sessionId: true, sessionName: true },
|
|
2156
|
+
targetId: null,
|
|
2157
|
+
meta: {},
|
|
2158
|
+
redact: true,
|
|
2159
|
+
redactHits: [],
|
|
2160
|
+
result: null,
|
|
2161
|
+
busy: false,
|
|
2162
|
+
error: "",
|
|
2163
|
+
errorDetail: "",
|
|
2164
|
+
errorCode: "",
|
|
2165
|
+
errorTarget: "",
|
|
2166
|
+
errorProvider: "",
|
|
2167
|
+
search: "",
|
|
2168
|
+
probe: [],
|
|
2169
|
+
editing: null,
|
|
2170
|
+
form: {},
|
|
2171
|
+
/** Local favourite sinks (share-sink topic): { ok, message, action } of the last run. */
|
|
2172
|
+
sinkResult: null,
|
|
2173
|
+
sinkBusy: ""
|
|
2174
|
+
};
|
|
2175
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
2176
|
+
function locale() {
|
|
2177
|
+
try {
|
|
2178
|
+
return typeof window !== "undefined" && String(window.__PI_LOCALE__ || "").startsWith("zh") ? "zh" : "en";
|
|
2179
|
+
} catch {
|
|
2180
|
+
return "en";
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
function noteText(note) {
|
|
2184
|
+
if (!note) return "";
|
|
2185
|
+
if (typeof note === "object") return String(note[locale()] || note.zh || note.en || "").trim();
|
|
2186
|
+
return String(note);
|
|
2187
|
+
}
|
|
2188
|
+
function api(path) {
|
|
2189
|
+
return apiUrlFn ? apiUrlFn(`/api/extensions/aiti-msg-share/${path}`) : API(path);
|
|
2190
|
+
}
|
|
2191
|
+
async function getJSON(path, opts) {
|
|
2192
|
+
let r, data;
|
|
2193
|
+
try {
|
|
2194
|
+
r = await fetch(api(path), opts);
|
|
2195
|
+
} catch (e) {
|
|
2196
|
+
const err = new Error(`\u65E0\u6CD5\u8FDE\u63A5 pi-web \u670D\u52A1\uFF1A${e?.message || e}`);
|
|
2197
|
+
err.detail = String(e?.message || e);
|
|
2198
|
+
throw err;
|
|
2199
|
+
}
|
|
2200
|
+
data = await r.json().catch(() => ({}));
|
|
2201
|
+
if (!r.ok || data.ok === false) {
|
|
2202
|
+
const err = new Error(data.error || `HTTP ${r.status} (${api(path)})`);
|
|
2203
|
+
err.detail = data.detail || `${r.status} ${api(path)}`;
|
|
2204
|
+
err.kind = data.errorCode || data.errorKind;
|
|
2205
|
+
err.targetId = data.errorTarget;
|
|
2206
|
+
err.providerLabel = data.providerLabel;
|
|
2207
|
+
throw err;
|
|
2208
|
+
}
|
|
2209
|
+
return data;
|
|
2210
|
+
}
|
|
2211
|
+
function recentGet() {
|
|
2212
|
+
try {
|
|
2213
|
+
return JSON.parse(window.localStorage.getItem(RECENT_KEY) || "[]");
|
|
2214
|
+
} catch {
|
|
2215
|
+
return [];
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
function recentAdd(id) {
|
|
2219
|
+
if (!id) return;
|
|
2220
|
+
const next = [id, ...recentGet().filter((x) => x !== id)].slice(0, 10);
|
|
2221
|
+
try {
|
|
2222
|
+
window.localStorage.setItem(RECENT_KEY, JSON.stringify(next));
|
|
2223
|
+
} catch {
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
function recentClear() {
|
|
2227
|
+
try {
|
|
2228
|
+
window.localStorage.removeItem(RECENT_KEY);
|
|
2229
|
+
} catch {
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
function set(partial) {
|
|
2233
|
+
Object.assign(state, partial);
|
|
2234
|
+
emit();
|
|
2235
|
+
}
|
|
2236
|
+
function chooseTarget(id) {
|
|
2237
|
+
recentAdd(id);
|
|
2238
|
+
set({ targetId: id, manager: false, editing: null, error: "", errorDetail: "" });
|
|
2239
|
+
}
|
|
2240
|
+
function emit() {
|
|
2241
|
+
listeners.forEach((fn) => fn());
|
|
2242
|
+
}
|
|
2243
|
+
var STATUS_ICONS = { recent: "\u{1F558}", recommended: "\u2605", dead: "\u26A0", legacy: "\u26A0" };
|
|
2244
|
+
var CFG_BADGE = {
|
|
2245
|
+
anonymous: { icon: "\u{1F7E2}", key: "share.cfg.anonymous", color: "var(--accent, #4d8dff)" },
|
|
2246
|
+
ready: { icon: "\u2713", key: "share.cfg.ready", color: "var(--accent, #4d8dff)" },
|
|
2247
|
+
"needs-setup": { icon: "\u{1F7E0}", key: "share.cfg.needs", color: "#d9a13c" },
|
|
2248
|
+
dead: { icon: "\u{1F480}", key: "share.cfg.dead", color: "var(--text-muted, #8b909b)" }
|
|
2249
|
+
};
|
|
2250
|
+
var ICONS = {
|
|
2251
|
+
share: '<circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.6" y1="10.5" x2="15.4" y2="6.5"/><line x1="8.6" y1="13.5" x2="15.4" y2="17.5"/>',
|
|
2252
|
+
close: '<path d="M18 6 6 18M6 6l12 12"/>',
|
|
2253
|
+
gear: '<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1-2.8 2.8-.1-.1a1.7 1.7 0 0 0-1.9-.3 1.7 1.7 0 0 0-1 1.6V21h-4v-.1A1.7 1.7 0 0 0 8.9 19a1.7 1.7 0 0 0-1.9.3l-.1.1L4.1 16.6l.1-.1a1.7 1.7 0 0 0 .3-1.9A1.7 1.7 0 0 0 3 13.5H3v-3h.1a1.7 1.7 0 0 0 1.6-1 1.7 1.7 0 0 0-.3-1.9L4.3 7.5 7.1 4.7l.1.1a1.7 1.7 0 0 0 1.9.3h.1a1.7 1.7 0 0 0 1-1.6V3h4v.1a1.7 1.7 0 0 0 1 1.6 1.7 1.7 0 0 0 1.9-.3l.1-.1 2.8 2.8-.1.1a1.7 1.7 0 0 0-.3 1.9v.1a1.7 1.7 0 0 0 1.6 1H21v4h-.1a1.7 1.7 0 0 0-1.6 1z"/>'
|
|
2254
|
+
};
|
|
2255
|
+
function icon(name, size = 13) {
|
|
2256
|
+
const markup = ICONS[name];
|
|
2257
|
+
if (!markup) return null;
|
|
2258
|
+
return h("svg", {
|
|
2259
|
+
width: size,
|
|
2260
|
+
height: size,
|
|
2261
|
+
viewBox: "0 0 24 24",
|
|
2262
|
+
fill: "none",
|
|
2263
|
+
stroke: "currentColor",
|
|
2264
|
+
strokeWidth: 1.7,
|
|
2265
|
+
strokeLinecap: "round",
|
|
2266
|
+
strokeLinejoin: "round",
|
|
2267
|
+
"aria-hidden": "true",
|
|
2268
|
+
dangerouslySetInnerHTML: { __html: markup }
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
var SHARE_ICON = { svg: ICONS.share };
|
|
2272
|
+
function btn(label, onClick, opts = {}) {
|
|
2273
|
+
return h("button", {
|
|
2274
|
+
type: "button",
|
|
2275
|
+
onClick,
|
|
2276
|
+
title: opts.title || label,
|
|
2277
|
+
style: {
|
|
2278
|
+
border: "1px solid " + (opts.primary ? "var(--accent, #4d8dff)" : "var(--border, #34363c)"),
|
|
2279
|
+
background: opts.primary ? "var(--accent, #4d8dff)" : "var(--bg-hover, #25272c)",
|
|
2280
|
+
color: opts.primary ? "#fff" : "var(--text, #d8dade)",
|
|
2281
|
+
borderRadius: 7,
|
|
2282
|
+
padding: "5px 12px",
|
|
2283
|
+
fontSize: 12,
|
|
2284
|
+
cursor: "pointer",
|
|
2285
|
+
opacity: opts.disabled ? 0.5 : 1
|
|
2286
|
+
},
|
|
2287
|
+
disabled: opts.disabled
|
|
2288
|
+
}, label);
|
|
2289
|
+
}
|
|
2290
|
+
function openShare(payload = {}) {
|
|
2291
|
+
const kind = payload.kind || "message";
|
|
2292
|
+
const raw = payload.text || "";
|
|
2293
|
+
primeSinks();
|
|
2294
|
+
set({
|
|
2295
|
+
open: true,
|
|
2296
|
+
manager: false,
|
|
2297
|
+
payload,
|
|
2298
|
+
kind,
|
|
2299
|
+
text: raw,
|
|
2300
|
+
rawText: raw,
|
|
2301
|
+
baseText: raw,
|
|
2302
|
+
title: payload.title || "",
|
|
2303
|
+
tags: payload.tags || "",
|
|
2304
|
+
targetId: payload.targetId || null,
|
|
2305
|
+
result: null,
|
|
2306
|
+
error: "",
|
|
2307
|
+
errorDetail: "",
|
|
2308
|
+
errorCode: "",
|
|
2309
|
+
errorTarget: "",
|
|
2310
|
+
errorProvider: "",
|
|
2311
|
+
redact: true,
|
|
2312
|
+
redactHits: [],
|
|
2313
|
+
sinkResult: null,
|
|
2314
|
+
sinkBusy: ""
|
|
2315
|
+
});
|
|
2316
|
+
void refresh();
|
|
2317
|
+
void refreshPreview();
|
|
2318
|
+
return true;
|
|
2319
|
+
}
|
|
2320
|
+
async function refresh(force = false) {
|
|
2321
|
+
set({ loading: true });
|
|
2322
|
+
try {
|
|
2323
|
+
const [catalog, history, probe] = await Promise.all([
|
|
2324
|
+
getJSON("catalog"),
|
|
2325
|
+
getJSON("history"),
|
|
2326
|
+
getJSON("probe", { method: "POST" }).catch(() => ({ services: [] }))
|
|
2327
|
+
]);
|
|
2328
|
+
const targets = catalog.targets || [];
|
|
2329
|
+
set({
|
|
2330
|
+
targets,
|
|
2331
|
+
history: history.items || [],
|
|
2332
|
+
probe: probe.services || [],
|
|
2333
|
+
loading: false,
|
|
2334
|
+
targetId: state.targetId || targets.find((t) => t.recommended)?.id || targets[0]?.id
|
|
2335
|
+
});
|
|
2336
|
+
if (force) await getJSON("refresh", { method: "POST" }).catch(() => {
|
|
2337
|
+
});
|
|
2338
|
+
} catch (e) {
|
|
2339
|
+
set({ loading: false, error: e.message, errorDetail: e.detail || "catalog/history" });
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
function targetCard(target, selected, badge) {
|
|
2343
|
+
const disabled = target.status === "dead" || target.enabled === false;
|
|
2344
|
+
return h(
|
|
2345
|
+
"button",
|
|
2346
|
+
{
|
|
2347
|
+
type: "button",
|
|
2348
|
+
key: target.id,
|
|
2349
|
+
disabled,
|
|
2350
|
+
onClick: () => set({ targetId: target.id, error: "" }),
|
|
2351
|
+
title: noteText(target.note) || target.name,
|
|
2352
|
+
style: {
|
|
2353
|
+
display: "inline-flex",
|
|
2354
|
+
alignItems: "center",
|
|
2355
|
+
gap: 5,
|
|
2356
|
+
padding: "4px 9px",
|
|
2357
|
+
border: "1px solid " + (selected ? "var(--accent, #4d8dff)" : "var(--border, #34363c)"),
|
|
2358
|
+
borderRadius: 8,
|
|
2359
|
+
background: selected ? "rgba(77, 141, 255, 0.15)" : "var(--bg-hover, #25272c)",
|
|
2360
|
+
color: disabled ? "var(--text-muted, #8b909b)" : "var(--text, #d8dade)",
|
|
2361
|
+
fontSize: 12,
|
|
2362
|
+
cursor: "pointer",
|
|
2363
|
+
opacity: disabled ? 0.45 : 1
|
|
2364
|
+
}
|
|
2365
|
+
},
|
|
2366
|
+
h("span", null, STATUS_ICONS[badge] || "\u{1F517}"),
|
|
2367
|
+
target.name || target.id,
|
|
2368
|
+
...target.kinds?.length ? [h(
|
|
2369
|
+
"span",
|
|
2370
|
+
{ style: { color: "var(--text-muted, #8b909b)", fontSize: 10 } },
|
|
2371
|
+
target.kinds.map(kindLabel).join("/")
|
|
2372
|
+
)] : [],
|
|
2373
|
+
...(() => {
|
|
2374
|
+
const b = CFG_BADGE[target.configState];
|
|
2375
|
+
return b ? [h("span", { title: shareT(b.key), style: { fontSize: 10 } }, b.icon)] : [];
|
|
2376
|
+
})()
|
|
2377
|
+
);
|
|
2378
|
+
}
|
|
2379
|
+
var SINK_PRIME_EXTS = ["aiti-cmd", "aiti-prompts"];
|
|
2380
|
+
var sunkPrimed = false;
|
|
2381
|
+
function primeSinks() {
|
|
2382
|
+
if (sunkPrimed) return;
|
|
2383
|
+
sunkPrimed = true;
|
|
2384
|
+
const ensure = ctxRef?.ensureMaterialized;
|
|
2385
|
+
if (typeof ensure !== "function") return;
|
|
2386
|
+
for (const id of SINK_PRIME_EXTS) {
|
|
2387
|
+
try {
|
|
2388
|
+
Promise.resolve(ensure(id)).then(() => emit()).catch(() => {
|
|
2389
|
+
});
|
|
2390
|
+
} catch (e) {
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
function sinkItems() {
|
|
2395
|
+
const items = [];
|
|
2396
|
+
items.push({
|
|
2397
|
+
id: "copy",
|
|
2398
|
+
order: -1e3,
|
|
2399
|
+
builtin: true,
|
|
2400
|
+
get label() {
|
|
2401
|
+
return shareT("share.sink.copy");
|
|
2402
|
+
},
|
|
2403
|
+
icon: { svg: '<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>' },
|
|
2404
|
+
run: async () => {
|
|
2405
|
+
try {
|
|
2406
|
+
await navigator.clipboard.writeText(state.text);
|
|
2407
|
+
return { ok: true, message: shareT("share.sink.copied") };
|
|
2408
|
+
} catch (e) {
|
|
2409
|
+
return { ok: false, message: String(e && e.message || e) };
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
});
|
|
2413
|
+
try {
|
|
2414
|
+
for (const it of ctxRef?.getTopicItems?.("share-sink") || []) if (it && it.id) items.push(it);
|
|
2415
|
+
} catch (e) {
|
|
2416
|
+
}
|
|
2417
|
+
return items.sort((a, b) => (Number(a.order) || 100) - (Number(b.order) || 100));
|
|
2418
|
+
}
|
|
2419
|
+
function stripStamp(text) {
|
|
2420
|
+
const lines = String(text || "").split("\n");
|
|
2421
|
+
let i = 0;
|
|
2422
|
+
while (i < lines.length && /^>\s*\*\*[^*]+\*\*\s*:/.test(lines[i])) i++;
|
|
2423
|
+
return lines.slice(i).join("\n").trim();
|
|
2424
|
+
}
|
|
2425
|
+
function sinkPayload() {
|
|
2426
|
+
const raw = typeof state.baseText === "string" && state.baseText.length ? state.baseText : state.text;
|
|
2427
|
+
return { ...state.payload || {}, kind: state.kind, text: stripStamp(raw), title: state.title, tags: state.tags };
|
|
2428
|
+
}
|
|
2429
|
+
async function runSink(item) {
|
|
2430
|
+
if (state.sinkBusy) return;
|
|
2431
|
+
const payload = sinkPayload();
|
|
2432
|
+
if (!item.builtin && typeof item.accepts === "function") {
|
|
2433
|
+
let ok = false;
|
|
2434
|
+
try {
|
|
2435
|
+
ok = !!item.accepts(payload);
|
|
2436
|
+
} catch (e) {
|
|
2437
|
+
ok = false;
|
|
2438
|
+
}
|
|
2439
|
+
if (!ok) {
|
|
2440
|
+
const empty = !String(payload.text || "").trim();
|
|
2441
|
+
set({ sinkResult: { ok: false, message: empty ? shareT("share.sink.empty") : shareT("share.sink.unsupported") } });
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
set({ sinkBusy: item.id, sinkResult: null });
|
|
2446
|
+
try {
|
|
2447
|
+
const r = item.builtin ? await item.run(payload) : await item.save(payload);
|
|
2448
|
+
set({ sinkBusy: "", sinkResult: r || { ok: true } });
|
|
2449
|
+
} catch (e) {
|
|
2450
|
+
set({ sinkBusy: "", sinkResult: { ok: false, message: String(e && e.message || e) } });
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
function sinkSection() {
|
|
2454
|
+
const items = sinkItems();
|
|
2455
|
+
if (!items.length) return null;
|
|
2456
|
+
const res = state.sinkResult;
|
|
2457
|
+
return h(
|
|
2458
|
+
"div",
|
|
2459
|
+
null,
|
|
2460
|
+
h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, marginBottom: 5 } }, shareT("share.sinks")),
|
|
2461
|
+
h(
|
|
2462
|
+
"div",
|
|
2463
|
+
{ style: { display: "flex", flexWrap: "wrap", gap: 6 } },
|
|
2464
|
+
...items.map((it) => {
|
|
2465
|
+
const label = typeof it.label === "function" ? it.label() : it.label || it.id;
|
|
2466
|
+
const svg = it.icon && it.icon.svg;
|
|
2467
|
+
return h(
|
|
2468
|
+
"button",
|
|
2469
|
+
{
|
|
2470
|
+
type: "button",
|
|
2471
|
+
key: it.id,
|
|
2472
|
+
disabled: !!state.sinkBusy,
|
|
2473
|
+
onClick: () => {
|
|
2474
|
+
void runSink(it);
|
|
2475
|
+
},
|
|
2476
|
+
title: label,
|
|
2477
|
+
style: {
|
|
2478
|
+
display: "inline-flex",
|
|
2479
|
+
alignItems: "center",
|
|
2480
|
+
gap: 5,
|
|
2481
|
+
padding: "4px 9px",
|
|
2482
|
+
border: "1px solid var(--border, #34363c)",
|
|
2483
|
+
borderRadius: 8,
|
|
2484
|
+
background: "var(--bg-hover, #25272c)",
|
|
2485
|
+
color: "var(--text, #d8dade)",
|
|
2486
|
+
fontSize: 12,
|
|
2487
|
+
cursor: state.sinkBusy ? "default" : "pointer",
|
|
2488
|
+
opacity: state.sinkBusy && state.sinkBusy !== it.id ? 0.55 : 1
|
|
2489
|
+
}
|
|
2490
|
+
},
|
|
2491
|
+
svg ? h("span", { style: { display: "inline-flex" }, dangerouslySetInnerHTML: { __html: `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${svg}</svg>` } }) : null,
|
|
2492
|
+
label,
|
|
2493
|
+
state.sinkBusy === it.id ? h("span", { style: { fontSize: 10, opacity: 0.7 } }, "\u2026") : null
|
|
2494
|
+
);
|
|
2495
|
+
})
|
|
2496
|
+
),
|
|
2497
|
+
res ? h(
|
|
2498
|
+
"div",
|
|
2499
|
+
{ style: {
|
|
2500
|
+
marginTop: 6,
|
|
2501
|
+
fontSize: 11,
|
|
2502
|
+
display: "flex",
|
|
2503
|
+
alignItems: "center",
|
|
2504
|
+
gap: 8,
|
|
2505
|
+
color: res.ok ? "var(--ok, #4ade80)" : "#e05d5d",
|
|
2506
|
+
wordBreak: "break-word"
|
|
2507
|
+
} },
|
|
2508
|
+
h("span", null, (res.ok ? "\u2713 " : "\u26A0 ") + (res.message || (res.ok ? shareT("share.sink.saved") : ""))),
|
|
2509
|
+
res.ok && res.action && typeof res.action.run === "function" ? h("button", {
|
|
2510
|
+
type: "button",
|
|
2511
|
+
onClick: () => {
|
|
2512
|
+
try {
|
|
2513
|
+
res.action.run();
|
|
2514
|
+
} catch (e) {
|
|
2515
|
+
}
|
|
2516
|
+
},
|
|
2517
|
+
style: {
|
|
2518
|
+
border: "1px solid var(--accent, #4d8dff)",
|
|
2519
|
+
background: "none",
|
|
2520
|
+
color: "var(--accent, #4d8dff)",
|
|
2521
|
+
borderRadius: 6,
|
|
2522
|
+
padding: "1px 8px",
|
|
2523
|
+
fontSize: 11,
|
|
2524
|
+
cursor: "pointer"
|
|
2525
|
+
}
|
|
2526
|
+
}, res.action.label || "\u2192") : null
|
|
2527
|
+
) : null
|
|
2528
|
+
);
|
|
2529
|
+
}
|
|
2530
|
+
function targetSection() {
|
|
2531
|
+
const recent = recentGet();
|
|
2532
|
+
const kind = contentKind();
|
|
2533
|
+
const compat = (x) => supportsKind(x, kind);
|
|
2534
|
+
const t = state.targets;
|
|
2535
|
+
const byId = new Map(t.map((x) => [x.id, x]));
|
|
2536
|
+
const recentItems = recent.map((id) => byId.get(id)).filter(Boolean).filter(compat).slice(0, 5);
|
|
2537
|
+
const mine = t.filter((x) => x.custom && !recent.includes(x.id) && compat(x));
|
|
2538
|
+
const recs = t.filter((x) => x.recommended && !recent.includes(x.id) && !x.custom && compat(x)).slice(0, 8);
|
|
2539
|
+
const shown = [];
|
|
2540
|
+
for (const item of recentItems) shown.push(targetCard(item, state.targetId === item.id, "recent"));
|
|
2541
|
+
for (const item of mine) shown.push(targetCard(item, state.targetId === item.id, null));
|
|
2542
|
+
for (const item of recs) shown.push(targetCard(item, state.targetId === item.id, "recommended"));
|
|
2543
|
+
const sel = byId.get(state.targetId);
|
|
2544
|
+
if (sel && !recent.includes(sel.id) && !sel.custom && !sel.recommended) {
|
|
2545
|
+
shown.unshift(targetCard(sel, true, null));
|
|
2546
|
+
}
|
|
2547
|
+
if (!recentItems.length && !mine.length && !recs.length) {
|
|
2548
|
+
shown.push(h(
|
|
2549
|
+
"span",
|
|
2550
|
+
{ style: { color: "var(--text-muted, #8b909b)", fontSize: 11, padding: "4px 2px" } },
|
|
2551
|
+
shareT("share.noCompatible", { kind: kindLabel(kind) })
|
|
2552
|
+
));
|
|
2553
|
+
}
|
|
2554
|
+
shown.push(h("button", {
|
|
2555
|
+
type: "button",
|
|
2556
|
+
onClick: () => set({ manager: true }),
|
|
2557
|
+
style: {
|
|
2558
|
+
border: "1px dashed var(--border, #34363c)",
|
|
2559
|
+
background: "none",
|
|
2560
|
+
color: "var(--text-muted, #8b909b)",
|
|
2561
|
+
borderRadius: 8,
|
|
2562
|
+
padding: "4px 10px",
|
|
2563
|
+
fontSize: 12,
|
|
2564
|
+
cursor: "pointer"
|
|
2565
|
+
}
|
|
2566
|
+
}, shareT("share.more")));
|
|
2567
|
+
return h(
|
|
2568
|
+
"div",
|
|
2569
|
+
null,
|
|
2570
|
+
h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, marginBottom: 5 } }, shareT("share.targets")),
|
|
2571
|
+
h("div", { style: { display: "flex", flexWrap: "wrap", gap: 6 } }, ...shown)
|
|
2572
|
+
);
|
|
2573
|
+
}
|
|
2574
|
+
function pageInfo() {
|
|
2575
|
+
const ua = typeof navigator !== "undefined" && navigator.userAgent || "";
|
|
2576
|
+
let os = "";
|
|
2577
|
+
if (/Windows NT 10|Windows NT 11/.test(ua)) os = "Windows 10/11";
|
|
2578
|
+
else if (/Windows/.test(ua)) os = "Windows";
|
|
2579
|
+
else if (/Mac OS X|Macintosh/.test(ua)) os = "macOS";
|
|
2580
|
+
else if (/Android/.test(ua)) os = "Android";
|
|
2581
|
+
else if (/iPhone|iPad|iPod/.test(ua)) os = "iOS";
|
|
2582
|
+
else if (/Linux/.test(ua)) os = "Linux";
|
|
2583
|
+
let browser = "";
|
|
2584
|
+
const b = (re, name) => {
|
|
2585
|
+
const m = ua.match(re);
|
|
2586
|
+
if (m) browser = name + " " + (m[1] || "");
|
|
2587
|
+
};
|
|
2588
|
+
b(/Edg\/([\d.]+)/, "Edge");
|
|
2589
|
+
if (!browser) b(/OPR\/([\d.]+)/, "Opera");
|
|
2590
|
+
if (!browser) b(/Chrome\/([\d.]+)/, "Chrome");
|
|
2591
|
+
if (!browser) b(/Firefox\/([\d.]+)/, "Firefox");
|
|
2592
|
+
if (!browser) b(/Version\/([\d.]+).*Safari/, "Safari");
|
|
2593
|
+
const svc = ctxRef?.getExtService?.("pi-web.session");
|
|
2594
|
+
const cur = (() => {
|
|
2595
|
+
try {
|
|
2596
|
+
return svc?.get?.() ?? svc;
|
|
2597
|
+
} catch {
|
|
2598
|
+
return null;
|
|
2599
|
+
}
|
|
2600
|
+
})();
|
|
2601
|
+
const sum = cur?.session || null;
|
|
2602
|
+
const rowSess = state.payload?.session;
|
|
2603
|
+
const listTitle = (s) => s ? s.name || s.firstMessage || String(s.id || "").slice(0, 12) : "";
|
|
2604
|
+
const sessionId = rowSess?.id || sum?.id || cur?.sessionId || state.payload?.sessionId || state.payload?.sessionName || (typeof location !== "undefined" ? new URL(location.href).searchParams.get("session") : "") || "";
|
|
2605
|
+
const sessionName = listTitle(rowSess) || listTitle(sum) || state.payload?.sessionName || "";
|
|
2606
|
+
return { os, browser, url: typeof location !== "undefined" ? location.href : "", sessionId, sessionName };
|
|
2607
|
+
}
|
|
2608
|
+
var STAMP_LABELS = { os: "share.pi.os", browser: "share.pi.browser", url: "share.pi.url", sessionId: "share.pi.sessionId", sessionName: "share.pi.sessionName" };
|
|
2609
|
+
function stampBlock(stamp = state.stamp) {
|
|
2610
|
+
const info = pageInfo();
|
|
2611
|
+
const lines = [];
|
|
2612
|
+
for (const key of Object.keys(STAMP_LABELS)) {
|
|
2613
|
+
if (!stamp?.[key]) continue;
|
|
2614
|
+
const value = info[key];
|
|
2615
|
+
if (!value) continue;
|
|
2616
|
+
lines.push(`> **${shareT(STAMP_LABELS[key])}**: ${value}`);
|
|
2617
|
+
}
|
|
2618
|
+
return lines.length ? lines.join("\n") + "\n\n" : "";
|
|
2619
|
+
}
|
|
2620
|
+
function composeText() {
|
|
2621
|
+
return stampBlock() + (state.baseText ?? "");
|
|
2622
|
+
}
|
|
2623
|
+
function errorText() {
|
|
2624
|
+
const code = state.errorCode || "";
|
|
2625
|
+
const name = state.errorProvider || state.targets.find((t) => t.id === state.errorTarget)?.name || state.errorTarget || "";
|
|
2626
|
+
const rawDetail = state.errorDetail || "";
|
|
2627
|
+
const detail = rawDetail.length > 220 ? rawDetail.slice(0, 220) + "\u2026" : rawDetail;
|
|
2628
|
+
const key = {
|
|
2629
|
+
network: "share.err.network",
|
|
2630
|
+
timeout: "share.err.timeout",
|
|
2631
|
+
incomplete: "share.err.incomplete",
|
|
2632
|
+
auth: "share.err.auth",
|
|
2633
|
+
tooLarge: "share.err.tooLarge",
|
|
2634
|
+
unavailable: "share.err.unavailable",
|
|
2635
|
+
disabled: "share.err.disabled",
|
|
2636
|
+
unknownTarget: "share.err.unknownTarget",
|
|
2637
|
+
noSession: "share.err.noSession",
|
|
2638
|
+
imageFetch: "share.err.imageFetch",
|
|
2639
|
+
endpoint: "share.err.endpoint",
|
|
2640
|
+
badRequest: "share.err.badRequest",
|
|
2641
|
+
badSxcu: "share.err.badSxcu",
|
|
2642
|
+
noProbe: "share.err.noProbe",
|
|
2643
|
+
forbidden: "share.err.forbidden",
|
|
2644
|
+
kind: "share.err.kind"
|
|
2645
|
+
}[code];
|
|
2646
|
+
if (key) return shareT(key, { name, detail });
|
|
2647
|
+
return state.error || shareT("share.err.generic", { detail });
|
|
2648
|
+
}
|
|
2649
|
+
async function refreshPreview() {
|
|
2650
|
+
const raw = composeText();
|
|
2651
|
+
set({ rawText: raw });
|
|
2652
|
+
await applyRedaction(raw, state.redact);
|
|
2653
|
+
}
|
|
2654
|
+
function stampToggles() {
|
|
2655
|
+
return h(
|
|
2656
|
+
"span",
|
|
2657
|
+
{ style: { display: "flex", flexWrap: "wrap", gap: 8, alignItems: "center" } },
|
|
2658
|
+
...Object.keys(STAMP_LABELS).map((key) => h(
|
|
2659
|
+
"label",
|
|
2660
|
+
{
|
|
2661
|
+
key,
|
|
2662
|
+
title: shareT(STAMP_LABELS[key]),
|
|
2663
|
+
style: {
|
|
2664
|
+
display: "flex",
|
|
2665
|
+
gap: 3,
|
|
2666
|
+
alignItems: "center",
|
|
2667
|
+
cursor: "pointer",
|
|
2668
|
+
fontSize: 10,
|
|
2669
|
+
color: state.stamp[key] ? "var(--accent, #4d8dff)" : "var(--text-muted, #8b909b)"
|
|
2670
|
+
}
|
|
2671
|
+
},
|
|
2672
|
+
h("input", {
|
|
2673
|
+
type: "checkbox",
|
|
2674
|
+
checked: !!state.stamp[key],
|
|
2675
|
+
onChange: (e) => {
|
|
2676
|
+
set({ stamp: { ...state.stamp, [key]: e.target.checked } });
|
|
2677
|
+
void refreshPreview();
|
|
2678
|
+
}
|
|
2679
|
+
}),
|
|
2680
|
+
shareT(STAMP_LABELS[key])
|
|
2681
|
+
))
|
|
2682
|
+
);
|
|
2683
|
+
}
|
|
2684
|
+
async function applyRedaction(raw, redact) {
|
|
2685
|
+
try {
|
|
2686
|
+
const r = await getJSON("preview-redact", {
|
|
2687
|
+
method: "POST",
|
|
2688
|
+
headers: { "content-type": "application/json" },
|
|
2689
|
+
body: JSON.stringify({ text: raw, redact })
|
|
2690
|
+
});
|
|
2691
|
+
set({ text: r.text, redactHits: r.hits || [], redact });
|
|
2692
|
+
} catch (e) {
|
|
2693
|
+
set({ text: raw, redactHits: [], redact });
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
function previewSection() {
|
|
2697
|
+
return h(
|
|
2698
|
+
"div",
|
|
2699
|
+
null,
|
|
2700
|
+
// Header row: label | page-info multi-select | redact toggle
|
|
2701
|
+
h(
|
|
2702
|
+
"div",
|
|
2703
|
+
{ style: { display: "flex", alignItems: "center", gap: 10, marginBottom: 5, flexWrap: "wrap" } },
|
|
2704
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11 } }, shareT("share.preview")),
|
|
2705
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, opacity: 0.8 } }, shareT("share.pageInfo") + ":"),
|
|
2706
|
+
stampToggles(),
|
|
2707
|
+
h(
|
|
2708
|
+
"label",
|
|
2709
|
+
{
|
|
2710
|
+
title: shareT("share.redactAuto"),
|
|
2711
|
+
style: {
|
|
2712
|
+
marginLeft: "auto",
|
|
2713
|
+
display: "flex",
|
|
2714
|
+
gap: 5,
|
|
2715
|
+
alignItems: "center",
|
|
2716
|
+
cursor: "pointer",
|
|
2717
|
+
fontSize: 11,
|
|
2718
|
+
color: state.redactHits.length ? "#d9a13c" : "var(--text-muted, #8b909b)"
|
|
2719
|
+
}
|
|
2720
|
+
},
|
|
2721
|
+
h("input", { type: "checkbox", checked: state.redact, onChange: (e) => {
|
|
2722
|
+
set({ redact: e.target.checked });
|
|
2723
|
+
void applyRedaction(state.rawText, e.target.checked);
|
|
2724
|
+
} }),
|
|
2725
|
+
shareT("share.redactToggle"),
|
|
2726
|
+
state.redactHits.length ? ` (${state.redactHits.reduce((a, b) => a + b.count, 0)})` : ""
|
|
2727
|
+
)
|
|
2728
|
+
),
|
|
2729
|
+
h("textarea", {
|
|
2730
|
+
value: state.text,
|
|
2731
|
+
onInput: (e) => {
|
|
2732
|
+
const v = e.target.value;
|
|
2733
|
+
set({ text: v, rawText: v, baseText: v, redactHits: [] });
|
|
2734
|
+
},
|
|
2735
|
+
style: {
|
|
2736
|
+
width: "100%",
|
|
2737
|
+
minHeight: 100,
|
|
2738
|
+
resize: "vertical",
|
|
2739
|
+
background: "var(--bg-hover, #25272c)",
|
|
2740
|
+
border: "1px solid var(--border, #34363c)",
|
|
2741
|
+
color: "var(--text, #d8dade)",
|
|
2742
|
+
borderRadius: 8,
|
|
2743
|
+
padding: 9,
|
|
2744
|
+
font: "12px/1.6 ui-monospace, Consolas, monospace"
|
|
2745
|
+
}
|
|
2746
|
+
}),
|
|
2747
|
+
...state.redactHits.length ? [h(
|
|
2748
|
+
"div",
|
|
2749
|
+
{ style: { color: "#d9a13c", fontSize: 11, marginTop: 4 } },
|
|
2750
|
+
"\u{1F6E1} " + state.redactHits.map((x) => `${x.rule}\xD7${x.count}`).join(" \xB7 ")
|
|
2751
|
+
)] : []
|
|
2752
|
+
);
|
|
2753
|
+
}
|
|
2754
|
+
function resultSection() {
|
|
2755
|
+
const r = state.result;
|
|
2756
|
+
const rurl = r.url;
|
|
2757
|
+
const isDeep = /^(joplin|obsidian|siyuan):/.test(rurl);
|
|
2758
|
+
return h(
|
|
2759
|
+
"div",
|
|
2760
|
+
{ style: {
|
|
2761
|
+
border: "1px solid #3fbf6e55",
|
|
2762
|
+
background: "#3fbf6e10",
|
|
2763
|
+
borderRadius: 9,
|
|
2764
|
+
padding: 11,
|
|
2765
|
+
display: "flex",
|
|
2766
|
+
gap: 12,
|
|
2767
|
+
alignItems: "center"
|
|
2768
|
+
} },
|
|
2769
|
+
h(
|
|
2770
|
+
"div",
|
|
2771
|
+
{ style: { flex: 1, minWidth: 0 } },
|
|
2772
|
+
h("a", {
|
|
2773
|
+
href: rurl,
|
|
2774
|
+
target: "_blank",
|
|
2775
|
+
rel: "noopener noreferrer",
|
|
2776
|
+
title: shareT("share.openInNewTab") || rurl,
|
|
2777
|
+
style: {
|
|
2778
|
+
color: "var(--accent, #4d8dff)",
|
|
2779
|
+
fontFamily: "monospace",
|
|
2780
|
+
fontSize: 12,
|
|
2781
|
+
wordBreak: "break-all",
|
|
2782
|
+
textDecoration: "none",
|
|
2783
|
+
cursor: "pointer"
|
|
2784
|
+
},
|
|
2785
|
+
onMouseEnter: (e) => {
|
|
2786
|
+
e.currentTarget.style.textDecoration = "underline";
|
|
2787
|
+
},
|
|
2788
|
+
onMouseLeave: (e) => {
|
|
2789
|
+
e.currentTarget.style.textDecoration = "none";
|
|
2790
|
+
}
|
|
2791
|
+
}, rurl),
|
|
2792
|
+
h(
|
|
2793
|
+
"div",
|
|
2794
|
+
{ style: { display: "flex", gap: 7, marginTop: 9, flexWrap: "wrap" } },
|
|
2795
|
+
btn(shareT("share.copy"), () => navigator.clipboard?.writeText(rurl).catch(() => {
|
|
2796
|
+
})),
|
|
2797
|
+
!isDeep && typeof navigator !== "undefined" && navigator.share ? btn(shareT("share.system"), () => navigator.share({ url: rurl, title: state.title }).catch(() => {
|
|
2798
|
+
})) : null,
|
|
2799
|
+
r.extra?.rawUrl ? h("a", {
|
|
2800
|
+
href: r.extra.rawUrl,
|
|
2801
|
+
target: "_blank",
|
|
2802
|
+
rel: "noopener",
|
|
2803
|
+
style: { fontSize: 12, color: "var(--accent, #4d8dff)" }
|
|
2804
|
+
}, shareT("share.raw")) : null,
|
|
2805
|
+
r.extra?.deletionUrl ? h("a", {
|
|
2806
|
+
href: r.extra.deletionUrl,
|
|
2807
|
+
target: "_blank",
|
|
2808
|
+
rel: "noopener",
|
|
2809
|
+
style: { fontSize: 12, color: "#e05d5d" }
|
|
2810
|
+
}, shareT("share.delete")) : null
|
|
2811
|
+
)
|
|
2812
|
+
),
|
|
2813
|
+
h("canvas", {
|
|
2814
|
+
ref: (el) => {
|
|
2815
|
+
if (el && !isDeep) import_qrcode.default.toCanvas(el, rurl, { width: 84, margin: 1 }).catch(() => {
|
|
2816
|
+
});
|
|
2817
|
+
},
|
|
2818
|
+
style: { display: isDeep ? "none" : "block", width: 84, height: 84, background: "#fff", borderRadius: 6, padding: 4 }
|
|
2819
|
+
})
|
|
2820
|
+
);
|
|
2821
|
+
}
|
|
2822
|
+
async function doShare() {
|
|
2823
|
+
if (!state.targetId || state.busy) return;
|
|
2824
|
+
set({ busy: true, error: "" });
|
|
2825
|
+
try {
|
|
2826
|
+
const body = {
|
|
2827
|
+
...state.payload || {},
|
|
2828
|
+
targetId: state.targetId,
|
|
2829
|
+
kind: state.kind,
|
|
2830
|
+
text: state.text,
|
|
2831
|
+
title: state.title,
|
|
2832
|
+
tags: state.tags,
|
|
2833
|
+
redact: false
|
|
2834
|
+
};
|
|
2835
|
+
if (state.kind === "image" && body.imageSrc) {
|
|
2836
|
+
const blob = await fetch(body.imageSrc).then((r2) => {
|
|
2837
|
+
if (!r2.ok) throw new Error("HTTP " + r2.status);
|
|
2838
|
+
return r2.blob();
|
|
2839
|
+
}).catch((e) => {
|
|
2840
|
+
throw Object.assign(new Error(shareT("share.err.imageFetch", { detail: e?.message || e })), { detail: String(e?.message || e) });
|
|
2841
|
+
});
|
|
2842
|
+
const dataUrl = await new Promise((res, rej) => {
|
|
2843
|
+
const fr = new FileReader();
|
|
2844
|
+
fr.onload = () => res(String(fr.result));
|
|
2845
|
+
fr.onerror = () => rej(new Error("FileReader failed"));
|
|
2846
|
+
fr.readAsDataURL(blob);
|
|
2847
|
+
});
|
|
2848
|
+
body.imageBase64 = dataUrl;
|
|
2849
|
+
body.mime = blob.type || "image/png";
|
|
2850
|
+
body.filename = body.filename || "image." + (blob.type.split("/")[1] || "png").replace("jpeg", "jpg");
|
|
2851
|
+
}
|
|
2852
|
+
const r = await getJSON("share", {
|
|
2853
|
+
method: "POST",
|
|
2854
|
+
headers: { "content-type": "application/json" },
|
|
2855
|
+
body: JSON.stringify(body)
|
|
2856
|
+
});
|
|
2857
|
+
recentAdd(state.targetId);
|
|
2858
|
+
set({ result: r, busy: false, redactHits: r.hits || [] });
|
|
2859
|
+
} catch (e) {
|
|
2860
|
+
set({
|
|
2861
|
+
busy: false,
|
|
2862
|
+
error: e.message,
|
|
2863
|
+
errorDetail: e.detail || api("share"),
|
|
2864
|
+
errorCode: e.kind || "",
|
|
2865
|
+
errorTarget: e.targetId || "",
|
|
2866
|
+
errorProvider: e.providerLabel || ""
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
var dialogBodyEl = null;
|
|
2871
|
+
function ShareDialogHost() {
|
|
2872
|
+
const [, setTick] = ctxRef.useState(0);
|
|
2873
|
+
ctxRef.useEffect(() => {
|
|
2874
|
+
const fn = () => setTick((n) => n + 1);
|
|
2875
|
+
listeners.add(fn);
|
|
2876
|
+
return () => listeners.delete(fn);
|
|
2877
|
+
}, []);
|
|
2878
|
+
const result = state.result;
|
|
2879
|
+
ctxRef.useEffect(() => {
|
|
2880
|
+
if (result && dialogBodyEl) {
|
|
2881
|
+
try {
|
|
2882
|
+
dialogBodyEl.scrollTop = dialogBodyEl.scrollHeight;
|
|
2883
|
+
} catch (e) {
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
}, [result]);
|
|
2887
|
+
return shareDialog();
|
|
2888
|
+
}
|
|
2889
|
+
function shareDialog() {
|
|
2890
|
+
if (!state.open) return null;
|
|
2891
|
+
if (state.manager) return managerDialog();
|
|
2892
|
+
const head = h(
|
|
2893
|
+
"div",
|
|
2894
|
+
{ style: {
|
|
2895
|
+
display: "flex",
|
|
2896
|
+
alignItems: "center",
|
|
2897
|
+
gap: 8,
|
|
2898
|
+
padding: "10px 14px",
|
|
2899
|
+
flexShrink: 0,
|
|
2900
|
+
borderBottom: "1px solid var(--border, #34363c)",
|
|
2901
|
+
background: "var(--bg-hover, #25272c)",
|
|
2902
|
+
borderRadius: "9px 9px 0 0"
|
|
2903
|
+
} },
|
|
2904
|
+
h("span", { style: { fontWeight: 600 } }, shareT("share.action")),
|
|
2905
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11 } }, shareT("share.subtitle", { kind: state.kind, chars: state.text.length })),
|
|
2906
|
+
h("div", { style: { flex: 1 } }),
|
|
2907
|
+
h("button", {
|
|
2908
|
+
type: "button",
|
|
2909
|
+
onClick: () => set({ open: false }),
|
|
2910
|
+
style: { background: "none", border: "none", color: "var(--text-muted, #8b909b)", cursor: "pointer", fontSize: 14 }
|
|
2911
|
+
}, "\u2715")
|
|
2912
|
+
);
|
|
2913
|
+
const body = h(
|
|
2914
|
+
"div",
|
|
2915
|
+
{
|
|
2916
|
+
ref: (el) => {
|
|
2917
|
+
dialogBodyEl = el;
|
|
2918
|
+
},
|
|
2919
|
+
style: { padding: "12px 14px", display: "flex", flexDirection: "column", gap: 12, flex: 1, minHeight: 0, overflowY: "auto" }
|
|
2920
|
+
},
|
|
2921
|
+
previewSection(),
|
|
2922
|
+
sinkSection(),
|
|
2923
|
+
targetSection(),
|
|
2924
|
+
h(
|
|
2925
|
+
"div",
|
|
2926
|
+
{ style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 9 } },
|
|
2927
|
+
h("input", {
|
|
2928
|
+
value: state.title,
|
|
2929
|
+
placeholder: shareT("share.titleField"),
|
|
2930
|
+
onInput: (e) => set({ title: e.target.value }),
|
|
2931
|
+
style: { background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", color: "var(--text, #d8dade)", borderRadius: 7, padding: "6px 9px", fontSize: 12 }
|
|
2932
|
+
}),
|
|
2933
|
+
h("input", {
|
|
2934
|
+
value: state.tags,
|
|
2935
|
+
placeholder: shareT("share.tagsField"),
|
|
2936
|
+
onInput: (e) => set({ tags: e.target.value }),
|
|
2937
|
+
style: { background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", color: "var(--text, #d8dade)", borderRadius: 7, padding: "6px 9px", fontSize: 12 }
|
|
2938
|
+
})
|
|
2939
|
+
),
|
|
2940
|
+
state.error ? h(
|
|
2941
|
+
"div",
|
|
2942
|
+
{ style: {
|
|
2943
|
+
border: "1px solid #e05d5d66",
|
|
2944
|
+
background: "#e05d5d18",
|
|
2945
|
+
borderRadius: 8,
|
|
2946
|
+
padding: "8px 10px",
|
|
2947
|
+
color: "#e05d5d",
|
|
2948
|
+
fontSize: 12,
|
|
2949
|
+
userSelect: "text",
|
|
2950
|
+
cursor: "text",
|
|
2951
|
+
wordBreak: "break-word"
|
|
2952
|
+
} },
|
|
2953
|
+
errorText(),
|
|
2954
|
+
state.errorDetail && state.errorDetail !== errorText() ? h("div", { style: { fontSize: 10, opacity: 0.75, marginTop: 4, fontFamily: "monospace" } }, state.errorDetail) : null,
|
|
2955
|
+
state.errorTarget ? h(
|
|
2956
|
+
"div",
|
|
2957
|
+
{ style: { marginTop: 6 } },
|
|
2958
|
+
h("button", {
|
|
2959
|
+
type: "button",
|
|
2960
|
+
onClick: () => set({ manager: true, editing: state.errorTarget }),
|
|
2961
|
+
style: {
|
|
2962
|
+
border: "1px solid #e05d5d",
|
|
2963
|
+
background: "none",
|
|
2964
|
+
color: "#e05d5d",
|
|
2965
|
+
borderRadius: 6,
|
|
2966
|
+
padding: "3px 9px",
|
|
2967
|
+
fontSize: 11,
|
|
2968
|
+
cursor: "pointer"
|
|
2969
|
+
}
|
|
2970
|
+
}, shareT("share.fixTarget"))
|
|
2971
|
+
) : null
|
|
2972
|
+
) : null,
|
|
2973
|
+
state.result ? resultSection() : null
|
|
2974
|
+
);
|
|
2975
|
+
const footer = h(
|
|
2976
|
+
"div",
|
|
2977
|
+
{ style: {
|
|
2978
|
+
display: "flex",
|
|
2979
|
+
justifyContent: "flex-end",
|
|
2980
|
+
gap: 8,
|
|
2981
|
+
flexShrink: 0,
|
|
2982
|
+
padding: "10px 14px",
|
|
2983
|
+
borderTop: "1px solid var(--border, #34363c)",
|
|
2984
|
+
background: "var(--bg-hover, #25272c)"
|
|
2985
|
+
} },
|
|
2986
|
+
btn(shareT("share.manage"), () => set({
|
|
2987
|
+
manager: true,
|
|
2988
|
+
...state.errorTarget ? { editing: state.errorTarget } : {}
|
|
2989
|
+
})),
|
|
2990
|
+
btn(state.busy ? shareT("share.uploading") : shareT("share.action"), doShare, { primary: true, disabled: state.busy })
|
|
2991
|
+
);
|
|
2992
|
+
return h("div", {
|
|
2993
|
+
"data-ext-float": "1",
|
|
2994
|
+
"data-ext-float-w": "640",
|
|
2995
|
+
"data-ext-float-h": "520",
|
|
2996
|
+
style: {
|
|
2997
|
+
background: "var(--bg-panel, #1e2021)",
|
|
2998
|
+
border: "1px solid var(--border, #34363c)",
|
|
2999
|
+
borderRadius: 10,
|
|
3000
|
+
boxShadow: "0 14px 44px #000a",
|
|
3001
|
+
overflow: "hidden",
|
|
3002
|
+
font: "13px/1.5 system-ui, sans-serif",
|
|
3003
|
+
color: "var(--text, #d8dade)",
|
|
3004
|
+
display: "flex",
|
|
3005
|
+
flexDirection: "column",
|
|
3006
|
+
maxHeight: "88vh"
|
|
3007
|
+
}
|
|
3008
|
+
}, head, body, footer);
|
|
3009
|
+
}
|
|
3010
|
+
function managerDialog() {
|
|
3011
|
+
const q = state.search.toLowerCase();
|
|
3012
|
+
const groups = { recent: [], recommended: [], all: [] };
|
|
3013
|
+
const recentIds = recentGet();
|
|
3014
|
+
for (const t of state.targets) {
|
|
3015
|
+
if (q && !(t.name || t.id).toLowerCase().includes(q)) continue;
|
|
3016
|
+
if (recentIds.includes(t.id)) groups.recent.push(t);
|
|
3017
|
+
else if (t.recommended) groups.recommended.push(t);
|
|
3018
|
+
else groups.all.push(t);
|
|
3019
|
+
}
|
|
3020
|
+
const item = (t) => h(
|
|
3021
|
+
"div",
|
|
3022
|
+
{
|
|
3023
|
+
key: t.id,
|
|
3024
|
+
onClick: () => set({
|
|
3025
|
+
editing: t.id,
|
|
3026
|
+
form: { ...t.values && !Array.isArray(t.values) ? t.values : {} }
|
|
3027
|
+
}),
|
|
3028
|
+
style: {
|
|
3029
|
+
display: "flex",
|
|
3030
|
+
alignItems: "center",
|
|
3031
|
+
gap: 7,
|
|
3032
|
+
padding: "5px 8px",
|
|
3033
|
+
borderRadius: 7,
|
|
3034
|
+
cursor: "pointer",
|
|
3035
|
+
background: state.editing === t.id ? "rgba(77, 141, 255, 0.15)" : "none",
|
|
3036
|
+
opacity: t.status === "dead" ? 0.5 : 1
|
|
3037
|
+
}
|
|
3038
|
+
},
|
|
3039
|
+
h("span", null, t.status === "dead" ? "\u{1F480}" : t.category === "archive" ? "\u{1F4D3}" : "\u{1F517}"),
|
|
3040
|
+
h(
|
|
3041
|
+
"div",
|
|
3042
|
+
{ style: { flex: 1, minWidth: 0 } },
|
|
3043
|
+
h("div", { style: { fontSize: 12, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, t.name || t.id),
|
|
3044
|
+
h("div", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)" } }, (t.kinds || []).map(kindLabel).join("/") + (() => {
|
|
3045
|
+
const n = noteText(t.note);
|
|
3046
|
+
return n ? " \xB7 " + n : "";
|
|
3047
|
+
})())
|
|
3048
|
+
),
|
|
3049
|
+
(() => {
|
|
3050
|
+
const b = CFG_BADGE[t.configState];
|
|
3051
|
+
return b ? h("span", {
|
|
3052
|
+
title: shareT(b.key),
|
|
3053
|
+
style: { color: b.color, fontSize: 9, whiteSpace: "nowrap", flexShrink: 0 }
|
|
3054
|
+
}, b.icon) : null;
|
|
3055
|
+
})(),
|
|
3056
|
+
t.recommended ? h("span", { style: { color: "var(--accent, #4d8dff)", fontSize: 10 } }, "\u2605") : null,
|
|
3057
|
+
// "Use" closes the loop: pick this target for the pending share and return to it.
|
|
3058
|
+
!supportsKind(t, contentKind()) ? h("span", {
|
|
3059
|
+
title: shareT("share.notCompatible", { kind: kindLabel(contentKind()) }),
|
|
3060
|
+
style: { color: "var(--text-muted, #8b909b)", fontSize: 9, whiteSpace: "nowrap", flexShrink: 0 }
|
|
3061
|
+
}, "\u2205") : t.status !== "dead" && t.configState !== "needs-setup" ? h("button", {
|
|
3062
|
+
type: "button",
|
|
3063
|
+
title: shareT("share.useTarget"),
|
|
3064
|
+
onClick: (e) => {
|
|
3065
|
+
e.stopPropagation();
|
|
3066
|
+
chooseTarget(t.id);
|
|
3067
|
+
},
|
|
3068
|
+
style: {
|
|
3069
|
+
border: "1px solid var(--accent, #4d8dff)",
|
|
3070
|
+
background: state.targetId === t.id ? "var(--accent, #4d8dff)" : "none",
|
|
3071
|
+
color: state.targetId === t.id ? "#fff" : "var(--accent, #4d8dff)",
|
|
3072
|
+
borderRadius: 6,
|
|
3073
|
+
padding: "2px 8px",
|
|
3074
|
+
fontSize: 10,
|
|
3075
|
+
cursor: "pointer",
|
|
3076
|
+
flexShrink: 0
|
|
3077
|
+
}
|
|
3078
|
+
}, shareT("share.use")) : h("button", {
|
|
3079
|
+
type: "button",
|
|
3080
|
+
title: shareT("share.setupFirst"),
|
|
3081
|
+
onClick: (e) => {
|
|
3082
|
+
e.stopPropagation();
|
|
3083
|
+
set({ editing: t.id, form: {} });
|
|
3084
|
+
},
|
|
3085
|
+
style: {
|
|
3086
|
+
border: "1px solid #d9a13c",
|
|
3087
|
+
background: "none",
|
|
3088
|
+
color: "#d9a13c",
|
|
3089
|
+
borderRadius: 6,
|
|
3090
|
+
padding: "2px 8px",
|
|
3091
|
+
fontSize: 10,
|
|
3092
|
+
cursor: "pointer",
|
|
3093
|
+
flexShrink: 0
|
|
3094
|
+
}
|
|
3095
|
+
}, shareT("share.setup"))
|
|
3096
|
+
);
|
|
3097
|
+
const edit = state.targets.find((t) => t.id === state.editing);
|
|
3098
|
+
const fields = edit?.fields || [];
|
|
3099
|
+
const form = edit ? h(
|
|
3100
|
+
"div",
|
|
3101
|
+
{ style: { flex: 1, padding: 14, display: "flex", flexDirection: "column", gap: 12, overflowY: "auto" } },
|
|
3102
|
+
h("div", { style: { fontWeight: 600 } }, edit.name || edit.id),
|
|
3103
|
+
(() => {
|
|
3104
|
+
const n = noteText(edit.note);
|
|
3105
|
+
return n ? h("div", { style: { fontSize: 11, color: "var(--text-muted, #8b909b)" } }, n) : null;
|
|
3106
|
+
})(),
|
|
3107
|
+
...fields.map((f) => {
|
|
3108
|
+
const key = typeof f === "string" ? f : f.key;
|
|
3109
|
+
const label = typeof f === "string" ? f : f.label || f.key;
|
|
3110
|
+
const type = typeof f === "string" ? "password" : f.type || "text";
|
|
3111
|
+
const hint = typeof f === "string" ? "" : f.hint || "";
|
|
3112
|
+
const opts = typeof f === "string" ? null : f.options;
|
|
3113
|
+
return h(
|
|
3114
|
+
"div",
|
|
3115
|
+
null,
|
|
3116
|
+
h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, marginBottom: 3 } }, label + (f.required ? " *" : "")),
|
|
3117
|
+
opts ? h(
|
|
3118
|
+
"select",
|
|
3119
|
+
{
|
|
3120
|
+
value: state.form[key] ?? edit.values?.[key] ?? opts[0]?.value ?? "",
|
|
3121
|
+
onChange: (e) => set({ form: { ...state.form, [key]: e.target.value } }),
|
|
3122
|
+
style: { width: "100%", background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", borderRadius: 7, padding: "6px 9px", color: "var(--text, #d8dade)" }
|
|
3123
|
+
},
|
|
3124
|
+
...opts.map((o) => h("option", { value: o.value }, o.label))
|
|
3125
|
+
) : h("input", {
|
|
3126
|
+
type: type === "password" ? "password" : "text",
|
|
3127
|
+
value: state.form[key] ?? "",
|
|
3128
|
+
placeholder: edit.values?.[key] ? shareT("share.notSet") + " " + edit.values[key] : hint || label,
|
|
3129
|
+
onInput: (e) => set({ form: { ...state.form, [key]: e.target.value } }),
|
|
3130
|
+
style: { width: "100%", background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", borderRadius: 7, padding: "6px 9px", color: "var(--text, #d8dade)" }
|
|
3131
|
+
}),
|
|
3132
|
+
hint ? h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, marginTop: 3 } }, hint) : null
|
|
3133
|
+
);
|
|
3134
|
+
}),
|
|
3135
|
+
fields.length === 0 ? h(
|
|
3136
|
+
"div",
|
|
3137
|
+
{ style: { fontSize: 12, color: "var(--text-muted, #8b909b)" } },
|
|
3138
|
+
shareT("share.noSetup")
|
|
3139
|
+
) : null,
|
|
3140
|
+
...edit.custom ? [btn(shareT("share.deleteTarget"), () => void getJSON(`targets?id=${encodeURIComponent(edit.id)}`, { method: "DELETE" }).then(() => refresh()), { title: shareT("share.delete") })] : [],
|
|
3141
|
+
btn(shareT("share.saveTest"), async () => {
|
|
3142
|
+
try {
|
|
3143
|
+
const saved = await getJSON("targets", {
|
|
3144
|
+
method: "POST",
|
|
3145
|
+
headers: { "content-type": "application/json" },
|
|
3146
|
+
body: JSON.stringify({ id: edit.id, provider: edit.provider, name: edit.name, values: { ...edit.values, ...state.form } })
|
|
3147
|
+
});
|
|
3148
|
+
const probe = await getJSON("targets/test", {
|
|
3149
|
+
method: "POST",
|
|
3150
|
+
headers: { "content-type": "application/json" },
|
|
3151
|
+
body: JSON.stringify({ provider: edit.provider, values: { ...edit.values, ...state.form } })
|
|
3152
|
+
});
|
|
3153
|
+
set({ error: probe.ok ? shareT("share.testOk") : shareT("share.testFail", { detail: probe.detail || "" }) });
|
|
3154
|
+
void refresh();
|
|
3155
|
+
} catch (e) {
|
|
3156
|
+
set({ error: e.message });
|
|
3157
|
+
}
|
|
3158
|
+
}),
|
|
3159
|
+
// After configuring, jump straight back into the share flow with this target.
|
|
3160
|
+
btn(shareT("share.saveUse"), async () => {
|
|
3161
|
+
try {
|
|
3162
|
+
await getJSON("targets", {
|
|
3163
|
+
method: "POST",
|
|
3164
|
+
headers: { "content-type": "application/json" },
|
|
3165
|
+
body: JSON.stringify({ id: edit.id, provider: edit.provider, name: edit.name, values: { ...edit.values, ...state.form } })
|
|
3166
|
+
});
|
|
3167
|
+
void refresh();
|
|
3168
|
+
chooseTarget(edit.id);
|
|
3169
|
+
} catch (e) {
|
|
3170
|
+
set({ error: e.message });
|
|
3171
|
+
}
|
|
3172
|
+
}, { primary: true })
|
|
3173
|
+
) : h("div", { style: { flex: 1, padding: 20, color: "var(--text-muted, #8b909b)" } }, shareT("share.selectTarget"));
|
|
3174
|
+
const localProbe = state.probe.length ? h(
|
|
3175
|
+
"div",
|
|
3176
|
+
{ style: { background: "#3fbf6e10", border: "1px solid #3fbf6e44", borderRadius: 7, padding: "6px 9px", fontSize: 11, color: "var(--accent, #4d8dff)" } },
|
|
3177
|
+
shareT("share.probeDetected", { ports: state.probe.map((p) => ":" + p.port).join(", ") })
|
|
3178
|
+
) : null;
|
|
3179
|
+
return h(
|
|
3180
|
+
"div",
|
|
3181
|
+
{
|
|
3182
|
+
"data-ext-float": "1",
|
|
3183
|
+
"data-ext-float-w": "820",
|
|
3184
|
+
"data-ext-float-h": "560",
|
|
3185
|
+
style: {
|
|
3186
|
+
display: "flex",
|
|
3187
|
+
flexDirection: "column",
|
|
3188
|
+
maxHeight: "88vh",
|
|
3189
|
+
background: "var(--bg-panel, #1e2021)",
|
|
3190
|
+
border: "1px solid var(--border, #34363c)",
|
|
3191
|
+
borderRadius: 10,
|
|
3192
|
+
boxShadow: "0 14px 44px #000a",
|
|
3193
|
+
overflow: "hidden",
|
|
3194
|
+
color: "var(--text, #d8dade)",
|
|
3195
|
+
font: "13px/1.5 system-ui"
|
|
3196
|
+
}
|
|
3197
|
+
},
|
|
3198
|
+
h(
|
|
3199
|
+
"div",
|
|
3200
|
+
{ style: { display: "flex", alignItems: "center", gap: 8, padding: "10px 14px", background: "var(--bg-hover, #25272c)", borderBottom: "1px solid var(--border, #34363c)" } },
|
|
3201
|
+
// Return to the share flow without losing the pending content.
|
|
3202
|
+
h("button", {
|
|
3203
|
+
type: "button",
|
|
3204
|
+
title: shareT("share.backToShare"),
|
|
3205
|
+
onClick: () => set({ manager: false }),
|
|
3206
|
+
style: { background: "none", border: "none", color: "var(--accent, #4d8dff)", cursor: "pointer", fontSize: 14 }
|
|
3207
|
+
}, "\u2190"),
|
|
3208
|
+
h("span", { style: { fontWeight: 600 } }, shareT("share.targets")),
|
|
3209
|
+
h("div", { style: { flex: 1 } }),
|
|
3210
|
+
btn("\u27F3", () => void refresh(true), { title: shareT("share.refresh") }),
|
|
3211
|
+
h("button", {
|
|
3212
|
+
type: "button",
|
|
3213
|
+
onClick: () => set({ manager: false, open: false }),
|
|
3214
|
+
style: { background: "none", border: "none", color: "var(--text-muted, #8b909b)", cursor: "pointer" }
|
|
3215
|
+
}, "\u2715")
|
|
3216
|
+
),
|
|
3217
|
+
localProbe,
|
|
3218
|
+
h(
|
|
3219
|
+
"div",
|
|
3220
|
+
{ style: { display: "flex", flex: 1, minHeight: 0 } },
|
|
3221
|
+
h(
|
|
3222
|
+
"div",
|
|
3223
|
+
{ style: { width: 300, borderRight: "1px solid var(--border, #34363c)", display: "flex", flexDirection: "column" } },
|
|
3224
|
+
h("div", { style: { padding: 8 } }, h("input", {
|
|
3225
|
+
value: state.search,
|
|
3226
|
+
placeholder: shareT("share.search"),
|
|
3227
|
+
onInput: (e) => set({ search: e.target.value }),
|
|
3228
|
+
style: { width: "100%", background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", borderRadius: 7, padding: "6px 9px", color: "var(--text, #d8dade)", fontSize: 12 }
|
|
3229
|
+
})),
|
|
3230
|
+
h(
|
|
3231
|
+
"div",
|
|
3232
|
+
{ style: { overflow: "auto", flex: 1, padding: "0 8px 10px" } },
|
|
3233
|
+
groups.recent.length ? h("div", null, h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, padding: "6px" } }, shareT("share.recent")), ...groups.recent.map(item)) : null,
|
|
3234
|
+
groups.recommended.length ? h("div", null, h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, padding: "6px" } }, shareT("share.recommended")), ...groups.recommended.map(item)) : null,
|
|
3235
|
+
h("div", null, h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, padding: "6px" } }, shareT("share.allTargets", { n: state.targets.length })), ...groups.all.map(item))
|
|
3236
|
+
),
|
|
3237
|
+
h(
|
|
3238
|
+
"div",
|
|
3239
|
+
{ style: { borderTop: "1px solid var(--border, #34363c)", padding: 8, display: "flex", gap: 6 } },
|
|
3240
|
+
btn(shareT("share.importSxcu"), () => {
|
|
3241
|
+
const text = window.prompt(shareT("share.importPrompt"));
|
|
3242
|
+
if (!text) return;
|
|
3243
|
+
void getJSON("import-sxcu", {
|
|
3244
|
+
method: "POST",
|
|
3245
|
+
headers: { "content-type": "application/json" },
|
|
3246
|
+
body: JSON.stringify({ config: text })
|
|
3247
|
+
}).then(() => refresh()).catch((e) => set({ error: e.message }));
|
|
3248
|
+
}),
|
|
3249
|
+
btn(shareT("share.clearRecent"), () => {
|
|
3250
|
+
recentClear();
|
|
3251
|
+
emit();
|
|
3252
|
+
})
|
|
3253
|
+
)
|
|
3254
|
+
),
|
|
3255
|
+
form
|
|
3256
|
+
),
|
|
3257
|
+
state.error ? h("div", { style: { padding: "6px 14px", color: "var(--accent, #4d8dff)", fontSize: 11 } }, state.error) : null
|
|
3258
|
+
);
|
|
3259
|
+
}
|
|
3260
|
+
function register(ctx) {
|
|
3261
|
+
h = ctx.h;
|
|
3262
|
+
ctxRef = ctx;
|
|
3263
|
+
tFn = typeof ctx.t === "function" ? ctx.t.bind(ctx) : null;
|
|
3264
|
+
if (typeof ctx.apiUrl === "function") apiUrlFn = ctx.apiUrl.bind(ctx);
|
|
3265
|
+
ctx.registerItems("dialogs", [{ id: "aiti-msg-share-dialog", render: () => ShareDialogHost() }]);
|
|
3266
|
+
const shareAction = (label) => (props) => h("button", {
|
|
3267
|
+
type: "button",
|
|
3268
|
+
title: label,
|
|
3269
|
+
onClick: () => openShare({ kind: "message", text: props?.text || "", sessionId: props?.sessionId }),
|
|
3270
|
+
style: {
|
|
3271
|
+
display: "inline-flex",
|
|
3272
|
+
alignItems: "center",
|
|
3273
|
+
gap: 4,
|
|
3274
|
+
padding: "3px 8px",
|
|
3275
|
+
height: 22,
|
|
3276
|
+
border: "none",
|
|
3277
|
+
background: "none",
|
|
3278
|
+
borderRadius: 5,
|
|
3279
|
+
color: "var(--text-dim, #8b909b)",
|
|
3280
|
+
cursor: "pointer",
|
|
3281
|
+
fontSize: 11
|
|
3282
|
+
}
|
|
3283
|
+
}, icon("share", 12), label);
|
|
3284
|
+
ctx.registerItems("userMessageActions", [{ id: "aiti-msg-share-user", render: shareAction(shareT("share.action")), meta: { order: 1 } }]);
|
|
3285
|
+
ctx.registerItems("assistantMessageActions", [
|
|
3286
|
+
{ id: "aiti-msg-share-assistant", render: shareAction(shareT("share.action")), meta: { order: 1 } },
|
|
3287
|
+
{ id: "aiti-msg-share-assistant-top", render: shareAction(shareT("share.action")), meta: { placement: "top", order: 1 } }
|
|
3288
|
+
]);
|
|
3289
|
+
ctx.registerItems("commands", [{
|
|
3290
|
+
id: "aiti-msg-share.center",
|
|
3291
|
+
render: () => null,
|
|
3292
|
+
meta: { label: shareT("share.center"), onClick: () => openShare({ kind: "session" }) }
|
|
3293
|
+
}]);
|
|
3294
|
+
if (typeof ctx.registerExtService === "function") {
|
|
3295
|
+
ctx.registerExtService("aiti-msg-share.openShare", (payload) => openShare(payload));
|
|
3296
|
+
}
|
|
3297
|
+
if (typeof ctx.registerTopicItem === "function") {
|
|
3298
|
+
ctx.registerTopicItem("editor-image-action", {
|
|
3299
|
+
id: "aiti-msg-share-image",
|
|
3300
|
+
label: shareT("share.action"),
|
|
3301
|
+
icon: SHARE_ICON,
|
|
3302
|
+
onClick: (img) => openShare({ kind: "image", imageSrc: img.src, filename: img.alt || "image" })
|
|
3303
|
+
});
|
|
3304
|
+
ctx.registerTopicItem("editor-file-action", {
|
|
3305
|
+
id: "aiti-msg-share-file",
|
|
3306
|
+
label: shareT("share.action"),
|
|
3307
|
+
icon: SHARE_ICON,
|
|
3308
|
+
onClick: (file) => file.selectionText ? openShare({ kind: "selection", text: file.selectionText, title: file.filePath?.split("/").pop() }) : openShare({ kind: "file", filePath: file.filePath, filename: file.filePath?.split("/").pop() })
|
|
3309
|
+
});
|
|
3310
|
+
ctx.registerTopicItem("session-row-menu-action", {
|
|
3311
|
+
id: "aiti-msg-share-session",
|
|
3312
|
+
label: shareT("share.session"),
|
|
3313
|
+
title: shareT("share.sessionTip"),
|
|
3314
|
+
icon: SHARE_ICON,
|
|
3315
|
+
match: () => true,
|
|
3316
|
+
onClick: (sess) => openShare({
|
|
3317
|
+
kind: "session",
|
|
3318
|
+
sessionId: sess?.id,
|
|
3319
|
+
session: sess,
|
|
3320
|
+
title: sess?.name || sess?.title || ""
|
|
3321
|
+
})
|
|
3322
|
+
});
|
|
3323
|
+
ctx.registerTopicItem("msg-file-action", {
|
|
3324
|
+
id: "aiti-msg-share-file",
|
|
3325
|
+
label: shareT("share.action"),
|
|
3326
|
+
title: shareT("share.fileTip"),
|
|
3327
|
+
icon: SHARE_ICON,
|
|
3328
|
+
type: "share",
|
|
3329
|
+
order: 20,
|
|
3330
|
+
match: (abs, isDir) => !isDir,
|
|
3331
|
+
onClick: (abs) => openShare({ kind: "file", filePath: abs, filename: abs.split("/").pop() })
|
|
3332
|
+
});
|
|
3333
|
+
ctx.registerTopicItem("msg-popover-top-action", {
|
|
3334
|
+
id: "aiti-msg-share-popover",
|
|
3335
|
+
label: shareT("share.action"),
|
|
3336
|
+
title: shareT("share.content"),
|
|
3337
|
+
icon: SHARE_ICON,
|
|
3338
|
+
onClick: (text) => {
|
|
3339
|
+
if (text && text.trim()) openShare({ kind: "selection", text });
|
|
3340
|
+
}
|
|
3341
|
+
});
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
export {
|
|
3345
|
+
register as default
|
|
3346
|
+
};
|