@tamagui/core 1.134.5 → 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.
@@ -11659,6 +11659,9 @@ var require_index_native12 = __commonJS({
11659
11659
  }), mod);
11660
11660
  }, index_exports2 = {};
11661
11661
  __export2(index_exports2, {
11662
+ LayoutMeasurementController: function() {
11663
+ return LayoutMeasurementController2;
11664
+ },
11662
11665
  createMeasure: function() {
11663
11666
  return createMeasure2;
11664
11667
  },
@@ -11697,18 +11700,29 @@ var require_index_native12 = __commonJS({
11697
11700
  }
11698
11701
  });
11699
11702
  module2.exports = __toCommonJS2(index_exports2);
11700
- var import_constants = require_index_native2(), import_is_equal_shallow = require_index_native5(), LayoutHandlers = /* @__PURE__ */ new WeakMap(), Nodes = /* @__PURE__ */ new Set(), IntersectionState = /* @__PURE__ */ new WeakMap(), globalIntersectionObserver = null, strategy = "async";
11703
+ var import_jsx_runtime2 = require("react/jsx-runtime"), import_constants = require_index_native2(), import_is_equal_shallow = require_index_native5(), import_react3 = require("react"), LayoutHandlers = /* @__PURE__ */ new WeakMap(), LayoutDisableKey = /* @__PURE__ */ new WeakMap(), Nodes = /* @__PURE__ */ new Set(), IntersectionState = /* @__PURE__ */ new WeakMap(), DisableLayoutContextValues = {}, DisableLayoutContextKey = /* @__PURE__ */ (0, import_react3.createContext)(""), ENABLE = import_constants.isClient && typeof IntersectionObserver < "u", LayoutMeasurementController2 = function(param) {
11704
+ var { disable, children } = param, id = (0, import_react3.useId)();
11705
+ return (0, import_constants.useIsomorphicLayoutEffect)(function() {
11706
+ DisableLayoutContextValues[id] = disable;
11707
+ }, [
11708
+ disable,
11709
+ id
11710
+ ]), /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DisableLayoutContextKey.Provider, {
11711
+ value: id,
11712
+ children
11713
+ });
11714
+ }, globalIntersectionObserver = null, strategy = "async";
11701
11715
  function setOnLayoutStrategy2(state) {
11702
11716
  strategy = state;
11703
11717
  }
11704
- 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();
11718
+ var NodeRectCache = /* @__PURE__ */ new WeakMap(), LastChangeTime = /* @__PURE__ */ new WeakMap(), avoidUpdates = !0, queuedUpdates = /* @__PURE__ */ new Map();
11705
11719
  function enable2() {
11706
11720
  avoidUpdates && (avoidUpdates = !1, queuedUpdates && (queuedUpdates.forEach(function(cb) {
11707
11721
  return cb();
11708
11722
  }), queuedUpdates.clear()));
11709
11723
  }
