@varlet/use 2.18.0-alpha.1697511280107 → 2.18.0-alpha.1697555377370
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 +12 -1
- package/lib/index.js +36 -2
- package/package.json +2 -2
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) => boolean;
|
|
67
|
+
isReachBottom: (element: Element, offset?: number) => boolean;
|
|
66
68
|
};
|
|
67
69
|
|
|
68
70
|
declare function useId(): vue.Ref<string | undefined>;
|
|
69
71
|
|
|
70
|
-
|
|
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
|
@@ -343,6 +343,15 @@ function useTouch() {
|
|
|
343
343
|
dragging.value = false;
|
|
344
344
|
});
|
|
345
345
|
};
|
|
346
|
+
const isReachTop = (element) => {
|
|
347
|
+
const { scrollTop } = element;
|
|
348
|
+
return scrollTop === 0 && deltaY.value > 0;
|
|
349
|
+
};
|
|
350
|
+
const isReachBottom = (element, offset = 1) => {
|
|
351
|
+
const { scrollHeight, clientHeight, scrollTop } = element;
|
|
352
|
+
const offsetBottom = Math.abs(scrollHeight - scrollTop - clientHeight);
|
|
353
|
+
return deltaY.value < 0 && offsetBottom <= offset;
|
|
354
|
+
};
|
|
346
355
|
return {
|
|
347
356
|
startX,
|
|
348
357
|
startY,
|
|
@@ -362,7 +371,9 @@ function useTouch() {
|
|
|
362
371
|
resetTouch,
|
|
363
372
|
startTouch,
|
|
364
373
|
moveTouch,
|
|
365
|
-
endTouch
|
|
374
|
+
endTouch,
|
|
375
|
+
isReachTop,
|
|
376
|
+
isReachBottom
|
|
366
377
|
};
|
|
367
378
|
}
|
|
368
379
|
|
|
@@ -376,6 +387,28 @@ function useId() {
|
|
|
376
387
|
id.value = process.env.NODE_ENV === "test" ? `${name}-mock-id` : `${name}-${instance.uid}`;
|
|
377
388
|
return id;
|
|
378
389
|
}
|
|
390
|
+
|
|
391
|
+
// src/useWindowSize.ts
|
|
392
|
+
import { inBrowser as inBrowser3 } from "@varlet/shared";
|
|
393
|
+
import { ref as ref4 } from "vue";
|
|
394
|
+
function useWindowSize(options = {}) {
|
|
395
|
+
const { initialWidth = 0, initialHeight = 0 } = options;
|
|
396
|
+
const width = ref4(initialWidth);
|
|
397
|
+
const height = ref4(initialHeight);
|
|
398
|
+
const update = () => {
|
|
399
|
+
if (!inBrowser3()) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
width.value = window.innerWidth;
|
|
403
|
+
height.value = window.innerHeight;
|
|
404
|
+
};
|
|
405
|
+
onSmartMounted(update);
|
|
406
|
+
onWindowResize(update);
|
|
407
|
+
return {
|
|
408
|
+
width,
|
|
409
|
+
height
|
|
410
|
+
};
|
|
411
|
+
}
|
|
379
412
|
export {
|
|
380
413
|
keyInProvides,
|
|
381
414
|
onSmartMounted,
|
|
@@ -387,5 +420,6 @@ export {
|
|
|
387
420
|
useId,
|
|
388
421
|
useInitialized,
|
|
389
422
|
useParent,
|
|
390
|
-
useTouch
|
|
423
|
+
useTouch,
|
|
424
|
+
useWindowSize
|
|
391
425
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/use",
|
|
3
|
-
"version": "2.18.0-alpha.
|
|
3
|
+
"version": "2.18.0-alpha.1697555377370",
|
|
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.
|
|
27
|
+
"@varlet/shared": "2.18.0-alpha.1697555377370"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^18.7.18",
|