app artwork
register names in the root layout when screens across your app reuse the same artwork. this page uses the happy and confused names already registered by the documentation site’s layout.
saved to your reading list.
waiting for review.
register names in the root layout
Add this setup to your existing src/routes/+layout.svelte. It shows where registration belongs and keeps Svelte’s child rendering; merge it into your current layout and keep its shell and other setup.
<script lang="ts">
import type { Snippet } from 'svelte';
import { registerEmotions } from '@ciabi/loafkit-ui';
let { children }: { children: Snippet } = $props();
const emotionImages = import.meta.glob<string>('../lib/assets/emotions/*.png', {
eager: true,
query: '?url',
import: 'default'
});
registerEmotions(
Object.entries(emotionImages).map(([path, src]) => ({
name: path.split('/').pop()?.replace(/\.png$/, '') ?? path,
src
}))
);
</script>
{@render children()}The glob imports each PNG and uses its filename without .png as the name, so happy.png is available as emotion="happy". The snippet is a minimal layout shape, not a replacement for your existing app shell. For the two images used here, keep happy.png and confused.png in src/lib/assets/emotions/ or adjust the glob to your app’s asset folder.
The registry is shared module state. Static artwork is fine to register for the app, but don’t register request-specific user data during server rendering.
use registered names
<script>
import { Emoticon } from '@ciabi/loafkit-ui';
</script>
<p><Emoticon emotion="happy" alt="" size="small" /> saved to your reading list.</p>
<p><Emoticon emotion="confused" alt="" size="small" /> waiting for review.</p>use an image directly
For a one-off visual, pass an imported image to src instead of registering a name. Empty alternative text works when nearby text already gives the image’s meaning.
waiting for review.
<script>
import { Emoticon } from '@ciabi/loafkit-ui';
import directArtwork from '$lib/assets/emotions/confused.png';
</script>
<p><Emoticon src={directArtwork} alt="" size="small" /> waiting for review.</p>API reference
The registry rejects empty names and definitions without a visual. Emotion is a string alias. EmotionDefinition requires a name and exactly one visual source; its src branch takes an image URL, and its Component branch takes a Svelte component.
registry functions
registerEmotion(definition)
definition-
adds or replaces this named visual.
- returns
-
registers the definition; invalid definitions throw.
registerEmotions(definitions)
definitions-
definitions to register in order.
- returns
-
registers each definition; earlier entries remain if a later one throws.
getEmotion(name)
listEmotions()
- returns
-
shallow copies of all registered definitions.
unregisterEmotion(name)
EmotionDefinition
a registered visual definition.
See Emoticon for its direct visual props and dialogs for dialog configuration.
saved to your reading list.
waiting for review.