wasmconvert

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wasmconvert holds the host-testable HTML→PDF conversion used by the browser WebAssembly bindings in ../../cmd/wasm. Keeping the conversion logic in a plain (non build-tagged) package lets it be unit tested without a wasm runtime, while the syscall/js glue stays a thin wrapper around it.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyHTML = errors.New("wasmconvert: html is empty")

ErrEmptyHTML is returned by HTMLToBase64 when the supplied HTML is empty or only whitespace.

View Source
var ErrEmptySpec = errors.New("wasmconvert: spec is empty")

ErrEmptySpec is returned by SpecToBase64 when the supplied spec is empty or only whitespace.

Functions

func HTMLToBase64

func HTMLToBase64(ctx context.Context, html string) (string, error)

HTMLToBase64 renders the given HTML to a PDF and returns it as a base64 string, suitable for handing back to JavaScript. It returns ErrEmptyHTML when html is empty or whitespace-only, propagates any error from generation (including context cancellation), and recovers from any panic in the render tree so the caller (and the wasm goroutine) always survives.

func SpecToBase64

func SpecToBase64(ctx context.Context, jsonSpec, pageSize string) (string, error)

SpecToBase64 renders a JSON layout spec into a PDF and returns it as base64. It returns ErrEmptySpec for empty input, a wrapped error for invalid JSON or generation failures, and recovers from any panic in the render tree so the caller (and the wasm goroutine) always survives.

Types

type Spec

type Spec struct {
	Rows []SpecRow `json:"rows"`
}

Spec is the JSON layout document accepted by SpecToBase64. It mirrors the schema used by the Paper Playground's component-grid editor.

type SpecComp

type SpecComp struct {
	Type     string     `json:"type"`
	Style    string     `json:"style,omitempty"`
	Align    string     `json:"align,omitempty"`
	Value    string     `json:"value,omitempty"`
	Label    string     `json:"label,omitempty"`
	Span     int        `json:"span,omitempty"`
	Checked  bool       `json:"checked,omitempty"`
	Soft     bool       `json:"soft,omitempty"`
	Size     float64    `json:"size,omitempty"`
	Width    float64    `json:"width,omitempty"`
	Height   float64    `json:"height,omitempty"`
	Head     []string   `json:"head,omitempty"`
	Rows     [][]string `json:"rows,omitempty"`
	ColAlign []string   `json:"colAlign,omitempty"`
}

SpecComp is one cell: a component plus its column span and presentation hints.

type SpecRow

type SpecRow struct {
	Cols []SpecComp `json:"cols"`
	Gap  *float64   `json:"gap,omitempty"`
	Mt   *float64   `json:"mt,omitempty"`
}

SpecRow is one row of the 12-column grid. Gap and Mt are layout hints from the editor; they are accepted but not applied by Paper's grid engine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL