All files / coherent.js/packages/core/src coherent.d.ts

0% Statements 0/270
0% Branches 0/1
0% Functions 0/1
0% Lines 0/270

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
// Type definitions for coherent-framework
// Project: Coherent.js - Pure object-based rendering framework

export interface CoherentElement {
  [tagName: string]: {
    text?: string;
    html?: string;
    children?: CoherentNode[];
    className?: string | (() => string);
    [key: string]: any;
  };
}

export type CoherentNode = CoherentElement | string | number | boolean | null | undefined;

export interface ComponentFunction {
  (props?: Record<string, any>): CoherentNode;
}

export interface RenderOptions {
  minify?: boolean;
  stream?: boolean;
  enableCache?: boolean;
  enableMonitoring?: boolean;
  enableDevTools?: boolean;
  cacheSize?: number;
  cacheTTL?: number;
  maxDepth?: number;
  cssFiles?: string[];
  cssLinks?: string[];
  cssInline?: string;
  cssMinify?: boolean;
  [key: string]: any;
}

// Core rendering functions
export function renderToString(node: CoherentNode, options?: RenderOptions): string;
export function renderHTML(node: CoherentNode, options?: RenderOptions): Promise<string>;
export function renderHTMLSync(node: CoherentNode, options?: RenderOptions): string | Promise<string>;
export function render(node: CoherentNode, options?: RenderOptions): Promise<string>;
export function renderToStream(node: CoherentNode, options?: RenderOptions): ReadableStream;
export function renderBatch(nodes: CoherentNode[], options?: RenderOptions): string[];

// Component creation helpers
export function createComponent(definition: Record<string, any> | Function): ComponentFunction;
export function withState<T>(initialState: T): (component: ComponentFunction) => ComponentFunction;
export function withProps(props: Record<string, any>): (component: ComponentFunction) => ComponentFunction;
export function memo(component: ComponentFunction, areEqual?: (prevProps: any, nextProps: any) => boolean): ComponentFunction;
export function lazy(loader: () => Promise<ComponentFunction>): ComponentFunction;

// Context API
export function provideContext<T>(key: string, value: T): void;
export function restoreContext<T>(key: string): T | undefined;
export function clearAllContexts(): void;
export function createContextProvider<T>(key: string, value: T, children: CoherentNode): ComponentFunction;
export function useContext<T>(key: string): T | undefined;

// State Management
export interface StateContainer<T> {
  get(key: keyof T): any;
  set(key: keyof T, value: any): StateContainer<T>;
  has(key: keyof T): boolean;
  delete(key: keyof T): boolean;
  clear(): StateContainer<T>;
  toObject(): T;
}

export interface StateManager {
  createState<T>(initialState: T): StateContainer<T>;
  globalState: Map<string, any>;
  set(key: string, value: any): void;
  get(key: string): any;
  has(key: string): boolean;
  clear(): void;
  createRequestState<T>(): StateContainer<T>;
}

export const stateManager: StateManager;

// CSS Management
export interface CSSOptions {
  files?: string[];
  links?: string[];
  inline?: string;
  minify?: boolean;
}

export interface CSSManager {
  loadCSSFile(filePath: string): Promise<string>;
  generateCSSLinks(filePaths: string[], baseUrl?: string): string;
  generateInlineStyles(css: string): string;
  minifyCSS(css: string): string;
}

export function createCSSManager(options?: { baseDir?: string; enableCache?: boolean; minify?: boolean }): CSSManager;
export const defaultCSSManager: CSSManager;

export interface CSSUtils {
  processCSSOptions(options: RenderOptions): CSSOptions;
  generateCSSHtml(cssOptions: CSSOptions, cssManager: CSSManager): Promise<string>;
}

export const cssUtils: CSSUtils;

// Performance Monitoring
export interface PerformanceMetrics {
  renderTime: number;
  memoryUsage: number;
  cacheHitRate: number;
  totalRenders: number;
  cacheSize: number;
}

export interface PerformanceRecommendations {
  type: string;
  component: string;
  potentialSavings: string;
  recommendation: string;
}

export function startPerformanceMonitor(): void;
export function getPerformanceMetrics(): PerformanceMetrics;
export function resetPerformanceMetrics(): void;
export function getPerformanceRecommendations(): PerformanceRecommendations[];

// Development tools
export function enableDevMode(): void;
export function disableDevMode(): void;
export function benchmark(component: ComponentFunction, iterations?: number): PerformanceMetrics;

// Cache management
export function clearCache(): void;
export function getCacheStats(): { hits: number; misses: number; size: number };
export function optimizeCache(): void;

