{"version":3,"file":"qualcomm-ui-angular-core-presence.mjs","sources":["../../src/presence/core-presence.directive.ts","../../src/presence/presence-context.service.ts","../../src/presence/render-strategy-context.service.ts","../../src/presence/use-presence-renderer.ts","../../src/presence/qualcomm-ui-angular-core-presence.ts"],"sourcesContent":["// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.\n// SPDX-License-Identifier: BSD-3-Clause-Clear\n\nimport {booleanAttribute, Directive, input, output} from \"@angular/core\"\n\nimport type {SignalifyInput} from \"@qualcomm-ui/angular-core/signals\"\nimport type {PresenceApiProps} from \"@qualcomm-ui/core/presence\"\nimport type {Booleanish} from \"@qualcomm-ui/utils/coercion\"\n\n@Directive()\nexport class CorePresenceDirective implements SignalifyInput<PresenceApiProps> {\n  /**\n   * Whether to synchronize the present change immediately or defer it to the next\n   * frame.\n   *\n   * @default false\n   */\n  readonly immediate = input<boolean | undefined, Booleanish>(undefined, {\n    transform: booleanAttribute,\n  })\n\n  /**\n   * When true, the component will not be rendered in the DOM until it becomes\n   * visible or active.\n   *\n   * @default false\n   */\n  readonly lazyMount = input<boolean | undefined, Booleanish>(undefined, {\n    transform: booleanAttribute,\n  })\n\n  /**\n   * The controlled presence of the node.\n   */\n  readonly present = input<boolean | undefined>(undefined)\n\n  /**\n   * Whether to allow the initial presence animation.\n   *\n   * @default false\n   */\n  readonly skipAnimationOnMount = input<boolean | undefined, Booleanish>(\n    undefined,\n    {transform: booleanAttribute},\n  )\n\n  /**\n   * When true, the component will be completely removed from the DOM when it\n   * becomes inactive or hidden, rather than just being hidden with CSS.\n   *\n   * @default false\n   */\n  readonly unmountOnExit = input<boolean | undefined, Booleanish>(undefined, {\n    transform: booleanAttribute,\n  })\n\n  /**\n   * Function called when the animation ends in the closed state\n   */\n  exitCompleted = output<void>()\n}\n","// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.\n// SPDX-License-Identifier: BSD-3-Clause-Clear\n\nimport {\n  computed,\n  Injectable,\n  type Provider,\n  signal,\n  type Signal,\n} from \"@angular/core\"\n\nimport type {PresenceApi} from \"@qualcomm-ui/core/presence\"\n\n@Injectable()\nexport class PresenceContextService {\n  readonly initialized = signal(false)\n\n  protected get context() {\n    if (!this._context) {\n      throw new Error(\"context not initialized\")\n    }\n    return this._context\n  }\n  private _context: Signal<PresenceApi> | undefined\n\n  init(computedApi: Signal<PresenceApi>): void {\n    if (this._context) {\n      throw new Error(\"context already initialized\")\n    }\n    this._context = computedApi\n    this.initialized.set(true)\n  }\n\n  setNode(node: HTMLElement | null) {\n    this.context().setNode(node)\n  }\n\n  immediatePresent: boolean | undefined\n\n  private _wasEverPresent: boolean = false\n\n  readonly wasEverPresent = computed<boolean>(() => {\n    if (this.context().present) {\n      this._wasEverPresent = true\n    }\n    return this._wasEverPresent\n  })\n\n  readonly unmounted = computed<boolean | undefined>(() => {\n    const lazyMount = this.context().lazyMount\n    const present = this.context().present\n    const unmountOnExit = this.context().unmountOnExit\n    const wasEverPresent = this.wasEverPresent()\n\n    return (\n      (!present && !wasEverPresent && lazyMount) ||\n      (unmountOnExit && !present && wasEverPresent)\n    )\n  })\n\n  readonly getPresenceBindings = computed(() => {\n    return {\n      \"data-state\":\n        this.context().skip && this.context().skipAnimationOnMount\n          ? undefined\n          : this.immediatePresent\n            ? \"open\"\n            : \"closed\",\n      hidden: !this.context().present,\n    }\n  })\n}\n\nexport function providePresenceContext(): Provider[] {\n  return [PresenceContextService]\n}\n","// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.\n// SPDX-License-Identifier: BSD-3-Clause-Clear\n\nimport {Injectable} from \"@angular/core\"\n\nimport {\n  type ApiContext,\n  BaseApiContextService,\n  createApiContext,\n} from \"@qualcomm-ui/angular-core/machine\"\nimport type {RenderStrategyApi} from \"@qualcomm-ui/core/presence\"\n\n@Injectable()\nexport class RenderStrategyContextService extends BaseApiContextService<RenderStrategyApi> {}\n\nexport const [\n  RENDER_STRATEGY_CONTEXT,\n  useRenderStrategyContext,\n  provideRenderStrategyContext,\n]: ApiContext<RenderStrategyApi> = createApiContext<RenderStrategyApi>(\n  \"RenderStrategyContext\",\n  RenderStrategyContextService,\n)\n","// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.\n// SPDX-License-Identifier: BSD-3-Clause-Clear\n\nimport {\n  effect,\n  type EffectRef,\n  ElementRef,\n  inject,\n  type InjectOptions,\n  Renderer2,\n} from \"@angular/core\"\n\nimport {PresenceContextService} from \"./presence-context.service\"\n\nexport interface UsePresenceRendererOptions {\n  /**\n   * Element to manage. Defaults to injected ElementRef\n   */\n  elementRef?: ElementRef\n\n  /**\n   * Injection options for PresenceContextService\n   */\n  injectOptions?: InjectOptions\n}\n\n/**\n * Removes the host element from the DOM when the presence context is unmounted,\n * and re-appends it when remounted. Useful for components that need to preserve\n * their lifecycle while being hidden from the DOM tree.\n *\n * @returns Effect reference that can be destroyed manually if needed\n */\nexport function usePresenceRenderer(\n  options: UsePresenceRendererOptions = {},\n): EffectRef {\n  const presenceContext = inject(\n    PresenceContextService,\n    options.injectOptions ?? {},\n  )\n  const elementRef = options.elementRef || inject(ElementRef)\n  const renderer = inject(Renderer2)\n\n  let parentNode: Node | null = null\n\n  return effect(() => {\n    presenceContext?.initialized()\n    const unmounted = presenceContext?.unmounted()\n    const element = elementRef.nativeElement\n\n    if (unmounted) {\n      parentNode = element.parentNode\n      renderer.removeChild(parentNode, element)\n    } else if (parentNode) {\n      renderer.appendChild(parentNode, element)\n    }\n  })\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA;AACA;MASa,qBAAqB,CAAA;AAChC;;;;;AAKG;IACM,SAAS,GAAG,KAAK,CAAkC,SAAS,iFACnE,SAAS,EAAE,gBAAgB,EAAA,CAC3B;AAEF;;;;;AAKG;IACM,SAAS,GAAG,KAAK,CAAkC,SAAS,iFACnE,SAAS,EAAE,gBAAgB,EAAA,CAC3B;AAEF;;AAEG;AACM,IAAA,OAAO,GAAG,KAAK,CA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