sard-uniapp 1.19.5 → 1.20.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.
Files changed (177) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -1
  3. package/components/calendar/README.md +20 -20
  4. package/components/calendar/calendar.vue +1 -1
  5. package/components/calendar-input/README.md +10 -10
  6. package/components/calendar-input/calendar-input.vue +2 -2
  7. package/components/calendar-month/calendar-month.vue +17 -21
  8. package/components/calendar-popout/calendar-popout.vue +1 -1
  9. package/components/card/README.md +16 -8
  10. package/components/card/card.vue +7 -1
  11. package/components/card/common.d.ts +2 -0
  12. package/components/card/index.scss +30 -2
  13. package/components/card/variables.scss +16 -1
  14. package/components/checkbox/common.d.ts +1 -0
  15. package/components/checkbox/common.js +1 -0
  16. package/components/checkbox-input/checkbox-input.vue +9 -0
  17. package/components/checkbox-popout/README.md +27 -6
  18. package/components/checkbox-popout/checkbox-popout.vue +113 -47
  19. package/components/checkbox-popout/common.d.ts +3 -0
  20. package/components/checkbox-popout/index.scss +16 -0
  21. package/components/config/index.d.ts +6 -0
  22. package/components/config/index.js +6 -0
  23. package/components/datetime-picker/README.md +1 -71
  24. package/components/datetime-picker/common.d.ts +1 -0
  25. package/components/datetime-picker/common.js +21 -8
  26. package/components/datetime-picker/datetime-picker.vue +3 -3
  27. package/components/datetime-picker-input/README.md +10 -10
  28. package/components/datetime-picker-input/datetime-picker-input.vue +2 -2
  29. package/components/datetime-picker-popout/datetime-picker-popout.vue +1 -1
  30. package/components/datetime-range-picker/datetime-range-picker.vue +12 -10
  31. package/components/datetime-range-picker-input/README.md +10 -10
  32. package/components/datetime-range-picker-input/datetime-range-picker-input.vue +2 -2
  33. package/components/datetime-range-picker-popout/README.md +0 -6
  34. package/components/datetime-range-picker-popout/datetime-range-picker-popout.vue +11 -8
  35. package/components/floating-bubble/floating-bubble.vue +3 -3
  36. package/components/form/README.md +19 -19
  37. package/components/form/form.vue +1 -1
  38. package/components/icon/icon.d.ts +1 -1
  39. package/components/indexes/README.md +4 -0
  40. package/components/indexes-nav/indexes-nav.vue +2 -2
  41. package/components/keyboard/common.d.ts +1 -2
  42. package/components/keyboard/common.js +2 -11
  43. package/components/keyboard/keyboard.d.ts +2 -2
  44. package/components/list-item/index.scss +4 -0
  45. package/components/locale/lang/en-US.d.ts +4 -0
  46. package/components/locale/lang/en-US.js +4 -0
  47. package/components/locale/lang/zh-CN.d.ts +4 -0
  48. package/components/locale/lang/zh-CN.js +4 -0
  49. package/components/marquee/README.md +8 -2
  50. package/components/marquee/marquee.vue +9 -1
  51. package/components/notice-bar/README.md +8 -2
  52. package/components/notice-bar/notice-bar.vue +14 -8
  53. package/components/notify/notify.d.ts +1 -1
  54. package/components/notify-agent/notify-agent.d.ts +1 -1
  55. package/components/pagination/pagination.vue +2 -2
  56. package/components/popover/utils.js +4 -4
  57. package/components/pull-down-refresh/common.d.ts +1 -1
  58. package/components/radio/common.d.ts +1 -0
  59. package/components/radio/common.js +1 -0
  60. package/components/radio-input/radio-input.vue +6 -0
  61. package/components/radio-popout/README.md +20 -6
  62. package/components/radio-popout/common.d.ts +2 -0
  63. package/components/radio-popout/index.scss +4 -0
  64. package/components/radio-popout/radio-popout.vue +91 -45
  65. package/components/read-more/README.md +82 -0
  66. package/components/read-more/common.d.ts +24 -0
  67. package/components/read-more/common.js +2 -0
  68. package/components/read-more/index.d.ts +1 -0
  69. package/components/read-more/index.js +1 -0
  70. package/components/read-more/index.scss +41 -0
  71. package/components/read-more/read-more.d.ts +20 -0
  72. package/components/read-more/read-more.vue +168 -0
  73. package/components/read-more/variables.scss +12 -0
  74. package/components/resize-sensor/README.md +55 -0
  75. package/components/resize-sensor/common.d.ts +19 -0
  76. package/components/resize-sensor/common.js +2 -0
  77. package/components/resize-sensor/index.d.ts +1 -0
  78. package/components/resize-sensor/index.js +1 -0
  79. package/components/resize-sensor/index.scss +33 -0
  80. package/components/resize-sensor/resize-sensor.d.ts +16 -0
  81. package/components/resize-sensor/resize-sensor.vue +152 -0
  82. package/components/scroll-list/README.md +79 -0
  83. package/components/scroll-list/common.d.ts +23 -0
  84. package/components/scroll-list/common.js +1 -0
  85. package/components/scroll-list/index.d.ts +1 -0
  86. package/components/scroll-list/index.js +1 -0
  87. package/components/scroll-list/index.scss +35 -0
  88. package/components/scroll-list/scroll-list.d.ts +20 -0
  89. package/components/scroll-list/scroll-list.vue +158 -0
  90. package/components/scroll-list/variables.scss +11 -0
  91. package/components/sidebar/README.md +8 -8
  92. package/components/sidebar/sidebar.vue +1 -1
  93. package/components/slider/slider.vue +4 -4
  94. package/components/stepper/stepper.vue +2 -2
  95. package/components/sticky/README.md +92 -0
  96. package/components/sticky/common.d.ts +15 -0
  97. package/components/sticky/common.js +1 -0
  98. package/components/sticky/index.d.ts +1 -0
  99. package/components/sticky/index.js +1 -0
  100. package/components/sticky/index.scss +18 -0
  101. package/components/sticky/sticky.d.ts +10 -0
  102. package/components/sticky/sticky.vue +190 -0
  103. package/components/sticky-box/common.d.ts +19 -0
  104. package/components/sticky-box/common.js +1 -0
  105. package/components/sticky-box/index.d.ts +1 -0
  106. package/components/sticky-box/index.js +1 -0
  107. package/components/sticky-box/index.scss +19 -0
  108. package/components/sticky-box/sticky-box.d.ts +10 -0
  109. package/components/sticky-box/sticky-box.vue +82 -0
  110. package/components/style/mixins/border.scss +101 -38
  111. package/components/style/variables-dark.scss +4 -0
  112. package/components/style/variables.scss +8 -0
  113. package/components/table/table.vue +2 -1
  114. package/components/table-fixation/table-fixation.vue +2 -1
  115. package/components/toast/toast.d.ts +1 -1
  116. package/components/toast-agent/toast-agent.d.ts +1 -1
  117. package/components/tree/tree.d.ts +1 -1
  118. package/components/tree-node/tree-node.vue +2 -2
  119. package/components/upload/README.md +23 -15
  120. package/components/upload/common.d.ts +6 -4
  121. package/components/upload/upload.d.ts +2 -0
  122. package/components/upload/upload.vue +51 -13
  123. package/components/upload/utils.d.ts +1 -0
  124. package/components/upload/utils.js +2 -0
  125. package/components/upload-preview/index.scss +1 -0
  126. package/components/upload-preview/upload-preview.d.ts +6 -4
  127. package/components/upload-preview/upload-preview.vue +17 -24
  128. package/global.d.ts +5 -0
  129. package/index.d.ts +5 -0
  130. package/index.js +5 -0
  131. package/index.scss +2 -0
  132. package/package.json +4 -2
  133. package/use/index.d.ts +4 -0
  134. package/use/index.js +4 -0
  135. package/use/useIndeterminate.d.ts +10 -0
  136. package/use/useIndeterminate.js +27 -0
  137. package/use/useIntersectionObserver.d.ts +16 -0
  138. package/use/useIntersectionObserver.js +52 -0
  139. package/use/useSimulatedClick.js +2 -2
  140. package/use/useSimulatedPress.js +2 -2
  141. package/use/useSingleTask.d.ts +6 -0
  142. package/use/useSingleTask.js +40 -0
  143. package/use/useWindowResize.d.ts +4 -0
  144. package/use/useWindowResize.js +15 -0
  145. package/utils/array.d.ts +28 -0
  146. package/utils/array.js +90 -0
  147. package/utils/common.d.ts +3 -0
  148. package/utils/common.js +1 -0
  149. package/utils/date.d.ts +84 -11
  150. package/utils/date.js +120 -63
  151. package/utils/dom.js +2 -0
  152. package/utils/geometry.d.ts +56 -38
  153. package/utils/geometry.js +56 -30
  154. package/utils/index.d.ts +8 -1
  155. package/utils/index.js +8 -1
  156. package/utils/is.d.ts +12 -0
  157. package/utils/is.js +16 -0
  158. package/utils/number.d.ts +24 -0
  159. package/utils/number.js +37 -0
  160. package/utils/object.d.ts +29 -0
  161. package/utils/object.js +139 -0
  162. package/utils/persist.d.ts +15 -0
  163. package/utils/persist.js +89 -0
  164. package/utils/physics.d.ts +34 -0
  165. package/utils/physics.js +66 -0
  166. package/utils/request.d.ts +227 -0
  167. package/utils/request.js +249 -0
  168. package/utils/router.d.ts +47 -0
  169. package/utils/router.js +115 -0
  170. package/utils/string.d.ts +46 -0
  171. package/utils/string.js +134 -0
  172. package/utils/url-query.d.ts +19 -0
  173. package/utils/url-query.js +95 -0
  174. package/utils/utils.d.ts +0 -166
  175. package/utils/utils.js +0 -441
  176. package/utils/case.d.ts +0 -4
  177. package/utils/case.js +0 -26
