libniimai 0.5.0 → 0.7.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.
@@ -0,0 +1,54 @@
1
+ import type { ClientLike } from './client.js';
2
+ /**
3
+ * A client that picks the real client when it connects, then passes
4
+ * everything through to it: the Bluetooth and USB printers behind the
5
+ * Connect buttons.
6
+ */
7
+ export declare abstract class RoutedClient implements ClientLike {
8
+ protected inner: ClientLike | null;
9
+ abstract connect(): Promise<{
10
+ deviceName?: string;
11
+ }>;
12
+ protected get client(): ClientLike;
13
+ disconnect(): Promise<void>;
14
+ isConnected(): boolean;
15
+ on(event: string, fn: (e: any) => void): unknown;
16
+ off(event: string, fn: (e: any) => void): unknown;
17
+ getPrinterInfo(): {
18
+ batteryPercents?: number;
19
+ modelId?: number;
20
+ printheadWidth?: number;
21
+ protocolVersion?: number;
22
+ };
23
+ getModelMetadata(): import("@mmote/niimbluelib").PrinterModelMeta | undefined;
24
+ getPrintTaskType(): "B1" | "B21_L2B" | "B21_V1" | "D110" | "D110M_V4" | "D11_V1" | "H1S" | undefined;
25
+ getRfidInfo(): {
26
+ labelRfidInfo?: {
27
+ tagPresent?: boolean;
28
+ barCode?: string;
29
+ allPaper?: number;
30
+ usedPaper?: number;
31
+ consumablesType?: number;
32
+ };
33
+ paperInfo?: {
34
+ valid?: boolean;
35
+ paperWidth?: number;
36
+ paperHeight?: number;
37
+ paperType?: number;
38
+ };
39
+ };
40
+ fetchRfidInfo(): Promise<unknown>;
41
+ startHeartbeat(): void;
42
+ stopHeartbeat(): void;
43
+ isHeartbeatStarted(): boolean;
44
+ get protocol(): {
45
+ newPrintTask(name: import("@mmote/niimbluelib").PrintTaskName, options: Record<string, unknown>): import("./client.js").PrintTaskLike;
46
+ printEnd(): Promise<boolean>;
47
+ };
48
+ get encodePage(): ((canvas: HTMLCanvasElement) => unknown) | undefined;
49
+ get rollKey(): (() => string) | undefined;
50
+ get feedPaper(): ((dots: number) => Promise<void>) | undefined;
51
+ get headUnknown(): boolean | undefined;
52
+ get setHeadDots(): ((dots: number) => void) | undefined;
53
+ get feedsBack(): boolean | undefined;
54
+ }
package/dist/service.d.ts CHANGED
@@ -34,6 +34,10 @@ export interface PrinterStatus {
34
34
  canFeed?: boolean;
35
35
  /** `feed()` can also move the paper back. */
36
36
  canRetract?: boolean;
37
+ /** The head's width is a guess: `setPrintWidth()` sets it, from the paper loaded. */
38
+ headUnknown?: boolean;
39
+ /** The printer was matched by its services, as this family: keep it with `rememberMatches()` so it skips the NIIMBOT handshake next time. */
40
+ matchedAs?: 'escpos' | 'cat';
37
41
  }
38
42
  /** Nudges the printed image, in mm: positive x moves right, positive y moves down. */
