@liquid-js/qr-code-styling 4.1.0 → 5.0.0-1

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,14 +45,18 @@ 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", DotType.wave = "wave", (CornerDotType = CornerDotType ||= {}).dot = "dot",
49
- CornerDotType.square = "square", CornerDotType.heart = "heart", CornerDotType.extraRounded = "extra-rounded",
50
- CornerDotType.classy = "classy", CornerDotType.outpoint = "outpoint", CornerDotType.inpoint = "inpoint",
48
+ DotType.diamond = "diamond", DotType.wave = "wave", DotType.heart = "heart", DotType.star = "star",
49
+ DotType.weave = "weave", DotType.pentagon = "pentagon", DotType.hexagon = "hexagon",
50
+ DotType.zebraHorizontal = "zebra-horizontal", DotType.zebraVertical = "zebra-vertical",
51
+ (CornerDotType = CornerDotType ||= {}).dot = "dot", CornerDotType.square = "square",
52
+ CornerDotType.heart = "heart", CornerDotType.extraRounded = "extra-rounded", CornerDotType.classy = "classy",
53
+ CornerDotType.inpoint = "inpoint", CornerDotType.outpoint = "outpoint", CornerDotType.star = "star",
54
+ CornerDotType.pentagon = "pentagon", CornerDotType.hexagon = "hexagon", CornerDotType.diamond = "diamond",
51
55
  (CornerSquareType = CornerSquareType ||= {}).dot = "dot", CornerSquareType.square = "square",
52
56
  CornerSquareType.extraRounded = "extra-rounded", CornerSquareType.classy = "classy",
53
- CornerSquareType.outpoint = "outpoint", CornerSquareType.inpoint = "inpoint", (ShapeType = ShapeType ||= {}).square = "square",
54
- ShapeType.circle = "circle", (ImageMode = ImageMode ||= {}).center = "center", ImageMode.overlay = "overlay",
55
- ImageMode.background = "background";
57
+ CornerSquareType.inpoint = "inpoint", CornerSquareType.outpoint = "outpoint", CornerSquareType.centerCircle = "center-circle",
58
+ (ShapeType = ShapeType ||= {}).square = "square", ShapeType.circle = "circle", (ImageMode = ImageMode ||= {}).center = "center",
59
+ ImageMode.overlay = "overlay", ImageMode.background = "background";
56
60
 
57
61
  let defaultOptions = {
58
62
  document: void 0,
@@ -129,697 +133,404 @@ function svgPath(strings, ...values) {
129
133
  }, "").trim().replace(/[\s\n\r]+/gim, " ");
130
134
  }
