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/types/color.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Color type discriminator
|
|
5
|
+
*/
|
|
6
|
+
export const colorTypeSchema = z.enum(["solid", "linear", "radial"]);
|
|
7
|
+
export type ColorType = z.infer<typeof colorTypeSchema>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Solid color configuration
|
|
11
|
+
*/
|
|
12
|
+
export const solidColorSchema = z.object({
|
|
13
|
+
type: z.literal("solid"),
|
|
14
|
+
color: z.string(),
|
|
15
|
+
});
|
|
16
|
+
export type SolidColor = z.infer<typeof solidColorSchema>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gradient stop configuration
|
|
20
|
+
*/
|
|
21
|
+
export const gradientStopSchema = z.object({
|
|
22
|
+
color: z.string(),
|
|
23
|
+
offset: z.number().min(0).max(100), // percentage: 0-100
|
|
24
|
+
});
|
|
25
|
+
export type GradientStop = z.infer<typeof gradientStopSchema>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Linear gradient configuration
|
|
29
|
+
*/
|
|
30
|
+
export const linearGradientSchema = z.object({
|
|
31
|
+
type: z.literal("linear"),
|
|
32
|
+
stops: z.array(gradientStopSchema).min(2),
|
|
33
|
+
angle: z.number().optional().default(0), // degrees: 0 = left-to-right, 90 = top-to-bottom
|
|
34
|
+
});
|
|
35
|
+
export type LinearGradient = z.infer<typeof linearGradientSchema>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Radial gradient configuration
|
|
39
|
+
* Note: cx, cy, r, fx, fy are calculated automatically based on QR size
|
|
40
|
+
* They use userSpaceOnUse units (absolute pixels)
|
|
41
|
+
*/
|
|
42
|
+
export const radialGradientSchema = z.object({
|
|
43
|
+
type: z.literal("radial"),
|
|
44
|
+
stops: z.array(gradientStopSchema).min(2),
|
|
45
|
+
});
|
|
46
|
+
export type RadialGradient = z.infer<typeof radialGradientSchema>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Union type for color configuration
|
|
50
|
+
* Supports:
|
|
51
|
+
* - string: backward compatible solid color
|
|
52
|
+
* - SolidColor: explicit solid color object
|
|
53
|
+
* - LinearGradient: linear gradient with start/end colors and angle
|
|
54
|
+
* - RadialGradient: radial gradient with start/end colors and positioning
|
|
55
|
+
*/
|
|
56
|
+
export const colorConfigSchema = z.union([
|
|
57
|
+
z.string(),
|
|
58
|
+
solidColorSchema,
|
|
59
|
+
linearGradientSchema,
|
|
60
|
+
radialGradientSchema,
|
|
61
|
+
]);
|
|
62
|
+
export type ColorConfig = z.infer<typeof colorConfigSchema>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Helper to normalize color config to object format
|
|
66
|
+
*/
|
|
67
|
+
export function normalizeColorConfig(
|
|
68
|
+
color: ColorConfig | undefined,
|
|
69
|
+
fallback = "#000000"
|
|
70
|
+
): SolidColor | LinearGradient | RadialGradient {
|
|
71
|
+
if (!color) {
|
|
72
|
+
return { type: "solid", color: fallback };
|
|
73
|
+
}
|
|
74
|
+
if (typeof color === "string") {
|
|
75
|
+
return { type: "solid", color };
|
|
76
|
+
}
|
|
77
|
+
return color;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Helper to check if color is gradient
|
|
82
|
+
*/
|
|
83
|
+
export function isGradient(
|
|
84
|
+
color: ColorConfig | undefined
|
|
85
|
+
): color is LinearGradient | RadialGradient {
|
|
86
|
+
if (!color || typeof color === "string") {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return color.type === "linear" || color.type === "radial";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Helper to get a solid color string from any ColorConfig
|
|
94
|
+
* For gradients, returns the first stop color
|
|
95
|
+
*/
|
|
96
|
+
export function getColorString(
|
|
97
|
+
color: ColorConfig | undefined,
|
|
98
|
+
fallback = "#000000"
|
|
99
|
+
): string {
|
|
100
|
+
const normalized = normalizeColorConfig(color, fallback);
|
|
101
|
+
if (normalized.type === "solid") {
|
|
102
|
+
return normalized.color;
|
|
103
|
+
}
|
|
104
|
+
return normalized.stops[0]?.color || fallback;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function getNormalizedColor(
|
|
108
|
+
color: ColorConfig | string | undefined
|
|
109
|
+
): string {
|
|
110
|
+
if (!color) {
|
|
111
|
+
return "#000000";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (typeof color === "string") {
|
|
115
|
+
return color;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const normalized = normalizeColorConfig(color);
|
|
119
|
+
if (normalized.type === "solid") {
|
|
120
|
+
return normalized.color;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const sortedStops = [...normalized.stops].sort((a, b) => a.offset - b.offset);
|
|
124
|
+
const colorStops = sortedStops
|
|
125
|
+
.map((stop) => `${stop.color} ${stop.offset}%`)
|
|
126
|
+
.join(", ");
|
|
127
|
+
|
|
128
|
+
if (normalized.type === "linear") {
|
|
129
|
+
return `linear-gradient(${normalized.angle ?? 0}deg, ${colorStops})`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return `radial-gradient(circle, ${colorStops})`;
|
|
133
|
+
}
|
package/types/corner-dot.ts
CHANGED
|
@@ -2,9 +2,16 @@ import { z } from "zod";
|
|
|
2
2
|
|
|
3
3
|
export const CORNER_EYE_DOT_PATTERNS = [
|
|
4
4
|
"square",
|
|
5
|
-
"rounded
|
|
5
|
+
"rounded",
|
|
6
6
|
"circle",
|
|
7
7
|
"diamond",
|
|
8
|
+
"message",
|
|
9
|
+
"message-reverse",
|
|
10
|
+
"diya",
|
|
11
|
+
"diya-reverse",
|
|
12
|
+
"rounded-triangle",
|
|
13
|
+
"star",
|
|
14
|
+
"banner",
|
|
8
15
|
] as const;
|
|
9
16
|
|
|
10
17
|
// Zod schema
|
package/types/corner-eye.ts
CHANGED
package/types/image-pattern.ts
CHANGED
package/types/index.ts
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
// Re-export all types from domain files
|
|
2
2
|
|
|
3
|
+
// Re-export utility functions that don't require React
|
|
4
|
+
// These can be used in server contexts without "use client" directive
|
|
5
|
+
export { getSolidColor } from "../src/utils/color";
|
|
6
|
+
export type {
|
|
7
|
+
ColorConfig,
|
|
8
|
+
ColorType,
|
|
9
|
+
GradientStop,
|
|
10
|
+
LinearGradient,
|
|
11
|
+
RadialGradient,
|
|
12
|
+
SolidColor,
|
|
13
|
+
} from "./color";
|
|
14
|
+
export {
|
|
15
|
+
colorConfigSchema,
|
|
16
|
+
colorTypeSchema,
|
|
17
|
+
getColorString,
|
|
18
|
+
getNormalizedColor,
|
|
19
|
+
gradientStopSchema,
|
|
20
|
+
isGradient,
|
|
21
|
+
linearGradientSchema,
|
|
22
|
+
normalizeColorConfig,
|
|
23
|
+
radialGradientSchema,
|
|
24
|
+
solidColorSchema,
|
|
25
|
+
} from "./color";
|
|
3
26
|
export type { Excavation, Modules } from "./common";
|
|
4
27
|
export { excavationSchema } from "./common";
|
|
5
|
-
|
|
6
28
|
export type { CornerEyeDotPattern } from "./corner-dot";
|
|
7
29
|
export {
|
|
8
30
|
CORNER_EYE_DOT_PATTERNS,
|
|
9
31
|
cornerEyeDotPatternSchema,
|
|
10
32
|
} from "./corner-dot";
|
|
11
|
-
|
|
12
33
|
export type { CornerEyePattern } from "./corner-eye";
|
|
13
34
|
export { CORNER_EYE_PATTERNS, cornerEyePatternSchema } from "./corner-eye";
|
|
14
|
-
|
|
15
35
|
export type { BodyPattern } from "./image-pattern";
|
|
16
36
|
export { BODY_PATTERN, bodyPatternSchema } from "./image-pattern";
|
|
17
|
-
|
|
18
37
|
export type {
|
|
19
38
|
ErrorLevel,
|
|
20
39
|
ImageSettings,
|
|
@@ -27,7 +46,6 @@ export {
|
|
|
27
46
|
imageSettingsSchema,
|
|
28
47
|
qrPropsSchema,
|
|
29
48
|
} from "./qr";
|
|
30
|
-
|
|
31
49
|
export type {
|
|
32
50
|
BaseTemplateProps,
|
|
33
51
|
TemplateConfig,
|
package/types/qr.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CSSProperties } from "react";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { type ColorConfig, colorConfigSchema } from "./color";
|
|
3
4
|
import {
|
|
4
5
|
type CornerEyeDotPattern,
|
|
5
6
|
cornerEyeDotPatternSchema,
|
|
@@ -24,10 +25,10 @@ export const qrPropsSchema = z.object({
|
|
|
24
25
|
value: z.string(),
|
|
25
26
|
size: z.number().optional(),
|
|
26
27
|
level: errorLevelSchema.optional(),
|
|
27
|
-
bgColor:
|
|
28
|
-
fgColor:
|
|
29
|
-
eyeColor:
|
|
30
|
-
dotColor:
|
|
28
|
+
bgColor: colorConfigSchema.optional(),
|
|
29
|
+
fgColor: colorConfigSchema.optional(),
|
|
30
|
+
eyeColor: colorConfigSchema.optional(),
|
|
31
|
+
dotColor: colorConfigSchema.optional(),
|
|
31
32
|
bodyPattern: bodyPatternSchema.optional(),
|
|
32
33
|
cornerEyePattern: cornerEyePatternSchema.optional(),
|
|
33
34
|
cornerEyeDotPattern: cornerEyeDotPatternSchema.optional(),
|
|
@@ -46,10 +47,10 @@ export type QRProps = {
|
|
|
46
47
|
value: string;
|
|
47
48
|
size?: number;
|
|
48
49
|
level?: ErrorLevel;
|
|
49
|
-
bgColor?:
|
|
50
|
-
fgColor?:
|
|
51
|
-
eyeColor?:
|
|
52
|
-
dotColor?:
|
|
50
|
+
bgColor?: ColorConfig;
|
|
51
|
+
fgColor?: ColorConfig;
|
|
52
|
+
eyeColor?: ColorConfig;
|
|
53
|
+
dotColor?: ColorConfig;
|
|
53
54
|
bodyPattern?: BodyPattern;
|
|
54
55
|
cornerEyePattern?: CornerEyePattern;
|
|
55
56
|
cornerEyeDotPattern?: CornerEyeDotPattern;
|