@atlaskit/top-layer 4.4.5 → 5.0.1

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 (137) hide show
  1. package/CHANGELOG.md +50 -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/is-native-element-open.js +19 -0
  15. package/dist/cjs/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  16. package/dist/cjs/internal/javascript-fallback/apply-javascript-fallback-positioning.js +297 -0
  17. package/dist/cjs/internal/javascript-fallback/resolve-css-length-to-pixels.js +90 -0
  18. package/dist/cjs/internal/javascript-fallback/warn-fallback-failure.js +19 -0
  19. package/dist/cjs/internal/resolve-placement.js +14 -6
  20. package/dist/cjs/internal/supports-anchor-positioning.js +17 -0
  21. package/dist/cjs/internal/supports-anchor-size.js +17 -0
  22. package/dist/cjs/internal/supports-css-declaration.js +25 -0
  23. package/dist/cjs/internal/surface-reset.js +5 -0
  24. package/dist/cjs/internal/use-anchored-popover-at-point.js +124 -0
  25. package/dist/cjs/internal/use-anchored-popover.js +277 -0
  26. package/dist/cjs/internal/use-animated-visibility.js +11 -23
  27. package/dist/cjs/popover/popover.compiled.css +4 -0
  28. package/dist/cjs/popover/popover.js +63 -61
  29. package/dist/cjs/testing/polyfill.js +6 -7
  30. package/dist/es2019/dialog/dialog-content.js +2 -0
  31. package/dist/es2019/entry-points/use-popover-id.js +6 -10
  32. package/dist/es2019/internal/anchor-positioning/apply-anchor-positioning.js +83 -0
  33. package/dist/es2019/internal/anchor-positioning/cross-axis-shift-margins.js +29 -0
  34. package/dist/es2019/internal/anchor-positioning/edge-margin.js +18 -0
  35. package/dist/es2019/internal/anchor-positioning/fit-margins.js +69 -0
  36. package/dist/es2019/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
  37. package/dist/es2019/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +9 -9
  38. package/dist/es2019/internal/anchor-positioning/placement-to-try-fallbacks.js +94 -0
  39. package/dist/es2019/internal/anchored-popover-size.js +343 -0
  40. package/dist/es2019/internal/get-aria-for-trigger.js +7 -13
  41. package/dist/es2019/internal/is-native-element-open.js +14 -0
  42. package/dist/es2019/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  43. package/dist/es2019/internal/javascript-fallback/apply-javascript-fallback-positioning.js +291 -0
  44. package/dist/es2019/internal/javascript-fallback/resolve-css-length-to-pixels.js +87 -0
  45. package/dist/es2019/internal/javascript-fallback/warn-fallback-failure.js +14 -0
  46. package/dist/es2019/internal/resolve-placement.js +14 -6
  47. package/dist/es2019/internal/supports-anchor-positioning.js +12 -0
  48. package/dist/es2019/internal/supports-anchor-size.js +12 -0
  49. package/dist/es2019/internal/supports-css-declaration.js +20 -0
  50. package/dist/es2019/internal/surface-reset.js +1 -0
  51. package/dist/es2019/internal/use-anchored-popover-at-point.js +116 -0
  52. package/dist/es2019/internal/use-anchored-popover.js +265 -0
  53. package/dist/es2019/internal/use-animated-visibility.js +1 -14
  54. package/dist/es2019/popover/popover.compiled.css +4 -0
  55. package/dist/es2019/popover/popover.js +69 -61
  56. package/dist/es2019/testing/polyfill.js +6 -7
  57. package/dist/esm/dialog/dialog-content.js +2 -0
  58. package/dist/esm/entry-points/use-popover-id.js +6 -10
  59. package/dist/esm/internal/anchor-positioning/apply-anchor-positioning.js +80 -0
  60. package/dist/esm/internal/anchor-positioning/cross-axis-shift-margins.js +28 -0
  61. package/dist/esm/internal/anchor-positioning/edge-margin.js +15 -0
  62. package/dist/esm/internal/anchor-positioning/fit-margins.js +71 -0
  63. package/dist/esm/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
  64. package/dist/esm/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +11 -12
  65. package/dist/esm/internal/anchor-positioning/placement-to-try-fallbacks.js +89 -0
  66. package/dist/esm/internal/anchored-popover-size.js +338 -0
  67. package/dist/esm/internal/get-aria-for-trigger.js +7 -13
  68. package/dist/esm/internal/is-native-element-open.js +13 -0
  69. package/dist/esm/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  70. package/dist/esm/internal/javascript-fallback/apply-javascript-fallback-positioning.js +290 -0
  71. package/dist/esm/internal/javascript-fallback/resolve-css-length-to-pixels.js +85 -0
  72. package/dist/esm/internal/javascript-fallback/warn-fallback-failure.js +13 -0
  73. package/dist/esm/internal/resolve-placement.js +14 -6
  74. package/dist/esm/internal/supports-anchor-positioning.js +12 -0
  75. package/dist/esm/internal/supports-anchor-size.js +12 -0
  76. package/dist/esm/internal/supports-css-declaration.js +19 -0
  77. package/dist/esm/internal/surface-reset.js +1 -0
  78. package/dist/esm/internal/use-anchored-popover-at-point.js +118 -0
  79. package/dist/esm/internal/use-anchored-popover.js +271 -0
  80. package/dist/esm/internal/use-animated-visibility.js +10 -22
  81. package/dist/esm/popover/popover.compiled.css +4 -0
  82. package/dist/esm/popover/popover.js +63 -61
  83. package/dist/esm/testing/polyfill.js +6 -7
  84. package/dist/types/entry-points/placement-map.d.ts +2 -2
  85. package/dist/types/entry-points/use-popover-id.d.ts +3 -7
  86. package/dist/types/internal/anchor-positioning/apply-anchor-positioning.d.ts +26 -0
  87. package/dist/types/internal/anchor-positioning/cross-axis-shift-margins.d.ts +19 -0
  88. package/dist/types/internal/anchor-positioning/edge-margin.d.ts +10 -0
  89. package/dist/types/internal/anchor-positioning/fit-margins.d.ts +30 -0
  90. package/dist/types/internal/anchor-positioning/get-existing-anchor-name.d.ts +8 -0
  91. package/dist/types/internal/{placement-to-position-area.d.ts → anchor-positioning/placement-to-position-area.d.ts} +10 -6
  92. package/dist/types/internal/anchor-positioning/placement-to-try-fallbacks.d.ts +30 -0
  93. package/dist/types/internal/anchored-popover-size.d.ts +126 -0
  94. package/dist/types/internal/get-aria-for-trigger.d.ts +13 -25
  95. package/dist/types/internal/is-native-element-open.d.ts +3 -0
  96. package/dist/types/internal/javascript-fallback/anchor-positioning-fallback.d.ts +36 -0
  97. package/dist/types/internal/javascript-fallback/apply-javascript-fallback-positioning.d.ts +15 -0
  98. package/dist/types/internal/javascript-fallback/resolve-css-length-to-pixels.d.ts +20 -0
  99. package/dist/types/internal/javascript-fallback/warn-fallback-failure.d.ts +7 -0
  100. package/dist/types/internal/resolve-placement.d.ts +18 -2
  101. package/dist/types/internal/supports-anchor-positioning.d.ts +5 -0
  102. package/dist/types/internal/supports-anchor-size.d.ts +5 -0
  103. package/dist/types/internal/supports-css-declaration.d.ts +11 -0
  104. package/dist/types/internal/surface-reset.d.ts +25 -0
  105. package/dist/types/internal/use-anchored-popover-at-point.d.ts +48 -0
  106. package/dist/types/internal/use-anchored-popover.d.ts +143 -0
  107. package/dist/types/popover/index.d.ts +2 -1
  108. package/dist/types/popover/popover.d.ts +1 -1
  109. package/dist/types/popover/types.d.ts +15 -17
  110. package/dist/types/testing/polyfill.d.ts +3 -3
  111. package/package.json +2 -2
  112. package/use-anchored-popover/package.json +10 -0
  113. package/use-anchored-popover-at-point/package.json +10 -0
  114. package/dist/cjs/internal/placement-to-try-fallbacks.js +0 -108
  115. package/dist/cjs/internal/resolve-css-length-to-pixels.js +0 -104
  116. package/dist/cjs/internal/use-anchor-position-at-point.js +0 -129
  117. package/dist/cjs/internal/use-anchor-position.js +0 -501
  118. package/dist/cjs/internal/use-width-from-anchor.js +0 -124
  119. package/dist/es2019/internal/placement-to-try-fallbacks.js +0 -108
  120. package/dist/es2019/internal/resolve-css-length-to-pixels.js +0 -101
  121. package/dist/es2019/internal/use-anchor-position-at-point.js +0 -124
  122. package/dist/es2019/internal/use-anchor-position.js +0 -480
  123. package/dist/es2019/internal/use-width-from-anchor.js +0 -120
  124. package/dist/esm/internal/placement-to-try-fallbacks.js +0 -103
  125. package/dist/esm/internal/resolve-css-length-to-pixels.js +0 -98
  126. package/dist/esm/internal/use-anchor-position-at-point.js +0 -124
  127. package/dist/esm/internal/use-anchor-position.js +0 -494
  128. package/dist/esm/internal/use-width-from-anchor.js +0 -118
  129. package/dist/types/internal/anchor-positioning-fallback.d.ts +0 -51
  130. package/dist/types/internal/placement-to-try-fallbacks.d.ts +0 -13
  131. package/dist/types/internal/resolve-css-length-to-pixels.d.ts +0 -20
  132. package/dist/types/internal/use-anchor-position-at-point.d.ts +0 -67
  133. package/dist/types/internal/use-anchor-position.d.ts +0 -87
  134. package/dist/types/internal/use-width-from-anchor.d.ts +0 -19
  135. package/use-anchor-position/package.json +0 -10
  136. package/use-anchor-position-at-point/package.json +0 -10
  137. package/use-width-from-anchor/package.json +0 -10
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VIEWPORT_PADDING = exports.FALLBACK_MINIMUM_MAIN_AXIS_SIZE = void 0;
7
+ exports.getAnchoredPopoverSizeDeclarations = getAnchoredPopoverSizeDeclarations;
8
+ /**
9
+ * The space kept clear between a popover and the viewport edge. Matches legacy
10
+ * `@atlaskit/popper`'s `preventOverflow` padding of `5`.
11
+ */
12
+ var VIEWPORT_PADDING = exports.VIEWPORT_PADDING = '5px';
13
+
14
+ /**
15
+ * The upper bound for the default placement-axis floor while fitting. A capped
16
+ * popover never overflows, so it never flips; this floor makes the margin box
17
+ * overflow a too-small cell so `position-try-fallbacks` fires. A flip driver and
18
+ * nothing else, so the JavaScript fallback, which has no cell to overflow, never
19
+ * writes it. See `getPlacementAxisFloor`.
20
+ *
21
+ * 150px is the value the flip was measured with, not a design constant
22
+ * (`notes/plans/should-fit-viewport.md`). Deliberately not a `space.*` token:
23
+ * theming it would move the flip threshold, and so change which side a popover
24
+ * lands on.
25
+ */
26
+ var FALLBACK_MINIMUM_MAIN_AXIS_SIZE = exports.FALLBACK_MINIMUM_MAIN_AXIS_SIZE = '150px';
27
+
28
+ /**
29
+ * Which way the POPOVER's inline axis runs; `'vertical'` covers the `vertical-*`
30
+ * and `sideways-*` writing modes. Measured rather than assumed, because every
31
+ * logical property this module writes resolves against the popover's own writing
32
+ * mode, and so must the viewport unit paired with it.
33
+ */
34
+
35
+ /**
36
+ * The dynamic viewport unit for one of the popover's axes. Not `dvi` / `dvb`:
37
+ * css-values-4 defines those against the ROOT element's writing mode, while the
38
+ * `max-{axis}-size` they are written to follows the popover's, so a popover in a
39
+ * `vertical-rl` subtree of a horizontal document would be capped by the wrong
40
+ * dimension.
41
+ */
42
+ function viewportUnit(_ref) {
43
+ var axis = _ref.axis,
44
+ writingMode = _ref.writingMode;
45
+ var isHorizontalAxis = axis === 'inline' === (writingMode === 'horizontal');
46
+ return isHorizontalAxis ? 'dvw' : 'dvh';
47
+ }
48
+
49
+ /**
50
+ * How one axis of an anchored popover is sized. Both axes take these four values
51
+ * under identical rules.
52
+ *
53
+ * - `'content'`: sized by its content. Named after `flex-basis: content`; NOT
54
+ * `'auto'`, whose CSS meaning for a positioned box is shrink-to-fit, the very
55
+ * behaviour rule 4 removes.
56
+ * - `'match-anchor'`: exactly the anchor's size on this axis.
57
+ * - `'min-anchor'`: at least the anchor's size on this axis, free to grow.
58
+ * - `'max-available'`: at most the space between the anchor and the viewport
59
+ * edge, content-sized below that. Capped by the `position-area` cell on the
60
+ * placement axis and by the viewport on the cross axis (a `span-*` cell is
61
+ * narrower than the viewport, so capping to it would wrap content that fits on
62
+ * screen).
63
+ *
64
+ * Four rules apply on top:
65
+ *
66
+ * 1. Fitting one axis fills a `'content'` other axis with `'max-available'` too.
67
+ * An explicit value is never overridden, so caps stay strictly per-axis.
68
+ * 2. Fitting either axis floors the placement axis, because flipping is a
69
+ * whole-popover outcome. See `getPlacementAxisFloor`.
70
+ * 3. The viewport cap is unconditional, so a non-fitting axis still cannot
71
+ * overhang the screen. `'max-available'` and `'content'` are therefore
72
+ * indistinguishable on the cross axis.
73
+ * 4. A non-anchor-relative inline axis gets `inline-size: max-content`. Under
74
+ * `position-area` the containing block is the cell, so a CSS `auto` inline
75
+ * size shrink-to-fits a too-narrow cell and WRAPS into it, never overflowing
76
+ * and so never sliding to the roomier side. The caps still beat it, because a
77
+ * max beats a definite size. Not needed on the block axis, which does not
78
+ * wrap, nor on the JavaScript fallback, whose containing block is the
79
+ * viewport. Consumers opt out with `shouldPreserveInlineSize`.
80
+ *
81
+ * See `notes/decisions/fit-available-space.md`.
82
+ */
83
+
84
+ /**
85
+ * Narrowed rather than `string`, so a typo cannot reach `setStyle` as a
86
+ * silently-ignored property name.
87
+ */
88
+
89
+ /**
90
+ * The anchor's size along each axis, as a CSS length. `null` when nothing needs
91
+ * it, so the measurement is skipped.
92
+ *
93
+ * The CSS path uses the `self-` keywords, whose axes are the POPOVER's, so each
94
+ * value matches the axis of the property it is set on (`anchor-size(inline)` and
95
+ * `anchor-size(width)` are both silently wrong in a vertical writing mode). The
96
+ * JavaScript fallback uses a measured pixel length, because `anchor-size()` needs
97
+ * a `position-anchor` that path never sets. See
98
+ * `notes/decisions/width-from-anchor-floors.md`.
99
+ */
100
+
101
+ function getCrossAxis(axis) {
102
+ return axis === 'block' ? 'inline' : 'block';
103
+ }
104
+
105
+ /**
106
+ * The whole viewport, less the reserved padding on both sides. Rule 3's backstop.
107
+ */
108
+ function viewportCap(_ref2) {
109
+ var axis = _ref2.axis,
110
+ writingMode = _ref2.writingMode;
111
+ return "calc(100".concat(viewportUnit({
112
+ axis: axis,
113
+ writingMode: writingMode
114
+ }), " - 2 * ").concat(VIEWPORT_PADDING, ")");
115
+ }
116
+
117
+ /**
118
+ * The position-area cell cap, for the placement axis only. The host carries
119
+ * `position-area`, so per css-anchor-position-1 the cell is its containing block:
120
+ * `100%` is the anchor edge to the viewport edge, and it follows whichever side
121
+ * `position-try-fallbacks` settles on. Percentages do not subtract margins, so
122
+ * the gap is subtracted here.
123
+ *
124
+ * Meaningless on the JavaScript fallback, whose containing block is the viewport,
125
+ * so that path gets `viewportCap` on both axes.
126
+ */
127
+ function cellCap(_ref3) {
128
+ var gap = _ref3.gap;
129
+ return "calc(100% - ".concat(VIEWPORT_PADDING, " - ").concat(gap, ")");
130
+ }
131
+
132
+ /**
133
+ * The anchor term of the placement-axis floor, and the one place it is capped.
134
+ *
135
+ * `'match-anchor'` earns a floor only where it can flip: a definite size clamps to
136
+ * the cap and shrinks below the anchor instead of flipping.
137
+ *
138
+ * The `canFlip` clamp is deliberate both ways. With no flip in play an unclamped
139
+ * floor beats `max-{axis}-size` (CSS resolves `min` last), making the viewport
140
+ * backstop inert. With a flip in play, clamping would stop the floor exceeding
141
+ * the cell cap, which is what drives the flip.
142
+ */
143
+ function getPlacementAxisAnchorFloor(_ref4) {
144
+ var placementAxis = _ref4.placementAxis,
145
+ placementAxisSize = _ref4.placementAxisSize,
146
+ anchorValue = _ref4.anchorValue,
147
+ canFlip = _ref4.canFlip,
148
+ writingMode = _ref4.writingMode;
149
+ var hasAnchorFloor = placementAxisSize === 'min-anchor' || placementAxisSize === 'match-anchor' && canFlip;
150
+ if (!hasAnchorFloor || anchorValue === null) {
151
+ return undefined;
152
+ }
153
+ if (canFlip) {
154
+ return anchorValue;
155
+ }
156
+ return "min(".concat(anchorValue, ", ").concat(viewportCap({
157
+ axis: placementAxis,
158
+ writingMode: writingMode
159
+ }), ")");
160
+ }
161
+
162
+ /**
163
+ * The default flip floor, clamped so that SOME cell can always hold it.
164
+ *
165
+ * The two cells either side of the anchor add up to the viewport less the anchor,
166
+ * so the roomier one is at least half of that. A floor whose margin box fits
167
+ * inside that half is guaranteed a cell somewhere in the fallback chain.
168
+ * Unclamped, a short viewport with a centred anchor has NO cell that holds
169
+ * 150px: every try-fallback overflows, the browser reverts to the base position,
170
+ * and the floor pushes the popover past the viewport edge.
171
+ *
172
+ * This is NOT the `min(floor, cellCap)` that suppresses flipping: it is relative
173
+ * to the VIEWPORT, so a small base cell still overflows it. `max(0px, …)` states
174
+ * the lower bound for an anchor taller than the viewport.
175
+ */
176
+ function getDefaultPlacementAxisFloor(_ref5) {
177
+ var placementAxis = _ref5.placementAxis,
178
+ anchorValue = _ref5.anchorValue,
179
+ gap = _ref5.gap,
180
+ writingMode = _ref5.writingMode;
181
+ if (anchorValue === null) {
182
+ return FALLBACK_MINIMUM_MAIN_AXIS_SIZE;
183
+ }
184
+ // The viewport term and the anchor term must measure the SAME axis; see
185
+ // `viewportUnit`.
186
+ var viewport = "100".concat(viewportUnit({
187
+ axis: placementAxis,
188
+ writingMode: writingMode
189
+ }));
190
+ var halfOfRemainingViewport = "calc((".concat(viewport, " - ").concat(anchorValue, ") / 2 - ").concat(gap, " - ").concat(VIEWPORT_PADDING, ")");
191
+ return "min(".concat(FALLBACK_MINIMUM_MAIN_AXIS_SIZE, ", max(0px, ").concat(halfOfRemainingViewport, "))");
192
+ }
193
+
194
+ /**
195
+ * The placement-axis floor: explicit minimums COMPOSE, the default does not.
196
+ *
197
+ * `placement.minSize` and the anchor term are both explicit requests, so they
198
+ * compose as `max()`. `FALLBACK_MINIMUM_MAIN_AXIS_SIZE` never composes: it only
199
+ * ever won by overriding a size the consumer asked for, and the anchor term drives
200
+ * the flip on its own. Knock-on, intended: `minSize: 0` no longer removes an
201
+ * anchor floor, because `max(0px, anchor)` IS the anchor.
202
+ */
203
+ function getPlacementAxisFloor(_ref6) {
204
+ var minSize = _ref6.minSize,
205
+ placementAxis = _ref6.placementAxis,
206
+ placementAxisSize = _ref6.placementAxisSize,
207
+ anchorValue = _ref6.anchorValue,
208
+ gap = _ref6.gap,
209
+ canFlip = _ref6.canFlip,
210
+ writingMode = _ref6.writingMode;
211
+ var anchorFloor = getPlacementAxisAnchorFloor({
212
+ placementAxis: placementAxis,
213
+ placementAxisSize: placementAxisSize,
214
+ anchorValue: anchorValue,
215
+ canFlip: canFlip,
216
+ writingMode: writingMode
217
+ });
218
+ if (minSize !== undefined) {
219
+ return anchorFloor === undefined ? minSize : "max(".concat(minSize, ", ").concat(anchorFloor, ")");
220
+ }
221
+ if (anchorFloor !== undefined) {
222
+ return anchorFloor;
223
+ }
224
+ if (!canFlip) {
225
+ return undefined;
226
+ }
227
+ return getDefaultPlacementAxisFloor({
228
+ placementAxis: placementAxis,
229
+ anchorValue: anchorValue,
230
+ gap: gap,
231
+ writingMode: writingMode
232
+ });
233
+ }
234
+
235
+ /**
236
+ * The whole size recipe for an anchored popover, in one place. Pure, so the truth
237
+ * table is unit-testable without a browser, and every size property on the
238
+ * popover host has exactly one writer.
239
+ *
240
+ * While anything is fitting on the CSS path, the placement-axis floor is never
241
+ * clamped to the CELL cap. Its whole job is to exceed it: overflow detection
242
+ * reads the margin box AFTER the clamp (css-anchor-position-1 §6.5), so
243
+ * `min(floor, cap)` suppresses `position-try-fallbacks` entirely. The cross-axis
244
+ * floor is always clamped, because there it is a size contract rather than a flip
245
+ * driver.
246
+ *
247
+ * See `notes/decisions/fit-available-space.md` for the full recipe and the
248
+ * measured evidence.
249
+ */
250
+ function getAnchoredPopoverSizeDeclarations(_ref7) {
251
+ var placement = _ref7.placement,
252
+ inlineSize = _ref7.inlineSize,
253
+ blockSize = _ref7.blockSize,
254
+ isUsingCssAnchorPositioning = _ref7.isUsingCssAnchorPositioning,
255
+ anchorSize = _ref7.anchorSize,
256
+ writingMode = _ref7.writingMode,
257
+ _ref7$shouldPreserveI = _ref7.shouldPreserveInlineSize,
258
+ shouldPreserveInlineSize = _ref7$shouldPreserveI === void 0 ? false : _ref7$shouldPreserveI;
259
+ var placementAxis = placement.axis;
260
+ var crossAxis = getCrossAxis(placementAxis);
261
+
262
+ // Rule 1. Feeds the per-axis CAPS only.
263
+ var size = {
264
+ inline: inlineSize === 'content' && blockSize === 'max-available' ? 'max-available' : inlineSize,
265
+ block: blockSize === 'content' && inlineSize === 'max-available' ? 'max-available' : blockSize
266
+ };
267
+
268
+ // Rule 2 reads the requested values instead, un-mirrored: flipping is a
269
+ // whole-popover outcome, so a fit request on either axis turns the floor on.
270
+ var isFitting = inlineSize === 'max-available' || blockSize === 'max-available';
271
+
272
+ // ...but only where the floor is what causes the flip. On the JavaScript
273
+ // fallback a floor only inflates the measured size the side is picked from, so
274
+ // it would flip a popover that fits.
275
+ var canFlip = isFitting && isUsingCssAnchorPositioning;
276
+ var declarations = [
277
+ // Rule 3: both caps are always written. Only the placement axis can take the
278
+ // cell cap.
279
+ {
280
+ property: "max-".concat(placementAxis, "-size"),
281
+ value: size[placementAxis] === 'max-available' && isUsingCssAnchorPositioning ? cellCap({
282
+ gap: placement.offset.gap
283
+ }) : viewportCap({
284
+ axis: placementAxis,
285
+ writingMode: writingMode
286
+ })
287
+ }, {
288
+ property: "max-".concat(crossAxis, "-size"),
289
+ value: viewportCap({
290
+ axis: crossAxis,
291
+ writingMode: writingMode
292
+ })
293
+ }];
294
+
295
+ // Rule 4. Only for a non-anchor-relative inline axis, so `'match-anchor'` below
296
+ // stays the one writer of `inline-size` when it applies. CSS path only: the
297
+ // fallback's containing block is the viewport, where shrink-to-fit already IS
298
+ // the natural width for anything that fits on screen.
299
+ if (isUsingCssAnchorPositioning && !shouldPreserveInlineSize && (size.inline === 'content' || size.inline === 'max-available')) {
300
+ declarations.push({
301
+ property: 'inline-size',
302
+ value: 'max-content'
303
+ });
304
+ }
305
+
306
+ // A max beats a definite size, so the caps above still win over this.
307
+ for (var _i = 0, _arr = [placementAxis, crossAxis]; _i < _arr.length; _i++) {
308
+ var axis = _arr[_i];
309
+ var anchorValue = anchorSize[axis];
310
+ if (size[axis] === 'match-anchor' && anchorValue !== null) {
311
+ declarations.push({
312
+ property: "".concat(axis, "-size"),
313
+ value: anchorValue
314
+ });
315
+ }
316
+ }
317
+ var placementAxisFloor = getPlacementAxisFloor({
318
+ minSize: placement.minSize,
319
+ placementAxis: placementAxis,
320
+ placementAxisSize: size[placementAxis],
321
+ anchorValue: anchorSize[placementAxis],
322
+ gap: placement.offset.gap,
323
+ canFlip: canFlip,
324
+ writingMode: writingMode
325
+ });
326
+ if (placementAxisFloor !== undefined) {
327
+ declarations.push({
328
+ property: "min-".concat(placementAxis, "-size"),
329
+ value: placementAxisFloor
330
+ });
331
+ }
332
+
333
+ // A size contract, not a flip driver, so it is clamped to the cap.
334
+ var crossAxisAnchorValue = anchorSize[crossAxis];
335
+ if (size[crossAxis] === 'min-anchor' && crossAxisAnchorValue !== null) {
336
+ declarations.push({
337
+ property: "min-".concat(crossAxis, "-size"),
338
+ value: "min(".concat(crossAxisAnchorValue, ", ").concat(viewportCap({
339
+ axis: crossAxis,
340
+ writingMode: writingMode
341
+ }), ")")
342
+ });
343
+ }
344
+ return declarations;
345
+ }
@@ -14,25 +14,19 @@ exports.getAriaForTrigger = getAriaForTrigger;
14
14
  */
