@tamagui/use-element-layout 2.7.7 → 3.0.0-beta.1091.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.
@@ -1,322 +1,268 @@
1
1
  import { useIsomorphicLayoutEffect } from "@tamagui/constants";
2
2
  import { createContext, useContext, useId } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
- const LayoutHandlers = /* @__PURE__ */new WeakMap();
5
- const LayoutDisableKey = /* @__PURE__ */new WeakMap();
6
- const Nodes = /* @__PURE__ */new Set();
4
+
5
+ const LayoutHandlers = /* @__PURE__ */ new WeakMap();
6
+ const LayoutDisableKey = /* @__PURE__ */ new WeakMap();
7
+ const Nodes = /* @__PURE__ */ new Set();
8
+ const NodeRectCache = /* @__PURE__ */ new WeakMap();
9
+ const PrevHostNode = /* @__PURE__ */ new WeakMap();
7
10
  const usePretransformDimensions = () => globalThis.__TAMAGUI_ONLAYOUT_PRETRANSFORM === true || process.env.TAMAGUI_ONLAYOUT_PRETRANSFORM === "1";
8
- let _debugLayout;
9
- function isDebugLayout() {
10
- if (_debugLayout === void 0) _debugLayout = typeof window !== "undefined" && new URLSearchParams(window.location.search).has("__tamaDebugLayout");
11
- return _debugLayout;
12
- }
11
+ const isDebugLayout = () => typeof window !== "undefined" && window.location?.search?.includes("__tamaDebugLayout");
13
12
  const DisableLayoutContextValues = {};
14
13
  const DisableLayoutContextKey = createContext("");
15
14
  const ENABLE = typeof IntersectionObserver !== "undefined";
