@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
128 lines • 4.59 kB
TypeScript
import type { CustomDirective, StxOptions } from './types';
/**
* Create a plugin with type safety
*/
export declare function definePlugin(plugin: StxPlugin): StxPlugin;
/**
* Create a simple directive plugin
*/
export declare function createDirectivePlugin(name: string, directives: CustomDirective[], options?: Partial<Omit<StxPlugin, 'name' | 'registerDirectives'>>): StxPlugin;
/**
* Create a simple filter plugin
*/
export declare function createFilterPlugin(name: string, filters: Record<string, (value: unknown, ...args: unknown[]) => unknown>, options?: Partial<Omit<StxPlugin, 'name' | 'registerFilters'>>): StxPlugin;
/**
* Variables plugin that adds common variables to context
*/
export declare function createVariablesPlugin(variables: Record<string, unknown>): StxPlugin;
/**
* Global plugin manager instance
*/
export declare const pluginManager: PluginManager;
/**
* Debug plugin that logs all lifecycle events
*/
export declare const debugPlugin: StxPlugin;
/**
* Timing plugin that measures processing time
*/
export declare const timingPlugin: StxPlugin;
/**
* Context passed to lifecycle hooks
*/
export declare interface PluginContext {
template: string
context: Record<string, unknown>
filePath: string
options: StxOptions
dependencies: Set<string>
metadata: Record<string, unknown>
}
/**
* Result from a lifecycle hook
*/
export declare interface PluginHookResult {
template?: string
context?: Record<string, unknown>
skip?: boolean
metadata?: Record<string, unknown>
}
/**
* Error context passed to onError hook
*/
export declare interface PluginErrorContext extends PluginContext {
error: Error
phase: string
directive?: string
}
/**
* Plugin definition interface
*/
export declare interface StxPlugin {
name: string
version?: string
description?: string
dependencies?: string[]
priority?: number
beforeProcess?: (ctx: PluginContext) => PluginHookResult | Promise<PluginHookResult> | void
afterParse?: (ctx: PluginContext) => PluginHookResult | Promise<PluginHookResult> | void
beforeDirective?: (phase: DirectivePhase, ctx: PluginContext) => PluginHookResult | Promise<PluginHookResult> | void
afterDirective?: (phase: DirectivePhase, ctx: PluginContext) => PluginHookResult | Promise<PluginHookResult> | void
beforeRender?: (ctx: PluginContext) => PluginHookResult | Promise<PluginHookResult> | void
afterRender?: (ctx: PluginContext) => PluginHookResult | Promise<PluginHookResult> | void
onError?: (ctx: PluginErrorContext) => PluginHookResult | Promise<PluginHookResult> | void
registerDirectives?: () => CustomDirective[]
registerFilters?: () => Record<string, (value: unknown, ...args: unknown[]) => unknown>
onRegister?: (options: StxOptions) => void | Promise<void>
onUnregister?: () => void | Promise<void>
}
/**
* Directive type identifier for beforeDirective/afterDirective hooks
*/
export type DirectivePhase = | 'comments'
| 'escaped'
| 'stacks'
| 'layouts'
| 'includes'
| 'js'
| 'ts'
| 'custom'
| 'components'
| 'animation'
| 'routes'
| 'auth'
| 'csrf'
| 'method'
| 'loops'
| 'conditionals'
| 'forms'
| 'markdown'
| 'i18n'
| 'a11y'
| 'seo'
| 'expressions'
/**
* Plugin manager that handles registration, lifecycle, and execution
*/
export declare class PluginManager {
private plugins: Map<string, StxPlugin>;
private sortedPlugins: StxPlugin[];
private initialized: any;
register(plugin: StxPlugin, options: StxOptions): Promise<void>;
unregister(name: string): Promise<boolean>;
get(name: string): StxPlugin | undefined;
has(name: string): boolean;
getAll(): StxPlugin[];
getAllDirectives(): CustomDirective[];
getAllFilters(): Record<string, (value: unknown, ...args: unknown[]) => unknown>;
runBeforeProcess(ctx: PluginContext): Promise<PluginContext>;
runAfterParse(ctx: PluginContext): Promise<PluginContext>;
runBeforeDirective(phase: DirectivePhase, ctx: PluginContext): Promise<PluginContext>;
runAfterDirective(phase: DirectivePhase, ctx: PluginContext): Promise<PluginContext>;
runBeforeRender(ctx: PluginContext): Promise<PluginContext>;
runAfterRender(ctx: PluginContext): Promise<PluginContext>;
runOnError(ctx: PluginErrorContext): Promise<PluginContext | null>;
private sortPlugins(): void;
private runHooks(hookName: 'beforeProcess' | 'afterParse' | 'beforeRender' | 'afterRender', ctx: PluginContext): Promise<PluginContext>;
private runDirectiveHooks(hookName: 'beforeDirective' | 'afterDirective', phase: DirectivePhase, ctx: PluginContext): Promise<PluginContext>;
}