@varlet/ui 2.16.7 → 2.16.8-alpha.1695118057982
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/es/action-sheet/ActionSheet.mjs +97 -67
- package/es/action-sheet/index.mjs +43 -28
- package/es/action-sheet/props.mjs +39 -8
- package/es/app-bar/AppBar.mjs +129 -56
- package/es/app-bar/index.mjs +10 -5
- package/es/app-bar/props.mjs +6 -3
- package/es/avatar/Avatar.mjs +97 -87
- package/es/avatar/index.mjs +10 -5
- package/es/avatar/props.mjs +8 -5
- package/es/avatar-group/AvatarGroup.mjs +26 -20
- package/es/avatar-group/index.mjs +10 -5
- package/es/avatar-group/props.mjs +5 -2
- package/es/back-top/BackTop.mjs +71 -53
- package/es/back-top/index.mjs +10 -5
- package/es/back-top/props.mjs +6 -3
- package/es/badge/Badge.mjs +74 -46
- package/es/badge/index.mjs +10 -5
- package/es/badge/props.mjs +7 -4
- package/es/bottom-navigation/BottomNavigation.mjs +100 -97
- package/es/bottom-navigation/index.mjs +10 -5
- package/es/bottom-navigation/props.mjs +7 -4
- package/es/bottom-navigation/provide.mjs +13 -9
- package/es/bottom-navigation-item/BottomNavigationItem.mjs +93 -74
- package/es/bottom-navigation-item/index.mjs +10 -5
- package/es/bottom-navigation-item/props.mjs +7 -4
- package/es/bottom-navigation-item/provide.mjs +14 -11
- package/es/breadcrumb/Breadcrumb.mjs +51 -36
- package/es/breadcrumb/index.mjs +10 -5
- package/es/breadcrumb/props.mjs +6 -3
- package/es/breadcrumb/provide.mjs +12 -11
- package/es/breadcrumbs/Breadcrumbs.mjs +26 -24
- package/es/breadcrumbs/index.mjs +10 -5
- package/es/breadcrumbs/props.mjs +6 -3
- package/es/breadcrumbs/provide.mjs +11 -9
- package/es/button/Button.mjs +88 -90
- package/es/button/index.mjs +10 -5
- package/es/button/props.mjs +31 -10
- package/es/button/provide.mjs +8 -9
- package/es/button-group/ButtonGroup.mjs +38 -26
- package/es/button-group/index.mjs +8 -4
- package/es/button-group/props.mjs +8 -5
- package/es/button-group/provide.mjs +9 -9
- package/es/card/Card.mjs +292 -189
- package/es/card/index.mjs +10 -5
- package/es/card/props.mjs +9 -6
- package/es/cell/Cell.mjs +96 -52
- package/es/cell/index.mjs +10 -5
- package/es/cell/props.mjs +6 -3
- package/es/checkbox/Checkbox.mjs +136 -130
- package/es/checkbox/index.mjs +10 -5
- package/es/checkbox/props.mjs +9 -6
- package/es/checkbox/provide.mjs +10 -9
- package/es/checkbox-group/CheckboxGroup.mjs +63 -96
- package/es/checkbox-group/index.mjs +10 -5
- package/es/checkbox-group/props.mjs +9 -6
- package/es/checkbox-group/provide.mjs +11 -9
- package/es/chip/Chip.mjs +66 -50
- package/es/chip/index.mjs +10 -5
- package/es/chip/props.mjs +10 -7
- package/es/col/Col.mjs +60 -55
- package/es/col/index.mjs +10 -5
- package/es/col/props.mjs +7 -4
- package/es/col/provide.mjs +8 -9
- package/es/collapse/Collapse.mjs +70 -73
- package/es/collapse/index.mjs +10 -5
- package/es/collapse/props.mjs +7 -4
- package/es/collapse/provide.mjs +11 -9
- package/es/collapse-item/CollapseItem.mjs +156 -93
- package/es/collapse-item/index.mjs +10 -5
- package/es/collapse-item/props.mjs +6 -3
- package/es/collapse-item/provide.mjs +12 -11
- package/es/context/index.mjs +9 -5
- package/es/context/lock.mjs +18 -22
- package/es/context/zIndex.mjs +19 -16
- package/es/countdown/Countdown.mjs +73 -70
- package/es/countdown/index.mjs +10 -5
- package/es/countdown/props.mjs +7 -4
- package/es/counter/Counter.mjs +169 -173
- package/es/counter/index.mjs +10 -5
- package/es/counter/props.mjs +8 -5
- package/es/counter/provide.ts +3 -0
- package/es/date-picker/DatePicker.mjs +411 -304
- package/es/date-picker/index.mjs +10 -5
- package/es/date-picker/props.mjs +71 -45
- package/es/date-picker/src/day-picker-panel.mjs +270 -208
- package/es/date-picker/src/month-picker-panel.mjs +205 -175
- package/es/date-picker/src/panel-header.mjs +101 -83
- package/es/date-picker/src/year-picker-panel.mjs +64 -54
- package/es/dialog/Dialog.mjs +171 -106
- package/es/dialog/index.mjs +49 -33
- package/es/dialog/props.mjs +39 -9
- package/es/divider/Divider.mjs +56 -51
- package/es/divider/index.mjs +10 -5
- package/es/divider/props.mjs +5 -2
- package/es/drag/Drag.mjs +126 -144
- package/es/drag/index.mjs +10 -5
- package/es/drag/props.mjs +8 -5
- package/es/ellipsis/Ellipsis.mjs +81 -50
- package/es/ellipsis/index.mjs +8 -4
- package/es/ellipsis/props.mjs +5 -2
- package/es/fab/Fab.mjs +73 -75
- package/es/fab/index.mjs +8 -4
- package/es/fab/props.mjs +14 -11
- package/es/field-decorator/FieldDecorator.mjs +215 -110
- package/es/field-decorator/props.mjs +9 -6
- package/es/form/Form.mjs +69 -79
- package/es/form/index.mjs +11 -6
- package/es/form/props.mjs +6 -3
- package/es/form/provide.mjs +35 -22
- package/es/form-details/FormDetails.mjs +81 -39
- package/es/form-details/index.mjs +10 -5
- package/es/form-details/props.mjs +7 -4
- package/es/hover/index.mjs +37 -40
- package/es/hover-overlay/HoverOverlay.mjs +18 -14
- package/es/hover-overlay/index.mjs +13 -8
- package/es/hover-overlay/props.mjs +5 -2
- package/es/icon/Icon.mjs +50 -33
- package/es/icon/index.mjs +10 -5
- package/es/icon/props.mjs +7 -4
- package/es/image/Image.mjs +76 -82
- package/es/image/index.mjs +10 -5
- package/es/image/props.mjs +7 -4
- package/es/image-preview/ImagePreview.mjs +176 -193
- package/es/image-preview/index.mjs +44 -30
- package/es/image-preview/props.mjs +34 -9
- package/es/index-anchor/IndexAnchor.mjs +45 -42
- package/es/index-anchor/index.mjs +10 -5
- package/es/index-anchor/props.mjs +5 -2
- package/es/index-anchor/provide.mjs +12 -11
- package/es/index-bar/IndexBar.mjs +130 -131
- package/es/index-bar/index.mjs +10 -5
- package/es/index-bar/props.mjs +6 -3
- package/es/index-bar/provide.mjs +11 -9
- package/es/index.bundle.mjs +1 -1
- package/es/index.mjs +1 -1
- package/es/input/Input.mjs +231 -247
- package/es/input/index.mjs +10 -5
- package/es/input/props.mjs +38 -8
- package/es/input/provide.ts +3 -0
- package/es/lazy/index.mjs +94 -87
- package/es/link/Link.mjs +39 -45
- package/es/link/index.mjs +10 -5
- package/es/link/props.mjs +8 -5
- package/es/list/List.mjs +144 -97
- package/es/list/index.mjs +10 -5
- package/es/list/props.mjs +8 -5
- package/es/list/provide.mjs +8 -9
- package/es/loading/Loading.mjs +165 -72
- package/es/loading/index.mjs +10 -5
- package/es/loading/props.mjs +7 -4
- package/es/loading-bar/LoadingBar.mjs +19 -16
- package/es/loading-bar/index.mjs +37 -30
- package/es/loading-bar/props.mjs +5 -2
- package/es/locale/en-US.mjs +76 -73
- package/es/locale/index.mjs +52 -41
- package/es/locale/zh-CN.mjs +76 -73
- package/es/menu/Menu.mjs +76 -57
- package/es/menu/index.mjs +10 -5
- package/es/menu/props.mjs +11 -8
- package/es/menu/usePopover.mjs +214 -207
- package/es/option/Option.mjs +86 -70
- package/es/option/index.mjs +10 -5
- package/es/option/props.mjs +5 -2
- package/es/option/provide.mjs +10 -11
- package/es/overlay/Overlay.mjs +29 -31
- package/es/overlay/index.mjs +10 -5
- package/es/overlay/props.mjs +7 -4
- package/es/pagination/Pagination.mjs +334 -202
- package/es/pagination/index.mjs +10 -5
- package/es/pagination/props.mjs +8 -5
- package/es/paper/Paper.mjs +43 -31
- package/es/paper/index.mjs +10 -5
- package/es/paper/props.mjs +6 -3
- package/es/picker/Picker.mjs +288 -224
- package/es/picker/index.mjs +24 -23
- package/es/picker/props.mjs +37 -7
- package/es/popup/Popup.mjs +68 -58
- package/es/popup/index.mjs +10 -5
- package/es/popup/props.mjs +9 -6
- package/es/popup/provide.mjs +12 -15
- package/es/progress/Progress.mjs +186 -114
- package/es/progress/index.mjs +10 -5
- package/es/progress/props.mjs +7 -4
- package/es/pull-refresh/PullRefresh.mjs +136 -116
- package/es/pull-refresh/index.mjs +10 -5
- package/es/pull-refresh/props.mjs +8 -5
- package/es/radio/Radio.mjs +122 -118
- package/es/radio/index.mjs +10 -5
- package/es/radio/props.mjs +8 -5
- package/es/radio/provide.mjs +8 -9
- package/es/radio-group/RadioGroup.mjs +50 -58
- package/es/radio-group/index.mjs +10 -5
- package/es/radio-group/props.mjs +10 -7
- package/es/radio-group/provide.mjs +11 -9
- package/es/rate/Rate.mjs +103 -132
- package/es/rate/index.mjs +10 -5
- package/es/rate/props.mjs +10 -7
- package/es/rate/provide.ts +3 -0
- package/es/result/Empty.mjs +21 -12
- package/es/result/Error.mjs +18 -9
- package/es/result/Info.mjs +18 -9
- package/es/result/Question.mjs +18 -9
- package/es/result/Result.mjs +102 -55
- package/es/result/Success.mjs +84 -40
- package/es/result/Warning.mjs +18 -9
- package/es/result/index.mjs +10 -5
- package/es/result/props.mjs +6 -3
- package/es/ripple/index.mjs +89 -101
- package/es/row/Row.mjs +40 -45
- package/es/row/index.mjs +10 -5
- package/es/row/props.mjs +8 -5
- package/es/row/provide.mjs +9 -9
- package/es/select/Select.mjs +308 -298
- package/es/select/index.mjs +10 -5
- package/es/select/props.mjs +40 -10
- package/es/select/provide.mjs +9 -9
- package/es/skeleton/Skeleton.mjs +182 -71
- package/es/skeleton/index.mjs +10 -5
- package/es/skeleton/props.mjs +5 -2
- package/es/slider/Slider.mjs +310 -260
- package/es/slider/index.mjs +10 -5
- package/es/slider/props.mjs +15 -11
- package/es/slider/provide.ts +3 -0
- package/es/snackbar/Snackbar.mjs +47 -34
- package/es/snackbar/core.mjs +140 -77
- package/es/snackbar/index.mjs +111 -97
- package/es/snackbar/props.mjs +35 -14
- package/es/space/Space.mjs +30 -28
- package/es/space/index.mjs +10 -5
- package/es/space/margin.mjs +22 -23
- package/es/space/props.mjs +8 -5
- package/es/step/Step.mjs +96 -74
- package/es/step/index.mjs +10 -5
- package/es/step/props.mjs +6 -3
- package/es/step/provide.mjs +10 -11
- package/es/steps/Steps.mjs +31 -30
- package/es/steps/index.mjs +10 -5
- package/es/steps/props.mjs +7 -4
- package/es/steps/provide.mjs +9 -8
- package/es/sticky/Sticky.mjs +104 -92
- package/es/sticky/index.mjs +10 -5
- package/es/sticky/props.mjs +6 -3
- package/es/style-provider/StyleProvider.mjs +19 -18
- package/es/style-provider/index.mjs +15 -11
- package/es/style-provider/props.mjs +6 -3
- package/es/swipe/Swipe.mjs +281 -268
- package/es/swipe/index.mjs +10 -5
- package/es/swipe/props.mjs +6 -3
- package/es/swipe/provide.mjs +11 -9
- package/es/swipe-item/SwipeItem.mjs +29 -29
- package/es/swipe-item/index.mjs +8 -4
- package/es/swipe-item/provide.mjs +10 -11
- package/es/switch/Switch.mjs +143 -103
- package/es/switch/index.mjs +10 -5
- package/es/switch/props.mjs +7 -4
- package/es/switch/provide.ts +3 -0
- package/es/tab/Tab.mjs +48 -61
- package/es/tab/index.mjs +10 -5
- package/es/tab/props.mjs +6 -3
- package/es/tab/provide.mjs +10 -11
- package/es/tab-item/TabItem.mjs +27 -32
- package/es/tab-item/index.mjs +10 -5
- package/es/tab-item/props.mjs +5 -2
- package/es/tab-item/provide.mjs +17 -18
- package/es/table/Table.mjs +54 -25
- package/es/table/index.mjs +10 -5
- package/es/table/props.mjs +6 -3
- package/es/tabs/Tabs.mjs +162 -134
- package/es/tabs/index.mjs +10 -5
- package/es/tabs/props.mjs +15 -12
- package/es/tabs/provide.mjs +9 -9
- package/es/tabs-items/TabsItems.mjs +61 -65
- package/es/tabs-items/index.mjs +10 -5
- package/es/tabs-items/props.mjs +7 -4
- package/es/tabs-items/provide.mjs +11 -9
- package/es/themes/dark/actionSheet.mjs +8 -5
- package/es/themes/dark/appBar.mjs +6 -3
- package/es/themes/dark/avatar.mjs +7 -4
- package/es/themes/dark/badge.mjs +6 -3
- package/es/themes/dark/bottomNavigation.mjs +7 -4
- package/es/themes/dark/bottomNavigationItem.mjs +6 -3
- package/es/themes/dark/breadcrumb.mjs +6 -3
- package/es/themes/dark/button.mjs +7 -4
- package/es/themes/dark/card.mjs +10 -7
- package/es/themes/dark/cell.mjs +7 -4
- package/es/themes/dark/checkbox.mjs +7 -4
- package/es/themes/dark/chip.mjs +7 -4
- package/es/themes/dark/collapse.mjs +8 -5
- package/es/themes/dark/countdown.mjs +6 -3
- package/es/themes/dark/datePicker.mjs +10 -7
- package/es/themes/dark/dialog.mjs +8 -5
- package/es/themes/dark/divider.mjs +7 -4
- package/es/themes/dark/fieldDecorator.mjs +7 -4
- package/es/themes/dark/index.mjs +69 -51
- package/es/themes/dark/link.mjs +6 -3
- package/es/themes/dark/menu.mjs +6 -3
- package/es/themes/dark/option.mjs +6 -3
- package/es/themes/dark/pagination.mjs +11 -8
- package/es/themes/dark/paper.mjs +6 -3
- package/es/themes/dark/picker.mjs +11 -8
- package/es/themes/dark/popup.mjs +6 -3
- package/es/themes/dark/progress.mjs +6 -3
- package/es/themes/dark/pullRefresh.mjs +6 -3
- package/es/themes/dark/radio.mjs +7 -4
- package/es/themes/dark/result.mjs +12 -9
- package/es/themes/dark/select.mjs +6 -3
- package/es/themes/dark/skeleton.mjs +11 -6
- package/es/themes/dark/steps.mjs +8 -5
- package/es/themes/dark/switch.mjs +7 -4
- package/es/themes/dark/tab.mjs +6 -3
- package/es/themes/dark/table.mjs +12 -9
- package/es/themes/dark/tabs.mjs +6 -3
- package/es/themes/dark/timePicker.mjs +9 -6
- package/es/themes/dark/uploader.mjs +10 -7
- package/es/themes/dark/watermark.mjs +6 -3
- package/es/themes/index.mjs +7 -5
- package/es/time-picker/TimePicker.mjs +297 -232
- package/es/time-picker/clock.mjs +222 -172
- package/es/time-picker/index.mjs +10 -5
- package/es/time-picker/props.mjs +14 -8
- package/es/time-picker/utils.mjs +46 -86
- package/es/tooltip/Tooltip.mjs +82 -62
- package/es/tooltip/index.mjs +10 -5
- package/es/tooltip/props.mjs +12 -9
- package/es/uploader/Uploader.mjs +315 -308
- package/es/uploader/index.mjs +10 -5
- package/es/uploader/props.mjs +10 -7
- package/es/uploader/provide.ts +3 -0
- package/es/utils/components.mjs +158 -127
- package/es/utils/elements.mjs +106 -123
- package/es/utils/logger.mjs +9 -5
- package/es/utils/shared.mjs +25 -23
- package/es/utils/test.mjs +105 -93
- package/es/varlet.esm.js +12464 -13425
- package/es/watermark/Watermark.mjs +191 -109
- package/es/watermark/index.mjs +8 -4
- package/es/watermark/props.mjs +8 -5
- package/highlight/web-types.en-US.json +3 -3
- package/highlight/web-types.zh-CN.json +2 -2
- package/lib/varlet.cjs.js +9187 -10199
- package/package.json +7 -7
- package/umd/varlet.js +4 -4
- package/es/counter/provide.mjs +0 -1
- package/es/input/provide.mjs +0 -1
- package/es/rate/provide.mjs +0 -1
- package/es/slider/provide.mjs +0 -1
- package/es/switch/provide.mjs +0 -1
- package/es/uploader/provide.mjs +0 -1
package/es/utils/elements.mjs
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
isNumber,
|
|
3
|
+
isObject,
|
|
4
|
+
isString,
|
|
5
|
+
kebabCase,
|
|
6
|
+
toNumber,
|
|
7
|
+
isWindow,
|
|
8
|
+
inBrowser,
|
|
9
|
+
getRect,
|
|
10
|
+
getStyle
|
|
11
|
+
} from "@varlet/shared";
|
|
12
|
+
import { error } from "./logger.mjs";
|
|
13
|
+
function getLeft(element) {
|
|
14
|
+
const { left } = getRect(element);
|
|
7
15
|
return left + (document.body.scrollLeft || document.documentElement.scrollLeft);
|
|
8
16
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
top
|
|
12
|
-
} = getRect(element);
|
|
17
|
+
function getTop(element) {
|
|
18
|
+
const { top } = getRect(element);
|
|
13
19
|
return top + (document.body.scrollTop || document.documentElement.scrollTop);
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// iOS scroll bounce cause minus scrollTop
|
|
21
|
+
function getScrollTop(element) {
|
|
22
|
+
const top = "scrollTop" in element ? element.scrollTop : element.pageYOffset;
|
|
19
23
|
return Math.max(top, 0);
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
function getScrollLeft(element) {
|
|
26
|
+
const left = "scrollLeft" in element ? element.scrollLeft : element.pageXOffset;
|
|
23
27
|
return Math.max(left, 0);
|
|
24
28
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = getStyle(el);
|
|
29
|
-
return +transform.slice(transform.lastIndexOf(',') + 2, transform.length - 1);
|
|
29
|
+
function getTranslateY(el) {
|
|
30
|
+
const { transform } = getStyle(el);
|
|
31
|
+
return +transform.slice(transform.lastIndexOf(",") + 2, transform.length - 1);
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
function getParentScroller(el) {
|
|
34
|
+
let element = el;
|
|
33
35
|
while (element) {
|
|
34
36
|
if (!element.parentNode) {
|
|
35
37
|
break;
|
|
@@ -38,42 +40,37 @@ export function getParentScroller(el) {
|
|
|
38
40
|
if (element === document.body || element === document.documentElement) {
|
|
39
41
|
break;
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
overflowY,
|
|
44
|
-
overflow
|
|
45
|
-
} = getStyle(element);
|
|
43
|
+
const scrollRE = /(scroll|auto)/;
|
|
44
|
+
const { overflowY, overflow } = getStyle(element);
|
|
46
45
|
if (scrollRE.test(overflowY) || scrollRE.test(overflow)) {
|
|
47
46
|
return element;
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
return window;
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
function getAllParentScroller(el) {
|
|
52
|
+
const allParentScroller = [];
|
|
53
|
+
let element = el;
|
|
55
54
|
while (!isWindow(element)) {
|
|
56
55
|
element = getParentScroller(element);
|
|
57
56
|
allParentScroller.push(element);
|
|
58
57
|
}
|
|
59
58
|
return allParentScroller;
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
function getTarget(target, componentName) {
|
|
62
61
|
if (isString(target)) {
|
|
63
|
-
|
|
62
|
+
const el = document.querySelector(target);
|
|
64
63
|
if (!el) {
|
|
65
|
-
error(componentName,
|
|
64
|
+
error(componentName, "target element cannot found");
|
|
66
65
|
}
|
|
67
66
|
return el;
|
|
68
67
|
}
|
|
69
|
-
if (isObject(target))
|
|
68
|
+
if (isObject(target))
|
|
69
|
+
return target;
|
|
70
70
|
error(componentName, 'type of prop "target" should be a selector or an element object');
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
width,
|
|
75
|
-
height
|
|
76
|
-
} = getRect(window);
|
|
72
|
+
function getViewportSize() {
|
|
73
|
+
const { width, height } = getRect(window);
|
|
77
74
|
return {
|
|
78
75
|
vw: width,
|
|
79
76
|
vh: height,
|
|
@@ -81,116 +78,76 @@ export function getViewportSize() {
|
|
|
81
78
|
vMax: Math.max(width, height)
|
|
82
79
|
};
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export var isPercent = value => isString(value) && value.endsWith('%');
|
|
96
|
-
|
|
97
|
-
// e.g. 1vw
|
|
98
|
-
export var isVw = value => isString(value) && value.endsWith('vw');
|
|
99
|
-
|
|
100
|
-
// e.g. 1vh
|
|
101
|
-
export var isVh = value => isString(value) && value.endsWith('vh');
|
|
102
|
-
|
|
103
|
-
// e.g. 1vmin
|
|
104
|
-
export var isVMin = value => isString(value) && value.endsWith('vmin');
|
|
105
|
-
|
|
106
|
-
// e.g. 1vmax
|
|
107
|
-
export var isVMax = value => isString(value) && value.endsWith('vmax');
|
|
108
|
-
|
|
109
|
-
// e.g. calc(1px + 1px)
|
|
110
|
-
export var isCalc = value => isString(value) && value.startsWith('calc(');
|
|
111
|
-
|
|
112
|
-
// e.g. var(--color-primary)
|
|
113
|
-
export var isVar = value => isString(value) && value.startsWith('var(');
|
|
114
|
-
|
|
115
|
-
// e.g. return 1
|
|
116
|
-
export var toPxNum = value => {
|
|
81
|
+
const isRem = (value) => isString(value) && value.endsWith("rem");
|
|
82
|
+
const isEm = (value) => isString(value) && value.endsWith("em") && !value.endsWith("rem");
|
|
83
|
+
const isPx = (value) => isString(value) && value.endsWith("px") || isNumber(value);
|
|
84
|
+
const isPercent = (value) => isString(value) && value.endsWith("%");
|
|
85
|
+
const isVw = (value) => isString(value) && value.endsWith("vw");
|
|
86
|
+
const isVh = (value) => isString(value) && value.endsWith("vh");
|
|
87
|
+
const isVMin = (value) => isString(value) && value.endsWith("vmin");
|
|
88
|
+
const isVMax = (value) => isString(value) && value.endsWith("vmax");
|
|
89
|
+
const isCalc = (value) => isString(value) && value.startsWith("calc(");
|
|
90
|
+
const isVar = (value) => isString(value) && value.startsWith("var(");
|
|
91
|
+
const toPxNum = (value) => {
|
|
117
92
|
if (isNumber(value)) {
|
|
118
93
|
return value;
|
|
119
94
|
}
|
|
120
95
|
if (isPx(value)) {
|
|
121
|
-
return +value.replace(
|
|
96
|
+
return +value.replace("px", "");
|
|
122
97
|
}
|
|
123
98
|
if (!inBrowser()) {
|
|
124
99
|
return 0;
|
|
125
100
|
}
|
|
126
|
-
|
|
127
|
-
vw,
|
|
128
|
-
vh,
|
|
129
|
-
vMin,
|
|
130
|
-
vMax
|
|
131
|
-
} = getViewportSize();
|
|
101
|
+
const { vw, vh, vMin, vMax } = getViewportSize();
|
|
132
102
|
if (isVw(value)) {
|
|
133
|
-
return +value.replace(
|
|
103
|
+
return +value.replace("vw", "") * vw / 100;
|
|
134
104
|
}
|
|
135
105
|
if (isVh(value)) {
|
|
136
|
-
return +value.replace(
|
|
106
|
+
return +value.replace("vh", "") * vh / 100;
|
|
137
107
|
}
|
|
138
108
|
if (isVMin(value)) {
|
|
139
|
-
return +value.replace(
|
|
109
|
+
return +value.replace("vmin", "") * vMin / 100;
|
|
140
110
|
}
|
|
141
111
|
if (isVMax(value)) {
|
|
142
|
-
return +value.replace(
|
|
112
|
+
return +value.replace("vmax", "") * vMax / 100;
|
|
143
113
|
}
|
|
144
114
|
if (isRem(value)) {
|
|
145
|
-
|
|
146
|
-
|
|
115
|
+
const num = +value.replace("rem", "");
|
|
116
|
+
const rootFontSize = getStyle(document.documentElement).fontSize;
|
|
147
117
|
return num * parseFloat(rootFontSize);
|
|
148
118
|
}
|
|
149
119
|
if (isString(value)) {
|
|
150
120
|
return toNumber(value);
|
|
151
121
|
}
|
|
152
|
-
|
|
153
|
-
// % and other
|
|
154
122
|
return 0;
|
|
155
123
|
};
|
|
156
|
-
|
|
157
|
-
// e.g. return 1px 1% 1vw 1vh 1rem null var(--color-primary) calc(1px + 1px)
|
|
158
|
-
export var toSizeUnit = value => {
|
|
124
|
+
const toSizeUnit = (value) => {
|
|
159
125
|
if (value == null) {
|
|
160
|
-
return
|
|
126
|
+
return void 0;
|
|
161
127
|
}
|
|
162
128
|
if (isPercent(value) || isVw(value) || isVh(value) || isEm(value) || isRem(value) || isCalc(value) || isVar(value) || isVMin(value) || isVMax(value)) {
|
|
163
129
|
return value;
|
|
164
130
|
}
|
|
165
|
-
return toPxNum(value)
|
|
131
|
+
return `${toPxNum(value)}px`;
|
|
166
132
|
};
|
|
167
|
-
|
|
168
|
-
if (quantity === void 0) {
|
|
169
|
-
quantity = 1;
|
|
170
|
-
}
|
|
133
|
+
const multiplySizeUnit = (value, quantity = 1) => {
|
|
171
134
|
if (value == null) {
|
|
172
|
-
return
|
|
135
|
+
return void 0;
|
|
173
136
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return
|
|
137
|
+
const legalSize = toSizeUnit(value);
|
|
138
|
+
const unit = legalSize.match(/(vh|%|r?em|px|vw|vmin|vmax)$/)[0];
|
|
139
|
+
return `${parseFloat(legalSize) * quantity}${unit}`;
|
|
177
140
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
var startTime = Date.now();
|
|
186
|
-
var scrollTop = getScrollTop(element);
|
|
187
|
-
var scrollLeft = getScrollLeft(element);
|
|
188
|
-
return new Promise(resolve => {
|
|
189
|
-
var frame = () => {
|
|
190
|
-
var progress = (Date.now() - startTime) / duration;
|
|
141
|
+
function scrollTo(element, { top = 0, left = 0, duration = 300, animation }) {
|
|
142
|
+
const startTime = Date.now();
|
|
143
|
+
const scrollTop = getScrollTop(element);
|
|
144
|
+
const scrollLeft = getScrollLeft(element);
|
|
145
|
+
return new Promise((resolve) => {
|
|
146
|
+
const frame = () => {
|
|
147
|
+
const progress = (Date.now() - startTime) / duration;
|
|
191
148
|
if (progress < 1) {
|
|
192
|
-
|
|
193
|
-
|
|
149
|
+
const nextTop = scrollTop + (top - scrollTop) * animation(progress);
|
|
150
|
+
const nextLeft = scrollLeft + (left - scrollLeft) * animation(progress);
|
|
194
151
|
element.scrollTo(nextLeft, nextTop);
|
|
195
152
|
requestAnimationFrame(frame);
|
|
196
153
|
} else {
|
|
@@ -201,14 +158,40 @@ export function scrollTo(element, _ref) {
|
|
|
201
158
|
requestAnimationFrame(frame);
|
|
202
159
|
});
|
|
203
160
|
}
|
|
204
|
-
|
|
205
|
-
return Object.entries(styleVars != null ? styleVars : {}).reduce((styles,
|
|
206
|
-
|
|
207
|
-
var cssVar = key.startsWith('--') ? key : "--" + kebabCase(key);
|
|
161
|
+
function formatStyleVars(styleVars) {
|
|
162
|
+
return Object.entries(styleVars != null ? styleVars : {}).reduce((styles, [key, value]) => {
|
|
163
|
+
const cssVar = key.startsWith("--") ? key : `--${kebabCase(key)}`;
|
|
208
164
|
styles[cssVar] = value;
|
|
209
165
|
return styles;
|
|
210
166
|
}, {});
|
|
211
167
|
}
|
|
212
|
-
|
|
213
|
-
return style ===
|
|
214
|
-
}
|
|
168
|
+
function padStartFlex(style) {
|
|
169
|
+
return style === "start" || style === "end" ? `flex-${style}` : style;
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
formatStyleVars,
|
|
173
|
+
getAllParentScroller,
|
|
174
|
+
getLeft,
|
|
175
|
+
getParentScroller,
|
|
176
|
+
getScrollLeft,
|
|
177
|
+
getScrollTop,
|
|
178
|
+
getTarget,
|
|
179
|
+
getTop,
|
|
180
|
+
getTranslateY,
|
|
181
|
+
getViewportSize,
|
|
182
|
+
isCalc,
|
|
183
|
+
isEm,
|
|
184
|
+
isPercent,
|
|
185
|
+
isPx,
|
|
186
|
+
isRem,
|
|
187
|
+
isVMax,
|
|
188
|
+
isVMin,
|
|
189
|
+
isVar,
|
|
190
|
+
isVh,
|
|
191
|
+
isVw,
|
|
192
|
+
multiplySizeUnit,
|
|
193
|
+
padStartFlex,
|
|
194
|
+
scrollTo,
|
|
195
|
+
toPxNum,
|
|
196
|
+
toSizeUnit
|
|
197
|
+
};
|
package/es/utils/logger.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
throw Error(
|
|
1
|
+
function error(source, message) {
|
|
2
|
+
throw Error(`Varlet [${source}]: ${message}`);
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
console.warn(
|
|
6
|
-
}
|
|
4
|
+
function warn(source, message) {
|
|
5
|
+
console.warn(`Varlet [${source}]: ${message}`);
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
error,
|
|
9
|
+
warn
|
|
10
|
+
};
|
package/es/utils/shared.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { removeItem } from
|
|
2
|
-
|
|
1
|
+
import { removeItem } from "@varlet/shared";
|
|
2
|
+
const isHTMLSupportImage = (val) => {
|
|
3
3
|
if (val == null) {
|
|
4
4
|
return false;
|
|
5
5
|
}
|
|
6
|
-
return val.startsWith(
|
|
6
|
+
return val.startsWith("data:image") || /\.(png|jpg|gif|jpeg|svg|webp)$/.test(val);
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
const isHTMLSupportVideo = (val) => {
|
|
9
9
|
if (val == null) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
-
return val.startsWith(
|
|
12
|
+
return val.startsWith("data:video") || /\.(mp4|webm|ogg)$/.test(val);
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const createCache = (max) => {
|
|
15
|
+
const cache = [];
|
|
16
16
|
return {
|
|
17
17
|
cache,
|
|
18
18
|
has(key) {
|
|
@@ -33,20 +33,22 @@ export var createCache = max => {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
if (fillString === void 0) {
|
|
46
|
-
fillString = '';
|
|
47
|
-
}
|
|
48
|
-
if (str.length >= maxLength) return str;
|
|
49
|
-
var len = maxLength - str.length;
|
|
50
|
-
var repeatCount = Math.floor(len / fillString.length);
|
|
36
|
+
const linear = (value) => value;
|
|
37
|
+
const cubic = (value) => value ** 3;
|
|
38
|
+
const easeInOutCubic = (value) => value < 0.5 ? cubic(value * 2) / 2 : 1 - cubic((1 - value) * 2) / 2;
|
|
39
|
+
const padStart = (str = "", maxLength, fillString = "") => {
|
|
40
|
+
if (str.length >= maxLength)
|
|
41
|
+
return str;
|
|
42
|
+
const len = maxLength - str.length;
|
|
43
|
+
const repeatCount = Math.floor(len / fillString.length);
|
|
51
44
|
return fillString.repeat(repeatCount) + fillString.slice(0, len % fillString.length) + str;
|
|
52
|
-
};
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
createCache,
|
|
48
|
+
cubic,
|
|
49
|
+
easeInOutCubic,
|
|
50
|
+
isHTMLSupportImage,
|
|
51
|
+
isHTMLSupportVideo,
|
|
52
|
+
linear,
|
|
53
|
+
padStart
|
|
54
|
+
};
|