@liquid-js/qr-code-styling 1.6.0-rc.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Denys Kozak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # QR Code Styling
2
+ [![Version](https://img.shields.io/npm/v/qr-code-styling.svg)](https://www.npmjs.org/package/qr-code-styling)
3
+
4
+ JavaScript library for generating QR codes with a logo and styling.
5
+
6
+ Try it here https://qr-code-styling.com
7
+
8
+ If you have issues / suggestions / notes / questions, please open an issue or contact me. Let's create a cool library together.
9
+ ### Examples
10
+ <p float="left">
11
+ <img style="display:inline-block" src="https://raw.githubusercontent.com/kozakdenys/qr-code-styling/master/src/assets/facebook_example_new.png" width="240" />
12
+ <img style="display:inline-block" src="https://raw.githubusercontent.com/kozakdenys/qr-code-styling/master/src/assets/qr_code_example.png" width="240" />
13
+ <img style="display:inline-block" src="https://raw.githubusercontent.com/kozakdenys/qr-code-styling/master/src/assets/telegram_example_new.png" width="240" />
14
+ </p>
15
+
16
+ ### Installation
17
+
18
+ ```
19
+ npm install qr-code-styling
20
+ ```
21
+
22
+ ### Usage
23
+
24
+ ```HTML
25
+ <!DOCTYPE html>
26
+ <html lang="en">
27
+ <head>
28
+ <meta charset="UTF-8">
29
+ <title>QR Code Styling</title>
30
+ <script type="text/javascript" src="https://unpkg.com/qr-code-styling@1.5.0/lib/qr-code-styling.js"></script>
31
+ </head>
32
+ <body>
33
+ <div id="canvas"></div>
34
+ <script type="text/javascript">
35
+
36
+ const qrCode = new QRCodeStyling.QRCodeStyling({
37
+ width: 300,
38
+ height: 300,
39
+ type: "svg",
40
+ data: "https://www.facebook.com/",
41
+ image: "https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg",
42
+ dotsOptions: {
43
+ color: "#4267b2",
44
+ type: "rounded"
45
+ },
46
+ backgroundOptions: {
47
+ color: "#e9ebee",
48
+ },
49
+ imageOptions: {
50
+ crossOrigin: "anonymous",
51
+ margin: 20
52
+ }
53
+ });
54
+
55
+ qrCode.append(document.getElementById("canvas"));
56
+ QRCodeStyling.browserUtils.download(qrCode);
57
+ </script>
58
+ </body>
59
+ </html>
60
+ ```
61
+ ---
62
+
63
+ [**React example (Codesandbox)**](https://codesandbox.io/s/qr-code-styling-react-example-l8rwl?file=/src/App.js)
64
+
65
+ [**Angular example (Codesandbox)**](https://codesandbox.io/s/agitated-panini-tpgb2?file=/src/app/app.component.ts)
66
+
67
+ ---
68
+
69
+ [**React example (source)**](https://github.com/kozakdenys/qr-code-styling-examples/tree/master/examples/react)
70
+
71
+ [**Angular example (source)**](https://github.com/kozakdenys/qr-code-styling-examples/tree/master/examples/angular)
72
+
73
+ [**Vue example (source)**](https://github.com/kozakdenys/qr-code-styling-examples/tree/master/examples/vue)
74
+
75
+ ---
76
+
77
+ ### API Documentation
78
+
79
+ #### QRCodeStyling instance
80
+ `new QRCodeStyling(options) => QRCodeStyling`
81
+
82
+ Param |Type |Description
83
+ -------|------|------------
84
+ options|object|Init object
85
+
86
+ `options` structure
87
+
88
+ Property |Type |Default Value|Description
89
+ -----------------------|-------------------------|-------------|-----------------------------------------------------
90
+ width |number |`300` |Size of canvas
91
+ height |number |`300` |Size of canvas
92
+ data |string | |The date will be encoded to the QR code
93
+ image |string | |The image will be copied to the center of the QR code
94
+ margin |number |`0` |Margin around canvas
95
+ qrOptions |object | |Options will be passed to `qrcode-generator` lib
96
+ imageOptions |object | |Specific image options, details see below
97
+ dotsOptions |object | |Dots styling options
98
+ cornersSquareOptions |object | |Square in the corners styling options
99
+ cornersDotOptionsHelper|object | |Dots in the corners styling options
100
+ backgroundOptions |object | |QR background styling options
101
+
102
+ `options.qrOptions` structure
103
+
104
+ Property |Type |Default Value
105
+ --------------------|--------------------------------------------------|-------------
106
+ typeNumber |number (`0 - 40`) |`0`
107
+ mode |string (`'Numeric' 'Alphanumeric' 'Byte' 'Kanji'`)|
108
+ errorCorrectionLevel|string (`'L' 'M' 'Q' 'H'`) |`'Q'`
109
+
110
+ `options.imageOptions` structure
111
+
112
+ Property |Type |Default Value|Description
113
+ ------------------|---------------------------------------|-------------|------------------------------------------------------------------------------
114
+ hideBackgroundDots|boolean |`true` |Hide all dots covered by the image
115
+ imageSize |number |`0.4` |Coefficient of the image size. Not recommended to use ove 0.5. Lower is better
116
+ margin |number |`0` |Margin of the image in px
117
+ crossOrigin |string(`'anonymous' 'use-credentials'`)| |Set "anonymous" if you want to download QR code from other origins.
118
+
119
+ `options.dotsOptions` structure
120
+
121
+ Property|Type |Default Value|Description
122
+ --------|------------------------------------------------------------------------------|-------------|-------------------
123
+ color |string |`'#000'` |Color of QR dots
124
+ gradient|object | |Gradient of QR dots
125
+ type |string (`'rounded' 'dots' 'classy' 'classy-rounded' 'square' 'extra-rounded'`)|`'square'` |Style of QR dots
126
+
127
+ `options.backgroundOptions` structure
128
+
129
+ Property|Type |Default Value
130
+ --------|------|-------------
131
+ color |string|`'#fff'`
132
+ gradient|object|
133
+
134
+ `options.cornersSquareOptions` structure
135
+
136
+ Property|Type |Default Value|Description
137
+ --------|-----------------------------------------|-------------|-----------------
138
+ color |string | |Color of Corners Square
139
+ gradient|object | |Gradient of Corners Square
140
+ type |string (`'dot' 'square' 'extra-rounded'`)| |Style of Corners Square
141
+
142
+ `options.cornersDotOptions` structure
143
+
144
+ Property|Type |Default Value|Description
145
+ --------|-------------------------|-------------|-----------------
146
+ color |string | |Color of Corners Dot
147
+ gradient|object | |Gradient of Corners Dot
148
+ type |string (`'dot' 'square'`)| |Style of Corners Dot
149
+
150
+ Gradient structure
151
+
152
+ `options.dotsOptions.gradient`
153
+
154
+ `options.backgroundOptions.gradient`
155
+
156
+ `options.cornersSquareOptions.gradient`
157
+
158
+ `options.cornersDotOptions.gradient`
159
+
160
+ Property |Type |Default Value|Description
161
+ ----------|----------------------------|-------------|---------------------------------------------------------
162
+ type |string (`'linear' 'radial'`)|"linear" |Type of gradient spread
163
+ rotation |number |0 |Rotation of gradient in radians (Math.PI === 180 degrees)
164
+ colorStops|array of objects | |Gradient colors. Example `[{ offset: 0, color: 'blue' }, { offset: 1, color: 'red' }]`
165
+
166
+ Gradient colorStops structure
167
+
168
+ `options.dotsOptions.gradient.colorStops[]`
169
+
170
+ `options.backgroundOptions.gradient.colorStops[]`
171
+
172
+ `options.cornersSquareOptions.gradient.colorStops[]`
173
+
174
+ `options.cornersDotOptions.gradient.colorStops[]`
175
+
176
+ Property|Type |Default Value|Description
177
+ --------|----------------|-------------|-----------------------------------
178
+ offset |number (`0 - 1`)| |Position of color in gradient range
179
+ color |string | |Color of stop in gradient range
180
+
181
+ #### QRCodeStyling methods
182
+ `QRCodeStyling.append(container) => void`
183
+
184
+ Param |Type |Description
185
+ ---------|-----------|-----------
186
+ container|DOM element|This container will be used for appending of the QR code
187
+
188
+ `QRCodeStyling.serialize() => Promise<string>`
189
+
190
+ `QRCodeStyling.update(options) => void`
191
+
192
+ Param |Type |Description
193
+ -------|------|--------------------------------------
194
+ options|object|The same options as for initialization
195
+
196
+ `QRCodeStyling.applyExtension(extension) => void`
197
+
198
+ Param |Type |Description
199
+ ---------|----------------------|------------------------------------------------------------------------------------------
200
+ extension|(svg, options) => void|Extension is a function that takes svg and previously applied options and modifies an svg
201
+
202
+ `applyExtension` example
203
+
204
+ ```JS
205
+ const extension = (svg, options) => {
206
+ const { width, height } = options;
207
+ const size = Math.min(width, height);
208
+ const border = document.createElementNS("http://www.w3.org/2000/svg", "rect");
209
+ const borderAttributes = {
210
+ "fill": "none",
211
+ "x": (width - size + 40) / 2,
212
+ "y": (height - size + 40) / 2,
213
+ "width": size - 40,
214
+ "height": size - 40,
215
+ "stroke": 'black',
216
+ "stroke-width": 40,
217
+ "rx": 100,
218
+ };
219
+ Object.keys(borderAttributes).forEach(attribute => {
220
+ border.setAttribute(attribute, borderAttributes[attribute]);
221
+ });
222
+ svg.appendChild(border);
223
+ };
224
+ ```
225
+
226
+ `QRCodeStyling.deleteExtension() => void`
227
+
228
+
229
+ ### License
230
+
231
+ [MIT License](https://raw.githubusercontent.com/kozakdenys/qr-code-styling/master/LICENSE). Copyright (c) 2021 Denys Kozak
232
+
@@ -0,0 +1,6 @@
1
+ export declare const ErrorCorrectionPercents: {
2
+ L: number;
3
+ M: number;
4
+ Q: number;
5
+ H: number;
6
+ };
@@ -0,0 +1,19 @@
1
+ import { ExtensionFunction, Options, QRCode } from "../types";
2
+ import { RequiredOptions } from "./QROptions";
3
+ export declare class QRCodeStyling {
4
+ _options: RequiredOptions;
5
+ _container?: HTMLElement;
6
+ _svg?: SVGElement;
7
+ _qr?: QRCode;
8
+ _extension?: ExtensionFunction;
9
+ _svgDrawingPromise?: Promise<void>;
10
+ constructor(options?: Partial<Options>);
11
+ static _clearContainer(container?: HTMLElement): void;
12
+ _setupSvg(): void;
13
+ _getElement(): Promise<SVGElement | undefined>;
14
+ update(options?: Partial<Options>): void;
15
+ append(container?: HTMLElement): void;
16
+ applyExtension(extension: ExtensionFunction): void;
17
+ deleteExtension(): void;
18
+ serialize(): Promise<string | undefined>;
19
+ }
@@ -0,0 +1,26 @@
1
+ import { DotType, ErrorCorrectionLevel, Gradient, Mode, Options, ShapeType, TypeNumber } from "../types";
2
+ export interface RequiredOptions extends Options {
3
+ document: Document;
4
+ shape: ShapeType;
5
+ width: number;
6
+ height: number;
7
+ margin: number;
8
+ data: string;
9
+ qrOptions: {
10
+ typeNumber: TypeNumber;
11
+ mode?: Mode;
12
+ errorCorrectionLevel: ErrorCorrectionLevel;
13
+ };
14
+ imageOptions: {
15
+ hideBackgroundDots: boolean;
16
+ imageSize: number;
17
+ crossOrigin?: string;
18
+ margin: number;
19
+ };
20
+ dotsOptions: {
21
+ type: DotType;
22
+ color: string;
23
+ gradient?: Gradient;
24
+ };
25
+ }
26
+ export declare const defaultOptions: RequiredOptions;
@@ -0,0 +1,38 @@
1
+ import { FilterFunction, Gradient, QRCode } from "../types";
2
+ import { RequiredOptions } from "./QROptions";
3
+ export declare class QRSVG {
4
+ _element: SVGElement;
5
+ _defs: SVGElement;
6
+ _backgroundClipPath?: SVGElement;
7
+ _dotsClipPath?: SVGElement;
8
+ _cornersSquareClipPath?: SVGElement;
9
+ _cornersDotClipPath?: SVGElement;
10
+ _options: RequiredOptions;
11
+ _qr?: QRCode;
12
+ _document: Document;
13
+ private _imageTools;
14
+ constructor(options: RequiredOptions);
15
+ get width(): number;
16
+ get height(): number;
17
+ getElement(): SVGElement;
18
+ drawQR(qr: QRCode): Promise<void>;
19
+ drawBackground(): void;
20
+ drawDots(filter?: FilterFunction): void;
21
+ drawCorners(): void;
22
+ drawImage({ width, height, count, dotSize }: {
23
+ width: number;
24
+ height: number;
25
+ count: number;
26
+ dotSize: number;
27
+ }): Promise<void>;
28
+ _createColor({ options, color, additionalRotation, x, y, height, width, name }: {
29
+ options?: Gradient;
30
+ color?: string;
31
+ additionalRotation: number;
32
+ x: number;
33
+ y: number;
34
+ height: number;
35
+ width: number;
36
+ name: string;
37
+ }): void;
38
+ }
@@ -0,0 +1,18 @@
1
+ import { CornerDotType, RotateFigureArgs, BasicFigureDrawArgs, DrawArgs } from "../../types";
2
+ export declare class QRCornerDot {
3
+ _element?: SVGElement;
4
+ _svg: SVGElement;
5
+ _type: CornerDotType;
6
+ _document: Document;
7
+ constructor({ svg, type, document }: {
8
+ svg: SVGElement;
9
+ type: CornerDotType;
10
+ document: Document;
11
+ });
12
+ draw(x: number, y: number, size: number, rotation: number): void;
13
+ _rotateFigure({ x, y, size, rotation, draw }: RotateFigureArgs): void;
14
+ _basicDot(args: BasicFigureDrawArgs): void;
15
+ _basicSquare(args: BasicFigureDrawArgs): void;
16
+ _drawDot({ x, y, size, rotation }: DrawArgs): void;
17
+ _drawSquare({ x, y, size, rotation }: DrawArgs): void;
18
+ }
@@ -0,0 +1,20 @@
1
+ import { CornerSquareType, DrawArgs, BasicFigureDrawArgs, RotateFigureArgs } from "../../types";
2
+ export declare class QRCornerSquare {
3
+ _element?: SVGElement;
4
+ _svg: SVGElement;
5
+ _type: CornerSquareType;
6
+ _document: Document;
7
+ constructor({ svg, type, document }: {
8
+ svg: SVGElement;
9
+ type: CornerSquareType;
10
+ document: Document;
11
+ });
12
+ draw(x: number, y: number, size: number, rotation: number): void;
13
+ _rotateFigure({ x, y, size, rotation, draw }: RotateFigureArgs): void;
14
+ _basicDot(args: BasicFigureDrawArgs): void;
15
+ _basicSquare(args: BasicFigureDrawArgs): void;
16
+ _basicExtraRounded(args: BasicFigureDrawArgs): void;
17
+ _drawDot({ x, y, size, rotation }: DrawArgs): void;
18
+ _drawSquare({ x, y, size, rotation }: DrawArgs): void;
19
+ _drawExtraRounded({ x, y, size, rotation }: DrawArgs): void;
20
+ }
@@ -0,0 +1,26 @@
1
+ import { DotType, GetNeighbor, DrawArgs, BasicFigureDrawArgs, RotateFigureArgs } from "../../types";
2
+ export declare class QRDot {
3
+ _element?: SVGElement;
4
+ _svg: SVGElement;
5
+ _type: DotType;
6
+ _document: Document;
7
+ constructor({ svg, type, document }: {
8
+ svg: SVGElement;
9
+ type: DotType;
10
+ document: Document;
11
+ });
12
+ draw(x: number, y: number, size: number, getNeighbor: GetNeighbor): void;
13
+ _rotateFigure({ x, y, size, rotation, draw }: RotateFigureArgs): void;
14
+ _basicDot(args: BasicFigureDrawArgs): void;
15
+ _basicSquare(args: BasicFigureDrawArgs): void;
16
+ _basicSideRounded(args: BasicFigureDrawArgs): void;
17
+ _basicCornerRounded(args: BasicFigureDrawArgs): void;
18
+ _basicCornerExtraRounded(args: BasicFigureDrawArgs): void;
19
+ _basicCornersRounded(args: BasicFigureDrawArgs): void;
20
+ _drawDot({ x, y, size }: DrawArgs): void;
21
+ _drawSquare({ x, y, size }: DrawArgs): void;
22
+ _drawRounded({ x, y, size, getNeighbor }: DrawArgs): void;
23
+ _drawExtraRounded({ x, y, size, getNeighbor }: DrawArgs): void;
24
+ _drawClassy({ x, y, size, getNeighbor }: DrawArgs): void;
25
+ _drawClassyRounded({ x, y, size, getNeighbor }: DrawArgs): void;
26
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { ErrorCorrectionPercents } from "./constants/errorCorrectionPercents";
2
+ import { QRCodeStyling } from "./core/QRCodeStyling";
3
+ import * as browserUtils from "./tools/browserUtils";
4
+ import * as types from "./types";
5
+ export * from "./tools/browserUtils";
6
+ export * from "./types";
7
+ export { ErrorCorrectionPercents, QRCodeStyling };
8
+ declare const _default: {
9
+ QRCodeStyling: typeof QRCodeStyling;
10
+ browserUtils: typeof browserUtils;
11
+ types: typeof types;
12
+ };
13
+ export default _default;
package/lib/node.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { RequiredOptions } from "./core/QROptions";
2
+ import { QRCodeStyling as _QRCodeStyling } from "./index";
3
+ export { ErrorCorrectionPercents } from "./constants/errorCorrectionPercents";
4
+ export * from "./types";
5
+ export declare class QRCodeStyling extends _QRCodeStyling {
6
+ constructor(options: RequiredOptions);
7
+ }