@liquid-js/qr-code-styling 4.0.8 → 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.
@@ -45,12 +45,12 @@ function sanitizeGradient(gradient_newGradient) {
45
45
  DotType.extraRounded = "extra-rounded", DotType.verticalLine = "vertical-line",
46
46
  DotType.horizontalLine = "horizontal-line", DotType.classy = "classy", DotType.classyRounded = "classy-rounded",
47
47
  DotType.square = "square", DotType.smallSquare = "small-square", DotType.tinySquare = "tiny-square",
48
- DotType.diamond = "diamond", (CornerDotType = CornerDotType ||= {}).dot = "dot",
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.outpoint = "outpoint", CornerDotType.inpoint = "inpoint",
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.outpoint = "outpoint", CornerSquareType.inpoint = "inpoint", (ShapeType = ShapeType ||= {}).square = "square",
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,656 +129,415 @@ function svgPath(strings, ...values) {
129
129
  }, "").trim().replace(/[\s\n\r]+/gim, " ");
130
130
  }
131
131
 
132
- class QRCornerDot {
133
- type;
134
- document;
135
- _element;
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
- }
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;
295
136
  }
296
137
 
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
- }
451
- }
452
-
453
- class QRDot {
454
- type;
455
- document;
456
- _element;
457
- get element() {
458
- return this._element;
459
- }
460
- constructor(type, document) {
461
- this.type = type, this.document = document;
462
- }
463
- draw(args) {
464
- let drawFunction;
465
- switch (this.type) {
466
- case DotType.dot:
467
- drawFunction = this.drawDot;
468
- break;
469
-
470
- case DotType.randomDot:
471
- drawFunction = this.drawRandomDot;
472
- break;
473
-
474
- case DotType.classy:
475
- drawFunction = this.drawClassy;
476
- break;
477
-
478
- case DotType.classyRounded:
479
- drawFunction = this.drawClassyRounded;
480
- break;
481
-
482
- case DotType.rounded:
483
- drawFunction = this.drawRounded;
484
- break;
485
-
486
- case DotType.verticalLine:
487
- drawFunction = this.drawVerticalLine;
488
- break;
489
-
490
- case DotType.horizontalLine:
491
- drawFunction = this.drawHorizontalLine;
492
- break;
493
-
494
- case DotType.extraRounded:
495
- drawFunction = this.drawExtraRounded;
496
- break;
497
-
498
- case DotType.diamond:
499
- drawFunction = this.drawDiamond;
500
- break;
501
-
502
- case DotType.smallSquare:
503
- drawFunction = this.drawSmallSquare;
504
- break;
505
-
506
- case DotType.tinySquare:
507
- drawFunction = this.drawTinySquare;
508
- break;
509
-
510
- default:
511
- drawFunction = this.drawSquare;
512
- }
513
- drawFunction.call(this, args);
514
- }
515
- rotateFigure({x: cx, y: cy, size, rotation = 0, draw}) {
516
- cx += size / 2, cy += size / 2, draw(), this._element?.setAttribute("transform", `rotate(${numToAttr(180 * rotation / Math.PI)},${cx},${cy})`);
517
- }
518
- basicDot(args) {
519
- let {size, x, y} = args;
520
- this.rotateFigure({
521
- ...args,
522
- draw: () => {
523
- this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "circle"),
524
- this._element.setAttribute("cx", numToAttr(x + size / 2)), this._element.setAttribute("cy", numToAttr(y + size / 2)),
525
- this._element.setAttribute("r", numToAttr(size / 2));
526
- }
527
- });
528
- }
529
- basicSquare(args) {
530
- let {size, x, y} = args;
531
- this.rotateFigure({
532
- ...args,
533
- draw: () => {
534
- this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "rect"),
535
- this._element.setAttribute("x", numToAttr(x)), this._element.setAttribute("y", numToAttr(y)),
536
- this._element.setAttribute("width", numToAttr(size)), this._element.setAttribute("height", numToAttr(size));
537
- }
538
- });
539
- }
540
- basicSideRounded(args) {
541
- let {size, x, y} = args;
542
- this.rotateFigure({
543
- ...args,
544
- draw: () => {
545
- this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
546
- this._element.setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size / 2} a ${size / 2} ${size / 2}, 0, 0, 0, 0 ${-size} z`);
547
- }
548
- });
549
- }
550
- basicCornerRounded(args) {
551
- let {size, x, y} = args;
552
- this.rotateFigure({
553
- ...args,
554
- draw: () => {
555
- this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
556
- 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`);
557
- }
558
- });
559
- }
560
- basicCornerExtraRounded(args) {
561
- let {size, x, y} = args;
562
- this.rotateFigure({
563
- ...args,
564
- draw: () => {
565
- this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
566
- this._element.setAttribute("d", svgPath`M ${x} ${y} v ${size} h ${size} a ${size} ${size}, 0, 0, 0, ${-size} ${-size} z`);
567
- }
568
- });
569
- }
570
- basicCornersRounded(args) {
571
- let {size, x, y} = args;
572
- this.rotateFigure({
573
- ...args,
574
- draw: () => {
575
- this._element = this.document.createElementNS("http://www.w3.org/2000/svg", "path"),
576
- 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`);
577
- }
578
- });
579
- }
580
- drawDot({x, y, size}) {
581
- this.basicDot({
582
- x,
583
- y,
584
- size,
585
- rotation: 0
586
- });
587
- }
588
- drawRandomDot({x, y, size}) {
589
- this.basicDot({
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" ], {
590
188
  x,
591
189
  y,
592
- size: size * (.25 * Math.random() + .75),
593
- rotation: 0
594
- });
595
- }
596
- drawSquare({x, y, size}) {
597
- this.basicSquare({
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}) => {
309
+ var leftNeighbor_rotation = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(-1, 0) : 0;
310
+ const rightNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, -1) : 0;
311
+ var neighborsCount_rotation = leftNeighbor_rotation + rightNeighbor + topNeighbor + (bottomNeighbor_getNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, 1) : 0);
312
+ return 0 === neighborsCount_rotation ? DotElements.dot({
598
313
  x,
599
314
  y,
600
315
  size,
601
- rotation: 0
602
- });
603
- }
604
- drawSmallSquare({x, y, size}) {
605
- let originalSize = size;
606
- size = .7 * originalSize, x += .15 * originalSize, y += .15 * originalSize, this.basicSquare({
316
+ document
317
+ }) : neighborsCount_rotation > 2 || leftNeighbor_rotation && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ? DotElements.square({
607
318
  x,
608
319
  y,
609
320
  size,
610
- rotation: 0
611
- });
612
- }
613
- drawTinySquare({x, y, size}) {
614
- let originalSize = size;
615
- size = .3 * originalSize, x += .35 * originalSize, y += .35 * originalSize, this.basicSquare({
321
+ document
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),
323
+ rotateFigure({
616
324
  x,
617
325
  y,
618
326
  size,
619
- rotation: 0
620
- });
621
- }
622
- drawDiamond({x, y, size}) {
623
- this.basicSquare({
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({
624
332
  x,
625
333
  y,
626
334
  size,
627
- rotation: Math.PI / 4
628
- });
629
- }
630
- drawRounded({x, y, size, getNeighbor: bottomNeighbor_getNeighbor}) {
631
- var leftNeighbor_rotation = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(-1, 0) : 0;
632
- let rightNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, -1) : 0;
633
- var neighborsCount_rotation = leftNeighbor_rotation + rightNeighbor + topNeighbor + (bottomNeighbor_getNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, 1) : 0);
634
- 0 === neighborsCount_rotation ? this.basicDot({
335
+ rotation: leftNeighbor_rotation,
336
+ document,
337
+ draw: DotElements.sideRounded
338
+ }));
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({
635
345
  x,
636
346
  y,
637
347
  size,
638
- rotation: 0
639
- }) : neighborsCount_rotation > 2 || leftNeighbor_rotation && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ? this.basicSquare({
348
+ document
349
+ }) : neighborsCount > 2 || leftNeighbor && rightNeighbor || topNeighbor && bottomNeighbor ? DotElements.square({
640
350
  x,
641
351
  y,
642
352
  size,
643
- rotation: 0
644
- }) : 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),
645
- this.basicCornerRounded({
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({
646
356
  x,
647
357
  y,
648
358
  size,
649
- rotation: neighborsCount_rotation
650
- })) : 1 === neighborsCount_rotation && (leftNeighbor_rotation = 0, topNeighbor ? leftNeighbor_rotation = Math.PI / 2 : rightNeighbor ? leftNeighbor_rotation = Math.PI : bottomNeighbor_getNeighbor && (leftNeighbor_rotation = -Math.PI / 2),
651
- this.basicSideRounded({
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({
652
364
  x,
653
365
  y,
654
366
  size,
655
- rotation: leftNeighbor_rotation
367
+ rotation: leftNeighbor,
368
+ document,
369
+ draw: DotElements.sideRounded
656
370
  }));
657
- }
658
- drawVerticalLine({x, y, size, getNeighbor: bottomNeighbor}) {
659
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
660
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || leftNeighbor && !topNeighbor && !bottomNeighbor || rightNeighbor && !topNeighbor && !bottomNeighbor ? this.basicDot({
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({
661
375
  x,
662
376
  y,
663
377
  size,
664
- rotation: 0
665
- }) : topNeighbor && bottomNeighbor ? this.basicSquare({
378
+ document
379
+ }) : topNeighbor && !bottomNeighbor ? rotateFigure({
666
380
  x,
667
381
  y,
668
382
  size,
669
- rotation: 0
670
- }) : topNeighbor && !bottomNeighbor ? this.basicSideRounded({
383
+ rotation: Math.PI / 2,
384
+ document,
385
+ draw: DotElements.sideRounded
386
+ }) : bottomNeighbor && !topNeighbor ? rotateFigure({
671
387
  x,
672
388
  y,
673
389
  size,
674
- rotation: Math.PI / 2
675
- }) : bottomNeighbor && !topNeighbor && this.basicSideRounded({
390
+ rotation: -Math.PI / 2,
391
+ document,
392
+ draw: DotElements.sideRounded
393
+ }) : DotElements.dot({
676
394
  x,
677
395
  y,
678
396
  size,
679
- rotation: -Math.PI / 2
397
+ document
680
398
  });
681
- }
682
- drawHorizontalLine({x, y, size, getNeighbor: bottomNeighbor}) {
683
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
684
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || topNeighbor && !leftNeighbor && !rightNeighbor || bottomNeighbor && !leftNeighbor && !rightNeighbor ? 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({
685
403
  x,
686
404
  y,
687
405
  size,
688
- rotation: 0
689
- }) : leftNeighbor && rightNeighbor ? this.basicSquare({
406
+ document
407
+ }) : leftNeighbor && !getNeighbor ? rotateFigure({
690
408
  x,
691
409
  y,
692
410
  size,
693
- rotation: 0
694
- }) : leftNeighbor && !rightNeighbor ? this.basicSideRounded({
411
+ rotation: 0,
412
+ document,
413
+ draw: DotElements.sideRounded
414
+ }) : getNeighbor && !leftNeighbor ? rotateFigure({
695
415
  x,
696
416
  y,
697
417
  size,
698
- rotation: 0
699
- }) : rightNeighbor && !leftNeighbor && this.basicSideRounded({
418
+ rotation: Math.PI,
419
+ document,
420
+ draw: DotElements.sideRounded
421
+ }) : DotElements.dot({
700
422
  x,
701
423
  y,
702
424
  size,
703
- rotation: Math.PI
425
+ document
704
426
  });
705
- }
706
- drawExtraRounded({x, y, size, getNeighbor: bottomNeighbor}) {
707
- var leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0;
708
- let rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
709
- var neighborsCount = leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0);
710
- 0 === neighborsCount ? this.basicDot({
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({
711
431
  x,
712
432
  y,
713
433
  size,
714
- rotation: 0
715
- }) : neighborsCount > 2 || leftNeighbor && rightNeighbor || topNeighbor && bottomNeighbor ? this.basicSquare({
434
+ rotation: Math.PI / 2,
435
+ document,
436
+ draw: DotElements.cornersRounded
437
+ }) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? DotElements.square({
716
438
  x,
717
439
  y,
718
440
  size,
719
- rotation: 0
720
- }) : 2 === neighborsCount ? (neighborsCount = 0, leftNeighbor && topNeighbor ? neighborsCount = Math.PI / 2 : topNeighbor && rightNeighbor ? neighborsCount = Math.PI : rightNeighbor && bottomNeighbor && (neighborsCount = -Math.PI / 2),
721
- this.basicCornerExtraRounded({
441
+ document
442
+ }) : rotateFigure({
722
443
  x,
723
444
  y,
724
445
  size,
725
- rotation: neighborsCount
726
- })) : 1 === neighborsCount && (leftNeighbor = 0, topNeighbor ? leftNeighbor = Math.PI / 2 : rightNeighbor ? leftNeighbor = Math.PI : bottomNeighbor && (leftNeighbor = -Math.PI / 2),
727
- this.basicSideRounded({
446
+ rotation: Math.PI / 2,
447
+ document,
448
+ draw: DotElements.cornerRounded
449
+ }) : rotateFigure({
728
450
  x,
729
451
  y,
730
452
  size,
731
- rotation: leftNeighbor
732
- }));
733
- }
734
- drawClassy({x, y, size, getNeighbor: bottomNeighbor}) {
735
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
736
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
453
+ rotation: -Math.PI / 2,
454
+ document,
455
+ draw: DotElements.cornerRounded
456
+ });
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({
737
461
  x,
738
462
  y,
739
463
  size,
740
- rotation: Math.PI / 2
741
- }) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? this.basicSquare({
464
+ rotation: Math.PI / 2,
465
+ document,
466
+ draw: DotElements.cornersRounded
467
+ }) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? DotElements.square({
742
468
  x,
743
469
  y,
744
470
  size,
745
- rotation: 0
746
- }) : this.basicCornerRounded({
471
+ document
472
+ }) : rotateFigure({
747
473
  x,
748
474
  y,
749
475
  size,
750
- rotation: Math.PI / 2
751
- }) : this.basicCornerRounded({
476
+ rotation: Math.PI / 2,
477
+ document,
478
+ draw: DotElements.cornerExtraRounded
479
+ }) : rotateFigure({
752
480
  x,
753
481
  y,
754
482
  size,
755
- rotation: -Math.PI / 2
483
+ rotation: -Math.PI / 2,
484
+ document,
485
+ draw: DotElements.cornerExtraRounded
756
486
  });
757
- }
758
- drawClassyRounded({x, y, size, getNeighbor: bottomNeighbor}) {
759
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
760
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
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;
508
+ var rotation = bottomNeighbor ? +bottomNeighbor(0, -1) : 0, neighborsCount = leftNeighbor + rightNeighbor + rotation + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0);
509
+ return 0 === neighborsCount ? DotElements.dot({
761
510
  x,
762
511
  y,
763
512
  size,
764
- rotation: Math.PI / 2
765
- }) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? this.basicSquare({
513
+ document
514
+ }) : neighborsCount > 2 || leftNeighbor && rightNeighbor || rotation && bottomNeighbor ? DotElements.square({
766
515
  x,
767
516
  y,
768
517
  size,
769
- rotation: 0
770
- }) : this.basicCornerExtraRounded({
518
+ document
519
+ }) : 2 === neighborsCount ? (neighborsCount = 0, leftNeighbor && rotation ? neighborsCount = Math.PI / 2 : rotation && rightNeighbor ? neighborsCount = Math.PI : rightNeighbor && bottomNeighbor && (neighborsCount = -Math.PI / 2),
520
+ rotateFigure({
771
521
  x,
772
522
  y,
773
523
  size,
774
- rotation: Math.PI / 2
775
- }) : this.basicCornerExtraRounded({
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({
776
529
  x,
777
530
  y,
778
531
  size,
779
- rotation: -Math.PI / 2
780
- });
532
+ rotation,
533
+ document,
534
+ draw: DotElements.wave
535
+ }));
781
536
  }
537
+ };
538
+
539
+ function getQrDotFigure(type) {
540
+ return qrDotFigures[type] || qrDotFigures[DotType.square];
782
541
  }
783
542
 
784
543
  let browserImageTools = {
@@ -833,7 +592,9 @@ function parseColor(base) {
833
592
  };
834
593
  }
835
594
 
836
- let squareMask = [ [ 1, 1, 1, 1, 1, 1, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 1, 1, 1, 1, 1, 1 ] ], dotMask = [ [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ] ];
595
+ let squareMask = [ [ 1, 1, 1, 1, 1, 1, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 1 ], [ 1, 1, 1, 1, 1, 1, 1 ] ], cornerSquareTypes = new Set(Object.values(CornerSquareType));
596
+
597
+ let dotMask = [ [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 1, 1, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ] ], cornerDotTypes = new Set(Object.values(CornerDotType));
837
598
 
838
599
  class QRSVG {
839
600
  options;
@@ -971,7 +732,7 @@ class QRSVG {
971
732
  var minSize_xFakeBeginning = Math.min(options.width, options.height);
972
733
  options.imageOptions.mode == ImageMode.background && (minSize_xFakeBeginning -= 2 * dotSize * (options.imageOptions.margin || 0));
973
734
  var colorCount_xBeginning = Math.floor((options.width - count * dotSize) / 2), yBeginning_yFakeBeginning = Math.floor((options.height - count * dotSize) / 2);
974
- let dot = new QRDot(options.dotsOptions.type, this.document), overlayDot = new QRDot(DotType.tinySquare, this.document), markerDot = new QRDot(DotType.square, this.document);
735
+ let draw = getQrDotFigure(options.dotsOptions.type);
975
736
  [this.dotsMask, this.dotsMaskGroup] = this.createMask("mask-dot-color"), this.defs.appendChild(this.dotsMask),
976
737
  options.imageOptions.mode == ImageMode.background && ([this.lightDotsMask, this.lightDotsMaskGroup] = this.createMask("mask-light-dot-color"),
977
738
  this.defs.appendChild(this.lightDotsMask));
@@ -995,18 +756,20 @@ class QRSVG {
995
756
  for (let i = 0; i < fakeCount_margin; i++) {
996
757
  count = alignment.find(v => i - additionalDots > v - 3 && i - additionalDots < v + 3);
997
758
  for (let j = 0; j < fakeCount_margin; j++) center_jAlign = alignment.find(v => j - additionalDots > v - 3 && j - additionalDots < v + 3),
998
- null != fakeMatrix[i][j] && (this.lightDotsMask && (dot = 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]) ? markerDot : overlayDot),
999
- fakeMatrix[i][j] ? (dot.draw({
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({
1000
761
  x: minSize_xFakeBeginning + i * dotSize,
1001
762
  y: yBeginning_yFakeBeginning + j * dotSize,
1002
763
  size: dotSize,
764
+ document: this.options.document,
1003
765
  getNeighbor: (xOffset, yOffset) => !0 === fakeMatrix[i + xOffset]?.[j + yOffset]
1004
- }), dot.element && this.dotsMaskGroup && this.dotsMaskGroup.appendChild(dot.element)) : this.lightDotsMask && (dot.draw({
766
+ })) : this.lightDotsMask && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(draw({
1005
767
  x: minSize_xFakeBeginning + i * dotSize,
1006
768
  y: yBeginning_yFakeBeginning + j * dotSize,
1007
769
  size: dotSize,
770
+ document: this.options.document,
1008
771
  getNeighbor: (xOffset, yOffset) => !1 === fakeMatrix[i + xOffset]?.[j + yOffset]
1009
- }), dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(dot.element)));
772
+ })));
1010
773
  }
1011
774
  this.lightDotsMask && this.createColor({
1012
775
  options: options.imageOptions.fill.gradient,
@@ -1033,71 +796,82 @@ class QRSVG {
1033
796
  let options = this.options;
1034
797
  if (!this._element) throw Error("Element code is not defined");
1035
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);
1036
- [ [ 0, 0, 0 ], [ 1, 0, Math.PI / 2 ], [ 0, 1, -Math.PI / 2 ] ].forEach(([column_cornersDot, row, dot]) => {
1037
- let x = xBeginning + column_cornersDot * dotSize * (count - 7), y = yBeginning + row * dotSize * (count - 7);
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);
1038
801
  var cornersDotMaskGroup_cornersSquareMask = this.dotsMask;
1039
802
  let cornersSquareMaskGroup = this.dotsMaskGroup;
1040
- var cornersDotMask_cornersSquare_dot = this.dotsMask;
1041
- if (cornersDotMaskGroup_cornersSquareMask = this.dotsMaskGroup, (options.cornersSquareOptions?.gradient || options.cornersSquareOptions?.color) && ([cornersDotMaskGroup_cornersSquareMask, cornersSquareMaskGroup] = this.createMask(`mask-corners-square-color-${column_cornersDot}-${row}`),
1042
- this.defs.appendChild(cornersDotMaskGroup_cornersSquareMask), cornersDotMask_cornersSquare_dot = 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,
1043
806
  cornersDotMaskGroup_cornersSquareMask = cornersSquareMaskGroup, this.createColor({
1044
807
  options: options.cornersSquareOptions?.gradient,
1045
808
  color: options.cornersSquareOptions?.color,
1046
- additionalRotation: dot,
809
+ additionalRotation: draw,
1047
810
  x,
1048
811
  y,
1049
812
  height: cornersSquareSize,
1050
813
  width: cornersSquareSize,
1051
- name: `corners-square-color-${column_cornersDot}-${row}`
1052
- })), options.cornersSquareOptions?.type) (cornersDotMask_cornersSquare_dot = new QRCornerSquare(options.cornersSquareOptions.type, this.document)).draw({
1053
- x,
1054
- y,
1055
- size: cornersSquareSize,
1056
- rotation: dot
1057
- }), cornersDotMask_cornersSquare_dot.element && cornersSquareMaskGroup && cornersSquareMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element),
1058
- cornersDotMask_cornersSquare_dot.fill && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.fill); else {
1059
- cornersDotMask_cornersSquare_dot = new QRDot(options.dotsOptions.type, this.document);
1060
- for (let i = 0; i < squareMask.length; i++) for (let j = 0; j < squareMask[i].length; j++) squareMask[i]?.[j] ? (cornersDotMask_cornersSquare_dot.draw({
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({
1061
827
  x: x + i * dotSize,
1062
828
  y: y + j * dotSize,
1063
829
  size: dotSize,
830
+ document: this.options.document,
1064
831
  getNeighbor: (xOffset, yOffset) => !!squareMask[i + xOffset]?.[j + yOffset]
1065
- }), cornersDotMask_cornersSquare_dot.element && cornersSquareMaskGroup && cornersSquareMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element)) : this.lightDotsMask && !dotMask[i]?.[j] && (cornersDotMask_cornersSquare_dot.draw({
832
+ })) : this.lightDotsMask && !dotMask[i]?.[j] && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_draw({
1066
833
  x: x + i * dotSize,
1067
834
  y: y + j * dotSize,
1068
835
  size: dotSize,
836
+ document: this.options.document,
1069
837
  getNeighbor: (xOffset, yOffset) => !squareMask[i + xOffset]?.[j + yOffset] && !dotMask[i + xOffset]?.[j + yOffset]
1070
- }), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
1071
- 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 || (cornersDotMask_cornersSquare_dot.draw({
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({
1072
840
  x: x + i * dotSize,
1073
841
  y: y + j * dotSize,
1074
842
  size: dotSize,
843
+ document: this.options.document,
1075
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))
1076
- }), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
845
+ }));
1077
846
  }
1078
- if ((options.cornersDotOptions?.gradient || options.cornersDotOptions?.color) && ([cornersDotMask_cornersSquare_dot, cornersDotMaskGroup_cornersSquareMask] = this.createMask(`mask-corners-dot-color-${column_cornersDot}-${row}`),
1079
- this.defs.appendChild(cornersDotMask_cornersSquare_dot), this.createColor({
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({
1080
849
  options: options.cornersDotOptions?.gradient,
1081
850
  color: options.cornersDotOptions?.color,
1082
- additionalRotation: dot,
851
+ additionalRotation: draw,
1083
852
  x: x + 2 * dotSize,
1084
853
  y: y + 2 * dotSize,
1085
854
  height: cornersDotSize,
1086
855
  width: cornersDotSize,
1087
- name: `corners-dot-color-${column_cornersDot}-${row}`
1088
- })), options.cornersDotOptions?.type) (column_cornersDot = new QRCornerDot(options.cornersDotOptions.type, this.document)).draw({
856
+ name: `corners-dot-color-${column_draw}-${row}`
857
+ })), function(val) {
858
+ return !(!val || !cornerDotTypes.has(val));
859
+ }(options.cornersDotOptions?.type)) column_draw = qrCornerDotFigures[options.cornersDotOptions.type] || qrCornerDotFigures[CornerDotType.square],
860
+ cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(column_draw({
1089
861
  x: x + 2 * dotSize,
1090
862
  y: y + 2 * dotSize,
1091
863
  size: cornersDotSize,
1092
- rotation: dot
1093
- }), column_cornersDot.element && cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(column_cornersDot.element); else {
1094
- dot = new QRDot(options.dotsOptions.type, this.document);
1095
- for (let i = 0; i < dotMask.length; i++) for (let j = 0; j < dotMask[i].length; j++) dotMask[i]?.[j] && (dot.draw({
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({
1096
869
  x: x + i * dotSize,
1097
870
  y: y + j * dotSize,
1098
871
  size: dotSize,
872
+ document: this.options.document,
1099
873
  getNeighbor: (xOffset, yOffset) => !!dotMask[i + xOffset]?.[j + yOffset]
1100
- }), dot.element && cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(dot.element));
874
+ }));
1101
875
  }
1102
876
  });
1103
877
  }