@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.
Files changed (111) hide show
  1. package/CHANGELOG.md +7 -7
  2. package/README.md +130 -7
  3. package/lib/PositioningConfigurationContext.js +1 -2
  4. package/lib/PositioningConfigurationContext.js.map +1 -1
  5. package/lib/createPositionManager.js +74 -82
  6. package/lib/createPositionManager.js.map +1 -1
  7. package/lib/engine/computePosition.js +258 -0
  8. package/lib/engine/computePosition.js.map +1 -0
  9. package/lib/engine/index.js +260 -0
  10. package/lib/engine/index.js.map +1 -0
  11. package/lib/engine/platform.js +209 -0
  12. package/lib/engine/platform.js.map +1 -0
  13. package/lib/middleware/flip.js +1 -1
  14. package/lib/middleware/flip.js.map +1 -1
  15. package/lib/middleware/intersecting.js +1 -1
  16. package/lib/middleware/intersecting.js.map +1 -1
  17. package/lib/middleware/maxSize.js +1 -1
  18. package/lib/middleware/maxSize.js.map +1 -1
  19. package/lib/middleware/offset.js +1 -1
  20. package/lib/middleware/offset.js.map +1 -1
  21. package/lib/middleware/shift.js +1 -1
  22. package/lib/middleware/shift.js.map +1 -1
  23. package/lib/usePositioning.js +38 -48
  24. package/lib/usePositioning.js.map +1 -1
  25. package/lib/usePositioning.raster.js +45 -0
  26. package/lib/usePositioning.raster.js.map +1 -0
  27. package/lib/usePositioningOptions.js +25 -117
  28. package/lib/usePositioningOptions.js.map +1 -1
  29. package/lib/utils/createResizeObserver.js +2 -2
  30. package/lib/utils/createResizeObserver.js.map +1 -1
  31. package/lib/utils/debounce.js +6 -13
  32. package/lib/utils/debounce.js.map +1 -1
  33. package/lib/utils/fromFloatingUIPlacement.js +10 -29
  34. package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
  35. package/lib/utils/getBoundary.js +8 -17
  36. package/lib/utils/getBoundary.js.map +1 -1
  37. package/lib/utils/index.js +0 -2
  38. package/lib/utils/index.js.map +1 -1
  39. package/lib/utils/listScrollParents.js +12 -20
  40. package/lib/utils/listScrollParents.js.map +1 -1
  41. package/lib/utils/normalizeAutoSize.js +15 -22
  42. package/lib/utils/normalizeAutoSize.js.map +1 -1
  43. package/lib/utils/toFloatingUIPlacement.js +9 -26
  44. package/lib/utils/toFloatingUIPlacement.js.map +1 -1
  45. package/lib/utils/useCallbackRef.js +1 -10
  46. package/lib/utils/useCallbackRef.js.map +1 -1
  47. package/lib-commonjs/PositioningConfigurationContext.cjs +1 -2
  48. package/lib-commonjs/PositioningConfigurationContext.cjs.map +1 -1
  49. package/lib-commonjs/createPositionManager.cjs +72 -80
  50. package/lib-commonjs/createPositionManager.cjs.map +1 -1
  51. package/lib-commonjs/engine/computePosition.cjs +265 -0
  52. package/lib-commonjs/engine/computePosition.cjs.map +1 -0
  53. package/lib-commonjs/engine/index.cjs +290 -0
  54. package/lib-commonjs/engine/index.cjs.map +1 -0
  55. package/lib-commonjs/engine/platform.cjs +264 -0
  56. package/lib-commonjs/engine/platform.cjs.map +1 -0
  57. package/lib-commonjs/middleware/flip.cjs +6 -6
  58. package/lib-commonjs/middleware/flip.cjs.map +1 -1
  59. package/lib-commonjs/middleware/intersecting.cjs +2 -2
  60. package/lib-commonjs/middleware/intersecting.cjs.map +1 -1
  61. package/lib-commonjs/middleware/maxSize.cjs +4 -4
  62. package/lib-commonjs/middleware/maxSize.cjs.map +1 -1
  63. package/lib-commonjs/middleware/offset.cjs +2 -2
  64. package/lib-commonjs/middleware/offset.cjs.map +1 -1
  65. package/lib-commonjs/middleware/shift.cjs +7 -7
  66. package/lib-commonjs/middleware/shift.cjs.map +1 -1
  67. package/lib-commonjs/usePositioning.cjs +37 -46
  68. package/lib-commonjs/usePositioning.cjs.map +1 -1
  69. package/lib-commonjs/usePositioning.raster.cjs +49 -0
  70. package/lib-commonjs/usePositioning.raster.cjs.map +1 -0
  71. package/lib-commonjs/usePositioningOptions.cjs +24 -112
  72. package/lib-commonjs/usePositioningOptions.cjs.map +1 -1
  73. package/lib-commonjs/utils/createResizeObserver.cjs +2 -2
  74. package/lib-commonjs/utils/createResizeObserver.cjs.map +1 -1
  75. package/lib-commonjs/utils/debounce.cjs +6 -13
  76. package/lib-commonjs/utils/debounce.cjs.map +1 -1
  77. package/lib-commonjs/utils/fromFloatingUIPlacement.cjs +21 -32
  78. package/lib-commonjs/utils/fromFloatingUIPlacement.cjs.map +1 -1
  79. package/lib-commonjs/utils/getBoundary.cjs +8 -17
  80. package/lib-commonjs/utils/getBoundary.cjs.map +1 -1
  81. package/lib-commonjs/utils/index.cjs +0 -8
  82. package/lib-commonjs/utils/index.cjs.map +1 -1
  83. package/lib-commonjs/utils/listScrollParents.cjs +12 -20
  84. package/lib-commonjs/utils/listScrollParents.cjs.map +1 -1
  85. package/lib-commonjs/utils/normalizeAutoSize.cjs +26 -25
  86. package/lib-commonjs/utils/normalizeAutoSize.cjs.map +1 -1
  87. package/lib-commonjs/utils/toFloatingUIPlacement.cjs +13 -27
  88. package/lib-commonjs/utils/toFloatingUIPlacement.cjs.map +1 -1
  89. package/lib-commonjs/utils/useCallbackRef.cjs +1 -9
  90. package/lib-commonjs/utils/useCallbackRef.cjs.map +1 -1
  91. package/package.json +5 -9
  92. package/lib/Arrow.module.css +0 -45
  93. package/lib/hooks/useSafeZoneArea/SafeZoneArea.module.css +0 -28
  94. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.css.js +0 -9
  95. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.css.js.map +0 -1
  96. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.js +0 -9
  97. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.js.map +0 -1
  98. package/lib/utils/writeArrowUpdates.js +0 -13
  99. package/lib/utils/writeArrowUpdates.js.map +0 -1
  100. package/lib/utils/writeContainerupdates.js +0 -43
  101. package/lib/utils/writeContainerupdates.js.map +0 -1
  102. package/lib-commonjs/Arrow.module.css +0 -45
  103. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.module.css +0 -28
  104. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.css.cjs +0 -20
  105. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.css.cjs.map +0 -1
  106. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.cjs +0 -20
  107. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.cjs.map +0 -1
  108. package/lib-commonjs/utils/writeArrowUpdates.cjs +0 -23
  109. package/lib-commonjs/utils/writeArrowUpdates.cjs.map +0 -1
  110. package/lib-commonjs/utils/writeContainerupdates.cjs +0 -51
  111. package/lib-commonjs/utils/writeContainerupdates.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/toFloatingUIPlacement.ts"],"sourcesContent":["import type { Placement, Side, Alignment as FloatingUIAlignment } from '@floating-ui/dom';\nimport type { Alignment, Position } from '../types';\n\ntype PlacementPosition = Side;\ntype PlacementAlign = FloatingUIAlignment;\n\nconst getPositionMap = (rtl?: boolean): Record<Position, PlacementPosition> => ({\n above: 'top',\n below: 'bottom',\n before: rtl ? 'right' : 'left',\n after: rtl ? 'left' : 'right',\n});\n\n// Floating UI automatically flips alignment\n// https://github.com/floating-ui/floating-ui/issues/1563\nconst getAlignmentMap = (): Record<Alignment, PlacementAlign | undefined> => ({\n start: 'start',\n end: 'end',\n top: 'start',\n bottom: 'end',\n center: undefined,\n});\n\nconst shouldAlignToCenter = (p?: Position, a?: Alignment): boolean => {\n const positionedVertically = p === 'above' || p === 'below';\n const alignedVertically = a === 'top' || a === 'bottom';\n\n return (positionedVertically && alignedVertically) || (!positionedVertically && !alignedVertically);\n};\n\n/**\n * Maps internal positioning values to Floating UI placement\n * @see positioningHelper.test.ts for expected placement values\n */\nexport const toFloatingUIPlacement = (align?: Alignment, position?: Position, rtl?: boolean): Placement | undefined => {\n const alignment = shouldAlignToCenter(position, align) ? 'center' : align;\n\n const computedPosition = position && getPositionMap(rtl)[position];\n const computedAlignment = alignment && getAlignmentMap()[alignment];\n\n if (computedPosition && computedAlignment) {\n return `${computedPosition}-${computedAlignment}` as Placement;\n }\n\n return computedPosition;\n};\n"],"names":["getPositionMap","rtl","above","below","before","after","getAlignmentMap","start","end","top","bottom","center","undefined","shouldAlignToCenter","p","a","positionedVertically","alignedVertically","toFloatingUIPlacement","align","position","alignment","computedPosition","computedAlignment"],"mappings":"AAMA,MAAMA,iBAAiB,CAACC,MAAwD,CAAA;QAC9EC,OAAO;QACPC,OAAO;QACPC,QAAQH,MAAM,UAAU;QACxBI,OAAOJ,MAAM,SAAS;IACxB,CAAA;AAEA,4CAA4C;AAC5C,yDAAyD;AACzD,MAAMK,kBAAkB,IAAsD,CAAA;QAC5EC,OAAO;QACPC,KAAK;QACLC,KAAK;QACLC,QAAQ;QACRC,QAAQC;IACV,CAAA;AAEA,MAAMC,sBAAsB,CAACC,GAAcC;IACzC,MAAMC,uBAAuBF,MAAM,WAAWA,MAAM;IACpD,MAAMG,oBAAoBF,MAAM,SAASA,MAAM;IAE/C,OAAO,AAACC,wBAAwBC,qBAAuB,CAACD,wBAAwB,CAACC;AACnF;AAEA;;;CAGC,GACD,OAAO,MAAMC,wBAAwB,CAACC,OAAmBC,UAAqBnB;IAC5E,MAAMoB,YAAYR,oBAAoBO,UAAUD,SAAS,WAAWA;IAEpE,MAAMG,mBAAmBF,YAAYpB,eAAeC,IAAI,CAACmB,SAAS;IAClE,MAAMG,oBAAoBF,aAAaf,iBAAiB,CAACe,UAAU;IAEnE,IAAIC,oBAAoBC,mBAAmB;QACzC,OAAO,GAAGD,iBAAiB,CAAC,EAAEC,mBAAmB;IACnD;IAEA,OAAOD;AACT,EAAE"}
