qrdx 0.0.1 → 0.0.2-beta.2
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/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/constants.d.ts +40 -5
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/corner-dot.d.ts +8 -0
- package/dist/src/corner-dot.d.ts.map +1 -1
- package/dist/src/corner-eye.d.ts +8 -0
- package/dist/src/corner-eye.d.ts.map +1 -1
- package/dist/src/helpers.d.ts +7 -32
- package/dist/src/helpers.d.ts.map +1 -1
- package/dist/src/qr-code.d.ts +5 -16
- package/dist/src/qr-code.d.ts.map +1 -1
- package/dist/types/common.d.ts +8 -6
- package/dist/types/common.d.ts.map +1 -1
- 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 +9 -2
- package/dist/types/corner-eye.d.ts.map +1 -1
- package/dist/types/image-pattern.d.ts +12 -1
- package/dist/types/image-pattern.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/qr.d.ts +69 -12
- package/dist/types/qr.d.ts.map +1 -1
- package/dist/types/template.d.ts +16 -8
- package/dist/types/template.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/constants.ts +46 -7
- package/src/corner-dot.tsx +9 -45
- package/src/corner-eye.ts +18 -84
- package/src/helpers.ts +15 -23
- package/src/qr-code.tsx +12 -28
- package/types/common.ts +12 -1
- package/types/corner-dot.ts +7 -6
- package/types/corner-eye.ts +7 -6
- package/types/image-pattern.ts +7 -1
- package/types/index.ts +28 -4
- package/types/qr.ts +41 -12
- package/types/template.ts +23 -9
package/src/corner-eye.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { CornerEyePattern } from "../types/corner-eye";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Pattern 1: Basic square corners
|
|
5
|
+
*/
|
|
4
6
|
function generateCornerSquarePattern(
|
|
5
7
|
offsetX: number,
|
|
6
8
|
offsetY: number,
|
|
@@ -14,7 +16,9 @@ function generateCornerSquarePattern(
|
|
|
14
16
|
return path;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Pattern 2: Rounded corners
|
|
21
|
+
*/
|
|
18
22
|
function generateCornerRoundedPattern(
|
|
19
23
|
offsetX: number,
|
|
20
24
|
offsetY: number,
|
|
@@ -29,76 +33,6 @@ function generateCornerRoundedPattern(
|
|
|
29
33
|
return path;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
// Pattern 3: Rounded inward
|
|
33
|
-
function generateCornerRoundedInwardPattern(
|
|
34
|
-
offsetX: number,
|
|
35
|
-
offsetY: number,
|
|
36
|
-
size: number
|
|
37
|
-
): string {
|
|
38
|
-
const scale = size / 80;
|
|
39
|
-
const transform = (coord: number, offset: number) => coord * scale + offset;
|
|
40
|
-
|
|
41
|
-
const path = `M ${transform(5, offsetX)} ${transform(30, offsetY)}v 20a ${25 * scale} ${25 * scale}, 0, 0, 0, ${25 * scale} ${25 * scale}h 45v -45a ${25 * scale} ${25 * scale}, 0, 0, 0, -${25 * scale} -${25 * scale}h -20a ${25 * scale} ${25 * scale}, 0, 0, 0, -${25 * scale} ${25 * scale}M ${transform(30, offsetX)} ${transform(15, offsetY)}h 20a ${15 * scale} ${15 * scale}, 0, 0, 1, ${15 * scale} ${15 * scale}v 35h -35a ${15 * scale} ${15 * scale}, 0, 0, 1, -${15 * scale} -${15 * scale}v -20a ${15 * scale} ${15 * scale}, 0, 0, 1, ${15 * scale} -${15 * scale}`;
|
|
42
|
-
|
|
43
|
-
return path;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Pattern 4: Rounded inward flipped
|
|
47
|
-
function generateCornerRoundedInwardFlippedPattern(
|
|
48
|
-
offsetX: number,
|
|
49
|
-
offsetY: number,
|
|
50
|
-
size: number
|
|
51
|
-
): string {
|
|
52
|
-
const scale = size / 80;
|
|
53
|
-
const transform = (coord: number, offset: number) => coord * scale + offset;
|
|
54
|
-
|
|
55
|
-
const path = `M ${transform(5, offsetX)} ${transform(30, offsetY)}v 20a ${25 * scale} ${25 * scale}, 0, 0, 0, ${25 * scale} ${25 * scale}h 45v -45a ${25 * scale} ${25 * scale}, 0, 0, 0, -${25 * scale} -${25 * scale}h -20a ${25 * scale} ${25 * scale}, 0, 0, 0, -${25 * scale} ${25 * scale}M ${transform(30, offsetX)} ${transform(15, offsetY)}h 20a ${15 * scale} ${15 * scale}, 0, 0, 1, ${15 * scale} ${15 * scale}v 35h -35a ${15 * scale} ${15 * scale}, 0, 0, 1, -${15 * scale} -${15 * scale}v -20a ${15 * scale} ${15 * scale}, 0, 0, 1, ${15 * scale} -${15 * scale}`;
|
|
56
|
-
|
|
57
|
-
return path;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Pattern 6: Semi-round
|
|
61
|
-
function generateCornerSemiRoundPattern(
|
|
62
|
-
offsetX: number,
|
|
63
|
-
offsetY: number,
|
|
64
|
-
size: number
|
|
65
|
-
): string {
|
|
66
|
-
const scale = size / 80;
|
|
67
|
-
const transform = (coord: number, offset: number) => coord * scale + offset;
|
|
68
|
-
|
|
69
|
-
const path = `M ${transform(5, offsetX)} ${transform(30, offsetY)}v 20a ${25 * scale} ${25 * scale}, 0, 0, 0, ${25 * scale} ${25 * scale}h 45v -45a ${25 * scale} ${25 * scale}, 0, 0, 0, -${25 * scale} -${25 * scale}h -20H ${transform(5, offsetX)}zM ${transform(30, offsetX)} ${transform(15, offsetY)}h 20a ${15 * scale} ${15 * scale}, 0, 0, 1, ${15 * scale} ${15 * scale}v 35h -35a ${15 * scale} ${15 * scale}, 0, 0, 1, -${15 * scale} -${15 * scale}v -35z`;
|
|
70
|
-
|
|
71
|
-
return path;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Pattern 7: Rounded-extra
|
|
75
|
-
function generateCornerRoundedExtraPattern(
|
|
76
|
-
offsetX: number,
|
|
77
|
-
offsetY: number,
|
|
78
|
-
size: number
|
|
79
|
-
): string {
|
|
80
|
-
const scale = size / 80;
|
|
81
|
-
const transform = (coord: number, offset: number) => coord * scale + offset;
|
|
82
|
-
|
|
83
|
-
const path = `M ${transform(5, offsetX)} ${transform(30, offsetY)}v 20a ${25 * scale} ${25 * scale}, 0, 0, 0, ${25 * scale} ${25 * scale}h 20a ${25 * scale} ${25 * scale}, 0, 0, 0, ${25 * scale} -${25 * scale}v -20a ${25 * scale} ${25 * scale}, 0, 0, 0, -${25 * scale} -${25 * scale}h -20a ${25 * scale} ${25 * scale}, 0, 0, 0, -${25 * scale} ${25 * scale}M ${transform(30, offsetX)} ${transform(15, offsetY)}h 20a ${15 * scale} ${15 * scale}, 0, 0, 1, ${15 * scale} ${15 * scale}v 20a ${15 * scale} ${15 * scale}, 0, 0, 1, -${15 * scale} ${15 * scale}h -20a ${15 * scale} ${15 * scale}, 0, 0, 1, -${15 * scale} -${15 * scale}v -20a ${15 * scale} ${15 * scale}, 0, 0, 1, ${15 * scale} -${15 * scale}`;
|
|
84
|
-
|
|
85
|
-
return path;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Pattern 8: Rounded-square
|
|
89
|
-
function generateCornerRoundedSquarePattern(
|
|
90
|
-
offsetX: number,
|
|
91
|
-
offsetY: number,
|
|
92
|
-
size: number
|
|
93
|
-
): string {
|
|
94
|
-
const scale = size / 80;
|
|
95
|
-
const transform = (coord: number, offset: number) => coord * scale + offset;
|
|
96
|
-
|
|
97
|
-
const path = `M ${transform(5, offsetX)} ${transform(40, offsetY)}a ${35 * scale} ${35 * scale}, 0, 0, 0, ${35 * scale} ${35 * scale}h 30a ${5 * scale} ${5 * scale}, 0, 0, 0, ${5 * scale} -${5 * scale}v -30a ${35 * scale} ${35 * scale}, 0, 0, 0, -${35 * scale} -${35 * scale}a ${35 * scale} ${35 * scale}, 0, 0, 0, -${35 * scale} ${35 * scale}zM ${transform(40, offsetX)} ${transform(15, offsetY)}a ${25 * scale} ${25 * scale}, 0, 0, 1, ${25 * scale} ${25 * scale}v 25h -25a ${25 * scale} ${25 * scale}, 0, 0, 1, -${25 * scale} -${25 * scale}a ${25 * scale} ${25 * scale}, 0, 0, 1, ${25 * scale} -${25 * scale}z`;
|
|
98
|
-
|
|
99
|
-
return path;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
36
|
// Pattern 9: Circle
|
|
103
37
|
function generateCornerCirclePattern(
|
|
104
38
|
offsetX: number,
|
|
@@ -116,7 +50,9 @@ function generateCornerCirclePattern(
|
|
|
116
50
|
return path;
|
|
117
51
|
}
|
|
118
52
|
|
|
119
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Pattern 4: Gear (current default decorative design)
|
|
55
|
+
*/
|
|
120
56
|
function generateCornerGearPattern(
|
|
121
57
|
offsetX: number,
|
|
122
58
|
offsetY: number,
|
|
@@ -135,7 +71,14 @@ function generateCornerGearPattern(
|
|
|
135
71
|
return path;
|
|
136
72
|
}
|
|
137
73
|
|
|
138
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Generate corner square path based on pattern type
|
|
76
|
+
* @param offsetX - X offset for the corner
|
|
77
|
+
* @param offsetY - Y offset for the corner
|
|
78
|
+
* @param size - Size of the corner pattern
|
|
79
|
+
* @param pattern - Pattern type for the corner eye
|
|
80
|
+
* @returns SVG path string for the pattern
|
|
81
|
+
*/
|
|
139
82
|
export function generateCornerSquarePath(
|
|
140
83
|
offsetX: number,
|
|
141
84
|
offsetY: number,
|
|
@@ -147,18 +90,9 @@ export function generateCornerSquarePath(
|
|
|
147
90
|
return generateCornerSquarePattern(offsetX, offsetY, size);
|
|
148
91
|
case "rounded":
|
|
149
92
|
return generateCornerRoundedPattern(offsetX, offsetY, size);
|
|
150
|
-
case "rounded-inward":
|
|
151
|
-
return generateCornerRoundedInwardPattern(offsetX, offsetY, size);
|
|
152
|
-
case "rounded-inward-flipped":
|
|
153
|
-
return generateCornerRoundedInwardFlippedPattern(offsetX, offsetY, size);
|
|
154
|
-
case "semi-round":
|
|
155
|
-
return generateCornerSemiRoundPattern(offsetX, offsetY, size);
|
|
156
|
-
case "rounded-extra":
|
|
157
|
-
return generateCornerRoundedExtraPattern(offsetX, offsetY, size);
|
|
158
|
-
case "rounded-square":
|
|
159
|
-
return generateCornerRoundedSquarePattern(offsetX, offsetY, size);
|
|
160
93
|
case "circle":
|
|
161
94
|
return generateCornerCirclePattern(offsetX, offsetY, size);
|
|
95
|
+
// case "gear":
|
|
162
96
|
default:
|
|
163
97
|
return generateCornerGearPattern(offsetX, offsetY, size);
|
|
164
98
|
}
|
package/src/helpers.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BodyPattern,
|
|
3
|
-
CornerEyeDotPattern,
|
|
4
|
-
CornerEyePattern,
|
|
5
|
-
} from "@/types";
|
|
1
|
+
import type { QRProps } from "../types";
|
|
6
2
|
import { FLAM_QR_LOGO } from "./constants";
|
|
7
3
|
|
|
4
|
+
interface QRDataProps extends QRProps {
|
|
5
|
+
hideLogo?: boolean;
|
|
6
|
+
logo?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface QRDataResult extends QRProps {
|
|
10
|
+
size: number; // Required in result
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
export function getQRData({
|
|
9
|
-
|
|
14
|
+
value,
|
|
15
|
+
size = 1024,
|
|
10
16
|
fgColor,
|
|
11
17
|
bgColor,
|
|
12
18
|
eyeColor,
|
|
@@ -19,23 +25,9 @@ export function getQRData({
|
|
|
19
25
|
cornerEyeDotPattern,
|
|
20
26
|
level,
|
|
21
27
|
templateId,
|
|
22
|
-
}: {
|
|
23
|
-
url: string;
|
|
24
|
-
fgColor?: string;
|
|
25
|
-
bgColor?: string;
|
|
26
|
-
eyeColor?: string;
|
|
27
|
-
dotColor?: string;
|
|
28
|
-
bodyPattern?: BodyPattern;
|
|
29
|
-
hideLogo?: boolean;
|
|
30
|
-
logo?: string;
|
|
31
|
-
margin?: number;
|
|
32
|
-
cornerEyePattern?: CornerEyePattern;
|
|
33
|
-
cornerEyeDotPattern?: CornerEyeDotPattern;
|
|
34
|
-
level?: "L" | "M" | "Q" | "H";
|
|
35
|
-
templateId?: string;
|
|
36
|
-
}) {
|
|
28
|
+
}: QRDataProps): QRDataResult {
|
|
37
29
|
return {
|
|
38
|
-
value: `${
|
|
30
|
+
value: `${value}`,
|
|
39
31
|
bgColor,
|
|
40
32
|
fgColor,
|
|
41
33
|
eyeColor,
|
|
@@ -45,7 +37,7 @@ export function getQRData({
|
|
|
45
37
|
cornerEyeDotPattern,
|
|
46
38
|
level,
|
|
47
39
|
templateId,
|
|
48
|
-
size
|
|
40
|
+
size,
|
|
49
41
|
margin,
|
|
50
42
|
...(!hideLogo && {
|
|
51
43
|
imageSettings: {
|
package/src/qr-code.tsx
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { memo, useMemo } from "react";
|
|
4
|
-
import type {
|
|
5
|
-
BodyPattern,
|
|
6
|
-
CornerEyeDotPattern,
|
|
7
|
-
CornerEyePattern,
|
|
8
|
-
TemplateDefinition,
|
|
9
|
-
} from "@/types";
|
|
4
|
+
import type { QRProps } from "../types";
|
|
10
5
|
import { DEFAULT_MARGIN } from "./constants";
|
|
11
6
|
import { getQRData } from "./helpers";
|
|
12
7
|
import { QRCodeSVG } from "./utils";
|
|
13
8
|
|
|
9
|
+
interface QRCodeProps extends QRProps {
|
|
10
|
+
hideLogo?: boolean;
|
|
11
|
+
logo?: string;
|
|
12
|
+
scale?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
14
15
|
export const QRCode = memo(
|
|
15
16
|
({
|
|
16
|
-
|
|
17
|
+
value,
|
|
17
18
|
fgColor,
|
|
18
19
|
hideLogo,
|
|
19
20
|
logo,
|
|
@@ -29,28 +30,11 @@ export const QRCode = memo(
|
|
|
29
30
|
templateId,
|
|
30
31
|
customTemplate,
|
|
31
32
|
customProps,
|
|
32
|
-
}: {
|
|
33
|
-
url: string;
|
|
34
|
-
fgColor?: string;
|
|
35
|
-
hideLogo?: boolean;
|
|
36
|
-
logo?: string;
|
|
37
|
-
bgColor?: string;
|
|
38
|
-
eyeColor?: string;
|
|
39
|
-
dotColor?: string;
|
|
40
|
-
bodyPattern?: BodyPattern;
|
|
41
|
-
cornerEyePattern?: CornerEyePattern;
|
|
42
|
-
cornerEyeDotPattern?: CornerEyeDotPattern;
|
|
43
|
-
level?: "L" | "M" | "Q" | "H";
|
|
44
|
-
scale?: number;
|
|
45
|
-
margin?: number;
|
|
46
|
-
templateId?: string;
|
|
47
|
-
customTemplate?: TemplateDefinition<any>;
|
|
48
|
-
customProps?: Record<string, any>;
|
|
49
|
-
}) => {
|
|
33
|
+
}: QRCodeProps) => {
|
|
50
34
|
const qrData = useMemo(
|
|
51
35
|
() =>
|
|
52
36
|
getQRData({
|
|
53
|
-
|
|
37
|
+
value,
|
|
54
38
|
fgColor,
|
|
55
39
|
hideLogo,
|
|
56
40
|
bgColor,
|
|
@@ -65,7 +49,7 @@ export const QRCode = memo(
|
|
|
65
49
|
margin,
|
|
66
50
|
}),
|
|
67
51
|
[
|
|
68
|
-
|
|
52
|
+
value,
|
|
69
53
|
fgColor,
|
|
70
54
|
hideLogo,
|
|
71
55
|
logo,
|
|
@@ -88,6 +72,7 @@ export const QRCode = memo(
|
|
|
88
72
|
cornerEyeDotPattern={qrData.cornerEyeDotPattern}
|
|
89
73
|
cornerEyePattern={qrData.cornerEyePattern}
|
|
90
74
|
customProps={customProps}
|
|
75
|
+
customTemplate={customTemplate}
|
|
91
76
|
dotColor={qrData.dotColor}
|
|
92
77
|
eyeColor={qrData.eyeColor}
|
|
93
78
|
fgColor={qrData.fgColor}
|
|
@@ -95,7 +80,6 @@ export const QRCode = memo(
|
|
|
95
80
|
margin={qrData.margin}
|
|
96
81
|
size={(qrData.size / 8) * scale}
|
|
97
82
|
templateId={qrData.templateId}
|
|
98
|
-
customTemplate={customTemplate}
|
|
99
83
|
value={qrData.value}
|
|
100
84
|
{...(qrData.imageSettings && {
|
|
101
85
|
imageSettings: {
|
package/types/common.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import type qrcodegen from "../src/codegen";
|
|
2
3
|
|
|
3
4
|
export type Modules = ReturnType<qrcodegen.QrCode["getModules"]>;
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
// Zod schemas
|
|
7
|
+
export const excavationSchema = z.object({
|
|
8
|
+
x: z.number(),
|
|
9
|
+
y: z.number(),
|
|
10
|
+
w: z.number(),
|
|
11
|
+
h: z.number(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Inferred types
|
|
15
|
+
export type Excavation = z.infer<typeof excavationSchema>;
|
package/types/corner-dot.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
1
3
|
export const CORNER_EYE_DOT_PATTERNS = [
|
|
2
4
|
"square",
|
|
3
5
|
"rounded-square",
|
|
4
6
|
"circle",
|
|
5
|
-
"rounded-inward",
|
|
6
|
-
"rounded-inward-flipped",
|
|
7
|
-
"semi-round",
|
|
8
|
-
"leaf",
|
|
9
7
|
"diamond",
|
|
10
|
-
"diamond-rounded",
|
|
11
8
|
] as const;
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
// Zod schema
|
|
11
|
+
export const cornerEyeDotPatternSchema = z.enum(CORNER_EYE_DOT_PATTERNS);
|
|
12
|
+
|
|
13
|
+
// Inferred type
|
|
14
|
+
export type CornerEyeDotPattern = z.infer<typeof cornerEyeDotPatternSchema>;
|
package/types/corner-eye.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
1
3
|
export const CORNER_EYE_PATTERNS = [
|
|
2
4
|
"square",
|
|
3
5
|
"rounded",
|
|
4
|
-
"rounded-inward",
|
|
5
|
-
"rounded-inward-flipped",
|
|
6
6
|
"gear",
|
|
7
|
-
"semi-round",
|
|
8
|
-
"rounded-extra",
|
|
9
|
-
"rounded-square",
|
|
10
7
|
"circle",
|
|
11
8
|
] as const;
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
// Zod schema
|
|
11
|
+
export const cornerEyePatternSchema = z.enum(CORNER_EYE_PATTERNS);
|
|
12
|
+
|
|
13
|
+
// Inferred type
|
|
14
|
+
export type CornerEyePattern = z.infer<typeof cornerEyePatternSchema>;
|
package/types/image-pattern.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
1
3
|
export const BODY_PATTERN = [
|
|
2
4
|
"circle",
|
|
3
5
|
"circle-large",
|
|
@@ -9,4 +11,8 @@ export const BODY_PATTERN = [
|
|
|
9
11
|
"clean-square",
|
|
10
12
|
] as const;
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
// Zod schema
|
|
15
|
+
export const bodyPatternSchema = z.enum(BODY_PATTERN);
|
|
16
|
+
|
|
17
|
+
// Inferred type
|
|
18
|
+
export type BodyPattern = z.infer<typeof bodyPatternSchema>;
|
package/types/index.ts
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
// Re-export all types from domain files
|
|
2
2
|
|
|
3
3
|
export type { Excavation, Modules } from "./common";
|
|
4
|
+
export { excavationSchema } from "./common";
|
|
5
|
+
|
|
4
6
|
export type { CornerEyeDotPattern } from "./corner-dot";
|
|
5
|
-
export {
|
|
7
|
+
export {
|
|
8
|
+
CORNER_EYE_DOT_PATTERNS,
|
|
9
|
+
cornerEyeDotPatternSchema,
|
|
10
|
+
} from "./corner-dot";
|
|
11
|
+
|
|
6
12
|
export type { CornerEyePattern } from "./corner-eye";
|
|
7
|
-
export { CORNER_EYE_PATTERNS } from "./corner-eye";
|
|
13
|
+
export { CORNER_EYE_PATTERNS, cornerEyePatternSchema } from "./corner-eye";
|
|
14
|
+
|
|
8
15
|
export type { BodyPattern } from "./image-pattern";
|
|
9
|
-
export { BODY_PATTERN } from "./image-pattern";
|
|
16
|
+
export { BODY_PATTERN, bodyPatternSchema } from "./image-pattern";
|
|
17
|
+
|
|
10
18
|
export type {
|
|
19
|
+
ErrorLevel,
|
|
11
20
|
ImageSettings,
|
|
12
21
|
QRProps,
|
|
13
22
|
QRPropsCanvas,
|
|
14
23
|
QRPropsSVG,
|
|
15
24
|
} from "./qr";
|
|
16
|
-
export
|
|
25
|
+
export {
|
|
26
|
+
errorLevelSchema,
|
|
27
|
+
imageSettingsSchema,
|
|
28
|
+
qrPropsSchema,
|
|
29
|
+
} from "./qr";
|
|
30
|
+
|
|
31
|
+
export type {
|
|
32
|
+
BaseTemplateProps,
|
|
33
|
+
TemplateConfig,
|
|
34
|
+
TemplateDefinition,
|
|
35
|
+
} from "./template";
|
|
36
|
+
export {
|
|
37
|
+
baseTemplatePropsSchema,
|
|
38
|
+
templateConfigSchema,
|
|
39
|
+
templateDefinitionBaseSchema,
|
|
40
|
+
} from "./template";
|
package/types/qr.ts
CHANGED
|
@@ -1,22 +1,51 @@
|
|
|
1
1
|
import type { CSSProperties } from "react";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
type CornerEyeDotPattern,
|
|
5
|
+
cornerEyeDotPatternSchema,
|
|
6
|
+
} from "./corner-dot";
|
|
7
|
+
import { type CornerEyePattern, cornerEyePatternSchema } from "./corner-eye";
|
|
8
|
+
import { type BodyPattern, bodyPatternSchema } from "./image-pattern";
|
|
5
9
|
import type { TemplateDefinition } from "./template";
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// Zod schemas
|
|
12
|
+
export const imageSettingsSchema = z.object({
|
|
13
|
+
src: z.string(),
|
|
14
|
+
height: z.number(),
|
|
15
|
+
width: z.number(),
|
|
16
|
+
excavate: z.boolean(),
|
|
17
|
+
x: z.number().optional(),
|
|
18
|
+
y: z.number().optional(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const errorLevelSchema = z.enum(["L", "M", "Q", "H"]);
|
|
22
|
+
|
|
23
|
+
export const qrPropsSchema = z.object({
|
|
24
|
+
value: z.string(),
|
|
25
|
+
size: z.number().optional(),
|
|
26
|
+
level: errorLevelSchema.optional(),
|
|
27
|
+
bgColor: z.string().optional(),
|
|
28
|
+
fgColor: z.string().optional(),
|
|
29
|
+
eyeColor: z.string().optional(),
|
|
30
|
+
dotColor: z.string().optional(),
|
|
31
|
+
bodyPattern: bodyPatternSchema.optional(),
|
|
32
|
+
cornerEyePattern: cornerEyePatternSchema.optional(),
|
|
33
|
+
cornerEyeDotPattern: cornerEyeDotPatternSchema.optional(),
|
|
34
|
+
margin: z.number().optional(),
|
|
35
|
+
imageSettings: imageSettingsSchema.optional(),
|
|
36
|
+
isOGContext: z.boolean().optional(),
|
|
37
|
+
templateId: z.string().optional(),
|
|
38
|
+
customProps: z.record(z.string(), z.any()).optional(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Inferred types
|
|
42
|
+
export type ImageSettings = z.infer<typeof imageSettingsSchema>;
|
|
43
|
+
export type ErrorLevel = z.infer<typeof errorLevelSchema>;
|
|
15
44
|
|
|
16
45
|
export type QRProps = {
|
|
17
46
|
value: string;
|
|
18
47
|
size?: number;
|
|
19
|
-
level?:
|
|
48
|
+
level?: ErrorLevel;
|
|
20
49
|
bgColor?: string;
|
|
21
50
|
fgColor?: string;
|
|
22
51
|
eyeColor?: string;
|
package/types/template.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
// Zod schemas
|
|
4
|
+
export const baseTemplatePropsSchema = z.object({
|
|
5
|
+
fgColor: z.string().optional(),
|
|
6
|
+
bgColor: z.string().optional(),
|
|
7
|
+
});
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Configuration object passed to template wrappers containing all QR code metadata.
|
|
@@ -23,10 +25,22 @@ export type BaseTemplateProps = {
|
|
|
23
25
|
* }
|
|
24
26
|
* ```
|
|
25
27
|
*/
|
|
26
|
-
export
|
|
27
|
-
pixelSize: number
|
|
28
|
-
url: string
|
|
29
|
-
};
|
|
28
|
+
export const templateConfigSchema = z.object({
|
|
29
|
+
pixelSize: z.number(),
|
|
30
|
+
url: z.string(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Note: TemplateDefinition cannot be fully represented in Zod due to React.ReactNode and function types
|
|
34
|
+
// We'll keep the type definition but add validation for the serializable parts
|
|
35
|
+
export const templateDefinitionBaseSchema = z.object({
|
|
36
|
+
id: z.string(),
|
|
37
|
+
name: z.string(),
|
|
38
|
+
description: z.string().optional(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Inferred types
|
|
42
|
+
export type BaseTemplateProps = z.infer<typeof baseTemplatePropsSchema>;
|
|
43
|
+
export type TemplateConfig = z.infer<typeof templateConfigSchema>;
|
|
30
44
|
|
|
31
45
|
// Generic template definition that allows custom props
|
|
32
46
|
export type TemplateDefinition<TCustomProps = Record<string, never>> = {
|