qrdx 0.0.59 → 0.0.61

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 (96) hide show
  1. package/README.md +4 -4
  2. package/dist/core.js +7 -7
  3. package/dist/core.js.map +1 -1
  4. package/dist/core.mjs +7 -7
  5. package/dist/core.mjs.map +1 -1
  6. package/dist/element.browser.mjs +6 -6
  7. package/dist/element.browser.mjs.map +1 -1
  8. package/dist/index.js +7 -7
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +7 -7
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/node.js +2 -2
  13. package/dist/node.js.map +1 -1
  14. package/dist/node.mjs +2 -2
  15. package/dist/node.mjs.map +1 -1
  16. package/dist/qr-code-canvas.js +1 -1
  17. package/dist/qr-code-canvas.js.map +1 -1
  18. package/dist/qr-code-canvas.mjs +1 -1
  19. package/dist/qr-code-canvas.mjs.map +1 -1
  20. package/dist/schemas.js +1 -1
  21. package/dist/schemas.js.map +1 -1
  22. package/dist/schemas.mjs +1 -1
  23. package/dist/schemas.mjs.map +1 -1
  24. package/dist/src/api.d.ts +2 -3
  25. package/dist/src/api.d.ts.map +1 -1
  26. package/dist/src/corner-dot.d.ts.map +1 -1
  27. package/dist/src/corner-eye.d.ts.map +1 -1
  28. package/dist/src/engine.d.ts +1 -1
  29. package/dist/src/engine.d.ts.map +1 -1
  30. package/dist/src/looks.d.ts +45 -17
  31. package/dist/src/looks.d.ts.map +1 -1
  32. package/dist/src/qr-code-canvas.d.ts +2 -8
  33. package/dist/src/qr-code-canvas.d.ts.map +1 -1
  34. package/dist/src/qr-code-svg.d.ts +2 -3
  35. package/dist/src/qr-code-svg.d.ts.map +1 -1
  36. package/dist/src/qr-code.d.ts +2 -2
  37. package/dist/src/qr-code.d.ts.map +1 -1
  38. package/dist/src/qr-frame-svg.d.ts +2 -3
  39. package/dist/src/qr-frame-svg.d.ts.map +1 -1
  40. package/dist/src/rasterize.d.ts +8 -0
  41. package/dist/src/rasterize.d.ts.map +1 -1
  42. package/dist/src/react-elements.d.ts.map +1 -1
  43. package/dist/src/scan-risk.d.ts.map +1 -1
  44. package/dist/src/scan-score.d.ts +34 -0
  45. package/dist/src/scan-score.d.ts.map +1 -1
  46. package/dist/src/shapes.d.ts +19 -0
  47. package/dist/src/shapes.d.ts.map +1 -1
  48. package/dist/src/utils/oklab.d.ts +16 -0
  49. package/dist/src/utils/oklab.d.ts.map +1 -0
  50. package/dist/src/utils.d.ts.map +1 -1
  51. package/dist/types/constants.d.ts +40 -5
  52. package/dist/types/constants.d.ts.map +1 -1
  53. package/dist/types/corner-dot.d.ts +11 -6
  54. package/dist/types/corner-dot.d.ts.map +1 -1
  55. package/dist/types/corner-eye.d.ts +21 -8
  56. package/dist/types/corner-eye.d.ts.map +1 -1
  57. package/dist/types/frame-spec.d.ts +1 -1
  58. package/dist/types/frame.d.ts +2 -2
  59. package/dist/types/image-pattern.d.ts +3 -3
  60. package/dist/types/image-pattern.d.ts.map +1 -1
  61. package/dist/types/index.js +2 -2
  62. package/dist/types/index.js.map +1 -1
  63. package/dist/types/index.mjs +2 -2
  64. package/dist/types/index.mjs.map +1 -1
  65. package/dist/types/plain.d.ts +1 -1
  66. package/dist/types/plain.d.ts.map +1 -1
  67. package/dist/types/qr.d.ts +96 -46
  68. package/dist/types/qr.d.ts.map +1 -1
  69. package/dist/types/react.d.ts +21 -3
  70. package/dist/types/react.d.ts.map +1 -1
  71. package/dist/vanilla.browser.mjs +29 -29
  72. package/dist/vanilla.browser.mjs.map +1 -1
  73. package/package.json +4 -6
  74. package/src/api.tsx +3 -4
  75. package/src/corner-dot.tsx +15 -0
  76. package/src/corner-eye.ts +163 -72
  77. package/src/engine.ts +4 -0
  78. package/src/looks.ts +272 -69
  79. package/src/qr-code-canvas.tsx +34 -27
  80. package/src/qr-code-svg.tsx +3 -4
  81. package/src/qr-code.tsx +7 -5
  82. package/src/qr-frame-svg.tsx +3 -4
  83. package/src/rasterize.ts +14 -1
  84. package/src/react-elements.ts +40 -2
  85. package/src/scan-risk.ts +19 -3
  86. package/src/scan-score.ts +231 -48
  87. package/src/shapes.ts +123 -0
  88. package/src/utils/oklab.ts +93 -0
  89. package/src/utils.tsx +20 -4
  90. package/types/constants.ts +59 -3
  91. package/types/corner-dot.ts +17 -7
  92. package/types/corner-eye.ts +26 -8
  93. package/types/image-pattern.ts +11 -4
  94. package/types/plain.ts +4 -0
  95. package/types/qr.ts +5 -3
  96. package/types/react.ts +22 -3
