### Run setup script Source: https://pub.dev/packages/typst_flutter Fetch dependencies and run the required one-time setup to download native Rust binaries. ```bash flutter pub get dart run typst_flutter:setup ``` -------------------------------- ### TypstCompileException.diagnostics property Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompileException-class.html Gets the structured diagnostics from the Typst compiler. ```APIDOC ## Property: diagnostics → List ### Description Structured diagnostics from the Typst compiler. This property is final and cannot be set. ### Type List ``` -------------------------------- ### compilerVersion Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler/compilerVersion.html Gets the version string of the embedded Typst compiler engine. This property is a getter that returns a String. ```APIDOC ## compilerVersion ### Description Returns the version string of the embedded Typst compiler engine. ### Signature String get compilerVersion ### Implementation ```dart String get compilerVersion => api.getTypstVersion(); ``` ``` -------------------------------- ### warnings Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocument/warnings.html Gets the list of compiler warnings emitted during compilation. These are non-fatal diagnostics that may indicate potential issues. ```APIDOC ## warnings ### Description Gets the list of compiler warnings emitted during compilation. These are non-fatal diagnostics (e.g. deprecated syntax, ambiguous layout) that did not prevent compilation but may indicate issues. ### Property `List get warnings` ### Return Value - **List** - A list of diagnostic objects representing compiler warnings. ### Implementation ```dart List get warnings => _inner.warnings(); ``` ``` -------------------------------- ### TypstDiagnostic constructor Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDiagnostic-class.html Creates a TypstDiagnostic instance with required severity, message, hints, and optional span start and end locations. ```APIDOC ## TypstDiagnostic({required TypstSeverity severity, required String message, required List hints, TypstSourceLocation? spanStart, TypstSourceLocation? spanEnd}) ### Description Creates a new TypstDiagnostic instance. ### Parameters - **severity** (TypstSeverity) - Required - Severity of the diagnostic. - **message** (String) - Required - Human-readable error message. - **hints** (List) - Required - Optional additional hints to help fix the error. - **spanStart** (TypstSourceLocation?) - Optional - Start position of the offending source range, if available. - **spanEnd** (TypstSourceLocation?) - Optional - End position of the offending source range, if available. ### Return Value A new TypstDiagnostic instance. ``` -------------------------------- ### stringify getter Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/stringify.html Gets a boolean value indicating whether the `toString` method should output the instance's props. If null, the global `EquatableConfig.stringify` value is used, defaulting to false. ```APIDOC ## stringify property ### Description Gets a boolean value indicating whether the `toString` method should output this instance's `props`. If set to `true`, `toString` is overridden to output the props. If null, the value of `EquatableConfig.stringify` is used, which defaults to `false`. ### Property `bool? get stringify` ### Return Value - **bool?** - A nullable boolean. `true` if `toString` should output props, `false` otherwise, or `null` to use the global default. ### Implementation ```dart bool? get stringify => null; ``` ``` -------------------------------- ### Create and use TypstCompiler Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler-class.html Shows the recommended usage pattern: create a single TypstCompiler instance with fonts, compile markup to a document handle, then lazily render pages or export PDF. Construction is lightweight; the native library loads once when RustLib.init is called. ```dart final compiler = await TypstCompiler.create( fonts: FontSource.assets(['assets/fonts/Roboto.ttf']), ); // Compile to a lightweight document handle final doc = await compiler.compile(source: myMarkup); // Lazily render pages or export PDF final pdfBytes = await doc.exportPdf(); final result = await doc.renderRaster(pageIndex: 0); ``` -------------------------------- ### TypstDocument.pageInfo(int pageIndex) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocument-class.html Gets the dimensions of a specific page in points (pt). ```APIDOC ## TypstDocument.pageInfo(int pageIndex) ### Description Gets the dimensions of a specific page in points (pt). ### Method pageInfo ### Parameters - **pageIndex** (int) - Required - The index of the page to get information for. ### Return Type PageInfo ``` -------------------------------- ### TypstView.source({required String? source, Key? key, FontSource? fonts, FileSource? files, DateTime? date, int pageIndex = 0, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, BoxFit fit = BoxFit.contain, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?}) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstView-class.html Constructor for creating a TypstView that compiles and renders the given source. ```APIDOC ## TypstView.source({required String? source, Key? key, FontSource? fonts, FileSource? files, DateTime? date, int pageIndex = 0, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, BoxFit fit = BoxFit.contain, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?}) ### Description Creates a TypstView that compiles and renders the given `source`. This constructor manages its own compilation lifecycle. ### Parameters - **source** (String?) - Required - The source markup to compile and render. - **key** (Key?) - Optional - Controls how one widget replaces another widget in the tree. - **fonts** (FontSource?) - Optional - Font files for compilation. - **files** (FileSource?) - Optional - Virtual files for compilation. - **date** (DateTime?) - Optional - The date to inject for `#datetime.today()`. - **pageIndex** (int) - Optional - The 0-based index of the page to render. Defaults to 0. - **renderMode** (TypstRenderMode) - Optional - The rendering mode (SVG or Raster). Defaults to TypstRenderMode.svg. - **pixelsPerPt** (double) - Optional - Pixel density for raster rendering. Defaults to 2.0. - **fit** (BoxFit) - Optional - How the image/SVG should be inscribed into the available space. Defaults to BoxFit.contain. - **loadingBuilder** (WidgetBuilder?) - Optional - Builder for the loading state. - **errorBuilder** (Widget Function(BuildContext, TypstException)?) - Optional - Builder for the error state. ``` -------------------------------- ### create Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler/create.html Creates a TypstCompiler and initialises the native bridge. Accepts an optional FontSource for additional fonts. Safe to call multiple times. ```APIDOC ## create ### Description Creates a TypstCompiler and initialises the native bridge. Accepts an optional FontSource for additional fonts. Safe to call multiple times. ### Method static Future create({FontSource? fonts}) ### Parameters - **fonts** (FontSource?) - Optional - Additional font files to make available to the Typst compiler. These are added on top of the bundled core fonts (`Libertinus Serif`, `DejaVu Sans Mono`, and `NewCM Math`). ### Return Value Future - A future that resolves to a TypstCompiler instance. ### Implementation ```dart static Future create({FontSource? fonts}) async { try { await RustLib.init(); // flutter_rust_bridge throws a StateError if init() is called more than // once. We ignore this specific error to remain robust in tests. // ignore: avoid_catching_errors } on StateError catch (e) { if (!e.message.contains('twice')) rethrow; } final engine = api.TypstEngine(); if (fonts != null) { final fontBytes = await fonts.load(); if (fontBytes.isNotEmpty) { await engine.addFonts(fontData: fontBytes); } } return TypstCompiler._(engine: engine); } ``` ``` -------------------------------- ### TypstDocumentViewer({required String? source, Key? key, FontSource? fonts, FileSource? files, DateTime? date, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?, double pageSpacing = 8.0, Color pageColor = Colors.white, double pageElevation = 2.0}) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocumentViewer-class.html Creates a TypstDocumentViewer that manages its own compilation. This constructor takes the Typst source and optional fonts, files, and date, and compiles the document once, rendering pages lazily. ```APIDOC ## TypstDocumentViewer Constructor ### Description Creates a TypstDocumentViewer that manages its own compilation. This constructor takes the Typst source and optional fonts, files, and date, and compiles the document once, rendering pages lazily. ### Constructor `TypstDocumentViewer({required String? source, Key? key, FontSource? fonts, FileSource? files, DateTime? date, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?, double pageSpacing = 8.0, Color pageColor = Colors.white, double pageElevation = 2.0})` ### Parameters - **source** (String?) - Required - The Typst markup source to compile and render. - **key** (Key?) - Optional - Controls how one widget replaces another widget in the tree. - **fonts** (FontSource?) - Optional - Font files to make available to the Typst compiler. - **files** (FileSource?) - Optional - Virtual files (images, data, includes) the markup may reference. - **date** (DateTime?) - Optional - The date to inject for `#datetime.today()`. - **renderMode** (TypstRenderMode) - Optional - The rendering mode (SVG or Raster). Defaults to `TypstRenderMode.svg`. - **pixelsPerPt** (double) - Optional - Density for raster rendering (only used if renderMode is raster). Defaults to `2.0`. - **loadingBuilder** (WidgetBuilder?) - Optional - Builder for the loading state shown while the compiler is running. - **errorBuilder** (Widget Function(BuildContext context, TypstException error)?) - Optional - Builder for the error state shown when an error occurs. - **pageSpacing** (double) - Optional - Spacing between pages in the list. Defaults to `8.0`. - **pageColor** (Color) - Optional - Background color of the pages. Defaults to `Colors.white`. - **pageElevation** (double) - Optional - Elevation of the page cards. Defaults to `2.0`. ### Example ```dart TypstDocumentViewer( source: myMarkup, fonts: FontSource.assets(['assets/fonts/Roboto.ttf']), ) ``` ``` -------------------------------- ### TypstCompiler.create() and compile() Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter Creates a Typst compiler instance and compiles Typst source code to a PDF document. ```APIDOC ## [DART] TypstCompiler.create() and compile() ### Description Creates a Typst compiler instance and compiles Typst source code to a PDF document. ### Method Dart async method ### Endpoint TypstCompiler.create() -> Future TypstCompiler.compile({required String source}) -> Future ### Parameters #### Method Parameters - **source** (String) - Required - The Typst markup source code to compile. ### Request Example ```dart final compiler = await TypstCompiler.create(); final doc = await compiler.compile(source: r'= Hello, Typst!'); ``` ### Response #### Success Response - **doc** (TypstDocument) - The compiled Typst document. The PDF bytes are available as `doc.pdf` (Uint8List). #### Response Example ```dart // doc.pdf is a Uint8List of raw PDF bytes ``` ``` -------------------------------- ### int get hashCode Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/hashCode.html The hash code for this object. It is overridden to combine the runtime type and the hash of the widget's properties. ```APIDOC ## int get hashCode ### Description The hash code for this object. It is overridden to combine the runtime type and the hash of the widget's properties. ### Method GET ### Endpoint `hashCode` ### Parameters None ### Request Example None ### Response #### Success Response (200) - **hashCode** (int) - The hash code for this object. #### Response Example ``` int hashCode => runtimeType.hashCode ^ mapPropsToHashCode(props); ``` ### Implementation ```dart @override int get hashCode => runtimeType.hashCode ^ mapPropsToHashCode(props); ``` ``` -------------------------------- ### PageInfo constructor Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/PageInfo/PageInfo.html Creates a PageInfo instance with the specified width and height in points. ```APIDOC ## PageInfo constructor ### Description Creates a PageInfo object with the given width and height in points. ### Constructor `const PageInfo({required double widthPt, required double heightPt})` ### Parameters - **widthPt** (double) - Required - The width of the page in points. - **heightPt** (double) - Required - The height of the page in points. ### Implementation ```dart const PageInfo({required this.widthPt, required this.heightPt}); ``` ``` -------------------------------- ### Render a PDF with TypstCompiler Source: https://pub.dev/packages/typst_flutter Initialize the compiler, compile Typst source code, query metadata, and export the result to PDF bytes. ```dart import 'package:typst_flutter/typst_flutter.dart'; final compiler = await TypstCompiler.create(); // Compile to an opaque document handle final doc = await compiler.compile( source: r''' #set page(width: 148mm, height: 210mm, margin: 1cm) = Hello Typst! This is rendered *natively* in Flutter. #sys.inputs.at("theme", default: "light") ''', inputs: {'theme': 'dark'}, // Safely pass variables to Typst ); // Query metadata/structure from the compiled document final headingJson = await compiler.query(document: doc, selector: ''); // Export to PDF bytes final pdfBytes = await doc.exportPdf(); print('Generated a ${doc.pageCount}-page PDF (${pdfBytes.length} bytes).'); // You can now save pdfBytes to disk or share it! // Don't forget to dispose the document handle doc.dispose(); ``` -------------------------------- ### Override hashCode implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/PageInfo/hashCode.html An example of overriding the hashCode property to include object state, ensuring consistency with the equality operator. ```dart @override int get hashCode => widthPt.hashCode ^ heightPt.hashCode; ``` -------------------------------- ### TypstView({required TypstDocument? document, Key? key, int pageIndex = 0, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, BoxFit fit = BoxFit.contain, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?}) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstView-class.html Constructor for creating a TypstView from an already-compiled TypstDocument. ```APIDOC ## TypstView({required TypstDocument? document, Key? key, int pageIndex = 0, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, BoxFit fit = BoxFit.contain, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?}) ### Description Creates a TypstView from an already-compiled TypstDocument. This constructor is used when the document is already compiled and ready to render. ### Parameters - **document** (TypstDocument?) - Required - The compiled document to render. - **key** (Key?) - Optional - Controls how one widget replaces another widget in the tree. - **pageIndex** (int) - Optional - The 0-based index of the page to render. Defaults to 0. - **renderMode** (TypstRenderMode) - Optional - The rendering mode (SVG or Raster). Defaults to TypstRenderMode.svg. - **pixelsPerPt** (double) - Optional - Pixel density for raster rendering. Defaults to 2.0. - **fit** (BoxFit) - Optional - How the image/SVG should be inscribed into the available space. Defaults to BoxFit.contain. - **loadingBuilder** (WidgetBuilder?) - Optional - Builder for the loading state. - **errorBuilder** (Widget Function(BuildContext, TypstException)?) - Optional - Builder for the error state. ``` -------------------------------- ### int get hashCode Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstSourceLocation/hashCode.html The hash code for this object. It is computed by XORing the line and column hash codes to represent the object's state consistently with equality. ```APIDOC ## int get hashCode ### Description The hash code for this object. A hash code is a single integer representing the state of the object that affects operator == comparisons. This override ensures consistent hashing with equality based on line and column. ### Implementation ```dart @override int get hashCode => line.hashCode ^ column.hashCode; ``` ### Returns - **int** - The hash code computed as the XOR of the hash codes of `line` and `column`. ``` -------------------------------- ### TypstView.source Constructor Implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstView/TypstView.source.html The implementation of the TypstView.source constructor, which initializes the compiler and sets up rendering parameters. ```dart const TypstView.source({ required this.source, super.key, this.fonts, this.files, this.date, this.pageIndex = 0, this.renderMode = TypstRenderMode.svg, this.pixelsPerPt = 2.0, this.fit = BoxFit.contain, this.loadingBuilder, this.errorBuilder, }) : document = null; ``` -------------------------------- ### pageInfo(int pageIndex) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocument/pageInfo.html Gets the dimensions of a specific page in points (pt). The aspect ratio can be calculated as widthPt / heightPt. Throws a RangeError if pageIndex is negative or >= pageCount. ```APIDOC ## pageInfo(int pageIndex) ### Description Gets the dimensions of a specific page in points (pt). The aspect ratio can be calculated as widthPt / heightPt. Throws a RangeError if pageIndex is negative or >= pageCount. ### Method pageInfo ### Parameters #### Parameters - **pageIndex** (int) - Required - The index of the page to get information for. ### Returns - **PageInfo** - The dimensions of the specified page in points (pt). ### Exceptions - **RangeError** - If pageIndex is negative or >= pageCount. ### Implementation ```dart content_copyapi.PageInfo pageInfo(int pageIndex) { _checkNotDisposed(); RangeError.checkValidIndex(pageIndex, null, 'pageIndex', pageCount); return _inner.pageInfo(index: BigInt.from(pageIndex)); } ``` ``` -------------------------------- ### FileSource() Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource-class.html Base constructor for FileSource. ```APIDOC ## FileSource() ### Description Base constructor for FileSource. ### Constructor FileSource() ### Parameters None. ### Returns A FileSource instance. ``` -------------------------------- ### int get hashCode Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/PageInfo/hashCode.html The hashCode getter returns the hash code for the object, computed as the XOR of the hash codes of widthPt and heightPt. This ensures consistency with the overridden operator ==. ```APIDOC ## int get hashCode ### Description The hash code for this object. It is computed as the XOR of the hash codes of widthPt and heightPt, ensuring consistency with the overridden operator ==. ### Method GET ### Endpoint Not applicable (property getter) ### Parameters None ### Return Value - **int** - The hash code for the object. ### Implementation ```dart @override int get hashCode => widthPt.hashCode ^ heightPt.hashCode; ``` ``` -------------------------------- ### TypstCompiler.compile({required String source, FileSource? files, DateTime? date, Map? inputs, bool allowPackages = true}) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler-class.html Compiles Typst source markup into a lightweight document handle. ```APIDOC ## compile ### Description Compiles Typst `source` markup into a lightweight document handle. ### Method Instance method ### Signature `Future compile({required String source, FileSource? files, DateTime? date, Map? inputs, bool allowPackages = true})` ### Parameters - **source** (String) - Required - The Typst source markup to compile. - **files** (FileSource?) - Optional - Additional file sources for the compilation. - **date** (DateTime?) - Optional - The date to use for compilation. - **inputs** (Map?) - Optional - Input variables for the compilation. - **allowPackages** (bool) - Optional - Whether to allow packages (default: true). ### Returns `Future` - A future that resolves to a document handle. ### Example ```dart final doc = await compiler.compile(source: myMarkup); ``` ``` -------------------------------- ### Compile and Render Typst Content Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter Demonstrates the basic workflow of compiling Typst markup into a PDF document and rendering it within a Flutter widget. ```dart // 1. Compile to PDF final compiler = await TypstCompiler.create(); final doc = await compiler.compile(source: r'= Hello, Typst!'); // doc.pdf is a Uint8List of raw PDF bytes // 2. Render a page as a Flutter widget (live reload) TypstView(source: myMarkupString) ``` -------------------------------- ### TypstDocumentViewer Constructor Implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocumentViewer/TypstDocumentViewer.html The implementation of the TypstDocumentViewer constructor, which initializes the viewer with various configuration parameters including source, rendering mode, and styling options. ```dart const TypstDocumentViewer({ required this.source, super.key, this.fonts, this.files, this.date, this.renderMode = TypstRenderMode.svg, this.pixelsPerPt = 2.0, this.loadingBuilder, this.errorBuilder, this.pageSpacing = 8.0, this.pageColor = Colors.white, this.pageElevation = 2.0, }) : document = null; ``` -------------------------------- ### TypstView constructor implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstView/TypstView.html The constructor initializes a TypstView with the given document, key, page index, render mode, pixels per point, fit, loading builder, and error builder. It sets source, fonts, files, and date to null. ```dart const TypstView({ required this.document, super.key, this.pageIndex = 0, this.renderMode = TypstRenderMode.svg, this.pixelsPerPt = 2.0, this.fit = BoxFit.contain, this.loadingBuilder, this.errorBuilder, }) : source = null, fonts = null, files = null, date = null; ``` -------------------------------- ### TypstDocumentViewer.new Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocumentViewer/TypstDocumentViewer.html Creates a TypstDocumentViewer widget that manages its own compilation. The constructor accepts the Typst source string and various rendering options. ```APIDOC ## TypstDocumentViewer.new ### Description Creates a TypstDocumentViewer that manages its own compilation. The widget renders a Typst document from the provided source string. ### Constructor `const TypstDocumentViewer({ required String? source, Key? key, FontSource? fonts, FileSource? files, DateTime? date, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?, double pageSpacing = 8.0, Color pageColor = Colors.white, double pageElevation = 2.0 })` ### Parameters - **source** (String?) - Required - The Typst source code to render. - **key** (Key?) - Optional - Flutter widget key. - **fonts** (FontSource?) - Optional - Custom font source for Typst compilation. - **files** (FileSource?) - Optional - Additional file source for Typst compilation. - **date** (DateTime?) - Optional - The date used for Typst compilation. - **renderMode** (TypstRenderMode) - Optional - The rendering mode, defaults to `TypstRenderMode.svg`. - **pixelsPerPt** (double) - Optional - Pixels per point, defaults to `2.0`. - **loadingBuilder** (WidgetBuilder?) - Optional - Builder for the loading state. - **errorBuilder** (Widget Function(BuildContext, TypstException)?) - Optional - Builder for error state. - **pageSpacing** (double) - Optional - Spacing between pages, defaults to `8.0`. - **pageColor** (Color) - Optional - Background color of pages, defaults to `Colors.white`. - **pageElevation** (double) - Optional - Elevation of pages, defaults to `2.0`. ### Implementation ```dart const TypstDocumentViewer({ required this.source, super.key, this.fonts, this.files, this.date, this.renderMode = TypstRenderMode.svg, this.pixelsPerPt = 2.0, this.loadingBuilder, this.errorBuilder, this.pageSpacing = 8.0, this.pageColor = Colors.white, this.pageElevation = 2.0, }) : document = null; ``` ``` -------------------------------- ### TypstDocumentViewer.document constructor Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocumentViewer/TypstDocumentViewer.document.html Creates a TypstDocumentViewer from an already-compiled TypstDocument. This avoids creating a per-widget compiler and is the recommended approach when you already have a TypstCompiler instance. ```APIDOC ## TypstDocumentViewer.document constructor ### Description Creates a TypstDocumentViewer from an already-compiled TypstDocument. This avoids creating a per-widget compiler and is the recommended approach when you already have a TypstCompiler instance. ### Constructor Signature ```dart const TypstDocumentViewer.document({ required TypstDocument? document, Key? key, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?, double pageSpacing = 8.0, Color pageColor = Colors.white, double pageElevation = 2.0, }) ``` ### Parameters - **document** (TypstDocument?) - Required - The compiled TypstDocument to display. - **key** (Key?) - Optional - The widget key. - **renderMode** (TypstRenderMode) - Optional - The rendering mode, defaults to TypstRenderMode.svg. - **pixelsPerPt** (double) - Optional - The pixel density, defaults to 2.0. - **loadingBuilder** (WidgetBuilder?) - Optional - A builder for the loading state. - **errorBuilder** (Widget Function(BuildContext, TypstException)?) - Optional - A builder for the error state. - **pageSpacing** (double) - Optional - Spacing between pages, defaults to 8.0. - **pageColor** (Color) - Optional - Background color of pages, defaults to Colors.white. - **pageElevation** (double) - Optional - Elevation of pages, defaults to 2.0. ### Implementation ```dart const TypstDocumentViewer.document({ required this.document, super.key, this.renderMode = TypstRenderMode.svg, this.pixelsPerPt = 2.0, this.loadingBuilder, this.errorBuilder, this.pageSpacing = 8.0, this.pageColor = Colors.white, this.pageElevation = 2.0, }) : source = null, fonts = null, files = null, date = null; ``` ``` -------------------------------- ### TypstView.source constructor Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstView/TypstView.source.html Creates a TypstView that compiles and renders the given source string. This constructor maintains its own internal compiler. ```APIDOC ## TypstView.source constructor ### Description Creates a TypstView that compiles and renders the given `source`. This constructor maintains its own internal compiler. ### Signature ```dart const TypstView.source({ required String? source, Key? key, FontSource? fonts, FileSource? files, DateTime? date, int pageIndex = 0, TypstRenderMode renderMode = TypstRenderMode.svg, double pixelsPerPt = 2.0, BoxFit fit = BoxFit.contain, WidgetBuilder? loadingBuilder, Widget errorBuilder(BuildContext context, TypstException error)?, }) ``` ### Parameters - **source** (String?) - Required - The Typst source code to compile and render. - **key** (Key?) - Optional - The widget key. - **fonts** (FontSource?) - Optional - Font source for custom fonts. - **files** (FileSource?) - Optional - File source for additional files. - **date** (DateTime?) - Optional - The date to use for compilation. - **pageIndex** (int) - Optional - The index of the page to display. Defaults to 0. - **renderMode** (TypstRenderMode) - Optional - The rendering mode. Defaults to TypstRenderMode.svg. - **pixelsPerPt** (double) - Optional - The number of pixels per point. Defaults to 2.0. - **fit** (BoxFit) - Optional - How to fit the rendered content. Defaults to BoxFit.contain. - **loadingBuilder** (WidgetBuilder?) - Optional - A builder for the loading state. - **errorBuilder** (Widget Function(BuildContext, TypstException)?) - Optional - A builder for the error state. ### Implementation ```dart const TypstView.source({ required this.source, super.key, this.fonts, this.files, this.date, this.pageIndex = 0, this.renderMode = TypstRenderMode.svg, this.pixelsPerPt = 2.0, this.fit = BoxFit.contain, this.loadingBuilder, this.errorBuilder, }) : document = null; ``` ``` -------------------------------- ### FileSource.assets implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/FileSource.assets.html The implementation of the FileSource.assets factory constructor. ```dart const factory FileSource.assets(Map pathMap) = _AssetFileSource; ``` -------------------------------- ### compile method implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler/compile.html Compiles Typst source markup into a lightweight document handle. Returns a TypstDocument for querying page dimensions, rendering raster/SVG pages, or exporting to PDF. The allowPackages parameter defaults to true, enabling automatic download and caching of packages from packages.typst.org; set to false for offline-only compilation or to prevent network access. Throws TypstCompileException on compilation errors. ```dart Future compile({ required String source, FileSource? files, DateTime? date, Map? inputs, bool allowPackages = true, }) async { final virtualFiles = await _buildVirtualFiles(files); try { final inner = await _engine.compile( markup: source, files: virtualFiles, sysTime: _dateTimeToSysTime(date), inputs: inputs, allowPackages: allowPackages, ); return TypstDocument.fromInner(inner); } on api.TypstCompileError catch (e) { throw TypstCompileException( 'Compilation failed', diagnostics: e.diagnostics, ); } catch (e) { throw TypstCompileException('$e'); } } ``` -------------------------------- ### Run integration test for typst_flutter Source: https://pub.dev/packages/typst_flutter Run the integration test for the typst_flutter package. Because the package relies on native Rust libraries via FFI, unit tests must be run as integration tests against a host platform. ```bash flutter test integration_test/simple_test.dart ``` -------------------------------- ### Pre-compiled document with TypstDocumentViewer.document Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocumentViewer-class.html Use this snippet when sharing a compiler to avoid per-widget compilation cost. Compile once using TypstCompiler.create and compiler.compile, then pass the resulting TypstDocument to TypstDocumentViewer.document. ```dart final compiler = await TypstCompiler.create(fonts: ...); final doc = await compiler.compile(source: myMarkup); TypstDocumentViewer.document(document: doc) ``` -------------------------------- ### TypstCompilerProvider.new Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompilerProvider/TypstCompilerProvider.html Creates a TypstCompilerProvider that provides the given compiler to the child widget. This is the constructor for the provider widget. ```APIDOC ## TypstCompilerProvider.new ### Description Creates a TypstCompilerProvider that provides `compiler` to `child`. ### Constructor `const TypstCompilerProvider({ required TypstCompiler compiler, required Widget child, Key? key })` ### Parameters - **compiler** (TypstCompiler) - Required - The TypstCompiler instance to provide to the child widget. - **child** (Widget) - Required - The widget that will receive the compiler through the provider. - **key** (Key?) - Optional - The key for the widget. ### Implementation ```dart const TypstCompilerProvider({ required this.compiler, required super.child, super.key, }); ``` ``` -------------------------------- ### FileSource.bytes(Map files) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource-class.html Load files from raw byte data already in memory. ```APIDOC ## FileSource.bytes(Map files) ### Description Load files from raw byte data already in memory. ### Constructor FileSource.bytes(Map files) ### Parameters - **files** (Map) - Required - A map where keys are virtual paths and values are the raw byte data of the files. ### Returns A FileSource instance. ``` -------------------------------- ### FileSource.bytes implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/FileSource.bytes.html The factory implementation for the FileSource.bytes constructor. ```dart const factory FileSource.bytes(Map files) = _BytesFileSource; ``` -------------------------------- ### FileSource.bytes Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/FileSource.bytes.html Constructor for creating a FileSource from in-memory byte data. ```APIDOC ## FileSource.bytes ### Description Loads files from raw byte data already in memory. The `files` map associates virtual paths (as used in markup) with raw file bytes. ### Constructor `const FileSource.bytes(Map files)` ### Parameters - **files** (`Map`) - Required - Maps virtual path (as used in markup) to raw file bytes. ### Implementation ```dart const factory FileSource.bytes(Map files) = _BytesFileSource; ``` ``` -------------------------------- ### TypstCompiler.create implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler/create.html Creates a TypstCompiler, initializes the native bridge via RustLib.init(), handles repeated initialization by ignoring StateError, and optionally loads additional fonts. ```dart static Future create({FontSource? fonts}) async { try { await RustLib.init(); // flutter_rust_bridge throws a StateError if init() is called more than // once. We ignore this specific error to remain robust in tests. // ignore: avoid_catching_errors } on StateError catch (e) { if (!e.message.contains('twice')) rethrow; } final engine = api.TypstEngine(); if (fonts != null) { final fontBytes = await fonts.load(); if (fontBytes.isNotEmpty) { await engine.addFonts(fontData: fontBytes); } } return TypstCompiler._(engine: engine); } ``` -------------------------------- ### FileSource.bytes constructor definition Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/FileSource.bytes.html The constructor signature for initializing a FileSource from raw byte data. ```dart const FileSource.bytes( 1. Map files ) ``` -------------------------------- ### compile Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler/compile.html Compiles Typst source markup into a lightweight document handle. Returns a TypstDocument that can be used to query page dimensions, lazily render raster/SVG pages, or export the full document to PDF. ```APIDOC ## compile ### Description Compiles Typst `source` markup into a lightweight document handle. Returns a TypstDocument which can be used to query page dimensions, lazily render raster/SVG pages, or export the full document to PDF. ### Method compile ### Signature Future compile({ required String source, FileSource? files, DateTime? date, Map? inputs, bool allowPackages = true, }) ### Parameters - **source** (String) - Required - The Typst markup source code to compile. - **files** (FileSource?) - Optional - Additional files to include in the compilation. - **date** (DateTime?) - Optional - The date to use for the compilation. - **inputs** (Map?) - Optional - Input variables for the Typst compilation. - **allowPackages** (bool) - Optional - Controls whether packages referenced via `#import "@preview/..."` will be automatically downloaded from `packages.typst.org` and cached in memory. Defaults to `true`. Set to `false` for offline-only compilation or to prevent network access. ### Returns - **TypstDocument** - A lightweight document handle that can be used to query page dimensions, lazily render raster/SVG pages, or export the full document to PDF. ### Exceptions - **TypstCompileException** - Thrown when compilation fails, with diagnostics information. ### Implementation ```dart Future compile({ required String source, FileSource? files, DateTime? date, Map? inputs, bool allowPackages = true, }) async { final virtualFiles = await _buildVirtualFiles(files); try { final inner = await _engine.compile( markup: source, files: virtualFiles, sysTime: _dateTimeToSysTime(date), inputs: inputs, allowPackages: allowPackages, ); return TypstDocument.fromInner(inner); } on api.TypstCompileError catch (e) { throw TypstCompileException( 'Compilation failed', diagnostics: e.diagnostics, ); } catch (e) { throw TypstCompileException('$e'); } } ``` ``` -------------------------------- ### PageInfo constructor implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/PageInfo/PageInfo.html The implementation of the PageInfo constructor, which requires widthPt and heightPt parameters. ```dart const PageInfo({required this.widthPt, required this.heightPt}); ``` -------------------------------- ### TypstDocumentViewer.document constructor implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocumentViewer/TypstDocumentViewer.document.html Creates a TypstDocumentViewer from an already-compiled TypstDocument. This constructor sets source, fonts, files, and date to null, relying on the provided document. Use this when you already have a TypstCompiler instance to avoid creating a per-widget compiler. ```dart const TypstDocumentViewer.document({ required this.document, super.key, this.renderMode = TypstRenderMode.svg, this.pixelsPerPt = 2.0, this.loadingBuilder, this.errorBuilder, this.pageSpacing = 8.0, this.pageColor = Colors.white, this.pageElevation = 2.0, }) : source = null, fonts = null, files = null, date = null; ``` -------------------------------- ### FileSource.none factory constructor implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/FileSource.none.html The implementation of the FileSource.none constructor, which is a factory that returns an instance of _NoneFileSource. This constructor is used when no additional files are available, and any external file references will cause an error. ```dart const factory FileSource.none() = _NoneFileSource; ``` -------------------------------- ### query Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstCompiler/query.html Queries the compiled Typst document using a selector string and returns a JSON string of matching elements. ```APIDOC ## query ### Description Queries the compiled `document` using a Typst `selector` string. Returns a JSON string containing the queried elements (e.g. headings). ### Method query ### Signature Future query({ required TypstDocument document, required String selector, }) ### Parameters - **document** (TypstDocument) - Required - The compiled Typst document to query. - **selector** (String) - Required - The Typst selector string used to query the document. ### Returns - **Future** - A JSON string containing the queried elements. ### Implementation ```dart Future query({ required TypstDocument document, required String selector, }) async => await _engine.query(document: document.inner, selector: selector); ``` ``` -------------------------------- ### toPng() Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstRenderResult/toPng.html Encodes the raw RGBA pixels as a PNG and returns the PNG bytes. This method is self-contained and handles image lifecycle management. ```APIDOC ## toPng() ### Description Encodes the raw RGBA pixels as a PNG and returns the PNG bytes. This method is self-contained: if no cached ui.Image exists, it creates a temporary one, encodes it, and disposes it immediately — no leak even if dispose is never called. If a cached image already exists (from a prior toImage call), it reuses that image without disposing it. ### Method Future toPng() ### Return Value - **Future** - A Future that resolves to the PNG-encoded image bytes. ### Implementation ```dart Future toPng() async { final hadCached = _cachedImage != null; final image = hadCached ? _cachedImage! : await _decodeImage(); try { final byteData = await image.toByteData(format: ui.ImageByteFormat.png); return byteData!.buffer.asUint8List(); } finally { // Only dispose the image if we created it ad-hoc for this call. if (!hadCached) image.dispose(); } } ``` ``` -------------------------------- ### FileSource.none() Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource-class.html No additional files — the compiler cannot resolve any external file references. Typst will return an error if the markup references any file (images, includes, etc.). ```APIDOC ## FileSource.none() ### Description No additional files — the compiler cannot resolve any external file references. Typst will return an error if the markup references any file (images, includes, etc.). ### Constructor FileSource.none() ### Parameters None. ### Returns A FileSource instance. ``` -------------------------------- ### toPng method implementation Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstRenderResult/toPng.html Encodes raw RGBA pixels as a PNG. If no cached ui.Image exists, it creates a temporary one, encodes it, and disposes it in a finally block to avoid leaks. If a cached image exists from a prior toImage call, it reuses it without disposing. ```dart Future toPng() async { final hadCached = _cachedImage != null; final image = hadCached ? _cachedImage! : await _decodeImage(); try { final byteData = await image.toByteData(format: ui.ImageByteFormat.png); return byteData!.buffer.asUint8List(); } finally { // Only dispose the image if we created it ad-hoc for this call. if (!hadCached) image.dispose(); } } ``` -------------------------------- ### props getter Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/FileSource/props.html Returns the list of properties used to determine whether two instances are equal. This is an inherited property. ```APIDOC ## props property ### Description Returns the list of properties used to determine whether two instances are equal. ### Signature List get props ### Implementation ```dart List get props; ``` ``` -------------------------------- ### Implementation of hints property Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDiagnostic/hints.html The hints property is defined as a List of strings. ```dart final List hints; ``` -------------------------------- ### TypstDocument.fromInner(CompiledDocument inner) Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocument-class.html Creates a TypstDocument from the inner native handle. ```APIDOC ## TypstDocument.fromInner(CompiledDocument inner) ### Description Creates a TypstDocument from the inner native handle. ### Method fromInner ### Parameters - **inner** (CompiledDocument) - Required - The inner native handle. ### Return Type TypstDocument ``` -------------------------------- ### TypstRenderResult constructor Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstRenderResult-class.html Creates a TypstRenderResult with the given index, raw RGBA pixel data, width, and height. ```APIDOC ## TypstRenderResult({required int index, required Uint8List bytes, required int width, required int height}) ### Description Creates a TypstRenderResult with the given index, raw RGBA pixel data, width, and height. ### Parameters - **index** (int) - Required - Zero-based index of this page. - **bytes** (Uint8List) - Required - Raw RGBA pixel data (4 bytes per pixel, row-major order). - **width** (int) - Required - Width of the rendered image in pixels. - **height** (int) - Required - Height of the rendered image in pixels. ### Returns A new TypstRenderResult instance. ``` -------------------------------- ### Use TypstCompilerProvider for performance Source: https://pub.dev/packages/typst_flutter Wrap your application in a TypstCompilerProvider to share a single compiler instance across multiple TypstView widgets. ```dart // 1. Initialize once final compiler = await TypstCompiler.create(); // 2. Wrap your app TypstCompilerProvider( compiler: compiler, child: Scaffold( body: ListView( children: [ // 3. These render instantly using the shared engine! TypstView.source(source: '$ x^2 + y^2 = r^2 $'), TypstView.source(source: '$ e^(i pi) + 1 = 0 $'), ], ) ) ) ``` -------------------------------- ### loadingBuilder Source: https://pub.dev/documentation/typst_flutter/latest/typst_flutter/TypstDocumentViewer/loadingBuilder.html A final WidgetBuilder? property that defines the loading state shown while the compiler is running. ```APIDOC ## loadingBuilder ### Description Builder for the loading state shown while the compiler is running. ### Declaration ```dart final WidgetBuilder? loadingBuilder; ``` ### Type `WidgetBuilder?` ### Modifiers - `final` ### Usage This property is used to provide a custom widget for the loading state while the compiler is running. If not provided, a default loading indicator may be shown. ```