@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
134 lines • 3.26 kB
TypeScript
import type { CraftComponentConfig } from './craft-components';
/**
* Compile an stx template into a Craft-optimized component tree
*/
export declare function compileTemplate(template: string, options?: { id?: string }): CompiledTemplate;
/**
* Render a compiled template to HTML with SSR optimizations
*/
export declare function renderSSR(compiled: CompiledTemplate, context?: Record<string, unknown>, config?: SSRConfig): Promise<SSRResult>;
/**
* Generate Craft optimization hints for a template
*/
export declare function generateCraftOptimizations(compiled: CompiledTemplate, _config?: CraftComponentConfig): CraftOptimization;
/**
* Pre-render static parts of a template for Craft
*/
export declare function prerenderForCraft(template: string, context?: Record<string, unknown>): {
staticHTML: string
dynamicPlaceholders: Map<string, string>
craftComponents: string[]
};
/**
* Clear template cache
*/
export declare function clearTemplateCache(): void;
/**
* Clear render cache
*/
export declare function clearRenderCache(): void;
/**
* Clear all caches
*/
export declare function clearAllCaches(): void;
/**
* Get SSR cache statistics
*/
export declare function getSSRCacheStats(): {
templateCacheSize: number
renderCacheSize: number
totalEntries: number
};
/**
* Represents a node in the Craft component tree
*/
export declare interface CraftNode {
type: 'element' | 'text' | 'component' | 'fragment' | 'slot'
tag?: string
props?: Record<string, unknown>
children?: CraftNode[]
text?: string
componentName?: string
slotName?: string
isStatic?: boolean
hydrationKey?: string
}
/**
* Compiled template representation
*/
export declare interface CompiledTemplate {
id: string
hash: string
tree: CraftNode
scripts: string[]
styles: string[]
staticParts: Map<string, string>
dynamicParts: Map<string, string>
dependencies: string[]
metadata: TemplateMetadata
}
/**
* Template metadata for optimization
*/
export declare interface TemplateMetadata {
hasSlots: boolean
hasDynamicContent: boolean
hasEventHandlers: boolean
hasAsyncContent: boolean
componentCount: number
maxDepth: number
estimatedSize: number
}
/**
* SSR configuration options
*/
export declare interface SSRConfig {
streaming?: boolean
prerender?: boolean
hydrate?: boolean
minify?: boolean
cache?: boolean
cacheTTL?: number
staticAnalysis?: boolean
target?: 'web' | 'craft' | 'both'
}
/**
* SSR result
*/
export declare interface SSRResult {
html: string
styles: string
scripts: string
hydrationData?: Record<string, unknown>
metadata: SSRMetadata
}
/**
* SSR metadata
*/
export declare interface SSRMetadata {
renderTime: number
cacheHit: boolean
streamChunks?: number
totalSize: number
componentCount: number
}
/**
* Optimization hints for Craft
*/
export declare interface CraftOptimization {
nativeComponents: string[]
staticHTML: string[]
dynamicParts: string[]
eventHandlers: Map<string, string>
nativeWidgets: NativeWidgetSuggestion[]
}
/**
* Native widget suggestion
*/
export declare interface NativeWidgetSuggestion {
htmlSelector: string
nativeComponent: string
confidence: number
reason: string
}
export default craftSSR;