Skip to content
pixi-silk
GitHub repository
Class

SilkBundle

import { SilkBundle } from 'pixi-silk/i18n';

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.

Constructors#

Constructor#

new SilkBundle(data: ArrayBuffer | BundleData, url?: string): SilkBundle;

Parameters#

ParameterTypeDefault value
dataArrayBuffer | BundleDataundefined
urlstring''

Returns#

SilkBundle

Properties#

PropertyModifierTypeDescriptionDefined in
datareadonlyBundleDataThe raw tables.packages/pixi-silk/src/i18n/messages.ts:93
urlreadonlystringURL the bundle was loaded from, used to resolve atlas page files. Empty when unknown.packages/pixi-silk/src/i18n/messages.ts:95

Accessors#

dir#

Get Signature#

get dir(): 0 | 1;

Paragraph direction: 0 left to right, 1 right to left.

Returns

0 | 1


faces#

Get Signature#

get faces(): ReadonlyMap<number, BundleFace>;

Faces, by id.

Returns

ReadonlyMap<number, BundleFace>


glyphCount#

Get Signature#

get glyphCount(): number;

Number of atlas glyph records (record 0 is the empty glyph).

Returns

number


id#

Get Signature#

get id(): string;

The app’s code for the locale (the bundle name), such as iq for ar-IQ.

Returns

string


locale#

Get Signature#

get locale(): string;

BCP 47 locale: what plural rules and number formatting use.

Returns

string

Methods#

face()#

face(id: number): BundleFace;

Face by id. Throws when the bundle has no such face.

Parameters#

ParameterType
idnumber

Returns#

BundleFace


fastPath()#

fastPath(slot: BundleSlot): boolean;

True when number slot updates of the same length can skip layout (tabular digits baked).

Parameters#

ParameterType
slotBundleSlot

Returns#

boolean


formatNumber()#

formatNumber(slot: BundleSlot, value: number): FormattedNumber;

Formats a number for a slot with Intl.NumberFormat in the bundle’s pinned numbering system (as a percentage for slots declared percent), then maps every character through the slot’s digit table. A character the table lacks (a browser whose ICU differs) falls back to Latin digits from the same table, never to a missing glyph.

Parameters#

ParameterType
slotBundleSlot
valuenumber

Returns#

FormattedNumber


keyOf()#

keyOf(message: number): string;

Key string of a message, when the bundle keeps keys (dev builds), else its hash in hex.

Parameters#

ParameterType
messagenumber

Returns#

string


message()#

message(key: string): number;

Message index of a key, or -1.

Parameters#

ParameterType
keystring

Returns#

number


pages()#

pages(): BundlePage[];

Atlas pages the bundle draws from, in the order its glyphs refer to them.

Returns#

BundlePage[]


pluralCategory()#

pluralCategory(n: number): "zero" | "one" | "two" | "few" | "many" | "other";

Plural category of a number in the bundle’s locale. Uses the platform’s Intl.PluralRules.

Parameters#

ParameterType
nnumber

Returns#

"zero" | "one" | "two" | "few" | "many" | "other"


selector()#

selector(message: number): number;

Slot id that selects the plural variant of a message, or -1.

Parameters#

ParameterType
messagenumber

Returns#

number


slot()#

slot(id: number): BundleSlot;

Slot record.

Parameters#

ParameterType
idnumber

Returns#

BundleSlot


tag()#

tag(id: number): string;

Tag name of a tag id.

Parameters#

ParameterType
idnumber

Returns#

string


variant()#

variant(message: number, category?: "zero" | "one" | "two" | "few" | "many" | "other"): number;

Variant index for a plural category: the matching variant, else other, else the first one.

Parameters#

ParameterTypeDefault value
messagenumberundefined
category"zero" | "one" | "two" | "few" | "many" | "other"'other'

Returns#

number


variantText()#

variantText(variant: number): string;

Text of a variant, holes as U+FFFC. Empty when the bundle has none.

Parameters#

ParameterType
variantnumber

Returns#

string