qr-code-styling-node 1.8.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 +71 -7
- package/lib/art/art.d.ts +12 -8
- package/lib/art/functionModules.d.ts +1 -1
- package/lib/core/QRCanvas.d.ts +3 -0
- package/lib/core/QROptions.d.ts +2 -0
- package/lib/core/QRSVG.d.ts +5 -1
- package/lib/figures/dot/canvas/QRDot.d.ts +2 -0
- package/lib/figures/dot/svg/QRDot.d.ts +2 -0
- package/lib/figures/shapes.d.ts +50 -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 +742 -178
- package/lib/qr-code-styling.mjs.map +4 -4
- package/lib/tools/cornerTypes.d.ts +10 -0
- package/lib/tools/frameLayout.d.ts +43 -0
- package/lib/tools/qrArea.d.ts +14 -0
- package/lib/tools/svgDom.d.ts +3 -0
- package/lib/types/index.d.ts +44 -5
- package/package.json +4 -2
package/lib/qr-code-styling.mjs
CHANGED
|
@@ -109,7 +109,148 @@ var dotTypes_default = {
|
|
|
109
109
|
classy: "classy",
|
|
110
110
|
classyRounded: "classy-rounded",
|
|
111
111
|
square: "square",
|
|
112
|
-
extraRounded: "extra-rounded"
|
|
112
|
+
extraRounded: "extra-rounded",
|
|
113
|
+
diamond: "diamond",
|
|
114
|
+
smallSquare: "small-square",
|
|
115
|
+
verticalLines: "vertical-lines",
|
|
116
|
+
horizontalLines: "horizontal-lines",
|
|
117
|
+
fluid: "fluid"
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/figures/shapes.ts
|
|
121
|
+
function toCanvas(context, shape) {
|
|
122
|
+
shape.forEach((command) => {
|
|
123
|
+
if (command.op === "M") context.moveTo(command.x, command.y);
|
|
124
|
+
else if (command.op === "L") context.lineTo(command.x, command.y);
|
|
125
|
+
else if (command.op === "A")
|
|
126
|
+
context.arc(command.cx, command.cy, command.r, command.start, command.end, !!command.anticlockwise);
|
|
127
|
+
else context.closePath();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
var round = (value) => Math.round(value * 1e3) / 1e3;
|
|
131
|
+
function toSVGPath(shape) {
|
|
132
|
+
const parts = [];
|
|
133
|
+
shape.forEach((command) => {
|
|
134
|
+
if (command.op === "M" || command.op === "L") {
|
|
135
|
+
parts.push(`${command.op} ${round(command.x)} ${round(command.y)}`);
|
|
136
|
+
} else if (command.op === "A") {
|
|
137
|
+
const { cx, cy, r, start, end, anticlockwise } = command;
|
|
138
|
+
let sweep = anticlockwise ? start - end : end - start;
|
|
139
|
+
while (sweep < 0) sweep += 2 * Math.PI;
|
|
140
|
+
parts.push(`L ${round(cx + r * Math.cos(start))} ${round(cy + r * Math.sin(start))}`);
|
|
141
|
+
parts.push(
|
|
142
|
+
`A ${round(r)} ${round(r)} 0 ${sweep > Math.PI ? 1 : 0} ${anticlockwise ? 0 : 1} ${round(cx + r * Math.cos(end))} ${round(cy + r * Math.sin(end))}`
|
|
143
|
+
);
|
|
144
|
+
} else {
|
|
145
|
+
parts.push("Z");
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return parts.join(" ");
|
|
149
|
+
}
|
|
150
|
+
var diamond = (x, y, size) => [
|
|
151
|
+
{ op: "M", x: x + size / 2, y },
|
|
152
|
+
{ op: "L", x: x + size, y: y + size / 2 },
|
|
153
|
+
{ op: "L", x: x + size / 2, y: y + size },
|
|
154
|
+
{ op: "L", x, y: y + size / 2 },
|
|
155
|
+
{ op: "Z" }
|
|
156
|
+
];
|
|
157
|
+
var rect = (x, y, width, height) => [
|
|
158
|
+
{ op: "M", x, y },
|
|
159
|
+
{ op: "L", x: x + width, y },
|
|
160
|
+
{ op: "L", x: x + width, y: y + height },
|
|
161
|
+
{ op: "L", x, y: y + height },
|
|
162
|
+
{ op: "Z" }
|
|
163
|
+
];
|
|
164
|
+
var smallSquare = (x, y, size) => {
|
|
165
|
+
const inset = size * 0.15;
|
|
166
|
+
return rect(x + inset, y + inset, size - 2 * inset, size - 2 * inset);
|
|
167
|
+
};
|
|
168
|
+
var line = (x, y, size, vertical, before, after) => {
|
|
169
|
+
const thickness = size * 0.8;
|
|
170
|
+
const r = thickness / 2;
|
|
171
|
+
const offset = (size - thickness) / 2;
|
|
172
|
+
if (vertical) {
|
|
173
|
+
const left = x + offset;
|
|
174
|
+
const right = left + thickness;
|
|
175
|
+
const cx = x + size / 2;
|
|
176
|
+
const shape2 = [];
|
|
177
|
+
if (before) shape2.push({ op: "M", x: left, y }, { op: "L", x: right, y });
|
|
178
|
+
else shape2.push({ op: "M", x: left, y: y + r }, { op: "A", cx, cy: y + r, r, start: Math.PI, end: 0 });
|
|
179
|
+
if (after) shape2.push({ op: "L", x: right, y: y + size }, { op: "L", x: left, y: y + size });
|
|
180
|
+
else
|
|
181
|
+
shape2.push({ op: "L", x: right, y: y + size - r }, { op: "A", cx, cy: y + size - r, r, start: 0, end: Math.PI });
|
|
182
|
+
shape2.push({ op: "Z" });
|
|
183
|
+
return shape2;
|
|
184
|
+
}
|
|
185
|
+
const top = y + offset;
|
|
186
|
+
const bottom = top + thickness;
|
|
187
|
+
const cy = y + size / 2;
|
|
188
|
+
const shape = [];
|
|
189
|
+
if (before) shape.push({ op: "M", x, y: bottom }, { op: "L", x, y: top });
|
|
190
|
+
else
|
|
191
|
+
shape.push(
|
|
192
|
+
{ op: "M", x: x + r, y: bottom },
|
|
193
|
+
{ op: "A", cx: x + r, cy, r, start: Math.PI / 2, end: 3 * Math.PI / 2 }
|
|
194
|
+
);
|
|
195
|
+
if (after) shape.push({ op: "L", x: x + size, y: top }, { op: "L", x: x + size, y: bottom });
|
|
196
|
+
else
|
|
197
|
+
shape.push(
|
|
198
|
+
{ op: "L", x: x + size - r, y: top },
|
|
199
|
+
{ op: "A", cx: x + size - r, cy, r, start: -Math.PI / 2, end: Math.PI / 2 }
|
|
200
|
+
);
|
|
201
|
+
shape.push({ op: "Z" });
|
|
202
|
+
return shape;
|
|
203
|
+
};
|
|
204
|
+
var roundedRect = (x, y, width, height, radius) => {
|
|
205
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
206
|
+
return [
|
|
207
|
+
{ op: "M", x: x + r, y },
|
|
208
|
+
{ op: "L", x: x + width - r, y },
|
|
209
|
+
{ op: "A", cx: x + width - r, cy: y + r, r, start: -Math.PI / 2, end: 0 },
|
|
210
|
+
{ op: "L", x: x + width, y: y + height - r },
|
|
211
|
+
{ op: "A", cx: x + width - r, cy: y + height - r, r, start: 0, end: Math.PI / 2 },
|
|
212
|
+
{ op: "L", x: x + r, y: y + height },
|
|
213
|
+
{ op: "A", cx: x + r, cy: y + height - r, r, start: Math.PI / 2, end: Math.PI },
|
|
214
|
+
{ op: "L", x, y: y + r },
|
|
215
|
+
{ op: "A", cx: x + r, cy: y + r, r, start: Math.PI, end: 3 * Math.PI / 2 },
|
|
216
|
+
{ op: "Z" }
|
|
217
|
+
];
|
|
218
|
+
};
|
|
219
|
+
var roundedRing = (x, y, size) => {
|
|
220
|
+
const module = size / 7;
|
|
221
|
+
return roundedRect(x, y, size, size, module * 1.5).concat(
|
|
222
|
+
roundedRect(x + module, y + module, size - 2 * module, size - 2 * module, module * 0.75)
|
|
223
|
+
);
|
|
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;
|
|
113
254
|
};
|
|
114
255
|
|
|
115
256
|
// src/figures/dot/canvas/QRDot.ts
|
|
@@ -138,12 +279,44 @@ var QRDot = class {
|
|
|
138
279
|
case dotTypes_default.extraRounded:
|
|
139
280
|
drawFunction = this._drawExtraRounded;
|
|
140
281
|
break;
|
|
282
|
+
case dotTypes_default.diamond:
|
|
283
|
+
drawFunction = (args) => this._drawShape(diamond(args.x, args.y, args.size));
|
|
284
|
+
break;
|
|
285
|
+
case dotTypes_default.smallSquare:
|
|
286
|
+
drawFunction = (args) => this._drawShape(smallSquare(args.x, args.y, args.size));
|
|
287
|
+
break;
|
|
288
|
+
case dotTypes_default.verticalLines:
|
|
289
|
+
case dotTypes_default.horizontalLines: {
|
|
290
|
+
const vertical = type === dotTypes_default.verticalLines;
|
|
291
|
+
drawFunction = (args) => {
|
|
292
|
+
const before = args.getNeighbor ? args.getNeighbor(vertical ? 0 : -1, vertical ? -1 : 0) : false;
|
|
293
|
+
const after = args.getNeighbor ? args.getNeighbor(vertical ? 0 : 1, vertical ? 1 : 0) : false;
|
|
294
|
+
this._drawShape(line(args.x, args.y, args.size, vertical, before, after));
|
|
295
|
+
};
|
|
296
|
+
break;
|
|
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;
|
|
141
311
|
case dotTypes_default.square:
|
|
142
312
|
default:
|
|
143
313
|
drawFunction = this._drawSquare;
|
|
144
314
|
}
|
|
145
315
|
drawFunction.call(this, { x, y, size, context, getNeighbor });
|
|
146
316
|
}
|
|
317
|
+
_drawShape(shape) {
|
|
318
|
+
toCanvas(this._context, shape);
|
|
319
|
+
}
|
|
147
320
|
_rotateFigure({ x, y, size, context, rotation = 0, draw }) {
|
|
148
321
|
const cx = x + size / 2;
|
|
149
322
|
const cy = y + size / 2;
|
|
@@ -365,7 +538,8 @@ var QRDot = class {
|
|
|
365
538
|
var cornerSquareTypes_default = {
|
|
366
539
|
dot: "dot",
|
|
367
540
|
square: "square",
|
|
368
|
-
extraRounded: "extra-rounded"
|
|
541
|
+
extraRounded: "extra-rounded",
|
|
542
|
+
rounded: "rounded"
|
|
369
543
|
};
|
|
370
544
|
|
|
371
545
|
// src/figures/cornerSquare/canvas/QRCornerSquare.ts
|
|
@@ -385,6 +559,9 @@ var QRCornerSquare = class {
|
|
|
385
559
|
case cornerSquareTypes_default.extraRounded:
|
|
386
560
|
drawFunction = this._drawExtraRounded;
|
|
387
561
|
break;
|
|
562
|
+
case cornerSquareTypes_default.rounded:
|
|
563
|
+
drawFunction = (args) => toCanvas(context, roundedRing(args.x, args.y, args.size));
|
|
564
|
+
break;
|
|
388
565
|
case cornerSquareTypes_default.dot:
|
|
389
566
|
default:
|
|
390
567
|
drawFunction = this._drawDot;
|
|
@@ -462,7 +639,8 @@ var QRCornerSquare = class {
|
|
|
462
639
|
// src/constants/cornerDotTypes.ts
|
|
463
640
|
var cornerDotTypes_default = {
|
|
464
641
|
dot: "dot",
|
|
465
|
-
square: "square"
|
|
642
|
+
square: "square",
|
|
643
|
+
rounded: "rounded"
|
|
466
644
|
};
|
|
467
645
|
|
|
468
646
|
// src/figures/cornerDot/canvas/QRCornerDot.ts
|
|
@@ -479,6 +657,9 @@ var QRCornerDot = class {
|
|
|
479
657
|
case cornerDotTypes_default.square:
|
|
480
658
|
drawFunction = this._drawSquare;
|
|
481
659
|
break;
|
|
660
|
+
case cornerDotTypes_default.rounded:
|
|
661
|
+
drawFunction = (args) => toCanvas(context, roundedSquare(args.x, args.y, args.size));
|
|
662
|
+
break;
|
|
482
663
|
case cornerDotTypes_default.dot:
|
|
483
664
|
default:
|
|
484
665
|
drawFunction = this._drawDot;
|
|
@@ -521,6 +702,209 @@ var QRCornerDot = class {
|
|
|
521
702
|
}
|
|
522
703
|
};
|
|
523
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
|
+
|
|
728
|
+
// src/tools/cornerTypes.ts
|
|
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"];
|
|
731
|
+
var needsSolidAlignment = (type) => SOLID_CORNER_DOT_TYPES.indexOf(type) !== -1;
|
|
732
|
+
function getCornerTypes(options) {
|
|
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;
|
|
743
|
+
return {
|
|
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)
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// src/tools/frameLayout.ts
|
|
750
|
+
var hasFrame = (options) => {
|
|
751
|
+
var _a;
|
|
752
|
+
return !!(options.frameOptions || ((_a = options.labelOptions) == null ? void 0 : _a.text));
|
|
753
|
+
};
|
|
754
|
+
function getFrameLayout(options) {
|
|
755
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
756
|
+
const { width, height } = options;
|
|
757
|
+
const unit = Math.min(width, height);
|
|
758
|
+
const frame = options.frameOptions;
|
|
759
|
+
const label = ((_a = options.labelOptions) == null ? void 0 : _a.text) ? options.labelOptions : void 0;
|
|
760
|
+
const thickness = frame ? Math.max(0, (_b = frame.width) != null ? _b : Math.round(unit * 0.04)) : 0;
|
|
761
|
+
const padding = Math.max(0, (_c = frame == null ? void 0 : frame.padding) != null ? _c : frame ? Math.round(unit * 0.04) : options.margin);
|
|
762
|
+
const fontSize = label ? (_d = label.fontSize) != null ? _d : Math.max(8, Math.round(unit * 0.07)) : 0;
|
|
763
|
+
const bandHeight = label ? Math.round(fontSize * 1.8) : 0;
|
|
764
|
+
const position = (label == null ? void 0 : label.position) === "top" ? "top" : "bottom";
|
|
765
|
+
const innerX = thickness;
|
|
766
|
+
const innerY = thickness;
|
|
767
|
+
const innerWidth = width - 2 * thickness;
|
|
768
|
+
const innerHeight = height - 2 * thickness;
|
|
769
|
+
const qrRegionY = position === "top" ? innerY + bandHeight : innerY;
|
|
770
|
+
const qrRegionHeight = innerHeight - bandHeight;
|
|
771
|
+
const size = Math.floor(Math.min(innerWidth, qrRegionHeight) - 2 * padding);
|
|
772
|
+
if (size <= 0) throw new Error("frameOptions/labelOptions leave no room for the QR code; increase width/height");
|
|
773
|
+
const frameColor = (_e = frame == null ? void 0 : frame.color) != null ? _e : "#000";
|
|
774
|
+
const fontFamily = (_f = label == null ? void 0 : label.fontFamily) != null ? _f : "Helvetica, Arial, sans-serif";
|
|
775
|
+
const fontWeight = String((_g = label == null ? void 0 : label.fontWeight) != null ? _g : "bold");
|
|
776
|
+
return {
|
|
777
|
+
width,
|
|
778
|
+
height,
|
|
779
|
+
qr: {
|
|
780
|
+
x: Math.round(innerX + (innerWidth - size) / 2),
|
|
781
|
+
y: Math.round(qrRegionY + (qrRegionHeight - size) / 2),
|
|
782
|
+
size
|
|
783
|
+
},
|
|
784
|
+
frame: frame ? { thickness, radius: Math.max(0, (_h = frame.radius) != null ? _h : 0), color: frameColor } : void 0,
|
|
785
|
+
label: label ? {
|
|
786
|
+
text: label.text,
|
|
787
|
+
band: {
|
|
788
|
+
x: innerX,
|
|
789
|
+
y: position === "top" ? innerY : innerY + innerHeight - bandHeight,
|
|
790
|
+
width: innerWidth,
|
|
791
|
+
height: bandHeight
|
|
792
|
+
},
|
|
793
|
+
color: (_i = label.color) != null ? _i : frame ? "#fff" : options.dotsOptions.color || "#000",
|
|
794
|
+
font: `${fontWeight} ${fontSize}px ${fontFamily}`,
|
|
795
|
+
fontSize,
|
|
796
|
+
fontFamily,
|
|
797
|
+
fontWeight
|
|
798
|
+
} : void 0,
|
|
799
|
+
background: options.backgroundOptions.color || "#fff"
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
var innerOptions = (options, size) => ({
|
|
803
|
+
...options,
|
|
804
|
+
width: size,
|
|
805
|
+
height: size,
|
|
806
|
+
margin: 0,
|
|
807
|
+
frameOptions: void 0,
|
|
808
|
+
labelOptions: void 0
|
|
809
|
+
});
|
|
810
|
+
var getLogoPlate = (options, dx, dy, width, height) => {
|
|
811
|
+
var _a;
|
|
812
|
+
const ratio = Math.min(0.5, Math.max(0, (_a = options.imageOptions.backgroundRadius) != null ? _a : 0.2));
|
|
813
|
+
return {
|
|
814
|
+
x: dx - options.imageOptions.margin,
|
|
815
|
+
y: dy - options.imageOptions.margin,
|
|
816
|
+
width,
|
|
817
|
+
height,
|
|
818
|
+
radius: ratio * Math.min(width, height)
|
|
819
|
+
};
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
// src/art/functionModules.ts
|
|
823
|
+
var ALIGNMENT_POSITIONS = [
|
|
824
|
+
[],
|
|
825
|
+
[6, 18],
|
|
826
|
+
[6, 22],
|
|
827
|
+
[6, 26],
|
|
828
|
+
[6, 30],
|
|
829
|
+
[6, 34],
|
|
830
|
+
[6, 22, 38],
|
|
831
|
+
[6, 24, 42],
|
|
832
|
+
[6, 26, 46],
|
|
833
|
+
[6, 28, 50],
|
|
834
|
+
[6, 30, 54],
|
|
835
|
+
[6, 32, 58],
|
|
836
|
+
[6, 34, 62],
|
|
837
|
+
[6, 26, 46, 66],
|
|
838
|
+
[6, 26, 48, 70],
|
|
839
|
+
[6, 26, 50, 74],
|
|
840
|
+
[6, 30, 54, 78],
|
|
841
|
+
[6, 30, 56, 82],
|
|
842
|
+
[6, 30, 58, 86],
|
|
843
|
+
[6, 34, 62, 90],
|
|
844
|
+
[6, 28, 50, 72, 94],
|
|
845
|
+
[6, 26, 50, 74, 98],
|
|
846
|
+
[6, 30, 54, 78, 102],
|
|
847
|
+
[6, 28, 54, 80, 106],
|
|
848
|
+
[6, 32, 58, 84, 110],
|
|
849
|
+
[6, 30, 58, 86, 114],
|
|
850
|
+
[6, 34, 62, 90, 118],
|
|
851
|
+
[6, 26, 50, 74, 98, 122],
|
|
852
|
+
[6, 30, 54, 78, 102, 126],
|
|
853
|
+
[6, 26, 52, 78, 104, 130],
|
|
854
|
+
[6, 30, 56, 82, 108, 134],
|
|
855
|
+
[6, 34, 60, 86, 112, 138],
|
|
856
|
+
[6, 30, 58, 86, 114, 142],
|
|
857
|
+
[6, 34, 62, 90, 118, 146],
|
|
858
|
+
[6, 30, 54, 78, 102, 126, 150],
|
|
859
|
+
[6, 24, 50, 76, 102, 128, 154],
|
|
860
|
+
[6, 28, 54, 80, 106, 132, 158],
|
|
861
|
+
[6, 32, 58, 84, 110, 136, 162],
|
|
862
|
+
[6, 26, 54, 82, 110, 138, 166],
|
|
863
|
+
[6, 30, 58, 86, 114, 142, 170]
|
|
864
|
+
];
|
|
865
|
+
function getModuleRoles(count) {
|
|
866
|
+
const version = (count - 17) / 4;
|
|
867
|
+
const roles = new Uint8Array(count * count);
|
|
868
|
+
const mark = (row, col, role) => {
|
|
869
|
+
if (row >= 0 && col >= 0 && row < count && col < count) roles[row * count + col] = role;
|
|
870
|
+
};
|
|
871
|
+
for (let r = 0; r < 8; r++) {
|
|
872
|
+
for (let c = 0; c < 8; c++) {
|
|
873
|
+
mark(r, c, 2);
|
|
874
|
+
mark(r, count - 1 - c, 2);
|
|
875
|
+
mark(count - 1 - r, c, 2);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
for (let i = 8; i < count - 8; i++) {
|
|
879
|
+
mark(6, i, 1);
|
|
880
|
+
mark(i, 6, 1);
|
|
881
|
+
}
|
|
882
|
+
const positions = ALIGNMENT_POSITIONS[version - 1] || [];
|
|
883
|
+
positions.forEach(
|
|
884
|
+
(row) => positions.forEach((col) => {
|
|
885
|
+
if (roles[row * count + col] === 2) return;
|
|
886
|
+
for (let r = -2; r <= 2; r++) for (let c = -2; c <= 2; c++) mark(row + r, col + c, 3);
|
|
887
|
+
})
|
|
888
|
+
);
|
|
889
|
+
for (let i = 0; i < 9; i++) {
|
|
890
|
+
if (roles[8 * count + i] !== 2) mark(8, i, 1);
|
|
891
|
+
if (roles[i * count + 8] !== 2) mark(i, 8, 1);
|
|
892
|
+
}
|
|
893
|
+
for (let i = 0; i < 8; i++) {
|
|
894
|
+
mark(8, count - 1 - i, 1);
|
|
895
|
+
mark(count - 1 - i, 8, 1);
|
|
896
|
+
}
|
|
897
|
+
if (version >= 7) {
|
|
898
|
+
for (let a = 0; a < 6; a++) {
|
|
899
|
+
for (let b = 0; b < 3; b++) {
|
|
900
|
+
mark(a, count - 11 + b, 1);
|
|
901
|
+
mark(count - 11 + b, a, 1);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return (row, col) => ["data", "function", "finder", "alignment"][roles[row * count + col]];
|
|
906
|
+
}
|
|
907
|
+
|
|
524
908
|
// src/tools/svgDom.ts
|
|
525
909
|
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
526
910
|
var escapeAttribute = (value) => value.replace(/[&<>"\t\n\r]/g, (char) => {
|
|
@@ -547,8 +931,16 @@ var VirtualSVGElement = class _VirtualSVGElement {
|
|
|
547
931
|
this.parentNode = null;
|
|
548
932
|
this.childNodes = [];
|
|
549
933
|
this._attributes = /* @__PURE__ */ new Map();
|
|
934
|
+
this._text = "";
|
|
550
935
|
this.tagName = tagName;
|
|
551
936
|
}
|
|
937
|
+
get textContent() {
|
|
938
|
+
return this._text + this.childNodes.map((child) => child.textContent).join("");
|
|
939
|
+
}
|
|
940
|
+
set textContent(value) {
|
|
941
|
+
this.childNodes = [];
|
|
942
|
+
this._text = String(value);
|
|
943
|
+
}
|
|
552
944
|
get nodeName() {
|
|
553
945
|
return this.tagName;
|
|
554
946
|
}
|
|
@@ -587,6 +979,7 @@ var VirtualSVGElement = class _VirtualSVGElement {
|
|
|
587
979
|
cloneNode(deep = false) {
|
|
588
980
|
const clone = new _VirtualSVGElement(this.tagName);
|
|
589
981
|
this._attributes.forEach((value, name) => clone.setAttribute(name, value));
|
|
982
|
+
if (deep) clone._text = this._text;
|
|
590
983
|
if (deep) this.childNodes.forEach((child) => clone.appendChild(child.cloneNode(true)));
|
|
591
984
|
return clone;
|
|
592
985
|
}
|
|
@@ -596,8 +989,9 @@ var VirtualSVGElement = class _VirtualSVGElement {
|
|
|
596
989
|
this._attributes.forEach((value, name) => {
|
|
597
990
|
markup += ` ${name}="${escapeAttribute(value)}"`;
|
|
598
991
|
});
|
|
599
|
-
if (!this.childNodes.length) return `${markup}/>`;
|
|
992
|
+
if (!this.childNodes.length && !this._text) return `${markup}/>`;
|
|
600
993
|
markup += ">";
|
|
994
|
+
markup += this._text.replace(/[&<>]/g, (char) => char === "&" ? "&" : char === "<" ? "<" : ">");
|
|
601
995
|
for (const child of this.childNodes) markup += child.serialize(false);
|
|
602
996
|
return `${markup}</${this.tagName}>`;
|
|
603
997
|
}
|
|
@@ -619,97 +1013,11 @@ var createVirtualWindow = () => ({
|
|
|
619
1013
|
});
|
|
620
1014
|
var hasBrowserDom = () => typeof window !== "undefined" && typeof document !== "undefined" && typeof document.createElementNS === "function";
|
|
621
1015
|
|
|
622
|
-
// src/art/functionModules.ts
|
|
623
|
-
var ALIGNMENT_POSITIONS = [
|
|
624
|
-
[],
|
|
625
|
-
[6, 18],
|
|
626
|
-
[6, 22],
|
|
627
|
-
[6, 26],
|
|
628
|
-
[6, 30],
|
|
629
|
-
[6, 34],
|
|
630
|
-
[6, 22, 38],
|
|
631
|
-
[6, 24, 42],
|
|
632
|
-
[6, 26, 46],
|
|
633
|
-
[6, 28, 50],
|
|
634
|
-
[6, 30, 54],
|
|
635
|
-
[6, 32, 58],
|
|
636
|
-
[6, 34, 62],
|
|
637
|
-
[6, 26, 46, 66],
|
|
638
|
-
[6, 26, 48, 70],
|
|
639
|
-
[6, 26, 50, 74],
|
|
640
|
-
[6, 30, 54, 78],
|
|
641
|
-
[6, 30, 56, 82],
|
|
642
|
-
[6, 30, 58, 86],
|
|
643
|
-
[6, 34, 62, 90],
|
|
644
|
-
[6, 28, 50, 72, 94],
|
|
645
|
-
[6, 26, 50, 74, 98],
|
|
646
|
-
[6, 30, 54, 78, 102],
|
|
647
|
-
[6, 28, 54, 80, 106],
|
|
648
|
-
[6, 32, 58, 84, 110],
|
|
649
|
-
[6, 30, 58, 86, 114],
|
|
650
|
-
[6, 34, 62, 90, 118],
|
|
651
|
-
[6, 26, 50, 74, 98, 122],
|
|
652
|
-
[6, 30, 54, 78, 102, 126],
|
|
653
|
-
[6, 26, 52, 78, 104, 130],
|
|
654
|
-
[6, 30, 56, 82, 108, 134],
|
|
655
|
-
[6, 34, 60, 86, 112, 138],
|
|
656
|
-
[6, 30, 58, 86, 114, 142],
|
|
657
|
-
[6, 34, 62, 90, 118, 146],
|
|
658
|
-
[6, 30, 54, 78, 102, 126, 150],
|
|
659
|
-
[6, 24, 50, 76, 102, 128, 154],
|
|
660
|
-
[6, 28, 54, 80, 106, 132, 158],
|
|
661
|
-
[6, 32, 58, 84, 110, 136, 162],
|
|
662
|
-
[6, 26, 54, 82, 110, 138, 166],
|
|
663
|
-
[6, 30, 58, 86, 114, 142, 170]
|
|
664
|
-
];
|
|
665
|
-
function getModuleRoles(count) {
|
|
666
|
-
const version = (count - 17) / 4;
|
|
667
|
-
const roles = new Uint8Array(count * count);
|
|
668
|
-
const mark = (row, col, role) => {
|
|
669
|
-
if (row >= 0 && col >= 0 && row < count && col < count) roles[row * count + col] = role;
|
|
670
|
-
};
|
|
671
|
-
for (let r = 0; r < 8; r++) {
|
|
672
|
-
for (let c = 0; c < 8; c++) {
|
|
673
|
-
mark(r, c, 2);
|
|
674
|
-
mark(r, count - 1 - c, 2);
|
|
675
|
-
mark(count - 1 - r, c, 2);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
for (let i = 8; i < count - 8; i++) {
|
|
679
|
-
mark(6, i, 1);
|
|
680
|
-
mark(i, 6, 1);
|
|
681
|
-
}
|
|
682
|
-
const positions = ALIGNMENT_POSITIONS[version - 1] || [];
|
|
683
|
-
positions.forEach(
|
|
684
|
-
(row) => positions.forEach((col) => {
|
|
685
|
-
if (roles[row * count + col] === 2) return;
|
|
686
|
-
for (let r = -2; r <= 2; r++) for (let c = -2; c <= 2; c++) mark(row + r, col + c, 1);
|
|
687
|
-
})
|
|
688
|
-
);
|
|
689
|
-
for (let i = 0; i < 9; i++) {
|
|
690
|
-
if (roles[8 * count + i] !== 2) mark(8, i, 1);
|
|
691
|
-
if (roles[i * count + 8] !== 2) mark(i, 8, 1);
|
|
692
|
-
}
|
|
693
|
-
for (let i = 0; i < 8; i++) {
|
|
694
|
-
mark(8, count - 1 - i, 1);
|
|
695
|
-
mark(count - 1 - i, 8, 1);
|
|
696
|
-
}
|
|
697
|
-
if (version >= 7) {
|
|
698
|
-
for (let a = 0; a < 6; a++) {
|
|
699
|
-
for (let b = 0; b < 3; b++) {
|
|
700
|
-
mark(a, count - 11 + b, 1);
|
|
701
|
-
mark(count - 11 + b, a, 1);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
return (row, col) => ["data", "function", "finder"][roles[row * count + col]];
|
|
706
|
-
}
|
|
707
|
-
|
|
708
1016
|
// src/art/art.ts
|
|
709
|
-
var DEFAULT_CONTRAST = { halftone: 0.5, colorize: 0.7 };
|
|
1017
|
+
var DEFAULT_CONTRAST = { halftone: 0.5, colorize: 0.7, blend: 0.6 };
|
|
710
1018
|
var clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
711
1019
|
var getContrast = (art) => clamp01(
|
|
712
|
-
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"]
|
|
713
1021
|
);
|
|
714
1022
|
var getLimits = (contrast) => ({
|
|
715
1023
|
dark: 0.45 - 0.35 * contrast,
|
|
@@ -824,7 +1132,8 @@ function planHalftone(options, art, image, qr, area, filter) {
|
|
|
824
1132
|
const centerOffset = (dotSize - centerSize) / 2;
|
|
825
1133
|
for (let i = 0; i < count; i++) {
|
|
826
1134
|
for (let j = 0; j < count; j++) {
|
|
827
|
-
const
|
|
1135
|
+
const found = role(i, j);
|
|
1136
|
+
const moduleRole = found === "alignment" ? "function" : found;
|
|
828
1137
|
if (moduleRole === "finder" || !filter(i, j)) continue;
|
|
829
1138
|
const dark = qr.isDark(i, j);
|
|
830
1139
|
for (let a = 0; a < sub; a++) {
|
|
@@ -894,15 +1203,82 @@ function prepareColorize(options, art, image, area) {
|
|
|
894
1203
|
background: art.background === false ? void 0 : makeLayer((color) => toLight(color, limits.light))
|
|
895
1204
|
};
|
|
896
1205
|
}
|
|
897
|
-
function
|
|
898
|
-
const
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
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];
|
|
905
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 };
|
|
906
1282
|
}
|
|
907
1283
|
async function prepareArt(options, qr, filter) {
|
|
908
1284
|
const art = options.art;
|
|
@@ -910,7 +1286,9 @@ async function prepareArt(options, qr, filter) {
|
|
|
910
1286
|
createCanvas(options, 1, 1);
|
|
911
1287
|
const image = await loadPicture(options, art);
|
|
912
1288
|
const area = getQRArea(options, qr.getModuleCount());
|
|
913
|
-
|
|
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);
|
|
914
1292
|
}
|
|
915
1293
|
|
|
916
1294
|
// src/constants/gradientTypes.ts
|
|
@@ -938,7 +1316,7 @@ var dotMask = [
|
|
|
938
1316
|
[0, 0, 0, 0, 0, 0, 0],
|
|
939
1317
|
[0, 0, 0, 0, 0, 0, 0]
|
|
940
1318
|
];
|
|
941
|
-
var QRCanvas = class {
|
|
1319
|
+
var QRCanvas = class _QRCanvas {
|
|
942
1320
|
//TODO don't pass all options to this class
|
|
943
1321
|
constructor(options) {
|
|
944
1322
|
var _a;
|
|
@@ -969,11 +1347,59 @@ var QRCanvas = class {
|
|
|
969
1347
|
canvasContext.clearRect(0, 0, this._canvas.width, this._canvas.height);
|
|
970
1348
|
}
|
|
971
1349
|
}
|
|
1350
|
+
async _drawFramed(qr) {
|
|
1351
|
+
const layout = getFrameLayout(this._options);
|
|
1352
|
+
const inner = new _QRCanvas(innerOptions(this._options, layout.qr.size));
|
|
1353
|
+
await inner.drawQR(qr);
|
|
1354
|
+
const context = this.context;
|
|
1355
|
+
this.clear();
|
|
1356
|
+
if (layout.frame) {
|
|
1357
|
+
const { thickness, radius, color } = layout.frame;
|
|
1358
|
+
context.beginPath();
|
|
1359
|
+
toCanvas(context, roundedRect(0, 0, layout.width, layout.height, radius));
|
|
1360
|
+
context.fillStyle = color;
|
|
1361
|
+
context.fill();
|
|
1362
|
+
context.save();
|
|
1363
|
+
context.beginPath();
|
|
1364
|
+
toCanvas(
|
|
1365
|
+
context,
|
|
1366
|
+
roundedRect(
|
|
1367
|
+
thickness,
|
|
1368
|
+
thickness,
|
|
1369
|
+
layout.width - 2 * thickness,
|
|
1370
|
+
layout.height - 2 * thickness,
|
|
1371
|
+
Math.max(0, radius - thickness)
|
|
1372
|
+
)
|
|
1373
|
+
);
|
|
1374
|
+
context.clip();
|
|
1375
|
+
this.drawBackground();
|
|
1376
|
+
context.restore();
|
|
1377
|
+
if (layout.label) {
|
|
1378
|
+
const { x, y, width, height } = layout.label.band;
|
|
1379
|
+
context.fillStyle = color;
|
|
1380
|
+
context.fillRect(x, y, width, height);
|
|
1381
|
+
}
|
|
1382
|
+
} else {
|
|
1383
|
+
this.drawBackground();
|
|
1384
|
+
}
|
|
1385
|
+
context.drawImage(inner.getCanvas(), layout.qr.x, layout.qr.y);
|
|
1386
|
+
if (layout.label) {
|
|
1387
|
+
const { band, font, color, text } = layout.label;
|
|
1388
|
+
context.font = font;
|
|
1389
|
+
context.fillStyle = color;
|
|
1390
|
+
context.textAlign = "center";
|
|
1391
|
+
context.textBaseline = "middle";
|
|
1392
|
+
context.fillText(text, band.x + band.width / 2, band.y + band.height / 2);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
972
1395
|
async drawQR(qr) {
|
|
973
1396
|
var _a;
|
|
1397
|
+
if (hasFrame(this._options)) {
|
|
1398
|
+
this._qr = qr;
|
|
1399
|
+
return this._drawFramed(qr);
|
|
1400
|
+
}
|
|
974
1401
|
const count = qr.getModuleCount();
|
|
975
|
-
const
|
|
976
|
-
const dotSize = Math.floor(minSize / count);
|
|
1402
|
+
const { dotSize } = getQRArea(this._options, count);
|
|
977
1403
|
let drawImageSize = {
|
|
978
1404
|
hideXDots: 0,
|
|
979
1405
|
hideYDots: 0,
|
|
@@ -1016,7 +1442,12 @@ var QRCanvas = class {
|
|
|
1016
1442
|
}
|
|
1017
1443
|
this.clear();
|
|
1018
1444
|
this.drawBackground();
|
|
1019
|
-
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") {
|
|
1020
1451
|
this._drawArtRects(art.rects);
|
|
1021
1452
|
this.drawDots(() => false);
|
|
1022
1453
|
} else {
|
|
@@ -1029,6 +1460,7 @@ var QRCanvas = class {
|
|
|
1029
1460
|
this._dotsFill = void 0;
|
|
1030
1461
|
}
|
|
1031
1462
|
this.drawCorners();
|
|
1463
|
+
this._finderColors = void 0;
|
|
1032
1464
|
if (this._options.image) {
|
|
1033
1465
|
this.drawImage({ width: drawImageSize.width, height: drawImageSize.height, count, dotSize });
|
|
1034
1466
|
}
|
|
@@ -1070,11 +1502,11 @@ var QRCanvas = class {
|
|
|
1070
1502
|
if (count > options.width || count > options.height) {
|
|
1071
1503
|
throw "The canvas is too small.";
|
|
1072
1504
|
}
|
|
1073
|
-
const
|
|
1074
|
-
const
|
|
1075
|
-
const
|
|
1076
|
-
const
|
|
1077
|
-
const
|
|
1505
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
1506
|
+
const typeDot = new QRDot({ context: canvasContext, type: options.dotsOptions.type });
|
|
1507
|
+
const squareDot = new QRDot({ context: canvasContext, type: "square" });
|
|
1508
|
+
const solidAlignment = needsSolidAlignment(options.dotsOptions.type);
|
|
1509
|
+
const role = solidAlignment ? getModuleRoles(count) : void 0;
|
|
1078
1510
|
canvasContext.beginPath();
|
|
1079
1511
|
for (let i = 0; i < count; i++) {
|
|
1080
1512
|
for (let j = 0; j < count; j++) {
|
|
@@ -1084,6 +1516,7 @@ var QRCanvas = class {
|
|
|
1084
1516
|
if (!this._qr.isDark(i, j)) {
|
|
1085
1517
|
continue;
|
|
1086
1518
|
}
|
|
1519
|
+
const dot = role && role(i, j) === "alignment" ? squareDot : typeDot;
|
|
1087
1520
|
dot.draw(
|
|
1088
1521
|
xBeginning + i * dotSize,
|
|
1089
1522
|
yBeginning + j * dotSize,
|
|
@@ -1121,9 +1554,15 @@ var QRCanvas = class {
|
|
|
1121
1554
|
_drawArtRects(rects) {
|
|
1122
1555
|
const context = this.context;
|
|
1123
1556
|
if (!context) return;
|
|
1124
|
-
rects.forEach(({ x, y, width, height, color }) => {
|
|
1557
|
+
rects.forEach(({ x, y, width, height, color, shape }) => {
|
|
1125
1558
|
context.fillStyle = color;
|
|
1126
|
-
|
|
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
|
+
}
|
|
1127
1566
|
});
|
|
1128
1567
|
}
|
|
1129
1568
|
drawCorners(filter) {
|
|
@@ -1136,25 +1575,23 @@ var QRCanvas = class {
|
|
|
1136
1575
|
}
|
|
1137
1576
|
const options = this._options;
|
|
1138
1577
|
const count = this._qr.getModuleCount();
|
|
1139
|
-
const
|
|
1140
|
-
const dotSize = Math.floor(minSize / count);
|
|
1578
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
1141
1579
|
const cornersSquareSize = dotSize * 7;
|
|
1142
1580
|
const cornersDotSize = dotSize * 3;
|
|
1143
|
-
const
|
|
1144
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1581
|
+
const cornerTypes = getCornerTypes(options);
|
|
1145
1582
|
[
|
|
1146
1583
|
[0, 0, 0],
|
|
1147
1584
|
[1, 0, Math.PI / 2],
|
|
1148
1585
|
[0, 1, -Math.PI / 2]
|
|
1149
|
-
].forEach(([column, row, rotation]) => {
|
|
1150
|
-
var _a, _b, _c, _d, _e, _f
|
|
1586
|
+
].forEach(([column, row, rotation], index) => {
|
|
1587
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1151
1588
|
if (filter && !filter(column, row)) {
|
|
1152
1589
|
return;
|
|
1153
1590
|
}
|
|
1154
1591
|
const x = xBeginning + column * dotSize * (count - 7);
|
|
1155
1592
|
const y = yBeginning + row * dotSize * (count - 7);
|
|
1156
|
-
if (
|
|
1157
|
-
const cornersSquare = new QRCornerSquare({ context: canvasContext, type:
|
|
1593
|
+
if (cornerTypes.square) {
|
|
1594
|
+
const cornersSquare = new QRCornerSquare({ context: canvasContext, type: cornerTypes.square });
|
|
1158
1595
|
canvasContext.beginPath();
|
|
1159
1596
|
cornersSquare.draw(x, y, cornersSquareSize, rotation);
|
|
1160
1597
|
} else {
|
|
@@ -1162,7 +1599,7 @@ var QRCanvas = class {
|
|
|
1162
1599
|
canvasContext.beginPath();
|
|
1163
1600
|
for (let i = 0; i < squareMask.length; i++) {
|
|
1164
1601
|
for (let j = 0; j < squareMask[i].length; j++) {
|
|
1165
|
-
if (!((
|
|
1602
|
+
if (!((_a = squareMask[i]) == null ? void 0 : _a[j])) {
|
|
1166
1603
|
continue;
|
|
1167
1604
|
}
|
|
1168
1605
|
dot.draw(
|
|
@@ -1177,7 +1614,7 @@ var QRCanvas = class {
|
|
|
1177
1614
|
}
|
|
1178
1615
|
}
|
|
1179
1616
|
}
|
|
1180
|
-
if ((
|
|
1617
|
+
if ((_b = options.cornersSquareOptions) == null ? void 0 : _b.gradient) {
|
|
1181
1618
|
const gradientOptions = options.cornersSquareOptions.gradient;
|
|
1182
1619
|
const gradient = this._createGradient({
|
|
1183
1620
|
context: canvasContext,
|
|
@@ -1191,12 +1628,14 @@ var QRCanvas = class {
|
|
|
1191
1628
|
gradient.addColorStop(offset, color);
|
|
1192
1629
|
});
|
|
1193
1630
|
canvasContext.fillStyle = canvasContext.strokeStyle = gradient;
|
|
1194
|
-
} else if ((
|
|
1631
|
+
} else if ((_c = options.cornersSquareOptions) == null ? void 0 : _c.color) {
|
|
1195
1632
|
canvasContext.fillStyle = canvasContext.strokeStyle = options.cornersSquareOptions.color;
|
|
1633
|
+
} else if (this._finderColors) {
|
|
1634
|
+
canvasContext.fillStyle = canvasContext.strokeStyle = this._finderColors[index];
|
|
1196
1635
|
}
|
|
1197
1636
|
canvasContext.fill("evenodd");
|
|
1198
|
-
if (
|
|
1199
|
-
const cornersDot = new QRCornerDot({ context: canvasContext, type:
|
|
1637
|
+
if (cornerTypes.dot) {
|
|
1638
|
+
const cornersDot = new QRCornerDot({ context: canvasContext, type: cornerTypes.dot });
|
|
1200
1639
|
canvasContext.beginPath();
|
|
1201
1640
|
cornersDot.draw(x + dotSize * 2, y + dotSize * 2, cornersDotSize, rotation);
|
|
1202
1641
|
} else {
|
|
@@ -1204,7 +1643,7 @@ var QRCanvas = class {
|
|
|
1204
1643
|
canvasContext.beginPath();
|
|
1205
1644
|
for (let i = 0; i < dotMask.length; i++) {
|
|
1206
1645
|
for (let j = 0; j < dotMask[i].length; j++) {
|
|
1207
|
-
if (!((
|
|
1646
|
+
if (!((_d = dotMask[i]) == null ? void 0 : _d[j])) {
|
|
1208
1647
|
continue;
|
|
1209
1648
|
}
|
|
1210
1649
|
dot.draw(
|
|
@@ -1219,7 +1658,7 @@ var QRCanvas = class {
|
|
|
1219
1658
|
}
|
|
1220
1659
|
}
|
|
1221
1660
|
}
|
|
1222
|
-
if ((
|
|
1661
|
+
if ((_e = options.cornersDotOptions) == null ? void 0 : _e.gradient) {
|
|
1223
1662
|
const gradientOptions = options.cornersDotOptions.gradient;
|
|
1224
1663
|
const gradient = this._createGradient({
|
|
1225
1664
|
context: canvasContext,
|
|
@@ -1233,8 +1672,10 @@ var QRCanvas = class {
|
|
|
1233
1672
|
gradient.addColorStop(offset, color);
|
|
1234
1673
|
});
|
|
1235
1674
|
canvasContext.fillStyle = canvasContext.strokeStyle = gradient;
|
|
1236
|
-
} else if ((
|
|
1675
|
+
} else if ((_f = options.cornersDotOptions) == null ? void 0 : _f.color) {
|
|
1237
1676
|
canvasContext.fillStyle = canvasContext.strokeStyle = options.cornersDotOptions.color;
|
|
1677
|
+
} else if (this._finderColors) {
|
|
1678
|
+
canvasContext.fillStyle = canvasContext.strokeStyle = this._finderColors[index];
|
|
1238
1679
|
}
|
|
1239
1680
|
canvasContext.fill("evenodd");
|
|
1240
1681
|
});
|
|
@@ -1283,12 +1724,18 @@ var QRCanvas = class {
|
|
|
1283
1724
|
throw "image is not defined";
|
|
1284
1725
|
}
|
|
1285
1726
|
const options = this._options;
|
|
1286
|
-
const xBeginning =
|
|
1287
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1727
|
+
const { x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
1288
1728
|
const dx = xBeginning + options.imageOptions.margin + (count * dotSize - width) / 2;
|
|
1289
1729
|
const dy = yBeginning + options.imageOptions.margin + (count * dotSize - height) / 2;
|
|
1290
1730
|
const dw = width - options.imageOptions.margin * 2;
|
|
1291
1731
|
const dh = height - options.imageOptions.margin * 2;
|
|
1732
|
+
if (options.imageOptions.backgroundColor) {
|
|
1733
|
+
const plate = getLogoPlate(options, dx, dy, width, height);
|
|
1734
|
+
canvasContext.beginPath();
|
|
1735
|
+
toCanvas(canvasContext, roundedRect(plate.x, plate.y, plate.width, plate.height, plate.radius));
|
|
1736
|
+
canvasContext.fillStyle = options.imageOptions.backgroundColor;
|
|
1737
|
+
canvasContext.fill();
|
|
1738
|
+
}
|
|
1292
1739
|
canvasContext.drawImage(this._image, dx, dy, dw < 0 ? 0 : dw, dh < 0 ? 0 : dh);
|
|
1293
1740
|
}
|
|
1294
1741
|
_createGradient({
|
|
@@ -1362,12 +1809,45 @@ var QRDot2 = class {
|
|
|
1362
1809
|
case dotTypes_default.extraRounded:
|
|
1363
1810
|
drawFunction = this._drawExtraRounded;
|
|
1364
1811
|
break;
|
|
1812
|
+
case dotTypes_default.diamond:
|
|
1813
|
+
drawFunction = (args) => this._drawShape(diamond(args.x, args.y, args.size));
|
|
1814
|
+
break;
|
|
1815
|
+
case dotTypes_default.smallSquare:
|
|
1816
|
+
drawFunction = (args) => this._drawShape(smallSquare(args.x, args.y, args.size));
|
|
1817
|
+
break;
|
|
1818
|
+
case dotTypes_default.verticalLines:
|
|
1819
|
+
case dotTypes_default.horizontalLines: {
|
|
1820
|
+
const vertical = type === dotTypes_default.verticalLines;
|
|
1821
|
+
drawFunction = (args) => {
|
|
1822
|
+
const before = args.getNeighbor ? args.getNeighbor(vertical ? 0 : -1, vertical ? -1 : 0) : false;
|
|
1823
|
+
const after = args.getNeighbor ? args.getNeighbor(vertical ? 0 : 1, vertical ? 1 : 0) : false;
|
|
1824
|
+
this._drawShape(line(args.x, args.y, args.size, vertical, before, after));
|
|
1825
|
+
};
|
|
1826
|
+
break;
|
|
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;
|
|
1365
1841
|
case dotTypes_default.square:
|
|
1366
1842
|
default:
|
|
1367
1843
|
drawFunction = this._drawSquare;
|
|
1368
1844
|
}
|
|
1369
1845
|
drawFunction.call(this, { x, y, size, getNeighbor });
|
|
1370
1846
|
}
|
|
1847
|
+
_drawShape(shape) {
|
|
1848
|
+
this._element = this._window.document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1849
|
+
this._element.setAttribute("d", toSVGPath(shape));
|
|
1850
|
+
}
|
|
1371
1851
|
_rotateFigure({ x, y, size, rotation = 0, draw }) {
|
|
1372
1852
|
var _a;
|
|
1373
1853
|
const cx = x + size / 2;
|
|
@@ -1603,6 +2083,13 @@ var QRCornerSquare2 = class {
|
|
|
1603
2083
|
case cornerSquareTypes_default.extraRounded:
|
|
1604
2084
|
drawFunction = this._drawExtraRounded;
|
|
1605
2085
|
break;
|
|
2086
|
+
case cornerSquareTypes_default.rounded:
|
|
2087
|
+
drawFunction = (args) => {
|
|
2088
|
+
this._element = this._window.document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
2089
|
+
this._element.setAttribute("clip-rule", "evenodd");
|
|
2090
|
+
this._element.setAttribute("d", toSVGPath(roundedRing(args.x, args.y, args.size)));
|
|
2091
|
+
};
|
|
2092
|
+
break;
|
|
1606
2093
|
case cornerSquareTypes_default.dot:
|
|
1607
2094
|
default:
|
|
1608
2095
|
drawFunction = this._drawDot;
|
|
@@ -1687,6 +2174,12 @@ var QRCornerDot2 = class {
|
|
|
1687
2174
|
case cornerDotTypes_default.square:
|
|
1688
2175
|
drawFunction = this._drawSquare;
|
|
1689
2176
|
break;
|
|
2177
|
+
case cornerDotTypes_default.rounded:
|
|
2178
|
+
drawFunction = (args) => {
|
|
2179
|
+
this._element = this._window.document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
2180
|
+
this._element.setAttribute("d", toSVGPath(roundedSquare(args.x, args.y, args.size)));
|
|
2181
|
+
};
|
|
2182
|
+
break;
|
|
1690
2183
|
case cornerDotTypes_default.dot:
|
|
1691
2184
|
default:
|
|
1692
2185
|
drawFunction = this._drawDot;
|
|
@@ -1882,13 +2375,16 @@ var dotMask2 = [
|
|
|
1882
2375
|
[0, 0, 0, 0, 0, 0, 0],
|
|
1883
2376
|
[0, 0, 0, 0, 0, 0, 0]
|
|
1884
2377
|
];
|
|
1885
|
-
var QRSVG = class {
|
|
2378
|
+
var QRSVG = class _QRSVG {
|
|
1886
2379
|
//TODO don't pass all options to this class
|
|
1887
|
-
constructor(options) {
|
|
2380
|
+
constructor(options, sharedWindow) {
|
|
1888
2381
|
/** True when no browser DOM or jsdom is available and the built-in virtual DOM is used. */
|
|
1889
2382
|
this._virtual = false;
|
|
1890
2383
|
var _a;
|
|
1891
|
-
if (
|
|
2384
|
+
if (sharedWindow) {
|
|
2385
|
+
this._window = sharedWindow;
|
|
2386
|
+
this._virtual = !!sharedWindow.isVirtual;
|
|
2387
|
+
} else if (options.jsdom) {
|
|
1892
2388
|
this._window = new options.jsdom("", { resources: "usable" }).window;
|
|
1893
2389
|
} else if (hasBrowserDom()) {
|
|
1894
2390
|
this._window = window;
|
|
@@ -1930,10 +2426,69 @@ var QRSVG = class {
|
|
|
1930
2426
|
this._defs = this._window.document.createElementNS("http://www.w3.org/2000/svg", "defs");
|
|
1931
2427
|
this._element.appendChild(this._defs);
|
|
1932
2428
|
}
|
|
2429
|
+
_svgElement(name, attributes) {
|
|
2430
|
+
const element = this._window.document.createElementNS("http://www.w3.org/2000/svg", name);
|
|
2431
|
+
Object.keys(attributes).forEach((key) => element.setAttribute(key, String(attributes[key])));
|
|
2432
|
+
return element;
|
|
2433
|
+
}
|
|
2434
|
+
async _drawFramed(qr) {
|
|
2435
|
+
const layout = getFrameLayout(this._options);
|
|
2436
|
+
const inner = new _QRSVG(innerOptions(this._options, layout.qr.size), this._window);
|
|
2437
|
+
await inner.drawQR(qr);
|
|
2438
|
+
this.clear();
|
|
2439
|
+
if (layout.frame) {
|
|
2440
|
+
const { thickness, radius, color } = layout.frame;
|
|
2441
|
+
this._element.appendChild(
|
|
2442
|
+
this._svgElement("path", { d: toSVGPath(roundedRect(0, 0, layout.width, layout.height, radius)), fill: color })
|
|
2443
|
+
);
|
|
2444
|
+
this._element.appendChild(
|
|
2445
|
+
this._svgElement("path", {
|
|
2446
|
+
d: toSVGPath(
|
|
2447
|
+
roundedRect(
|
|
2448
|
+
thickness,
|
|
2449
|
+
thickness,
|
|
2450
|
+
layout.width - 2 * thickness,
|
|
2451
|
+
layout.height - 2 * thickness,
|
|
2452
|
+
Math.max(0, radius - thickness)
|
|
2453
|
+
)
|
|
2454
|
+
),
|
|
2455
|
+
fill: layout.background
|
|
2456
|
+
})
|
|
2457
|
+
);
|
|
2458
|
+
if (layout.label) {
|
|
2459
|
+
const { x, y, width, height } = layout.label.band;
|
|
2460
|
+
this._element.appendChild(this._svgElement("rect", { x, y, width, height, fill: color }));
|
|
2461
|
+
}
|
|
2462
|
+
} else {
|
|
2463
|
+
this.drawBackground();
|
|
2464
|
+
}
|
|
2465
|
+
const element = inner.getElement();
|
|
2466
|
+
element.setAttribute("x", String(layout.qr.x));
|
|
2467
|
+
element.setAttribute("y", String(layout.qr.y));
|
|
2468
|
+
this._element.appendChild(element);
|
|
2469
|
+
if (layout.label) {
|
|
2470
|
+
const { band, color, text, fontSize, fontFamily, fontWeight } = layout.label;
|
|
2471
|
+
const label = this._svgElement("text", {
|
|
2472
|
+
x: band.x + band.width / 2,
|
|
2473
|
+
y: band.y + band.height / 2,
|
|
2474
|
+
fill: color,
|
|
2475
|
+
"font-family": fontFamily,
|
|
2476
|
+
"font-size": fontSize,
|
|
2477
|
+
"font-weight": fontWeight,
|
|
2478
|
+
"text-anchor": "middle",
|
|
2479
|
+
"dominant-baseline": "central"
|
|
2480
|
+
});
|
|
2481
|
+
label.textContent = text;
|
|
2482
|
+
this._element.appendChild(label);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
1933
2485
|
async drawQR(qr) {
|
|
2486
|
+
if (hasFrame(this._options)) {
|
|
2487
|
+
this._qr = qr;
|
|
2488
|
+
return this._drawFramed(qr);
|
|
2489
|
+
}
|
|
1934
2490
|
const count = qr.getModuleCount();
|
|
1935
|
-
const
|
|
1936
|
-
const dotSize = Math.floor(minSize / count);
|
|
2491
|
+
const { dotSize } = getQRArea(this._options, count);
|
|
1937
2492
|
let drawImageSize = {
|
|
1938
2493
|
hideXDots: 0,
|
|
1939
2494
|
hideYDots: 0,
|
|
@@ -1977,7 +2532,12 @@ var QRSVG = class {
|
|
|
1977
2532
|
}
|
|
1978
2533
|
this.clear();
|
|
1979
2534
|
this.drawBackground();
|
|
1980
|
-
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") {
|
|
1981
2541
|
this._drawArtRects(art.rects);
|
|
1982
2542
|
this.drawDots(() => false);
|
|
1983
2543
|
} else {
|
|
@@ -1989,6 +2549,7 @@ var QRSVG = class {
|
|
|
1989
2549
|
this._dotsImageHref = void 0;
|
|
1990
2550
|
}
|
|
1991
2551
|
this.drawCorners();
|
|
2552
|
+
this._finderColors = void 0;
|
|
1992
2553
|
if (this._options.image) {
|
|
1993
2554
|
this.drawImage({ width: drawImageSize.width, height: drawImageSize.height, count, dotSize });
|
|
1994
2555
|
}
|
|
@@ -2024,15 +2585,15 @@ var QRSVG = class {
|
|
|
2024
2585
|
if (count > options.width || count > options.height) {
|
|
2025
2586
|
throw "The canvas is too small.";
|
|
2026
2587
|
}
|
|
2027
|
-
const
|
|
2028
|
-
const
|
|
2029
|
-
const xBeginning = Math.floor((options.width - count * dotSize) / 2);
|
|
2030
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
2031
|
-
const dot = new QRDot2({
|
|
2588
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
2589
|
+
const typeDot = new QRDot2({
|
|
2032
2590
|
svg: this._element,
|
|
2033
2591
|
type: options.dotsOptions.type,
|
|
2034
2592
|
window: this._window
|
|
2035
2593
|
});
|
|
2594
|
+
const squareDot = new QRDot2({ svg: this._element, type: "square", window: this._window });
|
|
2595
|
+
const solidAlignment = needsSolidAlignment(options.dotsOptions.type);
|
|
2596
|
+
const role = solidAlignment ? getModuleRoles(count) : void 0;
|
|
2036
2597
|
this._dotsClipPath = this._window.document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2037
2598
|
this._dotsClipPath.setAttribute("id", "clip-path-dot-color");
|
|
2038
2599
|
this._defs.appendChild(this._dotsClipPath);
|
|
@@ -2055,6 +2616,7 @@ var QRSVG = class {
|
|
|
2055
2616
|
if (!((_b = this._qr) == null ? void 0 : _b.isDark(i, j))) {
|
|
2056
2617
|
continue;
|
|
2057
2618
|
}
|
|
2619
|
+
const dot = role && role(i, j) === "alignment" ? squareDot : typeDot;
|
|
2058
2620
|
dot.draw(
|
|
2059
2621
|
xBeginning + i * dotSize,
|
|
2060
2622
|
yBeginning + j * dotSize,
|
|
@@ -2081,30 +2643,28 @@ var QRSVG = class {
|
|
|
2081
2643
|
throw "Element code is not defined";
|
|
2082
2644
|
}
|
|
2083
2645
|
const count = this._qr.getModuleCount();
|
|
2084
|
-
const
|
|
2085
|
-
const dotSize = Math.floor(minSize / count);
|
|
2646
|
+
const { dotSize, x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
2086
2647
|
const cornersSquareSize = dotSize * 7;
|
|
2087
2648
|
const cornersDotSize = dotSize * 3;
|
|
2088
|
-
const
|
|
2089
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
2649
|
+
const cornerTypes = getCornerTypes(options);
|
|
2090
2650
|
[
|
|
2091
2651
|
[0, 0, 0],
|
|
2092
2652
|
[1, 0, Math.PI / 2],
|
|
2093
2653
|
[0, 1, -Math.PI / 2]
|
|
2094
|
-
].forEach(([column, row, rotation]) => {
|
|
2095
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2654
|
+
].forEach(([column, row, rotation], index) => {
|
|
2655
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2096
2656
|
const x = xBeginning + column * dotSize * (count - 7);
|
|
2097
2657
|
const y = yBeginning + row * dotSize * (count - 7);
|
|
2098
2658
|
let cornersSquareClipPath = this._dotsClipPath;
|
|
2099
2659
|
let cornersDotClipPath = this._dotsClipPath;
|
|
2100
|
-
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) {
|
|
2101
2661
|
cornersSquareClipPath = this._window.document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2102
2662
|
cornersSquareClipPath.setAttribute("id", `clip-path-corners-square-color-${column}-${row}`);
|
|
2103
2663
|
this._defs.appendChild(cornersSquareClipPath);
|
|
2104
2664
|
this._cornersSquareClipPath = this._cornersDotClipPath = cornersDotClipPath = cornersSquareClipPath;
|
|
2105
2665
|
this._createColor({
|
|
2106
2666
|
options: (_c = options.cornersSquareOptions) == null ? void 0 : _c.gradient,
|
|
2107
|
-
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],
|
|
2108
2668
|
additionalRotation: rotation,
|
|
2109
2669
|
x,
|
|
2110
2670
|
y,
|
|
@@ -2113,10 +2673,10 @@ var QRSVG = class {
|
|
|
2113
2673
|
name: `corners-square-color-${column}-${row}`
|
|
2114
2674
|
});
|
|
2115
2675
|
}
|
|
2116
|
-
if (
|
|
2676
|
+
if (cornerTypes.square) {
|
|
2117
2677
|
const cornersSquare = new QRCornerSquare2({
|
|
2118
2678
|
svg: this._element,
|
|
2119
|
-
type:
|
|
2679
|
+
type: cornerTypes.square,
|
|
2120
2680
|
window: this._window
|
|
2121
2681
|
});
|
|
2122
2682
|
cornersSquare.draw(x, y, cornersSquareSize, rotation);
|
|
@@ -2131,7 +2691,7 @@ var QRSVG = class {
|
|
|
2131
2691
|
});
|
|
2132
2692
|
for (let i = 0; i < squareMask2.length; i++) {
|
|
2133
2693
|
for (let j = 0; j < squareMask2[i].length; j++) {
|
|
2134
|
-
if (!((
|
|
2694
|
+
if (!((_g = squareMask2[i]) == null ? void 0 : _g[j])) {
|
|
2135
2695
|
continue;
|
|
2136
2696
|
}
|
|
2137
2697
|
dot.draw(
|
|
@@ -2149,14 +2709,14 @@ var QRSVG = class {
|
|
|
2149
2709
|
}
|
|
2150
2710
|
}
|
|
2151
2711
|
}
|
|
2152
|
-
if (((
|
|
2712
|
+
if (((_h = options.cornersDotOptions) == null ? void 0 : _h.gradient) || ((_i = options.cornersDotOptions) == null ? void 0 : _i.color) || this._finderColors) {
|
|
2153
2713
|
cornersDotClipPath = this._window.document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2154
2714
|
cornersDotClipPath.setAttribute("id", `clip-path-corners-dot-color-${column}-${row}`);
|
|
2155
2715
|
this._defs.appendChild(cornersDotClipPath);
|
|
2156
2716
|
this._cornersDotClipPath = cornersDotClipPath;
|
|
2157
2717
|
this._createColor({
|
|
2158
|
-
options: (
|
|
2159
|
-
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],
|
|
2160
2720
|
additionalRotation: rotation,
|
|
2161
2721
|
x: x + dotSize * 2,
|
|
2162
2722
|
y: y + dotSize * 2,
|
|
@@ -2165,10 +2725,10 @@ var QRSVG = class {
|
|
|
2165
2725
|
name: `corners-dot-color-${column}-${row}`
|
|
2166
2726
|
});
|
|
2167
2727
|
}
|
|
2168
|
-
if (
|
|
2728
|
+
if (cornerTypes.dot) {
|
|
2169
2729
|
const cornersDot = new QRCornerDot2({
|
|
2170
2730
|
svg: this._element,
|
|
2171
|
-
type:
|
|
2731
|
+
type: cornerTypes.dot,
|
|
2172
2732
|
window: this._window
|
|
2173
2733
|
});
|
|
2174
2734
|
cornersDot.draw(x + dotSize * 2, y + dotSize * 2, cornersDotSize, rotation);
|
|
@@ -2183,7 +2743,7 @@ var QRSVG = class {
|
|
|
2183
2743
|
});
|
|
2184
2744
|
for (let i = 0; i < dotMask2.length; i++) {
|
|
2185
2745
|
for (let j = 0; j < dotMask2[i].length; j++) {
|
|
2186
|
-
if (!((
|
|
2746
|
+
if (!((_n = dotMask2[i]) == null ? void 0 : _n[j])) {
|
|
2187
2747
|
continue;
|
|
2188
2748
|
}
|
|
2189
2749
|
dot.draw(
|
|
@@ -2204,14 +2764,10 @@ var QRSVG = class {
|
|
|
2204
2764
|
});
|
|
2205
2765
|
}
|
|
2206
2766
|
_drawArtRects(rects) {
|
|
2207
|
-
rects.forEach(({ x, y, width, height, color }) => {
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
rect.setAttribute("width", String(width));
|
|
2212
|
-
rect.setAttribute("height", String(height));
|
|
2213
|
-
rect.setAttribute("fill", color);
|
|
2214
|
-
this._element.appendChild(rect);
|
|
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
|
+
);
|
|
2215
2771
|
});
|
|
2216
2772
|
}
|
|
2217
2773
|
_appendImage(href, x, y) {
|
|
@@ -2283,12 +2839,20 @@ var QRSVG = class {
|
|
|
2283
2839
|
dotSize
|
|
2284
2840
|
}) {
|
|
2285
2841
|
const options = this._options;
|
|
2286
|
-
const xBeginning =
|
|
2287
|
-
const yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
2842
|
+
const { x: xBeginning, y: yBeginning } = getQRArea(options, count);
|
|
2288
2843
|
const dx = xBeginning + options.imageOptions.margin + (count * dotSize - width) / 2;
|
|
2289
2844
|
const dy = yBeginning + options.imageOptions.margin + (count * dotSize - height) / 2;
|
|
2290
2845
|
const dw = width - options.imageOptions.margin * 2;
|
|
2291
2846
|
const dh = height - options.imageOptions.margin * 2;
|
|
2847
|
+
if (options.imageOptions.backgroundColor) {
|
|
2848
|
+
const plate = getLogoPlate(options, dx, dy, width, height);
|
|
2849
|
+
this._element.appendChild(
|
|
2850
|
+
this._svgElement("path", {
|
|
2851
|
+
d: toSVGPath(roundedRect(plate.x, plate.y, plate.width, plate.height, plate.radius)),
|
|
2852
|
+
fill: options.imageOptions.backgroundColor
|
|
2853
|
+
})
|
|
2854
|
+
);
|
|
2855
|
+
}
|
|
2292
2856
|
const image = this._window.document.createElementNS("http://www.w3.org/2000/svg", "image");
|
|
2293
2857
|
image.setAttribute("href", this._imageUri || "");
|
|
2294
2858
|
image.setAttribute("x", String(dx));
|
|
@@ -2320,12 +2884,12 @@ var QRSVG = class {
|
|
|
2320
2884
|
this._element.appendChild(image);
|
|
2321
2885
|
return;
|
|
2322
2886
|
}
|
|
2323
|
-
const
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2887
|
+
const rect2 = this._window.document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
2888
|
+
rect2.setAttribute("x", String(x));
|
|
2889
|
+
rect2.setAttribute("y", String(y));
|
|
2890
|
+
rect2.setAttribute("height", String(height));
|
|
2891
|
+
rect2.setAttribute("width", String(width));
|
|
2892
|
+
rect2.setAttribute("clip-path", `url('#clip-path-${name}')`);
|
|
2329
2893
|
if (options) {
|
|
2330
2894
|
let gradient;
|
|
2331
2895
|
if (options.type === gradientTypes_default.radial) {
|
|
@@ -2379,12 +2943,12 @@ var QRSVG = class {
|
|
|
2379
2943
|
stop.setAttribute("stop-color", color2);
|
|
2380
2944
|
gradient.appendChild(stop);
|
|
2381
2945
|
});
|
|
2382
|
-
|
|
2946
|
+
rect2.setAttribute("fill", `url('#${name}')`);
|
|
2383
2947
|
this._defs.appendChild(gradient);
|
|
2384
2948
|
} else if (color) {
|
|
2385
|
-
|
|
2949
|
+
rect2.setAttribute("fill", color);
|
|
2386
2950
|
}
|
|
2387
|
-
this._element.appendChild(
|
|
2951
|
+
this._element.appendChild(rect2);
|
|
2388
2952
|
}
|
|
2389
2953
|
};
|
|
2390
2954
|
|