Skip to content
QuaLix
On this page

TypeScript & WebAssembly guide

Decode QLX streams in browser canvases, <video> elements, OPFS Web Workers, and Node.js using @quajs/qualix.

@quajs/qualix embeds the compiled qualix-ffi WebAssembly decoder inline, requiring zero external .wasm asset hosting across browsers, Web Workers, Vite, and Node.js.

Zero-WASM header inspection

Before allocating a decoder or inside lightweight metadata extractors (such as Quack asset scanners or QuickJS realms), inspect the 32-byte QLX header via @quajs/qualix/header:

TypeScript
import { inspectQuaLix, isQuaLix, QLX_MIME_TYPE } from '@quajs/qualix/header'if (isQuaLix(bytes)) { const info = inspectQuaLix(bytes) console.log(`${QLX_MIME_TYPE}: ${info.width}x${info.height}, ${info.frames}f @ ${info.fps} fps, ${info.color}`)}

Browser <canvas> and <video> playback

@quajs/qualix/web provides two ergonomic browser adapters:

  1. QuaLixCanvasPlayer: Drives an HTMLCanvasElement directly, uploading only changed row bands [firstRow, endRow) via putImageData after the first frame and automatically pausing ticks when offscreen or backgrounded.
  2. attachQuaLixToVideoElement: Mounts .qlx WASM decoding onto a standard <video> element (exposing videoWidth, videoHeight, duration, currentTime, loop, playbackRate, ended/error events, and captureStream() / __quaQualixCanvas access for masks and transitions).
TypeScript
import { QuaLixCanvasPlayer, attachQuaLixToVideoElement } from '@quajs/qualix/web'const player = await QuaLixCanvasPlayer.create(canvas, qlxBytes, { loop: true, pauseWhenHidden: true,})// Or drive an existing <video> element seamlessly:const handle = await attachQuaLixToVideoElement(videoElement, qlxBytes)

Streaming range reader in Web Workers

Large cutscenes do not need to reside wholly inside WASM linear memory. Inside a Dedicated Worker, pair openReader(size, readAt, budget) with OPFS FileSystemSyncAccessHandle:

TypeScript
import { loadQuaLixRuntime, QLX_DEFAULT_BUDGET } from '@quajs/qualix'const runtime = await loadQuaLixRuntime()const access = await fileHandle.createSyncAccessHandle()try { const clip = runtime.openReader(memberLength, (offset, target) => access.read(target, { at: memberOffset + offset }), QLX_DEFAULT_BUDGET) try { const frame = clip.decode(frameNumber) // frame.pixels aliases WASM linear memory until the next decode() or close() uploadRgbaTexture(frame.pixels, clip.info.width, clip.info.height, frame.firstRow, frame.endRow) } finally { clip.close() }} finally { access.close()}

[!NOTE] The 64 KiB internal read buffer is accounted inside budget. Do not re-enter the same runtime synchronously inside readAt. Call frame.toRgba8() to preview 10-bit pq10 / hlg10 streams on 8-bit SDR canvases.