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