qr-code-styling-node 1.8.0 → 1.9.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 +49 -4
- package/lib/art/functionModules.d.ts +1 -1
- package/lib/core/QRCanvas.d.ts +1 -0
- package/lib/core/QROptions.d.ts +2 -0
- package/lib/core/QRSVG.d.ts +3 -1
- package/lib/figures/dot/canvas/QRDot.d.ts +2 -0
- package/lib/figures/dot/svg/QRDot.d.ts +2 -0
- package/lib/figures/shapes.d.ts +39 -0
- 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 +539 -134
- package/lib/qr-code-styling.mjs.map +4 -4
- package/lib/tools/cornerTypes.d.ts +8 -0
- package/lib/tools/frameLayout.d.ts +43 -0
- package/lib/tools/svgDom.d.ts +3 -0
- package/lib/types/index.d.ts +31 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ npm install qr-code-styling-node
|
|
|
31
31
|
<head>
|
|
32
32
|
<meta charset="UTF-8">
|
|
33
33
|
<title>QR Code Styling</title>
|
|
34
|
-
<script type="text/javascript" src="https://unpkg.com/qr-code-styling-node@1.
|
|
34
|
+
<script type="text/javascript" src="https://unpkg.com/qr-code-styling-node@1.9.0/lib/qr-code-styling.js"></script>
|
|
35
35
|
</head>
|
|
36
36
|
<body>
|
|
37
37
|
<div id="canvas"></div>
|
|
@@ -77,6 +77,47 @@ The package ships an ES module build (`import`), a CommonJS/UMD build (`require`
|
|
|
77
77
|
|
|
78
78
|
---
|
|
79
79
|
|
|
80
|
+
### More styles, frames and labels
|
|
81
|
+
|
|
82
|
+
<img src="https://raw.githubusercontent.com/ducminhquan/qr-code-styling/master/src/assets/style_examples.png" width="720" />
|
|
83
|
+
|
|
84
|
+
New dot types `diamond`, `small-square`, `vertical-lines` and `horizontal-lines`, and a `rounded` type for both corner
|
|
85
|
+
options. A frame, a label and a plate behind the logo:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
const qrCode = new QRCodeStyling({
|
|
89
|
+
data: "https://example.com",
|
|
90
|
+
dotsOptions: { type: "rounded", color: "#1d4ed8" },
|
|
91
|
+
cornersSquareOptions: { type: "rounded" },
|
|
92
|
+
frameOptions: { color: "#1d4ed8", radius: 24 },
|
|
93
|
+
labelOptions: { text: "SCAN ME" },
|
|
94
|
+
image: "https://example.com/logo.svg",
|
|
95
|
+
imageOptions: { backgroundColor: "#ffffff", backgroundRadius: 0.5 }
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The frame and label are drawn inside `width` x `height`; the code shrinks to fit.
|
|
100
|
+
|
|
101
|
+
`frameOptions` structure
|
|
102
|
+
|
|
103
|
+
Property|Type |Default Value |Description
|
|
104
|
+
--------|------|-------------------|--------------------------------------------
|
|
105
|
+
color |string|`'#000'` |Frame and label band color
|
|
106
|
+
width |number|4% of the size |Border thickness in px
|
|
107
|
+
radius |number|`0` |Outer corner radius in px
|
|
108
|
+
padding |number|4% of the size |Space between the frame and the code in px
|
|
109
|
+
|
|
110
|
+
`labelOptions` structure
|
|
111
|
+
|
|
112
|
+
Property |Type |Default Value |Description
|
|
113
|
+
----------|---------------------------|------------------------------------|-----------------------------
|
|
114
|
+
text |string | |The text. Required
|
|
115
|
+
position |string (`'top' 'bottom'`) |`'bottom'` |Where the label goes
|
|
116
|
+
color |string |white on a frame, else the dots color|Text color
|
|
117
|
+
fontSize |number |7% of the size |In px
|
|
118
|
+
fontFamily|string |`'Helvetica, Arial, sans-serif'` |
|
|
119
|
+
fontWeight|string or number |`'bold'` |
|
|
120
|
+
|
|
80
121
|
### QR art
|
|
81
122
|
|
|
82
123
|
<img src="https://raw.githubusercontent.com/ducminhquan/qr-code-styling/master/src/assets/art_examples.png" width="720" />
|
|
@@ -157,6 +198,8 @@ nodeCanvas |node-canvas | |Node only, optio
|
|
|
157
198
|
jsdom |jsdom | |Node only, optional. Not needed for svg any more; still accepted for backward compatibility
|
|
158
199
|
resvg |`Resvg` from `@resvg/resvg-js`| |Node only, optional. Produces png without node-canvas, see the Node section below
|
|
159
200
|
art |object | |Blend a picture into the code, see "QR art" above
|
|
201
|
+
frameOptions |object | |Border around the code, see "Frames and labels" above
|
|
202
|
+
labelOptions |object | |Text above or below the code, see "Frames and labels" above
|
|
160
203
|
|
|
161
204
|
`options.qrOptions` structure
|
|
162
205
|
|
|
@@ -175,6 +218,8 @@ imageSize |number |`0.4` |Coeffic
|
|
|
175
218
|
margin |number |`0` |Margin of the image in px
|
|
176
219
|
crossOrigin |string(`'anonymous' 'use-credentials'`)| |Set "anonymous" if you want to download QR code from other origins.
|
|
177
220
|
saveAsBlob |boolean |`false` |Saves image as base64 blob in svg type, see bellow
|
|
221
|
+
backgroundColor |string | |Draws a plate of this color behind the image
|
|
222
|
+
backgroundRadius |number (`0 - 0.5`) |`0.2` |Corner radius of the plate, relative to its size. `0.5` is round
|
|
178
223
|
|
|
179
224
|
When QR type is svg, the image may not load in certain applications as it is saved as a url, and some svg applications will not render url images for security reasons. Setting `saveAsBlob` to true will instead save the image as a blob, allowing it to render correctly in more places, but will also increase the file size.
|
|
180
225
|
|
|
@@ -184,7 +229,7 @@ Property|Type
|
|
|
184
229
|
--------|------------------------------------------------------------------------------|-------------|-------------------
|
|
185
230
|
color |string |`'#000'` |Color of QR dots
|
|
186
231
|
gradient|object | |Gradient of QR dots
|
|
187
|
-
type |string (`'rounded' 'dots' 'classy' 'classy-rounded' 'square' 'extra-rounded'`)|`'square'` |Style of QR dots
|
|
232
|
+
type |string (`'rounded' 'dots' 'classy' 'classy-rounded' 'square' 'extra-rounded' 'diamond' 'small-square' 'vertical-lines' 'horizontal-lines'`)|`'square'` |Style of QR dots. With the last four, corners and alignment patterns stay solid unless you set a corner type
|
|
188
233
|
|
|
189
234
|
`options.backgroundOptions` structure
|
|
190
235
|
|
|
@@ -199,7 +244,7 @@ Property|Type |Default Value|Description
|
|
|
199
244
|
--------|-----------------------------------------|-------------|-----------------
|
|
200
245
|
color |string | |Color of Corners Square
|
|
201
246
|
gradient|object | |Gradient of Corners Square
|
|
202
|
-
type |string (`'dot' 'square' 'extra-rounded'`)| |Style of Corners Square
|
|
247
|
+
type |string (`'dot' 'square' 'extra-rounded' 'rounded'`)| |Style of Corners Square
|
|
203
248
|
|
|
204
249
|
`options.cornersDotOptions` structure
|
|
205
250
|
|
|
@@ -207,7 +252,7 @@ Property|Type |Default Value|Description
|
|
|
207
252
|
--------|-------------------------|-------------|-----------------
|
|
208
253
|
color |string | |Color of Corners Dot
|
|
209
254
|
gradient|object | |Gradient of Corners Dot
|
|
210
|
-
type |string (`'dot' 'square'`)| |Style of Corners Dot
|
|
255
|
+
type |string (`'dot' 'square' 'rounded'`)| |Style of Corners Dot
|
|
211
256
|
|
|
212
257
|
Gradient structure
|
|
213
258
|
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Which modules of a QR symbol are function patterns (finders, timing, alignment, format and
|
|
3
3
|
* version information). QR art leaves these solid so scanners can still locate and read the code.
|
|
4
4
|
*/
|
|
5
|
-
export type ModuleRole = "finder" | "function" | "data";
|
|
5
|
+
export type ModuleRole = "finder" | "function" | "alignment" | "data";
|
|
6
6
|
/** Returns a lookup of module roles for a symbol with `count` modules per side. */
|
|
7
7
|
export default function getModuleRoles(count: number): (row: number, col: number) => ModuleRole;
|
package/lib/core/QRCanvas.d.ts
CHANGED
package/lib/core/QROptions.d.ts
CHANGED
package/lib/core/QRSVG.d.ts
CHANGED
|
@@ -17,11 +17,13 @@ export default class QRSVG {
|
|
|
17
17
|
_virtual: boolean;
|
|
18
18
|
/** Image used to paint the dots instead of their color (QR art "colorize"). */
|
|
19
19
|
_dotsImageHref?: string;
|
|
20
|
-
constructor(options: RequiredOptions);
|
|
20
|
+
constructor(options: RequiredOptions, sharedWindow?: Window);
|
|
21
21
|
get width(): number;
|
|
22
22
|
get height(): number;
|
|
23
23
|
getElement(): SVGElement;
|
|
24
24
|
clear(): void;
|
|
25
|
+
_svgElement(name: string, attributes: Record<string, string | number>): SVGElement;
|
|
26
|
+
_drawFramed(qr: QRCode): Promise<void>;
|
|
25
27
|
drawQR(qr: QRCode): Promise<void>;
|
|
26
28
|
drawBackground(): void;
|
|
27
29
|
drawDots(filter?: FilterFunction): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Shape } from "../../shapes";
|
|
1
2
|
import { DotType, GetNeighbor, RotateFigureArgsCanvas, BasicFigureDrawArgsCanvas, DrawArgsCanvas } from "../../../types";
|
|
2
3
|
export default class QRDot {
|
|
3
4
|
_context: CanvasRenderingContext2D;
|
|
@@ -7,6 +8,7 @@ export default class QRDot {
|
|
|
7
8
|
type: DotType;
|
|
8
9
|
});
|
|
9
10
|
draw(x: number, y: number, size: number, getNeighbor: GetNeighbor): void;
|
|
11
|
+
_drawShape(shape: Shape): void;
|
|
10
12
|
_rotateFigure({ x, y, size, context, rotation, draw }: RotateFigureArgsCanvas): void;
|
|
11
13
|
_basicDot(args: BasicFigureDrawArgsCanvas): void;
|
|
12
14
|
_basicSquare(args: BasicFigureDrawArgsCanvas): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Shape } from "../../shapes";
|
|
1
2
|
import { DotType, GetNeighbor, DrawArgs, BasicFigureDrawArgs, RotateFigureArgs, Window } from "../../../types";
|
|
2
3
|
export default class QRDot {
|
|
3
4
|
_element?: SVGElement;
|
|
@@ -10,6 +11,7 @@ export default class QRDot {
|
|
|
10
11
|
window: Window;
|
|
11
12
|
});
|
|
12
13
|
draw(x: number, y: number, size: number, getNeighbor: GetNeighbor): void;
|
|
14
|
+
_drawShape(shape: Shape): void;
|
|
13
15
|
_rotateFigure({ x, y, size, rotation, draw }: RotateFigureArgs): void;
|
|
14
16
|
_basicDot(args: BasicFigureDrawArgs): void;
|
|
15
17
|
_basicSquare(args: BasicFigureDrawArgs): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shapes shared by the canvas and SVG renderers. A shape is a list of path commands in absolute
|
|
3
|
+
* coordinates; `toCanvas` replays them on a 2D context and `toSVGPath` turns them into a path "d".
|
|
4
|
+
* Sub-paths of one module never overlap their neighbours, so the even-odd fill used by the
|
|
5
|
+
* renderers only cuts the holes that are meant to be holes (corner rings).
|
|
6
|
+
*/
|
|
7
|
+
export type PathCommand = {
|
|
8
|
+
op: "M" | "L";
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}
|
|
12
|
+
/** Circular arc around (cx, cy), angles in radians, clockwise on screen unless anticlockwise. */
|
|
13
|
+
| {
|
|
14
|
+
op: "A";
|
|
15
|
+
cx: number;
|
|
16
|
+
cy: number;
|
|
17
|
+
r: number;
|
|
18
|
+
start: number;
|
|
19
|
+
end: number;
|
|
20
|
+
anticlockwise?: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
op: "Z";
|
|
23
|
+
};
|
|
24
|
+
export type Shape = PathCommand[];
|
|
25
|
+
export declare function toCanvas(context: CanvasRenderingContext2D, shape: Shape): void;
|
|
26
|
+
export declare function toSVGPath(shape: Shape): string;
|
|
27
|
+
export declare const diamond: (x: number, y: number, size: number) => Shape;
|
|
28
|
+
export declare const rect: (x: number, y: number, width: number, height: number) => Shape;
|
|
29
|
+
export declare const smallSquare: (x: number, y: number, size: number) => Shape;
|
|
30
|
+
/**
|
|
31
|
+
* A bar that joins its neighbours along one axis and gets a round cap where it has none.
|
|
32
|
+
* `before`/`after` are the neighbours above/below (vertical) or left/right (horizontal).
|
|
33
|
+
*/
|
|
34
|
+
export declare const line: (x: number, y: number, size: number, vertical: boolean, before: boolean, after: boolean) => Shape;
|
|
35
|
+
/** Rounded rectangle, drawn clockwise. */
|
|
36
|
+
export declare const roundedRect: (x: number, y: number, width: number, height: number, radius: number) => Shape;
|
|
37
|
+
/** Finder ring with rounded corners: outer square minus inner square (even-odd). */
|
|
38
|
+
export declare const roundedRing: (x: number, y: number, size: number) => Shape;
|
|
39
|
+
export declare const roundedSquare: (x: number, y: number, size: number) => Shape;
|