Browser and bundlers
In a browser, @lamina/pdf resolves through its browser export condition. The glue finds each .wasm file with new URL("…", import.meta.url), so your bundler emits the files as assets next to your code, and they load from your own origin.
This app is bundled by Vite and run in Chromium in CI (packages/pdf/test/vite.test.ts). It loads the base module, opens a document, then loads the text module and builds a page:
// A browser app using @lamina/pdf, bundled by test/vite.test.ts.import { Builder, Document, Font, init, loadText } from "@lamina/pdf";
/** Opens `bytes`, then builds a page of text: both modules, loaded the way a page would. */export async function run(bytes: Uint8Array): Promise<readonly [number, number]> { await init(); const pages = Document.open(bytes).pageCount; await loadText(); const b = new Builder(); const page = b.page("A6"); page.surface().text("Hi", { font: Font.standard("Helvetica"), size: 9, at: [9, 20] }); page.finish(); return [pages, Document.open(b.finish().save()).pageCount];}- Two modules, loaded on demand.
init()loads the base module (open, edit, save, vector pages).loadText()(orinit({ text: true })) adds fonts and text. A page that never draws text never downloads the text module. - Vite: exclude the package from dependency pre-bundling (
optimizeDeps.exclude: ["@lamina/pdf"]invite.config.ts), so the.wasmURLs stay next to the glue. - Content Security Policy: compiling WebAssembly needs
script-src 'wasm-unsafe-eval'. Nothing else is needed.
Next: draw text with fonts, or open and edit a file.