package/utils/date.d.ts CHANGED
@@ -1,15 +1,58 @@
1
+ /**
2
+ * 判断是否为闰年。
3
+ */
1
4
  export declare function isLeapYear(year: number): boolean;
2
- export declare function getMonthDays(year: number, month: number): number;
3
- export declare function getDaysInYear(date: Date): number;
4
- export declare function getWeekOfMonthStart(year: number, month: number): number;
5
- export declare function getDaysInDate(date: Date): number;
5
+ /**
6
+ * 获取某月的天数,月份从0开始。
7
+ */
8
+ export declare function getDaysInMonth(year: number, month: number): number;
9
+ /**
10
+ * 获取当前日期是一年中的第几天。
11
+ */
12
+ export declare function getDayOfYear(date: Date): number;
13
+ /**
14
+ * 获取指定月份第一天是星期几,月份从0开始。
15
+ */
16
+ export declare function getFirstDayWeekday(year: number, month: number): number;
17
+ /**
18
+ * 获取从基准日期(如1970-01-01)到指定日期的总天数。
19
+ */
20
+ export declare function getDaysSinceUnixEpoch(date: Date): number;
21
+ /**
22
+ * 把日期转换为年月日数值,例如:2025年7月1号 -> 20250601。
23
+ */
6
24
  export declare function toDateNumber(date: Date): number;
