floating-ui.dom.d.mts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import { AlignedPlacement } from '@floating-ui/core';
  2. import { Alignment } from '@floating-ui/core';
  3. import type { ArrowOptions as ArrowOptions_2 } from '@floating-ui/core';
  4. import type { AutoPlacementOptions as AutoPlacementOptions_2 } from '@floating-ui/core';
  5. import { Axis } from '@floating-ui/core';
  6. import { ClientRectObject } from '@floating-ui/core';
  7. import type { ComputePositionConfig as ComputePositionConfig_2 } from '@floating-ui/core';
  8. import { ComputePositionReturn } from '@floating-ui/core';
  9. import { Coords } from '@floating-ui/core';
  10. import type { detectOverflow as detectOverflow_2 } from '@floating-ui/core';
  11. import type { DetectOverflowOptions as DetectOverflowOptions_2 } from '@floating-ui/core';
  12. import { Dimensions } from '@floating-ui/core';
  13. import { ElementContext } from '@floating-ui/core';
  14. import { ElementRects } from '@floating-ui/core';
  15. import type { FlipOptions as FlipOptions_2 } from '@floating-ui/core';
  16. import { getOverflowAncestors } from '@floating-ui/utils/dom';
  17. import type { HideOptions as HideOptions_2 } from '@floating-ui/core';
  18. import { InlineOptions } from '@floating-ui/core';
  19. import { Length } from '@floating-ui/core';
  20. import { LimitShiftOptions } from '@floating-ui/core';
  21. import type { Middleware as Middleware_2 } from '@floating-ui/core';
  22. import { MiddlewareData } from '@floating-ui/core';
  23. import { MiddlewareReturn } from '@floating-ui/core';
  24. import type { MiddlewareState as MiddlewareState_2 } from '@floating-ui/core';
  25. import { Padding } from '@floating-ui/core';
  26. import { Placement } from '@floating-ui/core';
  27. import { Rect } from '@floating-ui/core';
  28. import { RootBoundary } from '@floating-ui/core';
  29. import type { ShiftOptions as ShiftOptions_2 } from '@floating-ui/core';
  30. import { Side } from '@floating-ui/core';
  31. import { SideObject } from '@floating-ui/core';
  32. import type { SizeOptions as SizeOptions_2 } from '@floating-ui/core';
  33. import { Strategy } from '@floating-ui/core';
  34. export { AlignedPlacement }
  35. export { Alignment }
  36. /**
  37. * Provides data to position an inner element of the floating element so that it
  38. * appears centered to the reference element.
  39. * @see https://floating-ui.com/docs/arrow
  40. */
  41. export declare const arrow: (options: ArrowOptions | Derivable<ArrowOptions>) => Middleware;
  42. export declare type ArrowOptions = Prettify<Omit<ArrowOptions_2, 'element'> & {
  43. element: Element;
  44. }>;
  45. /**
  46. * Optimizes the visibility of the floating element by choosing the placement
  47. * that has the most space available automatically, without needing to specify a
  48. * preferred placement. Alternative to `flip`.
  49. * @see https://floating-ui.com/docs/autoPlacement
  50. */
  51. export declare const autoPlacement: (options?: AutoPlacementOptions | Derivable<AutoPlacementOptions>) => Middleware;
  52. export declare type AutoPlacementOptions = Prettify<Omit<AutoPlacementOptions_2, 'boundary'> & DetectOverflowOptions>;
  53. /**
  54. * Automatically updates the position of the floating element when necessary.
  55. * Should only be called when the floating element is mounted on the DOM or
  56. * visible on the screen.
  57. * @returns cleanup function that should be invoked when the floating element is
  58. * removed from the DOM or hidden from the screen.
  59. * @see https://floating-ui.com/docs/autoUpdate
  60. */
  61. export declare function autoUpdate(reference: ReferenceElement, floating: FloatingElement | null, update: () => void, options?: AutoUpdateOptions): () => void;
  62. export declare interface AutoUpdateOptions {
  63. /**
  64. * Whether to update the position when an overflow ancestor is scrolled.
  65. * @default true
  66. */
  67. ancestorScroll?: boolean;
  68. /**
  69. * Whether to update the position when an overflow ancestor is resized. This
  70. * uses the native `resize` event.
  71. * @default true
  72. */
  73. ancestorResize?: boolean;
  74. /**
  75. * Whether to update the position when either the reference or floating
  76. * elements resized. This uses a `ResizeObserver`.
  77. * @default true
  78. */
  79. elementResize?: boolean;
  80. /**
  81. * Whether to update the position when the reference relocated on the screen
  82. * due to layout shift.
  83. * @default true
  84. */
  85. layoutShift?: boolean;
  86. /**
  87. * Whether to update on every animation frame if necessary. Only use if you
  88. * need to update the position in response to an animation using transforms.
  89. * @default false
  90. */
  91. animationFrame?: boolean;
  92. }
  93. export { Axis }
  94. /**
  95. * The clipping boundary area of the floating element.
  96. */
  97. export declare type Boundary = 'clippingAncestors' | Element | Array<Element> | Rect;
  98. export { ClientRectObject }
  99. /**
  100. * Computes the `x` and `y` coordinates that will place the floating element
  101. * next to a given reference element.
  102. */
  103. export declare const computePosition: (reference: ReferenceElement, floating: FloatingElement, options?: Partial<ComputePositionConfig>) => Promise<ComputePositionReturn>;
  104. export declare type ComputePositionConfig = Prettify<Omit<ComputePositionConfig_2, 'middleware' | 'platform'> & {
  105. /**
  106. * Array of middleware objects to modify the positioning or provide data for
  107. * rendering.
  108. */
  109. middleware?: Array<Middleware | null | undefined | false>;
  110. /**
  111. * Custom or extended platform object.
  112. */
  113. platform?: Platform;
  114. }>;
  115. export { ComputePositionReturn }
  116. export { Coords }
  117. export declare type Derivable<T> = (state: MiddlewareState) => T;
  118. /**
  119. * Resolves with an object of overflow side offsets that determine how much the
  120. * element is overflowing a given clipping boundary on each side.
  121. * - positive = overflowing the boundary by that number of pixels
  122. * - negative = how many pixels left before it will overflow
  123. * - 0 = lies flush with the boundary
  124. * @see https://floating-ui.com/docs/detectOverflow
  125. */
  126. export declare const detectOverflow: (state: MiddlewareState, options?: DetectOverflowOptions | Derivable<DetectOverflowOptions>) => Promise<SideObject>;
  127. export declare type DetectOverflowOptions = Prettify<Omit<DetectOverflowOptions_2, 'boundary'> & {
  128. boundary?: Boundary;
  129. }>;
  130. export { Dimensions }
  131. export { ElementContext }
  132. export { ElementRects }
  133. export declare interface Elements {
  134. reference: ReferenceElement;
  135. floating: FloatingElement;
  136. }
  137. /**
  138. * Optimizes the visibility of the floating element by flipping the `placement`
  139. * in order to keep it in view when the preferred placement(s) will overflow the
  140. * clipping boundary. Alternative to `autoPlacement`.
  141. * @see https://floating-ui.com/docs/flip
  142. */
  143. export declare const flip: (options?: FlipOptions | Derivable<FlipOptions>) => Middleware;
  144. export declare type FlipOptions = Prettify<Omit<FlipOptions_2, 'boundary'> & DetectOverflowOptions>;
  145. export declare type FloatingElement = HTMLElement;
  146. export { getOverflowAncestors }
  147. /**
  148. * Provides data to hide the floating element in applicable situations, such as
  149. * when it is not in the same clipping context as the reference element.
  150. * @see https://floating-ui.com/docs/hide
  151. */
  152. export declare const hide: (options?: HideOptions | Derivable<HideOptions>) => Middleware;
  153. export declare type HideOptions = Prettify<Omit<HideOptions_2, 'boundary'> & DetectOverflowOptions>;
  154. /**
  155. * Provides improved positioning for inline reference elements that can span
  156. * over multiple lines, such as hyperlinks or range selections.
  157. * @see https://floating-ui.com/docs/inline
  158. */
  159. export declare const inline: (options?: InlineOptions | Derivable<InlineOptions>) => Middleware;
  160. export { InlineOptions }
  161. export { Length }
  162. /**
  163. * Built-in `limiter` that will stop `shift()` at a certain point.
  164. */
  165. export declare const limitShift: (options?: LimitShiftOptions | Derivable<LimitShiftOptions>) => {
  166. options: any;
  167. fn: (state: MiddlewareState) => Coords;
  168. };
  169. export { LimitShiftOptions }
  170. export declare type Middleware = Prettify<Omit<Middleware_2, 'fn'> & {
  171. fn(state: MiddlewareState): Promisable<MiddlewareReturn>;
  172. }>;
  173. /**
  174. * @deprecated use `MiddlewareState` instead.
  175. */
  176. export declare type MiddlewareArguments = MiddlewareState;
  177. export { MiddlewareData }
  178. export { MiddlewareReturn }
  179. export declare type MiddlewareState = Prettify<Omit<MiddlewareState_2, 'elements'> & {
  180. elements: Elements;
  181. }>;
  182. export declare interface NodeScroll {
  183. scrollLeft: number;
  184. scrollTop: number;
  185. }
  186. /**
  187. * Modifies the placement by translating the floating element along the
  188. * specified axes.
  189. * A number (shorthand for `mainAxis` or distance), or an axes configuration
  190. * object may be passed.
  191. * @see https://floating-ui.com/docs/offset
  192. */
  193. export declare const offset: (options?: OffsetOptions) => Middleware;
  194. export declare type OffsetOptions = OffsetValue | Derivable<OffsetValue>;
  195. declare type OffsetValue = number | {
  196. /**
  197. * The axis that runs along the side of the floating element. Represents
  198. * the distance (gutter or margin) between the reference and floating
  199. * element.
  200. * @default 0
  201. */
  202. mainAxis?: number;
  203. /**
  204. * The axis that runs along the alignment of the floating element.
  205. * Represents the skidding between the reference and floating element.
  206. * @default 0
  207. */
  208. crossAxis?: number;
  209. /**
  210. * The same axis as `crossAxis` but applies only to aligned placements
  211. * and inverts the `end` alignment. When set to a number, it overrides the
  212. * `crossAxis` value.
  213. *
  214. * A positive number will move the floating element in the direction of
  215. * the opposite edge to the one that is aligned, while a negative number
  216. * the reverse.
  217. * @default null
  218. */
  219. alignmentAxis?: number | null;
  220. };
  221. export { Padding }
  222. export { Placement }
  223. export declare interface Platform {
  224. getElementRects: (args: {
  225. reference: ReferenceElement;
  226. floating: FloatingElement;
  227. strategy: Strategy;
  228. }) => Promisable<ElementRects>;
  229. getClippingRect: (args: {
  230. element: Element;
  231. boundary: Boundary;
  232. rootBoundary: RootBoundary;
  233. strategy: Strategy;
  234. }) => Promisable<Rect>;
  235. getDimensions: (element: Element) => Promisable<Dimensions>;
  236. convertOffsetParentRelativeRectToViewportRelativeRect: (args: {
  237. elements?: Elements;
  238. rect: Rect;
  239. offsetParent: Element;
  240. strategy: Strategy;
  241. }) => Promisable<Rect>;
  242. getOffsetParent: (element: Element, polyfill?: (element: HTMLElement) => Element | null) => Promisable<Element | Window>;
  243. isElement: (value: unknown) => Promisable<boolean>;
  244. getDocumentElement: (element: Element) => Promisable<HTMLElement>;
  245. getClientRects: (element: Element) => Promisable<Array<ClientRectObject>>;
  246. isRTL: (element: Element) => Promisable<boolean>;
  247. getScale: (element: HTMLElement) => Promisable<{
  248. x: number;
  249. y: number;
  250. }>;
  251. detectOverflow?: typeof detectOverflow_2;
  252. }
  253. export declare const platform: Platform;
  254. declare type Prettify<T> = {
  255. [K in keyof T]: T[K];
  256. } & {};
  257. declare type Promisable<T> = T | Promise<T>;
  258. export { Rect }
  259. export declare type ReferenceElement = Element | VirtualElement;
  260. export { RootBoundary }
  261. /**
  262. * Optimizes the visibility of the floating element by shifting it in order to
  263. * keep it in view when it will overflow the clipping boundary.
  264. * @see https://floating-ui.com/docs/shift
  265. */
  266. export declare const shift: (options?: ShiftOptions | Derivable<ShiftOptions>) => Middleware;
  267. export declare type ShiftOptions = Prettify<Omit<ShiftOptions_2, 'boundary'> & DetectOverflowOptions>;
  268. export { Side }
  269. export { SideObject }
  270. /**
  271. * Provides data that allows you to change the size of the floating element —
  272. * for instance, prevent it from overflowing the clipping boundary or match the
  273. * width of the reference element.
  274. * @see https://floating-ui.com/docs/size
  275. */
  276. export declare const size: (options?: SizeOptions | Derivable<SizeOptions>) => Middleware;
  277. export declare type SizeOptions = Prettify<Omit<SizeOptions_2, 'apply' | 'boundary'> & DetectOverflowOptions & {
  278. /**
  279. * Function that is called to perform style mutations to the floating element
  280. * to change its size.
  281. * @default undefined
  282. */
  283. apply?(args: MiddlewareState & {
  284. availableWidth: number;
  285. availableHeight: number;
  286. }): Promisable<void>;
  287. }>;
  288. export { Strategy }
  289. /**
  290. * Custom positioning reference element.
  291. * @see https://floating-ui.com/docs/virtual-elements
  292. */
  293. export declare interface VirtualElement {
  294. getBoundingClientRect(): ClientRectObject;
  295. getClientRects?(): Array<ClientRectObject> | DOMRectList;
  296. contextElement?: Element;
  297. }
  298. export { }