@vkontakte/vk-qr 2.0.13 → 3.0.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/LICENSE +1 -1
- package/README.md +3 -3
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1135 -0
- package/dist/index.js.map +1 -0
- package/dist/{types/qr.d.ts → qr.d.ts} +79 -87
- package/dist/qr.d.ts.map +1 -0
- package/dist/svg.d.ts +10 -0
- package/dist/svg.d.ts.map +1 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +55 -77
- package/src/index.ts +39 -26
- package/src/qr.ts +217 -179
- package/src/svg.ts +30 -14
- package/src/types.ts +19 -10
- package/dist/cjs/index.js +0 -1184
- package/dist/es/index.js +0 -1182
- package/dist/types/index.d.ts +0 -20
- package/dist/types/svg.d.ts +0 -8
- package/dist/types/types.d.ts +0 -47
- package/dist/umd/qrCodeGenerator.js +0 -1190
- package/dist/umd/qrCodeGenerator.min.js +0 -1
package/src/svg.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { QrCode } from './qr';
|
|
2
|
-
import {
|
|
1
|
+
import type { QrCode } from './qr.ts';
|
|
2
|
+
import type { RequiredQrOptions } from './types.ts';
|
|
3
3
|
|
|
4
4
|
const MULTI = 1;
|
|
5
5
|
const QR_BORDER = 7;
|
|
6
6
|
const TILE_SIZE = 96 * MULTI;
|
|
7
|
-
const INC_TILE_SIZE = 96 * MULTI;
|
|
7
|
+
export const INC_TILE_SIZE = 96 * MULTI;
|
|
8
8
|
const SMALL_QR_SIZE = 25;
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -12,7 +12,13 @@ const SMALL_QR_SIZE = 25;
|
|
|
12
12
|
* for white or true for black. The top left corner has the coordinates (x=0, y=0).
|
|
13
13
|
* If the given coordinates are out of bounds, then false (white) is returned.
|
|
14
14
|
*/
|
|
15
|
-
const getPixel = (
|
|
15
|
+
const getPixel = (
|
|
16
|
+
x: number,
|
|
17
|
+
y: number,
|
|
18
|
+
size: number,
|
|
19
|
+
modules: boolean[][],
|
|
20
|
+
isLogoShowed: boolean,
|
|
21
|
+
) => {
|
|
16
22
|
if (x < QR_BORDER && y < QR_BORDER) {
|
|
17
23
|
return false;
|
|
18
24
|
}
|
|
@@ -48,15 +54,21 @@ const getPixel = (x: number, y: number, size: number, modules: boolean[][], isLo
|
|
|
48
54
|
return 0 <= x && x < size && 0 <= y && y < size && modules[y][x];
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
return modules[y]
|
|
57
|
+
return modules[y]?.[x];
|
|
52
58
|
};
|
|
53
59
|
|
|
54
|
-
const getNeighbors = (
|
|
60
|
+
const getNeighbors = (
|
|
61
|
+
x: number,
|
|
62
|
+
y: number,
|
|
63
|
+
size: number,
|
|
64
|
+
modules: boolean[][],
|
|
65
|
+
isLogoShowed = true,
|
|
66
|
+
) => ({
|
|
55
67
|
l: getPixel(x - 1, y, size, modules, isLogoShowed),
|
|
56
68
|
r: getPixel(x + 1, y, size, modules, isLogoShowed),
|
|
57
69
|
t: getPixel(x, y - 1, size, modules, isLogoShowed),
|
|
58
70
|
b: getPixel(x, y + 1, size, modules, isLogoShowed),
|
|
59
|
-
current: getPixel(x, y, size, modules, isLogoShowed)
|
|
71
|
+
current: getPixel(x, y, size, modules, isLogoShowed),
|
|
60
72
|
});
|
|
61
73
|
|
|
62
74
|
/**
|
|
@@ -64,7 +76,7 @@ const getNeighbors = (x: number, y: number, size: number, modules: boolean[][],
|
|
|
64
76
|
* @param qrCode QrCode instance
|
|
65
77
|
* @param options Convertation options
|
|
66
78
|
*/
|
|
67
|
-
export const convertSegmentsToSvgString = (qrCode: QrCode, options:
|
|
79
|
+
export const convertSegmentsToSvgString = (qrCode: QrCode, options: RequiredQrOptions): string => {
|
|
68
80
|
if (typeof options.qrSize !== 'number') {
|
|
69
81
|
throw new Error('Size should be a number');
|
|
70
82
|
}
|
|
@@ -111,8 +123,10 @@ export const convertSegmentsToSvgString = (qrCode: QrCode, options: Required<QrO
|
|
|
111
123
|
let selector = '';
|
|
112
124
|
|
|
113
125
|
if (neighbors.current) {
|
|
114
|
-
selector =
|
|
115
|
-
|
|
126
|
+
selector =
|
|
127
|
+
!selector && !neighbors.l && !neighbors.r && !neighbors.t && !neighbors.b ? 'empty' : '';
|
|
128
|
+
selector =
|
|
129
|
+
(!selector && neighbors.l && neighbors.r) || (neighbors.t && neighbors.b) ? 'rect' : '';
|
|
116
130
|
if (!selector) {
|
|
117
131
|
selector += neighbors.l ? 'l' : neighbors.r ? 'r' : '';
|
|
118
132
|
selector += neighbors.t ? 't' : neighbors.b ? 'b' : '';
|
|
@@ -167,13 +181,15 @@ export const convertSegmentsToSvgString = (qrCode: QrCode, options: Required<QrO
|
|
|
167
181
|
position += 50;
|
|
168
182
|
}
|
|
169
183
|
|
|
170
|
-
const pointPosition = (qrCode.size - QR_BORDER) *
|
|
171
|
-
parts.push(
|
|
184
|
+
const pointPosition = (qrCode.size - QR_BORDER) * options.incTileSize;
|
|
185
|
+
parts.push(
|
|
186
|
+
`<use fill-rule="evenodd" transform="translate(0,0)" xlink:href="#point-${options.suffix}"/>`,
|
|
187
|
+
);
|
|
172
188
|
parts.push(
|
|
173
|
-
`<use fill-rule="evenodd" transform="translate(${pointPosition},0)" xlink:href="#point-${options.suffix}"
|
|
189
|
+
`<use fill-rule="evenodd" transform="translate(${pointPosition},0)" xlink:href="#point-${options.suffix}"/>`,
|
|
174
190
|
);
|
|
175
191
|
parts.push(
|
|
176
|
-
`<use fill-rule="evenodd" transform="translate(0,${pointPosition})" xlink:href="#point-${options.suffix}"
|
|
192
|
+
`<use fill-rule="evenodd" transform="translate(0,${pointPosition})" xlink:href="#point-${options.suffix}"/>`,
|
|
177
193
|
);
|
|
178
194
|
|
|
179
195
|
if (options.isShowLogo) {
|
package/src/types.ts
CHANGED
|
@@ -3,54 +3,63 @@ export type QrOptions = {
|
|
|
3
3
|
* Size of QR code
|
|
4
4
|
* @default 128
|
|
5
5
|
*/
|
|
6
|
-
qrSize?: number;
|
|
6
|
+
qrSize?: number | undefined;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Class name of root SVG element
|
|
10
10
|
*/
|
|
11
|
-
className?: string;
|
|
11
|
+
className?: string | undefined;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Show VK logo in center of QR code
|
|
15
15
|
* @default false
|
|
16
16
|
*/
|
|
17
|
-
isShowLogo?: boolean;
|
|
17
|
+
isShowLogo?: boolean | undefined;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Show QR background
|
|
21
21
|
* @default false
|
|
22
22
|
*/
|
|
23
|
-
isShowBackground?: boolean;
|
|
23
|
+
isShowBackground?: boolean | undefined;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* QR code background HEX color. Works if `isShowBackground` is enabled.
|
|
27
27
|
* @default "#ffffff"
|
|
28
28
|
*/
|
|
29
|
-
backgroundColor?: string;
|
|
29
|
+
backgroundColor?: string | undefined;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* QR code HEX color
|
|
33
33
|
*/
|
|
34
|
-
foregroundColor?: string;
|
|
34
|
+
foregroundColor?: string | undefined;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Color of logo
|
|
38
38
|
* @default "#000000"
|
|
39
39
|
*/
|
|
40
|
-
logoColor?: string;
|
|
40
|
+
logoColor?: string | undefined;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Reference to logo as a reference IRI
|
|
44
44
|
*/
|
|
45
|
-
logoData?: string | null;
|
|
45
|
+
logoData?: string | null | undefined;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* SVG elements id postfix
|
|
49
49
|
*/
|
|
50
|
-
suffix?: string;
|
|
50
|
+
suffix?: string | undefined;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* ECC Level
|
|
54
54
|
*/
|
|
55
|
-
ecc?: number
|
|
55
|
+
ecc?: number | undefined;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Custom INC_TILE_SIZE
|
|
59
|
+
*/
|
|
60
|
+
incTileSize?: number | undefined;
|
|
56
61
|
};
|
|
62
|
+
|
|
63
|
+
type NotUndefined<T> = { [k in keyof T]-?: Exclude<T[k], undefined> };
|
|
64
|
+
|
|
65
|
+
export type RequiredQrOptions = NotUndefined<QrOptions>;
|