@nuvui/barcodes 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +60 -2
- package/dist/components/barcode/barcode.cjs +94 -0
- package/dist/components/barcode/barcode.d.cts +70 -0
- package/dist/components/barcode/barcode.d.ts +70 -0
- package/dist/components/barcode/barcode.js +94 -0
- package/dist/components/barcode/encode.cjs +86 -0
- package/dist/components/barcode/encode.d.cts +52 -0
- package/dist/components/barcode/encode.d.ts +52 -0
- package/dist/components/barcode/encode.js +85 -0
- package/dist/components/barcode/index.cjs +6 -0
- package/dist/components/barcode/index.d.cts +3 -0
- package/dist/components/barcode/index.d.ts +3 -0
- package/dist/components/barcode/index.js +3 -0
- package/dist/components/qrcode/encode.cjs +28 -0
- package/dist/components/qrcode/encode.d.cts +29 -0
- package/dist/components/qrcode/encode.d.ts +29 -0
- package/dist/components/qrcode/encode.js +28 -0
- package/dist/components/qrcode/index.cjs +6 -0
- package/dist/components/qrcode/index.d.cts +3 -0
- package/dist/components/qrcode/index.d.ts +3 -0
- package/dist/components/qrcode/index.js +3 -0
- package/dist/components/qrcode/qrcode.cjs +121 -0
- package/dist/components/qrcode/qrcode.d.cts +59 -0
- package/dist/components/qrcode/qrcode.d.ts +59 -0
- package/dist/components/qrcode/qrcode.js +120 -0
- package/dist/css/barcode.css +26 -0
- package/dist/css/qrcode.css +28 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/dist/save.cjs +120 -0
- package/dist/save.d.cts +38 -0
- package/dist/save.d.ts +38 -0
- package/dist/save.js +117 -0
- package/dist/styles.css +53 -0
- package/dist/utils/cx.cjs +6 -0
- package/dist/utils/cx.js +6 -0
- package/package.json +118 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_encode = require("./components/barcode/encode.cjs");
|
|
3
|
+
const require_barcode = require("./components/barcode/barcode.cjs");
|
|
4
|
+
const require_encode$1 = require("./components/qrcode/encode.cjs");
|
|
5
|
+
const require_qrcode = require("./components/qrcode/qrcode.cjs");
|
|
6
|
+
const require_save = require("./save.cjs");
|
|
7
|
+
exports.Barcode = require_barcode.Barcode;
|
|
8
|
+
exports.QRCode = require_qrcode.QRCode;
|
|
9
|
+
exports.QRCodeSwissCross = require_qrcode.QRCodeSwissCross;
|
|
10
|
+
exports.barcodeTypes = require_encode.barcodeTypes;
|
|
11
|
+
exports.codeToBlob = require_save.codeToBlob;
|
|
12
|
+
exports.codeToSvg = require_save.codeToSvg;
|
|
13
|
+
exports.encodeBarcode = require_encode.encodeBarcode;
|
|
14
|
+
exports.encodeQRCode = require_encode$1.encodeQRCode;
|
|
15
|
+
exports.saveCode = require_save.saveCode;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BarcodeEncodeOptions, BarcodeEncoding, BarcodePart, BarcodeType, barcodeTypes, encodeBarcode } from "./components/barcode/encode.cjs";
|
|
2
|
+
import { Barcode, BarcodeOwnProps, BarcodeProps } from "./components/barcode/barcode.cjs";
|
|
3
|
+
import "./components/barcode/index.cjs";
|
|
4
|
+
import { QRCodeEncodeOptions, QRCodeEncoding, QRCodeErrorCorrection, encodeQRCode } from "./components/qrcode/encode.cjs";
|
|
5
|
+
import { QRCode, QRCodeOwnProps, QRCodeProps, QRCodeSwissCross, QRCodeSwissCrossProps } from "./components/qrcode/qrcode.cjs";
|
|
6
|
+
import "./components/qrcode/index.cjs";
|
|
7
|
+
import { CodeFileOptions, SaveCodeOptions, codeToBlob, codeToSvg, saveCode } from "./save.cjs";
|
|
8
|
+
export { Barcode, type BarcodeEncodeOptions, type BarcodeEncoding, type BarcodeOwnProps, type BarcodePart, type BarcodeProps, type BarcodeType, CodeFileOptions, QRCode, type QRCodeEncodeOptions, type QRCodeEncoding, type QRCodeErrorCorrection, type QRCodeOwnProps, type QRCodeProps, QRCodeSwissCross, type QRCodeSwissCrossProps, SaveCodeOptions, barcodeTypes, codeToBlob, codeToSvg, encodeBarcode, encodeQRCode, saveCode };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BarcodeEncodeOptions, BarcodeEncoding, BarcodePart, BarcodeType, barcodeTypes, encodeBarcode } from "./components/barcode/encode.js";
|
|
2
|
+
import { Barcode, BarcodeOwnProps, BarcodeProps } from "./components/barcode/barcode.js";
|
|
3
|
+
import "./components/barcode/index.js";
|
|
4
|
+
import { QRCodeEncodeOptions, QRCodeEncoding, QRCodeErrorCorrection, encodeQRCode } from "./components/qrcode/encode.js";
|
|
5
|
+
import { QRCode, QRCodeOwnProps, QRCodeProps, QRCodeSwissCross, QRCodeSwissCrossProps } from "./components/qrcode/qrcode.js";
|
|
6
|
+
import "./components/qrcode/index.js";
|
|
7
|
+
import { CodeFileOptions, SaveCodeOptions, codeToBlob, codeToSvg, saveCode } from "./save.js";
|
|
8
|
+
export { Barcode, type BarcodeEncodeOptions, type BarcodeEncoding, type BarcodeOwnProps, type BarcodePart, type BarcodeProps, type BarcodeType, CodeFileOptions, QRCode, type QRCodeEncodeOptions, type QRCodeEncoding, type QRCodeErrorCorrection, type QRCodeOwnProps, type QRCodeProps, QRCodeSwissCross, type QRCodeSwissCrossProps, SaveCodeOptions, barcodeTypes, codeToBlob, codeToSvg, encodeBarcode, encodeQRCode, saveCode };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { barcodeTypes, encodeBarcode } from "./components/barcode/encode.js";
|
|
2
|
+
import { Barcode } from "./components/barcode/barcode.js";
|
|
3
|
+
import { encodeQRCode } from "./components/qrcode/encode.js";
|
|
4
|
+
import { QRCode, QRCodeSwissCross } from "./components/qrcode/qrcode.js";
|
|
5
|
+
import { codeToBlob, codeToSvg, saveCode } from "./save.js";
|
|
6
|
+
export { Barcode, QRCode, QRCodeSwissCross, barcodeTypes, codeToBlob, codeToSvg, encodeBarcode, encodeQRCode, saveCode };
|
package/dist/save.cjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/save.ts
|
|
3
|
+
const carried = [
|
|
4
|
+
"fill",
|
|
5
|
+
"stroke",
|
|
6
|
+
"stroke-width",
|
|
7
|
+
"stroke-dasharray",
|
|
8
|
+
"font-family",
|
|
9
|
+
"font-size",
|
|
10
|
+
"font-weight",
|
|
11
|
+
"direction"
|
|
12
|
+
];
|
|
13
|
+
function read(blob) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const reader = new FileReader();
|
|
16
|
+
reader.onload = () => resolve(String(reader.result));
|
|
17
|
+
reader.onerror = () => reject(reader.error);
|
|
18
|
+
reader.readAsDataURL(blob);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function embed(image) {
|
|
22
|
+
const address = image.getAttribute("href") ?? image.getAttribute("xlink:href") ?? "";
|
|
23
|
+
if (address === "" || address.startsWith("data:")) return;
|
|
24
|
+
try {
|
|
25
|
+
const answer = await fetch(new URL(address, document.baseURI));
|
|
26
|
+
if (!answer.ok) return;
|
|
27
|
+
image.setAttribute("href", await read(await answer.blob()));
|
|
28
|
+
image.removeAttribute("xlink:href");
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The text of an SVG file for a `Barcode` or a `QRCode` on the page, with
|
|
33
|
+
* its colors and its font written into it.
|
|
34
|
+
*/
|
|
35
|
+
function codeToSvg(code) {
|
|
36
|
+
return write(code, 1);
|
|
37
|
+
}
|
|
38
|
+
async function write(code, scale) {
|
|
39
|
+
const copy = code.cloneNode(true);
|
|
40
|
+
const drawn = [code, ...code.querySelectorAll("*")];
|
|
41
|
+
const copied = [copy, ...copy.querySelectorAll("*")];
|
|
42
|
+
for (const [index, element] of copied.entries()) {
|
|
43
|
+
const from = drawn[index];
|
|
44
|
+
if (!from) continue;
|
|
45
|
+
const style = getComputedStyle(from);
|
|
46
|
+
if (element !== copy) for (const property of carried) {
|
|
47
|
+
const value = style.getPropertyValue(property);
|
|
48
|
+
if (value !== "") element.setAttribute(property, value);
|
|
49
|
+
}
|
|
50
|
+
element.removeAttribute("class");
|
|
51
|
+
element.removeAttribute("style");
|
|
52
|
+
}
|
|
53
|
+
await Promise.all(Array.from(copy.querySelectorAll("image"), embed));
|
|
54
|
+
const box = code.viewBox.baseVal;
|
|
55
|
+
const width = Number(code.getAttribute("width") ?? box.width);
|
|
56
|
+
const height = Number(code.getAttribute("height") ?? box.height);
|
|
57
|
+
copy.setAttribute("width", String(width * scale));
|
|
58
|
+
copy.setAttribute("height", String(height * scale));
|
|
59
|
+
copy.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
60
|
+
copy.removeAttribute("role");
|
|
61
|
+
const name = code.getAttribute("aria-label");
|
|
62
|
+
copy.removeAttribute("aria-label");
|
|
63
|
+
copy.removeAttribute("aria-labelledby");
|
|
64
|
+
if (name) {
|
|
65
|
+
const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
|
|
66
|
+
title.textContent = name;
|
|
67
|
+
copy.prepend(title);
|
|
68
|
+
}
|
|
69
|
+
return new XMLSerializer().serializeToString(copy);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A `Barcode` or a `QRCode` on the page as a file's contents: an SVG, or
|
|
73
|
+
* a PNG at `scale` times the size.
|
|
74
|
+
*/
|
|
75
|
+
async function codeToBlob(code, { format = "svg", scale = 4 } = {}) {
|
|
76
|
+
const svg = new Blob([await write(code, format === "svg" ? 1 : scale)], { type: "image/svg+xml;charset=utf-8" });
|
|
77
|
+
if (format === "svg") return svg;
|
|
78
|
+
const address = URL.createObjectURL(svg);
|
|
79
|
+
try {
|
|
80
|
+
const image = new Image();
|
|
81
|
+
await new Promise((resolve, reject) => {
|
|
82
|
+
image.onload = () => resolve();
|
|
83
|
+
image.onerror = () => reject(/* @__PURE__ */ new Error("The code couldn't be drawn."));
|
|
84
|
+
image.src = address;
|
|
85
|
+
});
|
|
86
|
+
const canvas = document.createElement("canvas");
|
|
87
|
+
canvas.width = Math.round(image.width);
|
|
88
|
+
canvas.height = Math.round(image.height);
|
|
89
|
+
const context = canvas.getContext("2d");
|
|
90
|
+
if (!context) throw new Error("The browser gave no canvas to draw on.");
|
|
91
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
92
|
+
return await new Promise((resolve, reject) => {
|
|
93
|
+
canvas.toBlob((blob) => blob ? resolve(blob) : reject(/* @__PURE__ */ new Error("The code couldn't be made into a PNG.")), "image/png");
|
|
94
|
+
});
|
|
95
|
+
} finally {
|
|
96
|
+
URL.revokeObjectURL(address);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Saves a `Barcode` or a `QRCode` on the page as a file, the way a link
|
|
101
|
+
* with `download` does. Call it from a press of a button.
|
|
102
|
+
*/
|
|
103
|
+
async function saveCode(code, { name = "code", format = "svg", scale } = {}) {
|
|
104
|
+
const address = URL.createObjectURL(await codeToBlob(code, {
|
|
105
|
+
format,
|
|
106
|
+
scale
|
|
107
|
+
}));
|
|
108
|
+
const link = document.createElement("a");
|
|
109
|
+
link.href = address;
|
|
110
|
+
link.download = `${name}.${format}`;
|
|
111
|
+
link.hidden = true;
|
|
112
|
+
document.body.append(link);
|
|
113
|
+
link.click();
|
|
114
|
+
link.remove();
|
|
115
|
+
setTimeout(() => URL.revokeObjectURL(address), 1e3);
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
exports.codeToBlob = codeToBlob;
|
|
119
|
+
exports.codeToSvg = codeToSvg;
|
|
120
|
+
exports.saveCode = saveCode;
|
package/dist/save.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/save.d.ts
|
|
2
|
+
export interface CodeFileOptions {
|
|
3
|
+
/**
|
|
4
|
+
* `"svg"` stays sharp at any size and is the one to print from. `"png"`
|
|
5
|
+
* is for where an SVG isn't taken.
|
|
6
|
+
* @default "svg"
|
|
7
|
+
*/
|
|
8
|
+
format?: "svg" | "png";
|
|
9
|
+
/**
|
|
10
|
+
* How many pixels of a PNG there are to each pixel of the code on the
|
|
11
|
+
* page. A code that's printed wants more than one that's shown.
|
|
12
|
+
* @default 4
|
|
13
|
+
*/
|
|
14
|
+
scale?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface SaveCodeOptions extends CodeFileOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The file's name, without its ending.
|
|
19
|
+
* @default "code"
|
|
20
|
+
*/
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The text of an SVG file for a `Barcode` or a `QRCode` on the page, with
|
|
25
|
+
* its colors and its font written into it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function codeToSvg(code: SVGSVGElement): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* A `Barcode` or a `QRCode` on the page as a file's contents: an SVG, or
|
|
30
|
+
* a PNG at `scale` times the size.
|
|
31
|
+
*/
|
|
32
|
+
export declare function codeToBlob(code: SVGSVGElement, { format, scale }?: CodeFileOptions): Promise<Blob>;
|
|
33
|
+
/**
|
|
34
|
+
* Saves a `Barcode` or a `QRCode` on the page as a file, the way a link
|
|
35
|
+
* with `download` does. Call it from a press of a button.
|
|
36
|
+
*/
|
|
37
|
+
export declare function saveCode(code: SVGSVGElement, { name, format, scale }?: SaveCodeOptions): Promise<void>;
|
|
38
|
+
//#endregion
|
package/dist/save.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/save.d.ts
|
|
2
|
+
export interface CodeFileOptions {
|
|
3
|
+
/**
|
|
4
|
+
* `"svg"` stays sharp at any size and is the one to print from. `"png"`
|
|
5
|
+
* is for where an SVG isn't taken.
|
|
6
|
+
* @default "svg"
|
|
7
|
+
*/
|
|
8
|
+
format?: "svg" | "png";
|
|
9
|
+
/**
|
|
10
|
+
* How many pixels of a PNG there are to each pixel of the code on the
|
|
11
|
+
* page. A code that's printed wants more than one that's shown.
|
|
12
|
+
* @default 4
|
|
13
|
+
*/
|
|
14
|
+
scale?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface SaveCodeOptions extends CodeFileOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The file's name, without its ending.
|
|
19
|
+
* @default "code"
|
|
20
|
+
*/
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The text of an SVG file for a `Barcode` or a `QRCode` on the page, with
|
|
25
|
+
* its colors and its font written into it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function codeToSvg(code: SVGSVGElement): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* A `Barcode` or a `QRCode` on the page as a file's contents: an SVG, or
|
|
30
|
+
* a PNG at `scale` times the size.
|
|
31
|
+
*/
|
|
32
|
+
export declare function codeToBlob(code: SVGSVGElement, { format, scale }?: CodeFileOptions): Promise<Blob>;
|
|
33
|
+
/**
|
|
34
|
+
* Saves a `Barcode` or a `QRCode` on the page as a file, the way a link
|
|
35
|
+
* with `download` does. Call it from a press of a button.
|
|
36
|
+
*/
|
|
37
|
+
export declare function saveCode(code: SVGSVGElement, { name, format, scale }?: SaveCodeOptions): Promise<void>;
|
|
38
|
+
//#endregion
|
package/dist/save.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
//#region src/save.ts
|
|
2
|
+
const carried = [
|
|
3
|
+
"fill",
|
|
4
|
+
"stroke",
|
|
5
|
+
"stroke-width",
|
|
6
|
+
"stroke-dasharray",
|
|
7
|
+
"font-family",
|
|
8
|
+
"font-size",
|
|
9
|
+
"font-weight",
|
|
10
|
+
"direction"
|
|
11
|
+
];
|
|
12
|
+
function read(blob) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const reader = new FileReader();
|
|
15
|
+
reader.onload = () => resolve(String(reader.result));
|
|
16
|
+
reader.onerror = () => reject(reader.error);
|
|
17
|
+
reader.readAsDataURL(blob);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async function embed(image) {
|
|
21
|
+
const address = image.getAttribute("href") ?? image.getAttribute("xlink:href") ?? "";
|
|
22
|
+
if (address === "" || address.startsWith("data:")) return;
|
|
23
|
+
try {
|
|
24
|
+
const answer = await fetch(new URL(address, document.baseURI));
|
|
25
|
+
if (!answer.ok) return;
|
|
26
|
+
image.setAttribute("href", await read(await answer.blob()));
|
|
27
|
+
image.removeAttribute("xlink:href");
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The text of an SVG file for a `Barcode` or a `QRCode` on the page, with
|
|
32
|
+
* its colors and its font written into it.
|
|
33
|
+
*/
|
|
34
|
+
function codeToSvg(code) {
|
|
35
|
+
return write(code, 1);
|
|
36
|
+
}
|
|
37
|
+
async function write(code, scale) {
|
|
38
|
+
const copy = code.cloneNode(true);
|
|
39
|
+
const drawn = [code, ...code.querySelectorAll("*")];
|
|
40
|
+
const copied = [copy, ...copy.querySelectorAll("*")];
|
|
41
|
+
for (const [index, element] of copied.entries()) {
|
|
42
|
+
const from = drawn[index];
|
|
43
|
+
if (!from) continue;
|
|
44
|
+
const style = getComputedStyle(from);
|
|
45
|
+
if (element !== copy) for (const property of carried) {
|
|
46
|
+
const value = style.getPropertyValue(property);
|
|
47
|
+
if (value !== "") element.setAttribute(property, value);
|
|
48
|
+
}
|
|
49
|
+
element.removeAttribute("class");
|
|
50
|
+
element.removeAttribute("style");
|
|
51
|
+
}
|
|
52
|
+
await Promise.all(Array.from(copy.querySelectorAll("image"), embed));
|
|
53
|
+
const box = code.viewBox.baseVal;
|
|
54
|
+
const width = Number(code.getAttribute("width") ?? box.width);
|
|
55
|
+
const height = Number(code.getAttribute("height") ?? box.height);
|
|
56
|
+
copy.setAttribute("width", String(width * scale));
|
|
57
|
+
copy.setAttribute("height", String(height * scale));
|
|
58
|
+
copy.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
59
|
+
copy.removeAttribute("role");
|
|
60
|
+
const name = code.getAttribute("aria-label");
|
|
61
|
+
copy.removeAttribute("aria-label");
|
|
62
|
+
copy.removeAttribute("aria-labelledby");
|
|
63
|
+
if (name) {
|
|
64
|
+
const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
|
|
65
|
+
title.textContent = name;
|
|
66
|
+
copy.prepend(title);
|
|
67
|
+
}
|
|
68
|
+
return new XMLSerializer().serializeToString(copy);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A `Barcode` or a `QRCode` on the page as a file's contents: an SVG, or
|
|
72
|
+
* a PNG at `scale` times the size.
|
|
73
|
+
*/
|
|
74
|
+
async function codeToBlob(code, { format = "svg", scale = 4 } = {}) {
|
|
75
|
+
const svg = new Blob([await write(code, format === "svg" ? 1 : scale)], { type: "image/svg+xml;charset=utf-8" });
|
|
76
|
+
if (format === "svg") return svg;
|
|
77
|
+
const address = URL.createObjectURL(svg);
|
|
78
|
+
try {
|
|
79
|
+
const image = new Image();
|
|
80
|
+
await new Promise((resolve, reject) => {
|
|
81
|
+
image.onload = () => resolve();
|
|
82
|
+
image.onerror = () => reject(/* @__PURE__ */ new Error("The code couldn't be drawn."));
|
|
83
|
+
image.src = address;
|
|
84
|
+
});
|
|
85
|
+
const canvas = document.createElement("canvas");
|
|
86
|
+
canvas.width = Math.round(image.width);
|
|
87
|
+
canvas.height = Math.round(image.height);
|
|
88
|
+
const context = canvas.getContext("2d");
|
|
89
|
+
if (!context) throw new Error("The browser gave no canvas to draw on.");
|
|
90
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
91
|
+
return await new Promise((resolve, reject) => {
|
|
92
|
+
canvas.toBlob((blob) => blob ? resolve(blob) : reject(/* @__PURE__ */ new Error("The code couldn't be made into a PNG.")), "image/png");
|
|
93
|
+
});
|
|
94
|
+
} finally {
|
|
95
|
+
URL.revokeObjectURL(address);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Saves a `Barcode` or a `QRCode` on the page as a file, the way a link
|
|
100
|
+
* with `download` does. Call it from a press of a button.
|
|
101
|
+
*/
|
|
102
|
+
async function saveCode(code, { name = "code", format = "svg", scale } = {}) {
|
|
103
|
+
const address = URL.createObjectURL(await codeToBlob(code, {
|
|
104
|
+
format,
|
|
105
|
+
scale
|
|
106
|
+
}));
|
|
107
|
+
const link = document.createElement("a");
|
|
108
|
+
link.href = address;
|
|
109
|
+
link.download = `${name}.${format}`;
|
|
110
|
+
link.hidden = true;
|
|
111
|
+
document.body.append(link);
|
|
112
|
+
link.click();
|
|
113
|
+
link.remove();
|
|
114
|
+
setTimeout(() => URL.revokeObjectURL(address), 1e3);
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { codeToBlob, codeToSvg, saveCode };
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@layer tokens, base, components;
|
|
2
|
+
@layer components {
|
|
3
|
+
.nuv-barcode {
|
|
4
|
+
display: block;
|
|
5
|
+
max-inline-size: 100%;
|
|
6
|
+
block-size: auto;
|
|
7
|
+
forced-color-adjust: none;
|
|
8
|
+
}
|
|
9
|
+
.nuv-barcode__ground {
|
|
10
|
+
fill: var(--nuv-barcode-bg, var(--color-white));
|
|
11
|
+
}
|
|
12
|
+
.nuv-barcode__bars {
|
|
13
|
+
fill: var(--nuv-barcode-fg, var(--color-black));
|
|
14
|
+
}
|
|
15
|
+
.nuv-barcode__text {
|
|
16
|
+
direction: ltr;
|
|
17
|
+
fill: var(--nuv-barcode-fg, var(--color-black));
|
|
18
|
+
font-family: var(--nuv-barcode-font, var(--font-mono));
|
|
19
|
+
}
|
|
20
|
+
.nuv-barcode__mark {
|
|
21
|
+
fill: none;
|
|
22
|
+
stroke: var(--nuv-barcode-invalid, var(--color-danger));
|
|
23
|
+
stroke-width: 1;
|
|
24
|
+
stroke-dasharray: 4 3;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
@layer components {
|
|
28
|
+
.nuv-qrcode {
|
|
29
|
+
display: block;
|
|
30
|
+
max-inline-size: 100%;
|
|
31
|
+
block-size: auto;
|
|
32
|
+
forced-color-adjust: none;
|
|
33
|
+
}
|
|
34
|
+
.nuv-qrcode__ground {
|
|
35
|
+
fill: var(--nuv-qrcode-bg, var(--color-white));
|
|
36
|
+
}
|
|
37
|
+
.nuv-qrcode__squares {
|
|
38
|
+
fill: var(--nuv-qrcode-fg, var(--color-black));
|
|
39
|
+
}
|
|
40
|
+
.nuv-qrcode__overlay {
|
|
41
|
+
overflow: hidden;
|
|
42
|
+
}
|
|
43
|
+
.nuv-qrcode__cross-ground {
|
|
44
|
+
fill: var(--color-black);
|
|
45
|
+
}
|
|
46
|
+
.nuv-qrcode__cross-arms {
|
|
47
|
+
fill: var(--color-white);
|
|
48
|
+
}
|
|
49
|
+
.nuv-qrcode__mark {
|
|
50
|
+
fill: none;
|
|
51
|
+
stroke: var(--nuv-qrcode-invalid, var(--color-danger));
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/utils/cx.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,121 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuvui/barcodes",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Barcodes and QR codes for @nuvui/react, drawn as SVG.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Nuvraxis",
|
|
7
|
+
"homepage": "https://nuvui.nuvraxis.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Nuvraxis/nuvui.git",
|
|
11
|
+
"directory": "packages/barcodes"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Nuvraxis/nuvui/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": [
|
|
21
|
+
"**/*.css"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"main": "./dist/index.cjs",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.cts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
37
|
+
"default": "./dist/index.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./barcode": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/components/barcode/index.d.ts",
|
|
43
|
+
"default": "./dist/components/barcode/index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/components/barcode/index.d.cts",
|
|
47
|
+
"default": "./dist/components/barcode/index.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./qrcode": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/components/qrcode/index.d.ts",
|
|
53
|
+
"default": "./dist/components/qrcode/index.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/components/qrcode/index.d.cts",
|
|
57
|
+
"default": "./dist/components/qrcode/index.cjs"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./save": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/save.d.ts",
|
|
63
|
+
"default": "./dist/save.js"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/save.d.cts",
|
|
67
|
+
"default": "./dist/save.cjs"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./styles.css": "./dist/styles.css",
|
|
71
|
+
"./css/*.css": "./dist/css/*.css",
|
|
72
|
+
"./package.json": "./package.json"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@nuvui/react": "^0.4.0",
|
|
76
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
77
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
81
|
+
"@nuvui/react": "0.4.0",
|
|
82
|
+
"@nuvui/tooling": "0.0.0",
|
|
83
|
+
"@nuvui/typescript-config": "0.0.0",
|
|
84
|
+
"@size-limit/preset-small-lib": "14.1.0",
|
|
85
|
+
"@types/node": "^24.0.0",
|
|
86
|
+
"@types/react": "^19.3.0",
|
|
87
|
+
"@types/react-dom": "^19.3.0",
|
|
88
|
+
"@vitest/browser-playwright": "^5.0.3",
|
|
89
|
+
"@zxing/library": "^0.23.0",
|
|
90
|
+
"axe-core": "^4.13.0",
|
|
91
|
+
"playwright": "1.63.0",
|
|
92
|
+
"publint": "^0.3.25",
|
|
93
|
+
"react": "^19.3.0",
|
|
94
|
+
"react-dom": "^19.3.0",
|
|
95
|
+
"sass-embedded": "^1.105.1",
|
|
96
|
+
"size-limit": "14.1.0",
|
|
97
|
+
"stylelint": "^17.16.0",
|
|
98
|
+
"tsdown": "0.23.0",
|
|
99
|
+
"typescript": "^7.0.2",
|
|
100
|
+
"vitest": "^5.0.3",
|
|
101
|
+
"vitest-browser-react": "^2.3.0"
|
|
102
|
+
},
|
|
103
|
+
"publishConfig": {
|
|
104
|
+
"access": "public",
|
|
105
|
+
"provenance": true
|
|
106
|
+
},
|
|
107
|
+
"dependencies": {
|
|
108
|
+
"jsbarcode": "^3.12.3",
|
|
109
|
+
"uqr": "~0.1.3"
|
|
110
|
+
},
|
|
111
|
+
"scripts": {
|
|
112
|
+
"build": "tsdown && node scripts/check-dist.mjs",
|
|
113
|
+
"dev": "tsdown --watch src",
|
|
114
|
+
"lint": "stylelint \"src/**/*.scss\"",
|
|
115
|
+
"typecheck": "tsc --noEmit",
|
|
116
|
+
"test": "vitest run",
|
|
117
|
+
"test:watch": "vitest",
|
|
118
|
+
"check:package": "publint && pnpm pack --out node_modules/.cache/attw/package.tgz && attw node_modules/.cache/attw/package.tgz",
|
|
119
|
+
"size": "size-limit"
|
|
120
|
+
}
|
|
6
121
|
}
|