package/src/utils.tsx CHANGED
@@ -19,7 +19,13 @@ import {
19
19
  isImagePaint,
20
20
  normalizeColorConfig,
21
21
  } from "../types/color-helpers";
22
- import { AUTO_LEVEL_LOGO_COVERAGE } from "../types/constants";
22
+ import {
23
+ AUTO_LEVEL_LOGO_COVERAGE,
24
+ WITHDRAWN_BODY_PATTERNS,
25
+ WITHDRAWN_CORNER_EYE_DOT_PATTERNS,
26
+ WITHDRAWN_CORNER_EYE_PATTERNS,
27
+ withdrawnFallback,
28
+ } from "../types/constants";
23
29
  import type { EyePosition, QRCodeShape } from "../types/qr";
24
30
  import { getQRArtEyeColors, isQRArtActive, renderQRArt } from "./art";
25
31
  import {
@@ -954,9 +960,9 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
954
960
  fgColor = DEFAULT_FGCOLOR,
955
961
  eyeColor,
956
962
  dotColor,
957
- bodyPattern = "circle",
958
- cornerEyePattern = "gear",
959
- cornerEyeDotPattern = "circle",
963
+ bodyPattern: requestedBody = "circle",
964
+ cornerEyePattern: requestedEye = "gear",
965
+ cornerEyeDotPattern: requestedDot = "circle",
960
966
  margin = DEFAULT_MARGIN,
961
967
  isOGContext = false,
962
968
  imageSettings: requestedImageSettings,
@@ -979,6 +985,16 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
979
985
  partMarkers,
980
986
  ...otherProps
981
987
  } = props;
988
+ // A shape withdrawn before release draws as the one it maps to
989
+ const bodyPattern = withdrawnFallback(WITHDRAWN_BODY_PATTERNS, requestedBody);
990
+ const cornerEyePattern = withdrawnFallback(
991
+ WITHDRAWN_CORNER_EYE_PATTERNS,
992
+ requestedEye
993
+ );
994
+ const cornerEyeDotPattern = withdrawnFallback(
995
+ WITHDRAWN_CORNER_EYE_DOT_PATTERNS,
996
+ requestedDot
997
+ );
982
998
  // A logo no bigger than the code can repair (logo-budget.ts)
