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:
TypeScriptimport { 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:
QuaLixCanvasPlayer: Drives anHTMLCanvasElementdirectly, uploading only changed row bands[firstRow, endRow)viaputImageDataafter the first frame and automatically pausing ticks when offscreen or backgrounded.attachQuaLixToVideoElement: Mounts.qlxWASM decoding onto a standard<video>element (exposingvideoWidth,videoHeight,duration,currentTime,loop,playbackRate,ended/errorevents, andcaptureStream()/__quaQualixCanvasaccess for masks and transitions).
TypeScriptimport { 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:
TypeScriptimport { 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 insidereadAt. Callframe.toRgba8()to preview 10-bitpq10/hlg10streams on 8-bit SDR canvases.