libniimai 0.5.0 → 0.6.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 +9 -8
- package/dist/bluetooth.d.ts +2 -43
- package/dist/catalog.d.ts +21 -1
- package/dist/client.d.ts +9 -6
- package/dist/index.d.ts +7 -4
- package/dist/libniimai.js +246 -77
- package/dist/libniimai.js.map +1 -1
- package/dist/routed.d.ts +52 -0
- package/dist/thermal.d.ts +5 -1
- package/dist/usb.d.ts +39 -0
- package/package.json +4 -2
package/dist/routed.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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 feedsBack(): boolean | undefined;
|
|
52
|
+
}
|
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.
|
|
4
|
-
"description": "Print to NIIMBOT, TSPL, ESC/POS and cat printers from the browser over Web Bluetooth
|
|
3
|
+
"version": "0.6.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
|
}
|