{"version":3,"file":"types.mjs","sources":["../../../src/lib/vdom/types.ts"],"sourcesContent":["/**\n * @file Virtual Modular DOM System - Core Type Definitions\n * @module vdom/types\n * @description Comprehensive type system for the Virtual Modular DOM architecture.\n * Provides type-safe interfaces for virtual nodes, module boundaries, hydration,\n * security policies, and cross-module communication.\n *\n * @author Agent 5 - PhD Virtual DOM Expert\n * @version 1.0.0\n */\n\nimport type { ReactNode, ComponentType, ErrorInfo, RefObject } from 'react';\nimport type * as _React from 'react';\n\n// ============================================================================\n// Utility Types\n// ============================================================================\n\n/**\n * Branded type for unique module identifiers.\n * Prevents accidental mixing of module IDs with regular strings.\n */\nexport type ModuleId = string & { readonly __brand: 'ModuleId' };\n\n/**\n * Branded type for virtual node identifiers.\n */\nexport type VNodeId = string & { readonly __brand: 'VNodeId' };\n\n/**\n * Branded type for security nonces.\n */\nexport type SecurityNonce = string & { readonly __brand: 'SecurityNonce' };\n\n/**\n * Type-safe event name with module namespace.\n */\nexport type ModuleEventName<T extends string = string> = `module:${T}`;\n\n/**\n * Deep readonly utility type.\n */\nexport type DeepReadonly<T> = T extends (infer R)[]\n  ? ReadonlyArray<DeepReadonly<R>>\n  : T extends object\n    ? { readonly [K in keyof T]: DeepReadonly<T[K]> }\n    : T;\n\n/**\n * Optional properties utility.\n */\nexport type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n// ============================================================================\n// Virtual Node Types\n// ============================================================================\n\n/**\n * Virtual node types enumeration.\n * Represents different categories of virtual DOM nodes.\n */\nexport const VNodeType = {\n  ELEMENT: 'element',\n  TEXT: 'text',\n  COMMENT: 'comment',\n  FRAGMENT: 'fragment',\n  COMPONENT: 'component',\n  PORTAL: 'portal',\n  SUSPENSE: 'suspense',\n  MODULE_BOUNDARY: 'module_boundary',\n} as const;\n\n/**\n * Virtual node properties interface.\n * Represents attributes and event handlers on virtual elements.\n */\nexport interface VNodeProps {\n  /** CSS class names */\n  readonly className?: string;\n  /** Inline styles */\n  readonly style?: Readonly<Record<string, string | number>>;\n  /** Data attributes */\n  readonly data?: Readonly<Record<string, string>>;\n  /** ARIA attributes */\n  readonly aria?: Readonly<Record<string, string | boolean>>;\n  /** Event handlers (keys are event names without 'on' prefix) */\n  readonly events?: Readonly<Record<string, EventListener>>;\n  /** Custom attributes */\n  readonly attributes?: Readonly<Record<string, string | number | boolean | null>>;\n  /** Key for reconciliation */\n  readonly key?: string | number;\n  /** Ref callback or ref object */\n  readonly ref?: ((el: Element | null) => void) | { current: Element | null };\n}\n\n/**\n * Core virtual node interface.\n * Represents a node in the virtual DOM tree.\n */\nexport interface VirtualNode {\n  /** Unique identifier for this virtual node */\n  readonly id: VNodeId;\n  /** Type of virtual node */\n  readonly type: VNodeType;\n  /** Tag name for element nodes, component name for component nodes */\n  readonly tag: string | ComponentType<unknown>;\n  /** Node properties */\n  readonly props: VNodeProps;\n  /** Child virtual nodes */\n  readonly children: ReadonlyArray<VirtualNode | string>;\n  /** Parent node reference (null for root) */\n  parent: VirtualNode | null;\n  /** Associated real DOM element (null before mounting) */\n  element: Element | Text | null;\n  /** Module boundary this node belongs to */\n  readonly moduleId: ModuleId | null;\n  /** Hydration state for SSR */\n  hydrationState: HydrationState;\n  /** Pool generation for garbage collection */\n  poolGeneration: number;\n  /** Whether this node is currently pooled */\n  isPooled: boolean;\n  /** Timestamp of last update */\n  lastUpdated: number;\n}\n\n/**\n * Virtual node creation options.\n */\nexport interface VNodeCreateOptions {\n  /** Parent module ID */\n  moduleId?: ModuleId;\n  /** Initial hydration state */\n  hydrationState?: HydrationState;\n  /** Key for reconciliation */\n  key?: string | number;\n}\n\n// ============================================================================\n// Module Lifecycle Types\n// ============================================================================\n\n/**\n * Module lifecycle states.\n * Represents the current state of a module in its lifecycle.\n */\nexport const ModuleLifecycleState = {\n  /** Module is registered but not yet initialized */\n  REGISTERED: 'registered',\n  /** Module is currently being initialized */\n  INITIALIZING: 'initializing',\n  /** Module has been initialized but not mounted */\n  INITIALIZED: 'initialized',\n  /** Module is currently mounting */\n  MOUNTING: 'mounting',\n  /** Module is fully mounted and active */\n  MOUNTED: 'mounted',\n  /** Module is in suspended state (lazy) */\n  SUSPENDED: 'suspended',\n  /** Module is currently unmounting */\n  UNMOUNTING: 'unmounting',\n  /** Module has been unmounted */\n  UNMOUNTED: 'unmounted',\n  /** Module encountered an error */\n  ERROR: 'error',\n  /** Module has been disposed */\n  DISPOSED: 'disposed',\n} as const;\n\n/**\n * Module lifecycle event types.\n */\nexport const ModuleLifecycleEvent = {\n  BEFORE_INIT: 'beforeInit',\n  AFTER_INIT: 'afterInit',\n  BEFORE_MOUNT: 'beforeMount',\n  AFTER_MOUNT: 'afterMount',\n  BEFORE_UPDATE: 'beforeUpdate',\n  AFTER_UPDATE: 'afterUpdate',\n  BEFORE_UNMOUNT: 'beforeUnmount',\n  AFTER_UNMOUNT: 'afterUnmount',\n  ERROR: 'error',\n  DISPOSE: 'dispose',\n} as const;\n\n/**\n * Lifecycle hook callback type.\n */\nexport type LifecycleHook<T = void> = () => T | Promise<T>;\n\n/**\n * Module lifecycle hooks configuration.\n */\nexport interface ModuleLifecycleHooks {\n  /** Called before module initialization */\n  readonly onBeforeInit?: LifecycleHook;\n  /** Called after module initialization */\n  readonly onAfterInit?: LifecycleHook;\n  /** Called before module mounts */\n  readonly onBeforeMount?: LifecycleHook;\n  /** Called after module mounts */\n  readonly onAfterMount?: LifecycleHook;\n  /** Called before module updates */\n  readonly onBeforeUpdate?: LifecycleHook;\n  /** Called after module updates */\n  readonly onAfterUpdate?: LifecycleHook;\n  /** Called before module unmounts */\n  readonly onBeforeUnmount?: LifecycleHook;\n  /** Called after module unmounts */\n  readonly onAfterUnmount?: LifecycleHook;\n  /** Called when module encounters an error */\n  readonly onError?: (error: Error, errorInfo?: ErrorInfo) => void;\n  /** Called when module is being disposed */\n  readonly onDispose?: LifecycleHook;\n}\n\n// ============================================================================\n// Hydration Types\n// ============================================================================\n\n/**\n * Hydration states for SSR support.\n */\nexport const HydrationState = {\n  /** Not yet hydrated (server-rendered HTML) */\n  DEHYDRATED: 'dehydrated',\n  /** Hydration is pending/scheduled */\n  PENDING: 'pending',\n  /** Currently hydrating */\n  HYDRATING: 'hydrating',\n  /** Fully hydrated and interactive */\n  HYDRATED: 'hydrated',\n  /** Hydration skipped (client-only) */\n  SKIPPED: 'skipped',\n  /** Hydration failed */\n  FAILED: 'failed',\n} as const;\n\n/**\n * Hydration priority levels.\n * Lower numbers indicate higher priority.\n */\nexport const HydrationPriority = {\n  /** Critical - hydrate immediately (above fold, interactive) */\n  CRITICAL: 1,\n  /** High - hydrate soon (visible, may be interacted with) */\n  HIGH: 2,\n  /** Normal - standard hydration priority */\n  NORMAL: 3,\n  /** Low - hydrate when idle (below fold) */\n  LOW: 4,\n  /** Deferred - hydrate only when needed */\n  DEFERRED: 5,\n} as const;\n\n/**\n * Hydration trigger types.\n */\nexport const HydrationTrigger = {\n  /** Hydrate immediately on load */\n  IMMEDIATE: 'immediate',\n  /** Hydrate when element becomes visible */\n  VISIBLE: 'visible',\n  /** Hydrate during idle time */\n  IDLE: 'idle',\n  /** Hydrate on user interaction */\n  INTERACTION: 'interaction',\n  /** Hydrate only when explicitly triggered */\n  MANUAL: 'manual',\n} as const;\n\n/**\n * Hydration configuration for a module.\n */\nexport interface HydrationConfig {\n  /** Hydration priority level */\n  readonly priority: HydrationPriority;\n  /** What triggers hydration */\n  readonly trigger: HydrationTrigger;\n  /** Timeout before fallback (ms) */\n  readonly timeout?: number;\n  /** Root margin for visibility trigger */\n  readonly rootMargin?: string;\n  /** Visibility threshold (0-1) */\n  readonly threshold?: number;\n  /** Whether to hydrate children independently */\n  readonly independentChildren?: boolean;\n  /** Callback when hydration starts */\n  readonly onHydrationStart?: () => void;\n  /** Callback when hydration completes */\n  readonly onHydrationComplete?: () => void;\n  /** Callback when hydration fails */\n  readonly onHydrationError?: (error: Error) => void;\n}\n\n/**\n * Hydration data passed from server.\n */\nexport interface HydrationData {\n  /** Unique identifier */\n  readonly id: string;\n  /** Module ID this data belongs to */\n  readonly moduleId: ModuleId;\n  /** Serialized state */\n  readonly state: unknown;\n  /** Timestamp when data was created */\n  readonly timestamp: number;\n  /** Checksum for integrity verification */\n  readonly checksum: string;\n  /** Whether data has been sanitized */\n  readonly sanitized: boolean;\n}\n\n// ============================================================================\n// Module Boundary Types\n// ============================================================================\n\n/**\n * Module dependency type.\n */\nexport interface ModuleDependency {\n  /** ID of the dependency module */\n  readonly moduleId: ModuleId;\n  /** Whether this dependency is required */\n  readonly required: boolean;\n  /** Minimum version if versioned */\n  readonly minVersion?: string;\n  /** Whether to load lazily */\n  readonly lazy?: boolean;\n}\n\n/**\n * Slot definition for module composition.\n */\nexport interface ModuleSlotDefinition {\n  /** Unique slot name */\n  readonly name: string;\n  /** Default content if slot is empty */\n  readonly defaultContent?: ReactNode;\n  /** Whether slot is required */\n  readonly required?: boolean;\n  /** Accepted child module types */\n  readonly accepts?: ReadonlyArray<string>;\n  /** Maximum number of children */\n  readonly maxChildren?: number;\n}\n\n/**\n * Module boundary configuration.\n */\nexport interface ModuleBoundaryConfig {\n  /** Unique module identifier */\n  readonly id: ModuleId;\n  /** Human-readable module name */\n  readonly name: string;\n  /** Module version */\n  readonly version?: string;\n  /** Module dependencies */\n  readonly dependencies?: ReadonlyArray<ModuleDependency>;\n  /** Available slots for composition */\n  readonly slots?: ReadonlyArray<ModuleSlotDefinition>;\n  /** Lifecycle hooks */\n  readonly lifecycle?: ModuleLifecycleHooks;\n  /** Hydration configuration */\n  readonly hydration?: Partial<HydrationConfig>;\n  /** Security configuration */\n  readonly security?: Partial<ModuleSecurityConfig>;\n  /** Whether module should be isolated */\n  readonly isolated?: boolean;\n  /** Performance budget (ms) */\n  readonly performanceBudget?: number;\n  /** Whether to enable strict mode */\n  readonly strict?: boolean;\n}\n\n/**\n * Module boundary state.\n */\nexport interface ModuleBoundaryState {\n  /** Current lifecycle state */\n  readonly lifecycleState: ModuleLifecycleState;\n  /** Current hydration state */\n  readonly hydrationState: HydrationState;\n  /** Whether module is currently visible */\n  readonly isVisible: boolean;\n  /** Whether module is currently active */\n  readonly isActive: boolean;\n  /** Error if module is in error state */\n  readonly error: Error | null;\n  /** Error info from React error boundary */\n  readonly errorInfo: ErrorInfo | null;\n  /** Slot contents */\n  readonly slots: Map<string, ReactNode>;\n  /** Module-scoped state */\n  readonly moduleState: Map<string, unknown>;\n  /** Performance metrics */\n  readonly metrics: ModulePerformanceMetrics;\n}\n\n/**\n * Virtual module interface.\n * Represents a complete module unit.\n */\nexport interface VirtualModule {\n  /** Module configuration */\n  readonly config: ModuleBoundaryConfig;\n  /** Module state */\n  readonly state: ModuleBoundaryState;\n  /** Root virtual nodes */\n  readonly vdom: ReadonlyArray<VirtualNode>;\n  /** Container element */\n  container: Element | null;\n  /** Portal roots */\n  readonly portals: Map<string, Element>;\n  /** Child modules */\n  readonly children: Map<ModuleId, VirtualModule>;\n  /** Parent module */\n  parent: VirtualModule | null;\n}\n\n// ============================================================================\n// Security Types\n// ============================================================================\n\n/**\n * Content Security Policy directive types.\n */\nexport interface CSPDirectives {\n  readonly 'default-src'?: ReadonlyArray<string>;\n  readonly 'script-src'?: ReadonlyArray<string>;\n  readonly 'style-src'?: ReadonlyArray<string>;\n  readonly 'img-src'?: ReadonlyArray<string>;\n  readonly 'font-src'?: ReadonlyArray<string>;\n  readonly 'connect-src'?: ReadonlyArray<string>;\n  readonly 'frame-src'?: ReadonlyArray<string>;\n  readonly 'object-src'?: ReadonlyArray<string>;\n  readonly 'base-uri'?: ReadonlyArray<string>;\n  readonly 'form-action'?: ReadonlyArray<string>;\n}\n\n/**\n * Module security configuration.\n */\nexport interface ModuleSecurityConfig {\n  /** CSP directives for this module */\n  readonly csp?: CSPDirectives;\n  /** Security nonce for inline scripts/styles */\n  readonly nonce?: SecurityNonce;\n  /** Whether to sandbox the module */\n  readonly sandbox?: boolean;\n  /** Sandbox flags if sandboxed */\n  readonly sandboxFlags?: ReadonlyArray<string>;\n  /** Trusted types policy name */\n  readonly trustedTypesPolicy?: string;\n  /** Whether to sanitize hydration data */\n  readonly sanitizeHydration?: boolean;\n  /** Allowed cross-module event patterns */\n  readonly allowedEvents?: ReadonlyArray<string | RegExp>;\n  /** Blocked cross-module event patterns */\n  readonly blockedEvents?: ReadonlyArray<string | RegExp>;\n  /** Maximum message size for cross-module communication */\n  readonly maxMessageSize?: number;\n  /** Whether to validate message origins */\n  readonly validateOrigins?: boolean;\n}\n\n/**\n * Security context for a module.\n */\nexport interface SecurityContext {\n  /** Security configuration */\n  readonly config: ModuleSecurityConfig;\n  /** Current nonce */\n  readonly nonce: SecurityNonce | null;\n  /** Whether context is secure */\n  readonly isSecure: boolean;\n  /** Violations detected */\n  readonly violations: ReadonlyArray<SecurityViolation>;\n  /** Validate content against policy */\n  readonly validateContent: (content: string) => boolean;\n  /** Sanitize content */\n  readonly sanitize: (content: string) => string;\n  /** Check if event is allowed */\n  readonly isEventAllowed: (eventName: string) => boolean;\n}\n\n/**\n * Security violation record.\n */\nexport interface SecurityViolation {\n  /** Type of violation */\n  readonly type: 'csp' | 'xss' | 'injection' | 'origin' | 'size';\n  /** Description of violation */\n  readonly message: string;\n  /** Module where violation occurred */\n  readonly moduleId: ModuleId;\n  /** Timestamp of violation */\n  readonly timestamp: number;\n  /** Source of violation */\n  readonly source?: string;\n  /** Blocked content */\n  readonly blockedContent?: string;\n}\n\n// ============================================================================\n// Event Bus Types\n// ============================================================================\n\n/**\n * Event priority levels.\n */\nexport const EventPriority = {\n  /** Highest priority - process immediately */\n  CRITICAL: 0,\n  /** High priority */\n  HIGH: 1,\n  /** Normal priority */\n  NORMAL: 2,\n  /** Low priority - process when idle */\n  LOW: 3,\n} as const;\n\n/**\n * Base event message interface.\n */\nexport interface ModuleEventMessage<T = unknown> {\n  /** Unique event ID */\n  readonly id: string;\n  /** Event name */\n  readonly name: string;\n  /** Source module ID */\n  readonly source: ModuleId;\n  /** Target module ID (null for broadcast) */\n  readonly target: ModuleId | null;\n  /** Event payload */\n  readonly payload: T;\n  /** Event priority */\n  readonly priority: EventPriority;\n  /** Timestamp */\n  readonly timestamp: number;\n  /** Whether event requires acknowledgment */\n  readonly requiresAck?: boolean;\n  /** Correlation ID for request-response patterns */\n  readonly correlationId?: string;\n}\n\n/**\n * Event subscription options.\n */\nexport interface EventSubscriptionOptions {\n  /** Filter by source module */\n  readonly sourceFilter?: ModuleId | RegExp;\n  /** Priority filter (only receive events of this priority or higher) */\n  readonly priorityFilter?: EventPriority;\n  /** Whether to receive own events */\n  readonly receiveSelf?: boolean;\n  /** Maximum events to receive before auto-unsubscribe */\n  readonly maxEvents?: number;\n  /** Timeout before auto-unsubscribe */\n  readonly timeout?: number;\n  /** Transform payload before delivery */\n  readonly transform?: <T>(payload: T) => T;\n}\n\n/**\n * Event handler type.\n */\nexport type EventHandler<T = unknown> = (message: ModuleEventMessage<T>) => void | Promise<void>;\n\n/**\n * Subscription handle for cleanup.\n */\nexport interface EventSubscription {\n  /** Unique subscription ID */\n  readonly id: string;\n  /** Event name subscribed to */\n  readonly eventName: string;\n  /** Unsubscribe from event */\n  readonly unsubscribe: () => void;\n  /** Whether subscription is still active */\n  readonly isActive: boolean;\n}\n\n// ============================================================================\n// Pool Types\n// ============================================================================\n\n/**\n * Pool configuration.\n */\nexport interface VDOMPoolConfig {\n  /** Initial pool size */\n  readonly initialSize: number;\n  /** Maximum pool size */\n  readonly maxSize: number;\n  /** Minimum free nodes to maintain */\n  readonly minFreeNodes: number;\n  /** Growth factor when pool needs expansion */\n  readonly growthFactor: number;\n  /** Shrink threshold (percentage of unused nodes) */\n  readonly shrinkThreshold: number;\n  /** GC interval in milliseconds */\n  readonly gcIntervalMs: number;\n  /** Node TTL before eligible for GC */\n  readonly nodeTtlMs: number;\n  /** Enable memory pressure detection */\n  readonly enableMemoryPressure: boolean;\n  /** Memory threshold to trigger aggressive GC (0-1) */\n  readonly memoryPressureThreshold: number;\n}\n\n/**\n * Pool statistics.\n */\nexport interface VDOMPoolStats {\n  /** Total nodes in pool */\n  readonly totalNodes: number;\n  /** Currently in-use nodes */\n  readonly inUseNodes: number;\n  /** Available nodes */\n  readonly freeNodes: number;\n  /** Nodes acquired since start */\n  readonly acquireCount: number;\n  /** Nodes released since start */\n  readonly releaseCount: number;\n  /** Pool expansions performed */\n  readonly expansionCount: number;\n  /** GC runs performed */\n  readonly gcCount: number;\n  /** Nodes collected by GC */\n  readonly gcCollectedCount: number;\n  /** Current pool generation */\n  readonly generation: number;\n  /** Estimated memory usage (bytes) */\n  readonly estimatedMemoryBytes: number;\n  /** Last GC timestamp */\n  readonly lastGcTimestamp: number;\n  /** Pool utilization (0-1) */\n  readonly utilization: number;\n}\n\n// ============================================================================\n// Registry Types\n// ============================================================================\n\n/**\n * Module registration entry.\n */\nexport interface ModuleRegistryEntry {\n  /** Module configuration */\n  readonly config: ModuleBoundaryConfig;\n  /** Dynamic import function for lazy loading */\n  readonly loader?: () => Promise<ComponentType<unknown>>;\n  /** Loaded component (null if not yet loaded) */\n  component: ComponentType<unknown> | null;\n  /** Loading state */\n  loadingState: 'idle' | 'loading' | 'loaded' | 'error';\n  /** Loading error if any */\n  loadingError: Error | null;\n  /** Registration timestamp */\n  readonly registeredAt: number;\n  /** Last accessed timestamp */\n  lastAccessedAt: number;\n  /** Access count */\n  accessCount: number;\n  /** Whether module supports HMR */\n  readonly hmrEnabled?: boolean;\n}\n\n/**\n * Module registry query options.\n */\nexport interface ModuleQueryOptions {\n  /** Filter by lifecycle state */\n  readonly lifecycleState?: ModuleLifecycleState;\n  /** Filter by hydration state */\n  readonly hydrationState?: HydrationState;\n  /** Include only modules matching pattern */\n  readonly namePattern?: RegExp;\n  /** Include dependencies */\n  readonly includeDependencies?: boolean;\n  /** Maximum depth for dependency resolution */\n  readonly maxDepth?: number;\n}\n\n// ============================================================================\n// Loader Types\n// ============================================================================\n\n/**\n * Module loading priority.\n */\nexport const LoadingPriority = {\n  /** Critical - load immediately */\n  CRITICAL: 0,\n  /** High - load soon */\n  HIGH: 1,\n  /** Normal - standard loading */\n  NORMAL: 2,\n  /** Low - load when idle */\n  LOW: 3,\n  /** Prefetch - load in background */\n  PREFETCH: 4,\n} as const;\n\n/**\n * Module loading options.\n */\nexport interface ModuleLoadOptions {\n  /** Loading priority */\n  readonly priority?: LoadingPriority;\n  /** Timeout in milliseconds */\n  readonly timeout?: number;\n  /** Retry count on failure */\n  readonly retries?: number;\n  /** Retry delay in milliseconds */\n  readonly retryDelay?: number;\n  /** Whether to preload dependencies */\n  readonly preloadDependencies?: boolean;\n  /** Callback on loading progress */\n  readonly onProgress?: (progress: number) => void;\n  /** Callback on loading complete */\n  readonly onComplete?: () => void;\n  /** Callback on loading error */\n  readonly onError?: (error: Error) => void;\n}\n\n/**\n * Module loading state.\n */\nexport interface ModuleLoadingState {\n  /** Module ID */\n  readonly moduleId: ModuleId;\n  /** Current loading state */\n  readonly state: 'idle' | 'queued' | 'loading' | 'loaded' | 'error';\n  /** Loading progress (0-1) */\n  readonly progress: number;\n  /** Error if state is 'error' */\n  readonly error: Error | null;\n  /** Started loading timestamp */\n  readonly startedAt: number | null;\n  /** Completed loading timestamp */\n  readonly completedAt: number | null;\n  /** Dependencies loaded */\n  readonly dependenciesLoaded: number;\n  /** Total dependencies */\n  readonly dependenciesTotal: number;\n}\n\n// ============================================================================\n// Performance Types\n// ============================================================================\n\n/**\n * Module performance metrics.\n */\nexport interface ModulePerformanceMetrics {\n  /** Time to initialize (ms) */\n  readonly initTime: number;\n  /** Time to mount (ms) */\n  readonly mountTime: number;\n  /** Time to hydrate (ms) */\n  readonly hydrationTime: number;\n  /** Render count */\n  readonly renderCount: number;\n  /** Total render time (ms) */\n  readonly totalRenderTime: number;\n  /** Average render time (ms) */\n  readonly avgRenderTime: number;\n  /** Peak render time (ms) */\n  readonly peakRenderTime: number;\n  /** Update count */\n  readonly updateCount: number;\n  /** Memory usage estimate (bytes) */\n  readonly memoryEstimate: number;\n  /** Virtual nodes count */\n  readonly vNodeCount: number;\n  /** DOM nodes count */\n  readonly domNodeCount: number;\n  /** Last measured timestamp */\n  readonly lastMeasuredAt: number;\n}\n\n/**\n * Performance budget configuration.\n */\nexport interface PerformanceBudget {\n  /** Maximum init time (ms) */\n  readonly maxInitTime?: number;\n  /** Maximum mount time (ms) */\n  readonly maxMountTime?: number;\n  /** Maximum render time (ms) */\n  readonly maxRenderTime?: number;\n  /** Maximum hydration time (ms) */\n  readonly maxHydrationTime?: number;\n  /** Maximum virtual nodes */\n  readonly maxVNodes?: number;\n  /** Maximum memory (bytes) */\n  readonly maxMemory?: number;\n  /** Callback when budget exceeded */\n  readonly onBudgetExceeded?: (\n    metric: keyof PerformanceBudget,\n    value: number,\n    budget: number\n  ) => void;\n}\n\n// ============================================================================\n// Context Types\n// ============================================================================\n\n/**\n * Module context value.\n */\nexport interface ModuleContextValue {\n  /** Module ID */\n  readonly moduleId: ModuleId;\n  /** Module configuration */\n  readonly config: ModuleBoundaryConfig;\n  /** Module state */\n  readonly state: ModuleBoundaryState;\n  /** Security context */\n  readonly security: SecurityContext;\n  /** Parent module context (null if root) */\n  readonly parent: ModuleContextValue | null;\n  /** Dispatch module action */\n  readonly dispatch: (action: ModuleAction) => void;\n  /** Get slot content */\n  readonly getSlot: (name: string) => ReactNode | null;\n  /** Set slot content */\n  readonly setSlot: (name: string, content: ReactNode) => void;\n  /** Trigger hydration */\n  readonly hydrate: () => Promise<void>;\n  /** Subscribe to lifecycle events */\n  readonly subscribe: (event: ModuleLifecycleEvent, handler: () => void) => () => void;\n}\n\n/**\n * Module actions for state updates.\n */\nexport type ModuleAction =\n  | { type: 'SET_STATE'; key: string; value: unknown }\n  | { type: 'MERGE_STATE'; state: Record<string, unknown> }\n  | { type: 'RESET_STATE' }\n  | { type: 'SET_SLOT'; name: string; content: ReactNode }\n  | { type: 'CLEAR_SLOT'; name: string }\n  | { type: 'TRIGGER_HYDRATION' }\n  | { type: 'SET_VISIBILITY'; isVisible: boolean }\n  | { type: 'SET_ERROR'; error: Error; errorInfo?: ErrorInfo }\n  | { type: 'CLEAR_ERROR' }\n  | { type: 'TRANSITION_STATE'; to: ModuleLifecycleState };\n\n/**\n * Module provider configuration.\n */\nexport interface ModuleProviderConfig {\n  /** Enable development mode features */\n  readonly devMode?: boolean;\n  /** Enable strict mode checks */\n  readonly strictMode?: boolean;\n  /** Global security configuration */\n  readonly security?: Partial<ModuleSecurityConfig>;\n  /** Global hydration configuration */\n  readonly hydration?: Partial<HydrationConfig>;\n  /** Global performance budget */\n  readonly performanceBudget?: PerformanceBudget;\n  /** VDOM pool configuration */\n  readonly poolConfig?: Partial<VDOMPoolConfig>;\n  /** Enable telemetry */\n  readonly enableTelemetry?: boolean;\n  /** Telemetry reporter */\n  readonly telemetryReporter?: (metrics: ModulePerformanceMetrics) => void;\n}\n\n// ============================================================================\n// Hook Return Types\n// ============================================================================\n\n/**\n * useModule hook return type.\n */\nexport interface UseModuleReturn {\n  /** Module ID */\n  readonly moduleId: ModuleId;\n  /** Module configuration */\n  readonly config: ModuleBoundaryConfig;\n  /** Module lifecycle state */\n  readonly lifecycleState: ModuleLifecycleState;\n  /** Whether module is mounted */\n  readonly isMounted: boolean;\n  /** Whether module is visible */\n  readonly isVisible: boolean;\n  /** Whether module has error */\n  readonly hasError: boolean;\n  /** Module error if any */\n  readonly error: Error | null;\n  /** Performance metrics */\n  readonly metrics: ModulePerformanceMetrics;\n  /** Emit event */\n  readonly emit: <T>(name: string, payload: T) => void;\n  /** Subscribe to event */\n  readonly on: <T>(\n    name: string,\n    handler: EventHandler<T>,\n    options?: EventSubscriptionOptions\n  ) => EventSubscription;\n}\n\n/**\n * useModuleState hook return type.\n */\nexport interface UseModuleStateReturn<T> {\n  /** Current state value */\n  readonly state: T;\n  /** Set state value */\n  readonly setState: (value: T | ((prev: T) => T)) => void;\n  /** Merge partial state */\n  readonly mergeState: (partial: Partial<T>) => void;\n  /** Reset to initial state */\n  readonly resetState: () => void;\n  /** Whether state is loading */\n  readonly isLoading: boolean;\n  /** State error if any */\n  readonly error: Error | null;\n}\n\n/**\n * useModuleBoundary hook return type.\n */\nexport interface UseModuleBoundaryReturn {\n  /** Boundary element ref */\n  readonly boundaryRef: RefObject<HTMLElement | null>;\n  /** Slot definitions */\n  readonly slots: ReadonlyArray<ModuleSlotDefinition>;\n  /** Get slot content */\n  readonly getSlot: (name: string) => ReactNode | null;\n  /** Fill slot with content */\n  readonly fillSlot: (name: string, content: ReactNode) => void;\n  /** Clear slot content */\n  readonly clearSlot: (name: string) => void;\n  /** Boundary dimensions */\n  readonly dimensions: DOMRect | null;\n  /** Is boundary visible */\n  readonly isVisible: boolean;\n  /** Parent boundary info */\n  readonly parentBoundary: UseModuleBoundaryReturn | null;\n}\n\n/**\n * useModuleHydration hook return type.\n */\nexport interface UseModuleHydrationReturn {\n  /** Current hydration state */\n  readonly hydrationState: HydrationState;\n  /** Whether hydration is complete */\n  readonly isHydrated: boolean;\n  /** Whether hydration is pending */\n  readonly isPending: boolean;\n  /** Whether hydration is in progress */\n  readonly isHydrating: boolean;\n  /** Whether hydration failed */\n  readonly hasFailed: boolean;\n  /** Hydration error if failed */\n  readonly error: Error | null;\n  /** Hydration progress (0-1) */\n  readonly progress: number;\n  /** Trigger manual hydration */\n  readonly hydrate: () => Promise<void>;\n  /** Skip hydration */\n  readonly skip: () => void;\n  /** Hydration data from server */\n  readonly data: HydrationData | null;\n}\n\n/**\n * useSecureModule hook return type.\n */\nexport interface UseSecureModuleReturn {\n  /** Security context */\n  readonly securityContext: SecurityContext;\n  /** Current nonce */\n  readonly nonce: SecurityNonce | null;\n  /** Whether context is secure */\n  readonly isSecure: boolean;\n  /** Validate content */\n  readonly validateContent: (content: string) => boolean;\n  /** Sanitize content */\n  readonly sanitize: (content: string) => string;\n  /** Check if event is allowed */\n  readonly isEventAllowed: (eventName: string) => boolean;\n  /** Security violations */\n  readonly violations: ReadonlyArray<SecurityViolation>;\n  /** Report security violation */\n  readonly reportViolation: (violation: Omit<SecurityViolation, 'timestamp'>) => void;\n}\n\n// ============================================================================\n// Factory Functions Type Helpers\n// ============================================================================\n\n/**\n * Creates a branded ModuleId from a string.\n */\nexport function createModuleId(id: string): ModuleId {\n  return id as ModuleId;\n}\n\n/**\n * Creates a branded VNodeId from a string.\n */\nexport function createVNodeId(id: string): VNodeId {\n  return id as VNodeId;\n}\n\n/**\n * Creates a branded SecurityNonce from a string.\n */\nexport function createSecurityNonce(nonce: string): SecurityNonce {\n  return nonce as SecurityNonce;\n}\n\n/**\n * Type guard for ModuleId.\n */\nexport function isModuleId(value: unknown): value is ModuleId {\n  return typeof value === 'string' && value.length > 0;\n}\n\n/**\n * Type guard for VNodeId.\n */\nexport function isVNodeId(value: unknown): value is VNodeId {\n  return typeof value === 'string' && value.length > 0;\n}\n\n/**\n * Default hydration configuration.\n */\nexport const DEFAULT_HYDRATION_CONFIG: HydrationConfig = {\n  priority: HydrationPriority.NORMAL,\n  trigger: HydrationTrigger.VISIBLE,\n  timeout: 5000,\n  rootMargin: '100px',\n  threshold: 0.1,\n  independentChildren: false,\n} as const;\n\n/**\n * Default pool configuration.\n */\nexport const DEFAULT_POOL_CONFIG: VDOMPoolConfig = {\n  initialSize: 100,\n  maxSize: 10000,\n  minFreeNodes: 20,\n  growthFactor: 2,\n  shrinkThreshold: 0.75,\n  gcIntervalMs: 30000,\n  nodeTtlMs: 60000,\n  enableMemoryPressure: true,\n  memoryPressureThreshold: 0.9,\n} as const;\n\n/**\n * Default security configuration.\n */\nexport const DEFAULT_SECURITY_CONFIG: ModuleSecurityConfig = {\n  sandbox: false,\n  sanitizeHydration: true,\n  maxMessageSize: 1024 * 1024, // 1MB\n  validateOrigins: true,\n} as const;\n\n// ============================================================================\n// Derived Types (must be at end to avoid redeclaration errors)\n// ============================================================================\n\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type VNodeType = (typeof VNodeType)[keyof typeof VNodeType];\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type ModuleLifecycleState = (typeof ModuleLifecycleState)[keyof typeof ModuleLifecycleState];\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type ModuleLifecycleEvent = (typeof ModuleLifecycleEvent)[keyof typeof ModuleLifecycleEvent];\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type HydrationState = (typeof HydrationState)[keyof typeof HydrationState];\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type HydrationPriority = (typeof HydrationPriority)[keyof typeof HydrationPriority];\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type HydrationTrigger = (typeof HydrationTrigger)[keyof typeof HydrationTrigger];\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type EventPriority = (typeof EventPriority)[keyof typeof EventPriority];\n// eslint-disable-next-line no-redeclare -- Valid TypeScript pattern for const/type with same name\nexport type LoadingPriority = (typeof LoadingPriority)[keyof typeof LoadingPriority];\n"],"names":["VNodeType","ModuleLifecycleState","ModuleLifecycleEvent","HydrationState","HydrationPriority","HydrationTrigger","EventPriority","LoadingPriority","createModuleId","id","createVNodeId","createSecurityNonce","nonce","isModuleId","value","isVNodeId","DEFAULT_HYDRATION_CONFIG","DEFAULT_POOL_CONFIG","DEFAULT_SECURITY_CONFIG"],"mappings":"AA6DO,MAAMA,IAAY;AAAA,EACvB,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,iBAAiB;AACnB,GA4EaC,IAAuB;AAAA;AAAA,EAElC,YAAY;AAAA;AAAA,EAEZ,cAAc;AAAA;AAAA,EAEd,aAAa;AAAA;AAAA,EAEb,UAAU;AAAA;AAAA,EAEV,SAAS;AAAA;AAAA,EAET,WAAW;AAAA;AAAA,EAEX,YAAY;AAAA;AAAA,EAEZ,WAAW;AAAA;AAAA,EAEX,OAAO;AAAA;AAAA,EAEP,UAAU;AACZ,GAKaC,IAAuB;AAAA,EAClC,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,aAAa;AAAA,EACb,eAAe;AAAA,EACf,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AACX,GAwCaC,IAAiB;AAAA;AAAA,EAE5B,YAAY;AAAA;AAAA,EAEZ,SAAS;AAAA;AAAA,EAET,WAAW;AAAA;AAAA,EAEX,UAAU;AAAA;AAAA,EAEV,SAAS;AAAA;AAAA,EAET,QAAQ;AACV,GAMaC,IAAoB;AAAA;AAAA,EAE/B,UAAU;AAAA;AAAA,EAEV,MAAM;AAAA;AAAA,EAEN,QAAQ;AAAA;AAAA,EAER,KAAK;AAAA;AAAA,EAEL,UAAU;AACZ,GAKaC,IAAmB;AAAA;AAAA,EAE9B,WAAW;AAAA;AAAA,EAEX,SAAS;AAAA;AAAA,EAET,MAAM;AAAA;AAAA,EAEN,aAAa;AAAA;AAAA,EAEb,QAAQ;AACV,GAkPaC,IAAgB;AAAA;AAAA,EAE3B,UAAU;AAAA;AAAA,EAEV,MAAM;AAAA;AAAA,EAEN,QAAQ;AAAA;AAAA,EAER,KAAK;AACP,GA4KaC,IAAkB;AAAA;AAAA,EAE7B,UAAU;AAAA;AAAA,EAEV,MAAM;AAAA;AAAA,EAEN,QAAQ;AAAA;AAAA,EAER,KAAK;AAAA;AAAA,EAEL,UAAU;AACZ;AA4SO,SAASC,EAAeC,GAAsB;AACnD,SAAOA;AACT;AAKO,SAASC,EAAcD,GAAqB;AACjD,SAAOA;AACT;AAKO,SAASE,EAAoBC,GAA8B;AAChE,SAAOA;AACT;AAKO,SAASC,EAAWC,GAAmC;AAC5D,SAAO,OAAOA,KAAU,YAAYA,EAAM,SAAS;AACrD;AAKO,SAASC,EAAUD,GAAkC;AAC1D,SAAO,OAAOA,KAAU,YAAYA,EAAM,SAAS;AACrD;AAKO,MAAME,IAA4C;AAAA,EACvD,UAAUZ,EAAkB;AAAA,EAC5B,SAASC,EAAiB;AAAA,EAC1B,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,qBAAqB;AACvB,GAKaY,IAAsC;AAAA,EACjD,aAAa;AAAA,EACb,SAAS;AAAA,EACT,cAAc;AAAA,EACd,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,WAAW;AAAA,EACX,sBAAsB;AAAA,EACtB,yBAAyB;AAC3B,GAKaC,IAAgD;AAAA,EAC3D,SAAS;AAAA,EACT,mBAAmB;AAAA,EACnB,gBAAgB,OAAO;AAAA;AAAA,EACvB,iBAAiB;AACnB;"}