@zag-js/popper 1.34.0 → 1.35.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.
@@ -0,0 +1,73 @@
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
+ var import_middleware = require("./middleware.cjs");
27
+ var ARROW_FLOATING_STYLE = {
28
+ bottom: "rotate(45deg)",
29
+ left: "rotate(135deg)",
30
+ top: "rotate(225deg)",
31
+ right: "rotate(315deg)"
32
+ };
33
+ function getPlacementStyles(options = {}) {
34
+ const { placement, sameWidth, fitViewport, strategy = "absolute" } = options;
35
+ return {
36
+ arrow: {
37
+ position: "absolute",
38
+ width: import_middleware.cssVars.arrowSize.reference,
39
+ height: import_middleware.cssVars.arrowSize.reference,
40
+ [import_middleware.cssVars.arrowSizeHalf.variable]: `calc(${import_middleware.cssVars.arrowSize.reference} / 2)`,
41
+ [import_middleware.cssVars.arrowOffset.variable]: `calc(${import_middleware.cssVars.arrowSizeHalf.reference} * -1)`
42
+ },
43
+ arrowTip: {
44
+ // @ts-expect-error - Fix this
45
+ transform: placement ? ARROW_FLOATING_STYLE[placement.split("-")[0]] : void 0,
46
+ background: import_middleware.cssVars.arrowBg.reference,
47
+ top: "0",
48
+ left: "0",
49
+ width: "100%",
50
+ height: "100%",
51
+ position: "absolute",
52
+ zIndex: "inherit"
53
+ },
54
+ floating: {
55
+ position: strategy,
56
+ isolation: "isolate",
57
+ minWidth: sameWidth ? void 0 : "max-content",
58
+ width: sameWidth ? "var(--reference-width)" : void 0,
59
+ maxWidth: fitViewport ? "var(--available-width)" : void 0,
60
+ maxHeight: fitViewport ? "var(--available-height)" : void 0,
61
+ pointerEvents: !placement ? "none" : void 0,
62
+ top: "0px",
63
+ left: "0px",
64
+ // move off-screen if placement is not defined
65
+ transform: placement ? "translate3d(var(--x), var(--y), 0)" : "translate3d(0, -100vh, 0)",
66
+ zIndex: "var(--z-index)"
67
+ }
68
+ };
69
+ }
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ getPlacementStyles
73
+ });
@@ -0,0 +1,48 @@
1
+ // src/get-styles.ts
2
+ import { cssVars } from "./middleware.mjs";
3
+ var ARROW_FLOATING_STYLE = {
4
+ bottom: "rotate(45deg)",
5
+ left: "rotate(135deg)",
6
+ top: "rotate(225deg)",
7
+ right: "rotate(315deg)"
8
+ };
9
+ function getPlacementStyles(options = {}) {
10
+ const { placement, sameWidth, fitViewport, strategy = "absolute" } = options;
11
+ return {
12
+ arrow: {
13
+ position: "absolute",
14
+ width: cssVars.arrowSize.reference,
15
+ height: cssVars.arrowSize.reference,
16
+ [cssVars.arrowSizeHalf.variable]: `calc(${cssVars.arrowSize.reference} / 2)`,
17
+ [cssVars.arrowOffset.variable]: `calc(${cssVars.arrowSizeHalf.reference} * -1)`
18
+ },
19
+ arrowTip: {
20
+ // @ts-expect-error - Fix this
21
+ transform: placement ? ARROW_FLOATING_STYLE[placement.split("-")[0]] : void 0,
22
+ background: cssVars.arrowBg.reference,
23
+ top: "0",
24
+ left: "0",
25
+ width: "100%",
26
+ height: "100%",
27
+ position: "absolute",
28
+ zIndex: "inherit"
29
+ },
30
+ floating: {
31
+ position: strategy,
32
+ isolation: "isolate",
33
+ minWidth: sameWidth ? void 0 : "max-content",
34
+ width: sameWidth ? "var(--reference-width)" : void 0,
35
+ maxWidth: fitViewport ? "var(--available-width)" : void 0,
36
+ maxHeight: fitViewport ? "var(--available-height)" : void 0,
37
+ pointerEvents: !placement ? "none" : void 0,
38
+ top: "0px",
39
+ left: "0px",
40
+ // move off-screen if placement is not defined
41
+ transform: placement ? "translate3d(var(--x), var(--y), 0)" : "translate3d(0, -100vh, 0)",
42
+ zIndex: "var(--z-index)"
43
+ }
44
+ };
45
+ }
46
+ export {
47
+ getPlacementStyles
48
+ };
package/dist/index.d.mts CHANGED
@@ -1,188 +1,6 @@
1
- import { Placement, Boundary, AutoUpdateOptions, ComputePositionReturn, VirtualElement } from '@floating-ui/dom';
1
+ export { getPlacement } from './get-placement.mjs';
2
+ export { GetPlacementStylesOptions, getPlacementStyles } from './get-styles.mjs';
3
+ export { getPlacementSide, isValidPlacement } from './placement.mjs';
4
+ export { AnchorRect, PlacementAlign, PlacementSide, PositioningOptions } from './types.mjs';
2
5
  export { AutoUpdateOptions, Boundary, ComputePositionReturn, Placement } from '@floating-ui/dom';
