qr-code-styling-node 1.9.0 → 1.10.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 +23 -4
- package/lib/art/art.d.ts +12 -8
- package/lib/core/QRCanvas.d.ts +2 -0
- package/lib/core/QRSVG.d.ts +2 -0
- package/lib/figures/shapes.d.ts +11 -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 +221 -62
- package/lib/qr-code-styling.mjs.map +4 -4
- package/lib/tools/cornerTypes.d.ts +2 -0
- package/lib/tools/qrArea.d.ts +14 -0
- package/lib/types/index.d.ts +14 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -122,10 +122,25 @@ fontWeight|string or number |`'bold'` |
|
|
|
122
122
|
|
|
123
123
|
<img src="https://raw.githubusercontent.com/ducminhquan/qr-code-styling/master/src/assets/art_examples.png" width="720" />
|
|
124
124
|
|
|
125
|
-
Blend a picture into the code with `art`.
|
|
125
|
+
Blend a picture into the code with `art`. Three modes:
|
|
126
126
|
|
|
127
127
|
- `halftone` (default): the picture is redrawn as fine pixels, with each QR module kept in the middle. Use `colored: true` to keep the picture's colors.
|
|
128
128
|
- `colorize`: dots keep their shape (any `dotsOptions.type`) and are painted with a darkened copy of the picture, over a light copy of it.
|
|
129
|
+
- `blend`: the picture fills the whole image, like an illustration. Dots are drawn only where the picture is not already
|
|
130
|
+
dark or light enough for the code; finders take a dark color from the picture and sit on a light plate.
|
|
131
|
+
Use `placement` to put the code in one part of a larger picture.
|
|
132
|
+
|
|
133
|
+
<img src="https://raw.githubusercontent.com/ducminhquan/qr-code-styling/master/src/assets/blend_examples.png" width="720" />
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
const qrCode = new QRCodeStyling({
|
|
137
|
+
width: 760,
|
|
138
|
+
height: 300,
|
|
139
|
+
data: "https://example.com",
|
|
140
|
+
dotsOptions: { type: "dots" }, // round dots give round finders in blend mode
|
|
141
|
+
art: { image: "poster.jpg", mode: "blend", placement: { x: 510, y: 40, size: 220 } }
|
|
142
|
+
});
|
|
143
|
+
```
|
|
129
144
|
|
|
130
145
|
```js
|
|
131
146
|
const qrCode = new QRCodeStyling({
|
|
@@ -144,11 +159,15 @@ QR art reads the picture's pixels, so it needs a canvas: it works as is in the b
|
|
|
144
159
|
Property |Type |Default Value|Description
|
|
145
160
|
----------|----------------------------------|-------------|------------------------------------------------------------
|
|
146
161
|
image |string | |The picture (URL or data URL). Required
|
|
147
|
-
mode |string (`'halftone' 'colorize'`)
|
|
162
|
+
mode |string (`'halftone' 'colorize' 'blend'`)|`'halftone'` |How the picture is blended in
|
|
148
163
|
colored |boolean |`false` |halftone: use the picture's colors instead of dots/background colors
|
|
149
164
|
background|boolean |`true` |colorize: show a light copy of the picture behind the dots
|
|
150
|
-
contrast |number (`0 - 1`) |`0.5` halftone, `0.7` colorize|Higher is easier to scan but shows less of the picture
|
|
165
|
+
contrast |number (`0 - 1`) |`0.5` halftone, `0.7` colorize, `0.6` blend|Higher is easier to scan but shows less of the picture
|
|
151
166
|
crossOrigin|string | |Overrides `imageOptions.crossOrigin` for the picture
|
|
167
|
+
placement |object `{ x, y, size }` | |Put the code in this square (in pixels) instead of the middle; the margin is ignored. Mostly for `blend`
|
|
168
|
+
|
|
169
|
+
Always check art codes with `verify()` below: a picture with large mid-grey areas or very small modules
|
|
170
|
+
(under about 7 px) may need a higher `contrast`, a larger size or a higher error correction level.
|
|
152
171
|
|
|
153
172
|
### Checking that a code scans
|
|
154
173
|
|
|
@@ -229,7 +248,7 @@ Property|Type
|
|
|
229
248
|
--------|------------------------------------------------------------------------------|-------------|-------------------
|
|
230
249
|
color |string |`'#000'` |Color of QR dots
|
|
231
250
|
gradient|object | |Gradient 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
|
|
251
|
+
type |string (`'rounded' 'dots' 'classy' 'classy-rounded' 'square' 'extra-rounded' 'diamond' 'small-square' 'vertical-lines' 'horizontal-lines' 'fluid'`)|`'square'` |Style of QR dots. With `diamond`, `small-square` and the lines, corners and alignment patterns stay solid unless you set a corner type. `fluid` joins neighbouring dots into soft strokes, with solid rounded corners
|
|
233
252
|
|
|
234
253
|
`options.backgroundOptions` structure
|
|
235
254
|
|
package/lib/art/art.d.ts
CHANGED
|
@@ -13,12 +13,7 @@ export interface ArtRect {
|
|
|
13
13
|
width: number;
|
|
14
14
|
height: number;
|
|
15
15
|
color: string;
|
|
16
|
-
|
|
17
|
-
export interface QRArea {
|
|
18
|
-
count: number;
|
|
19
|
-
dotSize: number;
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
16
|
+
shape?: "rect" | "circle";
|
|
22
17
|
}
|
|
23
18
|
export interface HalftoneArt {
|
|
24
19
|
mode: "halftone";
|
|
@@ -31,11 +26,21 @@ export interface ColorizeArt {
|
|
|
31
26
|
/** Full-size canvas holding a light copy of the picture, drawn behind the dots (when art.background). */
|
|
32
27
|
background?: Canvas;
|
|
33
28
|
}
|
|
34
|
-
export
|
|
29
|
+
export interface BlendArt {
|
|
30
|
+
mode: "blend";
|
|
31
|
+
/** Full-size canvas with the picture, drawn behind everything. */
|
|
32
|
+
picture: Canvas;
|
|
33
|
+
/** Light plates behind the finders, then the dots that correct the picture. */
|
|
34
|
+
rects: ArtRect[];
|
|
35
|
+
/** Dark color picked from the picture around each finder (top-left, top-right, bottom-left). */
|
|
36
|
+
finderColors: string[];
|
|
37
|
+
}
|
|
38
|
+
export type PreparedArt = HalftoneArt | ColorizeArt | BlendArt;
|
|
35
39
|
/** Default contrast per mode: colorize keeps the dot shapes, so it needs more contrast to scan reliably. */
|
|
36
40
|
export declare const DEFAULT_CONTRAST: {
|
|
37
41
|
halftone: number;
|
|
38
42
|
colorize: number;
|
|
43
|
+
blend: number;
|
|
39
44
|
};
|
|
40
45
|
export declare const getContrast: (art: ArtOptions) => number;
|
|
41
46
|
/** Luminance limits for "dark" and "light" pixels at a given contrast. */
|
|
@@ -46,6 +51,5 @@ export declare const getLimits: (contrast: number) => {
|
|
|
46
51
|
export declare const toDark: (color: RGB, limit: number) => RGB;
|
|
47
52
|
export declare const toLight: (color: RGB, limit: number) => RGB;
|
|
48
53
|
export declare function createCanvas(options: RequiredOptions, width: number, height: number): Canvas;
|
|
49
|
-
export declare function getQRArea(options: RequiredOptions, count: number): QRArea;
|
|
50
54
|
export declare function prepareArt(options: RequiredOptions, qr: QRCode, filter: FilterFunction): Promise<PreparedArt>;
|
|
51
55
|
export {};
|
package/lib/core/QRCanvas.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export default class QRCanvas {
|
|
|
8
8
|
_image?: HTMLImageElement;
|
|
9
9
|
/** Fill used for the dots instead of their color (QR art "colorize"). */
|
|
10
10
|
_dotsFill?: CanvasPattern;
|
|
11
|
+
/** Per-finder colors used when corners have no color of their own (QR art "blend"). */
|
|
12
|
+
_finderColors?: string[];
|
|
11
13
|
constructor(options: RequiredOptions);
|
|
12
14
|
get context(): CanvasRenderingContext2D | null;
|
|
13
15
|
get width(): number;
|
package/lib/core/QRSVG.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ 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
|
+
/** Per-finder colors used when corners have no color of their own (QR art "blend"). */
|
|
21
|
+
_finderColors?: string[];
|
|
20
22
|
constructor(options: RequiredOptions, sharedWindow?: Window);
|
|
21
23
|
get width(): number;
|
|
22
24
|
get height(): number;
|
package/lib/figures/shapes.d.ts
CHANGED
|
@@ -37,3 +37,14 @@ export declare const roundedRect: (x: number, y: number, width: number, height:
|
|
|
37
37
|
/** Finder ring with rounded corners: outer square minus inner square (even-odd). */
|
|
38
38
|
export declare const roundedRing: (x: number, y: number, size: number) => Shape;
|
|
39
39
|
export declare const roundedSquare: (x: number, y: number, size: number) => Shape;
|
|
40
|
+
/**
|
|
41
|
+
* "fluid" dot: a rounded square that flows into its dark neighbours, so runs of modules read as
|
|
42
|
+
* soft connected strokes and a lone module is a circle. Arms stay inside the module's own cell,
|
|
43
|
+
* so neighbouring shapes touch but never overlap.
|
|
44
|
+
*/
|
|
45
|
+
export declare const fluid: (x: number, y: number, size: number, neighbors: {
|
|
46
|
+
left: boolean;
|
|
47
|
+
right: boolean;
|
|
48
|
+
top: boolean;
|
|
49
|
+
bottom: boolean;
|
|
50
|
+
}) => Shape;
|