@naturalcycles/js-lib 15.77.0 → 15.79.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/dist/qr/qr.d.ts +104 -0
- package/dist/qr/qr.js +945 -0
- package/package.json +2 -1
- package/src/object/keySortedMap.ts +1 -1
- package/src/object/lazyKeySortedMap.ts +1 -1
- package/src/qr/qr.ts +1087 -0
package/dist/qr/qr.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/// <reference lib="dom" preserve="true" />
|
|
2
|
+
/**
|
|
3
|
+
* Error correction level, ordered by recovery capacity (and overhead):
|
|
4
|
+
* L ~7%, M ~15%, Q ~25%, H ~30%.
|
|
5
|
+
*/
|
|
6
|
+
export type QrErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
|
|
7
|
+
/**
|
|
8
|
+
* Encoding mode for the payload.
|
|
9
|
+
* - `numeric`: digits only (most compact)
|
|
10
|
+
* - `alphanumeric`: 0-9 A-Z and ` $%*+-./:` (uppercase only)
|
|
11
|
+
* - `byte`: any string, encoded as UTF-8
|
|
12
|
+
*
|
|
13
|
+
* When omitted, the smallest applicable mode is auto-detected.
|
|
14
|
+
*/
|
|
15
|
+
export type QrMode = 'numeric' | 'alphanumeric' | 'byte';
|
|
16
|
+
export interface QrCodeOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Error correction level. Default: `M`.
|
|
19
|
+
*/
|
|
20
|
+
ecl?: QrErrorCorrectionLevel;
|
|
21
|
+
/**
|
|
22
|
+
* QR version 1..40 (matrix grows by 4 modules per step: v1=21x21, v40=177x177).
|
|
23
|
+
* Default: `0` = auto-select the smallest version that fits the payload.
|
|
24
|
+
*/
|
|
25
|
+
typeNumber?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Force an encoding mode. Default: auto-detect (`numeric` < `alphanumeric` < `byte`).
|
|
28
|
+
* Ignored when the content is a `Uint8Array` (always `byte`).
|
|
29
|
+
*/
|
|
30
|
+
mode?: QrMode;
|
|
31
|
+
}
|
|
32
|
+
export interface QrSvgOptions {
|
|
33
|
+
/** Pixels per module (the rendered `width`/`height` = `(size + border*2) * scale`). Default `4`. */
|
|
34
|
+
scale?: number;
|
|
35
|
+
/** Quiet-zone width in modules. The spec recommends `4`. Default `4`. */
|
|
36
|
+
border?: number;
|
|
37
|
+
/** Color of dark modules. Default `#000000`. */
|
|
38
|
+
dark?: string;
|
|
39
|
+
/** Color of light modules / background. Default `#ffffff`. */
|
|
40
|
+
light?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface QrAsciiOptions {
|
|
43
|
+
/** Quiet-zone width in modules. Default `2`. */
|
|
44
|
+
border?: number;
|
|
45
|
+
/** Swap dark/light glyphs (useful on dark terminal backgrounds). Default `false`. */
|
|
46
|
+
invert?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface QrCanvasOptions {
|
|
49
|
+
/** Pixels per module. Default `4`. */
|
|
50
|
+
scale?: number;
|
|
51
|
+
/** Quiet-zone width in modules. Default `4`. */
|
|
52
|
+
border?: number;
|
|
53
|
+
/** Color of dark modules. Default `#000000`. */
|
|
54
|
+
dark?: string;
|
|
55
|
+
/** Color of light modules. Default `#ffffff`. */
|
|
56
|
+
light?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a QR code from a string or raw bytes.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* createQrCode('https://example.com').toDataUrl()
|
|
63
|
+
* createQrCode('HELLO', { ecl: 'H' }).toSvg({ scale: 8 })
|
|
64
|
+
*/
|
|
65
|
+
export declare function createQrCode(content: string | Uint8Array, opt?: QrCodeOptions): QrCode;
|
|
66
|
+
/**
|
|
67
|
+
* An immutable QR code: a square matrix of dark/light modules, plus renderers.
|
|
68
|
+
*/
|
|
69
|
+
export declare class QrCode {
|
|
70
|
+
/** Width/height of the matrix in modules (`typeNumber * 4 + 17`). */
|
|
71
|
+
readonly size: number;
|
|
72
|
+
/** `modules[row][col]` - `true` = dark. */
|
|
73
|
+
readonly modules: readonly boolean[][];
|
|
74
|
+
/** Error correction level used. */
|
|
75
|
+
readonly ecl: QrErrorCorrectionLevel;
|
|
76
|
+
constructor(
|
|
77
|
+
/** Width/height of the matrix in modules (`typeNumber * 4 + 17`). */
|
|
78
|
+
size: number,
|
|
79
|
+
/** `modules[row][col]` - `true` = dark. */
|
|
80
|
+
modules: readonly boolean[][],
|
|
81
|
+
/** Error correction level used. */
|
|
82
|
+
ecl: QrErrorCorrectionLevel);
|
|
83
|
+
/** Whether the module at `[row, col]` is dark. */
|
|
84
|
+
isDark(row: number, col: number): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Render as a standalone SVG document string.
|
|
87
|
+
*/
|
|
88
|
+
toSvg(opt?: QrSvgOptions): string;
|
|
89
|
+
/**
|
|
90
|
+
* Render as an `data:image/svg+xml` URL, ready for `<img src>` or CSS `background`.
|
|
91
|
+
*/
|
|
92
|
+
toDataUrl(opt?: QrSvgOptions): string;
|
|
93
|
+
/**
|
|
94
|
+
* Render as ASCII art using block characters - handy for terminals and logs.
|
|
95
|
+
* Each module is 2 chars wide so the output keeps a square aspect ratio.
|
|
96
|
+
*/
|
|
97
|
+
toAscii(opt?: QrAsciiOptions): string;
|
|
98
|
+
/** Same as {@link toAscii} with defaults. */
|
|
99
|
+
toString(): string;
|
|
100
|
+
/**
|
|
101
|
+
* Paint the QR code onto a 2d canvas context (browser).
|
|
102
|
+
*/
|
|
103
|
+
renderToCanvas(ctx: CanvasRenderingContext2D, opt?: QrCanvasOptions): void;
|
|
104
|
+
}
|