# Vanilla WebGPU & Mini3 Reference (`ultra-text/vanilla` and `ultra-text/slug-vanilla`) Both vanilla entry points run DOM capture, Pretext/Range layout, `reflow()`, observers, and GPU preprocessing with **zero Three.js dependency** and **zero `@webgpu/types` dependency** (structural `GPUDevice` / `GPUTexture` / `GPUBuffer` interfaces). ## SDF controller (`ultra-text/vanilla`) Note the argument order: `DomText.create(element, gpuDevice, options)` takes the HTML element **first** and the `GPUDevice` (or `{ device }` object) **second**. ```ts import { DomText } from 'ultra-text/vanilla' await document.fonts.ready const source = document.querySelector('#card')! const domText = await DomText.create(source, gpuDevice, { quality: 'high', reflowable: true, onChange(instance, reason) { // reason: 'create' | 'rebuild' | 'reflow' | 'motion' | 'dispose' // instance.glyphs -> VanillaGlyphInstances (positions, uvs, colors, sdfParams, ...) // instance.plainRects -> VanillaRectInstances | null // instance.litRects -> VanillaRectInstances | null // instance.decorations -> VanillaDecorationInstances | null // instance.atlas -> VanillaSdfAtlas (gpuTexture on GPU, data Uint8Array on CPU) }, }) // Fast width-only relayout: fires onChange(instance, 'reflow') domText.reflow(560) // Cleanup: domText.dispose() ``` - **String helper**: `Text` (`VanillaText`) supports `await Text.create('Hello', { device: gpuDevice, css, cssClass, onChange })` as well as `setText()`, `setCss()`, and `setClass()`. - **Lower-level exports**: `collectDomSnapshot`, `reflowSnapshot`, `buildVanillaSdfAtlas` (`buildSdfAtlas`), `buildVanillaGpuSdfAtlas`, `buildVanillaCpuSdfAtlas`, `rasterizeGlyphAtlas`, `packGlyphInstances`, `updateGlyphInstances`, `updateGlyphContentInstances`, `packRectInstances`, `updateRectInstances`, `packDecorationInstances`, `updateDecorationInstances`, `computeInstanceBounds`, `resolveDomTextTone`, `UNIT_QUAD_POSITIONS`, `UNIT_QUAD_NORMALS`, `UNIT_QUAD_INDICES`. ## Pure Slug WebGPU pipeline (`ultra-text/slug-vanilla`) `ultra-text/slug-vanilla` omits all SDF/JFA/CPU-EDT code and ships `SLUG_WGSL`, `createVanillaSlugPipeline`, and `uploadSlugGlyphBuffers` for immediate rendering in any raw `GPURenderPassEncoder`: ```ts import { createVanillaSlugPipeline, DomSlug, uploadSlugGlyphBuffers, type VanillaSlugGpuInstances, } from 'ultra-text/slug-vanilla' await document.fonts.ready const pipeline = createVanillaSlugPipeline(gpuDevice, { format: navigator.gpu.getPreferredCanvasFormat(), depthFormat: 'depth24plus', // optional }) let gpuInstances: VanillaSlugGpuInstances | null = null let bindGroup: unknown = null const domSlug = await DomSlug.create(source, gpuDevice, { // Optional: outlineProvider: createTrueTypeOutlineProvider(ttfBuffer) onChange(instance, reason) { if (reason === 'dispose') { gpuInstances?.dispose() gpuInstances = null bindGroup = null return } bindGroup = pipeline.createBindGroup(instance.atlas) if (!gpuInstances) { gpuInstances = uploadSlugGlyphBuffers(gpuDevice, instance.glyphs) } else { gpuInstances.update(instance.glyphs) } }, }) // Inside render pass: pipeline.writeUniforms({ mvp, // column-major 4x4 Float32Array viewportWidth: canvas.width, viewportHeight: canvas.height, }) if (bindGroup && gpuInstances) { pipeline.draw(pass, bindGroup, gpuInstances) // calls pass.draw(6, gpuInstances.count) } // Cleanup: domSlug.dispose() pipeline.dispose() ``` - **Buffer caution on rebuilds**: `gpuInstances.update(next)` calls `writeBuffer` into the existing vertex buffers; if a rebuild increases glyph capacity beyond the initial buffer sizes, recreate `gpuInstances = uploadSlugGlyphBuffers(gpuDevice, next)` after disposing the old one. - **Standalone lower-level Slug exports**: `buildVanillaSlugAtlas` (`buildSlugAtlas`), `packSlugGlyphInstances`, `updateSlugGlyphInstances`, `preprocessSlugGlyphs`, `createTrueTypeOutlineProvider`, `parseTrueTypeFont`, `createTracedOutlineProvider`, `createSvgEmojiOutlineProvider`, `svgToWindfoilOutlines`, `windfoilOutlineFromSvgPaths`, `SLUG_WGSL`.