{"version":3,"file":"portal-bridge.mjs","sources":["../../../../src/lib/layouts/context-aware/portal-bridge.ts"],"sourcesContent":["/**\n * @fileoverview Portal Context Bridge System\n *\n * This module provides context preservation across React portals:\n * - Maintains DOM context when rendering through portals\n * - Bridges z-index management across portal boundaries\n * - Enables event bubbling back to source context\n * - Supports nested portal hierarchies\n *\n * @module layouts/context-aware/portal-bridge\n * @author Agent 4 - PhD Context Systems Expert\n * @version 1.0.0\n */\n\nimport type {\n  PortalContext,\n  DOMContextSnapshot,\n  ZIndexLayer,\n  ZIndexContext,\n  LayoutAncestor,\n  ViewportInfo,\n  ScrollContainer,\n  ContextTrackingConfig,\n} from './types';\nimport { Z_INDEX_LAYERS, DEFAULT_TRACKING_CONFIG } from './types';\nimport { getDOMContextTracker } from './dom-context';\nimport { getViewportTracker } from './viewport-awareness';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Options for creating a portal context.\n */\nexport interface PortalContextOptions {\n  /** Target portal root element or selector */\n  target?: Element | string;\n  /** Z-index layer for the portal */\n  layer?: ZIndexLayer;\n  /** Whether to bridge events back to source */\n  bridgeEvents?: boolean;\n  /** Parent portal context (for nesting) */\n  parentPortal?: PortalContext | null;\n}\n\n/**\n * Callback for portal lifecycle events.\n */\nexport type PortalLifecycleCallback = (portal: PortalContext) => void;\n\n/**\n * Event handler for bridged events.\n */\nexport type BridgedEventHandler = (event: Event, sourceContext: DOMContextSnapshot) => void;\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst DEFAULT_PORTAL_ROOT_ID = 'portal-root';\nconst PORTAL_CONTEXT_ATTR = 'data-portal-context';\n\n// ============================================================================\n// PortalContextManager Class\n// ============================================================================\n\n/**\n * Manages portal contexts and context bridging across portal boundaries.\n *\n * @remarks\n * Singleton class that handles the creation and management of portal contexts,\n * ensuring that DOM context is preserved when components render through portals.\n *\n * @example\n * ```typescript\n * const manager = PortalContextManager.getInstance();\n *\n * // Create a portal context from a source element\n * const context = manager.createPortalContext(sourceElement, {\n *   target: document.getElementById('modal-root'),\n *   layer: 'modal',\n *   bridgeEvents: true,\n * });\n *\n * // Use the context in your portal\n * // When done:\n * manager.destroyPortalContext(context.portalId);\n * ```\n */\nexport class PortalContextManager {\n  private static instance: PortalContextManager | null = null;\n\n  /** Map of portal IDs to their contexts */\n  private readonly portalContexts: Map<string, PortalContext> = new Map();\n\n  /** Map of portal IDs to their source elements */\n  private readonly sourceElements: Map<string, Element> = new Map();\n\n  /** Map of portal IDs to lifecycle callbacks */\n  private readonly lifecycleCallbacks: Map<string, Set<PortalLifecycleCallback>> = new Map();\n\n  /** Map of portal IDs to bridged event handlers */\n  private readonly eventHandlers: Map<string, Set<BridgedEventHandler>> = new Map();\n\n  /** Configuration */\n  private readonly config: ContextTrackingConfig;\n\n  /** Whether we're in SSR mode */\n  private readonly isSSR: boolean;\n\n  /** Portal ID counter */\n  private portalIdCounter = 0;\n\n  /**\n   * Creates a new PortalContextManager instance.\n   */\n  private constructor(config: Partial<ContextTrackingConfig> = {}) {\n    this.config = { ...DEFAULT_TRACKING_CONFIG, ...config };\n    this.isSSR = typeof window === 'undefined';\n  }\n\n  /**\n   * Gets the singleton instance.\n   */\n  public static getInstance(config?: Partial<ContextTrackingConfig>): PortalContextManager {\n    PortalContextManager.instance ??= new PortalContextManager(config);\n    return PortalContextManager.instance;\n  }\n\n  /**\n   * Resets the singleton instance.\n   */\n  public static resetInstance(): void {\n    if (PortalContextManager.instance) {\n      PortalContextManager.instance.destroyAll();\n      PortalContextManager.instance = null;\n    }\n  }\n\n  // ==========================================================================\n  // Public API - Portal Creation\n  // ==========================================================================\n\n  /**\n   * Creates a new portal context.\n   *\n   * @param sourceElement - The element where the portal is invoked\n   * @param options - Portal options\n   * @returns Created PortalContext\n   */\n  public createPortalContext(\n    sourceElement: Element,\n    options: PortalContextOptions = {}\n  ): PortalContext {\n    const { target, layer = 'modal', bridgeEvents = true, parentPortal = null } = options;\n\n    // Resolve portal root\n    const portalRoot = this.resolvePortalRoot(target);\n    if (!portalRoot) {\n      throw new Error('[PortalContextManager] Could not resolve portal root');\n    }\n\n    // Generate portal ID\n    const portalId = this.generatePortalId();\n\n    // Capture source context snapshot\n    const sourceContext = this.captureContextSnapshot(sourceElement);\n\n    // Calculate nesting depth\n    const nestingDepth = parentPortal ? parentPortal.nestingDepth + 1 : 0;\n\n    // Create portal context\n    const portalContext: PortalContext = {\n      portalRoot,\n      sourceContext,\n      layer: Z_INDEX_LAYERS[layer],\n      bridgeEvents,\n      nestingDepth,\n      parentPortal,\n      portalId,\n    };\n\n    // Store context and source element\n    this.portalContexts.set(portalId, portalContext);\n    this.sourceElements.set(portalId, sourceElement);\n\n    // Mark portal root with context attribute\n    portalRoot.setAttribute(PORTAL_CONTEXT_ATTR, portalId);\n\n    // Set up event bridging if enabled\n    if (bridgeEvents && !this.isSSR) {\n      this.setupEventBridging(portalId, portalRoot, sourceContext);\n    }\n\n    // Notify lifecycle callbacks\n    this.notifyLifecycle(portalId, portalContext);\n\n    if (this.config.debug) {\n      // eslint-disable-next-line no-console -- debug logging\n      console.debug('[PortalContextManager] Created portal:', portalId, portalContext);\n    }\n\n    return portalContext;\n  }\n\n  /**\n   * Destroys a portal context.\n   *\n   * @param portalId - ID of the portal to destroy\n   */\n  public destroyPortalContext(portalId: string): void {\n    const context = this.portalContexts.get(portalId);\n    if (!context) {\n      return;\n    }\n\n    // Remove portal root attribute\n    context.portalRoot.removeAttribute(PORTAL_CONTEXT_ATTR);\n\n    // Clean up event bridging\n    this.cleanupEventBridging(portalId);\n\n    // Remove from maps\n    this.portalContexts.delete(portalId);\n    this.sourceElements.delete(portalId);\n    this.lifecycleCallbacks.delete(portalId);\n    this.eventHandlers.delete(portalId);\n\n    if (this.config.debug) {\n      // eslint-disable-next-line no-console -- debug logging\n      console.debug('[PortalContextManager] Destroyed portal:', portalId);\n    }\n  }\n\n  /**\n   * Destroys all portal contexts.\n   */\n  public destroyAll(): void {\n    const portalIds = Array.from(this.portalContexts.keys());\n    portalIds.forEach((id) => this.destroyPortalContext(id));\n  }\n\n  // ==========================================================================\n  // Public API - Context Access\n  // ==========================================================================\n\n  /**\n   * Gets a portal context by ID.\n   *\n   * @param portalId - Portal ID\n   * @returns PortalContext or undefined\n   */\n  public getPortalContext(portalId: string): PortalContext | undefined {\n    return this.portalContexts.get(portalId);\n  }\n\n  /**\n   * Gets the portal context for an element (if it's inside a portal).\n   *\n   * @param element - Element to check\n   * @returns PortalContext or null\n   */\n  public getContextForElement(element: Element): PortalContext | null {\n    // Walk up the DOM to find a portal root\n    let current: Element | null = element;\n\n    while (current !== null) {\n      const portalId = current.getAttribute(PORTAL_CONTEXT_ATTR);\n      if (portalId !== null && portalId !== '') {\n        return this.portalContexts.get(portalId) ?? null;\n      }\n      current = current.parentElement;\n    }\n\n    return null;\n  }\n\n  /**\n   * Gets the source context for a portal.\n   *\n   * @param portalId - Portal ID\n   * @returns Source context snapshot or null\n   */\n  public getSourceContext(portalId: string): DOMContextSnapshot | null {\n    const context = this.portalContexts.get(portalId);\n    return context?.sourceContext ?? null;\n  }\n\n  /**\n   * Gets the source element for a portal.\n   *\n   * @param portalId - Portal ID\n   * @returns Source element or null\n   */\n  public getSourceElement(portalId: string): Element | null {\n    return this.sourceElements.get(portalId) ?? null;\n  }\n\n  /**\n   * Checks if an element is inside a portal.\n   *\n   * @param element - Element to check\n   * @returns Whether element is inside a portal\n   */\n  public isInPortal(element: Element): boolean {\n    return this.getContextForElement(element) !== null;\n  }\n\n  /**\n   * Gets the portal hierarchy for an element.\n   *\n   * @param element - Element to check\n   * @returns Array of portal contexts from innermost to outermost\n   */\n  public getPortalHierarchy(element: Element): PortalContext[] {\n    const hierarchy: PortalContext[] = [];\n    let context = this.getContextForElement(element);\n\n    while (context) {\n      hierarchy.push(context);\n      context = context.parentPortal;\n    }\n\n    return hierarchy;\n  }\n\n  // ==========================================================================\n  // Public API - Lifecycle & Events\n  // ==========================================================================\n\n  /**\n   * Registers a lifecycle callback for a portal.\n   *\n   * @param portalId - Portal ID\n   * @param callback - Lifecycle callback\n   * @returns Unregister function\n   */\n  public onLifecycle(portalId: string, callback: PortalLifecycleCallback): () => void {\n    let callbacks = this.lifecycleCallbacks.get(portalId);\n    if (!callbacks) {\n      callbacks = new Set();\n      this.lifecycleCallbacks.set(portalId, callbacks);\n    }\n    callbacks.add(callback);\n\n    return () => {\n      callbacks?.delete(callback);\n    };\n  }\n\n  /**\n   * Registers an event handler for bridged events.\n   *\n   * @param portalId - Portal ID\n   * @param handler - Event handler\n   * @returns Unregister function\n   */\n  public onBridgedEvent(portalId: string, handler: BridgedEventHandler): () => void {\n    let handlers = this.eventHandlers.get(portalId);\n    if (!handlers) {\n      handlers = new Set();\n      this.eventHandlers.set(portalId, handlers);\n    }\n    handlers.add(handler);\n\n    return () => {\n      handlers?.delete(handler);\n    };\n  }\n\n  /**\n   * Updates the source context snapshot for a portal.\n   *\n   * @param portalId - Portal ID\n   */\n  public refreshSourceContext(portalId: string): void {\n    const sourceElement = this.sourceElements.get(portalId);\n    const context = this.portalContexts.get(portalId);\n\n    if (sourceElement && context) {\n      const newSnapshot = this.captureContextSnapshot(sourceElement);\n      // Create new context with updated snapshot\n      const updatedContext: PortalContext = {\n        ...context,\n        sourceContext: newSnapshot,\n      };\n      this.portalContexts.set(portalId, updatedContext);\n    }\n  }\n\n  // ==========================================================================\n  // Private Methods\n  // ==========================================================================\n\n  /**\n   * Generates a unique portal ID.\n   */\n  private generatePortalId(): string {\n    return `portal-${++this.portalIdCounter}-${Date.now()}`;\n  }\n\n  /**\n   * Resolves the portal root element.\n   */\n  private resolvePortalRoot(target?: Element | string): Element | null {\n    if (this.isSSR) {\n      return null;\n    }\n\n    if (target instanceof Element) {\n      return target;\n    }\n\n    if (typeof target === 'string') {\n      return document.querySelector(target);\n    }\n\n    // Try to find or create default portal root\n    let root = document.getElementById(DEFAULT_PORTAL_ROOT_ID);\n    if (!root) {\n      root = document.createElement('div');\n      root.id = DEFAULT_PORTAL_ROOT_ID;\n      document.body.appendChild(root);\n    }\n\n    return root;\n  }\n\n  /**\n   * Captures a snapshot of the current DOM context.\n   */\n  private captureContextSnapshot(element: Element): DOMContextSnapshot {\n    const tracker = getDOMContextTracker();\n    const viewportTracker = getViewportTracker();\n\n    // Get ancestors\n    const ancestors: LayoutAncestor[] = tracker.getAncestry(element);\n\n    // Get viewport\n    const viewport: ViewportInfo = viewportTracker.getViewport();\n\n    // Find scroll container (simplified for snapshot)\n    const scrollContainer: ScrollContainer | null = null;\n    // Note: In a full implementation, we would get this from ScrollContainerRegistry\n\n    // Get z-index context (simplified)\n    const zIndex: ZIndexContext = {\n      zIndex: 0,\n      layer: 'base',\n      stackingContextRoot: null,\n      createsStackingContext: false,\n      orderInLayer: 0,\n      layerCount: 1,\n    };\n\n    return {\n      ancestors,\n      viewport,\n      scrollContainer,\n      zIndex,\n      timestamp: Date.now(),\n    };\n  }\n\n  /**\n   * Sets up event bridging for a portal.\n   */\n  private setupEventBridging(\n    portalId: string,\n    portalRoot: Element,\n    sourceContext: DOMContextSnapshot\n  ): void {\n    // List of events to bridge\n    const eventsTobridge = ['click', 'keydown', 'keyup', 'focus', 'blur'];\n\n    const bridgeHandler = (event: Event): void => {\n      const handlers = this.eventHandlers.get(portalId);\n      if (handlers) {\n        handlers.forEach((handler) => {\n          try {\n            handler(event, sourceContext);\n          } catch (error) {\n            if (this.config.debug) {\n              console.error('[PortalContextManager] Event bridge error:', error);\n            }\n          }\n        });\n      }\n    };\n\n    // Store the handler reference for cleanup\n    (portalRoot as Element & { __portalBridgeHandler?: (e: Event) => void }).__portalBridgeHandler =\n      bridgeHandler;\n\n    eventsTobridge.forEach((eventType) => {\n      portalRoot.addEventListener(eventType, bridgeHandler, { capture: true });\n    });\n  }\n\n  /**\n   * Cleans up event bridging for a portal.\n   */\n  private cleanupEventBridging(portalId: string): void {\n    const context = this.portalContexts.get(portalId);\n    if (!context) {\n      return;\n    }\n\n    const portalRoot = context.portalRoot as Element & {\n      __portalBridgeHandler?: (e: Event) => void;\n    };\n    const handler = portalRoot.__portalBridgeHandler;\n\n    if (handler) {\n      const eventsTobridge = ['click', 'keydown', 'keyup', 'focus', 'blur'];\n      eventsTobridge.forEach((eventType) => {\n        portalRoot.removeEventListener(eventType, handler, { capture: true });\n      });\n      delete portalRoot.__portalBridgeHandler;\n    }\n  }\n\n  /**\n   * Notifies lifecycle callbacks.\n   */\n  private notifyLifecycle(portalId: string, context: PortalContext): void {\n    const callbacks = this.lifecycleCallbacks.get(portalId);\n    if (callbacks) {\n      callbacks.forEach((callback) => {\n        try {\n          callback(context);\n        } catch (error) {\n          if (this.config.debug) {\n            console.error('[PortalContextManager] Lifecycle callback error:', error);\n          }\n        }\n      });\n    }\n  }\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Gets the portal context manager instance.\n */\nexport function getPortalContextManager(): PortalContextManager {\n  return PortalContextManager.getInstance();\n}\n\n/**\n * Creates a portal context from a source element.\n *\n * @param sourceElement - Source element\n * @param options - Portal options\n * @returns Created portal context\n */\nexport function createPortalContext(\n  sourceElement: Element,\n  options?: PortalContextOptions\n): PortalContext {\n  return getPortalContextManager().createPortalContext(sourceElement, options);\n}\n\n/**\n * Destroys a portal context.\n *\n * @param portalId - Portal ID to destroy\n */\nexport function destroyPortalContext(portalId: string): void {\n  getPortalContextManager().destroyPortalContext(portalId);\n}\n\n/**\n * Gets the portal context for an element.\n *\n * @param element - Element to check\n * @returns Portal context or null\n */\nexport function getPortalContextForElement(element: Element): PortalContext | null {\n  return getPortalContextManager().getContextForElement(element);\n}\n\n/**\n * Checks if an element is inside a portal.\n *\n * @param element - Element to check\n * @returns Whether inside a portal\n */\nexport function isInPortal(element: Element): boolean {\n  return getPortalContextManager().isInPortal(element);\n}\n\n/**\n * Gets the complete portal hierarchy for an element.\n *\n * @param element - Element to check\n * @returns Array of portal contexts\n */\nexport function getPortalHierarchy(element: Element): PortalContext[] {\n  return getPortalContextManager().getPortalHierarchy(element);\n}\n"],"names":["DEFAULT_PORTAL_ROOT_ID","PORTAL_CONTEXT_ATTR","PortalContextManager","config","DEFAULT_TRACKING_CONFIG","sourceElement","options","target","layer","bridgeEvents","parentPortal","portalRoot","portalId","sourceContext","nestingDepth","portalContext","Z_INDEX_LAYERS","context","id","element","current","hierarchy","callback","callbacks","handler","handlers","newSnapshot","updatedContext","root","tracker","getDOMContextTracker","viewportTracker","getViewportTracker","ancestors","viewport","eventsTobridge","bridgeHandler","event","error","eventType","getPortalContextManager","createPortalContext","destroyPortalContext","getPortalContextForElement","isInPortal","getPortalHierarchy"],"mappings":";;;AA4DA,MAAMA,IAAyB,eACzBC,IAAsB;AA6BrB,MAAMC,EAAqB;AAAA,EAChC,OAAe,WAAwC;AAAA;AAAA,EAGtC,qCAAiD,IAAA;AAAA;AAAA,EAGjD,qCAA2C,IAAA;AAAA;AAAA,EAG3C,yCAAoE,IAAA;AAAA;AAAA,EAGpE,oCAA2D,IAAA;AAAA;AAAA,EAG3D;AAAA;AAAA,EAGA;AAAA;AAAA,EAGT,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAKlB,YAAYC,IAAyC,IAAI;AAC/D,SAAK,SAAS,EAAE,GAAGC,GAAyB,GAAGD,EAAA,GAC/C,KAAK,QAAQ,OAAO,SAAW;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,YAAYA,GAA+D;AACvF,WAAAD,EAAqB,aAAa,IAAIA,EAAqBC,CAAM,GAC1DD,EAAqB;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,gBAAsB;AAClC,IAAIA,EAAqB,aACvBA,EAAqB,SAAS,WAAA,GAC9BA,EAAqB,WAAW;AAAA,EAEpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,oBACLG,GACAC,IAAgC,IACjB;AACf,UAAM,EAAE,QAAAC,GAAQ,OAAAC,IAAQ,SAAS,cAAAC,IAAe,IAAM,cAAAC,IAAe,SAASJ,GAGxEK,I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