API

@zplkit/preview

The <zpl-preview> element, its events and configure().

import "@zplkit/preview";
import { configure } from "@zplkit/preview";

Preview shows how to use it in each framework.

<zpl-preview>

Attribute or propertyTypeDefaultDescription
zplstring, or anything with toZPL()The ZPL to show. Only the property takes a Label.
width, heightnumber^PW and ^LL, else 4 × 6 inLabel size in millimeters
dpmmnumber8Dots per millimeter: 6, 8, 12 or 24
smoothingnumber0.4Edge smoothing, from 0 (the printer's exact dots) to 1 (fully anti-aliased)
max-labels, maxLabelsnumber20Labels to show; past that, a line says how many more there are
fadebooleanfalseFade labels in when they first appear, over --zpl-fade-duration (200 ms)

The images are styled with ::part(label), their container with ::part(labels) and the error message with ::part(error). Each image is in a ::part(item), with copies printed with ^PQ marked in ::part(copies), and the line about more labels is ::part(more).

Events

zpl-render-start

PropertyTypeDescription
zplstring

zpl-render

PropertyTypeDescription
imagesstring[]
copiesnumber[]

How many times each label prints in a row, from ^PQ

labels?number

Different labels and labels printed in all, with the default renderer. More than images when there are more than max-labels.

printed?number
widthnumber

Label width and height in millimeters

heightnumber
dpmmnumber
durationnumber

Milliseconds from the start of the render to the images

zpl-error

PropertyTypeDescription
errorError

configure

configure(options: ConfigureOptions): void

Changes how every preview on the page renders.

PropertyTypeDefaultDescription
render?RenderrenderZpl from

Use your own renderer, for example one that calls an API

A renderer is a function (zpl, options) => Promise<string[]> that returns one base64-encoded PNG per label. It's called with:

PropertyTypeDescription
widthMmnumber

Label width in millimeters

heightMmnumber

Label height in millimeters

dpmmnumber

Dots per millimeter: 6, 8, 12 or 24

grayscaleboolean

Anti-aliased 8-bit output instead of the printer's 1-bit dots

fonts?Record<string, Uint8Array<ArrayBufferLike>>

Fonts already on the printer, by path like "E:ARIAL.TTF"

font0?Uint8Array<ArrayBufferLike>

A font file to draw font 0 with instead of the open-licensed stand-in

limit?number

Render only the first labels; a renderer may render all of them

React

import "@zplkit/preview/react" registers the element and adds its props to React's JSX types, including onzpl-render-start, onzpl-render and onzpl-error. Its props type is exported as ZplPreviewProps.