qrdx 0.0.58 → 0.0.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qrdx",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "description": "Customizable QR code generator for React and plain JavaScript: SVG and canvas rendering, dot and eye patterns, gradients, logos, frames, Logo QR and Image QR art, PNG/JPG/WebP/SVG/PDF/EPS export, a scan score and QR scanning.",
5
5
  "keywords": [
6
6
  "qr-code",
@@ -87,32 +87,45 @@ function rootAttributes(props: QRCodeOptions): QRSVGAttributes {
87
87
 
88
88
  type QRData = ReturnType<typeof getQRData>;
89
89
 
90
- /** What `getQRData` lays out for `QRCode`'s props. */
90
+ /**
91
+ * Every prop `getQRCodeData` lays the code out from, in one list. React's
92
+ * `QRCode` keeps its layout until one of these changes, so a prop the layout
93
+ * reads can't be left out of that check: the looks once were (the per-eye
94
+ * shapes, the eyes' gradient span, the rounded background and its backdrop,
95
+ * the halo and the shadow), and a code drawn without them stayed on screen
96
+ * after one was turned on.
97
+ */
98
+ export const QR_CODE_DATA_KEYS = [
99
+ "value",
100
+ "fgColor",
101
+ "hideLogo",
102
+ "bgColor",
103
+ "eyeColor",
104
+ "dotColor",
105
+ "bodyPattern",
106
+ "cornerEyePattern",
107
+ "cornerEyeDotPattern",
108
+ "level",
109
+ "templateId",
110
+ "logo",
111
+ "logoOptions",
112
+ "margin",
113
+ "autoLevel",
114
+ "shape",
115
+ "eyeShapes",
116
+ "eyeGradient",
117
+ "bgRadius",
118
+ "backdrop",
119
+ "halo",
120
+ "shadow",
121
+ ] as const satisfies readonly (keyof QRCodeProps)[];
122
+
123
+ /** What `getQRData` lays out for `QRCode`'s props (QR_CODE_DATA_KEYS). */
91
124
  export function getQRCodeData(props: QRCodeProps): QRData {
92
- return getQRData({
93
- value: props.value,
94
- fgColor: props.fgColor,
95
- hideLogo: props.hideLogo,
96
- bgColor: props.bgColor,
97
- eyeColor: props.eyeColor,
98
- dotColor: props.dotColor,
99
- bodyPattern: props.bodyPattern,
100
- cornerEyePattern: props.cornerEyePattern,
101
- cornerEyeDotPattern: props.cornerEyeDotPattern,
102
- level: props.level,
103
- templateId: props.templateId,
104
- logo: props.logo,
105
- logoOptions: props.logoOptions,
106
- margin: props.margin ?? DEFAULT_MARGIN,
107
- autoLevel: props.autoLevel,
108
- shape: props.shape,
109
- eyeShapes: props.eyeShapes,
110
- eyeGradient: props.eyeGradient,
111
- bgRadius: props.bgRadius,
112
- backdrop: props.backdrop,
113
- halo: props.halo,
114
- shadow: props.shadow,
115
- });
125
+ const read = Object.fromEntries(
126
+ QR_CODE_DATA_KEYS.map((key) => [key, props[key]])
127
+ ) as Pick<QRCodeProps, (typeof QR_CODE_DATA_KEYS)[number]>;
128
+ return getQRData({ ...read, margin: props.margin ?? DEFAULT_MARGIN });
116
129
  }
117
130
 
118
131
  /**
package/src/qr-code.tsx CHANGED
@@ -2,8 +2,11 @@
2
2
  // on the server; only QRCodeCanvas needs a client boundary.
3
3
  import { memo, useMemo } from "react";
4
4
  import type { QRCodePropsSVG } from "../types/react";
5
- import { DEFAULT_MARGIN } from "./constants";
6
- import { getQRCodeData, getQRCodeSVGProps } from "./qr-code-props";
5
+ import {
6
+ getQRCodeData,
7
+ getQRCodeSVGProps,
8
+ QR_CODE_DATA_KEYS,
9
+ } from "./qr-code-props";
7
10
  import { QRCodeSVG } from "./qr-code-svg";
8
11
 
9
12
  /**
@@ -12,45 +15,10 @@ import { QRCodeSVG } from "./qr-code-svg";
12
15
  * goes on the `<svg>`, as with `QRCodeSVG`.
13
16
  */
14
17
  export const QRCode = memo((props: QRCodePropsSVG) => {
15
- const {
16
- value,
17
- fgColor,
18
- hideLogo,
19
- logo,
20
- logoOptions,
21
- bgColor,
22
- eyeColor,
23
- dotColor,
24
- bodyPattern,
25
- cornerEyePattern,
26
- cornerEyeDotPattern,
27
- level,
28
- margin = DEFAULT_MARGIN,
29
- templateId,
30
- autoLevel,
31
- shape,
32
- } = props;
33
- // biome-ignore lint/correctness/useExhaustiveDependencies: the layout depends on exactly these props
34
18
  const qrData = useMemo(
35
19
  () => getQRCodeData(props),
36
- [
37
- value,
38
- fgColor,
39
- hideLogo,
40
- logo,
41
- logoOptions,
42
- margin,
43
- autoLevel,
44
- shape,
45
- bgColor,
46
- eyeColor,
47
- dotColor,
48
- bodyPattern,
49
- cornerEyePattern,
50
- cornerEyeDotPattern,
51
- level,
52
- templateId,
53
- ]
20
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the layout reads exactly these props (QR_CODE_DATA_KEYS, the list getQRCodeData lays out from)
21
+ QR_CODE_DATA_KEYS.map((key) => props[key])
54
22
  );
55
23
 
56
24
  return <QRCodeSVG {...getQRCodeSVGProps(props, qrData)} />;