qrdx 0.0.2-beta.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4225 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/corner-dot.d.ts.map +1 -1
- package/dist/src/corner-eye.d.ts +1 -1
- package/dist/src/corner-eye.d.ts.map +1 -1
- package/dist/src/detection.d.ts.map +1 -1
- package/dist/src/download.d.ts +1 -1
- package/dist/src/download.d.ts.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/utils/color.d.ts +12 -0
- package/dist/src/utils/color.d.ts.map +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/types/color.d.ts +92 -0
- package/dist/types/color.d.ts.map +1 -0
- package/dist/types/corner-dot.d.ts +9 -2
- package/dist/types/corner-dot.d.ts.map +1 -1
- package/dist/types/corner-eye.d.ts +7 -2
- package/dist/types/corner-eye.d.ts.map +1 -1
- package/dist/types/image-pattern.d.ts +4 -3
- package/dist/types/image-pattern.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/qr.d.ts +90 -12
- package/dist/types/qr.d.ts.map +1 -1
- package/package.json +13 -8
- package/src/api.tsx +7 -2
- package/src/constants.ts +1 -1
- package/src/corner-dot.tsx +83 -2
- package/src/corner-eye.ts +98 -5
- package/src/detection.ts +0 -3
- package/src/download.tsx +102 -2
- package/src/index.tsx +95 -29
- package/src/utils/color.ts +34 -0
- package/src/utils.tsx +550 -57
- package/types/color.ts +133 -0
- package/types/corner-dot.ts +8 -1
- package/types/corner-eye.ts +5 -0
- package/types/image-pattern.ts +2 -1
- package/types/index.ts +23 -5
- package/types/qr.ts +9 -8
package/src/utils.tsx
CHANGED
|
@@ -3,11 +3,15 @@ import React from "react";
|
|
|
3
3
|
import type { TemplateConfig } from "@/types/template";
|
|
4
4
|
import type {
|
|
5
5
|
BodyPattern,
|
|
6
|
+
ColorConfig,
|
|
6
7
|
Excavation,
|
|
7
8
|
ImageSettings,
|
|
9
|
+
LinearGradient,
|
|
8
10
|
Modules,
|
|
9
11
|
QRPropsSVG,
|
|
12
|
+
RadialGradient,
|
|
10
13
|
} from "../types";
|
|
14
|
+
import { normalizeColorConfig } from "../types/color";
|
|
11
15
|
import qrcodegen from "./codegen";
|
|
12
16
|
import {
|
|
13
17
|
DEFAULT_BGCOLOR,
|
|
@@ -21,6 +25,7 @@ import {
|
|
|
21
25
|
import { generateCornerDotPath } from "./corner-dot";
|
|
22
26
|
import { generateCornerSquarePath } from "./corner-eye";
|
|
23
27
|
import { getTemplate } from "./templates";
|
|
28
|
+
import { getSolidColor } from "./utils/color";
|
|
24
29
|
|
|
25
30
|
// We could just do this in generatePath, except that we want to support
|
|
26
31
|
// non-Path2D canvas, so we need to keep it an explicit step.
|
|
@@ -153,7 +158,7 @@ function generateDataCircles(
|
|
|
153
158
|
}
|
|
154
159
|
break;
|
|
155
160
|
|
|
156
|
-
case "square":
|
|
161
|
+
case "small-square":
|
|
157
162
|
// Pattern 2: Squares
|
|
158
163
|
{
|
|
159
164
|
const halfSize = pixelSize * 0.357_143; // half of 71.4% pixel size
|
|
@@ -185,7 +190,7 @@ function generateDataCircles(
|
|
|
185
190
|
// Pattern 4: Circles with varying sizes
|
|
186
191
|
{
|
|
187
192
|
const randomFactor =
|
|
188
|
-
(x + y) % 3 === 0 ?
|
|
193
|
+
(x + y) % 3 === 0 ? 0.5 : (x + y) % 2 === 0 ? 1 : 1.25;
|
|
189
194
|
const variedRadius = radius * randomFactor;
|
|
190
195
|
shapes.push(
|
|
191
196
|
<circle
|
|
@@ -234,7 +239,7 @@ function generateDataCircles(
|
|
|
234
239
|
}
|
|
235
240
|
break;
|
|
236
241
|
|
|
237
|
-
case "
|
|
242
|
+
case "square":
|
|
238
243
|
// Pattern 12: Clean rectangles only
|
|
239
244
|
{
|
|
240
245
|
const halfSize = pixelSize * 0.5;
|
|
@@ -251,6 +256,21 @@ function generateDataCircles(
|
|
|
251
256
|
}
|
|
252
257
|
break;
|
|
253
258
|
|
|
259
|
+
case "vertical-line":
|
|
260
|
+
// Pattern: Horizontal lines
|
|
261
|
+
{
|
|
262
|
+
const lineHeight = pixelSize * 0.714_286; // ~71.4% height
|
|
263
|
+
const lineWidth = pixelSize; // full width
|
|
264
|
+
shapes.push(
|
|
265
|
+
<path
|
|
266
|
+
d={`M ${cx - pixelSize * 0.5} ${cy - lineHeight * 0.5}v ${lineHeight}h ${lineWidth}v -${lineHeight}z`}
|
|
267
|
+
key={key}
|
|
268
|
+
transform={`rotate(90,${cx},${cy})`}
|
|
269
|
+
/>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
break;
|
|
273
|
+
|
|
254
274
|
default:
|
|
255
275
|
// Default to circle
|
|
256
276
|
shapes.push(
|
|
@@ -270,6 +290,269 @@ function generateDataCircles(
|
|
|
270
290
|
return shapes;
|
|
271
291
|
}
|
|
272
292
|
|
|
293
|
+
// Helper to calculate gradient coordinates based on angle
|
|
294
|
+
function calculateGradientCoordinates(
|
|
295
|
+
angle: number,
|
|
296
|
+
size: number
|
|
297
|
+
): { x1: number; y1: number; x2: number; y2: number } {
|
|
298
|
+
// Convert angle to radians
|
|
299
|
+
const radians = (angle * Math.PI) / 180;
|
|
300
|
+
|
|
301
|
+
// Calculate center point
|
|
302
|
+
const centerX = size / 2;
|
|
303
|
+
const centerY = size / 2;
|
|
304
|
+
|
|
305
|
+
// Calculate vector length (half diagonal for maximum coverage)
|
|
306
|
+
const length = Math.sqrt(size * size + size * size) / 2;
|
|
307
|
+
|
|
308
|
+
// Calculate start and end points
|
|
309
|
+
const x1 = centerX - length * Math.cos(radians);
|
|
310
|
+
const y1 = centerY - length * Math.sin(radians);
|
|
311
|
+
const x2 = centerX + length * Math.cos(radians);
|
|
312
|
+
const y2 = centerY + length * Math.sin(radians);
|
|
313
|
+
|
|
314
|
+
return { x1, y1, x2, y2 };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Generate unique gradient ID
|
|
318
|
+
let gradientIdCounter = 0;
|
|
319
|
+
function generateGradientId(prefix: string): string {
|
|
320
|
+
gradientIdCounter += 1;
|
|
321
|
+
return `${prefix}-${Date.now()}-${gradientIdCounter}`;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Helper to calculate gradient coordinates for a corner based on corner position
|
|
325
|
+
/** biome-ignore lint: Function needs multiple parameters for corner-specific gradients */
|
|
326
|
+
function calculateCornerGradientCoordinates(
|
|
327
|
+
angle: number,
|
|
328
|
+
cornerX: number,
|
|
329
|
+
cornerY: number,
|
|
330
|
+
cornerSize: number,
|
|
331
|
+
cornerType: "top-left" | "top-right" | "bottom-left"
|
|
332
|
+
): { x1: number; y1: number; x2: number; y2: number } {
|
|
333
|
+
// Default angles for each corner if angle is 0
|
|
334
|
+
let effectiveAngle = angle;
|
|
335
|
+
if (angle === 0) {
|
|
336
|
+
switch (cornerType) {
|
|
337
|
+
case "top-left":
|
|
338
|
+
effectiveAngle = 0; // horizontal
|
|
339
|
+
break;
|
|
340
|
+
case "top-right":
|
|
341
|
+
effectiveAngle = 90; // vertical
|
|
342
|
+
break;
|
|
343
|
+
case "bottom-left":
|
|
344
|
+
effectiveAngle = 270; // vertical (bottom to top)
|
|
345
|
+
break;
|
|
346
|
+
default:
|
|
347
|
+
effectiveAngle = 0;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Convert angle to radians
|
|
352
|
+
const radians = (effectiveAngle * Math.PI) / 180;
|
|
353
|
+
|
|
354
|
+
// Calculate center point of the corner
|
|
355
|
+
const centerX = cornerX + cornerSize / 2;
|
|
356
|
+
const centerY = cornerY + cornerSize / 2;
|
|
357
|
+
|
|
358
|
+
// Calculate vector length (half diagonal for maximum coverage)
|
|
359
|
+
const length =
|
|
360
|
+
Math.sqrt(cornerSize * cornerSize + cornerSize * cornerSize) / 2;
|
|
361
|
+
|
|
362
|
+
// Calculate start and end points relative to corner position
|
|
363
|
+
const x1 = centerX - length * Math.cos(radians);
|
|
364
|
+
const y1 = centerY - length * Math.sin(radians);
|
|
365
|
+
const x2 = centerX + length * Math.cos(radians);
|
|
366
|
+
const y2 = centerY + length * Math.sin(radians);
|
|
367
|
+
|
|
368
|
+
return { x1, y1, x2, y2 };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Generate gradient definition elements for corners
|
|
372
|
+
// biome-ignore lint: Function needs multiple parameters for corner-specific gradients
|
|
373
|
+
function generateCornerGradientDef(
|
|
374
|
+
colorConfig: ColorConfig,
|
|
375
|
+
cornerX: number,
|
|
376
|
+
cornerY: number,
|
|
377
|
+
cornerSize: number,
|
|
378
|
+
cornerType: "top-left" | "top-right" | "bottom-left",
|
|
379
|
+
idPrefix: string
|
|
380
|
+
): { id: string; element: JSX.Element } | null {
|
|
381
|
+
const normalized = normalizeColorConfig(colorConfig);
|
|
382
|
+
|
|
383
|
+
if (normalized.type === "solid") {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const id = generateGradientId(idPrefix);
|
|
388
|
+
|
|
389
|
+
if (normalized.type === "linear") {
|
|
390
|
+
const gradient = normalized as LinearGradient;
|
|
391
|
+
const angle = gradient.angle ?? 0;
|
|
392
|
+
const { x1, y1, x2, y2 } = calculateCornerGradientCoordinates(
|
|
393
|
+
angle,
|
|
394
|
+
cornerX,
|
|
395
|
+
cornerY,
|
|
396
|
+
cornerSize,
|
|
397
|
+
cornerType
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
return {
|
|
401
|
+
id,
|
|
402
|
+
element: (
|
|
403
|
+
<linearGradient
|
|
404
|
+
gradientUnits="userSpaceOnUse"
|
|
405
|
+
id={id}
|
|
406
|
+
key={id}
|
|
407
|
+
x1={x1}
|
|
408
|
+
x2={x2}
|
|
409
|
+
y1={y1}
|
|
410
|
+
y2={y2}
|
|
411
|
+
>
|
|
412
|
+
{gradient.stops.map((stop, index) => (
|
|
413
|
+
<stop
|
|
414
|
+
key={`${id}-stop-${index}`}
|
|
415
|
+
offset={`${stop.offset}%`}
|
|
416
|
+
stopColor={stop.color}
|
|
417
|
+
/>
|
|
418
|
+
))}
|
|
419
|
+
</linearGradient>
|
|
420
|
+
),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (normalized.type === "radial") {
|
|
425
|
+
const gradient = normalized as RadialGradient;
|
|
426
|
+
const centerX = cornerX + cornerSize / 2;
|
|
427
|
+
const centerY = cornerY + cornerSize / 2;
|
|
428
|
+
const radius = (cornerSize / 2) * 0.97; // Slightly less than half to ensure full coverage
|
|
429
|
+
|
|
430
|
+
return {
|
|
431
|
+
id,
|
|
432
|
+
element: (
|
|
433
|
+
<radialGradient
|
|
434
|
+
cx={centerX}
|
|
435
|
+
cy={centerY}
|
|
436
|
+
fx={centerX}
|
|
437
|
+
fy={centerY}
|
|
438
|
+
gradientUnits="userSpaceOnUse"
|
|
439
|
+
id={id}
|
|
440
|
+
key={id}
|
|
441
|
+
r={radius}
|
|
442
|
+
>
|
|
443
|
+
{gradient.stops.map((stop, index) => (
|
|
444
|
+
<stop
|
|
445
|
+
key={`${id}-stop-${index}`}
|
|
446
|
+
offset={`${stop.offset}%`}
|
|
447
|
+
stopColor={stop.color}
|
|
448
|
+
/>
|
|
449
|
+
))}
|
|
450
|
+
</radialGradient>
|
|
451
|
+
),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Generate gradient definition elements
|
|
459
|
+
function generateGradientDef(
|
|
460
|
+
colorConfig: ColorConfig,
|
|
461
|
+
size: number,
|
|
462
|
+
idPrefix: string
|
|
463
|
+
): { id: string; element: JSX.Element } | null {
|
|
464
|
+
const normalized = normalizeColorConfig(colorConfig);
|
|
465
|
+
|
|
466
|
+
if (normalized.type === "solid") {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const id = generateGradientId(idPrefix);
|
|
471
|
+
|
|
472
|
+
if (normalized.type === "linear") {
|
|
473
|
+
const gradient = normalized as LinearGradient;
|
|
474
|
+
const angle = gradient.angle ?? 0;
|
|
475
|
+
const { x1, y1, x2, y2 } = calculateGradientCoordinates(angle, size);
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
id,
|
|
479
|
+
element: (
|
|
480
|
+
<linearGradient
|
|
481
|
+
gradientUnits="userSpaceOnUse"
|
|
482
|
+
id={id}
|
|
483
|
+
key={id}
|
|
484
|
+
x1={x1}
|
|
485
|
+
x2={x2}
|
|
486
|
+
y1={y1}
|
|
487
|
+
y2={y2}
|
|
488
|
+
>
|
|
489
|
+
{gradient.stops.map((stop, index) => (
|
|
490
|
+
<stop
|
|
491
|
+
key={`${id}-stop-${index}`}
|
|
492
|
+
offset={`${stop.offset}%`}
|
|
493
|
+
stopColor={stop.color}
|
|
494
|
+
/>
|
|
495
|
+
))}
|
|
496
|
+
</linearGradient>
|
|
497
|
+
),
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (normalized.type === "radial") {
|
|
502
|
+
const gradient = normalized as RadialGradient;
|
|
503
|
+
const centerX = size / 2;
|
|
504
|
+
const centerY = size / 2;
|
|
505
|
+
const radius = (size / 2) * 0.97; // Slightly less than half to ensure full coverage
|
|
506
|
+
|
|
507
|
+
return {
|
|
508
|
+
id,
|
|
509
|
+
element: (
|
|
510
|
+
<radialGradient
|
|
511
|
+
cx={centerX}
|
|
512
|
+
cy={centerY}
|
|
513
|
+
fx={centerX}
|
|
514
|
+
fy={centerY}
|
|
515
|
+
gradientUnits="userSpaceOnUse"
|
|
516
|
+
id={id}
|
|
517
|
+
key={id}
|
|
518
|
+
r={radius}
|
|
519
|
+
>
|
|
520
|
+
{gradient.stops.map((stop, index) => (
|
|
521
|
+
<stop
|
|
522
|
+
key={`${id}-stop-${index}`}
|
|
523
|
+
offset={`${stop.offset}%`}
|
|
524
|
+
stopColor={stop.color}
|
|
525
|
+
/>
|
|
526
|
+
))}
|
|
527
|
+
</radialGradient>
|
|
528
|
+
),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Get fill value from color config
|
|
536
|
+
function getFillValue(
|
|
537
|
+
colorConfig: ColorConfig | undefined,
|
|
538
|
+
gradientId: string | null,
|
|
539
|
+
fallback: string
|
|
540
|
+
): string {
|
|
541
|
+
if (gradientId) {
|
|
542
|
+
return `url(#${gradientId})`;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const normalized = normalizeColorConfig(colorConfig, fallback);
|
|
546
|
+
if (normalized.type === "solid") {
|
|
547
|
+
return normalized.color;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return fallback;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// Re-export getSolidColor from color utils
|
|
554
|
+
export { getSolidColor } from "./utils/color";
|
|
555
|
+
|
|
273
556
|
export function getImageSettings(
|
|
274
557
|
cells: Modules,
|
|
275
558
|
size: number,
|
|
@@ -428,6 +711,42 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
428
711
|
pattern: bodyPattern,
|
|
429
712
|
});
|
|
430
713
|
|
|
714
|
+
// Normalize bgColor and fgColor first to ensure proper structure
|
|
715
|
+
const normalizedBgColor = normalizeColorConfig(bgColor, DEFAULT_BGCOLOR);
|
|
716
|
+
const normalizedFgColor = normalizeColorConfig(fgColor, DEFAULT_FGCOLOR);
|
|
717
|
+
|
|
718
|
+
// Generate gradient definitions if needed
|
|
719
|
+
const bgColorGradient =
|
|
720
|
+
normalizedBgColor.type === "linear" || normalizedBgColor.type === "radial"
|
|
721
|
+
? generateGradientDef(
|
|
722
|
+
normalizedBgColor as LinearGradient | RadialGradient,
|
|
723
|
+
size,
|
|
724
|
+
"bg-color"
|
|
725
|
+
)
|
|
726
|
+
: null;
|
|
727
|
+
|
|
728
|
+
const fgColorGradient =
|
|
729
|
+
normalizedFgColor.type === "linear" || normalizedFgColor.type === "radial"
|
|
730
|
+
? generateGradientDef(
|
|
731
|
+
normalizedFgColor as LinearGradient | RadialGradient,
|
|
732
|
+
size,
|
|
733
|
+
"fg-color"
|
|
734
|
+
)
|
|
735
|
+
: null;
|
|
736
|
+
|
|
737
|
+
// Get fill values - use normalized color for gradient detection
|
|
738
|
+
const bgFillValue = getFillValue(
|
|
739
|
+
bgColor, // Pass original for getFillValue to handle normalization internally
|
|
740
|
+
bgColorGradient?.id ?? null,
|
|
741
|
+
DEFAULT_BGCOLOR
|
|
742
|
+
);
|
|
743
|
+
|
|
744
|
+
const fgFillValue = getFillValue(
|
|
745
|
+
fgColor, // Pass original for getFillValue to handle normalization internally
|
|
746
|
+
fgColorGradient?.id ?? null,
|
|
747
|
+
DEFAULT_FGCOLOR
|
|
748
|
+
);
|
|
749
|
+
|
|
431
750
|
// Calculate corner positions with margin
|
|
432
751
|
const topLeftX = margin * pixelSize;
|
|
433
752
|
const topLeftY = margin * pixelSize;
|
|
@@ -436,86 +755,221 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
436
755
|
const bottomLeftX = margin * pixelSize;
|
|
437
756
|
const bottomLeftY = (qrSize - 7 + margin) * pixelSize;
|
|
438
757
|
|
|
758
|
+
// Normalize eyeColor and dotColor
|
|
759
|
+
const normalizedEyeColor = normalizeColorConfig(
|
|
760
|
+
eyeColor,
|
|
761
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
762
|
+
);
|
|
763
|
+
const normalizedDotColor = normalizeColorConfig(
|
|
764
|
+
dotColor,
|
|
765
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
// Generate gradient definitions for eyeColor (corner squares) for each corner
|
|
769
|
+
const topLeftEyeGradient =
|
|
770
|
+
normalizedEyeColor.type === "linear" || normalizedEyeColor.type === "radial"
|
|
771
|
+
? generateCornerGradientDef(
|
|
772
|
+
normalizedEyeColor as LinearGradient | RadialGradient,
|
|
773
|
+
topLeftX,
|
|
774
|
+
topLeftY,
|
|
775
|
+
cornerSize,
|
|
776
|
+
"top-left",
|
|
777
|
+
"corners-square-color-0-0"
|
|
778
|
+
)
|
|
779
|
+
: null;
|
|
780
|
+
|
|
781
|
+
const topRightEyeGradient =
|
|
782
|
+
normalizedEyeColor.type === "linear" || normalizedEyeColor.type === "radial"
|
|
783
|
+
? generateCornerGradientDef(
|
|
784
|
+
normalizedEyeColor as LinearGradient | RadialGradient,
|
|
785
|
+
topRightX,
|
|
786
|
+
topRightY,
|
|
787
|
+
cornerSize,
|
|
788
|
+
"top-right",
|
|
789
|
+
"corners-square-color-1-0"
|
|
790
|
+
)
|
|
791
|
+
: null;
|
|
792
|
+
|
|
793
|
+
const bottomLeftEyeGradient =
|
|
794
|
+
normalizedEyeColor.type === "linear" || normalizedEyeColor.type === "radial"
|
|
795
|
+
? generateCornerGradientDef(
|
|
796
|
+
normalizedEyeColor as LinearGradient | RadialGradient,
|
|
797
|
+
bottomLeftX,
|
|
798
|
+
bottomLeftY,
|
|
799
|
+
cornerSize,
|
|
800
|
+
"bottom-left",
|
|
801
|
+
"corners-square-color-0-1"
|
|
802
|
+
)
|
|
803
|
+
: null;
|
|
804
|
+
|
|
805
|
+
// Generate gradient definitions for dotColor (corner dots) for each corner
|
|
806
|
+
const topLeftDotGradient =
|
|
807
|
+
normalizedDotColor.type === "linear" || normalizedDotColor.type === "radial"
|
|
808
|
+
? generateCornerGradientDef(
|
|
809
|
+
normalizedDotColor as LinearGradient | RadialGradient,
|
|
810
|
+
topLeftX,
|
|
811
|
+
topLeftY,
|
|
812
|
+
cornerSize,
|
|
813
|
+
"top-left",
|
|
814
|
+
"corners-dot-color-0-0"
|
|
815
|
+
)
|
|
816
|
+
: null;
|
|
817
|
+
|
|
818
|
+
const topRightDotGradient =
|
|
819
|
+
normalizedDotColor.type === "linear" || normalizedDotColor.type === "radial"
|
|
820
|
+
? generateCornerGradientDef(
|
|
821
|
+
normalizedDotColor as LinearGradient | RadialGradient,
|
|
822
|
+
topRightX,
|
|
823
|
+
topRightY,
|
|
824
|
+
cornerSize,
|
|
825
|
+
"top-right",
|
|
826
|
+
"corners-dot-color-1-0"
|
|
827
|
+
)
|
|
828
|
+
: null;
|
|
829
|
+
|
|
830
|
+
const bottomLeftDotGradient =
|
|
831
|
+
normalizedDotColor.type === "linear" || normalizedDotColor.type === "radial"
|
|
832
|
+
? generateCornerGradientDef(
|
|
833
|
+
normalizedDotColor as LinearGradient | RadialGradient,
|
|
834
|
+
bottomLeftX,
|
|
835
|
+
bottomLeftY,
|
|
836
|
+
cornerSize,
|
|
837
|
+
"bottom-left",
|
|
838
|
+
"corners-dot-color-0-1"
|
|
839
|
+
)
|
|
840
|
+
: null;
|
|
841
|
+
|
|
842
|
+
// Get fill values for eyeColor and dotColor
|
|
843
|
+
const topLeftEyeFillValue = getFillValue(
|
|
844
|
+
eyeColor,
|
|
845
|
+
topLeftEyeGradient?.id ?? null,
|
|
846
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
847
|
+
);
|
|
848
|
+
const topRightEyeFillValue = getFillValue(
|
|
849
|
+
eyeColor,
|
|
850
|
+
topRightEyeGradient?.id ?? null,
|
|
851
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
852
|
+
);
|
|
853
|
+
const bottomLeftEyeFillValue = getFillValue(
|
|
854
|
+
eyeColor,
|
|
855
|
+
bottomLeftEyeGradient?.id ?? null,
|
|
856
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
857
|
+
);
|
|
858
|
+
|
|
859
|
+
const topLeftDotFillValue = getFillValue(
|
|
860
|
+
dotColor,
|
|
861
|
+
topLeftDotGradient?.id ?? null,
|
|
862
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
863
|
+
);
|
|
864
|
+
const topRightDotFillValue = getFillValue(
|
|
865
|
+
dotColor,
|
|
866
|
+
topRightDotGradient?.id ?? null,
|
|
867
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
868
|
+
);
|
|
869
|
+
const bottomLeftDotFillValue = getFillValue(
|
|
870
|
+
dotColor,
|
|
871
|
+
bottomLeftDotGradient?.id ?? null,
|
|
872
|
+
getSolidColor(fgColor, DEFAULT_FGCOLOR)
|
|
873
|
+
);
|
|
874
|
+
|
|
875
|
+
const topLeftEye = generateCornerSquarePath(
|
|
876
|
+
topLeftX,
|
|
877
|
+
topLeftY,
|
|
878
|
+
cornerSize,
|
|
879
|
+
cornerEyePattern
|
|
880
|
+
);
|
|
881
|
+
|
|
882
|
+
const topLeftDot = generateCornerDotPath(
|
|
883
|
+
topLeftX + cornerSize / 2,
|
|
884
|
+
topLeftY + cornerSize / 2,
|
|
885
|
+
cornerDotRadius,
|
|
886
|
+
cornerEyeDotPattern
|
|
887
|
+
);
|
|
888
|
+
|
|
889
|
+
const topRightEye = generateCornerSquarePath(
|
|
890
|
+
topRightX,
|
|
891
|
+
topRightY,
|
|
892
|
+
cornerSize,
|
|
893
|
+
cornerEyePattern
|
|
894
|
+
);
|
|
895
|
+
|
|
896
|
+
const topRightDot = generateCornerDotPath(
|
|
897
|
+
topRightX + cornerSize / 2,
|
|
898
|
+
topRightY + cornerSize / 2,
|
|
899
|
+
cornerDotRadius,
|
|
900
|
+
cornerEyeDotPattern
|
|
901
|
+
);
|
|
902
|
+
|
|
903
|
+
const bottomLeftEye = generateCornerSquarePath(
|
|
904
|
+
bottomLeftX,
|
|
905
|
+
bottomLeftY,
|
|
906
|
+
cornerSize,
|
|
907
|
+
cornerEyePattern
|
|
908
|
+
);
|
|
909
|
+
|
|
910
|
+
const bottomLeftDot = generateCornerDotPath(
|
|
911
|
+
bottomLeftX + cornerSize / 2,
|
|
912
|
+
bottomLeftY + cornerSize / 2,
|
|
913
|
+
cornerDotRadius,
|
|
914
|
+
cornerEyeDotPattern
|
|
915
|
+
);
|
|
916
|
+
|
|
439
917
|
// QR Code content (can be used standalone or inside wrapper)
|
|
440
918
|
const qrContent = (
|
|
441
919
|
<>
|
|
920
|
+
{/* Gradient definitions */}
|
|
921
|
+
<defs>
|
|
922
|
+
{bgColorGradient?.element}
|
|
923
|
+
{fgColorGradient?.element}
|
|
924
|
+
{topLeftEyeGradient?.element}
|
|
925
|
+
{topRightEyeGradient?.element}
|
|
926
|
+
{bottomLeftEyeGradient?.element}
|
|
927
|
+
{topLeftDotGradient?.element}
|
|
928
|
+
{topRightDotGradient?.element}
|
|
929
|
+
{bottomLeftDotGradient?.element}
|
|
930
|
+
</defs>
|
|
931
|
+
|
|
442
932
|
{/* Background */}
|
|
443
|
-
<rect fill={
|
|
933
|
+
<rect fill={bgFillValue} height={size} width={size} x={0} y={0} />
|
|
444
934
|
|
|
445
935
|
{/* Data module circles */}
|
|
446
|
-
<g fill={
|
|
936
|
+
<g fill={fgFillValue}>{dataCircles}</g>
|
|
447
937
|
|
|
448
938
|
{/* Top-left corner square */}
|
|
449
|
-
<g fill={
|
|
939
|
+
<g fill={topLeftEyeFillValue}>
|
|
450
940
|
<path
|
|
451
941
|
clipRule="evenodd"
|
|
452
|
-
d={
|
|
453
|
-
topLeftX,
|
|
454
|
-
topLeftY,
|
|
455
|
-
cornerSize,
|
|
456
|
-
cornerEyePattern
|
|
457
|
-
)}
|
|
942
|
+
d={topLeftEye}
|
|
458
943
|
transform={`rotate(0,${topLeftX + cornerSize / 2},${topLeftY + cornerSize / 2})`}
|
|
459
944
|
/>
|
|
460
945
|
</g>
|
|
461
946
|
|
|
462
947
|
{/* Top-left corner dot */}
|
|
463
|
-
<g fill={
|
|
464
|
-
{generateCornerDotPath(
|
|
465
|
-
topLeftX + cornerSize / 2,
|
|
466
|
-
topLeftY + cornerSize / 2,
|
|
467
|
-
cornerDotRadius,
|
|
468
|
-
cornerEyeDotPattern
|
|
469
|
-
)}
|
|
470
|
-
</g>
|
|
948
|
+
<g fill={topLeftDotFillValue}>{topLeftDot}</g>
|
|
471
949
|
|
|
472
950
|
{/* Top-right corner square */}
|
|
473
|
-
<g fill={
|
|
951
|
+
<g fill={topRightEyeFillValue}>
|
|
474
952
|
<path
|
|
475
953
|
clipRule="evenodd"
|
|
476
|
-
d={
|
|
477
|
-
topRightX,
|
|
478
|
-
topRightY,
|
|
479
|
-
cornerSize,
|
|
480
|
-
cornerEyePattern
|
|
481
|
-
)}
|
|
954
|
+
d={topRightEye}
|
|
482
955
|
transform={`rotate(0,${topRightX + cornerSize / 2},${topRightY + cornerSize / 2})`}
|
|
483
956
|
/>
|
|
484
957
|
</g>
|
|
485
958
|
|
|
486
959
|
{/* Top-right corner dot */}
|
|
487
|
-
<g fill={
|
|
488
|
-
{generateCornerDotPath(
|
|
489
|
-
topRightX + cornerSize / 2,
|
|
490
|
-
topRightY + cornerSize / 2,
|
|
491
|
-
cornerDotRadius,
|
|
492
|
-
cornerEyeDotPattern
|
|
493
|
-
)}
|
|
494
|
-
</g>
|
|
960
|
+
<g fill={topRightDotFillValue}>{topRightDot}</g>
|
|
495
961
|
|
|
496
962
|
{/* Bottom-left corner square */}
|
|
497
|
-
<g fill={
|
|
963
|
+
<g fill={bottomLeftEyeFillValue}>
|
|
498
964
|
<path
|
|
499
965
|
clipRule="evenodd"
|
|
500
|
-
d={
|
|
501
|
-
bottomLeftX,
|
|
502
|
-
bottomLeftY,
|
|
503
|
-
cornerSize,
|
|
504
|
-
cornerEyePattern
|
|
505
|
-
)}
|
|
966
|
+
d={bottomLeftEye}
|
|
506
967
|
transform={`rotate(0,${bottomLeftX + cornerSize / 2},${bottomLeftY + cornerSize / 2})`}
|
|
507
968
|
/>
|
|
508
969
|
</g>
|
|
509
970
|
|
|
510
971
|
{/* Bottom-left corner dot */}
|
|
511
|
-
<g fill={
|
|
512
|
-
{generateCornerDotPath(
|
|
513
|
-
bottomLeftX + cornerSize / 2,
|
|
514
|
-
bottomLeftY + cornerSize / 2,
|
|
515
|
-
cornerDotRadius,
|
|
516
|
-
cornerEyeDotPattern
|
|
517
|
-
)}
|
|
518
|
-
</g>
|
|
972
|
+
<g fill={bottomLeftDotFillValue}>{bottomLeftDot}</g>
|
|
519
973
|
|
|
520
974
|
{image}
|
|
521
975
|
</>
|
|
@@ -529,20 +983,58 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
529
983
|
// Templates expect the QR content to be in a coordinate system that matches their transforms
|
|
530
984
|
const templateSize = 300; // All templates use 300x300 base coordinate system
|
|
531
985
|
|
|
986
|
+
// Generate background gradient for template size (gradients use userSpaceOnUse, so coordinates must match)
|
|
987
|
+
const templateBgColorGradient =
|
|
988
|
+
normalizedBgColor.type === "linear" || normalizedBgColor.type === "radial"
|
|
989
|
+
? generateGradientDef(
|
|
990
|
+
normalizedBgColor as LinearGradient | RadialGradient,
|
|
991
|
+
templateSize,
|
|
992
|
+
"bg-color-template"
|
|
993
|
+
)
|
|
994
|
+
: null;
|
|
995
|
+
|
|
996
|
+
const templateBgFillValue = getFillValue(
|
|
997
|
+
bgColor,
|
|
998
|
+
templateBgColorGradient?.id ?? null,
|
|
999
|
+
DEFAULT_BGCOLOR
|
|
1000
|
+
);
|
|
1001
|
+
|
|
532
1002
|
// Create QR content as a complete SVG for templates
|
|
533
1003
|
const templateQrContent = (
|
|
534
1004
|
<svg
|
|
535
1005
|
height={templateSize}
|
|
536
1006
|
viewBox={`0 0 ${templateSize} ${templateSize}`}
|
|
537
1007
|
width={templateSize}
|
|
1008
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
538
1009
|
>
|
|
1010
|
+
{/* Gradient definitions */}
|
|
1011
|
+
<defs>
|
|
1012
|
+
{templateBgColorGradient?.element}
|
|
1013
|
+
{fgColorGradient?.element}
|
|
1014
|
+
{topLeftEyeGradient?.element}
|
|
1015
|
+
{topRightEyeGradient?.element}
|
|
1016
|
+
{bottomLeftEyeGradient?.element}
|
|
1017
|
+
{topLeftDotGradient?.element}
|
|
1018
|
+
{topRightDotGradient?.element}
|
|
1019
|
+
{bottomLeftDotGradient?.element}
|
|
1020
|
+
</defs>
|
|
1021
|
+
|
|
1022
|
+
{/* Background */}
|
|
1023
|
+
<rect
|
|
1024
|
+
fill={templateBgFillValue}
|
|
1025
|
+
height={templateSize}
|
|
1026
|
+
width={templateSize}
|
|
1027
|
+
x={0}
|
|
1028
|
+
y={0}
|
|
1029
|
+
/>
|
|
1030
|
+
|
|
539
1031
|
{/* Scale all QR elements to fit template coordinate system */}
|
|
540
1032
|
<g transform={`scale(${templateSize / size})`}>
|
|
541
1033
|
{/* Data module circles */}
|
|
542
|
-
<g fill={
|
|
1034
|
+
<g fill={fgFillValue}>{dataCircles}</g>
|
|
543
1035
|
|
|
544
1036
|
{/* Top-left corner square */}
|
|
545
|
-
<g fill={
|
|
1037
|
+
<g fill={topLeftEyeFillValue}>
|
|
546
1038
|
<path
|
|
547
1039
|
clipRule="evenodd"
|
|
548
1040
|
d={generateCornerSquarePath(
|
|
@@ -556,7 +1048,7 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
556
1048
|
</g>
|
|
557
1049
|
|
|
558
1050
|
{/* Top-left corner dot */}
|
|
559
|
-
<g fill={
|
|
1051
|
+
<g fill={topLeftDotFillValue}>
|
|
560
1052
|
{generateCornerDotPath(
|
|
561
1053
|
topLeftX + cornerSize / 2,
|
|
562
1054
|
topLeftY + cornerSize / 2,
|
|
@@ -566,7 +1058,7 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
566
1058
|
</g>
|
|
567
1059
|
|
|
568
1060
|
{/* Top-right corner square */}
|
|
569
|
-
<g fill={
|
|
1061
|
+
<g fill={topRightEyeFillValue}>
|
|
570
1062
|
<path
|
|
571
1063
|
clipRule="evenodd"
|
|
572
1064
|
d={generateCornerSquarePath(
|
|
@@ -580,7 +1072,7 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
580
1072
|
</g>
|
|
581
1073
|
|
|
582
1074
|
{/* Top-right corner dot */}
|
|
583
|
-
<g fill={
|
|
1075
|
+
<g fill={topRightDotFillValue}>
|
|
584
1076
|
{generateCornerDotPath(
|
|
585
1077
|
topRightX + cornerSize / 2,
|
|
586
1078
|
topRightY + cornerSize / 2,
|
|
@@ -590,7 +1082,7 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
590
1082
|
</g>
|
|
591
1083
|
|
|
592
1084
|
{/* Bottom-left corner square */}
|
|
593
|
-
<g fill={
|
|
1085
|
+
<g fill={bottomLeftEyeFillValue}>
|
|
594
1086
|
<path
|
|
595
1087
|
clipRule="evenodd"
|
|
596
1088
|
d={generateCornerSquarePath(
|
|
@@ -604,7 +1096,7 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
604
1096
|
</g>
|
|
605
1097
|
|
|
606
1098
|
{/* Bottom-left corner dot */}
|
|
607
|
-
<g fill={
|
|
1099
|
+
<g fill={bottomLeftDotFillValue}>
|
|
608
1100
|
{generateCornerDotPath(
|
|
609
1101
|
bottomLeftX + cornerSize / 2,
|
|
610
1102
|
bottomLeftY + cornerSize / 2,
|
|
@@ -666,6 +1158,7 @@ export function QRCodeSVG(props: QRPropsSVG) {
|
|
|
666
1158
|
height={size}
|
|
667
1159
|
viewBox={`0 0 ${size} ${size}`}
|
|
668
1160
|
width={size}
|
|
1161
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
669
1162
|
{...otherProps}
|
|
670
1163
|
>
|
|
671
1164
|
{qrContent}
|