---
description:
globs: *.svelte
alwaysApply: false
---
# Svelte Style
Observe the the following style guidelines when programming Svelte components or SvelteKit pages:
- Always use idiomatic Svelte 5 syntax and features. Svelte 5 idioms include:
- Runes, such as `$state`, `$derived`, `$effect`, and `$props`.
- Callback props.
- Snippets.
- Avoid using deprecated Svelte 4 syntax and features. Depecrated features include:
- Props declared via `export let`.
- Event handlers attached via the `on:` directive.
- Event dispatchers.
- Component slots.
- Remember that Svelte 5 state is deeply reactive.
- Mutating a state object automatically triggers reactivity in most cases.
- Avoid trying to trigger reactivity by reassigning state variables unless other options have failed.
- Write components in TypeScript, and prefer strong typing for variables, props, and function signatures.
- Limit component logic to rendering concerns. Extract business logic into separate TypeScript modules, and import functions and classes into Svelte components as needed.
- Use PascalCase when naming Svelte components.
- Keep component files under 500 lines, when possible.
## Component Code Organization Example
When writing or editing a Svelte component, organize the code according to the following template:
```
{#snippet contentParagraph(content: string, publicationType: string, isSectionStart: boolean)}
{/snippet}
{#await leafEvent}
{@render contentParagraph(leafEvent.content.toString(), publicationType ?? 'article', false)}
{/await}
```