Skip to content
SnapDOMGitHub★ 8K
@zumer/snapdom-plugins · MIT

Export the capture as JPEG XL.

Adds toJxl(), toBlob({ format: 'jxl' }) and download({ format: 'jxl' }). Text and interface stay exact while photos take the quality, in one JPEG XL file. The encoder is rapier-jxl (MIT), an optional peer: the text measurement loads at the first capture, the encoder at the first export.

npm install @zumer/snapdom@latest @zumer/snapdom-plugins@latest
npm install rapier-jxl

Usage

import { snapdom } from '@zumer/snapdom';
import { jxl } from '@zumer/snapdom-plugins/jxl';

const el = document.querySelector('#target');
const result = await snapdom(el, { plugins: [jxl()] });
const img = await result.toJxl({ quality: 0.8 });
const blob = await result.toBlob({ format: 'jxl' });
await result.download({ format: 'jxl', filename: 'card' });

Options

OptionTypeDefaultDescription
modulestring'rapier-jxl/capture-complete'With your codec: 'rapier-jxl/capture' (every pixel exact) or 'rapier-jxl/upload' (photographic)
codecobjectnoneYour own encoder with prepare and capture
decoderobjectnonecreateCodec() from rapier-jxl/codec/decode, for toJxl() where JPEG XL does not show
effortnumber3Default effort, 1-9
webgpufalse | 'required'noneDisable WebGPU, or require a device
helpersboolean | objectnoneHelper workers for the encoder the plugin creates

Exports take toWebp()'s options, plus effort, signal, onProgress (0 to 1) and onEncoded (once). quality: 1 is exact. The plugin's own encoder takes up to 40 megapixels; plugin.close() ends its workers.

Encoding works in every browser: toBlob() and download() give image/jxl. Where the browser cannot show JPEG XL (Edge, for one), toJxl() shows the decoder's pixels, or rejects with JXL_NOT_SHOWN without one.