sard 1.0.2 → 1.0.3
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/components/preview-image/common.d.ts +3 -1
- package/components/preview-image/common.js +2 -0
- package/components/preview-image/preview-image.d.ts +2 -0
- package/components/preview-image/preview-image.js +17 -5
- package/components/swiper/useSwiper.js +10 -6
- package/components/swiper/useSwiperData.d.ts +10 -0
- package/components/swiper/useSwiperData.js +3 -1
- package/package.json +1 -1
|
@@ -2,9 +2,11 @@ import type { InjectionKey } from 'vue';
|
|
|
2
2
|
import { type DefaultProps } from '../config';
|
|
3
3
|
import type { MotionEmits } from '../motion';
|
|
4
4
|
export interface PreviewImageProps {
|
|
5
|
+
urls?: string[];
|
|
5
6
|
visible?: boolean;
|
|
6
7
|
current?: number;
|
|
7
|
-
|
|
8
|
+
showIndicator?: boolean;
|
|
9
|
+
loop?: boolean;
|
|
8
10
|
}
|
|
9
11
|
export declare const defaultPreviewImageProps: DefaultProps<PreviewImageProps>;
|
|
10
12
|
export interface PreviewImageSlots {
|
|
@@ -29,6 +29,8 @@ declare const __VLS_base: import("vue").DefineComponent<PreviewImageProps, Previ
|
|
|
29
29
|
visible: boolean;
|
|
30
30
|
current: number;
|
|
31
31
|
urls: string[];
|
|
32
|
+
showIndicator: boolean;
|
|
33
|
+
loop: boolean;
|
|
32
34
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
33
35
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
34
36
|
declare const _default: typeof __VLS_export;
|
|
@@ -8,13 +8,17 @@ import { defaultPreviewImageProps, previewImageContextKey } from "./common.js";
|
|
|
8
8
|
import swiper_default from "../swiper/swiper.js";
|
|
9
9
|
import swiper_item_default from "../swiper/swiper-item.js";
|
|
10
10
|
import preview_image_item_default from "./preview-image-item.js";
|
|
11
|
-
import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createVNode, defineComponent, isRef, mergeDefaults, normalizeClass, normalizeStyle, openBlock, provide, reactive, ref, renderList, toDisplayString, unref, useModel, watch, withCtx } from "vue";
|
|
11
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, isRef, mergeDefaults, normalizeClass, normalizeStyle, openBlock, provide, reactive, ref, renderList, toDisplayString, unref, useModel, watch, withCtx } from "vue";
|
|
12
12
|
//#region packages/sard/components/preview-image/preview-image.vue
|
|
13
13
|
const CLOSE_THRESHOLD = 80;
|
|
14
14
|
const SCALE_THRESHOLD = 300;
|
|
15
15
|
var preview_image_default = /*@__PURE__*/ defineComponent({
|
|
16
16
|
__name: "preview-image",
|
|
17
17
|
props: /*@__PURE__*/ mergeDefaults({
|
|
18
|
+
urls: {
|
|
19
|
+
type: Array,
|
|
20
|
+
required: false
|
|
21
|
+
},
|
|
18
22
|
visible: {
|
|
19
23
|
type: Boolean,
|
|
20
24
|
required: false
|
|
@@ -23,8 +27,12 @@ var preview_image_default = /*@__PURE__*/ defineComponent({
|
|
|
23
27
|
type: Number,
|
|
24
28
|
required: false
|
|
25
29
|
},
|
|
26
|
-
|
|
27
|
-
type:
|
|
30
|
+
showIndicator: {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
required: false
|
|
33
|
+
},
|
|
34
|
+
loop: {
|
|
35
|
+
type: Boolean,
|
|
28
36
|
required: false
|
|
29
37
|
}
|
|
30
38
|
}, defaultPreviewImageProps),
|
|
@@ -146,7 +154,7 @@ var preview_image_default = /*@__PURE__*/ defineComponent({
|
|
|
146
154
|
}, [createVNode(unref(swiper_default), {
|
|
147
155
|
modelValue: unref(current),
|
|
148
156
|
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(current) ? current.value = $event : null),
|
|
149
|
-
loop:
|
|
157
|
+
loop: __props.loop,
|
|
150
158
|
duration: visibleSwitching.value ? 0 : 300,
|
|
151
159
|
"space-between": 20,
|
|
152
160
|
class: normalizeClass([unref(bem).e("swiper"), unref(bem).is("preview-image")])
|
|
@@ -160,9 +168,13 @@ var preview_image_default = /*@__PURE__*/ defineComponent({
|
|
|
160
168
|
_: 1
|
|
161
169
|
}, 8, [
|
|
162
170
|
"modelValue",
|
|
171
|
+
"loop",
|
|
163
172
|
"duration",
|
|
164
173
|
"class"
|
|
165
|
-
])], 38), createElementVNode("div", { class: normalizeClass(unref(bem).e("toolbar")) }, [
|
|
174
|
+
])], 38), createElementVNode("div", { class: normalizeClass(unref(bem).e("toolbar")) }, [__props.showIndicator ? (openBlock(), createElementBlock("div", {
|
|
175
|
+
key: 0,
|
|
176
|
+
class: normalizeClass(unref(bem).e("indicator"))
|
|
177
|
+
}, toDisplayString(unref(current) + 1) + " / " + toDisplayString(__props.urls.length), 3)) : createCommentVNode("v-if", true)], 2)]),
|
|
166
178
|
_: 1
|
|
167
179
|
}, 8, ["overlay-class", "visible"]);
|
|
168
180
|
};
|
|
@@ -43,13 +43,13 @@ function useSwiper(props, emit) {
|
|
|
43
43
|
const setSwiperItems = (_swiperItems) => {
|
|
44
44
|
swiperItems = _swiperItems;
|
|
45
45
|
};
|
|
46
|
-
const { offset, swiperSize, startEdge, endEdge, activeIndex, slidesPerView, slidesPerGroup, spaceBetween, centeredSlides, pageCount, loop,
|
|
46
|
+
const { offset, swiperSize, startEdge, endEdge, activeIndex, slidesPerView, slidesPerGroup, spaceBetween, centeredSlides, pageCount, loop, slides, setSlides, getNearestOffset, getPreviousNearestOffset, getNextNearestOffset, getNextIndexOffset, normalizeLoopOffset, snapTo } = useSwiperData();
|
|
47
47
|
watchSyncEffect(() => {
|
|
48
48
|
slidesPerView.value = props.slidesPerView;
|
|
49
49
|
spaceBetween.value = props.spaceBetween;
|
|
50
50
|
slidesPerGroup.value = Math.floor(Math.max(Math.min(props.slidesPerGroup, props.slidesPerView), 1));
|
|
51
51
|
centeredSlides.value = props.centeredSlides;
|
|
52
|
-
loop.value = props.loop;
|
|
52
|
+
loop.value = props.loop && slides.value.length > 1;
|
|
53
53
|
});
|
|
54
54
|
watchPostEffect(() => {
|
|
55
55
|
const wrapper = wrapperRef.value;
|
|
@@ -76,14 +76,18 @@ function useSwiper(props, emit) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
+
activeIndex.value = Number(props.modelValue) || 0;
|
|
79
80
|
watch(() => props.modelValue, (index) => {
|
|
80
81
|
if (!isNullish(index)) {
|
|
81
82
|
index = clamp(~~index, 0, pageCount.value - 1);
|
|
82
|
-
if (index !== activeIndex.value)
|
|
83
|
-
|
|
84
|
-
index
|
|
85
|
-
}
|
|
83
|
+
if (index !== activeIndex.value) {
|
|
84
|
+
activeIndex.value = index;
|
|
85
|
+
snapTo(index);
|
|
86
|
+
}
|
|
86
87
|
}
|
|
88
|
+
}, { flush: "post" });
|
|
89
|
+
onMounted(() => {
|
|
90
|
+
snapTo(props.modelValue);
|
|
87
91
|
});
|
|
88
92
|
let startX = 0;
|
|
89
93
|
let startY = 0;
|
|
@@ -16,6 +16,15 @@ export declare function useSwiperData(): {
|
|
|
16
16
|
centeredSlides: import("vue").Ref<boolean, boolean>;
|
|
17
17
|
loop: import("vue").Ref<boolean, boolean>;
|
|
18
18
|
pageCount: import("vue").ComputedRef<number>;
|
|
19
|
+
slides: import("vue").Ref<{
|
|
20
|
+
el: HTMLElement | null;
|
|
21
|
+
size: number;
|
|
22
|
+
offset: number;
|
|
23
|
+
}[], SwiperSlideData[] | {
|
|
24
|
+
el: HTMLElement | null;
|
|
25
|
+
size: number;
|
|
26
|
+
offset: number;
|
|
27
|
+
}[]>;
|
|
19
28
|
setSlides: (_slides: SwiperSlideData[]) => void;
|
|
20
29
|
getOffsetByIndex: (index: number) => number;
|
|
21
30
|
getNearestOffset: (forceSide?: "before" | "after") => {
|
|
@@ -46,4 +55,5 @@ export declare function useSwiperData(): {
|
|
|
46
55
|
index: number;
|
|
47
56
|
};
|
|
48
57
|
normalizeLoopOffset: (nextOffset: number) => number;
|
|
58
|
+
snapTo: (index: number) => void;
|
|
49
59
|
};
|
|
@@ -207,6 +207,7 @@ function useSwiperData() {
|
|
|
207
207
|
centeredSlides,
|
|
208
208
|
loop,
|
|
209
209
|
pageCount,
|
|
210
|
+
slides,
|
|
210
211
|
setSlides,
|
|
211
212
|
getOffsetByIndex,
|
|
212
213
|
getNearestOffset,
|
|
@@ -221,7 +222,8 @@ function useSwiperData() {
|
|
|
221
222
|
getPreviousIndex,
|
|
222
223
|
getNextIndexOffset,
|
|
223
224
|
getPreviousIndexOffset,
|
|
224
|
-
normalizeLoopOffset
|
|
225
|
+
normalizeLoopOffset,
|
|
226
|
+
snapTo
|
|
225
227
|
};
|
|
226
228
|
}
|
|
227
229
|
//#endregion
|