39
43
  export interface PrintOffset {
@@ -100,6 +104,14 @@ export declare class PrinterService {
100
104
  private set;
101
105
  /** Swaps the whole status, so fields from an earlier connection never linger. */
102
106
  private replace;
107
+ private matches;
108
+ /**
109
+ * Printers matched by their services on earlier connections, by Bluetooth
110
+ * name (from `status.matchedAs` and `status.deviceName`). They connect
111
+ * straight to that client, skipping the NIIMBOT handshake, whose bytes a
112
+ * receipt printer would print as text.
113
+ */
114
+ rememberMatches(matches: Record<string, 'escpos' | 'cat'>): void;
103
115
  setManualProfile(id: string | null): void;
104
116
  private currentProfile;
105
117
  private readRfid;
@@ -112,6 +124,11 @@ export declare class PrinterService {
112
124
  * already done. That task polls here instead.
113
125
  */
114
126
  private waitForFinished;
127
+ /**
128
+ * Sets the print width, in mm, on a printer whose head width is not known
129
+ * (`status.headUnknown`); the profile follows. Other printers keep theirs.
130
+ */
131
+ setPrintWidth(mm: number): void;
115
132
  /**
116
133
  * Moves the paper by `mm`, out of the printer when positive and back in when
117
134
  * negative, to line it up on printers that cannot sense it.
package/dist/thermal.d.ts CHANGED
@@ -23,6 +23,8 @@ export interface ThermalModel {
23
23
  brand?: string;
24
24
  /** Dots across the head, where it differs from the family's usual one: 576 on 80 mm receipt printers. */
25
25
  headDots?: number;
26
+ /** USB vendor and product IDs, for printers that also connect by cable as a standard USB printer. */
27
+ usbIds?: [vendorId: number, productId: number][];
26
28
  }
27
29
  /** The name a printer shows: its model, or its own Bluetooth name when the model entry is only a brand or a stock name. */
28
30
  export declare const shownName: (model: ThermalModel | null, transport: {
@@ -39,9 +41,11 @@ export declare const THERMAL_DEFAULT_SIZE: LabelSize;
39
41
  * the highest.
40
42
  */
41
43
  export declare function packRows(data: ArrayLike<number>, width: number, height: number, order: 'lsb' | 'msb', head?: number): Uint8Array[];
42
- /** The Bluetooth link, kept narrow so tests can stand in for it. */
44
+ /** The Bluetooth or USB link, kept narrow so tests can stand in for it. */
43
45
  export interface ThermalTransport {
44
46
  name?: string;
47
+ /** Bytes per write, for links that take more than Bluetooth's cautious start. */
48
+ chunkBytes?: number;
45
49
  write(chunk: Uint8Array): Promise<void>;
46
50
  onNotify(fn: (data: Uint8Array) => void): void;
47
51
  onDisconnect(fn: () => void): void;
package/dist/usb.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Label and receipt printers on a USB cable that show up as standard USB
3
+ * printers (interface class 7), which Web Serial cannot see. They take the
4
+ * same TSPL or ESC/POS bytes as over Bluetooth, through WebUSB. NIIMBOT
5
+ * printers show up as serial ports and keep using Web Serial.
6
+ */
7
+ import { type PrinterFamily } from './catalog.js';
8
+ import type { ThermalTransport } from './thermal.js';
9
+ import { RoutedClient } from './routed.js';
10
+ export declare const USB_PRINTER_CLASS = 7;
11
+ /**
12
+ * The fields of an IEEE 1284 device ID, keys in capitals:
13
+ * "MFG:ACME;COMMAND SET:TSC/ESC/POS;MODEL:CC390;" → { MFG, 'COMMAND SET', MODEL }.
14
+ */
15
+ export declare function parseDeviceId(text: string): Record<string, string>;
16
+ /** The printer languages a device ID names, TSPL first: label printers often take ESC/POS as well. */
17
+ export declare function familiesFromDeviceId(text: string): PrinterFamily[];
18
+ /** USB printers this site may already use that are plugged in. */
19
+ export declare function rememberedUsbPrinters(): Promise<USBDevice[]>;
20
+ /** Opens a USB printer and claims its printer interface. Also reads the printer's device ID. */
21
+ export declare function usbTransport(device: USBDevice): Promise<{
22
+ transport: ThermalTransport;
23
+ deviceId: string;
24
+ }>;
25
+ /**
26
+ * The USB printer behind the USB button for label and receipt printers. A
27
+ * printer this site already uses connects straight away when it is the only
28
+ * one plugged in; otherwise the browser lists USB printers. The printer's
29
+ * language comes from the catalog, then from the type picked under Advanced
30
+ * when the printer speaks it (or does not say), then from the device ID the
31
+ * printer reports.
32
+ */
33
+ export declare class UsbPrinter extends RoutedClient {
34
+ private fallback;
35
+ unrecognisedAs(typeId: string | null): void;
36
+ connect(): Promise<{
37
+ deviceName?: string;
38
+ }>;
39
+ }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "libniimai",
3
- "version": "0.5.0",
4
- "description": "Print to NIIMBOT, TSPL, ESC/POS and cat printers from the browser over Web Bluetooth and Web Serial.",
3
+ "version": "0.7.0",
4
+ "description": "Print to NIIMBOT, TSPL, ESC/POS and cat printers from the browser over Web Bluetooth, Web Serial and WebUSB.",
5
5
  "keywords": [
6
6
  "niimbot",
7
7
  "label printer",
8
8
  "thermal printer",
9
9
  "web bluetooth",
10
10
  "web serial",
11
+ "webusb",
11
12
  "tspl",
12
13
  "esc/pos",
13
14
  "cat printer"
@@ -47,6 +48,7 @@
47
48
  "dependencies": {
48
49
  "@mmote/niimbluelib": "^0.48.0",
49
50
  "@types/w3c-web-serial": "^1.0.8",
51
+ "@types/w3c-web-usb": "^1.0.10",
50
52
  "@types/web-bluetooth": "^0.0.22"
51
53
  }
52
54
  }