@fluentui/react-positioning 0.0.0-nightly-20230529-0417.1 → 0.0.0-nightly-20230531-0416.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.json +9 -9
  2. package/CHANGELOG.md +7 -7
  3. package/lib/constants.js +0 -1
  4. package/lib/constants.js.map +1 -1
  5. package/lib/createArrowStyles.js +47 -55
  6. package/lib/createArrowStyles.js.map +1 -1
  7. package/lib/createPositionManager.js +95 -110
  8. package/lib/createPositionManager.js.map +1 -1
  9. package/lib/createVirtualElementFromClick.js +18 -19
  10. package/lib/createVirtualElementFromClick.js.map +1 -1
  11. package/lib/index.js +0 -1
  12. package/lib/index.js.map +1 -1
  13. package/lib/middleware/coverTarget.js +26 -32
  14. package/lib/middleware/coverTarget.js.map +1 -1
  15. package/lib/middleware/flip.js +22 -32
  16. package/lib/middleware/flip.js.map +1 -1
  17. package/lib/middleware/index.js +0 -1
  18. package/lib/middleware/index.js.map +1 -1
  19. package/lib/middleware/intersecting.js +16 -17
  20. package/lib/middleware/intersecting.js.map +1 -1
  21. package/lib/middleware/maxSize.js +25 -34
  22. package/lib/middleware/maxSize.js.map +1 -1
  23. package/lib/middleware/offset.js +3 -5
  24. package/lib/middleware/offset.js.map +1 -1
  25. package/lib/middleware/shift.js +21 -30
  26. package/lib/middleware/shift.js.map +1 -1
  27. package/lib/types.js +0 -1
  28. package/lib/types.js.map +1 -1
  29. package/lib/usePositioning.js +188 -156
  30. package/lib/usePositioning.js.map +1 -1
  31. package/lib/usePositioningMouseTarget.js +24 -23
  32. package/lib/usePositioningMouseTarget.js.map +1 -1
  33. package/lib/utils/debounce.js +13 -14
  34. package/lib/utils/debounce.js.map +1 -1
  35. package/lib/utils/fromFloatingUIPlacement.js +23 -28
  36. package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
  37. package/lib/utils/getBoundary.js +14 -16
  38. package/lib/utils/getBoundary.js.map +1 -1
  39. package/lib/utils/getFloatingUIOffset.js +16 -27
  40. package/lib/utils/getFloatingUIOffset.js.map +1 -1
  41. package/lib/utils/getReactFiberFromNode.js +36 -37
  42. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  43. package/lib/utils/getScrollParent.js +35 -42
  44. package/lib/utils/getScrollParent.js.map +1 -1
  45. package/lib/utils/hasAutoFocusFilter.js +9 -11
  46. package/lib/utils/hasAutoFocusFilter.js.map +1 -1
  47. package/lib/utils/index.js +0 -1
  48. package/lib/utils/index.js.map +1 -1
  49. package/lib/utils/mergeArrowOffset.js +24 -25
  50. package/lib/utils/mergeArrowOffset.js.map +1 -1
  51. package/lib/utils/parseFloatingUIPlacement.js +6 -7
  52. package/lib/utils/parseFloatingUIPlacement.js.map +1 -1
  53. package/lib/utils/resolvePositioningShorthand.js +55 -56
  54. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  55. package/lib/utils/toFloatingUIPadding.js +16 -21
  56. package/lib/utils/toFloatingUIPadding.js.map +1 -1
  57. package/lib/utils/toFloatingUIPlacement.js +25 -27
  58. package/lib/utils/toFloatingUIPlacement.js.map +1 -1
  59. package/lib/utils/toggleScrollListener.js +12 -14
  60. package/lib/utils/toggleScrollListener.js.map +1 -1
  61. package/lib/utils/useCallbackRef.js +30 -32
  62. package/lib/utils/useCallbackRef.js.map +1 -1
  63. package/lib/utils/writeArrowUpdates.js +10 -17
  64. package/lib/utils/writeArrowUpdates.js.map +1 -1
  65. package/lib/utils/writeContainerupdates.js +37 -47
  66. package/lib/utils/writeContainerupdates.js.map +1 -1
  67. package/lib-commonjs/constants.js +1 -3
  68. package/lib-commonjs/constants.js.map +1 -1
  69. package/lib-commonjs/createArrowStyles.js +1 -3
  70. package/lib-commonjs/createArrowStyles.js.map +1 -1
  71. package/lib-commonjs/createPositionManager.js +1 -3
  72. package/lib-commonjs/createPositionManager.js.map +1 -1
  73. package/lib-commonjs/createVirtualElementFromClick.js +1 -3
  74. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  75. package/lib-commonjs/index.js +0 -3
  76. package/lib-commonjs/index.js.map +1 -1
  77. package/lib-commonjs/middleware/coverTarget.js +1 -3
  78. package/lib-commonjs/middleware/coverTarget.js.map +1 -1
  79. package/lib-commonjs/middleware/flip.js +1 -3
  80. package/lib-commonjs/middleware/flip.js.map +1 -1
  81. package/lib-commonjs/middleware/index.js +0 -3
  82. package/lib-commonjs/middleware/index.js.map +1 -1
  83. package/lib-commonjs/middleware/intersecting.js +1 -3
  84. package/lib-commonjs/middleware/intersecting.js.map +1 -1
  85. package/lib-commonjs/middleware/maxSize.js +1 -3
  86. package/lib-commonjs/middleware/maxSize.js.map +1 -1
  87. package/lib-commonjs/middleware/offset.js +1 -3
  88. package/lib-commonjs/middleware/offset.js.map +1 -1
  89. package/lib-commonjs/middleware/shift.js +1 -3
  90. package/lib-commonjs/middleware/shift.js.map +1 -1
  91. package/lib-commonjs/types.js +0 -3
  92. package/lib-commonjs/types.js.map +1 -1
  93. package/lib-commonjs/usePositioning.js +1 -3
  94. package/lib-commonjs/usePositioning.js.map +1 -1
  95. package/lib-commonjs/usePositioningMouseTarget.js +1 -3
  96. package/lib-commonjs/usePositioningMouseTarget.js.map +1 -1
  97. package/lib-commonjs/utils/debounce.js +1 -3
  98. package/lib-commonjs/utils/debounce.js.map +1 -1
  99. package/lib-commonjs/utils/fromFloatingUIPlacement.js +1 -3
  100. package/lib-commonjs/utils/fromFloatingUIPlacement.js.map +1 -1
  101. package/lib-commonjs/utils/getBoundary.js +1 -3
  102. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  103. package/lib-commonjs/utils/getFloatingUIOffset.js +1 -3
  104. package/lib-commonjs/utils/getFloatingUIOffset.js.map +1 -1
  105. package/lib-commonjs/utils/getReactFiberFromNode.js +1 -3
  106. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  107. package/lib-commonjs/utils/getScrollParent.js +1 -3
  108. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  109. package/lib-commonjs/utils/hasAutoFocusFilter.js +1 -3
  110. package/lib-commonjs/utils/hasAutoFocusFilter.js.map +1 -1
  111. package/lib-commonjs/utils/index.js +0 -3
  112. package/lib-commonjs/utils/index.js.map +1 -1
  113. package/lib-commonjs/utils/mergeArrowOffset.js +1 -3
  114. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  115. package/lib-commonjs/utils/parseFloatingUIPlacement.js +1 -3
  116. package/lib-commonjs/utils/parseFloatingUIPlacement.js.map +1 -1
  117. package/lib-commonjs/utils/resolvePositioningShorthand.js +1 -3
  118. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  119. package/lib-commonjs/utils/toFloatingUIPadding.js +1 -3
  120. package/lib-commonjs/utils/toFloatingUIPadding.js.map +1 -1
  121. package/lib-commonjs/utils/toFloatingUIPlacement.js +1 -3
  122. package/lib-commonjs/utils/toFloatingUIPlacement.js.map +1 -1
  123. package/lib-commonjs/utils/toggleScrollListener.js +1 -3
  124. package/lib-commonjs/utils/toggleScrollListener.js.map +1 -1
  125. package/lib-commonjs/utils/useCallbackRef.js +1 -3
  126. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  127. package/lib-commonjs/utils/writeArrowUpdates.js +1 -3
  128. package/lib-commonjs/utils/writeArrowUpdates.js.map +1 -1
  129. package/lib-commonjs/utils/writeContainerupdates.js +1 -3
  130. package/lib-commonjs/utils/writeContainerupdates.js.map +1 -1
  131. package/package.json +5 -5