16
- const LayoutMeasurementController = ({
17
- disable,
18
- children
19
- }) => {
20
- const id = useId();
21
- useIsomorphicLayoutEffect(() => {
22
- const wasDisabled = DisableLayoutContextValues[id] === true;
23
- DisableLayoutContextValues[id] = disable;
24
- if (wasDisabled && !disable) measureOnNextFrame?.();
25
- }, [disable, id]);
26
- return /* @__PURE__ */jsx(DisableLayoutContextKey.Provider, {
27
- value: id,
28
- children
29
- });
15
+ const LayoutMeasurementController = ({ disable, children }) => {
16
+ const id = useId();
17
+ useIsomorphicLayoutEffect(() => {
18
+ const wasDisabled = DisableLayoutContextValues[id] === true;
19
+ DisableLayoutContextValues[id] = disable;
20
+ if (wasDisabled && !disable) measureOnNextFrame?.();
21
+ }, [disable, id]);
22
+ return /* @__PURE__ */ jsx(DisableLayoutContextKey.Provider, {
23
+ value: id,
24
+ children
25
+ });
30
26
  };
31
- let strategy = "async";
32
27
  let resumeLayoutLoop;
33
28
  let measureOnNextFrame;
34
- function setOnLayoutStrategy(state) {
35
- strategy = state;
36
- resumeLayoutLoop?.();
37
- }
38
- const NodeRectCache = /* @__PURE__ */new WeakMap();
39
29
  let avoidUpdates = true;
40
- const queuedUpdates = /* @__PURE__ */new Map();
30
+ const queuedUpdates = /* @__PURE__ */ new Map();
41
31
  function enable() {
42
- if (avoidUpdates) {
43
- avoidUpdates = false;
44
- if (queuedUpdates) {
45
- queuedUpdates.forEach(cb => cb());
46
- queuedUpdates.clear();
47
- }
48
- }
32
+ if (avoidUpdates) {
33
+ avoidUpdates = false;
34
+ if (queuedUpdates) {
35
+ queuedUpdates.forEach((cb) => cb());
36
+ queuedUpdates.clear();
37
+ }
38
+ }
49
39
  }
50
40
  function rectsEqual(a, b) {
51
- return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
41
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
52
42
  }
53
43
  if (ENABLE) {
54
- let ensureRectFetchObserver = function () {
55
- if (rectFetchObserver) return rectFetchObserver;
56
- rectFetchObserver = new IntersectionObserver(entries => {
57
- lastCallbackDelay = Math.round(performance.now() - rectFetchStartTime);
58
- for (let i = 0; i < entries.length; i++) BoundingRects.set(entries[i].target, entries[i].boundingClientRect);
59
- if (process.env.NODE_ENV === "development" && isDebugLayout() && lastCallbackDelay > 50) console.warn("[onLayout-io-delay]", lastCallbackDelay + "ms", entries.length, "entries");
60
- if (rectFetchResolve) {
61
- rectFetchResolve(true);
62
- rectFetchResolve = null;
63
- }
64
- }, {
65
- threshold: 0
66
- });
67
- return rectFetchObserver;
68
- },
69
- scheduleLayoutFrame = function () {
70
- if (frameScheduled || strategy === "off" || Nodes.size === 0 || document.hidden) return;
71
- frameScheduled = true;
72
- rAF ? rAF(layoutOnAnimationFrame) : setTimeout(layoutOnAnimationFrame, 16);
73
- };
74
- const BoundingRects = /* @__PURE__ */new WeakMap();
75
- let rectFetchObserver = null;
76
- let rectFetchResolve = null;
77
- let rectFetchStartTime = 0;
78
- let lastCallbackDelay = 0;
79
- async function updateLayoutIfChanged(node) {
80
- if (typeof LayoutHandlers.get(node) !== "function") return;
81
- const parentNode = node.parentElement;
82
- if (!parentNode) return;
83
- let nodeRect;
84
- let parentRect;
85
- if (strategy === "async") {
86
- nodeRect = BoundingRects.get(node);
87
- parentRect = BoundingRects.get(parentNode);
88
- if (!nodeRect || !parentRect) return;
89
- } else {
90
- nodeRect = node.getBoundingClientRect();
91
- parentRect = parentNode.getBoundingClientRect();
92
- }
93
- emitLayoutIfChanged(node, parentNode, nodeRect, parentRect);
94
- }
95
- const rAF = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : void 0;
96
- const userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP;
97
- const BASE_SKIP_FRAMES = userSkipVal ? +userSkipVal : 10;
98
- const MAX_SKIP_FRAMES = 20;
99
- let skipFrames = BASE_SKIP_FRAMES;
100
- let frameCount = 0;
101
- let frameScheduled = false;
102
- async function layoutOnAnimationFrame() {
103
- if (frameCount++ % skipFrames !== 0) {
104
- frameScheduled = false;
105
- scheduleLayoutFrame();
106
- return;
107
- }
108
- if (frameCount >= Number.MAX_SAFE_INTEGER) frameCount = 0;
109
- if (strategy !== "off") {
110
- const activeNodes = [];
111
- const parentsToObserve = /* @__PURE__ */new Set();
112
- for (const node of Nodes) {
113
- const parentElement = node.parentElement;
114
- if (!(parentElement instanceof HTMLElement)) {
115
- cleanupNode(node);
116
- continue;
117
- }
118
- const disableKey = LayoutDisableKey.get(node);
119
- if (disableKey && DisableLayoutContextValues[disableKey] === true) continue;
120
- activeNodes.push(node);
121
- parentsToObserve.add(parentElement);
122
- }
123
- if (activeNodes.length > 0) {
124
- const io = ensureRectFetchObserver();
125
- rectFetchStartTime = performance.now();
126
- for (let i = 0; i < activeNodes.length; i++) io.observe(activeNodes[i]);
127
- for (const parent of parentsToObserve) io.observe(parent);
128
- await new Promise(res => {
129
- rectFetchResolve = res;
130
- });
131
- for (let i = 0; i < activeNodes.length; i++) io.unobserve(activeNodes[i]);
132
- for (const parent of parentsToObserve) io.unobserve(parent);
133
- if (lastCallbackDelay > 50) skipFrames = Math.min(skipFrames + 2, MAX_SKIP_FRAMES);else if (lastCallbackDelay < 20) skipFrames = Math.max(skipFrames - 1, BASE_SKIP_FRAMES);
134
- for (let i = 0; i < activeNodes.length; i++) updateLayoutIfChanged(activeNodes[i]);
135
- }
136
- }
137
- frameScheduled = false;
138
- scheduleLayoutFrame();
139
- }
140
- resumeLayoutLoop = scheduleLayoutFrame;
141
- measureOnNextFrame = () => {
142
- frameCount = 0;
143
- scheduleLayoutFrame();
144
- };
145
- document.addEventListener("visibilitychange", scheduleLayoutFrame);
146
- scheduleLayoutFrame();
44
+ let ensureRectFetchObserver = function() {
45
+ if (rectFetchObserver) return rectFetchObserver;
46
+ rectFetchObserver = new IntersectionObserver((entries) => {
47
+ lastCallbackDelay = Math.round(performance.now() - rectFetchStartTime);
48
+ for (let i = 0; i < entries.length; i++) BoundingRects.set(entries[i].target, entries[i].boundingClientRect);
49
+ if (process.env.NODE_ENV === "development" && isDebugLayout() && lastCallbackDelay > 50) console.warn("[onLayout-io-delay]", lastCallbackDelay + "ms", entries.length, "entries");
50
+ if (rectFetchResolve) {
51
+ rectFetchResolve(true);
52
+ rectFetchResolve = null;
53
+ }
54
+ }, { threshold: 0 });
55
+ return rectFetchObserver;
56
+ }, updateLayoutIfChanged = function(node) {
57
+ if (typeof LayoutHandlers.get(node) !== "function") return;
58
+ const parentNode = node.parentElement;
59
+ if (!parentNode) return;
60
+ let nodeRect;
61
+ let parentRect;
62
+ nodeRect = BoundingRects.get(node);
63
+ parentRect = BoundingRects.get(parentNode);
64
+ if (!nodeRect || !parentRect) return;
65
+ emitLayoutIfChanged(node, parentNode, nodeRect, parentRect);
66
+ }, scheduleLayoutFrame = function() {
67
+ if (frameScheduled || Nodes.size === 0 || document.hidden) return;
68
+ frameScheduled = true;
69
+ rAF ? rAF(layoutOnAnimationFrame) : setTimeout(layoutOnAnimationFrame, 16);
70
+ };
71
+ const BoundingRects = /* @__PURE__ */ new WeakMap();
72
+ let rectFetchObserver = null;
73
+ let rectFetchResolve = null;
74
+ let rectFetchStartTime = 0;
75
+ let lastCallbackDelay = 0;
76
+ const rAF = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : void 0;
77
+ const userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP;
78
+ const BASE_SKIP_FRAMES = userSkipVal ? +userSkipVal : 10;
79
+ const MAX_SKIP_FRAMES = 20;
80
+ let skipFrames = BASE_SKIP_FRAMES;
81
+ let frameCount = 0;
82
+ let frameScheduled = false;
83
+ async function layoutOnAnimationFrame() {
84
+ if (frameCount++ % skipFrames !== 0) {
85
+ frameScheduled = false;
86
+ scheduleLayoutFrame();
87
+ return;
88
+ }
89
+ if (frameCount >= Number.MAX_SAFE_INTEGER) frameCount = 0;
90
+ {
91
+ const activeNodes = [];
92
+ const parentsToObserve = /* @__PURE__ */ new Set();
93
+ for (const node of Nodes) {
94
+ const parentElement = node.parentElement;
95
+ if (!(parentElement instanceof HTMLElement)) {
96
+ cleanupNode(node);
97
+ continue;
98
+ }
99
+ const disableKey = LayoutDisableKey.get(node);
100
+ if (disableKey && DisableLayoutContextValues[disableKey] === true) continue;
101
+ activeNodes.push(node);
102
+ parentsToObserve.add(parentElement);
103
+ }
104
+ if (activeNodes.length > 0) {
105
+ const io = ensureRectFetchObserver();
106
+ rectFetchStartTime = performance.now();
107
+ for (let i = 0; i < activeNodes.length; i++) io.observe(activeNodes[i]);
108
+ for (const parent of parentsToObserve) io.observe(parent);
109
+ await new Promise((res) => {
110
+ rectFetchResolve = res;
111
+ });
112
+ for (let i = 0; i < activeNodes.length; i++) io.unobserve(activeNodes[i]);
113
+ for (const parent of parentsToObserve) io.unobserve(parent);
114
+ if (lastCallbackDelay > 50) skipFrames = Math.min(skipFrames + 2, MAX_SKIP_FRAMES);
115
+ else if (lastCallbackDelay < 20) skipFrames = Math.max(skipFrames - 1, BASE_SKIP_FRAMES);
116
+ for (let i = 0; i < activeNodes.length; i++) updateLayoutIfChanged(activeNodes[i]);
117
+ }
118
+ }
119
+ frameScheduled = false;
120
+ scheduleLayoutFrame();
121
+ }
122
+ resumeLayoutLoop = scheduleLayoutFrame;
123
+ measureOnNextFrame = () => {
124
+ frameCount = 0;
125
+ scheduleLayoutFrame();
126
+ };
127
+ document.addEventListener("visibilitychange", scheduleLayoutFrame);
128
+ scheduleLayoutFrame();
147
129
  }
148
- const getElementLayoutEvent = (nodeRect, parentRect, node) => {
149
- return {
150
- nativeEvent: {
151
- layout: getRelativeDimensions(nodeRect, parentRect, node),
152
- target: nodeRect
153
- },
154
- timeStamp: Date.now()
155
- };
156
- };
157
- const getPreTransformDimensions = node => {
158
- return {
159
- width: node.offsetWidth,
160
- height: node.offsetHeight
161
- };
162
- };
130
+ const getElementLayoutEvent = (nodeRect, parentRect, node) => ({
131
+ nativeEvent: {
132
+ layout: getRelativeDimensions(nodeRect, parentRect, node),
133
+ target: nodeRect
134
+ },
135
+ timeStamp: Date.now()
136
+ });
137
+ const getPreTransformDimensions = (node) => ({
138
+ width: node.offsetWidth,
139
+ height: node.offsetHeight
140
+ });
163
141
  const getRelativeDimensions = (a, b, aNode) => {
164
- const {
165
- left,
166
- top
167
- } = a;
168
- const x = left - b.left;
169
- const y = top - b.top;
170
- const {
171
- width,
172
- height
173
- } = usePretransformDimensions() && aNode ? getPreTransformDimensions(aNode) : {
174
- width: a.width,
175
- height: a.height
176
- };
177
- return {
178
- x,
179
- y,
180
- width,
181
- height,
182
- pageX: a.left,
183
- pageY: a.top
184
- };
142
+ const left = a.left - b.left;
143
+ const top = a.top - b.top;
144
+ const { width, height } = usePretransformDimensions() && aNode ? getPreTransformDimensions(aNode) : {
145
+ width: a.width,
146
+ height: a.height
147
+ };
148
+ return {
149
+ x: left,
150
+ y: top,
151
+ width,
152
+ height,
153
+ pageX: a.left,
154
+ pageY: a.top
155
+ };
185
156
  };
186
157
  function emitLayoutIfChanged(node, parentNode, nodeRect, parentRect) {
187
- const onLayout = LayoutHandlers.get(node);
188
- if (typeof onLayout !== "function") return;
189
- const cachedRect = NodeRectCache.get(node);
190
- const cachedParentRect = NodeRectCache.get(parentNode);
191
- const nodeChanged = !cachedRect || !rectsEqual(cachedRect, nodeRect);
192
- const parentChanged = !cachedParentRect || !rectsEqual(cachedParentRect, parentRect);
193
- if (!nodeChanged && !parentChanged) return;
194
- NodeRectCache.set(node, nodeRect);
195
- NodeRectCache.set(parentNode, parentRect);
196
- const event = getElementLayoutEvent(nodeRect, parentRect, node);
197
- if (process.env.NODE_ENV === "development" && isDebugLayout()) console.log("[useElementLayout] change", {
198
- tag: node.tagName,
199
- id: node.id || void 0,
200
- className: (node.className || "").slice(0, 60) || void 0,
201
- layout: event.nativeEvent.layout,
202
- first: !cachedRect
203
- });
204
- if (avoidUpdates) queuedUpdates.set(node, () => onLayout(event));else onLayout(event);
158
+ const onLayout = LayoutHandlers.get(node);
159
+ if (typeof onLayout !== "function") return;
160
+ const cachedRect = NodeRectCache.get(node);
161
+ const cachedParentRect = NodeRectCache.get(parentNode);
162
+ const nodeChanged = !cachedRect || !rectsEqual(cachedRect, nodeRect);
163
+ const parentChanged = !cachedParentRect || !rectsEqual(cachedParentRect, parentRect);
164
+ if (!nodeChanged && !parentChanged) return;
165
+ NodeRectCache.set(node, nodeRect);
166
+ NodeRectCache.set(parentNode, parentRect);
167
+ const event = getElementLayoutEvent(nodeRect, parentRect, node);
168
+ if (avoidUpdates) queuedUpdates.set(node, () => onLayout(event));
169
+ else onLayout(event);
205
170
  }
206
171
  function observeLayoutNode(node, disableKey) {
207
- Nodes.add(node);
208
- if (disableKey) LayoutDisableKey.set(node, disableKey);else LayoutDisableKey.delete(node);
209
- resumeLayoutLoop?.();
172
+ Nodes.add(node);
173
+ if (disableKey) LayoutDisableKey.set(node, disableKey);
174
+ else LayoutDisableKey.delete(node);
175
+ resumeLayoutLoop?.();
210
176
  }
211
177
  function registerLayoutNode(node, onChange, disableKey) {
212
- LayoutHandlers.set(node, onChange);
213
- observeLayoutNode(node, disableKey);
214
- return () => cleanupNode(node);
178
+ LayoutHandlers.set(node, onChange);
179
+ observeLayoutNode(node, disableKey);
180
+ return () => cleanupNode(node);
215
181
  }
216
182
  function cleanupNode(node) {
217
- Nodes.delete(node);
218
- LayoutHandlers.delete(node);
219
- LayoutDisableKey.delete(node);
220
- NodeRectCache.delete(node);
183
+ Nodes.delete(node);
184
+ LayoutHandlers.delete(node);
185
+ LayoutDisableKey.delete(node);
186
+ NodeRectCache.delete(node);
221
187
  }
222
- const PrevHostNode = /* @__PURE__ */new WeakMap();
223
188
  function emitLayoutSync(node) {
224
- const onLayout = LayoutHandlers.get(node);
225
- if (typeof onLayout !== "function") return;
226
- const parentNode = node.parentElement;
227
- if (!parentNode) return;
228
- const nodeRect = node.getBoundingClientRect();
229
- const parentRect = parentNode.getBoundingClientRect();
230
- NodeRectCache.set(node, nodeRect);
231
- NodeRectCache.set(parentNode, parentRect);
232
- onLayout(getElementLayoutEvent(nodeRect, parentRect, node));
189
+ const onLayout = LayoutHandlers.get(node);
190
+ if (typeof onLayout !== "function") return;
191
+ const parentNode = node.parentElement;
192
+ if (!parentNode) return;
193
+ const nodeRect = node.getBoundingClientRect();
194
+ const parentRect = parentNode.getBoundingClientRect();
195
+ NodeRectCache.set(node, nodeRect);
196
+ NodeRectCache.set(parentNode, parentRect);
197
+ onLayout(getElementLayoutEvent(nodeRect, parentRect, node));
233
198
  }
234
199
  function useElementLayout(ref, onLayout) {
235
- const disableKey = useContext(DisableLayoutContextKey);
236
- const node = ensureWebElement(ref.current?.host);
237
- if (node && onLayout) {
238
- LayoutHandlers.set(node, onLayout);
239
- LayoutDisableKey.set(node, disableKey);
240
- }
241
- useIsomorphicLayoutEffect(() => {
242
- if (!onLayout) return;
243
- const nextNode = ensureWebElement(ref.current?.host);
244
- const prevNode = PrevHostNode.get(ref);
245
- if (nextNode === prevNode) return;
246
- if (prevNode) cleanupNode(prevNode);
247
- PrevHostNode.set(ref, nextNode);
248
- if (!nextNode) return;
249
- LayoutHandlers.set(nextNode, onLayout);
250
- observeLayoutNode(nextNode, disableKey);
251
- emitLayoutSync(nextNode);
252
- });
253
- useIsomorphicLayoutEffect(() => {
254
- if (!onLayout) return;
255
- const node2 = ref.current?.host;
256
- if (!node2) return;
257
- LayoutHandlers.set(node2, onLayout);
258
- observeLayoutNode(node2, disableKey);
259
- if (process.env.NODE_ENV === "development" && isDebugLayout()) console.log("[useElementLayout] register", {
260
- tag: node2.tagName,
261
- id: node2.id || void 0,
262
- className: (node2.className || "").slice(0, 60) || void 0,
263
- totalNodes: Nodes.size
264
- });
265
- return () => {
266
- cleanupNode(node2);
267
- const swappedNode = PrevHostNode.get(ref);
268
- if (swappedNode && swappedNode !== node2) cleanupNode(swappedNode);
269
- PrevHostNode.delete(ref);
270
- };
271
- }, [ref, !!onLayout]);
200
+ const disableKey = useContext(DisableLayoutContextKey);
201
+ const node = ensureWebElement(ref.current?.host);
202
+ if (node && onLayout) {
203
+ LayoutHandlers.set(node, onLayout);
204
+ LayoutDisableKey.set(node, disableKey);
205
+ }
206
+ useIsomorphicLayoutEffect(() => {
207
+ if (!onLayout) return;
208
+ const nextNode = ensureWebElement(ref.current?.host);
209
+ const prevNode = PrevHostNode.get(ref);
210
+ if (nextNode !== prevNode) {
211
+ if (prevNode) cleanupNode(prevNode);
212
+ PrevHostNode.set(ref, nextNode);
213
+ if (nextNode) {
214
+ LayoutHandlers.set(nextNode, onLayout);
215
+ observeLayoutNode(nextNode, disableKey);
216
+ emitLayoutSync(nextNode);
217
+ }
218
+ }
219
+ return () => {
220
+ const activeNode = ensureWebElement(ref.current?.host);
221
+ if (activeNode) cleanupNode(activeNode);
222
+ const swapped = PrevHostNode.get(ref);
223
+ if (swapped && swapped !== activeNode) cleanupNode(swapped);
224
+ PrevHostNode.delete(ref);
225
+ };
226
+ }, [ref, !!onLayout]);
272
227
  }
273
228
  function ensureWebElement(x) {
274
- if (typeof HTMLElement === "undefined") return;
275
- return x instanceof HTMLElement ? x : void 0;
229
+ if (typeof HTMLElement === "undefined") return void 0;
230
+ return x instanceof HTMLElement ? x : void 0;
276
231
  }
277
- const getBoundingClientRectAsync = node => {
278
- return new Promise(res => {
279
- if (!node || node.nodeType !== 1) return res(false);
280
- const io = new IntersectionObserver(entries => {
281
- io.disconnect();
282
- return res(entries[0].boundingClientRect);
283
- }, {
284
- threshold: 0
285
- });
286
- io.observe(node);
287
- });
288
- };
232
+ const getBoundingClientRectAsync = (node) => new Promise((res) => {
233
+ if (!node || node.nodeType !== 1) return res(false);
234
+ const io = new IntersectionObserver((entries) => {
235
+ io.disconnect();
236
+ res(entries[0].boundingClientRect);
237
+ });
238
+ io.observe(node);
239
+ });
289
240
  const measureNode = async (node, relativeTo) => {
290
- const relativeNode = relativeTo || node?.parentElement;
291
- if (relativeNode instanceof HTMLElement) {
292
- const [nodeDim, relativeNodeDim] = await Promise.all([getBoundingClientRectAsync(node), getBoundingClientRectAsync(relativeNode)]);
293
- if (relativeNodeDim && nodeDim) return getRelativeDimensions(nodeDim, relativeNodeDim, node);
294
- }
295
- return null;
241
+ const relativeNode = relativeTo || node?.parentElement;
242
+ if (relativeNode instanceof HTMLElement) {
243
+ const [nodeDim, relativeNodeDim] = await Promise.all([getBoundingClientRectAsync(node), getBoundingClientRectAsync(relativeNode)]);
244
+ if (relativeNodeDim && nodeDim) return getRelativeDimensions(nodeDim, relativeNodeDim, node);
245
+ }
246
+ return null;
296
247
  };
297
248
  const measure = async (node, callback) => {
298
- const out = await measureNode(node, node.parentNode instanceof HTMLElement ? node.parentNode : null);
299
- if (out) callback?.(out.x, out.y, out.width, out.height, out.pageX, out.pageY);
300
- return out;
249
+ const out = await measureNode(node, node.parentElement);
250
+ if (out) callback?.(out.x, out.y, out.width, out.height, out.pageX, out.pageY);
251
+ return out;
301
252
  };
302
- function createMeasure(node) {
303
- return callback => measure(node, callback);
304
- }
253
+ const createMeasure = (node) => (callback) => measure(node, callback);
305
254
  const measureInWindow = async (node, callback) => {
306
- const out = await measureNode(node, null);
307
- if (out) callback?.(out.pageX, out.pageY, out.width, out.height);
308
- return out;
309
- };
310
- const createMeasureInWindow = node => {
311
- return callback => measureInWindow(node, callback);
255
+ const out = await measureNode(node, null);
256
+ if (out) callback?.(out.pageX, out.pageY, out.width, out.height);
257
+ return out;
312
258
  };
259
+ const createMeasureInWindow = (node) => (callback) => measureInWindow(node, callback);
313
260
  const measureLayout = async (node, relativeNode, callback) => {
314
- const out = await measureNode(node, relativeNode);
315
- if (out) callback?.(out.x, out.y, out.width, out.height, out.pageX, out.pageY);
316
- return out;
261
+ const out = await measureNode(node, relativeNode);
262
+ if (out) callback?.(out.x, out.y, out.width, out.height, out.pageX, out.pageY);
263
+ return out;
317
264
  };
318
- function createMeasureLayout(node) {
319
- return (relativeTo, callback) => measureLayout(node, relativeTo, callback);
320
- }
321
- export { LayoutMeasurementController, createMeasure, createMeasureInWindow, createMeasureLayout, enable, getBoundingClientRectAsync, getElementLayoutEvent, measure, measureInWindow, measureLayout, measureNode, registerLayoutNode, setOnLayoutStrategy, useElementLayout };
265
+ const createMeasureLayout = (node) => (relativeTo, callback) => measureLayout(node, relativeTo, callback);
266
+
267
+ export { LayoutMeasurementController, createMeasure, createMeasureInWindow, createMeasureLayout, enable, getBoundingClientRectAsync, getElementLayoutEvent, measure, measureInWindow, measureLayout, measureNode, registerLayoutNode, useElementLayout };
322
268
  //# sourceMappingURL=index.mjs.map