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
@@ -111,6 +111,7 @@
111
111
  padding: 0 var(--sar-upload-status-message-padding-x);
112
112
  margin-top: var(--sar-upload-status-message-margin-top);
113
113
  font-size: var(--sar-upload-status-message-font-size);
114
+ text-align: center;
114
115
  }
115
116
 
116
117
  @include e(remove) {
@@ -1,10 +1,12 @@
1
1
  import { type UploadPreviewProps } from '../upload/common';
2
2
  declare const _default: import("vue").DefineComponent<UploadPreviewProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
3
- remove: (index: number) => any;
4
- "image-click": (index: number) => any;
3
+ click: () => any;
4
+ remove: () => any;
5
+ "image-click": () => any;
5
6
  }, string, import("vue").PublicProps, Readonly<UploadPreviewProps> & Readonly<{
6
- onRemove?: ((index: number) => any) | undefined;
7
- "onImage-click"?: ((index: number) => any) | undefined;
7
+ onClick?: (() => any) | undefined;
8
+ onRemove?: (() => any) | undefined;
9
+ "onImage-click"?: (() => any) | undefined;
8
10
  }>, {
9
11
  status: import("../upload/common").UploadStatus;
10
12
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -1,5 +1,9 @@
1
1
  <template>
2
- <view :class="uploadPreviewClass" :style="uploadPreviewStyle">
2
+ <view
3
+ :class="uploadPreviewClass"
4
+ :style="uploadPreviewStyle"
5
+ @click="onClick"
6
+ >
3
7
  <image
4
8
  v-if="isImage"
5
9
  :class="bem.e('image')"
@@ -47,7 +51,7 @@
47
51
  <view
48
52
  v-if="removable && !disabled && !readonly && status !== 'uploading'"
49
53
  :class="bem.e('remove')"
50
- @click="onRemove"
54
+ @click.stop="onRemove"
51
55
  >
52
56
  <view :class="bem.e('close')">
53
57
  <sar-icon family="sari" name="close" />
@@ -95,12 +99,11 @@ export default _defineComponent({
95
99
  name: { type: String, required: false },
96
100
  message: { type: String, required: false },
97
101
  removable: { type: Boolean, required: false },
98
- beforeRemove: { type: Function, required: false },
99
102
  index: { type: Number, required: true },
100
103
  disabled: { type: Boolean, required: false },
101
104
  readonly: { type: Boolean, required: false }
102
105
  }, defaultUploadPreviewProps),
103
- emits: ["image-click", "remove"],
106
+ emits: ["image-click", "remove", "click"],
104
107
  setup(__props, { expose: __expose, emit: __emit }) {
105
108
  __expose();
106
109
  const props = __props;
@@ -116,7 +119,7 @@ export default _defineComponent({
116
119
  return props.url || props.file?.path || "";
117
120
  });
118
121
  const onImageClick = () => {
119
- emit("image-click", props.index);
122
+ emit("image-click");
120
123
  };
121
124
  const videoId = uniqid();
122
125
  const instance = getCurrentInstance();
@@ -131,30 +134,20 @@ export default _defineComponent({
131
134
  controlsVisible.value = false;
132
135
  }
133
136
  };
134
- const onPlayClick = () => {
137
+ const previewVideo = () => {
135
138
  videoContext.requestFullScreen({
136
139
  direction: 0
137
140
  });
138
141
  };
142
+ const onPlayClick = () => {
143
+ previewVideo();
144
+ };
139
145
  const onRemove = () => {
140
146
  if (!props.removable || props.disabled || props.readonly) return;
141
- function remove() {
142
- emit("remove", props.index);
143
- }
144
- if (props.beforeRemove) {
145
- const ret = props.beforeRemove(props.index);
146
- if (!ret) {
147
- return;
148
- }
149
- if (ret instanceof Promise) {
150
- ret.then(() => {
151
- remove();
152
- }).catch(() => {
153
- });
154
- return;
155
- }
156
- }
157
- remove();
147
+ emit("remove");
148
+ };
149
+ const onClick = () => {
150
+ emit("click");
158
151
  };
159
152
  const uploadPreviewClass = computed(() => {
160
153
  return classNames(
@@ -166,7 +159,7 @@ export default _defineComponent({
166
159
  const uploadPreviewStyle = computed(() => {
167
160
  return stringifyStyle(props.rootStyle);
168
161
  });
169
- const __returned__ = { props, emit, bem, isImage, isVideo, mediaUrl, onImageClick, videoId, instance, controlsVisible, videoContext, onFullscreenchange, onPlayClick, onRemove, uploadPreviewClass, uploadPreviewStyle, SarIcon, SarLoading };
162
+ const __returned__ = { props, emit, bem, isImage, isVideo, mediaUrl, onImageClick, videoId, instance, controlsVisible, videoContext, onFullscreenchange, previewVideo, onPlayClick, onRemove, onClick, uploadPreviewClass, uploadPreviewStyle, SarIcon, SarLoading };
170
163
  return __returned__;
171
164
  }
172
165
  });
package/global.d.ts CHANGED
@@ -82,8 +82,11 @@ declare module 'vue' {
82
82
  SarRadioInput: typeof import('./components/radio-input/radio-input').default
83
83
  SarRadioPopout: typeof import('./components/radio-popout/radio-popout').default
84
84
  SarRate: typeof import('./components/rate/rate').default
85
+ SarReadMore: typeof import('./components/read-more/read-more').default
86
+ SarResizeSensor: typeof import('./components/resize-sensor/resize-sensor').default
85
87
  SarResult: typeof import('./components/result/result').default
86
88
  SarRow: typeof import('./components/row/row').default
89
+ SarScrollList: typeof import('./components/scroll-list/scroll-list').default
87
90
  SarScrollSpy: typeof import('./components/scroll-spy/scroll-spy').default
88
91
  SarScrollSpyAnchor: typeof import('./components/scroll-spy-anchor/scroll-spy-anchor').default
89
92
  SarSearch: typeof import('./components/search/search').default
@@ -102,6 +105,8 @@ declare module 'vue' {
102
105
  SarStep: typeof import('./components/step/step').default
103
106
  SarStepper: typeof import('./components/stepper/stepper').default
104
107
  SarSteps: typeof import('./components/steps/steps').default
108
+ SarSticky: typeof import('./components/sticky/sticky').default
109
+ SarStickyBox: typeof import('./components/sticky-box/sticky-box').default
105
110
  SarSwipeAction: typeof import('./components/swipe-action/swipe-action').default
106
111
  SarSwiperDot: typeof import('./components/swiper-dot/swiper-dot').default
107
112
  SarSwitch: typeof import('./components/switch/switch').default
package/index.d.ts CHANGED
@@ -73,7 +73,10 @@ export * from './components/radio';
73
73
  export * from './components/radio-input';
74
74
  export * from './components/radio-popout';
75
75
  export * from './components/rate';
76
+ export * from './components/read-more';
77
+ export * from './components/resize-sensor';
76
78
  export * from './components/result';
79
+ export * from './components/scroll-list';
77
80
  export * from './components/scroll-spy';
78
81
  export * from './components/scroll-spy-anchor';
79
82
  export * from './components/search';
@@ -88,6 +91,8 @@ export * from './components/status-bar';
88
91
  export * from './components/step';
89
92
  export * from './components/stepper';
90
93
  export * from './components/steps';
94
+ export * from './components/sticky';
95
+ export * from './components/sticky-box';
91
96
  export * from './components/swipe-action';
92
97
  export * from './components/swiper-dot';
93
98
  export * from './components/switch';
package/index.js CHANGED
@@ -73,7 +73,10 @@ export * from './components/radio';
73
73
  export * from './components/radio-input';
74
74
  export * from './components/radio-popout';
75
75
  export * from './components/rate';
76
+ export * from './components/read-more';
77
+ export * from './components/resize-sensor';
76
78
  export * from './components/result';
79
+ export * from './components/scroll-list';
77
80
  export * from './components/scroll-spy';
78
81
  export * from './components/scroll-spy-anchor';
79
82
  export * from './components/search';
@@ -88,6 +91,8 @@ export * from './components/status-bar';
88
91
  export * from './components/step';
89
92
  export * from './components/stepper';
90
93
  export * from './components/steps';
94
+ export * from './components/sticky';
95
+ export * from './components/sticky-box';
91
96
  export * from './components/swipe-action';
92
97
  export * from './components/swiper-dot';
93
98
  export * from './components/switch';
package/index.scss CHANGED
@@ -50,8 +50,10 @@
50
50
  @use './components/radio-popout/variables.scss' as *;
51
51
  @use './components/radio/variables.scss' as *;
52
52
  @use './components/rate/variables.scss' as *;
53
+ @use './components/read-more/variables.scss' as *;
53
54
  @use './components/result/variables.scss' as *;
54
55
  @use './components/row/variables.scss' as *;
56
+ @use './components/scroll-list/variables.scss' as *;
55
57
  @use './components/search/variables.scss' as *;
56
58
  @use './components/share-sheet/variables.scss' as *;
57
59
  @use './components/sidebar/variables.scss' as *;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "sard-uniapp",
3
3
  "name": "sard-uniapp",
4
4
  "displayName": "sard-uniapp",
5
- "version": "1.19.5",
5
+ "version": "1.20.0",
6
6
  "description": "sard-uniapp 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库",
7
7
  "main": "index.js",
8
8
  "scripts": {
@@ -108,6 +108,7 @@
108
108
  "@vitejs/plugin-vue-jsx": "^3.1.0",
109
109
  "@vue/runtime-core": "^3.4.21",
110
110
  "@vue/test-utils": "^2.4.6",
111
+ "chokidar": "^4.0.3",
111
112
  "consola": "^3.2.3",
112
113
  "eslint": "^9.16.0",
113
114
  "eslint-config-prettier": "^8.10.0",
@@ -122,8 +123,9 @@
122
123
  "lodash-es": "^4.17.21",
123
124
  "prettier": "^3.5.3",
124
125
  "region-data": "^1.2.3",
125
- "sard-cli": "^1.3.1",
126
+ "sard-cli": "^1.3.3",
126
127
  "sass": "^1.69.7",
128
+ "tailwindcss": "^3.4.17",
127
129
  "tel-area-code": "^1.1.0",
128
130
  "ts-custom-error": "^3.3.1",
129
131
  "tsx": "^4.19.2",
package/use/index.d.ts CHANGED
@@ -18,3 +18,7 @@ export * from './usePopoutInput';
18
18
  export * from './useFormPopout';
19
19
  export * from './useInitialVelocity';
20
20
  export * from './useStopMovedClick';
21
+ export * from './useIndeterminate';
22
+ export * from './useWindowResize';
23
+ export * from './useSingleTask';
24
+ export * from './useIntersectionObserver';
package/use/index.js CHANGED
@@ -18,3 +18,7 @@ export * from './usePopoutInput';
18
18
  export * from './useFormPopout';
19
19
  export * from './useInitialVelocity';
20
20
  export * from './useStopMovedClick';
21
+ export * from './useIndeterminate';
22
+ export * from './useWindowResize';
23
+ export * from './useSingleTask';
24
+ export * from './useIntersectionObserver';
@@ -0,0 +1,10 @@
1
+ import { MaybeRef, type Ref } from 'vue';
2
+ export declare function useIndeterminate(value: Ref<any[]>, options: MaybeRef<{
3
+ label: any;
4
+ value: any;
5
+ disabled?: boolean;
6
+ }[]>): {
7
+ allChecked: Ref<boolean, boolean>;
8
+ isIndeterminate: import("vue").ComputedRef<boolean>;
9
+ onAllChange: (checked: boolean) => void;
10
+ };
@@ -0,0 +1,27 @@
1
+ import { computed, ref, unref, watch } from 'vue';
2
+ export function useIndeterminate(value, options) {
3
+ const filterOptions = computed(() => {
4
+ return unref(options).filter((option) => !option.disabled);
5
+ });
6
+ const checkedLength = computed(() => value.value?.length || 0);
7
+ const optionsLength = computed(() => unref(filterOptions)?.length || 0);
8
+ const allChecked = ref(false);
9
+ const isIndeterminate = computed(() => {
10
+ return checkedLength.value > 0 && checkedLength.value < optionsLength.value;
11
+ });
12
+ const onAllChange = (checked) => {
13
+ value.value = checked
14
+ ? unref(filterOptions).map((option) => option.value)
15
+ : [];
16
+ };
17
+ watch([checkedLength, optionsLength], () => {
18
+ allChecked.value = checkedLength.value === optionsLength.value;
19
+ }, {
20
+ immediate: true,
21
+ });
22
+ return {
23
+ allChecked,
24
+ isIndeterminate,
25
+ onAllChange,
26
+ };
27
+ }
@@ -0,0 +1,16 @@
1
+ import { type ComponentInternalInstance, MaybeRef } from 'vue';
2
+ interface IntersectionObserverOptions {
3
+ root?: MaybeRef<string>;
4
+ selector?: MaybeRef<string>;
5
+ offsetTop?: MaybeRef<number | undefined>;
6
+ offsetBottom?: MaybeRef<number | undefined>;
7
+ thresholds?: number[];
8
+ initialRatio?: number;
9
+ observeAll?: boolean;
10
+ instance?: ComponentInternalInstance;
11
+ }
12
+ export declare function useIntersectionObserver(callback: (result: UniApp.ObserveResult) => void, options?: IntersectionObserverOptions): {
13
+ recreate: () => void;
14
+ disconnect: () => void;
15
+ };
16
+ export {};
@@ -0,0 +1,52 @@
1
+ import { computed, getCurrentInstance, onBeforeUnmount, onMounted, unref, watch, } from 'vue';
2
+ export function useIntersectionObserver(callback, options = {}) {
3
+ const instance = getCurrentInstance();
4
+ let observer = null;
5
+ const selector = computed(() => unref(options.selector));
6
+ const root = computed(() => unref(options.root));
7
+ const offsetTop = computed(() => -(unref(options.offsetTop) || 0));
8
+ const offsetBottom = computed(() => -(unref(options.offsetBottom) || 0));
9
+ const createObserver = () => {
10
+ if (!selector.value) {
11
+ return;
12
+ }
13
+ observer = uni.createIntersectionObserver(options.instance?.proxy || instance?.proxy, {
14
+ thresholds: options.thresholds,
15
+ initialRatio: options.initialRatio,
16
+ observeAll: options.observeAll,
17
+ });
18
+ if (root.value) {
19
+ observer?.relativeTo(root.value, {
20
+ top: offsetTop.value,
21
+ bottom: offsetBottom.value,
22
+ });
23
+ }
24
+ else {
25
+ observer?.relativeToViewport({
26
+ top: offsetTop.value,
27
+ bottom: offsetBottom.value,
28
+ });
29
+ }
30
+ observer?.observe(selector.value, callback);
31
+ };
32
+ watch([selector, root, offsetTop, offsetBottom], () => {
33
+ recreate();
34
+ });
35
+ const disconnect = () => {
36
+ observer?.disconnect();
37
+ };
38
+ const recreate = () => {
39
+ disconnect();
40
+ createObserver();
41
+ };
42
+ onMounted(() => {
43
+ createObserver();
44
+ });
45
+ onBeforeUnmount(() => {
46
+ disconnect();
47
+ });
48
+ return {
49
+ recreate,
50
+ disconnect,
51
+ };
52
+ }
@@ -1,4 +1,4 @@
1
- import { getDistanceBetweenTwoPoints } from '../utils';
1
+ import { getTwoPointsDistance } from '../utils';
2
2
  import { useTimeout } from './useTimeout';
3
3
  export function useSimulatedClick(click, duration = 10000) {
4
4
  let timeout = false;
@@ -20,7 +20,7 @@ export function useSimulatedClick(click, duration = 10000) {
20
20
  x: event.changedTouches[0].clientX,
21
21
  y: event.changedTouches[0].clientY,
22
22
  };
23
- const distance = getDistanceBetweenTwoPoints(downCoord, upCoord);
23
+ const distance = getTwoPointsDistance(downCoord, upCoord);
24
24
  if (distance <= 10) {
25
25
  click();
26
26
  }
@@ -1,4 +1,4 @@
1
- import { getDistanceBetweenTwoPoints } from '../utils';
1
+ import { getTwoPointsDistance } from '../utils';
2
2
  import { useTimeout } from './useTimeout';
3
3
  export function useSimulatedPress(options = {}) {
4
4
  const { start, move, end, duration = 500 } = options;
@@ -29,7 +29,7 @@ export function useSimulatedPress(options = {}) {
29
29
  });
30
30
  }
31
31
  else if (isWaitingToTriggerPress.value) {
32
- const distance = getDistanceBetweenTwoPoints(downCoord, moveCoord);
32
+ const distance = getTwoPointsDistance(downCoord, moveCoord);
33
33
  if (distance > 10) {
34
34
  cancelTriggerPress();
35
35
  }
@@ -0,0 +1,6 @@
1
+ export declare function useSingleTask(): {
2
+ isWorking: Readonly<import("vue").Ref<boolean, boolean>>;
3
+ startTask: (task: () => any) => Promise<void>;
4
+ onFinishTask: (handler: () => any) => void;
5
+ offFinishTask: (handler: () => any) => void;
6
+ };
@@ -0,0 +1,40 @@
1
+ import { readonly, ref } from 'vue';
2
+ export function useSingleTask() {
3
+ const isWorking = ref(false);
4
+ let listeners = [];
5
+ async function startTask(task) {
6
+ if (!isWorking.value) {
7
+ isWorking.value = true;
8
+ await task();
9
+ isWorking.value = false;
10
+ listeners.forEach((handler) => {
11
+ handler();
12
+ });
13
+ listeners = [];
14
+ }
15
+ }
16
+ function onFinishTask(handler) {
17
+ if (isWorking.value) {
18
+ if (!listeners.includes(handler)) {
19
+ listeners.push(handler);
20
+ }
21
+ }
22
+ else {
23
+ handler();
24
+ }
25
+ }
26
+ function offFinishTask(handler) {
27
+ if (isWorking.value) {
28
+ const index = listeners.indexOf(handler);
29
+ if (index !== -1) {
30
+ listeners.splice(index, 1);
31
+ }
32
+ }
33
+ }
34
+ return {
35
+ isWorking: readonly(isWorking),
36
+ startTask,
37
+ onFinishTask,
38
+ offFinishTask,
39
+ };
40
+ }
@@ -0,0 +1,4 @@
1
+ export declare function useWindowResize(callback: (size: {
2
+ windowWidth: number;
3
+ windowHeight: number;
4
+ }) => void): void;
@@ -0,0 +1,15 @@
1
+ import { onBeforeUnmount, onMounted } from 'vue';
2
+ export function useWindowResize(callback) {
3
+ const cb = (res) => {
4
+ callback({
5
+ windowWidth: res.size.windowWidth,
6
+ windowHeight: res.size.windowHeight,
7
+ });
8
+ };
9
+ onMounted(() => {
10
+ uni.onWindowResize?.(cb);
11
+ });
12
+ onBeforeUnmount(() => {
13
+ uni.offWindowResize?.(cb);
14
+ });
15
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @description: 确保目标是一个数组
3
+ * @param {any} target
4
+ * @return {array}
5
+ */
6
+ export declare function toArray(target: any): any[];
7
+ /**
8
+ * @description: 扩散性遍历
9
+ * @param {any[]} array 要遍历的数组
10
+ * @param {(el: any, spreadIndex: number, index: number) => any} callback 回调函数,接收当前元素、扩散性下标、迭代下标作为参数,
11
+ * 如果返回true,则中止遍历
12
+ * @param {number} currIndex 遍历开始的下标
13
+ * @param {number} direction 开始遍历的方向
14
+ * @return {number} 扩散性下标、或开始下标
15
+ */
16
+ export declare function spreadEach(array: any[], callback: (el: any, spreadIndex: number, index: number) => any, startIndex?: number, direction?: number): number;
17
+ /**
18
+ * 判断两数组是否相等,浅比较,元素个数和位置都要相等才为真。
19
+ */
20
+ export declare function arrayEqual(arr1: any[], arr2: any[]): boolean;
21
+ /**
22
+ * 打乱并返回数组,会修改原数组。
23
+ */
24
+ export declare function shuffle<T>(array: T[]): T[];
25
+ /**
26
+ * 移动数组中的元素,会返回移动后的新数组。
27
+ */
28
+ export declare function arrayMove<T>(array: T[], fromIndex: number, toIndex: number): T[];
package/utils/array.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @description: 确保目标是一个数组
3
+ * @param {any} target
4
+ * @return {array}
5
+ */
6
+ export function toArray(target) {
7
+ return Array.isArray(target) ? target : [target];
8
+ }
9
+ /**
10
+ * @description: 扩散性遍历
11
+ * @param {any[]} array 要遍历的数组
12
+ * @param {(el: any, spreadIndex: number, index: number) => any} callback 回调函数,接收当前元素、扩散性下标、迭代下标作为参数,
13
+ * 如果返回true,则中止遍历
14
+ * @param {number} currIndex 遍历开始的下标
15
+ * @param {number} direction 开始遍历的方向
16
+ * @return {number} 扩散性下标、或开始下标
17
+ */
18
+ export function spreadEach(array, callback, startIndex = 0, direction = -1) {
19
+ const len = array.length;
20
+ let spreadIndex = startIndex;
21
+ let edge = 0;
22
+ direction = -direction;
23
+ for (let i = 0; i < len; i++) {
24
+ if (edge < 0) {
25
+ spreadIndex = len - 1 - i;
26
+ }
27
+ else if (edge > 0) {
28
+ spreadIndex = i;
29
+ }
30
+ else {
31
+ spreadIndex = spreadIndex + direction * i;
32
+ edge = spreadIndex === 0 ? 1 : spreadIndex === len - 1 ? -1 : 0;
33
+ direction = -direction;
34
+ }
35
+ if (typeof callback === 'function') {
36
+ if (callback(array[spreadIndex], spreadIndex, i)) {
37
+ return spreadIndex;
38
+ }
39
+ }
40
+ }
41
+ return startIndex;
42
+ }
43
+ /**
44
+ * 判断两数组是否相等,浅比较,元素个数和位置都要相等才为真。
45
+ */
46
+ export function arrayEqual(arr1, arr2) {
47
+ return arr1.length === arr1.length && arr1.every((el, i) => el === arr2[i]);
48
+ }
49
+ /**
50
+ * 打乱并返回数组,会修改原数组。
51
+ */
52
+ export function shuffle(array) {
53
+ const len = array.length;
54
+ for (let i = len - 1; i >= 0; i--) {
55
+ const randomIndex = ~~(Math.random() * (i + 1));
56
+ const temp = array[randomIndex];
57
+ array[randomIndex] = array[i];
58
+ array[i] = temp;
59
+ }
60
+ return array;
61
+ }
62
+ /**
63
+ * 移动数组中的元素,会返回移动后的新数组。
64
+ */
65
+ export function arrayMove(array, fromIndex, toIndex) {
66
+ if (fromIndex === toIndex ||
67
+ fromIndex < 0 ||
68
+ fromIndex >= array.length ||
69
+ toIndex < 0 ||
70
+ toIndex >= array.length) {
71
+ return array;
72
+ }
73
+ const fromValue = array[fromIndex];
74
+ if (fromIndex > toIndex) {
75
+ return [
76
+ ...array.slice(0, fromIndex),
77
+ ...array.slice(fromIndex + 1, toIndex + 1),
78
+ fromValue,
79
+ ...array.slice(toIndex + 1),
80
+ ];
81
+ }
82
+ else {
83
+ return [
84
+ ...array.slice(0, toIndex),
85
+ fromValue,
86
+ ...array.slice(toIndex, fromIndex),
87
+ ...array.slice(fromIndex + 1),
88
+ ];
89
+ }
90
+ }
@@ -0,0 +1,3 @@
1
+ export interface AnyObject {
2
+ [key: string]: any;
3
+ }
@@ -0,0 +1 @@
1
+ export {};