sard 1.0.21 → 1.0.23
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/button/button.vue.d.ts +1 -1
- package/components/count-to/count-to.vue.d.ts +1 -1
- package/components/count-to/count-to.vue.js +5 -5
- package/components/floating-panel/floating-panel.vue.d.ts +1 -1
- package/components/input/input.vue.d.ts +1 -1
- package/components/progress-bar/progress-bar.vue.d.ts +1 -1
- package/components/progress-circle/progress-circle.vue.d.ts +1 -1
- package/components/skeleton/skeleton.vue.d.ts +1 -1
- package/components/swiper/useSwiperAnimation.js +5 -5
- package/components/tabbar/tabbar.vue.d.ts +1 -1
- package/components/tag/tag.vue.d.ts +1 -1
- package/index.js +2 -3
- package/package.json +1 -3
- package/use/index.d.ts +0 -1
- package/use/index.js +1 -2
- package/use/useLuckyDraw.js +1 -1
- package/use/usePopper.js +1 -1
- package/utils/animation.d.ts +31 -0
- package/utils/animation.js +56 -0
- package/utils/index.js +2 -2
- package/utils/inertialAnimate.js +1 -1
- package/utils/number.d.ts +18 -0
- package/utils/number.js +57 -1
- package/utils/scroller/useEasingAnimation.js +5 -5
- package/utils/scroller/useScrollAnimation.js +1 -1
- package/use/useImperative.d.ts +0 -11
- package/use/useImperative.js +0 -44
|
@@ -5,12 +5,12 @@ declare const __VLS_base: import("vue").DefineComponent<ButtonProps, {}, {}, {},
|
|
|
5
5
|
}, string, import("vue").PublicProps, Readonly<ButtonProps> & Readonly<{
|
|
6
6
|
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
7
7
|
}>, {
|
|
8
|
+
round: boolean;
|
|
8
9
|
size: "xs" | "small" | "medium" | "large";
|
|
9
10
|
loading: boolean;
|
|
10
11
|
disabled: boolean;
|
|
11
12
|
color: "primary" | "secondary" | "success" | "warning" | "danger" | "white" | "black";
|
|
12
13
|
square: boolean;
|
|
13
|
-
round: boolean;
|
|
14
14
|
variant: "solid" | "outlined" | "dashed" | "filled" | "text" | "link";
|
|
15
15
|
loadingType: "clock" | "circular";
|
|
16
16
|
block: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type CountToProps } from './common';
|
|
2
2
|
declare const __VLS_export: import("vue").DefineComponent<CountToProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CountToProps> & Readonly<{}>, {
|
|
3
|
-
value: number;
|
|
4
3
|
duration: number;
|
|
4
|
+
value: number;
|
|
5
5
|
separator: string;
|
|
6
6
|
precision: number;
|
|
7
7
|
separatorDigit: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { addSeparator } from "../../utils/string.js";
|
|
2
|
+
import { animateNumber } from "../../utils/animation.js";
|
|
2
3
|
import { defaultCountToProps } from "./common.js";
|
|
3
4
|
import { computed, createElementBlock, defineComponent, mergeDefaults, onUnmounted, openBlock, ref, toDisplayString, watch } from "vue";
|
|
4
|
-
import { createAnimation } from "lwa";
|
|
5
5
|
//#region packages/sard/components/count-to/count-to.vue
|
|
6
6
|
var count_to_default = /*@__PURE__*/ defineComponent({
|
|
7
7
|
__name: "count-to",
|
|
@@ -30,14 +30,14 @@ var count_to_default = /*@__PURE__*/ defineComponent({
|
|
|
30
30
|
setup(__props) {
|
|
31
31
|
const props = __props;
|
|
32
32
|
const number = ref(0);
|
|
33
|
-
let
|
|
33
|
+
let animation;
|
|
34
34
|
const renderedNumer = computed(() => {
|
|
35
35
|
const fixedNum = number.value.toFixed(props.precision);
|
|
36
36
|
return props.separator ? addSeparator(fixedNum, props.separator, props.separatorDigit) : fixedNum;
|
|
37
37
|
});
|
|
38
38
|
watch(() => props.value, () => {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
animation?.pause();
|
|
40
|
+
animation = animateNumber(number, props.value, {
|
|
41
41
|
duration: props.duration,
|
|
42
42
|
easing: "easeOutQuint",
|
|
43
43
|
round: Math.pow(10, props.precision)
|
|
@@ -47,7 +47,7 @@ var count_to_default = /*@__PURE__*/ defineComponent({
|
|
|
47
47
|
immediate: true
|
|
48
48
|
});
|
|
49
49
|
onUnmounted(() => {
|
|
50
|
-
|
|
50
|
+
animation?.pause();
|
|
51
51
|
});
|
|
52
52
|
return (_ctx, _cache) => {
|
|
53
53
|
return openBlock(), createElementBlock("span", null, toDisplayString(renderedNumer.value), 1);
|
|
@@ -7,8 +7,8 @@ declare const __VLS_base: import("vue").DefineComponent<FloatingPanelProps, Floa
|
|
|
7
7
|
"onUpdate:height"?: ((value: number) => any) | undefined;
|
|
8
8
|
"onHeight-change"?: ((value: number) => any) | undefined;
|
|
9
9
|
}>, {
|
|
10
|
-
height: number;
|
|
11
10
|
duration: number;
|
|
11
|
+
height: number;
|
|
12
12
|
anchors: number[];
|
|
13
13
|
contentDraggable: boolean;
|
|
14
14
|
safeAreaInsetBottom: boolean;
|
|
@@ -32,7 +32,7 @@ declare const __VLS_base: import("vue").DefineComponent<InputProps, InputExpose,
|
|
|
32
32
|
autoHeight: import("./common").InputAutoHeight;
|
|
33
33
|
formatter: (value: string, trigger: "input" | "change") => string;
|
|
34
34
|
placeholder: string;
|
|
35
|
-
inputmode: "text" | "search" | "none" | "url" | "email" | "tel" | "numeric"
|
|
35
|
+
inputmode: "decimal" | "text" | "search" | "none" | "url" | "email" | "tel" | "numeric";
|
|
36
36
|
enterkeyhint: "search" | "done" | "enter" | "next" | "go" | "previous" | "send";
|
|
37
37
|
spellcheck: boolean | "true" | "false";
|
|
38
38
|
modelModifiers: import("./common").InputModelModifiers;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type ProgressBarProps, type ProgressBarSlots } from './common';
|
|
2
2
|
type __VLS_Slots = ProgressBarSlots;
|
|
3
3
|
declare const __VLS_base: import("vue").DefineComponent<ProgressBarProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ProgressBarProps> & Readonly<{}>, {
|
|
4
|
+
percent: number;
|
|
4
5
|
animated: boolean;
|
|
5
6
|
color: string;
|
|
6
7
|
status: "success" | "warning" | "error";
|
|
7
8
|
inside: boolean;
|
|
8
|
-
percent: number;
|
|
9
9
|
trackColor: string;
|
|
10
10
|
thickness: string;
|
|
11
11
|
showText: boolean;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type ProgressCircleProps, type ProgressCircleSlots } from './common';
|
|
2
2
|
type __VLS_Slots = ProgressCircleSlots;
|
|
3
3
|
declare const __VLS_base: import("vue").DefineComponent<ProgressCircleProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ProgressCircleProps> & Readonly<{}>, {
|
|
4
|
+
percent: number;
|
|
4
5
|
size: string;
|
|
5
6
|
color: string;
|
|
6
7
|
status: "success" | "warning" | "error";
|
|
7
|
-
percent: number;
|
|
8
8
|
trackColor: string;
|
|
9
9
|
thickness: number;
|
|
10
10
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -3,8 +3,8 @@ type __VLS_Slots = SkeletonSlots;
|
|
|
3
3
|
declare const __VLS_base: import("vue").DefineComponent<SkeletonProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<SkeletonProps> & Readonly<{}>, {
|
|
4
4
|
title: boolean;
|
|
5
5
|
animated: boolean;
|
|
6
|
-
loading: boolean;
|
|
7
6
|
round: boolean;
|
|
7
|
+
loading: boolean;
|
|
8
8
|
avatar: boolean;
|
|
9
9
|
rows: number;
|
|
10
10
|
avatarSize: string;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { animateNumber } from "../../utils/animation.js";
|
|
1
2
|
import { withResolvers } from "../../utils/polyfill.js";
|
|
2
3
|
import { onUnmounted } from "vue";
|
|
3
|
-
import { createAnimation } from "lwa";
|
|
4
4
|
//#region packages/sard/components/swiper/useSwiperAnimation.ts
|
|
5
5
|
function useSwiperAnimation(target) {
|
|
6
|
-
let
|
|
6
|
+
let animation;
|
|
7
7
|
let promiseWithResolvers;
|
|
8
8
|
const play = (value, duration, update) => {
|
|
9
|
-
|
|
9
|
+
animation?.pause();
|
|
10
10
|
promiseWithResolvers = withResolvers();
|
|
11
|
-
|
|
11
|
+
animation = animateNumber(target, value, {
|
|
12
12
|
duration,
|
|
13
13
|
easing: "easeOutCubic",
|
|
14
14
|
update,
|
|
@@ -19,7 +19,7 @@ function useSwiperAnimation(target) {
|
|
|
19
19
|
return promiseWithResolvers.promise;
|
|
20
20
|
};
|
|
21
21
|
const pause = () => {
|
|
22
|
-
|
|
22
|
+
animation?.pause();
|
|
23
23
|
};
|
|
24
24
|
onUnmounted(() => {
|
|
25
25
|
pause();
|
|
@@ -7,8 +7,8 @@ declare const __VLS_base: import("vue").DefineComponent<TabbarProps, {}, {}, {},
|
|
|
7
7
|
onChange?: ((value: string | number) => any) | undefined;
|
|
8
8
|
"onUpdate:modelValue"?: ((value: string | number) => any) | undefined;
|
|
9
9
|
}>, {
|
|
10
|
-
fixed: boolean;
|
|
11
10
|
modelValue: number | string;
|
|
11
|
+
fixed: boolean;
|
|
12
12
|
color: string;
|
|
13
13
|
bordered: boolean;
|
|
14
14
|
safeAreaInsetBottom: boolean;
|
|
@@ -8,10 +8,10 @@ declare const __VLS_base: import("vue").DefineComponent<TagProps, {}, {}, {}, {}
|
|
|
8
8
|
onClose?: ((event: any) => any) | undefined;
|
|
9
9
|
}>, {
|
|
10
10
|
mark: "left" | "right";
|
|
11
|
+
round: boolean;
|
|
11
12
|
size: "small" | "medium" | "large";
|
|
12
13
|
color: "default" | "primary" | "success" | "warning" | "danger";
|
|
13
14
|
closable: boolean;
|
|
14
|
-
round: boolean;
|
|
15
15
|
variant: "filled" | "solid" | "outlined";
|
|
16
16
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
17
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createBem, createBemStruct, cssVar, cssVarName, defaultBemConfig } from "./utils/bem.js";
|
|
2
|
-
import { clamp, formatNumber, getDecimalsLength, inRange, looseToNumber, mround, random, round } from "./utils/number.js";
|
|
2
|
+
import { abbrNumber, clamp, formatNumber, formatThousands, getDecimalsLength, inRange, looseToNumber, mround, random, round, truncToFixed } from "./utils/number.js";
|
|
3
3
|
import { baseLunarYear, earthlyBranches, formatDate, getDayOfYear, getDaysAfterLastDay, getDaysBeforeFirstDay, getDaysInMonth, getDaysSinceUnixEpoch, getFirstDayWeekday, getLunarDayName, getLunarHourName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, getLunarYearDays, getLunarYearName, getNextMonthDate, getNextMonthHeadDays, getPrevMonthDate, getPrevMonthTailDays, heavenlyStems, isLeapYear, lunarDayNames, lunarInfo, lunarMonthNames, lunarToSolar, lunarYearNames, minmaxDate, parseDate, solarToLunar, springFestivals, toDate, toDateNumber, toDateString, toMonthNumber } from "./utils/date.js";
|
|
4
4
|
import { checkRtl, getScrollTop, toTouchEvent } from "./utils/dom.js";
|
|
5
5
|
import { chooseFile, getFileName, imageDataToDataURL, isFileUrl, isImageFile, isImageUrl, isVideoFile, isVideoUrl, loadImage, readFileContent } from "./utils/file.js";
|
|
@@ -24,7 +24,6 @@ import { Friction } from "./utils/scroller/Friction.js";
|
|
|
24
24
|
import { Spring } from "./utils/scroller/Spring.js";
|
|
25
25
|
import { useTimeout } from "./use/useTimeout.js";
|
|
26
26
|
import { useZIndex } from "./use/useZIndex.js";
|
|
27
|
-
import { getAllImperatives, getAvailableImperative, getImperatives, useImperative } from "./use/useImperative.js";
|
|
28
27
|
import { useLuckyDraw } from "./use/useLuckyDraw.js";
|
|
29
28
|
import { getGridCenterSize, getGridIndex, getGridPrizeCount, useLuckyGrid } from "./use/useLuckyGrid.js";
|
|
30
29
|
import { useLuckyWheel } from "./use/useLuckyWheel.js";
|
|
@@ -217,4 +216,4 @@ function prepareEnvironment() {
|
|
|
217
216
|
});
|
|
218
217
|
}
|
|
219
218
|
//#endregion
|
|
220
|
-
export { ADD_SWIPER_CONTEXT_KEY, ALPHANUMERIC_CHARS, Accordion, AccordionItem, ActionSheet, ActionSheetItem, Alert, Avatar, AvatarGroup, BackTop, Badge, Barcode, BarcodeFormatList, BarcodeTextPositionList, Button, Calendar, CalendarInput, CalendarPopout, CancelError, Card, Cascader, CascaderInput, CascaderPopout, Checkbox, CheckboxGroup, CheckboxInput, CheckboxPopout, Col, Collapse, ColorPicker, ColorPickerInput, ColorPickerPopout, Compact, CoolIcon, CountDown, CountTo, CropImage, DateStrip, DatetimePicker, DatetimePickerInput, DatetimePickerPopout, DatetimeRangePicker, DatetimeRangePickerInput, DatetimeRangePickerPopout, Descriptions, DescriptionsItem, Dialog, Divider, Dnd, DndHandle, DndItem, Dropdown, DropdownItem, ECLList, Ellipsis, Empty, Fab, FabItem, Flex, FloatingBubble, FloatingPanel, Form, FormItem, FormItemPlain, FormPlain, Friction, Grid, GridItem, Image, Indexes, IndexesAnchor, IndexesNav, Input, Keyboard, KeyboardPopout, List, ListItem, LoadMore, LoadMoreStatus, Loading, Marquee, Menu, MenuItem, Motion, Navbar, NavbarItem, NavbarPit, NoticeBar, Notify, OnlyChild, Overlay, Pagination, PasswordInput, Picker, PickerInput, PickerPopout, PickerView, PickerViewColumn, Popout, PopoutInput, Popover, Popup, PreviewImage, ProgressBar, ProgressCircle, PullDownRefresh, PuzzleVerify, Qrcode, REMOVE_SWIPER_CONTEXT_KEY, Radio, RadioGroup, RadioInput, RadioPopout, Rate, ReadMore, Result, RotateVerify, Row, SWIPER_AUTO_HEIGHT_KEY, ScrollList, ScrollSpy, ScrollSpyAnchor, Search, Segmented, SegmentedItem, Select, SelectInput, SelectOption, SelectOptionGroup, SelectPopout, ShareSheet, ShareSheetIcon, ShareSheetItem, ShareSheetRow, Sidebar, SidebarItem, Signature, Skeleton, SkeletonAvatar, SkeletonBlock, SkeletonParagraph, SkeletonTitle, SlideVerify, Slider, Spring, StatusBar, Step, Stepper, Steps, Sticky, StickyBox, SwipeAction, Swiper, SwiperItem, Switch, Tab, Tabbar, TabbarItem, TabbarPit, Table, Tabs, Tag, Text, Timeline, TimelineItem, Toast, Tree, TreeBranch, TreeNode, Upload, UploadPreview, Waterfall, WaterfallItem, WaterfallLoad, Watermark, actionSheet, addSeparator, addUnit, arrayEqual, arrayMove, assignDeep, autoUpdate, barcode, baseLunarYear, calculateBarcodeLayout, camelCase, capitalize, chainGet, chainSet, checkRtl, chooseFile, clamp, clipboard, computePosition, createActionSheet, createBem, createBemStruct, createCropImage, createDialog, createInertialAnimate, createNotify, createPreviewImage, createToast, cropImage, cssVar, cssVarName, currentLocale, debounce, deepClone, defaultBemConfig, defaultColorPickerPresets, defaultColorPickerValue, defaultOptionKeys, defineSetupFnComponent, dialog, earthlyBranches, enhanceComponent, extend, flatVNode, flexGap, formatColor, formatDate, formatNumber,
|
|
219
|
+
export { ADD_SWIPER_CONTEXT_KEY, ALPHANUMERIC_CHARS, Accordion, AccordionItem, ActionSheet, ActionSheetItem, Alert, Avatar, AvatarGroup, BackTop, Badge, Barcode, BarcodeFormatList, BarcodeTextPositionList, Button, Calendar, CalendarInput, CalendarPopout, CancelError, Card, Cascader, CascaderInput, CascaderPopout, Checkbox, CheckboxGroup, CheckboxInput, CheckboxPopout, Col, Collapse, ColorPicker, ColorPickerInput, ColorPickerPopout, Compact, CoolIcon, CountDown, CountTo, CropImage, DateStrip, DatetimePicker, DatetimePickerInput, DatetimePickerPopout, DatetimeRangePicker, DatetimeRangePickerInput, DatetimeRangePickerPopout, Descriptions, DescriptionsItem, Dialog, Divider, Dnd, DndHandle, DndItem, Dropdown, DropdownItem, ECLList, Ellipsis, Empty, Fab, FabItem, Flex, FloatingBubble, FloatingPanel, Form, FormItem, FormItemPlain, FormPlain, Friction, Grid, GridItem, Image, Indexes, IndexesAnchor, IndexesNav, Input, Keyboard, KeyboardPopout, List, ListItem, LoadMore, LoadMoreStatus, Loading, Marquee, Menu, MenuItem, Motion, Navbar, NavbarItem, NavbarPit, NoticeBar, Notify, OnlyChild, Overlay, Pagination, PasswordInput, Picker, PickerInput, PickerPopout, PickerView, PickerViewColumn, Popout, PopoutInput, Popover, Popup, PreviewImage, ProgressBar, ProgressCircle, PullDownRefresh, PuzzleVerify, Qrcode, REMOVE_SWIPER_CONTEXT_KEY, Radio, RadioGroup, RadioInput, RadioPopout, Rate, ReadMore, Result, RotateVerify, Row, SWIPER_AUTO_HEIGHT_KEY, ScrollList, ScrollSpy, ScrollSpyAnchor, Search, Segmented, SegmentedItem, Select, SelectInput, SelectOption, SelectOptionGroup, SelectPopout, ShareSheet, ShareSheetIcon, ShareSheetItem, ShareSheetRow, Sidebar, SidebarItem, Signature, Skeleton, SkeletonAvatar, SkeletonBlock, SkeletonParagraph, SkeletonTitle, SlideVerify, Slider, Spring, StatusBar, Step, Stepper, Steps, Sticky, StickyBox, SwipeAction, Swiper, SwiperItem, Switch, Tab, Tabbar, TabbarItem, TabbarPit, Table, Tabs, Tag, Text, Timeline, TimelineItem, Toast, Tree, TreeBranch, TreeNode, Upload, UploadPreview, Waterfall, WaterfallItem, WaterfallLoad, Watermark, abbrNumber, actionSheet, addSeparator, addUnit, arrayEqual, arrayMove, assignDeep, autoUpdate, barcode, baseLunarYear, calculateBarcodeLayout, camelCase, capitalize, chainGet, chainSet, checkRtl, chooseFile, clamp, clipboard, computePosition, createActionSheet, createBem, createBemStruct, createCropImage, createDialog, createInertialAnimate, createNotify, createPreviewImage, createToast, cropImage, cssVar, cssVarName, currentLocale, debounce, deepClone, defaultBemConfig, defaultColorPickerPresets, defaultColorPickerValue, defaultOptionKeys, defineSetupFnComponent, dialog, earthlyBranches, enhanceComponent, extend, flatVNode, flexGap, formatColor, formatDate, formatNumber, formatThousands, formatTime, getAspectFillSize, getAspectFitSize, getCurrentTime, getDampingValue, getDayOfYear, getDaysAfterLastDay, getDaysBeforeFirstDay, getDaysInMonth, getDaysSinceUnixEpoch, getDecimalsLength, getFileName, getFirstDayWeekday, getGridCenterSize, getGridIndex, getGridPrizeCount, getInBoundValue, getLeafNodes, getLunarDayName, getLunarHourName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, getLunarYearDays, getLunarYearName, getNextMonthDate, getNextMonthHeadDays, getNodeLevel, getOverflowRangeInArea, getPageRange, getPrevMonthDate, getPrevMonthTailDays, getPreviewColor, getRectDampingValue, getRotatedRect, getScrollIntoViewValue, getScrollTop, getTouchPoint, getTransformOrigin, getTreeCheckedKeys, getTreeHalfCheckedKeys, getTwoPointsDistance, heavenlyStems, hslToHsv, hslToHwb, hslToRgb, hsvToHsl, hwbToHsl, imageDataToDataURL, inRange, initializeCheckNodes, installer, interpolate, isBoolean, isCancelError, isColorScheme, isConfigObject, isDate, isEmptyArray, isEmptyBinding, isEmptyValue, isFileUrl, isFunction, isImageFile, isImageUrl, isKorean, isLeapYear, isNoEmptyArray, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isRectEqual, isRenderVisible, isSizeEqual, isString, isUndefined, isVideoFile, isVideoUrl, isVisibleEmpty, kebabCase, loadImage, localeContextKey, logError, looseToNumber, lowerFirst, lunarDayNames, lunarInfo, lunarMonthNames, lunarToSolar, lunarYearNames, mapTreeToGrid, matchScrollVisible, measureTextWidth, minmaxDate, mround, nestedToMulti, noop, normalizeBarcodeOptions, normalizeHsla, normalizeHsva, notify, omit, omitFormPopoutProps, parseColor, parseDate, partition, partitionPopoutInputProps, pascalCase, pick, plateEnglishLetterKeys, plateProvinceKeys, plateSuffixKeys, popupManager, prepareEnvironment, previewImage, provideColorScheme, provideLocale, qrcode, random, reactiveComputed, readFileContent, rgbToHsl, round, safeAreaInsets, scrollToTarget, setCheckedRecursively, setLocale, shuffle, sleep, snakeCase, solarToLunar, splitUnit, spreadEach, springFestivals, throttle, toArray, toDate, toDateNumber, toDateString, toMonthNumber, toReactive, toTouchEvent, toast, treeToMap, truncToFixed, uniqid, updateAncestorsChecked, upperFirst, useClickOutside, useColorScheme, useComposition, useCountDown, useDragPinch, useElementBackTop, useElementScroll, useFormContext, useFormItem, useFormItemContext, useFormPopout, useInPopup, useIndeterminate, useInitialVelocity, useIntersectionObserver, useKeyList, useLocale, useLockScroll, useLuckyDraw, useLuckyGrid, useLuckyWheel, useMotioning, useOptionKeys, usePageBackTop, usePageScroll, usePointerDown, usePopoutInput, usePopper, usePopupEnter, usePopupVisibleHookProvide, useReachBottom, useResizeObserver, useRtl, useScrollSide, useScrollSpy, useScroller, useSimulatedClick, useSimulatedDblClick, useSimulatedPress, useSingleTask, useSlotMachine, useStopMovedClick, useTimeout, useTimeoutLoading, useTranslate, useTranslateWithPrefix, useWindowResize, useZIndex, walkAncestor, walkDescendant, walkNodes, windowInfo, withResolvers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "sard 是基于 Vue3 的 Web 移动端 UI 组件库",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"UI",
|
|
@@ -20,12 +20,10 @@
|
|
|
20
20
|
"main": "index.js",
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@sard/icons": "^0.1.0",
|
|
23
|
-
"lwa": "^0.3.0",
|
|
24
23
|
"vue": "^3.5.0"
|
|
25
24
|
},
|
|
26
25
|
"peerDependencies": {
|
|
27
26
|
"@sard/icons": "^0.1.0",
|
|
28
|
-
"lwa": "^0.3.0",
|
|
29
27
|
"vue": "^3.5.0"
|
|
30
28
|
}
|
|
31
29
|
}
|
package/use/index.d.ts
CHANGED
package/use/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useTimeout } from "./useTimeout.js";
|
|
2
2
|
import { useZIndex } from "./useZIndex.js";
|
|
3
|
-
import { getAllImperatives, getAvailableImperative, getImperatives, useImperative } from "./useImperative.js";
|
|
4
3
|
import { useLuckyDraw } from "./useLuckyDraw.js";
|
|
5
4
|
import { getGridCenterSize, getGridIndex, getGridPrizeCount, useLuckyGrid } from "./useLuckyGrid.js";
|
|
6
5
|
import { useLuckyWheel } from "./useLuckyWheel.js";
|
|
@@ -33,4 +32,4 @@ import { useRtl } from "./useRtl.js";
|
|
|
33
32
|
import { autoUpdate, computePosition, usePopper } from "./usePopper.js";
|
|
34
33
|
import { useClickOutside } from "./useClickOutside.js";
|
|
35
34
|
import { isColorScheme, provideColorScheme, useColorScheme } from "./useColorScheme.js";
|
|
36
|
-
export { autoUpdate, computePosition, defaultOptionKeys,
|
|
35
|
+
export { autoUpdate, computePosition, defaultOptionKeys, getGridCenterSize, getGridIndex, getGridPrizeCount, isColorScheme, provideColorScheme, reactiveComputed, toReactive, useClickOutside, useColorScheme, useComposition, useDragPinch, useElementScroll, useIndeterminate, useInitialVelocity, useIntersectionObserver, useKeyList, useLockScroll, useLuckyDraw, useLuckyGrid, useLuckyWheel, useOptionKeys, usePageScroll, usePointerDown, usePopper, useReachBottom, useResizeObserver, useRtl, useScrollSide, useScrollSpy, useSimulatedClick, useSimulatedDblClick, useSimulatedPress, useSingleTask, useSlotMachine, useStopMovedClick, useTimeout, useTimeoutLoading, useWindowResize, useZIndex };
|
package/use/useLuckyDraw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { random } from "../utils/number.js";
|
|
2
|
+
import { ticker } from "../utils/animation.js";
|
|
2
3
|
import { computed, onScopeDispose, ref, unref } from "vue";
|
|
3
|
-
import { ticker } from "lwa";
|
|
4
4
|
//#region packages/sard/use/useLuckyDraw.ts
|
|
5
5
|
const defaultOptions = {
|
|
6
6
|
minSpeed: .1,
|
package/use/usePopper.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clamp } from "../utils/number.js";
|
|
2
2
|
import { isRectEqual } from "../utils/geometry.js";
|
|
3
|
+
import { ticker } from "../utils/animation.js";
|
|
3
4
|
import { onBeforeUnmount, reactive, watch } from "vue";
|
|
4
|
-
import { ticker } from "lwa";
|
|
5
5
|
//#region packages/sard/use/usePopper.ts
|
|
6
6
|
const directions = [
|
|
7
7
|
"top",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
type TickCallback = () => void;
|
|
3
|
+
/**
|
|
4
|
+
* 基于单个 requestAnimationFrame 的共享循环,多个动画共用同一帧循环。
|
|
5
|
+
*/
|
|
6
|
+
export declare const ticker: {
|
|
7
|
+
add(callback: TickCallback): void;
|
|
8
|
+
remove(callback: TickCallback): void;
|
|
9
|
+
};
|
|
10
|
+
type EasingName = 'easeOutCubic' | 'easeOutQuint';
|
|
11
|
+
export interface AnimateNumberOptions {
|
|
12
|
+
/** 动画时长,单位毫秒 */
|
|
13
|
+
duration?: number;
|
|
14
|
+
/** 缓动函数名或自定义缓动函数 */
|
|
15
|
+
easing?: EasingName | ((k: number) => number);
|
|
16
|
+
/** 取整因子,每帧值会被舍入为 Math.round(value * round) / round */
|
|
17
|
+
round?: number;
|
|
18
|
+
/** 每帧更新后回调 */
|
|
19
|
+
update?: () => void;
|
|
20
|
+
/** 动画结束回调 */
|
|
21
|
+
complete?: () => void;
|
|
22
|
+
}
|
|
23
|
+
export interface Animation {
|
|
24
|
+
/** 暂停动画,暂停后不会触发 complete */
|
|
25
|
+
pause: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 将数字 ref 的 value 从当前值缓动到目标值,创建后自动播放。
|
|
29
|
+
*/
|
|
30
|
+
export declare function animateNumber(ref: Ref<number>, to: number, options?: AnimateNumberOptions): Animation;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region packages/sard/utils/animation.ts
|
|
2
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
3
|
+
let rafId = 0;
|
|
4
|
+
function loop() {
|
|
5
|
+
rafId = requestAnimationFrame(loop);
|
|
6
|
+
callbacks.forEach((callback) => callback());
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 基于单个 requestAnimationFrame 的共享循环,多个动画共用同一帧循环。
|
|
10
|
+
*/
|
|
11
|
+
const ticker = {
|
|
12
|
+
add(callback) {
|
|
13
|
+
callbacks.add(callback);
|
|
14
|
+
if (rafId === 0) rafId = requestAnimationFrame(loop);
|
|
15
|
+
},
|
|
16
|
+
remove(callback) {
|
|
17
|
+
callbacks.delete(callback);
|
|
18
|
+
if (rafId !== 0 && callbacks.size === 0) {
|
|
19
|
+
cancelAnimationFrame(rafId);
|
|
20
|
+
rafId = 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const easings = {
|
|
25
|
+
easeOutCubic: (k) => 1 - Math.pow(1 - k, 3),
|
|
26
|
+
easeOutQuint: (k) => 1 - Math.pow(1 - k, 5)
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 将数字 ref 的 value 从当前值缓动到目标值,创建后自动播放。
|
|
30
|
+
*/
|
|
31
|
+
function animateNumber(ref, to, options = {}) {
|
|
32
|
+
const { duration = 0, easing = "easeOutCubic", round, update, complete } = options;
|
|
33
|
+
const easingFn = typeof easing === "function" ? easing : easings[easing];
|
|
34
|
+
const from = ref.value;
|
|
35
|
+
const change = to - from;
|
|
36
|
+
const start = performance.now();
|
|
37
|
+
const setValue = (value) => {
|
|
38
|
+
ref.value = round === void 0 ? value : Math.round(value * round) / round;
|
|
39
|
+
};
|
|
40
|
+
const tick = () => {
|
|
41
|
+
const progress = duration > 0 ? Math.min((performance.now() - start) / duration, 1) : 1;
|
|
42
|
+
setValue(from + change * easingFn(progress));
|
|
43
|
+
update?.();
|
|
44
|
+
if (progress >= 1) {
|
|
45
|
+
pause();
|
|
46
|
+
complete?.();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const pause = () => {
|
|
50
|
+
ticker.remove(tick);
|
|
51
|
+
};
|
|
52
|
+
ticker.add(tick);
|
|
53
|
+
return { pause };
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { animateNumber, ticker };
|
package/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createBem, createBemStruct, cssVar, cssVarName, defaultBemConfig } from "./bem.js";
|
|
2
|
-
import { clamp, formatNumber, getDecimalsLength, inRange, looseToNumber, mround, random, round } from "./number.js";
|
|
2
|
+
import { abbrNumber, clamp, formatNumber, formatThousands, getDecimalsLength, inRange, looseToNumber, mround, random, round, truncToFixed } from "./number.js";
|
|
3
3
|
import { baseLunarYear, earthlyBranches, formatDate, getDayOfYear, getDaysAfterLastDay, getDaysBeforeFirstDay, getDaysInMonth, getDaysSinceUnixEpoch, getFirstDayWeekday, getLunarDayName, getLunarHourName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, getLunarYearDays, getLunarYearName, getNextMonthDate, getNextMonthHeadDays, getPrevMonthDate, getPrevMonthTailDays, heavenlyStems, isLeapYear, lunarDayNames, lunarInfo, lunarMonthNames, lunarToSolar, lunarYearNames, minmaxDate, parseDate, solarToLunar, springFestivals, toDate, toDateNumber, toDateString, toMonthNumber } from "./date.js";
|
|
4
4
|
import { checkRtl, getScrollTop, toTouchEvent } from "./dom.js";
|
|
5
5
|
import { chooseFile, getFileName, imageDataToDataURL, isFileUrl, isImageFile, isImageUrl, isVideoFile, isVideoUrl, loadImage, readFileContent } from "./file.js";
|
|
@@ -24,4 +24,4 @@ import { Friction } from "./scroller/Friction.js";
|
|
|
24
24
|
import { Spring } from "./scroller/Spring.js";
|
|
25
25
|
import { withResolvers } from "./polyfill.js";
|
|
26
26
|
import { useScroller } from "./scroller/useScroller.js";
|
|
27
|
-
export { ALPHANUMERIC_CHARS, BarcodeFormatList, BarcodeTextPositionList, ECLList, Friction, OnlyChild, Spring, addSeparator, addUnit, arrayEqual, arrayMove, assignDeep, barcode, baseLunarYear, calculateBarcodeLayout, camelCase, capitalize, chainGet, chainSet, checkRtl, chooseFile, clamp, clipboard, createBem, createBemStruct, createInertialAnimate, cssVar, cssVarName, debounce, deepClone, defaultBemConfig, defaultColorPickerPresets, defaultColorPickerValue, defineSetupFnComponent, earthlyBranches, enhanceComponent, extend, flatVNode, formatColor, formatDate, formatNumber, getAspectFillSize, getAspectFitSize, getDampingValue, getDayOfYear, getDaysAfterLastDay, getDaysBeforeFirstDay, getDaysInMonth, getDaysSinceUnixEpoch, getDecimalsLength, getFileName, getFirstDayWeekday, getInBoundValue, getLeafNodes, getLunarDayName, getLunarHourName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, getLunarYearDays, getLunarYearName, getNextMonthDate, getNextMonthHeadDays, getNodeLevel, getOverflowRangeInArea, getPageRange, getPrevMonthDate, getPrevMonthTailDays, getPreviewColor, getRectDampingValue, getRotatedRect, getScrollIntoViewValue, getScrollTop, getTouchPoint, getTransformOrigin, getTreeCheckedKeys, getTreeHalfCheckedKeys, getTwoPointsDistance, heavenlyStems, hslToHsv, hslToHwb, hslToRgb, hsvToHsl, hwbToHsl, imageDataToDataURL, inRange, initializeCheckNodes, interpolate, isBoolean, isConfigObject, isDate, isEmptyArray, isEmptyBinding, isEmptyValue, isFileUrl, isFunction, isImageFile, isImageUrl, isKorean, isLeapYear, isNoEmptyArray, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isRectEqual, isRenderVisible, isSizeEqual, isString, isUndefined, isVideoFile, isVideoUrl, isVisibleEmpty, kebabCase, loadImage, logError, looseToNumber, lowerFirst, lunarDayNames, lunarInfo, lunarMonthNames, lunarToSolar, lunarYearNames, mapTreeToGrid, matchScrollVisible, measureTextWidth, minmaxDate, mround, nestedToMulti, noop, normalizeBarcodeOptions, normalizeHsla, normalizeHsva, omit, parseColor, parseDate, partition, pascalCase, pick, qrcode, random, readFileContent, rgbToHsl, round, scrollToTarget, setCheckedRecursively, shuffle, sleep, snakeCase, solarToLunar, splitUnit, spreadEach, springFestivals, throttle, toArray, toDate, toDateNumber, toDateString, toMonthNumber, toTouchEvent, treeToMap, uniqid, updateAncestorsChecked, upperFirst, useScroller, walkAncestor, walkDescendant, walkNodes, withResolvers };
|
|
27
|
+
export { ALPHANUMERIC_CHARS, BarcodeFormatList, BarcodeTextPositionList, ECLList, Friction, OnlyChild, Spring, abbrNumber, addSeparator, addUnit, arrayEqual, arrayMove, assignDeep, barcode, baseLunarYear, calculateBarcodeLayout, camelCase, capitalize, chainGet, chainSet, checkRtl, chooseFile, clamp, clipboard, createBem, createBemStruct, createInertialAnimate, cssVar, cssVarName, debounce, deepClone, defaultBemConfig, defaultColorPickerPresets, defaultColorPickerValue, defineSetupFnComponent, earthlyBranches, enhanceComponent, extend, flatVNode, formatColor, formatDate, formatNumber, formatThousands, getAspectFillSize, getAspectFitSize, getDampingValue, getDayOfYear, getDaysAfterLastDay, getDaysBeforeFirstDay, getDaysInMonth, getDaysSinceUnixEpoch, getDecimalsLength, getFileName, getFirstDayWeekday, getInBoundValue, getLeafNodes, getLunarDayName, getLunarHourName, getLunarLeapMonth, getLunarLeapMonthDays, getLunarMonthDays, getLunarMonthName, getLunarYearDays, getLunarYearName, getNextMonthDate, getNextMonthHeadDays, getNodeLevel, getOverflowRangeInArea, getPageRange, getPrevMonthDate, getPrevMonthTailDays, getPreviewColor, getRectDampingValue, getRotatedRect, getScrollIntoViewValue, getScrollTop, getTouchPoint, getTransformOrigin, getTreeCheckedKeys, getTreeHalfCheckedKeys, getTwoPointsDistance, heavenlyStems, hslToHsv, hslToHwb, hslToRgb, hsvToHsl, hwbToHsl, imageDataToDataURL, inRange, initializeCheckNodes, interpolate, isBoolean, isConfigObject, isDate, isEmptyArray, isEmptyBinding, isEmptyValue, isFileUrl, isFunction, isImageFile, isImageUrl, isKorean, isLeapYear, isNoEmptyArray, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isRectEqual, isRenderVisible, isSizeEqual, isString, isUndefined, isVideoFile, isVideoUrl, isVisibleEmpty, kebabCase, loadImage, logError, looseToNumber, lowerFirst, lunarDayNames, lunarInfo, lunarMonthNames, lunarToSolar, lunarYearNames, mapTreeToGrid, matchScrollVisible, measureTextWidth, minmaxDate, mround, nestedToMulti, noop, normalizeBarcodeOptions, normalizeHsla, normalizeHsva, omit, parseColor, parseDate, partition, pascalCase, pick, qrcode, random, readFileContent, rgbToHsl, round, scrollToTarget, setCheckedRecursively, shuffle, sleep, snakeCase, solarToLunar, splitUnit, spreadEach, springFestivals, throttle, toArray, toDate, toDateNumber, toDateString, toMonthNumber, toTouchEvent, treeToMap, truncToFixed, uniqid, updateAncestorsChecked, upperFirst, useScroller, walkAncestor, walkDescendant, walkNodes, withResolvers };
|
package/utils/inertialAnimate.js
CHANGED
package/utils/number.d.ts
CHANGED
|
@@ -30,3 +30,21 @@ export declare function looseToNumber(val: any): any;
|
|
|
30
30
|
* 将任意字符的字符串格式化为数字字符串,可以指定是否允许小数和负数
|
|
31
31
|
*/
|
|
32
32
|
export declare function formatNumber(value: string, allowDot?: boolean, allowMinus?: boolean): string;
|
|
33
|
+
/**
|
|
34
|
+
* trunc 版本的 toFixed,避免四舍五入
|
|
35
|
+
* @param num
|
|
36
|
+
* @param decimals 小数位数
|
|
37
|
+
*/
|
|
38
|
+
export declare function truncToFixed(num: number, decimals?: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* 通过添加单位缩写数字
|
|
41
|
+
* @param num
|
|
42
|
+
* @param decimals 小数位数
|
|
43
|
+
* @param keepZero 是否保留为0时的小数部分
|
|
44
|
+
*/
|
|
45
|
+
export declare function abbrNumber(num: number, decimals?: number, keepZero?: boolean): string;
|
|
46
|
+
/**
|
|
47
|
+
* 将数字格式化为千分位格式
|
|
48
|
+
* @param num
|
|
49
|
+
*/
|
|
50
|
+
export declare function formatThousands(num?: number): string;
|
package/utils/number.js
CHANGED
|
@@ -58,5 +58,61 @@ function formatNumber(value, allowDot = true, allowMinus = true) {
|
|
|
58
58
|
else value = value.replace(/-/g, "");
|
|
59
59
|
return value;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* trunc 版本的 toFixed,避免四舍五入
|
|
63
|
+
* @param num
|
|
64
|
+
* @param decimals 小数位数
|
|
65
|
+
*/
|
|
66
|
+
function truncToFixed(num, decimals = 0) {
|
|
67
|
+
const n = Math.pow(10, decimals);
|
|
68
|
+
return (Math.trunc(num * n) / n).toFixed(decimals);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 通过添加单位缩写数字
|
|
72
|
+
* @param num
|
|
73
|
+
* @param decimals 小数位数
|
|
74
|
+
* @param keepZero 是否保留为0时的小数部分
|
|
75
|
+
*/
|
|
76
|
+
function abbrNumber(num, decimals = 1, keepZero = false) {
|
|
77
|
+
if (!isFinite(num)) return "0";
|
|
78
|
+
const units = [
|
|
79
|
+
{
|
|
80
|
+
value: 0xe8d4a51000,
|
|
81
|
+
symbol: "T"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
value: 1e9,
|
|
85
|
+
symbol: "B"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
value: 1e6,
|
|
89
|
+
symbol: "M"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: 1e3,
|
|
93
|
+
symbol: "K"
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
const isNegative = num < 0;
|
|
97
|
+
if (isNegative) num = Math.abs(num);
|
|
98
|
+
let formattedNum = truncToFixed(num, decimals);
|
|
99
|
+
let selectedSymbol = "";
|
|
100
|
+
for (let i = 0; i < units.length; i++) if (num >= units[i].value) {
|
|
101
|
+
formattedNum = truncToFixed(num / units[i].value, decimals);
|
|
102
|
+
selectedSymbol = units[i].symbol;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (!keepZero) formattedNum = formattedNum.replace(/\.0+$/, "");
|
|
106
|
+
return (isNegative ? "-" : "") + formattedNum + selectedSymbol;
|
|
107
|
+
}
|
|
108
|
+
let numberFormat;
|
|
109
|
+
/**
|
|
110
|
+
* 将数字格式化为千分位格式
|
|
111
|
+
* @param num
|
|
112
|
+
*/
|
|
113
|
+
function formatThousands(num = 0) {
|
|
114
|
+
if (!numberFormat) numberFormat = new Intl.NumberFormat("en-US", { style: "decimal" });
|
|
115
|
+
return numberFormat.format(num);
|
|
116
|
+
}
|
|
61
117
|
//#endregion
|
|
62
|
-
export { clamp, formatNumber, getDecimalsLength, inRange, looseToNumber, mround, random, round };
|
|
118
|
+
export { abbrNumber, clamp, formatNumber, formatThousands, getDecimalsLength, inRange, looseToNumber, mround, random, round, truncToFixed };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { animateNumber } from "../animation.js";
|
|
1
2
|
import { withResolvers } from "../polyfill.js";
|
|
2
3
|
import { onUnmounted } from "vue";
|
|
3
|
-
import { createAnimation } from "lwa";
|
|
4
4
|
//#region packages/sard/utils/scroller/useEasingAnimation.ts
|
|
5
5
|
function useEasingAnimation(target) {
|
|
6
|
-
let
|
|
6
|
+
let animation;
|
|
7
7
|
let promiseWithResolvers;
|
|
8
8
|
const play = (value, duration) => {
|
|
9
|
-
|
|
9
|
+
animation?.pause();
|
|
10
10
|
promiseWithResolvers = withResolvers();
|
|
11
|
-
|
|
11
|
+
animation = animateNumber(target, value, {
|
|
12
12
|
duration,
|
|
13
13
|
easing: "easeOutCubic",
|
|
14
14
|
complete() {
|
|
@@ -18,7 +18,7 @@ function useEasingAnimation(target) {
|
|
|
18
18
|
return promiseWithResolvers.promise;
|
|
19
19
|
};
|
|
20
20
|
const pause = () => {
|
|
21
|
-
|
|
21
|
+
animation?.pause();
|
|
22
22
|
};
|
|
23
23
|
onUnmounted(() => {
|
|
24
24
|
pause();
|
package/use/useImperative.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type Ref } from 'vue';
|
|
2
|
-
type ImperativeItem<T = any> = {
|
|
3
|
-
show: boolean;
|
|
4
|
-
imperative: T;
|
|
5
|
-
};
|
|
6
|
-
type AllImperatives<T = any> = Record<string, Record<string, ImperativeItem<T>[] | undefined> | undefined>;
|
|
7
|
-
export declare function useImperative<T = any>(name: string, imperative: T, id: Ref<string>): void;
|
|
8
|
-
export declare function getAvailableImperative<T = any>(name: string, id: string): T | void;
|
|
9
|
-
export declare function getImperatives<T = any>(name: string, id: string): ImperativeItem<T>[] | undefined;
|
|
10
|
-
export declare function getAllImperatives<T = any>(): AllImperatives<T>;
|
|
11
|
-
export {};
|
package/use/useImperative.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { onMounted, onUnmounted } from "vue";
|
|
2
|
-
//#region packages/sard/use/useImperative.ts
|
|
3
|
-
const allImperatives = {};
|
|
4
|
-
function useImperative(name, imperative, id) {
|
|
5
|
-
onMounted(() => {
|
|
6
|
-
if (id.value) {
|
|
7
|
-
const imperativeItems = (allImperatives[name] ??= {})[id.value] ??= [];
|
|
8
|
-
if (imperativeItems.findIndex((item) => item.imperative === imperative) === -1) imperativeItems.push({
|
|
9
|
-
imperative,
|
|
10
|
-
show: true
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
onUnmounted(() => {
|
|
15
|
-
if (id.value) {
|
|
16
|
-
const imperativeItems = allImperatives[name]?.[id.value];
|
|
17
|
-
if (imperativeItems) {
|
|
18
|
-
const index = imperativeItems.findIndex((item) => item.imperative === imperative);
|
|
19
|
-
if (index !== -1) {
|
|
20
|
-
imperativeItems.splice(index, 1);
|
|
21
|
-
if (imperativeItems.length === 0) delete allImperatives[name]?.[id.value];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function getAvailableImperative(name, id) {
|
|
28
|
-
const imperativeItems = allImperatives[name]?.[id];
|
|
29
|
-
if (imperativeItems) {
|
|
30
|
-
for (let i = imperativeItems.length - 1; i >= 0; i--) {
|
|
31
|
-
const imperativeItem = imperativeItems[i];
|
|
32
|
-
if (imperativeItem && imperativeItem.show) return imperativeItem.imperative;
|
|
33
|
-
}
|
|
34
|
-
return imperativeItems[imperativeItems.length - 1]?.imperative;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function getImperatives(name, id) {
|
|
38
|
-
return allImperatives[name]?.[id];
|
|
39
|
-
}
|
|
40
|
-
function getAllImperatives() {
|
|
41
|
-
return allImperatives;
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { getAllImperatives, getAvailableImperative, getImperatives, useImperative };
|