qr-code-styling-node 1.6.0 → 1.7.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 +44 -5
- package/lib/core/QRCodeStyling.d.ts +14 -0
- package/lib/core/QRSVG.d.ts +3 -0
- package/lib/qr-code-styling.common.js +1 -1
- package/lib/qr-code-styling.common.js.map +1 -1
- package/lib/qr-code-styling.js +1 -1
- package/lib/qr-code-styling.js.map +1 -1
- package/lib/qr-code-styling.mjs +321 -4
- package/lib/qr-code-styling.mjs.map +4 -4
- package/lib/tools/imageSize.d.ts +17 -0
- package/lib/tools/svgDom.d.ts +37 -0
- package/lib/types/index.d.ts +20 -0
- package/package.json +4 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads an image's intrinsic size from its bytes, without a canvas or DOM.
|
|
3
|
+
* Supports PNG, JPEG, GIF, WebP and SVG. Used by the SVG renderer outside the browser.
|
|
4
|
+
*/
|
|
5
|
+
export interface ImageData {
|
|
6
|
+
bytes: Uint8Array;
|
|
7
|
+
mimeType: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ImageSize {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const encodeBase64: (bytes: Uint8Array) => string;
|
|
14
|
+
/** Loads image bytes from a data URL or an http(s) URL (using the global fetch). */
|
|
15
|
+
export declare const loadImageData: (source: string) => Promise<ImageData>;
|
|
16
|
+
export declare const toDataUrl: ({ bytes, mimeType }: ImageData) => string;
|
|
17
|
+
export declare const getImageSize: ({ bytes, mimeType }: ImageData) => ImageSize;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tiny DOM subset used to build SVG output where no browser DOM exists (Node.js, Deno, Bun,
|
|
3
|
+
* edge runtimes, workers). It implements only what the SVG renderer calls, and its serializer
|
|
4
|
+
* produces the same markup as a browser / jsdom XMLSerializer, so output is byte-identical
|
|
5
|
+
* to the jsdom path.
|
|
6
|
+
*/
|
|
7
|
+
export declare class VirtualSVGElement {
|
|
8
|
+
readonly namespaceURI = "http://www.w3.org/2000/svg";
|
|
9
|
+
readonly tagName: string;
|
|
10
|
+
parentNode: VirtualSVGElement | null;
|
|
11
|
+
childNodes: VirtualSVGElement[];
|
|
12
|
+
private _attributes;
|
|
13
|
+
constructor(tagName: string);
|
|
14
|
+
get nodeName(): string;
|
|
15
|
+
setAttribute(name: string, value: string): void;
|
|
16
|
+
getAttribute(name: string): string | null;
|
|
17
|
+
removeAttribute(name: string): void;
|
|
18
|
+
appendChild<T extends VirtualSVGElement>(child: T): T;
|
|
19
|
+
removeChild<T extends VirtualSVGElement>(child: T): T;
|
|
20
|
+
replaceChild<T extends VirtualSVGElement>(newChild: VirtualSVGElement, oldChild: T): T;
|
|
21
|
+
cloneNode(deep?: boolean): VirtualSVGElement;
|
|
22
|
+
serialize(isRoot?: boolean): string;
|
|
23
|
+
}
|
|
24
|
+
export declare class VirtualXMLSerializer {
|
|
25
|
+
serializeToString(node: VirtualSVGElement): string;
|
|
26
|
+
}
|
|
27
|
+
declare class VirtualDocument {
|
|
28
|
+
createElementNS(_namespace: string, tagName: string): VirtualSVGElement;
|
|
29
|
+
}
|
|
30
|
+
/** Window-like object accepted wherever the SVG renderer expects a DOM window. */
|
|
31
|
+
export declare const createVirtualWindow: () => {
|
|
32
|
+
document: VirtualDocument;
|
|
33
|
+
XMLSerializer: typeof VirtualXMLSerializer;
|
|
34
|
+
isVirtual: true;
|
|
35
|
+
};
|
|
36
|
+
export declare const hasBrowserDom: () => boolean;
|
|
37
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -69,6 +69,21 @@ export interface QRCode {
|
|
|
69
69
|
createASCII(cellSize?: number, margin?: number): string;
|
|
70
70
|
renderTo2dContext(context: CanvasRenderingContext2D, cellSize?: number): void;
|
|
71
71
|
}
|
|
72
|
+
export interface ResvgConstructor {
|
|
73
|
+
new (svg: string | Uint8Array, options?: {
|
|
74
|
+
fitTo?: {
|
|
75
|
+
mode: "original";
|
|
76
|
+
} | {
|
|
77
|
+
mode: "width";
|
|
78
|
+
value: number;
|
|
79
|
+
};
|
|
80
|
+
background?: string;
|
|
81
|
+
}): {
|
|
82
|
+
render(): {
|
|
83
|
+
asPng(): Uint8Array;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|
|
72
87
|
export type Options = {
|
|
73
88
|
type?: DrawType;
|
|
74
89
|
width?: number;
|
|
@@ -78,6 +93,11 @@ export type Options = {
|
|
|
78
93
|
image?: string;
|
|
79
94
|
nodeCanvas?: Canvas;
|
|
80
95
|
jsdom?: typeof JSDom;
|
|
96
|
+
/**
|
|
97
|
+
* The `Resvg` class from `@resvg/resvg-js`. Lets `getRawData("png")` work on a server without
|
|
98
|
+
* node-canvas: the QR code is drawn as SVG and rasterized by resvg.
|
|
99
|
+
*/
|
|
100
|
+
resvg?: ResvgConstructor;
|
|
81
101
|
qrOptions?: {
|
|
82
102
|
typeNumber?: TypeNumber;
|
|
83
103
|
mode?: Mode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qr-code-styling-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Style your QR codes: dots, corners, gradients and a logo. Works in the browser and on Node.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"qr",
|
|
@@ -69,13 +69,15 @@
|
|
|
69
69
|
"test": "vitest run",
|
|
70
70
|
"test:watch": "vitest",
|
|
71
71
|
"start": "webpack serve --open --config webpack.config.dev-server.js",
|
|
72
|
-
"clean": "node -e \"require('fs').rmSync('lib',{recursive:true,force:true})\""
|
|
72
|
+
"clean": "node -e \"require('fs').rmSync('lib',{recursive:true,force:true})\"",
|
|
73
|
+
"bench": "npm run build && node scripts/bench.mjs"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
76
|
"qrcode-generator": "^1.4.3"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
79
|
"@eslint/js": "^9.39.5",
|
|
80
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
79
81
|
"@types/node": "^22.20.5",
|
|
80
82
|
"@vitest/coverage-v8": "^2.1.9",
|
|
81
83
|
"canvas": "^3.2.3",
|