How melt-ui/next-gen works
Overview
Melt UI is a Svelte library of headless, accessible component builders. It supplies interaction behavior, state, and WAI-ARIA-oriented behavior while application code supplies markup composition, styling, and surrounding components.
Public surfaces
• packages/melt/src/lib/index.ts is the primary package entry point.
• packages/melt/src/lib/builders/index.ts organizes the component-builder API, including controls such as dialogs, selects, tabs, menus, and trees.
• packages/melt/src/lib/components/index.ts provides a separate Svelte component surface for the component implementations present in that directory.
• docs/src/pages/index.astro is the documentation site entry; its content describes installation, styling, component usage, and API behavior.
Core implementation areas
• Builder layer — packages/melt/src/lib/builders
Contains per-component Svelte/TypeScript builders. This is the main headless behavior layer and is the primary extension surface for applications that want their own DOM and visual design.
• Svelte component layer — packages/melt/src/lib/components
Contains ready-made Svelte component implementations for part of the builder catalog. It is a distinct consumer-facing surface; the tree does not establish that every component delegates directly to a builder.
• Shared runtime utilities — packages/melt/src/lib/utils
Provides reusable browser and interaction mechanics, including attributes, DOM events, keyboard handling, focus trapping, pointer behavior, popovers, collections, typeahead, floating positioning, and selection state.
• Shared contracts — packages/melt/src/lib/types.ts
Centralizes TypeScript types used across the library’s public and internal surfaces.
State and boundaries
Interaction state appears to be in-memory and Svelte-reactive, supported by state-oriented modules such as selection-state.svelte.ts, getters.svelte.ts, and effect.svelte.ts. No durable storage or server-side persistence layer is visible in the supplied tree.
The external actor is the consuming Svelte application: it chooses markup, styles, component composition, and application data. Melt UI owns reusable interaction and accessibility behavior. Browser DOM APIs and events form the principal runtime boundary.
Relationships
A consuming Svelte app reaches the library through packages/melt/src/lib/index.ts, then uses either the builder surface or available Svelte components. Builders and components share contracts from packages/melt/src/lib/types.ts and reusable mechanics from packages/melt/src/lib/utils. The documentation site explains these public surfaces but is a separate documentation application, not a runtime dependency of the library.
Main entry points: index.ts Library entry · components Svelte components · builders Builders · utils Runtime utilities
Components 8
Public surfaces
Consumer-facing library entry points.
- Library entry
packages/melt/src/lib/index.ts - Svelte components · Provides ready-made Svelte component implementations.
packages/melt/src/lib/components
Library runtime
Headless behavior, components, shared mechanics, and contracts.
- Builders · Provides reusable interaction and accessibility behavior.
packages/melt/src/lib/builders - Runtime utilities · Provides browser and interaction mechanics.
packages/melt/src/lib/utils - Shared contracts
packages/melt/src/lib/types.ts
External boundaries
Consumer applications and browser runtime.
- Consuming Svelte app · Supplies markup, styling, composition, and application data.
- Browser DOM and events
Documentation
Separate documentation application.
- Documentation site · Explains installation, styling, usage, and API behavior.
docs/src/pages/index.astro
Connections 9
- Consuming Svelte app → Library entry: imports
- Library entry → Builders: exposes
- Library entry → Svelte components: exposes
- Builders → Runtime utilities: uses mechanics
- Svelte components → Runtime utilities: uses mechanics
- Builders → Shared contracts: uses contracts
- Svelte components → Shared contracts: uses contracts
- Runtime utilities → Browser DOM and events: uses DOM events
- Documentation site → Library entry: documents