qrdx 0.0.46 → 0.0.47

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.
Files changed (206) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -300
  3. package/dist/index.js +27 -7
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +27 -7
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/qr-code-canvas.js +12 -0
  8. package/dist/qr-code-canvas.js.map +1 -0
  9. package/dist/qr-code-canvas.mjs +12 -0
  10. package/dist/qr-code-canvas.mjs.map +1 -0
  11. package/dist/src/api.d.ts.map +1 -1
  12. package/dist/src/art-trace.d.ts +46 -0
  13. package/dist/src/art-trace.d.ts.map +1 -0
  14. package/dist/src/art.d.ts +138 -0
  15. package/dist/src/art.d.ts.map +1 -0
  16. package/dist/src/body-patterns.d.ts +34 -0
  17. package/dist/src/body-patterns.d.ts.map +1 -0
  18. package/dist/src/codegen.d.ts +5 -5
  19. package/dist/src/codegen.d.ts.map +1 -1
  20. package/dist/src/codeword-map.d.ts +40 -0
  21. package/dist/src/codeword-map.d.ts.map +1 -0
  22. package/dist/src/constants.d.ts +4 -7
  23. package/dist/src/constants.d.ts.map +1 -1
  24. package/dist/src/corner-dot.d.ts +3 -1
  25. package/dist/src/corner-dot.d.ts.map +1 -1
  26. package/dist/src/corner-eye.d.ts +5 -2
  27. package/dist/src/corner-eye.d.ts.map +1 -1
  28. package/dist/src/detection.d.ts.map +1 -1
  29. package/dist/src/download.d.ts +22 -5
  30. package/dist/src/download.d.ts.map +1 -1
  31. package/dist/src/eps.d.ts +62 -0
  32. package/dist/src/eps.d.ts.map +1 -0
  33. package/dist/src/frame-icons.d.ts +11 -0
  34. package/dist/src/frame-icons.d.ts.map +1 -0
  35. package/dist/src/frame-import.d.ts +61 -0
  36. package/dist/src/frame-import.d.ts.map +1 -0
  37. package/dist/src/frame-spec.d.ts +24 -0
  38. package/dist/src/frame-spec.d.ts.map +1 -0
  39. package/dist/src/frame-styles.d.ts +50 -0
  40. package/dist/src/frame-styles.d.ts.map +1 -0
  41. package/dist/src/frame.d.ts +126 -0
  42. package/dist/src/frame.d.ts.map +1 -0
  43. package/dist/src/frames/builtin.d.ts +8 -0
  44. package/dist/src/frames/builtin.d.ts.map +1 -0
  45. package/dist/src/frames/official.d.ts +18 -0
  46. package/dist/src/frames/official.d.ts.map +1 -0
  47. package/dist/src/helpers.d.ts +15 -2
  48. package/dist/src/helpers.d.ts.map +1 -1
  49. package/dist/src/index.d.ts +24 -13
  50. package/dist/src/index.d.ts.map +1 -1
  51. package/dist/src/logo-budget.d.ts +54 -0
  52. package/dist/src/logo-budget.d.ts.map +1 -0
  53. package/dist/src/logo-cleanup.d.ts +25 -0
  54. package/dist/src/logo-cleanup.d.ts.map +1 -0
  55. package/dist/src/logo.d.ts +28 -0
  56. package/dist/src/logo.d.ts.map +1 -0
  57. package/dist/src/print.d.ts +73 -0
  58. package/dist/src/print.d.ts.map +1 -0
  59. package/dist/src/qr-code-canvas.d.ts +13 -0
  60. package/dist/src/qr-code-canvas.d.ts.map +1 -0
  61. package/dist/src/qr-code.d.ts +4 -2
  62. package/dist/src/qr-code.d.ts.map +1 -1
  63. package/dist/src/qr-outline.d.ts +41 -0
  64. package/dist/src/qr-outline.d.ts.map +1 -0
  65. package/dist/src/qr-shape.d.ts +72 -0
  66. package/dist/src/qr-shape.d.ts.map +1 -0
  67. package/dist/src/scan-risk.d.ts +40 -0
  68. package/dist/src/scan-risk.d.ts.map +1 -0
  69. package/dist/src/scan-score.d.ts +154 -0
  70. package/dist/src/scan-score.d.ts.map +1 -0
  71. package/dist/src/shapes.d.ts +36 -0
  72. package/dist/src/shapes.d.ts.map +1 -0
  73. package/dist/src/silhouette.d.ts +28 -0
  74. package/dist/src/silhouette.d.ts.map +1 -0
  75. package/dist/src/utils/color.d.ts.map +1 -1
  76. package/dist/src/utils/fmt.d.ts +24 -0
  77. package/dist/src/utils/fmt.d.ts.map +1 -0
  78. package/dist/src/utils/paint.d.ts +80 -0
  79. package/dist/src/utils/paint.d.ts.map +1 -0
  80. package/dist/src/utils/parse-color.d.ts +21 -0
  81. package/dist/src/utils/parse-color.d.ts.map +1 -0
  82. package/dist/src/utils/path-data.d.ts +24 -0
  83. package/dist/src/utils/path-data.d.ts.map +1 -0
  84. package/dist/src/utils/png.d.ts +16 -0
  85. package/dist/src/utils/png.d.ts.map +1 -0
  86. package/dist/src/utils/polygon-clip.d.ts +26 -0
  87. package/dist/src/utils/polygon-clip.d.ts.map +1 -0
  88. package/dist/src/utils/print-shared.d.ts +20 -0
  89. package/dist/src/utils/print-shared.d.ts.map +1 -0
  90. package/dist/src/utils/svg-geometry.d.ts +49 -0
  91. package/dist/src/utils/svg-geometry.d.ts.map +1 -0
  92. package/dist/src/utils/svg-gradient.d.ts +59 -0
  93. package/dist/src/utils/svg-gradient.d.ts.map +1 -0
  94. package/dist/src/utils/svg-painter.d.ts +152 -0
  95. package/dist/src/utils/svg-painter.d.ts.map +1 -0
  96. package/dist/src/utils.d.ts +18 -2
  97. package/dist/src/utils.d.ts.map +1 -1
  98. package/dist/types/art.d.ts +64 -0
  99. package/dist/types/art.d.ts.map +1 -0
  100. package/dist/types/color.d.ts +125 -7
  101. package/dist/types/color.d.ts.map +1 -1
  102. package/dist/types/corner-dot.d.ts +52 -2
  103. package/dist/types/corner-dot.d.ts.map +1 -1
  104. package/dist/types/corner-eye.d.ts +43 -2
  105. package/dist/types/corner-eye.d.ts.map +1 -1
  106. package/dist/types/frame-spec.d.ts +3509 -0
  107. package/dist/types/frame-spec.d.ts.map +1 -0
  108. package/dist/types/frame.d.ts +68 -0
  109. package/dist/types/frame.d.ts.map +1 -0
  110. package/dist/types/image-pattern.d.ts +15 -1
  111. package/dist/types/image-pattern.d.ts.map +1 -1
  112. package/dist/types/index.d.ts +15 -9
  113. package/dist/types/index.d.ts.map +1 -1
  114. package/dist/types/index.js +6 -0
  115. package/dist/types/index.js.map +1 -0
  116. package/dist/types/index.mjs +6 -0
  117. package/dist/types/index.mjs.map +1 -0
  118. package/dist/types/qr.d.ts +1684 -4
  119. package/dist/types/qr.d.ts.map +1 -1
  120. package/dist/types/template.d.ts +2 -2
  121. package/dist/types/template.d.ts.map +1 -1
  122. package/package.json +68 -25
  123. package/src/api.tsx +67 -17
  124. package/src/art-trace.ts +554 -0
  125. package/src/art.tsx +2226 -0
  126. package/src/body-patterns.tsx +389 -0
  127. package/src/codegen.ts +10 -5
  128. package/src/codeword-map.ts +265 -0
  129. package/src/constants.ts +4 -8
  130. package/src/corner-dot.tsx +209 -33
  131. package/src/corner-eye.ts +328 -60
  132. package/src/detection.ts +5 -11
  133. package/src/download.tsx +123 -52
  134. package/src/eps.ts +701 -0
  135. package/src/frame-icons.ts +325 -0
  136. package/src/frame-import.ts +1198 -0
  137. package/src/frame-spec.ts +518 -0
  138. package/src/frame-styles.ts +1095 -0
  139. package/src/frame.tsx +630 -0
  140. package/src/frames/builtin/banner-bottom.json +58 -0
  141. package/src/frames/builtin/circle.json +81 -0
  142. package/src/frames/builtin/rounded-border.json +60 -0
  143. package/src/frames/builtin/ticket.json +51 -0
  144. package/src/frames/builtin.ts +20 -0
  145. package/src/frames/official/attendance.json +110 -0
  146. package/src/frames/official/audio-guide.json +95 -0
  147. package/src/frames/official/book-now.json +103 -0
  148. package/src/frames/official/check-in.json +110 -0
  149. package/src/frames/official/christmas.json +131 -0
  150. package/src/frames/official/donate.json +77 -0
  151. package/src/frames/official/event-ticket.json +77 -0
  152. package/src/frames/official/feedback-bubble.json +73 -0
  153. package/src/frames/official/follow-us.json +83 -0
  154. package/src/frames/official/get-the-app.json +107 -0
  155. package/src/frames/official/halloween.json +80 -0
  156. package/src/frames/official/new-year.json +94 -0
  157. package/src/frames/official/order-at-table.json +86 -0
  158. package/src/frames/official/product-info.json +119 -0
  159. package/src/frames/official/register-product.json +77 -0
  160. package/src/frames/official/review-us.json +127 -0
  161. package/src/frames/official/rsvp-card.json +112 -0
  162. package/src/frames/official/save-contact.json +117 -0
  163. package/src/frames/official/scan-to-pay.json +94 -0
  164. package/src/frames/official/shop-window.json +81 -0
  165. package/src/frames/official/sign-rider.json +81 -0
  166. package/src/frames/official/table-tent.json +75 -0
  167. package/src/frames/official/wifi-card.json +89 -0
  168. package/src/frames/official/winter.json +142 -0
  169. package/src/frames/official.ts +77 -0
  170. package/src/helpers.ts +168 -11
  171. package/src/index.tsx +141 -172
  172. package/src/logo-budget.ts +226 -0
  173. package/src/logo-cleanup.ts +146 -0
  174. package/src/logo.tsx +137 -0
  175. package/src/print.ts +794 -0
  176. package/src/qr-code-canvas.tsx +241 -0
  177. package/src/qr-code.tsx +51 -16
  178. package/src/qr-outline.ts +511 -0
  179. package/src/qr-shape.ts +255 -0
  180. package/src/scan-risk.ts +197 -0
  181. package/src/scan-score.ts +1629 -0
  182. package/src/shapes.ts +169 -0
  183. package/src/silhouette.ts +334 -0
  184. package/src/utils/color.ts +10 -1
  185. package/src/utils/fmt.ts +59 -0
  186. package/src/utils/paint.ts +317 -0
  187. package/src/utils/parse-color.ts +135 -0
  188. package/src/utils/path-data.ts +182 -0
  189. package/src/utils/png.ts +175 -0
  190. package/src/utils/polygon-clip.ts +163 -0
  191. package/src/utils/print-shared.ts +74 -0
  192. package/src/utils/svg-geometry.ts +838 -0
  193. package/src/utils/svg-gradient.ts +407 -0
  194. package/src/utils/svg-painter.ts +946 -0
  195. package/src/utils.tsx +794 -385
  196. package/types/art.ts +74 -0
  197. package/types/color.ts +132 -12
  198. package/types/corner-dot.ts +41 -4
  199. package/types/corner-eye.ts +31 -4
  200. package/types/frame-spec.ts +748 -0
  201. package/types/frame.ts +67 -0
  202. package/types/image-pattern.ts +15 -0
  203. package/types/index.ts +106 -4
  204. package/types/qr.ts +180 -2
  205. package/types/template.ts +2 -2
  206. package/dist/cli.js +0 -4319
