viz

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package viz bundles the scenes of the nodes (spec 10) and checks their traces.

A scene is viz/scene.ts. It imports only "@prog/viz". Build bundles it with esbuild into a script that registers the scene in window.AlgoScenes. The player of the site runs it in the browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(scenePath string, minify bool) ([]byte, error)

Build bundles the scene file into a browser script. The script sets window.AlgoScenes[slug] to the scene, and window.AlgoViz to the runtime.

func Core

func Core() string

Core is the source of @prog/viz.

func Probe

func Probe(src []byte, file string) ([]byte, error)

Probe turns each "// @line" marker of a TypeScript reference into a probe call, and compiles the result to a CommonJS script (rule V06). The probe is the global function __probe(id), which returns true.

The probe goes where the line runs:

  • On an if, an else if or a while, the probe is the first part of the condition, so it runs each time the condition is tested, also the last time.
  • On a for loop with three clauses, the probe is the first part of the test, so it also runs each time the test runs. On a for of loop, the probe is the first statement of the body.
  • On an else, the probe is the first statement of the block.
  • On any other line, the probe is a statement before the code of the line.

A line with code that continues the line before it, such as the second line of a long call, cannot carry a marker.

func Reference

func Reference(src, path string) ([]byte, error)

Reference gives the Scene fields of the TypeScript reference src, the file path, for V06. An empty src gives no reference.

Types

type Preset

type Preset struct {
	Name  string `json:"name"`
	Input any    `json:"input"`
}

Preset is a named input of a scene.

type Report

type Report struct {
	Slug    string   `json:"slug"`
	Fails   []string `json:"fails"`
	Lines   []string `json:"lines"` // the line ids that the presets reach
	Steps   []int    `json:"steps"` // the number of steps of each preset
	Skipped string   `json:"skipped,omitempty"`
}

Report is the result of checking one scene.

func Check

func Check(sc Scene) Report

Check runs the bundled scene in Node on each preset (rules V01, V02, V04, V05, V06, V10, and the state vocabulary of V09). It also checks that each event names a view of its kind. When the scene has a reference, it runs the reference on each preset and compares the lines (V06). Without Node, the check is skipped and says so.

type Scene

type Scene struct {
	Slug    string
	Bundle  []byte   // the output of Build
	Presets []Preset // the presets of viz/presets.yaml
	IDs     []string // the line ids of the main pseudocode block of the page
	// Ref is the TypeScript reference after Probe, or nil when the node has none. RefErr is the error of Probe, which V06 reports.
	Ref    []byte
	RefErr error
}

Scene is what Check needs to check one scene.

Jump to

Keyboard shortcuts

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