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