25
+ /**
26
+ * 把日期转换为年月日字符串,,例如:2025年7月1号 -> 2025-7-1。
27
+ */
7
28
  export declare function toDateString(date: Date): string;
29
+ /**
30
+ * 把日期转换为年月数值,例如:2025年7月1号 -> 20250600。
31
+ */
8
32
  export declare function toMonthNumber(date: Date): number;
9
- export declare function getPadStartDays(year: number, month: number, amount: number): Date[];
10
- export declare function getPadEndDays(year: number, month: number, amount: number): Date[];
11
- export declare function getOffsetDaysFromMonthStart(weekOnMonthStart: number, weekStartsOn: number): number;
33
+ /**
34
+ * 计算当前月份1号前面需要显示的上个月末尾的天数。
35
+ */
36
+ export declare function getDaysBeforeFirstDay(year: number, month: number, weekStartsOn?: number): number;
37
+ /**
38
+ * 获取当前月份最后一天之后需要显示的下个月开始的天数。
39
+ */
40
+ export declare function getDaysAfterLastDay(year: number, month: number, weekStartsOn?: number): number;
41
+ /**
42
+ * 获取当前月份1号之前需要显示的上个月末尾的日期。
43
+ */
44
+ export declare function getPrevMonthTailDays(year: number, month: number, weekStartsOn?: number): Date[];
45
+ /**
46
+ * 获取当前月份最后一天之后需要显示的下个月开始的日期。
47
+ */
48
+ export declare function getNextMonthHeadDays(year: number, month: number, weekStartsOn?: number): Date[];
49
+ /**
50
+ * 根据传入的占位符返回格式化后的日期。
51
+ */
12
52
  export declare function formatDate(date: Date, format?: string): string;
53
+ /**
54
+ * 解析日期的字符串表示形式,并返回 Date 实例对象。
55
+ */
13
56
  export declare function parseDate(value: string, format?: string): Date;
14
57
  export declare function toDate(date: Date | string, valueFormat?: string): Date;
15
58
  export declare function minmaxDate(date: Date, minDate: Date, maxDate: Date): Date;
@@ -21,26 +64,56 @@ export declare function getNextMonthDate(date: Date): Date;
21
64
  export declare const lunarInfo: number[];
22
65
  export declare const springFestivals: number[][];
23
66
  export declare const baseLunarYear = 1900;
67
+ /**
68
+ * 获取农历某年闰月的月份,月份从1开始(0表示无闰月)。
69
+ */
24
70
  export declare function getLunarLeapMonth(year: number): number;
25
- export declare function getLunarLeapMonthDays(year: number): 0 | 30 | 29;
71
+ /**
72
+ * 获取农历某年闰月的天数。
73
+ */
74
+ export declare function getLunarLeapMonthDays(year: number): number;
75
+ /**
76
+ * 获取农历某年的总天数。
77
+ */
26
78
  export declare function getLunarYearDays(year: number): number;
