qr-code-styling-node 1.9.0 → 1.10.0
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/README.md +23 -4
- package/lib/art/art.d.ts +12 -8
- package/lib/core/QRCanvas.d.ts +2 -0
- package/lib/core/QRSVG.d.ts +2 -0
- package/lib/figures/shapes.d.ts +11 -0
- package/lib/qr-code-styling.common.js +1 -1
- package/lib/qr-code-styling.common.js.map +1 -1
- package/lib/qr-code-styling.js +1 -1
- package/lib/qr-code-styling.js.map +1 -1
- package/lib/qr-code-styling.mjs +221 -62
- package/lib/qr-code-styling.mjs.map +4 -4
- package/lib/tools/cornerTypes.d.ts +2 -0
- package/lib/tools/qrArea.d.ts +14 -0
- package/lib/types/index.d.ts +14 -3
- package/package.json +3 -2
package/lib/qr-code-styling.mjs
CHANGED
|
@@ -113,7 +113,8 @@ var dotTypes_default = {
|
|
|
113
113
|
diamond: "diamond",
|
|
114
114
|
smallSquare: "small-square",
|
|
115
115
|
verticalLines: "vertical-lines",
|
|
116
|
-
horizontalLines: "horizontal-lines"
|
|
116
|
+
horizontalLines: "horizontal-lines",
|
|
117
|
+
fluid: "fluid"
|
|
117
118
|
};
|
|
118
119
|
|
|
119
120
|
// src/figures/shapes.ts
|
|
@@ -222,6 +223,35 @@ var roundedRing = (x, y, size) => {
|
|
|
222
223
|
);
|
|
223
224
|
};
|
|
224
225
|
var roundedSquare = (x, y, size) => roundedRect(x, y, size, size, size * 0.25);
|
|
226
|
+
var fluid = (x, y, size, neighbors) => {
|
|
227
|
+
const { left, right, top, bottom } = neighbors;
|
|
228
|
+
const inset = size * 0.1;
|
|
229
|
+
const x0 = x + inset;
|
|
230
|
+
const x1 = x + size - inset;
|
|
231
|
+
const y0 = y + inset;
|
|
232
|
+
const y1 = y + size - inset;
|
|
233
|
+
const r = (size - 2 * inset) / 2;
|
|
234
|
+
const cx = x + size / 2;
|
|
235
|
+
const cy = y + size / 2;
|
|
236
|
+
const roundTL = !left && !top;
|
|
237
|
+
const roundTR = !top && !right;
|
|
238
|
+
const roundBR = !right && !bottom;
|
|
239
|
+
const roundBL = !bottom && !left;
|
|
240
|
+
const shape = [{ op: "M", x: roundTL ? cx : x0, y: y0 }];
|
|
241
|
+
if (top) shape.push({ op: "L", x: x0, y }, { op: "L", x: x1, y }, { op: "L", x: x1, y: y0 });
|
|
242
|
+
if (roundTR) shape.push({ op: "A", cx, cy, r, start: -Math.PI / 2, end: 0 });
|
|
243
|
+
else shape.push({ op: "L", x: x1, y: y0 });
|
|
244
|
+
if (right) shape.push({ op: "L", x: x + size, y: y0 }, { op: "L", x: x + size, y: y1 }, { op: "L", x: x1, y: y1 });
|
|
245
|
+
if (roundBR) shape.push({ op: "A", cx, cy, r, start: 0, end: Math.PI / 2 });
|
|
246
|
+
else shape.push({ op: "L", x: x1, y: y1 });
|
|
247
|
+
if (bottom) shape.push({ op: "L", x: x1, y: y + size }, { op: "L", x: x0, y: y + size }, { op: "L", x: x0, y: y1 });
|
|
248
|
+
if (roundBL) shape.push({ op: "A", cx, cy, r, start: Math.PI / 2, end: Math.PI });
|
|
249
|
+
else shape.push({ op: "L", x: x0, y: y1 });
|
|
250
|
+
if (left) shape.push({ op: "L", x, y: y1 }, { op: "L", x, y: y0 }, { op: "L", x: x0, y: y0 });
|
|
251
|
+
if (roundTL) shape.push({ op: "A", cx, cy, r, start: Math.PI, end: 3 * Math.PI / 2 });
|
|
252
|
+
shape.push({ op: "Z" });
|
|
253
|
+
return shape;
|
|
254
|
+
};
|
|
225
255
|
|
|
226
256
|
// src/figures/dot/canvas/QRDot.ts
|
|
227
257
|
var QRDot = class {
|
|
@@ -265,6 +295,19 @@ var QRDot = class {
|
|
|
265
295
|
};
|
|
266
296
|
break;
|
|
267
297
|
}
|
|
298
|
+
case dotTypes_default.fluid:
|
|
299
|
+
drawFunction = (args) => {
|
|
300
|
+
const has = (dx, dy) => args.getNeighbor ? args.getNeighbor(dx, dy) : false;
|
|
301
|
+
this._drawShape(
|
|
302
|
+
fluid(args.x, args.y, args.size, {
|
|
303
|
+
left: has(-1, 0),
|
|
304
|
+
right: has(1, 0),
|
|
305
|
+
top: has(0, -1),
|
|
306
|
+
bottom: has(0, 1)
|
|
307
|
+
})
|
|
308
|
+
);
|
|
309
|
+
};
|
|
310
|
+
break;
|
|
268
311
|
case dotTypes_default.square:
|
|
269
312
|
default:
|
|
270
313
|
drawFunction = this._drawSquare;
|
|
@@ -659,15 +702,47 @@ var QRCornerDot = class {
|
|
|
659
702
|
}
|
|
660
703
|
};
|
|
661
704
|
|
|
705
|
+
// src/tools/qrArea.ts
|
|
706
|
+
function getQRArea(options, count) {
|
|
707
|
+
var _a;
|
|
708
|
+
const placement = (_a = options.art) == null ? void 0 : _a.placement;
|
|
709
|
+
if (placement && placement.size > 0) {
|
|
710
|
+
const dotSize2 = Math.floor(placement.size / count);
|
|
711
|
+
return {
|
|
712
|
+
count,
|
|
713
|
+
dotSize: dotSize2,
|
|
714
|
+
x: Math.floor(placement.x + (placement.size - count * dotSize2) / 2),
|
|
715
|
+
y: Math.floor(placement.y + (placement.size - count * dotSize2) / 2)
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
const minSize = Math.min(options.width, options.height) - options.margin * 2;
|
|
719
|
+
const dotSize = Math.floor(minSize / count);
|
|
720
|
+
return {
|
|
721
|
+
count,
|
|
722
|
+
dotSize,
|
|
723
|
+
x: Math.floor((options.width - count * dotSize) / 2),
|
|
724
|
+
y: Math.floor((options.height - count * dotSize) / 2)
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
|
|
662
728
|
// src/tools/cornerTypes.ts
|
|
663
729
|
var SOLID_CORNER_DOT_TYPES = ["diamond", "small-square", "vertical-lines", "horizontal-lines"];
|
|
730
|
+
var ROUND_DOT_TYPES = ["dots", "rounded", "extra-rounded", "classy-rounded", "fluid"];
|
|
664
731
|
var needsSolidAlignment = (type) => SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
665
732
|
function getCornerTypes(options) {
|
|
666
|
-
var _a, _b;
|
|
667
|
-
const
|
|
733
|
+
var _a, _b, _c, _d, _e;
|
|
734
|
+
const type = options.dotsOptions.type;
|
|
735
|
+
if (((_a = options.art) == null ? void 0 : _a.mode) === "blend" || type === "fluid") {
|
|
736
|
+
const round2 = ROUND_DOT_TYPES.indexOf(type) !== -1;
|
|
737
|
+
return {
|
|
738
|
+
square: ((_b = options.cornersSquareOptions) == null ? void 0 : _b.type) || (round2 ? "rounded" : "square"),
|
|
739
|
+
dot: ((_c = options.cornersDotOptions) == null ? void 0 : _c.type) || (round2 ? "rounded" : "square")
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
const solid = SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
668
743
|
return {
|
|
669
|
-
square: ((
|
|
670
|
-
dot: ((
|
|
744
|
+
square: ((_d = options.cornersSquareOptions) == null ? void 0 : _d.type) || (solid ? "square" : void 0),
|
|
745
|
+
dot: ((_e = options.cornersDotOptions) == null ? void 0 : _e.type) || (solid ? "square" : void 0)
|
|
671
746
|
};
|
|
672
747
|
}
|
|
673
748
|
|
|
@@ -939,10 +1014,10 @@ var createVirtualWindow = () => ({
|
|
|
939
1014
|
var hasBrowserDom = () => typeof window !== "undefined" && typeof document !== "undefined" && typeof document.createElementNS === "function";
|
|
940
1015
|
|
|
941
1016
|
// src/art/art.ts
|
|
942
|
-
var DEFAULT_CONTRAST = { halftone: 0.5, colorize: 0.7 };
|
|
1017
|
+
var DEFAULT_CONTRAST = { halftone: 0.5, colorize: 0.7, blend: 0.6 };
|
|
943
1018
|
var clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
944
1019
|
var getContrast = (art) => clamp01(
|
|
945
|
-
typeof art.contrast === "number" && !isNaN(art.contrast) ? art.contrast : DEFAULT_CONTRAST[art.mode === "colorize"
|
|
1020
|
+
typeof art.contrast === "number" && !isNaN(art.contrast) ? art.contrast : DEFAULT_CONTRAST[art.mode === "colorize" || art.mode === "blend" ? art.mode : "halftone"]
|
|
946
1021
|
);
|
|
947
1022
|
var getLimits = (contrast) => ({
|
|
948
1023
|
dark: 0.45 - 0.35 * contrast,
|
|
@@ -1128,15 +1203,82 @@ function prepareColorize(options, art, image, area) {
|
|
|
1128
1203
|
background: art.background === false ? void 0 : makeLayer((color) => toLight(color, limits.light))
|
|
1129
1204
|
};
|
|
1130
1205
|
}
|
|
1131
|
-
function
|
|
1132
|
-
const
|
|
1133
|
-
const
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1206
|
+
function prepareBlend(options, art, image, qr, area, filter) {
|
|
1207
|
+
const { count, dotSize } = area;
|
|
1208
|
+
const { canvas: picture, data } = readPixels(options, image, options.width, options.height);
|
|
1209
|
+
const width = options.width;
|
|
1210
|
+
const contrast = getContrast(art);
|
|
1211
|
+
const limits = getLimits(contrast);
|
|
1212
|
+
const strong = getLimits(Math.max(contrast, 0.8));
|
|
1213
|
+
const role = getModuleRoles(count);
|
|
1214
|
+
const shape = ROUND_DOT_TYPES.indexOf(options.dotsOptions.type) !== -1 ? "circle" : "rect";
|
|
1215
|
+
const average = (x0, y0, size) => {
|
|
1216
|
+
let r = 0;
|
|
1217
|
+
let g = 0;
|
|
1218
|
+
let b = 0;
|
|
1219
|
+
let n = 0;
|
|
1220
|
+
const xStart = Math.max(0, Math.floor(x0));
|
|
1221
|
+
const yStart = Math.max(0, Math.floor(y0));
|
|
1222
|
+
const xEnd = Math.min(options.width, Math.ceil(x0 + size));
|
|
1223
|
+
const yEnd = Math.min(options.height, Math.ceil(y0 + size));
|
|
1224
|
+
for (let y = yStart; y < yEnd; y++) {
|
|
1225
|
+
for (let x = xStart; x < xEnd; x++) {
|
|
1226
|
+
const index = (y * width + x) * 4;
|
|
1227
|
+
r += data[index];
|
|
1228
|
+
g += data[index + 1];
|
|
1229
|
+
b += data[index + 2];
|
|
1230
|
+
n++;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
return n ? [r / n, g / n, b / n] : [255, 255, 255];
|
|
1139
1234
|
};
|
|
1235
|
+
const rects = [];
|
|
1236
|
+
const finderColors = [];
|
|
1237
|
+
[
|
|
1238
|
+
[0, 0],
|
|
1239
|
+
[count - 8, 0],
|
|
1240
|
+
[0, count - 8]
|
|
1241
|
+
].forEach(([column, row]) => {
|
|
1242
|
+
const x = area.x + column * dotSize;
|
|
1243
|
+
const y = area.y + row * dotSize;
|
|
1244
|
+
const color = average(x, y, 8 * dotSize);
|
|
1245
|
+
const x0 = Math.max(0, x - dotSize);
|
|
1246
|
+
const y0 = Math.max(0, y - dotSize);
|
|
1247
|
+
const x1 = Math.min(options.width, x + 8 * dotSize + (column ? dotSize : 0));
|
|
1248
|
+
const y1 = Math.min(options.height, y + 8 * dotSize + (row ? dotSize : 0));
|
|
1249
|
+
rects.push({ x: x0, y: y0, width: x1 - x0, height: y1 - y0, color: css(toLight(color, strong.light)) });
|
|
1250
|
+
finderColors.push(css(toDark(color, strong.dark)));
|
|
1251
|
+
});
|
|
1252
|
+
const dot = Math.max(
|
|
1253
|
+
1,
|
|
1254
|
+
Math.min(dotSize, Math.round(dotSize * ((shape === "circle" ? 0.55 : 0.45) + contrast * 0.3)))
|
|
1255
|
+
);
|
|
1256
|
+
const offset = (dotSize - dot) / 2;
|
|
1257
|
+
for (let i = 0; i < count; i++) {
|
|
1258
|
+
for (let j = 0; j < count; j++) {
|
|
1259
|
+
const moduleRole = role(i, j);
|
|
1260
|
+
if (moduleRole === "finder" || !filter(i, j)) continue;
|
|
1261
|
+
const x = area.x + i * dotSize;
|
|
1262
|
+
const y = area.y + j * dotSize;
|
|
1263
|
+
const color = average(x + dotSize / 3, y + dotSize / 3, dotSize / 3);
|
|
1264
|
+
const lum = luminance(color);
|
|
1265
|
+
const dark = qr.isDark(i, j);
|
|
1266
|
+
const agrees = dark ? lum <= limits.dark : lum >= limits.light;
|
|
1267
|
+
if (agrees && moduleRole === "data" && !dark) continue;
|
|
1268
|
+
const full = moduleRole === "alignment";
|
|
1269
|
+
rects.push({
|
|
1270
|
+
x: full ? x : x + offset,
|
|
1271
|
+
y: full ? y : y + offset,
|
|
1272
|
+
width: full ? dotSize : dot,
|
|
1273
|
+
height: full ? dotSize : dot,
|
|
1274
|
+
shape: full ? "rect" : shape,
|
|
1275
|
+
color: css(
|
|
1276
|
+
dark ? toDark(color, agrees ? Math.min(lum, strong.dark) * 0.4 : strong.dark) : toLight(color, strong.light)
|
|
1277
|
+
)
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return { mode: "blend", picture, rects, finderColors };
|
|
1140
1282
|
}
|
|
1141
1283
|
async function prepareArt(options, qr, filter) {
|
|
1142
1284
|
const art = options.art;
|
|
@@ -1144,7 +1286,9 @@ async function prepareArt(options, qr, filter) {
|
|
|
1144
1286
|
createCanvas(options, 1, 1);
|
|
1145
1287
|
const image = await loadPicture(options, art);
|
|
1146
1288
|
const area = getQRArea(options, qr.getModuleCount());
|
|
1147
|
-
|
|
1289
|
+
if (art.mode === "colorize") return prepareColorize(options, art, image, area);
|
|
1290
|
+
if (art.mode === "blend") return prepareBlend(options, art, image, qr, area, filter);
|
|
1291
|
+
return planHalftone(options, art, image, qr, area, filter);
|
|
1148
1292
|
}
|
|
1149
1293
|
|
|
1150
1294
|
// src/constants/gradientTypes.ts
|
|
@@ -1255,8 +1399,7 @@ var QRCanvas = class _QRCanvas {
|
|
|
1255
1399
|
return this._drawFramed(qr);
|
|
1256
1400
|
}
|
|
1257
1401
|
const count = qr.getModuleCount();
|
|
1258
|
-
const
|
|
1259
|
-
const dotSize = Math.floor(minSize / count);
|
|
1402
|
+
const { dotSize } = getQRArea(this._options, count);
|
|
1260
1403
|
let drawImageSize = {
|
|
1261
1404
|
hideXDots: 0,
|
|
1262
1405
|
hideYDots: 0,
|
|
@@ -1299,7 +1442,12 @@ var QRCanvas = class _QRCanvas {
|
|
|
1299
1442
|
}
|
|
1300
1443
|
this.clear();
|
|
1301
1444
|
this.drawBackground();
|
|
1302
|
-
if ((art == null ? void 0 : art.mode) === "
|
|
1445
|
+
if ((art == null ? void 0 : art.mode) === "blend") {
|
|
1446
|
+
this.context.drawImage(art.picture, 0, 0);
|
|
1447
|
+
this._drawArtRects(art.rects);
|
|
1448
|
+
this.drawDots(() => false);
|
|
1449
|
+
this._finderColors = art.finderColors;
|
|
1450
|
+
} else if ((art == null ? void 0 : art.mode) === "halftone") {
|
|
1303
1451
|
this._drawArtRects(art.rects);
|
|
1304
1452
|
this.drawDots(() => false);
|
|
1305
1453
|
} else {
|
|
@@ -1312,6 +1460,7 @@ var QRCanvas = class _QRCanvas {
|
|
|
1312
1460
|
this._dotsFill = void 0;
|
|
1313
1461
|
}
|
|
1314
1462
|
this.drawCorners();
|
|
1463
|
+
this._finderColors = void 0;
|
|
1315
1464
|
if (this._options.image) {
|
|
1316
1465
|
this.drawImage({ width: drawImageSize.width, height: drawImageSize.height, count, dotSize });
|
|
1317
1466
|
}
|
|
@@ -1353,10 +1502,7 @@ var QRCanvas = class _QRCanvas {
|
|
|
1353
1502
|
if (count > options.width || count > options.height) {
|
|
1354
1503
|
throw "The canvas is too small.";
|
|
1355
1504
|
}
|
|
1356
|
-
const
|
|
1357
|
-
const dotSize = Math.floor(minSize / count);
|
|
1358
|
-
const xBeginning = Math.floor((options.width - count * dotSize) / 2);
|
|
1359
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1505
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
1360
1506
|
const typeDot = new QRDot({ context: canvasContext, type: options.dotsOptions.type });
|
|
1361
1507
|
const squareDot = new QRDot({ context: canvasContext, type: "square" });
|
|
1362
1508
|
const solidAlignment = needsSolidAlignment(options.dotsOptions.type);
|
|
@@ -1408,9 +1554,15 @@ var QRCanvas = class _QRCanvas {
|
|
|
1408
1554
|
_drawArtRects(rects) {
|
|
1409
1555
|
const context = this.context;
|
|
1410
1556
|
if (!context) return;
|
|
1411
|
-
rects.forEach(({ x, y, width, height, color }) => {
|
|
1557
|
+
rects.forEach(({ x, y, width, height, color, shape }) => {
|
|
1412
1558
|
context.fillStyle = color;
|
|
1413
|
-
|
|
1559
|
+
if (shape === "circle") {
|
|
1560
|
+
context.beginPath();
|
|
1561
|
+
context.arc(x + width / 2, y + height / 2, width / 2, 0, Math.PI * 2);
|
|
1562
|
+
context.fill();
|
|
1563
|
+
} else {
|
|
1564
|
+
context.fillRect(x, y, width, height);
|
|
1565
|
+
}
|
|
1414
1566
|
});
|
|
1415
1567
|
}
|
|
1416
1568
|
drawCorners(filter) {
|
|
@@ -1423,18 +1575,15 @@ var QRCanvas = class _QRCanvas {
|
|
|
1423
1575
|
}
|
|
1424
1576
|
const options = this._options;
|
|
1425
1577
|
const count = this._qr.getModuleCount();
|
|
1426
|
-
const
|
|
1427
|
-
const dotSize = Math.floor(minSize / count);
|
|
1578
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
1428
1579
|
const cornersSquareSize = dotSize * 7;
|
|
1429
1580
|
const cornersDotSize = dotSize * 3;
|
|
1430
1581
|
const cornerTypes = getCornerTypes(options);
|
|
1431
|
-
const xBeginning = Math.floor((options.width - count * dotSize) / 2);
|
|
1432
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1433
1582
|
[
|
|
1434
1583
|
[0, 0, 0],
|
|
1435
1584
|
[1, 0, Math.PI / 2],
|
|
1436
1585
|
[0, 1, -Math.PI / 2]
|
|
1437
|
-
].forEach(([column, row, rotation]) => {
|
|
1586
|
+
].forEach(([column, row, rotation], index) => {
|
|
1438
1587
|
var _a, _b, _c, _d, _e, _f;
|
|
1439
1588
|
if (filter && !filter(column, row)) {
|
|
1440
1589
|
return;
|
|
@@ -1481,6 +1630,8 @@ var QRCanvas = class _QRCanvas {
|
|
|
1481
1630
|
canvasContext.fillStyle = canvasContext.strokeStyle = gradient;
|
|
1482
1631
|
} else if ((_c = options.cornersSquareOptions) == null ? void 0 : _c.color) {
|
|
1483
1632
|
canvasContext.fillStyle = canvasContext.strokeStyle = options.cornersSquareOptions.color;
|
|
1633
|
+
} else if (this._finderColors) {
|
|
1634
|
+
canvasContext.fillStyle = canvasContext.strokeStyle = this._finderColors[index];
|
|
1484
1635
|
}
|
|
1485
1636
|
canvasContext.fill("evenodd");
|
|
1486
1637
|
if (cornerTypes.dot) {
|
|
@@ -1523,6 +1674,8 @@ var QRCanvas = class _QRCanvas {
|
|
|
1523
1674
|
canvasContext.fillStyle = canvasContext.strokeStyle = gradient;
|
|
1524
1675
|
} else if ((_f = options.cornersDotOptions) == null ? void 0 : _f.color) {
|
|
1525
1676
|
canvasContext.fillStyle = canvasContext.strokeStyle = options.cornersDotOptions.color;
|
|
1677
|
+
} else if (this._finderColors) {
|
|
1678
|
+
canvasContext.fillStyle = canvasContext.strokeStyle = this._finderColors[index];
|
|
1526
1679
|
}
|
|
1527
1680
|
canvasContext.fill("evenodd");
|
|
1528
1681
|
});
|
|
@@ -1571,8 +1724,7 @@ var QRCanvas = class _QRCanvas {
|
|
|
1571
1724
|
throw "image is not defined";
|
|
1572
1725
|
}
|
|
1573
1726
|
const options = this._options;
|
|
1574
|
-
const xBeginning =
|
|
1575
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1727
|
+
const { x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
1576
1728
|
const dx = xBeginning + options.imageOptions.margin + (count * dotSize - width) / 2;
|
|
1577
1729
|
const dy = yBeginning + options.imageOptions.margin + (count * dotSize - height) / 2;
|
|
1578
1730
|
const dw = width - options.imageOptions.margin * 2;
|
|
@@ -1673,6 +1825,19 @@ var QRDot2 = class {
|
|
|
1673
1825
|
};
|
|
1674
1826
|
break;
|
|
1675
1827
|
}
|
|
1828
|
+
case dotTypes_default.fluid:
|
|
1829
|
+
drawFunction = (args) => {
|
|
1830
|
+
const has = (dx, dy) => args.getNeighbor ? args.getNeighbor(dx, dy) : false;
|
|
1831
|
+
this._drawShape(
|
|
1832
|
+
fluid(args.x, args.y, args.size, {
|
|
1833
|
+
left: has(-1, 0),
|
|
1834
|
+
right: has(1, 0),
|
|
1835
|
+
top: has(0, -1),
|
|
1836
|
+
bottom: has(0, 1)
|
|
1837
|
+
})
|
|
1838
|
+
);
|
|
1839
|
+
};
|
|
1840
|
+
break;
|
|
1676
1841
|
case dotTypes_default.square:
|
|
1677
1842
|
default:
|
|
1678
1843
|
drawFunction = this._drawSquare;
|
|
@@ -2323,8 +2488,7 @@ var QRSVG = class _QRSVG {
|
|
|
2323
2488
|
return this._drawFramed(qr);
|
|
2324
2489
|
}
|
|
2325
2490
|
const count = qr.getModuleCount();
|
|
2326
|
-
const
|
|
2327
|
-
const dotSize = Math.floor(minSize / count);
|
|
2491
|
+
const { dotSize } = getQRArea(this._options, count);
|
|
2328
2492
|
let drawImageSize = {
|
|
2329
2493
|
hideXDots: 0,
|
|
2330
2494
|
hideYDots: 0,
|
|
@@ -2368,7 +2532,12 @@ var QRSVG = class _QRSVG {
|
|
|
2368
2532
|
}
|
|
2369
2533
|
this.clear();
|
|
2370
2534
|
this.drawBackground();
|
|
2371
|
-
if ((art == null ? void 0 : art.mode) === "
|
|
2535
|
+
if ((art == null ? void 0 : art.mode) === "blend") {
|
|
2536
|
+
this._appendImage(art.picture.toDataURL("image/png"), 0, 0);
|
|
2537
|
+
this._drawArtRects(art.rects);
|
|
2538
|
+
this.drawDots(() => false);
|
|
2539
|
+
this._finderColors = art.finderColors;
|
|
2540
|
+
} else if ((art == null ? void 0 : art.mode) === "halftone") {
|
|
2372
2541
|
this._drawArtRects(art.rects);
|
|
2373
2542
|
this.drawDots(() => false);
|
|
2374
2543
|
} else {
|
|
@@ -2380,6 +2549,7 @@ var QRSVG = class _QRSVG {
|
|
|
2380
2549
|
this._dotsImageHref = void 0;
|
|
2381
2550
|
}
|
|
2382
2551
|
this.drawCorners();
|
|
2552
|
+
this._finderColors = void 0;
|
|
2383
2553
|
if (this._options.image) {
|
|
2384
2554
|
this.drawImage({ width: drawImageSize.width, height: drawImageSize.height, count, dotSize });
|
|
2385
2555
|
}
|
|
@@ -2415,10 +2585,7 @@ var QRSVG = class _QRSVG {
|
|
|
2415
2585
|
if (count > options.width || count > options.height) {
|
|
2416
2586
|
throw "The canvas is too small.";
|
|
2417
2587
|
}
|
|
2418
|
-
const
|
|
2419
|
-
const dotSize = Math.floor(minSize / count);
|
|
2420
|
-
const xBeginning = Math.floor((options.width - count * dotSize) / 2);
|
|
2421
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
2588
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
2422
2589
|
const typeDot = new QRDot2({
|
|
2423
2590
|
svg: this._element,
|
|
2424
2591
|
type: options.dotsOptions.type,
|
|
@@ -2476,31 +2643,28 @@ var QRSVG = class _QRSVG {
|
|
|
2476
2643
|
throw "Element code is not defined";
|
|
2477
2644
|
}
|
|
2478
2645
|
const count = this._qr.getModuleCount();
|
|
2479
|
-
const
|
|
2480
|
-
const dotSize = Math.floor(minSize / count);
|
|
2646
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
2481
2647
|
const cornersSquareSize = dotSize * 7;
|
|
2482
2648
|
const cornersDotSize = dotSize * 3;
|
|
2483
2649
|
const cornerTypes = getCornerTypes(options);
|
|
2484
|
-
const xBeginning = Math.floor((options.width - count * dotSize) / 2);
|
|
2485
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
2486
2650
|
[
|
|
2487
2651
|
[0, 0, 0],
|
|
2488
2652
|
[1, 0, Math.PI / 2],
|
|
2489
2653
|
[0, 1, -Math.PI / 2]
|
|
2490
|
-
].forEach(([column, row, rotation]) => {
|
|
2491
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2654
|
+
].forEach(([column, row, rotation], index) => {
|
|
2655
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2492
2656
|
const x = xBeginning + column * dotSize * (count - 7);
|
|
2493
2657
|
const y = yBeginning + row * dotSize * (count - 7);
|
|
2494
2658
|
let cornersSquareClipPath = this._dotsClipPath;
|
|
2495
2659
|
let cornersDotClipPath = this._dotsClipPath;
|
|
2496
|
-
if (((_a = options.cornersSquareOptions) == null ? void 0 : _a.gradient) || ((_b = options.cornersSquareOptions) == null ? void 0 : _b.color)) {
|
|
2660
|
+
if (((_a = options.cornersSquareOptions) == null ? void 0 : _a.gradient) || ((_b = options.cornersSquareOptions) == null ? void 0 : _b.color) || this._finderColors) {
|
|
2497
2661
|
cornersSquareClipPath = this._window.document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2498
2662
|
cornersSquareClipPath.setAttribute("id", `clip-path-corners-square-color-${column}-${row}`);
|
|
2499
2663
|
this._defs.appendChild(cornersSquareClipPath);
|
|
2500
2664
|
this._cornersSquareClipPath = this._cornersDotClipPath = cornersDotClipPath = cornersSquareClipPath;
|
|
2501
2665
|
this._createColor({
|
|
2502
2666
|
options: (_c = options.cornersSquareOptions) == null ? void 0 : _c.gradient,
|
|
2503
|
-
color: (_d = options.cornersSquareOptions) == null ? void 0 : _d.color,
|
|
2667
|
+
color: (_f = (_d = options.cornersSquareOptions) == null ? void 0 : _d.color) != null ? _f : (_e = this._finderColors) == null ? void 0 : _e[index],
|
|
2504
2668
|
additionalRotation: rotation,
|
|
2505
2669
|
x,
|
|
2506
2670
|
y,
|
|
@@ -2527,7 +2691,7 @@ var QRSVG = class _QRSVG {
|
|
|
2527
2691
|
});
|
|
2528
2692
|
for (let i = 0; i < squareMask2.length; i++) {
|
|
2529
2693
|
for (let j = 0; j < squareMask2[i].length; j++) {
|
|
2530
|
-
if (!((
|
|
2694
|
+
if (!((_g = squareMask2[i]) == null ? void 0 : _g[j])) {
|
|
2531
2695
|
continue;
|
|
2532
2696
|
}
|
|
2533
2697
|
dot.draw(
|
|
@@ -2545,14 +2709,14 @@ var QRSVG = class _QRSVG {
|
|
|
2545
2709
|
}
|
|
2546
2710
|
}
|
|
2547
2711
|
}
|
|
2548
|
-
if (((
|
|
2712
|
+
if (((_h = options.cornersDotOptions) == null ? void 0 : _h.gradient) || ((_i = options.cornersDotOptions) == null ? void 0 : _i.color) || this._finderColors) {
|
|
2549
2713
|
cornersDotClipPath = this._window.document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2550
2714
|
cornersDotClipPath.setAttribute("id", `clip-path-corners-dot-color-${column}-${row}`);
|
|
2551
2715
|
this._defs.appendChild(cornersDotClipPath);
|
|
2552
2716
|
this._cornersDotClipPath = cornersDotClipPath;
|
|
2553
2717
|
this._createColor({
|
|
2554
|
-
options: (
|
|
2555
|
-
color: (
|
|
2718
|
+
options: (_j = options.cornersDotOptions) == null ? void 0 : _j.gradient,
|
|
2719
|
+
color: (_m = (_k = options.cornersDotOptions) == null ? void 0 : _k.color) != null ? _m : (_l = this._finderColors) == null ? void 0 : _l[index],
|
|
2556
2720
|
additionalRotation: rotation,
|
|
2557
2721
|
x: x + dotSize * 2,
|
|
2558
2722
|
y: y + dotSize * 2,
|
|
@@ -2579,7 +2743,7 @@ var QRSVG = class _QRSVG {
|
|
|
2579
2743
|
});
|
|
2580
2744
|
for (let i = 0; i < dotMask2.length; i++) {
|
|
2581
2745
|
for (let j = 0; j < dotMask2[i].length; j++) {
|
|
2582
|
-
if (!((
|
|
2746
|
+
if (!((_n = dotMask2[i]) == null ? void 0 : _n[j])) {
|
|
2583
2747
|
continue;
|
|
2584
2748
|
}
|
|
2585
2749
|
dot.draw(
|
|
@@ -2600,14 +2764,10 @@ var QRSVG = class _QRSVG {
|
|
|
2600
2764
|
});
|
|
2601
2765
|
}
|
|
2602
2766
|
_drawArtRects(rects) {
|
|
2603
|
-
rects.forEach(({ x, y, width, height, color }) => {
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
rect2.setAttribute("width", String(width));
|
|
2608
|
-
rect2.setAttribute("height", String(height));
|
|
2609
|
-
rect2.setAttribute("fill", color);
|
|
2610
|
-
this._element.appendChild(rect2);
|
|
2767
|
+
rects.forEach(({ x, y, width, height, color, shape }) => {
|
|
2768
|
+
this._element.appendChild(
|
|
2769
|
+
shape === "circle" ? this._svgElement("circle", { cx: x + width / 2, cy: y + height / 2, r: width / 2, fill: color }) : this._svgElement("rect", { x, y, width, height, fill: color })
|
|
2770
|
+
);
|
|
2611
2771
|
});
|
|
2612
2772
|
}
|
|
2613
2773
|
_appendImage(href, x, y) {
|
|
@@ -2679,8 +2839,7 @@ var QRSVG = class _QRSVG {
|
|
|
2679
2839
|
dotSize
|
|
2680
2840
|
}) {
|
|
2681
2841
|
const options = this._options;
|
|
2682
|
-
const xBeginning =
|
|
2683
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
2842
|
+
const { x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
2684
2843
|
const dx = xBeginning + options.imageOptions.margin + (count * dotSize - width) / 2;
|
|
2685
2844
|
const dy = yBeginning + options.imageOptions.margin + (count * dotSize - height) / 2;
|
|
2686
2845
|
const dw = width - options.imageOptions.margin * 2;
|