@vielzeug/orbit 1.1.5 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +18 -58
  2. package/dist/auto-update.cjs +1 -1
  3. package/dist/auto-update.cjs.map +1 -1
  4. package/dist/auto-update.d.ts.map +1 -1
  5. package/dist/auto-update.js +1 -1
  6. package/dist/auto-update.js.map +1 -1
  7. package/dist/core.cjs +1 -1
  8. package/dist/core.cjs.map +1 -1
  9. package/dist/core.d.ts.map +1 -1
  10. package/dist/core.js +1 -1
  11. package/dist/core.js.map +1 -1
  12. package/dist/devtools.cjs +1 -1
  13. package/dist/devtools.cjs.map +1 -1
  14. package/dist/devtools.d.ts +7 -7
  15. package/dist/devtools.d.ts.map +1 -1
  16. package/dist/devtools.js +1 -1
  17. package/dist/devtools.js.map +1 -1
  18. package/dist/float.cjs +1 -1
  19. package/dist/float.cjs.map +1 -1
  20. package/dist/float.d.ts +18 -65
  21. package/dist/float.d.ts.map +1 -1
  22. package/dist/float.js +1 -1
  23. package/dist/float.js.map +1 -1
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.d.ts +3 -5
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/inline.cjs +1 -1
  29. package/dist/inline.cjs.map +1 -1
  30. package/dist/inline.d.ts +3 -2
  31. package/dist/inline.d.ts.map +1 -1
  32. package/dist/inline.js +1 -1
  33. package/dist/inline.js.map +1 -1
  34. package/dist/middleware/arrow.cjs +1 -1
  35. package/dist/middleware/arrow.cjs.map +1 -1
  36. package/dist/middleware/arrow.d.ts +2 -2
  37. package/dist/middleware/arrow.d.ts.map +1 -1
  38. package/dist/middleware/arrow.js +1 -1
  39. package/dist/middleware/arrow.js.map +1 -1
  40. package/dist/middleware/auto-placement.cjs +1 -1
  41. package/dist/middleware/auto-placement.cjs.map +1 -1
  42. package/dist/middleware/auto-placement.d.ts.map +1 -1
  43. package/dist/middleware/auto-placement.js +1 -1
  44. package/dist/middleware/auto-placement.js.map +1 -1
  45. package/dist/middleware/flip.cjs +1 -1
  46. package/dist/middleware/flip.cjs.map +1 -1
  47. package/dist/middleware/flip.d.ts +2 -2
  48. package/dist/middleware/flip.d.ts.map +1 -1
  49. package/dist/middleware/flip.js +1 -1
  50. package/dist/middleware/flip.js.map +1 -1
  51. package/dist/middleware/hide.cjs +1 -1
  52. package/dist/middleware/hide.cjs.map +1 -1
  53. package/dist/middleware/hide.d.ts +2 -2
  54. package/dist/middleware/hide.d.ts.map +1 -1
  55. package/dist/middleware/hide.js +1 -1
  56. package/dist/middleware/hide.js.map +1 -1
  57. package/dist/middleware/offset.cjs +1 -1
  58. package/dist/middleware/offset.cjs.map +1 -1
  59. package/dist/middleware/offset.js +1 -1
  60. package/dist/middleware/offset.js.map +1 -1
  61. package/dist/middleware/shift.cjs +1 -1
  62. package/dist/middleware/shift.cjs.map +1 -1
  63. package/dist/middleware/shift.d.ts +2 -2
  64. package/dist/middleware/shift.d.ts.map +1 -1
  65. package/dist/middleware/shift.js +1 -1
  66. package/dist/middleware/shift.js.map +1 -1
  67. package/dist/middleware/size.cjs +1 -1
  68. package/dist/middleware/size.cjs.map +1 -1
  69. package/dist/middleware/size.d.ts +6 -5
  70. package/dist/middleware/size.d.ts.map +1 -1
  71. package/dist/middleware/size.js +1 -1
  72. package/dist/middleware/size.js.map +1 -1
  73. package/dist/orbit.cjs +1 -1
  74. package/dist/orbit.cjs.map +1 -1
  75. package/dist/orbit.iife.js +1 -1
  76. package/dist/orbit.iife.js.map +1 -1
  77. package/dist/orbit.js +1 -1
  78. package/dist/orbit.js.map +1 -1
  79. package/dist/presets.cjs.map +1 -1
  80. package/dist/presets.d.ts +9 -5
  81. package/dist/presets.d.ts.map +1 -1
  82. package/dist/presets.js.map +1 -1
  83. package/dist/reactive.cjs +1 -1
  84. package/dist/reactive.cjs.map +1 -1
  85. package/dist/reactive.d.ts +6 -43
  86. package/dist/reactive.d.ts.map +1 -1
  87. package/dist/reactive.js +1 -1
  88. package/dist/reactive.js.map +1 -1
  89. package/dist/types.d.ts +2 -29
  90. package/dist/types.d.ts.map +1 -1
  91. package/dist/utils.cjs +1 -1
  92. package/dist/utils.cjs.map +1 -1
  93. package/dist/utils.d.ts +1 -2
  94. package/dist/utils.d.ts.map +1 -1
  95. package/dist/utils.js +1 -1
  96. package/dist/utils.js.map +1 -1
  97. package/package.json +10 -13
  98. package/dist/compose.cjs +0 -2
  99. package/dist/compose.cjs.map +0 -1
  100. package/dist/compose.d.ts +0 -25
  101. package/dist/compose.d.ts.map +0 -1
  102. package/dist/compose.js +0 -2
  103. package/dist/compose.js.map +0 -1
  104. package/dist/ssr.cjs +0 -2
  105. package/dist/ssr.cjs.map +0 -1
  106. package/dist/ssr.d.ts +0 -41
  107. package/dist/ssr.d.ts.map +0 -1
  108. package/dist/ssr.js +0 -2
  109. package/dist/ssr.js.map +0 -1
package/dist/float.d.ts CHANGED
@@ -1,73 +1,26 @@
1
- import type { ComputePositionOptions, ComputePositionResult, FloatHandle, Placement, ReferenceElement } from './types';
1
+ import type { ComputePositionOptions, ComputePositionResult, ReferenceElement } from './types';
2
2
  import { type AutoUpdateOptions } from './auto-update';
