Spec Registry
Help your agents use open-source better. Learn more.
Find usage specs for your project’s dependencies
- Author
- tessl
- Last updated
- Spec files
npm-svelte
Describes: npm/svelte
- Description
- Revolutionary JavaScript framework and compiler that builds web applications without runtime overhead by compiling components at build time.
- Author
- tessl
- Last updated
index.md docs/
1# Svelte23Svelte is a revolutionary JavaScript framework and compiler that takes a unique approach to building web applications. Rather than running in the browser as a traditional framework, Svelte compiles components at build time into highly optimized vanilla JavaScript that surgically updates the DOM. This compilation step eliminates the overhead of a virtual DOM and framework runtime, resulting in smaller bundle sizes and faster performance.45## Package Information67- **Package Name**: svelte8- **Package Type**: npm9- **Language**: JavaScript/TypeScript10- **Installation**: `npm install svelte`1112## Core Imports1314```javascript15import { onMount, createEventDispatcher } from "svelte";16```1718Additional imports for animations, transitions, and easing:1920```javascript21import { spring, tweened } from "svelte/motion";22import { fade, fly, slide, scale } from "svelte/transition";23import { cubicOut, elasticOut } from "svelte/easing";24import { flip } from "svelte/animate";25```2627Compiler usage:2829```javascript30import { compile, parse, preprocess } from "svelte/compiler";31```3233Store management:3435```javascript36import { writable, readable, derived } from "svelte/store";37```3839## Basic Usage4041```javascript42// Component lifecycle43import { onMount, onDestroy } from "svelte";4445export let name = "";4647onMount(() => {48console.log("Component mounted");49return () => {50console.log("Cleanup function");51};52});5354// Event handling55import { createEventDispatcher } from "svelte";5657const dispatch = createEventDispatcher();5859function handleClick() {60dispatch("message", {61text: "Hello from component"62});63}6465// Store usage66import { writable } from "svelte/store";6768const count = writable(0);6970function increment() {71count.update(n => n + 1);72}73```7475## Architecture7677Svelte's architecture consists of several key components:7879- **Compiler**: Transforms `.svelte` components into optimized JavaScript at build time80- **Runtime**: Minimal runtime library providing lifecycle hooks and reactivity81- **Component System**: Template-based components with scoped CSS and reactive state82- **Store System**: Global state management with reactive subscriptions83- **Transition/Animation**: Built-in animation and transition effects84- **Server-Side Rendering**: Full SSR support with hydration capabilities8586## Capabilities8788### Core Runtime8990Component lifecycle hooks, event dispatching, and context management for building interactive Svelte components.9192```javascript { .api }93function onMount(fn: () => NotFunction<T> | Promise<NotFunction<T>> | (() => any)): void;94function onDestroy(fn: () => any): void;95function beforeUpdate(fn: () => void): void;96function afterUpdate(fn: () => void): void;97function tick(): Promise<void>;98function createEventDispatcher<EventMap extends Record<string, any> = any>(): EventDispatcher<EventMap>;99function setContext<T>(key: any, context: T): T;100function getContext<T>(key: any): T;101function getAllContexts<T extends Map<any, any> = Map<any, any>>(): T;102function hasContext(key: any): boolean;103```104105[Core Runtime](./core-runtime.md)106107### Compiler108109Complete compilation pipeline for transforming Svelte components into optimized JavaScript with preprocessing support.110111```javascript { .api }112function compile(source: string, options?: CompileOptions): CompileResult;113function parse(template: string, options?: ParserOptions): Ast;114function preprocess(source: string, preprocessor: PreprocessorGroup | PreprocessorGroup[], options?: { filename?: string }): Promise<Processed>;115function walk(ast: Node, visitors: { enter?: (node: Node, parent?: Node) => void; leave?: (node: Node, parent?: Node) => void; }): void;116const VERSION: string;117```118119[Compiler](./compiler.md)120121### Store Management122123Reactive state management system with readable, writable, and derived stores for application-wide state.124125```javascript { .api }126function writable<T>(value?: T, start?: StartStopNotifier<T>): Writable<T>;127function readable<T>(value?: T, start?: StartStopNotifier<T>): Readable<T>;128function derived<S extends Stores, T>(stores: S, fn: Function, initial_value?: T): Readable<T>;129function readonly<T>(store: Readable<T>): Readable<T>;130function get<T>(store: Readable<T>): T;131```132133[Store Management](./store-management.md)134135### Motion and Animation136137Physics-based animations and smooth transitions between state values with spring and tween effects.138139```javascript { .api }140function spring<T = any>(value?: T, opts?: SpringOpts): Spring<T>;141function tweened<T>(value?: T, defaults?: TweenedOptions<T>): Tweened<T>;142```143144[Motion and Animation](./motion-animation.md)145146### List Animations147148FLIP animations for smooth list reordering and element positioning transitions.149150```javascript { .api }151function flip(node: Element, { from, to }: { from: DOMRect; to: DOMRect }, params?: FlipParams): AnimationConfig;152```153154[List Animations](./list-animations.md)155156### Transitions157158Built-in transition effects for element enter/exit animations with customizable parameters and easing functions.159160```javascript { .api }161function blur(node: Element, params?: BlurParams): TransitionConfig;162function fade(node: Element, params?: FadeParams): TransitionConfig;163function fly(node: Element, params?: FlyParams): TransitionConfig;164function slide(node: Element, params?: SlideParams): TransitionConfig;165function scale(node: Element, params?: ScaleParams): TransitionConfig;166function draw(node: SVGElement & { getTotalLength(): number }, params?: DrawParams): TransitionConfig;167function crossfade(params: CrossfadeParams): [send: Function, receive: Function];168```169170[Transitions](./transitions.md)171172### Easing Functions173174Comprehensive collection of easing functions for smooth animation curves and natural motion effects.175176```javascript { .api }177function linear(t: number): number;178function cubicInOut(t: number): number;179function elasticOut(t: number): number;180function bounceInOut(t: number): number;181```182183[Easing Functions](./easing-functions.md)184185### Actions186187Element lifecycle and behavior enhancement system for reusable DOM interactions.188189```javascript { .api }190interface Action<Element = HTMLElement, Parameter = undefined, Attributes extends Record<string, any> = Record<never, any>> {191(node: Element, parameter?: Parameter): void | ActionReturn<Parameter, Attributes>;192}193194interface ActionReturn<Parameter = undefined, Attributes extends Record<string, any> = Record<never, any>> {195update?: (parameter: Parameter) => void;196destroy?: () => void;197}198```199200[Actions](./actions.md)201202## Core Types203204```javascript { .api }205class SvelteComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any> {206constructor(options: ComponentConstructorOptions<Props>);207$destroy(): void;208$on<K extends Extract<keyof Events, string>>(type: K, callback: ((e: Events[K]) => void) | null | undefined): () => void;209$set(props: Partial<Props>): void;210}211212interface ComponentConstructorOptions<Props extends Record<string, any> = Record<string, any>> {213target: Element | Document | ShadowRoot;214anchor?: Element;215props?: Props;216context?: Map<any, any>;217hydrate?: boolean;218intro?: boolean;219}220221interface EventDispatcher<EventMap extends Record<string, any>> {222<Type extends keyof EventMap>(223...args: null extends EventMap[Type]224? [type: Type, parameter?: EventMap[Type] | null | undefined, options?: DispatchOptions]225: undefined extends EventMap[Type]226? [type: Type, parameter?: EventMap[Type] | null | undefined, options?: DispatchOptions]227: [type: Type, parameter: EventMap[Type], options?: DispatchOptions]228): boolean;229}230231interface DispatchOptions {232cancelable?: boolean;233}234```