@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
88 lines • 2.45 kB
TypeScript
/**
* Create a registry for managing island components
*/
export declare function createIslandRegistry(): IslandRegistry;
/**
* Process all partial hydration directives
*/
export declare function processPartialHydrationDirectives(template: string, context?: Record<string, unknown>, _filePath?: string): string;
/**
* Generate CSS for partial hydration
*/
export declare function generatePartialHydrationCSS(): string;
/**
* Manually hydrate an island by ID
*/
export declare function hydrateIsland(islandId: string): void;
/**
* Hydrate all islands with a specific strategy
*/
export declare function hydrateByStrategy(strategy: HydrationStrategy): void;
/**
* Hydrate all pending islands
*/
export declare function hydrateAll(): void;
/**
* Check if an island is hydrated
*/
export declare function isHydrated(islandId: string): boolean;
/**
* Wait for an island to be hydrated
*/
export declare function onHydrated(islandId: string): Promise<void>;
/**
* Mark content as static (never hydrate)
*/
export declare function processStaticDirectives(template: string): string;
/**
* Generate island manifest for client
*/
export declare function generateIslandManifest(islands: IslandComponent[]): string;
export declare interface HydrationOptions {
strategy: HydrationStrategy
priority?: 'high' | 'low'
rootMargin?: string
threshold?: number | number[]
media?: string
event?: string
timeout?: number
placeholder?: string
preserveServerHTML?: boolean
}
export declare interface IslandComponent {
id: string
component: string
props: Record<string, unknown>
options: HydrationOptions
serverHTML: string
hydrated: boolean
}
export declare interface IslandRegistry {
islands: Map<string, IslandComponent>
register: (island: IslandComponent) => void
get: (id: string) => IslandComponent | undefined
hydrate: (id: string) => Promise<void>
hydrateAll: () => Promise<void>
}
// ============================================================================
// Types
// ============================================================================
export type HydrationStrategy = | 'load'
| 'idle'
| 'visible'
| 'media'
| 'only'
| 'hover'
| 'event'
export default {
processPartialHydrationDirectives,
processStaticDirectives,
generatePartialHydrationCSS,
generateIslandManifest,
createIslandRegistry,
hydrateIsland,
hydrateByStrategy,
hydrateAll,
isHydrated,
onHydrated,
};