@vielzeug/orbit 2.0.1 → 2.1.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/dist/auto-update.cjs.map +1 -1
- package/dist/auto-update.d.ts +10 -10
- package/dist/auto-update.d.ts.map +1 -1
- package/dist/auto-update.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +1 -36
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- 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/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/float.cjs +1 -1
- package/dist/float.cjs.map +1 -1
- package/dist/float.d.ts +1 -1
- package/dist/float.d.ts.map +1 -1
- package/dist/float.js +1 -1
- package/dist/float.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +15 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/inline.cjs.map +1 -1
- package/dist/inline.d.ts +7 -7
- package/dist/inline.d.ts.map +1 -1
- package/dist/inline.js.map +1 -1
- package/dist/middleware/auto-placement.cjs.map +1 -1
- package/dist/middleware/auto-placement.d.ts +5 -5
- package/dist/middleware/auto-placement.d.ts.map +1 -1
- package/dist/middleware/auto-placement.js.map +1 -1
- package/dist/middleware/flip.cjs.map +1 -1
- package/dist/middleware/flip.d.ts.map +1 -1
- package/dist/middleware/flip.js.map +1 -1
- package/dist/middleware/hide.cjs.map +1 -1
- package/dist/middleware/hide.d.ts.map +1 -1
- package/dist/middleware/hide.js.map +1 -1
- package/dist/middleware/shift.cjs.map +1 -1
- package/dist/middleware/shift.d.ts +5 -5
- package/dist/middleware/shift.d.ts.map +1 -1
- package/dist/middleware/shift.js.map +1 -1
- package/dist/middleware/size.cjs.map +1 -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 +1 -1
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js.map +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.map +1 -1
- package/dist/types.d.ts +32 -32
- package/dist/types.d.ts.map +1 -1
- package/package.json +41 -36
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
+
export type { AutoUpdateOptions } from './auto-update';
|
|
2
|
+
export { autoUpdate } from './auto-update';
|
|
3
|
+
export { computePosition } from './core';
|
|
1
4
|
export { OrbitConfigError, OrbitError } from './errors';
|
|
2
|
-
export { computePosition, computePositionAsync, computePositionRaf, getRects } from './core';
|
|
3
|
-
export { detectOverflow, getClippingAncestorRect } from './overflow';
|
|
4
|
-
export { createPositioner } from './float';
|
|
5
5
|
export type { Positioner, PositionerOptions, PositionStrategy } from './float';
|
|
6
|
-
export {
|
|
7
|
-
export type {
|
|
8
|
-
export {
|
|
6
|
+
export { createPositioner } from './float';
|
|
7
|
+
export type { InlineOptions } from './inline';
|
|
8
|
+
export { inline } from './inline';
|
|
9
9
|
export type { ArrowOptions } from './middleware/arrow';
|
|
10
|
-
export {
|
|
10
|
+
export { arrow } from './middleware/arrow';
|
|
11
11
|
export type { AutoPlacementOptions } from './middleware/auto-placement';
|
|
12
|
-
export {
|
|
12
|
+
export { autoPlacement } from './middleware/auto-placement';
|
|
13
13
|
export type { FlipOptions } from './middleware/flip';
|
|
14
|
-
export {
|
|
14
|
+
export { flip } from './middleware/flip';
|
|
15
15
|
export type { HideOptions } from './middleware/hide';
|
|
16
|
-
export {
|
|
17
|
-
export type { InlineOptions } from './inline';
|
|
18
|
-
export { offset } from './middleware/offset';
|
|
16
|
+
export { hide } from './middleware/hide';
|
|
19
17
|
export type { OffsetConfig, OffsetValue } from './middleware/offset';
|
|
20
|
-
export {
|
|
18
|
+
export { offset } from './middleware/offset';
|
|
21
19
|
export type { LimitShiftOptions, ShiftLimiter, ShiftOptions } from './middleware/shift';
|
|
22
|
-
export {
|
|
20
|
+
export { limitShift, shift } from './middleware/shift';
|
|
23
21
|
export type { SizeOptions } from './middleware/size';
|
|
22
|
+
export { size } from './middleware/size';
|
|
23
|
+
export { detectOverflow, getClippingAncestorRect } from './overflow';
|
|
24
24
|
export type { PositioningPreset, PresetOptions } from './presets';
|
|
25
|
-
export { getAlignment, getSide } from './utils';
|
|
26
25
|
export type { Alignment, ArrowData, ComputePositionOptions, ComputePositionResult, DetectOverflowOptions, FlipData, HideData, Middleware, MiddlewareData, MiddlewareReset, MiddlewareResult, MiddlewareState, Padding, Placement, Rect, ReferenceElement, ShiftData, Side, SideObject, SizeData, VirtualReference, } from './types';
|
|
26
|
+
export { getAlignment, getSide } from './utils';
|
|
27
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,EAAE,gBAAgB,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rB,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,SAAS,EACT,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getAlignment as e,getSide as t}from"./utils.js";import{autoUpdate as n}from"./auto-update.js";import{OrbitConfigError as r,OrbitError as i}from"./errors.js";import{computePosition as a
|
|
1
|
+
import{getAlignment as e,getSide as t}from"./utils.js";import{autoUpdate as n}from"./auto-update.js";import{OrbitConfigError as r,OrbitError as i}from"./errors.js";import{computePosition as a}from"./core.js";import{detectOverflow as o,getClippingAncestorRect as s}from"./overflow.js";import{createPositioner as c}from"./float.js";import{inline as l}from"./inline.js";import{arrow as u}from"./middleware/arrow.js";import{autoPlacement as d}from"./middleware/auto-placement.js";import{flip as f}from"./middleware/flip.js";import{hide as p}from"./middleware/hide.js";import{offset as m}from"./middleware/offset.js";import{limitShift as h,shift as g}from"./middleware/shift.js";import{size as _}from"./middleware/size.js";export{r as OrbitConfigError,i as OrbitError,u as arrow,d as autoPlacement,n as autoUpdate,a as computePosition,c as createPositioner,o as detectOverflow,f as flip,e as getAlignment,s as getClippingAncestorRect,t as getSide,p as hide,l as inline,h as limitShift,m as offset,g as shift,_ as size};
|
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 *
|
|
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 * positioner.start();\n * ```\n */\nexport function inline(options: InlineOptions = {}): Middleware {\n function inlineMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const rects = getClientRects(state.elements.reference);\n\n if (rects.length <= 1) return;\n\n const padding = toSideObject(options.padding ?? 2);\n const side = getSide(state.placement);\n let nextRect = rects[0]!;\n\n if (options.x != null && options.y != null) {\n nextRect = rects.find((rect) => rectContainsPoint(rect, options.x!, options.y!, padding)) ?? nextRect;\n } else if (side === 'top' || side === 'bottom') {\n const targetX = state.x + state.rects.floating.width / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.x + best.width / 2 - targetX);\n const rectDist = Math.abs(rect.x + rect.width / 2 - targetX);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n } else {\n const targetY = state.y + state.rects.floating.height / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.y + best.height / 2 - targetY);\n const rectDist = Math.abs(rect.y + rect.height / 2 - targetY);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n }\n\n if (sameRect(nextRect, state.rects.reference)) return;\n\n return { reset: { rects: { ...state.rects, reference: nextRect } } };\n }\n\n return inlineMiddleware;\n}\n"],"mappings":"kGAMA,SAAS,EAAe,EAAqC,CAG3D,MAFI,EAAE,mBAAoB,IAAc,OAAO,EAAU,gBAAmB,WAAmB,CAAC,EAEzF,MAAM,KAAM,EAAU,eAAi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M,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
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { Middleware, Padding } from './types';
|
|
2
2
|
export interface InlineOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Cursor x-coordinate. When provided alongside `y`, the middleware picks the
|
|
5
|
-
* client rect that contains the cursor instead of the closest rect to the floating element.
|
|
6
|
-
*/
|
|
7
|
-
x?: number;
|
|
8
|
-
/** Cursor y-coordinate. */
|
|
9
|
-
y?: number;
|
|
10
3
|
/**
|
|
11
4
|
* Padding used when hit-testing cursor coordinates against client rects.
|
|
12
5
|
* Prevents snapping when the cursor is just outside a rect edge. Default: `2`.
|
|
@@ -14,6 +7,13 @@ export interface InlineOptions {
|
|
|
14
7
|
* @remarks Only applies when both `x` and `y` are provided.
|
|
15
8
|
*/
|
|
16
9
|
padding?: Padding;
|
|
10
|
+
/**
|
|
11
|
+
* Cursor x-coordinate. When provided alongside `y`, the middleware picks the
|
|
12
|
+
* client rect that contains the cursor instead of the closest rect to the floating element.
|
|
13
|
+
*/
|
|
14
|
+
x?: number;
|
|
15
|
+
/** Cursor y-coordinate. */
|
|
16
|
+
y?: number;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Improves positioning accuracy for inline references that span multiple lines
|
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
|
|
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;;;;;;;;;;;;;;;;GAgBG;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 *
|
|
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 * positioner.start();\n * ```\n */\nexport function inline(options: InlineOptions = {}): Middleware {\n function inlineMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const rects = getClientRects(state.elements.reference);\n\n if (rects.length <= 1) return;\n\n const padding = toSideObject(options.padding ?? 2);\n const side = getSide(state.placement);\n let nextRect = rects[0]!;\n\n if (options.x != null && options.y != null) {\n nextRect = rects.find((rect) => rectContainsPoint(rect, options.x!, options.y!, padding)) ?? nextRect;\n } else if (side === 'top' || side === 'bottom') {\n const targetX = state.x + state.rects.floating.width / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.x + best.width / 2 - targetX);\n const rectDist = Math.abs(rect.x + rect.width / 2 - targetX);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n } else {\n const targetY = state.y + state.rects.floating.height / 2;\n\n nextRect = rects.reduce((best, rect) => {\n const bestDist = Math.abs(best.y + best.height / 2 - targetY);\n const rectDist = Math.abs(rect.y + rect.height / 2 - targetY);\n\n return rectDist < bestDist ? rect : best;\n }, nextRect);\n }\n\n if (sameRect(nextRect, state.rects.reference)) return;\n\n return { reset: { rects: { ...state.rects, reference: nextRect } } };\n }\n\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,M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js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n };\n}\n"],"mappings":"0DAqBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,SAAiC,EAA0D,CAChG,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAA,qBAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAA,cAAc,CAAQ,EACtC,EAAiB,EAAA,kBAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,CACF"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { Alignment, DetectOverflowOptions, Middleware, Placement } from '../types';
|
|
2
2
|
export interface AutoPlacementOptions extends DetectOverflowOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Placements to evaluate. When provided, takes precedence over `alignment`.
|
|
5
|
-
* Note: use either `flip` or `autoPlacement`, not both.
|
|
6
|
-
*/
|
|
7
|
-
allowedPlacements?: Placement[];
|
|
8
3
|
/**
|
|
9
4
|
* Constrains auto-placement to variants with the given alignment.
|
|
10
5
|
*
|
|
@@ -14,6 +9,11 @@ export interface AutoPlacementOptions extends DetectOverflowOptions {
|
|
|
14
9
|
* - omitted (default) — evaluates the 4 cardinal sides only.
|
|
15
10
|
*/
|
|
16
11
|
alignment?: Alignment | null;
|
|
12
|
+
/**
|
|
13
|
+
* Placements to evaluate. When provided, takes precedence over `alignment`.
|
|
14
|
+
* Note: use either `flip` or `autoPlacement`, not both.
|
|
15
|
+
*/
|
|
16
|
+
allowedPlacements?: Placement[];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Automatically selects the placement with the most available space and least overflow.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-placement.d.ts","sourceRoot":"","sources":["../../src/middleware/auto-placement.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-placement.d.ts","sourceRoot":"","sources":["../../src/middleware/auto-placement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAQ,MAAM,UAAU,CAAC;AAE9F,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC7B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC;CACjC;AAcD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,UAAU,CA6B5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-placement.js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"auto-placement.js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n };\n}\n"],"mappings":"wIAqBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,SAAiC,EAA0D,CAChG,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAc,CAAQ,EACtC,EAAiB,EAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flip.cjs","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"flip.cjs","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, Placement } from '../types';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"6DAgBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAA,eAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAA,YAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAA,aAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAA,cAAc,EAAA,SAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAA,cAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAA,qBAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAA,cAAc,CAAiB,EAE7C,GAAI,CAAC,EAAA,YAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/middleware/flip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/middleware/flip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG7E,MAAM,WAAW,WAAY,SAAQ,qBAAqB;IACxD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CAyC1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flip.js","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"flip.js","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, Placement } from '../types';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"uMAgBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAc,EAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAc,CAAiB,EAE7C,GAAI,CAAC,EAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hide.cjs","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"hide.cjs","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, HideData, Middleware } from '../types';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'` — whether the reference itself is off-screen.\n * - `'escaped'` — whether the floating element has fully exited the boundary.\n * - `'both'` (default) — both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): Middleware {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return hideMiddleware;\n}\n"],"mappings":"mCAkBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,IAAM,EAAW,EAAQ,UAAY,OAErC,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAiB,CAAC,EAExB,GAAI,IAAa,WAAa,IAAa,OAAQ,CACjD,IAAM,EAAe,EAAA,gBAAgB,CAAK,EACpC,EAAiB,EAAA,qBAAqB,EAAc,EAAU,CAAO,EAE3E,EAAK,QAAU,EAAA,eAAe,EAAc,CAAc,EAC1D,EAAK,eAAiB,CACxB,CAEA,GAAI,IAAa,mBAAqB,IAAa,OAAQ,CACzD,IAAM,EAAyB,EAAA,qBAAqB,EAAM,MAAM,UAAW,EAAU,CAAO,EAE5F,EAAK,gBAAkB,EAAA,eAAe,EAAM,MAAM,UAAW,CAAsB,EACnF,EAAK,uBAAyB,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAM,CAAK,CAAE,CAChC,CAEA,OAAO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hide.d.ts","sourceRoot":"","sources":["../../src/middleware/hide.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hide.d.ts","sourceRoot":"","sources":["../../src/middleware/hide.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAY,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5E,MAAM,WAAW,WAAY,SAAQ,qBAAqB;IACxD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,iBAAiB,GAAG,SAAS,GAAG,MAAM,CAAC;CACnD;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CA0B1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hide.js","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"hide.js","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, HideData, Middleware } from '../types';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'` — whether the reference itself is off-screen.\n * - `'escaped'` — whether the floating element has fully exited the boundary.\n * - `'both'` (default) — both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): Middleware {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return hideMiddleware;\n}\n"],"mappings":"oHAkBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,IAAM,EAAW,EAAQ,UAAY,OAErC,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAiB,CAAC,EAExB,GAAI,IAAa,WAAa,IAAa,OAAQ,CACjD,IAAM,EAAe,EAAgB,CAAK,EACpC,EAAiB,EAAqB,EAAc,EAAU,CAAO,EAE3E,EAAK,QAAU,EAAe,EAAc,CAAc,EAC1D,EAAK,eAAiB,CACxB,CAEA,GAAI,IAAa,mBAAqB,IAAa,OAAQ,CACzD,IAAM,EAAyB,EAAqB,EAAM,MAAM,UAAW,EAAU,CAAO,EAE5F,EAAK,gBAAkB,EAAe,EAAM,MAAM,UAAW,CAAsB,EACnF,EAAK,uBAAyB,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAM,CAAK,CAAE,CAChC,CAEA,OAAO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shift.cjs","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import
|
|
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 { clamp, 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":"6DAwCA,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,E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AAE,KAAM,CAAE,MAAO,CAAE,EAAG,EAAI,EAAG,CAAG,CAAE,EAAG,EAAG,EAAM,EAAI,EAAI,EAAG,EAAM,EAAI,CAAG,CAC/E,CAEA,OAAO,CACT"}
|
|
@@ -38,11 +38,6 @@ export interface LimitShiftOptions {
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function limitShift(options?: LimitShiftOptions): ShiftLimiter;
|
|
40
40
|
export interface ShiftOptions extends DetectOverflowOptions {
|
|
41
|
-
/**
|
|
42
|
-
* Whether to shift along the main axis (the axis away from the reference).
|
|
43
|
-
* Default: `false` — main-axis overflow is better handled by `flip`.
|
|
44
|
-
*/
|
|
45
|
-
mainAxis?: boolean;
|
|
46
41
|
/**
|
|
47
42
|
* Whether to shift along the cross axis (perpendicular to the reference direction).
|
|
48
43
|
* Default: `true`.
|
|
@@ -53,6 +48,11 @@ export interface ShiftOptions extends DetectOverflowOptions {
|
|
|
53
48
|
* Pass `limitShift()` to keep the float within the reference's extent.
|
|
54
49
|
*/
|
|
55
50
|
limiter?: ShiftLimiter;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to shift along the main axis (the axis away from the reference).
|
|
53
|
+
* Default: `false` — main-axis overflow is better handled by `flip`.
|
|
54
|
+
*/
|
|
55
|
+
mainAxis?: boolean;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Shifts the floating element along the cross axis to keep it inside the boundary.
|
|
@@ -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":"AACA,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shift.js","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import
|
|
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 { clamp, 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":"iGAwCA,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,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AG,CAC/E,CAEA,OAAO,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size.cjs","names":[],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import
|
|
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 * positioner.start();\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":"6DAyBA,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../src/middleware/size.ts"],"names":[],"mappings":"
|
|
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;;;;;;;;;;;;;;;;;;GAkBG;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
|
|
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 * positioner.start();\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":"uFAyBA,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"}
|
package/dist/orbit.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},t=class extends e{};function n(e,t,n){return Math.min(Math.max(e,t),n)}var r={bottom:`top`,left:`right`,right:`left`,top:`bottom`};function i(e){return e.split(`-`)[0]}function a(e){return e.split(`-`)[1]??null}function o(e,t){return t?`${e}-${t}`:e}function s({height:e,width:t,x:n,y:r}){return{height:e,width:t,x:n,y:r}}function c(e=0){return typeof e==`number`?{bottom:e,left:e,right:e,top:e}:{bottom:e.bottom??0,left:e.left??0,right:e.right??0,top:e.top??0}}function l(e){return typeof Element<`u`&&e instanceof Element}function u(e){return e.assignedSlot?e.assignedSlot:e.parentElement??(e.getRootNode()instanceof ShadowRoot?e.getRootNode().host:null)}function d(e,t,n,r){return e===`start`?t:e===`end`?t+n-r:t+(n-r)/2}function f(e,t,n){let r=i(e),o=a(e);switch(r){case`bottom`:return{x:d(o,t.x,t.width,n.width),y:t.y+t.height};case`left`:return{x:t.x-n.width,y:d(o,t.y,t.height,n.height)};case`right`:return{x:t.x+t.width,y:d(o,t.y,t.height,n.height)};case`top`:return{x:d(o,t.x,t.width,n.width),y:t.y-n.height}}}function p(e,t){return{floating:s(t.getBoundingClientRect()),reference:s(e.getBoundingClientRect())}}function m(e,t){return t?{...e,middlewareData:t.data?Object.assign(Object.create(null),e.middlewareData,t.data):e.middlewareData,placement:t.placement??e.placement,x:t.x??e.x,y:t.y??e.y}:e}var h=8;function g(e,t,n){return Promise.resolve().then(()=>v(e,t,n))}function _(e,t,n){return new Promise((r,i)=>{requestAnimationFrame(()=>{try{r(v(e,t,n))}catch(e){i(e)}})})}function v(e,n,{boundary:r,containingBlock:i,middleware:a=[],padding:o,placement:s=`bottom`}={}){let c=a,l=s,u={},d=p(e,n);for(let t=0;t<h;t+=1){let t={...f(l,d.reference,d.floating),boundary:r,elements:{floating:n,reference:e},initialPlacement:s,middlewareData:u,padding:o,placement:l,rects:d},a;for(let e of c){let n=e(t);if(t=m(t,n),u=t.middlewareData,a=n?.reset,a)break}if(!a){let e={middlewareData:t.middlewareData,placement:t.placement,x:t.x,y:t.y};if(i){let t=i.getBoundingClientRect();return{...e,x:e.x-t.x,y:e.y-t.y}}return e}a.remeasure?d=p(e,n):a.rects!=null&&(d=a.rects),l=a.placement??t.placement}throw new t(`Middleware triggered too many resets in a single compute cycle.`)}function y(){let e=window.visualViewport;return e?{height:e.height,width:e.width,x:e.offsetLeft,y:e.offsetTop}:{height:window.innerHeight,width:window.innerWidth,x:0,y:0}}function b(e){if(!e)return y();if(e instanceof Element){let t=e.getBoundingClientRect();return{height:t.height,width:t.width,x:t.x,y:t.y}}return e}var x=/(hidden|clip|scroll|auto|overlay)/;function S(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{height:Math.max(0,a-r),width:Math.max(0,i-n),x:n,y:r}}function C(e){let t=u(e),n=y();for(;t;){let e=getComputedStyle(t);if(x.test(`${e.overflow}${e.overflowX}${e.overflowY}`)){let e=t.getBoundingClientRect();n=S(n,{height:e.height,width:e.width,x:e.x,y:e.y})}t=u(t)}return n}function w(e,t){return{boundary:b(e.boundary??t.boundary),padding:c(e.padding??t.padding)}}function T(e){return{...e.rects.floating,x:e.x,y:e.y}}function E(e,t,n){return{bottom:e.y+e.height-(t.y+t.height-n.bottom),left:t.x+n.left-e.x,right:e.x+e.width-(t.x+t.width-n.right),top:t.y+n.top-e.y}}function D(e){return Math.max(e.top,0)+Math.max(e.right,0)+Math.max(e.bottom,0)+Math.max(e.left,0)}function O(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function k(e,t){return t.top>=e.height||t.right>=e.width||t.bottom>=e.height||t.left>=e.width}function A(e,t,n,r){let a=e.rects.reference;switch(i(t)){case`bottom`:return n.y+n.height-r.bottom-(a.y+a.height);case`left`:return a.x-(n.x+r.left);case`right`:return n.x+n.width-r.right-(a.x+a.width);case`top`:return a.y-(n.y+r.top)}}function j(e,t,n={}){let{x:r,y:i}=f(t,e.rects.reference,e.rects.floating),{boundary:a,padding:o}=w(n,e);return E({...e.rects.floating,x:r,y:i},a,o)}function M(e,t={}){let{boundary:n,padding:r}=w(t,e);return E(T(e),n,r)}function N(e,t){let n,r=0,i=(()=>{let i=Date.now(),a=t-(i-r);if(a<=0){n!==void 0&&clearTimeout(n),n=void 0,r=i,e();return}n===void 0&&(n=setTimeout(()=>{n=void 0,r=Date.now(),e()},a))});return i.cancel=()=>{n!==void 0&&clearTimeout(n),n=void 0},i}function P(e){let t=[],n=u(e);for(;n;){let e=getComputedStyle(n),r=e.overflow+e.overflowX+e.overflowY;/auto|scroll|overlay/.test(r)&&t.push(n),n=u(n)}return t}function F(e,t,n,{animationFrame:r=!1,observeAncestors:i=!0,observeFloating:a=!0,observeVisualViewport:o=!0,pauseWhenHidden:s=!0,throttle:c=0}={}){let u=c>0?N(n,c):null,d=u??n,f=!0,p=()=>{f&&d()};d();let m=[];if(s&&l(e)&&typeof IntersectionObserver<`u`){let t=new IntersectionObserver(e=>{f=e.at(-1)?.isIntersecting??!0,f&&d()});t.observe(e),m.push(()=>t.disconnect())}if(l(e)&&i){let t=P(e);for(let e of t)e.addEventListener(`scroll`,p,{passive:!0}),m.push(()=>e.removeEventListener(`scroll`,p));window.addEventListener(`scroll`,p,{passive:!0}),m.push(()=>window.removeEventListener(`scroll`,p))}else{let e=e=>{e.composedPath().includes(t)||p()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),m.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,p,{passive:!0}),m.push(()=>window.removeEventListener(`resize`,p));let h=o?window.visualViewport:null;h&&(h.addEventListener(`resize`,p,{passive:!0}),h.addEventListener(`scroll`,p,{passive:!0}),m.push(()=>{h.removeEventListener(`resize`,p),h.removeEventListener(`scroll`,p)}));let g=new ResizeObserver(p);l(e)&&g.observe(e),a&&g.observe(t),m.push(()=>g.disconnect());let _=0;if(r){let e=()=>{p(),_=window.requestAnimationFrame(e)};_=window.requestAnimationFrame(e),m.push(()=>window.cancelAnimationFrame(_))}return()=>{u?.cancel();for(let e of m)e()}}var I=[`transform`,`perspective`,`filter`],L=[`layout`,`paint`,`strict`,`content`];function R(e){return e.transform!==`none`||e.perspective!==`none`||e.filter!==`none`||e.backdropFilter&&e.backdropFilter!==`none`||e.willChange!==`auto`&&I.some(t=>e.willChange.includes(t))?!0:e.contain!==`none`&&L.some(t=>e.contain.includes(t))}function z(e){let t=u(e);for(;t;){if(R(getComputedStyle(t)))return t;t=u(t)}return null}function B(e,t,n,r){let i=new AbortController,a=!1;return{get disposalSignal(){return i.signal},dispose(){a||(a=!0,i.abort(),e())},get disposed(){return a},getPosition:t,start(){a||n()},[Symbol.dispose](){this.dispose()},update(){a||r()}}}function V(e,t){return t===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:z(e)}function H(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function U(e,t,{apply:n,autoUpdate:r={},boundary:i=`clippingAncestors`,middleware:a,padding:o,placement:s=`bottom`,strategy:c=`fixed`}={}){let l=!0,u,d=null,f=!1;function p(){if(!l)return;let r=V(t,c),u=v(e,t,{boundary:i===`clippingAncestors`?C(t):i,containingBlock:r,middleware:a,padding:o,placement:s});d=u,(n??(e=>H(e,t,c)))(u)}function m(){f||(f=!0,r===!1?p():u=F(e,t,p,r))}return B(()=>{l=!1,u?.()},()=>d,m,p)}function W({element:e,padding:t=0}){function r(r){let a=i(r.placement),o=c(t),l=s(e.getBoundingClientRect());if(a===`top`||a===`bottom`){let e=r.rects.reference.x+r.rects.reference.width/2-r.x-l.width/2,t=o.left,i=n(e,t,Math.max(t,r.rects.floating.width-l.width-o.right));return{data:{arrow:{centerOffset:e-i,constrained:i!==e,x:i}}}}let u=r.rects.reference.y+r.rects.reference.height/2-r.y-l.height/2,d=o.top,f=n(u,d,Math.max(d,r.rects.floating.height-l.height-o.bottom));return{data:{arrow:{centerOffset:u-f,constrained:f!==u,y:f}}}}return r}var G=[`top`,`right`,`bottom`,`left`];function K(e){return e===void 0?G:e===null?G.flatMap(e=>[e,`${e}-start`,`${e}-end`]):G.map(t=>`${t}-${e}`)}function q(e={}){return function(t){let{boundary:n,padding:r}=w(e,t),i=e.allowedPlacements??K(e.alignment);i.length;let a=t.placement,o=1/0,s=-1/0;for(let c of i){let i=D(j(t,c,e)),l=A(t,c,n,r);(i<o||i===o&&l>s)&&(a=c,o=i,s=l)}if(a!==t.placement)return{reset:{placement:a}}}}function J(e={}){function t(t){let n=M(t,e);if(!O(n))return;let s=i(t.placement),c=a(t.placement),l=e.fallbackPlacements??[o(r[s],c)],u=[t.placement],d=t.placement,f=D(n);for(let n of l){let r=j(t,n,e),i=D(r);if(!O(r))return{data:{flip:{skippedPlacements:u}},reset:{placement:n}};u.push(n),i<f&&(d=n,f=i)}if(d!==t.placement)return{data:{flip:{skippedPlacements:u}},reset:{placement:d}}}return t}function Y(e={}){let t=e.strategy??`both`;function n(n){let{boundary:r,padding:i}=w(e,n),a={};if(t===`escaped`||t===`both`){let e=T(n),t=E(e,r,i);a.escaped=k(e,t),a.escapedOffsets=t}if(t===`referenceHidden`||t===`both`){let e=E(n.rects.reference,r,i);a.referenceHidden=k(n.rects.reference,e),a.referenceHiddenOffsets=e}return{data:{hide:a}}}return n}function X(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(s).filter(e=>e.width>0||e.height>0)}function Z(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function Q(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function $(e={}){function t(t){let n=X(t.elements.reference);if(n.length<=1)return;let r=c(e.padding??2),a=i(t.placement),o=n[0];if(e.x!=null&&e.y!=null)o=n.find(t=>Z(t,e.x,e.y,r))??o;else if(a===`top`||a===`bottom`){let e=t.x+t.rects.floating.width/2;o=n.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},o)}else{let e=t.y+t.rects.floating.height/2;o=n.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},o)}if(!Q(o,t.rects.reference))return{reset:{rects:{...t.rects,reference:o}}}}return t}function ee(e,t){let n=typeof e==`function`?e(t):e;return typeof n==`number`?{crossAxis:0,mainAxis:n}:{crossAxis:n.crossAxis??0,mainAxis:n.mainAxis??0}}function te(e){return function(t){let n=i(t.placement),{crossAxis:r,mainAxis:a}=ee(e,t);switch(n){case`bottom`:return{x:t.x+r,y:t.y+a};case`left`:return{x:t.x-a,y:t.y+r};case`right`:return{x:t.x+a,y:t.y+r};case`top`:return{x:t.x+r,y:t.y-a}}}}function ne(e={}){return(t,r)=>{let{placement:a,rects:o,x:s,y:c}=t,l=i(a),u=l===`top`||l===`bottom`,d=typeof e.offset==`function`?e.offset(t):e.offset??0;if(u){let e=o.reference.x-d,t=o.reference.x+o.reference.width+d-o.floating.width,[i,a]=e<=t?[e,t]:[t,e],c=n(s+r.crossAxis,i,a);return{...r,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+r.crossAxis,m,h);return{...r,crossAxis:g-c}}}function re(e={}){let{crossAxis:t=!0,limiter:n,mainAxis:r=!1}=e;function a(a){let o=M(a,e),s=i(a.placement),c=s===`top`||s===`bottom`,l=Math.max(o.left,0)-Math.max(o.right,0),u=Math.max(o.top,0)-Math.max(o.bottom,0),d=c?t:r,f=c?r:t,p=d?l:0,m=f?u:0;if(n){let e=n(a,{crossAxis:c?p:m,mainAxis:c?m:p});p=c?e.crossAxis:e.mainAxis,m=c?e.mainAxis:e.crossAxis}return{data:{shift:{x:p,y:m}},x:a.x+p,y:a.y+m}}return a}function ie(e={}){function t(t){let{boundary:n,padding:r}=w(e,t),a=i(t.placement),o=n.y+r.top,s=n.x+n.width-r.right,c=n.y+n.height-r.bottom,l=n.x+r.left;return{data:{size:{availableHeight:a===`bottom`?Math.max(0,c-t.y):a===`top`?Math.max(0,t.rects.reference.y-o):Math.max(0,c-o),availableWidth:a===`right`?Math.max(0,s-t.x):a===`left`?Math.max(0,t.rects.reference.x-l):Math.max(0,s-l)}}}}return t}exports.OrbitConfigError=t,exports.OrbitError=e,exports.arrow=W,exports.autoPlacement=q,exports.autoUpdate=F,exports.computePosition=v,exports.computePositionAsync=g,exports.computePositionRaf=_,exports.createPositioner=U,exports.detectOverflow=M,exports.flip=J,exports.getAlignment=a,exports.getClippingAncestorRect=C,exports.getRects=p,exports.getSide=i,exports.hide=Y,exports.inline=$,exports.limitShift=ne,exports.offset=te,exports.shift=re,exports.size=ie;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,t,n){return Math.min(Math.max(e,t),n)}var t={bottom:`top`,left:`right`,right:`left`,top:`bottom`};function n(e){return e.split(`-`)[0]}function r(e){return e.split(`-`)[1]??null}function i(e,t){return t?`${e}-${t}`:e}function a({height:e,width:t,x:n,y:r}){return{height:e,width:t,x:n,y:r}}function o(e=0){return typeof e==`number`?{bottom:e,left:e,right:e,top:e}:{bottom:e.bottom??0,left:e.left??0,right:e.right??0,top:e.top??0}}function s(e){return typeof Element<`u`&&e instanceof Element}function c(e){return e.assignedSlot?e.assignedSlot:e.parentElement??(e.getRootNode()instanceof ShadowRoot?e.getRootNode().host:null)}function l(e,t,n,r){return e===`start`?t:e===`end`?t+n-r:t+(n-r)/2}function u(e,t,i){let a=n(e),o=r(e);switch(a){case`bottom`:return{x:l(o,t.x,t.width,i.width),y:t.y+t.height};case`left`:return{x:t.x-i.width,y:l(o,t.y,t.height,i.height)};case`right`:return{x:t.x+t.width,y:l(o,t.y,t.height,i.height)};case`top`:return{x:l(o,t.x,t.width,i.width),y:t.y-i.height}}}function d(e,t){let n,r=0,i=(()=>{let i=Date.now(),a=t-(i-r);if(a<=0){n!==void 0&&clearTimeout(n),n=void 0,r=i,e();return}n===void 0&&(n=setTimeout(()=>{n=void 0,r=Date.now(),e()},a))});return i.cancel=()=>{n!==void 0&&clearTimeout(n),n=void 0},i}function f(e){let t=[],n=c(e);for(;n;){let e=getComputedStyle(n),r=e.overflow+e.overflowX+e.overflowY;/auto|scroll|overlay/.test(r)&&t.push(n),n=c(n)}return t}function p(e,t,n,{animationFrame:r=!1,observeAncestors:i=!0,observeFloating:a=!0,observeVisualViewport:o=!0,pauseWhenHidden:c=!0,throttle:l=0}={}){let u=l>0?d(n,l):null,p=u??n,m=!0,h=()=>{m&&p()};p();let g=[];if(c&&s(e)&&typeof IntersectionObserver<`u`){let t=new IntersectionObserver(e=>{m=e.at(-1)?.isIntersecting??!0,m&&p()});t.observe(e),g.push(()=>t.disconnect())}if(s(e)&&i){let t=f(e);for(let e of t)e.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>e.removeEventListener(`scroll`,h));window.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>window.removeEventListener(`scroll`,h))}else{let e=e=>{e.composedPath().includes(t)||h()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),g.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,h,{passive:!0}),g.push(()=>window.removeEventListener(`resize`,h));let _=o?window.visualViewport:null;_&&(_.addEventListener(`resize`,h,{passive:!0}),_.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>{_.removeEventListener(`resize`,h),_.removeEventListener(`scroll`,h)}));let v=new ResizeObserver(h);s(e)&&v.observe(e),a&&v.observe(t),g.push(()=>v.disconnect());let y=0;if(r){let e=()=>{h(),y=window.requestAnimationFrame(e)};y=window.requestAnimationFrame(e),g.push(()=>window.cancelAnimationFrame(y))}return()=>{u?.cancel();for(let e of g)e()}}var m=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},h=class extends m{};function g(e,t){return{floating:a(t.getBoundingClientRect()),reference:a(e.getBoundingClientRect())}}function _(e,t){return t?{...e,middlewareData:t.data?Object.assign(Object.create(null),e.middlewareData,t.data):e.middlewareData,placement:t.placement??e.placement,x:t.x??e.x,y:t.y??e.y}:e}var v=8;function y(e,t,{boundary:n,containingBlock:r,middleware:i=[],padding:a,placement:o=`bottom`}={}){let s=i,c=o,l={},d=g(e,t);for(let i=0;i<v;i+=1){let i={...u(c,d.reference,d.floating),boundary:n,elements:{floating:t,reference:e},initialPlacement:o,middlewareData:l,padding:a,placement:c,rects:d},f;for(let e of s){let t=e(i);if(i=_(i,t),l=i.middlewareData,f=t?.reset,f)break}if(!f){let e={middlewareData:i.middlewareData,placement:i.placement,x:i.x,y:i.y};if(r){let t=r.getBoundingClientRect();return{...e,x:e.x-t.x,y:e.y-t.y}}return e}f.remeasure?d=g(e,t):f.rects!=null&&(d=f.rects),c=f.placement??i.placement}throw new h(`Middleware triggered too many resets in a single compute cycle.`)}var b=[`transform`,`perspective`,`filter`],x=[`layout`,`paint`,`strict`,`content`];function S(e){return e.transform!==`none`||e.perspective!==`none`||e.filter!==`none`||e.backdropFilter&&e.backdropFilter!==`none`||e.willChange!==`auto`&&b.some(t=>e.willChange.includes(t))?!0:e.contain!==`none`&&x.some(t=>e.contain.includes(t))}function C(e){let t=c(e);for(;t;){if(S(getComputedStyle(t)))return t;t=c(t)}return null}function w(){let e=window.visualViewport;return e?{height:e.height,width:e.width,x:e.offsetLeft,y:e.offsetTop}:{height:window.innerHeight,width:window.innerWidth,x:0,y:0}}function T(e){if(!e)return w();if(e instanceof Element){let t=e.getBoundingClientRect();return{height:t.height,width:t.width,x:t.x,y:t.y}}return e}var E=/(hidden|clip|scroll|auto|overlay)/;function D(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{height:Math.max(0,a-r),width:Math.max(0,i-n),x:n,y:r}}function O(e){let t=c(e),n=w();for(;t;){let e=getComputedStyle(t);if(E.test(`${e.overflow}${e.overflowX}${e.overflowY}`)){let e=t.getBoundingClientRect();n=D(n,{height:e.height,width:e.width,x:e.x,y:e.y})}t=c(t)}return n}function k(e,t){return{boundary:T(e.boundary??t.boundary),padding:o(e.padding??t.padding)}}function A(e){return{...e.rects.floating,x:e.x,y:e.y}}function j(e,t,n){return{bottom:e.y+e.height-(t.y+t.height-n.bottom),left:t.x+n.left-e.x,right:e.x+e.width-(t.x+t.width-n.right),top:t.y+n.top-e.y}}function M(e){return Math.max(e.top,0)+Math.max(e.right,0)+Math.max(e.bottom,0)+Math.max(e.left,0)}function N(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function P(e,t){return t.top>=e.height||t.right>=e.width||t.bottom>=e.height||t.left>=e.width}function F(e,t,r,i){let a=e.rects.reference;switch(n(t)){case`bottom`:return r.y+r.height-i.bottom-(a.y+a.height);case`left`:return a.x-(r.x+i.left);case`right`:return r.x+r.width-i.right-(a.x+a.width);case`top`:return a.y-(r.y+i.top)}}function I(e,t,n={}){let{x:r,y:i}=u(t,e.rects.reference,e.rects.floating),{boundary:a,padding:o}=k(n,e);return j({...e.rects.floating,x:r,y:i},a,o)}function L(e,t={}){let{boundary:n,padding:r}=k(t,e);return j(A(e),n,r)}function R(e,t){return t===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:C(e)}function z(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function B(e,t,{apply:n,autoUpdate:r={},boundary:i=`clippingAncestors`,middleware:a,padding:o,placement:s=`bottom`,strategy:c=`fixed`}={}){let l=new AbortController,u=!0,d=!1,f,m=null,h=!1;function g(){if(!u)return;let r=R(t,c),l=y(e,t,{boundary:i===`clippingAncestors`?O(t):i,containingBlock:r,middleware:a,padding:o,placement:s});m=l,(n??(e=>z(e,t,c)))(l)}function _(){h||d||(h=!0,r===!1?g():f=p(e,t,g,r))}return{get disposalSignal(){return l.signal},dispose(){d||(d=!0,u=!1,l.abort(),f?.())},get disposed(){return d},getPosition:()=>m,start:_,[Symbol.dispose](){this.dispose()},update(){d||g()}}}function V(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(a).filter(e=>e.width>0||e.height>0)}function H(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function U(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function W(e={}){function t(t){let r=V(t.elements.reference);if(r.length<=1)return;let i=o(e.padding??2),a=n(t.placement),s=r[0];if(e.x!=null&&e.y!=null)s=r.find(t=>H(t,e.x,e.y,i))??s;else if(a===`top`||a===`bottom`){let e=t.x+t.rects.floating.width/2;s=r.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},s)}else{let e=t.y+t.rects.floating.height/2;s=r.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},s)}if(!U(s,t.rects.reference))return{reset:{rects:{...t.rects,reference:s}}}}return t}function G({element:t,padding:r=0}){function i(i){let s=n(i.placement),c=o(r),l=a(t.getBoundingClientRect());if(s===`top`||s===`bottom`){let t=i.rects.reference.x+i.rects.reference.width/2-i.x-l.width/2,n=c.left,r=e(t,n,Math.max(n,i.rects.floating.width-l.width-c.right));return{data:{arrow:{centerOffset:t-r,constrained:r!==t,x:r}}}}let u=i.rects.reference.y+i.rects.reference.height/2-i.y-l.height/2,d=c.top,f=e(u,d,Math.max(d,i.rects.floating.height-l.height-c.bottom));return{data:{arrow:{centerOffset:u-f,constrained:f!==u,y:f}}}}return i}var K=[`top`,`right`,`bottom`,`left`];function q(e){return e===void 0?K:e===null?K.flatMap(e=>[e,`${e}-start`,`${e}-end`]):K.map(t=>`${t}-${e}`)}function J(e={}){return function(t){let{boundary:n,padding:r}=k(e,t),i=e.allowedPlacements??q(e.alignment);i.length;let a=t.placement,o=1/0,s=-1/0;for(let c of i){let i=M(I(t,c,e)),l=F(t,c,n,r);(i<o||i===o&&l>s)&&(a=c,o=i,s=l)}if(a!==t.placement)return{reset:{placement:a}}}}function Y(e={}){function a(a){let o=L(a,e);if(!N(o))return;let s=n(a.placement),c=r(a.placement),l=e.fallbackPlacements??[i(t[s],c)],u=[a.placement],d=a.placement,f=M(o);for(let t of l){let n=I(a,t,e),r=M(n);if(!N(n))return{data:{flip:{skippedPlacements:u}},reset:{placement:t}};u.push(t),r<f&&(d=t,f=r)}if(d!==a.placement)return{data:{flip:{skippedPlacements:u}},reset:{placement:d}}}return a}function X(e={}){let t=e.strategy??`both`;function n(n){let{boundary:r,padding:i}=k(e,n),a={};if(t===`escaped`||t===`both`){let e=A(n),t=j(e,r,i);a.escaped=P(e,t),a.escapedOffsets=t}if(t===`referenceHidden`||t===`both`){let e=j(n.rects.reference,r,i);a.referenceHidden=P(n.rects.reference,e),a.referenceHiddenOffsets=e}return{data:{hide:a}}}return n}function Z(e,t){let n=typeof e==`function`?e(t):e;return typeof n==`number`?{crossAxis:0,mainAxis:n}:{crossAxis:n.crossAxis??0,mainAxis:n.mainAxis??0}}function Q(e){return function(t){let r=n(t.placement),{crossAxis:i,mainAxis:a}=Z(e,t);switch(r){case`bottom`:return{x:t.x+i,y:t.y+a};case`left`:return{x:t.x-a,y:t.y+i};case`right`:return{x:t.x+a,y:t.y+i};case`top`:return{x:t.x+i,y:t.y-a}}}}function $(t={}){return(r,i)=>{let{placement:a,rects:o,x:s,y:c}=r,l=n(a),u=l===`top`||l===`bottom`,d=typeof t.offset==`function`?t.offset(r):t.offset??0;if(u){let t=o.reference.x-d,n=o.reference.x+o.reference.width+d-o.floating.width,[r,a]=t<=n?[t,n]:[n,t],c=e(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=e(c+i.crossAxis,m,h);return{...i,crossAxis:g-c}}}function ee(e={}){let{crossAxis:t=!0,limiter:r,mainAxis:i=!1}=e;function a(a){let o=L(a,e),s=n(a.placement),c=s===`top`||s===`bottom`,l=Math.max(o.left,0)-Math.max(o.right,0),u=Math.max(o.top,0)-Math.max(o.bottom,0),d=c?t:i,f=c?i:t,p=d?l:0,m=f?u:0;if(r){let e=r(a,{crossAxis:c?p:m,mainAxis:c?m:p});p=c?e.crossAxis:e.mainAxis,m=c?e.mainAxis:e.crossAxis}return{data:{shift:{x:p,y:m}},x:a.x+p,y:a.y+m}}return a}function te(e={}){function t(t){let{boundary:r,padding:i}=k(e,t),a=n(t.placement),o=r.y+i.top,s=r.x+r.width-i.right,c=r.y+r.height-i.bottom,l=r.x+i.left;return{data:{size:{availableHeight:a===`bottom`?Math.max(0,c-t.y):a===`top`?Math.max(0,t.rects.reference.y-o):Math.max(0,c-o),availableWidth:a===`right`?Math.max(0,s-t.x):a===`left`?Math.max(0,t.rects.reference.x-l):Math.max(0,s-l)}}}}return t}exports.OrbitConfigError=h,exports.OrbitError=m,exports.arrow=G,exports.autoPlacement=J,exports.autoUpdate=p,exports.computePosition=y,exports.createPositioner=B,exports.detectOverflow=L,exports.flip=Y,exports.getAlignment=r,exports.getClippingAncestorRect=O,exports.getSide=n,exports.hide=X,exports.inline=W,exports.limitShift=$,exports.offset=Q,exports.shift=ee,exports.size=te;
|
|
2
2
|
//# sourceMappingURL=orbit.cjs.map
|