@zag-js/popper 0.2.1 → 0.2.3
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.d.ts +11 -0
- package/dist/auto-update.js +144 -0
- package/dist/auto-update.mjs +6 -0
- package/dist/chunk-A2YMJLJJ.mjs +121 -0
- package/dist/chunk-I46LTIWB.mjs +51 -0
- package/dist/chunk-L7FW633C.mjs +114 -0
- package/dist/chunk-X5LLREVI.mjs +57 -0
- package/dist/get-placement.d.ts +8 -0
- package/dist/get-placement.js +301 -0
- package/dist/get-placement.mjs +10 -0
- package/dist/get-styles.d.ts +37 -0
- package/dist/get-styles.js +83 -0
- package/dist/get-styles.mjs +7 -0
- package/dist/index.d.ts +4 -108
- package/dist/index.js +22 -18
- package/dist/index.mjs +9 -311
- package/dist/middleware.d.ts +31 -0
- package/dist/middleware.js +83 -0
- package/dist/middleware.mjs +10 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +19 -9
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/get-placement.ts
|
|
21
|
+
var get_placement_exports = {};
|
|
22
|
+
__export(get_placement_exports, {
|
|
23
|
+
getBasePlacement: () => getBasePlacement,
|
|
24
|
+
getPlacement: () => getPlacement
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(get_placement_exports);
|
|
27
|
+
var import_dom2 = require("@floating-ui/dom");
|
|
28
|
+
|
|
29
|
+
// ../core/src/functions.ts
|
|
30
|
+
var runIfFn = (v, ...a) => {
|
|
31
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
32
|
+
return res ?? void 0;
|
|
33
|
+
};
|
|
34
|
+
var callAll = (...fns) => (...a) => {
|
|
35
|
+
fns.forEach(function(fn) {
|
|
36
|
+
fn?.(...a);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// ../core/src/guard.ts
|
|
41
|
+
var isBoolean = (v) => v === true || v === false;
|
|
42
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
43
|
+
|
|
44
|
+
// src/auto-update.ts
|
|
45
|
+
var import_dom = require("@floating-ui/dom");
|
|
46
|
+
|
|
47
|
+
// ../dom/src/query.ts
|
|
48
|
+
function isHTMLElement(v) {
|
|
49
|
+
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../dom/src/listener.ts
|
|
53
|
+
var isRef = (v) => hasProp(v, "current");
|
|
54
|
+
function addDomEvent(target, eventName, handler, options) {
|
|
55
|
+
const node = isRef(target) ? target.current : runIfFn(target);
|
|
56
|
+
node?.addEventListener(eventName, handler, options);
|
|
57
|
+
return () => {
|
|
58
|
+
node?.removeEventListener(eventName, handler, options);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ../dom/src/rect-observer.ts
|
|
63
|
+
function getObservedElements() {
|
|
64
|
+
;
|
|
65
|
+
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
66
|
+
return globalThis.__rectObserverMap__;
|
|
67
|
+
}
|
|
68
|
+
function observeElementRect(el, fn) {
|
|
69
|
+
const observedElements = getObservedElements();
|
|
70
|
+
const data = observedElements.get(el);
|
|
71
|
+
if (!data) {
|
|
72
|
+
observedElements.set(el, { rect: {}, callbacks: [fn] });
|
|
73
|
+
if (observedElements.size === 1) {
|
|
74
|
+
rafId = requestAnimationFrame(runLoop);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
data.callbacks.push(fn);
|
|
78
|
+
fn(el.getBoundingClientRect());
|
|
79
|
+
}
|
|
80
|
+
return function unobserve() {
|
|
81
|
+
const data2 = observedElements.get(el);
|
|
82
|
+
if (!data2)
|
|
83
|
+
return;
|
|
84
|
+
const index = data2.callbacks.indexOf(fn);
|
|
85
|
+
if (index > -1) {
|
|
86
|
+
data2.callbacks.splice(index, 1);
|
|
87
|
+
}
|
|
88
|
+
if (data2.callbacks.length === 0) {
|
|
89
|
+
observedElements.delete(el);
|
|
90
|
+
if (observedElements.size === 0) {
|
|
91
|
+
cancelAnimationFrame(rafId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
var rafId;
|
|
97
|
+
function runLoop() {
|
|
98
|
+
const observedElements = getObservedElements();
|
|
99
|
+
const changedRectsData = [];
|
|
100
|
+
observedElements.forEach((data, element) => {
|
|
101
|
+
const newRect = element.getBoundingClientRect();
|
|
102
|
+
if (!isEqual(data.rect, newRect)) {
|
|
103
|
+
data.rect = newRect;
|
|
104
|
+
changedRectsData.push(data);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
changedRectsData.forEach((data) => {
|
|
108
|
+
data.callbacks.forEach((callback) => callback(data.rect));
|
|
109
|
+
});
|
|
110
|
+
rafId = requestAnimationFrame(runLoop);
|
|
111
|
+
}
|
|
112
|
+
function isEqual(rect1, rect2) {
|
|
113
|
+
return rect1.width === rect2.width && rect1.height === rect2.height && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom && rect1.left === rect2.left;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/auto-update.ts
|
|
117
|
+
function resolveOptions(option) {
|
|
118
|
+
const bool = isBoolean(option);
|
|
119
|
+
return {
|
|
120
|
+
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
121
|
+
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
122
|
+
referenceResize: bool ? option : option.referenceResize ?? true
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function autoUpdate(reference, floating, update, options = false) {
|
|
126
|
+
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
127
|
+
const useAncestors = ancestorScroll || ancestorResize;
|
|
128
|
+
const ancestors = [];
|
|
129
|
+
if (useAncestors && isHTMLElement(reference)) {
|
|
130
|
+
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
131
|
+
}
|
|
132
|
+
function addResizeListeners() {
|
|
133
|
+
let cleanups = [observeElementRect(floating, update)];
|
|
134
|
+
if (referenceResize && isHTMLElement(reference)) {
|
|
135
|
+
cleanups.push(observeElementRect(reference, update));
|
|
136
|
+
}
|
|
137
|
+
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
138
|
+
return () => cleanups.forEach((fn) => fn());
|
|
139
|
+
}
|
|
140
|
+
function addScrollListeners() {
|
|
141
|
+
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
142
|
+
}
|
|
143
|
+
return callAll(addResizeListeners(), addScrollListeners());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/middleware.ts
|
|
147
|
+
var toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
148
|
+
var cssVars = {
|
|
149
|
+
arrowSize: toVar("--arrow-size"),
|
|
150
|
+
arrowSizeHalf: toVar("--arrow-size-half"),
|
|
151
|
+
arrowBg: toVar("--arrow-background"),
|
|
152
|
+
transformOrigin: toVar("--transform-origin"),
|
|
153
|
+
arrowOffset: toVar("--arrow-offset")
|
|
154
|
+
};
|
|
155
|
+
var getTransformOrigin = (arrow2) => ({
|
|
156
|
+
top: "bottom center",
|
|
157
|
+
"top-start": arrow2 ? `${arrow2.x}px bottom` : "left bottom",
|
|
158
|
+
"top-end": arrow2 ? `${arrow2.x}px bottom` : "right bottom",
|
|
159
|
+
bottom: "top center",
|
|
160
|
+
"bottom-start": arrow2 ? `${arrow2.x}px top` : "top left",
|
|
161
|
+
"bottom-end": arrow2 ? `${arrow2.x}px top` : "top right",
|
|
162
|
+
left: "right center",
|
|
163
|
+
"left-start": arrow2 ? `right ${arrow2.y}px` : "right top",
|
|
164
|
+
"left-end": arrow2 ? `right ${arrow2.y}px` : "right bottom",
|
|
165
|
+
right: "left center",
|
|
166
|
+
"right-start": arrow2 ? `left ${arrow2.y}px` : "left top",
|
|
167
|
+
"right-end": arrow2 ? `left ${arrow2.y}px` : "left bottom"
|
|
168
|
+
});
|
|
169
|
+
var transformOrigin = {
|
|
170
|
+
name: "transformOrigin",
|
|
171
|
+
fn({ placement, elements, middlewareData }) {
|
|
172
|
+
const { arrow: arrow2 } = middlewareData;
|
|
173
|
+
const transformOrigin2 = getTransformOrigin(arrow2)[placement];
|
|
174
|
+
const { floating } = elements;
|
|
175
|
+
floating.style.setProperty(cssVars.transformOrigin.variable, transformOrigin2);
|
|
176
|
+
return {
|
|
177
|
+
data: { transformOrigin: transformOrigin2 }
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var shiftArrow = (opts) => ({
|
|
182
|
+
name: "shiftArrow",
|
|
183
|
+
fn({ placement, middlewareData }) {
|
|
184
|
+
const { element: arrow2 } = opts;
|
|
185
|
+
if (middlewareData.arrow) {
|
|
186
|
+
const { x, y } = middlewareData.arrow;
|
|
187
|
+
const dir = placement.split("-")[0];
|
|
188
|
+
Object.assign(arrow2.style, {
|
|
189
|
+
left: x != null ? `${x}px` : "",
|
|
190
|
+
top: y != null ? `${y}px` : "",
|
|
191
|
+
[dir]: `calc(100% + ${cssVars.arrowOffset.reference})`
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// src/get-placement.ts
|
|
199
|
+
var defaultOptions = {
|
|
200
|
+
strategy: "absolute",
|
|
201
|
+
placement: "bottom",
|
|
202
|
+
listeners: true,
|
|
203
|
+
gutter: 8,
|
|
204
|
+
flip: true,
|
|
205
|
+
sameWidth: false,
|
|
206
|
+
overflowPadding: 8
|
|
207
|
+
};
|
|
208
|
+
function getPlacement(reference, floating, opts = {}) {
|
|
209
|
+
if (!floating || !reference)
|
|
210
|
+
return;
|
|
211
|
+
const options = Object.assign({}, defaultOptions, opts);
|
|
212
|
+
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
213
|
+
const middleware = [];
|
|
214
|
+
const boundary = typeof options.boundary === "function" ? options.boundary() : options.boundary;
|
|
215
|
+
if (options.flip) {
|
|
216
|
+
middleware.push(
|
|
217
|
+
(0, import_dom2.flip)({
|
|
218
|
+
boundary,
|
|
219
|
+
padding: options.overflowPadding
|
|
220
|
+
})
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (options.gutter || options.offset) {
|
|
224
|
+
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
225
|
+
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
226
|
+
if (data?.mainAxis != null)
|
|
227
|
+
data.mainAxis += arrowOffset;
|
|
228
|
+
middleware.push((0, import_dom2.offset)(data));
|
|
229
|
+
}
|
|
230
|
+
middleware.push(
|
|
231
|
+
(0, import_dom2.shift)({
|
|
232
|
+
boundary,
|
|
233
|
+
crossAxis: options.overlap,
|
|
234
|
+
padding: options.overflowPadding
|
|
235
|
+
})
|
|
236
|
+
);
|
|
237
|
+
if (arrowEl) {
|
|
238
|
+
middleware.push(
|
|
239
|
+
(0, import_dom2.arrow)({ element: arrowEl, padding: 8 }),
|
|
240
|
+
shiftArrow({ element: arrowEl })
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
middleware.push(transformOrigin);
|
|
244
|
+
middleware.push(
|
|
245
|
+
(0, import_dom2.size)({
|
|
246
|
+
padding: options.overflowPadding,
|
|
247
|
+
apply({ rects, availableHeight, availableWidth }) {
|
|
248
|
+
const referenceWidth = Math.round(rects.reference.width);
|
|
249
|
+
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
250
|
+
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
251
|
+
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
252
|
+
if (options.sameWidth) {
|
|
253
|
+
Object.assign(floating.style, {
|
|
254
|
+
width: `${referenceWidth}px`,
|
|
255
|
+
minWidth: "unset"
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (options.fitViewport) {
|
|
259
|
+
Object.assign(floating.style, {
|
|
260
|
+
maxWidth: `${availableWidth}px`,
|
|
261
|
+
maxHeight: `${availableHeight}px`
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
function compute(config = {}) {
|
|
268
|
+
if (!reference || !floating)
|
|
269
|
+
return;
|
|
270
|
+
const { placement, strategy } = options;
|
|
271
|
+
(0, import_dom2.computePosition)(reference, floating, {
|
|
272
|
+
placement,
|
|
273
|
+
middleware,
|
|
274
|
+
strategy,
|
|
275
|
+
...config
|
|
276
|
+
}).then((data) => {
|
|
277
|
+
const x = Math.round(data.x);
|
|
278
|
+
const y = Math.round(data.y);
|
|
279
|
+
Object.assign(floating.style, {
|
|
280
|
+
position: data.strategy,
|
|
281
|
+
top: "0",
|
|
282
|
+
left: "0",
|
|
283
|
+
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
284
|
+
});
|
|
285
|
+
options.onComplete?.({ ...data, compute });
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
compute();
|
|
289
|
+
return callAll(
|
|
290
|
+
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
291
|
+
options.onCleanup
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
function getBasePlacement(placement) {
|
|
295
|
+
return placement.split("-")[0];
|
|
296
|
+
}
|
|
297
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
298
|
+
0 && (module.exports = {
|
|
299
|
+
getBasePlacement,
|
|
300
|
+
getPlacement
|
|
301
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Placement } from '@floating-ui/dom';
|
|
2
|
+
|
|
3
|
+
type Options = {
|
|
4
|
+
measured: boolean;
|
|
5
|
+
strategy?: "absolute" | "fixed";
|
|
6
|
+
placement?: Placement;
|
|
7
|
+
};
|
|
8
|
+
declare function getPlacementStyles(options: Options): {
|
|
9
|
+
arrow: {
|
|
10
|
+
readonly [x: string]: string | 0 | undefined;
|
|
11
|
+
readonly position: "absolute";
|
|
12
|
+
readonly width: string;
|
|
13
|
+
readonly height: string;
|
|
14
|
+
readonly opacity: 0 | undefined;
|
|
15
|
+
};
|
|
16
|
+
arrowTip: {
|
|
17
|
+
readonly transform: any;
|
|
18
|
+
readonly background: string;
|
|
19
|
+
readonly top: "0";
|
|
20
|
+
readonly left: "0";
|
|
21
|
+
readonly width: "100%";
|
|
22
|
+
readonly height: "100%";
|
|
23
|
+
readonly position: "absolute";
|
|
24
|
+
readonly zIndex: "inherit";
|
|
25
|
+
};
|
|
26
|
+
floating: {
|
|
27
|
+
position: "fixed" | "absolute";
|
|
28
|
+
readonly top?: 0 | undefined;
|
|
29
|
+
readonly left?: 0 | undefined;
|
|
30
|
+
readonly opacity?: 0 | undefined;
|
|
31
|
+
readonly transform?: "translate3d(0, -200%, 0)" | undefined;
|
|
32
|
+
readonly pointerEvents?: "none" | undefined;
|
|
33
|
+
readonly minWidth: "max-content";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { getPlacementStyles };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/get-styles.ts
|
|
21
|
+
var get_styles_exports = {};
|
|
22
|
+
__export(get_styles_exports, {
|
|
23
|
+
getPlacementStyles: () => getPlacementStyles
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(get_styles_exports);
|
|
26
|
+
|
|
27
|
+
// src/middleware.ts
|
|
28
|
+
var toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
29
|
+
var cssVars = {
|
|
30
|
+
arrowSize: toVar("--arrow-size"),
|
|
31
|
+
arrowSizeHalf: toVar("--arrow-size-half"),
|
|
32
|
+
arrowBg: toVar("--arrow-background"),
|
|
33
|
+
transformOrigin: toVar("--transform-origin"),
|
|
34
|
+
arrowOffset: toVar("--arrow-offset")
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/get-styles.ts
|
|
38
|
+
var UNMEASURED_FLOATING_STYLE = {
|
|
39
|
+
position: "fixed",
|
|
40
|
+
top: 0,
|
|
41
|
+
left: 0,
|
|
42
|
+
opacity: 0,
|
|
43
|
+
transform: "translate3d(0, -200%, 0)",
|
|
44
|
+
pointerEvents: "none"
|
|
45
|
+
};
|
|
46
|
+
var ARROW_FLOATING_STYLE = {
|
|
47
|
+
bottom: "rotate(45deg)",
|
|
48
|
+
left: "rotate(135deg)",
|
|
49
|
+
top: "rotate(225deg)",
|
|
50
|
+
right: "rotate(315deg)"
|
|
51
|
+
};
|
|
52
|
+
function getPlacementStyles(options) {
|
|
53
|
+
const { measured, strategy = "absolute", placement = "bottom" } = options;
|
|
54
|
+
return {
|
|
55
|
+
arrow: {
|
|
56
|
+
position: "absolute",
|
|
57
|
+
width: cssVars.arrowSize.reference,
|
|
58
|
+
height: cssVars.arrowSize.reference,
|
|
59
|
+
[cssVars.arrowSizeHalf.variable]: `calc(${cssVars.arrowSize.reference} / 2)`,
|
|
60
|
+
[cssVars.arrowOffset.variable]: `calc(${cssVars.arrowSizeHalf.reference} * -1)`,
|
|
61
|
+
opacity: !measured ? 0 : void 0
|
|
62
|
+
},
|
|
63
|
+
arrowTip: {
|
|
64
|
+
transform: ARROW_FLOATING_STYLE[placement.split("-")[0]],
|
|
65
|
+
background: cssVars.arrowBg.reference,
|
|
66
|
+
top: "0",
|
|
67
|
+
left: "0",
|
|
68
|
+
width: "100%",
|
|
69
|
+
height: "100%",
|
|
70
|
+
position: "absolute",
|
|
71
|
+
zIndex: "inherit"
|
|
72
|
+
},
|
|
73
|
+
floating: {
|
|
74
|
+
position: strategy,
|
|
75
|
+
minWidth: "max-content",
|
|
76
|
+
...!measured && UNMEASURED_FLOATING_STYLE
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
getPlacementStyles
|
|
83
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,109 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { getBasePlacement, getPlacement } from './get-placement.js';
|
|
2
|
+
export { getPlacementStyles } from './get-styles.js';
|
|
3
|
+
export { PositioningOptions } from './types.js';
|
|
2
4
|
export { Placement } from '@floating-ui/dom';
|
|
3
|
-
|
|
4
|
-
type AutoUpdateOptions = {
|
|
5
|
-
ancestorScroll?: boolean;
|
|
6
|
-
ancestorResize?: boolean;
|
|
7
|
-
referenceResize?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type PositioningOptions = {
|
|
11
|
-
/**
|
|
12
|
-
* The strategy to use for positioning
|
|
13
|
-
*/
|
|
14
|
-
strategy?: "absolute" | "fixed";
|
|
15
|
-
/**
|
|
16
|
-
* The initial placement of the floating element
|
|
17
|
-
*/
|
|
18
|
-
placement?: Placement;
|
|
19
|
-
/**
|
|
20
|
-
* The offset of the floating element
|
|
21
|
-
*/
|
|
22
|
-
offset?: {
|
|
23
|
-
mainAxis?: number;
|
|
24
|
-
crossAxis?: number;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* The main axis offset or gap between the reference and floating elements
|
|
28
|
-
*/
|
|
29
|
-
gutter?: number;
|
|
30
|
-
/**
|
|
31
|
-
* The virtual padding around the viewport edges to check for overflow
|
|
32
|
-
*/
|
|
33
|
-
overflowPadding?: number;
|
|
34
|
-
/**
|
|
35
|
-
* Whether to flip the placement
|
|
36
|
-
*/
|
|
37
|
-
flip?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Whether the floating element can overlap the reference element
|
|
40
|
-
* @default false
|
|
41
|
-
*/
|
|
42
|
-
overlap?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Whether to make the floating element same width as the reference element
|
|
45
|
-
*/
|
|
46
|
-
sameWidth?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Whether the popover should fit the viewport.
|
|
49
|
-
*/
|
|
50
|
-
fitViewport?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* The overflow boundary of the reference element
|
|
53
|
-
*/
|
|
54
|
-
boundary?: Boundary | (() => Boundary);
|
|
55
|
-
/**
|
|
56
|
-
* Options to activate auto-update listeners
|
|
57
|
-
*/
|
|
58
|
-
listeners?: boolean | AutoUpdateOptions;
|
|
59
|
-
/**
|
|
60
|
-
* Function called when the placement is computed
|
|
61
|
-
*/
|
|
62
|
-
onComplete?(data: ComputePositionReturn & {
|
|
63
|
-
compute: (config?: Omit<ComputePositionConfig, "platform">) => void;
|
|
64
|
-
}): void;
|
|
65
|
-
/**
|
|
66
|
-
* Function called on cleanup of all listeners
|
|
67
|
-
*/
|
|
68
|
-
onCleanup?: VoidFunction;
|
|
69
|
-
};
|
|
70
|
-
type BasePlacement = "top" | "right" | "bottom" | "left";
|
|
71
|
-
|
|
72
|
-
declare function getPlacement(reference: HTMLElement | VirtualElement | null, floating: HTMLElement | null, opts?: PositioningOptions): (() => void) | undefined;
|
|
73
|
-
declare function getBasePlacement(placement: Placement): BasePlacement;
|
|
74
|
-
|
|
75
|
-
type Options = {
|
|
76
|
-
measured: boolean;
|
|
77
|
-
strategy?: "absolute" | "fixed";
|
|
78
|
-
placement?: Placement;
|
|
79
|
-
};
|
|
80
|
-
declare function getPlacementStyles(options: Options): {
|
|
81
|
-
arrow: {
|
|
82
|
-
readonly [x: string]: string | 0 | undefined;
|
|
83
|
-
readonly position: "absolute";
|
|
84
|
-
readonly width: string;
|
|
85
|
-
readonly height: string;
|
|
86
|
-
readonly opacity: 0 | undefined;
|
|
87
|
-
};
|
|
88
|
-
arrowTip: {
|
|
89
|
-
readonly transform: any;
|
|
90
|
-
readonly background: string;
|
|
91
|
-
readonly top: "0";
|
|
92
|
-
readonly left: "0";
|
|
93
|
-
readonly width: "100%";
|
|
94
|
-
readonly height: "100%";
|
|
95
|
-
readonly position: "absolute";
|
|
96
|
-
readonly zIndex: "inherit";
|
|
97
|
-
};
|
|
98
|
-
floating: {
|
|
99
|
-
position: "absolute" | "fixed";
|
|
100
|
-
readonly top?: 0 | undefined;
|
|
101
|
-
readonly left?: 0 | undefined;
|
|
102
|
-
readonly opacity?: 0 | undefined;
|
|
103
|
-
readonly transform?: "translate3d(0, -200%, 0)" | undefined;
|
|
104
|
-
readonly pointerEvents?: "none" | undefined;
|
|
105
|
-
readonly minWidth: "max-content";
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export { PositioningOptions, getBasePlacement, getPlacement, getPlacementStyles };
|
|
5
|
+
import './auto-update.js';
|
package/dist/index.js
CHANGED
|
@@ -29,34 +29,40 @@ module.exports = __toCommonJS(src_exports);
|
|
|
29
29
|
// src/get-placement.ts
|
|
30
30
|
var import_dom2 = require("@floating-ui/dom");
|
|
31
31
|
|
|
32
|
-
// ../core/
|
|
32
|
+
// ../core/src/functions.ts
|
|
33
|
+
var runIfFn = (v, ...a) => {
|
|
34
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
35
|
+
return res ?? void 0;
|
|
36
|
+
};
|
|
33
37
|
var callAll = (...fns) => (...a) => {
|
|
34
38
|
fns.forEach(function(fn) {
|
|
35
|
-
fn
|
|
39
|
+
fn?.(...a);
|
|
36
40
|
});
|
|
37
41
|
};
|
|
42
|
+
|
|
43
|
+
// ../core/src/guard.ts
|
|
38
44
|
var isBoolean = (v) => v === true || v === false;
|
|
45
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
39
46
|
|
|
40
47
|
// src/auto-update.ts
|
|
41
48
|
var import_dom = require("@floating-ui/dom");
|
|
42
49
|
|
|
43
|
-
// ../dom/
|
|
44
|
-
var runIfFn = (v, ...a) => {
|
|
45
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
46
|
-
return res != null ? res : void 0;
|
|
47
|
-
};
|
|
48
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
50
|
+
// ../dom/src/query.ts
|
|
49
51
|
function isHTMLElement(v) {
|
|
50
|
-
return typeof v === "object" &&
|
|
52
|
+
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
51
53
|
}
|
|
54
|
+
|
|
55
|
+
// ../dom/src/listener.ts
|
|
52
56
|
var isRef = (v) => hasProp(v, "current");
|
|
53
57
|
function addDomEvent(target, eventName, handler, options) {
|
|
54
58
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
55
|
-
node
|
|
59
|
+
node?.addEventListener(eventName, handler, options);
|
|
56
60
|
return () => {
|
|
57
|
-
node
|
|
61
|
+
node?.removeEventListener(eventName, handler, options);
|
|
58
62
|
};
|
|
59
63
|
}
|
|
64
|
+
|
|
65
|
+
// ../dom/src/rect-observer.ts
|
|
60
66
|
function getObservedElements() {
|
|
61
67
|
;
|
|
62
68
|
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
@@ -112,12 +118,11 @@ function isEqual(rect1, rect2) {
|
|
|
112
118
|
|
|
113
119
|
// src/auto-update.ts
|
|
114
120
|
function resolveOptions(option) {
|
|
115
|
-
var _a, _b, _c;
|
|
116
121
|
const bool = isBoolean(option);
|
|
117
122
|
return {
|
|
118
|
-
ancestorResize: bool ? option :
|
|
119
|
-
ancestorScroll: bool ? option :
|
|
120
|
-
referenceResize: bool ? option :
|
|
123
|
+
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
124
|
+
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
125
|
+
referenceResize: bool ? option : option.referenceResize ?? true
|
|
121
126
|
};
|
|
122
127
|
}
|
|
123
128
|
function autoUpdate(reference, floating, update, options = false) {
|
|
@@ -221,7 +226,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
221
226
|
if (options.gutter || options.offset) {
|
|
222
227
|
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
223
228
|
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
224
|
-
if (
|
|
229
|
+
if (data?.mainAxis != null)
|
|
225
230
|
data.mainAxis += arrowOffset;
|
|
226
231
|
middleware.push((0, import_dom2.offset)(data));
|
|
227
232
|
}
|
|
@@ -272,7 +277,6 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
272
277
|
strategy,
|
|
273
278
|
...config
|
|
274
279
|
}).then((data) => {
|
|
275
|
-
var _a;
|
|
276
280
|
const x = Math.round(data.x);
|
|
277
281
|
const y = Math.round(data.y);
|
|
278
282
|
Object.assign(floating.style, {
|
|
@@ -281,7 +285,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
281
285
|
left: "0",
|
|
282
286
|
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
283
287
|
});
|
|
284
|
-
|
|
288
|
+
options.onComplete?.({ ...data, compute });
|
|
285
289
|
});
|
|
286
290
|
}
|
|
287
291
|
compute();
|