131
135
 
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
- }
136
+ function rotateFigure({draw: draw_element, ...args}) {
137
+ let {x, y, size, rotation = 0} = args, cx = x + size / 2, cy = y + size / 2;
138
+ 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})`)),
139
+ draw_element;
295
140
  }
296
141
 
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({
142
+ let DotElements = {
143
+ dot: args => {
144
+ const {size, x, y, document} = args;
145
+ return (args = document.createElementNS("http://www.w3.org/2000/svg", "circle")).setAttribute("cx", numToAttr(x + size / 2)),
146
+ args.setAttribute("cy", numToAttr(y + size / 2)), args.setAttribute("r", numToAttr(size / 2)),
147
+ args;
148
+ },
149
+ square: (args, {width = args.size, height = args.size} = {}) => {
150
+ const {x, y, size, document} = args;
151
+ return (args = document.createElementNS("http://www.w3.org/2000/svg", "rect")).setAttribute("x", numToAttr(x + (size - width) / 2)),
152
+ args.setAttribute("y", numToAttr(y + (size - height) / 2)), args.setAttribute("width", numToAttr(width)),
153
+ args.setAttribute("height", numToAttr(height)), args;
154
+ },
155
+ sideRounded: (args, {height = args.size} = {}) => {
156
+ const {size, x, y, document} = args;
157
+ return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", svgPath`M ${x} ${y + (size - height) / 2} v ${height} h ${size / 2} a ${height / 2} ${height / 2} 0 0 0 0 ${-height} z`),
158
+ args;
159
+ },
160
+ cornerRounded: args => {
161
+ const {size, x, y, document} = args;
162
+ 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`),
163
+ args;
164
+ },
165
+ cornerExtraRounded: args => {
166
+ const {size, x, y, document} = args;
167
+ 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`),
168
+ args;
169
+ },
170
+ cornersRounded: args => {
171
+ const {size, x, y, document} = args;
172
+ 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`),
173
+ args;
174
+ },
175
+ wave: args => {
176
+ const {size, x, y, document} = args;
177
+ var a1_c23y = 5 * Math.PI / 180, a2_c31y = 65 * Math.PI / 180;
178
+ args = size * (1 - .65 * Math.sin(a1_c23y)), a1_c23y = -size * (.95 - .65 * Math.cos(a1_c23y));
179
+ const c31x = -size * Math.sin(a2_c31y) / 2;
180
+ a2_c31y = size * Math.cos(a2_c31y) / 2;
181
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
182
+ return element.setAttribute("d", svgPath`M ${x} ${y + size} c ${.65 * size} 0 ${args} ${a1_c23y} ${size} ${.95 * -size} c ${c31x} ${a2_c31y} ${-size / 2} ${size * (.95 - 1)} ${-size} ${size * (.95 - 1)} z`),
183
+ element;
184
+ },
185
+ heart: args => {
186
+ const {size, x, y, document} = args;
187
+ return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", function(path, {x, y, size}) {
188
+ let move = !1, i = 0;
189
+ return path.map(v => "string" == typeof v ? (i = 0, move = v.toUpperCase() == v,
190
+ v) : (i++, v *= size, move && (v += i % 2 == 1 ? x : y), numToAttr(v))).join(" ");
191
+ }([ "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" ], {
437
192
  x,
438
193
  y,
439
- size,
440
- rotation
441
- });
442
- }
443
- drawOutpoint({x, y, size, rotation}) {
444
- this.basicInpoint({
194
+ size
195
+ })), args;
196
+ },
197
+ rounded: args => {
198
+ const {size, x, y, document} = args;
199
+ return (args = document.createElementNS("http://www.w3.org/2000/svg", "rect")).setAttribute("x", numToAttr(x)),
200
+ args.setAttribute("y", numToAttr(y)), args.setAttribute("width", numToAttr(size)),
201
+ args.setAttribute("height", numToAttr(size)), args.setAttribute("rx", numToAttr(size / 4)),
202
+ args.setAttribute("ry", numToAttr(size / 4)), args;
203
+ },
204
+ classy: args => {
205
+ const {size, x, y, document} = args;
206
+ args = size / 7;
207
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
208
+ 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`),
209
+ element;
210
+ },
211
+ inpoint: args => {
212
+ const {size, x, y, document} = args;
213
+ 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`),
214
+ args;
215
+ },
216
+ star: (args, {spikes = 5, outerRadius = args.size / 2, innerRadius = args.size / 4} = {}) => {
217
+ const {size, x, y, document} = args, cx = x + size / 2, cy = y + size / 2, angle = Math.PI / spikes;
218
+ return (args = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("d", Array(2 * spikes).fill(0).map((__radius, i) => svgPath`${0 === i ? "M" : "L"} ${cx + (__radius = i % 2 == 0 ? outerRadius : innerRadius) * Math.sin(i * angle)} ${cy - __radius * Math.cos(i * angle)}`).join(" ")),
219
+ args;
220
+ },
221
+ weave: args => {
222
+ const {size, x, y, document} = args, notch = (size - (args = .6 * size)) / 2, element = document.createElementNS("http://www.w3.org/2000/svg", "path");
223
+ return element.setAttribute("d", svgPath`M ${x + notch} ${y} l ${args} 0 l 0 ${notch} l ${notch} 0 l 0 ${args} l ${-notch} 0 l 0 ${notch} l ${-args} 0 l 0 ${-notch} l ${-notch} 0 l 0 ${-args} l ${notch} 0 z`),
224
+ element;
225
+ }
226
+ }, qrCornerDotFigures = {
227
+ [CornerDotType.dot]: args => rotateFigure({
228
+ ...args,
229
+ draw: DotElements.dot
230
+ }),
231
+ [CornerDotType.square]: args => rotateFigure({
232
+ ...args,
233
+ draw: DotElements.square
234
+ }),
235
+ [CornerDotType.heart]: args => DotElements.heart(args),
236
+ [CornerDotType.extraRounded]: args => rotateFigure({
237
+ ...args,
238
+ draw: DotElements.rounded
239
+ }),
240
+ [CornerDotType.classy]: args => rotateFigure({
241
+ ...args,
242
+ draw: DotElements.classy
243
+ }),
244
+ [CornerDotType.inpoint]: args => rotateFigure({
245
+ ...args,
246
+ draw: DotElements.inpoint
247
+ }),
248
+ [CornerDotType.outpoint]: args => rotateFigure({
249
+ ...args,
250
+ rotation: (args.rotation || 0) + Math.PI,
251
+ draw: DotElements.inpoint
252
+ }),
253
+ [CornerDotType.star]: args => DotElements.star(args),
254
+ [CornerDotType.pentagon]: args => DotElements.star(args, {
255
+ spikes: 2.5,
256
+ outerRadius: args.size / 2,
257
+ innerRadius: args.size / 2
258
+ }),
259
+ [CornerDotType.hexagon]: args => DotElements.star(args, {
260
+ spikes: 3,
261
+ outerRadius: args.size / 2,
262
+ innerRadius: args.size / 2
263
+ }),
264
+ [CornerDotType.diamond]: args => rotateFigure({
265
+ ...args,
266
+ rotation: Math.PI / 4,
267
+ draw: args2 => DotElements.square(args2, {
268
+ width: .85 * args2.size,
269
+ height: .85 * args2.size
270
+ })
271
+ })
272
+ }, SquareElements = {
273
+ dot: args => {
274
+ const {size, x, y, document} = args;
275
+ args = size / 7;
276
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
277
+ 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`);
278
+ const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
279
+ 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`),
280
+ [ element, fill ];
281
+ },
282
+ square: args => {
283
+ const {size, x, y, document} = args;
284
+ args = size / 7;
285
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
286
+ 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`);
287
+ const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
288
+ 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`),
289
+ [ element, fill ];
290
+ },
291
+ extraRounded: args => {
292
+ const {size, x, y, document} = args;
293
+ args = size / 7;
294
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
295
+ 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`);
296
+ const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
297
+ 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`),
298
+ [ element, fill ];
299
+ },
300
+ classy: args => {
301
+ const {size, x, y, document} = args;
302
+ args = size / 7;
303
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
304
+ 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`);
305
+ const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
306
+ 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`),
307
+ [ element, fill ];
308
+ },
309
+ inpoint: args => {
310
+ const {size, x, y, document} = args;
311
+ args = size / 7;
312
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
313
+ 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`);
314
+ const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
315
+ 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`),
316
+ [ element, fill ];
317
+ },
318
+ centerCircle: args => {
319
+ const {x, y, size} = args;
320
+ var circleRadius_fill = size / 2.5;
321
+ const cx = x + size / 2, cy = y + size / 2;
322
+ args = size / 7;
323
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
324
+ return element.setAttribute("clip-rule", "evenodd"), element.setAttribute("d", svgPath`M ${x} ${y} h ${size} v ${size} h ${-size} z M ${cx - circleRadius_fill} ${cy} a ${circleRadius_fill} ${circleRadius_fill} 0 1 0 ${2 * circleRadius_fill} 0 a ${circleRadius_fill} ${circleRadius_fill} 0 1 0 ${2 * -circleRadius_fill} 0 z`),
325
+ (circleRadius_fill = document.createElementNS("http://www.w3.org/2000/svg", "path")).setAttribute("clip-rule", "evenodd"),
326
+ circleRadius_fill.setAttribute("d", svgPath`M ${x - args} ${y - args} h ${size + 2 * args} v ${size + 2 * args} h ${-size - 2 * args} z`),
327
+ [ element, circleRadius_fill ];
328
+ },
329
+ cornerCut: args => {
330
+ const {x, y, size} = args;
331
+ args = size / 8;
332
+ const element = document.createElementNS("http://www.w3.org/2000/svg", "path");
333
+ element.setAttribute("clip-rule", "evenodd"), element.setAttribute("d", `M ${x} ${y} L ${x + size} ${y} L ${x + size} ${y + size - args} Q ${x + size} ${y + size} ${x + size - args} ${y + size} L ${x + args} ${y + size} Q ${x} ${y + size - args} ${x} ${y + size - args} Z M ${x + args} ${y + args} L ${x + size - args} ${y + args} L ${x + size - args} ${y + size - args} L ${x + args} ${y + size - args} Z`);
334
+ const fill = document.createElementNS("http://www.w3.org/2000/svg", "path");
335
+ 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`),
336
+ [ element, fill ];
337
+ }
338
+ }, qrCornerSquareFigures = {
339
+ [CornerSquareType.dot]: args => SquareElements.dot(args),
340
+ [CornerSquareType.square]: args => SquareElements.square(args),
341
+ [CornerSquareType.extraRounded]: args => SquareElements.extraRounded(args),
342
+ [CornerSquareType.classy]: args => rotateFigure({
343
+ ...args,
344
+ draw: SquareElements.classy
345
+ }),
346
+ [CornerSquareType.inpoint]: args => rotateFigure({
347
+ ...args,
348
+ draw: SquareElements.inpoint
349
+ }),
350
+ [CornerSquareType.outpoint]: ({rotation, ...args}) => rotateFigure({
351
+ ...args,
352
+ rotation: (rotation || 0) + Math.PI,
353
+ draw: SquareElements.inpoint
354
+ }),
355
+ [CornerSquareType.centerCircle]: args => SquareElements.centerCircle(args)
356
+ }, compoundDots_rounded = ({x, y, size, document, getNeighbor: bottomNeighbor_getNeighbor}, {corner: corner_rotation = DotElements.cornerRounded, end = DotElements.sideRounded} = {}) => {
357
+ const leftNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, -1) : 0, neighborsCount = leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor_getNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, 1) : 0);
358
+ return 0 === neighborsCount ? DotElements.dot({
359
+ x,
360
+ y,
361
+ size,
362
+ document
363
+ }) : neighborsCount > 2 || leftNeighbor && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ? DotElements.square({
364
+ x,
365
+ y,
366
+ size,
367
+ document
368
+ }) : 2 === neighborsCount ? (end = 0, leftNeighbor && topNeighbor ? end = Math.PI / 2 : topNeighbor && rightNeighbor ? end = Math.PI : rightNeighbor && bottomNeighbor_getNeighbor && (end = -Math.PI / 2),
369
+ rotateFigure({
370
+ x,
371
+ y,
372
+ size,
373
+ rotation: end,
374
+ document,
375
+ draw: corner_rotation
376
+ })) : (corner_rotation = 0, topNeighbor ? corner_rotation = Math.PI / 2 : rightNeighbor ? corner_rotation = Math.PI : bottomNeighbor_getNeighbor && (corner_rotation = -Math.PI / 2),
377
+ rotateFigure({
378
+ x,
379
+ y,
380
+ size,
381
+ rotation: corner_rotation,
382
+ document,
383
+ draw: end
384
+ }));
385
+ }, compoundDots_classy = ({x, y, size, document, getNeighbor: bottomNeighbor}, {corner = DotElements.cornerRounded} = {}) => {
386
+ const leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
387
+ return leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? rotateFigure({
388
+ x,
389
+ y,
390
+ size,
391
+ rotation: Math.PI / 2,
392
+ document,
393
+ draw: DotElements.cornersRounded
394
+ }) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? DotElements.square({
395
+ x,
396
+ y,
397
+ size,
398
+ document
399
+ }) : rotateFigure({
400
+ x,
401
+ y,
402
+ size,
403
+ rotation: Math.PI / 2,
404
+ document,
405
+ draw: corner
406
+ }) : rotateFigure({
407
+ x,
408
+ y,
409
+ size,
410
+ rotation: -Math.PI / 2,
411
+ document,
412
+ draw: corner
413
+ });
414
+ }, compoundDots_line = ({x, y, size, document, getNeighbor: bottomNeighbor}, {stripe = size, rotation = 0} = {}) => {
415
+ const topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
416
+ return bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0, topNeighbor && bottomNeighbor ? rotateFigure({
417
+ x,
418
+ y,
419
+ size,
420
+ rotation,
421
+ document,
422
+ draw: () => DotElements.square({
445
423
  x,
446
424
  y,
447
425
  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
- case DotType.wave:
511
- drawFunction = this.drawWave;
512
- break;
426
+ document
427
+ }, {
428
+ width: stripe
429
+ })
430
+ }) : topNeighbor && !bottomNeighbor ? (rotation += Math.PI / 2, rotateFigure({
431
+ x,
432
+ y,
433
+ size,
434
+ rotation,
435
+ document,
436
+ draw: args => DotElements.sideRounded(args, {
437
+ height: stripe
438
+ })
439
+ })) : bottomNeighbor && !topNeighbor ? (rotation -= Math.PI / 2, rotateFigure({
440
+ x,
441
+ y,
442
+ size,
443
+ rotation,
444
+ document,
445
+ draw: args => DotElements.sideRounded(args, {
446
+ height: stripe
447
+ })
448
+ })) : rotateFigure({
449
+ x,
450
+ y,
451
+ size,
452
+ rotation,
453
+ document,
454
+ draw: () => DotElements.dot({
455
+ x: x + (size - stripe) / 2,
456
+ y: y + (size - stripe) / 2,
457
+ size: stripe,
458
+ document
459
+ })
460
+ });
461
+ }, qrDotFigures = {
462
+ [DotType.dot]: args => DotElements.dot(args),
463
+ [DotType.randomDot]: ({size, ...args}) => DotElements.dot({
464
+ ...args,
465
+ size: size * (.25 * Math.random() + .75)
466
+ }),
467
+ [DotType.rounded]: args => compoundDots_rounded(args),
468
+ [DotType.extraRounded]: args => compoundDots_rounded(args, {
469
+ corner: DotElements.cornerExtraRounded
470
+ }),
471
+ [DotType.verticalLine]: args => compoundDots_line(args),
472
+ [DotType.horizontalLine]: ({getNeighbor, ...args}) => compoundDots_line({
473
+ ...args,
474
+ getNeighbor: getNeighbor ? (x, y) => getNeighbor(y, x) : void 0
475
+ }, {
476
+ rotation: -Math.PI / 2
477
+ }),
478
+ [DotType.classy]: args => compoundDots_classy(args),
479
+ [DotType.classyRounded]: args => compoundDots_classy(args, {
480
+ corner: DotElements.cornerExtraRounded
481
+ }),
482
+ [DotType.square]: args => DotElements.square(args),
483
+ [DotType.smallSquare]: ({x, y, size, document}) => DotElements.square({
484
+ x: x += .15 * size,
485
+ y: y += .15 * size,
486
+ size: size = .7 * size,
487
+ document
488
+ }),
489
+ [DotType.tinySquare]: ({x, y, size, document}) => DotElements.square({
490
+ x: x += .35 * size,
491
+ y: y += .35 * size,
492
+ size: size = .3 * size,
493
+ document
494
+ }),
495
+ [DotType.diamond]: args => rotateFigure({
496
+ ...args,
497
+ rotation: Math.PI / 4,
498
+ draw: args2 => DotElements.square(args2, {
499
+ width: .85 * args2.size,
500
+ height: .85 * args2.size
501
+ })
502
+ }),
503
+ [DotType.wave]: args => compoundDots_rounded(args, {
504
+ corner: DotElements.cornerExtraRounded,
505
+ end: DotElements.wave
506
+ }),
507
+ [DotType.heart]: args => DotElements.heart(args),
508
+ [DotType.star]: args => DotElements.star(args),
509
+ [DotType.weave]: args => DotElements.weave(args),
510
+ [DotType.pentagon]: args => DotElements.star(args, {
511
+ spikes: 2.5,
512
+ outerRadius: args.size / 2,
513
+ innerRadius: args.size / 2
514
+ }),
515
+ [DotType.hexagon]: args => DotElements.star(args, {
516
+ spikes: 3,
517
+ outerRadius: args.size / 2,
518
+ innerRadius: args.size / 2
519
+ }),
520
+ [DotType.zebraVertical]: args => compoundDots_line(args, {
521
+ stripe: .8 * args.size
522
+ }),
523
+ [DotType.zebraHorizontal]: ({getNeighbor, ...args}) => compoundDots_line({
524
+ ...args,
525
+ getNeighbor: getNeighbor ? (x, y) => getNeighbor(y, x) : void 0
526
+ }, {
527
+ stripe: .8 * args.size,
528
+ rotation: -Math.PI / 2
529
+ })
530
+ };
513
531
 
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({
638
- x,
639
- y,
640
- size,
641
- rotation: Math.PI / 4
642
- });
643
- }
644
- drawRounded({x, y, size, getNeighbor: bottomNeighbor_getNeighbor}) {
645
- var leftNeighbor_rotation = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(-1, 0) : 0;
646
- let rightNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, -1) : 0;
647
- var neighborsCount_rotation = leftNeighbor_rotation + rightNeighbor + topNeighbor + (bottomNeighbor_getNeighbor = bottomNeighbor_getNeighbor ? +bottomNeighbor_getNeighbor(0, 1) : 0);
648
- 0 === neighborsCount_rotation ? this.basicDot({
649
- x,
650
- y,
651
- size,
652
- rotation: 0
653
- }) : neighborsCount_rotation > 2 || leftNeighbor_rotation && rightNeighbor || topNeighbor && bottomNeighbor_getNeighbor ? this.basicSquare({
654
- x,
655
- y,
656
- size,
657
- rotation: 0
658
- }) : 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
- this.basicCornerRounded({
660
- x,
661
- y,
662
- size,
663
- rotation: neighborsCount_rotation
664
- })) : 1 === neighborsCount_rotation && (leftNeighbor_rotation = 0, topNeighbor ? leftNeighbor_rotation = Math.PI / 2 : rightNeighbor ? leftNeighbor_rotation = Math.PI : bottomNeighbor_getNeighbor && (leftNeighbor_rotation = -Math.PI / 2),
665
- this.basicSideRounded({
666
- x,
667
- y,
668
- size,
669
- rotation: leftNeighbor_rotation
670
- }));
671
- }
672
- drawVerticalLine({x, y, size, getNeighbor: bottomNeighbor}) {
673
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
674
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || leftNeighbor && !topNeighbor && !bottomNeighbor || rightNeighbor && !topNeighbor && !bottomNeighbor ? this.basicDot({
675
- x,
676
- y,
677
- size,
678
- rotation: 0
679
- }) : topNeighbor && bottomNeighbor ? this.basicSquare({
680
- x,
681
- y,
682
- size,
683
- rotation: 0
684
- }) : topNeighbor && !bottomNeighbor ? this.basicSideRounded({
685
- x,
686
- y,
687
- size,
688
- rotation: Math.PI / 2
689
- }) : bottomNeighbor && !topNeighbor && this.basicSideRounded({
690
- x,
691
- y,
692
- size,
693
- rotation: -Math.PI / 2
694
- });
695
- }
696
- drawHorizontalLine({x, y, size, getNeighbor: bottomNeighbor}) {
697
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
698
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 || topNeighbor && !leftNeighbor && !rightNeighbor || bottomNeighbor && !leftNeighbor && !rightNeighbor ? this.basicDot({
699
- x,
700
- y,
701
- size,
702
- rotation: 0
703
- }) : leftNeighbor && rightNeighbor ? this.basicSquare({
704
- x,
705
- y,
706
- size,
707
- rotation: 0
708
- }) : leftNeighbor && !rightNeighbor ? this.basicSideRounded({
709
- x,
710
- y,
711
- size,
712
- rotation: 0
713
- }) : rightNeighbor && !leftNeighbor && this.basicSideRounded({
714
- x,
715
- y,
716
- size,
717
- rotation: Math.PI
718
- });
719
- }
720
- drawExtraRounded({x, y, size, getNeighbor: bottomNeighbor}) {
721
- var leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0;
722
- let rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
723
- var neighborsCount = leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0);
724
- 0 === neighborsCount ? this.basicDot({
725
- x,
726
- y,
727
- size,
728
- rotation: 0
729
- }) : neighborsCount > 2 || leftNeighbor && rightNeighbor || topNeighbor && bottomNeighbor ? this.basicSquare({
730
- x,
731
- y,
732
- size,
733
- rotation: 0
734
- }) : 2 === neighborsCount ? (neighborsCount = 0, leftNeighbor && topNeighbor ? neighborsCount = Math.PI / 2 : topNeighbor && rightNeighbor ? neighborsCount = Math.PI : rightNeighbor && bottomNeighbor && (neighborsCount = -Math.PI / 2),
735
- this.basicCornerExtraRounded({
736
- x,
737
- y,
738
- size,
739
- rotation: neighborsCount
740
- })) : 1 === neighborsCount && (leftNeighbor = 0, topNeighbor ? leftNeighbor = Math.PI / 2 : rightNeighbor ? leftNeighbor = Math.PI : bottomNeighbor && (leftNeighbor = -Math.PI / 2),
741
- this.basicSideRounded({
742
- x,
743
- y,
744
- size,
745
- rotation: leftNeighbor
746
- }));
747
- }
748
- drawClassy({x, y, size, getNeighbor: bottomNeighbor}) {
749
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
750
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
751
- x,
752
- y,
753
- size,
754
- rotation: Math.PI / 2
755
- }) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? this.basicSquare({
756
- x,
757
- y,
758
- size,
759
- rotation: 0
760
- }) : this.basicCornerRounded({
761
- x,
762
- y,
763
- size,
764
- rotation: Math.PI / 2
765
- }) : this.basicCornerRounded({
766
- x,
767
- y,
768
- size,
769
- rotation: -Math.PI / 2
770
- });
771
- }
772
- drawClassyRounded({x, y, size, getNeighbor: bottomNeighbor}) {
773
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0, topNeighbor = bottomNeighbor ? +bottomNeighbor(0, -1) : 0;
774
- leftNeighbor + rightNeighbor + topNeighbor + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0) === 0 ? this.basicCornersRounded({
775
- x,
776
- y,
777
- size,
778
- rotation: Math.PI / 2
779
- }) : leftNeighbor || topNeighbor ? rightNeighbor || bottomNeighbor ? this.basicSquare({
780
- x,
781
- y,
782
- size,
783
- rotation: 0
784
- }) : this.basicCornerExtraRounded({
785
- x,
786
- y,
787
- size,
788
- rotation: Math.PI / 2
789
- }) : this.basicCornerExtraRounded({
790
- x,
791
- y,
792
- size,
793
- rotation: -Math.PI / 2
794
- });
795
- }
796
- drawWave({x, y, size, getNeighbor: bottomNeighbor}) {
797
- let leftNeighbor = bottomNeighbor ? +bottomNeighbor(-1, 0) : 0, rightNeighbor = bottomNeighbor ? +bottomNeighbor(1, 0) : 0;
798
- var rotation = bottomNeighbor ? +bottomNeighbor(0, -1) : 0, neighborsCount = leftNeighbor + rightNeighbor + rotation + (bottomNeighbor = bottomNeighbor ? +bottomNeighbor(0, 1) : 0);
799
- 0 === neighborsCount ? this.basicDot({
800
- x,
801
- y,
802
- size,
803
- rotation: 0
804
- }) : neighborsCount > 2 || leftNeighbor && rightNeighbor || rotation && bottomNeighbor ? this.basicSquare({
805
- x,
806
- y,
807
- size,
808
- rotation: 0
809
- }) : 2 === neighborsCount ? (neighborsCount = 0, leftNeighbor && rotation ? neighborsCount = Math.PI / 2 : rotation && rightNeighbor ? neighborsCount = Math.PI : rightNeighbor && bottomNeighbor && (neighborsCount = -Math.PI / 2),
810
- this.basicCornerExtraRounded({
811
- x,
812
- y,
813
- size,
814
- rotation: neighborsCount
815
- })) : 1 === neighborsCount && (rotation = 0, rightNeighbor ? rotation = Math.PI / 2 : bottomNeighbor ? rotation = Math.PI : leftNeighbor && (rotation = -Math.PI / 2),
816
- this.basicWave({
817
- x,
818
- y,
819
- size,
820
- rotation
821
- }));
822
- }
532
+ function getQrDotFigure(type) {
533
+ return qrDotFigures[type] || qrDotFigures[DotType.square];
823
534
  }
824
535
 
825
536
  let browserImageTools = {
@@ -1014,7 +725,7 @@ class QRSVG {
1014
725
  var minSize_xFakeBeginning = Math.min(options.width, options.height);
1015
726
  options.imageOptions.mode == ImageMode.background && (minSize_xFakeBeginning -= 2 * dotSize * (options.imageOptions.margin || 0));
1016
727
  var colorCount_xBeginning = Math.floor((options.width - count * dotSize) / 2), yBeginning_yFakeBeginning = Math.floor((options.height - count * dotSize) / 2);
1017
- let dot = new QRDot(options.dotsOptions.type, this.document), overlayDot = new QRDot(DotType.tinySquare, this.document), markerDot = new QRDot(DotType.square, this.document);
728
+ let draw = getQrDotFigure(options.dotsOptions.type);
1018
729
  [this.dotsMask, this.dotsMaskGroup] = this.createMask("mask-dot-color"), this.defs.appendChild(this.dotsMask),
1019
730
  options.imageOptions.mode == ImageMode.background && ([this.lightDotsMask, this.lightDotsMaskGroup] = this.createMask("mask-light-dot-color"),
1020
731
  this.defs.appendChild(this.lightDotsMask));
@@ -1038,18 +749,20 @@ class QRSVG {
1038
749
  for (let i = 0; i < fakeCount_margin; i++) {
1039
750
  count = alignment.find(v => i - additionalDots > v - 3 && i - additionalDots < v + 3);
1040
751
  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 && (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),
1042
- fakeMatrix[i][j] ? (dot.draw({
752
+ 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)),
753
+ fakeMatrix[i][j] ? this.dotsMaskGroup && this.dotsMaskGroup.appendChild(draw({
1043
754
  x: minSize_xFakeBeginning + i * dotSize,
1044
755
  y: yBeginning_yFakeBeginning + j * dotSize,
1045
756
  size: dotSize,
757
+ document: this.options.document,
1046
758
  getNeighbor: (xOffset, yOffset) => !0 === fakeMatrix[i + xOffset]?.[j + yOffset]
1047
- }), dot.element && this.dotsMaskGroup && this.dotsMaskGroup.appendChild(dot.element)) : this.lightDotsMask && (dot.draw({
759
+ })) : this.lightDotsMask && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(draw({
1048
760
  x: minSize_xFakeBeginning + i * dotSize,
1049
761
  y: yBeginning_yFakeBeginning + j * dotSize,
1050
762
  size: dotSize,
763
+ document: this.options.document,
1051
764
  getNeighbor: (xOffset, yOffset) => !1 === fakeMatrix[i + xOffset]?.[j + yOffset]
1052
- }), dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(dot.element)));
765
+ })));
1053
766
  }
1054
767
  this.lightDotsMask && this.createColor({
1055
768
  options: options.imageOptions.fill.gradient,
@@ -1076,73 +789,82 @@ class QRSVG {
1076
789
  let options = this.options;
1077
790
  if (!this._element) throw Error("Element code is not defined");
1078
791
  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(([column_cornersDot, row, dot]) => {
1080
- let x = xBeginning + column_cornersDot * dotSize * (count - 7), y = yBeginning + row * dotSize * (count - 7);
792
+ [ [ 0, 0, 0 ], [ 1, 0, Math.PI / 2 ], [ 0, 1, -Math.PI / 2 ] ].forEach(([column_draw, row, draw]) => {
793
+ let x = xBeginning + column_draw * dotSize * (count - 7), y = yBeginning + row * dotSize * (count - 7);
1081
794
  var cornersDotMaskGroup_cornersSquareMask = this.dotsMask;
1082
795
  let cornersSquareMaskGroup = this.dotsMaskGroup;
1083
- var val, cornersDotMask_cornersSquare_dot = this.dotsMask;
1084
- if (cornersDotMaskGroup_cornersSquareMask = this.dotsMaskGroup, (options.cornersSquareOptions?.gradient || options.cornersSquareOptions?.color) && ([cornersDotMaskGroup_cornersSquareMask, cornersSquareMaskGroup] = this.createMask(`mask-corners-square-color-${column_cornersDot}-${row}`),
1085
- this.defs.appendChild(cornersDotMaskGroup_cornersSquareMask), cornersDotMask_cornersSquare_dot = cornersDotMaskGroup_cornersSquareMask,
796
+ var val, cornersDotMask_draw = this.dotsMask;
797
+ if (cornersDotMaskGroup_cornersSquareMask = this.dotsMaskGroup, (options.cornersSquareOptions?.gradient || options.cornersSquareOptions?.color) && ([cornersDotMaskGroup_cornersSquareMask, cornersSquareMaskGroup] = this.createMask(`mask-corners-square-color-${column_draw}-${row}`),
798
+ this.defs.appendChild(cornersDotMaskGroup_cornersSquareMask), cornersDotMask_draw = cornersDotMaskGroup_cornersSquareMask,
1086
799
  cornersDotMaskGroup_cornersSquareMask = cornersSquareMaskGroup, this.createColor({
1087
800
  options: options.cornersSquareOptions?.gradient,
1088
801
  color: options.cornersSquareOptions?.color,
1089
- additionalRotation: dot,
802
+ additionalRotation: draw,
1090
803
  x,
1091
804
  y,
1092
805
  height: cornersSquareSize,
1093
806
  width: cornersSquareSize,
1094
- name: `corners-square-color-${column_cornersDot}-${row}`
1095
- })), val = options.cornersSquareOptions?.type, val && cornerSquareTypes.has(val)) (cornersDotMask_cornersSquare_dot = new QRCornerSquare(options.cornersSquareOptions.type, this.document)).draw({
1096
- x,
1097
- y,
1098
- size: cornersSquareSize,
1099
- rotation: dot
1100
- }), cornersDotMask_cornersSquare_dot.element && cornersSquareMaskGroup && cornersSquareMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element),
1101
- cornersDotMask_cornersSquare_dot.fill && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.fill); else {
1102
- cornersDotMask_cornersSquare_dot = new QRDot(options.cornersSquareOptions?.type || options.dotsOptions.type, this.document);
1103
- for (let i = 0; i < squareMask.length; i++) for (let j = 0; j < squareMask[i].length; j++) squareMask[i]?.[j] ? (cornersDotMask_cornersSquare_dot.draw({
807
+ name: `corners-square-color-${column_draw}-${row}`
808
+ })), val = options.cornersSquareOptions?.type, val && cornerSquareTypes.has(val)) {
809
+ let [cornerElement, cornerFill] = (qrCornerSquareFigures[options.cornersSquareOptions.type] || qrCornerSquareFigures[CornerSquareType.square])({
810
+ x,
811
+ y,
812
+ size: cornersSquareSize,
813
+ document: this.options.document,
814
+ rotation: draw
815
+ });
816
+ cornersSquareMaskGroup && cornersSquareMaskGroup.appendChild(cornerElement), this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornerFill);
817
+ } else {
818
+ cornersDotMask_draw = getQrDotFigure(options.cornersSquareOptions?.type || options.dotsOptions.type);
819
+ 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
820
  x: x + i * dotSize,
1105
821
  y: y + j * dotSize,
1106
822
  size: dotSize,
823
+ document: this.options.document,
1107
824
  getNeighbor: (xOffset, yOffset) => !!squareMask[i + xOffset]?.[j + yOffset]
1108
- }), cornersDotMask_cornersSquare_dot.element && cornersSquareMaskGroup && cornersSquareMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element)) : this.lightDotsMask && !dotMask[i]?.[j] && (cornersDotMask_cornersSquare_dot.draw({
825
+ })) : this.lightDotsMask && !dotMask[i]?.[j] && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_draw({
1109
826
  x: x + i * dotSize,
1110
827
  y: y + j * dotSize,
1111
828
  size: dotSize,
829
+ document: this.options.document,
1112
830
  getNeighbor: (xOffset, yOffset) => !squareMask[i + xOffset]?.[j + yOffset] && !dotMask[i + xOffset]?.[j + yOffset]
1113
- }), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
1114
- 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({
831
+ }));
832
+ 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
833
  x: x + i * dotSize,
1116
834
  y: y + j * dotSize,
1117
835
  size: dotSize,
836
+ document: this.options.document,
1118
837
  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
- }), cornersDotMask_cornersSquare_dot.element && this.lightDotsMaskGroup && this.lightDotsMaskGroup.appendChild(cornersDotMask_cornersSquare_dot.element));
838
+ }));
1120
839
  }
1121
- if ((options.cornersDotOptions?.gradient || options.cornersDotOptions?.color) && ([cornersDotMask_cornersSquare_dot, cornersDotMaskGroup_cornersSquareMask] = this.createMask(`mask-corners-dot-color-${column_cornersDot}-${row}`),
1122
- this.defs.appendChild(cornersDotMask_cornersSquare_dot), this.createColor({
840
+ if ((options.cornersDotOptions?.gradient || options.cornersDotOptions?.color) && ([cornersDotMask_draw, cornersDotMaskGroup_cornersSquareMask] = this.createMask(`mask-corners-dot-color-${column_draw}-${row}`),
841
+ this.defs.appendChild(cornersDotMask_draw), this.createColor({
1123
842
  options: options.cornersDotOptions?.gradient,
1124
843
  color: options.cornersDotOptions?.color,
1125
- additionalRotation: dot,
844
+ additionalRotation: draw,
1126
845
  x: x + 2 * dotSize,
1127
846
  y: y + 2 * dotSize,
1128
847
  height: cornersDotSize,
1129
848
  width: cornersDotSize,
1130
- name: `corners-dot-color-${column_cornersDot}-${row}`
849
+ name: `corners-dot-color-${column_draw}-${row}`
1131
850
  })), function(val) {
1132
851
  return !(!val || !cornerDotTypes.has(val));
1133
- }(options.cornersDotOptions?.type)) (column_cornersDot = new QRCornerDot(options.cornersDotOptions.type, this.document)).draw({
852
+ }(options.cornersDotOptions?.type)) column_draw = qrCornerDotFigures[options.cornersDotOptions.type] || qrCornerDotFigures[CornerDotType.square],
853
+ cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(column_draw({
1134
854
  x: x + 2 * dotSize,
1135
855
  y: y + 2 * dotSize,
1136
856
  size: cornersDotSize,
1137
- rotation: dot
1138
- }), column_cornersDot.element && cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(column_cornersDot.element); else {
1139
- dot = new QRDot(options.cornersDotOptions?.type || options.dotsOptions.type, this.document);
1140
- for (let i = 0; i < dotMask.length; i++) for (let j = 0; j < dotMask[i].length; j++) dotMask[i]?.[j] && (dot.draw({
857
+ document: this.document,
858
+ rotation: draw
859
+ })); else {
860
+ draw = getQrDotFigure(options.cornersDotOptions?.type || options.dotsOptions.type);
861
+ 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
862
  x: x + i * dotSize,
1142
863
  y: y + j * dotSize,
1143
864
  size: dotSize,
865
+ document: this.options.document,
1144
866
  getNeighbor: (xOffset, yOffset) => !!dotMask[i + xOffset]?.[j + yOffset]
1145
- }), dot.element && cornersDotMaskGroup_cornersSquareMask && cornersDotMaskGroup_cornersSquareMask.appendChild(dot.element));
867
+ }));
1146
868
  }
1147
869
  });
1148
870
  }
@@ -1163,7 +885,9 @@ class QRSVG {
1163
885
  this._element.appendChild(image);
1164
886
  }
1165
887
  createColor({options, color, additionalRotation: additionalRotation_positiveRotation, x, y, height, width, name}) {
1166
- var size = width > height ? width : height;
888
+ var gradientSize_x0 = width > height ? width : height;
889
+ x -= this.options.dotsOptions.size, y -= this.options.dotsOptions.size, width += 2 * this.options.dotsOptions.size,
890
+ height += 2 * this.options.dotsOptions.size;
1167
891
  let rect = this.document.createElementNS("http://www.w3.org/2000/svg", "rect");
1168
892
  if (rect.setAttribute("x", numToAttr(x)), rect.setAttribute("y", numToAttr(y)),
1169
893
  rect.setAttribute("height", numToAttr(height)), rect.setAttribute("width", numToAttr(width)),
@@ -1173,17 +897,17 @@ class QRSVG {
1173
897
  gradient.setAttribute("id", name), gradient.setAttribute("gradientUnits", "userSpaceOnUse"),
1174
898
  gradient.setAttribute("fx", numToAttr(x + width / 2)), gradient.setAttribute("fy", numToAttr(y + height / 2)),
1175
899
  gradient.setAttribute("cx", numToAttr(x + width / 2)), gradient.setAttribute("cy", numToAttr(y + height / 2)),
1176
- gradient.setAttribute("r", numToAttr(size / 2)); else {
1177
- size = x + width / 2;
900
+ gradient.setAttribute("r", numToAttr(gradientSize_x0 / 2)); else {
901
+ gradientSize_x0 = x + width / 2;
1178
902
  let y0 = y + height / 2;
1179
- x += width / 2, y += height / 2, (additionalRotation_positiveRotation = ((color = ((options.rotation || 0) + additionalRotation_positiveRotation) % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI)) >= 0 && additionalRotation_positiveRotation <= .25 * Math.PI || additionalRotation_positiveRotation > 1.75 * Math.PI && additionalRotation_positiveRotation <= 2 * Math.PI ? (size -= width / 2,
903
+ x += width / 2, y += height / 2, (additionalRotation_positiveRotation = ((color = ((options.rotation || 0) + additionalRotation_positiveRotation) % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI)) >= 0 && additionalRotation_positiveRotation <= .25 * Math.PI || additionalRotation_positiveRotation > 1.75 * Math.PI && additionalRotation_positiveRotation <= 2 * Math.PI ? (gradientSize_x0 -= width / 2,
1180
904
  y0 -= height / 2 * Math.tan(color), x += width / 2, y += height / 2 * Math.tan(color)) : additionalRotation_positiveRotation > .25 * Math.PI && additionalRotation_positiveRotation <= .75 * Math.PI ? (y0 -= height / 2,
1181
- size -= width / 2 / Math.tan(color), y += height / 2, x += width / 2 / Math.tan(color)) : additionalRotation_positiveRotation > .75 * Math.PI && additionalRotation_positiveRotation <= 1.25 * Math.PI ? (size += width / 2,
905
+ gradientSize_x0 -= width / 2 / Math.tan(color), y += height / 2, x += width / 2 / Math.tan(color)) : additionalRotation_positiveRotation > .75 * Math.PI && additionalRotation_positiveRotation <= 1.25 * Math.PI ? (gradientSize_x0 += width / 2,
1182
906
  y0 += height / 2 * Math.tan(color), x -= width / 2, y -= height / 2 * Math.tan(color)) : additionalRotation_positiveRotation > 1.25 * Math.PI && additionalRotation_positiveRotation <= 1.75 * Math.PI && (y0 += height / 2,
1183
- size += width / 2 / Math.tan(color), y -= height / 2, x -= width / 2 / Math.tan(color)),
907
+ gradientSize_x0 += width / 2 / Math.tan(color), y -= height / 2, x -= width / 2 / Math.tan(color)),
1184
908
  gradient = this.document.createElementNS("http://www.w3.org/2000/svg", "linearGradient"),
1185
909
  gradient.setAttribute("id", name), gradient.setAttribute("gradientUnits", "userSpaceOnUse"),
1186
- gradient.setAttribute("x1", numToAttr(size)), gradient.setAttribute("y1", numToAttr(y0)),
910
+ gradient.setAttribute("x1", numToAttr(gradientSize_x0)), gradient.setAttribute("y1", numToAttr(y0)),
1187
911
  gradient.setAttribute("x2", numToAttr(x)), gradient.setAttribute("y2", numToAttr(y));
1188
912
  }
1189
913
  options.colorStops.forEach(parsed_stopCfg => {