@bobfrankston/brother-label 1.0.14 → 1.1.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/README.md CHANGED
@@ -61,21 +61,35 @@ brother-print config -p "Brother PT-P710BT" # Set default printer
61
61
  brother-print list # List Brother printers
62
62
  ```
63
63
 
64
+ ### Print clipboard contents
65
+ ```bash
66
+ brother-print -clip # auto-detect: image if present, else text
67
+ ```
68
+
64
69
  ### Options
65
70
  | Option | Description |
66
71
  |--------|-------------|
67
72
  | `-t, --text` | Force input as literal text; repeatable for multi-segment labels |
68
- | `-q, --qr` | QR code segment; repeatable for multi-segment labels |
69
- | `-s, --tape <size>` | Tape size: 6, 9, 12, 18, 24 (mm) |
73
+ | `-qr <data>` | QR code segment; repeatable for multi-segment labels |
74
+ | `-tape <size>` | Tape size: 6, 9, 12, 18, 24 (mm); auto-detected if omitted |
70
75
  | `-p, --printer <name>` | Printer name |
71
76
  | `-o, --output <file>` | Save to file instead of printing |
72
77
  | `-a, --aspect <ratio>` | Aspect ratio width:height for HTML (e.g., 3.5:2) |
73
78
  | `-H, --height <size>` | Text height: 12mm, .5in, or 50% (of tape height) |
79
+ | `-s, --space <size>` | Space between segments: 12px, 1mm, .2in |
74
80
  | `-w, --html` | Force input as HTML file path |
75
81
  | `-i, --image` | Force input as image file path |
82
+ | `-c, --clip` | Read content from clipboard (image preferred, then text) |
83
+ | `-no-wait` | Fail immediately if printer is offline (default: wait) |
84
+ | `-timeout <secs>` | Max wait time when printer is offline |
85
+ | `-interval <secs>` | Polling interval while waiting (default: 2) |
76
86
 
77
87
  Single-hyphen long options are supported: `-text` works the same as `--text`, `-tape` as `--tape`, etc. Single letters are strict: `-t` means `--text`, not the start of `-tape`.
78
88
 
89
+ ### Offline handling
90
+
91
+ By default `print()` waits for the printer to come online if it's asleep. Use `-no-wait` to fail immediately, or `-timeout <secs>` to bound the wait. Use `brother-print status` to check the current online state. The wait reports any other Brother printers that are online as alternatives.
92
+
79
93
  ## API Usage
80
94
 
81
95
  ### Print text
@@ -129,6 +143,35 @@ await print({ imagePath: "photo.png" });
129
143
  await print({ imageBuffer: fs.readFileSync("photo.png") });
130
144
  ```
131
145
 
146
+ ### Print clipboard contents
147
+ ```typescript
148
+ await print({ clip: true }); // image if present, else text
149
+ ```
150
+
151
+ ### Offline handling
152
+ ```typescript
153
+ await print({
154
+ text: "Hello",
155
+ onWaiting: (status, elapsedMs, alternatives) => {
156
+ console.log(`waiting on ${status.name} (${Math.floor(elapsedMs/1000)}s)`);
157
+ },
158
+ waitTimeoutMs: 60_000,
159
+ });
160
+
161
+ await print({ text: "Hello", wait: false }); // fail immediately if offline
162
+ ```
163
+
164
+ ### Cross-driver code
165
+ ```typescript
166
+ import type { LabelPrinter } from "@bobfrankston/label-core";
167
+ import { brotherPrinter } from "@bobfrankston/brother-label";
168
+ import { dymoPrinter } from "@bobfrankston/dymo-print";
169
+
170
+ async function printOn(p: LabelPrinter, text: string) {
171
+ await p.print({ text });
172
+ }
173
+ ```
174
+
132
175
  ### Configuration
