@radix-ng/primitives 1.0.0-beta.1 → 1.0.0-beta.3

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.
Files changed (107) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +76 -6
  3. package/fesm2022/radix-ng-primitives-accordion.mjs +2 -2
  4. package/fesm2022/radix-ng-primitives-accordion.mjs.map +1 -1
  5. package/fesm2022/radix-ng-primitives-alert-dialog.mjs +30 -24
  6. package/fesm2022/radix-ng-primitives-alert-dialog.mjs.map +1 -1
  7. package/fesm2022/radix-ng-primitives-autocomplete.mjs +1786 -0
  8. package/fesm2022/radix-ng-primitives-autocomplete.mjs.map +1 -0
  9. package/fesm2022/radix-ng-primitives-calendar.mjs +14 -1
  10. package/fesm2022/radix-ng-primitives-calendar.mjs.map +1 -1
  11. package/fesm2022/radix-ng-primitives-checkbox.mjs +2 -2
  12. package/fesm2022/radix-ng-primitives-checkbox.mjs.map +1 -1
  13. package/fesm2022/radix-ng-primitives-collapsible.mjs +1 -1
  14. package/fesm2022/radix-ng-primitives-collapsible.mjs.map +1 -1
  15. package/fesm2022/radix-ng-primitives-combobox.mjs +1983 -0
  16. package/fesm2022/radix-ng-primitives-combobox.mjs.map +1 -0
  17. package/fesm2022/radix-ng-primitives-context-menu.mjs +1 -1
  18. package/fesm2022/radix-ng-primitives-context-menu.mjs.map +1 -1
  19. package/fesm2022/radix-ng-primitives-core.mjs +480 -469
  20. package/fesm2022/radix-ng-primitives-core.mjs.map +1 -1
  21. package/fesm2022/radix-ng-primitives-cropper.mjs +1 -1
  22. package/fesm2022/radix-ng-primitives-cropper.mjs.map +1 -1
  23. package/fesm2022/radix-ng-primitives-date-field.mjs +11 -0
  24. package/fesm2022/radix-ng-primitives-date-field.mjs.map +1 -1
  25. package/fesm2022/radix-ng-primitives-dialog.mjs +44 -46
  26. package/fesm2022/radix-ng-primitives-dialog.mjs.map +1 -1
  27. package/fesm2022/radix-ng-primitives-drawer.mjs +154 -64
  28. package/fesm2022/radix-ng-primitives-drawer.mjs.map +1 -1
  29. package/fesm2022/radix-ng-primitives-editable.mjs +1 -1
  30. package/fesm2022/radix-ng-primitives-editable.mjs.map +1 -1
  31. package/fesm2022/radix-ng-primitives-field.mjs +86 -6
  32. package/fesm2022/radix-ng-primitives-field.mjs.map +1 -1
  33. package/fesm2022/radix-ng-primitives-fieldset.mjs +1 -1
  34. package/fesm2022/radix-ng-primitives-fieldset.mjs.map +1 -1
  35. package/fesm2022/radix-ng-primitives-focus-scope.mjs +1 -1
  36. package/fesm2022/radix-ng-primitives-focus-scope.mjs.map +1 -1
  37. package/fesm2022/radix-ng-primitives-form.mjs +207 -0
  38. package/fesm2022/radix-ng-primitives-form.mjs.map +1 -0
  39. package/fesm2022/radix-ng-primitives-input.mjs +85 -4
  40. package/fesm2022/radix-ng-primitives-input.mjs.map +1 -1
  41. package/fesm2022/radix-ng-primitives-menu.mjs +44 -24
  42. package/fesm2022/radix-ng-primitives-menu.mjs.map +1 -1
  43. package/fesm2022/radix-ng-primitives-menubar.mjs +1 -1
  44. package/fesm2022/radix-ng-primitives-menubar.mjs.map +1 -1
  45. package/fesm2022/radix-ng-primitives-meter.mjs +1 -1
  46. package/fesm2022/radix-ng-primitives-meter.mjs.map +1 -1
  47. package/fesm2022/radix-ng-primitives-navigation-menu.mjs +39 -55
  48. package/fesm2022/radix-ng-primitives-navigation-menu.mjs.map +1 -1
  49. package/fesm2022/radix-ng-primitives-number-field.mjs +2 -2
  50. package/fesm2022/radix-ng-primitives-number-field.mjs.map +1 -1
  51. package/fesm2022/radix-ng-primitives-popover.mjs +36 -51
  52. package/fesm2022/radix-ng-primitives-popover.mjs.map +1 -1
  53. package/fesm2022/radix-ng-primitives-popper.mjs +12 -6
  54. package/fesm2022/radix-ng-primitives-popper.mjs.map +1 -1
  55. package/fesm2022/radix-ng-primitives-portal.mjs +107 -17
  56. package/fesm2022/radix-ng-primitives-portal.mjs.map +1 -1
  57. package/fesm2022/radix-ng-primitives-presence.mjs +262 -79
  58. package/fesm2022/radix-ng-primitives-presence.mjs.map +1 -1
  59. package/fesm2022/radix-ng-primitives-preview-card.mjs +37 -51
  60. package/fesm2022/radix-ng-primitives-preview-card.mjs.map +1 -1
  61. package/fesm2022/radix-ng-primitives-progress.mjs +1 -1
  62. package/fesm2022/radix-ng-primitives-progress.mjs.map +1 -1
  63. package/fesm2022/radix-ng-primitives-roving-focus.mjs +1 -1
  64. package/fesm2022/radix-ng-primitives-roving-focus.mjs.map +1 -1
  65. package/fesm2022/radix-ng-primitives-scroll-area.mjs +3 -3
  66. package/fesm2022/radix-ng-primitives-scroll-area.mjs.map +1 -1
  67. package/fesm2022/radix-ng-primitives-select.mjs +469 -258
  68. package/fesm2022/radix-ng-primitives-select.mjs.map +1 -1
  69. package/fesm2022/radix-ng-primitives-slider.mjs +1 -1
  70. package/fesm2022/radix-ng-primitives-slider.mjs.map +1 -1
  71. package/fesm2022/radix-ng-primitives-switch.mjs +3 -2
  72. package/fesm2022/radix-ng-primitives-switch.mjs.map +1 -1
  73. package/fesm2022/radix-ng-primitives-tabs.mjs +1 -1
  74. package/fesm2022/radix-ng-primitives-tabs.mjs.map +1 -1
  75. package/fesm2022/radix-ng-primitives-time-field.mjs +27 -3
  76. package/fesm2022/radix-ng-primitives-time-field.mjs.map +1 -1
  77. package/fesm2022/radix-ng-primitives-toast.mjs +1 -1
  78. package/fesm2022/radix-ng-primitives-toast.mjs.map +1 -1
  79. package/fesm2022/radix-ng-primitives-toggle-group.mjs +1 -1
  80. package/fesm2022/radix-ng-primitives-toggle-group.mjs.map +1 -1
  81. package/fesm2022/radix-ng-primitives-toolbar.mjs +2 -2
  82. package/fesm2022/radix-ng-primitives-toolbar.mjs.map +1 -1
  83. package/fesm2022/radix-ng-primitives-tooltip.mjs +39 -42
  84. package/fesm2022/radix-ng-primitives-tooltip.mjs.map +1 -1
  85. package/package.json +13 -1
  86. package/schematics/ng-add/index.js +57 -0
  87. package/schematics/ng-add/index.js.map +1 -1
  88. package/schematics/ng-add/schema.d.ts +1 -0
  89. package/schematics/ng-add/schema.json +6 -0
  90. package/types/radix-ng-primitives-alert-dialog.d.ts +17 -11
  91. package/types/radix-ng-primitives-autocomplete.d.ts +596 -0
  92. package/types/radix-ng-primitives-combobox.d.ts +1310 -0
  93. package/types/radix-ng-primitives-core.d.ts +148 -56
  94. package/types/radix-ng-primitives-dialog.d.ts +32 -25
  95. package/types/radix-ng-primitives-drawer.d.ts +49 -22
  96. package/types/radix-ng-primitives-field.d.ts +71 -2
  97. package/types/radix-ng-primitives-form.d.ts +124 -0
  98. package/types/radix-ng-primitives-input.d.ts +75 -5
  99. package/types/radix-ng-primitives-menu.d.ts +19 -10
  100. package/types/radix-ng-primitives-navigation-menu.d.ts +24 -26
  101. package/types/radix-ng-primitives-popover.d.ts +23 -23
  102. package/types/radix-ng-primitives-popper.d.ts +7 -1
  103. package/types/radix-ng-primitives-portal.d.ts +53 -8
  104. package/types/radix-ng-primitives-presence.d.ts +98 -17
  105. package/types/radix-ng-primitives-preview-card.d.ts +24 -23
  106. package/types/radix-ng-primitives-select.d.ts +294 -137
  107. package/types/radix-ng-primitives-tooltip.d.ts +26 -19
