pixi-silk/i18n
Baked localized text, renderer-agnostic core: reads .silk bundles from @pixi-silk/compiler, picks plural variants, formats number slots and lays out lines from baked data. No Pixi, no Unicode tables.
import { HeadlessBackend, LayoutCache, SilkBundle, SilkBundleError } from 'pixi-silk/i18n';
Classes#
| Class | Description |
|---|---|
| HeadlessBackend | A reference backend with no GPU: it keeps everything in arrays and rasterizes the fill of every glyph and line into an RGBA buffer on the CPU (bilinear distance samples, one-pixel ramp). Slow, and with no outline, glow or shadow: it exists to prove the core needs no renderer, and for tests. |
| LayoutCache | A least-recently-used cache of laid out messages with a memory budget (brief sec. 8). Messages that show the same variant, values, size and width share one layout. Entries are immutable: a message that updates a slot in place clones its layout first (cloneLayout). |
| SilkBundle | A loaded .silk bundle (brief sec. 5) with lookups: messages by key, faces by id, slots, tags, variants by plural category, and number formatting through the baked digit tables. Holds typed arrays over the fetched buffer and decodes nothing up front. |
| SilkBundleError | Thrown when a buffer is not a .silk bundle this runtime can read. |
| StyleTable | The style rows of a theme: one row per unique stack of tags in use (the base style, then each tag from the outermost in). Rows are packed by packStyle into one Float32Array, ready to upload as a data texture. Changing a paint property rewrites only the rows that include that tag. |
Interfaces#
| Interface | Description |
|---|---|
| BundleData | Everything a .silk bundle holds, as typed arrays. The reader returns views over the fetched buffer, and the compiler builds one of these and writes it. Record layouts are in format.ts. |
| BundleFace | A face of a bundle. |
| BundlePage | An atlas page a bundle draws from. |
| BundleRuns | The columns of the RUNS section: one entry per shaped glyph. |
| BundleSlot | A slot of a bundle. |
| FormattedNumber | A formatted number slot: one glyph per output character. |
| InlineMetrics | Size of an inline object such as <coin/>, in em of the message size. |
| LayoutBox | A box in local pixels. |
| MessageLayout | A laid out message: instances ready to upload, plus boxes for objects, text slots and taps. |
| MessageLayoutOptions | Options of layoutMessage. |
| RowLayout | How a style row changes layout compared with what was baked. |
| RunSprite | A text slot drawn by the dynamic path: a single-channel SDF bitmap of the whole value, drawn as one glyph with the slot’s style, plus the colour pixels of any emoji. |
| RuntimeShaper | A runtime shaper for one font file. |
| ShapedGlyphOut | One shaped glyph, in visual order, font units. |
| SilkBackend | What a renderer implements to draw baked text (brief sec. 2.3). The core lays out and writes instances (INSTANCE_FLOATS floats each) and style rows (STYLE_FLOATS floats each). A backend stores and draws them. pixi-silk/i18n/pixi is the PixiJS one, HeadlessBackend a software reference. |
| SlotPlacement | A number slot as laid out, for value-fast updates. |
| StoredPage | An atlas page as HeadlessBackend stores it. |
| StyleChange | What a StyleTable.set changed. |
| TextBufferHandle | A text buffer a backend made. |
| ThemeData | A theme file, $silk: 2. |
| ThemeGlow | A soft halo around the glyphs. |
| ThemeLine | A line under or through the glyphs. |
| ThemeOutline | A line around the glyphs. |
| ThemeShadow | A blurred copy under the glyphs, moved by an offset. |
| ThemeStyle | One style. Every field is optional: a tag’s style overrides only what it sets. |
Type Aliases#
| Type Alias | Description |
|---|---|
| MessageAlign | Horizontal alignment. start and end follow the locale’s direction. |
| PluralCategory | A CLDR plural category. |
Variables#
| Variable | Description |
|---|---|
| BundleFlag | Header flags. |
| DIGIT_ENTRY_STRIDE | Int32 per digit table entry: code point, glyph index (-1 for a zero-width mark), advance (font units). |
| DIGIT_STRIDE | Uint32 per digit table: face, numbering system ref, first entry, entry count, tabular advance, flags. |
| FACE_STRIDE | Int32 per face: face id, units per em, hash low, hash high, ascender, descender, line gap, family ref, weight. |
| GLYPH_STRIDE | Int16 per atlas glyph: page, x, y, w, h (atlas pixels), planeL, planeB, planeR, planeT (font units), face. |
| HEADER_BYTES | Bytes before the section table. |
| INSTANCE_FLOATS | Floats per glyph instance: x, y, scale, glyph, style row, kind, size, width. |
| InstanceKind | What an instance draws. |
| LAYOUT_ALIGNS | Align codes of baked layouts. |
| LAYOUT_STRIDE | Float32 per baked layout (LAYOUTS, brief sec. 5): variant, size, max width, align (0 start, 1 end, 2 left, 3 center, 4 right), line height, first instance, instance count, width, height, first line, line count, 0. Instances use INSTANCE_FLOATS floats with a stack index in place of the style row. Lines are 3 floats: baseline, left, right. |
| MESSAGE_STRIDE | Uint32 per message: key hash, key string ref (or NONE), selector slot (or NONE), first variant, variant count, flags. |
| NONE | “No value” in u32 fields. |
| PAGE_STRIDE | Float32 per page: page id, file ref, kind, width, height, distance range (atlas px), em size (atlas px per em). |
| PageKind | Glyph kinds of atlas pages. |
| PAINT_PROPERTIES | Properties that change only paint: live-editable at runtime. |
| PLURAL_CATEGORIES | Plural categories in the order the VARIANTS section stores them. |
| RunFlag | Per-glyph flags in the RUNS flags column. |
| Section | Section ids. |
| SECTION_ENTRY_BYTES | Bytes per section table entry. |
| SEGMENT_STRIDE | Uint32 per segment: kind, a, b, c, bidi level. Static: run start, run length, face. Slot: slot id, text offset, RunFlag bits. Object: tag id, text offset, RunFlag bits. |
| SegmentKind | Kinds of message segments. |
| SHADOW_MAX_BLUR | Shadow blur at softness: 1, in pixels at scale 1. |
| SHAPE_PROPERTIES | Properties that change shaping or advances: they need a recompile or a runtime shaper. |
| SILK_MAGIC | SILK read as a little-endian u32. |
| SILK_MAJOR | Major version this runtime reads. A bundle with another major is refused. |
| SILK_MINOR | Minor version this runtime was written for. A newer minor loads with a warning. |
| SLOT_STRIDE | Uint32 per slot: name ref, type, max digits or chars, digit table (or NONE), flags, face. |
| SlotFlag | Slot flags. |
| SlotType | Types of slots. |
| SPAN_STRIDE | Uint16 per span: tag id, start segment, start cluster, end segment, end cluster (end exclusive). |
| STYLE_FLOATS | Floats per style row. |
| STYLE_TEXELS | RGBA32F texels per style row. |
| StyleFlag | Style row flags (texel 7, z). |
| VARIANT_STRIDE | Uint32 per variant: plural category index, first segment, segment count, first span, span count, base level, text string ref (the variant’s characters with U+FFFC for holes, for accessibility). |
Functions#
| Function | Description |
|---|---|
| align8 | Rounds n up to the next multiple of 8. |
| bundleCounts | Number of faces, pages and digit tables, for diagnostics. |
| cloneLayout | A copy of a layout whose instances and number slots can change without touching the original. |
| digitGlyph | Digit table entry for code point cp in table table, as [glyph, advance], or null. |
| effectReach | How far the paint effects of a style reach past the glyph edge, in pixels at scale 1: the largest of the outline width, the glow width and the shadow blur. The compiler sizes the atlas distance range from it. |
| findMessage | Index of the message with key hash hash (binary search), or -1. |
| fontHash | 64-bit FNV-1a of font bytes as 16 hex digits: the hash the compiler stores per face. Compare it with SilkBundle.faces.get(id).hash before shaping with a font at runtime. |
| hashKey | 32-bit FNV-1a hash of a message key, over its UTF-16 code units. Production bundles store only this. The compiler fails when two keys of one bundle collide. |
| isLittleEndian | True on little-endian platforms. The format is little-endian and typed arrays use the platform order. |
| layoutMessage | Lays out one variant of a message from baked data (brief sec. 6.2): greedy line filling over the baked advances, breaking only where the compiler marked a break opportunity, then visual reordering of every line from the baked bidi levels. No shaping and no Unicode tables. Number slots map their characters through the digit tables. Text slots and inline objects are boxes. A layout the compiler baked for exactly these options is returned as is (baked: true). |
| mergeStyles | Merges styles left to right: later ones override the fields they set. null removes an effect. |
| packStyle | Packs a resolved style into one style row of STYLE_FLOATS floats at offset: |
| parseHex | #rgb, #rgba, #rrggbb or #rrggbbaa as linear-free 0 to 1 RGBA, or null. |
| propertyClass | paint, shape or behaviour for a style property. The compiler and the runtime both use this table. |
| readBundle | Reads a .silk bundle without copying: every table is a typed-array view over buffer, and only the string table is decoded. Throws SilkBundleError on a wrong magic, another major version, a truncated buffer or a misaligned section. A newer minor version calls warn. |
| reorder | Visual order of a line from its levels (UAX #9 rule L2). |
| sameFont | True when a shaper’s font is the one a bundle face was baked from. When it is not, the brief’s rule applies: warn, and keep the baked data for static text. |
| shapeKey | Shape-relevant fields of a style, the part that decides how text is shaped. |
| submitLayout | pixi-silk/i18n: the renderer-agnostic core of baked localized text. Reads .silk bundles made by @pixi-silk/compiler, resolves messages and plural variants, formats number slots from baked digit tables, lays out lines from baked advances and break flags, and writes glyph instances. It imports no Pixi code and carries no Unicode data tables. pixi-silk/i18n/pixi draws it. |
| updateNumberSlot | Rewrites the glyphs of a number slot in place when the new value has as many characters, each with the advance of the one it replaces (brief sec. 6.3, value-fast): no layout, no allocation beyond the formatting. Returns false when the caller must lay out again. |
| validateTheme | Checks a parsed theme file. Returns problems as sentences. An empty list means the theme is valid. |