@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 CHANGED
@@ -1,567 +1,417 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
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
- let isMounted = false;
75
- (0, import_vue.onMounted)(() => {
76
- hook();
77
- (0, import_vue.nextTick)(() => {
78
- isMounted = true;
79
- });
80
- });
81
- (0, import_vue.onActivated)(() => {
82
- if (!isMounted) {
83
- return;
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
- // src/useEventListener.ts
18
+ //#endregion
19
+ //#region src/useEventListener.ts
90
20
  function useEventListener(target, type, listener, options = {}) {
91
- if (!(0, import_shared.inBrowser)()) {
92
- return;
93
- }
94
- const { passive = false, capture = false } = options;
95
- let listening = false;
96
- let cleaned = false;
97
- const getElement = (target2) => (0, import_shared.isFunction)(target2) ? target2() : (0, import_vue2.unref)(target2);
98
- const add = (target2) => {
99
- if (listening || cleaned) {
100
- return;
101
- }
102
- const element = getElement(target2);
103
- if (element) {
104
- element.addEventListener(type, listener, {
105
- passive,
106
- capture
107
- });
108
- listening = true;
109
- }
110
- };
111
- const remove = (target2) => {
112
- if (!listening || cleaned) {
113
- return;
114
- }
115
- const element = getElement(target2);
116
- if (element) {
117
- element.removeEventListener(type, listener, {
118
- capture
119
- });
120
- listening = false;
121
- }
122
- };
123
- let watchStopHandle;
124
- if ((0, import_vue2.isRef)(target)) {
125
- watchStopHandle = (0, import_vue2.watch)(
126
- () => target.value,
127
- (newValue, oldValue) => {
128
- remove(oldValue);
129
- add(newValue);
130
- }
131
- );
132
- }
133
- const cleanup = () => {
134
- watchStopHandle == null ? void 0 : watchStopHandle();
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
- // src/useClickOutside.ts
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
- if (!(0, import_shared2.inBrowser)()) {
155
- return;
156
- }
157
- const handler = (event) => {
158
- const element = (0, import_shared2.isFunction)(target) ? target() : (0, import_vue3.unref)(target);
159
- if (element && !element.contains(event.target)) {
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
- // src/onSmartUnmounted.ts
167
- var import_vue4 = require("vue");
76
+ //#endregion
77
+ //#region src/onSmartUnmounted.ts
168
78
  function onSmartUnmounted(hook) {
169
- let keepalive = false;
170
- (0, import_vue4.onDeactivated)(() => {
171
- keepalive = true;
172
- hook();
173
- });
174
- (0, import_vue4.onUnmounted)(() => {
175
- if (keepalive) {
176
- return;
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
- // src/useParent.ts
183
- var import_vue5 = require("vue");
89
+ //#endregion
90
+ //#region src/useParent.ts
184
91
  function keyInProvides(key) {
185
- const instance = (0, import_vue5.getCurrentInstance)();
186
- return key in instance.provides;
92
+ return key in (0, vue.getCurrentInstance)().provides;
187
93
  }
188
94
  function useParent(key) {
189
- if (!keyInProvides(key)) {
190
- return {
191
- index: null,
192
- parentProvider: null,
193
- bindParent: null
194
- };
195
- }
196
- const provider = (0, import_vue5.inject)(key);
197
- const _a = provider, { childInstances, collect, clear } = _a, parentProvider = __objRest(_a, ["childInstances", "collect", "clear"]);
198
- const childInstance = (0, import_vue5.getCurrentInstance)();
199
- const index = (0, import_vue5.computed)(() => childInstances.indexOf(childInstance));
200
- const bindParent = (childProvider) => {
201
- (0, import_vue5.onMounted)(() => {
202
- (0, import_vue5.nextTick)().then(() => {
203
- collect(childInstance, childProvider);
204
- });
205
- });
206
- (0, import_vue5.onBeforeUnmount)(() => {
207
- (0, import_vue5.nextTick)().then(() => {
208
- clear(childInstance, childProvider);
209
- });
210
- });
211
- };
212
- return {
213
- index,
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
- // src/useChildren.ts
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
- const vNodes = [];
224
- const flat = (subTree2) => {
225
- if (subTree2 == null ? void 0 : subTree2.component) {
226
- flat(subTree2 == null ? void 0 : subTree2.component.subTree);
227
- return;
228
- }
229
- if ((0, import_shared3.isArray)(subTree2 == null ? void 0 : subTree2.children)) {
230
- subTree2.children.forEach((child) => {
231
- if ((0, import_vue6.isVNode)(child)) {
232
- vNodes.push(child);
233
- flat(child);
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
- const parentInstance = (0, import_vue6.getCurrentInstance)();
243
- const childInstances = (0, import_vue6.reactive)([]);
244
- const childProviders = [];
245
- const length = (0, import_vue6.computed)(() => childInstances.length);
246
- const sortInstances = () => {
247
- const vNodes = flatVNodes(parentInstance.subTree);
248
- childInstances.sort((a, b) => vNodes.indexOf(a.vnode) - vNodes.indexOf(b.vnode));
249
- };
250
- const collect = (childInstance, childProvider) => {
251
- childInstances.push(childInstance);
252
- childProviders.push(childProvider);
253
- sortInstances();
254
- };
255
- const clear = (childInstance, childProvider) => {
256
- (0, import_shared3.removeItem)(childInstances, childInstance);
257
- (0, import_shared3.removeItem)(childProviders, childProvider);
258
- };
259
- const bindChildren = (parentProvider) => {
260
- (0, import_vue6.provide)(key, __spreadValues({
261
- childInstances,
262
- collect,
263
- clear
264
- }, parentProvider));
265
- };
266
- return {
267
- length,
268
- childProviders,
269
- bindChildren
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
- // src/onWindowResize.ts
172
+ //#endregion
173
+ //#region src/onWindowResize.ts
274
174
  function onWindowResize(listener) {
275
- useEventListener(() => window, "resize", listener, { passive: true });
276
- useEventListener(() => window, "orientationchange", listener, { passive: true });
175
+ useEventListener(() => window, "resize", listener, { passive: true });
176
+ useEventListener(() => window, "orientationchange", listener, { passive: true });
277
177
  }
278
-
279
- // src/useInitialized.ts
280
- var import_vue7 = require("vue");
178
+ //#endregion
179
+ //#region src/useInitialized.ts
281
180
  function useInitialized(source, value) {
282
- const initialized = (0, import_vue7.ref)(false);
283
- (0, import_vue7.watch)(
284
- source,
285
- (newValue) => {
286
- if (value === newValue) {
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
- // src/useTouch.ts
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
- if (x > y) {
300
- return "horizontal";
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
- const startX = (0, import_vue8.ref)(0);
308
- const startY = (0, import_vue8.ref)(0);
309
- const deltaX = (0, import_vue8.ref)(0);
310
- const deltaY = (0, import_vue8.ref)(0);
311
- const offsetX = (0, import_vue8.ref)(0);
312
- const offsetY = (0, import_vue8.ref)(0);
313
- const prevX = (0, import_vue8.ref)(0);
314
- const prevY = (0, import_vue8.ref)(0);
315
- const moveX = (0, import_vue8.ref)(0);
316
- const moveY = (0, import_vue8.ref)(0);
317
- const direction = (0, import_vue8.ref)();
318
- const touching = (0, import_vue8.ref)(false);
319
- const dragging = (0, import_vue8.ref)(false);
320
- const startTime = (0, import_vue8.ref)(0);
321
- const distance = (0, import_vue8.ref)(0);
322
- let draggingAnimationFrame = null;
323
- const resetTouch = () => {
324
- startX.value = 0;
325
- startY.value = 0;
326
- deltaX.value = 0;
327
- deltaY.value = 0;
328
- offsetX.value = 0;
329
- offsetY.value = 0;
330
- prevX.value = 0;
331
- prevY.value = 0;
332
- moveX.value = 0;
333
- moveY.value = 0;
334
- direction.value = void 0;
335
- touching.value = false;
336
- dragging.value = false;
337
- startTime.value = 0;
338
- distance.value = 0;
339
- };
340
- const startTouch = (event) => {
341
- resetTouch();
342
- const { clientX: x, clientY: y } = event.touches[0];
343
- startX.value = x;
344
- startY.value = y;
345
- prevX.value = x;
346
- prevY.value = y;
347
- touching.value = true;
348
- startTime.value = performance.now();
349
- dragging.value = false;
350
- if (draggingAnimationFrame) {
351
- window.cancelAnimationFrame(draggingAnimationFrame);
352
- }
353
- };
354
- const moveTouch = (event) => {
355
- const { clientX: x, clientY: y } = event.touches[0];
356
- dragging.value = true;
357
- deltaX.value = x - startX.value;
358
- deltaY.value = y - startY.value;
359
- offsetX.value = Math.abs(deltaX.value);
360
- offsetY.value = Math.abs(deltaY.value);
361
- distance.value = Math.sqrt(offsetX.value ** 2 + offsetY.value ** 2);
362
- moveX.value = x - prevX.value;
363
- moveY.value = y - prevY.value;
364
- if (!direction.value) {
365
- direction.value = getDirection(offsetX.value, offsetY.value);
366
- }
367
- prevX.value = x;
368
- prevY.value = y;
369
- };
370
- const endTouch = () => {
371
- touching.value = false;
372
- draggingAnimationFrame = window.requestAnimationFrame(() => {
373
- dragging.value = false;
374
- });
375
- };
376
- const isReachTop = (element) => {
377
- const scrollTop = (0, import_shared4.getScrollTop)(element);
378
- return scrollTop === 0 && deltaY.value > 0;
379
- };
380
- const isReachBottom = (element, offset = 1) => {
381
- const { scrollHeight, clientHeight, scrollTop } = element;
382
- const offsetBottom = Math.abs(scrollHeight - scrollTop - clientHeight);
383
- return deltaY.value < 0 && offsetBottom <= offset;
384
- };
385
- return {
386
- startX,
387
- startY,
388
- deltaX,
389
- deltaY,
390
- offsetX,
391
- offsetY,
392
- prevX,
393
- prevY,
394
- moveX,
395
- moveY,
396
- direction,
397
- touching,
398
- dragging,
399
- startTime,
400
- distance,
401
- resetTouch,
402
- startTouch,
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
- // src/useId.ts
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
- const id = (0, import_vue9.ref)();
415
- const instance = (0, import_vue9.getCurrentInstance)();
416
- const name = (0, import_shared5.kebabCase)(instance.type.name);
417
- id.value = process.env.NODE_ENV === "test" ? `${name}-mock-id` : `${name}-${instance.uid}`;
418
- return id;
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
- // src/useClientId.ts
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
- const instance = (0, import_vue10.getCurrentInstance)();
426
- const name = (0, import_shared6.kebabCase)(instance.type.name);
427
- const id = (0, import_vue10.ref)(process.env.NODE_ENV === "test" ? `${name}-mock-id` : void 0);
428
- (0, import_vue10.onMounted)(() => {
429
- if (process.env.NODE_ENV !== "test") {
430
- id.value = `${name}-${instance.uid}`;
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
- // src/useWindowSize.ts
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
- const { initialWidth = 0, initialHeight = 0 } = options;
441
- const width = (0, import_vue11.ref)(initialWidth);
442
- const height = (0, import_vue11.ref)(initialHeight);
443
- const update = () => {
444
- if (!(0, import_shared7.inBrowser)()) {
445
- return;
446
- }
447
- width.value = window.innerWidth;
448
- height.value = window.innerHeight;
449
- };
450
- onSmartMounted(update);
451
- onWindowResize(update);
452
- return {
453
- width,
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
- // src/useVModel.ts
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
- const { passive = true, eventName, defaultValue, emit } = options;
463
- const event = eventName != null ? eventName : `onUpdate:${key.toString()}`;
464
- const getValue = () => {
465
- var _a;
466
- return (_a = props[key]) != null ? _a : defaultValue;
467
- };
468
- if (!passive) {
469
- return (0, import_vue12.computed)({
470
- get() {
471
- return getValue();
472
- },
473
- set(value) {
474
- emit ? emit(event, value) : (0, import_shared8.call)(props[event], value);
475
- }
476
- });
477
- }
478
- const proxy = (0, import_vue12.ref)(getValue());
479
- let shouldEmit = true;
480
- (0, import_vue12.watch)(
481
- () => props[key],
482
- () => {
483
- shouldEmit = false;
484
- proxy.value = getValue();
485
- (0, import_vue12.nextTick)(() => {
486
- shouldEmit = true;
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
- // src/useMotion.ts
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
- const value = (0, import_vue13.ref)(getter(options.from));
507
- const state = (0, import_vue13.ref)("pending");
508
- let ctx = createMotionContext();
509
- function getter(value2) {
510
- return (0, import_shared9.isFunction)(value2) ? value2() : value2;
511
- }
512
- function reset() {
513
- ctx.reset();
514
- value.value = getter(options.from);
515
- state.value = "pending";
516
- ctx = createMotionContext();
517
- }
518
- function start() {
519
- ctx.start();
520
- }
521
- function pause() {
522
- ctx.pause();
523
- }
524
- function createMotionContext() {
525
- return (0, import_shared9.motion)({
526
- from: getter(options.from),
527
- to: getter(options.to),
528
- duration: options.duration ? getter(options.duration) : 300,
529
- timingFunction: options.timingFunction,
530
- onStateChange(newState) {
531
- state.value = newState;
532
- },
533
- frame({ value: newValue, done }) {
534
- var _a;
535
- value.value = newValue;
536
- if (done) {
537
- (_a = options.onFinished) == null ? void 0 : _a.call(options, value.value);
538
- }
539
- }
540
- });
541
- }
542
- return {
543
- value,
544
- state,
545
- start,
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
- // Annotate the CommonJS export names for ESM import in node:
551
- 0 && (module.exports = {
552
- keyInProvides,
553
- onSmartMounted,
554
- onSmartUnmounted,
555
- onWindowResize,
556
- useChildren,
557
- useClickOutside,
558
- useClientId,
559
- useEventListener,
560
- useId,
561
- useInitialized,
562
- useMotion,
563
- useParent,
564
- useTouch,
565
- useVModel,
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;