@@ -1,19 +1,8 @@
1
- import { isPlatformBrowser } from '@angular/common';
2
1
  import * as i0 from '@angular/core';
3
- import { InjectionToken, inject, ViewContainerRef, TemplateRef, Injector, PLATFORM_ID, effect, afterNextRender, DestroyRef, Directive } from '@angular/core';
2
+ import { effect, afterNextRender, InjectionToken, inject, ViewContainerRef, TemplateRef, Injector, PLATFORM_ID, DestroyRef, Directive } from '@angular/core';
3
+ import { getMaxTransitionDuration } from '@radix-ng/primitives/core';
4
+ import { isPlatformBrowser } from '@angular/common';
4
5
 
5
- const RDX_PRESENCE_CONTEXT = new InjectionToken('RdxPresenceContext');
6
- /**
7
- * Factory provider helper.
8
- * In your parent component/directive you can write:
9
- *
10
- * providers: [
11
- * provideRdxPresenceContext(() => ({ present: myBooleanSignal }))
12
- * ]
13
- */
14
- function provideRdxPresenceContext(contextFactory) {
15
- return { provide: RDX_PRESENCE_CONTEXT, useFactory: contextFactory };
16
- }
17
6
  /**
18
7
  * State machine mirroring `@radix-ui/react-presence`.
19
8
  *
@@ -28,31 +17,59 @@ const MACHINE = {
28
17
  unmounted: { MOUNT: 'mounted' }
29
18
  };
30
19
  /**
31
- * Headless structural directive that conditionally renders its template based on a reactive
32
- * `present` signal supplied through {@link RDX_PRESENCE_CONTEXT}.
20
+ * Grace period (ms) added to the longest declared exit duration before the safety-net timer
21
+ * force-completes the exit. Only matters when a `finished` promise never settles (the engine
22
+ * under-reports `getAnimations`, the animation is replaced without a cancel, reduced motion, …).
23
+ * Mirrors `TRANSITION_FALLBACK_BUFFER` in `use-transition-status.ts`.
24
+ */
25
+ const EXIT_FALLBACK_BUFFER = 50;
26
+ /**
27
+ * Reusable presence state machine extracted from `RdxPresenceDirective`. It keeps content mounted
28
+ * while a CSS exit animation runs anywhere inside the template — a `@keyframes` **or** a
29
+ * `transition` (`data-ending-style`), on a watched root **or any of its descendants** — and unmounts
30
+ * only once every exit animation started by the close has finished. With no exit animation it
31
+ * unmounts immediately. For a single watched node and a root-level keyframe this reduces exactly to
32
+ * the original `RdxPresenceDirective` behavior.
33
33
  *
34
- * Unlike a plain `*ngIf`, it keeps the content mounted while a CSS exit animation
35
- * (`@keyframes` applied for the closed state) is running, and unmounts it only once that
36
- * animation finishes. If the content has no exit animation, it unmounts immediately.
34
+ * Detection (ADR 0011) uses the Web Animations API: when `present()` flips `false` we snapshot a
35
+ * close timestamp, and after the next render collect `node.getAnimations({ subtree: true })`, keeping
36
+ * only animations that are running/pending and were *started by* the close (`startTime` null or
37
+ * `>= closeTimestamp`). The view stays mounted until all of their `finished` promises settle, bounded
38
+ * by a duration-based safety net. The legacy root-level computed-`animationName` check and the
39
+ * `animationstart`/`animationend` listeners are kept as an additional acceptor — they drive the
40
+ * zoneless jsdom suites (where `getAnimations` is absent) and cost nothing in a real browser.
37
41
  */
