@atlaskit/top-layer 4.4.5 → 5.0.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.
Files changed (130) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +13 -4
  3. package/dist/cjs/dialog/dialog-content.js +2 -0
  4. package/dist/cjs/entry-points/use-popover-id.js +5 -10
  5. package/dist/cjs/internal/anchor-positioning/apply-anchor-positioning.js +86 -0
  6. package/dist/cjs/internal/anchor-positioning/cross-axis-shift-margins.js +34 -0
  7. package/dist/cjs/internal/anchor-positioning/edge-margin.js +21 -0
  8. package/dist/cjs/internal/anchor-positioning/fit-margins.js +77 -0
  9. package/dist/cjs/internal/anchor-positioning/get-existing-anchor-name.js +18 -0
  10. package/dist/cjs/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +11 -11
  11. package/dist/cjs/internal/anchor-positioning/placement-to-try-fallbacks.js +95 -0
  12. package/dist/cjs/internal/anchored-popover-size.js +345 -0
  13. package/dist/cjs/internal/get-aria-for-trigger.js +7 -13
  14. package/dist/cjs/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  15. package/dist/cjs/internal/javascript-fallback/apply-javascript-fallback-positioning.js +297 -0
  16. package/dist/cjs/internal/javascript-fallback/resolve-css-length-to-pixels.js +90 -0
  17. package/dist/cjs/internal/javascript-fallback/warn-fallback-failure.js +19 -0
  18. package/dist/cjs/internal/resolve-placement.js +14 -6
  19. package/dist/cjs/internal/supports-anchor-positioning.js +17 -0
  20. package/dist/cjs/internal/supports-anchor-size.js +17 -0
  21. package/dist/cjs/internal/supports-css-declaration.js +25 -0
  22. package/dist/cjs/internal/surface-reset.js +5 -0
  23. package/dist/cjs/internal/use-anchored-popover-at-point.js +124 -0
  24. package/dist/cjs/internal/use-anchored-popover.js +277 -0
  25. package/dist/cjs/popover/popover.compiled.css +4 -0
  26. package/dist/cjs/popover/popover.js +11 -4
  27. package/dist/cjs/testing/polyfill.js +6 -7
  28. package/dist/es2019/dialog/dialog-content.js +2 -0
  29. package/dist/es2019/entry-points/use-popover-id.js +6 -10
  30. package/dist/es2019/internal/anchor-positioning/apply-anchor-positioning.js +83 -0
  31. package/dist/es2019/internal/anchor-positioning/cross-axis-shift-margins.js +29 -0
  32. package/dist/es2019/internal/anchor-positioning/edge-margin.js +18 -0
  33. package/dist/es2019/internal/anchor-positioning/fit-margins.js +69 -0
  34. package/dist/es2019/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
  35. package/dist/es2019/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +9 -9
  36. package/dist/es2019/internal/anchor-positioning/placement-to-try-fallbacks.js +94 -0
  37. package/dist/es2019/internal/anchored-popover-size.js +343 -0
  38. package/dist/es2019/internal/get-aria-for-trigger.js +7 -13
  39. package/dist/es2019/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  40. package/dist/es2019/internal/javascript-fallback/apply-javascript-fallback-positioning.js +291 -0
  41. package/dist/es2019/internal/javascript-fallback/resolve-css-length-to-pixels.js +87 -0
  42. package/dist/es2019/internal/javascript-fallback/warn-fallback-failure.js +14 -0
  43. package/dist/es2019/internal/resolve-placement.js +14 -6
  44. package/dist/es2019/internal/supports-anchor-positioning.js +12 -0
  45. package/dist/es2019/internal/supports-anchor-size.js +12 -0
  46. package/dist/es2019/internal/supports-css-declaration.js +20 -0
  47. package/dist/es2019/internal/surface-reset.js +1 -0
  48. package/dist/es2019/internal/use-anchored-popover-at-point.js +116 -0
  49. package/dist/es2019/internal/use-anchored-popover.js +265 -0
  50. package/dist/es2019/popover/popover.compiled.css +4 -0
  51. package/dist/es2019/popover/popover.js +11 -4
  52. package/dist/es2019/testing/polyfill.js +6 -7
  53. package/dist/esm/dialog/dialog-content.js +2 -0
  54. package/dist/esm/entry-points/use-popover-id.js +6 -10
  55. package/dist/esm/internal/anchor-positioning/apply-anchor-positioning.js +80 -0
  56. package/dist/esm/internal/anchor-positioning/cross-axis-shift-margins.js +28 -0
  57. package/dist/esm/internal/anchor-positioning/edge-margin.js +15 -0
  58. package/dist/esm/internal/anchor-positioning/fit-margins.js +71 -0
  59. package/dist/esm/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
  60. package/dist/esm/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +11 -12
  61. package/dist/esm/internal/anchor-positioning/placement-to-try-fallbacks.js +89 -0
  62. package/dist/esm/internal/anchored-popover-size.js +338 -0
  63. package/dist/esm/internal/get-aria-for-trigger.js +7 -13
  64. package/dist/esm/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  65. package/dist/esm/internal/javascript-fallback/apply-javascript-fallback-positioning.js +290 -0
  66. package/dist/esm/internal/javascript-fallback/resolve-css-length-to-pixels.js +85 -0
  67. package/dist/esm/internal/javascript-fallback/warn-fallback-failure.js +13 -0
  68. package/dist/esm/internal/resolve-placement.js +14 -6
  69. package/dist/esm/internal/supports-anchor-positioning.js +12 -0
  70. package/dist/esm/internal/supports-anchor-size.js +12 -0
  71. package/dist/esm/internal/supports-css-declaration.js +19 -0
  72. package/dist/esm/internal/surface-reset.js +1 -0
  73. package/dist/esm/internal/use-anchored-popover-at-point.js +118 -0
  74. package/dist/esm/internal/use-anchored-popover.js +271 -0
  75. package/dist/esm/popover/popover.compiled.css +4 -0
  76. package/dist/esm/popover/popover.js +11 -4
  77. package/dist/esm/testing/polyfill.js +6 -7
  78. package/dist/types/entry-points/placement-map.d.ts +2 -2
  79. package/dist/types/entry-points/use-popover-id.d.ts +3 -7
  80. package/dist/types/internal/anchor-positioning/apply-anchor-positioning.d.ts +26 -0
  81. package/dist/types/internal/anchor-positioning/cross-axis-shift-margins.d.ts +19 -0
  82. package/dist/types/internal/anchor-positioning/edge-margin.d.ts +10 -0
  83. package/dist/types/internal/anchor-positioning/fit-margins.d.ts +30 -0
  84. package/dist/types/internal/anchor-positioning/get-existing-anchor-name.d.ts +8 -0
  85. package/dist/types/internal/{placement-to-position-area.d.ts → anchor-positioning/placement-to-position-area.d.ts} +10 -6
  86. package/dist/types/internal/anchor-positioning/placement-to-try-fallbacks.d.ts +30 -0
  87. package/dist/types/internal/anchored-popover-size.d.ts +126 -0
  88. package/dist/types/internal/get-aria-for-trigger.d.ts +13 -25
  89. package/dist/types/internal/javascript-fallback/anchor-positioning-fallback.d.ts +36 -0
  90. package/dist/types/internal/javascript-fallback/apply-javascript-fallback-positioning.d.ts +15 -0
  91. package/dist/types/internal/javascript-fallback/resolve-css-length-to-pixels.d.ts +20 -0
  92. package/dist/types/internal/javascript-fallback/warn-fallback-failure.d.ts +7 -0
  93. package/dist/types/internal/resolve-placement.d.ts +18 -2
  94. package/dist/types/internal/supports-anchor-positioning.d.ts +5 -0
  95. package/dist/types/internal/supports-anchor-size.d.ts +5 -0
  96. package/dist/types/internal/supports-css-declaration.d.ts +11 -0
  97. package/dist/types/internal/surface-reset.d.ts +25 -0
  98. package/dist/types/internal/use-anchored-popover-at-point.d.ts +48 -0
  99. package/dist/types/internal/use-anchored-popover.d.ts +143 -0
  100. package/dist/types/popover/index.d.ts +2 -1
  101. package/dist/types/popover/popover.d.ts +1 -1
  102. package/dist/types/popover/types.d.ts +15 -17
  103. package/dist/types/testing/polyfill.d.ts +3 -3
  104. package/package.json +2 -2
  105. package/use-anchored-popover/package.json +10 -0
  106. package/use-anchored-popover-at-point/package.json +10 -0
  107. package/dist/cjs/internal/placement-to-try-fallbacks.js +0 -108
  108. package/dist/cjs/internal/resolve-css-length-to-pixels.js +0 -104
  109. package/dist/cjs/internal/use-anchor-position-at-point.js +0 -129
  110. package/dist/cjs/internal/use-anchor-position.js +0 -501
  111. package/dist/cjs/internal/use-width-from-anchor.js +0 -124
  112. package/dist/es2019/internal/placement-to-try-fallbacks.js +0 -108
  113. package/dist/es2019/internal/resolve-css-length-to-pixels.js +0 -101
  114. package/dist/es2019/internal/use-anchor-position-at-point.js +0 -124
  115. package/dist/es2019/internal/use-anchor-position.js +0 -480
  116. package/dist/es2019/internal/use-width-from-anchor.js +0 -120
  117. package/dist/esm/internal/placement-to-try-fallbacks.js +0 -103
  118. package/dist/esm/internal/resolve-css-length-to-pixels.js +0 -98
  119. package/dist/esm/internal/use-anchor-position-at-point.js +0 -124
  120. package/dist/esm/internal/use-anchor-position.js +0 -494
  121. package/dist/esm/internal/use-width-from-anchor.js +0 -118
  122. package/dist/types/internal/anchor-positioning-fallback.d.ts +0 -51
  123. package/dist/types/internal/placement-to-try-fallbacks.d.ts +0 -13
  124. package/dist/types/internal/resolve-css-length-to-pixels.d.ts +0 -20
  125. package/dist/types/internal/use-anchor-position-at-point.d.ts +0 -67
  126. package/dist/types/internal/use-anchor-position.d.ts +0 -87
  127. package/dist/types/internal/use-width-from-anchor.d.ts +0 -19
  128. package/use-anchor-position/package.json +0 -10
  129. package/use-anchor-position-at-point/package.json +0 -10
  130. package/use-width-from-anchor/package.json +0 -10
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Positioning AND anchor-relative sizing for top-layer popovers. Anchors an
3
+ * ELEMENT; to anchor a viewport coordinate use `useAnchoredPopoverAtPoint`.
4
+ *
5
+ * Two runtime paths, each a function that applies its styles and returns the
6
+ * cleanup: CSS Anchor Positioning in `./anchor-positioning`, and the JavaScript
7
+ * fallback in `./javascript-fallback`. The path is resolved ONCE, at the top of
8
+ * the hook, and threaded through positioning, sizing and margins.
9
+ *
10
+ * See `notes/architecture/positioning.md` and
11
+ * `notes/decisions/fit-available-space.md`.
12
+ */
13
+ import { useLayoutEffect, useMemo } from 'react';
14
+ import { useId } from '@atlaskit/ds-lib/use-id';
15
+ import { applyAnchorPositioning } from './anchor-positioning/apply-anchor-positioning';
16
+ import { getAnchoredPopoverSizeDeclarations } from './anchored-popover-size';
17
+ import { applyJavaScriptFallbackPositioning } from './javascript-fallback/apply-javascript-fallback-positioning';
18
+ import { resolvePlacement } from './resolve-placement';
19
+ import { supportsAnchorPositioning } from './supports-anchor-positioning';
20
+ import { supportsAnchorSize } from './supports-anchor-size';
21
+
22
+ /**
23
+ * Which way the popover's inline axis runs. Maps every physical measurement below
24
+ * onto a logical axis: the viewport unit of each cap and the anchor's measured
25
+ * size. A style read, not a layout read, so it is cheap enough to take for every
26
+ * popover.
27
+ */
28
+ function getPopoverWritingMode(_ref) {
29
+ var popover = _ref.popover;
30
+ // `String()` because not every test environment implements `writing-mode`.
31
+ var writingMode = String(getComputedStyle(popover).writingMode);
32
+ var isVertical = writingMode.startsWith('vertical') || writingMode.startsWith('sideways');
33
+ return isVertical ? 'vertical' : 'horizontal';
34
+ }
35
+
36
+ /**
37
+ * Measured stand-in for `anchor-size(self-*)`, used wherever `anchor-size()` is
38
+ * not: the JavaScript fallback, and browsers with anchor positioning but no
39
+ * `anchor-size()`.
40
+ *
41
+ * `offsetWidth` / `offsetHeight` are physical, so the axis is picked from the
42
+ * POPOVER's `writing-mode`. Deliberately not memoized: a cached anchor size is a
43
+ * stale one. Runs once per effect, not per frame.
44
+ */
45
+ function measureAnchorSize(_ref2) {
46
+ var anchor = _ref2.anchor,
47
+ writingMode = _ref2.writingMode;
48
+ if (writingMode === 'vertical') {
49
+ return {
50
+ inline: "".concat(anchor.offsetHeight, "px"),
51
+ block: "".concat(anchor.offsetWidth, "px")
52
+ };
53
+ }
54
+ return {
55
+ inline: "".concat(anchor.offsetWidth, "px"),
56
+ block: "".concat(anchor.offsetHeight, "px")
57
+ };
58
+ }
59
+ var NO_ANCHOR_SIZE = {
60
+ inline: null,
61
+ block: null
62
+ };
63
+ var CSS_ANCHOR_SIZE = {
64
+ inline: 'anchor-size(self-inline)',
65
+ block: 'anchor-size(self-block)'
66
+ };
67
+ function isAnchorRelative(size) {
68
+ return size === 'match-anchor' || size === 'min-anchor';
69
+ }
70
+
71
+ /**
72
+ * The `anchor-name` written to an anchor that does not already carry one, as a CSS
73
+ * `<dashed-ident>`. `useId()` is the same source as every other id in the design
74
+ * system, including the popover's own `id` that `aria-controls` and `popovertarget`
75
+ * point at, so it is unique exactly where those are and collides exactly where
76
+ * they do. See `useAnchoredPopover` for the one case that needs the host's help.
77
+ *
78
+ * `@atlaskit/ds-lib`'s `useId` already swaps React's `:` and `«»` for `_`. The
79
+ * replace covers a host `identifierPrefix`, which may carry characters a
80
+ * `<dashed-ident>` cannot.
81
+ */
82
+ function useNewAnchorName() {
83
+ var id = useId();
84
+ return useMemo(function () {
85
+ return "--anchor-".concat(id.replace(/[^A-Za-z0-9_-]/g, '_'));
86
+ }, [id]);
87
+ }
88
+
89
+ /**
90
+ * A referentially-stable, fully-resolved `TPlacement`, so a fresh inline
91
+ * `placement` object does not re-run the effect.
92
+ */
93
+ function useStablePlacement(placement) {
94
+ var resolved = resolvePlacement({
95
+ placement: placement
96
+ });
97
+ var axis = resolved.axis;
98
+ var edge = resolved.edge;
99
+ var align = resolved.align;
100
+ var minSize = resolved.minSize;
101
+ var gap = resolved.offset.gap;
102
+ var shiftValue = resolved.offset.crossAxisShift.value;
103
+ var shiftDirection = resolved.offset.crossAxisShift.direction;
104
+ // Rebuilt from primitive deps, so the factory does not close over `resolved`
105
+ // and exhaustive-deps can verify it.
106
+ return useMemo(function () {
107
+ return {
108
+ axis: axis,
109
+ edge: edge,
110
+ align: align,
111
+ minSize: minSize,
112
+ offset: {
113
+ gap: gap,
114
+ crossAxisShift: {
115
+ value: shiftValue,
116
+ direction: shiftDirection
117
+ }
118
+ }
119
+ };
120
+ }, [axis, edge, align, minSize, gap, shiftValue, shiftDirection]);
121
+ }
122
+
123
+ /**
124
+ * Exported so `useAnchoredPopoverAtPoint` can forward the options it does not own.
125
+ */
126
+
127
+ /**
128
+ * Positions and sizes a popover relative to an anchor. Owns every inline style on
129
+ * the popover host: where it goes, how big it is relative to its anchor, and the
130
+ * margins that keep it clear of the anchor and the viewport edge. It knows nothing
131
+ * about visibility or animation - compose it with `Popover`.
132
+ *
133
+ * On modern browsers the browser handles flipping via CSS Anchor Positioning;
134
+ * otherwise it falls back to measured `position: fixed` coordinates, re-run on
135
+ * scroll and resize.
136
+ *
137
+ * `inlineSize` and `blockSize` both default to `'content'`. Two rules are
138
+ * surprising: fitting one axis also fits an axis left on `'content'`, and fitting
139
+ * either axis floors the placement axis. See `TPopoverAxisSize`.
140
+ *
141
+ * **Several React roots on one page.** The `anchor-name` this hook writes to an
142
+ * anchor that has none is minted from `useId()`, like every other id in the design
143
+ * system. `useId()` is unique within a root; across roots it is unique for
144
+ * client-rendered roots but NOT for roots that hydrate the same markup, where it
145
+ * is derived from tree position. Two anchors carrying one name resolve to the last
146
+ * in tree order, so a popover can attach to another root's trigger. A host that
147
+ * hydrates more than one root must give each a distinct `identifierPrefix` (on
148
+ * `hydrateRoot` and the matching server render). That is already required for the
149
+ * popover's own `id`, which `aria-controls` and `popovertarget` point at, and for
150
+ * every `aria-*` id the design system mints. A bundle with two copies of
151
+ * `react-dom` has the same exposure for client-rendered roots.
152
+ *
153
+ * @example Position a popover below its trigger
154
+ * ```tsx
155
+ * const triggerRef = useRef<HTMLButtonElement>(null);
156
+ * const popoverRef = useRef<HTMLDivElement>(null);
157
+ *
158
+ * useAnchoredPopover({
159
+ * anchorRef: triggerRef,
160
+ * popoverRef,
161
+ * placement: { axis: 'block', edge: 'end' },
162
+ * isOpen,
163
+ * });
164
+ * ```
165
+ *
166
+ * @example Match the trigger's width and keep the popover on screen
167
+ * ```tsx
168
+ * // What `<Popup shouldFitContainer shouldFitViewport>` maps to.
169
+ * useAnchoredPopover({
170
+ * anchorRef: triggerRef,
171
+ * popoverRef,
172
+ * placement: { axis: 'block', edge: 'end' },
173
+ * isOpen,
174
+ * inlineSize: 'match-anchor',
175
+ * blockSize: 'max-available',
176
+ * });
177
+ * ```
178
+ *
179
+ * @example Switch to a cursor position mid-mount
180
+ * ```tsx
181
+ * // Complementary `isEnabled`, so exactly one hook owns the popover.
182
+ * const shared = { popoverRef, placement, isOpen };
183
+ *
184
+ * useAnchoredPopover({ ...shared, anchorRef: triggerRef, isEnabled: !mousePos });
185
+ * useAnchoredPopoverAtPoint({
186
+ * ...shared,
187
+ * isEnabled: Boolean(mousePos),
188
+ * getPoint: () => mousePosRef.current,
189
+ * });
190
+ * ```
191
+ */
192
+ export function useAnchoredPopover(_ref3) {
193
+ var anchorRef = _ref3.anchorRef,
194
+ popoverRef = _ref3.popoverRef,
195
+ placement = _ref3.placement,
196
+ isOpen = _ref3.isOpen,
197
+ _ref3$isEnabled = _ref3.isEnabled,
198
+ isEnabled = _ref3$isEnabled === void 0 ? true : _ref3$isEnabled,
199
+ _ref3$inlineSize = _ref3.inlineSize,
200
+ inlineSize = _ref3$inlineSize === void 0 ? 'content' : _ref3$inlineSize,
201
+ _ref3$blockSize = _ref3.blockSize,
202
+ blockSize = _ref3$blockSize === void 0 ? 'content' : _ref3$blockSize,
203
+ _ref3$shouldPreserveI = _ref3.shouldPreserveInlineSize,
204
+ shouldPreserveInlineSize = _ref3$shouldPreserveI === void 0 ? false : _ref3$shouldPreserveI,
205
+ _ref3$forceFallbackPo = _ref3.forceFallbackPositioning,
206
+ forceFallbackPositioning = _ref3$forceFallbackPo === void 0 ? false : _ref3$forceFallbackPo;
207
+ // Stable for the life of the hook instance, so it follows a replacement anchor
208
+ // element (the point hook remounts its `<div>`).
209
+ var fallbackAnchorName = useNewAnchorName();
210
+ var stablePlacement = useStablePlacement(placement);
211
+ useLayoutEffect(function () {
212
+ if (!isEnabled) {
213
+ return;
214
+ }
215
+
216
+ // Resolved once, so positioning, sizing and margins cannot disagree about it.
217
+ var isUsingCssAnchorPositioning = supportsAnchorPositioning() && !forceFallbackPositioning;
218
+
219
+ // BOTH probes: a browser can have positioning without sizing, and
220
+ // `anchor-size()` needs the `position-anchor` only the CSS path writes.
221
+ var canUseAnchorSize = isUsingCssAnchorPositioning && supportsAnchorSize();
222
+ var trigger = anchorRef.current;
223
+ var popover = popoverRef.current;
224
+ if (!trigger || !popover) {
225
+ return;
226
+ }
227
+
228
+ // Fitting also reserves padding from the viewport edge as a margin.
229
+ var isFitting = inlineSize === 'max-available' || blockSize === 'max-available';
230
+
231
+ // Always read: the viewport caps are always written, and their unit follows
232
+ // the popover's writing mode.
233
+ var writingMode = getPopoverWritingMode({
234
+ popover: popover
235
+ });
236
+
237
+ // Skipped where possible, so a position-only consumer pays no layout read.
238
+ // Fitting on the CSS path needs it to clamp the default flip floor; see
239
+ // `getDefaultPlacementAxisFloor`.
240
+ var needsAnchorSize = isAnchorRelative(inlineSize) || isAnchorRelative(blockSize) || isFitting && isUsingCssAnchorPositioning;
241
+ var anchorSize = needsAnchorSize ? canUseAnchorSize ? CSS_ANCHOR_SIZE : measureAnchorSize({
242
+ anchor: trigger,
243
+ writingMode: writingMode
244
+ }) : NO_ANCHOR_SIZE;
245
+ var sizeStyles = getAnchoredPopoverSizeDeclarations({
246
+ placement: stablePlacement,
247
+ inlineSize: inlineSize,
248
+ blockSize: blockSize,
249
+ isUsingCssAnchorPositioning: isUsingCssAnchorPositioning,
250
+ anchorSize: anchorSize,
251
+ writingMode: writingMode,
252
+ shouldPreserveInlineSize: shouldPreserveInlineSize
253
+ });
254
+ if (isUsingCssAnchorPositioning) {
255
+ return applyAnchorPositioning({
256
+ anchor: trigger,
257
+ popover: popover,
258
+ placement: stablePlacement,
259
+ sizeStyles: sizeStyles,
260
+ isFitting: isFitting,
261
+ fallbackAnchorName: fallbackAnchorName
262
+ });
263
+ }
264
+ return applyJavaScriptFallbackPositioning({
265
+ anchor: trigger,
266
+ popover: popover,
267
+ placement: stablePlacement,
268
+ sizeStyles: sizeStyles
269
+ });
270
+ }, [isEnabled, anchorRef, popoverRef, stablePlacement, inlineSize, blockSize, shouldPreserveInlineSize, fallbackAnchorName, forceFallbackPositioning, isOpen]);
271
+ }
@@ -22,6 +22,10 @@
22
22
  ._n3tdidpf{padding-bottom:0}
