qr-code-styling-node 1.7.0 → 1.9.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,8 @@
1
+ import { RequiredOptions } from "../core/QROptions";
2
+ import { CornerDotType, CornerSquareType, DotType } from "../types";
3
+ /** True when alignment patterns must be drawn as plain squares for this dot type to scan. */
4
+ export declare const needsSolidAlignment: (type: DotType) => boolean;
5
+ export default function getCornerTypes(options: RequiredOptions): {
6
+ square?: CornerSquareType;
7
+ dot?: CornerDotType;
8
+ };
@@ -0,0 +1,43 @@
1
+ import { RequiredOptions } from "../core/QROptions";
2
+ export interface FrameLayout {
3
+ width: number;
4
+ height: number;
5
+ /** Where the QR code goes, as a square. */
6
+ qr: {
7
+ x: number;
8
+ y: number;
9
+ size: number;
10
+ };
11
+ frame?: {
12
+ thickness: number;
13
+ radius: number;
14
+ color: string;
15
+ };
16
+ label?: {
17
+ text: string;
18
+ band: {
19
+ x: number;
20
+ y: number;
21
+ width: number;
22
+ height: number;
23
+ };
24
+ color: string;
25
+ font: string;
26
+ fontSize: number;
27
+ fontFamily: string;
28
+ fontWeight: string;
29
+ };
30
+ background: string;
31
+ }
32
+ export declare const hasFrame: (options: RequiredOptions) => boolean;
33
+ export default function getFrameLayout(options: RequiredOptions): FrameLayout;
34
+ /** Options for drawing the bare QR code inside the frame. */
35
+ export declare const innerOptions: (options: RequiredOptions, size: number) => RequiredOptions;
36
+ /** Area behind the logo: the logo box including its margin, with rounded corners. */
37
+ export declare const getLogoPlate: (options: RequiredOptions, dx: number, dy: number, width: number, height: number) => {
38
+ x: number;
39
+ y: number;
40
+ width: number;
41
+ height: number;
42
+ radius: number;
43
+ };
@@ -10,6 +10,9 @@ export declare class VirtualSVGElement {
10
10
  parentNode: VirtualSVGElement | null;
11
11
  childNodes: VirtualSVGElement[];
12
12
  private _attributes;
13
+ private _text;
14
+ get textContent(): string;
15
+ set textContent(value: string);
13
16
  constructor(tagName: string);
14
17
  get nodeName(): string;
15
18
  setAttribute(name: string, value: string): void;
@@ -1,9 +1,9 @@
1
1
  export interface UnknownObject {
2
2
  [key: string]: any;
3
3
  }
4
- export type DotType = "dots" | "rounded" | "classy" | "classy-rounded" | "square" | "extra-rounded";
5
- export type CornerDotType = "dot" | "square";
6
- export type CornerSquareType = "dot" | "square" | "extra-rounded";
4
+ export type DotType = "dots" | "rounded" | "classy" | "classy-rounded" | "square" | "extra-rounded" | "diamond" | "small-square" | "vertical-lines" | "horizontal-lines";
5
+ export type CornerDotType = "dot" | "square" | "rounded";
6
+ export type CornerSquareType = "dot" | "square" | "extra-rounded" | "rounded";
7
7
  export type Extension = "svg" | "png" | "jpeg" | "webp";
8
8
  export type GradientType = "radial" | "linear";
9
9
  export type DrawType = "canvas" | "svg";
@@ -81,9 +81,67 @@ export interface ResvgConstructor {
81
81
  }): {
82
82
  render(): {
83
83
  asPng(): Uint8Array;
84
+ pixels: Uint8Array;
85
+ width: number;
86
+ height: number;
84
87
  };
85
88
  };
86
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
+ }
125
+ export interface FrameOptions {
126
+ /** Frame and label band color. Default "#000". */
127
+ color?: string;
128
+ /** Border thickness in px. Default 4% of the size. */
129
+ width?: number;
130
+ /** Outer corner radius in px. Default 0. */
131
+ radius?: number;
132
+ /** Space between the frame and the QR code in px. Default 4% of the size. */
133
+ padding?: number;
134
+ }
135
+ export interface LabelOptions {
136
+ text: string;
137
+ position?: "top" | "bottom";
138
+ /** Default white on a frame, otherwise the dots color. */
139
+ color?: string;
140
+ /** In px. Default 7% of the size. */
141
+ fontSize?: number;
142
+ fontFamily?: string;
143
+ fontWeight?: string | number;
144
+ }
87
145
  export type Options = {
88
146
  type?: DrawType;
89
147
  width?: number;
@@ -98,6 +156,12 @@ export type Options = {
98
156
  * node-canvas: the QR code is drawn as SVG and rasterized by resvg.
99
157
  */
100
158
  resvg?: ResvgConstructor;
159
+ /** Blend a picture into the QR code. Needs a canvas (browser, or nodeCanvas on Node). */
160
+ art?: ArtOptions;
161
+ /** A border around the code. The code shrinks to fit inside width x height. */
162
+ frameOptions?: FrameOptions;
163
+ /** A line of text above or below the code, such as "Scan to order". */
164
+ labelOptions?: LabelOptions;
101
165
  qrOptions?: {
102
166
  typeNumber?: TypeNumber;
103
167
  mode?: Mode;
@@ -109,6 +173,10 @@ export type Options = {
109
173
  imageSize?: number;
110
174
  crossOrigin?: string;
111
175
  margin?: number;
176
+ /** Plate drawn behind the logo, e.g. "#ffffff". */
177
+ backgroundColor?: string;
178
+ /** Corner radius of the plate, 0 (square) to 0.5 (round). Default 0.2. */
179
+ backgroundRadius?: number;
112
180
  };
113
181
  dotsOptions?: {
114
182
  type?: DotType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qr-code-styling-node",
3
- "version": "1.7.0",
3
+ "version": "1.9.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",
@@ -70,7 +70,9 @@
70
70
  "test:watch": "vitest",
71
71
  "start": "webpack serve --open --config webpack.config.dev-server.js",
72
72
  "clean": "node -e \"require('fs').rmSync('lib',{recursive:true,force:true})\"",
73
- "bench": "npm run build && node scripts/bench.mjs"
73
+ "bench": "npm run build && node scripts/bench.mjs",
74
+ "art-examples": "npm run build && node scripts/art-examples.mjs",
75
+ "style-examples": "npm run build && node scripts/style-examples.mjs"
74
76
  },
75
77
  "dependencies": {
76
78
  "qrcode-generator": "^1.4.3"
@@ -88,6 +90,7 @@
88
90
  "globals": "^15.15.0",
89
91
  "html-webpack-plugin": "^5.6.8",
90
92
  "jsdom": "^26.1.0",
93
+ "jsqr": "^1.4.0",
91
94
  "prettier": "^3.10.1",
92
95
  "qr-code-styling-node-v1-5": "npm:qr-code-styling-node@1.5.0",
93
96
  "ts-loader": "^9.6.2",