@fluentui/react-positioning 9.75.1-experimental.css-modules.20261103-d6c85ee2a9.0 → 9.75.1-experimental.positioning-engine.20261103-19efe125d1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -7
- package/README.md +130 -7
- package/lib/PositioningConfigurationContext.js +1 -2
- package/lib/PositioningConfigurationContext.js.map +1 -1
- package/lib/createPositionManager.js +74 -82
- package/lib/createPositionManager.js.map +1 -1
- package/lib/engine/computePosition.js +258 -0
- package/lib/engine/computePosition.js.map +1 -0
- package/lib/engine/index.js +260 -0
- package/lib/engine/index.js.map +1 -0
- package/lib/engine/platform.js +209 -0
- package/lib/engine/platform.js.map +1 -0
- package/lib/middleware/flip.js +1 -1
- package/lib/middleware/flip.js.map +1 -1
- package/lib/middleware/intersecting.js +1 -1
- package/lib/middleware/intersecting.js.map +1 -1
- package/lib/middleware/maxSize.js +1 -1
- package/lib/middleware/maxSize.js.map +1 -1
- package/lib/middleware/offset.js +1 -1
- package/lib/middleware/offset.js.map +1 -1
- package/lib/middleware/shift.js +1 -1
- package/lib/middleware/shift.js.map +1 -1
- package/lib/usePositioning.js +38 -48
- package/lib/usePositioning.js.map +1 -1
- package/lib/usePositioning.raster.js +45 -0
- package/lib/usePositioning.raster.js.map +1 -0
- package/lib/usePositioningOptions.js +25 -117
- package/lib/usePositioningOptions.js.map +1 -1
- package/lib/utils/createResizeObserver.js +2 -2
- package/lib/utils/createResizeObserver.js.map +1 -1
- package/lib/utils/debounce.js +6 -13
- package/lib/utils/debounce.js.map +1 -1
- package/lib/utils/fromFloatingUIPlacement.js +10 -29
- package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
- package/lib/utils/getBoundary.js +8 -17
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/index.js +0 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/listScrollParents.js +12 -20
- package/lib/utils/listScrollParents.js.map +1 -1
- package/lib/utils/normalizeAutoSize.js +15 -22
- package/lib/utils/normalizeAutoSize.js.map +1 -1
- package/lib/utils/toFloatingUIPlacement.js +9 -26
- package/lib/utils/toFloatingUIPlacement.js.map +1 -1
- package/lib/utils/useCallbackRef.js +1 -10
- package/lib/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/PositioningConfigurationContext.cjs +1 -2
- package/lib-commonjs/PositioningConfigurationContext.cjs.map +1 -1
- package/lib-commonjs/createPositionManager.cjs +72 -80
- package/lib-commonjs/createPositionManager.cjs.map +1 -1
- package/lib-commonjs/engine/computePosition.cjs +265 -0
- package/lib-commonjs/engine/computePosition.cjs.map +1 -0
- package/lib-commonjs/engine/index.cjs +290 -0
- package/lib-commonjs/engine/index.cjs.map +1 -0
- package/lib-commonjs/engine/platform.cjs +264 -0
- package/lib-commonjs/engine/platform.cjs.map +1 -0
- package/lib-commonjs/middleware/flip.cjs +6 -6
- package/lib-commonjs/middleware/flip.cjs.map +1 -1
- package/lib-commonjs/middleware/intersecting.cjs +2 -2
- package/lib-commonjs/middleware/intersecting.cjs.map +1 -1
- package/lib-commonjs/middleware/maxSize.cjs +4 -4
- package/lib-commonjs/middleware/maxSize.cjs.map +1 -1
- package/lib-commonjs/middleware/offset.cjs +2 -2
- package/lib-commonjs/middleware/offset.cjs.map +1 -1
- package/lib-commonjs/middleware/shift.cjs +7 -7
- package/lib-commonjs/middleware/shift.cjs.map +1 -1
- package/lib-commonjs/usePositioning.cjs +37 -46
- package/lib-commonjs/usePositioning.cjs.map +1 -1
- package/lib-commonjs/usePositioning.raster.cjs +49 -0
- package/lib-commonjs/usePositioning.raster.cjs.map +1 -0
- package/lib-commonjs/usePositioningOptions.cjs +24 -112
- package/lib-commonjs/usePositioningOptions.cjs.map +1 -1
- package/lib-commonjs/utils/createResizeObserver.cjs +2 -2
- package/lib-commonjs/utils/createResizeObserver.cjs.map +1 -1
- package/lib-commonjs/utils/debounce.cjs +6 -13
- package/lib-commonjs/utils/debounce.cjs.map +1 -1
- package/lib-commonjs/utils/fromFloatingUIPlacement.cjs +21 -32
- package/lib-commonjs/utils/fromFloatingUIPlacement.cjs.map +1 -1
- package/lib-commonjs/utils/getBoundary.cjs +8 -17
- package/lib-commonjs/utils/getBoundary.cjs.map +1 -1
- package/lib-commonjs/utils/index.cjs +0 -8
- package/lib-commonjs/utils/index.cjs.map +1 -1
- package/lib-commonjs/utils/listScrollParents.cjs +12 -20
- package/lib-commonjs/utils/listScrollParents.cjs.map +1 -1
- package/lib-commonjs/utils/normalizeAutoSize.cjs +26 -25
- package/lib-commonjs/utils/normalizeAutoSize.cjs.map +1 -1
- package/lib-commonjs/utils/toFloatingUIPlacement.cjs +13 -27
- package/lib-commonjs/utils/toFloatingUIPlacement.cjs.map +1 -1
- package/lib-commonjs/utils/useCallbackRef.cjs +1 -9
- package/lib-commonjs/utils/useCallbackRef.cjs.map +1 -1
- package/package.json +5 -9
- package/lib/Arrow.module.css +0 -45
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.module.css +0 -28
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.css.js +0 -9
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.css.js.map +0 -1
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.js +0 -9
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.js.map +0 -1
- package/lib/utils/writeArrowUpdates.js +0 -13
- package/lib/utils/writeArrowUpdates.js.map +0 -1
- package/lib/utils/writeContainerupdates.js +0 -43
- package/lib/utils/writeContainerupdates.js.map +0 -1
- package/lib-commonjs/Arrow.module.css +0 -45
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.module.css +0 -28
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.css.cjs +0 -20
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.css.cjs.map +0 -1
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.cjs +0 -20
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.cjs.map +0 -1
- package/lib-commonjs/utils/writeArrowUpdates.cjs +0 -23
- package/lib-commonjs/utils/writeArrowUpdates.cjs.map +0 -1
- package/lib-commonjs/utils/writeContainerupdates.cjs +0 -51
- package/lib-commonjs/utils/writeContainerupdates.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-positioning
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on Tue, 03 Nov 2026 14:
|
|
3
|
+
<!-- This log was last generated on Tue, 03 Nov 2026 14:18:06 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## [9.75.1-experimental.
|
|
7
|
+
## [9.75.1-experimental.positioning-engine.20261103-19efe125d1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.75.1-experimental.positioning-engine.20261103-19efe125d1.0)
|
|
8
8
|
|
|
9
|
-
Tue, 03 Nov 2026 14:
|
|
9
|
+
Tue, 03 Nov 2026 14:18:06 GMT
|
|
10
10
|
|
|
11
11
|
### Changes
|
|
12
12
|
|
|
13
|
-
- Release 9.75.1-experimental.
|
|
14
|
-
- Bump @fluentui/react-shared-contexts to v9.75.1-experimental.
|
|
15
|
-
- Bump @fluentui/react-theme to v9.75.1-experimental.
|
|
16
|
-
- Bump @fluentui/react-utilities to v9.75.1-experimental.
|
|
13
|
+
- Release 9.75.1-experimental.positioning-engine.20261103-19efe125d1 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by 257645319+office-ogx-auth-helper[bot]@users.noreply.github.com)
|
|
14
|
+
- Bump @fluentui/react-shared-contexts to v9.75.1-experimental.positioning-engine.20261103-19efe125d1.0 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
15
|
+
- Bump @fluentui/react-theme to v9.75.1-experimental.positioning-engine.20261103-19efe125d1.0 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
16
|
+
- Bump @fluentui/react-utilities to v9.75.1-experimental.positioning-engine.20261103-19efe125d1.0 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
17
17
|
|
|
18
18
|
## [9.23.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.23.4)
|
|
19
19
|
|
package/README.md
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# @fluentui/react-positioning
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
The opt-in `@fluentui/react-positioning/arrow.module.css` export requires a CSS
|
|
8
|
-
Modules loader. It is excluded from Are the Types Wrong's JavaScript entry-point
|
|
9
|
-
checks in `.attw.json`; the package's JavaScript exports remain checked.
|
|
3
|
+
React utilities for positioning elements in the DOM, using a standalone JavaScript engine.
|
|
4
|
+
The fallback preserves the existing Floating UI-based hook's placement and configuration semantics
|
|
5
|
+
without importing the Floating UI engine at runtime.
|
|
10
6
|
|
|
11
7
|
## Usage
|
|
12
8
|
|
|
@@ -29,3 +25,130 @@ const PopupExample: React.FC = ({ children }) => {
|
|
|
29
25
|
);
|
|
30
26
|
};
|
|
31
27
|
```
|
|
28
|
+
|
|
29
|
+
## Browser behavior contracts
|
|
30
|
+
|
|
31
|
+
`src/usePositioning.geometry.cy.tsx` exercises the public hook with real DOM layout and the
|
|
32
|
+
unmocked positioning engine. Run it through the existing component-test target:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
yarn nx run react-positioning:e2e --spec=src/usePositioning.geometry.cy.tsx --browser=electron --config=retries=0
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The committed expectations in `src/usePositioning.geometry-baseline.cy.ts` were captured from
|
|
39
|
+
master baseline `f626209351609e43bc98eb8cc1296273faa679b7` using Cypress 14.4.1 / Electron 130
|
|
40
|
+
at an 800-by-600 viewport. They pin exact CSS-pixel rectangles, placement, strategy, transform
|
|
41
|
+
serialization, left/top, maximum sizes, arrow coordinates, visibility attributes, match-target
|
|
42
|
+
CSS variable, and overflow styles. No tolerance or engine-derived expected coordinates are used.
|
|
43
|
+
The baseline helper only expands literal expected values. Engine replacements must pass these
|
|
44
|
+
expectations, not regenerate them.
|
|
45
|
+
|
|
46
|
+
For fractional DPR cases with transforms disabled, only rectangle x/y are compared to an
|
|
47
|
+
engine-free sibling positioned with the committed literal left/top values. Native layout
|
|
48
|
+
quantization is host-dependent: Electron 130 lays out `280.667px` at `280.6640625` on the
|
|
49
|
+
original macOS host but at `280.65625` on Linux CI. Both are distinct from device-pixel rounding
|
|
50
|
+
performed by the engine. The sibling runs no positioning logic and never reads engine output;
|
|
51
|
+
all inline styles, dimensions, placement, and other fields remain exact literal assertions.
|
|
52
|
+
The original rectangle snapshots are retained as provenance, not regenerated for each host.
|
|
53
|
+
Negative-control tests at DPR 1.5 and 3 reject a `0.001px` left/top change even when native
|
|
54
|
+
layout produces the same rectangle, and reject displaced rectangles with unchanged left/top.
|
|
55
|
+
|
|
56
|
+
Coverage includes the finite 4-position by 5-alignment by 2-direction matrix (including invalid
|
|
57
|
+
axis combinations), edge flips, ordered fallbacks and best fit, pinned shifting, tether options,
|
|
58
|
+
shift-to-cover limits, number/object/function offsets, arrows, rectangular/element/intersected
|
|
59
|
+
element-array/window/scroll/clipping boundaries, independent flip/overflow boundaries, logical
|
|
60
|
+
padding, auto-size aliases, target-width matching, target covering, containing-block scaling and
|
|
61
|
+
transforms, virtual targets, and fractional rectangles at DPR 1, 1.25, 1.5, 2, and 3. DPR is
|
|
62
|
+
controlled independently of the host display; geometry and the engine are never mocked.
|
|
63
|
+
Scrollbars are hidden without disabling scrolling so native scrollbar widths do not alter the fixture.
|
|
64
|
+
The fixture includes a scoped `::-webkit-scrollbar` rule for the older Chromium bundled with
|
|
65
|
+
Cypress 13 in React 17 compatibility tests, which does not support `scrollbar-width`.
|
|
66
|
+
|
|
67
|
+
Lifecycle cases cover imperative updates and retargeting, target prop removal, option removal,
|
|
68
|
+
enable/disable, resize and scroll updates, visibility recovery, native end events, detached
|
|
69
|
+
container cleanup, idle behavior, and inline end callbacks that update React state. A safety cap
|
|
70
|
+
on the state-updating callback makes an update loop fail without hanging the browser.
|
|
71
|
+
|
|
72
|
+
These are geometry contracts, not screenshot rasterization baselines or a claim of every
|
|
73
|
+
possible combination. Font rasterization, browser zoom, native high-DPI capture, cross-browser
|
|
74
|
+
layout differences and native visual-viewport/mobile behavior are not
|
|
75
|
+
covered. The explicit `strategy: 'absolute'` case deliberately records the existing baseline's
|
|
76
|
+
`fixed` result; changing that behavior requires a separate intentional compatibility decision.
|
|
77
|
+
|
|
78
|
+
`src/usePositioning.regressions.cy.tsx` adds focused real-browser checks for individual CSS
|
|
79
|
+
transforms, shadow-host containing blocks and clipping, boxless overflow ancestors, fixed
|
|
80
|
+
surfaces inside absolute wrappers, and bordered/padded/scaled same-origin iframe references.
|
|
81
|
+
It also covers boolean/all disabled-tether limiting, assigned-slot ancestry, SVG virtual-reference
|
|
82
|
+
clipping, viewport-propagated body overflow, top-layer popovers and modal dialogs and their
|
|
83
|
+
descendants, and positioned `display: contents` ancestors in scrolled documents.
|
|
84
|
+
These cases compare against Floating UI where supported. Individual transform properties predate
|
|
85
|
+
support in the pinned oracle, so those cases instead assert physical target/surface alignment.
|
|
86
|
+
|
|
87
|
+
## Engine parity, size and performance validation
|
|
88
|
+
|
|
89
|
+
The engine measures in containing-block CSS pixels and resolves matching, offsets, covering,
|
|
90
|
+
best-fit flipping, shifting/tethering, available-size constraints, arrows, and visibility in order.
|
|
91
|
+
Positioning callbacks and imperative refs do not recreate the manager on callback-only rerenders.
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
yarn nx run react-positioning:bundle-size --skip-nx-cache
|
|
95
|
+
yarn nx run react-positioning:test-bundle-size
|
|
96
|
+
yarn nx run react-positioning:test-raster
|
|
97
|
+
yarn nx run react-positioning:benchmark
|
|
98
|
+
yarn nx run react-positioning:test-webkit
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The bundle gate runs the repository's monosize/webpack measurement for the existing
|
|
102
|
+
`bundle-size/usePopper.fixture.js` entry, labeled `usePositioning`, and rejects an actual
|
|
103
|
+
minified output larger than **12,000 bytes**. This is an absolute, uncompressed limit; gzip
|
|
104
|
+
is reported separately. Gate tests cover the inclusive limit and invalid or stale measurements.
|
|
105
|
+
|
|
106
|
+
The WebKit target runs focused real-browser checks for filtered ancestors and nested
|
|
107
|
+
top-layer surfaces. Filter cases preserve the pinned Floating UI WebKit exception; nested
|
|
108
|
+
top-layer cases assert physical layout, including containment by the top-layer ancestor itself.
|
|
109
|
+
It requires the workspace's Playwright WebKit browser installation.
|
|
110
|
+
It also compares fixed/absolute positioning, containing blocks, and rectangular boundaries
|
|
111
|
+
against Floating UI with controlled visual-viewport offsets. Element geometry remains real;
|
|
112
|
+
the viewport metrics are emulated, so these checks do not replace native pinch-zoom/pan testing.
|
|
113
|
+
|
|
114
|
+
The package is compiled to ES2019, so the engine avoids optional chaining and nullish coalescing
|
|
115
|
+
in hot paths (they are lowered to verbose helpers), prefers expression-bodied helpers, and keeps
|
|
116
|
+
DOM traversal in one place (`src/engine/platform.ts`) that the scroll-parent listing reuses.
|
|
117
|
+
|
|
118
|
+
The raster target extracts the unchanged lower-PR source from
|
|
119
|
+
`788e3b739fe79246a2f8850d1c575cf4018fd744` into a temporary directory, then runs the same
|
|
120
|
+
contracts against that implementation and the replacement in Electron. A paint-only wrapper
|
|
121
|
+
makes otherwise transparent fixtures visible without changing their layout. It compares every
|
|
122
|
+
decoded RGBA pixel, including antialiasing, and writes its report to
|
|
123
|
+
`dist/positioning-raster/comparison.json`. It does not update the pinned geometry expectations.
|
|
124
|
+
This is bounded fixture coverage on the same browser and host display, not a guarantee of all
|
|
125
|
+
option combinations, fonts, browsers, iframe/shadow-root targets, or mobile visual viewports.
|
|
126
|
+
|
|
127
|
+
The performance target mounts 24 concurrent positioning instances per engine in the same Electron
|
|
128
|
+
browser and compares against the unchanged Floating UI implementation from upstream lower PR
|
|
129
|
+
`fca219991ed9e907b01274bd89ac1431e51c573a`.
|
|
130
|
+
It mounts only one engine at a time, warms up both engines, randomizes workload order, and randomizes
|
|
131
|
+
which engine runs first in every pair, including initialization. The inactive engine is unmounted
|
|
132
|
+
and its listeners are disposed before timing, so global events cannot contaminate the other
|
|
133
|
+
engine's samples. The mix includes flips/fallbacks, explicit boundaries, arrows, offsets, and
|
|
134
|
+
autosizing. It measures completion through the actual `usePositioning` end-event path; setup is
|
|
135
|
+
excluded from update timings, while initialization intentionally includes mount-to-all-positioned.
|
|
136
|
+
|
|
137
|
+
Every workload runs in two layouts:
|
|
138
|
+
|
|
139
|
+
- `flat`: targets are fixed children of the body, the cheapest case for ancestor traversal.
|
|
140
|
+
- `nested`: targets are 12 levels deep inside a scroll container and surfaces are portaled to the
|
|
141
|
+
end of the document, the common application shape. It exercises clipping, containing-block and
|
|
142
|
+
scroll-parent traversal, and its `scroll` workload dispatches element scroll events that reach
|
|
143
|
+
the managers through their scroll-parent listeners rather than the window listener.
|
|
144
|
+
|
|
145
|
+
Each layout records paired initialization, imperative, scroll, and window-resize completion
|
|
146
|
+
times. The script reports per-workload median, p95, p10/p90 and coefficient of variation for both
|
|
147
|
+
engines, and the paired replacement/oracle ratios as a geometric mean with a seeded bootstrap 95%
|
|
148
|
+
confidence interval (an interval entirely below 1 means the replacement is faster on that host).
|
|
149
|
+
It enforces complete, finite, nonzero samples but intentionally has no machine-dependent
|
|
150
|
+
performance pass/fail threshold. Run it on the same host/browser for meaningful comparisons.
|
|
151
|
+
Set `POSITIONING_BENCH_SEED` to reproduce or vary the randomized order. The full samples,
|
|
152
|
+
statistics and browser/machine metadata (including whether the engine had uncommitted changes)
|
|
153
|
+
are written to `dist/positioning-perf/benchmark.json`, and a Markdown table for pull request
|
|
154
|
+
descriptions to `dist/positioning-perf/summary.md`.
|
|
@@ -12,6 +12,5 @@ const PositioningConfigurationContext = React.createContext(undefined);
|
|
|
12
12
|
* Accepts a function that takes the positioning options and returns them modified.
|
|
13
13
|
*/ export const PositioningConfigurationProvider = PositioningConfigurationContext.Provider;
|
|
14
14
|
export const usePositioningConfiguration = ()=>{
|
|
15
|
-
|
|
16
|
-
return (_React_useContext = React.useContext(PositioningConfigurationContext)) !== null && _React_useContext !== void 0 ? _React_useContext : DEFAULT_CONFIGURATION;
|
|
15
|
+
return React.useContext(PositioningConfigurationContext) || DEFAULT_CONFIGURATION;
|
|
17
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/PositioningConfigurationContext.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { PositioningConfigurationFn } from './types';\n\n// ---\n\nconst DEFAULT_CONFIGURATION: PositioningConfigurationFn = ({ options }) => {\n return options;\n};\n\n// ---\n\nconst PositioningConfigurationContext = React.createContext<PositioningConfigurationFn | undefined>(undefined);\n\n/**\n * A context provider for the positioning configuration.\n *\n * Accepts a function that takes the positioning options and returns them modified.\n */\nexport const PositioningConfigurationProvider = PositioningConfigurationContext.Provider;\n\nexport const usePositioningConfiguration = (): PositioningConfigurationFn => {\n return React.useContext(PositioningConfigurationContext)
|
|
1
|
+
{"version":3,"sources":["../src/PositioningConfigurationContext.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { PositioningConfigurationFn } from './types';\n\n// ---\n\nconst DEFAULT_CONFIGURATION: PositioningConfigurationFn = ({ options }) => {\n return options;\n};\n\n// ---\n\nconst PositioningConfigurationContext = React.createContext<PositioningConfigurationFn | undefined>(undefined);\n\n/**\n * A context provider for the positioning configuration.\n *\n * Accepts a function that takes the positioning options and returns them modified.\n */\nexport const PositioningConfigurationProvider = PositioningConfigurationContext.Provider;\n\nexport const usePositioningConfiguration = (): PositioningConfigurationFn => {\n return React.useContext(PositioningConfigurationContext) || DEFAULT_CONFIGURATION;\n};\n"],"names":["React","DEFAULT_CONFIGURATION","options","PositioningConfigurationContext","createContext","undefined","PositioningConfigurationProvider","Provider","usePositioningConfiguration","useContext"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAG/B,MAAM;AAEN,MAAMC,wBAAoD,CAAC,EAAEC,OAAO,EAAE;IACpE,OAAOA;AACT;AAEA,MAAM;AAEN,MAAMC,kCAAkCH,MAAMI,aAAa,CAAyCC;AAEpG;;;;CAIC,GACD,OAAO,MAAMC,mCAAmCH,gCAAgCI,QAAQ,CAAC;AAEzF,OAAO,MAAMC,8BAA8B;IACzC,OAAOR,MAAMS,UAAU,CAACN,oCAAoCF;AAC9D,EAAE"}
|
|
@@ -1,39 +1,54 @@
|
|
|
1
|
-
import { computePosition } from "
|
|
1
|
+
import { computePosition } from "./engine/computePosition.js";
|
|
2
|
+
import { getWindow, px } from "./engine/platform.js";
|
|
2
3
|
import { isHTMLElement } from "@fluentui/react-utilities";
|
|
3
|
-
import { debounce
|
|
4
|
+
import { debounce } from "./utils/index.js";
|
|
4
5
|
import { listScrollParents } from "./utils/listScrollParents.js";
|
|
5
|
-
import { POSITIONING_END_EVENT } from "./constants.js";
|
|
6
|
+
import { DATA_POSITIONING_ESCAPED, DATA_POSITIONING_HIDDEN, DATA_POSITIONING_INTERSECTING, DATA_POSITIONING_PLACEMENT, POSITIONING_END_EVENT } from "./constants.js";
|
|
6
7
|
import { createResizeObserver } from "./utils/createResizeObserver.js";
|
|
7
|
-
function isLayoutViewportUnavailable(container) {
|
|
8
|
-
const { clientWidth, clientHeight } = container.ownerDocument.documentElement;
|
|
9
|
-
return clientWidth === 0 && clientHeight === 0;
|
|
10
|
-
}
|
|
11
8
|
/**
|
|
12
9
|
* @internal
|
|
13
10
|
* @returns manager that handles positioning out of the react lifecycle
|
|
14
|
-
*/ export function createPositionManager(
|
|
11
|
+
*/ export function createPositionManager(managerOptions) {
|
|
15
12
|
let isDestroyed = false;
|
|
16
|
-
const { container, target, arrow, strategy,
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const { container, target, arrow, strategy, options = {} } = managerOptions;
|
|
14
|
+
// Modifies whether the container is positioned using transform
|
|
15
|
+
const { useTransform = true, disableUpdateOnResize } = options;
|
|
16
|
+
const targetWindow = getWindow(container);
|
|
17
|
+
// Containers of documents without a window (e.g. `DOMParser`) can't be positioned
|
|
18
|
+
if (!targetWindow) {
|
|
19
|
+
const noop = ()=>undefined;
|
|
19
20
|
return {
|
|
20
|
-
updatePosition:
|
|
21
|
-
dispose:
|
|
21
|
+
updatePosition: noop,
|
|
22
|
+
dispose: noop
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
// When the dimensions of the target or the container change - trigger a position update
|
|
25
|
+
// When the dimensions of the target or the container change - trigger a position update,
|
|
26
|
+
// unless disabled by the `disableUpdateOnResize` option
|
|
25
27
|
const resizeObserver = disableUpdateOnResize ? null : createResizeObserver(targetWindow, (entries)=>{
|
|
26
28
|
// If content rect dimensions to go 0 -> very likely that `display: none` is being used to hide the element
|
|
27
29
|
// In this case don't update and let users update imperatively
|
|
28
|
-
|
|
29
|
-
return entry.contentRect.width > 0 && entry.contentRect.height > 0;
|
|
30
|
-
});
|
|
31
|
-
if (shouldUpdateOnResize) {
|
|
30
|
+
if (entries.every((entry)=>entry.contentRect.width > 0 && entry.contentRect.height > 0)) {
|
|
32
31
|
updatePosition();
|
|
33
32
|
}
|
|
34
33
|
});
|
|
35
34
|
let isFirstUpdate = true;
|
|
36
|
-
|
|
35
|
+
// The window and the scroll parents of the container and the target, the target is only observed
|
|
36
|
+
// when it is an element as virtual elements are not part of the DOM
|
|
37
|
+
const scrollTargets = new Set([
|
|
38
|
+
targetWindow
|
|
39
|
+
]);
|
|
40
|
+
const elements = isHTMLElement(target) ? [
|
|
41
|
+
container,
|
|
42
|
+
target
|
|
43
|
+
] : [
|
|
44
|
+
container
|
|
45
|
+
];
|
|
46
|
+
const listenToScroll = (scrollTarget)=>{
|
|
47
|
+
scrollTargets.add(scrollTarget);
|
|
48
|
+
scrollTarget.addEventListener('scroll', updatePosition, {
|
|
49
|
+
passive: true
|
|
50
|
+
});
|
|
51
|
+
};
|
|
37
52
|
// When the container is first resolved, set position `fixed` to avoid scroll jumps.
|
|
38
53
|
// Without this scroll jumps can occur when the element is rendered initially and receives focus
|
|
39
54
|
Object.assign(container.style, {
|
|
@@ -49,68 +64,52 @@ function isLayoutViewportUnavailable(container) {
|
|
|
49
64
|
return;
|
|
50
65
|
}
|
|
51
66
|
if (isFirstUpdate) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
scrollParents.forEach((scrollParent)=>{
|
|
57
|
-
scrollParent.addEventListener('scroll', updatePosition, {
|
|
58
|
-
passive: true
|
|
59
|
-
});
|
|
67
|
+
elements.forEach((element)=>{
|
|
68
|
+
listScrollParents(element).forEach(listenToScroll);
|
|
69
|
+
resizeObserver && resizeObserver.observe(element);
|
|
60
70
|
});
|
|
61
|
-
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(container);
|
|
62
|
-
if (isHTMLElement(target)) {
|
|
63
|
-
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(target);
|
|
64
|
-
}
|
|
65
71
|
isFirstUpdate = false;
|
|
66
72
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
computePosition(target, container, {
|
|
71
|
-
placement,
|
|
72
|
-
middleware,
|
|
73
|
-
strategy
|
|
74
|
-
}).then(({ x, y, middlewareData, placement: computedPlacement })=>{
|
|
75
|
-
var _ref, _ref1;
|
|
76
|
-
var _positioningMiddlewareData_hide, _positioningMiddlewareData_hide1;
|
|
73
|
+
container.style.position = strategy;
|
|
74
|
+
computePosition(target, container, managerOptions).then(({ x, y, placement, arrow: arrowCoordinates, intersecting, escaped, referenceHidden })=>{
|
|
77
75
|
// Promise can still resolve after destruction
|
|
78
76
|
// early return to avoid applying outdated position
|
|
79
77
|
if (isDestroyed) {
|
|
80
78
|
return;
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
80
|
+
if (arrow && arrowCoordinates) {
|
|
81
|
+
Object.assign(arrow.style, {
|
|
82
|
+
left: px(arrowCoordinates.x),
|
|
83
|
+
top: px(arrowCoordinates.y)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
container.setAttribute(DATA_POSITIONING_PLACEMENT, placement);
|
|
87
|
+
container.toggleAttribute(DATA_POSITIONING_INTERSECTING, intersecting);
|
|
88
|
+
container.toggleAttribute(DATA_POSITIONING_ESCAPED, escaped);
|
|
89
|
+
container.toggleAttribute(DATA_POSITIONING_HIDDEN, referenceHidden);
|
|
90
|
+
// Round so that the coordinates land on device pixels.
|
|
91
|
+
// This prevents blurriness in cases where the browser doesn't apply pixel snapping, such as when other
|
|
92
|
+
// effects like `backdrop-filter: blur()` are applied to the container, and the browser is zoomed in.
|
|
93
|
+
// See https://github.com/microsoft/fluentui/issues/26764 for more info.
|
|
94
|
+
const devicePixelRatio = targetWindow.devicePixelRatio || 1;
|
|
95
|
+
const left = px(Math.round(x * devicePixelRatio) / devicePixelRatio);
|
|
96
|
+
const top = px(Math.round(y * devicePixelRatio) / devicePixelRatio);
|
|
97
|
+
Object.assign(container.style, useTransform ? {
|
|
98
|
+
// Layer acceleration can disable subpixel rendering which causes slightly
|
|
99
|
+
// blurry text on low PPI displays, so we want to use 2D transforms instead
|
|
100
|
+
transform: devicePixelRatio <= 1 ? `translate(${left}, ${top})` : `translate3d(${left}, ${top}, 0)`
|
|
101
|
+
} : {
|
|
102
|
+
left,
|
|
103
|
+
top
|
|
105
104
|
});
|
|
106
105
|
container.dispatchEvent(new CustomEvent(POSITIONING_END_EVENT, {
|
|
107
106
|
detail: {
|
|
108
107
|
// Cast from Floating UI's Placement to the Fluent-owned PositioningPlacement.
|
|
109
108
|
// These are equivalent string unions; the cast avoids leaking @floating-ui/dom
|
|
110
109
|
// types into the public API surface.
|
|
111
|
-
placement:
|
|
112
|
-
escaped
|
|
113
|
-
referenceHidden
|
|
110
|
+
placement: placement,
|
|
111
|
+
escaped,
|
|
112
|
+
referenceHidden
|
|
114
113
|
}
|
|
115
114
|
}));
|
|
116
115
|
}).catch((err)=>{
|
|
@@ -127,25 +126,18 @@ function isLayoutViewportUnavailable(container) {
|
|
|
127
126
|
}
|
|
128
127
|
});
|
|
129
128
|
};
|
|
130
|
-
const updatePosition = debounce(
|
|
129
|
+
const updatePosition = debounce(forceUpdate);
|
|
131
130
|
const dispose = ()=>{
|
|
132
131
|
isDestroyed = true;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
scrollParents.forEach((scrollParent)=>{
|
|
138
|
-
scrollParent.removeEventListener('scroll', updatePosition);
|
|
132
|
+
targetWindow.removeEventListener('resize', updatePosition);
|
|
133
|
+
scrollTargets.forEach((scrollTarget)=>{
|
|
134
|
+
scrollTarget.removeEventListener('scroll', updatePosition);
|
|
139
135
|
});
|
|
140
|
-
|
|
141
|
-
resizeObserver
|
|
136
|
+
scrollTargets.clear();
|
|
137
|
+
resizeObserver && resizeObserver.disconnect();
|
|
142
138
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
passive: true
|
|
146
|
-
});
|
|
147
|
-
targetWindow.addEventListener('resize', updatePosition);
|
|
148
|
-
}
|
|
139
|
+
listenToScroll(targetWindow);
|
|
140
|
+
targetWindow.addEventListener('resize', updatePosition);
|
|
149
141
|
// Update the position on initialization
|
|
150
142
|
updatePosition();
|
|
151
143
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createPositionManager.ts"],"sourcesContent":["import { computePosition } from '@floating-ui/dom';\nimport type { Middleware, Placement, Strategy } from '@floating-ui/dom';\nimport { isHTMLElement } from '@fluentui/react-utilities';\nimport type { OnPositioningEndEventDetail, PositionManager, PositioningPlacement, TargetElement } from './types';\nimport { debounce, writeArrowUpdates, writeContainerUpdates } from './utils';\nimport { listScrollParents } from './utils/listScrollParents';\nimport { POSITIONING_END_EVENT } from './constants';\nimport { createResizeObserver } from './utils/createResizeObserver';\n\ninterface PositionManagerOptions {\n /**\n * The positioned element\n */\n container: HTMLElement;\n /**\n * Element that the container will be anchored to\n */\n target: TargetElement;\n /**\n * Arrow that points from the container to the target\n */\n arrow: HTMLElement | null;\n /**\n * The value of the css `position` property\n * @default absolute\n */\n strategy: Strategy;\n /**\n * [Floating UI middleware](https://floating-ui.com/docs/middleware)\n */\n middleware: Middleware[];\n /**\n * [Floating UI placement](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: Placement;\n /**\n * Modifies whether popover is positioned using transform.\n * @default true\n */\n useTransform?: boolean;\n /**\n * Disables the resize observer that updates position on target or dimension change\n */\n disableUpdateOnResize?: boolean;\n}\n\nfunction isLayoutViewportUnavailable(container: HTMLElement): boolean {\n const { clientWidth, clientHeight } = container.ownerDocument.documentElement;\n\n return clientWidth === 0 && clientHeight === 0;\n}\n\n/**\n * @internal\n * @returns manager that handles positioning out of the react lifecycle\n */\nexport function createPositionManager(options: PositionManagerOptions): PositionManager {\n let isDestroyed = false;\n const {\n container,\n target,\n arrow,\n strategy,\n middleware,\n placement,\n useTransform = true,\n disableUpdateOnResize = false,\n } = options;\n const targetWindow = container.ownerDocument.defaultView;\n if (!target || !container || !targetWindow) {\n return {\n updatePosition: () => undefined,\n dispose: () => undefined,\n };\n }\n\n // When the dimensions of the target or the container change - trigger a position update\n const resizeObserver = disableUpdateOnResize\n ? null\n : createResizeObserver(targetWindow, entries => {\n // If content rect dimensions to go 0 -> very likely that `display: none` is being used to hide the element\n // In this case don't update and let users update imperatively\n const shouldUpdateOnResize = entries.every(entry => {\n return entry.contentRect.width > 0 && entry.contentRect.height > 0;\n });\n\n if (shouldUpdateOnResize) {\n updatePosition();\n }\n });\n\n let isFirstUpdate = true;\n const scrollParents: Set<HTMLElement> = new Set<HTMLElement>();\n\n // When the container is first resolved, set position `fixed` to avoid scroll jumps.\n // Without this scroll jumps can occur when the element is rendered initially and receives focus\n Object.assign(container.style, { position: 'fixed', left: 0, top: 0, margin: 0 });\n\n const forceUpdate = () => {\n // debounced update can still occur afterwards\n // early return to avoid memory leaks\n if (isDestroyed) {\n return;\n }\n\n if (isFirstUpdate) {\n listScrollParents(container).forEach(scrollParent => scrollParents.add(scrollParent));\n if (isHTMLElement(target)) {\n listScrollParents(target).forEach(scrollParent => scrollParents.add(scrollParent));\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.addEventListener('scroll', updatePosition, { passive: true });\n });\n\n resizeObserver?.observe(container);\n if (isHTMLElement(target)) {\n resizeObserver?.observe(target);\n }\n\n isFirstUpdate = false;\n }\n\n Object.assign(container.style, { position: strategy });\n computePosition(target, container, { placement, middleware, strategy })\n .then(({ x, y, middlewareData, placement: computedPlacement }) => {\n // Promise can still resolve after destruction\n // early return to avoid applying outdated position\n if (isDestroyed) {\n return;\n }\n\n const positioningMiddlewareData = isLayoutViewportUnavailable(container)\n ? {\n ...middlewareData,\n hide: { ...middlewareData.hide, escaped: false, referenceHidden: false },\n }\n : middlewareData;\n\n writeArrowUpdates({ arrow, middlewareData: positioningMiddlewareData });\n writeContainerUpdates({\n container,\n middlewareData: positioningMiddlewareData,\n placement: computedPlacement,\n coordinates: { x, y },\n lowPPI: (targetWindow?.devicePixelRatio || 1) <= 1,\n strategy,\n useTransform,\n });\n\n container.dispatchEvent(\n new CustomEvent<OnPositioningEndEventDetail>(POSITIONING_END_EVENT, {\n detail: {\n // Cast from Floating UI's Placement to the Fluent-owned PositioningPlacement.\n // These are equivalent string unions; the cast avoids leaking @floating-ui/dom\n // types into the public API surface.\n placement: computedPlacement satisfies PositioningPlacement,\n escaped: positioningMiddlewareData.hide?.escaped ?? false,\n referenceHidden: positioningMiddlewareData.hide?.referenceHidden ?? false,\n },\n }),\n );\n })\n .catch(err => {\n // https://github.com/floating-ui/floating-ui/issues/1845\n // FIXME for node > 14\n // node 15 introduces promise rejection which means that any components\n // tests need to be `it('', async () => {})` otherwise there can be race conditions with\n // JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist\n // Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing\n // will actually be counter productive\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.error('[usePositioning]: Failed to calculate position', err);\n }\n });\n };\n\n const updatePosition = debounce(() => forceUpdate());\n\n const dispose = () => {\n isDestroyed = true;\n\n if (targetWindow) {\n targetWindow.removeEventListener('scroll', updatePosition);\n targetWindow.removeEventListener('resize', updatePosition);\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.removeEventListener('scroll', updatePosition);\n });\n scrollParents.clear();\n\n resizeObserver?.disconnect();\n };\n\n if (targetWindow) {\n targetWindow.addEventListener('scroll', updatePosition, { passive: true });\n targetWindow.addEventListener('resize', updatePosition);\n }\n\n // Update the position on initialization\n updatePosition();\n\n return {\n updatePosition,\n dispose,\n };\n}\n"],"names":["computePosition","isHTMLElement","debounce","writeArrowUpdates","writeContainerUpdates","listScrollParents","POSITIONING_END_EVENT","createResizeObserver","isLayoutViewportUnavailable","container","clientWidth","clientHeight","ownerDocument","documentElement","createPositionManager","options","isDestroyed","target","arrow","strategy","middleware","placement","useTransform","disableUpdateOnResize","targetWindow","defaultView","updatePosition","undefined","dispose","resizeObserver","entries","shouldUpdateOnResize","every","entry","contentRect","width","height","isFirstUpdate","scrollParents","Set","Object","assign","style","position","left","top","margin","forceUpdate","forEach","scrollParent","add","addEventListener","passive","observe","then","x","y","middlewareData","computedPlacement","positioningMiddlewareData","hide","escaped","referenceHidden","coordinates","lowPPI","devicePixelRatio","dispatchEvent","CustomEvent","detail","catch","err","process","env","NODE_ENV","console","error","removeEventListener","clear","disconnect"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AAEnD,SAASC,aAAa,QAAQ,4BAA4B;AAE1D,SAASC,QAAQ,EAAEC,iBAAiB,EAAEC,qBAAqB,QAAQ,mBAAU;AAC7E,SAASC,iBAAiB,QAAQ,+BAA4B;AAC9D,SAASC,qBAAqB,QAAQ,iBAAc;AACpD,SAASC,oBAAoB,QAAQ,kCAA+B;AAuCpE,SAASC,4BAA4BC,SAAsB;IACzD,MAAM,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGF,UAAUG,aAAa,CAACC,eAAe;IAE7E,OAAOH,gBAAgB,KAAKC,iBAAiB;AAC/C;AAEA;;;CAGC,GACD,OAAO,SAASG,sBAAsBC,OAA+B;IACnE,IAAIC,cAAc;IAClB,MAAM,EACJP,SAAS,EACTQ,MAAM,EACNC,KAAK,EACLC,QAAQ,EACRC,UAAU,EACVC,SAAS,EACTC,eAAe,IAAI,EACnBC,wBAAwB,KAAK,EAC9B,GAAGR;IACJ,MAAMS,eAAef,UAAUG,aAAa,CAACa,WAAW;IACxD,IAAI,CAACR,UAAU,CAACR,aAAa,CAACe,cAAc;QAC1C,OAAO;YACLE,gBAAgB,IAAMC;YACtBC,SAAS,IAAMD;QACjB;IACF;IAEA,wFAAwF;IACxF,MAAME,iBAAiBN,wBACnB,OACAhB,qBAAqBiB,cAAcM,CAAAA;QACjC,2GAA2G;QAC3G,8DAA8D;QAC9D,MAAMC,uBAAuBD,QAAQE,KAAK,CAACC,CAAAA;YACzC,OAAOA,MAAMC,WAAW,CAACC,KAAK,GAAG,KAAKF,MAAMC,WAAW,CAACE,MAAM,GAAG;QACnE;QAEA,IAAIL,sBAAsB;YACxBL;QACF;IACF;IAEJ,IAAIW,gBAAgB;IACpB,MAAMC,gBAAkC,IAAIC;IAE5C,oFAAoF;IACpF,gGAAgG;IAChGC,OAAOC,MAAM,CAAChC,UAAUiC,KAAK,EAAE;QAAEC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ts"],"sourcesContent":["import { computePosition } from './engine/computePosition';\nimport { getWindow, px } from './engine/platform';\nimport type { Middleware, Placement, Strategy } from '@floating-ui/dom';\nimport { isHTMLElement } from '@fluentui/react-utilities';\nimport type {\n OnPositioningEndEventDetail,\n PositionManager,\n PositioningOptions,\n PositioningPlacement,\n TargetElement,\n} from './types';\nimport { debounce } from './utils';\nimport { listScrollParents } from './utils/listScrollParents';\nimport {\n DATA_POSITIONING_ESCAPED,\n DATA_POSITIONING_HIDDEN,\n DATA_POSITIONING_INTERSECTING,\n DATA_POSITIONING_PLACEMENT,\n POSITIONING_END_EVENT,\n} from './constants';\nimport { createResizeObserver } from './utils/createResizeObserver';\n\ninterface PositionManagerOptions {\n /**\n * The positioned element\n */\n container: HTMLElement;\n /**\n * Element that the container will be anchored to\n */\n target: TargetElement;\n /**\n * Arrow that points from the container to the target\n */\n arrow: HTMLElement | null;\n /**\n * The value of the css `position` property\n * @default absolute\n */\n strategy: Strategy;\n /**\n * [Floating UI middleware](https://floating-ui.com/docs/middleware)\n */\n middleware?: Middleware[];\n /** Positioning options resolved by the configuration context */\n options?: PositioningOptions;\n isRtl?: boolean;\n /**\n * [Floating UI placement](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: Placement;\n}\n\n/**\n * @internal\n * @returns manager that handles positioning out of the react lifecycle\n */\nexport function createPositionManager(managerOptions: PositionManagerOptions): PositionManager {\n let isDestroyed = false;\n const { container, target, arrow, strategy, options = {} } = managerOptions;\n // Modifies whether the container is positioned using transform\n const { useTransform = true, disableUpdateOnResize } = options;\n const targetWindow = getWindow(container) as (Window & typeof globalThis) | null;\n // Containers of documents without a window (e.g. `DOMParser`) can't be positioned\n if (!targetWindow) {\n const noop = () => undefined;\n return { updatePosition: noop, dispose: noop };\n }\n\n // When the dimensions of the target or the container change - trigger a position update,\n // unless disabled by the `disableUpdateOnResize` option\n const resizeObserver = disableUpdateOnResize\n ? null\n : createResizeObserver(targetWindow, entries => {\n // If content rect dimensions to go 0 -> very likely that `display: none` is being used to hide the element\n // In this case don't update and let users update imperatively\n if (entries.every(entry => entry.contentRect.width > 0 && entry.contentRect.height > 0)) {\n updatePosition();\n }\n });\n\n let isFirstUpdate = true;\n // The window and the scroll parents of the container and the target, the target is only observed\n // when it is an element as virtual elements are not part of the DOM\n const scrollTargets = new Set<EventTarget>([targetWindow]);\n const elements = isHTMLElement(target) ? [container, target] : [container];\n const listenToScroll = (scrollTarget: EventTarget) => {\n scrollTargets.add(scrollTarget);\n scrollTarget.addEventListener('scroll', updatePosition, { passive: true });\n };\n\n // When the container is first resolved, set position `fixed` to avoid scroll jumps.\n // Without this scroll jumps can occur when the element is rendered initially and receives focus\n Object.assign(container.style, { position: 'fixed', left: 0, top: 0, margin: 0 });\n\n const forceUpdate = () => {\n // debounced update can still occur afterwards\n // early return to avoid memory leaks\n if (isDestroyed) {\n return;\n }\n\n if (isFirstUpdate) {\n elements.forEach(element => {\n listScrollParents(element).forEach(listenToScroll);\n resizeObserver && resizeObserver.observe(element);\n });\n\n isFirstUpdate = false;\n }\n\n container.style.position = strategy;\n computePosition(target, container, managerOptions)\n .then(({ x, y, placement, arrow: arrowCoordinates, intersecting, escaped, referenceHidden }) => {\n // Promise can still resolve after destruction\n // early return to avoid applying outdated position\n if (isDestroyed) {\n return;\n }\n\n if (arrow && arrowCoordinates) {\n Object.assign(arrow.style, { left: px(arrowCoordinates.x), top: px(arrowCoordinates.y) });\n }\n container.setAttribute(DATA_POSITIONING_PLACEMENT, placement);\n container.toggleAttribute(DATA_POSITIONING_INTERSECTING, intersecting);\n container.toggleAttribute(DATA_POSITIONING_ESCAPED, escaped);\n container.toggleAttribute(DATA_POSITIONING_HIDDEN, referenceHidden);\n\n // Round so that the coordinates land on device pixels.\n // This prevents blurriness in cases where the browser doesn't apply pixel snapping, such as when other\n // effects like `backdrop-filter: blur()` are applied to the container, and the browser is zoomed in.\n // See https://github.com/microsoft/fluentui/issues/26764 for more info.\n const devicePixelRatio = targetWindow.devicePixelRatio || 1;\n const left = px(Math.round(x * devicePixelRatio) / devicePixelRatio);\n const top = px(Math.round(y * devicePixelRatio) / devicePixelRatio);\n Object.assign(\n container.style,\n useTransform\n ? {\n // Layer acceleration can disable subpixel rendering which causes slightly\n // blurry text on low PPI displays, so we want to use 2D transforms instead\n transform: devicePixelRatio <= 1 ? `translate(${left}, ${top})` : `translate3d(${left}, ${top}, 0)`,\n }\n : { left, top },\n );\n\n container.dispatchEvent(\n new CustomEvent<OnPositioningEndEventDetail>(POSITIONING_END_EVENT, {\n detail: {\n // Cast from Floating UI's Placement to the Fluent-owned PositioningPlacement.\n // These are equivalent string unions; the cast avoids leaking @floating-ui/dom\n // types into the public API surface.\n placement: placement satisfies PositioningPlacement,\n escaped,\n referenceHidden,\n },\n }),\n );\n })\n .catch(err => {\n // https://github.com/floating-ui/floating-ui/issues/1845\n // FIXME for node > 14\n // node 15 introduces promise rejection which means that any components\n // tests need to be `it('', async () => {})` otherwise there can be race conditions with\n // JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist\n // Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing\n // will actually be counter productive\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.error('[usePositioning]: Failed to calculate position', err);\n }\n });\n };\n\n const updatePosition = debounce(forceUpdate);\n\n const dispose = () => {\n isDestroyed = true;\n\n targetWindow.removeEventListener('resize', updatePosition);\n scrollTargets.forEach(scrollTarget => {\n scrollTarget.removeEventListener('scroll', updatePosition);\n });\n scrollTargets.clear();\n\n resizeObserver && resizeObserver.disconnect();\n };\n\n listenToScroll(targetWindow);\n targetWindow.addEventListener('resize', updatePosition);\n\n // Update the position on initialization\n updatePosition();\n\n return {\n updatePosition,\n dispose,\n };\n}\n"],"names":["computePosition","getWindow","px","isHTMLElement","debounce","listScrollParents","DATA_POSITIONING_ESCAPED","DATA_POSITIONING_HIDDEN","DATA_POSITIONING_INTERSECTING","DATA_POSITIONING_PLACEMENT","POSITIONING_END_EVENT","createResizeObserver","createPositionManager","managerOptions","isDestroyed","container","target","arrow","strategy","options","useTransform","disableUpdateOnResize","targetWindow","noop","undefined","updatePosition","dispose","resizeObserver","entries","every","entry","contentRect","width","height","isFirstUpdate","scrollTargets","Set","elements","listenToScroll","scrollTarget","add","addEventListener","passive","Object","assign","style","position","left","top","margin","forceUpdate","forEach","element","observe","then","x","y","placement","arrowCoordinates","intersecting","escaped","referenceHidden","setAttribute","toggleAttribute","devicePixelRatio","Math","round","transform","dispatchEvent","CustomEvent","detail","catch","err","process","env","NODE_ENV","console","error","removeEventListener","clear","disconnect"],"mappings":"AAAA,SAASA,eAAe,QAAQ,8BAA2B;AAC3D,SAASC,SAAS,EAAEC,EAAE,QAAQ,uBAAoB;AAElD,SAASC,aAAa,QAAQ,4BAA4B;AAQ1D,SAASC,QAAQ,QAAQ,mBAAU;AACnC,SAASC,iBAAiB,QAAQ,+BAA4B;AAC9D,SACEC,wBAAwB,EACxBC,uBAAuB,EACvBC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,qBAAqB,QAChB,iBAAc;AACrB,SAASC,oBAAoB,QAAQ,kCAA+B;AAiCpE;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,cAAsC;IAC1E,IAAIC,cAAc;IAClB,MAAM,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,CAAC,CAAC,EAAE,GAAGN;IAC7D,+DAA+D;IAC/D,MAAM,EAAEO,eAAe,IAAI,EAAEC,qBAAqB,EAAE,GAAGF;IACvD,MAAMG,eAAerB,UAAUc;IAC/B,kFAAkF;IAClF,IAAI,CAACO,cAAc;QACjB,MAAMC,OAAO,IAAMC;QACnB,OAAO;YAAEC,gBAAgBF;YAAMG,SAASH;QAAK;IAC/C;IAEA,yFAAyF;IACzF,wDAAwD;IACxD,MAAMI,iBAAiBN,wBACnB,OACAV,qBAAqBW,cAAcM,CAAAA;QACjC,2GAA2G;QAC3G,8DAA8D;QAC9D,IAAIA,QAA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