15
15
 
16
16
  /**
17
- * Valid values for the `aria-haspopup` attribute.
17
+ * Maps each supported popover role to its `aria-haspopup` value.
18
18
  *
19
19
  * Derived from the HTML spec - maps popover roles to what the trigger
20
- * announces. `undefined` means the attribute is omitted entirely (used for
20
+ * announces. Roles that do not produce a popup use `undefined` instead (for
21
21
  * non-popup roles like `tooltip`/`status`/`alert`/`note`/`log` where
22
- * `aria-haspopup` would be misleading).
22
+ * `aria-haspopup` would be misleading), so they are intentionally excluded
23
+ * from this mapping and from `getAriaForTrigger`.
23
24
  *
24
- * `true` is intentionally NOT in the union - the runtime only ever produces
25
- * the explicit string forms, so widening the type would invite consumers to
26
- * pass `true` and get an `aria-haspopup="true"` serialisation that the
25
+ * `true` is intentionally not a value in this mapping. The runtime only ever
26
+ * produces the explicit string forms, so allowing it would invite consumers
27
+ * to pass `true` and get an `aria-haspopup="true"` serialisation that the
27
28
  * runtime no longer emits.
28
29
  */
29
-
30
- /**
31
- * Non-undefined subset of `TAriaHasPopupValue`. Every role accepted by
32
- * `getAriaForTrigger` maps to a concrete `aria-haspopup` string, so the
33
- * trigger always receives a defined attribute value.
34
- */
35
-
36
30
  var roleToAriaHasPopup = {
37
31
  dialog: 'dialog',
38
32
  alertdialog: 'dialog',
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isNativeElementOpen = isNativeElementOpen;
7
+ function isNativeElementOpen(_ref) {
8
+ var element = _ref.element;
9
+ if (element instanceof HTMLDialogElement) {
10
+ return element.open;
11
+ }
12
+
13
+ // Some DOM implementations throw for unsupported pseudo-classes.
14
+ try {
15
+ return element.matches(':popover-open');
16
+ } catch (_unused) {
17
+ return false;
18
+ }
19
+ }
@@ -8,29 +8,14 @@ exports.computeFallbackPosition = computeFallbackPosition;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
- /**
12
- * JS fallback positioning math. Used only when the browser does not
13
- * support CSS Anchor Positioning (less than 6% of users).
14
- *
15
- * Consumer-supplied `offset.gap` and `offset.crossAxisShift` are
16
- * honored: the caller (`useAnchorPosition`) resolves CSS length strings
17
- * (tokens, calc, var, etc) to pixels via a DOM probe before passing them
18
- * in. The caller also keeps the popover hidden (`opacity: 0`) until the
19
- * first measurement completes, so the popover never paints at the wrong
20
- * position.
21
- */
22
-
23
11
  /**
24
12
  * A viewport-relative position, in pixels. Physical rather than logical
25
13
  * because it is written straight to `top` / `left`.
26
14
  */
27
15
 
28
16
  /**
29
- * The cross-axis shift with its length already resolved to pixels.
30
- *
31
- * Mirrors `TCrossAxisShiftOffset`, whose `value` is an unresolved CSS length
32
- * string. Only this module needs the pixel form, because only this module does
33
- * the arithmetic itself.
17
+ * `TCrossAxisShiftOffset` with its CSS length already resolved to pixels. Only
18
+ * this module needs the pixel form, because only this module does arithmetic.
34
19
  */
35
20
 
36
21
  /**
@@ -141,18 +126,13 @@ function applyAlignment(_ref2) {
141
126
  }
142
127
 
143
128
  /**
144
- * Applies the cross-axis shift offset.
145
- *
146
- * `forwards` always moves the popover toward the cross-axis END and
147
- * `backwards` toward the START, for every `align` value. See
148
- * `notes/decisions/placement-offset.md`.
129
+ * Applies the cross-axis shift offset. `forwards` always moves the popover
130
+ * toward the cross-axis END, for every `align` value.
149
131
  *
150
- * This is a coordinate, so the direction is the sign and nothing else. There
151
- * is deliberately no per-`align` sign inversion here: the CSS path inverts the
152
- * sign only because a margin on the END side pushes a box the opposite way to
153
- * a margin on the START side, which is a property of margins rather than of
154
- * the shift. Applying that inversion to a coordinate moved `align: 'end'`
155
- * popovers the wrong way.
132
+ * Do not add a per-`align` sign inversion here. This is a coordinate, so the
133
+ * direction is the sign and nothing else. The CSS path inverts only because an
134
+ * END-side margin pushes a box the opposite way to a START-side one, which is a
135
+ * property of margins.
156
136
  */
157
137
  function applyCrossAxisShift(_ref3) {
158
138
  var position = _ref3.position,
@@ -176,12 +156,11 @@ function applyCrossAxisShift(_ref3) {
176
156
  }
177
157
 
178
158
  /**
179
- * Computes popover position from trigger rect and viewport, flipping to
180
- * the side with more space when needed. Re-runs on scroll/resize.
159
+ * Computes the popover position from the trigger rect and viewport, flipping to
160
+ * the side with more space when needed.
181
161
  *
182
- * `gap` and `crossAxisShift` are pre-resolved to pixels by the
183
- * caller (see `resolveCssLengthToPixels`), so this function stays purely
184
- * numeric.
162
+ * `gap` and `crossAxisShift` arrive already resolved to pixels (see
163
+ * `resolveCssLengthToPixels`), so this stays purely numeric.
185
164
  */
186
165
  function computeFallbackPosition(_ref4) {
187
166
  var triggerRect = _ref4.triggerRect,