@zag-js/popper 0.2.0 → 0.2.2
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 +145 -0
- package/dist/auto-update.mjs +6 -0
- package/dist/chunk-7DJY6BDG.mjs +115 -0
- package/dist/chunk-I46LTIWB.mjs +51 -0
- package/dist/chunk-MDQJEIPL.mjs +122 -0
- package/dist/chunk-X5LLREVI.mjs +57 -0
- package/dist/get-placement.d.ts +8 -0
- package/dist/get-placement.js +303 -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 +14 -8
- 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,303 @@
|
|
|
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 != null ? res : void 0;
|
|
33
|
+
};
|
|
34
|
+
var callAll = (...fns) => (...a) => {
|
|
35
|
+
fns.forEach(function(fn) {
|
|
36
|
+
fn == null ? void 0 : 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 == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : 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 == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
57
|
+
return () => {
|
|
58
|
+
node == null ? void 0 : 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
|
+
var _a, _b, _c;
|
|
119
|
+
const bool = isBoolean(option);
|
|
120
|
+
return {
|
|
121
|
+
ancestorResize: bool ? option : (_a = option.ancestorResize) != null ? _a : true,
|
|
122
|
+
ancestorScroll: bool ? option : (_b = option.ancestorScroll) != null ? _b : true,
|
|
123
|
+
referenceResize: bool ? option : (_c = option.referenceResize) != null ? _c : true
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function autoUpdate(reference, floating, update, options = false) {
|
|
127
|
+
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
128
|
+
const useAncestors = ancestorScroll || ancestorResize;
|
|
129
|
+
const ancestors = [];
|
|
130
|
+
if (useAncestors && isHTMLElement(reference)) {
|
|
131
|
+
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
132
|
+
}
|
|
133
|
+
function addResizeListeners() {
|
|
134
|
+
let cleanups = [observeElementRect(floating, update)];
|
|
135
|
+
if (referenceResize && isHTMLElement(reference)) {
|
|
136
|
+
cleanups.push(observeElementRect(reference, update));
|
|
137
|
+
}
|
|
138
|
+
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
139
|
+
return () => cleanups.forEach((fn) => fn());
|
|
140
|
+
}
|
|
141
|
+
function addScrollListeners() {
|
|
142
|
+
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
143
|
+
}
|
|
144
|
+
return callAll(addResizeListeners(), addScrollListeners());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/middleware.ts
|
|
148
|
+
var toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
149
|
+
var cssVars = {
|
|
150
|
+
arrowSize: toVar("--arrow-size"),
|
|
151
|
+
arrowSizeHalf: toVar("--arrow-size-half"),
|
|
152
|
+
arrowBg: toVar("--arrow-background"),
|
|
153
|
+
transformOrigin: toVar("--transform-origin"),
|
|
154
|
+
arrowOffset: toVar("--arrow-offset")
|
|
155
|
+
};
|
|
156
|
+
var getTransformOrigin = (arrow2) => ({
|
|
157
|
+
top: "bottom center",
|
|
158
|
+
"top-start": arrow2 ? `${arrow2.x}px bottom` : "left bottom",
|
|
159
|
+
"top-end": arrow2 ? `${arrow2.x}px bottom` : "right bottom",
|
|
160
|
+
bottom: "top center",
|
|
161
|
+
"bottom-start": arrow2 ? `${arrow2.x}px top` : "top left",
|
|
162
|
+
"bottom-end": arrow2 ? `${arrow2.x}px top` : "top right",
|
|
163
|
+
left: "right center",
|
|
164
|
+
"left-start": arrow2 ? `right ${arrow2.y}px` : "right top",
|
|
165
|
+
"left-end": arrow2 ? `right ${arrow2.y}px` : "right bottom",
|
|
166
|
+
right: "left center",
|
|
167
|
+
"right-start": arrow2 ? `left ${arrow2.y}px` : "left top",
|
|
168
|
+
"right-end": arrow2 ? `left ${arrow2.y}px` : "left bottom"
|
|
169
|
+
});
|
|
170
|
+
var transformOrigin = {
|
|
171
|
+
name: "transformOrigin",
|
|
172
|
+
fn({ placement, elements, middlewareData }) {
|
|
173
|
+
const { arrow: arrow2 } = middlewareData;
|
|
174
|
+
const transformOrigin2 = getTransformOrigin(arrow2)[placement];
|
|
175
|
+
const { floating } = elements;
|
|
176
|
+
floating.style.setProperty(cssVars.transformOrigin.variable, transformOrigin2);
|
|
177
|
+
return {
|
|
178
|
+
data: { transformOrigin: transformOrigin2 }
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var shiftArrow = (opts) => ({
|
|
183
|
+
name: "shiftArrow",
|
|
184
|
+
fn({ placement, middlewareData }) {
|
|
185
|
+
const { element: arrow2 } = opts;
|
|
186
|
+
if (middlewareData.arrow) {
|
|
187
|
+
const { x, y } = middlewareData.arrow;
|
|
188
|
+
const dir = placement.split("-")[0];
|
|
189
|
+
Object.assign(arrow2.style, {
|
|
190
|
+
left: x != null ? `${x}px` : "",
|
|
191
|
+
top: y != null ? `${y}px` : "",
|
|
192
|
+
[dir]: `calc(100% + ${cssVars.arrowOffset.reference})`
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// src/get-placement.ts
|
|
200
|
+
var defaultOptions = {
|
|
201
|
+
strategy: "absolute",
|
|
202
|
+
placement: "bottom",
|
|
203
|
+
listeners: true,
|
|
204
|
+
gutter: 8,
|
|
205
|
+
flip: true,
|
|
206
|
+
sameWidth: false,
|
|
207
|
+
overflowPadding: 8
|
|
208
|
+
};
|
|
209
|
+
function getPlacement(reference, floating, opts = {}) {
|
|
210
|
+
if (!floating || !reference)
|
|
211
|
+
return;
|
|
212
|
+
const options = Object.assign({}, defaultOptions, opts);
|
|
213
|
+
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
214
|
+
const middleware = [];
|
|
215
|
+
const boundary = typeof options.boundary === "function" ? options.boundary() : options.boundary;
|
|
216
|
+
if (options.flip) {
|
|
217
|
+
middleware.push(
|
|
218
|
+
(0, import_dom2.flip)({
|
|
219
|
+
boundary,
|
|
220
|
+
padding: options.overflowPadding
|
|
221
|
+
})
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (options.gutter || options.offset) {
|
|
225
|
+
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
226
|
+
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
227
|
+
if ((data == null ? void 0 : data.mainAxis) != null)
|
|
228
|
+
data.mainAxis += arrowOffset;
|
|
229
|
+
middleware.push((0, import_dom2.offset)(data));
|
|
230
|
+
}
|
|
231
|
+
middleware.push(
|
|
232
|
+
(0, import_dom2.shift)({
|
|
233
|
+
boundary,
|
|
234
|
+
crossAxis: options.overlap,
|
|
235
|
+
padding: options.overflowPadding
|
|
236
|
+
})
|
|
237
|
+
);
|
|
238
|
+
if (arrowEl) {
|
|
239
|
+
middleware.push(
|
|
240
|
+
(0, import_dom2.arrow)({ element: arrowEl, padding: 8 }),
|
|
241
|
+
shiftArrow({ element: arrowEl })
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
middleware.push(transformOrigin);
|
|
245
|
+
middleware.push(
|
|
246
|
+
(0, import_dom2.size)({
|
|
247
|
+
padding: options.overflowPadding,
|
|
248
|
+
apply({ rects, availableHeight, availableWidth }) {
|
|
249
|
+
const referenceWidth = Math.round(rects.reference.width);
|
|
250
|
+
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
251
|
+
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
252
|
+
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
253
|
+
if (options.sameWidth) {
|
|
254
|
+
Object.assign(floating.style, {
|
|
255
|
+
width: `${referenceWidth}px`,
|
|
256
|
+
minWidth: "unset"
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (options.fitViewport) {
|
|
260
|
+
Object.assign(floating.style, {
|
|
261
|
+
maxWidth: `${availableWidth}px`,
|
|
262
|
+
maxHeight: `${availableHeight}px`
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
);
|
|
268
|
+
function compute(config = {}) {
|
|
269
|
+
if (!reference || !floating)
|
|
270
|
+
return;
|
|
271
|
+
const { placement, strategy } = options;
|
|
272
|
+
(0, import_dom2.computePosition)(reference, floating, {
|
|
273
|
+
placement,
|
|
274
|
+
middleware,
|
|
275
|
+
strategy,
|
|
276
|
+
...config
|
|
277
|
+
}).then((data) => {
|
|
278
|
+
var _a;
|
|
279
|
+
const x = Math.round(data.x);
|
|
280
|
+
const y = Math.round(data.y);
|
|
281
|
+
Object.assign(floating.style, {
|
|
282
|
+
position: data.strategy,
|
|
283
|
+
top: "0",
|
|
284
|
+
left: "0",
|
|
285
|
+
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
286
|
+
});
|
|
287
|
+
(_a = options.onComplete) == null ? void 0 : _a.call(options, { ...data, compute });
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
compute();
|
|
291
|
+
return callAll(
|
|
292
|
+
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
293
|
+
options.onCleanup
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
function getBasePlacement(placement) {
|
|
297
|
+
return placement.split("-")[0];
|
|
298
|
+
}
|
|
299
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
300
|
+
0 && (module.exports = {
|
|
301
|
+
getBasePlacement,
|
|
302
|
+
getPlacement
|
|
303
|
+
});
|
|
@@ -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
|
-
declare type AutoUpdateOptions = {
|
|
5
|
-
ancestorScroll?: boolean;
|
|
6
|
-
ancestorResize?: boolean;
|
|
7
|
-
referenceResize?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
declare 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
|
-
declare 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
|
-
declare 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
|
-
innerArrow: {
|
|
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,26 +29,30 @@ 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 != null ? res : void 0;
|
|
36
|
+
};
|
|
33
37
|
var callAll = (...fns) => (...a) => {
|
|
34
38
|
fns.forEach(function(fn) {
|
|
35
39
|
fn == null ? void 0 : 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
52
|
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : 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);
|
|
@@ -57,6 +61,8 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
57
61
|
node == null ? void 0 : 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();
|
|
@@ -320,7 +326,7 @@ function getPlacementStyles(options) {
|
|
|
320
326
|
[cssVars.arrowOffset.variable]: `calc(${cssVars.arrowSizeHalf.reference} * -1)`,
|
|
321
327
|
opacity: !measured ? 0 : void 0
|
|
322
328
|
},
|
|
323
|
-
|
|
329
|
+
arrowTip: {
|
|
324
330
|
transform: ARROW_FLOATING_STYLE[placement.split("-")[0]],
|
|
325
331
|
background: cssVars.arrowBg.reference,
|
|
326
332
|
top: "0",
|