27
- export declare function getLunarMonthDays(year: number, month: number): 30 | 29;
28
- export declare function solarToLunar(year: number, _month: number, date: number): {
79
+ /**
80
+ * 获取农历某年某月的天数,月份从1开始。
81
+ */
82
+ export declare function getLunarMonthDays(year: number, month: number): number;
83
+ /**
84
+ * 公历转农历,月份从1开始(返回的闰月为负数)。
85
+ */
86
+ export declare function solarToLunar(year: number, month: number, day: number): {
29
87
  year: number;
30
88
  month: number;
31
89
  day: number;
32
90
  };
33
- export declare function lunarToSolar(lunarYear: number, lunarMonth: number, lunarDay: number): {
91
+ /**
92
+ * 农历转公历(闰月需传递负数)。
93
+ */
94
+ export declare function lunarToSolar(year: number, month: number, day: number): {
34
95
  year: number;
35
96
  month: number;
36
97
  day: number;
37
98
  };
38
99
  export declare const lunarYearNames: string[];
100
+ /**
101
+ * 将阿拉伯数字的年份转为汉字数字年份
102
+ */
39
103
  export declare function getLunarYearName(year: number): string;
40
104
  export declare const lunarMonthNames: string[];
105
+ /**
106
+ * 获取农历月份名称,月份从1开始,例如:正月,十月,腊月。
107
+ */
41
108
  export declare function getLunarMonthName(month: number, isLeapMonth?: boolean): string;
42
109
  export declare const lunarDayNames: string[];
110
+ /**
111
+ * 获取农历日期名称,例如:初一,十二,廿一。
112
+ */
43
113
  export declare function getLunarDayName(day: number): string;
44
114
  export declare const heavenlyStems: string[];
45
115
  export declare const earthlyBranches: string[];
116
+ /**
117
+ * 获取农历时辰名称,例如:子初、子正、午初,午正。
118
+ */
46
119
  export declare function getLunarHourName(hour: number): string;
package/utils/date.js CHANGED
@@ -1,70 +1,102 @@
1
+ import { clamp } from './number';
1
2
  import { escapeRegExp } from './regexp';
2
- import { minmax } from './utils';
3
- // 判断是否为闰年
3
+ /**
4
+ * 判断是否为闰年。
5
+ */
4
6
  export function isLeapYear(year) {
5
7
  return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
6
8
  }
7
9
  const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
8
- // 获取某月的天数
9
- export function getMonthDays(year, month) {
10
- if (month === 2) {
10
+ /**
11
+ * 获取某月的天数,月份从0开始。
12
+ */
13
+ export function getDaysInMonth(year, month) {
14
+ if (month === 1) {
11
15
  return isLeapYear(year) ? 29 : 28;
12
16
  }
13
17
  else {
14
- return monthDays[month - 1];
18
+ return monthDays[month];
15
19
  }
16
20
  }
17
- // 获取当前日期是一年中的第几天
18
- export function getDaysInYear(date) {
21
+ /**
22
+ * 获取当前日期是一年中的第几天。
23
+ */
24
+ export function getDayOfYear(date) {
19
25
  const year = date.getFullYear();
20
26
  const month = date.getMonth();
21
27
  const d = date.getDate();
22
28
  let days = 0;
23
29
  for (let m = 0; m < month; m++) {
24
- days += getMonthDays(year, m + 1);
30
+ days += getDaysInMonth(year, m);
25
31
  }
26
32
  return days + d;
27
33
  }
28
- // 获取某月一号对应是星期几
29
- export function getWeekOfMonthStart(year, month) {
30
- return new Date(year, month - 1, 1).getDay();
34
+ /**
35
+ * 获取指定月份第一天是星期几,月份从0开始。
36
+ */
37
+ export function getFirstDayWeekday(year, month) {
38
+ return new Date(year, month, 1).getDay();
31
39
  }
32
- // 获取 Date 中的总天数
33
- export function getDaysInDate(date) {
40
+ /**
41
+ * 获取从基准日期(如1970-01-01)到指定日期的总天数。
42
+ */
43
+ export function getDaysSinceUnixEpoch(date) {
34
44
  return Math.floor(date.getTime() / 1000 / 60 / 60 / 24);
35
45
  }
36
- // 把日期转换为年月日数值
46
+ /**
47
+ * 把日期转换为年月日数值,例如:2025年7月1号 -> 20250601。
48
+ */
37
49
  export function toDateNumber(date) {
38
50
  return date.getFullYear() * 10000 + date.getMonth() * 100 + date.getDate();
39
51
  }
40
- // 把日期转换为年月日字符串
52
+ /**
53
+ * 把日期转换为年月日字符串,,例如:2025年7月1号 -> 2025-7-1。
54
+ */
41
55
  export function toDateString(date) {
42
56
  return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
43
57
  }
44
- // 把日期转换为年月数值
58
+ /**
59
+ * 把日期转换为年月数值,例如:2025年7月1号 -> 20250600。
60
+ */
45
61
  export function toMonthNumber(date) {
46
62
  return date.getFullYear() * 10000 + date.getMonth() * 100;
47
63
  }
48
- // 获取从开头开始填充的日期
49
- export function getPadStartDays(year, month, amount) {
64
+ /**
65
+ * 计算当前月份1号前面需要显示的上个月末尾的天数。
66
+ */
67
+ export function getDaysBeforeFirstDay(year, month, weekStartsOn = 0) {
68
+ const week = getFirstDayWeekday(year, month);
69
+ return (week - weekStartsOn + 7) % 7;
70
+ }
71
+ /**
72
+ * 获取当前月份最后一天之后需要显示的下个月开始的天数。
73
+ */
74
+ export function getDaysAfterLastDay(year, month, weekStartsOn = 0) {
75
+ const daysBefore = getDaysBeforeFirstDay(year, month, weekStartsOn);
76
+ return 42 - daysBefore - getDaysInMonth(year, month);
77
+ }
78
+ /**
79
+ * 获取当前月份1号之前需要显示的上个月末尾的日期。
80
+ */
81
+ export function getPrevMonthTailDays(year, month, weekStartsOn = 0) {
82
+ const daysBefore = getDaysBeforeFirstDay(year, month, weekStartsOn);
50
83
  const dates = [];
51
- for (let i = amount - 1; i >= 0; i--) {
52
- dates.push(new Date(year, month - 1, -i));
84
+ for (let i = daysBefore - 1; i >= 0; i--) {
85
+ dates.push(new Date(year, month, -i));
53
86
  }
54
87
  return dates;
55
88
  }
56
- // 获取从结尾开始填充的日期
57
- export function getPadEndDays(year, month, amount) {
89
+ /**
90
+ * 获取当前月份最后一天之后需要显示的下个月开始的日期。
91
+ */
92
+ export function getNextMonthHeadDays(year, month, weekStartsOn = 0) {
93
+ const daysAfter = getDaysAfterLastDay(year, month, weekStartsOn);
58
94
  const dates = [];
59
- for (let i = 1; i <= amount; i++) {
60
- dates.push(new Date(year, month + 1 - 1, i));
95
+ for (let i = 1; i <= daysAfter; i++) {
96
+ dates.push(new Date(year, month + 1, i));
61
97
  }
62
98
  return dates;
63
99
  }
64
- // 获取一号偏移的天数
65
- export function getOffsetDaysFromMonthStart(weekOnMonthStart, weekStartsOn) {
66
- return (weekOnMonthStart - weekStartsOn + 7) % 7;
67
- }
68
100
  const dateTokensReg = /(YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|SSS)/g;
69
101
  const dateGetters = {
70
102
  YYYY: (date) => String(date.getFullYear()).padStart(4, '0'),
@@ -83,7 +115,9 @@ const dateGetters = {
83
115
  s: (date) => String(date.getSeconds()),
84
116
  SSS: (date) => String(date.getMilliseconds()).padStart(3, '0'),
85
117
  };
86
- // 根据传入的占位符返回格式化后的日期
118
+ /**
119
+ * 根据传入的占位符返回格式化后的日期。
120
+ */
87
121
  export function formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
88
122
  return format.replace(dateTokensReg, (match) => {
89
123
  return dateGetters[match](date);
@@ -116,7 +150,9 @@ function parseDateWithoutFormat(value) {
116
150
  });
117
151
  return date;
118
152
  }
119
- // 解析日期的字符串表示形式,并返回 Date 实例对象
153
+ /**
154
+ * 解析日期的字符串表示形式,并返回 Date 实例对象。
155
+ */
120
156
  export function parseDate(value, format) {
121
157
  if (!format) {
122
158
  return parseDateWithoutFormat(value);
@@ -139,22 +175,22 @@ export function parseDate(value, format) {
139
175
  });
140
176
  return date;
141
177
  }
142
- // 确保返回一个Date对象,如果传递字符串,则使用 parseDate 解析
178
+ // 确保返回一个Date对象,如果传递字符串,则使用 parseDate 解析。
143
179
  export function toDate(date, valueFormat) {
144
180
  if (date instanceof Date) {
145
181
  return date;
146
182
  }
147
183
  return parseDate(date, valueFormat);
148
184
  }
149
- // 限定日期范围
185
+ // 限定日期范围,会返回一个新的日期。
150
186
  export function minmaxDate(date, minDate, maxDate) {
151
- return new Date(minmax(date.getTime(), minDate.getTime(), maxDate.getTime()));
187
+ return new Date(clamp(date.getTime(), minDate.getTime(), maxDate.getTime()));
152
188
  }
153
- // 获取上一个月的日期对象
189
+ // 获取上一个月的日期对象。
154
190
  export function getPrevMonthDate(date) {
155
191
  return new Date(date.getFullYear(), date.getMonth() - 1, 1);
156
192
  }
157
- // 获取下一个月的日期对象
193
+ // 获取下一个月的日期对象。
158
194
  export function getNextMonthDate(date) {
159
195
  return new Date(date.getFullYear(), date.getMonth() + 1, 1);
160
196
  }
@@ -211,18 +247,24 @@ export const springFestivals = [
211
247
  [2, 9], // 2100
212
248
  ];
213
249
  export const baseLunarYear = 1900;
214
- // 获取农历某年闰月的月份(0表示无闰月)
250
+ /**
251
+ * 获取农历某年闰月的月份,月份从1开始(0表示无闰月)。
252
+ */
215
253
  export function getLunarLeapMonth(year) {
216
254
  return lunarInfo[year - baseLunarYear] & 0xf;
217
255
  }
218
- // 获取农历某年闰月的天数
256
+ /**
257
+ * 获取农历某年闰月的天数。
258
+ */
219
259
  export function getLunarLeapMonthDays(year) {
220
260
  if (getLunarLeapMonth(year)) {
221
261
  return lunarInfo[year - baseLunarYear] & 0x10000 ? 30 : 29;
222
262
  }
223
263
  return 0;
224
264
  }
225
- // 获取农历某年的总天数
265
+ /**
266
+ * 获取农历某年的总天数。
267
+ */
226
268
  export function getLunarYearDays(year) {
227
269
  let sum = 348; // 29天*12个月
228
270
  const info = lunarInfo[year - baseLunarYear];
@@ -233,14 +275,18 @@ export function getLunarYearDays(year) {
233
275
  // 加上闰月的天数
234
276
  return sum + getLunarLeapMonthDays(year);
235
277
  }
236
- // 获取农历某年某月的天数
278
+ /**
279
+ * 获取农历某年某月的天数,月份从1开始。
280
+ */
237
281
  export function getLunarMonthDays(year, month) {
238
282
  return lunarInfo[year - baseLunarYear] & (0x10000 >> month) ? 30 : 29;
239
283
  }
240
- // 公历转农历
241
- export function solarToLunar(year, _month, date) {
284
+ /**
285
+ * 公历转农历,月份从1开始(返回的闰月为负数)。
286
+ */
287
+ export function solarToLunar(year, month, day) {
242
288
  // 计算输入日期与基准日期的天数差
243
- const offsetDays = Math.floor((Date.UTC(year, _month - 1, date) - Date.UTC(baseLunarYear, 0, 31)) /
289
+ const offsetDays = Math.floor((Date.UTC(year, month - 1, day) - Date.UTC(baseLunarYear, 0, 31)) /
244
290
  (24 * 60 * 60 * 1000));
245
291
  // 农历年、月、日初始化
246
292
  let lunarYear = baseLunarYear;
@@ -260,25 +306,25 @@ export function solarToLunar(year, _month, date) {
260
306
  // 计算农历月和日
261
307
  const leapMonth = getLunarLeapMonth(lunarYear);
262
308
  let monthDays = 0;
263
- let month = 1;
264
- for (; month <= 12; month++) {
309
+ let _month = 1;
310
+ for (; _month <= 12; _month++) {
265
311
  // 处理闰月
266
- if (leapMonth > 0 && month === leapMonth + 1) {
312
+ if (leapMonth > 0 && _month === leapMonth + 1) {
267
313
  monthDays = getLunarLeapMonthDays(lunarYear);
268
314
  if (daysRemaining < monthDays) {
269
315
  isLeapMonth = true;
270
- month--;
316
+ _month--;
271
317
  break;
272
318
  }
273
319
  daysRemaining -= monthDays;
274
320
  }
275
- monthDays = getLunarMonthDays(lunarYear, month);
321
+ monthDays = getLunarMonthDays(lunarYear, _month);
276
322
  if (daysRemaining < monthDays) {
277
323
  break;
278
324
  }
279
325
  daysRemaining -= monthDays;
280
326
  }
281
- lunarMonth = month;
327
+ lunarMonth = _month;
282
328
  lunarDay = daysRemaining + 1;
283
329
  return {
284
330
  year: lunarYear,
@@ -286,24 +332,26 @@ export function solarToLunar(year, _month, date) {
286
332
  day: lunarDay,
287
333
  };
288
334
  }
289
- // 农历转公历(闰月需传递负数)
290
- export function lunarToSolar(lunarYear, lunarMonth, lunarDay) {
291
- const springFestival = springFestivals[lunarYear - baseLunarYear];
292
- const solarDate = new Date(lunarYear, springFestival[0] - 1, springFestival[1]);
293
- const info = lunarInfo[lunarYear - baseLunarYear];
335
+ /**
336
+ * 农历转公历(闰月需传递负数)。
337
+ */
338
+ export function lunarToSolar(year, month, day) {
339
+ const springFestival = springFestivals[year - baseLunarYear];
340
+ const solarDate = new Date(year, springFestival[0] - 1, springFestival[1]);
341
+ const info = lunarInfo[year - baseLunarYear];
294
342
  const leapMonth = info & 0xf;
295
343
  let totalDays = 0;
296
- const absMonth = Math.abs(lunarMonth);
344
+ const absMonth = Math.abs(month);
297
345
  for (let m = 1; m < absMonth; m++) {
298
346
  if (m === leapMonth) {
299
- totalDays += getLunarLeapMonthDays(lunarYear);
347
+ totalDays += getLunarLeapMonthDays(year);
300
348
  }
301
- totalDays += getLunarMonthDays(lunarYear, m);
349
+ totalDays += getLunarMonthDays(year, m);
302
350
  }
303
- if (lunarMonth < 0) {
304
- totalDays += getLunarMonthDays(lunarYear, absMonth);
351
+ if (month < 0) {
352
+ totalDays += getLunarMonthDays(year, absMonth);
305
353
  }
306
- totalDays += lunarDay - 1;
354
+ totalDays += day - 1;
307
355
  solarDate.setDate(solarDate.getDate() + totalDays);
308
356
  return {
309
357
  year: solarDate.getFullYear(),
@@ -314,6 +362,9 @@ export function lunarToSolar(lunarYear, lunarMonth, lunarDay) {
314
362
  // 农历年份的名称
315
363
  // prettier-ignore
316
364
  export const lunarYearNames = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'];
365
+ /**
366
+ * 将阿拉伯数字的年份转为汉字数字年份
367
+ */
317
368
  export function getLunarYearName(year) {
318
369
  return (String(year)
319
370
  .split('')
@@ -323,14 +374,18 @@ export function getLunarYearName(year) {
323
374
  // 农历月份的名称
324
375
  // prettier-ignore
325
376
  export const lunarMonthNames = ['正', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'];
326
- // 获取农历月份名称
377
+ /**
378
+ * 获取农历月份名称,月份从1开始,例如:正月,十月,腊月。
379
+ */
327
380
  export function getLunarMonthName(month, isLeapMonth) {
328
381
  return (isLeapMonth ? '闰' : '') + lunarMonthNames[month - 1] + '月';
329
382
  }
330
383
  // 农历日期的名称
331
384
  // prettier-ignore
332
385
  export const lunarDayNames = ['初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'];
333
- // 获取农历日期名称
386
+ /**
387
+ * 获取农历日期名称,例如:初一,十二,廿一。
388
+ */
334
389
  export function getLunarDayName(day) {
335
390
  return lunarDayNames[day - 1];
336
391
  }
@@ -340,7 +395,9 @@ export const heavenlyStems = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '
340
395
  // 十二地支
341
396
  // prettier-ignore
342
397
  export const earthlyBranches = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'];
343
- // 获取农历时辰名称
398
+ /**
399
+ * 获取农历时辰名称,例如:子初、子正、午初,午正。
400
+ */
344
401
  export function getLunarHourName(hour) {
345
402
  const index = Math.floor(((hour === 23 ? 0 : hour) + 1) / 2) % 12;
346
403
  return earthlyBranches[index] + (hour % 2 === 1 ? '初' : '正');
package/utils/dom.js CHANGED
@@ -58,6 +58,8 @@ export function toTouchEvent(event, windowTop = 0) {
58
58
  {
59
59
  clientX: event.clientX,
60
60
  clientY: event.clientY - windowTop,
61
+ pageY: event.pageY,
62
+ pageX: event.pageX,
61
63
  },
62
64
  ];
63
65
  event.changedTouches = touches;
@@ -1,9 +1,4 @@
1
1
  export type ScrollIntoViewPosition = 'start' | 'center' | 'end' | 'nearest';
2
- export interface ScrollIntoViewValueOptions {
3
- position?: ScrollIntoViewPosition;
4
- startOffset?: number;
5
- endOffset?: number;
6
- }
7
2
  export interface ScrollIntoViewOptions {
8
3
  position?: ScrollIntoViewPosition;
9
4
  startOffset?: number;
@@ -11,36 +6,32 @@ export interface ScrollIntoViewOptions {
11
6
  duration?: number;
12
7
  }
13
8
  /**
14
- ```
15
- page
16
-
17
- ╭───────────────╮ viewport
18
- ╭─│─ ─ ─ ─ ─ ─ ─ ─│─╮ ╱
19
- │ ╭───────────╮ │ │
20
- │ │ element │ │ │
21
- ╰───────────╯
22
- ╰─│─ ─ ─ ─ ─│─╯
23
-
24
-
25
- ╰───────────────╯
26
- ```
27
-
28
- # 参数
29
- - viewportHeight: viewport 高度
30
- - viewportScrollTop: viewport 垂直滚动值
31
- - elementHeight: element 高度
32
- - elementOffsetTop: element 距离页面顶部距离
33
-
34
- # 选项
35
- - position: element 在视窗中的位置(start, center, end, nearest)
36
- - startOffset: element 距离视窗顶部的偏移量
37
- - endOffset: element 距离视窗底部的偏移量
38
-
39
- # 结果值
40
- - viewportScrollTop: viewport 新的垂直滚动值
41
-
42
- */
43
- export declare function getScrollIntoViewValue(viewportHeight: number, viewportScrollTop: number, elementHeight: number, elementOffsetTop: number, options?: ScrollIntoViewValueOptions): number;
9
+ * 根据最后位置计算 page 滚动到顶部的值。
10
+ *
11
+ * 也可计算水平方向的滚动值。
12
+ *
13
+ * page
14
+ * ╱
15
+ * ╭───────────────╮ viewport
16
+ * ╭─│─ ─ ─ ─ ─│─╮ ╱
17
+ * ╭───────────╮
18
+ * │ element │ │ │
19
+ * ╰───────────╯ │ │
20
+ * ╰─│─ ─ ─ ─ ─ ─ ─ ─│─╯
21
+ * │ │
22
+ * │ │
23
+ * ╰───────────────╯
24
+ *
25
+ * @param {number} viewportHeight viewport 高度
26
+ * @param {number} viewportScrollTop viewport 垂直滚动值
27
+ * @param {number} elementHeight element 高度
28
+ * @param {number} elementOffsetTop element 距离页面顶部距离
29
+ * @param {string} options.position element 在 viewport 中的位置,可选:'start' | 'center' | 'end' | 'nearest'
30
+ * @param {number} options.startOffset element 距离视窗顶部的偏移量
31
+ * @param {number} options.endOffset element 距离视窗底部的偏移量
32
+ * @return {number} viewport 新的垂直滚动值
33
+ */
34
+ export declare function getScrollIntoViewValue(viewportHeight: number, viewportScrollTop: number, elementHeight: number, elementOffsetTop: number, options?: ScrollIntoViewOptions): number;
44
35
  export interface NodeRect {
45
36
  top: number;
46
37
  right: number;
@@ -49,19 +40,46 @@ export interface NodeRect {
49
40
  height: number;
50
41
  width: number;
51
42
  }
52
- interface MatchScrollVisibleOptions {
43
+ export interface MatchScrollVisibleOptions {
53
44
  offset?: number;
54
45
  errorValue?: number;
55
46
  }
56
47
  /**
57
- * @description: 匹配元素列表中第一个位于滚动盒子可视区域的元素
48
+ * 匹配元素列表中第一个位于滚动盒子可视区域的元素
49
+ *
50
+ * @param {array} rects NodeRect 类型数组
51
+ * @param {function} callback 匹配成功时调用,会接收匹配的元素的下标
52
+ * @param {number} options.offset 偏移量
53
+ * @param {number} options.errorValue 容错值
58
54
  */
59
55
  export declare function matchScrollVisible(rects: NodeRect[], callback: (index: number) => unknown, options?: MatchScrollVisibleOptions): Promise<unknown>;
56
+ /**
57
+ * 保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取。
58
+ */
60
59
  export declare function getAspectFillSize(origWidth: number, origHeight: number, containerWidth: number, containerHeight: number): [number, number];
60
+ /**
61
+ * 保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来。
62
+ */
61
63
  export declare function getAspectFitSize(origWidth: number, origHeight: number, containerWidth: number, containerHeight: number): [number, number];
62
- interface Point {
64
+ export interface Point {
63
65
  x: number;
64
66
  y: number;
65
67
  }
68
+ /**
69
+ * 获取两点间的距离
70
+ */
66
71
  export declare function getTwoPointsDistance(p1: Point, p2: Point): number;
72
+ interface Rect {
73
+ x: number;
74
+ y: number;
75
+ width: number;
76
+ height: number;
77
+ }
78
+ /**
79
+ * @description: 根据原始坐标尺寸和缩放后的坐标尺寸算出转换的原点
80
+ * @param {Rect} rect
81
+ * @param {Rect} scaleRect
82
+ * @return {[number, number]}
83
+ */
84
+ export declare function getTransformOrigin(rect: Rect, scaleRect: Rect): [number, number];
67
85
  export {};