Documentation
¶
Overview ¶
Package canvas recovers meaning from content that exists only as pixels.
A WebGL hero is invisible to every text parser: the words a visitor reads may be geometry in a 3D scene, or a texture, or a shader. Two attacks are worth making, in this order.
The scene graph parse is cheap and exact. A .glb or .gltf file carries names for every node, mesh and material, and authors name things after what they are -- "Chair_Oak_Backrest", "Hero_Title_Furniture". When it works it costs a few microseconds and invents nothing.
Vision captioning is the fallback, and it is the most expensive step in the whole pipeline by an order of magnitude. It runs only when a canvas is large enough to be carrying content and the scene graph yielded nothing.
Everything either produces is tagged with its provenance and a confidence, because a consumer must always be able to tell recovered pixels from real text.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotGLTF is returned when the bytes are not a scene-graph file. ErrNotGLTF = errors.New("not a glTF or GLB file") )
Functions ¶
This section is empty.
Types ¶
type Input ¶
type Input struct {
Canvases []capture.Canvas
// Assets are intercepted scene-graph files, keyed by URL.
Assets map[string][]byte
// Shots are rasterised canvas regions, keyed by canvas path.
Shots map[string]Shot
// Scene is what walking the live 3D scene produced.
Scene *capture.SceneIntrospection
// Corpus answers whether a recovered string appears in what the site
// shipped. It is a membership oracle and nothing else: it cannot be
// enumerated, and nothing in it can become content.
Corpus *corroborate.Index
}
Input is everything recovery has to work with.
type Options ¶
type Options struct {
// EnableVision turns on the vision model. It is off by default, and that
// default is a security property rather than a cost saving: with vision
// disabled the artifact structurally cannot contain invented text.
// Enabling it is an explicit, logged, budgeted choice.
EnableVision bool
// VisionModel and VisionBudget bound the expensive path.
VisionModel string
VisionBudget int64
// APIKey overrides the environment.
APIKey string
// before vision is worth spending on it.
ViewportShareGate float64
// MaxVisionCalls is a hard ceiling per job.
MaxVisionCalls int
// OCR is an optional external recogniser. OCR is near-free, deterministic,
// and fails loudly -- garbage output is obviously garbage -- whereas vision
// fails quietly and confidently. So it runs first when available.
OCR OCRFunc
// Logf receives progress lines.
Logf func(format string, args ...any)
}
Options configures recovery.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns settings with vision off.
type Recoverer ¶
type Recoverer struct {
// contains filtered or unexported fields
}
Recoverer runs the attacks in order.
func (*Recoverer) Recover ¶
Recover attempts each canvas, cheapest and most exact attack first.
The order is not arbitrary. Each rung is both cheaper and more trustworthy than the one below it, so the first that succeeds is also the best answer available:
- The canvas element's own accessibility fallback. Authored by the site, exact, free. Most tools ignore it entirely.
- The live scene graph, walked in the page. Catches procedurally built scenes that never loaded an asset file.
- Intercepted .glb / .gltf assets. Exact when the author named things.
- OCR. Deterministic, near-free, and it fails loudly.
- Vision. Expensive, slow, and it fails quietly and confidently -- which is why it is last and off by default.
Anything from rungs 4 and 5 is a guess about pixels, so it is cross-checked against the text the site shipped before it is allowed to count.
type Recovery ¶
type Recovery struct {
CanvasPath string
Text string
Source graph.Source
Score float64
// Confirmed reports that the text was found in the payload the site
// shipped. For a guess about pixels this is the difference between
// evidence and invention.
Confirmed bool
// ConfirmedBy is the fragment that matched, for the audit trail.
ConfirmedBy string
BBox [4]float64
}
Recovery is one canvas's worth of recovered meaning.
type Scene ¶
type Scene struct {
// Source is the asset URL.
Source string
// Generator is the tool that authored the file, from asset.generator.
Generator string
// Copyright is asset.copyright, which occasionally carries the real
// attribution for a model.
Copyright string
// Names are the meaningful node, mesh and material names, deduplicated and
// in the order they appeared.
Names []string
// Text is any string found in an `extras` block, where authors and
// exporters put annotations, labels and descriptions.
Text []string
// Nodes and Meshes are raw counts, useful for judging how substantial the
// scene is.
Nodes int
Meshes int
}
Scene is what a scene-graph file gave up.
func ParseAsset ¶
ParseAsset parses either a binary GLB or a JSON glTF.