qr-code-styling-node 1.9.0 → 1.11.0
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 +76 -4
- package/lib/art/art.d.ts +12 -8
- package/lib/core/QRCanvas.d.ts +2 -0
- package/lib/core/QRCodeStyling.d.ts +23 -1
- package/lib/core/QRSVG.d.ts +5 -1
- package/lib/figures/shapes.d.ts +11 -0
- package/lib/index.d.ts +3 -1
- package/lib/qr-code-styling.common.js +1 -1
- package/lib/qr-code-styling.common.js.map +1 -1
- package/lib/qr-code-styling.js +1 -1
- package/lib/qr-code-styling.js.map +1 -1
- package/lib/qr-code-styling.mjs +454 -97
- package/lib/qr-code-styling.mjs.map +4 -4
- package/lib/tools/circle.d.ts +16 -0
- package/lib/tools/cornerTypes.d.ts +2 -0
- package/lib/tools/payloads.d.ts +72 -0
- package/lib/tools/qrArea.d.ts +14 -0
- package/lib/tools/utf8.d.ts +4 -0
- package/lib/types/index.d.ts +25 -3
- package/package.json +4 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RequiredOptions } from "../core/QROptions";
|
|
2
|
+
/**
|
|
3
|
+
* Round QR codes (shape: "circle"). The real code stays a square in the middle; the rest of the circle
|
|
4
|
+
* is filled with decorative modules. A one-module empty ring around the real code keeps it readable,
|
|
5
|
+
* as scanners ignore everything outside the finder patterns.
|
|
6
|
+
*/
|
|
7
|
+
export interface CircleLayout {
|
|
8
|
+
/** Modules across the whole circle. */
|
|
9
|
+
size: number;
|
|
10
|
+
/** Decorative modules on each side of the real code. */
|
|
11
|
+
pad: number;
|
|
12
|
+
/** True for a dark decorative module. Always false inside the real code and its quiet ring. */
|
|
13
|
+
isDecoration: (i: number, j: number) => boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const isCircle: (options: RequiredOptions) => boolean;
|
|
16
|
+
export declare function getCircleLayout(count: number): CircleLayout;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { RequiredOptions } from "../core/QROptions";
|
|
2
2
|
import { CornerDotType, CornerSquareType, DotType } from "../types";
|
|
3
|
+
/** Dot types with a round look; blend art matches its corners and correction dots to them. */
|
|
4
|
+
export declare const ROUND_DOT_TYPES: DotType[];
|
|
3
5
|
/** True when alignment patterns must be drawn as plain squares for this dot type to scan. */
|
|
4
6
|
export declare const needsSolidAlignment: (type: DotType) => boolean;
|
|
5
7
|
export default function getCornerTypes(options: RequiredOptions): {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builders for the data of common QR codes: Wi-Fi, contact card, calendar event, e-mail, phone, SMS and
|
|
3
|
+
* location. They only return a string, to pass as `data`.
|
|
4
|
+
*/
|
|
5
|
+
export interface WifiOptions {
|
|
6
|
+
ssid: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
/** Default "WPA" when there is a password, otherwise "nopass". */
|
|
9
|
+
encryption?: "WPA" | "WEP" | "nopass";
|
|
10
|
+
hidden?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface VCardOptions {
|
|
13
|
+
firstName?: string;
|
|
14
|
+
lastName?: string;
|
|
15
|
+
/** Full name shown by phones. Default: first and last name. */
|
|
16
|
+
name?: string;
|
|
17
|
+
organization?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
phone?: string | string[];
|
|
20
|
+
email?: string | string[];
|
|
21
|
+
url?: string;
|
|
22
|
+
address?: {
|
|
23
|
+
street?: string;
|
|
24
|
+
city?: string;
|
|
25
|
+
region?: string;
|
|
26
|
+
postalCode?: string;
|
|
27
|
+
country?: string;
|
|
28
|
+
};
|
|
29
|
+
note?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface EventOptions {
|
|
32
|
+
title: string;
|
|
33
|
+
start: Date | string;
|
|
34
|
+
end?: Date | string;
|
|
35
|
+
/** Dates only, no time of day. */
|
|
36
|
+
allDay?: boolean;
|
|
37
|
+
location?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function wifi({ ssid, password, encryption, hidden }: WifiOptions): string;
|
|
41
|
+
export declare function vCard(contact: VCardOptions): string;
|
|
42
|
+
export declare function event({ title, start, end, allDay, location, description }: EventOptions): string;
|
|
43
|
+
export declare function email({ to, subject, body }: {
|
|
44
|
+
to: string;
|
|
45
|
+
subject?: string;
|
|
46
|
+
body?: string;
|
|
47
|
+
}): string;
|
|
48
|
+
export declare const phone: (number: string) => string;
|
|
49
|
+
export declare const sms: ({ number, message }: {
|
|
50
|
+
number: string;
|
|
51
|
+
message?: string;
|
|
52
|
+
}) => string;
|
|
53
|
+
export declare const geo: ({ latitude, longitude }: {
|
|
54
|
+
latitude: number;
|
|
55
|
+
longitude: number;
|
|
56
|
+
}) => string;
|
|
57
|
+
declare const _default: {
|
|
58
|
+
wifi: typeof wifi;
|
|
59
|
+
vCard: typeof vCard;
|
|
60
|
+
event: typeof event;
|
|
61
|
+
email: typeof email;
|
|
62
|
+
phone: (number: string) => string;
|
|
63
|
+
sms: ({ number, message }: {
|
|
64
|
+
number: string;
|
|
65
|
+
message?: string;
|
|
66
|
+
}) => string;
|
|
67
|
+
geo: ({ latitude, longitude }: {
|
|
68
|
+
latitude: number;
|
|
69
|
+
longitude: number;
|
|
70
|
+
}) => string;
|
|
71
|
+
};
|
|
72
|
+
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequiredOptions } from "../core/QROptions";
|
|
2
|
+
export interface QRArea {
|
|
3
|
+
count: number;
|
|
4
|
+
/** Size of one module in pixels. */
|
|
5
|
+
dotSize: number;
|
|
6
|
+
/** Top-left corner of the code (without margin). */
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Where the code sits in the output. By default it is centered and fills the size minus the margin.
|
|
12
|
+
* With art.placement it sits in that square of the picture instead.
|
|
13
|
+
*/
|
|
14
|
+
export default function getQRArea(options: RequiredOptions, count: number): QRArea;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** UTF-8 bytes of a string (works without TextEncoder, for old browsers). */
|
|
2
|
+
export default function toUTF8Bytes(text: string): number[];
|
|
3
|
+
/** True when the text has characters outside Latin-1, which byte mode cannot hold as single bytes. */
|
|
4
|
+
export declare const needsUTF8: (text: string) => boolean;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export interface UnknownObject {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
}
|
|
4
|
-
export type DotType = "dots" | "rounded" | "classy" | "classy-rounded" | "square" | "extra-rounded" | "diamond" | "small-square" | "vertical-lines" | "horizontal-lines";
|
|
4
|
+
export type DotType = "dots" | "rounded" | "classy" | "classy-rounded" | "square" | "extra-rounded" | "diamond" | "small-square" | "vertical-lines" | "horizontal-lines" | "fluid";
|
|
5
5
|
export type CornerDotType = "dot" | "square" | "rounded";
|
|
6
6
|
export type CornerSquareType = "dot" | "square" | "extra-rounded" | "rounded";
|
|
7
7
|
export type Extension = "svg" | "png" | "jpeg" | "webp";
|
|
8
8
|
export type GradientType = "radial" | "linear";
|
|
9
9
|
export type DrawType = "canvas" | "svg";
|
|
10
|
+
export type ShapeType = "square" | "circle";
|
|
10
11
|
export interface Canvas extends HTMLCanvasElement {
|
|
11
12
|
toBuffer?: (type: string) => Buffer;
|
|
12
13
|
createCanvas?: (width: number, height: number) => Canvas;
|
|
@@ -87,22 +88,33 @@ export interface ResvgConstructor {
|
|
|
87
88
|
};
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
|
-
export type ArtMode = "halftone" | "colorize";
|
|
91
|
+
export type ArtMode = "halftone" | "colorize" | "blend";
|
|
91
92
|
export interface ArtOptions {
|
|
92
93
|
/** The picture to blend into the QR code (URL or data URL). */
|
|
93
94
|
image: string;
|
|
94
95
|
/**
|
|
95
96
|
* "halftone": the picture is redrawn as fine black/white (or colored) pixels, with the QR modules in the middle.
|
|
96
97
|
* "colorize": the dots keep their shape and are painted with a darkened copy of the picture.
|
|
98
|
+
* "blend": the picture fills the whole image; dots are drawn only where the picture is not already
|
|
99
|
+
* dark or light enough for the code, so it reads as an illustration.
|
|
97
100
|
*/
|
|
98
101
|
mode?: ArtMode;
|
|
99
102
|
/** halftone only: use the picture's own colors instead of dotsOptions/backgroundOptions colors. */
|
|
100
103
|
colored?: boolean;
|
|
101
104
|
/** colorize only: also show a light copy of the picture behind the dots. Default true. */
|
|
102
105
|
background?: boolean;
|
|
103
|
-
/** 0 to 1. Higher keeps dark and light further apart: easier to scan, less of the picture. Default 0.5 (halftone), 0.7 (colorize). */
|
|
106
|
+
/** 0 to 1. Higher keeps dark and light further apart: easier to scan, less of the picture. Default 0.5 (halftone), 0.7 (colorize), 0.6 (blend). */
|
|
104
107
|
contrast?: number;
|
|
105
108
|
crossOrigin?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Put the code in a square of the picture instead of the middle, in pixels of the output:
|
|
111
|
+
* { x, y, size }. Mostly for "blend", where the picture fills the whole image. The margin is ignored.
|
|
112
|
+
*/
|
|
113
|
+
placement?: {
|
|
114
|
+
x: number;
|
|
115
|
+
y: number;
|
|
116
|
+
size: number;
|
|
117
|
+
};
|
|
106
118
|
}
|
|
107
119
|
/** Same signature as jsQR: (rgba, width, height) => { data } | null. */
|
|
108
120
|
export type QRDecoder = (data: Uint8ClampedArray, width: number, height: number, options?: Record<string, unknown>) => {
|
|
@@ -144,6 +156,11 @@ export interface LabelOptions {
|
|
|
144
156
|
}
|
|
145
157
|
export type Options = {
|
|
146
158
|
type?: DrawType;
|
|
159
|
+
/**
|
|
160
|
+
* "circle": a round QR code. The real code stays square in the middle and the rest of the circle is
|
|
161
|
+
* filled with decorative dots in the same style; the background becomes a circle. Default "square".
|
|
162
|
+
*/
|
|
163
|
+
shape?: ShapeType;
|
|
147
164
|
width?: number;
|
|
148
165
|
height?: number;
|
|
149
166
|
margin?: number;
|
|
@@ -203,6 +220,11 @@ export type DownloadOptions = {
|
|
|
203
220
|
name?: string;
|
|
204
221
|
extension?: Extension;
|
|
205
222
|
};
|
|
223
|
+
export type ShareOptions = DownloadOptions & {
|
|
224
|
+
/** Title and text passed to the share sheet. */
|
|
225
|
+
title?: string;
|
|
226
|
+
text?: string;
|
|
227
|
+
};
|
|
206
228
|
export type DrawArgs = {
|
|
207
229
|
x: number;
|
|
208
230
|
y: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qr-code-styling-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Style your QR codes: dots, corners, gradients and a logo. Works in the browser and on Node.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"qr",
|
|
@@ -72,7 +72,9 @@
|
|
|
72
72
|
"clean": "node -e \"require('fs').rmSync('lib',{recursive:true,force:true})\"",
|
|
73
73
|
"bench": "npm run build && node scripts/bench.mjs",
|
|
74
74
|
"art-examples": "npm run build && node scripts/art-examples.mjs",
|
|
75
|
-
"style-examples": "npm run build && node scripts/style-examples.mjs"
|
|
75
|
+
"style-examples": "npm run build && node scripts/style-examples.mjs",
|
|
76
|
+
"blend-examples": "npm run build && node scripts/blend-examples.mjs",
|
|
77
|
+
"circle-examples": "npm run build && node scripts/circle-examples.mjs"
|
|
76
78
|
},
|
|
77
79
|
"dependencies": {
|
|
78
80
|
"qrcode-generator": "^1.4.3"
|