@bobfrankston/brother-label 1.0.13 → 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
@@ -35,6 +35,14 @@ Use `<img qr="data">` to embed QR codes directly in HTML - they're converted to
35
35
  <img qr="any data here" class="my-qr">
36
36
  ```
37
37
 
38
+ ### Multi-segment labels
39
+ Combine multiple `-text` and `-qr` segments on a single label, printed side-by-side in order:
40
+ ```bash
41
+ brother-print -text "Hello" -qr "https://example.com"
42
+ brother-print -text "Top\nBottom" -qr "https://example.com" -text "More text"
43
+ brother-print -t "Label" -q "data" -o combined.png
44
+ ```
45
+
38
46
  ### Print image
39
47
  ```bash
40
48
  brother-print image photo.png
@@ -48,18 +56,39 @@ brother-print preview "Test Label" -o preview.png
48
56
  ### Configuration
49
57
  ```bash
50
58
  brother-print config --show # Show current config
51
- brother-print config -t 12mm # Set default tape size
59
+ brother-print config -s 12 # Set default tape size
52
60
  brother-print config -p "Brother PT-P710BT" # Set default printer
53
61
  brother-print list # List Brother printers
54
62
  ```
55
63
 
64
+ ### Print clipboard contents
65
+ ```bash
66
+ brother-print -clip # auto-detect: image if present, else text
67
+ ```
68
+
56
69
  ### Options
57
70
  | Option | Description |
58
71
  |--------|-------------|
72
+ | `-t, --text` | Force input as literal text; repeatable for multi-segment labels |
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 |
59
75
  | `-p, --printer <name>` | Printer name |
60
- | `-t, --tape <size>` | Tape size: 6mm, 9mm, 12mm, 18mm, 24mm, or 'auto' |
61
- | `-l, --label <text>` | Text label beside QR code (qr command only) |
62
76
  | `-o, --output <file>` | Save to file instead of printing |
77
+ | `-a, --aspect <ratio>` | Aspect ratio width:height for HTML (e.g., 3.5:2) |
78
+ | `-H, --height <size>` | Text height: 12mm, .5in, or 50% (of tape height) |
79
+ | `-s, --space <size>` | Space between segments: 12px, 1mm, .2in |
80
+ | `-w, --html` | Force input as HTML file path |
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) |
86
+
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`.
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.
63
92
 
64
93
  ## API Usage
65
94
 
@@ -114,6 +143,35 @@ await print({ imagePath: "photo.png" });
114
143
  await print({ imageBuffer: fs.readFileSync("photo.png") });
115
144
  ```
116
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
+
117
175
  ### Configuration
118
176
  ```typescript
119
177
  import { getConfig, setConfig, listPrinters } from "@bobfrankston/brother-label";
@@ -175,6 +233,8 @@ interface PrintResult {
175
233
  |----------|-------------|
176
234
  | `print(options)` | Render and print a label |
177
235
  | `render(options)` | Render label to PNG buffer |
236
+ | `renderSegments(segments, tape?, textHeight?)` | Render multiple text/qr segments side-by-side |
237
+ | `printSegments(segments, options?)` | Render and print multiple segments |
178
238
  | `getConfig()` | Get current configuration |
179
239
  | `setConfig(config)` | Set default tape/printer |
180
240
  | `getConfigPath()` | Get config file path |
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,30 +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 type { Segment };
34
35
  export declare function getConfig(): PrinterConfig;
35
36
  export declare function setConfig(config: Partial<PrinterConfig>): void;
36
37
  export declare function getConfigPath(): string;
37
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;
38
47
  export declare function render(options: PrintOptions): Promise<Buffer>;
39
48
  export declare function print(options: PrintOptions): Promise<PrintResult>;
49
+ export declare function renderSegments(segments: Segment[], tape?: TapeSize, textHeight?: string, space?: string): Promise<Buffer>;
50
+ export declare function printSegments(segments: Segment[], options?: SegmentOptions): Promise<PrintResult>;
40
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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