qreator 9.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +92 -0
- package/lib/browser/encode.d.ts +2 -0
- package/lib/browser/errorcode.d.ts +1 -0
- package/lib/browser/matrix.d.ts +9 -0
- package/lib/browser/pdf.d.ts +2 -0
- package/lib/browser/pdf.umd.js +26816 -0
- package/lib/browser/pdf.umd.js.map +1 -0
- package/lib/browser/png.d.ts +6 -0
- package/lib/browser/png.umd.js +1540 -0
- package/lib/browser/png.umd.js.map +1 -0
- package/lib/browser/png_browser.d.ts +5 -0
- package/lib/browser/qr-base.d.ts +4 -0
- package/lib/browser/qr.d.ts +2 -0
- package/lib/browser/svg.d.ts +7 -0
- package/lib/browser/svg.umd.js +1536 -0
- package/lib/browser/svg.umd.js.map +1 -0
- package/lib/browser/tests/_common.d.ts +4 -0
- package/lib/browser/tests/browser.test.d.ts +1 -0
- package/lib/browser/tests/test.d.ts +1 -0
- package/lib/browser/typing/types.d.ts +28 -0
- package/lib/browser/utils.d.ts +17 -0
- package/lib/encode.d.ts +2 -0
- package/lib/encode.js +137 -0
- package/lib/encode.js.map +1 -0
- package/lib/errorcode.d.ts +1 -0
- package/lib/errorcode.js +62 -0
- package/lib/errorcode.js.map +1 -0
- package/lib/matrix.d.ts +9 -0
- package/lib/matrix.js +347 -0
- package/lib/matrix.js.map +1 -0
- package/lib/pdf.d.ts +2 -0
- package/lib/pdf.js +64 -0
- package/lib/pdf.js.map +1 -0
- package/lib/png.d.ts +6 -0
- package/lib/png.js +30 -0
- package/lib/png.js.map +1 -0
- package/lib/png_browser.d.ts +5 -0
- package/lib/png_browser.js +53 -0
- package/lib/png_browser.js.map +1 -0
- package/lib/qr-base.d.ts +4 -0
- package/lib/qr-base.js +151 -0
- package/lib/qr-base.js.map +1 -0
- package/lib/qr.d.ts +2 -0
- package/lib/qr.js +2 -0
- package/lib/qr.js.map +1 -0
- package/lib/svg.d.ts +7 -0
- package/lib/svg.js +49 -0
- package/lib/svg.js.map +1 -0
- package/lib/tests/_common.d.ts +4 -0
- package/lib/tests/_common.js +36 -0
- package/lib/tests/_common.js.map +1 -0
- package/lib/tests/browser.test.d.ts +1 -0
- package/lib/tests/browser.test.js +193 -0
- package/lib/tests/browser.test.js.map +1 -0
- package/lib/tests/test.d.ts +1 -0
- package/lib/tests/test.js +238 -0
- package/lib/tests/test.js.map +1 -0
- package/lib/typing/types.d.ts +28 -0
- package/lib/typing/types.js +2 -0
- package/lib/typing/types.js.map +1 -0
- package/lib/utils.d.ts +17 -0
- package/lib/utils.js +68 -0
- package/lib/utils.js.map +1 -0
- package/package.json +105 -0
- package/src/encode.ts +176 -0
- package/src/errorcode.ts +75 -0
- package/src/matrix.ts +393 -0
- package/src/pdf.ts +80 -0
- package/src/png.ts +42 -0
- package/src/png_browser.ts +73 -0
- package/src/qr-base.ts +180 -0
- package/src/qr.ts +2 -0
- package/src/svg.ts +89 -0
- package/src/tests/_common.ts +40 -0
- package/src/tests/browser.test.ts +209 -0
- package/src/tests/test.ts +250 -0
- package/src/typing/index.d.ts +5 -0
- package/src/typing/types.ts +99 -0
- package/src/utils.ts +86 -0
|
@@ -0,0 +1,1540 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pngQrCode = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const enc = new TextEncoder();
|
|
8
|
+
const dec = new TextDecoder();
|
|
9
|
+
function encode$1(inData, parse_url) {
|
|
10
|
+
let str;
|
|
11
|
+
let data;
|
|
12
|
+
if (typeof inData === "string" || typeof inData === "number") {
|
|
13
|
+
str = `${inData}`;
|
|
14
|
+
data = enc.encode(str);
|
|
15
|
+
}
|
|
16
|
+
else if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
|
|
17
|
+
str = inData.toString();
|
|
18
|
+
}
|
|
19
|
+
else if (Array.isArray(inData)) {
|
|
20
|
+
data = new Uint8Array(inData);
|
|
21
|
+
str = dec.decode(inData);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error("Bad data: " + typeof inData);
|
|
25
|
+
}
|
|
26
|
+
if (/^[0-9]+$/.test(str)) {
|
|
27
|
+
if (data.byteLength > 7089) {
|
|
28
|
+
throw new Error("Too much data");
|
|
29
|
+
}
|
|
30
|
+
return encode_numeric(str);
|
|
31
|
+
}
|
|
32
|
+
if (/^[0-9A-Z \$%\*\+\.\/\:\-]+$/.test(str)) {
|
|
33
|
+
if (data.byteLength > 4296) {
|
|
34
|
+
throw new Error("Too much data");
|
|
35
|
+
}
|
|
36
|
+
return encode_alphanum(str);
|
|
37
|
+
}
|
|
38
|
+
if (parse_url && /^https?:/i.test(str)) {
|
|
39
|
+
return encode_url(str);
|
|
40
|
+
}
|
|
41
|
+
if (data.byteLength > 2953) {
|
|
42
|
+
throw new Error("Too much data");
|
|
43
|
+
}
|
|
44
|
+
return encode_8bit(new Uint8Array(data));
|
|
45
|
+
}
|
|
46
|
+
function pushBits(arr, n, value) {
|
|
47
|
+
for (let bit = 1 << (n - 1); bit; bit >>>= 1) {
|
|
48
|
+
arr.push(bit & value ? 1 : 0);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function encode_8bit(data) {
|
|
52
|
+
const len = data.byteLength;
|
|
53
|
+
const bits = [];
|
|
54
|
+
for (let i = 0; i < len; i++) {
|
|
55
|
+
pushBits(bits, 8, data[i]);
|
|
56
|
+
}
|
|
57
|
+
const res = {};
|
|
58
|
+
let d = [0, 1, 0, 0];
|
|
59
|
+
pushBits(d, 16, len);
|
|
60
|
+
res.data10 = res.data27 = d.concat(bits);
|
|
61
|
+
if (len < 256) {
|
|
62
|
+
let d = [0, 1, 0, 0];
|
|
63
|
+
pushBits(d, 8, len);
|
|
64
|
+
res.data1 = d.concat(bits);
|
|
65
|
+
}
|
|
66
|
+
return res;
|
|
67
|
+
}
|
|
68
|
+
const ALPHANUM = (function (s) {
|
|
69
|
+
const res = {};
|
|
70
|
+
for (let i = 0; i < s.length; i++) {
|
|
71
|
+
res[s[i]] = i;
|
|
72
|
+
}
|
|
73
|
+
return res;
|
|
74
|
+
})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:");
|
|
75
|
+
function encode_alphanum(str) {
|
|
76
|
+
const len = str.length;
|
|
77
|
+
const bits = [];
|
|
78
|
+
for (let i = 0; i < len; i += 2) {
|
|
79
|
+
let b = 6;
|
|
80
|
+
let n = ALPHANUM[str[i]];
|
|
81
|
+
if (str[i + 1]) {
|
|
82
|
+
b = 11;
|
|
83
|
+
n = n * 45 + ALPHANUM[str[i + 1]];
|
|
84
|
+
}
|
|
85
|
+
pushBits(bits, b, n);
|
|
86
|
+
}
|
|
87
|
+
const res = {};
|
|
88
|
+
let d = [0, 0, 1, 0];
|
|
89
|
+
pushBits(d, 13, len);
|
|
90
|
+
res.data27 = d.concat(bits);
|
|
91
|
+
if (len < 2048) {
|
|
92
|
+
let d = [0, 0, 1, 0];
|
|
93
|
+
pushBits(d, 11, len);
|
|
94
|
+
res.data10 = d.concat(bits);
|
|
95
|
+
}
|
|
96
|
+
if (len < 512) {
|
|
97
|
+
let d = [0, 0, 1, 0];
|
|
98
|
+
pushBits(d, 9, len);
|
|
99
|
+
res.data1 = d.concat(bits);
|
|
100
|
+
}
|
|
101
|
+
return res;
|
|
102
|
+
}
|
|
103
|
+
function encode_numeric(str) {
|
|
104
|
+
const len = str.length;
|
|
105
|
+
const bits = [];
|
|
106
|
+
for (let i = 0; i < len; i += 3) {
|
|
107
|
+
const s = str.substr(i, 3);
|
|
108
|
+
const b = Math.ceil((s.length * 10) / 3);
|
|
109
|
+
pushBits(bits, b, parseInt(s, 10));
|
|
110
|
+
}
|
|
111
|
+
const res = {};
|
|
112
|
+
let d = [0, 0, 0, 1];
|
|
113
|
+
pushBits(d, 14, len);
|
|
114
|
+
res.data27 = d.concat(bits);
|
|
115
|
+
if (len < 4096) {
|
|
116
|
+
let d = [0, 0, 0, 1];
|
|
117
|
+
pushBits(d, 12, len);
|
|
118
|
+
res.data10 = d.concat(bits);
|
|
119
|
+
}
|
|
120
|
+
if (len < 1024) {
|
|
121
|
+
let d = [0, 0, 0, 1];
|
|
122
|
+
pushBits(d, 10, len);
|
|
123
|
+
res.data1 = d.concat(bits);
|
|
124
|
+
}
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
127
|
+
function encode_url(str) {
|
|
128
|
+
const slash = str.indexOf("/", 8) + 1 || str.length;
|
|
129
|
+
const res = encode$1(str.slice(0, slash).toUpperCase(), false);
|
|
130
|
+
if (slash >= str.length) {
|
|
131
|
+
return res;
|
|
132
|
+
}
|
|
133
|
+
const path_res = encode$1(str.slice(slash), false);
|
|
134
|
+
res.data27 = res.data27.concat(path_res.data27);
|
|
135
|
+
if (res.data10 && path_res.data10) {
|
|
136
|
+
res.data10 = res.data10.concat(path_res.data10);
|
|
137
|
+
}
|
|
138
|
+
if (res.data1 && path_res.data1) {
|
|
139
|
+
res.data1 = res.data1.concat(path_res.data1);
|
|
140
|
+
}
|
|
141
|
+
return res;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function calculateEC(msg, ec_len) {
|
|
145
|
+
msg = [].slice.call(msg);
|
|
146
|
+
const poly = generatorPolynomial(ec_len);
|
|
147
|
+
for (let i = 0; i < ec_len; i++)
|
|
148
|
+
msg.push(0);
|
|
149
|
+
while (msg.length > ec_len) {
|
|
150
|
+
if (!msg[0]) {
|
|
151
|
+
msg.shift();
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const log_k = log(msg[0]);
|
|
155
|
+
for (let i = 0; i <= ec_len; i++) {
|
|
156
|
+
msg[i] = msg[i] ^ exp(poly[i] + log_k);
|
|
157
|
+
}
|
|
158
|
+
msg.shift();
|
|
159
|
+
}
|
|
160
|
+
return new Uint8Array(msg);
|
|
161
|
+
}
|
|
162
|
+
const GF256_BASE = 285;
|
|
163
|
+
const EXP_TABLE = [1];
|
|
164
|
+
const LOG_TABLE = [];
|
|
165
|
+
for (let i = 1; i < 256; i++) {
|
|
166
|
+
let n = EXP_TABLE[i - 1] << 1;
|
|
167
|
+
if (n > 255)
|
|
168
|
+
n ^= GF256_BASE;
|
|
169
|
+
EXP_TABLE[i] = n;
|
|
170
|
+
}
|
|
171
|
+
for (let i = 0; i < 255; i++) {
|
|
172
|
+
LOG_TABLE[EXP_TABLE[i]] = i;
|
|
173
|
+
}
|
|
174
|
+
function exp(k) {
|
|
175
|
+
while (k < 0)
|
|
176
|
+
k += 255;
|
|
177
|
+
while (k > 255)
|
|
178
|
+
k -= 255;
|
|
179
|
+
return EXP_TABLE[k];
|
|
180
|
+
}
|
|
181
|
+
function log(k) {
|
|
182
|
+
if (k < 1 || k > 255) {
|
|
183
|
+
throw Error(`Bad log(${k})`);
|
|
184
|
+
}
|
|
185
|
+
return LOG_TABLE[k];
|
|
186
|
+
}
|
|
187
|
+
const POLYNOMIALS = [
|
|
188
|
+
[0],
|
|
189
|
+
[0, 0],
|
|
190
|
+
[0, 25, 1],
|
|
191
|
+
];
|
|
192
|
+
function generatorPolynomial(num) {
|
|
193
|
+
if (POLYNOMIALS[num]) {
|
|
194
|
+
return POLYNOMIALS[num];
|
|
195
|
+
}
|
|
196
|
+
const prev = generatorPolynomial(num - 1);
|
|
197
|
+
const res = [];
|
|
198
|
+
res[0] = prev[0];
|
|
199
|
+
for (let i = 1; i <= num; i++) {
|
|
200
|
+
res[i] = log(exp(prev[i]) ^ exp(prev[i - 1] + num - 1));
|
|
201
|
+
}
|
|
202
|
+
POLYNOMIALS[num] = res;
|
|
203
|
+
return res;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function init(version) {
|
|
207
|
+
const N = (version << 2) + 0b10001;
|
|
208
|
+
const matrix = [];
|
|
209
|
+
let zeros = Array(N).fill(0);
|
|
210
|
+
for (let i = 0; i < N; i++) {
|
|
211
|
+
matrix[i] = [...zeros];
|
|
212
|
+
}
|
|
213
|
+
return matrix;
|
|
214
|
+
}
|
|
215
|
+
function fillFinders(matrix) {
|
|
216
|
+
const N = matrix.length;
|
|
217
|
+
for (var i = -3; i <= 3; i++) {
|
|
218
|
+
for (let j = -3; j <= 3; j++) {
|
|
219
|
+
const max = Math.max(i, j);
|
|
220
|
+
const min = Math.min(i, j);
|
|
221
|
+
const pixel = (max == 2 && min >= -2) || (min == -2 && max <= 2)
|
|
222
|
+
? 0x80
|
|
223
|
+
: 0x81;
|
|
224
|
+
matrix[3 + i][3 + j] = pixel;
|
|
225
|
+
matrix[3 + i][N - 4 + j] = pixel;
|
|
226
|
+
matrix[N - 4 + i][3 + j] = pixel;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
for (var i = 0; i < 8; i++) {
|
|
230
|
+
matrix[7][i] =
|
|
231
|
+
matrix[i][7] =
|
|
232
|
+
matrix[7][N - i - 1] =
|
|
233
|
+
matrix[i][N - 8] =
|
|
234
|
+
matrix[N - 8][i] =
|
|
235
|
+
matrix[N - 1 - i][7] =
|
|
236
|
+
0x80;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function fillAlignAndTiming(matrix) {
|
|
240
|
+
const N = matrix.length;
|
|
241
|
+
if (N > 21) {
|
|
242
|
+
const len = N - 13;
|
|
243
|
+
let delta = Math.round(len / Math.ceil(len / 28));
|
|
244
|
+
if (delta % 2)
|
|
245
|
+
delta++;
|
|
246
|
+
const res = [];
|
|
247
|
+
for (let p = len + 6; p > 10; p -= delta) {
|
|
248
|
+
res.unshift(p);
|
|
249
|
+
}
|
|
250
|
+
res.unshift(6);
|
|
251
|
+
for (var i = 0; i < res.length; i++) {
|
|
252
|
+
for (let j = 0; j < res.length; j++) {
|
|
253
|
+
const x = res[i];
|
|
254
|
+
const y = res[j];
|
|
255
|
+
if (matrix[x][y])
|
|
256
|
+
continue;
|
|
257
|
+
for (let r = -2; r <= 2; r++) {
|
|
258
|
+
for (let c = -2; c <= 2; c++) {
|
|
259
|
+
const max = Math.max(r, c);
|
|
260
|
+
const min = Math.min(r, c);
|
|
261
|
+
const pixel = (max == 1 && min >= -1) || (min == -1 && max <= 1)
|
|
262
|
+
? 0x80
|
|
263
|
+
: 0x81;
|
|
264
|
+
matrix[x + r][y + c] = pixel;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (var i = 8; i < N - 8; i++) {
|
|
271
|
+
matrix[6][i] = matrix[i][6] = i % 2 ? 0x80 : 0x81;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function fillStub(matrix) {
|
|
275
|
+
const N = matrix.length;
|
|
276
|
+
for (var i = 0; i < 8; i++) {
|
|
277
|
+
if (i != 6) {
|
|
278
|
+
matrix[8][i] = matrix[i][8] = 0x80;
|
|
279
|
+
}
|
|
280
|
+
matrix[8][N - 1 - i] = 0x80;
|
|
281
|
+
matrix[N - 1 - i][8] = 0x80;
|
|
282
|
+
}
|
|
283
|
+
matrix[8][8] = 0x80;
|
|
284
|
+
matrix[N - 8][8] = 0x81;
|
|
285
|
+
if (N < 45)
|
|
286
|
+
return;
|
|
287
|
+
for (var i = N - 11; i < N - 8; i++) {
|
|
288
|
+
for (let j = 0; j < 6; j++) {
|
|
289
|
+
matrix[i][j] = matrix[j][i] = 0x80;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const fillReserved = (function () {
|
|
294
|
+
const FORMATS = Array(32);
|
|
295
|
+
const VERSIONS = Array(40);
|
|
296
|
+
const gf15 = 0x0537;
|
|
297
|
+
const gf18 = 0x1f25;
|
|
298
|
+
const formats_mask = 0x5412;
|
|
299
|
+
for (let format = 0; format < 32; format++) {
|
|
300
|
+
let res = format << 10;
|
|
301
|
+
for (let i = 5; i > 0; i--) {
|
|
302
|
+
if (res >>> (9 + i)) {
|
|
303
|
+
res ^= gf15 << (i - 1);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
FORMATS[format] = (res | (format << 10)) ^ formats_mask;
|
|
307
|
+
}
|
|
308
|
+
for (let version = 7; version <= 40; version++) {
|
|
309
|
+
let res = version << 12;
|
|
310
|
+
for (let i = 6; i > 0; i--) {
|
|
311
|
+
if (res >>> (11 + i)) {
|
|
312
|
+
res ^= gf18 << (i - 1);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
VERSIONS[version] = res | (version << 12);
|
|
316
|
+
}
|
|
317
|
+
const EC_LEVELS = {
|
|
318
|
+
L: 1,
|
|
319
|
+
M: 0,
|
|
320
|
+
Q: 3,
|
|
321
|
+
H: 2,
|
|
322
|
+
};
|
|
323
|
+
return function fillReserved(matrix, ec_level, mask) {
|
|
324
|
+
const N = matrix.length;
|
|
325
|
+
const format = FORMATS[(EC_LEVELS[ec_level] << 3) | mask];
|
|
326
|
+
function F(k) {
|
|
327
|
+
return (format >> k) & 1 ? 0x81 : 0x80;
|
|
328
|
+
}
|
|
329
|
+
for (var i = 0; i < 8; i++) {
|
|
330
|
+
matrix[8][N - 1 - i] = F(i);
|
|
331
|
+
if (i < 6)
|
|
332
|
+
matrix[i][8] = F(i);
|
|
333
|
+
}
|
|
334
|
+
for (var i = 8; i < 15; i++) {
|
|
335
|
+
matrix[N - 15 + i][8] = F(i);
|
|
336
|
+
if (i > 8)
|
|
337
|
+
matrix[8][14 - i] = F(i);
|
|
338
|
+
}
|
|
339
|
+
matrix[7][8] = F(6);
|
|
340
|
+
matrix[8][8] = F(7);
|
|
341
|
+
matrix[8][7] = F(8);
|
|
342
|
+
const version = VERSIONS[(N - 17) / 4];
|
|
343
|
+
if (!version) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
function V(k) {
|
|
347
|
+
return (version >> k) & 1 ? 0x81 : 0x80;
|
|
348
|
+
}
|
|
349
|
+
for (var i = 0; i < 6; i++) {
|
|
350
|
+
for (let j = 0; j < 3; j++) {
|
|
351
|
+
matrix[N - 11 + j][i] = matrix[i][N - 11 + j] = V(i * 3 + j);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
})();
|
|
356
|
+
const fillData = (function () {
|
|
357
|
+
const MASK_FUNCTIONS = [
|
|
358
|
+
(i, j) => (i + j) % 2 == 0,
|
|
359
|
+
(i, j) => i % 2 == 0,
|
|
360
|
+
(i, j) => j % 3 == 0,
|
|
361
|
+
(i, j) => (i + j) % 3 == 0,
|
|
362
|
+
(i, j) => (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0,
|
|
363
|
+
(i, j) => ((i * j) % 2) + ((i * j) % 3) == 0,
|
|
364
|
+
(i, j) => (((i * j) % 2) + ((i * j) % 3)) % 2 == 0,
|
|
365
|
+
(i, j) => (((i * j) % 3) + ((i + j) % 2)) % 2 == 0,
|
|
366
|
+
];
|
|
367
|
+
return function fillData(matrix, data, mask) {
|
|
368
|
+
const N = matrix.length;
|
|
369
|
+
let row;
|
|
370
|
+
let col;
|
|
371
|
+
let dir = -1;
|
|
372
|
+
row = col = N - 1;
|
|
373
|
+
const mask_fn = MASK_FUNCTIONS[mask];
|
|
374
|
+
let len = data.blocks[data.blocks.length - 1].length;
|
|
375
|
+
for (var i = 0; i < len; i++) {
|
|
376
|
+
for (var b = 0; b < data.blocks.length; b++) {
|
|
377
|
+
if (data.blocks[b].length <= i) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
put(data.blocks[b][i]);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
len = data.ec_len;
|
|
384
|
+
for (var i = 0; i < len; i++) {
|
|
385
|
+
for (var b = 0; b < data.ec.length; b++) {
|
|
386
|
+
put(data.ec[b][i]);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (col > -1) {
|
|
390
|
+
do {
|
|
391
|
+
matrix[row][col] = mask_fn(row, col) ? 1 : 0;
|
|
392
|
+
} while (next());
|
|
393
|
+
}
|
|
394
|
+
function put(byte) {
|
|
395
|
+
for (let mask = 0x80; mask; mask >>= 1) {
|
|
396
|
+
let pixel = !!(mask & byte);
|
|
397
|
+
if (mask_fn(row, col))
|
|
398
|
+
pixel = !pixel;
|
|
399
|
+
matrix[row][col] = pixel ? 1 : 0;
|
|
400
|
+
next();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function next() {
|
|
404
|
+
do {
|
|
405
|
+
if (col % 2 ^ Number(col < 6)) {
|
|
406
|
+
if ((dir < 0 && row == 0) || (dir > 0 && row == N - 1)) {
|
|
407
|
+
col--;
|
|
408
|
+
dir = -dir;
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
col++;
|
|
412
|
+
row += dir;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
col--;
|
|
417
|
+
}
|
|
418
|
+
if (col == 6) {
|
|
419
|
+
col--;
|
|
420
|
+
}
|
|
421
|
+
if (col < 0) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
} while (matrix[row][col] & 0xf0);
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
})();
|
|
429
|
+
function calculatePenalty(matrix) {
|
|
430
|
+
const N = matrix.length;
|
|
431
|
+
let penalty = 0;
|
|
432
|
+
for (var i = 0; i < N; i++) {
|
|
433
|
+
var pixel = matrix[i][0] & 1;
|
|
434
|
+
var len = 1;
|
|
435
|
+
for (var j = 1; j < N; j++) {
|
|
436
|
+
var p = matrix[i][j] & 1;
|
|
437
|
+
if (p == pixel) {
|
|
438
|
+
len++;
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (len >= 5) {
|
|
442
|
+
penalty += len - 2;
|
|
443
|
+
}
|
|
444
|
+
pixel = p;
|
|
445
|
+
len = 1;
|
|
446
|
+
}
|
|
447
|
+
if (len >= 5) {
|
|
448
|
+
penalty += len - 2;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
for (var j = 0; j < N; j++) {
|
|
452
|
+
var pixel = matrix[0][j] & 1;
|
|
453
|
+
var len = 1;
|
|
454
|
+
for (var i = 1; i < N; i++) {
|
|
455
|
+
var p = matrix[i][j] & 1;
|
|
456
|
+
if (p == pixel) {
|
|
457
|
+
len++;
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (len >= 5) {
|
|
461
|
+
penalty += len - 2;
|
|
462
|
+
}
|
|
463
|
+
pixel = p;
|
|
464
|
+
len = 1;
|
|
465
|
+
}
|
|
466
|
+
if (len >= 5) {
|
|
467
|
+
penalty += len - 2;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
for (var i = 0; i < N - 1; i++) {
|
|
471
|
+
for (var j = 0; j < N - 1; j++) {
|
|
472
|
+
const s = (matrix[i][j] +
|
|
473
|
+
matrix[i][j + 1] +
|
|
474
|
+
matrix[i + 1][j] +
|
|
475
|
+
matrix[i + 1][j + 1]) &
|
|
476
|
+
7;
|
|
477
|
+
if (s == 0 || s == 4) {
|
|
478
|
+
penalty += 3;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function I(k) {
|
|
483
|
+
return matrix[i][j + k] & 1;
|
|
484
|
+
}
|
|
485
|
+
function J(k) {
|
|
486
|
+
return matrix[i + k][j] & 1;
|
|
487
|
+
}
|
|
488
|
+
for (var i = 0; i < N; i++) {
|
|
489
|
+
for (var j = 0; j < N; j++) {
|
|
490
|
+
if (j < N - 6 &&
|
|
491
|
+
I(0) &&
|
|
492
|
+
!I(1) &&
|
|
493
|
+
I(2) &&
|
|
494
|
+
I(3) &&
|
|
495
|
+
I(4) &&
|
|
496
|
+
!I(5) &&
|
|
497
|
+
I(6)) {
|
|
498
|
+
if (j >= 4 && !(I(-4) || I(-3) || I(-2) || I(-1))) {
|
|
499
|
+
penalty += 40;
|
|
500
|
+
}
|
|
501
|
+
if (j < N - 10 && !(I(7) || I(8) || I(9) || I(10))) {
|
|
502
|
+
penalty += 40;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (i < N - 6 &&
|
|
506
|
+
J(0) &&
|
|
507
|
+
!J(1) &&
|
|
508
|
+
J(2) &&
|
|
509
|
+
J(3) &&
|
|
510
|
+
J(4) &&
|
|
511
|
+
!J(5) &&
|
|
512
|
+
J(6)) {
|
|
513
|
+
if (i >= 4 && !(J(-4) || J(-3) || J(-2) || J(-1))) {
|
|
514
|
+
penalty += 40;
|
|
515
|
+
}
|
|
516
|
+
if (i < N - 10 && !(J(7) || J(8) || J(9) || J(10))) {
|
|
517
|
+
penalty += 40;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
let numDark = 0;
|
|
523
|
+
for (var i = 0; i < N; i++) {
|
|
524
|
+
for (var j = 0; j < N; j++) {
|
|
525
|
+
if (matrix[i][j] & 1)
|
|
526
|
+
numDark++;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
penalty += 10 * Math.floor(Math.abs(10 - (20 * numDark) / (N * N)));
|
|
530
|
+
return penalty;
|
|
531
|
+
}
|
|
532
|
+
function getMatrix(data) {
|
|
533
|
+
const matrix = init(data.version);
|
|
534
|
+
fillFinders(matrix);
|
|
535
|
+
fillAlignAndTiming(matrix);
|
|
536
|
+
fillStub(matrix);
|
|
537
|
+
let penalty = Infinity;
|
|
538
|
+
let bestMask = 0;
|
|
539
|
+
for (let mask = 0; mask < 8; mask++) {
|
|
540
|
+
fillData(matrix, data, mask);
|
|
541
|
+
fillReserved(matrix, data.ec_level, mask);
|
|
542
|
+
const p = calculatePenalty(matrix);
|
|
543
|
+
if (p < penalty) {
|
|
544
|
+
penalty = p;
|
|
545
|
+
bestMask = mask;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
fillData(matrix, data, bestMask);
|
|
549
|
+
fillReserved(matrix, data.ec_level, bestMask);
|
|
550
|
+
return matrix.map((row) => row.map((cell) => cell & 1));
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const EC_LEVELS = ["L", "M", "Q", "H"];
|
|
554
|
+
function getTemplate(message, ec_level) {
|
|
555
|
+
let i = 1;
|
|
556
|
+
let len;
|
|
557
|
+
if (message.data1) {
|
|
558
|
+
len = Math.ceil(message.data1.length / 8);
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
i = 10;
|
|
562
|
+
}
|
|
563
|
+
for (; i < 10; i++) {
|
|
564
|
+
let version = mappedVersions[i][ec_level];
|
|
565
|
+
if (version.data_len >= len) {
|
|
566
|
+
return deepCopy(version);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (message.data10) {
|
|
570
|
+
len = Math.ceil(message.data10.length / 8);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
i = 27;
|
|
574
|
+
}
|
|
575
|
+
for (; i < 27; i++) {
|
|
576
|
+
let version = mappedVersions[i][ec_level];
|
|
577
|
+
if (version.data_len >= len) {
|
|
578
|
+
return deepCopy(version);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
len = Math.ceil(message.data27.length / 8);
|
|
582
|
+
for (; i < 41; i++) {
|
|
583
|
+
let version = mappedVersions[i][ec_level];
|
|
584
|
+
if (version.data_len >= len) {
|
|
585
|
+
return deepCopy(version);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
throw new Error("Too much data");
|
|
589
|
+
}
|
|
590
|
+
function fillTemplate(message, template) {
|
|
591
|
+
const blocks = new Uint8Array(template.data_len);
|
|
592
|
+
let messageUpdated;
|
|
593
|
+
if (template.version < 10) {
|
|
594
|
+
messageUpdated = message.data1;
|
|
595
|
+
}
|
|
596
|
+
else if (template.version < 27) {
|
|
597
|
+
messageUpdated = message.data10;
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
messageUpdated = message.data27;
|
|
601
|
+
}
|
|
602
|
+
const len = messageUpdated.length;
|
|
603
|
+
for (let i = 0; i < len; i += 8) {
|
|
604
|
+
let b = 0;
|
|
605
|
+
for (let j = 0; j < 8; j++) {
|
|
606
|
+
b = (b << 1) | (messageUpdated[i + j] ? 1 : 0);
|
|
607
|
+
}
|
|
608
|
+
blocks[i / 8] = b;
|
|
609
|
+
}
|
|
610
|
+
let pad = 236;
|
|
611
|
+
for (let i = Math.ceil((len + 4) / 8); i < blocks.length; i++) {
|
|
612
|
+
blocks[i] = pad;
|
|
613
|
+
pad = pad == 236 ? 17 : 236;
|
|
614
|
+
}
|
|
615
|
+
let offset = 0;
|
|
616
|
+
template.blocks = template.blocks.map((n) => {
|
|
617
|
+
const b = blocks.slice(offset, offset + n);
|
|
618
|
+
offset += n;
|
|
619
|
+
template.ec.push(calculateEC(b, template.ec_len));
|
|
620
|
+
return b;
|
|
621
|
+
});
|
|
622
|
+
return template;
|
|
623
|
+
}
|
|
624
|
+
function QR(text, ec_level, parse_url) {
|
|
625
|
+
ec_level = EC_LEVELS.includes(ec_level) ? ec_level : "M";
|
|
626
|
+
const message = encode$1(text, parse_url);
|
|
627
|
+
const data = fillTemplate(message, getTemplate(message, ec_level));
|
|
628
|
+
return getMatrix(data);
|
|
629
|
+
}
|
|
630
|
+
const deepCopy = typeof structuredClone !== "undefined" ? structuredClone : ((obj) => JSON.parse(JSON.stringify(obj)));
|
|
631
|
+
const versions = [
|
|
632
|
+
[],
|
|
633
|
+
[26, 7, 1, 10, 1, 13, 1, 17, 1],
|
|
634
|
+
[44, 10, 1, 16, 1, 22, 1, 28, 1],
|
|
635
|
+
[70, 15, 1, 26, 1, 36, 2, 44, 2],
|
|
636
|
+
[100, 20, 1, 36, 2, 52, 2, 64, 4],
|
|
637
|
+
[134, 26, 1, 48, 2, 72, 4, 88, 4],
|
|
638
|
+
[172, 36, 2, 64, 4, 96, 4, 112, 4],
|
|
639
|
+
[196, 40, 2, 72, 4, 108, 6, 130, 5],
|
|
640
|
+
[242, 48, 2, 88, 4, 132, 6, 156, 6],
|
|
641
|
+
[292, 60, 2, 110, 5, 160, 8, 192, 8],
|
|
642
|
+
[346, 72, 4, 130, 5, 192, 8, 224, 8],
|
|
643
|
+
[404, 80, 4, 150, 5, 224, 8, 264, 11],
|
|
644
|
+
[466, 96, 4, 176, 8, 260, 10, 308, 11],
|
|
645
|
+
[532, 104, 4, 198, 9, 288, 12, 352, 16],
|
|
646
|
+
[581, 120, 4, 216, 9, 320, 16, 384, 16],
|
|
647
|
+
[655, 132, 6, 240, 10, 360, 12, 432, 18],
|
|
648
|
+
[733, 144, 6, 280, 10, 408, 17, 480, 16],
|
|
649
|
+
[815, 168, 6, 308, 11, 448, 16, 532, 19],
|
|
650
|
+
[901, 180, 6, 338, 13, 504, 18, 588, 21],
|
|
651
|
+
[991, 196, 7, 364, 14, 546, 21, 650, 25],
|
|
652
|
+
[1085, 224, 8, 416, 16, 600, 20, 700, 25],
|
|
653
|
+
[1156, 224, 8, 442, 17, 644, 23, 750, 25],
|
|
654
|
+
[1258, 252, 9, 476, 17, 690, 23, 816, 34],
|
|
655
|
+
[1364, 270, 9, 504, 18, 750, 25, 900, 30],
|
|
656
|
+
[1474, 300, 10, 560, 20, 810, 27, 960, 32],
|
|
657
|
+
[1588, 312, 12, 588, 21, 870, 29, 1050, 35],
|
|
658
|
+
[1706, 336, 12, 644, 23, 952, 34, 1110, 37],
|
|
659
|
+
[1828, 360, 12, 700, 25, 1020, 34, 1200, 40],
|
|
660
|
+
[1921, 390, 13, 728, 26, 1050, 35, 1260, 42],
|
|
661
|
+
[2051, 420, 14, 784, 28, 1140, 38, 1350, 45],
|
|
662
|
+
[2185, 450, 15, 812, 29, 1200, 40, 1440, 48],
|
|
663
|
+
[2323, 480, 16, 868, 31, 1290, 43, 1530, 51],
|
|
664
|
+
[2465, 510, 17, 924, 33, 1350, 45, 1620, 54],
|
|
665
|
+
[2611, 540, 18, 980, 35, 1440, 48, 1710, 57],
|
|
666
|
+
[2761, 570, 19, 1036, 37, 1530, 51, 1800, 60],
|
|
667
|
+
[2876, 570, 19, 1064, 38, 1590, 53, 1890, 63],
|
|
668
|
+
[3034, 600, 20, 1120, 40, 1680, 56, 1980, 66],
|
|
669
|
+
[3196, 630, 21, 1204, 43, 1770, 59, 2100, 70],
|
|
670
|
+
[3362, 660, 22, 1260, 45, 1860, 62, 2220, 74],
|
|
671
|
+
[3532, 720, 24, 1316, 47, 1950, 65, 2310, 77],
|
|
672
|
+
[3706, 750, 25, 1372, 49, 2040, 68, 2430, 81],
|
|
673
|
+
];
|
|
674
|
+
const mappedVersions = versions.map((el, index) => {
|
|
675
|
+
if (!index) {
|
|
676
|
+
return Object.create(null);
|
|
677
|
+
}
|
|
678
|
+
const res = Object.create(null);
|
|
679
|
+
for (let i = 1; i < 8; i += 2) {
|
|
680
|
+
const length = el[0] - el[i];
|
|
681
|
+
const num_template = el[i + 1];
|
|
682
|
+
const ec_level = EC_LEVELS[(i / 2) | 0];
|
|
683
|
+
const level = {
|
|
684
|
+
version: index,
|
|
685
|
+
ec_level,
|
|
686
|
+
data_len: length,
|
|
687
|
+
ec_len: el[i] / num_template,
|
|
688
|
+
blocks: [],
|
|
689
|
+
ec: [],
|
|
690
|
+
};
|
|
691
|
+
for (let k = num_template, n = length; k > 0; k--) {
|
|
692
|
+
const block = (n / k) | 0;
|
|
693
|
+
level.blocks.push(block);
|
|
694
|
+
n -= block;
|
|
695
|
+
}
|
|
696
|
+
res[ec_level] = level;
|
|
697
|
+
}
|
|
698
|
+
return res;
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
function getDefaultExportFromCjs (x) {
|
|
702
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
var colorString$1 = {exports: {}};
|
|
706
|
+
|
|
707
|
+
var colorName = {
|
|
708
|
+
"aliceblue": [240, 248, 255],
|
|
709
|
+
"antiquewhite": [250, 235, 215],
|
|
710
|
+
"aqua": [0, 255, 255],
|
|
711
|
+
"aquamarine": [127, 255, 212],
|
|
712
|
+
"azure": [240, 255, 255],
|
|
713
|
+
"beige": [245, 245, 220],
|
|
714
|
+
"bisque": [255, 228, 196],
|
|
715
|
+
"black": [0, 0, 0],
|
|
716
|
+
"blanchedalmond": [255, 235, 205],
|
|
717
|
+
"blue": [0, 0, 255],
|
|
718
|
+
"blueviolet": [138, 43, 226],
|
|
719
|
+
"brown": [165, 42, 42],
|
|
720
|
+
"burlywood": [222, 184, 135],
|
|
721
|
+
"cadetblue": [95, 158, 160],
|
|
722
|
+
"chartreuse": [127, 255, 0],
|
|
723
|
+
"chocolate": [210, 105, 30],
|
|
724
|
+
"coral": [255, 127, 80],
|
|
725
|
+
"cornflowerblue": [100, 149, 237],
|
|
726
|
+
"cornsilk": [255, 248, 220],
|
|
727
|
+
"crimson": [220, 20, 60],
|
|
728
|
+
"cyan": [0, 255, 255],
|
|
729
|
+
"darkblue": [0, 0, 139],
|
|
730
|
+
"darkcyan": [0, 139, 139],
|
|
731
|
+
"darkgoldenrod": [184, 134, 11],
|
|
732
|
+
"darkgray": [169, 169, 169],
|
|
733
|
+
"darkgreen": [0, 100, 0],
|
|
734
|
+
"darkgrey": [169, 169, 169],
|
|
735
|
+
"darkkhaki": [189, 183, 107],
|
|
736
|
+
"darkmagenta": [139, 0, 139],
|
|
737
|
+
"darkolivegreen": [85, 107, 47],
|
|
738
|
+
"darkorange": [255, 140, 0],
|
|
739
|
+
"darkorchid": [153, 50, 204],
|
|
740
|
+
"darkred": [139, 0, 0],
|
|
741
|
+
"darksalmon": [233, 150, 122],
|
|
742
|
+
"darkseagreen": [143, 188, 143],
|
|
743
|
+
"darkslateblue": [72, 61, 139],
|
|
744
|
+
"darkslategray": [47, 79, 79],
|
|
745
|
+
"darkslategrey": [47, 79, 79],
|
|
746
|
+
"darkturquoise": [0, 206, 209],
|
|
747
|
+
"darkviolet": [148, 0, 211],
|
|
748
|
+
"deeppink": [255, 20, 147],
|
|
749
|
+
"deepskyblue": [0, 191, 255],
|
|
750
|
+
"dimgray": [105, 105, 105],
|
|
751
|
+
"dimgrey": [105, 105, 105],
|
|
752
|
+
"dodgerblue": [30, 144, 255],
|
|
753
|
+
"firebrick": [178, 34, 34],
|
|
754
|
+
"floralwhite": [255, 250, 240],
|
|
755
|
+
"forestgreen": [34, 139, 34],
|
|
756
|
+
"fuchsia": [255, 0, 255],
|
|
757
|
+
"gainsboro": [220, 220, 220],
|
|
758
|
+
"ghostwhite": [248, 248, 255],
|
|
759
|
+
"gold": [255, 215, 0],
|
|
760
|
+
"goldenrod": [218, 165, 32],
|
|
761
|
+
"gray": [128, 128, 128],
|
|
762
|
+
"green": [0, 128, 0],
|
|
763
|
+
"greenyellow": [173, 255, 47],
|
|
764
|
+
"grey": [128, 128, 128],
|
|
765
|
+
"honeydew": [240, 255, 240],
|
|
766
|
+
"hotpink": [255, 105, 180],
|
|
767
|
+
"indianred": [205, 92, 92],
|
|
768
|
+
"indigo": [75, 0, 130],
|
|
769
|
+
"ivory": [255, 255, 240],
|
|
770
|
+
"khaki": [240, 230, 140],
|
|
771
|
+
"lavender": [230, 230, 250],
|
|
772
|
+
"lavenderblush": [255, 240, 245],
|
|
773
|
+
"lawngreen": [124, 252, 0],
|
|
774
|
+
"lemonchiffon": [255, 250, 205],
|
|
775
|
+
"lightblue": [173, 216, 230],
|
|
776
|
+
"lightcoral": [240, 128, 128],
|
|
777
|
+
"lightcyan": [224, 255, 255],
|
|
778
|
+
"lightgoldenrodyellow": [250, 250, 210],
|
|
779
|
+
"lightgray": [211, 211, 211],
|
|
780
|
+
"lightgreen": [144, 238, 144],
|
|
781
|
+
"lightgrey": [211, 211, 211],
|
|
782
|
+
"lightpink": [255, 182, 193],
|
|
783
|
+
"lightsalmon": [255, 160, 122],
|
|
784
|
+
"lightseagreen": [32, 178, 170],
|
|
785
|
+
"lightskyblue": [135, 206, 250],
|
|
786
|
+
"lightslategray": [119, 136, 153],
|
|
787
|
+
"lightslategrey": [119, 136, 153],
|
|
788
|
+
"lightsteelblue": [176, 196, 222],
|
|
789
|
+
"lightyellow": [255, 255, 224],
|
|
790
|
+
"lime": [0, 255, 0],
|
|
791
|
+
"limegreen": [50, 205, 50],
|
|
792
|
+
"linen": [250, 240, 230],
|
|
793
|
+
"magenta": [255, 0, 255],
|
|
794
|
+
"maroon": [128, 0, 0],
|
|
795
|
+
"mediumaquamarine": [102, 205, 170],
|
|
796
|
+
"mediumblue": [0, 0, 205],
|
|
797
|
+
"mediumorchid": [186, 85, 211],
|
|
798
|
+
"mediumpurple": [147, 112, 219],
|
|
799
|
+
"mediumseagreen": [60, 179, 113],
|
|
800
|
+
"mediumslateblue": [123, 104, 238],
|
|
801
|
+
"mediumspringgreen": [0, 250, 154],
|
|
802
|
+
"mediumturquoise": [72, 209, 204],
|
|
803
|
+
"mediumvioletred": [199, 21, 133],
|
|
804
|
+
"midnightblue": [25, 25, 112],
|
|
805
|
+
"mintcream": [245, 255, 250],
|
|
806
|
+
"mistyrose": [255, 228, 225],
|
|
807
|
+
"moccasin": [255, 228, 181],
|
|
808
|
+
"navajowhite": [255, 222, 173],
|
|
809
|
+
"navy": [0, 0, 128],
|
|
810
|
+
"oldlace": [253, 245, 230],
|
|
811
|
+
"olive": [128, 128, 0],
|
|
812
|
+
"olivedrab": [107, 142, 35],
|
|
813
|
+
"orange": [255, 165, 0],
|
|
814
|
+
"orangered": [255, 69, 0],
|
|
815
|
+
"orchid": [218, 112, 214],
|
|
816
|
+
"palegoldenrod": [238, 232, 170],
|
|
817
|
+
"palegreen": [152, 251, 152],
|
|
818
|
+
"paleturquoise": [175, 238, 238],
|
|
819
|
+
"palevioletred": [219, 112, 147],
|
|
820
|
+
"papayawhip": [255, 239, 213],
|
|
821
|
+
"peachpuff": [255, 218, 185],
|
|
822
|
+
"peru": [205, 133, 63],
|
|
823
|
+
"pink": [255, 192, 203],
|
|
824
|
+
"plum": [221, 160, 221],
|
|
825
|
+
"powderblue": [176, 224, 230],
|
|
826
|
+
"purple": [128, 0, 128],
|
|
827
|
+
"rebeccapurple": [102, 51, 153],
|
|
828
|
+
"red": [255, 0, 0],
|
|
829
|
+
"rosybrown": [188, 143, 143],
|
|
830
|
+
"royalblue": [65, 105, 225],
|
|
831
|
+
"saddlebrown": [139, 69, 19],
|
|
832
|
+
"salmon": [250, 128, 114],
|
|
833
|
+
"sandybrown": [244, 164, 96],
|
|
834
|
+
"seagreen": [46, 139, 87],
|
|
835
|
+
"seashell": [255, 245, 238],
|
|
836
|
+
"sienna": [160, 82, 45],
|
|
837
|
+
"silver": [192, 192, 192],
|
|
838
|
+
"skyblue": [135, 206, 235],
|
|
839
|
+
"slateblue": [106, 90, 205],
|
|
840
|
+
"slategray": [112, 128, 144],
|
|
841
|
+
"slategrey": [112, 128, 144],
|
|
842
|
+
"snow": [255, 250, 250],
|
|
843
|
+
"springgreen": [0, 255, 127],
|
|
844
|
+
"steelblue": [70, 130, 180],
|
|
845
|
+
"tan": [210, 180, 140],
|
|
846
|
+
"teal": [0, 128, 128],
|
|
847
|
+
"thistle": [216, 191, 216],
|
|
848
|
+
"tomato": [255, 99, 71],
|
|
849
|
+
"turquoise": [64, 224, 208],
|
|
850
|
+
"violet": [238, 130, 238],
|
|
851
|
+
"wheat": [245, 222, 179],
|
|
852
|
+
"white": [255, 255, 255],
|
|
853
|
+
"whitesmoke": [245, 245, 245],
|
|
854
|
+
"yellow": [255, 255, 0],
|
|
855
|
+
"yellowgreen": [154, 205, 50]
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
var simpleSwizzle = {exports: {}};
|
|
859
|
+
|
|
860
|
+
var isArrayish$1 = function isArrayish(obj) {
|
|
861
|
+
if (!obj || typeof obj === 'string') {
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
return obj instanceof Array || Array.isArray(obj) ||
|
|
866
|
+
(obj.length >= 0 && (obj.splice instanceof Function ||
|
|
867
|
+
(Object.getOwnPropertyDescriptor(obj, (obj.length - 1)) && obj.constructor.name !== 'String')));
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
var isArrayish = isArrayish$1;
|
|
871
|
+
|
|
872
|
+
var concat = Array.prototype.concat;
|
|
873
|
+
var slice = Array.prototype.slice;
|
|
874
|
+
|
|
875
|
+
var swizzle$1 = simpleSwizzle.exports = function swizzle(args) {
|
|
876
|
+
var results = [];
|
|
877
|
+
|
|
878
|
+
for (var i = 0, len = args.length; i < len; i++) {
|
|
879
|
+
var arg = args[i];
|
|
880
|
+
|
|
881
|
+
if (isArrayish(arg)) {
|
|
882
|
+
// http://jsperf.com/javascript-array-concat-vs-push/98
|
|
883
|
+
results = concat.call(results, slice.call(arg));
|
|
884
|
+
} else {
|
|
885
|
+
results.push(arg);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
return results;
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
swizzle$1.wrap = function (fn) {
|
|
893
|
+
return function () {
|
|
894
|
+
return fn(swizzle$1(arguments));
|
|
895
|
+
};
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
var simpleSwizzleExports = simpleSwizzle.exports;
|
|
899
|
+
|
|
900
|
+
/* MIT license */
|
|
901
|
+
|
|
902
|
+
var colorNames = colorName;
|
|
903
|
+
var swizzle = simpleSwizzleExports;
|
|
904
|
+
var hasOwnProperty = Object.hasOwnProperty;
|
|
905
|
+
|
|
906
|
+
var reverseNames = Object.create(null);
|
|
907
|
+
|
|
908
|
+
// create a list of reverse color names
|
|
909
|
+
for (var name in colorNames) {
|
|
910
|
+
if (hasOwnProperty.call(colorNames, name)) {
|
|
911
|
+
reverseNames[colorNames[name]] = name;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
var cs = colorString$1.exports = {
|
|
916
|
+
to: {},
|
|
917
|
+
get: {}
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
cs.get = function (string) {
|
|
921
|
+
var prefix = string.substring(0, 3).toLowerCase();
|
|
922
|
+
var val;
|
|
923
|
+
var model;
|
|
924
|
+
switch (prefix) {
|
|
925
|
+
case 'hsl':
|
|
926
|
+
val = cs.get.hsl(string);
|
|
927
|
+
model = 'hsl';
|
|
928
|
+
break;
|
|
929
|
+
case 'hwb':
|
|
930
|
+
val = cs.get.hwb(string);
|
|
931
|
+
model = 'hwb';
|
|
932
|
+
break;
|
|
933
|
+
default:
|
|
934
|
+
val = cs.get.rgb(string);
|
|
935
|
+
model = 'rgb';
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
if (!val) {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
return {model: model, value: val};
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
cs.get.rgb = function (string) {
|
|
947
|
+
if (!string) {
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
var abbr = /^#([a-f0-9]{3,4})$/i;
|
|
952
|
+
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
|
953
|
+
var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
954
|
+
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
955
|
+
var keyword = /^(\w+)$/;
|
|
956
|
+
|
|
957
|
+
var rgb = [0, 0, 0, 1];
|
|
958
|
+
var match;
|
|
959
|
+
var i;
|
|
960
|
+
var hexAlpha;
|
|
961
|
+
|
|
962
|
+
if (match = string.match(hex)) {
|
|
963
|
+
hexAlpha = match[2];
|
|
964
|
+
match = match[1];
|
|
965
|
+
|
|
966
|
+
for (i = 0; i < 3; i++) {
|
|
967
|
+
// https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19
|
|
968
|
+
var i2 = i * 2;
|
|
969
|
+
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
if (hexAlpha) {
|
|
973
|
+
rgb[3] = parseInt(hexAlpha, 16) / 255;
|
|
974
|
+
}
|
|
975
|
+
} else if (match = string.match(abbr)) {
|
|
976
|
+
match = match[1];
|
|
977
|
+
hexAlpha = match[3];
|
|
978
|
+
|
|
979
|
+
for (i = 0; i < 3; i++) {
|
|
980
|
+
rgb[i] = parseInt(match[i] + match[i], 16);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
if (hexAlpha) {
|
|
984
|
+
rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
|
|
985
|
+
}
|
|
986
|
+
} else if (match = string.match(rgba)) {
|
|
987
|
+
for (i = 0; i < 3; i++) {
|
|
988
|
+
rgb[i] = parseInt(match[i + 1], 0);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
if (match[4]) {
|
|
992
|
+
if (match[5]) {
|
|
993
|
+
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
994
|
+
} else {
|
|
995
|
+
rgb[3] = parseFloat(match[4]);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
} else if (match = string.match(per)) {
|
|
999
|
+
for (i = 0; i < 3; i++) {
|
|
1000
|
+
rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (match[4]) {
|
|
1004
|
+
if (match[5]) {
|
|
1005
|
+
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
1006
|
+
} else {
|
|
1007
|
+
rgb[3] = parseFloat(match[4]);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
} else if (match = string.match(keyword)) {
|
|
1011
|
+
if (match[1] === 'transparent') {
|
|
1012
|
+
return [0, 0, 0, 0];
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
if (!hasOwnProperty.call(colorNames, match[1])) {
|
|
1016
|
+
return null;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
rgb = colorNames[match[1]];
|
|
1020
|
+
rgb[3] = 1;
|
|
1021
|
+
|
|
1022
|
+
return rgb;
|
|
1023
|
+
} else {
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
for (i = 0; i < 3; i++) {
|
|
1028
|
+
rgb[i] = clamp(rgb[i], 0, 255);
|
|
1029
|
+
}
|
|
1030
|
+
rgb[3] = clamp(rgb[3], 0, 1);
|
|
1031
|
+
|
|
1032
|
+
return rgb;
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
cs.get.hsl = function (string) {
|
|
1036
|
+
if (!string) {
|
|
1037
|
+
return null;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
1041
|
+
var match = string.match(hsl);
|
|
1042
|
+
|
|
1043
|
+
if (match) {
|
|
1044
|
+
var alpha = parseFloat(match[4]);
|
|
1045
|
+
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
|
1046
|
+
var s = clamp(parseFloat(match[2]), 0, 100);
|
|
1047
|
+
var l = clamp(parseFloat(match[3]), 0, 100);
|
|
1048
|
+
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
1049
|
+
|
|
1050
|
+
return [h, s, l, a];
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
return null;
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
cs.get.hwb = function (string) {
|
|
1057
|
+
if (!string) {
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
1062
|
+
var match = string.match(hwb);
|
|
1063
|
+
|
|
1064
|
+
if (match) {
|
|
1065
|
+
var alpha = parseFloat(match[4]);
|
|
1066
|
+
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
|
1067
|
+
var w = clamp(parseFloat(match[2]), 0, 100);
|
|
1068
|
+
var b = clamp(parseFloat(match[3]), 0, 100);
|
|
1069
|
+
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
1070
|
+
return [h, w, b, a];
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
return null;
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
cs.to.hex = function () {
|
|
1077
|
+
var rgba = swizzle(arguments);
|
|
1078
|
+
|
|
1079
|
+
return (
|
|
1080
|
+
'#' +
|
|
1081
|
+
hexDouble(rgba[0]) +
|
|
1082
|
+
hexDouble(rgba[1]) +
|
|
1083
|
+
hexDouble(rgba[2]) +
|
|
1084
|
+
(rgba[3] < 1
|
|
1085
|
+
? (hexDouble(Math.round(rgba[3] * 255)))
|
|
1086
|
+
: '')
|
|
1087
|
+
);
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
cs.to.rgb = function () {
|
|
1091
|
+
var rgba = swizzle(arguments);
|
|
1092
|
+
|
|
1093
|
+
return rgba.length < 4 || rgba[3] === 1
|
|
1094
|
+
? 'rgb(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ')'
|
|
1095
|
+
: 'rgba(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ', ' + rgba[3] + ')';
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
cs.to.rgb.percent = function () {
|
|
1099
|
+
var rgba = swizzle(arguments);
|
|
1100
|
+
|
|
1101
|
+
var r = Math.round(rgba[0] / 255 * 100);
|
|
1102
|
+
var g = Math.round(rgba[1] / 255 * 100);
|
|
1103
|
+
var b = Math.round(rgba[2] / 255 * 100);
|
|
1104
|
+
|
|
1105
|
+
return rgba.length < 4 || rgba[3] === 1
|
|
1106
|
+
? 'rgb(' + r + '%, ' + g + '%, ' + b + '%)'
|
|
1107
|
+
: 'rgba(' + r + '%, ' + g + '%, ' + b + '%, ' + rgba[3] + ')';
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
cs.to.hsl = function () {
|
|
1111
|
+
var hsla = swizzle(arguments);
|
|
1112
|
+
return hsla.length < 4 || hsla[3] === 1
|
|
1113
|
+
? 'hsl(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%)'
|
|
1114
|
+
: 'hsla(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%, ' + hsla[3] + ')';
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
// hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
|
|
1118
|
+
// (hwb have alpha optional & 1 is default value)
|
|
1119
|
+
cs.to.hwb = function () {
|
|
1120
|
+
var hwba = swizzle(arguments);
|
|
1121
|
+
|
|
1122
|
+
var a = '';
|
|
1123
|
+
if (hwba.length >= 4 && hwba[3] !== 1) {
|
|
1124
|
+
a = ', ' + hwba[3];
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
return 'hwb(' + hwba[0] + ', ' + hwba[1] + '%, ' + hwba[2] + '%' + a + ')';
|
|
1128
|
+
};
|
|
1129
|
+
|
|
1130
|
+
cs.to.keyword = function (rgb) {
|
|
1131
|
+
return reverseNames[rgb.slice(0, 3)];
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
// helpers
|
|
1135
|
+
function clamp(num, min, max) {
|
|
1136
|
+
return Math.min(Math.max(min, num), max);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
function hexDouble(num) {
|
|
1140
|
+
var str = Math.round(num).toString(16).toUpperCase();
|
|
1141
|
+
return (str.length < 2) ? '0' + str : str;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
var colorStringExports = colorString$1.exports;
|
|
1145
|
+
var colorString = /*@__PURE__*/getDefaultExportFromCjs(colorStringExports);
|
|
1146
|
+
|
|
1147
|
+
function getOptions(inOptions) {
|
|
1148
|
+
const type = inOptions?.type ?? "png";
|
|
1149
|
+
const defaults = type === "png" ? BITMAP_OPTIONS : VECTOR_OPTIONS;
|
|
1150
|
+
return { ...defaults, ...inOptions };
|
|
1151
|
+
}
|
|
1152
|
+
function colorToHex(color) {
|
|
1153
|
+
if (typeof color === "string") {
|
|
1154
|
+
return colorString.to.hex(colorString.get.rgb(color));
|
|
1155
|
+
}
|
|
1156
|
+
return `#${(color >>> 8).toString(16).padStart(6, "0")}`;
|
|
1157
|
+
}
|
|
1158
|
+
function getSVGPath(matrix, size, margin = 0, borderRadius = 0) {
|
|
1159
|
+
let rectangles = [];
|
|
1160
|
+
for (let x = 0; x < matrix.length; x++) {
|
|
1161
|
+
const column = matrix[x];
|
|
1162
|
+
for (let y = 0; y < column.length; y++) {
|
|
1163
|
+
if (column[y]) {
|
|
1164
|
+
const leftX = x * size + margin;
|
|
1165
|
+
const rightX = (x + 1) * size + margin;
|
|
1166
|
+
const topY = y * size + margin;
|
|
1167
|
+
const bottomY = (y + 1) * size + margin;
|
|
1168
|
+
const rectangle = [];
|
|
1169
|
+
rectangle.push(`M ${leftX} ${topY + borderRadius}`);
|
|
1170
|
+
rectangle.push(`L ${leftX} ${bottomY - borderRadius}`);
|
|
1171
|
+
if (borderRadius > 0) {
|
|
1172
|
+
rectangle.push(`A ${borderRadius} ${borderRadius} 0 0 0 ${leftX + borderRadius} ${bottomY} `);
|
|
1173
|
+
}
|
|
1174
|
+
rectangle.push(`L ${rightX - borderRadius} ${bottomY}`);
|
|
1175
|
+
if (borderRadius > 0) {
|
|
1176
|
+
rectangle.push(`A ${borderRadius} ${borderRadius} 0 0 0 ${rightX} ${bottomY - borderRadius}`);
|
|
1177
|
+
}
|
|
1178
|
+
rectangle.push(`L ${rightX} ${topY + borderRadius}`);
|
|
1179
|
+
if (borderRadius > 0) {
|
|
1180
|
+
rectangle.push(`A ${borderRadius} ${borderRadius} 0 0 0 ${rightX - borderRadius} ${topY}`);
|
|
1181
|
+
}
|
|
1182
|
+
rectangle.push(`L ${leftX + borderRadius} ${topY}`);
|
|
1183
|
+
if (borderRadius > 0) {
|
|
1184
|
+
rectangle.push(`A ${borderRadius} ${borderRadius} 0 0 0 ${leftX} ${topY + borderRadius}`);
|
|
1185
|
+
}
|
|
1186
|
+
rectangle.push(`z`);
|
|
1187
|
+
rectangles.push(rectangle.join(" "));
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
return rectangles.join(" ");
|
|
1192
|
+
}
|
|
1193
|
+
const commonOptions = {
|
|
1194
|
+
type: "png",
|
|
1195
|
+
parse_url: false,
|
|
1196
|
+
ec_level: "M",
|
|
1197
|
+
logo: undefined,
|
|
1198
|
+
logoWidth: 20,
|
|
1199
|
+
logoHeight: 20,
|
|
1200
|
+
bgColor: 0xffffffff,
|
|
1201
|
+
color: 0x000000ff,
|
|
1202
|
+
};
|
|
1203
|
+
const BITMAP_OPTIONS = {
|
|
1204
|
+
...commonOptions,
|
|
1205
|
+
margin: 1,
|
|
1206
|
+
size: 5,
|
|
1207
|
+
};
|
|
1208
|
+
const VECTOR_OPTIONS = {
|
|
1209
|
+
...commonOptions,
|
|
1210
|
+
margin: 1,
|
|
1211
|
+
size: 0,
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* base64.ts
|
|
1216
|
+
*
|
|
1217
|
+
* Licensed under the BSD 3-Clause License.
|
|
1218
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
|
1219
|
+
*
|
|
1220
|
+
* References:
|
|
1221
|
+
* http://en.wikipedia.org/wiki/Base64
|
|
1222
|
+
*
|
|
1223
|
+
* @author Dan Kogai (https://github.com/dankogai)
|
|
1224
|
+
*/
|
|
1225
|
+
const version = '3.7.7';
|
|
1226
|
+
/**
|
|
1227
|
+
* @deprecated use lowercase `version`.
|
|
1228
|
+
*/
|
|
1229
|
+
const VERSION = version;
|
|
1230
|
+
const _hasBuffer = typeof Buffer === 'function';
|
|
1231
|
+
const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
|
|
1232
|
+
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
|
1233
|
+
const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
1234
|
+
const b64chs = Array.prototype.slice.call(b64ch);
|
|
1235
|
+
const b64tab = ((a) => {
|
|
1236
|
+
let tab = {};
|
|
1237
|
+
a.forEach((c, i) => tab[c] = i);
|
|
1238
|
+
return tab;
|
|
1239
|
+
})(b64chs);
|
|
1240
|
+
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
1241
|
+
const _fromCC = String.fromCharCode.bind(String);
|
|
1242
|
+
const _U8Afrom = typeof Uint8Array.from === 'function'
|
|
1243
|
+
? Uint8Array.from.bind(Uint8Array)
|
|
1244
|
+
: (it) => new Uint8Array(Array.prototype.slice.call(it, 0));
|
|
1245
|
+
const _mkUriSafe = (src) => src
|
|
1246
|
+
.replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_');
|
|
1247
|
+
const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
|
|
1248
|
+
/**
|
|
1249
|
+
* polyfill version of `btoa`
|
|
1250
|
+
*/
|
|
1251
|
+
const btoaPolyfill = (bin) => {
|
|
1252
|
+
// console.log('polyfilled');
|
|
1253
|
+
let u32, c0, c1, c2, asc = '';
|
|
1254
|
+
const pad = bin.length % 3;
|
|
1255
|
+
for (let i = 0; i < bin.length;) {
|
|
1256
|
+
if ((c0 = bin.charCodeAt(i++)) > 255 ||
|
|
1257
|
+
(c1 = bin.charCodeAt(i++)) > 255 ||
|
|
1258
|
+
(c2 = bin.charCodeAt(i++)) > 255)
|
|
1259
|
+
throw new TypeError('invalid character found');
|
|
1260
|
+
u32 = (c0 << 16) | (c1 << 8) | c2;
|
|
1261
|
+
asc += b64chs[u32 >> 18 & 63]
|
|
1262
|
+
+ b64chs[u32 >> 12 & 63]
|
|
1263
|
+
+ b64chs[u32 >> 6 & 63]
|
|
1264
|
+
+ b64chs[u32 & 63];
|
|
1265
|
+
}
|
|
1266
|
+
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
|
1267
|
+
};
|
|
1268
|
+
/**
|
|
1269
|
+
* does what `window.btoa` of web browsers do.
|
|
1270
|
+
* @param {String} bin binary string
|
|
1271
|
+
* @returns {string} Base64-encoded string
|
|
1272
|
+
*/
|
|
1273
|
+
const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)
|
|
1274
|
+
: _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
|
|
1275
|
+
: btoaPolyfill;
|
|
1276
|
+
const _fromUint8Array = _hasBuffer
|
|
1277
|
+
? (u8a) => Buffer.from(u8a).toString('base64')
|
|
1278
|
+
: (u8a) => {
|
|
1279
|
+
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
|
1280
|
+
const maxargs = 0x1000;
|
|
1281
|
+
let strs = [];
|
|
1282
|
+
for (let i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
1283
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
1284
|
+
}
|
|
1285
|
+
return _btoa(strs.join(''));
|
|
1286
|
+
};
|
|
1287
|
+
/**
|
|
1288
|
+
* converts a Uint8Array to a Base64 string.
|
|
1289
|
+
* @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
|
|
1290
|
+
* @returns {string} Base64 string
|
|
1291
|
+
*/
|
|
1292
|
+
const fromUint8Array = (u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
|
|
1293
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
|
1294
|
+
// const utob = (src: string) => unescape(encodeURIComponent(src));
|
|
1295
|
+
// reverting good old fationed regexp
|
|
1296
|
+
const cb_utob = (c) => {
|
|
1297
|
+
if (c.length < 2) {
|
|
1298
|
+
var cc = c.charCodeAt(0);
|
|
1299
|
+
return cc < 0x80 ? c
|
|
1300
|
+
: cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
|
|
1301
|
+
+ _fromCC(0x80 | (cc & 0x3f)))
|
|
1302
|
+
: (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
|
|
1303
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
|
1304
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
|
1305
|
+
}
|
|
1306
|
+
else {
|
|
1307
|
+
var cc = 0x10000
|
|
1308
|
+
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
|
1309
|
+
+ (c.charCodeAt(1) - 0xDC00);
|
|
1310
|
+
return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
|
|
1311
|
+
+ _fromCC(0x80 | ((cc >>> 12) & 0x3f))
|
|
1312
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
|
1313
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
1317
|
+
/**
|
|
1318
|
+
* @deprecated should have been internal use only.
|
|
1319
|
+
* @param {string} src UTF-8 string
|
|
1320
|
+
* @returns {string} UTF-16 string
|
|
1321
|
+
*/
|
|
1322
|
+
const utob = (u) => u.replace(re_utob, cb_utob);
|
|
1323
|
+
//
|
|
1324
|
+
const _encode = _hasBuffer
|
|
1325
|
+
? (s) => Buffer.from(s, 'utf8').toString('base64')
|
|
1326
|
+
: _TE
|
|
1327
|
+
? (s) => _fromUint8Array(_TE.encode(s))
|
|
1328
|
+
: (s) => _btoa(utob(s));
|
|
1329
|
+
/**
|
|
1330
|
+
* converts a UTF-8-encoded string to a Base64 string.
|
|
1331
|
+
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
|
1332
|
+
* @returns {string} Base64 string
|
|
1333
|
+
*/
|
|
1334
|
+
const encode = (src, urlsafe = false) => urlsafe
|
|
1335
|
+
? _mkUriSafe(_encode(src))
|
|
1336
|
+
: _encode(src);
|
|
1337
|
+
/**
|
|
1338
|
+
* converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.
|
|
1339
|
+
* @returns {string} Base64 string
|
|
1340
|
+
*/
|
|
1341
|
+
const encodeURI = (src) => encode(src, true);
|
|
1342
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
|
1343
|
+
// const btou = (src: string) => decodeURIComponent(escape(src));
|
|
1344
|
+
// reverting good old fationed regexp
|
|
1345
|
+
const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
|
1346
|
+
const cb_btou = (cccc) => {
|
|
1347
|
+
switch (cccc.length) {
|
|
1348
|
+
case 4:
|
|
1349
|
+
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
|
1350
|
+
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
|
1351
|
+
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
|
1352
|
+
| (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;
|
|
1353
|
+
return (_fromCC((offset >>> 10) + 0xD800)
|
|
1354
|
+
+ _fromCC((offset & 0x3FF) + 0xDC00));
|
|
1355
|
+
case 3:
|
|
1356
|
+
return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)
|
|
1357
|
+
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
|
1358
|
+
| (0x3f & cccc.charCodeAt(2)));
|
|
1359
|
+
default:
|
|
1360
|
+
return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)
|
|
1361
|
+
| (0x3f & cccc.charCodeAt(1)));
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
/**
|
|
1365
|
+
* @deprecated should have been internal use only.
|
|
1366
|
+
* @param {string} src UTF-16 string
|
|
1367
|
+
* @returns {string} UTF-8 string
|
|
1368
|
+
*/
|
|
1369
|
+
const btou = (b) => b.replace(re_btou, cb_btou);
|
|
1370
|
+
/**
|
|
1371
|
+
* polyfill version of `atob`
|
|
1372
|
+
*/
|
|
1373
|
+
const atobPolyfill = (asc) => {
|
|
1374
|
+
// console.log('polyfilled');
|
|
1375
|
+
asc = asc.replace(/\s+/g, '');
|
|
1376
|
+
if (!b64re.test(asc))
|
|
1377
|
+
throw new TypeError('malformed base64.');
|
|
1378
|
+
asc += '=='.slice(2 - (asc.length & 3));
|
|
1379
|
+
let u24, bin = '', r1, r2;
|
|
1380
|
+
for (let i = 0; i < asc.length;) {
|
|
1381
|
+
u24 = b64tab[asc.charAt(i++)] << 18
|
|
1382
|
+
| b64tab[asc.charAt(i++)] << 12
|
|
1383
|
+
| (r1 = b64tab[asc.charAt(i++)]) << 6
|
|
1384
|
+
| (r2 = b64tab[asc.charAt(i++)]);
|
|
1385
|
+
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
|
|
1386
|
+
: r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
|
|
1387
|
+
: _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
|
|
1388
|
+
}
|
|
1389
|
+
return bin;
|
|
1390
|
+
};
|
|
1391
|
+
/**
|
|
1392
|
+
* does what `window.atob` of web browsers do.
|
|
1393
|
+
* @param {String} asc Base64-encoded string
|
|
1394
|
+
* @returns {string} binary string
|
|
1395
|
+
*/
|
|
1396
|
+
const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
|
|
1397
|
+
: _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
|
|
1398
|
+
: atobPolyfill;
|
|
1399
|
+
//
|
|
1400
|
+
const _toUint8Array = _hasBuffer
|
|
1401
|
+
? (a) => _U8Afrom(Buffer.from(a, 'base64'))
|
|
1402
|
+
: (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
|
|
1403
|
+
/**
|
|
1404
|
+
* converts a Base64 string to a Uint8Array.
|
|
1405
|
+
*/
|
|
1406
|
+
const toUint8Array = (a) => _toUint8Array(_unURI(a));
|
|
1407
|
+
//
|
|
1408
|
+
const _decode = _hasBuffer
|
|
1409
|
+
? (a) => Buffer.from(a, 'base64').toString('utf8')
|
|
1410
|
+
: _TD
|
|
1411
|
+
? (a) => _TD.decode(_toUint8Array(a))
|
|
1412
|
+
: (a) => btou(_atob(a));
|
|
1413
|
+
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
|
|
1414
|
+
/**
|
|
1415
|
+
* converts a Base64 string to a UTF-8 string.
|
|
1416
|
+
* @param {String} src Base64 string. Both normal and URL-safe are supported
|
|
1417
|
+
* @returns {string} UTF-8 string
|
|
1418
|
+
*/
|
|
1419
|
+
const decode = (src) => _decode(_unURI(src));
|
|
1420
|
+
/**
|
|
1421
|
+
* check if a value is a valid Base64 string
|
|
1422
|
+
* @param {String} src a value to check
|
|
1423
|
+
*/
|
|
1424
|
+
const isValid = (src) => {
|
|
1425
|
+
if (typeof src !== 'string')
|
|
1426
|
+
return false;
|
|
1427
|
+
const s = src.replace(/\s+/g, '').replace(/={0,2}$/, '');
|
|
1428
|
+
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
|
|
1429
|
+
};
|
|
1430
|
+
//
|
|
1431
|
+
const _noEnum = (v) => {
|
|
1432
|
+
return {
|
|
1433
|
+
value: v, enumerable: false, writable: true, configurable: true
|
|
1434
|
+
};
|
|
1435
|
+
};
|
|
1436
|
+
/**
|
|
1437
|
+
* extend String.prototype with relevant methods
|
|
1438
|
+
*/
|
|
1439
|
+
const extendString = function () {
|
|
1440
|
+
const _add = (name, body) => Object.defineProperty(String.prototype, name, _noEnum(body));
|
|
1441
|
+
_add('fromBase64', function () { return decode(this); });
|
|
1442
|
+
_add('toBase64', function (urlsafe) { return encode(this, urlsafe); });
|
|
1443
|
+
_add('toBase64URI', function () { return encode(this, true); });
|
|
1444
|
+
_add('toBase64URL', function () { return encode(this, true); });
|
|
1445
|
+
_add('toUint8Array', function () { return toUint8Array(this); });
|
|
1446
|
+
};
|
|
1447
|
+
/**
|
|
1448
|
+
* extend Uint8Array.prototype with relevant methods
|
|
1449
|
+
*/
|
|
1450
|
+
const extendUint8Array = function () {
|
|
1451
|
+
const _add = (name, body) => Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));
|
|
1452
|
+
_add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });
|
|
1453
|
+
_add('toBase64URI', function () { return fromUint8Array(this, true); });
|
|
1454
|
+
_add('toBase64URL', function () { return fromUint8Array(this, true); });
|
|
1455
|
+
};
|
|
1456
|
+
/**
|
|
1457
|
+
* extend Builtin prototypes with relevant methods
|
|
1458
|
+
*/
|
|
1459
|
+
const extendBuiltins = () => {
|
|
1460
|
+
extendString();
|
|
1461
|
+
extendUint8Array();
|
|
1462
|
+
};
|
|
1463
|
+
const gBase64 = {
|
|
1464
|
+
version: version,
|
|
1465
|
+
VERSION: VERSION,
|
|
1466
|
+
atob: _atob,
|
|
1467
|
+
atobPolyfill: atobPolyfill,
|
|
1468
|
+
btoa: _btoa,
|
|
1469
|
+
btoaPolyfill: btoaPolyfill,
|
|
1470
|
+
fromBase64: decode,
|
|
1471
|
+
toBase64: encode,
|
|
1472
|
+
encode: encode,
|
|
1473
|
+
encodeURI: encodeURI,
|
|
1474
|
+
encodeURL: encodeURI,
|
|
1475
|
+
utob: utob,
|
|
1476
|
+
btou: btou,
|
|
1477
|
+
decode: decode,
|
|
1478
|
+
isValid: isValid,
|
|
1479
|
+
fromUint8Array: fromUint8Array,
|
|
1480
|
+
toUint8Array: toUint8Array,
|
|
1481
|
+
extendString: extendString,
|
|
1482
|
+
extendUint8Array: extendUint8Array,
|
|
1483
|
+
extendBuiltins: extendBuiltins
|
|
1484
|
+
};
|
|
1485
|
+
|
|
1486
|
+
async function getPNG(text, inOptions) {
|
|
1487
|
+
const options = getOptions(inOptions);
|
|
1488
|
+
const matrix = QR(text, options.ec_level, options.parse_url);
|
|
1489
|
+
return generateImage({ matrix, ...options, type: 'png' });
|
|
1490
|
+
}
|
|
1491
|
+
function dataURItoArrayBuffer(dataURI) {
|
|
1492
|
+
return gBase64.toUint8Array(dataURI.split(',')[1]);
|
|
1493
|
+
}
|
|
1494
|
+
function blobToDataURL(blob) {
|
|
1495
|
+
return new Promise((resolve, reject) => {
|
|
1496
|
+
try {
|
|
1497
|
+
var a = new FileReader();
|
|
1498
|
+
a.onload = function (e) { resolve(e.target.result); };
|
|
1499
|
+
a.onerror = reject;
|
|
1500
|
+
a.readAsDataURL(blob);
|
|
1501
|
+
}
|
|
1502
|
+
catch (e) {
|
|
1503
|
+
reject(e);
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
async function generateImage({ matrix, size, margin, logo, logoWidth, logoHeight, color, bgColor, borderRadius, }) {
|
|
1508
|
+
const marginPx = margin * size;
|
|
1509
|
+
const imageSize = matrix.length * size + marginPx * 2;
|
|
1510
|
+
const canvas = document.createElement('canvas');
|
|
1511
|
+
canvas.width = imageSize;
|
|
1512
|
+
canvas.height = imageSize;
|
|
1513
|
+
const context = canvas.getContext('2d');
|
|
1514
|
+
context.fillStyle = colorToHex(bgColor);
|
|
1515
|
+
context.fillRect(0, 0, imageSize, imageSize);
|
|
1516
|
+
const path = new Path2D(getSVGPath(matrix, size, marginPx, borderRadius));
|
|
1517
|
+
context.fillStyle = colorToHex(color);
|
|
1518
|
+
context.fill(path);
|
|
1519
|
+
if (logo) {
|
|
1520
|
+
const logoImage = await new Promise(async (resolve, reject) => {
|
|
1521
|
+
try {
|
|
1522
|
+
const image = new Image();
|
|
1523
|
+
image.onload = () => resolve(image);
|
|
1524
|
+
image.onerror = reject;
|
|
1525
|
+
image.src = await blobToDataURL(new window.Blob([logo]));
|
|
1526
|
+
}
|
|
1527
|
+
catch (e) {
|
|
1528
|
+
reject(e);
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
context.drawImage(logoImage, imageSize / 2 - (logoWidth / 2 / 100) * imageSize, imageSize / 2 - (logoHeight / 2 / 100) * imageSize, (logoWidth / 100) * imageSize, (logoHeight / 100) * imageSize);
|
|
1532
|
+
}
|
|
1533
|
+
return dataURItoArrayBuffer(canvas.toDataURL('image/png'));
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
exports.generateImage = generateImage;
|
|
1537
|
+
exports.getPNG = getPNG;
|
|
1538
|
+
|
|
1539
|
+
}));
|
|
1540
|
+
//# sourceMappingURL=png.umd.js.map
|