@varlet/use 2.18.0-alpha.1697511280107 → 2.18.0-alpha.1697559303154

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/lib/index.d.ts CHANGED
@@ -63,8 +63,19 @@ declare function useTouch(): {
63
63
  startTouch: (event: TouchEvent) => void;
64
64
  moveTouch: (event: TouchEvent) => void;
65
65
  endTouch: () => void;
66
+ isReachTop: (element: Element | Window) => boolean;
67
+ isReachBottom: (element: Element, offset?: number) => boolean;
66
68
  };
67
69
 
68
70
  declare function useId(): vue.Ref<string | undefined>;
69
71
 
70
- export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useEventListener, useId, useInitialized, useParent, useTouch };
72
+ interface UseWindowSizeOptions {
73
+ initialWidth?: number;
74
+ initialHeight?: number;
75
+ }
76
+ declare function useWindowSize(options?: UseWindowSizeOptions): {
77
+ width: vue.Ref<number>;
78
+ height: vue.Ref<number>;
79
+ };
80
+
81
+ export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useEventListener, useId, useInitialized, useParent, useTouch, useWindowSize };
package/lib/index.js CHANGED
@@ -265,6 +265,7 @@ function useInitialized(source, value) {
265
265
 
266
266
  // src/useTouch.ts
267
267
  import { ref as ref2 } from "vue";
268
+ import { getScrollTop } from "@varlet/shared";
268
269
  function getDirection(x, y) {
269
270
  if (x > y) {
270
271
  return "horizontal";
@@ -343,6 +344,15 @@ function useTouch() {
343
344
  dragging.value = false;
344
345
  });
345
346
  };
347
+ const isReachTop = (element) => {
348
+ const scrollTop = getScrollTop(element);
349
+ return scrollTop === 0 && deltaY.value > 0;
350
+ };
351
+ const isReachBottom = (element, offset = 1) => {
352
+ const { scrollHeight, clientHeight, scrollTop } = element;
353
+ const offsetBottom = Math.abs(scrollHeight - scrollTop - clientHeight);
354
+ return deltaY.value < 0 && offsetBottom <= offset;
355
+ };
346
356
  return {
347
357
  startX,
348
358
  startY,
@@ -362,7 +372,9 @@ function useTouch() {
362
372
  resetTouch,
363
373
  startTouch,
364
374
  moveTouch,
365
- endTouch
375
+ endTouch,
376
+ isReachTop,
377
+ isReachBottom
366
378
  };
367
379
  }
368
380
 
@@ -376,6 +388,28 @@ function useId() {
376
388
  id.value = process.env.NODE_ENV === "test" ? `${name}-mock-id` : `${name}-${instance.uid}`;
377
389
  return id;
378
390
  }
391
+
392
+ // src/useWindowSize.ts
393
+ import { inBrowser as inBrowser3 } from "@varlet/shared";
394
+ import { ref as ref4 } from "vue";
395
+ function useWindowSize(options = {}) {
396
+ const { initialWidth = 0, initialHeight = 0 } = options;
397
+ const width = ref4(initialWidth);
398
+ const height = ref4(initialHeight);
399
+ const update = () => {
400
+ if (!inBrowser3()) {
401
+ return;
402
+ }
403
+ width.value = window.innerWidth;
404
+ height.value = window.innerHeight;
405
+ };
406
+ onSmartMounted(update);
407
+ onWindowResize(update);
408
+ return {
409
+ width,
410
+ height
411
+ };
412
+ }
379
413
  export {
380
414
  keyInProvides,
381
415
  onSmartMounted,
@@ -387,5 +421,6 @@ export {
387
421
  useId,
388
422
  useInitialized,
389
423
  useParent,
390
- useTouch
424
+ useTouch,
425
+ useWindowSize
391
426
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/use",
3
- "version": "2.18.0-alpha.1697511280107",
3
+ "version": "2.18.0-alpha.1697559303154",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/varletjs/varlet/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@varlet/shared": "2.18.0-alpha.1697511280107"
27
+ "@varlet/shared": "2.18.0-alpha.1697559303154"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^18.7.18",