1
+ {"version":3,"sources":["../../src/utils/toFloatingUIPlacement.ts"],"sourcesContent":["import type { Placement, Side } from '@floating-ui/dom';\nimport type { Alignment, Position } from '../types';\n\n/**\n * Maps internal positioning values to Floating UI placement\n * @see positioningHelper.test.ts for expected placement values\n */\nexport const toFloatingUIPlacement = (align?: Alignment, position?: Position, rtl?: boolean): Placement | undefined => {\n if (!position) {\n return undefined;\n }\n const block = position === 'above' || position === 'below';\n const side: Side = block\n ? position === 'above'\n ? 'top'\n : 'bottom'\n : (position === 'before') !== !!rtl\n ? 'left'\n : 'right';\n const alignedVertically = align === 'top' || align === 'bottom';\n if (!align || align === 'center' || block === alignedVertically) {\n return side;\n }\n return `${side}-${align === 'start' || align === 'top' ? 'start' : 'end'}`;\n};\n"],"names":["toFloatingUIPlacement","align","position","rtl","undefined","block","side","alignedVertically"],"mappings":"AAGA;;;CAGC,GACD,OAAO,MAAMA,wBAAwB,CAACC,OAAmBC,UAAqBC;IAC5E,IAAI,CAACD,UAAU;QACb,OAAOE;IACT;IACA,MAAMC,QAAQH,aAAa,WAAWA,aAAa;IACnD,MAAMI,OAAaD,QACfH,aAAa,UACX,QACA,WACF,AAACA,aAAa,aAAc,CAAC,CAACC,MAC9B,SACA;IACJ,MAAMI,oBAAoBN,UAAU,SAASA,UAAU;IACvD,IAAI,CAACA,SAASA,UAAU,YAAYI,UAAUE,mBAAmB;QAC/D,OAAOD;IACT;IACA,OAAO,GAAGA,KAAK,CAAC,EAAEL,UAAU,WAAWA,UAAU,QAAQ,UAAU,OAAO;AAC5E,EAAE"}
@@ -1,6 +1,5 @@
1
1
  'use client';
