@sheinx/hooks 3.5.0-beta.1 → 3.5.0-beta.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. package/cjs/common/use-in-view/index.d.ts +2 -0
  2. package/cjs/common/use-in-view/index.d.ts.map +1 -0
  3. package/cjs/common/use-in-view/index.js +14 -0
  4. package/cjs/common/use-in-view/use-in-view.d.ts +14 -0
  5. package/cjs/common/use-in-view/use-in-view.d.ts.map +1 -0
  6. package/cjs/common/use-in-view/use-in-view.js +73 -0
  7. package/cjs/common/use-position-style/check-position.d.ts +11 -0
  8. package/cjs/common/use-position-style/check-position.d.ts.map +1 -0
  9. package/cjs/common/use-position-style/check-position.js +90 -0
  10. package/cjs/common/use-position-style/index.d.ts.map +1 -1
  11. package/cjs/common/use-position-style/index.js +15 -21
  12. package/cjs/components/use-form/index.d.ts +1 -0
  13. package/cjs/components/use-form/index.d.ts.map +1 -1
  14. package/cjs/components/use-form/index.js +12 -0
  15. package/cjs/components/use-form/use-form-context.d.ts +6 -0
  16. package/cjs/components/use-form/use-form-context.d.ts.map +1 -0
  17. package/cjs/components/use-form/use-form-context.js +22 -0
  18. package/cjs/components/use-form/use-form-context.type.d.ts +45 -0
  19. package/cjs/components/use-form/use-form-context.type.d.ts.map +1 -0
  20. package/cjs/components/use-form/use-form-context.type.js +5 -0
  21. package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  22. package/cjs/components/use-form/use-form-control/use-form-control.js +30 -11
  23. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  24. package/cjs/components/use-form/use-form.js +4 -2
  25. package/cjs/components/use-form/use-form.type.d.ts +7 -0
  26. package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
  27. package/cjs/components/use-image/use-image.d.ts.map +1 -1
  28. package/cjs/components/use-image/use-image.js +7 -0
  29. package/cjs/components/use-image/use-image.type.d.ts +7 -0
  30. package/cjs/components/use-image/use-image.type.d.ts.map +1 -1
  31. package/cjs/components/use-input/use-input-format.d.ts +1 -1
  32. package/cjs/components/use-input/use-input-number.d.ts +1 -1
  33. package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
  34. package/cjs/components/use-input/use-input-number.js +5 -0
  35. package/cjs/components/use-table/use-table-group.d.ts.map +1 -1
  36. package/cjs/components/use-table/use-table-group.js +2 -1
  37. package/cjs/components/use-table/use-table-layout.d.ts.map +1 -1
  38. package/cjs/components/use-table/use-table-layout.js +2 -1
  39. package/cjs/components/use-table/use-table.type.d.ts +26 -0
  40. package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
  41. package/cjs/index.d.ts +1 -0
  42. package/cjs/index.d.ts.map +1 -1
  43. package/cjs/index.js +12 -0
  44. package/cjs/utils/dom/document.d.ts +2 -0
  45. package/cjs/utils/dom/document.d.ts.map +1 -0
  46. package/cjs/utils/dom/document.js +49 -0
  47. package/cjs/utils/dom/element.d.ts +1 -1
  48. package/cjs/utils/dom/element.d.ts.map +1 -1
  49. package/cjs/utils/dom/index.d.ts +1 -0
  50. package/cjs/utils/dom/index.d.ts.map +1 -1
  51. package/cjs/utils/dom/index.js +12 -0
  52. package/cjs/utils/is.d.ts +0 -1
  53. package/cjs/utils/is.d.ts.map +1 -1
  54. package/cjs/utils/is.js +1 -10
  55. package/cjs/utils/lazyload.d.ts +1 -0
  56. package/cjs/utils/lazyload.d.ts.map +1 -1
  57. package/cjs/utils/lazyload.js +3 -0
  58. package/esm/common/use-in-view/index.d.ts +2 -0
  59. package/esm/common/use-in-view/index.d.ts.map +1 -0
  60. package/esm/common/use-in-view/index.js +2 -0
  61. package/esm/common/use-in-view/use-in-view.d.ts +14 -0
  62. package/esm/common/use-in-view/use-in-view.d.ts.map +1 -0
  63. package/esm/common/use-in-view/use-in-view.js +70 -0
  64. package/esm/common/use-position-style/check-position.d.ts +11 -0
  65. package/esm/common/use-position-style/check-position.d.ts.map +1 -0
  66. package/esm/common/use-position-style/check-position.js +84 -0
  67. package/esm/common/use-position-style/index.d.ts.map +1 -1
  68. package/esm/common/use-position-style/index.js +17 -22
  69. package/esm/components/use-form/index.d.ts +1 -0
  70. package/esm/components/use-form/index.d.ts.map +1 -1
  71. package/esm/components/use-form/index.js +1 -0
  72. package/esm/components/use-form/use-form-context.d.ts +6 -0
  73. package/esm/components/use-form/use-form-context.d.ts.map +1 -0
  74. package/esm/components/use-form/use-form-context.js +13 -0
  75. package/esm/components/use-form/use-form-context.type.d.ts +45 -0
  76. package/esm/components/use-form/use-form-context.type.d.ts.map +1 -0
  77. package/esm/components/use-form/use-form-context.type.js +1 -0
  78. package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  79. package/esm/components/use-form/use-form-control/use-form-control.js +30 -11
  80. package/esm/components/use-form/use-form.d.ts.map +1 -1
  81. package/esm/components/use-form/use-form.js +4 -2
  82. package/esm/components/use-form/use-form.type.d.ts +7 -0
  83. package/esm/components/use-form/use-form.type.d.ts.map +1 -1
  84. package/esm/components/use-image/use-image.d.ts.map +1 -1
  85. package/esm/components/use-image/use-image.js +7 -0
  86. package/esm/components/use-image/use-image.type.d.ts +7 -0
  87. package/esm/components/use-image/use-image.type.d.ts.map +1 -1
  88. package/esm/components/use-input/use-input-format.d.ts +1 -1
  89. package/esm/components/use-input/use-input-number.d.ts +1 -1
  90. package/esm/components/use-input/use-input-number.d.ts.map +1 -1
  91. package/esm/components/use-input/use-input-number.js +5 -0
  92. package/esm/components/use-table/use-table-group.d.ts.map +1 -1
  93. package/esm/components/use-table/use-table-group.js +3 -2
  94. package/esm/components/use-table/use-table-layout.d.ts.map +1 -1
  95. package/esm/components/use-table/use-table-layout.js +2 -1
  96. package/esm/components/use-table/use-table.type.d.ts +26 -0
  97. package/esm/components/use-table/use-table.type.d.ts.map +1 -1
  98. package/esm/index.d.ts +1 -0
  99. package/esm/index.d.ts.map +1 -1
  100. package/esm/index.js +1 -0
  101. package/esm/utils/dom/document.d.ts +2 -0
  102. package/esm/utils/dom/document.d.ts.map +1 -0
  103. package/esm/utils/dom/document.js +43 -0
  104. package/esm/utils/dom/element.d.ts +1 -1
  105. package/esm/utils/dom/element.d.ts.map +1 -1
  106. package/esm/utils/dom/index.d.ts +1 -0
  107. package/esm/utils/dom/index.d.ts.map +1 -1
  108. package/esm/utils/dom/index.js +1 -0
  109. package/esm/utils/is.d.ts +0 -1
  110. package/esm/utils/is.d.ts.map +1 -1
  111. package/esm/utils/is.js +0 -9
  112. package/esm/utils/lazyload.d.ts +1 -0
  113. package/esm/utils/lazyload.d.ts.map +1 -1
  114. package/esm/utils/lazyload.js +3 -0
  115. package/package.json +1 -1
