qr-code-styling-node 1.6.0 → 1.8.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.
@@ -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 {};
@@ -69,6 +69,59 @@ 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
+ pixels: Uint8Array;
85
+ width: number;
86
+ height: number;
87
+ };
88
+ };
89
+ }
90
+ export type ArtMode = "halftone" | "colorize";
91
+ export interface ArtOptions {
92
+ /** The picture to blend into the QR code (URL or data URL). */
93
+ image: string;
94
+ /**
95
+ * "halftone": the picture is redrawn as fine black/white (or colored) pixels, with the QR modules in the middle.
96
+ * "colorize": the dots keep their shape and are painted with a darkened copy of the picture.
97
+ */
98
+ mode?: ArtMode;
99
+ /** halftone only: use the picture's own colors instead of dotsOptions/backgroundOptions colors. */
100
+ colored?: boolean;
101
+ /** colorize only: also show a light copy of the picture behind the dots. Default true. */
102
+ background?: boolean;
103
+ /** 0 to 1. Higher keeps dark and light further apart: easier to scan, less of the picture. Default 0.5 (halftone), 0.7 (colorize). */
104
+ contrast?: number;
105
+ crossOrigin?: string;
106
+ }
107
+ /** Same signature as jsQR: (rgba, width, height) => { data } | null. */
108
+ export type QRDecoder = (data: Uint8ClampedArray, width: number, height: number, options?: Record<string, unknown>) => {
109
+ data: string;
110
+ } | null;
111
+ export interface VerifyOptions {
112
+ /** A QR decoder, for example `jsQR` from the "jsqr" package. */
113
+ decoder: QRDecoder;
114
+ /** For QR art: raise art.contrast step by step until the code scans. Default false. */
115
+ adjust?: boolean;
116
+ }
117
+ export interface VerifyResult {
118
+ readable: boolean;
119
+ /** Text the decoder read, if any. */
120
+ decoded?: string;
121
+ /** Final art.contrast when art is used. */
122
+ contrast?: number;
123
+ attempts: number;
124
+ }
72
125
  export type Options = {
73
126
  type?: DrawType;
74
127
  width?: number;
@@ -78,6 +131,13 @@ export type Options = {
78
131
  image?: string;
79
132
  nodeCanvas?: Canvas;
80
133
  jsdom?: typeof JSDom;
134
+ /**
135
+ * The `Resvg` class from `@resvg/resvg-js`. Lets `getRawData("png")` work on a server without
136
+ * node-canvas: the QR code is drawn as SVG and rasterized by resvg.
137
+ */
138
+ resvg?: ResvgConstructor;
139
+ /** Blend a picture into the QR code. Needs a canvas (browser, or nodeCanvas on Node). */
140
+ art?: ArtOptions;
81
141
  qrOptions?: {
82
142
  typeNumber?: TypeNumber;
83
143
  mode?: Mode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qr-code-styling-node",
3
- "version": "1.6.0",
3
+ "version": "1.8.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,16 @@
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",
74
+ "art-examples": "npm run build && node scripts/art-examples.mjs"
73
75
  },
74
76
  "dependencies": {
75
77
  "qrcode-generator": "^1.4.3"
76
78
  },
77
79
  "devDependencies": {
78
80
  "@eslint/js": "^9.39.5",
81
+ "@resvg/resvg-js": "^2.6.2",
79
82
  "@types/node": "^22.20.5",
80
83
  "@vitest/coverage-v8": "^2.1.9",
81
84
  "canvas": "^3.2.3",
@@ -86,6 +89,7 @@
86
89
  "globals": "^15.15.0",
87
90
  "html-webpack-plugin": "^5.6.8",
88
91
  "jsdom": "^26.1.0",
92
+ "jsqr": "^1.4.0",
89
93
  "prettier": "^3.10.1",
90
94
  "qr-code-styling-node-v1-5": "npm:qr-code-styling-node@1.5.0",
91
95
  "ts-loader": "^9.6.2",