Advanced / Composition · guide
Named assets (painter.assets)
Current Apexify.js 6.0.0 documentation for Named assets (painter.assets).
AssetManager is the named composition registry on painter.assets. It stores images, font paths, palettes, and arbitrary JSON-like values, then resolves $name / dotted $value.path references for scenes, templates, and opt-in imperative APIs.
renderScene,renderSceneToGIF,renderSceneToVideoFrames— asset resolution is on by default; passresolveAssetRefs: falseto skip it.- Templates — placeholders resolve first, then asset references resolve during
TemplateHandle.render/toRenderInput. SceneBuilder.render— asset resolution is off by default; opt in with{ resolveAssetRefs: true }.- Imperative create APIs / batch / chain — resolution is opt-in; see Imperative & batch resolution.
Registering assets
Duplicate and replacement contract
Root names are unique across the whole registry. loadImage, loadFont, loadPalette, and loadValue throw ApexifyAssetError when that name is already registered. Replacement is explicit:
replaceImage(name, source)replaceFont(name, path)replacePalette(name, colors)replaceValue(name, value)
A replace call also throws when the target name does not exist. This prevents accidental overwrite during application startup.
Cleanup/introspection:
has(name)— root-name existence check.delete(name)— remove any asset kind by root name.unregisterImage,unregisterFont,unregisterPalette— kind-specific removal helpers.list()— returns{ name, kind }registrations.clear()— empties the registry.
Registered JSON-like data and Buffers are copied on ingress, and resolve() returns an isolated copy. Mutating the original registration value or a resolved Buffer does not mutate registry storage.
Reference syntax
Call assets.resolve() without the leading dollar sign:
In composition data, use the leading $:
| Value in config | Meaning |
|---|---|
"$logo" | Resolve the complete logo asset. A lone reference may return a string, scalar, object/array value, or Buffer. |
"$theme.text" | Dotted own-property lookup. |
"$copy.spacing.1" | Array indices are allowed in dotted paths. |
"color=$theme.text" | Embedded references are allowed only when they resolve to string/number/boolean scalars. |
"$$theme.text" | Literal $theme.text; $$ escapes a dollar sign. |
Unknown roots, missing nested properties, unsafe path segments, and attempts to embed a non-scalar asset inside a longer string throw ApexifyAssetError. Use a non-scalar reference as the entire field value instead.
The deep resolver rejects cyclic arrays/plain objects rather than recursing indefinitely. Opaque runtime objects are preserved; JSON-like arrays/records are traversed.
Example — scene + palette + image
Use loadFont plus a full-field font path reference when a text API accepts a font path string.
prepareForRender
painter.prepareForRender<T>(value): T deep-resolves asset references in JSON-like arrays/records without rendering anything. It is useful when an imperative API does not expose an asset-resolution option or when you want one resolved snapshot reused across calls.
Because resolution returns a new composition structure, the input object is not mutated.
Relationship to templates
Templates use one deterministic pipeline: visibility filtering → placeholder resolution → asset resolution → numeric/layout normalization → scene validation. A whole placeholder or asset reference can preserve native values such as false, 0, arrays, objects, or Buffers where the target field accepts them.
Use createTemplate(definition, { resolveAssetRef }) when one template needs a custom asset resolver instead of painter.assets.