@@ -5,7 +5,7 @@ declare const useInputFormat: (props: InputFormatProps) => {
5
5
  onBlur: (e: React.FocusEvent) => void;
6
6
  onFocus: (e: React.FocusEvent) => void;
7
7
  value: string | undefined;
8
- type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "checkbox" | "radio" | "hidden" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
8
+ type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "hidden" | "checkbox" | "radio" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
9
9
  };
10
10
  export default useInputFormat;
11
11
  //# sourceMappingURL=use-input-format.d.ts.map
@@ -7,7 +7,7 @@ declare const useNumberFormat: (props: InputNumberProps) => {
7
7
  onBlur: (e: React.FocusEvent<Element, Element>) => void;
8
8
  onFocus: (e: React.FocusEvent<Element, Element>) => void;
9
9
  value: string | undefined;
10
- type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "checkbox" | "radio" | "hidden" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
10
+ type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "hidden" | "checkbox" | "radio" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
11
11
  };
12
12
  export default useNumberFormat;
13
13
  //# sourceMappingURL=use-input-number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CAkJ/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CAuJ/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -76,6 +76,11 @@ var useNumberFormat = function useNumberFormat(props) {
76
76
  setInternalInputValue(getStringValue(val));
77
77
  if (typeof val === 'string') {
78
78
  var num = parseFloat(val);
79
+ if (val === '') {
80
+ // 如果允许空值,则返回 null,否则返回 undefined
81
+ onChange === null || onChange === void 0 || onChange(allowNull ? null : undefined);
82
+ return;
83
+ }
79
84
  if (isNaN(num)) return;
80
85
  onChange === null || onChange === void 0 || onChange(num);
81
86
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-group.d.ts","sourceRoot":"","sources":["use-table-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAoB,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKxF,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AACD,QAAA,MAAM,aAAa,UAAW,kBAAkB;;;CAoE/C,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"use-table-group.d.ts","sourceRoot":"","sources":["use-table-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAoB,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKxF,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AACD,QAAA,MAAM,aAAa,UAAW,kBAAkB;;;CAsE/C,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -59,8 +59,9 @@ var useTableGroup = function useTableGroup(props) {
59
59
  });