3
-
4
- type MaybeRectElement = HTMLElement | VirtualElement | null;
5
- type MaybeElement = HTMLElement | null;
6
- type MaybeFn<T> = T | (() => T);
7
- type PlacementSide = "top" | "right" | "bottom" | "left";
8
- type PlacementAlign = "start" | "center" | "end";
9
- interface AnchorRect {
10
- x?: number | undefined;
11
- y?: number | undefined;
12
- width?: number | undefined;
13
- height?: number | undefined;
14
- }
15
- interface PositioningOptions {
16
- /**
17
- * Whether the popover should be hidden when the reference element is detached
18
- */
19
- hideWhenDetached?: boolean | undefined;
20
- /**
21
- * The strategy to use for positioning
22
- */
23
- strategy?: "absolute" | "fixed" | undefined;
24
- /**
25
- * The initial placement of the floating element
26
- */
27
- placement?: Placement | undefined;
28
- /**
29
- * The offset of the floating element
30
- */
31
- offset?: {
32
- mainAxis?: number | undefined;
33
- crossAxis?: number | undefined;
34
- } | undefined;
35
- /**
36
- * The main axis offset or gap between the reference and floating elements
37
- */
38
- gutter?: number | undefined;
39
- /**
40
- * The secondary axis offset or gap between the reference and floating elements
41
- */
42
- shift?: number | undefined;
43
- /**
44
- * The virtual padding around the viewport edges to check for overflow
45
- */
46
- overflowPadding?: number | undefined;
47
- /**
48
- * The minimum padding between the arrow and the floating element's corner.
49
- * @default 4
50
- */
51
- arrowPadding?: number | undefined;
52
- /**
53
- * Whether to flip the placement
54
- */
55
- flip?: boolean | Placement[] | undefined;
56
- /**
57
- * Whether the popover should slide when it overflows.
58
- */
59
- slide?: boolean | undefined;
60
- /**
61
- * Whether the floating element can overlap the reference element
62
- * @default false
63
- */
64
- overlap?: boolean | undefined;
65
- /**
66
- * Whether to make the floating element same width as the reference element
67
- */
68
- sameWidth?: boolean | undefined;
69
- /**
70
- * Whether the popover should fit the viewport.
71
- */
72
- fitViewport?: boolean | undefined;
73
- /**
74
- * Whether to use the size middleware from Floating UI.
75
- * It computes and sets CSS variables (`--reference-width`, `--reference-height`, `--available-width`, `--available-height`) used by `sameWidth` and `fitViewport`.
76
- *
77
- * Disabling it improves scroll performance with heavy content by avoiding layout thrashing on each update.
78
- * Only applies when both `sameWidth` and `fitViewport` are false — the middleware is always used when either is enabled.
79
- * @default true
80
- */
81
- sizeMiddleware?: boolean | undefined;
82
- /**
83
- * The overflow boundary of the reference element
84
- * Accepts a function returning a Boundary, a Boundary directly,
85
- * or the shorthand string 'clipping-ancestors' which maps to Floating UI's 'clippingAncestors'.
86
- */
87
- boundary?: (() => Boundary) | Boundary | "clipping-ancestors" | undefined;
88
- /**
89
- * Options to activate auto-update listeners
90
- */
91
- listeners?: boolean | AutoUpdateOptions | undefined;
92
- /**
93
- * Function called when the placement is computed
94
- */
95
- onComplete?: ((data: ComputePositionReturn) => void) | undefined;
96
- /**
97
- * Function called when the floating element is positioned or not
98
- */
99
- onPositioned?: ((data: {
100
- placed: boolean;
101
- }) => void) | undefined;
102
- /**
103
- * Function that returns the anchor element.
104
- * Useful when you want to use a different element as the anchor.
105
- */
106
- getAnchorElement?: (() => HTMLElement | VirtualElement | null) | undefined;
107
- /**
108
- * Function that returns the anchor rect
109
- * @deprecated Use `getAnchorElement` instead
110
- */
111
- getAnchorRect?: ((element: HTMLElement | VirtualElement | null) => AnchorRect | null) | undefined;
112
- /**
113
- * A callback that will be called when the popover needs to calculate its
114
- * position.
115
- */
116
- updatePosition?: ((data: {
117
- updatePosition: () => Promise<void>;
118
- floatingElement: HTMLElement | null;
119
- }) => void | Promise<void>) | undefined;
120
- }
121
-
122
- declare function getPlacement(referenceOrFn: MaybeFn<MaybeRectElement>, floatingOrFn: MaybeFn<MaybeElement>, opts?: PositioningOptions & {
123
- defer?: boolean | undefined;
124
- }): () => void;
125
-
126
- declare const cssVars: {
127
- arrowSize: {
128
- variable: string;
129
- reference: string;
130
- };
131
- arrowSizeHalf: {
132
- variable: string;
133
- reference: string;
134
- };
135
- arrowBg: {
136
- variable: string;
137
- reference: string;
138
- };
139
- transformOrigin: {
140
- variable: string;
141
- reference: string;
142
- };
143
- arrowOffset: {
144
- variable: string;
145
- reference: string;
146
- };
147
- };
148
-
149
- interface GetPlacementStylesOptions {
150
- placement?: Placement | undefined;
151
- }
152
- declare function getPlacementStyles(options?: Pick<PositioningOptions, "placement" | "sameWidth" | "fitViewport" | "strategy">): {
153
- arrow: {
154
- readonly [cssVars.arrowSizeHalf.variable]: `calc(${string} / 2)`;
155
- readonly [cssVars.arrowOffset.variable]: `calc(${string} * -1)`;
156
- readonly position: "absolute";
157
- readonly width: string;
158
- readonly height: string;
159
- };
160
- arrowTip: {
161
- readonly transform: any;
162
- readonly background: string;
163
- readonly top: "0";
164
- readonly left: "0";
165
- readonly width: "100%";
166
- readonly height: "100%";
167
- readonly position: "absolute";
168
- readonly zIndex: "inherit";
169
- };
170
- floating: {
171
- readonly position: "fixed" | "absolute";
172
- readonly isolation: "isolate";
173
- readonly minWidth: "max-content" | undefined;
174
- readonly width: "var(--reference-width)" | undefined;
175
- readonly maxWidth: "var(--available-width)" | undefined;
176
- readonly maxHeight: "var(--available-height)" | undefined;
177
- readonly pointerEvents: "none" | undefined;
178
- readonly top: "0px";
179
- readonly left: "0px";
180
- readonly transform: "translate3d(var(--x), var(--y), 0)" | "translate3d(0, -100vh, 0)";
181
- readonly zIndex: "var(--z-index)";
182
- };
183
- };
184
-
185
- declare function isValidPlacement(v: string): v is Placement;
186
- declare function getPlacementSide(placement: Placement): PlacementSide;
187
-
188
- export { type AnchorRect, type GetPlacementStylesOptions, type PlacementAlign, type PlacementSide, type PositioningOptions, getPlacement, getPlacementSide, getPlacementStyles, isValidPlacement };
6
+ import './middleware.mjs';
package/dist/index.d.ts CHANGED
@@ -1,188 +1,6 @@
1
- import { Placement, Boundary, AutoUpdateOptions, ComputePositionReturn, VirtualElement } from '@floating-ui/dom';
1
+ export { getPlacement } from './get-placement.js';
2
+ export { GetPlacementStylesOptions, getPlacementStyles } from './get-styles.js';
3
+ export { getPlacementSide, isValidPlacement } from './placement.js';
4
+ export { AnchorRect, PlacementAlign, PlacementSide, PositioningOptions } from './types.js';
2
5
  export { AutoUpdateOptions, Boundary, ComputePositionReturn, Placement } from '@floating-ui/dom';
