jc-printer-sdk-ts 0.1.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/README.md +86 -0
- package/dist/builder.d.ts +60 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +411 -0
- package/dist/builder.js.map +1 -0
- package/dist/client.d.ts +85 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +352 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +186 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +179 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/transport.d.ts +132 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +334 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +310 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
- package/src/builder.ts +562 -0
- package/src/client.ts +588 -0
- package/src/constants.ts +210 -0
- package/src/index.ts +5 -0
- package/src/transport.ts +526 -0
- package/src/types.ts +385 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
export const AddressType = {
|
|
2
|
+
SPP: "SPP",
|
|
3
|
+
BLE: "BLE",
|
|
4
|
+
DUAL: "DUAL",
|
|
5
|
+
WiFi: "WiFi",
|
|
6
|
+
};
|
|
7
|
+
export const AddressTypeCode = {
|
|
8
|
+
SPP: 16,
|
|
9
|
+
BLE: 20,
|
|
10
|
+
DUAL: 31,
|
|
11
|
+
WiFi: 240,
|
|
12
|
+
};
|
|
13
|
+
export const PrinterState = {
|
|
14
|
+
Connecting: "Connecting",
|
|
15
|
+
Connected: "Connected",
|
|
16
|
+
Connected2: "Connected2",
|
|
17
|
+
Printing: "Printing",
|
|
18
|
+
Working: "Working",
|
|
19
|
+
Disconnected: "Disconnected",
|
|
20
|
+
};
|
|
21
|
+
export const PrinterStateGroup = {
|
|
22
|
+
Connecting: 1,
|
|
23
|
+
Connected: 2,
|
|
24
|
+
Connected2: 2,
|
|
25
|
+
Printing: 2,
|
|
26
|
+
Working: 2,
|
|
27
|
+
Disconnected: 0,
|
|
28
|
+
};
|
|
29
|
+
export const GeneralProgress = {
|
|
30
|
+
Start: "Start",
|
|
31
|
+
Success: "Success",
|
|
32
|
+
Success2: "Success2",
|
|
33
|
+
Failed: "Failed",
|
|
34
|
+
Cancelled: "Cancelled",
|
|
35
|
+
Timeout: "Timeout",
|
|
36
|
+
Info: "Info",
|
|
37
|
+
};
|
|
38
|
+
export const PrintProgress = {
|
|
39
|
+
Connected: "Connected",
|
|
40
|
+
StartCopy: "StartCopy",
|
|
41
|
+
DataEnded: "DataEnded",
|
|
42
|
+
Success: "Success",
|
|
43
|
+
Failed: "Failed",
|
|
44
|
+
};
|
|
45
|
+
export const ProgressInfo = {
|
|
46
|
+
AdapterEnabling: "AdapterEnabling",
|
|
47
|
+
AdapterEnabled: "AdapterEnabled",
|
|
48
|
+
AdapterDisabled: "AdapterDisabled",
|
|
49
|
+
DeviceBonding: "DeviceBonding",
|
|
50
|
+
DeviceBonded: "DeviceBonded",
|
|
51
|
+
DeviceUnbonded: "DeviceUnbonded",
|
|
52
|
+
};
|
|
53
|
+
export const PrintFailReason = {
|
|
54
|
+
OK: "OK",
|
|
55
|
+
IsPrinting: "IsPrinting",
|
|
56
|
+
IsRotating: "IsRotating",
|
|
57
|
+
VolTooLow: "VolTooLow",
|
|
58
|
+
VolTooHigh: "VolTooHigh",
|
|
59
|
+
TphNotFound: "TphNotFound",
|
|
60
|
+
TphTooHot: "TphTooHot",
|
|
61
|
+
TphTooCold: "TphTooCold",
|
|
62
|
+
TphOpened: "TphOpened",
|
|
63
|
+
CoverOpened: "CoverOpened",
|
|
64
|
+
No_Paper: "No_Paper",
|
|
65
|
+
No_Ribbon: "No_Ribbon",
|
|
66
|
+
Unmatched_Ribbon: "Unmatched_Ribbon",
|
|
67
|
+
Usedup_Ribbon: "Usedup_Ribbon",
|
|
68
|
+
Usedup_Ribbon2: "Usedup_Ribbon2",
|
|
69
|
+
Cancelled: "Cancelled",
|
|
70
|
+
Disconnected: "Disconnected",
|
|
71
|
+
Timeout: "Timeout",
|
|
72
|
+
Other: "Other",
|
|
73
|
+
};
|
|
74
|
+
export const PrintParamName = {
|
|
75
|
+
PRINT_DARKNESS: "PRINT_DENSITY",
|
|
76
|
+
PRINT_DENSITY: "PRINT_DENSITY",
|
|
77
|
+
PRINT_SPEED: "PRINT_SPEED",
|
|
78
|
+
PRINT_DIRECTION: "PRINT_DIRECTION",
|
|
79
|
+
PRINT_COPIES: "PRINT_COPIES",
|
|
80
|
+
GAP_TYPE: "GAP_TYPE",
|
|
81
|
+
GAP_LENGTH_01MM: "GAP_LENGTH_01MM",
|
|
82
|
+
GAP_LENGTH_PX: "GAP_LENGTH_PX",
|
|
83
|
+
GAP_LENGTH: "GAP_LENGTH_01MM",
|
|
84
|
+
PRINT_ALIGNMENT: "PRINT_ALIGNMENT",
|
|
85
|
+
ANTI_COLOR: "ANTI_COLOR",
|
|
86
|
+
HORIZONTAL_OFFSET_01MM: "HORIZONTAL_OFFSET_01MM",
|
|
87
|
+
HORIZONTAL_OFFSET_PX: "HORIZONTAL_OFFSET_PX",
|
|
88
|
+
VERTICAL_OFFSET_01MM: "VERTICAL_OFFSET_01MM",
|
|
89
|
+
VERTICAL_OFFSET_PX: "VERTICAL_OFFSET_PX",
|
|
90
|
+
LEFT_MARGIN_01MM: "LEFT_MARGIN_01MM",
|
|
91
|
+
LEFT_MARGIN_PX: "LEFT_MARGIN_PX",
|
|
92
|
+
RIGHT_MARGIN_01MM: "RIGHT_MARGIN_01MM",
|
|
93
|
+
RIGHT_MARGIN_PX: "RIGHT_MARGIN_PX",
|
|
94
|
+
TOP_MARGIN_01MM: "TOP_MARGIN_01MM",
|
|
95
|
+
TOP_MARGIN_PX: "TOP_MARGIN_PX",
|
|
96
|
+
BOTTOM_MARGIN_01MM: "BOTTOM_MARGIN_01MM",
|
|
97
|
+
BOTTOM_MARGIN_PX: "BOTTOM_MARGIN_PX",
|
|
98
|
+
IMAGE_THRESHOLD: "IMAGE_THRESHOLD",
|
|
99
|
+
MOTOR_MODE: "MOTOR_MODE",
|
|
100
|
+
AUTO_POWEROFF: "AUTO_POWEROFF",
|
|
101
|
+
LANGUAGE: "LANGUAGE",
|
|
102
|
+
};
|
|
103
|
+
export const PrintParamValue = {
|
|
104
|
+
MIN_PRINT_DARKNESS: 0,
|
|
105
|
+
DEFAULT_PRINT_DARKNESS: 5,
|
|
106
|
+
MAX_PRINT_DARKNESS: 14,
|
|
107
|
+
MIN_PRINT_SPEED: 0,
|
|
108
|
+
DEFAULT_PRINT_SPEED: 2,
|
|
109
|
+
MAX_PRINT_SPEED: 4,
|
|
110
|
+
GAP_NONE: 0,
|
|
111
|
+
GAP_HOLE: 1,
|
|
112
|
+
GAP_GAP: 2,
|
|
113
|
+
GAP_BLACK: 3,
|
|
114
|
+
PRINT_ALIGNMENT_LEFT: 1024,
|
|
115
|
+
PRINT_ALIGNMENT_CENTER: 512,
|
|
116
|
+
PRINT_ALIGNMENT_RIGHT: 0,
|
|
117
|
+
};
|
|
118
|
+
export const FontStyle = {
|
|
119
|
+
REGULAR: 0,
|
|
120
|
+
BOLD: 1,
|
|
121
|
+
ITALIC: 2,
|
|
122
|
+
BOLDITALIC: 3,
|
|
123
|
+
UNDERLINE: 4,
|
|
124
|
+
STRIKEOUT: 8,
|
|
125
|
+
};
|
|
126
|
+
export const ItemAlignment = {
|
|
127
|
+
NEAR: 0,
|
|
128
|
+
CENTER: 1,
|
|
129
|
+
FAR: 2,
|
|
130
|
+
SAMEASITEM: 3,
|
|
131
|
+
LEFT: 0,
|
|
132
|
+
RIGHT: 2,
|
|
133
|
+
TOP: 0,
|
|
134
|
+
MIDDLE: 1,
|
|
135
|
+
BOTTOM: 2,
|
|
136
|
+
};
|
|
137
|
+
export const PenAlignment = {
|
|
138
|
+
CENTER: 0,
|
|
139
|
+
INSET: 1,
|
|
140
|
+
};
|
|
141
|
+
export const LabelScaleUnit = {
|
|
142
|
+
PIXEL: 0,
|
|
143
|
+
MM01: 1,
|
|
144
|
+
};
|
|
145
|
+
export const ErrorCorrectionLevel = {
|
|
146
|
+
L: 0,
|
|
147
|
+
M: 1,
|
|
148
|
+
Q: 2,
|
|
149
|
+
H: 3,
|
|
150
|
+
};
|
|
151
|
+
export const BarcodeType1D = {
|
|
152
|
+
UPC_A: 20,
|
|
153
|
+
UPC_E: 21,
|
|
154
|
+
EAN13: 22,
|
|
155
|
+
EAN8: 23,
|
|
156
|
+
CODE39: 24,
|
|
157
|
+
ITF25: 25,
|
|
158
|
+
CODABAR: 26,
|
|
159
|
+
CODE93: 27,
|
|
160
|
+
CODE128: 28,
|
|
161
|
+
ISBN: 29,
|
|
162
|
+
ECODE39: 30,
|
|
163
|
+
AUTO: 60,
|
|
164
|
+
};
|
|
165
|
+
export const BarcodeType2D = {
|
|
166
|
+
QR_CODE: 41,
|
|
167
|
+
DATA_MATRIX: 42,
|
|
168
|
+
PDF_417: 43,
|
|
169
|
+
};
|
|
170
|
+
export const ResultCode = {
|
|
171
|
+
OK: 0,
|
|
172
|
+
PARAM_ERROR: 1,
|
|
173
|
+
SYSTEM_ERROR: 2,
|
|
174
|
+
NOPRINTDATA: 5,
|
|
175
|
+
NOPAGEDIMENSION: 6,
|
|
176
|
+
INVALID_FILE: 7,
|
|
177
|
+
PRINTDATANOTREADY: 8,
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,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T,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;IACV,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,EAAE;CACA,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,EAAE;IACX,WAAW,EAAE,EAAE;IACf,OAAO,EAAE,EAAE;CACH,CAAC;AAEX,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,EAAE,EAAE,CAAC;IACL,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,eAAe,EAAE,CAAC;IAClB,YAAY,EAAE,CAAC;IACf,iBAAiB,EAAE,CAAC;CACZ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { BitmapLike, BundleLike, IAtBitmapDocument, MaybePromise, PaperInfo, PrintCallback, PrintDocument, PrinterDevice, PrinterInfo, PrinterSdkCallback, PrinterState, ScanCallback } from "./types.js";
|
|
2
|
+
export interface PrinterTransport {
|
|
3
|
+
getSdkVersion?(): MaybePromise<string>;
|
|
4
|
+
init?(application: unknown): MaybePromise<boolean>;
|
|
5
|
+
initSdk?(application: unknown): MaybePromise<boolean>;
|
|
6
|
+
setSdkCallback?(callback?: PrinterSdkCallback): void;
|
|
7
|
+
initDefaultImageLibrarySettings?(fontDirectory: string, extra: string): MaybePromise<number>;
|
|
8
|
+
initImageProcessingDefault?(fontDirectory: string, extra: string): MaybePromise<number>;
|
|
9
|
+
openPrinterByAddress?(address: string): MaybePromise<number>;
|
|
10
|
+
openPrinterSync?(address: string): MaybePromise<number>;
|
|
11
|
+
connectBluetoothPrinter?(address: string): MaybePromise<number>;
|
|
12
|
+
connectWifiPrinter?(host: string, port: number): MaybePromise<number>;
|
|
13
|
+
configurationWifi?(ssid: string, password: string): MaybePromise<number>;
|
|
14
|
+
getConfigurationWifiName?(): MaybePromise<string>;
|
|
15
|
+
scanWifiPrinter?(callback: ScanCallback): MaybePromise<void>;
|
|
16
|
+
setPrinterAutoShutdownTime?(minutes: number): MaybePromise<number>;
|
|
17
|
+
setTotalPrintQuantity?(quantity: number): MaybePromise<void>;
|
|
18
|
+
setTotalQuantityOfPrints?(quantity: number): MaybePromise<void>;
|
|
19
|
+
startPrintJob?(density: number, paperType: number, printMode: number, callback: PrintCallback): MaybePromise<void>;
|
|
20
|
+
commitData?(jsonPages: string[], infoPages: string[]): MaybePromise<void>;
|
|
21
|
+
commitDocument?(document: PrintDocument, infoPages: string[]): MaybePromise<void>;
|
|
22
|
+
endJob?(): MaybePromise<boolean>;
|
|
23
|
+
endPrintJob?(): MaybePromise<boolean>;
|
|
24
|
+
cancelJob?(): MaybePromise<boolean>;
|
|
25
|
+
cancel?(): MaybePromise<void>;
|
|
26
|
+
reopenPrinter?(): MaybePromise<boolean>;
|
|
27
|
+
reopenPrinterSync?(): MaybePromise<boolean>;
|
|
28
|
+
close?(): MaybePromise<void>;
|
|
29
|
+
quit?(): MaybePromise<void>;
|
|
30
|
+
printBitmap?(bitmap: BitmapLike, bundle?: BundleLike): MaybePromise<boolean>;
|
|
31
|
+
printATBitmap?(bitmap: IAtBitmapDocument, bundle?: BundleLike): MaybePromise<boolean>;
|
|
32
|
+
getPaperInfo?(): MaybePromise<PaperInfo | null>;
|
|
33
|
+
isConnection?(): MaybePromise<number>;
|
|
34
|
+
getPrintScaleMultiplier?(): MaybePromise<number>;
|
|
35
|
+
getPrinterName?(): MaybePromise<string>;
|
|
36
|
+
getPrinterInfo?(): MaybePromise<PrinterInfo | null>;
|
|
37
|
+
getPrinterState?(): MaybePromise<PrinterState>;
|
|
38
|
+
waitPrinterState?(state: PrinterState, timeoutMs: number): MaybePromise<boolean>;
|
|
39
|
+
measureFontHeight?(text: string, x: number, y: number, width: number, height: number, rotation: number, fontSize: number): MaybePromise<number>;
|
|
40
|
+
generatePreviewImage?(json: string, info: string): MaybePromise<BitmapLike>;
|
|
41
|
+
generatePrintPreviewImage?(json: string, widthMm: number, heightMm: number, orientation: number): MaybePromise<BitmapLike>;
|
|
42
|
+
setPrinterState?(state: PrinterState): void;
|
|
43
|
+
setPrinterInfo?(info: PrinterInfo): void;
|
|
44
|
+
setPaperInfo?(info: PaperInfo): void;
|
|
45
|
+
setScanResults?(results: PrinterDevice[]): void;
|
|
46
|
+
emitPrintProgress?(pageIndex: number, quantityIndex: number, meta?: Record<string, unknown>): void;
|
|
47
|
+
emitPrintError?(errorCode: number, printState?: number): void;
|
|
48
|
+
emitBufferFree?(pageIndex: number, bufferSize: number): void;
|
|
49
|
+
emitCancel?(success: boolean): void;
|
|
50
|
+
lastDocument?: PrintDocument | undefined;
|
|
51
|
+
}
|
|
52
|
+
export declare class MemoryPrinterTransport implements PrinterTransport {
|
|
53
|
+
private sdkVersion;
|
|
54
|
+
private configurationWifiName;
|
|
55
|
+
private printerInfo;
|
|
56
|
+
private paperInfo;
|
|
57
|
+
private printerState;
|
|
58
|
+
private printerName;
|
|
59
|
+
private connectedAddress;
|
|
60
|
+
private connectedType;
|
|
61
|
+
private lastConnectedAddress;
|
|
62
|
+
private lastConnectedType;
|
|
63
|
+
private sdkCallback;
|
|
64
|
+
private connectionResult;
|
|
65
|
+
private wifiConfigurationResult;
|
|
66
|
+
private shutdownResult;
|
|
67
|
+
private scanResults;
|
|
68
|
+
private printState;
|
|
69
|
+
private totalPrintQuantity;
|
|
70
|
+
lastDocument: PrintDocument | undefined;
|
|
71
|
+
lastBitmap?: BitmapLike;
|
|
72
|
+
lastAtBitmap?: IAtBitmapDocument;
|
|
73
|
+
lastCommitPayload: {
|
|
74
|
+
jsonPages: string[];
|
|
75
|
+
infoPages: string[];
|
|
76
|
+
} | undefined;
|
|
77
|
+
lastPreview: BitmapLike | undefined;
|
|
78
|
+
getSdkVersion(): string;
|
|
79
|
+
setSdkVersion(version: string): void;
|
|
80
|
+
initSdk(): boolean;
|
|
81
|
+
init(): boolean;
|
|
82
|
+
setSdkCallback(callback?: PrinterSdkCallback): void;
|
|
83
|
+
initDefaultImageLibrarySettings(): number;
|
|
84
|
+
initImageProcessingDefault(): number;
|
|
85
|
+
private syncPrinterInfo;
|
|
86
|
+
openPrinterByAddress(address: string): number;
|
|
87
|
+
openPrinterSync(address: string): number;
|
|
88
|
+
connectBluetoothPrinter(address: string): number;
|
|
89
|
+
connectWifiPrinter(host: string, _port: number): number;
|
|
90
|
+
configurationWifi(ssid: string, _password: string): number;
|
|
91
|
+
getConfigurationWifiName(): string;
|
|
92
|
+
scanWifiPrinter(callback: ScanCallback): void;
|
|
93
|
+
setPrinterAutoShutdownTime(minutes: number): number;
|
|
94
|
+
setTotalPrintQuantity(quantity: number): void;
|
|
95
|
+
setTotalQuantityOfPrints(quantity: number): void;
|
|
96
|
+
startPrintJob(_density: number, _paperType: number, _printMode: number, callback: PrintCallback): void;
|
|
97
|
+
commitData(jsonPages: string[], infoPages: string[]): void;
|
|
98
|
+
commitDocument(document: PrintDocument, infoPages: string[]): void;
|
|
99
|
+
endJob(): boolean;
|
|
100
|
+
endPrintJob(): boolean;
|
|
101
|
+
cancelJob(): boolean;
|
|
102
|
+
cancel(): void;
|
|
103
|
+
close(): void;
|
|
104
|
+
quit(): void;
|
|
105
|
+
reopenPrinter(): boolean;
|
|
106
|
+
reopenPrinterSync(): boolean;
|
|
107
|
+
printBitmap(bitmap: BitmapLike): boolean;
|
|
108
|
+
printATBitmap(bitmap: IAtBitmapDocument): boolean;
|
|
109
|
+
getPaperInfo(): PaperInfo;
|
|
110
|
+
isConnection(): number;
|
|
111
|
+
getPrintScaleMultiplier(): number;
|
|
112
|
+
getPrinterName(): string;
|
|
113
|
+
getPrinterInfo(): PrinterInfo;
|
|
114
|
+
getPrinterState(): PrinterState;
|
|
115
|
+
waitPrinterState(state: PrinterState): boolean;
|
|
116
|
+
measureFontHeight(text: string, _x: number, _y: number, _width: number, _height: number, _rotation: number, fontSize: number): number;
|
|
117
|
+
generatePreviewImage(json: string, info: string): BitmapLike;
|
|
118
|
+
generatePrintPreviewImage(json: string, widthMm: number, heightMm: number, orientation: number): BitmapLike;
|
|
119
|
+
setPrinterState(state: PrinterState): void;
|
|
120
|
+
setPrinterInfo(info: PrinterInfo): void;
|
|
121
|
+
setPaperInfo(info: PaperInfo): void;
|
|
122
|
+
setScanResults(results: PrinterDevice[]): void;
|
|
123
|
+
emitPrintProgress(pageIndex: number, quantityIndex: number, meta?: Record<string, unknown>): void;
|
|
124
|
+
emitPrintError(errorCode: number, printState?: number): void;
|
|
125
|
+
emitBufferFree(pageIndex: number, bufferSize: number): void;
|
|
126
|
+
emitCancel(success: boolean): void;
|
|
127
|
+
setConnectionResult(result: number): void;
|
|
128
|
+
setWifiConfigurationResult(result: number): void;
|
|
129
|
+
setShutdownResult(result: number): void;
|
|
130
|
+
}
|
|
131
|
+
export declare function createMemoryPrinterTransport(): MemoryPrinterTransport;
|
|
132
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"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AE,MAAM,EAAE,UAAU,SAAI,GAAG,IAAI;IAIvD,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAI3D,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIzC,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIhD,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAGxC;AAED,wBAAgB,4BAA4B,IAAI,sBAAsB,CAErE"}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
function clone(value) {
|
|
2
|
+
if (typeof globalThis.structuredClone === "function") {
|
|
3
|
+
return globalThis.structuredClone(value);
|
|
4
|
+
}
|
|
5
|
+
return JSON.parse(JSON.stringify(value));
|
|
6
|
+
}
|
|
7
|
+
function defaultPrinterInfo() {
|
|
8
|
+
return {
|
|
9
|
+
deviceType: 0,
|
|
10
|
+
deviceName: "",
|
|
11
|
+
deviceVersion: "",
|
|
12
|
+
softwareVersion: "",
|
|
13
|
+
deviceAddress: "",
|
|
14
|
+
deviceAddrType: 0,
|
|
15
|
+
deviceDPI: 0,
|
|
16
|
+
deviceWidth: 0,
|
|
17
|
+
manufacturer: "",
|
|
18
|
+
seriesName: "",
|
|
19
|
+
devIntName: "",
|
|
20
|
+
peripheralFlags: 0,
|
|
21
|
+
hardwareFlags: 0,
|
|
22
|
+
softwareFlags: 0,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function defaultPaperInfo() {
|
|
26
|
+
return {
|
|
27
|
+
state: 0,
|
|
28
|
+
gapHeightPixel: 0,
|
|
29
|
+
totalHeightPixel: 0,
|
|
30
|
+
paperType: 0,
|
|
31
|
+
gapHeight: 0,
|
|
32
|
+
totalHeight: 0,
|
|
33
|
+
paperWidthPixel: 0,
|
|
34
|
+
paperWidth: 0,
|
|
35
|
+
direction: 0,
|
|
36
|
+
tailLengthPixel: 0,
|
|
37
|
+
tailLength: 0,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function dimensionsFromInfo(info) {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(info);
|
|
43
|
+
const imageInfo = parsed.printerImageProcessingInfo;
|
|
44
|
+
const width = Number(imageInfo?.width ?? 0);
|
|
45
|
+
const height = Number(imageInfo?.height ?? 0);
|
|
46
|
+
return {
|
|
47
|
+
width: Number.isFinite(width) ? width : 0,
|
|
48
|
+
height: Number.isFinite(height) ? height : 0,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return { width: 0, height: 0 };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class MemoryPrinterTransport {
|
|
56
|
+
constructor() {
|
|
57
|
+
this.sdkVersion = "ts-mock";
|
|
58
|
+
this.configurationWifiName = "";
|
|
59
|
+
this.printerInfo = defaultPrinterInfo();
|
|
60
|
+
this.paperInfo = defaultPaperInfo();
|
|
61
|
+
this.printerState = "Disconnected";
|
|
62
|
+
this.printerName = "";
|
|
63
|
+
this.connectedAddress = "";
|
|
64
|
+
this.connectedType = -1;
|
|
65
|
+
this.lastConnectedAddress = "";
|
|
66
|
+
this.lastConnectedType = -1;
|
|
67
|
+
this.connectionResult = 0;
|
|
68
|
+
this.wifiConfigurationResult = 0;
|
|
69
|
+
this.shutdownResult = 0;
|
|
70
|
+
this.scanResults = [];
|
|
71
|
+
this.printState = { callback: undefined, jobStarted: false };
|
|
72
|
+
this.totalPrintQuantity = 0;
|
|
73
|
+
}
|
|
74
|
+
getSdkVersion() {
|
|
75
|
+
return this.sdkVersion;
|
|
76
|
+
}
|
|
77
|
+
setSdkVersion(version) {
|
|
78
|
+
this.sdkVersion = version;
|
|
79
|
+
}
|
|
80
|
+
initSdk() {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
init() {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
setSdkCallback(callback) {
|
|
87
|
+
this.sdkCallback = callback;
|
|
88
|
+
if (callback && this.printerState !== "Disconnected" && this.connectedAddress) {
|
|
89
|
+
callback.onConnectSuccess(this.connectedAddress, this.connectedType);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
initDefaultImageLibrarySettings() {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
initImageProcessingDefault() {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
syncPrinterInfo(address, type) {
|
|
99
|
+
this.printerInfo = {
|
|
100
|
+
...this.printerInfo,
|
|
101
|
+
deviceName: address,
|
|
102
|
+
deviceAddress: address,
|
|
103
|
+
deviceAddrType: type,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
openPrinterByAddress(address) {
|
|
107
|
+
if (this.connectionResult === 0) {
|
|
108
|
+
this.connectedAddress = address;
|
|
109
|
+
this.connectedType = 0;
|
|
110
|
+
this.lastConnectedAddress = address;
|
|
111
|
+
this.lastConnectedType = this.connectedType;
|
|
112
|
+
this.printerName = address;
|
|
113
|
+
this.syncPrinterInfo(address, this.connectedType);
|
|
114
|
+
this.printerState = "Connected";
|
|
115
|
+
this.sdkCallback?.onConnectSuccess(address, this.connectedType);
|
|
116
|
+
}
|
|
117
|
+
return this.connectionResult;
|
|
118
|
+
}
|
|
119
|
+
openPrinterSync(address) {
|
|
120
|
+
return this.openPrinterByAddress(address);
|
|
121
|
+
}
|
|
122
|
+
connectBluetoothPrinter(address) {
|
|
123
|
+
if (this.connectionResult === 0) {
|
|
124
|
+
this.connectedAddress = address;
|
|
125
|
+
this.connectedType = 0;
|
|
126
|
+
this.lastConnectedAddress = address;
|
|
127
|
+
this.lastConnectedType = this.connectedType;
|
|
128
|
+
this.printerName = address;
|
|
129
|
+
this.syncPrinterInfo(address, this.connectedType);
|
|
130
|
+
this.printerState = "Connected";
|
|
131
|
+
this.sdkCallback?.onConnectSuccess(address, this.connectedType);
|
|
132
|
+
}
|
|
133
|
+
return this.connectionResult;
|
|
134
|
+
}
|
|
135
|
+
connectWifiPrinter(host, _port) {
|
|
136
|
+
if (this.connectionResult === 0) {
|
|
137
|
+
this.connectedAddress = host;
|
|
138
|
+
this.connectedType = 1;
|
|
139
|
+
this.lastConnectedAddress = host;
|
|
140
|
+
this.lastConnectedType = this.connectedType;
|
|
141
|
+
this.printerName = host;
|
|
142
|
+
this.syncPrinterInfo(host, this.connectedType);
|
|
143
|
+
this.printerState = "Connected";
|
|
144
|
+
this.sdkCallback?.onConnectSuccess(host, this.connectedType);
|
|
145
|
+
}
|
|
146
|
+
return this.connectionResult;
|
|
147
|
+
}
|
|
148
|
+
configurationWifi(ssid, _password) {
|
|
149
|
+
this.configurationWifiName = ssid;
|
|
150
|
+
return this.wifiConfigurationResult;
|
|
151
|
+
}
|
|
152
|
+
getConfigurationWifiName() {
|
|
153
|
+
return this.configurationWifiName;
|
|
154
|
+
}
|
|
155
|
+
scanWifiPrinter(callback) {
|
|
156
|
+
for (const device of this.scanResults) {
|
|
157
|
+
callback.onScan(clone(device));
|
|
158
|
+
}
|
|
159
|
+
callback.onFinish();
|
|
160
|
+
}
|
|
161
|
+
setPrinterAutoShutdownTime(minutes) {
|
|
162
|
+
this.shutdownResult = minutes >= 0 ? 0 : -1;
|
|
163
|
+
return this.shutdownResult;
|
|
164
|
+
}
|
|
165
|
+
setTotalPrintQuantity(quantity) {
|
|
166
|
+
this.totalPrintQuantity = quantity;
|
|
167
|
+
}
|
|
168
|
+
setTotalQuantityOfPrints(quantity) {
|
|
169
|
+
this.totalPrintQuantity = quantity;
|
|
170
|
+
}
|
|
171
|
+
startPrintJob(_density, _paperType, _printMode, callback) {
|
|
172
|
+
this.printState = { callback, jobStarted: true };
|
|
173
|
+
if (this.connectedAddress) {
|
|
174
|
+
this.printerState = "Printing";
|
|
175
|
+
}
|
|
176
|
+
this.lastDocument = undefined;
|
|
177
|
+
this.lastCommitPayload = undefined;
|
|
178
|
+
this.lastPreview = undefined;
|
|
179
|
+
}
|
|
180
|
+
commitData(jsonPages, infoPages) {
|
|
181
|
+
this.lastCommitPayload = {
|
|
182
|
+
jsonPages: clone(jsonPages),
|
|
183
|
+
infoPages: clone(infoPages),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
commitDocument(document, infoPages) {
|
|
187
|
+
this.lastDocument = clone(document);
|
|
188
|
+
this.lastCommitPayload = {
|
|
189
|
+
jsonPages: document.pages.map((page) => JSON.stringify(page)),
|
|
190
|
+
infoPages: clone(infoPages),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
endJob() {
|
|
194
|
+
this.printState.jobStarted = false;
|
|
195
|
+
this.printState.callback = undefined;
|
|
196
|
+
this.printerState = this.connectedAddress ? "Connected" : "Disconnected";
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
endPrintJob() {
|
|
200
|
+
this.printState.jobStarted = false;
|
|
201
|
+
this.printState.callback = undefined;
|
|
202
|
+
this.printerState = this.connectedAddress ? "Connected" : "Disconnected";
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
cancelJob() {
|
|
206
|
+
this.printState.jobStarted = false;
|
|
207
|
+
this.printState.callback?.onCancelJob(true);
|
|
208
|
+
this.printState.callback = undefined;
|
|
209
|
+
this.printerState = this.connectedAddress ? "Connected" : "Disconnected";
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
cancel() {
|
|
213
|
+
this.cancelJob();
|
|
214
|
+
}
|
|
215
|
+
close() {
|
|
216
|
+
const wasConnected = this.printerState !== "Disconnected";
|
|
217
|
+
this.printState.jobStarted = false;
|
|
218
|
+
this.printState.callback = undefined;
|
|
219
|
+
this.printerState = "Disconnected";
|
|
220
|
+
this.connectedAddress = "";
|
|
221
|
+
this.connectedType = -1;
|
|
222
|
+
this.printerName = "";
|
|
223
|
+
if (wasConnected) {
|
|
224
|
+
this.sdkCallback?.onDisConnect();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
quit() {
|
|
228
|
+
this.close();
|
|
229
|
+
}
|
|
230
|
+
reopenPrinter() {
|
|
231
|
+
if (!this.lastConnectedAddress) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
this.connectedAddress = this.lastConnectedAddress;
|
|
235
|
+
this.connectedType = this.lastConnectedType;
|
|
236
|
+
this.printerName = this.connectedAddress;
|
|
237
|
+
this.syncPrinterInfo(this.connectedAddress, this.connectedType);
|
|
238
|
+
this.printerState = "Connected";
|
|
239
|
+
this.sdkCallback?.onConnectSuccess(this.connectedAddress, this.connectedType);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
reopenPrinterSync() {
|
|
243
|
+
return this.reopenPrinter();
|
|
244
|
+
}
|
|
245
|
+
printBitmap(bitmap) {
|
|
246
|
+
this.lastBitmap = clone(bitmap);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
printATBitmap(bitmap) {
|
|
250
|
+
this.lastAtBitmap = clone(bitmap);
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
getPaperInfo() {
|
|
254
|
+
return clone(this.paperInfo);
|
|
255
|
+
}
|
|
256
|
+
isConnection() {
|
|
257
|
+
return this.printerState === "Disconnected" ? -1 : 0;
|
|
258
|
+
}
|
|
259
|
+
getPrintScaleMultiplier() {
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
getPrinterName() {
|
|
263
|
+
return this.printerName;
|
|
264
|
+
}
|
|
265
|
+
getPrinterInfo() {
|
|
266
|
+
return clone(this.printerInfo);
|
|
267
|
+
}
|
|
268
|
+
getPrinterState() {
|
|
269
|
+
return this.printerState;
|
|
270
|
+
}
|
|
271
|
+
waitPrinterState(state) {
|
|
272
|
+
return this.printerState === state;
|
|
273
|
+
}
|
|
274
|
+
measureFontHeight(text, _x, _y, _width, _height, _rotation, fontSize) {
|
|
275
|
+
const lines = text.split(/\r?\n/).length;
|
|
276
|
+
return Math.max(fontSize, Math.ceil(fontSize * 1.2 * lines));
|
|
277
|
+
}
|
|
278
|
+
generatePreviewImage(json, info) {
|
|
279
|
+
const { width, height } = dimensionsFromInfo(info);
|
|
280
|
+
this.lastPreview = {
|
|
281
|
+
width,
|
|
282
|
+
height,
|
|
283
|
+
description: "preview",
|
|
284
|
+
meta: { json, info },
|
|
285
|
+
};
|
|
286
|
+
return clone(this.lastPreview);
|
|
287
|
+
}
|
|
288
|
+
generatePrintPreviewImage(json, widthMm, heightMm, orientation) {
|
|
289
|
+
this.lastPreview = {
|
|
290
|
+
width: widthMm,
|
|
291
|
+
height: heightMm,
|
|
292
|
+
description: "print-preview",
|
|
293
|
+
meta: { json, orientation },
|
|
294
|
+
};
|
|
295
|
+
return clone(this.lastPreview);
|
|
296
|
+
}
|
|
297
|
+
setPrinterState(state) {
|
|
298
|
+
this.printerState = state;
|
|
299
|
+
}
|
|
300
|
+
setPrinterInfo(info) {
|
|
301
|
+
this.printerInfo = clone(info);
|
|
302
|
+
}
|
|
303
|
+
setPaperInfo(info) {
|
|
304
|
+
this.paperInfo = clone(info);
|
|
305
|
+
}
|
|
306
|
+
setScanResults(results) {
|
|
307
|
+
this.scanResults = clone(results);
|
|
308
|
+
}
|
|
309
|
+
emitPrintProgress(pageIndex, quantityIndex, meta = {}) {
|
|
310
|
+
this.printState.callback?.onProgress(pageIndex, quantityIndex, meta);
|
|
311
|
+
}
|
|
312
|
+
emitPrintError(errorCode, printState = 0) {
|
|
313
|
+
this.printState.callback?.onError(errorCode, printState);
|
|
314
|
+
}
|
|
315
|
+
emitBufferFree(pageIndex, bufferSize) {
|
|
316
|
+
this.printState.callback?.onBufferFree(pageIndex, bufferSize);
|
|
317
|
+
}
|
|
318
|
+
emitCancel(success) {
|
|
319
|
+
this.printState.callback?.onCancelJob(success);
|
|
320
|
+
}
|
|
321
|
+
setConnectionResult(result) {
|
|
322
|
+
this.connectionResult = result;
|
|
323
|
+
}
|
|
324
|
+
setWifiConfigurationResult(result) {
|
|
325
|
+
this.wifiConfigurationResult = result;
|
|
326
|
+
}
|
|
327
|
+
setShutdownResult(result) {
|
|
328
|
+
this.shutdownResult = result;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
export function createMemoryPrinterTransport() {
|
|
332
|
+
return new MemoryPrinterTransport();
|
|
333
|
+
}
|
|
334
|
+
//# sourceMappingURL=transport.js.map
|