Skip to content

NamedStyles

Named-style CRUD, accessible via styleManager.named.

Named styles live alongside the anonymous style pool on the same StyleManager. Anonymous styles may inherit from them via Style.extendsStyle, which is stored as an opaque pointer (resolution of inherited properties is the view layer’s concern).

Storage of the named-style map is owned by this class. Mutations that affect anonymous styles (delete, rename) call back into the owning StyleManager to rewrite extendsStyle pointers and rebuild the dedup cache.

Note the asymmetry on names that don’t exist: delete returns false (idempotent, deleting nothing still yields the requested post-state, “the entry does not exist”), while rename throws (a rename of a non-existent source has no defined target, so more likely to be a mistake on the part of the caller).

const styles = styleManager.named;
styles.add({ name: 'Heading', bold: true, fontSize: 14 });
styles.update('Heading', { color: { type: 'srgb', value: '4472C4' } });
const { cascadedTo } = styles.rename('Heading', 'Title');
styles.delete('Title');
get size(): number;

The number of named styles.

number

iterator: IterableIterator<NamedStyle>;

IterableIterator<NamedStyle>


add(style): NamedStyle;

Register a new named style.

NamedStyle

The named style to register. style.name must be non-empty and unique under case-insensitive comparison; style.extendsStyle must be absent (named styles cannot extend other named styles).

NamedStyle

if any precondition is violated.


delete(name): NamedStyleDeleteResult;

Remove a named style. Any anonymous styles that inherited from it (via extendsStyle) have that field cleared.

string

Name of the style to remove (case-insensitive).

NamedStyleDeleteResult

A NamedStyleDeleteResult describing what was removed and how many pool entries had their extendsStyle cleared.


get(name): NamedStyle | null;

Look up a named style by name (case-insensitive). Returns null if no style with that name exists.

string

NamedStyle | null


getAll(): NamedStyle[];

Return all named styles in insertion order.

NamedStyle[]


has(name): boolean;

Whether a named style with this name exists (case-insensitive).

string

boolean


rename(oldName, newName): NamedStyleRenameResult;

Rename a named style. Any styles in the anonymous pool that inherited from the old name have their extendsStyle rewritten to the new name.

string

The current name of the style to rename (case-insensitive). A named style with this name must exist.

string

The new name. Must be non-empty and must not already be in use by a different named style (case-insensitive).

NamedStyleRenameResult

A NamedStyleRenameResult describing how many pool entries had their extendsStyle rewritten to the new name.

if any precondition is violated.


toRecord(): Record<string, NamedStyle>;

Return all named styles as a JSF-shaped record keyed by name.

Record<string, NamedStyle>


update(name, patch): NamedStyle;

Update properties on a named style in place. The stored name is untouched (use rename to change it); extendsStyle is rejected for the same reason it is rejected by add (named styles cannot extend other named styles).

Does not touch the anonymous style pool: extendsStyle pointers there continue to resolve to the same named style, just with different properties.

string

Name of the style to update (case-insensitive). A named style with this name must exist.

NamedStylePatch

Properties to merge into the stored style. name and extendsStyle on the patch are rejected; all other fields are applied verbatim. Passing null or undefined for a property removes that property from the stored style (so a subsequent toRecord()/JSF export omits the key entirely rather than emitting a nullish value).

NamedStyle

The updated named style.

if any precondition is violated.