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 ADDED
@@ -0,0 +1,86 @@
1
+ # JC Printer SDK TS
2
+
3
+ This package turns the current Android SDK surface into TypeScript-first types and helpers.
4
+
5
+ ## SDK analysis
6
+
7
+ The package in this workspace contains three runtime artifacts:
8
+
9
+ - `3.2.4-release.aar`: current main API, exposed as `com.gengcon.www.jcprintersdk.JCPrintApi`
10
+ - `image-1.8.7.aar`: native image/preview runtime, including `NBCanvasImage`
11
+ - `LPAPI-2019-11-20-R.jar`: legacy/compatibility layer for B50/B11-style flows, including `LPAPI`, `IAtBitmap`, and `IDzPrinter`
12
+
13
+ The Demo uses `JCPrintApi` as the core path:
14
+
15
+ 1. initialize SDK and image/font library
16
+ 2. connect Bluetooth or Wi-Fi printer
17
+ 3. call `startPrintJob`
18
+ 4. build page data with `drawEmptyLabel` and `drawLabel*`
19
+ 5. call `generateLabelJson`
20
+ 6. submit page batches with `commitData`
21
+ 7. finish with `endPrintJob`
22
+
23
+ ## What is covered
24
+
25
+ - `JCPrintApi` style flows from `3.2.4-release.aar`
26
+ - label drawing commands: text, barcode, QR code, shapes, image, line
27
+ - print job payload assembly with `generateLabelJson` and `commitData`
28
+ - connection/configuration methods: Bluetooth, Wi-Fi, preview, shutdown, status
29
+ - core legacy constants from `LPAPI-2019-11-20-R.jar`
30
+
31
+ ## What is not
32
+
33
+ - no native Android code is embedded here
34
+ - a real device adapter still needs a transport implementation
35
+
36
+ ## Core idea
37
+
38
+ Use `JCPrintApi` or `PrinterClient` plus a transport:
39
+
40
+ ```ts
41
+ import {
42
+ JCPrintApi,
43
+ createMemoryPrinterTransport,
44
+ } from "jc-printer-sdk-ts";
45
+
46
+ const printer = JCPrintApi.getInstance(
47
+ {
48
+ onConnectSuccess() {},
49
+ onDisConnect() {},
50
+ onElectricityChange() {},
51
+ onCoverStatus() {},
52
+ onPaperStatus() {},
53
+ onRfidReadStatus() {},
54
+ onRibbonStatus() {},
55
+ onRibbonRfidReadStatus() {},
56
+ onFirmErrors() {},
57
+ },
58
+ createMemoryPrinterTransport(),
59
+ );
60
+
61
+ printer.initSdk({});
62
+ printer.startPrintJob(3, 1, 1, {
63
+ onProgress() {},
64
+ onError() {},
65
+ onBufferFree() {},
66
+ onCancelJob() {},
67
+ });
68
+
69
+ printer.drawEmptyLabel(70, 50, 90, ["ZT008.ttf"]);
70
+ printer.drawLabelText(12, 2, 40, 10, "Hello", "ZT008", 18);
71
+ const json = printer.generateLabelJson();
72
+ ```
73
+
74
+ For real hardware, implement `PrinterTransport` and forward calls to the Android native SDK. For local tests, use `MemoryPrinterTransport`.
75
+
76
+ `JCPrintApi` mirrors the current Android surface, while `LabelBuilder` keeps the normalized label document used by the TS layer.
77
+ Use `JCPrintApi.getInstance` for the singleton-style facade, or `createPrinterClient` / `new JCPrintApi(...)` when you want to inject a custom transport.
78
+
79
+ ## Mapping
80
+
81
+ - `openPrinterByAddress` -> connection by address
82
+ - `connectBluetoothPrinter` / `connectWifiPrinter` -> current device connect API
83
+ - `drawEmptyLabel` -> page setup
84
+ - `drawLabelText` / `drawLabelBarCode` / `drawLabelQrCode` / `drawLabelGraph` -> label commands
85
+ - `generateLabelJson` -> serialized page payload
86
+ - `commitData` -> page batch submission
@@ -0,0 +1,60 @@
1
+ import type { BitmapLike, CommitPayload, IAtBitmapDocument, LabelBarcodeOptions, LabelGraphOptions, LabelImageOptions, LabelLineOptions, LabelQrCodeOptions, LabelTextOptions, Point, PrintDocument, PrintJobOptions, PrintPage } from "./types.js";
2
+ export declare class LabelBuilder {
3
+ readonly unit: "mm" | "px";
4
+ private job;
5
+ private pages;
6
+ private currentPage;
7
+ private pageDefaults;
8
+ private itemOrientation;
9
+ private itemHorizontalAlignment;
10
+ private itemVerticalAlignment;
11
+ private itemPenAlignment;
12
+ constructor(unit?: "mm" | "px");
13
+ reset(): void;
14
+ startJob(density: number, paperType: number, printMode: number): void;
15
+ abortJob(): void;
16
+ startPage(): void;
17
+ endPage(): void;
18
+ endJob(): void;
19
+ drawEmptyLabel(width: number, height: number, orientation: number, fonts: string | string[]): void;
20
+ drawLabelText(x: number, y: number, width: number, height: number, text: string, fontName: string, fontSize: number, options?: LabelTextOptions): void;
21
+ drawLabelBarCode(x: number, y: number, width: number, height: number, codeType: number, text: string, options?: LabelBarcodeOptions): void;
22
+ drawLabelQrCode(x: number, y: number, width: number, height: number, text: string, options?: LabelQrCodeOptions): void;
23
+ drawLabelGraph(x: number, y: number, width: number, height: number, graphType: number, options?: LabelGraphOptions): void;
24
+ drawLabelImage(source: string | BitmapLike, x: number, y: number, width: number, height: number, options?: LabelImageOptions): void;
25
+ drawLabelLine(x: number, y: number, width: number, height: number, options?: LabelLineOptions): void;
26
+ setDrawParam(name: string, value: unknown): void;
27
+ getItemOrientation(): number;
28
+ setItemOrientation(value: number): void;
29
+ getItemHorizontalAlignment(): number;
30
+ setItemHorizontalAlignment(value: number): void;
31
+ getItemVerticalAlignment(): number;
32
+ setItemVerticalAlignment(value: number): void;
33
+ getItemPenAlignment(): number;
34
+ setItemPenAlignment(value: number): void;
35
+ setBackground(color: number): void;
36
+ getPrintMultiple(): number;
37
+ setTotalPrintQuantity(quantity: number): void;
38
+ setTotalQuantityOfPrints(quantity: number): void;
39
+ getJobPages(): PrintPage[];
40
+ getCurrentPage(): PrintPage | null;
41
+ toDocument(): PrintDocument;
42
+ serialize(): string;
43
+ generateLabelJson(): Uint8Array;
44
+ toCommitPayload(): CommitPayload;
45
+ commitImageData(orientation: number, bitmap: BitmapLike, width: number, height: number, printQuantity: number, marginLeft: number, marginTop: number, marginRight: number, marginBottom: number, rfid: string): void;
46
+ generatePreviewImage(json: string, info: string): BitmapLike;
47
+ getMultiple(): number;
48
+ measureFontHeight(text: string, x: number, y: number, width: number, height: number, rotation: number, fontSize: number): number;
49
+ getStrPrintSize(text: string, fontStyle: number, fontSize: number): Point;
50
+ getMin1DBarcode(text: string, codeType: number): BitmapLike;
51
+ getMin2DQRCode(text: string): BitmapLike;
52
+ addLabelCommand(kind: string, payload: Record<string, unknown>): void;
53
+ private ensurePage;
54
+ private openPage;
55
+ private closePage;
56
+ private addCommand;
57
+ }
58
+ export declare function createLabelBuilder(unit?: "mm" | "px"): LabelBuilder;
59
+ export declare function createAtBitmapDocument(job?: PrintJobOptions): IAtBitmapDocument;
60
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAEV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAEhB,KAAK,EACL,aAAa,EACb,eAAe,EACf,SAAS,EACV,MAAM,YAAY,CAAC;AA0EpB,qBAAa,YAAY;IACvB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAE3B,OAAO,CAAC,GAAG,CAAuB;IAClC,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,qBAAqB,CAA6B;IAC1D,OAAO,CAAC,gBAAgB,CAA+B;gBAE3C,IAAI,GAAE,IAAI,GAAG,IAAW;IAIpC,KAAK,IAAI,IAAI;IAWb,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAarE,QAAQ,IAAI,IAAI;IAIhB,SAAS,IAAI,IAAI;IAajB,OAAO,IAAI,IAAI;IAIf,MAAM,IAAI,IAAI;IAId,cAAc,CACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EAC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AAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK;IAQzE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU;IAI3D,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAIxC,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIrE,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,UAAU;CAInB;AAED,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,IAAI,GAAG,IAAW,GAAG,YAAY,CAEzE;AAED,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,eAAoB,GACxB,iBAAiB,CAOnB"}
@@ -0,0 +1,411 @@
1
+ import { ItemAlignment, PenAlignment } from "./constants.js";
2
+ function clone(value) {
3
+ if (typeof globalThis.structuredClone === "function") {
4
+ return globalThis.structuredClone(value);
5
+ }
6
+ return JSON.parse(JSON.stringify(value));
7
+ }
8
+ function normalizeFonts(fonts) {
9
+ if (Array.isArray(fonts)) {
10
+ return fonts.filter(Boolean);
11
+ }
12
+ if (typeof fonts === "string" && fonts.trim()) {
13
+ return [fonts];
14
+ }
15
+ return [];
16
+ }
17
+ function toCommand(kind, payload) {
18
+ return { kind, payload };
19
+ }
20
+ function safeNumber(value, fallback) {
21
+ return Number.isFinite(value) ? value : fallback;
22
+ }
23
+ function buildInfoPage(page, job) {
24
+ return JSON.stringify({
25
+ printerImageProcessingInfo: {
26
+ orientation: page.orientation,
27
+ margin: [0, 0, 0, 0],
28
+ printQuantity: page.printQuantity || job.totalQuantity || 1,
29
+ horizontalOffset: 0,
30
+ verticalOffset: 0,
31
+ width: page.width,
32
+ height: page.height,
33
+ printMultiple: job.printMultiple ?? 1,
34
+ epc: job.epc ?? "",
35
+ },
36
+ });
37
+ }
38
+ function bitmapFromPayload(description, width, height, payload) {
39
+ return {
40
+ width,
41
+ height,
42
+ description,
43
+ meta: payload,
44
+ };
45
+ }
46
+ function dimensionsFromInfo(info) {
47
+ try {
48
+ const parsed = JSON.parse(info);
49
+ const imageInfo = parsed.printerImageProcessingInfo;
50
+ const width = Number(imageInfo?.width ?? 0);
51
+ const height = Number(imageInfo?.height ?? 0);
52
+ return {
53
+ width: Number.isFinite(width) ? width : 0,
54
+ height: Number.isFinite(height) ? height : 0,
55
+ };
56
+ }
57
+ catch {
58
+ return { width: 0, height: 0 };
59
+ }
60
+ }
61
+ export class LabelBuilder {
62
+ constructor(unit = "mm") {
63
+ this.job = {};
64
+ this.pages = [];
65
+ this.currentPage = null;
66
+ this.pageDefaults = null;
67
+ this.itemOrientation = 0;
68
+ this.itemHorizontalAlignment = ItemAlignment.LEFT;
69
+ this.itemVerticalAlignment = ItemAlignment.TOP;
70
+ this.itemPenAlignment = PenAlignment.CENTER;
71
+ this.unit = unit;
72
+ }
73
+ reset() {
74
+ this.job = {};
75
+ this.pages = [];
76
+ this.currentPage = null;
77
+ this.pageDefaults = null;
78
+ this.itemOrientation = 0;
79
+ this.itemHorizontalAlignment = ItemAlignment.LEFT;
80
+ this.itemVerticalAlignment = ItemAlignment.TOP;
81
+ this.itemPenAlignment = PenAlignment.CENTER;
82
+ }
83
+ startJob(density, paperType, printMode) {
84
+ this.pages = [];
85
+ this.currentPage = null;
86
+ this.pageDefaults = null;
87
+ this.job = {
88
+ ...this.job,
89
+ density,
90
+ paperType,
91
+ printMode,
92
+ pageUnit: this.unit,
93
+ };
94
+ }
95
+ abortJob() {
96
+ this.reset();
97
+ }
98
+ startPage() {
99
+ this.closePage();
100
+ this.openPage(this.pageDefaults ?? {
101
+ width: 0,
102
+ height: 0,
103
+ orientation: 0,
104
+ fonts: [],
105
+ background: 0xffffff,
106
+ printQuantity: this.job.totalQuantity ?? 1,
107
+ drawParams: {},
108
+ });
109
+ }
110
+ endPage() {
111
+ this.closePage();
112
+ }
113
+ endJob() {
114
+ this.closePage();
115
+ }
116
+ drawEmptyLabel(width, height, orientation, fonts) {
117
+ this.closePage();
118
+ this.openPage({
119
+ width,
120
+ height,
121
+ orientation,
122
+ fonts: normalizeFonts(fonts),
123
+ background: 0xffffff,
124
+ printQuantity: this.job.totalQuantity ?? 1,
125
+ drawParams: {},
126
+ });
127
+ this.pageDefaults = {
128
+ width,
129
+ height,
130
+ orientation,
131
+ fonts: normalizeFonts(fonts),
132
+ background: 0xffffff,
133
+ printQuantity: this.job.totalQuantity ?? 1,
134
+ drawParams: {},
135
+ };
136
+ }
137
+ drawLabelText(x, y, width, height, text, fontName, fontSize, options = {}) {
138
+ this.addCommand("drawLabelText", {
139
+ x,
140
+ y,
141
+ width,
142
+ height,
143
+ text,
144
+ fontName,
145
+ fontSize,
146
+ rotation: options.rotation ?? 0,
147
+ horizontalAlignment: options.horizontalAlignment ?? ItemAlignment.LEFT,
148
+ verticalAlignment: options.verticalAlignment ?? ItemAlignment.TOP,
149
+ mode: options.mode ?? 0,
150
+ indent: options.indent ?? 0,
151
+ scale: options.scale ?? 1,
152
+ flags: clone(options.flags ?? []),
153
+ unit: this.unit,
154
+ });
155
+ }
156
+ drawLabelBarCode(x, y, width, height, codeType, text, options = {}) {
157
+ this.addCommand("drawLabelBarCode", {
158
+ x,
159
+ y,
160
+ width,
161
+ height,
162
+ codeType,
163
+ text,
164
+ rotation: options.rotation ?? 0,
165
+ ratio: options.ratio ?? 1,
166
+ fontSize: options.fontSize ?? 0,
167
+ fontName: options.fontName ?? "",
168
+ showText: options.showText ?? true,
169
+ threshold: options.threshold ?? 0,
170
+ alignment: options.alignment ?? ItemAlignment.LEFT,
171
+ quietZone: options.quietZone ?? 0,
172
+ unit: this.unit,
173
+ });
174
+ }
175
+ drawLabelQrCode(x, y, width, height, text, options = {}) {
176
+ this.addCommand("drawLabelQrCode", {
177
+ x,
178
+ y,
179
+ width,
180
+ height,
181
+ text,
182
+ rotation: options.rotation ?? 0,
183
+ version: options.version ?? 0,
184
+ errorCorrectionLevel: options.errorCorrectionLevel ?? 0,
185
+ margin: options.margin ?? 0,
186
+ unit: this.unit,
187
+ });
188
+ }
189
+ drawLabelGraph(x, y, width, height, graphType, options = {}) {
190
+ this.addCommand("drawLabelGraph", {
191
+ x,
192
+ y,
193
+ width,
194
+ height,
195
+ graphType,
196
+ rotation: options.rotation ?? 0,
197
+ lineWidth: options.lineWidth ?? 1,
198
+ penAlignment: options.penAlignment ?? PenAlignment.CENTER,
199
+ dashPattern: clone(options.dashPattern ?? []),
200
+ unit: this.unit,
201
+ });
202
+ }
203
+ drawLabelImage(source, x, y, width, height, options = {}) {
204
+ this.addCommand("drawLabelImage", {
205
+ source,
206
+ x,
207
+ y,
208
+ width,
209
+ height,
210
+ rotation: options.rotation ?? 0,
211
+ threshold: options.threshold ?? 0,
212
+ scale: options.scale ?? 1,
213
+ actualSize: options.actualSize ?? false,
214
+ unit: this.unit,
215
+ });
216
+ }
217
+ drawLabelLine(x, y, width, height, options = {}) {
218
+ this.addCommand("drawLabelLine", {
219
+ x,
220
+ y,
221
+ width,
222
+ height,
223
+ rotation: options.rotation ?? 0,
224
+ lineWidth: options.lineWidth ?? 1,
225
+ penAlignment: options.penAlignment ?? PenAlignment.CENTER,
226
+ dashPattern: clone(options.dashPattern ?? []),
227
+ unit: this.unit,
228
+ });
229
+ }
230
+ setDrawParam(name, value) {
231
+ this.ensurePage();
232
+ this.currentPage.drawParams[name] = clone(value);
233
+ }
234
+ getItemOrientation() {
235
+ return this.itemOrientation;
236
+ }
237
+ setItemOrientation(value) {
238
+ this.itemOrientation = value;
239
+ }
240
+ getItemHorizontalAlignment() {
241
+ return this.itemHorizontalAlignment;
242
+ }
243
+ setItemHorizontalAlignment(value) {
244
+ this.itemHorizontalAlignment = value;
245
+ }
246
+ getItemVerticalAlignment() {
247
+ return this.itemVerticalAlignment;
248
+ }
249
+ setItemVerticalAlignment(value) {
250
+ this.itemVerticalAlignment = value;
251
+ }
252
+ getItemPenAlignment() {
253
+ return this.itemPenAlignment;
254
+ }
255
+ setItemPenAlignment(value) {
256
+ this.itemPenAlignment = value;
257
+ }
258
+ setBackground(color) {
259
+ this.ensurePage();
260
+ this.currentPage.background = color;
261
+ }
262
+ getPrintMultiple() {
263
+ return this.job.printMultiple ?? 1;
264
+ }
265
+ setTotalPrintQuantity(quantity) {
266
+ this.job.totalQuantity = quantity;
267
+ }
268
+ setTotalQuantityOfPrints(quantity) {
269
+ this.setTotalPrintQuantity(quantity);
270
+ }
271
+ getJobPages() {
272
+ const pages = this.currentPage
273
+ ? [...this.pages, clone(this.currentPage)]
274
+ : this.pages;
275
+ return clone(pages);
276
+ }
277
+ getCurrentPage() {
278
+ return this.currentPage ? clone(this.currentPage) : null;
279
+ }
280
+ toDocument() {
281
+ const pages = this.getJobPages();
282
+ return {
283
+ schema: "jc-printer-sdk-ts/print-document@1",
284
+ unit: this.unit,
285
+ job: clone(this.job),
286
+ pages,
287
+ };
288
+ }
289
+ serialize() {
290
+ return JSON.stringify(this.toDocument());
291
+ }
292
+ generateLabelJson() {
293
+ const page = this.currentPage ?? this.pages[this.pages.length - 1];
294
+ const serialized = page
295
+ ? JSON.stringify({
296
+ schema: "jc-printer-sdk-ts/page@1",
297
+ unit: this.unit,
298
+ job: clone(this.job),
299
+ page: clone(page),
300
+ })
301
+ : JSON.stringify({
302
+ schema: "jc-printer-sdk-ts/page@1",
303
+ unit: this.unit,
304
+ job: clone(this.job),
305
+ page: null,
306
+ });
307
+ return new TextEncoder().encode(serialized);
308
+ }
309
+ toCommitPayload() {
310
+ const pages = this.getJobPages();
311
+ return {
312
+ jsonPages: pages.map((page) => JSON.stringify({
313
+ schema: "jc-printer-sdk-ts/page@1",
314
+ unit: this.unit,
315
+ job: clone(this.job),
316
+ page,
317
+ })),
318
+ infoPages: pages.map((page) => buildInfoPage(page, this.job)),
319
+ };
320
+ }
321
+ commitImageData(orientation, bitmap, width, height, printQuantity, marginLeft, marginTop, marginRight, marginBottom, rfid) {
322
+ this.addCommand("commitImageData", {
323
+ orientation,
324
+ bitmap: clone(bitmap),
325
+ width,
326
+ height,
327
+ printQuantity,
328
+ marginLeft,
329
+ marginTop,
330
+ marginRight,
331
+ marginBottom,
332
+ rfid,
333
+ });
334
+ }
335
+ generatePreviewImage(json, info) {
336
+ const { width, height } = dimensionsFromInfo(info);
337
+ return bitmapFromPayload("preview", width, height, { json, info, unit: this.unit });
338
+ }
339
+ getMultiple() {
340
+ return this.getPrintMultiple();
341
+ }
342
+ measureFontHeight(text, x, y, width, height, rotation, fontSize) {
343
+ const lines = text.split(/\r?\n/).length;
344
+ const size = safeNumber(fontSize, 0);
345
+ return Math.max(size, Math.ceil(size * 1.2 * lines));
346
+ }
347
+ getStrPrintSize(text, fontStyle, fontSize) {
348
+ const lines = text.split(/\r?\n/);
349
+ const maxLine = lines.reduce((longest, line) => Math.max(longest, line.length), 0);
350
+ const width = Math.ceil(maxLine * fontSize * 0.6);
351
+ const height = Math.ceil(lines.length * fontSize * 1.2);
352
+ return { x: width, y: height };
353
+ }
354
+ getMin1DBarcode(text, codeType) {
355
+ return bitmapFromPayload("min-1d-barcode", 0, 0, { text, codeType });
356
+ }
357
+ getMin2DQRCode(text) {
358
+ return bitmapFromPayload("min-2d-qrcode", 0, 0, { text });
359
+ }
360
+ addLabelCommand(kind, payload) {
361
+ this.addCommand(kind, payload);
362
+ }
363
+ ensurePage() {
364
+ if (!this.currentPage) {
365
+ this.openPage(this.pageDefaults ?? {
366
+ width: 0,
367
+ height: 0,
368
+ orientation: 0,
369
+ fonts: [],
370
+ background: 0xffffff,
371
+ printQuantity: this.job.totalQuantity ?? 1,
372
+ drawParams: {},
373
+ });
374
+ }
375
+ }
376
+ openPage(options) {
377
+ this.currentPage = {
378
+ width: options.width,
379
+ height: options.height,
380
+ orientation: options.orientation,
381
+ fonts: clone(options.fonts ?? []),
382
+ background: options.background ?? 0xffffff,
383
+ printQuantity: options.printQuantity ?? this.job.totalQuantity ?? 1,
384
+ drawParams: clone(options.drawParams ?? {}),
385
+ commands: [],
386
+ };
387
+ }
388
+ closePage() {
389
+ if (!this.currentPage) {
390
+ return;
391
+ }
392
+ this.pages.push(clone(this.currentPage));
393
+ this.currentPage = null;
394
+ }
395
+ addCommand(kind, payload) {
396
+ this.ensurePage();
397
+ this.currentPage.commands.push(toCommand(kind, clone(payload)));
398
+ }
399
+ }
400
+ export function createLabelBuilder(unit = "mm") {
401
+ return new LabelBuilder(unit);
402
+ }
403
+ export function createAtBitmapDocument(job = {}) {
404
+ return {
405
+ schema: "jc-printer-sdk-ts/at-bitmap@1",
406
+ unit: "px",
407
+ job: clone(job),
408
+ pages: [],
409
+ };
410
+ }
411
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAmB7D,SAAS,KAAK,CAAI,KAAQ;IACxB,IAAI,OAAO,UAAU,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QACrD,OAAO,UAAU,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAM,CAAC;AAChD,CAAC;AAED,SAAS,cAAc,CAAC,KAAoC;IAC1D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9C,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,OAAgC;IAC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AAC,GAAG,CAAC;QACf,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { AddressType } from "./constants.js";
2
+ import { LabelBuilder } from "./builder.js";
3
+ import type { BitmapLike, BluetoothDeviceLike, BundleLike, IAtBitmapDocument, LabelBarcodeOptions, LabelGraphOptions, LabelImageOptions, LabelLineOptions, LabelQrCodeOptions, LabelTextOptions, MaybePromise, PaperInfo, PrintCallback, PrintDocument, PrinterSdkCallback, PrinterAddress, PrinterInfo, PrinterState, Point, ScanCallback } from "./types.js";
4
+ import type { PrinterTransport } from "./transport.js";
5
+ export declare function inferAddressType(code?: number): AddressType;
6
+ export declare function encodeAddressType(type: AddressType | undefined): number;
7
+ export declare function isBluetoothAddressType(type: AddressType | undefined): boolean;
8
+ export declare function createPrinterAddress(macAddress: string, addressType?: AddressType, shownName?: string): PrinterAddress;
9
+ export declare function createPrinterAddressFromDevice(device: BluetoothDeviceLike): PrinterAddress;
10
+ export declare function printerStateGroup(state: PrinterState): number;
11
+ export declare class PrinterClient {
12
+ readonly transport: PrinterTransport;
13
+ readonly builder: LabelBuilder;
14
+ private lastPrintCallback;
15
+ private sdkCallback;
16
+ private currentDocument;
17
+ private currentAtBitmap;
18
+ private pendingApplication;
19
+ constructor(transport?: PrinterTransport, sdkCallback?: PrinterSdkCallback);
20
+ getSdkVersion(): MaybePromise<string>;
21
+ init(application: unknown): MaybePromise<boolean>;
22
+ initSdk(application: unknown): MaybePromise<boolean>;
23
+ setSdkCallback(callback?: PrinterSdkCallback): void;
24
+ getSdkCallback(): PrinterSdkCallback | undefined;
25
+ initDefaultImageLibrarySettings(fontDirectory: string, extra?: string): MaybePromise<number>;
26
+ initImageProcessingDefault(fontDirectory: string, extra?: string): MaybePromise<number>;
27
+ openPrinterByAddress(address: string): MaybePromise<number>;
28
+ openPrinterSync(address: string): MaybePromise<number>;
29
+ connectBluetoothPrinter(address: string): MaybePromise<number>;
30
+ connectWifiPrinter(host: string, port: number): MaybePromise<number>;
31
+ configurationWifi(ssid: string, password: string): MaybePromise<number>;
32
+ getConfigurationWifiName(): MaybePromise<string>;
33
+ scanWifiPrinter(callback: ScanCallback): MaybePromise<void>;
34
+ setPrinterAutoShutdownTime(minutes: number): MaybePromise<number>;
35
+ setTotalPrintQuantity(quantity: number): MaybePromise<void>;
36
+ setTotalQuantityOfPrints(quantity: number): MaybePromise<void>;
37
+ startPrintJob(density: number, paperType: number, printMode: number, callback: PrintCallback): MaybePromise<void>;
38
+ commitData(jsonPages: string[], infoPages: string[]): MaybePromise<void>;
39
+ commitDocument(document: PrintDocument): MaybePromise<void>;
40
+ endJob(): MaybePromise<boolean>;
41
+ endPrintJob(): MaybePromise<boolean>;
42
+ cancelJob(): MaybePromise<boolean>;
43
+ cancel(): MaybePromise<void>;
44
+ reopenPrinter(): MaybePromise<boolean>;
45
+ reopenPrinterSync(): MaybePromise<boolean>;
46
+ close(): MaybePromise<void>;
47
+ quit(): MaybePromise<void>;
48
+ printBitmap(bitmap: BitmapLike, bundle?: BundleLike): MaybePromise<boolean>;
49
+ printATBitmap(bitmap: IAtBitmapDocument, bundle?: BundleLike): MaybePromise<boolean>;
50
+ getPaperInfo(): MaybePromise<PaperInfo | null>;
51
+ isConnection(): MaybePromise<number>;
52
+ getPrintScaleMultiplier(): MaybePromise<number>;
53
+ measureFontHeight(text: string, x: number, y: number, width: number, height: number, rotation: number, fontSize: number): MaybePromise<number>;
54
+ getStrPrintSize(text: string, fontStyle: number, fontSize: number): Point;
55
+ getMin1DBarcode(text: string, codeType: number): BitmapLike;
56
+ getMin2DQRCode(text: string): BitmapLike;
57
+ getPrinterName(): MaybePromise<string>;
58
+ getPrinterInfo(): MaybePromise<PrinterInfo | null>;
59
+ getPrinterState(): MaybePromise<PrinterState>;
60
+ waitPrinterState(state: PrinterState, timeoutMs: number): MaybePromise<boolean>;
61
+ drawEmptyLabel(width: number, height: number, orientation: number, fonts: string | string[]): void;
62
+ drawLabelText(x: number, y: number, width: number, height: number, text: string, fontName: string, fontSize: number, options?: LabelTextOptions): void;
63
+ drawLabelBarCode(x: number, y: number, width: number, height: number, codeType: number, text: string, options?: LabelBarcodeOptions): void;
64
+ drawLabelQrCode(x: number, y: number, width: number, height: number, text: string, options?: LabelQrCodeOptions): void;
65
+ drawLabelGraph(x: number, y: number, width: number, height: number, graphType: number, options?: LabelGraphOptions): void;
66
+ drawLabelImage(source: string | BitmapLike, x: number, y: number, width: number, height: number, options?: LabelImageOptions): void;
67
+ drawLabelLine(x: number, y: number, width: number, height: number, options?: LabelLineOptions): void;
68
+ generateLabelJson(): Uint8Array;
69
+ commitImageData(orientation: number, bitmap: BitmapLike, width: number, height: number, printQuantity: number, marginLeft: number, marginTop: number, marginRight: number, marginBottom: number, rfid: string): MaybePromise<void>;
70
+ generatePreviewImage(json: string, info: string): MaybePromise<BitmapLike>;
71
+ static generatePrintPreviewImage(json: string, widthMm: number, heightMm: number, orientation: number): BitmapLike;
72
+ getMultiple(): MaybePromise<number>;
73
+ getDocument(): PrintDocument;
74
+ getLastCommittedDocument(): PrintDocument | null;
75
+ getLastCommittedAtBitmap(): IAtBitmapDocument | null;
76
+ createAtBitmapDocument(job?: PrintDocument["job"]): IAtBitmapDocument;
77
+ createLabelBuilder(): LabelBuilder;
78
+ getPendingApplication(): unknown;
79
+ }
80
+ export declare class JCPrintApi extends PrinterClient {
81
+ private static instance?;
82
+ static getInstance(callback?: PrinterSdkCallback, transport?: PrinterTransport): JCPrintApi;
83
+ }
84
+ export declare function createPrinterClient(transport?: PrinterTransport, sdkCallback?: PrinterSdkCallback): PrinterClient;
85
+ //# sourceMappingURL=client.d.ts.map