# Lidta DRP Plugin

Lidta Direct Print is a JavaScript SDK for printing HTML to local printers through the Lidta browser extension and native desktop app.

## Install

```bash
npm install lidta-drp
```

```html
<script src="https://cdn.jsdelivr.net/npm/lidta-drp/dist/lidta-drp.umd.js"></script>
```

## Quick Start

```js
import { waitUntilReady, getPrinters, printHtml } from 'lidta-drp';

await waitUntilReady();

const printers = await getPrinters();

await printHtml({
  html: '<h1>Receipt #123</h1>',
  printers: [printers[0].name]
});
```

`printHtml` also accepts printer objects returned by `getPrinters()`:

```js
await printHtml('<h1>Receipt #123</h1>', [printers[0]]);
```

## Printer Configuration

Configuration UI belongs to your web app. Storage stays inside the Lidta app.

```js
import {
  getPrinterConfig,
  getAllPrinterConfigs,
  savePrinterConfig
} from 'lidta-drp';

const config = await getPrinterConfig('POS-80');

config.options.width = '80';
config.options.height = '297';
config.options.copies = '1';

await savePrinterConfig(config);

const allConfigs = await getAllPrinterConfigs();
```

## API

| Method | Returns | Description |
| --- | --- | --- |
| `waitUntilReady()` | `Promise<ReadyResponse>` | Checks extension and native app connectivity. |
| `isReady()` | `Promise<boolean>` | Quick true/false readiness check. |
| `getPrinters()` | `Promise<PrinterInfo[]>` | Lists available printers with saved options merged in. |
| `getPrinterConfig(name)` | `Promise<PrinterInfo>` | Gets one printer configuration. |
| `getAllPrinterConfigs()` | `Promise<PrinterInfo[]>` | Gets all printer configurations. |
| `savePrinterConfig(printer)` | `Promise<SavePrinterConfigResponse>` | Saves printer options in the native app. |
| `configurePrinter(name)` | `Promise<PrinterInfo>` | Compatibility alias for `getPrinterConfig(name)`. |
| `printHtml({ html, printers })` | `Promise<PrintResponse>` | Prints HTML to the named printers. |
| `enableDebug()` | `() => void` | Logs Lidta bridge responses; returns an unsubscribe function. |
| `debug()` | `() => void` | Compatibility alias for `enableDebug()`. |

## Types

```ts
interface PrinterInfo {
  name: string;
  displayName: string;
  status?: string;
  description?: string;
  is_default?: boolean;
  options: {
    width: string;
    height: string;
    zoom: string;
    margin_top: string;
    margin_bottom: string;
    margin_left: string;
    margin_right: string;
    orientation: 'Portrait' | 'Landscape';
    copies: string;
  };
}
```

## Requirements

- Lidta desktop app installed and registered as a native messaging host.
- Lidta browser extension installed and enabled.
- Your page must run in a browser profile where the extension is available.