2
2
  import * as React from "react";
3
- import { useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
4
3
  /**
5
4
  * Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content
6
5
  * changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via
@@ -11,14 +10,12 @@ import { useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
11
10
  *
12
11
  * @param initialValue - initial ref value
13
12
  * @param callback - a callback to run when value changes
14
- * @param skipInitialResolve - a flag to skip an initial ref report
15
13
  *
16
14
  * @example
17
15
  * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
18
16
  * ref.current = 1;
19
17
  * // prints 0 -> 1
20
- */ export function useCallbackRef(initialValue, callback, skipInitialResolve) {
21
- const isFirst = React.useRef(true);
18
+ */ export function useCallbackRef(initialValue, callback) {
22
19
  const [ref] = React.useState(()=>({
23
20
  // value
24
21
  value: initialValue,
@@ -33,17 +30,11 @@ import { useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
33
30
  const last = ref.value;
34
31
  if (last !== value) {
35
32
  ref.value = value;
36
- if (skipInitialResolve && isFirst.current) {
37
- return;
38
- }
39
33
  ref.callback(value, last);
40
34
  }
41
35
  }
42
36
  }
43
37
  }));
44
- useIsomorphicLayoutEffect(()=>{
45
- isFirst.current = false;
46
- }, []);
47
38
  // update callback
48
39
  ref.callback = callback;
49
40
  return ref.facade;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/useCallbackRef.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\n/**\n * Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content\n * changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via\n * React.useState(), but it will cause re-renders always.\n *\n * https://reactjs.org/docs/hooks-reference.html#useref\n * https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref\n *\n * @param initialValue - initial ref value\n * @param callback - a callback to run when value changes\n * @param skipInitialResolve - a flag to skip an initial ref report\n *\n * @example\n * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);\n * ref.current = 1;\n * // prints 0 -> 1\n */\nexport function useCallbackRef<T>(\n initialValue: T | null,\n callback: (newValue: T | null, lastValue: T | null) => void,\n skipInitialResolve?: boolean,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n): React.MutableRefObject<T | null> {\n const isFirst = React.useRef(true);\n const [ref] = React.useState(() => ({\n // value\n value: initialValue,\n // last callback\n callback,\n // \"memoized\" public interface\n facade: {\n get current() {\n return ref.value;\n },\n set current(value) {\n const last = ref.value;\n\n if (last !== value) {\n ref.value = value;\n\n if (skipInitialResolve && isFirst.current) {\n return;\n }\n\n ref.callback(value, last);\n }\n },\n },\n }));\n\n useIsomorphicLayoutEffect(() => {\n isFirst.current = false;\n }, []);\n\n // update callback\n ref.callback = callback;\n\n return ref.facade;\n}\n"],"names":["React","useIsomorphicLayoutEffect","useCallbackRef","initialValue","callback","skipInitialResolve","isFirst","useRef","ref","useState","value","facade","current","last"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ,4BAA4B;AAEtE;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASC,eACdC,YAAsB,EACtBC,QAA2D,EAC3DC,kBAA4B;IAG5B,MAAMC,UAAUN,MAAMO,MAAM,CAAC;IAC7B,MAAM,CAACC,IAAI,GAAGR,MAAMS,QAAQ,CAAC,IAAO,CAAA;YAClC,QAAQ;YACRC,OAAOP;YACP,gBAAgB;YAChBC;YACA,8BAA8B;YAC9BO,QAAQ;gBACN,IAAIC,WAAU;oBACZ,OAAOJ,IAAIE,KAAK;gBAClB;gBACA,IAAIE,SAAQF,MAAO;oBACjB,MAAMG,OAAOL,IAAIE,KAAK;oBAEtB,IAAIG,SAASH,OAAO;wBAClBF,IAAIE,KAAK,GAAGA;wBAEZ,IAAIL,sBAAsBC,QAAQM,OAAO,EAAE;4BACzC;wBACF;wBAEAJ,IAAIJ,QAAQ,CAACM,OAAOG;oBACtB;gBACF;YACF;QACF,CAAA;IAEAZ,0BAA0B;QACxBK,QAAQM,OAAO,GAAG;IACpB,GAAG,EAAE;IAEL,kBAAkB;IAClBJ,IAAIJ,QAAQ,GAAGA;IAEf,OAAOI,IAAIG,MAAM;AACnB"}
1
+ {"version":3,"sources":["../../src/utils/useCallbackRef.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\n\n/**\n * Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content\n * changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via\n * React.useState(), but it will cause re-renders always.\n *\n * https://reactjs.org/docs/hooks-reference.html#useref\n * https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref\n *\n * @param initialValue - initial ref value\n * @param callback - a callback to run when value changes\n *\n * @example\n * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);\n * ref.current = 1;\n * // prints 0 -> 1\n */\nexport function useCallbackRef<T>(\n initialValue: T | null,\n callback: (newValue: T | null, lastValue: T | null) => void,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n): React.MutableRefObject<T | null> {\n const [ref] = React.useState(() => ({\n // value\n value: initialValue,\n // last callback\n callback,\n // \"memoized\" public interface\n facade: {\n get current() {\n return ref.value;\n },\n set current(value) {\n const last = ref.value;\n\n if (last !== value) {\n ref.value = value;\n ref.callback(value, last);\n }\n },\n },\n }));\n\n // update callback\n ref.callback = callback;\n\n return ref.facade;\n}\n"],"names":["React","useCallbackRef","initialValue","callback","ref","useState","value","facade","current","last"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAE/B;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASC,eACdC,YAAsB,EACtBC,QAA2D;IAG3D,MAAM,CAACC,IAAI,GAAGJ,MAAMK,QAAQ,CAAC,IAAO,CAAA;YAClC,QAAQ;YACRC,OAAOJ;YACP,gBAAgB;YAChBC;YACA,8BAA8B;YAC9BI,QAAQ;gBACN,IAAIC,WAAU;oBACZ,OAAOJ,IAAIE,KAAK;gBAClB;gBACA,IAAIE,SAAQF,MAAO;oBACjB,MAAMG,OAAOL,IAAIE,KAAK;oBAEtB,IAAIG,SAASH,OAAO;wBAClBF,IAAIE,KAAK,GAAGA;wBACZF,IAAID,QAAQ,CAACG,OAAOG;oBACtB;gBACF;YACF;QACF,CAAA;IAEA,kBAAkB;IAClBL,IAAID,QAAQ,GAAGA;IAEf,OAAOC,IAAIG,MAAM;AACnB"}
@@ -27,6 +27,5 @@ const DEFAULT_CONFIGURATION = ({ options })=>{
27
27
  const PositioningConfigurationContext = /*#__PURE__*/ _react.createContext(undefined);
28
28
  const PositioningConfigurationProvider = PositioningConfigurationContext.Provider;
29
29
  const usePositioningConfiguration = ()=>{
30
- var _React_useContext;
31
- return (_React_useContext = _react.useContext(PositioningConfigurationContext)) !== null && _React_useContext !== void 0 ? _React_useContext : DEFAULT_CONFIGURATION;
30
+ return _react.useContext(PositioningConfigurationContext) || DEFAULT_CONFIGURATION;
32
31
  };
@@ -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) ?? DEFAULT_CONFIGURATION;\n};\n"],"names":["React","DEFAULT_CONFIGURATION","options","PositioningConfigurationContext","createContext","undefined","PositioningConfigurationProvider","Provider","usePositioningConfiguration","useContext"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;iEAEuB,QAAQ;AAG/B,MAAM;AAEN,MAAMC,wBAAoD,CAAC,EAAEC,OAAO,EAAE;IACpE,OAAOA;AACT;AAEA,MAAM;AAEN,MAAMC,gDAAkCH,OAAMI,aAAa,CAAyCC;AAO7F,MAAMC,mCAAmCH,gCAAgCI,QAAQ,CAAC;AAElF,MAAMC,8BAA8B;QAClCR;IAAP,OAAA,CAAOA,oBAAAA,OAAMS,UAAU,CAACN,gCAAAA,MAAAA,QAAjBH,sBAAAA,KAAAA,IAAAA,oBAAqDC;AAC9D,EAAE"}
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;;;;;;;;;;;;;;;;;;;;iEAEuB,QAAQ;AAG/B,MAAM;AAEN,MAAMC,wBAAoD,CAAC,EAAEC,OAAO,EAAE;IACpE,OAAOA;AACT;AAEA,MAAM;AAEN,MAAMC,gDAAkCH,OAAMI,aAAa,CAAyCC;AAO7F,MAAMC,mCAAmCH,gCAAgCI,QAAQ,CAAC;AAElF,MAAMC,8BAA8B;IACzC,OAAOR,OAAMS,UAAU,CAACN,oCAAoCF;AAC9D,EAAE"}
@@ -8,39 +8,54 @@ Object.defineProperty(exports, "createPositionManager", {
8
8
  return createPositionManager;
9
9
  }
10
10
  });
11
- const _dom = require("@floating-ui/dom");
11
+ const _computePosition = require("./engine/computePosition.cjs");
12
+ const _platform = require("./engine/platform.cjs");
12
13
  const _reactutilities = require("@fluentui/react-utilities");
13
14
  const _index = require("./utils/index.cjs");
14
15
  const _listScrollParents = require("./utils/listScrollParents.cjs");
15
16
  const _constants = require("./constants.cjs");
16
17
  const _createResizeObserver = require("./utils/createResizeObserver.cjs");
17
- function isLayoutViewportUnavailable(container) {
18
- const { clientWidth, clientHeight } = container.ownerDocument.documentElement;
19
- return clientWidth === 0 && clientHeight === 0;
20
- }
21
- function createPositionManager(options) {
18
+ function createPositionManager(managerOptions) {
22
19
  let isDestroyed = false;
23
- const { container, target, arrow, strategy, middleware, placement, useTransform = true, disableUpdateOnResize = false } = options;
24
- const targetWindow = container.ownerDocument.defaultView;
25
- if (!target || !container || !targetWindow) {
20
+ const { container, target, arrow, strategy, options = {} } = managerOptions;
21
+ // Modifies whether the container is positioned using transform
22
+ const { useTransform = true, disableUpdateOnResize } = options;
23
+ const targetWindow = (0, _platform.getWindow)(container);
24
+ // Containers of documents without a window (e.g. `DOMParser`) can't be positioned
25
+ if (!targetWindow) {
26
+ const noop = ()=>undefined;
26
27
  return {
27
- updatePosition: ()=>undefined,
28
- dispose: ()=>undefined
28
+ updatePosition: noop,
29
+ dispose: noop
29
30
  };
30
31
  }
31
- // When the dimensions of the target or the container change - trigger a position update
32
+ // When the dimensions of the target or the container change - trigger a position update,
33
+ // unless disabled by the `disableUpdateOnResize` option
32
34
  const resizeObserver = disableUpdateOnResize ? null : (0, _createResizeObserver.createResizeObserver)(targetWindow, (entries)=>{
33
35
  // If content rect dimensions to go 0 -> very likely that `display: none` is being used to hide the element
34
36
  // In this case don't update and let users update imperatively
35
- const shouldUpdateOnResize = entries.every((entry)=>{
36
- return entry.contentRect.width > 0 && entry.contentRect.height > 0;
37
- });
38
- if (shouldUpdateOnResize) {
37
+ if (entries.every((entry)=>entry.contentRect.width > 0 && entry.contentRect.height > 0)) {
39
38
  updatePosition();
40
39
  }
41
40
  });
42
41
  let isFirstUpdate = true;
43
- const scrollParents = new Set();
42
+ // The window and the scroll parents of the container and the target, the target is only observed
43
+ // when it is an element as virtual elements are not part of the DOM
44
+ const scrollTargets = new Set([
45
+ targetWindow
46
+ ]);
47
+ const elements = (0, _reactutilities.isHTMLElement)(target) ? [
48
+ container,
49
+ target
50
+ ] : [
51
+ container
52
+ ];
53
+ const listenToScroll = (scrollTarget)=>{
54
+ scrollTargets.add(scrollTarget);
55
+ scrollTarget.addEventListener('scroll', updatePosition, {
56
+ passive: true
57
+ });
58
+ };
44
59
  // When the container is first resolved, set position `fixed` to avoid scroll jumps.
45
60
  // Without this scroll jumps can occur when the element is rendered initially and receives focus
46
61
  Object.assign(container.style, {
@@ -56,68 +71,52 @@ function createPositionManager(options) {
56
71
  return;
57
72
  }
58
73
  if (isFirstUpdate) {
59
- (0, _listScrollParents.listScrollParents)(container).forEach((scrollParent)=>scrollParents.add(scrollParent));
60
- if ((0, _reactutilities.isHTMLElement)(target)) {
61
- (0, _listScrollParents.listScrollParents)(target).forEach((scrollParent)=>scrollParents.add(scrollParent));
62
- }
63
- scrollParents.forEach((scrollParent)=>{
64
- scrollParent.addEventListener('scroll', updatePosition, {
65
- passive: true
66
- });
74
+ elements.forEach((element)=>{
75
+ (0, _listScrollParents.listScrollParents)(element).forEach(listenToScroll);
76
+ resizeObserver && resizeObserver.observe(element);
67
77
  });
68
- resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(container);
69
- if ((0, _reactutilities.isHTMLElement)(target)) {
70
- resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(target);
71
- }
72
78
  isFirstUpdate = false;
73
79
  }
74
- Object.assign(container.style, {
75
- position: strategy
76
- });
77
- (0, _dom.computePosition)(target, container, {
78
- placement,
79
- middleware,
80
- strategy
81
- }).then(({ x, y, middlewareData, placement: computedPlacement })=>{
82
- var _ref, _ref1;
83
- var _positioningMiddlewareData_hide, _positioningMiddlewareData_hide1;
80
+ container.style.position = strategy;
81
+ (0, _computePosition.computePosition)(target, container, managerOptions).then(({ x, y, placement, arrow: arrowCoordinates, intersecting, escaped, referenceHidden })=>{
84
82
  // Promise can still resolve after destruction
85
83
  // early return to avoid applying outdated position
86
84
  if (isDestroyed) {
87
85
  return;
88
86
  }
89
- const positioningMiddlewareData = isLayoutViewportUnavailable(container) ? {
90
- ...middlewareData,
91
- hide: {
92
- ...middlewareData.hide,
93
- escaped: false,
94
- referenceHidden: false
95
- }
96
- } : middlewareData;
97
- (0, _index.writeArrowUpdates)({
98
- arrow,
99
- middlewareData: positioningMiddlewareData
100
- });
101
- (0, _index.writeContainerUpdates)({
102
- container,
103
- middlewareData: positioningMiddlewareData,
104
- placement: computedPlacement,
105
- coordinates: {
106
- x,
107
- y
108
- },
109
- lowPPI: ((targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.devicePixelRatio) || 1) <= 1,
110
- strategy,
111
- useTransform
87
+ if (arrow && arrowCoordinates) {
88
+ Object.assign(arrow.style, {
89
+ left: (0, _platform.px)(arrowCoordinates.x),
90
+ top: (0, _platform.px)(arrowCoordinates.y)
91
+ });
92
+ }
93
+ container.setAttribute(_constants.DATA_POSITIONING_PLACEMENT, placement);
94
+ container.toggleAttribute(_constants.DATA_POSITIONING_INTERSECTING, intersecting);
95
+ container.toggleAttribute(_constants.DATA_POSITIONING_ESCAPED, escaped);
96
+ container.toggleAttribute(_constants.DATA_POSITIONING_HIDDEN, referenceHidden);
97
+ // Round so that the coordinates land on device pixels.
98
+ // This prevents blurriness in cases where the browser doesn't apply pixel snapping, such as when other
99
+ // effects like `backdrop-filter: blur()` are applied to the container, and the browser is zoomed in.
100
+ // See https://github.com/microsoft/fluentui/issues/26764 for more info.
101
+ const devicePixelRatio = targetWindow.devicePixelRatio || 1;
102
+ const left = (0, _platform.px)(Math.round(x * devicePixelRatio) / devicePixelRatio);
103
+ const top = (0, _platform.px)(Math.round(y * devicePixelRatio) / devicePixelRatio);
104
+ Object.assign(container.style, useTransform ? {
105
+ // Layer acceleration can disable subpixel rendering which causes slightly
106
+ // blurry text on low PPI displays, so we want to use 2D transforms instead
107
+ transform: devicePixelRatio <= 1 ? `translate(${left}, ${top})` : `translate3d(${left}, ${top}, 0)`
108
+ } : {
109
+ left,
110
+ top
112
111
  });
113
112
  container.dispatchEvent(new CustomEvent(_constants.POSITIONING_END_EVENT, {
114
113
  detail: {
115
114
  // Cast from Floating UI's Placement to the Fluent-owned PositioningPlacement.
116
115
  // These are equivalent string unions; the cast avoids leaking @floating-ui/dom
117
116
  // types into the public API surface.
118
- placement: computedPlacement,
119
- escaped: (_ref = (_positioningMiddlewareData_hide = positioningMiddlewareData.hide) === null || _positioningMiddlewareData_hide === void 0 ? void 0 : _positioningMiddlewareData_hide.escaped) !== null && _ref !== void 0 ? _ref : false,
120
- referenceHidden: (_ref1 = (_positioningMiddlewareData_hide1 = positioningMiddlewareData.hide) === null || _positioningMiddlewareData_hide1 === void 0 ? void 0 : _positioningMiddlewareData_hide1.referenceHidden) !== null && _ref1 !== void 0 ? _ref1 : false
117
+ placement: placement,
118
+ escaped,
119
+ referenceHidden
121
120
  }
122
121
  }));
123
122
  }).catch((err)=>{
@@ -134,25 +133,18 @@ function createPositionManager(options) {
134
133
  }
135
134
  });
136
135
  };
137
- const updatePosition = (0, _index.debounce)(()=>forceUpdate());
136
+ const updatePosition = (0, _index.debounce)(forceUpdate);
138
137
  const dispose = ()=>{
139
138
  isDestroyed = true;
140
- if (targetWindow) {
141
- targetWindow.removeEventListener('scroll', updatePosition);
142
- targetWindow.removeEventListener('resize', updatePosition);
143
- }
144
- scrollParents.forEach((scrollParent)=>{
145
- scrollParent.removeEventListener('scroll', updatePosition);
139
+ targetWindow.removeEventListener('resize', updatePosition);
140
+ scrollTargets.forEach((scrollTarget)=>{
141
+ scrollTarget.removeEventListener('scroll', updatePosition);
146
142
  });
147
- scrollParents.clear();
148
- resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
143
+ scrollTargets.clear();
144
+ resizeObserver && resizeObserver.disconnect();
149
145
  };
150
- if (targetWindow) {
151
- targetWindow.addEventListener('scroll', updatePosition, {
152
- passive: true
153
- });
154
- targetWindow.addEventListener('resize', updatePosition);
155
- }
146
+ listenToScroll(targetWindow);
147
+ targetWindow.addEventListener('resize', updatePosition);
156
148
  // Update the position on initialization
157
149
  updatePosition();
158
150
  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":";;;;+BAwDgBc;;;;;;qBAxDgB,mBAAmB;gCAErB,4BAA4B;uBAES,mBAAU;mCAC3C,+BAA4B;2BACxB,iBAAc;sCACf,kCAA+B;AAuCpE,SAASN,4BAA4BC,SAAsB;IACzD,MAAM,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGF,UAAUG,aAAa,CAACC,eAAe;IAE7E,OAAOH,gBAAgB,KAAKC,iBAAiB;AAC/C;AAMO,+BAA+BI,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,WACAhB,0CAAAA,EAAqBiB,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,UAAU;QAASC,MAAM;QAAGC,KAAK;QAAGC,QAAQ;IAAE;IAE/E,MAAMC,cAAc;QAClB,8CAA8C;QAC9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;QAEnBhD,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAgBiD,UAAU;IAC5B;IAEA,IAAItD,cAAc;QAChBA,aAAa2B,gBAAgB,CAAC,UAAUzB,gBAAgB;YAAE0B,SAAS;QAAK;QACxE5B,aAAa2B,gBAAgB,CAAC,UAAUzB;IAC1C;IAEA,wCAAwC;IACxCA;IAEA,OAAO;QACLA;QACAE;IACF;AACF"}
1
+ {"version":3,"sources":["../src/createPositionManager.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":";;;;+BAyDgBY;;;;;;iCAzDgB,8BAA2B;0BAC7B,uBAAoB;gCAEpB,4BAA4B;uBAQjC,mBAAU;mCACD,+BAA4B;2BAOvD,iBAAc;sCACgB,kCAA+B;AAqC7D,+BAA+BC,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,mBAAerB,mBAAAA,EAAUc;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,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KAAK,eAAe;gBAC1C,sCAAsC;gBACtCC,QAAQC,KAAK,CAAC,kDAAkDL;YAClE;QACF;IACJ;IAEA,MAAM/C,qBAAiBrB,eAAAA,EAAS8C;IAEhC,MAAMxB,UAAU;QACdZ,cAAc;QAEdQ,aAAawD,mBAAmB,CAAC,UAAUrD;QAC3CU,cAAcgB,OAAO,CAACZ,CAAAA;YACpBA,aAAauC,mBAAmB,CAAC,UAAUrD;QAC7C;QACAU,cAAc4C,KAAK;QAEnBpD,kBAAkBA,eAAeqD,UAAU;IAC7C;IAEA1C,eAAehB;IACfA,aAAamB,gBAAgB,CAAC,UAAUhB;IAExC,wCAAwC;IACxCA;IAEA,OAAO;QACLA;QACAC;IACF;AACF"}
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "computePosition", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return computePosition;
9
+ }
10
+ });
11
+ const _index = require("../utils/index.cjs");
12
+ const _fromFloatingUIPlacement = require("../utils/fromFloatingUIPlacement.cjs");
13
+ const _normalizeAutoSize = require("../utils/normalizeAutoSize.cjs");
14
+ const _platform = require("./platform.cjs");
15
+ const SIDES = [
16
+ 'top',
17
+ 'right',
18
+ 'bottom',
19
+ 'left'
20
+ ];
21
+ const lengthOf = (axis)=>axis === 'x' ? 'width' : 'height';
22
+ const startOf = (axis)=>axis === 'x' ? 'left' : 'top';
23
+ const endOf = (axis)=>axis === 'x' ? 'right' : 'bottom';
24
+ const sides = (top, right, bottom, left)=>({
25
+ top,
26
+ right,
27
+ bottom,
28
+ left
29
+ });
30
+ const clamp = (min, value, max)=>Math.max(min, Math.min(value, max));
31
+ /** Moves the coordinate on the axis by the least amount that removes the overflow */ const shiftOverflow = (coords, axis, overflow)=>coords[axis] = clamp(coords[axis] + overflow[startOf(axis)], coords[axis], coords[axis] - overflow[endOf(axis)]);
32
+ async function computePosition(target, container, { placement: initial = 'bottom', strategy, options = {}, isRtl = false, arrow }) {
33
+ const { autoSize: rawAutoSize, offset, matchTargetSize, coverTarget, pinned, flipBoundary, overflowBoundary, overflowBoundaryPadding: rawPadding = 0, fallbackPositions = [], arrowPadding = 0, shiftToCoverTarget, unstable_disableTether: disableTether } = options;
34
+ const css = container.style;
35
+ // An empty value removes the property
36
+ const setStyle = (property, value = '')=>css.setProperty(property, value);
37
+ const autoSize = (0, _normalizeAutoSize.getAutoSizeDimensions)(rawAutoSize);
38
+ for (const dimension of autoSize){
39
+ setStyle('box-sizing');
40
+ setStyle(`max-${dimension}`);
41
+ setStyle(dimension);
42
+ }
43
+ const rtl = (0, _platform.getStyle)(container).direction === 'rtl';
44
+ const referenceElement = 'nodeType' in target ? target : target.contextElement || (0, _platform.getRoot)(container);
45
+ const clip = (element, boundary)=>(0, _platform.getClippingRect)(element, (0, _index.getBoundary)(container, boundary) || 'clippingAncestors', (0, _platform.getWindow)(container), strategy);
46
+ // Without explicit boundaries flipping and shifting share the clipping ancestors of the container
47
+ let containerClip;
48
+ const boundaryClip = (boundary)=>boundary ? clip(referenceElement, boundary) : containerClip || (containerClip = clip(container));
49
+ const flipClip = boundaryClip(flipBoundary);
50
+ const shiftClip = boundaryClip(overflowBoundary);
51
+ const visibilityClip = clip(referenceElement);
52
+ const padding = typeof rawPadding === 'number' ? sides(rawPadding, rawPadding, rawPadding, rawPadding) : sides(rawPadding.top || 0, rawPadding[isRtl ? 'start' : 'end'] || 0, rawPadding.bottom || 0, rawPadding[isRtl ? 'end' : 'start'] || 0);
53
+ /** How far the box (in container coordinates) overflows the bounds (in viewport coordinates) on each side */ const overflow = (box, bounds, inset = sides(0, 0, 0, 0))=>{
54
+ const result = {
55
+ ...inset
56
+ };
57
+ for (const axis of [
58
+ 'x',
59
+ 'y'
60
+ ]){
61
+ const length = lengthOf(axis);
62
+ const axisScale = scale[axis];
63
+ const origin = initialSpace[axis];
64
+ result[startOf(axis)] = (bounds[axis] - (box[axis] * axisScale + origin) + inset[startOf(axis)]) / axisScale;
65
+ result[endOf(axis)] = ((box[axis] + box[length]) * axisScale + origin - bounds[axis] - bounds[length] + inset[endOf(axis)]) / axisScale;
66
+ }
67
+ return result;
68
+ };
69
+ const [initialSide, initialAlign] = initial.split('-');
70
+ // Without fallbacks: the initial placement, the opposite alignment, the opposite side and both opposites
71
+ const candidates = fallbackPositions.length ? [
72
+ initial,
73
+ ...fallbackPositions.map((shorthand)=>{
74
+ const [position, align] = shorthand.split('-');
75
+ return (0, _index.toFloatingUIPlacement)(align, position, isRtl);
76
+ })
77
+ ] : [
78
+ initialSide,
79
+ SIDES[(SIDES.indexOf(initialSide) + 2) % 4]
80
+ ].flatMap((side)=>initialAlign ? [
81
+ `${side}-${initialAlign}`,
82
+ `${side}-${initialAlign === 'start' ? 'end' : 'start'}`
83
+ ] : [
84
+ side
85
+ ]);
86
+ const attempts = [];
87
+ let space;
88
+ /** The reference and floating rects in the container's coordinate space */ const measure = ()=>{
89
+ space = (0, _platform.getCoordinateSpace)(container, strategy);
90
+ const { width, height } = (0, _platform.getDimensions)(container);
91
+ return [
92
+ (0, _platform.getReferenceRect)(target, referenceElement, container, space, strategy),
93
+ (0, _platform.rect)(0, 0, width, height)
94
+ ];
95
+ };
96
+ let rects = measure();
97
+ // Overflow is always measured in the initial coordinate space
98
+ const initialSpace = space;
99
+ const { scale } = initialSpace;
100
+ let candidateIndex = 0;
101
+ let placement = initial;
102
+ let matchAttempt = false;
103
+ let arrowAdjusted = false;
104
+ let preserveCoordinates = false;
105
+ let arrowData;
106
+ let coords;
107
+ let delta = _platform.NO_OFFSET;
108
+ for(let attempt = 0; attempt <= 50; attempt++){
109
+ const [r, f] = rects;
110
+ const [side, align] = placement.split('-');
111
+ const isVertical = side === 'top' || side === 'bottom';
112
+ const isStart = side === 'top' || side === 'left';
113
+ // `main` is the alignment axis, `cross` is the axis that leads away from the target
114
+ const main = isVertical ? 'x' : 'y';
115
+ const cross = isVertical ? 'y' : 'x';
116
+ const mainLength = lengthOf(main);
117
+ const crossLength = lengthOf(cross);
118
+ const floatingRect = ()=>({
119
+ ...f,
120
+ ...coords
121
+ });
122
+ if (!preserveCoordinates) {
123
+ coords = {
124
+ x: r.x + r.width / 2 - f.width / 2,
125
+ y: r.y + r.height / 2 - f.height / 2
126
+ };
127
+ coords[cross] = isStart ? r[cross] - f[crossLength] : r[cross] + r[crossLength];
128
+ if (align) {
129
+ coords[main] += (r[mainLength] / 2 - f[mainLength] / 2) * (rtl && isVertical ? -1 : 1) * (align === 'start' ? -1 : 1);
130
+ }
131
+ }
132
+ preserveCoordinates = false;
133
+ if (matchTargetSize && r.width !== f.width && !matchAttempt) {
134
+ const property = '--fui-match-target-size';
135
+ setStyle(property, (0, _platform.px)(r.width));
136
+ if (!css.width) {
137
+ css.width = `var(${property})`;
138
+ }
139
+ matchAttempt = true;
140
+ rects = measure();
141
+ continue;
142
+ }
143
+ if (offset) {
144
+ const raw = typeof offset === 'function' ? offset({
145
+ positionedRect: f,
146
+ targetRect: r,
147
+ ...(0, _fromFloatingUIPlacement.toPositioningValues)(side, align)
148
+ }) : offset;
149
+ const value = typeof raw === 'number' ? {
150
+ mainAxis: raw
151
+ } : raw;
152
+ if (!arrowAdjusted) {
153
+ delta = {
154
+ [cross]: (value.mainAxis || 0) * (isStart ? -1 : 1),
155
+ [main]: (value.crossAxis || 0) * (rtl && isVertical ? -1 : 1)
156
+ };
157
+ coords.x += delta.x;
158
+ coords.y += delta.y;
159
+ }
160
+ }
161
+ if (coverTarget) {
162
+ coords[cross] += (isStart ? 1 : -1) * r[crossLength];
163
+ }
164
+ if (!pinned && !arrowAdjusted) {
165
+ const values = overflow(floatingRect(), flipClip);
166
+ // The edge on the alignment axis that overflows first: the end edge for start alignment (logical in RTL),
167
+ // the opposite one when the target is larger than the floating element
168
+ const alignEnd = align === (rtl && isVertical ? 'end' : 'start') !== r[mainLength] > f[mainLength];
169
+ const overflows = [
170
+ values[side],
171
+ values[(alignEnd ? endOf : startOf)(main)],
172
+ values[(alignEnd ? startOf : endOf)(main)]
173
+ ];
174
+ attempts.push([
175
+ placement,
176
+ overflows
177
+ ]);
178
+ if (overflows.some((value)=>value > 0)) {
179
+ const next = candidates[++candidateIndex];
180
+ if (next) {
181
+ placement = next;
182
+ continue;
183
+ }
184
+ const score = (scores)=>scores.reduce((sum, value)=>sum + Math.max(0, value), 0);
185
+ const best = (attempts.filter((item)=>item[1][0] <= 0).sort((a, b)=>a[1][1] - b[1][1])[0] || attempts.slice().sort((a, b)=>score(a[1]) - score(b[1]))[0])[0];
186
+ if (best !== placement) {
187
+ placement = best;
188
+ continue;
189
+ }
190
+ }
191
+ }
192
+ const shiftCross = disableTether ? disableTether === 'all' : !!shiftToCoverTarget;
193
+ const values = overflow(floatingRect(), shiftClip, padding);
194
+ shiftOverflow(coords, main, values);
195
+ if (shiftCross) {
196
+ shiftOverflow(coords, cross, values);
197
+ }
198
+ // Shifting on the cross axis, and disabling the tether on one axis, keep the floating element next to the target
199
+ if (disableTether !== 'all' && (shiftCross || disableTether)) {
200
+ coords[cross] = clamp(r[cross] - f[crossLength] + (isStart ? delta[cross] : 0), coords[cross], r[cross] + r[crossLength] + (isStart ? 0 : delta[cross]));
201
+ }
202
+ if (autoSize.length) {
203
+ const available = overflow(floatingRect(), shiftClip, padding);
204
+ for (const dimension of autoSize){
205
+ const axis = dimension === 'width' ? 'x' : 'y';
206
+ const max = f[dimension] - available[startOf(axis)] - available[endOf(axis)];
207
+ // Shifting on an axis makes the whole boundary available, otherwise the side facing away from the target
208
+ const size = axis === main || shiftCross ? max : Math.min(f[dimension] - available[side], max);
209
+ setStyle('box-sizing', 'border-box');
210
+ setStyle(`max-${dimension}`, (0, _platform.px)(size));
211
+ if (f[dimension] > size) {
212
+ setStyle(dimension, (0, _platform.px)(size));
213
+ const property = `overflow-${axis}`;
214
+ if (!css.getPropertyValue(property)) {
215
+ setStyle(property, 'auto');
216
+ }
217
+ }
218
+ }
219
+ const dimensions = (0, _platform.getDimensions)(container);
220
+ if (f.width !== dimensions.width || f.height !== dimensions.height) {
221
+ rects = measure();
222
+ continue;
223
+ }
224
+ }
225
+ if (arrow) {
226
+ const client = main === 'x' ? 'clientWidth' : 'clientHeight';
227
+ const arrowLength = (0, _platform.getDimensions)(arrow)[mainLength];
228
+ const parent = (0, _platform.getOffsetParent)(arrow);
229
+ const clientSize = parent && parent[client] || container[client] || f[mainLength];
230
+ const inset = Math.min(arrowPadding, clientSize / 2 - arrowLength / 2 - 1);
231
+ const startDiff = coords[main] - r[main];
232
+ const endDiff = r[mainLength] + r[main] - coords[main] - f[mainLength];
233
+ const center = clientSize / 2 - arrowLength / 2 + endDiff / 2 - startDiff / 2;
234
+ const arrowOffset = clamp(inset, center, clientSize - arrowLength - inset);
235
+ arrowData = {
236
+ [main]: arrowOffset
237
+ };
238
+ if (!arrowAdjusted && align && center !== arrowOffset && r[mainLength] / 2 - inset - arrowLength / 2 < 0) {
239
+ coords[main] += center - arrowOffset;
240
+ arrowAdjusted = preserveCoordinates = true;
241
+ continue;
242
+ }
243
+ }
244
+ break;
245
+ }
246
+ const [reference, floating] = rects;
247
+ const floatingOverflow = overflow({
248
+ ...floating,
249
+ ...coords
250
+ }, visibilityClip);
251
+ const { clientWidth, clientHeight } = (0, _platform.getRoot)(container);
252
+ // Visibility can't be determined without a layout viewport (e.g. in jsdom)
253
+ const isHidden = (values, box)=>!!(clientWidth || clientHeight) && SIDES.some((side, index)=>values[side] >= box[index % 2 ? 'width' : 'height']);
254
+ return {
255
+ ...coords,
256
+ placement,
257
+ arrow: arrowData,
258
+ referenceHidden: isHidden(overflow(reference, visibilityClip), reference),
259
+ escaped: isHidden(floatingOverflow, floating),
260
+ intersecting: [
261
+ floatingOverflow.top,
262
+ floatingOverflow.bottom
263
+ ].some((value)=>value > 0 && value < floating.height)
264
+ };
265
+ }