qrdx 0.0.60 → 0.0.62
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/README.md +3 -2
- package/dist/angular.js +7 -2
- package/dist/angular.js.map +1 -1
- package/dist/angular.mjs +7 -2
- package/dist/angular.mjs.map +1 -1
- package/dist/core.js +7 -7
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +7 -7
- package/dist/core.mjs.map +1 -1
- package/dist/element.browser.mjs +6 -6
- package/dist/element.browser.mjs.map +1 -1
- package/dist/element.js +1 -1
- package/dist/element.js.map +1 -1
- package/dist/element.mjs +1 -1
- package/dist/element.mjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/dist/node.js +2 -2
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +2 -2
- package/dist/node.mjs.map +1 -1
- package/dist/qr-code-canvas.js +1 -1
- package/dist/qr-code-canvas.js.map +1 -1
- package/dist/qr-code-canvas.mjs +1 -1
- package/dist/qr-code-canvas.mjs.map +1 -1
- package/dist/schemas.js +1 -1
- package/dist/schemas.js.map +1 -1
- package/dist/schemas.mjs +1 -1
- package/dist/schemas.mjs.map +1 -1
- package/dist/src/angular.d.ts +2 -1
- package/dist/src/api.d.ts +2 -3
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/element.d.ts +2 -0
- package/dist/src/element.d.ts.map +1 -1
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/helpers.d.ts.map +1 -1
- package/dist/src/logo-budget.d.ts +3 -1
- package/dist/src/logo-budget.d.ts.map +1 -1
- package/dist/src/looks.d.ts +2 -2
- package/dist/src/looks.d.ts.map +1 -1
- package/dist/src/plain.d.ts.map +1 -1
- package/dist/src/print.d.ts.map +1 -1
- package/dist/src/qr-code-canvas.d.ts +2 -8
- package/dist/src/qr-code-canvas.d.ts.map +1 -1
- package/dist/src/qr-code-props.d.ts +1 -1
- package/dist/src/qr-code-props.d.ts.map +1 -1
- package/dist/src/qr-code-svg.d.ts +2 -3
- package/dist/src/qr-code-svg.d.ts.map +1 -1
- package/dist/src/qr-code.d.ts +2 -2
- package/dist/src/qr-code.d.ts.map +1 -1
- package/dist/src/qr-frame-svg.d.ts +2 -3
- package/dist/src/qr-frame-svg.d.ts.map +1 -1
- package/dist/src/rasterize.d.ts +8 -0
- package/dist/src/rasterize.d.ts.map +1 -1
- package/dist/src/react-elements.d.ts.map +1 -1
- package/dist/src/scan-score.d.ts +34 -0
- package/dist/src/scan-score.d.ts.map +1 -1
- package/dist/src/symbol.d.ts +13 -0
- package/dist/src/symbol.d.ts.map +1 -0
- package/dist/src/utils/print-shared.d.ts.map +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/vue.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/qr.d.ts +2 -0
- package/dist/types/qr.d.ts.map +1 -1
- package/dist/types/react.d.ts +21 -3
- package/dist/types/react.d.ts.map +1 -1
- package/dist/vanilla.browser.mjs +16 -16
- package/dist/vanilla.browser.mjs.map +1 -1
- package/dist/vue.js +1 -1
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +1 -1
- package/dist/vue.mjs.map +1 -1
- package/package.json +4 -6
- package/src/angular.ts +2 -0
- package/src/api.tsx +3 -4
- package/src/element.ts +3 -0
- package/src/helpers.ts +27 -10
- package/src/logo-budget.ts +9 -8
- package/src/looks.ts +17 -14
- package/src/plain.tsx +5 -7
- package/src/print.ts +3 -6
- package/src/qr-code-canvas.tsx +39 -34
- package/src/qr-code-props.ts +4 -0
- package/src/qr-code-svg.tsx +3 -4
- package/src/qr-code.tsx +7 -5
- package/src/qr-frame-svg.tsx +3 -4
- package/src/rasterize.ts +14 -1
- package/src/react-elements.ts +40 -2
- package/src/scan-score.ts +225 -51
- package/src/symbol.ts +27 -0
- package/src/utils/print-shared.ts +5 -9
- package/src/utils.tsx +9 -9
- package/src/vue.ts +1 -0
- package/types/qr.ts +6 -0
- package/types/react.ts +22 -3
package/src/utils.tsx
CHANGED
|
@@ -34,7 +34,6 @@ import {
|
|
|
34
34
|
isShapedBodyPattern,
|
|
35
35
|
renderShapedBody,
|
|
36
36
|
} from "./body-patterns";
|
|
37
|
-
import qrcodegen from "./codegen";
|
|
38
37
|
import {
|
|
39
38
|
DEFAULT_BGCOLOR,
|
|
40
39
|
DEFAULT_FGCOLOR,
|
|
@@ -42,7 +41,6 @@ import {
|
|
|
42
41
|
DEFAULT_LEVEL,
|
|
43
42
|
DEFAULT_MARGIN,
|
|
44
43
|
DEFAULT_SIZE,
|
|
45
|
-
ERROR_LEVEL_MAP,
|
|
46
44
|
} from "./constants";
|
|
47
45
|
import { generateCornerDotPath } from "./corner-dot";
|
|
48
46
|
import { generateCornerSquarePath } from "./corner-eye";
|
|
@@ -54,6 +52,7 @@ import { clampBgRadius, eyeShapeOf, resolveHalo, resolveShadow } from "./looks";
|
|
|
54
52
|
import { partMarker, type QRPart, type QRPartEye } from "./part-markers";
|
|
55
53
|
import { getLayoutMargin, shapeBackground, shapeDecoration } from "./qr-shape";
|
|
56
54
|
import { hashString } from "./shapes";
|
|
55
|
+
import { encodeSymbol } from "./symbol";
|
|
57
56
|
import { getTemplate } from "./templates";
|
|
58
57
|
import { getSolidColor } from "./utils/color";
|
|
59
58
|
import { compact, fmt, SCALE_DECIMALS } from "./utils/fmt";
|
|
@@ -888,6 +887,7 @@ export function resolveErrorLevel(props: {
|
|
|
888
887
|
imageSettings?: ImageSettings;
|
|
889
888
|
isOGContext?: boolean;
|
|
890
889
|
autoLevel?: boolean;
|
|
890
|
+
exactLevel?: boolean;
|
|
891
891
|
shape?: QRCodeShape;
|
|
892
892
|
}): ErrorLevel {
|
|
893
893
|
const level = props.level ?? DEFAULT_LEVEL;
|
|
@@ -899,9 +899,10 @@ export function resolveErrorLevel(props: {
|
|
|
899
899
|
? "Q"
|
|
900
900
|
: level;
|
|
901
901
|
if (props.autoLevel && imageSettings && effective !== "H") {
|
|
902
|
-
const cells =
|
|
902
|
+
const cells = encodeSymbol(
|
|
903
903
|
props.value,
|
|
904
|
-
|
|
904
|
+
effective,
|
|
905
|
+
props.exactLevel
|
|
905
906
|
).getModules();
|
|
906
907
|
const settings = getImageSettings(
|
|
907
908
|
cells,
|
|
@@ -974,6 +975,7 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
|
|
|
974
975
|
eyeColors,
|
|
975
976
|
moduleScale,
|
|
976
977
|
autoLevel,
|
|
978
|
+
exactLevel,
|
|
977
979
|
shape,
|
|
978
980
|
eyeShapes,
|
|
979
981
|
eyeGradient,
|
|
@@ -997,7 +999,7 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
|
|
|
997
999
|
);
|
|
998
1000
|
// A logo no bigger than the code can repair (logo-budget.ts)
|
|
999
1001
|
const imageSettings = capImageSettings(
|
|
1000
|
-
{ value, size, margin, level, shape, autoLevel, isOGContext },
|
|
1002
|
+
{ value, size, margin, level, shape, autoLevel, exactLevel, isOGContext },
|
|
1001
1003
|
requestedImageSettings
|
|
1002
1004
|
);
|
|
1003
1005
|
|
|
@@ -1025,13 +1027,11 @@ export function createQRCodeTree(props: QRSVGOptions): QRNode {
|
|
|
1025
1027
|
imageSettings,
|
|
1026
1028
|
isOGContext,
|
|
1027
1029
|
autoLevel,
|
|
1030
|
+
exactLevel,
|
|
1028
1031
|
shape,
|
|
1029
1032
|
});
|
|
1030
1033
|
|
|
1031
|
-
const qrCode =
|
|
1032
|
-
value,
|
|
1033
|
-
ERROR_LEVEL_MAP[effectiveLevel]
|
|
1034
|
-
);
|
|
1034
|
+
const qrCode = encodeSymbol(value, effectiveLevel, exactLevel);
|
|
1035
1035
|
let cells = qrCode.getModules();
|
|
1036
1036
|
// A shaped code draws the symbol further in, inside its disc, heart or
|
|
1037
1037
|
// silhouette (a silhouette that can't hold the code draws square)
|
package/src/vue.ts
CHANGED
package/types/qr.ts
CHANGED
|
@@ -236,6 +236,7 @@ export const qrPropsSchema = z.object({
|
|
|
236
236
|
.max(MODULE_SCALE_MAX)
|
|
237
237
|
.optional(),
|
|
238
238
|
autoLevel: z.boolean().optional(),
|
|
239
|
+
exactLevel: z.boolean().optional(),
|
|
239
240
|
shape: qrCodeShapeSchema.optional(),
|
|
240
241
|
eyeShapes: eyeShapesSchema.optional(),
|
|
241
242
|
eyeGradient: eyeGradientSpanSchema.optional(),
|
|
@@ -290,6 +291,11 @@ export interface QRProps {
|
|
|
290
291
|
// Raise error correction to H when the logo covers more than 7% of the
|
|
291
292
|
// code (off by default, so existing output never changes)
|
|
292
293
|
autoLevel?: boolean;
|
|
294
|
+
// Encode at exactly the level the code is drawn at. By default the encoder
|
|
295
|
+
// raises it to Q or H when the data still fits the same version (more
|
|
296
|
+
// error correction for free); a Swiss QR-bill must be M, so it sets this.
|
|
297
|
+
// Off by default, so existing output never changes.
|
|
298
|
+
exactLevel?: boolean;
|
|
293
299
|
// Outline: "circle" or "heart" puts the symbol in a disc or a heart of
|
|
294
300
|
// decorative modules (see QR_SHAPES); a QRSilhouette fills an outline of
|
|
295
301
|
// your own. Ignored with a template.
|
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 &
|
|
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 &
|
|
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
|