Documentation
¶
Overview ¶
Package kinds resolves what kind an icon-pack item is (icon or illustration) from the pack's config.json, and suggests kinds for items a human has not classified. It is the Go side of the "kinds and flavours" contract; core's Support\KindResolver and Support\KindGlob are the PHP side, and the glob vector table and heuristic constants are identical in both.
Index ¶
Constants ¶
const ( // HeuristicAspectMin and HeuristicAspectMax bound the viewBox width/height // ratio an icon is expected to sit inside. HeuristicAspectMin = 0.8 HeuristicAspectMax = 1.25 // HeuristicPaletteMin is the number of distinct literal colours that fires. HeuristicPaletteMin = 4 // HeuristicBytesMax and HeuristicElementsMax fire when exceeded. HeuristicBytesMax = 20_000 HeuristicElementsMax = 150 // HeuristicCanvasMax fires when the larger viewBox side exceeds it. HeuristicCanvasMax = 256 // HeuristicMinSignals is how many signals must fire to suggest. HeuristicMinSignals = 3 // HeuristicGroupMin is how many items a folder needs before its suggestions // collapse into one rule (at least 80% of them suggested). HeuristicGroupMin = 5 )
The row 7 heuristic (contract section 3). It looks at an SVG's shape and suggests that a human reclassify it. It never decides anything: no code path here writes a kind anywhere.
These constants are identical in core (IchavaConstants::KIND_HEURISTIC_*).
const ( SignalAspect = "aspect" SignalPalette = "palette" SignalBytes = "bytes" SignalElements = "elements" SignalCanvas = "canvas" )
Signal ids.
const ( IssueInvalidValue = "kind.invalid_value" IssueInvalidGlob = "kind.invalid_glob" )
Issue codes.
Variables ¶
This section is empty.
Functions ¶
func CategoryOf ¶
CategoryOf is the category an item files under: its first folder, slugged, or "" for a file at the pack's root. This is IconClassifier::categoryOf for an item path. The slug is Str::slug's for ASCII (lower case, runs of anything else become one "-"); non-ASCII letters are not transliterated.
func Qualifies ¶
Qualifies applies the suggestion rule: enough signals, and at least one of them is bytes or elements. That requirement keeps flags out (4:3, multicolour, small).
func WriteRecords ¶
WriteRecords writes a pack's suggestions as a JSON array, replacing the file atomically. An empty list is written as [] so a reader can tell "ran, found nothing" from "never ran".
Types ¶
type Config ¶
type Config struct {
// Issues lists every entry that was dropped, in document order where the
// document has one.
Issues []Issue
// contains filtered or unexported fields
}
Config is the kind-relevant part of a pack's resources/assets/svg/config.json.
func ParseConfig ¶
ParseConfig reads a pack's config.json.
It mirrors core's PackConfigData: the documented shape is metadata.data.<section>, the top-level key is a fallback, and the documented section wins whenever it holds anything. An entry that names no valid kind or glob is dropped and recorded in Issues rather than failing the pack.
func (*Config) Resolve ¶
func (c *Config) Resolve(itemPath string) Resolution
Resolve decides one item's kind. The first row that yields a kind wins: item, then the first matching rule, then category, then the pack, then icon. It reads nothing but the config, so it is the same answer at any time.
func (*Config) ThemeSuffixes ¶
ThemeSuffixes returns the filename suffixes (before ".svg") of the theme twins the item's category declares, in theme-name order. A file whose stem ends in one of them, beside a light sibling, is a twin and not an item.
type Glob ¶
type Glob struct {
// contains filtered or unexported fields
}
Glob is a compiled item-path pattern (contract section 1.2). In a pattern, "*" is zero or more characters other than "/", "?" is exactly one character other than "/", and "**" is zero or more whole segments (it must be a whole segment).
The match is anchored (the whole path) and case-sensitive. Everything else is literal. It is matched segment by segment rather than compiled to a regexp, which keeps "never /" true by construction and makes the cost bounded.
type Issue ¶
type Issue struct {
Code string `json:"code"` // kind.invalid_value or kind.invalid_glob
Where string `json:"where"` // the key path
Detail string `json:"detail"` // what is wrong
}
Issue is something wrong in a pack's kind keys. Codes match core's doctor check ids, so one vocabulary covers both tools.
type Kind ¶
type Kind string
Kind is what an item is. The values are the ones core's IconKind enum and js-ui-kernel's IconKind union use.
The two kinds. There is no "mixed": a pack is mixed when its items resolve to more than one kind, and that is derived, never declared.
type Metrics ¶
type Metrics struct {
Bytes int64
Elements int
// HasViewBox is true only for a viewBox with four numbers and a positive
// width and height. Width and height attributes are not consulted.
HasViewBox bool
Width, Height float64
// Colours are the distinct literal paint colours, normalised: hex as
// lowercase #rrggbb (alpha dropped), rgb()/rgba() converted to the same, a
// named colour as its lowercase name. none, transparent, currentColor,
// inherit and anything that is not a literal (url(), var(), hsl()) are not
// colours here.
Colours []string
}
Metrics are the measured facts about one SVG.
type Record ¶
type Record struct {
Package string `json:"package"`
Path string `json:"path"`
Current Current `json:"current"`
Suggested Kind `json:"suggested"`
Signals []Signal `json:"signals"`
Accept map[string]any `json:"accept"`
}
Record is one suggestion, the same JSON shape core's doctor emits. A human accepts it by merging Accept into the pack's config.json; nothing here does.
type Resolution ¶
type Resolution struct {
Kind Kind
Source Source
// Rule is the matching rule's pattern (SourceRule) or the category slug
// (SourceCategory), and empty otherwise.
Rule string
}
Resolution is the outcome for one item.
type ScanResult ¶
type ScanResult struct {
Records []Record
// Items is the number of items looked at: every .svg under files/ that is
// not a theme twin, whether or not it could be measured.
Items int
// Skipped lists items that could not be measured, with the reason.
Skipped []string
// Issues are problems in the pack's own kind keys.
Issues []Issue
}
ScanResult is everything a scan found.
func Scan ¶
func Scan(pkg, svgDir string, mode Mode) (*ScanResult, error)
Scan measures every item in a pack and returns the suggestions.
svgDir is the pack's resources/assets/svg directory: config.json beside a files/ tree. It only reads. A missing config.json is a pack with no kind keys, and every item then reads icon/default.