3
-
4
- type MaybeRectElement = HTMLElement | VirtualElement | null;
5
- type MaybeElement = HTMLElement | null;
6
- type MaybeFn<T> = T | (() => T);
7
- type PlacementSide = "top" | "right" | "bottom" | "left";
8
- type PlacementAlign = "start" | "center" | "end";
9
- interface AnchorRect {
10
- x?: number | undefined;
11
- y?: number | undefined;
12
- width?: number | undefined;
13
- height?: number | undefined;
14
- }
15
- interface PositioningOptions {
16
- /**
17
- * Whether the popover should be hidden when the reference element is detached
18
- */
19
- hideWhenDetached?: boolean | undefined;
20
- /**
21
- * The strategy to use for positioning
22
- */
23
- strategy?: "absolute" | "fixed" | undefined;
24
- /**
25
- * The initial placement of the floating element
26
- */
27
- placement?: Placement | undefined;
28
- /**
29
- * The offset of the floating element
30
- */
31
- offset?: {
32
- mainAxis?: number | undefined;
33
- crossAxis?: number | undefined;
34
- } | undefined;
35
- /**
36
- * The main axis offset or gap between the reference and floating elements
37
- */
38
- gutter?: number | undefined;
39
- /**
40
- * The secondary axis offset or gap between the reference and floating elements
41
- */
42
- shift?: number | undefined;
43
- /**
44
- * The virtual padding around the viewport edges to check for overflow
45
- */
46
- overflowPadding?: number | undefined;
47
- /**
48
- * The minimum padding between the arrow and the floating element's corner.
49
- * @default 4
50
- */
51
- arrowPadding?: number | undefined;
52
- /**
53
- * Whether to flip the placement
54
- */
55
- flip?: boolean | Placement[] | undefined;
56
- /**
57
- * Whether the popover should slide when it overflows.
58
- */
59
- slide?: boolean | undefined;
60
- /**
61
- * Whether the floating element can overlap the reference element
62
- * @default false
63
- */
64
- overlap?: boolean | undefined;
65
- /**
66
- * Whether to make the floating element same width as the reference element
67
- */
68
- sameWidth?: boolean | undefined;
69
- /**
70
- * Whether the popover should fit the viewport.
71
- */
72
- fitViewport?: boolean | undefined;
73
- /**
74
- * Whether to use the size middleware from Floating UI.
75
- * It computes and sets CSS variables (`--reference-width`, `--reference-height`, `--available-width`, `--available-height`) used by `sameWidth` and `fitViewport`.
76
- *
77
- * Disabling it improves scroll performance with heavy content by avoiding layout thrashing on each update.
78
- * Only applies when both `sameWidth` and `fitViewport` are false — the middleware is always used when either is enabled.
79
- * @default true
80
- */
81
- sizeMiddleware?: boolean | undefined;
82
- /**
83
- * The overflow boundary of the reference element
84
- * Accepts a function returning a Boundary, a Boundary directly,
85
- * or the shorthand string 'clipping-ancestors' which maps to Floating UI's 'clippingAncestors'.
86
- */
87
- boundary?: (() => Boundary) | Boundary | "clipping-ancestors" | undefined;
88
- /**
89
- * Options to activate auto-update listeners
90
- */
91
- listeners?: boolean | AutoUpdateOptions | undefined;
92
- /**
93
- * Function called when the placement is computed
94
- */
95
- onComplete?: ((data: ComputePositionReturn) => void) | undefined;
96
- /**
97
- * Function called when the floating element is positioned or not
98
- */
99
- onPositioned?: ((data: {
100
- placed: boolean;
101
- }) => void) | undefined;
102
- /**
103
- * Function that returns the anchor element.
104
- * Useful when you want to use a different element as the anchor.
105
- */
106
- getAnchorElement?: (() => HTMLElement | VirtualElement | null) | undefined;
107
- /**
108
- * Function that returns the anchor rect
109
- * @deprecated Use `getAnchorElement` instead
110
- */
111
- getAnchorRect?: ((element: HTMLElement | VirtualElement | null) => AnchorRect | null) | undefined;
112
- /**
113
- * A callback that will be called when the popover needs to calculate its
114
- * position.
115
- */
116
- updatePosition?: ((data: {
117
- updatePosition: () => Promise<void>;
118
- floatingElement: HTMLElement | null;
119
- }) => void | Promise<void>) | undefined;
120
- }
121
-
122
- declare function getPlacement(referenceOrFn: MaybeFn<MaybeRectElement>, floatingOrFn: MaybeFn<MaybeElement>, opts?: PositioningOptions & {
123
- defer?: boolean | undefined;
124
- }): () => void;
125
-
126
- declare const cssVars: {
127
- arrowSize: {
128
- variable: string;
129
- reference: string;
130
- };
131
- arrowSizeHalf: {
132
- variable: string;
133
- reference: string;
134
- };
135
- arrowBg: {
136
- variable: string;
137
- reference: string;
138
- };
139
- transformOrigin: {
140
- variable: string;
141
- reference: string;
142
- };
143
- arrowOffset: {
144
- variable: string;
145
- reference: string;
146
- };
147
- };
148
-
149
- interface GetPlacementStylesOptions {
150
- placement?: Placement | undefined;
151
- }
152
- declare function getPlacementStyles(options?: Pick<PositioningOptions, "placement" | "sameWidth" | "fitViewport" | "strategy">): {
153
- arrow: {
154
- readonly [cssVars.arrowSizeHalf.variable]: `calc(${string} / 2)`;
155
- readonly [cssVars.arrowOffset.variable]: `calc(${string} * -1)`;
156
- readonly position: "absolute";
157
- readonly width: string;
158
- readonly height: string;
159
- };
160
- arrowTip: {
161
- readonly transform: any;
162
- readonly background: string;
163
- readonly top: "0";
164
- readonly left: "0";
165
- readonly width: "100%";
166
- readonly height: "100%";
167
- readonly position: "absolute";
168
- readonly zIndex: "inherit";
169
- };
170
- floating: {
171
- readonly position: "fixed" | "absolute";
172
- readonly isolation: "isolate";
173
- readonly minWidth: "max-content" | undefined;
174
- readonly width: "var(--reference-width)" | undefined;
175
- readonly maxWidth: "var(--available-width)" | undefined;
176
- readonly maxHeight: "var(--available-height)" | undefined;
177
- readonly pointerEvents: "none" | undefined;
178
- readonly top: "0px";
179
- readonly left: "0px";
180
- readonly transform: "translate3d(var(--x), var(--y), 0)" | "translate3d(0, -100vh, 0)";
181
- readonly zIndex: "var(--z-index)";
182
- };
183
- };
184
-
185
- declare function isValidPlacement(v: string): v is Placement;
186
- declare function getPlacementSide(placement: Placement): PlacementSide;
187
-
188
- export { type AnchorRect, type GetPlacementStylesOptions, type PlacementAlign, type PlacementSide, type PositioningOptions, getPlacement, getPlacementSide, getPlacementStyles, isValidPlacement };
6
+ import './middleware.js';