@vielzeug/orbit 2.1.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.d.ts.map +1 -1
- package/dist/devtools.js +1 -1
- package/dist/devtools.js.map +1 -1
- package/dist/float.cjs +1 -1
- package/dist/float.cjs.map +1 -1
- package/dist/float.d.ts +3 -4
- package/dist/float.d.ts.map +1 -1
- package/dist/float.js +1 -1
- package/dist/float.js.map +1 -1
- package/dist/inline.cjs.map +1 -1
- package/dist/inline.d.ts +0 -1
- package/dist/inline.d.ts.map +1 -1
- package/dist/inline.js.map +1 -1
- package/dist/middleware/arrow.cjs +1 -1
- package/dist/middleware/arrow.cjs.map +1 -1
- package/dist/middleware/arrow.d.ts.map +1 -1
- package/dist/middleware/arrow.js +1 -1
- package/dist/middleware/arrow.js.map +1 -1
- package/dist/middleware/shift.cjs +1 -1
- package/dist/middleware/shift.cjs.map +1 -1
- package/dist/middleware/shift.d.ts.map +1 -1
- package/dist/middleware/shift.js +1 -1
- package/dist/middleware/shift.js.map +1 -1
- package/dist/middleware/size.cjs.map +1 -1
- package/dist/middleware/size.d.ts +0 -1
- package/dist/middleware/size.d.ts.map +1 -1
- package/dist/middleware/size.js.map +1 -1
- package/dist/orbit.cjs +1 -1
- package/dist/orbit.cjs.map +1 -1
- package/dist/orbit.iife.js +1 -1
- package/dist/orbit.iife.js.map +1 -1
- package/dist/orbit.js +1 -1
- package/dist/orbit.js.map +1 -1
- package/dist/presets.cjs.map +1 -1
- package/dist/presets.d.ts +0 -4
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js.map +1 -1
- package/dist/reactive.cjs +1 -1
- package/dist/reactive.cjs.map +1 -1
- package/dist/reactive.d.ts +1 -1
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +1 -1
- package/dist/reactive.js.map +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
# @vielzeug/orbit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Floating UI positioning with lifecycle-owned geometry and middleware
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- `createPositioner()` owns coordinates, clipping, updates, and cleanup.
|
|
8
|
-
- `computePosition()` remains available for advanced platform-managed positioning.
|
|
9
|
-
- Middleware supports offset, flip, shift, size, hide, arrow, inline, and auto-placement.
|
|
10
|
-
- `@vielzeug/orbit/reactive` exposes a Ripple adapter when Ripple is installed.
|
|
11
|
-
- Root imports are SSR-safe; start positioners only from a client mount lifecycle.
|
|
12
|
-
|
|
13
|
-
## Install
|
|
5
|
+
## Installation
|
|
14
6
|
|
|
15
7
|
```sh
|
|
16
8
|
pnpm add @vielzeug/orbit
|
|
9
|
+
npm install @vielzeug/orbit
|
|
10
|
+
yarn add @vielzeug/orbit
|
|
17
11
|
```
|
|
18
12
|
|
|
19
13
|
Install `@vielzeug/ripple` only when importing `@vielzeug/orbit/reactive`.
|
|
20
14
|
|
|
21
15
|
## Quick Start
|
|
22
16
|
|
|
23
|
-
Create a positioner after both elements mount, then dispose it with their owner.
|
|
24
|
-
|
|
25
17
|
```ts
|
|
26
18
|
import { createPositioner, flip, offset, shift } from '@vielzeug/orbit';
|
|
27
19
|
|
|
@@ -30,8 +22,17 @@ const positioner = createPositioner(trigger, tooltip, {
|
|
|
30
22
|
placement: 'top',
|
|
31
23
|
});
|
|
32
24
|
|
|
33
|
-
positioner.start();
|
|
34
25
|
positioner.dispose();
|
|
35
26
|
```
|
|
36
27
|
|
|
37
|
-
|
|
28
|
+
## Documentation
|
|
29
|
+
|
|
30
|
+
- [Overview](https://vielzeug.dev/orbit/)
|
|
31
|
+
- [Usage Guide](https://vielzeug.dev/orbit/usage)
|
|
32
|
+
- [API Reference](https://vielzeug.dev/orbit/api)
|
|
33
|
+
- [Examples](https://vielzeug.dev/orbit/examples)
|
|
34
|
+
- [Migration Guide](https://vielzeug.dev/orbit/migration)
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
package/dist/devtools.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./float.cjs");function t(e,t){for(let[n,r]of Object.entries(t))e.style.setProperty(n,r)}function n(){let e=document.createElement(`div`);return e.dataset.orbitDebug=``,t(e,{"font-family":`monospace`,"font-size":`11px`,left:`0`,"pointer-events":`none`,position:`fixed`,top:`0`,"z-index":`2147483647`}),e}function r(e,n,r){let i=document.createElement(`div`);return i.textContent=e,t(i,{background:`rgba(0,100,255,0.85)`,"border-radius":`3px`,color:`#fff`,left:`${n}px`,padding:`1px 6px`,position:`fixed`,top:`${Math.max(0,r)}px`,"white-space":`nowrap`}),i}function i(e,n,r,i,a){let o=document.createElement(`div`);return t(o,{border:`1.5px dashed ${a}`,height:`${i}px`,left:`${e}px`,position:`fixed`,top:`${n}px`,width:`${r}px`}),o}function a(t,a,o={}){let s=n();document.body.appendChild(s);function c(e){if(s.innerHTML=``,s.appendChild(i(1,1,window.innerWidth-2,window.innerHeight-2,`rgba(0,100,255,0.3)`)),t instanceof Element){let e=t.getBoundingClientRect();s.appendChild(i(e.left,e.top,e.width,e.height,`rgba(255,120,0,0.7)`))}let n=a.getBoundingClientRect();s.appendChild(r(e.placement,n.left,n.top-22))}let l=o.apply;function u(t){l?l(t):e.applyDefault(t,a,o.strategy??`fixed`),c(t)}let d=e.createPositioner(t,a,{...o,apply:u}),f=d.dispose.bind(d);return
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./float.cjs");function t(e,t){for(let[n,r]of Object.entries(t))e.style.setProperty(n,r)}function n(){let e=document.createElement(`div`);return e.dataset.orbitDebug=``,t(e,{"font-family":`monospace`,"font-size":`11px`,left:`0`,"pointer-events":`none`,position:`fixed`,top:`0`,"z-index":`2147483647`}),e}function r(e,n,r){let i=document.createElement(`div`);return i.textContent=e,t(i,{background:`rgba(0,100,255,0.85)`,"border-radius":`3px`,color:`#fff`,left:`${n}px`,padding:`1px 6px`,position:`fixed`,top:`${Math.max(0,r)}px`,"white-space":`nowrap`}),i}function i(e,n,r,i,a){let o=document.createElement(`div`);return t(o,{border:`1.5px dashed ${a}`,height:`${i}px`,left:`${e}px`,position:`fixed`,top:`${n}px`,width:`${r}px`}),o}function a(t,a,o={}){let s=n();document.body.appendChild(s);function c(e){if(s.innerHTML=``,s.appendChild(i(1,1,window.innerWidth-2,window.innerHeight-2,`rgba(0,100,255,0.3)`)),t instanceof Element){let e=t.getBoundingClientRect();s.appendChild(i(e.left,e.top,e.width,e.height,`rgba(255,120,0,0.7)`))}let n=a.getBoundingClientRect();s.appendChild(r(e.placement,n.left,n.top-22))}let l=o.apply;function u(t){l?l(t):e.applyDefault(t,a,o.strategy??`fixed`),c(t)}let d=e.createPositioner(t,a,{...o,apply:u}),f=d.dispose.bind(d);return Object.assign(d,{dispose(){f(),s.remove()}})}exports.debugPositioner=a;
|
|
2
2
|
//# sourceMappingURL=devtools.cjs.map
|
package/dist/devtools.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.cjs","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["/**\n * @vielzeug/orbit — debug overlay for positioning visualisation.\n *\n * Import from the dedicated sub-path so it is tree-shaken from production bundles:\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n * ```\n */\n\nimport type { Positioner, PositionerOptions } from './float';\nimport { applyDefault, createPositioner } from './float';\nimport type { ComputePositionResult, ReferenceElement } from './types';\n\n// ── Overlay helpers ───────────────────────────────────────────────────────────\n\nfunction setStyles(el: HTMLElement, styles: Record<string, string>): void {\n for (const [key, val] of Object.entries(styles)) {\n el.style.setProperty(key, val);\n }\n}\n\nfunction createOverlay(): HTMLElement {\n const el = document.createElement('div');\n\n el.dataset.orbitDebug = '';\n setStyles(el, {\n 'font-family': 'monospace',\n 'font-size': '11px',\n left: '0',\n 'pointer-events': 'none',\n position: 'fixed',\n top: '0',\n 'z-index': '2147483647',\n });\n\n return el;\n}\n\nfunction createPlacementBadge(text: string, x: number, y: number): HTMLElement {\n const el = document.createElement('div');\n\n el.textContent = text;\n setStyles(el, {\n background: 'rgba(0,100,255,0.85)',\n 'border-radius': '3px',\n color: '#fff',\n left: `${x}px`,\n padding: '1px 6px',\n position: 'fixed',\n top: `${Math.max(0, y)}px`,\n 'white-space': 'nowrap',\n });\n\n return el;\n}\n\nfunction createOutlineBox(x: number, y: number, width: number, height: number, color: string): HTMLElement {\n const el = document.createElement('div');\n\n setStyles(el, {\n border: `1.5px dashed ${color}`,\n height: `${height}px`,\n left: `${x}px`,\n position: 'fixed',\n top: `${y}px`,\n width: `${width}px`,\n });\n\n return el;\n}\n\n// ── Public API ────────────────────────────────────────────────────────────────\n\n/**\n * Wraps `createPositioner()` and attaches a persistent visual debug overlay to the document.\n *\n * The overlay renders on every position update:\n * - **Blue dashed outline** — the viewport boundary used by overflow detection.\n * - **Orange dashed outline** — the reference element's bounding rect.\n * - **Blue label** — the active placement string (e.g. `\"top-start\"`).\n *\n * The overlay is automatically removed when `handle.dispose()` is called.\n *\n * Use only in development. Tree-shaken from production bundles via the sub-path import.\n *\n * @example\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n *\n * const handle = debugPositioner(reference, tooltip, {\n * placement: 'top',\n * middleware: [offset(8), flip(), shift({ padding: 6 })],\n * });\n * // on teardown:\n * handle.dispose();\n * ```\n */\nexport function debugPositioner(\n reference: ReferenceElement,\n floating: HTMLElement,\n options: PositionerOptions = {},\n): Positioner {\n const overlay = createOverlay();\n\n document.body.appendChild(overlay);\n\n function renderOverlay(result: ComputePositionResult): void {\n overlay.innerHTML = '';\n\n // Viewport boundary.\n overlay.appendChild(createOutlineBox(1, 1, window.innerWidth - 2, window.innerHeight - 2, 'rgba(0,100,255,0.3)'));\n\n // Reference element.\n if (reference instanceof Element) {\n const r = reference.getBoundingClientRect();\n\n overlay.appendChild(createOutlineBox(r.left, r.top, r.width, r.height, 'rgba(255,120,0,0.7)'));\n }\n\n // Placement label — positioned just above the floating element.\n const fr = floating.getBoundingClientRect();\n\n overlay.appendChild(createPlacementBadge(result.placement, fr.left, fr.top - 22));\n }\n\n const userApply = options.apply;\n\n function wrappedApply(result: ComputePositionResult): void {\n if (userApply) {\n userApply(result);\n } else {\n applyDefault(result, floating, options.strategy ?? 'fixed');\n }\n\n renderOverlay(result);\n }\n\n const positioner = createPositioner(reference, floating, { ...options, apply: wrappedApply });\n const dispose = positioner.dispose.bind(positioner);\n\n
|
|
1
|
+
{"version":3,"file":"devtools.cjs","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["/**\n * @vielzeug/orbit — debug overlay for positioning visualisation.\n *\n * Import from the dedicated sub-path so it is tree-shaken from production bundles:\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n * ```\n */\n\nimport type { Positioner, PositionerOptions } from './float';\nimport { applyDefault, createPositioner } from './float';\nimport type { ComputePositionResult, ReferenceElement } from './types';\n\n// ── Overlay helpers ───────────────────────────────────────────────────────────\n\nfunction setStyles(el: HTMLElement, styles: Record<string, string>): void {\n for (const [key, val] of Object.entries(styles)) {\n el.style.setProperty(key, val);\n }\n}\n\nfunction createOverlay(): HTMLElement {\n const el = document.createElement('div');\n\n el.dataset.orbitDebug = '';\n setStyles(el, {\n 'font-family': 'monospace',\n 'font-size': '11px',\n left: '0',\n 'pointer-events': 'none',\n position: 'fixed',\n top: '0',\n 'z-index': '2147483647',\n });\n\n return el;\n}\n\nfunction createPlacementBadge(text: string, x: number, y: number): HTMLElement {\n const el = document.createElement('div');\n\n el.textContent = text;\n setStyles(el, {\n background: 'rgba(0,100,255,0.85)',\n 'border-radius': '3px',\n color: '#fff',\n left: `${x}px`,\n padding: '1px 6px',\n position: 'fixed',\n top: `${Math.max(0, y)}px`,\n 'white-space': 'nowrap',\n });\n\n return el;\n}\n\nfunction createOutlineBox(x: number, y: number, width: number, height: number, color: string): HTMLElement {\n const el = document.createElement('div');\n\n setStyles(el, {\n border: `1.5px dashed ${color}`,\n height: `${height}px`,\n left: `${x}px`,\n position: 'fixed',\n top: `${y}px`,\n width: `${width}px`,\n });\n\n return el;\n}\n\n// ── Public API ────────────────────────────────────────────────────────────────\n\n/**\n * Wraps `createPositioner()` and attaches a persistent visual debug overlay to the document.\n *\n * The overlay renders on every position update:\n * - **Blue dashed outline** — the viewport boundary used by overflow detection.\n * - **Orange dashed outline** — the reference element's bounding rect.\n * - **Blue label** — the active placement string (e.g. `\"top-start\"`).\n *\n * The overlay is automatically removed when `handle.dispose()` is called.\n *\n * Use only in development. Tree-shaken from production bundles via the sub-path import.\n *\n * @example\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n *\n * const handle = debugPositioner(reference, tooltip, {\n * placement: 'top',\n * middleware: [offset(8), flip(), shift({ padding: 6 })],\n * });\n * // on teardown:\n * handle.dispose();\n * ```\n */\nexport function debugPositioner(\n reference: ReferenceElement,\n floating: HTMLElement,\n options: PositionerOptions = {},\n): Positioner {\n const overlay = createOverlay();\n\n document.body.appendChild(overlay);\n\n function renderOverlay(result: ComputePositionResult): void {\n overlay.innerHTML = '';\n\n // Viewport boundary.\n overlay.appendChild(createOutlineBox(1, 1, window.innerWidth - 2, window.innerHeight - 2, 'rgba(0,100,255,0.3)'));\n\n // Reference element.\n if (reference instanceof Element) {\n const r = reference.getBoundingClientRect();\n\n overlay.appendChild(createOutlineBox(r.left, r.top, r.width, r.height, 'rgba(255,120,0,0.7)'));\n }\n\n // Placement label — positioned just above the floating element.\n const fr = floating.getBoundingClientRect();\n\n overlay.appendChild(createPlacementBadge(result.placement, fr.left, fr.top - 22));\n }\n\n const userApply = options.apply;\n\n function wrappedApply(result: ComputePositionResult): void {\n if (userApply) {\n userApply(result);\n } else {\n applyDefault(result, floating, options.strategy ?? 'fixed');\n }\n\n renderOverlay(result);\n }\n\n const positioner = createPositioner(reference, floating, { ...options, apply: wrappedApply });\n const dispose = positioner.dispose.bind(positioner);\n\n return Object.assign(positioner, {\n dispose(): void {\n dispose();\n overlay.remove();\n },\n });\n}\n"],"mappings":"kGAeA,SAAS,EAAU,EAAiB,EAAsC,CACxE,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAM,EAC5C,EAAG,MAAM,YAAY,EAAK,CAAG,CAEjC,CAEA,SAAS,GAA6B,CACpC,IAAM,EAAK,SAAS,cAAc,KAAK,EAavC,MAXA,GAAG,QAAQ,WAAa,GACxB,EAAU,EAAI,CACZ,cAAe,YACf,YAAa,OACb,KAAM,IACN,iBAAkB,OAClB,SAAU,QACV,IAAK,IACL,UAAW,YACb,CAAC,EAEM,CACT,CAEA,SAAS,EAAqB,EAAc,EAAW,EAAwB,CAC7E,IAAM,EAAK,SAAS,cAAc,KAAK,EAcvC,MAZA,GAAG,YAAc,EACjB,EAAU,EAAI,CACZ,WAAY,uBACZ,gBAAiB,MACjB,MAAO,OACP,KAAM,GAAG,EAAE,IACX,QAAS,UACT,SAAU,QACV,IAAK,GAAG,KAAK,IAAI,EAAG,CAAC,EAAE,IACvB,cAAe,QACjB,CAAC,EAEM,CACT,CAEA,SAAS,EAAiB,EAAW,EAAW,EAAe,EAAgB,EAA4B,CACzG,IAAM,EAAK,SAAS,cAAc,KAAK,EAWvC,OATA,EAAU,EAAI,CACZ,OAAQ,gBAAgB,IACxB,OAAQ,GAAG,EAAO,IAClB,KAAM,GAAG,EAAE,IACX,SAAU,QACV,IAAK,GAAG,EAAE,IACV,MAAO,GAAG,EAAM,GAClB,CAAC,EAEM,CACT,CA4BA,SAAgB,EACd,EACA,EACA,EAA6B,CAAC,EAClB,CACZ,IAAM,EAAU,EAAc,EAE9B,SAAS,KAAK,YAAY,CAAO,EAEjC,SAAS,EAAc,EAAqC,CAO1D,GANA,EAAQ,UAAY,GAGpB,EAAQ,YAAY,EAAiB,EAAG,EAAG,OAAO,WAAa,EAAG,OAAO,YAAc,EAAG,qBAAqB,CAAC,EAG5G,aAAqB,QAAS,CAChC,IAAM,EAAI,EAAU,sBAAsB,EAE1C,EAAQ,YAAY,EAAiB,EAAE,KAAM,EAAE,IAAK,EAAE,MAAO,EAAE,OAAQ,qBAAqB,CAAC,CAC/F,CAGA,IAAM,EAAK,EAAS,sBAAsB,EAE1C,EAAQ,YAAY,EAAqB,EAAO,UAAW,EAAG,KAAM,EAAG,IAAM,EAAE,CAAC,CAClF,CAEA,IAAM,EAAY,EAAQ,MAE1B,SAAS,EAAa,EAAqC,CACrD,EACF,EAAU,CAAM,EAEhB,EAAA,aAAa,EAAQ,EAAU,EAAQ,UAAY,OAAO,EAG5D,EAAc,CAAM,CACtB,CAEA,IAAM,EAAa,EAAA,iBAAiB,EAAW,EAAU,CAAE,GAAG,EAAS,MAAO,CAAa,CAAC,EACtF,EAAU,EAAW,QAAQ,KAAK,CAAU,EAElD,OAAO,OAAO,OAAO,EAAY,CAC/B,SAAgB,CACd,EAAQ,EACR,EAAQ,OAAO,CACjB,CACF,CAAC,CACH"}
|
package/dist/devtools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE7D,OAAO,KAAK,EAAyB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA8DvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,WAAW,EACrB,OAAO,GAAE,iBAAsB,GAC9B,UAAU,
|
|
1
|
+
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE7D,OAAO,KAAK,EAAyB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA8DvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,WAAW,EACrB,OAAO,GAAE,iBAAsB,GAC9B,UAAU,CA6CZ"}
|
package/dist/devtools.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{applyDefault as e,createPositioner as t}from"./float.js";function n(e,t){for(let[n,r]of Object.entries(t))e.style.setProperty(n,r)}function r(){let e=document.createElement(`div`);return e.dataset.orbitDebug=``,n(e,{"font-family":`monospace`,"font-size":`11px`,left:`0`,"pointer-events":`none`,position:`fixed`,top:`0`,"z-index":`2147483647`}),e}function i(e,t,r){let i=document.createElement(`div`);return i.textContent=e,n(i,{background:`rgba(0,100,255,0.85)`,"border-radius":`3px`,color:`#fff`,left:`${t}px`,padding:`1px 6px`,position:`fixed`,top:`${Math.max(0,r)}px`,"white-space":`nowrap`}),i}function a(e,t,r,i,a){let o=document.createElement(`div`);return n(o,{border:`1.5px dashed ${a}`,height:`${i}px`,left:`${e}px`,position:`fixed`,top:`${t}px`,width:`${r}px`}),o}function o(n,o,s={}){let c=r();document.body.appendChild(c);function l(e){if(c.innerHTML=``,c.appendChild(a(1,1,window.innerWidth-2,window.innerHeight-2,`rgba(0,100,255,0.3)`)),n instanceof Element){let e=n.getBoundingClientRect();c.appendChild(a(e.left,e.top,e.width,e.height,`rgba(255,120,0,0.7)`))}let t=o.getBoundingClientRect();c.appendChild(i(e.placement,t.left,t.top-22))}let u=s.apply;function d(t){u?u(t):e(t,o,s.strategy??`fixed`),l(t)}let f=t(n,o,{...s,apply:d}),p=f.dispose.bind(f);return
|
|
1
|
+
import{applyDefault as e,createPositioner as t}from"./float.js";function n(e,t){for(let[n,r]of Object.entries(t))e.style.setProperty(n,r)}function r(){let e=document.createElement(`div`);return e.dataset.orbitDebug=``,n(e,{"font-family":`monospace`,"font-size":`11px`,left:`0`,"pointer-events":`none`,position:`fixed`,top:`0`,"z-index":`2147483647`}),e}function i(e,t,r){let i=document.createElement(`div`);return i.textContent=e,n(i,{background:`rgba(0,100,255,0.85)`,"border-radius":`3px`,color:`#fff`,left:`${t}px`,padding:`1px 6px`,position:`fixed`,top:`${Math.max(0,r)}px`,"white-space":`nowrap`}),i}function a(e,t,r,i,a){let o=document.createElement(`div`);return n(o,{border:`1.5px dashed ${a}`,height:`${i}px`,left:`${e}px`,position:`fixed`,top:`${t}px`,width:`${r}px`}),o}function o(n,o,s={}){let c=r();document.body.appendChild(c);function l(e){if(c.innerHTML=``,c.appendChild(a(1,1,window.innerWidth-2,window.innerHeight-2,`rgba(0,100,255,0.3)`)),n instanceof Element){let e=n.getBoundingClientRect();c.appendChild(a(e.left,e.top,e.width,e.height,`rgba(255,120,0,0.7)`))}let t=o.getBoundingClientRect();c.appendChild(i(e.placement,t.left,t.top-22))}let u=s.apply;function d(t){u?u(t):e(t,o,s.strategy??`fixed`),l(t)}let f=t(n,o,{...s,apply:d}),p=f.dispose.bind(f);return Object.assign(f,{dispose(){p(),c.remove()}})}export{o as debugPositioner};
|
|
2
2
|
//# sourceMappingURL=devtools.js.map
|
package/dist/devtools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.js","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["/**\n * @vielzeug/orbit — debug overlay for positioning visualisation.\n *\n * Import from the dedicated sub-path so it is tree-shaken from production bundles:\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n * ```\n */\n\nimport type { Positioner, PositionerOptions } from './float';\nimport { applyDefault, createPositioner } from './float';\nimport type { ComputePositionResult, ReferenceElement } from './types';\n\n// ── Overlay helpers ───────────────────────────────────────────────────────────\n\nfunction setStyles(el: HTMLElement, styles: Record<string, string>): void {\n for (const [key, val] of Object.entries(styles)) {\n el.style.setProperty(key, val);\n }\n}\n\nfunction createOverlay(): HTMLElement {\n const el = document.createElement('div');\n\n el.dataset.orbitDebug = '';\n setStyles(el, {\n 'font-family': 'monospace',\n 'font-size': '11px',\n left: '0',\n 'pointer-events': 'none',\n position: 'fixed',\n top: '0',\n 'z-index': '2147483647',\n });\n\n return el;\n}\n\nfunction createPlacementBadge(text: string, x: number, y: number): HTMLElement {\n const el = document.createElement('div');\n\n el.textContent = text;\n setStyles(el, {\n background: 'rgba(0,100,255,0.85)',\n 'border-radius': '3px',\n color: '#fff',\n left: `${x}px`,\n padding: '1px 6px',\n position: 'fixed',\n top: `${Math.max(0, y)}px`,\n 'white-space': 'nowrap',\n });\n\n return el;\n}\n\nfunction createOutlineBox(x: number, y: number, width: number, height: number, color: string): HTMLElement {\n const el = document.createElement('div');\n\n setStyles(el, {\n border: `1.5px dashed ${color}`,\n height: `${height}px`,\n left: `${x}px`,\n position: 'fixed',\n top: `${y}px`,\n width: `${width}px`,\n });\n\n return el;\n}\n\n// ── Public API ────────────────────────────────────────────────────────────────\n\n/**\n * Wraps `createPositioner()` and attaches a persistent visual debug overlay to the document.\n *\n * The overlay renders on every position update:\n * - **Blue dashed outline** — the viewport boundary used by overflow detection.\n * - **Orange dashed outline** — the reference element's bounding rect.\n * - **Blue label** — the active placement string (e.g. `\"top-start\"`).\n *\n * The overlay is automatically removed when `handle.dispose()` is called.\n *\n * Use only in development. Tree-shaken from production bundles via the sub-path import.\n *\n * @example\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n *\n * const handle = debugPositioner(reference, tooltip, {\n * placement: 'top',\n * middleware: [offset(8), flip(), shift({ padding: 6 })],\n * });\n * // on teardown:\n * handle.dispose();\n * ```\n */\nexport function debugPositioner(\n reference: ReferenceElement,\n floating: HTMLElement,\n options: PositionerOptions = {},\n): Positioner {\n const overlay = createOverlay();\n\n document.body.appendChild(overlay);\n\n function renderOverlay(result: ComputePositionResult): void {\n overlay.innerHTML = '';\n\n // Viewport boundary.\n overlay.appendChild(createOutlineBox(1, 1, window.innerWidth - 2, window.innerHeight - 2, 'rgba(0,100,255,0.3)'));\n\n // Reference element.\n if (reference instanceof Element) {\n const r = reference.getBoundingClientRect();\n\n overlay.appendChild(createOutlineBox(r.left, r.top, r.width, r.height, 'rgba(255,120,0,0.7)'));\n }\n\n // Placement label — positioned just above the floating element.\n const fr = floating.getBoundingClientRect();\n\n overlay.appendChild(createPlacementBadge(result.placement, fr.left, fr.top - 22));\n }\n\n const userApply = options.apply;\n\n function wrappedApply(result: ComputePositionResult): void {\n if (userApply) {\n userApply(result);\n } else {\n applyDefault(result, floating, options.strategy ?? 'fixed');\n }\n\n renderOverlay(result);\n }\n\n const positioner = createPositioner(reference, floating, { ...options, apply: wrappedApply });\n const dispose = positioner.dispose.bind(positioner);\n\n
|
|
1
|
+
{"version":3,"file":"devtools.js","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["/**\n * @vielzeug/orbit — debug overlay for positioning visualisation.\n *\n * Import from the dedicated sub-path so it is tree-shaken from production bundles:\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n * ```\n */\n\nimport type { Positioner, PositionerOptions } from './float';\nimport { applyDefault, createPositioner } from './float';\nimport type { ComputePositionResult, ReferenceElement } from './types';\n\n// ── Overlay helpers ───────────────────────────────────────────────────────────\n\nfunction setStyles(el: HTMLElement, styles: Record<string, string>): void {\n for (const [key, val] of Object.entries(styles)) {\n el.style.setProperty(key, val);\n }\n}\n\nfunction createOverlay(): HTMLElement {\n const el = document.createElement('div');\n\n el.dataset.orbitDebug = '';\n setStyles(el, {\n 'font-family': 'monospace',\n 'font-size': '11px',\n left: '0',\n 'pointer-events': 'none',\n position: 'fixed',\n top: '0',\n 'z-index': '2147483647',\n });\n\n return el;\n}\n\nfunction createPlacementBadge(text: string, x: number, y: number): HTMLElement {\n const el = document.createElement('div');\n\n el.textContent = text;\n setStyles(el, {\n background: 'rgba(0,100,255,0.85)',\n 'border-radius': '3px',\n color: '#fff',\n left: `${x}px`,\n padding: '1px 6px',\n position: 'fixed',\n top: `${Math.max(0, y)}px`,\n 'white-space': 'nowrap',\n });\n\n return el;\n}\n\nfunction createOutlineBox(x: number, y: number, width: number, height: number, color: string): HTMLElement {\n const el = document.createElement('div');\n\n setStyles(el, {\n border: `1.5px dashed ${color}`,\n height: `${height}px`,\n left: `${x}px`,\n position: 'fixed',\n top: `${y}px`,\n width: `${width}px`,\n });\n\n return el;\n}\n\n// ── Public API ────────────────────────────────────────────────────────────────\n\n/**\n * Wraps `createPositioner()` and attaches a persistent visual debug overlay to the document.\n *\n * The overlay renders on every position update:\n * - **Blue dashed outline** — the viewport boundary used by overflow detection.\n * - **Orange dashed outline** — the reference element's bounding rect.\n * - **Blue label** — the active placement string (e.g. `\"top-start\"`).\n *\n * The overlay is automatically removed when `handle.dispose()` is called.\n *\n * Use only in development. Tree-shaken from production bundles via the sub-path import.\n *\n * @example\n * ```ts\n * import { debugPositioner } from '@vielzeug/orbit/devtools';\n *\n * const handle = debugPositioner(reference, tooltip, {\n * placement: 'top',\n * middleware: [offset(8), flip(), shift({ padding: 6 })],\n * });\n * // on teardown:\n * handle.dispose();\n * ```\n */\nexport function debugPositioner(\n reference: ReferenceElement,\n floating: HTMLElement,\n options: PositionerOptions = {},\n): Positioner {\n const overlay = createOverlay();\n\n document.body.appendChild(overlay);\n\n function renderOverlay(result: ComputePositionResult): void {\n overlay.innerHTML = '';\n\n // Viewport boundary.\n overlay.appendChild(createOutlineBox(1, 1, window.innerWidth - 2, window.innerHeight - 2, 'rgba(0,100,255,0.3)'));\n\n // Reference element.\n if (reference instanceof Element) {\n const r = reference.getBoundingClientRect();\n\n overlay.appendChild(createOutlineBox(r.left, r.top, r.width, r.height, 'rgba(255,120,0,0.7)'));\n }\n\n // Placement label — positioned just above the floating element.\n const fr = floating.getBoundingClientRect();\n\n overlay.appendChild(createPlacementBadge(result.placement, fr.left, fr.top - 22));\n }\n\n const userApply = options.apply;\n\n function wrappedApply(result: ComputePositionResult): void {\n if (userApply) {\n userApply(result);\n } else {\n applyDefault(result, floating, options.strategy ?? 'fixed');\n }\n\n renderOverlay(result);\n }\n\n const positioner = createPositioner(reference, floating, { ...options, apply: wrappedApply });\n const dispose = positioner.dispose.bind(positioner);\n\n return Object.assign(positioner, {\n dispose(): void {\n dispose();\n overlay.remove();\n },\n });\n}\n"],"mappings":"gEAeA,SAAS,EAAU,EAAiB,EAAsC,CACxE,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAM,EAC5C,EAAG,MAAM,YAAY,EAAK,CAAG,CAEjC,CAEA,SAAS,GAA6B,CACpC,IAAM,EAAK,SAAS,cAAc,KAAK,EAavC,MAXA,GAAG,QAAQ,WAAa,GACxB,EAAU,EAAI,CACZ,cAAe,YACf,YAAa,OACb,KAAM,IACN,iBAAkB,OAClB,SAAU,QACV,IAAK,IACL,UAAW,YACb,CAAC,EAEM,CACT,CAEA,SAAS,EAAqB,EAAc,EAAW,EAAwB,CAC7E,IAAM,EAAK,SAAS,cAAc,KAAK,EAcvC,MAZA,GAAG,YAAc,EACjB,EAAU,EAAI,CACZ,WAAY,uBACZ,gBAAiB,MACjB,MAAO,OACP,KAAM,GAAG,EAAE,IACX,QAAS,UACT,SAAU,QACV,IAAK,GAAG,KAAK,IAAI,EAAG,CAAC,EAAE,IACvB,cAAe,QACjB,CAAC,EAEM,CACT,CAEA,SAAS,EAAiB,EAAW,EAAW,EAAe,EAAgB,EAA4B,CACzG,IAAM,EAAK,SAAS,cAAc,KAAK,EAWvC,OATA,EAAU,EAAI,CACZ,OAAQ,gBAAgB,IACxB,OAAQ,GAAG,EAAO,IAClB,KAAM,GAAG,EAAE,IACX,SAAU,QACV,IAAK,GAAG,EAAE,IACV,MAAO,GAAG,EAAM,GAClB,CAAC,EAEM,CACT,CA4BA,SAAgB,EACd,EACA,EACA,EAA6B,CAAC,EAClB,CACZ,IAAM,EAAU,EAAc,EAE9B,SAAS,KAAK,YAAY,CAAO,EAEjC,SAAS,EAAc,EAAqC,CAO1D,GANA,EAAQ,UAAY,GAGpB,EAAQ,YAAY,EAAiB,EAAG,EAAG,OAAO,WAAa,EAAG,OAAO,YAAc,EAAG,qBAAqB,CAAC,EAG5G,aAAqB,QAAS,CAChC,IAAM,EAAI,EAAU,sBAAsB,EAE1C,EAAQ,YAAY,EAAiB,EAAE,KAAM,EAAE,IAAK,EAAE,MAAO,EAAE,OAAQ,qBAAqB,CAAC,CAC/F,CAGA,IAAM,EAAK,EAAS,sBAAsB,EAE1C,EAAQ,YAAY,EAAqB,EAAO,UAAW,EAAG,KAAM,EAAG,IAAM,EAAE,CAAC,CAClF,CAEA,IAAM,EAAY,EAAQ,MAE1B,SAAS,EAAa,EAAqC,CACrD,EACF,EAAU,CAAM,EAEhB,EAAa,EAAQ,EAAU,EAAQ,UAAY,OAAO,EAG5D,EAAc,CAAM,CACtB,CAEA,IAAM,EAAa,EAAiB,EAAW,EAAU,CAAE,GAAG,EAAS,MAAO,CAAa,CAAC,EACtF,EAAU,EAAW,QAAQ,KAAK,CAAU,EAElD,OAAO,OAAO,OAAO,EAAY,CAC/B,SAAgB,CACd,EAAQ,EACR,EAAQ,OAAO,CACjB,CACF,CAAC,CACH"}
|
package/dist/float.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./auto-update.cjs"),t=require("./containing-block.cjs"),n=require("./core.cjs"),r=require("./overflow.cjs");function i(e,n){return n===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:t.getContainingBlock(e)}function a(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function o(t,o,{apply:s,autoUpdate:c={},boundary:l=`clippingAncestors`,middleware:u,padding:d,placement:f=`bottom`,strategy:p=`fixed`}={}){let m=new AbortController,h=!0,g=!1,_,v
|
|
1
|
+
const e=require("./auto-update.cjs"),t=require("./containing-block.cjs"),n=require("./core.cjs"),r=require("./overflow.cjs");function i(e,n){return n===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:t.getContainingBlock(e)}function a(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function o(t,o,{apply:s,autoUpdate:c={},boundary:l=`clippingAncestors`,middleware:u,padding:d,placement:f=`bottom`,strategy:p=`fixed`}={}){let m=new AbortController,h=!0,g=!1,_,v;function y(){if(!h)return;let e=i(o,p),c=l===`clippingAncestors`?r.getClippingAncestorRect(o):l,m=n.computePosition(t,o,{boundary:c,containingBlock:e,middleware:u,padding:d,placement:f});v=m,(s??(e=>a(e,o,p)))(m)}let b={get disposalSignal(){return m.signal},dispose(){g||(g=!0,h=!1,m.abort(),_?.())},get disposed(){return g},getPosition:()=>v,[Symbol.dispose](){this.dispose()},update(){g||y()}};return c===!1?y():_=e.autoUpdate(t,o,y,c),b}exports.applyDefault=a,exports.createPositioner=o;
|
|
2
2
|
//# sourceMappingURL=float.cjs.map
|
package/dist/float.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"float.cjs","names":[],"sources":["../src/float.ts"],"sourcesContent":["import { type AutoUpdateOptions, autoUpdate } from './auto-update';\nimport { getContainingBlock } from './containing-block';\nimport { computePosition } from './core';\nimport { getClippingAncestorRect } from './overflow';\nimport type { ComputePositionOptions, ComputePositionResult, ReferenceElement } from './types';\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
|
|
1
|
+
{"version":3,"file":"float.cjs","names":[],"sources":["../src/float.ts"],"sourcesContent":["import { type AutoUpdateOptions, autoUpdate } from './auto-update';\nimport { getContainingBlock } from './containing-block';\nimport { computePosition } from './core';\nimport { getClippingAncestorRect } from './overflow';\nimport type { ComputePositionOptions, ComputePositionResult, ReferenceElement } from './types';\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;\n update(): void;\n [Symbol.dispose](): void;\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\n/** @internal — default apply: sets position, left, top on the floating element. */\nexport function 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 starts immediately and owns coordinate strategy, clipping-boundary resolution,\n * updates, and cleanup. Create it after the elements mount and dispose it 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 const controller = new AbortController();\n let active = true;\n let disposed = false;\n let cleanup: (() => void) | undefined;\n let lastPosition: ComputePositionResult;\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 const positioner: Positioner = {\n get disposalSignal() {\n return controller.signal;\n },\n dispose() {\n if (disposed) return;\n\n disposed = true;\n active = false;\n controller.abort();\n cleanup?.();\n },\n get disposed() {\n return disposed;\n },\n getPosition: () => lastPosition,\n [Symbol.dispose]() {\n this.dispose();\n },\n update() {\n if (!disposed) update();\n },\n };\n\n if (autoUpdateOptions === false) update();\n else cleanup = autoUpdate(reference, floating, update, autoUpdateOptions);\n\n return positioner;\n}\n"],"mappings":"6HAwBA,SAAS,EAAuB,EAAuB,EAA4C,CAGjG,OAFI,IAAa,WAAmB,EAAS,wBAAwB,QAAU,EAAS,aAAe,KAEhG,EAAA,mBAAmB,CAAQ,CACpC,CAGA,SAAgB,EAAa,EAA+B,EAAuB,EAAkC,CACnH,EAAS,MAAM,SAAW,EAC1B,EAAS,MAAM,KAAO,GAAG,EAAO,EAAE,IAClC,EAAS,MAAM,IAAM,GAAG,EAAO,EAAE,GACnC,CAQA,SAAgB,EACd,EACA,EACA,CACE,QACA,WAAY,EAAoB,CAAC,EACjC,SAAU,EAAiB,oBAC3B,aACA,UACA,YAAY,SACZ,WAAW,SACU,CAAC,EACZ,CACZ,IAAM,EAAa,IAAI,gBACnB,EAAS,GACT,EAAW,GACX,EACA,EAEJ,SAAS,GAAe,CACtB,GAAI,CAAC,EAAQ,OAEb,IAAM,EAAkB,EAAuB,EAAU,CAAQ,EAC3D,EAAW,IAAmB,oBAAsB,EAAA,wBAAwB,CAAQ,EAAI,EACxF,EAAS,EAAA,gBAAgB,EAAW,EAAU,CAAE,WAAU,kBAAiB,aAAY,UAAS,WAAU,CAAC,EAEjH,EAAe,GACd,IAAW,GAAa,EAAa,EAAU,EAAU,CAAQ,GAAA,CAAI,CAAM,CAC9E,CAEA,IAAM,EAAyB,CAC7B,IAAI,gBAAiB,CACnB,OAAO,EAAW,MACpB,EACA,SAAU,CACJ,IAEJ,EAAW,GACX,EAAS,GACT,EAAW,MAAM,EACjB,IAAU,EACZ,EACA,IAAI,UAAW,CACb,OAAO,CACT,EACA,gBAAmB,EACnB,CAAC,OAAO,UAAW,CACjB,KAAK,QAAQ,CACf,EACA,QAAS,CACF,GAAU,EAAO,CACxB,CACF,EAKA,OAHI,IAAsB,GAAO,EAAO,EACnC,EAAU,EAAA,WAAW,EAAW,EAAU,EAAQ,CAAiB,EAEjE,CACT"}
|
package/dist/float.d.ts
CHANGED
|
@@ -11,16 +11,15 @@ export interface Positioner {
|
|
|
11
11
|
readonly disposalSignal: AbortSignal;
|
|
12
12
|
dispose(): void;
|
|
13
13
|
readonly disposed: boolean;
|
|
14
|
-
getPosition(): ComputePositionResult
|
|
15
|
-
start(): void;
|
|
14
|
+
getPosition(): ComputePositionResult;
|
|
16
15
|
update(): void;
|
|
17
16
|
[Symbol.dispose](): void;
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
19
|
* Creates a lifecycle-owned floating positioner.
|
|
21
20
|
*
|
|
22
|
-
* The positioner owns coordinate strategy, clipping-boundary resolution,
|
|
23
|
-
*
|
|
21
|
+
* The positioner starts immediately and owns coordinate strategy, clipping-boundary resolution,
|
|
22
|
+
* updates, and cleanup. Create it after the elements mount and dispose it when their owner ends.
|
|
24
23
|
*/
|
|
25
24
|
export declare function createPositioner(reference: ReferenceElement, floating: HTMLElement, { apply, autoUpdate: autoUpdateOptions, boundary: boundaryOption, middleware, padding, placement, strategy, }?: PositionerOptions): Positioner;
|
|
26
25
|
//# sourceMappingURL=float.d.ts.map
|
package/dist/float.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"float.d.ts","sourceRoot":"","sources":["../src/float.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,eAAe,CAAC;AAInE,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE/F,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,iBAAiB,CAAC;IACrG,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAChD,UAAU,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC;IACvC,QAAQ,CAAC,EAAE,sBAAsB,CAAC,UAAU,CAAC,GAAG,mBAAmB,CAAC;IACpE,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC;IACrC,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,WAAW,IAAI,qBAAqB,
|
|
1
|
+
{"version":3,"file":"float.d.ts","sourceRoot":"","sources":["../src/float.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,eAAe,CAAC;AAInE,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE/F,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,iBAAiB,CAAC;IACrG,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAChD,UAAU,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC;IACvC,QAAQ,CAAC,EAAE,sBAAsB,CAAC,UAAU,CAAC,GAAG,mBAAmB,CAAC;IACpE,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC;IACrC,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,WAAW,IAAI,qBAAqB,CAAC;IACrC,MAAM,IAAI,IAAI,CAAC;IACf,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;CAC1B;AAeD;;;;;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,CA8CZ"}
|
package/dist/float.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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,n){return n===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:t(e)}function a(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function o(t,o,{apply:s,autoUpdate:c={},boundary:l=`clippingAncestors`,middleware:u,padding:d,placement:f=`bottom`,strategy:p=`fixed`}={}){let m=new AbortController,h=!0,g=!1,_,v
|
|
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,n){return n===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:t(e)}function a(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function o(t,o,{apply:s,autoUpdate:c={},boundary:l=`clippingAncestors`,middleware:u,padding:d,placement:f=`bottom`,strategy:p=`fixed`}={}){let m=new AbortController,h=!0,g=!1,_,v;function y(){if(!h)return;let e=i(o,p),c=l===`clippingAncestors`?r(o):l,m=n(t,o,{boundary:c,containingBlock:e,middleware:u,padding:d,placement:f});v=m,(s??(e=>a(e,o,p)))(m)}let b={get disposalSignal(){return m.signal},dispose(){g||(g=!0,h=!1,m.abort(),_?.())},get disposed(){return g},getPosition:()=>v,[Symbol.dispose](){this.dispose()},update(){g||y()}};return c===!1?y():_=e(t,o,y,c),b}export{a as applyDefault,o 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 AutoUpdateOptions, autoUpdate } from './auto-update';\nimport { getContainingBlock } from './containing-block';\nimport { computePosition } from './core';\nimport { getClippingAncestorRect } from './overflow';\nimport type { ComputePositionOptions, ComputePositionResult, ReferenceElement } from './types';\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
|
|
1
|
+
{"version":3,"file":"float.js","names":[],"sources":["../src/float.ts"],"sourcesContent":["import { type AutoUpdateOptions, autoUpdate } from './auto-update';\nimport { getContainingBlock } from './containing-block';\nimport { computePosition } from './core';\nimport { getClippingAncestorRect } from './overflow';\nimport type { ComputePositionOptions, ComputePositionResult, ReferenceElement } from './types';\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;\n update(): void;\n [Symbol.dispose](): void;\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\n/** @internal — default apply: sets position, left, top on the floating element. */\nexport function 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 starts immediately and owns coordinate strategy, clipping-boundary resolution,\n * updates, and cleanup. Create it after the elements mount and dispose it 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 const controller = new AbortController();\n let active = true;\n let disposed = false;\n let cleanup: (() => void) | undefined;\n let lastPosition: ComputePositionResult;\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 const positioner: Positioner = {\n get disposalSignal() {\n return controller.signal;\n },\n dispose() {\n if (disposed) return;\n\n disposed = true;\n active = false;\n controller.abort();\n cleanup?.();\n },\n get disposed() {\n return disposed;\n },\n getPosition: () => lastPosition,\n [Symbol.dispose]() {\n this.dispose();\n },\n update() {\n if (!disposed) update();\n },\n };\n\n if (autoUpdateOptions === false) update();\n else cleanup = autoUpdate(reference, floating, update, autoUpdateOptions);\n\n return positioner;\n}\n"],"mappings":"6MAwBA,SAAS,EAAuB,EAAuB,EAA4C,CAGjG,OAFI,IAAa,WAAmB,EAAS,wBAAwB,QAAU,EAAS,aAAe,KAEhG,EAAmB,CAAQ,CACpC,CAGA,SAAgB,EAAa,EAA+B,EAAuB,EAAkC,CACnH,EAAS,MAAM,SAAW,EAC1B,EAAS,MAAM,KAAO,GAAG,EAAO,EAAE,IAClC,EAAS,MAAM,IAAM,GAAG,EAAO,EAAE,GACnC,CAQA,SAAgB,EACd,EACA,EACA,CACE,QACA,WAAY,EAAoB,CAAC,EACjC,SAAU,EAAiB,oBAC3B,aACA,UACA,YAAY,SACZ,WAAW,SACU,CAAC,EACZ,CACZ,IAAM,EAAa,IAAI,gBACnB,EAAS,GACT,EAAW,GACX,EACA,EAEJ,SAAS,GAAe,CACtB,GAAI,CAAC,EAAQ,OAEb,IAAM,EAAkB,EAAuB,EAAU,CAAQ,EAC3D,EAAW,IAAmB,oBAAsB,EAAwB,CAAQ,EAAI,EACxF,EAAS,EAAgB,EAAW,EAAU,CAAE,WAAU,kBAAiB,aAAY,UAAS,WAAU,CAAC,EAEjH,EAAe,GACd,IAAW,GAAa,EAAa,EAAU,EAAU,CAAQ,GAAA,CAAI,CAAM,CAC9E,CAEA,IAAM,EAAyB,CAC7B,IAAI,gBAAiB,CACnB,OAAO,EAAW,MACpB,EACA,SAAU,CACJ,IAEJ,EAAW,GACX,EAAS,GACT,EAAW,MAAM,EACjB,IAAU,EACZ,EACA,IAAI,UAAW,CACb,OAAO,CACT,EACA,gBAAmB,EACnB,CAAC,OAAO,UAAW,CACjB,KAAK,QAAQ,CACf,EACA,QAAS,CACF,GAAU,EAAO,CACxB,CACF,EAKA,OAHI,IAAsB,GAAO,EAAO,EACnC,EAAU,EAAW,EAAW,EAAU,EAAQ,CAAiB,EAEjE,CACT"}
|
package/dist/inline.cjs.map
CHANGED
|
@@ -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, 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 * 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 * 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\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 *
|
|
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 * 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 * 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\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 * ```\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 inlineMiddleware;\n}\n"],"mappings":"kGAMA,SAAS,EAAe,EAAqC,CAG3D,MAFI,EAAE,mBAAoB,IAAc,OAAO,EAAU,gBAAmB,WAAmB,CAAC,EAEzF,MAAM,KAAM,EAAU,eAAiD,CAAC,CAAC,CAC7E,IAAI,EAAA,MAAM,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,aAAa,EAAQ,SAAW,CAAC,EAC3C,EAAO,EAAA,QAAQ,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,CACT"}
|
package/dist/inline.d.ts
CHANGED
|
@@ -29,7 +29,6 @@ export interface InlineOptions {
|
|
|
29
29
|
* placement: 'top',
|
|
30
30
|
* middleware: [inline({ x: cursorX, y: cursorY }), flip(), shift({ padding: 6 })],
|
|
31
31
|
* });
|
|
32
|
-
* positioner.start();
|
|
33
32
|
* ```
|
|
34
33
|
*/
|
|
35
34
|
export declare function inline(options?: InlineOptions): Middleware;
|
package/dist/inline.d.ts.map
CHANGED
|
@@ -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;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED
|
|
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;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,UAAU,CAsC9D"}
|
package/dist/inline.js.map
CHANGED
|
@@ -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, 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 * 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 * 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\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 *
|
|
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 * 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 * 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\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 * ```\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 inlineMiddleware;\n}\n"],"mappings":"mEAMA,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,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils.cjs");
|
|
1
|
+
const e=require("../utils.cjs");let t=require("@vielzeug/arsenal");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 i}exports.arrow=n;
|
|
2
2
|
//# sourceMappingURL=arrow.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow.cjs","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { Middleware, Padding } from '../types';\n\nimport {
|
|
1
|
+
{"version":3,"file":"arrow.cjs","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\n\nimport type { Middleware, Padding } from '../types';\n\nimport { 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":"mEA6BA,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,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,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../src/middleware/arrow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"arrow.d.ts","sourceRoot":"","sources":["../../src/middleware/arrow.ts"],"names":[],"mappings":"AAEA,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"}
|
package/dist/middleware/arrow.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getSide as e,toRect as t,toSideObject as n}from"../utils.js";import{clamp as r}from"@vielzeug/arsenal";function i({element:i,padding:a=0}){function o(o){let s=e(o.placement),c=n(a),l=t(i.getBoundingClientRect());if(s===`top`||s===`bottom`){let e=o.rects.reference.x+o.rects.reference.width/2-o.x-l.width/2,t=c.left,n=Math.max(t,o.rects.floating.width-l.width-c.right),i=r(e,t,n);return{data:{arrow:{centerOffset:e-i,constrained:i!==e,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=r(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 { Middleware, Padding } from '../types';\n\nimport {
|
|
1
|
+
{"version":3,"file":"arrow.js","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\n\nimport type { Middleware, Padding } from '../types';\n\nimport { 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":"8GA6BA,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"),t=require("../overflow.cjs");
|
|
1
|
+
const e=require("../utils.cjs"),t=require("../overflow.cjs");let n=require("@vielzeug/arsenal");function r(t={}){return(r,i)=>{let{placement:a,rects:o,x:s,y:c}=r,l=e.getSide(a),u=l===`top`||l===`bottom`,d=typeof t.offset==`function`?t.offset(r):t.offset??0;if(u){let e=o.reference.x-d,t=o.reference.x+o.reference.width+d-o.floating.width,[r,a]=e<=t?[e,t]:[t,e],c=(0,n.clamp)(s+i.crossAxis,r,a);return{...i,crossAxis:c-s}}let f=o.reference.y-d,p=o.reference.y+o.reference.height+d-o.floating.height,[m,h]=f<=p?[f,p]:[p,f],g=(0,n.clamp)(c+i.crossAxis,m,h);return{...i,crossAxis:g-c}}}function i(n={}){let{crossAxis:r=!0,limiter:i,mainAxis:a=!1}=n;function o(o){let s=t.detectOverflow(o,n),c=e.getSide(o.placement),l=c===`top`||c===`bottom`,u=Math.max(s.left,0)-Math.max(s.right,0),d=Math.max(s.top,0)-Math.max(s.bottom,0),f=l?r:a,p=l?a:r,m=f?u:0,h=p?d:0;if(i){let e=i(o,{crossAxis:l?m:h,mainAxis:l?h:m});m=l?e.crossAxis:e.mainAxis,h=l?e.mainAxis:e.crossAxis}return{data:{shift:{x:m,y:h}},x:o.x+m,y:o.y+h}}return o}exports.limitShift=r,exports.shift=i;
|
|
2
2
|
//# sourceMappingURL=shift.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shift.cjs","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { detectOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport {
|
|
1
|
+
{"version":3,"file":"shift.cjs","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { detectOverflow } from '../overflow';\n\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport { getSide } from '../utils';\n\n/**\n * A limiter function passed to `shift()` that constrains the maximum allowed drift.\n * Receives the current middleware state and the proposed shift correction (as deltas),\n * and returns the clamped correction.\n */\nexport type ShiftLimiter = (\n state: MiddlewareState,\n correction: { crossAxis: number; mainAxis: number },\n) => { crossAxis: number; mainAxis: number };\n\nexport interface LimitShiftOptions {\n /**\n * Extra pixels of allowed drift past the reference's cross-axis extent before clamping kicks in.\n * Can be a static number or a function returning a number based on current state.\n * Default: `0`.\n */\n offset?: number | ((state: MiddlewareState) => number);\n}\n\n/**\n * Returns a {@link ShiftLimiter} that constrains `shift()` so the floating element\n * stays visually connected to the reference along the cross axis.\n *\n * Without a limiter, `shift()` will push the float as far as needed to fit in the boundary —\n * potentially sliding it far away from the reference. `limitShift` clamps the drift so the\n * float stays within the reference's cross-axis extent (± `offset` pixels).\n *\n * @example\n * ```ts\n * // Tooltip stays above the button even when viewport clips it.\n * shift({ padding: 6, limiter: limitShift() })\n *\n * // Allow up to 10px of drift beyond the reference's edges.\n * shift({ padding: 6, limiter: limitShift({ offset: 10 }) })\n * ```\n */\nexport function limitShift(options: LimitShiftOptions = {}): ShiftLimiter {\n return (state, correction) => {\n const { placement, rects, x, y } = state;\n const side = getSide(placement);\n const isVertical = side === 'top' || side === 'bottom';\n const extra = typeof options.offset === 'function' ? options.offset(state) : (options.offset ?? 0);\n\n if (isVertical) {\n // Cross axis is x. Clamp float.left to [ref.left-extra, ref.right+extra-float.width].\n const lo = rects.reference.x - extra;\n const hi = rects.reference.x + rects.reference.width + extra - rects.floating.width;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(x + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - x };\n }\n\n // Cross axis is y. Clamp float.top to [ref.top-extra, ref.bottom+extra-float.height].\n const lo = rects.reference.y - extra;\n const hi = rects.reference.y + rects.reference.height + extra - rects.floating.height;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(y + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - y };\n };\n}\n\nexport interface ShiftOptions extends DetectOverflowOptions {\n /**\n * Whether to shift along the cross axis (perpendicular to the reference direction).\n * Default: `true`.\n */\n crossAxis?: boolean;\n /**\n * Constrains how far `shift()` can move the floating element along the cross axis.\n * Pass `limitShift()` to keep the float within the reference's extent.\n */\n limiter?: ShiftLimiter;\n /**\n * Whether to shift along the main axis (the axis away from the reference).\n * Default: `false` — main-axis overflow is better handled by `flip`.\n */\n mainAxis?: boolean;\n}\n\n/**\n * Shifts the floating element along the cross axis to keep it inside the boundary.\n *\n * By default only the cross axis is corrected. Enable `mainAxis` to also shift\n * along the main axis (useful when `flip` is not in the pipeline).\n *\n * | Placement | Cross axis | Main axis |\n * |------------------|------------|-----------|\n * | `top` / `bottom` | horizontal | vertical |\n * | `left` / `right` | vertical | horizontal|\n */\nexport function shift(options: ShiftOptions = {}): Middleware {\n const { crossAxis = true, limiter, mainAxis = false } = options;\n\n function shiftMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const overflow = detectOverflow(state, options);\n const side = getSide(state.placement);\n const isVertical = side === 'top' || side === 'bottom';\n\n const xCorrection = Math.max(overflow.left, 0) - Math.max(overflow.right, 0);\n const yCorrection = Math.max(overflow.top, 0) - Math.max(overflow.bottom, 0);\n const applyX = isVertical ? crossAxis : mainAxis;\n const applyY = isVertical ? mainAxis : crossAxis;\n\n let dx = applyX ? xCorrection : 0;\n let dy = applyY ? yCorrection : 0;\n\n if (limiter) {\n const limited = limiter(state, {\n crossAxis: isVertical ? dx : dy,\n mainAxis: isVertical ? dy : dx,\n });\n\n dx = isVertical ? limited.crossAxis : limited.mainAxis;\n dy = isVertical ? limited.mainAxis : limited.crossAxis;\n }\n\n return { data: { shift: { x: dx, y: dy } }, x: state.x + dx, y: state.y + dy };\n }\n\n return shiftMiddleware;\n}\n"],"mappings":"gGA0CA,SAAgB,EAAW,EAA6B,CAAC,EAAiB,CACxE,OAAQ,EAAO,IAAe,CAC5B,GAAM,CAAE,YAAW,QAAO,IAAG,KAAM,EAC7B,EAAO,EAAA,QAAQ,CAAS,EACxB,EAAa,IAAS,OAAS,IAAS,SACxC,EAAQ,OAAO,EAAQ,QAAW,WAAa,EAAQ,OAAO,CAAK,EAAK,EAAQ,QAAU,EAEhG,GAAI,EAAY,CAEd,IAAM,EAAK,EAAM,UAAU,EAAI,EACzB,EAAK,EAAM,UAAU,EAAI,EAAM,UAAU,MAAQ,EAAQ,EAAM,SAAS,MACxE,CAAC,EAAK,GAAO,GAAM,EAAK,CAAC,EAAI,CAAE,EAAI,CAAC,EAAI,CAAE,EAC1C,GAAA,EAAU,EAAA,MAAA,CAAM,EAAI,EAAW,UAAW,EAAK,CAAG,EAExD,MAAO,CAAE,GAAG,EAAY,UAAW,EAAU,CAAE,CACjD,CAGA,IAAM,EAAK,EAAM,UAAU,EAAI,EACzB,EAAK,EAAM,UAAU,EAAI,EAAM,UAAU,OAAS,EAAQ,EAAM,SAAS,OACzE,CAAC,EAAK,GAAO,GAAM,EAAK,CAAC,EAAI,CAAE,EAAI,CAAC,EAAI,CAAE,EAC1C,GAAA,EAAU,EAAA,MAAA,CAAM,EAAI,EAAW,UAAW,EAAK,CAAG,EAExD,MAAO,CAAE,GAAG,EAAY,UAAW,EAAU,CAAE,CACjD,CACF,CA+BA,SAAgB,EAAM,EAAwB,CAAC,EAAe,CAC5D,GAAM,CAAE,YAAY,GAAM,UAAS,WAAW,IAAU,EAExD,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAW,EAAA,eAAe,EAAO,CAAO,EACxC,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAa,IAAS,OAAS,IAAS,SAExC,EAAc,KAAK,IAAI,EAAS,KAAM,CAAC,EAAI,KAAK,IAAI,EAAS,MAAO,CAAC,EACrE,EAAc,KAAK,IAAI,EAAS,IAAK,CAAC,EAAI,KAAK,IAAI,EAAS,OAAQ,CAAC,EACrE,EAAS,EAAa,EAAY,EAClC,EAAS,EAAa,EAAW,EAEnC,EAAK,EAAS,EAAc,EAC5B,EAAK,EAAS,EAAc,EAEhC,GAAI,EAAS,CACX,IAAM,EAAU,EAAQ,EAAO,CAC7B,UAAW,EAAa,EAAK,EAC7B,SAAU,EAAa,EAAK,CAC9B,CAAC,EAED,EAAK,EAAa,EAAQ,UAAY,EAAQ,SAC9C,EAAK,EAAa,EAAQ,SAAW,EAAQ,SAC/C,CAEA,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,EAAG,EAAI,EAAG,CAAG,CAAE,EAAG,EAAG,EAAM,EAAI,EAAI,EAAG,EAAM,EAAI,CAAG,CAC/E,CAEA,OAAO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shift.d.ts","sourceRoot":"","sources":["../../src/middleware/shift.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shift.d.ts","sourceRoot":"","sources":["../../src/middleware/shift.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAGnF;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAChD;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,MAAM,CAAC,CAAC;CACxD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,YAAY,CAyBxE;AAED,MAAM,WAAW,YAAa,SAAQ,qBAAqB;IACzD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,UAAU,CA8B5D"}
|
package/dist/middleware/shift.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getSide as e}from"../utils.js";import{detectOverflow as t}from"../overflow.js";import{clamp as n}from"@vielzeug/arsenal";function r(t={}){return(r,i)=>{let{placement:a,rects:o,x:s,y:c}=r,l=e(a),u=l===`top`||l===`bottom`,d=typeof t.offset==`function`?t.offset(r):t.offset??0;if(u){let e=o.reference.x-d,t=o.reference.x+o.reference.width+d-o.floating.width,[r,a]=e<=t?[e,t]:[t,e],c=n(s+i.crossAxis,r,a);return{...i,crossAxis:c-s}}let f=o.reference.y-d,p=o.reference.y+o.reference.height+d-o.floating.height,[m,h]=f<=p?[f,p]:[p,f],g=n(c+i.crossAxis,m,h);return{...i,crossAxis:g-c}}}function i(n={}){let{crossAxis:r=!0,limiter:i,mainAxis:a=!1}=n;function o(o){let s=t(o,n),c=e(o.placement),l=c===`top`||c===`bottom`,u=Math.max(s.left,0)-Math.max(s.right,0),d=Math.max(s.top,0)-Math.max(s.bottom,0),f=l?r:a,p=l?a:r,m=f?u:0,h=p?d:0;if(i){let e=i(o,{crossAxis:l?m:h,mainAxis:l?h:m});m=l?e.crossAxis:e.mainAxis,h=l?e.mainAxis:e.crossAxis}return{data:{shift:{x:m,y:h}},x:o.x+m,y:o.y+h}}return o}export{r as limitShift,i as shift};
|
|
2
2
|
//# sourceMappingURL=shift.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shift.js","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { detectOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport {
|
|
1
|
+
{"version":3,"file":"shift.js","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { detectOverflow } from '../overflow';\n\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport { getSide } from '../utils';\n\n/**\n * A limiter function passed to `shift()` that constrains the maximum allowed drift.\n * Receives the current middleware state and the proposed shift correction (as deltas),\n * and returns the clamped correction.\n */\nexport type ShiftLimiter = (\n state: MiddlewareState,\n correction: { crossAxis: number; mainAxis: number },\n) => { crossAxis: number; mainAxis: number };\n\nexport interface LimitShiftOptions {\n /**\n * Extra pixels of allowed drift past the reference's cross-axis extent before clamping kicks in.\n * Can be a static number or a function returning a number based on current state.\n * Default: `0`.\n */\n offset?: number | ((state: MiddlewareState) => number);\n}\n\n/**\n * Returns a {@link ShiftLimiter} that constrains `shift()` so the floating element\n * stays visually connected to the reference along the cross axis.\n *\n * Without a limiter, `shift()` will push the float as far as needed to fit in the boundary —\n * potentially sliding it far away from the reference. `limitShift` clamps the drift so the\n * float stays within the reference's cross-axis extent (± `offset` pixels).\n *\n * @example\n * ```ts\n * // Tooltip stays above the button even when viewport clips it.\n * shift({ padding: 6, limiter: limitShift() })\n *\n * // Allow up to 10px of drift beyond the reference's edges.\n * shift({ padding: 6, limiter: limitShift({ offset: 10 }) })\n * ```\n */\nexport function limitShift(options: LimitShiftOptions = {}): ShiftLimiter {\n return (state, correction) => {\n const { placement, rects, x, y } = state;\n const side = getSide(placement);\n const isVertical = side === 'top' || side === 'bottom';\n const extra = typeof options.offset === 'function' ? options.offset(state) : (options.offset ?? 0);\n\n if (isVertical) {\n // Cross axis is x. Clamp float.left to [ref.left-extra, ref.right+extra-float.width].\n const lo = rects.reference.x - extra;\n const hi = rects.reference.x + rects.reference.width + extra - rects.floating.width;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(x + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - x };\n }\n\n // Cross axis is y. Clamp float.top to [ref.top-extra, ref.bottom+extra-float.height].\n const lo = rects.reference.y - extra;\n const hi = rects.reference.y + rects.reference.height + extra - rects.floating.height;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(y + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - y };\n };\n}\n\nexport interface ShiftOptions extends DetectOverflowOptions {\n /**\n * Whether to shift along the cross axis (perpendicular to the reference direction).\n * Default: `true`.\n */\n crossAxis?: boolean;\n /**\n * Constrains how far `shift()` can move the floating element along the cross axis.\n * Pass `limitShift()` to keep the float within the reference's extent.\n */\n limiter?: ShiftLimiter;\n /**\n * Whether to shift along the main axis (the axis away from the reference).\n * Default: `false` — main-axis overflow is better handled by `flip`.\n */\n mainAxis?: boolean;\n}\n\n/**\n * Shifts the floating element along the cross axis to keep it inside the boundary.\n *\n * By default only the cross axis is corrected. Enable `mainAxis` to also shift\n * along the main axis (useful when `flip` is not in the pipeline).\n *\n * | Placement | Cross axis | Main axis |\n * |------------------|------------|-----------|\n * | `top` / `bottom` | horizontal | vertical |\n * | `left` / `right` | vertical | horizontal|\n */\nexport function shift(options: ShiftOptions = {}): Middleware {\n const { crossAxis = true, limiter, mainAxis = false } = options;\n\n function shiftMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const overflow = detectOverflow(state, options);\n const side = getSide(state.placement);\n const isVertical = side === 'top' || side === 'bottom';\n\n const xCorrection = Math.max(overflow.left, 0) - Math.max(overflow.right, 0);\n const yCorrection = Math.max(overflow.top, 0) - Math.max(overflow.bottom, 0);\n const applyX = isVertical ? crossAxis : mainAxis;\n const applyY = isVertical ? mainAxis : crossAxis;\n\n let dx = applyX ? xCorrection : 0;\n let dy = applyY ? yCorrection : 0;\n\n if (limiter) {\n const limited = limiter(state, {\n crossAxis: isVertical ? dx : dy,\n mainAxis: isVertical ? dy : dx,\n });\n\n dx = isVertical ? limited.crossAxis : limited.mainAxis;\n dy = isVertical ? limited.mainAxis : limited.crossAxis;\n }\n\n return { data: { shift: { x: dx, y: dy } }, x: state.x + dx, y: state.y + dy };\n }\n\n return shiftMiddleware;\n}\n"],"mappings":"gIA0CA,SAAgB,EAAW,EAA6B,CAAC,EAAiB,CACxE,OAAQ,EAAO,IAAe,CAC5B,GAAM,CAAE,YAAW,QAAO,IAAG,KAAM,EAC7B,EAAO,EAAQ,CAAS,EACxB,EAAa,IAAS,OAAS,IAAS,SACxC,EAAQ,OAAO,EAAQ,QAAW,WAAa,EAAQ,OAAO,CAAK,EAAK,EAAQ,QAAU,EAEhG,GAAI,EAAY,CAEd,IAAM,EAAK,EAAM,UAAU,EAAI,EACzB,EAAK,EAAM,UAAU,EAAI,EAAM,UAAU,MAAQ,EAAQ,EAAM,SAAS,MACxE,CAAC,EAAK,GAAO,GAAM,EAAK,CAAC,EAAI,CAAE,EAAI,CAAC,EAAI,CAAE,EAC1C,EAAU,EAAM,EAAI,EAAW,UAAW,EAAK,CAAG,EAExD,MAAO,CAAE,GAAG,EAAY,UAAW,EAAU,CAAE,CACjD,CAGA,IAAM,EAAK,EAAM,UAAU,EAAI,EACzB,EAAK,EAAM,UAAU,EAAI,EAAM,UAAU,OAAS,EAAQ,EAAM,SAAS,OACzE,CAAC,EAAK,GAAO,GAAM,EAAK,CAAC,EAAI,CAAE,EAAI,CAAC,EAAI,CAAE,EAC1C,EAAU,EAAM,EAAI,EAAW,UAAW,EAAK,CAAG,EAExD,MAAO,CAAE,GAAG,EAAY,UAAW,EAAU,CAAE,CACjD,CACF,CA+BA,SAAgB,EAAM,EAAwB,CAAC,EAAe,CAC5D,GAAM,CAAE,YAAY,GAAM,UAAS,WAAW,IAAU,EAExD,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAW,EAAe,EAAO,CAAO,EACxC,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAa,IAAS,OAAS,IAAS,SAExC,EAAc,KAAK,IAAI,EAAS,KAAM,CAAC,EAAI,KAAK,IAAI,EAAS,MAAO,CAAC,EACrE,EAAc,KAAK,IAAI,EAAS,IAAK,CAAC,EAAI,KAAK,IAAI,EAAS,OAAQ,CAAC,EACrE,EAAS,EAAa,EAAY,EAClC,EAAS,EAAa,EAAW,EAEnC,EAAK,EAAS,EAAc,EAC5B,EAAK,EAAS,EAAc,EAEhC,GAAI,EAAS,CACX,IAAM,EAAU,EAAQ,EAAO,CAC7B,UAAW,EAAa,EAAK,EAC7B,SAAU,EAAa,EAAK,CAC9B,CAAC,EAED,EAAK,EAAa,EAAQ,UAAY,EAAQ,SAC9C,EAAK,EAAa,EAAQ,SAAW,EAAQ,SAC/C,CAEA,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,EAAG,EAAI,EAAG,CAAG,CAAE,EAAG,EAAG,EAAM,EAAI,EAAI,EAAG,EAAM,EAAI,CAAG,CAC/E,CAEA,OAAO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size.cjs","names":[],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n *
|
|
1
|
+
{"version":3,"file":"size.cjs","names":[],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n * ```\n */\nexport function size(options: SizeOptions = {}): Middleware {\n function sizeMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const side = getSide(state.placement);\n const top = boundary.y + padding.top;\n const right = boundary.x + boundary.width - padding.right;\n const bottom = boundary.y + boundary.height - padding.bottom;\n const left = boundary.x + padding.left;\n\n const availableHeight =\n side === 'bottom'\n ? Math.max(0, bottom - state.y)\n : side === 'top'\n ? Math.max(0, state.rects.reference.y - top)\n : Math.max(0, bottom - top);\n\n const availableWidth =\n side === 'right'\n ? Math.max(0, right - state.x)\n : side === 'left'\n ? Math.max(0, state.rects.reference.x - left)\n : Math.max(0, right - left);\n\n return { data: { size: { availableHeight, availableWidth } } };\n }\n\n return sizeMiddleware;\n}\n"],"mappings":"6DAwBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAM,EAAS,EAAI,EAAQ,IAC3B,EAAQ,EAAS,EAAI,EAAS,MAAQ,EAAQ,MAC9C,EAAS,EAAS,EAAI,EAAS,OAAS,EAAQ,OAChD,EAAO,EAAS,EAAI,EAAQ,KAgBlC,MAAO,CAAE,KAAM,CAAE,KAAM,CAAE,gBAbvB,IAAS,SACL,KAAK,IAAI,EAAG,EAAS,EAAM,CAAC,EAC5B,IAAS,MACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAG,EACzC,KAAK,IAAI,EAAG,EAAS,CAAG,EASU,eANxC,IAAS,QACL,KAAK,IAAI,EAAG,EAAQ,EAAM,CAAC,EAC3B,IAAS,OACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAI,EAC1C,KAAK,IAAI,EAAG,EAAQ,CAAI,CAEyB,CAAE,CAAE,CAC/D,CAEA,OAAO,CACT"}
|
|
@@ -16,7 +16,6 @@ export type SizeOptions = DetectOverflowOptions;
|
|
|
16
16
|
* el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;
|
|
17
17
|
* },
|
|
18
18
|
* });
|
|
19
|
-
* positioner.start();
|
|
20
19
|
* ```
|
|
21
20
|
*/
|
|
22
21
|
export declare function size(options?: SizeOptions): Middleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../src/middleware/size.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGlE,MAAM,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAEhD
|
|
1
|
+
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../src/middleware/size.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGlE,MAAM,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAEhD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CA2B1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size.js","names":[],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n *
|
|
1
|
+
{"version":3,"file":"size.js","names":[],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n * ```\n */\nexport function size(options: SizeOptions = {}): Middleware {\n function sizeMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const side = getSide(state.placement);\n const top = boundary.y + padding.top;\n const right = boundary.x + boundary.width - padding.right;\n const bottom = boundary.y + boundary.height - padding.bottom;\n const left = boundary.x + padding.left;\n\n const availableHeight =\n side === 'bottom'\n ? Math.max(0, bottom - state.y)\n : side === 'top'\n ? Math.max(0, state.rects.reference.y - top)\n : Math.max(0, bottom - top);\n\n const availableWidth =\n side === 'right'\n ? Math.max(0, right - state.x)\n : side === 'left'\n ? Math.max(0, state.rects.reference.x - left)\n : Math.max(0, right - left);\n\n return { data: { size: { availableHeight, availableWidth } } };\n }\n\n return sizeMiddleware;\n}\n"],"mappings":"uFAwBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAM,EAAS,EAAI,EAAQ,IAC3B,EAAQ,EAAS,EAAI,EAAS,MAAQ,EAAQ,MAC9C,EAAS,EAAS,EAAI,EAAS,OAAS,EAAQ,OAChD,EAAO,EAAS,EAAI,EAAQ,KAgBlC,MAAO,CAAE,KAAM,CAAE,KAAM,CAAE,gBAbvB,IAAS,SACL,KAAK,IAAI,EAAG,EAAS,EAAM,CAAC,EAC5B,IAAS,MACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAG,EACzC,KAAK,IAAI,EAAG,EAAS,CAAG,EASU,eANxC,IAAS,QACL,KAAK,IAAI,EAAG,EAAQ,EAAM,CAAC,EAC3B,IAAS,OACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAI,EAC1C,KAAK,IAAI,EAAG,EAAQ,CAAI,CAEyB,CAAE,CAAE,CAC/D,CAEA,OAAO,CACT"}
|