@maple-design/use 0.0.0-stage → 1.1.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.
package/lib/index.cjs ADDED
@@ -0,0 +1,871 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
78
+
79
+ // src/index.ts
80
+ var src_exports = {};
81
+ __export(src_exports, {
82
+ keyInProvides: () => keyInProvides,
83
+ onSmartMounted: () => onSmartMounted,
84
+ onSmartUnmounted: () => onSmartUnmounted,
85
+ onWindowResize: () => onWindowResize,
86
+ provideDirection: () => provideDirection,
87
+ readingDirectionKey: () => readingDirectionKey,
88
+ resolveDirection: () => resolveDirection,
89
+ useAsyncData: () => useAsyncData,
90
+ useChildren: () => useChildren,
91
+ useClickOutside: () => useClickOutside,
92
+ useClientId: () => useClientId,
93
+ useDirection: () => useDirection,
94
+ useEventListener: () => useEventListener,
95
+ useId: () => useId2,
96
+ useInitialized: () => useInitialized,
97
+ useMotion: () => useMotion,
98
+ useParent: () => useParent,
99
+ useTouch: () => useTouch,
100
+ useVModel: () => useVModel,
101
+ useWindowSize: () => useWindowSize
102
+ });
103
+ module.exports = __toCommonJS(src_exports);
104
+
105
+ // src/useEventListener.ts
106
+ var import_vue2 = require("vue");
107
+ var import_shared = require("@maple-design/shared");
108
+
109
+ // src/onSmartMounted.ts
110
+ var import_vue = require("vue");
111
+ function onSmartMounted(hook) {
112
+ let isMounted = false;
113
+ (0, import_vue.onMounted)(() => {
114
+ hook();
115
+ (0, import_vue.nextTick)(() => {
116
+ isMounted = true;
117
+ });
118
+ });
119
+ (0, import_vue.onActivated)(() => {
120
+ if (!isMounted) {
121
+ return;
122
+ }
123
+ hook();
124
+ });
125
+ }
126
+
127
+ // src/useEventListener.ts
128
+ function useEventListener(target, type, listener, options = {}) {
129
+ if (!(0, import_shared.inBrowser)()) {
130
+ return () => {
131
+ };
132
+ }
133
+ const { passive = false, capture = false } = options;
134
+ let boundTarget;
135
+ let active = false;
136
+ let cleaned = false;
137
+ let stop;
138
+ const resolveTarget = () => {
139
+ var _a;
140
+ return (_a = (0, import_shared.isFunction)(target) ? target() : (0, import_vue2.unref)(target)) != null ? _a : void 0;
141
+ };
142
+ const detach = () => {
143
+ boundTarget == null ? void 0 : boundTarget.removeEventListener(type, listener, { capture });
144
+ boundTarget = void 0;
145
+ };
146
+ const bind = () => {
147
+ if (!active || cleaned) {
148
+ return;
149
+ }
150
+ const next = resolveTarget();
151
+ if (next === boundTarget) {
152
+ return;
153
+ }
154
+ detach();
155
+ next == null ? void 0 : next.addEventListener(type, listener, { passive, capture });
156
+ boundTarget = next;
157
+ };
158
+ const cleanup = () => {
159
+ if (cleaned) {
160
+ return;
161
+ }
162
+ cleaned = true;
163
+ active = false;
164
+ stop == null ? void 0 : stop();
165
+ detach();
166
+ };
167
+ if ((0, import_vue2.isRef)(target) || (0, import_shared.isFunction)(target)) {
168
+ stop = (0, import_vue2.watch)(resolveTarget, bind);
169
+ }
170
+ onSmartMounted(() => {
171
+ active = true;
172
+ bind();
173
+ });
174
+ (0, import_vue2.onDeactivated)(() => {
175
+ active = false;
176
+ detach();
177
+ });
178
+ (0, import_vue2.onBeforeUnmount)(cleanup);
179
+ return cleanup;
180
+ }
181
+
182
+ // src/useClickOutside.ts
183
+ var import_vue3 = require("vue");
184
+ var import_shared2 = require("@maple-design/shared");
185
+ function useClickOutside(target, type, listener) {
186
+ if (!(0, import_shared2.inBrowser)()) {
187
+ return;
188
+ }
189
+ const handler = (event) => {
190
+ const element = (0, import_shared2.isFunction)(target) ? target() : (0, import_vue3.unref)(target);
191
+ if (element && !event.composedPath().includes(element) && !element.contains(event.target)) {
192
+ listener(event);
193
+ }
194
+ };
195
+ useEventListener(document, type, handler);
196
+ }
197
+
198
+ // src/onSmartUnmounted.ts
199
+ var import_vue4 = require("vue");
200
+ function onSmartUnmounted(hook) {
201
+ let keepalive = false;
202
+ (0, import_vue4.onDeactivated)(() => {
203
+ keepalive = true;
204
+ hook();
205
+ });
206
+ (0, import_vue4.onUnmounted)(() => {
207
+ if (keepalive) {
208
+ return;
209
+ }
210
+ hook();
211
+ });
212
+ }
213
+
214
+ // src/useParent.ts
215
+ var import_vue5 = require("vue");
216
+ function keyInProvides(key) {
217
+ const instance = (0, import_vue5.getCurrentInstance)();
218
+ return key in instance.provides;
219
+ }
220
+ function useParent(key) {
221
+ if (!keyInProvides(key)) {
222
+ return {
223
+ index: null,
224
+ parentProvider: null,
225
+ bindParent: null
226
+ };
227
+ }
228
+ const provider = (0, import_vue5.inject)(key);
229
+ const _a = provider, { childInstances, collect, clear } = _a, parentProvider = __objRest(_a, ["childInstances", "collect", "clear"]);
230
+ const childInstance = (0, import_vue5.getCurrentInstance)();
231
+ const index = (0, import_vue5.computed)(() => childInstances.indexOf(childInstance));
232
+ const bindParent = (childProvider) => {
233
+ let active = false;
234
+ let registered = false;
235
+ const add = () => {
236
+ active = true;
237
+ (0, import_vue5.nextTick)(() => {
238
+ if (active && !registered) {
239
+ collect(childInstance, childProvider);
240
+ registered = true;
241
+ }
242
+ });
243
+ };
244
+ const remove = () => {
245
+ active = false;
246
+ if (registered) {
247
+ clear(childInstance, childProvider);
248
+ registered = false;
249
+ }
250
+ };
251
+ (0, import_vue5.onMounted)(add);
252
+ (0, import_vue5.onActivated)(add);
253
+ (0, import_vue5.onDeactivated)(remove);
254
+ (0, import_vue5.onBeforeUnmount)(remove);
255
+ };
256
+ return {
257
+ index,
258
+ parentProvider,
259
+ bindParent
260
+ };
261
+ }
262
+
263
+ // src/useChildren.ts
264
+ var import_vue6 = require("vue");
265
+ var import_shared3 = require("@maple-design/shared");
266
+ function flatVNodes(subTree) {
267
+ const vNodes = [];
268
+ const flat = (subTree2) => {
269
+ if (subTree2 == null ? void 0 : subTree2.component) {
270
+ flat(subTree2 == null ? void 0 : subTree2.component.subTree);
271
+ return;
272
+ }
273
+ if ((0, import_shared3.isArray)(subTree2 == null ? void 0 : subTree2.children)) {
274
+ subTree2.children.forEach((child) => {
275
+ if ((0, import_vue6.isVNode)(child)) {
276
+ vNodes.push(child);
277
+ flat(child);
278
+ }
279
+ });
280
+ }
281
+ };
282
+ flat(subTree);
283
+ return vNodes;
284
+ }
285
+ function useChildren(key) {
286
+ const parentInstance = (0, import_vue6.getCurrentInstance)();
287
+ const childInstances = (0, import_vue6.reactive)([]);
288
+ const childProviders = [];
289
+ const length = (0, import_vue6.computed)(() => childInstances.length);
290
+ const sortInstances = () => {
291
+ const vNodes = flatVNodes(parentInstance.subTree);
292
+ const sorted = [...childInstances].sort((a, b) => vNodes.indexOf(a.vnode) - vNodes.indexOf(b.vnode));
293
+ if (sorted.every((instance, index) => instance === childInstances[index])) {
294
+ return;
295
+ }
296
+ const providers = sorted.map((instance) => childProviders[childInstances.indexOf(instance)]);
297
+ childInstances.splice(0, childInstances.length, ...sorted);
298
+ childProviders.splice(0, childProviders.length, ...providers);
299
+ };
300
+ (0, import_vue6.onUpdated)(sortInstances);
301
+ const collect = (childInstance, childProvider) => {
302
+ if (childInstances.includes(childInstance)) {
303
+ return;
304
+ }
305
+ childInstances.push(childInstance);
306
+ childProviders.push(childProvider);
307
+ sortInstances();
308
+ };
309
+ const clear = (childInstance, childProvider) => {
310
+ (0, import_shared3.removeItem)(childInstances, childInstance);
311
+ (0, import_shared3.removeItem)(childProviders, childProvider);
312
+ };
313
+ const bindChildren = (parentProvider) => {
314
+ (0, import_vue6.provide)(key, __spreadValues({
315
+ childInstances,
316
+ collect,
317
+ clear
318
+ }, parentProvider));
319
+ };
320
+ return {
321
+ length,
322
+ childProviders,
323
+ bindChildren
324
+ };
325
+ }
326
+
327
+ // src/onWindowResize.ts
328
+ function onWindowResize(listener) {
329
+ useEventListener(() => window, "resize", listener, { passive: true });
330
+ useEventListener(() => window, "orientationchange", listener, { passive: true });
331
+ }
332
+
333
+ // src/useInitialized.ts
334
+ var import_vue7 = require("vue");
335
+ function useInitialized(source, value) {
336
+ const initialized = (0, import_vue7.ref)(false);
337
+ (0, import_vue7.watch)(
338
+ source,
339
+ (newValue) => {
340
+ if (value === newValue) {
341
+ initialized.value = true;
342
+ }
343
+ },
344
+ { immediate: true }
345
+ );
346
+ return initialized;
347
+ }
348
+
349
+ // src/useTouch.ts
350
+ var import_vue8 = require("vue");
351
+ var import_shared4 = require("@maple-design/shared");
352
+ function getDirection(x, y) {
353
+ if (x > y) {
354
+ return "horizontal";
355
+ }
356
+ if (y > x) {
357
+ return "vertical";
358
+ }
359
+ }
360
+ function useTouch() {
361
+ const startX = (0, import_vue8.ref)(0);
362
+ const startY = (0, import_vue8.ref)(0);
363
+ const deltaX = (0, import_vue8.ref)(0);
364
+ const deltaY = (0, import_vue8.ref)(0);
365
+ const offsetX = (0, import_vue8.ref)(0);
366
+ const offsetY = (0, import_vue8.ref)(0);
367
+ const prevX = (0, import_vue8.ref)(0);
368
+ const prevY = (0, import_vue8.ref)(0);
369
+ const moveX = (0, import_vue8.ref)(0);
370
+ const moveY = (0, import_vue8.ref)(0);
371
+ const direction = (0, import_vue8.ref)();
372
+ const touching = (0, import_vue8.ref)(false);
373
+ const dragging = (0, import_vue8.ref)(false);
374
+ const startTime = (0, import_vue8.ref)(0);
375
+ const distance = (0, import_vue8.ref)(0);
376
+ let draggingAnimationFrame = null;
377
+ const cancelFrame = () => {
378
+ if (draggingAnimationFrame !== null && typeof window !== "undefined") {
379
+ window.cancelAnimationFrame(draggingAnimationFrame);
380
+ }
381
+ draggingAnimationFrame = null;
382
+ };
383
+ const resetTouch = () => {
384
+ cancelFrame();
385
+ startX.value = 0;
386
+ startY.value = 0;
387
+ deltaX.value = 0;
388
+ deltaY.value = 0;
389
+ offsetX.value = 0;
390
+ offsetY.value = 0;
391
+ prevX.value = 0;
392
+ prevY.value = 0;
393
+ moveX.value = 0;
394
+ moveY.value = 0;
395
+ direction.value = void 0;
396
+ touching.value = false;
397
+ dragging.value = false;
398
+ startTime.value = 0;
399
+ distance.value = 0;
400
+ };
401
+ const startTouch = (event) => {
402
+ resetTouch();
403
+ if (!event.touches.length) {
404
+ return;
405
+ }
406
+ const { clientX: x, clientY: y } = event.touches[0];
407
+ startX.value = x;
408
+ startY.value = y;
409
+ prevX.value = x;
410
+ prevY.value = y;
411
+ touching.value = true;
412
+ startTime.value = performance.now();
413
+ dragging.value = false;
414
+ if (draggingAnimationFrame) {
415
+ window.cancelAnimationFrame(draggingAnimationFrame);
416
+ }
417
+ };
418
+ const moveTouch = (event) => {
419
+ if (!event.touches.length) {
420
+ return;
421
+ }
422
+ const { clientX: x, clientY: y } = event.touches[0];
423
+ dragging.value = true;
424
+ deltaX.value = x - startX.value;
425
+ deltaY.value = y - startY.value;
426
+ offsetX.value = Math.abs(deltaX.value);
427
+ offsetY.value = Math.abs(deltaY.value);
428
+ distance.value = Math.sqrt(offsetX.value ** 2 + offsetY.value ** 2);
429
+ moveX.value = x - prevX.value;
430
+ moveY.value = y - prevY.value;
431
+ if (!direction.value) {
432
+ direction.value = getDirection(offsetX.value, offsetY.value);
433
+ }
434
+ prevX.value = x;
435
+ prevY.value = y;
436
+ };
437
+ const endTouch = () => {
438
+ touching.value = false;
439
+ cancelFrame();
440
+ if (typeof window === "undefined") {
441
+ dragging.value = false;
442
+ return;
443
+ }
444
+ draggingAnimationFrame = window.requestAnimationFrame(() => {
445
+ draggingAnimationFrame = null;
446
+ dragging.value = false;
447
+ });
448
+ };
449
+ const isReachTop = (element) => {
450
+ const scrollTop = (0, import_shared4.getScrollTop)(element);
451
+ return scrollTop === 0 && deltaY.value > 0;
452
+ };
453
+ const isReachBottom = (element, offset = 1) => {
454
+ const { scrollHeight, clientHeight, scrollTop } = element;
455
+ const offsetBottom = Math.abs(scrollHeight - scrollTop - clientHeight);
456
+ return deltaY.value < 0 && offsetBottom <= offset;
457
+ };
458
+ (0, import_vue8.onBeforeUnmount)(resetTouch);
459
+ (0, import_vue8.onDeactivated)(resetTouch);
460
+ return {
461
+ startX,
462
+ startY,
463
+ deltaX,
464
+ deltaY,
465
+ offsetX,
466
+ offsetY,
467
+ prevX,
468
+ prevY,
469
+ moveX,
470
+ moveY,
471
+ direction,
472
+ touching,
473
+ dragging,
474
+ startTime,
475
+ distance,
476
+ resetTouch,
477
+ startTouch,
478
+ moveTouch,
479
+ endTouch,
480
+ isReachTop,
481
+ isReachBottom
482
+ };
483
+ }
484
+
485
+ // src/useId.ts
486
+ var Vue = __toESM(require("vue"), 1);
487
+ var import_shared5 = require("@maple-design/shared");
488
+ function useId2() {
489
+ var _a, _b;
490
+ const instance = Vue.getCurrentInstance();
491
+ const name = (0, import_shared5.kebabCase)((_a = instance.type.name) != null ? _a : "component");
492
+ const nativeId = (_b = Vue.useId) == null ? void 0 : _b();
493
+ const id = Vue.ref();
494
+ id.value = process.env.NODE_ENV === "test" ? `${name}-mock-id` : nativeId ? `${name}-${nativeId}` : void 0;
495
+ Vue.onMounted(() => {
496
+ if (id.value === void 0) {
497
+ id.value = `${name}-${instance.uid}`;
498
+ }
499
+ });
500
+ return id;
501
+ }
502
+
503
+ // src/useClientId.ts
504
+ var import_vue9 = require("vue");
505
+ var import_shared6 = require("@maple-design/shared");
506
+ function useClientId() {
507
+ const instance = (0, import_vue9.getCurrentInstance)();
508
+ const name = (0, import_shared6.kebabCase)(instance.type.name);
509
+ const id = (0, import_vue9.ref)(process.env.NODE_ENV === "test" ? `${name}-mock-id` : void 0);
510
+ (0, import_vue9.onMounted)(() => {
511
+ if (process.env.NODE_ENV !== "test") {
512
+ id.value = `${name}-${instance.uid}`;
513
+ }
514
+ });
515
+ return id;
516
+ }
517
+
518
+ // src/useWindowSize.ts
519
+ var import_vue10 = require("vue");
520
+ var import_shared7 = require("@maple-design/shared");
521
+ function useWindowSize(options = {}) {
522
+ const { initialWidth = 0, initialHeight = 0 } = options;
523
+ const width = (0, import_vue10.ref)(initialWidth);
524
+ const height = (0, import_vue10.ref)(initialHeight);
525
+ const update = () => {
526
+ if (!(0, import_shared7.inBrowser)()) {
527
+ return;
528
+ }
529
+ width.value = window.innerWidth;
530
+ height.value = window.innerHeight;
531
+ };
532
+ onSmartMounted(update);
533
+ onWindowResize(update);
534
+ return {
535
+ width,
536
+ height
537
+ };
538
+ }
539
+
540
+ // src/useVModel.ts
541
+ var import_vue11 = require("vue");
542
+ var import_shared8 = require("@maple-design/shared");
543
+ function useVModel(props, key, options = {}) {
544
+ const { passive = true, eventName, defaultValue, emit } = options;
545
+ const event = eventName != null ? eventName : `${emit ? "update" : "onUpdate"}:${key.toString()}`;
546
+ const getValue = () => {
547
+ var _a;
548
+ return (_a = props[key]) != null ? _a : defaultValue;
549
+ };
550
+ if (!passive) {
551
+ return (0, import_vue11.computed)({
552
+ get() {
553
+ return getValue();
554
+ },
555
+ set(value) {
556
+ emit ? emit(event, value) : (0, import_shared8.call)(props[event], value);
557
+ }
558
+ });
559
+ }
560
+ const proxy = (0, import_vue11.ref)(getValue());
561
+ let shouldEmit = true;
562
+ (0, import_vue11.watch)(
563
+ () => props[key],
564
+ () => {
565
+ shouldEmit = false;
566
+ proxy.value = getValue();
567
+ (0, import_vue11.nextTick)(() => {
568
+ shouldEmit = true;
569
+ });
570
+ }
571
+ );
572
+ (0, import_vue11.watch)(
573
+ () => proxy.value,
574
+ (newValue) => {
575
+ if (!shouldEmit) {
576
+ return;
577
+ }
578
+ emit ? emit(event, newValue) : (0, import_shared8.call)(props[event], newValue);
579
+ }
580
+ );
581
+ return proxy;
582
+ }
583
+
584
+ // src/useMotion.ts
585
+ var import_vue12 = require("vue");
586
+ var import_shared9 = require("@maple-design/shared");
587
+ function useMotion(options) {
588
+ const value = (0, import_vue12.ref)(getter(options.from));
589
+ const state = (0, import_vue12.ref)("pending");
590
+ let ctx = createMotionContext();
591
+ function getter(value2) {
592
+ return (0, import_shared9.isFunction)(value2) ? value2() : value2;
593
+ }
594
+ function reset() {
595
+ ctx.reset();
596
+ value.value = getter(options.from);
597
+ state.value = "pending";
598
+ ctx = createMotionContext();
599
+ }
600
+ function start() {
601
+ ctx.start();
602
+ }
603
+ function pause() {
604
+ ctx.pause();
605
+ }
606
+ function createMotionContext() {
607
+ return (0, import_shared9.motion)({
608
+ from: getter(options.from),
609
+ to: getter(options.to),
610
+ duration: options.duration === void 0 ? 300 : getter(options.duration),
611
+ timingFunction: options.timingFunction,
612
+ onStateChange(newState) {
613
+ state.value = newState;
614
+ },
615
+ frame({ value: newValue, done }) {
616
+ var _a;
617
+ value.value = newValue;
618
+ if (done) {
619
+ (_a = options.onFinished) == null ? void 0 : _a.call(options, value.value);
620
+ }
621
+ }
622
+ });
623
+ }
624
+ return {
625
+ value,
626
+ state,
627
+ start,
628
+ pause,
629
+ reset
630
+ };
631
+ }
632
+
633
+ // src/useAsyncData.ts
634
+ var import_vue13 = require("vue");
635
+ function useAsyncData(loader, options) {
636
+ const data = (0, import_vue13.shallowRef)(options.initialData);
637
+ const loading = (0, import_vue13.ref)(false);
638
+ const error = (0, import_vue13.shallowRef)();
639
+ const initialKey = Symbol("initial");
640
+ const cache = /* @__PURE__ */ new Map();
641
+ let active;
642
+ let last = {};
643
+ let disposed = false;
644
+ let started = false;
645
+ function cancel() {
646
+ const task = active;
647
+ active = void 0;
648
+ if (task) {
649
+ clearTimeout(task.timer);
650
+ task.controller.abort();
651
+ task.settle({ status: "cancelled" });
652
+ }
653
+ loading.value = false;
654
+ }
655
+ function run(request, delay) {
656
+ var _a, _b, _c;
657
+ cancel();
658
+ if (disposed) {
659
+ return Promise.resolve({ status: "cancelled" });
660
+ }
661
+ started = true;
662
+ last = request;
663
+ error.value = void 0;
664
+ const currentLoader = (_a = request.loader) != null ? _a : loader;
665
+ const key = (_b = request.cacheKey) != null ? _b : request.loader ? void 0 : initialKey;
666
+ const ttl = (_c = options.cacheTime) != null ? _c : 0;
667
+ const cached = key === void 0 ? void 0 : cache.get(key);
668
+ if (!request.force && ttl > 0 && cached && cached.expires > Date.now()) {
669
+ data.value = cached.data;
670
+ return Promise.resolve({ status: "success", data: cached.data });
671
+ }
672
+ if (key !== void 0) {
673
+ cache.delete(key);
674
+ }
675
+ loading.value = true;
676
+ return new Promise((settle) => {
677
+ const task = {
678
+ controller: new AbortController(),
679
+ settle,
680
+ timer: void 0
681
+ };
682
+ active = task;
683
+ const start = () => __async(this, null, function* () {
684
+ try {
685
+ const value = yield currentLoader({ signal: task.controller.signal });
686
+ if (active !== task) {
687
+ return;
688
+ }
689
+ data.value = value;
690
+ if (ttl > 0 && key !== void 0) {
691
+ if (cache.size >= 50) {
692
+ cache.delete(cache.keys().next().value);
693
+ }
694
+ cache.set(key, { data: value, expires: Date.now() + ttl });
695
+ }
696
+ settle({ status: "success", data: value });
697
+ } catch (cause) {
698
+ if (active !== task) {
699
+ return;
700
+ }
701
+ error.value = cause;
702
+ settle({ status: "error", error: cause });
703
+ } finally {
704
+ if (active === task) {
705
+ active = void 0;
706
+ loading.value = false;
707
+ }
708
+ }
709
+ });
710
+ if (delay > 0) {
711
+ task.timer = setTimeout(start, delay);
712
+ } else {
713
+ void start();
714
+ }
715
+ });
716
+ }
717
+ const execute = (request = {}) => {
718
+ var _a;
719
+ return run(request, (_a = options.debounce) != null ? _a : 0);
720
+ };
721
+ const refresh = () => run(__spreadProps(__spreadValues({}, last), { force: true }), 0);
722
+ const initialize = () => {
723
+ if (!started && !disposed && options.immediate !== false) {
724
+ void run({}, 0);
725
+ }
726
+ };
727
+ if ((0, import_vue13.getCurrentInstance)()) {
728
+ (0, import_vue13.onMounted)(initialize);
729
+ } else {
730
+ initialize();
731
+ }
732
+ if ((0, import_vue13.getCurrentScope)()) {
733
+ (0, import_vue13.onScopeDispose)(() => {
734
+ disposed = true;
735
+ cancel();
736
+ cache.clear();
737
+ });
738
+ }
739
+ return {
740
+ data,
741
+ loading: (0, import_vue13.readonly)(loading),
742
+ error: (0, import_vue13.readonly)(error),
743
+ execute,
744
+ refresh,
745
+ cancel,
746
+ clearCache: () => cache.clear()
747
+ };
748
+ }
749
+
750
+ // src/useDirection.ts
751
+ var import_vue14 = require("vue");
752
+ var readingDirectionKey = Symbol("reading-direction");
753
+ function provideDirection(direction) {
754
+ (0, import_vue14.provide)(readingDirectionKey, direction);
755
+ }
756
+ function resolveDirection(element, fallback = "ltr") {
757
+ var _a, _b;
758
+ const scope = element == null ? void 0 : element.closest("[dir]");
759
+ const value = (_a = scope == null ? void 0 : scope.getAttribute("dir")) == null ? void 0 : _a.toLowerCase();
760
+ if (value === "ltr" || value === "rtl") {
761
+ return value;
762
+ }
763
+ if (value === "auto" && scope) {
764
+ return ((_b = scope.ownerDocument.defaultView) == null ? void 0 : _b.getComputedStyle(scope).direction) === "rtl" ? "rtl" : "ltr";
765
+ }
766
+ return fallback;
767
+ }
768
+ var documents = /* @__PURE__ */ new WeakMap();
769
+ function useDirection(target, explicit) {
770
+ const inherited = (0, import_vue14.inject)(readingDirectionKey, void 0);
771
+ const instance = (0, import_vue14.getCurrentInstance)();
772
+ const element = (0, import_vue14.shallowRef)();
773
+ const version = (0, import_vue14.shallowRef)();
774
+ let release;
775
+ let active = false;
776
+ function observe(node) {
777
+ var _a;
778
+ if (node === element.value && release) {
779
+ return;
780
+ }
781
+ release == null ? void 0 : release();
782
+ release = void 0;
783
+ element.value = node != null ? node : void 0;
784
+ version.value = void 0;
785
+ const doc = node == null ? void 0 : node.ownerDocument;
786
+ const Observer = (_a = doc == null ? void 0 : doc.defaultView) == null ? void 0 : _a.MutationObserver;
787
+ if (!doc || !Observer) {
788
+ return;
789
+ }
790
+ let state = documents.get(doc);
791
+ if (!state) {
792
+ const counter = (0, import_vue14.ref)(0);
793
+ const observer = new Observer(() => {
794
+ counter.value++;
795
+ });
796
+ observer.observe(doc.documentElement, { subtree: true, attributes: true, attributeFilter: ["dir"] });
797
+ state = { version: counter, observer, users: 0 };
798
+ documents.set(doc, state);
799
+ }
800
+ state.users++;
801
+ version.value = state.version;
802
+ const current = state;
803
+ release = () => {
804
+ if (--current.users === 0) {
805
+ current.observer.disconnect();
806
+ documents.delete(doc);
807
+ }
808
+ };
809
+ }
810
+ function refresh() {
811
+ const node = target ? target() : instance == null ? void 0 : instance.vnode.el;
812
+ observe((node == null ? void 0 : node.nodeType) === 1 ? node : node == null ? void 0 : node.parentElement);
813
+ }
814
+ function start() {
815
+ active = true;
816
+ refresh();
817
+ }
818
+ function stop() {
819
+ active = false;
820
+ release == null ? void 0 : release();
821
+ release = void 0;
822
+ version.value = void 0;
823
+ }
824
+ (0, import_vue14.onMounted)(start);
825
+ (0, import_vue14.onActivated)(start);
826
+ (0, import_vue14.onDeactivated)(stop);
827
+ (0, import_vue14.onScopeDispose)(stop);
828
+ (0, import_vue14.watchPostEffect)(() => {
829
+ const node = target == null ? void 0 : target();
830
+ if (active) {
831
+ if (target) {
832
+ observe(node);
833
+ } else {
834
+ refresh();
835
+ }
836
+ }
837
+ });
838
+ const dir = (0, import_vue14.computed)(() => {
839
+ var _a, _b;
840
+ void ((_a = version.value) == null ? void 0 : _a.value);
841
+ const value = explicit == null ? void 0 : explicit();
842
+ if (value === "ltr" || value === "rtl") {
843
+ return value;
844
+ }
845
+ return resolveDirection(element.value, (_b = inherited == null ? void 0 : inherited.value) != null ? _b : "ltr");
846
+ });
847
+ return { dir, isRtl: (0, import_vue14.computed)(() => dir.value === "rtl") };
848
+ }
849
+ // Annotate the CommonJS export names for ESM import in node:
850
+ 0 && (module.exports = {
851
+ keyInProvides,
852
+ onSmartMounted,
853
+ onSmartUnmounted,
854
+ onWindowResize,
855
+ provideDirection,
856
+ readingDirectionKey,
857
+ resolveDirection,
858
+ useAsyncData,
859
+ useChildren,
860
+ useClickOutside,
861
+ useClientId,
862
+ useDirection,
863
+ useEventListener,
864
+ useId,
865
+ useInitialized,
866
+ useMotion,
867
+ useParent,
868
+ useTouch,
869
+ useVModel,
870
+ useWindowSize
871
+ });