@liquid-js/qr-code-styling 4.1.0 → 5.0.0-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/lib/figures/corner-dot.d.ts +1 -22
- package/lib/figures/corner-square.d.ts +1 -22
- package/lib/figures/dot-elements.d.ts +14 -0
- package/lib/figures/dot.d.ts +1 -29
- package/lib/figures/square-elements.d.ts +8 -0
- package/lib/qr-code-styling-node.js +358 -629
- package/lib/qr-code-styling-node.js.map +1 -1
- package/lib/qr-code-styling.js +1 -1
- package/lib/qr-code-styling.js.map +1 -1
- package/lib/types/helper.d.ts +6 -12
- package/lib/utils/options.d.ts +4 -4
- package/lib/utils/svg.d.ts +7 -0
- package/package.json +1 -1
|
@@ -47,10 +47,10 @@ DotType.horizontalLine = "horizontal-line", DotType.classy = "classy", DotType.c
|
|
|
47
47
|
DotType.square = "square", DotType.smallSquare = "small-square", DotType.tinySquare = "tiny-square",
|
|
48
48
|
DotType.diamond = "diamond", DotType.wave = "wave", (CornerDotType = CornerDotType ||= {}).dot = "dot",
|
|
49
49
|
CornerDotType.square = "square", CornerDotType.heart = "heart", CornerDotType.extraRounded = "extra-rounded",
|
|
50
|
-
CornerDotType.classy = "classy", CornerDotType.
|
|
50
|
+
CornerDotType.classy = "classy", CornerDotType.inpoint = "inpoint", CornerDotType.outpoint = "outpoint",
|
|
51
51
|
(CornerSquareType = CornerSquareType ||= {}).dot = "dot", CornerSquareType.square = "square",
|
|
52
52
|
CornerSquareType.extraRounded = "extra-rounded", CornerSquareType.classy = "classy",
|
|
53
|
-
CornerSquareType.
|
|
53
|
+
CornerSquareType.inpoint = "inpoint", CornerSquareType.outpoint = "outpoint", (ShapeType = ShapeType ||= {}).square = "square",
|
|
54
54
|
ShapeType.circle = "circle", (ImageMode = ImageMode ||= {}).center = "center", ImageMode.overlay = "overlay",
|
|
55
55
|
ImageMode.background = "background";
|
|
56
56
|
|
|
@@ -129,697 +129,415 @@ function svgPath(strings, ...values) {
|
|
|
129
129
|
}, "").trim().replace(/[\s\n\r]+/gim, " ");
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
get element() {
|
|
137
|
-
return this._element;
|
|
138
|
-
}
|
|
139
|
-
constructor(type, document) {
|
|
140
|
-
this.type = type, this.document = document;
|
|
141
|
-
}
|
|
142
|
-
draw(args) {
|
|
143
|
-
let drawFunction;
|
|
144
|
-
switch (this.type) {
|
|
145
|
-
case CornerDotType.square:
|
|
146
|
-
drawFunction = this.drawSquare;
|
|
147
|
-
break;
|
|
148
|
-
|
|
149
|
-
case CornerDotType.heart:
|
|
150
|
-
drawFunction = this.drawHeart;
|
|
151
|
-
break;
|
|
152
|
-
|
|
153
|
-
case CornerDotType.extraRounded:
|
|
154
|
-
drawFunction = this.drawRounded;
|
|
155
|
-
break;
|
|
156
|
-
|
|
157
|
-
case CornerDotType.classy:
|
|
158
|
-
drawFunction = this.drawClassy;
|
|
159
|
-
break;
|
|
160
|
-
|
|
161
|
-
case CornerDotType.inpoint:
|
|
162
|
-
drawFunction = this.drawInpoint;
|
|
163
|
-
break;
|
|
164
|
-
|
|
165
|
-
case CornerDotType.outpoint:
|
|
166
|
-
drawFunction = this.drawOutpoint;
|
|
167
|
-
break;
|
|
168
|
-
|
|
169
|
-
default:
|
|
170
|
-
drawFunction = this.drawDot;
|
|
171
|
-
}
|
|
172
|
-
drawFunction.call(this, args);
|
|
173
|
-
}
|
|
174
|
-
rotateFigure({x: cx, y: cy, size, rotation = 0, draw}) {
|
|
175
|
-
cx += size / 2, cy += size / 2, draw(), this._element?.setAttribute("transform", `rotate(${numToAttr(180 * rotation / Math.PI)},${cx},${cy})`);
|
|
176
|
-
}
|
|
177
|
-
basicDot(args) {
|
|
178
|
-
let {size, x, y} = args;
|
|
179
|
-
this.rotateFigure({
|
|
180
|
-
...args,
|
|
181
|
-
draw: () => {
|
|
182
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "circle"),
|
|
183
|
-
this._element.setAttribute("cx", numToAttr(x + size / 2)), this._element.setAttribute("cy", numToAttr(y + size / 2)),
|
|
184
|
-
this._element.setAttribute("r", numToAttr(size / 2));
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
basicSquare(args) {
|
|
189
|
-
let {size, x, y} = args;
|
|
190
|
-
this.rotateFigure({
|
|
191
|
-
...args,
|
|
192
|
-
draw: () => {
|
|
193
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "rect"),
|
|
194
|
-
this._element.setAttribute("x", numToAttr(x)), this._element.setAttribute("y", numToAttr(y)),
|
|
195
|
-
this._element.setAttribute("width", numToAttr(size)), this._element.setAttribute("height", numToAttr(size));
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
basicHeart(args) {
|
|
200
|
-
let {size, x, y} = args;
|
|
201
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
202
|
-
let move = !1, i = 0;
|
|
203
|
-
this._element.setAttribute("d", [ "M", 1, .3262506, "c", 0, .0383376, -.0064626, .0758377, -.0193751, .1125001, "s", -.0356247, .076875, -.0681248, .1206252, "c", -.0325, .0437499, -.0762503, .0931247, -.1312501, .1481249, "C", .7262502, .7625008, .6566626, .8279132, .5724999, .9037505, "L", .5, .9687506, "L", .4275001, .9037505, "C", .3433374, .8279132, .2737499, .7625005, .21875, .7075007, "C", .1637501, .6525008, .1199999, .6031258, .0874999, .5593758, "S", .0322876, .4754133, .0193751, .4387506, "S", 0, .3645881, 0, .3262506, "c", 0, -.0783374, .0262499, -.1437498, .07875, -.1962499, "s", .1179124, -.07875, .1962499, -.07875, "c", .0433376, 0, .0845875, .0091625, .12375, .0274999, "S", .4716623, .1229131, .5, .1562506, "c", .0283374, -.0333375, .0620874, -.0591625, .1012502, -.0775, "c", .0391627, -.0183375, .0804126, -.0274999, .12375, -.0274999, "c", .0783374, 0, .1437497, .0262499, .1962501, .07875, "S", 1, .2479131, 1, .3262506, "z" ].map(v => "string" == typeof v ? (i = 0,
|
|
204
|
-
move = v.toUpperCase() == v, v) : (i++, v *= size, move && (v += i % 2 == 1 ? x : y),
|
|
205
|
-
numToAttr(v))).join(" "));
|
|
206
|
-
}
|
|
207
|
-
basicRounded(args) {
|
|
208
|
-
let {size, x, y} = args;
|
|
209
|
-
this.rotateFigure({
|
|
210
|
-
...args,
|
|
211
|
-
draw: () => {
|
|
212
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "rect"),
|
|
213
|
-
this._element.setAttribute("x", numToAttr(x)), this._element.setAttribute("y", numToAttr(y)),
|
|
214
|
-
this._element.setAttribute("width", numToAttr(size)), this._element.setAttribute("height", numToAttr(size)),
|
|
215
|
-
this._element.setAttribute("rx", numToAttr(size / 4)), this._element.setAttribute("ry", numToAttr(size / 4));
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
basicClassy(args) {
|
|
220
|
-
let {size, x, y} = args, dotSize = size / 7;
|
|
221
|
-
this.rotateFigure({
|
|
222
|
-
...args,
|
|
223
|
-
draw: () => {
|
|
224
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
225
|
-
this._element.setAttribute("clip-rule", "evenodd"), this._element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * dotSize} v ${2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * dotSize} ${2.5 * dotSize} h ${4.5 * dotSize} v ${-4.5 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * -dotSize} ${2.5 * -dotSize} h ${-2 * dotSize} H ${x} z`);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
basicInpoint(args) {
|
|
230
|
-
let {size, x, y} = args;
|
|
231
|
-
this.rotateFigure({
|
|
232
|
-
...args,
|
|
233
|
-
draw: () => {
|
|
234
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
235
|
-
this._element.setAttribute("clip-rule", "evenodd"), this._element.setAttribute("d", svgPath`M ${x} ${y + size / 2} v ${size / 4} a ${size / 4}, ${size / 4} 0 0 0 ${size / 4}, ${size / 4} h ${size / 4 * 3} v ${-size / 4 * 3} a ${size / 4}, ${size / 4} 0 0 0 ${-size / 4}, ${-size / 4} h ${-size / 2} a ${size / 4}, ${size / 4} 0 0 0 ${-size / 4}, ${size / 4} z`);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
drawDot({x, y, size, rotation}) {
|
|
240
|
-
this.basicDot({
|
|
241
|
-
x,
|
|
242
|
-
y,
|
|
243
|
-
size,
|
|
244
|
-
rotation
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
drawSquare({x, y, size, rotation}) {
|
|
248
|
-
this.basicSquare({
|
|
249
|
-
x,
|
|
250
|
-
y,
|
|
251
|
-
size,
|
|
252
|
-
rotation
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
drawHeart({x, y, size, rotation}) {
|
|
256
|
-
this.basicHeart({
|
|
257
|
-
x,
|
|
258
|
-
y,
|
|
259
|
-
size,
|
|
260
|
-
rotation
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
drawRounded({x, y, size, rotation}) {
|
|
264
|
-
this.basicRounded({
|
|
265
|
-
x,
|
|
266
|
-
y,
|
|
267
|
-
size,
|
|
268
|
-
rotation
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
drawClassy({x, y, size, rotation}) {
|
|
272
|
-
this.basicClassy({
|
|
273
|
-
x,
|
|
274
|
-
y,
|
|
275
|
-
size,
|
|
276
|
-
rotation
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
drawInpoint({x, y, size, rotation}) {
|
|
280
|
-
this.basicInpoint({
|
|
281
|
-
x,
|
|
282
|
-
y,
|
|
283
|
-
size,
|
|
284
|
-
rotation
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
drawOutpoint({x, y, size, rotation}) {
|
|
288
|
-
this.basicInpoint({
|
|
289
|
-
x,
|
|
290
|
-
y,
|
|
291
|
-
size,
|
|
292
|
-
rotation: (rotation || 0) + Math.PI
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
class QRCornerSquare {
|
|
298
|
-
type;
|
|
299
|
-
document;
|
|
300
|
-
_element;
|
|
301
|
-
_fill;
|
|
302
|
-
get element() {
|
|
303
|
-
return this._element;
|
|
304
|
-
}
|
|
305
|
-
get fill() {
|
|
306
|
-
return this._fill;
|
|
307
|
-
}
|
|
308
|
-
constructor(type, document) {
|
|
309
|
-
this.type = type, this.document = document;
|
|
310
|
-
}
|
|
311
|
-
draw(args) {
|
|
312
|
-
let drawFunction;
|
|
313
|
-
switch (this.type) {
|
|
314
|
-
case CornerSquareType.square:
|
|
315
|
-
drawFunction = this.drawSquare;
|
|
316
|
-
break;
|
|
317
|
-
|
|
318
|
-
case CornerSquareType.extraRounded:
|
|
319
|
-
drawFunction = this.drawExtraRounded;
|
|
320
|
-
break;
|
|
321
|
-
|
|
322
|
-
case CornerSquareType.classy:
|
|
323
|
-
drawFunction = this.drawClassy;
|
|
324
|
-
break;
|
|
325
|
-
|
|
326
|
-
case CornerSquareType.outpoint:
|
|
327
|
-
drawFunction = this.drawOutpoint;
|
|
328
|
-
break;
|
|
329
|
-
|
|
330
|
-
case CornerSquareType.inpoint:
|
|
331
|
-
drawFunction = this.drawInpoint;
|
|
332
|
-
break;
|
|
333
|
-
|
|
334
|
-
default:
|
|
335
|
-
drawFunction = this.drawDot;
|
|
336
|
-
}
|
|
337
|
-
drawFunction.call(this, args);
|
|
338
|
-
}
|
|
339
|
-
rotateFigure({x: cx, y: cy, size, rotation = 0, draw}) {
|
|
340
|
-
cx += size / 2, cy += size / 2, draw(), this._element?.setAttribute("transform", `rotate(${numToAttr(180 * rotation / Math.PI)},${cx},${cy})`),
|
|
341
|
-
this._fill?.setAttribute("transform", `rotate(${numToAttr(180 * rotation / Math.PI)},${cx},${cy})`);
|
|
342
|
-
}
|
|
343
|
-
basicDot(args) {
|
|
344
|
-
let {size, x, y} = args, dotSize = size / 7;
|
|
345
|
-
this.rotateFigure({
|
|
346
|
-
...args,
|
|
347
|
-
draw: () => {
|
|
348
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
349
|
-
this._element.setAttribute("clip-rule", "evenodd"), this._element.setAttribute("d", svgPath`M ${x + size / 2} ${y} a ${size / 2} ${size / 2} 0 1 0 0.1 0 z m 0 ${dotSize} a ${size / 2 - dotSize} ${size / 2 - dotSize} 0 1 1 -0.1 0 Z`),
|
|
350
|
-
this._fill = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
351
|
-
this._fill.setAttribute("clip-rule", "evenodd"), this._fill.setAttribute("d", svgPath`M ${x + size / 2} ${y - dotSize} a ${size / 2 + dotSize} ${size / 2 + dotSize} 0 1 0 0.1 0 z`);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
basicSquare(args) {
|
|
356
|
-
let {size, x, y} = args, dotSize = size / 7;
|
|
357
|
-
this.rotateFigure({
|
|
358
|
-
...args,
|
|
359
|
-
draw: () => {
|
|
360
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
361
|
-
this._element.setAttribute("clip-rule", "evenodd"), this._element.setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size} v ${-size} z M ${x + dotSize} ${y + dotSize} h ${size - 2 * dotSize} v ${size - 2 * dotSize} h ${2 * dotSize - size} z`),
|
|
362
|
-
this._fill = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
363
|
-
this._fill.setAttribute("clip-rule", "evenodd"), this._fill.setAttribute("d", svgPath`M ${x - dotSize} ${y - dotSize} h ${size + 2 * dotSize} v ${size + 2 * dotSize} h ${-size - 2 * dotSize} z`);
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
basicExtraRounded(args) {
|
|
368
|
-
let {size, x, y} = args, dotSize = size / 7;
|
|
369
|
-
this.rotateFigure({
|
|
370
|
-
...args,
|
|
371
|
-
draw: () => {
|
|
372
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
373
|
-
this._element.setAttribute("clip-rule", "evenodd"), this._element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * dotSize} v ${2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * dotSize} ${2.5 * dotSize} h ${2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * dotSize} ${2.5 * -dotSize} v ${-2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * -dotSize} ${2.5 * -dotSize} h ${-2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * -dotSize} ${2.5 * dotSize} z M ${x + 2.5 * dotSize} ${y + dotSize} h ${2 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * dotSize} ${1.5 * dotSize} v ${2 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * -dotSize} ${1.5 * dotSize} h ${-2 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * -dotSize} ${1.5 * -dotSize} v ${-2 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * dotSize} ${1.5 * -dotSize} z`),
|
|
374
|
-
this._fill = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
375
|
-
this._fill.setAttribute("clip-rule", "evenodd"), this._fill.setAttribute("d", svgPath`M ${x - dotSize} ${y + 2.5 * dotSize} v ${2 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 0, ${3.5 * dotSize} ${3.5 * dotSize} h ${2 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 0, ${3.5 * dotSize} ${3.5 * -dotSize} v ${-2 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 0, ${3.5 * -dotSize} ${3.5 * -dotSize} h ${-2 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 0, ${3.5 * -dotSize} ${3.5 * dotSize} z`);
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
basicClassy(args) {
|
|
380
|
-
let {size, x, y} = args, dotSize = size / 7;
|
|
381
|
-
this.rotateFigure({
|
|
382
|
-
...args,
|
|
383
|
-
draw: () => {
|
|
384
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
385
|
-
this._element.setAttribute("clip-rule", "evenodd"), this._element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * dotSize} v ${2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * dotSize} ${2.5 * dotSize} h ${4.5 * dotSize} v ${-4.5 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * -dotSize} ${2.5 * -dotSize} h ${-2 * dotSize} H ${x} z M ${x + 2.5 * dotSize} ${y + dotSize} h ${2 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * dotSize} ${1.5 * dotSize} v ${3.5 * dotSize} h ${-3.5 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * -dotSize} ${1.5 * -dotSize} v ${-3.5 * dotSize} z`),
|
|
386
|
-
this._fill = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
387
|
-
this._fill.setAttribute("clip-rule", "evenodd"), this._fill.setAttribute("d", svgPath`M ${x + .5 * dotSize} ${y - dotSize} h ${4 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 1, ${3.5 * dotSize} ${3.5 * dotSize} v ${5.5 * dotSize} h ${-5.5 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 1, ${3.5 * -dotSize} ${3.5 * -dotSize} v ${-5.5 * dotSize} z`);
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
basicInpoint(args) {
|
|
392
|
-
let {size, x, y} = args, dotSize = size / 7;
|
|
393
|
-
this.rotateFigure({
|
|
394
|
-
...args,
|
|
395
|
-
draw: () => {
|
|
396
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
397
|
-
this._element.setAttribute("clip-rule", "evenodd"), this._element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * dotSize} v ${2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * dotSize} ${2.5 * dotSize} h ${4.5 * dotSize} v ${-4.5 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * -dotSize} ${2.5 * -dotSize} h ${-2 * dotSize} a ${2.5 * dotSize} ${2.5 * dotSize}, 0, 0, 0, ${2.5 * -dotSize} ${2.5 * dotSize} z M ${x + 2.5 * dotSize} ${y + dotSize} h ${2 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * dotSize} ${1.5 * dotSize} v ${3.5 * dotSize} h ${-3.5 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * -dotSize} ${1.5 * -dotSize} v ${-2 * dotSize} a ${1.5 * dotSize} ${1.5 * dotSize}, 0, 0, 1, ${1.5 * dotSize} ${1.5 * -dotSize} z`),
|
|
398
|
-
this._fill = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
399
|
-
this._fill.setAttribute("clip-rule", "evenodd"), this._fill.setAttribute("d", svgPath`M ${x + .5 * dotSize} ${y - dotSize} h ${4 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 1, ${3.5 * dotSize} ${3.5 * dotSize} v ${5.5 * dotSize} h ${-5.5 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 1, ${3.5 * -dotSize} ${3.5 * -dotSize} v ${-2 * dotSize} a ${3.5 * dotSize} ${3.5 * dotSize}, 0, 0, 1, ${3.5 * dotSize} ${3.5 * -dotSize} z`);
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
drawDot({x, y, size, rotation}) {
|
|
404
|
-
this.basicDot({
|
|
405
|
-
x,
|
|
406
|
-
y,
|
|
407
|
-
size,
|
|
408
|
-
rotation
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
drawSquare({x, y, size, rotation}) {
|
|
412
|
-
this.basicSquare({
|
|
413
|
-
x,
|
|
414
|
-
y,
|
|
415
|
-
size,
|
|
416
|
-
rotation
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
drawExtraRounded({x, y, size, rotation}) {
|
|
420
|
-
this.basicExtraRounded({
|
|
421
|
-
x,
|
|
422
|
-
y,
|
|
423
|
-
size,
|
|
424
|
-
rotation
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
drawClassy({x, y, size, rotation}) {
|
|
428
|
-
this.basicClassy({
|
|
429
|
-
x,
|
|
430
|
-
y,
|
|
431
|
-
size,
|
|
432
|
-
rotation
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
drawInpoint({x, y, size, rotation}) {
|
|
436
|
-
this.basicInpoint({
|
|
437
|
-
x,
|
|
438
|
-
y,
|
|
439
|
-
size,
|
|
440
|
-
rotation
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
drawOutpoint({x, y, size, rotation}) {
|
|
444
|
-
this.basicInpoint({
|
|
445
|
-
x,
|
|
446
|
-
y,
|
|
447
|
-
size,
|
|
448
|
-
rotation: (rotation || 0) + Math.PI
|
|
449
|
-
});
|
|
450
|
-
}
|
|
132
|
+
function rotateFigure({draw: draw_element, ...args}) {
|
|
133
|
+
let {x, y, size, rotation = 0} = args, cx = x + size / 2, cy = y + size / 2;
|
|
134
|
+
return draw_element = draw_element(args), rotation && (Array.isArray(draw_element) ? draw_element : [ draw_element ]).forEach(el => el.setAttribute("transform", `rotate(${numToAttr(180 * rotation / Math.PI)},${cx},${cy})`)),
|
|
135
|
+
draw_element;
|
|
451
136
|
}
|
|
452
137
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
drawFunction = this.drawSmallSquare;
|
|
504
|
-
break;
|
|
505
|
-
|
|
506
|
-
case DotType.tinySquare:
|
|
507
|
-
drawFunction = this.drawTinySquare;
|
|
508
|
-
break;
|
|
509
|
-
|
|
510
|
-
case DotType.wave:
|
|
511
|
-
drawFunction = this.drawWave;
|
|
512
|
-
break;
|
|
513
|
-
|
|
514
|
-
default:
|
|
515
|
-
drawFunction = this.drawSquare;
|
|
516
|
-
}
|
|
517
|
-
drawFunction.call(this, args);
|
|
518
|
-
}
|
|
519
|
-
rotateFigure({x: cx, y: cy, size, rotation = 0, draw}) {
|
|
520
|
-
cx += size / 2, cy += size / 2, draw(), this._element?.setAttribute("transform", `rotate(${numToAttr(180 * rotation / Math.PI)},${cx},${cy})`);
|
|
521
|
-
}
|
|
522
|
-
basicDot(args) {
|
|
523
|
-
let {size, x, y} = args;
|
|
524
|
-
this.rotateFigure({
|
|
525
|
-
...args,
|
|
526
|
-
draw: () => {
|
|
527
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "circle"),
|
|
528
|
-
this._element.setAttribute("cx", numToAttr(x + size / 2)), this._element.setAttribute("cy", numToAttr(y + size / 2)),
|
|
529
|
-
this._element.setAttribute("r", numToAttr(size / 2));
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
basicSquare(args) {
|
|
534
|
-
let {size, x, y} = args;
|
|
535
|
-
this.rotateFigure({
|
|
536
|
-
...args,
|
|
537
|
-
draw: () => {
|
|
538
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "rect"),
|
|
539
|
-
this._element.setAttribute("x", numToAttr(x)), this._element.setAttribute("y", numToAttr(y)),
|
|
540
|
-
this._element.setAttribute("width", numToAttr(size)), this._element.setAttribute("height", numToAttr(size));
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
basicSideRounded(args) {
|
|
545
|
-
let {size, x, y} = args;
|
|
546
|
-
this.rotateFigure({
|
|
547
|
-
...args,
|
|
548
|
-
draw: () => {
|
|
549
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
550
|
-
this._element.setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, 0 ${-size} z`);
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
basicCornerRounded(args) {
|
|
555
|
-
let {size, x, y} = args;
|
|
556
|
-
this.rotateFigure({
|
|
557
|
-
...args,
|
|
558
|
-
draw: () => {
|
|
559
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
560
|
-
this._element.setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size} v ${-size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, ${-size / 2} ${-size / 2} z`);
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
basicCornerExtraRounded(args) {
|
|
565
|
-
let {size, x, y} = args;
|
|
566
|
-
this.rotateFigure({
|
|
567
|
-
...args,
|
|
568
|
-
draw: () => {
|
|
569
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
570
|
-
this._element.setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size} a ${size} ${size}, 0, 0, 0, ${-size} ${-size} z`);
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
basicCornersRounded(args) {
|
|
575
|
-
let {size, x, y} = args;
|
|
576
|
-
this.rotateFigure({
|
|
577
|
-
...args,
|
|
578
|
-
draw: () => {
|
|
579
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
580
|
-
this._element.setAttribute("d", svgPath`M ${x} ${y} v ${size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, ${size / 2} ${size / 2} h ${size / 2} v ${-size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, ${-size / 2} ${-size / 2} z`);
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
basicWave(args) {
|
|
585
|
-
let {size, x, y} = args, a1 = 5 * Math.PI / 180, a2 = 65 * Math.PI / 180, c23x = size * (.95 - .65 * Math.cos(a1)), c23y = size * (1 - .65 * Math.sin(a1)), c31x = -size * Math.cos(a2) / 2, c31y = -size * Math.sin(a2) / 2;
|
|
586
|
-
this.rotateFigure({
|
|
587
|
-
...args,
|
|
588
|
-
draw: () => {
|
|
589
|
-
this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
|
590
|
-
this._element.setAttribute("d", svgPath`M ${x} ${y} c 0 ${.65 * size} ${c23x} ${c23y} ${.95 * size} ${size} c ${c31x} ${c31y} ${size * (1 - .95)} ${-size / 2} ${size * (1 - .95)} ${-size} z`);
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
drawDot({x, y, size}) {
|
|
595
|
-
this.basicDot({
|
|
596
|
-
x,
|
|
597
|
-
y,
|
|
598
|
-
size,
|
|
599
|
-
rotation: 0
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
drawRandomDot({x, y, size}) {
|
|
603
|
-
this.basicDot({
|
|
604
|
-
x,
|
|
605
|
-
y,
|
|
606
|
-
size: size * (.25 * Math.random() + .75),
|
|
607
|
-
rotation: 0
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
drawSquare({x, y, size}) {
|
|
611
|
-
this.basicSquare({
|
|
612
|
-
x,
|
|
613
|
-
y,
|
|
614
|
-
size,
|
|
615
|
-
rotation: 0
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
drawSmallSquare({x, y, size}) {
|
|
619
|
-
let originalSize = size;
|
|
620
|
-
size = .7 * originalSize, x += .15 * originalSize, y += .15 * originalSize, this.basicSquare({
|
|
621
|
-
x,
|
|
622
|
-
y,
|
|
623
|
-
size,
|
|
624
|
-
rotation: 0
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
drawTinySquare({x, y, size}) {
|
|
628
|
-
let originalSize = size;
|
|
629
|
-
size = .3 * originalSize, x += .35 * originalSize, y += .35 * originalSize, this.basicSquare({
|
|
630
|
-
x,
|
|
631
|
-
y,
|
|
632
|
-
size,
|
|
633
|
-
rotation: 0
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
drawDiamond({x, y, size}) {
|
|
637
|
-
this.basicSquare({
|
|
138
|
+
let DotElements = {
|
|
139
|
+
dot: args => {
|
|
140
|
+
const {size, x, y, document} = args;
|
|
141
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "circle")).setAttribute("cx", numToAttr(x + size / 2)),
|
|
142
|
+
args.setAttribute("cy", numToAttr(y + size / 2)), args.setAttribute("r", numToAttr(size / 2)),
|
|
143
|
+
args;
|
|
144
|
+
},
|
|
145
|
+
square: args => {
|
|
146
|
+
const {size, x, y, document} = args;
|
|
147
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "rect")).setAttribute("x", numToAttr(x)),
|
|
148
|
+
args.setAttribute("y", numToAttr(y)), args.setAttribute("width", numToAttr(size)),
|
|
149
|
+
args.setAttribute("height", numToAttr(size)), args;
|
|
150
|
+
},
|
|
151
|
+
sideRounded: args => {
|
|
152
|
+
const {size, x, y, document} = args;
|
|
153
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, 0 ${-size} z`),
|
|
154
|
+
args;
|
|
155
|
+
},
|
|
156
|
+
cornerRounded: args => {
|
|
157
|
+
const {size, x, y, document} = args;
|
|
158
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size} v ${-size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, ${-size / 2} ${-size / 2} z`),
|
|
159
|
+
args;
|
|
160
|
+
},
|
|
161
|
+
cornerExtraRounded: args => {
|
|
162
|
+
const {size, x, y, document} = args;
|
|
163
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size} a ${size} ${size}, 0, 0, 0, ${-size} ${-size} z`),
|
|
164
|
+
args;
|
|
165
|
+
},
|
|
166
|
+
cornersRounded: args => {
|
|
167
|
+
const {size, x, y, document} = args;
|
|
168
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", svgPath`M ${x} ${y} v ${size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, ${size / 2} ${size / 2} h ${size / 2} v ${-size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, ${-size / 2} ${-size / 2} z`),
|
|
169
|
+
args;
|
|
170
|
+
},
|
|
171
|
+
wave: args => {
|
|
172
|
+
const {size, x, y, document} = args;
|
|
173
|
+
var a1_c23y = 5 * Math.PI / 180, a2_c31y = 65 * Math.PI / 180;
|
|
174
|
+
args = size * (.95 - .65 * Math.cos(a1_c23y)), a1_c23y = size * (1 - .65 * Math.sin(a1_c23y));
|
|
175
|
+
const c31x = -size * Math.cos(a2_c31y) / 2;
|
|
176
|
+
a2_c31y = -size * Math.sin(a2_c31y) / 2;
|
|
177
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
178
|
+
return element.setAttribute("d", svgPath`M ${x} ${y} c 0 ${.65 * size} ${args} ${a1_c23y} ${.95 * size} ${size} c ${c31x} ${a2_c31y} ${size * (1 - .95)} ${-size / 2} ${size * (1 - .95)} ${-size} z`),
|
|
179
|
+
element;
|
|
180
|
+
},
|
|
181
|
+
heart: args => {
|
|
182
|
+
const {size, x, y, document} = args;
|
|
183
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", function(path, {x, y, size}) {
|
|
184
|
+
let move = !1, i = 0;
|
|
185
|
+
return path.map(v => "string" == typeof v ? (i = 0, move = v.toUpperCase() == v,
|
|
186
|
+
v) : (i++, v *= size, move && (v += i % 2 == 1 ? x : y), numToAttr(v))).join(" ");
|
|
187
|
+
}([ "M", 1, .31629, "c", -86e-5, .15702, -.10534, .26323, -.21876, .38123, "c", -.06736, .06834, -.18938, .17948, -.28124, .26126, "c", -.09188, -.08178, -.2139, -.19292, -.28124, -.26126, "c", -.11344, -.118, -.2179, -.22422, -.21876, -.38123, "c", -96e-5, -.27136, .33154, -.36842, .5, -.17, "c", .16844, -.19842, .50094, -.10136, .5, .17, "z" ], {
|
|
638
188
|
x,
|
|
639
189
|
y,
|
|
640
|
-
size
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
190
|
+
size
|
|
191
|
+
})), args;
|
|
192
|
+
},
|
|
193
|
+
rounded: args => {
|
|
194
|
+
const {size, x, y, document} = args;
|
|
195
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "rect")).setAttribute("x", numToAttr(x)),
|
|
196
|
+
args.setAttribute("y", numToAttr(y)), args.setAttribute("width", numToAttr(size)),
|
|
197
|
+
args.setAttribute("height", numToAttr(size)), args.setAttribute("rx", numToAttr(size / 4)),
|
|
198
|
+
args.setAttribute("ry", numToAttr(size / 4)), args;
|
|
199
|
+
},
|
|
200
|
+
classy: args => {
|
|
201
|
+
const {size, x, y, document} = args;
|
|
202
|
+
args = size / 7;
|
|
203
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
204
|
+
return element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * args} v ${2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * args} ${2.5 * args} h ${4.5 * args} v ${-4.5 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * -args} ${2.5 * -args} h ${-2 * args} H ${x} z`),
|
|
205
|
+
element;
|
|
206
|
+
},
|
|
207
|
+
inpoint: args => {
|
|
208
|
+
const {size, x, y, document} = args;
|
|
209
|
+
return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", svgPath`M ${x} ${y + size / 2} v ${size / 4} a ${size / 4}, ${size / 4} 0 0 0 ${size / 4}, ${size / 4} h ${size / 4 * 3} v ${-size / 4 * 3} a ${size / 4}, ${size / 4} 0 0 0 ${-size / 4}, ${-size / 4} h ${-size / 2} a ${size / 4}, ${size / 4} 0 0 0 ${-size / 4}, ${size / 4} z`),
|
|
210
|
+
args;
|
|
211
|
+
}
|
|
212
|
+
}, qrCornerDotFigures = {
|
|
213
|
+
[CornerDotType.dot]: args => rotateFigure({
|
|
214
|
+
...args,
|
|
215
|
+
draw: DotElements.dot
|
|
216
|
+
}),
|
|
217
|
+
[CornerDotType.square]: args => rotateFigure({
|
|
218
|
+
...args,
|
|
219
|
+
draw: DotElements.square
|
|
220
|
+
}),
|
|
221
|
+
[CornerDotType.heart]: args => DotElements.heart(args),
|
|
222
|
+
[CornerDotType.extraRounded]: args => rotateFigure({
|
|
223
|
+
...args,
|
|
224
|
+
draw: DotElements.rounded
|
|
225
|
+
}),
|
|
226
|
+
[CornerDotType.classy]: args => rotateFigure({
|
|
227
|
+
...args,
|
|
228
|
+
draw: DotElements.classy
|
|
229
|
+
}),
|
|
230
|
+
[CornerDotType.inpoint]: args => rotateFigure({
|
|
231
|
+
...args,
|
|
232
|
+
draw: DotElements.inpoint
|
|
233
|
+
}),
|
|
234
|
+
[CornerDotType.outpoint]: args => rotateFigure({
|
|
235
|
+
...args,
|
|
236
|
+
rotation: (args.rotation || 0) + Math.PI,
|
|
237
|
+
draw: DotElements.inpoint
|
|
238
|
+
})
|
|
239
|
+
}, SquareElements = {
|
|
240
|
+
dot: args => {
|
|
241
|
+
const {size, x, y, document} = args;
|
|
242
|
+
args = size / 7;
|
|
243
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
244
|
+
element.setAttribute("clip-rule", "evenodd"), element.setAttribute("d", svgPath`M ${x + size / 2} ${y} a ${size / 2} ${size / 2} 0 1 0 0.1 0 z m 0 ${args} a ${size / 2 - args} ${size / 2 - args} 0 1 1 -0.1 0 Z`);
|
|
245
|
+
const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
246
|
+
return fill.setAttribute("clip-rule", "evenodd"), fill.setAttribute("d", svgPath`M ${x + size / 2} ${y - args} a ${size / 2 + args} ${size / 2 + args} 0 1 0 0.1 0 z`),
|
|
247
|
+
[ element, fill ];
|
|
248
|
+
},
|
|
249
|
+
square: args => {
|
|
250
|
+
const {size, x, y, document} = args;
|
|
251
|
+
args = size / 7;
|
|
252
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
253
|
+
element.setAttribute("clip-rule", "evenodd"), element.setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size} v ${-size} z M ${x + args} ${y + args} h ${size - 2 * args} v ${size - 2 * args} h ${2 * args - size} z`);
|
|
254
|
+
const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
255
|
+
return fill.setAttribute("clip-rule", "evenodd"), fill.setAttribute("d", svgPath`M ${x - args} ${y - args} h ${size + 2 * args} v ${size + 2 * args} h ${-size - 2 * args} z`),
|
|
256
|
+
[ element, fill ];
|
|
257
|
+
},
|
|
258
|
+
extraRounded: args => {
|
|
259
|
+
const {size, x, y, document} = args;
|
|
260
|
+
args = size / 7;
|
|
261
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
262
|
+
element.setAttribute("clip-rule", "evenodd"), element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * args} v ${2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * args} ${2.5 * args} h ${2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * args} ${2.5 * -args} v ${-2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * -args} ${2.5 * -args} h ${-2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * -args} ${2.5 * args} z M ${x + 2.5 * args} ${y + args} h ${2 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * args} ${1.5 * args} v ${2 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * -args} ${1.5 * args} h ${-2 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * -args} ${1.5 * -args} v ${-2 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * args} ${1.5 * -args} z`);
|
|
263
|
+
const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
264
|
+
return fill.setAttribute("clip-rule", "evenodd"), fill.setAttribute("d", svgPath`M ${x - args} ${y + 2.5 * args} v ${2 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 0, ${3.5 * args} ${3.5 * args} h ${2 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 0, ${3.5 * args} ${3.5 * -args} v ${-2 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 0, ${3.5 * -args} ${3.5 * -args} h ${-2 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 0, ${3.5 * -args} ${3.5 * args} z`),
|
|
265
|
+
[ element, fill ];
|
|
266
|
+
},
|
|
267
|
+
classy: args => {
|
|
268
|
+
const {size, x, y, document} = args;
|
|
269
|
+
args = size / 7;
|
|
270
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
271
|
+
element.setAttribute("clip-rule", "evenodd"), element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * args} v ${2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * args} ${2.5 * args} h ${4.5 * args} v ${-4.5 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * -args} ${2.5 * -args} h ${-2 * args} H ${x} z M ${x + 2.5 * args} ${y + args} h ${2 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * args} ${1.5 * args} v ${3.5 * args} h ${-3.5 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * -args} ${1.5 * -args} v ${-3.5 * args} z`);
|
|
272
|
+
const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
273
|
+
return fill.setAttribute("clip-rule", "evenodd"), fill.setAttribute("d", svgPath`M ${x + .5 * args} ${y - args} h ${4 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 1, ${3.5 * args} ${3.5 * args} v ${5.5 * args} h ${-5.5 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 1, ${3.5 * -args} ${3.5 * -args} v ${-5.5 * args} z`),
|
|
274
|
+
[ element, fill ];
|
|
275
|
+
},
|
|
276
|
+
inpoint: args => {
|
|
277
|
+
const {size, x, y, document} = args;
|
|
278
|
+
args = size / 7;
|
|
279
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
280
|
+
element.setAttribute("clip-rule", "evenodd"), element.setAttribute("d", svgPath`M ${x} ${y + 2.5 * args} v ${2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * args} ${2.5 * args} h ${4.5 * args} v ${-4.5 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * -args} ${2.5 * -args} h ${-2 * args} a ${2.5 * args} ${2.5 * args}, 0, 0, 0, ${2.5 * -args} ${2.5 * args} z M ${x + 2.5 * args} ${y + args} h ${2 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * args} ${1.5 * args} v ${3.5 * args} h ${-3.5 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * -args} ${1.5 * -args} v ${-2 * args} a ${1.5 * args} ${1.5 * args}, 0, 0, 1, ${1.5 * args} ${1.5 * -args} z`);
|
|
281
|
+
const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
282
|
+
return fill.setAttribute("clip-rule", "evenodd"), fill.setAttribute("d", svgPath`M ${x + .5 * args} ${y - args} h ${4 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 1, ${3.5 * args} ${3.5 * args} v ${5.5 * args} h ${-5.5 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 1, ${3.5 * -args} ${3.5 * -args} v ${-2 * args} a ${3.5 * args} ${3.5 * args}, 0, 0, 1, ${3.5 * args} ${3.5 * -args} z`),
|
|
283
|
+
[ element, fill ];
|
|
284
|
+
}
|
|
285
|
+
}, qrCornerSquareFigures = {
|
|
286
|
+
[CornerSquareType.dot]: args => SquareElements.dot(args),
|
|
287
|
+
[CornerSquareType.square]: args => SquareElements.square(args),
|
|
288
|
+
[CornerSquareType.extraRounded]: args => SquareElements.extraRounded(args),
|
|
289
|
+
[CornerSquareType.classy]: args => rotateFigure({
|
|
290
|
+
...args,
|
|
291
|
+
draw: SquareElements.classy
|
|
292
|
+
}),
|
|
293
|
+
[CornerSquareType.inpoint]: args => rotateFigure({
|
|
294
|
+
...args,
|
|
295
|
+
draw: SquareElements.inpoint
|
|
296
|
+
}),
|
|
297
|
+
[CornerSquareType.outpoint]: ({rotation, ...args}) => rotateFigure({
|
|
298
|
+
...args,
|
|
299
|
+
rotation: (rotation || 0) + Math.PI,
|
|
300
|
+
draw: SquareElements.inpoint
|
|
301
|
+
})
|
|
302
|
+
}, qrDotFigures = {
|
|
303
|
+
[DotType.dot]: args => DotElements.dot(args),
|
|
304
|
+
[DotType.randomDot]: ({size, ...args}) => DotElements.dot({
|
|
305
|
+
...args,
|
|
306
|
+
size: size * (.25 * Math.random() + .75)
|
|
307
|
+
}),
|
|
308
|
+
[DotType.rounded]: ({x, y, size, document, getNeighbor: bottomNeighbor_getNeighbor}) => {
|
|
645
309
|
var leftNeighbor_rotation = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(-1, 0) : 0;
|
|
646
|
-
|
|
310
|
+
const rightNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, -1) : 0;
|
|
647
311
|
var neighborsCount_rotation = leftNeighbor_rotation + rightNeighbor + topNeighbor + (bottomNeighbor_getNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, 1) : 0);
|
|
648
|
-
0 === neighborsCount_rotation ?
|
|
312
|
+
return 0 === neighborsCount_rotation ? DotElements.dot({
|
|
649
313
|
x,
|
|
650
314
|
y,
|
|
651
315
|
size,
|
|
652
|
-
|
|
653
|
-
}) : neighborsCount_rotation > 2 || leftNeighbor_rotation && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ?
|
|
316
|
+
document
|
|
317
|
+
}) : neighborsCount_rotation > 2 || leftNeighbor_rotation && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ? DotElements.square({
|
|
654
318
|
x,
|
|
655
319
|
y,
|
|
656
320
|
size,
|
|
657
|
-
|
|
321
|
+
document
|
|
658
322
|
}) : 2 === neighborsCount_rotation ? (neighborsCount_rotation = 0, leftNeighbor_rotation && topNeighbor ? neighborsCount_rotation = Math.PI / 2 : topNeighbor && rightNeighbor ? neighborsCount_rotation = Math.PI : rightNeighbor && bottomNeighbor_getNeighbor && (neighborsCount_rotation = -Math.PI / 2),
|
|
659
|
-
|
|
323
|
+
rotateFigure({
|
|
660
324
|
x,
|
|
661
325
|
y,
|
|
662
326
|
size,
|
|
663
|
-
rotation: neighborsCount_rotation
|
|
664
|
-
|
|
665
|
-
|
|
327
|
+
rotation: neighborsCount_rotation,
|
|
328
|
+
document,
|
|
329
|
+
draw: DotElements.cornerRounded
|
|
330
|
+
})) : (leftNeighbor_rotation = 0, topNeighbor ? leftNeighbor_rotation = Math.PI / 2 : rightNeighbor ? leftNeighbor_rotation = Math.PI : bottomNeighbor_getNeighbor && (leftNeighbor_rotation = -Math.PI / 2),
|
|
331
|
+
rotateFigure({
|
|
666
332
|
x,
|
|
667
333
|
y,
|
|
668
334
|
size,
|
|
669
|
-
rotation: leftNeighbor_rotation
|
|
335
|
+
rotation: leftNeighbor_rotation,
|
|
336
|
+
document,
|
|
337
|
+
draw: DotElements.sideRounded
|
|
670
338
|
}));
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
339
|
+
},
|
|
340
|
+
[DotType.extraRounded]: ({x, y, size, document, getNeighbor: bottomNeighbor}) => {
|
|
341
|
+
var leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0;
|
|
342
|
+
const rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
343
|
+
var neighborsCount = leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0);
|
|
344
|
+
return 0 === neighborsCount ? DotElements.dot({
|
|
675
345
|
x,
|
|
676
346
|
y,
|
|
677
347
|
size,
|
|
678
|
-
|
|
679
|
-
}) : topNeighbor && bottomNeighbor ?
|
|
348
|
+
document
|
|
349
|
+
}) : neighborsCount > 2 || leftNeighbor && rightNeighbor || topNeighbor && bottomNeighbor ? DotElements.square({
|
|
680
350
|
x,
|
|
681
351
|
y,
|
|
682
352
|
size,
|
|
683
|
-
|
|
684
|
-
}) : topNeighbor &&
|
|
353
|
+
document
|
|
354
|
+
}) : 2 === neighborsCount ? (neighborsCount = 0, leftNeighbor && topNeighbor ? neighborsCount = Math.PI / 2 : topNeighbor && rightNeighbor ? neighborsCount = Math.PI : rightNeighbor && bottomNeighbor && (neighborsCount = -Math.PI / 2),
|
|
355
|
+
rotateFigure({
|
|
685
356
|
x,
|
|
686
357
|
y,
|
|
687
358
|
size,
|
|
688
|
-
rotation:
|
|
689
|
-
|
|
359
|
+
rotation: neighborsCount,
|
|
360
|
+
document,
|
|
361
|
+
draw: DotElements.cornerExtraRounded
|
|
362
|
+
})) : (leftNeighbor = 0, topNeighbor ? leftNeighbor = Math.PI / 2 : rightNeighbor ? leftNeighbor = Math.PI : bottomNeighbor && (leftNeighbor = -Math.PI / 2),
|
|
363
|
+
rotateFigure({
|
|
690
364
|
x,
|
|
691
365
|
y,
|
|
692
366
|
size,
|
|
693
|
-
rotation:
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
367
|
+
rotation: leftNeighbor,
|
|
368
|
+
document,
|
|
369
|
+
draw: DotElements.sideRounded
|
|
370
|
+
}));
|
|
371
|
+
},
|
|
372
|
+
[DotType.verticalLine]: ({x, y, size, document, getNeighbor: bottomNeighbor}) => {
|
|
373
|
+
const topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
374
|
+
return bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0, topNeighbor && bottomNeighbor ? DotElements.square({
|
|
699
375
|
x,
|
|
700
376
|
y,
|
|
701
377
|
size,
|
|
702
|
-
|
|
703
|
-
}) :
|
|
378
|
+
document
|
|
379
|
+
}) : topNeighbor && !bottomNeighbor ? rotateFigure({
|
|
704
380
|
x,
|
|
705
381
|
y,
|
|
706
382
|
size,
|
|
707
|
-
rotation:
|
|
708
|
-
|
|
383
|
+
rotation: Math.PI / 2,
|
|
384
|
+
document,
|
|
385
|
+
draw: DotElements.sideRounded
|
|
386
|
+
}) : bottomNeighbor && !topNeighbor ? rotateFigure({
|
|
709
387
|
x,
|
|
710
388
|
y,
|
|
711
389
|
size,
|
|
712
|
-
rotation:
|
|
713
|
-
|
|
390
|
+
rotation: -Math.PI / 2,
|
|
391
|
+
document,
|
|
392
|
+
draw: DotElements.sideRounded
|
|
393
|
+
}) : DotElements.dot({
|
|
714
394
|
x,
|
|
715
395
|
y,
|
|
716
396
|
size,
|
|
717
|
-
|
|
397
|
+
document
|
|
718
398
|
});
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
var neighborsCount = leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0);
|
|
724
|
-
0 === neighborsCount ? this.basicDot({
|
|
399
|
+
},
|
|
400
|
+
[DotType.horizontalLine]: ({x, y, size, document, getNeighbor}) => {
|
|
401
|
+
const leftNeighbor = getNeighbor ? +getNeighbor(-1, 0) : 0;
|
|
402
|
+
return getNeighbor = getNeighbor ? +getNeighbor(1, 0) : 0, leftNeighbor && getNeighbor ? DotElements.square({
|
|
725
403
|
x,
|
|
726
404
|
y,
|
|
727
405
|
size,
|
|
728
|
-
|
|
729
|
-
}) :
|
|
406
|
+
document
|
|
407
|
+
}) : leftNeighbor && !getNeighbor ? rotateFigure({
|
|
730
408
|
x,
|
|
731
409
|
y,
|
|
732
410
|
size,
|
|
733
|
-
rotation: 0
|
|
734
|
-
|
|
735
|
-
|
|
411
|
+
rotation: 0,
|
|
412
|
+
document,
|
|
413
|
+
draw: DotElements.sideRounded
|
|
414
|
+
}) : getNeighbor && !leftNeighbor ? rotateFigure({
|
|
736
415
|
x,
|
|
737
416
|
y,
|
|
738
417
|
size,
|
|
739
|
-
rotation:
|
|
740
|
-
|
|
741
|
-
|
|
418
|
+
rotation: Math.PI,
|
|
419
|
+
document,
|
|
420
|
+
draw: DotElements.sideRounded
|
|
421
|
+
}) : DotElements.dot({
|
|
742
422
|
x,
|
|
743
423
|
y,
|
|
744
424
|
size,
|
|
745
|
-
|
|
746
|
-
})
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ?
|
|
425
|
+
document
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
[DotType.classy]: ({x, y, size, document, getNeighbor: bottomNeighbor}) => {
|
|
429
|
+
const leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
430
|
+
return leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? rotateFigure({
|
|
751
431
|
x,
|
|
752
432
|
y,
|
|
753
433
|
size,
|
|
754
|
-
rotation: Math.PI / 2
|
|
755
|
-
|
|
434
|
+
rotation: Math.PI / 2,
|
|
435
|
+
document,
|
|
436
|
+
draw: DotElements.cornersRounded
|
|
437
|
+
}) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? DotElements.square({
|
|
756
438
|
x,
|
|
757
439
|
y,
|
|
758
440
|
size,
|
|
759
|
-
|
|
760
|
-
}) :
|
|
441
|
+
document
|
|
442
|
+
}) : rotateFigure({
|
|
761
443
|
x,
|
|
762
444
|
y,
|
|
763
445
|
size,
|
|
764
|
-
rotation: Math.PI / 2
|
|
765
|
-
|
|
446
|
+
rotation: Math.PI / 2,
|
|
447
|
+
document,
|
|
448
|
+
draw: DotElements.cornerRounded
|
|
449
|
+
}) : rotateFigure({
|
|
766
450
|
x,
|
|
767
451
|
y,
|
|
768
452
|
size,
|
|
769
|
-
rotation: -Math.PI / 2
|
|
453
|
+
rotation: -Math.PI / 2,
|
|
454
|
+
document,
|
|
455
|
+
draw: DotElements.cornerRounded
|
|
770
456
|
});
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ?
|
|
457
|
+
},
|
|
458
|
+
[DotType.classyRounded]: ({x, y, size, document, getNeighbor: bottomNeighbor}) => {
|
|
459
|
+
const leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
|
|
460
|
+
return leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? rotateFigure({
|
|
775
461
|
x,
|
|
776
462
|
y,
|
|
777
463
|
size,
|
|
778
|
-
rotation: Math.PI / 2
|
|
779
|
-
|
|
464
|
+
rotation: Math.PI / 2,
|
|
465
|
+
document,
|
|
466
|
+
draw: DotElements.cornersRounded
|
|
467
|
+
}) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? DotElements.square({
|
|
780
468
|
x,
|
|
781
469
|
y,
|
|
782
470
|
size,
|
|
783
|
-
|
|
784
|
-
}) :
|
|
471
|
+
document
|
|
472
|
+
}) : rotateFigure({
|
|
785
473
|
x,
|
|
786
474
|
y,
|
|
787
475
|
size,
|
|
788
|
-
rotation: Math.PI / 2
|
|
789
|
-
|
|
476
|
+
rotation: Math.PI / 2,
|
|
477
|
+
document,
|
|
478
|
+
draw: DotElements.cornerExtraRounded
|
|
479
|
+
}) : rotateFigure({
|
|
790
480
|
x,
|
|
791
481
|
y,
|
|
792
482
|
size,
|
|
793
|
-
rotation: -Math.PI / 2
|
|
483
|
+
rotation: -Math.PI / 2,
|
|
484
|
+
document,
|
|
485
|
+
draw: DotElements.cornerExtraRounded
|
|
794
486
|
});
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
|
|
487
|
+
},
|
|
488
|
+
[DotType.square]: args => DotElements.square(args),
|
|
489
|
+
[DotType.smallSquare]: ({x, y, size, document}) => DotElements.square({
|
|
490
|
+
x: x += .15 * size,
|
|
491
|
+
y: y += .15 * size,
|
|
492
|
+
size: size = .7 * size,
|
|
493
|
+
document
|
|
494
|
+
}),
|
|
495
|
+
[DotType.tinySquare]: ({x, y, size, document}) => DotElements.square({
|
|
496
|
+
x: x += .35 * size,
|
|
497
|
+
y: y += .35 * size,
|
|
498
|
+
size: size = .3 * size,
|
|
499
|
+
document
|
|
500
|
+
}),
|
|
501
|
+
[DotType.diamond]: args => rotateFigure({
|
|
502
|
+
...args,
|
|
503
|
+
rotation: Math.PI / 4,
|
|
504
|
+
draw: DotElements.square
|
|
505
|
+
}),
|
|
506
|
+
[DotType.wave]: ({x, y, size, document, getNeighbor: bottomNeighbor}) => {
|
|
507
|
+
const leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0;
|
|
798
508
|
var rotation = bottomNeighbor ? +bottomNeighbor(0, -1) : 0, neighborsCount = leftNeighbor + rightNeighbor + rotation + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0);
|
|
799
|
-
0 === neighborsCount ?
|
|
509
|
+
return 0 === neighborsCount ? DotElements.dot({
|
|
800
510
|
x,
|
|
801
511
|
y,
|
|
802
512
|
size,
|
|
803
|
-
|
|
804
|
-
}) : neighborsCount > 2 || leftNeighbor && rightNeighbor || rotation && bottomNeighbor ?
|
|
513
|
+
document
|
|
514
|
+
}) : neighborsCount > 2 || leftNeighbor && rightNeighbor || rotation && bottomNeighbor ? DotElements.square({
|
|
805
515
|
x,
|
|
806
516
|
y,
|
|
807
517
|
size,
|
|
808
|
-
|
|
518
|
+
document
|
|
809
519
|
}) : 2 === neighborsCount ? (neighborsCount = 0, leftNeighbor && rotation ? neighborsCount = Math.PI / 2 : rotation && rightNeighbor ? neighborsCount = Math.PI : rightNeighbor && bottomNeighbor && (neighborsCount = -Math.PI / 2),
|
|
810
|
-
|
|
520
|
+
rotateFigure({
|
|
811
521
|
x,
|
|
812
522
|
y,
|
|
813
523
|
size,
|
|
814
|
-
rotation: neighborsCount
|
|
815
|
-
|
|
816
|
-
|
|
524
|
+
rotation: neighborsCount,
|
|
525
|
+
document,
|
|
526
|
+
draw: DotElements.cornerExtraRounded
|
|
527
|
+
})) : (rotation = 0, rightNeighbor ? rotation = Math.PI / 2 : bottomNeighbor ? rotation = Math.PI : leftNeighbor && (rotation = -Math.PI / 2),
|
|
528
|
+
rotateFigure({
|
|
817
529
|
x,
|
|
818
530
|
y,
|
|
819
531
|
size,
|
|
820
|
-
rotation
|
|
532
|
+
rotation,
|
|
533
|
+
document,
|
|
534
|
+
draw: DotElements.wave
|
|
821
535
|
}));
|
|
822
536
|
}
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
function getQrDotFigure(type) {
|
|
540
|
+
return qrDotFigures[type] || qrDotFigures[DotType.square];
|
|
823
541
|
}
|
|
824
542
|
|
|
825
543
|
let browserImageTools = {
|
|
@@ -1014,7 +732,7 @@ class QRSVG {
|
|
|
1014
732
|
var minSize_xFakeBeginning = Math.min(options.width, options.height);
|
|
1015
733
|
options.imageOptions.mode == ImageMode.background && (minSize_xFakeBeginning -= 2 * dotSize * (options.imageOptions.margin || 0));
|
|
1016
734
|
var colorCount_xBeginning = Math.floor((options.width - count * dotSize) / 2), yBeginning_yFakeBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1017
|
-
let
|
|
735
|
+
let draw = getQrDotFigure(options.dotsOptions.type);
|
|
1018
736
|
[this.dotsMask, this.dotsMaskGroup] = this.createMask("mask-dot-color"), this.defs.appendChild(this.dotsMask),
|
|
1019
737
|
options.imageOptions.mode == ImageMode.background && ([this.lightDotsMask, this.lightDotsMaskGroup] = this.createMask("mask-light-dot-color"),
|
|
1020
738
|
this.defs.appendChild(this.lightDotsMask));
|
|
@@ -1038,18 +756,20 @@ class QRSVG {
|
|
|
1038
756
|
for (let i = 0; i < fakeCount_margin; i++) {
|
|
1039
757
|
count = alignment.find(v => i - additionalDots > v - 3 && i - additionalDots < v + 3);
|
|
1040
758
|
for (let j = 0; j < fakeCount_margin; j++) center_jAlign = alignment.find(v => j - additionalDots > v - 3 && j - additionalDots < v + 3),
|
|
1041
|
-
null != fakeMatrix[i][j] && (this.lightDotsMask && (
|
|
1042
|
-
fakeMatrix[i][j] ? (
|
|
759
|
+
null != fakeMatrix[i][j] && (this.lightDotsMask && (draw = count && center_jAlign && (count != alignment[0] && center_jAlign != alignment[0] || center_jAlign != alignment[0] && center_jAlign != alignment[alignment.length - 1] || count != alignment[0] && count != alignment[alignment.length - 1]) ? getQrDotFigure(DotType.square) : getQrDotFigure(DotType.tinySquare)),
|
|
760
|
+
fakeMatrix[i][j] ? this.dotsMaskGroup && this.dotsMaskGroup.appendChild(draw({
|
|
1043
761
|
x: minSize_xFakeBeginning + i * dotSize,
|
|
1044
762
|
y: yBeginning_yFakeBeginning + j * dotSize,
|
|
1045
763
|
size: dotSize,
|
|
764
|
+
document: this.options.document,
|
|
1046
765
|
getNeighbor: (xOffset, yOffset) => !0 === fakeMatrix[i + xOffset]?.[j + yOffset]
|
|
1047
|
-
})
|
|
766
|
+
})) : this.lightDotsMask && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(draw({
|
|
1048
767
|
x: minSize_xFakeBeginning + i * dotSize,
|
|
1049
768
|
y: yBeginning_yFakeBeginning + j * dotSize,
|
|
1050
769
|
size: dotSize,
|
|
770
|
+
document: this.options.document,
|
|
1051
771
|
getNeighbor: (xOffset, yOffset) => !1 === fakeMatrix[i + xOffset]?.[j + yOffset]
|
|
1052
|
-
})
|
|
772
|
+
})));
|
|
1053
773
|
}
|
|
1054
774
|
this.lightDotsMask && this.createColor({
|
|
1055
775
|
options: options.imageOptions.fill.gradient,
|
|
@@ -1076,73 +796,82 @@ class QRSVG {
|
|
|
1076
796
|
let options = this.options;
|
|
1077
797
|
if (!this._element) throw Error("Element code is not defined");
|
|
1078
798
|
let count = this.qr.getModuleCount(), dotSize = this.options.dotsOptions.size, cornersSquareSize = 7 * dotSize, cornersDotSize = 3 * dotSize, xBeginning = Math.floor((options.width - count * dotSize) / 2), yBeginning = Math.floor((options.height - count * dotSize) / 2);
|
|
1079
|
-
[ [ 0, 0, 0 ], [ 1, 0, Math.PI / 2 ], [ 0, 1, -Math.PI / 2 ] ].forEach(([
|
|
1080
|
-
let x = xBeginning +
|
|
799
|
+
[ [ 0, 0, 0 ], [ 1, 0, Math.PI / 2 ], [ 0, 1, -Math.PI / 2 ] ].forEach(([column_draw, row, draw]) => {
|
|
800
|
+
let x = xBeginning + column_draw * dotSize * (count - 7), y = yBeginning + row * dotSize * (count - 7);
|
|
1081
801
|
var cornersDotMaskGroup_cornersSquareMask = this.dotsMask;
|
|
1082
802
|
let cornersSquareMaskGroup = this.dotsMaskGroup;
|
|
1083
|
-
var val,
|
|
1084
|
-
if (cornersDotMaskGroup_cornersSquareMask = this.dotsMaskGroup, (options.cornersSquareOptions?.gradient || options.cornersSquareOptions?.color) && ([cornersDotMaskGroup_cornersSquareMask, cornersSquareMaskGroup] = this.createMask(`mask-corners-square-color-${
|
|
1085
|
-
this.defs.appendChild(cornersDotMaskGroup_cornersSquareMask),
|
|
803
|
+
var val, cornersDotMask_draw = this.dotsMask;
|
|
804
|
+
if (cornersDotMaskGroup_cornersSquareMask = this.dotsMaskGroup, (options.cornersSquareOptions?.gradient || options.cornersSquareOptions?.color) && ([cornersDotMaskGroup_cornersSquareMask, cornersSquareMaskGroup] = this.createMask(`mask-corners-square-color-${column_draw}-${row}`),
|
|
805
|
+
this.defs.appendChild(cornersDotMaskGroup_cornersSquareMask), cornersDotMask_draw = cornersDotMaskGroup_cornersSquareMask,
|
|
1086
806
|
cornersDotMaskGroup_cornersSquareMask = cornersSquareMaskGroup, this.createColor({
|
|
1087
807
|
options: options.cornersSquareOptions?.gradient,
|
|
1088
808
|
color: options.cornersSquareOptions?.color,
|
|
1089
|
-
additionalRotation:
|
|
809
|
+
additionalRotation: draw,
|
|
1090
810
|
x,
|
|
1091
811
|
y,
|
|
1092
812
|
height: cornersSquareSize,
|
|
1093
813
|
width: cornersSquareSize,
|
|
1094
|
-
name: `corners-square-color-${
|
|
1095
|
-
})), val = options.cornersSquareOptions?.type, val && cornerSquareTypes.has(val))
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
814
|
+
name: `corners-square-color-${column_draw}-${row}`
|
|
815
|
+
})), val = options.cornersSquareOptions?.type, val && cornerSquareTypes.has(val)) {
|
|
816
|
+
let [cornerElement, cornerFill] = (qrCornerSquareFigures[options.cornersSquareOptions.type] || qrCornerSquareFigures[CornerSquareType.square])({
|
|
817
|
+
x,
|
|
818
|
+
y,
|
|
819
|
+
size: cornersSquareSize,
|
|
820
|
+
document: this.options.document,
|
|
821
|
+
rotation: draw
|
|
822
|
+
});
|
|
823
|
+
cornersSquareMaskGroup && cornersSquareMaskGroup.appendChild(cornerElement), this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornerFill);
|
|
824
|
+
} else {
|
|
825
|
+
cornersDotMask_draw = getQrDotFigure(options.cornersSquareOptions?.type || options.dotsOptions.type);
|
|
826
|
+
for (let i = 0; i < squareMask.length; i++) for (let j = 0; j < squareMask[i].length; j++) squareMask[i]?.[j] ? cornersSquareMaskGroup && cornersSquareMaskGroup.appendChild(cornersDotMask_draw({
|
|
1104
827
|
x: x + i * dotSize,
|
|
1105
828
|
y: y + j * dotSize,
|
|
1106
829
|
size: dotSize,
|
|
830
|
+
document: this.options.document,
|
|
1107
831
|
getNeighbor: (xOffset, yOffset) => !!squareMask[i + xOffset]?.[j + yOffset]
|
|
1108
|
-
})
|
|
832
|
+
})) : this.lightDotsMask && !dotMask[i]?.[j] && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_draw({
|
|
1109
833
|
x: x + i * dotSize,
|
|
1110
834
|
y: y + j * dotSize,
|
|
1111
835
|
size: dotSize,
|
|
836
|
+
document: this.options.document,
|
|
1112
837
|
getNeighbor: (xOffset, yOffset) => !squareMask[i + xOffset]?.[j + yOffset] && !dotMask[i + xOffset]?.[j + yOffset]
|
|
1113
|
-
})
|
|
1114
|
-
if (this.lightDotsMask) for (let i = -1; i < 8; i++) for (let j = -1; j < 8; j++) -1
|
|
838
|
+
}));
|
|
839
|
+
if (this.lightDotsMask) for (let i = -1; i < 8; i++) for (let j = -1; j < 8; j++) (-1 == i || 7 == i || -1 == j || 7 == j) && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_draw({
|
|
1115
840
|
x: x + i * dotSize,
|
|
1116
841
|
y: y + j * dotSize,
|
|
1117
842
|
size: dotSize,
|
|
843
|
+
document: this.options.document,
|
|
1118
844
|
getNeighbor: (ii, jj) => (jj = j + jj, (ii = i + ii) >= -1 && ii <= 7 && jj >= -1 && jj <= 7 && (-1 == ii || 7 == ii || -1 == jj || 7 == jj))
|
|
1119
|
-
})
|
|
845
|
+
}));
|
|
1120
846
|
}
|
|
1121
|
-
if ((options.cornersDotOptions?.gradient || options.cornersDotOptions?.color) && ([
|
|
1122
|
-
this.defs.appendChild(
|
|
847
|
+
if ((options.cornersDotOptions?.gradient || options.cornersDotOptions?.color) && ([cornersDotMask_draw, cornersDotMaskGroup_cornersSquareMask] = this.createMask(`mask-corners-dot-color-${column_draw}-${row}`),
|
|
848
|
+
this.defs.appendChild(cornersDotMask_draw), this.createColor({
|
|
1123
849
|
options: options.cornersDotOptions?.gradient,
|
|
1124
850
|
color: options.cornersDotOptions?.color,
|
|
1125
|
-
additionalRotation:
|
|
851
|
+
additionalRotation: draw,
|
|
1126
852
|
x: x + 2 * dotSize,
|
|
1127
853
|
y: y + 2 * dotSize,
|
|
1128
854
|
height: cornersDotSize,
|
|
1129
855
|
width: cornersDotSize,
|
|
1130
|
-
name: `corners-dot-color-${
|
|
856
|
+
name: `corners-dot-color-${column_draw}-${row}`
|
|
1131
857
|
})), function(val) {
|
|
1132
858
|
return !(!val || !cornerDotTypes.has(val));
|
|
1133
|
-
}(options.cornersDotOptions?.type))
|
|
859
|
+
}(options.cornersDotOptions?.type)) column_draw = qrCornerDotFigures[options.cornersDotOptions.type] || qrCornerDotFigures[CornerDotType.square],
|
|
860
|
+
cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(column_draw({
|
|
1134
861
|
x: x + 2 * dotSize,
|
|
1135
862
|
y: y + 2 * dotSize,
|
|
1136
863
|
size: cornersDotSize,
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
864
|
+
document: this.document,
|
|
865
|
+
rotation: draw
|
|
866
|
+
})); else {
|
|
867
|
+
draw = getQrDotFigure(options.cornersDotOptions?.type || options.dotsOptions.type);
|
|
868
|
+
for (let i = 0; i < dotMask.length; i++) for (let j = 0; j < dotMask[i].length; j++) dotMask[i]?.[j] && cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(draw({
|
|
1141
869
|
x: x + i * dotSize,
|
|
1142
870
|
y: y + j * dotSize,
|
|
1143
871
|
size: dotSize,
|
|
872
|
+
document: this.options.document,
|
|
1144
873
|
getNeighbor: (xOffset, yOffset) => !!dotMask[i + xOffset]?.[j + yOffset]
|
|
1145
|
-
})
|
|
874
|
+
}));
|
|
1146
875
|
}
|
|
1147
876
|
});
|
|
1148
877
|
}
|