1 |
|
2 |
|
3 | import * as stream from "stream";
|
4 |
|
5 | export type QRCodeErrorCorrectionLevel = "low" | "medium" | "quartile" | "high" | "L" | "M" | "Q" | "H";
|
6 | export type QRCodeMaskPattern = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
7 | export type QRCodeToSJISFunc = (codePoint: string) => number;
|
8 |
|
9 | export interface QRCodeOptions {
|
10 | |
11 |
|
12 |
|
13 | version?: number | undefined;
|
14 | |
15 |
|
16 |
|
17 |
|
18 | errorCorrectionLevel?: QRCodeErrorCorrectionLevel | undefined;
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 | maskPattern?: QRCodeMaskPattern | undefined;
|
25 | |
26 |
|
27 |
|
28 |
|
29 | toSJISFunc?: QRCodeToSJISFunc | undefined;
|
30 | }
|
31 |
|
32 | export type QRCodeDataURLType = "image/png" | "image/jpeg" | "image/webp";
|
33 | export type QRCodeToDataURLOptions = QRCodeToDataURLOptionsJpegWebp | QRCodeToDataURLOptionsOther;
|
34 | export interface QRCodeToDataURLOptionsJpegWebp extends QRCodeRenderersOptions {
|
35 | |
36 |
|
37 |
|
38 |
|
39 | type: "image/jpeg" | "image/webp";
|
40 | rendererOpts?:
|
41 | | {
|
42 | |
43 |
|
44 |
|
45 |
|
46 | quality?: number | undefined;
|
47 | }
|
48 | | undefined;
|
49 | }
|
50 | export interface QRCodeToDataURLOptionsOther extends QRCodeRenderersOptions {
|
51 | |
52 |
|
53 |
|
54 |
|
55 | type?: Exclude<QRCodeDataURLType, "image/jpeg" | "image/webp"> | undefined;
|
56 | }
|
57 |
|
58 | export type QRCodeStringType = "utf8" | "svg" | "terminal";
|
59 | export type QRCodeToStringOptions = QRCodeToStringOptionsTerminal | QRCodeToStringOptionsOther;
|
60 | export interface QRCodeToStringOptionsTerminal extends QRCodeRenderersOptions {
|
61 | |
62 |
|
63 |
|
64 |
|
65 | type: "terminal";
|
66 | |
67 |
|
68 |
|
69 |
|
70 | small?: boolean | undefined;
|
71 | }
|
72 | export interface QRCodeToStringOptionsOther extends QRCodeRenderersOptions {
|
73 | |
74 |
|
75 |
|
76 |
|
77 | type?: Exclude<QRCodeStringType, "terminal"> | undefined;
|
78 | }
|
79 |
|
80 | export type QRCodeFileType = "png" | "svg" | "utf8";
|
81 | export type QRCodeToFileOptions = QRCodeToFileOptionsPng | QRCodeToFileOptionsOther;
|
82 | export interface QRCodeToFileOptionsPng extends QRCodeRenderersOptions {
|
83 | |
84 |
|
85 |
|
86 |
|
87 | type?: "png" | undefined;
|
88 | rendererOpts?:
|
89 | | {
|
90 | |
91 |
|
92 |
|
93 |
|
94 | deflateLevel?: number | undefined;
|
95 | |
96 |
|
97 |
|
98 |
|
99 | deflateStrategy?: number | undefined;
|
100 | }
|
101 | | undefined;
|
102 | }
|
103 | export interface QRCodeToFileOptionsOther extends QRCodeRenderersOptions {
|
104 | |
105 |
|
106 |
|
107 |
|
108 | type: Exclude<QRCodeFileType, "png"> | undefined;
|
109 | }
|
110 |
|
111 | export type QRCodeFileStreamType = "png";
|
112 | export interface QRCodeToFileStreamOptions extends QRCodeRenderersOptions {
|
113 | |
114 |
|
115 |
|
116 | type?: QRCodeFileStreamType | undefined;
|
117 | rendererOpts?:
|
118 | | {
|
119 | |
120 |
|
121 |
|
122 |
|
123 | deflateLevel?: number | undefined;
|
124 | |
125 |
|
126 |
|
127 |
|
128 | deflateStrategy?: number | undefined;
|
129 | }
|
130 | | undefined;
|
131 | }
|
132 |
|
133 | export type QRCodeBufferType = "png";
|
134 | export interface QRCodeToBufferOptions extends QRCodeRenderersOptions {
|
135 | |
136 |
|
137 |
|
138 | type?: QRCodeBufferType | undefined;
|
139 | rendererOpts?:
|
140 | | {
|
141 | |
142 |
|
143 |
|
144 |
|
145 | deflateLevel?: number | undefined;
|
146 | |
147 |
|
148 |
|
149 |
|
150 | deflateStrategy?: number | undefined;
|
151 | }
|
152 | | undefined;
|
153 | }
|
154 |
|
155 | export interface QRCodeRenderersOptions extends QRCodeOptions {
|
156 | |
157 |
|
158 |
|
159 |
|
160 | margin?: number | undefined;
|
161 | |
162 |
|
163 |
|
164 |
|
165 | scale?: number | undefined;
|
166 | |
167 |
|
168 |
|
169 |
|
170 |
|
171 | width?: number | undefined;
|
172 | color?:
|
173 | | {
|
174 | |
175 |
|
176 |
|
177 |
|
178 |
|
179 | dark?: string | undefined;
|
180 | |
181 |
|
182 |
|
183 |
|
184 | light?: string | undefined;
|
185 | }
|
186 | | undefined;
|
187 | }
|
188 |
|
189 | export type QRCodeSegmentMode = "alphanumeric" | "numeric" | "byte" | "kanji";
|
190 | export type QRCodeSegment =
|
191 | | QRCodeNumericSegment
|
192 | | QRCodeAlphanumericSegment
|
193 | | QRCodeByteSegment
|
194 | | QRCodeKanjiSegment
|
195 | | {
|
196 | mode?: never;
|
197 | data: string | Buffer | Uint8ClampedArray | Uint8Array;
|
198 | };
|
199 |
|
200 | export interface QRCodeNumericSegment {
|
201 | mode: "numeric";
|
202 | data: string | number;
|
203 | }
|
204 |
|
205 | export interface QRCodeAlphanumericSegment {
|
206 | mode: "alphanumeric";
|
207 | data: string;
|
208 | }
|
209 |
|
210 | export interface QRCodeByteSegment {
|
211 | mode: "byte";
|
212 | data: Buffer | Uint8ClampedArray | Uint8Array;
|
213 | }
|
214 |
|
215 | export interface QRCodeKanjiSegment {
|
216 | mode: "kanji";
|
217 | data: string;
|
218 | }
|
219 |
|
220 | export interface QRCode {
|
221 | |
222 |
|
223 |
|
224 | modules: BitMatrix;
|
225 | |
226 |
|
227 |
|
228 | version: number;
|
229 | |
230 |
|
231 |
|
232 | errorCorrectionLevel: ErrorCorrectionLevel;
|
233 | |
234 |
|
235 |
|
236 | maskPattern: QRCodeMaskPattern | undefined;
|
237 | |
238 |
|
239 |
|
240 | segments: GeneratedQRCodeSegment[];
|
241 | }
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | export interface BitMatrix {
|
247 | |
248 |
|
249 |
|
250 | size: number;
|
251 | data: Uint8Array;
|
252 | reservedBit: Uint8Array;
|
253 | |
254 |
|
255 |
|
256 |
|
257 | set(row: number, col: number, value: number, reserved: boolean): void;
|
258 | |
259 |
|
260 |
|
261 | get(row: number, col: number): number;
|
262 | |
263 |
|
264 |
|
265 | xor(row: number, col: number, value: number): void;
|
266 | |
267 |
|
268 |
|
269 | isReserved(row: number, col: number): number;
|
270 | }
|
271 |
|
272 | export interface ErrorCorrectionLevel {
|
273 | bit: 0 | 1 | 2 | 3;
|
274 | }
|
275 |
|
276 | export type ModeId = "Numeric" | "Alphanumeric" | "Byte" | "Kanji";
|
277 | export interface Mode<TModeId extends ModeId = ModeId> {
|
278 | id: TModeId;
|
279 | bit: number;
|
280 | ccBits: readonly number[];
|
281 | }
|
282 |
|
283 | export type GeneratedQRCodeSegment = NumericData | AlphanumericData | ByteData | KanjiData;
|
284 |
|
285 | export interface DataSegment {
|
286 | getLength(): number;
|
287 | getBitsLength(): number;
|
288 | }
|
289 |
|
290 | export interface NumericData extends DataSegment {
|
291 | mode: Mode<"Numeric">;
|
292 | data: string;
|
293 | }
|
294 |
|
295 | export interface AlphanumericData extends DataSegment {
|
296 | mode: Mode<"Alphanumeric">;
|
297 | data: string;
|
298 | }
|
299 |
|
300 | export interface ByteData extends DataSegment {
|
301 | mode: Mode<"Byte">;
|
302 | data: Uint8Array;
|
303 | }
|
304 |
|
305 | export interface KanjiData extends DataSegment {
|
306 | mode: Mode<"Kanji">;
|
307 | data: string;
|
308 | }
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 | export function create(text: string | QRCodeSegment[], options?: QRCodeOptions): QRCode;
|
315 |
|
316 |
|
317 |
|
318 |
|
319 | export function toCanvas(
|
320 | canvasElement: HTMLCanvasElement,
|
321 | text: string | QRCodeSegment[],
|
322 | callback: (error: Error | null | undefined) => void,
|
323 | ): void;
|
324 |
|
325 |
|
326 |
|
327 | export function toCanvas(
|
328 | canvasElement: HTMLCanvasElement,
|
329 | text: string | QRCodeSegment[],
|
330 | options?: QRCodeRenderersOptions,
|
331 | ): Promise<void>;
|
332 |
|
333 |
|
334 |
|
335 | export function toCanvas(
|
336 | canvasElement: HTMLCanvasElement,
|
337 | text: string | QRCodeSegment[],
|
338 | options: QRCodeRenderersOptions,
|
339 | callback: (error: Error | null | undefined) => void,
|
340 | ): void;
|
341 |
|
342 |
|
343 |
|
344 | export function toCanvas(
|
345 | text: string | QRCodeSegment[],
|
346 | callback: (error: Error | null | undefined, canvas: HTMLCanvasElement) => void,
|
347 | ): void;
|
348 |
|
349 |
|
350 |
|
351 | export function toCanvas(text: string | QRCodeSegment[], options?: QRCodeRenderersOptions): Promise<HTMLCanvasElement>;
|
352 |
|
353 |
|
354 |
|
355 | export function toCanvas(
|
356 | text: string | QRCodeSegment[],
|
357 | options: QRCodeRenderersOptions,
|
358 | callback: (error: Error | null | undefined, canvas: HTMLCanvasElement) => void,
|
359 | ): void;
|
360 |
|
361 |
|
362 |
|
363 | export function toCanvas(
|
364 | canvas: any,
|
365 | text: string | QRCodeSegment[],
|
366 | callback: (error: Error | null | undefined) => void,
|
367 | ): void;
|
368 |
|
369 |
|
370 |
|
371 | export function toCanvas(canvas: any, text: string | QRCodeSegment[], options?: QRCodeRenderersOptions): Promise<void>;
|
372 |
|
373 |
|
374 |
|
375 | export function toCanvas(
|
376 | canvas: any,
|
377 | text: string | QRCodeSegment[],
|
378 | options: QRCodeRenderersOptions,
|
379 | callback: (error: Error | null | undefined) => void,
|
380 | ): void;
|
381 |
|
382 |
|
383 |
|
384 |
|
385 | export function toDataURL(
|
386 | canvasElement: HTMLCanvasElement,
|
387 | text: string | QRCodeSegment[],
|
388 | callback: (error: Error | null | undefined, url: string) => void,
|
389 | ): void;
|
390 |
|
391 |
|
392 |
|
393 | export function toDataURL(
|
394 | canvasElement: HTMLCanvasElement,
|
395 | text: string | QRCodeSegment[],
|
396 | options?: QRCodeToDataURLOptions,
|
397 | ): Promise<string>;
|
398 |
|
399 |
|
400 |
|
401 | export function toDataURL(
|
402 | canvasElement: HTMLCanvasElement,
|
403 | text: string | QRCodeSegment[],
|
404 | options: QRCodeToDataURLOptions,
|
405 | callback: (error: Error | null | undefined, url: string) => void,
|
406 | ): void;
|
407 |
|
408 |
|
409 |
|
410 |
|
411 | export function toDataURL(
|
412 | text: string | QRCodeSegment[],
|
413 | callback: (error: Error | null | undefined, url: string) => void,
|
414 | ): void;
|
415 |
|
416 |
|
417 |
|
418 | export function toDataURL(text: string | QRCodeSegment[], options?: QRCodeToDataURLOptions): Promise<string>;
|
419 |
|
420 |
|
421 |
|
422 | export function toDataURL(
|
423 | text: string | QRCodeSegment[],
|
424 | options: QRCodeToDataURLOptions,
|
425 | callback: (error: Error | null | undefined, url: string) => void,
|
426 | ): void;
|
427 |
|
428 |
|
429 |
|
430 |
|
431 | export function toString(
|
432 | text: string | QRCodeSegment[],
|
433 | callback: (error: Error | null | undefined, string: string) => void,
|
434 | ): void;
|
435 |
|
436 |
|
437 |
|
438 | export function toString(text: string | QRCodeSegment[], options?: QRCodeToStringOptions): Promise<string>;
|
439 |
|
440 |
|
441 |
|
442 | export function toString(
|
443 | text: string | QRCodeSegment[],
|
444 | options: QRCodeToStringOptions,
|
445 | callback: (error: Error | null | undefined, string: string) => void,
|
446 | ): void;
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 | export function toFile(
|
453 | path: string,
|
454 | text: string | QRCodeSegment[],
|
455 | callback: (error: Error | null | undefined) => void,
|
456 | ): void;
|
457 |
|
458 |
|
459 |
|
460 |
|
461 | export function toFile(path: string, text: string | QRCodeSegment[], options?: QRCodeToFileOptions): Promise<void>;
|
462 |
|
463 |
|
464 |
|
465 |
|
466 | export function toFile(
|
467 | path: string,
|
468 | text: string | QRCodeSegment[],
|
469 | options: QRCodeToFileOptions,
|
470 | callback: (error: Error | null | undefined) => void,
|
471 | ): void;
|
472 |
|
473 |
|
474 |
|
475 |
|
476 | export function toFileStream(
|
477 | stream: stream.Writable,
|
478 | text: string | QRCodeSegment[],
|
479 | callback: (error: Error | null | undefined) => void,
|
480 | ): void;
|
481 |
|
482 |
|
483 |
|
484 | export function toFileStream(
|
485 | stream: stream.Writable,
|
486 | text: string | QRCodeSegment[],
|
487 | options?: QRCodeToFileStreamOptions,
|
488 | ): Promise<void>;
|
489 |
|
490 |
|
491 |
|
492 | export function toFileStream(
|
493 | stream: stream.Writable,
|
494 | text: string | QRCodeSegment[],
|
495 | options: QRCodeToFileStreamOptions,
|
496 | callback: (error: Error | null | undefined) => void,
|
497 | ): void;
|
498 |
|
499 |
|
500 |
|
501 |
|
502 | export function toBuffer(
|
503 | text: string | QRCodeSegment[],
|
504 | callback: (error: Error | null | undefined, buffer: Buffer) => void,
|
505 | ): void;
|
506 |
|
507 |
|
508 |
|
509 | export function toBuffer(text: string | QRCodeSegment[], options?: QRCodeToBufferOptions): Promise<Buffer>;
|
510 |
|
511 |
|
512 |
|
513 | export function toBuffer(
|
514 | text: string | QRCodeSegment[],
|
515 | options: QRCodeToBufferOptions,
|
516 | callback: (error: Error | null | undefined, buffer: Buffer) => void,
|
517 | ): void;
|