983
999
  const imageSettings = capImageSettings(
984
1000
  { value, size, margin, level, shape, autoLevel, isOGContext },
@@ -55,6 +55,8 @@ export const CORNER_EYE_DOT_PATTERNS = [
55
55
  "extra-rounded",
56
56
  "leaf-reverse",
57
57
  "drop-reverse",
58
+ // Added after 0.0.57
59
+ "cushion",
58
60
  ] as const;
59
61
 
60
62
  /**
@@ -92,6 +94,12 @@ export const CORNER_EYE_PATTERNS = [
92
94
  "shield",
93
95
  "petal",
94
96
  "leaf-reverse",
97
+ // Added after 0.0.57
98
+ "porthole",
99
+ "notch",
100
+ "plus",
101
+ "bud",
102
+ "bowl",
95
103
  ] as const;
96
104
 
97
105
  /**
@@ -130,6 +138,52 @@ export const BODY_PATTERN = [
130
138
  "octagon",
131
139
  ] as const;
132
140
 
141
+ // ── Withdrawn before release ───────────────────────────────────────────────
142
+
143
+ /**
144
+ * Shapes that staging builds offered after 0.0.57 and that were withdrawn
145
+ * before any release: they missed strict decoders in sharp renders, or
146
+ * looked like a shape the catalogue already has. A saved design, link or
147
+ * API call that still names one draws the shape it maps to.
148
+ */
149
+ export const WITHDRAWN_BODY_PATTERNS = {
150
+ x: "plus",
151
+ pebble: "rounded",
152
+ flower: "circle",
153
+ beads: "circle",
154
+ bubble: "circle",
155
+ chain: "circle",
156
+ petal: "leaf",
157
+ drop: "rounded",
158
+ squircle: "rounded",
159
+ } as const satisfies Record<string, (typeof BODY_PATTERN)[number]>;
160
+
161
+ export const WITHDRAWN_CORNER_EYE_PATTERNS = {
162
+ pebble: "squircle",
163
+ tag: "rounded",
164
+ crest: "shield",
165
+ doodle: "squircle",
166
+ stamp: "notch",
167
+ } as const satisfies Record<string, (typeof CORNER_EYE_PATTERNS)[number]>;
168
+
169
+ export const WITHDRAWN_CORNER_EYE_DOT_PATTERNS = {
170
+ bevel: "square",
171
+ notch: "square",
172
+ } as const satisfies Record<string, (typeof CORNER_EYE_DOT_PATTERNS)[number]>;
173
+
174
+ /**
175
+ * The shape to draw for `value`: its replacement when it was withdrawn,
176
+ * otherwise `value` itself (anything else, valid or not, passes through).
177
+ */
178
+ export function withdrawnFallback<T>(
179
+ withdrawn: Readonly<Record<string, string>>,
180
+ value: T
181
+ ): T {
182
+ return typeof value === "string" && Object.hasOwn(withdrawn, value)
183
+ ? (withdrawn[value] as T)
184
+ : value;
185
+ }
186
+
133
187
  // ── Frames (frame.ts) ──────────────────────────────────────────────────────
134
188
 
135
189
  export const FRAME_STYLES = [
@@ -236,9 +290,11 @@ export const BG_RADIUS_QUIET_RATIO = 2;
236
290
  /**
237
291
  * A halo is a light rim around every dark module and eye (`halo`); its
238
292
  * width is in modules. It is a look, not a quiet zone: decoders still need
239
- * `margin`. It is drawn only on an opaque background, in a rim at least as
240
- * light as HALO_LIGHT_MIN and no lighter than the background (looks.ts
241
- * getHaloRisk). The default rim is a light grey, so it shows on white.
293
+ * `margin`. It is drawn only on an opaque background at least as light as
294
+ * HALO_LIGHT_MIN, in a rim at least as light as HALO_LIGHT_MIN and no
295
+ * lighter than the background: any other rim color is drawn in the
296
+ * closest one inside that range (looks.ts fitHaloColor). The default rim
297
+ * is a light grey, so it shows on white.
242
298
  */
243
299
  export const HALO_WIDTH_MIN = 0.1;
244
300
  export const HALO_WIDTH_MAX = 0.5;
@@ -2,22 +2,32 @@ import { z } from "zod";
2
2
  import {
3
3
  CORNER_EYE_DOT_PATTERNS,
4
4
  RETIRED_CORNER_EYE_DOT_PATTERNS,
5
+ WITHDRAWN_CORNER_EYE_DOT_PATTERNS,
6
+ withdrawnFallback,
5
7
  } from "./constants";
6
8
 
7
9
  export {
8
10
  CORNER_EYE_DOT_PATTERNS,
9
11
  RETIRED_CORNER_EYE_DOT_PATTERNS,
12
+ WITHDRAWN_CORNER_EYE_DOT_PATTERNS,
10
13
  } from "./constants";
11
14
 
12
- /** Accepts current and retired values, so saved designs still validate. */
13
- export const cornerEyeDotPatternSchema = z.enum([
14
- ...CORNER_EYE_DOT_PATTERNS,
15
- ...RETIRED_CORNER_EYE_DOT_PATTERNS,
16
- ]);
15
+ const fallback = (value: unknown) =>
16
+ withdrawnFallback(WITHDRAWN_CORNER_EYE_DOT_PATTERNS, value);
17
+
18
+ /**
19
+ * Accepts current and retired values, so saved designs still validate; a
20
+ * withdrawn id parses as the shape it maps to.
21
+ */
22
+ export const cornerEyeDotPatternSchema = z.preprocess(
23
+ fallback,
24
+ z.enum([...CORNER_EYE_DOT_PATTERNS, ...RETIRED_CORNER_EYE_DOT_PATTERNS])
25
+ );
17
26
 
18
27
  /** Current values only: for anything that offers a choice (UI, AI, MCP). */
19
- export const pickableCornerEyeDotPatternSchema = z.enum(
20
- CORNER_EYE_DOT_PATTERNS
28
+ export const pickableCornerEyeDotPatternSchema = z.preprocess(
29
+ fallback,
30
+ z.enum(CORNER_EYE_DOT_PATTERNS)
21
31
  );
22
32
 
23
33
  // Inferred types
@@ -1,16 +1,34 @@
1
1
  import { z } from "zod";
2
- import { CORNER_EYE_PATTERNS, RETIRED_CORNER_EYE_PATTERNS } from "./constants";
2
+ import {
3
+ CORNER_EYE_PATTERNS,
4
+ RETIRED_CORNER_EYE_PATTERNS,
5
+ WITHDRAWN_CORNER_EYE_PATTERNS,
6
+ withdrawnFallback,
7
+ } from "./constants";
3
8
 
4
- export { CORNER_EYE_PATTERNS, RETIRED_CORNER_EYE_PATTERNS } from "./constants";
9
+ export {
10
+ CORNER_EYE_PATTERNS,
11
+ RETIRED_CORNER_EYE_PATTERNS,
12
+ WITHDRAWN_CORNER_EYE_PATTERNS,
13
+ } from "./constants";
5
14
 
6
- /** Accepts current and retired values, so saved designs still validate. */
7
- export const cornerEyePatternSchema = z.enum([
8
- ...CORNER_EYE_PATTERNS,
9
- ...RETIRED_CORNER_EYE_PATTERNS,
10
- ]);
15
+ const fallback = (value: unknown) =>
16
+ withdrawnFallback(WITHDRAWN_CORNER_EYE_PATTERNS, value);
17
+
18
+ /**
19
+ * Accepts current and retired values, so saved designs still validate; a
20
+ * withdrawn id parses as the shape it maps to.
21
+ */
22
+ export const cornerEyePatternSchema = z.preprocess(
23
+ fallback,
24
+ z.enum([...CORNER_EYE_PATTERNS, ...RETIRED_CORNER_EYE_PATTERNS])
25
+ );
11
26
 
12
27
  /** Current values only: for anything that offers a choice (UI, AI, MCP). */
13
- export const pickableCornerEyePatternSchema = z.enum(CORNER_EYE_PATTERNS);
28
+ export const pickableCornerEyePatternSchema = z.preprocess(
29
+ fallback,
30
+ z.enum(CORNER_EYE_PATTERNS)
31
+ );
14
32
 
15
33
  // Inferred types
16
34
  export type CornerEyePattern = z.infer<typeof cornerEyePatternSchema>;
@@ -1,10 +1,17 @@
1
1
  import { z } from "zod";
2
- import { BODY_PATTERN } from "./constants";
2
+ import {
3
+ BODY_PATTERN,
4
+ WITHDRAWN_BODY_PATTERNS,
5
+ withdrawnFallback,
6
+ } from "./constants";
3
7
 
4
- export { BODY_PATTERN } from "./constants";
8
+ export { BODY_PATTERN, WITHDRAWN_BODY_PATTERNS } from "./constants";
5
9
 
6
- // Zod schema
7
- export const bodyPatternSchema = z.enum(BODY_PATTERN);
10
+ // Zod schema: a withdrawn id parses as the shape it maps to
11
+ export const bodyPatternSchema = z.preprocess(
12
+ (value) => withdrawnFallback(WITHDRAWN_BODY_PATTERNS, value),
13
+ z.enum(BODY_PATTERN)
14
+ );
8
15
 
9
16
  // Inferred type
10
17
  export type BodyPattern = z.infer<typeof bodyPatternSchema>;
package/types/plain.ts CHANGED
@@ -75,6 +75,10 @@ export {
75
75
  SHADOW_OPACITY_DEFAULT,
76
76
  SHADOW_OPACITY_MAX,
77
77
  SHADOW_OPACITY_MIN,
78
+ WITHDRAWN_BODY_PATTERNS,
79
+ WITHDRAWN_CORNER_EYE_DOT_PATTERNS,
80
+ WITHDRAWN_CORNER_EYE_PATTERNS,
81
+ withdrawnFallback,
78
82
  } from "./constants";
79
83
  export type {
80
84
  CornerEyeDotPattern,
package/types/qr.ts CHANGED
@@ -183,9 +183,11 @@ export const eyeGradientSpanSchema = z.enum(EYE_GRADIENT_SPANS);
183
183
  * A light rim around every dark module and eye. `width` is in modules
184
184
  * (HALO_WIDTH_MIN to HALO_WIDTH_MAX, default HALO_WIDTH_DEFAULT); `color`
185
185
  * is a solid color (default HALO_COLOR_DEFAULT, #e5e7eb), drawn opaque
186
- * (its alpha is dropped). Drawn only on an opaque background, in a color at
187
- * least as light as HALO_LIGHT_MIN and no lighter than the background
188
- * (getHaloRisk says why not otherwise).
186
+ * (its alpha is dropped). Drawn only on an opaque background at least as
187
+ * light as HALO_LIGHT_MIN (getHaloRisk says why not otherwise). Any color
188
+ * is taken: one decoders read darker than HALO_LIGHT_MIN or lighter than
189
+ * the background is drawn in the closest color between the two
190
+ * (fitHaloColor).
189
191
  */
190
192
  export const haloSchema = z.object({
191
193
  color: z.string().optional(),
package/types/react.ts CHANGED
@@ -1,18 +1,37 @@
1
1
  // Prop types of the React components. Only the React entry (and the
2
2
  // `qrdx/types` entry, for compatibility) reach this file; the core's types
3
3
  // never do, so they work without React's types installed.
4
- import type { CanvasHTMLAttributes, ReactElement, SVGProps } from "react";
4
+ import type { CanvasHTMLAttributes, ReactElement, Ref, SVGProps } from "react";
5
5
  import type { FrameTreeOptions } from "../src/frame";
6
6
  import type { QRCodeProps } from "../src/qr-code-props";
7
7
  import type { QRProps } from "./qr";
8
8
 
9
+ /**
10
+ * What the React components return: `ReactElement<any, any>`, the type that
11
+ * React 18 and 19's types call `JSX.Element`. It's spelled out because the
12
+ * `react` module of @types/react 16 and 17 has no `JSX` to import.
13
+ */
14
+ export type ReactQRElement = ReactElement<any, any>;
15
+
16
+ /**
17
+ * React's attributes for the `<svg>`, with `ref` a ref object or callback.
18
+ * @types/react 16 to 18 also allow a string there (a legacy string ref,
19
+ * which React never took on a function component), and with it a typed set
20
+ * of these props didn't type-check when spread into `QRCode`, a memo
21
+ * component, under those versions' types. React 19's types are the same
22
+ * either way.
23
+ */
24
+ type SVGRootProps = Omit<SVGProps<SVGSVGElement>, "ref"> & {
25
+ ref?: Ref<SVGSVGElement>;
26
+ };
27
+
9
28
  export type QRPropsCanvas = QRProps & CanvasHTMLAttributes<HTMLCanvasElement>;
10
- export type QRPropsSVG = QRProps & SVGProps<SVGSVGElement>;
29
+ export type QRPropsSVG = QRProps & SVGRootProps;
11
30
  /**
12
31
  * React's `QRCode` props: `QRCodeProps` (the logo API included) plus the
13
32
  * SVG attributes, which go on the `<svg>` as with `QRCodeSVG`.
14
33
  */
15
- export type QRCodePropsSVG = QRCodeProps & SVGProps<SVGSVGElement>;
34
+ export type QRCodePropsSVG = QRCodeProps & SVGRootProps;
16
35
 
17
36
  /**
18
37
  * `QRFrameSVG`'s props: the frame, the code size it's laid out around and