qrdx 0.0.58 → 0.0.60

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 (73) hide show
  1. package/README.md +3 -3
  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/qr-code-canvas.js +1 -1
  13. package/dist/qr-code-canvas.js.map +1 -1
  14. package/dist/qr-code-canvas.mjs +1 -1
  15. package/dist/qr-code-canvas.mjs.map +1 -1
  16. package/dist/schemas.js +1 -1
  17. package/dist/schemas.js.map +1 -1
  18. package/dist/schemas.mjs +1 -1
  19. package/dist/schemas.mjs.map +1 -1
  20. package/dist/src/corner-dot.d.ts.map +1 -1
  21. package/dist/src/corner-eye.d.ts.map +1 -1
  22. package/dist/src/engine.d.ts +1 -1
  23. package/dist/src/engine.d.ts.map +1 -1
  24. package/dist/src/looks.d.ts +45 -17
  25. package/dist/src/looks.d.ts.map +1 -1
  26. package/dist/src/qr-code-props.d.ts +10 -1
  27. package/dist/src/qr-code-props.d.ts.map +1 -1
  28. package/dist/src/qr-code.d.ts.map +1 -1
  29. package/dist/src/scan-risk.d.ts.map +1 -1
  30. package/dist/src/scan-score.d.ts.map +1 -1
  31. package/dist/src/shapes.d.ts +19 -0
  32. package/dist/src/shapes.d.ts.map +1 -1
  33. package/dist/src/utils/oklab.d.ts +16 -0
  34. package/dist/src/utils/oklab.d.ts.map +1 -0
  35. package/dist/src/utils.d.ts.map +1 -1
  36. package/dist/types/constants.d.ts +40 -5
  37. package/dist/types/constants.d.ts.map +1 -1
  38. package/dist/types/corner-dot.d.ts +11 -6
  39. package/dist/types/corner-dot.d.ts.map +1 -1
  40. package/dist/types/corner-eye.d.ts +21 -8
  41. package/dist/types/corner-eye.d.ts.map +1 -1
  42. package/dist/types/frame-spec.d.ts +1 -1
  43. package/dist/types/frame.d.ts +2 -2
  44. package/dist/types/image-pattern.d.ts +3 -3
  45. package/dist/types/image-pattern.d.ts.map +1 -1
  46. package/dist/types/index.js +2 -2
  47. package/dist/types/index.js.map +1 -1
  48. package/dist/types/index.mjs +2 -2
  49. package/dist/types/index.mjs.map +1 -1
  50. package/dist/types/plain.d.ts +1 -1
  51. package/dist/types/plain.d.ts.map +1 -1
  52. package/dist/types/qr.d.ts +96 -46
  53. package/dist/types/qr.d.ts.map +1 -1
  54. package/dist/vanilla.browser.mjs +29 -29
  55. package/dist/vanilla.browser.mjs.map +1 -1
  56. package/package.json +1 -1
  57. package/src/corner-dot.tsx +15 -0
  58. package/src/corner-eye.ts +163 -72
  59. package/src/engine.ts +4 -0
  60. package/src/looks.ts +272 -69
  61. package/src/qr-code-props.ts +38 -25
  62. package/src/qr-code.tsx +7 -39
  63. package/src/scan-risk.ts +19 -3
  64. package/src/scan-score.ts +11 -1
  65. package/src/shapes.ts +123 -0
  66. package/src/utils/oklab.ts +93 -0
  67. package/src/utils.tsx +20 -4
  68. package/types/constants.ts +59 -3
  69. package/types/corner-dot.ts +17 -7
  70. package/types/corner-eye.ts +26 -8
  71. package/types/image-pattern.ts +11 -4
  72. package/types/plain.ts +4 -0
  73. package/types/qr.ts +5 -3
package/src/shapes.ts CHANGED
@@ -57,6 +57,25 @@ export function roundedRectPath(
57
57
  );
58
58
  }
59
59
 
60
+ /** Square with `cut` chamfered off each corner, clockwise from the top. */
61
+ export function octagonPoints(
62
+ x: number,
63
+ y: number,
64
+ size: number,
65
+ cut: number
66
+ ): Point[] {
67
+ return [
68
+ [x + cut, y],
69
+ [x + size - cut, y],
70
+ [x + size, y + cut],
71
+ [x + size, y + size - cut],
72
+ [x + size - cut, y + size],
73
+ [x + cut, y + size],
74
+ [x, y + size - cut],
75
+ [x, y + cut],
76
+ ];
77
+ }
78
+
60
79
  /** Points of a regular polygon (clockwise), first vertex at `rotation` degrees. */
61
80
  export function regularPolygon(
62
81
  cx: number,
@@ -167,3 +186,107 @@ export function hashString(value: string): string {
167
186
  }
168
187
  return (h >>> 0).toString(36);
169
188
  }