23
23
  ._o5724jg8{white-space:normal}
24
24
  ._otyridpf{margin-bottom:0}
25
+ ._p6861txw:popover-open{display:flex}
25
26
  ._u5f3idpf{padding-right:0}
26
27
  ._y3gnv2br{text-align:start}
28
+ :where(._1yp3idpf)>*{min-inline-size:0}
29
+ :where(._51hckb7n)>*{flex-grow:1}
30
+ :where(._f5r5idpf)>*{min-block-size:0}
27
31
  @media (prefers-reduced-motion:reduce){._bl8aglyw{animation-name:none}._156y147i{transition-duration:var(--ds-duration-instant,0ms)}}
@@ -33,15 +33,22 @@ var supportsPopoverHint = once(function () {
33
33
  // avoided this by rendering at `<body>`). Excludes `color`/`font` (theming) and
34
34
  // `direction`/`unicode-bidi` (RTL must inherit).
35
35
  //
36
+ // Not `all: initial`: the target is what `<body>` gave the portal path, not the
37
+ // spec initial values (UA serif, black, `color-scheme: normal`), and as an author
38
+ // declaration it would also override the UA `[popover]` rules (`position: fixed`,
39
+ // `display: none` when closed).
40
+ //
36
41
  // KEEP IN SYNC with the identical `surfaceResetStyles` in `dialog/dialog-content.tsx`.
37
42
  // ADS forbids sharing styles across files (`no-exported-styles` /
38
43
  // `no-imported-style-values` — Compiled styles are null at runtime), so the reset is
39
- // co-located and duplicated deliberately.
44
+ // co-located and duplicated deliberately. The `satisfies` check below fails the
45
+ // build if either copy drifts.
40
46
  var surfaceResetStyles = {
41
47
  root: "_lcxv1wug _o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
42
48
  };
49
+ true;
43
50
  var styles = {
44
- root: "_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _19pkidpf _2hwxidpf _otyridpf _18u0idpf _1r041wug _1reoewfl _18m9ewfl _bfhk1j28 _4t3i1wug",
51
+ root: "_19itglyw _ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _19pkidpf _2hwxidpf _otyridpf _18u0idpf _1r041wug _1reoewfl _18m9ewfl _bfhk1j28 _4t3i1wug _p6861txw _51hckb7n _1yp3idpf _f5r5idpf",
45
52
  motion: "_k8m011k7 _1oecdn4k _1s9z1a5r _1o511hrf _bl8aglyw _156y147i",
46
53
  enter: "_y44v179n",
47
54
  exit: "_y44vof1f"
@@ -79,7 +86,7 @@ var POPUP_ROLES = new Set(['menu', 'listbox', 'dialog', 'alertdialog', 'tree', '
79
86
 
80
87
  /**
81
88
  * Unopinionated top-layer primitive. Owns visibility and animation only;
82
- * compose with `useAnchorPosition` / `useWidthFromAnchor` for positioning.
89
+ * compose with `useAnchoredPopover` for positioning and sizing.
83
90
  *
84
91
  * ### 🔌 Visibility
85
92
  *
@@ -247,7 +254,7 @@ export var Popover = /*#__PURE__*/forwardRef(function Popover(_ref, ref) {
247
254
  // for dialog roles. Restoration is native for outermost popovers; nested
248
255
  // focus-capturing roles are handled above via the `beforetoggle` snapshot.
249
256
  // Passing `phase` keeps `useFocusWrap` attached through the animated-exit
250
- // window (WCAG 2.4.3 guard). See notes/architecture/focus-restoration.md.
257
+ // window (WCAG 2.4.3 guard). See notes/architecture/focus.md.
251
258
  useFocusWrap({
252
259
  elementRef: ownRef,
253
260
  role: role,
@@ -13,9 +13,9 @@
13
13
  * - Popover open state tracked via `data-popover-open` (no `:popover-open` in jsdom).
14
14
  * - Auto popovers: maintain an open stack, perform light-dismiss on document mousedown
15
15
  * outside the open chain, and dismiss the topmost on Escape.
16
- * - On open, removes any inline `opacity: 0` from the popover element so callers that
17
- * rely on a `ResizeObserver` reveal callback (e.g. `use-anchor-position`) become
18
- * visible in jsdom, where layout-driven RO callbacks never fire.
16
+ * - On open, removes any inline `opacity: 0` from the popover element, so the
17
+ * JavaScript positioning fallback's `ResizeObserver` reveal is not needed in
18
+ * jsdom, where its non-zero-layout guard can never pass.
19
19
  *
20
20
  * Companion `toBeVisible` patch lives at `./to-be-visible`.
21
21
  *
@@ -247,10 +247,9 @@ function stackForMode(_ref9) {
247
247
  return null;
248
248
  }
249
249
 
250
- // Polyfill-only. Real browsers reveal the popover once `ResizeObserver`
251
- // callbacks fire after the first layout pass. jsdom has no layout, so we clear
252
- // any inline `opacity: 0` (set by callers like `use-anchor-position`) once
253
- // the open toggle has fired.
250
+ // Polyfill-only. Real browsers reveal the popover on the first non-zero layout
251
+ // their `ResizeObserver` reports; jsdom always reports 0, so that guard never
252
+ // passes and the inline `opacity: 0` is cleared on the open toggle instead.
254
253
  function clearOpacityOnOpenToggle(_ref0) {
255
254
  var element = _ref0.element;
256
255
  var unbind = bind(element, {
@@ -5,8 +5,8 @@ export { fromLegacyPlacement } from '../placement-map';
5
5
  /**
6
6
  * @deprecated Import from the generated per-export subpath instead.
7
7
  */
8
- export { LEGACY_PLACEMENTS } from '../placement-map/legacy-placements';
8
+ export { LEGACY_PLACEMENTS, type TLegacyPlacement } from '../placement-map/legacy-placements';
9
9
  /**
10
10
  * @deprecated Import from the generated per-export subpath instead.
11
11
  */
12
- export type { TLegacyPlacement, TPlacementOptions } from '../placement-map';
12
+ export type { TPlacementOptions } from '../internal/resolve-placement';
@@ -1,11 +1,7 @@
1
1
  /**
2
- * Returns a stable HTML `id` used to wire a trigger element to its popover
3
- * via ARIA (`aria-controls`) and the Popover API (`popovertarget`).
2
+ * A stable `id` for wiring a trigger to its popover: the popover's `id`, and the
3
+ * trigger's matching `aria-controls` / `popovertarget`.
4
4
  *
5
- * The returned value is intended for the `id` attribute on the popover and
6
- * for the matching `aria-controls` / `popovertarget` references on the
7
- * trigger. It is NOT a CSS `anchor-name` value: CSS anchor positioning is
8
- * handled internally by `useAnchorPosition`, which mints and applies its
9
- * own `anchor-name` on the trigger element.
5
+ * NOT a CSS `anchor-name` - `useAnchoredPopover` mints and writes its own.
10
6
  */
11
7
  export declare function usePopoverId(): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The CSS Anchor Positioning path: `position-anchor`, `position-area`,
3
+ * `position-try-fallbacks` and the gap / shift margins, all declared on the
4
+ * popover so the browser owns placement and flipping. The twin of
5
+ * `../javascript-fallback/apply-javascript-fallback-positioning`.
6
+ */
7
+ import { type TPlacement } from '../resolve-placement';
8
+ import { type TStyleDeclaration } from '../set-style';
9
+ /**
10
+ * Returns the cleanup.
11
+ */
12
+ export declare function applyAnchorPositioning({ anchor, popover, placement, sizeStyles, isFitting, fallbackAnchorName, }: {
13
+ anchor: HTMLElement;
14
+ popover: HTMLElement;
15
+ placement: TPlacement;
16
+ sizeStyles: TStyleDeclaration[];
17
+ /**
18
+ * Whether either axis is `'max-available'`, which also reserves padding from
19
+ * the viewport edge as a margin.
20
+ */
21
+ isFitting: boolean;
22
+ /**
23
+ * Written to the anchor when it does not already carry one.
24
+ */
25
+ fallbackAnchorName: string;
26
+ }): () => void;
@@ -0,0 +1,19 @@
1
+ import { type TCrossAxisShiftDirection, type TPlacement } from '../resolve-placement';
2
+ import { type TStyleDeclaration } from '../set-style';
3
+ import { type TLogicalMarginProperty } from './fit-margins';
4
+ /**
5
+ * The cross-axis shift, written antisymmetrically on BOTH cross-axis sides rather
6
+ * than as one margin. Do not collapse it to one side: a single margin widens the
7
+ * margin box, so `anchor-center` displaces the border box by only half the value,
8
+ * a `<position-area>` fallback sliding across the cross axis drops it entirely,
9
+ * and the widened box changes where the popover is judged to overflow.
10
+ *
11
+ * A positive value always moves the popover toward the cross-axis END, so
12
+ * `direction: 'forwards'` means the same thing for every `align` value. See
13
+ * `notes/decisions/placement-offset.md`.
14
+ */
15
+ export declare function crossAxisShiftMargins({ placement, crossAxisShiftCssValue, direction, }: {
16
+ placement: TPlacement;
17
+ crossAxisShiftCssValue: string;
18
+ direction: TCrossAxisShiftDirection;
19
+ }): TStyleDeclaration<TLogicalMarginProperty>[];
@@ -0,0 +1,10 @@
1
+ import { type TPlacement } from '../resolve-placement';
2
+ import { type TStyleDeclaration } from '../set-style';
3
+ import { type TLogicalMarginProperty } from './fit-margins';
4
+ /**
5
+ * The margin that creates the gap between the popover and its anchor.
6
+ */
7
+ export declare function edgeMargin({ placement, offset, }: {
8
+ placement: TPlacement;
9
+ offset: string;
10
+ }): TStyleDeclaration<TLogicalMarginProperty>;
@@ -0,0 +1,30 @@
1
+ import { type TPlacement, type TPlacementAxis, type TPlacementEdge } from '../resolve-placement';
2
+ import { type TStyleDeclaration } from '../set-style';
3
+ /**
4
+ * Every logical margin property the fit recipe can write. Declared here and
5
+ * imported by `edge-margin.tsx` and `cross-axis-shift-margins.tsx`: two
6
+ * structurally identical declarations are interchangeable to the compiler, so a
7
+ * divergence would surface only as a silently-ignored property name at
8
+ * `setStyle`.
9
+ */
10
+ export type TLogicalMarginProperty = `margin-${TPlacementAxis}-${TPlacementEdge}`;
11
+ /**
12
+ * The margin half of the fit recipe. The caps reserve the viewport padding by
13
+ * subtracting it, but nothing makes the reservation land on the viewport side, so
14
+ * a capped popover packs flush against the edge it slid or flipped to.
15
+ *
16
+ * The padding buys visual clearance and nothing else: at the cap the margin box
17
+ * is exactly `100%` of the cell, so these margins never make
18
+ * `position-try-fallbacks` fire. Only the unclamped placement-axis floor does
19
+ * that; see `getPlacementAxisFloor`.
20
+ *
21
+ * The cross-axis sides are composed, not overwritten: they already carry the
22
+ * antisymmetric `crossAxisShift` pair.
23
+ */
24
+ export declare function getFitMarginDeclarations({ placement, crossAxisShiftMargins, }: {
25
+ placement: TPlacement;
26
+ /**
27
+ * The antisymmetric cross-axis shift pair, to compose the padding into.
28
+ */
29
+ crossAxisShiftMargins: TStyleDeclaration<TLogicalMarginProperty>[];
30
+ }): TStyleDeclaration<TLogicalMarginProperty>[];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The `anchor-name` an element already carries, or `null`. Computed as well as
3
+ * inline, so a name set from a STYLESHEET is found: a minted inline name would
4
+ * otherwise override it for every other rule anchored to that element.
5
+ * `anchor-name` is a list and `position-anchor` takes one ident, so the first
6
+ * name is the one to anchor to.
7
+ */
8
+ export declare function getExistingAnchorName(element: HTMLElement): string | null;
@@ -1,6 +1,6 @@
1
- import { type TPlacementOptions } from '../internal/resolve-placement';
1
+ import { type TPlacement } from '../resolve-placement';
2
2
  /**
3
- * Resolves placement options to CSS `position-area` syntax.
3
+ * Resolves a placement to CSS `position-area` syntax.
4
4
  *
5
5
  * The `align` field represents the *visual* alignment:
6
6
  * - `align: 'start'` means "aligned to the trigger's start edge" (left in LTR for block axis)
@@ -11,11 +11,15 @@ import { type TPlacementOptions } from '../internal/resolve-placement';
11
11
  * Visual start-alignment requires `span-{cross-axis}-end` (expand toward end = start-aligned).
12
12
  * This function handles the inversion internally.
13
13
  *
14
+ * Takes the RESOLVED placement, which the hook threads through positioning,
15
+ * sizing and margins alike, so nothing here can disagree with them.
16
+ *
14
17
  * @example
15
- * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'center' } }) // → 'block-end'
16
- * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'start' } }) // → 'block-end span-inline-end'
17
- * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'end' } }) // → 'block-end span-inline-start'
18
+ * // For a `block-end` placement, by `align`:
19
+ * // 'center' → 'block-end'
20
+ * // 'start' → 'block-end span-inline-end'
21
+ * // 'end' → 'block-end span-inline-start'
18
22
  */
19
23
  export declare function placementToPositionArea({ placement }: {
20
- placement: TPlacementOptions;
24
+ placement: TPlacement;
21
25
  }): string;
@@ -0,0 +1,30 @@
1
+ import { type TPlacement } from '../resolve-placement';
2
+ /**
3
+ * Returns the `position-try-fallbacks` value for a RESOLVED placement. The
4
+ * browser tries the entries in order and uses the first one whose margin box
5
+ * fits, so an entry over a cell already tried can never be chosen; `slideOnEdge`
6
+ * explains which ones those are.
7
+ *
8
+ * Centred: slide along the requested edge to either span, flip to the opposite
9
+ * edge, then slide along that edge to either span.
10
+ *
11
+ * Start / end aligned: slide along the requested edge (re-centred, then the far
12
+ * span), flip to the opposite edge keeping the alignment, flip on the diagonal
13
+ * into the opposite corner, then re-centre on the opposite edge. The diagonal is
14
+ * the clean escape when the popover would land off screen on both axes: a flip
15
+ * keyword carries the gap and shift margins across, where a position-area slide
16
+ * leaves them on the original sides.
17
+ *
18
+ * @example
19
+ * // Centred on the block-end edge (the default placement):
20
+ * placementToTryFallbacks({ placement: resolvePlacement({ placement: {} }) });
21
+ * // => 'block-end span-inline-end, block-end span-inline-start, flip-block,
22
+ * // block-start span-inline-end, block-start span-inline-start'
23
+ *
24
+ * // Start-aligned on the block-end edge:
25
+ * placementToTryFallbacks({ placement: resolvePlacement({ placement: { align: 'start' } }) });
26
+ * // => 'block-end, block-end span-inline-start, flip-block, flip-block flip-inline, block-start'
27
+ */
28
+ export declare function placementToTryFallbacks({ placement }: {
29
+ placement: TPlacement;
30
+ }): string;