60
60
  return columns;
61
61
  };
62
+ var groupColumns = (0, _react.useMemo)(formatColumns, [props.columns]);
62
63
  return {
63
- groupColumns: formatColumns(),
64
+ groupColumns: groupColumns,
64
65
  columnLevel: context.columnLevel
65
66
  };
66
67
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-layout.d.ts","sourceRoot":"","sources":["use-table-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAKlE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAerE,MAAM,WAAW,mBACf,SAAQ,IAAI,CACV,cAAc,CAAC,GAAG,CAAC,EACnB,MAAM,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAC7E;IACD,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,cAAc,UAAW,mBAAmB;;;;;;;;;;;yBA+CX,MAAM,UAAU,MAAM;;;;;;;;CAmO5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"use-table-layout.d.ts","sourceRoot":"","sources":["use-table-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAKlE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAerE,MAAM,WAAW,mBACf,SAAQ,IAAI,CACV,cAAc,CAAC,GAAG,CAAC,EACnB,MAAM,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAC7E;IACD,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,cAAc,UAAW,mBAAmB;;;;;;;;;;;yBA+CX,MAAM,UAAU,MAAM;;;;;;;;CAsO5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -347,6 +347,7 @@ var useTableLayout = function useTableLayout(props) {
347
347
  checkScroll();
348
348
  checkFloat();
349
349
  }, [colgroup]);
