preview

package
v0.1.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 13 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 preview renders every Sweef UI page through the real Sweef engine (the same Tab and paintPage path that `sweef screenshot` uses) with a mocked window.sweef and sample state. It is the design feedback loop and the basis of the UI regression test.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Engine

func Engine() *engine.Engine

Engine returns a fresh engine configured for UI rendering.

func Generate

func Generate(outDir, filter string, scales []float64, log func(string)) ([]string, error)

Generate renders all scenarios whose name contains filter into outDir at 1x (and 2x unless only1x). It returns the files written and any page errors.

func Server

func Server() *httptest.Server

Server serves ui.FS on a loopback port for the engine to fetch from, plus the design-system sheets (not part of the shipped UI) under /__sheet/.

Types

type M

type M = map[string]any

func BaseState

func BaseState(platform string) M

BaseState is a realistic full "state" snapshot.

type Result

type Result struct {
	PNG    []byte
	Errors []string        // console errors and uncaught exceptions
	Posts  [][]interface{} // messages the page posted to Go
}

Result of rendering a scenario.

func Render

func Render(e *engine.Engine, base string, sc Scenario, scale float64) (*Result, error)

Render loads the scenario, runs its Setup and screenshots it at the given scale.

type Scenario

type Scenario struct {
	Name     string // file stem
	Page     string // path in ui.FS, e.g. chrome/index.html
	Query    string // "?k=v" appended to the URL
	W, H     int
	State    any    // JSON-marshalled and delivered as the "state" message
	Setup    string // JS run after the state arrives (open popovers, stream events...)
	Then     string // JS run after Setup has settled (for steps that need lazily loaded code)
	Backdrop string // fake web page behind the transparent viewport: article|shop|blank
	// BackdropFrom names another scenario whose screenshot is placed in the viewport hole (the engine does not paint iframes)
	BackdropFrom string
	Skip         bool // used only as a backdrop source: not written or tested on its own
	NoState      bool
}

Scenario is one screenshot: a page, a viewport, a state snapshot and a script.

func Scenarios

func Scenarios() []Scenario

Scenarios is the full preview/test matrix.

type Session

type Session struct {
	Tab *engine.Tab
	// contains filtered or unexported fields
}

Session is one loaded page that tests and previews can drive.

func Open

func Open(e *engine.Engine, base string, sc Scenario, scale float64) (*Session, error)

Open loads the scenario (init mock, navigate, deliver state) without running its Setup.

func (*Session) ClearPosts

func (s *Session) ClearPosts()

ClearPosts forgets recorded posts.

func (*Session) Errors

func (s *Session) Errors() []string

Errors returns console errors, warnings and uncaught exceptions seen so far.

func (*Session) Eval

func (s *Session) Eval(js string) (any, error)

Eval evaluates an expression and returns its JSON-decoded value.

func (*Session) PNG

func (s *Session) PNG(scale float64) []byte

PNG screenshots the page at its configured size.

func (*Session) Posts

func (s *Session) Posts() [][]interface{}

Posts returns every message the page has posted to Go so far.

func (*Session) Run

func (s *Session) Run(js string)

Run evaluates JS, recording an error if it throws.

func (*Session) Settle

func (s *Session) Settle()

Settle pumps the page's event loop long enough for chained rAF callbacks.

Jump to

Keyboard shortcuts

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