uqr 0.0.3 → 0.1.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 +24 -2
- package/dist/index.cjs +9 -5
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +9 -5
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# uqr
|
|
2
2
|
|
|
3
|
-
[![
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![bundle][bundle-src]][bundle-href]
|
|
6
|
+
[![License][license-src]][license-href]
|
|
7
|
+
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
10
|
+
|
|
11
|
+
Generate QR Code universally, in any runtime, to ANSI, Unicode or SVG. ES module , zero dependency, tree-shakable.
|
|
6
12
|
|
|
7
13
|
## Install
|
|
8
14
|
|
|
@@ -114,3 +120,19 @@ CLI renders are inspired by [qrcode-terminal](https://github.com/gtanner/qrcode-
|
|
|
114
120
|
## License
|
|
115
121
|
|
|
116
122
|
[MIT](./LICENSE) License
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
<!-- Badges -->
|
|
126
|
+
|
|
127
|
+
[npm-version-src]: https://img.shields.io/npm/v/uqr?style=flat&colorA=18181B&colorB=F0DB4F
|
|
128
|
+
[npm-version-href]: https://npmjs.com/package/uqr
|
|
129
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/uqr?style=flat&colorA=18181B&colorB=F0DB4F
|
|
130
|
+
[npm-downloads-href]: https://npmjs.com/package/uqr
|
|
131
|
+
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/uqr/main?style=flat&colorA=18181B&colorB=F0DB4F
|
|
132
|
+
[codecov-href]: https://codecov.io/gh/unjs/uqr
|
|
133
|
+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/uqr?style=flat&colorA=18181B&colorB=F0DB4F
|
|
134
|
+
[bundle-href]: https://bundlephobia.com/result?p=uqr
|
|
135
|
+
[license-src]: https://img.shields.io/github/license/unjs/uqr.svg?style=flat&colorA=18181B&colorB=F0DB4F
|
|
136
|
+
[license-href]: https://github.com/unjs/uqr/blob/main/LICENSE
|
|
137
|
+
[jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F
|
|
138
|
+
[jsdocs-href]: https://www.jsdocs.io/package/uqr
|
package/dist/index.cjs
CHANGED
|
@@ -613,12 +613,13 @@ function encode(data, options) {
|
|
|
613
613
|
}, border);
|
|
614
614
|
if (options?.invert)
|
|
615
615
|
result.data = result.data.map((row) => row.map((mod) => !mod));
|
|
616
|
+
options?.onEncoded?.(result);
|
|
616
617
|
return result;
|
|
617
618
|
}
|
|
618
619
|
function addBorder(input, border = 1) {
|
|
619
620
|
if (!border)
|
|
620
621
|
return input;
|
|
621
|
-
const { size
|
|
622
|
+
const { size } = input;
|
|
622
623
|
const newSize = size + border * 2;
|
|
623
624
|
input.size = newSize;
|
|
624
625
|
input.data.forEach((row) => {
|
|
@@ -700,21 +701,24 @@ function renderUnicodeCompact(data, options = {}) {
|
|
|
700
701
|
function renderSVG(data, options = {}) {
|
|
701
702
|
const result = encode(data, options);
|
|
702
703
|
const {
|
|
703
|
-
pixelSize =
|
|
704
|
+
pixelSize = 10,
|
|
704
705
|
whiteColor = "white",
|
|
705
706
|
blackColor = "black"
|
|
706
707
|
} = options;
|
|
707
708
|
const height = result.size * pixelSize;
|
|
708
709
|
const width = result.size * pixelSize;
|
|
709
|
-
let svg = `<svg xmlns="http://www.w3.org/2000/svg"
|
|
710
|
+
let svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}">`;
|
|
711
|
+
const pathes = [];
|
|
710
712
|
for (let row = 0; row < result.size; row++) {
|
|
711
713
|
for (let col = 0; col < result.size; col++) {
|
|
712
714
|
const x = col * pixelSize;
|
|
713
715
|
const y = row * pixelSize;
|
|
714
|
-
|
|
715
|
-
|
|
716
|
+
if (result.data[row][col])
|
|
717
|
+
pathes.push(`M${x},${y}h${pixelSize}v${pixelSize}h-${pixelSize}z`);
|
|
716
718
|
}
|
|
717
719
|
}
|
|
720
|
+
svg += `<rect fill="${whiteColor}" width="${width}" height="${height}"/>`;
|
|
721
|
+
svg += `<path fill="${blackColor}" d="${pathes.join("")}"/>`;
|
|
718
722
|
svg += "</svg>";
|
|
719
723
|
return svg;
|
|
720
724
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ interface QrCodeGenerateOptions {
|
|
|
44
44
|
* Invert black and white
|
|
45
45
|
*/
|
|
46
46
|
invert?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Callback function to receive the generated QR Code
|
|
49
|
+
*/
|
|
50
|
+
onEncoded?: (qr: QrCodeGenerateResult) => void;
|
|
47
51
|
}
|
|
48
52
|
declare enum QrCodeDataType {
|
|
49
53
|
Border = -1,
|
|
@@ -88,7 +92,7 @@ interface QrCodeGenerateSvgOptions extends QrCodeGenerateOptions {
|
|
|
88
92
|
/**
|
|
89
93
|
* Size of each pixel
|
|
90
94
|
*
|
|
91
|
-
* @default
|
|
95
|
+
* @default 20
|
|
92
96
|
*/
|
|
93
97
|
pixelSize?: number;
|
|
94
98
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -611,12 +611,13 @@ function encode(data, options) {
|
|
|
611
611
|
}, border);
|
|
612
612
|
if (options?.invert)
|
|
613
613
|
result.data = result.data.map((row) => row.map((mod) => !mod));
|
|
614
|
+
options?.onEncoded?.(result);
|
|
614
615
|
return result;
|
|
615
616
|
}
|
|
616
617
|
function addBorder(input, border = 1) {
|
|
617
618
|
if (!border)
|
|
618
619
|
return input;
|
|
619
|
-
const { size
|
|
620
|
+
const { size } = input;
|
|
620
621
|
const newSize = size + border * 2;
|
|
621
622
|
input.size = newSize;
|
|
622
623
|
input.data.forEach((row) => {
|
|
@@ -698,21 +699,24 @@ function renderUnicodeCompact(data, options = {}) {
|
|
|
698
699
|
function renderSVG(data, options = {}) {
|
|
699
700
|
const result = encode(data, options);
|
|
700
701
|
const {
|
|
701
|
-
pixelSize =
|
|
702
|
+
pixelSize = 10,
|
|
702
703
|
whiteColor = "white",
|
|
703
704
|
blackColor = "black"
|
|
704
705
|
} = options;
|
|
705
706
|
const height = result.size * pixelSize;
|
|
706
707
|
const width = result.size * pixelSize;
|
|
707
|
-
let svg = `<svg xmlns="http://www.w3.org/2000/svg"
|
|
708
|
+
let svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}">`;
|
|
709
|
+
const pathes = [];
|
|
708
710
|
for (let row = 0; row < result.size; row++) {
|
|
709
711
|
for (let col = 0; col < result.size; col++) {
|
|
710
712
|
const x = col * pixelSize;
|
|
711
713
|
const y = row * pixelSize;
|
|
712
|
-
|
|
713
|
-
|
|
714
|
+
if (result.data[row][col])
|
|
715
|
+
pathes.push(`M${x},${y}h${pixelSize}v${pixelSize}h-${pixelSize}z`);
|
|
714
716
|
}
|
|
715
717
|
}
|
|
718
|
+
svg += `<rect fill="${whiteColor}" width="${width}" height="${height}"/>`;
|
|
719
|
+
svg += `<path fill="${blackColor}" d="${pathes.join("")}"/>`;
|
|
716
720
|
svg += "</svg>";
|
|
717
721
|
return svg;
|
|
718
722
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uqr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"packageManager": "pnpm@8.6.
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"packageManager": "pnpm@8.6.12",
|
|
6
6
|
"description": "Generate QR Code universally, in any runtime, to ANSI, Unicode or SVG.",
|
|
7
7
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -46,21 +46,21 @@
|
|
|
46
46
|
"typecheck": "tsc --noEmit"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@antfu/eslint-config": "^0.40.
|
|
49
|
+
"@antfu/eslint-config": "^0.40.2",
|
|
50
50
|
"@antfu/ni": "^0.21.5",
|
|
51
51
|
"@antfu/utils": "^0.7.5",
|
|
52
|
-
"@types/node": "^20.4.
|
|
52
|
+
"@types/node": "^20.4.9",
|
|
53
53
|
"bumpp": "^9.1.1",
|
|
54
54
|
"eslint": "^8.46.0",
|
|
55
55
|
"esno": "^0.17.0",
|
|
56
56
|
"lint-staged": "^13.2.3",
|
|
57
|
-
"pnpm": "^8.6.
|
|
57
|
+
"pnpm": "^8.6.12",
|
|
58
58
|
"rimraf": "^5.0.1",
|
|
59
|
-
"rollup": "^3.
|
|
59
|
+
"rollup": "^3.28.0",
|
|
60
60
|
"simple-git-hooks": "^2.9.0",
|
|
61
61
|
"typescript": "^5.1.6",
|
|
62
62
|
"unbuild": "^1.2.1",
|
|
63
|
-
"vite": "^4.4.
|
|
63
|
+
"vite": "^4.4.9",
|
|
64
64
|
"vitest": "^0.34.1"
|
|
65
65
|
},
|
|
66
66
|
"simple-git-hooks": {
|