@zag-js/popper 1.38.0 → 1.38.1

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.
@@ -33,6 +33,7 @@ var defaultOptions = {
33
33
  strategy: "absolute",
34
34
  placement: "bottom",
35
35
  listeners: true,
36
+ restoreStyles: false,
36
37
  gutter: 8,
37
38
  flip: true,
38
39
  slide: true,
@@ -138,12 +139,41 @@ function getAutoUpdateOptions(opts) {
138
139
  }
139
140
  return opts;
140
141
  }
142
+ var floatingStyleProps = [
143
+ "transform",
144
+ "visibility",
145
+ "pointer-events",
146
+ "--x",
147
+ "--y",
148
+ "--z-index",
149
+ "--reference-width",
150
+ "--reference-height",
151
+ "--available-width",
152
+ "--available-height",
153
+ "--transform-origin"
154
+ ];
155
+ var arrowStyleProps = ["top", "right", "bottom", "left"];
156
+ function createStyleCleanup(el, props) {
157
+ if (!el) return import_utils.noop;
158
+ const prev = new Map(props.map((prop) => [prop, el.style.getPropertyValue(prop)]));
159
+ return () => {
160
+ prev.forEach((value, prop) => {
161
+ if (value) el.style.setProperty(prop, value);
162
+ else el.style.removeProperty(prop);
163
+ });
164
+ if (el.style.length === 0) {
165
+ el.removeAttribute("style");
166
+ }
167
+ };
168
+ }
141
169
  function getPlacementImpl(referenceOrVirtual, floating, opts = {}) {
142
170
  const anchor = opts.getAnchorElement?.() ?? referenceOrVirtual;
143
171
  const reference = (0, import_get_anchor.getAnchorElement)(anchor, opts.getAnchorRect);
144
172
  if (!floating || !reference) return;
145
173
  const options = Object.assign({}, defaultOptions, opts);
146
174
  const arrowEl = floating.querySelector("[data-part=arrow]");
175
+ const restoreFloatingStyles = options.restoreStyles ? createStyleCleanup(floating, floatingStyleProps) : void 0;
176
+ const restoreArrowStyles = options.restoreStyles ? createStyleCleanup(arrowEl, arrowStyleProps) : void 0;
147
177
  const middleware = [
148
178
  getOffsetMiddleware(arrowEl, options),
149
179
  getFlipMiddleware(options),
@@ -213,6 +243,8 @@ function getPlacementImpl(referenceOrVirtual, floating, opts = {}) {
213
243
  update();
214
244
  return () => {
215
245
  cancelAutoUpdate?.();
246
+ restoreArrowStyles?.();
247
+ restoreFloatingStyles?.();
216
248
  onPositioned?.({ placed: false });
217
249
  };
218
250
  }
@@ -9,6 +9,7 @@ var defaultOptions = {
9
9
  strategy: "absolute",
10
10
  placement: "bottom",
11
11
  listeners: true,
12
+ restoreStyles: false,
12
13
  gutter: 8,
13
14
  flip: true,
14
15
  slide: true,
@@ -114,12 +115,41 @@ function getAutoUpdateOptions(opts) {
114
115
  }
115
116
  return opts;
116
117
  }
118
+ var floatingStyleProps = [
119
+ "transform",
120
+ "visibility",
121
+ "pointer-events",
122
+ "--x",
123
+ "--y",
124
+ "--z-index",
125
+ "--reference-width",
126
+ "--reference-height",
127
+ "--available-width",
128
+ "--available-height",
129
+ "--transform-origin"
130
+ ];
131
+ var arrowStyleProps = ["top", "right", "bottom", "left"];
132
+ function createStyleCleanup(el, props) {
133
+ if (!el) return noop;
134
+ const prev = new Map(props.map((prop) => [prop, el.style.getPropertyValue(prop)]));
135
+ return () => {
136
+ prev.forEach((value, prop) => {
137
+ if (value) el.style.setProperty(prop, value);
138
+ else el.style.removeProperty(prop);
139
+ });
140
+ if (el.style.length === 0) {
141
+ el.removeAttribute("style");
142
+ }
143
+ };
144
+ }
117
145
  function getPlacementImpl(referenceOrVirtual, floating, opts = {}) {
118
146
  const anchor = opts.getAnchorElement?.() ?? referenceOrVirtual;
119
147
  const reference = getAnchorElement(anchor, opts.getAnchorRect);
120
148
  if (!floating || !reference) return;
121
149
  const options = Object.assign({}, defaultOptions, opts);
122
150
  const arrowEl = floating.querySelector("[data-part=arrow]");
151
+ const restoreFloatingStyles = options.restoreStyles ? createStyleCleanup(floating, floatingStyleProps) : void 0;
152
+ const restoreArrowStyles = options.restoreStyles ? createStyleCleanup(arrowEl, arrowStyleProps) : void 0;
123
153
  const middleware = [
124
154
  getOffsetMiddleware(arrowEl, options),
125
155
  getFlipMiddleware(options),
@@ -189,6 +219,8 @@ function getPlacementImpl(referenceOrVirtual, floating, opts = {}) {
189
219
  update();
190
220
  return () => {
191
221
  cancelAutoUpdate?.();
222
+ restoreArrowStyles?.();
223
+ restoreFloatingStyles?.();
192
224
  onPositioned?.({ placed: false });
193
225
  };
194
226
  }
package/dist/types.d.mts CHANGED
@@ -13,6 +13,10 @@ interface AnchorRect {
13
13
  height?: number | undefined;
14
14
  }
15
15
  interface PositioningOptions {
16
+ /**
17
+ * Whether styles applied by the positioning utility should be restored on cleanup.
18
+ */
19
+ restoreStyles?: boolean | undefined;
16
20
  /**
17
21
  * Whether the popover should be hidden when the reference element is detached
18
22
  */
package/dist/types.d.ts CHANGED
@@ -13,6 +13,10 @@ interface AnchorRect {
13
13
  height?: number | undefined;
14
14
  }
15
15
  interface PositioningOptions {
16
+ /**
17
+ * Whether styles applied by the positioning utility should be restored on cleanup.
18
+ */
19
+ restoreStyles?: boolean | undefined;
16
20
  /**
17
21
  * Whether the popover should be hidden when the reference element is detached
18
22
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popper",
3
- "version": "1.38.0",
3
+ "version": "1.38.1",
4
4
  "description": "Dynamic positioning logic for ui machines",
5
5
  "keywords": [
6
6
  "js",
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@floating-ui/dom": "^1.7.6",
26
- "@zag-js/dom-query": "1.38.0",
27
- "@zag-js/utils": "1.38.0"
26
+ "@zag-js/dom-query": "1.38.1",
27
+ "@zag-js/utils": "1.38.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "clean-package": "2.2.0"