typwire
An extended CBOR encoder for the Typst plugin system.
This library provides a CBOR encoder with extended support for Typst types, along with corresponding Rust types and deserialization, enabling seamless data exchange between Typst and Rust WASM plugins.
Usage
Note: The versions used in Typst and Rust MUST match exactly.
Rust:
Add typwire to your Rust project like this:
use Deserialize;
use ;
use *;
initiate_protocol!;
Typst:
#import "@preview/typwire:0.1.0"
#let custom-plugin = plugin("custom_plugin.wasm")
#let custom = (
"angle": 90deg,
"color": red,
"datetime": datetime.today(),
)
#let encoded = typwire.cbor.encode(custom)
#custom-plugin.custom_fn(encoded)
Supported types
- int
- float
- bytes
- str
- bool
- content
- none
- array
- dictionary
- angle
- length
- ratio
- color
- gradient
- datetime
- duration
- version
- type
- fraction
- direction
- relative
- decimal
Missing features
- Color conversion in Rust
- Dynamic Value type that includes all Typst types
- Decoding from plugin
- Static Gradient defaults
- Support for all types