LCARdS Pack System
How packs are structured, loaded and distributed to the core registries. Follow this page to add a pack, a component type or a new asset kind.
Overview
A pack is a plain JavaScript object that contributes data to LCARdS: themes, style presets, components, rules, assets and sound schemes. At startup PackManager (src/core/PackManager.js) registers each built-in pack, handing each key to the singleton that owns it.
Rule: cards and editors query a singleton registry (themeManager, stylePresetManager, componentManager, assetManager, soundManager), not the pack data files. Packs are the source of truth; registries are the query interface. Known exceptions in the code today: CoreConfigManager._getComponentDefaults() and the button editor import src/core/packs/components/index.js directly, and ApexChartsAdapter reads BUILTIN_THEMES_PACK.chartAnimationPresets directly (src/charts/ApexChartsAdapter.js).
All packs are built in: there is no external or user pack loader. A third-party pack is added to the bundle like a built-in one (see How to Add a New Pack).
Architecture Diagram
Pack Format
Every key except id is optional. registerPack() acts only on the keys below; others are ignored, and the retired keys overlays, anchors, routing, palettes, profiles log a warning.
{
// ── Identity ──────────────────────────────────────────────────────────────
id: 'my_pack', // required (snake_case); a pack without id is skipped with a warning
version: '1.0.0', // built-in packs use __LCARDS_VERSION__
name: 'My Pack', // shown in the Pack Explorer
description: 'What this adds',
// ── Themes → ThemeManager.registerThemesFromPack() ───────────────────────
themes: {
'my-theme': { id: 'my-theme', name: 'My Theme', description: '...', tokens: { /* token tree */ } }
},
defaultTheme: 'my-theme', // read only by ThemeManager.initialize(), which the core does not call
// ── Style presets → StylePresetManager.registerPresetsFromPack() ─────────
// Key: card type; value: { presetName: partial card config }
style_presets: {
button: {
'my-lozenge': {
extends: 'button.lozenge',
card: { color: { background: { active: 'theme:colors.card.buttonOn' } } }
}
}
},
// ── Rules → RulesEngine (rules / rulesById, then compiled) ───────────────
rules: [
{
id: 'my_rule', // rules without id are skipped
when: { entity: 'light.example', state: 'on' },
apply: {
overlays: {
'tag:example': { style: { card: { color: { background: 'theme:colors.alert.red' } } } }
}
}
}
],
// ── Assets → AssetManager.preloadFromPack() (registered, loaded on first use) ─
svg_assets: { my_msd: { url: '/local/my_pack/msd.svg', metadata: { description: '...' } } },
font_assets: { lcards_my_font: { url: '/local/my_pack/my-font.css', displayName: 'My Font', category: 'Custom' } },
image_assets: { my_bg: { url: '/local/my_pack/bg.webp', label: 'My background', category: 'backgrounds' } },
model_assets: { my_ship: { url: '/local/my_pack/ship.glb', label: 'My ship', parts: ['saucer'] } },
audio_assets: { my_tap: { url: '/local/my_pack/tap.mp3', description: 'Tap beep' } },
// ── Sound schemes → SoundManager.registerSchemes() ───────────────────────
// Event key → audio asset key; null silences the event, an omitted key falls through
sound_schemes: {
my_scheme: { card_tap: 'my_tap', alert_clear: null }
},
// ── Components → ComponentManager.registerComponentsFromPack() ───────────
// Each definition needs metadata.type (the getComponentsByType() group)
components: {
'my-widget': { svg: '<svg>...</svg>', metadata: { type: 'my_widget', name: 'My Widget', version: '1.0.0' } }
}
}- Asset entry fields per type are on the Asset Manager page. A font
urlis a CSS file with@font-facerules, injected as a stylesheet. - Rules use the rules grammar (
when/apply): Rules Engine. - The preset shape is on the Style Preset Manager page; component shapes on the Component Manager page.
- Packs carry no animation presets: the built-in ones register when
loadBuiltinPacks()callsregisterBuiltinAnimationPresets()(src/core/packs/animations/presets/index.js), not through a pack key. Each is recorded as packcorewith a category, so the Pack Explorer lists them under the core pack (listAnimationPresetInfo()insrc/core/animation/presets.js). src/core/packs/example/lcards-example-pack.jsis a commented template with every key (its rule and presets are checked bytests/core/example-pack.test.js).
Built-in Pack Inventory
BUILTIN_REGISTRY in src/core/packs/loadBuiltinPacks.js:
| Pack ID | File | Key(s) | Registry |
|---|---|---|---|
core | core-pack.js | none (version anchor) | Pack Explorer only |
lcards_buttons | lcards-buttons-pack.js | style_presets.button | StylePresetManager |
lcards_sliders | lcards-sliders-pack.js | style_presets.slider | StylePresetManager |
lcards_elbows | lcards-elbows-pack.js | components (type elbow) | ComponentManager |
builtin_themes | builtin-themes.js | themes, defaultTheme, chartAnimationPresets | ThemeManager (the chart presets are read by ApexChartsAdapter) |
builtin_msd_backgrounds | builtin-msd.js | svg_assets | AssetManager |
core_fonts | core-fonts-pack.js | font_assets (built from core_fonts.json) | AssetManager |
lcards_sounds_default | lcards-default-sound-scheme.js | audio_assets, sound_schemes | AssetManager, SoundManager |
lcards_beeps | lcards-beeps-pack.js | audio_assets | AssetManager |
lcards_alerts | lcards-alerts-pack.js | audio_assets | AssetManager |
lcards_power | lcards-power-pack.js | audio_assets | AssetManager |
lcards_images | lcards-images-pack.js | image_assets, model_assets | AssetManager |
lcards_textures | lcards-textures-pack.js | none (metadata only; the texture presets in textures/presets/index.js are imported by the renderer) | Pack Explorer only |
Which load. The core calls packManager.loadBuiltinPacks() with its default, CORE_REQUESTED_PACK_IDS (['core', 'lcards_buttons', 'lcards_sliders', 'builtin_themes']). loadBuiltinPacks(requested) adds the always-loaded set (builtin_themes, builtin_msd_backgrounds, core_fonts, lcards_sounds_default, lcards_beeps, lcards_alerts, lcards_elbows, lcards_textures, lcards_images, lcards_power), removes duplicates, warns about ids not in BUILTIN_REGISTRY (Unknown builtin pack ids ignored) and returns the pack objects in that order. So all 13 packs load. BUILTIN_PACK_IDS exports every registry id.
File Structure Convention
Pack wrapper files live directly under src/core/packs/. Subfolders hold the data the wrappers import, plus runtime code that belongs to a pack domain (backgrounds, textures).
src/core/packs/
loadBuiltinPacks.js ← manifest + loader only (BUILTIN_REGISTRY, CORE_REQUESTED_PACK_IDS)
core_fonts.json ← font list for core-fonts-pack.js
── Pack wrappers ──────────────────────────────────────────────
core-pack.js ← no data keys
core-fonts-pack.js ← font_assets
lcards-buttons-pack.js ← style_presets.button
lcards-sliders-pack.js ← style_presets.slider
lcards-elbows-pack.js ← components (type: elbow)
builtin-themes.js ← themes, chartAnimationPresets
builtin-msd.js ← svg_assets
lcards-default-sound-scheme.js ← audio_assets + sound_schemes
lcards-beeps-pack.js ← audio_assets
lcards-alerts-pack.js ← audio_assets
lcards-power-pack.js ← audio_assets
lcards-images-pack.js ← image_assets + model_assets
lcards-textures-pack.js ← metadata only
── Data and domain code ───────────────────────────────────────
style-presets/
buttons/index.js ← BUTTON_PRESETS
sliders/index.js ← SLIDER_PRESETS
components/
index.js ← `components`: the ComponentManager bootstrap list
elbows/index.js ← elbowComponents
sliders/ ← sliderComponents (default, picard, demo, shaped, ring)
dpad/, dpad_voyager/ ← dpadComponents, dpadVoyagerComponents (+ .svg)
alert/, brackets/ ← alertComponents, bracketsComponents
buttons/index.js ← BUTTON_COMPONENTS (not in components/index.js)
themes/
tokens/lcardsDefaultTokens.js ← token tree of lcards-default
animations/
index.js ← re-exports registerBuiltinAnimationPresets()
presets/ ← effect, stagger, text and timeline presets
backgrounds/ ← background animation renderer, effects, presets, WebGL scenes
textures/ ← CanvasTextureRenderer, texture effects, presets
shared/ ← ImageLoader.js, ImageDrawUtils.js
example/
lcards-example-pack.js ← full-feature template for pack authorsRule: loadBuiltinPacks.js imports packs; it does not define them.
Rule: pack wrapper files live at the packs/ root, never inside a domain subfolder.
Registration Flow
- The step numbers follow the comments in
registerPack(); step 6 is a note that animations need no registration. ComponentManageris filled fromcomponents/index.jsbefore any pack registers; step 7 re-registers a pack's components with apackfield (see Component Manager).- Each step runs only when the pack has the key and the core has that manager.
loadBuiltinPacks()throws when no pack comes back. - After the loop the core loads
autoLoadfonts and activateslcards-default(see Theme System).
Consumer Rules
| Consumer | Correct pattern | Anti-pattern |
|---|---|---|
| Card rendering | window.lcards.core.componentManager.getComponent('header-left') | import { getElbowComponent } from '…/elbows/index.js' |
| Card editor dropdown | window.lcards.core.stylePresetManager.getAvailablePresets('button') | import { BUTTON_PRESETS } from '…/style-presets/buttons/index.js' |
| Theme token | window.lcards.core.themeManager.getToken('colors.ui.primary', fallback) | Importing lcardsDefaultTokens |
| Image or model | window.lcards.core.assetManager.resolveImageUrl(key) / resolveModelUrl(key) | Hard-coding /lcards/images/... |
| Sound | window.lcards.core.soundManager.play('card_tap') | Hard-coding an audio URL |
Direct imports tie cards to files, skip the registries' provenance (pack fields, Pack Explorer) and stop another pack from replacing a definition.
How to Add a New Pack
Create the wrapper file at the
packs/root:js// src/core/packs/lcards-my-pack.js export const MY_PACK = { id: 'my_pack', name: 'My Pack', version: __LCARDS_VERSION__, description: '...', audio_assets: { /* ... */ } };Register it in
loadBuiltinPacks.js:jsimport { MY_PACK } from './lcards-my-pack.js'; // In BUILTIN_REGISTRY: my_pack: MY_PACK, // Then add 'my_pack' to alwaysLoad (or to CORE_REQUESTED_PACK_IDS); // a pack in neither list is never loaded at startup.PackManagerdistributes the keys. If the pack adds a name a config can reference (a preset, component, sound, asset), check that the config checker knows it:scripts/lib/registries.jsreads its names from the same modules the runtime registers from, and a new kind of name needs its check inregistryIssues()(scripts/lib/config-validator.js).
How to Add a New Component Type
Components ship like any pack key. Two things are specific to them:
metadata.typeis required on every definition;ComponentManagergroups by it forgetComponentsByType(). Addmetadata.card_type('button', ...) when an editor should offer it:getComponentsForCard()incomponents/index.jsfilters on it.js// src/core/packs/components/mytype/index.js export const myTypeComponents = { 'my-variant': { svg: `<svg viewBox="0 0 100 40">…</svg>`, segments: { /* per-segment defaults with theme: tokens */ }, presets: { default: {} }, metadata: { type: 'mytype', card_type: 'button', name: 'My Variant', version: '1.0.0' } } };Add it to the
components/index.jsspread, whichComponentManager.initialize()registers before any pack loads:jsimport { myTypeComponents } from './mytype/index.js'; export const components = { // ...the existing spreads ...myTypeComponents };A pack wrapper with
components: myTypeComponentsis optional; it adds thepackfield the Pack Explorer shows.
Then query it through the singleton:
window.lcards.core.componentManager.getComponentsByType('mytype')
window.lcards.core.componentManager.getComponent('my-variant')The card that renders the type has to understand its shape (button segments, slider render(), elbow pathGenerator()); see Component Manager.
Public API
PackManager is a plain class (not a BaseService) created by the core with a reference to it.
| Method | Returns | Description |
|---|---|---|
loadBuiltinPacks(packIds?) | Promise<void> | Load and register built-in packs (default CORE_REQUESTED_PACK_IDS); throws when none load |
registerPack(pack) | Promise<void> | Distribute one pack to the registries (see Registration Flow) |
getPack(id) | Object|undefined | The stored summary { id, version, description, registeredAt }, not the pack object |
getLoadedPackIds() | string[] | Ids in registration order |
getLoadedPacks() | Object[] | Summaries plus themeCount and presetCount (ruleCount and assetCount are always 0) |
getPackMetadata(id) | Object|null | Summary plus themes and presets (by type) from that pack; rules: [], assets: {} |
getPackStatistics() | Object | { totalPacks, totalThemes, totalPresets, totalRules, totalAssets } |
getDebugInfo() | Object | { loadedPacks, packCount } |
Console Access
window.lcards.debug.singleton('packManager')
// → { loadedPacks: [ { id: 'core', version, description, registeredAt }, { id: 'lcards_buttons', ... }, ... ], packCount: 13 }const pm = window.lcards.core.packManager
pm.getLoadedPackIds() // ['core', 'lcards_buttons', 'lcards_sliders', 'builtin_themes', ...]
pm.getLoadedPacks() // summaries with content counts
pm.getPack('lcards_buttons') // { id, version, description, registeredAt }
pm.getPackMetadata('lcards_buttons') // with presets.button
pm.getPackStatistics() // totals for the Pack Explorer