Documentation
¶
Overview ¶
Package preview manages persistent, revisioned compilation sessions for low-latency web previews. Sessions coalesce edits, cancel superseded work, retain LaTeX auxiliary files, and report only changed pages.
Index ¶
- Variables
- type AssetResolver
- type CompileOutput
- type CompileRequest
- type Compiler
- type Diagnostic
- type ExecProcessRunner
- type LaTeXCompiler
- type LaTeXCompilerOptions
- type Options
- type Page
- type PageRasterizer
- type PopplerRasterizer
- type Process
- type ProcessOutput
- type ProcessRunner
- type RasterOutput
- type Result
- type Session
- type StageTimings
- type Workspace
- type WorkspaceFactory
Constants ¶
This section is empty.
Variables ¶
var ( ErrProcessRunnerRequired = errors.New("preview: process runner is required") ErrRasterizerRequired = errors.New("preview: page rasterizer is required") ErrPreviewPDFMissing = errors.New("preview: compiler produced no PDF") )
var ( ErrClosed = errors.New("preview session is closed") ErrSuperseded = errors.New("preview revision was superseded") ErrCompilerRequired = errors.New("preview compiler is required") ErrResolverRequired = errors.New("preview asset resolver is required") ErrUnsafePath = errors.New("unsafe preview workspace path") )
var ErrWorkspaceRequired = errors.New("preview workspace factory returned no workspace")
Functions ¶
This section is empty.
Types ¶
type AssetResolver ¶
AssetResolver collects one inert asset at the workspace effect boundary.
type CompileOutput ¶
type CompileOutput struct {
PDF []byte
Pages []Page
Diagnostics []Diagnostic
Timings StageTimings
}
CompileOutput is returned by a target-specific compiler/rasterizer adapter.
type CompileRequest ¶
type CompileRequest struct {
Revision uint64
Workspace string
Main string
DirtyFiles []string
SourceMap map[string]latex.SourceLocation
}
CompileRequest identifies one revision within a persistent workspace.
type Compiler ¶
type Compiler interface {
Compile(context.Context, CompileRequest) (CompileOutput, error)
}
Compiler is the effect port around LaTeX execution and page rasterization.
type Diagnostic ¶
type Diagnostic struct {
ComponentID string `json:"componentId,omitempty"`
Path string `json:"path,omitempty"`
Line int `json:"line,omitempty"`
Severity string `json:"severity,omitempty"`
Message string `json:"message"`
}
Diagnostic is a compiler message addressable to generated source.
type ExecProcessRunner ¶
type ExecProcessRunner struct{}
ExecProcessRunner uses exec.CommandContext; cancellation terminates the child.
func (ExecProcessRunner) Run ¶
func (ExecProcessRunner) Run(ctx context.Context, process Process) (ProcessOutput, error)
type LaTeXCompiler ¶
type LaTeXCompiler struct {
// contains filtered or unexported fields
}
LaTeXCompiler retains per-workspace page fingerprints while TeX retains aux state in the workspace itself.
func NewLaTeXCompiler ¶
func NewLaTeXCompiler(options LaTeXCompilerOptions) (*LaTeXCompiler, error)
NewLaTeXCompiler creates a concrete preview compiler. Defaults: xelatex, job name autopdf-preview, 144 DPI, and Poppler rasterization.
func (*LaTeXCompiler) Compile ¶
func (compiler *LaTeXCompiler) Compile(ctx context.Context, request CompileRequest) (CompileOutput, error)
Compile reuses workspace aux files, compiles the current main source, then returns full page identities with bytes only for changed pages.
type LaTeXCompilerOptions ¶
type LaTeXCompilerOptions struct {
Engine string
JobName string
DPI int
Runner ProcessRunner
Rasterizer PageRasterizer
}
LaTeXCompilerOptions configures a warm compiler bound to session workspaces.
type Options ¶
type Options struct {
WorkspaceRoot string
IdleTTL time.Duration
KeepWorkspace bool
Resolver AssetResolver
WorkspaceFactory WorkspaceFactory
}
Options controls workspace placement and idle expiry.
type Page ¶
type Page struct {
Number int `json:"number"`
MediaType string `json:"mediaType"`
Data []byte `json:"data"`
Hash string `json:"hash"`
}
Page is browser-ready output for one page. Hash may be omitted by compiler; the session fills it from MIME and Data.
type PageRasterizer ¶
type PageRasterizer interface {
Rasterize(context.Context, string, string, map[int]string) (RasterOutput, error)
}
PageRasterizer fingerprints pages and rasterizes only changed identities.
type PopplerRasterizer ¶
type PopplerRasterizer struct {
// contains filtered or unexported fields
}
PopplerRasterizer uses a cheap low-DPI visual pass for stable page identities and full-DPI pdftoppm only for pages whose identity changed.
func NewPopplerRasterizer ¶
func NewPopplerRasterizer(runner ProcessRunner, dpi int) *PopplerRasterizer
func (*PopplerRasterizer) Rasterize ¶
func (rasterizer *PopplerRasterizer) Rasterize(ctx context.Context, pdfPath, workspace string, previous map[int]string) (RasterOutput, error)
type ProcessOutput ¶
ProcessOutput retains both output streams for diagnostic parsing.
type ProcessRunner ¶
type ProcessRunner interface {
Run(context.Context, Process) (ProcessOutput, error)
}
ProcessRunner is injectable so process lifecycle can be tested without TeX.
type RasterOutput ¶
RasterOutput reports complete page identities; unchanged pages intentionally carry no Data, avoiding needless rasterization and transport.
type Result ¶
type Result struct {
Revision uint64 `json:"revision"`
Projection string `json:"projectionHash,omitempty"`
PDF []byte `json:"pdf,omitempty"`
ChangedPages []Page `json:"changedPages,omitempty"`
RemovedPages []int `json:"removedPages,omitempty"`
Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
DirtyFiles []string `json:"dirtyFiles,omitempty"`
Timings StageTimings `json:"timings"`
Err error `json:"-"`
}
Result contains only pages changed from the last accepted revision.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session serializes compiles within one persistent LaTeX workspace.
func NewSession ¶
NewSession creates a private workspace retained across preview revisions.
func (*Session) Done ¶
func (session *Session) Done() <-chan struct{}
Done closes when manual close or idle expiry has released the workspace.
type StageTimings ¶
type StageTimings struct {
Materialize time.Duration `json:"materialize"`
TeX time.Duration `json:"tex"`
Fingerprint time.Duration `json:"fingerprint"`
Raster time.Duration `json:"raster"`
Total time.Duration `json:"total"`
}
StageTimings separates deterministic orchestration from environment-sensitive TeX and raster work.
type WorkspaceFactory ¶
WorkspaceFactory is the injectable lifecycle port for preview storage.