11710
11724
  function startGlobalObservers() {
11711
- !import_constants.isClient || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(function(entries) {
11725
+ !ENABLE || globalIntersectionObserver || (globalIntersectionObserver = new IntersectionObserver(function(entries) {
11712
11726
  entries.forEach(function(entry) {
11713
11727
  var node = entry.target;
11714
11728
  IntersectionState.get(node) !== entry.isIntersecting && IntersectionState.set(node, entry.isIntersecting);
@@ -11717,29 +11731,29 @@ var require_index_native12 = __commonJS({
11717
11731
  threshold: 0
11718
11732
  }));
11719
11733
  }
11720
- if (import_constants.isClient && rAF) {
11721
- supportsCheckVisibility = "checkVisibility" in document.body, BoundingRects = /* @__PURE__ */ new WeakMap();
11734
+ if (ENABLE) {
11735
+ BoundingRects = /* @__PURE__ */ new WeakMap();
11722
11736
  async function updateLayoutIfChanged(node) {
11723
- if (IntersectionState.get(node) !== !1 && !(process.env.TAMAGUI_ONLAYOUT_VISIBILITY_CHECK === "1" && supportsCheckVisibility && !node.checkVisibility())) {
11724
- var onLayout = LayoutHandlers.get(node);
11725
- if (typeof onLayout == "function") {
11726
- var parentNode = node.parentElement;
11727
- if (parentNode) {
11728
- var nodeRect, parentRect;
11729
- if (strategy === "async") {
11730
- var [nr, pr] = await Promise.all([
11731
- BoundingRects.get(node) || getBoundingClientRectAsync(node),
11732
- BoundingRects.get(parentNode) || getBoundingClientRectAsync(parentNode)
11733
- ]);
11734
- if (nr === !1 || pr === !1) return;
11735
- nodeRect = nr, parentRect = pr;
11736
- } else nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
11737
+ var onLayout = LayoutHandlers.get(node);
11738
+ if (typeof onLayout == "function") {
11739
+ var parentNode = node.parentElement;
11740
+ if (parentNode) {
11741
+ var nodeRect, parentRect;
11742
+ if (strategy === "async") {
11743
+ var [nr, pr] = await Promise.all([
11744
+ BoundingRects.get(node),
11745
+ BoundingRects.get(parentNode)
11746
+ ]);
11747
+ if (!nr || !pr) return;
11748
+ nodeRect = nr, parentRect = pr;
11749
+ } else nodeRect = node.getBoundingClientRect(), parentRect = parentNode.getBoundingClientRect();
11750
+ if (!(!nodeRect || !parentRect)) {
11737
11751
  var cachedRect = NodeRectCache.get(node), cachedParentRect = NodeRectCache.get(parentNode);
11738
- if (!cachedRect || // has changed one rect
11752
+ if (!cachedRect || !cachedParentRect || // has changed one rect
11739
11753
  // @ts-expect-error DOMRectReadOnly can go into object
11740
- !(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) && // @ts-expect-error DOMRectReadOnly can go into object
11741
- (!cachedParentRect || !(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect))) {
11742
- NodeRectCache.set(node, nodeRect), ParentRectCache.set(parentNode, parentRect);
11754
+ !(0, import_is_equal_shallow.isEqualShallow)(cachedRect, nodeRect) || // @ts-expect-error DOMRectReadOnly can go into object
11755
+ !(0, import_is_equal_shallow.isEqualShallow)(cachedParentRect, parentRect)) {
11756
+ NodeRectCache.set(node, nodeRect), NodeRectCache.set(parentNode, parentRect);
11743
11757
  var event = getElementLayoutEvent(nodeRect, parentRect);
11744
11758
  avoidUpdates ? queuedUpdates.set(node, function() {
11745
11759
  return onLayout(event);
@@ -11749,14 +11763,10 @@ var require_index_native12 = __commonJS({
11749
11763
  }
11750
11764
  }
11751
11765
  }
11752
- rAF(layoutOnAnimationFrame), frameCount = 0, userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP, RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 10;
11766
+ userSkipVal = process.env.TAMAGUI_LAYOUT_FRAME_SKIP, RUN_EVERY_X_FRAMES = userSkipVal ? +userSkipVal : 14;
11753
11767
  async function layoutOnAnimationFrame() {
11754
11768
  if (strategy !== "off") {
11755
- if (!Nodes.size || frameCount++ % RUN_EVERY_X_FRAMES !== 0) {
11756
- rAF(layoutOnAnimationFrame);
11757
- return;
11758
- }
11759
- frameCount === Number.MAX_SAFE_INTEGER && (frameCount = 0), await new Promise(function(res) {
11769
+ var visibleNodes = [], didRun = await new Promise(function(res) {
11760
11770
  var io = new IntersectionObserver(function(entries) {
11761
11771
  io.disconnect();
11762
11772
  var _iteratorNormalCompletion2 = !0, _didIteratorError2 = !1, _iteratorError2 = void 0;
@@ -11774,14 +11784,17 @@ var require_index_native12 = __commonJS({
11774
11784
  if (_didIteratorError2) throw _iteratorError2;
11775
11785
  }
11776
11786
  }
11777
- res();
11787
+ res(!0);
11778
11788
  }, {
11779
11789
  threshold: 0
11780
- }), _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
11790
+ }), didObserve = !1, _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
11781
11791
  try {
11782
11792
  for (var _iterator = Nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
11783
11793
  var node = _step.value;
11784
- node.parentElement instanceof HTMLElement && (io.observe(node), io.observe(node.parentElement));
11794
+ if (node.parentElement instanceof HTMLElement) {
11795
+ var disableKey = LayoutDisableKey.get(node);
11796
+ disableKey && DisableLayoutContextValues[disableKey] === !0 || IntersectionState.get(node) !== !1 && (didObserve = !0, io.observe(node), io.observe(node.parentElement), visibleNodes.push(node));
11797
+ }
11785
11798
  }
11786
11799
  } catch (err) {
11787
11800
  _didIteratorError = !0, _iteratorError = err;
@@ -11792,14 +11805,17 @@ var require_index_native12 = __commonJS({
11792
11805
  if (_didIteratorError) throw _iteratorError;
11793
11806
  }
11794
11807
  }
11795
- }), Nodes.forEach(function(node) {
11808
+ didObserve || res(!1);
11809
+ });
11810
+ didRun && visibleNodes.forEach(function(node) {
11796
11811
  updateLayoutIfChanged(node);
11797
11812
  });
11798
11813
  }
11799
- rAF(layoutOnAnimationFrame);
11814
+ setTimeout(layoutOnAnimationFrame, 16.6667 * RUN_EVERY_X_FRAMES);
11800
11815
  }
11816
+ layoutOnAnimationFrame();
11801
11817
  }
11802
- var supportsCheckVisibility, BoundingRects, frameCount, userSkipVal, RUN_EVERY_X_FRAMES, getElementLayoutEvent = function(nodeRect, parentRect) {
11818
+ var BoundingRects, userSkipVal, RUN_EVERY_X_FRAMES, getElementLayoutEvent = function(nodeRect, parentRect) {
11803
11819
  return {
11804
11820
  nativeEvent: {
11805
11821
  layout: getRelativeDimensions(nodeRect, parentRect),
@@ -11819,8 +11835,8 @@ var require_index_native12 = __commonJS({
11819
11835
  };
11820
11836
  };
11821
11837
  function useElementLayout2(ref, onLayout) {
11822
- var _ref_current, node = ensureWebElement((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.host);
11823
- node && onLayout && LayoutHandlers.set(node, onLayout), (0, import_constants.useIsomorphicLayoutEffect)(function() {
11838
+ var _ref_current, disableKey = (0, import_react3.useContext)(DisableLayoutContextKey), node = ensureWebElement((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.host);
11839
+ node && onLayout && (LayoutHandlers.set(node, onLayout), LayoutDisableKey.set(node, disableKey)), (0, import_constants.useIsomorphicLayoutEffect)(function() {
11824
11840
  var _ref_current2;
11825
11841
  if (onLayout) {
11826
11842
  var node2 = (_ref_current2 = ref.current) === null || _ref_current2 === void 0 ? void 0 : _ref_current2.host;
@@ -11904,6 +11920,7 @@ var init_idFn = __esm({
11904
11920
  // src/index.tsx
11905
11921
  var index_exports = {};
11906
11922
  __export(index_exports, {
11923
+ LayoutMeasurementController: () => import_use_element_layout2.LayoutMeasurementController,
11907
11924
  Stack: () => Stack,
11908
11925
  TamaguiProvider: () => TamaguiProvider,
11909
11926
  Text: () => Text,
@@ -12197,6 +12214,7 @@ var dontComposePressabilityKeys = {
12197
12214
  }, View = import_web.View, Stack = import_web.Stack, Text = import_web.Text;
12198
12215
  // Annotate the CommonJS export names for ESM import in node:
12199
12216
  0 && (module.exports = {
12217
+ LayoutMeasurementController,
12200
12218
  Stack,
12201
12219
  TamaguiProvider,
12202
12220
  Text,