# API Reference This directory is the public API entrypoint for `pressedslip`. ## Public entrypoints | Import path | Runtime | Use it for | |---|---|---| | `pressedslip` | Node | Render PNGs with the Node resvg-js renderer, define blocks, build registries, compose provider-backed compositions, load themes/fonts, and use the browser-safe provider primitives. | | `pressedslip/browser` | Browser | Render PNGs with resvg-wasm and use the browser-safe block, registry, theme, provider, and composition APIs without importing Node native modules. | | `pressedslip/providers` | Node | Node-oriented provider helpers: file cache, node font cache, OpenMeteo provider, and provider registry helpers. | | `pressedslip/transports` | Node | Delivery adapters: ESC/POS raster output, file transport, HTTP transport, and shared transport types. | | `pressedslip/testing` | Node or test runners | Builtin block fixtures and structural assertion helpers for downstream regression tests. | ## Common imports ```ts import { PAPER, builtinBlocks, createRegistry, loadThemeFonts, render, themes, } from "pressedslip"; ``` ```ts import { builtinBlocks, createRegistry, render, themes } from "pressedslip/browser"; ``` ```ts import { createFileCache, createOpenMeteoProvider } from "pressedslip/providers"; import { createEscPosTransport } from "pressedslip/transports"; import { assertNoFailedBlocks } from "pressedslip/testing"; ``` ## Local image inputs `imageBlock`, `ImageData`, and `imageFromBuffer` are available from both the root and `/browser` entrypoints. The helper accepts a `Uint8Array` (including a Node `Buffer`) and produces a base64 data URI after checking the payload and PNG header or SVG syntax and safety rules; it does not fetch or render an image. ```ts import { imageFromBuffer, type ImageData } from "pressedslip"; // Supply PNG bytes from your application. const imageData: ImageData = { layout: "column", images: [{ src: imageFromBuffer(bytes, "image/png"), alt: "Logo" }], }; ``` See the [image block reference](../blocks/image.md) for accepted formats and limits. `pressedslip/testing` exports `imageFixtures` and `builtinFixtures.image`. ## Image URL loading `imageFromUrl`, `ImageFromUrlOptions`, and `ImageCache` are exported from both `pressedslip` and `pressedslip/browser`. The asynchronous helper resolves HTTP(S) PNG/static-SVG bytes into a data URI before composition or rendering. It defaults to a 5000 ms request/body timeout and a 2 MiB streamed source cap. Optional injected fetch and raw-byte cache implementations are supported; no cache is used by default. ```ts import { imageFromUrl, memoryFontCache, type ImageCache, type ImageFromUrlOptions } from "pressedslip"; const cache: ImageCache = memoryFontCache(); const options: ImageFromUrlOptions = { cache, timeoutMs: 5000 }; const src = await imageFromUrl( "https://raw.githubusercontent.com/diegomarino/pressedslip/663028ea9ce813192efec798323b5cadd382fffd/docs/assets/visual-refs/block-image-tux.png", options, ); ``` See [URL limits and validation](../blocks/image.md#loading-a-url-before-rendering) and [complete provider wiring](../guide/providers.md#loading-an-image-url). Automatic URL resolution in JSON is deferred; image rendering stays network-free. ## Generated TypeDoc The complete symbol-by-symbol reference is generated from TSDoc-annotated source by [TypeDoc](https://typedoc.org/). Regenerate it locally: ```bash pnpm docs:api ``` The generated HTML lands in `docs/api/reference/` as a browsable site. Open `docs/api/reference/index.html` after running the command. Generated HTML is ignored by git; this `README.md` is the committed API overview. ## CI coverage API documentation is checked mechanically: - `pnpm docs:api` fails on TypeDoc warnings, undocumented public symbols, and invalid links. - `pnpm check-docs` enforces public TSDoc blocks and Markdown link health. - `pnpm check-public-docs` rejects stale public snippets, old package names, old render option names, and removed D2/SVG diagram references.