38
- class RdxPresenceDirective {
39
- constructor() {
40
- this.context = inject(RDX_PRESENCE_CONTEXT);
41
- this.viewContainerRef = inject(ViewContainerRef);
42
- this.templateRef = inject((TemplateRef));
43
- this.injector = inject(Injector);
44
- this.isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
45
- this.viewRef = null;
46
- this.node = null;
42
+ class PresenceMachine {
43
+ constructor(host) {
44
+ this.host = host;
45
+ /** Root nodes currently watched for exit animations (set on mount). */
46
+ this.nodes = [];
47
+ /** Last-seen computed `animationName` per node, used to detect a *fresh* root exit animation. */
48
+ this.prevAnimationNames = new WeakMap();
49
+ /** Root nodes whose exit animation the event path is still waiting on (jsdom / root-keyframe). */
50
+ this.pendingExits = new Set();
47
51
  this.removeListeners = null;
48
- this.prevAnimationName = 'none';
49
- this.prevPresent = this.context.present();
52
+ /**
53
+ * Timeline time captured the moment `present` flipped `false`, on the same clock as
54
+ * `Animation.startTime`. Animations started at or after it are the exit animations.
55
+ */
56
+ this.closeTimestamp = 0;
57
+ /**
58
+ * Monotonic counter bumped on every mount/unmount transition. A suspended exit captures it and
59
+ * its `finished`/safety-net resolution is ignored if it changed in the meantime (re-open or a
60
+ * second close), so a stale promise can never tear down a freshly-reopened view.
61
+ */
62
+ this.exitVersion = 0;
63
+ /** True while a WAAPI `finished`-promise wait owns completion; gates the event path off. */
64
+ this.waapiPending = false;
65
+ this.safetyTimer = null;
66
+ this.prevPresent = host.present();
50
67
  this.state = this.prevPresent ? 'mounted' : 'unmounted';
51
68
  if (this.prevPresent) {
52
- this.mountView();
69
+ this.mount();
53
70
  }
54
71
  effect(() => {
55
- const present = this.context.present();
72
+ const present = host.present();
56
73
  if (present === this.prevPresent) {
57
74
  return;
58
75
  }
@@ -61,34 +78,122 @@ class RdxPresenceDirective {
61
78
  // Mount synchronously so the enter animation can start on this frame.
62
79
  this.send('MOUNT');
63
80
  }
64
- else if (this.isBrowser) {
81
+ else if (host.isBrowser) {
82
+ // Snapshot the close time *now* (before the render that applies the closed-state
83
+ // styles) so the freshness filter can tell exit animations from pre-existing ones.
84
+ this.closeTimestamp = this.now();
65
85
  // Defer the unmount decision until the next render, so the consumer's
66
- // `data-state` (and therefore the exit `@keyframes`) is applied to the DOM
67
- // before we read the computed animation name.
68
- afterNextRender(() => this.evaluateExit(), { injector: this.injector });
86
+ // `data-state` / `data-ending-style` (and therefore the exit styles) are applied
87
+ // to the DOM before we read the running animations.
88
+ afterNextRender(() => this.evaluateExit(), { injector: host.injector });
69
89
  }
70
90
  else {
71
91
  this.send('UNMOUNT');
72
92
  }
73
- });
74
- inject(DestroyRef).onDestroy(() => this.destroyView());
93
+ }, { injector: host.injector });
94
+ }
95
+ /** Tear the machine down — destroys the view. Call from the host's `DestroyRef`. */
96
+ dispose() {
97
+ this.unmount();
75
98
  }
76
99
  /** Decides whether to suspend the unmount for an exit animation (port of Radix' logic). */
77
100
  evaluateExit() {
78
101
  // Re-opened before this callback ran — keep the content mounted.
79
- if (this.state !== 'mounted' || this.context.present()) {
102
+ if (this.state !== 'mounted' || this.host.present()) {
80
103
  return;
81
104
  }
82
- const styles = this.getComputedStyles();
83
- const currentAnimationName = styles?.animationName || 'none';
84
- if (currentAnimationName === 'none' || styles?.display === 'none') {
85
- // No exit animation (or the element is hidden) unmount right away.
105
+ this.pendingExits.clear();
106
+ // Legacy acceptor: a watched root whose closed state starts a *different* `@keyframes`.
107
+ // This is what the zoneless jsdom suite drives (via synthetic `animationstart`/`animationend`)
108
+ // and what catches root keyframes in engines that do not expose `getAnimations`.
109
+ for (const node of this.nodes) {
110
+ const styles = getComputedStyle(node);
111
+ const currentAnimationName = styles.animationName || 'none';
112
+ const prevAnimationName = this.prevAnimationNames.get(node) ?? 'none';
113
+ const isAnimating = currentAnimationName !== 'none' &&
114
+ styles.display !== 'none' &&
115
+ prevAnimationName !== currentAnimationName;
116
+ if (isAnimating) {
117
+ this.pendingExits.add(node);
118
+ }
119
+ }
120
+ // WAAPI acceptor (ADR 0011): subtree-aware, transitions *or* keyframes, on any element in the
121
+ // template. This is what makes popup-level exits work without a positioner decoy keyframe.
122
+ const exitAnimations = this.collectExitAnimations();
123
+ if (this.pendingExits.size === 0 && exitAnimations.length === 0) {
124
+ // Nothing runs a fresh exit animation — unmount right away.
86
125
  this.send('UNMOUNT');
126
+ return;
127
+ }
128
+ this.send('ANIMATION_OUT');
129
+ if (exitAnimations.length > 0) {
130
+ // WAAPI sees the whole subtree, so it supersedes the root-event path for this close:
131
+ // wait for every fresh exit animation, version-guarded against re-open.
132
+ this.waapiPending = true;
133
+ const version = this.exitVersion;
134
+ void Promise.all(exitAnimations.map((animation) => animation.finished.catch(() => undefined))).then(() => this.finishExit(version));
135
+ this.armSafetyNet(version, exitAnimations);
136
+ }
137
+ // else: no WAAPI animations (jsdom, or an engine without `getAnimations`) → the root-event
138
+ // path drains `pendingExits` through `onEnd`, exactly as before this ADR.
139
+ }
140
+ /**
141
+ * Running/pending animations across the watched subtrees that were *started by* the close.
142
+ * Pre-existing animations (an infinite spinner, a settled enter) have an earlier `startTime`
143
+ * and must not delay the unmount.
144
+ */
145
+ collectExitAnimations() {
146
+ if (!this.host.isBrowser) {
147
+ return [];
87
148
  }
88
- else {
89
- // Only suspend the unmount if the closed state actually starts a *different* animation.
90
- const isAnimating = this.prevAnimationName !== currentAnimationName;
91
- this.send(isAnimating ? 'ANIMATION_OUT' : 'UNMOUNT');
149
+ const result = [];
150
+ for (const node of this.nodes) {
151
+ if (typeof node.getAnimations !== 'function') {
152
+ continue;
153
+ }
154
+ for (const animation of node.getAnimations({ subtree: true })) {
155
+ const fresh = animation.startTime === null || Number(animation.startTime) >= this.closeTimestamp;
156
+ // `animation.pending` is the WAAPI "created but not yet started this frame" flag — a
157
+ // freshly triggered exit. `playState` itself never reports `'pending'`.
158
+ if ((animation.playState === 'running' || animation.pending) && fresh) {
159
+ result.push(animation);
160
+ }
161
+ }
162
+ }
163
+ return result;
164
+ }
165
+ /**
166
+ * Force-completes the exit shortly after the longest declared duration, in case a `finished`
167
+ * promise never settles. Measures the animated targets (falling back to the roots).
168
+ */
169
+ armSafetyNet(version, exitAnimations) {
170
+ const targets = new Set(this.nodes);
171
+ for (const animation of exitAnimations) {
172
+ const target = animation.effect?.target;
173
+ if (target instanceof HTMLElement) {
174
+ targets.add(target);
175
+ }
176
+ }
177
+ let maxDuration = 0;
178
+ for (const element of targets) {
179
+ maxDuration = Math.max(maxDuration, getMaxTransitionDuration(element));
180
+ }
181
+ this.clearSafetyNet();
182
+ this.safetyTimer = setTimeout(() => this.finishExit(version), maxDuration + EXIT_FALLBACK_BUFFER);
183
+ }
184
+ /** Settle a WAAPI/safety-net exit wait, ignoring it if a newer mount/unmount superseded it. */
185
+ finishExit(version) {
186
+ if (version !== this.exitVersion) {
187
+ return;
188
+ }
189
+ this.waapiPending = false;
190
+ this.clearSafetyNet();
191
+ this.send('ANIMATION_END');
192
+ }
193
+ clearSafetyNet() {
194
+ if (this.safetyTimer !== null) {
195
+ clearTimeout(this.safetyTimer);
196
+ this.safetyTimer = null;
92
197
  }
93
198
  }
94
199
  send(event) {
@@ -98,60 +203,138 @@ class RdxPresenceDirective {
98
203
  }
99
204
  this.state = next;
100
205
  if (next === 'mounted') {
101
- if (this.viewRef) {
102
- // Re-opened while an exit animation was running — refresh the tracked animation.
103
- this.prevAnimationName = this.getAnimationName();
206
+ // Bump the version so any in-flight exit wait from a prior close is ignored.
207
+ this.exitVersion++;
208
+ this.waapiPending = false;
209
+ this.clearSafetyNet();
210
+ if (this.nodes.length > 0) {
211
+ // Re-opened while an exit animation was running — refresh the tracked animations and
212
+ // drop any pending exits so a late `animationend` cannot tear down the live view.
213
+ this.pendingExits.clear();
214
+ for (const node of this.nodes) {
215
+ this.prevAnimationNames.set(node, this.getAnimationName(node));
216
+ }
104
217
  }
105
218
  else {
106
- this.mountView();
219
+ this.mount();
107
220
  }
108
221
  }
109
222
  else if (next === 'unmounted') {
110
- this.destroyView();
223
+ this.exitVersion++;
224
+ this.unmount();
111
225
  }
112
226
  // `unmountSuspended` keeps the existing view mounted until ANIMATION_END.
113
227
  }
114
- mountView() {
115
- this.viewRef = this.viewContainerRef.createEmbeddedView(this.templateRef);
116
- this.node = this.viewRef.rootNodes.find((n) => n instanceof HTMLElement) ?? null;
117
- if (this.node && this.isBrowser) {
118
- this.prevAnimationName = this.getAnimationName();
119
- this.addAnimationListeners(this.node);
228
+ mount() {
229
+ this.nodes = this.host.mountView();
230
+ if (this.host.isBrowser && this.nodes.length > 0) {
231
+ for (const node of this.nodes) {
232
+ this.prevAnimationNames.set(node, this.getAnimationName(node));
233
+ }
234
+ this.addAnimationListeners();
120
235
  }
121
236
  }
122
- destroyView() {
237
+ unmount() {
123
238
  this.removeListeners?.();
124
239
  this.removeListeners = null;
125
- this.viewRef?.destroy();
126
- this.viewRef = null;
127
- this.node = null;
240
+ this.clearSafetyNet();
241
+ this.waapiPending = false;
242
+ this.host.destroyView();
243
+ this.nodes = [];
244
+ this.pendingExits.clear();
128
245
  }
129
- addAnimationListeners(node) {
246
+ addAnimationListeners() {
130
247
  const onStart = (event) => {
131
- if (event.target === node) {
132
- this.prevAnimationName = this.getAnimationName();
248
+ const node = event.target;
249
+ if (this.nodes.includes(node)) {
250
+ this.prevAnimationNames.set(node, this.getAnimationName(node));
133
251
  }
134
252
  };
135
253
  const onEnd = (event) => {
136
- const isCurrentAnimation = this.getAnimationName().includes(event.animationName);
137
- if (event.target === node && isCurrentAnimation) {
138
- this.send('ANIMATION_END');
254
+ const node = event.target;
255
+ if (!this.nodes.includes(node)) {
256
+ return;
257
+ }
258
+ // Ignore the end of an animation other than the one we are currently waiting on.
259
+ if (!this.getAnimationName(node).includes(event.animationName)) {
260
+ return;
261
+ }
262
+ this.pendingExits.delete(node);
263
+ // While a WAAPI wait owns completion it is authoritative (it sees the full subtree); the
264
+ // event path only drives the unmount when no WAAPI animations were detected.
265
+ if (!this.waapiPending && this.pendingExits.size === 0) {
266
+ this.finishExit(this.exitVersion);
139
267
  }
140
268
  };
141
- node.addEventListener('animationstart', onStart);
142
- node.addEventListener('animationcancel', onEnd);
143
- node.addEventListener('animationend', onEnd);
269
+ for (const node of this.nodes) {
270
+ node.addEventListener('animationstart', onStart);
271
+ node.addEventListener('animationcancel', onEnd);
272
+ node.addEventListener('animationend', onEnd);
273
+ }
144
274
  this.removeListeners = () => {
145
- node.removeEventListener('animationstart', onStart);
146
- node.removeEventListener('animationcancel', onEnd);
147
- node.removeEventListener('animationend', onEnd);
275
+ for (const node of this.nodes) {
276
+ node.removeEventListener('animationstart', onStart);
277
+ node.removeEventListener('animationcancel', onEnd);
278
+ node.removeEventListener('animationend', onEnd);
279
+ }
148
280
  };
149
281
  }
150
- getComputedStyles() {
151
- return this.node && this.isBrowser ? getComputedStyle(this.node) : null;
282
+ getAnimationName(node) {
283
+ return (this.host.isBrowser ? getComputedStyle(node).animationName : '') || 'none';
284
+ }
285
+ /** Current timeline time on the same clock as `Animation.startTime` (ms), or 0 if unavailable. */
286
+ now() {
287
+ const time = typeof document !== 'undefined' ? document.timeline?.currentTime : null;
288
+ return typeof time === 'number' ? time : Number(time ?? 0);
152
289
  }
153
- getAnimationName() {
154
- return this.getComputedStyles()?.animationName || 'none';
290
+ }
291
+
292
+ const RDX_PRESENCE_CONTEXT = new InjectionToken('RdxPresenceContext');
293
+ /**
294
+ * Factory provider helper.
295
+ * In your parent component/directive you can write:
296
+ *
297
+ * providers: [
298
+ * provideRdxPresenceContext(() => ({ present: myBooleanSignal }))
299
+ * ]
300
+ */
301
+ function provideRdxPresenceContext(contextFactory) {
302
+ return { provide: RDX_PRESENCE_CONTEXT, useFactory: contextFactory };
303
+ }
304
+ /**
305
+ * Headless structural directive that conditionally renders its template based on a reactive
306
+ * `present` signal supplied through {@link RDX_PRESENCE_CONTEXT}.
307
+ *
308
+ * Unlike a plain `*ngIf`, it keeps the content mounted while a CSS exit animation
309
+ * (`@keyframes` applied for the closed state) is running, and unmounts it only once that
310
+ * animation finishes. If the content has no exit animation, it unmounts immediately.
311
+ *
312
+ * The mount/unmount-with-exit logic lives in the shared {@link PresenceMachine}; this directive just
313
+ * creates the embedded view in place (`RdxPortalPresence` reuses the same machine and additionally
314
+ * relocates the view into a portal container).
315
+ */
316
+ class RdxPresenceDirective {
317
+ constructor() {
318
+ this.viewContainerRef = inject(ViewContainerRef);
319
+ this.templateRef = inject((TemplateRef));
320
+ this.viewRef = null;
321
+ const machine = new PresenceMachine({
322
+ present: inject(RDX_PRESENCE_CONTEXT).present,
323
+ isBrowser: isPlatformBrowser(inject(PLATFORM_ID)),
324
+ injector: inject(Injector),
325
+ mountView: () => this.mountView(),
326
+ destroyView: () => this.destroyView()
327
+ });
328
+ inject(DestroyRef).onDestroy(() => machine.dispose());
329
+ }
330
+ mountView() {
331
+ this.viewRef = this.viewContainerRef.createEmbeddedView(this.templateRef);
332
+ const node = this.viewRef.rootNodes.find((n) => n instanceof HTMLElement);
333
+ return node ? [node] : [];
334
+ }
335
+ destroyView() {
336
+ this.viewRef?.destroy();
337
+ this.viewRef = null;
155
338
  }
156
339
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxPresenceDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
157
340
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: RdxPresenceDirective, isStandalone: true, ngImport: i0 }); }
@@ -167,5 +350,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
167
350
  * Generated bundle index. Do not edit.
168
351
  */
169
352
 
170
- export { RDX_PRESENCE_CONTEXT, RdxPresenceDirective, provideRdxPresenceContext };
353
+ export { PresenceMachine, RDX_PRESENCE_CONTEXT, RdxPresenceDirective, provideRdxPresenceContext };
171
354
  //# sourceMappingURL=radix-ng-primitives-presence.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"radix-ng-primitives-presence.mjs","sources":["../../../packages/primitives/presence/src/presence.directive.ts","../../../packages/primitives/presence/radix-ng-primitives-presence.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n afterNextRender,\n DestroyRef,\n Directive,\n effect,\n EmbeddedViewRef,\n inject,\n InjectionToken,\n Injector,\n PLATFORM_ID,\n Provider,\n Signal,\n TemplateRef,\n ViewContainerRef\n} from '@angular/core';\n\n/**\n * Context interface for RdxPresence directive\n * Contains a Signal that indicates whether the content should be present in the DOM\n */\nexport type RdxPresenceContext = {\n present: Signal<boolean>;\n};\n\nexport const RDX_PRESENCE_CONTEXT = new InjectionToken<RdxPresenceContext>('RdxPresenceContext');\n\n/**\n * Factory provider helper.\n * In your parent component/directive you can write:\n *\n * providers: [\n * provideRdxPresenceContext(() => ({ present: myBooleanSignal }))\n * ]\n */\nexport function provideRdxPresenceContext(contextFactory: () => RdxPresenceContext): Provider {\n return { provide: RDX_PRESENCE_CONTEXT, useFactory: contextFactory };\n}\n\ntype PresenceState = 'mounted' | 'unmountSuspended' | 'unmounted';\ntype PresenceEvent = 'MOUNT' | 'UNMOUNT' | 'ANIMATION_OUT' | 'ANIMATION_END';\n\n/**\n * State machine mirroring `@radix-ui/react-presence`.\n *\n * - `mounted` — content rendered, `present` is `true`.\n * - `unmountSuspended` — `present` flipped to `false` but an exit animation is running;\n * the content stays in the DOM until the animation ends.\n * - `unmounted` — content removed.\n */\nconst MACHINE: Record<PresenceState, Partial<Record<PresenceEvent, PresenceState>>> = {\n mounted: { UNMOUNT: 'unmounted', ANIMATION_OUT: 'unmountSuspended' },\n unmountSuspended: { MOUNT: 'mounted', ANIMATION_END: 'unmounted' },\n unmounted: { MOUNT: 'mounted' }\n};\n\n/**\n * Headless structural directive that conditionally renders its template based on a reactive\n * `present` signal supplied through {@link RDX_PRESENCE_CONTEXT}.\n *\n * Unlike a plain `*ngIf`, it keeps the content mounted while a CSS exit animation\n * (`@keyframes` applied for the closed state) is running, and unmounts it only once that\n * animation finishes. If the content has no exit animation, it unmounts immediately.\n */\n@Directive({\n standalone: true\n})\nexport class RdxPresenceDirective {\n private readonly context = inject(RDX_PRESENCE_CONTEXT);\n private readonly viewContainerRef = inject(ViewContainerRef);\n private readonly templateRef = inject(TemplateRef<void>);\n private readonly injector = inject(Injector);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n private viewRef: EmbeddedViewRef<void> | null = null;\n private node: HTMLElement | null = null;\n private removeListeners: (() => void) | null = null;\n\n private state: PresenceState;\n private prevPresent: boolean;\n private prevAnimationName = 'none';\n\n constructor() {\n this.prevPresent = this.context.present();\n this.state = this.prevPresent ? 'mounted' : 'unmounted';\n\n if (this.prevPresent) {\n this.mountView();\n }\n\n effect(() => {\n const present = this.context.present();\n\n if (present === this.prevPresent) {\n return;\n }\n this.prevPresent = present;\n\n if (present) {\n // Mount synchronously so the enter animation can start on this frame.\n this.send('MOUNT');\n } else if (this.isBrowser) {\n // Defer the unmount decision until the next render, so the consumer's\n // `data-state` (and therefore the exit `@keyframes`) is applied to the DOM\n // before we read the computed animation name.\n afterNextRender(() => this.evaluateExit(), { injector: this.injector });\n } else {\n this.send('UNMOUNT');\n }\n });\n\n inject(DestroyRef).onDestroy(() => this.destroyView());\n }\n\n /** Decides whether to suspend the unmount for an exit animation (port of Radix' logic). */\n private evaluateExit(): void {\n // Re-opened before this callback ran — keep the content mounted.\n if (this.state !== 'mounted' || this.context.present()) {\n return;\n }\n\n const styles = this.getComputedStyles();\n const currentAnimationName = styles?.animationName || 'none';\n\n if (currentAnimationName === 'none' || styles?.display === 'none') {\n // No exit animation (or the element is hidden) — unmount right away.\n this.send('UNMOUNT');\n } else {\n // Only suspend the unmount if the closed state actually starts a *different* animation.\n const isAnimating = this.prevAnimationName !== currentAnimationName;\n this.send(isAnimating ? 'ANIMATION_OUT' : 'UNMOUNT');\n }\n }\n\n private send(event: PresenceEvent): void {\n const next = MACHINE[this.state][event];\n if (next === undefined || next === this.state) {\n return;\n }\n\n this.state = next;\n\n if (next === 'mounted') {\n if (this.viewRef) {\n // Re-opened while an exit animation was running — refresh the tracked animation.\n this.prevAnimationName = this.getAnimationName();\n } else {\n this.mountView();\n }\n } else if (next === 'unmounted') {\n this.destroyView();\n }\n // `unmountSuspended` keeps the existing view mounted until ANIMATION_END.\n }\n\n private mountView(): void {\n this.viewRef = this.viewContainerRef.createEmbeddedView(this.templateRef);\n this.node = this.viewRef.rootNodes.find((n): n is HTMLElement => n instanceof HTMLElement) ?? null;\n\n if (this.node && this.isBrowser) {\n this.prevAnimationName = this.getAnimationName();\n this.addAnimationListeners(this.node);\n }\n }\n\n private destroyView(): void {\n this.removeListeners?.();\n this.removeListeners = null;\n this.viewRef?.destroy();\n this.viewRef = null;\n this.node = null;\n }\n\n private addAnimationListeners(node: HTMLElement): void {\n const onStart = (event: AnimationEvent) => {\n if (event.target === node) {\n this.prevAnimationName = this.getAnimationName();\n }\n };\n const onEnd = (event: AnimationEvent) => {\n const isCurrentAnimation = this.getAnimationName().includes(event.animationName);\n if (event.target === node && isCurrentAnimation) {\n this.send('ANIMATION_END');\n }\n };\n\n node.addEventListener('animationstart', onStart);\n node.addEventListener('animationcancel', onEnd);\n node.addEventListener('animationend', onEnd);\n\n this.removeListeners = () => {\n node.removeEventListener('animationstart', onStart);\n node.removeEventListener('animationcancel', onEnd);\n node.removeEventListener('animationend', onEnd);\n };\n }\n\n private getComputedStyles(): CSSStyleDeclaration | null {\n return this.node && this.isBrowser ? getComputedStyle(this.node) : null;\n }\n\n private getAnimationName(): string {\n return this.getComputedStyles()?.animationName || 'none';\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAyBa,oBAAoB,GAAG,IAAI,cAAc,CAAqB,oBAAoB;AAE/F;;;;;;;AAOG;AACG,SAAU,yBAAyB,CAAC,cAAwC,EAAA;IAC9E,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,cAAc,EAAE;AACxE;AAKA;;;;;;;AAOG;AACH,MAAM,OAAO,GAAyE;IAClF,OA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ives-presence.mjs","sources":["../../../packages/primitives/presence/src/presence-machine.ts","../../../packages/primitives/presence/src/presence.directive.ts","../../../packages/primitives/presence/radix-ng-primitives-presence.ts"],"sourcesContent":["import { afterNextRender, effect, Injector, Signal } from '@angular/core';\nimport { getMaxTransitionDuration } from '@radix-ng/primitives/core';\n\ntype PresenceState = 'mounted' | 'unmountSuspended' | 'unmounted';\ntype PresenceEvent = 'MOUNT' | 'UNMOUNT' | 'ANIMATION_OUT' | 'ANIMATION_END';\n\n/**\n * State machine mirroring `@radix-ui/react-presence`.\n *\n * - `mounted` — content rendered, `present` is `true`.\n * - `unmountSuspended` — `present` flipped to `false` but an exit animation is running;\n * the content stays in the DOM until the animation ends.\n * - `unmounted` — content removed.\n */\nconst MACHINE: Record<PresenceState, Partial<Record<PresenceEvent, PresenceState>>> = {\n mounted: { UNMOUNT: 'unmounted', ANIMATION_OUT: 'unmountSuspended' },\n unmountSuspended: { MOUNT: 'mounted', ANIMATION_END: 'unmounted' },\n unmounted: { MOUNT: 'mounted' }\n};\n\n/**\n * Grace period (ms) added to the longest declared exit duration before the safety-net timer\n * force-completes the exit. Only matters when a `finished` promise never settles (the engine\n * under-reports `getAnimations`, the animation is replaced without a cancel, reduced motion, …).\n * Mirrors `TRANSITION_FALLBACK_BUFFER` in `use-transition-status.ts`.\n */\nconst EXIT_FALLBACK_BUFFER = 50;\n\n/**\n * Operations the host directive supplies to {@link PresenceMachine}. The machine owns *when* the\n * view is mounted/unmounted (the state transitions and exit-animation suspension); the host owns\n * *how* — `RdxPresenceDirective` simply creates the embedded view in place, while `RdxPortalPresence`\n * additionally relocates its root nodes into a portal container.\n */\nexport interface PresenceMachineHost {\n /** Reactive `present` flag driving the machine. */\n readonly present: Signal<boolean>;\n /** Whether we are running in a browser (animation/computed-style logic is skipped on the server). */\n readonly isBrowser: boolean;\n /** Injection context for the internal `effect` / `afterNextRender`. */\n readonly injector: Injector;\n /**\n * Create (and, for the portal, relocate) the view. Returns the root `HTMLElement` nodes whose\n * exit animations should suspend the unmount. For a single-root template this is one element —\n * identical to the previous single-node behavior; dialog-shaped templates return backdrop + popup.\n */\n mountView(): HTMLElement[];\n /** Destroy the view (Angular removes the nodes from wherever they currently live). */\n destroyView(): void;\n}\n\n/**\n * Reusable presence state machine extracted from `RdxPresenceDirective`. It keeps content mounted\n * while a CSS exit animation runs anywhere inside the template — a `@keyframes` **or** a\n * `transition` (`data-ending-style`), on a watched root **or any of its descendants** — and unmounts\n * only once every exit animation started by the close has finished. With no exit animation it\n * unmounts immediately. For a single watched node and a root-level keyframe this reduces exactly to\n * the original `RdxPresenceDirective` behavior.\n *\n * Detection (ADR 0011) uses the Web Animations API: when `present()` flips `false` we snapshot a\n * close timestamp, and after the next render collect `node.getAnimations({ subtree: true })`, keeping\n * only animations that are running/pending and were *started by* the close (`startTime` null or\n * `>= closeTimestamp`). The view stays mounted until all of their `finished` promises settle, bounded\n * by a duration-based safety net. The legacy root-level computed-`animationName` check and the\n * `animationstart`/`animationend` listeners are kept as an additional acceptor — they drive the\n * zoneless jsdom suites (where `getAnimations` is absent) and cost nothing in a real browser.\n */\nexport class PresenceMachine {\n private state: PresenceState;\n private prevPresent: boolean;\n\n /** Root nodes currently watched for exit animations (set on mount). */\n private nodes: HTMLElement[] = [];\n /** Last-seen computed `animationName` per node, used to detect a *fresh* root exit animation. */\n private readonly prevAnimationNames = new WeakMap<HTMLElement, string>();\n /** Root nodes whose exit animation the event path is still waiting on (jsdom / root-keyframe). */\n private readonly pendingExits = new Set<HTMLElement>();\n private removeListeners: (() => void) | null = null;\n\n /**\n * Timeline time captured the moment `present` flipped `false`, on the same clock as\n * `Animation.startTime`. Animations started at or after it are the exit animations.\n */\n private closeTimestamp = 0;\n /**\n * Monotonic counter bumped on every mount/unmount transition. A suspended exit captures it and\n * its `finished`/safety-net resolution is ignored if it changed in the meantime (re-open or a\n * second close), so a stale promise can never tear down a freshly-reopened view.\n */\n private exitVersion = 0;\n /** True while a WAAPI `finished`-promise wait owns completion; gates the event path off. */\n private waapiPending = false;\n private safetyTimer: ReturnType<typeof setTimeout> | null = null;\n\n constructor(private readonly host: PresenceMachineHost) {\n this.prevPresent = host.present();\n this.state = this.prevPresent ? 'mounted' : 'unmounted';\n\n if (this.prevPresent) {\n this.mount();\n }\n\n effect(\n () => {\n const present = host.present();\n\n if (present === this.prevPresent) {\n return;\n }\n this.prevPresent = present;\n\n if (present) {\n // Mount synchronously so the enter animation can start on this frame.\n this.send('MOUNT');\n } else if (host.isBrowser) {\n // Snapshot the close time *now* (before the render that applies the closed-state\n // styles) so the freshness filter can tell exit animations from pre-existing ones.\n this.closeTimestamp = this.now();\n // Defer the unmount decision until the next render, so the consumer's\n // `data-state` / `data-ending-style` (and therefore the exit styles) are applied\n // to the DOM before we read the running animations.\n afterNextRender(() => this.evaluateExit(), { injector: host.injector });\n } else {\n this.send('UNMOUNT');\n }\n },\n { injector: host.injector }\n );\n }\n\n /** Tear the machine down — destroys the view. Call from the host's `DestroyRef`. */\n dispose(): void {\n this.unmount();\n }\n\n /** Decides whether to suspend the unmount for an exit animation (port of Radix' logic). */\n private evaluateExit(): void {\n // Re-opened before this callback ran — keep the content mounted.\n if (this.state !== 'mounted' || this.host.present()) {\n return;\n }\n\n this.pendingExits.clear();\n\n // Legacy acceptor: a watched root whose closed state starts a *different* `@keyframes`.\n // This is what the zoneless jsdom suite drives (via synthetic `animationstart`/`animationend`)\n // and what catches root keyframes in engines that do not expose `getAnimations`.\n for (const node of this.nodes) {\n const styles = getComputedStyle(node);\n const currentAnimationName = styles.animationName || 'none';\n const prevAnimationName = this.prevAnimationNames.get(node) ?? 'none';\n\n const isAnimating =\n currentAnimationName !== 'none' &&\n styles.display !== 'none' &&\n prevAnimationName !== currentAnimationName;\n\n if (isAnimating) {\n this.pendingExits.add(node);\n }\n }\n\n // WAAPI acceptor (ADR 0011): subtree-aware, transitions *or* keyframes, on any element in the\n // template. This is what makes popup-level exits work without a positioner decoy keyframe.\n const exitAnimations = this.collectExitAnimations();\n\n if (this.pendingExits.size === 0 && exitAnimations.length === 0) {\n // Nothing runs a fresh exit animation — unmount right away.\n this.send('UNMOUNT');\n return;\n }\n\n this.send('ANIMATION_OUT');\n\n if (exitAnimations.length > 0) {\n // WAAPI sees the whole subtree, so it supersedes the root-event path for this close:\n // wait for every fresh exit animation, version-guarded against re-open.\n this.waapiPending = true;\n const version = this.exitVersion;\n\n void Promise.all(exitAnimations.map((animation) => animation.finished.catch(() => undefined))).then(() =>\n this.finishExit(version)\n );\n\n this.armSafetyNet(version, exitAnimations);\n }\n // else: no WAAPI animations (jsdom, or an engine without `getAnimations`) → the root-event\n // path drains `pendingExits` through `onEnd`, exactly as before this ADR.\n }\n\n /**\n * Running/pending animations across the watched subtrees that were *started by* the close.\n * Pre-existing animations (an infinite spinner, a settled enter) have an earlier `startTime`\n * and must not delay the unmount.\n */\n private collectExitAnimations(): Animation[] {\n if (!this.host.isBrowser) {\n return [];\n }\n\n const result: Animation[] = [];\n\n for (const node of this.nodes) {\n if (typeof node.getAnimations !== 'function') {\n continue;\n }\n\n for (const animation of node.getAnimations({ subtree: true })) {\n const fresh = animation.startTime === null || Number(animation.startTime) >= this.closeTimestamp;\n\n // `animation.pending` is the WAAPI \"created but not yet started this frame\" flag — a\n // freshly triggered exit. `playState` itself never reports `'pending'`.\n if ((animation.playState === 'running' || animation.pending) && fresh) {\n result.push(animation);\n }\n }\n }\n\n return result;\n }\n\n /**\n * Force-completes the exit shortly after the longest declared duration, in case a `finished`\n * promise never settles. Measures the animated targets (falling back to the roots).\n */\n private armSafetyNet(version: number, exitAnimations: Animation[]): void {\n const targets = new Set<HTMLElement>(this.nodes);\n\n for (const animation of exitAnimations) {\n const target = (animation.effect as KeyframeEffect | null)?.target;\n if (target instanceof HTMLElement) {\n targets.add(target);\n }\n }\n\n let maxDuration = 0;\n for (const element of targets) {\n maxDuration = Math.max(maxDuration, getMaxTransitionDuration(element));\n }\n\n this.clearSafetyNet();\n this.safetyTimer = setTimeout(() => this.finishExit(version), maxDuration + EXIT_FALLBACK_BUFFER);\n }\n\n /** Settle a WAAPI/safety-net exit wait, ignoring it if a newer mount/unmount superseded it. */\n private finishExit(version: number): void {\n if (version !== this.exitVersion) {\n return;\n }\n this.waapiPending = false;\n this.clearSafetyNet();\n this.send('ANIMATION_END');\n }\n\n private clearSafetyNet(): void {\n if (this.safetyTimer !== null) {\n clearTimeout(this.safetyTimer);\n this.safetyTimer = null;\n }\n }\n\n private send(event: PresenceEvent): void {\n const next = MACHINE[this.state][event];\n if (next === undefined || next === this.state) {\n return;\n }\n\n this.state = next;\n\n if (next === 'mounted') {\n // Bump the version so any in-flight exit wait from a prior close is ignored.\n this.exitVersion++;\n this.waapiPending = false;\n this.clearSafetyNet();\n\n if (this.nodes.length > 0) {\n // Re-opened while an exit animation was running — refresh the tracked animations and\n // drop any pending exits so a late `animationend` cannot tear down the live view.\n this.pendingExits.clear();\n for (const node of this.nodes) {\n this.prevAnimationNames.set(node, this.getAnimationName(node));\n }\n } else {\n this.mount();\n }\n } else if (next === 'unmounted') {\n this.exitVersion++;\n this.unmount();\n }\n // `unmountSuspended` keeps the existing view mounted until ANIMATION_END.\n }\n\n private mount(): void {\n this.nodes = this.host.mountView();\n\n if (this.host.isBrowser && this.nodes.length > 0) {\n for (const node of this.nodes) {\n this.prevAnimationNames.set(node, this.getAnimationName(node));\n }\n this.addAnimationListeners();\n }\n }\n\n private unmount(): void {\n this.removeListeners?.();\n this.removeListeners = null;\n this.clearSafetyNet();\n this.waapiPending = false;\n this.host.destroyView();\n this.nodes = [];\n this.pendingExits.clear();\n }\n\n private addAnimationListeners(): void {\n const onStart = (event: AnimationEvent) => {\n const node = event.target as HTMLElement;\n if (this.nodes.includes(node)) {\n this.prevAnimationNames.set(node, this.getAnimationName(node));\n }\n };\n const onEnd = (event: AnimationEvent) => {\n const node = event.target as HTMLElement;\n if (!this.nodes.includes(node)) {\n return;\n }\n // Ignore the end of an animation other than the one we are currently waiting on.\n if (!this.getAnimationName(node).includes(event.animationName)) {\n return;\n }\n\n this.pendingExits.delete(node);\n // While a WAAPI wait owns completion it is authoritative (it sees the full subtree); the\n // event path only drives the unmount when no WAAPI animations were detected.\n if (!this.waapiPending && this.pendingExits.size === 0) {\n this.finishExit(this.exitVersion);\n }\n };\n\n for (const node of this.nodes) {\n node.addEventListener('animationstart', onStart);\n node.addEventListener('animationcancel', onEnd);\n node.addEventListener('animationend', onEnd);\n }\n\n this.removeListeners = () => {\n for (const node of this.nodes) {\n node.removeEventListener('animationstart', onStart);\n node.removeEventListener('animationcancel', onEnd);\n node.removeEventListener('animationend', onEnd);\n }\n };\n }\n\n private getAnimationName(node: HTMLElement): string {\n return (this.host.isBrowser ? getComputedStyle(node).animationName : '') || 'none';\n }\n\n /** Current timeline time on the same clock as `Animation.startTime` (ms), or 0 if unavailable. */\n private now(): number {\n const time = typeof document !== 'undefined' ? document.timeline?.currentTime : null;\n return typeof time === 'number' ? time : Number(time ?? 0);\n }\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n DestroyRef,\n Directive,\n EmbeddedViewRef,\n inject,\n InjectionToken,\n Injector,\n PLATFORM_ID,\n Provider,\n Signal,\n TemplateRef,\n ViewContainerRef\n} from '@angular/core';\nimport { PresenceMachine } from './presence-machine';\n\n/**\n * Context interface for RdxPresence directive\n * Contains a Signal that indicates whether the content should be present in the DOM\n */\nexport type RdxPresenceContext = {\n present: Signal<boolean>;\n};\n\nexport const RDX_PRESENCE_CONTEXT = new InjectionToken<RdxPresenceContext>('RdxPresenceContext');\n\n/**\n * Factory provider helper.\n * In your parent component/directive you can write:\n *\n * providers: [\n * provideRdxPresenceContext(() => ({ present: myBooleanSignal }))\n * ]\n */\nexport function provideRdxPresenceContext(contextFactory: () => RdxPresenceContext): Provider {\n return { provide: RDX_PRESENCE_CONTEXT, useFactory: contextFactory };\n}\n\n/**\n * Headless structural directive that conditionally renders its template based on a reactive\n * `present` signal supplied through {@link RDX_PRESENCE_CONTEXT}.\n *\n * Unlike a plain `*ngIf`, it keeps the content mounted while a CSS exit animation\n * (`@keyframes` applied for the closed state) is running, and unmounts it only once that\n * animation finishes. If the content has no exit animation, it unmounts immediately.\n *\n * The mount/unmount-with-exit logic lives in the shared {@link PresenceMachine}; this directive just\n * creates the embedded view in place (`RdxPortalPresence` reuses the same machine and additionally\n * relocates the view into a portal container).\n */\n@Directive({\n standalone: true\n})\nexport class RdxPresenceDirective {\n private readonly viewContainerRef = inject(ViewContainerRef);\n private readonly templateRef = inject(TemplateRef<void>);\n\n private viewRef: EmbeddedViewRef<void> | null = null;\n\n constructor() {\n const machine = new PresenceMachine({\n present: inject(RDX_PRESENCE_CONTEXT).present,\n isBrowser: isPlatformBrowser(inject(PLATFORM_ID)),\n injector: inject(Injector),\n mountView: () => this.mountView(),\n destroyView: () => this.destroyView()\n });\n\n inject(DestroyRef).onDestroy(() => machine.dispose());\n }\n\n private mountView(): HTMLElement[] {\n this.viewRef = this.viewContainerRef.createEmbeddedView(this.templateRef);\n const node = this.viewRef.rootNodes.find((n): n is HTMLElement => n instanceof HTMLElement);\n return node ? [node] : [];\n }\n\n private destroyView(): void {\n this.viewRef?.destroy();\n this.viewRef = null;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAMA;;;;;;;AAOG;AACH,MAAM,OAAO,GAAyE;IAClF,OAAO,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE;IACpE,gBAAgB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE;AAClE,IAAA,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS;CAChC;AAED;;;;;AAKG;AACH,MAAM,oBAAoB,GAAG,EAAE;AAyB/B;;;;;;;;;;;;;;;AAeG;MACU,eAAe,CAAA;AA2BxB,IAAA,WAAA,CAA6B,IAAyB,EAAA;QAAzB,IAAA,CAAA,IAAI,GAAJ,IAAI;;QAtBzB,IAAA,CAAA,K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