@tamagui/use-element-layout 1.134.4 → 1.135.0

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.
@@ -20,6 +20,7 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
20
20
  }), mod);
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ LayoutMeasurementController: () => LayoutMeasurementController,
23
24
  createMeasure: () => createMeasure,
24
25
  createMeasureInWindow: () => createMeasureInWindow,
25
26
  createMeasureLayout: () => createMeasureLayout,
@@ -35,26 +36,42 @@ __export(index_exports, {
35
36
  });
36
37
  module.exports = __toCommonJS(index_exports);
37
38
  var import_constants = require("@tamagui/constants"),
38
- import_is_equal_shallow = require("@tamagui/is-equal-shallow");
39
+ import_is_equal_shallow = require("@tamagui/is-equal-shallow"),
40
+ import_react = require("react"),
41
+ import_jsx_runtime = require("react/jsx-runtime");
39
42
  const LayoutHandlers = /* @__PURE__ */new WeakMap(),
43
+ LayoutDisableKey = /* @__PURE__ */new WeakMap(),
40
44
  Nodes = /* @__PURE__ */new Set(),
41
- IntersectionState = /* @__PURE__ */new WeakMap();
45
+ IntersectionState = /* @__PURE__ */new WeakMap(),
46
+ DisableLayoutContextValues = {},
47
+ DisableLayoutContextKey = (0, import_react.createContext)(""),
48
+ ENABLE = import_constants.isClient && typeof IntersectionObserver < "u",
49
+ LayoutMeasurementController = ({
50
+ disable,
51
+ children
52
+ }) => {
53
+ const id = (0, import_react.useId)();
54
+ return (0, import_constants.useIsomorphicLayoutEffect)(() => {
55
+ DisableLayoutContextValues[id] = disable;
56
+ }, [disable, id]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(DisableLayoutContextKey.Provider, {
57
+ value: id,
58
+ children
59
+ });
60
+ };
42
61
  let globalIntersectionObserver = null,
43
62
  strategy = "async";
44
63
  function setOnLayoutStrategy(state) {
45
64
  strategy = state;
46
65
  }
47
66
  const NodeRectCache = /* @__PURE__ */new WeakMap(),
48
- ParentRectCache = /* @__PURE__ */new WeakMap(),
49
- LastChangeTime = /* @__PURE__ */new WeakMap(),
50
- rAF = typeof window < "u" ? window.requestAnimationFrame : void 0;
67
+ LastChangeTime = /* @__PURE__ */new WeakMap();
51
68
  let avoidUpdates = !0;
52
69
  const queuedUpdates = /* @__PURE__ */new Map();
53
70
  function enable() {
54
71
  avoidUpdates && (avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(cb => cb()), queuedUpdates.clear()));
55
72
  }
