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