@zag-js/popper 0.10.2 → 0.10.4
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 +4 -7
- package/dist/auto-update.js +14 -36
- package/dist/auto-update.mjs +40 -5
- package/dist/get-placement.d.ts +5 -8
- package/dist/get-placement.js +29 -144
- package/dist/get-placement.mjs +120 -9
- package/dist/get-styles.d.ts +3 -5
- package/dist/get-styles.js +11 -44
- package/dist/get-styles.mjs +37 -6
- package/dist/index.d.ts +3 -5
- package/dist/index.js +7 -276
- package/dist/index.mjs +2 -14
- package/dist/middleware.d.ts +5 -7
- package/dist/middleware.js +12 -37
- package/dist/middleware.mjs +51 -9
- package/dist/types.d.ts +5 -8
- package/package.json +6 -11
- package/src/get-placement.ts +1 -1
- package/dist/chunk-EC2KMZAZ.mjs +0 -130
- package/dist/chunk-MLNMIWN3.mjs +0 -43
- package/dist/chunk-V4C4UQPN.mjs +0 -43
- package/dist/chunk-X5LLREVI.mjs +0 -57
- package/dist/types.js +0 -18
- package/dist/types.mjs +0 -0
package/dist/index.js
CHANGED
|
@@ -1,281 +1,12 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
getBasePlacement: () => getBasePlacement,
|
|
24
|
-
getPlacement: () => getPlacement,
|
|
25
|
-
getPlacementStyles: () => getPlacementStyles
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
32
|
-
var import_utils = require("@zag-js/utils");
|
|
5
|
+
const getPlacement = require('./get-placement.js');
|
|
6
|
+
const getStyles = require('./get-styles.js');
|
|
33
7
|
|
|
34
|
-
// src/auto-update.ts
|
|
35
|
-
var import_dom = require("@floating-ui/dom");
|
|
36
|
-
var import_element_rect = require("@zag-js/element-rect");
|
|
37
|
-
var callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
38
|
-
var isHTMLElement = (el) => {
|
|
39
|
-
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
40
|
-
};
|
|
41
|
-
var addDomEvent = (el, type, fn, options) => {
|
|
42
|
-
el.addEventListener(type, fn, options);
|
|
43
|
-
return () => el.removeEventListener(type, fn, options);
|
|
44
|
-
};
|
|
45
|
-
function resolveOptions(option) {
|
|
46
|
-
const bool = typeof option === "boolean";
|
|
47
|
-
return {
|
|
48
|
-
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
49
|
-
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
50
|
-
referenceResize: bool ? option : option.referenceResize ?? true
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function autoUpdate(reference, floating, update, options = false) {
|
|
54
|
-
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
55
|
-
const useAncestors = ancestorScroll || ancestorResize;
|
|
56
|
-
const ancestors = [];
|
|
57
|
-
if (useAncestors && isHTMLElement(reference)) {
|
|
58
|
-
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
59
|
-
}
|
|
60
|
-
function addResizeListeners() {
|
|
61
|
-
let cleanups = [(0, import_element_rect.trackElementRect)(floating, { scope: "size", onChange: update })];
|
|
62
|
-
if (referenceResize && isHTMLElement(reference)) {
|
|
63
|
-
cleanups.push((0, import_element_rect.trackElementRect)(reference, { onChange: update }));
|
|
64
|
-
}
|
|
65
|
-
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
66
|
-
return () => cleanups.forEach((fn) => fn());
|
|
67
|
-
}
|
|
68
|
-
function addScrollListeners() {
|
|
69
|
-
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
70
|
-
}
|
|
71
|
-
return callAll(addResizeListeners(), addScrollListeners());
|
|
72
|
-
}
|
|
73
8
|
|
|
74
|
-
// src/middleware.ts
|
|
75
|
-
var toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
76
|
-
var cssVars = {
|
|
77
|
-
arrowSize: toVar("--arrow-size"),
|
|
78
|
-
arrowSizeHalf: toVar("--arrow-size-half"),
|
|
79
|
-
arrowBg: toVar("--arrow-background"),
|
|
80
|
-
transformOrigin: toVar("--transform-origin"),
|
|
81
|
-
arrowOffset: toVar("--arrow-offset")
|
|
82
|
-
};
|
|
83
|
-
var getTransformOrigin = (arrow2) => ({
|
|
84
|
-
top: "bottom center",
|
|
85
|
-
"top-start": arrow2 ? `${arrow2.x}px bottom` : "left bottom",
|
|
86
|
-
"top-end": arrow2 ? `${arrow2.x}px bottom` : "right bottom",
|
|
87
|
-
bottom: "top center",
|
|
88
|
-
"bottom-start": arrow2 ? `${arrow2.x}px top` : "top left",
|
|
89
|
-
"bottom-end": arrow2 ? `${arrow2.x}px top` : "top right",
|
|
90
|
-
left: "right center",
|
|
91
|
-
"left-start": arrow2 ? `right ${arrow2.y}px` : "right top",
|
|
92
|
-
"left-end": arrow2 ? `right ${arrow2.y}px` : "right bottom",
|
|
93
|
-
right: "left center",
|
|
94
|
-
"right-start": arrow2 ? `left ${arrow2.y}px` : "left top",
|
|
95
|
-
"right-end": arrow2 ? `left ${arrow2.y}px` : "left bottom"
|
|
96
|
-
});
|
|
97
|
-
var transformOrigin = {
|
|
98
|
-
name: "transformOrigin",
|
|
99
|
-
fn({ placement, elements, middlewareData }) {
|
|
100
|
-
const { arrow: arrow2 } = middlewareData;
|
|
101
|
-
const transformOrigin2 = getTransformOrigin(arrow2)[placement];
|
|
102
|
-
const { floating } = elements;
|
|
103
|
-
floating.style.setProperty(cssVars.transformOrigin.variable, transformOrigin2);
|
|
104
|
-
return {
|
|
105
|
-
data: { transformOrigin: transformOrigin2 }
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
var shiftArrow = (opts) => ({
|
|
110
|
-
name: "shiftArrow",
|
|
111
|
-
fn({ placement, middlewareData }) {
|
|
112
|
-
const { element: arrow2 } = opts;
|
|
113
|
-
if (middlewareData.arrow) {
|
|
114
|
-
const { x, y } = middlewareData.arrow;
|
|
115
|
-
const dir = placement.split("-")[0];
|
|
116
|
-
Object.assign(arrow2.style, {
|
|
117
|
-
left: x != null ? `${x}px` : "",
|
|
118
|
-
top: y != null ? `${y}px` : "",
|
|
119
|
-
[dir]: `calc(100% + ${cssVars.arrowOffset.reference})`
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return {};
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
9
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
placement: "bottom",
|
|
130
|
-
listeners: true,
|
|
131
|
-
gutter: 8,
|
|
132
|
-
flip: true,
|
|
133
|
-
sameWidth: false,
|
|
134
|
-
overflowPadding: 8
|
|
135
|
-
};
|
|
136
|
-
function getPlacementImpl(reference, floating, opts = {}) {
|
|
137
|
-
if (!floating || !reference)
|
|
138
|
-
return;
|
|
139
|
-
const options = Object.assign({}, defaultOptions, opts);
|
|
140
|
-
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
141
|
-
const middleware = [];
|
|
142
|
-
const boundary = typeof options.boundary === "function" ? options.boundary() : options.boundary;
|
|
143
|
-
if (options.flip) {
|
|
144
|
-
middleware.push(
|
|
145
|
-
(0, import_dom2.flip)({
|
|
146
|
-
boundary,
|
|
147
|
-
padding: options.overflowPadding
|
|
148
|
-
})
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
if (options.gutter || options.offset) {
|
|
152
|
-
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
153
|
-
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
154
|
-
if (data?.mainAxis != null)
|
|
155
|
-
data.mainAxis += arrowOffset;
|
|
156
|
-
middleware.push((0, import_dom2.offset)(data));
|
|
157
|
-
}
|
|
158
|
-
middleware.push(
|
|
159
|
-
(0, import_dom2.shift)({
|
|
160
|
-
boundary,
|
|
161
|
-
crossAxis: options.overlap,
|
|
162
|
-
padding: options.overflowPadding
|
|
163
|
-
})
|
|
164
|
-
);
|
|
165
|
-
if (arrowEl) {
|
|
166
|
-
middleware.push(
|
|
167
|
-
(0, import_dom2.arrow)({ element: arrowEl, padding: 8 }),
|
|
168
|
-
shiftArrow({ element: arrowEl })
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
middleware.push(transformOrigin);
|
|
172
|
-
middleware.push(
|
|
173
|
-
(0, import_dom2.size)({
|
|
174
|
-
padding: options.overflowPadding,
|
|
175
|
-
apply({ rects, availableHeight, availableWidth }) {
|
|
176
|
-
const referenceWidth = Math.round(rects.reference.width);
|
|
177
|
-
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
178
|
-
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
179
|
-
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
180
|
-
if (options.sameWidth) {
|
|
181
|
-
Object.assign(floating.style, {
|
|
182
|
-
width: `${referenceWidth}px`,
|
|
183
|
-
minWidth: "unset"
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
if (options.fitViewport) {
|
|
187
|
-
Object.assign(floating.style, {
|
|
188
|
-
maxWidth: `${availableWidth}px`,
|
|
189
|
-
maxHeight: `${availableHeight}px`
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
function compute(config = {}) {
|
|
196
|
-
if (!reference || !floating)
|
|
197
|
-
return;
|
|
198
|
-
const { placement, strategy, onComplete } = options;
|
|
199
|
-
(0, import_dom2.computePosition)(reference, floating, {
|
|
200
|
-
placement,
|
|
201
|
-
middleware,
|
|
202
|
-
strategy,
|
|
203
|
-
...config
|
|
204
|
-
}).then((data) => {
|
|
205
|
-
const x = Math.round(data.x);
|
|
206
|
-
const y = Math.round(data.y);
|
|
207
|
-
Object.assign(floating.style, {
|
|
208
|
-
position: data.strategy,
|
|
209
|
-
top: "0px",
|
|
210
|
-
left: "0px",
|
|
211
|
-
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
212
|
-
});
|
|
213
|
-
onComplete?.(data);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
compute();
|
|
217
|
-
return (0, import_utils.callAll)(
|
|
218
|
-
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
219
|
-
options.onCleanup
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
function getBasePlacement(placement) {
|
|
223
|
-
return placement.split("-")[0];
|
|
224
|
-
}
|
|
225
|
-
function getPlacement(referenceOrFn, floatingOrFn, opts = {}) {
|
|
226
|
-
const { defer, ...restOptions } = opts;
|
|
227
|
-
const func = defer ? import_dom_query.raf : (v) => v();
|
|
228
|
-
const cleanups = [];
|
|
229
|
-
cleanups.push(
|
|
230
|
-
func(() => {
|
|
231
|
-
const reference = typeof referenceOrFn === "function" ? referenceOrFn() : referenceOrFn;
|
|
232
|
-
const floating = typeof floatingOrFn === "function" ? floatingOrFn() : floatingOrFn;
|
|
233
|
-
cleanups.push(getPlacementImpl(reference, floating, restOptions));
|
|
234
|
-
})
|
|
235
|
-
);
|
|
236
|
-
return () => {
|
|
237
|
-
cleanups.forEach((fn) => fn?.());
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// src/get-styles.ts
|
|
242
|
-
var ARROW_FLOATING_STYLE = {
|
|
243
|
-
bottom: "rotate(45deg)",
|
|
244
|
-
left: "rotate(135deg)",
|
|
245
|
-
top: "rotate(225deg)",
|
|
246
|
-
right: "rotate(315deg)"
|
|
247
|
-
};
|
|
248
|
-
function getPlacementStyles(options) {
|
|
249
|
-
const { placement = "bottom" } = options;
|
|
250
|
-
return {
|
|
251
|
-
arrow: {
|
|
252
|
-
position: "absolute",
|
|
253
|
-
width: cssVars.arrowSize.reference,
|
|
254
|
-
height: cssVars.arrowSize.reference,
|
|
255
|
-
[cssVars.arrowSizeHalf.variable]: `calc(${cssVars.arrowSize.reference} / 2)`,
|
|
256
|
-
[cssVars.arrowOffset.variable]: `calc(${cssVars.arrowSizeHalf.reference} * -1)`
|
|
257
|
-
},
|
|
258
|
-
arrowTip: {
|
|
259
|
-
transform: ARROW_FLOATING_STYLE[placement.split("-")[0]],
|
|
260
|
-
background: cssVars.arrowBg.reference,
|
|
261
|
-
top: "0",
|
|
262
|
-
left: "0",
|
|
263
|
-
width: "100%",
|
|
264
|
-
height: "100%",
|
|
265
|
-
position: "absolute",
|
|
266
|
-
zIndex: "inherit"
|
|
267
|
-
},
|
|
268
|
-
floating: {
|
|
269
|
-
position: "absolute",
|
|
270
|
-
minWidth: "max-content",
|
|
271
|
-
top: "0px",
|
|
272
|
-
left: "0px"
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
277
|
-
0 && (module.exports = {
|
|
278
|
-
getBasePlacement,
|
|
279
|
-
getPlacement,
|
|
280
|
-
getPlacementStyles
|
|
281
|
-
});
|
|
10
|
+
exports.getBasePlacement = getPlacement.getBasePlacement;
|
|
11
|
+
exports.getPlacement = getPlacement.getPlacement;
|
|
12
|
+
exports.getPlacementStyles = getStyles.getPlacementStyles;
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
getPlacement
|
|
4
|
-
} from "./chunk-EC2KMZAZ.mjs";
|
|
5
|
-
import "./chunk-MLNMIWN3.mjs";
|
|
6
|
-
import {
|
|
7
|
-
getPlacementStyles
|
|
8
|
-
} from "./chunk-V4C4UQPN.mjs";
|
|
9
|
-
import "./chunk-X5LLREVI.mjs";
|
|
10
|
-
export {
|
|
11
|
-
getBasePlacement,
|
|
12
|
-
getPlacement,
|
|
13
|
-
getPlacementStyles
|
|
14
|
-
};
|
|
1
|
+
export { getBasePlacement, getPlacement } from './get-placement.mjs';
|
|
2
|
+
export { getPlacementStyles } from './get-styles.mjs';
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Middleware } from
|
|
2
|
-
|
|
3
|
-
declare const cssVars: {
|
|
1
|
+
import type { Middleware } from "@floating-ui/dom";
|
|
2
|
+
export declare const cssVars: {
|
|
4
3
|
arrowSize: {
|
|
5
4
|
variable: string;
|
|
6
5
|
reference: string;
|
|
@@ -22,10 +21,9 @@ declare const cssVars: {
|
|
|
22
21
|
reference: string;
|
|
23
22
|
};
|
|
24
23
|
};
|
|
25
|
-
declare const transformOrigin: Middleware;
|
|
24
|
+
export declare const transformOrigin: Middleware;
|
|
26
25
|
type ArrowOptions = {
|
|
27
26
|
element: HTMLElement;
|
|
28
27
|
};
|
|
29
|
-
declare const shiftArrow: (opts: ArrowOptions) => Middleware;
|
|
30
|
-
|
|
31
|
-
export { cssVars, shiftArrow, transformOrigin };
|
|
28
|
+
export declare const shiftArrow: (opts: ArrowOptions) => Middleware;
|
|
29
|
+
export {};
|
package/dist/middleware.js
CHANGED
|
@@ -1,39 +1,16 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
shiftArrow: () => shiftArrow,
|
|
25
|
-
transformOrigin: () => transformOrigin
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(middleware_exports);
|
|
28
|
-
var toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
29
|
-
var cssVars = {
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
6
|
+
const cssVars = {
|
|
30
7
|
arrowSize: toVar("--arrow-size"),
|
|
31
8
|
arrowSizeHalf: toVar("--arrow-size-half"),
|
|
32
9
|
arrowBg: toVar("--arrow-background"),
|
|
33
10
|
transformOrigin: toVar("--transform-origin"),
|
|
34
11
|
arrowOffset: toVar("--arrow-offset")
|
|
35
12
|
};
|
|
36
|
-
|
|
13
|
+
const getTransformOrigin = (arrow) => ({
|
|
37
14
|
top: "bottom center",
|
|
38
15
|
"top-start": arrow ? `${arrow.x}px bottom` : "left bottom",
|
|
39
16
|
"top-end": arrow ? `${arrow.x}px bottom` : "right bottom",
|
|
@@ -47,7 +24,7 @@ var getTransformOrigin = (arrow) => ({
|
|
|
47
24
|
"right-start": arrow ? `left ${arrow.y}px` : "left top",
|
|
48
25
|
"right-end": arrow ? `left ${arrow.y}px` : "left bottom"
|
|
49
26
|
});
|
|
50
|
-
|
|
27
|
+
const transformOrigin = {
|
|
51
28
|
name: "transformOrigin",
|
|
52
29
|
fn({ placement, elements, middlewareData }) {
|
|
53
30
|
const { arrow } = middlewareData;
|
|
@@ -59,7 +36,7 @@ var transformOrigin = {
|
|
|
59
36
|
};
|
|
60
37
|
}
|
|
61
38
|
};
|
|
62
|
-
|
|
39
|
+
const shiftArrow = (opts) => ({
|
|
63
40
|
name: "shiftArrow",
|
|
64
41
|
fn({ placement, middlewareData }) {
|
|
65
42
|
const { element: arrow } = opts;
|
|
@@ -75,9 +52,7 @@ var shiftArrow = (opts) => ({
|
|
|
75
52
|
return {};
|
|
76
53
|
}
|
|
77
54
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
transformOrigin
|
|
83
|
-
});
|
|
55
|
+
|
|
56
|
+
exports.cssVars = cssVars;
|
|
57
|
+
exports.shiftArrow = shiftArrow;
|
|
58
|
+
exports.transformOrigin = transformOrigin;
|
package/dist/middleware.mjs
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
shiftArrow,
|
|
9
|
-
transformOrigin
|
|
1
|
+
const toVar = (value) => ({ variable: value, reference: `var(${value})` });
|
|
2
|
+
const cssVars = {
|
|
3
|
+
arrowSize: toVar("--arrow-size"),
|
|
4
|
+
arrowSizeHalf: toVar("--arrow-size-half"),
|
|
5
|
+
arrowBg: toVar("--arrow-background"),
|
|
6
|
+
transformOrigin: toVar("--transform-origin"),
|
|
7
|
+
arrowOffset: toVar("--arrow-offset")
|
|
10
8
|
};
|
|
9
|
+
const getTransformOrigin = (arrow) => ({
|
|
10
|
+
top: "bottom center",
|
|
11
|
+
"top-start": arrow ? `${arrow.x}px bottom` : "left bottom",
|
|
12
|
+
"top-end": arrow ? `${arrow.x}px bottom` : "right bottom",
|
|
13
|
+
bottom: "top center",
|
|
14
|
+
"bottom-start": arrow ? `${arrow.x}px top` : "top left",
|
|
15
|
+
"bottom-end": arrow ? `${arrow.x}px top` : "top right",
|
|
16
|
+
left: "right center",
|
|
17
|
+
"left-start": arrow ? `right ${arrow.y}px` : "right top",
|
|
18
|
+
"left-end": arrow ? `right ${arrow.y}px` : "right bottom",
|
|
19
|
+
right: "left center",
|
|
20
|
+
"right-start": arrow ? `left ${arrow.y}px` : "left top",
|
|
21
|
+
"right-end": arrow ? `left ${arrow.y}px` : "left bottom"
|
|
22
|
+
});
|
|
23
|
+
const transformOrigin = {
|
|
24
|
+
name: "transformOrigin",
|
|
25
|
+
fn({ placement, elements, middlewareData }) {
|
|
26
|
+
const { arrow } = middlewareData;
|
|
27
|
+
const transformOrigin2 = getTransformOrigin(arrow)[placement];
|
|
28
|
+
const { floating } = elements;
|
|
29
|
+
floating.style.setProperty(cssVars.transformOrigin.variable, transformOrigin2);
|
|
30
|
+
return {
|
|
31
|
+
data: { transformOrigin: transformOrigin2 }
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const shiftArrow = (opts) => ({
|
|
36
|
+
name: "shiftArrow",
|
|
37
|
+
fn({ placement, middlewareData }) {
|
|
38
|
+
const { element: arrow } = opts;
|
|
39
|
+
if (middlewareData.arrow) {
|
|
40
|
+
const { x, y } = middlewareData.arrow;
|
|
41
|
+
const dir = placement.split("-")[0];
|
|
42
|
+
Object.assign(arrow.style, {
|
|
43
|
+
left: x != null ? `${x}px` : "",
|
|
44
|
+
top: y != null ? `${y}px` : "",
|
|
45
|
+
[dir]: `calc(100% + ${cssVars.arrowOffset.reference})`
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export { cssVars, shiftArrow, transformOrigin };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type PositioningOptions = {
|
|
1
|
+
import type { Boundary, ComputePositionReturn, Placement } from "@floating-ui/dom";
|
|
2
|
+
import type { AutoUpdateOptions } from "./auto-update";
|
|
3
|
+
export type { Placement };
|
|
4
|
+
export type PositioningOptions = {
|
|
6
5
|
/**
|
|
7
6
|
* The strategy to use for positioning
|
|
8
7
|
*/
|
|
@@ -60,6 +59,4 @@ type PositioningOptions = {
|
|
|
60
59
|
*/
|
|
61
60
|
onCleanup?: VoidFunction;
|
|
62
61
|
};
|
|
63
|
-
type BasePlacement = "top" | "right" | "bottom" | "left";
|
|
64
|
-
|
|
65
|
-
export { BasePlacement, PositioningOptions };
|
|
62
|
+
export type BasePlacement = "top" | "right" | "bottom" | "left";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popper",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
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.
|
|
27
|
-
"@zag-js/dom-query": "0.10.
|
|
28
|
-
"@zag-js/element-rect": "0.10.
|
|
29
|
-
"@zag-js/utils": "0.10.
|
|
26
|
+
"@floating-ui/dom": "1.4.3",
|
|
27
|
+
"@zag-js/dom-query": "0.10.4",
|
|
28
|
+
"@zag-js/element-rect": "0.10.4",
|
|
29
|
+
"@zag-js/utils": "0.10.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"clean-package": "2.2.0"
|
|
@@ -44,13 +44,8 @@
|
|
|
44
44
|
"./package.json": "./package.json"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build
|
|
48
|
-
"start": "pnpm build --watch",
|
|
49
|
-
"build": "tsup src --dts",
|
|
50
|
-
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
47
|
+
"build": "vite build -c ../../../vite.config.ts",
|
|
51
48
|
"lint": "eslint src --ext .ts,.tsx",
|
|
52
|
-
"test-ci": "pnpm test --ci --runInBand",
|
|
53
|
-
"test-watch": "pnpm test --watch -u",
|
|
54
49
|
"typecheck": "tsc --noEmit"
|
|
55
50
|
}
|
|
56
51
|
}
|
package/src/get-placement.ts
CHANGED
|
@@ -45,7 +45,7 @@ function getPlacementImpl(reference: MaybeRectElement, floating: MaybeElement, o
|
|
|
45
45
|
|
|
46
46
|
if (options.gutter || options.offset) {
|
|
47
47
|
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0
|
|
48
|
-
const data = options.
|
|
48
|
+
const data = options.offset ? options.offset : { mainAxis: options.gutter }
|
|
49
49
|
if (data?.mainAxis != null) data.mainAxis += arrowOffset
|
|
50
50
|
middleware.push(offset(data))
|
|
51
51
|
}
|
package/dist/chunk-EC2KMZAZ.mjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
autoUpdate
|
|
3
|
-
} from "./chunk-MLNMIWN3.mjs";
|
|
4
|
-
import {
|
|
5
|
-
shiftArrow,
|
|
6
|
-
transformOrigin
|
|
7
|
-
} from "./chunk-X5LLREVI.mjs";
|
|
8
|
-
|
|
9
|
-
// src/get-placement.ts
|
|
10
|
-
import { arrow, computePosition, flip, offset, shift, size } from "@floating-ui/dom";
|
|
11
|
-
import { raf } from "@zag-js/dom-query";
|
|
12
|
-
import { callAll } from "@zag-js/utils";
|
|
13
|
-
var defaultOptions = {
|
|
14
|
-
strategy: "absolute",
|
|
15
|
-
placement: "bottom",
|
|
16
|
-
listeners: true,
|
|
17
|
-
gutter: 8,
|
|
18
|
-
flip: true,
|
|
19
|
-
sameWidth: false,
|
|
20
|
-
overflowPadding: 8
|
|
21
|
-
};
|
|
22
|
-
function getPlacementImpl(reference, floating, opts = {}) {
|
|
23
|
-
if (!floating || !reference)
|
|
24
|
-
return;
|
|
25
|
-
const options = Object.assign({}, defaultOptions, opts);
|
|
26
|
-
const arrowEl = floating.querySelector("[data-part=arrow]");
|
|
27
|
-
const middleware = [];
|
|
28
|
-
const boundary = typeof options.boundary === "function" ? options.boundary() : options.boundary;
|
|
29
|
-
if (options.flip) {
|
|
30
|
-
middleware.push(
|
|
31
|
-
flip({
|
|
32
|
-
boundary,
|
|
33
|
-
padding: options.overflowPadding
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
if (options.gutter || options.offset) {
|
|
38
|
-
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
39
|
-
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
40
|
-
if (data?.mainAxis != null)
|
|
41
|
-
data.mainAxis += arrowOffset;
|
|
42
|
-
middleware.push(offset(data));
|
|
43
|
-
}
|
|
44
|
-
middleware.push(
|
|
45
|
-
shift({
|
|
46
|
-
boundary,
|
|
47
|
-
crossAxis: options.overlap,
|
|
48
|
-
padding: options.overflowPadding
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
if (arrowEl) {
|
|
52
|
-
middleware.push(
|
|
53
|
-
arrow({ element: arrowEl, padding: 8 }),
|
|
54
|
-
shiftArrow({ element: arrowEl })
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
middleware.push(transformOrigin);
|
|
58
|
-
middleware.push(
|
|
59
|
-
size({
|
|
60
|
-
padding: options.overflowPadding,
|
|
61
|
-
apply({ rects, availableHeight, availableWidth }) {
|
|
62
|
-
const referenceWidth = Math.round(rects.reference.width);
|
|
63
|
-
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
|
64
|
-
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
|
65
|
-
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
|
66
|
-
if (options.sameWidth) {
|
|
67
|
-
Object.assign(floating.style, {
|
|
68
|
-
width: `${referenceWidth}px`,
|
|
69
|
-
minWidth: "unset"
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
if (options.fitViewport) {
|
|
73
|
-
Object.assign(floating.style, {
|
|
74
|
-
maxWidth: `${availableWidth}px`,
|
|
75
|
-
maxHeight: `${availableHeight}px`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
function compute(config = {}) {
|
|
82
|
-
if (!reference || !floating)
|
|
83
|
-
return;
|
|
84
|
-
const { placement, strategy, onComplete } = options;
|
|
85
|
-
computePosition(reference, floating, {
|
|
86
|
-
placement,
|
|
87
|
-
middleware,
|
|
88
|
-
strategy,
|
|
89
|
-
...config
|
|
90
|
-
}).then((data) => {
|
|
91
|
-
const x = Math.round(data.x);
|
|
92
|
-
const y = Math.round(data.y);
|
|
93
|
-
Object.assign(floating.style, {
|
|
94
|
-
position: data.strategy,
|
|
95
|
-
top: "0px",
|
|
96
|
-
left: "0px",
|
|
97
|
-
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
98
|
-
});
|
|
99
|
-
onComplete?.(data);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
compute();
|
|
103
|
-
return callAll(
|
|
104
|
-
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
105
|
-
options.onCleanup
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
function getBasePlacement(placement) {
|
|
109
|
-
return placement.split("-")[0];
|
|
110
|
-
}
|
|
111
|
-
function getPlacement(referenceOrFn, floatingOrFn, opts = {}) {
|
|
112
|
-
const { defer, ...restOptions } = opts;
|
|
113
|
-
const func = defer ? raf : (v) => v();
|
|
114
|
-
const cleanups = [];
|
|
115
|
-
cleanups.push(
|
|
116
|
-
func(() => {
|
|
117
|
-
const reference = typeof referenceOrFn === "function" ? referenceOrFn() : referenceOrFn;
|
|
118
|
-
const floating = typeof floatingOrFn === "function" ? floatingOrFn() : floatingOrFn;
|
|
119
|
-
cleanups.push(getPlacementImpl(reference, floating, restOptions));
|
|
120
|
-
})
|
|
121
|
-
);
|
|
122
|
-
return () => {
|
|
123
|
-
cleanups.forEach((fn) => fn?.());
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
getBasePlacement,
|
|
129
|
-
getPlacement
|
|
130
|
-
};
|