3
- declare function isCssAnchorPositioningSupported(): boolean;
4
- export interface CssAnchorHandle extends FloatHandle {
5
- /** Always `true` — position is managed natively by CSS Anchor Positioning. */
6
- readonly cssAnchor: true;
7
- }
8
- /**
9
- * Uses CSS Anchor Positioning to let the browser handle repositioning natively.
10
- * No JavaScript positioning loop — the browser manages placement via `position-try-fallbacks`.
11
- *
12
- * Requires both elements to be `HTMLElement`. Falls back to `float()` for complex cases
13
- * (e.g. middleware pipelines, custom apply callbacks).
14
- *
15
- * @experimental CSS Anchor Positioning support varies by browser. Check `isCssAnchorSupported()`
16
- * before using in production.
17
- *
18
- * @example
19
- * ```ts
20
- * import { floatWithAnchor } from '@vielzeug/orbit';
21
- *
22
- * const handle = floatWithAnchor(trigger, tooltip, { placement: 'top' });
23
- * // on hide:
24
- * handle.dispose();
25
- * ```
26
- */
27
- export declare function floatWithAnchor(reference: HTMLElement, floating: HTMLElement, { fallbacks, placement, }?: {
28
- fallbacks?: string;
29
- placement?: Placement;
30
- }): CssAnchorHandle;
31
- /**
32
- * Returns `true` when the browser supports CSS Anchor Positioning.
33
- * Use to guard `floatWithAnchor()` calls in production.
34
- */
35
- export { isCssAnchorPositioningSupported as isCssAnchorSupported };
36
- /**
37
- * Options for `float()`. Extends `ComputePositionOptions` so all positioning
38
- * options (`placement`, `middleware`, `boundary`, `padding`, `containingBlock`)
39
- * are inherited directly.
40
- */
41
- export interface FloatOptions extends ComputePositionOptions {
42
- /**
43
- * Custom callback to apply the computed position to the DOM.
44
- * Called once per position update with the full `ComputePositionResult`.
45
- * Defaults to writing `left` / `top` on the floating element (requires `position: fixed`).
46
- */
3
+ export type PositionStrategy = 'absolute' | 'fixed';
4
+ export interface PositionerOptions extends Omit<ComputePositionOptions, 'boundary' | 'containingBlock'> {
47
5
  apply?: (result: ComputePositionResult) => void;
48
- /**
49
- * Options for the auto-update loop. Omit to use defaults.
50
- * Pass `false` to disable auto-updating (position is computed once on call).
51
- */
52
6
  autoUpdate?: AutoUpdateOptions | false;
7
+ boundary?: ComputePositionOptions['boundary'] | 'clippingAncestors';
8
+ strategy?: PositionStrategy;
9
+ }
10
+ export interface Positioner {
11
+ readonly disposalSignal: AbortSignal;
12
+ dispose(): void;
13
+ readonly disposed: boolean;
14
+ getPosition(): ComputePositionResult | null;
15
+ start(): void;
16
+ update(): void;
17
+ [Symbol.dispose](): void;
53
18
  }
54
19
  /**
55
- * High-level API: positions the floating element and continuously keeps it updated.
56
- *
57
- * For CSS Anchor Positioning (browser-native, no JS loop), use {@link floatWithAnchor} instead.
58
- *
59
- * Returns a {@link FloatHandle} with `dispose()`, `update()`, and `getPosition()`.
60
- * Always call `dispose()` on teardown to remove listeners.
20
+ * Creates a lifecycle-owned floating positioner.
61
21
  *
62
- * @example
63
- * ```ts
64
- * const handle = float(trigger, tooltip, {
65
- * placement: 'top',
66
- * middleware: [offset(8), flip(), shift({ padding: 6 })],
67
- * });
68
- * // on hide:
69
- * handle.dispose();
70
- * ```
22
+ * The positioner owns coordinate strategy, clipping-boundary resolution, updates, and cleanup.
23
+ * Call `start()` once the elements are mounted, then call `dispose()` when their owner ends.
71
24
  */
72
- export declare function float(reference: ReferenceElement, floating: HTMLElement, { apply, autoUpdate: autoUpdateOptions, boundary, containingBlock, middleware, padding, placement, }?: FloatOptions): FloatHandle;
25
+ export declare function createPositioner(reference: ReferenceElement, floating: HTMLElement, { apply, autoUpdate: autoUpdateOptions, boundary: boundaryOption, middleware, padding, placement, strategy, }?: PositionerOptions): Positioner;
73
26
  //# sourceMappingURL=float.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"float.d.ts","sourceRoot":"","sources":["../src/float.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEvH,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAyCnE,iBAAS,+BAA+B,IAAI,OAAO,CAElD;AAqED,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,WAAW,EACrB,EACE,SAA6D,EAC7D,SAAoB,GACrB,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAA;CAAO,GACpD,eAAe,CASjB;AAED;;;GAGG;AACH,OAAO,EAAE,+BAA+B,IAAI,oBAAoB,EAAE,CAAC;AAInE;;;;GAIG;AACH,MAAM,WAAW,YAAa,SAAQ,sBAAsB;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,CAAC;IACf,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;CAC1B;AAkDD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,WAAW,EACrB,EACE,KAAK,EACL,UAAU,EAAE,iBAAsB,EAClC,QAAQ,EAAE,cAAoC,EAC9C,UAAU,EACV,OAAO,EACP,SAAoB,EACpB,QAAkB,GACnB,GAAE,iBAAsB,GACxB,UAAU,CAmCZ"}
package/dist/float.js CHANGED
@@ -1,2 +1,2 @@
1
- import{autoUpdate as e}from"./auto-update.js";import{computePosition as t}from"./core.js";function n(e,t,n){let r=new AbortController,i=!1;return{get disposalSignal(){return r.signal},dispose(){i||(i=!0,r.abort(),e())},get disposed(){return i},getPosition:t,[Symbol.dispose](){this.dispose()},update:n}}function r(){return typeof CSS<`u`&&CSS.supports(`anchor-name`,`--orbit`)}var i=0,a={bottom:`block-end center`,"bottom-end":`block-end span-inline-end`,"bottom-start":`block-end span-inline-start`,left:`inline-start center`,"left-end":`inline-start span-block-end`,"left-start":`inline-start span-block-start`,right:`inline-end center`,"right-end":`inline-end span-block-end`,"right-start":`inline-end span-block-start`,top:`block-start center`,"top-end":`block-start span-inline-end`,"top-start":`block-start span-inline-start`};function o(e,t){let n={};for(let r of Object.keys(t)){let i=e.style.getPropertyValue(r);n[r]=i===``?void 0:i,e.style.setProperty(r,t[r])}return()=>{for(let r of Object.keys(t)){let t=n[r];t===void 0?e.style.removeProperty(r):e.style.setProperty(r,t)}}}function s(e,t,n,r){let s=`--orbit-${++i}`,c=o(e,{"anchor-name":s}),l=o(t,{position:`fixed`,"position-anchor":s,"position-area":a[n],"position-try-fallbacks":r});return()=>{c(),l()}}function c(e,t,{fallbacks:r=`flip-block, flip-inline, flip-block flip-inline`,placement:i=`bottom`}={}){let a=s(e,t,i,r),o=n(()=>a(),()=>null,()=>{});return Object.assign(o,{cssAnchor:!0})}function l(e,t){t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function u(r,i,{apply:a,autoUpdate:o={},boundary:s,containingBlock:c,middleware:u,padding:d,placement:f=`bottom`}={}){let p=null,m=a??(e=>l(e,i));function h(){let e=t(r,i,{boundary:s,containingBlock:c,middleware:u,padding:d,placement:f});p=e,m(e)}if(o===!1)return h(),n(()=>{},()=>p,h);let g=e(r,i,h,o);return n(()=>g(),()=>p,h)}export{u as float,c as floatWithAnchor,r as isCssAnchorSupported,n as makeHandle};
1
+ import{autoUpdate as e}from"./auto-update.js";import{getContainingBlock as t}from"./containing-block.js";import{computePosition as n}from"./core.js";import{getClippingAncestorRect as r}from"./overflow.js";function i(e,t,n,r){let i=new AbortController,a=!1;return{get disposalSignal(){return i.signal},dispose(){a||(a=!0,i.abort(),e())},get disposed(){return a},getPosition:t,start(){a||n()},[Symbol.dispose](){this.dispose()},update(){a||r()}}}function a(e,n){return n===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:t(e)}function o(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function s(t,s,{apply:c,autoUpdate:l={},boundary:u=`clippingAncestors`,middleware:d,padding:f,placement:p=`bottom`,strategy:m=`fixed`}={}){let h=!0,g,_=null,v=!1;function y(){if(!h)return;let e=a(s,m),i=u===`clippingAncestors`?r(s):u,l=n(t,s,{boundary:i,containingBlock:e,middleware:d,padding:f,placement:p});_=l,(c??(e=>o(e,s,m)))(l)}function b(){v||(v=!0,l===!1?y():g=e(t,s,y,l))}return i(()=>{h=!1,g?.()},()=>_,b,y)}export{s as createPositioner};
2
2
  //# sourceMappingURL=float.js.map
package/dist/float.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"float.js","names":[],"sources":["../src/float.ts"],"sourcesContent":["import type { ComputePositionOptions, ComputePositionResult, FloatHandle, Placement, ReferenceElement } from './types';\n\nimport { autoUpdate, type AutoUpdateOptions } from './auto-update';\nimport { computePosition } from './core';\n\n// ── makeHandle ────────────────────────────────────────────────────────────────\n\n/**\n * Constructs a {@link FloatHandle} with idempotent dispose, disposalSignal, and disposed getter.\n * @internal — exported for use by ssr.ts and devtools.ts only.\n */\nexport function makeHandle(\n rawDispose: () => void,\n getPosition: () => ComputePositionResult | null,\n update: () => void,\n): FloatHandle {\n const controller = new AbortController();\n let disposed = false;\n\n return {\n get disposalSignal() {\n return controller.signal;\n },\n dispose() {\n if (disposed) return;\n\n disposed = true;\n controller.abort();\n rawDispose();\n },\n get disposed() {\n return disposed;\n },\n getPosition,\n [Symbol.dispose](): void {\n this.dispose();\n },\n update,\n };\n}\n\n// ── CSS Anchor Positioning ────────────────────────────────────────────────────\n\nfunction isCssAnchorPositioningSupported(): boolean {\n return typeof CSS !== 'undefined' && CSS.supports('anchor-name', '--orbit');\n}\n\nlet anchorCounter = 0;\n\n/**\n * Maps a placement to the CSS `position-area` value.\n * https://drafts.csswg.org/css-anchor-position/#position-area\n */\nconst POSITION_AREA: Record<Placement, string> = {\n bottom: 'block-end center',\n 'bottom-end': 'block-end span-inline-end',\n 'bottom-start': 'block-end span-inline-start',\n left: 'inline-start center',\n 'left-end': 'inline-start span-block-end',\n 'left-start': 'inline-start span-block-start',\n right: 'inline-end center',\n 'right-end': 'inline-end span-block-end',\n 'right-start': 'inline-end span-block-start',\n top: 'block-start center',\n 'top-end': 'block-start span-inline-end',\n 'top-start': 'block-start span-inline-start',\n};\n\n/** Applies a set of CSS properties to an element and returns a cleanup that restores them. */\nfunction withStyles(el: HTMLElement, props: Record<string, string>): () => void {\n const saved: Record<string, string | undefined> = {};\n\n for (const prop of Object.keys(props)) {\n const prev = el.style.getPropertyValue(prop);\n\n saved[prop] = prev !== '' ? prev : undefined;\n el.style.setProperty(prop, props[prop]);\n }\n\n return () => {\n for (const prop of Object.keys(props)) {\n const prev = saved[prop];\n\n if (prev !== undefined) {\n el.style.setProperty(prop, prev);\n } else {\n el.style.removeProperty(prop);\n }\n }\n };\n}\n\nfunction setupCssAnchorPositioning(\n reference: HTMLElement,\n floating: HTMLElement,\n placement: Placement,\n fallbacks: string,\n): () => void {\n const name = `--orbit-${++anchorCounter}`;\n\n const cleanupRef = withStyles(reference, { 'anchor-name': name });\n const cleanupFloat = withStyles(floating, {\n position: 'fixed',\n 'position-anchor': name,\n 'position-area': POSITION_AREA[placement],\n 'position-try-fallbacks': fallbacks,\n });\n\n return () => {\n cleanupRef();\n cleanupFloat();\n };\n}\n\nexport interface CssAnchorHandle extends FloatHandle {\n /** Always `true` — position is managed natively by CSS Anchor Positioning. */\n readonly cssAnchor: true;\n}\n\n/**\n * Uses CSS Anchor Positioning to let the browser handle repositioning natively.\n * No JavaScript positioning loop — the browser manages placement via `position-try-fallbacks`.\n *\n * Requires both elements to be `HTMLElement`. Falls back to `float()` for complex cases\n * (e.g. middleware pipelines, custom apply callbacks).\n *\n * @experimental CSS Anchor Positioning support varies by browser. Check `isCssAnchorSupported()`\n * before using in production.\n *\n * @example\n * ```ts\n * import { floatWithAnchor } from '@vielzeug/orbit';\n *\n * const handle = floatWithAnchor(trigger, tooltip, { placement: 'top' });\n * // on hide:\n * handle.dispose();\n * ```\n */\nexport function floatWithAnchor(\n reference: HTMLElement,\n floating: HTMLElement,\n {\n fallbacks = 'flip-block, flip-inline, flip-block flip-inline',\n placement = 'bottom',\n }: { fallbacks?: string; placement?: Placement } = {},\n): CssAnchorHandle {\n const cleanupFn = setupCssAnchorPositioning(reference, floating, placement, fallbacks);\n const base = makeHandle(\n () => cleanupFn(),\n () => null,\n () => {},\n );\n\n return Object.assign(base, { cssAnchor: true as const });\n}\n\n/**\n * Returns `true` when the browser supports CSS Anchor Positioning.\n * Use to guard `floatWithAnchor()` calls in production.\n */\nexport { isCssAnchorPositioningSupported as isCssAnchorSupported };\n\n// ── float() ───────────────────────────────────────────────────────────────────\n\n/**\n * Options for `float()`. Extends `ComputePositionOptions` so all positioning\n * options (`placement`, `middleware`, `boundary`, `padding`, `containingBlock`)\n * are inherited directly.\n */\nexport interface FloatOptions extends ComputePositionOptions {\n /**\n * Custom callback to apply the computed position to the DOM.\n * Called once per position update with the full `ComputePositionResult`.\n * Defaults to writing `left` / `top` on the floating element (requires `position: fixed`).\n */\n apply?: (result: ComputePositionResult) => void;\n /**\n * Options for the auto-update loop. Omit to use defaults.\n * Pass `false` to disable auto-updating (position is computed once on call).\n */\n autoUpdate?: AutoUpdateOptions | false;\n}\n\nfunction applyDefault(result: ComputePositionResult, floating: HTMLElement): void {\n floating.style.left = `${result.x}px`;\n floating.style.top = `${result.y}px`;\n}\n\n/**\n * High-level API: positions the floating element and continuously keeps it updated.\n *\n * For CSS Anchor Positioning (browser-native, no JS loop), use {@link floatWithAnchor} instead.\n *\n * Returns a {@link FloatHandle} with `dispose()`, `update()`, and `getPosition()`.\n * Always call `dispose()` on teardown to remove listeners.\n *\n * @example\n * ```ts\n * const handle = float(trigger, tooltip, {\n * placement: 'top',\n * middleware: [offset(8), flip(), shift({ padding: 6 })],\n * });\n * // on hide:\n * handle.dispose();\n * ```\n */\nexport function float(\n reference: ReferenceElement,\n floating: HTMLElement,\n {\n apply,\n autoUpdate: autoUpdateOptions = {},\n boundary,\n containingBlock,\n middleware,\n padding,\n placement = 'bottom',\n }: FloatOptions = {},\n): FloatHandle {\n let lastPosition: ComputePositionResult | null = null;\n const applyFn = apply ?? ((result) => applyDefault(result, floating));\n\n function update(): void {\n const result = computePosition(reference, floating, { boundary, containingBlock, middleware, padding, placement });\n\n lastPosition = result;\n applyFn(result);\n }\n\n if (autoUpdateOptions === false) {\n update();\n\n return makeHandle(\n () => {},\n () => lastPosition,\n update,\n );\n }\n\n const cleanupFn = autoUpdate(reference, floating, update, autoUpdateOptions);\n\n return makeHandle(\n () => cleanupFn(),\n () => lastPosition,\n update,\n );\n}\n"],"mappings":"0FAWA,SAAgB,EACd,EACA,EACA,EACa,CACb,IAAM,EAAa,IAAI,gBACnB,EAAW,GAEf,MAAO,CACL,IAAI,gBAAiB,CACnB,OAAO,EAAW,MACpB,EACA,SAAU,CACJ,IAEJ,EAAW,GACX,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U,MACV,SACA,CAAC,CACT,EAEA,OAAO,OAAO,OAAO,EAAM,CAAE,UAAW,EAAc,CAAC,CACzD,CA6BA,SAAS,EAAa,EAA+B,EAA6B,CAChF,EAAS,MAAM,KAAO,GAAG,EAAO,EAAE,IAClC,EAAS,MAAM,IAAM,GAAG,EAAO,EAAE,GACnC,CAoBA,SAAgB,EACd,EACA,EACA,CACE,QACA,WAAY,EAAoB,CAAC,EACjC,WACA,kBACA,aACA,UACA,YAAY,UACI,CAAC,EACN,CACb,IAAI,EAA6C,KAC3C,EAAU,IAAW,GAAW,EAAa,EAAQ,CAAQ,GAEnE,SAAS,GAAe,CACtB,IAAM,EAAS,EAAgB,EAAW,EAAU,CAAE,WAAU,kBAAiB,aAAY,UAAS,WAAU,CAAC,EAEjH,EAAe,EACf,EAAQ,CAAM,CAChB,CAEA,GAAI,IAAsB,GAGxB,OAFA,EAAO,EAEA,MACC,CAAC,MACD,EACN,CACF,EAGF,IAAM,EAAY,EAAW,EAAW,EAAU,EAAQ,CAAiB,EAE3E,OAAO,MACC,EAAU,MACV,EACN,CACF,CACF"}
1
+ {"version":3,"file":"float.js","names":[],"sources":["../src/float.ts"],"sourcesContent":["import type { ComputePositionOptions, ComputePositionResult, ReferenceElement } from './types';\n\nimport { autoUpdate, type AutoUpdateOptions } from './auto-update';\nimport { getContainingBlock } from './containing-block';\nimport { computePosition } from './core';\nimport { getClippingAncestorRect } from './overflow';\n\nexport type PositionStrategy = 'absolute' | 'fixed';\n\nexport interface PositionerOptions extends Omit<ComputePositionOptions, 'boundary' | 'containingBlock'> {\n apply?: (result: ComputePositionResult) => void;\n autoUpdate?: AutoUpdateOptions | false;\n boundary?: ComputePositionOptions['boundary'] | 'clippingAncestors';\n strategy?: PositionStrategy;\n}\n\nexport interface Positioner {\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n getPosition(): ComputePositionResult | null;\n start(): void;\n update(): void;\n [Symbol.dispose](): void;\n}\n\nfunction makePositioner(\n rawDispose: () => void,\n getPosition: () => ComputePositionResult | null,\n start: () => void,\n update: () => void,\n): Positioner {\n const controller = new AbortController();\n let disposed = false;\n\n return {\n get disposalSignal() {\n return controller.signal;\n },\n dispose() {\n if (disposed) return;\n\n disposed = true;\n controller.abort();\n rawDispose();\n },\n get disposed() {\n return disposed;\n },\n getPosition,\n start(): void {\n if (!disposed) start();\n },\n [Symbol.dispose](): void {\n this.dispose();\n },\n update(): void {\n if (!disposed) update();\n },\n };\n}\n\nfunction resolveContainingBlock(floating: HTMLElement, strategy: PositionStrategy): Element | null {\n if (strategy === 'absolute') return floating.offsetParent instanceof Element ? floating.offsetParent : null;\n\n return getContainingBlock(floating);\n}\n\nfunction applyDefault(result: ComputePositionResult, floating: HTMLElement, strategy: PositionStrategy): void {\n floating.style.position = strategy;\n floating.style.left = `${result.x}px`;\n floating.style.top = `${result.y}px`;\n}\n\n/**\n * Creates a lifecycle-owned floating positioner.\n *\n * The positioner owns coordinate strategy, clipping-boundary resolution, updates, and cleanup.\n * Call `start()` once the elements are mounted, then call `dispose()` when their owner ends.\n */\nexport function createPositioner(\n reference: ReferenceElement,\n floating: HTMLElement,\n {\n apply,\n autoUpdate: autoUpdateOptions = {},\n boundary: boundaryOption = 'clippingAncestors',\n middleware,\n padding,\n placement = 'bottom',\n strategy = 'fixed',\n }: PositionerOptions = {},\n): Positioner {\n let active = true;\n let cleanup: (() => void) | undefined;\n let lastPosition: ComputePositionResult | null = null;\n let started = false;\n\n function update(): void {\n if (!active) return;\n\n const containingBlock = resolveContainingBlock(floating, strategy);\n const boundary = boundaryOption === 'clippingAncestors' ? getClippingAncestorRect(floating) : boundaryOption;\n const result = computePosition(reference, floating, { boundary, containingBlock, middleware, padding, placement });\n\n lastPosition = result;\n (apply ?? ((position) => applyDefault(position, floating, strategy)))(result);\n }\n\n function start(): void {\n if (started) return;\n\n started = true;\n\n if (autoUpdateOptions === false) update();\n else cleanup = autoUpdate(reference, floating, update, autoUpdateOptions);\n }\n\n return makeP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AO,EACnC,EAAU,EAAW,EAAW,EAAU,EAAQ,CAAiB,EAC1E,CAEA,OAAO,MACC,CACJ,EAAS,GACT,IAAU,CACZ,MACM,EACN,EACA,CACF,CACF"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./utils.cjs"),n=require("./auto-update.cjs"),r=require("./core.cjs"),i=require("./float.cjs"),a=require("./overflow.cjs"),o=require("./containing-block.cjs"),s=require("./compose.cjs"),c=require("./middleware/arrow.cjs"),l=require("./middleware/auto-placement.cjs"),u=require("./middleware/flip.cjs"),d=require("./middleware/hide.cjs"),f=require("./inline.cjs"),p=require("./middleware/offset.cjs"),m=require("./middleware/shift.cjs"),h=require("./middleware/size.cjs");exports.OrbitConfigError=e.OrbitConfigError,exports.OrbitError=e.OrbitError,exports.arrow=c.arrow,exports.autoPlacement=l.autoPlacement,exports.autoUpdate=n.autoUpdate,exports.compose=s.compose,exports.computePosition=r.computePosition,exports.computePositionAsync=r.computePositionAsync,exports.computePositionRaf=r.computePositionRaf,exports.detectOverflow=a.detectOverflow,exports.flip=u.flip,exports.float=i.float,exports.floatWithAnchor=i.floatWithAnchor,exports.getAlignment=t.getAlignment,exports.getClippingAncestorRect=a.getClippingAncestorRect,exports.getContainingBlock=o.getContainingBlock,exports.getRects=r.getRects,exports.getSide=t.getSide,exports.hide=d.hide,exports.inline=f.inline,exports.isCssAnchorSupported=i.isCssAnchorSupported,exports.limitShift=m.limitShift,exports.offset=p.offset,exports.shift=m.shift,exports.size=h.size;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils.cjs"),t=require("./auto-update.cjs"),n=require("./errors.cjs"),r=require("./core.cjs"),i=require("./overflow.cjs"),a=require("./float.cjs"),o=require("./middleware/arrow.cjs"),s=require("./middleware/auto-placement.cjs"),c=require("./middleware/flip.cjs"),l=require("./middleware/hide.cjs"),u=require("./inline.cjs"),d=require("./middleware/offset.cjs"),f=require("./middleware/shift.cjs"),p=require("./middleware/size.cjs");exports.OrbitConfigError=n.OrbitConfigError,exports.OrbitError=n.OrbitError,exports.arrow=o.arrow,exports.autoPlacement=s.autoPlacement,exports.autoUpdate=t.autoUpdate,exports.computePosition=r.computePosition,exports.computePositionAsync=r.computePositionAsync,exports.computePositionRaf=r.computePositionRaf,exports.createPositioner=a.createPositioner,exports.detectOverflow=i.detectOverflow,exports.flip=c.flip,exports.getAlignment=e.getAlignment,exports.getClippingAncestorRect=i.getClippingAncestorRect,exports.getRects=r.getRects,exports.getSide=e.getSide,exports.hide=l.hide,exports.inline=u.inline,exports.limitShift=f.limitShift,exports.offset=d.offset,exports.shift=f.shift,exports.size=p.size;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  export { OrbitConfigError, OrbitError } from './errors';
2
2
  export { computePosition, computePositionAsync, computePositionRaf, getRects } from './core';
3
3
  export { detectOverflow, getClippingAncestorRect } from './overflow';
4
- export { getContainingBlock } from './containing-block';
5
- export { float, floatWithAnchor, isCssAnchorSupported } from './float';
6
- export type { CssAnchorHandle, FloatOptions } from './float';
4
+ export { createPositioner } from './float';
5
+ export type { Positioner, PositionerOptions, PositionStrategy } from './float';
7
6
  export { autoUpdate } from './auto-update';
8
7
  export type { AutoUpdateOptions } from './auto-update';
9
- export { compose } from './compose';
10
8
  export { arrow } from './middleware/arrow';
11
9
  export type { ArrowOptions } from './middleware/arrow';
12
10
  export { autoPlacement } from './middleware/auto-placement';
@@ -25,5 +23,5 @@ export { size } from './middleware/size';
25
23
  export type { SizeOptions } from './middleware/size';
26
24
  export type { PositioningPreset, PresetOptions } from './presets';
27
25
  export { getAlignment, getSide } from './utils';
28
- export type { Alignment, ArrowData, ComputePositionOptions, ComputePositionResult, DetectOverflowOptions, FlipData, FloatHandle, HideData, Middleware, MiddlewareData, MiddlewareReset, MiddlewareResult, MiddlewareState, Padding, Placement, Rect, ReferenceElement, ShiftData, Side, SideObject, SizeData, TypedMiddleware, VirtualReference, } from './types';
26
+ export type { Alignment, ArrowData, ComputePositionOptions, ComputePositionResult, DetectOverflowOptions, FlipData, HideData, Middleware, MiddlewareData, MiddlewareReset, MiddlewareResult, MiddlewareState, Padding, Placement, Rect, ReferenceElement, ShiftData, Side, SideObject, SizeData, VirtualReference, } from './types';
29
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC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AS,EACT,SAAS,EACT,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,SAAS,EACT,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,gBAAgB,GACjB,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{OrbitConfigError as e,OrbitError as t}from"./errors.js";import{getAlignment as n,getSide as r}from"./utils.js";import{autoUpdate as i}from"./auto-update.js";import{computePosition as a,computePositionAsync as o,computePositionRaf as s,getRects as c}from"./core.js";import{float as l,floatWithAnchor as u,isCssAnchorSupported as d}from"./float.js";import{detectOverflow as f,getClippingAncestorRect as p}from"./overflow.js";import{getContainingBlock as m}from"./containing-block.js";import{compose as h}from"./compose.js";import{arrow as g}from"./middleware/arrow.js";import{autoPlacement as _}from"./middleware/auto-placement.js";import{flip as v}from"./middleware/flip.js";import{hide as y}from"./middleware/hide.js";import{inline as b}from"./inline.js";import{offset as x}from"./middleware/offset.js";import{limitShift as S,shift as C}from"./middleware/shift.js";import{size as w}from"./middleware/size.js";export{e as OrbitConfigError,t as OrbitError,g as arrow,_ as autoPlacement,i as autoUpdate,h as compose,a as computePosition,o as computePositionAsync,s as computePositionRaf,f as detectOverflow,v as flip,l as float,u as floatWithAnchor,n as getAlignment,p as getClippingAncestorRect,m as getContainingBlock,c as getRects,r as getSide,y as hide,b as inline,d as isCssAnchorSupported,S as limitShift,x as offset,C as shift,w as size};
1
+ import{getAlignment as e,getSide as t}from"./utils.js";import{autoUpdate as n}from"./auto-update.js";import{OrbitConfigError as r,OrbitError as i}from"./errors.js";import{computePosition as a,computePositionAsync as o,computePositionRaf as s,getRects as c}from"./core.js";import{detectOverflow as l,getClippingAncestorRect as u}from"./overflow.js";import{createPositioner as d}from"./float.js";import{arrow as f}from"./middleware/arrow.js";import{autoPlacement as p}from"./middleware/auto-placement.js";import{flip as m}from"./middleware/flip.js";import{hide as h}from"./middleware/hide.js";import{inline as g}from"./inline.js";import{offset as _}from"./middleware/offset.js";import{limitShift as v,shift as y}from"./middleware/shift.js";import{size as b}from"./middleware/size.js";export{r as OrbitConfigError,i as OrbitError,f as arrow,p as autoPlacement,n as autoUpdate,a as computePosition,o as computePositionAsync,s as computePositionRaf,d as createPositioner,l as detectOverflow,m as flip,e as getAlignment,u as getClippingAncestorRect,c as getRects,t as getSide,h as hide,g as inline,v as limitShift,_ as offset,y as shift,b as size};
package/dist/inline.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils.cjs");function t(t){return!(`getClientRects`in t)||typeof t.getClientRects!=`function`?[]:Array.from(t.getClientRects()).map(e.toRect).filter(e=>e.width>0||e.height>0)}function n(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function r(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function i(i={}){function a(a){let o=t(a.elements.reference);if(o.length<=1)return;let s=e.toSideObject(i.padding??2),c=e.getSide(a.placement),l=o[0];if(i.x!=null&&i.y!=null)l=o.find(e=>n(e,i.x,i.y,s))??l;else if(c===`top`||c===`bottom`){let e=a.x+a.rects.floating.width/2;l=o.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},l)}else{let e=a.y+a.rects.floating.height/2;l=o.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},l)}if(!r(l,a.rects.reference))return{reset:{rects:{...a.rects,reference:l}}}}return e.tagMiddleware(a,`inline`)}exports.inline=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils.cjs");function t(t){return!(`getClientRects`in t)||typeof t.getClientRects!=`function`?[]:Array.from(t.getClientRects()).map(e.toRect).filter(e=>e.width>0||e.height>0)}function n(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function r(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function i(i={}){function a(a){let o=t(a.elements.reference);if(o.length<=1)return;let s=e.toSideObject(i.padding??2),c=e.getSide(a.placement),l=o[0];if(i.x!=null&&i.y!=null)l=o.find(e=>n(e,i.x,i.y,s))??l;else if(c===`top`||c===`bottom`){let e=a.x+a.rects.floating.width/2;l=o.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},l)}else{let e=a.y+a.rects.floating.height/2;l=o.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},l)}if(!r(l,a.rects.reference))return{reset:{rects:{...a.rects,reference:l}}}}return a}exports.inline=i;
2
2
  //# sourceMappingURL=inline.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline.cjs","names":[],"sources":["../src/inline.ts"],"sourcesContent":["import type { Middleware, Padding, Rect, ReferenceElement } from './types';\n\nimport { getSide, tagMiddleware, toRect, toSideObject } from './utils';\n\n// ── Private helpers (only used by inline) ────────────────────────────────────────────\n\nfunction getClientRects(reference: ReferenceElement): Rect[] {\n if (!('getClientRects' in reference) || typeof reference.getClientRects !== 'function') return [];\n\n return Array.from((reference.getClientRects as () => DOMRectList | DOMRect[])())\n .map(toRect)\n .filter((r) => r.width > 0 || r.height > 0);\n}\n\nfunction rectContainsPoint(rect: Rect, x: number, y: number, padding: ReturnType<typeof toSideObject>): boolean {\n return (\n x >= rect.x - padding.left &&\n x <= rect.x + rect.width + padding.right &&\n y >= rect.y - padding.top &&\n y <= rect.y + rect.height + padding.bottom\n );\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\n// ── Inline middleware ─────────────────────────────────────────────────────────────────\n\nexport interface InlineOptions {\n /**\n * Cursor x-coordinate. When provided alongside `y`, the middleware picks the\n * client rect that contains the cursor instead of the closest rect to the floating element.\n */\n x?: number;\n /** Cursor y-coordinate. */\n y?: number;\n /**\n * Padding used when hit-testing cursor coordinates against client rects.\n * Prevents snapping when the cursor is just outside a rect edge. Default: `2`.\n *\n * @remarks Only applies when both `x` and `y` are provided.\n */\n padding?: Padding;\n}\n\n/**\n * Improves positioning accuracy for inline references that span multiple lines\n * (e.g. `<span>` wrapping across line breaks).\n *\n * Must be placed **before** `flip()` and other middleware in the pipeline.\n *\n * @example Tooltip on selected text:\n * ```ts\n * import { inline, float, flip, shift } from '@vielzeug/orbit';\n *\n * float(selectionRef, tooltip, {\n * placement: 'top',\n * middleware: [inline({ x: cursorX, y: cursorY }), flip(), shift({ padding: 6 })],\n * });\n * ```\n */\nexport function inline(options: InlineOptions = {}): Middleware {\n function inlineMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const rects = getClientRects(state.elements.reference);\n\n if (rects.length <= 1) return;\n\n const padding = toSideObject(options.padding ?? 2);\n const side = getSide(state.placement);\n let nextRect = rects[0]!;\n\n if (options.x != null && options.y != null) {\n nextRect = rects.find((rect) => rectContainsPoint(rect, options.x!, options.y!, padding)) ?? nextRect;\n } else if (side === 'top' || side === 'bottom') {\n const targetX = state.x + state.rects.floating.width / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.x + best.width / 2 - targetX);\n const rectDist = Math.abs(rect.x + rect.width / 2 - targetX);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n } else {\n const targetY = state.y + state.rects.floating.height / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.y + best.height / 2 - targetY);\n const rectDist = Math.abs(rect.y + rect.height / 2 - targetY);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n }\n\n if (sameRect(next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AK,EAAI,EAAK,MAAQ,EAAI,CAAO,EAG3D,OAFiB,KAAK,IAAI,EAAK,EAAI,EAAK,MAAQ,EAAI,CAE7C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,KAAO,CACL,IAAM,EAAU,EAAM,EAAI,EAAM,MAAM,SAAS,OAAS,EAExD,EAAW,EAAM,QAAQ,EAAM,IAAS,CACtC,IAAM,EAAW,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAAO,EAG5D,OAFiB,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAE9C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,CAEI,MAAS,EAAU,EAAM,MAAM,SAAS,EAE5C,MAAO,CAAE,MAAO,CAAE,MAAO,CAAE,GAAG,EAAM,MAAO,UAAW,CAAS,CAAE,CAAE,CACrE,CAEA,OAAO,EAAA,cAAc,EAAkB,QAAQ,CACjD"}
