@cngx/ui 0.1.0-rc.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -59
- package/action-button/README.md +170 -53
- package/breadcrumb/README.md +5 -6
- package/collection/README.md +1 -1
- package/command-palette/README.md +4 -3
- package/data-grid-accordion/README.md +1 -1
- package/empty-state/README.md +2 -3
- package/feedback/README.md +1 -1
- package/fesm2022/cngx-ui-a11y.mjs +13 -23
- package/fesm2022/cngx-ui-a11y.mjs.map +1 -1
- package/fesm2022/cngx-ui-accordion.mjs +44 -66
- package/fesm2022/cngx-ui-accordion.mjs.map +1 -1
- package/fesm2022/cngx-ui-action-button.mjs +213 -335
- package/fesm2022/cngx-ui-action-button.mjs.map +1 -1
- package/fesm2022/cngx-ui-breadcrumb.mjs +60 -80
- package/fesm2022/cngx-ui-breadcrumb.mjs.map +1 -1
- package/fesm2022/cngx-ui-chart-panel.mjs +18 -31
- package/fesm2022/cngx-ui-chart-panel.mjs.map +1 -1
- package/fesm2022/cngx-ui-collection.mjs +28 -44
- package/fesm2022/cngx-ui-collection.mjs.map +1 -1
- package/fesm2022/cngx-ui-command-palette.mjs +29 -51
- package/fesm2022/cngx-ui-command-palette.mjs.map +1 -1
- package/fesm2022/cngx-ui-context-menu.mjs +78 -83
- package/fesm2022/cngx-ui-context-menu.mjs.map +1 -1
- package/fesm2022/cngx-ui-data-grid-accordion.mjs +52 -74
- package/fesm2022/cngx-ui-data-grid-accordion.mjs.map +1 -1
- package/fesm2022/cngx-ui-empty-state.mjs +17 -44
- package/fesm2022/cngx-ui-empty-state.mjs.map +1 -1
- package/fesm2022/cngx-ui-feedback.mjs +589 -467
- package/fesm2022/cngx-ui-feedback.mjs.map +1 -1
- package/fesm2022/cngx-ui-layout.mjs +17 -13
- package/fesm2022/cngx-ui-layout.mjs.map +1 -1
- package/fesm2022/cngx-ui-mat-accordion.mjs +3 -5
- package/fesm2022/cngx-ui-mat-accordion.mjs.map +1 -1
- package/fesm2022/cngx-ui-mat-paginator.mjs +5 -9
- package/fesm2022/cngx-ui-mat-paginator.mjs.map +1 -1
- package/fesm2022/cngx-ui-mat-stepper.mjs +6 -9
- package/fesm2022/cngx-ui-mat-stepper.mjs.map +1 -1
- package/fesm2022/cngx-ui-mat-tabs.mjs +71 -68
- package/fesm2022/cngx-ui-mat-tabs.mjs.map +1 -1
- package/fesm2022/cngx-ui-nav-rail.mjs +440 -0
- package/fesm2022/cngx-ui-nav-rail.mjs.map +1 -0
- package/fesm2022/cngx-ui-overlay.mjs +9 -10
- package/fesm2022/cngx-ui-overlay.mjs.map +1 -1
- package/fesm2022/cngx-ui-paginator.mjs +149 -171
- package/fesm2022/cngx-ui-paginator.mjs.map +1 -1
- package/fesm2022/cngx-ui-sidenav.mjs +858 -721
- package/fesm2022/cngx-ui-sidenav.mjs.map +1 -1
- package/fesm2022/cngx-ui-skeleton.mjs +17 -19
- package/fesm2022/cngx-ui-skeleton.mjs.map +1 -1
- package/fesm2022/cngx-ui-speak.mjs +21 -74
- package/fesm2022/cngx-ui-speak.mjs.map +1 -1
- package/fesm2022/cngx-ui-stat-card.mjs +39 -62
- package/fesm2022/cngx-ui-stat-card.mjs.map +1 -1
- package/fesm2022/cngx-ui-stepper.mjs +207 -90
- package/fesm2022/cngx-ui-stepper.mjs.map +1 -1
- package/fesm2022/cngx-ui-tabs.mjs +71 -32
- package/fesm2022/cngx-ui-tabs.mjs.map +1 -1
- package/fesm2022/cngx-ui-timeline.mjs +21 -27
- package/fesm2022/cngx-ui-timeline.mjs.map +1 -1
- package/fesm2022/cngx-ui-toc.mjs +27 -40
- package/fesm2022/cngx-ui-toc.mjs.map +1 -1
- package/fesm2022/cngx-ui.mjs +5 -5
- package/fesm2022/cngx-ui.mjs.map +1 -1
- package/mat-tabs/README.md +28 -14
- package/mat-tabs/styles/mat-tabs.css +233 -258
- package/nav-rail/README.md +325 -0
- package/package.json +10 -5
- package/paginator/README.md +10 -0
- package/schematics/ng-add/index.js +7 -7
- package/schematics/ng-add/schema.json +5 -0
- package/sidenav/README.md +150 -55
- package/skeleton/README.md +1 -1
- package/speak/README.md +1 -2
- package/stepper/README.md +20 -5
- package/tabs/README.md +13 -0
- package/timeline/README.md +1 -1
- package/toc/README.md +1 -1
- package/types/cngx-ui-a11y.d.ts +20 -38
- package/types/cngx-ui-accordion.d.ts +45 -77
- package/types/cngx-ui-action-button.d.ts +113 -151
- package/types/cngx-ui-breadcrumb.d.ts +58 -94
- package/types/cngx-ui-chart-panel.d.ts +22 -40
- package/types/cngx-ui-collection.d.ts +30 -53
- package/types/cngx-ui-command-palette.d.ts +40 -64
- package/types/cngx-ui-context-menu.d.ts +67 -44
- package/types/cngx-ui-data-grid-accordion.d.ts +49 -77
- package/types/cngx-ui-empty-state.d.ts +18 -8
- package/types/cngx-ui-feedback.d.ts +264 -289
- package/types/cngx-ui-layout.d.ts +4 -12
- package/types/cngx-ui-mat-accordion.d.ts +2 -3
- package/types/cngx-ui-mat-paginator.d.ts +4 -10
- package/types/cngx-ui-mat-stepper.d.ts +5 -10
- package/types/cngx-ui-mat-tabs.d.ts +43 -69
- package/types/cngx-ui-nav-rail.d.ts +416 -0
- package/types/cngx-ui-overlay.d.ts +4 -13
- package/types/cngx-ui-paginator.d.ts +164 -154
- package/types/cngx-ui-sidenav.d.ts +557 -437
- package/types/cngx-ui-skeleton.d.ts +7 -13
- package/types/cngx-ui-speak.d.ts +40 -24
- package/types/cngx-ui-stat-card.d.ts +45 -36
- package/types/cngx-ui-stepper.d.ts +183 -62
- package/types/cngx-ui-tabs.d.ts +101 -27
- package/types/cngx-ui-timeline.d.ts +20 -48
- package/types/cngx-ui-toc.d.ts +30 -51
- package/types/cngx-ui.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cngx-ui-overlay.mjs","sources":["../../../projects/ui/overlay/overlay-ref.ts","../../../projects/ui/overlay/overlay.service.ts","../../../projects/ui/overlay/public-api.ts","../../../projects/ui/overlay/cngx-ui-overlay.ts"],"sourcesContent":["import { type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { signal, type Signal } from '@angular/core';\nimport { Subject, takeUntil } from 'rxjs';\n\n/**\n * Construction-time options for a {@link CngxOverlayRef}. Set by\n * {@link CngxOverlay.open}, not by consumers.\n *\n * @category ui/overlay\n */\nexport interface CngxOverlayRefConfig {\n /**\n * When `true`, neither Escape nor a backdrop click closes the overlay - the\n * only way out is a programmatic `close()`. Default `false`.\n */\n readonly disableClose?: boolean;\n /**\n * Element focus returns to when the overlay closes - captured at open time,\n * before the overlay steals focus. `null` skips restoration.\n */\n readonly restoreFocusTo?: HTMLElement | null;\n}\n\n/**\n * Typed wrapper around a CDK OverlayRef that exposes a close result stream.\n *\n * Closes on Escape and on a backdrop click (unless `disableClose`), restores\n * focus to the element that opened it, and surfaces its open state as a signal\n * beside the RxJS `afterClosed$`.\n *\n * @category ui/overlay\n * @docsKind primary\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay-ref.ts\n * @since 0.1.0\n * @relatedTo CngxOverlay, provideOverlay\n */\nexport class CngxOverlayRef<R = unknown> {\n private readonly _afterClosed = new Subject<R | undefined>();\n\n /** Emits once with the close result when the overlay is dismissed, then completes. */\n readonly afterClosed$ = this._afterClosed.asObservable();\n\n private readonly openState = signal(true);\n /**\n * `true` while the overlay is open, `false` once closed. The signal view of\n * the lifecycle beside {@link afterClosed$} - bind it in a template without\n * an `async` pipe.\n */\n readonly isOpen: Signal<boolean> = this.openState.asReadonly();\n\n private readonly restoreFocusTo: HTMLElement | null;\n\n constructor(\n private readonly cdkRef: CdkOverlayRef,\n config: CngxOverlayRefConfig = {},\n ) {\n this.restoreFocusTo = config.restoreFocusTo ?? null;\n\n if (!config.disableClose) {\n cdkRef\n .backdropClick()\n .pipe(takeUntil(this._afterClosed))\n .subscribe(() => this.close());\n cdkRef\n .keydownEvents()\n .pipe(takeUntil(this._afterClosed))\n .subscribe((event) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n this.close();\n }\n });\n }\n }\n\n /**\n * Closes the overlay, emitting `result` on `afterClosed$`, disposing the CDK\n * ref, and restoring focus. Idempotent - a second call (e.g. Escape after a\n * scope teardown already closed it) is a no-op.\n */\n close(result?: R): void {\n if (!this.openState()) {\n return;\n }\n this.openState.set(false);\n this._afterClosed.next(result);\n this._afterClosed.complete();\n this.cdkRef.dispose();\n this.restoreFocusTo?.focus();\n }\n}\n","import { DOCUMENT } from '@angular/common';\nimport {\n DestroyRef,\n Injectable,\n Injector,\n inject,\n makeEnvironmentProviders,\n type EnvironmentProviders,\n type Type,\n} from '@angular/core';\nimport { Overlay, OverlayConfig, type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { ComponentPortal } from '@angular/cdk/portal';\nimport { CngxOverlayRef } from './overlay-ref';\n\n/**\n * Config accepted by {@link CngxOverlay.open}. A partial of CDK's\n * {@link OverlayConfig} - every field is optional and falls back to the CDK\n * overlay default - plus `disableClose`, a cngx addition that turns off the\n * Escape / backdrop dismiss affordances.\n *\n * @category ui/overlay\n */\nexport type CngxOverlayConfig = Partial<OverlayConfig> & {\n /**\n * When `true`, Escape and backdrop clicks do not close the overlay; only a\n * programmatic `close()` does. Default `false`.\n */\n readonly disableClose?: boolean;\n};\n\n/**\n * Thin service over CDK Overlay that returns a typed CngxOverlayRef.\n *\n * Must be provided via `provideOverlay()` in application or component providers.\n * ```ts\n * // app.config.ts\n * provideOverlay()\n\n * // usage\n * const ref = overlayService.open(MyComponent, { hasBackdrop: true });\n * ref.afterClosed$.subscribe(result => console.log(result));\n* ```\n *\n * @category ui/overlay\n * @docsKind primary\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay.service.ts\n * @since 0.1.0\n * @relatedTo CngxOverlayRef, provideOverlay\n */\n@Injectable()\nexport class CngxOverlay {\n private readonly overlay = inject(Overlay);\n private readonly injector = inject(Injector);\n private readonly document = inject(DOCUMENT);\n // Held by the only capability the registry needs; the generic CngxOverlayRef\n // is invariant in R (its Subject leaks into the type), so a structural close\n // handle sidesteps that without an unknown-cast.\n private readonly openRefs = new Set<{ close(): void }>();\n\n constructor() {\n // The service is destroyed with its providing scope (component or\n // environment injector). Anything still open would otherwise leak a\n // detached overlay panel and its subscriptions - close them.\n inject(DestroyRef).onDestroy(() => {\n for (const ref of [...this.openRefs]) {\n ref.close();\n }\n });\n }\n\n /**\n * Opens `component` in a CDK overlay panel and returns a typed ref.\n *\n * Defaults to a centered, backdropped panel that closes on Escape or a\n * backdrop click; pass `disableClose` to opt out. Focus returns to the\n * element that was focused at open time. Merge `config` to override position\n * strategy, scroll strategy, or any other CDK `OverlayConfig` option.\n *\n * @param component Component class to attach as a portal.\n * @param config Overlay configuration overrides (CDK options + `disableClose`).\n */\n open<C, R = unknown>(component: Type<C>, config: CngxOverlayConfig = {}): CngxOverlayRef<R> {\n const { disableClose, ...cdkConfig } = config;\n const overlayConfig = new OverlayConfig({\n hasBackdrop: true,\n positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically(),\n ...cdkConfig,\n });\n\n const cdkRef: CdkOverlayRef = this.overlay.create(overlayConfig);\n // Capture the opener BEFORE attaching, so focus can return to it on close.\n const restoreFocusTo = this.document.activeElement as HTMLElement | null;\n const ngxRef = new CngxOverlayRef<R>(cdkRef, { disableClose, restoreFocusTo });\n\n this.openRefs.add(ngxRef);\n ngxRef.afterClosed$.subscribe({ complete: () => this.openRefs.delete(ngxRef) });\n\n const injector = Injector.create({\n parent: this.injector,\n providers: [{ provide: CngxOverlayRef, useValue: ngxRef }],\n });\n\n const portal = new ComponentPortal(component, null, injector);\n cdkRef.attach(portal);\n return ngxRef;\n }\n}\n\n/**\n * Provides `CngxOverlay` as an environment-scoped service.\n *\n * @category ui/overlay\n */\nexport function provideOverlay(): EnvironmentProviders {\n return makeEnvironmentProviders([CngxOverlay]);\n}\n","/**\n * Public API Surface of @cngx/ui/overlay\n * @module @cngx/ui/overlay\n */\n\nexport { CngxOverlay, provideOverlay, type CngxOverlayConfig } from './overlay.service';\nexport { CngxOverlayRef } from './overlay-ref';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAuBA;;;;;;;;;;;;;AAaG;MACU,cAAc,CAAA;AAiBN,IAAA,MAAA;AAhBF,IAAA,YAAY,GAAG,IAAI,OAAO,EAAiB;;AAGnD,IAAA,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;AAEvC,IAAA,SAAS,GAAG,MAAM,CAAC,IAAI,gFAAC;AACzC;;;;AAIG;AACM,IAAA,MAAM,GAAoB,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;AAE7C,IAAA,cAAc;IAE/B,WAAA,CACmB,MAAqB,EACtC,MAAA,GAA+B,EAAE,EAAA;QADhB,IAAA,CAAA,MAAM,GAAN,MAAM;QAGvB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI;AAEnD,QAAA,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YACxB;AACG,iBAAA,aAAa;AACb,iBAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;iBACjC,SAAS,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC;AACG,iBAAA,aAAa;AACb,iBAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;AACjC,iBAAA,SAAS,CAAC,CAAC,KAAK,KAAI;AACnB,gBAAA,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;oBAC1B,KAAK,CAAC,cAAc,EAAE;oBACtB,IAAI,CAAC,KAAK,EAAE;gBACd;AACF,YAAA,CAAC,CAAC;QACN;IACF;AAEA;;;;AAIG;AACH,IAAA,KAAK,CAAC,MAAU,EAAA;AACd,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE;YACrB;QACF;AACA,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MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAmC;AACxE,QAAA,MAAM,MAAM,GAAG,IAAI,cAAc,CAAI,MAAM,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAE9E,QAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;QACzB,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AAE/E,QAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;YAC/B,MAAM,EAAE,IAAI,CAAC,QAAQ;YACrB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC3D,SAAA,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC;AAC7D,QAAA,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;AACrB,QAAA,OAAO,MAAM;IACf;uGAvDW,WAAW,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;2GAAX,WAAW,EAAA,CAAA;;2FAAX,WAAW,EAAA,UAAA,EAAA,CAAA;kBADvB;;AA2DD;;;;AAIG;SACa,cAAc,GAAA;AAC5B,IAAA,OAAO,wBAAwB,CAAC,CAAC,WAAW,CAAC,CAAC;AAChD;;ACpHA;;;AAGG;;ACHH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"cngx-ui-overlay.mjs","sources":["../../../projects/ui/overlay/overlay-ref.ts","../../../projects/ui/overlay/overlay.service.ts","../../../projects/ui/overlay/public-api.ts","../../../projects/ui/overlay/cngx-ui-overlay.ts"],"sourcesContent":["import { type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { signal, type Signal } from '@angular/core';\nimport { Subject, takeUntil } from 'rxjs';\n\n/**\n * Construction-time options for a {@link CngxOverlayRef}. Set by\n * {@link CngxOverlay.open}, not by consumers.\n */\nexport interface CngxOverlayRefConfig {\n /**\n * When `true`, neither Escape nor a backdrop click closes the overlay - the\n * only way out is a programmatic `close()`. Default `false`.\n */\n readonly disableClose?: boolean;\n /**\n * Element focus returns to when the overlay closes - captured at open time,\n * before the overlay steals focus. `null` skips restoration.\n */\n readonly restoreFocusTo?: HTMLElement | null;\n}\n\n/**\n * Typed wrapper around a CDK OverlayRef that exposes a close result stream.\n *\n * Closes on Escape and on a backdrop click (unless `disableClose`), restores\n * focus to the element that opened it, and surfaces its open state as a signal\n * beside the RxJS `afterClosed$`.\n *\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay-ref.ts\n * @since 0.3.0\n * @relatedTo CngxOverlay, provideOverlay\n */\nexport class CngxOverlayRef<R = unknown> {\n private readonly _afterClosed = new Subject<R | undefined>();\n\n /** Emits once with the close result when the overlay is dismissed, then completes. */\n readonly afterClosed$ = this._afterClosed.asObservable();\n\n private readonly openState = signal(true);\n /**\n * `true` while the overlay is open, `false` once closed. The signal view of\n * the lifecycle beside {@link afterClosed$} - bind it in a template without\n * an `async` pipe.\n */\n readonly isOpen: Signal<boolean> = this.openState.asReadonly();\n\n private readonly restoreFocusTo: HTMLElement | null;\n\n constructor(\n private readonly cdkRef: CdkOverlayRef,\n config: CngxOverlayRefConfig = {},\n ) {\n this.restoreFocusTo = config.restoreFocusTo ?? null;\n\n if (!config.disableClose) {\n cdkRef\n .backdropClick()\n .pipe(takeUntil(this._afterClosed))\n .subscribe(() => this.close());\n cdkRef\n .keydownEvents()\n .pipe(takeUntil(this._afterClosed))\n .subscribe((event) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n this.close();\n }\n });\n }\n }\n\n /**\n * Closes the overlay, emitting `result` on `afterClosed$`, disposing the CDK\n * ref, and restoring focus. Idempotent - a second call (e.g. Escape after a\n * scope teardown already closed it) is a no-op.\n */\n close(result?: R): void {\n if (!this.openState()) {\n return;\n }\n this.openState.set(false);\n this._afterClosed.next(result);\n this._afterClosed.complete();\n this.cdkRef.dispose();\n this.restoreFocusTo?.focus();\n }\n}\n","import { DOCUMENT } from '@angular/common';\nimport {\n DestroyRef,\n Injectable,\n Injector,\n inject,\n makeEnvironmentProviders,\n type EnvironmentProviders,\n type Type,\n} from '@angular/core';\nimport { Overlay, OverlayConfig, type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { ComponentPortal } from '@angular/cdk/portal';\nimport { injectDirection } from '@cngx/core';\nimport { CngxOverlayRef } from './overlay-ref';\n\n/**\n * Config accepted by {@link CngxOverlay.open}. A partial of CDK's\n * {@link OverlayConfig} - every field is optional and falls back to the CDK\n * overlay default - plus `disableClose`, a cngx addition that turns off the\n * Escape / backdrop dismiss affordances.\n */\nexport type CngxOverlayConfig = Partial<OverlayConfig> & {\n /**\n * When `true`, Escape and backdrop clicks do not close the overlay; only a\n * programmatic `close()` does. Default `false`.\n */\n readonly disableClose?: boolean;\n};\n\n/**\n * Thin service over CDK Overlay that returns a typed CngxOverlayRef.\n *\n * Must be provided via `provideOverlay()` in application or component providers.\n * ```ts\n * // app.config.ts\n * provideOverlay()\n\n * // usage\n * const ref = overlayService.open(MyComponent, { hasBackdrop: true });\n * ref.afterClosed$.subscribe(result => console.log(result));\n* ```\n *\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay.service.ts\n * @since 0.3.0\n * @relatedTo CngxOverlayRef, provideOverlay\n */\n@Injectable()\nexport class CngxOverlay {\n private readonly overlay = inject(Overlay);\n private readonly injector = inject(Injector);\n private readonly document = inject(DOCUMENT);\n // The CDK Directionality reads <html dir> once; the cngx direction follows\n // a runtime pack switch, so every pane opens in the current one.\n private readonly direction = injectDirection();\n // Held by the only capability the registry needs; the generic CngxOverlayRef\n // is invariant in R (its Subject leaks into the type), so a structural close\n // handle sidesteps that without an unknown-cast.\n private readonly openRefs = new Set<{ close(): void }>();\n\n constructor() {\n // The service is destroyed with its providing scope (component or\n // environment injector). Anything still open would otherwise leak a\n // detached overlay panel and its subscriptions - close them.\n inject(DestroyRef).onDestroy(() => {\n for (const ref of [...this.openRefs]) {\n ref.close();\n }\n });\n }\n\n /**\n * Opens `component` in a CDK overlay panel and returns a typed ref.\n *\n * Defaults to a centered, backdropped panel that closes on Escape or a\n * backdrop click; pass `disableClose` to opt out. Focus returns to the\n * element that was focused at open time. Merge `config` to override position\n * strategy, scroll strategy, or any other CDK `OverlayConfig` option.\n *\n * @param component Component class to attach as a portal.\n * @param config Overlay configuration overrides (CDK options + `disableClose`).\n */\n open<C, R = unknown>(component: Type<C>, config: CngxOverlayConfig = {}): CngxOverlayRef<R> {\n const { disableClose, ...cdkConfig } = config;\n const overlayConfig = new OverlayConfig({\n hasBackdrop: true,\n direction: this.direction(),\n positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically(),\n ...cdkConfig,\n });\n\n const cdkRef: CdkOverlayRef = this.overlay.create(overlayConfig);\n // Capture the opener BEFORE attaching, so focus can return to it on close.\n const restoreFocusTo = this.document.activeElement as HTMLElement | null;\n const ngxRef = new CngxOverlayRef<R>(cdkRef, { disableClose, restoreFocusTo });\n\n this.openRefs.add(ngxRef);\n ngxRef.afterClosed$.subscribe({ complete: () => this.openRefs.delete(ngxRef) });\n\n const injector = Injector.create({\n parent: this.injector,\n providers: [{ provide: CngxOverlayRef, useValue: ngxRef }],\n });\n\n const portal = new ComponentPortal(component, null, injector);\n cdkRef.attach(portal);\n return ngxRef;\n }\n}\n\n/**\n * Provides `CngxOverlay` as an environment-scoped service.\n */\nexport function provideOverlay(): EnvironmentProviders {\n return makeEnvironmentProviders([CngxOverlay]);\n}\n","/**\n * Public API Surface of `@cngx/ui/overlay`\n * @module `@cngx/ui/overlay`\n */\n\nexport { CngxOverlay, provideOverlay, type CngxOverlayConfig } from './overlay.service';\nexport { CngxOverlayRef, type CngxOverlayRefConfig } from './overlay-ref';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;AAqBA;;;;;;;;;;;AAWG;MACU,cAAc,CAAA;AAiBN,IAAA,MAAA;AAhBF,IAAA,YAAY,GAAG,IAAI,OAAO,EAAiB;;AAGnD,IAAA,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;AAEvC,IAAA,SAAS,GAAG,MAAM,CAAC,IAAI,gFAAC;AACzC;;;;AAIG;AACM,IAAA,MAAM,GAAoB,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;AAE7C,IAAA,cAAc;IAE/B,WAAA,CACmB,MAAqB,EACtC,MAAA,GAA+B,EAAE,EAAA;QADhB,IAAA,CAAA,MAAM,GAAN,MAAM;QAGvB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI;AAEnD,QAAA,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YACxB;AACG,iBAAA,aAAa;AACb,iBAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;iBACjC,SAAS,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC;AACG,iBAAA,aAAa;AACb,iBAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;AACjC,iBAAA,SAAS,CAAC,CAAC,KAAK,KAAI;AACnB,gBAAA,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;oBAC1B,KAAK,CAAC,cAAc,EAAE;oBACtB,IAAI,CAAC,KAAK,EAAE;gBACd;AACF,YAAA,CAAC,CAAC;QACN;IACF;AAEA;;;;AAIG;AACH,IAAA,KAAK,CAAC,MAAU,EAAA;AACd,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE;YACrB;QACF;AACA,QAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;AACzB,QAAA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