@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.
- package/dist/cjs/index.cjs +253 -306
- package/dist/cjs/index.native.cjs +385 -0
- package/dist/cjs/index.native.js +332 -378
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/index.js +226 -280
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +226 -280
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +309 -351
- package/dist/esm/index.native.js.map +1 -1
- package/package.json +6 -5
- package/src/index.tsx +78 -249
- package/types/index.d.ts +6 -8
- package/types/index.d.ts.map +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -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
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
178
|
+
LayoutHandlers.set(node, onChange);
|
|
179
|
+
observeLayoutNode(node, disableKey);
|
|
180
|
+
return () => cleanupNode(node);
|
|
215
181
|
}
|
|
216
182
|
function cleanupNode(node) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
275
|
-
|
|
229
|
+
if (typeof HTMLElement === "undefined") return void 0;
|
|
230
|
+
return x instanceof HTMLElement ? x : void 0;
|
|
276
231
|
}
|
|
277
|
-
const getBoundingClientRectAsync = node => {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
303
|
-
return callback => measure(node, callback);
|
|
304
|
-
}
|
|
253
|
+
const createMeasure = (node) => (callback) => measure(node, callback);
|
|
305
254
|
const measureInWindow = async (node, callback) => {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
319
|
-
|
|
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
|