1
+ {"version":3,"file":"inline.cjs","names":[],"sources":["../src/inline.ts"],"sourcesContent":["import type { Middleware, Padding, Rect, ReferenceElement } from './types';\n\nimport { getSide, toRect, toSideObject } from './utils';\n\n// ── Private helpers (only used by inline) ────────────────────────────────────────────\n\nfunction getClientRects(reference: ReferenceElement): Rect[] {\n if (!('getClientRects' in reference) || typeof reference.getClientRects !== 'function') return [];\n\n return Array.from((reference.getClientRects as () => DOMRectList | DOMRect[])())\n .map(toRect)\n .filter((r) => r.width > 0 || r.height > 0);\n}\n\nfunction rectContainsPoint(rect: Rect, x: number, y: number, padding: ReturnType<typeof toSideObject>): boolean {\n return (\n x >= rect.x - padding.left &&\n x <= rect.x + rect.width + padding.right &&\n y >= rect.y - padding.top &&\n y <= rect.y + rect.height + padding.bottom\n );\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\n// ── Inline middleware ─────────────────────────────────────────────────────────────────\n\nexport interface InlineOptions {\n /**\n * Cursor x-coordinate. When provided alongside `y`, the middleware picks the\n * client rect that contains the cursor instead of the closest rect to the floating element.\n */\n x?: number;\n /** Cursor y-coordinate. */\n y?: number;\n /**\n * Padding used when hit-testing cursor coordinates against client rects.\n * Prevents snapping when the cursor is just outside a rect edge. Default: `2`.\n *\n * @remarks Only applies when both `x` and `y` are provided.\n */\n padding?: Padding;\n}\n\n/**\n * Improves positioning accuracy for inline references that span multiple lines\n * (e.g. `<span>` wrapping across line breaks).\n *\n * Must be placed **before** `flip()` and other middleware in the pipeline.\n *\n * @example Tooltip on selected text:\n * ```ts\n * import { createPositioner, inline, flip, shift } from '@vielzeug/orbit';\n *\n * const positioner = createPositioner(selectionRef, tooltip, {\n * placement: 'top',\n * middleware: [inline({ x: cursorX, y: cursorY }), flip(), shift({ padding: 6 })],\n * });\n * positioner.start();\n * ```\n */\nexport function inline(options: InlineOptions = {}): Middleware {\n function inlineMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const rects = getClientRects(state.elements.reference);\n\n if (rects.length <= 1) return;\n\n const padding = toSideObject(options.padding ?? 2);\n const side = getSide(state.placement);\n let nextRect = rects[0]!;\n\n if (options.x != null && options.y != null) {\n nextRect = rects.find((rect) => rectContainsPoint(rect, options.x!, options.y!, padding)) ?? nextRect;\n } else if (side === 'top' || side === 'bottom') {\n const targetX = state.x + state.rects.floating.width / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.x + best.width / 2 - targetX);\n const rectDist = Math.abs(rect.x + rect.width / 2 - targetX);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n } else {\n const targetY = state.y + state.rects.floating.height / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.y + best.height / 2 - targetY);\n const rectDist = Math.abs(rect.y + rect.height / 2 - targetY);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n }\n\n if (sameRect(nextRect, state.rects.reference)) return;\n\n return { reset: { rects: { ...state.rects, reference: nextRect } } };\n }\n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AK,MAAQ,EAAI,CAE7C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,KAAO,CACL,IAAM,EAAU,EAAM,EAAI,EAAM,MAAM,SAAS,OAAS,EAExD,EAAW,EAAM,QAAQ,EAAM,IAAS,CACtC,IAAM,EAAW,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAAO,EAG5D,OAFiB,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAE9C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,CAEI,MAAS,EAAU,EAAM,MAAM,SAAS,EAE5C,MAAO,CAAE,MAAO,CAAE,MAAO,CAAE,GAAG,EAAM,MAAO,UAAW,CAAS,CAAE,CAAE,CACrE,CAEA,OAAO,CACT"}
package/dist/inline.d.ts CHANGED
@@ -23,12 +23,13 @@ export interface InlineOptions {
23
23
  *
24
24
  * @example Tooltip on selected text:
25
25
  * ```ts
26
- * import { inline, float, flip, shift } from '@vielzeug/orbit';
26
+ * import { createPositioner, inline, flip, shift } from '@vielzeug/orbit';
27
27
  *
28
- * float(selectionRef, tooltip, {
28
+ * const positioner = createPositioner(selectionRef, tooltip, {
29
29
  * placement: 'top',
30
30
  * middleware: [inline({ x: cursorX, y: cursorY }), flip(), shift({ padding: 6 })],
31
31
  * });
32
+ * positioner.start();
32
33
  * ```
33
34
  */
34
35
  export declare function inline(options?: InlineOptions): Middleware;
@@ -1 +1 @@
1
- {"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../src/inline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAA0B,MAAM,SAAS,CAAC;AA6B3E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,UAAU,CAsC9D"}
1
+ {"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../src/inline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAA0B,MAAM,SAAS,CAAC;AA6B3E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,UAAU,CAsC9D"}
package/dist/inline.js CHANGED
@@ -1,2 +1,2 @@
1
- import{getSide as e,tagMiddleware as t,toRect as n,toSideObject as r}from"./utils.js";function i(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(n).filter(e=>e.width>0||e.height>0)}function a(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function o(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function s(n={}){function s(t){let s=i(t.elements.reference);if(s.length<=1)return;let c=r(n.padding??2),l=e(t.placement),u=s[0];if(n.x!=null&&n.y!=null)u=s.find(e=>a(e,n.x,n.y,c))??u;else if(l===`top`||l===`bottom`){let e=t.x+t.rects.floating.width/2;u=s.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},u)}else{let e=t.y+t.rects.floating.height/2;u=s.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},u)}if(!o(u,t.rects.reference))return{reset:{rects:{...t.rects,reference:u}}}}return t(s,`inline`)}export{s as inline};
1
+ import{getSide as e,toRect as t,toSideObject as n}from"./utils.js";function r(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(t).filter(e=>e.width>0||e.height>0)}function i(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function a(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function o(t={}){function o(o){let s=r(o.elements.reference);if(s.length<=1)return;let c=n(t.padding??2),l=e(o.placement),u=s[0];if(t.x!=null&&t.y!=null)u=s.find(e=>i(e,t.x,t.y,c))??u;else if(l===`top`||l===`bottom`){let e=o.x+o.rects.floating.width/2;u=s.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},u)}else{let e=o.y+o.rects.floating.height/2;u=s.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},u)}if(!a(u,o.rects.reference))return{reset:{rects:{...o.rects,reference:u}}}}return o}export{o as inline};
2
2
  //# sourceMappingURL=inline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline.js","names":[],"sources":["../src/inline.ts"],"sourcesContent":["import type { Middleware, Padding, Rect, ReferenceElement } from './types';\n\nimport { getSide, tagMiddleware, toRect, toSideObject } from './utils';\n\n// ── Private helpers (only used by inline) ────────────────────────────────────────────\n\nfunction getClientRects(reference: ReferenceElement): Rect[] {\n if (!('getClientRects' in reference) || typeof reference.getClientRects !== 'function') return [];\n\n return Array.from((reference.getClientRects as () => DOMRectList | DOMRect[])())\n .map(toRect)\n .filter((r) => r.width > 0 || r.height > 0);\n}\n\nfunction rectContainsPoint(rect: Rect, x: number, y: number, padding: ReturnType<typeof toSideObject>): boolean {\n return (\n x >= rect.x - padding.left &&\n x <= rect.x + rect.width + padding.right &&\n y >= rect.y - padding.top &&\n y <= rect.y + rect.height + padding.bottom\n );\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\n// ── Inline middleware ─────────────────────────────────────────────────────────────────\n\nexport interface InlineOptions {\n /**\n * Cursor x-coordinate. When provided alongside `y`, the middleware picks the\n * client rect that contains the cursor instead of the closest rect to the floating element.\n */\n x?: number;\n /** Cursor y-coordinate. */\n y?: number;\n /**\n * Padding used when hit-testing cursor coordinates against client rects.\n * Prevents snapping when the cursor is just outside a rect edge. Default: `2`.\n *\n * @remarks Only applies when both `x` and `y` are provided.\n */\n padding?: Padding;\n}\n\n/**\n * Improves positioning accuracy for inline references that span multiple lines\n * (e.g. `<span>` wrapping across line breaks).\n *\n * Must be placed **before** `flip()` and other middleware in the pipeline.\n *\n * @example Tooltip on selected text:\n * ```ts\n * import { inline, float, flip, shift } from '@vielzeug/orbit';\n *\n * float(selectionRef, tooltip, {\n * placement: 'top',\n * middleware: [inline({ x: cursorX, y: cursorY }), flip(), shift({ padding: 6 })],\n * });\n * ```\n */\nexport function inline(options: InlineOptions = {}): Middleware {\n function inlineMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const rects = getClientRects(state.elements.reference);\n\n if (rects.length <= 1) return;\n\n const padding = toSideObject(options.padding ?? 2);\n const side = getSide(state.placement);\n let nextRect = rects[0]!;\n\n if (options.x != null && options.y != null) {\n nextRect = rects.find((rect) => rectContainsPoint(rect, options.x!, options.y!, padding)) ?? nextRect;\n } else if (side === 'top' || side === 'bottom') {\n const targetX = state.x + state.rects.floating.width / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.x + best.width / 2 - targetX);\n const rectDist = Math.abs(rect.x + rect.width / 2 - targetX);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n } else {\n const targetY = state.y + state.rects.floating.height / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.y + best.height / 2 - targetY);\n const rectDist = Math.abs(rect.y + rect.height / 2 - targetY);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n }\n\n if (sameRect(nextRect, state.rects.reference)) return;\n\n return { reset: { rects: { ...state.rects, reference: nextRect } } };\n }\n\n return tagMiddleware(inlineMiddleware, 'inline');\n}\n"],"mappings":"sFAMA,SAAS,EAAe,EAAqC,CAG3D,MAFI,EAAE,mBAAoB,IAAc,OAAO,EAAU,gBAAmB,WAAmB,CAAC,EAEzF,MAAM,KAAM,EAAU,eAAiD,CAAC,CAAC,CAC7E,IAAI,CAAM,CAAC,CACX,OAAQ,GAAM,EAAE,MAAQ,GAAK,EAAE,OAAS,CAAC,CAC9C,CAEA,SAAS,EAAkB,EAAY,EAAW,EAAW,EAAmD,CAC9G,OACE,GAAK,EAAK,EAAI,EAAQ,MACtB,GAAK,EAAK,EAAI,EAAK,MAAQ,EAAQ,OACnC,GAAK,EAAK,EAAI,EAAQ,KACtB,GAAK,EAAK,EAAI,EAAK,OAAS,EAAQ,MAExC,CAEA,SAAS,EAAS,EAAS,EAAkB,CAC3C,OAAO,EAAE,IAAM,EAAE,GAAK,EAAE,IAAM,EAAE,GAAK,EAAE,QAAU,EAAE,OAAS,EAAE,SAAW,EAAE,MAC7E,CAqCA,SAAgB,EAAO,EAAyB,CAAC,EAAe,CAC9D,SAAS,EAAiB,EAA0D,CAClF,IAAM,EAAQ,EAAe,EAAM,SAAS,SAAS,EAErD,GAAI,EAAM,QAAU,EAAG,OAEvB,IAAM,EAAU,EAAa,EAAQ,SAAW,CAAC,EAC3C,EAAO,EAAQ,EAAM,SAAS,EAChC,EAAW,EAAM,GAErB,GAAI,EAAQ,GAAK,MAAQ,EAAQ,GAAK,KACpC,EAAW,EAAM,KAAM,GAAS,EAAkB,EAAM,EAAQ,EAAI,EAAQ,EAAI,CAAO,CAAC,GAAK,OACxF,GAAI,IAAS,OAAS,IAAS,SAAU,CAC9C,IAAM,EAAU,EAAM,EAAI,EAAM,MAAM,SAAS,MAAQ,EAEvD,EAAW,EAAM,QAAQ,EAAM,IAAS,CACtC,IAAM,EAAW,KAAK,IAAI,EAAK,EAAI,EAAK,MAAQ,EAAI,CAAO,EAG3D,OAFiB,KAAK,IAAI,EAAK,EAAI,EAAK,MAAQ,EAAI,CAE7C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,KAAO,CACL,IAAM,EAAU,EAAM,EAAI,EAAM,MAAM,SAAS,OAAS,EAExD,EAAW,EAAM,QAAQ,EAAM,IAAS,CACtC,IAAM,EAAW,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAAO,EAG5D,OAFiB,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAE9C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,CAEI,MAAS,EAAU,EAAM,MAAM,SAAS,EAE5C,MAAO,CAAE,MAAO,CAAE,MAAO,CAAE,GAAG,EAAM,MAAO,UAAW,CAAS,CAAE,CAAE,CACrE,CAEA,OAAO,EAAc,EAAkB,QAAQ,CACjD"}
