sard-uniapp 1.11.1 → 1.12.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.
- package/CHANGELOG.md +34 -0
- package/README.md +5 -3
- package/components/action-sheet/action-sheet.vue +8 -2
- package/components/action-sheet/index.scss +1 -1
- package/components/back-top/back-top.d.ts +1 -1
- package/components/badge/badge.vue +1 -1
- package/components/button/button.d.ts +1 -0
- package/components/button/button.vue +2 -0
- package/components/button/common.d.ts +2 -0
- package/components/button/index.scss +6 -1
- package/components/calendar/calendar.d.ts +1 -1
- package/components/calendar/calendar.vue +49 -22
- package/components/calendar/index.scss +5 -5
- package/components/calendar/variables.scss +1 -1
- package/components/calendar-input/calendar-input.d.ts +1 -1
- package/components/calendar-month/index.scss +1 -0
- package/components/cascader/cascader.d.ts +6 -6
- package/components/cascader/cascader.vue +9 -4
- package/components/cascader/common.d.ts +3 -3
- package/components/cascader/index.scss +1 -0
- package/components/checkbox-input/checkbox-input.vue +59 -32
- package/components/checkbox-input/index.scss +4 -0
- package/components/config/index.d.ts +23 -0
- package/components/config/index.js +47 -18
- package/components/crop-image/common.d.ts +32 -0
- package/components/crop-image/common.js +2 -0
- package/components/crop-image/crop-image.d.ts +19 -0
- package/components/crop-image/crop-image.vue +671 -0
- package/components/crop-image/index.d.ts +1 -0
- package/components/crop-image/index.scss +81 -0
- package/components/crop-image-agent/common.d.ts +19 -0
- package/components/crop-image-agent/common.js +16 -0
- package/components/crop-image-agent/crop-image-agent.d.ts +9 -0
- package/components/crop-image-agent/crop-image-agent.vue +70 -0
- package/components/crop-image-agent/index.d.ts +1 -0
- package/components/crop-image-agent/index.js +1 -0
- package/components/datetime-picker-input/datetime-picker-input.vue +4 -4
- package/components/datetime-range-picker/datetime-range-picker.vue +4 -3
- package/components/datetime-range-picker-input/datetime-range-picker-input.vue +4 -4
- package/components/dialog/common.d.ts +2 -3
- package/components/dialog/dialog.d.ts +6 -13
- package/components/dialog/dialog.vue +15 -4
- package/components/dialog-agent/dialog-agent.d.ts +1 -1
- package/components/dropdown-item/dropdown-item.vue +6 -6
- package/components/fab/fab.d.ts +1 -1
- package/components/floating-bubble/floating-bubble.vue +14 -19
- package/components/form-item/form-item.vue +4 -3
- package/components/grid/common.d.ts +4 -0
- package/components/grid-item/grid-item.vue +33 -18
- package/components/grid-item/index.scss +12 -4
- package/components/icon/index.scss +1 -0
- package/components/icon/sari.scss +9 -1
- package/components/indexes/common.d.ts +3 -5
- package/components/indexes/indexes.d.ts +2 -0
- package/components/indexes/indexes.vue +45 -109
- package/components/indexes-anchor/indexes-anchor.vue +9 -9
- package/components/indexes-nav/indexes-nav.vue +26 -22
- package/components/input/input.d.ts +4 -4
- package/components/loading/index.scss +1 -1
- package/components/locale/lang/en-US.d.ts +9 -0
- package/components/locale/lang/en-US.js +9 -0
- package/components/locale/lang/zh-CN.d.ts +9 -0
- package/components/locale/lang/zh-CN.js +9 -0
- package/components/navbar/common.d.ts +12 -0
- package/components/navbar/index.scss +17 -10
- package/components/navbar/navbar.d.ts +5 -1
- package/components/navbar/navbar.vue +45 -15
- package/components/navbar/variables.scss +4 -1
- package/components/navbar-item/index.scss +10 -0
- package/components/navbar-item/navbar-item.vue +27 -4
- package/components/navbar-pit/navbar-pit.d.ts +2 -0
- package/components/navbar-pit/navbar-pit.vue +22 -0
- package/components/notify/common.d.ts +1 -0
- package/components/notify/index.scss +12 -7
- package/components/notify/notify.vue +9 -3
- package/components/notify-agent/notify-agent.vue +9 -11
- package/components/pagination/pagination.d.ts +1 -1
- package/components/picker-input/picker-input.vue +4 -4
- package/components/popout/common.d.ts +2 -3
- package/components/popout/popout.d.ts +5 -12
- package/components/popout/popout.vue +16 -5
- package/components/popover/utils.js +2 -4
- package/components/popover-reference/popover-reference.vue +3 -3
- package/components/popup/common.d.ts +5 -3
- package/components/popup/index.scss +25 -3
- package/components/popup/popup.d.ts +1 -1
- package/components/pull-down-refresh/pull-down-refresh.d.ts +1 -1
- package/components/qrcode/qrcode.d.ts +1 -1
- package/components/qrcode/qrcode.vue +4 -7
- package/components/radio-input/index.scss +5 -1
- package/components/radio-input/radio-input.vue +59 -32
- package/components/scroll-spy/common.d.ts +29 -0
- package/components/scroll-spy/common.js +1 -0
- package/components/scroll-spy/index.d.ts +1 -0
- package/components/scroll-spy/index.js +1 -0
- package/components/scroll-spy/scroll-spy.d.ts +28 -0
- package/components/scroll-spy/scroll-spy.vue +120 -0
- package/components/scroll-spy-anchor/common.d.ts +13 -0
- package/components/scroll-spy-anchor/index.d.ts +1 -0
- package/components/scroll-spy-anchor/index.js +1 -0
- package/components/scroll-spy-anchor/scroll-spy-anchor.d.ts +10 -0
- package/components/scroll-spy-anchor/scroll-spy-anchor.vue +50 -0
- package/components/search/search.vue +2 -0
- package/components/share-sheet/share-sheet.vue +3 -2
- package/components/sidebar/common.d.ts +28 -0
- package/components/sidebar/common.js +1 -0
- package/components/sidebar/index.d.ts +1 -0
- package/components/sidebar/index.js +1 -0
- package/components/sidebar/index.scss +15 -0
- package/components/sidebar/sidebar.d.ts +16 -0
- package/components/sidebar/sidebar.vue +136 -0
- package/components/sidebar/variables.scss +20 -0
- package/components/sidebar-item/common.d.ts +16 -0
- package/components/sidebar-item/common.js +1 -0
- package/components/sidebar-item/index.d.ts +1 -0
- package/components/sidebar-item/index.js +1 -0
- package/components/sidebar-item/index.scss +70 -0
- package/components/sidebar-item/sidebar-item.d.ts +14 -0
- package/components/sidebar-item/sidebar-item.vue +111 -0
- package/components/signature/common.d.ts +41 -0
- package/components/signature/common.js +2 -0
- package/components/signature/index.d.ts +1 -0
- package/components/signature/index.js +1 -0
- package/components/signature/index.scss +109 -0
- package/components/signature/signature.d.ts +32 -0
- package/components/signature/signature.vue +580 -0
- package/components/signature/variables-dark.scss +7 -0
- package/components/signature/variables.scss +9 -0
- package/components/status-bar/common.d.ts +17 -0
- package/components/status-bar/common.js +2 -0
- package/components/status-bar/index.d.ts +1 -0
- package/components/status-bar/index.js +1 -0
- package/components/status-bar/index.scss +7 -0
- package/components/status-bar/status-bar.d.ts +12 -0
- package/components/status-bar/status-bar.vue +56 -0
- package/components/style/mixins/ellipsis.scss +7 -0
- package/components/style/mixins/scroll-shadow.scss +40 -0
- package/components/style/mixins.scss +1 -0
- package/components/style/variables.scss +3 -0
- package/components/swiper-dot/swiper-dot.d.ts +1 -1
- package/components/tab/tab.vue +4 -3
- package/components/tabbar/common.d.ts +1 -0
- package/components/tabbar/tabbar.d.ts +2 -0
- package/components/tabbar/tabbar.vue +2 -1
- package/components/table-cell/index.scss +1 -2
- package/components/table-fixation/table-fixation.vue +16 -8
- package/components/tree/tree.vue +6 -4
- package/components/tree-node/tree-node.vue +12 -10
- package/components/upload/upload.vue +3 -2
- package/dark.scss +1 -0
- package/global.d.ts +9 -0
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/index.scss +2 -0
- package/package.json +28 -24
- package/use/index.d.ts +4 -0
- package/use/index.js +4 -0
- package/use/useDragPinch.d.ts +15 -0
- package/use/useDragPinch.js +88 -0
- package/use/useImperative.js +1 -0
- package/use/useInitialVelocity.d.ts +13 -0
- package/use/useInitialVelocity.js +65 -0
- package/use/useMouseDown.js +3 -4
- package/use/useScrollSide.d.ts +6 -0
- package/use/useScrollSide.js +34 -0
- package/use/useScrollSpy.d.ts +19 -0
- package/use/useScrollSpy.js +99 -0
- package/use/useTimeoutLoading.d.ts +6 -0
- package/use/useTimeoutLoading.js +53 -0
- package/use/useZIndex.js +7 -3
- package/utils/bem.d.ts +8 -8
- package/utils/dom.d.ts +3 -69
- package/utils/dom.js +32 -109
- package/utils/file.d.ts +1 -0
- package/utils/file.js +14 -0
- package/utils/geometry.d.ts +67 -0
- package/utils/geometry.js +127 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +2 -0
- package/utils/inertialAnimate.d.ts +10 -0
- package/utils/inertialAnimate.js +42 -0
- package/utils/is.d.ts +8 -0
- package/utils/is.js +8 -0
- package/utils/system.d.ts +2 -0
- package/utils/system.js +6 -3
- package/utils/utils.d.ts +7 -0
- package/utils/utils.js +13 -0
- package/components/_template/_template.d.ts +0 -16
- package/components/_template/_template.vue +0 -45
- package/components/_template/common.d.ts +0 -14
- package/components/_template/index.d.ts +0 -1
- package/components/_template/index.scss +0 -17
- package/components/_template/variables.scss +0 -5
- /package/components/{_template → crop-image}/index.js +0 -0
- /package/components/{_template → scroll-spy-anchor}/common.js +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getTwoPointsDistance } from '../utils';
|
|
2
|
+
import { useInitialVelocity } from './useInitialVelocity';
|
|
3
|
+
import { useMouseDown } from './useMouseDown';
|
|
4
|
+
function getPoint(touch) {
|
|
5
|
+
return {
|
|
6
|
+
x: touch.clientX,
|
|
7
|
+
y: touch.clientY,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function getCenterPoint(touches) {
|
|
11
|
+
const points = Array.from(touches).map(getPoint);
|
|
12
|
+
const firstPoint = points[0];
|
|
13
|
+
if (points.length === 0) {
|
|
14
|
+
return firstPoint;
|
|
15
|
+
}
|
|
16
|
+
return points.slice(1).reduce((centerPoint, point) => {
|
|
17
|
+
return {
|
|
18
|
+
x: (point.x - centerPoint.x) / 2 + centerPoint.x,
|
|
19
|
+
y: (point.y - centerPoint.y) / 2 + centerPoint.y,
|
|
20
|
+
};
|
|
21
|
+
}, firstPoint);
|
|
22
|
+
}
|
|
23
|
+
function getScalePoints(touches) {
|
|
24
|
+
const points = Array.from(touches).map(getPoint);
|
|
25
|
+
if (points.length < 2) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
else if (points.length === 2) {
|
|
29
|
+
return points;
|
|
30
|
+
}
|
|
31
|
+
const centerPoint = points.slice(1, -1).reduce((centerPoint, point) => {
|
|
32
|
+
return {
|
|
33
|
+
x: (point.x - centerPoint.x) / 2 + centerPoint.x,
|
|
34
|
+
y: (point.y - centerPoint.y) / 2 + centerPoint.y,
|
|
35
|
+
};
|
|
36
|
+
}, points[0]);
|
|
37
|
+
return [centerPoint, points[points.length - 1]];
|
|
38
|
+
}
|
|
39
|
+
export function useDragPinch(options) {
|
|
40
|
+
const { onOffset, onScale, onCapture, onRelease } = options;
|
|
41
|
+
const initVelocity = useInitialVelocity();
|
|
42
|
+
let prevCenter = {
|
|
43
|
+
x: 0,
|
|
44
|
+
y: 0,
|
|
45
|
+
};
|
|
46
|
+
let prevScalePoints = null;
|
|
47
|
+
const onTouchStart = (event) => {
|
|
48
|
+
if (event.touches.length === 1) {
|
|
49
|
+
initVelocity.onStart(getPoint(event.touches[0]));
|
|
50
|
+
}
|
|
51
|
+
prevCenter = getCenterPoint(event.touches);
|
|
52
|
+
prevScalePoints = getScalePoints(event.touches);
|
|
53
|
+
onCapture?.();
|
|
54
|
+
};
|
|
55
|
+
const onTouchMove = (event) => {
|
|
56
|
+
const currCenterPoint = getCenterPoint(event.touches);
|
|
57
|
+
const offsetX = currCenterPoint.x - prevCenter.x;
|
|
58
|
+
const offsetY = currCenterPoint.y - prevCenter.y;
|
|
59
|
+
prevCenter = currCenterPoint;
|
|
60
|
+
onOffset?.(offsetX, offsetY);
|
|
61
|
+
const currScalePoints = getScalePoints(event.touches);
|
|
62
|
+
if (prevScalePoints && currScalePoints) {
|
|
63
|
+
const prevDistance = getTwoPointsDistance(...prevScalePoints);
|
|
64
|
+
const currDistance = getTwoPointsDistance(...currScalePoints);
|
|
65
|
+
const scale = (currDistance - prevDistance) / prevDistance;
|
|
66
|
+
onScale?.(currCenterPoint.x, currCenterPoint.y, scale);
|
|
67
|
+
}
|
|
68
|
+
prevScalePoints = currScalePoints;
|
|
69
|
+
if (event.touches.length === 1) {
|
|
70
|
+
initVelocity.onMove(getPoint(event.touches[0]));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const onTouchEnd = (event) => {
|
|
74
|
+
prevCenter = getCenterPoint(event.touches);
|
|
75
|
+
prevScalePoints = getScalePoints(event.touches);
|
|
76
|
+
if (event.touches.length === 0) {
|
|
77
|
+
const velocity = initVelocity.onEnd();
|
|
78
|
+
onRelease?.(velocity);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const onMouseDown = useMouseDown(onTouchStart, onTouchMove, onTouchEnd);
|
|
82
|
+
return {
|
|
83
|
+
onMouseDown,
|
|
84
|
+
onTouchStart,
|
|
85
|
+
onTouchMove,
|
|
86
|
+
onTouchEnd,
|
|
87
|
+
};
|
|
88
|
+
}
|
package/use/useImperative.js
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export function useInitialVelocity() {
|
|
2
|
+
const touchInfo = {
|
|
3
|
+
x: 0,
|
|
4
|
+
y: 0,
|
|
5
|
+
historyX: [],
|
|
6
|
+
historyY: [],
|
|
7
|
+
historyTime: [],
|
|
8
|
+
};
|
|
9
|
+
function findDelta(point) {
|
|
10
|
+
return {
|
|
11
|
+
x: point.x - touchInfo.x,
|
|
12
|
+
y: point.y - touchInfo.y,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function onStart(point) {
|
|
16
|
+
touchInfo.x = point.x;
|
|
17
|
+
touchInfo.y = point.y;
|
|
18
|
+
touchInfo.historyX = [0];
|
|
19
|
+
touchInfo.historyY = [0];
|
|
20
|
+
touchInfo.historyTime = [Date.now()];
|
|
21
|
+
}
|
|
22
|
+
function onMove(point) {
|
|
23
|
+
const delta = findDelta(point);
|
|
24
|
+
touchInfo.historyX.push(delta.x);
|
|
25
|
+
touchInfo.historyY.push(delta.y);
|
|
26
|
+
touchInfo.historyTime.push(Date.now());
|
|
27
|
+
while (touchInfo.historyTime.length > 10) {
|
|
28
|
+
touchInfo.historyTime.shift();
|
|
29
|
+
touchInfo.historyX.shift();
|
|
30
|
+
touchInfo.historyY.shift();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function onEnd() {
|
|
34
|
+
const velocity = {
|
|
35
|
+
x: 0,
|
|
36
|
+
y: 0,
|
|
37
|
+
};
|
|
38
|
+
const length = touchInfo.historyTime.length;
|
|
39
|
+
if (length > 2) {
|
|
40
|
+
let i = length - 1;
|
|
41
|
+
const time1 = touchInfo.historyTime[i];
|
|
42
|
+
const x = touchInfo.historyX[i];
|
|
43
|
+
const y = touchInfo.historyY[i];
|
|
44
|
+
while (i > 0) {
|
|
45
|
+
i--;
|
|
46
|
+
const time0 = touchInfo.historyTime[i];
|
|
47
|
+
const time = time1 - time0;
|
|
48
|
+
if (time > 30 && time < 50) {
|
|
49
|
+
velocity.x = (x - touchInfo.historyX[i]) / time;
|
|
50
|
+
velocity.y = (y - touchInfo.historyY[i]) / time;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
touchInfo.historyTime = [];
|
|
56
|
+
touchInfo.historyX = [];
|
|
57
|
+
touchInfo.historyY = [];
|
|
58
|
+
return velocity;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
onStart,
|
|
62
|
+
onMove,
|
|
63
|
+
onEnd,
|
|
64
|
+
};
|
|
65
|
+
}
|
package/use/useMouseDown.js
CHANGED
|
@@ -5,14 +5,13 @@ export function useMouseDown(startCallback, moveCallback, endCallback) {
|
|
|
5
5
|
if ('ontouchstart' in document) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
startCallback?.(toTouchEvent(event, info.windowTop));
|
|
8
|
+
startCallback?.(toTouchEvent(event));
|
|
10
9
|
const moveHandler = (event) => {
|
|
11
10
|
event.preventDefault();
|
|
12
|
-
moveCallback?.(toTouchEvent(event
|
|
11
|
+
moveCallback?.(toTouchEvent(event));
|
|
13
12
|
};
|
|
14
13
|
const upHandler = (event) => {
|
|
15
|
-
endCallback?.(toTouchEvent(event
|
|
14
|
+
endCallback?.(toTouchEvent(event));
|
|
16
15
|
document.removeEventListener('mousemove', moveHandler);
|
|
17
16
|
document.removeEventListener('mouseup', upHandler);
|
|
18
17
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
export function useScrollSide() {
|
|
3
|
+
const scrollSide = ref(null);
|
|
4
|
+
let prevScrollTop = 0;
|
|
5
|
+
const onScroll = (event) => {
|
|
6
|
+
const scrollTop = event.detail.scrollTop;
|
|
7
|
+
if (scrollTop === 0) {
|
|
8
|
+
scrollSide.value = 'start';
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
// 支付宝 lower-threshold 设为0不会触发 scrolltolower
|
|
12
|
+
// 可设 trap-scroll 使到达边界时仍触发 scroll 来判断是否触底
|
|
13
|
+
if (prevScrollTop === scrollTop) {
|
|
14
|
+
scrollSide.value = 'end';
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
scrollSide.value = 'center';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
prevScrollTop = scrollTop;
|
|
21
|
+
};
|
|
22
|
+
const onScrolltoupper = () => {
|
|
23
|
+
scrollSide.value = 'start';
|
|
24
|
+
};
|
|
25
|
+
const onScrolltolower = () => {
|
|
26
|
+
scrollSide.value = 'end';
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
scrollSide,
|
|
30
|
+
onScroll,
|
|
31
|
+
onScrolltoupper,
|
|
32
|
+
onScrolltolower,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type NodeRect } from '../utils';
|
|
2
|
+
export interface UseScrollSpyOptions {
|
|
3
|
+
defaultCurrent?: string | number;
|
|
4
|
+
getSpiedRect: () => Promise<NodeRect>;
|
|
5
|
+
initialScroll?: boolean;
|
|
6
|
+
startOffset?: number;
|
|
7
|
+
onChange?: (name: string | number) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function useScrollSpy(options: UseScrollSpyOptions): {
|
|
10
|
+
scrollTop: import("vue").Ref<number | undefined, number | undefined>;
|
|
11
|
+
innerCurrent: import("vue").Ref<string | number | undefined, string | number | undefined>;
|
|
12
|
+
anchorRectList: import("vue").ShallowRef<[string | number, NodeRect][], [string | number, NodeRect][]>;
|
|
13
|
+
register: (name: string | number, getRect: () => Promise<NodeRect>) => void;
|
|
14
|
+
unregister: (name: string | number) => void;
|
|
15
|
+
onScroll: (event: any) => void;
|
|
16
|
+
scrollTo: (name: string | number) => void;
|
|
17
|
+
update: () => Promise<void>;
|
|
18
|
+
initialize: () => Promise<void>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { computed, ref, shallowRef } from 'vue';
|
|
2
|
+
import { useSetTimeout } from './useSetTimeout';
|
|
3
|
+
import { isNullish, matchScrollVisible } from '../utils';
|
|
4
|
+
export function useScrollSpy(options) {
|
|
5
|
+
const { defaultCurrent, initialScroll, onChange, getSpiedRect } = options;
|
|
6
|
+
const startOffset = computed(() => options.startOffset || 0);
|
|
7
|
+
let memoScrollTop = 0;
|
|
8
|
+
const scrollTop = ref(0);
|
|
9
|
+
const innerCurrent = ref(defaultCurrent);
|
|
10
|
+
const anchorRectList = shallowRef([]);
|
|
11
|
+
const anchorMap = new Map();
|
|
12
|
+
let lockScroll = false;
|
|
13
|
+
const [unLockScrollLater] = useSetTimeout(() => {
|
|
14
|
+
lockScroll = false;
|
|
15
|
+
});
|
|
16
|
+
const register = (name, getRect) => {
|
|
17
|
+
anchorMap.set(name, getRect);
|
|
18
|
+
};
|
|
19
|
+
const unregister = (name) => {
|
|
20
|
+
anchorMap.delete(name);
|
|
21
|
+
};
|
|
22
|
+
const calcPosition = (offset) => {
|
|
23
|
+
matchScrollVisible(anchorRectList.value.map((item) => item[1]), (index) => {
|
|
24
|
+
const name = anchorRectList.value[index][0];
|
|
25
|
+
if (name !== innerCurrent.value) {
|
|
26
|
+
innerCurrent.value = name;
|
|
27
|
+
onChange?.(name);
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
offset,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const onScroll = (event) => {
|
|
34
|
+
memoScrollTop = event.detail.scrollTop;
|
|
35
|
+
if (lockScroll) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
calcPosition(memoScrollTop + startOffset.value);
|
|
39
|
+
};
|
|
40
|
+
const scrollTo = (name) => {
|
|
41
|
+
if (anchorRectList.value.length > 0) {
|
|
42
|
+
const item = anchorRectList.value.find((item) => item[0] === name);
|
|
43
|
+
if (item) {
|
|
44
|
+
const offset = item[1].top;
|
|
45
|
+
scrollTop.value = offset - startOffset.value;
|
|
46
|
+
lockScroll = true;
|
|
47
|
+
unLockScrollLater(150);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const getAllAnchorRect = async () => {
|
|
52
|
+
const allRect = await Promise.all([...anchorMap].map(([name, getRect]) => {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
getRect().then((rect) => {
|
|
55
|
+
resolve([name, rect]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}));
|
|
59
|
+
return allRect.sort((a, b) => {
|
|
60
|
+
return a[1].top - b[1].top;
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const calcRect = async () => {
|
|
64
|
+
const spiedRect = await getSpiedRect();
|
|
65
|
+
anchorRectList.value = (await getAllAnchorRect()).map(([name, rect]) => {
|
|
66
|
+
return [
|
|
67
|
+
name,
|
|
68
|
+
{
|
|
69
|
+
...rect,
|
|
70
|
+
top: rect.top - spiedRect.top + memoScrollTop,
|
|
71
|
+
bottom: rect.bottom - spiedRect.top + memoScrollTop,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const update = async () => {
|
|
77
|
+
await calcRect();
|
|
78
|
+
};
|
|
79
|
+
const initialize = async () => {
|
|
80
|
+
await calcRect();
|
|
81
|
+
if (isNullish(innerCurrent.value)) {
|
|
82
|
+
innerCurrent.value = anchorRectList.value[0]?.[0];
|
|
83
|
+
}
|
|
84
|
+
if (initialScroll) {
|
|
85
|
+
scrollTo(innerCurrent.value);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
scrollTop,
|
|
90
|
+
innerCurrent,
|
|
91
|
+
anchorRectList,
|
|
92
|
+
register,
|
|
93
|
+
unregister,
|
|
94
|
+
onScroll,
|
|
95
|
+
scrollTo,
|
|
96
|
+
update,
|
|
97
|
+
initialize,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { computed, watch } from 'vue';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import { useSetTimeout } from './useSetTimeout';
|
|
4
|
+
export function useTimeoutLoading(loading, options = {}) {
|
|
5
|
+
const { leading = 150, trailing = 20000 } = options;
|
|
6
|
+
const status = ref('idle');
|
|
7
|
+
let startTime = 0;
|
|
8
|
+
const [waitTrailing, cancelTrailing] = useSetTimeout(() => {
|
|
9
|
+
status.value = 'idle';
|
|
10
|
+
});
|
|
11
|
+
const [waitLeading, cancelLeading] = useSetTimeout(() => {
|
|
12
|
+
status.value = 'loading';
|
|
13
|
+
startTime = Date.now();
|
|
14
|
+
});
|
|
15
|
+
watch(loading, () => {
|
|
16
|
+
cancelLeading();
|
|
17
|
+
cancelTrailing();
|
|
18
|
+
if (loading.value) {
|
|
19
|
+
switch (status.value) {
|
|
20
|
+
case 'idle':
|
|
21
|
+
status.value = 'leading';
|
|
22
|
+
waitLeading(leading);
|
|
23
|
+
break;
|
|
24
|
+
case 'trailing':
|
|
25
|
+
status.value = 'loading';
|
|
26
|
+
startTime = Date.now();
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
switch (status.value) {
|
|
32
|
+
case 'leading':
|
|
33
|
+
status.value = 'idle';
|
|
34
|
+
break;
|
|
35
|
+
case 'loading': {
|
|
36
|
+
const duration = Date.now() - startTime;
|
|
37
|
+
if (duration >= trailing) {
|
|
38
|
+
status.value = 'idle';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
status.value = 'trailing';
|
|
42
|
+
waitTrailing(trailing - duration);
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const timeoutLoading = computed(() => {
|
|
50
|
+
return status.value === 'loading' || status.value === 'trailing';
|
|
51
|
+
});
|
|
52
|
+
return timeoutLoading;
|
|
53
|
+
}
|
package/use/useZIndex.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ref } from 'vue';
|
|
2
|
-
|
|
2
|
+
import { defaultConfig } from '../components/config';
|
|
3
|
+
let currentZIndex = 0;
|
|
3
4
|
export function useZIndex() {
|
|
4
|
-
|
|
5
|
+
if (currentZIndex === 0) {
|
|
6
|
+
currentZIndex = defaultConfig.initialZIndex;
|
|
7
|
+
}
|
|
8
|
+
const zIndex = ref(currentZIndex);
|
|
5
9
|
function increase() {
|
|
6
|
-
zIndex.value =
|
|
10
|
+
zIndex.value = currentZIndex = currentZIndex + 1;
|
|
7
11
|
}
|
|
8
12
|
return [zIndex, increase];
|
|
9
13
|
}
|
package/utils/bem.d.ts
CHANGED
|
@@ -7,17 +7,17 @@ export interface BemConfig {
|
|
|
7
7
|
type IsType = boolean | number | string | null | undefined | object;
|
|
8
8
|
export declare function createBemStruct(config: BemConfig): (block: string | number) => {
|
|
9
9
|
b(): string;
|
|
10
|
-
e(element: string | number | undefined, is?: IsType): string;
|
|
11
|
-
m(modifier: string | number | undefined, is?: IsType): string;
|
|
12
|
-
em(element: string | number, modifier: string | number | undefined, is?: IsType): string;
|
|
13
|
-
bem(block: string | number, element?: string | number, modifier?: string | number, is?: boolean | number | string | null): string;
|
|
10
|
+
e(element: string | number | undefined | null, is?: IsType): string;
|
|
11
|
+
m(modifier: string | number | undefined | null, is?: IsType): string;
|
|
12
|
+
em(element: string | number, modifier: string | number | undefined | null, is?: IsType): string;
|
|
13
|
+
bem(block: string | number, element?: string | number, modifier?: string | number, is?: boolean | number | string | undefined | null): string;
|
|
14
14
|
};
|
|
15
15
|
export declare const createBem: (block: string | number) => {
|
|
16
16
|
b(): string;
|
|
17
|
-
e(element: string | number | undefined, is?: IsType): string;
|
|
18
|
-
m(modifier: string | number | undefined, is?: IsType): string;
|
|
19
|
-
em(element: string | number, modifier: string | number | undefined, is?: IsType): string;
|
|
20
|
-
bem(block: string | number, element?: string | number, modifier?: string | number, is?: boolean | number | string | null): string;
|
|
17
|
+
e(element: string | number | undefined | null, is?: IsType): string;
|
|
18
|
+
m(modifier: string | number | undefined | null, is?: IsType): string;
|
|
19
|
+
em(element: string | number, modifier: string | number | undefined | null, is?: IsType): string;
|
|
20
|
+
bem(block: string | number, element?: string | number, modifier?: string | number, is?: boolean | number | string | undefined | null): string;
|
|
21
21
|
};
|
|
22
22
|
export type Bem = ReturnType<typeof createBem>;
|
|
23
23
|
export {};
|
package/utils/dom.d.ts
CHANGED
|
@@ -1,55 +1,5 @@
|
|
|
1
1
|
import { ComponentInternalInstance } from 'vue';
|
|
2
|
-
|
|
3
|
-
export interface ScrollIntoViewValueOptions {
|
|
4
|
-
position?: ScrollIntoViewPosition;
|
|
5
|
-
startOffset?: number;
|
|
6
|
-
endOffset?: number;
|
|
7
|
-
}
|
|
8
|
-
export interface ScrollIntoViewOptions {
|
|
9
|
-
position?: ScrollIntoViewPosition;
|
|
10
|
-
startOffset?: number;
|
|
11
|
-
endOffset?: number;
|
|
12
|
-
duration?: number;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
```
|
|
16
|
-
page
|
|
17
|
-
╱
|
|
18
|
-
╭───────────────╮ viewport
|
|
19
|
-
╭─│─ ─ ─ ─ ─ ─ ─ ─│─╮ ╱
|
|
20
|
-
│ │ ╭───────────╮ │ │
|
|
21
|
-
│ │ │ element │ │ │
|
|
22
|
-
│ │ ╰───────────╯ │ │
|
|
23
|
-
╰─│─ ─ ─ ─ ─ ─ ─ ─│─╯
|
|
24
|
-
│ │
|
|
25
|
-
│ │
|
|
26
|
-
╰───────────────╯
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
# 参数
|
|
30
|
-
- viewportHeight: viewport 高度
|
|
31
|
-
- viewportScrollTop: viewport 垂直滚动值
|
|
32
|
-
- elementHeight: element 高度
|
|
33
|
-
- elementOffsetTop: element 距离页面顶部距离
|
|
34
|
-
|
|
35
|
-
# 选项
|
|
36
|
-
- position: element 在视窗中的位置(start, center, end, nearest)
|
|
37
|
-
- startOffset: element 距离视窗顶部的偏移量
|
|
38
|
-
- endOffset: element 距离视窗底部的偏移量
|
|
39
|
-
|
|
40
|
-
# 结果值
|
|
41
|
-
- viewportScrollTop: viewport 新的垂直滚动值
|
|
42
|
-
|
|
43
|
-
*/
|
|
44
|
-
export declare function getScrollIntoViewValue(viewportHeight: number, viewportScrollTop: number, elementHeight: number, elementOffsetTop: number, options?: ScrollIntoViewValueOptions): number;
|
|
45
|
-
export interface NodeRect {
|
|
46
|
-
top: number;
|
|
47
|
-
right: number;
|
|
48
|
-
bottom: number;
|
|
49
|
-
left: number;
|
|
50
|
-
height: number;
|
|
51
|
-
width: number;
|
|
52
|
-
}
|
|
2
|
+
import { type NodeRect } from './geometry';
|
|
53
3
|
/**
|
|
54
4
|
* uni boundingClientRect的 Promise 版本
|
|
55
5
|
* @param selector 组件选择器
|
|
@@ -59,16 +9,8 @@ export interface NodeRect {
|
|
|
59
9
|
export declare function getBoundingClientRect(selector: string, instance: ComponentInternalInstance | null): Promise<NodeRect>;
|
|
60
10
|
/**
|
|
61
11
|
* 获取可使用窗口尺寸
|
|
62
|
-
* @returns Promise<WindowInfo>
|
|
63
12
|
*/
|
|
64
|
-
export declare function getWindowInfo():
|
|
65
|
-
export interface WindowInfo {
|
|
66
|
-
windowWidth: number;
|
|
67
|
-
windowHeight: number;
|
|
68
|
-
windowTop: number;
|
|
69
|
-
windowBottom: number;
|
|
70
|
-
statusBarHeight: number;
|
|
71
|
-
}
|
|
13
|
+
export declare function getWindowInfo(): UniNamespace.GetWindowInfoResult;
|
|
72
14
|
export interface ViewportScrollInfo {
|
|
73
15
|
scrollLeft: number;
|
|
74
16
|
scrollTop: number;
|
|
@@ -77,13 +19,5 @@ export interface ViewportScrollInfo {
|
|
|
77
19
|
* 获取可使用窗口尺寸、滚动信息
|
|
78
20
|
*/
|
|
79
21
|
export declare function getViewportScrollInfo(): Promise<ViewportScrollInfo>;
|
|
80
|
-
interface MatchScrollVisibleOptions {
|
|
81
|
-
offset?: number;
|
|
82
|
-
errorValue?: number;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @description: 匹配元素列表中第一个位于滚动盒子可视区域的元素
|
|
86
|
-
*/
|
|
87
|
-
export declare function matchScrollVisible(rects: NodeRect[], callback: (index: number) => unknown, options?: MatchScrollVisibleOptions): Promise<unknown>;
|
|
88
22
|
export declare function toTouchEvent(event: MouseEvent | TouchEvent, windowTop?: number): TouchEvent;
|
|
89
|
-
export
|
|
23
|
+
export declare function getNode<T = any>(selector: string, instance: ComponentInternalInstance | null): Promise<T>;
|