@plank-cms/plank 0.14.1 → 0.14.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/dist/admin/assets/{index-qgnby08U.js → index-BJbRJ4YN.js} +50 -50
- package/dist/admin/assets/index-BmcINqbt.css +2 -0
- package/dist/admin/index.html +2 -2
- package/dist/index.js +4 -3
- package/dist/migrations/025_auth_security.sql +13 -0
- package/dist/{server-WLCTRM3K.js → server-CKAS7YSX.js} +189 -4656
- package/package.json +4 -4
- package/dist/admin/assets/index-Xo36womD.css +0 -2
- package/dist/chunk-MO4EEYFW.js +0 -38
|
@@ -1,4577 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
__commonJS,
|
|
4
|
-
__require,
|
|
5
|
-
__toESM
|
|
6
|
-
} from "./chunk-MO4EEYFW.js";
|
|
7
|
-
|
|
8
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js
|
|
9
|
-
var require_can_promise = __commonJS({
|
|
10
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js"(exports, module) {
|
|
11
|
-
"use strict";
|
|
12
|
-
module.exports = function() {
|
|
13
|
-
return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js
|
|
19
|
-
var require_utils = __commonJS({
|
|
20
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"(exports) {
|
|
21
|
-
"use strict";
|
|
22
|
-
var toSJISFunction;
|
|
23
|
-
var CODEWORDS_COUNT = [
|
|
24
|
-
0,
|
|
25
|
-
// Not used
|
|
26
|
-
26,
|
|
27
|
-
44,
|
|
28
|
-
70,
|
|
29
|
-
100,
|
|
30
|
-
134,
|
|
31
|
-
172,
|
|
32
|
-
196,
|
|
33
|
-
242,
|
|
34
|
-
292,
|
|
35
|
-
346,
|
|
36
|
-
404,
|
|
37
|
-
466,
|
|
38
|
-
532,
|
|
39
|
-
581,
|
|
40
|
-
655,
|
|
41
|
-
733,
|
|
42
|
-
815,
|
|
43
|
-
901,
|
|
44
|
-
991,
|
|
45
|
-
1085,
|
|
46
|
-
1156,
|
|
47
|
-
1258,
|
|
48
|
-
1364,
|
|
49
|
-
1474,
|
|
50
|
-
1588,
|
|
51
|
-
1706,
|
|
52
|
-
1828,
|
|
53
|
-
1921,
|
|
54
|
-
2051,
|
|
55
|
-
2185,
|
|
56
|
-
2323,
|
|
57
|
-
2465,
|
|
58
|
-
2611,
|
|
59
|
-
2761,
|
|
60
|
-
2876,
|
|
61
|
-
3034,
|
|
62
|
-
3196,
|
|
63
|
-
3362,
|
|
64
|
-
3532,
|
|
65
|
-
3706
|
|
66
|
-
];
|
|
67
|
-
exports.getSymbolSize = function getSymbolSize(version) {
|
|
68
|
-
if (!version) throw new Error('"version" cannot be null or undefined');
|
|
69
|
-
if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
|
|
70
|
-
return version * 4 + 17;
|
|
71
|
-
};
|
|
72
|
-
exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
|
|
73
|
-
return CODEWORDS_COUNT[version];
|
|
74
|
-
};
|
|
75
|
-
exports.getBCHDigit = function(data) {
|
|
76
|
-
let digit = 0;
|
|
77
|
-
while (data !== 0) {
|
|
78
|
-
digit++;
|
|
79
|
-
data >>>= 1;
|
|
80
|
-
}
|
|
81
|
-
return digit;
|
|
82
|
-
};
|
|
83
|
-
exports.setToSJISFunction = function setToSJISFunction(f2) {
|
|
84
|
-
if (typeof f2 !== "function") {
|
|
85
|
-
throw new Error('"toSJISFunc" is not a valid function.');
|
|
86
|
-
}
|
|
87
|
-
toSJISFunction = f2;
|
|
88
|
-
};
|
|
89
|
-
exports.isKanjiModeEnabled = function() {
|
|
90
|
-
return typeof toSJISFunction !== "undefined";
|
|
91
|
-
};
|
|
92
|
-
exports.toSJIS = function toSJIS(kanji) {
|
|
93
|
-
return toSJISFunction(kanji);
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js
|
|
99
|
-
var require_error_correction_level = __commonJS({
|
|
100
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"(exports) {
|
|
101
|
-
"use strict";
|
|
102
|
-
exports.L = { bit: 1 };
|
|
103
|
-
exports.M = { bit: 0 };
|
|
104
|
-
exports.Q = { bit: 3 };
|
|
105
|
-
exports.H = { bit: 2 };
|
|
106
|
-
function fromString(string) {
|
|
107
|
-
if (typeof string !== "string") {
|
|
108
|
-
throw new Error("Param is not a string");
|
|
109
|
-
}
|
|
110
|
-
const lcStr = string.toLowerCase();
|
|
111
|
-
switch (lcStr) {
|
|
112
|
-
case "l":
|
|
113
|
-
case "low":
|
|
114
|
-
return exports.L;
|
|
115
|
-
case "m":
|
|
116
|
-
case "medium":
|
|
117
|
-
return exports.M;
|
|
118
|
-
case "q":
|
|
119
|
-
case "quartile":
|
|
120
|
-
return exports.Q;
|
|
121
|
-
case "h":
|
|
122
|
-
case "high":
|
|
123
|
-
return exports.H;
|
|
124
|
-
default:
|
|
125
|
-
throw new Error("Unknown EC Level: " + string);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.isValid = function isValid(level) {
|
|
129
|
-
return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
|
|
130
|
-
};
|
|
131
|
-
exports.from = function from(value, defaultValue) {
|
|
132
|
-
if (exports.isValid(value)) {
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
try {
|
|
136
|
-
return fromString(value);
|
|
137
|
-
} catch (e) {
|
|
138
|
-
return defaultValue;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js
|
|
145
|
-
var require_bit_buffer = __commonJS({
|
|
146
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js"(exports, module) {
|
|
147
|
-
"use strict";
|
|
148
|
-
function BitBuffer() {
|
|
149
|
-
this.buffer = [];
|
|
150
|
-
this.length = 0;
|
|
151
|
-
}
|
|
152
|
-
BitBuffer.prototype = {
|
|
153
|
-
get: function(index) {
|
|
154
|
-
const bufIndex = Math.floor(index / 8);
|
|
155
|
-
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
|
|
156
|
-
},
|
|
157
|
-
put: function(num, length) {
|
|
158
|
-
for (let i2 = 0; i2 < length; i2++) {
|
|
159
|
-
this.putBit((num >>> length - i2 - 1 & 1) === 1);
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
getLengthInBits: function() {
|
|
163
|
-
return this.length;
|
|
164
|
-
},
|
|
165
|
-
putBit: function(bit) {
|
|
166
|
-
const bufIndex = Math.floor(this.length / 8);
|
|
167
|
-
if (this.buffer.length <= bufIndex) {
|
|
168
|
-
this.buffer.push(0);
|
|
169
|
-
}
|
|
170
|
-
if (bit) {
|
|
171
|
-
this.buffer[bufIndex] |= 128 >>> this.length % 8;
|
|
172
|
-
}
|
|
173
|
-
this.length++;
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
module.exports = BitBuffer;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js
|
|
181
|
-
var require_bit_matrix = __commonJS({
|
|
182
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js"(exports, module) {
|
|
183
|
-
"use strict";
|
|
184
|
-
function BitMatrix(size) {
|
|
185
|
-
if (!size || size < 1) {
|
|
186
|
-
throw new Error("BitMatrix size must be defined and greater than 0");
|
|
187
|
-
}
|
|
188
|
-
this.size = size;
|
|
189
|
-
this.data = new Uint8Array(size * size);
|
|
190
|
-
this.reservedBit = new Uint8Array(size * size);
|
|
191
|
-
}
|
|
192
|
-
BitMatrix.prototype.set = function(row, col, value, reserved) {
|
|
193
|
-
const index = row * this.size + col;
|
|
194
|
-
this.data[index] = value;
|
|
195
|
-
if (reserved) this.reservedBit[index] = true;
|
|
196
|
-
};
|
|
197
|
-
BitMatrix.prototype.get = function(row, col) {
|
|
198
|
-
return this.data[row * this.size + col];
|
|
199
|
-
};
|
|
200
|
-
BitMatrix.prototype.xor = function(row, col, value) {
|
|
201
|
-
this.data[row * this.size + col] ^= value;
|
|
202
|
-
};
|
|
203
|
-
BitMatrix.prototype.isReserved = function(row, col) {
|
|
204
|
-
return this.reservedBit[row * this.size + col];
|
|
205
|
-
};
|
|
206
|
-
module.exports = BitMatrix;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js
|
|
211
|
-
var require_alignment_pattern = __commonJS({
|
|
212
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js"(exports) {
|
|
213
|
-
"use strict";
|
|
214
|
-
var getSymbolSize = require_utils().getSymbolSize;
|
|
215
|
-
exports.getRowColCoords = function getRowColCoords(version) {
|
|
216
|
-
if (version === 1) return [];
|
|
217
|
-
const posCount = Math.floor(version / 7) + 2;
|
|
218
|
-
const size = getSymbolSize(version);
|
|
219
|
-
const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
|
|
220
|
-
const positions = [size - 7];
|
|
221
|
-
for (let i2 = 1; i2 < posCount - 1; i2++) {
|
|
222
|
-
positions[i2] = positions[i2 - 1] - intervals;
|
|
223
|
-
}
|
|
224
|
-
positions.push(6);
|
|
225
|
-
return positions.reverse();
|
|
226
|
-
};
|
|
227
|
-
exports.getPositions = function getPositions(version) {
|
|
228
|
-
const coords = [];
|
|
229
|
-
const pos = exports.getRowColCoords(version);
|
|
230
|
-
const posLength = pos.length;
|
|
231
|
-
for (let i2 = 0; i2 < posLength; i2++) {
|
|
232
|
-
for (let j = 0; j < posLength; j++) {
|
|
233
|
-
if (i2 === 0 && j === 0 || // top-left
|
|
234
|
-
i2 === 0 && j === posLength - 1 || // bottom-left
|
|
235
|
-
i2 === posLength - 1 && j === 0) {
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
coords.push([pos[i2], pos[j]]);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return coords;
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js
|
|
247
|
-
var require_finder_pattern = __commonJS({
|
|
248
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js"(exports) {
|
|
249
|
-
"use strict";
|
|
250
|
-
var getSymbolSize = require_utils().getSymbolSize;
|
|
251
|
-
var FINDER_PATTERN_SIZE = 7;
|
|
252
|
-
exports.getPositions = function getPositions(version) {
|
|
253
|
-
const size = getSymbolSize(version);
|
|
254
|
-
return [
|
|
255
|
-
// top-left
|
|
256
|
-
[0, 0],
|
|
257
|
-
// top-right
|
|
258
|
-
[size - FINDER_PATTERN_SIZE, 0],
|
|
259
|
-
// bottom-left
|
|
260
|
-
[0, size - FINDER_PATTERN_SIZE]
|
|
261
|
-
];
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js
|
|
267
|
-
var require_mask_pattern = __commonJS({
|
|
268
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js"(exports) {
|
|
269
|
-
"use strict";
|
|
270
|
-
exports.Patterns = {
|
|
271
|
-
PATTERN000: 0,
|
|
272
|
-
PATTERN001: 1,
|
|
273
|
-
PATTERN010: 2,
|
|
274
|
-
PATTERN011: 3,
|
|
275
|
-
PATTERN100: 4,
|
|
276
|
-
PATTERN101: 5,
|
|
277
|
-
PATTERN110: 6,
|
|
278
|
-
PATTERN111: 7
|
|
279
|
-
};
|
|
280
|
-
var PenaltyScores = {
|
|
281
|
-
N1: 3,
|
|
282
|
-
N2: 3,
|
|
283
|
-
N3: 40,
|
|
284
|
-
N4: 10
|
|
285
|
-
};
|
|
286
|
-
exports.isValid = function isValid(mask) {
|
|
287
|
-
return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
|
|
288
|
-
};
|
|
289
|
-
exports.from = function from(value) {
|
|
290
|
-
return exports.isValid(value) ? parseInt(value, 10) : void 0;
|
|
291
|
-
};
|
|
292
|
-
exports.getPenaltyN1 = function getPenaltyN1(data) {
|
|
293
|
-
const size = data.size;
|
|
294
|
-
let points = 0;
|
|
295
|
-
let sameCountCol = 0;
|
|
296
|
-
let sameCountRow = 0;
|
|
297
|
-
let lastCol = null;
|
|
298
|
-
let lastRow = null;
|
|
299
|
-
for (let row = 0; row < size; row++) {
|
|
300
|
-
sameCountCol = sameCountRow = 0;
|
|
301
|
-
lastCol = lastRow = null;
|
|
302
|
-
for (let col = 0; col < size; col++) {
|
|
303
|
-
let module2 = data.get(row, col);
|
|
304
|
-
if (module2 === lastCol) {
|
|
305
|
-
sameCountCol++;
|
|
306
|
-
} else {
|
|
307
|
-
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
308
|
-
lastCol = module2;
|
|
309
|
-
sameCountCol = 1;
|
|
310
|
-
}
|
|
311
|
-
module2 = data.get(col, row);
|
|
312
|
-
if (module2 === lastRow) {
|
|
313
|
-
sameCountRow++;
|
|
314
|
-
} else {
|
|
315
|
-
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
316
|
-
lastRow = module2;
|
|
317
|
-
sameCountRow = 1;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
321
|
-
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
322
|
-
}
|
|
323
|
-
return points;
|
|
324
|
-
};
|
|
325
|
-
exports.getPenaltyN2 = function getPenaltyN2(data) {
|
|
326
|
-
const size = data.size;
|
|
327
|
-
let points = 0;
|
|
328
|
-
for (let row = 0; row < size - 1; row++) {
|
|
329
|
-
for (let col = 0; col < size - 1; col++) {
|
|
330
|
-
const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
|
|
331
|
-
if (last === 4 || last === 0) points++;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return points * PenaltyScores.N2;
|
|
335
|
-
};
|
|
336
|
-
exports.getPenaltyN3 = function getPenaltyN3(data) {
|
|
337
|
-
const size = data.size;
|
|
338
|
-
let points = 0;
|
|
339
|
-
let bitsCol = 0;
|
|
340
|
-
let bitsRow = 0;
|
|
341
|
-
for (let row = 0; row < size; row++) {
|
|
342
|
-
bitsCol = bitsRow = 0;
|
|
343
|
-
for (let col = 0; col < size; col++) {
|
|
344
|
-
bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
|
|
345
|
-
if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
|
|
346
|
-
bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
|
|
347
|
-
if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return points * PenaltyScores.N3;
|
|
351
|
-
};
|
|
352
|
-
exports.getPenaltyN4 = function getPenaltyN4(data) {
|
|
353
|
-
let darkCount = 0;
|
|
354
|
-
const modulesCount = data.data.length;
|
|
355
|
-
for (let i2 = 0; i2 < modulesCount; i2++) darkCount += data.data[i2];
|
|
356
|
-
const k3 = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
|
|
357
|
-
return k3 * PenaltyScores.N4;
|
|
358
|
-
};
|
|
359
|
-
function getMaskAt(maskPattern, i2, j) {
|
|
360
|
-
switch (maskPattern) {
|
|
361
|
-
case exports.Patterns.PATTERN000:
|
|
362
|
-
return (i2 + j) % 2 === 0;
|
|
363
|
-
case exports.Patterns.PATTERN001:
|
|
364
|
-
return i2 % 2 === 0;
|
|
365
|
-
case exports.Patterns.PATTERN010:
|
|
366
|
-
return j % 3 === 0;
|
|
367
|
-
case exports.Patterns.PATTERN011:
|
|
368
|
-
return (i2 + j) % 3 === 0;
|
|
369
|
-
case exports.Patterns.PATTERN100:
|
|
370
|
-
return (Math.floor(i2 / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
371
|
-
case exports.Patterns.PATTERN101:
|
|
372
|
-
return i2 * j % 2 + i2 * j % 3 === 0;
|
|
373
|
-
case exports.Patterns.PATTERN110:
|
|
374
|
-
return (i2 * j % 2 + i2 * j % 3) % 2 === 0;
|
|
375
|
-
case exports.Patterns.PATTERN111:
|
|
376
|
-
return (i2 * j % 3 + (i2 + j) % 2) % 2 === 0;
|
|
377
|
-
default:
|
|
378
|
-
throw new Error("bad maskPattern:" + maskPattern);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
exports.applyMask = function applyMask(pattern, data) {
|
|
382
|
-
const size = data.size;
|
|
383
|
-
for (let col = 0; col < size; col++) {
|
|
384
|
-
for (let row = 0; row < size; row++) {
|
|
385
|
-
if (data.isReserved(row, col)) continue;
|
|
386
|
-
data.xor(row, col, getMaskAt(pattern, row, col));
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
exports.getBestMask = function getBestMask(data, setupFormatFunc) {
|
|
391
|
-
const numPatterns = Object.keys(exports.Patterns).length;
|
|
392
|
-
let bestPattern = 0;
|
|
393
|
-
let lowerPenalty = Infinity;
|
|
394
|
-
for (let p = 0; p < numPatterns; p++) {
|
|
395
|
-
setupFormatFunc(p);
|
|
396
|
-
exports.applyMask(p, data);
|
|
397
|
-
const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
|
|
398
|
-
exports.applyMask(p, data);
|
|
399
|
-
if (penalty < lowerPenalty) {
|
|
400
|
-
lowerPenalty = penalty;
|
|
401
|
-
bestPattern = p;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return bestPattern;
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js
|
|
410
|
-
var require_error_correction_code = __commonJS({
|
|
411
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"(exports) {
|
|
412
|
-
"use strict";
|
|
413
|
-
var ECLevel = require_error_correction_level();
|
|
414
|
-
var EC_BLOCKS_TABLE = [
|
|
415
|
-
// L M Q H
|
|
416
|
-
1,
|
|
417
|
-
1,
|
|
418
|
-
1,
|
|
419
|
-
1,
|
|
420
|
-
1,
|
|
421
|
-
1,
|
|
422
|
-
1,
|
|
423
|
-
1,
|
|
424
|
-
1,
|
|
425
|
-
1,
|
|
426
|
-
2,
|
|
427
|
-
2,
|
|
428
|
-
1,
|
|
429
|
-
2,
|
|
430
|
-
2,
|
|
431
|
-
4,
|
|
432
|
-
1,
|
|
433
|
-
2,
|
|
434
|
-
4,
|
|
435
|
-
4,
|
|
436
|
-
2,
|
|
437
|
-
4,
|
|
438
|
-
4,
|
|
439
|
-
4,
|
|
440
|
-
2,
|
|
441
|
-
4,
|
|
442
|
-
6,
|
|
443
|
-
5,
|
|
444
|
-
2,
|
|
445
|
-
4,
|
|
446
|
-
6,
|
|
447
|
-
6,
|
|
448
|
-
2,
|
|
449
|
-
5,
|
|
450
|
-
8,
|
|
451
|
-
8,
|
|
452
|
-
4,
|
|
453
|
-
5,
|
|
454
|
-
8,
|
|
455
|
-
8,
|
|
456
|
-
4,
|
|
457
|
-
5,
|
|
458
|
-
8,
|
|
459
|
-
11,
|
|
460
|
-
4,
|
|
461
|
-
8,
|
|
462
|
-
10,
|
|
463
|
-
11,
|
|
464
|
-
4,
|
|
465
|
-
9,
|
|
466
|
-
12,
|
|
467
|
-
16,
|
|
468
|
-
4,
|
|
469
|
-
9,
|
|
470
|
-
16,
|
|
471
|
-
16,
|
|
472
|
-
6,
|
|
473
|
-
10,
|
|
474
|
-
12,
|
|
475
|
-
18,
|
|
476
|
-
6,
|
|
477
|
-
10,
|
|
478
|
-
17,
|
|
479
|
-
16,
|
|
480
|
-
6,
|
|
481
|
-
11,
|
|
482
|
-
16,
|
|
483
|
-
19,
|
|
484
|
-
6,
|
|
485
|
-
13,
|
|
486
|
-
18,
|
|
487
|
-
21,
|
|
488
|
-
7,
|
|
489
|
-
14,
|
|
490
|
-
21,
|
|
491
|
-
25,
|
|
492
|
-
8,
|
|
493
|
-
16,
|
|
494
|
-
20,
|
|
495
|
-
25,
|
|
496
|
-
8,
|
|
497
|
-
17,
|
|
498
|
-
23,
|
|
499
|
-
25,
|
|
500
|
-
9,
|
|
501
|
-
17,
|
|
502
|
-
23,
|
|
503
|
-
34,
|
|
504
|
-
9,
|
|
505
|
-
18,
|
|
506
|
-
25,
|
|
507
|
-
30,
|
|
508
|
-
10,
|
|
509
|
-
20,
|
|
510
|
-
27,
|
|
511
|
-
32,
|
|
512
|
-
12,
|
|
513
|
-
21,
|
|
514
|
-
29,
|
|
515
|
-
35,
|
|
516
|
-
12,
|
|
517
|
-
23,
|
|
518
|
-
34,
|
|
519
|
-
37,
|
|
520
|
-
12,
|
|
521
|
-
25,
|
|
522
|
-
34,
|
|
523
|
-
40,
|
|
524
|
-
13,
|
|
525
|
-
26,
|
|
526
|
-
35,
|
|
527
|
-
42,
|
|
528
|
-
14,
|
|
529
|
-
28,
|
|
530
|
-
38,
|
|
531
|
-
45,
|
|
532
|
-
15,
|
|
533
|
-
29,
|
|
534
|
-
40,
|
|
535
|
-
48,
|
|
536
|
-
16,
|
|
537
|
-
31,
|
|
538
|
-
43,
|
|
539
|
-
51,
|
|
540
|
-
17,
|
|
541
|
-
33,
|
|
542
|
-
45,
|
|
543
|
-
54,
|
|
544
|
-
18,
|
|
545
|
-
35,
|
|
546
|
-
48,
|
|
547
|
-
57,
|
|
548
|
-
19,
|
|
549
|
-
37,
|
|
550
|
-
51,
|
|
551
|
-
60,
|
|
552
|
-
19,
|
|
553
|
-
38,
|
|
554
|
-
53,
|
|
555
|
-
63,
|
|
556
|
-
20,
|
|
557
|
-
40,
|
|
558
|
-
56,
|
|
559
|
-
66,
|
|
560
|
-
21,
|
|
561
|
-
43,
|
|
562
|
-
59,
|
|
563
|
-
70,
|
|
564
|
-
22,
|
|
565
|
-
45,
|
|
566
|
-
62,
|
|
567
|
-
74,
|
|
568
|
-
24,
|
|
569
|
-
47,
|
|
570
|
-
65,
|
|
571
|
-
77,
|
|
572
|
-
25,
|
|
573
|
-
49,
|
|
574
|
-
68,
|
|
575
|
-
81
|
|
576
|
-
];
|
|
577
|
-
var EC_CODEWORDS_TABLE = [
|
|
578
|
-
// L M Q H
|
|
579
|
-
7,
|
|
580
|
-
10,
|
|
581
|
-
13,
|
|
582
|
-
17,
|
|
583
|
-
10,
|
|
584
|
-
16,
|
|
585
|
-
22,
|
|
586
|
-
28,
|
|
587
|
-
15,
|
|
588
|
-
26,
|
|
589
|
-
36,
|
|
590
|
-
44,
|
|
591
|
-
20,
|
|
592
|
-
36,
|
|
593
|
-
52,
|
|
594
|
-
64,
|
|
595
|
-
26,
|
|
596
|
-
48,
|
|
597
|
-
72,
|
|
598
|
-
88,
|
|
599
|
-
36,
|
|
600
|
-
64,
|
|
601
|
-
96,
|
|
602
|
-
112,
|
|
603
|
-
40,
|
|
604
|
-
72,
|
|
605
|
-
108,
|
|
606
|
-
130,
|
|
607
|
-
48,
|
|
608
|
-
88,
|
|
609
|
-
132,
|
|
610
|
-
156,
|
|
611
|
-
60,
|
|
612
|
-
110,
|
|
613
|
-
160,
|
|
614
|
-
192,
|
|
615
|
-
72,
|
|
616
|
-
130,
|
|
617
|
-
192,
|
|
618
|
-
224,
|
|
619
|
-
80,
|
|
620
|
-
150,
|
|
621
|
-
224,
|
|
622
|
-
264,
|
|
623
|
-
96,
|
|
624
|
-
176,
|
|
625
|
-
260,
|
|
626
|
-
308,
|
|
627
|
-
104,
|
|
628
|
-
198,
|
|
629
|
-
288,
|
|
630
|
-
352,
|
|
631
|
-
120,
|
|
632
|
-
216,
|
|
633
|
-
320,
|
|
634
|
-
384,
|
|
635
|
-
132,
|
|
636
|
-
240,
|
|
637
|
-
360,
|
|
638
|
-
432,
|
|
639
|
-
144,
|
|
640
|
-
280,
|
|
641
|
-
408,
|
|
642
|
-
480,
|
|
643
|
-
168,
|
|
644
|
-
308,
|
|
645
|
-
448,
|
|
646
|
-
532,
|
|
647
|
-
180,
|
|
648
|
-
338,
|
|
649
|
-
504,
|
|
650
|
-
588,
|
|
651
|
-
196,
|
|
652
|
-
364,
|
|
653
|
-
546,
|
|
654
|
-
650,
|
|
655
|
-
224,
|
|
656
|
-
416,
|
|
657
|
-
600,
|
|
658
|
-
700,
|
|
659
|
-
224,
|
|
660
|
-
442,
|
|
661
|
-
644,
|
|
662
|
-
750,
|
|
663
|
-
252,
|
|
664
|
-
476,
|
|
665
|
-
690,
|
|
666
|
-
816,
|
|
667
|
-
270,
|
|
668
|
-
504,
|
|
669
|
-
750,
|
|
670
|
-
900,
|
|
671
|
-
300,
|
|
672
|
-
560,
|
|
673
|
-
810,
|
|
674
|
-
960,
|
|
675
|
-
312,
|
|
676
|
-
588,
|
|
677
|
-
870,
|
|
678
|
-
1050,
|
|
679
|
-
336,
|
|
680
|
-
644,
|
|
681
|
-
952,
|
|
682
|
-
1110,
|
|
683
|
-
360,
|
|
684
|
-
700,
|
|
685
|
-
1020,
|
|
686
|
-
1200,
|
|
687
|
-
390,
|
|
688
|
-
728,
|
|
689
|
-
1050,
|
|
690
|
-
1260,
|
|
691
|
-
420,
|
|
692
|
-
784,
|
|
693
|
-
1140,
|
|
694
|
-
1350,
|
|
695
|
-
450,
|
|
696
|
-
812,
|
|
697
|
-
1200,
|
|
698
|
-
1440,
|
|
699
|
-
480,
|
|
700
|
-
868,
|
|
701
|
-
1290,
|
|
702
|
-
1530,
|
|
703
|
-
510,
|
|
704
|
-
924,
|
|
705
|
-
1350,
|
|
706
|
-
1620,
|
|
707
|
-
540,
|
|
708
|
-
980,
|
|
709
|
-
1440,
|
|
710
|
-
1710,
|
|
711
|
-
570,
|
|
712
|
-
1036,
|
|
713
|
-
1530,
|
|
714
|
-
1800,
|
|
715
|
-
570,
|
|
716
|
-
1064,
|
|
717
|
-
1590,
|
|
718
|
-
1890,
|
|
719
|
-
600,
|
|
720
|
-
1120,
|
|
721
|
-
1680,
|
|
722
|
-
1980,
|
|
723
|
-
630,
|
|
724
|
-
1204,
|
|
725
|
-
1770,
|
|
726
|
-
2100,
|
|
727
|
-
660,
|
|
728
|
-
1260,
|
|
729
|
-
1860,
|
|
730
|
-
2220,
|
|
731
|
-
720,
|
|
732
|
-
1316,
|
|
733
|
-
1950,
|
|
734
|
-
2310,
|
|
735
|
-
750,
|
|
736
|
-
1372,
|
|
737
|
-
2040,
|
|
738
|
-
2430
|
|
739
|
-
];
|
|
740
|
-
exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
|
|
741
|
-
switch (errorCorrectionLevel) {
|
|
742
|
-
case ECLevel.L:
|
|
743
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
|
|
744
|
-
case ECLevel.M:
|
|
745
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
|
|
746
|
-
case ECLevel.Q:
|
|
747
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
|
|
748
|
-
case ECLevel.H:
|
|
749
|
-
return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
|
|
750
|
-
default:
|
|
751
|
-
return void 0;
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
|
|
755
|
-
switch (errorCorrectionLevel) {
|
|
756
|
-
case ECLevel.L:
|
|
757
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
|
|
758
|
-
case ECLevel.M:
|
|
759
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
|
|
760
|
-
case ECLevel.Q:
|
|
761
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
|
|
762
|
-
case ECLevel.H:
|
|
763
|
-
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
|
|
764
|
-
default:
|
|
765
|
-
return void 0;
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js
|
|
772
|
-
var require_galois_field = __commonJS({
|
|
773
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js"(exports) {
|
|
774
|
-
"use strict";
|
|
775
|
-
var EXP_TABLE = new Uint8Array(512);
|
|
776
|
-
var LOG_TABLE = new Uint8Array(256);
|
|
777
|
-
(function initTables() {
|
|
778
|
-
let x4 = 1;
|
|
779
|
-
for (let i2 = 0; i2 < 255; i2++) {
|
|
780
|
-
EXP_TABLE[i2] = x4;
|
|
781
|
-
LOG_TABLE[x4] = i2;
|
|
782
|
-
x4 <<= 1;
|
|
783
|
-
if (x4 & 256) {
|
|
784
|
-
x4 ^= 285;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
for (let i2 = 255; i2 < 512; i2++) {
|
|
788
|
-
EXP_TABLE[i2] = EXP_TABLE[i2 - 255];
|
|
789
|
-
}
|
|
790
|
-
})();
|
|
791
|
-
exports.log = function log(n) {
|
|
792
|
-
if (n < 1) throw new Error("log(" + n + ")");
|
|
793
|
-
return LOG_TABLE[n];
|
|
794
|
-
};
|
|
795
|
-
exports.exp = function exp(n) {
|
|
796
|
-
return EXP_TABLE[n];
|
|
797
|
-
};
|
|
798
|
-
exports.mul = function mul(x4, y2) {
|
|
799
|
-
if (x4 === 0 || y2 === 0) return 0;
|
|
800
|
-
return EXP_TABLE[LOG_TABLE[x4] + LOG_TABLE[y2]];
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
|
|
805
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js
|
|
806
|
-
var require_polynomial = __commonJS({
|
|
807
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js"(exports) {
|
|
808
|
-
"use strict";
|
|
809
|
-
var GF = require_galois_field();
|
|
810
|
-
exports.mul = function mul(p1, p2) {
|
|
811
|
-
const coeff = new Uint8Array(p1.length + p2.length - 1);
|
|
812
|
-
for (let i2 = 0; i2 < p1.length; i2++) {
|
|
813
|
-
for (let j = 0; j < p2.length; j++) {
|
|
814
|
-
coeff[i2 + j] ^= GF.mul(p1[i2], p2[j]);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
return coeff;
|
|
818
|
-
};
|
|
819
|
-
exports.mod = function mod(divident, divisor) {
|
|
820
|
-
let result = new Uint8Array(divident);
|
|
821
|
-
while (result.length - divisor.length >= 0) {
|
|
822
|
-
const coeff = result[0];
|
|
823
|
-
for (let i2 = 0; i2 < divisor.length; i2++) {
|
|
824
|
-
result[i2] ^= GF.mul(divisor[i2], coeff);
|
|
825
|
-
}
|
|
826
|
-
let offset = 0;
|
|
827
|
-
while (offset < result.length && result[offset] === 0) offset++;
|
|
828
|
-
result = result.slice(offset);
|
|
829
|
-
}
|
|
830
|
-
return result;
|
|
831
|
-
};
|
|
832
|
-
exports.generateECPolynomial = function generateECPolynomial(degree) {
|
|
833
|
-
let poly = new Uint8Array([1]);
|
|
834
|
-
for (let i2 = 0; i2 < degree; i2++) {
|
|
835
|
-
poly = exports.mul(poly, new Uint8Array([1, GF.exp(i2)]));
|
|
836
|
-
}
|
|
837
|
-
return poly;
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js
|
|
843
|
-
var require_reed_solomon_encoder = __commonJS({
|
|
844
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js"(exports, module) {
|
|
845
|
-
"use strict";
|
|
846
|
-
var Polynomial = require_polynomial();
|
|
847
|
-
function ReedSolomonEncoder(degree) {
|
|
848
|
-
this.genPoly = void 0;
|
|
849
|
-
this.degree = degree;
|
|
850
|
-
if (this.degree) this.initialize(this.degree);
|
|
851
|
-
}
|
|
852
|
-
ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
|
|
853
|
-
this.degree = degree;
|
|
854
|
-
this.genPoly = Polynomial.generateECPolynomial(this.degree);
|
|
855
|
-
};
|
|
856
|
-
ReedSolomonEncoder.prototype.encode = function encode(data) {
|
|
857
|
-
if (!this.genPoly) {
|
|
858
|
-
throw new Error("Encoder not initialized");
|
|
859
|
-
}
|
|
860
|
-
const paddedData = new Uint8Array(data.length + this.degree);
|
|
861
|
-
paddedData.set(data);
|
|
862
|
-
const remainder = Polynomial.mod(paddedData, this.genPoly);
|
|
863
|
-
const start2 = this.degree - remainder.length;
|
|
864
|
-
if (start2 > 0) {
|
|
865
|
-
const buff = new Uint8Array(this.degree);
|
|
866
|
-
buff.set(remainder, start2);
|
|
867
|
-
return buff;
|
|
868
|
-
}
|
|
869
|
-
return remainder;
|
|
870
|
-
};
|
|
871
|
-
module.exports = ReedSolomonEncoder;
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js
|
|
876
|
-
var require_version_check = __commonJS({
|
|
877
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"(exports) {
|
|
878
|
-
"use strict";
|
|
879
|
-
exports.isValid = function isValid(version) {
|
|
880
|
-
return !isNaN(version) && version >= 1 && version <= 40;
|
|
881
|
-
};
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
|
|
885
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js
|
|
886
|
-
var require_regex = __commonJS({
|
|
887
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js"(exports) {
|
|
888
|
-
"use strict";
|
|
889
|
-
var numeric = "[0-9]+";
|
|
890
|
-
var alphanumeric = "[A-Z $%*+\\-./:]+";
|
|
891
|
-
var kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
|
|
892
|
-
kanji = kanji.replace(/u/g, "\\u");
|
|
893
|
-
var byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + ")(?:.|[\r\n]))+";
|
|
894
|
-
exports.KANJI = new RegExp(kanji, "g");
|
|
895
|
-
exports.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
|
|
896
|
-
exports.BYTE = new RegExp(byte, "g");
|
|
897
|
-
exports.NUMERIC = new RegExp(numeric, "g");
|
|
898
|
-
exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
|
|
899
|
-
var TEST_KANJI = new RegExp("^" + kanji + "$");
|
|
900
|
-
var TEST_NUMERIC = new RegExp("^" + numeric + "$");
|
|
901
|
-
var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
|
|
902
|
-
exports.testKanji = function testKanji(str) {
|
|
903
|
-
return TEST_KANJI.test(str);
|
|
904
|
-
};
|
|
905
|
-
exports.testNumeric = function testNumeric(str) {
|
|
906
|
-
return TEST_NUMERIC.test(str);
|
|
907
|
-
};
|
|
908
|
-
exports.testAlphanumeric = function testAlphanumeric(str) {
|
|
909
|
-
return TEST_ALPHANUMERIC.test(str);
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
});
|
|
913
|
-
|
|
914
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js
|
|
915
|
-
var require_mode = __commonJS({
|
|
916
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"(exports) {
|
|
917
|
-
"use strict";
|
|
918
|
-
var VersionCheck = require_version_check();
|
|
919
|
-
var Regex = require_regex();
|
|
920
|
-
exports.NUMERIC = {
|
|
921
|
-
id: "Numeric",
|
|
922
|
-
bit: 1 << 0,
|
|
923
|
-
ccBits: [10, 12, 14]
|
|
924
|
-
};
|
|
925
|
-
exports.ALPHANUMERIC = {
|
|
926
|
-
id: "Alphanumeric",
|
|
927
|
-
bit: 1 << 1,
|
|
928
|
-
ccBits: [9, 11, 13]
|
|
929
|
-
};
|
|
930
|
-
exports.BYTE = {
|
|
931
|
-
id: "Byte",
|
|
932
|
-
bit: 1 << 2,
|
|
933
|
-
ccBits: [8, 16, 16]
|
|
934
|
-
};
|
|
935
|
-
exports.KANJI = {
|
|
936
|
-
id: "Kanji",
|
|
937
|
-
bit: 1 << 3,
|
|
938
|
-
ccBits: [8, 10, 12]
|
|
939
|
-
};
|
|
940
|
-
exports.MIXED = {
|
|
941
|
-
bit: -1
|
|
942
|
-
};
|
|
943
|
-
exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
|
|
944
|
-
if (!mode.ccBits) throw new Error("Invalid mode: " + mode);
|
|
945
|
-
if (!VersionCheck.isValid(version)) {
|
|
946
|
-
throw new Error("Invalid version: " + version);
|
|
947
|
-
}
|
|
948
|
-
if (version >= 1 && version < 10) return mode.ccBits[0];
|
|
949
|
-
else if (version < 27) return mode.ccBits[1];
|
|
950
|
-
return mode.ccBits[2];
|
|
951
|
-
};
|
|
952
|
-
exports.getBestModeForData = function getBestModeForData(dataStr) {
|
|
953
|
-
if (Regex.testNumeric(dataStr)) return exports.NUMERIC;
|
|
954
|
-
else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;
|
|
955
|
-
else if (Regex.testKanji(dataStr)) return exports.KANJI;
|
|
956
|
-
else return exports.BYTE;
|
|
957
|
-
};
|
|
958
|
-
exports.toString = function toString(mode) {
|
|
959
|
-
if (mode && mode.id) return mode.id;
|
|
960
|
-
throw new Error("Invalid mode");
|
|
961
|
-
};
|
|
962
|
-
exports.isValid = function isValid(mode) {
|
|
963
|
-
return mode && mode.bit && mode.ccBits;
|
|
964
|
-
};
|
|
965
|
-
function fromString(string) {
|
|
966
|
-
if (typeof string !== "string") {
|
|
967
|
-
throw new Error("Param is not a string");
|
|
968
|
-
}
|
|
969
|
-
const lcStr = string.toLowerCase();
|
|
970
|
-
switch (lcStr) {
|
|
971
|
-
case "numeric":
|
|
972
|
-
return exports.NUMERIC;
|
|
973
|
-
case "alphanumeric":
|
|
974
|
-
return exports.ALPHANUMERIC;
|
|
975
|
-
case "kanji":
|
|
976
|
-
return exports.KANJI;
|
|
977
|
-
case "byte":
|
|
978
|
-
return exports.BYTE;
|
|
979
|
-
default:
|
|
980
|
-
throw new Error("Unknown mode: " + string);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
exports.from = function from(value, defaultValue) {
|
|
984
|
-
if (exports.isValid(value)) {
|
|
985
|
-
return value;
|
|
986
|
-
}
|
|
987
|
-
try {
|
|
988
|
-
return fromString(value);
|
|
989
|
-
} catch (e) {
|
|
990
|
-
return defaultValue;
|
|
991
|
-
}
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
|
|
996
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js
|
|
997
|
-
var require_version = __commonJS({
|
|
998
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js"(exports) {
|
|
999
|
-
"use strict";
|
|
1000
|
-
var Utils = require_utils();
|
|
1001
|
-
var ECCode = require_error_correction_code();
|
|
1002
|
-
var ECLevel = require_error_correction_level();
|
|
1003
|
-
var Mode = require_mode();
|
|
1004
|
-
var VersionCheck = require_version_check();
|
|
1005
|
-
var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
|
|
1006
|
-
var G18_BCH = Utils.getBCHDigit(G18);
|
|
1007
|
-
function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
|
|
1008
|
-
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
1009
|
-
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
|
|
1010
|
-
return currentVersion;
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
return void 0;
|
|
1014
|
-
}
|
|
1015
|
-
function getReservedBitsCount(mode, version) {
|
|
1016
|
-
return Mode.getCharCountIndicator(mode, version) + 4;
|
|
1017
|
-
}
|
|
1018
|
-
function getTotalBitsFromDataArray(segments, version) {
|
|
1019
|
-
let totalBits = 0;
|
|
1020
|
-
segments.forEach(function(data) {
|
|
1021
|
-
const reservedBits = getReservedBitsCount(data.mode, version);
|
|
1022
|
-
totalBits += reservedBits + data.getBitsLength();
|
|
1023
|
-
});
|
|
1024
|
-
return totalBits;
|
|
1025
|
-
}
|
|
1026
|
-
function getBestVersionForMixedData(segments, errorCorrectionLevel) {
|
|
1027
|
-
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
1028
|
-
const length = getTotalBitsFromDataArray(segments, currentVersion);
|
|
1029
|
-
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
|
|
1030
|
-
return currentVersion;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
return void 0;
|
|
1034
|
-
}
|
|
1035
|
-
exports.from = function from(value, defaultValue) {
|
|
1036
|
-
if (VersionCheck.isValid(value)) {
|
|
1037
|
-
return parseInt(value, 10);
|
|
1038
|
-
}
|
|
1039
|
-
return defaultValue;
|
|
1040
|
-
};
|
|
1041
|
-
exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
|
|
1042
|
-
if (!VersionCheck.isValid(version)) {
|
|
1043
|
-
throw new Error("Invalid QR Code version");
|
|
1044
|
-
}
|
|
1045
|
-
if (typeof mode === "undefined") mode = Mode.BYTE;
|
|
1046
|
-
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1047
|
-
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1048
|
-
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
1049
|
-
if (mode === Mode.MIXED) return dataTotalCodewordsBits;
|
|
1050
|
-
const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
|
|
1051
|
-
switch (mode) {
|
|
1052
|
-
case Mode.NUMERIC:
|
|
1053
|
-
return Math.floor(usableBits / 10 * 3);
|
|
1054
|
-
case Mode.ALPHANUMERIC:
|
|
1055
|
-
return Math.floor(usableBits / 11 * 2);
|
|
1056
|
-
case Mode.KANJI:
|
|
1057
|
-
return Math.floor(usableBits / 13);
|
|
1058
|
-
case Mode.BYTE:
|
|
1059
|
-
default:
|
|
1060
|
-
return Math.floor(usableBits / 8);
|
|
1061
|
-
}
|
|
1062
|
-
};
|
|
1063
|
-
exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
|
|
1064
|
-
let seg;
|
|
1065
|
-
const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
|
|
1066
|
-
if (Array.isArray(data)) {
|
|
1067
|
-
if (data.length > 1) {
|
|
1068
|
-
return getBestVersionForMixedData(data, ecl);
|
|
1069
|
-
}
|
|
1070
|
-
if (data.length === 0) {
|
|
1071
|
-
return 1;
|
|
1072
|
-
}
|
|
1073
|
-
seg = data[0];
|
|
1074
|
-
} else {
|
|
1075
|
-
seg = data;
|
|
1076
|
-
}
|
|
1077
|
-
return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
|
|
1078
|
-
};
|
|
1079
|
-
exports.getEncodedBits = function getEncodedBits(version) {
|
|
1080
|
-
if (!VersionCheck.isValid(version) || version < 7) {
|
|
1081
|
-
throw new Error("Invalid QR Code version");
|
|
1082
|
-
}
|
|
1083
|
-
let d4 = version << 12;
|
|
1084
|
-
while (Utils.getBCHDigit(d4) - G18_BCH >= 0) {
|
|
1085
|
-
d4 ^= G18 << Utils.getBCHDigit(d4) - G18_BCH;
|
|
1086
|
-
}
|
|
1087
|
-
return version << 12 | d4;
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
});
|
|
1091
|
-
|
|
1092
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js
|
|
1093
|
-
var require_format_info = __commonJS({
|
|
1094
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js"(exports) {
|
|
1095
|
-
"use strict";
|
|
1096
|
-
var Utils = require_utils();
|
|
1097
|
-
var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
|
|
1098
|
-
var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
|
|
1099
|
-
var G15_BCH = Utils.getBCHDigit(G15);
|
|
1100
|
-
exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
|
|
1101
|
-
const data = errorCorrectionLevel.bit << 3 | mask;
|
|
1102
|
-
let d4 = data << 10;
|
|
1103
|
-
while (Utils.getBCHDigit(d4) - G15_BCH >= 0) {
|
|
1104
|
-
d4 ^= G15 << Utils.getBCHDigit(d4) - G15_BCH;
|
|
1105
|
-
}
|
|
1106
|
-
return (data << 10 | d4) ^ G15_MASK;
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1110
|
-
|
|
1111
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js
|
|
1112
|
-
var require_numeric_data = __commonJS({
|
|
1113
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js"(exports, module) {
|
|
1114
|
-
"use strict";
|
|
1115
|
-
var Mode = require_mode();
|
|
1116
|
-
function NumericData(data) {
|
|
1117
|
-
this.mode = Mode.NUMERIC;
|
|
1118
|
-
this.data = data.toString();
|
|
1119
|
-
}
|
|
1120
|
-
NumericData.getBitsLength = function getBitsLength(length) {
|
|
1121
|
-
return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
|
|
1122
|
-
};
|
|
1123
|
-
NumericData.prototype.getLength = function getLength() {
|
|
1124
|
-
return this.data.length;
|
|
1125
|
-
};
|
|
1126
|
-
NumericData.prototype.getBitsLength = function getBitsLength() {
|
|
1127
|
-
return NumericData.getBitsLength(this.data.length);
|
|
1128
|
-
};
|
|
1129
|
-
NumericData.prototype.write = function write(bitBuffer) {
|
|
1130
|
-
let i2, group, value;
|
|
1131
|
-
for (i2 = 0; i2 + 3 <= this.data.length; i2 += 3) {
|
|
1132
|
-
group = this.data.substr(i2, 3);
|
|
1133
|
-
value = parseInt(group, 10);
|
|
1134
|
-
bitBuffer.put(value, 10);
|
|
1135
|
-
}
|
|
1136
|
-
const remainingNum = this.data.length - i2;
|
|
1137
|
-
if (remainingNum > 0) {
|
|
1138
|
-
group = this.data.substr(i2);
|
|
1139
|
-
value = parseInt(group, 10);
|
|
1140
|
-
bitBuffer.put(value, remainingNum * 3 + 1);
|
|
1141
|
-
}
|
|
1142
|
-
};
|
|
1143
|
-
module.exports = NumericData;
|
|
1144
|
-
}
|
|
1145
|
-
});
|
|
1146
|
-
|
|
1147
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js
|
|
1148
|
-
var require_alphanumeric_data = __commonJS({
|
|
1149
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js"(exports, module) {
|
|
1150
|
-
"use strict";
|
|
1151
|
-
var Mode = require_mode();
|
|
1152
|
-
var ALPHA_NUM_CHARS = [
|
|
1153
|
-
"0",
|
|
1154
|
-
"1",
|
|
1155
|
-
"2",
|
|
1156
|
-
"3",
|
|
1157
|
-
"4",
|
|
1158
|
-
"5",
|
|
1159
|
-
"6",
|
|
1160
|
-
"7",
|
|
1161
|
-
"8",
|
|
1162
|
-
"9",
|
|
1163
|
-
"A",
|
|
1164
|
-
"B",
|
|
1165
|
-
"C",
|
|
1166
|
-
"D",
|
|
1167
|
-
"E",
|
|
1168
|
-
"F",
|
|
1169
|
-
"G",
|
|
1170
|
-
"H",
|
|
1171
|
-
"I",
|
|
1172
|
-
"J",
|
|
1173
|
-
"K",
|
|
1174
|
-
"L",
|
|
1175
|
-
"M",
|
|
1176
|
-
"N",
|
|
1177
|
-
"O",
|
|
1178
|
-
"P",
|
|
1179
|
-
"Q",
|
|
1180
|
-
"R",
|
|
1181
|
-
"S",
|
|
1182
|
-
"T",
|
|
1183
|
-
"U",
|
|
1184
|
-
"V",
|
|
1185
|
-
"W",
|
|
1186
|
-
"X",
|
|
1187
|
-
"Y",
|
|
1188
|
-
"Z",
|
|
1189
|
-
" ",
|
|
1190
|
-
"$",
|
|
1191
|
-
"%",
|
|
1192
|
-
"*",
|
|
1193
|
-
"+",
|
|
1194
|
-
"-",
|
|
1195
|
-
".",
|
|
1196
|
-
"/",
|
|
1197
|
-
":"
|
|
1198
|
-
];
|
|
1199
|
-
function AlphanumericData(data) {
|
|
1200
|
-
this.mode = Mode.ALPHANUMERIC;
|
|
1201
|
-
this.data = data;
|
|
1202
|
-
}
|
|
1203
|
-
AlphanumericData.getBitsLength = function getBitsLength(length) {
|
|
1204
|
-
return 11 * Math.floor(length / 2) + 6 * (length % 2);
|
|
1205
|
-
};
|
|
1206
|
-
AlphanumericData.prototype.getLength = function getLength() {
|
|
1207
|
-
return this.data.length;
|
|
1208
|
-
};
|
|
1209
|
-
AlphanumericData.prototype.getBitsLength = function getBitsLength() {
|
|
1210
|
-
return AlphanumericData.getBitsLength(this.data.length);
|
|
1211
|
-
};
|
|
1212
|
-
AlphanumericData.prototype.write = function write(bitBuffer) {
|
|
1213
|
-
let i2;
|
|
1214
|
-
for (i2 = 0; i2 + 2 <= this.data.length; i2 += 2) {
|
|
1215
|
-
let value = ALPHA_NUM_CHARS.indexOf(this.data[i2]) * 45;
|
|
1216
|
-
value += ALPHA_NUM_CHARS.indexOf(this.data[i2 + 1]);
|
|
1217
|
-
bitBuffer.put(value, 11);
|
|
1218
|
-
}
|
|
1219
|
-
if (this.data.length % 2) {
|
|
1220
|
-
bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i2]), 6);
|
|
1221
|
-
}
|
|
1222
|
-
};
|
|
1223
|
-
module.exports = AlphanumericData;
|
|
1224
|
-
}
|
|
1225
|
-
});
|
|
1226
|
-
|
|
1227
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js
|
|
1228
|
-
var require_byte_data = __commonJS({
|
|
1229
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js"(exports, module) {
|
|
1230
|
-
"use strict";
|
|
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 i2 = 0, l2 = this.data.length; i2 < l2; i2++) {
|
|
1251
|
-
bitBuffer.put(this.data[i2], 8);
|
|
1252
|
-
}
|
|
1253
|
-
};
|
|
1254
|
-
module.exports = ByteData;
|
|
1255
|
-
}
|
|
1256
|
-
});
|
|
1257
|
-
|
|
1258
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js
|
|
1259
|
-
var require_kanji_data = __commonJS({
|
|
1260
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js"(exports, module) {
|
|
1261
|
-
"use strict";
|
|
1262
|
-
var Mode = require_mode();
|
|
1263
|
-
var Utils = require_utils();
|
|
1264
|
-
function KanjiData(data) {
|
|
1265
|
-
this.mode = Mode.KANJI;
|
|
1266
|
-
this.data = data;
|
|
1267
|
-
}
|
|
1268
|
-
KanjiData.getBitsLength = function getBitsLength(length) {
|
|
1269
|
-
return length * 13;
|
|
1270
|
-
};
|
|
1271
|
-
KanjiData.prototype.getLength = function getLength() {
|
|
1272
|
-
return this.data.length;
|
|
1273
|
-
};
|
|
1274
|
-
KanjiData.prototype.getBitsLength = function getBitsLength() {
|
|
1275
|
-
return KanjiData.getBitsLength(this.data.length);
|
|
1276
|
-
};
|
|
1277
|
-
KanjiData.prototype.write = function(bitBuffer) {
|
|
1278
|
-
let i2;
|
|
1279
|
-
for (i2 = 0; i2 < this.data.length; i2++) {
|
|
1280
|
-
let value = Utils.toSJIS(this.data[i2]);
|
|
1281
|
-
if (value >= 33088 && value <= 40956) {
|
|
1282
|
-
value -= 33088;
|
|
1283
|
-
} else if (value >= 57408 && value <= 60351) {
|
|
1284
|
-
value -= 49472;
|
|
1285
|
-
} else {
|
|
1286
|
-
throw new Error(
|
|
1287
|
-
"Invalid SJIS character: " + this.data[i2] + "\nMake sure your charset is UTF-8"
|
|
1288
|
-
);
|
|
1289
|
-
}
|
|
1290
|
-
value = (value >>> 8 & 255) * 192 + (value & 255);
|
|
1291
|
-
bitBuffer.put(value, 13);
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
module.exports = KanjiData;
|
|
1295
|
-
}
|
|
1296
|
-
});
|
|
1297
|
-
|
|
1298
|
-
// ../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js
|
|
1299
|
-
var require_dijkstra = __commonJS({
|
|
1300
|
-
"../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js"(exports, module) {
|
|
1301
|
-
"use strict";
|
|
1302
|
-
var dijkstra = {
|
|
1303
|
-
single_source_shortest_paths: function(graph, s, d4) {
|
|
1304
|
-
var predecessors = {};
|
|
1305
|
-
var costs = {};
|
|
1306
|
-
costs[s] = 0;
|
|
1307
|
-
var open = dijkstra.PriorityQueue.make();
|
|
1308
|
-
open.push(s, 0);
|
|
1309
|
-
var closest, u, v3, 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;
|
|
1310
|
-
while (!open.empty()) {
|
|
1311
|
-
closest = open.pop();
|
|
1312
|
-
u = closest.value;
|
|
1313
|
-
cost_of_s_to_u = closest.cost;
|
|
1314
|
-
adjacent_nodes = graph[u] || {};
|
|
1315
|
-
for (v3 in adjacent_nodes) {
|
|
1316
|
-
if (adjacent_nodes.hasOwnProperty(v3)) {
|
|
1317
|
-
cost_of_e = adjacent_nodes[v3];
|
|
1318
|
-
cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
|
|
1319
|
-
cost_of_s_to_v = costs[v3];
|
|
1320
|
-
first_visit = typeof costs[v3] === "undefined";
|
|
1321
|
-
if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
|
|
1322
|
-
costs[v3] = cost_of_s_to_u_plus_cost_of_e;
|
|
1323
|
-
open.push(v3, cost_of_s_to_u_plus_cost_of_e);
|
|
1324
|
-
predecessors[v3] = u;
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
if (typeof d4 !== "undefined" && typeof costs[d4] === "undefined") {
|
|
1330
|
-
var msg = ["Could not find a path from ", s, " to ", d4, "."].join("");
|
|
1331
|
-
throw new Error(msg);
|
|
1332
|
-
}
|
|
1333
|
-
return predecessors;
|
|
1334
|
-
},
|
|
1335
|
-
extract_shortest_path_from_predecessor_list: function(predecessors, d4) {
|
|
1336
|
-
var nodes = [];
|
|
1337
|
-
var u = d4;
|
|
1338
|
-
var predecessor;
|
|
1339
|
-
while (u) {
|
|
1340
|
-
nodes.push(u);
|
|
1341
|
-
predecessor = predecessors[u];
|
|
1342
|
-
u = predecessors[u];
|
|
1343
|
-
}
|
|
1344
|
-
nodes.reverse();
|
|
1345
|
-
return nodes;
|
|
1346
|
-
},
|
|
1347
|
-
find_path: function(graph, s, d4) {
|
|
1348
|
-
var predecessors = dijkstra.single_source_shortest_paths(graph, s, d4);
|
|
1349
|
-
return dijkstra.extract_shortest_path_from_predecessor_list(
|
|
1350
|
-
predecessors,
|
|
1351
|
-
d4
|
|
1352
|
-
);
|
|
1353
|
-
},
|
|
1354
|
-
/**
|
|
1355
|
-
* A very naive priority queue implementation.
|
|
1356
|
-
*/
|
|
1357
|
-
PriorityQueue: {
|
|
1358
|
-
make: function(opts) {
|
|
1359
|
-
var T3 = dijkstra.PriorityQueue, t2 = {}, key;
|
|
1360
|
-
opts = opts || {};
|
|
1361
|
-
for (key in T3) {
|
|
1362
|
-
if (T3.hasOwnProperty(key)) {
|
|
1363
|
-
t2[key] = T3[key];
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
t2.queue = [];
|
|
1367
|
-
t2.sorter = opts.sorter || T3.default_sorter;
|
|
1368
|
-
return t2;
|
|
1369
|
-
},
|
|
1370
|
-
default_sorter: function(a2, b3) {
|
|
1371
|
-
return a2.cost - b3.cost;
|
|
1372
|
-
},
|
|
1373
|
-
/**
|
|
1374
|
-
* Add a new item to the queue and ensure the highest priority element
|
|
1375
|
-
* is at the front of the queue.
|
|
1376
|
-
*/
|
|
1377
|
-
push: function(value, cost) {
|
|
1378
|
-
var item = { value, cost };
|
|
1379
|
-
this.queue.push(item);
|
|
1380
|
-
this.queue.sort(this.sorter);
|
|
1381
|
-
},
|
|
1382
|
-
/**
|
|
1383
|
-
* Return the highest priority element in the queue.
|
|
1384
|
-
*/
|
|
1385
|
-
pop: function() {
|
|
1386
|
-
return this.queue.shift();
|
|
1387
|
-
},
|
|
1388
|
-
empty: function() {
|
|
1389
|
-
return this.queue.length === 0;
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
};
|
|
1393
|
-
if (typeof module !== "undefined") {
|
|
1394
|
-
module.exports = dijkstra;
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
|
|
1399
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js
|
|
1400
|
-
var require_segments = __commonJS({
|
|
1401
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js"(exports) {
|
|
1402
|
-
"use strict";
|
|
1403
|
-
var Mode = require_mode();
|
|
1404
|
-
var NumericData = require_numeric_data();
|
|
1405
|
-
var AlphanumericData = require_alphanumeric_data();
|
|
1406
|
-
var ByteData = require_byte_data();
|
|
1407
|
-
var KanjiData = require_kanji_data();
|
|
1408
|
-
var Regex = require_regex();
|
|
1409
|
-
var Utils = require_utils();
|
|
1410
|
-
var dijkstra = require_dijkstra();
|
|
1411
|
-
function getStringByteLength(str) {
|
|
1412
|
-
return unescape(encodeURIComponent(str)).length;
|
|
1413
|
-
}
|
|
1414
|
-
function getSegments(regex, mode, str) {
|
|
1415
|
-
const segments = [];
|
|
1416
|
-
let result;
|
|
1417
|
-
while ((result = regex.exec(str)) !== null) {
|
|
1418
|
-
segments.push({
|
|
1419
|
-
data: result[0],
|
|
1420
|
-
index: result.index,
|
|
1421
|
-
mode,
|
|
1422
|
-
length: result[0].length
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
return segments;
|
|
1426
|
-
}
|
|
1427
|
-
function getSegmentsFromString(dataStr) {
|
|
1428
|
-
const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
|
|
1429
|
-
const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
|
|
1430
|
-
let byteSegs;
|
|
1431
|
-
let kanjiSegs;
|
|
1432
|
-
if (Utils.isKanjiModeEnabled()) {
|
|
1433
|
-
byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
|
|
1434
|
-
kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
|
|
1435
|
-
} else {
|
|
1436
|
-
byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
|
|
1437
|
-
kanjiSegs = [];
|
|
1438
|
-
}
|
|
1439
|
-
const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
|
|
1440
|
-
return segs.sort(function(s1, s2) {
|
|
1441
|
-
return s1.index - s2.index;
|
|
1442
|
-
}).map(function(obj) {
|
|
1443
|
-
return {
|
|
1444
|
-
data: obj.data,
|
|
1445
|
-
mode: obj.mode,
|
|
1446
|
-
length: obj.length
|
|
1447
|
-
};
|
|
1448
|
-
});
|
|
1449
|
-
}
|
|
1450
|
-
function getSegmentBitsLength(length, mode) {
|
|
1451
|
-
switch (mode) {
|
|
1452
|
-
case Mode.NUMERIC:
|
|
1453
|
-
return NumericData.getBitsLength(length);
|
|
1454
|
-
case Mode.ALPHANUMERIC:
|
|
1455
|
-
return AlphanumericData.getBitsLength(length);
|
|
1456
|
-
case Mode.KANJI:
|
|
1457
|
-
return KanjiData.getBitsLength(length);
|
|
1458
|
-
case Mode.BYTE:
|
|
1459
|
-
return ByteData.getBitsLength(length);
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
function mergeSegments(segs) {
|
|
1463
|
-
return segs.reduce(function(acc, curr) {
|
|
1464
|
-
const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
|
|
1465
|
-
if (prevSeg && prevSeg.mode === curr.mode) {
|
|
1466
|
-
acc[acc.length - 1].data += curr.data;
|
|
1467
|
-
return acc;
|
|
1468
|
-
}
|
|
1469
|
-
acc.push(curr);
|
|
1470
|
-
return acc;
|
|
1471
|
-
}, []);
|
|
1472
|
-
}
|
|
1473
|
-
function buildNodes(segs) {
|
|
1474
|
-
const nodes = [];
|
|
1475
|
-
for (let i2 = 0; i2 < segs.length; i2++) {
|
|
1476
|
-
const seg = segs[i2];
|
|
1477
|
-
switch (seg.mode) {
|
|
1478
|
-
case Mode.NUMERIC:
|
|
1479
|
-
nodes.push([
|
|
1480
|
-
seg,
|
|
1481
|
-
{ data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
|
|
1482
|
-
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
1483
|
-
]);
|
|
1484
|
-
break;
|
|
1485
|
-
case Mode.ALPHANUMERIC:
|
|
1486
|
-
nodes.push([
|
|
1487
|
-
seg,
|
|
1488
|
-
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
1489
|
-
]);
|
|
1490
|
-
break;
|
|
1491
|
-
case Mode.KANJI:
|
|
1492
|
-
nodes.push([
|
|
1493
|
-
seg,
|
|
1494
|
-
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
1495
|
-
]);
|
|
1496
|
-
break;
|
|
1497
|
-
case Mode.BYTE:
|
|
1498
|
-
nodes.push([
|
|
1499
|
-
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
1500
|
-
]);
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
return nodes;
|
|
1504
|
-
}
|
|
1505
|
-
function buildGraph(nodes, version) {
|
|
1506
|
-
const table = {};
|
|
1507
|
-
const graph = { start: {} };
|
|
1508
|
-
let prevNodeIds = ["start"];
|
|
1509
|
-
for (let i2 = 0; i2 < nodes.length; i2++) {
|
|
1510
|
-
const nodeGroup = nodes[i2];
|
|
1511
|
-
const currentNodeIds = [];
|
|
1512
|
-
for (let j = 0; j < nodeGroup.length; j++) {
|
|
1513
|
-
const node = nodeGroup[j];
|
|
1514
|
-
const key = "" + i2 + j;
|
|
1515
|
-
currentNodeIds.push(key);
|
|
1516
|
-
table[key] = { node, lastCount: 0 };
|
|
1517
|
-
graph[key] = {};
|
|
1518
|
-
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
1519
|
-
const prevNodeId = prevNodeIds[n];
|
|
1520
|
-
if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
|
|
1521
|
-
graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
|
|
1522
|
-
table[prevNodeId].lastCount += node.length;
|
|
1523
|
-
} else {
|
|
1524
|
-
if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
|
|
1525
|
-
graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
prevNodeIds = currentNodeIds;
|
|
1530
|
-
}
|
|
1531
|
-
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
1532
|
-
graph[prevNodeIds[n]].end = 0;
|
|
1533
|
-
}
|
|
1534
|
-
return { map: graph, table };
|
|
1535
|
-
}
|
|
1536
|
-
function buildSingleSegment(data, modesHint) {
|
|
1537
|
-
let mode;
|
|
1538
|
-
const bestMode = Mode.getBestModeForData(data);
|
|
1539
|
-
mode = Mode.from(modesHint, bestMode);
|
|
1540
|
-
if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
|
|
1541
|
-
throw new Error('"' + data + '" cannot be encoded with mode ' + Mode.toString(mode) + ".\n Suggested mode is: " + Mode.toString(bestMode));
|
|
1542
|
-
}
|
|
1543
|
-
if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
|
|
1544
|
-
mode = Mode.BYTE;
|
|
1545
|
-
}
|
|
1546
|
-
switch (mode) {
|
|
1547
|
-
case Mode.NUMERIC:
|
|
1548
|
-
return new NumericData(data);
|
|
1549
|
-
case Mode.ALPHANUMERIC:
|
|
1550
|
-
return new AlphanumericData(data);
|
|
1551
|
-
case Mode.KANJI:
|
|
1552
|
-
return new KanjiData(data);
|
|
1553
|
-
case Mode.BYTE:
|
|
1554
|
-
return new ByteData(data);
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
exports.fromArray = function fromArray(array) {
|
|
1558
|
-
return array.reduce(function(acc, seg) {
|
|
1559
|
-
if (typeof seg === "string") {
|
|
1560
|
-
acc.push(buildSingleSegment(seg, null));
|
|
1561
|
-
} else if (seg.data) {
|
|
1562
|
-
acc.push(buildSingleSegment(seg.data, seg.mode));
|
|
1563
|
-
}
|
|
1564
|
-
return acc;
|
|
1565
|
-
}, []);
|
|
1566
|
-
};
|
|
1567
|
-
exports.fromString = function fromString(data, version) {
|
|
1568
|
-
const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
|
|
1569
|
-
const nodes = buildNodes(segs);
|
|
1570
|
-
const graph = buildGraph(nodes, version);
|
|
1571
|
-
const path = dijkstra.find_path(graph.map, "start", "end");
|
|
1572
|
-
const optimizedSegs = [];
|
|
1573
|
-
for (let i2 = 1; i2 < path.length - 1; i2++) {
|
|
1574
|
-
optimizedSegs.push(graph.table[path[i2]].node);
|
|
1575
|
-
}
|
|
1576
|
-
return exports.fromArray(mergeSegments(optimizedSegs));
|
|
1577
|
-
};
|
|
1578
|
-
exports.rawSplit = function rawSplit(data) {
|
|
1579
|
-
return exports.fromArray(
|
|
1580
|
-
getSegmentsFromString(data, Utils.isKanjiModeEnabled())
|
|
1581
|
-
);
|
|
1582
|
-
};
|
|
1583
|
-
}
|
|
1584
|
-
});
|
|
1585
|
-
|
|
1586
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js
|
|
1587
|
-
var require_qrcode = __commonJS({
|
|
1588
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"(exports) {
|
|
1589
|
-
"use strict";
|
|
1590
|
-
var Utils = require_utils();
|
|
1591
|
-
var ECLevel = require_error_correction_level();
|
|
1592
|
-
var BitBuffer = require_bit_buffer();
|
|
1593
|
-
var BitMatrix = require_bit_matrix();
|
|
1594
|
-
var AlignmentPattern = require_alignment_pattern();
|
|
1595
|
-
var FinderPattern = require_finder_pattern();
|
|
1596
|
-
var MaskPattern = require_mask_pattern();
|
|
1597
|
-
var ECCode = require_error_correction_code();
|
|
1598
|
-
var ReedSolomonEncoder = require_reed_solomon_encoder();
|
|
1599
|
-
var Version = require_version();
|
|
1600
|
-
var FormatInfo = require_format_info();
|
|
1601
|
-
var Mode = require_mode();
|
|
1602
|
-
var Segments = require_segments();
|
|
1603
|
-
function setupFinderPattern(matrix, version) {
|
|
1604
|
-
const size = matrix.size;
|
|
1605
|
-
const pos = FinderPattern.getPositions(version);
|
|
1606
|
-
for (let i2 = 0; i2 < pos.length; i2++) {
|
|
1607
|
-
const row = pos[i2][0];
|
|
1608
|
-
const col = pos[i2][1];
|
|
1609
|
-
for (let r2 = -1; r2 <= 7; r2++) {
|
|
1610
|
-
if (row + r2 <= -1 || size <= row + r2) continue;
|
|
1611
|
-
for (let c3 = -1; c3 <= 7; c3++) {
|
|
1612
|
-
if (col + c3 <= -1 || size <= col + c3) continue;
|
|
1613
|
-
if (r2 >= 0 && r2 <= 6 && (c3 === 0 || c3 === 6) || c3 >= 0 && c3 <= 6 && (r2 === 0 || r2 === 6) || r2 >= 2 && r2 <= 4 && c3 >= 2 && c3 <= 4) {
|
|
1614
|
-
matrix.set(row + r2, col + c3, true, true);
|
|
1615
|
-
} else {
|
|
1616
|
-
matrix.set(row + r2, col + c3, false, true);
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
function setupTimingPattern(matrix) {
|
|
1623
|
-
const size = matrix.size;
|
|
1624
|
-
for (let r2 = 8; r2 < size - 8; r2++) {
|
|
1625
|
-
const value = r2 % 2 === 0;
|
|
1626
|
-
matrix.set(r2, 6, value, true);
|
|
1627
|
-
matrix.set(6, r2, value, true);
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
function setupAlignmentPattern(matrix, version) {
|
|
1631
|
-
const pos = AlignmentPattern.getPositions(version);
|
|
1632
|
-
for (let i2 = 0; i2 < pos.length; i2++) {
|
|
1633
|
-
const row = pos[i2][0];
|
|
1634
|
-
const col = pos[i2][1];
|
|
1635
|
-
for (let r2 = -2; r2 <= 2; r2++) {
|
|
1636
|
-
for (let c3 = -2; c3 <= 2; c3++) {
|
|
1637
|
-
if (r2 === -2 || r2 === 2 || c3 === -2 || c3 === 2 || r2 === 0 && c3 === 0) {
|
|
1638
|
-
matrix.set(row + r2, col + c3, true, true);
|
|
1639
|
-
} else {
|
|
1640
|
-
matrix.set(row + r2, col + c3, false, true);
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
function setupVersionInfo(matrix, version) {
|
|
1647
|
-
const size = matrix.size;
|
|
1648
|
-
const bits = Version.getEncodedBits(version);
|
|
1649
|
-
let row, col, mod;
|
|
1650
|
-
for (let i2 = 0; i2 < 18; i2++) {
|
|
1651
|
-
row = Math.floor(i2 / 3);
|
|
1652
|
-
col = i2 % 3 + size - 8 - 3;
|
|
1653
|
-
mod = (bits >> i2 & 1) === 1;
|
|
1654
|
-
matrix.set(row, col, mod, true);
|
|
1655
|
-
matrix.set(col, row, mod, true);
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
|
|
1659
|
-
const size = matrix.size;
|
|
1660
|
-
const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
|
|
1661
|
-
let i2, mod;
|
|
1662
|
-
for (i2 = 0; i2 < 15; i2++) {
|
|
1663
|
-
mod = (bits >> i2 & 1) === 1;
|
|
1664
|
-
if (i2 < 6) {
|
|
1665
|
-
matrix.set(i2, 8, mod, true);
|
|
1666
|
-
} else if (i2 < 8) {
|
|
1667
|
-
matrix.set(i2 + 1, 8, mod, true);
|
|
1668
|
-
} else {
|
|
1669
|
-
matrix.set(size - 15 + i2, 8, mod, true);
|
|
1670
|
-
}
|
|
1671
|
-
if (i2 < 8) {
|
|
1672
|
-
matrix.set(8, size - i2 - 1, mod, true);
|
|
1673
|
-
} else if (i2 < 9) {
|
|
1674
|
-
matrix.set(8, 15 - i2 - 1 + 1, mod, true);
|
|
1675
|
-
} else {
|
|
1676
|
-
matrix.set(8, 15 - i2 - 1, mod, true);
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
matrix.set(size - 8, 8, 1, true);
|
|
1680
|
-
}
|
|
1681
|
-
function setupData(matrix, data) {
|
|
1682
|
-
const size = matrix.size;
|
|
1683
|
-
let inc = -1;
|
|
1684
|
-
let row = size - 1;
|
|
1685
|
-
let bitIndex = 7;
|
|
1686
|
-
let byteIndex = 0;
|
|
1687
|
-
for (let col = size - 1; col > 0; col -= 2) {
|
|
1688
|
-
if (col === 6) col--;
|
|
1689
|
-
while (true) {
|
|
1690
|
-
for (let c3 = 0; c3 < 2; c3++) {
|
|
1691
|
-
if (!matrix.isReserved(row, col - c3)) {
|
|
1692
|
-
let dark = false;
|
|
1693
|
-
if (byteIndex < data.length) {
|
|
1694
|
-
dark = (data[byteIndex] >>> bitIndex & 1) === 1;
|
|
1695
|
-
}
|
|
1696
|
-
matrix.set(row, col - c3, dark);
|
|
1697
|
-
bitIndex--;
|
|
1698
|
-
if (bitIndex === -1) {
|
|
1699
|
-
byteIndex++;
|
|
1700
|
-
bitIndex = 7;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
row += inc;
|
|
1705
|
-
if (row < 0 || size <= row) {
|
|
1706
|
-
row -= inc;
|
|
1707
|
-
inc = -inc;
|
|
1708
|
-
break;
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
function createData(version, errorCorrectionLevel, segments) {
|
|
1714
|
-
const buffer = new BitBuffer();
|
|
1715
|
-
segments.forEach(function(data) {
|
|
1716
|
-
buffer.put(data.mode.bit, 4);
|
|
1717
|
-
buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
|
|
1718
|
-
data.write(buffer);
|
|
1719
|
-
});
|
|
1720
|
-
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1721
|
-
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1722
|
-
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
1723
|
-
if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
|
|
1724
|
-
buffer.put(0, 4);
|
|
1725
|
-
}
|
|
1726
|
-
while (buffer.getLengthInBits() % 8 !== 0) {
|
|
1727
|
-
buffer.putBit(0);
|
|
1728
|
-
}
|
|
1729
|
-
const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
|
|
1730
|
-
for (let i2 = 0; i2 < remainingByte; i2++) {
|
|
1731
|
-
buffer.put(i2 % 2 ? 17 : 236, 8);
|
|
1732
|
-
}
|
|
1733
|
-
return createCodewords(buffer, version, errorCorrectionLevel);
|
|
1734
|
-
}
|
|
1735
|
-
function createCodewords(bitBuffer, version, errorCorrectionLevel) {
|
|
1736
|
-
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1737
|
-
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1738
|
-
const dataTotalCodewords = totalCodewords - ecTotalCodewords;
|
|
1739
|
-
const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
|
|
1740
|
-
const blocksInGroup2 = totalCodewords % ecTotalBlocks;
|
|
1741
|
-
const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
|
|
1742
|
-
const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
|
|
1743
|
-
const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
|
|
1744
|
-
const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
|
|
1745
|
-
const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
|
|
1746
|
-
const rs = new ReedSolomonEncoder(ecCount);
|
|
1747
|
-
let offset = 0;
|
|
1748
|
-
const dcData = new Array(ecTotalBlocks);
|
|
1749
|
-
const ecData = new Array(ecTotalBlocks);
|
|
1750
|
-
let maxDataSize = 0;
|
|
1751
|
-
const buffer = new Uint8Array(bitBuffer.buffer);
|
|
1752
|
-
for (let b3 = 0; b3 < ecTotalBlocks; b3++) {
|
|
1753
|
-
const dataSize = b3 < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
|
|
1754
|
-
dcData[b3] = buffer.slice(offset, offset + dataSize);
|
|
1755
|
-
ecData[b3] = rs.encode(dcData[b3]);
|
|
1756
|
-
offset += dataSize;
|
|
1757
|
-
maxDataSize = Math.max(maxDataSize, dataSize);
|
|
1758
|
-
}
|
|
1759
|
-
const data = new Uint8Array(totalCodewords);
|
|
1760
|
-
let index = 0;
|
|
1761
|
-
let i2, r2;
|
|
1762
|
-
for (i2 = 0; i2 < maxDataSize; i2++) {
|
|
1763
|
-
for (r2 = 0; r2 < ecTotalBlocks; r2++) {
|
|
1764
|
-
if (i2 < dcData[r2].length) {
|
|
1765
|
-
data[index++] = dcData[r2][i2];
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
for (i2 = 0; i2 < ecCount; i2++) {
|
|
1770
|
-
for (r2 = 0; r2 < ecTotalBlocks; r2++) {
|
|
1771
|
-
data[index++] = ecData[r2][i2];
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
return data;
|
|
1775
|
-
}
|
|
1776
|
-
function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
|
|
1777
|
-
let segments;
|
|
1778
|
-
if (Array.isArray(data)) {
|
|
1779
|
-
segments = Segments.fromArray(data);
|
|
1780
|
-
} else if (typeof data === "string") {
|
|
1781
|
-
let estimatedVersion = version;
|
|
1782
|
-
if (!estimatedVersion) {
|
|
1783
|
-
const rawSegments = Segments.rawSplit(data);
|
|
1784
|
-
estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
|
|
1785
|
-
}
|
|
1786
|
-
segments = Segments.fromString(data, estimatedVersion || 40);
|
|
1787
|
-
} else {
|
|
1788
|
-
throw new Error("Invalid data");
|
|
1789
|
-
}
|
|
1790
|
-
const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
|
|
1791
|
-
if (!bestVersion) {
|
|
1792
|
-
throw new Error("The amount of data is too big to be stored in a QR Code");
|
|
1793
|
-
}
|
|
1794
|
-
if (!version) {
|
|
1795
|
-
version = bestVersion;
|
|
1796
|
-
} else if (version < bestVersion) {
|
|
1797
|
-
throw new Error(
|
|
1798
|
-
"\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + bestVersion + ".\n"
|
|
1799
|
-
);
|
|
1800
|
-
}
|
|
1801
|
-
const dataBits = createData(version, errorCorrectionLevel, segments);
|
|
1802
|
-
const moduleCount = Utils.getSymbolSize(version);
|
|
1803
|
-
const modules = new BitMatrix(moduleCount);
|
|
1804
|
-
setupFinderPattern(modules, version);
|
|
1805
|
-
setupTimingPattern(modules);
|
|
1806
|
-
setupAlignmentPattern(modules, version);
|
|
1807
|
-
setupFormatInfo(modules, errorCorrectionLevel, 0);
|
|
1808
|
-
if (version >= 7) {
|
|
1809
|
-
setupVersionInfo(modules, version);
|
|
1810
|
-
}
|
|
1811
|
-
setupData(modules, dataBits);
|
|
1812
|
-
if (isNaN(maskPattern)) {
|
|
1813
|
-
maskPattern = MaskPattern.getBestMask(
|
|
1814
|
-
modules,
|
|
1815
|
-
setupFormatInfo.bind(null, modules, errorCorrectionLevel)
|
|
1816
|
-
);
|
|
1817
|
-
}
|
|
1818
|
-
MaskPattern.applyMask(maskPattern, modules);
|
|
1819
|
-
setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
|
|
1820
|
-
return {
|
|
1821
|
-
modules,
|
|
1822
|
-
version,
|
|
1823
|
-
errorCorrectionLevel,
|
|
1824
|
-
maskPattern,
|
|
1825
|
-
segments
|
|
1826
|
-
};
|
|
1827
|
-
}
|
|
1828
|
-
exports.create = function create(data, options) {
|
|
1829
|
-
if (typeof data === "undefined" || data === "") {
|
|
1830
|
-
throw new Error("No input text");
|
|
1831
|
-
}
|
|
1832
|
-
let errorCorrectionLevel = ECLevel.M;
|
|
1833
|
-
let version;
|
|
1834
|
-
let mask;
|
|
1835
|
-
if (typeof options !== "undefined") {
|
|
1836
|
-
errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
|
|
1837
|
-
version = Version.from(options.version);
|
|
1838
|
-
mask = MaskPattern.from(options.maskPattern);
|
|
1839
|
-
if (options.toSJISFunc) {
|
|
1840
|
-
Utils.setToSJISFunction(options.toSJISFunc);
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
return createSymbol(data, version, errorCorrectionLevel, mask);
|
|
1844
|
-
};
|
|
1845
|
-
}
|
|
1846
|
-
});
|
|
1847
|
-
|
|
1848
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js
|
|
1849
|
-
var require_chunkstream = __commonJS({
|
|
1850
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/chunkstream.js"(exports, module) {
|
|
1851
|
-
"use strict";
|
|
1852
|
-
var util = __require("util");
|
|
1853
|
-
var Stream = __require("stream");
|
|
1854
|
-
var ChunkStream = module.exports = function() {
|
|
1855
|
-
Stream.call(this);
|
|
1856
|
-
this._buffers = [];
|
|
1857
|
-
this._buffered = 0;
|
|
1858
|
-
this._reads = [];
|
|
1859
|
-
this._paused = false;
|
|
1860
|
-
this._encoding = "utf8";
|
|
1861
|
-
this.writable = true;
|
|
1862
|
-
};
|
|
1863
|
-
util.inherits(ChunkStream, Stream);
|
|
1864
|
-
ChunkStream.prototype.read = function(length, callback) {
|
|
1865
|
-
this._reads.push({
|
|
1866
|
-
length: Math.abs(length),
|
|
1867
|
-
// if length < 0 then at most this length
|
|
1868
|
-
allowLess: length < 0,
|
|
1869
|
-
func: callback
|
|
1870
|
-
});
|
|
1871
|
-
process.nextTick(
|
|
1872
|
-
function() {
|
|
1873
|
-
this._process();
|
|
1874
|
-
if (this._paused && this._reads && this._reads.length > 0) {
|
|
1875
|
-
this._paused = false;
|
|
1876
|
-
this.emit("drain");
|
|
1877
|
-
}
|
|
1878
|
-
}.bind(this)
|
|
1879
|
-
);
|
|
1880
|
-
};
|
|
1881
|
-
ChunkStream.prototype.write = function(data, encoding) {
|
|
1882
|
-
if (!this.writable) {
|
|
1883
|
-
this.emit("error", new Error("Stream not writable"));
|
|
1884
|
-
return false;
|
|
1885
|
-
}
|
|
1886
|
-
let dataBuffer;
|
|
1887
|
-
if (Buffer.isBuffer(data)) {
|
|
1888
|
-
dataBuffer = data;
|
|
1889
|
-
} else {
|
|
1890
|
-
dataBuffer = Buffer.from(data, encoding || this._encoding);
|
|
1891
|
-
}
|
|
1892
|
-
this._buffers.push(dataBuffer);
|
|
1893
|
-
this._buffered += dataBuffer.length;
|
|
1894
|
-
this._process();
|
|
1895
|
-
if (this._reads && this._reads.length === 0) {
|
|
1896
|
-
this._paused = true;
|
|
1897
|
-
}
|
|
1898
|
-
return this.writable && !this._paused;
|
|
1899
|
-
};
|
|
1900
|
-
ChunkStream.prototype.end = function(data, encoding) {
|
|
1901
|
-
if (data) {
|
|
1902
|
-
this.write(data, encoding);
|
|
1903
|
-
}
|
|
1904
|
-
this.writable = false;
|
|
1905
|
-
if (!this._buffers) {
|
|
1906
|
-
return;
|
|
1907
|
-
}
|
|
1908
|
-
if (this._buffers.length === 0) {
|
|
1909
|
-
this._end();
|
|
1910
|
-
} else {
|
|
1911
|
-
this._buffers.push(null);
|
|
1912
|
-
this._process();
|
|
1913
|
-
}
|
|
1914
|
-
};
|
|
1915
|
-
ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
|
|
1916
|
-
ChunkStream.prototype._end = function() {
|
|
1917
|
-
if (this._reads.length > 0) {
|
|
1918
|
-
this.emit("error", new Error("Unexpected end of input"));
|
|
1919
|
-
}
|
|
1920
|
-
this.destroy();
|
|
1921
|
-
};
|
|
1922
|
-
ChunkStream.prototype.destroy = function() {
|
|
1923
|
-
if (!this._buffers) {
|
|
1924
|
-
return;
|
|
1925
|
-
}
|
|
1926
|
-
this.writable = false;
|
|
1927
|
-
this._reads = null;
|
|
1928
|
-
this._buffers = null;
|
|
1929
|
-
this.emit("close");
|
|
1930
|
-
};
|
|
1931
|
-
ChunkStream.prototype._processReadAllowingLess = function(read) {
|
|
1932
|
-
this._reads.shift();
|
|
1933
|
-
let smallerBuf = this._buffers[0];
|
|
1934
|
-
if (smallerBuf.length > read.length) {
|
|
1935
|
-
this._buffered -= read.length;
|
|
1936
|
-
this._buffers[0] = smallerBuf.slice(read.length);
|
|
1937
|
-
read.func.call(this, smallerBuf.slice(0, read.length));
|
|
1938
|
-
} else {
|
|
1939
|
-
this._buffered -= smallerBuf.length;
|
|
1940
|
-
this._buffers.shift();
|
|
1941
|
-
read.func.call(this, smallerBuf);
|
|
1942
|
-
}
|
|
1943
|
-
};
|
|
1944
|
-
ChunkStream.prototype._processRead = function(read) {
|
|
1945
|
-
this._reads.shift();
|
|
1946
|
-
let pos = 0;
|
|
1947
|
-
let count = 0;
|
|
1948
|
-
let data = Buffer.alloc(read.length);
|
|
1949
|
-
while (pos < read.length) {
|
|
1950
|
-
let buf = this._buffers[count++];
|
|
1951
|
-
let len = Math.min(buf.length, read.length - pos);
|
|
1952
|
-
buf.copy(data, pos, 0, len);
|
|
1953
|
-
pos += len;
|
|
1954
|
-
if (len !== buf.length) {
|
|
1955
|
-
this._buffers[--count] = buf.slice(len);
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
if (count > 0) {
|
|
1959
|
-
this._buffers.splice(0, count);
|
|
1960
|
-
}
|
|
1961
|
-
this._buffered -= read.length;
|
|
1962
|
-
read.func.call(this, data);
|
|
1963
|
-
};
|
|
1964
|
-
ChunkStream.prototype._process = function() {
|
|
1965
|
-
try {
|
|
1966
|
-
while (this._buffered > 0 && this._reads && this._reads.length > 0) {
|
|
1967
|
-
let read = this._reads[0];
|
|
1968
|
-
if (read.allowLess) {
|
|
1969
|
-
this._processReadAllowingLess(read);
|
|
1970
|
-
} else if (this._buffered >= read.length) {
|
|
1971
|
-
this._processRead(read);
|
|
1972
|
-
} else {
|
|
1973
|
-
break;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
if (this._buffers && !this.writable) {
|
|
1977
|
-
this._end();
|
|
1978
|
-
}
|
|
1979
|
-
} catch (ex) {
|
|
1980
|
-
this.emit("error", ex);
|
|
1981
|
-
}
|
|
1982
|
-
};
|
|
1983
|
-
}
|
|
1984
|
-
});
|
|
1985
|
-
|
|
1986
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js
|
|
1987
|
-
var require_interlace = __commonJS({
|
|
1988
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/interlace.js"(exports) {
|
|
1989
|
-
"use strict";
|
|
1990
|
-
var imagePasses = [
|
|
1991
|
-
{
|
|
1992
|
-
// pass 1 - 1px
|
|
1993
|
-
x: [0],
|
|
1994
|
-
y: [0]
|
|
1995
|
-
},
|
|
1996
|
-
{
|
|
1997
|
-
// pass 2 - 1px
|
|
1998
|
-
x: [4],
|
|
1999
|
-
y: [0]
|
|
2000
|
-
},
|
|
2001
|
-
{
|
|
2002
|
-
// pass 3 - 2px
|
|
2003
|
-
x: [0, 4],
|
|
2004
|
-
y: [4]
|
|
2005
|
-
},
|
|
2006
|
-
{
|
|
2007
|
-
// pass 4 - 4px
|
|
2008
|
-
x: [2, 6],
|
|
2009
|
-
y: [0, 4]
|
|
2010
|
-
},
|
|
2011
|
-
{
|
|
2012
|
-
// pass 5 - 8px
|
|
2013
|
-
x: [0, 2, 4, 6],
|
|
2014
|
-
y: [2, 6]
|
|
2015
|
-
},
|
|
2016
|
-
{
|
|
2017
|
-
// pass 6 - 16px
|
|
2018
|
-
x: [1, 3, 5, 7],
|
|
2019
|
-
y: [0, 2, 4, 6]
|
|
2020
|
-
},
|
|
2021
|
-
{
|
|
2022
|
-
// pass 7 - 32px
|
|
2023
|
-
x: [0, 1, 2, 3, 4, 5, 6, 7],
|
|
2024
|
-
y: [1, 3, 5, 7]
|
|
2025
|
-
}
|
|
2026
|
-
];
|
|
2027
|
-
exports.getImagePasses = function(width, height) {
|
|
2028
|
-
let images = [];
|
|
2029
|
-
let xLeftOver = width % 8;
|
|
2030
|
-
let yLeftOver = height % 8;
|
|
2031
|
-
let xRepeats = (width - xLeftOver) / 8;
|
|
2032
|
-
let yRepeats = (height - yLeftOver) / 8;
|
|
2033
|
-
for (let i2 = 0; i2 < imagePasses.length; i2++) {
|
|
2034
|
-
let pass = imagePasses[i2];
|
|
2035
|
-
let passWidth = xRepeats * pass.x.length;
|
|
2036
|
-
let passHeight = yRepeats * pass.y.length;
|
|
2037
|
-
for (let j = 0; j < pass.x.length; j++) {
|
|
2038
|
-
if (pass.x[j] < xLeftOver) {
|
|
2039
|
-
passWidth++;
|
|
2040
|
-
} else {
|
|
2041
|
-
break;
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
for (let j = 0; j < pass.y.length; j++) {
|
|
2045
|
-
if (pass.y[j] < yLeftOver) {
|
|
2046
|
-
passHeight++;
|
|
2047
|
-
} else {
|
|
2048
|
-
break;
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
if (passWidth > 0 && passHeight > 0) {
|
|
2052
|
-
images.push({ width: passWidth, height: passHeight, index: i2 });
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
return images;
|
|
2056
|
-
};
|
|
2057
|
-
exports.getInterlaceIterator = function(width) {
|
|
2058
|
-
return function(x4, y2, pass) {
|
|
2059
|
-
let outerXLeftOver = x4 % imagePasses[pass].x.length;
|
|
2060
|
-
let outerX = (x4 - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
|
|
2061
|
-
let outerYLeftOver = y2 % imagePasses[pass].y.length;
|
|
2062
|
-
let outerY = (y2 - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
|
|
2063
|
-
return outerX * 4 + outerY * width * 4;
|
|
2064
|
-
};
|
|
2065
|
-
};
|
|
2066
|
-
}
|
|
2067
|
-
});
|
|
2068
|
-
|
|
2069
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js
|
|
2070
|
-
var require_paeth_predictor = __commonJS({
|
|
2071
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/paeth-predictor.js"(exports, module) {
|
|
2072
|
-
"use strict";
|
|
2073
|
-
module.exports = function paethPredictor(left, above, upLeft) {
|
|
2074
|
-
let paeth = left + above - upLeft;
|
|
2075
|
-
let pLeft = Math.abs(paeth - left);
|
|
2076
|
-
let pAbove = Math.abs(paeth - above);
|
|
2077
|
-
let pUpLeft = Math.abs(paeth - upLeft);
|
|
2078
|
-
if (pLeft <= pAbove && pLeft <= pUpLeft) {
|
|
2079
|
-
return left;
|
|
2080
|
-
}
|
|
2081
|
-
if (pAbove <= pUpLeft) {
|
|
2082
|
-
return above;
|
|
2083
|
-
}
|
|
2084
|
-
return upLeft;
|
|
2085
|
-
};
|
|
2086
|
-
}
|
|
2087
|
-
});
|
|
2088
|
-
|
|
2089
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js
|
|
2090
|
-
var require_filter_parse = __commonJS({
|
|
2091
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse.js"(exports, module) {
|
|
2092
|
-
"use strict";
|
|
2093
|
-
var interlaceUtils = require_interlace();
|
|
2094
|
-
var paethPredictor = require_paeth_predictor();
|
|
2095
|
-
function getByteWidth(width, bpp, depth) {
|
|
2096
|
-
let byteWidth = width * bpp;
|
|
2097
|
-
if (depth !== 8) {
|
|
2098
|
-
byteWidth = Math.ceil(byteWidth / (8 / depth));
|
|
2099
|
-
}
|
|
2100
|
-
return byteWidth;
|
|
2101
|
-
}
|
|
2102
|
-
var Filter = module.exports = function(bitmapInfo, dependencies) {
|
|
2103
|
-
let width = bitmapInfo.width;
|
|
2104
|
-
let height = bitmapInfo.height;
|
|
2105
|
-
let interlace = bitmapInfo.interlace;
|
|
2106
|
-
let bpp = bitmapInfo.bpp;
|
|
2107
|
-
let depth = bitmapInfo.depth;
|
|
2108
|
-
this.read = dependencies.read;
|
|
2109
|
-
this.write = dependencies.write;
|
|
2110
|
-
this.complete = dependencies.complete;
|
|
2111
|
-
this._imageIndex = 0;
|
|
2112
|
-
this._images = [];
|
|
2113
|
-
if (interlace) {
|
|
2114
|
-
let passes = interlaceUtils.getImagePasses(width, height);
|
|
2115
|
-
for (let i2 = 0; i2 < passes.length; i2++) {
|
|
2116
|
-
this._images.push({
|
|
2117
|
-
byteWidth: getByteWidth(passes[i2].width, bpp, depth),
|
|
2118
|
-
height: passes[i2].height,
|
|
2119
|
-
lineIndex: 0
|
|
2120
|
-
});
|
|
2121
|
-
}
|
|
2122
|
-
} else {
|
|
2123
|
-
this._images.push({
|
|
2124
|
-
byteWidth: getByteWidth(width, bpp, depth),
|
|
2125
|
-
height,
|
|
2126
|
-
lineIndex: 0
|
|
2127
|
-
});
|
|
2128
|
-
}
|
|
2129
|
-
if (depth === 8) {
|
|
2130
|
-
this._xComparison = bpp;
|
|
2131
|
-
} else if (depth === 16) {
|
|
2132
|
-
this._xComparison = bpp * 2;
|
|
2133
|
-
} else {
|
|
2134
|
-
this._xComparison = 1;
|
|
2135
|
-
}
|
|
2136
|
-
};
|
|
2137
|
-
Filter.prototype.start = function() {
|
|
2138
|
-
this.read(
|
|
2139
|
-
this._images[this._imageIndex].byteWidth + 1,
|
|
2140
|
-
this._reverseFilterLine.bind(this)
|
|
2141
|
-
);
|
|
2142
|
-
};
|
|
2143
|
-
Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
|
|
2144
|
-
let xComparison = this._xComparison;
|
|
2145
|
-
let xBiggerThan = xComparison - 1;
|
|
2146
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
2147
|
-
let rawByte = rawData[1 + x4];
|
|
2148
|
-
let f1Left = x4 > xBiggerThan ? unfilteredLine[x4 - xComparison] : 0;
|
|
2149
|
-
unfilteredLine[x4] = rawByte + f1Left;
|
|
2150
|
-
}
|
|
2151
|
-
};
|
|
2152
|
-
Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
|
|
2153
|
-
let lastLine = this._lastLine;
|
|
2154
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
2155
|
-
let rawByte = rawData[1 + x4];
|
|
2156
|
-
let f2Up = lastLine ? lastLine[x4] : 0;
|
|
2157
|
-
unfilteredLine[x4] = rawByte + f2Up;
|
|
2158
|
-
}
|
|
2159
|
-
};
|
|
2160
|
-
Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
|
|
2161
|
-
let xComparison = this._xComparison;
|
|
2162
|
-
let xBiggerThan = xComparison - 1;
|
|
2163
|
-
let lastLine = this._lastLine;
|
|
2164
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
2165
|
-
let rawByte = rawData[1 + x4];
|
|
2166
|
-
let f3Up = lastLine ? lastLine[x4] : 0;
|
|
2167
|
-
let f3Left = x4 > xBiggerThan ? unfilteredLine[x4 - xComparison] : 0;
|
|
2168
|
-
let f3Add = Math.floor((f3Left + f3Up) / 2);
|
|
2169
|
-
unfilteredLine[x4] = rawByte + f3Add;
|
|
2170
|
-
}
|
|
2171
|
-
};
|
|
2172
|
-
Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
|
|
2173
|
-
let xComparison = this._xComparison;
|
|
2174
|
-
let xBiggerThan = xComparison - 1;
|
|
2175
|
-
let lastLine = this._lastLine;
|
|
2176
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
2177
|
-
let rawByte = rawData[1 + x4];
|
|
2178
|
-
let f4Up = lastLine ? lastLine[x4] : 0;
|
|
2179
|
-
let f4Left = x4 > xBiggerThan ? unfilteredLine[x4 - xComparison] : 0;
|
|
2180
|
-
let f4UpLeft = x4 > xBiggerThan && lastLine ? lastLine[x4 - xComparison] : 0;
|
|
2181
|
-
let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
|
|
2182
|
-
unfilteredLine[x4] = rawByte + f4Add;
|
|
2183
|
-
}
|
|
2184
|
-
};
|
|
2185
|
-
Filter.prototype._reverseFilterLine = function(rawData) {
|
|
2186
|
-
let filter = rawData[0];
|
|
2187
|
-
let unfilteredLine;
|
|
2188
|
-
let currentImage = this._images[this._imageIndex];
|
|
2189
|
-
let byteWidth = currentImage.byteWidth;
|
|
2190
|
-
if (filter === 0) {
|
|
2191
|
-
unfilteredLine = rawData.slice(1, byteWidth + 1);
|
|
2192
|
-
} else {
|
|
2193
|
-
unfilteredLine = Buffer.alloc(byteWidth);
|
|
2194
|
-
switch (filter) {
|
|
2195
|
-
case 1:
|
|
2196
|
-
this._unFilterType1(rawData, unfilteredLine, byteWidth);
|
|
2197
|
-
break;
|
|
2198
|
-
case 2:
|
|
2199
|
-
this._unFilterType2(rawData, unfilteredLine, byteWidth);
|
|
2200
|
-
break;
|
|
2201
|
-
case 3:
|
|
2202
|
-
this._unFilterType3(rawData, unfilteredLine, byteWidth);
|
|
2203
|
-
break;
|
|
2204
|
-
case 4:
|
|
2205
|
-
this._unFilterType4(rawData, unfilteredLine, byteWidth);
|
|
2206
|
-
break;
|
|
2207
|
-
default:
|
|
2208
|
-
throw new Error("Unrecognised filter type - " + filter);
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
this.write(unfilteredLine);
|
|
2212
|
-
currentImage.lineIndex++;
|
|
2213
|
-
if (currentImage.lineIndex >= currentImage.height) {
|
|
2214
|
-
this._lastLine = null;
|
|
2215
|
-
this._imageIndex++;
|
|
2216
|
-
currentImage = this._images[this._imageIndex];
|
|
2217
|
-
} else {
|
|
2218
|
-
this._lastLine = unfilteredLine;
|
|
2219
|
-
}
|
|
2220
|
-
if (currentImage) {
|
|
2221
|
-
this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
2222
|
-
} else {
|
|
2223
|
-
this._lastLine = null;
|
|
2224
|
-
this.complete();
|
|
2225
|
-
}
|
|
2226
|
-
};
|
|
2227
|
-
}
|
|
2228
|
-
});
|
|
2229
|
-
|
|
2230
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js
|
|
2231
|
-
var require_filter_parse_async = __commonJS({
|
|
2232
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-async.js"(exports, module) {
|
|
2233
|
-
"use strict";
|
|
2234
|
-
var util = __require("util");
|
|
2235
|
-
var ChunkStream = require_chunkstream();
|
|
2236
|
-
var Filter = require_filter_parse();
|
|
2237
|
-
var FilterAsync = module.exports = function(bitmapInfo) {
|
|
2238
|
-
ChunkStream.call(this);
|
|
2239
|
-
let buffers = [];
|
|
2240
|
-
let that = this;
|
|
2241
|
-
this._filter = new Filter(bitmapInfo, {
|
|
2242
|
-
read: this.read.bind(this),
|
|
2243
|
-
write: function(buffer) {
|
|
2244
|
-
buffers.push(buffer);
|
|
2245
|
-
},
|
|
2246
|
-
complete: function() {
|
|
2247
|
-
that.emit("complete", Buffer.concat(buffers));
|
|
2248
|
-
}
|
|
2249
|
-
});
|
|
2250
|
-
this._filter.start();
|
|
2251
|
-
};
|
|
2252
|
-
util.inherits(FilterAsync, ChunkStream);
|
|
2253
|
-
}
|
|
2254
|
-
});
|
|
2255
|
-
|
|
2256
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js
|
|
2257
|
-
var require_constants = __commonJS({
|
|
2258
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/constants.js"(exports, module) {
|
|
2259
|
-
"use strict";
|
|
2260
|
-
module.exports = {
|
|
2261
|
-
PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
|
|
2262
|
-
TYPE_IHDR: 1229472850,
|
|
2263
|
-
TYPE_IEND: 1229278788,
|
|
2264
|
-
TYPE_IDAT: 1229209940,
|
|
2265
|
-
TYPE_PLTE: 1347179589,
|
|
2266
|
-
TYPE_tRNS: 1951551059,
|
|
2267
|
-
// eslint-disable-line camelcase
|
|
2268
|
-
TYPE_gAMA: 1732332865,
|
|
2269
|
-
// eslint-disable-line camelcase
|
|
2270
|
-
// color-type bits
|
|
2271
|
-
COLORTYPE_GRAYSCALE: 0,
|
|
2272
|
-
COLORTYPE_PALETTE: 1,
|
|
2273
|
-
COLORTYPE_COLOR: 2,
|
|
2274
|
-
COLORTYPE_ALPHA: 4,
|
|
2275
|
-
// e.g. grayscale and alpha
|
|
2276
|
-
// color-type combinations
|
|
2277
|
-
COLORTYPE_PALETTE_COLOR: 3,
|
|
2278
|
-
COLORTYPE_COLOR_ALPHA: 6,
|
|
2279
|
-
COLORTYPE_TO_BPP_MAP: {
|
|
2280
|
-
0: 1,
|
|
2281
|
-
2: 3,
|
|
2282
|
-
3: 1,
|
|
2283
|
-
4: 2,
|
|
2284
|
-
6: 4
|
|
2285
|
-
},
|
|
2286
|
-
GAMMA_DIVISION: 1e5
|
|
2287
|
-
};
|
|
2288
|
-
}
|
|
2289
|
-
});
|
|
2290
|
-
|
|
2291
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js
|
|
2292
|
-
var require_crc = __commonJS({
|
|
2293
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/crc.js"(exports, module) {
|
|
2294
|
-
"use strict";
|
|
2295
|
-
var crcTable = [];
|
|
2296
|
-
(function() {
|
|
2297
|
-
for (let i2 = 0; i2 < 256; i2++) {
|
|
2298
|
-
let currentCrc = i2;
|
|
2299
|
-
for (let j = 0; j < 8; j++) {
|
|
2300
|
-
if (currentCrc & 1) {
|
|
2301
|
-
currentCrc = 3988292384 ^ currentCrc >>> 1;
|
|
2302
|
-
} else {
|
|
2303
|
-
currentCrc = currentCrc >>> 1;
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
crcTable[i2] = currentCrc;
|
|
2307
|
-
}
|
|
2308
|
-
})();
|
|
2309
|
-
var CrcCalculator = module.exports = function() {
|
|
2310
|
-
this._crc = -1;
|
|
2311
|
-
};
|
|
2312
|
-
CrcCalculator.prototype.write = function(data) {
|
|
2313
|
-
for (let i2 = 0; i2 < data.length; i2++) {
|
|
2314
|
-
this._crc = crcTable[(this._crc ^ data[i2]) & 255] ^ this._crc >>> 8;
|
|
2315
|
-
}
|
|
2316
|
-
return true;
|
|
2317
|
-
};
|
|
2318
|
-
CrcCalculator.prototype.crc32 = function() {
|
|
2319
|
-
return this._crc ^ -1;
|
|
2320
|
-
};
|
|
2321
|
-
CrcCalculator.crc32 = function(buf) {
|
|
2322
|
-
let crc = -1;
|
|
2323
|
-
for (let i2 = 0; i2 < buf.length; i2++) {
|
|
2324
|
-
crc = crcTable[(crc ^ buf[i2]) & 255] ^ crc >>> 8;
|
|
2325
|
-
}
|
|
2326
|
-
return crc ^ -1;
|
|
2327
|
-
};
|
|
2328
|
-
}
|
|
2329
|
-
});
|
|
2330
|
-
|
|
2331
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js
|
|
2332
|
-
var require_parser = __commonJS({
|
|
2333
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"(exports, module) {
|
|
2334
|
-
"use strict";
|
|
2335
|
-
var constants = require_constants();
|
|
2336
|
-
var CrcCalculator = require_crc();
|
|
2337
|
-
var Parser = module.exports = function(options, dependencies) {
|
|
2338
|
-
this._options = options;
|
|
2339
|
-
options.checkCRC = options.checkCRC !== false;
|
|
2340
|
-
this._hasIHDR = false;
|
|
2341
|
-
this._hasIEND = false;
|
|
2342
|
-
this._emittedHeadersFinished = false;
|
|
2343
|
-
this._palette = [];
|
|
2344
|
-
this._colorType = 0;
|
|
2345
|
-
this._chunks = {};
|
|
2346
|
-
this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
|
|
2347
|
-
this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
|
|
2348
|
-
this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
|
|
2349
|
-
this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
|
|
2350
|
-
this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
|
|
2351
|
-
this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
|
|
2352
|
-
this.read = dependencies.read;
|
|
2353
|
-
this.error = dependencies.error;
|
|
2354
|
-
this.metadata = dependencies.metadata;
|
|
2355
|
-
this.gamma = dependencies.gamma;
|
|
2356
|
-
this.transColor = dependencies.transColor;
|
|
2357
|
-
this.palette = dependencies.palette;
|
|
2358
|
-
this.parsed = dependencies.parsed;
|
|
2359
|
-
this.inflateData = dependencies.inflateData;
|
|
2360
|
-
this.finished = dependencies.finished;
|
|
2361
|
-
this.simpleTransparency = dependencies.simpleTransparency;
|
|
2362
|
-
this.headersFinished = dependencies.headersFinished || function() {
|
|
2363
|
-
};
|
|
2364
|
-
};
|
|
2365
|
-
Parser.prototype.start = function() {
|
|
2366
|
-
this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
|
|
2367
|
-
};
|
|
2368
|
-
Parser.prototype._parseSignature = function(data) {
|
|
2369
|
-
let signature = constants.PNG_SIGNATURE;
|
|
2370
|
-
for (let i2 = 0; i2 < signature.length; i2++) {
|
|
2371
|
-
if (data[i2] !== signature[i2]) {
|
|
2372
|
-
this.error(new Error("Invalid file signature"));
|
|
2373
|
-
return;
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
2377
|
-
};
|
|
2378
|
-
Parser.prototype._parseChunkBegin = function(data) {
|
|
2379
|
-
let length = data.readUInt32BE(0);
|
|
2380
|
-
let type = data.readUInt32BE(4);
|
|
2381
|
-
let name = "";
|
|
2382
|
-
for (let i2 = 4; i2 < 8; i2++) {
|
|
2383
|
-
name += String.fromCharCode(data[i2]);
|
|
2384
|
-
}
|
|
2385
|
-
let ancillary = Boolean(data[4] & 32);
|
|
2386
|
-
if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
|
|
2387
|
-
this.error(new Error("Expected IHDR on beggining"));
|
|
2388
|
-
return;
|
|
2389
|
-
}
|
|
2390
|
-
this._crc = new CrcCalculator();
|
|
2391
|
-
this._crc.write(Buffer.from(name));
|
|
2392
|
-
if (this._chunks[type]) {
|
|
2393
|
-
return this._chunks[type](length);
|
|
2394
|
-
}
|
|
2395
|
-
if (!ancillary) {
|
|
2396
|
-
this.error(new Error("Unsupported critical chunk type " + name));
|
|
2397
|
-
return;
|
|
2398
|
-
}
|
|
2399
|
-
this.read(length + 4, this._skipChunk.bind(this));
|
|
2400
|
-
};
|
|
2401
|
-
Parser.prototype._skipChunk = function() {
|
|
2402
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
2403
|
-
};
|
|
2404
|
-
Parser.prototype._handleChunkEnd = function() {
|
|
2405
|
-
this.read(4, this._parseChunkEnd.bind(this));
|
|
2406
|
-
};
|
|
2407
|
-
Parser.prototype._parseChunkEnd = function(data) {
|
|
2408
|
-
let fileCrc = data.readInt32BE(0);
|
|
2409
|
-
let calcCrc = this._crc.crc32();
|
|
2410
|
-
if (this._options.checkCRC && calcCrc !== fileCrc) {
|
|
2411
|
-
this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
|
|
2412
|
-
return;
|
|
2413
|
-
}
|
|
2414
|
-
if (!this._hasIEND) {
|
|
2415
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
2416
|
-
}
|
|
2417
|
-
};
|
|
2418
|
-
Parser.prototype._handleIHDR = function(length) {
|
|
2419
|
-
this.read(length, this._parseIHDR.bind(this));
|
|
2420
|
-
};
|
|
2421
|
-
Parser.prototype._parseIHDR = function(data) {
|
|
2422
|
-
this._crc.write(data);
|
|
2423
|
-
let width = data.readUInt32BE(0);
|
|
2424
|
-
let height = data.readUInt32BE(4);
|
|
2425
|
-
let depth = data[8];
|
|
2426
|
-
let colorType = data[9];
|
|
2427
|
-
let compr = data[10];
|
|
2428
|
-
let filter = data[11];
|
|
2429
|
-
let interlace = data[12];
|
|
2430
|
-
if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
|
|
2431
|
-
this.error(new Error("Unsupported bit depth " + depth));
|
|
2432
|
-
return;
|
|
2433
|
-
}
|
|
2434
|
-
if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
|
|
2435
|
-
this.error(new Error("Unsupported color type"));
|
|
2436
|
-
return;
|
|
2437
|
-
}
|
|
2438
|
-
if (compr !== 0) {
|
|
2439
|
-
this.error(new Error("Unsupported compression method"));
|
|
2440
|
-
return;
|
|
2441
|
-
}
|
|
2442
|
-
if (filter !== 0) {
|
|
2443
|
-
this.error(new Error("Unsupported filter method"));
|
|
2444
|
-
return;
|
|
2445
|
-
}
|
|
2446
|
-
if (interlace !== 0 && interlace !== 1) {
|
|
2447
|
-
this.error(new Error("Unsupported interlace method"));
|
|
2448
|
-
return;
|
|
2449
|
-
}
|
|
2450
|
-
this._colorType = colorType;
|
|
2451
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
|
|
2452
|
-
this._hasIHDR = true;
|
|
2453
|
-
this.metadata({
|
|
2454
|
-
width,
|
|
2455
|
-
height,
|
|
2456
|
-
depth,
|
|
2457
|
-
interlace: Boolean(interlace),
|
|
2458
|
-
palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
|
|
2459
|
-
color: Boolean(colorType & constants.COLORTYPE_COLOR),
|
|
2460
|
-
alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
|
|
2461
|
-
bpp,
|
|
2462
|
-
colorType
|
|
2463
|
-
});
|
|
2464
|
-
this._handleChunkEnd();
|
|
2465
|
-
};
|
|
2466
|
-
Parser.prototype._handlePLTE = function(length) {
|
|
2467
|
-
this.read(length, this._parsePLTE.bind(this));
|
|
2468
|
-
};
|
|
2469
|
-
Parser.prototype._parsePLTE = function(data) {
|
|
2470
|
-
this._crc.write(data);
|
|
2471
|
-
let entries = Math.floor(data.length / 3);
|
|
2472
|
-
for (let i2 = 0; i2 < entries; i2++) {
|
|
2473
|
-
this._palette.push([data[i2 * 3], data[i2 * 3 + 1], data[i2 * 3 + 2], 255]);
|
|
2474
|
-
}
|
|
2475
|
-
this.palette(this._palette);
|
|
2476
|
-
this._handleChunkEnd();
|
|
2477
|
-
};
|
|
2478
|
-
Parser.prototype._handleTRNS = function(length) {
|
|
2479
|
-
this.simpleTransparency();
|
|
2480
|
-
this.read(length, this._parseTRNS.bind(this));
|
|
2481
|
-
};
|
|
2482
|
-
Parser.prototype._parseTRNS = function(data) {
|
|
2483
|
-
this._crc.write(data);
|
|
2484
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
|
|
2485
|
-
if (this._palette.length === 0) {
|
|
2486
|
-
this.error(new Error("Transparency chunk must be after palette"));
|
|
2487
|
-
return;
|
|
2488
|
-
}
|
|
2489
|
-
if (data.length > this._palette.length) {
|
|
2490
|
-
this.error(new Error("More transparent colors than palette size"));
|
|
2491
|
-
return;
|
|
2492
|
-
}
|
|
2493
|
-
for (let i2 = 0; i2 < data.length; i2++) {
|
|
2494
|
-
this._palette[i2][3] = data[i2];
|
|
2495
|
-
}
|
|
2496
|
-
this.palette(this._palette);
|
|
2497
|
-
}
|
|
2498
|
-
if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
|
|
2499
|
-
this.transColor([data.readUInt16BE(0)]);
|
|
2500
|
-
}
|
|
2501
|
-
if (this._colorType === constants.COLORTYPE_COLOR) {
|
|
2502
|
-
this.transColor([
|
|
2503
|
-
data.readUInt16BE(0),
|
|
2504
|
-
data.readUInt16BE(2),
|
|
2505
|
-
data.readUInt16BE(4)
|
|
2506
|
-
]);
|
|
2507
|
-
}
|
|
2508
|
-
this._handleChunkEnd();
|
|
2509
|
-
};
|
|
2510
|
-
Parser.prototype._handleGAMA = function(length) {
|
|
2511
|
-
this.read(length, this._parseGAMA.bind(this));
|
|
2512
|
-
};
|
|
2513
|
-
Parser.prototype._parseGAMA = function(data) {
|
|
2514
|
-
this._crc.write(data);
|
|
2515
|
-
this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
|
|
2516
|
-
this._handleChunkEnd();
|
|
2517
|
-
};
|
|
2518
|
-
Parser.prototype._handleIDAT = function(length) {
|
|
2519
|
-
if (!this._emittedHeadersFinished) {
|
|
2520
|
-
this._emittedHeadersFinished = true;
|
|
2521
|
-
this.headersFinished();
|
|
2522
|
-
}
|
|
2523
|
-
this.read(-length, this._parseIDAT.bind(this, length));
|
|
2524
|
-
};
|
|
2525
|
-
Parser.prototype._parseIDAT = function(length, data) {
|
|
2526
|
-
this._crc.write(data);
|
|
2527
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
|
|
2528
|
-
throw new Error("Expected palette not found");
|
|
2529
|
-
}
|
|
2530
|
-
this.inflateData(data);
|
|
2531
|
-
let leftOverLength = length - data.length;
|
|
2532
|
-
if (leftOverLength > 0) {
|
|
2533
|
-
this._handleIDAT(leftOverLength);
|
|
2534
|
-
} else {
|
|
2535
|
-
this._handleChunkEnd();
|
|
2536
|
-
}
|
|
2537
|
-
};
|
|
2538
|
-
Parser.prototype._handleIEND = function(length) {
|
|
2539
|
-
this.read(length, this._parseIEND.bind(this));
|
|
2540
|
-
};
|
|
2541
|
-
Parser.prototype._parseIEND = function(data) {
|
|
2542
|
-
this._crc.write(data);
|
|
2543
|
-
this._hasIEND = true;
|
|
2544
|
-
this._handleChunkEnd();
|
|
2545
|
-
if (this.finished) {
|
|
2546
|
-
this.finished();
|
|
2547
|
-
}
|
|
2548
|
-
};
|
|
2549
|
-
}
|
|
2550
|
-
});
|
|
2551
|
-
|
|
2552
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js
|
|
2553
|
-
var require_bitmapper = __commonJS({
|
|
2554
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitmapper.js"(exports) {
|
|
2555
|
-
"use strict";
|
|
2556
|
-
var interlaceUtils = require_interlace();
|
|
2557
|
-
var pixelBppMapper = [
|
|
2558
|
-
// 0 - dummy entry
|
|
2559
|
-
function() {
|
|
2560
|
-
},
|
|
2561
|
-
// 1 - L
|
|
2562
|
-
// 0: 0, 1: 0, 2: 0, 3: 0xff
|
|
2563
|
-
function(pxData, data, pxPos, rawPos) {
|
|
2564
|
-
if (rawPos === data.length) {
|
|
2565
|
-
throw new Error("Ran out of data");
|
|
2566
|
-
}
|
|
2567
|
-
let pixel = data[rawPos];
|
|
2568
|
-
pxData[pxPos] = pixel;
|
|
2569
|
-
pxData[pxPos + 1] = pixel;
|
|
2570
|
-
pxData[pxPos + 2] = pixel;
|
|
2571
|
-
pxData[pxPos + 3] = 255;
|
|
2572
|
-
},
|
|
2573
|
-
// 2 - LA
|
|
2574
|
-
// 0: 0, 1: 0, 2: 0, 3: 1
|
|
2575
|
-
function(pxData, data, pxPos, rawPos) {
|
|
2576
|
-
if (rawPos + 1 >= data.length) {
|
|
2577
|
-
throw new Error("Ran out of data");
|
|
2578
|
-
}
|
|
2579
|
-
let pixel = data[rawPos];
|
|
2580
|
-
pxData[pxPos] = pixel;
|
|
2581
|
-
pxData[pxPos + 1] = pixel;
|
|
2582
|
-
pxData[pxPos + 2] = pixel;
|
|
2583
|
-
pxData[pxPos + 3] = data[rawPos + 1];
|
|
2584
|
-
},
|
|
2585
|
-
// 3 - RGB
|
|
2586
|
-
// 0: 0, 1: 1, 2: 2, 3: 0xff
|
|
2587
|
-
function(pxData, data, pxPos, rawPos) {
|
|
2588
|
-
if (rawPos + 2 >= data.length) {
|
|
2589
|
-
throw new Error("Ran out of data");
|
|
2590
|
-
}
|
|
2591
|
-
pxData[pxPos] = data[rawPos];
|
|
2592
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
2593
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
2594
|
-
pxData[pxPos + 3] = 255;
|
|
2595
|
-
},
|
|
2596
|
-
// 4 - RGBA
|
|
2597
|
-
// 0: 0, 1: 1, 2: 2, 3: 3
|
|
2598
|
-
function(pxData, data, pxPos, rawPos) {
|
|
2599
|
-
if (rawPos + 3 >= data.length) {
|
|
2600
|
-
throw new Error("Ran out of data");
|
|
2601
|
-
}
|
|
2602
|
-
pxData[pxPos] = data[rawPos];
|
|
2603
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
2604
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
2605
|
-
pxData[pxPos + 3] = data[rawPos + 3];
|
|
2606
|
-
}
|
|
2607
|
-
];
|
|
2608
|
-
var pixelBppCustomMapper = [
|
|
2609
|
-
// 0 - dummy entry
|
|
2610
|
-
function() {
|
|
2611
|
-
},
|
|
2612
|
-
// 1 - L
|
|
2613
|
-
// 0: 0, 1: 0, 2: 0, 3: 0xff
|
|
2614
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
2615
|
-
let pixel = pixelData[0];
|
|
2616
|
-
pxData[pxPos] = pixel;
|
|
2617
|
-
pxData[pxPos + 1] = pixel;
|
|
2618
|
-
pxData[pxPos + 2] = pixel;
|
|
2619
|
-
pxData[pxPos + 3] = maxBit;
|
|
2620
|
-
},
|
|
2621
|
-
// 2 - LA
|
|
2622
|
-
// 0: 0, 1: 0, 2: 0, 3: 1
|
|
2623
|
-
function(pxData, pixelData, pxPos) {
|
|
2624
|
-
let pixel = pixelData[0];
|
|
2625
|
-
pxData[pxPos] = pixel;
|
|
2626
|
-
pxData[pxPos + 1] = pixel;
|
|
2627
|
-
pxData[pxPos + 2] = pixel;
|
|
2628
|
-
pxData[pxPos + 3] = pixelData[1];
|
|
2629
|
-
},
|
|
2630
|
-
// 3 - RGB
|
|
2631
|
-
// 0: 0, 1: 1, 2: 2, 3: 0xff
|
|
2632
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
2633
|
-
pxData[pxPos] = pixelData[0];
|
|
2634
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
2635
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
2636
|
-
pxData[pxPos + 3] = maxBit;
|
|
2637
|
-
},
|
|
2638
|
-
// 4 - RGBA
|
|
2639
|
-
// 0: 0, 1: 1, 2: 2, 3: 3
|
|
2640
|
-
function(pxData, pixelData, pxPos) {
|
|
2641
|
-
pxData[pxPos] = pixelData[0];
|
|
2642
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
2643
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
2644
|
-
pxData[pxPos + 3] = pixelData[3];
|
|
2645
|
-
}
|
|
2646
|
-
];
|
|
2647
|
-
function bitRetriever(data, depth) {
|
|
2648
|
-
let leftOver = [];
|
|
2649
|
-
let i2 = 0;
|
|
2650
|
-
function split2() {
|
|
2651
|
-
if (i2 === data.length) {
|
|
2652
|
-
throw new Error("Ran out of data");
|
|
2653
|
-
}
|
|
2654
|
-
let byte = data[i2];
|
|
2655
|
-
i2++;
|
|
2656
|
-
let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
|
2657
|
-
switch (depth) {
|
|
2658
|
-
default:
|
|
2659
|
-
throw new Error("unrecognised depth");
|
|
2660
|
-
case 16:
|
|
2661
|
-
byte2 = data[i2];
|
|
2662
|
-
i2++;
|
|
2663
|
-
leftOver.push((byte << 8) + byte2);
|
|
2664
|
-
break;
|
|
2665
|
-
case 4:
|
|
2666
|
-
byte2 = byte & 15;
|
|
2667
|
-
byte1 = byte >> 4;
|
|
2668
|
-
leftOver.push(byte1, byte2);
|
|
2669
|
-
break;
|
|
2670
|
-
case 2:
|
|
2671
|
-
byte4 = byte & 3;
|
|
2672
|
-
byte3 = byte >> 2 & 3;
|
|
2673
|
-
byte2 = byte >> 4 & 3;
|
|
2674
|
-
byte1 = byte >> 6 & 3;
|
|
2675
|
-
leftOver.push(byte1, byte2, byte3, byte4);
|
|
2676
|
-
break;
|
|
2677
|
-
case 1:
|
|
2678
|
-
byte8 = byte & 1;
|
|
2679
|
-
byte7 = byte >> 1 & 1;
|
|
2680
|
-
byte6 = byte >> 2 & 1;
|
|
2681
|
-
byte5 = byte >> 3 & 1;
|
|
2682
|
-
byte4 = byte >> 4 & 1;
|
|
2683
|
-
byte3 = byte >> 5 & 1;
|
|
2684
|
-
byte2 = byte >> 6 & 1;
|
|
2685
|
-
byte1 = byte >> 7 & 1;
|
|
2686
|
-
leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
|
|
2687
|
-
break;
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
return {
|
|
2691
|
-
get: function(count) {
|
|
2692
|
-
while (leftOver.length < count) {
|
|
2693
|
-
split2();
|
|
2694
|
-
}
|
|
2695
|
-
let returner = leftOver.slice(0, count);
|
|
2696
|
-
leftOver = leftOver.slice(count);
|
|
2697
|
-
return returner;
|
|
2698
|
-
},
|
|
2699
|
-
resetAfterLine: function() {
|
|
2700
|
-
leftOver.length = 0;
|
|
2701
|
-
},
|
|
2702
|
-
end: function() {
|
|
2703
|
-
if (i2 !== data.length) {
|
|
2704
|
-
throw new Error("extra data found");
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
};
|
|
2708
|
-
}
|
|
2709
|
-
function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
|
|
2710
|
-
let imageWidth = image.width;
|
|
2711
|
-
let imageHeight = image.height;
|
|
2712
|
-
let imagePass = image.index;
|
|
2713
|
-
for (let y2 = 0; y2 < imageHeight; y2++) {
|
|
2714
|
-
for (let x4 = 0; x4 < imageWidth; x4++) {
|
|
2715
|
-
let pxPos = getPxPos(x4, y2, imagePass);
|
|
2716
|
-
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
|
2717
|
-
rawPos += bpp;
|
|
2718
|
-
}
|
|
2719
|
-
}
|
|
2720
|
-
return rawPos;
|
|
2721
|
-
}
|
|
2722
|
-
function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
|
|
2723
|
-
let imageWidth = image.width;
|
|
2724
|
-
let imageHeight = image.height;
|
|
2725
|
-
let imagePass = image.index;
|
|
2726
|
-
for (let y2 = 0; y2 < imageHeight; y2++) {
|
|
2727
|
-
for (let x4 = 0; x4 < imageWidth; x4++) {
|
|
2728
|
-
let pixelData = bits.get(bpp);
|
|
2729
|
-
let pxPos = getPxPos(x4, y2, imagePass);
|
|
2730
|
-
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
|
2731
|
-
}
|
|
2732
|
-
bits.resetAfterLine();
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
exports.dataToBitMap = function(data, bitmapInfo) {
|
|
2736
|
-
let width = bitmapInfo.width;
|
|
2737
|
-
let height = bitmapInfo.height;
|
|
2738
|
-
let depth = bitmapInfo.depth;
|
|
2739
|
-
let bpp = bitmapInfo.bpp;
|
|
2740
|
-
let interlace = bitmapInfo.interlace;
|
|
2741
|
-
let bits;
|
|
2742
|
-
if (depth !== 8) {
|
|
2743
|
-
bits = bitRetriever(data, depth);
|
|
2744
|
-
}
|
|
2745
|
-
let pxData;
|
|
2746
|
-
if (depth <= 8) {
|
|
2747
|
-
pxData = Buffer.alloc(width * height * 4);
|
|
2748
|
-
} else {
|
|
2749
|
-
pxData = new Uint16Array(width * height * 4);
|
|
2750
|
-
}
|
|
2751
|
-
let maxBit = Math.pow(2, depth) - 1;
|
|
2752
|
-
let rawPos = 0;
|
|
2753
|
-
let images;
|
|
2754
|
-
let getPxPos;
|
|
2755
|
-
if (interlace) {
|
|
2756
|
-
images = interlaceUtils.getImagePasses(width, height);
|
|
2757
|
-
getPxPos = interlaceUtils.getInterlaceIterator(width, height);
|
|
2758
|
-
} else {
|
|
2759
|
-
let nonInterlacedPxPos = 0;
|
|
2760
|
-
getPxPos = function() {
|
|
2761
|
-
let returner = nonInterlacedPxPos;
|
|
2762
|
-
nonInterlacedPxPos += 4;
|
|
2763
|
-
return returner;
|
|
2764
|
-
};
|
|
2765
|
-
images = [{ width, height }];
|
|
2766
|
-
}
|
|
2767
|
-
for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
|
|
2768
|
-
if (depth === 8) {
|
|
2769
|
-
rawPos = mapImage8Bit(
|
|
2770
|
-
images[imageIndex],
|
|
2771
|
-
pxData,
|
|
2772
|
-
getPxPos,
|
|
2773
|
-
bpp,
|
|
2774
|
-
data,
|
|
2775
|
-
rawPos
|
|
2776
|
-
);
|
|
2777
|
-
} else {
|
|
2778
|
-
mapImageCustomBit(
|
|
2779
|
-
images[imageIndex],
|
|
2780
|
-
pxData,
|
|
2781
|
-
getPxPos,
|
|
2782
|
-
bpp,
|
|
2783
|
-
bits,
|
|
2784
|
-
maxBit
|
|
2785
|
-
);
|
|
2786
|
-
}
|
|
2787
|
-
}
|
|
2788
|
-
if (depth === 8) {
|
|
2789
|
-
if (rawPos !== data.length) {
|
|
2790
|
-
throw new Error("extra data found");
|
|
2791
|
-
}
|
|
2792
|
-
} else {
|
|
2793
|
-
bits.end();
|
|
2794
|
-
}
|
|
2795
|
-
return pxData;
|
|
2796
|
-
};
|
|
2797
|
-
}
|
|
2798
|
-
});
|
|
2799
|
-
|
|
2800
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js
|
|
2801
|
-
var require_format_normaliser = __commonJS({
|
|
2802
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/format-normaliser.js"(exports, module) {
|
|
2803
|
-
"use strict";
|
|
2804
|
-
function dePalette(indata, outdata, width, height, palette) {
|
|
2805
|
-
let pxPos = 0;
|
|
2806
|
-
for (let y2 = 0; y2 < height; y2++) {
|
|
2807
|
-
for (let x4 = 0; x4 < width; x4++) {
|
|
2808
|
-
let color = palette[indata[pxPos]];
|
|
2809
|
-
if (!color) {
|
|
2810
|
-
throw new Error("index " + indata[pxPos] + " not in palette");
|
|
2811
|
-
}
|
|
2812
|
-
for (let i2 = 0; i2 < 4; i2++) {
|
|
2813
|
-
outdata[pxPos + i2] = color[i2];
|
|
2814
|
-
}
|
|
2815
|
-
pxPos += 4;
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
function replaceTransparentColor(indata, outdata, width, height, transColor) {
|
|
2820
|
-
let pxPos = 0;
|
|
2821
|
-
for (let y2 = 0; y2 < height; y2++) {
|
|
2822
|
-
for (let x4 = 0; x4 < width; x4++) {
|
|
2823
|
-
let makeTrans = false;
|
|
2824
|
-
if (transColor.length === 1) {
|
|
2825
|
-
if (transColor[0] === indata[pxPos]) {
|
|
2826
|
-
makeTrans = true;
|
|
2827
|
-
}
|
|
2828
|
-
} else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
|
|
2829
|
-
makeTrans = true;
|
|
2830
|
-
}
|
|
2831
|
-
if (makeTrans) {
|
|
2832
|
-
for (let i2 = 0; i2 < 4; i2++) {
|
|
2833
|
-
outdata[pxPos + i2] = 0;
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
pxPos += 4;
|
|
2837
|
-
}
|
|
2838
|
-
}
|
|
2839
|
-
}
|
|
2840
|
-
function scaleDepth(indata, outdata, width, height, depth) {
|
|
2841
|
-
let maxOutSample = 255;
|
|
2842
|
-
let maxInSample = Math.pow(2, depth) - 1;
|
|
2843
|
-
let pxPos = 0;
|
|
2844
|
-
for (let y2 = 0; y2 < height; y2++) {
|
|
2845
|
-
for (let x4 = 0; x4 < width; x4++) {
|
|
2846
|
-
for (let i2 = 0; i2 < 4; i2++) {
|
|
2847
|
-
outdata[pxPos + i2] = Math.floor(
|
|
2848
|
-
indata[pxPos + i2] * maxOutSample / maxInSample + 0.5
|
|
2849
|
-
);
|
|
2850
|
-
}
|
|
2851
|
-
pxPos += 4;
|
|
2852
|
-
}
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
module.exports = function(indata, imageData) {
|
|
2856
|
-
let depth = imageData.depth;
|
|
2857
|
-
let width = imageData.width;
|
|
2858
|
-
let height = imageData.height;
|
|
2859
|
-
let colorType = imageData.colorType;
|
|
2860
|
-
let transColor = imageData.transColor;
|
|
2861
|
-
let palette = imageData.palette;
|
|
2862
|
-
let outdata = indata;
|
|
2863
|
-
if (colorType === 3) {
|
|
2864
|
-
dePalette(indata, outdata, width, height, palette);
|
|
2865
|
-
} else {
|
|
2866
|
-
if (transColor) {
|
|
2867
|
-
replaceTransparentColor(indata, outdata, width, height, transColor);
|
|
2868
|
-
}
|
|
2869
|
-
if (depth !== 8) {
|
|
2870
|
-
if (depth === 16) {
|
|
2871
|
-
outdata = Buffer.alloc(width * height * 4);
|
|
2872
|
-
}
|
|
2873
|
-
scaleDepth(indata, outdata, width, height, depth);
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
return outdata;
|
|
2877
|
-
};
|
|
2878
|
-
}
|
|
2879
|
-
});
|
|
2880
|
-
|
|
2881
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js
|
|
2882
|
-
var require_parser_async = __commonJS({
|
|
2883
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-async.js"(exports, module) {
|
|
2884
|
-
"use strict";
|
|
2885
|
-
var util = __require("util");
|
|
2886
|
-
var zlib = __require("zlib");
|
|
2887
|
-
var ChunkStream = require_chunkstream();
|
|
2888
|
-
var FilterAsync = require_filter_parse_async();
|
|
2889
|
-
var Parser = require_parser();
|
|
2890
|
-
var bitmapper = require_bitmapper();
|
|
2891
|
-
var formatNormaliser = require_format_normaliser();
|
|
2892
|
-
var ParserAsync = module.exports = function(options) {
|
|
2893
|
-
ChunkStream.call(this);
|
|
2894
|
-
this._parser = new Parser(options, {
|
|
2895
|
-
read: this.read.bind(this),
|
|
2896
|
-
error: this._handleError.bind(this),
|
|
2897
|
-
metadata: this._handleMetaData.bind(this),
|
|
2898
|
-
gamma: this.emit.bind(this, "gamma"),
|
|
2899
|
-
palette: this._handlePalette.bind(this),
|
|
2900
|
-
transColor: this._handleTransColor.bind(this),
|
|
2901
|
-
finished: this._finished.bind(this),
|
|
2902
|
-
inflateData: this._inflateData.bind(this),
|
|
2903
|
-
simpleTransparency: this._simpleTransparency.bind(this),
|
|
2904
|
-
headersFinished: this._headersFinished.bind(this)
|
|
2905
|
-
});
|
|
2906
|
-
this._options = options;
|
|
2907
|
-
this.writable = true;
|
|
2908
|
-
this._parser.start();
|
|
2909
|
-
};
|
|
2910
|
-
util.inherits(ParserAsync, ChunkStream);
|
|
2911
|
-
ParserAsync.prototype._handleError = function(err) {
|
|
2912
|
-
this.emit("error", err);
|
|
2913
|
-
this.writable = false;
|
|
2914
|
-
this.destroy();
|
|
2915
|
-
if (this._inflate && this._inflate.destroy) {
|
|
2916
|
-
this._inflate.destroy();
|
|
2917
|
-
}
|
|
2918
|
-
if (this._filter) {
|
|
2919
|
-
this._filter.destroy();
|
|
2920
|
-
this._filter.on("error", function() {
|
|
2921
|
-
});
|
|
2922
|
-
}
|
|
2923
|
-
this.errord = true;
|
|
2924
|
-
};
|
|
2925
|
-
ParserAsync.prototype._inflateData = function(data) {
|
|
2926
|
-
if (!this._inflate) {
|
|
2927
|
-
if (this._bitmapInfo.interlace) {
|
|
2928
|
-
this._inflate = zlib.createInflate();
|
|
2929
|
-
this._inflate.on("error", this.emit.bind(this, "error"));
|
|
2930
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
2931
|
-
this._inflate.pipe(this._filter);
|
|
2932
|
-
} else {
|
|
2933
|
-
let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
|
|
2934
|
-
let imageSize = rowSize * this._bitmapInfo.height;
|
|
2935
|
-
let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
|
|
2936
|
-
this._inflate = zlib.createInflate({ chunkSize });
|
|
2937
|
-
let leftToInflate = imageSize;
|
|
2938
|
-
let emitError = this.emit.bind(this, "error");
|
|
2939
|
-
this._inflate.on("error", function(err) {
|
|
2940
|
-
if (!leftToInflate) {
|
|
2941
|
-
return;
|
|
2942
|
-
}
|
|
2943
|
-
emitError(err);
|
|
2944
|
-
});
|
|
2945
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
2946
|
-
let filterWrite = this._filter.write.bind(this._filter);
|
|
2947
|
-
this._inflate.on("data", function(chunk) {
|
|
2948
|
-
if (!leftToInflate) {
|
|
2949
|
-
return;
|
|
2950
|
-
}
|
|
2951
|
-
if (chunk.length > leftToInflate) {
|
|
2952
|
-
chunk = chunk.slice(0, leftToInflate);
|
|
2953
|
-
}
|
|
2954
|
-
leftToInflate -= chunk.length;
|
|
2955
|
-
filterWrite(chunk);
|
|
2956
|
-
});
|
|
2957
|
-
this._inflate.on("end", this._filter.end.bind(this._filter));
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
this._inflate.write(data);
|
|
2961
|
-
};
|
|
2962
|
-
ParserAsync.prototype._handleMetaData = function(metaData) {
|
|
2963
|
-
this._metaData = metaData;
|
|
2964
|
-
this._bitmapInfo = Object.create(metaData);
|
|
2965
|
-
this._filter = new FilterAsync(this._bitmapInfo);
|
|
2966
|
-
};
|
|
2967
|
-
ParserAsync.prototype._handleTransColor = function(transColor) {
|
|
2968
|
-
this._bitmapInfo.transColor = transColor;
|
|
2969
|
-
};
|
|
2970
|
-
ParserAsync.prototype._handlePalette = function(palette) {
|
|
2971
|
-
this._bitmapInfo.palette = palette;
|
|
2972
|
-
};
|
|
2973
|
-
ParserAsync.prototype._simpleTransparency = function() {
|
|
2974
|
-
this._metaData.alpha = true;
|
|
2975
|
-
};
|
|
2976
|
-
ParserAsync.prototype._headersFinished = function() {
|
|
2977
|
-
this.emit("metadata", this._metaData);
|
|
2978
|
-
};
|
|
2979
|
-
ParserAsync.prototype._finished = function() {
|
|
2980
|
-
if (this.errord) {
|
|
2981
|
-
return;
|
|
2982
|
-
}
|
|
2983
|
-
if (!this._inflate) {
|
|
2984
|
-
this.emit("error", "No Inflate block");
|
|
2985
|
-
} else {
|
|
2986
|
-
this._inflate.end();
|
|
2987
|
-
}
|
|
2988
|
-
};
|
|
2989
|
-
ParserAsync.prototype._complete = function(filteredData) {
|
|
2990
|
-
if (this.errord) {
|
|
2991
|
-
return;
|
|
2992
|
-
}
|
|
2993
|
-
let normalisedBitmapData;
|
|
2994
|
-
try {
|
|
2995
|
-
let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
|
|
2996
|
-
normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo);
|
|
2997
|
-
bitmapData = null;
|
|
2998
|
-
} catch (ex) {
|
|
2999
|
-
this._handleError(ex);
|
|
3000
|
-
return;
|
|
3001
|
-
}
|
|
3002
|
-
this.emit("parsed", normalisedBitmapData);
|
|
3003
|
-
};
|
|
3004
|
-
}
|
|
3005
|
-
});
|
|
3006
|
-
|
|
3007
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js
|
|
3008
|
-
var require_bitpacker = __commonJS({
|
|
3009
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js"(exports, module) {
|
|
3010
|
-
"use strict";
|
|
3011
|
-
var constants = require_constants();
|
|
3012
|
-
module.exports = function(dataIn, width, height, options) {
|
|
3013
|
-
let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
|
|
3014
|
-
options.colorType
|
|
3015
|
-
) !== -1;
|
|
3016
|
-
if (options.colorType === options.inputColorType) {
|
|
3017
|
-
let bigEndian = (function() {
|
|
3018
|
-
let buffer = new ArrayBuffer(2);
|
|
3019
|
-
new DataView(buffer).setInt16(
|
|
3020
|
-
0,
|
|
3021
|
-
256,
|
|
3022
|
-
true
|
|
3023
|
-
/* littleEndian */
|
|
3024
|
-
);
|
|
3025
|
-
return new Int16Array(buffer)[0] !== 256;
|
|
3026
|
-
})();
|
|
3027
|
-
if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
|
|
3028
|
-
return dataIn;
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
|
3032
|
-
let maxValue = 255;
|
|
3033
|
-
let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
|
3034
|
-
if (inBpp === 4 && !options.inputHasAlpha) {
|
|
3035
|
-
inBpp = 3;
|
|
3036
|
-
}
|
|
3037
|
-
let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
|
|
3038
|
-
if (options.bitDepth === 16) {
|
|
3039
|
-
maxValue = 65535;
|
|
3040
|
-
outBpp *= 2;
|
|
3041
|
-
}
|
|
3042
|
-
let outData = Buffer.alloc(width * height * outBpp);
|
|
3043
|
-
let inIndex = 0;
|
|
3044
|
-
let outIndex = 0;
|
|
3045
|
-
let bgColor = options.bgColor || {};
|
|
3046
|
-
if (bgColor.red === void 0) {
|
|
3047
|
-
bgColor.red = maxValue;
|
|
3048
|
-
}
|
|
3049
|
-
if (bgColor.green === void 0) {
|
|
3050
|
-
bgColor.green = maxValue;
|
|
3051
|
-
}
|
|
3052
|
-
if (bgColor.blue === void 0) {
|
|
3053
|
-
bgColor.blue = maxValue;
|
|
3054
|
-
}
|
|
3055
|
-
function getRGBA() {
|
|
3056
|
-
let red;
|
|
3057
|
-
let green;
|
|
3058
|
-
let blue;
|
|
3059
|
-
let alpha = maxValue;
|
|
3060
|
-
switch (options.inputColorType) {
|
|
3061
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
3062
|
-
alpha = data[inIndex + 3];
|
|
3063
|
-
red = data[inIndex];
|
|
3064
|
-
green = data[inIndex + 1];
|
|
3065
|
-
blue = data[inIndex + 2];
|
|
3066
|
-
break;
|
|
3067
|
-
case constants.COLORTYPE_COLOR:
|
|
3068
|
-
red = data[inIndex];
|
|
3069
|
-
green = data[inIndex + 1];
|
|
3070
|
-
blue = data[inIndex + 2];
|
|
3071
|
-
break;
|
|
3072
|
-
case constants.COLORTYPE_ALPHA:
|
|
3073
|
-
alpha = data[inIndex + 1];
|
|
3074
|
-
red = data[inIndex];
|
|
3075
|
-
green = red;
|
|
3076
|
-
blue = red;
|
|
3077
|
-
break;
|
|
3078
|
-
case constants.COLORTYPE_GRAYSCALE:
|
|
3079
|
-
red = data[inIndex];
|
|
3080
|
-
green = red;
|
|
3081
|
-
blue = red;
|
|
3082
|
-
break;
|
|
3083
|
-
default:
|
|
3084
|
-
throw new Error(
|
|
3085
|
-
"input color type:" + options.inputColorType + " is not supported at present"
|
|
3086
|
-
);
|
|
3087
|
-
}
|
|
3088
|
-
if (options.inputHasAlpha) {
|
|
3089
|
-
if (!outHasAlpha) {
|
|
3090
|
-
alpha /= maxValue;
|
|
3091
|
-
red = Math.min(
|
|
3092
|
-
Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
|
|
3093
|
-
maxValue
|
|
3094
|
-
);
|
|
3095
|
-
green = Math.min(
|
|
3096
|
-
Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
|
|
3097
|
-
maxValue
|
|
3098
|
-
);
|
|
3099
|
-
blue = Math.min(
|
|
3100
|
-
Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
|
|
3101
|
-
maxValue
|
|
3102
|
-
);
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
return { red, green, blue, alpha };
|
|
3106
|
-
}
|
|
3107
|
-
for (let y2 = 0; y2 < height; y2++) {
|
|
3108
|
-
for (let x4 = 0; x4 < width; x4++) {
|
|
3109
|
-
let rgba = getRGBA(data, inIndex);
|
|
3110
|
-
switch (options.colorType) {
|
|
3111
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
3112
|
-
case constants.COLORTYPE_COLOR:
|
|
3113
|
-
if (options.bitDepth === 8) {
|
|
3114
|
-
outData[outIndex] = rgba.red;
|
|
3115
|
-
outData[outIndex + 1] = rgba.green;
|
|
3116
|
-
outData[outIndex + 2] = rgba.blue;
|
|
3117
|
-
if (outHasAlpha) {
|
|
3118
|
-
outData[outIndex + 3] = rgba.alpha;
|
|
3119
|
-
}
|
|
3120
|
-
} else {
|
|
3121
|
-
outData.writeUInt16BE(rgba.red, outIndex);
|
|
3122
|
-
outData.writeUInt16BE(rgba.green, outIndex + 2);
|
|
3123
|
-
outData.writeUInt16BE(rgba.blue, outIndex + 4);
|
|
3124
|
-
if (outHasAlpha) {
|
|
3125
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 6);
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
break;
|
|
3129
|
-
case constants.COLORTYPE_ALPHA:
|
|
3130
|
-
case constants.COLORTYPE_GRAYSCALE: {
|
|
3131
|
-
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
|
3132
|
-
if (options.bitDepth === 8) {
|
|
3133
|
-
outData[outIndex] = grayscale;
|
|
3134
|
-
if (outHasAlpha) {
|
|
3135
|
-
outData[outIndex + 1] = rgba.alpha;
|
|
3136
|
-
}
|
|
3137
|
-
} else {
|
|
3138
|
-
outData.writeUInt16BE(grayscale, outIndex);
|
|
3139
|
-
if (outHasAlpha) {
|
|
3140
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 2);
|
|
3141
|
-
}
|
|
3142
|
-
}
|
|
3143
|
-
break;
|
|
3144
|
-
}
|
|
3145
|
-
default:
|
|
3146
|
-
throw new Error("unrecognised color Type " + options.colorType);
|
|
3147
|
-
}
|
|
3148
|
-
inIndex += inBpp;
|
|
3149
|
-
outIndex += outBpp;
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
return outData;
|
|
3153
|
-
};
|
|
3154
|
-
}
|
|
3155
|
-
});
|
|
3156
|
-
|
|
3157
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js
|
|
3158
|
-
var require_filter_pack = __commonJS({
|
|
3159
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-pack.js"(exports, module) {
|
|
3160
|
-
"use strict";
|
|
3161
|
-
var paethPredictor = require_paeth_predictor();
|
|
3162
|
-
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
3163
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3164
|
-
rawData[rawPos + x4] = pxData[pxPos + x4];
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
function filterSumNone(pxData, pxPos, byteWidth) {
|
|
3168
|
-
let sum = 0;
|
|
3169
|
-
let length = pxPos + byteWidth;
|
|
3170
|
-
for (let i2 = pxPos; i2 < length; i2++) {
|
|
3171
|
-
sum += Math.abs(pxData[i2]);
|
|
3172
|
-
}
|
|
3173
|
-
return sum;
|
|
3174
|
-
}
|
|
3175
|
-
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
3176
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3177
|
-
let left = x4 >= bpp ? pxData[pxPos + x4 - bpp] : 0;
|
|
3178
|
-
let val = pxData[pxPos + x4] - left;
|
|
3179
|
-
rawData[rawPos + x4] = val;
|
|
3180
|
-
}
|
|
3181
|
-
}
|
|
3182
|
-
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
|
3183
|
-
let sum = 0;
|
|
3184
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3185
|
-
let left = x4 >= bpp ? pxData[pxPos + x4 - bpp] : 0;
|
|
3186
|
-
let val = pxData[pxPos + x4] - left;
|
|
3187
|
-
sum += Math.abs(val);
|
|
3188
|
-
}
|
|
3189
|
-
return sum;
|
|
3190
|
-
}
|
|
3191
|
-
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
3192
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3193
|
-
let up = pxPos > 0 ? pxData[pxPos + x4 - byteWidth] : 0;
|
|
3194
|
-
let val = pxData[pxPos + x4] - up;
|
|
3195
|
-
rawData[rawPos + x4] = val;
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
function filterSumUp(pxData, pxPos, byteWidth) {
|
|
3199
|
-
let sum = 0;
|
|
3200
|
-
let length = pxPos + byteWidth;
|
|
3201
|
-
for (let x4 = pxPos; x4 < length; x4++) {
|
|
3202
|
-
let up = pxPos > 0 ? pxData[x4 - byteWidth] : 0;
|
|
3203
|
-
let val = pxData[x4] - up;
|
|
3204
|
-
sum += Math.abs(val);
|
|
3205
|
-
}
|
|
3206
|
-
return sum;
|
|
3207
|
-
}
|
|
3208
|
-
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
3209
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3210
|
-
let left = x4 >= bpp ? pxData[pxPos + x4 - bpp] : 0;
|
|
3211
|
-
let up = pxPos > 0 ? pxData[pxPos + x4 - byteWidth] : 0;
|
|
3212
|
-
let val = pxData[pxPos + x4] - (left + up >> 1);
|
|
3213
|
-
rawData[rawPos + x4] = val;
|
|
3214
|
-
}
|
|
3215
|
-
}
|
|
3216
|
-
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
|
3217
|
-
let sum = 0;
|
|
3218
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3219
|
-
let left = x4 >= bpp ? pxData[pxPos + x4 - bpp] : 0;
|
|
3220
|
-
let up = pxPos > 0 ? pxData[pxPos + x4 - byteWidth] : 0;
|
|
3221
|
-
let val = pxData[pxPos + x4] - (left + up >> 1);
|
|
3222
|
-
sum += Math.abs(val);
|
|
3223
|
-
}
|
|
3224
|
-
return sum;
|
|
3225
|
-
}
|
|
3226
|
-
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
3227
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3228
|
-
let left = x4 >= bpp ? pxData[pxPos + x4 - bpp] : 0;
|
|
3229
|
-
let up = pxPos > 0 ? pxData[pxPos + x4 - byteWidth] : 0;
|
|
3230
|
-
let upleft = pxPos > 0 && x4 >= bpp ? pxData[pxPos + x4 - (byteWidth + bpp)] : 0;
|
|
3231
|
-
let val = pxData[pxPos + x4] - paethPredictor(left, up, upleft);
|
|
3232
|
-
rawData[rawPos + x4] = val;
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
|
3236
|
-
let sum = 0;
|
|
3237
|
-
for (let x4 = 0; x4 < byteWidth; x4++) {
|
|
3238
|
-
let left = x4 >= bpp ? pxData[pxPos + x4 - bpp] : 0;
|
|
3239
|
-
let up = pxPos > 0 ? pxData[pxPos + x4 - byteWidth] : 0;
|
|
3240
|
-
let upleft = pxPos > 0 && x4 >= bpp ? pxData[pxPos + x4 - (byteWidth + bpp)] : 0;
|
|
3241
|
-
let val = pxData[pxPos + x4] - paethPredictor(left, up, upleft);
|
|
3242
|
-
sum += Math.abs(val);
|
|
3243
|
-
}
|
|
3244
|
-
return sum;
|
|
3245
|
-
}
|
|
3246
|
-
var filters = {
|
|
3247
|
-
0: filterNone,
|
|
3248
|
-
1: filterSub,
|
|
3249
|
-
2: filterUp,
|
|
3250
|
-
3: filterAvg,
|
|
3251
|
-
4: filterPaeth
|
|
3252
|
-
};
|
|
3253
|
-
var filterSums = {
|
|
3254
|
-
0: filterSumNone,
|
|
3255
|
-
1: filterSumSub,
|
|
3256
|
-
2: filterSumUp,
|
|
3257
|
-
3: filterSumAvg,
|
|
3258
|
-
4: filterSumPaeth
|
|
3259
|
-
};
|
|
3260
|
-
module.exports = function(pxData, width, height, options, bpp) {
|
|
3261
|
-
let filterTypes;
|
|
3262
|
-
if (!("filterType" in options) || options.filterType === -1) {
|
|
3263
|
-
filterTypes = [0, 1, 2, 3, 4];
|
|
3264
|
-
} else if (typeof options.filterType === "number") {
|
|
3265
|
-
filterTypes = [options.filterType];
|
|
3266
|
-
} else {
|
|
3267
|
-
throw new Error("unrecognised filter types");
|
|
3268
|
-
}
|
|
3269
|
-
if (options.bitDepth === 16) {
|
|
3270
|
-
bpp *= 2;
|
|
3271
|
-
}
|
|
3272
|
-
let byteWidth = width * bpp;
|
|
3273
|
-
let rawPos = 0;
|
|
3274
|
-
let pxPos = 0;
|
|
3275
|
-
let rawData = Buffer.alloc((byteWidth + 1) * height);
|
|
3276
|
-
let sel = filterTypes[0];
|
|
3277
|
-
for (let y2 = 0; y2 < height; y2++) {
|
|
3278
|
-
if (filterTypes.length > 1) {
|
|
3279
|
-
let min = Infinity;
|
|
3280
|
-
for (let i2 = 0; i2 < filterTypes.length; i2++) {
|
|
3281
|
-
let sum = filterSums[filterTypes[i2]](pxData, pxPos, byteWidth, bpp);
|
|
3282
|
-
if (sum < min) {
|
|
3283
|
-
sel = filterTypes[i2];
|
|
3284
|
-
min = sum;
|
|
3285
|
-
}
|
|
3286
|
-
}
|
|
3287
|
-
}
|
|
3288
|
-
rawData[rawPos] = sel;
|
|
3289
|
-
rawPos++;
|
|
3290
|
-
filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
|
|
3291
|
-
rawPos += byteWidth;
|
|
3292
|
-
pxPos += byteWidth;
|
|
3293
|
-
}
|
|
3294
|
-
return rawData;
|
|
3295
|
-
};
|
|
3296
|
-
}
|
|
3297
|
-
});
|
|
3298
|
-
|
|
3299
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js
|
|
3300
|
-
var require_packer = __commonJS({
|
|
3301
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js"(exports, module) {
|
|
3302
|
-
"use strict";
|
|
3303
|
-
var constants = require_constants();
|
|
3304
|
-
var CrcStream = require_crc();
|
|
3305
|
-
var bitPacker = require_bitpacker();
|
|
3306
|
-
var filter = require_filter_pack();
|
|
3307
|
-
var zlib = __require("zlib");
|
|
3308
|
-
var Packer = module.exports = function(options) {
|
|
3309
|
-
this._options = options;
|
|
3310
|
-
options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
|
|
3311
|
-
options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
|
|
3312
|
-
options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
|
|
3313
|
-
options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
|
|
3314
|
-
options.deflateFactory = options.deflateFactory || zlib.createDeflate;
|
|
3315
|
-
options.bitDepth = options.bitDepth || 8;
|
|
3316
|
-
options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
3317
|
-
options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
3318
|
-
if ([
|
|
3319
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
3320
|
-
constants.COLORTYPE_COLOR,
|
|
3321
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
3322
|
-
constants.COLORTYPE_ALPHA
|
|
3323
|
-
].indexOf(options.colorType) === -1) {
|
|
3324
|
-
throw new Error(
|
|
3325
|
-
"option color type:" + options.colorType + " is not supported at present"
|
|
3326
|
-
);
|
|
3327
|
-
}
|
|
3328
|
-
if ([
|
|
3329
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
3330
|
-
constants.COLORTYPE_COLOR,
|
|
3331
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
3332
|
-
constants.COLORTYPE_ALPHA
|
|
3333
|
-
].indexOf(options.inputColorType) === -1) {
|
|
3334
|
-
throw new Error(
|
|
3335
|
-
"option input color type:" + options.inputColorType + " is not supported at present"
|
|
3336
|
-
);
|
|
3337
|
-
}
|
|
3338
|
-
if (options.bitDepth !== 8 && options.bitDepth !== 16) {
|
|
3339
|
-
throw new Error(
|
|
3340
|
-
"option bit depth:" + options.bitDepth + " is not supported at present"
|
|
3341
|
-
);
|
|
3342
|
-
}
|
|
3343
|
-
};
|
|
3344
|
-
Packer.prototype.getDeflateOptions = function() {
|
|
3345
|
-
return {
|
|
3346
|
-
chunkSize: this._options.deflateChunkSize,
|
|
3347
|
-
level: this._options.deflateLevel,
|
|
3348
|
-
strategy: this._options.deflateStrategy
|
|
3349
|
-
};
|
|
3350
|
-
};
|
|
3351
|
-
Packer.prototype.createDeflate = function() {
|
|
3352
|
-
return this._options.deflateFactory(this.getDeflateOptions());
|
|
3353
|
-
};
|
|
3354
|
-
Packer.prototype.filterData = function(data, width, height) {
|
|
3355
|
-
let packedData = bitPacker(data, width, height, this._options);
|
|
3356
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
|
|
3357
|
-
let filteredData = filter(packedData, width, height, this._options, bpp);
|
|
3358
|
-
return filteredData;
|
|
3359
|
-
};
|
|
3360
|
-
Packer.prototype._packChunk = function(type, data) {
|
|
3361
|
-
let len = data ? data.length : 0;
|
|
3362
|
-
let buf = Buffer.alloc(len + 12);
|
|
3363
|
-
buf.writeUInt32BE(len, 0);
|
|
3364
|
-
buf.writeUInt32BE(type, 4);
|
|
3365
|
-
if (data) {
|
|
3366
|
-
data.copy(buf, 8);
|
|
3367
|
-
}
|
|
3368
|
-
buf.writeInt32BE(
|
|
3369
|
-
CrcStream.crc32(buf.slice(4, buf.length - 4)),
|
|
3370
|
-
buf.length - 4
|
|
3371
|
-
);
|
|
3372
|
-
return buf;
|
|
3373
|
-
};
|
|
3374
|
-
Packer.prototype.packGAMA = function(gamma) {
|
|
3375
|
-
let buf = Buffer.alloc(4);
|
|
3376
|
-
buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
|
|
3377
|
-
return this._packChunk(constants.TYPE_gAMA, buf);
|
|
3378
|
-
};
|
|
3379
|
-
Packer.prototype.packIHDR = function(width, height) {
|
|
3380
|
-
let buf = Buffer.alloc(13);
|
|
3381
|
-
buf.writeUInt32BE(width, 0);
|
|
3382
|
-
buf.writeUInt32BE(height, 4);
|
|
3383
|
-
buf[8] = this._options.bitDepth;
|
|
3384
|
-
buf[9] = this._options.colorType;
|
|
3385
|
-
buf[10] = 0;
|
|
3386
|
-
buf[11] = 0;
|
|
3387
|
-
buf[12] = 0;
|
|
3388
|
-
return this._packChunk(constants.TYPE_IHDR, buf);
|
|
3389
|
-
};
|
|
3390
|
-
Packer.prototype.packIDAT = function(data) {
|
|
3391
|
-
return this._packChunk(constants.TYPE_IDAT, data);
|
|
3392
|
-
};
|
|
3393
|
-
Packer.prototype.packIEND = function() {
|
|
3394
|
-
return this._packChunk(constants.TYPE_IEND, null);
|
|
3395
|
-
};
|
|
3396
|
-
}
|
|
3397
|
-
});
|
|
3398
|
-
|
|
3399
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js
|
|
3400
|
-
var require_packer_async = __commonJS({
|
|
3401
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js"(exports, module) {
|
|
3402
|
-
"use strict";
|
|
3403
|
-
var util = __require("util");
|
|
3404
|
-
var Stream = __require("stream");
|
|
3405
|
-
var constants = require_constants();
|
|
3406
|
-
var Packer = require_packer();
|
|
3407
|
-
var PackerAsync = module.exports = function(opt) {
|
|
3408
|
-
Stream.call(this);
|
|
3409
|
-
let options = opt || {};
|
|
3410
|
-
this._packer = new Packer(options);
|
|
3411
|
-
this._deflate = this._packer.createDeflate();
|
|
3412
|
-
this.readable = true;
|
|
3413
|
-
};
|
|
3414
|
-
util.inherits(PackerAsync, Stream);
|
|
3415
|
-
PackerAsync.prototype.pack = function(data, width, height, gamma) {
|
|
3416
|
-
this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
|
|
3417
|
-
this.emit("data", this._packer.packIHDR(width, height));
|
|
3418
|
-
if (gamma) {
|
|
3419
|
-
this.emit("data", this._packer.packGAMA(gamma));
|
|
3420
|
-
}
|
|
3421
|
-
let filteredData = this._packer.filterData(data, width, height);
|
|
3422
|
-
this._deflate.on("error", this.emit.bind(this, "error"));
|
|
3423
|
-
this._deflate.on(
|
|
3424
|
-
"data",
|
|
3425
|
-
function(compressedData) {
|
|
3426
|
-
this.emit("data", this._packer.packIDAT(compressedData));
|
|
3427
|
-
}.bind(this)
|
|
3428
|
-
);
|
|
3429
|
-
this._deflate.on(
|
|
3430
|
-
"end",
|
|
3431
|
-
function() {
|
|
3432
|
-
this.emit("data", this._packer.packIEND());
|
|
3433
|
-
this.emit("end");
|
|
3434
|
-
}.bind(this)
|
|
3435
|
-
);
|
|
3436
|
-
this._deflate.end(filteredData);
|
|
3437
|
-
};
|
|
3438
|
-
}
|
|
3439
|
-
});
|
|
3440
|
-
|
|
3441
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js
|
|
3442
|
-
var require_sync_inflate = __commonJS({
|
|
3443
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-inflate.js"(exports, module) {
|
|
3444
|
-
"use strict";
|
|
3445
|
-
var assert = __require("assert").ok;
|
|
3446
|
-
var zlib = __require("zlib");
|
|
3447
|
-
var util = __require("util");
|
|
3448
|
-
var kMaxLength = __require("buffer").kMaxLength;
|
|
3449
|
-
function Inflate(opts) {
|
|
3450
|
-
if (!(this instanceof Inflate)) {
|
|
3451
|
-
return new Inflate(opts);
|
|
3452
|
-
}
|
|
3453
|
-
if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
|
|
3454
|
-
opts.chunkSize = zlib.Z_MIN_CHUNK;
|
|
3455
|
-
}
|
|
3456
|
-
zlib.Inflate.call(this, opts);
|
|
3457
|
-
this._offset = this._offset === void 0 ? this._outOffset : this._offset;
|
|
3458
|
-
this._buffer = this._buffer || this._outBuffer;
|
|
3459
|
-
if (opts && opts.maxLength != null) {
|
|
3460
|
-
this._maxLength = opts.maxLength;
|
|
3461
|
-
}
|
|
3462
|
-
}
|
|
3463
|
-
function createInflate(opts) {
|
|
3464
|
-
return new Inflate(opts);
|
|
3465
|
-
}
|
|
3466
|
-
function _close(engine, callback) {
|
|
3467
|
-
if (callback) {
|
|
3468
|
-
process.nextTick(callback);
|
|
3469
|
-
}
|
|
3470
|
-
if (!engine._handle) {
|
|
3471
|
-
return;
|
|
3472
|
-
}
|
|
3473
|
-
engine._handle.close();
|
|
3474
|
-
engine._handle = null;
|
|
3475
|
-
}
|
|
3476
|
-
Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
|
|
3477
|
-
if (typeof asyncCb === "function") {
|
|
3478
|
-
return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
|
|
3479
|
-
}
|
|
3480
|
-
let self = this;
|
|
3481
|
-
let availInBefore = chunk && chunk.length;
|
|
3482
|
-
let availOutBefore = this._chunkSize - this._offset;
|
|
3483
|
-
let leftToInflate = this._maxLength;
|
|
3484
|
-
let inOff = 0;
|
|
3485
|
-
let buffers = [];
|
|
3486
|
-
let nread = 0;
|
|
3487
|
-
let error;
|
|
3488
|
-
this.on("error", function(err) {
|
|
3489
|
-
error = err;
|
|
3490
|
-
});
|
|
3491
|
-
function handleChunk(availInAfter, availOutAfter) {
|
|
3492
|
-
if (self._hadError) {
|
|
3493
|
-
return;
|
|
3494
|
-
}
|
|
3495
|
-
let have = availOutBefore - availOutAfter;
|
|
3496
|
-
assert(have >= 0, "have should not go down");
|
|
3497
|
-
if (have > 0) {
|
|
3498
|
-
let out = self._buffer.slice(self._offset, self._offset + have);
|
|
3499
|
-
self._offset += have;
|
|
3500
|
-
if (out.length > leftToInflate) {
|
|
3501
|
-
out = out.slice(0, leftToInflate);
|
|
3502
|
-
}
|
|
3503
|
-
buffers.push(out);
|
|
3504
|
-
nread += out.length;
|
|
3505
|
-
leftToInflate -= out.length;
|
|
3506
|
-
if (leftToInflate === 0) {
|
|
3507
|
-
return false;
|
|
3508
|
-
}
|
|
3509
|
-
}
|
|
3510
|
-
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
|
|
3511
|
-
availOutBefore = self._chunkSize;
|
|
3512
|
-
self._offset = 0;
|
|
3513
|
-
self._buffer = Buffer.allocUnsafe(self._chunkSize);
|
|
3514
|
-
}
|
|
3515
|
-
if (availOutAfter === 0) {
|
|
3516
|
-
inOff += availInBefore - availInAfter;
|
|
3517
|
-
availInBefore = availInAfter;
|
|
3518
|
-
return true;
|
|
3519
|
-
}
|
|
3520
|
-
return false;
|
|
3521
|
-
}
|
|
3522
|
-
assert(this._handle, "zlib binding closed");
|
|
3523
|
-
let res;
|
|
3524
|
-
do {
|
|
3525
|
-
res = this._handle.writeSync(
|
|
3526
|
-
flushFlag,
|
|
3527
|
-
chunk,
|
|
3528
|
-
// in
|
|
3529
|
-
inOff,
|
|
3530
|
-
// in_off
|
|
3531
|
-
availInBefore,
|
|
3532
|
-
// in_len
|
|
3533
|
-
this._buffer,
|
|
3534
|
-
// out
|
|
3535
|
-
this._offset,
|
|
3536
|
-
//out_off
|
|
3537
|
-
availOutBefore
|
|
3538
|
-
);
|
|
3539
|
-
res = res || this._writeState;
|
|
3540
|
-
} while (!this._hadError && handleChunk(res[0], res[1]));
|
|
3541
|
-
if (this._hadError) {
|
|
3542
|
-
throw error;
|
|
3543
|
-
}
|
|
3544
|
-
if (nread >= kMaxLength) {
|
|
3545
|
-
_close(this);
|
|
3546
|
-
throw new RangeError(
|
|
3547
|
-
"Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"
|
|
3548
|
-
);
|
|
3549
|
-
}
|
|
3550
|
-
let buf = Buffer.concat(buffers, nread);
|
|
3551
|
-
_close(this);
|
|
3552
|
-
return buf;
|
|
3553
|
-
};
|
|
3554
|
-
util.inherits(Inflate, zlib.Inflate);
|
|
3555
|
-
function zlibBufferSync(engine, buffer) {
|
|
3556
|
-
if (typeof buffer === "string") {
|
|
3557
|
-
buffer = Buffer.from(buffer);
|
|
3558
|
-
}
|
|
3559
|
-
if (!(buffer instanceof Buffer)) {
|
|
3560
|
-
throw new TypeError("Not a string or buffer");
|
|
3561
|
-
}
|
|
3562
|
-
let flushFlag = engine._finishFlushFlag;
|
|
3563
|
-
if (flushFlag == null) {
|
|
3564
|
-
flushFlag = zlib.Z_FINISH;
|
|
3565
|
-
}
|
|
3566
|
-
return engine._processChunk(buffer, flushFlag);
|
|
3567
|
-
}
|
|
3568
|
-
function inflateSync(buffer, opts) {
|
|
3569
|
-
return zlibBufferSync(new Inflate(opts), buffer);
|
|
3570
|
-
}
|
|
3571
|
-
module.exports = exports = inflateSync;
|
|
3572
|
-
exports.Inflate = Inflate;
|
|
3573
|
-
exports.createInflate = createInflate;
|
|
3574
|
-
exports.inflateSync = inflateSync;
|
|
3575
|
-
}
|
|
3576
|
-
});
|
|
3577
|
-
|
|
3578
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js
|
|
3579
|
-
var require_sync_reader = __commonJS({
|
|
3580
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/sync-reader.js"(exports, module) {
|
|
3581
|
-
"use strict";
|
|
3582
|
-
var SyncReader = module.exports = function(buffer) {
|
|
3583
|
-
this._buffer = buffer;
|
|
3584
|
-
this._reads = [];
|
|
3585
|
-
};
|
|
3586
|
-
SyncReader.prototype.read = function(length, callback) {
|
|
3587
|
-
this._reads.push({
|
|
3588
|
-
length: Math.abs(length),
|
|
3589
|
-
// if length < 0 then at most this length
|
|
3590
|
-
allowLess: length < 0,
|
|
3591
|
-
func: callback
|
|
3592
|
-
});
|
|
3593
|
-
};
|
|
3594
|
-
SyncReader.prototype.process = function() {
|
|
3595
|
-
while (this._reads.length > 0 && this._buffer.length) {
|
|
3596
|
-
let read = this._reads[0];
|
|
3597
|
-
if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
|
|
3598
|
-
this._reads.shift();
|
|
3599
|
-
let buf = this._buffer;
|
|
3600
|
-
this._buffer = buf.slice(read.length);
|
|
3601
|
-
read.func.call(this, buf.slice(0, read.length));
|
|
3602
|
-
} else {
|
|
3603
|
-
break;
|
|
3604
|
-
}
|
|
3605
|
-
}
|
|
3606
|
-
if (this._reads.length > 0) {
|
|
3607
|
-
return new Error("There are some read requests waitng on finished stream");
|
|
3608
|
-
}
|
|
3609
|
-
if (this._buffer.length > 0) {
|
|
3610
|
-
return new Error("unrecognised content at end of stream");
|
|
3611
|
-
}
|
|
3612
|
-
};
|
|
3613
|
-
}
|
|
3614
|
-
});
|
|
3615
|
-
|
|
3616
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js
|
|
3617
|
-
var require_filter_parse_sync = __commonJS({
|
|
3618
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/filter-parse-sync.js"(exports) {
|
|
3619
|
-
"use strict";
|
|
3620
|
-
var SyncReader = require_sync_reader();
|
|
3621
|
-
var Filter = require_filter_parse();
|
|
3622
|
-
exports.process = function(inBuffer, bitmapInfo) {
|
|
3623
|
-
let outBuffers = [];
|
|
3624
|
-
let reader = new SyncReader(inBuffer);
|
|
3625
|
-
let filter = new Filter(bitmapInfo, {
|
|
3626
|
-
read: reader.read.bind(reader),
|
|
3627
|
-
write: function(bufferPart) {
|
|
3628
|
-
outBuffers.push(bufferPart);
|
|
3629
|
-
},
|
|
3630
|
-
complete: function() {
|
|
3631
|
-
}
|
|
3632
|
-
});
|
|
3633
|
-
filter.start();
|
|
3634
|
-
reader.process();
|
|
3635
|
-
return Buffer.concat(outBuffers);
|
|
3636
|
-
};
|
|
3637
|
-
}
|
|
3638
|
-
});
|
|
3639
|
-
|
|
3640
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js
|
|
3641
|
-
var require_parser_sync = __commonJS({
|
|
3642
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser-sync.js"(exports, module) {
|
|
3643
|
-
"use strict";
|
|
3644
|
-
var hasSyncZlib = true;
|
|
3645
|
-
var zlib = __require("zlib");
|
|
3646
|
-
var inflateSync = require_sync_inflate();
|
|
3647
|
-
if (!zlib.deflateSync) {
|
|
3648
|
-
hasSyncZlib = false;
|
|
3649
|
-
}
|
|
3650
|
-
var SyncReader = require_sync_reader();
|
|
3651
|
-
var FilterSync = require_filter_parse_sync();
|
|
3652
|
-
var Parser = require_parser();
|
|
3653
|
-
var bitmapper = require_bitmapper();
|
|
3654
|
-
var formatNormaliser = require_format_normaliser();
|
|
3655
|
-
module.exports = function(buffer, options) {
|
|
3656
|
-
if (!hasSyncZlib) {
|
|
3657
|
-
throw new Error(
|
|
3658
|
-
"To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
|
|
3659
|
-
);
|
|
3660
|
-
}
|
|
3661
|
-
let err;
|
|
3662
|
-
function handleError(_err_) {
|
|
3663
|
-
err = _err_;
|
|
3664
|
-
}
|
|
3665
|
-
let metaData;
|
|
3666
|
-
function handleMetaData(_metaData_) {
|
|
3667
|
-
metaData = _metaData_;
|
|
3668
|
-
}
|
|
3669
|
-
function handleTransColor(transColor) {
|
|
3670
|
-
metaData.transColor = transColor;
|
|
3671
|
-
}
|
|
3672
|
-
function handlePalette(palette) {
|
|
3673
|
-
metaData.palette = palette;
|
|
3674
|
-
}
|
|
3675
|
-
function handleSimpleTransparency() {
|
|
3676
|
-
metaData.alpha = true;
|
|
3677
|
-
}
|
|
3678
|
-
let gamma;
|
|
3679
|
-
function handleGamma(_gamma_) {
|
|
3680
|
-
gamma = _gamma_;
|
|
3681
|
-
}
|
|
3682
|
-
let inflateDataList = [];
|
|
3683
|
-
function handleInflateData(inflatedData2) {
|
|
3684
|
-
inflateDataList.push(inflatedData2);
|
|
3685
|
-
}
|
|
3686
|
-
let reader = new SyncReader(buffer);
|
|
3687
|
-
let parser = new Parser(options, {
|
|
3688
|
-
read: reader.read.bind(reader),
|
|
3689
|
-
error: handleError,
|
|
3690
|
-
metadata: handleMetaData,
|
|
3691
|
-
gamma: handleGamma,
|
|
3692
|
-
palette: handlePalette,
|
|
3693
|
-
transColor: handleTransColor,
|
|
3694
|
-
inflateData: handleInflateData,
|
|
3695
|
-
simpleTransparency: handleSimpleTransparency
|
|
3696
|
-
});
|
|
3697
|
-
parser.start();
|
|
3698
|
-
reader.process();
|
|
3699
|
-
if (err) {
|
|
3700
|
-
throw err;
|
|
3701
|
-
}
|
|
3702
|
-
let inflateData = Buffer.concat(inflateDataList);
|
|
3703
|
-
inflateDataList.length = 0;
|
|
3704
|
-
let inflatedData;
|
|
3705
|
-
if (metaData.interlace) {
|
|
3706
|
-
inflatedData = zlib.inflateSync(inflateData);
|
|
3707
|
-
} else {
|
|
3708
|
-
let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
|
|
3709
|
-
let imageSize = rowSize * metaData.height;
|
|
3710
|
-
inflatedData = inflateSync(inflateData, {
|
|
3711
|
-
chunkSize: imageSize,
|
|
3712
|
-
maxLength: imageSize
|
|
3713
|
-
});
|
|
3714
|
-
}
|
|
3715
|
-
inflateData = null;
|
|
3716
|
-
if (!inflatedData || !inflatedData.length) {
|
|
3717
|
-
throw new Error("bad png - invalid inflate data response");
|
|
3718
|
-
}
|
|
3719
|
-
let unfilteredData = FilterSync.process(inflatedData, metaData);
|
|
3720
|
-
inflateData = null;
|
|
3721
|
-
let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
|
|
3722
|
-
unfilteredData = null;
|
|
3723
|
-
let normalisedBitmapData = formatNormaliser(bitmapData, metaData);
|
|
3724
|
-
metaData.data = normalisedBitmapData;
|
|
3725
|
-
metaData.gamma = gamma || 0;
|
|
3726
|
-
return metaData;
|
|
3727
|
-
};
|
|
3728
|
-
}
|
|
3729
|
-
});
|
|
3730
|
-
|
|
3731
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js
|
|
3732
|
-
var require_packer_sync = __commonJS({
|
|
3733
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-sync.js"(exports, module) {
|
|
3734
|
-
"use strict";
|
|
3735
|
-
var hasSyncZlib = true;
|
|
3736
|
-
var zlib = __require("zlib");
|
|
3737
|
-
if (!zlib.deflateSync) {
|
|
3738
|
-
hasSyncZlib = false;
|
|
3739
|
-
}
|
|
3740
|
-
var constants = require_constants();
|
|
3741
|
-
var Packer = require_packer();
|
|
3742
|
-
module.exports = function(metaData, opt) {
|
|
3743
|
-
if (!hasSyncZlib) {
|
|
3744
|
-
throw new Error(
|
|
3745
|
-
"To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
|
|
3746
|
-
);
|
|
3747
|
-
}
|
|
3748
|
-
let options = opt || {};
|
|
3749
|
-
let packer = new Packer(options);
|
|
3750
|
-
let chunks = [];
|
|
3751
|
-
chunks.push(Buffer.from(constants.PNG_SIGNATURE));
|
|
3752
|
-
chunks.push(packer.packIHDR(metaData.width, metaData.height));
|
|
3753
|
-
if (metaData.gamma) {
|
|
3754
|
-
chunks.push(packer.packGAMA(metaData.gamma));
|
|
3755
|
-
}
|
|
3756
|
-
let filteredData = packer.filterData(
|
|
3757
|
-
metaData.data,
|
|
3758
|
-
metaData.width,
|
|
3759
|
-
metaData.height
|
|
3760
|
-
);
|
|
3761
|
-
let compressedData = zlib.deflateSync(
|
|
3762
|
-
filteredData,
|
|
3763
|
-
packer.getDeflateOptions()
|
|
3764
|
-
);
|
|
3765
|
-
filteredData = null;
|
|
3766
|
-
if (!compressedData || !compressedData.length) {
|
|
3767
|
-
throw new Error("bad png - invalid compressed data response");
|
|
3768
|
-
}
|
|
3769
|
-
chunks.push(packer.packIDAT(compressedData));
|
|
3770
|
-
chunks.push(packer.packIEND());
|
|
3771
|
-
return Buffer.concat(chunks);
|
|
3772
|
-
};
|
|
3773
|
-
}
|
|
3774
|
-
});
|
|
3775
|
-
|
|
3776
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js
|
|
3777
|
-
var require_png_sync = __commonJS({
|
|
3778
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js"(exports) {
|
|
3779
|
-
"use strict";
|
|
3780
|
-
var parse = require_parser_sync();
|
|
3781
|
-
var pack = require_packer_sync();
|
|
3782
|
-
exports.read = function(buffer, options) {
|
|
3783
|
-
return parse(buffer, options || {});
|
|
3784
|
-
};
|
|
3785
|
-
exports.write = function(png, options) {
|
|
3786
|
-
return pack(png, options);
|
|
3787
|
-
};
|
|
3788
|
-
}
|
|
3789
|
-
});
|
|
3790
|
-
|
|
3791
|
-
// ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js
|
|
3792
|
-
var require_png = __commonJS({
|
|
3793
|
-
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png.js"(exports) {
|
|
3794
|
-
"use strict";
|
|
3795
|
-
var util = __require("util");
|
|
3796
|
-
var Stream = __require("stream");
|
|
3797
|
-
var Parser = require_parser_async();
|
|
3798
|
-
var Packer = require_packer_async();
|
|
3799
|
-
var PNGSync = require_png_sync();
|
|
3800
|
-
var PNG = exports.PNG = function(options) {
|
|
3801
|
-
Stream.call(this);
|
|
3802
|
-
options = options || {};
|
|
3803
|
-
this.width = options.width | 0;
|
|
3804
|
-
this.height = options.height | 0;
|
|
3805
|
-
this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
|
|
3806
|
-
if (options.fill && this.data) {
|
|
3807
|
-
this.data.fill(0);
|
|
3808
|
-
}
|
|
3809
|
-
this.gamma = 0;
|
|
3810
|
-
this.readable = this.writable = true;
|
|
3811
|
-
this._parser = new Parser(options);
|
|
3812
|
-
this._parser.on("error", this.emit.bind(this, "error"));
|
|
3813
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
3814
|
-
this._parser.on("metadata", this._metadata.bind(this));
|
|
3815
|
-
this._parser.on("gamma", this._gamma.bind(this));
|
|
3816
|
-
this._parser.on(
|
|
3817
|
-
"parsed",
|
|
3818
|
-
function(data) {
|
|
3819
|
-
this.data = data;
|
|
3820
|
-
this.emit("parsed", data);
|
|
3821
|
-
}.bind(this)
|
|
3822
|
-
);
|
|
3823
|
-
this._packer = new Packer(options);
|
|
3824
|
-
this._packer.on("data", this.emit.bind(this, "data"));
|
|
3825
|
-
this._packer.on("end", this.emit.bind(this, "end"));
|
|
3826
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
3827
|
-
this._packer.on("error", this.emit.bind(this, "error"));
|
|
3828
|
-
};
|
|
3829
|
-
util.inherits(PNG, Stream);
|
|
3830
|
-
PNG.sync = PNGSync;
|
|
3831
|
-
PNG.prototype.pack = function() {
|
|
3832
|
-
if (!this.data || !this.data.length) {
|
|
3833
|
-
this.emit("error", "No data provided");
|
|
3834
|
-
return this;
|
|
3835
|
-
}
|
|
3836
|
-
process.nextTick(
|
|
3837
|
-
function() {
|
|
3838
|
-
this._packer.pack(this.data, this.width, this.height, this.gamma);
|
|
3839
|
-
}.bind(this)
|
|
3840
|
-
);
|
|
3841
|
-
return this;
|
|
3842
|
-
};
|
|
3843
|
-
PNG.prototype.parse = function(data, callback) {
|
|
3844
|
-
if (callback) {
|
|
3845
|
-
let onParsed, onError;
|
|
3846
|
-
onParsed = function(parsedData) {
|
|
3847
|
-
this.removeListener("error", onError);
|
|
3848
|
-
this.data = parsedData;
|
|
3849
|
-
callback(null, this);
|
|
3850
|
-
}.bind(this);
|
|
3851
|
-
onError = function(err) {
|
|
3852
|
-
this.removeListener("parsed", onParsed);
|
|
3853
|
-
callback(err, null);
|
|
3854
|
-
}.bind(this);
|
|
3855
|
-
this.once("parsed", onParsed);
|
|
3856
|
-
this.once("error", onError);
|
|
3857
|
-
}
|
|
3858
|
-
this.end(data);
|
|
3859
|
-
return this;
|
|
3860
|
-
};
|
|
3861
|
-
PNG.prototype.write = function(data) {
|
|
3862
|
-
this._parser.write(data);
|
|
3863
|
-
return true;
|
|
3864
|
-
};
|
|
3865
|
-
PNG.prototype.end = function(data) {
|
|
3866
|
-
this._parser.end(data);
|
|
3867
|
-
};
|
|
3868
|
-
PNG.prototype._metadata = function(metadata) {
|
|
3869
|
-
this.width = metadata.width;
|
|
3870
|
-
this.height = metadata.height;
|
|
3871
|
-
this.emit("metadata", metadata);
|
|
3872
|
-
};
|
|
3873
|
-
PNG.prototype._gamma = function(gamma) {
|
|
3874
|
-
this.gamma = gamma;
|
|
3875
|
-
};
|
|
3876
|
-
PNG.prototype._handleClose = function() {
|
|
3877
|
-
if (!this._parser.writable && !this._packer.readable) {
|
|
3878
|
-
this.emit("close");
|
|
3879
|
-
}
|
|
3880
|
-
};
|
|
3881
|
-
PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
3882
|
-
srcX |= 0;
|
|
3883
|
-
srcY |= 0;
|
|
3884
|
-
width |= 0;
|
|
3885
|
-
height |= 0;
|
|
3886
|
-
deltaX |= 0;
|
|
3887
|
-
deltaY |= 0;
|
|
3888
|
-
if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
|
|
3889
|
-
throw new Error("bitblt reading outside image");
|
|
3890
|
-
}
|
|
3891
|
-
if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
|
|
3892
|
-
throw new Error("bitblt writing outside image");
|
|
3893
|
-
}
|
|
3894
|
-
for (let y2 = 0; y2 < height; y2++) {
|
|
3895
|
-
src.data.copy(
|
|
3896
|
-
dst.data,
|
|
3897
|
-
(deltaY + y2) * dst.width + deltaX << 2,
|
|
3898
|
-
(srcY + y2) * src.width + srcX << 2,
|
|
3899
|
-
(srcY + y2) * src.width + srcX + width << 2
|
|
3900
|
-
);
|
|
3901
|
-
}
|
|
3902
|
-
};
|
|
3903
|
-
PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
3904
|
-
PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
|
|
3905
|
-
return this;
|
|
3906
|
-
};
|
|
3907
|
-
PNG.adjustGamma = function(src) {
|
|
3908
|
-
if (src.gamma) {
|
|
3909
|
-
for (let y2 = 0; y2 < src.height; y2++) {
|
|
3910
|
-
for (let x4 = 0; x4 < src.width; x4++) {
|
|
3911
|
-
let idx = src.width * y2 + x4 << 2;
|
|
3912
|
-
for (let i2 = 0; i2 < 3; i2++) {
|
|
3913
|
-
let sample = src.data[idx + i2] / 255;
|
|
3914
|
-
sample = Math.pow(sample, 1 / 2.2 / src.gamma);
|
|
3915
|
-
src.data[idx + i2] = Math.round(sample * 255);
|
|
3916
|
-
}
|
|
3917
|
-
}
|
|
3918
|
-
}
|
|
3919
|
-
src.gamma = 0;
|
|
3920
|
-
}
|
|
3921
|
-
};
|
|
3922
|
-
PNG.prototype.adjustGamma = function() {
|
|
3923
|
-
PNG.adjustGamma(this);
|
|
3924
|
-
};
|
|
3925
|
-
}
|
|
3926
|
-
});
|
|
3927
|
-
|
|
3928
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js
|
|
3929
|
-
var require_utils2 = __commonJS({
|
|
3930
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js"(exports) {
|
|
3931
|
-
"use strict";
|
|
3932
|
-
function hex2rgba(hex) {
|
|
3933
|
-
if (typeof hex === "number") {
|
|
3934
|
-
hex = hex.toString();
|
|
3935
|
-
}
|
|
3936
|
-
if (typeof hex !== "string") {
|
|
3937
|
-
throw new Error("Color should be defined as hex string");
|
|
3938
|
-
}
|
|
3939
|
-
let hexCode = hex.slice().replace("#", "").split("");
|
|
3940
|
-
if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
|
|
3941
|
-
throw new Error("Invalid hex color: " + hex);
|
|
3942
|
-
}
|
|
3943
|
-
if (hexCode.length === 3 || hexCode.length === 4) {
|
|
3944
|
-
hexCode = Array.prototype.concat.apply([], hexCode.map(function(c3) {
|
|
3945
|
-
return [c3, c3];
|
|
3946
|
-
}));
|
|
3947
|
-
}
|
|
3948
|
-
if (hexCode.length === 6) hexCode.push("F", "F");
|
|
3949
|
-
const hexValue = parseInt(hexCode.join(""), 16);
|
|
3950
|
-
return {
|
|
3951
|
-
r: hexValue >> 24 & 255,
|
|
3952
|
-
g: hexValue >> 16 & 255,
|
|
3953
|
-
b: hexValue >> 8 & 255,
|
|
3954
|
-
a: hexValue & 255,
|
|
3955
|
-
hex: "#" + hexCode.slice(0, 6).join("")
|
|
3956
|
-
};
|
|
3957
|
-
}
|
|
3958
|
-
exports.getOptions = function getOptions(options) {
|
|
3959
|
-
if (!options) options = {};
|
|
3960
|
-
if (!options.color) options.color = {};
|
|
3961
|
-
const margin = typeof options.margin === "undefined" || options.margin === null || options.margin < 0 ? 4 : options.margin;
|
|
3962
|
-
const width = options.width && options.width >= 21 ? options.width : void 0;
|
|
3963
|
-
const scale = options.scale || 4;
|
|
3964
|
-
return {
|
|
3965
|
-
width,
|
|
3966
|
-
scale: width ? 4 : scale,
|
|
3967
|
-
margin,
|
|
3968
|
-
color: {
|
|
3969
|
-
dark: hex2rgba(options.color.dark || "#000000ff"),
|
|
3970
|
-
light: hex2rgba(options.color.light || "#ffffffff")
|
|
3971
|
-
},
|
|
3972
|
-
type: options.type,
|
|
3973
|
-
rendererOpts: options.rendererOpts || {}
|
|
3974
|
-
};
|
|
3975
|
-
};
|
|
3976
|
-
exports.getScale = function getScale(qrSize, opts) {
|
|
3977
|
-
return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
|
|
3978
|
-
};
|
|
3979
|
-
exports.getImageWidth = function getImageWidth(qrSize, opts) {
|
|
3980
|
-
const scale = exports.getScale(qrSize, opts);
|
|
3981
|
-
return Math.floor((qrSize + opts.margin * 2) * scale);
|
|
3982
|
-
};
|
|
3983
|
-
exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
|
|
3984
|
-
const size = qr.modules.size;
|
|
3985
|
-
const data = qr.modules.data;
|
|
3986
|
-
const scale = exports.getScale(size, opts);
|
|
3987
|
-
const symbolSize = Math.floor((size + opts.margin * 2) * scale);
|
|
3988
|
-
const scaledMargin = opts.margin * scale;
|
|
3989
|
-
const palette = [opts.color.light, opts.color.dark];
|
|
3990
|
-
for (let i2 = 0; i2 < symbolSize; i2++) {
|
|
3991
|
-
for (let j = 0; j < symbolSize; j++) {
|
|
3992
|
-
let posDst = (i2 * symbolSize + j) * 4;
|
|
3993
|
-
let pxColor = opts.color.light;
|
|
3994
|
-
if (i2 >= scaledMargin && j >= scaledMargin && i2 < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
|
|
3995
|
-
const iSrc = Math.floor((i2 - scaledMargin) / scale);
|
|
3996
|
-
const jSrc = Math.floor((j - scaledMargin) / scale);
|
|
3997
|
-
pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
|
|
3998
|
-
}
|
|
3999
|
-
imgData[posDst++] = pxColor.r;
|
|
4000
|
-
imgData[posDst++] = pxColor.g;
|
|
4001
|
-
imgData[posDst++] = pxColor.b;
|
|
4002
|
-
imgData[posDst] = pxColor.a;
|
|
4003
|
-
}
|
|
4004
|
-
}
|
|
4005
|
-
};
|
|
4006
|
-
}
|
|
4007
|
-
});
|
|
4008
|
-
|
|
4009
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js
|
|
4010
|
-
var require_png2 = __commonJS({
|
|
4011
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/png.js"(exports) {
|
|
4012
|
-
"use strict";
|
|
4013
|
-
var fs = __require("fs");
|
|
4014
|
-
var PNG = require_png().PNG;
|
|
4015
|
-
var Utils = require_utils2();
|
|
4016
|
-
exports.render = function render(qrData, options) {
|
|
4017
|
-
const opts = Utils.getOptions(options);
|
|
4018
|
-
const pngOpts = opts.rendererOpts;
|
|
4019
|
-
const size = Utils.getImageWidth(qrData.modules.size, opts);
|
|
4020
|
-
pngOpts.width = size;
|
|
4021
|
-
pngOpts.height = size;
|
|
4022
|
-
const pngImage = new PNG(pngOpts);
|
|
4023
|
-
Utils.qrToImageData(pngImage.data, qrData, opts);
|
|
4024
|
-
return pngImage;
|
|
4025
|
-
};
|
|
4026
|
-
exports.renderToDataURL = function renderToDataURL(qrData, options, cb) {
|
|
4027
|
-
if (typeof cb === "undefined") {
|
|
4028
|
-
cb = options;
|
|
4029
|
-
options = void 0;
|
|
4030
|
-
}
|
|
4031
|
-
exports.renderToBuffer(qrData, options, function(err, output) {
|
|
4032
|
-
if (err) cb(err);
|
|
4033
|
-
let url = "data:image/png;base64,";
|
|
4034
|
-
url += output.toString("base64");
|
|
4035
|
-
cb(null, url);
|
|
4036
|
-
});
|
|
4037
|
-
};
|
|
4038
|
-
exports.renderToBuffer = function renderToBuffer(qrData, options, cb) {
|
|
4039
|
-
if (typeof cb === "undefined") {
|
|
4040
|
-
cb = options;
|
|
4041
|
-
options = void 0;
|
|
4042
|
-
}
|
|
4043
|
-
const png = exports.render(qrData, options);
|
|
4044
|
-
const buffer = [];
|
|
4045
|
-
png.on("error", cb);
|
|
4046
|
-
png.on("data", function(data) {
|
|
4047
|
-
buffer.push(data);
|
|
4048
|
-
});
|
|
4049
|
-
png.on("end", function() {
|
|
4050
|
-
cb(null, Buffer.concat(buffer));
|
|
4051
|
-
});
|
|
4052
|
-
png.pack();
|
|
4053
|
-
};
|
|
4054
|
-
exports.renderToFile = function renderToFile(path, qrData, options, cb) {
|
|
4055
|
-
if (typeof cb === "undefined") {
|
|
4056
|
-
cb = options;
|
|
4057
|
-
options = void 0;
|
|
4058
|
-
}
|
|
4059
|
-
let called = false;
|
|
4060
|
-
const done = (...args) => {
|
|
4061
|
-
if (called) return;
|
|
4062
|
-
called = true;
|
|
4063
|
-
cb.apply(null, args);
|
|
4064
|
-
};
|
|
4065
|
-
const stream = fs.createWriteStream(path);
|
|
4066
|
-
stream.on("error", done);
|
|
4067
|
-
stream.on("close", done);
|
|
4068
|
-
exports.renderToFileStream(stream, qrData, options);
|
|
4069
|
-
};
|
|
4070
|
-
exports.renderToFileStream = function renderToFileStream(stream, qrData, options) {
|
|
4071
|
-
const png = exports.render(qrData, options);
|
|
4072
|
-
png.pack().pipe(stream);
|
|
4073
|
-
};
|
|
4074
|
-
}
|
|
4075
|
-
});
|
|
4076
|
-
|
|
4077
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js
|
|
4078
|
-
var require_utf8 = __commonJS({
|
|
4079
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utf8.js"(exports) {
|
|
4080
|
-
"use strict";
|
|
4081
|
-
var Utils = require_utils2();
|
|
4082
|
-
var BLOCK_CHAR = {
|
|
4083
|
-
WW: " ",
|
|
4084
|
-
WB: "\u2584",
|
|
4085
|
-
BB: "\u2588",
|
|
4086
|
-
BW: "\u2580"
|
|
4087
|
-
};
|
|
4088
|
-
var INVERTED_BLOCK_CHAR = {
|
|
4089
|
-
BB: " ",
|
|
4090
|
-
BW: "\u2584",
|
|
4091
|
-
WW: "\u2588",
|
|
4092
|
-
WB: "\u2580"
|
|
4093
|
-
};
|
|
4094
|
-
function getBlockChar(top, bottom, blocks) {
|
|
4095
|
-
if (top && bottom) return blocks.BB;
|
|
4096
|
-
if (top && !bottom) return blocks.BW;
|
|
4097
|
-
if (!top && bottom) return blocks.WB;
|
|
4098
|
-
return blocks.WW;
|
|
4099
|
-
}
|
|
4100
|
-
exports.render = function(qrData, options, cb) {
|
|
4101
|
-
const opts = Utils.getOptions(options);
|
|
4102
|
-
let blocks = BLOCK_CHAR;
|
|
4103
|
-
if (opts.color.dark.hex === "#ffffff" || opts.color.light.hex === "#000000") {
|
|
4104
|
-
blocks = INVERTED_BLOCK_CHAR;
|
|
4105
|
-
}
|
|
4106
|
-
const size = qrData.modules.size;
|
|
4107
|
-
const data = qrData.modules.data;
|
|
4108
|
-
let output = "";
|
|
4109
|
-
let hMargin = Array(size + opts.margin * 2 + 1).join(blocks.WW);
|
|
4110
|
-
hMargin = Array(opts.margin / 2 + 1).join(hMargin + "\n");
|
|
4111
|
-
const vMargin = Array(opts.margin + 1).join(blocks.WW);
|
|
4112
|
-
output += hMargin;
|
|
4113
|
-
for (let i2 = 0; i2 < size; i2 += 2) {
|
|
4114
|
-
output += vMargin;
|
|
4115
|
-
for (let j = 0; j < size; j++) {
|
|
4116
|
-
const topModule = data[i2 * size + j];
|
|
4117
|
-
const bottomModule = data[(i2 + 1) * size + j];
|
|
4118
|
-
output += getBlockChar(topModule, bottomModule, blocks);
|
|
4119
|
-
}
|
|
4120
|
-
output += vMargin + "\n";
|
|
4121
|
-
}
|
|
4122
|
-
output += hMargin.slice(0, -1);
|
|
4123
|
-
if (typeof cb === "function") {
|
|
4124
|
-
cb(null, output);
|
|
4125
|
-
}
|
|
4126
|
-
return output;
|
|
4127
|
-
};
|
|
4128
|
-
exports.renderToFile = function renderToFile(path, qrData, options, cb) {
|
|
4129
|
-
if (typeof cb === "undefined") {
|
|
4130
|
-
cb = options;
|
|
4131
|
-
options = void 0;
|
|
4132
|
-
}
|
|
4133
|
-
const fs = __require("fs");
|
|
4134
|
-
const utf8 = exports.render(qrData, options);
|
|
4135
|
-
fs.writeFile(path, utf8, cb);
|
|
4136
|
-
};
|
|
4137
|
-
}
|
|
4138
|
-
});
|
|
4139
|
-
|
|
4140
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js
|
|
4141
|
-
var require_terminal = __commonJS({
|
|
4142
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal.js"(exports) {
|
|
4143
|
-
"use strict";
|
|
4144
|
-
exports.render = function(qrData, options, cb) {
|
|
4145
|
-
const size = qrData.modules.size;
|
|
4146
|
-
const data = qrData.modules.data;
|
|
4147
|
-
const black = "\x1B[40m \x1B[0m";
|
|
4148
|
-
const white = "\x1B[47m \x1B[0m";
|
|
4149
|
-
let output = "";
|
|
4150
|
-
const hMargin = Array(size + 3).join(white);
|
|
4151
|
-
const vMargin = Array(2).join(white);
|
|
4152
|
-
output += hMargin + "\n";
|
|
4153
|
-
for (let i2 = 0; i2 < size; ++i2) {
|
|
4154
|
-
output += white;
|
|
4155
|
-
for (let j = 0; j < size; j++) {
|
|
4156
|
-
output += data[i2 * size + j] ? black : white;
|
|
4157
|
-
}
|
|
4158
|
-
output += vMargin + "\n";
|
|
4159
|
-
}
|
|
4160
|
-
output += hMargin + "\n";
|
|
4161
|
-
if (typeof cb === "function") {
|
|
4162
|
-
cb(null, output);
|
|
4163
|
-
}
|
|
4164
|
-
return output;
|
|
4165
|
-
};
|
|
4166
|
-
}
|
|
4167
|
-
});
|
|
4168
|
-
|
|
4169
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js
|
|
4170
|
-
var require_terminal_small = __commonJS({
|
|
4171
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal/terminal-small.js"(exports) {
|
|
4172
|
-
"use strict";
|
|
4173
|
-
var backgroundWhite = "\x1B[47m";
|
|
4174
|
-
var backgroundBlack = "\x1B[40m";
|
|
4175
|
-
var foregroundWhite = "\x1B[37m";
|
|
4176
|
-
var foregroundBlack = "\x1B[30m";
|
|
4177
|
-
var reset = "\x1B[0m";
|
|
4178
|
-
var lineSetupNormal = backgroundWhite + foregroundBlack;
|
|
4179
|
-
var lineSetupInverse = backgroundBlack + foregroundWhite;
|
|
4180
|
-
var createPalette = function(lineSetup, foregroundWhite2, foregroundBlack2) {
|
|
4181
|
-
return {
|
|
4182
|
-
// 1 ... white, 2 ... black, 0 ... transparent (default)
|
|
4183
|
-
"00": reset + " " + lineSetup,
|
|
4184
|
-
"01": reset + foregroundWhite2 + "\u2584" + lineSetup,
|
|
4185
|
-
"02": reset + foregroundBlack2 + "\u2584" + lineSetup,
|
|
4186
|
-
10: reset + foregroundWhite2 + "\u2580" + lineSetup,
|
|
4187
|
-
11: " ",
|
|
4188
|
-
12: "\u2584",
|
|
4189
|
-
20: reset + foregroundBlack2 + "\u2580" + lineSetup,
|
|
4190
|
-
21: "\u2580",
|
|
4191
|
-
22: "\u2588"
|
|
4192
|
-
};
|
|
4193
|
-
};
|
|
4194
|
-
var mkCodePixel = function(modules, size, x4, y2) {
|
|
4195
|
-
const sizePlus = size + 1;
|
|
4196
|
-
if (x4 >= sizePlus || y2 >= sizePlus || y2 < -1 || x4 < -1) return "0";
|
|
4197
|
-
if (x4 >= size || y2 >= size || y2 < 0 || x4 < 0) return "1";
|
|
4198
|
-
const idx = y2 * size + x4;
|
|
4199
|
-
return modules[idx] ? "2" : "1";
|
|
4200
|
-
};
|
|
4201
|
-
var mkCode = function(modules, size, x4, y2) {
|
|
4202
|
-
return mkCodePixel(modules, size, x4, y2) + mkCodePixel(modules, size, x4, y2 + 1);
|
|
4203
|
-
};
|
|
4204
|
-
exports.render = function(qrData, options, cb) {
|
|
4205
|
-
const size = qrData.modules.size;
|
|
4206
|
-
const data = qrData.modules.data;
|
|
4207
|
-
const inverse = !!(options && options.inverse);
|
|
4208
|
-
const lineSetup = options && options.inverse ? lineSetupInverse : lineSetupNormal;
|
|
4209
|
-
const white = inverse ? foregroundBlack : foregroundWhite;
|
|
4210
|
-
const black = inverse ? foregroundWhite : foregroundBlack;
|
|
4211
|
-
const palette = createPalette(lineSetup, white, black);
|
|
4212
|
-
const newLine = reset + "\n" + lineSetup;
|
|
4213
|
-
let output = lineSetup;
|
|
4214
|
-
for (let y2 = -1; y2 < size + 1; y2 += 2) {
|
|
4215
|
-
for (let x4 = -1; x4 < size; x4++) {
|
|
4216
|
-
output += palette[mkCode(data, size, x4, y2)];
|
|
4217
|
-
}
|
|
4218
|
-
output += palette[mkCode(data, size, size, y2)] + newLine;
|
|
4219
|
-
}
|
|
4220
|
-
output += reset;
|
|
4221
|
-
if (typeof cb === "function") {
|
|
4222
|
-
cb(null, output);
|
|
4223
|
-
}
|
|
4224
|
-
return output;
|
|
4225
|
-
};
|
|
4226
|
-
}
|
|
4227
|
-
});
|
|
4228
|
-
|
|
4229
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js
|
|
4230
|
-
var require_terminal2 = __commonJS({
|
|
4231
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/terminal.js"(exports) {
|
|
4232
|
-
"use strict";
|
|
4233
|
-
var big = require_terminal();
|
|
4234
|
-
var small = require_terminal_small();
|
|
4235
|
-
exports.render = function(qrData, options, cb) {
|
|
4236
|
-
if (options && options.small) {
|
|
4237
|
-
return small.render(qrData, options, cb);
|
|
4238
|
-
}
|
|
4239
|
-
return big.render(qrData, options, cb);
|
|
4240
|
-
};
|
|
4241
|
-
}
|
|
4242
|
-
});
|
|
4243
|
-
|
|
4244
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js
|
|
4245
|
-
var require_svg_tag = __commonJS({
|
|
4246
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js"(exports) {
|
|
4247
|
-
"use strict";
|
|
4248
|
-
var Utils = require_utils2();
|
|
4249
|
-
function getColorAttrib(color, attrib) {
|
|
4250
|
-
const alpha = color.a / 255;
|
|
4251
|
-
const str = attrib + '="' + color.hex + '"';
|
|
4252
|
-
return alpha < 1 ? str + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
|
|
4253
|
-
}
|
|
4254
|
-
function svgCmd(cmd, x4, y2) {
|
|
4255
|
-
let str = cmd + x4;
|
|
4256
|
-
if (typeof y2 !== "undefined") str += " " + y2;
|
|
4257
|
-
return str;
|
|
4258
|
-
}
|
|
4259
|
-
function qrToPath(data, size, margin) {
|
|
4260
|
-
let path = "";
|
|
4261
|
-
let moveBy = 0;
|
|
4262
|
-
let newRow = false;
|
|
4263
|
-
let lineLength = 0;
|
|
4264
|
-
for (let i2 = 0; i2 < data.length; i2++) {
|
|
4265
|
-
const col = Math.floor(i2 % size);
|
|
4266
|
-
const row = Math.floor(i2 / size);
|
|
4267
|
-
if (!col && !newRow) newRow = true;
|
|
4268
|
-
if (data[i2]) {
|
|
4269
|
-
lineLength++;
|
|
4270
|
-
if (!(i2 > 0 && col > 0 && data[i2 - 1])) {
|
|
4271
|
-
path += newRow ? svgCmd("M", col + margin, 0.5 + row + margin) : svgCmd("m", moveBy, 0);
|
|
4272
|
-
moveBy = 0;
|
|
4273
|
-
newRow = false;
|
|
4274
|
-
}
|
|
4275
|
-
if (!(col + 1 < size && data[i2 + 1])) {
|
|
4276
|
-
path += svgCmd("h", lineLength);
|
|
4277
|
-
lineLength = 0;
|
|
4278
|
-
}
|
|
4279
|
-
} else {
|
|
4280
|
-
moveBy++;
|
|
4281
|
-
}
|
|
4282
|
-
}
|
|
4283
|
-
return path;
|
|
4284
|
-
}
|
|
4285
|
-
exports.render = function render(qrData, options, cb) {
|
|
4286
|
-
const opts = Utils.getOptions(options);
|
|
4287
|
-
const size = qrData.modules.size;
|
|
4288
|
-
const data = qrData.modules.data;
|
|
4289
|
-
const qrcodesize = size + opts.margin * 2;
|
|
4290
|
-
const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + ' d="M0 0h' + qrcodesize + "v" + qrcodesize + 'H0z"/>';
|
|
4291
|
-
const path = "<path " + getColorAttrib(opts.color.dark, "stroke") + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
|
|
4292
|
-
const viewBox = 'viewBox="0 0 ' + qrcodesize + " " + qrcodesize + '"';
|
|
4293
|
-
const width = !opts.width ? "" : 'width="' + opts.width + '" height="' + opts.width + '" ';
|
|
4294
|
-
const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + "</svg>\n";
|
|
4295
|
-
if (typeof cb === "function") {
|
|
4296
|
-
cb(null, svgTag);
|
|
4297
|
-
}
|
|
4298
|
-
return svgTag;
|
|
4299
|
-
};
|
|
4300
|
-
}
|
|
4301
|
-
});
|
|
4302
|
-
|
|
4303
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js
|
|
4304
|
-
var require_svg = __commonJS({
|
|
4305
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js"(exports) {
|
|
4306
|
-
"use strict";
|
|
4307
|
-
var svgTagRenderer = require_svg_tag();
|
|
4308
|
-
exports.render = svgTagRenderer.render;
|
|
4309
|
-
exports.renderToFile = function renderToFile(path, qrData, options, cb) {
|
|
4310
|
-
if (typeof cb === "undefined") {
|
|
4311
|
-
cb = options;
|
|
4312
|
-
options = void 0;
|
|
4313
|
-
}
|
|
4314
|
-
const fs = __require("fs");
|
|
4315
|
-
const svgTag = exports.render(qrData, options);
|
|
4316
|
-
const xmlStr = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' + svgTag;
|
|
4317
|
-
fs.writeFile(path, xmlStr, cb);
|
|
4318
|
-
};
|
|
4319
|
-
}
|
|
4320
|
-
});
|
|
4321
|
-
|
|
4322
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js
|
|
4323
|
-
var require_canvas = __commonJS({
|
|
4324
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js"(exports) {
|
|
4325
|
-
"use strict";
|
|
4326
|
-
var Utils = require_utils2();
|
|
4327
|
-
function clearCanvas(ctx, canvas, size) {
|
|
4328
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
4329
|
-
if (!canvas.style) canvas.style = {};
|
|
4330
|
-
canvas.height = size;
|
|
4331
|
-
canvas.width = size;
|
|
4332
|
-
canvas.style.height = size + "px";
|
|
4333
|
-
canvas.style.width = size + "px";
|
|
4334
|
-
}
|
|
4335
|
-
function getCanvasElement() {
|
|
4336
|
-
try {
|
|
4337
|
-
return document.createElement("canvas");
|
|
4338
|
-
} catch (e) {
|
|
4339
|
-
throw new Error("You need to specify a canvas element");
|
|
4340
|
-
}
|
|
4341
|
-
}
|
|
4342
|
-
exports.render = function render(qrData, canvas, options) {
|
|
4343
|
-
let opts = options;
|
|
4344
|
-
let canvasEl = canvas;
|
|
4345
|
-
if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
|
|
4346
|
-
opts = canvas;
|
|
4347
|
-
canvas = void 0;
|
|
4348
|
-
}
|
|
4349
|
-
if (!canvas) {
|
|
4350
|
-
canvasEl = getCanvasElement();
|
|
4351
|
-
}
|
|
4352
|
-
opts = Utils.getOptions(opts);
|
|
4353
|
-
const size = Utils.getImageWidth(qrData.modules.size, opts);
|
|
4354
|
-
const ctx = canvasEl.getContext("2d");
|
|
4355
|
-
const image = ctx.createImageData(size, size);
|
|
4356
|
-
Utils.qrToImageData(image.data, qrData, opts);
|
|
4357
|
-
clearCanvas(ctx, canvasEl, size);
|
|
4358
|
-
ctx.putImageData(image, 0, 0);
|
|
4359
|
-
return canvasEl;
|
|
4360
|
-
};
|
|
4361
|
-
exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
|
|
4362
|
-
let opts = options;
|
|
4363
|
-
if (typeof opts === "undefined" && (!canvas || !canvas.getContext)) {
|
|
4364
|
-
opts = canvas;
|
|
4365
|
-
canvas = void 0;
|
|
4366
|
-
}
|
|
4367
|
-
if (!opts) opts = {};
|
|
4368
|
-
const canvasEl = exports.render(qrData, canvas, opts);
|
|
4369
|
-
const type = opts.type || "image/png";
|
|
4370
|
-
const rendererOpts = opts.rendererOpts || {};
|
|
4371
|
-
return canvasEl.toDataURL(type, rendererOpts.quality);
|
|
4372
|
-
};
|
|
4373
|
-
}
|
|
4374
|
-
});
|
|
4375
|
-
|
|
4376
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js
|
|
4377
|
-
var require_browser = __commonJS({
|
|
4378
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js"(exports) {
|
|
4379
|
-
"use strict";
|
|
4380
|
-
var canPromise = require_can_promise();
|
|
4381
|
-
var QRCode2 = require_qrcode();
|
|
4382
|
-
var CanvasRenderer = require_canvas();
|
|
4383
|
-
var SvgRenderer = require_svg_tag();
|
|
4384
|
-
function renderCanvas(renderFunc, canvas, text, opts, cb) {
|
|
4385
|
-
const args = [].slice.call(arguments, 1);
|
|
4386
|
-
const argsNum = args.length;
|
|
4387
|
-
const isLastArgCb = typeof args[argsNum - 1] === "function";
|
|
4388
|
-
if (!isLastArgCb && !canPromise()) {
|
|
4389
|
-
throw new Error("Callback required as last argument");
|
|
4390
|
-
}
|
|
4391
|
-
if (isLastArgCb) {
|
|
4392
|
-
if (argsNum < 2) {
|
|
4393
|
-
throw new Error("Too few arguments provided");
|
|
4394
|
-
}
|
|
4395
|
-
if (argsNum === 2) {
|
|
4396
|
-
cb = text;
|
|
4397
|
-
text = canvas;
|
|
4398
|
-
canvas = opts = void 0;
|
|
4399
|
-
} else if (argsNum === 3) {
|
|
4400
|
-
if (canvas.getContext && typeof cb === "undefined") {
|
|
4401
|
-
cb = opts;
|
|
4402
|
-
opts = void 0;
|
|
4403
|
-
} else {
|
|
4404
|
-
cb = opts;
|
|
4405
|
-
opts = text;
|
|
4406
|
-
text = canvas;
|
|
4407
|
-
canvas = void 0;
|
|
4408
|
-
}
|
|
4409
|
-
}
|
|
4410
|
-
} else {
|
|
4411
|
-
if (argsNum < 1) {
|
|
4412
|
-
throw new Error("Too few arguments provided");
|
|
4413
|
-
}
|
|
4414
|
-
if (argsNum === 1) {
|
|
4415
|
-
text = canvas;
|
|
4416
|
-
canvas = opts = void 0;
|
|
4417
|
-
} else if (argsNum === 2 && !canvas.getContext) {
|
|
4418
|
-
opts = text;
|
|
4419
|
-
text = canvas;
|
|
4420
|
-
canvas = void 0;
|
|
4421
|
-
}
|
|
4422
|
-
return new Promise(function(resolve, reject) {
|
|
4423
|
-
try {
|
|
4424
|
-
const data = QRCode2.create(text, opts);
|
|
4425
|
-
resolve(renderFunc(data, canvas, opts));
|
|
4426
|
-
} catch (e) {
|
|
4427
|
-
reject(e);
|
|
4428
|
-
}
|
|
4429
|
-
});
|
|
4430
|
-
}
|
|
4431
|
-
try {
|
|
4432
|
-
const data = QRCode2.create(text, opts);
|
|
4433
|
-
cb(null, renderFunc(data, canvas, opts));
|
|
4434
|
-
} catch (e) {
|
|
4435
|
-
cb(e);
|
|
4436
|
-
}
|
|
4437
|
-
}
|
|
4438
|
-
exports.create = QRCode2.create;
|
|
4439
|
-
exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
|
|
4440
|
-
exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
|
|
4441
|
-
exports.toString = renderCanvas.bind(null, function(data, _3, opts) {
|
|
4442
|
-
return SvgRenderer.render(data, opts);
|
|
4443
|
-
});
|
|
4444
|
-
}
|
|
4445
|
-
});
|
|
4446
|
-
|
|
4447
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js
|
|
4448
|
-
var require_server = __commonJS({
|
|
4449
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/server.js"(exports) {
|
|
4450
|
-
"use strict";
|
|
4451
|
-
var canPromise = require_can_promise();
|
|
4452
|
-
var QRCode2 = require_qrcode();
|
|
4453
|
-
var PngRenderer = require_png2();
|
|
4454
|
-
var Utf8Renderer = require_utf8();
|
|
4455
|
-
var TerminalRenderer = require_terminal2();
|
|
4456
|
-
var SvgRenderer = require_svg();
|
|
4457
|
-
function checkParams(text, opts, cb) {
|
|
4458
|
-
if (typeof text === "undefined") {
|
|
4459
|
-
throw new Error("String required as first argument");
|
|
4460
|
-
}
|
|
4461
|
-
if (typeof cb === "undefined") {
|
|
4462
|
-
cb = opts;
|
|
4463
|
-
opts = {};
|
|
4464
|
-
}
|
|
4465
|
-
if (typeof cb !== "function") {
|
|
4466
|
-
if (!canPromise()) {
|
|
4467
|
-
throw new Error("Callback required as last argument");
|
|
4468
|
-
} else {
|
|
4469
|
-
opts = cb || {};
|
|
4470
|
-
cb = null;
|
|
4471
|
-
}
|
|
4472
|
-
}
|
|
4473
|
-
return {
|
|
4474
|
-
opts,
|
|
4475
|
-
cb
|
|
4476
|
-
};
|
|
4477
|
-
}
|
|
4478
|
-
function getTypeFromFilename(path) {
|
|
4479
|
-
return path.slice((path.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
|
|
4480
|
-
}
|
|
4481
|
-
function getRendererFromType(type) {
|
|
4482
|
-
switch (type) {
|
|
4483
|
-
case "svg":
|
|
4484
|
-
return SvgRenderer;
|
|
4485
|
-
case "txt":
|
|
4486
|
-
case "utf8":
|
|
4487
|
-
return Utf8Renderer;
|
|
4488
|
-
case "png":
|
|
4489
|
-
case "image/png":
|
|
4490
|
-
default:
|
|
4491
|
-
return PngRenderer;
|
|
4492
|
-
}
|
|
4493
|
-
}
|
|
4494
|
-
function getStringRendererFromType(type) {
|
|
4495
|
-
switch (type) {
|
|
4496
|
-
case "svg":
|
|
4497
|
-
return SvgRenderer;
|
|
4498
|
-
case "terminal":
|
|
4499
|
-
return TerminalRenderer;
|
|
4500
|
-
case "utf8":
|
|
4501
|
-
default:
|
|
4502
|
-
return Utf8Renderer;
|
|
4503
|
-
}
|
|
4504
|
-
}
|
|
4505
|
-
function render(renderFunc, text, params) {
|
|
4506
|
-
if (!params.cb) {
|
|
4507
|
-
return new Promise(function(resolve, reject) {
|
|
4508
|
-
try {
|
|
4509
|
-
const data = QRCode2.create(text, params.opts);
|
|
4510
|
-
return renderFunc(data, params.opts, function(err, data2) {
|
|
4511
|
-
return err ? reject(err) : resolve(data2);
|
|
4512
|
-
});
|
|
4513
|
-
} catch (e) {
|
|
4514
|
-
reject(e);
|
|
4515
|
-
}
|
|
4516
|
-
});
|
|
4517
|
-
}
|
|
4518
|
-
try {
|
|
4519
|
-
const data = QRCode2.create(text, params.opts);
|
|
4520
|
-
return renderFunc(data, params.opts, params.cb);
|
|
4521
|
-
} catch (e) {
|
|
4522
|
-
params.cb(e);
|
|
4523
|
-
}
|
|
4524
|
-
}
|
|
4525
|
-
exports.create = QRCode2.create;
|
|
4526
|
-
exports.toCanvas = require_browser().toCanvas;
|
|
4527
|
-
exports.toString = function toString(text, opts, cb) {
|
|
4528
|
-
const params = checkParams(text, opts, cb);
|
|
4529
|
-
const type = params.opts ? params.opts.type : void 0;
|
|
4530
|
-
const renderer = getStringRendererFromType(type);
|
|
4531
|
-
return render(renderer.render, text, params);
|
|
4532
|
-
};
|
|
4533
|
-
exports.toDataURL = function toDataURL(text, opts, cb) {
|
|
4534
|
-
const params = checkParams(text, opts, cb);
|
|
4535
|
-
const renderer = getRendererFromType(params.opts.type);
|
|
4536
|
-
return render(renderer.renderToDataURL, text, params);
|
|
4537
|
-
};
|
|
4538
|
-
exports.toBuffer = function toBuffer(text, opts, cb) {
|
|
4539
|
-
const params = checkParams(text, opts, cb);
|
|
4540
|
-
const renderer = getRendererFromType(params.opts.type);
|
|
4541
|
-
return render(renderer.renderToBuffer, text, params);
|
|
4542
|
-
};
|
|
4543
|
-
exports.toFile = function toFile(path, text, opts, cb) {
|
|
4544
|
-
if (typeof path !== "string" || !(typeof text === "string" || typeof text === "object")) {
|
|
4545
|
-
throw new Error("Invalid argument");
|
|
4546
|
-
}
|
|
4547
|
-
if (arguments.length < 3 && !canPromise()) {
|
|
4548
|
-
throw new Error("Too few arguments provided");
|
|
4549
|
-
}
|
|
4550
|
-
const params = checkParams(text, opts, cb);
|
|
4551
|
-
const type = params.opts.type || getTypeFromFilename(path);
|
|
4552
|
-
const renderer = getRendererFromType(type);
|
|
4553
|
-
const renderToFile = renderer.renderToFile.bind(null, path);
|
|
4554
|
-
return render(renderToFile, text, params);
|
|
4555
|
-
};
|
|
4556
|
-
exports.toFileStream = function toFileStream(stream, text, opts) {
|
|
4557
|
-
if (arguments.length < 2) {
|
|
4558
|
-
throw new Error("Too few arguments provided");
|
|
4559
|
-
}
|
|
4560
|
-
const params = checkParams(text, opts, stream.emit.bind(stream, "error"));
|
|
4561
|
-
const renderer = getRendererFromType("png");
|
|
4562
|
-
const renderToFileStream = renderer.renderToFileStream.bind(null, stream);
|
|
4563
|
-
render(renderToFileStream, text, params);
|
|
4564
|
-
};
|
|
4565
|
-
}
|
|
4566
|
-
});
|
|
4567
|
-
|
|
4568
|
-
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js
|
|
4569
|
-
var require_lib = __commonJS({
|
|
4570
|
-
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/index.js"(exports, module) {
|
|
4571
|
-
"use strict";
|
|
4572
|
-
module.exports = require_server();
|
|
4573
|
-
}
|
|
4574
|
-
});
|
|
4575
2
|
|
|
4576
3
|
// ../db/dist/pool.js
|
|
4577
4
|
import pg from "pg";
|
|
@@ -6575,10 +2002,17 @@ var IV_LENGTH = 12;
|
|
|
6575
2002
|
var TAG_LENGTH = 16;
|
|
6576
2003
|
function getKey() {
|
|
6577
2004
|
const raw = process.env.PLANK_ENCRYPTION_KEY;
|
|
6578
|
-
if (!raw)
|
|
2005
|
+
if (!raw) {
|
|
2006
|
+
if (process.env.NODE_ENV === "production") {
|
|
2007
|
+
throw new Error("PLANK_ENCRYPTION_KEY is required in production");
|
|
2008
|
+
}
|
|
6579
2009
|
return null;
|
|
2010
|
+
}
|
|
6580
2011
|
const buf = Buffer.from(raw, "hex");
|
|
6581
2012
|
if (buf.length !== KEY_LENGTH) {
|
|
2013
|
+
if (process.env.NODE_ENV === "production") {
|
|
2014
|
+
throw new Error("PLANK_ENCRYPTION_KEY must be 64 hex chars (32 bytes) in production");
|
|
2015
|
+
}
|
|
6582
2016
|
console.warn("[plank] PLANK_ENCRYPTION_KEY must be 64 hex chars (32 bytes). Falling back to plaintext storage.");
|
|
6583
2017
|
return null;
|
|
6584
2018
|
}
|
|
@@ -6877,37 +2311,100 @@ var RegisterSchema = z.object({
|
|
|
6877
2311
|
email: z.email(),
|
|
6878
2312
|
password: z.string().min(8)
|
|
6879
2313
|
});
|
|
6880
|
-
var loginAttempts = /* @__PURE__ */ new Map();
|
|
6881
|
-
var RATE_LIMIT_MAX = 10;
|
|
6882
2314
|
var RATE_LIMIT_WINDOW_MS = 15 * 60 * 1e3;
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
2315
|
+
var LOGIN_RATE_LIMIT_MAX = 10;
|
|
2316
|
+
var LOGIN_2FA_RATE_LIMIT_MAX = 5;
|
|
2317
|
+
var ACCESS_TOKEN_COOKIE = "plank_session";
|
|
2318
|
+
var ACCESS_TOKEN_EXPIRES_SECONDS = 60 * 15;
|
|
2319
|
+
function isProduction() {
|
|
2320
|
+
return process.env.NODE_ENV === "production";
|
|
2321
|
+
}
|
|
2322
|
+
function setSessionCookie(res, token) {
|
|
2323
|
+
res.cookie(ACCESS_TOKEN_COOKIE, token, {
|
|
2324
|
+
httpOnly: true,
|
|
2325
|
+
secure: isProduction(),
|
|
2326
|
+
sameSite: "lax",
|
|
2327
|
+
path: "/",
|
|
2328
|
+
maxAge: ACCESS_TOKEN_EXPIRES_SECONDS * 1e3
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2331
|
+
function clearSessionCookie(res) {
|
|
2332
|
+
res.clearCookie(ACCESS_TOKEN_COOKIE, {
|
|
2333
|
+
httpOnly: true,
|
|
2334
|
+
secure: isProduction(),
|
|
2335
|
+
sameSite: "lax",
|
|
2336
|
+
path: "/"
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
async function consumeRateLimit(scope, rateKey, max) {
|
|
2340
|
+
const resetAt = new Date(Date.now() + RATE_LIMIT_WINDOW_MS);
|
|
2341
|
+
const { rows } = await pool_default.query(`INSERT INTO plank_auth_rate_limits (id, scope, rate_key, count, reset_at)
|
|
2342
|
+
VALUES ($1, $2, $3, 1, $4)
|
|
2343
|
+
ON CONFLICT (scope, rate_key)
|
|
2344
|
+
DO UPDATE
|
|
2345
|
+
SET count = CASE
|
|
2346
|
+
WHEN plank_auth_rate_limits.reset_at <= NOW() THEN 1
|
|
2347
|
+
ELSE plank_auth_rate_limits.count + 1
|
|
2348
|
+
END,
|
|
2349
|
+
reset_at = CASE
|
|
2350
|
+
WHEN plank_auth_rate_limits.reset_at <= NOW() THEN $4
|
|
2351
|
+
ELSE plank_auth_rate_limits.reset_at
|
|
2352
|
+
END,
|
|
2353
|
+
updated_at = NOW()
|
|
2354
|
+
RETURNING count, reset_at`, [createId(), scope, rateKey, resetAt]);
|
|
2355
|
+
return (rows[0]?.count ?? max + 1) <= max;
|
|
2356
|
+
}
|
|
2357
|
+
async function clearRateLimit(scope, rateKey) {
|
|
2358
|
+
await pool_default.query("DELETE FROM plank_auth_rate_limits WHERE scope = $1 AND rate_key = $2", [
|
|
2359
|
+
scope,
|
|
2360
|
+
rateKey
|
|
2361
|
+
]);
|
|
2362
|
+
}
|
|
2363
|
+
function buildAccessToken(payload) {
|
|
2364
|
+
return jwt.sign(payload, process.env.PLANK_JWT_SECRET, { expiresIn: "15m" });
|
|
6894
2365
|
}
|
|
6895
|
-
function
|
|
6896
|
-
|
|
2366
|
+
function buildChallengeToken(payload) {
|
|
2367
|
+
return jwt.sign(payload, process.env.PLANK_JWT_SECRET, { expiresIn: "5m" });
|
|
2368
|
+
}
|
|
2369
|
+
async function buildAuthPayload(user) {
|
|
2370
|
+
const { rows: roleRows } = await pool_default.query("SELECT id, name, permissions FROM plank_roles WHERE id = $1", [user.role_id]);
|
|
2371
|
+
let avatarUrl = user.avatar_url;
|
|
2372
|
+
if (avatarUrl && !avatarUrl.startsWith("http")) {
|
|
2373
|
+
const provider = await getProvider();
|
|
2374
|
+
avatarUrl = await provider.getUrl(avatarUrl);
|
|
2375
|
+
}
|
|
2376
|
+
const token = buildAccessToken({ sub: user.id, roleId: user.role_id, sv: user.session_version });
|
|
2377
|
+
return {
|
|
2378
|
+
token,
|
|
2379
|
+
user: {
|
|
2380
|
+
id: user.id,
|
|
2381
|
+
email: user.email,
|
|
2382
|
+
role: roleRows[0]?.name ?? "unknown",
|
|
2383
|
+
permissions: roleRows[0]?.permissions ?? [],
|
|
2384
|
+
firstName: user.first_name,
|
|
2385
|
+
lastName: user.last_name,
|
|
2386
|
+
avatarUrl,
|
|
2387
|
+
jobTitle: user.job_title,
|
|
2388
|
+
organization: user.organization,
|
|
2389
|
+
country: user.country,
|
|
2390
|
+
twoFactorEnabled: user.two_factor_enabled
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
6897
2393
|
}
|
|
6898
2394
|
async function login(req, res) {
|
|
6899
2395
|
const ip = req.ip ?? "unknown";
|
|
6900
|
-
if (!checkRateLimit(ip)) {
|
|
6901
|
-
res.status(429).json({ error: "Too many login attempts. Try again in 15 minutes." });
|
|
6902
|
-
return;
|
|
6903
|
-
}
|
|
6904
2396
|
const parsed = LoginSchema.safeParse(req.body);
|
|
6905
2397
|
if (!parsed.success) {
|
|
6906
2398
|
res.status(400).json({ errors: flattenError(parsed.error, (i2) => i2.message) });
|
|
6907
2399
|
return;
|
|
6908
2400
|
}
|
|
6909
2401
|
const { email, password } = parsed.data;
|
|
6910
|
-
const
|
|
2402
|
+
const rateKey = `${ip}:${email.toLowerCase()}`;
|
|
2403
|
+
if (!await consumeRateLimit("login", rateKey, LOGIN_RATE_LIMIT_MAX)) {
|
|
2404
|
+
res.status(429).json({ error: "Too many login attempts. Try again in 15 minutes." });
|
|
2405
|
+
return;
|
|
2406
|
+
}
|
|
2407
|
+
const { rows } = await pool_default.query(`SELECT id, email, password, role_id, first_name, last_name, avatar_url, job_title, organization, country, two_factor_enabled, two_factor_secret, session_version
|
|
6911
2408
|
FROM plank_users
|
|
6912
2409
|
WHERE email = $1`, [email]);
|
|
6913
2410
|
const user = rows[0];
|
|
@@ -6915,40 +2412,27 @@ async function login(req, res) {
|
|
|
6915
2412
|
res.status(401).json({ error: "Invalid credentials" });
|
|
6916
2413
|
return;
|
|
6917
2414
|
}
|
|
6918
|
-
|
|
6919
|
-
clearRateLimit(ip);
|
|
6920
|
-
let avatarUrl = user.avatar_url;
|
|
6921
|
-
if (avatarUrl && !avatarUrl.startsWith("http")) {
|
|
6922
|
-
const provider = await getProvider();
|
|
6923
|
-
avatarUrl = await provider.getUrl(avatarUrl);
|
|
6924
|
-
}
|
|
2415
|
+
await clearRateLimit("login", rateKey);
|
|
6925
2416
|
if (user.two_factor_enabled && user.two_factor_secret) {
|
|
6926
|
-
const challengeToken =
|
|
2417
|
+
const challengeToken = buildChallengeToken({
|
|
2418
|
+
sub: user.id,
|
|
2419
|
+
roleId: user.role_id,
|
|
2420
|
+
sv: user.session_version,
|
|
2421
|
+
twoFactor: true,
|
|
2422
|
+
jti: createId()
|
|
2423
|
+
});
|
|
6927
2424
|
res.json({ requiresTwoFactor: true, challengeToken });
|
|
6928
2425
|
return;
|
|
6929
2426
|
}
|
|
6930
|
-
const
|
|
6931
|
-
|
|
6932
|
-
});
|
|
2427
|
+
const auth = await buildAuthPayload(user);
|
|
2428
|
+
setSessionCookie(res, auth.token);
|
|
6933
2429
|
res.json({
|
|
6934
2430
|
requiresTwoFactor: false,
|
|
6935
|
-
|
|
6936
|
-
user: {
|
|
6937
|
-
id: user.id,
|
|
6938
|
-
email: user.email,
|
|
6939
|
-
role: roleRows[0]?.name ?? "unknown",
|
|
6940
|
-
permissions: roleRows[0]?.permissions ?? [],
|
|
6941
|
-
firstName: user.first_name,
|
|
6942
|
-
lastName: user.last_name,
|
|
6943
|
-
avatarUrl,
|
|
6944
|
-
jobTitle: user.job_title,
|
|
6945
|
-
organization: user.organization,
|
|
6946
|
-
country: user.country,
|
|
6947
|
-
twoFactorEnabled: user.two_factor_enabled
|
|
6948
|
-
}
|
|
2431
|
+
user: auth.user
|
|
6949
2432
|
});
|
|
6950
2433
|
}
|
|
6951
2434
|
async function loginWithTwoFactor(req, res) {
|
|
2435
|
+
const ip = req.ip ?? "unknown";
|
|
6952
2436
|
const parsed = Login2FASchema.safeParse(req.body);
|
|
6953
2437
|
if (!parsed.success) {
|
|
6954
2438
|
res.status(400).json({ errors: flattenError(parsed.error, (i2) => i2.message) });
|
|
@@ -6965,13 +2449,22 @@ async function loginWithTwoFactor(req, res) {
|
|
|
6965
2449
|
res.status(400).json({ error: "Invalid 2FA challenge token" });
|
|
6966
2450
|
return;
|
|
6967
2451
|
}
|
|
6968
|
-
const
|
|
2452
|
+
const rateKey = `${ip}:${payload.sub}:${payload.jti ?? "nojti"}`;
|
|
2453
|
+
if (!await consumeRateLimit("login-2fa", rateKey, LOGIN_2FA_RATE_LIMIT_MAX)) {
|
|
2454
|
+
res.status(429).json({ error: "Too many 2FA attempts. Try again in 15 minutes." });
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2457
|
+
const { rows } = await pool_default.query(`SELECT id, email, role_id, first_name, last_name, avatar_url, job_title, organization, country, two_factor_enabled, two_factor_secret, password, session_version
|
|
6969
2458
|
FROM plank_users WHERE id = $1`, [payload.sub]);
|
|
6970
2459
|
const user = rows[0];
|
|
6971
2460
|
if (!user || !user.two_factor_enabled || !user.two_factor_secret) {
|
|
6972
2461
|
res.status(401).json({ error: "2FA is not enabled for this account" });
|
|
6973
2462
|
return;
|
|
6974
2463
|
}
|
|
2464
|
+
if (user.session_version !== payload.sv) {
|
|
2465
|
+
res.status(401).json({ error: "2FA challenge expired. Start login again." });
|
|
2466
|
+
return;
|
|
2467
|
+
}
|
|
6975
2468
|
const result = d3({
|
|
6976
2469
|
token: parsed.data.code,
|
|
6977
2470
|
secret: decrypt(user.two_factor_secret)
|
|
@@ -6980,33 +2473,31 @@ async function loginWithTwoFactor(req, res) {
|
|
|
6980
2473
|
res.status(401).json({ error: "Invalid verification code" });
|
|
6981
2474
|
return;
|
|
6982
2475
|
}
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
const provider = await getProvider();
|
|
6987
|
-
avatarUrl = await provider.getUrl(avatarUrl);
|
|
6988
|
-
}
|
|
6989
|
-
const token = jwt.sign({ sub: user.id, roleId: user.role_id }, process.env.PLANK_JWT_SECRET, {
|
|
6990
|
-
expiresIn: "7d"
|
|
6991
|
-
});
|
|
2476
|
+
await clearRateLimit("login-2fa", rateKey);
|
|
2477
|
+
const auth = await buildAuthPayload(user);
|
|
2478
|
+
setSessionCookie(res, auth.token);
|
|
6992
2479
|
res.json({
|
|
6993
2480
|
requiresTwoFactor: false,
|
|
6994
|
-
|
|
6995
|
-
user: {
|
|
6996
|
-
id: user.id,
|
|
6997
|
-
email: user.email,
|
|
6998
|
-
role: roleRows[0]?.name ?? "unknown",
|
|
6999
|
-
permissions: roleRows[0]?.permissions ?? [],
|
|
7000
|
-
firstName: user.first_name,
|
|
7001
|
-
lastName: user.last_name,
|
|
7002
|
-
avatarUrl,
|
|
7003
|
-
jobTitle: user.job_title,
|
|
7004
|
-
organization: user.organization,
|
|
7005
|
-
country: user.country,
|
|
7006
|
-
twoFactorEnabled: user.two_factor_enabled
|
|
7007
|
-
}
|
|
2481
|
+
user: auth.user
|
|
7008
2482
|
});
|
|
7009
2483
|
}
|
|
2484
|
+
async function logout(req, res) {
|
|
2485
|
+
const cookieHeader = req.headers.cookie ?? "";
|
|
2486
|
+
const raw = cookieHeader.split(";").map((c3) => c3.trim()).find((c3) => c3.startsWith(`${ACCESS_TOKEN_COOKIE}=`))?.slice(`${ACCESS_TOKEN_COOKIE}=`.length);
|
|
2487
|
+
if (raw) {
|
|
2488
|
+
try {
|
|
2489
|
+
const payload = jwt.verify(decodeURIComponent(raw), process.env.PLANK_JWT_SECRET);
|
|
2490
|
+
if (payload.sub) {
|
|
2491
|
+
await pool_default.query("UPDATE plank_users SET session_version = session_version + 1 WHERE id = $1", [payload.sub]);
|
|
2492
|
+
}
|
|
2493
|
+
} catch {
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
clearSessionCookie(res);
|
|
2497
|
+
const ip = req.ip ?? "unknown";
|
|
2498
|
+
await pool_default.query("DELETE FROM plank_auth_rate_limits WHERE rate_key LIKE $1", [`${ip}:%`]);
|
|
2499
|
+
res.status(204).end();
|
|
2500
|
+
}
|
|
7010
2501
|
async function setup(_req, res) {
|
|
7011
2502
|
const { rows } = await pool_default.query("SELECT COUNT(*) as count FROM plank_users");
|
|
7012
2503
|
res.json({ needsSetup: parseInt(rows[0].count) === 0 });
|
|
@@ -7035,6 +2526,7 @@ var router = Router();
|
|
|
7035
2526
|
router.get("/setup", setup);
|
|
7036
2527
|
router.post("/login", login);
|
|
7037
2528
|
router.post("/login/2fa", loginWithTwoFactor);
|
|
2529
|
+
router.post("/logout", logout);
|
|
7038
2530
|
router.post("/register", register);
|
|
7039
2531
|
var auth_default = router;
|
|
7040
2532
|
|
|
@@ -7043,15 +2535,37 @@ import { Router as Router2 } from "express";
|
|
|
7043
2535
|
|
|
7044
2536
|
// ../core/dist/middlewares/authenticate.js
|
|
7045
2537
|
import jwt2 from "jsonwebtoken";
|
|
7046
|
-
function
|
|
2538
|
+
function cookieValue(raw, key) {
|
|
2539
|
+
if (!raw)
|
|
2540
|
+
return null;
|
|
2541
|
+
const parts = raw.split(";");
|
|
2542
|
+
for (const part of parts) {
|
|
2543
|
+
const [k3, ...rest] = part.trim().split("=");
|
|
2544
|
+
if (k3 === key)
|
|
2545
|
+
return decodeURIComponent(rest.join("="));
|
|
2546
|
+
}
|
|
2547
|
+
return null;
|
|
2548
|
+
}
|
|
2549
|
+
async function authenticate(req, res, next) {
|
|
7047
2550
|
const header = req.headers.authorization;
|
|
7048
|
-
|
|
2551
|
+
const bearer = header?.startsWith("Bearer ") ? header.slice(7) : null;
|
|
2552
|
+
const cookieToken = cookieValue(req.headers.cookie, "plank_session");
|
|
2553
|
+
const token = bearer ?? cookieToken;
|
|
2554
|
+
if (!token) {
|
|
7049
2555
|
res.status(401).json({ error: "Unauthorized" });
|
|
7050
2556
|
return;
|
|
7051
2557
|
}
|
|
7052
|
-
const token = header.slice(7);
|
|
7053
2558
|
try {
|
|
7054
2559
|
const payload = jwt2.verify(token, process.env.PLANK_JWT_SECRET);
|
|
2560
|
+
if (typeof payload.sv !== "number") {
|
|
2561
|
+
res.status(401).json({ error: "Invalid session token" });
|
|
2562
|
+
return;
|
|
2563
|
+
}
|
|
2564
|
+
const { rows } = await pool_default.query("SELECT session_version FROM plank_users WHERE id = $1", [payload.sub]);
|
|
2565
|
+
if (!rows[0] || rows[0].session_version !== payload.sv) {
|
|
2566
|
+
res.status(401).json({ error: "Session has been revoked" });
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
7055
2569
|
req.user = { id: payload.sub, roleId: payload.roleId };
|
|
7056
2570
|
next();
|
|
7057
2571
|
} catch {
|
|
@@ -7919,7 +3433,6 @@ var deleteEntry = async (req, res) => {
|
|
|
7919
3433
|
|
|
7920
3434
|
// ../core/dist/controllers/users.js
|
|
7921
3435
|
import bcrypt2 from "bcryptjs";
|
|
7922
|
-
var import_qrcode = __toESM(require_lib(), 1);
|
|
7923
3436
|
import { z as z4, flattenError as flattenError4 } from "zod";
|
|
7924
3437
|
var CreateUserSchema = z4.object({
|
|
7925
3438
|
email: z4.email(),
|
|
@@ -7946,6 +3459,10 @@ var UpdateMeSchema = z4.object({
|
|
|
7946
3459
|
var TwoFactorCodeSchema = z4.object({
|
|
7947
3460
|
code: z4.string().trim().length(6)
|
|
7948
3461
|
});
|
|
3462
|
+
var DisableTwoFactorSchema = z4.object({
|
|
3463
|
+
password: z4.string().min(1),
|
|
3464
|
+
code: z4.string().trim().length(6)
|
|
3465
|
+
});
|
|
7949
3466
|
async function resolveAvatarUrl(row) {
|
|
7950
3467
|
if (!row.avatar_url || row.avatar_url.startsWith("http"))
|
|
7951
3468
|
return row;
|
|
@@ -8000,10 +3517,8 @@ async function startTwoFactorSetup(req, res) {
|
|
|
8000
3517
|
encrypt(secret),
|
|
8001
3518
|
req.user.id
|
|
8002
3519
|
]);
|
|
8003
|
-
const
|
|
8004
|
-
|
|
8005
|
-
const qrCodeDataUrl = await import_qrcode.default.toDataURL(otpauthUri);
|
|
8006
|
-
res.json({ otpauthUri, qrCodeDataUrl, secret });
|
|
3520
|
+
const otpauthUri = T2({ issuer: "Plank CMS", label: rows[0].email, secret });
|
|
3521
|
+
res.json({ otpauthUri, secret });
|
|
8007
3522
|
}
|
|
8008
3523
|
async function verifyTwoFactorSetup(req, res) {
|
|
8009
3524
|
const parsed = TwoFactorCodeSchema.safeParse(req.body);
|
|
@@ -8025,17 +3540,18 @@ async function verifyTwoFactorSetup(req, res) {
|
|
|
8025
3540
|
await pool_default.query(`UPDATE plank_users
|
|
8026
3541
|
SET two_factor_enabled = TRUE,
|
|
8027
3542
|
two_factor_secret = two_factor_temp_secret,
|
|
8028
|
-
two_factor_temp_secret = NULL
|
|
3543
|
+
two_factor_temp_secret = NULL,
|
|
3544
|
+
session_version = session_version + 1
|
|
8029
3545
|
WHERE id = $1`, [req.user.id]);
|
|
8030
3546
|
res.status(204).end();
|
|
8031
3547
|
}
|
|
8032
3548
|
async function disableTwoFactor(req, res) {
|
|
8033
|
-
const parsed =
|
|
3549
|
+
const parsed = DisableTwoFactorSchema.safeParse(req.body);
|
|
8034
3550
|
if (!parsed.success) {
|
|
8035
3551
|
res.status(400).json({ errors: flattenError4(parsed.error, (i2) => i2.message) });
|
|
8036
3552
|
return;
|
|
8037
3553
|
}
|
|
8038
|
-
const { rows } = await pool_default.query("SELECT two_factor_enabled, two_factor_secret FROM plank_users WHERE id = $1", [req.user.id]);
|
|
3554
|
+
const { rows } = await pool_default.query("SELECT two_factor_enabled, two_factor_secret, password FROM plank_users WHERE id = $1", [req.user.id]);
|
|
8039
3555
|
const user = rows[0];
|
|
8040
3556
|
if (!user) {
|
|
8041
3557
|
res.status(404).json({ error: "User not found" });
|
|
@@ -8045,6 +3561,11 @@ async function disableTwoFactor(req, res) {
|
|
|
8045
3561
|
res.status(400).json({ error: "2FA is not enabled" });
|
|
8046
3562
|
return;
|
|
8047
3563
|
}
|
|
3564
|
+
const passwordOk = await bcrypt2.compare(parsed.data.password, user.password);
|
|
3565
|
+
if (!passwordOk) {
|
|
3566
|
+
res.status(401).json({ error: "Current password is incorrect" });
|
|
3567
|
+
return;
|
|
3568
|
+
}
|
|
8048
3569
|
const result = d3({
|
|
8049
3570
|
token: parsed.data.code,
|
|
8050
3571
|
secret: decrypt(user.two_factor_secret)
|
|
@@ -8056,7 +3577,8 @@ async function disableTwoFactor(req, res) {
|
|
|
8056
3577
|
await pool_default.query(`UPDATE plank_users
|
|
8057
3578
|
SET two_factor_enabled = FALSE,
|
|
8058
3579
|
two_factor_secret = NULL,
|
|
8059
|
-
two_factor_temp_secret = NULL
|
|
3580
|
+
two_factor_temp_secret = NULL,
|
|
3581
|
+
session_version = session_version + 1
|
|
8060
3582
|
WHERE id = $1`, [req.user.id]);
|
|
8061
3583
|
res.status(204).end();
|
|
8062
3584
|
}
|
|
@@ -8148,7 +3670,7 @@ async function changePassword(req, res) {
|
|
|
8148
3670
|
return;
|
|
8149
3671
|
}
|
|
8150
3672
|
const hashed = await bcrypt2.hash(parsed.data.newPassword, 12);
|
|
8151
|
-
await pool_default.query("UPDATE plank_users SET password = $1 WHERE id = $2", [hashed, req.user.id]);
|
|
3673
|
+
await pool_default.query("UPDATE plank_users SET password = $1, session_version = session_version + 1 WHERE id = $2", [hashed, req.user.id]);
|
|
8152
3674
|
res.status(204).end();
|
|
8153
3675
|
}
|
|
8154
3676
|
async function createUser(req, res) {
|
|
@@ -8968,6 +4490,17 @@ function errorHandler(err, _req, res, _next) {
|
|
|
8968
4490
|
}
|
|
8969
4491
|
|
|
8970
4492
|
// ../core/dist/app.js
|
|
4493
|
+
function assertSecurityEnv() {
|
|
4494
|
+
if (process.env.NODE_ENV !== "production")
|
|
4495
|
+
return;
|
|
4496
|
+
if (!process.env.PLANK_JWT_SECRET || process.env.PLANK_JWT_SECRET.length < 32) {
|
|
4497
|
+
throw new Error("PLANK_JWT_SECRET is required in production and should be at least 32 characters.");
|
|
4498
|
+
}
|
|
4499
|
+
if (!process.env.PLANK_ENCRYPTION_KEY || process.env.PLANK_ENCRYPTION_KEY.length !== 64) {
|
|
4500
|
+
throw new Error("PLANK_ENCRYPTION_KEY is required in production and must be 64 hex characters.");
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
assertSecurityEnv();
|
|
8971
4504
|
var app = express();
|
|
8972
4505
|
app.use(helmet({
|
|
8973
4506
|
contentSecurityPolicy: {
|