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).
Example
Section titled “Example”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');Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size(): number;The number of named styles.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”iterator: IterableIterator<NamedStyle>;Returns
Section titled “Returns”IterableIterator<NamedStyle>
add(style): NamedStyle;Register a new named style.
Parameters
Section titled “Parameters”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).
Returns
Section titled “Returns”Throws
Section titled “Throws”if any precondition is violated.
delete()
Section titled “delete()”delete(name): NamedStyleDeleteResult;Remove a named style. Any anonymous styles that inherited from it (via
extendsStyle) have that field cleared.
Parameters
Section titled “Parameters”string
Name of the style to remove (case-insensitive).
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”NamedStyle | null
getAll()
Section titled “getAll()”getAll(): NamedStyle[];Return all named styles in insertion order.
Returns
Section titled “Returns”has(name): boolean;Whether a named style with this name exists (case-insensitive).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
rename()
Section titled “rename()”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.
Parameters
Section titled “Parameters”oldName
Section titled “oldName”string
The current name of the style to rename (case-insensitive). A named style with this name must exist.
newName
Section titled “newName”string
The new name. Must be non-empty and must not already be in use by a different named style (case-insensitive).
Returns
Section titled “Returns”A NamedStyleRenameResult describing how many pool entries had their
extendsStyle rewritten to the new name.
Throws
Section titled “Throws”if any precondition is violated.
toRecord()
Section titled “toRecord()”toRecord(): Record<string, NamedStyle>;Return all named styles as a JSF-shaped record keyed by name.
Returns
Section titled “Returns”Record<string, NamedStyle>
update()
Section titled “update()”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.
Parameters
Section titled “Parameters”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).
Returns
Section titled “Returns”The updated named style.
Throws
Section titled “Throws”if any precondition is violated.