// Precompilation
export function precompileComponent(component: ComponentFunction, options?: RenderOptions): ComponentFunction;

// Validation helpers
export function validateComponent(component: CoherentNode): boolean;
export function isCoherentObject(obj: any): boolean;

// Utility methods
export function deepClone<T>(obj: T): T;
export function mergeProps(obj1: Record<string, any>, obj2: Record<string, any>): Record<string, any>;
export function escapeHtml(text: string): string;
export function isVoidElement(tagName: string): boolean;

// Main Coherent class
export class Coherent {
  constructor(options?: RenderOptions);
  
  // Rendering methods
  render(component: CoherentNode, options?: RenderOptions): string;
  renderToString(component: CoherentNode, options?: RenderOptions): string;
  renderBatch(components: CoherentNode[], options?: RenderOptions): string[];
  stream(component: CoherentNode, options?: RenderOptions): ReadableStream;
  
  // Component helpers
  createComponent(definition: Record<string, any>): ComponentFunction;
  withState<T>(initialState: T): (component: ComponentFunction) => ComponentFunction;
  withProps(props: Record<string, any>): (component: ComponentFunction) => ComponentFunction;
  memo(component: ComponentFunction, areEqual?: (prevProps: any, nextProps: any) => boolean): ComponentFunction;
  lazy(loader: () => Promise<ComponentFunction>): ComponentFunction;
  
  // Performance and monitoring
  getPerformanceStats(): PerformanceMetrics;
  getPerformanceRecommendations(): PerformanceRecommendations[];
  enableDevMode(): void;
  disableDevMode(): void;
  benchmark(component: ComponentFunction, iterations?: number): PerformanceMetrics;
  
  // Cache management
  clearCache(): void;
  getCacheStats(): { hits: number; misses: number; size: number };
  optimizeCache(): void;
  
  // Precompilation
  precompile(component: ComponentFunction, options?: RenderOptions): ComponentFunction;
  
  // Validation helpers
  validate(component: CoherentNode): boolean;
  isCoherent(obj: any): boolean;
  
  // Utility methods
  clone<T>(obj: T): T;
  merge(obj1: Record<string, any>, obj2: Record<string, any>): Record<string, any>;
  extract(element: CoherentElement): Record<string, any>;
  normalize(children: CoherentNode | CoherentNode[]): CoherentNode[];
  escape(text: string): string;
  
  // Framework information
  getVersion(): string;
  getInfo(): {
    name: string;
    version: string;
    description: string;
    features: string[];
    stats: PerformanceMetrics;
  };
}

// Default instance
export const coherent: Coherent;
export default Coherent;

// Named exports for specific functionality
export const server: {
  render: typeof renderToString;
  renderBatch: typeof renderBatch;
  stream: typeof renderToStream;
  createStreamingRenderer: Function;
  CacheManager: Function;
  performanceMonitor: {
    start: typeof startPerformanceMonitor;
    getStats: typeof getPerformanceMetrics;
    reset: typeof resetPerformanceMetrics;
    getRecommendations: typeof getPerformanceRecommendations;
  };
};

export const client: {
  hydrate: typeof import('./client/hydration').hydrate;
  hydrateAll: typeof import('./client/hydration').hydrateAll;
  hydrateBySelector: typeof import('./client/hydration').hydrateBySelector;
  enableClientEvents: typeof import('./client/hydration').enableClientEvents;
  makeHydratable: typeof import('./client/hydration').makeHydratable;
};

export const components: {
  createComponent: typeof createComponent;
  withState: typeof withState;
  withProps: typeof withProps;
  memo: typeof memo;
  lazy: typeof lazy;
  validateComponent: typeof validateComponent;
  isCoherentObject: typeof isCoherentObject;
};

export const utils: {
  deepClone: typeof deepClone;
  mergeProps: typeof mergeProps;
  escapeHtml: typeof escapeHtml;
  isVoidElement: typeof isVoidElement;
  extractProps: Function;
  hasChildren: Function;
  normalizeChildren: Function;
  formatAttributes: Function;
  minifyHtml: Function;
  merge: typeof mergeProps;
  getNestedValue: Function;
  setNestedValue: Function;
  cssUtils: typeof cssUtils;
};

export const performance: {
  performanceMonitor: {
    start: typeof startPerformanceMonitor;
    getStats: typeof getPerformanceMetrics;
    reset: typeof resetPerformanceMetrics;
    getRecommendations: typeof getPerformanceRecommendations;
  };
  CacheManager: Function;
  getCache: Function;
  resetCache: typeof clearCache;
  getRenderingStats: Function;
};

// Development tools
export const DevTools: Function;