@vkontakte/vk-qr 2.1.1 → 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 +1 -1
- 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/{types/svg.d.ts → svg.d.ts} +10 -9
- package/dist/svg.d.ts.map +1 -0
- package/dist/{types/types.d.ts → types.d.ts} +57 -51
- package/dist/types.d.ts.map +1 -0
- package/package.json +55 -80
- package/src/index.ts +38 -26
- package/src/qr.ts +217 -179
- package/src/svg.ts +28 -12
- package/src/types.ts +15 -11
- package/dist/cjs/index.js +0 -1185
- package/dist/es/index.js +0 -1183
- package/dist/types/index.d.ts +0 -20
- package/dist/umd/qrCodeGenerator.js +0 -1191
- package/dist/umd/qrCodeGenerator.min.js +0 -1
package/package.json
CHANGED
|
@@ -1,82 +1,57 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"rollup-plugin-babel": "^4.3.3",
|
|
58
|
-
"rollup-plugin-bundle-size": "^1.0.3",
|
|
59
|
-
"rollup-plugin-commonjs": "^10.0.1",
|
|
60
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
61
|
-
"rollup-plugin-typescript2": "^0.22.0",
|
|
62
|
-
"rollup-plugin-uglify": "^6.0.2",
|
|
63
|
-
"size-limit": "^11.0.0",
|
|
64
|
-
"ts-node": "^8.3.0",
|
|
65
|
-
"typescript": "^3.5.3",
|
|
66
|
-
"xml-js": "^1.6.11"
|
|
67
|
-
},
|
|
68
|
-
"size-limit": [
|
|
69
|
-
{
|
|
70
|
-
"path": "dist/cjs/index.js"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"path": "dist/es/index.js"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"path": "dist/umd/qrCodeGenerator.js"
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
|
-
"publishConfig": {
|
|
80
|
-
"access": "public"
|
|
81
|
-
}
|
|
2
|
+
"name": "@vkontakte/vk-qr",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "QR Code generator",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"module": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "node --test tests/**/*.test.ts",
|
|
23
|
+
"test:update": "UPDATE_SNAPSHOTS=1 node --import tsx --test tests/**/*.test.ts",
|
|
24
|
+
"watch": "rslib --watch",
|
|
25
|
+
"build": "rslib",
|
|
26
|
+
"lint": "yarn lint:biome && yarn lint:types",
|
|
27
|
+
"size": "size-limit",
|
|
28
|
+
"lint:biome": "biome check",
|
|
29
|
+
"lint:biome:fix": "biome check --write",
|
|
30
|
+
"lint:types": "tsc -b",
|
|
31
|
+
"prepack": "yarn build"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [],
|
|
34
|
+
"author": "vk.ru",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": "VKCOM/vk-qr",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@swc/helpers": "^0.5.21"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@biomejs/biome": "^2.4.12",
|
|
42
|
+
"@rslib/core": "^0.21.2",
|
|
43
|
+
"@size-limit/preset-small-lib": "^12.1.0",
|
|
44
|
+
"@types/node": "^25.6.0",
|
|
45
|
+
"size-limit": "^12.1.0",
|
|
46
|
+
"typescript": "^6.0.3"
|
|
47
|
+
},
|
|
48
|
+
"size-limit": [
|
|
49
|
+
{
|
|
50
|
+
"path": "dist/index.js"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
82
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { convertSegmentsToSvgString, INC_TILE_SIZE } from './svg';
|
|
2
|
-
import { QrSegment, QrCode } from './qr';
|
|
3
|
-
import { QrOptions } from './types';
|
|
4
|
-
import Ecc = QrCode.Ecc;
|
|
1
|
+
import { convertSegmentsToSvgString, INC_TILE_SIZE } from './svg.ts';
|
|
2
|
+
import { QrSegment, QrCode, QrCodeEcc } from './qr.ts';
|
|
3
|
+
import type { QrOptions, RequiredQrOptions } from './types.ts';
|
|
5
4
|
|
|
6
5
|
/** Default width and height of QR code */
|
|
7
6
|
const DEFAULT_SIZE = 128;
|
|
@@ -20,7 +19,7 @@ const LOGO_COLOR_DEFAULT = '#07f';
|
|
|
20
19
|
* @param text String to encode
|
|
21
20
|
* @param options QR code options
|
|
22
21
|
*/
|
|
23
|
-
function createQR(text: string, options?: QrOptions): string;
|
|
22
|
+
export function createQR(text: string, options?: QrOptions): string;
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Legacy interface
|
|
@@ -30,16 +29,21 @@ function createQR(text: string, options?: QrOptions): string;
|
|
|
30
29
|
* @param className SVG element class name
|
|
31
30
|
* @param options Options of the QR code
|
|
32
31
|
*/
|
|
33
|
-
function createQR(
|
|
32
|
+
export function createQR(
|
|
33
|
+
text: string,
|
|
34
|
+
qrSize: number,
|
|
35
|
+
className: string,
|
|
36
|
+
options?: QrOptions,
|
|
37
|
+
): string;
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
40
|
* Implementation
|
|
37
41
|
*/
|
|
38
|
-
function createQR(
|
|
42
|
+
export function createQR(
|
|
39
43
|
text: string,
|
|
40
44
|
qrSizeOrOptions?: number | QrOptions,
|
|
41
45
|
classNameLegacy?: string,
|
|
42
|
-
legacyOptions?: QrOptions
|
|
46
|
+
legacyOptions?: QrOptions,
|
|
43
47
|
): string {
|
|
44
48
|
if (typeof text !== 'string') {
|
|
45
49
|
throw new TypeError('Enter text for encoding');
|
|
@@ -50,46 +54,54 @@ function createQR(
|
|
|
50
54
|
...(typeof qrSizeOrOptions === 'object' && qrSizeOrOptions !== null ? qrSizeOrOptions : {}),
|
|
51
55
|
...(typeof legacyOptions === 'object' && legacyOptions !== null ? legacyOptions : {}),
|
|
52
56
|
qrSize:
|
|
53
|
-
typeof qrSizeOrOptions === 'object' &&
|
|
57
|
+
typeof qrSizeOrOptions === 'object' &&
|
|
58
|
+
qrSizeOrOptions !== null &&
|
|
59
|
+
typeof qrSizeOrOptions.qrSize === 'number'
|
|
54
60
|
? qrSizeOrOptions.qrSize
|
|
55
61
|
: (qrSizeOrOptions as number),
|
|
56
62
|
className:
|
|
57
|
-
typeof qrSizeOrOptions === 'object' &&
|
|
63
|
+
typeof qrSizeOrOptions === 'object' &&
|
|
64
|
+
qrSizeOrOptions !== null &&
|
|
65
|
+
typeof qrSizeOrOptions.className === 'string'
|
|
58
66
|
? qrSizeOrOptions.className
|
|
59
|
-
: classNameLegacy
|
|
67
|
+
: classNameLegacy,
|
|
60
68
|
};
|
|
61
69
|
|
|
62
70
|
// ECC levels mapping
|
|
63
|
-
const eccLevels = [
|
|
64
|
-
QrCode.Ecc.LOW,
|
|
65
|
-
QrCode.Ecc.MEDIUM,
|
|
66
|
-
QrCode.Ecc.QUARTILE,
|
|
67
|
-
QrCode.Ecc.HIGH
|
|
68
|
-
];
|
|
71
|
+
const eccLevels = [QrCodeEcc.LOW, QrCodeEcc.MEDIUM, QrCodeEcc.QUARTILE, QrCodeEcc.HIGH];
|
|
69
72
|
|
|
70
73
|
// Fallback undefined options
|
|
71
|
-
const fallbackOptions:
|
|
74
|
+
const fallbackOptions: RequiredQrOptions = {
|
|
72
75
|
qrSize: typeof options.qrSize === 'number' ? options.qrSize : DEFAULT_SIZE,
|
|
73
76
|
className: typeof options.className === 'string' ? options.className : classNameLegacy || '',
|
|
74
77
|
isShowLogo: !!options.isShowLogo || false,
|
|
75
78
|
isShowBackground: !!options.isShowBackground || false,
|
|
76
|
-
foregroundColor:
|
|
77
|
-
|
|
79
|
+
foregroundColor:
|
|
80
|
+
typeof options.foregroundColor === 'string'
|
|
81
|
+
? options.foregroundColor
|
|
82
|
+
: FOREGROUND_COLOR_DEFAULT,
|
|
83
|
+
backgroundColor:
|
|
84
|
+
typeof options.backgroundColor === 'string'
|
|
85
|
+
? options.backgroundColor
|
|
86
|
+
: BACKGROUND_COLOR_DEFAULT,
|
|
78
87
|
logoColor: typeof options.logoColor === 'string' ? options.logoColor : LOGO_COLOR_DEFAULT,
|
|
79
88
|
suffix: options.suffix ? options.suffix.toString() : '0',
|
|
80
89
|
logoData: typeof options.logoData === 'string' ? options.logoData : null,
|
|
81
|
-
ecc:
|
|
90
|
+
ecc: typeof options.ecc === 'number' && eccLevels[options.ecc] ? options.ecc : 3,
|
|
82
91
|
incTileSize: typeof options.incTileSize === 'number' ? options.incTileSize : INC_TILE_SIZE,
|
|
83
92
|
};
|
|
84
93
|
|
|
85
94
|
// Code generation
|
|
86
95
|
const segments: QrSegment[] = QrSegment.makeSegments(text);
|
|
87
|
-
const qrCode: QrCode = QrCode.encodeSegments(
|
|
96
|
+
const qrCode: QrCode = QrCode.encodeSegments(
|
|
97
|
+
segments,
|
|
98
|
+
eccLevels[fallbackOptions.ecc],
|
|
99
|
+
1,
|
|
100
|
+
40,
|
|
101
|
+
-1,
|
|
102
|
+
true,
|
|
103
|
+
);
|
|
88
104
|
const svgCode = convertSegmentsToSvgString(qrCode, fallbackOptions);
|
|
89
105
|
|
|
90
106
|
return svgCode;
|
|
91
107
|
}
|
|
92
|
-
|
|
93
|
-
export default {
|
|
94
|
-
createQR
|
|
95
|
-
};
|