189
+
190
+ /**
191
+ * Rectangle whose corners are scooped out by concave quarter circles of
192
+ * radius `scoop` (clockwise, like roundedRectPath).
193
+ */
194
+ export function scoopedRectPath(
195
+ x: number,
196
+ y: number,
197
+ width: number,
198
+ height: number,
199
+ scoop: number
200
+ ): string {
201
+ const s = Math.max(0, Math.min(scoop, Math.min(width, height) / 2));
202
+ const arc = (toX: number, toY: number) =>
203
+ `A${fmt(s)} ${fmt(s)} 0 0 0 ${fmt(toX)} ${fmt(toY)}`;
204
+ return (
205
+ `M${fmt(x + s)} ${fmt(y)}` +
206
+ `H${fmt(x + width - s)}${arc(x + width, y + s)}` +
207
+ `V${fmt(y + height - s)}${arc(x + width - s, y + height)}` +
208
+ `H${fmt(x + s)}${arc(x, y + height - s)}` +
209
+ `V${fmt(y + s)}${arc(x + s, y)}Z`
210
+ );
211
+ }
212
+
213
+ /** Rectangle with a square notch of side `notch` cut from each corner. */
214
+ export function notchedRectPath(
215
+ x: number,
216
+ y: number,
217
+ width: number,
218
+ height: number,
219
+ notch: number
220
+ ): string {
221
+ const n = Math.max(0, Math.min(notch, Math.min(width, height) / 2));
222
+ return polygonPath([
223
+ [x + n, y],
224
+ [x + width - n, y],
225
+ [x + width - n, y + n],
226
+ [x + width, y + n],
227
+ [x + width, y + height - n],
228
+ [x + width - n, y + height - n],
229
+ [x + width - n, y + height],
230
+ [x + n, y + height],
231
+ [x + n, y + height - n],
232
+ [x, y + height - n],
233
+ [x, y + n],
234
+ [x + n, y + n],
235
+ ]);
236
+ }
237
+
238
+ /**
239
+ * Rounded square whose sides pinch in slightly, like a cushion. Sides meet
240
+ * the corners tangentially, so the outline has no kinks.
241
+ */
242
+ export function cushionPath(
243
+ x: number,
244
+ y: number,
245
+ size: number,
246
+ radius: number,
247
+ pinch: number
248
+ ): string {
249
+ const r = radius;
250
+ const mid = size / 2;
251
+ const pull = (mid - r) * 0.55;
252
+ const P = (px: number, py: number) => `${fmt(x + px)} ${fmt(y + py)}`;
253
+ return (
254
+ `M${P(r, 0)}` +
255
+ `C${P(r + pull, 0)} ${P(mid - pull, pinch)} ${P(mid, pinch)}` +
256
+ `C${P(mid + pull, pinch)} ${P(size - r - pull, 0)} ${P(size - r, 0)}` +
257
+ `A${fmt(r)} ${fmt(r)} 0 0 1 ${P(size, r)}` +
258
+ `C${P(size, r + pull)} ${P(size - pinch, mid - pull)} ${P(size - pinch, mid)}` +
259
+ `C${P(size - pinch, mid + pull)} ${P(size, size - r - pull)} ${P(size, size - r)}` +
260
+ `A${fmt(r)} ${fmt(r)} 0 0 1 ${P(size - r, size)}` +
261
+ `C${P(size - r - pull, size)} ${P(mid + pull, size - pinch)} ${P(mid, size - pinch)}` +
262
+ `C${P(mid - pull, size - pinch)} ${P(r + pull, size)} ${P(r, size)}` +
263
+ `A${fmt(r)} ${fmt(r)} 0 0 1 ${P(0, size - r)}` +
264
+ `C${P(0, size - r - pull)} ${P(pinch, mid + pull)} ${P(pinch, mid)}` +
265
+ `C${P(pinch, mid - pull)} ${P(0, r + pull)} ${P(0, r)}` +
266
+ `A${fmt(r)} ${fmt(r)} 0 0 1 ${P(r, 0)}Z`
267
+ );
268
+ }
269
+
270
+ /**
271
+ * Shield: flat top with corners of `radius`, straight sides down to
272
+ * `shoulder`, then curving to a point at the bottom. `m` scales the curve.
273
+ */
274
+ export function shieldPath(
275
+ x: number,
276
+ y: number,
277
+ size: number,
278
+ radius: number,
279
+ shoulder: number,
280
+ m: number
281
+ ): string {
282
+ const mid = size / 2;
283
+ const P = (px: number, py: number) => `${fmt(x + px)} ${fmt(y + py)}`;
284
+ return (
285
+ `M${P(radius, 0)}H${fmt(x + size - radius)}` +
286
+ `A${fmt(radius)} ${fmt(radius)} 0 0 1 ${P(size, radius)}` +
287
+ `V${fmt(y + shoulder)}` +
288
+ `C${P(size, shoulder + 1.55 * m)} ${P(mid + 1.6 * m, size)} ${P(mid, size)}` +
289
+ `C${P(mid - 1.6 * m, size)} ${P(0, shoulder + 1.55 * m)} ${P(0, shoulder)}` +
290
+ `V${fmt(y + radius)}A${fmt(radius)} ${fmt(radius)} 0 0 1 ${P(radius, 0)}Z`
291
+ );
292
+ }
@@ -0,0 +1,93 @@
1
+ /** biome-ignore-all lint/style/noMagicNumbers: color math */
2
+ // sRGB to OKLCh and back (Björn Ottosson's OKLab matrices), so a color's
3
+ // lightness can move while its hue stays: the halo's rim (looks.ts
4
+ // fitHaloColor) keeps the hue a person picked and only changes how light
5
+ // it is.
6
+ import type { RGBAColor } from "./parse-color";
7
+
8
+ /** OKLab lightness (0 to 1), chroma and hue (radians). */
9
+ export interface OkLch {
10
+ l: number;
11
+ c: number;
12
+ h: number;
13
+ }
14
+
15
+ const toLinear = (channel: number) => {
16
+ const value = channel / 255;
17
+ return value <= 0.040_45 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
18
+ };
19
+
20
+ const toGamma = (value: number) =>
21
+ 255 *
22
+ (value <= 0.003_130_8 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - 0.055);
23
+
24
+ /** An sRGB color (channels 0 to 255) in OKLCh; its alpha is dropped. */
25
+ export function rgbToOklch({ r, g, b }: RGBAColor): OkLch {
26
+ const red = toLinear(r);
27
+ const green = toLinear(g);
28
+ const blue = toLinear(b);
29
+ const l = Math.cbrt(
30
+ 0.412_221_470_8 * red + 0.536_332_536_3 * green + 0.051_445_992_9 * blue
31
+ );
32
+ const m = Math.cbrt(
33
+ 0.211_903_498_2 * red + 0.680_699_545_1 * green + 0.107_396_956_6 * blue
34
+ );
35
+ const s = Math.cbrt(
36
+ 0.088_302_461_9 * red + 0.281_718_837_6 * green + 0.629_978_700_5 * blue
37
+ );
38
+ const a = 1.977_998_495_1 * l - 2.428_592_205 * m + 0.450_593_709_9 * s;
39
+ const bb = 0.025_904_037_1 * l + 0.782_771_766_2 * m - 0.808_675_766 * s;
40
+ return {
41
+ l: 0.210_454_255_3 * l + 0.793_617_785 * m - 0.004_072_046_8 * s,
42
+ c: Math.hypot(a, bb),
43
+ h: Math.atan2(bb, a),
44
+ };
45
+ }
46
+
47
+ /** Linear sRGB (0 to 1 inside the gamut) of an OKLCh color. */
48
+ function toLinearRgb({ l, c, h }: OkLch): [number, number, number] {
49
+ const a = c * Math.cos(h);
50
+ const b = c * Math.sin(h);
51
+ const long = (l + 0.396_337_777_4 * a + 0.215_803_757_3 * b) ** 3;
52
+ const medium = (l - 0.105_561_345_8 * a - 0.063_854_172_8 * b) ** 3;
53
+ const short = (l - 0.089_484_177_5 * a - 1.291_485_548 * b) ** 3;
54
+ return [
55
+ 4.076_741_662_1 * long - 3.307_711_591_3 * medium + 0.230_969_929_2 * short,
56
+ -1.268_438_004_6 * long +
57
+ 2.609_757_401_1 * medium -
58
+ 0.341_319_396_5 * short,
59
+ -0.004_196_086_3 * long - 0.703_418_614_7 * medium + 1.707_614_701 * short,
60
+ ];
61
+ }
62
+
63
+ const GAMUT_SLACK = 1e-7;
64
+ const inGamut = (rgb: number[]) =>
65
+ rgb.every((value) => value >= -GAMUT_SLACK && value <= 1 + GAMUT_SLACK);
66
+
67
+ /** Halvings of the chroma when a color is outside sRGB: well past a channel step. */
68
+ const GAMUT_STEPS = 20;
69
+
70
+ /**
71
+ * An OKLCh color as sRGB, channels rounded to whole numbers. Outside sRGB
72
+ * its chroma is reduced until it fits, its lightness and hue kept.
73
+ */
74
+ export function oklchToRgb(color: OkLch): RGBAColor {
75
+ let linear = toLinearRgb(color);
76
+ if (!inGamut(linear)) {
77
+ let inside = 0;
78
+ let outside = color.c;
79
+ for (let step = 0; step < GAMUT_STEPS; step++) {
80
+ const c = (inside + outside) / 2;
81
+ if (inGamut(toLinearRgb({ ...color, c }))) {
82
+ inside = c;
83
+ } else {
84
+ outside = c;
85
+ }
86
+ }
87
+ linear = toLinearRgb({ ...color, c: inside });
88
+ }
89
+ const [r = 0, g = 0, b = 0] = linear.map((value) =>
90
+ Math.round(toGamma(Math.min(1, Math.max(0, value))))
91
+ );
92
+ return { r, g, b, a: 1 };
93
+ }
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(),