package/CHANGELOG.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@fluentui/react-positioning",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 29 May 2023 04:22:27 GMT",
6
- "tag": "@fluentui/react-positioning_v0.0.0-nightly-20230529-0417.1",
7
- "version": "0.0.0-nightly-20230529-0417.1",
5
+ "date": "Wed, 31 May 2023 04:21:52 GMT",
6
+ "tag": "@fluentui/react-positioning_v0.0.0-nightly-20230531-0416.1",
7
+ "version": "0.0.0-nightly-20230531-0416.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
@@ -16,20 +16,20 @@
16
16
  {
17
17
  "author": "beachball",
18
18
  "package": "@fluentui/react-positioning",
19
- "comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230529-0417.1",
20
- "commit": "7df11de7bd463f5d170ca4e80e14d2352a752b3b"
19
+ "comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230531-0416.1",
20
+ "commit": "ae1413c54c14b251f857528305e1d8b16f931ef6"
21
21
  },
22
22
  {
23
23
  "author": "beachball",
24
24
  "package": "@fluentui/react-positioning",
25
- "comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230529-0417.1",
26
- "commit": "7df11de7bd463f5d170ca4e80e14d2352a752b3b"
25
+ "comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230531-0416.1",
26
+ "commit": "ae1413c54c14b251f857528305e1d8b16f931ef6"
27
27
  },
28
28
  {
29
29
  "author": "beachball",
30
30
  "package": "@fluentui/react-positioning",
31
- "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230529-0417.1",
32
- "commit": "7df11de7bd463f5d170ca4e80e14d2352a752b3b"
31
+ "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230531-0416.1",
32
+ "commit": "ae1413c54c14b251f857528305e1d8b16f931ef6"
33
33
  }
34
34
  ]
35
35
  }
package/CHANGELOG.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # Change Log - @fluentui/react-positioning
2
2
 
3
- This log was last generated on Mon, 29 May 2023 04:22:27 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 31 May 2023 04:21:52 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20230529-0417.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v0.0.0-nightly-20230529-0417.1)
7
+ ## [0.0.0-nightly-20230531-0416.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v0.0.0-nightly-20230531-0416.1)
8
8
 
9
- Mon, 29 May 2023 04:22:27 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.5.14..@fluentui/react-positioning_v0.0.0-nightly-20230529-0417.1)
9
+ Wed, 31 May 2023 04:21:52 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.5.14..@fluentui/react-positioning_v0.0.0-nightly-20230531-0416.1)
11
11
 
12
12
  ### Changes
13
13
 
14
14
  - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