350
+ var tableWidth = isNaN(Number(props.width)) ? undefined : typeof props.width === 'number' ? props.width + deltaXSum : props.width;
350
351
  return {
351
352
  isScrollX: !!isScrollX,
352
353
  isScrollY: !!isScrollY,
@@ -355,7 +356,7 @@ var useTableLayout = function useTableLayout(props) {
355
356
  scrollBarWidth: scrollBarWidth,
356
357
  colgroup: colgroup ? colgroup : [],
357
358
  func: func,
358
- width: typeof props.width === 'number' ? props.width + deltaXSum : props.width,
359
+ width: tableWidth,
359
360
  shouldLastColAuto: props.columnResizable && !adjust,
360
361
  scrollWidth: scrollWidth,
361
362
  maxScrollLeft: scrollWidth - context.clientWidth,
@@ -31,6 +31,18 @@ export interface BaseTableProps<Item> {
31
31
  * @cn 树形数据展开行,受控
32
32
  */
33
33
  treeExpandKeys?: KeygenResult[];
34
+ /**
35
+ * @en Tree Table expand icon
36
+ * @cn 树形数据展开图标,函数返回null时隐藏展开图标
37
+ * @version 3.5.0
38
+ */
39
+ treeExpandIcon?: (data: Item, index: number, isExpanded: boolean) => React.ReactNode;
40
+ /**
41
+ * @en Tree Table data loader
42
+ * @cn 树形数据加载函数
43
+ * @version 3.5.0
44
+ */
45
+ loader?: (data: Item, index: number) => Promise<void>;
34
46
  /**
35
47
  * @en data
36
48
  * @cn 数据
@@ -54,6 +66,13 @@ export interface BaseTableProps<Item> {
54
66
  * @cn 排序取消事件
55
67
  */
56
68
  onSortCancel?: (preType: 'asc' | 'desc', key: KeygenResult, orders: SortItem[], sorter: string) => void;
69
+ /**
70
+ * @en sort directions
71
+ * @cn 排序方向
72
+ * @default ['asc', 'desc']
73
+ * @version 3.5.0
74
+ */
75
+ sortDirections?: ('asc' | 'desc')[];
57
76
  /**
58
77
  * @en Set columnResizable to true to make all columns scalable
59
78
  * @cn 设置 columnResizable 为 true,使所有列可伸缩
@@ -195,6 +214,13 @@ export interface TableColumnItem<DataItem> {
195
214
  * 服务端排序,不要返回值,自行处理即可。(旧用法)
196
215
  */
197
216
  sorter?: ((order: TableColumnOrder) => ((prevRowData: DataItem, nextRowData: DataItem) => number) | void) | string | TableColumnSorter;
217
+ /**
218
+ * @en sort directions
219
+ * @cn 排序方向
220
+ * @default ['asc', 'desc']
221
+ * @version 3.5.0
222
+ */
223
+ sortDirections?: ('asc' | 'desc')[];
198
224
  /**
199
225
  * @en The content of the header
200
226
  * @cn 表头显示内容
@@ -1 +1 @@
1
- {"version":3,"file":"use-table.type.d.ts","sourceRoot":"","sources":["use-table.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAA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O,CAAC;IACrB,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC"}
package/cjs/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { util };
5
5
  export * from './common/type';
6
6
  export * from './common/use-fork-ref';
7
7
  export * from './common/use-input-able';
8
+ export * from './common/use-in-view';
8
9
  export * from './common/use-latest-obj';
9
10
  export * from './common/use-persist-fn';
10
11
  export * from './common/use-key-event';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,UAAU,CAAC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,cAAc,eAAe,CAAC;AAE9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAG7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B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C;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAG7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;;AAE1C,wBAAkB"}
package/cjs/index.js CHANGED
@@ -71,6 +71,18 @@ Object.keys(_useInputAble).forEach(function (key) {
71
71
  }
72
72
  });
73
73
  });
74
+ var _useInView = require("./common/use-in-view");
75
+ Object.keys(_useInView).forEach(function (key) {
76
+ if (key === "default" || key === "__esModule") return;
77
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
78
+ if (key in exports && exports[key] === _useInView[key]) return;
79
+ Object.defineProperty(exports, key, {
80
+ enumerable: true,
81
+ get: function get() {
82
+ return _useInView[key];
83
+ }
84
+ });
85
+ });
74
86
  var _useLatestObj = require("./common/use-latest-obj");
75
87
  Object.keys(_useLatestObj).forEach(function (key) {
76
88
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,2 @@
1
+ export declare const getCurrentCSSZoom: () => number;
2
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["document.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,QAAO,MAqBpC,CAAA"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCurrentCSSZoom = void 0;
7
+ var cachedZoom = 0;
8
+ var getCurrentCSSZoom = exports.getCurrentCSSZoom = function getCurrentCSSZoom() {
9
+ if (cachedZoom) return cachedZoom;
10
+ if (typeof window === 'undefined' || typeof navigator === 'undefined' || !document.body) {
11
+ return 1;
12
+ }
13
+ var currentCSSZoom = Math.round(document.body.getBoundingClientRect().width) / document.body.clientWidth;
14
+ if (window.ResizeObserver) {
15
+ // 监听document.body的变化,更新缓存的zoom
16
+ var resizeObserver = new ResizeObserver(function () {
17
+ cachedZoom = Math.round(document.body.getBoundingClientRect().width) / document.body.clientWidth;
18
+ });
19
+ resizeObserver.observe(document.body);
20
+ }
21
+ cachedZoom = currentCSSZoom;
22
+ return currentCSSZoom;
23
+ };
24
+
25
+ // export const getZoomBoundingClientRect = (element: HTMLElement) => {
26
+ // const currentCSSZoom = getCurrentCSSZoom()
27
+ // if (currentCSSZoom === 1 || !currentCSSZoom) {
28
+ // return element.getBoundingClientRect()
29
+ // }
30
+ // const isNotZoom = currentCSSZoom === 1 || !currentCSSZoom
31
+
32
+ // if (isNotZoom) {
33
+ // return element.getBoundingClientRect()
34
+ // }
35
+
36
+ // const zoomRatio = 1 / currentCSSZoom
37
+ // const rect = element.getBoundingClientRect()
38
+
39
+ // return {
40
+ // x: rect.x * zoomRatio,
41
+ // y: rect.y * zoomRatio,
42
+ // top: rect.top * zoomRatio,
43
+ // right: rect.right * zoomRatio,
44
+ // bottom: rect.bottom * zoomRatio,
45
+ // left: rect.left * zoomRatio,
46
+ // width: rect.width * zoomRatio,
47
+ // height: rect.height * zoomRatio,
48
+ // }
49
+ // }
@@ -12,7 +12,7 @@ export declare const addResizeObserver: (el: HTMLElement, handler: any, options?
12
12
  timer?: number | undefined;
13
13
  }) => () => void;
14
14
  export declare function getParent(el: HTMLElement | null | Element, target?: string | HTMLElement): Element | null;
15
- export declare function getClosestScrollContainer(element: HTMLElement | null): Element | null;
15
+ export declare function getClosestScrollContainer(element: HTMLElement | null): HTMLElement | null;
16
16
  export declare function cssSupport(attr: keyof CSSStyleDeclaration, value: string): boolean;
17
17
  export declare const parsePxToNumber: (str: string) => number;
18
18
  //# sourceMappingURL=element.d.ts.map
@@ -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;;;gBA4Cb,CAAC;AAEF,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,kBAmBxF;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,kBA+BpE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAAmB,EAAE,KAAK,EAAE,MAAM,WAYxE;AAED,eAAO,MAAM,eAAe,QAAS,MAAM,WAAwC,CAAC"}
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;;;gBA4Cb,CAAC;AAEF,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,kBAmBxF;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CA+BzF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAAmB,EAAE,KAAK,EAAE,MAAM,WAYxE;AAED,eAAO,MAAM,eAAe,QAAS,MAAM,WAAwC,CAAC"}
@@ -3,6 +3,7 @@ export { parsePxToNumber, addResizeObserver } from './element';
3
3
  export type { OldWheelEvent } from './normalize-wheel.type';
4
4
  export * from './ready';
5
5
  export * from './element';
6
+ export * from './document';
6
7
  export { default as ResponsiveObserve } from './responsiveObserve';
7
8
  export type { Breakpoint, ScreenMap } from './responsiveObserve.type';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAE1B,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC"}
@@ -64,5 +64,17 @@ Object.keys(_ready).forEach(function (key) {
64
64
  }
65
65
  });
66
66
  });
67
+ var _document = require("./document");
68
+ Object.keys(_document).forEach(function (key) {
69
+ if (key === "default" || key === "__esModule") return;
70
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
71
+ if (key in exports && exports[key] === _document[key]) return;
72
+ Object.defineProperty(exports, key, {
73
+ enumerable: true,
74
+ get: function get() {
75
+ return _document[key];
76
+ }
77
+ });
78
+ });
67
79
  var _responsiveObserve = _interopRequireDefault(require("./responsiveObserve"));
68
80
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/cjs/utils/is.d.ts CHANGED
@@ -24,6 +24,5 @@ export declare const isLink: (el: unknown) => el is React.ReactElement<any, stri
24
24
  export declare function isNamedComponent(type: any): type is React.ForwardRefExoticComponent<unknown>;
25
25
  export declare const isMacOS: () => boolean;
26
26
  export declare const isFirefox: () => boolean;
27
- export declare const isChromeLowerThan: (version: number) => boolean;
28
27
  export declare function isDomElement(element: any): element is HTMLElement;
29
28
  //# sourceMappingURL=is.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,wBAAgB,S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OAAO,KAAG,OActC,CAAC;AAEF,eAAO,MAAM,MAAM,OAAQ,OAAO,6EASjC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAE5F;AAED,eAAO,MAAM,OAAO,QAAO,OACqC,CAAC;AAEjE,eAAO,MAAM,SAAS,QAAO,OAG5B,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,WAAW,CAQjE"}
package/cjs/utils/is.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isBoolean = exports.isArray = void 0;
7
7
  exports.isBrowser = isBrowser;
8
- exports.isDate = exports.isChromeLowerThan = exports.isBuffer = void 0;
8
+ exports.isDate = exports.isBuffer = void 0;
9
9
  exports.isDomElement = isDomElement;
10
10
  exports.isMergeable = exports.isMap = exports.isMacOS = exports.isLink = exports.isFunc = exports.isFirefox = exports.isError = exports.isEmpty = void 0;
11
11
  exports.isNamedComponent = isNamedComponent;
@@ -108,15 +108,6 @@ var isFirefox = exports.isFirefox = function isFirefox() {
108
108
  if (!isBrowser()) return false;
109
109
  return navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
110
110
  };
111
- var isChromeLowerThan = exports.isChromeLowerThan = function isChromeLowerThan(version) {
112
- // 服务器端渲染时,不执行版本检查
113
- if (typeof window === 'undefined' || typeof navigator === 'undefined') {
114
- return false;
115
- }
116
- var ua = navigator.userAgent;
117
- var chrome = ua.match(/chrome\/(\d+)/i);
118
- return Boolean(chrome && chrome[1] && parseInt(chrome[1], 10) < version);
119
- };
120
111
  function isDomElement(element) {
121
112
  return (typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement)) === 'object' ? element instanceof HTMLElement // DOM2
122
113
  : element && _typeof(element) === 'object' && element !== null && element.nodeType === 1 && typeof element.nodeName === 'string';
@@ -2,6 +2,7 @@ type LazyConfig = {
2
2
  container?: Element | null;
3
3
  element: Element;
4
4
  render: () => void;
5
+ offscreen?: () => void;
5
6
  offset: number;
6
7
  noRemove?: boolean;
7
8
  observer?: IntersectionObserver;
@@ -1 +1 @@
1
- {"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.ts"],"names":[],"mappings":"AAIA,KAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CACjC,CAAC;AAoBF,wBAAgB,QAAQ,SAgBvB;AAWD,wBAAgB,WAAW,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,cAAc,CAAC,EAAE,OAAO,QAUvE;AAsBD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,iBA4BvC"}
1
+ {"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.ts"],"names":[],"mappings":"AAIA,KAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CACjC,CAAC;AAoBF,wBAAgB,QAAQ,SAgBvB;AAWD,wBAAgB,WAAW,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,cAAc,CAAC,EAAE,OAAO,QAUvE;AAwBD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,iBA4BvC"}
@@ -68,12 +68,15 @@ function getObserver(obj, id) {
68
68
  container = _obj$container === void 0 ? null : _obj$container,
69
69
  offset = obj.offset,
70
70
  render = obj.render,
71
+ offscreen = obj.offscreen,
71
72
  noRemove = obj.noRemove;
72
73
  var observer = new IntersectionObserver(function (entries) {
73
74
  entries.forEach(function (en) {
74
75
  if (en.isIntersecting || en.intersectionRatio > 0) {
75
76
  render();
76
77
  if (!noRemove) removeStack(id);
78
+ } else {
79
+ offscreen && offscreen();
77
80
  }
78
81
  });
79
82
  }, {
@@ -0,0 +1,2 @@
1
+ export { default as useInView } from './use-in-view';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export { default as useInView } from "./use-in-view";
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ interface UseInViewOptions {
3
+ root?: HTMLElement | null;
4
+ rootMargin?: string;
5
+ threshold?: number | number[];
6
+ once?: boolean;
7
+ }
8
+ declare const useInView: <T extends HTMLElement>(options?: UseInViewOptions) => {
9
+ ref: import("react").MutableRefObject<T | null>;
10
+ isInView: boolean;
11
+ wasInView: boolean;
12
+ };
13
+ export default useInView;
14
+ //# sourceMappingURL=use-in-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-in-view.d.ts","sourceRoot":"","sources":["use-in-view.ts"],"names":[],"mappings":";AAIA,UAAU,gBAAgB;IACxB,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,QAAA,MAAM,SAAS,oCAAoC,gBAAgB;;;;CA2ClE,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,70 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useRef, useState } from 'react';
8
+ var useInView = function useInView() {
9
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10
+ var elementRef = useRef(null);
11
+ var _useState = useState(false),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ isInView = _useState2[0],
14
+ setIsInView = _useState2[1];
15
+ var _useState3 = useState(false),
16
+ _useState4 = _slicedToArray(_useState3, 2),
17
+ wasInView = _useState4[0],
18
+ setWasInView = _useState4[1];
19
+ useEffect(function () {
20
+ var element = elementRef.current;
21
+ if (!element) return;
22
+ if (typeof window === 'undefined' || !window.IntersectionObserver) {
23
+ setIsInView(true);
24
+ setWasInView(true);
25
+ return;
26
+ }
27
+ var observer = new IntersectionObserver(function (_ref) {
28
+ var _ref2 = _slicedToArray(_ref, 1),
29
+ entry = _ref2[0];
30
+ var inView = entry.isIntersecting;
31
+ setIsInView(inView);
32
+ if (inView) {
33
+ setWasInView(true);
34
+ // 如果设置了 once 选项,且元素已经出现过,则取消观察
35
+ if (options.once) {
36
+ observer.disconnect();
37
+ }
38
+ }
39
+ }, {
40
+ root: options.root || null,
41
+ rootMargin: options.rootMargin || '0px',
42
+ threshold: options.threshold || 0
43
+ });
44
+ observer.observe(element);
45
+ return function () {
46
+ observer.disconnect();
47
+ };
48
+ }, [options.root, options.rootMargin, options.threshold, options.once]);
49
+ return {
50
+ ref: elementRef,
51
+ isInView: isInView,
52
+ wasInView: wasInView
53
+ };
54
+ };
55
+ export default useInView;
56
+
57
+ // 使用示例
58
+ // const Example = () => {
59
+ // const { ref, isInView } = useInView({
60
+ // threshold: 0.5,
61
+ // rootMargin: '50px',
62
+ // once: true
63
+ // });
64
+
65
+ // return (
66
+ // <div ref={ref}>
67
+ // {isInView ? '元素在视窗中' : '元素不在视窗中'}
68
+ // </div>
69
+ // );
70
+ // };
@@ -0,0 +1,11 @@
1
+ interface Position {
2
+ top: number;
3
+ left: number;
4
+ }
5
+ interface UseCheckElementPositionOptions {
6
+ enable?: boolean;
7
+ scrollContainer?: HTMLElement | null;
8
+ }
9
+ export declare const useCheckElementPosition: (elementRef: React.RefObject<HTMLElement>, options?: UseCheckElementPositionOptions) => Position | null;
10
+ export {};
11
+ //# sourceMappingURL=check-position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-position.d.ts","sourceRoot":"","sources":["check-position.ts"],"names":[],"mappings":"AAEA,UAAU,QAAQ;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,8BAA8B;IAEtC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,uBAAuB,eACtB,MAAM,SAAS,CAAC,WAAW,CAAC,YAC/B,8BAA8B,KACtC,QAAQ,GAAG,IAyEb,CAAC"}
@@ -0,0 +1,84 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useState, useEffect, useRef, useCallback } from 'react';
8
+ export var useCheckElementPosition = function useCheckElementPosition(elementRef) {
9
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10
+ var enable = options.enable,
11
+ scrollContainer = options.scrollContainer;
12
+ var _useState = useState({
13
+ top: 0,
14
+ left: 0
15
+ }),
16
+ _useState2 = _slicedToArray(_useState, 2),
17
+ position = _useState2[0],
18
+ setPosition = _useState2[1];
19
+ var lastPosition = useRef({
20
+ top: 0,
21
+ left: 0
22
+ });
23
+ var checkPosition = useCallback(function () {
24
+ if (elementRef.current) {
25
+ var rect = elementRef.current.getBoundingClientRect();
26
+ var scrollContainerRect = scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.getBoundingClientRect();
27
+ var newPosition;
28
+ if (scrollContainerRect) {
29
+ newPosition = {
30
+ top: rect.top - scrollContainerRect.top,
31
+ left: rect.left - scrollContainerRect.left
32
+ };
33
+ } else {
34
+ newPosition = {
35
+ top: rect.top,
36
+ left: rect.left
37
+ };
38
+ }
39
+ if (newPosition.top !== lastPosition.current.top || newPosition.left !== lastPosition.current.left) {
40
+ setPosition(newPosition);
41
+ lastPosition.current = newPosition;
42
+ }
43
+ }
44
+ }, [elementRef, scrollContainer]);
45
+ useEffect(function () {
46
+ var _window;
47
+ if (!enable) return;
48
+ var element = elementRef.current;
49
+ var container = scrollContainer || window;
50
+ if (!element) return;
51
+
52
+ // 初始检查
53
+ checkPosition();
54
+ var resizeObserver = null;
55
+ if ((_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
56
+ resizeObserver = new ResizeObserver(checkPosition);
57
+ resizeObserver.observe(element);
58
+ if (container instanceof Element) {
59
+ resizeObserver.observe(container);
60
+ }
61
+ }
62
+ // 滚动事件监听
63
+ container.addEventListener('scroll', checkPosition);
64
+
65
+ // 如果容器不是 window,我们仍然需要监听 window 的 resize 事件
66
+ if (container !== window) {
67
+ window.addEventListener('resize', checkPosition);
68
+ }
69
+
70
+ // 清理函数
71
+ return function () {
72
+ var _resizeObserver;
73
+ (_resizeObserver = resizeObserver) === null || _resizeObserver === void 0 || _resizeObserver.disconnect();
74
+ container.removeEventListener('scroll', checkPosition);
75
+ if (container !== window) {
76
+ window.removeEventListener('resize', checkPosition);
77
+ }
78
+ };
79
+ }, [enable, elementRef, scrollContainer, checkPosition]);
80
+ if (!enable || !elementRef) {
81
+ return null;
82
+ }
83
+ return position;
84
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAOnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAQD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;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