@destyler/popper 0.2.11 → 0.2.12
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 +5 -6
- package/dist/index.mjs +23 -26
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AutoUpdateOptions, Boundary, ComputePositionReturn, Placement, Placement as Placement$1, VirtualElement } from "@floating-ui/dom";
|
|
2
|
-
|
|
3
2
|
//#region src/types.d.ts
|
|
4
3
|
type MaybeRectElement = HTMLElement | VirtualElement | null;
|
|
5
4
|
type MaybeElement = HTMLElement | null;
|
|
@@ -102,7 +101,7 @@ interface PositioningOptions {
|
|
|
102
101
|
}
|
|
103
102
|
//#endregion
|
|
104
103
|
//#region src/get-placement.d.ts
|
|
105
|
-
declare function getPlacement(referenceOrFn: MaybeFn<MaybeRectElement>, floatingOrFn: MaybeFn<MaybeElement>, opts?: PositioningOptions & {
|
|
104
|
+
export declare function getPlacement(referenceOrFn: MaybeFn<MaybeRectElement>, floatingOrFn: MaybeFn<MaybeElement>, opts?: PositioningOptions & {
|
|
106
105
|
defer?: boolean;
|
|
107
106
|
}): () => void;
|
|
108
107
|
//#endregion
|
|
@@ -134,7 +133,7 @@ declare const cssVars: {
|
|
|
134
133
|
interface GetPlacementStylesOptions {
|
|
135
134
|
placement?: Placement$1 | undefined;
|
|
136
135
|
}
|
|
137
|
-
declare function getPlacementStyles(options?: Pick<PositioningOptions, 'placement' | 'sameWidth' | 'fitViewport' | 'strategy'>): {
|
|
136
|
+
export declare function getPlacementStyles(options?: Pick<PositioningOptions, 'placement' | 'sameWidth' | 'fitViewport' | 'strategy'>): {
|
|
138
137
|
arrow: {
|
|
139
138
|
readonly [cssVars.arrowSizeHalf.variable]: `calc(${string} / 2)`;
|
|
140
139
|
readonly [cssVars.arrowOffset.variable]: `calc(${string} * -1)`;
|
|
@@ -167,7 +166,7 @@ declare function getPlacementStyles(options?: Pick<PositioningOptions, 'placemen
|
|
|
167
166
|
};
|
|
168
167
|
//#endregion
|
|
169
168
|
//#region src/placement.d.ts
|
|
170
|
-
declare function isValidPlacement(v: string): v is Placement$1;
|
|
171
|
-
declare function getPlacementSide(placement: Placement$1): PlacementSide;
|
|
169
|
+
export declare function isValidPlacement(v: string): v is Placement$1;
|
|
170
|
+
export declare function getPlacementSide(placement: Placement$1): PlacementSide;
|
|
172
171
|
//#endregion
|
|
173
|
-
export {
|
|
172
|
+
export type { AnchorRect, AutoUpdateOptions, Boundary, ComputePositionReturn, GetPlacementStylesOptions, Placement, PlacementAlign, PlacementSide, PositioningOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getComputedStyle, getWindow, isHTMLElement, raf } from "@destyler/dom";
|
|
2
2
|
import { compact, isNull, noop, runIfFn } from "@destyler/utils";
|
|
3
3
|
import { arrow, autoUpdate, computePosition, flip, hide, limitShift, offset, shift, size } from "@floating-ui/dom";
|
|
4
|
-
|
|
5
4
|
//#region src/get-anchor.ts
|
|
6
5
|
function createDOMRect(x = 0, y = 0, width = 0, height = 0) {
|
|
7
6
|
if (typeof DOMRect === "function") return new DOMRect(x, y, width, height);
|
|
@@ -36,7 +35,6 @@ function getAnchorElement(anchorElement, getAnchorRect) {
|
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
//#endregion
|
|
41
39
|
//#region src/middleware.ts
|
|
42
40
|
const toVar = (value) => ({
|
|
@@ -50,27 +48,27 @@ const cssVars = {
|
|
|
50
48
|
transformOrigin: toVar("--transform-origin"),
|
|
51
49
|
arrowOffset: toVar("--arrow-offset")
|
|
52
50
|
};
|
|
53
|
-
function getTransformOrigin(arrow
|
|
51
|
+
function getTransformOrigin(arrow) {
|
|
54
52
|
return {
|
|
55
53
|
"top": "bottom center",
|
|
56
|
-
"top-start": arrow
|
|
57
|
-
"top-end": arrow
|
|
54
|
+
"top-start": arrow ? `${arrow.x}px bottom` : "left bottom",
|
|
55
|
+
"top-end": arrow ? `${arrow.x}px bottom` : "right bottom",
|
|
58
56
|
"bottom": "top center",
|
|
59
|
-
"bottom-start": arrow
|
|
60
|
-
"bottom-end": arrow
|
|
57
|
+
"bottom-start": arrow ? `${arrow.x}px top` : "top left",
|
|
58
|
+
"bottom-end": arrow ? `${arrow.x}px top` : "top right",
|
|
61
59
|
"left": "right center",
|
|
62
|
-
"left-start": arrow
|
|
63
|
-
"left-end": arrow
|
|
60
|
+
"left-start": arrow ? `right ${arrow.y}px` : "right top",
|
|
61
|
+
"left-end": arrow ? `right ${arrow.y}px` : "right bottom",
|
|
64
62
|
"right": "left center",
|
|
65
|
-
"right-start": arrow
|
|
66
|
-
"right-end": arrow
|
|
63
|
+
"right-start": arrow ? `left ${arrow.y}px` : "left top",
|
|
64
|
+
"right-end": arrow ? `left ${arrow.y}px` : "left bottom"
|
|
67
65
|
};
|
|
68
66
|
}
|
|
69
67
|
const transformOriginMiddleware = {
|
|
70
68
|
name: "transformOrigin",
|
|
71
69
|
fn({ placement, elements, middlewareData }) {
|
|
72
|
-
const { arrow
|
|
73
|
-
const transformOrigin = getTransformOrigin(arrow
|
|
70
|
+
const { arrow } = middlewareData;
|
|
71
|
+
const transformOrigin = getTransformOrigin(arrow)[placement];
|
|
74
72
|
const { floating } = elements;
|
|
75
73
|
floating.style.setProperty(cssVars.transformOrigin.variable, transformOrigin);
|
|
76
74
|
return { data: { transformOrigin } };
|
|
@@ -99,7 +97,6 @@ function shiftArrowMiddleware(arrowEl) {
|
|
|
99
97
|
}
|
|
100
98
|
};
|
|
101
99
|
}
|
|
102
|
-
|
|
103
100
|
//#endregion
|
|
104
101
|
//#region src/placement.ts
|
|
105
102
|
function isValidPlacement(v) {
|
|
@@ -116,7 +113,6 @@ function getPlacementDetails(placement) {
|
|
|
116
113
|
function getPlacementSide(placement) {
|
|
117
114
|
return placement.split("-")[0];
|
|
118
115
|
}
|
|
119
|
-
|
|
120
116
|
//#endregion
|
|
121
117
|
//#region src/get-placement.ts
|
|
122
118
|
const defaultOptions = {
|
|
@@ -153,9 +149,10 @@ function getOffsetMiddleware(arrowElement, opts) {
|
|
|
153
149
|
const gutter = opts.offset?.mainAxis ?? opts.gutter;
|
|
154
150
|
const mainAxis = typeof gutter === "number" ? gutter + arrowOffset : gutter ?? arrowOffset;
|
|
155
151
|
const { hasAlign } = getPlacementDetails(placement);
|
|
156
|
-
const shift
|
|
152
|
+
const shift = !hasAlign ? opts.shift : void 0;
|
|
153
|
+
const crossAxis = opts.offset?.crossAxis ?? shift;
|
|
157
154
|
return compact({
|
|
158
|
-
crossAxis
|
|
155
|
+
crossAxis,
|
|
159
156
|
mainAxis,
|
|
160
157
|
alignmentAxis: opts.shift
|
|
161
158
|
});
|
|
@@ -241,12 +238,14 @@ function getPlacementImpl(referenceOrVirtual, floating, opts = {}) {
|
|
|
241
238
|
const y = roundByDpr(win, pos.y);
|
|
242
239
|
floating.style.setProperty("--x", `${x}px`);
|
|
243
240
|
floating.style.setProperty("--y", `${y}px`);
|
|
244
|
-
if (options.hideWhenDetached)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
241
|
+
if (options.hideWhenDetached) {
|
|
242
|
+
if (pos.middlewareData.hide?.referenceHidden) {
|
|
243
|
+
floating.style.setProperty("visibility", "hidden");
|
|
244
|
+
floating.style.setProperty("pointer-events", "none");
|
|
245
|
+
} else {
|
|
246
|
+
floating.style.removeProperty("visibility");
|
|
247
|
+
floating.style.removeProperty("pointer-events");
|
|
248
|
+
}
|
|
250
249
|
}
|
|
251
250
|
const contentEl = floating.firstElementChild;
|
|
252
251
|
if (contentEl) {
|
|
@@ -281,7 +280,6 @@ function getPlacement(referenceOrFn, floatingOrFn, opts = {}) {
|
|
|
281
280
|
cleanups.forEach((fn) => fn?.());
|
|
282
281
|
};
|
|
283
282
|
}
|
|
284
|
-
|
|
285
283
|
//#endregion
|
|
286
284
|
//#region src/get-styles.ts
|
|
287
285
|
const ARROW_FLOATING_STYLE = {
|
|
@@ -324,6 +322,5 @@ function getPlacementStyles(options = {}) {
|
|
|
324
322
|
}
|
|
325
323
|
};
|
|
326
324
|
}
|
|
327
|
-
|
|
328
325
|
//#endregion
|
|
329
|
-
export { getPlacement, getPlacementSide, getPlacementStyles, isValidPlacement };
|
|
326
|
+
export { getPlacement, getPlacementSide, getPlacementStyles, isValidPlacement };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/popper",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.12",
|
|
5
5
|
"description": "Dynamic positioning logic for UI machines",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@destyler/
|
|
27
|
-
"@
|
|
25
|
+
"@destyler/dom": "0.2.12",
|
|
26
|
+
"@destyler/utils": "0.2.12",
|
|
27
|
+
"@floating-ui/dom": "1.8.0"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|