package/types/frame.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+
3
+ export const FRAME_STYLES = [
4
+ "none",
5
+ "banner-bottom",
6
+ "banner-top",
7
+ "border",
8
+ "rounded-border",
9
+ "speech-bubble",
10
+ // Added after 0.0.46
11
+ "banner-top-bottom",
12
+ "speech-bubble-top",
13
+ "chat-bubble",
14
+ "circle",
15
+ "polaroid",
16
+ "phone",
17
+ "ticket",
18
+ "badge",
19
+ "envelope",
20
+ "tag",
21
+ "menu-card",
22
+ "sticker",
23
+ "gradient-border",
24
+ "focus",
25
+ ] as const;
26
+
27
+ /** Longest call-to-action label a frame renders. */
28
+ export const FRAME_TEXT_MAX_LENGTH = 24;
29
+
30
+ /** Label used when a frame has no `text`. Pass `""` to hide the label. */
31
+ export const DEFAULT_FRAME_TEXT = "Scan me";
32
+
33
+ /** Smallest and largest `fontScale` (label size relative to the default). */
34
+ export const FRAME_FONT_SCALE_MIN = 0.5;
35
+ export const FRAME_FONT_SCALE_MAX = 1.5;
36
+
37
+ // Zod schemas
38
+ export const frameStyleSchema = z.enum(FRAME_STYLES);
39
+
40
+ export const frameSchema = z.object({
41
+ style: frameStyleSchema,
42
+ text: z.string().max(FRAME_TEXT_MAX_LENGTH).optional(),
43
+ color: z.string().optional(),
44
+ textColor: z.string().optional(),
45
+ /**
46
+ * Second label: the bottom band of "banner-top-bottom", the lower arc of
47
+ * "circle" and the footer of "menu-card". Other styles ignore it.
48
+ */
49
+ secondaryText: z.string().max(FRAME_TEXT_MAX_LENGTH).optional(),
50
+ /** End color of "gradient-border" (the gradient runs from `color`). */
51
+ secondaryColor: z.string().optional(),
52
+ /** Label size relative to the default, 0.5 to 1.5 (labels still fit). */
53
+ fontScale: z
54
+ .number()
55
+ .min(FRAME_FONT_SCALE_MIN)
56
+ .max(FRAME_FONT_SCALE_MAX)
57
+ .optional(),
58
+ });
59
+
60
+ // Inferred types
61
+ export type FrameStyle = z.infer<typeof frameStyleSchema>;
62
+
63
+ /**
64
+ * Call-to-action frame drawn around the QR code. The frame adds space around
65
+ * the code, so the QR modules and quiet zone are never covered.
66
+ */
67
+ export type QRFrame = z.infer<typeof frameSchema>;
@@ -10,6 +10,21 @@ export const BODY_PATTERN = [
10
10
  "rounded",
11
11
  "small-square",
12
12
  "vertical-line",
13
+ // Added after 0.0.46 (drawn by src/body-patterns.tsx)
14
+ "horizontal-line",
15
+ "liquid",
16
+ "liquid-horizontal",
17
+ "liquid-vertical",
18
+ "classy",
19
+ "classy-rounded",
20
+ "leaf",
21
+ "plus",
22
+ "hexagon",
23
+ "star",
24
+ "heart",
25
+ "random-dots",
26
+ "mosaic",
27
+ "octagon",
13
28
  ] as const;
