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