@varlet/use 3.6.4 → 3.7.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 +51 -0
- package/lib/index.d.cts +17 -1
- package/lib/index.d.ts +17 -1
- package/lib/index.js +50 -0
- package/package.json +3 -3
package/lib/index.cjs
CHANGED
|
@@ -56,6 +56,7 @@ __export(src_exports, {
|
|
|
56
56
|
useEventListener: () => useEventListener,
|
|
57
57
|
useId: () => useId,
|
|
58
58
|
useInitialized: () => useInitialized,
|
|
59
|
+
useMotion: () => useMotion,
|
|
59
60
|
useParent: () => useParent,
|
|
60
61
|
useTouch: () => useTouch,
|
|
61
62
|
useVModel: () => useVModel,
|
|
@@ -497,6 +498,55 @@ function useVModel(props, key, options = {}) {
|
|
|
497
498
|
);
|
|
498
499
|
return proxy;
|
|
499
500
|
}
|
|
501
|
+
|
|
502
|
+
// src/useMotion.ts
|
|
503
|
+
var import_shared9 = require("@varlet/shared");
|
|
504
|
+
var import_vue13 = require("vue");
|
|
505
|
+
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
|
+
};
|
|
549
|
+
}
|
|
500
550
|
// Annotate the CommonJS export names for ESM import in node:
|
|
501
551
|
0 && (module.exports = {
|
|
502
552
|
keyInProvides,
|
|
@@ -509,6 +559,7 @@ function useVModel(props, key, options = {}) {
|
|
|
509
559
|
useEventListener,
|
|
510
560
|
useId,
|
|
511
561
|
useInitialized,
|
|
562
|
+
useMotion,
|
|
512
563
|
useParent,
|
|
513
564
|
useTouch,
|
|
514
565
|
useVModel,
|
package/lib/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { Ref, ComponentInternalInstance, ComputedRef, WatchSource, WritableComputedRef } from 'vue';
|
|
3
|
+
import { MotionState } from '@varlet/shared';
|
|
3
4
|
|
|
4
5
|
type UseEventListenerTarget = EventTarget | Ref<EventTarget | undefined | null> | (() => EventTarget);
|
|
5
6
|
interface UseEventListenerOptions {
|
|
@@ -88,4 +89,19 @@ interface UseVModelOptions<P, K extends keyof P> {
|
|
|
88
89
|
}
|
|
89
90
|
declare function useVModel<P extends Record<string, any>, K extends keyof P>(props: P, key: K, options?: UseVModelOptions<P, K>): WritableComputedRef<P[K]> | Ref<P[K]>;
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
interface UseMotionOptions {
|
|
93
|
+
from: number | (() => number);
|
|
94
|
+
to: number | (() => number);
|
|
95
|
+
duration?: number | (() => number);
|
|
96
|
+
timingFunction?: (v: number) => number;
|
|
97
|
+
onFinished?: (value: number) => void;
|
|
98
|
+
}
|
|
99
|
+
declare function useMotion(options: UseMotionOptions): {
|
|
100
|
+
value: vue.Ref<number>;
|
|
101
|
+
state: vue.Ref<MotionState>;
|
|
102
|
+
start: () => void;
|
|
103
|
+
pause: () => void;
|
|
104
|
+
reset: () => void;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseMotionOptions, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useClientId, useEventListener, useId, useInitialized, useMotion, useParent, useTouch, useVModel, useWindowSize };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { Ref, ComponentInternalInstance, ComputedRef, WatchSource, WritableComputedRef } from 'vue';
|
|
3
|
+
import { MotionState } from '@varlet/shared';
|
|
3
4
|
|
|
4
5
|
type UseEventListenerTarget = EventTarget | Ref<EventTarget | undefined | null> | (() => EventTarget);
|
|
5
6
|
interface UseEventListenerOptions {
|
|
@@ -88,4 +89,19 @@ interface UseVModelOptions<P, K extends keyof P> {
|
|
|
88
89
|
}
|
|
89
90
|
declare function useVModel<P extends Record<string, any>, K extends keyof P>(props: P, key: K, options?: UseVModelOptions<P, K>): WritableComputedRef<P[K]> | Ref<P[K]>;
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
interface UseMotionOptions {
|
|
93
|
+
from: number | (() => number);
|
|
94
|
+
to: number | (() => number);
|
|
95
|
+
duration?: number | (() => number);
|
|
96
|
+
timingFunction?: (v: number) => number;
|
|
97
|
+
onFinished?: (value: number) => void;
|
|
98
|
+
}
|
|
99
|
+
declare function useMotion(options: UseMotionOptions): {
|
|
100
|
+
value: vue.Ref<number>;
|
|
101
|
+
state: vue.Ref<MotionState>;
|
|
102
|
+
start: () => void;
|
|
103
|
+
pause: () => void;
|
|
104
|
+
reset: () => void;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { TouchDirection, UseChildrenBaseProvider, UseClickOutsideTarget, UseEventListenerOptions, UseEventListenerTarget, UseMotionOptions, UseVModelOptions, UseWindowSizeOptions, keyInProvides, onSmartMounted, onSmartUnmounted, onWindowResize, useChildren, useClickOutside, useClientId, useEventListener, useId, useInitialized, useMotion, useParent, useTouch, useVModel, useWindowSize };
|
package/lib/index.js
CHANGED
|
@@ -474,6 +474,55 @@ function useVModel(props, key, options = {}) {
|
|
|
474
474
|
);
|
|
475
475
|
return proxy;
|
|
476
476
|
}
|
|
477
|
+
|
|
478
|
+
// src/useMotion.ts
|
|
479
|
+
import { isFunction as isFunction3, motion } from "@varlet/shared";
|
|
480
|
+
import { ref as ref7 } from "vue";
|
|
481
|
+
function useMotion(options) {
|
|
482
|
+
const value = ref7(getter(options.from));
|
|
483
|
+
const state = ref7("pending");
|
|
484
|
+
let ctx = createMotionContext();
|
|
485
|
+
function getter(value2) {
|
|
486
|
+
return isFunction3(value2) ? value2() : value2;
|
|
487
|
+
}
|
|
488
|
+
function reset() {
|
|
489
|
+
ctx.reset();
|
|
490
|
+
value.value = getter(options.from);
|
|
491
|
+
state.value = "pending";
|
|
492
|
+
ctx = createMotionContext();
|
|
493
|
+
}
|
|
494
|
+
function start() {
|
|
495
|
+
ctx.start();
|
|
496
|
+
}
|
|
497
|
+
function pause() {
|
|
498
|
+
ctx.pause();
|
|
499
|
+
}
|
|
500
|
+
function createMotionContext() {
|
|
501
|
+
return motion({
|
|
502
|
+
from: getter(options.from),
|
|
503
|
+
to: getter(options.to),
|
|
504
|
+
duration: options.duration ? getter(options.duration) : 300,
|
|
505
|
+
timingFunction: options.timingFunction,
|
|
506
|
+
onStateChange(newState) {
|
|
507
|
+
state.value = newState;
|
|
508
|
+
},
|
|
509
|
+
frame({ value: newValue, done }) {
|
|
510
|
+
var _a;
|
|
511
|
+
value.value = newValue;
|
|
512
|
+
if (done) {
|
|
513
|
+
(_a = options.onFinished) == null ? void 0 : _a.call(options, value.value);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
value,
|
|
520
|
+
state,
|
|
521
|
+
start,
|
|
522
|
+
pause,
|
|
523
|
+
reset
|
|
524
|
+
};
|
|
525
|
+
}
|
|
477
526
|
export {
|
|
478
527
|
keyInProvides,
|
|
479
528
|
onSmartMounted,
|
|
@@ -485,6 +534,7 @@ export {
|
|
|
485
534
|
useEventListener,
|
|
486
535
|
useId,
|
|
487
536
|
useInitialized,
|
|
537
|
+
useMotion,
|
|
488
538
|
useParent,
|
|
489
539
|
useTouch,
|
|
490
540
|
useVModel,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/use",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"url": "https://github.com/varletjs/varlet/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@varlet/shared": "3.
|
|
36
|
+
"@varlet/shared": "3.7.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^18.7.18",
|
|
40
40
|
"tsup": "7.2.0",
|
|
41
|
-
"typescript": "
|
|
41
|
+
"typescript": "5.3.3",
|
|
42
42
|
"vue": "3.4.21"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|