qr-code-styling-node 1.10.0 → 1.12.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 +74 -1
- package/lib/core/QRCodeStyling.d.ts +23 -1
- package/lib/core/QRSVG.d.ts +5 -1
- package/lib/figures/shapes.d.ts +19 -0
- package/lib/index.d.ts +3 -1
- 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 +481 -51
- package/lib/qr-code-styling.mjs.map +4 -4
- package/lib/tools/circle.d.ts +16 -0
- package/lib/tools/cornerTypes.d.ts +0 -1
- package/lib/tools/pathRecorder.d.ts +15 -0
- package/lib/tools/payloads.d.ts +72 -0
- package/lib/tools/utf8.d.ts +4 -0
- package/lib/types/index.d.ts +17 -1
- package/package.json +4 -2
package/lib/qr-code-styling.mjs
CHANGED
|
@@ -114,7 +114,10 @@ var dotTypes_default = {
|
|
|
114
114
|
smallSquare: "small-square",
|
|
115
115
|
verticalLines: "vertical-lines",
|
|
116
116
|
horizontalLines: "horizontal-lines",
|
|
117
|
-
fluid: "fluid"
|
|
117
|
+
fluid: "fluid",
|
|
118
|
+
wave: "wave",
|
|
119
|
+
blob: "blob",
|
|
120
|
+
circuit: "circuit"
|
|
118
121
|
};
|
|
119
122
|
|
|
120
123
|
// src/figures/shapes.ts
|
|
@@ -252,6 +255,102 @@ var fluid = (x, y, size, neighbors) => {
|
|
|
252
255
|
shape.push({ op: "Z" });
|
|
253
256
|
return shape;
|
|
254
257
|
};
|
|
258
|
+
var bulgeArc = (x0, y0, x1, y1, sagitta) => {
|
|
259
|
+
const chord = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
|
|
260
|
+
const r = chord * chord / (8 * sagitta) + sagitta / 2;
|
|
261
|
+
const nx = (y1 - y0) / chord;
|
|
262
|
+
const ny = -(x1 - x0) / chord;
|
|
263
|
+
const cx = (x0 + x1) / 2 - nx * (r - sagitta);
|
|
264
|
+
const cy = (y0 + y1) / 2 - ny * (r - sagitta);
|
|
265
|
+
return { op: "A", cx, cy, r, start: Math.atan2(y0 - cy, x0 - cx), end: Math.atan2(y1 - cy, x1 - cx) };
|
|
266
|
+
};
|
|
267
|
+
var wave = (x, y, size, { left, right }) => {
|
|
268
|
+
const half = size * 0.3;
|
|
269
|
+
const bulge = size * 0.1;
|
|
270
|
+
const cy = y + size / 2;
|
|
271
|
+
const x0 = left ? x : x + half;
|
|
272
|
+
const x1 = right ? x + size : x + size - half;
|
|
273
|
+
const shape = [{ op: "M", x: x0, y: cy - half }];
|
|
274
|
+
shape.push(bulgeArc(x0, cy - half, x1, cy - half, bulge));
|
|
275
|
+
if (right) shape.push({ op: "L", x: x1, y: cy + half });
|
|
276
|
+
else shape.push({ op: "A", cx: x1, cy, r: half, start: -Math.PI / 2, end: Math.PI / 2 });
|
|
277
|
+
shape.push(bulgeArc(x1, cy + half, x0, cy + half, bulge));
|
|
278
|
+
if (left) shape.push({ op: "L", x: x0, y: cy - half });
|
|
279
|
+
else shape.push({ op: "A", cx: x0, cy, r: half, start: Math.PI / 2, end: 3 * Math.PI / 2 });
|
|
280
|
+
shape.push({ op: "Z" });
|
|
281
|
+
return shape;
|
|
282
|
+
};
|
|
283
|
+
var noise = (a, b, salt) => {
|
|
284
|
+
let h = Math.imul(Math.round(a * 16) + 40503, 668265261) ^ Math.imul(Math.round(b * 16) + salt, 374761393);
|
|
285
|
+
h = Math.imul(h ^ h >>> 15, 2246822507);
|
|
286
|
+
h ^= h >>> 13;
|
|
287
|
+
return (h >>> 0) / 4294967296;
|
|
288
|
+
};
|
|
289
|
+
var blob = (x, y, size) => {
|
|
290
|
+
const inset = size * (0.03 + 0.07 * noise(x, y, 1));
|
|
291
|
+
const left = x + inset;
|
|
292
|
+
const top = y + inset;
|
|
293
|
+
const side = size - 2 * inset;
|
|
294
|
+
const radius = (k) => side * (0.25 + 0.25 * noise(x, y, k + 2));
|
|
295
|
+
const [tl, tr, br, bl] = [radius(0), radius(1), radius(2), radius(3)];
|
|
296
|
+
return [
|
|
297
|
+
{ op: "M", x: left + tl, y: top },
|
|
298
|
+
{ op: "L", x: left + side - tr, y: top },
|
|
299
|
+
{ op: "A", cx: left + side - tr, cy: top + tr, r: tr, start: -Math.PI / 2, end: 0 },
|
|
300
|
+
{ op: "L", x: left + side, y: top + side - br },
|
|
301
|
+
{ op: "A", cx: left + side - br, cy: top + side - br, r: br, start: 0, end: Math.PI / 2 },
|
|
302
|
+
{ op: "L", x: left + bl, y: top + side },
|
|
303
|
+
{ op: "A", cx: left + bl, cy: top + side - bl, r: bl, start: Math.PI / 2, end: Math.PI },
|
|
304
|
+
{ op: "L", x: left, y: top + tl },
|
|
305
|
+
{ op: "A", cx: left + tl, cy: top + tl, r: tl, start: Math.PI, end: 3 * Math.PI / 2 },
|
|
306
|
+
{ op: "Z" }
|
|
307
|
+
];
|
|
308
|
+
};
|
|
309
|
+
var circuit = (x, y, size, neighbors) => {
|
|
310
|
+
const cx = x + size / 2;
|
|
311
|
+
const cy = y + size / 2;
|
|
312
|
+
const r = size * 0.36;
|
|
313
|
+
const w = size * 0.17;
|
|
314
|
+
const alpha = Math.asin(w / r);
|
|
315
|
+
const arms = [
|
|
316
|
+
{ on: neighbors.top, angle: -Math.PI / 2 },
|
|
317
|
+
{ on: neighbors.right, angle: 0 },
|
|
318
|
+
{ on: neighbors.bottom, angle: Math.PI / 2 },
|
|
319
|
+
{ on: neighbors.left, angle: Math.PI }
|
|
320
|
+
].filter((arm) => arm.on);
|
|
321
|
+
if (!arms.length) {
|
|
322
|
+
return [
|
|
323
|
+
{ op: "M", x: cx + r, y: cy },
|
|
324
|
+
{ op: "A", cx, cy, r, start: 0, end: Math.PI },
|
|
325
|
+
{ op: "A", cx, cy, r, start: Math.PI, end: 2 * Math.PI },
|
|
326
|
+
{ op: "Z" }
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
const point = (angle) => ({
|
|
330
|
+
x: cx + r * Math.cos(angle),
|
|
331
|
+
y: cy + r * Math.sin(angle)
|
|
332
|
+
});
|
|
333
|
+
const toEdge = (angle, at) => {
|
|
334
|
+
const reach = size / 2 - r * Math.cos(alpha);
|
|
335
|
+
return { x: at.x + reach * Math.cos(angle), y: at.y + reach * Math.sin(angle) };
|
|
336
|
+
};
|
|
337
|
+
const first = point(arms[0].angle + alpha);
|
|
338
|
+
const shape = [{ op: "M", x: first.x, y: first.y }];
|
|
339
|
+
for (let k = 0; k < arms.length; k++) {
|
|
340
|
+
const from = arms[k].angle + alpha;
|
|
341
|
+
const next = arms[(k + 1) % arms.length];
|
|
342
|
+
let to = next.angle - alpha;
|
|
343
|
+
if (k === arms.length - 1 || to <= from) to += 2 * Math.PI;
|
|
344
|
+
if (to - from > 1e-6) shape.push({ op: "A", cx, cy, r, start: from, end: to });
|
|
345
|
+
const a = point(next.angle - alpha);
|
|
346
|
+
const b = point(next.angle + alpha);
|
|
347
|
+
const ea = toEdge(next.angle, a);
|
|
348
|
+
const eb = toEdge(next.angle, b);
|
|
349
|
+
shape.push({ op: "L", x: ea.x, y: ea.y }, { op: "L", x: eb.x, y: eb.y }, { op: "L", x: b.x, y: b.y });
|
|
350
|
+
}
|
|
351
|
+
shape.push({ op: "Z" });
|
|
352
|
+
return shape;
|
|
353
|
+
};
|
|
255
354
|
|
|
256
355
|
// src/figures/dot/canvas/QRDot.ts
|
|
257
356
|
var QRDot = class {
|
|
@@ -295,11 +394,17 @@ var QRDot = class {
|
|
|
295
394
|
};
|
|
296
395
|
break;
|
|
297
396
|
}
|
|
397
|
+
case dotTypes_default.blob:
|
|
398
|
+
drawFunction = (args) => this._drawShape(blob(args.x, args.y, args.size));
|
|
399
|
+
break;
|
|
400
|
+
case dotTypes_default.wave:
|
|
401
|
+
case dotTypes_default.circuit:
|
|
298
402
|
case dotTypes_default.fluid:
|
|
299
403
|
drawFunction = (args) => {
|
|
300
404
|
const has = (dx, dy) => args.getNeighbor ? args.getNeighbor(dx, dy) : false;
|
|
405
|
+
const shapeOf = type === dotTypes_default.wave ? wave : type === dotTypes_default.circuit ? circuit : fluid;
|
|
301
406
|
this._drawShape(
|
|
302
|
-
|
|
407
|
+
shapeOf(args.x, args.y, args.size, {
|
|
303
408
|
left: has(-1, 0),
|
|
304
409
|
right: has(1, 0),
|
|
305
410
|
top: has(0, -1),
|
|
@@ -702,12 +807,33 @@ var QRCornerDot = class {
|
|
|
702
807
|
}
|
|
703
808
|
};
|
|
704
809
|
|
|
810
|
+
// src/tools/circle.ts
|
|
811
|
+
var isCircle = (options) => options.shape === "circle";
|
|
812
|
+
function getCircleLayout(count) {
|
|
813
|
+
let size = Math.ceil((count + 2) * Math.SQRT2) + 1;
|
|
814
|
+
if ((size - count) % 2) size++;
|
|
815
|
+
const pad2 = (size - count) / 2;
|
|
816
|
+
const radius = size / 2;
|
|
817
|
+
const center = count / 2;
|
|
818
|
+
const isDecoration = (i, j) => {
|
|
819
|
+
if (i >= -1 && i <= count && j >= -1 && j <= count) return false;
|
|
820
|
+
const dx = i + 0.5 - center;
|
|
821
|
+
const dy = j + 0.5 - center;
|
|
822
|
+
if (dx * dx + dy * dy > (radius - 0.5) * (radius - 0.5)) return false;
|
|
823
|
+
let h = Math.imul(i + 1013, 668265261) ^ Math.imul(j + 7919, 374761393) ^ Math.imul(count, 2654435769);
|
|
824
|
+
h = Math.imul(h ^ h >>> 15, 2246822507);
|
|
825
|
+
h ^= h >>> 13;
|
|
826
|
+
return (h >>> 0) % 100 < 45;
|
|
827
|
+
};
|
|
828
|
+
return { size, pad: pad2, isDecoration };
|
|
829
|
+
}
|
|
830
|
+
|
|
705
831
|
// src/tools/qrArea.ts
|
|
706
832
|
function getQRArea(options, count) {
|
|
707
833
|
var _a;
|
|
708
834
|
const placement = (_a = options.art) == null ? void 0 : _a.placement;
|
|
709
835
|
if (placement && placement.size > 0) {
|
|
710
|
-
const dotSize2 = Math.floor(placement.size / count);
|
|
836
|
+
const dotSize2 = Math.floor(placement.size / (options.shape === "circle" ? getCircleLayout(count).size : count));
|
|
711
837
|
return {
|
|
712
838
|
count,
|
|
713
839
|
dotSize: dotSize2,
|
|
@@ -716,7 +842,7 @@ function getQRArea(options, count) {
|
|
|
716
842
|
};
|
|
717
843
|
}
|
|
718
844
|
const minSize = Math.min(options.width, options.height) - options.margin * 2;
|
|
719
|
-
const dotSize = Math.floor(minSize / count);
|
|
845
|
+
const dotSize = Math.floor(minSize / (options.shape === "circle" ? getCircleLayout(count).size : count));
|
|
720
846
|
return {
|
|
721
847
|
count,
|
|
722
848
|
dotSize,
|
|
@@ -727,12 +853,22 @@ function getQRArea(options, count) {
|
|
|
727
853
|
|
|
728
854
|
// src/tools/cornerTypes.ts
|
|
729
855
|
var SOLID_CORNER_DOT_TYPES = ["diamond", "small-square", "vertical-lines", "horizontal-lines"];
|
|
730
|
-
var ROUND_DOT_TYPES = [
|
|
731
|
-
|
|
856
|
+
var ROUND_DOT_TYPES = [
|
|
857
|
+
"dots",
|
|
858
|
+
"rounded",
|
|
859
|
+
"extra-rounded",
|
|
860
|
+
"classy-rounded",
|
|
861
|
+
"fluid",
|
|
862
|
+
"wave",
|
|
863
|
+
"blob",
|
|
864
|
+
"circuit"
|
|
865
|
+
];
|
|
866
|
+
var SOLID_ROUND_DOT_TYPES = ["fluid", "wave", "blob", "circuit"];
|
|
867
|
+
var needsSolidAlignment = (type) => SOLID_ROUND_DOT_TYPES.indexOf(type) !== -1 || SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
732
868
|
function getCornerTypes(options) {
|
|
733
869
|
var _a, _b, _c, _d, _e;
|
|
734
870
|
const type = options.dotsOptions.type;
|
|
735
|
-
if (((_a = options.art) == null ? void 0 : _a.mode) === "blend" ||
|
|
871
|
+
if (((_a = options.art) == null ? void 0 : _a.mode) === "blend" || options.shape === "circle" || SOLID_ROUND_DOT_TYPES.indexOf(type) !== -1) {
|
|
736
872
|
const round2 = ROUND_DOT_TYPES.indexOf(type) !== -1;
|
|
737
873
|
return {
|
|
738
874
|
square: ((_b = options.cornersSquareOptions) == null ? void 0 : _b.type) || (round2 ? "rounded" : "square"),
|
|
@@ -1486,10 +1622,18 @@ var QRCanvas = class _QRCanvas {
|
|
|
1486
1622
|
} else if (options.backgroundOptions.color) {
|
|
1487
1623
|
canvasContext.fillStyle = options.backgroundOptions.color;
|
|
1488
1624
|
}
|
|
1625
|
+
if (isCircle(options)) {
|
|
1626
|
+
const size = Math.min(this._canvas.width, this._canvas.height);
|
|
1627
|
+
canvasContext.beginPath();
|
|
1628
|
+
canvasContext.arc(this._canvas.width / 2, this._canvas.height / 2, size / 2, 0, Math.PI * 2);
|
|
1629
|
+
canvasContext.fill();
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1489
1632
|
canvasContext.fillRect(0, 0, this._canvas.width, this._canvas.height);
|
|
1490
1633
|
}
|
|
1491
1634
|
}
|
|
1492
1635
|
drawDots(filter) {
|
|
1636
|
+
var _a;
|
|
1493
1637
|
if (!this._qr) {
|
|
1494
1638
|
throw "QR code is not defined";
|
|
1495
1639
|
}
|
|
@@ -1503,28 +1647,38 @@ var QRCanvas = class _QRCanvas {
|
|
|
1503
1647
|
throw "The canvas is too small.";
|
|
1504
1648
|
}
|
|
1505
1649
|
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
1650
|
+
const colorPad = isCircle(options) ? getCircleLayout(count).pad * dotSize : 0;
|
|
1506
1651
|
const typeDot = new QRDot({ context: canvasContext, type: options.dotsOptions.type });
|
|
1507
1652
|
const squareDot = new QRDot({ context: canvasContext, type: "square" });
|
|
1508
1653
|
const solidAlignment = needsSolidAlignment(options.dotsOptions.type);
|
|
1509
1654
|
const role = solidAlignment ? getModuleRoles(count) : void 0;
|
|
1510
1655
|
canvasContext.beginPath();
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1656
|
+
const circle = isCircle(options) ? getCircleLayout(count) : void 0;
|
|
1657
|
+
const from = circle ? -circle.pad : 0;
|
|
1658
|
+
const to = circle ? count + circle.pad : count;
|
|
1659
|
+
const inCode = (i, j) => i >= 0 && j >= 0 && i < count && j < count;
|
|
1660
|
+
const isDark = (i, j) => {
|
|
1661
|
+
if (filter && !filter(i, j)) return false;
|
|
1662
|
+
if (inCode(i, j)) return !!this._qr && this._qr.isDark(i, j);
|
|
1663
|
+
return !!circle && circle.isDecoration(i, j);
|
|
1664
|
+
};
|
|
1665
|
+
for (let i = from; i < to; i++) {
|
|
1666
|
+
for (let j = from; j < to; j++) {
|
|
1667
|
+
if (inCode(i, j) ? filter && !filter(i, j) || !((_a = this._qr) == null ? void 0 : _a.isDark(i, j)) : !isDark(i, j)) {
|
|
1517
1668
|
continue;
|
|
1518
1669
|
}
|
|
1519
|
-
const dot = role && role(i, j) === "alignment" ? squareDot : typeDot;
|
|
1670
|
+
const dot = role && inCode(i, j) && role(i, j) === "alignment" ? squareDot : typeDot;
|
|
1520
1671
|
dot.draw(
|
|
1521
1672
|
xBeginning + i * dotSize,
|
|
1522
1673
|
yBeginning + j * dotSize,
|
|
1523
1674
|
dotSize,
|
|
1524
1675
|
(xOffset, yOffset) => {
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1527
|
-
|
|
1676
|
+
if (!circle) {
|
|
1677
|
+
if (i + xOffset < 0 || j + yOffset < 0 || i + xOffset >= count || j + yOffset >= count) return false;
|
|
1678
|
+
if (filter && !filter(i + xOffset, j + yOffset)) return false;
|
|
1679
|
+
return !!this._qr && this._qr.isDark(i + xOffset, j + yOffset);
|
|
1680
|
+
}
|
|
1681
|
+
return isDark(i + xOffset, j + yOffset);
|
|
1528
1682
|
}
|
|
1529
1683
|
);
|
|
1530
1684
|
}
|
|
@@ -1535,9 +1689,9 @@ var QRCanvas = class _QRCanvas {
|
|
|
1535
1689
|
context: canvasContext,
|
|
1536
1690
|
options: gradientOptions,
|
|
1537
1691
|
additionalRotation: 0,
|
|
1538
|
-
x: xBeginning,
|
|
1539
|
-
y: yBeginning,
|
|
1540
|
-
size: count * dotSize
|
|
1692
|
+
x: xBeginning - colorPad,
|
|
1693
|
+
y: yBeginning - colorPad,
|
|
1694
|
+
size: count * dotSize + 2 * colorPad
|
|
1541
1695
|
});
|
|
1542
1696
|
gradientOptions.colorStops.forEach(({ offset, color }) => {
|
|
1543
1697
|
gradient.addColorStop(offset, color);
|
|
@@ -1825,11 +1979,17 @@ var QRDot2 = class {
|
|
|
1825
1979
|
};
|
|
1826
1980
|
break;
|
|
1827
1981
|
}
|
|
1982
|
+
case dotTypes_default.blob:
|
|
1983
|
+
drawFunction = (args) => this._drawShape(blob(args.x, args.y, args.size));
|
|
1984
|
+
break;
|
|
1985
|
+
case dotTypes_default.wave:
|
|
1986
|
+
case dotTypes_default.circuit:
|
|
1828
1987
|
case dotTypes_default.fluid:
|
|
1829
1988
|
drawFunction = (args) => {
|
|
1830
1989
|
const has = (dx, dy) => args.getNeighbor ? args.getNeighbor(dx, dy) : false;
|
|
1990
|
+
const shapeOf = type === dotTypes_default.wave ? wave : type === dotTypes_default.circuit ? circuit : fluid;
|
|
1831
1991
|
this._drawShape(
|
|
1832
|
-
|
|
1992
|
+
shapeOf(args.x, args.y, args.size, {
|
|
1833
1993
|
left: has(-1, 0),
|
|
1834
1994
|
right: has(1, 0),
|
|
1835
1995
|
top: has(0, -1),
|
|
@@ -2066,6 +2226,85 @@ var QRDot2 = class {
|
|
|
2066
2226
|
}
|
|
2067
2227
|
};
|
|
2068
2228
|
|
|
2229
|
+
// src/tools/pathRecorder.ts
|
|
2230
|
+
var fmt = (value) => String(Math.round(value * 1e3) / 1e3);
|
|
2231
|
+
var PathRecorder = class {
|
|
2232
|
+
constructor() {
|
|
2233
|
+
this._m = [1, 0, 0, 1, 0, 0];
|
|
2234
|
+
this._parts = [];
|
|
2235
|
+
this._open = false;
|
|
2236
|
+
}
|
|
2237
|
+
get d() {
|
|
2238
|
+
return this._parts.join("");
|
|
2239
|
+
}
|
|
2240
|
+
beginPath() {
|
|
2241
|
+
}
|
|
2242
|
+
translate(x, y) {
|
|
2243
|
+
const [a, b, c, d, e, f] = this._m;
|
|
2244
|
+
this._m = [a, b, c, d, e + a * x + c * y, f + b * x + d * y];
|
|
2245
|
+
}
|
|
2246
|
+
rotate(angle) {
|
|
2247
|
+
const [a, b, c, d, e, f] = this._m;
|
|
2248
|
+
const cos = Math.cos(angle);
|
|
2249
|
+
const sin = Math.sin(angle);
|
|
2250
|
+
this._m = [a * cos + c * sin, b * cos + d * sin, c * cos - a * sin, d * cos - b * sin, e, f];
|
|
2251
|
+
}
|
|
2252
|
+
_point(x, y) {
|
|
2253
|
+
const [a, b, c, d, e, f] = this._m;
|
|
2254
|
+
return [a * x + c * y + e, b * x + d * y + f];
|
|
2255
|
+
}
|
|
2256
|
+
moveTo(x, y) {
|
|
2257
|
+
const [px, py] = this._point(x, y);
|
|
2258
|
+
this._parts.push(`M${fmt(px)} ${fmt(py)}`);
|
|
2259
|
+
this._open = true;
|
|
2260
|
+
}
|
|
2261
|
+
lineTo(x, y) {
|
|
2262
|
+
if (!this._open) return this.moveTo(x, y);
|
|
2263
|
+
const [px, py] = this._point(x, y);
|
|
2264
|
+
this._parts.push(`L${fmt(px)} ${fmt(py)}`);
|
|
2265
|
+
}
|
|
2266
|
+
closePath() {
|
|
2267
|
+
if (!this._open) return;
|
|
2268
|
+
this._parts.push("Z");
|
|
2269
|
+
this._open = false;
|
|
2270
|
+
}
|
|
2271
|
+
rect(x, y, width, height) {
|
|
2272
|
+
this.moveTo(x, y);
|
|
2273
|
+
this.lineTo(x + width, y);
|
|
2274
|
+
this.lineTo(x + width, y + height);
|
|
2275
|
+
this.lineTo(x, y + height);
|
|
2276
|
+
this.closePath();
|
|
2277
|
+
}
|
|
2278
|
+
arc(cx, cy, r, start, end, anticlockwise = false) {
|
|
2279
|
+
let sweep = anticlockwise ? start - end : end - start;
|
|
2280
|
+
const full = sweep >= 2 * Math.PI - 1e-9;
|
|
2281
|
+
if (!full) {
|
|
2282
|
+
sweep %= 2 * Math.PI;
|
|
2283
|
+
if (sweep < 0) sweep += 2 * Math.PI;
|
|
2284
|
+
}
|
|
2285
|
+
const direction = anticlockwise ? -1 : 1;
|
|
2286
|
+
const at = (angle) => this._point(cx + r * Math.cos(angle), cy + r * Math.sin(angle));
|
|
2287
|
+
const [sx, sy] = at(start);
|
|
2288
|
+
if (this._open) this._parts.push(`L${fmt(sx)} ${fmt(sy)}`);
|
|
2289
|
+
else {
|
|
2290
|
+
this._parts.push(`M${fmt(sx)} ${fmt(sy)}`);
|
|
2291
|
+
this._open = true;
|
|
2292
|
+
}
|
|
2293
|
+
const segment = (to, length) => {
|
|
2294
|
+
const [ex, ey] = at(to);
|
|
2295
|
+
this._parts.push(
|
|
2296
|
+
`A${fmt(r)} ${fmt(r)} 0 ${length > Math.PI ? 1 : 0} ${anticlockwise ? 0 : 1} ${fmt(ex)} ${fmt(ey)}`
|
|
2297
|
+
);
|
|
2298
|
+
};
|
|
2299
|
+
if (full) {
|
|
2300
|
+
segment(start + direction * Math.PI, Math.PI);
|
|
2301
|
+
segment(start + direction * 2 * Math.PI, Math.PI);
|
|
2302
|
+
} else if (sweep > 1e-9) {
|
|
2303
|
+
segment(start + direction * sweep, sweep);
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
|
|
2069
2308
|
// src/figures/cornerSquare/svg/QRCornerSquare.ts
|
|
2070
2309
|
var QRCornerSquare2 = class {
|
|
2071
2310
|
constructor({ svg, type, window: window2 }) {
|
|
@@ -2562,6 +2801,21 @@ var QRSVG = class _QRSVG {
|
|
|
2562
2801
|
const gradientOptions = (_a = options.backgroundOptions) == null ? void 0 : _a.gradient;
|
|
2563
2802
|
const color = (_b = options.backgroundOptions) == null ? void 0 : _b.color;
|
|
2564
2803
|
if (gradientOptions || color) {
|
|
2804
|
+
if (isCircle(options)) {
|
|
2805
|
+
const size = Math.min(options.width, options.height);
|
|
2806
|
+
this._createColor({
|
|
2807
|
+
options: gradientOptions,
|
|
2808
|
+
color,
|
|
2809
|
+
additionalRotation: 0,
|
|
2810
|
+
x: (options.width - size) / 2,
|
|
2811
|
+
y: (options.height - size) / 2,
|
|
2812
|
+
height: size,
|
|
2813
|
+
width: size,
|
|
2814
|
+
name: "background-color",
|
|
2815
|
+
radius: size / 2
|
|
2816
|
+
});
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2565
2819
|
this._createColor({
|
|
2566
2820
|
options: gradientOptions,
|
|
2567
2821
|
color,
|
|
@@ -2576,7 +2830,7 @@ var QRSVG = class _QRSVG {
|
|
|
2576
2830
|
}
|
|
2577
2831
|
}
|
|
2578
2832
|
drawDots(filter) {
|
|
2579
|
-
var _a, _b;
|
|
2833
|
+
var _a, _b, _c;
|
|
2580
2834
|
if (!this._qr) {
|
|
2581
2835
|
throw "QR code is not defined";
|
|
2582
2836
|
}
|
|
@@ -2586,52 +2840,70 @@ var QRSVG = class _QRSVG {
|
|
|
2586
2840
|
throw "The canvas is too small.";
|
|
2587
2841
|
}
|
|
2588
2842
|
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
2843
|
+
const colorPad = isCircle(options) ? getCircleLayout(count).pad * dotSize : 0;
|
|
2589
2844
|
const typeDot = new QRDot2({
|
|
2590
2845
|
svg: this._element,
|
|
2591
2846
|
type: options.dotsOptions.type,
|
|
2592
2847
|
window: this._window
|
|
2593
2848
|
});
|
|
2594
2849
|
const squareDot = new QRDot2({ svg: this._element, type: "square", window: this._window });
|
|
2850
|
+
const recorder = ((_a = options.svgOptions) == null ? void 0 : _a.mergePaths) ? new PathRecorder() : void 0;
|
|
2851
|
+
const recorded = recorder ? recorder : void 0;
|
|
2852
|
+
const typeDotMerged = recorded ? new QRDot({ context: recorded, type: options.dotsOptions.type }) : void 0;
|
|
2853
|
+
const squareDotMerged = recorded ? new QRDot({ context: recorded, type: "square" }) : void 0;
|
|
2595
2854
|
const solidAlignment = needsSolidAlignment(options.dotsOptions.type);
|
|
2596
2855
|
const role = solidAlignment ? getModuleRoles(count) : void 0;
|
|
2597
2856
|
this._dotsClipPath = this._window.document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2598
2857
|
this._dotsClipPath.setAttribute("id", "clip-path-dot-color");
|
|
2599
2858
|
this._defs.appendChild(this._dotsClipPath);
|
|
2600
2859
|
this._createColor({
|
|
2601
|
-
options: (
|
|
2860
|
+
options: (_b = options.dotsOptions) == null ? void 0 : _b.gradient,
|
|
2602
2861
|
color: options.dotsOptions.color,
|
|
2603
2862
|
additionalRotation: 0,
|
|
2604
|
-
x: xBeginning,
|
|
2605
|
-
y: yBeginning,
|
|
2606
|
-
height: count * dotSize,
|
|
2607
|
-
width: count * dotSize,
|
|
2863
|
+
x: xBeginning - colorPad,
|
|
2864
|
+
y: yBeginning - colorPad,
|
|
2865
|
+
height: count * dotSize + 2 * colorPad,
|
|
2866
|
+
width: count * dotSize + 2 * colorPad,
|
|
2608
2867
|
name: "dot-color",
|
|
2609
2868
|
imageHref: this._dotsImageHref
|
|
2610
2869
|
});
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2870
|
+
const circle = isCircle(options) ? getCircleLayout(count) : void 0;
|
|
2871
|
+
const from = circle ? -circle.pad : 0;
|
|
2872
|
+
const to = circle ? count + circle.pad : count;
|
|
2873
|
+
const inCode = (i, j) => i >= 0 && j >= 0 && i < count && j < count;
|
|
2874
|
+
const isDark = (i, j) => {
|
|
2875
|
+
if (filter && !filter(i, j)) return false;
|
|
2876
|
+
if (inCode(i, j)) return !!this._qr && this._qr.isDark(i, j);
|
|
2877
|
+
return !!circle && circle.isDecoration(i, j);
|
|
2878
|
+
};
|
|
2879
|
+
for (let i = from; i < to; i++) {
|
|
2880
|
+
for (let j = from; j < to; j++) {
|
|
2881
|
+
if (inCode(i, j) ? filter && !filter(i, j) || !((_c = this._qr) == null ? void 0 : _c.isDark(i, j)) : !isDark(i, j)) {
|
|
2617
2882
|
continue;
|
|
2618
2883
|
}
|
|
2619
|
-
const
|
|
2884
|
+
const alignment = role && inCode(i, j) && role(i, j) === "alignment";
|
|
2885
|
+
const dot = recorded ? alignment ? squareDotMerged : typeDotMerged : alignment ? squareDot : typeDot;
|
|
2620
2886
|
dot.draw(
|
|
2621
2887
|
xBeginning + i * dotSize,
|
|
2622
2888
|
yBeginning + j * dotSize,
|
|
2623
2889
|
dotSize,
|
|
2624
2890
|
(xOffset, yOffset) => {
|
|
2625
|
-
if (
|
|
2626
|
-
|
|
2627
|
-
|
|
2891
|
+
if (!circle) {
|
|
2892
|
+
if (i + xOffset < 0 || j + yOffset < 0 || i + xOffset >= count || j + yOffset >= count) return false;
|
|
2893
|
+
if (filter && !filter(i + xOffset, j + yOffset)) return false;
|
|
2894
|
+
return !!this._qr && this._qr.isDark(i + xOffset, j + yOffset);
|
|
2895
|
+
}
|
|
2896
|
+
return isDark(i + xOffset, j + yOffset);
|
|
2628
2897
|
}
|
|
2629
2898
|
);
|
|
2630
|
-
if (dot._element && this._dotsClipPath) {
|
|
2899
|
+
if (!recorded && dot._element && this._dotsClipPath) {
|
|
2631
2900
|
this._dotsClipPath.appendChild(dot._element);
|
|
2632
2901
|
}
|
|
2633
2902
|
}
|
|
2634
2903
|
}
|
|
2904
|
+
if (recorder && recorder.d && this._dotsClipPath) {
|
|
2905
|
+
this._dotsClipPath.appendChild(this._svgElement("path", { d: recorder.d, "clip-rule": "evenodd" }));
|
|
2906
|
+
}
|
|
2635
2907
|
}
|
|
2636
2908
|
drawCorners() {
|
|
2637
2909
|
if (!this._qr) {
|
|
@@ -2652,7 +2924,7 @@ var QRSVG = class _QRSVG {
|
|
|
2652
2924
|
[1, 0, Math.PI / 2],
|
|
2653
2925
|
[0, 1, -Math.PI / 2]
|
|
2654
2926
|
].forEach(([column, row, rotation], index) => {
|
|
2655
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2927
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2656
2928
|
const x = xBeginning + column * dotSize * (count - 7);
|
|
2657
2929
|
const y = yBeginning + row * dotSize * (count - 7);
|
|
2658
2930
|
let cornersSquareClipPath = this._dotsClipPath;
|
|
@@ -2683,6 +2955,8 @@ var QRSVG = class _QRSVG {
|
|
|
2683
2955
|
if (cornersSquare._element && cornersSquareClipPath) {
|
|
2684
2956
|
cornersSquareClipPath.appendChild(cornersSquare._element);
|
|
2685
2957
|
}
|
|
2958
|
+
} else if ((_g = options.svgOptions) == null ? void 0 : _g.mergePaths) {
|
|
2959
|
+
this._drawMergedMask(squareMask2, x, y, dotSize, cornersSquareClipPath);
|
|
2686
2960
|
} else {
|
|
2687
2961
|
const dot = new QRDot2({
|
|
2688
2962
|
svg: this._element,
|
|
@@ -2691,7 +2965,7 @@ var QRSVG = class _QRSVG {
|
|
|
2691
2965
|
});
|
|
2692
2966
|
for (let i = 0; i < squareMask2.length; i++) {
|
|
2693
2967
|
for (let j = 0; j < squareMask2[i].length; j++) {
|
|
2694
|
-
if (!((
|
|
2968
|
+
if (!((_h = squareMask2[i]) == null ? void 0 : _h[j])) {
|
|
2695
2969
|
continue;
|
|
2696
2970
|
}
|
|
2697
2971
|
dot.draw(
|
|
@@ -2709,14 +2983,14 @@ var QRSVG = class _QRSVG {
|
|
|
2709
2983
|
}
|
|
2710
2984
|
}
|
|
2711
2985
|
}
|
|
2712
|
-
if (((
|
|
2986
|
+
if (((_i = options.cornersDotOptions) == null ? void 0 : _i.gradient) || ((_j = options.cornersDotOptions) == null ? void 0 : _j.color) || this._finderColors) {
|
|
2713
2987
|
cornersDotClipPath = this._window.document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2714
2988
|
cornersDotClipPath.setAttribute("id", `clip-path-corners-dot-color-${column}-${row}`);
|
|
2715
2989
|
this._defs.appendChild(cornersDotClipPath);
|
|
2716
2990
|
this._cornersDotClipPath = cornersDotClipPath;
|
|
2717
2991
|
this._createColor({
|
|
2718
|
-
options: (
|
|
2719
|
-
color: (
|
|
2992
|
+
options: (_k = options.cornersDotOptions) == null ? void 0 : _k.gradient,
|
|
2993
|
+
color: (_n = (_l = options.cornersDotOptions) == null ? void 0 : _l.color) != null ? _n : (_m = this._finderColors) == null ? void 0 : _m[index],
|
|
2720
2994
|
additionalRotation: rotation,
|
|
2721
2995
|
x: x + dotSize * 2,
|
|
2722
2996
|
y: y + dotSize * 2,
|
|
@@ -2735,6 +3009,8 @@ var QRSVG = class _QRSVG {
|
|
|
2735
3009
|
if (cornersDot._element && cornersDotClipPath) {
|
|
2736
3010
|
cornersDotClipPath.appendChild(cornersDot._element);
|
|
2737
3011
|
}
|
|
3012
|
+
} else if ((_o = options.svgOptions) == null ? void 0 : _o.mergePaths) {
|
|
3013
|
+
this._drawMergedMask(dotMask2, x, y, dotSize, cornersDotClipPath);
|
|
2738
3014
|
} else {
|
|
2739
3015
|
const dot = new QRDot2({
|
|
2740
3016
|
svg: this._element,
|
|
@@ -2743,7 +3019,7 @@ var QRSVG = class _QRSVG {
|
|
|
2743
3019
|
});
|
|
2744
3020
|
for (let i = 0; i < dotMask2.length; i++) {
|
|
2745
3021
|
for (let j = 0; j < dotMask2[i].length; j++) {
|
|
2746
|
-
if (!((
|
|
3022
|
+
if (!((_p = dotMask2[i]) == null ? void 0 : _p[j])) {
|
|
2747
3023
|
continue;
|
|
2748
3024
|
}
|
|
2749
3025
|
dot.draw(
|
|
@@ -2763,6 +3039,26 @@ var QRSVG = class _QRSVG {
|
|
|
2763
3039
|
}
|
|
2764
3040
|
});
|
|
2765
3041
|
}
|
|
3042
|
+
/** Finder modules drawn with the dots' own figure, as one path (svgOptions.mergePaths). */
|
|
3043
|
+
_drawMergedMask(mask, x, y, dotSize, clipPath) {
|
|
3044
|
+
var _a;
|
|
3045
|
+
const recorder = new PathRecorder();
|
|
3046
|
+
const dot = new QRDot({
|
|
3047
|
+
context: recorder,
|
|
3048
|
+
type: this._options.dotsOptions.type
|
|
3049
|
+
});
|
|
3050
|
+
for (let i = 0; i < mask.length; i++) {
|
|
3051
|
+
for (let j = 0; j < mask[i].length; j++) {
|
|
3052
|
+
if (!((_a = mask[i]) == null ? void 0 : _a[j])) continue;
|
|
3053
|
+
dot.draw(x + i * dotSize, y + j * dotSize, dotSize, (xOffset, yOffset) => {
|
|
3054
|
+
var _a2;
|
|
3055
|
+
return !!((_a2 = mask[i + xOffset]) == null ? void 0 : _a2[j + yOffset]);
|
|
3056
|
+
});
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
if (recorder.d && clipPath)
|
|
3060
|
+
clipPath.appendChild(this._svgElement("path", { d: recorder.d, "clip-rule": "evenodd" }));
|
|
3061
|
+
}
|
|
2766
3062
|
_drawArtRects(rects) {
|
|
2767
3063
|
rects.forEach(({ x, y, width, height, color, shape }) => {
|
|
2768
3064
|
this._element.appendChild(
|
|
@@ -2870,7 +3166,8 @@ var QRSVG = class _QRSVG {
|
|
|
2870
3166
|
height,
|
|
2871
3167
|
width,
|
|
2872
3168
|
name,
|
|
2873
|
-
imageHref
|
|
3169
|
+
imageHref,
|
|
3170
|
+
radius
|
|
2874
3171
|
}) {
|
|
2875
3172
|
const size = width > height ? width : height;
|
|
2876
3173
|
if (imageHref) {
|
|
@@ -2890,6 +3187,10 @@ var QRSVG = class _QRSVG {
|
|
|
2890
3187
|
rect2.setAttribute("height", String(height));
|
|
2891
3188
|
rect2.setAttribute("width", String(width));
|
|
2892
3189
|
rect2.setAttribute("clip-path", `url('#clip-path-${name}')`);
|
|
3190
|
+
if (radius) {
|
|
3191
|
+
rect2.setAttribute("rx", String(radius));
|
|
3192
|
+
rect2.setAttribute("ry", String(radius));
|
|
3193
|
+
}
|
|
2893
3194
|
if (options) {
|
|
2894
3195
|
let gradient;
|
|
2895
3196
|
if (options.type === gradientTypes_default.radial) {
|
|
@@ -3068,7 +3369,93 @@ function sanitizeOptions(options) {
|
|
|
3068
3369
|
|
|
3069
3370
|
// src/core/QRCodeStyling.ts
|
|
3070
3371
|
import qrcode from "qrcode-generator";
|
|
3071
|
-
|
|
3372
|
+
|
|
3373
|
+
// src/tools/utf8.ts
|
|
3374
|
+
function toUTF8Bytes(text) {
|
|
3375
|
+
const bytes = [];
|
|
3376
|
+
for (let i = 0; i < text.length; i++) {
|
|
3377
|
+
let code = text.charCodeAt(i);
|
|
3378
|
+
if (code >= 55296 && code < 56320 && i + 1 < text.length) {
|
|
3379
|
+
const next = text.charCodeAt(i + 1);
|
|
3380
|
+
if (next >= 56320 && next < 57344) {
|
|
3381
|
+
code = 65536 + (code - 55296 << 10) + (next - 56320);
|
|
3382
|
+
i++;
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
if (code < 128) bytes.push(code);
|
|
3386
|
+
else if (code < 2048) bytes.push(192 | code >> 6, 128 | code & 63);
|
|
3387
|
+
else if (code < 65536) bytes.push(224 | code >> 12, 128 | code >> 6 & 63, 128 | code & 63);
|
|
3388
|
+
else
|
|
3389
|
+
bytes.push(240 | code >> 18, 128 | code >> 12 & 63, 128 | code >> 6 & 63, 128 | code & 63);
|
|
3390
|
+
}
|
|
3391
|
+
return bytes;
|
|
3392
|
+
}
|
|
3393
|
+
var needsUTF8 = (text) => {
|
|
3394
|
+
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) > 255) return true;
|
|
3395
|
+
return false;
|
|
3396
|
+
};
|
|
3397
|
+
|
|
3398
|
+
// src/tools/payloads.ts
|
|
3399
|
+
var escapeWifi = (value) => value.replace(/([\\;,:"])/g, "\\$1");
|
|
3400
|
+
var escapeText = (value) => value.replace(/\\/g, "\\\\").replace(/;/g, "\\;").replace(/,/g, "\\,").replace(/\r?\n/g, "\\n");
|
|
3401
|
+
var list = (value) => value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
3402
|
+
function wifi({ ssid, password, encryption, hidden }) {
|
|
3403
|
+
const type = encryption || (password ? "WPA" : "nopass");
|
|
3404
|
+
let data = `WIFI:T:${type};S:${escapeWifi(ssid)};`;
|
|
3405
|
+
if (type !== "nopass" && password) data += `P:${escapeWifi(password)};`;
|
|
3406
|
+
if (hidden) data += "H:true;";
|
|
3407
|
+
return `${data};`;
|
|
3408
|
+
}
|
|
3409
|
+
function vCard(contact) {
|
|
3410
|
+
const first = contact.firstName || "";
|
|
3411
|
+
const last = contact.lastName || "";
|
|
3412
|
+
const fullName = contact.name || [first, last].filter(Boolean).join(" ");
|
|
3413
|
+
const lines = [
|
|
3414
|
+
"BEGIN:VCARD",
|
|
3415
|
+
"VERSION:3.0",
|
|
3416
|
+
`N:${escapeText(last)};${escapeText(first)};;;`,
|
|
3417
|
+
`FN:${escapeText(fullName)}`
|
|
3418
|
+
];
|
|
3419
|
+
if (contact.organization) lines.push(`ORG:${escapeText(contact.organization)}`);
|
|
3420
|
+
if (contact.title) lines.push(`TITLE:${escapeText(contact.title)}`);
|
|
3421
|
+
list(contact.phone).forEach((phone2) => lines.push(`TEL;TYPE=CELL:${escapeText(phone2)}`));
|
|
3422
|
+
list(contact.email).forEach((email2) => lines.push(`EMAIL:${escapeText(email2)}`));
|
|
3423
|
+
if (contact.url) lines.push(`URL:${escapeText(contact.url)}`);
|
|
3424
|
+
if (contact.address) {
|
|
3425
|
+
const { street = "", city = "", region = "", postalCode = "", country = "" } = contact.address;
|
|
3426
|
+
lines.push(`ADR;TYPE=WORK:;;${[street, city, region, postalCode, country].map(escapeText).join(";")}`);
|
|
3427
|
+
}
|
|
3428
|
+
if (contact.note) lines.push(`NOTE:${escapeText(contact.note)}`);
|
|
3429
|
+
lines.push("END:VCARD");
|
|
3430
|
+
return lines.join("\r\n");
|
|
3431
|
+
}
|
|
3432
|
+
var pad = (value) => value < 10 ? `0${value}` : String(value);
|
|
3433
|
+
var formatDate = (value, allDay) => {
|
|
3434
|
+
const date = typeof value === "string" ? new Date(value) : value;
|
|
3435
|
+
if (isNaN(date.getTime())) throw new Error(`Invalid date: ${value}`);
|
|
3436
|
+
if (allDay) return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`;
|
|
3437
|
+
return `${date.getUTCFullYear()}${pad(date.getUTCMonth() + 1)}${pad(date.getUTCDate())}T${pad(date.getUTCHours())}${pad(date.getUTCMinutes())}${pad(date.getUTCSeconds())}Z`;
|
|
3438
|
+
};
|
|
3439
|
+
function event({ title, start, end, allDay, location, description }) {
|
|
3440
|
+
const dateType = allDay ? ";VALUE=DATE" : "";
|
|
3441
|
+
const lines = ["BEGIN:VEVENT", `SUMMARY:${escapeText(title)}`, `DTSTART${dateType}:${formatDate(start, allDay)}`];
|
|
3442
|
+
if (end) lines.push(`DTEND${dateType}:${formatDate(end, allDay)}`);
|
|
3443
|
+
if (location) lines.push(`LOCATION:${escapeText(location)}`);
|
|
3444
|
+
if (description) lines.push(`DESCRIPTION:${escapeText(description)}`);
|
|
3445
|
+
lines.push("END:VEVENT");
|
|
3446
|
+
return lines.join("\r\n");
|
|
3447
|
+
}
|
|
3448
|
+
function email({ to, subject, body }) {
|
|
3449
|
+
const query = [subject && `subject=${encodeURIComponent(subject)}`, body && `body=${encodeURIComponent(body)}`].filter(Boolean).join("&");
|
|
3450
|
+
return `mailto:${to}${query ? `?${query}` : ""}`;
|
|
3451
|
+
}
|
|
3452
|
+
var phone = (number) => `tel:${number.replace(/[^\d+*#]/g, "")}`;
|
|
3453
|
+
var sms = ({ number, message }) => `SMSTO:${number.replace(/[^\d+]/g, "")}:${message || ""}`;
|
|
3454
|
+
var geo = ({ latitude, longitude }) => `geo:${latitude},${longitude}`;
|
|
3455
|
+
var payloads_default = { wifi, vCard, event, email, phone, sms, geo };
|
|
3456
|
+
|
|
3457
|
+
// src/core/QRCodeStyling.ts
|
|
3458
|
+
var _QRCodeStyling = class _QRCodeStyling {
|
|
3072
3459
|
constructor(options) {
|
|
3073
3460
|
this._options = options ? sanitizeOptions(mergeDeep(QROptions_default, options)) : QROptions_default;
|
|
3074
3461
|
this.update();
|
|
@@ -3121,7 +3508,19 @@ var QRCodeStyling = class _QRCodeStyling {
|
|
|
3121
3508
|
return;
|
|
3122
3509
|
}
|
|
3123
3510
|
this._qr = qrcode(this._options.qrOptions.typeNumber, this._options.qrOptions.errorCorrectionLevel);
|
|
3124
|
-
|
|
3511
|
+
const data = this._options.data;
|
|
3512
|
+
if (needsUTF8(data)) {
|
|
3513
|
+
const generator = qrcode;
|
|
3514
|
+
const latin1 = generator.stringToBytes;
|
|
3515
|
+
generator.stringToBytes = toUTF8Bytes;
|
|
3516
|
+
try {
|
|
3517
|
+
this._qr.addData(data, this._options.qrOptions.mode || getMode(data));
|
|
3518
|
+
} finally {
|
|
3519
|
+
generator.stringToBytes = latin1;
|
|
3520
|
+
}
|
|
3521
|
+
} else {
|
|
3522
|
+
this._qr.addData(data, this._options.qrOptions.mode || getMode(data));
|
|
3523
|
+
}
|
|
3125
3524
|
this._qr.make();
|
|
3126
3525
|
if (this._options.type === drawTypes_default.canvas && !this._canUseCanvas()) {
|
|
3127
3526
|
this._canvas = void 0;
|
|
@@ -3233,12 +3632,12 @@ ${serializer.serializeToString(svg.getElement())}`;
|
|
|
3233
3632
|
}
|
|
3234
3633
|
async _decode(decoder) {
|
|
3235
3634
|
const { data, width, height } = await this._getPixels();
|
|
3236
|
-
const
|
|
3237
|
-
const paddedWidth = width +
|
|
3238
|
-
const paddedHeight = height +
|
|
3635
|
+
const pad2 = Math.max(16, Math.round(Math.min(width, height) / 8));
|
|
3636
|
+
const paddedWidth = width + pad2 * 2;
|
|
3637
|
+
const paddedHeight = height + pad2 * 2;
|
|
3239
3638
|
const padded = new Uint8ClampedArray(paddedWidth * paddedHeight * 4).fill(255);
|
|
3240
3639
|
for (let y = 0; y < height; y++) {
|
|
3241
|
-
padded.set(data.subarray(y * width * 4, (y + 1) * width * 4), ((y +
|
|
3640
|
+
padded.set(data.subarray(y * width * 4, (y + 1) * width * 4), ((y + pad2) * paddedWidth + pad2) * 4);
|
|
3242
3641
|
}
|
|
3243
3642
|
const result = decoder(padded, paddedWidth, paddedHeight, { inversionAttempts: "attemptBoth" });
|
|
3244
3643
|
return result ? result.data : void 0;
|
|
@@ -3331,7 +3730,37 @@ ${source}`;
|
|
|
3331
3730
|
downloadURI(url, `${name}.${extension}`);
|
|
3332
3731
|
}
|
|
3333
3732
|
}
|
|
3733
|
+
/**
|
|
3734
|
+
* Opens the phone's share sheet with the QR code as a file (Web Share API). Where sharing files is not
|
|
3735
|
+
* supported (most desktop browsers), downloads it instead. Resolves to "shared", "downloaded", or
|
|
3736
|
+
* "cancelled" when the user closes the share sheet.
|
|
3737
|
+
*/
|
|
3738
|
+
async share(shareOptions = {}) {
|
|
3739
|
+
if (!this._qr) throw "QR code is empty";
|
|
3740
|
+
const extension = shareOptions.extension || "png";
|
|
3741
|
+
const name = shareOptions.name || "qr";
|
|
3742
|
+
const nav = typeof navigator !== "undefined" ? navigator : void 0;
|
|
3743
|
+
if ((nav == null ? void 0 : nav.share) && typeof File !== "undefined") {
|
|
3744
|
+
const blob2 = await this.getRawData(extension);
|
|
3745
|
+
const type = extension === "svg" ? "image/svg+xml" : `image/${extension}`;
|
|
3746
|
+
const file = new File([blob2], `${name}.${extension}`, { type });
|
|
3747
|
+
const data = { files: [file], title: shareOptions.title, text: shareOptions.text };
|
|
3748
|
+
if (!nav.canShare || nav.canShare(data)) {
|
|
3749
|
+
try {
|
|
3750
|
+
await nav.share(data);
|
|
3751
|
+
return "shared";
|
|
3752
|
+
} catch (error) {
|
|
3753
|
+
if ((error == null ? void 0 : error.name) === "AbortError") return "cancelled";
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
await this.download({ name, extension });
|
|
3758
|
+
return "downloaded";
|
|
3759
|
+
}
|
|
3334
3760
|
};
|
|
3761
|
+
/** Builders for Wi-Fi, contact, event, e-mail, phone, SMS and location codes: pass the result as `data`. */
|
|
3762
|
+
_QRCodeStyling.payload = payloads_default;
|
|
3763
|
+
var QRCodeStyling = _QRCodeStyling;
|
|
3335
3764
|
|
|
3336
3765
|
// src/types/index.ts
|
|
3337
3766
|
var JSDom = class {
|
|
@@ -3354,6 +3783,7 @@ export {
|
|
|
3354
3783
|
errorCorrectionLevels_default as errorCorrectionLevels,
|
|
3355
3784
|
errorCorrectionPercents_default as errorCorrectionPercents,
|
|
3356
3785
|
modes_default as modes,
|
|
3786
|
+
payloads_default as payload,
|
|
3357
3787
|
qrTypes_default as qrTypes
|
|
3358
3788
|
};
|
|
3359
3789
|
//# sourceMappingURL=qr-code-styling.mjs.map
|