Skip to content
pixi-silk
GitHub repository
Entry point

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#

ClassDescription
HeadlessBackendA 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.
LayoutCacheA 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).
SilkBundleA 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.
SilkBundleErrorThrown when a buffer is not a .silk bundle this runtime can read.
StyleTableThe 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#

InterfaceDescription
BundleDataEverything 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.
BundleFaceA face of a bundle.
BundlePageAn atlas page a bundle draws from.
BundleRunsThe columns of the RUNS section: one entry per shaped glyph.
BundleSlotA slot of a bundle.
FormattedNumberA formatted number slot: one glyph per output character.
InlineMetricsSize of an inline object such as <coin/>, in em of the message size.
LayoutBoxA box in local pixels.
MessageLayoutA laid out message: instances ready to upload, plus boxes for objects, text slots and taps.
MessageLayoutOptionsOptions of layoutMessage.
RowLayoutHow a style row changes layout compared with what was baked.
RunSpriteA 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.
RuntimeShaperA runtime shaper for one font file.
ShapedGlyphOutOne shaped glyph, in visual order, font units.
SilkBackendWhat 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.
SlotPlacementA number slot as laid out, for value-fast updates.
StoredPageAn atlas page as HeadlessBackend stores it.
StyleChangeWhat a StyleTable.set changed.
TextBufferHandleA text buffer a backend made.
ThemeDataA theme file, $silk: 2.
ThemeGlowA soft halo around the glyphs.
ThemeLineA line under or through the glyphs.
ThemeOutlineA line around the glyphs.
ThemeShadowA blurred copy under the glyphs, moved by an offset.
ThemeStyleOne style. Every field is optional: a tag’s style overrides only what it sets.

Type Aliases#

Type AliasDescription
MessageAlignHorizontal alignment. start and end follow the locale’s direction.
PluralCategoryA CLDR plural category.

Variables#

VariableDescription
BundleFlagHeader flags.
DIGIT_ENTRY_STRIDEInt32 per digit table entry: code point, glyph index (-1 for a zero-width mark), advance (font units).
DIGIT_STRIDEUint32 per digit table: face, numbering system ref, first entry, entry count, tabular advance, flags.
FACE_STRIDEInt32 per face: face id, units per em, hash low, hash high, ascender, descender, line gap, family ref, weight.
GLYPH_STRIDEInt16 per atlas glyph: page, x, y, w, h (atlas pixels), planeL, planeB, planeR, planeT (font units), face.
HEADER_BYTESBytes before the section table.
INSTANCE_FLOATSFloats per glyph instance: x, y, scale, glyph, style row, kind, size, width.
InstanceKindWhat an instance draws.
LAYOUT_ALIGNSAlign codes of baked layouts.
LAYOUT_STRIDEFloat32 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_STRIDEUint32 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_STRIDEFloat32 per page: page id, file ref, kind, width, height, distance range (atlas px), em size (atlas px per em).
PageKindGlyph kinds of atlas pages.
PAINT_PROPERTIESProperties that change only paint: live-editable at runtime.
PLURAL_CATEGORIESPlural categories in the order the VARIANTS section stores them.
RunFlagPer-glyph flags in the RUNS flags column.
SectionSection ids.
SECTION_ENTRY_BYTESBytes per section table entry.
SEGMENT_STRIDEUint32 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.
SegmentKindKinds of message segments.
SHADOW_MAX_BLURShadow blur at softness: 1, in pixels at scale 1.
SHAPE_PROPERTIESProperties that change shaping or advances: they need a recompile or a runtime shaper.
SILK_MAGICSILK read as a little-endian u32.
SILK_MAJORMajor version this runtime reads. A bundle with another major is refused.
SILK_MINORMinor version this runtime was written for. A newer minor loads with a warning.
SLOT_STRIDEUint32 per slot: name ref, type, max digits or chars, digit table (or NONE), flags, face.
SlotFlagSlot flags.
SlotTypeTypes of slots.
SPAN_STRIDEUint16 per span: tag id, start segment, start cluster, end segment, end cluster (end exclusive).
STYLE_FLOATSFloats per style row.
STYLE_TEXELSRGBA32F texels per style row.
StyleFlagStyle row flags (texel 7, z).
VARIANT_STRIDEUint32 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#

FunctionDescription
align8Rounds n up to the next multiple of 8.
bundleCountsNumber of faces, pages and digit tables, for diagnostics.
cloneLayoutA copy of a layout whose instances and number slots can change without touching the original.
digitGlyphDigit table entry for code point cp in table table, as [glyph, advance], or null.
effectReachHow 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.
findMessageIndex of the message with key hash hash (binary search), or -1.
fontHash64-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.
hashKey32-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.
isLittleEndianTrue on little-endian platforms. The format is little-endian and typed arrays use the platform order.
layoutMessageLays 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).
mergeStylesMerges styles left to right: later ones override the fields they set. null removes an effect.
packStylePacks 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.
propertyClasspaint, shape or behaviour for a style property. The compiler and the runtime both use this table.
readBundleReads 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.
reorderVisual order of a line from its levels (UAX #9 rule L2).
sameFontTrue 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.
shapeKeyShape-relevant fields of a style, the part that decides how text is shaped.
submitLayoutpixi-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.
updateNumberSlotRewrites 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.
validateThemeChecks a parsed theme file. Returns problems as sentences. An empty list means the theme is valid.