Documentation
¶
Index ¶
- type ImageCache
- func (ic *ImageCache) Close()
- func (ic *ImageCache) Dir() string
- func (ic *ImageCache) Lookup(url string) (string, bool)
- func (ic *ImageCache) ResolveImages(ctx context.Context, images map[string]string, ...) map[string]string
- func (ic *ImageCache) Store(url string, ext string, data []byte) (string, error)
- type ImageCacheOptions
- type Service
- type TypstBuilder
- type TypstConverter
- type TypstOptions
- type TypstRenderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ImageCache ¶
type ImageCache struct {
// contains filtered or unexported fields
}
ImageCache provides a shared disk-based cache for downloaded images. Files are keyed by SHA-256 of the URL and cleaned up periodically by age.
func NewImageCache ¶
func NewImageCache(opts ImageCacheOptions) (*ImageCache, error)
NewImageCache creates and starts an image cache with periodic cleanup. If dir is empty, a temp directory is created.
func (*ImageCache) Dir ¶
func (ic *ImageCache) Dir() string
Dir returns the cache directory path for use as Typst --root.
func (*ImageCache) Lookup ¶
func (ic *ImageCache) Lookup(url string) (string, bool)
Lookup checks if an image for the given URL exists in cache. Returns the file path and true if found, or empty string and false if not.
func (*ImageCache) ResolveImages ¶
func (ic *ImageCache) ResolveImages(ctx context.Context, images map[string]string, downloadFn func(ctx context.Context, url, destPath string) (string, error)) map[string]string
ResolveImages downloads images that aren't cached, stores them, and returns a map of typst placeholder filenames to actual filenames in the cache dir.
type ImageCacheOptions ¶
ImageCacheOptions configures the image cache.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements the PDFRenderer interface using Typst.
func NewService ¶
func NewService(opts TypstOptions, imageCache *ImageCache) (*Service, error)
NewService creates a new PDF renderer service.
func (*Service) RenderPreview ¶
func (s *Service) RenderPreview(ctx context.Context, req *port.RenderPreviewRequest) (*port.RenderPreviewResult, error)
RenderPreview generates a preview PDF with injected values.
type TypstBuilder ¶
type TypstBuilder struct {
// contains filtered or unexported fields
}
TypstBuilder constructs complete Typst documents from portable documents.
func NewTypstBuilder ¶
func NewTypstBuilder( injectables map[string]any, injectableDefaults map[string]string, ) *TypstBuilder
NewTypstBuilder creates a new Typst builder.
func (*TypstBuilder) Build ¶
func (b *TypstBuilder) Build(doc *portabledoc.Document) string
Build creates a complete Typst document from a portable document.
func (*TypstBuilder) GetPageCount ¶
func (b *TypstBuilder) GetPageCount() int
GetPageCount returns the page count based on page breaks encountered.
func (*TypstBuilder) RemoteImages ¶
func (b *TypstBuilder) RemoteImages() map[string]string
RemoteImages returns the map of remote image URLs to local filenames collected during build.
type TypstConverter ¶
type TypstConverter struct {
// contains filtered or unexported fields
}
TypstConverter converts ProseMirror/TipTap nodes to Typst markup.
func NewTypstConverter ¶
func NewTypstConverter( injectables map[string]any, injectableDefaults map[string]string, ) *TypstConverter
NewTypstConverter creates a new Typst node converter.
func (*TypstConverter) ConvertNode ¶
func (c *TypstConverter) ConvertNode(node portabledoc.Node) string
ConvertNode converts a single node to Typst markup.
func (*TypstConverter) ConvertNodes ¶
func (c *TypstConverter) ConvertNodes(nodes []portabledoc.Node) string
ConvertNodes converts a slice of nodes to Typst markup.
func (*TypstConverter) GetCurrentPage ¶
func (c *TypstConverter) GetCurrentPage() int
GetCurrentPage returns the current page number.
func (*TypstConverter) RemoteImages ¶
func (c *TypstConverter) RemoteImages() map[string]string
RemoteImages returns the map of remote image URLs to local filenames.
type TypstOptions ¶
type TypstOptions struct {
// BinPath is the path to the typst binary (default: "typst").
BinPath string
// Timeout is the maximum time to wait for PDF compilation.
Timeout time.Duration
// FontDirs are additional directories to search for fonts.
FontDirs []string
// MaxConcurrent limits simultaneous typst processes (0 = unlimited).
MaxConcurrent int
// AcquireTimeout is the max wait time to acquire a render slot.
AcquireTimeout time.Duration
}
TypstOptions configures the Typst renderer.
func DefaultTypstOptions ¶
func DefaultTypstOptions() TypstOptions
DefaultTypstOptions returns sensible default options.
type TypstRenderer ¶
type TypstRenderer struct {
// contains filtered or unexported fields
}
TypstRenderer handles PDF generation using the Typst CLI.
func NewTypstRenderer ¶
func NewTypstRenderer(opts TypstOptions) (*TypstRenderer, error)
NewTypstRenderer creates a new Typst-based PDF renderer.
func (*TypstRenderer) Close ¶
func (r *TypstRenderer) Close() error
Close is a no-op for Typst (no persistent processes to clean up).
func (*TypstRenderer) GeneratePDF ¶
func (r *TypstRenderer) GeneratePDF(ctx context.Context, typstSource string, rootDir string) ([]byte, error)
GeneratePDF compiles Typst source to PDF bytes. rootDir is optional; if set, it's passed as --root to typst for resolving local file paths.