@zag-js/popper 0.10.5 → 0.11.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/index.d.mts +106 -0
- package/dist/index.d.ts +106 -3
- package/dist/index.js +277 -7
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +253 -2
- package/dist/index.mjs.map +1 -0
- package/package.json +6 -6
- package/dist/auto-update.d.ts +0 -8
- package/dist/auto-update.js +0 -45
- package/dist/auto-update.mjs +0 -41
- package/dist/get-placement.d.ts +0 -10
- package/dist/get-placement.js +0 -126
- package/dist/get-placement.mjs +0 -121
- package/dist/get-styles.d.ts +0 -29
- package/dist/get-styles.js +0 -42
- package/dist/get-styles.mjs +0 -38
- package/dist/middleware.d.ts +0 -29
- package/dist/middleware.js +0 -58
- package/dist/middleware.mjs +0 -52
- package/dist/types.d.ts +0 -62
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,253 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/get-placement.ts
|
|
2
|
+
import { arrow, computePosition, flip, offset, shift, size } from "@floating-ui/dom";
|
|
3
|
+
import { raf } from "@zag-js/dom-query";
|
|
4
|
+
import { callAll as callAll2 } from "@zag-js/utils";
|
|
5
|
+
|
|
6
|
+
// src/auto-update.ts
|
|
7
|
+
import { getOverflowAncestors } from "@floating-ui/dom";
|
|
8
|
+
import { trackElementRect } from "@zag-js/element-rect";
|
|
9
|
+
var callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
10
|
+
var isHTMLElement = (el) => {
|
|
11
|
+
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
12
|
+
};
|
|
13
|
+
var addDomEvent = (el, type, fn, options) => {
|
|
14
|
+
el.addEventListener(type, fn, options);
|
|
15
|
+
return () => el.removeEventListener(type, fn, options);
|
|
16
|
+
};
|
|
17
|
+
function resolveOptions(option) {
|
|
18
|
+
const bool = typeof option === "boolean";
|
|
19
|
+
return {
|
|
20
|
+
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
21
|
+
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
22
|
+
referenceResize: bool ? option : option.referenceResize ?? true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function autoUpdate(reference, floating, update, options = false) {
|
|
26
|
+
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
27
|
+
const useAncestors = ancestorScroll || ancestorResize;
|
|
28
|
+
const ancestors = [];
|
|
29
|
+
if (useAncestors && isHTMLElement(reference)) {
|
|
30
|
+
ancestors.push(...getOverflowAncestors(reference));
|
|
31
|
+
}
|
|
32
|
+
function addResizeListeners() {
|
|
33
|
+
let cleanups = [trackElementRect(floating, { scope: "size", onChange: update })];
|
|
34
|
+
if (referenceResize && isHTMLElement(reference)) {
|
|
35
|
+
cleanups.push(trackElementRect(reference, { onChange: update }));
|
|
36
|
+
}
|
|
37
|
+
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
38
|
+
return () => cleanups.forEach((fn) => fn());
|
|
39
|
+
}
|
|
40
|
+
function addScrollListeners() {
|
|
41
|
+
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
42
|
+
}
|
|
43
|
+
return callAll(addResizeListeners(), addScrollListeners());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/middleware.ts
|
|
47
|
+
var toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
48
|
+
var cssVars = {
|
|
49
|
+
arrowSize: toVar("--arrow-size"),
|
|
50
|
+
arrowSizeHalf: toVar("--arrow-size-half"),
|
|
51
|
+
arrowBg: toVar("--arrow-background"),
|
|
52
|
+
transformOrigin: toVar("--transform-origin"),
|
|
53
|
+
arrowOffset: toVar("--arrow-offset")
|
|
54
|
+
};
|
|
55
|
+
var getTransformOrigin = (arrow2) => ({
|
|
56
|
+
top: "bottom center",
|
|
57
|
+
"top-start": arrow2 ? `${arrow2.x}px bottom` : "left bottom",
|
|
58
|
+
"top-end": arrow2 ? `${arrow2.x}px bottom` : "right bottom",
|
|
59
|
+
bottom: "top center",
|
|
60
|
+
"bottom-start": arrow2 ? `${arrow2.x}px top` : "top left",
|
|
61
|
+
"bottom-end": arrow2 ? `${arrow2.x}px top` : "top right",
|
|
62
|
+
left: "right center",
|
|
63
|
+
"left-start": arrow2 ? `right ${arrow2.y}px` : "right top",
|
|
64
|
+
"left-end": arrow2 ? `right ${arrow2.y}px` : "right bottom",
|
|
65
|
+
right: "left center",
|
|
66
|
+
"right-start": arrow2 ? `left ${arrow2.y}px` : "left top",
|
|
67
|
+
"right-end": arrow2 ? `left ${arrow2.y}px` : "left bottom"
|
|
68
|
+
});
|
|
69
|
+
var transformOrigin = {
|
|
70
|
+
name: "transformOrigin",
|
|
71
|
+
fn({ placement, elements, middlewareData }) {
|
|
72
|
+
const { arrow: arrow2 } = middlewareData;
|
|
73
|
+
const transformOrigin2 = getTransformOrigin(arrow2)[placement];
|
|
74
|
+
const { floating } = elements;
|
|
75
|
+
floating.style.setProperty(cssVars.transformOrigin.variable, transformOrigin2);
|
|
76
|
+
return {
|
|
77
|
+
data: { transformOrigin: transformOrigin2 }
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var shiftArrow = (opts) => ({
|
|
82
|
+
name: "shiftArrow",
|
|
83
|
+
fn({ placement, middlewareData }) {
|
|
84
|
+
const { element: arrow2 } = opts;
|
|
85
|
+
if (middlewareData.arrow) {
|
|
86
|
+
const { x, y } = middlewareData.arrow;
|
|
87
|
+
const dir = placement.split("-")[0];
|
|
88
|
+
Object.assign(arrow2.style, {
|
|
89
|
+
left: x != null ? `${x}px` : "",
|
|
90
|
+
top: y != null ? `${y}px` : "",
|
|
91
|
+
[dir]: `calc(100% + ${cssVars.arrowOffset.reference})`
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// src/get-placement.ts
|
|
99
|
+
var defaultOptions = {
|
|
100
|
+
strategy: "absolute",
|
|
101
|
+
placement: "bottom",
|
|
102
|
+
listeners: true,
|
|
103
|
+
gutter: 8,
|
|
104
|
+
flip: true,
|
|
105
|
+
sameWidth: false,
|
|
106
|
+
overflowPadding: 8
|
|
107
|
+
};
|
|
108
|
+
function getPlacementImpl(reference, floating, opts = {}) {
|
|
109
|
+
if (!floating || !reference)
|
|
110
|
+
return;
|
|
111
|
+
const options = Object.assign({}, defaultOptions, opts);
|
|
112
|
+
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
113
|
+
const middleware = [];
|
|
114
|
+
const boundary = typeof options.boundary === "function" ? options.boundary() : options.boundary;
|
|
115
|
+
if (options.flip) {
|
|
116
|
+
middleware.push(
|
|
117
|
+
flip({
|
|
118
|
+
boundary,
|
|
119
|
+
padding: options.overflowPadding
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (options.gutter || options.offset) {
|
|
124
|
+
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
125
|
+
const data = options.offset ? options.offset : { mainAxis: options.gutter };
|
|
126
|
+
if (data?.mainAxis != null)
|
|
127
|
+
data.mainAxis += arrowOffset;
|
|
128
|
+
middleware.push(offset(data));
|
|
129
|
+
}
|
|
130
|
+
middleware.push(
|
|
131
|
+
shift({
|
|
132
|
+
boundary,
|
|
133
|
+
crossAxis: options.overlap,
|
|
134
|
+
padding: options.overflowPadding
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
if (arrowEl) {
|
|
138
|
+
middleware.push(
|
|
139
|
+
arrow({ element: arrowEl, padding: 8 }),
|
|
140
|
+
shiftArrow({ element: arrowEl })
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
middleware.push(transformOrigin);
|
|
144
|
+
middleware.push(
|
|
145
|
+
size({
|
|
146
|
+
padding: options.overflowPadding,
|
|
147
|
+
apply({ rects, availableHeight, availableWidth }) {
|
|
148
|
+
const referenceWidth = Math.round(rects.reference.width);
|
|
149
|
+
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
150
|
+
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
151
|
+
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
152
|
+
if (options.sameWidth) {
|
|
153
|
+
Object.assign(floating.style, {
|
|
154
|
+
width: `${referenceWidth}px`,
|
|
155
|
+
minWidth: "unset"
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (options.fitViewport) {
|
|
159
|
+
Object.assign(floating.style, {
|
|
160
|
+
maxWidth: `${availableWidth}px`,
|
|
161
|
+
maxHeight: `${availableHeight}px`
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
function compute(config = {}) {
|
|
168
|
+
if (!reference || !floating)
|
|
169
|
+
return;
|
|
170
|
+
const { placement, strategy, onComplete } = options;
|
|
171
|
+
computePosition(reference, floating, {
|
|
172
|
+
placement,
|
|
173
|
+
middleware,
|
|
174
|
+
strategy,
|
|
175
|
+
...config
|
|
176
|
+
}).then((data) => {
|
|
177
|
+
const x = Math.round(data.x);
|
|
178
|
+
const y = Math.round(data.y);
|
|
179
|
+
Object.assign(floating.style, {
|
|
180
|
+
position: data.strategy,
|
|
181
|
+
top: "0px",
|
|
182
|
+
left: "0px",
|
|
183
|
+
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
184
|
+
});
|
|
185
|
+
onComplete?.(data);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
compute();
|
|
189
|
+
return callAll2(
|
|
190
|
+
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
191
|
+
options.onCleanup
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
function getBasePlacement(placement) {
|
|
195
|
+
return placement.split("-")[0];
|
|
196
|
+
}
|
|
197
|
+
function getPlacement(referenceOrFn, floatingOrFn, opts = {}) {
|
|
198
|
+
const { defer, ...restOptions } = opts;
|
|
199
|
+
const func = defer ? raf : (v) => v();
|
|
200
|
+
const cleanups = [];
|
|
201
|
+
cleanups.push(
|
|
202
|
+
func(() => {
|
|
203
|
+
const reference = typeof referenceOrFn === "function" ? referenceOrFn() : referenceOrFn;
|
|
204
|
+
const floating = typeof floatingOrFn === "function" ? floatingOrFn() : floatingOrFn;
|
|
205
|
+
cleanups.push(getPlacementImpl(reference, floating, restOptions));
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
return () => {
|
|
209
|
+
cleanups.forEach((fn) => fn?.());
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/get-styles.ts
|
|
214
|
+
var ARROW_FLOATING_STYLE = {
|
|
215
|
+
bottom: "rotate(45deg)",
|
|
216
|
+
left: "rotate(135deg)",
|
|
217
|
+
top: "rotate(225deg)",
|
|
218
|
+
right: "rotate(315deg)"
|
|
219
|
+
};
|
|
220
|
+
function getPlacementStyles(options) {
|
|
221
|
+
const { placement = "bottom" } = options;
|
|
222
|
+
return {
|
|
223
|
+
arrow: {
|
|
224
|
+
position: "absolute",
|
|
225
|
+
width: cssVars.arrowSize.reference,
|
|
226
|
+
height: cssVars.arrowSize.reference,
|
|
227
|
+
[cssVars.arrowSizeHalf.variable]: `calc(${cssVars.arrowSize.reference} / 2)`,
|
|
228
|
+
[cssVars.arrowOffset.variable]: `calc(${cssVars.arrowSizeHalf.reference} * -1)`
|
|
229
|
+
},
|
|
230
|
+
arrowTip: {
|
|
231
|
+
transform: ARROW_FLOATING_STYLE[placement.split("-")[0]],
|
|
232
|
+
background: cssVars.arrowBg.reference,
|
|
233
|
+
top: "0",
|
|
234
|
+
left: "0",
|
|
235
|
+
width: "100%",
|
|
236
|
+
height: "100%",
|
|
237
|
+
position: "absolute",
|
|
238
|
+
zIndex: "inherit"
|
|
239
|
+
},
|
|
240
|
+
floating: {
|
|
241
|
+
position: "absolute",
|
|
242
|
+
minWidth: "max-content",
|
|
243
|
+
top: "0px",
|
|
244
|
+
left: "0px"
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
export {
|
|
249
|
+
getBasePlacement,
|
|
250
|
+
getPlacement,
|
|
251
|
+
getPlacementStyles
|
|
252
|
+
};
|
|
253
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/get-placement.ts","../src/auto-update.ts","../src/middleware.ts","../src/get-styles.ts"],"sourcesContent":["import type { Middleware, Placement, VirtualElement } from \"@floating-ui/dom\"\nimport { ComputePositionConfig, arrow, computePosition, flip, offset, shift, size } from \"@floating-ui/dom\"\nimport { raf } from \"@zag-js/dom-query\"\nimport { callAll } from \"@zag-js/utils\"\nimport { autoUpdate } from \"./auto-update\"\nimport { shiftArrow, transformOrigin } from \"./middleware\"\nimport type { BasePlacement, PositioningOptions } from \"./types\"\n\nconst defaultOptions: PositioningOptions = {\n strategy: \"absolute\",\n placement: \"bottom\",\n listeners: true,\n gutter: 8,\n flip: true,\n sameWidth: false,\n overflowPadding: 8,\n}\n\ntype MaybeRectElement = HTMLElement | VirtualElement | null\ntype MaybeElement = HTMLElement | null\ntype MaybeFn<T> = T | (() => T)\n\nfunction getPlacementImpl(reference: MaybeRectElement, floating: MaybeElement, opts: PositioningOptions = {}) {\n if (!floating || !reference) return\n\n const options = Object.assign({}, defaultOptions, opts)\n\n /* -----------------------------------------------------------------------------\n * The middleware stack\n * -----------------------------------------------------------------------------*/\n\n const arrowEl = floating.querySelector<HTMLElement>(\"[data-part=arrow]\")\n const middleware: Middleware[] = []\n\n const boundary = typeof options.boundary === \"function\" ? options.boundary() : options.boundary\n\n if (options.flip) {\n middleware.push(\n flip({\n boundary,\n padding: options.overflowPadding,\n }),\n )\n }\n\n if (options.gutter || options.offset) {\n const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0\n const data = options.offset ? options.offset : { mainAxis: options.gutter }\n if (data?.mainAxis != null) data.mainAxis += arrowOffset\n middleware.push(offset(data))\n }\n\n middleware.push(\n shift({\n boundary,\n crossAxis: options.overlap,\n padding: options.overflowPadding,\n }),\n )\n\n if (arrowEl) {\n // prettier-ignore\n middleware.push(\n arrow({ element: arrowEl, padding: 8 }),\n shiftArrow({ element: arrowEl }),\n )\n }\n\n middleware.push(transformOrigin)\n\n middleware.push(\n size({\n padding: options.overflowPadding,\n apply({ rects, availableHeight, availableWidth }) {\n const referenceWidth = Math.round(rects.reference.width)\n\n floating.style.setProperty(\"--reference-width\", `${referenceWidth}px`)\n floating.style.setProperty(\"--available-width\", `${availableWidth}px`)\n floating.style.setProperty(\"--available-height\", `${availableHeight}px`)\n\n if (options.sameWidth) {\n Object.assign(floating.style, {\n width: `${referenceWidth}px`,\n minWidth: \"unset\",\n })\n }\n\n if (options.fitViewport) {\n Object.assign(floating.style, {\n maxWidth: `${availableWidth}px`,\n maxHeight: `${availableHeight}px`,\n })\n }\n },\n }),\n )\n\n /* -----------------------------------------------------------------------------\n * The actual positioning function\n * -----------------------------------------------------------------------------*/\n\n function compute(config: Omit<ComputePositionConfig, \"platform\"> = {}) {\n if (!reference || !floating) return\n const { placement, strategy, onComplete } = options\n\n computePosition(reference, floating, {\n placement,\n middleware,\n strategy,\n ...config,\n }).then((data) => {\n const x = Math.round(data.x)\n const y = Math.round(data.y)\n\n Object.assign(floating.style, {\n position: data.strategy,\n top: \"0px\",\n left: \"0px\",\n transform: `translate3d(${x}px, ${y}px, 0)`,\n })\n\n onComplete?.(data)\n })\n }\n\n compute()\n\n return callAll(\n options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : undefined,\n options.onCleanup,\n )\n}\n\nexport function getBasePlacement(placement: Placement): BasePlacement {\n return placement.split(\"-\")[0] as BasePlacement\n}\n\nexport function getPlacement(\n referenceOrFn: MaybeFn<MaybeRectElement>,\n floatingOrFn: MaybeFn<MaybeElement>,\n opts: PositioningOptions & { defer?: boolean } = {},\n) {\n const { defer, ...restOptions } = opts\n const func = defer ? raf : (v: any) => v()\n const cleanups: (VoidFunction | undefined)[] = []\n cleanups.push(\n func(() => {\n const reference = typeof referenceOrFn === \"function\" ? referenceOrFn() : referenceOrFn\n const floating = typeof floatingOrFn === \"function\" ? floatingOrFn() : floatingOrFn\n cleanups.push(getPlacementImpl(reference, floating, restOptions))\n }),\n )\n return () => {\n cleanups.forEach((fn) => fn?.())\n }\n}\n","import type { Placement, ReferenceElement } from \"@floating-ui/dom\"\nimport { getOverflowAncestors } from \"@floating-ui/dom\"\nimport { trackElementRect } from \"@zag-js/element-rect\"\n\nexport type { Placement }\n\nexport type AutoUpdateOptions = {\n ancestorScroll?: boolean\n ancestorResize?: boolean\n referenceResize?: boolean\n}\n\ntype Ancestors = ReturnType<typeof getOverflowAncestors>\n\nconst callAll =\n (...fns: VoidFunction[]) =>\n () =>\n fns.forEach((fn) => fn())\n\nconst isHTMLElement = (el: any): el is HTMLElement => {\n return typeof el === \"object\" && el !== null && el.nodeType === 1\n}\n\nconst addDomEvent = (el: HTMLElement, type: string, fn: VoidFunction, options?: boolean | AddEventListenerOptions) => {\n el.addEventListener(type, fn, options)\n return () => el.removeEventListener(type, fn, options)\n}\n\nfunction resolveOptions(option: boolean | AutoUpdateOptions) {\n const bool = typeof option === \"boolean\"\n return {\n ancestorResize: bool ? option : option.ancestorResize ?? true,\n ancestorScroll: bool ? option : option.ancestorScroll ?? true,\n referenceResize: bool ? option : option.referenceResize ?? true,\n }\n}\n\nexport function autoUpdate(\n reference: ReferenceElement,\n floating: HTMLElement,\n update: () => void,\n options: boolean | AutoUpdateOptions = false,\n) {\n const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options)\n\n const useAncestors = ancestorScroll || ancestorResize\n const ancestors: Ancestors = []\n\n if (useAncestors && isHTMLElement(reference)) {\n ancestors.push(...getOverflowAncestors(reference))\n }\n\n function addResizeListeners() {\n let cleanups: VoidFunction[] = [trackElementRect(floating, { scope: \"size\", onChange: update })]\n if (referenceResize && isHTMLElement(reference)) {\n cleanups.push(trackElementRect(reference, { onChange: update }))\n }\n cleanups.push(callAll(...ancestors.map((el: any) => addDomEvent(el, \"resize\", update))))\n return () => cleanups.forEach((fn) => fn())\n }\n\n function addScrollListeners() {\n return callAll(...ancestors.map((el: any) => addDomEvent(el, \"scroll\", update, { passive: true })))\n }\n\n return callAll(addResizeListeners(), addScrollListeners())\n}\n","import type { Coords, Middleware } from \"@floating-ui/dom\"\n\n/* -----------------------------------------------------------------------------\n * Shared middleware utils\n * -----------------------------------------------------------------------------*/\n\nconst toVar = (value: string) => ({ variable: value, reference: `var(${value})` })\n\nexport const cssVars = {\n arrowSize: toVar(\"--arrow-size\"),\n arrowSizeHalf: toVar(\"--arrow-size-half\"),\n arrowBg: toVar(\"--arrow-background\"),\n transformOrigin: toVar(\"--transform-origin\"),\n arrowOffset: toVar(\"--arrow-offset\"),\n}\n\n/* -----------------------------------------------------------------------------\n * Transform Origin Middleware\n * -----------------------------------------------------------------------------*/\n\nconst getTransformOrigin = (arrow?: Partial<Coords>) => ({\n top: \"bottom center\",\n \"top-start\": arrow ? `${arrow.x}px bottom` : \"left bottom\",\n \"top-end\": arrow ? `${arrow.x}px bottom` : \"right bottom\",\n bottom: \"top center\",\n \"bottom-start\": arrow ? `${arrow.x}px top` : \"top left\",\n \"bottom-end\": arrow ? `${arrow.x}px top` : \"top right\",\n left: \"right center\",\n \"left-start\": arrow ? `right ${arrow.y}px` : \"right top\",\n \"left-end\": arrow ? `right ${arrow.y}px` : \"right bottom\",\n right: \"left center\",\n \"right-start\": arrow ? `left ${arrow.y}px` : \"left top\",\n \"right-end\": arrow ? `left ${arrow.y}px` : \"left bottom\",\n})\n\nexport const transformOrigin: Middleware = {\n name: \"transformOrigin\",\n fn({ placement, elements, middlewareData }) {\n const { arrow } = middlewareData\n const transformOrigin = getTransformOrigin(arrow)[placement]\n\n const { floating } = elements\n floating.style.setProperty(cssVars.transformOrigin.variable, transformOrigin)\n\n return {\n data: { transformOrigin },\n }\n },\n}\n\n/* -----------------------------------------------------------------------------\n * Arrow Middleware\n * -----------------------------------------------------------------------------*/\n\ntype ArrowOptions = { element: HTMLElement }\n\ntype BasePlacement = \"top\" | \"bottom\" | \"left\" | \"right\"\n\nexport const shiftArrow = (opts: ArrowOptions): Middleware => ({\n name: \"shiftArrow\",\n fn({ placement, middlewareData }) {\n const { element: arrow } = opts\n\n if (middlewareData.arrow) {\n const { x, y } = middlewareData.arrow\n\n const dir = placement.split(\"-\")[0] as BasePlacement\n\n Object.assign(arrow.style, {\n left: x != null ? `${x}px` : \"\",\n top: y != null ? `${y}px` : \"\",\n [dir]: `calc(100% + ${cssVars.arrowOffset.reference})`,\n })\n }\n\n return {}\n },\n})\n","import type { Placement } from \"@floating-ui/dom\"\nimport { cssVars } from \"./middleware\"\n\ntype Options = {\n placement?: Placement\n}\n\nconst ARROW_FLOATING_STYLE = {\n bottom: \"rotate(45deg)\",\n left: \"rotate(135deg)\",\n top: \"rotate(225deg)\",\n right: \"rotate(315deg)\",\n} as const\n\nexport function getPlacementStyles(options: Options) {\n const { placement = \"bottom\" } = options\n\n return {\n arrow: {\n position: \"absolute\",\n width: cssVars.arrowSize.reference,\n height: cssVars.arrowSize.reference,\n [cssVars.arrowSizeHalf.variable]: `calc(${cssVars.arrowSize.reference} / 2)`,\n [cssVars.arrowOffset.variable]: `calc(${cssVars.arrowSizeHalf.reference} * -1)`,\n } as const,\n\n arrowTip: {\n transform: ARROW_FLOATING_STYLE[placement.split(\"-\")[0]],\n background: cssVars.arrowBg.reference,\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n position: \"absolute\",\n zIndex: \"inherit\",\n } as const,\n\n floating: {\n position: \"absolute\",\n minWidth: \"max-content\",\n top: \"0px\",\n left: \"0px\",\n } as const,\n }\n}\n"],"mappings":";AACA,SAAgC,OAAO,iBAAiB,MAAM,QAAQ,OAAO,YAAY;AACzF,SAAS,WAAW;AACpB,SAAS,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A,MAC1B,CAAC,QAAQ,cAAc,QAAQ,GAAG,QAAQ,QAAQ,UAAU;AAAA,MAC5D,CAAC,QAAQ,YAAY,QAAQ,GAAG,QAAQ,QAAQ,cAAc;AAAA,IAChE;AAAA,IAEA,UAAU;AAAA,MACR,WAAW,qBAAqB,UAAU,MAAM,GAAG,EAAE,CAAC,CAAC;AAAA,MACvD,YAAY,QAAQ,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,QAAQ;AAAA,IACV;AAAA,IAEA,UAAU;AAAA,MACR,UAAU;AAAA,MACV,UAAU;AAAA,MACV,KAAK;AAAA,MACL,MAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["callAll","arrow","transformOrigin","callAll"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Dynamic positioning logic for ui machines",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@floating-ui/dom": "1.4.
|
|
27
|
-
"@zag-js/dom-query": "0.
|
|
28
|
-
"@zag-js/element-rect": "0.
|
|
29
|
-
"@zag-js/utils": "0.
|
|
26
|
+
"@floating-ui/dom": "1.4.4",
|
|
27
|
+
"@zag-js/dom-query": "0.11.0",
|
|
28
|
+
"@zag-js/element-rect": "0.11.0",
|
|
29
|
+
"@zag-js/utils": "0.11.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"clean-package": "2.2.0"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"./package.json": "./package.json"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "
|
|
47
|
+
"build": "tsup",
|
|
48
48
|
"lint": "eslint src --ext .ts,.tsx",
|
|
49
49
|
"typecheck": "tsc --noEmit"
|
|
50
50
|
}
|
package/dist/auto-update.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Placement, ReferenceElement } from "@floating-ui/dom";
|
|
2
|
-
export type { Placement };
|
|
3
|
-
export type AutoUpdateOptions = {
|
|
4
|
-
ancestorScroll?: boolean;
|
|
5
|
-
ancestorResize?: boolean;
|
|
6
|
-
referenceResize?: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare function autoUpdate(reference: ReferenceElement, floating: HTMLElement, update: () => void, options?: boolean | AutoUpdateOptions): () => void;
|
package/dist/auto-update.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const dom = require('@floating-ui/dom');
|
|
6
|
-
const elementRect = require('@zag-js/element-rect');
|
|
7
|
-
|
|
8
|
-
const callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
9
|
-
const isHTMLElement = (el) => {
|
|
10
|
-
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
11
|
-
};
|
|
12
|
-
const addDomEvent = (el, type, fn, options) => {
|
|
13
|
-
el.addEventListener(type, fn, options);
|
|
14
|
-
return () => el.removeEventListener(type, fn, options);
|
|
15
|
-
};
|
|
16
|
-
function resolveOptions(option) {
|
|
17
|
-
const bool = typeof option === "boolean";
|
|
18
|
-
return {
|
|
19
|
-
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
20
|
-
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
21
|
-
referenceResize: bool ? option : option.referenceResize ?? true
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function autoUpdate(reference, floating, update, options = false) {
|
|
25
|
-
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
26
|
-
const useAncestors = ancestorScroll || ancestorResize;
|
|
27
|
-
const ancestors = [];
|
|
28
|
-
if (useAncestors && isHTMLElement(reference)) {
|
|
29
|
-
ancestors.push(...dom.getOverflowAncestors(reference));
|
|
30
|
-
}
|
|
31
|
-
function addResizeListeners() {
|
|
32
|
-
let cleanups = [elementRect.trackElementRect(floating, { scope: "size", onChange: update })];
|
|
33
|
-
if (referenceResize && isHTMLElement(reference)) {
|
|
34
|
-
cleanups.push(elementRect.trackElementRect(reference, { onChange: update }));
|
|
35
|
-
}
|
|
36
|
-
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
37
|
-
return () => cleanups.forEach((fn) => fn());
|
|
38
|
-
}
|
|
39
|
-
function addScrollListeners() {
|
|
40
|
-
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
41
|
-
}
|
|
42
|
-
return callAll(addResizeListeners(), addScrollListeners());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
exports.autoUpdate = autoUpdate;
|
package/dist/auto-update.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getOverflowAncestors } from '@floating-ui/dom';
|
|
2
|
-
import { trackElementRect } from '@zag-js/element-rect';
|
|
3
|
-
|
|
4
|
-
const callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
5
|
-
const isHTMLElement = (el) => {
|
|
6
|
-
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
7
|
-
};
|
|
8
|
-
const addDomEvent = (el, type, fn, options) => {
|
|
9
|
-
el.addEventListener(type, fn, options);
|
|
10
|
-
return () => el.removeEventListener(type, fn, options);
|
|
11
|
-
};
|
|
12
|
-
function resolveOptions(option) {
|
|
13
|
-
const bool = typeof option === "boolean";
|
|
14
|
-
return {
|
|
15
|
-
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
16
|
-
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
17
|
-
referenceResize: bool ? option : option.referenceResize ?? true
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function autoUpdate(reference, floating, update, options = false) {
|
|
21
|
-
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
22
|
-
const useAncestors = ancestorScroll || ancestorResize;
|
|
23
|
-
const ancestors = [];
|
|
24
|
-
if (useAncestors && isHTMLElement(reference)) {
|
|
25
|
-
ancestors.push(...getOverflowAncestors(reference));
|
|
26
|
-
}
|
|
27
|
-
function addResizeListeners() {
|
|
28
|
-
let cleanups = [trackElementRect(floating, { scope: "size", onChange: update })];
|
|
29
|
-
if (referenceResize && isHTMLElement(reference)) {
|
|
30
|
-
cleanups.push(trackElementRect(reference, { onChange: update }));
|
|
31
|
-
}
|
|
32
|
-
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
33
|
-
return () => cleanups.forEach((fn) => fn());
|
|
34
|
-
}
|
|
35
|
-
function addScrollListeners() {
|
|
36
|
-
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
37
|
-
}
|
|
38
|
-
return callAll(addResizeListeners(), addScrollListeners());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { autoUpdate };
|
package/dist/get-placement.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Placement, VirtualElement } from "@floating-ui/dom";
|
|
2
|
-
import type { BasePlacement, PositioningOptions } from "./types";
|
|
3
|
-
type MaybeRectElement = HTMLElement | VirtualElement | null;
|
|
4
|
-
type MaybeElement = HTMLElement | null;
|
|
5
|
-
type MaybeFn<T> = T | (() => T);
|
|
6
|
-
export declare function getBasePlacement(placement: Placement): BasePlacement;
|
|
7
|
-
export declare function getPlacement(referenceOrFn: MaybeFn<MaybeRectElement>, floatingOrFn: MaybeFn<MaybeElement>, opts?: PositioningOptions & {
|
|
8
|
-
defer?: boolean;
|
|
9
|
-
}): () => void;
|
|
10
|
-
export {};
|
package/dist/get-placement.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const dom = require('@floating-ui/dom');
|
|
6
|
-
const domQuery = require('@zag-js/dom-query');
|
|
7
|
-
const utils = require('@zag-js/utils');
|
|
8
|
-
const autoUpdate = require('./auto-update.js');
|
|
9
|
-
const middleware = require('./middleware.js');
|
|
10
|
-
|
|
11
|
-
const defaultOptions = {
|
|
12
|
-
strategy: "absolute",
|
|
13
|
-
placement: "bottom",
|
|
14
|
-
listeners: true,
|
|
15
|
-
gutter: 8,
|
|
16
|
-
flip: true,
|
|
17
|
-
sameWidth: false,
|
|
18
|
-
overflowPadding: 8
|
|
19
|
-
};
|
|
20
|
-
function getPlacementImpl(reference, floating, opts = {}) {
|
|
21
|
-
if (!floating || !reference)
|
|
22
|
-
return;
|
|
23
|
-
const options = Object.assign({}, defaultOptions, opts);
|
|
24
|
-
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
25
|
-
const middleware$1 = [];
|
|
26
|
-
const boundary = typeof options.boundary === "function" ? options.boundary() : options.boundary;
|
|
27
|
-
if (options.flip) {
|
|
28
|
-
middleware$1.push(
|
|
29
|
-
dom.flip({
|
|
30
|
-
boundary,
|
|
31
|
-
padding: options.overflowPadding
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
if (options.gutter || options.offset) {
|
|
36
|
-
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
37
|
-
const data = options.offset ? options.offset : { mainAxis: options.gutter };
|
|
38
|
-
if (data?.mainAxis != null)
|
|
39
|
-
data.mainAxis += arrowOffset;
|
|
40
|
-
middleware$1.push(dom.offset(data));
|
|
41
|
-
}
|
|
42
|
-
middleware$1.push(
|
|
43
|
-
dom.shift({
|
|
44
|
-
boundary,
|
|
45
|
-
crossAxis: options.overlap,
|
|
46
|
-
padding: options.overflowPadding
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
if (arrowEl) {
|
|
50
|
-
middleware$1.push(
|
|
51
|
-
dom.arrow({ element: arrowEl, padding: 8 }),
|
|
52
|
-
middleware.shiftArrow({ element: arrowEl })
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
middleware$1.push(middleware.transformOrigin);
|
|
56
|
-
middleware$1.push(
|
|
57
|
-
dom.size({
|
|
58
|
-
padding: options.overflowPadding,
|
|
59
|
-
apply({ rects, availableHeight, availableWidth }) {
|
|
60
|
-
const referenceWidth = Math.round(rects.reference.width);
|
|
61
|
-
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
62
|
-
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
63
|
-
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
64
|
-
if (options.sameWidth) {
|
|
65
|
-
Object.assign(floating.style, {
|
|
66
|
-
width: `${referenceWidth}px`,
|
|
67
|
-
minWidth: "unset"
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (options.fitViewport) {
|
|
71
|
-
Object.assign(floating.style, {
|
|
72
|
-
maxWidth: `${availableWidth}px`,
|
|
73
|
-
maxHeight: `${availableHeight}px`
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
);
|
|
79
|
-
function compute(config = {}) {
|
|
80
|
-
if (!reference || !floating)
|
|
81
|
-
return;
|
|
82
|
-
const { placement, strategy, onComplete } = options;
|
|
83
|
-
dom.computePosition(reference, floating, {
|
|
84
|
-
placement,
|
|
85
|
-
middleware: middleware$1,
|
|
86
|
-
strategy,
|
|
87
|
-
...config
|
|
88
|
-
}).then((data) => {
|
|
89
|
-
const x = Math.round(data.x);
|
|
90
|
-
const y = Math.round(data.y);
|
|
91
|
-
Object.assign(floating.style, {
|
|
92
|
-
position: data.strategy,
|
|
93
|
-
top: "0px",
|
|
94
|
-
left: "0px",
|
|
95
|
-
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
96
|
-
});
|
|
97
|
-
onComplete?.(data);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
compute();
|
|
101
|
-
return utils.callAll(
|
|
102
|
-
options.listeners ? autoUpdate.autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
103
|
-
options.onCleanup
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
function getBasePlacement(placement) {
|
|
107
|
-
return placement.split("-")[0];
|
|
108
|
-
}
|
|
109
|
-
function getPlacement(referenceOrFn, floatingOrFn, opts = {}) {
|
|
110
|
-
const { defer, ...restOptions } = opts;
|
|
111
|
-
const func = defer ? domQuery.raf : (v) => v();
|
|
112
|
-
const cleanups = [];
|
|
113
|
-
cleanups.push(
|
|
114
|
-
func(() => {
|
|
115
|
-
const reference = typeof referenceOrFn === "function" ? referenceOrFn() : referenceOrFn;
|
|
116
|
-
const floating = typeof floatingOrFn === "function" ? floatingOrFn() : floatingOrFn;
|
|
117
|
-
cleanups.push(getPlacementImpl(reference, floating, restOptions));
|
|
118
|
-
})
|
|
119
|
-
);
|
|
120
|
-
return () => {
|
|
121
|
-
cleanups.forEach((fn) => fn?.());
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
exports.getBasePlacement = getBasePlacement;
|
|
126
|
-
exports.getPlacement = getPlacement;
|
package/dist/get-placement.mjs
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { flip, offset, shift, arrow, size, computePosition } from '@floating-ui/dom';
|
|
2
|
-
import { raf } from '@zag-js/dom-query';
|
|
3
|
-
import { callAll } from '@zag-js/utils';
|
|
4
|
-
import { autoUpdate } from './auto-update.mjs';
|
|
5
|
-
import { shiftArrow, transformOrigin } from './middleware.mjs';
|
|
6
|
-
|
|
7
|
-
const defaultOptions = {
|
|
8
|
-
strategy: "absolute",
|
|
9
|
-
placement: "bottom",
|
|
10
|
-
listeners: true,
|
|
11
|
-
gutter: 8,
|
|
12
|
-
flip: true,
|
|
13
|
-
sameWidth: false,
|
|
14
|
-
overflowPadding: 8
|
|
15
|
-
};
|
|
16
|
-
function getPlacementImpl(reference, floating, opts = {}) {
|
|
17
|
-
if (!floating || !reference)
|
|
18
|
-
return;
|
|
19
|
-
const options = Object.assign({}, defaultOptions, opts);
|
|
20
|
-
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
21
|
-
const middleware = [];
|
|
22
|
-
const boundary = typeof options.boundary === "function" ? options.boundary() : options.boundary;
|
|
23
|
-
if (options.flip) {
|
|
24
|
-
middleware.push(
|
|
25
|
-
flip({
|
|
26
|
-
boundary,
|
|
27
|
-
padding: options.overflowPadding
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
if (options.gutter || options.offset) {
|
|
32
|
-
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
33
|
-
const data = options.offset ? options.offset : { mainAxis: options.gutter };
|
|
34
|
-
if (data?.mainAxis != null)
|
|
35
|
-
data.mainAxis += arrowOffset;
|
|
36
|
-
middleware.push(offset(data));
|
|
37
|
-
}
|
|
38
|
-
middleware.push(
|
|
39
|
-
shift({
|
|
40
|
-
boundary,
|
|
41
|
-
crossAxis: options.overlap,
|
|
42
|
-
padding: options.overflowPadding
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
if (arrowEl) {
|
|
46
|
-
middleware.push(
|
|
47
|
-
arrow({ element: arrowEl, padding: 8 }),
|
|
48
|
-
shiftArrow({ element: arrowEl })
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
middleware.push(transformOrigin);
|
|
52
|
-
middleware.push(
|
|
53
|
-
size({
|
|
54
|
-
padding: options.overflowPadding,
|
|
55
|
-
apply({ rects, availableHeight, availableWidth }) {
|
|
56
|
-
const referenceWidth = Math.round(rects.reference.width);
|
|
57
|
-
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
58
|
-
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
59
|
-
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
60
|
-
if (options.sameWidth) {
|
|
61
|
-
Object.assign(floating.style, {
|
|
62
|
-
width: `${referenceWidth}px`,
|
|
63
|
-
minWidth: "unset"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
if (options.fitViewport) {
|
|
67
|
-
Object.assign(floating.style, {
|
|
68
|
-
maxWidth: `${availableWidth}px`,
|
|
69
|
-
maxHeight: `${availableHeight}px`
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
-
function compute(config = {}) {
|
|
76
|
-
if (!reference || !floating)
|
|
77
|
-
return;
|
|
78
|
-
const { placement, strategy, onComplete } = options;
|
|
79
|
-
computePosition(reference, floating, {
|
|
80
|
-
placement,
|
|
81
|
-
middleware,
|
|
82
|
-
strategy,
|
|
83
|
-
...config
|
|
84
|
-
}).then((data) => {
|
|
85
|
-
const x = Math.round(data.x);
|
|
86
|
-
const y = Math.round(data.y);
|
|
87
|
-
Object.assign(floating.style, {
|
|
88
|
-
position: data.strategy,
|
|
89
|
-
top: "0px",
|
|
90
|
-
left: "0px",
|
|
91
|
-
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
92
|
-
});
|
|
93
|
-
onComplete?.(data);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
compute();
|
|
97
|
-
return callAll(
|
|
98
|
-
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
99
|
-
options.onCleanup
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
function getBasePlacement(placement) {
|
|
103
|
-
return placement.split("-")[0];
|
|
104
|
-
}
|
|
105
|
-
function getPlacement(referenceOrFn, floatingOrFn, opts = {}) {
|
|
106
|
-
const { defer, ...restOptions } = opts;
|
|
107
|
-
const func = defer ? raf : (v) => v();
|
|
108
|
-
const cleanups = [];
|
|
109
|
-
cleanups.push(
|
|
110
|
-
func(() => {
|
|
111
|
-
const reference = typeof referenceOrFn === "function" ? referenceOrFn() : referenceOrFn;
|
|
112
|
-
const floating = typeof floatingOrFn === "function" ? floatingOrFn() : floatingOrFn;
|
|
113
|
-
cleanups.push(getPlacementImpl(reference, floating, restOptions));
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
return () => {
|
|
117
|
-
cleanups.forEach((fn) => fn?.());
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export { getBasePlacement, getPlacement };
|