56
73
  function startGlobalObservers() {
57
- !import_constants.isClient || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(entries => {
74
+ !ENABLE || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(entries => {
58
75
  entries.forEach(entry => {
59
76
  const node = entry.target;
60
77
  IntersectionState.get(node) !== entry.isIntersecting && IntersectionState.set(node, entry.isIntersecting);
@@ -63,60 +80,61 @@ function startGlobalObservers() {
63
80
  threshold: 0
64
81
  }));
65
82
  }
66
- if (import_constants.isClient) if (rAF) {
67
- const supportsCheckVisibility = "checkVisibility" in document.body,
68
- BoundingRects = /* @__PURE__ */new WeakMap();
83
+ if (ENABLE) {
84
+ const BoundingRects = /* @__PURE__ */new WeakMap();
69
85
  async function updateLayoutIfChanged(node) {
70
- if (IntersectionState.get(node) === !1 || process.env.TAMAGUI_ONLAYOUT_VISIBILITY_CHECK === "1" && supportsCheckVisibility && !node.checkVisibility()) return;
71
86
  const onLayout = LayoutHandlers.get(node);
72
87
  if (typeof onLayout != "function") return;
73
88
  const parentNode = node.parentElement;
74
89
  if (!parentNode) return;
75
90
  let nodeRect, parentRect;
76
91
  if (strategy === "async") {
77
- const [nr, pr] = await Promise.all([BoundingRects.get(node) || getBoundingClientRectAsync(node), BoundingRects.get(parentNode) || getBoundingClientRectAsync(parentNode)]);
78
- if (nr === !1 || pr === !1) return;
92
+ const [nr, pr] = await Promise.all([BoundingRects.get(node), BoundingRects.get(parentNode)]);
93
+ if (!nr || !pr) return;
79
94
  nodeRect = nr, parentRect = pr;
80
95
  } else nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
96
+ if (!nodeRect || !parentRect) return;
81
97
  const cachedRect = NodeRectCache.get(node),
82
98
  cachedParentRect = NodeRectCache.get(parentNode);
83
- if (!cachedRect ||
99
+ if (!cachedRect || !cachedParentRect ||
84
100
  // has changed one rect
85
101
  // @ts-expect-error DOMRectReadOnly can go into object
86
- !(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) && (
102
+ !(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) ||
87
103
  // @ts-expect-error DOMRectReadOnly can go into object
88
- !cachedParentRect || !(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect))) {
89
- NodeRectCache.set(node, nodeRect), ParentRectCache.set(parentNode, parentRect);
104
+ !(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect)) {
105
+ NodeRectCache.set(node, nodeRect), NodeRectCache.set(parentNode, parentRect);
90
106
  const event = getElementLayoutEvent(nodeRect, parentRect);
91
107
  avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
92
108
  }
93
109
  }
94
- rAF(layoutOnAnimationFrame);
95
- let frameCount = 0;
96
110
  const userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP,
97
- RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 10;
111
+ RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 14;
98
112
  async function layoutOnAnimationFrame() {
99
113
  if (strategy !== "off") {
100
- if (!Nodes.size || frameCount++ % RUN_EVERY_X_FRAMES !== 0) {
101
- rAF(layoutOnAnimationFrame);
102
- return;
103
- }
104
- frameCount === Number.MAX_SAFE_INTEGER && (frameCount = 0), await new Promise(res => {
114
+ const visibleNodes = [];
115
+ (await new Promise(res => {
105
116
  const io = new IntersectionObserver(entries => {
106
117
  io.disconnect();
107
118
  for (const entry of entries) BoundingRects.set(entry.target, entry.boundingClientRect);
108
- res();
119
+ res(!0);
109
120
  }, {
110
121
  threshold: 0
111
122
  });
112
- for (const node of Nodes) node.parentElement instanceof HTMLElement && (io.observe(node), io.observe(node.parentElement));
113
- }), Nodes.forEach(node => {
123
+ let didObserve = !1;
124
+ for (const node of Nodes) {
125
+ if (!(node.parentElement instanceof HTMLElement)) continue;
126
+ const disableKey = LayoutDisableKey.get(node);
127
+ disableKey && DisableLayoutContextValues[disableKey] === !0 || IntersectionState.get(node) !== !1 && (didObserve = !0, io.observe(node), io.observe(node.parentElement), visibleNodes.push(node));
128
+ }
129
+ didObserve || res(!1);
130
+ })) && visibleNodes.forEach(node => {
114
131
  updateLayoutIfChanged(node);
115
132
  });
116
133
  }
117
- rAF(layoutOnAnimationFrame);
134
+ setTimeout(layoutOnAnimationFrame, 16.6667 * RUN_EVERY_X_FRAMES);
118
135
  }
119
- } else process.env.NODE_ENV === "development" && console.warn("No requestAnimationFrame - please polyfill for onLayout to work correctly");
136
+ layoutOnAnimationFrame();
137
+ }
120
138
  const getElementLayoutEvent = (nodeRect, parentRect) => ({
121
139
  nativeEvent: {
122
140
  layout: getRelativeDimensions(nodeRect, parentRect),
@@ -143,8 +161,9 @@ const getElementLayoutEvent = (nodeRect, parentRect) => ({
143
161
  };
144
162
  };
145
163
  function useElementLayout(ref, onLayout) {
146
- const node = ensureWebElement(ref.current?.host);
147
- node && onLayout && LayoutHandlers.set(node, onLayout), (0, import_constants.useIsomorphicLayoutEffect)(() => {
164
+ const disableKey = (0, import_react.useContext)(DisableLayoutContextKey),
165
+ node = ensureWebElement(ref.current?.host);
166
+ node && onLayout && (LayoutHandlers.set(node, onLayout), LayoutDisableKey.set(node, disableKey)), (0, import_constants.useIsomorphicLayoutEffect)(() => {
148
167
  if (!onLayout) return;
149
168
  const node2 = ref.current?.host;
150
169
  if (!node2) return;
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,7 @@ var __export = (target, all) => {
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
15
  var index_exports = {};
16
16
  __export(index_exports, {
17
+ LayoutMeasurementController: () => LayoutMeasurementController,
17
18
  createMeasure: () => createMeasure,
18
19
  createMeasureInWindow: () => createMeasureInWindow,
19
20
  createMeasureLayout: () => createMeasureLayout,
@@ -28,20 +29,28 @@ __export(index_exports, {
28
29
  useElementLayout: () => useElementLayout
29
30
  });
30
31
  module.exports = __toCommonJS(index_exports);
31
- var import_constants = require("@tamagui/constants"), import_is_equal_shallow = require("@tamagui/is-equal-shallow");
32
- const LayoutHandlers = /* @__PURE__ */ new WeakMap(), Nodes = /* @__PURE__ */ new Set(), IntersectionState = /* @__PURE__ */ new WeakMap();
32
+ var import_constants = require("@tamagui/constants"), import_is_equal_shallow = require("@tamagui/is-equal-shallow"), import_react = require("react"), import_jsx_runtime = require("react/jsx-runtime");
33
+ const LayoutHandlers = /* @__PURE__ */ new WeakMap(), LayoutDisableKey = /* @__PURE__ */ new WeakMap(), Nodes = /* @__PURE__ */ new Set(), IntersectionState = /* @__PURE__ */ new WeakMap(), DisableLayoutContextValues = {}, DisableLayoutContextKey = (0, import_react.createContext)(""), ENABLE = import_constants.isClient && typeof IntersectionObserver < "u", LayoutMeasurementController = ({
34
+ disable,
35
+ children
36
+ }) => {
37
+ const id = (0, import_react.useId)();
38
+ return (0, import_constants.useIsomorphicLayoutEffect)(() => {
39
+ DisableLayoutContextValues[id] = disable;
40
+ }, [disable, id]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DisableLayoutContextKey.Provider, { value: id, children });
41
+ };
33
42
  let globalIntersectionObserver = null, strategy = "async";
34
43
  function setOnLayoutStrategy(state) {
35
44
  strategy = state;
36
45
  }
37
- const NodeRectCache = /* @__PURE__ */ new WeakMap(), ParentRectCache = /* @__PURE__ */ new WeakMap(), LastChangeTime = /* @__PURE__ */ new WeakMap(), rAF = typeof window < "u" ? window.requestAnimationFrame : void 0;
46
+ const NodeRectCache = /* @__PURE__ */ new WeakMap(), LastChangeTime = /* @__PURE__ */ new WeakMap();
38
47
  let avoidUpdates = !0;
39
48
  const queuedUpdates = /* @__PURE__ */ new Map();
40
49
  function enable() {
41
50
  avoidUpdates && (avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach((cb) => cb()), queuedUpdates.clear()));
42
51
  }
43
52
  function startGlobalObservers() {
44
- !import_constants.isClient || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(
53
+ !ENABLE || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(
45
54
  (entries) => {
46
55
  entries.forEach((entry) => {
47
56
  const node = entry.target;
@@ -53,70 +62,67 @@ function startGlobalObservers() {
53
62
  }
54
63
  ));
55
64
  }
56
- if (import_constants.isClient)
57
- if (rAF) {
58
- const supportsCheckVisibility = "checkVisibility" in document.body, BoundingRects = /* @__PURE__ */ new WeakMap();
59
- async function updateLayoutIfChanged(node) {
60
- if (IntersectionState.get(node) === !1 || process.env.TAMAGUI_ONLAYOUT_VISIBILITY_CHECK === "1" && supportsCheckVisibility && !node.checkVisibility())
65
+ if (ENABLE) {
66
+ const BoundingRects = /* @__PURE__ */ new WeakMap();
67
+ async function updateLayoutIfChanged(node) {
68
+ const onLayout = LayoutHandlers.get(node);
69
+ if (typeof onLayout != "function") return;
70
+ const parentNode = node.parentElement;
71
+ if (!parentNode) return;
72
+ let nodeRect, parentRect;
73
+ if (strategy === "async") {
74
+ const [nr, pr] = await Promise.all([
75
+ BoundingRects.get(node),
76
+ BoundingRects.get(parentNode)
77
+ ]);
78
+ if (!nr || !pr)
61
79
  return;
62
- const onLayout = LayoutHandlers.get(node);
63
- if (typeof onLayout != "function") return;
64
- const parentNode = node.parentElement;
65
- if (!parentNode) return;
66
- let nodeRect, parentRect;
67
- if (strategy === "async") {
68
- const [nr, pr] = await Promise.all([
69
- BoundingRects.get(node) || getBoundingClientRectAsync(node),
70
- BoundingRects.get(parentNode) || getBoundingClientRectAsync(parentNode)
71
- ]);
72
- if (nr === !1 || pr === !1)
73
- return;
74
- nodeRect = nr, parentRect = pr;
75
- } else
76
- nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
77
- const cachedRect = NodeRectCache.get(node), cachedParentRect = NodeRectCache.get(parentNode);
78
- if (!cachedRect || // has changed one rect
79
- // @ts-expect-error DOMRectReadOnly can go into object
80
- !(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) && // @ts-expect-error DOMRectReadOnly can go into object
81
- (!cachedParentRect || !(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect))) {
82
- NodeRectCache.set(node, nodeRect), ParentRectCache.set(parentNode, parentRect);
83
- const event = getElementLayoutEvent(nodeRect, parentRect);
84
- avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
85
- }
80
+ nodeRect = nr, parentRect = pr;
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)) {
90
+ NodeRectCache.set(node, nodeRect), NodeRectCache.set(parentNode, parentRect);
91
+ const event = getElementLayoutEvent(nodeRect, parentRect);
92
+ avoidUpdates ? queuedUpdates.set(node, () => onLayout(event)) : onLayout(event);
86
93
  }
87
- rAF(layoutOnAnimationFrame);
88
- let frameCount = 0;
89
- const userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP, RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 10;
90
- async function layoutOnAnimationFrame() {
91
- if (strategy !== "off") {
92
- if (!Nodes.size || frameCount++ % RUN_EVERY_X_FRAMES !== 0) {
93
- rAF(layoutOnAnimationFrame);
94
- return;
94
+ }
95
+ const userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP, RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 14;
96
+ async function layoutOnAnimationFrame() {
97
+ if (strategy !== "off") {
98
+ const visibleNodes = [];
99
+ await new Promise((res) => {
100
+ const io = new IntersectionObserver(
101
+ (entries) => {
102
+ io.disconnect();
103
+ for (const entry of entries)
104
+ BoundingRects.set(entry.target, entry.boundingClientRect);
105
+ res(!0);
106
+ },
107
+ {
108
+ threshold: 0
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));
95
116
  }
96
- frameCount === Number.MAX_SAFE_INTEGER && (frameCount = 0), await new Promise((res) => {
97
- const io = new IntersectionObserver(
98
- (entries) => {
99
- io.disconnect();
100
- for (const entry of entries)
101
- BoundingRects.set(entry.target, entry.boundingClientRect);
102
- res();
103
- },
104
- {
105
- threshold: 0
106
- }
107
- );
108
- for (const node of Nodes)
109
- node.parentElement instanceof HTMLElement && (io.observe(node), io.observe(node.parentElement));
110
- }), Nodes.forEach((node) => {
111
- updateLayoutIfChanged(node);
112
- });
113
- }
114
- rAF(layoutOnAnimationFrame);
117
+ didObserve || res(!1);
118
+ }) && visibleNodes.forEach((node) => {
119
+ updateLayoutIfChanged(node);
120
+ });
115
121
  }
116
- } else
117
- process.env.NODE_ENV === "development" && console.warn(
118
- "No requestAnimationFrame - please polyfill for onLayout to work correctly"
119
- );
122
+ setTimeout(layoutOnAnimationFrame, 16.6667 * RUN_EVERY_X_FRAMES);
123
+ }
124
+ layoutOnAnimationFrame();
125
+ }
120
126
  const getElementLayoutEvent = (nodeRect, parentRect) => ({
121
127
  nativeEvent: {
122
128
  layout: getRelativeDimensions(nodeRect, parentRect),
@@ -128,8 +134,8 @@ const getElementLayoutEvent = (nodeRect, parentRect) => ({
128
134
  return { x, y, width, height, pageX: a.left, pageY: a.top };
129
135
  };
130
136
  function useElementLayout(ref, onLayout) {
131
- const node = ensureWebElement(ref.current?.host);
132
- node && onLayout && LayoutHandlers.set(node, onLayout), (0, import_constants.useIsomorphicLayoutEffect)(() => {
137
+ const disableKey = (0, import_react.useContext)(DisableLayoutContextKey), node = ensureWebElement(ref.current?.host);
138
+ node && onLayout && (LayoutHandlers.set(node, onLayout), LayoutDisableKey.set(node, disableKey)), (0, import_constants.useIsomorphicLayoutEffect)(() => {
133
139
  if (!onLayout) return;
134
140
  const node2 = ref.current?.host;
135
141
  if (!node2) return;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAoD,+BACpD,0BAA+B;AAG/B,MAAM,iBAAiB,oBAAI,QAA+B,GACpD,QAAQ,oBAAI,IAAiB,GAC7B,oBAAoB,oBAAI,QAA8B;AAG5D,IAAI,6BAA0D,MAQ1D,WAAsC;AAEnC,SAAS,oBAAoB,OAAwC;AAC1E,aAAW;AACb;AAmBA,MAAM,gBAAgB,oBAAI,QAA8B,GAClD,kBAAkB,oBAAI,QAA8B,GACpD,iBAAiB,oBAAI,QAA6B,GAElD,MAAM,OAAO,SAAW,MAAc,OAAO,wBAAwB;AAG3E,IAAI,eAAe;AACnB,MAAM,gBAAgB,oBAAI,IAA2B;AAE9C,SAAS,SAAe;AAC7B,EAAI,iBACF,eAAe,IACX,kBACF,cAAc,QAAQ,CAAC,OAAO,GAAG,CAAC,GAClC,cAAc,MAAM;AAG1B;AAEA,SAAS,uBAAuB;AAC9B,EAA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K,aAAa;AAAA,EAC7D;AACA,SAAI,OACF,WAAW,IAAI,GAAG,IAAI,GAAG,IAAI,OAAO,IAAI,QAAQ,IAAI,OAAO,IAAI,KAAK,GAE/D;AACT;AAEO,SAAS,cACd,MACsD;AACtD,SAAO,CAAC,aAAa,QAAQ,MAAM,QAAQ;AAC7C;AAIO,MAAM,kBAAkB,OAC7B,MACA,aACiC;AACjC,QAAM,MAAM,MAAM,YAAY,MAAM,IAAI;AACxC,SAAI,OACF,WAAW,IAAI,OAAO,IAAI,OAAO,IAAI,OAAO,IAAI,MAAM,GAEjD;AACT,GAEa,wBAAwB,CACnC,SAEO,CAAC,aAAa,gBAAgB,MAAM,QAAQ,GAGxC,gBAAgB,OAC3B,MACA,cACA,aACgC;AAChC,QAAM,MAAM,MAAM,YAAY,MAAM,YAAY;AAChD,SAAI,OACF,WAAW,IAAI,GAAG,IAAI,GAAG,IAAI,OAAO,IAAI,QAAQ,IAAI,OAAO,IAAI,KAAK,GAE/D;AACT;AAEO,SAAS,oBACd,MAC+E;AAC/E,SAAO,CAAC,YAAY,aAAa,cAAc,MAAM,YAAY,QAAQ;AAC3E;",
5
5
  "names": ["node"]
6
6
  }
@@ -15,6 +15,7 @@ var __export = (target, all) => {
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
16
  var index_exports = {};
17
17
  __export(index_exports, {
18
+ LayoutMeasurementController: () => LayoutMeasurementController,
18
19
  createMeasure: () => createMeasure,
19
20
  createMeasureInWindow: () => createMeasureInWindow,
20
21
  createMeasureLayout: () => createMeasureLayout,
@@ -29,18 +30,29 @@ __export(index_exports, {
29
30
  useElementLayout: () => useElementLayout
30
31
  });
31
32
  module.exports = __toCommonJS(index_exports);
32
- var import_constants = require("@tamagui/constants"), import_is_equal_shallow = require("@tamagui/is-equal-shallow"), LayoutHandlers = /* @__PURE__ */ new WeakMap(), Nodes = /* @__PURE__ */ new Set(), IntersectionState = /* @__PURE__ */ new WeakMap(), globalIntersectionObserver = null, strategy = "async";
33
+ var import_jsx_runtime = require("react/jsx-runtime"), import_constants = require("@tamagui/constants"), import_is_equal_shallow = require("@tamagui/is-equal-shallow"), import_react = require("react"), LayoutHandlers = /* @__PURE__ */ new WeakMap(), LayoutDisableKey = /* @__PURE__ */ new WeakMap(), Nodes = /* @__PURE__ */ new Set(), IntersectionState = /* @__PURE__ */ new WeakMap(), DisableLayoutContextValues = {}, DisableLayoutContextKey = /* @__PURE__ */ (0, import_react.createContext)(""), ENABLE = import_constants.isClient && typeof IntersectionObserver < "u", LayoutMeasurementController = function(param) {
34
+ var { disable, children } = param, id = (0, import_react.useId)();
35
+ return (0, import_constants.useIsomorphicLayoutEffect)(function() {
36
+ DisableLayoutContextValues[id] = disable;
37
+ }, [
38
+ disable,
39
+ id
40
+ ]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DisableLayoutContextKey.Provider, {
41
+ value: id,
42
+ children
43
+ });
44
+ }, globalIntersectionObserver = null, strategy = "async";
33
45
  function setOnLayoutStrategy(state) {
34
46
  strategy = state;
35
47
  }
36
- var NodeRectCache = /* @__PURE__ */ new WeakMap(), ParentRectCache = /* @__PURE__ */ new WeakMap(), LastChangeTime = /* @__PURE__ */ new WeakMap(), rAF = typeof window < "u" ? window.requestAnimationFrame : void 0, avoidUpdates = !0, queuedUpdates = /* @__PURE__ */ new Map();
48
+ var NodeRectCache = /* @__PURE__ */ new WeakMap(), LastChangeTime = /* @__PURE__ */ new WeakMap(), avoidUpdates = !0, queuedUpdates = /* @__PURE__ */ new Map();
37
49
  function enable() {
38
50
  avoidUpdates && (avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(function(cb) {
39
51
  return cb();
40
52
  }), queuedUpdates.clear()));
41
53
  }
42
54
  function startGlobalObservers() {
43
- !import_constants.isClient || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(function(entries) {
55
+ !ENABLE || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(function(entries) {
44
56
  entries.forEach(function(entry) {
45
57
  var node = entry.target;
46
58
  IntersectionState.get(node) !== entry.isIntersecting && IntersectionState.set(node, entry.isIntersecting);
@@ -49,95 +61,94 @@ function startGlobalObservers() {
49
61
  threshold: 0
50
62
  }));
51
63
  }
52
- if (import_constants.isClient)
53
- if (rAF) {
54
- var supportsCheckVisibility = "checkVisibility" in document.body, BoundingRects = /* @__PURE__ */ new WeakMap();
55
- async function updateLayoutIfChanged(node) {
56
- if (IntersectionState.get(node) !== !1 && !(process.env.TAMAGUI_ONLAYOUT_VISIBILITY_CHECK === "1" && supportsCheckVisibility && !node.checkVisibility())) {
57
- var onLayout = LayoutHandlers.get(node);
58
- if (typeof onLayout == "function") {
59
- var parentNode = node.parentElement;
60
- if (parentNode) {
61
- var nodeRect, parentRect;
62
- if (strategy === "async") {
63
- var [nr, pr] = await Promise.all([
64
- BoundingRects.get(node) || getBoundingClientRectAsync(node),
65
- BoundingRects.get(parentNode) || getBoundingClientRectAsync(parentNode)
66
- ]);
67
- if (nr === !1 || pr === !1)
68
- return;
69
- nodeRect = nr, parentRect = pr;
70
- } else
71
- nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
72
- var cachedRect = NodeRectCache.get(node), cachedParentRect = NodeRectCache.get(parentNode);
73
- if (!cachedRect || // has changed one rect
74
- // @ts-expect-error DOMRectReadOnly can go into object
75
- !(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) && // @ts-expect-error DOMRectReadOnly can go into object
76
- (!cachedParentRect || !(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect))) {
77
- NodeRectCache.set(node, nodeRect), ParentRectCache.set(parentNode, parentRect);
78
- var event = getElementLayoutEvent(nodeRect, parentRect);
79
- avoidUpdates ? queuedUpdates.set(node, function() {
80
- return onLayout(event);
81
- }) : onLayout(event);
82
- }
64
+ if (ENABLE) {
65
+ var BoundingRects = /* @__PURE__ */ new WeakMap();
66
+ async function updateLayoutIfChanged(node) {
67
+ var onLayout = LayoutHandlers.get(node);
68
+ if (typeof onLayout == "function") {
69
+ var parentNode = node.parentElement;
70
+ if (parentNode) {
71
+ var nodeRect, parentRect;
72
+ if (strategy === "async") {
73
+ var [nr, pr] = await Promise.all([
74
+ BoundingRects.get(node),
75
+ BoundingRects.get(parentNode)
76
+ ]);
77
+ if (!nr || !pr)
78
+ return;
79
+ nodeRect = nr, parentRect = pr;
80
+ } else
81
+ nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
82
+ if (!(!nodeRect || !parentRect)) {
83
+ var cachedRect = NodeRectCache.get(node), cachedParentRect = NodeRectCache.get(parentNode);
84
+ if (!cachedRect || !cachedParentRect || // has changed one rect
85
+ // @ts-expect-error DOMRectReadOnly can go into object
86
+ !(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) || // @ts-expect-error DOMRectReadOnly can go into object
87
+ !(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect)) {
88
+ NodeRectCache.set(node, nodeRect), NodeRectCache.set(parentNode, parentRect);
89
+ var event = getElementLayoutEvent(nodeRect, parentRect);
90
+ avoidUpdates ? queuedUpdates.set(node, function() {
91
+ return onLayout(event);
92
+ }) : onLayout(event);
83
93
  }
84
94
  }
85
95
  }
86
96
  }
87
- rAF(layoutOnAnimationFrame);
88
- var frameCount = 0, userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP, RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 10;
89
- async function layoutOnAnimationFrame() {
90
- if (strategy !== "off") {
91
- if (!Nodes.size || frameCount++ % RUN_EVERY_X_FRAMES !== 0) {
92
- rAF(layoutOnAnimationFrame);
93
- return;
94
- }
95
- frameCount === Number.MAX_SAFE_INTEGER && (frameCount = 0), await new Promise(function(res) {
96
- var io = new IntersectionObserver(function(entries) {
97
- io.disconnect();
98
- var _iteratorNormalCompletion2 = !0, _didIteratorError2 = !1, _iteratorError2 = void 0;
99
- try {
100
- for (var _iterator2 = entries[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
101
- var entry = _step2.value;
102
- BoundingRects.set(entry.target, entry.boundingClientRect);
103
- }
104
- } catch (err) {
105
- _didIteratorError2 = !0, _iteratorError2 = err;
106
- } finally {
107
- try {
108
- !_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
109
- } finally {
110
- if (_didIteratorError2)
111
- throw _iteratorError2;
112
- }
113
- }
114
- res();
115
- }, {
116
- threshold: 0
117
- }), _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
97
+ }
98
+ var userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP, RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 14;
99
+ async function layoutOnAnimationFrame() {
100
+ if (strategy !== "off") {
101
+ var visibleNodes = [], didRun = await new Promise(function(res) {
102
+ var io = new IntersectionObserver(function(entries) {
103
+ io.disconnect();
104
+ var _iteratorNormalCompletion2 = !0, _didIteratorError2 = !1, _iteratorError2 = void 0;
118
105
  try {
119
- for (var _iterator = Nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
120
- var node = _step.value;
121
- node.parentElement instanceof HTMLElement && (io.observe(node), io.observe(node.parentElement));
106
+ for (var _iterator2 = entries[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
107
+ var entry = _step2.value;
108
+ BoundingRects.set(entry.target, entry.boundingClientRect);
122
109
  }
123
110
  } catch (err) {
124
- _didIteratorError = !0, _iteratorError = err;
111
+ _didIteratorError2 = !0, _iteratorError2 = err;
125
112
  } finally {
126
113
  try {
127
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
114
+ !_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
128
115
  } finally {
129
- if (_didIteratorError)
130
- throw _iteratorError;
116
+ if (_didIteratorError2)
117
+ throw _iteratorError2;
131
118
  }
132
119
  }
133
- }), Nodes.forEach(function(node) {
134
- updateLayoutIfChanged(node);
135
- });
136
- }
137
- rAF(layoutOnAnimationFrame);
120
+ res(!0);
121
+ }, {
122
+ threshold: 0
123
+ }), didObserve = !1, _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
124
+ try {
125
+ for (var _iterator = Nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
126
+ var node = _step.value;
127
+ if (node.parentElement instanceof HTMLElement) {
128
+ var disableKey = LayoutDisableKey.get(node);
129
+ disableKey && DisableLayoutContextValues[disableKey] === !0 || IntersectionState.get(node) !== !1 && (didObserve = !0, io.observe(node), io.observe(node.parentElement), visibleNodes.push(node));
130
+ }
131
+ }
132
+ } catch (err) {
133
+ _didIteratorError = !0, _iteratorError = err;
134
+ } finally {
135
+ try {
136
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
137
+ } finally {
138
+ if (_didIteratorError)
139
+ throw _iteratorError;
140
+ }
141
+ }
142
+ didObserve || res(!1);
143
+ });
144
+ didRun && visibleNodes.forEach(function(node) {
145
+ updateLayoutIfChanged(node);
146
+ });
138
147
  }
139
- } else
140
- process.env.NODE_ENV === "development" && console.warn("No requestAnimationFrame - please polyfill for onLayout to work correctly");
148
+ setTimeout(layoutOnAnimationFrame, 16.6667 * RUN_EVERY_X_FRAMES);
149
+ }
150
+ layoutOnAnimationFrame();
151
+ }
141
152
  var getElementLayoutEvent = function(nodeRect, parentRect) {
142
153
  return {
143
154
  nativeEvent: {
@@ -158,8 +169,8 @@ var getElementLayoutEvent = function(nodeRect, parentRect) {
158
169
  };
159
170
  };
160
171
  function useElementLayout(ref, onLayout) {
161
- var _ref_current, node = ensureWebElement((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.host);
162
- node && onLayout && LayoutHandlers.set(node, onLayout), (0, import_constants.useIsomorphicLayoutEffect)(function() {
172
+ var _ref_current, disableKey = (0, import_react.useContext)(DisableLayoutContextKey), node = ensureWebElement((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.host);
173
+ node && onLayout && (LayoutHandlers.set(node, onLayout), LayoutDisableKey.set(node, disableKey)), (0, import_constants.useIsomorphicLayoutEffect)(function() {
163
174
  var _ref_current2;
164
175
  if (onLayout) {
165
176
  var node2 = (_ref_current2 = ref.current) === null || _ref_current2 === void 0 ? void 0 : _ref_current2.host;
@@ -228,6 +239,7 @@ function createMeasureLayout(node) {
228
239
  }
229
240
  // Annotate the CommonJS export names for ESM import in node:
230
241
  0 && (module.exports = {
242
+ LayoutMeasurementController,
231
243
  createMeasure,
232
244
  createMeasureInWindow,
233
245
  createMeasureLayout,