@varlet/use 3.14.2 → 3.15.0-alpha.1776606769606
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/lib/index.cjs +383 -533
- package/lib/index.d.cts +88 -74
- package/lib/index.d.ts +88 -74
- package/lib/index.js +368 -508
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -1,542 +1,402 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __objRest = (source, exclude) => {
|
|
18
|
-
var target = {};
|
|
19
|
-
for (var prop in source)
|
|
20
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
-
target[prop] = source[prop];
|
|
22
|
-
if (source != null && __getOwnPropSymbols)
|
|
23
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// src/useEventListener.ts
|
|
31
|
-
import { isRef, onBeforeUnmount, onDeactivated, unref, watch } from "vue";
|
|
32
|
-
import { inBrowser, isFunction } from "@varlet/shared";
|
|
33
|
-
|
|
34
|
-
// src/onSmartMounted.ts
|
|
35
|
-
import { nextTick, onActivated, onMounted } from "vue";
|
|
1
|
+
import { call, getScrollTop, inBrowser, isArray, isFunction, kebabCase, motion, removeItem } from "@varlet/shared";
|
|
2
|
+
import { computed, getCurrentInstance, inject, isRef, isVNode, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted, onUnmounted, provide, reactive, ref, unref, watch } from "vue";
|
|
3
|
+
//#region src/onSmartMounted.ts
|
|
36
4
|
function onSmartMounted(hook) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
hook();
|
|
49
|
-
});
|
|
5
|
+
let isMounted = false;
|
|
6
|
+
onMounted(() => {
|
|
7
|
+
hook();
|
|
8
|
+
nextTick(() => {
|
|
9
|
+
isMounted = true;
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
onActivated(() => {
|
|
13
|
+
if (!isMounted) return;
|
|
14
|
+
hook();
|
|
15
|
+
});
|
|
50
16
|
}
|
|
51
|
-
|
|
52
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/useEventListener.ts
|
|
53
19
|
function useEventListener(target, type, listener, options = {}) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
remove(target);
|
|
99
|
-
cleaned = true;
|
|
100
|
-
};
|
|
101
|
-
onSmartMounted(() => {
|
|
102
|
-
add(target);
|
|
103
|
-
});
|
|
104
|
-
onBeforeUnmount(() => {
|
|
105
|
-
remove(target);
|
|
106
|
-
});
|
|
107
|
-
onDeactivated(() => {
|
|
108
|
-
remove(target);
|
|
109
|
-
});
|
|
110
|
-
return cleanup;
|
|
20
|
+
if (!inBrowser()) return;
|
|
21
|
+
const { passive = false, capture = false } = options;
|
|
22
|
+
let listening = false;
|
|
23
|
+
let cleaned = false;
|
|
24
|
+
const getElement = (target) => isFunction(target) ? target() : unref(target);
|
|
25
|
+
const add = (target) => {
|
|
26
|
+
if (listening || cleaned) return;
|
|
27
|
+
const element = getElement(target);
|
|
28
|
+
if (element) {
|
|
29
|
+
element.addEventListener(type, listener, {
|
|
30
|
+
passive,
|
|
31
|
+
capture
|
|
32
|
+
});
|
|
33
|
+
listening = true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const remove = (target) => {
|
|
37
|
+
if (!listening || cleaned) return;
|
|
38
|
+
const element = getElement(target);
|
|
39
|
+
if (element) {
|
|
40
|
+
element.removeEventListener(type, listener, { capture });
|
|
41
|
+
listening = false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
let watchStopHandle;
|
|
45
|
+
if (isRef(target)) watchStopHandle = watch(() => target.value, (newValue, oldValue) => {
|
|
46
|
+
remove(oldValue);
|
|
47
|
+
add(newValue);
|
|
48
|
+
});
|
|
49
|
+
const cleanup = () => {
|
|
50
|
+
watchStopHandle?.();
|
|
51
|
+
remove(target);
|
|
52
|
+
cleaned = true;
|
|
53
|
+
};
|
|
54
|
+
onSmartMounted(() => {
|
|
55
|
+
add(target);
|
|
56
|
+
});
|
|
57
|
+
onBeforeUnmount(() => {
|
|
58
|
+
remove(target);
|
|
59
|
+
});
|
|
60
|
+
onDeactivated(() => {
|
|
61
|
+
remove(target);
|
|
62
|
+
});
|
|
63
|
+
return cleanup;
|
|
111
64
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
import { unref as unref2 } from "vue";
|
|
115
|
-
import { inBrowser as inBrowser2, isFunction as isFunction2 } from "@varlet/shared";
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/useClickOutside.ts
|
|
116
67
|
function useClickOutside(target, type, listener) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
listener(event);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
useEventListener(document, type, handler);
|
|
68
|
+
if (!inBrowser()) return;
|
|
69
|
+
const handler = (event) => {
|
|
70
|
+
const element = isFunction(target) ? target() : unref(target);
|
|
71
|
+
if (element && !element.contains(event.target)) listener(event);
|
|
72
|
+
};
|
|
73
|
+
useEventListener(document, type, handler);
|
|
127
74
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
import { onDeactivated as onDeactivated2, onUnmounted } from "vue";
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/onSmartUnmounted.ts
|
|
131
77
|
function onSmartUnmounted(hook) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
hook();
|
|
142
|
-
});
|
|
78
|
+
let keepalive = false;
|
|
79
|
+
onDeactivated(() => {
|
|
80
|
+
keepalive = true;
|
|
81
|
+
hook();
|
|
82
|
+
});
|
|
83
|
+
onUnmounted(() => {
|
|
84
|
+
if (keepalive) return;
|
|
85
|
+
hook();
|
|
86
|
+
});
|
|
143
87
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
import {
|
|
147
|
-
computed,
|
|
148
|
-
getCurrentInstance,
|
|
149
|
-
inject,
|
|
150
|
-
nextTick as nextTick2,
|
|
151
|
-
onBeforeUnmount as onBeforeUnmount2,
|
|
152
|
-
onMounted as onMounted2
|
|
153
|
-
} from "vue";
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/useParent.ts
|
|
154
90
|
function keyInProvides(key) {
|
|
155
|
-
|
|
156
|
-
return key in instance.provides;
|
|
91
|
+
return key in getCurrentInstance().provides;
|
|
157
92
|
}
|
|
158
93
|
function useParent(key) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
parentProvider,
|
|
185
|
-
bindParent
|
|
186
|
-
};
|
|
94
|
+
if (!keyInProvides(key)) return {
|
|
95
|
+
index: null,
|
|
96
|
+
parentProvider: null,
|
|
97
|
+
bindParent: null
|
|
98
|
+
};
|
|
99
|
+
const { childInstances, collect, clear, ...parentProvider } = inject(key);
|
|
100
|
+
const childInstance = getCurrentInstance();
|
|
101
|
+
const index = computed(() => childInstances.indexOf(childInstance));
|
|
102
|
+
const bindParent = (childProvider) => {
|
|
103
|
+
onMounted(() => {
|
|
104
|
+
nextTick().then(() => {
|
|
105
|
+
collect(childInstance, childProvider);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
onBeforeUnmount(() => {
|
|
109
|
+
nextTick().then(() => {
|
|
110
|
+
clear(childInstance, childProvider);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
index,
|
|
116
|
+
parentProvider,
|
|
117
|
+
bindParent
|
|
118
|
+
};
|
|
187
119
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
import {
|
|
191
|
-
computed as computed2,
|
|
192
|
-
getCurrentInstance as getCurrentInstance2,
|
|
193
|
-
isVNode,
|
|
194
|
-
provide,
|
|
195
|
-
reactive
|
|
196
|
-
} from "vue";
|
|
197
|
-
import { isArray, removeItem } from "@varlet/shared";
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/useChildren.ts
|
|
198
122
|
function flatVNodes(subTree) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
flat(subTree);
|
|
215
|
-
return vNodes;
|
|
123
|
+
const vNodes = [];
|
|
124
|
+
const flat = (subTree) => {
|
|
125
|
+
if (subTree?.component) {
|
|
126
|
+
flat(subTree?.component.subTree);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (isArray(subTree?.children)) subTree.children.forEach((child) => {
|
|
130
|
+
if (isVNode(child)) {
|
|
131
|
+
vNodes.push(child);
|
|
132
|
+
flat(child);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
flat(subTree);
|
|
137
|
+
return vNodes;
|
|
216
138
|
}
|
|
217
139
|
function useChildren(key) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
140
|
+
const parentInstance = getCurrentInstance();
|
|
141
|
+
const childInstances = reactive([]);
|
|
142
|
+
const childProviders = [];
|
|
143
|
+
const length = computed(() => childInstances.length);
|
|
144
|
+
const sortInstances = () => {
|
|
145
|
+
const vNodes = flatVNodes(parentInstance.subTree);
|
|
146
|
+
childInstances.sort((a, b) => vNodes.indexOf(a.vnode) - vNodes.indexOf(b.vnode));
|
|
147
|
+
};
|
|
148
|
+
const collect = (childInstance, childProvider) => {
|
|
149
|
+
childInstances.push(childInstance);
|
|
150
|
+
childProviders.push(childProvider);
|
|
151
|
+
sortInstances();
|
|
152
|
+
};
|
|
153
|
+
const clear = (childInstance, childProvider) => {
|
|
154
|
+
removeItem(childInstances, childInstance);
|
|
155
|
+
removeItem(childProviders, childProvider);
|
|
156
|
+
};
|
|
157
|
+
const bindChildren = (parentProvider) => {
|
|
158
|
+
provide(key, {
|
|
159
|
+
childInstances,
|
|
160
|
+
collect,
|
|
161
|
+
clear,
|
|
162
|
+
...parentProvider
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
length,
|
|
167
|
+
childProviders,
|
|
168
|
+
bindChildren
|
|
169
|
+
};
|
|
247
170
|
}
|
|
248
|
-
|
|
249
|
-
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/onWindowResize.ts
|
|
250
173
|
function onWindowResize(listener) {
|
|
251
|
-
|
|
252
|
-
|
|
174
|
+
useEventListener(() => window, "resize", listener, { passive: true });
|
|
175
|
+
useEventListener(() => window, "orientationchange", listener, { passive: true });
|
|
253
176
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
import { ref, watch as watch2 } from "vue";
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/useInitialized.ts
|
|
257
179
|
function useInitialized(source, value) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
initialized.value = true;
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
{ immediate: true }
|
|
267
|
-
);
|
|
268
|
-
return initialized;
|
|
180
|
+
const initialized = ref(false);
|
|
181
|
+
watch(source, (newValue) => {
|
|
182
|
+
if (value === newValue) initialized.value = true;
|
|
183
|
+
}, { immediate: true });
|
|
184
|
+
return initialized;
|
|
269
185
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
import { ref as ref2 } from "vue";
|
|
273
|
-
import { getScrollTop } from "@varlet/shared";
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/useTouch.ts
|
|
274
188
|
function getDirection(x, y) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
if (y > x) {
|
|
279
|
-
return "vertical";
|
|
280
|
-
}
|
|
189
|
+
if (x > y) return "horizontal";
|
|
190
|
+
if (y > x) return "vertical";
|
|
281
191
|
}
|
|
282
192
|
function useTouch() {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
moveTouch,
|
|
380
|
-
endTouch,
|
|
381
|
-
isReachTop,
|
|
382
|
-
isReachBottom
|
|
383
|
-
};
|
|
193
|
+
const startX = ref(0);
|
|
194
|
+
const startY = ref(0);
|
|
195
|
+
const deltaX = ref(0);
|
|
196
|
+
const deltaY = ref(0);
|
|
197
|
+
const offsetX = ref(0);
|
|
198
|
+
const offsetY = ref(0);
|
|
199
|
+
const prevX = ref(0);
|
|
200
|
+
const prevY = ref(0);
|
|
201
|
+
const moveX = ref(0);
|
|
202
|
+
const moveY = ref(0);
|
|
203
|
+
const direction = ref();
|
|
204
|
+
const touching = ref(false);
|
|
205
|
+
const dragging = ref(false);
|
|
206
|
+
const startTime = ref(0);
|
|
207
|
+
const distance = ref(0);
|
|
208
|
+
let draggingAnimationFrame = null;
|
|
209
|
+
const resetTouch = () => {
|
|
210
|
+
startX.value = 0;
|
|
211
|
+
startY.value = 0;
|
|
212
|
+
deltaX.value = 0;
|
|
213
|
+
deltaY.value = 0;
|
|
214
|
+
offsetX.value = 0;
|
|
215
|
+
offsetY.value = 0;
|
|
216
|
+
prevX.value = 0;
|
|
217
|
+
prevY.value = 0;
|
|
218
|
+
moveX.value = 0;
|
|
219
|
+
moveY.value = 0;
|
|
220
|
+
direction.value = void 0;
|
|
221
|
+
touching.value = false;
|
|
222
|
+
dragging.value = false;
|
|
223
|
+
startTime.value = 0;
|
|
224
|
+
distance.value = 0;
|
|
225
|
+
};
|
|
226
|
+
const startTouch = (event) => {
|
|
227
|
+
resetTouch();
|
|
228
|
+
const { clientX: x, clientY: y } = event.touches[0];
|
|
229
|
+
startX.value = x;
|
|
230
|
+
startY.value = y;
|
|
231
|
+
prevX.value = x;
|
|
232
|
+
prevY.value = y;
|
|
233
|
+
touching.value = true;
|
|
234
|
+
startTime.value = performance.now();
|
|
235
|
+
dragging.value = false;
|
|
236
|
+
if (draggingAnimationFrame) window.cancelAnimationFrame(draggingAnimationFrame);
|
|
237
|
+
};
|
|
238
|
+
const moveTouch = (event) => {
|
|
239
|
+
const { clientX: x, clientY: y } = event.touches[0];
|
|
240
|
+
dragging.value = true;
|
|
241
|
+
deltaX.value = x - startX.value;
|
|
242
|
+
deltaY.value = y - startY.value;
|
|
243
|
+
offsetX.value = Math.abs(deltaX.value);
|
|
244
|
+
offsetY.value = Math.abs(deltaY.value);
|
|
245
|
+
distance.value = Math.sqrt(offsetX.value ** 2 + offsetY.value ** 2);
|
|
246
|
+
moveX.value = x - prevX.value;
|
|
247
|
+
moveY.value = y - prevY.value;
|
|
248
|
+
if (!direction.value) direction.value = getDirection(offsetX.value, offsetY.value);
|
|
249
|
+
prevX.value = x;
|
|
250
|
+
prevY.value = y;
|
|
251
|
+
};
|
|
252
|
+
const endTouch = () => {
|
|
253
|
+
touching.value = false;
|
|
254
|
+
draggingAnimationFrame = window.requestAnimationFrame(() => {
|
|
255
|
+
dragging.value = false;
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const isReachTop = (element) => {
|
|
259
|
+
return getScrollTop(element) === 0 && deltaY.value > 0;
|
|
260
|
+
};
|
|
261
|
+
const isReachBottom = (element, offset = 1) => {
|
|
262
|
+
const { scrollHeight, clientHeight, scrollTop } = element;
|
|
263
|
+
const offsetBottom = Math.abs(scrollHeight - scrollTop - clientHeight);
|
|
264
|
+
return deltaY.value < 0 && offsetBottom <= offset;
|
|
265
|
+
};
|
|
266
|
+
return {
|
|
267
|
+
startX,
|
|
268
|
+
startY,
|
|
269
|
+
deltaX,
|
|
270
|
+
deltaY,
|
|
271
|
+
offsetX,
|
|
272
|
+
offsetY,
|
|
273
|
+
prevX,
|
|
274
|
+
prevY,
|
|
275
|
+
moveX,
|
|
276
|
+
moveY,
|
|
277
|
+
direction,
|
|
278
|
+
touching,
|
|
279
|
+
dragging,
|
|
280
|
+
startTime,
|
|
281
|
+
distance,
|
|
282
|
+
resetTouch,
|
|
283
|
+
startTouch,
|
|
284
|
+
moveTouch,
|
|
285
|
+
endTouch,
|
|
286
|
+
isReachTop,
|
|
287
|
+
isReachBottom
|
|
288
|
+
};
|
|
384
289
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
import { getCurrentInstance as getCurrentInstance3, ref as ref3 } from "vue";
|
|
388
|
-
import { kebabCase } from "@varlet/shared";
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/useId.ts
|
|
389
292
|
function useId() {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
293
|
+
const id = ref();
|
|
294
|
+
const instance = getCurrentInstance();
|
|
295
|
+
const name = kebabCase(instance.type.name);
|
|
296
|
+
id.value = process.env.NODE_ENV === "test" ? `${name}-mock-id` : `${name}-${instance.uid}`;
|
|
297
|
+
return id;
|
|
395
298
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
import { getCurrentInstance as getCurrentInstance4, onMounted as onMounted3, ref as ref4 } from "vue";
|
|
399
|
-
import { kebabCase as kebabCase2 } from "@varlet/shared";
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/useClientId.ts
|
|
400
301
|
function useClientId() {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
});
|
|
409
|
-
return id;
|
|
302
|
+
const instance = getCurrentInstance();
|
|
303
|
+
const name = kebabCase(instance.type.name);
|
|
304
|
+
const id = ref(process.env.NODE_ENV === "test" ? `${name}-mock-id` : void 0);
|
|
305
|
+
onMounted(() => {
|
|
306
|
+
if (process.env.NODE_ENV !== "test") id.value = `${name}-${instance.uid}`;
|
|
307
|
+
});
|
|
308
|
+
return id;
|
|
410
309
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
import { ref as ref5 } from "vue";
|
|
414
|
-
import { inBrowser as inBrowser3 } from "@varlet/shared";
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/useWindowSize.ts
|
|
415
312
|
function useWindowSize(options = {}) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
height
|
|
431
|
-
};
|
|
313
|
+
const { initialWidth = 0, initialHeight = 0 } = options;
|
|
314
|
+
const width = ref(initialWidth);
|
|
315
|
+
const height = ref(initialHeight);
|
|
316
|
+
const update = () => {
|
|
317
|
+
if (!inBrowser()) return;
|
|
318
|
+
width.value = window.innerWidth;
|
|
319
|
+
height.value = window.innerHeight;
|
|
320
|
+
};
|
|
321
|
+
onSmartMounted(update);
|
|
322
|
+
onWindowResize(update);
|
|
323
|
+
return {
|
|
324
|
+
width,
|
|
325
|
+
height
|
|
326
|
+
};
|
|
432
327
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
import { computed as computed3, nextTick as nextTick3, ref as ref6, watch as watch3 } from "vue";
|
|
436
|
-
import { call } from "@varlet/shared";
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/useVModel.ts
|
|
437
330
|
function useVModel(props, key, options = {}) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
);
|
|
466
|
-
watch3(
|
|
467
|
-
() => proxy.value,
|
|
468
|
-
(newValue) => {
|
|
469
|
-
if (!shouldEmit) {
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
emit ? emit(event, newValue) : call(props[event], newValue);
|
|
473
|
-
}
|
|
474
|
-
);
|
|
475
|
-
return proxy;
|
|
331
|
+
const { passive = true, eventName, defaultValue, emit } = options;
|
|
332
|
+
const event = eventName ?? `onUpdate:${key.toString()}`;
|
|
333
|
+
const getValue = () => props[key] ?? defaultValue;
|
|
334
|
+
if (!passive) return computed({
|
|
335
|
+
get() {
|
|
336
|
+
return getValue();
|
|
337
|
+
},
|
|
338
|
+
set(value) {
|
|
339
|
+
emit ? emit(event, value) : call(props[event], value);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
const proxy = ref(getValue());
|
|
343
|
+
let shouldEmit = true;
|
|
344
|
+
watch(() => props[key], () => {
|
|
345
|
+
shouldEmit = false;
|
|
346
|
+
proxy.value = getValue();
|
|
347
|
+
nextTick(() => {
|
|
348
|
+
shouldEmit = true;
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
watch(() => proxy.value, (newValue) => {
|
|
352
|
+
if (!shouldEmit) return;
|
|
353
|
+
emit ? emit(event, newValue) : call(props[event], newValue);
|
|
354
|
+
});
|
|
355
|
+
return proxy;
|
|
476
356
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
import { ref as ref7 } from "vue";
|
|
480
|
-
import { isFunction as isFunction3, motion } from "@varlet/shared";
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/useMotion.ts
|
|
481
359
|
function useMotion(options) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
pause,
|
|
523
|
-
reset
|
|
524
|
-
};
|
|
360
|
+
const value = ref(getter(options.from));
|
|
361
|
+
const state = ref("pending");
|
|
362
|
+
let ctx = createMotionContext();
|
|
363
|
+
function getter(value) {
|
|
364
|
+
return isFunction(value) ? value() : value;
|
|
365
|
+
}
|
|
366
|
+
function reset() {
|
|
367
|
+
ctx.reset();
|
|
368
|
+
value.value = getter(options.from);
|
|
369
|
+
state.value = "pending";
|
|
370
|
+
ctx = createMotionContext();
|
|
371
|
+
}
|
|
372
|
+
function start() {
|
|
373
|
+
ctx.start();
|
|
374
|
+
}
|
|
375
|
+
function pause() {
|
|
376
|
+
ctx.pause();
|
|
377
|
+
}
|
|
378
|
+
function createMotionContext() {
|
|
379
|
+
return motion({
|
|
380
|
+
from: getter(options.from),
|
|
381
|
+
to: getter(options.to),
|
|
382
|
+
duration: options.duration ? getter(options.duration) : 300,
|
|
383
|
+
timingFunction: options.timingFunction,
|
|
384
|
+
onStateChange(newState) {
|
|
385
|
+
state.value = newState;
|
|
386
|
+
},
|
|
387
|
+
frame({ value: newValue, done }) {
|
|
388
|
+
value.value = newValue;
|
|
389
|
+
if (done) options.onFinished?.(value.value);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
value,
|
|
395
|
+
state,
|
|
396
|
+
start,
|
|
397
|
+
pause,
|
|
398
|
+
reset
|
|
399
|
+
};
|
|
525
400
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
onSmartMounted,
|
|
529
|
-
onSmartUnmounted,
|
|
530
|
-
onWindowResize,
|
|
531
|
-
useChildren,
|
|
532
|
-
useClickOutside,
|
|
533
|
-
useClientId,
|
|
534
|
-
useEventListener,
|
|
535
|
-
useId,
|
|
536
|
-
useInitialized,
|
|
537
|
-
useMotion,
|
|
538
|
-
useParent,
|
|
539
|
-
useTouch,
|
|
540
|
-
useVModel,
|
|
541
|
-
useWindowSize
|
|
542
|
-
};
|
|
401
|
+
//#endregion
|
|
402
|
+
export { keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useClientId, useEventListener, useId, useInitialized, useMotion, useParent, useTouch, useVModel, useWindowSize };
|