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