thumbtypes

package
v1.136.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package thumbtypes names the content families a browser can rasterize into a tile, and which of them are drawn on a forced background and so need a second capture for dark mode.

It exists because the rule was written out four times -- once per store, once for the browser gate, once for the capturer's dispatch -- and the four copies stopped agreeing: a JSX resource was never offered although the capturer renders JSX, and an image asset was never offered although the capturer downscales images (#1568). This is the one Go definition; the one TypeScript definition is ui/src/lib/thumbnailSupport.ts, and TestGoAndBrowserAgree holds the two to each other.

A thumbnail is a property of a piece of content rather than of a kind, so nothing here knows whether the row it is asked about is a portal asset or a managed resource.

Index

Constants

View Source
const DefaultSourceLimit = 1 << 20 // 1 MB

DefaultSourceLimit is the largest document a tile is drawn from. A tile is drawn by loading the whole document into the renderer beside the platform, whose memory is sized for documents, not archives; above it a file keeps its content-type icon (#1351).

View Source
const LargeSourceLimit = 32 << 20 // 32 MB

LargeSourceLimit is the bound the families in LargeSourceFamilies are held to instead.

Variables

View Source
var Capturable = slices.Concat(svgTypes, pdfTypes, documentTypes, markdownTypes, tableTypes,
	jsonTypes, codeTypes, rasterTypes)

Capturable names every content type a browser can draw into a tile, in the order the entries are tried: a type belongs to the family of the FIRST entry it matches.

Everything else -- spreadsheets, word-processing documents, presentations, archives, binaries -- has no renderer, keeps its content-type icon, and is never offered for capture.

View Source
var HeadDrawnFamilies = tableTypes

HeadDrawnFamilies are the families whose tile is drawn from the head of the document rather than from the whole of it.

A table's tile is its header row and its first rows -- the tile page keeps ten of them -- so the rest of the document is parsed, copied through a JavaScript string and discarded. The worker cuts the file at a record boundary before the tile page is built, which is what makes the raised bound above safe for these two (#1802).

PDF is NOT here although only its first page is drawn: its bytes travel to the tile page by URL and pdf.js reads the pages it needs itself, so there is nothing for the worker to cut.

View Source
var LargeSourceFamilies = slices.Concat(pdfTypes, tableTypes)

LargeSourceFamilies are the families whose source bound is LargeSourceLimit rather than DefaultSourceLimit.

What the default bound protects against is the renderer holding a whole document. A family is here when its tile costs less of that than the file's size suggests, because the tile is drawn from a part of the file rather than from all of it.

PDF: the tile page decodes page one and nothing else, and the default bound would leave the feature looking broken on the documents it exists for -- one letter page scanned at 300dpi measures about 2 MB, twice the default, so most scanned PDFs would keep an icon (#1794). A 26 MB, 12-page scan drew in 2.7s with the renderer at 291 MiB.

CSV and TSV: the tile is the header row and the first rows, so the worker hands the renderer the head of the file and nothing else (HeadDrawnFamilies). A CSV is the family most likely to be large -- it is what an export produces, what a script lands on a schedule, and what a person uploads to register as a table -- and at the default bound the files people upload most kept an icon while the small ones tiled (#1802).

The bound is still the most the worker reads from the object store for a tile, which is why a family here has one at all. Every other family is held to DefaultSourceLimit, because every other family is laid out in full to be drawn.

View Source
var Themeable = slices.Concat(documentTypes, markdownTypes, tableTypes, jsonTypes, codeTypes)

Themeable are the families drawn once per color scheme.

The families the portal lays out on its own surface are drawn on the scheme's background. HTML and JSX are drawn with the renderer emulating the scheme, which is what a document's own prefers-color-scheme rules answer to and what the viewer's frame does for a reader in that scheme: a dashboard with a dark stylesheet opened dark and had a white card (#1789). SVG, PDF and a raster image are drawn as stored and serve the one image in both modes, so reading their empty dark key as "pending" would offer them forever.

In Capturable's order, which is what the parity test compares.

Functions

func DrawnAsDocument added in v1.133.0

func DrawnAsDocument(contentType string) bool

DrawnAsDocument reports whether contentType is a document that lays itself out at page size -- HTML and JSX -- rather than a family the portal lays out on its own tile-sized surface. The two are drawn at different geometries.

func DrawnFromHead added in v1.133.3

func DrawnFromHead(contentType string) bool

DrawnFromHead reports whether a tile of contentType is drawn from the head of the document, so the worker may hand the tile page a prefix of it.

The family is the FIRST Capturable entry the type matches, as it is everywhere else here.

func IsThemeable added in v1.133.0

func IsThemeable(contentType string) bool

IsThemeable reports whether contentType is drawn on a forced background and so has a tile per color scheme.

A content type belongs to the family of the FIRST Capturable entry it matches, which is how Capturable's order resolves overlaps: image/svg+xml matches both "image/svg+xml" and "%+xml", is an SVG, and is drawn as stored. Asking only "does it match a themeable entry" would call it themeable, and a store asking that would owe every SVG a dark tile nothing ever draws.

func Patterns added in v1.136.0

func Patterns(entries []string) []string

Patterns are the SQL ILIKE patterns that ask of a column what matches asks of one value: every spelling of each type (contenttype.Spellings), bare and with parameters, and each structured suffix likewise. A type is stored canonical, lowercase and parameter-free when the platform writes it, so the other forms cover rows written before it did; ILIKE ignores case either way.

func SourceLimit added in v1.133.2

func SourceLimit(contentType string) int64

SourceLimit is the largest document of contentType's family a tile is drawn from.

The family is the FIRST Capturable entry the type matches, as it is everywhere else here, so a bound is raised for the family a type is actually drawn as rather than for any entry it would also match.

func SourceLimitExpr added in v1.133.2

func SourceLimitExpr(sizeCol, typeCol, familiesPlaceholder string) string

SourceLimitExpr is the same bound as a SQL predicate, over the column holding a row's stored size and the column holding its content type. familiesPlaceholder is where the caller binds Patterns(LargeSourceFamilies), in the placeholder style its own statement is written in ("?" for a builder that renumbers, "$3" for a hand-numbered statement).

The two limits are written into the expression rather than bound, so the whole rule is one fragment: a caller that had to append them as arguments could append them in the wrong order and still compile.

func ThemeableShadows added in v1.133.0

func ThemeableShadows() []string

ThemeableShadows are the entries that are not themeable and come before the themeable ones in Capturable's order. A content type is themeable exactly when it matches a themeable entry and none of these, which is the form a store's SQL asks it in. That is exact only while every such entry precedes all the themeable ones; a test holds the order to it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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