-
Notifications
You must be signed in to change notification settings - Fork 7
/
writerOptions.ts
89 lines (85 loc) · 2 KB
/
writerOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { ZXingModule } from "../core.js";
import type { WriteInputBarcodeFormat } from "./barcodeFormat.js";
import { type CharacterSet, characterSetToZXingEnum } from "./characterSet.js";
import type { WriteInputEccLevel } from "./eccLevel.js";
import type { ZXingEnum } from "./enum.js";
/**
* @internal
*/
export interface ZXingWriterOptions {
/**
* Width of the barcode.
*
* @defaultValue `200`
*/
width: number;
/**
* Height of the barcode.
*
* @defaultValue `200`
*/
height: number;
format: string;
characterSet: ZXingEnum;
eccLevel: number;
/**
* The minimum number of quiet zone pixels.
*
* @defaultValue `10`
*/
margin: number;
}
/**
* Writer options for writing barcodes.
*/
export interface WriterOptions
extends Partial<
Omit<ZXingWriterOptions, "format" | "characterSet" | "eccLevel">
> {
/**
* The format of the barcode to write.
*
* Supported values are:
* `"Aztec"`, `"Codabar"`, `"Code128"`, `"Code39"`, `"Code93"`,
* `"DataMatrix"`, `"EAN-13"`, `"EAN-8"`, `"ITF"`,
* `"PDF417"`, `"QRCode"`, `"UPC-A"`, `"UPC-E"`
*
* @defaultValue `"QRCode"`
*/
format?: WriteInputBarcodeFormat;
/**
* Character set to use for encoding the text.
* Used for Aztec, PDF417, and QRCode only.
*
* @defaultValue `"UTF8"`
*/
characterSet?: CharacterSet;
/**
* Error correction level of the symbol.
* Used for Aztec, PDF417, and QRCode only.
* `-1` means auto.
*
* @defaultValue `-1`
*/
eccLevel?: WriteInputEccLevel;
}
export const defaultWriterOptions: Required<WriterOptions> = {
width: 200,
height: 200,
format: "QRCode",
characterSet: "UTF8",
eccLevel: -1,
margin: 10,
};
export function writerOptionsToZXingWriterOptions<T extends "writer" | "full">(
zxingModule: ZXingModule<T>,
writerOptions: Required<WriterOptions>,
): ZXingWriterOptions {
return {
...writerOptions,
characterSet: characterSetToZXingEnum(
zxingModule,
writerOptions.characterSet,
),
};
}