@sheinx/hooks 3.9.10-beta.5 → 3.9.10

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.
@@ -28,7 +28,7 @@ var useResize = exports.useResize = function useResize(props) {
28
28
  (0, _react.useEffect)(function () {
29
29
  if (!targetRef.current) return;
30
30
  var el = targetRef.current;
31
- if (el) {
31
+ if (el && el.offsetParent !== null) {
32
32
  setWidth(el.clientWidth);
33
33
  setHeight(el.clientHeight);
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"element.d.ts","sourceRoot":"","sources":["element.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,WAAW,UAAQ,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,KAAK,CAAC,SAAS,CASjB;AAGD,eAAO,MAAM,iBAAiB,OACxB,WAAW,WACN,GAAG;;;;gBAqDb,CAAC;AAEF,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,kBAmBxF;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,WAAW,WAW3C;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAqBzF;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,EACrC,SAAS,GAAE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,EAA0B,sBAuBrE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAAmB,EAAE,KAAK,EAAE,MAAM,WAYxE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,UAM7C;AAED,eAAO,MAAM,eAAe,QAAS,MAAM,WAAwC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69,43 +69,39 @@ var addResizeObserver = exports.addResizeObserver = function addResizeObserver(e
69
69
  _debounce2 = _slicedToArray(_debounce, 2),
70
70
  debounceHandler = _debounce2[0],
71
71
  cleanTimer = _debounce2[1];
72
- var h = debounceHandler;
73
- var lastWidth;
74
- var lastHeight;
72
+ var lastWidth = el.clientWidth;
73
+ var lastHeight = el.clientHeight;
75
74
  if (window.ResizeObserver) {
76
- if (direction) {
77
- lastWidth = el.clientWidth;
78
- lastHeight = el.clientHeight;
79
- h = function h(entry) {
80
- if ((el === null || el === void 0 ? void 0 : el.offsetParent) === null) {
81
- options.lazy && el.setAttribute('data-observer-hidden', 'true');
82
- return;
83
- }
84
- if (options.lazy && el.getAttribute('data-observer-hidden') === 'true') {
85
- el.removeAttribute('data-observer-hidden');
86
- return;
75
+ var h = function h(entry) {
76
+ var _entry$0$contentRect = entry[0].contentRect,
77
+ width = _entry$0$contentRect.width,
78
+ height = _entry$0$contentRect.height;
79
+ // 元素不可见(display:none)时跳过:offsetParent null 且尺寸为 0
80
+ if ((el === null || el === void 0 ? void 0 : el.offsetParent) === null && !width && !height) {
81
+ options.lazy && el.setAttribute('data-observer-hidden', 'true');
82
+ return;
83
+ }
84
+ if (options.lazy && el.getAttribute('data-observer-hidden') === 'true') {
85
+ el.removeAttribute('data-observer-hidden');
86
+ return;
87
+ }
88
+ if (width && direction === 'x') {
89
+ if (lastWidth !== width) {
90
+ debounceHandler(entry);
87
91
  }
88
- var _entry$0$contentRect = entry[0].contentRect,
89
- width = _entry$0$contentRect.width,
90
- height = _entry$0$contentRect.height;
91
- if (width && direction === 'x') {
92
- if (lastWidth !== width) {
93
- debounceHandler(entry);
94
- }
95
- } else if (direction === 'y') {
96
- if (height && lastHeight !== height) {
97
- debounceHandler(entry);
98
- }
99
- } else if (lastWidth !== width || lastHeight !== height) {
100
- debounceHandler(entry, {
101
- x: lastWidth !== width,
102
- y: lastHeight !== height
103
- });
92
+ } else if (direction === 'y') {
93
+ if (height && lastHeight !== height) {
94
+ debounceHandler(entry);
104
95
  }
105
- lastWidth = width;
106
- lastHeight = height;
107
- };
108
- }
96
+ } else if (lastWidth !== width || lastHeight !== height) {
97
+ debounceHandler(entry, {
98
+ x: lastWidth !== width,
99
+ y: lastHeight !== height
100
+ });
101
+ }
102
+ lastWidth = width;
103
+ lastHeight = height;
104
+ };
109
105
  var observer = new ResizeObserver(h);
110
106
  observer.observe(el);
111
107
  return function () {
@@ -22,7 +22,7 @@ export var useResize = function useResize(props) {
22
22
  useEffect(function () {
23
23
  if (!targetRef.current) return;
24
24
  var el = targetRef.current;
25
- if (el) {
25
+ if (el && el.offsetParent !== null) {
26
26
  setWidth(el.clientWidth);
27
27
  setHeight(el.clientHeight);
28
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"element.d.ts","sourceRoot":"","sources":["element.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,WAAW,UAAQ,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,KAAK,CAAC,SAAS,CASjB;AAGD,eAAO,MAAM,iBAAiB,OACxB,WAAW,WACN,GAAG;;;;gBAqDb,CAAC;AAEF,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,kBAmBxF;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,WAAW,WAW3C;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAqBzF;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,EACrC,SAAS,GAAE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,EAA0B,sBAuBrE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,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AAGD,eAAO,MAAM,UAAU,UAAW,MAAM,aAAa,MAAM,uBAG1D,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,MAAM,aAAa,MAAM,WAG9D,CAAC"}
@@ -53,43 +53,39 @@ export var addResizeObserver = function addResizeObserver(el, handler) {
53
53
  _debounce2 = _slicedToArray(_debounce, 2),
54
54
  debounceHandler = _debounce2[0],
55
55
  cleanTimer = _debounce2[1];
56
- var h = debounceHandler;
57
- var lastWidth;
58
- var lastHeight;
56
+ var lastWidth = el.clientWidth;
57
+ var lastHeight = el.clientHeight;
59
58
  if (window.ResizeObserver) {
60
- if (direction) {
61
- lastWidth = el.clientWidth;
62
- lastHeight = el.clientHeight;
63
- h = function h(entry) {
64
- if ((el === null || el === void 0 ? void 0 : el.offsetParent) === null) {
65
- options.lazy && el.setAttribute('data-observer-hidden', 'true');
66
- return;
67
- }
68
- if (options.lazy && el.getAttribute('data-observer-hidden') === 'true') {
69
- el.removeAttribute('data-observer-hidden');
70
- return;
59
+ var h = function h(entry) {
60
+ var _entry$0$contentRect = entry[0].contentRect,
61
+ width = _entry$0$contentRect.width,
62
+ height = _entry$0$contentRect.height;
63
+ // 元素不可见(display:none)时跳过:offsetParent null 且尺寸为 0
64
+ if ((el === null || el === void 0 ? void 0 : el.offsetParent) === null && !width && !height) {
65
+ options.lazy && el.setAttribute('data-observer-hidden', 'true');
66
+ return;
67
+ }
68
+ if (options.lazy && el.getAttribute('data-observer-hidden') === 'true') {
69
+ el.removeAttribute('data-observer-hidden');
70
+ return;
71
+ }
72
+ if (width && direction === 'x') {
73
+ if (lastWidth !== width) {
74
+ debounceHandler(entry);
71
75
  }
72
- var _entry$0$contentRect = entry[0].contentRect,
73
- width = _entry$0$contentRect.width,
74
- height = _entry$0$contentRect.height;
75
- if (width && direction === 'x') {
76
- if (lastWidth !== width) {
77
- debounceHandler(entry);
78
- }
79
- } else if (direction === 'y') {
80
- if (height && lastHeight !== height) {
81
- debounceHandler(entry);
82
- }
83
- } else if (lastWidth !== width || lastHeight !== height) {
84
- debounceHandler(entry, {
85
- x: lastWidth !== width,
86
- y: lastHeight !== height
87
- });
76
+ } else if (direction === 'y') {
77
+ if (height && lastHeight !== height) {
78
+ debounceHandler(entry);
88
79
  }
89
- lastWidth = width;
90
- lastHeight = height;
91
- };
92
- }
80
+ } else if (lastWidth !== width || lastHeight !== height) {
81
+ debounceHandler(entry, {
82
+ x: lastWidth !== width,
83
+ y: lastHeight !== height
84
+ });
85
+ }
86
+ lastWidth = width;
87
+ lastHeight = height;
88
+ };
93
89
  var observer = new ResizeObserver(h);
94
90
  observer.observe(el);
95
91
  return function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.9.10-beta.5",
3
+ "version": "3.9.10",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",