133
176
  ```typescript
134
177
  import { getConfig, setConfig, listPrinters } from "@bobfrankston/brother-label";
package/api.d.ts CHANGED
@@ -1,9 +1,17 @@
1
1
  /**
2
2
  * Brother Label Printer API
3
- * Programmatic interface for printing labels on Brother P-touch printers
3
+ * Programmatic interface for printing labels on Brother P-touch printers.
4
+ *
5
+ * Implements the unified LabelPrinter interface from @bobfrankston/label-core.
6
+ * All printer-agnostic logic (rendering, segments, clipboard, CLI primitives,
7
+ * online-wait) lives in label-core. This file holds the Brother-specific bits:
8
+ * TAPE_SIZES catalog, MEDIA_OPTIONS (CustomMediaSize* names), XPS PrintTicket
9
+ * builder with the Brother namespace, and detectTapeSize.
4
10
  */
11
+ import { LabelPrinter, PrintOptions as CorePrintOptions, SegmentOptions as CoreSegmentOptions, Segment } from "@bobfrankston/label-core";
5
12
  export type TapeSize = 6 | 9 | 12 | 18 | 24;
6
13
  export type Orientation = "landscape" | "portrait";
14
+ /** Backward-compat: brother-label's config kept the `defaultTape` name. */
7
15
  export interface PrinterConfig {
8
16
  defaultTape?: TapeSize;
9
17
  defaultPrinter?: string;
@@ -11,41 +19,33 @@ export interface PrinterConfig {
11
19
  export interface PrinterInfo {
12
20
  name: string;
13
21
  }
14
- export interface PrintOptions {
15
- text?: string;
16
- html?: string;
17
- htmlPath?: string;
18
- textFile?: string;
19
- imagePath?: string;
20
- imageBuffer?: Buffer;
21
- qr?: string;
22
+ /** Brother-specific PrintOptions: same as core but with tape alias for media. */
23
+ export interface PrintOptions extends Omit<CorePrintOptions, "media"> {
24
+ tape?: TapeSize; /** Tape size in mm — alias for core.media */
25
+ orientation?: Orientation; /** Reserved (Brother PT prints landscape only) */
26
+ length?: number; /** Reserved — explicit length in mm */
27
+ }
28
+ export interface SegmentOptions extends Omit<CoreSegmentOptions, "media"> {
22
29
  tape?: TapeSize;
23
- printer?: string;
24
- orientation?: Orientation;
25
- length?: number;
26
- basePath?: string;
27
- aspect?: string;
28
- qrLabel?: string;
29
- textHeight?: string;
30
30
  }
31
31
  export interface PrintResult {
32
32
  image: Buffer;
33
33
  }
34
- export interface Segment {
35
- type: "text" | "qr";
36
- value: string;
37
- }
34
+ export type { Segment };
38
35
  export declare function getConfig(): PrinterConfig;
39
36
  export declare function setConfig(config: Partial<PrinterConfig>): void;
40
37
  export declare function getConfigPath(): string;
41
38
  export declare function listPrinters(): Promise<PrinterInfo[]>;
39
+ /**
40
+ * Auto-detect tape size from printer's default print ticket. Returns null if
41
+ * detection fails. Brother's driver embeds the loaded tape's CustomMediaSize
42
+ * name in the default PrintTicket XML.
43
+ */
44
+ export declare function detectTapeSize(printerName?: string): Promise<TapeSize>;
45
+ /** Public Brother singleton (implements LabelPrinter). */
46
+ export declare const brotherPrinter: LabelPrinter;
42
47
  export declare function render(options: PrintOptions): Promise<Buffer>;
43
48
  export declare function print(options: PrintOptions): Promise<PrintResult>;
44
49
  export declare function renderSegments(segments: Segment[], tape?: TapeSize, textHeight?: string, space?: string): Promise<Buffer>;
45
- export declare function printSegments(segments: Segment[], options?: {
46
- tape?: TapeSize;
47
- printer?: string;
48
- textHeight?: string;
49
- space?: string;
50
- }): Promise<PrintResult>;
50
+ export declare function printSegments(segments: Segment[], options?: SegmentOptions): Promise<PrintResult>;
51
51
  //# sourceMappingURL=api.d.ts.map
package/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAC5C,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC1B,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAEzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,CAAC;IAGZ,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW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