alink-cli 0.1.0 → 0.1.2
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/bin/agentlink.js +36 -2
- package/dist/qr.js +1104 -0
- package/package.json +4 -3
package/bin/agentlink.js
CHANGED
|
@@ -67,6 +67,29 @@ function persistCredential(token) {
|
|
|
67
67
|
chmodSync(CREDENTIAL_FILE, 0o600);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// `qr` 子命令:在终端打印本机凭证的二维码(含 E2EE 密钥段)+ 指纹——给新手机
|
|
71
|
+
// 的「录入密钥」扫。凭证从 --token / AGENTLINK_TOKEN / 落盘文件取,不联网。
|
|
72
|
+
if (rawArgs[0] === "qr") {
|
|
73
|
+
const token = flagValue("token") || process.env.AGENTLINK_TOKEN || readCredentialFile();
|
|
74
|
+
if (!token) {
|
|
75
|
+
console.error("这台电脑上还没有凭证。先在手机 AgentLink 的「添加机器」里生成命令并运行一次。");
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const parts = token.split(".");
|
|
79
|
+
if (parts.length < 4) {
|
|
80
|
+
console.log("此凭证不含加密密钥(明文接入),其他设备无需录入密钥,直接使用即可。");
|
|
81
|
+
process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
const { renderQr } = await import(join(dirname(fileURLToPath(import.meta.url)), "../dist/qr.js"));
|
|
84
|
+
const { createHash } = await import("node:crypto");
|
|
85
|
+
const enckey = parts[3];
|
|
86
|
+
const fp = createHash("sha256").update(Buffer.from(enckey, "base64url")).digest("hex").slice(0, 8);
|
|
87
|
+
console.log("用手机 AgentLink 的「录入密钥」扫下面的二维码:\n");
|
|
88
|
+
renderQr(token);
|
|
89
|
+
console.log(`密钥指纹 ${fp} —— 与手机上显示的一致即可放心保存。`);
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
|
|
70
93
|
// --tunnel 模式下 daemon 会自起本地 hub,且与 --hub 互斥,所以此时绝不注入 --hub。
|
|
71
94
|
const tunnelMode = hasFlag("tunnel");
|
|
72
95
|
|
|
@@ -87,9 +110,19 @@ if (explicitToken) {
|
|
|
87
110
|
// 环境变量已给——daemon 自己会读 AGENTLINK_TOKEN,这里什么都不用做。
|
|
88
111
|
} else {
|
|
89
112
|
// 命令行和环境变量都没有——回落到落盘凭证(若有),塞进 AGENTLINK_TOKEN 供
|
|
90
|
-
// daemon
|
|
113
|
+
// daemon 读取。
|
|
91
114
|
const saved = readCredentialFile();
|
|
92
|
-
if (saved)
|
|
115
|
+
if (saved) {
|
|
116
|
+
process.env.AGENTLINK_TOKEN = saved;
|
|
117
|
+
} else if (!hasFlag("hub") || flagValue("hub") === OFFICIAL_HUB) {
|
|
118
|
+
// 什么凭证都没有且连的是官方 hub:直接给指引并退出——否则 daemon 会生成
|
|
119
|
+
// 随机 token 去连 multi hub 然后被 4401 拒,报错对新用户完全不可解。
|
|
120
|
+
// (自建 --hub 的 single 模式仍保留旧行为:daemon 自己生成 token 并打印。)
|
|
121
|
+
console.error("还没有这台电脑的凭证。");
|
|
122
|
+
console.error("请在手机 AgentLink App(或电脑控制台)的「添加机器」里生成命令,");
|
|
123
|
+
console.error("复制到这里运行:npx alink-cli --token al1.…");
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
93
126
|
}
|
|
94
127
|
|
|
95
128
|
// 3) 把补好默认值的 argv 交还给 daemon(daemon 读 process.argv.slice(2))。
|
|
@@ -125,6 +158,7 @@ function printHelp() {
|
|
|
125
158
|
process.stdout.write(
|
|
126
159
|
[
|
|
127
160
|
`用法: npx ${self} [--token <al1.…>] [--hub <wss://…>] [--dir <目录>]…`,
|
|
161
|
+
` npx ${self} qr # 终端打印本机凭证二维码(给新手机录密钥)`,
|
|
128
162
|
``,
|
|
129
163
|
`把当前这台工作机接入 AgentLink,随时随地遥控本机的编码 agent。`,
|
|
130
164
|
``,
|
package/dist/qr.js
ADDED
|
@@ -0,0 +1,1104 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRMode.js
|
|
28
|
+
var require_QRMode = __commonJS({
|
|
29
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRMode.js"(exports, module) {
|
|
30
|
+
module.exports = {
|
|
31
|
+
MODE_NUMBER: 1 << 0,
|
|
32
|
+
MODE_ALPHA_NUM: 1 << 1,
|
|
33
|
+
MODE_8BIT_BYTE: 1 << 2,
|
|
34
|
+
MODE_KANJI: 1 << 3
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QR8bitByte.js
|
|
40
|
+
var require_QR8bitByte = __commonJS({
|
|
41
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QR8bitByte.js"(exports, module) {
|
|
42
|
+
var QRMode = require_QRMode();
|
|
43
|
+
function QR8bitByte(data) {
|
|
44
|
+
this.mode = QRMode.MODE_8BIT_BYTE;
|
|
45
|
+
this.data = data;
|
|
46
|
+
}
|
|
47
|
+
QR8bitByte.prototype = {
|
|
48
|
+
getLength: function() {
|
|
49
|
+
return this.data.length;
|
|
50
|
+
},
|
|
51
|
+
write: function(buffer) {
|
|
52
|
+
for (var i = 0; i < this.data.length; i++) {
|
|
53
|
+
buffer.put(this.data.charCodeAt(i), 8);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
module.exports = QR8bitByte;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRMath.js
|
|
62
|
+
var require_QRMath = __commonJS({
|
|
63
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRMath.js"(exports, module) {
|
|
64
|
+
var QRMath = {
|
|
65
|
+
glog: function(n) {
|
|
66
|
+
if (n < 1) {
|
|
67
|
+
throw new Error("glog(" + n + ")");
|
|
68
|
+
}
|
|
69
|
+
return QRMath.LOG_TABLE[n];
|
|
70
|
+
},
|
|
71
|
+
gexp: function(n) {
|
|
72
|
+
while (n < 0) {
|
|
73
|
+
n += 255;
|
|
74
|
+
}
|
|
75
|
+
while (n >= 256) {
|
|
76
|
+
n -= 255;
|
|
77
|
+
}
|
|
78
|
+
return QRMath.EXP_TABLE[n];
|
|
79
|
+
},
|
|
80
|
+
EXP_TABLE: new Array(256),
|
|
81
|
+
LOG_TABLE: new Array(256)
|
|
82
|
+
};
|
|
83
|
+
for (i = 0; i < 8; i++) {
|
|
84
|
+
QRMath.EXP_TABLE[i] = 1 << i;
|
|
85
|
+
}
|
|
86
|
+
var i;
|
|
87
|
+
for (i = 8; i < 256; i++) {
|
|
88
|
+
QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
|
|
89
|
+
}
|
|
90
|
+
var i;
|
|
91
|
+
for (i = 0; i < 255; i++) {
|
|
92
|
+
QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
|
|
93
|
+
}
|
|
94
|
+
var i;
|
|
95
|
+
module.exports = QRMath;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRPolynomial.js
|
|
100
|
+
var require_QRPolynomial = __commonJS({
|
|
101
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRPolynomial.js"(exports, module) {
|
|
102
|
+
var QRMath = require_QRMath();
|
|
103
|
+
function QRPolynomial(num, shift) {
|
|
104
|
+
if (num.length === void 0) {
|
|
105
|
+
throw new Error(num.length + "/" + shift);
|
|
106
|
+
}
|
|
107
|
+
var offset = 0;
|
|
108
|
+
while (offset < num.length && num[offset] === 0) {
|
|
109
|
+
offset++;
|
|
110
|
+
}
|
|
111
|
+
this.num = new Array(num.length - offset + shift);
|
|
112
|
+
for (var i = 0; i < num.length - offset; i++) {
|
|
113
|
+
this.num[i] = num[i + offset];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
QRPolynomial.prototype = {
|
|
117
|
+
get: function(index) {
|
|
118
|
+
return this.num[index];
|
|
119
|
+
},
|
|
120
|
+
getLength: function() {
|
|
121
|
+
return this.num.length;
|
|
122
|
+
},
|
|
123
|
+
multiply: function(e) {
|
|
124
|
+
var num = new Array(this.getLength() + e.getLength() - 1);
|
|
125
|
+
for (var i = 0; i < this.getLength(); i++) {
|
|
126
|
+
for (var j = 0; j < e.getLength(); j++) {
|
|
127
|
+
num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return new QRPolynomial(num, 0);
|
|
131
|
+
},
|
|
132
|
+
mod: function(e) {
|
|
133
|
+
if (this.getLength() - e.getLength() < 0) {
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0));
|
|
137
|
+
var num = new Array(this.getLength());
|
|
138
|
+
for (var i = 0; i < this.getLength(); i++) {
|
|
139
|
+
num[i] = this.get(i);
|
|
140
|
+
}
|
|
141
|
+
for (var x = 0; x < e.getLength(); x++) {
|
|
142
|
+
num[x] ^= QRMath.gexp(QRMath.glog(e.get(x)) + ratio);
|
|
143
|
+
}
|
|
144
|
+
return new QRPolynomial(num, 0).mod(e);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
module.exports = QRPolynomial;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRMaskPattern.js
|
|
152
|
+
var require_QRMaskPattern = __commonJS({
|
|
153
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRMaskPattern.js"(exports, module) {
|
|
154
|
+
module.exports = {
|
|
155
|
+
PATTERN000: 0,
|
|
156
|
+
PATTERN001: 1,
|
|
157
|
+
PATTERN010: 2,
|
|
158
|
+
PATTERN011: 3,
|
|
159
|
+
PATTERN100: 4,
|
|
160
|
+
PATTERN101: 5,
|
|
161
|
+
PATTERN110: 6,
|
|
162
|
+
PATTERN111: 7
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRUtil.js
|
|
168
|
+
var require_QRUtil = __commonJS({
|
|
169
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRUtil.js"(exports, module) {
|
|
170
|
+
var QRMode = require_QRMode();
|
|
171
|
+
var QRPolynomial = require_QRPolynomial();
|
|
172
|
+
var QRMath = require_QRMath();
|
|
173
|
+
var QRMaskPattern = require_QRMaskPattern();
|
|
174
|
+
var QRUtil = {
|
|
175
|
+
PATTERN_POSITION_TABLE: [
|
|
176
|
+
[],
|
|
177
|
+
[6, 18],
|
|
178
|
+
[6, 22],
|
|
179
|
+
[6, 26],
|
|
180
|
+
[6, 30],
|
|
181
|
+
[6, 34],
|
|
182
|
+
[6, 22, 38],
|
|
183
|
+
[6, 24, 42],
|
|
184
|
+
[6, 26, 46],
|
|
185
|
+
[6, 28, 50],
|
|
186
|
+
[6, 30, 54],
|
|
187
|
+
[6, 32, 58],
|
|
188
|
+
[6, 34, 62],
|
|
189
|
+
[6, 26, 46, 66],
|
|
190
|
+
[6, 26, 48, 70],
|
|
191
|
+
[6, 26, 50, 74],
|
|
192
|
+
[6, 30, 54, 78],
|
|
193
|
+
[6, 30, 56, 82],
|
|
194
|
+
[6, 30, 58, 86],
|
|
195
|
+
[6, 34, 62, 90],
|
|
196
|
+
[6, 28, 50, 72, 94],
|
|
197
|
+
[6, 26, 50, 74, 98],
|
|
198
|
+
[6, 30, 54, 78, 102],
|
|
199
|
+
[6, 28, 54, 80, 106],
|
|
200
|
+
[6, 32, 58, 84, 110],
|
|
201
|
+
[6, 30, 58, 86, 114],
|
|
202
|
+
[6, 34, 62, 90, 118],
|
|
203
|
+
[6, 26, 50, 74, 98, 122],
|
|
204
|
+
[6, 30, 54, 78, 102, 126],
|
|
205
|
+
[6, 26, 52, 78, 104, 130],
|
|
206
|
+
[6, 30, 56, 82, 108, 134],
|
|
207
|
+
[6, 34, 60, 86, 112, 138],
|
|
208
|
+
[6, 30, 58, 86, 114, 142],
|
|
209
|
+
[6, 34, 62, 90, 118, 146],
|
|
210
|
+
[6, 30, 54, 78, 102, 126, 150],
|
|
211
|
+
[6, 24, 50, 76, 102, 128, 154],
|
|
212
|
+
[6, 28, 54, 80, 106, 132, 158],
|
|
213
|
+
[6, 32, 58, 84, 110, 136, 162],
|
|
214
|
+
[6, 26, 54, 82, 110, 138, 166],
|
|
215
|
+
[6, 30, 58, 86, 114, 142, 170]
|
|
216
|
+
],
|
|
217
|
+
G15: 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0,
|
|
218
|
+
G18: 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0,
|
|
219
|
+
G15_MASK: 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1,
|
|
220
|
+
getBCHTypeInfo: function(data) {
|
|
221
|
+
var d = data << 10;
|
|
222
|
+
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
|
|
223
|
+
d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15);
|
|
224
|
+
}
|
|
225
|
+
return (data << 10 | d) ^ QRUtil.G15_MASK;
|
|
226
|
+
},
|
|
227
|
+
getBCHTypeNumber: function(data) {
|
|
228
|
+
var d = data << 12;
|
|
229
|
+
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
|
|
230
|
+
d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18);
|
|
231
|
+
}
|
|
232
|
+
return data << 12 | d;
|
|
233
|
+
},
|
|
234
|
+
getBCHDigit: function(data) {
|
|
235
|
+
var digit = 0;
|
|
236
|
+
while (data !== 0) {
|
|
237
|
+
digit++;
|
|
238
|
+
data >>>= 1;
|
|
239
|
+
}
|
|
240
|
+
return digit;
|
|
241
|
+
},
|
|
242
|
+
getPatternPosition: function(typeNumber) {
|
|
243
|
+
return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
|
|
244
|
+
},
|
|
245
|
+
getMask: function(maskPattern, i, j) {
|
|
246
|
+
switch (maskPattern) {
|
|
247
|
+
case QRMaskPattern.PATTERN000:
|
|
248
|
+
return (i + j) % 2 === 0;
|
|
249
|
+
case QRMaskPattern.PATTERN001:
|
|
250
|
+
return i % 2 === 0;
|
|
251
|
+
case QRMaskPattern.PATTERN010:
|
|
252
|
+
return j % 3 === 0;
|
|
253
|
+
case QRMaskPattern.PATTERN011:
|
|
254
|
+
return (i + j) % 3 === 0;
|
|
255
|
+
case QRMaskPattern.PATTERN100:
|
|
256
|
+
return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
257
|
+
case QRMaskPattern.PATTERN101:
|
|
258
|
+
return i * j % 2 + i * j % 3 === 0;
|
|
259
|
+
case QRMaskPattern.PATTERN110:
|
|
260
|
+
return (i * j % 2 + i * j % 3) % 2 === 0;
|
|
261
|
+
case QRMaskPattern.PATTERN111:
|
|
262
|
+
return (i * j % 3 + (i + j) % 2) % 2 === 0;
|
|
263
|
+
default:
|
|
264
|
+
throw new Error("bad maskPattern:" + maskPattern);
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
getErrorCorrectPolynomial: function(errorCorrectLength) {
|
|
268
|
+
var a = new QRPolynomial([1], 0);
|
|
269
|
+
for (var i = 0; i < errorCorrectLength; i++) {
|
|
270
|
+
a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
|
|
271
|
+
}
|
|
272
|
+
return a;
|
|
273
|
+
},
|
|
274
|
+
getLengthInBits: function(mode, type) {
|
|
275
|
+
if (1 <= type && type < 10) {
|
|
276
|
+
switch (mode) {
|
|
277
|
+
case QRMode.MODE_NUMBER:
|
|
278
|
+
return 10;
|
|
279
|
+
case QRMode.MODE_ALPHA_NUM:
|
|
280
|
+
return 9;
|
|
281
|
+
case QRMode.MODE_8BIT_BYTE:
|
|
282
|
+
return 8;
|
|
283
|
+
case QRMode.MODE_KANJI:
|
|
284
|
+
return 8;
|
|
285
|
+
default:
|
|
286
|
+
throw new Error("mode:" + mode);
|
|
287
|
+
}
|
|
288
|
+
} else if (type < 27) {
|
|
289
|
+
switch (mode) {
|
|
290
|
+
case QRMode.MODE_NUMBER:
|
|
291
|
+
return 12;
|
|
292
|
+
case QRMode.MODE_ALPHA_NUM:
|
|
293
|
+
return 11;
|
|
294
|
+
case QRMode.MODE_8BIT_BYTE:
|
|
295
|
+
return 16;
|
|
296
|
+
case QRMode.MODE_KANJI:
|
|
297
|
+
return 10;
|
|
298
|
+
default:
|
|
299
|
+
throw new Error("mode:" + mode);
|
|
300
|
+
}
|
|
301
|
+
} else if (type < 41) {
|
|
302
|
+
switch (mode) {
|
|
303
|
+
case QRMode.MODE_NUMBER:
|
|
304
|
+
return 14;
|
|
305
|
+
case QRMode.MODE_ALPHA_NUM:
|
|
306
|
+
return 13;
|
|
307
|
+
case QRMode.MODE_8BIT_BYTE:
|
|
308
|
+
return 16;
|
|
309
|
+
case QRMode.MODE_KANJI:
|
|
310
|
+
return 12;
|
|
311
|
+
default:
|
|
312
|
+
throw new Error("mode:" + mode);
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
throw new Error("type:" + type);
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
getLostPoint: function(qrCode) {
|
|
319
|
+
var moduleCount = qrCode.getModuleCount();
|
|
320
|
+
var lostPoint = 0;
|
|
321
|
+
var row = 0;
|
|
322
|
+
var col = 0;
|
|
323
|
+
for (row = 0; row < moduleCount; row++) {
|
|
324
|
+
for (col = 0; col < moduleCount; col++) {
|
|
325
|
+
var sameCount = 0;
|
|
326
|
+
var dark = qrCode.isDark(row, col);
|
|
327
|
+
for (var r = -1; r <= 1; r++) {
|
|
328
|
+
if (row + r < 0 || moduleCount <= row + r) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
for (var c = -1; c <= 1; c++) {
|
|
332
|
+
if (col + c < 0 || moduleCount <= col + c) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (r === 0 && c === 0) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (dark === qrCode.isDark(row + r, col + c)) {
|
|
339
|
+
sameCount++;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (sameCount > 5) {
|
|
344
|
+
lostPoint += 3 + sameCount - 5;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
for (row = 0; row < moduleCount - 1; row++) {
|
|
349
|
+
for (col = 0; col < moduleCount - 1; col++) {
|
|
350
|
+
var count = 0;
|
|
351
|
+
if (qrCode.isDark(row, col)) count++;
|
|
352
|
+
if (qrCode.isDark(row + 1, col)) count++;
|
|
353
|
+
if (qrCode.isDark(row, col + 1)) count++;
|
|
354
|
+
if (qrCode.isDark(row + 1, col + 1)) count++;
|
|
355
|
+
if (count === 0 || count === 4) {
|
|
356
|
+
lostPoint += 3;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
for (row = 0; row < moduleCount; row++) {
|
|
361
|
+
for (col = 0; col < moduleCount - 6; col++) {
|
|
362
|
+
if (qrCode.isDark(row, col) && !qrCode.isDark(row, col + 1) && qrCode.isDark(row, col + 2) && qrCode.isDark(row, col + 3) && qrCode.isDark(row, col + 4) && !qrCode.isDark(row, col + 5) && qrCode.isDark(row, col + 6)) {
|
|
363
|
+
lostPoint += 40;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
for (col = 0; col < moduleCount; col++) {
|
|
368
|
+
for (row = 0; row < moduleCount - 6; row++) {
|
|
369
|
+
if (qrCode.isDark(row, col) && !qrCode.isDark(row + 1, col) && qrCode.isDark(row + 2, col) && qrCode.isDark(row + 3, col) && qrCode.isDark(row + 4, col) && !qrCode.isDark(row + 5, col) && qrCode.isDark(row + 6, col)) {
|
|
370
|
+
lostPoint += 40;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
var darkCount = 0;
|
|
375
|
+
for (col = 0; col < moduleCount; col++) {
|
|
376
|
+
for (row = 0; row < moduleCount; row++) {
|
|
377
|
+
if (qrCode.isDark(row, col)) {
|
|
378
|
+
darkCount++;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
|
|
383
|
+
lostPoint += ratio * 10;
|
|
384
|
+
return lostPoint;
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
module.exports = QRUtil;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js
|
|
392
|
+
var require_QRErrorCorrectLevel = __commonJS({
|
|
393
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js"(exports, module) {
|
|
394
|
+
module.exports = {
|
|
395
|
+
L: 1,
|
|
396
|
+
M: 0,
|
|
397
|
+
Q: 3,
|
|
398
|
+
H: 2
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRRSBlock.js
|
|
404
|
+
var require_QRRSBlock = __commonJS({
|
|
405
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRRSBlock.js"(exports, module) {
|
|
406
|
+
var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
|
|
407
|
+
function QRRSBlock(totalCount, dataCount) {
|
|
408
|
+
this.totalCount = totalCount;
|
|
409
|
+
this.dataCount = dataCount;
|
|
410
|
+
}
|
|
411
|
+
QRRSBlock.RS_BLOCK_TABLE = [
|
|
412
|
+
// L
|
|
413
|
+
// M
|
|
414
|
+
// Q
|
|
415
|
+
// H
|
|
416
|
+
// 1
|
|
417
|
+
[1, 26, 19],
|
|
418
|
+
[1, 26, 16],
|
|
419
|
+
[1, 26, 13],
|
|
420
|
+
[1, 26, 9],
|
|
421
|
+
// 2
|
|
422
|
+
[1, 44, 34],
|
|
423
|
+
[1, 44, 28],
|
|
424
|
+
[1, 44, 22],
|
|
425
|
+
[1, 44, 16],
|
|
426
|
+
// 3
|
|
427
|
+
[1, 70, 55],
|
|
428
|
+
[1, 70, 44],
|
|
429
|
+
[2, 35, 17],
|
|
430
|
+
[2, 35, 13],
|
|
431
|
+
// 4
|
|
432
|
+
[1, 100, 80],
|
|
433
|
+
[2, 50, 32],
|
|
434
|
+
[2, 50, 24],
|
|
435
|
+
[4, 25, 9],
|
|
436
|
+
// 5
|
|
437
|
+
[1, 134, 108],
|
|
438
|
+
[2, 67, 43],
|
|
439
|
+
[2, 33, 15, 2, 34, 16],
|
|
440
|
+
[2, 33, 11, 2, 34, 12],
|
|
441
|
+
// 6
|
|
442
|
+
[2, 86, 68],
|
|
443
|
+
[4, 43, 27],
|
|
444
|
+
[4, 43, 19],
|
|
445
|
+
[4, 43, 15],
|
|
446
|
+
// 7
|
|
447
|
+
[2, 98, 78],
|
|
448
|
+
[4, 49, 31],
|
|
449
|
+
[2, 32, 14, 4, 33, 15],
|
|
450
|
+
[4, 39, 13, 1, 40, 14],
|
|
451
|
+
// 8
|
|
452
|
+
[2, 121, 97],
|
|
453
|
+
[2, 60, 38, 2, 61, 39],
|
|
454
|
+
[4, 40, 18, 2, 41, 19],
|
|
455
|
+
[4, 40, 14, 2, 41, 15],
|
|
456
|
+
// 9
|
|
457
|
+
[2, 146, 116],
|
|
458
|
+
[3, 58, 36, 2, 59, 37],
|
|
459
|
+
[4, 36, 16, 4, 37, 17],
|
|
460
|
+
[4, 36, 12, 4, 37, 13],
|
|
461
|
+
// 10
|
|
462
|
+
[2, 86, 68, 2, 87, 69],
|
|
463
|
+
[4, 69, 43, 1, 70, 44],
|
|
464
|
+
[6, 43, 19, 2, 44, 20],
|
|
465
|
+
[6, 43, 15, 2, 44, 16],
|
|
466
|
+
// 11
|
|
467
|
+
[4, 101, 81],
|
|
468
|
+
[1, 80, 50, 4, 81, 51],
|
|
469
|
+
[4, 50, 22, 4, 51, 23],
|
|
470
|
+
[3, 36, 12, 8, 37, 13],
|
|
471
|
+
// 12
|
|
472
|
+
[2, 116, 92, 2, 117, 93],
|
|
473
|
+
[6, 58, 36, 2, 59, 37],
|
|
474
|
+
[4, 46, 20, 6, 47, 21],
|
|
475
|
+
[7, 42, 14, 4, 43, 15],
|
|
476
|
+
// 13
|
|
477
|
+
[4, 133, 107],
|
|
478
|
+
[8, 59, 37, 1, 60, 38],
|
|
479
|
+
[8, 44, 20, 4, 45, 21],
|
|
480
|
+
[12, 33, 11, 4, 34, 12],
|
|
481
|
+
// 14
|
|
482
|
+
[3, 145, 115, 1, 146, 116],
|
|
483
|
+
[4, 64, 40, 5, 65, 41],
|
|
484
|
+
[11, 36, 16, 5, 37, 17],
|
|
485
|
+
[11, 36, 12, 5, 37, 13],
|
|
486
|
+
// 15
|
|
487
|
+
[5, 109, 87, 1, 110, 88],
|
|
488
|
+
[5, 65, 41, 5, 66, 42],
|
|
489
|
+
[5, 54, 24, 7, 55, 25],
|
|
490
|
+
[11, 36, 12],
|
|
491
|
+
// 16
|
|
492
|
+
[5, 122, 98, 1, 123, 99],
|
|
493
|
+
[7, 73, 45, 3, 74, 46],
|
|
494
|
+
[15, 43, 19, 2, 44, 20],
|
|
495
|
+
[3, 45, 15, 13, 46, 16],
|
|
496
|
+
// 17
|
|
497
|
+
[1, 135, 107, 5, 136, 108],
|
|
498
|
+
[10, 74, 46, 1, 75, 47],
|
|
499
|
+
[1, 50, 22, 15, 51, 23],
|
|
500
|
+
[2, 42, 14, 17, 43, 15],
|
|
501
|
+
// 18
|
|
502
|
+
[5, 150, 120, 1, 151, 121],
|
|
503
|
+
[9, 69, 43, 4, 70, 44],
|
|
504
|
+
[17, 50, 22, 1, 51, 23],
|
|
505
|
+
[2, 42, 14, 19, 43, 15],
|
|
506
|
+
// 19
|
|
507
|
+
[3, 141, 113, 4, 142, 114],
|
|
508
|
+
[3, 70, 44, 11, 71, 45],
|
|
509
|
+
[17, 47, 21, 4, 48, 22],
|
|
510
|
+
[9, 39, 13, 16, 40, 14],
|
|
511
|
+
// 20
|
|
512
|
+
[3, 135, 107, 5, 136, 108],
|
|
513
|
+
[3, 67, 41, 13, 68, 42],
|
|
514
|
+
[15, 54, 24, 5, 55, 25],
|
|
515
|
+
[15, 43, 15, 10, 44, 16],
|
|
516
|
+
// 21
|
|
517
|
+
[4, 144, 116, 4, 145, 117],
|
|
518
|
+
[17, 68, 42],
|
|
519
|
+
[17, 50, 22, 6, 51, 23],
|
|
520
|
+
[19, 46, 16, 6, 47, 17],
|
|
521
|
+
// 22
|
|
522
|
+
[2, 139, 111, 7, 140, 112],
|
|
523
|
+
[17, 74, 46],
|
|
524
|
+
[7, 54, 24, 16, 55, 25],
|
|
525
|
+
[34, 37, 13],
|
|
526
|
+
// 23
|
|
527
|
+
[4, 151, 121, 5, 152, 122],
|
|
528
|
+
[4, 75, 47, 14, 76, 48],
|
|
529
|
+
[11, 54, 24, 14, 55, 25],
|
|
530
|
+
[16, 45, 15, 14, 46, 16],
|
|
531
|
+
// 24
|
|
532
|
+
[6, 147, 117, 4, 148, 118],
|
|
533
|
+
[6, 73, 45, 14, 74, 46],
|
|
534
|
+
[11, 54, 24, 16, 55, 25],
|
|
535
|
+
[30, 46, 16, 2, 47, 17],
|
|
536
|
+
// 25
|
|
537
|
+
[8, 132, 106, 4, 133, 107],
|
|
538
|
+
[8, 75, 47, 13, 76, 48],
|
|
539
|
+
[7, 54, 24, 22, 55, 25],
|
|
540
|
+
[22, 45, 15, 13, 46, 16],
|
|
541
|
+
// 26
|
|
542
|
+
[10, 142, 114, 2, 143, 115],
|
|
543
|
+
[19, 74, 46, 4, 75, 47],
|
|
544
|
+
[28, 50, 22, 6, 51, 23],
|
|
545
|
+
[33, 46, 16, 4, 47, 17],
|
|
546
|
+
// 27
|
|
547
|
+
[8, 152, 122, 4, 153, 123],
|
|
548
|
+
[22, 73, 45, 3, 74, 46],
|
|
549
|
+
[8, 53, 23, 26, 54, 24],
|
|
550
|
+
[12, 45, 15, 28, 46, 16],
|
|
551
|
+
// 28
|
|
552
|
+
[3, 147, 117, 10, 148, 118],
|
|
553
|
+
[3, 73, 45, 23, 74, 46],
|
|
554
|
+
[4, 54, 24, 31, 55, 25],
|
|
555
|
+
[11, 45, 15, 31, 46, 16],
|
|
556
|
+
// 29
|
|
557
|
+
[7, 146, 116, 7, 147, 117],
|
|
558
|
+
[21, 73, 45, 7, 74, 46],
|
|
559
|
+
[1, 53, 23, 37, 54, 24],
|
|
560
|
+
[19, 45, 15, 26, 46, 16],
|
|
561
|
+
// 30
|
|
562
|
+
[5, 145, 115, 10, 146, 116],
|
|
563
|
+
[19, 75, 47, 10, 76, 48],
|
|
564
|
+
[15, 54, 24, 25, 55, 25],
|
|
565
|
+
[23, 45, 15, 25, 46, 16],
|
|
566
|
+
// 31
|
|
567
|
+
[13, 145, 115, 3, 146, 116],
|
|
568
|
+
[2, 74, 46, 29, 75, 47],
|
|
569
|
+
[42, 54, 24, 1, 55, 25],
|
|
570
|
+
[23, 45, 15, 28, 46, 16],
|
|
571
|
+
// 32
|
|
572
|
+
[17, 145, 115],
|
|
573
|
+
[10, 74, 46, 23, 75, 47],
|
|
574
|
+
[10, 54, 24, 35, 55, 25],
|
|
575
|
+
[19, 45, 15, 35, 46, 16],
|
|
576
|
+
// 33
|
|
577
|
+
[17, 145, 115, 1, 146, 116],
|
|
578
|
+
[14, 74, 46, 21, 75, 47],
|
|
579
|
+
[29, 54, 24, 19, 55, 25],
|
|
580
|
+
[11, 45, 15, 46, 46, 16],
|
|
581
|
+
// 34
|
|
582
|
+
[13, 145, 115, 6, 146, 116],
|
|
583
|
+
[14, 74, 46, 23, 75, 47],
|
|
584
|
+
[44, 54, 24, 7, 55, 25],
|
|
585
|
+
[59, 46, 16, 1, 47, 17],
|
|
586
|
+
// 35
|
|
587
|
+
[12, 151, 121, 7, 152, 122],
|
|
588
|
+
[12, 75, 47, 26, 76, 48],
|
|
589
|
+
[39, 54, 24, 14, 55, 25],
|
|
590
|
+
[22, 45, 15, 41, 46, 16],
|
|
591
|
+
// 36
|
|
592
|
+
[6, 151, 121, 14, 152, 122],
|
|
593
|
+
[6, 75, 47, 34, 76, 48],
|
|
594
|
+
[46, 54, 24, 10, 55, 25],
|
|
595
|
+
[2, 45, 15, 64, 46, 16],
|
|
596
|
+
// 37
|
|
597
|
+
[17, 152, 122, 4, 153, 123],
|
|
598
|
+
[29, 74, 46, 14, 75, 47],
|
|
599
|
+
[49, 54, 24, 10, 55, 25],
|
|
600
|
+
[24, 45, 15, 46, 46, 16],
|
|
601
|
+
// 38
|
|
602
|
+
[4, 152, 122, 18, 153, 123],
|
|
603
|
+
[13, 74, 46, 32, 75, 47],
|
|
604
|
+
[48, 54, 24, 14, 55, 25],
|
|
605
|
+
[42, 45, 15, 32, 46, 16],
|
|
606
|
+
// 39
|
|
607
|
+
[20, 147, 117, 4, 148, 118],
|
|
608
|
+
[40, 75, 47, 7, 76, 48],
|
|
609
|
+
[43, 54, 24, 22, 55, 25],
|
|
610
|
+
[10, 45, 15, 67, 46, 16],
|
|
611
|
+
// 40
|
|
612
|
+
[19, 148, 118, 6, 149, 119],
|
|
613
|
+
[18, 75, 47, 31, 76, 48],
|
|
614
|
+
[34, 54, 24, 34, 55, 25],
|
|
615
|
+
[20, 45, 15, 61, 46, 16]
|
|
616
|
+
];
|
|
617
|
+
QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
|
|
618
|
+
var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
|
|
619
|
+
if (rsBlock === void 0) {
|
|
620
|
+
throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
|
|
621
|
+
}
|
|
622
|
+
var length = rsBlock.length / 3;
|
|
623
|
+
var list = [];
|
|
624
|
+
for (var i = 0; i < length; i++) {
|
|
625
|
+
var count = rsBlock[i * 3 + 0];
|
|
626
|
+
var totalCount = rsBlock[i * 3 + 1];
|
|
627
|
+
var dataCount = rsBlock[i * 3 + 2];
|
|
628
|
+
for (var j = 0; j < count; j++) {
|
|
629
|
+
list.push(new QRRSBlock(totalCount, dataCount));
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return list;
|
|
633
|
+
};
|
|
634
|
+
QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
|
|
635
|
+
switch (errorCorrectLevel) {
|
|
636
|
+
case QRErrorCorrectLevel.L:
|
|
637
|
+
return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
|
|
638
|
+
case QRErrorCorrectLevel.M:
|
|
639
|
+
return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
|
|
640
|
+
case QRErrorCorrectLevel.Q:
|
|
641
|
+
return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
|
|
642
|
+
case QRErrorCorrectLevel.H:
|
|
643
|
+
return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
|
|
644
|
+
default:
|
|
645
|
+
return void 0;
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
module.exports = QRRSBlock;
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
// node_modules/qrcode-terminal/vendor/QRCode/QRBitBuffer.js
|
|
653
|
+
var require_QRBitBuffer = __commonJS({
|
|
654
|
+
"node_modules/qrcode-terminal/vendor/QRCode/QRBitBuffer.js"(exports, module) {
|
|
655
|
+
function QRBitBuffer() {
|
|
656
|
+
this.buffer = [];
|
|
657
|
+
this.length = 0;
|
|
658
|
+
}
|
|
659
|
+
QRBitBuffer.prototype = {
|
|
660
|
+
get: function(index) {
|
|
661
|
+
var bufIndex = Math.floor(index / 8);
|
|
662
|
+
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
|
|
663
|
+
},
|
|
664
|
+
put: function(num, length) {
|
|
665
|
+
for (var i = 0; i < length; i++) {
|
|
666
|
+
this.putBit((num >>> length - i - 1 & 1) == 1);
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
getLengthInBits: function() {
|
|
670
|
+
return this.length;
|
|
671
|
+
},
|
|
672
|
+
putBit: function(bit) {
|
|
673
|
+
var bufIndex = Math.floor(this.length / 8);
|
|
674
|
+
if (this.buffer.length <= bufIndex) {
|
|
675
|
+
this.buffer.push(0);
|
|
676
|
+
}
|
|
677
|
+
if (bit) {
|
|
678
|
+
this.buffer[bufIndex] |= 128 >>> this.length % 8;
|
|
679
|
+
}
|
|
680
|
+
this.length++;
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
module.exports = QRBitBuffer;
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
// node_modules/qrcode-terminal/vendor/QRCode/index.js
|
|
688
|
+
var require_QRCode = __commonJS({
|
|
689
|
+
"node_modules/qrcode-terminal/vendor/QRCode/index.js"(exports, module) {
|
|
690
|
+
var QR8bitByte = require_QR8bitByte();
|
|
691
|
+
var QRUtil = require_QRUtil();
|
|
692
|
+
var QRPolynomial = require_QRPolynomial();
|
|
693
|
+
var QRRSBlock = require_QRRSBlock();
|
|
694
|
+
var QRBitBuffer = require_QRBitBuffer();
|
|
695
|
+
function QRCode(typeNumber, errorCorrectLevel) {
|
|
696
|
+
this.typeNumber = typeNumber;
|
|
697
|
+
this.errorCorrectLevel = errorCorrectLevel;
|
|
698
|
+
this.modules = null;
|
|
699
|
+
this.moduleCount = 0;
|
|
700
|
+
this.dataCache = null;
|
|
701
|
+
this.dataList = [];
|
|
702
|
+
}
|
|
703
|
+
QRCode.prototype = {
|
|
704
|
+
addData: function(data) {
|
|
705
|
+
var newData = new QR8bitByte(data);
|
|
706
|
+
this.dataList.push(newData);
|
|
707
|
+
this.dataCache = null;
|
|
708
|
+
},
|
|
709
|
+
isDark: function(row, col) {
|
|
710
|
+
if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
|
|
711
|
+
throw new Error(row + "," + col);
|
|
712
|
+
}
|
|
713
|
+
return this.modules[row][col];
|
|
714
|
+
},
|
|
715
|
+
getModuleCount: function() {
|
|
716
|
+
return this.moduleCount;
|
|
717
|
+
},
|
|
718
|
+
make: function() {
|
|
719
|
+
if (this.typeNumber < 1) {
|
|
720
|
+
var typeNumber = 1;
|
|
721
|
+
for (typeNumber = 1; typeNumber < 40; typeNumber++) {
|
|
722
|
+
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
|
|
723
|
+
var buffer = new QRBitBuffer();
|
|
724
|
+
var totalDataCount = 0;
|
|
725
|
+
for (var i = 0; i < rsBlocks.length; i++) {
|
|
726
|
+
totalDataCount += rsBlocks[i].dataCount;
|
|
727
|
+
}
|
|
728
|
+
for (var x = 0; x < this.dataList.length; x++) {
|
|
729
|
+
var data = this.dataList[x];
|
|
730
|
+
buffer.put(data.mode, 4);
|
|
731
|
+
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
|
|
732
|
+
data.write(buffer);
|
|
733
|
+
}
|
|
734
|
+
if (buffer.getLengthInBits() <= totalDataCount * 8)
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
this.typeNumber = typeNumber;
|
|
738
|
+
}
|
|
739
|
+
this.makeImpl(false, this.getBestMaskPattern());
|
|
740
|
+
},
|
|
741
|
+
makeImpl: function(test, maskPattern) {
|
|
742
|
+
this.moduleCount = this.typeNumber * 4 + 17;
|
|
743
|
+
this.modules = new Array(this.moduleCount);
|
|
744
|
+
for (var row = 0; row < this.moduleCount; row++) {
|
|
745
|
+
this.modules[row] = new Array(this.moduleCount);
|
|
746
|
+
for (var col = 0; col < this.moduleCount; col++) {
|
|
747
|
+
this.modules[row][col] = null;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
this.setupPositionProbePattern(0, 0);
|
|
751
|
+
this.setupPositionProbePattern(this.moduleCount - 7, 0);
|
|
752
|
+
this.setupPositionProbePattern(0, this.moduleCount - 7);
|
|
753
|
+
this.setupPositionAdjustPattern();
|
|
754
|
+
this.setupTimingPattern();
|
|
755
|
+
this.setupTypeInfo(test, maskPattern);
|
|
756
|
+
if (this.typeNumber >= 7) {
|
|
757
|
+
this.setupTypeNumber(test);
|
|
758
|
+
}
|
|
759
|
+
if (this.dataCache === null) {
|
|
760
|
+
this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
|
|
761
|
+
}
|
|
762
|
+
this.mapData(this.dataCache, maskPattern);
|
|
763
|
+
},
|
|
764
|
+
setupPositionProbePattern: function(row, col) {
|
|
765
|
+
for (var r = -1; r <= 7; r++) {
|
|
766
|
+
if (row + r <= -1 || this.moduleCount <= row + r) continue;
|
|
767
|
+
for (var c = -1; c <= 7; c++) {
|
|
768
|
+
if (col + c <= -1 || this.moduleCount <= col + c) continue;
|
|
769
|
+
if (0 <= r && r <= 6 && (c === 0 || c === 6) || 0 <= c && c <= 6 && (r === 0 || r === 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {
|
|
770
|
+
this.modules[row + r][col + c] = true;
|
|
771
|
+
} else {
|
|
772
|
+
this.modules[row + r][col + c] = false;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
getBestMaskPattern: function() {
|
|
778
|
+
var minLostPoint = 0;
|
|
779
|
+
var pattern = 0;
|
|
780
|
+
for (var i = 0; i < 8; i++) {
|
|
781
|
+
this.makeImpl(true, i);
|
|
782
|
+
var lostPoint = QRUtil.getLostPoint(this);
|
|
783
|
+
if (i === 0 || minLostPoint > lostPoint) {
|
|
784
|
+
minLostPoint = lostPoint;
|
|
785
|
+
pattern = i;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return pattern;
|
|
789
|
+
},
|
|
790
|
+
createMovieClip: function(target_mc, instance_name, depth) {
|
|
791
|
+
var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
|
|
792
|
+
var cs = 1;
|
|
793
|
+
this.make();
|
|
794
|
+
for (var row = 0; row < this.modules.length; row++) {
|
|
795
|
+
var y = row * cs;
|
|
796
|
+
for (var col = 0; col < this.modules[row].length; col++) {
|
|
797
|
+
var x = col * cs;
|
|
798
|
+
var dark = this.modules[row][col];
|
|
799
|
+
if (dark) {
|
|
800
|
+
qr_mc.beginFill(0, 100);
|
|
801
|
+
qr_mc.moveTo(x, y);
|
|
802
|
+
qr_mc.lineTo(x + cs, y);
|
|
803
|
+
qr_mc.lineTo(x + cs, y + cs);
|
|
804
|
+
qr_mc.lineTo(x, y + cs);
|
|
805
|
+
qr_mc.endFill();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
return qr_mc;
|
|
810
|
+
},
|
|
811
|
+
setupTimingPattern: function() {
|
|
812
|
+
for (var r = 8; r < this.moduleCount - 8; r++) {
|
|
813
|
+
if (this.modules[r][6] !== null) {
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
this.modules[r][6] = r % 2 === 0;
|
|
817
|
+
}
|
|
818
|
+
for (var c = 8; c < this.moduleCount - 8; c++) {
|
|
819
|
+
if (this.modules[6][c] !== null) {
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
this.modules[6][c] = c % 2 === 0;
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
setupPositionAdjustPattern: function() {
|
|
826
|
+
var pos = QRUtil.getPatternPosition(this.typeNumber);
|
|
827
|
+
for (var i = 0; i < pos.length; i++) {
|
|
828
|
+
for (var j = 0; j < pos.length; j++) {
|
|
829
|
+
var row = pos[i];
|
|
830
|
+
var col = pos[j];
|
|
831
|
+
if (this.modules[row][col] !== null) {
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
for (var r = -2; r <= 2; r++) {
|
|
835
|
+
for (var c = -2; c <= 2; c++) {
|
|
836
|
+
if (Math.abs(r) === 2 || Math.abs(c) === 2 || r === 0 && c === 0) {
|
|
837
|
+
this.modules[row + r][col + c] = true;
|
|
838
|
+
} else {
|
|
839
|
+
this.modules[row + r][col + c] = false;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
setupTypeNumber: function(test) {
|
|
847
|
+
var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
|
|
848
|
+
var mod;
|
|
849
|
+
for (var i = 0; i < 18; i++) {
|
|
850
|
+
mod = !test && (bits >> i & 1) === 1;
|
|
851
|
+
this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
|
|
852
|
+
}
|
|
853
|
+
for (var x = 0; x < 18; x++) {
|
|
854
|
+
mod = !test && (bits >> x & 1) === 1;
|
|
855
|
+
this.modules[x % 3 + this.moduleCount - 8 - 3][Math.floor(x / 3)] = mod;
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
setupTypeInfo: function(test, maskPattern) {
|
|
859
|
+
var data = this.errorCorrectLevel << 3 | maskPattern;
|
|
860
|
+
var bits = QRUtil.getBCHTypeInfo(data);
|
|
861
|
+
var mod;
|
|
862
|
+
for (var v = 0; v < 15; v++) {
|
|
863
|
+
mod = !test && (bits >> v & 1) === 1;
|
|
864
|
+
if (v < 6) {
|
|
865
|
+
this.modules[v][8] = mod;
|
|
866
|
+
} else if (v < 8) {
|
|
867
|
+
this.modules[v + 1][8] = mod;
|
|
868
|
+
} else {
|
|
869
|
+
this.modules[this.moduleCount - 15 + v][8] = mod;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
for (var h = 0; h < 15; h++) {
|
|
873
|
+
mod = !test && (bits >> h & 1) === 1;
|
|
874
|
+
if (h < 8) {
|
|
875
|
+
this.modules[8][this.moduleCount - h - 1] = mod;
|
|
876
|
+
} else if (h < 9) {
|
|
877
|
+
this.modules[8][15 - h - 1 + 1] = mod;
|
|
878
|
+
} else {
|
|
879
|
+
this.modules[8][15 - h - 1] = mod;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
this.modules[this.moduleCount - 8][8] = !test;
|
|
883
|
+
},
|
|
884
|
+
mapData: function(data, maskPattern) {
|
|
885
|
+
var inc = -1;
|
|
886
|
+
var row = this.moduleCount - 1;
|
|
887
|
+
var bitIndex = 7;
|
|
888
|
+
var byteIndex = 0;
|
|
889
|
+
for (var col = this.moduleCount - 1; col > 0; col -= 2) {
|
|
890
|
+
if (col === 6) col--;
|
|
891
|
+
while (true) {
|
|
892
|
+
for (var c = 0; c < 2; c++) {
|
|
893
|
+
if (this.modules[row][col - c] === null) {
|
|
894
|
+
var dark = false;
|
|
895
|
+
if (byteIndex < data.length) {
|
|
896
|
+
dark = (data[byteIndex] >>> bitIndex & 1) === 1;
|
|
897
|
+
}
|
|
898
|
+
var mask = QRUtil.getMask(maskPattern, row, col - c);
|
|
899
|
+
if (mask) {
|
|
900
|
+
dark = !dark;
|
|
901
|
+
}
|
|
902
|
+
this.modules[row][col - c] = dark;
|
|
903
|
+
bitIndex--;
|
|
904
|
+
if (bitIndex === -1) {
|
|
905
|
+
byteIndex++;
|
|
906
|
+
bitIndex = 7;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
row += inc;
|
|
911
|
+
if (row < 0 || this.moduleCount <= row) {
|
|
912
|
+
row -= inc;
|
|
913
|
+
inc = -inc;
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
QRCode.PAD0 = 236;
|
|
921
|
+
QRCode.PAD1 = 17;
|
|
922
|
+
QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
|
|
923
|
+
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
|
|
924
|
+
var buffer = new QRBitBuffer();
|
|
925
|
+
for (var i = 0; i < dataList.length; i++) {
|
|
926
|
+
var data = dataList[i];
|
|
927
|
+
buffer.put(data.mode, 4);
|
|
928
|
+
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
|
|
929
|
+
data.write(buffer);
|
|
930
|
+
}
|
|
931
|
+
var totalDataCount = 0;
|
|
932
|
+
for (var x = 0; x < rsBlocks.length; x++) {
|
|
933
|
+
totalDataCount += rsBlocks[x].dataCount;
|
|
934
|
+
}
|
|
935
|
+
if (buffer.getLengthInBits() > totalDataCount * 8) {
|
|
936
|
+
throw new Error("code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")");
|
|
937
|
+
}
|
|
938
|
+
if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
|
|
939
|
+
buffer.put(0, 4);
|
|
940
|
+
}
|
|
941
|
+
while (buffer.getLengthInBits() % 8 !== 0) {
|
|
942
|
+
buffer.putBit(false);
|
|
943
|
+
}
|
|
944
|
+
while (true) {
|
|
945
|
+
if (buffer.getLengthInBits() >= totalDataCount * 8) {
|
|
946
|
+
break;
|
|
947
|
+
}
|
|
948
|
+
buffer.put(QRCode.PAD0, 8);
|
|
949
|
+
if (buffer.getLengthInBits() >= totalDataCount * 8) {
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
buffer.put(QRCode.PAD1, 8);
|
|
953
|
+
}
|
|
954
|
+
return QRCode.createBytes(buffer, rsBlocks);
|
|
955
|
+
};
|
|
956
|
+
QRCode.createBytes = function(buffer, rsBlocks) {
|
|
957
|
+
var offset = 0;
|
|
958
|
+
var maxDcCount = 0;
|
|
959
|
+
var maxEcCount = 0;
|
|
960
|
+
var dcdata = new Array(rsBlocks.length);
|
|
961
|
+
var ecdata = new Array(rsBlocks.length);
|
|
962
|
+
for (var r = 0; r < rsBlocks.length; r++) {
|
|
963
|
+
var dcCount = rsBlocks[r].dataCount;
|
|
964
|
+
var ecCount = rsBlocks[r].totalCount - dcCount;
|
|
965
|
+
maxDcCount = Math.max(maxDcCount, dcCount);
|
|
966
|
+
maxEcCount = Math.max(maxEcCount, ecCount);
|
|
967
|
+
dcdata[r] = new Array(dcCount);
|
|
968
|
+
for (var i = 0; i < dcdata[r].length; i++) {
|
|
969
|
+
dcdata[r][i] = 255 & buffer.buffer[i + offset];
|
|
970
|
+
}
|
|
971
|
+
offset += dcCount;
|
|
972
|
+
var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
|
|
973
|
+
var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
|
|
974
|
+
var modPoly = rawPoly.mod(rsPoly);
|
|
975
|
+
ecdata[r] = new Array(rsPoly.getLength() - 1);
|
|
976
|
+
for (var x = 0; x < ecdata[r].length; x++) {
|
|
977
|
+
var modIndex = x + modPoly.getLength() - ecdata[r].length;
|
|
978
|
+
ecdata[r][x] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
var totalCodeCount = 0;
|
|
982
|
+
for (var y = 0; y < rsBlocks.length; y++) {
|
|
983
|
+
totalCodeCount += rsBlocks[y].totalCount;
|
|
984
|
+
}
|
|
985
|
+
var data = new Array(totalCodeCount);
|
|
986
|
+
var index = 0;
|
|
987
|
+
for (var z = 0; z < maxDcCount; z++) {
|
|
988
|
+
for (var s = 0; s < rsBlocks.length; s++) {
|
|
989
|
+
if (z < dcdata[s].length) {
|
|
990
|
+
data[index++] = dcdata[s][z];
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
for (var xx = 0; xx < maxEcCount; xx++) {
|
|
995
|
+
for (var t = 0; t < rsBlocks.length; t++) {
|
|
996
|
+
if (xx < ecdata[t].length) {
|
|
997
|
+
data[index++] = ecdata[t][xx];
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return data;
|
|
1002
|
+
};
|
|
1003
|
+
module.exports = QRCode;
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
// node_modules/qrcode-terminal/lib/main.js
|
|
1008
|
+
var require_main = __commonJS({
|
|
1009
|
+
"node_modules/qrcode-terminal/lib/main.js"(exports, module) {
|
|
1010
|
+
var QRCode = require_QRCode();
|
|
1011
|
+
var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
|
|
1012
|
+
var black = "\x1B[40m \x1B[0m";
|
|
1013
|
+
var white = "\x1B[47m \x1B[0m";
|
|
1014
|
+
var toCell = function(isBlack) {
|
|
1015
|
+
return isBlack ? black : white;
|
|
1016
|
+
};
|
|
1017
|
+
var repeat = function(color) {
|
|
1018
|
+
return {
|
|
1019
|
+
times: function(count) {
|
|
1020
|
+
return new Array(count).join(color);
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
};
|
|
1024
|
+
var fill = function(length, value) {
|
|
1025
|
+
var arr = new Array(length);
|
|
1026
|
+
for (var i = 0; i < length; i++) {
|
|
1027
|
+
arr[i] = value;
|
|
1028
|
+
}
|
|
1029
|
+
return arr;
|
|
1030
|
+
};
|
|
1031
|
+
module.exports = {
|
|
1032
|
+
error: QRErrorCorrectLevel.L,
|
|
1033
|
+
generate: function(input, opts, cb) {
|
|
1034
|
+
if (typeof opts === "function") {
|
|
1035
|
+
cb = opts;
|
|
1036
|
+
opts = {};
|
|
1037
|
+
}
|
|
1038
|
+
var qrcode2 = new QRCode(-1, this.error);
|
|
1039
|
+
qrcode2.addData(input);
|
|
1040
|
+
qrcode2.make();
|
|
1041
|
+
var output = "";
|
|
1042
|
+
if (opts && opts.small) {
|
|
1043
|
+
var BLACK = true, WHITE = false;
|
|
1044
|
+
var moduleCount = qrcode2.getModuleCount();
|
|
1045
|
+
var moduleData = qrcode2.modules.slice();
|
|
1046
|
+
var oddRow = moduleCount % 2 === 1;
|
|
1047
|
+
if (oddRow) {
|
|
1048
|
+
moduleData.push(fill(moduleCount, WHITE));
|
|
1049
|
+
}
|
|
1050
|
+
var platte = {
|
|
1051
|
+
WHITE_ALL: "\u2588",
|
|
1052
|
+
WHITE_BLACK: "\u2580",
|
|
1053
|
+
BLACK_WHITE: "\u2584",
|
|
1054
|
+
BLACK_ALL: " "
|
|
1055
|
+
};
|
|
1056
|
+
var borderTop = repeat(platte.BLACK_WHITE).times(moduleCount + 3);
|
|
1057
|
+
var borderBottom = repeat(platte.WHITE_BLACK).times(moduleCount + 3);
|
|
1058
|
+
output += borderTop + "\n";
|
|
1059
|
+
for (var row = 0; row < moduleCount; row += 2) {
|
|
1060
|
+
output += platte.WHITE_ALL;
|
|
1061
|
+
for (var col = 0; col < moduleCount; col++) {
|
|
1062
|
+
if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === WHITE) {
|
|
1063
|
+
output += platte.WHITE_ALL;
|
|
1064
|
+
} else if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === BLACK) {
|
|
1065
|
+
output += platte.WHITE_BLACK;
|
|
1066
|
+
} else if (moduleData[row][col] === BLACK && moduleData[row + 1][col] === WHITE) {
|
|
1067
|
+
output += platte.BLACK_WHITE;
|
|
1068
|
+
} else {
|
|
1069
|
+
output += platte.BLACK_ALL;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
output += platte.WHITE_ALL + "\n";
|
|
1073
|
+
}
|
|
1074
|
+
if (!oddRow) {
|
|
1075
|
+
output += borderBottom;
|
|
1076
|
+
}
|
|
1077
|
+
} else {
|
|
1078
|
+
var border = repeat(white).times(qrcode2.getModuleCount() + 3);
|
|
1079
|
+
output += border + "\n";
|
|
1080
|
+
qrcode2.modules.forEach(function(row2) {
|
|
1081
|
+
output += white;
|
|
1082
|
+
output += row2.map(toCell).join("");
|
|
1083
|
+
output += white + "\n";
|
|
1084
|
+
});
|
|
1085
|
+
output += border;
|
|
1086
|
+
}
|
|
1087
|
+
if (cb) cb(output);
|
|
1088
|
+
else console.log(output);
|
|
1089
|
+
},
|
|
1090
|
+
setErrorLevel: function(error) {
|
|
1091
|
+
this.error = QRErrorCorrectLevel[error] || this.error;
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
// qr-entry.js
|
|
1098
|
+
var import_qrcode_terminal = __toESM(require_main(), 1);
|
|
1099
|
+
function renderQr(text) {
|
|
1100
|
+
import_qrcode_terminal.default.generate(text, { small: true });
|
|
1101
|
+
}
|
|
1102
|
+
export {
|
|
1103
|
+
renderQr
|
|
1104
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alink-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "一条命令把工作机接入 AgentLink,随时随地遥控本机的编码 agent。One command to link your machine to AgentLink and control your coding agents from anywhere.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,9 +35,10 @@
|
|
|
35
35
|
"README.md"
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "esbuild ../daemon/src/main.ts --bundle --platform=node --format=esm --outfile=dist/daemon.js --external:bufferutil --external:utf-8-validate --banner:js=\"import { createRequire as __agentlinkRequire } from 'module'; const require = __agentlinkRequire(import.meta.url);\""
|
|
38
|
+
"build": "esbuild ../daemon/src/main.ts --bundle --platform=node --format=esm --outfile=dist/daemon.js --external:bufferutil --external:utf-8-validate --banner:js=\"import { createRequire as __agentlinkRequire } from 'module'; const require = __agentlinkRequire(import.meta.url);\" && esbuild qr-entry.js --bundle --platform=node --format=esm --outfile=dist/qr.js"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"esbuild": "^0.25.0"
|
|
41
|
+
"esbuild": "^0.25.0",
|
|
42
|
+
"qrcode-terminal": "^0.12.0"
|
|
42
43
|
}
|
|
43
44
|
}
|