typst_flutter 2.2.0
typst_flutter: ^2.2.0 copied to clipboard
Embed the Typst typesetting compiler natively in Flutter via Rust FFI. Compile Typst markup to PDF or rendered images on all platforms except web — no WASM, no server required.
2.2.0 #
Engine Upgrade #
- Typst 0.15.0: Upgraded the underlying Typst compiler engine to 0.15.0. This brings variable font support, improved diagnostics, and many layout refinements. All Typst sub-crates (
typst-pdf,typst-render,typst-svg,typst-layout,typst-utils) are updated in lockstep.
New Features & Optimizations #
- Shared Compiler Architecture: Added
TypstCompilerProvider, anInheritedWidgetthat allowsTypstViewandTypstDocumentViewerwidgets to seamlessly discover and reuse a globally shared Rust engine instance. This eliminates thread spawning and font decoding overhead, reducing multi-widget rendering latency from ~200ms to 0ms. - Data Extraction: Added
TypstCompiler.query()to extract JSON metadata and document structure programmatically using Typst selectors (e.g.,<heading>). - Variable Injection: Added
sys.inputssupport toTypstCompiler.compile(). You can now pass aMap<String, String>from Dart directly into the Typst#sys.inputsdictionary, safely injecting theme data, usernames, or configuration flags into your documents. - Enabled Thin LTO: Release builds now use
lto = "thin"for cross-crate link-time optimization, yielding ~5-15% smaller native binaries without major compile-time impact.
2.1.0 #
Optimizations & API Refinements #
- Synchronous Metadata API:
TypstDocument.pageCount,TypstDocument.pageInfo(), andTypstCompiler.compilerVersionare now fully synchronous. By leveragingflutter_rust_bridgev2's#[frb(sync)]feature, these lightweight calls execute instantly on the main thread, eliminatingFutureoverhead and preventing UI layout jumps during rendering. - Dynamic Versioning: The Rust build script now dynamically extracts the exact
typstcrate version fromCargo.toml.compilerVersionwill always be perfectly accurate without manual updates. - Robust Date Handling: The Rust
SimpleWorldenvironment now gracefully falls back to the native OS system time (std::time::SystemTime::now()) if no date is provided from Dart. This means callingcompile()without adateparameter will no longer crash when evaluating#datetime.today()in Typst markup.
Documentation #
- 100% API Hover Docs: Every public class, method, and field in the Dart API now has extensive documentation comments (
///), providing a premium developer experience in IDEs. - Bundled Fonts Documented: The built-in core fonts (
Libertinus Serif,DejaVu Sans Mono, andNewCM Math) are now explicitly documented in the API so developers know what's available out-of-the-box.
2.0.0 #
⚠️ Breaking Changes #
-
TypstDocumentis now an opaque document handle. The oldTypstDocument(with.pdf,.svgs,.imageForPage()) has been replaced with a lightweight handle wrapping the compiled document in Rust memory. Rendering and export are now lazy — calldoc.exportPdf(),doc.renderSvg(pageIndex), ordoc.renderRaster(pageIndex: i)on demand. -
compile()now returnsTypstDocument(the opaque handle), not a container holding pre-generated PDF bytes. Calldoc.exportPdf()to get theUint8List. -
Removed
compileDocument()/renderCachedPage()/renderCachedPageAsSvg(). These implicit shared-state APIs are gone. Usecompile()→TypstDocument→renderRaster()/renderSvg()instead. EachTypstDocumentis independent. -
Removed
compileSvg()— Usecompile()thendoc.renderSvg(pageIndex)per page. -
Removed
renderPage()/renderPageAsPng()— Usecompile()thendoc.renderRaster()or callresult.toPng()for PNG bytes. -
Removed
TypstSvgViewwidget. UseTypstViewwithrenderMode: TypstRenderMode.svginstead. -
Removed
PdfDocument,SvgDocument,RasterDocumentsealed class hierarchy. All compilation now returnsTypstDocument. -
TypstDocumentViewerreplacesuseSvg: boolwithrenderMode: TypstRenderMode. -
errorBuildersignature changed fromObjecttoTypstCompileException.
Migration Guide #
// ── Before (1.x) ──────────────────────────────────────────
// PDF
final doc = await compiler.compile(source: markup);
final pdf = doc.pdf; // Uint8List directly
// Raster
final result = await compiler.renderPage(source: markup);
final image = await result.toImage();
// SVG
final doc = await compiler.compileSvg(source: markup);
final svgs = doc.svgs;
// Multi-page (implicit state — race condition prone)
final count = await compiler.compileDocument(source: markup);
final svg = await compiler.renderCachedPageAsSvg(pageIndex: 0);
// ── After (2.0) ───────────────────────────────────────────
// PDF
final doc = await compiler.compile(source: markup);
final pdf = await doc.exportPdf();
// Raster
final doc = await compiler.compile(source: markup);
final result = await doc.renderRaster(pageIndex: 0);
final image = await result.toImage();
// SVG
final doc = await compiler.compile(source: markup);
final svg = await doc.renderSvg(0);
// Multi-page (safe — each doc is independent)
final doc = await compiler.compile(source: markup);
for (var i = 0; i < doc.pageCount; i++) {
final svg = await doc.renderSvg(i);
}
// Don't forget to dispose when done!
doc.dispose();
New Features #
-
TypstDocument.dispose()— Explicit lifecycle management for the native Rust document handle. Callingdispose()eagerly frees the underlyingPagedDocumentmemory (which can be several MB). Use-after-dispose throwsStateError. Safe to call multiple times. -
TypstDocument.pageInfo(int pageIndex)— Query page dimensions in points without rendering. -
TypstViewdual constructor pattern:TypstView(document: doc)— renders from a pre-compiled document (shared compiler).TypstView.source(source: markup)— self-manages compilation (convenience).
-
TypstDocumentViewer.document()constructor — Accepts a pre-compiledTypstDocument, avoiding per-widget compiler creation. -
TypstRenderModeenum (svg,raster) — Replaces the fragileuseSvg: boolflag onTypstDocumentViewer. -
@internalannotation onFontSource.load()— Prevents users from calling the internal font loading method directly.
Fixes #
-
Fixed image leak in
TypstRenderResult.toPng()— The method now creates a temporary image and disposes it immediately if no cached image exists, preventing nativeui.Imageleaks whendispose()is never called. -
Fixed missing
dispose()in widget lifecycle —TypstViewandTypstDocumentViewernow properly dispose their ownedTypstCompilerinstances inState.dispose()and when fonts change indidUpdateWidget. -
Fixed implicit shared mutable state —
compileDocument()returned an int and stored the document in the Rust engine. Concurrent callers could silently clobber each other's documents. The newTypstDocumenthandle eliminates this entirely.
Internal #
TypstCompiler._engineis now private (wasenginepublic).TypstCompilerimplementsFinalizable.- Typed
TypstCompileExceptionused throughout (wasObjectin error handlers). - Added
prefer_expression_function_bodieslint rule. - Added
metadependency for@internalannotation. - Updated
.pubignoreto exclude internal files from pub.dev.
1.1.1 #
- Feature: Truly Zero-Configuration native setup! Android and iOS builds now automatically execute
typst_flutter:setupon the fly to download native binaries. No manual commands required. - Fix: Fixed a severe path-parsing bug on Windows where
setup.dartcrashed with aPathNotFoundExceptionwhile writing macOS binaries. - Fix: Safely fall back to
cargokitcompilation if auto-downloads fail or the user is strictly offline.
1.1.0 #
- New:
TypstDocumentViewerwidget for efficiently displaying multi-page documents with lazy rendering. - New:
TypstSvgViewwidget for crisp, scalable vector graphics rendering (SVG) at any zoom level. (Removed in 2.0.0 — useTypstViewwithTypstRenderMode.svg) - New: Structured Error Diagnostics via
TypstCompileException.diagnostics. Errors now include severity, exact messages, and hints. - New: Date Injection. You can now pass a
DateTimeinto the compiler to provide the date for#datetime.today(). - New: Support for rendering single pages directly to PNG bytes entirely in Rust (no Flutter UI thread or GPU roundtrip needed) via
renderPageAsPng.
1.0.1 #
- Fix CI/CD publishing pipeline
- Initial stable release
1.0.0 #
- Initial stable release.
- Added
TypstCompilerfor native PDF compilation. - Added
TypstViewwidget for live preview rendering. - Support for passing images and custom fonts via virtual files (
FileSource,FontSource). - Zero-Rust install workflow via
dart run typst_flutter:setupusing pre-built binaries. - Full cross-platform support: Android, iOS, macOS, Windows, Linux.