15
- - Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230529-0417.1 ([commit](https://github.com/microsoft/fluentui/commit/7df11de7bd463f5d170ca4e80e14d2352a752b3b) by beachball)
16
- - Bump @fluentui/react-theme to v0.0.0-nightly-20230529-0417.1 ([commit](https://github.com/microsoft/fluentui/commit/7df11de7bd463f5d170ca4e80e14d2352a752b3b) by beachball)
17
- - Bump @fluentui/react-utilities to v0.0.0-nightly-20230529-0417.1 ([commit](https://github.com/microsoft/fluentui/commit/7df11de7bd463f5d170ca4e80e14d2352a752b3b) by beachball)
15
+ - Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230531-0416.1 ([commit](https://github.com/microsoft/fluentui/commit/ae1413c54c14b251f857528305e1d8b16f931ef6) by beachball)
16
+ - Bump @fluentui/react-theme to v0.0.0-nightly-20230531-0416.1 ([commit](https://github.com/microsoft/fluentui/commit/ae1413c54c14b251f857528305e1d8b16f931ef6) by beachball)
17
+ - Bump @fluentui/react-utilities to v0.0.0-nightly-20230531-0416.1 ([commit](https://github.com/microsoft/fluentui/commit/ae1413c54c14b251f857528305e1d8b16f931ef6) by beachball)
18
18
 
19
19
  ## [9.5.14](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.5.14)
20
20
 
package/lib/constants.js CHANGED
@@ -2,4 +2,3 @@ export const DATA_POSITIONING_INTERSECTING = 'data-popper-is-intersecting';
2
2
  export const DATA_POSITIONING_ESCAPED = 'data-popper-escaped';
3
3
  export const DATA_POSITIONING_HIDDEN = 'data-popper-reference-hidden';
4
4
  export const DATA_POSITIONING_PLACEMENT = 'data-popper-placement';
5
- //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["DATA_POSITIONING_INTERSECTING","DATA_POSITIONING_ESCAPED","DATA_POSITIONING_HIDDEN","DATA_POSITIONING_PLACEMENT"],"sources":["../src/constants.ts"],"sourcesContent":["export const DATA_POSITIONING_INTERSECTING = 'data-popper-is-intersecting';\nexport const DATA_POSITIONING_ESCAPED = 'data-popper-escaped';\nexport const DATA_POSITIONING_HIDDEN = 'data-popper-reference-hidden';\nexport const DATA_POSITIONING_PLACEMENT = 'data-popper-placement';\n"],"mappings":"AAAA,OAAO,MAAMA,6BAAA,GAAgC;AAC7C,OAAO,MAAMC,wBAAA,GAA2B;AACxC,OAAO,MAAMC,uBAAA,GAA0B;AACvC,OAAO,MAAMC,0BAAA,GAA6B"}
1
+ {"version":3,"sources":["constants.ts"],"sourcesContent":["export const DATA_POSITIONING_INTERSECTING = 'data-popper-is-intersecting';\nexport const DATA_POSITIONING_ESCAPED = 'data-popper-escaped';\nexport const DATA_POSITIONING_HIDDEN = 'data-popper-reference-hidden';\nexport const DATA_POSITIONING_PLACEMENT = 'data-popper-placement';\n"],"names":["DATA_POSITIONING_INTERSECTING","DATA_POSITIONING_ESCAPED","DATA_POSITIONING_HIDDEN","DATA_POSITIONING_PLACEMENT"],"mappings":"AAAA,OAAO,MAAMA,gCAAgC,8BAA8B;AAC3E,OAAO,MAAMC,2BAA2B,sBAAsB;AAC9D,OAAO,MAAMC,0BAA0B,+BAA+B;AACtE,OAAO,MAAMC,6BAA6B,wBAAwB"}
@@ -22,51 +22,45 @@ import { tokens } from '@fluentui/react-theme';
22
22
  * state.mediumArrow && styles.mediumArrow,
23
23
  * )
24
24
  * ```
25
- */
26
- export function createArrowStyles(options) {
27
- const {
28
- arrowHeight,
29
- borderWidth = '1px',
30
- borderStyle = 'solid',
31
- borderColor = tokens.colorTransparentStroke
32
- } = options;
33
- return {
34
- position: 'absolute',
35
- backgroundColor: 'inherit',
36
- visibility: 'hidden',
37
- zIndex: -1,
38
- ...(arrowHeight && createArrowHeightStyles(arrowHeight)),
39
- '::before': {
40
- content: '""',
41
- visibility: 'visible',
42
- position: 'absolute',
43
- boxSizing: 'border-box',
44
- width: 'inherit',
45
- height: 'inherit',
46
- backgroundColor: 'inherit',
47
- ...shorthands.borderRight(`${borderWidth} /* @noflip */`, `${borderStyle} /* @noflip */`, `${borderColor} /* @noflip */`),
48
- ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),
49
- borderBottomRightRadius: tokens.borderRadiusSmall,
50
- transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)'
51
- },
52
- // Popper sets data-popper-placement on the root element, which is used to align the arrow
53
- ':global([data-popper-placement^="top"])': {
54
- bottom: `-${borderWidth}`,
55
- '--angle': '0'
56
- },
57
- ':global([data-popper-placement^="right"])': {
58
- left: `-${borderWidth} /* @noflip */`,
59
- '--angle': '90deg'
60
- },
61
- ':global([data-popper-placement^="bottom"])': {
62
- top: `-${borderWidth}`,
63
- '--angle': '180deg'
64
- },
65
- ':global([data-popper-placement^="left"])': {
66
- right: `-${borderWidth} /* @noflip */`,
67
- '--angle': '270deg'
68
- }
69
- };
25
+ */ export function createArrowStyles(options) {
26
+ const { arrowHeight , borderWidth ='1px' , borderStyle ='solid' , borderColor =tokens.colorTransparentStroke } = options;
27
+ return {
28
+ position: 'absolute',
29
+ backgroundColor: 'inherit',
30
+ visibility: 'hidden',
31
+ zIndex: -1,
32
+ ...arrowHeight && createArrowHeightStyles(arrowHeight),
33
+ '::before': {
34
+ content: '""',
35
+ visibility: 'visible',
36
+ position: 'absolute',
37
+ boxSizing: 'border-box',
38
+ width: 'inherit',
39
+ height: 'inherit',
40
+ backgroundColor: 'inherit',
41
+ ...shorthands.borderRight(`${borderWidth} /* @noflip */`, `${borderStyle} /* @noflip */`, `${borderColor} /* @noflip */`),
42
+ ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),
43
+ borderBottomRightRadius: tokens.borderRadiusSmall,
44
+ transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)'
45
+ },
46
+ // Popper sets data-popper-placement on the root element, which is used to align the arrow
47
+ ':global([data-popper-placement^="top"])': {
48
+ bottom: `-${borderWidth}`,
49
+ '--angle': '0'
50
+ },
51
+ ':global([data-popper-placement^="right"])': {
52
+ left: `-${borderWidth} /* @noflip */`,
53
+ '--angle': '90deg'
54
+ },
55
+ ':global([data-popper-placement^="bottom"])': {
56
+ top: `-${borderWidth}`,
57
+ '--angle': '180deg'
58
+ },
59
+ ':global([data-popper-placement^="left"])': {
60
+ right: `-${borderWidth} /* @noflip */`,
61
+ '--angle': '270deg'
62
+ }
63
+ };
70
64
  }
71
65
  /**
72
66
  * @internal
@@ -74,14 +68,12 @@ export function createArrowStyles(options) {
74
68
  *
75
69
  * Use this when you need to create classes for several different arrow sizes. If you only need a
76
70
  * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
77
- */
78
- export function createArrowHeightStyles(arrowHeight) {
79
- // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.
80
- // Multiply the triangle's height by sqrt(2) to get length of its edges.
81
- const edgeLength = `${1.414 * arrowHeight}px`;
82
- return {
83
- width: edgeLength,
84
- height: edgeLength
85
- };
71
+ */ export function createArrowHeightStyles(arrowHeight) {
72
+ // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.
73
+ // Multiply the triangle's height by sqrt(2) to get length of its edges.
74
+ const edgeLength = `${1.414 * arrowHeight}px`;
75
+ return {
76
+ width: edgeLength,
77
+ height: edgeLength
78
+ };
86
79
  }
87
- //# sourceMappingURL=createArrowStyles.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["shorthands","tokens","createArrowStyles","options","arrowHeight","borderWidth","borderStyle","borderColor","colorTransparentStroke","position","backgroundColor","visibility","zIndex","createArrowHeightStyles","content","boxSizing","width","height","borderRight","borderBottom","borderBottomRightRadius","borderRadiusSmall","transform","bottom","left","top","right","edgeLength"],"sources":["../src/createArrowStyles.ts"],"sourcesContent":["import { shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\n\n/**\n * @internal\n * Options parameter for the createArrowStyles function\n */\nexport type CreateArrowStylesOptions = {\n /**\n * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.\n *\n * This can be undefined to leave out the arrow size styles. You must then add styles created by\n * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.\n */\n arrowHeight: number | undefined;\n\n /**\n * The borderWidth of the arrow. Should be the same borderWidth as the parent element.\n *\n * @defaultvalue 1px\n */\n borderWidth?: GriffelStyle['borderBottomWidth'];\n\n /**\n * The borderStyle for the arrow. Should be the same borderStyle as the parent element.\n *\n * @defaultvalue solid\n */\n borderStyle?: GriffelStyle['borderBottomStyle'];\n\n /**\n * The borderColor of the arrow. Should be the same borderColor as the parent element.\n *\n * @defaultvalue tokens.colorTransparentStroke\n */\n borderColor?: GriffelStyle['borderBottomColor'];\n};\n\n/**\n * @internal\n * Helper that creates a makeStyles rule for an arrow element.\n * For runtime arrow size toggling simply create extra classnames to apply to the arrow element\n *\n * ```ts\n * makeStyles({\n * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),\n *\n * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),\n * mediumArrow: createArrowHeightStyles(4),\n * smallArrow: createArrowHeightStyles(2),\n * })\n * ...\n *\n * state.arrowWithSize.className = styles.arrowWithSize;\n * state.arrowWithoutSize.className = mergeClasses(\n * styles.arrowWithoutSize,\n * state.smallArrow && styles.smallArrow,\n * state.mediumArrow && styles.mediumArrow,\n * )\n * ```\n */\nexport function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle {\n const {\n arrowHeight,\n borderWidth = '1px',\n borderStyle = 'solid',\n borderColor = tokens.colorTransparentStroke,\n } = options;\n\n return {\n position: 'absolute',\n backgroundColor: 'inherit',\n visibility: 'hidden',\n zIndex: -1,\n\n ...(arrowHeight && createArrowHeightStyles(arrowHeight)),\n\n '::before': {\n content: '\"\"',\n visibility: 'visible',\n position: 'absolute',\n boxSizing: 'border-box',\n width: 'inherit',\n height: 'inherit',\n backgroundColor: 'inherit',\n ...shorthands.borderRight(\n `${borderWidth} /* @noflip */`,\n `${borderStyle} /* @noflip */`,\n `${borderColor} /* @noflip */`,\n ),\n ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),\n borderBottomRightRadius: tokens.borderRadiusSmall,\n transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',\n },\n\n // Popper sets data-popper-placement on the root element, which is used to align the arrow\n ':global([data-popper-placement^=\"top\"])': {\n bottom: `-${borderWidth}`,\n '--angle': '0',\n },\n ':global([data-popper-placement^=\"right\"])': {\n left: `-${borderWidth} /* @noflip */`,\n '--angle': '90deg',\n },\n ':global([data-popper-placement^=\"bottom\"])': {\n top: `-${borderWidth}`,\n '--angle': '180deg',\n },\n ':global([data-popper-placement^=\"left\"])': {\n right: `-${borderWidth} /* @noflip */`,\n '--angle': '270deg',\n },\n };\n}\n\n/**\n * @internal\n * Creates CSS styles to size the arrow created by createArrowStyles to the given height.\n *\n * Use this when you need to create classes for several different arrow sizes. If you only need a\n * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.\n */\nexport function createArrowHeightStyles(arrowHeight: number) {\n // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.\n // Multiply the triangle's height by sqrt(2) to get length of its edges.\n const edgeLength = `${1.414 * arrowHeight}px`;\n return { width: edgeLength, height: edgeLength };\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ;AAC3B,SAASC,MAAM,QAAQ;AAsCvB;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,SAASC,kBAAkBC,OAAiC,EAAgB;EACjF,MAAM;I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import { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\n\n/**\n * @internal\n * Options parameter for the createArrowStyles function\n */\nexport type CreateArrowStylesOptions = {\n /**\n * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.\n *\n * This can be undefined to leave out the arrow size styles. You must then add styles created by\n * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.\n */\n arrowHeight: number | undefined;\n\n /**\n * The borderWidth of the arrow. Should be the same borderWidth as the parent element.\n *\n * @defaultvalue 1px\n */\n borderWidth?: GriffelStyle['borderBottomWidth'];\n\n /**\n * The borderStyle for the arrow. Should be the same borderStyle as the parent element.\n *\n * @defaultvalue solid\n */\n borderStyle?: GriffelStyle['borderBottomStyle'];\n\n /**\n * The borderColor of the arrow. Should be the same borderColor as the parent element.\n *\n * @defaultvalue tokens.colorTransparentStroke\n */\n borderColor?: GriffelStyle['borderBottomColor'];\n};\n\n/**\n * @internal\n * Helper that creates a makeStyles rule for an arrow element.\n * For runtime arrow size toggling simply create extra classnames to apply to the arrow element\n *\n * ```ts\n * makeStyles({\n * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),\n *\n * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),\n * mediumArrow: createArrowHeightStyles(4),\n * smallArrow: createArrowHeightStyles(2),\n * })\n * ...\n *\n * state.arrowWithSize.className = styles.arrowWithSize;\n * state.arrowWithoutSize.className = mergeClasses(\n * styles.arrowWithoutSize,\n * state.smallArrow && styles.smallArrow,\n * state.mediumArrow && styles.mediumArrow,\n * )\n * ```\n */\nexport function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle {\n const {\n arrowHeight,\n borderWidth = '1px',\n borderStyle = 'solid',\n borderColor = tokens.colorTransparentStroke,\n } = options;\n\n return {\n position: 'absolute',\n backgroundColor: 'inherit',\n visibility: 'hidden',\n zIndex: -1,\n\n ...(arrowHeight && createArrowHeightStyles(arrowHeight)),\n\n '::before': {\n content: '\"\"',\n visibility: 'visible',\n position: 'absolute',\n boxSizing: 'border-box',\n width: 'inherit',\n height: 'inherit',\n backgroundColor: 'inherit',\n ...shorthands.borderRight(\n `${borderWidth} /* @noflip */`,\n `${borderStyle} /* @noflip */`,\n `${borderColor} /* @noflip */`,\n ),\n ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),\n borderBottomRightRadius: tokens.borderRadiusSmall,\n transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',\n },\n\n // Popper sets data-popper-placement on the root element, which is used to align the arrow\n ':global([data-popper-placement^=\"top\"])': {\n bottom: `-${borderWidth}`,\n '--angle': '0',\n },\n ':global([data-popper-placement^=\"right\"])': {\n left: `-${borderWidth} /* @noflip */`,\n '--angle': '90deg',\n },\n ':global([data-popper-placement^=\"bottom\"])': {\n top: `-${borderWidth}`,\n '--angle': '180deg',\n },\n ':global([data-popper-placement^=\"left\"])': {\n right: `-${borderWidth} /* @noflip */`,\n '--angle': '270deg',\n },\n };\n}\n\n/**\n * @internal\n * Creates CSS styles to size the arrow created by createArrowStyles to the given height.\n *\n * Use this when you need to create classes for several different arrow sizes. If you only need a\n * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.\n */\nexport function createArrowHeightStyles(arrowHeight: number) {\n // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.\n // Multiply the triangle's height by sqrt(2) to get length of its edges.\n const edgeLength = `${1.414 * arrowHeight}px`;\n return { width: edgeLength, height: edgeLength };\n}\n"],"names":["shorthands","tokens","createArrowStyles","options","arrowHeight","borderWidth","borderStyle","borderColor","colorTransparentStroke","position","backgroundColor","visibility","zIndex","createArrowHeightStyles","content","boxSizing","width","height","borderRight","borderBottom","borderBottomRightRadius","borderRadiusSmall","transform","bottom","left","top","right","edgeLength"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,MAAM,QAAQ,wBAAwB;AAsC/C;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASC,kB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
6
  * @returns manager that handles positioning out of the react lifecycle
7
- */
8
- export function createPositionManager(options) {
9
- const {
10
- container,
11
- target,
12
- arrow,
13
- strategy,
14
- middleware,
15
- placement,
16
- useTransform = true
17
- } = options;
18
- let isDestroyed = false;
19
- if (!target || !container) {
20
- return {
21
- updatePosition: () => undefined,
22
- dispose: () => undefined
23
- };
24
- }
25
- let isFirstUpdate = true;
26
- const scrollParents = new Set();
27
- const targetWindow = container.ownerDocument.defaultView;
28
- // When the container is first resolved, set position `fixed` to avoid scroll jumps.
29
- // Without this scroll jumps can occur when the element is rendered initially and receives focus
30
- Object.assign(container.style, {
31
- position: 'fixed',
32
- left: 0,
33
- top: 0,
34
- margin: 0
35
- });
36
- const forceUpdate = () => {
37
- // debounced update can still occur afterwards
38
- // early return to avoid memory leaks
39
- if (isDestroyed) {
40
- return;
41
- }
42
- if (isFirstUpdate) {
43
- scrollParents.add(getScrollParent(container));
44
- if (isHTMLElement(target)) {
45
- scrollParents.add(getScrollParent(target));
46
- }
47
- scrollParents.forEach(scrollParent => {
48
- scrollParent.addEventListener('scroll', updatePosition);
49
- });
50
- isFirstUpdate = false;
7
+ */ export function createPositionManager(options) {
8
+ const { container , target , arrow , strategy , middleware , placement , useTransform =true } = options;
9
+ let isDestroyed = false;
10
+ if (!target || !container) {
11
+ return {
12
+ updatePosition: ()=>undefined,
13
+ dispose: ()=>undefined
14
+ };
51
15
  }
16
+ let isFirstUpdate = true;
17
+ const scrollParents = new Set();
18
+ const targetWindow = container.ownerDocument.defaultView;
19
+ // When the container is first resolved, set position `fixed` to avoid scroll jumps.
20
+ // Without this scroll jumps can occur when the element is rendered initially and receives focus
52
21
  Object.assign(container.style, {
53
- position: strategy
22
+ position: 'fixed',
23
+ left: 0,
24
+ top: 0,
25
+ margin: 0
54
26
  });
55
- computePosition(target, container, {
56
- placement,
57
- middleware,
58
- strategy
59
- }).then(({
60
- x,
61
- y,
62
- middlewareData,
63
- placement: computedPlacement
64
- }) => {
65
- // Promise can still resolve after destruction
66
- // early return to avoid applying outdated position
67
- if (isDestroyed) {
68
- return;
69
- }
70
- writeArrowUpdates({
71
- arrow,
72
- middlewareData
73
- });
74
- writeContainerUpdates({
75
- container,
76
- middlewareData,
77
- placement: computedPlacement,
78
- coordinates: {
79
- x,
80
- y
81
- },
82
- lowPPI: ((targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.devicePixelRatio) || 1) <= 1,
83
- strategy,
84
- useTransform
85
- });
86
- }).catch(err => {
87
- // https://github.com/floating-ui/floating-ui/issues/1845
88
- // FIXME for node > 14
89
- // node 15 introduces promise rejection which means that any components
90
- // tests need to be `it('', async () => {})` otherwise there can be race conditions with
91
- // JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist
92
- // Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing
93
- // will actually be counter productive
94
- if (process.env.NODE_ENV === 'development') {
95
- // eslint-disable-next-line no-console
96
- console.error('[usePositioning]: Failed to calculate position', err);
97
- }
98
- });
99
- };
100
- const updatePosition = debounce(() => forceUpdate());
101
- const dispose = () => {
102
- isDestroyed = true;
27
+ const forceUpdate = ()=>{
28
+ // debounced update can still occur afterwards
29
+ // early return to avoid memory leaks
30
+ if (isDestroyed) {
31
+ return;
32
+ }
33
+ if (isFirstUpdate) {
34
+ scrollParents.add(getScrollParent(container));
35
+ if (isHTMLElement(target)) {
36
+ scrollParents.add(getScrollParent(target));
37
+ }
38
+ scrollParents.forEach((scrollParent)=>{
39
+ scrollParent.addEventListener('scroll', updatePosition);
40
+ });
41
+ isFirstUpdate = false;
42
+ }
43
+ Object.assign(container.style, {
44
+ position: strategy
45
+ });
46
+ computePosition(target, container, {
47
+ placement,
48
+ middleware,
49
+ strategy
50
+ }).then(({ x , y , middlewareData , placement: computedPlacement })=>{
51
+ // Promise can still resolve after destruction
52
+ // early return to avoid applying outdated position
53
+ if (isDestroyed) {
54
+ return;
55
+ }
56
+ writeArrowUpdates({
57
+ arrow,
58
+ middlewareData
59
+ });
60
+ writeContainerUpdates({
61
+ container,
62
+ middlewareData,
63
+ placement: computedPlacement,
64
+ coordinates: {
65
+ x,
66
+ y
67
+ },
68
+ lowPPI: ((targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.devicePixelRatio) || 1) <= 1,
69
+ strategy,
70
+ useTransform
71
+ });
72
+ }).catch((err)=>{
73
+ // https://github.com/floating-ui/floating-ui/issues/1845
74
+ // FIXME for node > 14
75
+ // node 15 introduces promise rejection which means that any components
76
+ // tests need to be `it('', async () => {})` otherwise there can be race conditions with
77
+ // JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist
78
+ // Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing
79
+ // will actually be counter productive
80
+ if (process.env.NODE_ENV === 'development') {
81
+ // eslint-disable-next-line no-console
82
+ console.error('[usePositioning]: Failed to calculate position', err);
83
+ }
84
+ });
85
+ };
86
+ const updatePosition = debounce(()=>forceUpdate());
87
+ const dispose = ()=>{
88
+ isDestroyed = true;
89
+ if (targetWindow) {
90
+ targetWindow.removeEventListener('scroll', updatePosition);
91
+ targetWindow.removeEventListener('resize', updatePosition);
92
+ }
93
+ scrollParents.forEach((scrollParent)=>{
94
+ scrollParent.removeEventListener('scroll', updatePosition);
95
+ });
96
+ };
103
97
  if (targetWindow) {
104
- targetWindow.removeEventListener('scroll', updatePosition);
105
- targetWindow.removeEventListener('resize', updatePosition);
98
+ targetWindow.addEventListener('scroll', updatePosition);
99
+ targetWindow.addEventListener('resize', updatePosition);
106
100
  }
107
- scrollParents.forEach(scrollParent => {
108
- scrollParent.removeEventListener('scroll', updatePosition);
109
- });
110
- };
111
- if (targetWindow) {
112
- targetWindow.addEventListener('scroll', updatePosition);
113
- targetWindow.addEventListener('resize', updatePosition);
114
- }
115
- // Update the position on initialization
116
- updatePosition();
117
- return {
118
- updatePosition,
119
- dispose
120
- };
101
+ // Update the position on initialization
102
+ updatePosition();
103
+ return {
104
+ updatePosition,
105
+ dispose
106
+ };
121
107
  }
122
- //# sourceMappingURL=createPositionManager.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["computePosition","debounce","writeArrowUpdates","writeContainerUpdates","getScrollParent","isHTMLElement","createPositionManager","options","container","target","arrow","strategy","middleware","placement","useTransform","isDestroyed","updatePosition","undefined","dispose","isFirstUpdate","scrollParents","Set","targetWindow","ownerDocument","defaultView","Object","assign","style","position","left","top","margin","forceUpdate","add","forEach","scrollParent","addEventListener","then","x","y","middlewareData","computedPlacement","coordinates","lowPPI","devicePixelRatio","catch","err","process","env","NODE_ENV","console","error","removeEventListener"],"sources":["../src/createPositionManager.ts"],"sourcesContent":["import { computePosition } from '@floating-ui/dom';\nimport type { Middleware, Placement, Strategy } from '@floating-ui/dom';\nimport type { PositionManager, TargetElement } from './types';\nimport { debounce, writeArrowUpdates, writeContainerUpdates, getScrollParent } from './utils';\nimport { isHTMLElement } from '@fluentui/react-utilities';\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\n/**\n * @internal\n * @returns manager that handles positioning out of the react lifecycle\n */\nexport function createPositionManager(options: PositionManagerOptions): PositionManager {\n const { container, target, arrow, strategy, middleware, placement, useTransform = true } = options;\n let isDestroyed = false;\n if (!target || !container) {\n return {\n updatePosition: () => undefined,\n dispose: () => undefined,\n };\n }\n\n let isFirstUpdate = true;\n const scrollParents: Set<HTMLElement> = new Set<HTMLElement>();\n const targetWindow = container.ownerDocument.defaultView;\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 scrollParents.add(getScrollParent(container));\n if (isHTMLElement(target)) {\n scrollParents.add(getScrollParent(target));\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.addEventListener('scroll', updatePosition);\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 writeArrowUpdates({ arrow, middlewareData });\n writeContainerUpdates({\n container,\n middlewareData,\n placement: computedPlacement,\n coordinates: { x, y },\n lowPPI: (targetWindow?.devicePixelRatio || 1) <= 1,\n strategy,\n useTransform,\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 };\n\n if (targetWindow) {\n targetWindow.addEventListener('scroll', updatePosition);\n targetWindow.addEventListener('resize', updatePosition);\n }\n\n // Update the position on initialization\n updatePosition();\n\n return {\n updatePosition,\n dispose,\n };\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ac,gBAAgB,CAAC,UAAUpB,cAAA;EAC1C;EAEA;EACAA,cAAA;EAEA,OAAO;IACLA,cAAA;IACAE;EACF;AACF"}
1
+ {"version":3,"sources":["createPositionManager.ts"],"sourcesContent":["import { computePosition } from '@floating-ui/dom';\nimport type { Middleware, Placement, Strategy } from '@floating-ui/dom';\nimport type { PositionManager, TargetElement } from './types';\nimport { debounce, writeArrowUpdates, writeContainerUpdates, getScrollParent } from './utils';\nimport { isHTMLElement } from '@fluentui/react-utilities';\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\n/**\n * @internal\n * @returns manager that handles positioning out of the react lifecycle\n */\nexport function createPositionManager(options: PositionManagerOptions): PositionManager {\n const { container, target, arrow, strategy, middleware, placement, useTransform = true } = options;\n let isDestroyed = false;\n if (!target || !container) {\n return {\n updatePosition: () => undefined,\n dispose: () => undefined,\n };\n }\n\n let isFirstUpdate = true;\n const scrollParents: Set<HTMLElement> = new Set<HTMLElement>();\n const targetWindow = container.ownerDocument.defaultView;\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 scrollParents.add(getScrollParent(container));\n if (isHTMLElement(target)) {\n scrollParents.add(getScrollParent(target));\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.addEventListener('scroll', updatePosition);\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 writeArrowUpdates({ arrow, middlewareData });\n writeContainerUpdates({\n container,\n middlewareData,\n placement: computedPlacement,\n coordinates: { x, y },\n lowPPI: (targetWindow?.devicePixelRatio || 1) <= 1,\n strategy,\n useTransform,\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 };\n\n if (targetWindow) {\n targetWindow.addEventListener('scroll', updatePosition);\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","debounce","writeArrowUpdates","writeContainerUpdates","getScrollParent","isHTMLElement","createPositionManager","options","container","target","arrow","strategy","middleware","placement","useTransform","isDestroyed","updatePosition","undefined","dispose","isFirstUpdate","scrollParents","Set","targetWindow","ownerDocument","defaultView","Object","assign","style","position","left","top","margin","forceUpdate","add","forEach","scrollParent","addEventListener","then","x","y","middlewareData","computedPlacement","coordinates","lowPPI","devicePixelRatio","catch","err","process","env","NODE_ENV","console","error","removeEventListener"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AAGnD,SAASC,QAAQ,EAAEC,iBAAiB,EAAEC,qBAAqB,EAAEC,eAAe,QAAQ,UAAU;AAC9F,SAASC,aAAa,QAAQ,4BAA4B;AAmC1D;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,OAA+B,EAAmB;IACtF,MAAM,EAAEC,UAAS,EAAEC,OAAM,EAAEC,MAAK,EAAEC,SAAQ,EAAEC,WAAU,EAAEC,UAAS,EAAEC,cAAe,IAAI,CAAA,EAAE,GAAGP;IAC3F,IAAIQ,cAAc,KAAK;IACvB,IAAI,CAACN,UAAU,CAACD,WAAW;QACzB,OAAO;YACLQ,gBAAgB,IAAMC;YACtBC,SAAS,IAAMD;QACjB;IACF,CAAC;IAED,IAAIE,gBAAgB,IAAI;IACxB,MAAMC,gBAAkC,IAAIC;IAC5C,MAAMC,eAAed,UAAUe,aAAa,CAACC,WAAW;IAExD,oFAAoF;IACpF,gGAAgG;IAChGC,OAAOC,MAAM,CAAClB,UAAUmB,KAAK,EAAE;QAAEC,UAAU;QAASC,MAAM;QAAGC,KAAK;QAAGC,QAAQ;IAAE;IAE/E,MAAMC,cAAc,IAAM;QACxB,8CAA8C;QAC9C,qCAAqC;QACrC,IAAIjB,aAAa;YACf;QACF,CAAC;QAED,IAAII,eAAe;YACjBC,cAAca,GAAG,CAAC7B,gBAAgBI;YAClC,IAAIH,cAAcI,SAAS;gBACzBW,cAAca,GAAG,CAAC7B,gBAAgBK;YACpC,CAAC;YAEDW,cAAcc,OAAO,CAACC,CAAAA,eAAgB;gBACpCA,aAAaC,gBAAgB,CAAC,UAAUpB;YAC1C;YAEAG,gBAAgB,KAAK;QACvB,CAAC;QAEDM,OAAOC,MAAM,CAAClB,UAAUmB,KAAK,EAAE;YAAEC,UAAUjB;QAAS;QACpDX,gBAAgBS,QAAQD,WAAW;Y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position of a click event
3
3
  * Can be used as a target for popper in scenarios such as context menus
4
- */export function createVirtualElementFromClick(nativeEvent) {
5
- const left = nativeEvent.clientX;
6
- const top = nativeEvent.clientY;
7
- const right = left + 1;
8
- const bottom = top + 1;
9
- function getBoundingClientRect() {
4
+ */ export function createVirtualElementFromClick(nativeEvent) {
5
+ const left = nativeEvent.clientX;
6
+ const top = nativeEvent.clientY;
7
+ const right = left + 1;
8
+ const bottom = top + 1;
9
+ function getBoundingClientRect() {
10
+ return {
11
+ left,
12
+ top,
13
+ right,
14
+ bottom,
15
+ x: left,
16
+ y: top,
17
+ height: 1,
18
+ width: 1
19
+ };
20
+ }
10
21
  return {
11
- left,
12
- top,
13
- right,
14
- bottom,
15
- x: left,
16
- y: top,
17
- height: 1,
18
- width: 1
22
+ getBoundingClientRect
19
23
  };
20
- }
21
- return {
22
- getBoundingClientRect
23
- };
24
24
  }
25
- //# sourceMappingURL=createVirtualElementFromClick.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createVirtualElementFromClick","nativeEvent","left","clientX","top","clientY","right","bottom","getBoundingClientRect","x","y","height","width"],"sources":["../src/createVirtualElementFromClick.ts"],"sourcesContent":["import type { PositioningVirtualElement } from './types';\n\n/**\n * Creates a virtual element based on the position of a click event\n * Can be used as a target for popper in scenarios such as context menus\n */\nexport function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect() {\n return {\n left,\n top,\n right,\n bottom,\n x: left,\n y: top,\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"],"mappings":"AAEA;;;GAIA,OAAO,SAASA,8BAA8BC,WAAuB,EAA6B;EAChG,MAAMC,IAAA,GAAOD,WAAA,CAAYE,OAAO;EAChC,MAAMC,GAAA,GAAMH,WAAA,CAAYI,OAAO;EAC/B,MAAMC,KAAA,GAAQJ,IAAA,GAAO;EACrB,MAAMK,MAAA,GAASH,GAAA,GAAM;EAErB,SAASI,sBAAA,EAAwB;IAC/B,OAAO;MACLN,IAAA;MACAE,GAAA;MACAE,KAAA;MACAC,MAAA;MACAE,CAAA,EAAGP,IAAA;MACHQ,CAAA,EAAGN,GAAA;MACHO,MAAA,EAAQ;MACRC,KAAA,EAAO;IACT;EACF;EAEA,OAAO;IACLJ;EACF;AACF"}
1
+ {"version":3,"sources":["createVirtualElementFromClick.ts"],"sourcesContent":["import type { PositioningVirtualElement } from './types';\n\n/**\n * Creates a virtual element based on the position of a click event\n * Can be used as a target for popper in scenarios such as context menus\n */\nexport function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect() {\n return {\n left,\n top,\n right,\n bottom,\n x: left,\n y: top,\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"],"names":["createVirtualElementFromClick","nativeEvent","left","clientX","top","clientY","right","bottom","getBoundingClientRect","x","y","height","width"],"mappings":"AAEA;;;CAGC,GACD,OAAO,SAASA,8BAA8BC,WAAuB,EAA6B;IAChG,MAAMC,OAAOD,YAAYE,OAAO;IAChC,MAAMC,MAAMH,YAAYI,OAAO;IAC/B,MAAMC,QAAQJ,OAAO;IACrB,MAAMK,SAASH,MAAM;IAErB,SAASI,wBAAwB;QAC/B,OAAO;YACLN;YACAE;YACAE;YACAC;YACAE,GAAGP;YACHQ,GAAGN;YACHO,QAAQ;YACRC,OAAO;QACT;IACF;IAEA,OAAO;QACLJ;IACF;AACF,CAAC"}
package/lib/index.js CHANGED
@@ -3,4 +3,3 @@ export { createArrowHeightStyles, createArrowStyles } from './createArrowStyles'
3
3
  export { usePositioning } from './usePositioning';
4
4
  export { usePositioningMouseTarget } from './usePositioningMouseTarget';
5
5
  export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
6
- //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createVirtualElementFromClick","createArrowHeightStyles","createArrowStyles","usePositioning","usePositioningMouseTarget","resolvePositioningShorthand","mergeArrowOffset"],"sources":["../src/index.ts"],"sourcesContent":["export { createVirtualElementFromClick } from './createVirtualElementFromClick';\nexport { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';\nexport type { CreateArrowStylesOptions } from './createArrowStyles';\nexport { usePositioning } from './usePositioning';\nexport { usePositioningMouseTarget } from './usePositioningMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport type {\n Alignment,\n AutoSize,\n Boundary,\n Offset,\n OffsetFunction,\n OffsetFunctionParam,\n OffsetObject,\n OffsetShorthand,\n Position,\n PositioningImperativeRef,\n PositioningProps,\n PositioningShorthand,\n PositioningShorthandValue,\n PositioningVirtualElement,\n SetVirtualMouseTarget,\n} from './types';\n"],"mappings":"AAAA,SAASA,6BAA6B,QAAQ;AAC9C,SAASC,uBAAuB,EAAEC,iBAAiB,QAAQ;AAE3D,SAASC,cAAc,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,2BAA2B,EAAEC,gBAAgB,QAAQ"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export { createVirtualElementFromClick } from './createVirtualElementFromClick';\nexport { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';\nexport type { CreateArrowStylesOptions } from './createArrowStyles';\nexport { usePositioning } from './usePositioning';\nexport { usePositioningMouseTarget } from './usePositioningMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport type {\n Alignment,\n AutoSize,\n Boundary,\n Offset,\n OffsetFunction,\n OffsetFunctionParam,\n OffsetObject,\n OffsetShorthand,\n Position,\n PositioningImperativeRef,\n PositioningProps,\n PositioningShorthand,\n PositioningShorthandValue,\n PositioningVirtualElement,\n SetVirtualMouseTarget,\n} from './types';\n"],"names":["createVirtualElementFromClick","createArrowHeightStyles","createArrowStyles","usePositioning","usePositioningMouseTarget","resolvePositioningShorthand","mergeArrowOffset"],"mappings":"AAAA,SAASA,6BAA6B,QAAQ,kCAAkC;AAChF,SAASC,uBAAuB,EAAEC,iBAAiB,QAAQ,sBAAsB;AAEjF,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,yBAAyB,QAAQ,8BAA8B;AACxE,SAASC,2BAA2B,EAAEC,gBAAgB,QAAQ,gBAAgB"}