@tamagui/use-element-layout 2.0.0-rc.3 → 2.0.0-rc.30
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 +123 -53
- package/dist/cjs/index.js +217 -132
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +181 -86
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/index.js +198 -136
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/index.mjs +123 -54
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +181 -87
- package/dist/esm/index.native.js.map +1 -1
- package/package.json +7 -10
- package/src/index.tsx +280 -89
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +4 -4
package/dist/cjs/index.js
CHANGED
|
@@ -3,15 +3,21 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
15
21
|
var index_exports = {};
|
|
16
22
|
__export(index_exports, {
|
|
17
23
|
LayoutMeasurementController: () => LayoutMeasurementController,
|
|
@@ -25,45 +31,78 @@ __export(index_exports, {
|
|
|
25
31
|
measureInWindow: () => measureInWindow,
|
|
26
32
|
measureLayout: () => measureLayout,
|
|
27
33
|
measureNode: () => measureNode,
|
|
34
|
+
registerLayoutNode: () => registerLayoutNode,
|
|
28
35
|
setOnLayoutStrategy: () => setOnLayoutStrategy,
|
|
29
36
|
useElementLayout: () => useElementLayout
|
|
30
37
|
});
|
|
31
38
|
module.exports = __toCommonJS(index_exports);
|
|
32
|
-
var import_constants = require("@tamagui/constants"),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
var import_constants = require("@tamagui/constants"),
|
|
40
|
+
import_react = require("react"),
|
|
41
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
const LayoutHandlers = /* @__PURE__ */new WeakMap(),
|
|
43
|
+
LayoutDisableKey = /* @__PURE__ */new WeakMap(),
|
|
44
|
+
Nodes = /* @__PURE__ */new Set(),
|
|
45
|
+
IntersectionState = /* @__PURE__ */new WeakMap(),
|
|
46
|
+
usePretransformDimensions = () => globalThis.__TAMAGUI_ONLAYOUT_PRETRANSFORM === !0 || process.env.TAMAGUI_ONLAYOUT_PRETRANSFORM === "1";
|
|
47
|
+
let _debugLayout;
|
|
48
|
+
function isDebugLayout() {
|
|
49
|
+
return _debugLayout === void 0 && (_debugLayout = typeof window < "u" && new URLSearchParams(window.location.search).has("__tamaDebugLayout")), _debugLayout;
|
|
50
|
+
}
|
|
51
|
+
const DisableLayoutContextValues = {},
|
|
52
|
+
DisableLayoutContextKey = (0, import_react.createContext)(""),
|
|
53
|
+
ENABLE = typeof IntersectionObserver < "u",
|
|
54
|
+
LayoutMeasurementController = ({
|
|
55
|
+
disable,
|
|
56
|
+
children
|
|
57
|
+
}) => {
|
|
58
|
+
const id = (0, import_react.useId)();
|
|
59
|
+
return (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
60
|
+
DisableLayoutContextValues[id] = disable;
|
|
61
|
+
}, [disable, id]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(DisableLayoutContextKey.Provider, {
|
|
62
|
+
value: id,
|
|
63
|
+
children
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
let globalIntersectionObserver = null,
|
|
67
|
+
strategy = "async";
|
|
43
68
|
function setOnLayoutStrategy(state) {
|
|
44
69
|
strategy = state;
|
|
45
70
|
}
|
|
46
|
-
const NodeRectCache = /* @__PURE__ */
|
|
71
|
+
const NodeRectCache = /* @__PURE__ */new WeakMap();
|
|
47
72
|
let avoidUpdates = !0;
|
|
48
|
-
const queuedUpdates = /* @__PURE__ */
|
|
73
|
+
const queuedUpdates = /* @__PURE__ */new Map();
|
|
49
74
|
function enable() {
|
|
50
|
-
avoidUpdates && (avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(
|
|
75
|
+
avoidUpdates && (avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(cb => cb()), queuedUpdates.clear()));
|
|
51
76
|
}
|
|
52
77
|
function startGlobalObservers() {
|
|
53
|
-
!ENABLE || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(
|
|
54
|
-
(entries)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
threshold: 0
|
|
78
|
+
!ENABLE || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(entries => {
|
|
79
|
+
for (let i = 0; i < entries.length; i++) {
|
|
80
|
+
const entry = entries[i],
|
|
81
|
+
node = entry.target;
|
|
82
|
+
IntersectionState.get(node) !== entry.isIntersecting && IntersectionState.set(node, entry.isIntersecting);
|
|
62
83
|
}
|
|
63
|
-
|
|
84
|
+
}, {
|
|
85
|
+
threshold: 0
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
function rectsEqual(a, b) {
|
|
89
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
64
90
|
}
|
|
65
91
|
if (ENABLE) {
|
|
66
|
-
|
|
92
|
+
let ensureRectFetchObserver = function () {
|
|
93
|
+
return rectFetchObserver || (rectFetchObserver = new IntersectionObserver(entries => {
|
|
94
|
+
lastCallbackDelay = Math.round(performance.now() - rectFetchStartTime);
|
|
95
|
+
for (let i = 0; i < entries.length; i++) BoundingRects.set(entries[i].target, entries[i].boundingClientRect);
|
|
96
|
+
process.env.NODE_ENV === "development" && isDebugLayout() && lastCallbackDelay > 50 && console.warn("[onLayout-io-delay]", lastCallbackDelay + "ms", entries.length, "entries"), rectFetchResolve && (rectFetchResolve(!0), rectFetchResolve = null);
|
|
97
|
+
}, {
|
|
98
|
+
threshold: 0
|
|
99
|
+
}), rectFetchObserver);
|
|
100
|
+
};
|
|
101
|
+
const BoundingRects = /* @__PURE__ */new WeakMap();
|
|
102
|
+
let rectFetchObserver = null,
|
|
103
|
+
rectFetchResolve = null,
|
|
104
|
+
rectFetchStartTime = 0,
|
|
105
|
+
lastCallbackDelay = 0;
|
|
67
106
|
async function updateLayoutIfChanged(node) {
|
|
68
107
|
const onLayout = LayoutHandlers.get(node);
|
|
69
108
|
if (typeof onLayout != "function") return;
|
|
@@ -71,128 +110,174 @@ if (ENABLE) {
|
|
|
71
110
|
if (!parentNode) return;
|
|
72
111
|
let nodeRect, parentRect;
|
|
73
112
|
if (strategy === "async") {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} else
|
|
82
|
-
nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
|
|
83
|
-
if (!nodeRect || !parentRect)
|
|
84
|
-
return;
|
|
85
|
-
const cachedRect = NodeRectCache.get(node), cachedParentRect = NodeRectCache.get(parentNode);
|
|
86
|
-
if (!cachedRect || !cachedParentRect || // has changed one rect
|
|
87
|
-
// @ts-expect-error DOMRectReadOnly can go into object
|
|
88
|
-
!(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) || // @ts-expect-error DOMRectReadOnly can go into object
|
|
89
|
-
!(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect)) {
|
|
113
|
+
if (nodeRect = BoundingRects.get(node), parentRect = BoundingRects.get(parentNode), !nodeRect || !parentRect) return;
|
|
114
|
+
} else nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
|
|
115
|
+
const cachedRect = NodeRectCache.get(node),
|
|
116
|
+
cachedParentRect = NodeRectCache.get(parentNode),
|
|
117
|
+
nodeChanged = !cachedRect || !rectsEqual(cachedRect, nodeRect),
|
|
118
|
+
parentChanged = !cachedParentRect || !rectsEqual(cachedParentRect, parentRect);
|
|
119
|
+
if (nodeChanged || parentChanged) {
|
|
90
120
|
NodeRectCache.set(node, nodeRect), NodeRectCache.set(parentNode, parentRect);
|
|
91
|
-
const event = getElementLayoutEvent(nodeRect, parentRect);
|
|
92
|
-
|
|
121
|
+
const event = getElementLayoutEvent(nodeRect, parentRect, node);
|
|
122
|
+
process.env.NODE_ENV === "development" && isDebugLayout() && console.log("[useElementLayout] change", {
|
|
123
|
+
tag: node.tagName,
|
|
124
|
+
id: node.id || void 0,
|
|
125
|
+
className: (node.className || "").slice(0, 60) || void 0,
|
|
126
|
+
layout: event.nativeEvent.layout,
|
|
127
|
+
first: !cachedRect
|
|
128
|
+
}), avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
|
|
93
129
|
}
|
|
94
130
|
}
|
|
95
|
-
const
|
|
131
|
+
const rAF = typeof requestAnimationFrame < "u" ? requestAnimationFrame : void 0,
|
|
132
|
+
userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP,
|
|
133
|
+
BASE_SKIP_FRAMES = userSkipVal ? +userSkipVal : 10,
|
|
134
|
+
MAX_SKIP_FRAMES = 20;
|
|
135
|
+
let skipFrames = BASE_SKIP_FRAMES,
|
|
136
|
+
frameCount = 0;
|
|
96
137
|
async function layoutOnAnimationFrame() {
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
let didObserve = !1;
|
|
112
|
-
for (const node of Nodes) {
|
|
113
|
-
if (!(node.parentElement instanceof HTMLElement)) continue;
|
|
114
|
-
const disableKey = LayoutDisableKey.get(node);
|
|
115
|
-
disableKey && DisableLayoutContextValues[disableKey] === !0 || IntersectionState.get(node) !== !1 && (didObserve = !0, io.observe(node), io.observe(node.parentElement), visibleNodes.push(node));
|
|
138
|
+
if (frameCount++ % skipFrames !== 0) {
|
|
139
|
+
rAF ? rAF(layoutOnAnimationFrame) : setTimeout(layoutOnAnimationFrame, 16);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (frameCount >= Number.MAX_SAFE_INTEGER && (frameCount = 0), strategy !== "off") {
|
|
143
|
+
const visibleNodes = [],
|
|
144
|
+
parentsToObserve = /* @__PURE__ */new Set();
|
|
145
|
+
for (const node of Nodes) {
|
|
146
|
+
const parentElement = node.parentElement;
|
|
147
|
+
if (!(parentElement instanceof HTMLElement)) {
|
|
148
|
+
cleanupNode(node);
|
|
149
|
+
continue;
|
|
116
150
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
151
|
+
const disableKey = LayoutDisableKey.get(node);
|
|
152
|
+
disableKey && DisableLayoutContextValues[disableKey] === !0 || IntersectionState.get(node) !== !1 && (visibleNodes.push(node), parentsToObserve.add(parentElement));
|
|
153
|
+
}
|
|
154
|
+
if (visibleNodes.length > 0) {
|
|
155
|
+
const io = ensureRectFetchObserver();
|
|
156
|
+
rectFetchStartTime = performance.now();
|
|
157
|
+
for (let i = 0; i < visibleNodes.length; i++) io.observe(visibleNodes[i]);
|
|
158
|
+
for (const parent of parentsToObserve) io.observe(parent);
|
|
159
|
+
await new Promise(res => {
|
|
160
|
+
rectFetchResolve = res;
|
|
161
|
+
});
|
|
162
|
+
for (let i = 0; i < visibleNodes.length; i++) io.unobserve(visibleNodes[i]);
|
|
163
|
+
for (const parent of parentsToObserve) io.unobserve(parent);
|
|
164
|
+
lastCallbackDelay > 50 ? skipFrames = Math.min(skipFrames + 2, MAX_SKIP_FRAMES) : lastCallbackDelay < 20 && (skipFrames = Math.max(skipFrames - 1, BASE_SKIP_FRAMES));
|
|
165
|
+
for (let i = 0; i < visibleNodes.length; i++) updateLayoutIfChanged(visibleNodes[i]);
|
|
166
|
+
}
|
|
121
167
|
}
|
|
122
|
-
setTimeout(layoutOnAnimationFrame, 16
|
|
168
|
+
rAF ? rAF(layoutOnAnimationFrame) : setTimeout(layoutOnAnimationFrame, 16);
|
|
123
169
|
}
|
|
124
170
|
layoutOnAnimationFrame();
|
|
125
171
|
}
|
|
126
|
-
const getElementLayoutEvent = (nodeRect, parentRect) => ({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
172
|
+
const getElementLayoutEvent = (nodeRect, parentRect, node) => ({
|
|
173
|
+
nativeEvent: {
|
|
174
|
+
layout: getRelativeDimensions(nodeRect, parentRect, node),
|
|
175
|
+
target: nodeRect
|
|
176
|
+
},
|
|
177
|
+
timeStamp: Date.now()
|
|
178
|
+
}),
|
|
179
|
+
getPreTransformDimensions = node => ({
|
|
180
|
+
width: node.offsetWidth,
|
|
181
|
+
height: node.offsetHeight
|
|
182
|
+
}),
|
|
183
|
+
getRelativeDimensions = (a, b, aNode) => {
|
|
184
|
+
const {
|
|
185
|
+
left,
|
|
186
|
+
top
|
|
187
|
+
} = a,
|
|
188
|
+
x = left - b.left,
|
|
189
|
+
y = top - b.top,
|
|
190
|
+
{
|
|
191
|
+
width,
|
|
192
|
+
height
|
|
193
|
+
} = usePretransformDimensions() && aNode ? getPreTransformDimensions(aNode) : {
|
|
194
|
+
width: a.width,
|
|
195
|
+
height: a.height
|
|
196
|
+
};
|
|
197
|
+
return {
|
|
198
|
+
x,
|
|
199
|
+
y,
|
|
200
|
+
width,
|
|
201
|
+
height,
|
|
202
|
+
pageX: a.left,
|
|
203
|
+
pageY: a.top
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
function registerLayoutNode(node, onChange, disableKey) {
|
|
207
|
+
return Nodes.add(node), LayoutHandlers.set(node, onChange), disableKey && LayoutDisableKey.set(node, disableKey), startGlobalObservers(), globalIntersectionObserver && (globalIntersectionObserver.observe(node), IntersectionState.set(node, !0)), () => cleanupNode(node);
|
|
208
|
+
}
|
|
209
|
+
function cleanupNode(node) {
|
|
210
|
+
Nodes.delete(node), LayoutHandlers.delete(node), LayoutDisableKey.delete(node), NodeRectCache.delete(node), IntersectionState.delete(node), globalIntersectionObserver && globalIntersectionObserver.unobserve(node);
|
|
211
|
+
}
|
|
212
|
+
const PrevHostNode = /* @__PURE__ */new WeakMap();
|
|
136
213
|
function useElementLayout(ref, onLayout) {
|
|
137
|
-
const disableKey = (0, import_react.useContext)(DisableLayoutContextKey),
|
|
214
|
+
const disableKey = (0, import_react.useContext)(DisableLayoutContextKey),
|
|
215
|
+
node = ensureWebElement(ref.current?.host);
|
|
138
216
|
node && onLayout && (LayoutHandlers.set(node, onLayout), LayoutDisableKey.set(node, disableKey)), (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
217
|
+
if (!onLayout) return;
|
|
218
|
+
const nextNode = ensureWebElement(ref.current?.host),
|
|
219
|
+
prevNode = PrevHostNode.get(ref);
|
|
220
|
+
if (nextNode === prevNode || (prevNode && cleanupNode(prevNode), PrevHostNode.set(ref, nextNode), !nextNode)) return;
|
|
221
|
+
Nodes.add(nextNode), startGlobalObservers(), globalIntersectionObserver && (globalIntersectionObserver.observe(nextNode), IntersectionState.set(nextNode, !0));
|
|
222
|
+
const handler = LayoutHandlers.get(nextNode);
|
|
223
|
+
if (typeof handler != "function") return;
|
|
224
|
+
const parentNode = nextNode.parentElement;
|
|
225
|
+
if (!parentNode) return;
|
|
226
|
+
const nodeRect = nextNode.getBoundingClientRect(),
|
|
227
|
+
parentRect = parentNode.getBoundingClientRect();
|
|
228
|
+
NodeRectCache.set(nextNode, nodeRect), NodeRectCache.set(parentNode, parentRect), handler(getElementLayoutEvent(nodeRect, parentRect, nextNode));
|
|
229
|
+
}), (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
139
230
|
if (!onLayout) return;
|
|
140
231
|
const node2 = ref.current?.host;
|
|
141
232
|
if (!node2) return;
|
|
142
|
-
Nodes.add(node2), startGlobalObservers(), globalIntersectionObserver && (globalIntersectionObserver.observe(node2), IntersectionState.set(node2, !0))
|
|
233
|
+
Nodes.add(node2), startGlobalObservers(), globalIntersectionObserver && (globalIntersectionObserver.observe(node2), IntersectionState.set(node2, !0)), process.env.NODE_ENV === "development" && isDebugLayout() && console.log("[useElementLayout] register", {
|
|
234
|
+
tag: node2.tagName,
|
|
235
|
+
id: node2.id || void 0,
|
|
236
|
+
className: (node2.className || "").slice(0, 60) || void 0,
|
|
237
|
+
totalNodes: Nodes.size
|
|
238
|
+
});
|
|
143
239
|
const parentNode = node2.parentNode;
|
|
144
|
-
return parentNode && onLayout(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
)
|
|
149
|
-
), () => {
|
|
150
|
-
Nodes.delete(node2), LayoutHandlers.delete(node2), NodeRectCache.delete(node2), LastChangeTime.delete(node2), IntersectionState.delete(node2), globalIntersectionObserver && globalIntersectionObserver.unobserve(node2);
|
|
240
|
+
return parentNode && onLayout(getElementLayoutEvent(node2.getBoundingClientRect(), parentNode.getBoundingClientRect(), node2)), () => {
|
|
241
|
+
cleanupNode(node2);
|
|
242
|
+
const swappedNode = PrevHostNode.get(ref);
|
|
243
|
+
swappedNode && swappedNode !== node2 && cleanupNode(swappedNode), PrevHostNode.delete(ref);
|
|
151
244
|
};
|
|
152
245
|
}, [ref, !!onLayout]);
|
|
153
246
|
}
|
|
154
247
|
function ensureWebElement(x) {
|
|
155
|
-
if (!(typeof HTMLElement > "u"))
|
|
156
|
-
return x instanceof HTMLElement ? x : void 0;
|
|
248
|
+
if (!(typeof HTMLElement > "u")) return x instanceof HTMLElement ? x : void 0;
|
|
157
249
|
}
|
|
158
|
-
const getBoundingClientRectAsync =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(entries) => (io.disconnect(), res(entries[0].boundingClientRect)),
|
|
162
|
-
{
|
|
250
|
+
const getBoundingClientRectAsync = node => new Promise(res => {
|
|
251
|
+
if (!node || node.nodeType !== 1) return res(!1);
|
|
252
|
+
const io = new IntersectionObserver(entries => (io.disconnect(), res(entries[0].boundingClientRect)), {
|
|
163
253
|
threshold: 0
|
|
254
|
+
});
|
|
255
|
+
io.observe(node);
|
|
256
|
+
}),
|
|
257
|
+
measureNode = async (node, relativeTo) => {
|
|
258
|
+
const relativeNode = relativeTo || node?.parentElement;
|
|
259
|
+
if (relativeNode instanceof HTMLElement) {
|
|
260
|
+
const [nodeDim, relativeNodeDim] = await Promise.all([getBoundingClientRectAsync(node), getBoundingClientRectAsync(relativeNode)]);
|
|
261
|
+
if (relativeNodeDim && nodeDim) return getRelativeDimensions(nodeDim, relativeNodeDim, node);
|
|
164
262
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
getBoundingClientRectAsync(node),
|
|
172
|
-
getBoundingClientRectAsync(relativeNode)
|
|
173
|
-
]);
|
|
174
|
-
if (relativeNodeDim && nodeDim)
|
|
175
|
-
return getRelativeDimensions(nodeDim, relativeNodeDim);
|
|
176
|
-
}
|
|
177
|
-
return null;
|
|
178
|
-
}, measure = async (node, callback) => {
|
|
179
|
-
const out = await measureNode(
|
|
180
|
-
node,
|
|
181
|
-
node.parentNode instanceof HTMLElement ? node.parentNode : null
|
|
182
|
-
);
|
|
183
|
-
return out && callback?.(out.x, out.y, out.width, out.height, out.pageX, out.pageY), out;
|
|
184
|
-
};
|
|
263
|
+
return null;
|
|
264
|
+
},
|
|
265
|
+
measure = async (node, callback) => {
|
|
266
|
+
const out = await measureNode(node, node.parentNode instanceof HTMLElement ? node.parentNode : null);
|
|
267
|
+
return out && callback?.(out.x, out.y, out.width, out.height, out.pageX, out.pageY), out;
|
|
268
|
+
};
|
|
185
269
|
function createMeasure(node) {
|
|
186
|
-
return
|
|
270
|
+
return callback => measure(node, callback);
|
|
187
271
|
}
|
|
188
272
|
const measureInWindow = async (node, callback) => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
273
|
+
const out = await measureNode(node, null);
|
|
274
|
+
return out && callback?.(out.pageX, out.pageY, out.width, out.height), out;
|
|
275
|
+
},
|
|
276
|
+
createMeasureInWindow = node => callback => measureInWindow(node, callback),
|
|
277
|
+
measureLayout = async (node, relativeNode, callback) => {
|
|
278
|
+
const out = await measureNode(node, relativeNode);
|
|
279
|
+
return out && callback?.(out.x, out.y, out.width, out.height, out.pageX, out.pageY), out;
|
|
280
|
+
};
|
|
195
281
|
function createMeasureLayout(node) {
|
|
196
282
|
return (relativeTo, callback) => measureLayout(node, relativeTo, callback);
|
|
197
|
-
}
|
|
198
|
-
//# sourceMappingURL=index.js.map
|
|
283
|
+
}
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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