14
29
 
15
30
  // Zod schema
package/types/index.ts CHANGED
@@ -1,23 +1,45 @@
1
1
  // Re-export all types from domain files
2
2
 
3
+ export { DEFAULT_MARGIN } from "../src/constants";
3
4
  // Re-export utility functions that don't require React
4
5
  // These can be used in server contexts without "use client" directive
5
6
  export { getSolidColor } from "../src/utils/color";
7
+ export type { QRArt, QRArtImage, QRArtMode, QRArtVariant } from "./art";
8
+ export {
9
+ QR_ART_MAX_SAMPLE_SIZE,
10
+ QR_ART_MODES,
11
+ QR_ART_VARIANTS,
12
+ qrArtImageSchema,
13
+ qrArtModeSchema,
14
+ qrArtSchema,
15
+ qrArtVariantSchema,
16
+ } from "./art";
6
17
  export type {
18
+ AngularGradient,
7
19
  ColorConfig,
8
20
  ColorType,
21
+ Gradient,
9
22
  GradientStop,
23
+ ImageFit,
24
+ ImagePaint,
25
+ ImagePosition,
10
26
  LinearGradient,
11
27
  RadialGradient,
12
28
  SolidColor,
13
29
  } from "./color";
14
30
  export {
31
+ angularGradientSchema,
15
32
  colorConfigSchema,
16
33
  colorTypeSchema,
17
34
  getColorString,
18
35
  getNormalizedColor,
19
36
  gradientStopSchema,
37
+ imageFitSchema,
38
+ imagePaintSchema,
39
+ imagePositionCss,
40
+ imagePositionSchema,
20
41
  isGradient,
42
+ isImagePaint,
21
43
  linearGradientSchema,
22
44
  normalizeColorConfig,
23
45
  radialGradientSchema,
@@ -25,27 +47,107 @@ export {
25
47
  } from "./color";
26
48
  export type { Excavation, Modules } from "./common";
27
49
  export { excavationSchema } from "./common";
28
- export type { CornerEyeDotPattern } from "./corner-dot";
50
+ export type {
51
+ CornerEyeDotPattern,
52
+ PickableCornerEyeDotPattern,
53
+ } from "./corner-dot";
29
54
  export {
30
55
  CORNER_EYE_DOT_PATTERNS,
31
56
  cornerEyeDotPatternSchema,
57
+ pickableCornerEyeDotPatternSchema,
58
+ RETIRED_CORNER_EYE_DOT_PATTERNS,
32
59
  } from "./corner-dot";
33
- export type { CornerEyePattern } from "./corner-eye";
34
- export { CORNER_EYE_PATTERNS, cornerEyePatternSchema } from "./corner-eye";
60
+ export type { CornerEyePattern, PickableCornerEyePattern } from "./corner-eye";
61
+ export {
62
+ CORNER_EYE_PATTERNS,
63
+ cornerEyePatternSchema,
64
+ pickableCornerEyePatternSchema,
65
+ RETIRED_CORNER_EYE_PATTERNS,
66
+ } from "./corner-eye";
67
+ export type { FrameStyle, QRFrame } from "./frame";
68
+ export {
69
+ DEFAULT_FRAME_TEXT,
70
+ FRAME_FONT_SCALE_MAX,
71
+ FRAME_FONT_SCALE_MIN,
72
+ FRAME_STYLES,
73
+ FRAME_TEXT_MAX_LENGTH,
74
+ frameSchema,
75
+ frameStyleSchema,
76
+ } from "./frame";
77
+ export type {
78
+ AnyQRFrame,
79
+ FrameSpec,
80
+ FrameSpecColor,
81
+ FrameSpecIcon,
82
+ FrameSpecLabel,
83
+ FrameSpecPaint,
84
+ FrameSpecShape,
85
+ QRCustomFrame,
86
+ } from "./frame-spec";
87
+ export {
88
+ anyFrameSchema,
89
+ CUSTOM_FRAME_STYLE,
90
+ customFrameSchema,
91
+ FRAME_COLOR_TOKENS,
92
+ FRAME_ICON_MAX_SEGMENTS,
93
+ FRAME_ICONS,
94
+ FRAME_SPEC_KIND,
95
+ FRAME_SPEC_LABEL_MAX_FONT,
96
+ FRAME_SPEC_LIMITS,
97
+ FRAME_SPEC_VERSION,
98
+ frameSpecColorSchema,
99
+ frameSpecLabelSchema,
100
+ frameSpecPadding,
101
+ frameSpecPaintSchema,
102
+ frameSpecQrZone,
103
+ frameSpecSchema,
104
+ frameSpecShapeSchema,
105
+ getFrameSpecIssues,
106
+ isLatin1Text,
107
+ sanitizeFrameText,
108
+ } from "./frame-spec";
35
109
  export type { BodyPattern } from "./image-pattern";
36
110
  export { BODY_PATTERN, bodyPatternSchema } from "./image-pattern";
37
- export { DEFAULT_MARGIN } from "../src/constants";
38
111
  export type {
39
112
  ErrorLevel,
113
+ EyeColorOverride,
114
+ EyeColors,
115
+ EyePosition,
40
116
  ImageSettings,
117
+ LogoOptions,
118
+ LogoShape,
119
+ QRCodeShape,
41
120
  QRProps,
42
121
  QRPropsCanvas,
43
122
  QRPropsSVG,
123
+ QRShape,
124
+ QRSilhouette,
44
125
  } from "./qr";
45
126
  export {
127
+ AUTO_LEVEL_LOGO_COVERAGE,
128
+ EYE_POSITIONS,
46
129
  errorLevelSchema,
130
+ eyeColorOverrideSchema,
131
+ eyeColorsSchema,
47
132
  imageSettingsSchema,
133
+ LOGO_PADDING_MAX,
134
+ LOGO_SHAPES,
135
+ LOGO_SIZE_DEFAULT,
136
+ LOGO_SIZE_MAX,
137
+ LOGO_SIZE_MIN,
138
+ logoOptionsSchema,
139
+ logoShapeSchema,
140
+ MODULE_SCALE_MAX,
141
+ MODULE_SCALE_MIN,
142
+ QR_CIRCLE_QUIET_MIN,
143
+ QR_SHAPES,
144
+ QR_SILHOUETTE_MAX_CELLS,
145
+ QR_SILHOUETTE_MIN_CELLS,
146
+ QR_SILHOUETTE_MIN_SHARE,
147
+ qrCodeShapeSchema,
48
148
  qrPropsSchema,
149
+ qrShapeSchema,
150
+ qrSilhouetteSchema,
49
151
  } from "./qr";
50
152
  export type {
51
153
  BaseTemplateProps,
package/types/qr.ts CHANGED
@@ -1,14 +1,24 @@
1
1
  import type { CSSProperties } from "react";
2
2
  import { z } from "zod";
3
+ import { type QRArt, qrArtSchema } from "./art";
3
4
  import { type ColorConfig, colorConfigSchema } from "./color";
4
5
  import {
5
6
  type CornerEyeDotPattern,
6
7
  cornerEyeDotPatternSchema,
7
8
  } from "./corner-dot";
8
9
  import { type CornerEyePattern, cornerEyePatternSchema } from "./corner-eye";
10
+ import { type AnyQRFrame, anyFrameSchema } from "./frame-spec";
9
11
  import { type BodyPattern, bodyPatternSchema } from "./image-pattern";
10
12
  import type { TemplateDefinition } from "./template";
11
13
 
14
+ /**
15
+ * How a logo is cropped: "square" (as uploaded), "rounded" corners or a
16
+ * "circle". A plate behind the logo takes the same shape.
17
+ */
18
+ export const LOGO_SHAPES = ["square", "rounded", "circle"] as const;
19
+ export const logoShapeSchema = z.enum(LOGO_SHAPES);
20
+ export type LogoShape = z.infer<typeof logoShapeSchema>;
21
+
12
22
  // Zod schemas
13
23
  export const imageSettingsSchema = z.object({
14
24
  src: z.string(),
@@ -17,10 +27,144 @@ export const imageSettingsSchema = z.object({
17
27
  excavate: z.boolean(),
18
28
  x: z.number().optional(),
19
29
  y: z.number().optional(),
30
+ /**
31
+ * Extra clear space around the logo when `excavate` is on, in the same
32
+ * pixels as `width` and `height` (default 0).
33
+ */
34
+ padding: z.number().min(0).optional(),
35
+ /** Crop the logo to this shape (default "square": no crop). */
36
+ shape: logoShapeSchema.optional(),
37
+ /**
38
+ * Solid color of a plate behind the logo, in the logo's shape. The plate
39
+ * fills the logo box and the logo is drawn inset inside it.
40
+ */
41
+ plate: z.string().optional(),
42
+ });
43
+
44
+ /**
45
+ * Smallest and largest logo width, as a share of the code's width. Above
46
+ * 25% even level H stops reading in our decode tests (tests/engine-options).
47
+ */
48
+ export const LOGO_SIZE_MIN = 0.1;
49
+ export const LOGO_SIZE_MAX = 0.3;
50
+ /** Logo width `getQRData` uses when no size is given (25%). */
51
+ export const LOGO_SIZE_DEFAULT = 0.25;
52
+ /** Most clear space around a logo, in modules. */
53
+ export const LOGO_PADDING_MAX = 2;
54
+
55
+ /**
56
+ * Logo layout for `getQRData` and `<QRCode>`, in units that don't depend on
57
+ * the render size: `size` is a share of the code's width, `padding` is clear
58
+ * space in modules, `x` and `y` place the logo's center across the code
59
+ * (0 to 1, 0.5 is the middle; the logo always stays inside the code).
60
+ * `shape` crops it and `plate` draws a solid plate behind it.
61
+ */
62
+ export const logoOptionsSchema = z.object({
63
+ size: z.number().min(LOGO_SIZE_MIN).max(LOGO_SIZE_MAX).optional(),
64
+ padding: z.number().min(0).max(LOGO_PADDING_MAX).optional(),
65
+ x: z.number().min(0).max(1).optional(),
66
+ y: z.number().min(0).max(1).optional(),
67
+ shape: logoShapeSchema.optional(),
68
+ plate: z.string().optional(),
20
69
  });
70
+ export type LogoOptions = z.infer<typeof logoOptionsSchema>;
21
71
 
22
72
  export const errorLevelSchema = z.enum(["L", "M", "Q", "H"]);
23
73
 
74
+ /** Smallest and largest `moduleScale` (size of each data module). */
75
+ export const MODULE_SCALE_MIN = 0.5;
76
+ export const MODULE_SCALE_MAX = 1;
77
+
78
+ /**
79
+ * Share of the code a logo may cover before `autoLevel` raises error
80
+ * correction to H (level L recovers about 7%).
81
+ */
82
+ export const AUTO_LEVEL_LOGO_COVERAGE = 0.07;
83
+
84
+ /**
85
+ * Outline of the whole code: "square" (the QR symbol as is), "circle" or
86
+ * "heart": the symbol sits in a disc or a heart filled with decorative
87
+ * modules. Decoders read only the symbol, which keeps its quiet ring
88
+ * (`margin`, at least QR_CIRCLE_QUIET_MIN modules) before the decoration
89
+ * starts. `shape` also takes a `QRSilhouette`, an outline of your own.
90
+ */
91
+ export const QR_SHAPES = ["square", "circle", "heart"] as const;
92
+ export const qrShapeSchema = z.enum(QR_SHAPES);
93
+ export type QRShape = z.infer<typeof qrShapeSchema>;
94
+ /** Smallest light ring between a shaped code's symbol and its decoration. */
95
+ export const QR_CIRCLE_QUIET_MIN = 3;
96
+
97
+ /** Most cells along a silhouette's longer side. */
98
+ export const QR_SILHOUETTE_MAX_CELLS = 64;
99
+ /** Fewest cells along each side of a silhouette. */
100
+ export const QR_SILHOUETTE_MIN_CELLS = 8;
101
+ /**
102
+ * Smallest share of the artwork's width the symbol and its quiet ring may
103
+ * take inside a silhouette (a circle code's is about 0.7, a heart's 0.6).
104
+ * Thinner silhouettes are refused: the code would be a small square in a
105
+ * large field of decoration.
106
+ */
107
+ export const QR_SILHOUETTE_MIN_SHARE = 0.42;
108
+
109
+ /**
110
+ * An outline of your own for `shape`: a small grid sampled from a picture's
111
+ * alpha or darkness (`createQRSilhouette`, `loadQRSilhouette`), never the
112
+ * picture itself. The symbol sits in the middle of the silhouette's largest
113
+ * square and the rest of it fills with decorative modules, like a circle
114
+ * code. `getQRSilhouetteFit` says whether one is roomy enough; one that
115
+ * isn't draws as a square code.
116
+ */
117
+ export const qrSilhouetteSchema = z
118
+ .object({
119
+ type: z.literal("silhouette"),
120
+ width: z
121
+ .number()
122
+ .int()
123
+ .min(QR_SILHOUETTE_MIN_CELLS)
124
+ .max(QR_SILHOUETTE_MAX_CELLS),
125
+ height: z
126
+ .number()
127
+ .int()
128
+ .min(QR_SILHOUETTE_MIN_CELLS)
129
+ .max(QR_SILHOUETTE_MAX_CELLS),
130
+ cells: z
131
+ .string()
132
+ .max(QR_SILHOUETTE_MAX_CELLS * QR_SILHOUETTE_MAX_CELLS)
133
+ .regex(/^[01]*$/)
134
+ .describe(
135
+ 'Row by row, "1" inside the shape and "0" outside: width × height characters'
136
+ ),
137
+ })
138
+ .refine(
139
+ (silhouette) =>
140
+ silhouette.cells.length === silhouette.width * silhouette.height,
141
+ {
142
+ message: "Silhouette cells do not match its width and height",
143
+ }
144
+ );
145
+ export type QRSilhouette = z.infer<typeof qrSilhouetteSchema>;
146
+
147
+ /** What `shape` takes: a named outline or a silhouette. */
148
+ export const qrCodeShapeSchema = z.union([qrShapeSchema, qrSilhouetteSchema]);
149
+ export type QRCodeShape = QRShape | QRSilhouette;
150
+
151
+ /** The three finder patterns, for per-eye colors. */
152
+ export const EYE_POSITIONS = ["topLeft", "topRight", "bottomLeft"] as const;
153
+ export type EyePosition = (typeof EYE_POSITIONS)[number];
154
+
155
+ /** Colors of one eye: `outer` is the frame, `inner` the dot in it. */
156
+ export const eyeColorOverrideSchema = z.object({
157
+ outer: colorConfigSchema.optional(),
158
+ inner: colorConfigSchema.optional(),
159
+ });
160
+
161
+ /** Per-eye overrides of `eyeColor` (outer) and `dotColor` (inner). */
162
+ export const eyeColorsSchema = z.object({
163
+ topLeft: eyeColorOverrideSchema.optional(),
164
+ topRight: eyeColorOverrideSchema.optional(),
165
+ bottomLeft: eyeColorOverrideSchema.optional(),
166
+ });
167
+
24
168
  export const qrPropsSchema = z.object({
25
169
  value: z.string(),
26
170
  size: z.number().optional(),
@@ -37,13 +181,25 @@ export const qrPropsSchema = z.object({
37
181
  isOGContext: z.boolean().optional(),
38
182
  templateId: z.string().optional(),
39
183
  customProps: z.record(z.string(), z.any()).optional(),
184
+ frame: anyFrameSchema.optional(),
185
+ art: qrArtSchema.optional(),
186
+ eyeColors: eyeColorsSchema.optional(),
187
+ moduleScale: z
188
+ .number()
189
+ .min(MODULE_SCALE_MIN)
190
+ .max(MODULE_SCALE_MAX)
191
+ .optional(),
192
+ autoLevel: z.boolean().optional(),
193
+ shape: qrCodeShapeSchema.optional(),
40
194
  });
41
195
 
42
196
  // Inferred types
43
197
  export type ImageSettings = z.infer<typeof imageSettingsSchema>;
44
198
  export type ErrorLevel = z.infer<typeof errorLevelSchema>;
199
+ export type EyeColorOverride = z.infer<typeof eyeColorOverrideSchema>;
200
+ export type EyeColors = z.infer<typeof eyeColorsSchema>;
45
201
 
46
- export type QRProps = {
202
+ export interface QRProps {
47
203
  value: string;
48
204
  size?: number;
49
205
  level?: ErrorLevel;
@@ -64,7 +220,29 @@ export type QRProps = {
64
220
  // Generic custom props that can be used by any template
65
221
  // Each template can define its own custom props type (e.g., FlamQRProps)
66
222
  customProps?: Record<string, any>;
67
- };
223
+ // Frame around the code: a built-in style, or { style: "custom", spec }
224
+ // (see types/frame-spec.ts); the rendered output grows to fit it
225
+ frame?: AnyQRFrame;
226
+ // Blend a logo or photo into the modules (vector, no AI); see types/art.ts
227
+ art?: QRArt;
228
+ // Per-eye colors; each overrides eyeColor (outer) / dotColor (inner)
229
+ eyeColors?: EyeColors;
230
+ // Size of each data module, 0.5 to 1 (default 1). Connected styles get
231
+ // thinner lines instead. Alignment patterns stay full size.
232
+ moduleScale?: number;
233
+ // Raise error correction to H when the logo covers more than 7% of the
234
+ // code (off by default, so existing output never changes)
235
+ autoLevel?: boolean;
236
+ // Outline: "circle" or "heart" puts the symbol in a disc or a heart of
237
+ // decorative modules (see QR_SHAPES); a QRSilhouette fills an outline of
238
+ // your own. Ignored with a template.
239
+ shape?: QRCodeShape;
240
+ // For editors drawing a live preview: marks each frame label <text> with
241
+ // data-qrdx-frame-label (its FrameLabel.field). Off by default, and every
242
+ // export (getQRAsSVGDataUri and the PNG, JPG, PDF and EPS built on it)
243
+ // drops it, so downloads never carry the marker.
244
+ frameLabelMarkers?: boolean;
245
+ }
68
246
 
69
247
  export type QRPropsCanvas = QRProps &
70
248
  React.CanvasHTMLAttributes<HTMLCanvasElement>;
package/types/template.ts CHANGED
@@ -43,7 +43,7 @@ export type BaseTemplateProps = z.infer<typeof baseTemplatePropsSchema>;
43
43
  export type TemplateConfig = z.infer<typeof templateConfigSchema>;
44
44
 
45
45
  // Generic template definition that allows custom props
46
- export type TemplateDefinition<TCustomProps = Record<string, never>> = {
46
+ export interface TemplateDefinition<TCustomProps = Record<string, never>> {
47
47
  id: string;
48
48
  name: string;
49
49
  description?: string;
@@ -52,4 +52,4 @@ export type TemplateDefinition<TCustomProps = Record<string, never>> = {
52
52
  props?: BaseTemplateProps & TCustomProps,
53
53
  templateConfig?: TemplateConfig
54
54
  ) => React.ReactNode;
55
- };
55
+ }