1
+ {"version":3,"file":"inline.js","names":[],"sources":["../src/inline.ts"],"sourcesContent":["import type { Middleware, Padding, Rect, ReferenceElement } from './types';\n\nimport { getSide, toRect, toSideObject } from './utils';\n\n// ── Private helpers (only used by inline) ────────────────────────────────────────────\n\nfunction getClientRects(reference: ReferenceElement): Rect[] {\n if (!('getClientRects' in reference) || typeof reference.getClientRects !== 'function') return [];\n\n return Array.from((reference.getClientRects as () => DOMRectList | DOMRect[])())\n .map(toRect)\n .filter((r) => r.width > 0 || r.height > 0);\n}\n\nfunction rectContainsPoint(rect: Rect, x: number, y: number, padding: ReturnType<typeof toSideObject>): boolean {\n return (\n x >= rect.x - padding.left &&\n x <= rect.x + rect.width + padding.right &&\n y >= rect.y - padding.top &&\n y <= rect.y + rect.height + padding.bottom\n );\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\n// ── Inline middleware ─────────────────────────────────────────────────────────────────\n\nexport interface InlineOptions {\n /**\n * Cursor x-coordinate. When provided alongside `y`, the middleware picks the\n * client rect that contains the cursor instead of the closest rect to the floating element.\n */\n x?: number;\n /** Cursor y-coordinate. */\n y?: number;\n /**\n * Padding used when hit-testing cursor coordinates against client rects.\n * Prevents snapping when the cursor is just outside a rect edge. Default: `2`.\n *\n * @remarks Only applies when both `x` and `y` are provided.\n */\n padding?: Padding;\n}\n\n/**\n * Improves positioning accuracy for inline references that span multiple lines\n * (e.g. `<span>` wrapping across line breaks).\n *\n * Must be placed **before** `flip()` and other middleware in the pipeline.\n *\n * @example Tooltip on selected text:\n * ```ts\n * import { createPositioner, inline, flip, shift } from '@vielzeug/orbit';\n *\n * const positioner = createPositioner(selectionRef, tooltip, {\n * placement: 'top',\n * middleware: [inline({ x: cursorX, y: cursorY }), flip(), shift({ padding: 6 })],\n * });\n * positioner.start();\n * ```\n */\nexport function inline(options: InlineOptions = {}): Middleware {\n function inlineMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const rects = getClientRects(state.elements.reference);\n\n if (rects.length <= 1) return;\n\n const padding = toSideObject(options.padding ?? 2);\n const side = getSide(state.placement);\n let nextRect = rects[0]!;\n\n if (options.x != null && options.y != null) {\n nextRect = rects.find((rect) => rectContainsPoint(rect, options.x!, options.y!, padding)) ?? nextRect;\n } else if (side === 'top' || side === 'bottom') {\n const targetX = state.x + state.rects.floating.width / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.x + best.width / 2 - targetX);\n const rectDist = Math.abs(rect.x + rect.width / 2 - targetX);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n } else {\n const targetY = state.y + state.rects.floating.height / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.y + best.height / 2 - targetY);\n const rectDist = Math.abs(rect.y + rect.height / 2 - targetY);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n }\n\n if (sameRect(nextRect, state.rects.reference)) return;\n\n return { reset: { rects: { ...state.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,EAAK,MAAQ,EAAI,CAE7C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,KAAO,CACL,IAAM,EAAU,EAAM,EAAI,EAAM,MAAM,SAAS,OAAS,EAExD,EAAW,EAAM,QAAQ,EAAM,IAAS,CACtC,IAAM,EAAW,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAAO,EAG5D,OAFiB,KAAK,IAAI,EAAK,EAAI,EAAK,OAAS,EAAI,CAE9C,EAAW,EAAW,EAAO,CACtC,EAAG,CAAQ,CACb,CAEI,MAAS,EAAU,EAAM,MAAM,SAAS,EAE5C,MAAO,CAAE,MAAO,CAAE,MAAO,CAAE,GAAG,EAAM,MAAO,UAAW,CAAS,CAAE,CAAE,CACrE,CAEA,OAAO,CACT"}
@@ -1,2 +1,2 @@
1
- const e=require("../utils.cjs");let t=require("@vielzeug/arsenal/math");function n({element:n,padding:r=0}){function i(i){let a=e.getSide(i.placement),o=e.toSideObject(r),s=e.toRect(n.getBoundingClientRect());if(a===`top`||a===`bottom`){let e=i.rects.reference.x+i.rects.reference.width/2-i.x-s.width/2,n=o.left,r=Math.max(n,i.rects.floating.width-s.width-o.right),a=(0,t.clamp)(e,n,r);return{data:{arrow:{centerOffset:e-a,constrained:a!==e,x:a}}}}let c=i.rects.reference.y+i.rects.reference.height/2-i.y-s.height/2,l=o.top,u=Math.max(l,i.rects.floating.height-s.height-o.bottom),d=(0,t.clamp)(c,l,u);return{data:{arrow:{centerOffset:c-d,constrained:d!==c,y:d}}}}return e.tagMiddleware(i,`arrow`)}exports.arrow=n;
1
+ const e=require("../utils.cjs");function t({element:t,padding:n=0}){function r(r){let i=e.getSide(r.placement),a=e.toSideObject(n),o=e.toRect(t.getBoundingClientRect());if(i===`top`||i===`bottom`){let t=r.rects.reference.x+r.rects.reference.width/2-r.x-o.width/2,n=a.left,i=Math.max(n,r.rects.floating.width-o.width-a.right),s=e.clamp(t,n,i);return{data:{arrow:{centerOffset:t-s,constrained:s!==t,x:s}}}}let s=r.rects.reference.y+r.rects.reference.height/2-r.y-o.height/2,c=a.top,l=Math.max(c,r.rects.floating.height-o.height-a.bottom),u=e.clamp(s,c,l);return{data:{arrow:{centerOffset:s-u,constrained:u!==s,y:u}}}}return r}exports.arrow=t;
2
2
  //# sourceMappingURL=arrow.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"arrow.cjs","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { ArrowData, Middleware, Padding, TypedMiddleware } from '../types';\n\nimport { clamp, getSide, tagMiddleware, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): TypedMiddleware<'arrow', ArrowData> {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return tagMiddleware<'arrow', ArrowData, typeof arrowMiddleware>(arrowMiddleware, 'arrow');\n}\n"],"mappings":"wEA2BA,SAAgB,EAAM,CAAE,UAAS,UAAU,GAAwD,CACjG,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAA,aAAa,CAAO,EAC5B,EAAY,EAAA,OAAO,EAAQ,sBAAsB,CAAC,EAExD,GAAI,IAAS,OAAS,IAAS,SAAU,CACvC,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,MAAQ,EAAI,EAAM,EAAI,EAAU,MAAQ,EACjG,EAAO,EAAM,KACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,MAAQ,EAAU,MAAQ,EAAM,KAAK,EAChF,GAAA,EAAI,EAAA,MAAA,CAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,OAAS,EAAI,EAAM,EAAI,EAAU,OAAS,EACnG,EAAO,EAAM,IACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,OAAS,EAAU,OAAS,EAAM,MAAM,EACnF,GAAA,EAAI,EAAA,MAAA,CAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,OAAO,EAAA,cAA0D,EAAiB,OAAO,CAC3F"}
1
+ {"version":3,"file":"arrow.cjs","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { Middleware, Padding } from '../types';\n\nimport { clamp, getSide, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): Middleware {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return arrowMiddleware;\n}\n"],"mappings":"gCA2BA,SAAgB,EAAM,CAAE,UAAS,UAAU,GAA+B,CACxE,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAA,aAAa,CAAO,EAC5B,EAAY,EAAA,OAAO,EAAQ,sBAAsB,CAAC,EAExD,GAAI,IAAS,OAAS,IAAS,SAAU,CACvC,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,MAAQ,EAAI,EAAM,EAAI,EAAU,MAAQ,EACjG,EAAO,EAAM,KACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,MAAQ,EAAU,MAAQ,EAAM,KAAK,EAChF,EAAI,EAAA,MAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,OAAS,EAAI,EAAM,EAAI,EAAU,OAAS,EACnG,EAAO,EAAM,IACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,OAAS,EAAU,OAAS,EAAM,MAAM,EACnF,EAAI,EAAA,MAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,OAAO,CACT"}
@@ -1,4 +1,4 @@
1
- import type { ArrowData, Padding, TypedMiddleware } from '../types';
1
+ import type { Middleware, Padding } from '../types';
2
2
  export interface ArrowOptions {
3
3
  /** The arrow DOM element. Must be a child of the floating element. */
4
4
  element: HTMLElement;
@@ -21,5 +21,5 @@ export interface ArrowOptions {
21
21
  * arrowEl.style.top = y != null ? `${y}px` : '';
22
22
  * ```
23
23
  */
24
- export declare function arrow({ element, padding }: ArrowOptions): TypedMiddleware<'arrow', ArrowData>;
24
+ export declare function arrow({ element, padding }: ArrowOptions): Middleware;
25
25
  //# sourceMappingURL=arrow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../src/middleware/arrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhF,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,OAAO,EAAE,WAAW,CAAC;IACrB,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,EAAE,OAAO,EAAE,OAAW,EAAE,EAAE,YAAY,GAAG,eAAe,CAAC,OAAO,EAAE,SAAS,CAAC,CAwBjG"}
1
+ {"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../src/middleware/arrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAIpD,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,OAAO,EAAE,WAAW,CAAC;IACrB,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,EAAE,OAAO,EAAE,OAAW,EAAE,EAAE,YAAY,GAAG,UAAU,CAwBxE"}
@@ -1,2 +1,2 @@
1
- import{clamp as e,getSide as t,tagMiddleware as n,toRect as r,toSideObject as i}from"../utils.js";function a({element:a,padding:o=0}){function s(n){let s=t(n.placement),c=i(o),l=r(a.getBoundingClientRect());if(s===`top`||s===`bottom`){let t=n.rects.reference.x+n.rects.reference.width/2-n.x-l.width/2,r=c.left,i=Math.max(r,n.rects.floating.width-l.width-c.right),a=e(t,r,i);return{data:{arrow:{centerOffset:t-a,constrained:a!==t,x:a}}}}let u=n.rects.reference.y+n.rects.reference.height/2-n.y-l.height/2,d=c.top,f=Math.max(d,n.rects.floating.height-l.height-c.bottom),p=e(u,d,f);return{data:{arrow:{centerOffset:u-p,constrained:p!==u,y:p}}}}return n(s,`arrow`)}export{a as arrow};
1
+ import{clamp as e,getSide as t,toRect as n,toSideObject as r}from"../utils.js";function i({element:i,padding:a=0}){function o(o){let s=t(o.placement),c=r(a),l=n(i.getBoundingClientRect());if(s===`top`||s===`bottom`){let t=o.rects.reference.x+o.rects.reference.width/2-o.x-l.width/2,n=c.left,r=Math.max(n,o.rects.floating.width-l.width-c.right),i=e(t,n,r);return{data:{arrow:{centerOffset:t-i,constrained:i!==t,x:i}}}}let u=o.rects.reference.y+o.rects.reference.height/2-o.y-l.height/2,d=c.top,f=Math.max(d,o.rects.floating.height-l.height-c.bottom),p=e(u,d,f);return{data:{arrow:{centerOffset:u-p,constrained:p!==u,y:p}}}}return o}export{i as arrow};
2
2
  //# sourceMappingURL=arrow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"arrow.js","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { ArrowData, Middleware, Padding, TypedMiddleware } from '../types';\n\nimport { clamp, getSide, tagMiddleware, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): TypedMiddleware<'arrow', ArrowData> {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return tagMiddleware<'arrow', ArrowData, typeof arrowMiddleware>(arrowMiddleware, 'arrow');\n}\n"],"mappings":"kGA2BA,SAAgB,EAAM,CAAE,UAAS,UAAU,GAAwD,CACjG,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,CAAO,EAC5B,EAAY,EAAO,EAAQ,sBAAsB,CAAC,EAExD,GAAI,IAAS,OAAS,IAAS,SAAU,CACvC,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,MAAQ,EAAI,EAAM,EAAI,EAAU,MAAQ,EACjG,EAAO,EAAM,KACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,MAAQ,EAAU,MAAQ,EAAM,KAAK,EAChF,EAAI,EAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,OAAS,EAAI,EAAM,EAAI,EAAU,OAAS,EACnG,EAAO,EAAM,IACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,OAAS,EAAU,OAAS,EAAM,MAAM,EACnF,EAAI,EAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,OAAO,EAA0D,EAAiB,OAAO,CAC3F"}
1
+ {"version":3,"file":"arrow.js","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { Middleware, Padding } from '../types';\n\nimport { clamp, getSide, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): Middleware {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return arrowMiddleware;\n}\n"],"mappings":"+EA2BA,SAAgB,EAAM,CAAE,UAAS,UAAU,GAA+B,CACxE,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,CAAO,EAC5B,EAAY,EAAO,EAAQ,sBAAsB,CAAC,EAExD,GAAI,IAAS,OAAS,IAAS,SAAU,CACvC,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,MAAQ,EAAI,EAAM,EAAI,EAAU,MAAQ,EACjG,EAAO,EAAM,KACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,MAAQ,EAAU,MAAQ,EAAM,KAAK,EAChF,EAAI,EAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,OAAS,EAAI,EAAM,EAAI,EAAU,OAAS,EACnG,EAAO,EAAM,IACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,OAAS,EAAU,OAAS,EAAM,MAAM,EACnF,EAAI,EAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,OAAO,CACT"}
@@ -1,2 +1,2 @@
1
- const e=require("../utils.cjs");require("../_dev.cjs");const t=require("../overflow.cjs");var n=[`top`,`right`,`bottom`,`left`];function r(e){return e===void 0?n:e===null?n.flatMap(e=>[e,`${e}-start`,`${e}-end`]):n.map(t=>`${t}-${e}`)}function i(n={}){return e.tagMiddleware(function(e){let{boundary:i,padding:a}=t.resolveBoundary(n,e),o=n.allowedPlacements??r(n.alignment);o.length;let s=e.placement,c=1/0,l=-1/0;for(let r of o){let o=t.getPlacementOverflow(e,r,n),u=t.totalOverflow(o),d=t.getAvailableSpace(e,r,i,a);(u<c||u===c&&d>l)&&(s=r,c=u,l=d)}if(s!==e.placement)return{reset:{placement:s}}},`autoPlacement`)}exports.autoPlacement=i;
1
+ require("../_dev.cjs");const e=require("../overflow.cjs");var t=[`top`,`right`,`bottom`,`left`];function n(e){return e===void 0?t:e===null?t.flatMap(e=>[e,`${e}-start`,`${e}-end`]):t.map(t=>`${t}-${e}`)}function r(t={}){return function(r){let{boundary:i,padding:a}=e.resolveBoundary(t,r),o=t.allowedPlacements??n(t.alignment);o.length;let s=r.placement,c=1/0,l=-1/0;for(let n of o){let o=e.getPlacementOverflow(r,n,t),u=e.totalOverflow(o),d=e.getAvailableSpace(r,n,i,a);(u<c||u===c&&d>l)&&(s=n,c=u,l=d)}if(s!==r.placement)return{reset:{placement:s}}}}exports.autoPlacement=r;
2
2
  //# sourceMappingURL=auto-placement.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto-placement.cjs","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport { tagMiddleware } from '../utils';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return tagMiddleware(function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n }, 'autoPlacement');\n}\n"],"mappings":"0FAuBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,EAAA,cAAc,SAAiC,EAA0D,CAC9G,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAA,qBAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAA,cAAc,CAAQ,EACtC,EAAiB,EAAA,kBAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,EAAG,eAAe,CACpB"}
1
+ {"version":3,"file":"auto-placement.cjs","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n };\n}\n"],"mappings":"0DAsBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,SAAiC,EAA0D,CAChG,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAA,qBAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAA,cAAc,CAAQ,EACtC,EAAiB,EAAA,kBAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"auto-placement.d.ts","sourceRoot":"","sources":["../../src/middleware/auto-placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAQ,MAAM,UAAU,CAAC;AAM9F,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE;;;OAGG;IACH,iBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC;IAChC;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CAC9B;AAcD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,UAAU,CA6B5E"}
1
+ {"version":3,"file":"auto-placement.d.ts","sourceRoot":"","sources":["../../src/middleware/auto-placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAQ,MAAM,UAAU,CAAC;AAK9F,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE;;;OAGG;IACH,iBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC;IAChC;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CAC9B;AAcD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,UAAU,CA6B5E"}
@@ -1,2 +1,2 @@
1
- import{tagMiddleware as e}from"../utils.js";import"../_dev.js";import{getAvailableSpace as t,getPlacementOverflow as n,resolveBoundary as r,totalOverflow as i}from"../overflow.js";var a=[`top`,`right`,`bottom`,`left`];function o(e){return e===void 0?a:e===null?a.flatMap(e=>[e,`${e}-start`,`${e}-end`]):a.map(t=>`${t}-${e}`)}function s(a={}){return e(function(e){let{boundary:s,padding:c}=r(a,e),l=a.allowedPlacements??o(a.alignment);l.length;let u=e.placement,d=1/0,f=-1/0;for(let r of l){let o=n(e,r,a),l=i(o),p=t(e,r,s,c);(l<d||l===d&&p>f)&&(u=r,d=l,f=p)}if(u!==e.placement)return{reset:{placement:u}}},`autoPlacement`)}export{s as autoPlacement};
1
+ import"../_dev.js";import{getAvailableSpace as e,getPlacementOverflow as t,resolveBoundary as n,totalOverflow as r}from"../overflow.js";var i=[`top`,`right`,`bottom`,`left`];function a(e){return e===void 0?i:e===null?i.flatMap(e=>[e,`${e}-start`,`${e}-end`]):i.map(t=>`${t}-${e}`)}function o(i={}){return function(o){let{boundary:s,padding:c}=n(i,o),l=i.allowedPlacements??a(i.alignment);l.length;let u=o.placement,d=1/0,f=-1/0;for(let n of l){let a=t(o,n,i),l=r(a),p=e(o,n,s,c);(l<d||l===d&&p>f)&&(u=n,d=l,f=p)}if(u!==o.placement)return{reset:{placement:u}}}}export{o as autoPlacement};
2
2
  //# sourceMappingURL=auto-placement.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto-placement.js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport { tagMiddleware } from '../utils';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return tagMiddleware(function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n }, 'autoPlacement');\n}\n"],"mappings":"oLAuBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,EAAc,SAAiC,EAA0D,CAC9G,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAc,CAAQ,EACtC,EAAiB,EAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,EAAG,eAAe,CACpB"}
1
+ {"version":3,"file":"auto-placement.js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n };\n}\n"],"mappings":"wIAsBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,SAAiC,EAA0D,CAChG,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAc,CAAQ,EACtC,EAAiB,EAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,CACF"}
@@ -1,2 +1,2 @@
1
- const e=require("../utils.cjs"),t=require("../overflow.cjs");function n(n={}){function r(r){let i=t.detectOverflow(r,n);if(!t.hasOverflow(i))return;let a=e.getSide(r.placement),o=e.getAlignment(r.placement),s=n.fallbackPlacements??[e.withPlacement(e.OPPOSITE[a],o)],c=[r.placement],l=r.placement,u=t.totalOverflow(i);for(let e of s){let i=t.getPlacementOverflow(r,e,n),a=t.totalOverflow(i);if(!t.hasOverflow(i))return{data:{flip:{skippedPlacements:c}},reset:{placement:e}};c.push(e),a<u&&(l=e,u=a)}if(l!==r.placement)return{data:{flip:{skippedPlacements:c}},reset:{placement:l}}}return e.tagMiddleware(r,`flip`)}exports.flip=n;
1
+ const e=require("../utils.cjs"),t=require("../overflow.cjs");function n(n={}){function r(r){let i=t.detectOverflow(r,n);if(!t.hasOverflow(i))return;let a=e.getSide(r.placement),o=e.getAlignment(r.placement),s=n.fallbackPlacements??[e.withPlacement(e.OPPOSITE[a],o)],c=[r.placement],l=r.placement,u=t.totalOverflow(i);for(let e of s){let i=t.getPlacementOverflow(r,e,n),a=t.totalOverflow(i);if(!t.hasOverflow(i))return{data:{flip:{skippedPlacements:c}},reset:{placement:e}};c.push(e),a<u&&(l=e,u=a)}if(l!==r.placement)return{data:{flip:{skippedPlacements:c}},reset:{placement:l}}}return r}exports.flip=n;
2
2
  //# sourceMappingURL=flip.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"flip.cjs","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import type { DetectOverflowOptions, FlipData, Middleware, Placement, TypedMiddleware } from '../types';\n\nimport { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport { getAlignment, getSide, OPPOSITE, tagMiddleware, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): TypedMiddleware<'flip', FlipData> {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return tagMiddleware<'flip', FlipData, typeof flipMiddleware>(flipMiddleware, 'flip');\n}\n"],"mappings":"6DAiBA,SAAgB,EAAK,EAAuB,CAAC,EAAsC,CACjF,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAA,eAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAA,YAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAA,aAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAA,cAAc,EAAA,SAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAA,cAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAA,qBAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAA,cAAc,CAAiB,EAE7C,GAAI,CAAC,EAAA,YAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,EAAA,cAAuD,EAAgB,MAAM,CACtF"}
1
+ {"version":3,"file":"flip.cjs","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import type { DetectOverflowOptions, Middleware, Placement } from '../types';\n\nimport { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"6DAiBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAA,eAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAA,YAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAA,aAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAA,cAAc,EAAA,SAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAA,cAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAA,qBAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAA,cAAc,CAAiB,EAE7C,GAAI,CAAC,EAAA,YAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,CACT"}
@@ -1,4 +1,4 @@
1
- import type { DetectOverflowOptions, FlipData, Placement, TypedMiddleware } from '../types';
1
+ import type { DetectOverflowOptions, Middleware, Placement } from '../types';
2
2
  export interface FlipOptions extends DetectOverflowOptions {
3
3
  /**
4
4
  * Ordered list of candidate placements to try when the floating element overflows.
@@ -10,5 +10,5 @@ export interface FlipOptions extends DetectOverflowOptions {
10
10
  * Flips the floating element to the opposite side when it overflows the boundary.
11
11
  * Falls back to the candidate with the least total overflow when no candidate fits.
12
12
  */
13
- export declare function flip(options?: FlipOptions): TypedMiddleware<'flip', FlipData>;
13
+ export declare function flip(options?: FlipOptions): Middleware;
14
14
  //# sourceMappingURL=flip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/middleware/flip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,QAAQ,EAAc,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAKxG,MAAM,WAAW,WAAY,SAAQ,qBAAqB;IACxD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAyCjF"}
1
+ {"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/middleware/flip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAK7E,MAAM,WAAW,WAAY,SAAQ,qBAAqB;IACxD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CAyC1D"}
@@ -1,2 +1,2 @@
1
- import{OPPOSITE as e,getAlignment as t,getSide as n,tagMiddleware as r,withPlacement as i}from"../utils.js";import{detectOverflow as a,getPlacementOverflow as o,hasOverflow as s,totalOverflow as c}from"../overflow.js";function l(l={}){function u(r){let u=a(r,l);if(!s(u))return;let d=n(r.placement),f=t(r.placement),p=l.fallbackPlacements??[i(e[d],f)],m=[r.placement],h=r.placement,g=c(u);for(let e of p){let t=o(r,e,l),n=c(t);if(!s(t))return{data:{flip:{skippedPlacements:m}},reset:{placement:e}};m.push(e),n<g&&(h=e,g=n)}if(h!==r.placement)return{data:{flip:{skippedPlacements:m}},reset:{placement:h}}}return r(u,`flip`)}export{l as flip};
1
+ import{OPPOSITE as e,getAlignment as t,getSide as n,withPlacement as r}from"../utils.js";import{detectOverflow as i,getPlacementOverflow as a,hasOverflow as o,totalOverflow as s}from"../overflow.js";function c(c={}){function l(l){let u=i(l,c);if(!o(u))return;let d=n(l.placement),f=t(l.placement),p=c.fallbackPlacements??[r(e[d],f)],m=[l.placement],h=l.placement,g=s(u);for(let e of p){let t=a(l,e,c),n=s(t);if(!o(t))return{data:{flip:{skippedPlacements:m}},reset:{placement:e}};m.push(e),n<g&&(h=e,g=n)}if(h!==l.placement)return{data:{flip:{skippedPlacements:m}},reset:{placement:h}}}return l}export{c as flip};
2
2
  //# sourceMappingURL=flip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"flip.js","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import type { DetectOverflowOptions, FlipData, Middleware, Placement, TypedMiddleware } from '../types';\n\nimport { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport { getAlignment, getSide, OPPOSITE, tagMiddleware, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): TypedMiddleware<'flip', FlipData> {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return tagMiddleware<'flip', FlipData, typeof flipMiddleware>(flipMiddleware, 'flip');\n}\n"],"mappings":"0NAiBA,SAAgB,EAAK,EAAuB,CAAC,EAAsC,CACjF,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAc,EAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAc,CAAiB,EAE7C,GAAI,CAAC,EAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,EAAuD,EAAgB,MAAM,CACtF"}
1
+ {"version":3,"file":"flip.js","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import type { DetectOverflowOptions, Middleware, Placement } from '../types';\n\nimport { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"uMAiBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAc,EAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAc,CAAiB,EAE7C,GAAI,CAAC,EAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,CACT"}
@@ -1,2 +1,2 @@
1
- const e=require("../utils.cjs"),t=require("../overflow.cjs");function n(n={}){let r=n.strategy??`both`;function i(e){let{boundary:i,padding:a}=t.resolveBoundary(n,e),o={};if(r===`escaped`||r===`both`){let n=t.getFloatingRect(e),r=t.detectOverflowAtRect(n,i,a);o.escaped=t.isFullyClipped(n,r),o.escapedOffsets=r}if(r===`referenceHidden`||r===`both`){let n=t.detectOverflowAtRect(e.rects.reference,i,a);o.referenceHidden=t.isFullyClipped(e.rects.reference,n),o.referenceHiddenOffsets=n}return{data:{hide:o}}}return e.tagMiddleware(i,`hide`)}exports.hide=n;
1
+ const e=require("../overflow.cjs");function t(t={}){let n=t.strategy??`both`;function r(r){let{boundary:i,padding:a}=e.resolveBoundary(t,r),o={};if(n===`escaped`||n===`both`){let t=e.getFloatingRect(r),n=e.detectOverflowAtRect(t,i,a);o.escaped=e.isFullyClipped(t,n),o.escapedOffsets=n}if(n===`referenceHidden`||n===`both`){let t=e.detectOverflowAtRect(r.rects.reference,i,a);o.referenceHidden=e.isFullyClipped(r.rects.reference,t),o.referenceHiddenOffsets=t}return{data:{hide:o}}}return r}exports.hide=t;
2
2
  //# sourceMappingURL=hide.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hide.cjs","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import type { DetectOverflowOptions, HideData, Middleware, TypedMiddleware } from '../types';\n\nimport { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\nimport { tagMiddleware } from '../utils';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'` — whether the reference itself is off-screen.\n * - `'escaped'` — whether the floating element has fully exited the boundary.\n * - `'both'` (default) — both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): TypedMiddleware<'hide', HideData> {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return tagMiddleware<'hide', HideData, typeof hideMiddleware>(hideMiddleware, 'hide');\n}\n"],"mappings":"6DAoBA,SAAgB,EAAK,EAAuB,CAAC,EAAsC,CACjF,IAAM,EAAW,EAAQ,UAAY,OAErC,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAiB,CAAC,EAExB,GAAI,IAAa,WAAa,IAAa,OAAQ,CACjD,IAAM,EAAe,EAAA,gBAAgB,CAAK,EACpC,EAAiB,EAAA,qBAAqB,EAAc,EAAU,CAAO,EAE3E,EAAK,QAAU,EAAA,eAAe,EAAc,CAAc,EAC1D,EAAK,eAAiB,CACxB,CAEA,GAAI,IAAa,mBAAqB,IAAa,OAAQ,CACzD,IAAM,EAAyB,EAAA,qBAAqB,EAAM,MAAM,UAAW,EAAU,CAAO,EAE5F,EAAK,gBAAkB,EAAA,eAAe,EAAM,MAAM,UAAW,CAAsB,EACnF,EAAK,uBAAyB,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAM,CAAK,CAAE,CAChC,CAEA,OAAO,EAAA,cAAuD,EAAgB,MAAM,CACtF"}
1
+ {"version":3,"file":"hide.cjs","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import type { DetectOverflowOptions, HideData, Middleware } from '../types';\n\nimport { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'` — whether the reference itself is off-screen.\n * - `'escaped'` — whether the floating element has fully exited the boundary.\n * - `'both'` (default) — both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): Middleware {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return hideMiddleware;\n}\n"],"mappings":"mCAmBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,IAAM,EAAW,EAAQ,UAAY,OAErC,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAiB,CAAC,EAExB,GAAI,IAAa,WAAa,IAAa,OAAQ,CACjD,IAAM,EAAe,EAAA,gBAAgB,CAAK,EACpC,EAAiB,EAAA,qBAAqB,EAAc,EAAU,CAAO,EAE3E,EAAK,QAAU,EAAA,eAAe,EAAc,CAAc,EAC1D,EAAK,eAAiB,CACxB,CAEA,GAAI,IAAa,mBAAqB,IAAa,OAAQ,CACzD,IAAM,EAAyB,EAAA,qBAAqB,EAAM,MAAM,UAAW,EAAU,CAAO,EAE5F,EAAK,gBAAkB,EAAA,eAAe,EAAM,MAAM,UAAW,CAAsB,EACnF,EAAK,uBAAyB,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAM,CAAK,CAAE,CAChC,CAEA,OAAO,CACT"}