pagemap

package
v4.0.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pagemap encodes a rendered page into the Gothic page-view payload: the page's own colour palette, one letter per grid cell, the DOM regions the cells land in, and the alerts the raster itself implies (palette coverage, edge bleed, overflow). Everything after the PNG is a pure function of the raster plus the DOM manifest, so the encoder is testable against fixture PNGs with no browser and no timing.

Index

Constants

View Source
const (
	DefaultGridW = 48
	DefaultGridH = 24
)

Locked defaults: the grid shape and the palette size.

View Source
const DefaultMaxColors = 10

DefaultMaxColors is the palette size the encoder quantizes to. A UI page has a couple dozen real colours plus an antialiasing tail; the top exact colours carry the layout, and every other pixel snaps to the nearest one.

Variables

This section is empty.

Functions

func Encode

func Encode(img image.Image, m *Manifest, opts Options) string

Encode turns a rendered page into the page-view payload a text-only model reads: grid = geometry and colour, legend = identity and content, alerts = the conclusions. img is the full-resolution screenshot; m the DOM manifest (nil is allowed and simply produces no regions and no manifest-derived alerts).

Types

type Alert

type Alert struct {
	Summary string
	Bullets []string
}

Alert is one derived warning: a headline plus indented bullets that carry the conclusion. Thresholds live as named constants so they read as policy.

type Color

type Color struct{ R, G, B, A uint8 }

Color is one exact sRGB colour with alpha. It is the currency the whole encoder works in and doubles as a hash-map key for the exact-colour histogram.

func (Color) Hex

func (c Color) Hex() string

Hex renders the colour the way the payload prints it. Alpha is not printed: a page view is built from an opaque compositor screenshot.

type Element

type Element struct {
	Selector  string  `json:"sel"`
	X         float64 `json:"x"`
	Y         float64 `json:"y"`
	W         float64 `json:"w"`
	H         float64 `json:"h"`
	BG        string  `json:"bg"`        // computed background-color, "" or "transparent" when none
	FG        string  `json:"fg"`        // computed color
	Overflows bool    `json:"overflows"` // scrollWidth > clientWidth at capture time
}

Element is one visible element's rect and computed colours.

type Grid

type Grid struct {
	Cols, Rows int
	Width      int // source raster size in pixels
	Height     int
	Cells      []int // len = Rows*Cols, row-major palette index per cell
}

Grid is the raster downsampled to one palette class per cell. The cell stores a palette index — the class its pixels BELONG to, never an average: averaging a purple button into a dark background is exactly the blend that makes the widget unreadable, and the mode keeps it.

func (Grid) ClassAt

func (g Grid) ClassAt(row, col int) int

ClassAt returns the palette index of the cell at (row, col).

type Manifest

type Manifest struct {
	Scroll [2]float64 `json:"scroll"` // [scrollX, scrollY] at capture time
	Rects  []Element  `json:"rects"`
}

Manifest is the DOM-side document the browser layer writes next to the screenshot: the scroll position plus, for every visible element, its viewport rect and the computed colours worth checking against the raster. The browser layer produces it with one page.Eval() — this package only consumes it.

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

ParseManifest decodes the DOM manifest JSON.

type Options

type Options struct {
	URL       string
	Engine    string
	ViewportW int
	ViewportH int
	GridW     int
	GridH     int
}

Options carries what the raster alone cannot tell the encoder. URL and Engine are capture metadata; ViewportW/H override the reported viewport (0 = use the raster size); GridW/H are the cell grid (0 = 48x24).

type Palette

type Palette struct {
	Entries []PaletteEntry
}

Palette is an extracted colour palette, sorted by pixel frequency with the dominant (background) colour first.

func (Palette) Dominant

func (p Palette) Dominant() PaletteEntry

Dominant returns the most frequent colour — the page's background.

func (Palette) Len

func (p Palette) Len() int

Len returns the number of palette entries.

type PaletteEntry

type PaletteEntry struct {
	Color Color
	Hex   string
	Exact int     // pixels whose colour is exactly this one
	Share float64 // 0..1, share of all pixels after the tail snapped
}

PaletteEntry is one palette slot: an exact colour from the raster, how many pixels carried it verbatim, and its share of the image once the antialiasing tail snapped to the nearest palette entry.

type Region

type Region struct {
	Selector string
	// RowFrom/RowTo and ColFrom/ColTo are INCLUSIVE cell spans.
	RowFrom, RowTo int
	ColFrom, ColTo int
	X0, X1         int    // the element's pixel span, clipped to the raster
	DeclaredHex    string // parsed BG as hex, "" when none/transparent
	RenderedHex    string // hex of the palette class dominating the region, "" when none
	// contains filtered or unexported fields
}

Region is one element's footprint on the grid: the cell span its own pixels land in and the palette class dominating them.

Jump to

Keyboard shortcuts

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