@levischuck/receiptline 0.0.1
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/LICENSE.txt +201 -0
- package/README.md +278 -0
- package/dist/barcode.d.ts +71 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1003 -0
- package/dist/parse.d.ts +73 -0
- package/dist/targets/base.d.ts +168 -0
- package/dist/targets/index.d.ts +7 -0
- package/dist/targets/svg.d.ts +52 -0
- package/dist/types.d.ts +65 -0
- package/package.json +52 -0
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Barcode, ParsedPrinter, Printer, QRCode } from './types.ts';
|
|
2
|
+
type ParsedProperty = {
|
|
3
|
+
align?: string;
|
|
4
|
+
border?: string;
|
|
5
|
+
code?: string;
|
|
6
|
+
image?: string;
|
|
7
|
+
option?: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
width?: string;
|
|
10
|
+
command?: string;
|
|
11
|
+
comment?: string;
|
|
12
|
+
[key: string]: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
type ParsedColumn = {
|
|
15
|
+
align: number;
|
|
16
|
+
wrap: boolean;
|
|
17
|
+
border: number;
|
|
18
|
+
width: number;
|
|
19
|
+
alignment: number;
|
|
20
|
+
text?: string[];
|
|
21
|
+
property?: ParsedProperty;
|
|
22
|
+
code?: Barcode | QRCode;
|
|
23
|
+
image?: string;
|
|
24
|
+
command?: string;
|
|
25
|
+
comment?: string;
|
|
26
|
+
hr?: '-' | '=';
|
|
27
|
+
vr?: '+' | '-';
|
|
28
|
+
error?: string;
|
|
29
|
+
};
|
|
30
|
+
export type ParseState = {
|
|
31
|
+
wrap: boolean;
|
|
32
|
+
border: number;
|
|
33
|
+
width: number[];
|
|
34
|
+
align: number;
|
|
35
|
+
option: {
|
|
36
|
+
type: 'upc' | 'ean' | 'jan' | 'code39' | 'itf' | 'codabar' | 'nw7' | 'code93' | 'code128' | 'qrcode';
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
hri: boolean;
|
|
40
|
+
cell: number;
|
|
41
|
+
level: 'l' | 'm' | 'q' | 'h';
|
|
42
|
+
quietZone: boolean;
|
|
43
|
+
};
|
|
44
|
+
line: 'waiting' | 'ready' | 'running' | 'horizontal';
|
|
45
|
+
rules: {
|
|
46
|
+
left: number;
|
|
47
|
+
width: number;
|
|
48
|
+
right: number;
|
|
49
|
+
widths: number[];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Validate printer configuration.
|
|
54
|
+
* @param printer printer configuration
|
|
55
|
+
* @returns validated printer configuration
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseOption(printer?: Partial<Printer>): ParsedPrinter;
|
|
58
|
+
/**
|
|
59
|
+
* Parse lines.
|
|
60
|
+
* @param columns line text without line breaks
|
|
61
|
+
* @param state state variables
|
|
62
|
+
* @returns parsed line object
|
|
63
|
+
*/
|
|
64
|
+
export declare function parseLine(columns: string, state: ParseState): ParsedColumn[];
|
|
65
|
+
/**
|
|
66
|
+
* Generate commands from line objects.
|
|
67
|
+
* @param line parsed line object
|
|
68
|
+
* @param printer printer configuration
|
|
69
|
+
* @param state state variables
|
|
70
|
+
* @returns printer command fragment or SVG image fragment
|
|
71
|
+
*/
|
|
72
|
+
export declare function createLine(line: ParsedColumn[], printer: ParsedPrinter, state: ParseState): string;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Encoding, ParsedPrinter, QRCode, Barcode, BaseTargetInterface } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Base target class for ReceiptLine commands.
|
|
4
|
+
*/
|
|
5
|
+
export declare class BaseTarget implements BaseTargetInterface {
|
|
6
|
+
/**
|
|
7
|
+
* Measure text width.
|
|
8
|
+
* @param {string} text string to measure
|
|
9
|
+
* @param {string} encoding codepage
|
|
10
|
+
* @returns {number} string width
|
|
11
|
+
*/
|
|
12
|
+
measureText(text: string, encoding: Encoding): number;
|
|
13
|
+
/**
|
|
14
|
+
* Create character array from string (supporting Thai combining characters).
|
|
15
|
+
* @param {string} text string
|
|
16
|
+
* @param {string} encoding codepage
|
|
17
|
+
* @returns {string[]} array instance
|
|
18
|
+
*/
|
|
19
|
+
arrayFrom(text: string, encoding: Encoding): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Start printing.
|
|
22
|
+
* @param {object} printer printer configuration
|
|
23
|
+
* @returns {string} commands
|
|
24
|
+
*/
|
|
25
|
+
open(printer: ParsedPrinter): string;
|
|
26
|
+
/**
|
|
27
|
+
* Finish printing.
|
|
28
|
+
* @returns {string} commands
|
|
29
|
+
*/
|
|
30
|
+
close(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Set print area.
|
|
33
|
+
* @param {number} left left margin (unit: characters)
|
|
34
|
+
* @param {number} width print area (unit: characters)
|
|
35
|
+
* @param {number} right right margin (unit: characters)
|
|
36
|
+
* @returns {string} commands
|
|
37
|
+
*/
|
|
38
|
+
area(left: number, width: number, right: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* Set line alignment.
|
|
41
|
+
* @param {number} align line alignment (0: left, 1: center, 2: right)
|
|
42
|
+
* @returns {string} commands
|
|
43
|
+
*/
|
|
44
|
+
align(align: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* Set absolute print position.
|
|
47
|
+
* @param {number} position absolute position (unit: characters)
|
|
48
|
+
* @returns {string} commands
|
|
49
|
+
*/
|
|
50
|
+
absolute(position: number): string;
|
|
51
|
+
/**
|
|
52
|
+
* Set relative print position.
|
|
53
|
+
* @param {number} position relative position (unit: characters)
|
|
54
|
+
* @returns {string} commands
|
|
55
|
+
*/
|
|
56
|
+
relative(position: number): string;
|
|
57
|
+
/**
|
|
58
|
+
* Print horizontal rule.
|
|
59
|
+
* @param {number} width line width (unit: characters)
|
|
60
|
+
* @returns {string} commands
|
|
61
|
+
*/
|
|
62
|
+
hr(width: number): string;
|
|
63
|
+
/**
|
|
64
|
+
* Print vertical rules.
|
|
65
|
+
* @param {number[]} widths vertical line spacing
|
|
66
|
+
* @param {number} height text height (1-6)
|
|
67
|
+
* @returns {string} commands
|
|
68
|
+
*/
|
|
69
|
+
vr(widths: number[], height: number): string;
|
|
70
|
+
/**
|
|
71
|
+
* Start rules.
|
|
72
|
+
* @param {number[]} widths vertical line spacing
|
|
73
|
+
* @returns {string} commands
|
|
74
|
+
*/
|
|
75
|
+
vrstart(widths: number[]): string;
|
|
76
|
+
/**
|
|
77
|
+
* Stop rules.
|
|
78
|
+
* @param {number[]} widths vertical line spacing
|
|
79
|
+
* @returns {string} commands
|
|
80
|
+
*/
|
|
81
|
+
vrstop(widths: number[]): string;
|
|
82
|
+
/**
|
|
83
|
+
* Print vertical and horizontal rules.
|
|
84
|
+
* @param {number[]} widths1 vertical line spacing (stop)
|
|
85
|
+
* @param {number[]} widths2 vertical line spacing (start)
|
|
86
|
+
* @param {number} dl difference in left position
|
|
87
|
+
* @param {number} dr difference in right position
|
|
88
|
+
* @returns {string} commands
|
|
89
|
+
*/
|
|
90
|
+
vrhr(widths1: number[], widths2: number[], dl: number, dr: number): string;
|
|
91
|
+
/**
|
|
92
|
+
* Set line spacing and feed new line.
|
|
93
|
+
* @param {boolean} vr whether vertical ruled lines are printed
|
|
94
|
+
* @returns {string} commands
|
|
95
|
+
*/
|
|
96
|
+
vrlf(vr: boolean): string;
|
|
97
|
+
/**
|
|
98
|
+
* Cut paper.
|
|
99
|
+
* @returns {string} commands
|
|
100
|
+
*/
|
|
101
|
+
cut(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Underline text.
|
|
104
|
+
* @returns {string} commands
|
|
105
|
+
*/
|
|
106
|
+
ul(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Emphasize text.
|
|
109
|
+
* @returns {string} commands
|
|
110
|
+
*/
|
|
111
|
+
em(): string;
|
|
112
|
+
/**
|
|
113
|
+
* Invert text.
|
|
114
|
+
* @returns {string} commands
|
|
115
|
+
*/
|
|
116
|
+
iv(): string;
|
|
117
|
+
/**
|
|
118
|
+
* Scale up text.
|
|
119
|
+
* @param {number} wh number of special character '^' (1-7)
|
|
120
|
+
* @returns {string} commands
|
|
121
|
+
*/
|
|
122
|
+
wh(wh: number): string;
|
|
123
|
+
/**
|
|
124
|
+
* Cancel text decoration.
|
|
125
|
+
* @returns {string} commands
|
|
126
|
+
*/
|
|
127
|
+
normal(): string;
|
|
128
|
+
/**
|
|
129
|
+
* Print text.
|
|
130
|
+
* @param {string} text string to print
|
|
131
|
+
* @param {string} encoding codepage
|
|
132
|
+
* @returns {string} commands
|
|
133
|
+
*/
|
|
134
|
+
text(text: string, encoding: Encoding): string;
|
|
135
|
+
/**
|
|
136
|
+
* Feed new line.
|
|
137
|
+
* @returns {string} commands
|
|
138
|
+
*/
|
|
139
|
+
lf(): string;
|
|
140
|
+
/**
|
|
141
|
+
* Insert commands.
|
|
142
|
+
* @param {string} command commands to insert
|
|
143
|
+
* @returns {string} commands
|
|
144
|
+
*/
|
|
145
|
+
command(command: string): string;
|
|
146
|
+
/**
|
|
147
|
+
* Print image.
|
|
148
|
+
* @param {string} image image data (base64 png format)
|
|
149
|
+
* @returns {string} commands
|
|
150
|
+
*/
|
|
151
|
+
image(image: string): string;
|
|
152
|
+
/**
|
|
153
|
+
* Print QR Code.
|
|
154
|
+
* @param {object} symbol QR Code information (data, type, cell, level)
|
|
155
|
+
* @param {string} encoding codepage
|
|
156
|
+
* @returns {string} commands
|
|
157
|
+
*/
|
|
158
|
+
qrcode(symbol: QRCode, encoding: Encoding): string;
|
|
159
|
+
/**
|
|
160
|
+
* Print barcode.
|
|
161
|
+
* @param {object} symbol barcode information (data, type, width, height, hri)
|
|
162
|
+
* @param {string} encoding codepage
|
|
163
|
+
* @returns {string} commands
|
|
164
|
+
*/
|
|
165
|
+
barcode(symbol: Barcode, encoding: Encoding): string;
|
|
166
|
+
calculatedWidth(): number;
|
|
167
|
+
calculatedHeight(): number;
|
|
168
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BaseTarget } from './base.ts';
|
|
2
|
+
import { Encoding, ParsedPrinter, QRCode, Barcode } from '../types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* SVG target class for ReceiptLine commands.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SvgTarget extends BaseTarget {
|
|
7
|
+
charWidth: number;
|
|
8
|
+
receiptId: string;
|
|
9
|
+
svgWidth: number;
|
|
10
|
+
svgHeight: number;
|
|
11
|
+
svgContent: string;
|
|
12
|
+
lineMargin: number;
|
|
13
|
+
lineAlign: number;
|
|
14
|
+
lineWidth: number;
|
|
15
|
+
lineHeight: number;
|
|
16
|
+
textElement: string;
|
|
17
|
+
textAttributes: Record<string, string>;
|
|
18
|
+
textPosition: number;
|
|
19
|
+
textScale: number;
|
|
20
|
+
textEncoding: Encoding;
|
|
21
|
+
feedMinimum: number;
|
|
22
|
+
spacing: boolean;
|
|
23
|
+
defaultFont: string;
|
|
24
|
+
fontSize: number;
|
|
25
|
+
open(printer: ParsedPrinter): string;
|
|
26
|
+
setDefaultFont(font: string): string;
|
|
27
|
+
close(): string;
|
|
28
|
+
area(left: number, width: number, right: number): string;
|
|
29
|
+
align(align: number): string;
|
|
30
|
+
absolute(position: number): string;
|
|
31
|
+
relative(position: number): string;
|
|
32
|
+
hr(width: number): string;
|
|
33
|
+
vr(widths: number[], height: number): string;
|
|
34
|
+
vrstart(widths: number[]): string;
|
|
35
|
+
vrstop(widths: number[]): string;
|
|
36
|
+
vrhr(widths1: number[], widths2: number[], dl: number, dr: number): string;
|
|
37
|
+
vrlf(vr: boolean): string;
|
|
38
|
+
cut(): string;
|
|
39
|
+
ul(): string;
|
|
40
|
+
em(): string;
|
|
41
|
+
iv(): string;
|
|
42
|
+
wh(wh: number): string;
|
|
43
|
+
normal(): string;
|
|
44
|
+
text(text: string, encoding: Encoding): string;
|
|
45
|
+
lf(): string;
|
|
46
|
+
command(command: string): string;
|
|
47
|
+
image(image: string): string;
|
|
48
|
+
qrcode(symbol: QRCode, _encoding: Encoding): string;
|
|
49
|
+
barcode(symbol: Barcode, encoding: Encoding): string;
|
|
50
|
+
calculatedWidth(): number;
|
|
51
|
+
calculatedHeight(): number;
|
|
52
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type Encoding = 'cp437' | 'cp852' | 'cp858' | 'cp860' | 'cp863' | 'cp865' | 'cp866' | 'cp1252' | 'cp932' | 'cp936' | 'cp949' | 'cp950' | 'multilingual' | 'shiftjis' | 'gb18030' | 'ksc5601' | 'big5' | 'tis620';
|
|
2
|
+
export type ParsedPrinter = {
|
|
3
|
+
cpl: number;
|
|
4
|
+
charWidth: number;
|
|
5
|
+
encoding: Encoding;
|
|
6
|
+
spacing: boolean;
|
|
7
|
+
margin: number;
|
|
8
|
+
marginRight: number;
|
|
9
|
+
target: BaseTargetInterface;
|
|
10
|
+
};
|
|
11
|
+
export interface BaseTargetInterface {
|
|
12
|
+
measureText(text: string, encoding: Encoding): number;
|
|
13
|
+
arrayFrom(text: string, encoding: Encoding): string[];
|
|
14
|
+
open(printer: ParsedPrinter): string;
|
|
15
|
+
close(): string;
|
|
16
|
+
area(left: number, width: number, right: number): string;
|
|
17
|
+
align(align: number): string;
|
|
18
|
+
absolute(position: number): string;
|
|
19
|
+
relative(position: number): string;
|
|
20
|
+
hr(width: number): string;
|
|
21
|
+
vr(widths: number[], height: number): string;
|
|
22
|
+
vrstart(widths: number[]): string;
|
|
23
|
+
vrstop(widths: number[]): string;
|
|
24
|
+
vrhr(widths1: number[], widths2: number[], dl: number, dr: number): string;
|
|
25
|
+
vrlf(vr: boolean): string;
|
|
26
|
+
cut(): string;
|
|
27
|
+
ul(): string;
|
|
28
|
+
em(): string;
|
|
29
|
+
iv(): string;
|
|
30
|
+
wh(wh: number): string;
|
|
31
|
+
normal(): string;
|
|
32
|
+
text(text: string, encoding: Encoding): string;
|
|
33
|
+
lf(): string;
|
|
34
|
+
command(command: string): string;
|
|
35
|
+
image(image: string): string;
|
|
36
|
+
qrcode(symbol: QRCode, encoding: Encoding): string;
|
|
37
|
+
barcode(symbol: Barcode, encoding: Encoding): string;
|
|
38
|
+
calculatedWidth(): number;
|
|
39
|
+
calculatedHeight(): number;
|
|
40
|
+
}
|
|
41
|
+
export type Printer = {
|
|
42
|
+
cpl?: number;
|
|
43
|
+
charWidth?: number;
|
|
44
|
+
encoding?: Encoding;
|
|
45
|
+
spacing?: boolean;
|
|
46
|
+
target?: string | BaseTargetInterface;
|
|
47
|
+
margin?: number;
|
|
48
|
+
marginRight?: number;
|
|
49
|
+
[propName: string]: any;
|
|
50
|
+
};
|
|
51
|
+
export type QRCode = {
|
|
52
|
+
data: string;
|
|
53
|
+
type: 'qrcode';
|
|
54
|
+
cell: number;
|
|
55
|
+
level: 'l' | 'm' | 'q' | 'h';
|
|
56
|
+
quietZone?: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type Barcode = {
|
|
59
|
+
data: string;
|
|
60
|
+
type: 'upc' | 'ean' | 'jan' | 'code39' | 'itf' | 'codabar' | 'nw7' | 'code93' | 'code128';
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
hri: boolean;
|
|
64
|
+
quietZone?: boolean;
|
|
65
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@levischuck/receiptline",
|
|
3
|
+
"module": "./dist/index.js",
|
|
4
|
+
"description": "Markdown for receipts. Printable digital receipts. Generate receipt printer commands and images.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Open Foodservice System Consortium, Levi Schuck",
|
|
8
|
+
"version": "0.0.1",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/bun": "latest",
|
|
11
|
+
"unplugin-dts": "^1.0.0-beta.6",
|
|
12
|
+
"vite": "^7.3.1"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"typescript": "^5"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@levischuck/tiny-qr": "^0.0.5",
|
|
19
|
+
"@levischuck/tiny-qr-svg": "^0.0.5"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"kiosk",
|
|
23
|
+
"receipt",
|
|
24
|
+
"invoice",
|
|
25
|
+
"kitchen",
|
|
26
|
+
"ticket",
|
|
27
|
+
"svg",
|
|
28
|
+
"markdown"
|
|
29
|
+
],
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"LICENSE.txt",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/levischuck/receiptline.git"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "vite build",
|
|
41
|
+
"type-check": "tsc --noEmit"
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"import": "./dist/index.js",
|
|
46
|
+
"types": "./dist/index.d.ts"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|